Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 1 | |
Christian König | ce40e47 | 2012-08-02 12:14:59 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2012 Advanced Micro Devices, Inc. |
| 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 | * on the rights to use, copy, modify, merge, publish, distribute, sub |
| 9 | * license, and/or sell copies of the Software, and to permit persons to whom |
| 10 | * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, |
| 20 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 21 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 22 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: |
| 25 | * Tom Stellard <thomas.stellard@amd.com> |
| 26 | * Michel Dänzer <michel.daenzer@amd.com> |
| 27 | * Christian König <christian.koenig@amd.com> |
| 28 | */ |
| 29 | |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 30 | #include "gallivm/lp_bld_tgsi_action.h" |
| 31 | #include "gallivm/lp_bld_const.h" |
Michel Dänzer | c2bae6b | 2012-08-02 17:19:22 +0200 | [diff] [blame] | 32 | #include "gallivm/lp_bld_gather.h" |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 33 | #include "gallivm/lp_bld_intr.h" |
Michel Dänzer | 7708a86 | 2012-11-02 15:57:30 +0100 | [diff] [blame] | 34 | #include "gallivm/lp_bld_logic.h" |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 35 | #include "gallivm/lp_bld_tgsi.h" |
Christian König | 5e616cf | 2013-03-07 11:58:56 +0100 | [diff] [blame] | 36 | #include "gallivm/lp_bld_arit.h" |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 37 | #include "radeon_llvm.h" |
Tom Stellard | 509ddb0 | 2012-04-16 17:48:44 -0400 | [diff] [blame] | 38 | #include "radeon_llvm_emit.h" |
Christian König | 0f6cf2b | 2013-03-15 15:53:25 +0100 | [diff] [blame] | 39 | #include "util/u_memory.h" |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 40 | #include "tgsi/tgsi_info.h" |
| 41 | #include "tgsi/tgsi_parse.h" |
| 42 | #include "tgsi/tgsi_scan.h" |
| 43 | #include "tgsi/tgsi_dump.h" |
| 44 | |
| 45 | #include "radeonsi_pipe.h" |
| 46 | #include "radeonsi_shader.h" |
Christian König | f67fae0 | 2012-07-17 23:43:00 +0200 | [diff] [blame] | 47 | #include "si_state.h" |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 48 | #include "sid.h" |
| 49 | |
| 50 | #include <assert.h> |
| 51 | #include <errno.h> |
| 52 | #include <stdio.h> |
| 53 | |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 54 | struct si_shader_context |
| 55 | { |
| 56 | struct radeon_llvm_context radeon_bld; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 57 | struct tgsi_parse_context parse; |
| 58 | struct tgsi_token * tokens; |
| 59 | struct si_pipe_shader *shader; |
| 60 | unsigned type; /* TGSI_PROCESSOR_* specifies the type of shader. */ |
Christian König | 206f059 | 2013-03-20 14:37:21 +0100 | [diff] [blame] | 61 | LLVMValueRef const_md; |
Christian König | 0f6cf2b | 2013-03-15 15:53:25 +0100 | [diff] [blame] | 62 | LLVMValueRef const_resource; |
| 63 | LLVMValueRef *constants; |
Christian König | 1c10018 | 2013-03-17 16:02:42 +0100 | [diff] [blame] | 64 | LLVMValueRef *resources; |
| 65 | LLVMValueRef *samplers; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | static struct si_shader_context * si_shader_context( |
| 69 | struct lp_build_tgsi_context * bld_base) |
| 70 | { |
| 71 | return (struct si_shader_context *)bld_base; |
| 72 | } |
| 73 | |
| 74 | |
| 75 | #define PERSPECTIVE_BASE 0 |
| 76 | #define LINEAR_BASE 9 |
| 77 | |
| 78 | #define SAMPLE_OFFSET 0 |
| 79 | #define CENTER_OFFSET 2 |
| 80 | #define CENTROID_OFSET 4 |
| 81 | |
| 82 | #define USE_SGPR_MAX_SUFFIX_LEN 5 |
Tom Stellard | 467f516 | 2012-05-16 15:15:35 -0400 | [diff] [blame] | 83 | #define CONST_ADDR_SPACE 2 |
Tom Stellard | 89ece08 | 2012-05-29 11:36:29 -0400 | [diff] [blame] | 84 | #define USER_SGPR_ADDR_SPACE 8 |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 85 | |
Tom Stellard | 467f516 | 2012-05-16 15:15:35 -0400 | [diff] [blame] | 86 | /** |
| 87 | * Build an LLVM bytecode indexed load using LLVMBuildGEP + LLVMBuildLoad |
| 88 | * |
| 89 | * @param offset The offset parameter specifies the number of |
| 90 | * elements to offset, not the number of bytes or dwords. An element is the |
| 91 | * the type pointed to by the base_ptr parameter (e.g. int is the element of |
| 92 | * an int* pointer) |
| 93 | * |
| 94 | * When LLVM lowers the load instruction, it will convert the element offset |
| 95 | * into a dword offset automatically. |
| 96 | * |
| 97 | */ |
| 98 | static LLVMValueRef build_indexed_load( |
Christian König | 206f059 | 2013-03-20 14:37:21 +0100 | [diff] [blame] | 99 | struct si_shader_context * si_shader_ctx, |
Tom Stellard | 467f516 | 2012-05-16 15:15:35 -0400 | [diff] [blame] | 100 | LLVMValueRef base_ptr, |
| 101 | LLVMValueRef offset) |
| 102 | { |
Christian König | 206f059 | 2013-03-20 14:37:21 +0100 | [diff] [blame] | 103 | struct lp_build_context * base = &si_shader_ctx->radeon_bld.soa.bld_base.base; |
Tom Stellard | 467f516 | 2012-05-16 15:15:35 -0400 | [diff] [blame] | 104 | |
Christian König | 206f059 | 2013-03-20 14:37:21 +0100 | [diff] [blame] | 105 | LLVMValueRef computed_ptr = LLVMBuildGEP( |
| 106 | base->gallivm->builder, base_ptr, &offset, 1, ""); |
| 107 | |
| 108 | LLVMValueRef result = LLVMBuildLoad(base->gallivm->builder, computed_ptr, ""); |
| 109 | LLVMSetMetadata(result, 1, si_shader_ctx->const_md); |
| 110 | return result; |
Tom Stellard | 467f516 | 2012-05-16 15:15:35 -0400 | [diff] [blame] | 111 | } |
| 112 | |
Christian König | a0dca44 | 2013-03-22 15:59:22 +0100 | [diff] [blame] | 113 | static LLVMValueRef get_instance_index( |
| 114 | struct radeon_llvm_context * radeon_bld, |
| 115 | unsigned divisor) |
| 116 | { |
| 117 | struct gallivm_state * gallivm = radeon_bld->soa.bld_base.base.gallivm; |
| 118 | |
| 119 | LLVMValueRef result = LLVMGetParam(radeon_bld->main_fn, SI_PARAM_INSTANCE_ID); |
| 120 | result = LLVMBuildAdd(gallivm->builder, result, LLVMGetParam( |
| 121 | radeon_bld->main_fn, SI_PARAM_START_INSTANCE), ""); |
| 122 | |
| 123 | if (divisor > 1) |
| 124 | result = LLVMBuildUDiv(gallivm->builder, result, |
| 125 | lp_build_const_int32(gallivm, divisor), ""); |
| 126 | |
| 127 | return result; |
| 128 | } |
| 129 | |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 130 | static void declare_input_vs( |
| 131 | struct si_shader_context * si_shader_ctx, |
| 132 | unsigned input_index, |
| 133 | const struct tgsi_full_declaration *decl) |
| 134 | { |
Christian König | a0dca44 | 2013-03-22 15:59:22 +0100 | [diff] [blame] | 135 | struct lp_build_context * base = &si_shader_ctx->radeon_bld.soa.bld_base.base; |
| 136 | unsigned divisor = si_shader_ctx->shader->key.vs.instance_divisors[input_index]; |
| 137 | |
| 138 | unsigned chan; |
| 139 | |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 140 | LLVMValueRef t_list_ptr; |
| 141 | LLVMValueRef t_offset; |
Tom Stellard | 467f516 | 2012-05-16 15:15:35 -0400 | [diff] [blame] | 142 | LLVMValueRef t_list; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 143 | LLVMValueRef attribute_offset; |
Christian König | a0dca44 | 2013-03-22 15:59:22 +0100 | [diff] [blame] | 144 | LLVMValueRef buffer_index; |
Tom Stellard | 467f516 | 2012-05-16 15:15:35 -0400 | [diff] [blame] | 145 | LLVMValueRef args[3]; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 146 | LLVMTypeRef vec4_type; |
| 147 | LLVMValueRef input; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 148 | |
Tom Stellard | 467f516 | 2012-05-16 15:15:35 -0400 | [diff] [blame] | 149 | /* Load the T list */ |
Christian König | 55fe5cc | 2013-03-04 16:30:06 +0100 | [diff] [blame] | 150 | t_list_ptr = LLVMGetParam(si_shader_ctx->radeon_bld.main_fn, SI_PARAM_VERTEX_BUFFER); |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 151 | |
Christian König | b15e3ae | 2012-07-25 11:22:59 +0200 | [diff] [blame] | 152 | t_offset = lp_build_const_int32(base->gallivm, input_index); |
Tom Stellard | 467f516 | 2012-05-16 15:15:35 -0400 | [diff] [blame] | 153 | |
Christian König | 206f059 | 2013-03-20 14:37:21 +0100 | [diff] [blame] | 154 | t_list = build_indexed_load(si_shader_ctx, t_list_ptr, t_offset); |
Tom Stellard | 467f516 | 2012-05-16 15:15:35 -0400 | [diff] [blame] | 155 | |
| 156 | /* Build the attribute offset */ |
Christian König | b15e3ae | 2012-07-25 11:22:59 +0200 | [diff] [blame] | 157 | attribute_offset = lp_build_const_int32(base->gallivm, 0); |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 158 | |
Christian König | a0dca44 | 2013-03-22 15:59:22 +0100 | [diff] [blame] | 159 | if (divisor) { |
| 160 | /* Build index from instance ID, start instance and divisor */ |
| 161 | si_shader_ctx->shader->shader.uses_instanceid = true; |
| 162 | buffer_index = get_instance_index(&si_shader_ctx->radeon_bld, divisor); |
| 163 | } else { |
| 164 | /* Load the buffer index, which is always stored in VGPR0 |
| 165 | * for Vertex Shaders */ |
| 166 | buffer_index = LLVMGetParam(si_shader_ctx->radeon_bld.main_fn, SI_PARAM_VERTEX_ID); |
| 167 | } |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 168 | |
| 169 | vec4_type = LLVMVectorType(base->elem_type, 4); |
Tom Stellard | 467f516 | 2012-05-16 15:15:35 -0400 | [diff] [blame] | 170 | args[0] = t_list; |
| 171 | args[1] = attribute_offset; |
Christian König | a0dca44 | 2013-03-22 15:59:22 +0100 | [diff] [blame] | 172 | args[2] = buffer_index; |
Christian König | 44e3224 | 2013-03-20 12:10:35 +0100 | [diff] [blame] | 173 | input = build_intrinsic(base->gallivm->builder, |
| 174 | "llvm.SI.vs.load.input", vec4_type, args, 3, |
| 175 | LLVMReadNoneAttribute | LLVMNoUnwindAttribute); |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 176 | |
| 177 | /* Break up the vec4 into individual components */ |
| 178 | for (chan = 0; chan < 4; chan++) { |
| 179 | LLVMValueRef llvm_chan = lp_build_const_int32(base->gallivm, chan); |
| 180 | /* XXX: Use a helper function for this. There is one in |
| 181 | * tgsi_llvm.c. */ |
| 182 | si_shader_ctx->radeon_bld.inputs[radeon_llvm_reg_index_soa(input_index, chan)] = |
| 183 | LLVMBuildExtractElement(base->gallivm->builder, |
| 184 | input, llvm_chan, ""); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | static void declare_input_fs( |
| 189 | struct si_shader_context * si_shader_ctx, |
| 190 | unsigned input_index, |
| 191 | const struct tgsi_full_declaration *decl) |
| 192 | { |
Michel Dänzer | c3db19e | 2012-09-27 20:01:33 +0200 | [diff] [blame] | 193 | struct si_shader *shader = &si_shader_ctx->shader->shader; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 194 | struct lp_build_context * base = |
| 195 | &si_shader_ctx->radeon_bld.soa.bld_base.base; |
| 196 | struct gallivm_state * gallivm = base->gallivm; |
Tom Stellard | 0fb1e68 | 2012-09-06 16:18:11 -0400 | [diff] [blame] | 197 | LLVMTypeRef input_type = LLVMFloatTypeInContext(gallivm->context); |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 198 | LLVMValueRef main_fn = si_shader_ctx->radeon_bld.main_fn; |
| 199 | |
| 200 | LLVMValueRef interp_param; |
| 201 | const char * intr_name; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 202 | |
| 203 | /* This value is: |
| 204 | * [15:0] NewPrimMask (Bit mask for each quad. It is set it the |
| 205 | * quad begins a new primitive. Bit 0 always needs |
| 206 | * to be unset) |
| 207 | * [32:16] ParamOffset |
| 208 | * |
| 209 | */ |
Christian König | 55fe5cc | 2013-03-04 16:30:06 +0100 | [diff] [blame] | 210 | LLVMValueRef params = LLVMGetParam(si_shader_ctx->radeon_bld.main_fn, SI_PARAM_PRIM_MASK); |
Michel Dänzer | c3db19e | 2012-09-27 20:01:33 +0200 | [diff] [blame] | 211 | LLVMValueRef attr_number; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 212 | |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 213 | unsigned chan; |
| 214 | |
Tom Stellard | 0fb1e68 | 2012-09-06 16:18:11 -0400 | [diff] [blame] | 215 | if (decl->Semantic.Name == TGSI_SEMANTIC_POSITION) { |
| 216 | for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) { |
Tom Stellard | 0fb1e68 | 2012-09-06 16:18:11 -0400 | [diff] [blame] | 217 | unsigned soa_index = |
| 218 | radeon_llvm_reg_index_soa(input_index, chan); |
Tom Stellard | 0fb1e68 | 2012-09-06 16:18:11 -0400 | [diff] [blame] | 219 | si_shader_ctx->radeon_bld.inputs[soa_index] = |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 220 | LLVMGetParam(main_fn, SI_PARAM_POS_X_FLOAT + chan); |
Michel Dänzer | 954bc4a | 2013-02-13 15:57:23 +0100 | [diff] [blame] | 221 | |
| 222 | if (chan == 3) |
| 223 | /* RCP for fragcoord.w */ |
| 224 | si_shader_ctx->radeon_bld.inputs[soa_index] = |
| 225 | LLVMBuildFDiv(gallivm->builder, |
| 226 | lp_build_const_float(gallivm, 1.0f), |
| 227 | si_shader_ctx->radeon_bld.inputs[soa_index], |
| 228 | ""); |
Tom Stellard | 0fb1e68 | 2012-09-06 16:18:11 -0400 | [diff] [blame] | 229 | } |
| 230 | return; |
| 231 | } |
| 232 | |
Michel Dänzer | 97078b1 | 2012-09-25 12:41:31 +0200 | [diff] [blame] | 233 | if (decl->Semantic.Name == TGSI_SEMANTIC_FACE) { |
| 234 | LLVMValueRef face, is_face_positive; |
| 235 | |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 236 | face = LLVMGetParam(main_fn, SI_PARAM_FRONT_FACE); |
| 237 | |
Michel Dänzer | 97078b1 | 2012-09-25 12:41:31 +0200 | [diff] [blame] | 238 | is_face_positive = LLVMBuildFCmp(gallivm->builder, |
| 239 | LLVMRealUGT, face, |
| 240 | lp_build_const_float(gallivm, 0.0f), |
| 241 | ""); |
| 242 | |
| 243 | si_shader_ctx->radeon_bld.inputs[radeon_llvm_reg_index_soa(input_index, 0)] = |
| 244 | LLVMBuildSelect(gallivm->builder, |
| 245 | is_face_positive, |
| 246 | lp_build_const_float(gallivm, 1.0f), |
| 247 | lp_build_const_float(gallivm, 0.0f), |
| 248 | ""); |
| 249 | si_shader_ctx->radeon_bld.inputs[radeon_llvm_reg_index_soa(input_index, 1)] = |
| 250 | si_shader_ctx->radeon_bld.inputs[radeon_llvm_reg_index_soa(input_index, 2)] = |
| 251 | lp_build_const_float(gallivm, 0.0f); |
| 252 | si_shader_ctx->radeon_bld.inputs[radeon_llvm_reg_index_soa(input_index, 3)] = |
| 253 | lp_build_const_float(gallivm, 1.0f); |
| 254 | |
| 255 | return; |
| 256 | } |
| 257 | |
Michel Dänzer | c3db19e | 2012-09-27 20:01:33 +0200 | [diff] [blame] | 258 | shader->input[input_index].param_offset = shader->ninterp++; |
| 259 | attr_number = lp_build_const_int32(gallivm, |
| 260 | shader->input[input_index].param_offset); |
| 261 | |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 262 | /* XXX: Handle all possible interpolation modes */ |
Francisco Jerez | 1279923 | 2012-04-30 18:27:52 +0200 | [diff] [blame] | 263 | switch (decl->Interp.Interpolate) { |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 264 | case TGSI_INTERPOLATE_COLOR: |
Christian König | a0dca44 | 2013-03-22 15:59:22 +0100 | [diff] [blame] | 265 | if (si_shader_ctx->shader->key.ps.flatshade) { |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 266 | interp_param = 0; |
Michel Dänzer | 1deb2be | 2012-05-14 16:26:19 +0200 | [diff] [blame] | 267 | } else { |
| 268 | if (decl->Interp.Centroid) |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 269 | interp_param = LLVMGetParam(main_fn, SI_PARAM_PERSP_CENTROID); |
Michel Dänzer | 1deb2be | 2012-05-14 16:26:19 +0200 | [diff] [blame] | 270 | else |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 271 | interp_param = LLVMGetParam(main_fn, SI_PARAM_PERSP_CENTER); |
Michel Dänzer | 1deb2be | 2012-05-14 16:26:19 +0200 | [diff] [blame] | 272 | } |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 273 | break; |
| 274 | case TGSI_INTERPOLATE_CONSTANT: |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 275 | interp_param = 0; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 276 | break; |
| 277 | case TGSI_INTERPOLATE_LINEAR: |
Michel Dänzer | 1deb2be | 2012-05-14 16:26:19 +0200 | [diff] [blame] | 278 | if (decl->Interp.Centroid) |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 279 | interp_param = LLVMGetParam(main_fn, SI_PARAM_LINEAR_CENTROID); |
Michel Dänzer | 1deb2be | 2012-05-14 16:26:19 +0200 | [diff] [blame] | 280 | else |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 281 | interp_param = LLVMGetParam(main_fn, SI_PARAM_LINEAR_CENTER); |
Michel Dänzer | 1deb2be | 2012-05-14 16:26:19 +0200 | [diff] [blame] | 282 | break; |
| 283 | case TGSI_INTERPOLATE_PERSPECTIVE: |
| 284 | if (decl->Interp.Centroid) |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 285 | interp_param = LLVMGetParam(main_fn, SI_PARAM_PERSP_CENTROID); |
Michel Dänzer | 1deb2be | 2012-05-14 16:26:19 +0200 | [diff] [blame] | 286 | else |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 287 | interp_param = LLVMGetParam(main_fn, SI_PARAM_PERSP_CENTER); |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 288 | break; |
| 289 | default: |
| 290 | fprintf(stderr, "Warning: Unhandled interpolation mode.\n"); |
| 291 | return; |
| 292 | } |
| 293 | |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 294 | intr_name = interp_param ? "llvm.SI.fs.interp" : "llvm.SI.fs.constant"; |
| 295 | |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 296 | /* XXX: Could there be more than TGSI_NUM_CHANNELS (4) ? */ |
Michel Dänzer | 691f08d | 2012-09-06 18:03:38 +0200 | [diff] [blame] | 297 | if (decl->Semantic.Name == TGSI_SEMANTIC_COLOR && |
Christian König | a0dca44 | 2013-03-22 15:59:22 +0100 | [diff] [blame] | 298 | si_shader_ctx->shader->key.ps.color_two_side) { |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 299 | LLVMValueRef args[4]; |
Michel Dänzer | 691f08d | 2012-09-06 18:03:38 +0200 | [diff] [blame] | 300 | LLVMValueRef face, is_face_positive; |
| 301 | LLVMValueRef back_attr_number = |
| 302 | lp_build_const_int32(gallivm, |
| 303 | shader->input[input_index].param_offset + 1); |
| 304 | |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 305 | face = LLVMGetParam(main_fn, SI_PARAM_FRONT_FACE); |
| 306 | |
Michel Dänzer | 691f08d | 2012-09-06 18:03:38 +0200 | [diff] [blame] | 307 | is_face_positive = LLVMBuildFCmp(gallivm->builder, |
| 308 | LLVMRealUGT, face, |
| 309 | lp_build_const_float(gallivm, 0.0f), |
| 310 | ""); |
| 311 | |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 312 | args[2] = params; |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 313 | args[3] = interp_param; |
Michel Dänzer | 691f08d | 2012-09-06 18:03:38 +0200 | [diff] [blame] | 314 | for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) { |
| 315 | LLVMValueRef llvm_chan = lp_build_const_int32(gallivm, chan); |
| 316 | unsigned soa_index = radeon_llvm_reg_index_soa(input_index, chan); |
| 317 | LLVMValueRef front, back; |
| 318 | |
| 319 | args[0] = llvm_chan; |
| 320 | args[1] = attr_number; |
| 321 | front = build_intrinsic(base->gallivm->builder, intr_name, |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 322 | input_type, args, args[3] ? 4 : 3, |
Christian König | 44e3224 | 2013-03-20 12:10:35 +0100 | [diff] [blame] | 323 | LLVMReadNoneAttribute | LLVMNoUnwindAttribute); |
Michel Dänzer | 691f08d | 2012-09-06 18:03:38 +0200 | [diff] [blame] | 324 | |
| 325 | args[1] = back_attr_number; |
| 326 | back = build_intrinsic(base->gallivm->builder, intr_name, |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 327 | input_type, args, args[3] ? 4 : 3, |
Christian König | 44e3224 | 2013-03-20 12:10:35 +0100 | [diff] [blame] | 328 | LLVMReadNoneAttribute | LLVMNoUnwindAttribute); |
Michel Dänzer | 691f08d | 2012-09-06 18:03:38 +0200 | [diff] [blame] | 329 | |
| 330 | si_shader_ctx->radeon_bld.inputs[soa_index] = |
| 331 | LLVMBuildSelect(gallivm->builder, |
| 332 | is_face_positive, |
| 333 | front, |
| 334 | back, |
| 335 | ""); |
| 336 | } |
| 337 | |
| 338 | shader->ninterp++; |
| 339 | } else { |
| 340 | for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) { |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 341 | LLVMValueRef args[4]; |
Michel Dänzer | 691f08d | 2012-09-06 18:03:38 +0200 | [diff] [blame] | 342 | LLVMValueRef llvm_chan = lp_build_const_int32(gallivm, chan); |
| 343 | unsigned soa_index = radeon_llvm_reg_index_soa(input_index, chan); |
| 344 | args[0] = llvm_chan; |
| 345 | args[1] = attr_number; |
| 346 | args[2] = params; |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 347 | args[3] = interp_param; |
Michel Dänzer | 691f08d | 2012-09-06 18:03:38 +0200 | [diff] [blame] | 348 | si_shader_ctx->radeon_bld.inputs[soa_index] = |
| 349 | build_intrinsic(base->gallivm->builder, intr_name, |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 350 | input_type, args, args[3] ? 4 : 3, |
Christian König | 44e3224 | 2013-03-20 12:10:35 +0100 | [diff] [blame] | 351 | LLVMReadNoneAttribute | LLVMNoUnwindAttribute); |
Michel Dänzer | 691f08d | 2012-09-06 18:03:38 +0200 | [diff] [blame] | 352 | } |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
| 356 | static void declare_input( |
| 357 | struct radeon_llvm_context * radeon_bld, |
| 358 | unsigned input_index, |
| 359 | const struct tgsi_full_declaration *decl) |
| 360 | { |
| 361 | struct si_shader_context * si_shader_ctx = |
| 362 | si_shader_context(&radeon_bld->soa.bld_base); |
| 363 | if (si_shader_ctx->type == TGSI_PROCESSOR_VERTEX) { |
| 364 | declare_input_vs(si_shader_ctx, input_index, decl); |
| 365 | } else if (si_shader_ctx->type == TGSI_PROCESSOR_FRAGMENT) { |
| 366 | declare_input_fs(si_shader_ctx, input_index, decl); |
| 367 | } else { |
| 368 | fprintf(stderr, "Warning: Unsupported shader type,\n"); |
| 369 | } |
| 370 | } |
| 371 | |
Christian König | e4ed587 | 2013-03-21 18:02:52 +0100 | [diff] [blame] | 372 | static void declare_system_value( |
| 373 | struct radeon_llvm_context * radeon_bld, |
| 374 | unsigned index, |
| 375 | const struct tgsi_full_declaration *decl) |
| 376 | { |
Christian König | cf9b31f | 2013-03-21 18:30:23 +0100 | [diff] [blame] | 377 | |
Christian König | e4ed587 | 2013-03-21 18:02:52 +0100 | [diff] [blame] | 378 | LLVMValueRef value = 0; |
| 379 | |
| 380 | switch (decl->Semantic.Name) { |
| 381 | case TGSI_SEMANTIC_INSTANCEID: |
Christian König | a0dca44 | 2013-03-22 15:59:22 +0100 | [diff] [blame] | 382 | value = get_instance_index(radeon_bld, 1); |
Christian König | e4ed587 | 2013-03-21 18:02:52 +0100 | [diff] [blame] | 383 | break; |
| 384 | |
| 385 | case TGSI_SEMANTIC_VERTEXID: |
| 386 | value = LLVMGetParam(radeon_bld->main_fn, SI_PARAM_VERTEX_ID); |
| 387 | break; |
| 388 | |
| 389 | default: |
| 390 | assert(!"unknown system value"); |
| 391 | return; |
| 392 | } |
| 393 | |
| 394 | radeon_bld->system_values[index] = value; |
| 395 | } |
| 396 | |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 397 | static LLVMValueRef fetch_constant( |
| 398 | struct lp_build_tgsi_context * bld_base, |
| 399 | const struct tgsi_full_src_register *reg, |
| 400 | enum tgsi_opcode_type type, |
| 401 | unsigned swizzle) |
| 402 | { |
Christian König | 55fe5cc | 2013-03-04 16:30:06 +0100 | [diff] [blame] | 403 | struct si_shader_context *si_shader_ctx = si_shader_context(bld_base); |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 404 | struct lp_build_context * base = &bld_base->base; |
Christian König | 0f6cf2b | 2013-03-15 15:53:25 +0100 | [diff] [blame] | 405 | const struct tgsi_ind_register *ireg = ®->Indirect; |
| 406 | unsigned idx; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 407 | |
Christian König | f5298b0 | 2013-02-28 14:50:07 +0100 | [diff] [blame] | 408 | LLVMValueRef args[2]; |
Christian König | 0f6cf2b | 2013-03-15 15:53:25 +0100 | [diff] [blame] | 409 | LLVMValueRef addr; |
Christian König | f5298b0 | 2013-02-28 14:50:07 +0100 | [diff] [blame] | 410 | LLVMValueRef result; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 411 | |
Christian König | 8514f5a | 2013-02-04 17:46:42 +0100 | [diff] [blame] | 412 | if (swizzle == LP_CHAN_ALL) { |
| 413 | unsigned chan; |
| 414 | LLVMValueRef values[4]; |
| 415 | for (chan = 0; chan < TGSI_NUM_CHANNELS; ++chan) |
| 416 | values[chan] = fetch_constant(bld_base, reg, type, chan); |
| 417 | |
| 418 | return lp_build_gather_values(bld_base->base.gallivm, values, 4); |
| 419 | } |
| 420 | |
Christian König | 0f6cf2b | 2013-03-15 15:53:25 +0100 | [diff] [blame] | 421 | idx = reg->Register.Index * 4 + swizzle; |
| 422 | if (!reg->Register.Indirect) |
| 423 | return bitcast(bld_base, type, si_shader_ctx->constants[idx]); |
Christian König | f5298b0 | 2013-02-28 14:50:07 +0100 | [diff] [blame] | 424 | |
Christian König | 0f6cf2b | 2013-03-15 15:53:25 +0100 | [diff] [blame] | 425 | args[0] = si_shader_ctx->const_resource; |
| 426 | args[1] = lp_build_const_int32(base->gallivm, idx * 4); |
| 427 | addr = si_shader_ctx->radeon_bld.soa.addr[ireg->Index][ireg->Swizzle]; |
| 428 | addr = LLVMBuildLoad(base->gallivm->builder, addr, "load addr reg"); |
| 429 | addr = lp_build_mul_imm(&bld_base->uint_bld, addr, 16); |
| 430 | args[1] = lp_build_add(&bld_base->uint_bld, addr, args[1]); |
Christian König | e7723b5 | 2012-08-24 12:55:34 +0200 | [diff] [blame] | 431 | |
Christian König | f5298b0 | 2013-02-28 14:50:07 +0100 | [diff] [blame] | 432 | result = build_intrinsic(base->gallivm->builder, "llvm.SI.load.const", base->elem_type, |
Christian König | 44e3224 | 2013-03-20 12:10:35 +0100 | [diff] [blame] | 433 | args, 2, LLVMReadNoneAttribute | LLVMNoUnwindAttribute); |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 434 | |
Christian König | f5298b0 | 2013-02-28 14:50:07 +0100 | [diff] [blame] | 435 | return bitcast(bld_base, type, result); |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 436 | } |
| 437 | |
Michel Dänzer | 26c7139 | 2012-08-24 12:03:11 +0200 | [diff] [blame] | 438 | /* Initialize arguments for the shader export intrinsic */ |
| 439 | static void si_llvm_init_export_args(struct lp_build_tgsi_context *bld_base, |
| 440 | struct tgsi_full_declaration *d, |
| 441 | unsigned index, |
| 442 | unsigned target, |
| 443 | LLVMValueRef *args) |
| 444 | { |
| 445 | struct si_shader_context *si_shader_ctx = si_shader_context(bld_base); |
| 446 | struct lp_build_context *uint = |
| 447 | &si_shader_ctx->radeon_bld.soa.bld_base.uint_bld; |
| 448 | struct lp_build_context *base = &bld_base->base; |
| 449 | unsigned compressed = 0; |
| 450 | unsigned chan; |
| 451 | |
Michel Dänzer | f402acd | 2012-08-22 18:15:36 +0200 | [diff] [blame] | 452 | if (si_shader_ctx->type == TGSI_PROCESSOR_FRAGMENT) { |
| 453 | int cbuf = target - V_008DFC_SQ_EXP_MRT; |
| 454 | |
| 455 | if (cbuf >= 0 && cbuf < 8) { |
Christian König | a0dca44 | 2013-03-22 15:59:22 +0100 | [diff] [blame] | 456 | compressed = (si_shader_ctx->shader->key.ps.export_16bpc >> cbuf) & 0x1; |
Michel Dänzer | 1ace200 | 2012-12-21 15:39:26 +0100 | [diff] [blame] | 457 | |
| 458 | if (compressed) |
| 459 | si_shader_ctx->shader->spi_shader_col_format |= |
| 460 | V_028714_SPI_SHADER_FP16_ABGR << (4 * cbuf); |
| 461 | else |
| 462 | si_shader_ctx->shader->spi_shader_col_format |= |
| 463 | V_028714_SPI_SHADER_32_ABGR << (4 * cbuf); |
Michel Dänzer | f402acd | 2012-08-22 18:15:36 +0200 | [diff] [blame] | 464 | } |
| 465 | } |
| 466 | |
| 467 | if (compressed) { |
| 468 | /* Pixel shader needs to pack output values before export */ |
| 469 | for (chan = 0; chan < 2; chan++ ) { |
| 470 | LLVMValueRef *out_ptr = |
| 471 | si_shader_ctx->radeon_bld.soa.outputs[index]; |
| 472 | args[0] = LLVMBuildLoad(base->gallivm->builder, |
| 473 | out_ptr[2 * chan], ""); |
| 474 | args[1] = LLVMBuildLoad(base->gallivm->builder, |
| 475 | out_ptr[2 * chan + 1], ""); |
| 476 | args[chan + 5] = |
| 477 | build_intrinsic(base->gallivm->builder, |
| 478 | "llvm.SI.packf16", |
| 479 | LLVMInt32TypeInContext(base->gallivm->context), |
| 480 | args, 2, |
Christian König | e4188ee | 2013-02-27 22:39:26 +0100 | [diff] [blame] | 481 | LLVMReadNoneAttribute | LLVMNoUnwindAttribute); |
Michel Dänzer | 8b6aec6 | 2012-11-27 19:53:58 +0100 | [diff] [blame] | 482 | args[chan + 7] = args[chan + 5] = |
| 483 | LLVMBuildBitCast(base->gallivm->builder, |
| 484 | args[chan + 5], |
| 485 | LLVMFloatTypeInContext(base->gallivm->context), |
| 486 | ""); |
Michel Dänzer | f402acd | 2012-08-22 18:15:36 +0200 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | /* Set COMPR flag */ |
| 490 | args[4] = uint->one; |
| 491 | } else { |
| 492 | for (chan = 0; chan < 4; chan++ ) { |
| 493 | LLVMValueRef out_ptr = |
| 494 | si_shader_ctx->radeon_bld.soa.outputs[index][chan]; |
| 495 | /* +5 because the first output value will be |
| 496 | * the 6th argument to the intrinsic. */ |
| 497 | args[chan + 5] = LLVMBuildLoad(base->gallivm->builder, |
| 498 | out_ptr, ""); |
| 499 | } |
| 500 | |
| 501 | /* Clear COMPR flag */ |
| 502 | args[4] = uint->zero; |
Michel Dänzer | 26c7139 | 2012-08-24 12:03:11 +0200 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | /* XXX: This controls which components of the output |
| 506 | * registers actually get exported. (e.g bit 0 means export |
| 507 | * X component, bit 1 means export Y component, etc.) I'm |
| 508 | * hard coding this to 0xf for now. In the future, we might |
| 509 | * want to do something else. */ |
| 510 | args[0] = lp_build_const_int32(base->gallivm, 0xf); |
| 511 | |
| 512 | /* Specify whether the EXEC mask represents the valid mask */ |
| 513 | args[1] = uint->zero; |
| 514 | |
| 515 | /* Specify whether this is the last export */ |
| 516 | args[2] = uint->zero; |
| 517 | |
| 518 | /* Specify the target we are exporting */ |
| 519 | args[3] = lp_build_const_int32(base->gallivm, target); |
| 520 | |
Michel Dänzer | 26c7139 | 2012-08-24 12:03:11 +0200 | [diff] [blame] | 521 | /* XXX: We probably need to keep track of the output |
| 522 | * values, so we know what we are passing to the next |
| 523 | * stage. */ |
| 524 | } |
| 525 | |
Michel Dänzer | 7708a86 | 2012-11-02 15:57:30 +0100 | [diff] [blame] | 526 | static void si_alpha_test(struct lp_build_tgsi_context *bld_base, |
| 527 | unsigned index) |
| 528 | { |
| 529 | struct si_shader_context *si_shader_ctx = si_shader_context(bld_base); |
| 530 | struct gallivm_state *gallivm = bld_base->base.gallivm; |
| 531 | |
Christian König | a0dca44 | 2013-03-22 15:59:22 +0100 | [diff] [blame] | 532 | if (si_shader_ctx->shader->key.ps.alpha_func != PIPE_FUNC_NEVER) { |
Michel Dänzer | 7708a86 | 2012-11-02 15:57:30 +0100 | [diff] [blame] | 533 | LLVMValueRef out_ptr = si_shader_ctx->radeon_bld.soa.outputs[index][3]; |
| 534 | LLVMValueRef alpha_pass = |
| 535 | lp_build_cmp(&bld_base->base, |
Christian König | a0dca44 | 2013-03-22 15:59:22 +0100 | [diff] [blame] | 536 | si_shader_ctx->shader->key.ps.alpha_func, |
Michel Dänzer | 7708a86 | 2012-11-02 15:57:30 +0100 | [diff] [blame] | 537 | LLVMBuildLoad(gallivm->builder, out_ptr, ""), |
Christian König | a0dca44 | 2013-03-22 15:59:22 +0100 | [diff] [blame] | 538 | lp_build_const_float(gallivm, si_shader_ctx->shader->key.ps.alpha_ref)); |
Michel Dänzer | 7708a86 | 2012-11-02 15:57:30 +0100 | [diff] [blame] | 539 | LLVMValueRef arg = |
| 540 | lp_build_select(&bld_base->base, |
| 541 | alpha_pass, |
| 542 | lp_build_const_float(gallivm, 1.0f), |
| 543 | lp_build_const_float(gallivm, -1.0f)); |
| 544 | |
| 545 | build_intrinsic(gallivm->builder, |
| 546 | "llvm.AMDGPU.kill", |
| 547 | LLVMVoidTypeInContext(gallivm->context), |
| 548 | &arg, 1, 0); |
| 549 | } else { |
| 550 | build_intrinsic(gallivm->builder, |
| 551 | "llvm.AMDGPU.kilp", |
| 552 | LLVMVoidTypeInContext(gallivm->context), |
| 553 | NULL, 0, 0); |
| 554 | } |
| 555 | } |
| 556 | |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 557 | /* XXX: This is partially implemented for VS only at this point. It is not complete */ |
| 558 | static void si_llvm_emit_epilogue(struct lp_build_tgsi_context * bld_base) |
| 559 | { |
| 560 | struct si_shader_context * si_shader_ctx = si_shader_context(bld_base); |
Christian König | 3c09f11 | 2012-07-18 17:39:15 +0200 | [diff] [blame] | 561 | struct si_shader * shader = &si_shader_ctx->shader->shader; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 562 | struct lp_build_context * base = &bld_base->base; |
| 563 | struct lp_build_context * uint = |
| 564 | &si_shader_ctx->radeon_bld.soa.bld_base.uint_bld; |
| 565 | struct tgsi_parse_context *parse = &si_shader_ctx->parse; |
Michel Dänzer | 1a616c1 | 2012-11-13 17:35:09 +0100 | [diff] [blame] | 566 | LLVMValueRef args[9]; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 567 | LLVMValueRef last_args[9] = { 0 }; |
Christian König | 3508815 | 2012-08-01 22:35:24 +0200 | [diff] [blame] | 568 | unsigned color_count = 0; |
| 569 | unsigned param_count = 0; |
Michel Dänzer | 1a616c1 | 2012-11-13 17:35:09 +0100 | [diff] [blame] | 570 | int depth_index = -1, stencil_index = -1; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 571 | |
| 572 | while (!tgsi_parse_end_of_tokens(parse)) { |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 573 | struct tgsi_full_declaration *d = |
| 574 | &parse->FullToken.FullDeclaration; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 575 | unsigned target; |
| 576 | unsigned index; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 577 | int i; |
| 578 | |
| 579 | tgsi_parse_token(parse); |
Michel Dänzer | c840270 | 2013-02-12 18:37:22 +0100 | [diff] [blame] | 580 | |
| 581 | if (parse->FullToken.Token.Type == TGSI_TOKEN_TYPE_PROPERTY && |
| 582 | parse->FullToken.FullProperty.Property.PropertyName == |
| 583 | TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS) |
| 584 | shader->fs_write_all = TRUE; |
| 585 | |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 586 | if (parse->FullToken.Token.Type != TGSI_TOKEN_TYPE_DECLARATION) |
| 587 | continue; |
| 588 | |
| 589 | switch (d->Declaration.File) { |
| 590 | case TGSI_FILE_INPUT: |
| 591 | i = shader->ninput++; |
| 592 | shader->input[i].name = d->Semantic.Name; |
| 593 | shader->input[i].sid = d->Semantic.Index; |
Francisco Jerez | 1279923 | 2012-04-30 18:27:52 +0200 | [diff] [blame] | 594 | shader->input[i].interpolate = d->Interp.Interpolate; |
| 595 | shader->input[i].centroid = d->Interp.Centroid; |
Christian König | 3508815 | 2012-08-01 22:35:24 +0200 | [diff] [blame] | 596 | continue; |
| 597 | |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 598 | case TGSI_FILE_OUTPUT: |
| 599 | i = shader->noutput++; |
| 600 | shader->output[i].name = d->Semantic.Name; |
| 601 | shader->output[i].sid = d->Semantic.Index; |
Francisco Jerez | 1279923 | 2012-04-30 18:27:52 +0200 | [diff] [blame] | 602 | shader->output[i].interpolate = d->Interp.Interpolate; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 603 | break; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 604 | |
Christian König | 3508815 | 2012-08-01 22:35:24 +0200 | [diff] [blame] | 605 | default: |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 606 | continue; |
Christian König | 3508815 | 2012-08-01 22:35:24 +0200 | [diff] [blame] | 607 | } |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 608 | |
| 609 | for (index = d->Range.First; index <= d->Range.Last; index++) { |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 610 | /* Select the correct target */ |
| 611 | switch(d->Semantic.Name) { |
Tom Stellard | c3c323a | 2012-08-30 10:35:36 -0400 | [diff] [blame] | 612 | case TGSI_SEMANTIC_PSIZE: |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 613 | target = V_008DFC_SQ_EXP_POS; |
| 614 | break; |
Michel Dänzer | 1a616c1 | 2012-11-13 17:35:09 +0100 | [diff] [blame] | 615 | case TGSI_SEMANTIC_POSITION: |
| 616 | if (si_shader_ctx->type == TGSI_PROCESSOR_VERTEX) { |
| 617 | target = V_008DFC_SQ_EXP_POS; |
| 618 | break; |
| 619 | } else { |
| 620 | depth_index = index; |
| 621 | continue; |
| 622 | } |
| 623 | case TGSI_SEMANTIC_STENCIL: |
| 624 | stencil_index = index; |
| 625 | continue; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 626 | case TGSI_SEMANTIC_COLOR: |
| 627 | if (si_shader_ctx->type == TGSI_PROCESSOR_VERTEX) { |
Michel Dänzer | 691f08d | 2012-09-06 18:03:38 +0200 | [diff] [blame] | 628 | case TGSI_SEMANTIC_BCOLOR: |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 629 | target = V_008DFC_SQ_EXP_PARAM + param_count; |
Michel Dänzer | dd9d619 | 2012-05-18 15:01:10 +0200 | [diff] [blame] | 630 | shader->output[i].param_offset = param_count; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 631 | param_count++; |
| 632 | } else { |
| 633 | target = V_008DFC_SQ_EXP_MRT + color_count; |
Michel Dänzer | 7708a86 | 2012-11-02 15:57:30 +0100 | [diff] [blame] | 634 | if (color_count == 0 && |
Christian König | a0dca44 | 2013-03-22 15:59:22 +0100 | [diff] [blame] | 635 | si_shader_ctx->shader->key.ps.alpha_func != PIPE_FUNC_ALWAYS) |
Michel Dänzer | 7708a86 | 2012-11-02 15:57:30 +0100 | [diff] [blame] | 636 | si_alpha_test(bld_base, index); |
| 637 | |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 638 | color_count++; |
| 639 | } |
| 640 | break; |
Michel Dänzer | 30b3037 | 2012-09-06 17:53:04 +0200 | [diff] [blame] | 641 | case TGSI_SEMANTIC_FOG: |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 642 | case TGSI_SEMANTIC_GENERIC: |
| 643 | target = V_008DFC_SQ_EXP_PARAM + param_count; |
Michel Dänzer | dd9d619 | 2012-05-18 15:01:10 +0200 | [diff] [blame] | 644 | shader->output[i].param_offset = param_count; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 645 | param_count++; |
| 646 | break; |
| 647 | default: |
| 648 | target = 0; |
| 649 | fprintf(stderr, |
| 650 | "Warning: SI unhandled output type:%d\n", |
| 651 | d->Semantic.Name); |
| 652 | } |
| 653 | |
Michel Dänzer | 26c7139 | 2012-08-24 12:03:11 +0200 | [diff] [blame] | 654 | si_llvm_init_export_args(bld_base, d, index, target, args); |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 655 | |
| 656 | if (si_shader_ctx->type == TGSI_PROCESSOR_VERTEX ? |
| 657 | (d->Semantic.Name == TGSI_SEMANTIC_POSITION) : |
| 658 | (d->Semantic.Name == TGSI_SEMANTIC_COLOR)) { |
| 659 | if (last_args[0]) { |
| 660 | lp_build_intrinsic(base->gallivm->builder, |
| 661 | "llvm.SI.export", |
| 662 | LLVMVoidTypeInContext(base->gallivm->context), |
| 663 | last_args, 9); |
| 664 | } |
| 665 | |
| 666 | memcpy(last_args, args, sizeof(args)); |
| 667 | } else { |
| 668 | lp_build_intrinsic(base->gallivm->builder, |
| 669 | "llvm.SI.export", |
| 670 | LLVMVoidTypeInContext(base->gallivm->context), |
| 671 | args, 9); |
| 672 | } |
| 673 | |
| 674 | } |
| 675 | } |
| 676 | |
Michel Dänzer | 1a616c1 | 2012-11-13 17:35:09 +0100 | [diff] [blame] | 677 | if (depth_index >= 0 || stencil_index >= 0) { |
| 678 | LLVMValueRef out_ptr; |
| 679 | unsigned mask = 0; |
| 680 | |
| 681 | /* Specify the target we are exporting */ |
| 682 | args[3] = lp_build_const_int32(base->gallivm, V_008DFC_SQ_EXP_MRTZ); |
| 683 | |
| 684 | if (depth_index >= 0) { |
| 685 | out_ptr = si_shader_ctx->radeon_bld.soa.outputs[depth_index][2]; |
| 686 | args[5] = LLVMBuildLoad(base->gallivm->builder, out_ptr, ""); |
| 687 | mask |= 0x1; |
| 688 | |
| 689 | if (stencil_index < 0) { |
| 690 | args[6] = |
| 691 | args[7] = |
| 692 | args[8] = args[5]; |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | if (stencil_index >= 0) { |
| 697 | out_ptr = si_shader_ctx->radeon_bld.soa.outputs[stencil_index][1]; |
| 698 | args[7] = |
| 699 | args[8] = |
| 700 | args[6] = LLVMBuildLoad(base->gallivm->builder, out_ptr, ""); |
| 701 | mask |= 0x2; |
| 702 | |
| 703 | if (depth_index < 0) |
| 704 | args[5] = args[6]; |
| 705 | } |
| 706 | |
| 707 | /* Specify which components to enable */ |
| 708 | args[0] = lp_build_const_int32(base->gallivm, mask); |
| 709 | |
| 710 | args[1] = |
| 711 | args[2] = |
| 712 | args[4] = uint->zero; |
| 713 | |
| 714 | if (last_args[0]) |
| 715 | lp_build_intrinsic(base->gallivm->builder, |
| 716 | "llvm.SI.export", |
| 717 | LLVMVoidTypeInContext(base->gallivm->context), |
| 718 | args, 9); |
| 719 | else |
| 720 | memcpy(last_args, args, sizeof(args)); |
| 721 | } |
| 722 | |
Christian König | f18fd25 | 2012-07-25 21:58:46 +0200 | [diff] [blame] | 723 | if (!last_args[0]) { |
| 724 | assert(si_shader_ctx->type == TGSI_PROCESSOR_FRAGMENT); |
| 725 | |
| 726 | /* Specify which components to enable */ |
| 727 | last_args[0] = lp_build_const_int32(base->gallivm, 0x0); |
| 728 | |
| 729 | /* Specify the target we are exporting */ |
| 730 | last_args[3] = lp_build_const_int32(base->gallivm, V_008DFC_SQ_EXP_MRT); |
| 731 | |
| 732 | /* Set COMPR flag to zero to export data as 32-bit */ |
| 733 | last_args[4] = uint->zero; |
| 734 | |
| 735 | /* dummy bits */ |
| 736 | last_args[5]= uint->zero; |
| 737 | last_args[6]= uint->zero; |
| 738 | last_args[7]= uint->zero; |
| 739 | last_args[8]= uint->zero; |
Michel Dänzer | 1ace200 | 2012-12-21 15:39:26 +0100 | [diff] [blame] | 740 | |
| 741 | si_shader_ctx->shader->spi_shader_col_format |= |
| 742 | V_028714_SPI_SHADER_32_ABGR; |
Christian König | f18fd25 | 2012-07-25 21:58:46 +0200 | [diff] [blame] | 743 | } |
| 744 | |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 745 | /* Specify whether the EXEC mask represents the valid mask */ |
| 746 | last_args[1] = lp_build_const_int32(base->gallivm, |
| 747 | si_shader_ctx->type == TGSI_PROCESSOR_FRAGMENT); |
| 748 | |
Michel Dänzer | c840270 | 2013-02-12 18:37:22 +0100 | [diff] [blame] | 749 | if (shader->fs_write_all && shader->nr_cbufs > 1) { |
| 750 | int i; |
| 751 | |
| 752 | /* Specify that this is not yet the last export */ |
| 753 | last_args[2] = lp_build_const_int32(base->gallivm, 0); |
| 754 | |
| 755 | for (i = 1; i < shader->nr_cbufs; i++) { |
| 756 | /* Specify the target we are exporting */ |
| 757 | last_args[3] = lp_build_const_int32(base->gallivm, |
| 758 | V_008DFC_SQ_EXP_MRT + i); |
| 759 | |
| 760 | lp_build_intrinsic(base->gallivm->builder, |
| 761 | "llvm.SI.export", |
| 762 | LLVMVoidTypeInContext(base->gallivm->context), |
| 763 | last_args, 9); |
| 764 | |
| 765 | si_shader_ctx->shader->spi_shader_col_format |= |
| 766 | si_shader_ctx->shader->spi_shader_col_format << 4; |
| 767 | } |
| 768 | |
| 769 | last_args[3] = lp_build_const_int32(base->gallivm, V_008DFC_SQ_EXP_MRT); |
| 770 | } |
| 771 | |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 772 | /* Specify that this is the last export */ |
| 773 | last_args[2] = lp_build_const_int32(base->gallivm, 1); |
| 774 | |
| 775 | lp_build_intrinsic(base->gallivm->builder, |
| 776 | "llvm.SI.export", |
| 777 | LLVMVoidTypeInContext(base->gallivm->context), |
| 778 | last_args, 9); |
| 779 | |
| 780 | /* XXX: Look up what this function does */ |
| 781 | /* ctx->shader->output[i].spi_sid = r600_spi_sid(&ctx->shader->output[i]);*/ |
| 782 | } |
| 783 | |
| 784 | static void tex_fetch_args( |
| 785 | struct lp_build_tgsi_context * bld_base, |
| 786 | struct lp_build_emit_data * emit_data) |
| 787 | { |
Christian König | 55fe5cc | 2013-03-04 16:30:06 +0100 | [diff] [blame] | 788 | struct si_shader_context *si_shader_ctx = si_shader_context(bld_base); |
Michel Dänzer | e5fb734 | 2013-01-24 18:54:51 +0100 | [diff] [blame] | 789 | struct gallivm_state *gallivm = bld_base->base.gallivm; |
Michel Dänzer | c2bae6b | 2012-08-02 17:19:22 +0200 | [diff] [blame] | 790 | const struct tgsi_full_instruction * inst = emit_data->inst; |
Michel Dänzer | 120efee | 2013-01-25 12:10:11 +0100 | [diff] [blame] | 791 | unsigned opcode = inst->Instruction.Opcode; |
| 792 | unsigned target = inst->Texture.Texture; |
Michel Dänzer | 120efee | 2013-01-25 12:10:11 +0100 | [diff] [blame] | 793 | LLVMValueRef coords[4]; |
| 794 | LLVMValueRef address[16]; |
| 795 | unsigned count = 0; |
Michel Dänzer | e5fb734 | 2013-01-24 18:54:51 +0100 | [diff] [blame] | 796 | unsigned chan; |
Tom Stellard | 467f516 | 2012-05-16 15:15:35 -0400 | [diff] [blame] | 797 | |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 798 | /* WriteMask */ |
Christian König | 250b7fd | 2012-08-01 23:18:14 +0200 | [diff] [blame] | 799 | /* XXX: should be optimized using emit_data->inst->Dst[0].Register.WriteMask*/ |
| 800 | emit_data->args[0] = lp_build_const_int32(bld_base->base.gallivm, 0xf); |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 801 | |
Michel Dänzer | 120efee | 2013-01-25 12:10:11 +0100 | [diff] [blame] | 802 | /* Fetch and project texture coordinates */ |
| 803 | coords[3] = lp_build_emit_fetch(bld_base, emit_data->inst, 0, TGSI_CHAN_W); |
Michel Dänzer | e5fb734 | 2013-01-24 18:54:51 +0100 | [diff] [blame] | 804 | for (chan = 0; chan < 3; chan++ ) { |
| 805 | coords[chan] = lp_build_emit_fetch(bld_base, |
| 806 | emit_data->inst, 0, |
| 807 | chan); |
Michel Dänzer | 120efee | 2013-01-25 12:10:11 +0100 | [diff] [blame] | 808 | if (opcode == TGSI_OPCODE_TXP) |
Michel Dänzer | c2bae6b | 2012-08-02 17:19:22 +0200 | [diff] [blame] | 809 | coords[chan] = lp_build_emit_llvm_binary(bld_base, |
| 810 | TGSI_OPCODE_DIV, |
Michel Dänzer | e5fb734 | 2013-01-24 18:54:51 +0100 | [diff] [blame] | 811 | coords[chan], |
| 812 | coords[3]); |
| 813 | } |
| 814 | |
Michel Dänzer | 120efee | 2013-01-25 12:10:11 +0100 | [diff] [blame] | 815 | if (opcode == TGSI_OPCODE_TXP) |
| 816 | coords[3] = bld_base->base.one; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 817 | |
Michel Dänzer | 120efee | 2013-01-25 12:10:11 +0100 | [diff] [blame] | 818 | /* Pack LOD bias value */ |
| 819 | if (opcode == TGSI_OPCODE_TXB) |
| 820 | address[count++] = coords[3]; |
Vadim Girlin | 8cf552b | 2012-12-18 17:39:19 +0400 | [diff] [blame] | 821 | |
Michel Dänzer | 120efee | 2013-01-25 12:10:11 +0100 | [diff] [blame] | 822 | if ((target == TGSI_TEXTURE_CUBE || target == TGSI_TEXTURE_SHADOWCUBE) && |
| 823 | opcode != TGSI_OPCODE_TXQ) |
Michel Dänzer | e5fb734 | 2013-01-24 18:54:51 +0100 | [diff] [blame] | 824 | radeon_llvm_emit_prepare_cube_coords(bld_base, emit_data, coords); |
Michel Dänzer | 120efee | 2013-01-25 12:10:11 +0100 | [diff] [blame] | 825 | |
| 826 | /* Pack depth comparison value */ |
| 827 | switch (target) { |
| 828 | case TGSI_TEXTURE_SHADOW1D: |
| 829 | case TGSI_TEXTURE_SHADOW1D_ARRAY: |
| 830 | case TGSI_TEXTURE_SHADOW2D: |
| 831 | case TGSI_TEXTURE_SHADOWRECT: |
| 832 | address[count++] = coords[2]; |
| 833 | break; |
| 834 | case TGSI_TEXTURE_SHADOWCUBE: |
| 835 | case TGSI_TEXTURE_SHADOW2D_ARRAY: |
| 836 | address[count++] = coords[3]; |
| 837 | break; |
| 838 | case TGSI_TEXTURE_SHADOWCUBE_ARRAY: |
| 839 | address[count++] = lp_build_emit_fetch(bld_base, inst, 1, 0); |
Michel Dänzer | e0f2ffc | 2012-12-03 12:46:30 +0100 | [diff] [blame] | 840 | } |
| 841 | |
Michel Dänzer | 120efee | 2013-01-25 12:10:11 +0100 | [diff] [blame] | 842 | /* Pack texture coordinates */ |
| 843 | address[count++] = coords[0]; |
| 844 | switch (target) { |
| 845 | case TGSI_TEXTURE_2D: |
| 846 | case TGSI_TEXTURE_2D_ARRAY: |
| 847 | case TGSI_TEXTURE_3D: |
| 848 | case TGSI_TEXTURE_CUBE: |
| 849 | case TGSI_TEXTURE_RECT: |
| 850 | case TGSI_TEXTURE_SHADOW2D: |
| 851 | case TGSI_TEXTURE_SHADOWRECT: |
| 852 | case TGSI_TEXTURE_SHADOW2D_ARRAY: |
| 853 | case TGSI_TEXTURE_SHADOWCUBE: |
| 854 | case TGSI_TEXTURE_2D_MSAA: |
| 855 | case TGSI_TEXTURE_2D_ARRAY_MSAA: |
| 856 | case TGSI_TEXTURE_CUBE_ARRAY: |
| 857 | case TGSI_TEXTURE_SHADOWCUBE_ARRAY: |
| 858 | address[count++] = coords[1]; |
| 859 | } |
| 860 | switch (target) { |
| 861 | case TGSI_TEXTURE_3D: |
| 862 | case TGSI_TEXTURE_CUBE: |
| 863 | case TGSI_TEXTURE_SHADOWCUBE: |
| 864 | case TGSI_TEXTURE_CUBE_ARRAY: |
| 865 | case TGSI_TEXTURE_SHADOWCUBE_ARRAY: |
| 866 | address[count++] = coords[2]; |
Michel Dänzer | e5fb734 | 2013-01-24 18:54:51 +0100 | [diff] [blame] | 867 | } |
| 868 | |
Michel Dänzer | 120efee | 2013-01-25 12:10:11 +0100 | [diff] [blame] | 869 | /* Pack array slice */ |
| 870 | switch (target) { |
| 871 | case TGSI_TEXTURE_1D_ARRAY: |
| 872 | address[count++] = coords[1]; |
| 873 | } |
| 874 | switch (target) { |
| 875 | case TGSI_TEXTURE_2D_ARRAY: |
| 876 | case TGSI_TEXTURE_2D_ARRAY_MSAA: |
| 877 | case TGSI_TEXTURE_SHADOW2D_ARRAY: |
| 878 | address[count++] = coords[2]; |
| 879 | } |
| 880 | switch (target) { |
| 881 | case TGSI_TEXTURE_CUBE_ARRAY: |
| 882 | case TGSI_TEXTURE_SHADOW1D_ARRAY: |
| 883 | case TGSI_TEXTURE_SHADOWCUBE_ARRAY: |
| 884 | address[count++] = coords[3]; |
| 885 | } |
| 886 | |
| 887 | /* Pack LOD */ |
| 888 | if (opcode == TGSI_OPCODE_TXL) |
| 889 | address[count++] = coords[3]; |
| 890 | |
| 891 | if (count > 16) { |
| 892 | assert(!"Cannot handle more than 16 texture address parameters"); |
| 893 | count = 16; |
| 894 | } |
| 895 | |
| 896 | for (chan = 0; chan < count; chan++ ) { |
| 897 | address[chan] = LLVMBuildBitCast(gallivm->builder, |
| 898 | address[chan], |
| 899 | LLVMInt32TypeInContext(gallivm->context), |
| 900 | ""); |
| 901 | } |
| 902 | |
| 903 | /* Pad to power of two vector */ |
| 904 | while (count < util_next_power_of_two(count)) |
| 905 | address[count++] = LLVMGetUndef(LLVMInt32TypeInContext(gallivm->context)); |
| 906 | |
Michel Dänzer | 120efee | 2013-01-25 12:10:11 +0100 | [diff] [blame] | 907 | emit_data->args[1] = lp_build_gather_values(gallivm, address, count); |
Michel Dänzer | e5fb734 | 2013-01-24 18:54:51 +0100 | [diff] [blame] | 908 | |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 909 | /* Resource */ |
Christian König | 1c10018 | 2013-03-17 16:02:42 +0100 | [diff] [blame] | 910 | emit_data->args[2] = si_shader_ctx->resources[emit_data->inst->Src[1].Register.Index]; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 911 | |
| 912 | /* Sampler */ |
Christian König | 1c10018 | 2013-03-17 16:02:42 +0100 | [diff] [blame] | 913 | emit_data->args[3] = si_shader_ctx->samplers[emit_data->inst->Src[1].Register.Index]; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 914 | |
| 915 | /* Dimensions */ |
Michel Dänzer | 120efee | 2013-01-25 12:10:11 +0100 | [diff] [blame] | 916 | emit_data->args[4] = lp_build_const_int32(bld_base->base.gallivm, target); |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 917 | |
Michel Dänzer | 6eb0d3d | 2012-11-30 11:38:24 +0100 | [diff] [blame] | 918 | emit_data->arg_count = 5; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 919 | /* XXX: To optimize, we could use a float or v2f32, if the last bits of |
| 920 | * the writemask are clear */ |
| 921 | emit_data->dst_type = LLVMVectorType( |
| 922 | LLVMFloatTypeInContext(bld_base->base.gallivm->context), |
| 923 | 4); |
| 924 | } |
| 925 | |
Michel Dänzer | 07eddc4 | 2013-02-06 15:43:10 +0100 | [diff] [blame] | 926 | static void build_tex_intrinsic(const struct lp_build_tgsi_action * action, |
| 927 | struct lp_build_tgsi_context * bld_base, |
| 928 | struct lp_build_emit_data * emit_data) |
| 929 | { |
| 930 | struct lp_build_context * base = &bld_base->base; |
| 931 | char intr_name[23]; |
| 932 | |
| 933 | sprintf(intr_name, "%sv%ui32", action->intr_name, |
| 934 | LLVMGetVectorSize(LLVMTypeOf(emit_data->args[1]))); |
| 935 | |
Christian König | 44e3224 | 2013-03-20 12:10:35 +0100 | [diff] [blame] | 936 | emit_data->output[emit_data->chan] = build_intrinsic( |
Michel Dänzer | 07eddc4 | 2013-02-06 15:43:10 +0100 | [diff] [blame] | 937 | base->gallivm->builder, intr_name, emit_data->dst_type, |
Christian König | 44e3224 | 2013-03-20 12:10:35 +0100 | [diff] [blame] | 938 | emit_data->args, emit_data->arg_count, |
| 939 | LLVMReadNoneAttribute | LLVMNoUnwindAttribute); |
Michel Dänzer | 07eddc4 | 2013-02-06 15:43:10 +0100 | [diff] [blame] | 940 | } |
| 941 | |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 942 | static const struct lp_build_tgsi_action tex_action = { |
| 943 | .fetch_args = tex_fetch_args, |
Michel Dänzer | 07eddc4 | 2013-02-06 15:43:10 +0100 | [diff] [blame] | 944 | .emit = build_tex_intrinsic, |
Michel Dänzer | e5fb734 | 2013-01-24 18:54:51 +0100 | [diff] [blame] | 945 | .intr_name = "llvm.SI.sample." |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 946 | }; |
| 947 | |
Michel Dänzer | 3e20513 | 2012-11-06 17:39:01 +0100 | [diff] [blame] | 948 | static const struct lp_build_tgsi_action txb_action = { |
| 949 | .fetch_args = tex_fetch_args, |
Michel Dänzer | 07eddc4 | 2013-02-06 15:43:10 +0100 | [diff] [blame] | 950 | .emit = build_tex_intrinsic, |
Michel Dänzer | e5fb734 | 2013-01-24 18:54:51 +0100 | [diff] [blame] | 951 | .intr_name = "llvm.SI.sampleb." |
Michel Dänzer | 3e20513 | 2012-11-06 17:39:01 +0100 | [diff] [blame] | 952 | }; |
| 953 | |
Michel Dänzer | 56ae9be | 2012-11-06 17:41:50 +0100 | [diff] [blame] | 954 | static const struct lp_build_tgsi_action txl_action = { |
| 955 | .fetch_args = tex_fetch_args, |
Michel Dänzer | 07eddc4 | 2013-02-06 15:43:10 +0100 | [diff] [blame] | 956 | .emit = build_tex_intrinsic, |
Michel Dänzer | e5fb734 | 2013-01-24 18:54:51 +0100 | [diff] [blame] | 957 | .intr_name = "llvm.SI.samplel." |
Michel Dänzer | 56ae9be | 2012-11-06 17:41:50 +0100 | [diff] [blame] | 958 | }; |
| 959 | |
Christian König | 206f059 | 2013-03-20 14:37:21 +0100 | [diff] [blame] | 960 | static void create_meta_data(struct si_shader_context *si_shader_ctx) |
| 961 | { |
| 962 | struct gallivm_state *gallivm = si_shader_ctx->radeon_bld.soa.bld_base.base.gallivm; |
| 963 | LLVMValueRef args[3]; |
| 964 | |
| 965 | args[0] = LLVMMDStringInContext(gallivm->context, "const", 5); |
| 966 | args[1] = 0; |
| 967 | args[2] = lp_build_const_int32(gallivm, 1); |
| 968 | |
| 969 | si_shader_ctx->const_md = LLVMMDNodeInContext(gallivm->context, args, 3); |
| 970 | } |
| 971 | |
Christian König | 55fe5cc | 2013-03-04 16:30:06 +0100 | [diff] [blame] | 972 | static void create_function(struct si_shader_context *si_shader_ctx) |
| 973 | { |
| 974 | struct gallivm_state *gallivm = si_shader_ctx->radeon_bld.soa.bld_base.base.gallivm; |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 975 | LLVMTypeRef params[20], f32, i8, i32, v2i32, v3i32; |
Christian König | 55fe5cc | 2013-03-04 16:30:06 +0100 | [diff] [blame] | 976 | unsigned i; |
| 977 | |
Christian König | 55fe5cc | 2013-03-04 16:30:06 +0100 | [diff] [blame] | 978 | i8 = LLVMInt8TypeInContext(gallivm->context); |
Christian König | c497321 | 2013-03-05 12:14:02 +0100 | [diff] [blame] | 979 | i32 = LLVMInt32TypeInContext(gallivm->context); |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 980 | f32 = LLVMFloatTypeInContext(gallivm->context); |
| 981 | v2i32 = LLVMVectorType(i32, 2); |
| 982 | v3i32 = LLVMVectorType(i32, 3); |
Christian König | c497321 | 2013-03-05 12:14:02 +0100 | [diff] [blame] | 983 | |
Christian König | f5298b0 | 2013-02-28 14:50:07 +0100 | [diff] [blame] | 984 | params[SI_PARAM_CONST] = LLVMPointerType(LLVMVectorType(i8, 16), CONST_ADDR_SPACE); |
| 985 | params[SI_PARAM_SAMPLER] = params[SI_PARAM_CONST]; |
Christian König | 55fe5cc | 2013-03-04 16:30:06 +0100 | [diff] [blame] | 986 | params[SI_PARAM_RESOURCE] = LLVMPointerType(LLVMVectorType(i8, 32), CONST_ADDR_SPACE); |
| 987 | |
Christian König | c497321 | 2013-03-05 12:14:02 +0100 | [diff] [blame] | 988 | if (si_shader_ctx->type == TGSI_PROCESSOR_VERTEX) { |
Christian König | 55fe5cc | 2013-03-04 16:30:06 +0100 | [diff] [blame] | 989 | params[SI_PARAM_VERTEX_BUFFER] = params[SI_PARAM_SAMPLER]; |
Christian König | cf9b31f | 2013-03-21 18:30:23 +0100 | [diff] [blame] | 990 | params[SI_PARAM_START_INSTANCE] = i32; |
Christian König | e4ed587 | 2013-03-21 18:02:52 +0100 | [diff] [blame] | 991 | params[SI_PARAM_VERTEX_ID] = i32; |
| 992 | params[SI_PARAM_DUMMY_0] = i32; |
| 993 | params[SI_PARAM_DUMMY_1] = i32; |
| 994 | params[SI_PARAM_INSTANCE_ID] = i32; |
Christian König | cf9b31f | 2013-03-21 18:30:23 +0100 | [diff] [blame] | 995 | radeon_llvm_create_func(&si_shader_ctx->radeon_bld, params, 9); |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 996 | |
Christian König | c497321 | 2013-03-05 12:14:02 +0100 | [diff] [blame] | 997 | } else { |
Christian König | 0666ffd | 2013-03-05 15:07:39 +0100 | [diff] [blame] | 998 | params[SI_PARAM_PRIM_MASK] = i32; |
| 999 | params[SI_PARAM_PERSP_SAMPLE] = v2i32; |
| 1000 | params[SI_PARAM_PERSP_CENTER] = v2i32; |
| 1001 | params[SI_PARAM_PERSP_CENTROID] = v2i32; |
| 1002 | params[SI_PARAM_PERSP_PULL_MODEL] = v3i32; |
| 1003 | params[SI_PARAM_LINEAR_SAMPLE] = v2i32; |
| 1004 | params[SI_PARAM_LINEAR_CENTER] = v2i32; |
| 1005 | params[SI_PARAM_LINEAR_CENTROID] = v2i32; |
| 1006 | params[SI_PARAM_LINE_STIPPLE_TEX] = f32; |
| 1007 | params[SI_PARAM_POS_X_FLOAT] = f32; |
| 1008 | params[SI_PARAM_POS_Y_FLOAT] = f32; |
| 1009 | params[SI_PARAM_POS_Z_FLOAT] = f32; |
| 1010 | params[SI_PARAM_POS_W_FLOAT] = f32; |
| 1011 | params[SI_PARAM_FRONT_FACE] = f32; |
| 1012 | params[SI_PARAM_ANCILLARY] = f32; |
| 1013 | params[SI_PARAM_SAMPLE_COVERAGE] = f32; |
| 1014 | params[SI_PARAM_POS_FIXED_PT] = f32; |
| 1015 | radeon_llvm_create_func(&si_shader_ctx->radeon_bld, params, 20); |
Christian König | c497321 | 2013-03-05 12:14:02 +0100 | [diff] [blame] | 1016 | } |
Christian König | 55fe5cc | 2013-03-04 16:30:06 +0100 | [diff] [blame] | 1017 | |
| 1018 | radeon_llvm_shader_type(si_shader_ctx->radeon_bld.main_fn, si_shader_ctx->type); |
| 1019 | for (i = SI_PARAM_CONST; i <= SI_PARAM_VERTEX_BUFFER; ++i) { |
| 1020 | LLVMValueRef P = LLVMGetParam(si_shader_ctx->radeon_bld.main_fn, i); |
| 1021 | LLVMAddAttribute(P, LLVMInRegAttribute); |
| 1022 | } |
Christian König | cf9b31f | 2013-03-21 18:30:23 +0100 | [diff] [blame] | 1023 | |
| 1024 | if (si_shader_ctx->type == TGSI_PROCESSOR_VERTEX) { |
| 1025 | LLVMValueRef P = LLVMGetParam(si_shader_ctx->radeon_bld.main_fn, |
| 1026 | SI_PARAM_START_INSTANCE); |
| 1027 | LLVMAddAttribute(P, LLVMInRegAttribute); |
| 1028 | } |
Christian König | 55fe5cc | 2013-03-04 16:30:06 +0100 | [diff] [blame] | 1029 | } |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 1030 | |
Christian König | 0f6cf2b | 2013-03-15 15:53:25 +0100 | [diff] [blame] | 1031 | static void preload_constants(struct si_shader_context *si_shader_ctx) |
| 1032 | { |
| 1033 | struct lp_build_tgsi_context * bld_base = &si_shader_ctx->radeon_bld.soa.bld_base; |
| 1034 | struct gallivm_state * gallivm = bld_base->base.gallivm; |
| 1035 | const struct tgsi_shader_info * info = bld_base->info; |
| 1036 | |
| 1037 | unsigned i, num_const = info->file_max[TGSI_FILE_CONSTANT] + 1; |
| 1038 | |
| 1039 | LLVMValueRef ptr; |
| 1040 | |
| 1041 | if (num_const == 0) |
| 1042 | return; |
| 1043 | |
| 1044 | /* Allocate space for the constant values */ |
| 1045 | si_shader_ctx->constants = CALLOC(num_const * 4, sizeof(LLVMValueRef)); |
| 1046 | |
| 1047 | /* Load the resource descriptor */ |
| 1048 | ptr = LLVMGetParam(si_shader_ctx->radeon_bld.main_fn, SI_PARAM_CONST); |
| 1049 | si_shader_ctx->const_resource = build_indexed_load(si_shader_ctx, ptr, bld_base->uint_bld.zero); |
| 1050 | |
| 1051 | /* Load the constants, we rely on the code sinking to do the rest */ |
| 1052 | for (i = 0; i < num_const * 4; ++i) { |
| 1053 | LLVMValueRef args[2] = { |
| 1054 | si_shader_ctx->const_resource, |
| 1055 | lp_build_const_int32(gallivm, i * 4) |
| 1056 | }; |
| 1057 | si_shader_ctx->constants[i] = build_intrinsic(gallivm->builder, "llvm.SI.load.const", |
| 1058 | bld_base->base.elem_type, args, 2, LLVMReadNoneAttribute | LLVMNoUnwindAttribute); |
| 1059 | } |
| 1060 | } |
| 1061 | |
Christian König | 1c10018 | 2013-03-17 16:02:42 +0100 | [diff] [blame] | 1062 | static void preload_samplers(struct si_shader_context *si_shader_ctx) |
| 1063 | { |
| 1064 | struct lp_build_tgsi_context * bld_base = &si_shader_ctx->radeon_bld.soa.bld_base; |
| 1065 | struct gallivm_state * gallivm = bld_base->base.gallivm; |
| 1066 | const struct tgsi_shader_info * info = bld_base->info; |
| 1067 | |
| 1068 | unsigned i, num_samplers = info->file_max[TGSI_FILE_SAMPLER] + 1; |
| 1069 | |
| 1070 | LLVMValueRef res_ptr, samp_ptr; |
| 1071 | LLVMValueRef offset; |
| 1072 | |
| 1073 | if (num_samplers == 0) |
| 1074 | return; |
| 1075 | |
| 1076 | /* Allocate space for the values */ |
| 1077 | si_shader_ctx->resources = CALLOC(num_samplers, sizeof(LLVMValueRef)); |
| 1078 | si_shader_ctx->samplers = CALLOC(num_samplers, sizeof(LLVMValueRef)); |
| 1079 | |
| 1080 | res_ptr = LLVMGetParam(si_shader_ctx->radeon_bld.main_fn, SI_PARAM_RESOURCE); |
| 1081 | samp_ptr = LLVMGetParam(si_shader_ctx->radeon_bld.main_fn, SI_PARAM_SAMPLER); |
| 1082 | |
| 1083 | /* Load the resources and samplers, we rely on the code sinking to do the rest */ |
| 1084 | for (i = 0; i < num_samplers; ++i) { |
| 1085 | |
| 1086 | /* Resource */ |
| 1087 | offset = lp_build_const_int32(gallivm, i); |
| 1088 | si_shader_ctx->resources[i] = build_indexed_load(si_shader_ctx, res_ptr, offset); |
| 1089 | |
| 1090 | /* Sampler */ |
| 1091 | offset = lp_build_const_int32(gallivm, i); |
| 1092 | si_shader_ctx->samplers[i] = build_indexed_load(si_shader_ctx, samp_ptr, offset); |
| 1093 | } |
| 1094 | } |
| 1095 | |
Tom Stellard | 302f53d | 2012-10-25 13:50:10 -0400 | [diff] [blame^] | 1096 | int si_compile_llvm(struct r600_context *rctx, struct si_pipe_shader *shader, |
| 1097 | LLVMModuleRef mod) |
| 1098 | { |
| 1099 | unsigned char *inst_bytes; |
| 1100 | unsigned inst_byte_count; |
| 1101 | unsigned i; |
| 1102 | uint32_t *ptr; |
| 1103 | bool dump; |
| 1104 | |
| 1105 | dump = debug_get_bool_option("RADEON_DUMP_SHADERS", FALSE); |
| 1106 | |
| 1107 | radeon_llvm_compile(mod, &inst_bytes, &inst_byte_count, |
| 1108 | r600_get_llvm_processor_name(rctx->screen->family), |
| 1109 | dump); |
| 1110 | |
| 1111 | if (dump) { |
| 1112 | fprintf(stderr, "SI CODE:\n"); |
| 1113 | for (i = 0; i < inst_byte_count; i+=4 ) { |
| 1114 | fprintf(stderr, "%02x%02x%02x%02x\n", inst_bytes[i + 3], |
| 1115 | inst_bytes[i + 2], inst_bytes[i + 1], |
| 1116 | inst_bytes[i]); |
| 1117 | } |
| 1118 | } |
| 1119 | |
| 1120 | shader->num_sgprs = util_le32_to_cpu(*(uint32_t*)inst_bytes); |
| 1121 | shader->num_vgprs = util_le32_to_cpu(*(uint32_t*)(inst_bytes + 4)); |
| 1122 | shader->spi_ps_input_ena = util_le32_to_cpu(*(uint32_t*)(inst_bytes + 8)); |
| 1123 | |
| 1124 | /* copy new shader */ |
| 1125 | si_resource_reference(&shader->bo, NULL); |
| 1126 | shader->bo = si_resource_create_custom(rctx->context.screen, PIPE_USAGE_IMMUTABLE, |
| 1127 | inst_byte_count - 12); |
| 1128 | if (shader->bo == NULL) { |
| 1129 | return -ENOMEM; |
| 1130 | } |
| 1131 | |
| 1132 | ptr = (uint32_t*)rctx->ws->buffer_map(shader->bo->cs_buf, rctx->cs, PIPE_TRANSFER_WRITE); |
| 1133 | if (0 /*R600_BIG_ENDIAN*/) { |
| 1134 | for (i = 0; i < (inst_byte_count-12)/4; ++i) { |
| 1135 | ptr[i] = util_bswap32(*(uint32_t*)(inst_bytes+12 + i*4)); |
| 1136 | } |
| 1137 | } else { |
| 1138 | memcpy(ptr, inst_bytes + 12, inst_byte_count - 12); |
| 1139 | } |
| 1140 | rctx->ws->buffer_unmap(shader->bo->cs_buf); |
| 1141 | |
| 1142 | free(inst_bytes); |
| 1143 | |
| 1144 | return 0; |
| 1145 | } |
| 1146 | |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 1147 | int si_pipe_shader_create( |
| 1148 | struct pipe_context *ctx, |
Christian König | a0dca44 | 2013-03-22 15:59:22 +0100 | [diff] [blame] | 1149 | struct si_pipe_shader *shader) |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 1150 | { |
| 1151 | struct r600_context *rctx = (struct r600_context*)ctx; |
Michel Dänzer | d1e40b3 | 2012-08-23 17:10:37 +0200 | [diff] [blame] | 1152 | struct si_pipe_shader_selector *sel = shader->selector; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 1153 | struct si_shader_context si_shader_ctx; |
| 1154 | struct tgsi_shader_info shader_info; |
| 1155 | struct lp_build_tgsi_context * bld_base; |
| 1156 | LLVMModuleRef mod; |
Michel Dänzer | 4c4ef9c | 2012-06-07 19:30:47 +0200 | [diff] [blame] | 1157 | bool dump; |
Tom Stellard | 302f53d | 2012-10-25 13:50:10 -0400 | [diff] [blame^] | 1158 | int r = 0; |
Michel Dänzer | 4c4ef9c | 2012-06-07 19:30:47 +0200 | [diff] [blame] | 1159 | |
| 1160 | dump = debug_get_bool_option("RADEON_DUMP_SHADERS", FALSE); |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 1161 | |
Michel Dänzer | 82e38ac | 2012-09-27 16:39:26 +0200 | [diff] [blame] | 1162 | assert(shader->shader.noutput == 0); |
| 1163 | assert(shader->shader.ninterp == 0); |
| 1164 | assert(shader->shader.ninput == 0); |
| 1165 | |
Michel Dänzer | cfebaf9 | 2012-08-31 19:04:08 +0200 | [diff] [blame] | 1166 | memset(&si_shader_ctx, 0, sizeof(si_shader_ctx)); |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 1167 | radeon_llvm_context_init(&si_shader_ctx.radeon_bld); |
| 1168 | bld_base = &si_shader_ctx.radeon_bld.soa.bld_base; |
| 1169 | |
Michel Dänzer | d1e40b3 | 2012-08-23 17:10:37 +0200 | [diff] [blame] | 1170 | tgsi_scan_shader(sel->tokens, &shader_info); |
Michel Dänzer | e44dfd4 | 2012-11-07 17:33:08 +0100 | [diff] [blame] | 1171 | shader->shader.uses_kill = shader_info.uses_kill; |
Christian König | e4ed587 | 2013-03-21 18:02:52 +0100 | [diff] [blame] | 1172 | shader->shader.uses_instanceid = shader_info.uses_instanceid; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 1173 | bld_base->info = &shader_info; |
| 1174 | bld_base->emit_fetch_funcs[TGSI_FILE_CONSTANT] = fetch_constant; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 1175 | bld_base->emit_epilogue = si_llvm_emit_epilogue; |
| 1176 | |
| 1177 | bld_base->op_actions[TGSI_OPCODE_TEX] = tex_action; |
Michel Dänzer | 3e20513 | 2012-11-06 17:39:01 +0100 | [diff] [blame] | 1178 | bld_base->op_actions[TGSI_OPCODE_TXB] = txb_action; |
Michel Dänzer | 56ae9be | 2012-11-06 17:41:50 +0100 | [diff] [blame] | 1179 | bld_base->op_actions[TGSI_OPCODE_TXL] = txl_action; |
Michel Dänzer | c2bae6b | 2012-08-02 17:19:22 +0200 | [diff] [blame] | 1180 | bld_base->op_actions[TGSI_OPCODE_TXP] = tex_action; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 1181 | |
| 1182 | si_shader_ctx.radeon_bld.load_input = declare_input; |
Christian König | e4ed587 | 2013-03-21 18:02:52 +0100 | [diff] [blame] | 1183 | si_shader_ctx.radeon_bld.load_system_value = declare_system_value; |
Michel Dänzer | d1e40b3 | 2012-08-23 17:10:37 +0200 | [diff] [blame] | 1184 | si_shader_ctx.tokens = sel->tokens; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 1185 | tgsi_parse_init(&si_shader_ctx.parse, si_shader_ctx.tokens); |
| 1186 | si_shader_ctx.shader = shader; |
| 1187 | si_shader_ctx.type = si_shader_ctx.parse.FullHeader.Processor.Processor; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 1188 | |
Christian König | 206f059 | 2013-03-20 14:37:21 +0100 | [diff] [blame] | 1189 | create_meta_data(&si_shader_ctx); |
Christian König | 55fe5cc | 2013-03-04 16:30:06 +0100 | [diff] [blame] | 1190 | create_function(&si_shader_ctx); |
Christian König | 0f6cf2b | 2013-03-15 15:53:25 +0100 | [diff] [blame] | 1191 | preload_constants(&si_shader_ctx); |
Christian König | 1c10018 | 2013-03-17 16:02:42 +0100 | [diff] [blame] | 1192 | preload_samplers(&si_shader_ctx); |
Christian König | b8f4ca3 | 2013-03-04 15:35:30 +0100 | [diff] [blame] | 1193 | |
Christian König | 835098a | 2012-07-17 21:28:10 +0200 | [diff] [blame] | 1194 | shader->shader.nr_cbufs = rctx->framebuffer.nr_cbufs; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 1195 | |
Tom Stellard | 185fc9a | 2012-07-12 10:40:47 -0400 | [diff] [blame] | 1196 | /* Dump TGSI code before doing TGSI->LLVM conversion in case the |
| 1197 | * conversion fails. */ |
| 1198 | if (dump) { |
Michel Dänzer | d1e40b3 | 2012-08-23 17:10:37 +0200 | [diff] [blame] | 1199 | tgsi_dump(sel->tokens, 0); |
Tom Stellard | 185fc9a | 2012-07-12 10:40:47 -0400 | [diff] [blame] | 1200 | } |
| 1201 | |
Michel Dänzer | d1e40b3 | 2012-08-23 17:10:37 +0200 | [diff] [blame] | 1202 | if (!lp_build_tgsi_llvm(bld_base, sel->tokens)) { |
Michel Dänzer | 82cd9c0 | 2012-08-08 15:35:42 +0200 | [diff] [blame] | 1203 | fprintf(stderr, "Failed to translate shader from TGSI to LLVM\n"); |
Christian König | 0f6cf2b | 2013-03-15 15:53:25 +0100 | [diff] [blame] | 1204 | FREE(si_shader_ctx.constants); |
Christian König | 1c10018 | 2013-03-17 16:02:42 +0100 | [diff] [blame] | 1205 | FREE(si_shader_ctx.resources); |
| 1206 | FREE(si_shader_ctx.samplers); |
Michel Dänzer | 82cd9c0 | 2012-08-08 15:35:42 +0200 | [diff] [blame] | 1207 | return -EINVAL; |
| 1208 | } |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 1209 | |
| 1210 | radeon_llvm_finalize_module(&si_shader_ctx.radeon_bld); |
| 1211 | |
| 1212 | mod = bld_base->base.gallivm->module; |
Tom Stellard | 302f53d | 2012-10-25 13:50:10 -0400 | [diff] [blame^] | 1213 | r = si_compile_llvm(rctx, shader, mod); |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 1214 | |
Michel Dänzer | 4b64fa2 | 2012-08-15 18:22:46 +0200 | [diff] [blame] | 1215 | radeon_llvm_dispose(&si_shader_ctx.radeon_bld); |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 1216 | tgsi_parse_free(&si_shader_ctx.parse); |
| 1217 | |
Christian König | 0f6cf2b | 2013-03-15 15:53:25 +0100 | [diff] [blame] | 1218 | FREE(si_shader_ctx.constants); |
Christian König | 1c10018 | 2013-03-17 16:02:42 +0100 | [diff] [blame] | 1219 | FREE(si_shader_ctx.resources); |
| 1220 | FREE(si_shader_ctx.samplers); |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 1221 | |
Tom Stellard | 302f53d | 2012-10-25 13:50:10 -0400 | [diff] [blame^] | 1222 | return r; |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | void si_pipe_shader_destroy(struct pipe_context *ctx, struct si_pipe_shader *shader) |
| 1226 | { |
Christian König | fe41287 | 2012-07-24 18:47:19 +0200 | [diff] [blame] | 1227 | si_resource_reference(&shader->bo, NULL); |
Tom Stellard | a75c616 | 2012-01-06 17:38:37 -0500 | [diff] [blame] | 1228 | } |