diff options
| -rw-r--r-- | examples/model-viewer/shaders.slang | 4 | ||||
| -rw-r--r-- | slang.h | 2 | ||||
| -rw-r--r-- | source/slang-glslang/slang-glslang.cpp | 1 | ||||
| -rw-r--r-- | source/slang/core.meta.slang | 3 | ||||
| -rw-r--r-- | source/slang/core.meta.slang.h | 3 | ||||
| -rw-r--r-- | source/slang/emit.cpp | 47 | ||||
| -rw-r--r-- | source/slang/hlsl.meta.slang | 34 | ||||
| -rw-r--r-- | source/slang/hlsl.meta.slang.h | 34 | ||||
| -rw-r--r-- | source/slang/ir-insts.h | 10 | ||||
| -rw-r--r-- | source/slang/ir-serialize.cpp | 7 | ||||
| -rw-r--r-- | source/slang/ir.cpp | 11 | ||||
| -rw-r--r-- | source/slang/ir.h | 1 | ||||
| -rw-r--r-- | source/slang/lower-to-ir.cpp | 4 | ||||
| -rw-r--r-- | source/slang/modifier-defs.h | 6 | ||||
| -rw-r--r-- | source/slang/options.cpp | 4 | ||||
| -rw-r--r-- | source/slang/parameter-binding.cpp | 8 | ||||
| -rw-r--r-- | source/slang/preprocessor.cpp | 2 | ||||
| -rw-r--r-- | source/slang/type-layout.cpp | 26 | ||||
| -rw-r--r-- | source/slang/type-layout.h | 1 | ||||
| -rw-r--r-- | tests/vkray/callable-caller.slang | 23 | ||||
| -rw-r--r-- | tests/vkray/callable-caller.slang.glsl | 67 | ||||
| -rw-r--r-- | tests/vkray/callable-shared.slang | 8 | ||||
| -rw-r--r-- | tests/vkray/callable.slang | 16 | ||||
| -rw-r--r-- | tests/vkray/callable.slang.glsl | 26 |
24 files changed, 334 insertions, 14 deletions
diff --git a/examples/model-viewer/shaders.slang b/examples/model-viewer/shaders.slang index 9b6538577..15ce0120d 100644 --- a/examples/model-viewer/shaders.slang +++ b/examples/model-viewer/shaders.slang @@ -155,7 +155,7 @@ struct SimpleMaterial : IMaterial // To satisfy the requirements of the `IMaterial` interface, our // material type needs to provide a suitable `BRDF` type. We // do this by using a simple `typedef`, although a nested - // `struct` type can also satisfy an assocaited type requirement. + // `struct` type can also satisfy an associated type requirement. // // A future version of the Slang compiler may allow the "right" // associated type definition to be inferred from the signature @@ -459,7 +459,7 @@ float4 fragmentMain( // from different light sources. // // Note that the return type here is `TMaterial.BRDF`, - // which is the `BRDF` type *assocaited* with the (unknown) + // which is the `BRDF` type *associated* with the (unknown) // `TMaterial` type. When `TMaterial` gets substituted for // a concrete type later (e.g., `SimpleMaterial`) this // will resolve to a concrete type too (e.g., `SimpleMaterial.BRDF` @@ -1378,6 +1378,7 @@ extern "C" SLANG_PARAMETER_CATEGORY_RAY_PAYLOAD, SLANG_PARAMETER_CATEGORY_HIT_ATTRIBUTES, + SLANG_PARAMETER_CATEGORY_CALLABLE_PAYLOAD, // SLANG_PARAMETER_CATEGORY_COUNT, @@ -1681,6 +1682,7 @@ namespace slang RayPayload = SLANG_PARAMETER_CATEGORY_RAY_PAYLOAD, HitAttributes = SLANG_PARAMETER_CATEGORY_HIT_ATTRIBUTES, + CallablePayload = SLANG_PARAMETER_CATEGORY_CALLABLE_PAYLOAD, // DEPRECATED: VertexInput = SLANG_PARAMETER_CATEGORY_VERTEX_INPUT, diff --git a/source/slang-glslang/slang-glslang.cpp b/source/slang-glslang/slang-glslang.cpp index ba39d6a12..68bf7b6a3 100644 --- a/source/slang-glslang/slang-glslang.cpp +++ b/source/slang-glslang/slang-glslang.cpp @@ -102,6 +102,7 @@ static int glslang_compileGLSLToSPIRV(glslang_CompileRequest* request) CASE(ANY_HIT, AnyHitNV); CASE(CLOSEST_HIT, ClosestHitNV); CASE(MISS, MissNV); + CASE(CALLABLE, CallableNV); #undef CASE diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index 26bf1112d..e7c424c33 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -1234,6 +1234,9 @@ __attributeTarget(VarDeclBase) attribute_syntax [__vulkanRayPayload] : VulkanRayPayloadAttribute; __attributeTarget(VarDeclBase) +attribute_syntax [__vulkanCallablePayload] : VulkanCallablePayloadAttribute; + +__attributeTarget(VarDeclBase) attribute_syntax [__vulkanHitAttributes] : VulkanHitAttributesAttribute; __attributeTarget(FunctionDeclBase) diff --git a/source/slang/core.meta.slang.h b/source/slang/core.meta.slang.h index 5380bd90f..addc3856f 100644 --- a/source/slang/core.meta.slang.h +++ b/source/slang/core.meta.slang.h @@ -1252,6 +1252,9 @@ SLANG_RAW("__attributeTarget(VarDeclBase)\n") SLANG_RAW("attribute_syntax [__vulkanRayPayload] : VulkanRayPayloadAttribute;\n") SLANG_RAW("\n") SLANG_RAW("__attributeTarget(VarDeclBase)\n") +SLANG_RAW("attribute_syntax [__vulkanCallablePayload] : VulkanCallablePayloadAttribute;\n") +SLANG_RAW("\n") +SLANG_RAW("__attributeTarget(VarDeclBase)\n") SLANG_RAW("attribute_syntax [__vulkanHitAttributes] : VulkanHitAttributesAttribute;\n") SLANG_RAW("\n") SLANG_RAW("__attributeTarget(FunctionDeclBase)\n") diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 5c39dd50c..644725fa8 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -148,6 +148,7 @@ struct SharedEmitContext DiagnosticSink* getSink() { return &entryPoint->compileRequest->mSink; } Dictionary<IRInst*, UInt> mapIRValueToRayPayloadLocation; + Dictionary<IRInst*, UInt> mapIRValueToCallablePayloadLocation; }; struct EmitContext @@ -3315,7 +3316,7 @@ struct EmitVisitor case 'P': { // The `$XP` case handles looking up - // the assocaited `location` for a variable + // the associated `location` for a variable // used as the argument ray payload at a // trace call site. @@ -3329,6 +3330,23 @@ struct EmitVisitor } break; + case 'C': + { + // The `$XC` case handles looking up + // the associated `location` for a variable + // used as the argument callable payload at a + // call site. + + UInt argIndex = 0; + SLANG_RELEASE_ASSERT(argCount > argIndex); + auto arg = args[argIndex].get(); + auto argLoad = as<IRLoad>(arg); + SLANG_RELEASE_ASSERT(argLoad); + auto argVar = argLoad->getOperand(0); + Emit(getCallablePayloadLocation(ctx, argVar)); + } + break; + case 'T': { // The `$XT` case handles selecting between @@ -5347,6 +5365,20 @@ struct EmitVisitor return value; } + UInt getCallablePayloadLocation( + EmitContext* ctx, + IRInst* inst) + { + auto& map = ctx->shared->mapIRValueToCallablePayloadLocation; + UInt value = 0; + if(map.TryGetValue(inst, value)) + return value; + + value = map.Count(); + map.Add(inst, value); + return value; + } + void emitIRVarModifiers( EmitContext* ctx, VarLayout* layout, @@ -5365,6 +5397,13 @@ struct EmitVisitor emit(")\n"); emit("rayPayloadNV\n"); } + if(varDecl->findDecoration<IRVulkanCallablePayloadDecoration>()) + { + emit("layout(location = "); + Emit(getCallablePayloadLocation(ctx, varDecl)); + emit(")\n"); + emit("callableDataNV\n"); + } if(varDecl->findDecoration<IRVulkanHitAttributesDecoration>()) { emit("hitAttributeNV\n"); @@ -5520,6 +5559,12 @@ struct EmitVisitor } break; + case LayoutResourceKind::CallablePayload: + { + emit("callableDataInNV "); + } + break; + case LayoutResourceKind::HitAttributes: { emit("hitAttributeNV "); diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index 56741f6b3..36cefc699 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -1355,8 +1355,38 @@ struct BuiltInTriangleIntersectionAttributes // 10.3 - Intrinsics
// 10.3.1
-__target_intrinsic(glsl, "callableShadersAreNotYetAvailableInVulkan")
-void CallShader<param_t>(uint ShaderIndex, inout param_t Parameter);
+
+void CallShader<Payload>(uint shaderIndex, inout Payload payload);
+
+// `executeCallableNV` is the GLSL intrinsic that will be used to implement
+// `CallShader()` for GLSL-based targets.
+//
+__target_intrinsic(glsl, "executeCallableNV")
+void __executeCallableNV(uint shaderIndex, int payloadLocation);
+
+// Next is the custom intrinsic that will compute the payload location
+// for a type being used in a `CallShader()` call for GLSL-based targets.
+//
+__generic<Payload>
+__target_intrinsic(glsl, "$XC")
+[__readNone]
+int __callablePayloadLocation(Payload payload);
+
+// Now we provide a hard-coded definition of `CallShader()` for GLSL-based
+// targets, which maps the generic HLSL operation into the non-generic
+// GLSL equivalent.
+//
+__generic<Payload>
+__specialized_for_target(glsl)
+void CallShader(uint shaderIndex, inout Payload payload)
+{
+ [__vulkanRayPayload]
+ static Payload p;
+
+ p = payload;
+ __executeCallableNV(shaderIndex, __callablePayloadLocation(p));
+ payload = p;
+}
// 10.3.2
void TraceRay<payload_t>(
diff --git a/source/slang/hlsl.meta.slang.h b/source/slang/hlsl.meta.slang.h index 5e00c2719..7194c9990 100644 --- a/source/slang/hlsl.meta.slang.h +++ b/source/slang/hlsl.meta.slang.h @@ -1403,8 +1403,38 @@ SLANG_RAW("\n") SLANG_RAW("// 10.3 - Intrinsics\n") SLANG_RAW("\n") SLANG_RAW("// 10.3.1\n") -SLANG_RAW("__target_intrinsic(glsl, \"callableShadersAreNotYetAvailableInVulkan\")\n") -SLANG_RAW("void CallShader<param_t>(uint ShaderIndex, inout param_t Parameter);\n") +SLANG_RAW("\n") +SLANG_RAW("void CallShader<Payload>(uint shaderIndex, inout Payload payload);\n") +SLANG_RAW("\n") +SLANG_RAW("// `executeCallableNV` is the GLSL intrinsic that will be used to implement\n") +SLANG_RAW("// `CallShader()` for GLSL-based targets.\n") +SLANG_RAW("//\n") +SLANG_RAW("__target_intrinsic(glsl, \"executeCallableNV\")\n") +SLANG_RAW("void __executeCallableNV(uint shaderIndex, int payloadLocation);\n") +SLANG_RAW("\n") +SLANG_RAW("// Next is the custom intrinsic that will compute the payload location\n") +SLANG_RAW("// for a type being used in a `CallShader()` call for GLSL-based targets.\n") +SLANG_RAW("//\n") +SLANG_RAW("__generic<Payload>\n") +SLANG_RAW("__target_intrinsic(glsl, \"$XC\")\n") +SLANG_RAW("[__readNone]\n") +SLANG_RAW("int __callablePayloadLocation(Payload payload);\n") +SLANG_RAW("\n") +SLANG_RAW("// Now we provide a hard-coded definition of `CallShader()` for GLSL-based\n") +SLANG_RAW("// targets, which maps the generic HLSL operation into the non-generic\n") +SLANG_RAW("// GLSL equivalent.\n") +SLANG_RAW("//\n") +SLANG_RAW("__generic<Payload>\n") +SLANG_RAW("__specialized_for_target(glsl)\n") +SLANG_RAW("void CallShader(uint shaderIndex, inout Payload payload)\n") +SLANG_RAW("{\n") +SLANG_RAW(" [__vulkanRayPayload]\n") +SLANG_RAW(" static Payload p;\n") +SLANG_RAW("\n") +SLANG_RAW(" p = payload;\n") +SLANG_RAW(" __executeCallableNV(shaderIndex, __callablePayloadLocation(p));\n") +SLANG_RAW(" payload = p;\n") +SLANG_RAW("}\n") SLANG_RAW("\n") SLANG_RAW("// 10.3.2\n") SLANG_RAW("void TraceRay<payload_t>(\n") diff --git a/source/slang/ir-insts.h b/source/slang/ir-insts.h index db61cae88..5cbdf326e 100644 --- a/source/slang/ir-insts.h +++ b/source/slang/ir-insts.h @@ -126,6 +126,14 @@ struct IRVulkanRayPayloadDecoration : IRDecoration }; /// A decoration that indicates that a variable represents +/// a vulkan callable shader payload, and should have a location assigned +/// to it. +struct IRVulkanCallablePayloadDecoration : IRDecoration +{ + enum { kDecorationOp = kIRDecorationOp_VulkanCallablePayload }; +}; + +/// A decoration that indicates that a variable represents /// vulkan hit attributes, and should have a location assigned /// to it. struct IRVulkanHitAttributesDecoration : IRDecoration @@ -978,7 +986,7 @@ IRGlobalValue* getSpecializedGlobalValueForDeclRef( struct ExtensionUsageTracker; // Clone the IR values reachable from the given entry point -// into the IR module assocaited with the specialization state. +// into the IR module associated with the specialization state. // When multiple definitions of a symbol are found, the one // that is best specialized for the given `targetReq` will be // used. diff --git a/source/slang/ir-serialize.cpp b/source/slang/ir-serialize.cpp index 7cc3d6384..7e7c6c8a7 100644 --- a/source/slang/ir-serialize.cpp +++ b/source/slang/ir-serialize.cpp @@ -704,6 +704,7 @@ Result IRSerialWriter::write(IRModule* module, SourceManager* sourceManager, Opt break; } case kIRDecorationOp_VulkanRayPayload: + case kIRDecorationOp_VulkanCallablePayload: case kIRDecorationOp_VulkanHitAttributes: case kIRDecorationOp_ReadNone: { @@ -1560,6 +1561,12 @@ IRDecoration* IRSerialReader::_createDecoration(const Ser::Inst& srcInst) SLANG_ASSERT(srcInst.m_payloadType == PayloadType::Empty); return decor; } + case kIRDecorationOp_VulkanCallablePayload: + { + auto decor = createEmptyDecoration<IRVulkanCallablePayloadDecoration>(m_module); + SLANG_ASSERT(srcInst.m_payloadType == PayloadType::Empty); + return decor; + } case kIRDecorationOp_VulkanHitAttributes: { auto decor = createEmptyDecoration<IRVulkanHitAttributesDecoration>(m_module); diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp index a66b26e93..356648212 100644 --- a/source/slang/ir.cpp +++ b/source/slang/ir.cpp @@ -2934,6 +2934,11 @@ namespace Slang dump(context, "\n[__vulkanRayPayload]"); } break; + case kIRDecorationOp_VulkanCallablePayload: + { + dump(context, "\n[__vulkanCallPayload]"); + } + break; case kIRDecorationOp_VulkanHitAttributes: { dump(context, "\n[__vulkanHitAttributes]"); @@ -5377,6 +5382,12 @@ namespace Slang } break; + case kIRDecorationOp_VulkanCallablePayload: + { + context->builder->addDecoration<IRVulkanCallablePayloadDecoration>(clonedValue); + } + break; + case kIRDecorationOp_VulkanHitAttributes: { context->builder->addDecoration<IRVulkanHitAttributesDecoration>(clonedValue); diff --git a/source/slang/ir.h b/source/slang/ir.h index def68098d..9c7637360 100644 --- a/source/slang/ir.h +++ b/source/slang/ir.h @@ -158,6 +158,7 @@ enum IRDecorationOp : uint16_t kIRDecorationOp_RequireGLSLVersion, kIRDecorationOp_RequireGLSLExtension, kIRDecorationOp_ReadNone, + kIRDecorationOp_VulkanCallablePayload, kIRDecorationOp_CountOf }; diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp index 815822495..4f40b4af6 100644 --- a/source/slang/lower-to-ir.cpp +++ b/source/slang/lower-to-ir.cpp @@ -1260,6 +1260,10 @@ void addVarDecorations( { builder->addDecoration<IRVulkanRayPayloadDecoration>(inst); } + else if(mod.As<VulkanCallablePayloadAttribute>()) + { + builder->addDecoration<IRVulkanCallablePayloadDecoration>(inst); + } else if(mod.As<VulkanHitAttributesAttribute>()) { builder->addDecoration<IRVulkanHitAttributesDecoration>(inst); diff --git a/source/slang/modifier-defs.h b/source/slang/modifier-defs.h index bb9aefcb7..f6f55ecbd 100644 --- a/source/slang/modifier-defs.h +++ b/source/slang/modifier-defs.h @@ -393,6 +393,12 @@ END_SYNTAX_CLASS() // ray tracing shader to pass per-ray payload information. SIMPLE_SYNTAX_CLASS(VulkanRayPayloadAttribute, Attribute) +// A `[__vulkanCallablePayload]` attribute, which is used in the +// standard library implementation to indicate that a variable +// actually represents the input/output interface for a Vulkan +// ray tracing shader to pass payload information to/from a callee. +SIMPLE_SYNTAX_CLASS(VulkanCallablePayloadAttribute, Attribute) + // A `[__vulkanHitAttributes]` attribute, which is used in the // standard library implementation to indicate that a variable // actually represents the output interface for a Vulkan diff --git a/source/slang/options.cpp b/source/slang/options.cpp index 9f65d0e5c..f1a5798ce 100644 --- a/source/slang/options.cpp +++ b/source/slang/options.cpp @@ -103,7 +103,7 @@ struct OptionsParser // An entry point represents a function to be checked and possibly have // code generated in one of our translation units. An entry point - // needs to have an assocaited stage, which might come via the + // needs to have an associated stage, which might come via the // `-stage` command line option, or a `[shader("...")]` attribute // in the source code. // @@ -1176,7 +1176,7 @@ struct OptionsParser // need to support output formats that can store multiple // entry points in one file). - // If an output doesn't have a target assocaited with + // If an output doesn't have a target associated with // it, then search for the target with the matching format. if( rawOutput.targetIndex == -1 ) { diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp index a4e9d6ca0..e156c9690 100644 --- a/source/slang/parameter-binding.cpp +++ b/source/slang/parameter-binding.cpp @@ -1910,13 +1910,19 @@ static RefPtr<TypeLayout> processEntryPointParameter( break; case Stage::AnyHit: - case Stage::Callable: case Stage::ClosestHit: case Stage::Miss: // `in out` or `out` parameter is payload return CreateTypeLayout(context->layoutContext.with( context->getRulesFamily()->getRayPayloadParameterRules()), type); + + case Stage::Callable: + // `in out` or `out` parameter is payload + return CreateTypeLayout(context->layoutContext.with( + context->getRulesFamily()->getCallablePayloadParameterRules()), + type); + } } else diff --git a/source/slang/preprocessor.cpp b/source/slang/preprocessor.cpp index 4b1d63850..00784ae92 100644 --- a/source/slang/preprocessor.cpp +++ b/source/slang/preprocessor.cpp @@ -478,7 +478,7 @@ static PreprocessorMacro* LookupMacro(PreprocessorEnvironment* environment, Name static PreprocessorEnvironment* GetCurrentEnvironment(Preprocessor* preprocessor) { - // The environment we will use for looking up a macro is assocaited + // The environment we will use for looking up a macro is associated // with the current input stream (because it may include entries // for macro arguments). // diff --git a/source/slang/type-layout.cpp b/source/slang/type-layout.cpp index 6915def2c..e3b89a831 100644 --- a/source/slang/type-layout.cpp +++ b/source/slang/type-layout.cpp @@ -401,12 +401,14 @@ GLSLVaryingLayoutRulesImpl kGLSLVaryingInputLayoutRulesImpl(LayoutResourceKind:: GLSLVaryingLayoutRulesImpl kGLSLVaryingOutputLayoutRulesImpl(LayoutResourceKind::FragmentOutput); GLSLRayTracingLayoutRulesImpl kGLSLRayPayloadParameterLayoutRulesImpl(LayoutResourceKind::RayPayload); +GLSLRayTracingLayoutRulesImpl kGLSLCallablePayloadParameterLayoutRulesImpl(LayoutResourceKind::CallablePayload); GLSLRayTracingLayoutRulesImpl kGLSLHitAttributesParameterLayoutRulesImpl(LayoutResourceKind::HitAttributes); HLSLVaryingLayoutRulesImpl kHLSLVaryingInputLayoutRulesImpl(LayoutResourceKind::VertexInput); HLSLVaryingLayoutRulesImpl kHLSLVaryingOutputLayoutRulesImpl(LayoutResourceKind::FragmentOutput); HLSLRayTracingLayoutRulesImpl kHLSLRayPayloadParameterLayoutRulesImpl(LayoutResourceKind::RayPayload); +HLSLRayTracingLayoutRulesImpl kHLSLCallablePayloadParameterLayoutRulesImpl(LayoutResourceKind::CallablePayload); HLSLRayTracingLayoutRulesImpl kHLSLHitAttributesParameterLayoutRulesImpl(LayoutResourceKind::HitAttributes); // @@ -423,7 +425,8 @@ struct GLSLLayoutRulesFamilyImpl : LayoutRulesFamilyImpl virtual LayoutRulesImpl* getParameterBlockRules() override; LayoutRulesImpl* getRayPayloadParameterRules() override; - LayoutRulesImpl* getHitAttributesParameterRules() override; + LayoutRulesImpl* getCallablePayloadParameterRules() override; + LayoutRulesImpl* getHitAttributesParameterRules() override; }; struct HLSLLayoutRulesFamilyImpl : LayoutRulesFamilyImpl @@ -438,7 +441,8 @@ struct HLSLLayoutRulesFamilyImpl : LayoutRulesFamilyImpl virtual LayoutRulesImpl* getParameterBlockRules() override; LayoutRulesImpl* getRayPayloadParameterRules() override; - LayoutRulesImpl* getHitAttributesParameterRules() override; + LayoutRulesImpl* getCallablePayloadParameterRules() override; + LayoutRulesImpl* getHitAttributesParameterRules() override; }; GLSLLayoutRulesFamilyImpl kGLSLLayoutRulesFamilyImpl; @@ -475,6 +479,10 @@ LayoutRulesImpl kGLSLRayPayloadParameterLayoutRulesImpl_ = { &kGLSLLayoutRulesFamilyImpl, &kGLSLRayPayloadParameterLayoutRulesImpl, &kGLSLObjectLayoutRulesImpl, }; +LayoutRulesImpl kGLSLCallablePayloadParameterLayoutRulesImpl_ = { + &kGLSLLayoutRulesFamilyImpl, &kGLSLCallablePayloadParameterLayoutRulesImpl, &kGLSLObjectLayoutRulesImpl, +}; + LayoutRulesImpl kGLSLHitAttributesParameterLayoutRulesImpl_ = { &kGLSLLayoutRulesFamilyImpl, &kGLSLHitAttributesParameterLayoutRulesImpl, &kGLSLObjectLayoutRulesImpl, }; @@ -501,6 +509,10 @@ LayoutRulesImpl kHLSLRayPayloadParameterLayoutRulesImpl_ = { &kHLSLLayoutRulesFamilyImpl, &kHLSLRayPayloadParameterLayoutRulesImpl, &kHLSLObjectLayoutRulesImpl, }; +LayoutRulesImpl kHLSLCallablePayloadParameterLayoutRulesImpl_ = { + &kHLSLLayoutRulesFamilyImpl, &kHLSLCallablePayloadParameterLayoutRulesImpl, &kHLSLObjectLayoutRulesImpl, +}; + LayoutRulesImpl kHLSLHitAttributesParameterLayoutRulesImpl_ = { &kHLSLLayoutRulesFamilyImpl, &kHLSLHitAttributesParameterLayoutRulesImpl, &kHLSLObjectLayoutRulesImpl, }; @@ -553,6 +565,11 @@ LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getRayPayloadParameterRules() return &kGLSLRayPayloadParameterLayoutRulesImpl_; } +LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getCallablePayloadParameterRules() +{ + return &kGLSLCallablePayloadParameterLayoutRulesImpl_; +} + LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getHitAttributesParameterRules() { return &kGLSLHitAttributesParameterLayoutRulesImpl_; @@ -607,6 +624,11 @@ LayoutRulesImpl* HLSLLayoutRulesFamilyImpl::getRayPayloadParameterRules() return &kHLSLRayPayloadParameterLayoutRulesImpl_; } +LayoutRulesImpl* HLSLLayoutRulesFamilyImpl::getCallablePayloadParameterRules() +{ + return &kHLSLCallablePayloadParameterLayoutRulesImpl_; +} + LayoutRulesImpl* HLSLLayoutRulesFamilyImpl::getHitAttributesParameterRules() { return &kHLSLHitAttributesParameterLayoutRulesImpl_; diff --git a/source/slang/type-layout.h b/source/slang/type-layout.h index a66d59801..7f662bdee 100644 --- a/source/slang/type-layout.h +++ b/source/slang/type-layout.h @@ -596,6 +596,7 @@ struct LayoutRulesFamilyImpl virtual LayoutRulesImpl* getParameterBlockRules() = 0; virtual LayoutRulesImpl* getRayPayloadParameterRules() = 0; + virtual LayoutRulesImpl* getCallablePayloadParameterRules() = 0; virtual LayoutRulesImpl* getHitAttributesParameterRules()= 0; }; diff --git a/tests/vkray/callable-caller.slang b/tests/vkray/callable-caller.slang new file mode 100644 index 000000000..e423f2bec --- /dev/null +++ b/tests/vkray/callable-caller.slang @@ -0,0 +1,23 @@ +// callable-caller.slang + +//TEST:CROSS_COMPILE: -profile sm_6_3 -stage raygeneration -entry main -target spirv-assembly + +import callable_shared; + +cbuffer C +{ + uint shaderIndex; +}; + +RWTexture2D<float4> gImage; + +void main() +{ + MaterialPayload payload; + payload.albedo = 0; + payload.uv = float2(DispatchRaysIndex().xy) / float2(DispatchRaysDimensions().xy); + + CallShader(shaderIndex, payload); + + gImage[DispatchRaysIndex().xy] = payload.albedo; +} diff --git a/tests/vkray/callable-caller.slang.glsl b/tests/vkray/callable-caller.slang.glsl new file mode 100644 index 000000000..2704e6720 --- /dev/null +++ b/tests/vkray/callable-caller.slang.glsl @@ -0,0 +1,67 @@ +#version 460 + +layout(row_major) uniform; +layout(row_major) buffer; +#extension GL_NV_ray_tracing : require + +struct SLANG_ParameterGroup_C_0 +{ + uint shaderIndex_0; +}; + +layout(binding = 0) +layout(std140) uniform C_0 +{ + uint shaderIndex_0; +}; + +struct MaterialPayload_0 +{ + vec4 albedo_0; + vec2 uv_0; +}; + +layout(location = 0) +rayPayloadNV MaterialPayload_0 p_0; + +layout(rgba32f) +layout(binding = 1) +uniform image2D gImage_0; + +void CallShader_0( + uint shaderIndex_1, + inout MaterialPayload_0 payload_0) +{ + p_0 = payload_0; + executeCallableNV(shaderIndex_1, (0)); + payload_0 = p_0; + return; +} + +void main() +{ + MaterialPayload_0 payload_1; + payload_1.albedo_0 = vec4(0); + + uvec3 _S1 = gl_LaunchIDNV; + vec2 _S2 = vec2(_S1.xy); + + uvec3 _S3 = gl_LaunchSizeNV; + vec2 _S4 = _S2 / vec2(_S3.xy); + + payload_1.uv_0 = _S4; + + uint _S5 = shaderIndex_0; + + MaterialPayload_0 _S6; + _S6 = payload_1; + CallShader_0(_S5, _S6); + payload_1 = _S6; + + uvec3 _S7 = gl_LaunchIDNV; + imageStore( + gImage_0, + ivec2(_S7.xy), + payload_1.albedo_0); + return; +} diff --git a/tests/vkray/callable-shared.slang b/tests/vkray/callable-shared.slang new file mode 100644 index 000000000..09e76aab1 --- /dev/null +++ b/tests/vkray/callable-shared.slang @@ -0,0 +1,8 @@ +// callable-shared.slang +//TEST_IGNORE_FILE: + +struct MaterialPayload +{ + float4 albedo; + float2 uv; +}; diff --git a/tests/vkray/callable.slang b/tests/vkray/callable.slang new file mode 100644 index 000000000..59d42546a --- /dev/null +++ b/tests/vkray/callable.slang @@ -0,0 +1,16 @@ +// callable.slang + +//TEST:CROSS_COMPILE: -profile sm_6_3 -stage callable -entry main -target spirv-assembly + +import callable_shared; + +Texture2D gAlbedoMap; +SamplerState gSampler; + +void main(in out MaterialPayload ioPayload) +{ + ioPayload.albedo = gAlbedoMap.SampleLevel( + gSampler, + ioPayload.uv, + 0); +} diff --git a/tests/vkray/callable.slang.glsl b/tests/vkray/callable.slang.glsl new file mode 100644 index 000000000..9b573a8ab --- /dev/null +++ b/tests/vkray/callable.slang.glsl @@ -0,0 +1,26 @@ +#version 460 + +#extension GL_NV_ray_tracing : require + +layout(binding = 0) uniform texture2D gAlbedoMap_0; +layout(binding = 1) uniform sampler gSampler_0; + +struct MaterialPayload_0 +{ + vec4 albedo_0; + vec2 uv_0; +}; + +callableDataInNV MaterialPayload_0 _S1; + +void main() +{ + vec4 _S2 = textureLod( + sampler2D(gAlbedoMap_0,gSampler_0), + _S1.uv_0, + float(0)); + + _S1.albedo_0 = _S2; + + return; +} |
