Browse Source

Merged PR 86: Finalize OpCode changes for Dxil 1.3 / SM 6.3

Finalize OpCode changes for Dxil 1.3 / SM 6.3

- Rename CreateHandleFromResourceStructForLib to CreateHandleForLib
- Add PrimitiveIndex
- Add final NumOp[Codes|Classes]_Dxil_1_3 values
- Fix legal shader stage set for PrimitiveID
Tex Riddell 7 years ago
parent
commit
d37f956c70

+ 166 - 165
docs/DXIL.rst

@@ -2083,171 +2083,172 @@ Opcodes are defined on a dense range and will be provided as enum in a header fi
 .. <py::lines('OPCODES-RST')>hctdb_instrhelp.get_opcodes_rst()</py>
 .. OPCODES-RST:BEGIN
 
-=== ==================================== =======================================================================================================================================================================================================================
-ID  Name                                 Description
-=== ==================================== =======================================================================================================================================================================================================================
-0   TempRegLoad_                         Helper load operation
-1   TempRegStore_                        Helper store operation
-2   MinPrecXRegLoad_                     Helper load operation for minprecision
-3   MinPrecXRegStore_                    Helper store operation for minprecision
-4   LoadInput_                           Loads the value from shader input
-5   StoreOutput_                         Stores the value to shader output
-6   FAbs_                                returns the absolute value of the input value.
-7   Saturate_                            clamps the result of a single or double precision floating point value to [0.0f...1.0f]
-8   IsNaN_                               Returns true if x is NAN or QNAN, false otherwise.
-9   IsInf_                               Returns true if x is +INF or -INF, false otherwise.
-10  IsFinite_                            Returns true if x is finite, false otherwise.
-11  IsNormal_                            returns IsNormal
-12  Cos_                                 returns cosine(theta) for theta in radians.
-13  Sin_                                 returns sine(theta) for theta in radians.
-14  Tan_                                 returns tan(theta) for theta in radians.
-15  Acos_                                Returns the arccosine of the specified value. Input should be a floating-point value within the range of -1 to 1.
-16  Asin_                                Returns the arccosine of the specified value. Input should be a floating-point value within the range of -1 to 1
-17  Atan_                                Returns the arctangent of the specified value. The return value is within the range of -PI/2 to PI/2.
-18  Hcos_                                returns the hyperbolic cosine of the specified value.
-19  Hsin_                                returns the hyperbolic sine of the specified value.
-20  Htan_                                returns the hyperbolic tangent of the specified value.
-21  Exp_                                 returns 2^exponent
-22  Frc_                                 extract fracitonal component.
-23  Log_                                 returns log base 2.
-24  Sqrt_                                returns square root
-25  Rsqrt_                               returns reciprocal square root (1 / sqrt(src)
-26  Round_ne_                            floating-point round to integral float.
-27  Round_ni_                            floating-point round to integral float.
-28  Round_pi_                            floating-point round to integral float.
-29  Round_z_                             floating-point round to integral float.
-30  Bfrev_                               Reverses the order of the bits.
-31  Countbits_                           Counts the number of bits in the input integer.
-32  FirstbitLo_                          Returns the location of the first set bit starting from the lowest order bit and working upward.
-33  FirstbitHi_                          Returns the location of the first set bit starting from the highest order bit and working downward.
-34  FirstbitSHi_                         Returns the location of the first set bit from the highest order bit based on the sign.
-35  FMax_                                returns a if a >= b, else b
-36  FMin_                                returns a if a < b, else b
-37  IMax_                                IMax(a,b) returns a if a > b, else b
-38  IMin_                                IMin(a,b) returns a if a < b, else b
-39  UMax_                                unsigned integer maximum. UMax(a,b) = a > b ? a : b
-40  UMin_                                unsigned integer minimum. UMin(a,b) = a < b ? a : b
-41  IMul_                                multiply of 32-bit operands to produce the correct full 64-bit result.
-42  UMul_                                multiply of 32-bit operands to produce the correct full 64-bit result.
-43  UDiv_                                unsigned divide of the 32-bit operand src0 by the 32-bit operand src1.
-44  UAddc_                               unsigned add of 32-bit operand with the carry
-45  USubb_                               unsigned subtract of 32-bit operands with the borrow
-46  FMad_                                floating point multiply & add
-47  Fma_                                 fused multiply-add
-48  IMad_                                Signed integer multiply & add
-49  UMad_                                Unsigned integer multiply & add
-50  Msad_                                masked Sum of Absolute Differences.
-51  Ibfe_                                Integer bitfield extract
-52  Ubfe_                                Unsigned integer bitfield extract
-53  Bfi_                                 Given a bit range from the LSB of a number, places that number of bits in another number at any offset
-54  Dot2_                                Two-dimensional vector dot-product
-55  Dot3_                                Three-dimensional vector dot-product
-56  Dot4_                                Four-dimensional vector dot-product
-57  CreateHandle                         creates the handle to a resource
-58  CBufferLoad                          loads a value from a constant buffer resource
-59  CBufferLoadLegacy                    loads a value from a constant buffer resource
-60  Sample                               samples a texture
-61  SampleBias                           samples a texture after applying the input bias to the mipmap level
-62  SampleLevel                          samples a texture using a mipmap-level offset
-63  SampleGrad                           samples a texture using a gradient to influence the way the sample location is calculated
-64  SampleCmp                            samples a texture and compares a single component against the specified comparison value
-65  SampleCmpLevelZero                   samples a texture and compares a single component against the specified comparison value
-66  TextureLoad                          reads texel data without any filtering or sampling
-67  TextureStore                         reads texel data without any filtering or sampling
-68  BufferLoad                           reads from a TypedBuffer
-69  BufferStore                          writes to a RWTypedBuffer
-70  BufferUpdateCounter                  atomically increments/decrements the hidden 32-bit counter stored with a Count or Append UAV
-71  CheckAccessFullyMapped               determines whether all values from a Sample, Gather, or Load operation accessed mapped tiles in a tiled resource
-72  GetDimensions                        gets texture size information
-73  TextureGather                        gathers the four texels that would be used in a bi-linear filtering operation
-74  TextureGatherCmp                     same as TextureGather, except this instrution performs comparison on texels, similar to SampleCmp
-75  Texture2DMSGetSamplePosition         gets the position of the specified sample
-76  RenderTargetGetSamplePosition        gets the position of the specified sample
-77  RenderTargetGetSampleCount           gets the number of samples for a render target
-78  AtomicBinOp                          performs an atomic operation on two operands
-79  AtomicCompareExchange                atomic compare and exchange to memory
-80  Barrier                              inserts a memory barrier in the shader
-81  CalculateLOD                         calculates the level of detail
-82  Discard                              discard the current pixel
-83  DerivCoarseX_                        computes the rate of change per stamp in x direction.
-84  DerivCoarseY_                        computes the rate of change per stamp in y direction.
-85  DerivFineX_                          computes the rate of change per pixel in x direction.
-86  DerivFineY_                          computes the rate of change per pixel in y direction.
-87  EvalSnapped                          evaluates an input attribute at pixel center with an offset
-88  EvalSampleIndex                      evaluates an input attribute at a sample location
-89  EvalCentroid                         evaluates an input attribute at pixel center
-90  SampleIndex                          returns the sample index in a sample-frequency pixel shader
-91  Coverage                             returns the coverage mask input in a pixel shader
-92  InnerCoverage                        returns underestimated coverage input from conservative rasterization in a pixel shader
-93  ThreadId                             reads the thread ID
-94  GroupId                              reads the group ID (SV_GroupID)
-95  ThreadIdInGroup                      reads the thread ID within the group (SV_GroupThreadID)
-96  FlattenedThreadIdInGroup             provides a flattened index for a given thread within a given group (SV_GroupIndex)
-97  EmitStream                           emits a vertex to a given stream
-98  CutStream                            completes the current primitive topology at the specified stream
-99  EmitThenCutStream                    equivalent to an EmitStream followed by a CutStream
-100 GSInstanceID                         GSInstanceID
-101 MakeDouble                           creates a double value
-102 SplitDouble                          splits a double into low and high parts
-103 LoadOutputControlPoint               LoadOutputControlPoint
-104 LoadPatchConstant                    LoadPatchConstant
-105 DomainLocation                       DomainLocation
-106 StorePatchConstant                   StorePatchConstant
-107 OutputControlPointID                 OutputControlPointID
-108 PrimitiveID                          PrimitiveID
-109 CycleCounterLegacy                   CycleCounterLegacy
-110 WaveIsFirstLane                      returns 1 for the first lane in the wave
-111 WaveGetLaneIndex                     returns the index of the current lane in the wave
-112 WaveGetLaneCount                     returns the number of lanes in the wave
-113 WaveAnyTrue                          returns 1 if any of the lane evaluates the value to true
-114 WaveAllTrue                          returns 1 if all the lanes evaluate the value to true
-115 WaveActiveAllEqual                   returns 1 if all the lanes have the same value
-116 WaveActiveBallot                     returns a struct with a bit set for each lane where the condition is true
-117 WaveReadLaneAt                       returns the value from the specified lane
-118 WaveReadLaneFirst                    returns the value from the first lane
-119 WaveActiveOp                         returns the result the operation across waves
-120 WaveActiveBit                        returns the result of the operation across all lanes
-121 WavePrefixOp                         returns the result of the operation on prior lanes
-122 QuadReadLaneAt                       reads from a lane in the quad
-123 QuadOp                               returns the result of a quad-level operation
-124 BitcastI16toF16                      bitcast between different sizes
-125 BitcastF16toI16                      bitcast between different sizes
-126 BitcastI32toF32                      bitcast between different sizes
-127 BitcastF32toI32                      bitcast between different sizes
-128 BitcastI64toF64                      bitcast between different sizes
-129 BitcastF64toI64                      bitcast between different sizes
-130 LegacyF32ToF16                       legacy fuction to convert float (f32) to half (f16) (this is not related to min-precision)
-131 LegacyF16ToF32                       legacy fuction to convert half (f16) to float (f32) (this is not related to min-precision)
-132 LegacyDoubleToFloat                  legacy fuction to convert double to float
-133 LegacyDoubleToSInt32                 legacy fuction to convert double to int32
-134 LegacyDoubleToUInt32                 legacy fuction to convert double to uint32
-135 WaveAllBitCount                      returns the count of bits set to 1 across the wave
-136 WavePrefixBitCount                   returns the count of bits set to 1 on prior lanes
-137 AttributeAtVertex_                   returns the values of the attributes at the vertex.
-138 ViewID                               returns the view index
-139 RawBufferLoad                        reads from a raw buffer and structured buffer
-140 RawBufferStore                       writes to a RWByteAddressBuffer or RWStructuredBuffer
-141 InstanceID                           The user-provided InstanceID on the bottom-level acceleration structure instance within the top-level structure
-142 InstanceIndex                        The autogenerated index of the current instance in the top-level structure
-143 HitKind                              Returns the value passed as HitKind in ReportIntersection().  If intersection was reported by fixed-function triangle intersection, HitKind will be one of HIT_KIND_TRIANGLE_FRONT_FACE or HIT_KIND_TRIANGLE_BACK_FACE.
-144 RayFlags                             uint containing the current ray flags.
-145 DispatchRaysIndex                    The current x and y location within the Width and Height
-146 DispatchRaysDimensions               The Width and Height values from the D3D12_DISPATCH_RAYS_DESC structure provided to the originating DispatchRays() call.
-147 WorldRayOrigin                       The world-space origin for the current ray.
-148 WorldRayDirection                    The world-space direction for the current ray.
-149 ObjectRayOrigin                      Object-space origin for the current ray.
-150 ObjectRayDirection                   Object-space direction for the current ray.
-151 ObjectToWorld                        Matrix for transforming from object-space to world-space.
-152 WorldToObject                        Matrix for transforming from world-space to object-space.
-153 RayTMin                              float representing the parametric starting point for the ray.
-154 RayTCurrent                          float representing the current parametric ending point for the ray
-155 IgnoreHit                            Used in an any hit shader to reject an intersection and terminate the shader
-156 AcceptHitAndEndSearch                Used in an any hit shader to abort the ray query and the intersection shader (if any). The current hit is committed and execution passes to the closest hit shader with the closest hit recorded so far
-157 TraceRay                             returns the view index
-158 ReportHit                            returns true if hit was accepted
-159 CallShader                           Call a shader in the callable shader table supplied through the DispatchRays() API
-160 CreateHandleFromResourceStructForLib create resource handle from resource struct for library
-=== ==================================== =======================================================================================================================================================================================================================
+=== ============================= =======================================================================================================================================================================================================================
+ID  Name                          Description
+=== ============================= =======================================================================================================================================================================================================================
+0   TempRegLoad_                  Helper load operation
+1   TempRegStore_                 Helper store operation
+2   MinPrecXRegLoad_              Helper load operation for minprecision
+3   MinPrecXRegStore_             Helper store operation for minprecision
+4   LoadInput_                    Loads the value from shader input
+5   StoreOutput_                  Stores the value to shader output
+6   FAbs_                         returns the absolute value of the input value.
+7   Saturate_                     clamps the result of a single or double precision floating point value to [0.0f...1.0f]
+8   IsNaN_                        Returns true if x is NAN or QNAN, false otherwise.
+9   IsInf_                        Returns true if x is +INF or -INF, false otherwise.
+10  IsFinite_                     Returns true if x is finite, false otherwise.
+11  IsNormal_                     returns IsNormal
+12  Cos_                          returns cosine(theta) for theta in radians.
+13  Sin_                          returns sine(theta) for theta in radians.
+14  Tan_                          returns tan(theta) for theta in radians.
+15  Acos_                         Returns the arccosine of the specified value. Input should be a floating-point value within the range of -1 to 1.
+16  Asin_                         Returns the arccosine of the specified value. Input should be a floating-point value within the range of -1 to 1
+17  Atan_                         Returns the arctangent of the specified value. The return value is within the range of -PI/2 to PI/2.
+18  Hcos_                         returns the hyperbolic cosine of the specified value.
+19  Hsin_                         returns the hyperbolic sine of the specified value.
+20  Htan_                         returns the hyperbolic tangent of the specified value.
+21  Exp_                          returns 2^exponent
+22  Frc_                          extract fracitonal component.
+23  Log_                          returns log base 2.
+24  Sqrt_                         returns square root
+25  Rsqrt_                        returns reciprocal square root (1 / sqrt(src)
+26  Round_ne_                     floating-point round to integral float.
+27  Round_ni_                     floating-point round to integral float.
+28  Round_pi_                     floating-point round to integral float.
+29  Round_z_                      floating-point round to integral float.
+30  Bfrev_                        Reverses the order of the bits.
+31  Countbits_                    Counts the number of bits in the input integer.
+32  FirstbitLo_                   Returns the location of the first set bit starting from the lowest order bit and working upward.
+33  FirstbitHi_                   Returns the location of the first set bit starting from the highest order bit and working downward.
+34  FirstbitSHi_                  Returns the location of the first set bit from the highest order bit based on the sign.
+35  FMax_                         returns a if a >= b, else b
+36  FMin_                         returns a if a < b, else b
+37  IMax_                         IMax(a,b) returns a if a > b, else b
+38  IMin_                         IMin(a,b) returns a if a < b, else b
+39  UMax_                         unsigned integer maximum. UMax(a,b) = a > b ? a : b
+40  UMin_                         unsigned integer minimum. UMin(a,b) = a < b ? a : b
+41  IMul_                         multiply of 32-bit operands to produce the correct full 64-bit result.
+42  UMul_                         multiply of 32-bit operands to produce the correct full 64-bit result.
+43  UDiv_                         unsigned divide of the 32-bit operand src0 by the 32-bit operand src1.
+44  UAddc_                        unsigned add of 32-bit operand with the carry
+45  USubb_                        unsigned subtract of 32-bit operands with the borrow
+46  FMad_                         floating point multiply & add
+47  Fma_                          fused multiply-add
+48  IMad_                         Signed integer multiply & add
+49  UMad_                         Unsigned integer multiply & add
+50  Msad_                         masked Sum of Absolute Differences.
+51  Ibfe_                         Integer bitfield extract
+52  Ubfe_                         Unsigned integer bitfield extract
+53  Bfi_                          Given a bit range from the LSB of a number, places that number of bits in another number at any offset
+54  Dot2_                         Two-dimensional vector dot-product
+55  Dot3_                         Three-dimensional vector dot-product
+56  Dot4_                         Four-dimensional vector dot-product
+57  CreateHandle                  creates the handle to a resource
+58  CBufferLoad                   loads a value from a constant buffer resource
+59  CBufferLoadLegacy             loads a value from a constant buffer resource
+60  Sample                        samples a texture
+61  SampleBias                    samples a texture after applying the input bias to the mipmap level
+62  SampleLevel                   samples a texture using a mipmap-level offset
+63  SampleGrad                    samples a texture using a gradient to influence the way the sample location is calculated
+64  SampleCmp                     samples a texture and compares a single component against the specified comparison value
+65  SampleCmpLevelZero            samples a texture and compares a single component against the specified comparison value
+66  TextureLoad                   reads texel data without any filtering or sampling
+67  TextureStore                  reads texel data without any filtering or sampling
+68  BufferLoad                    reads from a TypedBuffer
+69  BufferStore                   writes to a RWTypedBuffer
+70  BufferUpdateCounter           atomically increments/decrements the hidden 32-bit counter stored with a Count or Append UAV
+71  CheckAccessFullyMapped        determines whether all values from a Sample, Gather, or Load operation accessed mapped tiles in a tiled resource
+72  GetDimensions                 gets texture size information
+73  TextureGather                 gathers the four texels that would be used in a bi-linear filtering operation
+74  TextureGatherCmp              same as TextureGather, except this instrution performs comparison on texels, similar to SampleCmp
+75  Texture2DMSGetSamplePosition  gets the position of the specified sample
+76  RenderTargetGetSamplePosition gets the position of the specified sample
+77  RenderTargetGetSampleCount    gets the number of samples for a render target
+78  AtomicBinOp                   performs an atomic operation on two operands
+79  AtomicCompareExchange         atomic compare and exchange to memory
+80  Barrier                       inserts a memory barrier in the shader
+81  CalculateLOD                  calculates the level of detail
+82  Discard                       discard the current pixel
+83  DerivCoarseX_                 computes the rate of change per stamp in x direction.
+84  DerivCoarseY_                 computes the rate of change per stamp in y direction.
+85  DerivFineX_                   computes the rate of change per pixel in x direction.
+86  DerivFineY_                   computes the rate of change per pixel in y direction.
+87  EvalSnapped                   evaluates an input attribute at pixel center with an offset
+88  EvalSampleIndex               evaluates an input attribute at a sample location
+89  EvalCentroid                  evaluates an input attribute at pixel center
+90  SampleIndex                   returns the sample index in a sample-frequency pixel shader
+91  Coverage                      returns the coverage mask input in a pixel shader
+92  InnerCoverage                 returns underestimated coverage input from conservative rasterization in a pixel shader
+93  ThreadId                      reads the thread ID
+94  GroupId                       reads the group ID (SV_GroupID)
+95  ThreadIdInGroup               reads the thread ID within the group (SV_GroupThreadID)
+96  FlattenedThreadIdInGroup      provides a flattened index for a given thread within a given group (SV_GroupIndex)
+97  EmitStream                    emits a vertex to a given stream
+98  CutStream                     completes the current primitive topology at the specified stream
+99  EmitThenCutStream             equivalent to an EmitStream followed by a CutStream
+100 GSInstanceID                  GSInstanceID
+101 MakeDouble                    creates a double value
+102 SplitDouble                   splits a double into low and high parts
+103 LoadOutputControlPoint        LoadOutputControlPoint
+104 LoadPatchConstant             LoadPatchConstant
+105 DomainLocation                DomainLocation
+106 StorePatchConstant            StorePatchConstant
+107 OutputControlPointID          OutputControlPointID
+108 PrimitiveID                   PrimitiveID
+109 CycleCounterLegacy            CycleCounterLegacy
+110 WaveIsFirstLane               returns 1 for the first lane in the wave
+111 WaveGetLaneIndex              returns the index of the current lane in the wave
+112 WaveGetLaneCount              returns the number of lanes in the wave
+113 WaveAnyTrue                   returns 1 if any of the lane evaluates the value to true
+114 WaveAllTrue                   returns 1 if all the lanes evaluate the value to true
+115 WaveActiveAllEqual            returns 1 if all the lanes have the same value
+116 WaveActiveBallot              returns a struct with a bit set for each lane where the condition is true
+117 WaveReadLaneAt                returns the value from the specified lane
+118 WaveReadLaneFirst             returns the value from the first lane
+119 WaveActiveOp                  returns the result the operation across waves
+120 WaveActiveBit                 returns the result of the operation across all lanes
+121 WavePrefixOp                  returns the result of the operation on prior lanes
+122 QuadReadLaneAt                reads from a lane in the quad
+123 QuadOp                        returns the result of a quad-level operation
+124 BitcastI16toF16               bitcast between different sizes
+125 BitcastF16toI16               bitcast between different sizes
+126 BitcastI32toF32               bitcast between different sizes
+127 BitcastF32toI32               bitcast between different sizes
+128 BitcastI64toF64               bitcast between different sizes
+129 BitcastF64toI64               bitcast between different sizes
+130 LegacyF32ToF16                legacy fuction to convert float (f32) to half (f16) (this is not related to min-precision)
+131 LegacyF16ToF32                legacy fuction to convert half (f16) to float (f32) (this is not related to min-precision)
+132 LegacyDoubleToFloat           legacy fuction to convert double to float
+133 LegacyDoubleToSInt32          legacy fuction to convert double to int32
+134 LegacyDoubleToUInt32          legacy fuction to convert double to uint32
+135 WaveAllBitCount               returns the count of bits set to 1 across the wave
+136 WavePrefixBitCount            returns the count of bits set to 1 on prior lanes
+137 AttributeAtVertex_            returns the values of the attributes at the vertex.
+138 ViewID                        returns the view index
+139 RawBufferLoad                 reads from a raw buffer and structured buffer
+140 RawBufferStore                writes to a RWByteAddressBuffer or RWStructuredBuffer
+141 InstanceID                    The user-provided InstanceID on the bottom-level acceleration structure instance within the top-level structure
+142 InstanceIndex                 The autogenerated index of the current instance in the top-level structure
+143 HitKind                       Returns the value passed as HitKind in ReportIntersection().  If intersection was reported by fixed-function triangle intersection, HitKind will be one of HIT_KIND_TRIANGLE_FRONT_FACE or HIT_KIND_TRIANGLE_BACK_FACE.
+144 RayFlags                      uint containing the current ray flags.
+145 DispatchRaysIndex             The current x and y location within the Width and Height
+146 DispatchRaysDimensions        The Width and Height values from the D3D12_DISPATCH_RAYS_DESC structure provided to the originating DispatchRays() call.
+147 WorldRayOrigin                The world-space origin for the current ray.
+148 WorldRayDirection             The world-space direction for the current ray.
+149 ObjectRayOrigin               Object-space origin for the current ray.
+150 ObjectRayDirection            Object-space direction for the current ray.
+151 ObjectToWorld                 Matrix for transforming from object-space to world-space.
+152 WorldToObject                 Matrix for transforming from world-space to object-space.
+153 RayTMin                       float representing the parametric starting point for the ray.
+154 RayTCurrent                   float representing the current parametric ending point for the ray
+155 IgnoreHit                     Used in an any hit shader to reject an intersection and terminate the shader
+156 AcceptHitAndEndSearch         Used in an any hit shader to abort the ray query and the intersection shader (if any). The current hit is committed and execution passes to the closest hit shader with the closest hit recorded so far
+157 TraceRay                      returns the view index
+158 ReportHit                     returns true if hit was accepted
+159 CallShader                    Call a shader in the callable shader table supplied through the DispatchRays() API
+160 CreateHandleForLib            create resource handle from resource struct for library
+161 PrimitiveIndex                PrimitiveIndex for raytracing shaders
+=== ============================= =======================================================================================================================================================================================================================
 
 
 Acos

+ 15 - 7
include/dxc/HLSL/DxilConstants.h

@@ -360,9 +360,11 @@ namespace DXIL {
   
     // Hull shader
     OutputControlPointID = 107, // OutputControlPointID
-    PrimitiveID = 108, // PrimitiveID
     StorePatchConstant = 106, // StorePatchConstant
   
+    // Hull, Domain and Geometry shaders
+    PrimitiveID = 108, // PrimitiveID
+  
     // Indirect Shader Invocation
     CallShader = 159, // Call a shader in the callable shader table supplied through the DispatchRays() API
     ReportHit = 158, // returns true if hit was accepted
@@ -373,7 +375,7 @@ namespace DXIL {
     LegacyF32ToF16 = 130, // legacy fuction to convert float (f32) to half (f16) (this is not related to min-precision)
   
     // Library create handle from resource struct (like HL intrinsic)
-    CreateHandleFromResourceStructForLib = 160, // create resource handle from resource struct for library
+    CreateHandleForLib = 160, // create resource handle from resource struct for library
   
     // Other
     CycleCounterLegacy = 109, // CycleCounterLegacy
@@ -422,6 +424,7 @@ namespace DXIL {
     // Raytracing object space uint System Values
     InstanceID = 141, // The user-provided InstanceID on the bottom-level acceleration structure instance within the top-level structure
     InstanceIndex = 142, // The autogenerated index of the current instance in the top-level structure
+    PrimitiveIndex = 161, // PrimitiveIndex for raytracing shaders
   
     // Raytracing uint System Values
     RayFlags = 144, // uint containing the current ray flags.
@@ -539,8 +542,9 @@ namespace DXIL {
     NumOpCodes_Dxil_1_0 = 137,
     NumOpCodes_Dxil_1_1 = 139,
     NumOpCodes_Dxil_1_2 = 141,
+    NumOpCodes_Dxil_1_3 = 162,
   
-    NumOpCodes = 161 // exclusive last value of enumeration
+    NumOpCodes = 162 // exclusive last value of enumeration
   };
   // OPCODE-ENUM:END
 
@@ -605,9 +609,11 @@ namespace DXIL {
   
     // Hull shader
     OutputControlPointID,
-    PrimitiveID,
     StorePatchConstant,
   
+    // Hull, Domain and Geometry shaders
+    PrimitiveID,
+  
     // Indirect Shader Invocation
     CallShader,
     ReportHit,
@@ -621,7 +627,7 @@ namespace DXIL {
     LegacyF32ToF16,
   
     // Library create handle from resource struct (like HL intrinsic)
-    CreateHandleFromResourceStructForLib,
+    CreateHandleForLib,
   
     // Other
     CycleCounterLegacy,
@@ -667,6 +673,7 @@ namespace DXIL {
     // Raytracing object space uint System Values
     InstanceID,
     InstanceIndex,
+    PrimitiveIndex,
   
     // Raytracing uint System Values
     RayFlags,
@@ -742,8 +749,9 @@ namespace DXIL {
     NumOpClasses_Dxil_1_0 = 93,
     NumOpClasses_Dxil_1_1 = 95,
     NumOpClasses_Dxil_1_2 = 97,
+    NumOpClasses_Dxil_1_3 = 118,
   
-    NumOpClasses = 117 // exclusive last value of enumeration
+    NumOpClasses = 118 // exclusive last value of enumeration
   };
   // OPCODECLASS-ENUM:END
 
@@ -866,7 +874,7 @@ namespace DXIL {
     const unsigned kCreateHandleIsUniformOpIdx = 4;
 
     // CreateHandleFromResource
-    const unsigned kCreateHandleFromResourceStructForLibResOpIdx = 1;
+    const unsigned kCreateHandleForLibResOpIdx = 1;
 
     // TraceRay
     const unsigned kTraceRayRayDescOpIdx = 7;

+ 21 - 3
include/dxc/HLSL/DxilInstructions.h

@@ -5300,12 +5300,12 @@ struct DxilInst_CallShader {
 };
 
 /// This instruction create resource handle from resource struct for library
-struct DxilInst_CreateHandleFromResourceStructForLib {
+struct DxilInst_CreateHandleForLib {
   llvm::Instruction *Instr;
   // Construction and identification
-  DxilInst_CreateHandleFromResourceStructForLib(llvm::Instruction *pInstr) : Instr(pInstr) {}
+  DxilInst_CreateHandleForLib(llvm::Instruction *pInstr) : Instr(pInstr) {}
   operator bool() const {
-    return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::CreateHandleFromResourceStructForLib);
+    return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::CreateHandleForLib);
   }
   // Validation support
   bool isAllowed() const { return true; }
@@ -5323,5 +5323,23 @@ struct DxilInst_CreateHandleFromResourceStructForLib {
   llvm::Value *get_Resource() const { return Instr->getOperand(1); }
   void set_Resource(llvm::Value *val) { Instr->setOperand(1, val); }
 };
+
+/// This instruction PrimitiveIndex for raytracing shaders
+struct DxilInst_PrimitiveIndex {
+  llvm::Instruction *Instr;
+  // Construction and identification
+  DxilInst_PrimitiveIndex(llvm::Instruction *pInstr) : Instr(pInstr) {}
+  operator bool() const {
+    return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::PrimitiveIndex);
+  }
+  // Validation support
+  bool isAllowed() const { return true; }
+  bool isArgumentListValid() const {
+    if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands()) return false;
+    return true;
+  }
+  // Metadata
+  bool requiresUniformInputs() const { return false; }
+};
 // INSTR-HELPER:END
 } // namespace hlsl

+ 4 - 4
lib/HLSL/DxilCondenseResources.cpp

@@ -624,7 +624,7 @@ void UpdateOperandSelect(Instruction *SelInst, Instruction *Prototype,
 
 void RemovePhiOnResourceImp(Function *F, hlsl::OP *hlslOP) {
   Value *opArg = hlslOP->GetU32Const(
-      (unsigned)DXIL::OpCode::CreateHandleFromResourceStructForLib);
+      (unsigned)DXIL::OpCode::CreateHandleForLib);
 
   // Remove PhiNode createHandle first.
   std::vector<Instruction *> resSelects;
@@ -635,7 +635,7 @@ void RemovePhiOnResourceImp(Function *F, hlsl::OP *hlslOP) {
       continue;
     // must be call inst
     CallInst *CI = cast<CallInst>(user);
-    DxilInst_CreateHandleFromResourceStructForLib createHandle(CI);
+    DxilInst_CreateHandleForLib createHandle(CI);
     Value *res = createHandle.get_Resource();
     if (isa<SelectInst>(res) || isa<PHINode>(res))
       dxilutil::CollectSelect(cast<Instruction>(res), selectSet);
@@ -686,7 +686,7 @@ void DxilLowerCreateHandleForLib::RemovePhiOnResource() {
     if (hlslOP->IsDxilOpFunc(&F)) {
       hlsl::OP::OpCodeClass opClass;
       if (hlslOP->GetOpCodeClass(&F, opClass) &&
-          opClass == DXIL::OpCodeClass::CreateHandleFromResourceStructForLib) {
+          opClass == DXIL::OpCodeClass::CreateHandleForLib) {
         RemovePhiOnResourceImp(&F, hlslOP);
       }
     }
@@ -904,7 +904,7 @@ void ReplaceResourceUserWithHandle(
     LoadInst *Res, Value *handle) {
   for (auto resUser = Res->user_begin(); resUser != Res->user_end();) {
     CallInst *CI = dyn_cast<CallInst>(*(resUser++));
-    DxilInst_CreateHandleFromResourceStructForLib createHandle(CI);
+    DxilInst_CreateHandleForLib createHandle(CI);
     DXASSERT(createHandle, "must be createHandle");
     CI->replaceAllUsesWith(handle);
     CI->eraseFromParent();

+ 5 - 5
lib/HLSL/DxilGenerationPass.cpp

@@ -353,7 +353,7 @@ private:
 namespace {
 void TranslateHLCreateHandle(Function *F, hlsl::OP &hlslOP) {
   Value *opArg = hlslOP.GetU32Const(
-      (unsigned)DXIL::OpCode::CreateHandleFromResourceStructForLib);
+      (unsigned)DXIL::OpCode::CreateHandleForLib);
 
   for (auto U = F->user_begin(); U != F->user_end();) {
     Value *user = *(U++);
@@ -367,7 +367,7 @@ void TranslateHLCreateHandle(Function *F, hlsl::OP &hlslOP) {
     // Res could be ld/phi/select. Will be removed in
     // DxilLowerCreateHandleForLib.
     Function *createHandle = hlslOP.GetOpFunc(
-        DXIL::OpCode::CreateHandleFromResourceStructForLib, res->getType());
+        DXIL::OpCode::CreateHandleForLib, res->getType());
     newHandle = Builder.CreateCall(createHandle, {opArg, res});
 
     CI->replaceAllUsesWith(newHandle);
@@ -620,7 +620,7 @@ void DxilGenerationPass::GenerateDxilCBufferHandles(
     std::unordered_set<Value *> &NonUniformSet) {
   // For CBuffer, handle are mapped to HLCreateHandle.
   OP *hlslOP = m_pHLModule->GetOP();
-  Value *opArg = hlslOP->GetU32Const((unsigned)OP::OpCode::CreateHandleFromResourceStructForLib);
+  Value *opArg = hlslOP->GetU32Const((unsigned)OP::OpCode::CreateHandleForLib);
   LLVMContext &Ctx = hlslOP->GetCtx();
   Value *zeroIdx = hlslOP->GetU32Const(0);
 
@@ -644,7 +644,7 @@ void DxilGenerationPass::GenerateDxilCBufferHandles(
 
     if (CB.GetRangeSize() == 1) {
       Function *createHandle =
-          hlslOP->GetOpFunc(OP::OpCode::CreateHandleFromResourceStructForLib,
+          hlslOP->GetOpFunc(OP::OpCode::CreateHandleForLib,
                             GV->getType()->getElementType());
       for (auto U = GV->user_begin(); U != GV->user_end(); ) {
         // Must HLCreateHandle.
@@ -665,7 +665,7 @@ void DxilGenerationPass::GenerateDxilCBufferHandles(
       Type *EltTy = Ty->getElementType()->getArrayElementType()->getPointerTo(
           Ty->getAddressSpace());
       Function *createHandle = hlslOP->GetOpFunc(
-          OP::OpCode::CreateHandleFromResourceStructForLib, EltTy->getPointerElementType());
+          OP::OpCode::CreateHandleForLib, EltTy->getPointerElementType());
 
       for (auto U = GV->user_begin(); U != GV->user_end();) {
         // Must HLCreateHandle.

+ 14 - 3
lib/HLSL/DxilOperations.cpp

@@ -213,6 +213,8 @@ const OP::OpCodeProperty OP::m_OpCodeProps[(unsigned)OP::OpCode::NumOpCodes] = {
   // Hull shader                                                                                                            void,     h,     f,     d,    i1,    i8,   i16,   i32,   i64,   udt,  obj,  function attribute
   {  OC::StorePatchConstant,      "StorePatchConstant",       OCC::StorePatchConstant,       "storePatchConstant",         false,  true,  true, false, false, false,  true,  true, false, false, false, Attribute::None,     },
   {  OC::OutputControlPointID,    "OutputControlPointID",     OCC::OutputControlPointID,     "outputControlPointID",       false, false, false, false, false, false, false,  true, false, false, false, Attribute::ReadNone, },
+
+  // Hull, Domain and Geometry shaders                                                                                      void,     h,     f,     d,    i1,    i8,   i16,   i32,   i64,   udt,  obj,  function attribute
   {  OC::PrimitiveID,             "PrimitiveID",              OCC::PrimitiveID,              "primitiveID",                false, false, false, false, false, false, false,  true, false, false, false, Attribute::ReadNone, },
 
   // Other                                                                                                                  void,     h,     f,     d,    i1,    i8,   i16,   i32,   i64,   udt,  obj,  function attribute
@@ -305,7 +307,10 @@ const OP::OpCodeProperty OP::m_OpCodeProps[(unsigned)OP::OpCode::NumOpCodes] = {
   {  OC::CallShader,              "CallShader",               OCC::CallShader,               "callShader",                 false, false, false, false, false, false, false, false, false,  true, false, Attribute::None,     },
 
   // Library create handle from resource struct (like HL intrinsic)                                                         void,     h,     f,     d,    i1,    i8,   i16,   i32,   i64,   udt,  obj,  function attribute
-  {  OC::CreateHandleFromResourceStructForLib, "CreateHandleFromResourceStructForLib", OCC::CreateHandleFromResourceStructForLib, "createHandleFromResourceStructForLib",  false, false, false, false, false, false, false, false, false, false,  true, Attribute::ReadOnly, },
+  {  OC::CreateHandleForLib,      "CreateHandleForLib",       OCC::CreateHandleForLib,       "createHandleForLib",         false, false, false, false, false, false, false, false, false, false,  true, Attribute::ReadOnly, },
+
+  // Raytracing object space uint System Values                                                                             void,     h,     f,     d,    i1,    i8,   i16,   i32,   i64,   udt,  obj,  function attribute
+  {  OC::PrimitiveIndex,          "PrimitiveIndex",           OCC::PrimitiveIndex,           "primitiveIndex",             false, false, false, false, false, false, false,  true, false, false, false, Attribute::ReadNone, },
 };
 // OPCODE-OLOADS:END
 
@@ -792,6 +797,8 @@ Function *OP::GetOpFunc(OpCode OpCode, Type *pOverloadType) {
     // Hull shader
   case OpCode::StorePatchConstant:     A(pV);       A(pI32); A(pI32); A(pI32); A(pI8);  A(pETy); break;
   case OpCode::OutputControlPointID:   A(pI32);     A(pI32); break;
+
+    // Hull, Domain and Geometry shaders
   case OpCode::PrimitiveID:            A(pI32);     A(pI32); break;
 
     // Other
@@ -884,7 +891,10 @@ Function *OP::GetOpFunc(OpCode OpCode, Type *pOverloadType) {
   case OpCode::CallShader:             A(pV);       A(pI32); A(pI32); A(udt);  break;
 
     // Library create handle from resource struct (like HL intrinsic)
-  case OpCode::CreateHandleFromResourceStructForLib:A(pRes);     A(pI32); A(obj);  break;
+  case OpCode::CreateHandleForLib:     A(pRes);     A(pI32); A(obj);  break;
+
+    // Raytracing object space uint System Values
+  case OpCode::PrimitiveIndex:         A(pI32);     A(pI32); break;
   // OPCODE-OLOAD-FUNCS:END
   default: DXASSERT(false, "otherwise unhandled case"); break;
   }
@@ -993,7 +1003,7 @@ llvm::Type *OP::GetOverloadType(OpCode OpCode, llvm::Function *F) {
   case OpCode::UAddc:
   case OpCode::USubb:
   case OpCode::WaveActiveAllEqual:
-  case OpCode::CreateHandleFromResourceStructForLib:
+  case OpCode::CreateHandleForLib:
     DXASSERT_NOMSG(FT->getNumParams() > 1);
     return FT->getParamType(1);
   case OpCode::TextureStore:
@@ -1059,6 +1069,7 @@ llvm::Type *OP::GetOverloadType(OpCode OpCode, llvm::Function *F) {
   case OpCode::RayFlags:
   case OpCode::DispatchRaysIndex:
   case OpCode::DispatchRaysDimensions:
+  case OpCode::PrimitiveIndex:
     return IntegerType::get(m_Ctx, 32);
   case OpCode::CalculateLOD:
   case OpCode::DomainLocation:

+ 2 - 2
lib/HLSL/DxilShaderFlags.cpp

@@ -326,11 +326,11 @@ ShaderFlags ShaderFlags::CollectShaderFlags(const Function *F,
                 DXASSERT(false, "Resource class must be constant.");
               }
             }
-            else if (handleOp == DXIL::OpCode::CreateHandleFromResourceStructForLib) {
+            else if (handleOp == DXIL::OpCode::CreateHandleForLib) {
               // If library handle, find DxilResource by checking the name
               if (LoadInst *LI = dyn_cast<LoadInst>(handleCall->getArgOperand(
                       DXIL::OperandIndex::
-                          kCreateHandleFromResourceStructForLibResOpIdx))) {
+                          kCreateHandleForLibResOpIdx))) {
                 Value *resType = LI->getOperand(0);
                 for (auto &&res : M->GetUAVs()) {
                   if (res->GetGlobalSymbol() == resType) {

+ 9 - 9
lib/HLSL/DxilValidation.cpp

@@ -609,7 +609,7 @@ static bool ValidateOpcodeInProfile(DXIL::OpCode opcode,
     return (pSM->IsGS());
   // Instructions: PrimitiveID=108
   if (op == 108)
-    return (pSM->IsGS() || pSM->IsDS() || pSM->IsHS() || pSM->IsPS() || pSM->IsLib() || pSM->GetKind() == DXIL::ShaderKind::Intersection || pSM->GetKind() == DXIL::ShaderKind::AnyHit || pSM->GetKind() == DXIL::ShaderKind::ClosestHit);
+    return (pSM->IsGS() || pSM->IsDS() || pSM->IsHS());
   // Instructions: StorePatchConstant=106, OutputControlPointID=107
   if (106 <= op && op <= 107)
     return (pSM->IsHS());
@@ -631,7 +631,7 @@ static bool ValidateOpcodeInProfile(DXIL::OpCode opcode,
   // Instructions: RawBufferLoad=139, RawBufferStore=140
   if (139 <= op && op <= 140)
     return (pSM->GetMajor() > 6 || (pSM->GetMajor() == 6 && pSM->GetMinor() >= 2));
-  // Instructions: CreateHandleFromResourceStructForLib=160
+  // Instructions: CreateHandleForLib=160
   if (op == 160)
     return (pSM->GetMajor() > 6 || (pSM->GetMajor() == 6 && pSM->GetMinor() >= 3));
   // Instructions: IgnoreHit=155, AcceptHitAndEndSearch=156
@@ -648,8 +648,8 @@ static bool ValidateOpcodeInProfile(DXIL::OpCode opcode,
         && (pSM->IsLib() || pSM->GetKind() == DXIL::ShaderKind::Intersection);
   // Instructions: InstanceID=141, InstanceIndex=142, HitKind=143,
   // ObjectRayOrigin=149, ObjectRayDirection=150, ObjectToWorld=151,
-  // WorldToObject=152
-  if (141 <= op && op <= 143 || 149 <= op && op <= 152)
+  // WorldToObject=152, PrimitiveIndex=161
+  if (141 <= op && op <= 143 || 149 <= op && op <= 152 || op == 161)
     return (pSM->GetMajor() > 6 || (pSM->GetMajor() == 6 && pSM->GetMinor() >= 3))
         && (pSM->IsLib() || pSM->GetKind() == DXIL::ShaderKind::Intersection || pSM->GetKind() == DXIL::ShaderKind::AnyHit || pSM->GetKind() == DXIL::ShaderKind::ClosestHit);
   // Instructions: RayFlags=144, WorldRayOrigin=147, WorldRayDirection=148,
@@ -747,7 +747,7 @@ static DXIL::SamplerKind GetSamplerKind(Value *samplerHandle, ValidationContext
       return EmitError();
     }
 
-    DxilInst_CreateHandleFromResourceStructForLib createHandleFromRes(
+    DxilInst_CreateHandleForLib createHandleFromRes(
         cast<CallInst>(samplerHandle));
     if (!createHandleFromRes) {
       return EmitError();
@@ -831,7 +831,7 @@ static DXIL::ResourceKind GetResourceKindAndCompTy(Value *handle, DXIL::Componen
     if (!ValCtx.isLibProfile) {
       return EmitError();
     }
-    DxilInst_CreateHandleFromResourceStructForLib createHandleFromRes(
+    DxilInst_CreateHandleForLib createHandleFromRes(
         cast<CallInst>(handle));
     if (!createHandleFromRes) {
       return EmitError();
@@ -1211,7 +1211,7 @@ static int GetCBufSize(Value *cbHandle, ValidationContext &ValCtx) {
     if (!ValCtx.isLibProfile) {
       return EmitError();
     }
-    DxilInst_CreateHandleFromResourceStructForLib createHandleFromRes(
+    DxilInst_CreateHandleForLib createHandleFromRes(
         cast<CallInst>(cbHandle));
     if (!createHandleFromRes) {
       return EmitError();
@@ -2075,9 +2075,9 @@ static void ValidateDxilOperationCallInProfile(CallInst *CI,
       ValCtx.EmitFormatError(ValidationRule::SmOpcodeInInvalidFunction,
                              {"QuadReadLaneAt", "Pixel Shader"});
     break;
-  case DXIL::OpCode::CreateHandleFromResourceStructForLib:
+  case DXIL::OpCode::CreateHandleForLib:
     ValCtx.EmitFormatError(ValidationRule::SmOpcodeInInvalidFunction,
-                           {"CreateHandleFromResourceStructForLib", "Library"});
+                           {"CreateHandleForLib", "Library"});
     break;
   default:
     // Skip opcodes don't need special check.

+ 1 - 1
lib/HLSL/HLOperationLower.cpp

@@ -4464,7 +4464,7 @@ IntrinsicLower gLowerTable[static_cast<unsigned>(IntrinsicOp::Num_Intrinsics)] =
     {IntrinsicOp::IOP_ObjectRayDirection, TranslateNoArgVectorOperation, DXIL::OpCode::ObjectRayDirection},
     {IntrinsicOp::IOP_ObjectRayOrigin, TranslateNoArgVectorOperation, DXIL::OpCode::ObjectRayOrigin},
     {IntrinsicOp::IOP_ObjectToWorld, TranslateNoArgMatrixOperation, DXIL::OpCode::ObjectToWorld},
-    {IntrinsicOp::IOP_PrimitiveIndex, TrivialNoArgWithRetOperation, DXIL::OpCode::PrimitiveID},
+    {IntrinsicOp::IOP_PrimitiveIndex, TrivialNoArgWithRetOperation, DXIL::OpCode::PrimitiveIndex},
     {IntrinsicOp::IOP_Process2DQuadTessFactorsAvg, TranslateProcessTessFactors, DXIL::OpCode::NumOpCodes},
     {IntrinsicOp::IOP_Process2DQuadTessFactorsMax, TranslateProcessTessFactors, DXIL::OpCode::NumOpCodes},
     {IntrinsicOp::IOP_Process2DQuadTessFactorsMin, TranslateProcessTessFactors, DXIL::OpCode::NumOpCodes},

+ 3 - 3
tools/clang/test/CodeGenHLSL/quick-test/lib_select_res.hlsl

@@ -1,8 +1,8 @@
 // RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
 
-// Make sure createHandleFromResourceStructForLib is used for resource.
-// CHECK:call %dx.types.Handle @dx.op.createHandleFromResourceStructForLib.struct.ByteAddressBuffer(i32 160
-// CHECK:call %dx.types.Handle @dx.op.createHandleFromResourceStructForLib.struct.RWByteAddressBuffer(i32 160
+// Make sure createHandleForLib is used for resource.
+// CHECK:call %dx.types.Handle @dx.op.createHandleForLib.struct.ByteAddressBuffer(i32 160
+// CHECK:call %dx.types.Handle @dx.op.createHandleForLib.struct.RWByteAddressBuffer(i32 160
 
 RWByteAddressBuffer outputBuffer : register(u0);
 ByteAddressBuffer ReadBuffer : register(t0);

+ 2 - 2
tools/clang/test/CodeGenHLSL/quick-test/raytracing_callable.hlsl

@@ -9,8 +9,8 @@
 // CHECK: define void [[callable1:@"\\01\?callable1@[^\"]+"]](%struct.MyParam* noalias nocapture %param) #0 {
 // CHECK:   %[[i_0:[0-9]+]] = load %struct.SamplerState, %struct.SamplerState* @"\01?S@@3USamplerState@@A", align 4
 // CHECK:   %[[i_1:[0-9]+]] = load %"class.Texture2D<vector<float, 4> >", %"class.Texture2D<vector<float, 4> >"* @"\01?T@@3V?$Texture2D@V?$vector@M$03@@@@A", align 4
-// CHECK:   %[[i_3:[0-9]+]] = call %dx.types.Handle @"dx.op.createHandleFromResourceStructForLib.class.Texture2D<vector<float, 4> >"(i32 160, %"class.Texture2D<vector<float, 4> >" %[[i_1]])
-// CHECK:   %[[i_4:[0-9]+]] = call %dx.types.Handle @dx.op.createHandleFromResourceStructForLib.struct.SamplerState(i32 160, %struct.SamplerState %[[i_0]])
+// CHECK:   %[[i_3:[0-9]+]] = call %dx.types.Handle @"dx.op.createHandleForLib.class.Texture2D<vector<float, 4> >"(i32 160, %"class.Texture2D<vector<float, 4> >" %[[i_1]])
+// CHECK:   %[[i_4:[0-9]+]] = call %dx.types.Handle @dx.op.createHandleForLib.struct.SamplerState(i32 160, %struct.SamplerState %[[i_0]])
 // CHECK:   %[[i_7:[0-9]+]] = call %dx.types.ResRet.f32 @dx.op.sampleLevel.f32(i32 62, %dx.types.Handle %[[i_3]], %dx.types.Handle %[[i_4]], float %[[i_5:[0-9]+]], float %[[i_6:[0-9]+]], float undef, float undef, i32 undef, i32 undef, i32 undef, float 0.000000e+00)
 // CHECK:   ret void
 

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/raytracing_raygeneration.hlsl

@@ -9,7 +9,7 @@
 // CHECK:   call i32 @dx.op.dispatchRaysIndex.i32(i32 145, i8 0)
 // CHECK:   call i32 @dx.op.dispatchRaysIndex.i32(i32 145, i8 1)
 // CHECK:   call i32 @dx.op.dispatchRaysDimensions.i32(i32 146, i8 0)
-// CHECK:   %[[i_8:[0-9]+]] = call %dx.types.Handle @dx.op.createHandleFromResourceStructForLib.struct.RaytracingAccelerationStructure(i32 160, %struct.RaytracingAccelerationStructure %[[i_0]])
+// CHECK:   %[[i_8:[0-9]+]] = call %dx.types.Handle @dx.op.createHandleForLib.struct.RaytracingAccelerationStructure(i32 160, %struct.RaytracingAccelerationStructure %[[i_0]])
 // CHECK:   call void @dx.op.traceRay.struct.MyPayload(i32 157, %dx.types.Handle %[[i_8]], i32 0, i32 0, i32 0, i32 1, i32 0, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 1.250000e-01, float {{.*}}, float {{.*}}, float {{.*}}, float 1.280000e+02, %struct.MyPayload* nonnull {{.*}})
 // CHECK:   ret void
 

+ 1 - 1
tools/clang/test/CodeGenHLSL/quick-test/raytracing_sgv_intrin.hlsl

@@ -24,7 +24,7 @@
 
 // CHECK: call float @dx.op.rayTMin.f32(i32 153)
 // CHECK: call float @dx.op.rayTCurrent.f32(i32 154)
-// CHECK: call i32 @dx.op.primitiveID.i32(i32 108)
+// CHECK: call i32 @dx.op.primitiveIndex.i32(i32 161)
 // CHECK: call i32 @dx.op.instanceID.i32(i32 141)
 // CHECK: call i32 @dx.op.instanceIndex.i32(i32 142)
 // CHECK: call i32 @dx.op.hitKind.i32(i32 143)

+ 2 - 2
tools/clang/test/CodeGenHLSL/quick-test/res_in_struct.hlsl

@@ -1,7 +1,7 @@
 // RUN: %dxc -T lib_6_2 %s | FileCheck %s
 
-// TODO: make sure CreateHandleFromResourceStructForLib is called.
-// CHECK: emit
+// make sure CreateHandleForLib is called.
+// CHECK: call %dx.types.Handle @"dx.op.createHandleForLib.class.Texture2D<vector<float, 4> >"(i32 160,
 
 struct M {
    float3 a;

+ 1 - 1
tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_res_sel.hlsl

@@ -1,7 +1,7 @@
 // RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
 
 // Make sure select resource works for lib profile.
-// CHECK: call %dx.types.Handle @"dx.op.createHandleFromResourceStructForLib.class.RWStructuredBuffer<vector<float, 2> >"
+// CHECK: call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer<vector<float, 2> >"
 
 RWStructuredBuffer<float2> buf0;
 RWStructuredBuffer<float2> buf1;

+ 2 - 1
tools/clang/tools/dxcompiler/dxcdisassembler.cpp

@@ -999,7 +999,8 @@ static const char *OpCodeSignatures[] = {
   "(AccelerationStructure,RayFlags,InstanceInclusionMask,RayContributionToHitGroupIndex,MultiplierForGeometryContributionToShaderIndex,MissShaderIndex,Origin_X,Origin_Y,Origin_Z,TMin,Direction_X,Direction_Y,Direction_Z,TMax,payload)",  // TraceRay
   "(THit,HitKind,Attributes)",  // ReportHit
   "(ShaderIndex,Parameter)",  // CallShader
-  "(Resource)"  // CreateHandleFromResourceStructForLib
+  "(Resource)",  // CreateHandleForLib
+  "()"  // PrimitiveIndex
 };
 // OPCODE-SIGS:END
 

+ 2 - 2
tools/clang/unittests/HLSL/LinkerTest.cpp

@@ -635,7 +635,7 @@ TEST_F(LinkerTest, RunLinkWithPotentialIntrinsicNameCollisions) {
   RegisterDxcModule(libName2, pLib2, pLinker);
 
   Link(L"", L"lib_6_2", pLinker, { libName1, libName2 }, {
-    "declare %dx.types.Handle @\"dx.op.createHandleFromResourceStructForLib.class.Texture2D<vector<float, 4> >\"(i32, %\"class.Texture2D<vector<float, 4> >\")",
-    "declare %dx.types.Handle @\"dx.op.createHandleFromResourceStructForLib.class.Texture2D<float>\"(i32, %\"class.Texture2D<float>\")"
+    "declare %dx.types.Handle @\"dx.op.createHandleForLib.class.Texture2D<vector<float, 4> >\"(i32, %\"class.Texture2D<vector<float, 4> >\")",
+    "declare %dx.types.Handle @\"dx.op.createHandleForLib.class.Texture2D<float>\"(i32, %\"class.Texture2D<float>\")"
   }, { });
 }

+ 14 - 5
utils/hct/hctdb.py

@@ -293,8 +293,8 @@ class db_dxil(object):
             self.name_idx[i].category = "Hull shader"
             self.name_idx[i].shader_stages = ("hull",)
         for i in "PrimitiveID".split(","):
-            self.name_idx[i].category = "Hull shader"
-            self.name_idx[i].shader_stages = ("geometry", "domain", "hull", "pixel","library","intersection","anyhit","closesthit")		
+            self.name_idx[i].category = "Hull, Domain and Geometry shaders"
+            self.name_idx[i].shader_stages = ("geometry", "domain", "hull")
         for i in "ViewID".split(","):
             self.name_idx[i].category = "Graphics shader"
             self.name_idx[i].shader_stages = ("vertex", "hull", "domain", "geometry", "pixel")
@@ -318,7 +318,7 @@ class db_dxil(object):
             self.name_idx[i].category = "Ray Dispatch Arguments"
             self.name_idx[i].shader_model = 6,3
             self.name_idx[i].shader_stages = ("library", "raygeneration","intersection","anyhit", "closesthit","miss","callable")
-        for i in "InstanceID,InstanceIndex".split(","):
+        for i in "InstanceID,InstanceIndex,PrimitiveIndex".split(","):
             self.name_idx[i].category = "Raytracing object space uint System Values"
             self.name_idx[i].shader_model = 6,3
             self.name_idx[i].shader_stages = ("library","intersection","anyhit","closesthit")
@@ -362,7 +362,7 @@ class db_dxil(object):
             self.name_idx[i].category = "Indirect Shader Invocation"
             self.name_idx[i].shader_model = 6,3
             self.name_idx[i].shader_stages = ("library", "intersection")
-        for i in "CreateHandleFromResourceStructForLib".split(","):
+        for i in "CreateHandleForLib".split(","):
             self.name_idx[i].category = "Library create handle from resource struct (like HL intrinsic)"
             self.name_idx[i].shader_model = 6,3
 
@@ -1286,11 +1286,20 @@ class db_dxil(object):
             db_dxil_param(3, "udt", "Parameter", "User-defined parameters to pass to the callable shader,This parameter structure must match the parameter structure used in the callable shader pointed to in the shader table")])
         next_op_idx += 1
 
-        self.add_dxil_op("CreateHandleFromResourceStructForLib", next_op_idx, "CreateHandleFromResourceStructForLib", "create resource handle from resource struct for library", "o", "ro", [
+        self.add_dxil_op("CreateHandleForLib", next_op_idx, "CreateHandleForLib", "create resource handle from resource struct for library", "o", "ro", [
             db_dxil_param(0, "res", "", "result"),
             db_dxil_param(2, "obj", "Resource", "resource to create the handle")])
         next_op_idx += 1
 
+        # Maps to PrimitiveIndex() intrinsics for raytracing (same meaning as PrimitiveID)
+        self.add_dxil_op("PrimitiveIndex", next_op_idx, "PrimitiveIndex", "PrimitiveIndex for raytracing shaders", "i", "rn", [
+            db_dxil_param(0, "i32", "", "result")])
+        next_op_idx += 1
+
+        # End of DXIL 1.3 opcodes.
+        self.set_op_count_for_version(1, 3, next_op_idx)
+        assert next_op_idx == 162, "next operation index is %d rather than 162 and thus opcodes are broken" % next_op_idx
+
         # Set interesting properties.
         self.build_indices()
         for i in "CalculateLOD,DerivCoarseX,DerivCoarseY,DerivFineX,DerivFineY,Sample,SampleBias,SampleCmp,TextureGather,TextureGatherCmp".split(","):