2 * Copyright (c) 2017 Lima Project
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sub license,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
25 #include "util/ralloc.h"
26 #include "util/u_half.h"
27 #include "util/bitscan.h"
31 #include "lima_context.h"
33 static unsigned encode_swizzle(uint8_t *swizzle
, int shift
, int dest_shift
)
36 for (int i
= 0; i
< 4; i
++)
37 ret
|= ((swizzle
[i
] + shift
) & 0x3) << ((i
+ dest_shift
) * 2);
41 static int get_scl_reg_index(ppir_src
*src
, int component
)
43 int ret
= ppir_target_get_src_reg_index(src
);
44 ret
+= src
->swizzle
[component
];
48 static void ppir_codegen_encode_varying(ppir_node
*node
, void *code
)
50 ppir_codegen_field_varying
*f
= code
;
51 ppir_load_node
*load
= ppir_node_to_load(node
);
52 ppir_dest
*dest
= &load
->dest
;
53 int index
= ppir_target_get_dest_reg_index(dest
);
54 int num_components
= load
->num_components
;
56 if (node
->op
!= ppir_op_load_coords_reg
) {
57 assert(node
->op
== ppir_op_load_varying
||
58 node
->op
== ppir_op_load_coords
||
59 node
->op
== ppir_op_load_fragcoord
||
60 node
->op
== ppir_op_load_pointcoord
||
61 node
->op
== ppir_op_load_frontface
);
63 f
->imm
.dest
= index
>> 2;
64 f
->imm
.mask
= dest
->write_mask
<< (index
& 0x3);
66 int alignment
= num_components
== 3 ? 3 : num_components
- 1;
67 f
->imm
.alignment
= alignment
;
70 index
= ppir_target_get_src_reg_index(&load
->src
);
71 f
->imm
.offset_vector
= index
>> 2;
72 f
->imm
.offset_scalar
= index
& 0x3;
74 f
->imm
.offset_vector
= 0xf;
77 f
->imm
.index
= load
->index
>> 2;
79 f
->imm
.index
= load
->index
>> alignment
;
82 case ppir_op_load_fragcoord
:
83 f
->imm
.source_type
= 2;
84 f
->imm
.perspective
= 3;
86 case ppir_op_load_pointcoord
:
87 f
->imm
.source_type
= 3;
89 case ppir_op_load_frontface
:
90 f
->imm
.source_type
= 3;
91 f
->imm
.perspective
= 1;
93 case ppir_op_load_coords
:
94 /* num_components == 3 implies cubemap as we don't support 3D textures */
95 f
->imm
.source_type
= num_components
== 3 ? 2 : 0;
101 else { /* node->op == ppir_op_load_coords_reg */
102 f
->reg
.dest
= index
>> 2;
103 f
->reg
.mask
= dest
->write_mask
<< (index
& 0x3);
106 /* num_components == 3 implies cubemap as we don't support 3D textures */
107 if (num_components
== 3) {
108 f
->reg
.source_type
= 2;
109 f
->reg
.perspective
= 1;
111 f
->reg
.source_type
= 1;
113 ppir_src
*src
= &load
->src
;
114 index
= ppir_target_get_src_reg_index(src
);
115 f
->reg
.source
= index
>> 2;
116 f
->reg
.negate
= src
->negate
;
117 f
->reg
.absolute
= src
->absolute
;
118 f
->reg
.swizzle
= encode_swizzle(src
->swizzle
, index
& 0x3, 0);
123 static void ppir_codegen_encode_texld(ppir_node
*node
, void *code
)
125 ppir_codegen_field_sampler
*f
= code
;
126 ppir_load_texture_node
*ldtex
= ppir_node_to_load_texture(node
);
128 f
->index
= ldtex
->sampler
;
130 f
->lod_bias_en
= ldtex
->lod_bias_en
;
131 f
->explicit_lod
= ldtex
->explicit_lod
;
132 if (ldtex
->lod_bias_en
)
133 ppir_target_get_src_reg_index(&ldtex
->src
[1]);
135 switch (ldtex
->sampler_dim
) {
136 case GLSL_SAMPLER_DIM_2D
:
137 case GLSL_SAMPLER_DIM_RECT
:
138 case GLSL_SAMPLER_DIM_EXTERNAL
:
139 f
->type
= ppir_codegen_sampler_type_2d
;
141 case GLSL_SAMPLER_DIM_CUBE
:
142 f
->type
= ppir_codegen_sampler_type_cube
;
149 f
->unknown_2
= 0x39001;
152 static void ppir_codegen_encode_uniform(ppir_node
*node
, void *code
)
154 ppir_codegen_field_uniform
*f
= code
;
155 ppir_load_node
*load
= ppir_node_to_load(node
);
158 case ppir_op_load_uniform
:
159 f
->source
= ppir_codegen_uniform_src_uniform
;
161 case ppir_op_load_temp
:
162 f
->source
= ppir_codegen_uniform_src_temporary
;
168 /* Uniforms are always aligned to vec4 boundary */
170 f
->index
= load
->index
;
174 f
->offset_reg
= ppir_target_get_src_reg_index(&load
->src
);
178 static unsigned shift_to_op(int shift
)
180 assert(shift
>= -3 && shift
<= 3);
181 return shift
< 0 ? shift
+ 8 : shift
;
184 static void ppir_codegen_encode_vec_mul(ppir_node
*node
, void *code
)
186 ppir_codegen_field_vec4_mul
*f
= code
;
187 ppir_alu_node
*alu
= ppir_node_to_alu(node
);
189 ppir_dest
*dest
= &alu
->dest
;
191 if (dest
->type
!= ppir_target_pipeline
) {
192 int index
= ppir_target_get_dest_reg_index(dest
);
193 dest_shift
= index
& 0x3;
194 f
->dest
= index
>> 2;
195 f
->mask
= dest
->write_mask
<< dest_shift
;
197 f
->dest_modifier
= dest
->modifier
;
201 f
->op
= shift_to_op(alu
->shift
);
204 case ppir_op_store_color
:
205 f
->op
= ppir_codegen_vec4_mul_op_mov
;
208 f
->op
= ppir_codegen_vec4_mul_op_max
;
211 f
->op
= ppir_codegen_vec4_mul_op_min
;
214 f
->op
= ppir_codegen_vec4_mul_op_and
;
217 f
->op
= ppir_codegen_vec4_mul_op_or
;
220 f
->op
= ppir_codegen_vec4_mul_op_xor
;
223 f
->op
= ppir_codegen_vec4_mul_op_gt
;
226 f
->op
= ppir_codegen_vec4_mul_op_ge
;
229 f
->op
= ppir_codegen_vec4_mul_op_eq
;
232 f
->op
= ppir_codegen_vec4_mul_op_ne
;
235 f
->op
= ppir_codegen_vec4_mul_op_not
;
241 ppir_src
*src
= alu
->src
;
242 int index
= ppir_target_get_src_reg_index(src
);
243 f
->arg0_source
= index
>> 2;
244 f
->arg0_swizzle
= encode_swizzle(src
->swizzle
, index
& 0x3, dest_shift
);
245 f
->arg0_absolute
= src
->absolute
;
246 f
->arg0_negate
= src
->negate
;
248 if (alu
->num_src
== 2) {
250 index
= ppir_target_get_src_reg_index(src
);
251 f
->arg1_source
= index
>> 2;
252 f
->arg1_swizzle
= encode_swizzle(src
->swizzle
, index
& 0x3, dest_shift
);
253 f
->arg1_absolute
= src
->absolute
;
254 f
->arg1_negate
= src
->negate
;
258 static void ppir_codegen_encode_scl_mul(ppir_node
*node
, void *code
)
260 ppir_codegen_field_float_mul
*f
= code
;
261 ppir_alu_node
*alu
= ppir_node_to_alu(node
);
263 ppir_dest
*dest
= &alu
->dest
;
264 int dest_component
= ffs(dest
->write_mask
) - 1;
265 assert(dest_component
>= 0);
267 if (dest
->type
!= ppir_target_pipeline
) {
268 f
->dest
= ppir_target_get_dest_reg_index(dest
) + dest_component
;
271 f
->dest_modifier
= dest
->modifier
;
275 f
->op
= shift_to_op(alu
->shift
);
278 f
->op
= ppir_codegen_float_mul_op_mov
;
280 case ppir_op_sel_cond
:
281 f
->op
= ppir_codegen_float_mul_op_mov
;
284 f
->op
= ppir_codegen_float_mul_op_max
;
287 f
->op
= ppir_codegen_float_mul_op_min
;
290 f
->op
= ppir_codegen_float_mul_op_and
;
293 f
->op
= ppir_codegen_float_mul_op_or
;
296 f
->op
= ppir_codegen_float_mul_op_xor
;
299 f
->op
= ppir_codegen_float_mul_op_gt
;
302 f
->op
= ppir_codegen_float_mul_op_ge
;
305 f
->op
= ppir_codegen_float_mul_op_eq
;
308 f
->op
= ppir_codegen_float_mul_op_ne
;
311 f
->op
= ppir_codegen_float_mul_op_not
;
317 ppir_src
*src
= alu
->src
;
318 f
->arg0_source
= get_scl_reg_index(src
, dest_component
);
319 f
->arg0_absolute
= src
->absolute
;
320 f
->arg0_negate
= src
->negate
;
322 if (alu
->num_src
== 2) {
324 f
->arg1_source
= get_scl_reg_index(src
, dest_component
);
325 f
->arg1_absolute
= src
->absolute
;
326 f
->arg1_negate
= src
->negate
;
330 static void ppir_codegen_encode_vec_add(ppir_node
*node
, void *code
)
332 ppir_codegen_field_vec4_acc
*f
= code
;
333 ppir_alu_node
*alu
= ppir_node_to_alu(node
);
335 ppir_dest
*dest
= &alu
->dest
;
336 int index
= ppir_target_get_dest_reg_index(dest
);
337 int dest_shift
= index
& 0x3;
338 f
->dest
= index
>> 2;
339 f
->mask
= dest
->write_mask
<< dest_shift
;
340 f
->dest_modifier
= dest
->modifier
;
344 f
->op
= ppir_codegen_vec4_acc_op_add
;
347 case ppir_op_store_color
:
348 f
->op
= ppir_codegen_vec4_acc_op_mov
;
351 f
->op
= ppir_codegen_vec4_acc_op_sum3
;
355 f
->op
= ppir_codegen_vec4_acc_op_sum4
;
359 f
->op
= ppir_codegen_vec4_acc_op_floor
;
362 f
->op
= ppir_codegen_vec4_acc_op_ceil
;
365 f
->op
= ppir_codegen_vec4_acc_op_fract
;
368 f
->op
= ppir_codegen_vec4_acc_op_gt
;
371 f
->op
= ppir_codegen_vec4_acc_op_ge
;
374 f
->op
= ppir_codegen_vec4_acc_op_eq
;
377 f
->op
= ppir_codegen_vec4_acc_op_ne
;
380 f
->op
= ppir_codegen_vec4_acc_op_sel
;
383 f
->op
= ppir_codegen_vec4_acc_op_max
;
386 f
->op
= ppir_codegen_vec4_acc_op_min
;
389 f
->op
= ppir_codegen_vec4_acc_op_dFdx
;
392 f
->op
= ppir_codegen_vec4_acc_op_dFdy
;
398 ppir_src
*src
= node
->op
== ppir_op_select
? alu
->src
+ 1 : alu
->src
;
399 index
= ppir_target_get_src_reg_index(src
);
401 if (src
->type
== ppir_target_pipeline
&&
402 src
->pipeline
== ppir_pipeline_reg_vmul
)
405 f
->arg0_source
= index
>> 2;
407 f
->arg0_swizzle
= encode_swizzle(src
->swizzle
, index
& 0x3, dest_shift
);
408 f
->arg0_absolute
= src
->absolute
;
409 f
->arg0_negate
= src
->negate
;
411 if (++src
< alu
->src
+ alu
->num_src
) {
412 index
= ppir_target_get_src_reg_index(src
);
413 f
->arg1_source
= index
>> 2;
414 f
->arg1_swizzle
= encode_swizzle(src
->swizzle
, index
& 0x3, dest_shift
);
415 f
->arg1_absolute
= src
->absolute
;
416 f
->arg1_negate
= src
->negate
;
420 static void ppir_codegen_encode_scl_add(ppir_node
*node
, void *code
)
422 ppir_codegen_field_float_acc
*f
= code
;
423 ppir_alu_node
*alu
= ppir_node_to_alu(node
);
425 ppir_dest
*dest
= &alu
->dest
;
426 int dest_component
= ffs(dest
->write_mask
) - 1;
427 assert(dest_component
>= 0);
429 f
->dest
= ppir_target_get_dest_reg_index(dest
) + dest_component
;
431 f
->dest_modifier
= dest
->modifier
;
435 f
->op
= shift_to_op(alu
->shift
);
438 f
->op
= ppir_codegen_float_acc_op_mov
;
441 f
->op
= ppir_codegen_float_acc_op_max
;
444 f
->op
= ppir_codegen_float_acc_op_min
;
447 f
->op
= ppir_codegen_float_acc_op_floor
;
450 f
->op
= ppir_codegen_float_acc_op_ceil
;
453 f
->op
= ppir_codegen_float_acc_op_fract
;
456 f
->op
= ppir_codegen_float_acc_op_gt
;
459 f
->op
= ppir_codegen_float_acc_op_ge
;
462 f
->op
= ppir_codegen_float_acc_op_eq
;
465 f
->op
= ppir_codegen_float_acc_op_ne
;
468 f
->op
= ppir_codegen_float_acc_op_sel
;
471 f
->op
= ppir_codegen_float_acc_op_dFdx
;
474 f
->op
= ppir_codegen_float_acc_op_dFdy
;
480 ppir_src
*src
= node
->op
== ppir_op_select
? alu
->src
+ 1: alu
->src
;
481 if (src
->type
== ppir_target_pipeline
&&
482 src
->pipeline
== ppir_pipeline_reg_fmul
)
485 f
->arg0_source
= get_scl_reg_index(src
, dest_component
);
486 f
->arg0_absolute
= src
->absolute
;
487 f
->arg0_negate
= src
->negate
;
489 if (++src
< alu
->src
+ alu
->num_src
) {
490 f
->arg1_source
= get_scl_reg_index(src
, dest_component
);
491 f
->arg1_absolute
= src
->absolute
;
492 f
->arg1_negate
= src
->negate
;
496 static void ppir_codegen_encode_combine(ppir_node
*node
, void *code
)
498 ppir_codegen_field_combine
*f
= code
;
499 ppir_alu_node
*alu
= ppir_node_to_alu(node
);
510 f
->scalar
.dest_vec
= false;
511 f
->scalar
.arg1_en
= false;
513 ppir_dest
*dest
= &alu
->dest
;
514 int dest_component
= ffs(dest
->write_mask
) - 1;
515 assert(dest_component
>= 0);
516 f
->scalar
.dest
= ppir_target_get_dest_reg_index(dest
) + dest_component
;
517 f
->scalar
.dest_modifier
= dest
->modifier
;
519 ppir_src
*src
= alu
->src
;
520 f
->scalar
.arg0_src
= get_scl_reg_index(src
, dest_component
);
521 f
->scalar
.arg0_absolute
= src
->absolute
;
522 f
->scalar
.arg0_negate
= src
->negate
;
526 f
->scalar
.op
= ppir_codegen_combine_scalar_op_rsqrt
;
529 f
->scalar
.op
= ppir_codegen_combine_scalar_op_log2
;
532 f
->scalar
.op
= ppir_codegen_combine_scalar_op_exp2
;
535 f
->scalar
.op
= ppir_codegen_combine_scalar_op_rcp
;
538 f
->scalar
.op
= ppir_codegen_combine_scalar_op_sqrt
;
541 f
->scalar
.op
= ppir_codegen_combine_scalar_op_sin
;
544 f
->scalar
.op
= ppir_codegen_combine_scalar_op_cos
;
555 static void ppir_codegen_encode_store_temp(ppir_node
*node
, void *code
)
557 assert(node
->op
== ppir_op_store_temp
);
559 ppir_codegen_field_temp_write
*f
= code
;
560 ppir_store_node
*snode
= ppir_node_to_store(node
);
561 int num_components
= snode
->num_components
;
563 f
->temp_write
.dest
= 0x03; // 11 - temporary
564 f
->temp_write
.source
= snode
->src
.reg
->index
;
566 int alignment
= num_components
== 4 ? 2 : num_components
- 1;
567 f
->temp_write
.alignment
= alignment
;
568 f
->temp_write
.index
= snode
->index
<< (2 - alignment
);
570 f
->temp_write
.offset_reg
= snode
->index
>> 2;
573 static void ppir_codegen_encode_const(ppir_const
*constant
, uint16_t *code
)
575 for (int i
= 0; i
< constant
->num
; i
++)
576 code
[i
] = util_float_to_half(constant
->value
[i
].f
);
579 static void ppir_codegen_encode_discard(ppir_node
*node
, void *code
)
581 ppir_codegen_field_branch
*b
= code
;
582 assert(node
->op
== ppir_op_discard
);
584 b
->discard
.word0
= PPIR_CODEGEN_DISCARD_WORD0
;
585 b
->discard
.word1
= PPIR_CODEGEN_DISCARD_WORD1
;
586 b
->discard
.word2
= PPIR_CODEGEN_DISCARD_WORD2
;
589 static void ppir_codegen_encode_branch(ppir_node
*node
, void *code
)
591 ppir_codegen_field_branch
*b
= code
;
592 ppir_branch_node
*branch
;
593 ppir_instr
*target_instr
;
595 if (node
->op
== ppir_op_discard
) {
596 ppir_codegen_encode_discard(node
, code
);
600 assert(node
->op
== ppir_op_branch
);
601 branch
= ppir_node_to_branch(node
);
603 b
->branch
.unknown_0
= 0x0;
604 b
->branch
.unknown_1
= 0x0;
606 if (branch
->num_src
== 2) {
607 b
->branch
.arg0_source
= get_scl_reg_index(&branch
->src
[0], 0);
608 b
->branch
.arg1_source
= get_scl_reg_index(&branch
->src
[1], 0);
609 b
->branch
.cond_gt
= branch
->cond_gt
;
610 b
->branch
.cond_eq
= branch
->cond_eq
;
611 b
->branch
.cond_lt
= branch
->cond_lt
;
612 } else if (branch
->num_src
== 0) {
613 /* Unconditional branch */
614 b
->branch
.arg0_source
= 0;
615 b
->branch
.arg1_source
= 0;
616 b
->branch
.cond_gt
= true;
617 b
->branch
.cond_eq
= true;
618 b
->branch
.cond_lt
= true;
623 target
= branch
->target
;
624 while (list_is_empty(&target
->instr_list
)) {
625 if (!target
->list
.next
)
627 target
= LIST_ENTRY(ppir_block
, target
->list
.next
, list
);
630 assert(!list_is_empty(&target
->instr_list
));
632 target_instr
= list_first_entry(&target
->instr_list
, ppir_instr
, list
);
633 b
->branch
.target
= target_instr
->offset
- node
->instr
->offset
;
634 b
->branch
.next_count
= target_instr
->encode_size
;
637 typedef void (*ppir_codegen_instr_slot_encode_func
)(ppir_node
*, void *);
639 static const ppir_codegen_instr_slot_encode_func
640 ppir_codegen_encode_slot
[PPIR_INSTR_SLOT_NUM
] = {
641 [PPIR_INSTR_SLOT_VARYING
] = ppir_codegen_encode_varying
,
642 [PPIR_INSTR_SLOT_TEXLD
] = ppir_codegen_encode_texld
,
643 [PPIR_INSTR_SLOT_UNIFORM
] = ppir_codegen_encode_uniform
,
644 [PPIR_INSTR_SLOT_ALU_VEC_MUL
] = ppir_codegen_encode_vec_mul
,
645 [PPIR_INSTR_SLOT_ALU_SCL_MUL
] = ppir_codegen_encode_scl_mul
,
646 [PPIR_INSTR_SLOT_ALU_VEC_ADD
] = ppir_codegen_encode_vec_add
,
647 [PPIR_INSTR_SLOT_ALU_SCL_ADD
] = ppir_codegen_encode_scl_add
,
648 [PPIR_INSTR_SLOT_ALU_COMBINE
] = ppir_codegen_encode_combine
,
649 [PPIR_INSTR_SLOT_STORE_TEMP
] = ppir_codegen_encode_store_temp
,
650 [PPIR_INSTR_SLOT_BRANCH
] = ppir_codegen_encode_branch
,
653 static const int ppir_codegen_field_size
[] = {
654 34, 62, 41, 43, 30, 44, 31, 30, 41, 73
657 static inline int align_to_word(int size
)
659 return ((size
+ 0x1f) >> 5);
662 static int get_instr_encode_size(ppir_instr
*instr
)
666 for (int i
= 0; i
< PPIR_INSTR_SLOT_NUM
; i
++) {
668 size
+= ppir_codegen_field_size
[i
];
671 for (int i
= 0; i
< 2; i
++) {
672 if (instr
->constant
[i
].num
)
676 return align_to_word(size
) + 1;
679 static void bitcopy(void *dst
, int dst_offset
, void *src
, int src_size
)
681 int off1
= dst_offset
& 0x1f;
682 uint32_t *cpy_dst
= dst
, *cpy_src
= src
;
684 cpy_dst
+= (dst_offset
>> 5);
687 int off2
= 32 - off1
;
690 *cpy_dst
|= *cpy_src
<< off1
;
694 if (cpy_size
>= src_size
)
697 *cpy_dst
|= *cpy_src
>> off2
;
701 if (cpy_size
>= src_size
)
706 memcpy(cpy_dst
, cpy_src
, align_to_word(src_size
) * 4);
709 static int encode_instr(ppir_instr
*instr
, void *code
, void *last_code
)
712 ppir_codegen_ctrl
*ctrl
= code
;
714 for (int i
= 0; i
< PPIR_INSTR_SLOT_NUM
; i
++) {
715 if (instr
->slots
[i
]) {
716 /* max field size (73), align to dword */
717 uint8_t output
[12] = {0};
719 ppir_codegen_encode_slot
[i
](instr
->slots
[i
], output
);
720 bitcopy(ctrl
+ 1, size
, output
, ppir_codegen_field_size
[i
]);
722 size
+= ppir_codegen_field_size
[i
];
723 ctrl
->fields
|= 1 << i
;
727 if (instr
->slots
[PPIR_INSTR_SLOT_TEXLD
])
730 if (instr
->slots
[PPIR_INSTR_SLOT_ALU_VEC_ADD
]) {
731 ppir_node
*node
= instr
->slots
[PPIR_INSTR_SLOT_ALU_VEC_ADD
];
732 if (node
->op
== ppir_op_ddx
|| node
->op
== ppir_op_ddy
)
736 if (instr
->slots
[PPIR_INSTR_SLOT_ALU_SCL_ADD
]) {
737 ppir_node
*node
= instr
->slots
[PPIR_INSTR_SLOT_ALU_SCL_ADD
];
738 if (node
->op
== ppir_op_ddx
|| node
->op
== ppir_op_ddy
)
742 for (int i
= 0; i
< 2; i
++) {
743 if (instr
->constant
[i
].num
) {
744 uint16_t output
[4] = {0};
746 ppir_codegen_encode_const(instr
->constant
+ i
, output
);
747 bitcopy(ctrl
+ 1, size
, output
, instr
->constant
[i
].num
* 16);
750 ctrl
->fields
|= 1 << (ppir_codegen_field_shift_vec4_const_0
+ i
);
754 size
= align_to_word(size
) + 1;
761 ppir_codegen_ctrl
*last_ctrl
= last_code
;
762 last_ctrl
->next_count
= size
;
763 last_ctrl
->prefetch
= true;
769 static void ppir_codegen_print_prog(ppir_compiler
*comp
)
771 uint32_t *prog
= comp
->prog
->shader
;
774 printf("========ppir codegen========\n");
775 list_for_each_entry(ppir_block
, block
, &comp
->block_list
, list
) {
776 list_for_each_entry(ppir_instr
, instr
, &block
->instr_list
, list
) {
777 printf("%03d (@%6d): ", instr
->index
, instr
->offset
);
778 int n
= prog
[0] & 0x1f;
779 for (int i
= 0; i
< n
; i
++) {
782 printf("%08x ", prog
[i
]);
785 ppir_disassemble_instr(prog
, offset
);
790 printf("-----------------------\n");
793 bool ppir_codegen_prog(ppir_compiler
*comp
)
796 list_for_each_entry(ppir_block
, block
, &comp
->block_list
, list
) {
797 list_for_each_entry(ppir_instr
, instr
, &block
->instr_list
, list
) {
798 instr
->offset
= size
;
799 instr
->encode_size
= get_instr_encode_size(instr
);
800 size
+= instr
->encode_size
;
804 uint32_t *prog
= rzalloc_size(comp
->prog
, size
* sizeof(uint32_t));
808 uint32_t *code
= prog
, *last_code
= NULL
;
809 list_for_each_entry(ppir_block
, block
, &comp
->block_list
, list
) {
810 list_for_each_entry(ppir_instr
, instr
, &block
->instr_list
, list
) {
811 int offset
= encode_instr(instr
, code
, last_code
);
817 comp
->prog
->shader
= prog
;
818 comp
->prog
->shader_size
= size
* sizeof(uint32_t);
820 if (lima_debug
& LIMA_DEBUG_PP
)
821 ppir_codegen_print_prog(comp
);