Skip to content

Commit

Permalink
Merge pull request KhronosGroup#2977 from AMD-dwang/AMD_shader_early_…
Browse files Browse the repository at this point in the history
…and_late_fragment_tests

Add SPV_AMD_shader_early_and_late_fragment_tests
  • Loading branch information
greg-lunarg authored Jul 27, 2022
2 parents 7b75c5d + 070863a commit 22d39cd
Show file tree
Hide file tree
Showing 14 changed files with 208 additions and 23 deletions.
1 change: 1 addition & 0 deletions SPIRV/GLSL.ext.KHR.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ static const char* const E_SPV_KHR_terminate_invocation = "SPV_KHR_termi
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";
static const char* const E_SPV_AMD_shader_early_and_late_fragment_tests = "SPV_AMD_shader_early_and_late_fragment_tests";

#endif // #ifndef GLSLextKHR_H
23 changes: 23 additions & 0 deletions SPIRV/GlslangToSpv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1623,6 +1623,12 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(unsigned int spvVersion,
if (glslangIntermediate->getEarlyFragmentTests())
builder.addExecutionMode(shaderEntry, spv::ExecutionModeEarlyFragmentTests);

if (glslangIntermediate->getEarlyAndLateFragmentTestsAMD())
{
builder.addExecutionMode(shaderEntry, spv::ExecutionModeEarlyAndLateFragmentTestsAMD);
builder.addExtension(spv::E_SPV_AMD_shader_early_and_late_fragment_tests);
}

if (glslangIntermediate->getPostDepthCoverage()) {
builder.addCapability(spv::CapabilitySampleMaskPostDepthCoverage);
builder.addExecutionMode(shaderEntry, spv::ExecutionModePostDepthCoverage);
Expand All @@ -1632,6 +1638,9 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(unsigned int spvVersion,
if (glslangIntermediate->isDepthReplacing())
builder.addExecutionMode(shaderEntry, spv::ExecutionModeDepthReplacing);

if (glslangIntermediate->isStencilReplacing())
builder.addExecutionMode(shaderEntry, spv::ExecutionModeStencilRefReplacingEXT);

#ifndef GLSLANG_WEB

switch(glslangIntermediate->getDepth()) {
Expand All @@ -1640,6 +1649,20 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(unsigned int spvVersion,
case glslang::EldUnchanged: mode = spv::ExecutionModeDepthUnchanged; break;
default: mode = spv::ExecutionModeMax; break;
}

if (mode != spv::ExecutionModeMax)
builder.addExecutionMode(shaderEntry, (spv::ExecutionMode)mode);

switch (glslangIntermediate->getStencil()) {
case glslang::ElsRefUnchangedFrontAMD: mode = spv::ExecutionModeStencilRefUnchangedFrontAMD; break;
case glslang::ElsRefGreaterFrontAMD: mode = spv::ExecutionModeStencilRefGreaterFrontAMD; break;
case glslang::ElsRefLessFrontAMD: mode = spv::ExecutionModeStencilRefLessFrontAMD; break;
case glslang::ElsRefUnchangedBackAMD: mode = spv::ExecutionModeStencilRefUnchangedBackAMD; break;
case glslang::ElsRefGreaterBackAMD: mode = spv::ExecutionModeStencilRefGreaterBackAMD; break;
case glslang::ElsRefLessBackAMD: mode = spv::ExecutionModeStencilRefLessBackAMD; break;
default: mode = spv::ExecutionModeMax; break;
}

if (mode != spv::ExecutionModeMax)
builder.addExecutionMode(shaderEntry, (spv::ExecutionMode)mode);
switch (glslangIntermediate->getInterlockOrdering()) {
Expand Down
44 changes: 24 additions & 20 deletions SPIRV/doc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,28 +173,32 @@ const char* ExecutionModeString(int mode)
case 31: return "ContractionOff";
case 32: return "Bad";

case ExecutionModeInitializer: return "Initializer";
case ExecutionModeFinalizer: return "Finalizer";
case ExecutionModeSubgroupSize: return "SubgroupSize";
case ExecutionModeSubgroupsPerWorkgroup: return "SubgroupsPerWorkgroup";
case ExecutionModeSubgroupsPerWorkgroupId: return "SubgroupsPerWorkgroupId";
case ExecutionModeLocalSizeId: return "LocalSizeId";
case ExecutionModeLocalSizeHintId: return "LocalSizeHintId";

case ExecutionModePostDepthCoverage: return "PostDepthCoverage";
case ExecutionModeDenormPreserve: return "DenormPreserve";
case ExecutionModeDenormFlushToZero: return "DenormFlushToZero";
case ExecutionModeSignedZeroInfNanPreserve: return "SignedZeroInfNanPreserve";
case ExecutionModeRoundingModeRTE: return "RoundingModeRTE";
case ExecutionModeRoundingModeRTZ: return "RoundingModeRTZ";
case ExecutionModeStencilRefReplacingEXT: return "StencilRefReplacingEXT";
case ExecutionModeInitializer: return "Initializer";
case ExecutionModeFinalizer: return "Finalizer";
case ExecutionModeSubgroupSize: return "SubgroupSize";
case ExecutionModeSubgroupsPerWorkgroup: return "SubgroupsPerWorkgroup";
case ExecutionModeSubgroupsPerWorkgroupId: return "SubgroupsPerWorkgroupId";
case ExecutionModeLocalSizeId: return "LocalSizeId";
case ExecutionModeLocalSizeHintId: return "LocalSizeHintId";

case ExecutionModePostDepthCoverage: return "PostDepthCoverage";
case ExecutionModeDenormPreserve: return "DenormPreserve";
case ExecutionModeDenormFlushToZero: return "DenormFlushToZero";
case ExecutionModeSignedZeroInfNanPreserve: return "SignedZeroInfNanPreserve";
case ExecutionModeRoundingModeRTE: return "RoundingModeRTE";
case ExecutionModeRoundingModeRTZ: return "RoundingModeRTZ";
case ExecutionModeEarlyAndLateFragmentTestsAMD: return "EarlyAndLateFragmentTestsAMD";
case ExecutionModeStencilRefUnchangedFrontAMD: return "StencilRefUnchangedFrontAMD";
case ExecutionModeStencilRefLessFrontAMD: return "StencilRefLessFrontAMD";
case ExecutionModeStencilRefGreaterBackAMD: return "StencilRefGreaterBackAMD";
case ExecutionModeStencilRefReplacingEXT: return "StencilRefReplacingEXT";
case ExecutionModeSubgroupUniformControlFlowKHR: return "SubgroupUniformControlFlow";

case ExecutionModeOutputLinesNV: return "OutputLinesNV";
case ExecutionModeOutputPrimitivesNV: return "OutputPrimitivesNV";
case ExecutionModeOutputTrianglesNV: return "OutputTrianglesNV";
case ExecutionModeDerivativeGroupQuadsNV: return "DerivativeGroupQuadsNV";
case ExecutionModeDerivativeGroupLinearNV: return "DerivativeGroupLinearNV";
case ExecutionModeOutputLinesNV: return "OutputLinesNV";
case ExecutionModeOutputPrimitivesNV: return "OutputPrimitivesNV";
case ExecutionModeOutputTrianglesNV: return "OutputTrianglesNV";
case ExecutionModeDerivativeGroupQuadsNV: return "DerivativeGroupQuadsNV";
case ExecutionModeDerivativeGroupLinearNV: return "DerivativeGroupLinearNV";

case ExecutionModePixelInterlockOrderedEXT: return "PixelInterlockOrderedEXT";
case ExecutionModePixelInterlockUnorderedEXT: return "PixelInterlockUnorderedEXT";
Expand Down
7 changes: 7 additions & 0 deletions SPIRV/spirv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,14 @@ enum ExecutionMode {
ExecutionModeSignedZeroInfNanPreserve = 4461,
ExecutionModeRoundingModeRTE = 4462,
ExecutionModeRoundingModeRTZ = 4463,
ExecutionModeEarlyAndLateFragmentTestsAMD = 5017,
ExecutionModeStencilRefReplacingEXT = 5027,
ExecutionModeStencilRefUnchangedFrontAMD = 5079,
ExecutionModeStencilRefGreaterFrontAMD = 5080,
ExecutionModeStencilRefLessFrontAMD = 5081,
ExecutionModeStencilRefUnchangedBackAMD = 5082,
ExecutionModeStencilRefGreaterBackAMD = 5083,
ExecutionModeStencilRefLessBackAMD = 5084,
ExecutionModeOutputLinesNV = 5269,
ExecutionModeOutputPrimitivesNV = 5270,
ExecutionModeDerivativeGroupQuadsNV = 5289,
Expand Down
41 changes: 41 additions & 0 deletions Test/baseResults/spv.earlyAndlateFragmentTests.frag.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
spv.earlyAndlateFragmentTests.frag
// Module Version 10000
// Generated by (magic number): 8000a
// Id's are bound by 16

Capability Shader
Extension "SPV_AMD_shader_early_and_late_fragment_tests"
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 8 11
ExecutionMode 4 OriginUpperLeft
ExecutionMode 4 EarlyAndLateFragmentTestsAMD
ExecutionMode 4 DepthReplacing
ExecutionMode 4 DepthLess
Source GLSL 450
SourceExtension "GL_ARB_fragment_shader_interlock"
SourceExtension "GL_ARB_shader_stencil_export"
SourceExtension "GL_EXT_fragment_shading_rate"
Name 4 "main"
Name 8 "gl_FragDepth"
Name 11 "instanceIndex"
Decorate 8(gl_FragDepth) BuiltIn FragDepth
Decorate 11(instanceIndex) Flat
Decorate 11(instanceIndex) Location 0
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypePointer Output 6(float)
8(gl_FragDepth): 7(ptr) Variable Output
9: TypeInt 32 1
10: TypePointer Input 9(int)
11(instanceIndex): 10(ptr) Variable Input
14: 6(float) Constant 1117913088
4(main): 2 Function None 3
5: Label
12: 9(int) Load 11(instanceIndex)
13: 6(float) ConvertSToF 12
15: 6(float) FDiv 13 14
Store 8(gl_FragDepth) 15
Return
FunctionEnd
1 change: 1 addition & 0 deletions Test/baseResults/spv.shaderStencilExport.frag.out
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ spv.shaderStencilExport.frag
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 8
ExecutionMode 4 OriginUpperLeft
ExecutionMode 4 StencilRefReplacingEXT
Source GLSL 450
SourceExtension "GL_ARB_shader_stencil_export"
Name 4 "main"
Expand Down
12 changes: 12 additions & 0 deletions Test/spv.earlyAndlateFragmentTests.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#version 450 core
#extension GL_EXT_fragment_shading_rate : enable
#extension GL_ARB_shader_stencil_export : enable
#extension GL_ARB_fragment_shader_interlock : enable
#extension GL_AMD_shader_early_and_late_fragment_tests : enable
layout(location = 0) flat in int instanceIndex;
layout(early_and_late_fragment_tests_amd) in;
layout(depth_less) out float gl_FragDepth;
void main()
{
gl_FragDepth = float(instanceIndex) / float(81);
}
2 changes: 2 additions & 0 deletions glslang/Include/BaseTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ enum TStorageQualifier {
// built-ins written by fragment shader
EvqFragColor,
EvqFragDepth,
EvqFragStencil,

// end of list
EvqLast
Expand Down Expand Up @@ -353,6 +354,7 @@ __inline const char* GetStorageQualifierString(TStorageQualifier q)
case EvqPointCoord: return "gl_PointCoord"; break;
case EvqFragColor: return "fragColor"; break;
case EvqFragDepth: return "gl_FragDepth"; break;
case EvqFragStencil: return "gl_FragStencilRefARB"; break;
case EvqPayload: return "rayPayloadNV"; break;
case EvqPayloadIn: return "rayPayloadInNV"; break;
case EvqHitAttr: return "hitAttributeNV"; break;
Expand Down
35 changes: 35 additions & 0 deletions glslang/Include/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,18 @@ enum TLayoutDepth {
EldCount
};

enum TLayoutStencil {
ElsNone,
ElsRefUnchangedFrontAMD,
ElsRefGreaterFrontAMD,
ElsRefLessFrontAMD,
ElsRefUnchangedBackAMD,
ElsRefGreaterBackAMD,
ElsRefLessBackAMD,

ElsCount
};

enum TBlendEquationShift {
// No 'EBlendNone':
// These are used as bit-shift amounts. A mask of such shifts will have type 'int',
Expand Down Expand Up @@ -705,6 +717,7 @@ class TQualifier {
case EvqVaryingOut:
case EvqFragColor:
case EvqFragDepth:
case EvqFragStencil:
return true;
default:
return false;
Expand Down Expand Up @@ -772,6 +785,7 @@ class TQualifier {
case EvqVaryingOut:
case EvqFragColor:
case EvqFragDepth:
case EvqFragStencil:
return true;
default:
return false;
Expand Down Expand Up @@ -1239,6 +1253,18 @@ class TQualifier {
default: return "none";
}
}
static const char* getLayoutStencilString(TLayoutStencil s)
{
switch (s) {
case ElsRefUnchangedFrontAMD: return "stencil_ref_unchanged_front_amd";
case ElsRefGreaterFrontAMD: return "stencil_ref_greater_front_amd";
case ElsRefLessFrontAMD: return "stencil_ref_less_front_amd";
case ElsRefUnchangedBackAMD: return "stencil_ref_unchanged_back_amd";
case ElsRefGreaterBackAMD: return "stencil_ref_greater_back_amd";
case ElsRefLessBackAMD: return "stencil_ref_less_back_amd";
default: return "none";
}
}
static const char* getBlendEquationString(TBlendEquationShift e)
{
switch (e) {
Expand Down Expand Up @@ -1336,7 +1362,9 @@ struct TShaderQualifiers {
#ifndef GLSLANG_WEB
bool earlyFragmentTests; // fragment input
bool postDepthCoverage; // fragment input
bool earlyAndLateFragmentTestsAMD; //fragment input
TLayoutDepth layoutDepth;
TLayoutStencil layoutStencil;
bool blendEquation; // true if any blend equation was specified
int numViews; // multiview extenstions
TInterlockOrdering interlockOrdering;
Expand All @@ -1346,6 +1374,7 @@ struct TShaderQualifiers {
int primitives; // mesh shader "max_primitives"DerivativeGroupLinear; // true if layout derivative_group_linearNV set
bool layoutPrimitiveCulling; // true if layout primitive_culling set
TLayoutDepth getDepth() const { return layoutDepth; }
TLayoutStencil getStencil() const { return layoutStencil; }
#else
TLayoutDepth getDepth() const { return EldNone; }
#endif
Expand All @@ -1371,8 +1400,10 @@ struct TShaderQualifiers {
localSizeSpecId[2] = TQualifier::layoutNotSet;
#ifndef GLSLANG_WEB
earlyFragmentTests = false;
earlyAndLateFragmentTestsAMD = false;
postDepthCoverage = false;
layoutDepth = EldNone;
layoutStencil = ElsNone;
blendEquation = false;
numViews = TQualifier::layoutNotSet;
layoutOverrideCoverage = false;
Expand Down Expand Up @@ -1424,10 +1455,14 @@ struct TShaderQualifiers {
#ifndef GLSLANG_WEB
if (src.earlyFragmentTests)
earlyFragmentTests = true;
if (src.earlyAndLateFragmentTestsAMD)
earlyAndLateFragmentTestsAMD = true;
if (src.postDepthCoverage)
postDepthCoverage = true;
if (src.layoutDepth)
layoutDepth = src.layoutDepth;
if (src.layoutStencil)
layoutStencil = src.layoutStencil;
if (src.blendEquation)
blendEquation = src.blendEquation;
if (src.numViews != TQualifier::layoutNotSet)
Expand Down
1 change: 1 addition & 0 deletions glslang/MachineIndependent/Initialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8065,6 +8065,7 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
SpecialQualifier("gl_FragDepth", EvqFragDepth, EbvFragDepth, symbolTable);
#ifndef GLSLANG_WEB
SpecialQualifier("gl_FragDepthEXT", EvqFragDepth, EbvFragDepth, symbolTable);
SpecialQualifier("gl_FragStencilRefARB", EvqFragStencil, EbvFragStencilRef, symbolTable);
SpecialQualifier("gl_HelperInvocation", EvqVaryingIn, EbvHelperInvocation, symbolTable);

BuiltInVariable("gl_ClipDistance", EbvClipDistance, symbolTable);
Expand Down
Loading

0 comments on commit 22d39cd

Please sign in to comment.