summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-spirv.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-emit-spirv.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-emit-spirv.cpp')
-rw-r--r--source/slang/slang-emit-spirv.cpp34
1 files changed, 29 insertions, 5 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp
index 79f324988..afb1b3a63 100644
--- a/source/slang/slang-emit-spirv.cpp
+++ b/source/slang/slang-emit-spirv.cpp
@@ -2956,6 +2956,7 @@ struct SPIRVEmitContext
// We will continue to use the Slang terminology here, since
// this code path is a catch-all for stuff that only needs to
// be emitted if the owning instruction gets emitted.
+ bool isRayTracingObject = false;
switch( decoration->getOp() )
{
@@ -3225,13 +3226,25 @@ struct SPIRVEmitContext
}
break;
+ case kIROp_VulkanHitAttributesDecoration:
case kIROp_VulkanCallablePayloadDecoration:
+ case kIROp_VulkanCallablePayloadInDecoration:
+ ensureExtensionDeclaration(UnownedStringSlice("SPV_KHR_ray_tracing"));
+ requireSPIRVCapability(SpvCapabilityRayTracingKHR);
+ isRayTracingObject = true;
+ break;
case kIROp_VulkanHitObjectAttributesDecoration:
+ // needed since GLSL will not set optypes accordingly, but will keep the decoration
+ ensureExtensionDeclaration(UnownedStringSlice("SPV_NV_shader_invocation_reorder"));
+ requireSPIRVCapability(SpvCapabilityShaderInvocationReorderNV);
+ isRayTracingObject = true;
+ break;
case kIROp_VulkanRayPayloadDecoration:
- emitOpDecorateLocation(getSection(SpvLogicalSectionID::Annotations),
- decoration,
- dstID,
- SpvLiteralInteger::from32(int32_t(getIntVal(decoration->getOperand(0)))));
+ case kIROp_VulkanRayPayloadInDecoration:
+ // needed since GLSL will not set optypes accordingly, but will keep the decoration
+ ensureExtensionDeclaration(UnownedStringSlice("SPV_KHR_ray_query"));
+ requireSPIRVCapability(SpvCapabilityRayQueryKHR);
+ isRayTracingObject = true;
break;
case kIROp_GloballyCoherentDecoration:
emitOpDecorate(getSection(SpvLogicalSectionID::Annotations),
@@ -3242,6 +3255,17 @@ struct SPIRVEmitContext
// ...
}
+ if(isRayTracingObject)
+ {
+ if (decoration->getOperandCount() > 0) {
+ //if not greater than 0, this is not a layout decoration (no val)
+ emitOpDecorateLocation(getSection(SpvLogicalSectionID::Annotations),
+ decoration,
+ dstID,
+ SpvLiteralInteger::from32(int32_t(getIntVal(decoration->getOperand(0)))));
+ }
+ }
+
if (shouldEmitSPIRVReflectionInfo())
{
switch (decoration->getOp())
@@ -5823,7 +5847,7 @@ SlangResult emitSPIRVFromIR(
SPIRVEmitContext context(irModule, codeGenContext->getTargetProgram(), sink);
legalizeIRForSPIRV(&context, irModule, irEntryPoints, codeGenContext);
-
+
#if 0
{
DiagnosticSinkWriter writer(codeGenContext->getSink());