2 * Copyright 2010 Christoph Bumiller
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #include "draw/draw_context.h"
24 #include "pipe/p_defines.h"
26 #include "nv50_context.h"
27 #include "nv50_screen.h"
28 #include "nv50_resource.h"
30 #include "nouveau/nouveau_reloc.h"
33 nv50_flush(struct pipe_context
*pipe
,
34 struct pipe_fence_handle
**fence
)
36 struct nouveau_screen
*screen
= nouveau_screen(pipe
->screen
);
39 nouveau_fence_ref(screen
->fence
.current
, (struct nouveau_fence
**)fence
);
41 PUSH_KICK(screen
->pushbuf
);
45 nv50_texture_barrier(struct pipe_context
*pipe
)
47 struct nouveau_pushbuf
*push
= nv50_context(pipe
)->base
.pushbuf
;
49 BEGIN_NV04(push
, SUBC_3D(NV50_GRAPH_SERIALIZE
), 1);
51 BEGIN_NV04(push
, NV50_3D(TEX_CACHE_CTL
), 1);
52 PUSH_DATA (push
, 0x20);
56 nv50_default_kick_notify(struct nouveau_pushbuf
*push
)
58 struct nv50_screen
*screen
= push
->user_priv
;
61 nouveau_fence_next(&screen
->base
);
62 nouveau_fence_update(&screen
->base
, TRUE
);
64 screen
->cur_ctx
->state
.flushed
= TRUE
;
69 nv50_context_unreference_resources(struct nv50_context
*nv50
)
73 nouveau_bufctx_del(&nv50
->bufctx_3d
);
74 nouveau_bufctx_del(&nv50
->bufctx
);
76 for (i
= 0; i
< nv50
->num_vtxbufs
; ++i
)
77 pipe_resource_reference(&nv50
->vtxbuf
[i
].buffer
, NULL
);
79 pipe_resource_reference(&nv50
->idxbuf
.buffer
, NULL
);
81 for (s
= 0; s
< 3; ++s
) {
82 for (i
= 0; i
< nv50
->num_textures
[s
]; ++i
)
83 pipe_sampler_view_reference(&nv50
->textures
[s
][i
], NULL
);
85 for (i
= 0; i
< 16; ++i
)
86 pipe_resource_reference(&nv50
->constbuf
[s
][i
], NULL
);
91 nv50_destroy(struct pipe_context
*pipe
)
93 struct nv50_context
*nv50
= nv50_context(pipe
);
95 if (nv50_context_screen(nv50
)->cur_ctx
== nv50
) {
96 nv50
->base
.pushbuf
->kick_notify
= NULL
;
97 nv50_context_screen(nv50
)->cur_ctx
= NULL
;
98 nouveau_pushbuf_bufctx(nv50
->base
.pushbuf
, NULL
);
100 /* need to flush before destroying the bufctx */
101 nouveau_pushbuf_kick(nv50
->base
.pushbuf
, nv50
->base
.pushbuf
->channel
);
103 nv50_context_unreference_resources(nv50
);
105 draw_destroy(nv50
->draw
);
110 struct pipe_context
*
111 nv50_create(struct pipe_screen
*pscreen
, void *priv
)
113 struct nv50_screen
*screen
= nv50_screen(pscreen
);
114 struct nv50_context
*nv50
;
115 struct pipe_context
*pipe
;
119 nv50
= CALLOC_STRUCT(nv50_context
);
122 pipe
= &nv50
->base
.pipe
;
124 nv50
->base
.pushbuf
= screen
->base
.pushbuf
;
126 ret
= nouveau_bufctx_new(screen
->base
.client
, NV50_BIND_COUNT
,
129 ret
= nouveau_bufctx_new(screen
->base
.client
, 2, &nv50
->bufctx
);
133 nv50
->base
.screen
= &screen
->base
;
134 nv50
->base
.copy_data
= nv50_m2mf_copy_linear
;
135 nv50
->base
.push_data
= nv50_sifc_linear_u8
;
137 nv50
->screen
= screen
;
138 pipe
->screen
= pscreen
;
141 pipe
->destroy
= nv50_destroy
;
143 pipe
->draw_vbo
= nv50_draw_vbo
;
144 pipe
->clear
= nv50_clear
;
146 pipe
->flush
= nv50_flush
;
147 pipe
->texture_barrier
= nv50_texture_barrier
;
149 if (!screen
->cur_ctx
) {
150 screen
->cur_ctx
= nv50
;
151 nouveau_pushbuf_bufctx(screen
->base
.pushbuf
, nv50
->bufctx
);
154 nv50_init_query_functions(nv50
);
155 nv50_init_surface_functions(nv50
);
156 nv50_init_state_functions(nv50
);
157 nv50_init_resource_functions(pipe
);
159 nv50
->draw
= draw_create(pipe
);
161 draw_set_rasterize_stage(nv50
->draw
, nv50_draw_render_stage(nv50
));
163 nouveau_context_init_vdec(&nv50
->base
);
165 flags
= NOUVEAU_BO_VRAM
| NOUVEAU_BO_RD
;
167 BCTX_REFN_bo(nv50
->bufctx_3d
, SCREEN
, flags
, screen
->code
);
168 BCTX_REFN_bo(nv50
->bufctx_3d
, SCREEN
, flags
, screen
->uniforms
);
169 BCTX_REFN_bo(nv50
->bufctx_3d
, SCREEN
, flags
, screen
->txc
);
170 BCTX_REFN_bo(nv50
->bufctx_3d
, SCREEN
, flags
, screen
->stack_bo
);
172 flags
= NOUVEAU_BO_GART
| NOUVEAU_BO_WR
;
174 BCTX_REFN_bo(nv50
->bufctx_3d
, SCREEN
, flags
, screen
->fence
.bo
);
175 BCTX_REFN_bo(nv50
->bufctx
, FENCE
, flags
, screen
->fence
.bo
);
182 nouveau_bufctx_del(&nv50
->bufctx_3d
);
184 nouveau_bufctx_del(&nv50
->bufctx
);
191 nv50_bufctx_fence(struct nouveau_bufctx
*bufctx
, boolean on_flush
)
193 struct nouveau_list
*list
= on_flush
? &bufctx
->current
: &bufctx
->pending
;
194 struct nouveau_list
*it
;
196 for (it
= list
->next
; it
!= list
; it
= it
->next
) {
197 struct nouveau_bufref
*ref
= (struct nouveau_bufref
*)it
;
198 struct nv04_resource
*res
= ref
->priv
;
200 nv50_resource_validate(res
, (unsigned)ref
->priv_data
);