diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-11-12 09:57:46 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-12 09:57:46 -0800 |
| commit | 039c233d9e4617ba9edd702a8275df0837ca8365 (patch) | |
| tree | 75d22b74eb2e163bf5d57dc1a202b1b90aba10bd /source/slang/emit.cpp | |
| parent | c07f60af241b1b0f7b7eba62c65d9fe750f8f3b7 (diff) | |
Add callable shader support for Vulkan ray tracing (#718)
* Add callable shader support for Vulkan ray tracing
This change extends the previous work to update Vulkan ray tracing support for the finished `GL_NV_ray_tracing` spec.
One of the features missing in the experimental extension that was added to the final spec is "callable shaders," which allow ray tracing shaders to call other shaders as general-purpose subroutines.
Most of the implementation work here mirrors what was done for the `TraceRay()` function to map it to `traceNV()`.
We map the generic `CallShader<P>` function to the non-generic `executeCallableNV`, with a payload identifier that indicates a specific global variable of type `P` (the global variable being generated from a `static` local in `CallShader`). A new modifier is added to identify the payload structure, and the parameter binding/layout logic introduces a new resource kind for callable-shader payload data (where previously the logic had assumed ray and callable payloads should use the same resource kind).
Two test shaders are included: one for the callable shader (`callable.slang`) and one for a ray generation shader that calls it (`callable-caller.slang`). Just for kicks, the payload data type is defined in a shared file so that we can be sure the two agree (trying to emulate what might be good practice, and ensure that ray tracing support works together with other Slang mechanisms).
* Typo fix: assocaited->associated
One instance was found in review, but I went ahead and fixed a bunch since I seem to make this typo a lot.
* Typo fix: defintiion->definition
Diffstat (limited to 'source/slang/emit.cpp')
| -rw-r--r-- | source/slang/emit.cpp | 47 |
1 files changed, 46 insertions, 1 deletions
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 "); |
