Path: blob/21.2-virgl/src/gallium/drivers/virgl/virgl_resource.h
4570 views
/*1* Copyright 2014, 2015 Red Hat.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* on the rights to use, copy, modify, merge, publish, distribute, sub7* license, and/or sell copies of the Software, and to permit persons to whom8* the Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE.21*/2223#ifndef VIRGL_RESOURCE_H24#define VIRGL_RESOURCE_H2526#include "util/u_resource.h"27#include "util/u_range.h"28#include "util/list.h"29#include "util/u_transfer.h"3031#include "virtio-gpu/virgl_hw.h"32#include "virgl_screen.h"33#define VR_MAX_TEXTURE_2D_LEVELS 153435#define VIRGL_BLOB_MEM_GUEST 136#define VIRGL_BLOB_MEM_HOST3D 237#define VIRGL_BLOB_MEM_HOST3D_GUEST 33839struct winsys_handle;40struct virgl_screen;41struct virgl_context;4243struct virgl_resource_metadata44{45unsigned long level_offset[VR_MAX_TEXTURE_2D_LEVELS];46unsigned stride[VR_MAX_TEXTURE_2D_LEVELS];47unsigned layer_stride[VR_MAX_TEXTURE_2D_LEVELS];48uint32_t plane, plane_offset, total_size;49uint64_t modifier;50};5152struct virgl_resource {53struct pipe_resource b;54uint16_t clean_mask;55struct virgl_hw_res *hw_res;56struct virgl_resource_metadata metadata;5758/* For PIPE_BUFFER only. Data outside of this range are uninitialized. */59struct util_range valid_buffer_range;6061/* This mask indicates where the resource has been bound to, excluding62* pipe_surface binds.63*64* This is more accurate than pipe_resource::bind. Besides,65* pipe_resource::bind can be 0 with direct state access, and is not66* usable.67*/68unsigned bind_history;69uint32_t blob_mem;70};7172struct virgl_transfer {73struct pipe_transfer base;74uint32_t offset, l_stride;75struct util_range range;76struct list_head queue_link;77struct pipe_transfer *resolve_transfer;7879struct virgl_hw_res *hw_res;80void *hw_res_map;81/* If not NULL, denotes that this is a copy transfer, i.e.,82* that the transfer source data should be taken from this83* resource instead of the original transfer resource.84*/85struct virgl_hw_res *copy_src_hw_res;86/* The offset in the copy source resource to copy data from. */87uint32_t copy_src_offset;88};8990void virgl_resource_destroy(struct pipe_screen *screen,91struct pipe_resource *resource);9293void virgl_init_screen_resource_functions(struct pipe_screen *screen);9495void virgl_init_context_resource_functions(struct pipe_context *ctx);9697void virgl_texture_init(struct virgl_resource *res);9899static inline struct virgl_resource *virgl_resource(struct pipe_resource *r)100{101return (struct virgl_resource *)r;102}103104static inline struct virgl_transfer *virgl_transfer(struct pipe_transfer *trans)105{106return (struct virgl_transfer *)trans;107}108109void virgl_buffer_transfer_flush_region(struct pipe_context *ctx,110struct pipe_transfer *transfer,111const struct pipe_box *box);112113void virgl_buffer_transfer_unmap(struct pipe_context *ctx,114struct pipe_transfer *transfer);115116void virgl_buffer_init(struct virgl_resource *res);117118static inline unsigned pipe_to_virgl_bind(const struct virgl_screen *vs,119unsigned pbind)120{121unsigned outbind = 0;122if (pbind & PIPE_BIND_DEPTH_STENCIL)123outbind |= VIRGL_BIND_DEPTH_STENCIL;124if (pbind & PIPE_BIND_RENDER_TARGET)125outbind |= VIRGL_BIND_RENDER_TARGET;126if (pbind & PIPE_BIND_SAMPLER_VIEW)127outbind |= VIRGL_BIND_SAMPLER_VIEW;128if (pbind & PIPE_BIND_VERTEX_BUFFER)129outbind |= VIRGL_BIND_VERTEX_BUFFER;130if (pbind & PIPE_BIND_INDEX_BUFFER)131outbind |= VIRGL_BIND_INDEX_BUFFER;132if (pbind & PIPE_BIND_CONSTANT_BUFFER)133outbind |= VIRGL_BIND_CONSTANT_BUFFER;134if (pbind & PIPE_BIND_DISPLAY_TARGET)135outbind |= VIRGL_BIND_DISPLAY_TARGET;136if (pbind & PIPE_BIND_STREAM_OUTPUT)137outbind |= VIRGL_BIND_STREAM_OUTPUT;138if (pbind & PIPE_BIND_CURSOR)139outbind |= VIRGL_BIND_CURSOR;140if (pbind & PIPE_BIND_CUSTOM)141outbind |= VIRGL_BIND_CUSTOM;142if (pbind & PIPE_BIND_SCANOUT)143outbind |= VIRGL_BIND_SCANOUT;144if (pbind & PIPE_BIND_SHARED)145outbind |= VIRGL_BIND_SHARED;146if (pbind & PIPE_BIND_SHADER_BUFFER)147outbind |= VIRGL_BIND_SHADER_BUFFER;148if (pbind & PIPE_BIND_QUERY_BUFFER)149outbind |= VIRGL_BIND_QUERY_BUFFER;150if (pbind & PIPE_BIND_COMMAND_ARGS_BUFFER)151if (vs->caps.caps.v2.capability_bits & VIRGL_CAP_BIND_COMMAND_ARGS)152outbind |= VIRGL_BIND_COMMAND_ARGS;153154/* Staging resources should only be created directly through the winsys,155* not using pipe_resources.156*/157assert(!(outbind & VIRGL_BIND_STAGING));158159return outbind;160}161162static inline unsigned pipe_to_virgl_flags(const struct virgl_screen *vs,163unsigned pflags)164{165unsigned out_flags = 0;166if (pflags & PIPE_RESOURCE_FLAG_MAP_PERSISTENT)167out_flags |= VIRGL_RESOURCE_FLAG_MAP_PERSISTENT;168169if (pflags & PIPE_RESOURCE_FLAG_MAP_COHERENT)170out_flags |= VIRGL_RESOURCE_FLAG_MAP_COHERENT;171172return out_flags;173}174175void *176virgl_resource_transfer_map(struct pipe_context *ctx,177struct pipe_resource *resource,178unsigned level,179unsigned usage,180const struct pipe_box *box,181struct pipe_transfer **transfer);182183struct virgl_transfer *184virgl_resource_create_transfer(struct virgl_context *vctx,185struct pipe_resource *pres,186const struct virgl_resource_metadata *metadata,187unsigned level, unsigned usage,188const struct pipe_box *box);189190void virgl_resource_destroy_transfer(struct virgl_context *vctx,191struct virgl_transfer *trans);192193void virgl_resource_destroy(struct pipe_screen *screen,194struct pipe_resource *resource);195196bool virgl_resource_get_handle(struct pipe_screen *screen,197struct pipe_context *context,198struct pipe_resource *resource,199struct winsys_handle *whandle,200unsigned usage);201202void virgl_resource_dirty(struct virgl_resource *res, uint32_t level);203204void *virgl_texture_transfer_map(struct pipe_context *ctx,205struct pipe_resource *resource,206unsigned level,207unsigned usage,208const struct pipe_box *box,209struct pipe_transfer **transfer);210211void virgl_texture_transfer_unmap(struct pipe_context *ctx,212struct pipe_transfer *transfer);213214#endif215216217