Debian Codegraph @

src/gallium/drivers/nouveau/nvc0/nvc0_context.c

raw
1 /*
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
17 * 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.
21 */
22
23 #include "pipe/p_defines.h"
24 #include "util/u_framebuffer.h"
25 #include "util/u_upload_mgr.h"
26
27 #include "nvc0/nvc0_context.h"
28 #include "nvc0/nvc0_screen.h"
29 #include "nvc0/nvc0_resource.h"
30
31
32 #include "xf86drm.h"
33 #include "drm-uapi/nouveau_drm.h"
34
35
36 static void
37 nvc0_svm_migrate(struct pipe_context *pipe, unsigned num_ptrs,
38 const void* const* ptrs, const size_t *sizes,
39 bool to_device, bool mem_undefined)
40 {
41 struct nvc0_context *nvc0 = nvc0_context(pipe);
42 struct nouveau_screen *screen = &nvc0->screen->base;
43 int fd = screen->drm->fd;
44 unsigned i;
45
46 for (i = 0; i < num_ptrs; i++) {
47 struct drm_nouveau_svm_bind args;
48 uint64_t cmd, prio, target;
49
50 args.va_start = (uint64_t)(uintptr_t)ptrs[i];
51 if (sizes && sizes[i]) {
52 args.va_end = (uint64_t)(uintptr_t)ptrs[i] + sizes[i];
53 args.npages = DIV_ROUND_UP(args.va_end - args.va_start, 0x1000);
54 } else {
55 args.va_end = 0;
56 args.npages = 0;
57 }
58 args.stride = 0;
59
60 args.reserved0 = 0;
61 args.reserved1 = 0;
62
63 prio = 0;
64 cmd = NOUVEAU_SVM_BIND_COMMAND__MIGRATE;
65 target = to_device ? NOUVEAU_SVM_BIND_TARGET__GPU_VRAM : 0;
66
67 args.header = cmd << NOUVEAU_SVM_BIND_COMMAND_SHIFT;
68 args.header |= prio << NOUVEAU_SVM_BIND_PRIORITY_SHIFT;
69 args.header |= target << NOUVEAU_SVM_BIND_TARGET_SHIFT;
70
71 /* This is best effort, so no garanty whatsoever */
72 drmCommandWrite(fd, DRM_NOUVEAU_SVM_BIND,
73 &args, sizeof(args));
74 }
75 }
76
77
78 static void
79 nvc0_flush(struct pipe_context *pipe,
80 struct pipe_fence_handle **fence,
81 unsigned flags)
82 {
83 struct nvc0_context *nvc0 = nvc0_context(pipe);
84
85 if (fence)
86 nouveau_fence_ref(nvc0->base.fence, (struct nouveau_fence **)fence,
87 nvc0->base.screen);
88
89 PUSH_KICK(nvc0->base.pushbuf); /* fencing handled in kick_notify */
90
91 nouveau_context_update_frame_stats(&nvc0->base);
92 }
93
94 static void
95 nvc0_texture_barrier(struct pipe_context *pipe, unsigned flags)
96 {
97 struct nouveau_pushbuf *push = nvc0_context(pipe)->base.pushbuf;
98
99 IMMED_NVC0(push, NVC0_3D(SERIALIZE), 0);
100 IMMED_NVC0(push, NVC0_3D(TEX_CACHE_CTL), 0);
101 }
102
103 static void
104 nvc0_memory_barrier(struct pipe_context *pipe, unsigned flags)
105 {
106 struct nvc0_context *nvc0 = nvc0_context(pipe);
107 struct nouveau_pushbuf *push = nvc0->base.pushbuf;
108 int i, s;
109
110 if (!(flags & ~PIPE_BARRIER_UPDATE))
111 return;
112
113 if (flags & PIPE_BARRIER_MAPPED_BUFFER) {
114 for (i = 0; i < nvc0->num_vtxbufs; ++i) {
115 if (!nvc0->vtxbuf[i].buffer.resource && !nvc0->vtxbuf[i].is_user_buffer)
116 continue;
117 if (nvc0->vtxbuf[i].buffer.resource->flags & PIPE_RESOURCE_FLAG_MAP_PERSISTENT)
118 nvc0->base.vbo_dirty = true;
119 }
120
121 for (s = 0; s < 5 && !nvc0->cb_dirty; ++s) {
122 uint32_t valid = nvc0->constbuf_valid[s];
123
124 while (valid && !nvc0->cb_dirty) {
125 const unsigned i = ffs(valid) - 1;
126 struct pipe_resource *res;
127
128 valid &= ~(1 << i);
129 if (nvc0->constbuf[s][i].user)
130 continue;
131
132 res = nvc0->constbuf[s][i].u.buf;
133 if (!res)
134 continue;
135
136 if (res->flags & PIPE_RESOURCE_FLAG_MAP_PERSISTENT)
137 nvc0->cb_dirty = true;
138 }
139 }
140 } else {
141 /* Pretty much any writing by shaders needs a serialize after
142 * it. Especially when moving between 3d and compute pipelines, but even
143 * without that.
144 */
145 IMMED_NVC0(push, NVC0_3D(SERIALIZE), 0);
146 }
147
148 /* If we're going to texture from a buffer/image written by a shader, we
149 * must flush the texture cache.
150 */
151 if (flags & PIPE_BARRIER_TEXTURE)
152 IMMED_NVC0(push, NVC0_3D(TEX_CACHE_CTL), 0);
153
154 if (flags & PIPE_BARRIER_CONSTANT_BUFFER)
155 nvc0->cb_dirty = true;
156 if (flags & (PIPE_BARRIER_VERTEX_BUFFER | PIPE_BARRIER_INDEX_BUFFER))
157 nvc0->base.vbo_dirty = true;
158 }
159
160 static void
161 nvc0_emit_string_marker(struct pipe_context *pipe, const char *str, int len)
162 {
163 struct nouveau_pushbuf *push = nvc0_context(pipe)->base.pushbuf;
164 int string_words = len / 4;
165 int data_words;
166
167 if (len <= 0)
168 return;
169 string_words = MIN2(string_words, NV04_PFIFO_MAX_PACKET_LEN);
170 if (string_words == NV04_PFIFO_MAX_PACKET_LEN)
171 data_words = string_words;
172 else
173 data_words = string_words + !!(len & 3);
174 BEGIN_NIC0(push, SUBC_3D(NV04_GRAPH_NOP), data_words);
175 if (string_words)
176 PUSH_DATAp(push, str, string_words);
177 if (string_words != data_words) {
178 int data = 0;
179 memcpy(&data, &str[string_words * 4], len & 3);
180 PUSH_DATA (push, data);
181 }
182 }
183
184 static enum pipe_reset_status
185 nvc0_get_device_reset_status(struct pipe_context *pipe)
186 {
187 return PIPE_NO_RESET;
188 }
189
190 static void
191 nvc0_context_unreference_resources(struct nvc0_context *nvc0)
192 {
193 unsigned s, i;
194
195 nouveau_bufctx_del(&nvc0->bufctx_3d);
196 nouveau_bufctx_del(&nvc0->bufctx);
197 nouveau_bufctx_del(&nvc0->bufctx_cp);
198
199 nvc0_framebuffer_init(&nvc0->base.pipe, NULL, nvc0->fb_cbufs, &nvc0->fb_zsbuf);
200 util_unreference_framebuffer_state(&nvc0->framebuffer);
201
202 for (i = 0; i < nvc0->num_vtxbufs; ++i)
203 pipe_vertex_buffer_unreference(&nvc0->vtxbuf[i]);
204
205 for (s = 0; s < 6; ++s) {
206 for (i = 0; i < nvc0->num_textures[s]; ++i)
207 pipe_sampler_view_reference(&nvc0->textures[s][i], NULL);
208
209 for (i = 0; i < NVC0_MAX_PIPE_CONSTBUFS; ++i)
210 if (!nvc0->constbuf[s][i].user)
211 pipe_resource_reference(&nvc0->constbuf[s][i].u.buf, NULL);
212
213 for (i = 0; i < NVC0_MAX_BUFFERS; ++i)
214 pipe_resource_reference(&nvc0->buffers[s][i].buffer, NULL);
215
216 for (i = 0; i < NVC0_MAX_IMAGES; ++i) {
217 pipe_resource_reference(&nvc0->images[s][i].resource, NULL);
218 if (nvc0->screen->base.class_3d >= GM107_3D_CLASS)
219 pipe_sampler_view_reference(&nvc0->images_tic[s][i], NULL);
220 }
221 }
222
223 for (i = 0; i < nvc0->num_tfbbufs; ++i)
224 pipe_so_target_reference(&nvc0->tfbbuf[i], NULL);
225
226 for (i = 0; i < nvc0->global_residents.size / sizeof(struct pipe_resource *);
227 ++i) {
228 struct pipe_resource **res = util_dynarray_element(
229 &nvc0->global_residents, struct pipe_resource *, i);
230 pipe_resource_reference(res, NULL);
231 }
232 util_dynarray_fini(&nvc0->global_residents);
233
234 if (nvc0->tcp_empty)
235 nvc0->base.pipe.delete_tcs_state(&nvc0->base.pipe, nvc0->tcp_empty);
236 }
237
238 static void
239 nvc0_destroy(struct pipe_context *pipe)
240 {
241 struct nvc0_context *nvc0 = nvc0_context(pipe);
242
243 simple_mtx_lock(&nvc0->screen->state_lock);
244 if (nvc0->screen->cur_ctx == nvc0) {
245 nvc0->screen->cur_ctx = NULL;
246 nvc0->screen->save_state = nvc0->state;
247 nvc0->screen->save_state.tfb = NULL;
248 }
249 simple_mtx_unlock(&nvc0->screen->state_lock);
250
251 if (nvc0->base.pipe.stream_uploader)
252 u_upload_destroy(nvc0->base.pipe.stream_uploader);
253
254 /* Unset bufctx, we don't want to revalidate any resources after the flush.
255 * Other contexts will always set their bufctx again on action calls.
256 */
257 nouveau_pushbuf_bufctx(nvc0->base.pushbuf, NULL);
258 PUSH_KICK(nvc0->base.pushbuf);
259
260 nvc0_context_unreference_resources(nvc0);
261 nvc0_blitctx_destroy(nvc0);
262
263 list_for_each_entry_safe(struct nvc0_resident, pos, &nvc0->tex_head, list) {
264 list_del(&pos->list);
265 free(pos);
266 }
267
268 list_for_each_entry_safe(struct nvc0_resident, pos, &nvc0->img_head, list) {
269 list_del(&pos->list);
270 free(pos);
271 }
272
273 nouveau_fence_cleanup(&nvc0->base);
274 nouveau_context_destroy(&nvc0->base);
275 }
276
277 void
278 nvc0_default_kick_notify(struct nouveau_context *context)
279 {
280 struct nvc0_context *nvc0 = nvc0_context(&context->pipe);
281
282 _nouveau_fence_next(context);
283 _nouveau_fence_update(context->screen, true);
284
285 nvc0->state.flushed = true;
286 }
287
288 static int
289 nvc0_invalidate_resource_storage(struct nouveau_context *ctx,
290 struct pipe_resource *res,
291 int ref)
292 {
293 struct nvc0_context *nvc0 = nvc0_context(&ctx->pipe);
294 unsigned s, i;
295
296 if (res->bind & PIPE_BIND_RENDER_TARGET) {
297 for (i = 0; i < nvc0->framebuffer.nr_cbufs; ++i) {
298 if (nvc0->framebuffer.cbufs[i].texture == res) {
299 nvc0->dirty_3d |= NVC0_NEW_3D_FRAMEBUFFER;
300 nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_FB);
301 if (!--ref)
302 return ref;
303 }
304 }
305 }
306 if (res->bind & PIPE_BIND_DEPTH_STENCIL) {
307 if (nvc0->framebuffer.zsbuf.texture == res) {
308 nvc0->dirty_3d |= NVC0_NEW_3D_FRAMEBUFFER;
309 nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_FB);
310 if (!--ref)
311 return ref;
312 }
313 }
314
315 if (res->target == PIPE_BUFFER) {
316 for (i = 0; i < nvc0->num_vtxbufs; ++i) {
317 if (nvc0->vtxbuf[i].buffer.resource == res) {
318 nvc0->dirty_3d |= NVC0_NEW_3D_ARRAYS;
319 nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_VTX);
320 if (!--ref)
321 return ref;
322 }
323 }
324
325 for (s = 0; s < 6; ++s) {
326 for (i = 0; i < nvc0->num_textures[s]; ++i) {
327 if (nvc0->textures[s][i] &&
328 nvc0->textures[s][i]->texture == res) {
329 nvc0->textures_dirty[s] |= 1 << i;
330 if (unlikely(s == 5)) {
331 nvc0->dirty_cp |= NVC0_NEW_CP_TEXTURES;
332 nouveau_bufctx_reset(nvc0->bufctx_cp, NVC0_BIND_CP_TEX(i));
333 } else {
334 nvc0->dirty_3d |= NVC0_NEW_3D_TEXTURES;
335 nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_TEX(s, i));
336 }
337 if (!--ref)
338 return ref;
339 }
340 }
341 }
342
343 for (s = 0; s < 6; ++s) {
344 for (i = 0; i < NVC0_MAX_PIPE_CONSTBUFS; ++i) {
345 if (!(nvc0->constbuf_valid[s] & (1 << i)))
346 continue;
347 if (!nvc0->constbuf[s][i].user &&
348 nvc0->constbuf[s][i].u.buf == res) {
349 nvc0->constbuf_dirty[s] |= 1 << i;
350 if (unlikely(s == 5)) {
351 nvc0->dirty_cp |= NVC0_NEW_CP_CONSTBUF;
352 nouveau_bufctx_reset(nvc0->bufctx_cp, NVC0_BIND_CP_CB(i));
353 } else {
354 nvc0->dirty_3d |= NVC0_NEW_3D_CONSTBUF;
355 nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_CB(s, i));
356 }
357 if (!--ref)
358 return ref;
359 }
360 }
361 }
362
363 for (s = 0; s < 6; ++s) {
364 for (i = 0; i < NVC0_MAX_BUFFERS; ++i) {
365 if (nvc0->buffers[s][i].buffer == res) {
366 nvc0->buffers_dirty[s] |= 1 << i;
367 if (unlikely(s == 5)) {
368 nvc0->dirty_cp |= NVC0_NEW_CP_BUFFERS;
369 nouveau_bufctx_reset(nvc0->bufctx_cp, NVC0_BIND_CP_BUF);
370 } else {
371 nvc0->dirty_3d |= NVC0_NEW_3D_BUFFERS;
372 nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_BUF);
373 }
374 if (!--ref)
375 return ref;
376 }
377 }
378 }
379
380 for (s = 0; s < 6; ++s) {
381 for (i = 0; i < NVC0_MAX_IMAGES; ++i) {
382 if (nvc0->images[s][i].resource == res) {
383 nvc0->images_dirty[s] |= 1 << i;
384 if (unlikely(s == 5)) {
385 nvc0->dirty_cp |= NVC0_NEW_CP_SURFACES;
386 nouveau_bufctx_reset(nvc0->bufctx_cp, NVC0_BIND_CP_SUF);
387 } else {
388 nvc0->dirty_3d |= NVC0_NEW_3D_SURFACES;
389 nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_SUF);
390 }
391 }
392 if (!--ref)
393 return ref;
394 }
395 }
396 }
397
398 return ref;
399 }
400
401 static void
402 nvc0_context_get_sample_position(struct pipe_context *, unsigned, unsigned,
403 float *);
404
405 struct pipe_context *
406 nvc0_create(struct pipe_screen *pscreen, void *priv, unsigned ctxflags)
407 {
408 struct nvc0_screen *screen = nvc0_screen(pscreen);
409 struct nvc0_context *nvc0;
410 struct pipe_context *pipe;
411 int ret;
412 uint32_t flags;
413
414 nvc0 = CALLOC_STRUCT(nvc0_context);
415 if (!nvc0)
416 return NULL;
417 pipe = &nvc0->base.pipe;
418
419 if (!nvc0_blitctx_create(nvc0))
420 goto out_err;
421
422 if (nouveau_context_init(&nvc0->base, &screen->base))
423 goto out_err;
424 nvc0->base.kick_notify = nvc0_default_kick_notify;
425 nvc0->base.pushbuf->rsvd_kick = 5;
426
427 ret = nouveau_bufctx_new(nvc0->base.client, 2, &nvc0->bufctx);
428 if (!ret)
429 ret = nouveau_bufctx_new(nvc0->base.client, NVC0_BIND_3D_COUNT,
430 &nvc0->bufctx_3d);
431 if (!ret)
432 ret = nouveau_bufctx_new(nvc0->base.client, NVC0_BIND_CP_COUNT,
433 &nvc0->bufctx_cp);
434 if (ret)
435 goto out_err;
436
437 nvc0->screen = screen;
438 pipe->screen = pscreen;
439 pipe->priv = priv;
440 pipe->stream_uploader = u_upload_create_default(pipe);
441 if (!pipe->stream_uploader)
442 goto out_err;
443 pipe->const_uploader = pipe->stream_uploader;
444
445 pipe->destroy = nvc0_destroy;
446
447 pipe->draw_vbo = nvc0_draw_vbo;
448 pipe->clear = nvc0_clear;
449 pipe->launch_grid = (nvc0->screen->base.class_3d >= NVE4_3D_CLASS) ?
450 nve4_launch_grid : nvc0_launch_grid;
451
452 pipe->svm_migrate = nvc0_svm_migrate;
453
454 pipe->flush = nvc0_flush;
455 pipe->texture_barrier = nvc0_texture_barrier;
456 pipe->memory_barrier = nvc0_memory_barrier;
457 pipe->get_sample_position = nvc0_context_get_sample_position;
458 pipe->emit_string_marker = nvc0_emit_string_marker;
459 pipe->get_device_reset_status = nvc0_get_device_reset_status;
460
461 nvc0_init_query_functions(nvc0);
462 nvc0_init_surface_functions(nvc0);
463 nvc0_init_state_functions(nvc0);
464 nvc0_init_transfer_functions(nvc0);
465 nvc0_init_resource_functions(pipe);
466 if (nvc0->screen->base.class_3d >= NVE4_3D_CLASS)
467 nvc0_init_bindless_functions(pipe);
468
469 list_inithead(&nvc0->tex_head);
470 list_inithead(&nvc0->img_head);
471
472 nvc0->base.invalidate_resource_storage = nvc0_invalidate_resource_storage;
473
474 pipe->create_video_codec = nvc0_create_decoder;
475 pipe->create_video_buffer = nvc0_video_buffer_create;
476
477 /* shader builtin library is per-screen, but we need a context for m2mf */
478 nvc0_program_library_upload(nvc0);
479 nvc0_program_init_tcp_empty(nvc0);
480 if (!nvc0->tcp_empty)
481 goto out_err;
482 /* set the empty tctl prog on next draw in case one is never set */
483 nvc0->dirty_3d |= NVC0_NEW_3D_TCTLPROG;
484
485 /* Do not bind the COMPUTE driver constbuf at screen initialization because
486 * CBs are aliased between 3D and COMPUTE, but make sure it will be bound if
487 * a grid is launched later. */
488 nvc0->dirty_cp |= NVC0_NEW_CP_DRIVERCONST;
489
490 /* now that there are no more opportunities for errors, set the current
491 * context if there isn't already one.
492 */
493 simple_mtx_lock(&screen->state_lock);
494 if (!screen->cur_ctx) {
495 nvc0->state = screen->save_state;
496 screen->cur_ctx = nvc0;
497 }
498 simple_mtx_unlock(&screen->state_lock);
499
500 nouveau_pushbuf_bufctx(nvc0->base.pushbuf, nvc0->bufctx);
501 PUSH_SPACE(nvc0->base.pushbuf, 8);
502
503 /* add permanently resident buffers to bufctxts */
504
505 flags = NV_VRAM_DOMAIN(&screen->base) | NOUVEAU_BO_RD;
506
507 BCTX_REFN_bo(nvc0->bufctx_3d, 3D_SCREEN, flags, screen->uniform_bo);
508 BCTX_REFN_bo(nvc0->bufctx_3d, 3D_SCREEN, flags, screen->txc);
509 if (screen->compute) {
510 BCTX_REFN_bo(nvc0->bufctx_cp, CP_SCREEN, flags, screen->uniform_bo);
511 BCTX_REFN_bo(nvc0->bufctx_cp, CP_SCREEN, flags, screen->txc);
512 }
513
514 flags = NV_VRAM_DOMAIN(&screen->base) | NOUVEAU_BO_RDWR;
515
516 if (screen->poly_cache)
517 BCTX_REFN_bo(nvc0->bufctx_3d, 3D_SCREEN, flags, screen->poly_cache);
518 if (screen->compute)
519 BCTX_REFN_bo(nvc0->bufctx_cp, CP_SCREEN, flags, screen->tls);
520
521 flags = NOUVEAU_BO_GART | NOUVEAU_BO_WR;
522
523 BCTX_REFN_bo(nvc0->bufctx_3d, 3D_SCREEN, flags, screen->fence.bo);
524 BCTX_REFN_bo(nvc0->bufctx, FENCE, flags, screen->fence.bo);
525 if (screen->compute)
526 BCTX_REFN_bo(nvc0->bufctx_cp, CP_SCREEN, flags, screen->fence.bo);
527
528 nvc0->base.scratch.bo_size = 2 << 20;
529
530 memset(nvc0->tex_handles, ~0, sizeof(nvc0->tex_handles));
531
532 nvc0->global_residents = UTIL_DYNARRAY_INIT;
533
534 // Make sure that the first TSC entry has SRGB conversion bit set, since we
535 // use it as a fallback on Fermi for TXF, and on Kepler+ generations for
536 // FBFETCH handling (which also uses TXF).
537 //
538 // NOTE: Preliminary testing suggests that this isn't necessary at all at
539 // least on GM20x (untested on Kepler). However this is ~free, so no reason
540 // not to do it.
541 if (!screen->tsc.entries[0])
542 nvc0_upload_tsc0(nvc0);
543
544 // On Fermi, mark samplers dirty so that the proper binding can happen
545 if (screen->base.class_3d < NVE4_3D_CLASS) {
546 for (int s = 0; s < 6; s++)
547 nvc0->samplers_dirty[s] = 1;
548 nvc0->dirty_3d |= NVC0_NEW_3D_SAMPLERS;
549 nvc0->dirty_cp |= NVC0_NEW_CP_SAMPLERS;
550 }
551
552 nouveau_fence_new(&nvc0->base, &nvc0->base.fence);
553
554 return pipe;
555
556 out_err:
557 if (nvc0) {
558 if (pipe->stream_uploader)
559 u_upload_destroy(pipe->stream_uploader);
560 if (nvc0->bufctx_3d)
561 nouveau_bufctx_del(&nvc0->bufctx_3d);
562 if (nvc0->bufctx_cp)
563 nouveau_bufctx_del(&nvc0->bufctx_cp);
564 if (nvc0->bufctx)
565 nouveau_bufctx_del(&nvc0->bufctx);
566 FREE(nvc0->blit);
567 FREE(nvc0);
568 }
569 return NULL;
570 }
571
572 void
573 nvc0_bufctx_fence(struct nvc0_context *nvc0, struct nouveau_bufctx *bufctx,
574 bool on_flush)
575 {
576 struct list_head *list = on_flush ? &bufctx->current : &bufctx->pending;
577 struct list_head *it;
578 NOUVEAU_DRV_STAT_IFD(unsigned count = 0);
579
580 for (it = list->next; it != list; it = it->next) {
581 struct nouveau_bufref *ref = (struct nouveau_bufref *)it;
582 struct nv04_resource *res = ref->priv;
583 if (res)
584 nvc0_resource_validate(nvc0, res, (unsigned)ref->priv_data);
585 NOUVEAU_DRV_STAT_IFD(count++);
586 }
587 NOUVEAU_DRV_STAT(&nvc0->screen->base, resource_validate_count, count);
588 }
589
590 const void *
591 nvc0_get_sample_locations(unsigned sample_count)
592 {
593 static const uint8_t ms1[1][2] = { { 0x8, 0x8 } };
594 static const uint8_t ms2[2][2] = {
595 { 0x4, 0x4 }, { 0xc, 0xc } }; /* surface coords (0,0), (1,0) */
596 static const uint8_t ms4[4][2] = {
597 { 0x6, 0x2 }, { 0xe, 0x6 }, /* (0,0), (1,0) */
598 { 0x2, 0xa }, { 0xa, 0xe } }; /* (0,1), (1,1) */
599 static const uint8_t ms8[8][2] = {
600 { 0x1, 0x7 }, { 0x5, 0x3 }, /* (0,0), (1,0) */
601 { 0x3, 0xd }, { 0x7, 0xb }, /* (0,1), (1,1) */
602 { 0x9, 0x5 }, { 0xf, 0x1 }, /* (2,0), (3,0) */
603 { 0xb, 0xf }, { 0xd, 0x9 } }; /* (2,1), (3,1) */
604
605 const uint8_t (*ptr)[2];
606
607 switch (sample_count) {
608 case 0:
609 case 1: ptr = ms1; break;
610 case 2: ptr = ms2; break;
611 case 4: ptr = ms4; break;
612 case 8: ptr = ms8; break;
613 default:
614 assert(0);
615 return NULL; /* bad sample count -> undefined locations */
616 }
617 return ptr;
618 }
619
620 static void
621 nvc0_context_get_sample_position(struct pipe_context *pipe,
622 unsigned sample_count, unsigned sample_index,
623 float *xy)
624 {
625 const uint8_t (*ptr)[2];
626
627 ptr = nvc0_get_sample_locations(sample_count);
628 if (!ptr)
629 return;
630
631 xy[0] = ptr[sample_index][0] * 0.0625f;
632 xy[1] = ptr[sample_index][1] * 0.0625f;
633 }