Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/zink/zink_surface.h
4570 views
1
/*
2
* Copyright 2018 Collabora Ltd.
3
*
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* on the rights to use, copy, modify, merge, publish, distribute, sub
8
* license, and/or sell copies of the Software, and to permit persons to whom
9
* the Software is furnished to do so, subject to the following conditions:
10
*
11
* The above copyright notice and this permission notice (including the next
12
* paragraph) shall be included in all copies or substantial portions of the
13
* Software.
14
*
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18
* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21
* USE OR OTHER DEALINGS IN THE SOFTWARE.
22
*/
23
24
#ifndef ZINK_SURFACE_H
25
#define ZINK_SURFACE_H
26
27
#include "pipe/p_state.h"
28
#include "zink_batch.h"
29
#include <vulkan/vulkan.h>
30
31
struct pipe_context;
32
33
struct zink_surface {
34
struct pipe_surface base;
35
VkImageViewCreateInfo ivci;
36
VkImageView image_view;
37
VkImageView simage_view;//old iview after storage replacement/rebind
38
void *obj; //backing resource object
39
uint32_t hash;
40
struct zink_batch_usage *batch_uses;
41
struct util_dynarray framebuffer_refs;
42
struct zink_descriptor_refs desc_set_refs;
43
};
44
45
static inline struct zink_surface *
46
zink_surface(struct pipe_surface *pipe)
47
{
48
return (struct zink_surface *)pipe;
49
}
50
51
void
52
zink_destroy_surface(struct zink_screen *screen, struct pipe_surface *psurface);
53
54
static inline void
55
zink_surface_reference(struct zink_screen *screen, struct zink_surface **dst, struct zink_surface *src)
56
{
57
struct zink_surface *old_dst = *dst;
58
59
if (pipe_reference_described(old_dst ? &old_dst->base.reference : NULL,
60
src ? &src->base.reference : NULL,
61
(debug_reference_descriptor)
62
debug_describe_surface))
63
zink_destroy_surface(screen, &old_dst->base);
64
*dst = src;
65
}
66
67
void
68
zink_context_surface_init(struct pipe_context *context);
69
70
VkImageViewCreateInfo
71
create_ivci(struct zink_screen *screen,
72
struct zink_resource *res,
73
const struct pipe_surface *templ,
74
enum pipe_texture_target target);
75
76
struct pipe_surface *
77
zink_get_surface(struct zink_context *ctx,
78
struct pipe_resource *pres,
79
const struct pipe_surface *templ,
80
VkImageViewCreateInfo *ivci);
81
82
static inline VkImageViewType
83
zink_surface_clamp_viewtype(VkImageViewType viewType, unsigned first_layer, unsigned last_layer, unsigned array_size)
84
{
85
unsigned layerCount = 1 + last_layer - first_layer;
86
if (viewType == VK_IMAGE_VIEW_TYPE_CUBE || viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) {
87
if (first_layer == last_layer)
88
return VK_IMAGE_VIEW_TYPE_2D;
89
if (layerCount % 6 == 0) {
90
if (viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY && layerCount == 6)
91
return VK_IMAGE_VIEW_TYPE_CUBE;
92
} else if (first_layer || layerCount != array_size)
93
return VK_IMAGE_VIEW_TYPE_2D_ARRAY;
94
} else if (viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY) {
95
if (first_layer == last_layer)
96
return VK_IMAGE_VIEW_TYPE_2D;
97
}
98
return viewType;
99
}
100
101
bool
102
zink_rebind_surface(struct zink_context *ctx, struct pipe_surface **psurface);
103
104
struct pipe_surface *
105
zink_surface_create_null(struct zink_context *ctx, enum pipe_texture_target target, unsigned width, unsigned height, unsigned samples);
106
#endif
107
108