OSDN Git Service

Merge remote-tracking branch 'mesa/12.0' into marshmallow-x86
[android-x86/external-mesa.git] / src / gallium / drivers / nouveau / nvc0 / nvc0_context.c
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
26 #include "nvc0/nvc0_context.h"
27 #include "nvc0/nvc0_screen.h"
28 #include "nvc0/nvc0_resource.h"
29
30 static void
31 nvc0_flush(struct pipe_context *pipe,
32            struct pipe_fence_handle **fence,
33            unsigned flags)
34 {
35    struct nvc0_context *nvc0 = nvc0_context(pipe);
36    struct nouveau_screen *screen = &nvc0->screen->base;
37
38    if (fence)
39       nouveau_fence_ref(screen->fence.current, (struct nouveau_fence **)fence);
40
41    pipe_mutex_lock(screen->push_mutex);
42    PUSH_KICK(nvc0->base.pushbuf); /* fencing handled in kick_notify */
43    pipe_mutex_unlock(screen->push_mutex);
44
45    nouveau_context_update_frame_stats(&nvc0->base);
46 }
47
48 static void
49 nvc0_texture_barrier(struct pipe_context *pipe)
50 {
51    struct nouveau_pushbuf *push = nvc0_context(pipe)->base.pushbuf;
52
53    pipe_mutex_lock(nvc0_context(pipe)->screen->base.push_mutex);
54    IMMED_NVC0(push, NVC0_3D(SERIALIZE), 0);
55    IMMED_NVC0(push, NVC0_3D(TEX_CACHE_CTL), 0);
56    pipe_mutex_unlock(nvc0_context(pipe)->screen->base.push_mutex);
57 }
58
59 static void
60 nvc0_memory_barrier(struct pipe_context *pipe, unsigned flags)
61 {
62    struct nvc0_context *nvc0 = nvc0_context(pipe);
63    struct nouveau_pushbuf *push = nvc0->base.pushbuf;
64    int i, s;
65
66    pipe_mutex_lock(nvc0_context(pipe)->screen->base.push_mutex);
67
68    if (flags & PIPE_BARRIER_MAPPED_BUFFER) {
69       for (i = 0; i < nvc0->num_vtxbufs; ++i) {
70          if (!nvc0->vtxbuf[i].buffer)
71             continue;
72          if (nvc0->vtxbuf[i].buffer->flags & PIPE_RESOURCE_FLAG_MAP_PERSISTENT)
73             nvc0->base.vbo_dirty = true;
74       }
75
76       if (nvc0->idxbuf.buffer &&
77           nvc0->idxbuf.buffer->flags & PIPE_RESOURCE_FLAG_MAP_PERSISTENT)
78          nvc0->base.vbo_dirty = true;
79
80       for (s = 0; s < 5 && !nvc0->cb_dirty; ++s) {
81          uint32_t valid = nvc0->constbuf_valid[s];
82
83          while (valid && !nvc0->cb_dirty) {
84             const unsigned i = ffs(valid) - 1;
85             struct pipe_resource *res;
86
87             valid &= ~(1 << i);
88             if (nvc0->constbuf[s][i].user)
89                continue;
90
91             res = nvc0->constbuf[s][i].u.buf;
92             if (!res)
93                continue;
94
95             if (res->flags & PIPE_RESOURCE_FLAG_MAP_PERSISTENT)
96                nvc0->cb_dirty = true;
97          }
98       }
99    } else {
100       /* Pretty much any writing by shaders needs a serialize after
101        * it. Especially when moving between 3d and compute pipelines, but even
102        * without that.
103        */
104       IMMED_NVC0(push, NVC0_3D(SERIALIZE), 0);
105    }
106
107    /* If we're going to texture from a buffer/image written by a shader, we
108     * must flush the texture cache.
109     */
110    if (flags & PIPE_BARRIER_TEXTURE)
111       IMMED_NVC0(push, NVC0_3D(TEX_CACHE_CTL), 0);
112
113    if (flags & PIPE_BARRIER_CONSTANT_BUFFER)
114       nvc0->cb_dirty = true;
115    if (flags & (PIPE_BARRIER_VERTEX_BUFFER | PIPE_BARRIER_INDEX_BUFFER))
116       nvc0->base.vbo_dirty = true;
117
118    pipe_mutex_unlock(nvc0_context(pipe)->screen->base.push_mutex);
119 }
120
121 static void
122 nvc0_emit_string_marker(struct pipe_context *pipe, const char *str, int len)
123 {
124    struct nouveau_pushbuf *push = nvc0_context(pipe)->base.pushbuf;
125    int string_words = len / 4;
126    int data_words;
127
128    if (len <= 0)
129       return;
130    string_words = MIN2(string_words, NV04_PFIFO_MAX_PACKET_LEN);
131    if (string_words == NV04_PFIFO_MAX_PACKET_LEN)
132       data_words = string_words;
133    else
134       data_words = string_words + !!(len & 3);
135    pipe_mutex_lock(nvc0_context(pipe)->screen->base.push_mutex);
136    BEGIN_NIC0(push, SUBC_3D(NV04_GRAPH_NOP), data_words);
137    if (string_words)
138       PUSH_DATAp(push, str, string_words);
139    if (string_words != data_words) {
140       int data = 0;
141       memcpy(&data, &str[string_words * 4], len & 3);
142       PUSH_DATA (push, data);
143    }
144    pipe_mutex_unlock(nvc0_context(pipe)->screen->base.push_mutex);
145 }
146
147 static void
148 nvc0_context_unreference_resources(struct nvc0_context *nvc0)
149 {
150    unsigned s, i;
151
152    nouveau_bufctx_del(&nvc0->bufctx_3d);
153    nouveau_bufctx_del(&nvc0->bufctx);
154    nouveau_bufctx_del(&nvc0->bufctx_cp);
155
156    util_unreference_framebuffer_state(&nvc0->framebuffer);
157
158    for (i = 0; i < nvc0->num_vtxbufs; ++i)
159       pipe_resource_reference(&nvc0->vtxbuf[i].buffer, NULL);
160
161    pipe_resource_reference(&nvc0->idxbuf.buffer, NULL);
162
163    for (s = 0; s < 6; ++s) {
164       for (i = 0; i < nvc0->num_textures[s]; ++i)
165          pipe_sampler_view_reference(&nvc0->textures[s][i], NULL);
166
167       for (i = 0; i < NVC0_MAX_PIPE_CONSTBUFS; ++i)
168          if (!nvc0->constbuf[s][i].user)
169             pipe_resource_reference(&nvc0->constbuf[s][i].u.buf, NULL);
170
171       for (i = 0; i < NVC0_MAX_BUFFERS; ++i)
172          pipe_resource_reference(&nvc0->buffers[s][i].buffer, NULL);
173
174       for (i = 0; i < NVC0_MAX_IMAGES; ++i)
175          pipe_resource_reference(&nvc0->images[s][i].resource, NULL);
176    }
177
178    for (s = 0; s < 2; ++s) {
179       for (i = 0; i < NVC0_MAX_SURFACE_SLOTS; ++i)
180          pipe_surface_reference(&nvc0->surfaces[s][i], NULL);
181    }
182
183    for (i = 0; i < nvc0->num_tfbbufs; ++i)
184       pipe_so_target_reference(&nvc0->tfbbuf[i], NULL);
185
186    for (i = 0; i < nvc0->global_residents.size / sizeof(struct pipe_resource *);
187         ++i) {
188       struct pipe_resource **res = util_dynarray_element(
189          &nvc0->global_residents, struct pipe_resource *, i);
190       pipe_resource_reference(res, NULL);
191    }
192    util_dynarray_fini(&nvc0->global_residents);
193
194    if (nvc0->tcp_empty)
195       nvc0->base.pipe.delete_tcs_state(&nvc0->base.pipe, nvc0->tcp_empty);
196 }
197
198 static void
199 nvc0_destroy(struct pipe_context *pipe)
200 {
201    struct nvc0_context *nvc0 = nvc0_context(pipe);
202
203    if (nvc0->screen->cur_ctx == nvc0) {
204       nvc0->screen->cur_ctx = NULL;
205       nvc0->screen->save_state = nvc0->state;
206       nvc0->screen->save_state.tfb = NULL;
207    }
208
209    /* Unset bufctx, we don't want to revalidate any resources after the flush.
210     * Other contexts will always set their bufctx again on action calls.
211     */
212    nouveau_pushbuf_bufctx(nvc0->base.pushbuf, NULL);
213    nouveau_pushbuf_kick(nvc0->base.pushbuf, nvc0->base.pushbuf->channel);
214
215    nvc0_context_unreference_resources(nvc0);
216    nvc0_blitctx_destroy(nvc0);
217
218    nouveau_context_destroy(&nvc0->base);
219 }
220
221 void
222 nvc0_default_kick_notify(struct nouveau_pushbuf *push)
223 {
224    struct nvc0_screen *screen = push->user_priv;
225
226    if (screen) {
227       nouveau_fence_next(&screen->base);
228       nouveau_fence_update(&screen->base, true);
229       if (screen->cur_ctx)
230          screen->cur_ctx->state.flushed = true;
231       NOUVEAU_DRV_STAT(&screen->base, pushbuf_count, 1);
232    }
233 }
234
235 static int
236 nvc0_invalidate_resource_storage(struct nouveau_context *ctx,
237                                  struct pipe_resource *res,
238                                  int ref)
239 {
240    struct nvc0_context *nvc0 = nvc0_context(&ctx->pipe);
241    unsigned s, i;
242
243    if (res->bind & PIPE_BIND_RENDER_TARGET) {
244       for (i = 0; i < nvc0->framebuffer.nr_cbufs; ++i) {
245          if (nvc0->framebuffer.cbufs[i] &&
246              nvc0->framebuffer.cbufs[i]->texture == res) {
247             nvc0->dirty_3d |= NVC0_NEW_3D_FRAMEBUFFER;
248             nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_FB);
249             if (!--ref)
250                return ref;
251          }
252       }
253    }
254    if (res->bind & PIPE_BIND_DEPTH_STENCIL) {
255       if (nvc0->framebuffer.zsbuf &&
256           nvc0->framebuffer.zsbuf->texture == res) {
257          nvc0->dirty_3d |= NVC0_NEW_3D_FRAMEBUFFER;
258          nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_FB);
259          if (!--ref)
260             return ref;
261       }
262    }
263
264    if (res->target == PIPE_BUFFER) {
265       for (i = 0; i < nvc0->num_vtxbufs; ++i) {
266          if (nvc0->vtxbuf[i].buffer == res) {
267             nvc0->dirty_3d |= NVC0_NEW_3D_ARRAYS;
268             nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_VTX);
269             if (!--ref)
270                return ref;
271          }
272       }
273
274       if (nvc0->idxbuf.buffer == res) {
275          nvc0->dirty_3d |= NVC0_NEW_3D_IDXBUF;
276          nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_IDX);
277          if (!--ref)
278             return ref;
279       }
280
281       for (s = 0; s < 6; ++s) {
282          for (i = 0; i < nvc0->num_textures[s]; ++i) {
283             if (nvc0->textures[s][i] &&
284                 nvc0->textures[s][i]->texture == res) {
285                nvc0->textures_dirty[s] |= 1 << i;
286                if (unlikely(s == 5)) {
287                   nvc0->dirty_cp |= NVC0_NEW_CP_TEXTURES;
288                   nouveau_bufctx_reset(nvc0->bufctx_cp, NVC0_BIND_CP_TEX(i));
289                } else {
290                   nvc0->dirty_3d |= NVC0_NEW_3D_TEXTURES;
291                   nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_TEX(s, i));
292                }
293                if (!--ref)
294                   return ref;
295             }
296          }
297       }
298
299       for (s = 0; s < 6; ++s) {
300          for (i = 0; i < NVC0_MAX_PIPE_CONSTBUFS; ++i) {
301             if (!(nvc0->constbuf_valid[s] & (1 << i)))
302                continue;
303             if (!nvc0->constbuf[s][i].user &&
304                 nvc0->constbuf[s][i].u.buf == res) {
305                nvc0->constbuf_dirty[s] |= 1 << i;
306                if (unlikely(s == 5)) {
307                   nvc0->dirty_cp |= NVC0_NEW_CP_CONSTBUF;
308                   nouveau_bufctx_reset(nvc0->bufctx_cp, NVC0_BIND_CP_CB(i));
309                } else {
310                   nvc0->dirty_3d |= NVC0_NEW_3D_CONSTBUF;
311                   nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_CB(s, i));
312                }
313                if (!--ref)
314                   return ref;
315             }
316          }
317       }
318
319       for (s = 0; s < 6; ++s) {
320          for (i = 0; i < NVC0_MAX_BUFFERS; ++i) {
321             if (nvc0->buffers[s][i].buffer == res) {
322                nvc0->buffers_dirty[s] |= 1 << i;
323                if (unlikely(s == 5)) {
324                   nvc0->dirty_cp |= NVC0_NEW_CP_BUFFERS;
325                   nouveau_bufctx_reset(nvc0->bufctx_cp, NVC0_BIND_CP_BUF);
326                } else {
327                   nvc0->dirty_3d |= NVC0_NEW_3D_BUFFERS;
328                   nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_BUF);
329                }
330                if (!--ref)
331                   return ref;
332             }
333          }
334       }
335
336       for (s = 0; s < 6; ++s) {
337          for (i = 0; i < NVC0_MAX_IMAGES; ++i) {
338             if (nvc0->images[s][i].resource == res) {
339                nvc0->images_dirty[s] |= 1 << i;
340                if (unlikely(s == 5)) {
341                   nvc0->dirty_cp |= NVC0_NEW_CP_SURFACES;
342                   nouveau_bufctx_reset(nvc0->bufctx_cp, NVC0_BIND_CP_SUF);
343                } else {
344                   nvc0->dirty_3d |= NVC0_NEW_3D_SURFACES;
345                   nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_SUF);
346                }
347             }
348             if (!--ref)
349                return ref;
350          }
351       }
352    }
353
354    return ref;
355 }
356
357 static void
358 nvc0_context_get_sample_position(struct pipe_context *, unsigned, unsigned,
359                                  float *);
360
361 struct pipe_context *
362 nvc0_create(struct pipe_screen *pscreen, void *priv, unsigned ctxflags)
363 {
364    struct nvc0_screen *screen = nvc0_screen(pscreen);
365    struct nvc0_context *nvc0;
366    struct pipe_context *pipe;
367    int ret;
368    uint32_t flags;
369
370    nvc0 = CALLOC_STRUCT(nvc0_context);
371    if (!nvc0)
372       return NULL;
373    pipe = &nvc0->base.pipe;
374
375    pipe_mutex_lock(screen->base.push_mutex);
376
377    if (!nvc0_blitctx_create(nvc0))
378       goto out_err;
379
380    nvc0->base.pushbuf = screen->base.pushbuf;
381    nvc0->base.client = screen->base.client;
382
383    ret = nouveau_bufctx_new(screen->base.client, 2, &nvc0->bufctx);
384    if (!ret)
385       ret = nouveau_bufctx_new(screen->base.client, NVC0_BIND_3D_COUNT,
386                                &nvc0->bufctx_3d);
387    if (!ret)
388       ret = nouveau_bufctx_new(screen->base.client, NVC0_BIND_CP_COUNT,
389                                &nvc0->bufctx_cp);
390    if (ret)
391       goto out_err;
392
393    nvc0->screen = screen;
394    nvc0->base.screen = &screen->base;
395
396    pipe->screen = pscreen;
397    pipe->priv = priv;
398
399    pipe->destroy = nvc0_destroy;
400
401    pipe->draw_vbo = nvc0_draw_vbo;
402    pipe->clear = nvc0_clear;
403    pipe->launch_grid = (nvc0->screen->base.class_3d >= NVE4_3D_CLASS) ?
404       nve4_launch_grid : nvc0_launch_grid;
405
406    pipe->flush = nvc0_flush;
407    pipe->texture_barrier = nvc0_texture_barrier;
408    pipe->memory_barrier = nvc0_memory_barrier;
409    pipe->get_sample_position = nvc0_context_get_sample_position;
410    pipe->emit_string_marker = nvc0_emit_string_marker;
411
412    nouveau_context_init(&nvc0->base);
413    nvc0_init_query_functions(nvc0);
414    nvc0_init_surface_functions(nvc0);
415    nvc0_init_state_functions(nvc0);
416    nvc0_init_transfer_functions(nvc0);
417    nvc0_init_resource_functions(pipe);
418
419    nvc0->base.invalidate_resource_storage = nvc0_invalidate_resource_storage;
420
421    pipe->create_video_codec = nvc0_create_decoder;
422    pipe->create_video_buffer = nvc0_video_buffer_create;
423
424    /* shader builtin library is per-screen, but we need a context for m2mf */
425    nvc0_program_library_upload(nvc0);
426    nvc0_program_init_tcp_empty(nvc0);
427    if (!nvc0->tcp_empty)
428       goto out_err;
429    /* set the empty tctl prog on next draw in case one is never set */
430    nvc0->dirty_3d |= NVC0_NEW_3D_TCTLPROG;
431
432    /* Do not bind the COMPUTE driver constbuf at screen initialization because
433     * CBs are aliased between 3D and COMPUTE, but make sure it will be bound if
434     * a grid is launched later. */
435    nvc0->dirty_cp |= NVC0_NEW_CP_DRIVERCONST;
436
437    /* now that there are no more opportunities for errors, set the current
438     * context if there isn't already one.
439     */
440    if (!screen->cur_ctx) {
441       nvc0->state = screen->save_state;
442       screen->cur_ctx = nvc0;
443       nouveau_pushbuf_bufctx(screen->base.pushbuf, nvc0->bufctx);
444    }
445    screen->base.pushbuf->kick_notify = nvc0_default_kick_notify;
446
447    /* add permanently resident buffers to bufctxts */
448
449    flags = NV_VRAM_DOMAIN(&screen->base) | NOUVEAU_BO_RD;
450
451    BCTX_REFN_bo(nvc0->bufctx_3d, 3D_SCREEN, flags, screen->text);
452    BCTX_REFN_bo(nvc0->bufctx_3d, 3D_SCREEN, flags, screen->uniform_bo);
453    BCTX_REFN_bo(nvc0->bufctx_3d, 3D_SCREEN, flags, screen->txc);
454    if (screen->compute) {
455       BCTX_REFN_bo(nvc0->bufctx_cp, CP_SCREEN, flags, screen->text);
456       BCTX_REFN_bo(nvc0->bufctx_cp, CP_SCREEN, flags, screen->uniform_bo);
457       BCTX_REFN_bo(nvc0->bufctx_cp, CP_SCREEN, flags, screen->txc);
458    }
459
460    flags = NV_VRAM_DOMAIN(&screen->base) | NOUVEAU_BO_RDWR;
461
462    if (screen->poly_cache)
463       BCTX_REFN_bo(nvc0->bufctx_3d, 3D_SCREEN, flags, screen->poly_cache);
464    if (screen->compute)
465       BCTX_REFN_bo(nvc0->bufctx_cp, CP_SCREEN, flags, screen->tls);
466
467    flags = NOUVEAU_BO_GART | NOUVEAU_BO_WR;
468
469    BCTX_REFN_bo(nvc0->bufctx_3d, 3D_SCREEN, flags, screen->fence.bo);
470    BCTX_REFN_bo(nvc0->bufctx, FENCE, flags, screen->fence.bo);
471    if (screen->compute)
472       BCTX_REFN_bo(nvc0->bufctx_cp, CP_SCREEN, flags, screen->fence.bo);
473
474    nvc0->base.scratch.bo_size = 2 << 20;
475
476    memset(nvc0->tex_handles, ~0, sizeof(nvc0->tex_handles));
477
478    util_dynarray_init(&nvc0->global_residents);
479
480    pipe_mutex_unlock(screen->base.push_mutex);
481
482    return pipe;
483
484 out_err:
485    pipe_mutex_unlock(screen->base.push_mutex);
486    if (nvc0) {
487       if (nvc0->bufctx_3d)
488          nouveau_bufctx_del(&nvc0->bufctx_3d);
489       if (nvc0->bufctx_cp)
490          nouveau_bufctx_del(&nvc0->bufctx_cp);
491       if (nvc0->bufctx)
492          nouveau_bufctx_del(&nvc0->bufctx);
493       FREE(nvc0->blit);
494       FREE(nvc0);
495    }
496    return NULL;
497 }
498
499 void
500 nvc0_bufctx_fence(struct nvc0_context *nvc0, struct nouveau_bufctx *bufctx,
501                   bool on_flush)
502 {
503    struct nouveau_list *list = on_flush ? &bufctx->current : &bufctx->pending;
504    struct nouveau_list *it;
505    NOUVEAU_DRV_STAT_IFD(unsigned count = 0);
506
507    for (it = list->next; it != list; it = it->next) {
508       struct nouveau_bufref *ref = (struct nouveau_bufref *)it;
509       struct nv04_resource *res = ref->priv;
510       if (res)
511          nvc0_resource_validate(res, (unsigned)ref->priv_data);
512       NOUVEAU_DRV_STAT_IFD(count++);
513    }
514    NOUVEAU_DRV_STAT(&nvc0->screen->base, resource_validate_count, count);
515 }
516
517 const void *
518 nvc0_get_sample_locations(unsigned sample_count)
519 {
520    static const uint8_t ms1[1][2] = { { 0x8, 0x8 } };
521    static const uint8_t ms2[2][2] = {
522       { 0x4, 0x4 }, { 0xc, 0xc } }; /* surface coords (0,0), (1,0) */
523    static const uint8_t ms4[4][2] = {
524       { 0x6, 0x2 }, { 0xe, 0x6 },   /* (0,0), (1,0) */
525       { 0x2, 0xa }, { 0xa, 0xe } }; /* (0,1), (1,1) */
526    static const uint8_t ms8[8][2] = {
527       { 0x1, 0x7 }, { 0x5, 0x3 },   /* (0,0), (1,0) */
528       { 0x3, 0xd }, { 0x7, 0xb },   /* (0,1), (1,1) */
529       { 0x9, 0x5 }, { 0xf, 0x1 },   /* (2,0), (3,0) */
530       { 0xb, 0xf }, { 0xd, 0x9 } }; /* (2,1), (3,1) */
531 #if 0
532    /* NOTE: there are alternative modes for MS2 and MS8, currently not used */
533    static const uint8_t ms8_alt[8][2] = {
534       { 0x9, 0x5 }, { 0x7, 0xb },   /* (2,0), (1,1) */
535       { 0xd, 0x9 }, { 0x5, 0x3 },   /* (3,1), (1,0) */
536       { 0x3, 0xd }, { 0x1, 0x7 },   /* (0,1), (0,0) */
537       { 0xb, 0xf }, { 0xf, 0x1 } }; /* (2,1), (3,0) */
538 #endif
539
540    const uint8_t (*ptr)[2];
541
542    switch (sample_count) {
543    case 0:
544    case 1: ptr = ms1; break;
545    case 2: ptr = ms2; break;
546    case 4: ptr = ms4; break;
547    case 8: ptr = ms8; break;
548    default:
549       assert(0);
550       return NULL; /* bad sample count -> undefined locations */
551    }
552    return ptr;
553 }
554
555 static void
556 nvc0_context_get_sample_position(struct pipe_context *pipe,
557                                  unsigned sample_count, unsigned sample_index,
558                                  float *xy)
559 {
560    const uint8_t (*ptr)[2];
561
562    ptr = nvc0_get_sample_locations(sample_count);
563    if (!ptr)
564       return;
565
566    xy[0] = ptr[sample_index][0] * 0.0625f;
567    xy[1] = ptr[sample_index][1] * 0.0625f;
568 }