Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/zink/zink_resource.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_RESOURCE_H
25
#define ZINK_RESOURCE_H
26
27
struct pipe_screen;
28
struct sw_displaytarget;
29
struct zink_batch;
30
struct zink_context;
31
32
#define ZINK_RESOURCE_USAGE_STREAMOUT (1 << 10) //much greater than ZINK_DESCRIPTOR_TYPES
33
34
#include "util/simple_mtx.h"
35
#include "util/u_transfer.h"
36
#include "util/u_range.h"
37
#include "util/u_dynarray.h"
38
#include "util/u_threaded_context.h"
39
40
#include "zink_batch.h"
41
#include "zink_descriptors.h"
42
43
#include <vulkan/vulkan.h>
44
45
#define ZINK_MAP_TEMPORARY (PIPE_MAP_DRV_PRV << 0)
46
47
enum zink_resource_access {
48
ZINK_RESOURCE_ACCESS_READ = 1,
49
ZINK_RESOURCE_ACCESS_WRITE = 32,
50
ZINK_RESOURCE_ACCESS_RW = ZINK_RESOURCE_ACCESS_READ | ZINK_RESOURCE_ACCESS_WRITE,
51
};
52
53
struct mem_key {
54
unsigned seen_count;
55
struct {
56
unsigned heap_index;
57
VkMemoryRequirements reqs;
58
} key;
59
};
60
61
struct zink_resource_object {
62
struct pipe_reference reference;
63
union {
64
VkBuffer buffer;
65
VkImage image;
66
};
67
68
VkBuffer sbuffer;
69
bool storage_init; //layout was set for image
70
bool transfer_dst;
71
VkImageAspectFlags modifier_aspect;
72
73
VkDeviceMemory mem;
74
uint32_t mem_hash;
75
struct mem_key mkey;
76
VkDeviceSize offset, size;
77
78
VkSampleLocationsInfoEXT zs_evaluate;
79
bool needs_zs_evaluate;
80
81
unsigned persistent_maps; //if nonzero, requires vkFlushMappedMemoryRanges during batch use
82
struct zink_descriptor_refs desc_set_refs;
83
84
struct zink_batch_usage *reads;
85
struct zink_batch_usage *writes;
86
void *map;
87
unsigned map_count;
88
bool is_buffer;
89
bool host_visible;
90
bool coherent;
91
};
92
93
struct zink_resource {
94
struct threaded_resource base;
95
96
enum pipe_format internal_format:16;
97
98
VkPipelineStageFlagBits access_stage;
99
VkAccessFlags access;
100
bool unordered_barrier;
101
102
struct zink_resource_object *obj;
103
struct zink_resource_object *scanout_obj; //TODO: remove for wsi
104
bool scanout_obj_init;
105
union {
106
struct {
107
struct util_range valid_buffer_range;
108
uint16_t vbo_bind_count;
109
uint8_t ubo_bind_count[2];
110
uint32_t ubo_bind_mask[PIPE_SHADER_TYPES];
111
uint32_t ssbo_bind_mask[PIPE_SHADER_TYPES];
112
};
113
struct {
114
VkFormat format;
115
VkImageLayout layout;
116
VkImageAspectFlags aspect;
117
bool optimal_tiling;
118
uint8_t fb_binds;
119
};
120
};
121
uint32_t sampler_binds[PIPE_SHADER_TYPES];
122
uint16_t image_bind_count[2]; //gfx, compute
123
uint16_t write_bind_count[2]; //gfx, compute
124
uint16_t bind_count[2]; //gfx, compute
125
126
struct sw_displaytarget *dt;
127
unsigned dt_stride;
128
129
uint32_t bind_history; // enum zink_descriptor_type bitmask
130
uint32_t bind_stages;
131
132
uint8_t modifiers_count;
133
uint64_t *modifiers;
134
};
135
136
struct zink_transfer {
137
struct threaded_transfer base;
138
struct pipe_resource *staging_res;
139
unsigned offset;
140
unsigned depthPitch;
141
};
142
143
static inline struct zink_resource *
144
zink_resource(struct pipe_resource *r)
145
{
146
return (struct zink_resource *)r;
147
}
148
149
bool
150
zink_screen_resource_init(struct pipe_screen *pscreen);
151
152
void
153
zink_context_resource_init(struct pipe_context *pctx);
154
155
void
156
zink_get_depth_stencil_resources(struct pipe_resource *res,
157
struct zink_resource **out_z,
158
struct zink_resource **out_s);
159
VkMappedMemoryRange
160
zink_resource_init_mem_range(struct zink_screen *screen, struct zink_resource_object *obj, VkDeviceSize offset, VkDeviceSize size);
161
void
162
zink_resource_setup_transfer_layouts(struct zink_context *ctx, struct zink_resource *src, struct zink_resource *dst);
163
164
bool
165
zink_resource_has_usage(struct zink_resource *res, enum zink_resource_access usage);
166
167
void
168
zink_destroy_resource_object(struct zink_screen *screen, struct zink_resource_object *resource_object);
169
170
void
171
debug_describe_zink_resource_object(char *buf, const struct zink_resource_object *ptr);
172
173
static inline void
174
zink_resource_object_reference(struct zink_screen *screen,
175
struct zink_resource_object **dst,
176
struct zink_resource_object *src)
177
{
178
struct zink_resource_object *old_dst = dst ? *dst : NULL;
179
180
if (pipe_reference_described(old_dst ? &old_dst->reference : NULL, &src->reference,
181
(debug_reference_descriptor)debug_describe_zink_resource_object))
182
zink_destroy_resource_object(screen, old_dst);
183
if (dst) *dst = src;
184
}
185
186
bool
187
zink_resource_object_init_storage(struct zink_context *ctx, struct zink_resource *res);
188
#endif
189
190