Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for VK_EXT_fragment_shader_barycentric #2952

Merged
Merged
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
3 changes: 2 additions & 1 deletion SPIRV/GLSL.ext.KHR.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#define GLSLextKHR_H

static const int GLSLextKHRVersion = 100;
static const int GLSLextKHRRevision = 2;
static const int GLSLextKHRRevision = 3;

static const char* const E_SPV_KHR_shader_ballot = "SPV_KHR_shader_ballot";
static const char* const E_SPV_KHR_subgroup_vote = "SPV_KHR_subgroup_vote";
Expand All @@ -52,5 +52,6 @@ static const char* const E_SPV_KHR_fragment_shading_rate = "SPV_KHR_fragm
static const char* const E_SPV_KHR_terminate_invocation = "SPV_KHR_terminate_invocation";
static const char* const E_SPV_KHR_workgroup_memory_explicit_layout = "SPV_KHR_workgroup_memory_explicit_layout";
static const char* const E_SPV_KHR_subgroup_uniform_control_flow = "SPV_KHR_subgroup_uniform_control_flow";
static const char* const E_SPV_KHR_fragment_shader_barycentric = "SPV_KHR_fragment_shader_barycentric";

#endif // #ifndef GLSLextKHR_H
15 changes: 15 additions & 0 deletions SPIRV/GlslangToSpv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,15 @@ spv::BuiltIn TGlslangToSpvTraverser::TranslateBuiltInDecoration(glslang::TBuiltI
builder.addCapability(spv::CapabilityFragmentBarycentricNV);
return spv::BuiltInBaryCoordNoPerspNV;

case glslang::EbvBaryCoordEXT:
builder.addExtension(spv::E_SPV_KHR_fragment_shader_barycentric);
builder.addCapability(spv::CapabilityFragmentBarycentricKHR);
return spv::BuiltInBaryCoordKHR;
case glslang::EbvBaryCoordNoPerspEXT:
builder.addExtension(spv::E_SPV_KHR_fragment_shader_barycentric);
builder.addCapability(spv::CapabilityFragmentBarycentricKHR);
return spv::BuiltInBaryCoordNoPerspKHR;

// mesh shaders
case glslang::EbvTaskCountNV:
return spv::BuiltInTaskCountNV;
Expand Down Expand Up @@ -8866,6 +8875,12 @@ spv::Id TGlslangToSpvTraverser::getSymbolId(const glslang::TIntermSymbol* symbol
builder.addExtension(spv::E_SPV_NV_fragment_shader_barycentric);
}

if (symbol->getQualifier().pervertexEXT) {
builder.addDecoration(id, spv::DecorationPerVertexKHR);
builder.addCapability(spv::CapabilityFragmentBarycentricKHR);
builder.addExtension(spv::E_SPV_KHR_fragment_shader_barycentric);
}

if (glslangIntermediate->getHlslFunctionality1() && symbol->getType().getQualifier().semanticName != nullptr) {
builder.addExtension("SPV_GOOGLE_hlsl_functionality1");
builder.addDecoration(id, (spv::Decoration)spv::DecorationHlslSemanticGOOGLE,
Expand Down
9 changes: 5 additions & 4 deletions SPIRV/doc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ const char* DecorationString(int decoration)
case DecorationPerPrimitiveNV: return "PerPrimitiveNV";
case DecorationPerViewNV: return "PerViewNV";
case DecorationPerTaskNV: return "PerTaskNV";
case DecorationPerVertexNV: return "PerVertexNV";

case DecorationPerVertexKHR: return "PerVertexKHR";

case DecorationNonUniformEXT: return "DecorationNonUniformEXT";
case DecorationHlslCounterBufferGOOGLE: return "DecorationHlslCounterBufferGOOGLE";
Expand Down Expand Up @@ -407,8 +408,8 @@ const char* BuiltInString(int builtIn)
case BuiltInViewportMaskPerViewNV: return "ViewportMaskPerViewNV";
// case BuiltInFragmentSizeNV: return "FragmentSizeNV"; // superseded by BuiltInFragSizeEXT
// case BuiltInInvocationsPerPixelNV: return "InvocationsPerPixelNV"; // superseded by BuiltInFragInvocationCountEXT
case BuiltInBaryCoordNV: return "BaryCoordNV";
case BuiltInBaryCoordNoPerspNV: return "BaryCoordNoPerspNV";
case BuiltInBaryCoordKHR: return "BaryCoordKHR";
case BuiltInBaryCoordNoPerspKHR: return "BaryCoordNoPerspKHR";

case BuiltInFragSizeEXT: return "FragSizeEXT";
case BuiltInFragInvocationCountEXT: return "FragInvocationCountEXT";
Expand Down Expand Up @@ -932,7 +933,7 @@ const char* CapabilityString(int info)
case CapabilityRayTraversalPrimitiveCullingKHR: return "RayTraversalPrimitiveCullingKHR";
case CapabilityComputeDerivativeGroupQuadsNV: return "ComputeDerivativeGroupQuadsNV";
case CapabilityComputeDerivativeGroupLinearNV: return "ComputeDerivativeGroupLinearNV";
case CapabilityFragmentBarycentricNV: return "FragmentBarycentricNV";
case CapabilityFragmentBarycentricKHR: return "FragmentBarycentricKHR";
case CapabilityMeshShadingNV: return "MeshShadingNV";
case CapabilityImageFootprintNV: return "ImageFootprintNV";
// case CapabilityShadingRateNV: return "ShadingRateNV"; // superseded by FragmentDensityEXT
Expand Down
6 changes: 3 additions & 3 deletions Test/baseResults/spv.fragmentShaderBarycentric.frag.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ spv.fragmentShaderBarycentric.frag
// Id's are bound by 43

Capability Shader
Capability FragmentBarycentricNV
Capability FragmentBarycentricKHR
Extension "SPV_NV_fragment_shader_barycentric"
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
Expand All @@ -19,10 +19,10 @@ spv.fragmentShaderBarycentric.frag
MemberName 17(vertices) 0 "attrib"
Name 21 "v"
Decorate 8(value) Location 1
Decorate 11(gl_BaryCoordNV) BuiltIn BaryCoordNV
Decorate 11(gl_BaryCoordNV) BuiltIn BaryCoordKHR
Decorate 17(vertices) Block
Decorate 21(v) Location 0
Decorate 21(v) PerVertexNV
Decorate 21(v) PerVertexKHR
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
Expand Down
6 changes: 3 additions & 3 deletions Test/baseResults/spv.fragmentShaderBarycentric2.frag.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ spv.fragmentShaderBarycentric2.frag
// Id's are bound by 42

Capability Shader
Capability FragmentBarycentricNV
Capability FragmentBarycentricKHR
Extension "SPV_NV_fragment_shader_barycentric"
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
Expand All @@ -17,9 +17,9 @@ spv.fragmentShaderBarycentric2.frag
Name 11 "gl_BaryCoordNoPerspNV"
Name 20 "vertexIDs"
Decorate 8(value) Location 1
Decorate 11(gl_BaryCoordNoPerspNV) BuiltIn BaryCoordNoPerspNV
Decorate 11(gl_BaryCoordNoPerspNV) BuiltIn BaryCoordNoPerspKHR
Decorate 20(vertexIDs) Location 0
Decorate 20(vertexIDs) PerVertexNV
Decorate 20(vertexIDs) PerVertexKHR
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
Expand Down
69 changes: 69 additions & 0 deletions Test/baseResults/spv.fragmentShaderBarycentric3.frag.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
spv.fragmentShaderBarycentric3.frag
// Module Version 10000
// Generated by (magic number): 8000a
// Id's are bound by 43

Capability Shader
Capability FragmentBarycentricKHR
Extension "SPV_KHR_fragment_shader_barycentric"
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 8 11 21
ExecutionMode 4 OriginUpperLeft
Source GLSL 450
SourceExtension "GL_EXT_fragment_shader_barycentric"
Name 4 "main"
Name 8 "value"
Name 11 "gl_BaryCoordEXT"
Name 17 "vertices"
MemberName 17(vertices) 0 "attrib"
Name 21 "v"
Decorate 8(value) Location 1
Decorate 11(gl_BaryCoordEXT) BuiltIn BaryCoordKHR
Decorate 17(vertices) Block
Decorate 21(v) Location 0
Decorate 21(v) PerVertexKHR
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypePointer Output 6(float)
8(value): 7(ptr) Variable Output
9: TypeVector 6(float) 3
10: TypePointer Input 9(fvec3)
11(gl_BaryCoordEXT): 10(ptr) Variable Input
12: TypeInt 32 0
13: 12(int) Constant 0
14: TypePointer Input 6(float)
17(vertices): TypeStruct 6(float)
18: 12(int) Constant 3
19: TypeArray 17(vertices) 18
20: TypePointer Input 19
21(v): 20(ptr) Variable Input
22: TypeInt 32 1
23: 22(int) Constant 0
27: 12(int) Constant 1
30: 22(int) Constant 1
35: 12(int) Constant 2
38: 22(int) Constant 2
4(main): 2 Function None 3
5: Label
15: 14(ptr) AccessChain 11(gl_BaryCoordEXT) 13
16: 6(float) Load 15
24: 14(ptr) AccessChain 21(v) 23 23
25: 6(float) Load 24
26: 6(float) FMul 16 25
28: 14(ptr) AccessChain 11(gl_BaryCoordEXT) 27
29: 6(float) Load 28
31: 14(ptr) AccessChain 21(v) 30 23
32: 6(float) Load 31
33: 6(float) FMul 29 32
34: 6(float) FAdd 26 33
36: 14(ptr) AccessChain 11(gl_BaryCoordEXT) 35
37: 6(float) Load 36
39: 14(ptr) AccessChain 21(v) 38 23
40: 6(float) Load 39
41: 6(float) FMul 37 40
42: 6(float) FAdd 34 41
Store 8(value) 42
Return
FunctionEnd
65 changes: 65 additions & 0 deletions Test/baseResults/spv.fragmentShaderBarycentric4.frag.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
spv.fragmentShaderBarycentric4.frag
// Module Version 10000
// Generated by (magic number): 8000a
// Id's are bound by 42

Capability Shader
Capability FragmentBarycentricKHR
Extension "SPV_KHR_fragment_shader_barycentric"
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 8 11 20
ExecutionMode 4 OriginUpperLeft
Source ESSL 320
SourceExtension "GL_EXT_fragment_shader_barycentric"
Name 4 "main"
Name 8 "value"
Name 11 "gl_BaryCoordNoPerspEXT"
Name 20 "vertexIDs"
Decorate 8(value) Location 1
Decorate 11(gl_BaryCoordNoPerspEXT) BuiltIn BaryCoordNoPerspKHR
Decorate 20(vertexIDs) Location 0
Decorate 20(vertexIDs) PerVertexKHR
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypePointer Output 6(float)
8(value): 7(ptr) Variable Output
9: TypeVector 6(float) 3
10: TypePointer Input 9(fvec3)
11(gl_BaryCoordNoPerspEXT): 10(ptr) Variable Input
12: TypeInt 32 0
13: 12(int) Constant 0
14: TypePointer Input 6(float)
17: 12(int) Constant 3
18: TypeArray 6(float) 17
19: TypePointer Input 18
20(vertexIDs): 19(ptr) Variable Input
21: TypeInt 32 1
22: 21(int) Constant 0
26: 12(int) Constant 1
29: 21(int) Constant 1
34: 12(int) Constant 2
37: 21(int) Constant 2
4(main): 2 Function None 3
5: Label
15: 14(ptr) AccessChain 11(gl_BaryCoordNoPerspEXT) 13
16: 6(float) Load 15
23: 14(ptr) AccessChain 20(vertexIDs) 22
24: 6(float) Load 23
25: 6(float) FMul 16 24
27: 14(ptr) AccessChain 11(gl_BaryCoordNoPerspEXT) 26
28: 6(float) Load 27
30: 14(ptr) AccessChain 20(vertexIDs) 29
31: 6(float) Load 30
32: 6(float) FMul 28 31
33: 6(float) FAdd 25 32
35: 14(ptr) AccessChain 11(gl_BaryCoordNoPerspEXT) 34
36: 6(float) Load 35
38: 14(ptr) AccessChain 20(vertexIDs) 37
39: 6(float) Load 38
40: 6(float) FMul 36 39
41: 6(float) FAdd 33 40
Store 8(value) 41
Return
FunctionEnd
15 changes: 15 additions & 0 deletions Test/spv.fragmentShaderBarycentric3.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 450
#extension GL_EXT_fragment_shader_barycentric : require

layout(location = 0) pervertexEXT in vertices {
float attrib;
} v[];

layout(location = 1) out float value;

void main () {
value = (gl_BaryCoordEXT.x * v[0].attrib +
gl_BaryCoordEXT.y * v[1].attrib +
gl_BaryCoordEXT.z * v[2].attrib);

}
15 changes: 15 additions & 0 deletions Test/spv.fragmentShaderBarycentric4.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 320 es
#extension GL_EXT_fragment_shader_barycentric : require

precision highp float;

layout(location = 0) pervertexEXT in float vertexIDs[3];

layout(location = 1) out float value;

void main () {
value = (gl_BaryCoordNoPerspEXT.x * vertexIDs[0] +
gl_BaryCoordNoPerspEXT.y * vertexIDs[1] +
gl_BaryCoordNoPerspEXT.z * vertexIDs[2]);

}
8 changes: 6 additions & 2 deletions glslang/Include/BaseTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ enum TBuiltInVariable {
// barycentrics
EbvBaryCoordNV,
EbvBaryCoordNoPerspNV,
EbvBaryCoordEXT,
EbvBaryCoordNoPerspEXT,
// mesh shaders
EbvTaskCountNV,
EbvPrimitiveCountNV,
Expand Down Expand Up @@ -479,8 +481,10 @@ __inline const char* GetBuiltInVariableString(TBuiltInVariable v)
case EbvWorldToObject: return "WorldToObjectNV";
case EbvCurrentRayTimeNV: return "CurrentRayTimeNV";

case EbvBaryCoordNV: return "BaryCoordNV";
case EbvBaryCoordNoPerspNV: return "BaryCoordNoPerspNV";
case EbvBaryCoordEXT:
case EbvBaryCoordNV: return "BaryCoordKHR";
case EbvBaryCoordNoPerspEXT:
case EbvBaryCoordNoPerspNV: return "BaryCoordNoPerspKHR";

case EbvTaskCountNV: return "TaskCountNV";
case EbvPrimitiveCountNV: return "PrimitiveCountNV";
Expand Down
12 changes: 9 additions & 3 deletions glslang/Include/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ class TQualifier {
perViewNV = false;
perTaskNV = false;
#endif
pervertexEXT = false;
}

void clearMemory()
Expand Down Expand Up @@ -604,7 +605,8 @@ class TQualifier {
bool isNoContraction() const { return false; }
void setNoContraction() { }
bool isPervertexNV() const { return false; }
void setNullInit() { }
bool isPervertexEXT() const { return pervertexEXT; }
void setNullInit() {}
bool isNullInit() const { return false; }
void setSpirvByReference() { }
bool isSpirvByReference() { return false; }
Expand All @@ -615,6 +617,7 @@ class TQualifier {
bool nopersp : 1;
bool explicitInterp : 1;
bool pervertexNV : 1;
bool pervertexEXT : 1;
bool perPrimitiveNV : 1;
bool perViewNV : 1;
bool perTaskNV : 1;
Expand Down Expand Up @@ -663,12 +666,13 @@ class TQualifier {
}
bool isAuxiliary() const
{
return centroid || patch || sample || pervertexNV;
return centroid || patch || sample || pervertexNV || pervertexEXT;
}
bool isPatch() const { return patch; }
bool isNoContraction() const { return noContraction; }
void setNoContraction() { noContraction = true; }
bool isPervertexNV() const { return pervertexNV; }
bool isPervertexEXT() const { return pervertexEXT; }
void setNullInit() { nullInit = true; }
bool isNullInit() const { return nullInit; }
void setSpirvByReference() { spirvByReference = true; }
Expand Down Expand Up @@ -856,7 +860,7 @@ class TQualifier {
case EShLangTessEvaluation:
return ! patch && isPipeInput();
case EShLangFragment:
return pervertexNV && isPipeInput();
return (pervertexNV || pervertexEXT) && isPipeInput();
case EShLangMeshNV:
return ! perTaskNV && isPipeOutput();

Expand Down Expand Up @@ -2266,6 +2270,8 @@ class TType {
appendStr(" __explicitInterpAMD");
if (qualifier.pervertexNV)
appendStr(" pervertexNV");
if (qualifier.pervertexEXT)
appendStr(" pervertexEXT");
if (qualifier.perPrimitiveNV)
appendStr(" perprimitiveNV");
if (qualifier.perViewNV)
Expand Down
10 changes: 9 additions & 1 deletion glslang/MachineIndependent/Initialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5571,6 +5571,8 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
"flat in int gl_InvocationsPerPixelNV;"
"in vec3 gl_BaryCoordNV;" // GL_NV_fragment_shader_barycentric
"in vec3 gl_BaryCoordNoPerspNV;"
"in vec3 gl_BaryCoordEXT;" // GL_EXT_fragment_shader_barycentric
"in vec3 gl_BaryCoordNoPerspEXT;"
);

if (version >= 450)
Expand Down Expand Up @@ -5635,7 +5637,9 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
stageBuiltins[EShLangFragment].append(
"in vec3 gl_BaryCoordNV;"
"in vec3 gl_BaryCoordNoPerspNV;"
);
"in vec3 gl_BaryCoordEXT;"
"in vec3 gl_BaryCoordNoPerspEXT;"
);
if (version >= 310)
stageBuiltins[EShLangFragment].append(
"flat in highp int gl_ShadingRateEXT;" // GL_EXT_fragment_shading_rate
Expand Down Expand Up @@ -8321,6 +8325,10 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
symbolTable.setVariableExtensions("gl_BaryCoordNoPerspNV", 1, &E_GL_NV_fragment_shader_barycentric);
BuiltInVariable("gl_BaryCoordNV", EbvBaryCoordNV, symbolTable);
BuiltInVariable("gl_BaryCoordNoPerspNV", EbvBaryCoordNoPerspNV, symbolTable);
symbolTable.setVariableExtensions("gl_BaryCoordEXT", 1, &E_GL_EXT_fragment_shader_barycentric);
symbolTable.setVariableExtensions("gl_BaryCoordNoPerspEXT", 1, &E_GL_EXT_fragment_shader_barycentric);
BuiltInVariable("gl_BaryCoordEXT", EbvBaryCoordEXT, symbolTable);
BuiltInVariable("gl_BaryCoordNoPerspEXT", EbvBaryCoordNoPerspEXT, symbolTable);
}

if ((profile != EEsProfile && version >= 450) ||
Expand Down
Loading