Path: blob/21.2-virgl/src/gallium/drivers/nouveau/nv50/nv50_resource.c
4574 views
1#include "pipe/p_context.h"2#include "util/u_inlines.h"3#include "util/format/u_format.h"45#include "nouveau_screen.h"67#include "nv50/nv50_resource.h"89static struct pipe_resource *10nv50_resource_create(struct pipe_screen *screen,11const struct pipe_resource *templ)12{13switch (templ->target) {14case PIPE_BUFFER:15return nouveau_buffer_create(screen, templ);16default:17return nv50_miptree_create(screen, templ);18}19}2021static void22nv50_resource_destroy(struct pipe_screen *pscreen, struct pipe_resource *res)23{24if (res->target == PIPE_BUFFER)25nouveau_buffer_destroy(pscreen, res);26else27nv50_miptree_destroy(pscreen, res);28}2930static struct pipe_resource *31nv50_resource_from_handle(struct pipe_screen * screen,32const struct pipe_resource *templ,33struct winsys_handle *whandle,34unsigned usage)35{36if (templ->target == PIPE_BUFFER)37return NULL;38else39return nv50_miptree_from_handle(screen, templ, whandle);40}4142struct pipe_surface *43nv50_surface_from_buffer(struct pipe_context *pipe,44struct pipe_resource *pbuf,45const struct pipe_surface *templ)46{47struct nv50_surface *sf = CALLOC_STRUCT(nv50_surface);48if (!sf)49return NULL;5051pipe_reference_init(&sf->base.reference, 1);52pipe_resource_reference(&sf->base.texture, pbuf);5354sf->base.format = templ->format;55sf->base.writable = templ->writable;56sf->base.u.buf.first_element = templ->u.buf.first_element;57sf->base.u.buf.last_element = templ->u.buf.last_element;5859sf->offset =60templ->u.buf.first_element * util_format_get_blocksize(sf->base.format);6162sf->offset &= ~0x7f; /* FIXME: RT_ADDRESS requires 128 byte alignment */6364sf->width = templ->u.buf.last_element - templ->u.buf.first_element + 1;65sf->height = 1;66sf->depth = 1;6768sf->base.width = sf->width;69sf->base.height = sf->height;7071sf->base.context = pipe;72return &sf->base;73}7475static struct pipe_surface *76nv50_surface_create(struct pipe_context *pipe,77struct pipe_resource *pres,78const struct pipe_surface *templ)79{80if (unlikely(pres->target == PIPE_BUFFER))81return nv50_surface_from_buffer(pipe, pres, templ);82return nv50_miptree_surface_new(pipe, pres, templ);83}8485void86nv50_surface_destroy(struct pipe_context *pipe, struct pipe_surface *ps)87{88struct nv50_surface *s = nv50_surface(ps);8990pipe_resource_reference(&ps->texture, NULL);9192FREE(s);93}9495void96nv50_invalidate_resource(struct pipe_context *pipe, struct pipe_resource *res)97{98if (res->target == PIPE_BUFFER)99nouveau_buffer_invalidate(pipe, res);100}101102void103nv50_init_resource_functions(struct pipe_context *pcontext)104{105pcontext->buffer_map = nouveau_buffer_transfer_map;106pcontext->texture_map = nv50_miptree_transfer_map;107pcontext->transfer_flush_region = nouveau_buffer_transfer_flush_region;108pcontext->buffer_unmap = nouveau_buffer_transfer_unmap;109pcontext->texture_unmap = nv50_miptree_transfer_unmap;110pcontext->buffer_subdata = u_default_buffer_subdata;111pcontext->texture_subdata = u_default_texture_subdata;112pcontext->create_surface = nv50_surface_create;113pcontext->surface_destroy = nv50_surface_destroy;114pcontext->invalidate_resource = nv50_invalidate_resource;115}116117void118nv50_screen_init_resource_functions(struct pipe_screen *pscreen)119{120pscreen->resource_create = nv50_resource_create;121pscreen->resource_from_handle = nv50_resource_from_handle;122pscreen->resource_get_handle = nv50_miptree_get_handle;123pscreen->resource_destroy = nv50_resource_destroy;124}125126127