yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
3dc466487
master
Shader Execution Reordering (SER)
Slang provides preliminary support for Shader Execution Reordering (SER). The API hasn't been finalized and may change in the future.
The feature is available on D3D12 via NVAPI and on Vulkan through the GL_NV_shader_invocation_reorder extension.
Vulkan
SER as implemented on Vulkan has extra limitations on usage. On D3D via NvAPI HitObject variables are like regular variables. They can be assigned, passed to functions and so forth. Using GL_NV_shader_invocation_reorder on Vulkan, this isn't the case and HitObject variables are special and act is if their introduction allocates a single unique entry. One implication of this is there are limitations on Vulkan around HitObject with flow control, and assignment to HitObject variables.
TODO: Examples and discussion around these limitation.
Links
Preliminary API
The API is preliminary and based on the NvAPI SER interface. It may change with future Slang versions.
Free Functions
struct HitObject
Description
Immutable data type representing a ray hit or a miss. Can be used to invoke hit or miss shading, or as a key in ReorderThread. Created by one of several methods described below. HitObject and its related functions are available in raytracing shader types only.
Methods
- TraceRay
- TraceMotionRay
- MakeMiss
- MakeHit
- MakeMotionHit
- MakeMotionMiss
- MakeNop
- Invoke
- IsMiss
- IsHit
- IsNop
- GetRayDesc
- GetShaderTableIndex
- SetShaderTableIndex
- GetInstanceIndex
- GetInstanceID
- GetGeometryIndex
- GetPrimitiveIndex
- GetHitKind
- GetAttributes
- GetWorldToObject
- GetObjectToWorld
- GetCurrentTime
- GetObjectRayOrigin
- GetObjectRayDirection
- GetShaderRecordBufferHandle
- GetClusterID
- GetSpherePositionAndRadius
- GetLssPositionsAndRadii
- IsSphereHit
- IsLssHit
- LoadLocalRootTableConstant
<a id="trace-ray"></a>
HitObject.TraceRay
Description
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.
Signature
static HitObject HitObject.TraceRay<payload_t>(
RaytracingAccelerationStructure AccelerationStructure,
uint RayFlags,
uint InstanceInclusionMask,
uint RayContributionToHitGroupIndex,
uint MultiplierForGeometryContributionToHitGroupIndex,
uint MissShaderIndex,
RayDesc Ray,
inout payload_t Payload);
<a id="trace-motion-ray"></a>
HitObject.TraceMotionRay
Description
Executes motion 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.
Signature
static HitObject HitObject.TraceMotionRay<payload_t>(
RaytracingAccelerationStructure AccelerationStructure,
uint RayFlags,
uint InstanceInclusionMask,
uint RayContributionToHitGroupIndex,
uint MultiplierForGeometryContributionToHitGroupIndex,
uint MissShaderIndex,
RayDesc Ray,
float CurrentTime,
inout payload_t Payload);
<a id="make-hit"></a>
HitObject.MakeHit
Description
Creates a HitObject representing a hit based on values explicitly passed as arguments, without tracing a ray. The primitive specified by AccelerationStructure, InstanceIndex, GeometryIndex, and PrimitiveIndex must exist. The shader table index is computed using the formula used with 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.
Signature
static HitObject HitObject.MakeHit<attr_t>(
RaytracingAccelerationStructure AccelerationStructure,
uint InstanceIndex,
uint GeometryIndex,
uint PrimitiveIndex,
uint HitKind,
uint RayContributionToHitGroupIndex,
uint MultiplierForGeometryContributionToHitGroupIndex,
RayDesc Ray,
attr_t attributes);
static HitObject HitObject.MakeHit<attr_t>(
uint HitGroupRecordIndex,
RaytracingAccelerationStructure AccelerationStructure,
uint InstanceIndex,
uint GeometryIndex,
uint PrimitiveIndex,
uint HitKind,
RayDesc Ray,
attr_t attributes);
<a id="make-motion-hit"></a>
HitObject.MakeMotionHit
Description
See MakeHit but handles Motion Currently only supported on VK
Signature
static HitObject HitObject.MakeMotionHit<attr_t>(
RaytracingAccelerationStructure AccelerationStructure,
uint InstanceIndex,
uint GeometryIndex,
uint PrimitiveIndex,
uint HitKind,
uint RayContributionToHitGroupIndex,
uint MultiplierForGeometryContributionToHitGroupIndex,
RayDesc Ray,
float CurrentTime,
attr_t attributes);
static HitObject HitObject.MakeMotionHit<attr_t>(
uint HitGroupRecordIndex,
RaytracingAccelerationStructure AccelerationStructure,
uint InstanceIndex,
uint GeometryIndex,
uint PrimitiveIndex,
uint HitKind,
RayDesc Ray,
float CurrentTime,
attr_t attributes);
<a id="make-miss"></a>
HitObject.MakeMiss
Description
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 table.
Signature
static HitObject HitObject.MakeMiss(
uint MissShaderIndex,
RayDesc Ray);
<a id="make-motion-miss"></a>
HitObject.MakeMotionMiss
Description
See MakeMiss but handles Motion Currently only supported on VK
Signature
static HitObject HitObject.MakeMotionMiss(
uint MissShaderIndex,
RayDesc Ray,
float CurrentTime);
<a id="make-nop"></a>
HitObject.MakeNop
Description
Creates a HitObject representing “NOP” (no operation) which is neither a hit nor a miss. Invoking a NOP hit object using HitObject::Invoke has no effect. Reordering by hit objects using ReorderThread will group NOP hit objects together. This can be useful in some reordering scenarios where future control flow for some threads is known to process neither a hit nor a miss.
Signature
static HitObject HitObject.MakeNop();
<a id="invoke"></a>
HitObject.Invoke
Description
Invokes closesthit or miss shading for the specified hit object. In case of a NOP HitObject, no shader is invoked.
Signature
static void HitObject.Invoke<payload_t>(
RaytracingAccelerationStructure AccelerationStructure,
HitObject HitOrMiss,
inout payload_t Payload);
<a id="is-miss"></a>
HitObject.IsMiss
Description
Returns true if the HitObject encodes a miss, otherwise returns false.
Signature
bool HitObject.IsMiss();
<a id="is-hit"></a>
HitObject.IsHit
Description
Returns true if the HitObject encodes a hit, otherwise returns false.
Signature
bool HitObject.IsHit();
<a id="is-nop"></a>
HitObject.IsNop
Description
Returns true if the HitObject encodes a nop, otherwise returns false.
Signature
bool HitObject.IsNop();
<a id="get-ray-desc"></a>
HitObject.GetRayDesc
Description
Queries ray properties from HitObject. Valid if the hit object represents a hit or a miss.
Signature
RayDesc HitObject.GetRayDesc();
<a id="get-shader-table-index"></a>
HitObject.GetShaderTableIndex
Description
Queries shader table index from HitObject. Valid if the hit object represents a hit or a miss.
Signature
uint HitObject.GetShaderTableIndex();
<a id="get-instance-index"></a>
HitObject.GetInstanceIndex
Description
Returns the instance index of a hit. Valid if the hit object represents a hit.
Signature
uint HitObject.GetInstanceIndex();
<a id="get-instance-id"></a>
HitObject.GetInstanceID
Description
Returns the instance ID of a hit. Valid if the hit object represents a hit.
Signature
uint HitObject.GetInstanceID();
<a id="get-geometry-index"></a>
HitObject.GetGeometryIndex
Description
Returns the geometry index of a hit. Valid if the hit object represents a hit.
Signature
uint HitObject.GetGeometryIndex();
<a id="get-primitive-index"></a>
HitObject.GetPrimitiveIndex
Description
Returns the primitive index of a hit. Valid if the hit object represents a hit.
Signature
uint HitObject.GetPrimitiveIndex();
<a id="get-hit-kind"></a>
HitObject.GetHitKind
Description
Returns the hit kind. Valid if the hit object represents a hit.
Signature
uint HitObject.GetHitKind();
<a id="get-attributes"></a>
HitObject.GetAttributes
Description
Returns the attributes of a hit. Valid if the hit object represents a hit or a miss.
Signature
attr_t HitObject.GetAttributes<attr_t>();
<a id="load-local-root-table-constant"></a>
HitObject.LoadLocalRootTableConstant
Description
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.
Signature
uint HitObject.LoadLocalRootTableConstant(uint RootConstantOffsetInBytes);
<a id="set-shader-table-index"></a>
HitObject.SetShaderTableIndex
Description
Sets the shader table index of the hit object. Used to modify which shader gets invoked during HitObject.Invoke.
Signature
uint HitObject.SetShaderTableIndex(uint RecordIndex);
<a id="get-world-to-object"></a>
HitObject.GetWorldToObject
Description
Returns the world-to-object transformation matrix. Valid if the hit object represents a hit.
Signature
float4x3 HitObject.GetWorldToObject();
<a id="get-object-to-world"></a>
HitObject.GetObjectToWorld
Description
Returns the object-to-world transformation matrix. Valid if the hit object represents a hit.
Signature
float4x3 HitObject.GetObjectToWorld();
<a id="get-current-time"></a>
HitObject.GetCurrentTime
Description
Returns the current time for motion blur. Valid if the hit object represents a motion hit or miss.
Signature
float HitObject.GetCurrentTime();
<a id="get-object-ray-origin"></a>
HitObject.GetObjectRayOrigin
Description
Returns the ray origin in object space. Valid if the hit object represents a hit.
Signature
float3 HitObject.GetObjectRayOrigin();
<a id="get-object-ray-direction"></a>
HitObject.GetObjectRayDirection
Description
Returns the ray direction in object space. Valid if the hit object represents a hit.
Signature
float3 HitObject.GetObjectRayDirection();
<a id="get-shader-record-buffer-handle"></a>
HitObject.GetShaderRecordBufferHandle
Description
Returns the shader record buffer handle. Valid if the hit object represents a hit or a miss.
Signature
uint2 HitObject.GetShaderRecordBufferHandle();
<a id="get-cluster-id"></a>
HitObject.GetClusterID
Description
Returns the cluster ID for cluster acceleration structures. Valid if the hit object represents a hit.
Signature
int HitObject.GetClusterID();
<a id="get-sphere-position-and-radius"></a>
HitObject.GetSpherePositionAndRadius
Description
Returns the position and radius of a sphere primitive. Valid if the hit object represents a sphere hit.
Signature
float4 HitObject.GetSpherePositionAndRadius();
<a id="get-lss-positions-and-radii"></a>
HitObject.GetLssPositionsAndRadii
Description
Returns the positions and radii of a linear swept sphere primitive. Valid if the hit object represents an LSS hit.
Signature
float2x4 HitObject.GetLssPositionsAndRadii();
<a id="is-sphere-hit"></a>
HitObject.IsSphereHit
Description
Returns true if the HitObject represents a hit on a sphere primitive, otherwise returns false.
Signature
bool HitObject.IsSphereHit();
<a id="is-lss-hit"></a>
HitObject.IsLssHit
Description
Returns true if the HitObject represents a hit on a linear swept sphere primitive, otherwise returns false.
Signature
bool HitObject.IsLssHit();
<a id="reorder-thread"></a>
ReorderThread
Description
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). Applications should set this to the lowest value required to represent all possible values in CoherenceHint. For best performance, all threads should provide the same value for NumCoherenceHintBits. Where possible, reordering will also attempt to retain locality in the thread’s launch indices (DispatchRaysIndex in DXR).
ReorderThread(HitOrMiss) is equivalent to
void ReorderThread( HitObject HitOrMiss, uint CoherenceHint, uint NumCoherenceHintBitsFromLSB );
With CoherenceHint and NumCoherenceHintBitsFromLSB as 0, meaning they are ignored.
Signature
void ReorderThread(
uint CoherenceHint,
uint NumCoherenceHintBitsFromLSB);
void ReorderThread(
HitObject HitOrMiss,
uint CoherenceHint,
uint NumCoherenceHintBitsFromLSB);
void ReorderThread(HitObject HitOrMiss);
1Shader Execution Reordering (SER) 2================================= 3 4Slang provides preliminary support for Shader Execution Reordering (SER). The API hasn't been finalized and may change in the future. 5 6The feature is available on D3D12 via [NVAPI](nvapi-support.md) and on Vulkan through the [GL_NV_shader_invocation_reorder](https://github.com/KhronosGroup/GLSL/blob/master/extensions/nv/GLSL_NV_shader_invocation_reorder.txt) extension. 7 8## Vulkan 9 10SER as implemented on Vulkan has extra limitations on usage. On D3D via NvAPI `HitObject` variables are like regular variables. They can be assigned, passed to functions and so forth. Using `GL_NV_shader_invocation_reorder` on Vulkan, this isn't the case and `HitObject` variables are special and act is if their introduction allocates a single unique entry. One implication of this is there are limitations on Vulkan around HitObject with flow control, and assignment to HitObject variables. 11 12TODO: Examples and discussion around these limitation. 13 14## Links 15 16* [SER white paper for NVAPI](https://developer.nvidia.com/sites/default/files/akamai/gameworks/ser-whitepaper.pdf) 17 18# Preliminary API 19 20The API is preliminary and based on the NvAPI SER interface. It may change with future Slang versions. 21 22## Free Functions 23 24* [ReorderThread](#reorder-thread) 25 26-------------------------------------------------------------------------------- 27# `struct HitObject` 28 29## Description 30 31Immutable data type representing a ray hit or a miss. Can be used to invoke hit or miss shading, 32or as a key in ReorderThread. Created by one of several methods described below. HitObject 33and its related functions are available in raytracing shader types only. 34 35## Methods 36 37* [TraceRay](#trace-ray) 38* [TraceMotionRay](#trace-motion-ray) 39* [MakeMiss](#make-miss) 40* [MakeHit](#make-hit) 41* [MakeMotionHit](#make-motion-hit) 42* [MakeMotionMiss](#make-motion-miss) 43* [MakeNop](#make-nop) 44* [Invoke](#invoke) 45* [IsMiss](#is-miss) 46* [IsHit](#is-hit) 47* [IsNop](#is-nop) 48* [GetRayDesc](#get-ray-desc) 49* [GetShaderTableIndex](#get-shader-table-index) 50* [SetShaderTableIndex](#set-shader-table-index) 51* [GetInstanceIndex](#get-instance-index) 52* [GetInstanceID](#get-instance-id) 53* [GetGeometryIndex](#get-geometry-index) 54* [GetPrimitiveIndex](#get-primitive-index) 55* [GetHitKind](#get-hit-kind) 56* [GetAttributes](#get-attributes) 57* [GetWorldToObject](#get-world-to-object) 58* [GetObjectToWorld](#get-object-to-world) 59* [GetCurrentTime](#get-current-time) 60* [GetObjectRayOrigin](#get-object-ray-origin) 61* [GetObjectRayDirection](#get-object-ray-direction) 62* [GetShaderRecordBufferHandle](#get-shader-record-buffer-handle) 63* [GetClusterID](#get-cluster-id) 64* [GetSpherePositionAndRadius](#get-sphere-position-and-radius) 65* [GetLssPositionsAndRadii](#get-lss-positions-and-radii) 66* [IsSphereHit](#is-sphere-hit) 67* [IsLssHit](#is-lss-hit) 68* [LoadLocalRootTableConstant](#load-local-root-table-constant) 69 70-------------------------------------------------------------------------------- 71<a id="trace-ray"></a> 72# `HitObject.TraceRay` 73 74## Description 75 76Executes ray traversal (including anyhit and intersection shaders) like TraceRay, but returns the 77resulting hit information as a HitObject and does not trigger closesthit or miss shaders. 78 79## Signature 80 81 ``` 82static HitObject HitObject.TraceRay<payload_t>( 83RaytracingAccelerationStructure AccelerationStructure, 84uint RayFlags, 85uint InstanceInclusionMask, 86uint RayContributionToHitGroupIndex, 87uint MultiplierForGeometryContributionToHitGroupIndex, 88uint MissShaderIndex, 89RayDesc Ray, 90inout payload_t Payload); 91``` 92 93-------------------------------------------------------------------------------- 94<a id="trace-motion-ray"></a> 95# `HitObject.TraceMotionRay` 96 97## Description 98 99Executes motion ray traversal (including anyhit and intersection shaders) like TraceRay, but returns the 100resulting hit information as a HitObject and does not trigger closesthit or miss shaders. 101 102## Signature 103 104 ``` 105static HitObject HitObject.TraceMotionRay<payload_t>( 106RaytracingAccelerationStructure AccelerationStructure, 107uint RayFlags, 108uint InstanceInclusionMask, 109uint RayContributionToHitGroupIndex, 110uint MultiplierForGeometryContributionToHitGroupIndex, 111uint MissShaderIndex, 112RayDesc Ray, 113float CurrentTime, 114inout payload_t Payload); 115``` 116 117 118-------------------------------------------------------------------------------- 119<a id="make-hit"></a> 120# `HitObject.MakeHit` 121 122## Description 123 124Creates a HitObject representing a hit based on values explicitly passed as arguments, without 125tracing a ray. The primitive specified by AccelerationStructure, InstanceIndex, GeometryIndex, 126and PrimitiveIndex must exist. The shader table index is computed using the formula used with 127TraceRay. The computed index must reference a valid hit group record in the shader table. The 128Attributes parameter must either be an attribute struct, such as 129BuiltInTriangleIntersectionAttributes, or another HitObject to copy the attributes from. 130 131## Signature 132 133 ``` 134static HitObject HitObject.MakeHit<attr_t>( 135RaytracingAccelerationStructure AccelerationStructure, 136uint InstanceIndex, 137uint GeometryIndex, 138uint PrimitiveIndex, 139uint HitKind, 140uint RayContributionToHitGroupIndex, 141uint MultiplierForGeometryContributionToHitGroupIndex, 142RayDesc Ray, 143attr_t attributes); 144static HitObject HitObject.MakeHit<attr_t>( 145uint HitGroupRecordIndex, 146RaytracingAccelerationStructure AccelerationStructure, 147uint InstanceIndex, 148uint GeometryIndex, 149uint PrimitiveIndex, 150uint HitKind, 151RayDesc Ray, 152attr_t attributes); 153``` 154 155-------------------------------------------------------------------------------- 156<a id="make-motion-hit"></a> 157# `HitObject.MakeMotionHit` 158 159## Description 160 161See MakeHit but handles Motion 162Currently only supported on VK 163 164## Signature 165 166 ``` 167static HitObject HitObject.MakeMotionHit<attr_t>( 168RaytracingAccelerationStructure AccelerationStructure, 169uint InstanceIndex, 170uint GeometryIndex, 171uint PrimitiveIndex, 172uint HitKind, 173uint RayContributionToHitGroupIndex, 174uint MultiplierForGeometryContributionToHitGroupIndex, 175RayDesc Ray, 176float CurrentTime, 177attr_t attributes); 178static HitObject HitObject.MakeMotionHit<attr_t>( 179uint HitGroupRecordIndex, 180RaytracingAccelerationStructure AccelerationStructure, 181uint InstanceIndex, 182uint GeometryIndex, 183uint PrimitiveIndex, 184uint HitKind, 185RayDesc Ray, 186float CurrentTime, 187attr_t attributes); 188``` 189 190-------------------------------------------------------------------------------- 191<a id="make-miss"></a> 192# `HitObject.MakeMiss` 193 194## Description 195 196Creates a HitObject representing a miss based on values explicitly passed as arguments, without 197tracing a ray. The provided shader table index must reference a valid miss record in the shader 198table. 199 200## Signature 201 202 ``` 203static HitObject HitObject.MakeMiss( 204uint MissShaderIndex, 205RayDesc Ray); 206``` 207 208-------------------------------------------------------------------------------- 209<a id="make-motion-miss"></a> 210# `HitObject.MakeMotionMiss` 211 212## Description 213 214See MakeMiss but handles Motion 215Currently only supported on VK 216 217## Signature 218 219 ``` 220static HitObject HitObject.MakeMotionMiss( 221uint MissShaderIndex, 222RayDesc Ray, 223float CurrentTime); 224``` 225 226-------------------------------------------------------------------------------- 227<a id="make-nop"></a> 228# `HitObject.MakeNop` 229 230## Description 231 232Creates a HitObject representing “NOP” (no operation) which is neither a hit nor a miss. Invoking a 233NOP hit object using HitObject::Invoke has no effect. Reordering by hit objects using 234ReorderThread will group NOP hit objects together. This can be useful in some reordering 235scenarios where future control flow for some threads is known to process neither a hit nor a 236miss. 237 238## Signature 239 240 ``` 241static HitObject HitObject.MakeNop(); 242``` 243 244-------------------------------------------------------------------------------- 245<a id="invoke"></a> 246# `HitObject.Invoke` 247 248## Description 249 250Invokes closesthit or miss shading for the specified hit object. In case of a NOP HitObject, no 251shader is invoked. 252 253## Signature 254 255 ``` 256static void HitObject.Invoke<payload_t>( 257RaytracingAccelerationStructure AccelerationStructure, 258HitObject HitOrMiss, 259inout payload_t Payload); 260``` 261 262-------------------------------------------------------------------------------- 263<a id="is-miss"></a> 264# `HitObject.IsMiss` 265 266## Description 267 268Returns true if the HitObject encodes a miss, otherwise returns false. 269 270## Signature 271 272 ``` 273bool HitObject.IsMiss(); 274``` 275 276-------------------------------------------------------------------------------- 277<a id="is-hit"></a> 278# `HitObject.IsHit` 279 280## Description 281 282Returns true if the HitObject encodes a hit, otherwise returns false. 283 284## Signature 285 286 ``` 287bool HitObject.IsHit(); 288``` 289 290-------------------------------------------------------------------------------- 291<a id="is-nop"></a> 292# `HitObject.IsNop` 293 294## Description 295 296Returns true if the HitObject encodes a nop, otherwise returns false. 297 298## Signature 299 300 ``` 301bool HitObject.IsNop(); 302``` 303 304-------------------------------------------------------------------------------- 305<a id="get-ray-desc"></a> 306# `HitObject.GetRayDesc` 307 308## Description 309 310Queries ray properties from HitObject. Valid if the hit object represents a hit or a miss. 311 312## Signature 313 314 ``` 315RayDesc HitObject.GetRayDesc(); 316``` 317 318-------------------------------------------------------------------------------- 319<a id="get-shader-table-index"></a> 320# `HitObject.GetShaderTableIndex` 321 322## Description 323 324Queries shader table index from HitObject. Valid if the hit object represents a hit or a miss. 325 326## Signature 327 328 ``` 329uint HitObject.GetShaderTableIndex(); 330``` 331 332-------------------------------------------------------------------------------- 333<a id="get-instance-index"></a> 334# `HitObject.GetInstanceIndex` 335 336## Description 337 338Returns the instance index of a hit. Valid if the hit object represents a hit. 339 340## Signature 341 342 ``` 343uint HitObject.GetInstanceIndex(); 344``` 345 346-------------------------------------------------------------------------------- 347<a id="get-instance-id"></a> 348# `HitObject.GetInstanceID` 349 350## Description 351 352Returns the instance ID of a hit. Valid if the hit object represents a hit. 353 354## Signature 355 356 ``` 357uint HitObject.GetInstanceID(); 358``` 359 360-------------------------------------------------------------------------------- 361<a id="get-geometry-index"></a> 362# `HitObject.GetGeometryIndex` 363 364## Description 365 366Returns the geometry index of a hit. Valid if the hit object represents a hit. 367 368## Signature 369 370 ``` 371uint HitObject.GetGeometryIndex(); 372``` 373 374-------------------------------------------------------------------------------- 375<a id="get-primitive-index"></a> 376# `HitObject.GetPrimitiveIndex` 377 378## Description 379 380Returns the primitive index of a hit. Valid if the hit object represents a hit. 381 382## Signature 383 384 ``` 385uint HitObject.GetPrimitiveIndex(); 386``` 387 388-------------------------------------------------------------------------------- 389<a id="get-hit-kind"></a> 390# `HitObject.GetHitKind` 391 392## Description 393 394Returns the hit kind. Valid if the hit object represents a hit. 395 396## Signature 397 398 ``` 399uint HitObject.GetHitKind(); 400``` 401 402-------------------------------------------------------------------------------- 403<a id="get-attributes"></a> 404# `HitObject.GetAttributes` 405 406## Description 407 408Returns the attributes of a hit. Valid if the hit object represents a hit or a miss. 409 410## Signature 411 412 ``` 413attr_t HitObject.GetAttributes<attr_t>(); 414``` 415 416-------------------------------------------------------------------------------- 417<a id="load-local-root-table-constant"></a> 418# `HitObject.LoadLocalRootTableConstant` 419 420## Description 421 422Loads a root constant from the local root table referenced by the hit object. Valid if the hit object 423represents a hit or a miss. RootConstantOffsetInBytes must be a multiple of 4. 424 425## Signature 426 427 ``` 428uint HitObject.LoadLocalRootTableConstant(uint RootConstantOffsetInBytes); 429``` 430 431-------------------------------------------------------------------------------- 432<a id="set-shader-table-index"></a> 433# `HitObject.SetShaderTableIndex` 434 435## Description 436 437Sets the shader table index of the hit object. Used to modify which shader gets invoked during HitObject.Invoke. 438 439## Signature 440 441 ``` 442uint HitObject.SetShaderTableIndex(uint RecordIndex); 443``` 444 445-------------------------------------------------------------------------------- 446<a id="get-world-to-object"></a> 447# `HitObject.GetWorldToObject` 448 449## Description 450 451Returns the world-to-object transformation matrix. Valid if the hit object represents a hit. 452 453## Signature 454 455 ``` 456float4x3 HitObject.GetWorldToObject(); 457``` 458 459-------------------------------------------------------------------------------- 460<a id="get-object-to-world"></a> 461# `HitObject.GetObjectToWorld` 462 463## Description 464 465Returns the object-to-world transformation matrix. Valid if the hit object represents a hit. 466 467## Signature 468 469 ``` 470float4x3 HitObject.GetObjectToWorld(); 471``` 472 473-------------------------------------------------------------------------------- 474<a id="get-current-time"></a> 475# `HitObject.GetCurrentTime` 476 477## Description 478 479Returns the current time for motion blur. Valid if the hit object represents a motion hit or miss. 480 481## Signature 482 483 ``` 484float HitObject.GetCurrentTime(); 485``` 486 487-------------------------------------------------------------------------------- 488<a id="get-object-ray-origin"></a> 489# `HitObject.GetObjectRayOrigin` 490 491## Description 492 493Returns the ray origin in object space. Valid if the hit object represents a hit. 494 495## Signature 496 497 ``` 498float3 HitObject.GetObjectRayOrigin(); 499``` 500 501-------------------------------------------------------------------------------- 502<a id="get-object-ray-direction"></a> 503# `HitObject.GetObjectRayDirection` 504 505## Description 506 507Returns the ray direction in object space. Valid if the hit object represents a hit. 508 509## Signature 510 511 ``` 512float3 HitObject.GetObjectRayDirection(); 513``` 514 515-------------------------------------------------------------------------------- 516<a id="get-shader-record-buffer-handle"></a> 517# `HitObject.GetShaderRecordBufferHandle` 518 519## Description 520 521Returns the shader record buffer handle. Valid if the hit object represents a hit or a miss. 522 523## Signature 524 525 ``` 526uint2 HitObject.GetShaderRecordBufferHandle(); 527``` 528 529-------------------------------------------------------------------------------- 530<a id="get-cluster-id"></a> 531# `HitObject.GetClusterID` 532 533## Description 534 535Returns the cluster ID for cluster acceleration structures. Valid if the hit object represents a hit. 536 537## Signature 538 539 ``` 540int HitObject.GetClusterID(); 541``` 542 543-------------------------------------------------------------------------------- 544<a id="get-sphere-position-and-radius"></a> 545# `HitObject.GetSpherePositionAndRadius` 546 547## Description 548 549Returns the position and radius of a sphere primitive. Valid if the hit object represents a sphere hit. 550 551## Signature 552 553 ``` 554float4 HitObject.GetSpherePositionAndRadius(); 555``` 556 557-------------------------------------------------------------------------------- 558<a id="get-lss-positions-and-radii"></a> 559# `HitObject.GetLssPositionsAndRadii` 560 561## Description 562 563Returns the positions and radii of a linear swept sphere primitive. Valid if the hit object represents an LSS hit. 564 565## Signature 566 567 ``` 568float2x4 HitObject.GetLssPositionsAndRadii(); 569``` 570 571-------------------------------------------------------------------------------- 572<a id="is-sphere-hit"></a> 573# `HitObject.IsSphereHit` 574 575## Description 576 577Returns true if the HitObject represents a hit on a sphere primitive, otherwise returns false. 578 579## Signature 580 581 ``` 582bool HitObject.IsSphereHit(); 583``` 584 585-------------------------------------------------------------------------------- 586<a id="is-lss-hit"></a> 587# `HitObject.IsLssHit` 588 589## Description 590 591Returns true if the HitObject represents a hit on a linear swept sphere primitive, otherwise returns false. 592 593## Signature 594 595 ``` 596bool HitObject.IsLssHit(); 597``` 598 599-------------------------------------------------------------------------------- 600<a id="reorder-thread"></a> 601# `ReorderThread` 602 603## Description 604 605Reorders threads based on a coherence hint value. NumCoherenceHintBits indicates how many of 606the least significant bits of CoherenceHint should be considered during reordering (max: 16). 607Applications should set this to the lowest value required to represent all possible values in 608CoherenceHint. For best performance, all threads should provide the same value for 609NumCoherenceHintBits. 610Where possible, reordering will also attempt to retain locality in the thread’s launch indices 611(DispatchRaysIndex in DXR). 612 613`ReorderThread(HitOrMiss)` is equivalent to 614 615``` 616void ReorderThread( HitObject HitOrMiss, uint CoherenceHint, uint NumCoherenceHintBitsFromLSB ); 617``` 618 619With CoherenceHint and NumCoherenceHintBitsFromLSB as 0, meaning they are ignored. 620 621## Signature 622 623 ``` 624void ReorderThread( 625uint CoherenceHint, 626uint NumCoherenceHintBitsFromLSB); 627void ReorderThread( 628HitObject HitOrMiss, 629uint CoherenceHint, 630uint NumCoherenceHintBitsFromLSB); 631void ReorderThread(HitObject HitOrMiss); 632```