1 /* -*- c++ -*- */ 2 /* 3 * Copyright © 2010-2016 Intel Corporation 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the next 13 * paragraph) shall be included in all copies or substantial portions of the 14 * Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 * IN THE SOFTWARE. 23 */ 24 25 #pragma once 26 27 #include <assert.h> 28 #include "elk_reg.h" 29 #include "compiler/glsl/list.h" 30 31 #define MAX_SAMPLER_MESSAGE_SIZE 11 32 33 /* The sampler can return a vec5 when sampling with sparse residency. In 34 * SIMD32, each component takes up 4 GRFs, so we need to allow up to size-20 35 * VGRFs to hold the result. 36 */ 37 #define MAX_VGRF_SIZE(devinfo) ((devinfo)->ver >= 20 ? 40 : 20) 38 39 #ifdef __cplusplus 40 struct elk_backend_reg : private elk_reg 41 { elk_backend_regelk_backend_reg42 elk_backend_reg() {} elk_backend_regelk_backend_reg43 elk_backend_reg(const struct elk_reg ®) : elk_reg(reg), offset(0) {} 44 as_elk_regelk_backend_reg45 const elk_reg &as_elk_reg() const 46 { 47 assert(file == ARF || file == FIXED_GRF || file == MRF || file == IMM); 48 assert(offset == 0); 49 return static_cast<const elk_reg &>(*this); 50 } 51 as_elk_regelk_backend_reg52 elk_reg &as_elk_reg() 53 { 54 assert(file == ARF || file == FIXED_GRF || file == MRF || file == IMM); 55 assert(offset == 0); 56 return static_cast<elk_reg &>(*this); 57 } 58 59 bool equals(const elk_backend_reg &r) const; 60 bool negative_equals(const elk_backend_reg &r) const; 61 62 bool is_zero() const; 63 bool is_one() const; 64 bool is_negative_one() const; 65 bool is_null() const; 66 bool is_accumulator() const; 67 68 /** Offset from the start of the (virtual) register in bytes. */ 69 uint16_t offset; 70 71 using elk_reg::type; 72 using elk_reg::file; 73 using elk_reg::negate; 74 using elk_reg::abs; 75 using elk_reg::address_mode; 76 using elk_reg::subnr; 77 using elk_reg::nr; 78 79 using elk_reg::swizzle; 80 using elk_reg::writemask; 81 using elk_reg::indirect_offset; 82 using elk_reg::vstride; 83 using elk_reg::width; 84 using elk_reg::hstride; 85 86 using elk_reg::df; 87 using elk_reg::f; 88 using elk_reg::d; 89 using elk_reg::ud; 90 using elk_reg::d64; 91 using elk_reg::u64; 92 }; 93 94 struct elk_bblock_t; 95 96 struct elk_backend_instruction : public exec_node { 97 bool elk_is_3src(const struct elk_compiler *compiler) const; 98 bool is_math() const; 99 bool is_control_flow_begin() const; 100 bool is_control_flow_end() const; 101 bool is_control_flow() const; 102 bool is_commutative() const; 103 bool can_do_source_mods() const; 104 bool can_do_saturate() const; 105 bool can_do_cmod() const; 106 bool reads_accumulator_implicitly() const; 107 bool writes_accumulator_implicitly(const struct intel_device_info *devinfo) const; 108 109 /** 110 * Instructions that use indirect addressing have additional register 111 * regioning restrictions. 112 */ 113 bool uses_indirect_addressing() const; 114 115 void remove(elk_bblock_t *block, bool defer_later_block_ip_updates = false); 116 void insert_after(elk_bblock_t *block, elk_backend_instruction *inst); 117 void insert_before(elk_bblock_t *block, elk_backend_instruction *inst); 118 119 /** 120 * True if the instruction has side effects other than writing to 121 * its destination registers. You are expected not to reorder or 122 * optimize these out unless you know what you are doing. 123 */ 124 bool has_side_effects() const; 125 126 /** 127 * True if the instruction might be affected by side effects of other 128 * instructions. 129 */ 130 bool is_volatile() const; 131 #else 132 struct elk_backend_instruction { 133 struct exec_node link; 134 #endif 135 /** @{ 136 * Annotation for the generated IR. One of the two can be set. 137 */ 138 const void *ir; 139 const char *annotation; 140 /** @} */ 141 142 /** 143 * Execution size of the instruction. This is used by the generator to 144 * generate the correct binary for the given instruction. Current valid 145 * values are 1, 4, 8, 16, 32. 146 */ 147 uint8_t exec_size; 148 149 /** 150 * Channel group from the hardware execution and predication mask that 151 * should be applied to the instruction. The subset of channel enable 152 * signals (calculated from the EU control flow and predication state) 153 * given by [group, group + exec_size) will be used to mask GRF writes and 154 * any other side effects of the instruction. 155 */ 156 uint8_t group; 157 158 uint32_t offset; /**< spill/unspill offset or texture offset bitfield */ 159 uint8_t mlen; /**< SEND message length */ 160 int8_t base_mrf; /**< First MRF in the SEND message, if mlen is nonzero. */ 161 uint8_t target; /**< MRT target. */ 162 uint8_t sfid; /**< SFID for SEND instructions */ 163 uint32_t desc; /**< SEND[S] message descriptor immediate */ 164 unsigned size_written; /**< Data written to the destination register in bytes. */ 165 166 enum elk_opcode opcode; /* ELK_OPCODE_* or ELK_FS_OPCODE_* */ 167 enum elk_conditional_mod conditional_mod; /**< ELK_CONDITIONAL_* */ 168 enum elk_predicate predicate; 169 bool predicate_inverse:1; 170 bool writes_accumulator:1; /**< instruction implicitly writes accumulator */ 171 bool force_writemask_all:1; 172 bool no_dd_clear:1; 173 bool no_dd_check:1; 174 bool saturate:1; 175 bool shadow_compare:1; 176 bool check_tdr:1; /**< Only valid for SEND; turns it into a SENDC */ 177 bool send_has_side_effects:1; /**< Only valid for ELK_SHADER_OPCODE_SEND */ 178 bool send_is_volatile:1; /**< Only valid for ELK_SHADER_OPCODE_SEND */ 179 bool predicate_trivial:1; /**< The predication mask applied to this 180 * instruction is guaranteed to be uniform and 181 * a superset of the execution mask of the 182 * present block, no currently enabled channels 183 * will be disabled by the predicate. 184 */ 185 bool eot:1; 186 187 /* Chooses which flag subregister (f0.0 to f3.1) is used for conditional 188 * mod and predication. 189 */ 190 unsigned flag_subreg:3; 191 192 /** The number of hardware registers used for a message header. */ 193 uint8_t header_size; 194 }; 195