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 "nvc0_context.h"
27 #include "nvc0_screen.h"
28 #include "nvc0_resource.h"
30 #include "nouveau/nouveau_reloc.h"
33 nvc0_flush(struct pipe_context
*pipe
,
34 struct pipe_fence_handle
**fence
)
36 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
37 struct nouveau_screen
*screen
= &nvc0
->screen
->base
;
40 nouveau_fence_ref(screen
->fence
.current
, (struct nouveau_fence
**)fence
);
42 PUSH_KICK(nvc0
->base
.pushbuf
); /* fencing handled in kick_notify */
46 nvc0_texture_barrier(struct pipe_context
*pipe
)
48 struct nouveau_pushbuf
*push
= nvc0_context(pipe
)->base
.pushbuf
;
50 IMMED_NVC0(push
, NVC0_3D(SERIALIZE
), 0);
51 IMMED_NVC0(push
, NVC0_3D(TEX_CACHE_CTL
), 0);
55 nvc0_context_unreference_resources(struct nvc0_context
*nvc0
)
59 nouveau_bufctx_del(&nvc0
->bufctx_3d
);
60 nouveau_bufctx_del(&nvc0
->bufctx
);
62 for (i
= 0; i
< nvc0
->num_vtxbufs
; ++i
)
63 pipe_resource_reference(&nvc0
->vtxbuf
[i
].buffer
, NULL
);
65 pipe_resource_reference(&nvc0
->idxbuf
.buffer
, NULL
);
67 for (s
= 0; s
< 5; ++s
) {
68 for (i
= 0; i
< nvc0
->num_textures
[s
]; ++i
)
69 pipe_sampler_view_reference(&nvc0
->textures
[s
][i
], NULL
);
71 for (i
= 0; i
< 16; ++i
)
72 pipe_resource_reference(&nvc0
->constbuf
[s
][i
], NULL
);
75 for (i
= 0; i
< nvc0
->num_tfbbufs
; ++i
)
76 pipe_so_target_reference(&nvc0
->tfbbuf
[i
], NULL
);
80 nvc0_destroy(struct pipe_context
*pipe
)
82 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
84 if (nvc0
->screen
->cur_ctx
== nvc0
) {
85 nvc0
->base
.pushbuf
->kick_notify
= NULL
;
86 nvc0
->screen
->cur_ctx
= NULL
;
87 nouveau_pushbuf_bufctx(nvc0
->base
.pushbuf
, NULL
);
89 nouveau_pushbuf_kick(nvc0
->base
.pushbuf
, nvc0
->base
.pushbuf
->channel
);
91 nvc0_context_unreference_resources(nvc0
);
93 draw_destroy(nvc0
->draw
);
99 nvc0_default_kick_notify(struct nouveau_pushbuf
*push
)
101 struct nvc0_screen
*screen
= push
->user_priv
;
104 nouveau_fence_next(&screen
->base
);
105 nouveau_fence_update(&screen
->base
, TRUE
);
107 screen
->cur_ctx
->state
.flushed
= TRUE
;
111 struct pipe_context
*
112 nvc0_create(struct pipe_screen
*pscreen
, void *priv
)
114 struct nvc0_screen
*screen
= nvc0_screen(pscreen
);
115 struct nvc0_context
*nvc0
;
116 struct pipe_context
*pipe
;
120 nvc0
= CALLOC_STRUCT(nvc0_context
);
123 pipe
= &nvc0
->base
.pipe
;
125 nvc0
->base
.pushbuf
= screen
->base
.pushbuf
;
127 ret
= nouveau_bufctx_new(screen
->base
.client
, NVC0_BIND_COUNT
,
130 nouveau_bufctx_new(screen
->base
.client
, 2, &nvc0
->bufctx
);
134 nvc0
->screen
= screen
;
135 nvc0
->base
.screen
= &screen
->base
;
136 nvc0
->base
.copy_data
= nvc0_m2mf_copy_linear
;
137 nvc0
->base
.push_data
= nvc0_m2mf_push_linear
;
138 nvc0
->base
.push_cb
= nvc0_cb_push
;
140 pipe
->screen
= pscreen
;
143 pipe
->destroy
= nvc0_destroy
;
145 pipe
->draw_vbo
= nvc0_draw_vbo
;
146 pipe
->clear
= nvc0_clear
;
148 pipe
->flush
= nvc0_flush
;
149 pipe
->texture_barrier
= nvc0_texture_barrier
;
151 if (!screen
->cur_ctx
) {
152 screen
->cur_ctx
= nvc0
;
153 nouveau_pushbuf_bufctx(screen
->base
.pushbuf
, nvc0
->bufctx
);
155 screen
->base
.pushbuf
->kick_notify
= nvc0_default_kick_notify
;
157 nvc0_init_query_functions(nvc0
);
158 nvc0_init_surface_functions(nvc0
);
159 nvc0_init_state_functions(nvc0
);
160 nvc0_init_resource_functions(pipe
);
162 nvc0
->draw
= draw_create(pipe
);
164 draw_set_rasterize_stage(nvc0
->draw
, nvc0_draw_render_stage(nvc0
));
166 nouveau_context_init_vdec(&nvc0
->base
);
168 /* shader builtin library is per-screen, but we need a context for m2mf */
169 nvc0_program_library_upload(nvc0
);
171 /* add permanently resident buffers to bufctxts */
173 flags
= NOUVEAU_BO_VRAM
| NOUVEAU_BO_RD
;
175 BCTX_REFN_bo(nvc0
->bufctx_3d
, SCREEN
, flags
, screen
->text
);
176 BCTX_REFN_bo(nvc0
->bufctx_3d
, SCREEN
, flags
, screen
->uniforms
);
177 BCTX_REFN_bo(nvc0
->bufctx_3d
, SCREEN
, flags
, screen
->txc
);
179 flags
= NOUVEAU_BO_GART
| NOUVEAU_BO_WR
;
181 BCTX_REFN_bo(nvc0
->bufctx_3d
, SCREEN
, flags
, screen
->fence
.bo
);
182 BCTX_REFN_bo(nvc0
->bufctx
, FENCE
, flags
, screen
->fence
.bo
);
189 nouveau_bufctx_del(&nvc0
->bufctx_3d
);
191 nouveau_bufctx_del(&nvc0
->bufctx
);
198 nvc0_bufctx_fence(struct nvc0_context
*nvc0
, struct nouveau_bufctx
*bufctx
,
201 struct nouveau_list
*list
= on_flush
? &bufctx
->current
: &bufctx
->pending
;
202 struct nouveau_list
*it
;
204 for (it
= list
->next
; it
!= list
; it
= it
->next
) {
205 struct nouveau_bufref
*ref
= (struct nouveau_bufref
*)it
;
206 struct nv04_resource
*res
= ref
->priv
;
208 nvc0_resource_validate(res
, (unsigned)ref
->priv_data
);