Commit c9e0a42b by John Kessenich

SPV: Handle stride decorations for arrays of arrays, and using multiple type…

SPV: Handle stride decorations for arrays of arrays, and using multiple type instances when strides are used.
parent 4998789d
...@@ -1651,10 +1651,37 @@ spv::Id TGlslangToSpvTraverser::convertGlslangToSpvType(const glslang::TType& ty ...@@ -1651,10 +1651,37 @@ spv::Id TGlslangToSpvTraverser::convertGlslangToSpvType(const glslang::TType& ty
} }
if (type.isArray()) { if (type.isArray()) {
int stride = 0; // keep this 0 unless doing an explicit layout; 0 will mean no decoration, no stride
// Do all but the outer dimension // Do all but the outer dimension
for (int dim = type.getArraySizes()->getNumDims() - 1; dim > 0; --dim) { if (type.getArraySizes()->getNumDims() > 1) {
assert(type.getArraySizes()->getDimSize(dim) > 0); if (explicitLayout != glslang::ElpNone) {
spvType = builder.makeArrayType(spvType, type.getArraySizes()->getDimSize(dim)); // Use a dummy glslang type for querying internal strides of
// arrays of arrays, but using just a one-dimensional array.
glslang::TType simpleArrayType(type, 0); // deference type of the array
while (simpleArrayType.getArraySizes().getNumDims() > 1)
simpleArrayType.getArraySizes().dereference();
// Will compute the higher-order strides here, rather than making a whole
// pile of types and doing repetitive recursion on their contents.
stride = getArrayStride(simpleArrayType, explicitLayout, qualifier.layoutMatrix);
}
for (int dim = type.getArraySizes()->getNumDims() - 1; dim > 0; --dim) {
int size = type.getArraySizes()->getDimSize(dim);
assert(size > 0);
spvType = builder.makeArrayType(spvType, size, stride);
if (stride > 0)
builder.addDecoration(spvType, spv::DecorationArrayStride, stride);
stride *= size;
}
} else {
// single-dimensional array, and don't yet have stride
// We need to decorate array strides for types needing explicit layout,
// except for the very top if it is an array of blocks; that array is
// not laid out in memory in a way needing a stride.
if (explicitLayout != glslang::ElpNone && type.getBasicType() != glslang::EbtBlock)
stride = getArrayStride(type, explicitLayout, qualifier.layoutMatrix);
} }
// Do the outer dimension, which might not be known for a runtime-sized array // Do the outer dimension, which might not be known for a runtime-sized array
...@@ -1662,18 +1689,10 @@ spv::Id TGlslangToSpvTraverser::convertGlslangToSpvType(const glslang::TType& ty ...@@ -1662,18 +1689,10 @@ spv::Id TGlslangToSpvTraverser::convertGlslangToSpvType(const glslang::TType& ty
spvType = builder.makeRuntimeArray(spvType); spvType = builder.makeRuntimeArray(spvType);
} else { } else {
assert(type.getOuterArraySize() > 0); assert(type.getOuterArraySize() > 0);
spvType = builder.makeArrayType(spvType, type.getOuterArraySize()); spvType = builder.makeArrayType(spvType, type.getOuterArraySize(), stride);
} }
if (stride > 0)
// TODO: explicit layout still needs to be done hierarchically for arrays of arrays, which builder.addDecoration(spvType, spv::DecorationArrayStride, stride);
// may still require additional "link time" support from the front-end
// for arrays of arrays
// We need to decorate array strides for types needing explicit layout,
// except for the very top if it is an array of blocks; that array is
// not laid out in memory in a way needing a stride.
if (explicitLayout && type.getBasicType() != glslang::EbtBlock)
builder.addDecoration(spvType, spv::DecorationArrayStride, getArrayStride(type, explicitLayout, qualifier.layoutMatrix));
} }
return spvType; return spvType;
......
...@@ -281,18 +281,23 @@ Id Builder::makeMatrixType(Id component, int cols, int rows) ...@@ -281,18 +281,23 @@ Id Builder::makeMatrixType(Id component, int cols, int rows)
return type->getResultId(); return type->getResultId();
} }
Id Builder::makeArrayType(Id element, unsigned size) // TODO: performance: track arrays per stride
// If a stride is supplied (non-zero) make an array.
// If no stride (0), reuse previous array types.
Id Builder::makeArrayType(Id element, unsigned size, int stride)
{ {
// First, we need a constant instruction for the size // First, we need a constant instruction for the size
Id sizeId = makeUintConstant(size); Id sizeId = makeUintConstant(size);
// try to find existing type
Instruction* type; Instruction* type;
for (int t = 0; t < (int)groupedTypes[OpTypeArray].size(); ++t) { if (stride == 0) {
type = groupedTypes[OpTypeArray][t]; // try to find existing type
if (type->getIdOperand(0) == element && for (int t = 0; t < (int)groupedTypes[OpTypeArray].size(); ++t) {
type->getIdOperand(1) == sizeId) type = groupedTypes[OpTypeArray][t];
return type->getResultId(); if (type->getIdOperand(0) == element &&
type->getIdOperand(1) == sizeId)
return type->getResultId();
}
} }
// not found, make it // not found, make it
......
...@@ -102,7 +102,7 @@ public: ...@@ -102,7 +102,7 @@ public:
Id makeStructResultType(Id type0, Id type1); Id makeStructResultType(Id type0, Id type1);
Id makeVectorType(Id component, int size); Id makeVectorType(Id component, int size);
Id makeMatrixType(Id component, int cols, int rows); Id makeMatrixType(Id component, int cols, int rows);
Id makeArrayType(Id element, unsigned size); Id makeArrayType(Id element, unsigned size, int stride); // 0 means no stride decoration
Id makeRuntimeArray(Id element); Id makeRuntimeArray(Id element);
Id makeFunctionType(Id returnType, std::vector<Id>& paramTypes); Id makeFunctionType(Id returnType, std::vector<Id>& paramTypes);
Id makeImageType(Id sampledType, Dim, bool depth, bool arrayed, bool ms, unsigned sampled, ImageFormat format); Id makeImageType(Id sampledType, Dim, bool depth, bool arrayed, bool ms, unsigned sampled, ImageFormat format);
......
...@@ -5,7 +5,7 @@ Linked fragment stage: ...@@ -5,7 +5,7 @@ Linked fragment stage:
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80001 // Generated by (magic number): 80001
// Id's are bound by 99 // Id's are bound by 100
Capability Shader Capability Shader
1: ExtInstImport "GLSL.std.450" 1: ExtInstImport "GLSL.std.450"
...@@ -24,39 +24,39 @@ Linked fragment stage: ...@@ -24,39 +24,39 @@ Linked fragment stage:
Name 55 "sampR" Name 55 "sampR"
Name 63 "sampB" Name 63 "sampB"
Name 86 "samp2Da" Name 86 "samp2Da"
Name 90 "bn" Name 91 "bn"
MemberName 90(bn) 0 "matra" MemberName 91(bn) 0 "matra"
MemberName 90(bn) 1 "matca" MemberName 91(bn) 1 "matca"
MemberName 90(bn) 2 "matr" MemberName 91(bn) 2 "matr"
MemberName 90(bn) 3 "matc" MemberName 91(bn) 3 "matc"
MemberName 90(bn) 4 "matrdef" MemberName 91(bn) 4 "matrdef"
Name 92 "" Name 93 ""
Name 95 "bi" Name 96 "bi"
MemberName 95(bi) 0 "v" MemberName 96(bi) 0 "v"
Name 98 "bname" Name 99 "bname"
Decorate 16(gl_FrontFacing) BuiltIn FrontFacing Decorate 16(gl_FrontFacing) BuiltIn FrontFacing
Decorate 33(gl_ClipDistance) BuiltIn ClipDistance Decorate 33(gl_ClipDistance) BuiltIn ClipDistance
Decorate 89 ArrayStride 64 Decorate 89 ArrayStride 64
Decorate 89 ArrayStride 64 Decorate 90 ArrayStride 64
MemberDecorate 90(bn) 0 RowMajor MemberDecorate 91(bn) 0 RowMajor
MemberDecorate 90(bn) 0 Offset 0 MemberDecorate 91(bn) 0 Offset 0
MemberDecorate 90(bn) 0 MatrixStride 16 MemberDecorate 91(bn) 0 MatrixStride 16
MemberDecorate 90(bn) 1 ColMajor MemberDecorate 91(bn) 1 ColMajor
MemberDecorate 90(bn) 1 Offset 256 MemberDecorate 91(bn) 1 Offset 256
MemberDecorate 90(bn) 1 MatrixStride 16 MemberDecorate 91(bn) 1 MatrixStride 16
MemberDecorate 90(bn) 2 RowMajor MemberDecorate 91(bn) 2 RowMajor
MemberDecorate 90(bn) 2 Offset 512 MemberDecorate 91(bn) 2 Offset 512
MemberDecorate 90(bn) 2 MatrixStride 16 MemberDecorate 91(bn) 2 MatrixStride 16
MemberDecorate 90(bn) 3 ColMajor MemberDecorate 91(bn) 3 ColMajor
MemberDecorate 90(bn) 3 Offset 576 MemberDecorate 91(bn) 3 Offset 576
MemberDecorate 90(bn) 3 MatrixStride 16 MemberDecorate 91(bn) 3 MatrixStride 16
MemberDecorate 90(bn) 4 RowMajor MemberDecorate 91(bn) 4 RowMajor
MemberDecorate 90(bn) 4 Offset 640 MemberDecorate 91(bn) 4 Offset 640
MemberDecorate 90(bn) 4 MatrixStride 16 MemberDecorate 91(bn) 4 MatrixStride 16
Decorate 90(bn) Block Decorate 91(bn) Block
Decorate 94 ArrayStride 16 Decorate 95 ArrayStride 16
MemberDecorate 95(bi) 0 Offset 0 MemberDecorate 96(bi) 0 Offset 0
Decorate 95(bi) Block Decorate 96(bi) Block
2: TypeVoid 2: TypeVoid
3: TypeFunction 2 3: TypeFunction 2
6: TypeFloat 32 6: TypeFloat 32
...@@ -108,15 +108,16 @@ Linked fragment stage: ...@@ -108,15 +108,16 @@ Linked fragment stage:
87: TypeMatrix 26(fvec4) 4 87: TypeMatrix 26(fvec4) 4
88: 29(int) Constant 4 88: 29(int) Constant 4
89: TypeArray 87 88 89: TypeArray 87 88
90(bn): TypeStruct 89 89 87 87 87 90: TypeArray 87 88
91: TypePointer Uniform 90(bn) 91(bn): TypeStruct 89 90 87 87 87
92: 91(ptr) Variable Uniform 92: TypePointer Uniform 91(bn)
93: TypeVector 6(float) 3 93: 92(ptr) Variable Uniform
94: TypeArray 93(fvec3) 50 94: TypeVector 6(float) 3
95(bi): TypeStruct 94 95: TypeArray 94(fvec3) 50
96: TypeArray 95(bi) 88 96(bi): TypeStruct 95
97: TypePointer Uniform 96 97: TypeArray 96(bi) 88
98(bname): 97(ptr) Variable Uniform 98: TypePointer Uniform 97
99(bname): 98(ptr) Variable Uniform
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
13: 12(ptr) Variable Function 13: 12(ptr) Variable Function
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment