Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/drivers/d3d12/rendering_shader_container_d3d12.cpp
9973 views
1
/**************************************************************************/
2
/* rendering_shader_container_d3d12.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "rendering_shader_container_d3d12.h"
32
33
#include "core/templates/sort_array.h"
34
35
#include "dxil_hash.h"
36
37
#include <zlib.h>
38
39
#ifndef _MSC_VER
40
// Match current version used by MinGW, MSVC and Direct3D 12 headers use 500.
41
#define __REQUIRED_RPCNDR_H_VERSION__ 475
42
#endif
43
44
#include <d3dx12.h>
45
#include <dxgi1_6.h>
46
#define D3D12MA_D3D12_HEADERS_ALREADY_INCLUDED
47
#include <D3D12MemAlloc.h>
48
49
#include <wrl/client.h>
50
51
#if defined(_MSC_VER) && defined(MemoryBarrier)
52
// Annoying define from winnt.h. Reintroduced by some of the headers above.
53
#undef MemoryBarrier
54
#endif
55
56
GODOT_GCC_WARNING_PUSH
57
GODOT_GCC_WARNING_IGNORE("-Wimplicit-fallthrough")
58
GODOT_GCC_WARNING_IGNORE("-Wlogical-not-parentheses")
59
GODOT_GCC_WARNING_IGNORE("-Wmissing-field-initializers")
60
GODOT_GCC_WARNING_IGNORE("-Wnon-virtual-dtor")
61
GODOT_GCC_WARNING_IGNORE("-Wshadow")
62
GODOT_GCC_WARNING_IGNORE("-Wswitch")
63
GODOT_CLANG_WARNING_PUSH
64
GODOT_CLANG_WARNING_IGNORE("-Wimplicit-fallthrough")
65
GODOT_CLANG_WARNING_IGNORE("-Wlogical-not-parentheses")
66
GODOT_CLANG_WARNING_IGNORE("-Wmissing-field-initializers")
67
GODOT_CLANG_WARNING_IGNORE("-Wnon-virtual-dtor")
68
GODOT_CLANG_WARNING_IGNORE("-Wstring-plus-int")
69
GODOT_CLANG_WARNING_IGNORE("-Wswitch")
70
GODOT_MSVC_WARNING_PUSH
71
GODOT_MSVC_WARNING_IGNORE(4200) // "nonstandard extension used: zero-sized array in struct/union".
72
GODOT_MSVC_WARNING_IGNORE(4806) // "'&': unsafe operation: no value of type 'bool' promoted to type 'uint32_t' can equal the given constant".
73
74
#include <nir_spirv.h>
75
#include <nir_to_dxil.h>
76
#include <spirv_to_dxil.h>
77
extern "C" {
78
#include <dxil_spirv_nir.h>
79
}
80
81
GODOT_GCC_WARNING_POP
82
GODOT_CLANG_WARNING_POP
83
GODOT_MSVC_WARNING_POP
84
85
static D3D12_SHADER_VISIBILITY stages_to_d3d12_visibility(uint32_t p_stages_mask) {
86
switch (p_stages_mask) {
87
case RenderingDeviceCommons::SHADER_STAGE_VERTEX_BIT:
88
return D3D12_SHADER_VISIBILITY_VERTEX;
89
case RenderingDeviceCommons::SHADER_STAGE_FRAGMENT_BIT:
90
return D3D12_SHADER_VISIBILITY_PIXEL;
91
default:
92
return D3D12_SHADER_VISIBILITY_ALL;
93
}
94
}
95
96
uint32_t RenderingDXIL::patch_specialization_constant(
97
RenderingDeviceCommons::PipelineSpecializationConstantType p_type,
98
const void *p_value,
99
const uint64_t (&p_stages_bit_offsets)[D3D12_BITCODE_OFFSETS_NUM_STAGES],
100
HashMap<RenderingDeviceCommons::ShaderStage, Vector<uint8_t>> &r_stages_bytecodes,
101
bool p_is_first_patch) {
102
uint32_t patch_val = 0;
103
switch (p_type) {
104
case RenderingDeviceCommons::PIPELINE_SPECIALIZATION_CONSTANT_TYPE_INT: {
105
uint32_t int_value = *((const int *)p_value);
106
ERR_FAIL_COND_V(int_value & (1 << 31), 0);
107
patch_val = int_value;
108
} break;
109
case RenderingDeviceCommons::PIPELINE_SPECIALIZATION_CONSTANT_TYPE_BOOL: {
110
bool bool_value = *((const bool *)p_value);
111
patch_val = (uint32_t)bool_value;
112
} break;
113
case RenderingDeviceCommons::PIPELINE_SPECIALIZATION_CONSTANT_TYPE_FLOAT: {
114
uint32_t int_value = *((const int *)p_value);
115
ERR_FAIL_COND_V(int_value & (1 << 31), 0);
116
patch_val = (int_value >> 1);
117
} break;
118
}
119
// For VBR encoding to encode the number of bits we expect (32), we need to set the MSB unconditionally.
120
// However, signed VBR moves the MSB to the LSB, so setting the MSB to 1 wouldn't help. Therefore,
121
// the bit we set to 1 is the one at index 30.
122
patch_val |= (1 << 30);
123
patch_val <<= 1; // What signed VBR does.
124
125
auto tamper_bits = [](uint8_t *p_start, uint64_t p_bit_offset, uint64_t p_tb_value) -> uint64_t {
126
uint64_t original = 0;
127
uint32_t curr_input_byte = p_bit_offset / 8;
128
uint8_t curr_input_bit = p_bit_offset % 8;
129
auto get_curr_input_bit = [&]() -> bool {
130
return ((p_start[curr_input_byte] >> curr_input_bit) & 1);
131
};
132
auto move_to_next_input_bit = [&]() {
133
if (curr_input_bit == 7) {
134
curr_input_bit = 0;
135
curr_input_byte++;
136
} else {
137
curr_input_bit++;
138
}
139
};
140
auto tamper_input_bit = [&](bool p_new_bit) {
141
p_start[curr_input_byte] &= ~((uint8_t)1 << curr_input_bit);
142
if (p_new_bit) {
143
p_start[curr_input_byte] |= (uint8_t)1 << curr_input_bit;
144
}
145
};
146
uint8_t value_bit_idx = 0;
147
for (uint32_t i = 0; i < 5; i++) { // 32 bits take 5 full bytes in VBR.
148
for (uint32_t j = 0; j < 7; j++) {
149
bool input_bit = get_curr_input_bit();
150
original |= (uint64_t)(input_bit ? 1 : 0) << value_bit_idx;
151
tamper_input_bit((p_tb_value >> value_bit_idx) & 1);
152
move_to_next_input_bit();
153
value_bit_idx++;
154
}
155
#ifdef DEV_ENABLED
156
bool input_bit = get_curr_input_bit();
157
DEV_ASSERT((i < 4 && input_bit) || (i == 4 && !input_bit));
158
#endif
159
move_to_next_input_bit();
160
}
161
return original;
162
};
163
uint32_t stages_patched_mask = 0;
164
for (int stage = 0; stage < RenderingDeviceCommons::SHADER_STAGE_MAX; stage++) {
165
if (!r_stages_bytecodes.has((RenderingDeviceCommons::ShaderStage)stage)) {
166
continue;
167
}
168
169
uint64_t offset = p_stages_bit_offsets[RenderingShaderContainerD3D12::SHADER_STAGES_BIT_OFFSET_INDICES[stage]];
170
if (offset == 0) {
171
// This constant does not appear at this stage.
172
continue;
173
}
174
175
Vector<uint8_t> &bytecode = r_stages_bytecodes[(RenderingDeviceCommons::ShaderStage)stage];
176
#ifdef DEV_ENABLED
177
uint64_t orig_patch_val = tamper_bits(bytecode.ptrw(), offset, patch_val);
178
// Checking against the value the NIR patch should have set.
179
DEV_ASSERT(!p_is_first_patch || ((orig_patch_val >> 1) & GODOT_NIR_SC_SENTINEL_MAGIC_MASK) == GODOT_NIR_SC_SENTINEL_MAGIC);
180
uint64_t readback_patch_val = tamper_bits(bytecode.ptrw(), offset, patch_val);
181
DEV_ASSERT(readback_patch_val == patch_val);
182
#else
183
tamper_bits(bytecode.ptrw(), offset, patch_val);
184
#endif
185
186
stages_patched_mask |= (1 << stage);
187
}
188
189
return stages_patched_mask;
190
}
191
192
void RenderingDXIL::sign_bytecode(RenderingDeviceCommons::ShaderStage p_stage, Vector<uint8_t> &r_dxil_blob) {
193
uint8_t *w = r_dxil_blob.ptrw();
194
compute_dxil_hash(w + 20, r_dxil_blob.size() - 20, w + 4);
195
}
196
197
// RenderingShaderContainerD3D12
198
199
uint32_t RenderingShaderContainerD3D12::_format() const {
200
return 0x43443344;
201
}
202
203
uint32_t RenderingShaderContainerD3D12::_format_version() const {
204
return FORMAT_VERSION;
205
}
206
207
uint32_t RenderingShaderContainerD3D12::_from_bytes_reflection_extra_data(const uint8_t *p_bytes) {
208
reflection_data_d3d12 = *(const ReflectionDataD3D12 *)(p_bytes);
209
return sizeof(ReflectionDataD3D12);
210
}
211
212
uint32_t RenderingShaderContainerD3D12::_from_bytes_reflection_binding_uniform_extra_data_start(const uint8_t *p_bytes) {
213
reflection_binding_set_uniforms_data_d3d12.resize(reflection_binding_set_uniforms_data.size());
214
return 0;
215
}
216
217
uint32_t RenderingShaderContainerD3D12::_from_bytes_reflection_binding_uniform_extra_data(const uint8_t *p_bytes, uint32_t p_index) {
218
reflection_binding_set_uniforms_data_d3d12.ptrw()[p_index] = *(const ReflectionBindingDataD3D12 *)(p_bytes);
219
return sizeof(ReflectionBindingDataD3D12);
220
}
221
222
uint32_t RenderingShaderContainerD3D12::_from_bytes_reflection_specialization_extra_data_start(const uint8_t *p_bytes) {
223
reflection_specialization_data_d3d12.resize(reflection_specialization_data.size());
224
return 0;
225
}
226
227
uint32_t RenderingShaderContainerD3D12::_from_bytes_reflection_specialization_extra_data(const uint8_t *p_bytes, uint32_t p_index) {
228
reflection_specialization_data_d3d12.ptrw()[p_index] = *(const ReflectionSpecializationDataD3D12 *)(p_bytes);
229
return sizeof(ReflectionSpecializationDataD3D12);
230
}
231
232
uint32_t RenderingShaderContainerD3D12::_from_bytes_footer_extra_data(const uint8_t *p_bytes) {
233
ContainerFooterD3D12 footer = *(const ContainerFooterD3D12 *)(p_bytes);
234
root_signature_crc = footer.root_signature_crc;
235
root_signature_bytes.resize(footer.root_signature_length);
236
memcpy(root_signature_bytes.ptrw(), p_bytes + sizeof(ContainerFooterD3D12), root_signature_bytes.size());
237
return sizeof(ContainerFooterD3D12) + footer.root_signature_length;
238
}
239
240
uint32_t RenderingShaderContainerD3D12::_to_bytes_reflection_extra_data(uint8_t *p_bytes) const {
241
if (p_bytes != nullptr) {
242
*(ReflectionDataD3D12 *)(p_bytes) = reflection_data_d3d12;
243
}
244
245
return sizeof(ReflectionDataD3D12);
246
}
247
248
uint32_t RenderingShaderContainerD3D12::_to_bytes_reflection_binding_uniform_extra_data(uint8_t *p_bytes, uint32_t p_index) const {
249
if (p_bytes != nullptr) {
250
*(ReflectionBindingDataD3D12 *)(p_bytes) = reflection_binding_set_uniforms_data_d3d12[p_index];
251
}
252
253
return sizeof(ReflectionBindingDataD3D12);
254
}
255
256
uint32_t RenderingShaderContainerD3D12::_to_bytes_reflection_specialization_extra_data(uint8_t *p_bytes, uint32_t p_index) const {
257
if (p_bytes != nullptr) {
258
*(ReflectionSpecializationDataD3D12 *)(p_bytes) = reflection_specialization_data_d3d12[p_index];
259
}
260
261
return sizeof(ReflectionSpecializationDataD3D12);
262
}
263
264
uint32_t RenderingShaderContainerD3D12::_to_bytes_footer_extra_data(uint8_t *p_bytes) const {
265
if (p_bytes != nullptr) {
266
ContainerFooterD3D12 &footer = *(ContainerFooterD3D12 *)(p_bytes);
267
footer.root_signature_length = root_signature_bytes.size();
268
footer.root_signature_crc = root_signature_crc;
269
memcpy(p_bytes + sizeof(ContainerFooterD3D12), root_signature_bytes.ptr(), root_signature_bytes.size());
270
}
271
272
return sizeof(ContainerFooterD3D12) + root_signature_bytes.size();
273
}
274
275
#if NIR_ENABLED
276
bool RenderingShaderContainerD3D12::_convert_spirv_to_nir(const Vector<RenderingDeviceCommons::ShaderStageSPIRVData> &p_spirv, const nir_shader_compiler_options *p_compiler_options, HashMap<int, nir_shader *> &r_stages_nir_shaders, Vector<RenderingDeviceCommons::ShaderStage> &r_stages, BitField<RenderingDeviceCommons::ShaderStage> &r_stages_processed) {
277
r_stages_processed.clear();
278
279
dxil_spirv_runtime_conf dxil_runtime_conf = {};
280
dxil_runtime_conf.runtime_data_cbv.base_shader_register = RUNTIME_DATA_REGISTER;
281
dxil_runtime_conf.push_constant_cbv.base_shader_register = ROOT_CONSTANT_REGISTER;
282
dxil_runtime_conf.zero_based_vertex_instance_id = true;
283
dxil_runtime_conf.zero_based_compute_workgroup_id = true;
284
dxil_runtime_conf.declared_read_only_images_as_srvs = true;
285
286
// Making this explicit to let maintainers know that in practice this didn't improve performance,
287
// probably because data generated by one shader and consumed by another one forces the resource
288
// to transition from UAV to SRV, and back, instead of being an UAV all the time.
289
// In case someone wants to try, care must be taken so in case of incompatible bindings across stages
290
// happen as a result, all the stages are re-translated. That can happen if, for instance, a stage only
291
// uses an allegedly writable resource only for reading but the next stage doesn't.
292
dxil_runtime_conf.inferred_read_only_images_as_srvs = false;
293
294
// Translate SPIR-V to NIR.
295
for (int64_t i = 0; i < p_spirv.size(); i++) {
296
RenderingDeviceCommons::ShaderStage stage = p_spirv[i].shader_stage;
297
RenderingDeviceCommons::ShaderStage stage_flag = (RenderingDeviceCommons::ShaderStage)(1 << stage);
298
r_stages.push_back(stage);
299
r_stages_processed.set_flag(stage_flag);
300
301
const char *entry_point = "main";
302
static const gl_shader_stage SPIRV_TO_MESA_STAGES[RenderingDeviceCommons::SHADER_STAGE_MAX] = {
303
MESA_SHADER_VERTEX, // SHADER_STAGE_VERTEX
304
MESA_SHADER_FRAGMENT, // SHADER_STAGE_FRAGMENT
305
MESA_SHADER_TESS_CTRL, // SHADER_STAGE_TESSELATION_CONTROL
306
MESA_SHADER_TESS_EVAL, // SHADER_STAGE_TESSELATION_EVALUATION
307
MESA_SHADER_COMPUTE, // SHADER_STAGE_COMPUTE
308
};
309
310
nir_shader *shader = spirv_to_nir(
311
(const uint32_t *)(p_spirv[i].spirv.ptr()),
312
p_spirv[i].spirv.size() / sizeof(uint32_t),
313
nullptr,
314
0,
315
SPIRV_TO_MESA_STAGES[stage],
316
entry_point,
317
dxil_spirv_nir_get_spirv_options(),
318
p_compiler_options);
319
320
ERR_FAIL_NULL_V_MSG(shader, false, "Shader translation (step 1) at stage " + String(RenderingDeviceCommons::SHADER_STAGE_NAMES[stage]) + " failed.");
321
322
#ifdef DEV_ENABLED
323
nir_validate_shader(shader, "Validate before feeding NIR to the DXIL compiler");
324
#endif
325
326
if (stage == RenderingDeviceCommons::SHADER_STAGE_VERTEX) {
327
dxil_runtime_conf.yz_flip.y_mask = 0xffff;
328
dxil_runtime_conf.yz_flip.mode = DXIL_SPIRV_Y_FLIP_UNCONDITIONAL;
329
} else {
330
dxil_runtime_conf.yz_flip.y_mask = 0;
331
dxil_runtime_conf.yz_flip.mode = DXIL_SPIRV_YZ_FLIP_NONE;
332
}
333
334
dxil_spirv_nir_prep(shader);
335
bool requires_runtime_data = false;
336
dxil_spirv_nir_passes(shader, &dxil_runtime_conf, &requires_runtime_data);
337
338
r_stages_nir_shaders[stage] = shader;
339
}
340
341
// Link NIR shaders.
342
for (int i = RenderingDeviceCommons::SHADER_STAGE_MAX - 1; i >= 0; i--) {
343
if (!r_stages_nir_shaders.has(i)) {
344
continue;
345
}
346
nir_shader *shader = r_stages_nir_shaders[i];
347
nir_shader *prev_shader = nullptr;
348
for (int j = i - 1; j >= 0; j--) {
349
if (r_stages_nir_shaders.has(j)) {
350
prev_shader = r_stages_nir_shaders[j];
351
break;
352
}
353
}
354
// There is a bug in the Direct3D runtime during creation of a PSO with view instancing. If a fragment
355
// shader uses front/back face detection (SV_IsFrontFace), its signature must include the pixel position
356
// builtin variable (SV_Position), otherwise an Internal Runtime error will occur.
357
if (i == RenderingDeviceCommons::SHADER_STAGE_FRAGMENT) {
358
const bool use_front_face =
359
nir_find_variable_with_location(shader, nir_var_shader_in, VARYING_SLOT_FACE) ||
360
(shader->info.inputs_read & VARYING_BIT_FACE) ||
361
nir_find_variable_with_location(shader, nir_var_system_value, SYSTEM_VALUE_FRONT_FACE) ||
362
BITSET_TEST(shader->info.system_values_read, SYSTEM_VALUE_FRONT_FACE);
363
const bool use_position =
364
nir_find_variable_with_location(shader, nir_var_shader_in, VARYING_SLOT_POS) ||
365
(shader->info.inputs_read & VARYING_BIT_POS) ||
366
nir_find_variable_with_location(shader, nir_var_system_value, SYSTEM_VALUE_FRAG_COORD) ||
367
BITSET_TEST(shader->info.system_values_read, SYSTEM_VALUE_FRAG_COORD);
368
if (use_front_face && !use_position) {
369
nir_variable *const pos = nir_variable_create(shader, nir_var_shader_in, glsl_vec4_type(), "gl_FragCoord");
370
pos->data.location = VARYING_SLOT_POS;
371
shader->info.inputs_read |= VARYING_BIT_POS;
372
}
373
}
374
if (prev_shader) {
375
bool requires_runtime_data = {};
376
dxil_spirv_nir_link(shader, prev_shader, &dxil_runtime_conf, &requires_runtime_data);
377
}
378
}
379
380
return true;
381
}
382
383
struct GodotNirCallbackUserData {
384
RenderingShaderContainerD3D12 *container;
385
RenderingDeviceCommons::ShaderStage stage;
386
};
387
388
static dxil_shader_model shader_model_d3d_to_dxil(D3D_SHADER_MODEL p_d3d_shader_model) {
389
static_assert(SHADER_MODEL_6_0 == 0x60000);
390
static_assert(SHADER_MODEL_6_3 == 0x60003);
391
static_assert(D3D_SHADER_MODEL_6_0 == 0x60);
392
static_assert(D3D_SHADER_MODEL_6_3 == 0x63);
393
return (dxil_shader_model)((p_d3d_shader_model >> 4) * 0x10000 + (p_d3d_shader_model & 0xf));
394
}
395
396
bool RenderingShaderContainerD3D12::_convert_nir_to_dxil(const HashMap<int, nir_shader *> &p_stages_nir_shaders, BitField<RenderingDeviceCommons::ShaderStage> p_stages_processed, HashMap<RenderingDeviceCommons::ShaderStage, Vector<uint8_t>> &r_dxil_blobs) {
397
// Translate NIR to DXIL.
398
for (KeyValue<int, nir_shader *> it : p_stages_nir_shaders) {
399
RenderingDeviceCommons::ShaderStage stage = (RenderingDeviceCommons::ShaderStage)(it.key);
400
GodotNirCallbackUserData godot_nir_callback_user_data;
401
godot_nir_callback_user_data.container = this;
402
godot_nir_callback_user_data.stage = stage;
403
404
GodotNirCallbacks godot_nir_callbacks = {};
405
godot_nir_callbacks.data = &godot_nir_callback_user_data;
406
godot_nir_callbacks.report_resource = _nir_report_resource;
407
godot_nir_callbacks.report_sc_bit_offset_fn = _nir_report_sc_bit_offset;
408
godot_nir_callbacks.report_bitcode_bit_offset_fn = _nir_report_bitcode_bit_offset;
409
410
nir_to_dxil_options nir_to_dxil_options = {};
411
nir_to_dxil_options.environment = DXIL_ENVIRONMENT_VULKAN;
412
nir_to_dxil_options.shader_model_max = shader_model_d3d_to_dxil(D3D_SHADER_MODEL(REQUIRED_SHADER_MODEL));
413
nir_to_dxil_options.validator_version_max = NO_DXIL_VALIDATION;
414
nir_to_dxil_options.godot_nir_callbacks = &godot_nir_callbacks;
415
416
dxil_logger logger = {};
417
logger.log = [](void *p_priv, const char *p_msg) {
418
#ifdef DEBUG_ENABLED
419
print_verbose(p_msg);
420
#endif
421
};
422
423
blob dxil_blob = {};
424
bool ok = nir_to_dxil(it.value, &nir_to_dxil_options, &logger, &dxil_blob);
425
ERR_FAIL_COND_V_MSG(!ok, false, "Shader translation at stage " + String(RenderingDeviceCommons::SHADER_STAGE_NAMES[stage]) + " failed.");
426
427
Vector<uint8_t> blob_copy;
428
blob_copy.resize(dxil_blob.size);
429
memcpy(blob_copy.ptrw(), dxil_blob.data, dxil_blob.size);
430
blob_finish(&dxil_blob);
431
r_dxil_blobs.insert(stage, blob_copy);
432
}
433
434
return true;
435
}
436
437
bool RenderingShaderContainerD3D12::_convert_spirv_to_dxil(const Vector<RenderingDeviceCommons::ShaderStageSPIRVData> &p_spirv, HashMap<RenderingDeviceCommons::ShaderStage, Vector<uint8_t>> &r_dxil_blobs, Vector<RenderingDeviceCommons::ShaderStage> &r_stages, BitField<RenderingDeviceCommons::ShaderStage> &r_stages_processed) {
438
r_dxil_blobs.clear();
439
440
HashMap<int, nir_shader *> stages_nir_shaders;
441
auto free_nir_shaders = [&]() {
442
for (KeyValue<int, nir_shader *> &E : stages_nir_shaders) {
443
ralloc_free(E.value);
444
}
445
stages_nir_shaders.clear();
446
};
447
448
// This structure must live as long as the shaders are alive.
449
nir_shader_compiler_options compiler_options = *dxil_get_nir_compiler_options();
450
compiler_options.lower_base_vertex = false;
451
452
// This is based on spirv2dxil.c. May need updates when it changes.
453
// Also, this has to stay around until after linking.
454
if (!_convert_spirv_to_nir(p_spirv, &compiler_options, stages_nir_shaders, r_stages, r_stages_processed)) {
455
free_nir_shaders();
456
return false;
457
}
458
459
if (!_convert_nir_to_dxil(stages_nir_shaders, r_stages_processed, r_dxil_blobs)) {
460
free_nir_shaders();
461
return false;
462
}
463
464
free_nir_shaders();
465
return true;
466
}
467
468
bool RenderingShaderContainerD3D12::_generate_root_signature(BitField<RenderingDeviceCommons::ShaderStage> p_stages_processed) {
469
// Root (push) constants.
470
LocalVector<D3D12_ROOT_PARAMETER1> root_params;
471
if (reflection_data_d3d12.dxil_push_constant_stages) {
472
CD3DX12_ROOT_PARAMETER1 push_constant;
473
push_constant.InitAsConstants(
474
reflection_data.push_constant_size / sizeof(uint32_t),
475
ROOT_CONSTANT_REGISTER,
476
0,
477
stages_to_d3d12_visibility(reflection_data_d3d12.dxil_push_constant_stages));
478
479
root_params.push_back(push_constant);
480
}
481
482
// NIR-DXIL runtime data.
483
if (reflection_data_d3d12.nir_runtime_data_root_param_idx == 1) { // Set above to 1 when discovering runtime data is needed.
484
DEV_ASSERT(!reflection_data.is_compute); // Could be supported if needed, but it's pointless as of now.
485
reflection_data_d3d12.nir_runtime_data_root_param_idx = root_params.size();
486
CD3DX12_ROOT_PARAMETER1 nir_runtime_data;
487
nir_runtime_data.InitAsConstants(
488
sizeof(dxil_spirv_vertex_runtime_data) / sizeof(uint32_t),
489
RUNTIME_DATA_REGISTER,
490
0,
491
D3D12_SHADER_VISIBILITY_VERTEX);
492
root_params.push_back(nir_runtime_data);
493
}
494
495
// Descriptor tables (up to two per uniform set, for resources and/or samplers).
496
// These have to stay around until serialization!
497
struct TraceableDescriptorTable {
498
uint32_t stages_mask = {};
499
Vector<D3D12_DESCRIPTOR_RANGE1> ranges;
500
Vector<RootSignatureLocation *> root_signature_locations;
501
};
502
503
uint32_t binding_start = 0;
504
Vector<TraceableDescriptorTable> resource_tables_maps;
505
Vector<TraceableDescriptorTable> sampler_tables_maps;
506
for (uint32_t i = 0; i < reflection_binding_set_uniforms_count.size(); i++) {
507
bool first_resource_in_set = true;
508
bool first_sampler_in_set = true;
509
uint32_t uniform_count = reflection_binding_set_uniforms_count[i];
510
for (uint32_t j = 0; j < uniform_count; j++) {
511
const ReflectionBindingData &uniform = reflection_binding_set_uniforms_data[binding_start + j];
512
ReflectionBindingDataD3D12 &uniform_d3d12 = reflection_binding_set_uniforms_data_d3d12.ptrw()[binding_start + j];
513
bool really_used = uniform_d3d12.dxil_stages != 0;
514
#ifdef DEV_ENABLED
515
bool anybody_home = (ResourceClass)(uniform_d3d12.resource_class) != RES_CLASS_INVALID || uniform_d3d12.has_sampler;
516
DEV_ASSERT(anybody_home == really_used);
517
#endif
518
if (!really_used) {
519
continue; // Existed in SPIR-V; went away in DXIL.
520
}
521
522
auto insert_range = [](D3D12_DESCRIPTOR_RANGE_TYPE p_range_type,
523
uint32_t p_num_descriptors,
524
uint32_t p_dxil_register,
525
uint32_t p_dxil_stages_mask,
526
RootSignatureLocation *p_root_sig_locations,
527
Vector<TraceableDescriptorTable> &r_tables,
528
bool &r_first_in_set) {
529
if (r_first_in_set) {
530
r_tables.resize(r_tables.size() + 1);
531
r_first_in_set = false;
532
}
533
534
TraceableDescriptorTable &table = r_tables.write[r_tables.size() - 1];
535
table.stages_mask |= p_dxil_stages_mask;
536
537
CD3DX12_DESCRIPTOR_RANGE1 range;
538
// Due to the aliasing hack for SRV-UAV of different families,
539
// we can be causing an unintended change of data (sometimes the validation layers catch it).
540
D3D12_DESCRIPTOR_RANGE_FLAGS flags = D3D12_DESCRIPTOR_RANGE_FLAG_NONE;
541
if (p_range_type == D3D12_DESCRIPTOR_RANGE_TYPE_SRV || p_range_type == D3D12_DESCRIPTOR_RANGE_TYPE_UAV) {
542
flags = D3D12_DESCRIPTOR_RANGE_FLAG_DATA_VOLATILE;
543
} else if (p_range_type == D3D12_DESCRIPTOR_RANGE_TYPE_CBV) {
544
flags = D3D12_DESCRIPTOR_RANGE_FLAG_DATA_STATIC_WHILE_SET_AT_EXECUTE;
545
}
546
range.Init(p_range_type, p_num_descriptors, p_dxil_register, 0, flags);
547
548
table.ranges.push_back(range);
549
table.root_signature_locations.push_back(p_root_sig_locations);
550
};
551
552
uint32_t num_descriptors = 1;
553
D3D12_DESCRIPTOR_RANGE_TYPE resource_range_type = {};
554
switch ((ResourceClass)(uniform_d3d12.resource_class)) {
555
case RES_CLASS_INVALID: {
556
num_descriptors = uniform.length;
557
DEV_ASSERT(uniform_d3d12.has_sampler);
558
} break;
559
case RES_CLASS_CBV: {
560
resource_range_type = D3D12_DESCRIPTOR_RANGE_TYPE_CBV;
561
DEV_ASSERT(!uniform_d3d12.has_sampler);
562
} break;
563
case RES_CLASS_SRV: {
564
resource_range_type = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
565
num_descriptors = MAX(1u, uniform.length); // An unbound R/O buffer is reflected as zero-size.
566
} break;
567
case RES_CLASS_UAV: {
568
resource_range_type = D3D12_DESCRIPTOR_RANGE_TYPE_UAV;
569
num_descriptors = MAX(1u, uniform.length); // An unbound R/W buffer is reflected as zero-size.
570
DEV_ASSERT(!uniform_d3d12.has_sampler);
571
} break;
572
}
573
574
uint32_t dxil_register = i * GODOT_NIR_DESCRIPTOR_SET_MULTIPLIER + uniform.binding * GODOT_NIR_BINDING_MULTIPLIER;
575
if (uniform_d3d12.resource_class != RES_CLASS_INVALID) {
576
insert_range(
577
resource_range_type,
578
num_descriptors,
579
dxil_register,
580
uniform_d3d12.dxil_stages,
581
&uniform_d3d12.root_signature_locations[RS_LOC_TYPE_RESOURCE],
582
resource_tables_maps,
583
first_resource_in_set);
584
}
585
586
if (uniform_d3d12.has_sampler) {
587
insert_range(
588
D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER,
589
num_descriptors,
590
dxil_register,
591
uniform_d3d12.dxil_stages,
592
&uniform_d3d12.root_signature_locations[RS_LOC_TYPE_SAMPLER],
593
sampler_tables_maps,
594
first_sampler_in_set);
595
}
596
}
597
598
binding_start += uniform_count;
599
}
600
601
auto make_descriptor_tables = [&root_params](const Vector<TraceableDescriptorTable> &p_tables) {
602
for (const TraceableDescriptorTable &table : p_tables) {
603
D3D12_SHADER_VISIBILITY visibility = stages_to_d3d12_visibility(table.stages_mask);
604
DEV_ASSERT(table.ranges.size() == table.root_signature_locations.size());
605
for (int i = 0; i < table.ranges.size(); i++) {
606
// By now we know very well which root signature location corresponds to the pointed uniform.
607
table.root_signature_locations[i]->root_param_index = root_params.size();
608
table.root_signature_locations[i]->range_index = i;
609
}
610
611
CD3DX12_ROOT_PARAMETER1 root_table;
612
root_table.InitAsDescriptorTable(table.ranges.size(), table.ranges.ptr(), visibility);
613
root_params.push_back(root_table);
614
}
615
};
616
617
make_descriptor_tables(resource_tables_maps);
618
make_descriptor_tables(sampler_tables_maps);
619
620
CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC root_sig_desc = {};
621
D3D12_ROOT_SIGNATURE_FLAGS root_sig_flags =
622
D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS |
623
D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS |
624
D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS |
625
D3D12_ROOT_SIGNATURE_FLAG_DENY_AMPLIFICATION_SHADER_ROOT_ACCESS |
626
D3D12_ROOT_SIGNATURE_FLAG_DENY_MESH_SHADER_ROOT_ACCESS;
627
628
if (!p_stages_processed.has_flag(RenderingDeviceCommons::SHADER_STAGE_VERTEX_BIT)) {
629
root_sig_flags |= D3D12_ROOT_SIGNATURE_FLAG_DENY_VERTEX_SHADER_ROOT_ACCESS;
630
}
631
632
if (!p_stages_processed.has_flag(RenderingDeviceCommons::SHADER_STAGE_FRAGMENT_BIT)) {
633
root_sig_flags |= D3D12_ROOT_SIGNATURE_FLAG_DENY_PIXEL_SHADER_ROOT_ACCESS;
634
}
635
636
if (reflection_data.vertex_input_mask) {
637
root_sig_flags |= D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT;
638
}
639
640
root_sig_desc.Init_1_1(root_params.size(), root_params.ptr(), 0, nullptr, root_sig_flags);
641
642
// Create and store the root signature and its CRC32.
643
ID3DBlob *error_blob = nullptr;
644
ID3DBlob *root_sig_blob = nullptr;
645
HRESULT res = D3DX12SerializeVersionedRootSignature(HMODULE(lib_d3d12), &root_sig_desc, D3D_ROOT_SIGNATURE_VERSION_1_1, &root_sig_blob, &error_blob);
646
if (SUCCEEDED(res)) {
647
root_signature_bytes.resize(root_sig_blob->GetBufferSize());
648
memcpy(root_signature_bytes.ptrw(), root_sig_blob->GetBufferPointer(), root_sig_blob->GetBufferSize());
649
650
root_signature_crc = crc32(0, nullptr, 0);
651
root_signature_crc = crc32(root_signature_crc, (const Bytef *)root_sig_blob->GetBufferPointer(), root_sig_blob->GetBufferSize());
652
653
return true;
654
} else {
655
if (root_sig_blob != nullptr) {
656
root_sig_blob->Release();
657
}
658
659
String error_string;
660
if (error_blob != nullptr) {
661
error_string = vformat("Serialization of root signature failed with error 0x%08ux and the following message:\n%s", uint32_t(res), String::ascii(Span((char *)error_blob->GetBufferPointer(), error_blob->GetBufferSize())));
662
error_blob->Release();
663
} else {
664
error_string = vformat("Serialization of root signature failed with error 0x%08ux", uint32_t(res));
665
}
666
667
ERR_FAIL_V_MSG(false, error_string);
668
}
669
}
670
671
void RenderingShaderContainerD3D12::_nir_report_resource(uint32_t p_register, uint32_t p_space, uint32_t p_dxil_type, void *p_data) {
672
const GodotNirCallbackUserData &user_data = *(GodotNirCallbackUserData *)p_data;
673
674
// Types based on Mesa's dxil_container.h.
675
static const uint32_t DXIL_RES_SAMPLER = 1;
676
static const ResourceClass DXIL_TYPE_TO_CLASS[] = {
677
RES_CLASS_INVALID, // DXIL_RES_INVALID
678
RES_CLASS_INVALID, // DXIL_RES_SAMPLER
679
RES_CLASS_CBV, // DXIL_RES_CBV
680
RES_CLASS_SRV, // DXIL_RES_SRV_TYPED
681
RES_CLASS_SRV, // DXIL_RES_SRV_RAW
682
RES_CLASS_SRV, // DXIL_RES_SRV_STRUCTURED
683
RES_CLASS_UAV, // DXIL_RES_UAV_TYPED
684
RES_CLASS_UAV, // DXIL_RES_UAV_RAW
685
RES_CLASS_UAV, // DXIL_RES_UAV_STRUCTURED
686
RES_CLASS_INVALID, // DXIL_RES_UAV_STRUCTURED_WITH_COUNTER
687
};
688
689
DEV_ASSERT(p_dxil_type < ARRAY_SIZE(DXIL_TYPE_TO_CLASS));
690
ResourceClass resource_class = DXIL_TYPE_TO_CLASS[p_dxil_type];
691
692
if (p_register == ROOT_CONSTANT_REGISTER && p_space == 0) {
693
DEV_ASSERT(resource_class == RES_CLASS_CBV);
694
user_data.container->reflection_data_d3d12.dxil_push_constant_stages |= (1 << user_data.stage);
695
} else if (p_register == RUNTIME_DATA_REGISTER && p_space == 0) {
696
DEV_ASSERT(resource_class == RES_CLASS_CBV);
697
user_data.container->reflection_data_d3d12.nir_runtime_data_root_param_idx = 1; // Temporary, to be determined later.
698
} else {
699
DEV_ASSERT(p_space == 0);
700
701
uint32_t set = p_register / GODOT_NIR_DESCRIPTOR_SET_MULTIPLIER;
702
uint32_t binding = (p_register % GODOT_NIR_DESCRIPTOR_SET_MULTIPLIER) / GODOT_NIR_BINDING_MULTIPLIER;
703
704
DEV_ASSERT(set < (uint32_t)user_data.container->reflection_binding_set_uniforms_count.size());
705
706
uint32_t binding_start = 0;
707
for (uint32_t i = 0; i < set; i++) {
708
binding_start += user_data.container->reflection_binding_set_uniforms_count[i];
709
}
710
711
[[maybe_unused]] bool found = false;
712
for (uint32_t i = 0; i < user_data.container->reflection_binding_set_uniforms_count[set]; i++) {
713
const ReflectionBindingData &uniform = user_data.container->reflection_binding_set_uniforms_data[binding_start + i];
714
ReflectionBindingDataD3D12 &uniform_d3d12 = user_data.container->reflection_binding_set_uniforms_data_d3d12.ptrw()[binding_start + i];
715
if (uniform.binding != binding) {
716
continue;
717
}
718
719
uniform_d3d12.dxil_stages |= (1 << user_data.stage);
720
if (resource_class != RES_CLASS_INVALID) {
721
DEV_ASSERT(uniform_d3d12.resource_class == (uint32_t)RES_CLASS_INVALID || uniform_d3d12.resource_class == (uint32_t)resource_class);
722
uniform_d3d12.resource_class = resource_class;
723
} else if (p_dxil_type == DXIL_RES_SAMPLER) {
724
uniform_d3d12.has_sampler = (uint32_t)true;
725
} else {
726
DEV_ASSERT(false && "Unknown resource class.");
727
}
728
found = true;
729
}
730
731
DEV_ASSERT(found);
732
}
733
}
734
735
void RenderingShaderContainerD3D12::_nir_report_sc_bit_offset(uint32_t p_sc_id, uint64_t p_bit_offset, void *p_data) {
736
const GodotNirCallbackUserData &user_data = *(GodotNirCallbackUserData *)p_data;
737
[[maybe_unused]] bool found = false;
738
for (int64_t i = 0; i < user_data.container->reflection_specialization_data.size(); i++) {
739
const ReflectionSpecializationData &sc = user_data.container->reflection_specialization_data[i];
740
ReflectionSpecializationDataD3D12 &sc_d3d12 = user_data.container->reflection_specialization_data_d3d12.ptrw()[i];
741
if (sc.constant_id != p_sc_id) {
742
continue;
743
}
744
745
uint32_t offset_idx = SHADER_STAGES_BIT_OFFSET_INDICES[user_data.stage];
746
DEV_ASSERT(sc_d3d12.stages_bit_offsets[offset_idx] == 0);
747
sc_d3d12.stages_bit_offsets[offset_idx] = p_bit_offset;
748
found = true;
749
break;
750
}
751
752
DEV_ASSERT(found);
753
}
754
755
void RenderingShaderContainerD3D12::_nir_report_bitcode_bit_offset(uint64_t p_bit_offset, void *p_data) {
756
DEV_ASSERT(p_bit_offset % 8 == 0);
757
758
const GodotNirCallbackUserData &user_data = *(GodotNirCallbackUserData *)p_data;
759
uint32_t offset_idx = SHADER_STAGES_BIT_OFFSET_INDICES[user_data.stage];
760
for (int64_t i = 0; i < user_data.container->reflection_specialization_data.size(); i++) {
761
ReflectionSpecializationDataD3D12 &sc_d3d12 = user_data.container->reflection_specialization_data_d3d12.ptrw()[i];
762
if (sc_d3d12.stages_bit_offsets[offset_idx] == 0) {
763
// This SC has been optimized out from this stage.
764
continue;
765
}
766
767
sc_d3d12.stages_bit_offsets[offset_idx] += p_bit_offset;
768
}
769
}
770
#endif
771
772
void RenderingShaderContainerD3D12::_set_from_shader_reflection_post(const String &p_shader_name, const RenderingDeviceCommons::ShaderReflection &p_reflection) {
773
reflection_binding_set_uniforms_data_d3d12.resize(reflection_binding_set_uniforms_data.size());
774
reflection_specialization_data_d3d12.resize(reflection_specialization_data.size());
775
776
// Sort bindings inside each uniform set. This guarantees the root signature will be generated in the correct order.
777
SortArray<ReflectionBindingData> sorter;
778
uint32_t binding_start = 0;
779
for (uint32_t i = 0; i < reflection_binding_set_uniforms_count.size(); i++) {
780
uint32_t uniform_count = reflection_binding_set_uniforms_count[i];
781
if (uniform_count > 0) {
782
sorter.sort(&reflection_binding_set_uniforms_data.ptrw()[binding_start], uniform_count);
783
binding_start += uniform_count;
784
}
785
}
786
}
787
788
bool RenderingShaderContainerD3D12::_set_code_from_spirv(const Vector<RenderingDeviceCommons::ShaderStageSPIRVData> &p_spirv) {
789
#if NIR_ENABLED
790
reflection_data_d3d12.nir_runtime_data_root_param_idx = UINT32_MAX;
791
792
for (int64_t i = 0; i < reflection_specialization_data.size(); i++) {
793
DEV_ASSERT(reflection_specialization_data[i].constant_id < (sizeof(reflection_data_d3d12.spirv_specialization_constants_ids_mask) * 8) && "Constant IDs with values above 31 are not supported.");
794
reflection_data_d3d12.spirv_specialization_constants_ids_mask |= (1 << reflection_specialization_data[i].constant_id);
795
}
796
797
// Translate SPIR-V shaders to DXIL, and collect shader info from the new representation.
798
HashMap<RenderingDeviceCommons::ShaderStage, Vector<uint8_t>> dxil_blobs;
799
Vector<RenderingDeviceCommons::ShaderStage> stages;
800
BitField<RenderingDeviceCommons::ShaderStage> stages_processed = {};
801
if (!_convert_spirv_to_dxil(p_spirv, dxil_blobs, stages, stages_processed)) {
802
return false;
803
}
804
805
// Patch with default values of specialization constants.
806
DEV_ASSERT(reflection_specialization_data.size() == reflection_specialization_data_d3d12.size());
807
for (int32_t i = 0; i < reflection_specialization_data.size(); i++) {
808
const ReflectionSpecializationData &sc = reflection_specialization_data[i];
809
const ReflectionSpecializationDataD3D12 &sc_d3d12 = reflection_specialization_data_d3d12[i];
810
RenderingDXIL::patch_specialization_constant((RenderingDeviceCommons::PipelineSpecializationConstantType)(sc.type), &sc.int_value, sc_d3d12.stages_bit_offsets, dxil_blobs, true);
811
}
812
813
// Sign.
814
uint32_t shader_index = 0;
815
for (KeyValue<RenderingDeviceCommons::ShaderStage, Vector<uint8_t>> &E : dxil_blobs) {
816
RenderingDXIL::sign_bytecode(E.key, E.value);
817
}
818
819
// Store compressed DXIL blobs as the shaders.
820
shaders.resize(p_spirv.size());
821
for (int64_t i = 0; i < shaders.size(); i++) {
822
const PackedByteArray &dxil_bytes = dxil_blobs[stages[i]];
823
RenderingShaderContainer::Shader &shader = shaders.ptrw()[i];
824
uint32_t compressed_size = 0;
825
shader.shader_stage = stages[i];
826
shader.code_decompressed_size = dxil_bytes.size();
827
shader.code_compressed_bytes.resize(dxil_bytes.size());
828
829
bool compressed = compress_code(dxil_bytes.ptr(), dxil_bytes.size(), shader.code_compressed_bytes.ptrw(), &compressed_size, &shader.code_compression_flags);
830
ERR_FAIL_COND_V_MSG(!compressed, false, vformat("Failed to compress native code to native for SPIR-V #%d.", shader_index));
831
832
shader.code_compressed_bytes.resize(compressed_size);
833
}
834
835
if (!_generate_root_signature(stages_processed)) {
836
return false;
837
}
838
839
return true;
840
#else
841
ERR_FAIL_V_MSG(false, "Shader compilation is not supported at runtime without NIR.");
842
#endif
843
}
844
845
RenderingShaderContainerD3D12::RenderingShaderContainerD3D12() {
846
// Default empty constructor.
847
}
848
849
RenderingShaderContainerD3D12::RenderingShaderContainerD3D12(void *p_lib_d3d12) {
850
lib_d3d12 = p_lib_d3d12;
851
}
852
853
RenderingShaderContainerD3D12::ShaderReflectionD3D12 RenderingShaderContainerD3D12::get_shader_reflection_d3d12() const {
854
ShaderReflectionD3D12 reflection;
855
reflection.spirv_specialization_constants_ids_mask = reflection_data_d3d12.spirv_specialization_constants_ids_mask;
856
reflection.dxil_push_constant_stages = reflection_data_d3d12.dxil_push_constant_stages;
857
reflection.nir_runtime_data_root_param_idx = reflection_data_d3d12.nir_runtime_data_root_param_idx;
858
reflection.reflection_specialization_data_d3d12 = reflection_specialization_data_d3d12;
859
reflection.root_signature_bytes = root_signature_bytes;
860
reflection.root_signature_crc = root_signature_crc;
861
862
// Transform data vector into a vector of vectors that's easier to user.
863
uint32_t uniform_index = 0;
864
reflection.reflection_binding_set_uniforms_d3d12.resize(reflection_binding_set_uniforms_count.size());
865
for (int64_t i = 0; i < reflection.reflection_binding_set_uniforms_d3d12.size(); i++) {
866
Vector<ReflectionBindingDataD3D12> &uniforms = reflection.reflection_binding_set_uniforms_d3d12.ptrw()[i];
867
uniforms.resize(reflection_binding_set_uniforms_count[i]);
868
for (int64_t j = 0; j < uniforms.size(); j++) {
869
uniforms.ptrw()[j] = reflection_binding_set_uniforms_data_d3d12[uniform_index];
870
uniform_index++;
871
}
872
}
873
874
return reflection;
875
}
876
877
// RenderingShaderContainerFormatD3D12
878
879
void RenderingShaderContainerFormatD3D12::set_lib_d3d12(void *p_lib_d3d12) {
880
lib_d3d12 = p_lib_d3d12;
881
}
882
883
Ref<RenderingShaderContainer> RenderingShaderContainerFormatD3D12::create_container() const {
884
return memnew(RenderingShaderContainerD3D12(lib_d3d12));
885
}
886
887
RenderingDeviceCommons::ShaderLanguageVersion RenderingShaderContainerFormatD3D12::get_shader_language_version() const {
888
// NIR-DXIL is Vulkan 1.1-conformant.
889
return SHADER_LANGUAGE_VULKAN_VERSION_1_1;
890
}
891
892
RenderingDeviceCommons::ShaderSpirvVersion RenderingShaderContainerFormatD3D12::get_shader_spirv_version() const {
893
// The SPIR-V part of Mesa supports 1.6, but:
894
// - SPIRV-Reflect won't be able to parse the compute workgroup size.
895
// - We want to play it safe with NIR-DXIL.
896
return SHADER_SPIRV_VERSION_1_5;
897
}
898
899
RenderingShaderContainerFormatD3D12::RenderingShaderContainerFormatD3D12() {}
900
901
RenderingShaderContainerFormatD3D12::~RenderingShaderContainerFormatD3D12() {}
902
903