xref: /freebsd/contrib/llvm-project/llvm/lib/Target/DirectX/DXIL.td (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1//- DXIL.td - Describe DXIL operation -------------------------*- tablegen -*-//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This is a target description file for DXIL operations.
11///
12//===----------------------------------------------------------------------===//
13
14include "llvm/IR/Intrinsics.td"
15
16class DXILOpClass;
17
18// Following is a set of DXIL Operation classes whose names appear to be
19// arbitrary, yet need to be a substring of the function name used during
20// lowering to DXIL Operation calls. These class name strings are specified
21// as the third argument of add_dixil_op in utils/hct/hctdb.py and case converted
22// in utils/hct/hctdb_instrhelp.py of DirectXShaderCompiler repo. The function
23// name has the format "dx.op.<class-name>.<return-type>".
24
25defset list<DXILOpClass> OpClasses = {
26  def acceptHitAndEndSearch : DXILOpClass;
27  def allocateNodeOutputRecords : DXILOpClass;
28  def allocateRayQuery : DXILOpClass;
29  def annotateHandle : DXILOpClass;
30  def annotateNodeHandle : DXILOpClass;
31  def annotateNodeRecordHandle : DXILOpClass;
32  def atomicBinOp : DXILOpClass;
33  def atomicCompareExchange : DXILOpClass;
34  def attributeAtVertex : DXILOpClass;
35  def barrier : DXILOpClass;
36  def barrierByMemoryHandle : DXILOpClass;
37  def barrierByMemoryType : DXILOpClass;
38  def barrierByNodeRecordHandle : DXILOpClass;
39  def binary : DXILOpClass;
40  def binaryWithCarryOrBorrow : DXILOpClass;
41  def binaryWithTwoOuts : DXILOpClass;
42  def bitcastF16toI16 : DXILOpClass;
43  def bitcastF32toI32 : DXILOpClass;
44  def bitcastF64toI64 : DXILOpClass;
45  def bitcastI16toF16 : DXILOpClass;
46  def bitcastI32toF32 : DXILOpClass;
47  def bitcastI64toF64 : DXILOpClass;
48  def bufferLoad : DXILOpClass;
49  def bufferStore : DXILOpClass;
50  def bufferUpdateCounter : DXILOpClass;
51  def calculateLOD : DXILOpClass;
52  def callShader : DXILOpClass;
53  def cbufferLoad : DXILOpClass;
54  def cbufferLoadLegacy : DXILOpClass;
55  def checkAccessFullyMapped : DXILOpClass;
56  def coverage : DXILOpClass;
57  def createHandle : DXILOpClass;
58  def createHandleForLib : DXILOpClass;
59  def createHandleFromBinding : DXILOpClass;
60  def createHandleFromHeap : DXILOpClass;
61  def createNodeInputRecordHandle : DXILOpClass;
62  def createNodeOutputHandle : DXILOpClass;
63  def cutStream : DXILOpClass;
64  def cycleCounterLegacy : DXILOpClass;
65  def discard : DXILOpClass;
66  def dispatchMesh : DXILOpClass;
67  def dispatchRaysDimensions : DXILOpClass;
68  def dispatchRaysIndex : DXILOpClass;
69  def domainLocation : DXILOpClass;
70  def dot2 : DXILOpClass;
71  def dot2AddHalf : DXILOpClass;
72  def dot3 : DXILOpClass;
73  def dot4 : DXILOpClass;
74  def dot4AddPacked : DXILOpClass;
75  def emitIndices : DXILOpClass;
76  def emitStream : DXILOpClass;
77  def emitThenCutStream : DXILOpClass;
78  def evalCentroid : DXILOpClass;
79  def evalSampleIndex : DXILOpClass;
80  def evalSnapped : DXILOpClass;
81  def finishedCrossGroupSharing : DXILOpClass;
82  def flattenedThreadIdInGroup : DXILOpClass;
83  def geometryIndex : DXILOpClass;
84  def getDimensions : DXILOpClass;
85  def getInputRecordCount : DXILOpClass;
86  def getMeshPayload : DXILOpClass;
87  def getNodeRecordPtr : DXILOpClass;
88  def getRemainingRecursionLevels : DXILOpClass;
89  def groupId : DXILOpClass;
90  def gsInstanceID : DXILOpClass;
91  def hitKind : DXILOpClass;
92  def ignoreHit : DXILOpClass;
93  def incrementOutputCount : DXILOpClass;
94  def indexNodeHandle : DXILOpClass;
95  def innerCoverage : DXILOpClass;
96  def instanceID : DXILOpClass;
97  def instanceIndex : DXILOpClass;
98  def isHelperLane : DXILOpClass;
99  def isSpecialFloat : DXILOpClass;
100  def legacyDoubleToFloat : DXILOpClass;
101  def legacyDoubleToSInt32 : DXILOpClass;
102  def legacyDoubleToUInt32 : DXILOpClass;
103  def legacyF16ToF32 : DXILOpClass;
104  def legacyF32ToF16 : DXILOpClass;
105  def loadInput : DXILOpClass;
106  def loadOutputControlPoint : DXILOpClass;
107  def loadPatchConstant : DXILOpClass;
108  def makeDouble : DXILOpClass;
109  def minPrecXRegLoad : DXILOpClass;
110  def minPrecXRegStore : DXILOpClass;
111  def nodeOutputIsValid : DXILOpClass;
112  def objectRayDirection : DXILOpClass;
113  def objectRayOrigin : DXILOpClass;
114  def objectToWorld : DXILOpClass;
115  def outputComplete : DXILOpClass;
116  def outputControlPointID : DXILOpClass;
117  def pack4x8 : DXILOpClass;
118  def primitiveID : DXILOpClass;
119  def primitiveIndex : DXILOpClass;
120  def quadOp : DXILOpClass;
121  def quadReadLaneAt : DXILOpClass;
122  def quadVote : DXILOpClass;
123  def quaternary : DXILOpClass;
124  def rawBufferLoad : DXILOpClass;
125  def rawBufferStore : DXILOpClass;
126  def rayFlags : DXILOpClass;
127  def rayQuery_Abort : DXILOpClass;
128  def rayQuery_CommitNonOpaqueTriangleHit : DXILOpClass;
129  def rayQuery_CommitProceduralPrimitiveHit : DXILOpClass;
130  def rayQuery_Proceed : DXILOpClass;
131  def rayQuery_StateMatrix : DXILOpClass;
132  def rayQuery_StateScalar : DXILOpClass;
133  def rayQuery_StateVector : DXILOpClass;
134  def rayQuery_TraceRayInline : DXILOpClass;
135  def rayTCurrent : DXILOpClass;
136  def rayTMin : DXILOpClass;
137  def renderTargetGetSampleCount : DXILOpClass;
138  def renderTargetGetSamplePosition : DXILOpClass;
139  def reportHit : DXILOpClass;
140  def sample : DXILOpClass;
141  def sampleBias : DXILOpClass;
142  def sampleCmp : DXILOpClass;
143  def sampleCmpBias : DXILOpClass;
144  def sampleCmpGrad : DXILOpClass;
145  def sampleCmpLevel : DXILOpClass;
146  def sampleCmpLevelZero : DXILOpClass;
147  def sampleGrad : DXILOpClass;
148  def sampleIndex : DXILOpClass;
149  def sampleLevel : DXILOpClass;
150  def setMeshOutputCounts : DXILOpClass;
151  def splitDouble : DXILOpClass;
152  def startInstanceLocation : DXILOpClass;
153  def startVertexLocation : DXILOpClass;
154  def storeOutput : DXILOpClass;
155  def storePatchConstant : DXILOpClass;
156  def storePrimitiveOutput : DXILOpClass;
157  def storeVertexOutput : DXILOpClass;
158  def tempRegLoad : DXILOpClass;
159  def tempRegStore : DXILOpClass;
160  def tertiary : DXILOpClass;
161  def texture2DMSGetSamplePosition : DXILOpClass;
162  def textureGather : DXILOpClass;
163  def textureGatherCmp : DXILOpClass;
164  def textureGatherRaw : DXILOpClass;
165  def textureLoad : DXILOpClass;
166  def textureStore : DXILOpClass;
167  def textureStoreSample : DXILOpClass;
168  def threadId : DXILOpClass;
169  def threadIdInGroup : DXILOpClass;
170  def traceRay : DXILOpClass;
171  def unary : DXILOpClass;
172  def unaryBits : DXILOpClass;
173  def unpack4x8 : DXILOpClass;
174  def viewID : DXILOpClass;
175  def waveActiveAllEqual : DXILOpClass;
176  def waveActiveBallot : DXILOpClass;
177  def waveActiveBit : DXILOpClass;
178  def waveActiveOp : DXILOpClass;
179  def waveAllOp : DXILOpClass;
180  def waveAllTrue : DXILOpClass;
181  def waveAnyTrue : DXILOpClass;
182  def waveGetLaneCount : DXILOpClass;
183  def waveGetLaneIndex : DXILOpClass;
184  def waveIsFirstLane : DXILOpClass;
185  def waveMatch : DXILOpClass;
186  def waveMatrix_Accumulate : DXILOpClass;
187  def waveMatrix_Annotate : DXILOpClass;
188  def waveMatrix_Depth : DXILOpClass;
189  def waveMatrix_Fill : DXILOpClass;
190  def waveMatrix_LoadGroupShared : DXILOpClass;
191  def waveMatrix_LoadRawBuf : DXILOpClass;
192  def waveMatrix_Multiply : DXILOpClass;
193  def waveMatrix_ScalarOp : DXILOpClass;
194  def waveMatrix_StoreGroupShared : DXILOpClass;
195  def waveMatrix_StoreRawBuf : DXILOpClass;
196  def waveMultiPrefixBitCount : DXILOpClass;
197  def waveMultiPrefixOp : DXILOpClass;
198  def wavePrefixOp : DXILOpClass;
199  def waveReadLaneAt : DXILOpClass;
200  def waveReadLaneFirst : DXILOpClass;
201  def worldRayDirection : DXILOpClass;
202  def worldRayOrigin : DXILOpClass;
203  def worldToObject : DXILOpClass;
204  def writeSamplerFeedback : DXILOpClass;
205  def writeSamplerFeedbackBias : DXILOpClass;
206  def writeSamplerFeedbackGrad : DXILOpClass;
207  def writeSamplerFeedbackLevel: DXILOpClass;
208
209  // This is a sentinel definition. Hence placed at the end of the list
210  // and not as part of the above alphabetically sorted valid definitions.
211  // Additionally it is capitalized unlike all the others.
212  def UnknownOpClass: DXILOpClass;
213}
214
215// Several of the overloaded DXIL Operations support for data types
216// that are a subset of the overloaded LLVM intrinsics that they map to.
217// For e.g., llvm.sin.* intrinsic operates on any floating-point type and
218// maps for lowering to DXIL Op Sin. However, valid overloads of DXIL Sin
219// operation overloads are half (f16) and float (f32) only.
220//
221// The following abstracts overload types specific to DXIL operations.
222
223class DXILType : LLVMType<OtherVT> {
224  let isAny = 1;
225  int isI16OrI32 = 0;
226  int isHalfOrFloat = 0;
227}
228
229// Concrete records for various overload types supported specifically by
230// DXIL Operations.
231let isI16OrI32 = 1 in
232  def llvm_i16ori32_ty : DXILType;
233
234let isHalfOrFloat = 1 in
235  def llvm_halforfloat_ty : DXILType;
236
237// Abstraction DXIL Operation to LLVM intrinsic
238class DXILOpMappingBase {
239  int OpCode = 0;                      // Opcode of DXIL Operation
240  DXILOpClass OpClass = UnknownOpClass;// Class of DXIL Operation.
241  Intrinsic LLVMIntrinsic = ?;         // LLVM Intrinsic DXIL Operation maps to
242  string Doc = "";                     // A short description of the operation
243  list<LLVMType> OpTypes = ?;          // Valid types of DXIL Operation in the
244                                       // format [returnTy, param1ty, ...]
245}
246
247class DXILOpMapping<int opCode, DXILOpClass opClass,
248                    Intrinsic intrinsic, string doc,
249                    list<LLVMType> opTys = []> : DXILOpMappingBase {
250  int OpCode = opCode;                 // Opcode corresponding to DXIL Operation
251  DXILOpClass OpClass = opClass;       // Class of DXIL Operation.
252  Intrinsic LLVMIntrinsic = intrinsic; // LLVM Intrinsic the DXIL Operation maps
253  string Doc = doc;                    // to a short description of the operation
254  list<LLVMType> OpTypes = !if(!eq(!size(opTys), 0), LLVMIntrinsic.Types, opTys);
255}
256
257// Concrete definition of DXIL Operation mapping to corresponding LLVM intrinsic
258def Abs : DXILOpMapping<6, unary, int_fabs,
259                         "Returns the absolute value of the input.">;
260def IsInf : DXILOpMapping<9, isSpecialFloat, int_dx_isinf,
261                         "Determines if the specified value is infinite.",
262                         [llvm_i1_ty, llvm_halforfloat_ty]>;
263def Cos  : DXILOpMapping<12, unary, int_cos,
264                         "Returns cosine(theta) for theta in radians.",
265                         [llvm_halforfloat_ty, LLVMMatchType<0>]>;
266def Sin  : DXILOpMapping<13, unary, int_sin,
267                         "Returns sine(theta) for theta in radians.",
268                         [llvm_halforfloat_ty, LLVMMatchType<0>]>;
269def Tan  : DXILOpMapping<14, unary, int_tan,
270                         "Returns tangent(theta) for theta in radians.",
271                         [llvm_halforfloat_ty, LLVMMatchType<0>]>;
272def ACos  : DXILOpMapping<15, unary, int_acos,
273                         "Returns the arccosine of each component of input.",
274                         [llvm_halforfloat_ty, LLVMMatchType<0>]>;
275def ASin  : DXILOpMapping<16, unary, int_asin,
276                         "Returns the arcsine of each component of input.",
277                         [llvm_halforfloat_ty, LLVMMatchType<0>]>;
278def ATan  : DXILOpMapping<17, unary, int_atan,
279                         "Returns the arctangent of each component of input.",
280                         [llvm_halforfloat_ty, LLVMMatchType<0>]>;
281def HCos  : DXILOpMapping<18, unary, int_cosh,
282                         "Returns the hyperbolic cosine of the specified value.",
283                         [llvm_halforfloat_ty, LLVMMatchType<0>]>;
284def HSin  : DXILOpMapping<19, unary, int_sinh,
285                         "Returns the hyperbolic sine of the specified value.",
286                         [llvm_halforfloat_ty, LLVMMatchType<0>]>;
287def HTan  : DXILOpMapping<20, unary, int_tanh,
288                         "Returns the hyperbolic tan of the specified value.",
289                         [llvm_halforfloat_ty, LLVMMatchType<0>]>;
290
291def Exp2 : DXILOpMapping<21, unary, int_exp2,
292                         "Returns the base 2 exponential, or 2**x, of the specified value."
293                         "exp2(x) = 2**x.",
294                         [llvm_halforfloat_ty, LLVMMatchType<0>]>;
295def Frac : DXILOpMapping<22, unary, int_dx_frac,
296                         "Returns a fraction from 0 to 1 that represents the "
297                         "decimal part of the input.",
298                         [llvm_halforfloat_ty, LLVMMatchType<0>]>;
299def Log2 : DXILOpMapping<23, unary, int_log2,
300                         "Returns the base-2 logarithm of the specified value.",
301                         [llvm_halforfloat_ty, LLVMMatchType<0>]>;
302def Sqrt : DXILOpMapping<24, unary, int_sqrt,
303                         "Returns the square root of the specified floating-point"
304                         "value, per component.",
305                         [llvm_halforfloat_ty, LLVMMatchType<0>]>;
306def RSqrt : DXILOpMapping<25, unary, int_dx_rsqrt,
307                         "Returns the reciprocal of the square root of the specified value."
308                         "rsqrt(x) = 1 / sqrt(x).",
309                         [llvm_halforfloat_ty, LLVMMatchType<0>]>;
310def Round : DXILOpMapping<26, unary, int_roundeven,
311                         "Returns the input rounded to the nearest integer"
312                         "within a floating-point type.",
313                         [llvm_halforfloat_ty, LLVMMatchType<0>]>;
314def Floor : DXILOpMapping<27, unary, int_floor,
315                         "Returns the largest integer that is less than or equal to the input.",
316                         [llvm_halforfloat_ty, LLVMMatchType<0>]>;
317def Ceil : DXILOpMapping<28, unary, int_ceil,
318                         "Returns the smallest integer that is greater than or equal to the input.",
319                         [llvm_halforfloat_ty, LLVMMatchType<0>]>;
320def Trunc : DXILOpMapping<29, unary, int_trunc,
321                         "Returns the specified value truncated to the integer component.",
322                         [llvm_halforfloat_ty, LLVMMatchType<0>]>;
323def Rbits : DXILOpMapping<30, unary, int_bitreverse,
324                         "Returns the specified value with its bits reversed.",
325                         [llvm_anyint_ty, LLVMMatchType<0>]>;
326def FMax : DXILOpMapping<35, binary, int_maxnum,
327                         "Float maximum. FMax(a,b) = a > b ? a : b">;
328def FMin : DXILOpMapping<36, binary, int_minnum,
329                         "Float minimum. FMin(a,b) = a < b ? a : b">;
330def SMax : DXILOpMapping<37, binary, int_smax,
331                         "Signed integer maximum. SMax(a,b) = a > b ? a : b">;
332def SMin : DXILOpMapping<38, binary, int_smin,
333                         "Signed integer minimum. SMin(a,b) = a < b ? a : b">;
334def UMax : DXILOpMapping<39, binary, int_umax,
335                         "Unsigned integer maximum. UMax(a,b) = a > b ? a : b">;
336def UMin : DXILOpMapping<40, binary, int_umin,
337                         "Unsigned integer minimum. UMin(a,b) = a < b ? a : b">;
338def FMad : DXILOpMapping<46, tertiary, int_fmuladd,
339                         "Floating point arithmetic multiply/add operation. fmad(m,a,b) = m * a + b.">;
340def IMad : DXILOpMapping<48, tertiary, int_dx_imad,
341                         "Signed integer arithmetic multiply/add operation. imad(m,a,b) = m * a + b.">;
342def UMad : DXILOpMapping<49, tertiary, int_dx_umad,
343                         "Unsigned integer arithmetic multiply/add operation. umad(m,a,b) = m * a + b.">;
344let OpTypes = !listconcat([llvm_halforfloat_ty], !listsplat(llvm_halforfloat_ty, 4)) in
345  def Dot2 : DXILOpMapping<54, dot2, int_dx_dot2,
346                           "dot product of two float vectors Dot(a,b) = a[0]*b[0] + ... + a[n]*b[n] where n is between 0 and 1">;
347let OpTypes = !listconcat([llvm_halforfloat_ty], !listsplat(llvm_halforfloat_ty, 6)) in
348  def Dot3 : DXILOpMapping<55, dot3, int_dx_dot3,
349                           "dot product of two float vectors Dot(a,b) = a[0]*b[0] + ... + a[n]*b[n] where n is between 0 and 2">;
350let OpTypes = !listconcat([llvm_halforfloat_ty], !listsplat(llvm_halforfloat_ty, 8)) in
351  def Dot4 : DXILOpMapping<56, dot4, int_dx_dot4,
352                           "dot product of two float vectors Dot(a,b) = a[0]*b[0] + ... + a[n]*b[n] where n is between 0 and 3">;
353def ThreadId : DXILOpMapping<93, threadId, int_dx_thread_id,
354                             "Reads the thread ID">;
355def GroupId  : DXILOpMapping<94, groupId, int_dx_group_id,
356                             "Reads the group ID (SV_GroupID)">;
357def ThreadIdInGroup : DXILOpMapping<95, threadIdInGroup,
358                                    int_dx_thread_id_in_group,
359                                    "Reads the thread ID within the group "
360                                    "(SV_GroupThreadID)">;
361def FlattenedThreadIdInGroup : DXILOpMapping<96, flattenedThreadIdInGroup,
362                                             int_dx_flattened_thread_id_in_group,
363                                             "Provides a flattened index for a "
364                                             "given thread within a given "
365                                             "group (SV_GroupIndex)">;
366