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:
parent
ed3ee34565
commit
a5cc915948
|
|
@ -105,6 +105,7 @@ namespace Nz
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
std::vector<Member> members;
|
std::vector<Member> members;
|
||||||
|
std::vector<SpirvDecoration> decorations;
|
||||||
};
|
};
|
||||||
|
|
||||||
using AnyType = std::variant<Bool, Float, Function, Image, Integer, Matrix, Pointer, SampledImage, Structure, Vector, Void>;
|
using AnyType = std::variant<Bool, Float, Function, Image, Integer, Matrix, Pointer, SampledImage, Structure, Vector, Void>;
|
||||||
|
|
@ -166,6 +167,7 @@ namespace Nz
|
||||||
TypePtr BuildFunctionType(const ShaderAst::ExpressionType& retType, const std::vector<ShaderAst::ExpressionType>& parameters) const;
|
TypePtr BuildFunctionType(const ShaderAst::ExpressionType& retType, const std::vector<ShaderAst::ExpressionType>& parameters) const;
|
||||||
TypePtr BuildPointerType(const ShaderAst::PrimitiveType& type, SpirvStorageClass storageClass) const;
|
TypePtr BuildPointerType(const ShaderAst::PrimitiveType& type, SpirvStorageClass storageClass) const;
|
||||||
TypePtr BuildPointerType(const ShaderAst::ExpressionType& type, SpirvStorageClass storageClass) const;
|
TypePtr BuildPointerType(const ShaderAst::ExpressionType& type, SpirvStorageClass storageClass) const;
|
||||||
|
TypePtr BuildPointerType(const TypePtr& type, SpirvStorageClass storageClass) const;
|
||||||
TypePtr BuildType(const ShaderAst::ExpressionType& type) const;
|
TypePtr BuildType(const ShaderAst::ExpressionType& type) const;
|
||||||
TypePtr BuildType(const ShaderAst::IdentifierType& type) const;
|
TypePtr BuildType(const ShaderAst::IdentifierType& type) const;
|
||||||
TypePtr BuildType(const ShaderAst::MatrixType& type) const;
|
TypePtr BuildType(const ShaderAst::MatrixType& type) const;
|
||||||
|
|
@ -173,7 +175,7 @@ namespace Nz
|
||||||
TypePtr BuildType(const ShaderAst::PrimitiveType& type) const;
|
TypePtr BuildType(const ShaderAst::PrimitiveType& type) const;
|
||||||
TypePtr BuildType(const ShaderAst::SamplerType& type) const;
|
TypePtr BuildType(const ShaderAst::SamplerType& type) const;
|
||||||
TypePtr BuildType(const ShaderAst::StructType& type) const;
|
TypePtr BuildType(const ShaderAst::StructType& type) const;
|
||||||
TypePtr BuildType(const ShaderAst::StructDescription& structDesc) const;
|
TypePtr BuildType(const ShaderAst::StructDescription& structDesc, std::vector<SpirvDecoration> decorations = {}) const;
|
||||||
TypePtr BuildType(const ShaderAst::VectorType& type) const;
|
TypePtr BuildType(const ShaderAst::VectorType& type) const;
|
||||||
TypePtr BuildType(const ShaderAst::UniformType& type) const;
|
TypePtr BuildType(const ShaderAst::UniformType& type) const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,9 @@ namespace Nz
|
||||||
if (lhs.name != rhs.name)
|
if (lhs.name != rhs.name)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (lhs.decorations != rhs.decorations)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (!Compare(lhs.members, rhs.members))
|
if (!Compare(lhs.members, rhs.members))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
@ -484,6 +487,14 @@ namespace Nz
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto SpirvConstantCache::BuildPointerType(const TypePtr& type, SpirvStorageClass storageClass) const -> TypePtr
|
||||||
|
{
|
||||||
|
return std::make_shared<Type>(Pointer{
|
||||||
|
type,
|
||||||
|
storageClass
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
auto SpirvConstantCache::BuildPointerType(const ShaderAst::PrimitiveType& type, SpirvStorageClass storageClass) const -> TypePtr
|
auto SpirvConstantCache::BuildPointerType(const ShaderAst::PrimitiveType& type, SpirvStorageClass storageClass) const -> TypePtr
|
||||||
{
|
{
|
||||||
return std::make_shared<Type>(Pointer{
|
return std::make_shared<Type>(Pointer{
|
||||||
|
|
@ -583,10 +594,11 @@ namespace Nz
|
||||||
return BuildType(m_internal->structCallback(type.structIndex));
|
return BuildType(m_internal->structCallback(type.structIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto SpirvConstantCache::BuildType(const ShaderAst::StructDescription& structDesc) const -> TypePtr
|
auto SpirvConstantCache::BuildType(const ShaderAst::StructDescription& structDesc, std::vector<SpirvDecoration> decorations) const -> TypePtr
|
||||||
{
|
{
|
||||||
Structure sType;
|
Structure sType;
|
||||||
sType.name = structDesc.name;
|
sType.name = structDesc.name;
|
||||||
|
sType.decorations = std::move(decorations);
|
||||||
|
|
||||||
for (const auto& member : structDesc.members)
|
for (const auto& member : structDesc.members)
|
||||||
{
|
{
|
||||||
|
|
@ -864,7 +876,8 @@ namespace Nz
|
||||||
|
|
||||||
debugInfos.Append(SpirvOp::OpName, resultId, structData.name);
|
debugInfos.Append(SpirvOp::OpName, resultId, structData.name);
|
||||||
|
|
||||||
annotations.Append(SpirvOp::OpDecorate, resultId, SpirvDecoration::Block);
|
for (SpirvDecoration decoration : structData.decorations)
|
||||||
|
annotations.Append(SpirvOp::OpDecorate, resultId, decoration);
|
||||||
|
|
||||||
FieldOffsets structOffsets(StructLayout::Std140);
|
FieldOffsets structOffsets(StructLayout::Std140);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -143,8 +143,24 @@ namespace Nz
|
||||||
{
|
{
|
||||||
SpirvConstantCache::Variable variable;
|
SpirvConstantCache::Variable variable;
|
||||||
variable.debugName = extVar.name;
|
variable.debugName = extVar.name;
|
||||||
variable.storageClass = (ShaderAst::IsSamplerType(extVar.type)) ? SpirvStorageClass::UniformConstant : SpirvStorageClass::Uniform;
|
|
||||||
|
if (ShaderAst::IsSamplerType(extVar.type))
|
||||||
|
{
|
||||||
|
variable.storageClass = SpirvStorageClass::UniformConstant;
|
||||||
variable.type = m_constantCache.BuildPointerType(extVar.type, variable.storageClass);
|
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());
|
assert(extVar.bindingIndex.IsResultingValue());
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue