Shader/SPIRV: Fix structs being always decorated as block

They are now only decorated as blocks when used as uniform buffers, which fixes structure nesting
This commit is contained in:
Jérôme Leclercq
2021-12-23 17:36:40 +01:00
parent ed3ee34565
commit a5cc915948
3 changed files with 36 additions and 5 deletions

View File

@@ -143,8 +143,24 @@ namespace Nz
{
SpirvConstantCache::Variable variable;
variable.debugName = extVar.name;
variable.storageClass = (ShaderAst::IsSamplerType(extVar.type)) ? SpirvStorageClass::UniformConstant : SpirvStorageClass::Uniform;
variable.type = m_constantCache.BuildPointerType(extVar.type, variable.storageClass);
if (ShaderAst::IsSamplerType(extVar.type))
{
variable.storageClass = SpirvStorageClass::UniformConstant;
variable.type = m_constantCache.BuildPointerType(extVar.type, variable.storageClass);
}
else
{
assert(ShaderAst::IsUniformType(extVar.type));
const auto& uniformType = std::get<ShaderAst::UniformType>(extVar.type);
assert(std::holds_alternative<ShaderAst::StructType>(uniformType.containedType));
const auto& structType = std::get<ShaderAst::StructType>(uniformType.containedType);
assert(structType.structIndex < declaredStructs.size());
const auto& type = m_constantCache.BuildType(*declaredStructs[structType.structIndex], { SpirvDecoration::Block });
variable.storageClass = SpirvStorageClass::Uniform;
variable.type = m_constantCache.BuildPointerType(type, variable.storageClass);
}
assert(extVar.bindingIndex.IsResultingValue());