Path: blob/21.2-virgl/src/gallium/drivers/zink/zink_resource.h
4570 views
/*1* Copyright 2018 Collabora Ltd.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 ZINK_RESOURCE_H24#define ZINK_RESOURCE_H2526struct pipe_screen;27struct sw_displaytarget;28struct zink_batch;29struct zink_context;3031#define ZINK_RESOURCE_USAGE_STREAMOUT (1 << 10) //much greater than ZINK_DESCRIPTOR_TYPES3233#include "util/simple_mtx.h"34#include "util/u_transfer.h"35#include "util/u_range.h"36#include "util/u_dynarray.h"37#include "util/u_threaded_context.h"3839#include "zink_batch.h"40#include "zink_descriptors.h"4142#include <vulkan/vulkan.h>4344#define ZINK_MAP_TEMPORARY (PIPE_MAP_DRV_PRV << 0)4546enum zink_resource_access {47ZINK_RESOURCE_ACCESS_READ = 1,48ZINK_RESOURCE_ACCESS_WRITE = 32,49ZINK_RESOURCE_ACCESS_RW = ZINK_RESOURCE_ACCESS_READ | ZINK_RESOURCE_ACCESS_WRITE,50};5152struct mem_key {53unsigned seen_count;54struct {55unsigned heap_index;56VkMemoryRequirements reqs;57} key;58};5960struct zink_resource_object {61struct pipe_reference reference;62union {63VkBuffer buffer;64VkImage image;65};6667VkBuffer sbuffer;68bool storage_init; //layout was set for image69bool transfer_dst;70VkImageAspectFlags modifier_aspect;7172VkDeviceMemory mem;73uint32_t mem_hash;74struct mem_key mkey;75VkDeviceSize offset, size;7677VkSampleLocationsInfoEXT zs_evaluate;78bool needs_zs_evaluate;7980unsigned persistent_maps; //if nonzero, requires vkFlushMappedMemoryRanges during batch use81struct zink_descriptor_refs desc_set_refs;8283struct zink_batch_usage *reads;84struct zink_batch_usage *writes;85void *map;86unsigned map_count;87bool is_buffer;88bool host_visible;89bool coherent;90};9192struct zink_resource {93struct threaded_resource base;9495enum pipe_format internal_format:16;9697VkPipelineStageFlagBits access_stage;98VkAccessFlags access;99bool unordered_barrier;100101struct zink_resource_object *obj;102struct zink_resource_object *scanout_obj; //TODO: remove for wsi103bool scanout_obj_init;104union {105struct {106struct util_range valid_buffer_range;107uint16_t vbo_bind_count;108uint8_t ubo_bind_count[2];109uint32_t ubo_bind_mask[PIPE_SHADER_TYPES];110uint32_t ssbo_bind_mask[PIPE_SHADER_TYPES];111};112struct {113VkFormat format;114VkImageLayout layout;115VkImageAspectFlags aspect;116bool optimal_tiling;117uint8_t fb_binds;118};119};120uint32_t sampler_binds[PIPE_SHADER_TYPES];121uint16_t image_bind_count[2]; //gfx, compute122uint16_t write_bind_count[2]; //gfx, compute123uint16_t bind_count[2]; //gfx, compute124125struct sw_displaytarget *dt;126unsigned dt_stride;127128uint32_t bind_history; // enum zink_descriptor_type bitmask129uint32_t bind_stages;130131uint8_t modifiers_count;132uint64_t *modifiers;133};134135struct zink_transfer {136struct threaded_transfer base;137struct pipe_resource *staging_res;138unsigned offset;139unsigned depthPitch;140};141142static inline struct zink_resource *143zink_resource(struct pipe_resource *r)144{145return (struct zink_resource *)r;146}147148bool149zink_screen_resource_init(struct pipe_screen *pscreen);150151void152zink_context_resource_init(struct pipe_context *pctx);153154void155zink_get_depth_stencil_resources(struct pipe_resource *res,156struct zink_resource **out_z,157struct zink_resource **out_s);158VkMappedMemoryRange159zink_resource_init_mem_range(struct zink_screen *screen, struct zink_resource_object *obj, VkDeviceSize offset, VkDeviceSize size);160void161zink_resource_setup_transfer_layouts(struct zink_context *ctx, struct zink_resource *src, struct zink_resource *dst);162163bool164zink_resource_has_usage(struct zink_resource *res, enum zink_resource_access usage);165166void167zink_destroy_resource_object(struct zink_screen *screen, struct zink_resource_object *resource_object);168169void170debug_describe_zink_resource_object(char *buf, const struct zink_resource_object *ptr);171172static inline void173zink_resource_object_reference(struct zink_screen *screen,174struct zink_resource_object **dst,175struct zink_resource_object *src)176{177struct zink_resource_object *old_dst = dst ? *dst : NULL;178179if (pipe_reference_described(old_dst ? &old_dst->reference : NULL, &src->reference,180(debug_reference_descriptor)debug_describe_zink_resource_object))181zink_destroy_resource_object(screen, old_dst);182if (dst) *dst = src;183}184185bool186zink_resource_object_init_storage(struct zink_context *ctx, struct zink_resource *res);187#endif188189190