diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2022-11-03 14:31:51 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-03 14:31:51 -0400 |
| commit | 9a3a4b08c8817905c2f608549c0e57216f8068c5 (patch) | |
| tree | 4d394a4a071680bc06cd3cfa29c5f705a8594a35 /source | |
| parent | 8f9d58416934cbf850f0f01e5fefbdfe1b02d4d6 (diff) | |
Shader Execution Reordering without HLSL2021 (#2489)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Disable SER tests and enabling HLSL2021 by default.
* Small typos fix.
Improve SER coverage in testing.
* Fix typo.
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/hlsl.meta.slang | 116 | ||||
| -rw-r--r-- | source/slang/slang-emit-hlsl.cpp | 5 |
2 files changed, 108 insertions, 13 deletions
diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index 238739fcd..ec2e6de95 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -5421,6 +5421,7 @@ struct VkSubpassInputMS<T> T SubpassLoad(int sampleIndex); } + /// /// Shader Execution Reordering (SER) /// @@ -5445,8 +5446,7 @@ struct HitObject { /// Executes ray traversal (including anyhit and intersection shaders) like TraceRay, but returns the /// resulting hit information as a HitObject and does not trigger closesthit or miss shaders. - __target_intrinsic(hlsl, "NvTraceRayHitObject") - [__requiresNVAPI] + __specialized_for_target(hlsl) static HitObject TraceRay<payload_t>( RaytracingAccelerationStructure AccelerationStructure, uint RayFlags, @@ -5455,7 +5455,21 @@ struct HitObject uint MultiplierForGeometryContributionToHitGroupIndex, uint MissShaderIndex, RayDesc Ray, - inout payload_t Payload); + inout payload_t Payload) + { + HitObject hitObj; + __traceRay( + AccelerationStructure, + RayFlags, + InstanceInclusionMask, + RayContributionToHitGroupIndex, + MultiplierForGeometryContributionToHitGroupIndex, + MissShaderIndex, + Ray, + Payload, + hitObj); + return hitObj; + } /// Creates a HitObject representing a hit based on values explicitly passed as arguments, without /// tracing a ray. The primitive specified by AccelerationStructure, InstanceIndex, GeometryIndex, @@ -5463,8 +5477,7 @@ struct HitObject /// TraceRay. The computed index must reference a valid hit group record in the shader table. The /// Attributes parameter must either be an attribute struct, such as /// BuiltInTriangleIntersectionAttributes, or another HitObject to copy the attributes from. - __target_intrinsic(hlsl, "NvMakeHit") - [__requiresNVAPI] + __specialized_for_target(hlsl) static HitObject MakeHit<attr_t>( RaytracingAccelerationStructure AccelerationStructure, uint InstanceIndex, @@ -5474,7 +5487,22 @@ struct HitObject uint RayContributionToHitGroupIndex, uint MultiplierForGeometryContributionToHitGroupIndex, RayDesc Ray, - attr_t attributes); + attr_t attributes) + { + HitObject hitObj; + __makeHit( + AccelerationStructure, + InstanceIndex, + GeometryIndex, + PrimitiveIndex, + HitKind, + RayContributionToHitGroupIndex, + MultiplierForGeometryContributionToHitGroupIndex, + Ray, + attributes, + hitObj); + return hitObj; + } /// Creates a HitObject representing a hit based on values explicitly passed as arguments, without /// tracing a ray. The primitive specified by AccelerationStructure, InstanceIndex, GeometryIndex, @@ -5483,8 +5511,7 @@ struct HitObject /// reference a valid hit group record in the shader table. The Attributes parameter must either be an /// attribute struct, such as BuiltInTriangleIntersectionAttributes, or another HitObject to copy the /// attributes from. - __target_intrinsic(hlsl, "NvMakeHitWithRecordIndex") - [__requiresNVAPI] + __specialized_for_target(hlsl) static HitObject MakeHit<attr_t>( uint HitGroupRecordIndex, RaytracingAccelerationStructure AccelerationStructure, @@ -5493,7 +5520,21 @@ struct HitObject uint PrimitiveIndex, uint HitKind, RayDesc Ray, - attr_t attributes); + attr_t attributes) + { + HitObject hitObj; + __makeHitWithRecordIndex( + HitGroupRecordIndex, + AccelerationStructure, + InstanceIndex, + GeometryIndex, + PrimitiveIndex, + HitKind, + Ray, + attributes, + hitObj); + return hitObj; + } /// Creates a HitObject representing a miss based on values explicitly passed as arguments, without /// tracing a ray. The provided shader table index must reference a valid miss record in the shader @@ -5573,17 +5614,66 @@ struct HitObject uint GetHitKind(); /// Returns the attributes of a hit. Valid if the hit object represents a hit or a miss. - __target_intrinsic(hlsl, "$0.GetAttributes<$G0>()") - [__requiresNVAPI] - attr_t GetAttributes<attr_t>(); + __specialized_for_target(hlsl) + attr_t GetAttributes<attr_t>() + { + attr_t v; + __getAttributesFromHitObject(v); + return v; + } /// Loads a root constant from the local root table referenced by the hit object. Valid if the hit object /// represents a hit or a miss. RootConstantOffsetInBytes must be a multiple of 4. __target_intrinsic(hlsl) [__requiresNVAPI] uint LoadLocalRootTableConstant(uint RootConstantOffsetInBytes); -}; + /// + /// !!!! Internal impl. Do not use! + /// + + __target_intrinsic(hlsl, "NvGetAttributesFromHitObject($0, $1)") + [__requiresNVAPI] + void __getAttributesFromHitObject<T>(out T t); + + __target_intrinsic(hlsl, "NvMakeHitWithRecordIndex") + [__requiresNVAPI] + static void __makeHitWithRecordIndex<attr_t>(uint HitGroupRecordIndex, + RaytracingAccelerationStructure AccelerationStructure, + uint InstanceIndex, + uint GeometryIndex, + uint PrimitiveIndex, + uint HitKind, + RayDesc Ray, + attr_t attributes, + out HitObject hitObj); + + __target_intrinsic(hlsl, "NvMakeHit") + [__requiresNVAPI] + static void __makeHit<attr_t>(RaytracingAccelerationStructure AccelerationStructure, + uint InstanceIndex, + uint GeometryIndex, + uint PrimitiveIndex, + uint HitKind, + uint RayContributionToHitGroupIndex, + uint MultiplierForGeometryContributionToHitGroupIndex, + RayDesc Ray, + attr_t attributes, + out HitObject hitObj); + + __target_intrinsic(hlsl, "NvTraceRayHitObject") + [__requiresNVAPI] + static void __traceRay<payload_t>( + RaytracingAccelerationStructure AccelerationStructure, + uint RayFlags, + uint InstanceInclusionMask, + uint RayContributionToHitGroupIndex, + uint MultiplierForGeometryContributionToHitGroupIndex, + uint MissShaderIndex, + RayDesc Ray, + inout payload_t Payload, + out HitObject hitObj); +}; /// Reorders threads based on a coherence hint value. NumCoherenceHintBits indicates how many of /// the least significant bits of CoherenceHint should be considered during reordering (max: 16). diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp index 93b501ae0..187115232 100644 --- a/source/slang/slang-emit-hlsl.cpp +++ b/source/slang/slang-emit-hlsl.cpp @@ -1153,6 +1153,11 @@ void HLSLSourceEmitter::emitFrontMatterImpl(TargetRequest* targetReq) // m_writer->emit("#define SLANG_HLSL_ENABLE_NVAPI 1\n"); + // TODO(JS): For now when using NVAPI for generated code we do not want to + // use HLSL2021 features, that are typically used for Shader Execution Reordering + // so we turn on the 'macro' based interface by default + m_writer->emit(toSlice("#define NV_HITOBJECT_USE_MACRO_API 1\n")); + // In addition, if the user has informed the Slang compiler of // the register/space that it wants to use for NVAPI, then we // need to pass along that information to prelude in the |
