blob: 0e13556631ac18dcb9a5e26f1b207a4bb04cd842 [file] [log] [blame]
Christoph Bumiller4c224752010-11-12 15:17:40 +01001/*
2 * Copyright 2010 Christoph Bumiller
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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
Kenneth Graunke3d8d5b22013-04-21 13:46:48 -070017 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
Christoph Bumiller4c224752010-11-12 15:17:40 +010021 */
22
Christoph Bumiller4c224752010-11-12 15:17:40 +010023#include "pipe/p_defines.h"
Christoph Bumiller2d06ee82012-03-07 19:44:10 +010024#include "util/u_framebuffer.h"
Christoph Bumiller4c224752010-11-12 15:17:40 +010025
Christoph Bumillera48e5de2012-04-24 13:35:44 +020026#ifdef NVC0_WITH_DRAW_MODULE
27#include "draw/draw_context.h"
28#endif
29
Johannes Obermayr5eb7ff12013-08-20 20:14:00 +020030#include "nvc0/nvc0_context.h"
31#include "nvc0/nvc0_screen.h"
32#include "nvc0/nvc0_resource.h"
Christoph Bumiller4c224752010-11-12 15:17:40 +010033
Christoph Bumiller4c224752010-11-12 15:17:40 +010034static void
Marek Olšák7e023032011-03-08 00:57:48 +010035nvc0_flush(struct pipe_context *pipe,
Marek Olšák598cc1f2012-12-21 17:03:22 +010036 struct pipe_fence_handle **fence,
Chia-I Wu8c347d42013-05-02 16:25:15 +080037 unsigned flags)
Christoph Bumiller4c224752010-11-12 15:17:40 +010038{
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +020039 struct nvc0_context *nvc0 = nvc0_context(pipe);
40 struct nouveau_screen *screen = &nvc0->screen->base;
Christoph Bumiller4c224752010-11-12 15:17:40 +010041
Christoph Bumillera6ea37d2011-02-20 17:57:47 +010042 if (fence)
Christoph Bumiller43888172011-03-13 13:07:54 +010043 nouveau_fence_ref(screen->fence.current, (struct nouveau_fence **)fence);
Christoph Bumiller4c224752010-11-12 15:17:40 +010044
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +020045 PUSH_KICK(nvc0->base.pushbuf); /* fencing handled in kick_notify */
Christoph Bumiller48a45ec2013-01-08 16:13:11 +010046
47 nouveau_context_update_frame_stats(&nvc0->base);
Christoph Bumiller4c224752010-11-12 15:17:40 +010048}
49
50static void
Christoph Bumiller83ff3802011-03-17 17:07:30 +010051nvc0_texture_barrier(struct pipe_context *pipe)
52{
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +020053 struct nouveau_pushbuf *push = nvc0_context(pipe)->base.pushbuf;
Christoph Bumiller83ff3802011-03-17 17:07:30 +010054
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +020055 IMMED_NVC0(push, NVC0_3D(SERIALIZE), 0);
56 IMMED_NVC0(push, NVC0_3D(TEX_CACHE_CTL), 0);
Christoph Bumiller83ff3802011-03-17 17:07:30 +010057}
58
59static void
Ilia Mirkin3df4d692014-04-30 16:45:16 -040060nvc0_memory_barrier(struct pipe_context *pipe, unsigned flags)
61{
62 struct nvc0_context *nvc0 = nvc0_context(pipe);
63 int i;
64
65 if (flags & PIPE_BARRIER_MAPPED_BUFFER) {
66 for (i = 0; i < nvc0->num_vtxbufs; ++i) {
67 if (!nvc0->vtxbuf[i].buffer)
68 continue;
69 if (nvc0->vtxbuf[i].buffer->flags & PIPE_RESOURCE_FLAG_MAP_PERSISTENT)
70 nvc0->base.vbo_dirty = TRUE;
71 }
72
73 if (nvc0->idxbuf.buffer &&
74 nvc0->idxbuf.buffer->flags & PIPE_RESOURCE_FLAG_MAP_PERSISTENT)
75 nvc0->base.vbo_dirty = TRUE;
76 }
77}
78
79static void
Christoph Bumiller26a199e2011-03-13 13:06:42 +010080nvc0_context_unreference_resources(struct nvc0_context *nvc0)
81{
82 unsigned s, i;
83
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +020084 nouveau_bufctx_del(&nvc0->bufctx_3d);
85 nouveau_bufctx_del(&nvc0->bufctx);
Christoph Bumillere066f2f2013-02-23 19:40:23 +010086 nouveau_bufctx_del(&nvc0->bufctx_cp);
Christoph Bumiller26a199e2011-03-13 13:06:42 +010087
Christoph Bumiller2d06ee82012-03-07 19:44:10 +010088 util_unreference_framebuffer_state(&nvc0->framebuffer);
89
Christoph Bumiller26a199e2011-03-13 13:06:42 +010090 for (i = 0; i < nvc0->num_vtxbufs; ++i)
91 pipe_resource_reference(&nvc0->vtxbuf[i].buffer, NULL);
92
93 pipe_resource_reference(&nvc0->idxbuf.buffer, NULL);
94
Christoph Bumillere066f2f2013-02-23 19:40:23 +010095 for (s = 0; s < 6; ++s) {
Christoph Bumiller26a199e2011-03-13 13:06:42 +010096 for (i = 0; i < nvc0->num_textures[s]; ++i)
97 pipe_sampler_view_reference(&nvc0->textures[s][i], NULL);
98
Christoph Bumillerfcb28682012-05-16 20:52:41 +020099 for (i = 0; i < NVC0_MAX_PIPE_CONSTBUFS; ++i)
100 if (!nvc0->constbuf[s][i].user)
101 pipe_resource_reference(&nvc0->constbuf[s][i].u.buf, NULL);
Christoph Bumiller26a199e2011-03-13 13:06:42 +0100102 }
103
Christoph Bumillere066f2f2013-02-23 19:40:23 +0100104 for (s = 0; s < 2; ++s) {
105 for (i = 0; i < NVC0_MAX_SURFACE_SLOTS; ++i)
106 pipe_surface_reference(&nvc0->surfaces[s][i], NULL);
107 }
108
Christoph Bumiller26a199e2011-03-13 13:06:42 +0100109 for (i = 0; i < nvc0->num_tfbbufs; ++i)
Christoph Bumiller14bd9d72011-12-09 18:46:09 +0100110 pipe_so_target_reference(&nvc0->tfbbuf[i], NULL);
Christoph Bumillere066f2f2013-02-23 19:40:23 +0100111
112 for (i = 0; i < nvc0->global_residents.size / sizeof(struct pipe_resource *);
113 ++i) {
114 struct pipe_resource **res = util_dynarray_element(
115 &nvc0->global_residents, struct pipe_resource *, i);
116 pipe_resource_reference(res, NULL);
117 }
118 util_dynarray_fini(&nvc0->global_residents);
Christoph Bumiller26a199e2011-03-13 13:06:42 +0100119}
120
121static void
Christoph Bumiller4c224752010-11-12 15:17:40 +0100122nvc0_destroy(struct pipe_context *pipe)
123{
124 struct nvc0_context *nvc0 = nvc0_context(pipe);
125
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200126 if (nvc0->screen->cur_ctx == nvc0) {
127 nvc0->base.pushbuf->kick_notify = NULL;
128 nvc0->screen->cur_ctx = NULL;
129 nouveau_pushbuf_bufctx(nvc0->base.pushbuf, NULL);
130 }
131 nouveau_pushbuf_kick(nvc0->base.pushbuf, nvc0->base.pushbuf->channel);
132
Christoph Bumiller26a199e2011-03-13 13:06:42 +0100133 nvc0_context_unreference_resources(nvc0);
Joakim Sindholt2a7762b2013-05-12 16:17:00 +0200134 nvc0_blitctx_destroy(nvc0);
Christoph Bumiller26a199e2011-03-13 13:06:42 +0100135
Christoph Bumillera48e5de2012-04-24 13:35:44 +0200136#ifdef NVC0_WITH_DRAW_MODULE
Christoph Bumiller4c224752010-11-12 15:17:40 +0100137 draw_destroy(nvc0->draw);
Christoph Bumillera48e5de2012-04-24 13:35:44 +0200138#endif
Christoph Bumiller4c224752010-11-12 15:17:40 +0100139
Marcin Slusarz17e04722012-06-05 23:26:05 +0200140 nouveau_context_destroy(&nvc0->base);
Christoph Bumiller4c224752010-11-12 15:17:40 +0100141}
142
Christoph Bumillera6ea37d2011-02-20 17:57:47 +0100143void
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200144nvc0_default_kick_notify(struct nouveau_pushbuf *push)
Christoph Bumillera6ea37d2011-02-20 17:57:47 +0100145{
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200146 struct nvc0_screen *screen = push->user_priv;
Christoph Bumillera6ea37d2011-02-20 17:57:47 +0100147
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200148 if (screen) {
149 nouveau_fence_next(&screen->base);
150 nouveau_fence_update(&screen->base, TRUE);
151 if (screen->cur_ctx)
152 screen->cur_ctx->state.flushed = TRUE;
153 }
Christoph Bumiller198f5142013-03-29 16:30:58 +0100154 NOUVEAU_DRV_STAT(&screen->base, pushbuf_count, 1);
Christoph Bumillera6ea37d2011-02-20 17:57:47 +0100155}
156
Christoph Bumiller48a45ec2013-01-08 16:13:11 +0100157static int
158nvc0_invalidate_resource_storage(struct nouveau_context *ctx,
159 struct pipe_resource *res,
160 int ref)
161{
162 struct nvc0_context *nvc0 = nvc0_context(&ctx->pipe);
163 unsigned s, i;
164
165 if (res->bind & PIPE_BIND_RENDER_TARGET) {
166 for (i = 0; i < nvc0->framebuffer.nr_cbufs; ++i) {
167 if (nvc0->framebuffer.cbufs[i] &&
168 nvc0->framebuffer.cbufs[i]->texture == res) {
169 nvc0->dirty |= NVC0_NEW_FRAMEBUFFER;
170 nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_FB);
171 if (!--ref)
172 return ref;
173 }
174 }
175 }
176 if (res->bind & PIPE_BIND_DEPTH_STENCIL) {
177 if (nvc0->framebuffer.zsbuf &&
178 nvc0->framebuffer.zsbuf->texture == res) {
179 nvc0->dirty |= NVC0_NEW_FRAMEBUFFER;
180 nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_FB);
181 if (!--ref)
182 return ref;
183 }
184 }
185
186 if (res->bind & PIPE_BIND_VERTEX_BUFFER) {
187 for (i = 0; i < nvc0->num_vtxbufs; ++i) {
188 if (nvc0->vtxbuf[i].buffer == res) {
189 nvc0->dirty |= NVC0_NEW_ARRAYS;
190 nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_VTX);
191 if (!--ref)
192 return ref;
193 }
194 }
195 }
196 if (res->bind & PIPE_BIND_INDEX_BUFFER) {
197 if (nvc0->idxbuf.buffer == res) {
198 nvc0->dirty |= NVC0_NEW_IDXBUF;
199 nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_IDX);
200 if (!--ref)
201 return ref;
202 }
203 }
204
205 if (res->bind & PIPE_BIND_SAMPLER_VIEW) {
206 for (s = 0; s < 5; ++s) {
207 for (i = 0; i < nvc0->num_textures[s]; ++i) {
208 if (nvc0->textures[s][i] &&
209 nvc0->textures[s][i]->texture == res) {
210 nvc0->textures_dirty[s] |= 1 << i;
211 nvc0->dirty |= NVC0_NEW_TEXTURES;
212 nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_TEX(s, i));
213 if (!--ref)
214 return ref;
215 }
216 }
217 }
218 }
219
220 if (res->bind & PIPE_BIND_CONSTANT_BUFFER) {
221 for (s = 0; s < 5; ++s) {
222 for (i = 0; i < nvc0->num_vtxbufs; ++i) {
223 if (!nvc0->constbuf[s][i].user &&
224 nvc0->constbuf[s][i].u.buf == res) {
225 nvc0->dirty |= NVC0_NEW_CONSTBUF;
226 nvc0->constbuf_dirty[s] |= 1 << i;
227 nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_CB(s, i));
228 if (!--ref)
229 return ref;
230 }
231 }
232 }
233 }
234
235 return ref;
236}
237
Christoph Bumiller4da54c92013-04-06 14:52:05 +0200238static void
239nvc0_context_get_sample_position(struct pipe_context *, unsigned, unsigned,
240 float *);
241
Christoph Bumiller4c224752010-11-12 15:17:40 +0100242struct pipe_context *
243nvc0_create(struct pipe_screen *pscreen, void *priv)
244{
Christoph Bumiller4c224752010-11-12 15:17:40 +0100245 struct nvc0_screen *screen = nvc0_screen(pscreen);
246 struct nvc0_context *nvc0;
Ben Skeggs1ba8e952011-03-01 15:28:26 +1000247 struct pipe_context *pipe;
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200248 int ret;
249 uint32_t flags;
Christoph Bumiller4c224752010-11-12 15:17:40 +0100250
251 nvc0 = CALLOC_STRUCT(nvc0_context);
252 if (!nvc0)
253 return NULL;
Ben Skeggs1ba8e952011-03-01 15:28:26 +1000254 pipe = &nvc0->base.pipe;
255
Christoph Bumiller36ea7442012-09-26 23:06:40 +0200256 if (!nvc0_blitctx_create(nvc0))
257 goto out_err;
258
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200259 nvc0->base.pushbuf = screen->base.pushbuf;
Christoph Bumiller48a45ec2013-01-08 16:13:11 +0100260 nvc0->base.client = screen->base.client;
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200261
Christoph Bumillere066f2f2013-02-23 19:40:23 +0100262 ret = nouveau_bufctx_new(screen->base.client, 2, &nvc0->bufctx);
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200263 if (!ret)
Christoph Bumillere066f2f2013-02-23 19:40:23 +0100264 ret = nouveau_bufctx_new(screen->base.client, NVC0_BIND_3D_COUNT,
265 &nvc0->bufctx_3d);
266 if (!ret)
267 ret = nouveau_bufctx_new(screen->base.client, NVC0_BIND_CP_COUNT,
268 &nvc0->bufctx_cp);
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200269 if (ret)
270 goto out_err;
271
Christoph Bumiller4c224752010-11-12 15:17:40 +0100272 nvc0->screen = screen;
Christoph Bumillere44089b2012-04-14 23:56:56 +0200273 nvc0->base.screen = &screen->base;
Christoph Bumiller4c224752010-11-12 15:17:40 +0100274
Ben Skeggs1ba8e952011-03-01 15:28:26 +1000275 pipe->screen = pscreen;
276 pipe->priv = priv;
Christoph Bumiller4c224752010-11-12 15:17:40 +0100277
Ben Skeggs1ba8e952011-03-01 15:28:26 +1000278 pipe->destroy = nvc0_destroy;
Christoph Bumiller4c224752010-11-12 15:17:40 +0100279
Ben Skeggs1ba8e952011-03-01 15:28:26 +1000280 pipe->draw_vbo = nvc0_draw_vbo;
281 pipe->clear = nvc0_clear;
Samuel Pitoiset9dcd7882013-07-25 10:35:35 +0200282 pipe->launch_grid = (nvc0->screen->base.class_3d >= NVE4_3D_CLASS) ?
283 nve4_launch_grid : nvc0_launch_grid;
Christoph Bumiller4c224752010-11-12 15:17:40 +0100284
Ben Skeggs1ba8e952011-03-01 15:28:26 +1000285 pipe->flush = nvc0_flush;
Christoph Bumiller83ff3802011-03-17 17:07:30 +0100286 pipe->texture_barrier = nvc0_texture_barrier;
Ilia Mirkin3df4d692014-04-30 16:45:16 -0400287 pipe->memory_barrier = nvc0_memory_barrier;
Christoph Bumiller4da54c92013-04-06 14:52:05 +0200288 pipe->get_sample_position = nvc0_context_get_sample_position;
Christoph Bumiller4c224752010-11-12 15:17:40 +0100289
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200290 if (!screen->cur_ctx) {
Ben Skeggs48e191f2011-03-01 14:37:06 +1000291 screen->cur_ctx = nvc0;
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200292 nouveau_pushbuf_bufctx(screen->base.pushbuf, nvc0->bufctx);
293 }
294 screen->base.pushbuf->kick_notify = nvc0_default_kick_notify;
Christoph Bumiller4c224752010-11-12 15:17:40 +0100295
Christoph Bumillerb3d8e1f2011-01-09 21:50:06 +0100296 nvc0_init_query_functions(nvc0);
Christoph Bumiller4c224752010-11-12 15:17:40 +0100297 nvc0_init_surface_functions(nvc0);
298 nvc0_init_state_functions(nvc0);
Christoph Bumillere44089b2012-04-14 23:56:56 +0200299 nvc0_init_transfer_functions(nvc0);
Ben Skeggs1ba8e952011-03-01 15:28:26 +1000300 nvc0_init_resource_functions(pipe);
Christoph Bumiller4c224752010-11-12 15:17:40 +0100301
Christoph Bumiller48a45ec2013-01-08 16:13:11 +0100302 nvc0->base.invalidate_resource_storage = nvc0_invalidate_resource_storage;
303
Christoph Bumillera48e5de2012-04-24 13:35:44 +0200304#ifdef NVC0_WITH_DRAW_MODULE
305 /* no software fallbacks implemented */
Ben Skeggs1ba8e952011-03-01 15:28:26 +1000306 nvc0->draw = draw_create(pipe);
Christoph Bumiller4c224752010-11-12 15:17:40 +0100307 assert(nvc0->draw);
308 draw_set_rasterize_stage(nvc0->draw, nvc0_draw_render_stage(nvc0));
Christoph Bumillera48e5de2012-04-24 13:35:44 +0200309#endif
Christoph Bumiller4c224752010-11-12 15:17:40 +0100310
Christian Königf2f70642013-07-15 03:48:04 -0600311 pipe->create_video_codec = nvc0_create_decoder;
Maarten Lankhorst4fad2112012-12-02 12:07:35 +0100312 pipe->create_video_buffer = nvc0_video_buffer_create;
Christoph Bumillerea316c52011-07-21 10:39:41 +0200313
Christoph Bumiller3afabfb2011-09-13 23:10:35 +0200314 /* shader builtin library is per-screen, but we need a context for m2mf */
315 nvc0_program_library_upload(nvc0);
316
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200317 /* add permanently resident buffers to bufctxts */
318
319 flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_RD;
320
321 BCTX_REFN_bo(nvc0->bufctx_3d, SCREEN, flags, screen->text);
Christoph Bumillere44089b2012-04-14 23:56:56 +0200322 BCTX_REFN_bo(nvc0->bufctx_3d, SCREEN, flags, screen->uniform_bo);
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200323 BCTX_REFN_bo(nvc0->bufctx_3d, SCREEN, flags, screen->txc);
Christoph Bumillere066f2f2013-02-23 19:40:23 +0100324 if (screen->compute) {
325 BCTX_REFN_bo(nvc0->bufctx_cp, CP_SCREEN, flags, screen->text);
326 BCTX_REFN_bo(nvc0->bufctx_cp, CP_SCREEN, flags, screen->txc);
327 BCTX_REFN_bo(nvc0->bufctx_cp, CP_SCREEN, flags, screen->parm);
328 }
329
330 flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR;
331
Ben Skeggsd53bbab2012-10-08 09:13:46 +1000332 BCTX_REFN_bo(nvc0->bufctx_3d, SCREEN, flags, screen->poly_cache);
Christoph Bumillere066f2f2013-02-23 19:40:23 +0100333 if (screen->compute)
334 BCTX_REFN_bo(nvc0->bufctx_cp, CP_SCREEN, flags, screen->tls);
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200335
336 flags = NOUVEAU_BO_GART | NOUVEAU_BO_WR;
337
338 BCTX_REFN_bo(nvc0->bufctx_3d, SCREEN, flags, screen->fence.bo);
339 BCTX_REFN_bo(nvc0->bufctx, FENCE, flags, screen->fence.bo);
Christoph Bumillere066f2f2013-02-23 19:40:23 +0100340 if (screen->compute)
341 BCTX_REFN_bo(nvc0->bufctx_cp, CP_SCREEN, flags, screen->fence.bo);
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200342
Christoph Bumiller2206a7f2012-03-01 21:28:29 +0100343 nvc0->base.scratch.bo_size = 2 << 20;
344
Christoph Bumillerc321b1b2012-07-11 20:52:58 +0200345 memset(nvc0->tex_handles, ~0, sizeof(nvc0->tex_handles));
346
Christoph Bumillere066f2f2013-02-23 19:40:23 +0100347 util_dynarray_init(&nvc0->global_residents);
348
Ben Skeggs1ba8e952011-03-01 15:28:26 +1000349 return pipe;
Christoph Bumiller4c224752010-11-12 15:17:40 +0100350
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200351out_err:
352 if (nvc0) {
353 if (nvc0->bufctx_3d)
354 nouveau_bufctx_del(&nvc0->bufctx_3d);
Christoph Bumillere066f2f2013-02-23 19:40:23 +0100355 if (nvc0->bufctx_cp)
356 nouveau_bufctx_del(&nvc0->bufctx_cp);
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200357 if (nvc0->bufctx)
358 nouveau_bufctx_del(&nvc0->bufctx);
Christoph Bumiller36ea7442012-09-26 23:06:40 +0200359 if (nvc0->blit)
360 FREE(nvc0->blit);
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200361 FREE(nvc0);
Christoph Bumiller4c224752010-11-12 15:17:40 +0100362 }
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200363 return NULL;
Christoph Bumiller4c224752010-11-12 15:17:40 +0100364}
365
366void
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200367nvc0_bufctx_fence(struct nvc0_context *nvc0, struct nouveau_bufctx *bufctx,
368 boolean on_flush)
Christoph Bumiller4c224752010-11-12 15:17:40 +0100369{
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200370 struct nouveau_list *list = on_flush ? &bufctx->current : &bufctx->pending;
371 struct nouveau_list *it;
Christoph Bumiller198f5142013-03-29 16:30:58 +0100372 NOUVEAU_DRV_STAT_IFD(unsigned count = 0);
Christoph Bumiller4c224752010-11-12 15:17:40 +0100373
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200374 for (it = list->next; it != list; it = it->next) {
375 struct nouveau_bufref *ref = (struct nouveau_bufref *)it;
376 struct nv04_resource *res = ref->priv;
377 if (res)
378 nvc0_resource_validate(res, (unsigned)ref->priv_data);
Christoph Bumiller198f5142013-03-29 16:30:58 +0100379 NOUVEAU_DRV_STAT_IFD(count++);
Christoph Bumiller4c224752010-11-12 15:17:40 +0100380 }
Christoph Bumiller198f5142013-03-29 16:30:58 +0100381 NOUVEAU_DRV_STAT(&nvc0->screen->base, resource_validate_count, count);
Christoph Bumiller4c224752010-11-12 15:17:40 +0100382}
Christoph Bumiller4da54c92013-04-06 14:52:05 +0200383
384static void
385nvc0_context_get_sample_position(struct pipe_context *pipe,
386 unsigned sample_count, unsigned sample_index,
387 float *xy)
388{
389 static const uint8_t ms1[1][2] = { { 0x8, 0x8 } };
390 static const uint8_t ms2[2][2] = {
391 { 0x4, 0x4 }, { 0xc, 0xc } }; /* surface coords (0,0), (1,0) */
392 static const uint8_t ms4[4][2] = {
393 { 0x6, 0x2 }, { 0xe, 0x6 }, /* (0,0), (1,0) */
394 { 0x2, 0xa }, { 0xa, 0xe } }; /* (0,1), (1,1) */
395 static const uint8_t ms8[8][2] = {
396 { 0x1, 0x7 }, { 0x5, 0x3 }, /* (0,0), (1,0) */
397 { 0x3, 0xd }, { 0x7, 0xb }, /* (0,1), (1,1) */
398 { 0x9, 0x5 }, { 0xf, 0x1 }, /* (2,0), (3,0) */
399 { 0xb, 0xf }, { 0xd, 0x9 } }; /* (2,1), (3,1) */
400#if 0
401 /* NOTE: there are alternative modes for MS2 and MS8, currently not used */
402 static const uint8_t ms8_alt[8][2] = {
403 { 0x9, 0x5 }, { 0x7, 0xb }, /* (2,0), (1,1) */
404 { 0xd, 0x9 }, { 0x5, 0x3 }, /* (3,1), (1,0) */
405 { 0x3, 0xd }, { 0x1, 0x7 }, /* (0,1), (0,0) */
406 { 0xb, 0xf }, { 0xf, 0x1 } }; /* (2,1), (3,0) */
407#endif
408
409 const uint8_t (*ptr)[2];
410
411 switch (sample_count) {
412 case 0:
413 case 1: ptr = ms1; break;
414 case 2: ptr = ms2; break;
415 case 4: ptr = ms4; break;
416 case 8: ptr = ms8; break;
417 default:
418 assert(0);
Christoph Bumiller2daf9742013-08-06 22:20:25 +0200419 return; /* bad sample count -> undefined locations */
Christoph Bumiller4da54c92013-04-06 14:52:05 +0200420 }
421 xy[0] = ptr[sample_index][0] * 0.0625f;
422 xy[1] = ptr[sample_index][1] * 0.0625f;
423}