471c7be77e0fe4fd1c2aa5b694c35cffe92a2c49
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"
25 #include "util/u_framebuffer.h"
27 #include "nvc0_context.h"
28 #include "nvc0_screen.h"
29 #include "nvc0_resource.h"
32 nvc0_flush(struct pipe_context
*pipe
,
33 struct pipe_fence_handle
**fence
)
35 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
36 struct nouveau_screen
*screen
= &nvc0
->screen
->base
;
39 nouveau_fence_ref(screen
->fence
.current
, (struct nouveau_fence
**)fence
);
41 PUSH_KICK(nvc0
->base
.pushbuf
); /* fencing handled in kick_notify */
45 nvc0_texture_barrier(struct pipe_context
*pipe
)
47 struct nouveau_pushbuf
*push
= nvc0_context(pipe
)->base
.pushbuf
;
49 IMMED_NVC0(push
, NVC0_3D(SERIALIZE
), 0);
50 IMMED_NVC0(push
, NVC0_3D(TEX_CACHE_CTL
), 0);
54 nvc0_context_unreference_resources(struct nvc0_context
*nvc0
)
58 nouveau_bufctx_del(&nvc0
->bufctx_3d
);
59 nouveau_bufctx_del(&nvc0
->bufctx
);
61 util_unreference_framebuffer_state(&nvc0
->framebuffer
);
63 for (i
= 0; i
< nvc0
->num_vtxbufs
; ++i
)
64 pipe_resource_reference(&nvc0
->vtxbuf
[i
].buffer
, NULL
);
66 pipe_resource_reference(&nvc0
->idxbuf
.buffer
, NULL
);
68 for (s
= 0; s
< 5; ++s
) {
69 for (i
= 0; i
< nvc0
->num_textures
[s
]; ++i
)
70 pipe_sampler_view_reference(&nvc0
->textures
[s
][i
], NULL
);
72 for (i
= 0; i
< 16; ++i
)
73 pipe_resource_reference(&nvc0
->constbuf
[s
][i
], NULL
);
76 for (i
= 0; i
< nvc0
->num_tfbbufs
; ++i
)
77 pipe_so_target_reference(&nvc0
->tfbbuf
[i
], NULL
);
81 nvc0_destroy(struct pipe_context
*pipe
)
83 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
85 if (nvc0
->screen
->cur_ctx
== nvc0
) {
86 nvc0
->base
.pushbuf
->kick_notify
= NULL
;
87 nvc0
->screen
->cur_ctx
= NULL
;
88 nouveau_pushbuf_bufctx(nvc0
->base
.pushbuf
, NULL
);
90 nouveau_pushbuf_kick(nvc0
->base
.pushbuf
, nvc0
->base
.pushbuf
->channel
);
92 nvc0_context_unreference_resources(nvc0
);
94 draw_destroy(nvc0
->draw
);
100 nvc0_default_kick_notify(struct nouveau_pushbuf
*push
)
102 struct nvc0_screen
*screen
= push
->user_priv
;
105 nouveau_fence_next(&screen
->base
);
106 nouveau_fence_update(&screen
->base
, TRUE
);
108 screen
->cur_ctx
->state
.flushed
= TRUE
;
112 struct pipe_context
*
113 nvc0_create(struct pipe_screen
*pscreen
, void *priv
)
115 struct nvc0_screen
*screen
= nvc0_screen(pscreen
);
116 struct nvc0_context
*nvc0
;
117 struct pipe_context
*pipe
;
121 nvc0
= CALLOC_STRUCT(nvc0_context
);
124 pipe
= &nvc0
->base
.pipe
;
126 nvc0
->base
.pushbuf
= screen
->base
.pushbuf
;
128 ret
= nouveau_bufctx_new(screen
->base
.client
, NVC0_BIND_COUNT
,
131 nouveau_bufctx_new(screen
->base
.client
, 2, &nvc0
->bufctx
);
135 nvc0
->screen
= screen
;
136 nvc0
->base
.screen
= &screen
->base
;
137 nvc0
->base
.copy_data
= nvc0_m2mf_copy_linear
;
138 nvc0
->base
.push_data
= nvc0_m2mf_push_linear
;
139 nvc0
->base
.push_cb
= nvc0_cb_push
;
141 pipe
->screen
= pscreen
;
144 pipe
->destroy
= nvc0_destroy
;
146 pipe
->draw_vbo
= nvc0_draw_vbo
;
147 pipe
->clear
= nvc0_clear
;
149 pipe
->flush
= nvc0_flush
;
150 pipe
->texture_barrier
= nvc0_texture_barrier
;
152 if (!screen
->cur_ctx
) {
153 screen
->cur_ctx
= nvc0
;
154 nouveau_pushbuf_bufctx(screen
->base
.pushbuf
, nvc0
->bufctx
);
156 screen
->base
.pushbuf
->kick_notify
= nvc0_default_kick_notify
;
158 nvc0_init_query_functions(nvc0
);
159 nvc0_init_surface_functions(nvc0
);
160 nvc0_init_state_functions(nvc0
);
161 nvc0_init_resource_functions(pipe
);
163 nvc0
->draw
= draw_create(pipe
);
165 draw_set_rasterize_stage(nvc0
->draw
, nvc0_draw_render_stage(nvc0
));
167 nouveau_context_init_vdec(&nvc0
->base
);
169 /* shader builtin library is per-screen, but we need a context for m2mf */
170 nvc0_program_library_upload(nvc0
);
172 /* add permanently resident buffers to bufctxts */
174 flags
= NOUVEAU_BO_VRAM
| NOUVEAU_BO_RD
;
176 BCTX_REFN_bo(nvc0
->bufctx_3d
, SCREEN
, flags
, screen
->text
);
177 BCTX_REFN_bo(nvc0
->bufctx_3d
, SCREEN
, flags
, screen
->uniforms
);
178 BCTX_REFN_bo(nvc0
->bufctx_3d
, SCREEN
, flags
, screen
->txc
);
180 flags
= NOUVEAU_BO_GART
| NOUVEAU_BO_WR
;
182 BCTX_REFN_bo(nvc0
->bufctx_3d
, SCREEN
, flags
, screen
->fence
.bo
);
183 BCTX_REFN_bo(nvc0
->bufctx
, FENCE
, flags
, screen
->fence
.bo
);
190 nouveau_bufctx_del(&nvc0
->bufctx_3d
);
192 nouveau_bufctx_del(&nvc0
->bufctx
);
199 nvc0_bufctx_fence(struct nvc0_context
*nvc0
, struct nouveau_bufctx
*bufctx
,
202 struct nouveau_list
*list
= on_flush
? &bufctx
->current
: &bufctx
->pending
;
203 struct nouveau_list
*it
;
205 for (it
= list
->next
; it
!= list
; it
= it
->next
) {
206 struct nouveau_bufref
*ref
= (struct nouveau_bufref
*)it
;
207 struct nv04_resource
*res
= ref
->priv
;
209 nvc0_resource_validate(res
, (unsigned)ref
->priv_data
);