Store descriptor type directly in shader resources for shader reflection

This commit is contained in:
baldurk
2024-03-25 11:40:26 +00:00
parent 292bb596dc
commit f00ab9dee8
8 changed files with 59 additions and 35 deletions
+6
View File
@@ -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;
+2 -13
View File
@@ -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});
+2 -13
View File
@@ -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,
+13
View File
@@ -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;
@@ -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;
@@ -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;
+2 -9
View File
@@ -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;
+1
View File
@@ -224,6 +224,7 @@ template <typename SerialiserType>
void DoSerialise(SerialiserType &ser, ShaderResource &el)
{
SERIALISE_MEMBER(resType);
SERIALISE_MEMBER(descriptorType);
SERIALISE_MEMBER(name);
SERIALISE_MEMBER(variableType);
SERIALISE_MEMBER(bindPoint);