Path: blob/21.2-virgl/src/gallium/drivers/zink/zink_surface.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_SURFACE_H24#define ZINK_SURFACE_H2526#include "pipe/p_state.h"27#include "zink_batch.h"28#include <vulkan/vulkan.h>2930struct pipe_context;3132struct zink_surface {33struct pipe_surface base;34VkImageViewCreateInfo ivci;35VkImageView image_view;36VkImageView simage_view;//old iview after storage replacement/rebind37void *obj; //backing resource object38uint32_t hash;39struct zink_batch_usage *batch_uses;40struct util_dynarray framebuffer_refs;41struct zink_descriptor_refs desc_set_refs;42};4344static inline struct zink_surface *45zink_surface(struct pipe_surface *pipe)46{47return (struct zink_surface *)pipe;48}4950void51zink_destroy_surface(struct zink_screen *screen, struct pipe_surface *psurface);5253static inline void54zink_surface_reference(struct zink_screen *screen, struct zink_surface **dst, struct zink_surface *src)55{56struct zink_surface *old_dst = *dst;5758if (pipe_reference_described(old_dst ? &old_dst->base.reference : NULL,59src ? &src->base.reference : NULL,60(debug_reference_descriptor)61debug_describe_surface))62zink_destroy_surface(screen, &old_dst->base);63*dst = src;64}6566void67zink_context_surface_init(struct pipe_context *context);6869VkImageViewCreateInfo70create_ivci(struct zink_screen *screen,71struct zink_resource *res,72const struct pipe_surface *templ,73enum pipe_texture_target target);7475struct pipe_surface *76zink_get_surface(struct zink_context *ctx,77struct pipe_resource *pres,78const struct pipe_surface *templ,79VkImageViewCreateInfo *ivci);8081static inline VkImageViewType82zink_surface_clamp_viewtype(VkImageViewType viewType, unsigned first_layer, unsigned last_layer, unsigned array_size)83{84unsigned layerCount = 1 + last_layer - first_layer;85if (viewType == VK_IMAGE_VIEW_TYPE_CUBE || viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) {86if (first_layer == last_layer)87return VK_IMAGE_VIEW_TYPE_2D;88if (layerCount % 6 == 0) {89if (viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY && layerCount == 6)90return VK_IMAGE_VIEW_TYPE_CUBE;91} else if (first_layer || layerCount != array_size)92return VK_IMAGE_VIEW_TYPE_2D_ARRAY;93} else if (viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY) {94if (first_layer == last_layer)95return VK_IMAGE_VIEW_TYPE_2D;96}97return viewType;98}99100bool101zink_rebind_surface(struct zink_context *ctx, struct pipe_surface **psurface);102103struct pipe_surface *104zink_surface_create_null(struct zink_context *ctx, enum pipe_texture_target target, unsigned width, unsigned height, unsigned samples);105#endif106107108