summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-parser.cpp
diff options
context:
space:
mode:
authorArielG-NV <159081215+ArielG-NV@users.noreply.github.com>2024-03-15 16:14:32 -0400
committerGitHub <noreply@github.com>2024-03-15 16:14:32 -0400
commit9b434e50f02f9ec02ce230de9042ce7448bae451 (patch)
tree092aaecc785047a8005462764404f9c530e3a69c /source/slang/slang-parser.cpp
parent9ee88a43f4e67d9c714c27bf968401b6bf7524af (diff)
Implement raytracing extension(s); resolves #3560 for GLSL & SPIR-V targets (#3675)
The following PR implements raytracing extensions (GLSL_EXT_ray_tracing, GLSL_EXT_ray_query, GLSL_NV_shader_invocation_reorder & GLSL_NV_ray_tracing_motion_blur); for GLSL & SPIR-V targets. Fully implements all functions, built-in variables, & syntax; resolves #3560 for GLSL & SPIR-V Targets. notes of worth: * __rayPayloadFromLocation, __rayAttributeFromLocation, and __rayCallableFromLocation, were added as SPIR-V Intrinsics to refer to location's of raytracing objects in SPIR-V for when using GLSL syntax.
Diffstat (limited to 'source/slang/slang-parser.cpp')
-rw-r--r--source/slang/slang-parser.cpp47
1 files changed, 46 insertions, 1 deletions
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp
index cc87a3daa..e1dce5731 100644
--- a/source/slang/slang-parser.cpp
+++ b/source/slang/slang-parser.cpp
@@ -7102,6 +7102,30 @@ namespace Slang
{
return SPIRVAsmOperand{ SPIRVAsmOperand::NonSemanticDebugPrintfExtSet, parser->ReadToken() };
}
+ else if (AdvanceIf(parser, "__rayPayloadFromLocation"))
+ {
+ // reference a magic number to a layout(location) for late compiler resolution of rayPayload objects
+ parser->ReadToken(TokenType::LParent);
+ auto operand = SPIRVAsmOperand{ SPIRVAsmOperand::RayPayloadFromLocation, Token{}, parseAtomicExpr(parser) };
+ parser->ReadToken(TokenType::RParent);
+ return operand;
+ }
+ else if (AdvanceIf(parser, "__rayAttributeFromLocation"))
+ {
+ // works similar to __rayPayloadFromLocation
+ parser->ReadToken(TokenType::LParent);
+ auto operand = SPIRVAsmOperand{ SPIRVAsmOperand::RayAttributeFromLocation, Token{}, parseAtomicExpr(parser) };
+ parser->ReadToken(TokenType::RParent);
+ return operand;
+ }
+ else if (AdvanceIf(parser, "__rayCallableFromLocation"))
+ {
+ // works similar to __rayPayloadFromLocation
+ parser->ReadToken(TokenType::LParent);
+ auto operand = SPIRVAsmOperand{ SPIRVAsmOperand::RayCallableFromLocation, Token{}, parseAtomicExpr(parser) };
+ parser->ReadToken(TokenType::RParent);
+ return operand;
+ }
// A regular identifier
else if(parser->LookAheadToken(TokenType::Identifier))
{
@@ -7846,6 +7870,7 @@ namespace Slang
#define CASE(key, type) if (nameText == #key) { modifier = parser->astBuilder->create<type>(); } else
CASE(push_constant, PushConstantAttribute)
CASE(shaderRecordNV, ShaderRecordAttribute)
+ CASE(shaderRecordEXT, ShaderRecordAttribute)
CASE(constant_id, GLSLConstantIDLayoutModifier)
CASE(std140, GLSLStd140Modifier)
CASE(std430, GLSLStd430Modifier)
@@ -7893,6 +7918,20 @@ namespace Slang
parser->ReadToken(TokenType::Comma);
}
+#define CASE(key, type) if (AdvanceIf(parser, #key)) { auto modifier = parser->astBuilder->create<type>(); \
+ modifier->location = int(getIntegerLiteralValue(listBuilder.find<GLSLLayoutModifier>()->valToken)); listBuilder.add(modifier); } else
+
+ CASE(rayPayloadEXT, VulkanRayPayloadAttribute)
+ CASE(rayPayloadNV, VulkanRayPayloadAttribute)
+ CASE(rayPayloadInEXT, VulkanRayPayloadInAttribute)
+ CASE(rayPayloadInNV, VulkanRayPayloadInAttribute)
+ CASE(hitObjectAttributeNV, VulkanHitObjectAttributesAttribute)
+ CASE(callableDataEXT, VulkanCallablePayloadAttribute)
+ CASE(callableDataInEXT, VulkanCallablePayloadInAttribute)
+ {}
+
+#undef CASE
+
if (numThreadsAttrib)
{
listBuilder.add(numThreadsAttrib);
@@ -7903,6 +7942,12 @@ namespace Slang
return listBuilder.getFirst();
}
+ static NodeBase* parseHitAttributeEXTModifier(Parser* parser, void* /*userData*/)
+ {
+ VulkanHitAttributesAttribute* modifier = parser->astBuilder->create<VulkanHitAttributesAttribute>();
+ return modifier;
+ }
+
static NodeBase* parseBuiltinTypeModifier(Parser* parser, void* /*userData*/)
{
BuiltinTypeModifier* modifier = parser->astBuilder->create<BuiltinTypeModifier>();
@@ -8131,7 +8176,7 @@ namespace Slang
// or expect more tokens after the initial keyword.
_makeParseModifier("layout", parseLayoutModifier),
-
+ _makeParseModifier("hitAttributeEXT", parseHitAttributeEXTModifier),
_makeParseModifier("__intrinsic_op", parseIntrinsicOpModifier),
_makeParseModifier("__target_intrinsic", parseTargetIntrinsicModifier),
_makeParseModifier("__specialized_for_target", parseSpecializedForTargetModifier),