Skip to content

Commit

Permalink
Add support for primitive culling layout qualifier. (#2220)
Browse files Browse the repository at this point in the history
* Add support for primitive culling layout qualifier.

* Add error checks for primitive flags and negative test.
  • Loading branch information
alelenv authored May 21, 2020
1 parent eba1389 commit 59216d5
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion SPIRV/GlslangToSpv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,7 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(unsigned int spvVersion,
builder.addExecutionMode(shaderEntry, spv::ExecutionModeXfb);
}

if (sourceExtensions.find("GL_EXT_ray_flags_primitive_culling") != sourceExtensions.end()) {
if (glslangIntermediate->getLayoutPrimitiveCulling()) {
builder.addCapability(spv::CapabilityRayTraversalPrimitiveCullingProvisionalKHR);
}

Expand Down
9 changes: 9 additions & 0 deletions Test/baseResults/spv.ext.RayPrimCull_Errors.rgen.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spv.ext.RayPrimCull_Errors.rgen
ERROR: 0:3: 'primitive culling' : required extension not requested: GL_EXT_ray_flags_primitive_culling
ERROR: 0:5: 'primitive_culling' : layout qualifier can not have storage qualifiers
ERROR: 0:6: 'primitive_culling' : can only be applied as standalone
ERROR: 0:7: 'primitive_culling' : can only be applied as standalone
ERROR: 4 compilation errors. No code generated.


SPIR-V is not generated for failed compile or link
1 change: 1 addition & 0 deletions Test/rayQuery-allOps.comp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#extension GL_EXT_ray_query : enable
#extension GL_EXT_ray_flags_primitive_culling : enable

layout(primitive_culling);
struct Ray
{
vec3 pos;
Expand Down
1 change: 1 addition & 0 deletions Test/spv.ext.RayGenShader.rgen
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ layout(shaderRecordEXT) buffer block
vec3 origin;

};
layout(primitive_culling);
void main()
{
uint lx = gl_LaunchIDEXT.x;
Expand Down
10 changes: 10 additions & 0 deletions Test/spv.ext.RayPrimCull_Errors.rgen
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#version 460
#extension GL_EXT_ray_tracing : enable
layout(primitive_culling);
#extension GL_EXT_ray_flags_primitive_culling : enable
layout(primitive_culling) uniform;
layout(primitive_culling, binding = 2) uniform accelerationStructureEXT as;
layout(std140, binding = 2, primitive_culling) buffer block { int x; };
void main()
{
}
4 changes: 4 additions & 0 deletions glslang/Include/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,7 @@ struct TShaderQualifiers {
bool layoutDerivativeGroupQuads; // true if layout derivative_group_quadsNV set
bool layoutDerivativeGroupLinear; // true if layout derivative_group_linearNV set
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; }
#else
TLayoutDepth getDepth() const { return EldNone; }
Expand Down Expand Up @@ -1268,6 +1269,7 @@ struct TShaderQualifiers {
layoutOverrideCoverage = false;
layoutDerivativeGroupQuads = false;
layoutDerivativeGroupLinear = false;
layoutPrimitiveCulling = false;
primitives = TQualifier::layoutNotSet;
interlockOrdering = EioNone;
#endif
Expand Down Expand Up @@ -1331,6 +1333,8 @@ struct TShaderQualifiers {
primitives = src.primitives;
if (src.interlockOrdering != EioNone)
interlockOrdering = src.interlockOrdering;
if (src.layoutPrimitiveCulling)
layoutPrimitiveCulling = src.layoutPrimitiveCulling;
#endif
}
};
Expand Down
18 changes: 18 additions & 0 deletions glslang/MachineIndependent/ParseHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5173,6 +5173,12 @@ void TParseContext::setLayoutQualifier(const TSourceLoc& loc, TPublicType& publi
}
}
}

if (id == "primitive_culling") {
requireExtensions(loc, 1, &E_GL_EXT_ray_flags_primitive_culling, "primitive culling");
publicType.shaderQualifiers.layoutPrimitiveCulling = true;
return;
}
#endif

error(loc, "unrecognized layout identifier, or qualifier requires assignment (e.g., binding = 4)", id.c_str(), "");
Expand Down Expand Up @@ -6104,6 +6110,8 @@ void TParseContext::checkNoShaderLayouts(const TSourceLoc& loc, const TShaderQua
error(loc, message, "num_views", "");
if (shaderQualifiers.interlockOrdering != EioNone)
error(loc, message, TQualifier::getInterlockOrderingString(shaderQualifiers.interlockOrdering), "");
if (shaderQualifiers.layoutPrimitiveCulling)
error(loc, "can only be applied as standalone", "primitive_culling", "");
#endif
}

Expand Down Expand Up @@ -8368,6 +8376,16 @@ void TParseContext::updateStandaloneQualifierDefaults(const TSourceLoc& loc, con
{
checkIoArraysConsistency(loc);
}

if (publicType.shaderQualifiers.layoutPrimitiveCulling) {
if (publicType.qualifier.storage != EvqTemporary)
error(loc, "layout qualifier can not have storage qualifiers", "primitive_culling","", "");
else {
intermediate.setLayoutPrimitiveCulling();
}
// Exit early as further checks are not valid
return;
}
#endif
const TQualifier& qualifier = publicType.qualifier;

Expand Down
6 changes: 5 additions & 1 deletion glslang/MachineIndependent/localintermediate.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ class TIntermediate {
needToLegalize(false),
binaryDoubleOutput(false),
usePhysicalStorageBuffer(false),
uniformLocationBase(0)
uniformLocationBase(0),
layoutPrimitiveCulling(false)
#endif
{
localSize[0] = 1;
Expand Down Expand Up @@ -742,6 +743,8 @@ class TIntermediate {
void setLayoutDerivativeMode(ComputeDerivativeMode mode) { computeDerivativeMode = mode; }
bool hasLayoutDerivativeModeNone() const { return computeDerivativeMode != LayoutDerivativeNone; }
ComputeDerivativeMode getLayoutDerivativeModeNone() const { return computeDerivativeMode; }
void setLayoutPrimitiveCulling() { layoutPrimitiveCulling = true; }
bool getLayoutPrimitiveCulling() const { return layoutPrimitiveCulling; }
bool setPrimitives(int m)
{
if (primitives != TQualifier::layoutNotSet)
Expand Down Expand Up @@ -974,6 +977,7 @@ class TIntermediate {
ComputeDerivativeMode computeDerivativeMode;
int primitives;
int numTaskNVBlocks;
bool layoutPrimitiveCulling;

// Base shift values
std::array<unsigned int, EResCount> shiftBinding;
Expand Down
1 change: 1 addition & 0 deletions gtests/Spv.FromFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ INSTANTIATE_TEST_CASE_P(
"spv.ext.IntersectShader_Errors.rint",
"spv.ext.MissShader.rmiss",
"spv.ext.MissShader_Errors.rmiss",
"spv.ext.RayPrimCull_Errors.rgen",
"spv.ext.RayCallable.rcall",
"spv.ext.RayCallable_Errors.rcall",
"spv.ext.RayConstants.rgen",
Expand Down

0 comments on commit 59216d5

Please sign in to comment.