Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/zink/zink_program.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_PROGRAM_H
25
#define ZINK_PROGRAM_H
26
27
#include <vulkan/vulkan.h>
28
29
#include "compiler/shader_enums.h"
30
#include "pipe/p_state.h"
31
#include "util/u_inlines.h"
32
33
#include "zink_context.h"
34
#include "zink_compiler.h"
35
#include "zink_shader_keys.h"
36
#ifdef __cplusplus
37
extern "C" {
38
#endif
39
40
struct zink_screen;
41
struct zink_shader;
42
struct zink_gfx_pipeline_state;
43
struct zink_descriptor_set;
44
45
struct hash_table;
46
struct set;
47
struct util_dynarray;
48
49
struct zink_program;
50
51
struct zink_gfx_push_constant {
52
unsigned draw_mode_is_indexed;
53
unsigned draw_id;
54
float default_inner_level[2];
55
float default_outer_level[4];
56
};
57
58
struct zink_cs_push_constant {
59
unsigned work_dim;
60
};
61
62
/* a shader module is used for directly reusing a shader module between programs,
63
* e.g., in the case where we're swapping out only one shader,
64
* allowing us to skip going through shader keys
65
*/
66
struct zink_shader_module {
67
VkShaderModule shader;
68
bool default_variant;
69
};
70
71
struct zink_program {
72
struct pipe_reference reference;
73
unsigned char sha1[20];
74
struct util_queue_fence cache_fence;
75
VkPipelineCache pipeline_cache;
76
size_t pipeline_cache_size;
77
struct zink_batch_usage *batch_uses;
78
bool is_compute;
79
80
struct zink_program_descriptor_data *dd;
81
82
VkPipelineLayout layout;
83
VkDescriptorSetLayout dsl[ZINK_DESCRIPTOR_TYPES + 1]; // one for each type + push
84
unsigned num_dsl;
85
86
/* the shader cache stores a mapping of zink_shader_key::VkShaderModule */
87
struct hash_table shader_cache[ZINK_SHADER_COUNT];
88
};
89
90
struct zink_gfx_program {
91
struct zink_program base;
92
93
uint32_t stages_present; //mask of stages present in this program
94
struct nir_shader *nir[ZINK_SHADER_COUNT];
95
96
struct zink_shader_module *modules[ZINK_SHADER_COUNT]; // compute stage doesn't belong here
97
98
struct zink_shader_module *default_variants[ZINK_SHADER_COUNT][2]; //[default, no streamout]
99
const void *default_variant_key[ZINK_SHADER_COUNT];
100
struct zink_shader *last_vertex_stage;
101
102
struct zink_shader *shaders[ZINK_SHADER_COUNT];
103
struct hash_table *pipelines[11]; // number of draw modes we support
104
uint32_t default_variant_hash;
105
};
106
107
struct zink_compute_program {
108
struct zink_program base;
109
110
struct zink_shader_module *module;
111
struct zink_shader *shader;
112
struct hash_table *pipelines;
113
};
114
115
static inline enum zink_descriptor_type
116
zink_desc_type_from_vktype(VkDescriptorType type)
117
{
118
switch (type) {
119
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
120
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
121
return ZINK_DESCRIPTOR_TYPE_UBO;
122
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
123
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
124
return ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW;
125
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
126
return ZINK_DESCRIPTOR_TYPE_SSBO;
127
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
128
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
129
return ZINK_DESCRIPTOR_TYPE_IMAGE;
130
default:
131
unreachable("unhandled descriptor type");
132
}
133
}
134
135
void
136
zink_delete_shader_state(struct pipe_context *pctx, void *cso);
137
void *
138
zink_create_gfx_shader_state(struct pipe_context *pctx, const struct pipe_shader_state *shader);
139
140
unsigned
141
zink_program_num_bindings_typed(const struct zink_program *pg, enum zink_descriptor_type type, bool is_compute);
142
143
unsigned
144
zink_program_num_bindings(const struct zink_program *pg, bool is_compute);
145
146
bool
147
zink_program_descriptor_is_buffer(struct zink_context *ctx, enum pipe_shader_type stage, enum zink_descriptor_type type, unsigned i);
148
149
void
150
zink_update_gfx_program(struct zink_context *ctx, struct zink_gfx_program *prog);
151
152
struct zink_gfx_program *
153
zink_create_gfx_program(struct zink_context *ctx,
154
struct zink_shader *stages[ZINK_SHADER_COUNT]);
155
156
void
157
zink_destroy_gfx_program(struct zink_screen *screen,
158
struct zink_gfx_program *prog);
159
160
VkPipeline
161
zink_get_gfx_pipeline(struct zink_context *ctx,
162
struct zink_gfx_program *prog,
163
struct zink_gfx_pipeline_state *state,
164
enum pipe_prim_type mode);
165
166
void
167
zink_program_init(struct zink_context *ctx);
168
169
uint32_t
170
zink_program_get_descriptor_usage(struct zink_context *ctx, enum pipe_shader_type stage, enum zink_descriptor_type type);
171
172
void
173
debug_describe_zink_gfx_program(char* buf, const struct zink_gfx_program *ptr);
174
175
static inline bool
176
zink_gfx_program_reference(struct zink_screen *screen,
177
struct zink_gfx_program **dst,
178
struct zink_gfx_program *src)
179
{
180
struct zink_gfx_program *old_dst = dst ? *dst : NULL;
181
bool ret = false;
182
183
if (pipe_reference_described(old_dst ? &old_dst->base.reference : NULL, &src->base.reference,
184
(debug_reference_descriptor)debug_describe_zink_gfx_program)) {
185
zink_destroy_gfx_program(screen, old_dst);
186
ret = true;
187
}
188
if (dst) *dst = src;
189
return ret;
190
}
191
192
struct zink_compute_program *
193
zink_create_compute_program(struct zink_context *ctx, struct zink_shader *shader);
194
void
195
zink_destroy_compute_program(struct zink_screen *screen,
196
struct zink_compute_program *comp);
197
198
void
199
debug_describe_zink_compute_program(char* buf, const struct zink_compute_program *ptr);
200
201
static inline bool
202
zink_compute_program_reference(struct zink_screen *screen,
203
struct zink_compute_program **dst,
204
struct zink_compute_program *src)
205
{
206
struct zink_compute_program *old_dst = dst ? *dst : NULL;
207
bool ret = false;
208
209
if (pipe_reference_described(old_dst ? &old_dst->base.reference : NULL, &src->base.reference,
210
(debug_reference_descriptor)debug_describe_zink_compute_program)) {
211
zink_destroy_compute_program(screen, old_dst);
212
ret = true;
213
}
214
if (dst) *dst = src;
215
return ret;
216
}
217
218
VkPipelineLayout
219
zink_pipeline_layout_create(struct zink_screen *screen, struct zink_program *pg);
220
221
void
222
zink_program_update_compute_pipeline_state(struct zink_context *ctx, struct zink_compute_program *comp, const uint block[3]);
223
224
VkPipeline
225
zink_get_compute_pipeline(struct zink_screen *screen,
226
struct zink_compute_program *comp,
227
struct zink_compute_pipeline_state *state);
228
229
static inline bool
230
zink_program_has_descriptors(const struct zink_program *pg)
231
{
232
return pg->num_dsl > 0;
233
}
234
#ifdef __cplusplus
235
}
236
#endif
237
238
#endif
239
240