Commit af201e8a by John Kessenich

Merge branch GitHub 'master' into GitLab master

parents 4c42a976 c9e0a42b
...@@ -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;
...@@ -1707,25 +1726,25 @@ glslang::TLayoutPacking TGlslangToSpvTraverser::getExplicitLayout(const glslang: ...@@ -1707,25 +1726,25 @@ glslang::TLayoutPacking TGlslangToSpvTraverser::getExplicitLayout(const glslang:
int TGlslangToSpvTraverser::getArrayStride(const glslang::TType& arrayType, glslang::TLayoutPacking explicitLayout, glslang::TLayoutMatrix matrixLayout) int TGlslangToSpvTraverser::getArrayStride(const glslang::TType& arrayType, glslang::TLayoutPacking explicitLayout, glslang::TLayoutMatrix matrixLayout)
{ {
int size; int size;
int stride = glslangIntermediate->getBaseAlignment(arrayType, size, explicitLayout == glslang::ElpStd140, matrixLayout == glslang::ElmRowMajor); int stride;
if (arrayType.isMatrix()) { glslangIntermediate->getBaseAlignment(arrayType, size, stride, explicitLayout == glslang::ElpStd140, matrixLayout == glslang::ElmRowMajor);
// GLSL strides are set to alignments of the matrix flattened to individual rows/cols,
// but SPV needs an array stride for the whole matrix, not the rows/cols
if (matrixLayout == glslang::ElmRowMajor)
stride *= arrayType.getMatrixRows();
else
stride *= arrayType.getMatrixCols();
}
return stride; return stride;
} }
// Given a matrix type, returns the integer stride required for that matrix // Given a matrix type, or array (of array) of matrixes type, returns the integer stride required for that matrix
// when used as a member of an interface block // when used as a member of an interface block
int TGlslangToSpvTraverser::getMatrixStride(const glslang::TType& matrixType, glslang::TLayoutPacking explicitLayout, glslang::TLayoutMatrix matrixLayout) int TGlslangToSpvTraverser::getMatrixStride(const glslang::TType& matrixType, glslang::TLayoutPacking explicitLayout, glslang::TLayoutMatrix matrixLayout)
{ {
glslang::TType elementType;
elementType.shallowCopy(matrixType);
elementType.clearArraySizes();
int size; int size;
return glslangIntermediate->getBaseAlignment(matrixType, size, explicitLayout == glslang::ElpStd140, matrixLayout == glslang::ElmRowMajor); int stride;
glslangIntermediate->getBaseAlignment(elementType, size, stride, explicitLayout == glslang::ElpStd140, matrixLayout == glslang::ElmRowMajor);
return stride;
} }
// Given a member type of a struct, realign the current offset for it, and compute // Given a member type of a struct, realign the current offset for it, and compute
...@@ -1764,7 +1783,8 @@ void TGlslangToSpvTraverser::updateMemberOffset(const glslang::TType& structType ...@@ -1764,7 +1783,8 @@ void TGlslangToSpvTraverser::updateMemberOffset(const glslang::TType& structType
// but possibly not yet correctly aligned. // but possibly not yet correctly aligned.
int memberSize; int memberSize;
int memberAlignment = glslangIntermediate->getBaseAlignment(memberType, memberSize, explicitLayout == glslang::ElpStd140, matrixLayout == glslang::ElmRowMajor); int dummyStride;
int memberAlignment = glslangIntermediate->getBaseAlignment(memberType, memberSize, dummyStride, explicitLayout == glslang::ElpStd140, matrixLayout == glslang::ElmRowMajor);
glslang::RoundToPow2(currentOffset, memberAlignment); glslang::RoundToPow2(currentOffset, memberAlignment);
nextOffset = currentOffset + memberSize; nextOffset = currentOffset + memberSize;
} }
......
...@@ -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
......
...@@ -7,12 +7,12 @@ Linked vertex stage: ...@@ -7,12 +7,12 @@ Linked vertex stage:
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80001 // Generated by (magic number): 80001
// Id's are bound by 69 // Id's are bound by 70
Capability Shader Capability Shader
1: ExtInstImport "GLSL.std.450" 1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450 MemoryModel Logical GLSL450
EntryPoint Vertex 4 "main" 62 65 67 68 EntryPoint Vertex 4 "main" 63 66 68 69
Source GLSL 450 Source GLSL 450
Name 4 "main" Name 4 "main"
Name 14 "S" Name 14 "S"
...@@ -24,157 +24,159 @@ Linked vertex stage: ...@@ -24,157 +24,159 @@ Linked vertex stage:
MemberName 19(Block140) 1 "s" MemberName 19(Block140) 1 "s"
MemberName 19(Block140) 2 "v" MemberName 19(Block140) 2 "v"
Name 21 "inst140" Name 21 "inst140"
Name 22 "S" Name 23 "S"
MemberName 22(S) 0 "a" MemberName 23(S) 0 "a"
MemberName 22(S) 1 "b" MemberName 23(S) 1 "b"
MemberName 22(S) 2 "c" MemberName 23(S) 2 "c"
Name 25 "Block430" Name 26 "Block430"
MemberName 25(Block430) 0 "u" MemberName 26(Block430) 0 "u"
MemberName 25(Block430) 1 "s" MemberName 26(Block430) 1 "s"
MemberName 25(Block430) 2 "v" MemberName 26(Block430) 2 "v"
Name 27 "inst430" Name 28 "inst430"
Name 28 "S" Name 29 "S"
MemberName 28(S) 0 "a" MemberName 29(S) 0 "a"
MemberName 28(S) 1 "b" MemberName 29(S) 1 "b"
MemberName 28(S) 2 "c" MemberName 29(S) 2 "c"
Name 30 "s" Name 31 "s"
Name 31 "T" Name 32 "T"
MemberName 31(T) 0 "m" MemberName 32(T) 0 "m"
MemberName 31(T) 1 "a" MemberName 32(T) 1 "a"
Name 33 "t" Name 34 "t"
Name 34 "T" Name 35 "T"
MemberName 34(T) 0 "m" MemberName 35(T) 0 "m"
MemberName 34(T) 1 "a" MemberName 35(T) 1 "a"
Name 35 "Nestor" Name 36 "Nestor"
MemberName 35(Nestor) 0 "nestorT" MemberName 36(Nestor) 0 "nestorT"
Name 36 "Bt1" Name 37 "Bt1"
MemberName 36(Bt1) 0 "nt" MemberName 37(Bt1) 0 "nt"
Name 38 "Btn1" Name 39 "Btn1"
Name 39 "T" Name 40 "T"
MemberName 39(T) 0 "m" MemberName 40(T) 0 "m"
MemberName 39(T) 1 "a" MemberName 40(T) 1 "a"
Name 40 "Nestor" Name 41 "Nestor"
MemberName 40(Nestor) 0 "nestorT" MemberName 41(Nestor) 0 "nestorT"
Name 41 "Bt2" Name 42 "Bt2"
MemberName 41(Bt2) 0 "nt" MemberName 42(Bt2) 0 "nt"
Name 43 "Btn2" Name 44 "Btn2"
Name 44 "Bt3" Name 45 "Bt3"
MemberName 44(Bt3) 0 "ntcol" MemberName 45(Bt3) 0 "ntcol"
MemberName 44(Bt3) 1 "ntrow" MemberName 45(Bt3) 1 "ntrow"
Name 46 "Btn3" Name 47 "Btn3"
Name 47 "T" Name 48 "T"
MemberName 47(T) 0 "m" MemberName 48(T) 0 "m"
MemberName 47(T) 1 "a" MemberName 48(T) 1 "a"
Name 48 "Nestor" Name 49 "Nestor"
MemberName 48(Nestor) 0 "nestorT" MemberName 49(Nestor) 0 "nestorT"
Name 49 "bBt1" Name 50 "bBt1"
MemberName 49(bBt1) 0 "nt" MemberName 50(bBt1) 0 "nt"
Name 51 "bBtn1" Name 52 "bBtn1"
Name 52 "T" Name 53 "T"
MemberName 52(T) 0 "m" MemberName 53(T) 0 "m"
MemberName 52(T) 1 "a" MemberName 53(T) 1 "a"
Name 53 "Nestor" Name 54 "Nestor"
MemberName 53(Nestor) 0 "nestorT" MemberName 54(Nestor) 0 "nestorT"
Name 54 "bBt2" Name 55 "bBt2"
MemberName 54(bBt2) 0 "nt" MemberName 55(bBt2) 0 "nt"
Name 56 "bBtn2" Name 57 "bBtn2"
Name 57 "bBt3" Name 58 "bBt3"
MemberName 57(bBt3) 0 "ntcol" MemberName 58(bBt3) 0 "ntcol"
MemberName 57(bBt3) 1 "ntrow" MemberName 58(bBt3) 1 "ntrow"
Name 59 "bBtn3" Name 60 "bBtn3"
Name 60 "S" Name 61 "S"
MemberName 60(S) 0 "a" MemberName 61(S) 0 "a"
MemberName 60(S) 1 "b" MemberName 61(S) 1 "b"
MemberName 60(S) 2 "c" MemberName 61(S) 2 "c"
Name 62 "sout" Name 63 "sout"
Name 63 "S" Name 64 "S"
MemberName 63(S) 0 "a" MemberName 64(S) 0 "a"
MemberName 63(S) 1 "b" MemberName 64(S) 1 "b"
MemberName 63(S) 2 "c" MemberName 64(S) 2 "c"
Name 65 "soutinv" Name 66 "soutinv"
Name 67 "gl_VertexID" Name 68 "gl_VertexID"
Name 68 "gl_InstanceID" Name 69 "gl_InstanceID"
Decorate 13 ArrayStride 32 Decorate 13 ArrayStride 32
MemberDecorate 14(S) 0 Offset 0 MemberDecorate 14(S) 0 Offset 0
MemberDecorate 14(S) 1 ColMajor MemberDecorate 14(S) 1 ColMajor
MemberDecorate 14(S) 1 Offset 16 MemberDecorate 14(S) 1 Offset 16
MemberDecorate 14(S) 1 MatrixStride 16 MemberDecorate 14(S) 1 MatrixStride 16
MemberDecorate 14(S) 2 Offset 144 MemberDecorate 14(S) 2 Offset 144
Decorate 18 ArrayStride 16 Decorate 16 ArrayStride 160
Decorate 18 ArrayStride 480
MemberDecorate 19(Block140) 0 Offset 0 MemberDecorate 19(Block140) 0 Offset 0
MemberDecorate 19(Block140) 1 Offset 16 MemberDecorate 19(Block140) 1 Offset 16
MemberDecorate 19(Block140) 2 Offset 976 MemberDecorate 19(Block140) 2 Offset 976
Decorate 19(Block140) Block Decorate 19(Block140) Block
Decorate 21(inst140) DescriptorSet 0 Decorate 21(inst140) DescriptorSet 0
Decorate 21(inst140) Binding 0 Decorate 21(inst140) Binding 0
Decorate 13 ArrayStride 16 Decorate 22 ArrayStride 16
MemberDecorate 22(S) 0 Offset 0 MemberDecorate 23(S) 0 Offset 0
MemberDecorate 22(S) 1 ColMajor MemberDecorate 23(S) 1 ColMajor
MemberDecorate 22(S) 1 Offset 16 MemberDecorate 23(S) 1 Offset 16
MemberDecorate 22(S) 1 MatrixStride 8 MemberDecorate 23(S) 1 MatrixStride 8
MemberDecorate 22(S) 2 Offset 80 MemberDecorate 23(S) 2 Offset 80
Decorate 24 ArrayStride 16 Decorate 24 ArrayStride 96
MemberDecorate 25(Block430) 0 Offset 0 Decorate 25 ArrayStride 288
MemberDecorate 25(Block430) 1 Offset 16 MemberDecorate 26(Block430) 0 Offset 0
MemberDecorate 25(Block430) 2 Offset 592 MemberDecorate 26(Block430) 1 Offset 16
Decorate 25(Block430) BufferBlock MemberDecorate 26(Block430) 2 Offset 592
Decorate 27(inst430) DescriptorSet 0 Decorate 26(Block430) BufferBlock
Decorate 27(inst430) Binding 1 Decorate 28(inst430) DescriptorSet 0
MemberDecorate 34(T) 0 RowMajor Decorate 28(inst430) Binding 1
MemberDecorate 34(T) 0 Offset 0 MemberDecorate 35(T) 0 RowMajor
MemberDecorate 34(T) 0 MatrixStride 16 MemberDecorate 35(T) 0 Offset 0
MemberDecorate 34(T) 1 Offset 32 MemberDecorate 35(T) 0 MatrixStride 16
MemberDecorate 35(Nestor) 0 Offset 0 MemberDecorate 35(T) 1 Offset 32
MemberDecorate 36(Bt1) 0 Offset 0 MemberDecorate 36(Nestor) 0 Offset 0
Decorate 36(Bt1) Block MemberDecorate 37(Bt1) 0 Offset 0
Decorate 38(Btn1) DescriptorSet 1 Decorate 37(Bt1) Block
Decorate 38(Btn1) Binding 0 Decorate 39(Btn1) DescriptorSet 1
MemberDecorate 39(T) 0 ColMajor Decorate 39(Btn1) Binding 0
MemberDecorate 39(T) 0 Offset 0 MemberDecorate 40(T) 0 ColMajor
MemberDecorate 39(T) 0 MatrixStride 16 MemberDecorate 40(T) 0 Offset 0
MemberDecorate 39(T) 1 Offset 32 MemberDecorate 40(T) 0 MatrixStride 16
MemberDecorate 40(Nestor) 0 Offset 0 MemberDecorate 40(T) 1 Offset 32
MemberDecorate 41(Bt2) 0 Offset 0 MemberDecorate 41(Nestor) 0 Offset 0
Decorate 41(Bt2) Block MemberDecorate 42(Bt2) 0 Offset 0
Decorate 43(Btn2) DescriptorSet 1 Decorate 42(Bt2) Block
Decorate 43(Btn2) Binding 0 Decorate 44(Btn2) DescriptorSet 1
MemberDecorate 44(Bt3) 0 Offset 0 Decorate 44(Btn2) Binding 0
MemberDecorate 44(Bt3) 1 Offset 48 MemberDecorate 45(Bt3) 0 Offset 0
Decorate 44(Bt3) Block MemberDecorate 45(Bt3) 1 Offset 48
Decorate 46(Btn3) DescriptorSet 1 Decorate 45(Bt3) Block
Decorate 46(Btn3) Binding 0 Decorate 47(Btn3) DescriptorSet 1
MemberDecorate 47(T) 0 RowMajor Decorate 47(Btn3) Binding 0
MemberDecorate 47(T) 0 Offset 0 MemberDecorate 48(T) 0 RowMajor
MemberDecorate 47(T) 0 MatrixStride 8 MemberDecorate 48(T) 0 Offset 0
MemberDecorate 47(T) 1 Offset 16 MemberDecorate 48(T) 0 MatrixStride 8
MemberDecorate 48(Nestor) 0 Offset 0 MemberDecorate 48(T) 1 Offset 16
MemberDecorate 49(bBt1) 0 Offset 0 MemberDecorate 49(Nestor) 0 Offset 0
Decorate 49(bBt1) BufferBlock MemberDecorate 50(bBt1) 0 Offset 0
Decorate 51(bBtn1) DescriptorSet 1 Decorate 50(bBt1) BufferBlock
Decorate 51(bBtn1) Binding 0 Decorate 52(bBtn1) DescriptorSet 1
MemberDecorate 52(T) 0 ColMajor Decorate 52(bBtn1) Binding 0
MemberDecorate 52(T) 0 Offset 0 MemberDecorate 53(T) 0 ColMajor
MemberDecorate 52(T) 0 MatrixStride 8 MemberDecorate 53(T) 0 Offset 0
MemberDecorate 52(T) 1 Offset 16 MemberDecorate 53(T) 0 MatrixStride 8
MemberDecorate 53(Nestor) 0 Offset 0 MemberDecorate 53(T) 1 Offset 16
MemberDecorate 54(bBt2) 0 Offset 0 MemberDecorate 54(Nestor) 0 Offset 0
Decorate 54(bBt2) BufferBlock MemberDecorate 55(bBt2) 0 Offset 0
Decorate 56(bBtn2) DescriptorSet 1 Decorate 55(bBt2) BufferBlock
Decorate 56(bBtn2) Binding 0 Decorate 57(bBtn2) DescriptorSet 1
MemberDecorate 57(bBt3) 0 Offset 0 Decorate 57(bBtn2) Binding 0
MemberDecorate 57(bBt3) 1 Offset 24 MemberDecorate 58(bBt3) 0 Offset 0
Decorate 57(bBt3) BufferBlock MemberDecorate 58(bBt3) 1 Offset 24
Decorate 59(bBtn3) DescriptorSet 1 Decorate 58(bBt3) BufferBlock
Decorate 59(bBtn3) Binding 0 Decorate 60(bBtn3) DescriptorSet 1
MemberDecorate 60(S) 0 Flat Decorate 60(bBtn3) Binding 0
MemberDecorate 60(S) 1 Flat MemberDecorate 61(S) 0 Flat
MemberDecorate 60(S) 2 Flat MemberDecorate 61(S) 1 Flat
MemberDecorate 63(S) 0 Invariant MemberDecorate 61(S) 2 Flat
MemberDecorate 63(S) 1 Invariant MemberDecorate 64(S) 0 Invariant
MemberDecorate 63(S) 2 Invariant MemberDecorate 64(S) 1 Invariant
Decorate 65(soutinv) Invariant MemberDecorate 64(S) 2 Invariant
Decorate 67(gl_VertexID) BuiltIn VertexId Decorate 66(soutinv) Invariant
Decorate 68(gl_InstanceID) BuiltIn InstanceId Decorate 68(gl_VertexID) BuiltIn VertexId
Decorate 69(gl_InstanceID) BuiltIn InstanceId
2: TypeVoid 2: TypeVoid
3: TypeFunction 2 3: TypeFunction 2
6: TypeInt 32 1 6: TypeInt 32 1
...@@ -193,53 +195,54 @@ Linked vertex stage: ...@@ -193,53 +195,54 @@ Linked vertex stage:
19(Block140): TypeStruct 6(int) 18 10(fvec2) 19(Block140): TypeStruct 6(int) 18 10(fvec2)
20: TypePointer Uniform 19(Block140) 20: TypePointer Uniform 19(Block140)
21(inst140): 20(ptr) Variable Uniform 21(inst140): 20(ptr) Variable Uniform
22(S): TypeStruct 8(ivec3) 13 7(int) 22: TypeArray 11 12
23: TypeArray 22(S) 15 23(S): TypeStruct 8(ivec3) 22 7(int)
24: TypeArray 23 17 24: TypeArray 23(S) 15
25(Block430): TypeStruct 6(int) 24 10(fvec2) 25: TypeArray 24 17
26: TypePointer Uniform 25(Block430) 26(Block430): TypeStruct 6(int) 25 10(fvec2)
27(inst430): 26(ptr) Variable Uniform 27: TypePointer Uniform 26(Block430)
28(S): TypeStruct 8(ivec3) 13 7(int) 28(inst430): 27(ptr) Variable Uniform
29: TypePointer Private 28(S) 29(S): TypeStruct 8(ivec3) 13 7(int)
30(s): 29(ptr) Variable Private 30: TypePointer Private 29(S)
31(T): TypeStruct 11 6(int) 31(s): 30(ptr) Variable Private
32: TypePointer Private 31(T) 32(T): TypeStruct 11 6(int)
33(t): 32(ptr) Variable Private 33: TypePointer Private 32(T)
34(T): TypeStruct 11 6(int) 34(t): 33(ptr) Variable Private
35(Nestor): TypeStruct 34(T) 35(T): TypeStruct 11 6(int)
36(Bt1): TypeStruct 35(Nestor) 36(Nestor): TypeStruct 35(T)
37: TypePointer Uniform 36(Bt1) 37(Bt1): TypeStruct 36(Nestor)
38(Btn1): 37(ptr) Variable Uniform 38: TypePointer Uniform 37(Bt1)
39(T): TypeStruct 11 6(int) 39(Btn1): 38(ptr) Variable Uniform
40(Nestor): TypeStruct 39(T) 40(T): TypeStruct 11 6(int)
41(Bt2): TypeStruct 40(Nestor) 41(Nestor): TypeStruct 40(T)
42: TypePointer Uniform 41(Bt2) 42(Bt2): TypeStruct 41(Nestor)
43(Btn2): 42(ptr) Variable Uniform 43: TypePointer Uniform 42(Bt2)
44(Bt3): TypeStruct 40(Nestor) 35(Nestor) 44(Btn2): 43(ptr) Variable Uniform
45: TypePointer Uniform 44(Bt3) 45(Bt3): TypeStruct 41(Nestor) 36(Nestor)
46(Btn3): 45(ptr) Variable Uniform 46: TypePointer Uniform 45(Bt3)
47(T): TypeStruct 11 6(int) 47(Btn3): 46(ptr) Variable Uniform
48(Nestor): TypeStruct 47(T) 48(T): TypeStruct 11 6(int)
49(bBt1): TypeStruct 48(Nestor) 49(Nestor): TypeStruct 48(T)
50: TypePointer Uniform 49(bBt1) 50(bBt1): TypeStruct 49(Nestor)
51(bBtn1): 50(ptr) Variable Uniform 51: TypePointer Uniform 50(bBt1)
52(T): TypeStruct 11 6(int) 52(bBtn1): 51(ptr) Variable Uniform
53(Nestor): TypeStruct 52(T) 53(T): TypeStruct 11 6(int)
54(bBt2): TypeStruct 53(Nestor) 54(Nestor): TypeStruct 53(T)
55: TypePointer Uniform 54(bBt2) 55(bBt2): TypeStruct 54(Nestor)
56(bBtn2): 55(ptr) Variable Uniform 56: TypePointer Uniform 55(bBt2)
57(bBt3): TypeStruct 48(Nestor) 53(Nestor) 57(bBtn2): 56(ptr) Variable Uniform
58: TypePointer Uniform 57(bBt3) 58(bBt3): TypeStruct 49(Nestor) 54(Nestor)
59(bBtn3): 58(ptr) Variable Uniform 59: TypePointer Uniform 58(bBt3)
60(S): TypeStruct 8(ivec3) 13 7(int) 60(bBtn3): 59(ptr) Variable Uniform
61: TypePointer Output 60(S) 61(S): TypeStruct 8(ivec3) 13 7(int)
62(sout): 61(ptr) Variable Output 62: TypePointer Output 61(S)
63(S): TypeStruct 8(ivec3) 13 7(int) 63(sout): 62(ptr) Variable Output
64: TypePointer Output 63(S) 64(S): TypeStruct 8(ivec3) 13 7(int)
65(soutinv): 64(ptr) Variable Output 65: TypePointer Output 64(S)
66: TypePointer Input 6(int) 66(soutinv): 65(ptr) Variable Output
67(gl_VertexID): 66(ptr) Variable Input 67: TypePointer Input 6(int)
68(gl_InstanceID): 66(ptr) Variable Input 68(gl_VertexID): 67(ptr) Variable Input
69(gl_InstanceID): 67(ptr) Variable Input
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
Return Return
......
...@@ -1206,6 +1206,10 @@ public: ...@@ -1206,6 +1206,10 @@ public:
arraySizes = new TArraySizes; arraySizes = new TArraySizes;
*arraySizes = s; *arraySizes = s;
} }
void clearArraySizes()
{
arraySizes = 0;
}
void addArrayOuterSizes(const TArraySizes& s) void addArrayOuterSizes(const TArraySizes& s)
{ {
if (arraySizes == nullptr) if (arraySizes == nullptr)
......
...@@ -5353,7 +5353,8 @@ void TParseContext::fixBlockUniformOffsets(TQualifier& qualifier, TTypeList& typ ...@@ -5353,7 +5353,8 @@ void TParseContext::fixBlockUniformOffsets(TQualifier& qualifier, TTypeList& typ
// modify just the children's view of matrix layout, if there is one for this member // modify just the children's view of matrix layout, if there is one for this member
TLayoutMatrix subMatrixLayout = typeList[member].type->getQualifier().layoutMatrix; TLayoutMatrix subMatrixLayout = typeList[member].type->getQualifier().layoutMatrix;
int memberAlignment = intermediate.getBaseAlignment(*typeList[member].type, memberSize, qualifier.layoutPacking == ElpStd140, int dummyStride;
int memberAlignment = intermediate.getBaseAlignment(*typeList[member].type, memberSize, dummyStride, qualifier.layoutPacking == ElpStd140,
subMatrixLayout != ElmNone ? subMatrixLayout == ElmRowMajor : qualifier.layoutMatrix == ElmRowMajor); subMatrixLayout != ElmNone ? subMatrixLayout == ElmRowMajor : qualifier.layoutMatrix == ElmRowMajor);
if (memberQualifier.hasOffset()) { if (memberQualifier.hasOffset()) {
// "The specified offset must be a multiple // "The specified offset must be a multiple
......
...@@ -858,8 +858,14 @@ int TIntermediate::getBaseAlignmentScalar(const TType& type, int& size) ...@@ -858,8 +858,14 @@ int TIntermediate::getBaseAlignmentScalar(const TType& type, int& size)
// otherwise it does not, yielding std430 rules. // otherwise it does not, yielding std430 rules.
// //
// The size is returned in the 'size' parameter // The size is returned in the 'size' parameter
//
// The stride is only non-0 for arrays or matrices, and is the stride of the
// top-level object nested within the type. E.g., for an array of matrices,
// it is the distances needed between matrices, despite the rules saying the
// stride comes from the flattening down to vectors.
//
// Return value is the alignment of the type. // Return value is the alignment of the type.
int TIntermediate::getBaseAlignment(const TType& type, int& size, bool std140, bool rowMajor) int TIntermediate::getBaseAlignment(const TType& type, int& size, int& stride, bool std140, bool rowMajor)
{ {
int alignment; int alignment;
...@@ -916,16 +922,23 @@ int TIntermediate::getBaseAlignment(const TType& type, int& size, bool std140, b ...@@ -916,16 +922,23 @@ int TIntermediate::getBaseAlignment(const TType& type, int& size, bool std140, b
// //
// 10. If the member is an array of S structures, the S elements of the array are laid // 10. If the member is an array of S structures, the S elements of the array are laid
// out in order, according to rule (9). // out in order, according to rule (9).
//
// Assuming, for rule 10: The stride is the same as the size of an element.
stride = 0;
int dummyStride;
// rules 4, 6, and 8 // rules 4, 6, 8, and 10
if (type.isArray()) { if (type.isArray()) {
// TODO: perf: this might be flattened by using getCumulativeArraySize(), and a deref that discards all arrayness // TODO: perf: this might be flattened by using getCumulativeArraySize(), and a deref that discards all arrayness
TType derefType(type, 0); TType derefType(type, 0);
alignment = getBaseAlignment(derefType, size, std140, rowMajor); alignment = getBaseAlignment(derefType, size, dummyStride, std140, rowMajor);
if (std140) if (std140)
alignment = std::max(baseAlignmentVec4Std140, alignment); alignment = std::max(baseAlignmentVec4Std140, alignment);
RoundToPow2(size, alignment); RoundToPow2(size, alignment);
size *= type.getOuterArraySize(); stride = size; // uses full matrix size for stride of an array of matrices (not quite what rule 6/8, but what's expected)
// uses the assumption for rule 10 in the comment above
size = stride * type.getOuterArraySize();
return alignment; return alignment;
} }
...@@ -939,7 +952,7 @@ int TIntermediate::getBaseAlignment(const TType& type, int& size, bool std140, b ...@@ -939,7 +952,7 @@ int TIntermediate::getBaseAlignment(const TType& type, int& size, bool std140, b
int memberSize; int memberSize;
// modify just the children's view of matrix layout, if there is one for this member // modify just the children's view of matrix layout, if there is one for this member
TLayoutMatrix subMatrixLayout = memberList[m].type->getQualifier().layoutMatrix; TLayoutMatrix subMatrixLayout = memberList[m].type->getQualifier().layoutMatrix;
int memberAlignment = getBaseAlignment(*memberList[m].type, memberSize, std140, int memberAlignment = getBaseAlignment(*memberList[m].type, memberSize, dummyStride, std140,
(subMatrixLayout != ElmNone) ? (subMatrixLayout == ElmRowMajor) : rowMajor); (subMatrixLayout != ElmNone) ? (subMatrixLayout == ElmRowMajor) : rowMajor);
maxAlignment = std::max(maxAlignment, memberAlignment); maxAlignment = std::max(maxAlignment, memberAlignment);
RoundToPow2(size, memberAlignment); RoundToPow2(size, memberAlignment);
...@@ -971,14 +984,15 @@ int TIntermediate::getBaseAlignment(const TType& type, int& size, bool std140, b ...@@ -971,14 +984,15 @@ int TIntermediate::getBaseAlignment(const TType& type, int& size, bool std140, b
// rule 5: deref to row, not to column, meaning the size of vector is num columns instead of num rows // rule 5: deref to row, not to column, meaning the size of vector is num columns instead of num rows
TType derefType(type, 0, type.getQualifier().layoutMatrix == ElmRowMajor); TType derefType(type, 0, type.getQualifier().layoutMatrix == ElmRowMajor);
alignment = getBaseAlignment(derefType, size, std140, rowMajor); alignment = getBaseAlignment(derefType, size, dummyStride, std140, rowMajor);
if (std140) if (std140)
alignment = std::max(baseAlignmentVec4Std140, alignment); alignment = std::max(baseAlignmentVec4Std140, alignment);
RoundToPow2(size, alignment); RoundToPow2(size, alignment);
stride = size; // use intra-matrix stride for stride of a just a matrix
if (rowMajor) if (rowMajor)
size *= type.getMatrixRows(); size = stride * type.getMatrixRows();
else else
size *= type.getMatrixCols(); size = stride * type.getMatrixCols();
return alignment; return alignment;
} }
......
...@@ -305,7 +305,7 @@ public: ...@@ -305,7 +305,7 @@ public:
} }
int addXfbBufferOffset(const TType&); int addXfbBufferOffset(const TType&);
unsigned int computeTypeXfbSize(const TType&, bool& containsDouble) const; unsigned int computeTypeXfbSize(const TType&, bool& containsDouble) const;
static int getBaseAlignment(const TType&, int& size, bool std140, bool rowMajor); static int getBaseAlignment(const TType&, int& size, int& stride, bool std140, bool rowMajor);
protected: protected:
void error(TInfoSink& infoSink, const char*); void error(TInfoSink& infoSink, const char*);
......
...@@ -121,11 +121,12 @@ public: ...@@ -121,11 +121,12 @@ public:
return memberList[index].type->getQualifier().layoutOffset; return memberList[index].type->getQualifier().layoutOffset;
int memberSize; int memberSize;
int dummyStride;
int offset = 0; int offset = 0;
for (int m = 0; m <= index; ++m) { for (int m = 0; m <= index; ++m) {
// modify just the children's view of matrix layout, if there is one for this member // modify just the children's view of matrix layout, if there is one for this member
TLayoutMatrix subMatrixLayout = memberList[m].type->getQualifier().layoutMatrix; TLayoutMatrix subMatrixLayout = memberList[m].type->getQualifier().layoutMatrix;
int memberAlignment = intermediate.getBaseAlignment(*memberList[m].type, memberSize, type.getQualifier().layoutPacking == ElpStd140, int memberAlignment = intermediate.getBaseAlignment(*memberList[m].type, memberSize, dummyStride, type.getQualifier().layoutPacking == ElpStd140,
subMatrixLayout != ElmNone ? subMatrixLayout == ElmRowMajor : type.getQualifier().layoutMatrix == ElmRowMajor); subMatrixLayout != ElmNone ? subMatrixLayout == ElmRowMajor : type.getQualifier().layoutMatrix == ElmRowMajor);
RoundToPow2(offset, memberAlignment); RoundToPow2(offset, memberAlignment);
if (m < index) if (m < index)
...@@ -144,7 +145,8 @@ public: ...@@ -144,7 +145,8 @@ public:
int lastOffset = getOffset(blockType, lastIndex); int lastOffset = getOffset(blockType, lastIndex);
int lastMemberSize; int lastMemberSize;
intermediate.getBaseAlignment(*memberList[lastIndex].type, lastMemberSize, blockType.getQualifier().layoutPacking == ElpStd140, int dummyStride;
intermediate.getBaseAlignment(*memberList[lastIndex].type, lastMemberSize, dummyStride, blockType.getQualifier().layoutPacking == ElpStd140,
blockType.getQualifier().layoutMatrix == ElmRowMajor); blockType.getQualifier().layoutMatrix == ElmRowMajor);
return lastOffset + lastMemberSize; return lastOffset + lastMemberSize;
......
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