1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

Renderer: Move reflect_spirv to RenderingShaderContainer

This change introduces a new protected type, `ReflectedShaderStage` to
`RenderingShaderContainer` that derived types use to access SPIR-V and
the reflected module, `SpvReflectShaderModule` allowing implementations
to use the reflection information to compile their platform-specific
module.

* Fixes memory leak in `reflect_spirv` that would not deallocate the
  `SpvReflectShaderModule` if an error occurred.
* Removes unnecessary allocation when creating `SpvReflectShaderModule`
  by passing `NO_COPY` flag to `spvReflectCreateShaderModule2`
  constructor function.
* Replaces `VectorView` with `Span` for consistency
* Fixes unnecessary allocations in D3D12 shader container in
  `_convert_spirv_to_nir` and `_convert_spirv_to_dxil` which implicitly
  converted the old `VectorView` to a `Vector`
This commit is contained in:
Stuart Carnie
2025-09-29 07:04:23 +10:00
parent 9283328fe7
commit 65e8b0951b
12 changed files with 425 additions and 391 deletions

View File

@@ -44,21 +44,21 @@ uint32_t RenderingShaderContainerVulkan::_format_version() const {
return FORMAT_VERSION;
}
bool RenderingShaderContainerVulkan::_set_code_from_spirv(const Vector<RenderingDeviceCommons::ShaderStageSPIRVData> &p_spirv) {
bool RenderingShaderContainerVulkan::_set_code_from_spirv(Span<ReflectedShaderStage> p_spirv) {
PackedByteArray code_bytes;
shaders.resize(p_spirv.size());
for (int64_t i = 0; i < p_spirv.size(); i++) {
for (uint64_t i = 0; i < p_spirv.size(); i++) {
RenderingShaderContainer::Shader &shader = shaders.ptrw()[i];
if (debug_info_enabled) {
// Store SPIR-V as is when debug info is required.
shader.code_compressed_bytes = p_spirv[i].spirv;
shader.code_compressed_bytes = p_spirv[i].spirv_data();
shader.code_compression_flags = 0;
shader.code_decompressed_size = 0;
} else {
// Encode into smolv.
Span<uint8_t> spirv = p_spirv[i].spirv().reinterpret<uint8_t>();
smolv::ByteArray smolv_bytes;
bool smolv_encoded = smolv::Encode(p_spirv[i].spirv.ptr(), p_spirv[i].spirv.size(), smolv_bytes, smolv::kEncodeFlagStripDebugInfo);
bool smolv_encoded = smolv::Encode(spirv.ptr(), spirv.size(), smolv_bytes, smolv::kEncodeFlagStripDebugInfo);
ERR_FAIL_COND_V_MSG(!smolv_encoded, false, "Failed to compress SPIR-V into smolv.");
code_bytes.resize(smolv_bytes.size());