xref: /freebsd/contrib/llvm-project/llvm/lib/Target/DirectX/DXIL.td (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
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 operation.
11///
12//===----------------------------------------------------------------------===//
13
14include "llvm/IR/Intrinsics.td"
15
16class dxil_class<string _name> {
17  string name = _name;
18}
19class dxil_category<string _name> {
20  string name = _name;
21}
22
23def Unary : dxil_class<"Unary">;
24def Binary : dxil_class<"Binary">;
25def FlattenedThreadIdInGroupClass : dxil_class<"FlattenedThreadIdInGroup">;
26def ThreadIdInGroupClass : dxil_class<"ThreadIdInGroup">;
27def ThreadIdClass : dxil_class<"ThreadId">;
28def GroupIdClass : dxil_class<"GroupId">;
29
30def binary_uint : dxil_category<"Binary uint">;
31def unary_float : dxil_category<"Unary float">;
32def ComputeID : dxil_category<"Compute/Mesh/Amplification shader">;
33
34
35// The parameter description for a DXIL instruction
36class dxil_param<int _pos, string type, string _name, string _doc,
37                 bit _is_const = 0, string _enum_name = "",
38                 int _max_value = 0> {
39  int pos = _pos;           // position in parameter list
40  string llvm_type = type; // llvm type name, $o for overload, $r for resource
41                           // type, $cb for legacy cbuffer, $u4 for u4 struct
42  string name = _name;      // short, unique name
43  string doc = _doc;        // the documentation description of this parameter
44  bit is_const =
45      _is_const; // whether this argument requires a constant value in the IR
46  string enum_name = _enum_name; // the name of the enum type if applicable
47  int max_value =
48      _max_value; // the maximum value for this parameter if applicable
49}
50
51// A representation for a DXIL instruction
52class dxil_inst<string _name> {
53  string name = _name; // short, unique name
54
55  string dxil_op = "";       // name of DXIL operation
56  int dxil_opid = 0;         // ID of DXIL operation
57  dxil_class  op_class;      // name of the opcode class
58  dxil_category category;    // classification for this instruction
59  string doc = "";           // the documentation description of this instruction
60  list<dxil_param> ops = []; // the operands that this instruction takes
61  string oload_types = "";   // overload types if applicable
62  string fn_attr = "";       // attribute shorthands: rn=does not access
63                             // memory,ro=only reads from memory,
64  bit is_deriv = 0;          // whether this is some kind of derivative
65  bit is_gradient = 0;       // whether this requires a gradient calculation
66  bit is_feedback = 0;       // whether this is a sampler feedback op
67  bit is_wave = 0; // whether this requires in-wave, cross-lane functionality
68  bit requires_uniform_inputs = 0; // whether this operation requires that all
69                                   // of its inputs are uniform across the wave
70  // Group dxil operation for stats.
71  // Like how many atomic/float/uint/int/... instructions used in the program.
72  list<string> stats_group = [];
73}
74
75class dxil_op<string name, int code_id, dxil_class code_class, dxil_category op_category, string _doc,
76              string _oload_types, string _fn_attr, list<dxil_param> op_params,
77              list<string> _stats_group = []> : dxil_inst<name> {
78  let dxil_op = name;
79  let dxil_opid = code_id;
80  let doc = _doc;
81  let ops = op_params;
82  let op_class = code_class;
83  let category = op_category;
84  let oload_types = _oload_types;
85  let fn_attr = _fn_attr;
86  let stats_group = _stats_group;
87}
88
89// The intrinsic which map directly to this dxil op.
90class dxil_map_intrinsic<Intrinsic llvm_intrinsic_> { Intrinsic llvm_intrinsic = llvm_intrinsic_; }
91
92def Sin : dxil_op<"Sin", 13, Unary, unary_float, "returns sine(theta) for theta in radians.",
93  "half;float;", "rn",
94  [
95    dxil_param<0, "$o", "", "operation result">,
96    dxil_param<1, "i32", "opcode", "DXIL opcode">,
97    dxil_param<2, "$o", "value", "input value">
98  ],
99  ["floats"]>,
100  dxil_map_intrinsic<int_sin>;
101
102def UMax :dxil_op< "UMax", 39,  Binary,  binary_uint, "unsigned integer maximum. UMax(a,b) = a > b ? a : b",
103    "i16;i32;i64;",  "rn",
104  [
105    dxil_param<0,  "$o",  "",  "operation result">,
106    dxil_param<1,  "i32",  "opcode",  "DXIL opcode">,
107    dxil_param<2,  "$o",  "a",  "input value">,
108    dxil_param<3,  "$o",  "b",  "input value">
109  ],
110  ["uints"]>,
111  dxil_map_intrinsic<int_umax>;
112
113def ThreadId :dxil_op< "ThreadId", 93,  ThreadIdClass, ComputeID, "reads the thread ID", "i32;",  "rn",
114  [
115    dxil_param<0,  "i32",  "",  "thread ID component">,
116    dxil_param<1,  "i32",  "opcode",  "DXIL opcode">,
117    dxil_param<2,  "i32",  "component",  "component to read (x,y,z)">
118  ]>,
119  dxil_map_intrinsic<int_dx_thread_id>;
120
121def GroupId :dxil_op< "GroupId", 94,  GroupIdClass, ComputeID, "reads the group ID (SV_GroupID)", "i32;",  "rn",
122  [
123    dxil_param<0,  "i32",  "",  "group ID component">,
124    dxil_param<1,  "i32",  "opcode",  "DXIL opcode">,
125    dxil_param<2,  "i32",  "component",  "component to read">
126  ]>,
127  dxil_map_intrinsic<int_dx_group_id>;
128
129def ThreadIdInGroup :dxil_op< "ThreadIdInGroup", 95,  ThreadIdInGroupClass, ComputeID,
130  "reads the thread ID within the group (SV_GroupThreadID)", "i32;",  "rn",
131  [
132    dxil_param<0,  "i32",  "",  "thread ID in group component">,
133    dxil_param<1,  "i32",  "opcode",  "DXIL opcode">,
134    dxil_param<2,  "i32",  "component",  "component to read (x,y,z)">
135  ]>,
136  dxil_map_intrinsic<int_dx_thread_id_in_group>;
137
138def FlattenedThreadIdInGroup :dxil_op< "FlattenedThreadIdInGroup", 96,  FlattenedThreadIdInGroupClass, ComputeID,
139   "provides a flattened index for a given thread within a given group (SV_GroupIndex)", "i32;",  "rn",
140  [
141    dxil_param<0,  "i32",  "",  "result">,
142    dxil_param<1,  "i32",  "opcode",  "DXIL opcode">
143  ]>,
144  dxil_map_intrinsic<int_dx_flattened_thread_id_in_group>;
145