radeonsi: move shaders to new handling
[mesa.git] / src / gallium / drivers / radeonsi / radeonsi_shader.c
1
2 #include "gallivm/lp_bld_tgsi_action.h"
3 #include "gallivm/lp_bld_const.h"
4 #include "gallivm/lp_bld_intr.h"
5 #include "gallivm/lp_bld_tgsi.h"
6 #include "radeon_llvm.h"
7 #include "radeon_llvm_emit.h"
8 #include "tgsi/tgsi_info.h"
9 #include "tgsi/tgsi_parse.h"
10 #include "tgsi/tgsi_scan.h"
11 #include "tgsi/tgsi_dump.h"
12
13 #include "radeonsi_pipe.h"
14 #include "radeonsi_shader.h"
15 #include "si_state.h"
16 #include "sid.h"
17
18 #include <assert.h>
19 #include <errno.h>
20 #include <stdio.h>
21
22 /*
23 static ps_remap_inputs(
24 struct tgsi_llvm_context * tl_ctx,
25 unsigned tgsi_index,
26 unsigned tgsi_chan)
27 {
28 :
29 }
30
31 struct si_input
32 {
33 struct list_head head;
34 unsigned tgsi_index;
35 unsigned tgsi_chan;
36 unsigned order;
37 };
38 */
39
40
41 struct si_shader_context
42 {
43 struct radeon_llvm_context radeon_bld;
44 struct r600_context *rctx;
45 struct tgsi_parse_context parse;
46 struct tgsi_token * tokens;
47 struct si_pipe_shader *shader;
48 unsigned type; /* TGSI_PROCESSOR_* specifies the type of shader. */
49 /* unsigned num_inputs; */
50 /* struct list_head inputs; */
51 /* unsigned * input_mappings *//* From TGSI to SI hw */
52 /* struct tgsi_shader_info info;*/
53 };
54
55 static struct si_shader_context * si_shader_context(
56 struct lp_build_tgsi_context * bld_base)
57 {
58 return (struct si_shader_context *)bld_base;
59 }
60
61
62 #define PERSPECTIVE_BASE 0
63 #define LINEAR_BASE 9
64
65 #define SAMPLE_OFFSET 0
66 #define CENTER_OFFSET 2
67 #define CENTROID_OFSET 4
68
69 #define USE_SGPR_MAX_SUFFIX_LEN 5
70 #define CONST_ADDR_SPACE 2
71 #define USER_SGPR_ADDR_SPACE 8
72
73 enum sgpr_type {
74 SGPR_CONST_PTR_F32,
75 SGPR_CONST_PTR_V4I32,
76 SGPR_CONST_PTR_V8I32,
77 SGPR_I32,
78 SGPR_I64
79 };
80
81 /**
82 * Build an LLVM bytecode indexed load using LLVMBuildGEP + LLVMBuildLoad
83 *
84 * @param offset The offset parameter specifies the number of
85 * elements to offset, not the number of bytes or dwords. An element is the
86 * the type pointed to by the base_ptr parameter (e.g. int is the element of
87 * an int* pointer)
88 *
89 * When LLVM lowers the load instruction, it will convert the element offset
90 * into a dword offset automatically.
91 *
92 */
93 static LLVMValueRef build_indexed_load(
94 struct gallivm_state * gallivm,
95 LLVMValueRef base_ptr,
96 LLVMValueRef offset)
97 {
98 LLVMValueRef computed_ptr = LLVMBuildGEP(
99 gallivm->builder, base_ptr, &offset, 1, "");
100
101 return LLVMBuildLoad(gallivm->builder, computed_ptr, "");
102 }
103
104 /**
105 * Load a value stored in one of the user SGPRs
106 *
107 * @param sgpr This is the sgpr to load the value from. If you need to load a
108 * value that is stored in consecutive SGPR registers (e.g. a 64-bit pointer),
109 * then you should pass the index of the first SGPR that holds the value. For
110 * example, if you want to load a pointer that is stored in SGPRs 2 and 3, then
111 * use pass 2 for the sgpr parameter.
112 *
113 * The value of the sgpr parameter must also be aligned to the width of the type
114 * being loaded, so that the sgpr parameter is divisible by the dword width of the
115 * type. For example, if the value being loaded is two dwords wide, then the sgpr
116 * parameter must be divisible by two.
117 */
118 static LLVMValueRef use_sgpr(
119 struct gallivm_state * gallivm,
120 enum sgpr_type type,
121 unsigned sgpr)
122 {
123 LLVMValueRef sgpr_index;
124 LLVMTypeRef ret_type;
125 LLVMValueRef ptr;
126
127 sgpr_index = lp_build_const_int32(gallivm, sgpr);
128
129 switch (type) {
130 case SGPR_CONST_PTR_F32:
131 assert(sgpr % 2 == 0);
132 ret_type = LLVMFloatTypeInContext(gallivm->context);
133 ret_type = LLVMPointerType(ret_type, CONST_ADDR_SPACE);
134 break;
135
136 case SGPR_I32:
137 ret_type = LLVMInt32TypeInContext(gallivm->context);
138 break;
139
140 case SGPR_I64:
141 assert(sgpr % 2 == 0);
142 ret_type= LLVMInt64TypeInContext(gallivm->context);
143 break;
144
145 case SGPR_CONST_PTR_V4I32:
146 assert(sgpr % 2 == 0);
147 ret_type = LLVMInt32TypeInContext(gallivm->context);
148 ret_type = LLVMVectorType(ret_type, 4);
149 ret_type = LLVMPointerType(ret_type, CONST_ADDR_SPACE);
150 break;
151
152 case SGPR_CONST_PTR_V8I32:
153 assert(sgpr % 2 == 0);
154 ret_type = LLVMInt32TypeInContext(gallivm->context);
155 ret_type = LLVMVectorType(ret_type, 8);
156 ret_type = LLVMPointerType(ret_type, CONST_ADDR_SPACE);
157 break;
158
159 default:
160 assert(!"Unsupported SGPR type in use_sgpr()");
161 return NULL;
162 }
163
164 ret_type = LLVMPointerType(ret_type, USER_SGPR_ADDR_SPACE);
165 ptr = LLVMBuildIntToPtr(gallivm->builder, sgpr_index, ret_type, "");
166 return LLVMBuildLoad(gallivm->builder, ptr, "");
167 }
168
169 static void declare_input_vs(
170 struct si_shader_context * si_shader_ctx,
171 unsigned input_index,
172 const struct tgsi_full_declaration *decl)
173 {
174 LLVMValueRef t_list_ptr;
175 LLVMValueRef t_offset;
176 LLVMValueRef t_list;
177 LLVMValueRef attribute_offset;
178 LLVMValueRef buffer_index_reg;
179 LLVMValueRef args[3];
180 LLVMTypeRef vec4_type;
181 LLVMValueRef input;
182 struct lp_build_context * uint = &si_shader_ctx->radeon_bld.soa.bld_base.uint_bld;
183 struct lp_build_context * base = &si_shader_ctx->radeon_bld.soa.bld_base.base;
184 struct r600_context *rctx = si_shader_ctx->rctx;
185 struct pipe_vertex_element *velem = &rctx->vertex_elements->elements[input_index];
186 unsigned chan;
187
188 /* Load the T list */
189 /* XXX: Communicate with the rest of the driver about which SGPR the T#
190 * list pointer is going to be stored in. Hard code to SGPR[6:7] for
191 * now */
192 t_list_ptr = use_sgpr(base->gallivm, SGPR_CONST_PTR_V4I32, 6);
193
194 t_offset = lp_build_const_int32(base->gallivm, velem->vertex_buffer_index);
195
196 t_list = build_indexed_load(base->gallivm, t_list_ptr, t_offset);
197
198 /* Build the attribute offset */
199 attribute_offset = lp_build_const_int32(base->gallivm, velem->src_offset);
200
201 /* Load the buffer index is always, which is always stored in VGPR0
202 * for Vertex Shaders */
203 buffer_index_reg = lp_build_intrinsic(base->gallivm->builder,
204 "llvm.SI.vs.load.buffer.index", uint->elem_type, NULL, 0);
205
206 vec4_type = LLVMVectorType(base->elem_type, 4);
207 args[0] = t_list;
208 args[1] = attribute_offset;
209 args[2] = buffer_index_reg;
210 input = lp_build_intrinsic(base->gallivm->builder,
211 "llvm.SI.vs.load.input", vec4_type, args, 3);
212
213 /* Break up the vec4 into individual components */
214 for (chan = 0; chan < 4; chan++) {
215 LLVMValueRef llvm_chan = lp_build_const_int32(base->gallivm, chan);
216 /* XXX: Use a helper function for this. There is one in
217 * tgsi_llvm.c. */
218 si_shader_ctx->radeon_bld.inputs[radeon_llvm_reg_index_soa(input_index, chan)] =
219 LLVMBuildExtractElement(base->gallivm->builder,
220 input, llvm_chan, "");
221 }
222 }
223
224 static void declare_input_fs(
225 struct si_shader_context * si_shader_ctx,
226 unsigned input_index,
227 const struct tgsi_full_declaration *decl)
228 {
229 const char * intr_name;
230 unsigned chan;
231 struct lp_build_context * base =
232 &si_shader_ctx->radeon_bld.soa.bld_base.base;
233 struct gallivm_state * gallivm = base->gallivm;
234
235 /* This value is:
236 * [15:0] NewPrimMask (Bit mask for each quad. It is set it the
237 * quad begins a new primitive. Bit 0 always needs
238 * to be unset)
239 * [32:16] ParamOffset
240 *
241 */
242 /* XXX: This register number must be identical to the S_00B02C_USER_SGPR
243 * register field value
244 */
245 LLVMValueRef params = use_sgpr(base->gallivm, SGPR_I32, 6);
246
247
248 /* XXX: Is this the input_index? */
249 LLVMValueRef attr_number = lp_build_const_int32(gallivm, input_index);
250
251 /* XXX: Handle all possible interpolation modes */
252 switch (decl->Interp.Interpolate) {
253 case TGSI_INTERPOLATE_COLOR:
254 /* XXX: Flat shading hangs the GPU */
255 if (si_shader_ctx->rctx->queued.named.rasterizer->flatshade) {
256 #if 0
257 intr_name = "llvm.SI.fs.interp.constant";
258 #else
259 intr_name = "llvm.SI.fs.interp.linear.center";
260 #endif
261 } else {
262 if (decl->Interp.Centroid)
263 intr_name = "llvm.SI.fs.interp.persp.centroid";
264 else
265 intr_name = "llvm.SI.fs.interp.persp.center";
266 }
267 break;
268 case TGSI_INTERPOLATE_CONSTANT:
269 /* XXX: Flat shading hangs the GPU */
270 #if 0
271 intr_name = "llvm.SI.fs.interp.constant";
272 break;
273 #endif
274 case TGSI_INTERPOLATE_LINEAR:
275 if (decl->Interp.Centroid)
276 intr_name = "llvm.SI.fs.interp.linear.centroid";
277 else
278 intr_name = "llvm.SI.fs.interp.linear.center";
279 break;
280 case TGSI_INTERPOLATE_PERSPECTIVE:
281 if (decl->Interp.Centroid)
282 intr_name = "llvm.SI.fs.interp.persp.centroid";
283 else
284 intr_name = "llvm.SI.fs.interp.persp.center";
285 break;
286 default:
287 fprintf(stderr, "Warning: Unhandled interpolation mode.\n");
288 return;
289 }
290
291 /* XXX: Could there be more than TGSI_NUM_CHANNELS (4) ? */
292 for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
293 LLVMValueRef args[3];
294 LLVMValueRef llvm_chan = lp_build_const_int32(gallivm, chan);
295 unsigned soa_index = radeon_llvm_reg_index_soa(input_index, chan);
296 LLVMTypeRef input_type = LLVMFloatTypeInContext(gallivm->context);
297 args[0] = llvm_chan;
298 args[1] = attr_number;
299 args[2] = params;
300 si_shader_ctx->radeon_bld.inputs[soa_index] =
301 lp_build_intrinsic(gallivm->builder, intr_name,
302 input_type, args, 3);
303 }
304 }
305
306 static void declare_input(
307 struct radeon_llvm_context * radeon_bld,
308 unsigned input_index,
309 const struct tgsi_full_declaration *decl)
310 {
311 struct si_shader_context * si_shader_ctx =
312 si_shader_context(&radeon_bld->soa.bld_base);
313 if (si_shader_ctx->type == TGSI_PROCESSOR_VERTEX) {
314 declare_input_vs(si_shader_ctx, input_index, decl);
315 } else if (si_shader_ctx->type == TGSI_PROCESSOR_FRAGMENT) {
316 declare_input_fs(si_shader_ctx, input_index, decl);
317 } else {
318 fprintf(stderr, "Warning: Unsupported shader type,\n");
319 }
320 }
321
322 static LLVMValueRef fetch_constant(
323 struct lp_build_tgsi_context * bld_base,
324 const struct tgsi_full_src_register *reg,
325 enum tgsi_opcode_type type,
326 unsigned swizzle)
327 {
328 struct lp_build_context * base = &bld_base->base;
329
330 LLVMValueRef const_ptr;
331 LLVMValueRef offset;
332
333 /* XXX: Assume the pointer to the constant buffer is being stored in
334 * SGPR[0:1] */
335 const_ptr = use_sgpr(base->gallivm, SGPR_CONST_PTR_F32, 0);
336
337 /* XXX: This assumes that the constant buffer is not packed, so
338 * CONST[0].x will have an offset of 0 and CONST[1].x will have an
339 * offset of 4. */
340 offset = lp_build_const_int32(base->gallivm,
341 (reg->Register.Index * 4) + swizzle);
342
343 return build_indexed_load(base->gallivm, const_ptr, offset);
344 }
345
346 /* XXX: This is partially implemented for VS only at this point. It is not complete */
347 static void si_llvm_emit_epilogue(struct lp_build_tgsi_context * bld_base)
348 {
349 struct si_shader_context * si_shader_ctx = si_shader_context(bld_base);
350 struct si_shader * shader = &si_shader_ctx->shader->shader;
351 struct lp_build_context * base = &bld_base->base;
352 struct lp_build_context * uint =
353 &si_shader_ctx->radeon_bld.soa.bld_base.uint_bld;
354 struct tgsi_parse_context *parse = &si_shader_ctx->parse;
355 LLVMValueRef last_args[9] = { 0 };
356
357 while (!tgsi_parse_end_of_tokens(parse)) {
358 /* XXX: component_bits controls which components of the output
359 * registers actually get exported. (e.g bit 0 means export
360 * X component, bit 1 means export Y component, etc.) I'm
361 * hard coding this to 0xf for now. In the future, we might
362 * want to do something else. */
363 unsigned component_bits = 0xf;
364 unsigned chan;
365 struct tgsi_full_declaration *d =
366 &parse->FullToken.FullDeclaration;
367 LLVMValueRef args[9];
368 unsigned target;
369 unsigned index;
370 unsigned color_count = 0;
371 unsigned param_count = 0;
372 int i;
373
374 tgsi_parse_token(parse);
375 if (parse->FullToken.Token.Type != TGSI_TOKEN_TYPE_DECLARATION)
376 continue;
377
378 switch (d->Declaration.File) {
379 case TGSI_FILE_INPUT:
380 i = shader->ninput++;
381 shader->input[i].name = d->Semantic.Name;
382 shader->input[i].sid = d->Semantic.Index;
383 shader->input[i].interpolate = d->Interp.Interpolate;
384 shader->input[i].centroid = d->Interp.Centroid;
385 break;
386 case TGSI_FILE_OUTPUT:
387 i = shader->noutput++;
388 shader->output[i].name = d->Semantic.Name;
389 shader->output[i].sid = d->Semantic.Index;
390 shader->output[i].interpolate = d->Interp.Interpolate;
391 break;
392 }
393
394 if (d->Declaration.File != TGSI_FILE_OUTPUT)
395 continue;
396
397 for (index = d->Range.First; index <= d->Range.Last; index++) {
398 for (chan = 0; chan < 4; chan++ ) {
399 LLVMValueRef out_ptr =
400 si_shader_ctx->radeon_bld.soa.outputs
401 [index][chan];
402 /* +5 because the first output value will be
403 * the 6th argument to the intrinsic. */
404 args[chan + 5]= LLVMBuildLoad(
405 base->gallivm->builder, out_ptr, "");
406 }
407
408 /* XXX: We probably need to keep track of the output
409 * values, so we know what we are passing to the next
410 * stage. */
411
412 /* Select the correct target */
413 switch(d->Semantic.Name) {
414 case TGSI_SEMANTIC_POSITION:
415 target = V_008DFC_SQ_EXP_POS;
416 break;
417 case TGSI_SEMANTIC_COLOR:
418 if (si_shader_ctx->type == TGSI_PROCESSOR_VERTEX) {
419 target = V_008DFC_SQ_EXP_PARAM + param_count;
420 shader->output[i].param_offset = param_count;
421 param_count++;
422 } else {
423 target = V_008DFC_SQ_EXP_MRT + color_count;
424 color_count++;
425 }
426 break;
427 case TGSI_SEMANTIC_GENERIC:
428 target = V_008DFC_SQ_EXP_PARAM + param_count;
429 shader->output[i].param_offset = param_count;
430 param_count++;
431 break;
432 default:
433 target = 0;
434 fprintf(stderr,
435 "Warning: SI unhandled output type:%d\n",
436 d->Semantic.Name);
437 }
438
439 /* Specify which components to enable */
440 args[0] = lp_build_const_int32(base->gallivm,
441 component_bits);
442
443 /* Specify whether the EXEC mask represents the valid mask */
444 args[1] = lp_build_const_int32(base->gallivm, 0);
445
446 /* Specify whether this is the last export */
447 args[2] = lp_build_const_int32(base->gallivm, 0);
448
449 /* Specify the target we are exporting */
450 args[3] = lp_build_const_int32(base->gallivm, target);
451
452 /* Set COMPR flag to zero to export data as 32-bit */
453 args[4] = uint->zero;
454
455 if (si_shader_ctx->type == TGSI_PROCESSOR_VERTEX ?
456 (d->Semantic.Name == TGSI_SEMANTIC_POSITION) :
457 (d->Semantic.Name == TGSI_SEMANTIC_COLOR)) {
458 if (last_args[0]) {
459 lp_build_intrinsic(base->gallivm->builder,
460 "llvm.SI.export",
461 LLVMVoidTypeInContext(base->gallivm->context),
462 last_args, 9);
463 }
464
465 memcpy(last_args, args, sizeof(args));
466 } else {
467 lp_build_intrinsic(base->gallivm->builder,
468 "llvm.SI.export",
469 LLVMVoidTypeInContext(base->gallivm->context),
470 args, 9);
471 }
472
473 }
474 }
475
476 /* Specify whether the EXEC mask represents the valid mask */
477 last_args[1] = lp_build_const_int32(base->gallivm,
478 si_shader_ctx->type == TGSI_PROCESSOR_FRAGMENT);
479
480 /* Specify that this is the last export */
481 last_args[2] = lp_build_const_int32(base->gallivm, 1);
482
483 lp_build_intrinsic(base->gallivm->builder,
484 "llvm.SI.export",
485 LLVMVoidTypeInContext(base->gallivm->context),
486 last_args, 9);
487
488 /* XXX: Look up what this function does */
489 /* ctx->shader->output[i].spi_sid = r600_spi_sid(&ctx->shader->output[i]);*/
490 }
491
492 static void tex_fetch_args(
493 struct lp_build_tgsi_context * bld_base,
494 struct lp_build_emit_data * emit_data)
495 {
496 LLVMValueRef ptr;
497 LLVMValueRef offset;
498
499 /* WriteMask */
500 emit_data->args[0] = lp_build_const_int32(bld_base->base.gallivm,
501 emit_data->inst->Dst[0].Register.WriteMask);
502
503 /* Coordinates */
504 /* XXX: Not all sample instructions need 4 address arguments. */
505 emit_data->args[1] = lp_build_emit_fetch(bld_base, emit_data->inst,
506 0, LP_CHAN_ALL);
507
508 /* Resource */
509 ptr = use_sgpr(bld_base->base.gallivm, SGPR_CONST_PTR_V8I32, 4);
510 offset = lp_build_const_int32(bld_base->base.gallivm,
511 8 * emit_data->inst->Src[1].Register.Index);
512 emit_data->args[2] = build_indexed_load(bld_base->base.gallivm,
513 ptr, offset);
514
515 /* Sampler */
516 ptr = use_sgpr(bld_base->base.gallivm, SGPR_CONST_PTR_V4I32, 2);
517 offset = lp_build_const_int32(bld_base->base.gallivm,
518 4 * emit_data->inst->Src[1].Register.Index);
519 emit_data->args[3] = build_indexed_load(bld_base->base.gallivm,
520 ptr, offset);
521
522 /* Dimensions */
523 /* XXX: We might want to pass this information to the shader at some. */
524 /* emit_data->args[4] = lp_build_const_int32(bld_base->base.gallivm,
525 emit_data->inst->Texture.Texture);
526 */
527
528 emit_data->arg_count = 4;
529 /* XXX: To optimize, we could use a float or v2f32, if the last bits of
530 * the writemask are clear */
531 emit_data->dst_type = LLVMVectorType(
532 LLVMFloatTypeInContext(bld_base->base.gallivm->context),
533 4);
534 }
535
536 static const struct lp_build_tgsi_action tex_action = {
537 .fetch_args = tex_fetch_args,
538 .emit = lp_build_tgsi_intrinsic,
539 .intr_name = "llvm.SI.sample"
540 };
541
542
543 int si_pipe_shader_create(
544 struct pipe_context *ctx,
545 struct si_pipe_shader *shader)
546 {
547 struct r600_context *rctx = (struct r600_context*)ctx;
548 struct si_shader_context si_shader_ctx;
549 struct tgsi_shader_info shader_info;
550 struct lp_build_tgsi_context * bld_base;
551 LLVMModuleRef mod;
552 unsigned char * inst_bytes;
553 unsigned inst_byte_count;
554 unsigned i;
555 bool dump;
556
557 dump = debug_get_bool_option("RADEON_DUMP_SHADERS", FALSE);
558
559 radeon_llvm_context_init(&si_shader_ctx.radeon_bld);
560 bld_base = &si_shader_ctx.radeon_bld.soa.bld_base;
561
562 tgsi_scan_shader(shader->tokens, &shader_info);
563 bld_base->info = &shader_info;
564 bld_base->emit_fetch_funcs[TGSI_FILE_CONSTANT] = fetch_constant;
565 bld_base->emit_epilogue = si_llvm_emit_epilogue;
566
567 bld_base->op_actions[TGSI_OPCODE_TEX] = tex_action;
568
569 si_shader_ctx.radeon_bld.load_input = declare_input;
570 si_shader_ctx.tokens = shader->tokens;
571 tgsi_parse_init(&si_shader_ctx.parse, si_shader_ctx.tokens);
572 si_shader_ctx.shader = shader;
573 si_shader_ctx.type = si_shader_ctx.parse.FullHeader.Processor.Processor;
574 si_shader_ctx.rctx = rctx;
575
576 shader->shader.nr_cbufs = rctx->framebuffer.nr_cbufs;
577
578 /* Dump TGSI code before doing TGSI->LLVM conversion in case the
579 * conversion fails. */
580 if (dump) {
581 tgsi_dump(shader->tokens, 0);
582 }
583
584 lp_build_tgsi_llvm(bld_base, shader->tokens);
585
586 radeon_llvm_finalize_module(&si_shader_ctx.radeon_bld);
587
588 mod = bld_base->base.gallivm->module;
589 if (dump) {
590 LLVMDumpModule(mod);
591 }
592 radeon_llvm_compile(mod, &inst_bytes, &inst_byte_count, "SI", dump);
593 if (dump) {
594 fprintf(stderr, "SI CODE:\n");
595 for (i = 0; i < inst_byte_count; i+=4 ) {
596 fprintf(stderr, "%02x%02x%02x%02x\n", inst_bytes[i + 3],
597 inst_bytes[i + 2], inst_bytes[i + 1],
598 inst_bytes[i]);
599 }
600 }
601
602 shader->num_sgprs = util_le32_to_cpu(*(uint32_t*)inst_bytes);
603 shader->num_vgprs = util_le32_to_cpu(*(uint32_t*)(inst_bytes + 4));
604 shader->spi_ps_input_ena = util_le32_to_cpu(*(uint32_t*)(inst_bytes + 8));
605
606 tgsi_parse_free(&si_shader_ctx.parse);
607
608 /* copy new shader */
609 if (shader->bo == NULL) {
610 uint32_t *ptr;
611
612 shader->bo = (struct r600_resource*)
613 pipe_buffer_create(ctx->screen, PIPE_BIND_CUSTOM, PIPE_USAGE_IMMUTABLE, inst_byte_count);
614 if (shader->bo == NULL) {
615 return -ENOMEM;
616 }
617 ptr = (uint32_t*)rctx->ws->buffer_map(shader->bo->cs_buf, rctx->cs, PIPE_TRANSFER_WRITE);
618 if (0 /*R600_BIG_ENDIAN*/) {
619 for (i = 0; i < (inst_byte_count-12)/4; ++i) {
620 ptr[i] = util_bswap32(*(uint32_t*)(inst_bytes+12 + i*4));
621 }
622 } else {
623 memcpy(ptr, inst_bytes + 12, inst_byte_count - 12);
624 }
625 rctx->ws->buffer_unmap(shader->bo->cs_buf);
626 }
627
628 free(inst_bytes);
629
630 return 0;
631 }
632
633 void si_pipe_shader_destroy(struct pipe_context *ctx, struct si_pipe_shader *shader)
634 {
635 pipe_resource_reference((struct pipe_resource**)&shader->bo, NULL);
636
637 memset(&shader->shader,0,sizeof(struct si_shader));
638 }