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