mirror of
https://github.com/godotengine/godot.git
synced 2025-10-20 00:13:30 +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:
parent
9283328fe7
commit
65e8b0951b
12 changed files with 425 additions and 391 deletions
|
@ -3366,19 +3366,12 @@ String RenderingDevice::_shader_uniform_debug(RID p_shader, int p_set) {
|
|||
}
|
||||
|
||||
Vector<uint8_t> RenderingDevice::shader_compile_binary_from_spirv(const Vector<ShaderStageSPIRVData> &p_spirv, const String &p_shader_name) {
|
||||
ShaderReflection shader_refl;
|
||||
if (reflect_spirv(p_spirv, shader_refl) != OK) {
|
||||
return Vector<uint8_t>();
|
||||
}
|
||||
|
||||
const RenderingShaderContainerFormat &container_format = driver->get_shader_container_format();
|
||||
Ref<RenderingShaderContainer> shader_container = container_format.create_container();
|
||||
ERR_FAIL_COND_V(shader_container.is_null(), Vector<uint8_t>());
|
||||
|
||||
shader_container->set_from_shader_reflection(p_shader_name, shader_refl);
|
||||
|
||||
// Compile shader binary from SPIR-V.
|
||||
bool code_compiled = shader_container->set_code_from_spirv(p_spirv);
|
||||
bool code_compiled = shader_container->set_code_from_spirv(p_shader_name, p_spirv);
|
||||
ERR_FAIL_COND_V_MSG(!code_compiled, Vector<uint8_t>(), vformat("Failed to compile code to native for SPIR-V."));
|
||||
|
||||
return shader_container->to_bytes();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue