Path: blob/21.2-virgl/src/gallium/drivers/nouveau/nvc0/nvc0_context.c
4574 views
/*1* Copyright 2010 Christoph Bumiller2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice shall be included in11* all copies or substantial portions of the Software.12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR17* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,18* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR19* OTHER DEALINGS IN THE SOFTWARE.20*/2122#include "pipe/p_defines.h"23#include "util/u_framebuffer.h"24#include "util/u_upload_mgr.h"2526#include "nvc0/nvc0_context.h"27#include "nvc0/nvc0_screen.h"28#include "nvc0/nvc0_resource.h"293031#include "xf86drm.h"32#include "nouveau_drm.h"333435static void36nvc0_svm_migrate(struct pipe_context *pipe, unsigned num_ptrs,37const void* const* ptrs, const size_t *sizes,38bool to_device, bool mem_undefined)39{40struct nvc0_context *nvc0 = nvc0_context(pipe);41struct nouveau_screen *screen = &nvc0->screen->base;42int fd = screen->drm->fd;43unsigned i;4445for (i = 0; i < num_ptrs; i++) {46struct drm_nouveau_svm_bind args;47uint64_t cmd, prio, target;4849args.va_start = (uint64_t)(uintptr_t)ptrs[i];50if (sizes && sizes[i]) {51args.va_end = (uint64_t)(uintptr_t)ptrs[i] + sizes[i];52args.npages = DIV_ROUND_UP(args.va_end - args.va_start, 0x1000);53} else {54args.va_end = 0;55args.npages = 0;56}57args.stride = 0;5859args.reserved0 = 0;60args.reserved1 = 0;6162prio = 0;63cmd = NOUVEAU_SVM_BIND_COMMAND__MIGRATE;64target = to_device ? NOUVEAU_SVM_BIND_TARGET__GPU_VRAM : 0;6566args.header = cmd << NOUVEAU_SVM_BIND_COMMAND_SHIFT;67args.header |= prio << NOUVEAU_SVM_BIND_PRIORITY_SHIFT;68args.header |= target << NOUVEAU_SVM_BIND_TARGET_SHIFT;6970/* This is best effort, so no garanty whatsoever */71drmCommandWrite(fd, DRM_NOUVEAU_SVM_BIND,72&args, sizeof(args));73}74}757677static void78nvc0_flush(struct pipe_context *pipe,79struct pipe_fence_handle **fence,80unsigned flags)81{82struct nvc0_context *nvc0 = nvc0_context(pipe);83struct nouveau_screen *screen = &nvc0->screen->base;8485if (fence)86nouveau_fence_ref(screen->fence.current, (struct nouveau_fence **)fence);8788PUSH_KICK(nvc0->base.pushbuf); /* fencing handled in kick_notify */8990nouveau_context_update_frame_stats(&nvc0->base);91}9293static void94nvc0_texture_barrier(struct pipe_context *pipe, unsigned flags)95{96struct nouveau_pushbuf *push = nvc0_context(pipe)->base.pushbuf;9798IMMED_NVC0(push, NVC0_3D(SERIALIZE), 0);99IMMED_NVC0(push, NVC0_3D(TEX_CACHE_CTL), 0);100}101102static void103nvc0_memory_barrier(struct pipe_context *pipe, unsigned flags)104{105struct nvc0_context *nvc0 = nvc0_context(pipe);106struct nouveau_pushbuf *push = nvc0->base.pushbuf;107int i, s;108109if (!(flags & ~PIPE_BARRIER_UPDATE))110return;111112if (flags & PIPE_BARRIER_MAPPED_BUFFER) {113for (i = 0; i < nvc0->num_vtxbufs; ++i) {114if (!nvc0->vtxbuf[i].buffer.resource && !nvc0->vtxbuf[i].is_user_buffer)115continue;116if (nvc0->vtxbuf[i].buffer.resource->flags & PIPE_RESOURCE_FLAG_MAP_PERSISTENT)117nvc0->base.vbo_dirty = true;118}119120for (s = 0; s < 5 && !nvc0->cb_dirty; ++s) {121uint32_t valid = nvc0->constbuf_valid[s];122123while (valid && !nvc0->cb_dirty) {124const unsigned i = ffs(valid) - 1;125struct pipe_resource *res;126127valid &= ~(1 << i);128if (nvc0->constbuf[s][i].user)129continue;130131res = nvc0->constbuf[s][i].u.buf;132if (!res)133continue;134135if (res->flags & PIPE_RESOURCE_FLAG_MAP_PERSISTENT)136nvc0->cb_dirty = true;137}138}139} else {140/* Pretty much any writing by shaders needs a serialize after141* it. Especially when moving between 3d and compute pipelines, but even142* without that.143*/144IMMED_NVC0(push, NVC0_3D(SERIALIZE), 0);145}146147/* If we're going to texture from a buffer/image written by a shader, we148* must flush the texture cache.149*/150if (flags & PIPE_BARRIER_TEXTURE)151IMMED_NVC0(push, NVC0_3D(TEX_CACHE_CTL), 0);152153if (flags & PIPE_BARRIER_CONSTANT_BUFFER)154nvc0->cb_dirty = true;155if (flags & (PIPE_BARRIER_VERTEX_BUFFER | PIPE_BARRIER_INDEX_BUFFER))156nvc0->base.vbo_dirty = true;157}158159static void160nvc0_emit_string_marker(struct pipe_context *pipe, const char *str, int len)161{162struct nouveau_pushbuf *push = nvc0_context(pipe)->base.pushbuf;163int string_words = len / 4;164int data_words;165166if (len <= 0)167return;168string_words = MIN2(string_words, NV04_PFIFO_MAX_PACKET_LEN);169if (string_words == NV04_PFIFO_MAX_PACKET_LEN)170data_words = string_words;171else172data_words = string_words + !!(len & 3);173BEGIN_NIC0(push, SUBC_3D(NV04_GRAPH_NOP), data_words);174if (string_words)175PUSH_DATAp(push, str, string_words);176if (string_words != data_words) {177int data = 0;178memcpy(&data, &str[string_words * 4], len & 3);179PUSH_DATA (push, data);180}181}182183static enum pipe_reset_status184nvc0_get_device_reset_status(struct pipe_context *pipe)185{186return PIPE_NO_RESET;187}188189static void190nvc0_context_unreference_resources(struct nvc0_context *nvc0)191{192unsigned s, i;193194nouveau_bufctx_del(&nvc0->bufctx_3d);195nouveau_bufctx_del(&nvc0->bufctx);196nouveau_bufctx_del(&nvc0->bufctx_cp);197198util_unreference_framebuffer_state(&nvc0->framebuffer);199200for (i = 0; i < nvc0->num_vtxbufs; ++i)201pipe_vertex_buffer_unreference(&nvc0->vtxbuf[i]);202203for (s = 0; s < 6; ++s) {204for (i = 0; i < nvc0->num_textures[s]; ++i)205pipe_sampler_view_reference(&nvc0->textures[s][i], NULL);206207for (i = 0; i < NVC0_MAX_PIPE_CONSTBUFS; ++i)208if (!nvc0->constbuf[s][i].user)209pipe_resource_reference(&nvc0->constbuf[s][i].u.buf, NULL);210211for (i = 0; i < NVC0_MAX_BUFFERS; ++i)212pipe_resource_reference(&nvc0->buffers[s][i].buffer, NULL);213214for (i = 0; i < NVC0_MAX_IMAGES; ++i) {215pipe_resource_reference(&nvc0->images[s][i].resource, NULL);216if (nvc0->screen->base.class_3d >= GM107_3D_CLASS)217pipe_sampler_view_reference(&nvc0->images_tic[s][i], NULL);218}219}220221for (s = 0; s < 2; ++s) {222for (i = 0; i < NVC0_MAX_SURFACE_SLOTS; ++i)223pipe_surface_reference(&nvc0->surfaces[s][i], NULL);224}225226for (i = 0; i < nvc0->num_tfbbufs; ++i)227pipe_so_target_reference(&nvc0->tfbbuf[i], NULL);228229for (i = 0; i < nvc0->global_residents.size / sizeof(struct pipe_resource *);230++i) {231struct pipe_resource **res = util_dynarray_element(232&nvc0->global_residents, struct pipe_resource *, i);233pipe_resource_reference(res, NULL);234}235util_dynarray_fini(&nvc0->global_residents);236237if (nvc0->tcp_empty)238nvc0->base.pipe.delete_tcs_state(&nvc0->base.pipe, nvc0->tcp_empty);239}240241static void242nvc0_destroy(struct pipe_context *pipe)243{244struct nvc0_context *nvc0 = nvc0_context(pipe);245246if (nvc0->screen->cur_ctx == nvc0) {247nvc0->screen->cur_ctx = NULL;248nvc0->screen->save_state = nvc0->state;249nvc0->screen->save_state.tfb = NULL;250}251252if (nvc0->base.pipe.stream_uploader)253u_upload_destroy(nvc0->base.pipe.stream_uploader);254255/* Unset bufctx, we don't want to revalidate any resources after the flush.256* Other contexts will always set their bufctx again on action calls.257*/258nouveau_pushbuf_bufctx(nvc0->base.pushbuf, NULL);259nouveau_pushbuf_kick(nvc0->base.pushbuf, nvc0->base.pushbuf->channel);260261nvc0_context_unreference_resources(nvc0);262nvc0_blitctx_destroy(nvc0);263264list_for_each_entry_safe(struct nvc0_resident, pos, &nvc0->tex_head, list) {265list_del(&pos->list);266free(pos);267}268269list_for_each_entry_safe(struct nvc0_resident, pos, &nvc0->img_head, list) {270list_del(&pos->list);271free(pos);272}273274nouveau_context_destroy(&nvc0->base);275}276277void278nvc0_default_kick_notify(struct nouveau_pushbuf *push)279{280struct nvc0_screen *screen = push->user_priv;281282if (screen) {283nouveau_fence_next(&screen->base);284nouveau_fence_update(&screen->base, true);285if (screen->cur_ctx)286screen->cur_ctx->state.flushed = true;287NOUVEAU_DRV_STAT(&screen->base, pushbuf_count, 1);288}289}290291static int292nvc0_invalidate_resource_storage(struct nouveau_context *ctx,293struct pipe_resource *res,294int ref)295{296struct nvc0_context *nvc0 = nvc0_context(&ctx->pipe);297unsigned s, i;298299if (res->bind & PIPE_BIND_RENDER_TARGET) {300for (i = 0; i < nvc0->framebuffer.nr_cbufs; ++i) {301if (nvc0->framebuffer.cbufs[i] &&302nvc0->framebuffer.cbufs[i]->texture == res) {303nvc0->dirty_3d |= NVC0_NEW_3D_FRAMEBUFFER;304nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_FB);305if (!--ref)306return ref;307}308}309}310if (res->bind & PIPE_BIND_DEPTH_STENCIL) {311if (nvc0->framebuffer.zsbuf &&312nvc0->framebuffer.zsbuf->texture == res) {313nvc0->dirty_3d |= NVC0_NEW_3D_FRAMEBUFFER;314nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_FB);315if (!--ref)316return ref;317}318}319320if (res->target == PIPE_BUFFER) {321for (i = 0; i < nvc0->num_vtxbufs; ++i) {322if (nvc0->vtxbuf[i].buffer.resource == res) {323nvc0->dirty_3d |= NVC0_NEW_3D_ARRAYS;324nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_VTX);325if (!--ref)326return ref;327}328}329330for (s = 0; s < 6; ++s) {331for (i = 0; i < nvc0->num_textures[s]; ++i) {332if (nvc0->textures[s][i] &&333nvc0->textures[s][i]->texture == res) {334nvc0->textures_dirty[s] |= 1 << i;335if (unlikely(s == 5)) {336nvc0->dirty_cp |= NVC0_NEW_CP_TEXTURES;337nouveau_bufctx_reset(nvc0->bufctx_cp, NVC0_BIND_CP_TEX(i));338} else {339nvc0->dirty_3d |= NVC0_NEW_3D_TEXTURES;340nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_TEX(s, i));341}342if (!--ref)343return ref;344}345}346}347348for (s = 0; s < 6; ++s) {349for (i = 0; i < NVC0_MAX_PIPE_CONSTBUFS; ++i) {350if (!(nvc0->constbuf_valid[s] & (1 << i)))351continue;352if (!nvc0->constbuf[s][i].user &&353nvc0->constbuf[s][i].u.buf == res) {354nvc0->constbuf_dirty[s] |= 1 << i;355if (unlikely(s == 5)) {356nvc0->dirty_cp |= NVC0_NEW_CP_CONSTBUF;357nouveau_bufctx_reset(nvc0->bufctx_cp, NVC0_BIND_CP_CB(i));358} else {359nvc0->dirty_3d |= NVC0_NEW_3D_CONSTBUF;360nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_CB(s, i));361}362if (!--ref)363return ref;364}365}366}367368for (s = 0; s < 6; ++s) {369for (i = 0; i < NVC0_MAX_BUFFERS; ++i) {370if (nvc0->buffers[s][i].buffer == res) {371nvc0->buffers_dirty[s] |= 1 << i;372if (unlikely(s == 5)) {373nvc0->dirty_cp |= NVC0_NEW_CP_BUFFERS;374nouveau_bufctx_reset(nvc0->bufctx_cp, NVC0_BIND_CP_BUF);375} else {376nvc0->dirty_3d |= NVC0_NEW_3D_BUFFERS;377nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_BUF);378}379if (!--ref)380return ref;381}382}383}384385for (s = 0; s < 6; ++s) {386for (i = 0; i < NVC0_MAX_IMAGES; ++i) {387if (nvc0->images[s][i].resource == res) {388nvc0->images_dirty[s] |= 1 << i;389if (unlikely(s == 5)) {390nvc0->dirty_cp |= NVC0_NEW_CP_SURFACES;391nouveau_bufctx_reset(nvc0->bufctx_cp, NVC0_BIND_CP_SUF);392} else {393nvc0->dirty_3d |= NVC0_NEW_3D_SURFACES;394nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_SUF);395}396}397if (!--ref)398return ref;399}400}401}402403return ref;404}405406static void407nvc0_context_get_sample_position(struct pipe_context *, unsigned, unsigned,408float *);409410struct pipe_context *411nvc0_create(struct pipe_screen *pscreen, void *priv, unsigned ctxflags)412{413struct nvc0_screen *screen = nvc0_screen(pscreen);414struct nvc0_context *nvc0;415struct pipe_context *pipe;416int ret;417uint32_t flags;418419nvc0 = CALLOC_STRUCT(nvc0_context);420if (!nvc0)421return NULL;422pipe = &nvc0->base.pipe;423424if (!nvc0_blitctx_create(nvc0))425goto out_err;426427nvc0->base.pushbuf = screen->base.pushbuf;428nvc0->base.client = screen->base.client;429430ret = nouveau_bufctx_new(screen->base.client, 2, &nvc0->bufctx);431if (!ret)432ret = nouveau_bufctx_new(screen->base.client, NVC0_BIND_3D_COUNT,433&nvc0->bufctx_3d);434if (!ret)435ret = nouveau_bufctx_new(screen->base.client, NVC0_BIND_CP_COUNT,436&nvc0->bufctx_cp);437if (ret)438goto out_err;439440nvc0->screen = screen;441nvc0->base.screen = &screen->base;442443pipe->screen = pscreen;444pipe->priv = priv;445pipe->stream_uploader = u_upload_create_default(pipe);446if (!pipe->stream_uploader)447goto out_err;448pipe->const_uploader = pipe->stream_uploader;449450pipe->destroy = nvc0_destroy;451452pipe->draw_vbo = nvc0_draw_vbo;453pipe->clear = nvc0_clear;454pipe->launch_grid = (nvc0->screen->base.class_3d >= NVE4_3D_CLASS) ?455nve4_launch_grid : nvc0_launch_grid;456457pipe->svm_migrate = nvc0_svm_migrate;458459pipe->flush = nvc0_flush;460pipe->texture_barrier = nvc0_texture_barrier;461pipe->memory_barrier = nvc0_memory_barrier;462pipe->get_sample_position = nvc0_context_get_sample_position;463pipe->emit_string_marker = nvc0_emit_string_marker;464pipe->get_device_reset_status = nvc0_get_device_reset_status;465466nouveau_context_init(&nvc0->base);467nvc0_init_query_functions(nvc0);468nvc0_init_surface_functions(nvc0);469nvc0_init_state_functions(nvc0);470nvc0_init_transfer_functions(nvc0);471nvc0_init_resource_functions(pipe);472if (nvc0->screen->base.class_3d >= NVE4_3D_CLASS)473nvc0_init_bindless_functions(pipe);474475list_inithead(&nvc0->tex_head);476list_inithead(&nvc0->img_head);477478nvc0->base.invalidate_resource_storage = nvc0_invalidate_resource_storage;479480pipe->create_video_codec = nvc0_create_decoder;481pipe->create_video_buffer = nvc0_video_buffer_create;482483/* shader builtin library is per-screen, but we need a context for m2mf */484nvc0_program_library_upload(nvc0);485nvc0_program_init_tcp_empty(nvc0);486if (!nvc0->tcp_empty)487goto out_err;488/* set the empty tctl prog on next draw in case one is never set */489nvc0->dirty_3d |= NVC0_NEW_3D_TCTLPROG;490491/* Do not bind the COMPUTE driver constbuf at screen initialization because492* CBs are aliased between 3D and COMPUTE, but make sure it will be bound if493* a grid is launched later. */494nvc0->dirty_cp |= NVC0_NEW_CP_DRIVERCONST;495496/* now that there are no more opportunities for errors, set the current497* context if there isn't already one.498*/499if (!screen->cur_ctx) {500nvc0->state = screen->save_state;501screen->cur_ctx = nvc0;502nouveau_pushbuf_bufctx(screen->base.pushbuf, nvc0->bufctx);503}504screen->base.pushbuf->kick_notify = nvc0_default_kick_notify;505506/* add permanently resident buffers to bufctxts */507508flags = NV_VRAM_DOMAIN(&screen->base) | NOUVEAU_BO_RD;509510BCTX_REFN_bo(nvc0->bufctx_3d, 3D_SCREEN, flags, screen->uniform_bo);511BCTX_REFN_bo(nvc0->bufctx_3d, 3D_SCREEN, flags, screen->txc);512if (screen->compute) {513BCTX_REFN_bo(nvc0->bufctx_cp, CP_SCREEN, flags, screen->uniform_bo);514BCTX_REFN_bo(nvc0->bufctx_cp, CP_SCREEN, flags, screen->txc);515}516517flags = NV_VRAM_DOMAIN(&screen->base) | NOUVEAU_BO_RDWR;518519if (screen->poly_cache)520BCTX_REFN_bo(nvc0->bufctx_3d, 3D_SCREEN, flags, screen->poly_cache);521if (screen->compute)522BCTX_REFN_bo(nvc0->bufctx_cp, CP_SCREEN, flags, screen->tls);523524flags = NOUVEAU_BO_GART | NOUVEAU_BO_WR;525526BCTX_REFN_bo(nvc0->bufctx_3d, 3D_SCREEN, flags, screen->fence.bo);527BCTX_REFN_bo(nvc0->bufctx, FENCE, flags, screen->fence.bo);528if (screen->compute)529BCTX_REFN_bo(nvc0->bufctx_cp, CP_SCREEN, flags, screen->fence.bo);530531nvc0->base.scratch.bo_size = 2 << 20;532533memset(nvc0->tex_handles, ~0, sizeof(nvc0->tex_handles));534535util_dynarray_init(&nvc0->global_residents, NULL);536537// Make sure that the first TSC entry has SRGB conversion bit set, since we538// use it as a fallback on Fermi for TXF, and on Kepler+ generations for539// FBFETCH handling (which also uses TXF).540//541// NOTE: Preliminary testing suggests that this isn't necessary at all at542// least on GM20x (untested on Kepler). However this is ~free, so no reason543// not to do it.544if (!screen->tsc.entries[0])545nvc0_upload_tsc0(nvc0);546547// On Fermi, mark samplers dirty so that the proper binding can happen548if (screen->base.class_3d < NVE4_3D_CLASS) {549for (int s = 0; s < 6; s++)550nvc0->samplers_dirty[s] = 1;551nvc0->dirty_3d |= NVC0_NEW_3D_SAMPLERS;552nvc0->dirty_cp |= NVC0_NEW_CP_SAMPLERS;553}554555return pipe;556557out_err:558if (nvc0) {559if (pipe->stream_uploader)560u_upload_destroy(pipe->stream_uploader);561if (nvc0->bufctx_3d)562nouveau_bufctx_del(&nvc0->bufctx_3d);563if (nvc0->bufctx_cp)564nouveau_bufctx_del(&nvc0->bufctx_cp);565if (nvc0->bufctx)566nouveau_bufctx_del(&nvc0->bufctx);567FREE(nvc0->blit);568FREE(nvc0);569}570return NULL;571}572573void574nvc0_bufctx_fence(struct nvc0_context *nvc0, struct nouveau_bufctx *bufctx,575bool on_flush)576{577struct nouveau_list *list = on_flush ? &bufctx->current : &bufctx->pending;578struct nouveau_list *it;579NOUVEAU_DRV_STAT_IFD(unsigned count = 0);580581for (it = list->next; it != list; it = it->next) {582struct nouveau_bufref *ref = (struct nouveau_bufref *)it;583struct nv04_resource *res = ref->priv;584if (res)585nvc0_resource_validate(res, (unsigned)ref->priv_data);586NOUVEAU_DRV_STAT_IFD(count++);587}588NOUVEAU_DRV_STAT(&nvc0->screen->base, resource_validate_count, count);589}590591const void *592nvc0_get_sample_locations(unsigned sample_count)593{594static const uint8_t ms1[1][2] = { { 0x8, 0x8 } };595static const uint8_t ms2[2][2] = {596{ 0x4, 0x4 }, { 0xc, 0xc } }; /* surface coords (0,0), (1,0) */597static const uint8_t ms4[4][2] = {598{ 0x6, 0x2 }, { 0xe, 0x6 }, /* (0,0), (1,0) */599{ 0x2, 0xa }, { 0xa, 0xe } }; /* (0,1), (1,1) */600static const uint8_t ms8[8][2] = {601{ 0x1, 0x7 }, { 0x5, 0x3 }, /* (0,0), (1,0) */602{ 0x3, 0xd }, { 0x7, 0xb }, /* (0,1), (1,1) */603{ 0x9, 0x5 }, { 0xf, 0x1 }, /* (2,0), (3,0) */604{ 0xb, 0xf }, { 0xd, 0x9 } }; /* (2,1), (3,1) */605#if 0606/* NOTE: there are alternative modes for MS2 and MS8, currently not used */607static const uint8_t ms8_alt[8][2] = {608{ 0x9, 0x5 }, { 0x7, 0xb }, /* (2,0), (1,1) */609{ 0xd, 0x9 }, { 0x5, 0x3 }, /* (3,1), (1,0) */610{ 0x3, 0xd }, { 0x1, 0x7 }, /* (0,1), (0,0) */611{ 0xb, 0xf }, { 0xf, 0x1 } }; /* (2,1), (3,0) */612#endif613614const uint8_t (*ptr)[2];615616switch (sample_count) {617case 0:618case 1: ptr = ms1; break;619case 2: ptr = ms2; break;620case 4: ptr = ms4; break;621case 8: ptr = ms8; break;622default:623assert(0);624return NULL; /* bad sample count -> undefined locations */625}626return ptr;627}628629static void630nvc0_context_get_sample_position(struct pipe_context *pipe,631unsigned sample_count, unsigned sample_index,632float *xy)633{634const uint8_t (*ptr)[2];635636ptr = nvc0_get_sample_locations(sample_count);637if (!ptr)638return;639640xy[0] = ptr[sample_index][0] * 0.0625f;641xy[1] = ptr[sample_index][1] * 0.0625f;642}643644645