Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions SPIRV/GlslangToSpv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3282,6 +3282,8 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
glslang::TIntermSequence& glslangOperands = node->getSequence();
if (glslangOperands[0]->getAsTyped()->getVectorSize() == 1)
binOp = glslang::EOpMul;
else if (isTypeFloat(node->getType().getBasicType()))
binOp = glslang::EOpDot;
break;
}
case glslang::EOpMod:
Expand Down Expand Up @@ -7144,6 +7146,13 @@ spv::Id TGlslangToSpvTraverser::createBinaryOperation(glslang::TOperator op, OpD
binOp = spv::OpOuterProduct;
needMatchingVectors = false;
break;
case glslang::EOpDot:
if (typeProxy == glslang::EbtBFloat16) {
builder.addExtension(spv::E_SPV_KHR_bfloat16);
builder.addCapability(spv::CapabilityBFloat16DotProductKHR);
}
binOp = spv::OpDot;
break;

case glslang::EOpDiv:
case glslang::EOpDivAssign:
Expand Down Expand Up @@ -9152,10 +9161,6 @@ spv::Id TGlslangToSpvTraverser::createMiscOperation(glslang::TOperator op, spv::
if (builder.isFloatType(builder.getScalarTypeId(typeId0)) ||
// HLSL supports dot(int,int) which is just a multiply
glslangIntermediate->getSource() == glslang::EShSourceHlsl) {
if (typeProxy == glslang::EbtBFloat16) {
builder.addExtension(spv::E_SPV_KHR_bfloat16);
builder.addCapability(spv::CapabilityBFloat16DotProductKHR);
}
opCode = spv::OpDot;
} else {
builder.addExtension(spv::E_SPV_KHR_integer_dot_product);
Expand Down
51 changes: 51 additions & 0 deletions Test/baseResults/spv.precise.dot.vert.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
spv.precise.dot.vert
// Module Version 10000
// Generated by (magic number): 8000b
// Id's are bound by 28

Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Vertex 4 "main" 21
Source GLSL 450
Name 4 "main"
Name 9 "v"
Name 11 "u"
Name 15 "f"
Name 19 "gl_PerVertex"
MemberName 19(gl_PerVertex) 0 "gl_Position"
Name 21 ""
Decorate 18 NoContraction
Decorate 19(gl_PerVertex) Block
MemberDecorate 19(gl_PerVertex) 0 BuiltIn Position
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypePointer Function 7(fvec4)
10: TypePointer Private 6(float)
11(u): 10(ptr) Variable Private
14: TypePointer Function 6(float)
19(gl_PerVertex): TypeStruct 7(fvec4)
20: TypePointer Output 19(gl_PerVertex)
21: 20(ptr) Variable Output
22: TypeInt 32 1
23: 22(int) Constant 0
26: TypePointer Output 7(fvec4)
4(main): 2 Function None 3
5: Label
9(v): 8(ptr) Variable Function
15(f): 14(ptr) Variable Function
12: 6(float) Load 11(u)
13: 7(fvec4) CompositeConstruct 12 12 12 12
Store 9(v) 13
16: 7(fvec4) Load 9(v)
17: 7(fvec4) Load 9(v)
18: 6(float) Dot 16 17
Store 15(f) 18
24: 6(float) Load 15(f)
25: 7(fvec4) CompositeConstruct 24 24 24 24
27: 26(ptr) AccessChain 21 23
Store 27 25
Return
FunctionEnd
15 changes: 15 additions & 0 deletions Test/spv.precise.dot.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 450 core

out gl_PerVertex
{
precise vec4 gl_Position;
};

float u;

void main()
{
vec4 v = vec4(u);
float f = dot(v, v);
gl_Position = vec4(f);
}
4 changes: 4 additions & 0 deletions glslang/MachineIndependent/propagateNoContraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,10 @@ class TNoContractionPropagator : public glslang::TIntermTraverser {
}
return false;
}
// If this is an arithmetic operation, marks this node as 'noContraction'.
if (isArithmeticOperation(node->getOp())) {
node->getWritableType().getQualifier().noContraction = true;
}
return true;
}

Expand Down
1 change: 1 addition & 0 deletions gtests/Spv.FromFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ INSTANTIATE_TEST_SUITE_P(
"spv.subgroupSizeARB.frag",
"spv.precise.tese",
"spv.precise.tesc",
"spv.precise.dot.vert",
"spv.viewportindex.tese",
"spv.volatileAtomic.comp",
"spv.vulkan100.subgroupArithmetic.comp",
Expand Down
Loading