[spirv] Added methods to force type declaration for arrays and structs

This commit is contained in:
Philip Rebohle 2017-12-08 19:50:36 +01:00
parent 0610296248
commit feab720ddb
3 changed files with 54 additions and 4 deletions

View File

@ -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);

View File

@ -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<uint32_t, 1> 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) {

View File

@ -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);