From f00ab9dee84ad62069b5066631ca84feeff26df2 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 25 Mar 2024 11:40:26 +0000 Subject: [PATCH] Store descriptor type directly in shader resources for shader reflection --- renderdoc/api/replay/shader_types.h | 6 ++++++ renderdoc/driver/d3d11/d3d11_resources.cpp | 15 ++------------- renderdoc/driver/d3d12/d3d12_resources.cpp | 15 ++------------- renderdoc/driver/gl/gl_shader_refl.cpp | 13 +++++++++++++ renderdoc/driver/shaders/dxbc/dxbc_reflect.cpp | 18 ++++++++++++++++++ .../driver/shaders/spirv/spirv_reflect.cpp | 15 +++++++++++++++ renderdoc/driver/vulkan/vk_info.cpp | 11 ++--------- renderdoc/replay/renderdoc_serialise.inl | 1 + 8 files changed, 59 insertions(+), 35 deletions(-) diff --git a/renderdoc/api/replay/shader_types.h b/renderdoc/api/replay/shader_types.h index 49da7e6db..dabe53687 100644 --- a/renderdoc/api/replay/shader_types.h +++ b/renderdoc/api/replay/shader_types.h @@ -1461,6 +1461,12 @@ struct ShaderResource DOCUMENT("The :class:`TextureType` that describes the type of this resource."); TextureType resType; + DOCUMENT(R"(The :class:`DescriptorType` which this resource expects to access. + +:type: DescriptorType +)"); + DescriptorType descriptorType; + DOCUMENT("The name of this resource."); rdcstr name; diff --git a/renderdoc/driver/d3d11/d3d11_resources.cpp b/renderdoc/driver/d3d11/d3d11_resources.cpp index 08e3a09e4..c0fb0c68e 100644 --- a/renderdoc/driver/d3d11/d3d11_resources.cpp +++ b/renderdoc/driver/d3d11/d3d11_resources.cpp @@ -130,12 +130,7 @@ void WrappedShader::ShaderEntry::BuildReflection() for(uint16_t i = 0; i < m_Mapping.readOnlyResources.size(); i++) { access.staticallyUnused = !m_Mapping.readOnlyResources[i].used; - access.type = DescriptorType::Image; - if(!m_Details->readOnlyResources[i].isTexture) - access.type = (m_Details->readOnlyResources[i].variableType.baseType == VarType::UByte || - !m_Details->readOnlyResources[i].variableType.members.empty()) - ? DescriptorType::Buffer - : DescriptorType::TypedBuffer; + access.type = m_Details->readOnlyResources[i].descriptorType; access.index = i; access.byteOffset = EncodeD3D11DescriptorIndex({access.stage, D3D11DescriptorMapping::SRVs, (uint32_t)m_Mapping.readOnlyResources[i].bind}); @@ -146,13 +141,7 @@ void WrappedShader::ShaderEntry::BuildReflection() for(uint16_t i = 0; i < m_Mapping.readWriteResources.size(); i++) { access.staticallyUnused = !m_Mapping.readWriteResources[i].used; - access.type = DescriptorType::ReadWriteImage; - if(!m_Details->readWriteResources[i].isTexture) - access.type = (m_Details->readWriteResources[i].variableType.baseType == VarType::UByte || - !m_Details->readWriteResources[i].variableType.members.empty()) - ? DescriptorType::ReadWriteBuffer - : DescriptorType::ReadWriteTypedBuffer; - + access.type = m_Details->readWriteResources[i].descriptorType; access.index = i; access.byteOffset = EncodeD3D11DescriptorIndex({access.stage, D3D11DescriptorMapping::UAVs, (uint32_t)m_Mapping.readWriteResources[i].bind}); diff --git a/renderdoc/driver/d3d12/d3d12_resources.cpp b/renderdoc/driver/d3d12/d3d12_resources.cpp index 7c0062e01..2d50217ba 100644 --- a/renderdoc/driver/d3d12/d3d12_resources.cpp +++ b/renderdoc/driver/d3d12/d3d12_resources.cpp @@ -824,12 +824,7 @@ void WrappedID3D12PipelineState::ProcessDescriptorAccess() continue; access.staticallyUnused = !bind.used; - access.type = DescriptorType::Image; - if(!refl.readOnlyResources[i].isTexture) - access.type = (refl.readOnlyResources[i].variableType.baseType == VarType::UByte || - !refl.readOnlyResources[i].variableType.members.empty()) - ? DescriptorType::Buffer - : DescriptorType::TypedBuffer; + access.type = refl.readOnlyResources[i].descriptorType; access.index = i; rdctie(access.byteSize, access.byteOffset) = FindMatchingRootParameter(sig, visibility, D3D12_DESCRIPTOR_RANGE_TYPE_SRV, @@ -849,13 +844,7 @@ void WrappedID3D12PipelineState::ProcessDescriptorAccess() continue; access.staticallyUnused = !bind.used; - access.type = DescriptorType::ReadWriteImage; - if(!refl.readWriteResources[i].isTexture) - access.type = (refl.readWriteResources[i].variableType.baseType == VarType::UByte || - !refl.readWriteResources[i].variableType.members.empty()) - ? DescriptorType::ReadWriteBuffer - : DescriptorType::ReadWriteTypedBuffer; - + access.type = refl.readWriteResources[i].descriptorType; access.index = i; rdctie(access.byteSize, access.byteOffset) = FindMatchingRootParameter(sig, visibility, D3D12_DESCRIPTOR_RANGE_TYPE_UAV, diff --git a/renderdoc/driver/gl/gl_shader_refl.cpp b/renderdoc/driver/gl/gl_shader_refl.cpp index 06aab166a..766bfabc0 100644 --- a/renderdoc/driver/gl/gl_shader_refl.cpp +++ b/renderdoc/driver/gl/gl_shader_refl.cpp @@ -1270,12 +1270,15 @@ void MakeShaderReflection(GLenum shadType, GLuint sepProg, ShaderReflection &ref res.variableType.arrayByteStride = 0; res.variableType.matrixByteStride = 0; + res.descriptorType = DescriptorType::ImageSampler; + // float samplers if(values[0] == eGL_SAMPLER_BUFFER) { res.resType = TextureType::Buffer; res.variableType.name = "samplerBuffer"; res.variableType.baseType = VarType::Float; + res.descriptorType = DescriptorType::TypedBuffer; } else if(values[0] == eGL_SAMPLER_1D) { @@ -1379,6 +1382,7 @@ void MakeShaderReflection(GLenum shadType, GLuint sepProg, ShaderReflection &ref res.resType = TextureType::Buffer; res.variableType.name = "isamplerBuffer"; res.variableType.baseType = VarType::SInt; + res.descriptorType = DescriptorType::TypedBuffer; } else if(values[0] == eGL_INT_SAMPLER_1D) { @@ -1446,6 +1450,7 @@ void MakeShaderReflection(GLenum shadType, GLuint sepProg, ShaderReflection &ref res.resType = TextureType::Buffer; res.variableType.name = "usamplerBuffer"; res.variableType.baseType = VarType::UInt; + res.descriptorType = DescriptorType::TypedBuffer; } else if(values[0] == eGL_UNSIGNED_INT_SAMPLER_1D) { @@ -1514,6 +1519,7 @@ void MakeShaderReflection(GLenum shadType, GLuint sepProg, ShaderReflection &ref res.variableType.name = "imageBuffer"; res.variableType.baseType = VarType::Float; res.isReadOnly = false; + res.descriptorType = DescriptorType::ReadWriteTypedBuffer; } else if(values[0] == eGL_IMAGE_1D) { @@ -1592,6 +1598,7 @@ void MakeShaderReflection(GLenum shadType, GLuint sepProg, ShaderReflection &ref res.variableType.name = "iimageBuffer"; res.variableType.baseType = VarType::SInt; res.isReadOnly = false; + res.descriptorType = DescriptorType::ReadWriteTypedBuffer; } else if(values[0] == eGL_INT_IMAGE_1D) { @@ -1670,6 +1677,7 @@ void MakeShaderReflection(GLenum shadType, GLuint sepProg, ShaderReflection &ref res.variableType.name = "uimageBuffer"; res.variableType.baseType = VarType::UInt; res.isReadOnly = false; + res.descriptorType = DescriptorType::ReadWriteTypedBuffer; } else if(values[0] == eGL_UNSIGNED_INT_IMAGE_1D) { @@ -1750,6 +1758,7 @@ void MakeShaderReflection(GLenum shadType, GLuint sepProg, ShaderReflection &ref res.isReadOnly = false; res.isTexture = false; res.variableType.columns = 1; + res.descriptorType = DescriptorType::ReadWriteBuffer; } else { @@ -1757,6 +1766,9 @@ void MakeShaderReflection(GLenum shadType, GLuint sepProg, ShaderReflection &ref continue; } + if(!res.isReadOnly && res.resType == TextureType::Buffer) + res.descriptorType = DescriptorType::ReadWriteImage; + res.hasSampler = res.isReadOnly; char *namebuf = new char[values[1] + 1]; @@ -1820,6 +1832,7 @@ void MakeShaderReflection(GLenum shadType, GLuint sepProg, ShaderReflection &ref res.variableType.baseType = VarType::UInt; res.bindPoint = (int32_t)rwresources.size(); res.name = nm; + res.descriptorType = DescriptorType::ReadWriteBuffer; GLint numMembers = 0; diff --git a/renderdoc/driver/shaders/dxbc/dxbc_reflect.cpp b/renderdoc/driver/shaders/dxbc/dxbc_reflect.cpp index 1869e05d9..cea8f03d8 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_reflect.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_reflect.cpp @@ -256,6 +256,24 @@ static void MakeResourceList(bool srv, DXBC::DXBCContainer *dxbc, res.fixedBindSetOrSpace = r.space; res.bindArraySize = r.bindCount == 0 ? ~0U : r.bindCount; + if(res.isReadOnly) + { + res.descriptorType = DescriptorType::Image; + if(!res.isTexture) + res.descriptorType = (r.type == DXBC::ShaderInputBind::TYPE_TBUFFER || + r.type == DXBC::ShaderInputBind::TYPE_TEXTURE) + ? DescriptorType::TypedBuffer + : DescriptorType::Buffer; + } + else + { + res.descriptorType = DescriptorType::ReadWriteImage; + if(!res.isTexture) + res.descriptorType = r.type == DXBC::ShaderInputBind::TYPE_UAV_RWTYPED + ? DescriptorType::ReadWriteTypedBuffer + : DescriptorType::ReadWriteBuffer; + } + Bindpoint map; map.arraySize = r.bindCount == 0 ? ~0U : r.bindCount; map.bindset = r.space; diff --git a/renderdoc/driver/shaders/spirv/spirv_reflect.cpp b/renderdoc/driver/shaders/spirv/spirv_reflect.cpp index 0ff054b1e..059f55c2c 100644 --- a/renderdoc/driver/shaders/spirv/spirv_reflect.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_reflect.cpp @@ -1399,6 +1399,7 @@ void Reflector::MakeReflection(const GraphicsAPI sourceAPI, const ShaderStage st if(res.name.empty()) res.name = StringFormat::Fmt("atomic%u", global.id.value()); res.resType = TextureType::Buffer; + res.descriptorType = DescriptorType::ReadWriteBuffer; res.variableType.columns = 1; res.variableType.rows = 1; @@ -1479,9 +1480,22 @@ void Reflector::MakeReflection(const GraphicsAPI sourceAPI, const ShaderStage st res.variableType.baseType = imageType.retType.Type(); if(res.isReadOnly) + { + res.descriptorType = + res.hasSampler ? DescriptorType::ImageSampler : DescriptorType::Image; + if(!res.isTexture) + res.descriptorType = DescriptorType::TypedBuffer; + roresources.push_back(shaderrespair(bindmap, global.id, res)); + } else + { + res.descriptorType = DescriptorType::ReadWriteImage; + if(!res.isTexture) + res.descriptorType = DescriptorType::ReadWriteTypedBuffer; + rwresources.push_back(shaderrespair(bindmap, global.id, res)); + } } } else @@ -1552,6 +1566,7 @@ void Reflector::MakeReflection(const GraphicsAPI sourceAPI, const ShaderStage st if(res.name.empty()) res.name = StringFormat::Fmt("ssbo%u", global.id.value()); res.resType = TextureType::Buffer; + res.descriptorType = DescriptorType::ReadWriteBuffer; res.fixedBindNumber = bindmap.bind; res.fixedBindSetOrSpace = bindmap.bindset; diff --git a/renderdoc/driver/vulkan/vk_info.cpp b/renderdoc/driver/vulkan/vk_info.cpp index 293f8917a..881f19947 100644 --- a/renderdoc/driver/vulkan/vk_info.cpp +++ b/renderdoc/driver/vulkan/vk_info.cpp @@ -894,11 +894,7 @@ void VulkanCreationInfo::Pipeline::Shader::ProcessStaticDescriptorAccess( continue; access.staticallyUnused = !bind.used; - access.type = DescriptorType::Image; - if(!refl->readOnlyResources[i].isTexture) - access.type = DescriptorType::TypedBuffer; - if(refl->readOnlyResources[i].hasSampler) - access.type = DescriptorType::ImageSampler; + access.type = refl->readOnlyResources[i].descriptorType; access.index = i; access.byteSize = bind.bindset; access.byteOffset = setLayoutInfos[bind.bindset]->bindings[bind.bind].elemOffset; @@ -914,10 +910,7 @@ void VulkanCreationInfo::Pipeline::Shader::ProcessStaticDescriptorAccess( continue; access.staticallyUnused = !bind.used; - access.type = DescriptorType::ReadWriteImage; - if(!refl->readWriteResources[i].isTexture) - access.type = DescriptorType::ReadWriteBuffer; - + access.type = refl->readWriteResources[i].descriptorType; access.index = i; access.byteSize = bind.bindset; access.byteOffset = setLayoutInfos[bind.bindset]->bindings[bind.bind].elemOffset; diff --git a/renderdoc/replay/renderdoc_serialise.inl b/renderdoc/replay/renderdoc_serialise.inl index bb67ee5d6..c540b2000 100644 --- a/renderdoc/replay/renderdoc_serialise.inl +++ b/renderdoc/replay/renderdoc_serialise.inl @@ -224,6 +224,7 @@ template void DoSerialise(SerialiserType &ser, ShaderResource &el) { SERIALISE_MEMBER(resType); + SERIALISE_MEMBER(descriptorType); SERIALISE_MEMBER(name); SERIALISE_MEMBER(variableType); SERIALISE_MEMBER(bindPoint);