Implement the PrimitiveIndex
HLSL Function
#99193
Labels
backend:DirectX
backend:SPIR-V
bot:HLSL
HLSL
HLSL Language Support
metabug
Issue to collect references to a group of similar or related issues.
PrimitiveIndex
clang builtin,PrimitiveIndex
clang builtin withhlsl_intrinsics.h
PrimitiveIndex
toCheckHLSLBuiltinFunctionCall
inSemaChecking.cpp
PrimitiveIndex
toEmitHLSLBuiltinExpr
inCGBuiltin.cpp
clang/test/CodeGenHLSL/builtins/PrimitiveIndex.hlsl
clang/test/SemaHLSL/BuiltIns/PrimitiveIndex-errors.hlsl
int_dx_PrimitiveIndex
intrinsic inIntrinsicsDirectX.td
DXILOpMapping
ofint_dx_PrimitiveIndex
to161
inDXIL.td
PrimitiveIndex.ll
andPrimitiveIndex_errors.ll
tests inllvm/test/CodeGen/DirectX/
int_spv_PrimitiveIndex
intrinsic inIntrinsicsSPIRV.td
PrimitiveIndex
lowering and map it toint_spv_PrimitiveIndex
inSPIRVInstructionSelector::selectIntrinsic
.llvm/test/CodeGen/SPIRV/hlsl-intrinsics/PrimitiveIndex.ll
DirectX
SPIR-V
PrimitiveId
Short Description
PrimitiveId - Primitive ID
Description
PrimitiveId
Decorating a variable with the
PrimitiveId
built-in decoration willmake that variable contain the index of the current primitive.
The index of the first primitive generated by a drawing command is zero,
and the index is incremented after every individual point, line, or
triangle primitive is processed.
For triangles drawn as points or line segments (see Polygon Mode ), the primitive index
is incremented only once, even if multiple points or lines are
eventually drawn.
Variables decorated with
PrimitiveId
are reset to zero between eachinstance drawn.
Restarting a primitive topology using primitive restart has no effect on
the value of variables decorated with
PrimitiveId
.In tessellation control and tessellation evaluation shaders, it will
contain the index of the patch within the current set of rendering
primitives that corresponds to the shader invocation.
In a geometry shader, it will contain the number of primitives presented
as input to the shader since the current set of rendering primitives was
started.
In a fragment shader, it will contain the primitive index written by the
mesh shader if a mesh shader is present, or the primitive index written
by the geometry shader if a geometry shader is present, or with the
value that would have been presented as input to the geometry shader had
it been present.
In an intersection, any-hit, or closest hit shader, it will contain the
index within the geometry of the triangle or bounding box being
processed.
When the
PrimitiveId
decoration is applied to an output variable in the mesh shader or geometry shader, the resulting value is seen through thePrimitiveId
decorated input variable in the fragment shader.The fragment shader using
PrimitiveId
will need to declare either theMeshShadingNV
,MeshShadingEXT
,Geometry
orTessellation
capability to satisfy the requirement SPIR-V has to usePrimitiveId
.Valid Usage
VUID-PrimitiveId-PrimitiveId-04330
The
PrimitiveId
decoration must be used only within theMeshEXT
,MeshNV
,IntersectionKHR
,AnyHitKHR
,ClosestHitKHR
,TessellationControl
,TessellationEvaluation
,Geometry
, orFragment
Execution
Model
VUID-PrimitiveId-Fragment-04331
If pipeline contains both the
Fragment
andGeometry
Execution
Model
and a variable decorated withPrimitiveId
is read from
Fragment
shader, then theGeometry
shadermust write to the output variables decorated with
PrimitiveId
in all execution paths
VUID-PrimitiveId-Fragment-04332
If pipeline contains both the
Fragment
andMeshEXT
orMeshNV
Execution
Model
and a variable decorated withPrimitiveId
is read fromFragment
shader, then theMeshEXT
or
MeshNV
shader must write to the output variables decoratedwith
PrimitiveId
in all execution pathsVUID-PrimitiveId-Fragment-04333
If
Fragment
Execution
Model
contains a variable decoratedwith
PrimitiveId
, then either theMeshShadingEXT
,MeshShadingNV
,Geometry
orTessellation
capabilitymust also be declared
VUID-PrimitiveId-PrimitiveId-04334
The variable decorated with
PrimitiveId
within theTessellationControl
,TessellationEvaluation
,Fragment
,IntersectionKHR
,AnyHitKHR
, orClosestHitKHR
Execution
Model
must be declared using theInput
Storage
Class
VUID-PrimitiveId-PrimitiveId-04335
The variable decorated with
PrimitiveId
within theGeometry
Execution
Model
must be declared using theInput
orOutput
Storage
Class
VUID-PrimitiveId-PrimitiveId-04336
The variable decorated with
PrimitiveId
within theMeshEXT
orMeshNV
Execution
Model
must be declared using theOutput
Storage
Class
VUID-PrimitiveId-PrimitiveId-04337
The variable decorated with
PrimitiveId
must be declared as ascalar 32-bit integer value
VUID-PrimitiveId-PrimitiveId-07040
The variable decorated with
PrimitiveId
within theMeshEXT
Execution
Model
must also be decorated with thePerPrimitiveEXT
decorationTest Case(s)
Example 1
SPIRV Example(s):
Example 2
HLSL:
Retrieves the autogenerated index of the primitive within the geometry inside the bottom-level acceleration structure instance.
Syntax
Remarks
For D3D12_RAYTRACING_GEOMETRY_TYPE_TRIANGLES, this is the triangle index within the geometry object.
For D3D12_RAYTRACING_GEOMETRY_TYPE_PROCEDURAL_PRIMITIVE_AABBS, this is the index into the AABB array defining the geometry object.
This function can be called from the following raytracing shader types:
See also
The text was updated successfully, but these errors were encountered: