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