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 "pipe/p_defines.h"
24 #include "util/u_framebuffer.h"
26 #ifdef NVC0_WITH_DRAW_MODULE
27 #include "draw/draw_context.h"
30 #include "nvc0_context.h"
31 #include "nvc0_screen.h"
32 #include "nvc0_resource.h"
35 nvc0_flush(struct pipe_context
*pipe
,
36 struct pipe_fence_handle
**fence
,
37 enum pipe_flush_flags flags
)
39 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
40 struct nouveau_screen
*screen
= &nvc0
->screen
->base
;
43 nouveau_fence_ref(screen
->fence
.current
, (struct nouveau_fence
**)fence
);
45 PUSH_KICK(nvc0
->base
.pushbuf
); /* fencing handled in kick_notify */
49 nvc0_texture_barrier(struct pipe_context
*pipe
)
51 struct nouveau_pushbuf
*push
= nvc0_context(pipe
)->base
.pushbuf
;
53 IMMED_NVC0(push
, NVC0_3D(SERIALIZE
), 0);
54 IMMED_NVC0(push
, NVC0_3D(TEX_CACHE_CTL
), 0);
58 nvc0_context_unreference_resources(struct nvc0_context
*nvc0
)
62 nouveau_bufctx_del(&nvc0
->bufctx_3d
);
63 nouveau_bufctx_del(&nvc0
->bufctx
);
65 util_unreference_framebuffer_state(&nvc0
->framebuffer
);
67 for (i
= 0; i
< nvc0
->num_vtxbufs
; ++i
)
68 pipe_resource_reference(&nvc0
->vtxbuf
[i
].buffer
, NULL
);
70 pipe_resource_reference(&nvc0
->idxbuf
.buffer
, NULL
);
72 for (s
= 0; s
< 5; ++s
) {
73 for (i
= 0; i
< nvc0
->num_textures
[s
]; ++i
)
74 pipe_sampler_view_reference(&nvc0
->textures
[s
][i
], NULL
);
76 for (i
= 0; i
< NVC0_MAX_PIPE_CONSTBUFS
; ++i
)
77 if (!nvc0
->constbuf
[s
][i
].user
)
78 pipe_resource_reference(&nvc0
->constbuf
[s
][i
].u
.buf
, NULL
);
81 for (i
= 0; i
< nvc0
->num_tfbbufs
; ++i
)
82 pipe_so_target_reference(&nvc0
->tfbbuf
[i
], NULL
);
86 nvc0_destroy(struct pipe_context
*pipe
)
88 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
90 if (nvc0
->screen
->cur_ctx
== nvc0
) {
91 nvc0
->base
.pushbuf
->kick_notify
= NULL
;
92 nvc0
->screen
->cur_ctx
= NULL
;
93 nouveau_pushbuf_bufctx(nvc0
->base
.pushbuf
, NULL
);
95 nouveau_pushbuf_kick(nvc0
->base
.pushbuf
, nvc0
->base
.pushbuf
->channel
);
97 nvc0_context_unreference_resources(nvc0
);
99 #ifdef NVC0_WITH_DRAW_MODULE
100 draw_destroy(nvc0
->draw
);
103 nouveau_context_destroy(&nvc0
->base
);
107 nvc0_default_kick_notify(struct nouveau_pushbuf
*push
)
109 struct nvc0_screen
*screen
= push
->user_priv
;
112 nouveau_fence_next(&screen
->base
);
113 nouveau_fence_update(&screen
->base
, TRUE
);
115 screen
->cur_ctx
->state
.flushed
= TRUE
;
119 struct pipe_context
*
120 nvc0_create(struct pipe_screen
*pscreen
, void *priv
)
122 struct nvc0_screen
*screen
= nvc0_screen(pscreen
);
123 struct nvc0_context
*nvc0
;
124 struct pipe_context
*pipe
;
128 nvc0
= CALLOC_STRUCT(nvc0_context
);
131 pipe
= &nvc0
->base
.pipe
;
133 if (!nvc0_blitctx_create(nvc0
))
136 nvc0
->base
.pushbuf
= screen
->base
.pushbuf
;
138 ret
= nouveau_bufctx_new(screen
->base
.client
, NVC0_BIND_COUNT
,
141 nouveau_bufctx_new(screen
->base
.client
, 2, &nvc0
->bufctx
);
145 nvc0
->screen
= screen
;
146 nvc0
->base
.screen
= &screen
->base
;
148 pipe
->screen
= pscreen
;
151 pipe
->destroy
= nvc0_destroy
;
153 pipe
->draw_vbo
= nvc0_draw_vbo
;
154 pipe
->clear
= nvc0_clear
;
156 pipe
->flush
= nvc0_flush
;
157 pipe
->texture_barrier
= nvc0_texture_barrier
;
159 if (!screen
->cur_ctx
) {
160 screen
->cur_ctx
= nvc0
;
161 nouveau_pushbuf_bufctx(screen
->base
.pushbuf
, nvc0
->bufctx
);
163 screen
->base
.pushbuf
->kick_notify
= nvc0_default_kick_notify
;
165 nvc0_init_query_functions(nvc0
);
166 nvc0_init_surface_functions(nvc0
);
167 nvc0_init_state_functions(nvc0
);
168 nvc0_init_transfer_functions(nvc0
);
169 nvc0_init_resource_functions(pipe
);
171 #ifdef NVC0_WITH_DRAW_MODULE
172 /* no software fallbacks implemented */
173 nvc0
->draw
= draw_create(pipe
);
175 draw_set_rasterize_stage(nvc0
->draw
, nvc0_draw_render_stage(nvc0
));
178 nouveau_context_init_vdec(&nvc0
->base
);
180 /* shader builtin library is per-screen, but we need a context for m2mf */
181 nvc0_program_library_upload(nvc0
);
183 /* add permanently resident buffers to bufctxts */
185 flags
= NOUVEAU_BO_VRAM
| NOUVEAU_BO_RD
;
187 BCTX_REFN_bo(nvc0
->bufctx_3d
, SCREEN
, flags
, screen
->text
);
188 BCTX_REFN_bo(nvc0
->bufctx_3d
, SCREEN
, flags
, screen
->uniform_bo
);
189 BCTX_REFN_bo(nvc0
->bufctx_3d
, SCREEN
, flags
, screen
->txc
);
190 BCTX_REFN_bo(nvc0
->bufctx_3d
, SCREEN
, flags
, screen
->poly_cache
);
192 flags
= NOUVEAU_BO_GART
| NOUVEAU_BO_WR
;
194 BCTX_REFN_bo(nvc0
->bufctx_3d
, SCREEN
, flags
, screen
->fence
.bo
);
195 BCTX_REFN_bo(nvc0
->bufctx
, FENCE
, flags
, screen
->fence
.bo
);
197 nvc0
->base
.scratch
.bo_size
= 2 << 20;
199 memset(nvc0
->tex_handles
, ~0, sizeof(nvc0
->tex_handles
));
206 nouveau_bufctx_del(&nvc0
->bufctx_3d
);
208 nouveau_bufctx_del(&nvc0
->bufctx
);
217 nvc0_bufctx_fence(struct nvc0_context
*nvc0
, struct nouveau_bufctx
*bufctx
,
220 struct nouveau_list
*list
= on_flush
? &bufctx
->current
: &bufctx
->pending
;
221 struct nouveau_list
*it
;
223 for (it
= list
->next
; it
!= list
; it
= it
->next
) {
224 struct nouveau_bufref
*ref
= (struct nouveau_bufref
*)it
;
225 struct nv04_resource
*res
= ref
->priv
;
227 nvc0_resource_validate(res
, (unsigned)ref
->priv_data
);