[lunarglass] r1106 committed - GLSL Metadata: Propagate matrix majorness to arbitrary depth in the hi...

2 views
Skip to first unread message

lunar...@googlecode.com

unread,
Aug 11, 2015, 11:06:51 AM8/11/15
to lunargla...@googlegroups.com
Revision: 1106
Author: jo...@lunarg.com
Date: Tue Aug 11 15:06:31 2015 UTC
Log: GLSL Metadata: Propagate matrix majorness to arbitrary depth in
the hierarchy of metadata that adds type information.

https://code.google.com/p/lunarglass/source/detail?r=1106

Added:
/trunk/test/baseResults/metaMat.frag.out
/trunk/test/metaMat.frag
Modified:
/trunk/Frontends/glslang/GlslangToTopVisitor.cpp
/trunk/test/runtests

=======================================
--- /dev/null
+++ /trunk/test/baseResults/metaMat.frag.out Tue Aug 11 15:06:31 2015 UTC
@@ -0,0 +1,172 @@
+
+Top IR:
+; ModuleID = 'Glslang'
+
+%BNA = type { [3 x <4 x float>], %Si1 }
+%Si1 = type { float, %S1 }
+%S1 = type { i32, [2 x <3 x float>] }
+%BNB = type { [3 x <3 x float>], %Si1, %Si2, %Si2, [4 x <4 x float>], [4 x
<4 x float>] }
+%Si2 = type { float, %S2 }
+%S2 = type { i32, [2 x <3 x float>] }
+
+@BNAI = external addrspace(2) constant %BNA
+@BNBI = external addrspace(2) constant %BNB
+
+define fastcc void @main() {
+entry:
+ br label %mainBody
+
+mainBody: ; preds = %entry
+ br label %stage-epilogue
+
+stage-epilogue: ; preds = %mainBody
+ br label %stage-exit
+
+stage-exit: ; preds = %stage-epilogue
+ ret void
+}
+
+!gla.entrypoint = !{!0}
+!gla.uniforms = !{!1, !13}
+!gla.noStaticUse = !{!1, !13}
+
+!0 = metadata !{metadata !"main", i32 15}
+!1 = metadata !{metadata !"BNAI", i32 13, %BNA* @BNAI_typeProxy,
metadata !2, metadata !3}
+!2 = metadata !{i32 6, i32 0, i32 1024, null}
+!3 = metadata !{metadata !"BNA", metadata !2, metadata !"BNAm",
metadata !4, metadata !"si1", metadata !6}
+!4 = metadata !{metadata !"", metadata !5}
+!5 = metadata !{i32 3, i32 3, i32 1024, null}
+!6 = metadata !{metadata !"Si1", metadata !7, metadata !"f", metadata !8,
metadata !"s1", metadata !10}
+!7 = metadata !{i32 4, i32 0, i32 1024, null}
+!8 = metadata !{metadata !"", metadata !9}
+!9 = metadata !{i32 0, i32 3, i32 1024, null}
+!10 = metadata !{metadata !"S1", metadata !7, metadata !"i", metadata !11,
metadata !"S1m", metadata !4}
+!11 = metadata !{metadata !"", metadata !12}
+!12 = metadata !{i32 1, i32 2, i32 1024, null}
+!13 = metadata !{metadata !"BNBI", i32 13, %BNB* @BNBI_typeProxy,
metadata !2, metadata !14}
+!14 = metadata !{metadata !"BNB", metadata !2, metadata !"BNBm3",
metadata !15, metadata !"si1", metadata !17, metadata !"si21",
metadata !19, metadata !"si22", metadata !21, metadata !"BNBm41",
metadata !4, metadata !"BNBm42", metadata !15}
+!15 = metadata !{metadata !"", metadata !16}
+!16 = metadata !{i32 2, i32 3, i32 1024, null}
+!17 = metadata !{metadata !"Si1", metadata !7, metadata !"f", metadata !8,
metadata !"s1", metadata !18}
+!18 = metadata !{metadata !"S1", metadata !7, metadata !"i", metadata !11,
metadata !"S1m", metadata !15}
+!19 = metadata !{metadata !"Si2", metadata !7, metadata !"g", metadata !8,
metadata !"s2", metadata !20}
+!20 = metadata !{metadata !"S2", metadata !7, metadata !"i", metadata !11,
metadata !"S2m", metadata !4}
+!21 = metadata !{metadata !"Si2", metadata !7, metadata !"g", metadata !8,
metadata !"s2", metadata !22}
+!22 = metadata !{metadata !"S2", metadata !7, metadata !"i", metadata !11,
metadata !"S2m", metadata !15}
+
+
+Bottom IR:
+; ModuleID = 'Glslang'
+
+define fastcc void @main() {
+entry:
+ br label %stage-epilogue
+
+stage-epilogue: ; preds = %entry
+ br label %stage-exit
+
+stage-exit: ; preds = %stage-epilogue
+ ret void
+}
+
+!gla.entrypoint = !{!0}
+!gla.uniforms = !{!1, !13}
+!gla.noStaticUse = !{!1, !13}
+
+!0 = metadata !{metadata !"main", i32 15}
+!1 = metadata !{metadata !"BNAI", i32 13, %BNA* @BNAI_typeProxy,
metadata !2, metadata !3}
+!2 = metadata !{i32 6, i32 0, i32 1024, null}
+!3 = metadata !{metadata !"BNA", metadata !2, metadata !"BNAm",
metadata !4, metadata !"si1", metadata !6}
+!4 = metadata !{metadata !"", metadata !5}
+!5 = metadata !{i32 3, i32 3, i32 1024, null}
+!6 = metadata !{metadata !"Si1", metadata !7, metadata !"f", metadata !8,
metadata !"s1", metadata !10}
+!7 = metadata !{i32 4, i32 0, i32 1024, null}
+!8 = metadata !{metadata !"", metadata !9}
+!9 = metadata !{i32 0, i32 3, i32 1024, null}
+!10 = metadata !{metadata !"S1", metadata !7, metadata !"i", metadata !11,
metadata !"S1m", metadata !4}
+!11 = metadata !{metadata !"", metadata !12}
+!12 = metadata !{i32 1, i32 2, i32 1024, null}
+!13 = metadata !{metadata !"BNBI", i32 13, %BNB* @BNBI_typeProxy,
metadata !2, metadata !14}
+!14 = metadata !{metadata !"BNB", metadata !2, metadata !"BNBm3",
metadata !15, metadata !"si1", metadata !17, metadata !"si21",
metadata !19, metadata !"si22", metadata !21, metadata !"BNBm41",
metadata !4, metadata !"BNBm42", metadata !15}
+!15 = metadata !{metadata !"", metadata !16}
+!16 = metadata !{i32 2, i32 3, i32 1024, null}
+!17 = metadata !{metadata !"Si1", metadata !7, metadata !"f", metadata !8,
metadata !"s1", metadata !18}
+!18 = metadata !{metadata !"S1", metadata !7, metadata !"i", metadata !11,
metadata !"S1m", metadata !15}
+!19 = metadata !{metadata !"Si2", metadata !7, metadata !"g", metadata !8,
metadata !"s2", metadata !20}
+!20 = metadata !{metadata !"S2", metadata !7, metadata !"i", metadata !11,
metadata !"S2m", metadata !4}
+!21 = metadata !{metadata !"Si2", metadata !7, metadata !"g", metadata !8,
metadata !"s2", metadata !22}
+!22 = metadata !{metadata !"S2", metadata !7, metadata !"i", metadata !11,
metadata !"S2m", metadata !15}
+#version 300 es
+// LunarGOO output
+precision mediump float; // this will be almost entirely overridden by
individual declarations
+struct S1 {
+ mediump uint i;
+ highp mat2x3 S1m;
+};
+struct Si1 {
+ highp float f;
+ S1 s1;
+};
+struct S2 {
+ mediump uint i;
+ highp mat2x3 S2m;
+};
+struct Si2 {
+ highp float g;
+ S2 s2;
+};
+uniform BNA {
+ highp mat3x4 BNAm;
+ Si1 si1;
+} BNAI;
+uniform BNB {
+ layout(row_major) highp mat3 BNBm3;
+ Si1 si1;
+ Si2 si21;
+ Si2 si22;
+ highp mat4 BNBm41;
+ layout(row_major) highp mat4 BNBm42;
+} BNBI;
+
+void main()
+{
+
+}
+
+#version 300 es
+// LunarGOO output
+precision mediump float; // this will be almost entirely overridden by
individual declarations
+struct S1 {
+ mediump uint i;
+ highp mat2x3 S1m;
+};
+struct Si1 {
+ highp float f;
+ S1 s1;
+};
+struct S2 {
+ mediump uint i;
+ highp mat2x3 S2m;
+};
+struct Si2 {
+ highp float g;
+ S2 s2;
+};
+uniform BNA {
+ highp mat3x4 BNAm;
+ Si1 si1;
+} BNAI;
+uniform BNB {
+ layout(row_major) highp mat3 BNBm3;
+ Si1 si1;
+ Si2 si21;
+ Si2 si22;
+ highp mat4 BNBm41;
+ layout(row_major) highp mat4 BNBm42;
+} BNBI;
+
+void main()
+{
+
+}
+
=======================================
--- /dev/null
+++ /trunk/test/metaMat.frag Tue Aug 11 15:06:31 2015 UTC
@@ -0,0 +1,40 @@
+#version 300 es
+precision highp float;
+
+struct S1 {
+ uint i;
+ mat2x3 S1m;
+};
+
+struct S2 {
+ uint i;
+ mat2x3 S2m;
+};
+
+struct Si1 {
+ float f;
+ S1 s1;
+};
+
+struct Si2 {
+ float g;
+ S2 s2;
+};
+
+uniform BNA {
+ mat3x4 BNAm;
+ Si1 si1;
+} BNAI;
+
+layout (row_major) uniform BNB {
+ mat3 BNBm3;
+ Si1 si1;
+ layout(column_major) Si2 si21;
+ layout(row_major) Si2 si22;
+ layout(column_major) mat4 BNBm41;
+ mat4 BNBm42;
+} BNBI;
+
+void main()
+{
+}
=======================================
--- /trunk/Frontends/glslang/GlslangToTopVisitor.cpp Mon Aug 10 23:34:15
2015 UTC
+++ /trunk/Frontends/glslang/GlslangToTopVisitor.cpp Tue Aug 11 15:06:31
2015 UTC
@@ -120,10 +120,11 @@
llvm::Constant* createLLVMConstant(const glslang::TType& type, const
glslang::TConstUnionArray&, int& nextConst);
llvm::Value* MakePermanentTypeProxy(llvm::Type*, llvm::StringRef name);
llvm::MDNode* declareUniformMetadata(glslang::TIntermSymbol* node,
llvm::Value*);
- llvm::MDNode* declareMdIo(llvm::StringRef symbolName, const
glslang::TType&, llvm::Type* proxyType, llvm::StringRef proxyName, int
slot, const char* kind = nullptr);
- void declareChildMdIo(const glslang::TType& type, llvm::Type*
proxyType, llvm::SmallVector<llvm::MDNode*, 10>& members);
+ llvm::MDNode* declareMdIo(llvm::StringRef symbolName, const
glslang::TType&, llvm::Type* proxyType, llvm::StringRef proxyName, int slot,
+ gla::EMdTypeLayout inheritMatrix, const
char* kind = nullptr);
+ void declareChildMdIo(const glslang::TType& type, llvm::Type*
proxyType, llvm::SmallVector<llvm::MDNode*, 10>& members,
gla::EMdTypeLayout inheritMatrix);
llvm::MDNode* makeMdSampler(const glslang::TType&, llvm::Type*,
llvm::StringRef name);
- llvm::MDNode* declareMdType(const glslang::TType&);
+ llvm::MDNode* declareMdType(const glslang::TType&, gla::EMdTypeLayout
inheritMatrix);
void setOutputMetadata(glslang::TIntermSymbol* node, llvm::Value*, int
slot, int numSlots);
llvm::MDNode* makeInputMetadata(glslang::TIntermSymbol* node,
llvm::Value*, int slot);

@@ -215,16 +216,37 @@
return mdQualifier;
}

-gla::EMdTypeLayout GetMdTypeLayout(const glslang::TType& type)
+gla::EMdTypeLayout GetMdTypeLayout(const glslang::TType& type,
gla::EMdTypeLayout& inheritMatrix)
{
gla::EMdTypeLayout mdType;

if (type.isMatrix()) {
switch (type.getQualifier().layoutMatrix) {
- case glslang::ElmRowMajor: mdType = gla::EMtlRowMajorMatrix;
break;
- default: mdType = gla::EMtlColMajorMatrix;
break;
+ case glslang::ElmRowMajor:
+ mdType = gla::EMtlRowMajorMatrix;
+ break;
+ case glslang::ElmColumnMajor:
+ mdType = gla::EMtlColMajorMatrix;
+ break;
+ default:
+ if (inheritMatrix != gla::EMtlNone)
+ mdType = inheritMatrix;
+ else
+ mdType = gla::EMtlColMajorMatrix;
+ break;
}
} else {
+ switch (type.getQualifier().layoutMatrix) {
+ case glslang::ElmRowMajor:
+ inheritMatrix = gla::EMtlRowMajorMatrix;
+ break;
+ case glslang::ElmColumnMajor:
+ inheritMatrix = gla::EMtlColMajorMatrix;
+ break;
+ default:
+ break;
+ }
+
switch (type.getBasicType()) {
default: mdType = gla::EMtlNone; break;
case glslang::EbtSampler: mdType = gla::EMtlSampler; break;
@@ -2840,9 +2862,10 @@
return glaBuilder->getConstant(llvmConsts, type);
}

+// Make a type proxy that won't be optimized away (we still want the real
llvm::Value to get optimized away when it can)
llvm::Value* TGlslangToTopTraverser::MakePermanentTypeProxy(llvm::Type*
type, llvm::StringRef name)
{
- // Make a type proxy that won't be optimized away (we still want the
real llvm::Value to get optimized away when it can)
+ // bypass pointers
while (type->getTypeID() == llvm::Type::PointerTyID)
type =
llvm::dyn_cast<llvm::PointerType>(type)->getContainedType(0);

@@ -2871,8 +2894,14 @@
return 0;
}

-// Make a !aggregate, hierarchically, in metadata, recursively, as per
metadata.h.
-llvm::MDNode* TGlslangToTopTraverser::declareMdType(const glslang::TType&
type)
+// Make a !aggregate, hierarchically, in metadata, as per metadata.h,
+// for either a block or a structure.
+// This function walks the hierarchicy recursively.
+// If a structure is used more than once in the hierarchy, it is walked
more than once,
+// giving a chance to have different majorness (e.g.) each time (LLVM
reuses MD nodes when it can).
+// 'inheritMatrix' will get corrected each time a top-level block member
is visited,
+// and should then stay the same while visiting the substructure of that
member.
+llvm::MDNode* TGlslangToTopTraverser::declareMdType(const glslang::TType&
type, gla::EMdTypeLayout inheritMatrix)
{
// Figure out sampler information if it's a sampler
llvm::MDNode* samplerMd = makeMdSampler(type, nullptr, "");
@@ -2886,7 +2915,7 @@
mdArgs.push_back(llvm::MDString::get(context, ""));

// !typeLayout
- mdArgs.push_back(metadata.makeMdTypeLayout(GetMdTypeLayout(type),
GetMdPrecision(type), GetMdSlotLocation(type), samplerMd, -1,
GetMdBuiltIn(type)));
+ mdArgs.push_back(metadata.makeMdTypeLayout(GetMdTypeLayout(type,
inheritMatrix), GetMdPrecision(type), GetMdSlotLocation(type), samplerMd,
-1, GetMdBuiltIn(type)));

const glslang::TTypeList* typeList = type.getStruct();
if (typeList) {
@@ -2899,7 +2928,7 @@
mdArgs.push_back(llvm::MDString::get(context,
fieldType->getFieldName().c_str()));

// type of member
- llvm::MDNode* mdType = declareMdType(*fieldType);
+ llvm::MDNode* mdType = declareMdType(*fieldType,
inheritMatrix);
mdArgs.push_back(mdType);
}
}
@@ -2908,13 +2937,15 @@
}

// Make a !gla.uniform/input/output node, as per metadata.h, selected
by "kind"
+// Called at the block level.
+// If using useSingleTypeTree(), then it is mutually recursive with
declareChildMdIo.
llvm::MDNode* TGlslangToTopTraverser::declareMdIo(llvm::StringRef
instanceName, const glslang::TType& type, llvm::Type* proxyType,
llvm::StringRef proxyName,
- int slot, const char*
kind)
+ int slot,
gla::EMdTypeLayout inheritMatrix, const char* kind)
{
llvm::MDNode* samplerMd = makeMdSampler(type, proxyType, proxyName);
gla::EInterpolationMode interpolationMode = -1;
int location;
- gla::EMdTypeLayout layout = GetMdTypeLayout(type);
+ gla::EMdTypeLayout layout = GetMdTypeLayout(type, inheritMatrix);
gla::EMdInputOutput ioType = GetMdQualifier(type);

switch (ioType) {
@@ -2942,7 +2973,7 @@
llvm::SmallVector<llvm::MDNode*, 10> members;
if (type.getBasicType() == glslang::EbtStruct ||
type.getBasicType() == glslang::EbtBlock) {
typeName = type.getTypeName().c_str();
- declareChildMdIo(type, proxyType, members);
+ declareChildMdIo(type, proxyType, members, inheritMatrix);
}

// Make the !typeLayout for this level
@@ -2962,7 +2993,7 @@
// Make hierarchical type information (a recursive !aggregate node)
llvm::MDNode* aggregate = nullptr;
if (type.getBasicType() == glslang::EbtStruct ||
type.getBasicType() == glslang::EbtBlock)
- aggregate = declareMdType(type);
+ aggregate = declareMdType(type, inheritMatrix);

// Make the top-level !gla.uniform/input/output node that points
to the recursive !aggregate node
return metadata.makeMdInputOutput(instanceName, kind, ioType,
MakePermanentTypeProxy(proxyType, proxyName),
@@ -2972,7 +3003,12 @@
}

// Make a !gla.uniform/input/output child node, as per metadata.h
-void TGlslangToTopTraverser::declareChildMdIo(const glslang::TType& type,
llvm::Type* proxyType, llvm::SmallVector<llvm::MDNode*, 10>& members)
+// Operates mutually recursively with declareMdIo().
+// If a structure is used more than once in the hierarchy, it is walked
more than once,
+// giving a chance to have different majorness (e.g.) each time (LLVM
reuses MD nodes when it can).
+// 'inheritMatrix' will get corrected each time a top-level block member
is visited,
+// and should then stay the same while visiting the substructure of that
member.
+void TGlslangToTopTraverser::declareChildMdIo(const glslang::TType& type,
llvm::Type* proxyType, llvm::SmallVector<llvm::MDNode*, 10>& members,
gla::EMdTypeLayout inheritMatrix)
{
const glslang::TTypeList* typeList = type.getStruct();
if (typeList) {
@@ -2989,7 +3025,7 @@
continue;
// build a child md node and add it as an argument

members.push_back(declareMdIo(fieldType->getFieldName().c_str(),
*fieldType, structType->getContainedType(nonHiddenCount),
fieldType->getFieldName().c_str(),
- GetMdSlotLocation(type)));
+ GetMdSlotLocation(type),
inheritMatrix));
++nonHiddenCount;
}
}
@@ -3003,7 +3039,8 @@
if (md)
return md;

- md = declareMdIo(filterMdName(node->getName().c_str()),
node->getType(), value->getType(), value->getName(), 0,
gla::UniformListMdName);
+ gla::EMdTypeLayout inheritMatrix = gla::EMtlNone;
+ md = declareMdIo(filterMdName(node->getName().c_str()),
node->getType(), value->getType(), value->getName(), 0, inheritMatrix,
gla::UniformListMdName);
uniformMdMap[name] = md;

if (linkageOnly)
@@ -3016,7 +3053,8 @@
// output-variable cache in the gla builder.
void TGlslangToTopTraverser::setOutputMetadata(glslang::TIntermSymbol*
node, llvm::Value* storage, int slot, int numSlots)
{
- llvm::MDNode* md = declareMdIo(filterMdName(node->getName().c_str()),
node->getType(), storage->getType(), storage->getName(), slot,
gla::OutputListMdName);
+ gla::EMdTypeLayout inheritMatrix = gla::EMtlNone;
+ llvm::MDNode* md = declareMdIo(filterMdName(node->getName().c_str()),
node->getType(), storage->getType(), storage->getName(), slot,
inheritMatrix, gla::OutputListMdName);

if (node->getQualifier().invariant)

module->getOrInsertNamedMetadata(gla::InvariantListMdName)->addOperand(md);
@@ -3032,7 +3070,8 @@
llvm::MDNode* mdNode = inputMdMap[slot];
if (mdNode == 0) {
// set up metadata for pipeline intrinsic read
- mdNode = declareMdIo(filterMdName(node->getName().c_str()),
node->getType(), value->getType(), value->getName(), slot,
gla::InputListMdName);
+ gla::EMdTypeLayout inheritMatrix = gla::EMtlNone;
+ mdNode = declareMdIo(filterMdName(node->getName().c_str()),
node->getType(), value->getType(), value->getName(), slot, inheritMatrix,
gla::InputListMdName);
inputMdMap[slot] = mdNode;
if (linkageOnly)
metadata.addNoStaticUse(mdNode);
=======================================
--- /trunk/test/runtests Fri Jul 24 20:27:07 2015 UTC
+++ /trunk/test/runtests Tue Aug 11 15:06:31 2015 UTC
@@ -53,13 +53,14 @@
300layout.vert \
300layout.frag \
310.comp \
- simpleSwitch.vert \
+ simpleSwitch.vert \
switch.frag \
whileLoop.frag \
doWhileLoop.frag \
loops.frag \
forLoop.frag \
- atomic.comp \
+ atomic.comp \
+ metaMat.frag \
130.frag \
140.frag \
150.vert \
Reply all
Reply to author
Forward
0 new messages