Path: blob/21.2-virgl/src/gallium/drivers/nouveau/nv30/nv30_resource.c
4574 views
/*1* Copyright 2012 Red Hat Inc.2*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*21* Authors: Ben Skeggs22*23*/2425#include "util/format/u_format.h"26#include "util/u_inlines.h"2728#include "nv30/nv30_screen.h"29#include "nv30/nv30_context.h"30#include "nv30/nv30_resource.h"31#include "nv30/nv30_transfer.h"3233static void34nv30_memory_barrier(struct pipe_context *pipe, unsigned flags)35{36struct nv30_context *nv30 = nv30_context(pipe);37int i;3839if (flags & PIPE_BARRIER_MAPPED_BUFFER) {40for (i = 0; i < nv30->num_vtxbufs; ++i) {41if (!nv30->vtxbuf[i].buffer.resource)42continue;43if (nv30->vtxbuf[i].buffer.resource->flags & PIPE_RESOURCE_FLAG_MAP_PERSISTENT)44nv30->base.vbo_dirty = true;45}46}47}4849static struct pipe_resource *50nv30_resource_create(struct pipe_screen *pscreen,51const struct pipe_resource *tmpl)52{53switch (tmpl->target) {54case PIPE_BUFFER:55return nouveau_buffer_create(pscreen, tmpl);56default:57return nv30_miptree_create(pscreen, tmpl);58}59}6061static void62nv30_resource_destroy(struct pipe_screen *pscreen, struct pipe_resource *res)63{64if (res->target == PIPE_BUFFER)65nouveau_buffer_destroy(pscreen, res);66else67nv30_miptree_destroy(pscreen, res);68}6970static struct pipe_resource *71nv30_resource_from_handle(struct pipe_screen *pscreen,72const struct pipe_resource *tmpl,73struct winsys_handle *handle,74unsigned usage)75{76if (tmpl->target == PIPE_BUFFER)77return NULL;78else79return nv30_miptree_from_handle(pscreen, tmpl, handle);80}8182void83nv30_resource_screen_init(struct pipe_screen *pscreen)84{85pscreen->resource_create = nv30_resource_create;86pscreen->resource_from_handle = nv30_resource_from_handle;87pscreen->resource_get_handle = nv30_miptree_get_handle;88pscreen->resource_destroy = nv30_resource_destroy;89}9091void92nv30_resource_init(struct pipe_context *pipe)93{94pipe->buffer_map = nouveau_buffer_transfer_map;95pipe->texture_map = nv30_miptree_transfer_map;96pipe->transfer_flush_region = nouveau_buffer_transfer_flush_region;97pipe->buffer_unmap = nouveau_buffer_transfer_unmap;98pipe->texture_unmap = nv30_miptree_transfer_unmap;99pipe->buffer_subdata = u_default_buffer_subdata;100pipe->texture_subdata = u_default_texture_subdata;101pipe->create_surface = nv30_miptree_surface_new;102pipe->surface_destroy = nv30_miptree_surface_del;103pipe->resource_copy_region = nv30_resource_copy_region;104pipe->blit = nv30_blit;105pipe->flush_resource = nv30_flush_resource;106pipe->memory_barrier = nv30_memory_barrier;107}108109110