diff --git a/src/dxbc/gen/dxbc_gen_common.cpp b/src/dxbc/gen/dxbc_gen_common.cpp index e4f26995..b5150871 100644 --- a/src/dxbc/gen/dxbc_gen_common.cpp +++ b/src/dxbc/gen/dxbc_gen_common.cpp @@ -39,9 +39,10 @@ namespace dxvk { void DxbcCodeGen::dclConstantBuffer( uint32_t bufferId, uint32_t elementCount) { - uint32_t arrayType = this->defValueType( - DxbcValueType(DxbcScalarType::Float32, 4, elementCount)); - uint32_t structType = m_module.defStructType(1, &arrayType); + uint32_t arrayType = m_module.defArrayTypeUnique( + this->defValueType(DxbcValueType(DxbcScalarType::Float32, 4)), + m_module.constu32(elementCount)); + uint32_t structType = m_module.defStructTypeUnique(1, &arrayType); m_module.decorateArrayStride(arrayType, 16); m_module.memberDecorateOffset(structType, 0, 0); @@ -448,7 +449,7 @@ namespace dxvk { members[PerVertex_CullDist] = a2f32; members[PerVertex_ClipDist] = a2f32; - uint32_t typeId = m_module.defStructType( + uint32_t typeId = m_module.defStructTypeUnique( members.size(), members.data()); m_module.memberDecorateBuiltIn(typeId, PerVertex_Position, spv::BuiltInPosition); diff --git a/src/spirv/spirv_module.cpp b/src/spirv/spirv_module.cpp index 0a1bf642..6e67674b 100644 --- a/src/spirv/spirv_module.cpp +++ b/src/spirv/spirv_module.cpp @@ -392,6 +392,19 @@ namespace dxvk { } + uint32_t SpirvModule::defArrayTypeUnique( + uint32_t typeId, + uint32_t length) { + uint32_t resultId = this->allocateId(); + + m_typeConstDefs.putIns (spv::OpTypeArray, 4); + m_typeConstDefs.putWord(resultId); + m_typeConstDefs.putWord(typeId); + m_typeConstDefs.putWord(length); + return resultId; + } + + uint32_t SpirvModule::defRuntimeArrayType( uint32_t typeId) { std::array args = { typeId }; @@ -401,6 +414,17 @@ namespace dxvk { } + uint32_t SpirvModule::defRuntimeArrayTypeUnique( + uint32_t typeId) { + uint32_t resultId = this->allocateId(); + + m_typeConstDefs.putIns (spv::OpTypeRuntimeArray, 3); + m_typeConstDefs.putWord(resultId); + m_typeConstDefs.putWord(typeId); + return resultId; + } + + uint32_t SpirvModule::defFunctionType( uint32_t returnType, uint32_t argCount, @@ -424,6 +448,20 @@ namespace dxvk { } + uint32_t SpirvModule::defStructTypeUnique( + uint32_t memberCount, + const uint32_t* memberTypes) { + uint32_t resultId = this->allocateId(); + + m_typeConstDefs.putIns (spv::OpTypeStruct, 2 + memberCount); + m_typeConstDefs.putWord(resultId); + + for (uint32_t i = 0; i < memberCount; i++) + m_typeConstDefs.putWord(memberTypes[i]); + return resultId; + } + + uint32_t SpirvModule::defPointerType( uint32_t variableType, spv::StorageClass storageClass) { diff --git a/src/spirv/spirv_module.h b/src/spirv/spirv_module.h index f06a76d1..34b412c0 100644 --- a/src/spirv/spirv_module.h +++ b/src/spirv/spirv_module.h @@ -148,9 +148,16 @@ namespace dxvk { uint32_t typeId, uint32_t length); + uint32_t defArrayTypeUnique( + uint32_t typeId, + uint32_t length); + uint32_t defRuntimeArrayType( uint32_t typeId); + uint32_t defRuntimeArrayTypeUnique( + uint32_t typeId); + uint32_t defFunctionType( uint32_t returnType, uint32_t argCount, @@ -160,6 +167,10 @@ namespace dxvk { uint32_t memberCount, const uint32_t* memberTypes); + uint32_t defStructTypeUnique( + uint32_t memberCount, + const uint32_t* memberTypes); + uint32_t defPointerType( uint32_t variableType, spv::StorageClass storageClass);