summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-glsl.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-02-02 22:28:02 -0800
committerGitHub <noreply@github.com>2024-02-02 22:28:02 -0800
commit14764896c34b230a5563f48d8b8e565de2f3aa10 (patch)
tree2f105d3f6222103f458054f1cd38e280b6fb52b4 /source/slang/slang-emit-glsl.cpp
parentc15e7ade4e27e1649d5b98f5854e9e52bb9e60ae (diff)
Capability type checking. (#3530)
* Capability type checking. * Fix. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-emit-glsl.cpp')
-rw-r--r--source/slang/slang-emit-glsl.cpp144
1 files changed, 13 insertions, 131 deletions
diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp
index a0151133d..248b803f4 100644
--- a/source/slang/slang-emit-glsl.cpp
+++ b/source/slang/slang-emit-glsl.cpp
@@ -64,43 +64,14 @@ SlangResult GLSLSourceEmitter::init()
void GLSLSourceEmitter::_requireRayTracing()
{
- // There is more than one extension that provides ray-tracing capabilities,
- // and we need to pick which one to enable.
- //
- // By default, we will use the `GL_EXT_ray_tracing` extension, but if
- // the user has explicitly opted in to the `GL_NV_ray_tracing` extension
- // we will use that one instead.
- //
- if( getTargetCaps().implies(CapabilityAtom::_GL_NV_ray_tracing) )
- {
- m_glslExtensionTracker->requireExtension(UnownedStringSlice::fromLiteral("GL_NV_ray_tracing"));
- }
- else
- {
- m_glslExtensionTracker->requireExtension(UnownedStringSlice::fromLiteral("GL_EXT_ray_tracing"));
- m_glslExtensionTracker->requireSPIRVVersion(SemanticVersion(1, 4));
- }
-
+ m_glslExtensionTracker->requireExtension(UnownedStringSlice::fromLiteral("GL_EXT_ray_tracing"));
+ m_glslExtensionTracker->requireSPIRVVersion(SemanticVersion(1, 4));
m_glslExtensionTracker->requireVersion(ProfileVersion::GLSL_460);
}
void GLSLSourceEmitter::_requireFragmentShaderBarycentric()
{
- // There is more than one extension that provides barycentric coords in fragment shaders,
- // and we need to pick which one to enable.
- //
- // By default, we will use the `GL_EXT_fragment_shader_barycentric` extension, but if
- // the user has explicitly opted in to the `GL_NV_fragment_shader_barycentric` extension
- // we will use that one instead.
-
- if( getTargetCaps().implies(CapabilityAtom::_GL_NV_fragment_shader_barycentric) )
- {
- m_glslExtensionTracker->requireExtension(UnownedStringSlice::fromLiteral("GL_NV_fragment_shader_barycentric"));
- }
- else
- {
- m_glslExtensionTracker->requireExtension(UnownedStringSlice::fromLiteral("GL_EXT_fragment_shader_barycentric"));
- }
+ m_glslExtensionTracker->requireExtension(UnownedStringSlice::fromLiteral("GL_EXT_fragment_shader_barycentric"));
m_glslExtensionTracker->requireVersion(ProfileVersion::GLSL_450);
}
@@ -129,11 +100,6 @@ void GLSLSourceEmitter::_requireGLSLVersion(int version)
{
#define CASE(NUMBER) \
case NUMBER: _requireGLSLVersion(ProfileVersion::GLSL_##NUMBER); break
-
- CASE(110);
- CASE(120);
- CASE(130);
- CASE(140);
CASE(150);
CASE(330);
CASE(400);
@@ -684,14 +650,7 @@ bool GLSLSourceEmitter::_emitGLSLLayoutQualifierWithBindingKinds(LayoutResourceK
m_writer->emit("layout(push_constant)\n");
break;
case LayoutResourceKind::ShaderRecord:
- if (getTargetCaps().implies(CapabilityAtom::_GL_NV_ray_tracing))
- {
- m_writer->emit("layout(shaderRecordNV)\n");
- }
- else
- {
- m_writer->emit("layout(shaderRecordEXT)\n");
- }
+ m_writer->emit("layout(shaderRecordEXT)\n");
break;
}
@@ -1430,40 +1389,19 @@ void GLSLSourceEmitter::emitLayoutQualifiersImpl(IRVarLayout* layout)
case LayoutResourceKind::RayPayload:
{
- if( getTargetCaps().implies(CapabilityAtom::_GL_NV_ray_tracing) )
- {
- m_writer->emit("rayPayloadInNV ");
- }
- else
- {
- m_writer->emit("rayPayloadInEXT ");
- }
+ m_writer->emit("rayPayloadInEXT ");
}
break;
case LayoutResourceKind::CallablePayload:
{
- if( getTargetCaps().implies(CapabilityAtom::_GL_NV_ray_tracing) )
- {
- m_writer->emit("callableDataInNV ");
- }
- else
- {
- m_writer->emit("callableDataInEXT ");
- }
+ m_writer->emit("callableDataInEXT ");
}
break;
case LayoutResourceKind::HitAttributes:
{
- if( getTargetCaps().implies(CapabilityAtom::_GL_NV_ray_tracing) )
- {
- m_writer->emit("hitAttributeNV ");
- }
- else
- {
- m_writer->emit("hitAttributeEXT ");
- }
+ m_writer->emit("hitAttributeEXT ");
}
break;
@@ -2136,10 +2074,6 @@ static Index _getGLSLVersion(ProfileVersion profile)
switch (profile)
{
#define CASE(TAG, VALUE) case ProfileVersion::TAG: return VALUE;
- CASE(GLSL_110, 110);
- CASE(GLSL_120, 120);
- CASE(GLSL_130, 130);
- CASE(GLSL_140, 140);
CASE(GLSL_150, 150);
CASE(GLSL_330, 330);
CASE(GLSL_400, 400);
@@ -2479,45 +2413,8 @@ void GLSLSourceEmitter::emitSimpleTypeImpl(IRType* type)
{
case kIROp_RaytracingAccelerationStructureType:
{
- // Note: We have the problem here that we want to do `_requireRayTracing()`,
- // but just based on the use of a ray-tracing acceleration structure we
- // cannot know which extension the user means to use. The current options are:
- //
- // * GL_NV_ray_tracing
- // * GL_EXT_ray_tracing
- // * GL_EXT_ray_query
- //
- // The first two options there are basically equivalent extensions with
- // different GLSL syntax. We end up requiring the user to opt in to
- // `GL_NV_ray_tracing` using target capabilities, and will always default
- // to `GL_EXT_ray_tracing` otherwise.
- //
- if( getTargetCaps().implies(CapabilityAtom::_GL_NV_ray_tracing) )
- {
- // If the user has explicitly opted in to `GL_NV_ray_tracing`,
- // then we don't need to explicitly request the extentsion again.
- // We know that the acceleration structure type will translate
- // to the one from that extension:
- //
- _requireRayTracing();
- m_writer->emit("accelerationStructureNV");
- }
- else
- {
- // If the user does *not* opt into a specific extension, then we
- // have the problem that either `GL_EXT_ray_tracing` or `GL_EXT_ray-query`
- // could provide the `accelerationSturctureEXT` type, but there
- // can be drivers that provide only one and not the other.
- //
- // For now we will just kludge this by assuming that any driver
- // that supports one of these extensions supports the other.
- //
- // TODO: Revisit that decision once the driver landscape is more stable/clear.
- //
- _requireRayTracing();
-
- m_writer->emit("accelerationStructureEXT");
- }
+ _requireRayTracing();
+ m_writer->emit("accelerationStructureEXT");
break;
}
@@ -2580,14 +2477,7 @@ bool GLSLSourceEmitter::_maybeEmitInterpolationModifierText(IRInterpolationMode
if( stage == Stage::Fragment && isInput)
{
_requireFragmentShaderBarycentric();
- if (getTargetCaps().implies(CapabilityAtom::_GL_NV_fragment_shader_barycentric))
- {
- m_writer->emit("pervertexNV ");
- }
- else
- {
- m_writer->emit("pervertexEXT ");
- }
+ m_writer->emit("pervertexEXT ");
}
else
{
@@ -2694,6 +2584,7 @@ void GLSLSourceEmitter::emitVarDecorationsImpl(IRInst* varDecl)
for (auto decoration : varDecl->getDecorations())
{
UnownedStringSlice prefix;
+ UnownedStringSlice postfix = toSlice("EXT");
if (as<IRVulkanHitAttributesDecoration>(decoration))
{
prefix = toSlice("hitAttribute");
@@ -2713,6 +2604,7 @@ void GLSLSourceEmitter::emitVarDecorationsImpl(IRInst* varDecl)
break;
case kIROp_VulkanHitObjectAttributesDecoration:
prefix = toSlice("hitObjectAttribute");
+ postfix = toSlice("NV");
locationValue = getIntVal(decoration->getOperand(0));
break;
default:
@@ -2725,17 +2617,7 @@ void GLSLSourceEmitter::emitVarDecorationsImpl(IRInst* varDecl)
SLANG_ASSERT(prefix.getLength());
m_writer->emit(prefix);
-
- // Special case hitObjectAttribute as is only NV currently
- if (decoration->getOp() == kIROp_VulkanHitObjectAttributesDecoration ||
- getTargetCaps().implies(CapabilityAtom::_GL_NV_ray_tracing))
- {
- m_writer->emit(toSlice("NV"));
- }
- else
- {
- m_writer->emit(toSlice("EXT"));
- }
+ m_writer->emit(postfix);
m_writer->emit(toSlice("\n"));
// If we emit a location we are done.