Skip to content

Commit a18a0aa

Browse files
committed
Apply NoContraction to dot()
Implement the change in issue 2708 so `noContraction` is set for `dot()` in the AST. Translate `EOpDot` using `createBinaryOperation()`, which handles setting the `NoContraction` decoration unlike `createMiscOperation()`.
1 parent 4a038ea commit a18a0aa

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

SPIRV/GlslangToSpv.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,6 +3276,8 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
32763276
glslang::TIntermSequence& glslangOperands = node->getSequence();
32773277
if (glslangOperands[0]->getAsTyped()->getVectorSize() == 1)
32783278
binOp = glslang::EOpMul;
3279+
else if (isTypeFloat(node->getType().getBasicType()))
3280+
binOp = glslang::EOpDot;
32793281
break;
32803282
}
32813283
case glslang::EOpMod:
@@ -7130,6 +7132,9 @@ spv::Id TGlslangToSpvTraverser::createBinaryOperation(glslang::TOperator op, OpD
71307132
binOp = spv::OpOuterProduct;
71317133
needMatchingVectors = false;
71327134
break;
7135+
case glslang::EOpDot:
7136+
binOp = spv::OpDot;
7137+
break;
71337138

71347139
case glslang::EOpDiv:
71357140
case glslang::EOpDivAssign:
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
spv.precise.dot.vert
2+
// Module Version 10000
3+
// Generated by (magic number): 8000b
4+
// Id's are bound by 28
5+
6+
Capability Shader
7+
1: ExtInstImport "GLSL.std.450"
8+
MemoryModel Logical GLSL450
9+
EntryPoint Vertex 4 "main" 21
10+
Source GLSL 450
11+
Name 4 "main"
12+
Name 9 "v"
13+
Name 11 "u"
14+
Name 15 "f"
15+
Name 19 "gl_PerVertex"
16+
MemberName 19(gl_PerVertex) 0 "gl_Position"
17+
Name 21 ""
18+
Decorate 18 NoContraction
19+
Decorate 19(gl_PerVertex) Block
20+
MemberDecorate 19(gl_PerVertex) 0 BuiltIn Position
21+
2: TypeVoid
22+
3: TypeFunction 2
23+
6: TypeFloat 32
24+
7: TypeVector 6(float) 4
25+
8: TypePointer Function 7(fvec4)
26+
10: TypePointer Private 6(float)
27+
11(u): 10(ptr) Variable Private
28+
14: TypePointer Function 6(float)
29+
19(gl_PerVertex): TypeStruct 7(fvec4)
30+
20: TypePointer Output 19(gl_PerVertex)
31+
21: 20(ptr) Variable Output
32+
22: TypeInt 32 1
33+
23: 22(int) Constant 0
34+
26: TypePointer Output 7(fvec4)
35+
4(main): 2 Function None 3
36+
5: Label
37+
9(v): 8(ptr) Variable Function
38+
15(f): 14(ptr) Variable Function
39+
12: 6(float) Load 11(u)
40+
13: 7(fvec4) CompositeConstruct 12 12 12 12
41+
Store 9(v) 13
42+
16: 7(fvec4) Load 9(v)
43+
17: 7(fvec4) Load 9(v)
44+
18: 6(float) Dot 16 17
45+
Store 15(f) 18
46+
24: 6(float) Load 15(f)
47+
25: 7(fvec4) CompositeConstruct 24 24 24 24
48+
27: 26(ptr) AccessChain 21 23
49+
Store 27 25
50+
Return
51+
FunctionEnd

Test/spv.precise.dot.vert

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#version 450 core
2+
3+
out gl_PerVertex
4+
{
5+
precise vec4 gl_Position;
6+
};
7+
8+
float u;
9+
10+
void main()
11+
{
12+
vec4 v = vec4(u);
13+
float f = dot(v, v);
14+
gl_Position = vec4(f);
15+
}

glslang/MachineIndependent/propagateNoContraction.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,10 @@ class TNoContractionPropagator : public glslang::TIntermTraverser {
689689
}
690690
return false;
691691
}
692+
// If this is an arithmetic operation, marks this node as 'noContraction'.
693+
if (isArithmeticOperation(node->getOp())) {
694+
node->getWritableType().getQualifier().noContraction = true;
695+
}
692696
return true;
693697
}
694698

gtests/Spv.FromFile.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ INSTANTIATE_TEST_SUITE_P(
531531
"spv.subgroupSizeARB.frag",
532532
"spv.precise.tese",
533533
"spv.precise.tesc",
534+
"spv.precise.dot.vert",
534535
"spv.viewportindex.tese",
535536
"spv.volatileAtomic.comp",
536537
"spv.vulkan100.subgroupArithmetic.comp",

0 commit comments

Comments
 (0)