Skip to content

Commit 264e892

Browse files
mjn33arcady-lunarg
authored andcommitted
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 a0b70c2 commit 264e892

5 files changed

Lines changed: 80 additions & 0 deletions

File tree

SPIRV/GlslangToSpv.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3522,6 +3522,8 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
35223522
if (!glslangOperands[0]->getAsTyped()->getType().isLongVector() &&
35233523
glslangOperands[0]->getAsTyped()->getVectorSize() == 1)
35243524
binOp = glslang::EOpMul;
3525+
else if (isTypeFloat(node->getType().getBasicType()))
3526+
binOp = glslang::EOpDot;
35253527
break;
35263528
}
35273529
case glslang::EOpMod:
@@ -7864,6 +7866,13 @@ spv::Id TGlslangToSpvTraverser::createBinaryOperation(glslang::TOperator op, OpD
78647866
binOp = spv::Op::OpOuterProduct;
78657867
needMatchingVectors = false;
78667868
break;
7869+
case glslang::EOpDot:
7870+
if (typeProxy == glslang::EbtBFloat16) {
7871+
builder.addExtension(spv::E_SPV_KHR_bfloat16);
7872+
builder.addCapability(spv::Capability::BFloat16DotProductKHR);
7873+
}
7874+
binOp = spv::Op::OpDot;
7875+
break;
78677876

78687877
case glslang::EOpDiv:
78697878
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
@@ -565,6 +565,7 @@ INSTANTIATE_TEST_SUITE_P(
565565
"spv.subgroupSizeARB.frag",
566566
"spv.precise.tese",
567567
"spv.precise.tesc",
568+
"spv.precise.dot.vert",
568569
"spv.viewportindex.tese",
569570
"spv.volatileAtomic.comp",
570571
"spv.vulkan100.subgroupArithmetic.comp",

0 commit comments

Comments
 (0)