Path: blob/21.2-virgl/src/gallium/drivers/lima/ir/pp/codegen.c
4574 views
/*1* Copyright (c) 2017 Lima Project2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sub license,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the11* next paragraph) shall be included in all copies or substantial portions12* of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER20* DEALINGS IN THE SOFTWARE.21*22*/2324#include "util/ralloc.h"25#include "util/half_float.h"26#include "util/bitscan.h"2728#include "ppir.h"29#include "codegen.h"30#include "lima_context.h"3132static unsigned encode_swizzle(uint8_t *swizzle, int shift, int dest_shift)33{34unsigned ret = 0;35for (int i = 0; i < 4; i++)36ret |= ((swizzle[i] + shift) & 0x3) << ((i + dest_shift) * 2);37return ret;38}3940static int get_scl_reg_index(ppir_src *src, int component)41{42int ret = ppir_target_get_src_reg_index(src);43ret += src->swizzle[component];44return ret;45}4647static void ppir_codegen_encode_varying(ppir_node *node, void *code)48{49ppir_codegen_field_varying *f = code;50ppir_load_node *load = ppir_node_to_load(node);51ppir_dest *dest = &load->dest;52int index = ppir_target_get_dest_reg_index(dest);53int num_components = load->num_components;5455if (node->op != ppir_op_load_coords_reg) {56assert(node->op == ppir_op_load_varying ||57node->op == ppir_op_load_coords ||58node->op == ppir_op_load_fragcoord ||59node->op == ppir_op_load_pointcoord ||60node->op == ppir_op_load_frontface);6162f->imm.dest = index >> 2;63f->imm.mask = dest->write_mask << (index & 0x3);6465int alignment = num_components == 3 ? 3 : num_components - 1;66f->imm.alignment = alignment;6768if (load->num_src) {69index = ppir_target_get_src_reg_index(&load->src);70f->imm.offset_vector = index >> 2;71f->imm.offset_scalar = index & 0x3;72} else73f->imm.offset_vector = 0xf;7475if (alignment == 3)76f->imm.index = load->index >> 2;77else78f->imm.index = load->index >> alignment;7980switch (node->op) {81case ppir_op_load_fragcoord:82f->imm.source_type = 2;83f->imm.perspective = 3;84break;85case ppir_op_load_pointcoord:86f->imm.source_type = 3;87break;88case ppir_op_load_frontface:89f->imm.source_type = 3;90f->imm.perspective = 1;91break;92case ppir_op_load_coords:93/* num_components == 3 implies cubemap as we don't support 3D textures */94f->imm.source_type = num_components == 3 ? 2 : 0;95break;96default:97break;98}99}100else { /* node->op == ppir_op_load_coords_reg */101f->reg.dest = index >> 2;102f->reg.mask = dest->write_mask << (index & 0x3);103104if (load->num_src) {105/* num_components == 3 implies cubemap as we don't support 3D textures */106if (num_components == 3) {107f->reg.source_type = 2;108f->reg.perspective = 1;109} else {110f->reg.source_type = 1;111}112ppir_src *src = &load->src;113index = ppir_target_get_src_reg_index(src);114f->reg.source = index >> 2;115f->reg.negate = src->negate;116f->reg.absolute = src->absolute;117f->reg.swizzle = encode_swizzle(src->swizzle, index & 0x3, 0);118}119}120}121122static void ppir_codegen_encode_texld(ppir_node *node, void *code)123{124ppir_codegen_field_sampler *f = code;125ppir_load_texture_node *ldtex = ppir_node_to_load_texture(node);126127f->index = ldtex->sampler;128129f->lod_bias_en = ldtex->lod_bias_en;130f->explicit_lod = ldtex->explicit_lod;131if (ldtex->lod_bias_en)132f->lod_bias = ppir_target_get_src_reg_index(&ldtex->src[1]);133134switch (ldtex->sampler_dim) {135case GLSL_SAMPLER_DIM_2D:136case GLSL_SAMPLER_DIM_RECT:137case GLSL_SAMPLER_DIM_EXTERNAL:138f->type = ppir_codegen_sampler_type_2d;139break;140case GLSL_SAMPLER_DIM_CUBE:141f->type = ppir_codegen_sampler_type_cube;142break;143default:144break;145}146147f->offset_en = 0;148f->unknown_2 = 0x39001;149}150151static void ppir_codegen_encode_uniform(ppir_node *node, void *code)152{153ppir_codegen_field_uniform *f = code;154ppir_load_node *load = ppir_node_to_load(node);155156switch (node->op) {157case ppir_op_load_uniform:158f->source = ppir_codegen_uniform_src_uniform;159break;160case ppir_op_load_temp:161f->source = ppir_codegen_uniform_src_temporary;162break;163default:164assert(0);165}166167/* Uniforms are always aligned to vec4 boundary */168f->alignment = 2;169f->index = load->index;170171if (load->num_src) {172f->offset_en = 1;173f->offset_reg = ppir_target_get_src_reg_index(&load->src);174}175}176177static unsigned shift_to_op(int shift)178{179assert(shift >= -3 && shift <= 3);180return shift < 0 ? shift + 8 : shift;181}182183static void ppir_codegen_encode_vec_mul(ppir_node *node, void *code)184{185ppir_codegen_field_vec4_mul *f = code;186ppir_alu_node *alu = ppir_node_to_alu(node);187188ppir_dest *dest = &alu->dest;189int dest_shift = 0;190if (dest->type != ppir_target_pipeline) {191int index = ppir_target_get_dest_reg_index(dest);192dest_shift = index & 0x3;193f->dest = index >> 2;194f->mask = dest->write_mask << dest_shift;195}196f->dest_modifier = dest->modifier;197198switch (node->op) {199case ppir_op_mul:200f->op = shift_to_op(alu->shift);201break;202case ppir_op_mov:203f->op = ppir_codegen_vec4_mul_op_mov;204break;205case ppir_op_max:206f->op = ppir_codegen_vec4_mul_op_max;207break;208case ppir_op_min:209f->op = ppir_codegen_vec4_mul_op_min;210break;211case ppir_op_and:212f->op = ppir_codegen_vec4_mul_op_and;213break;214case ppir_op_or:215f->op = ppir_codegen_vec4_mul_op_or;216break;217case ppir_op_xor:218f->op = ppir_codegen_vec4_mul_op_xor;219break;220case ppir_op_gt:221f->op = ppir_codegen_vec4_mul_op_gt;222break;223case ppir_op_ge:224f->op = ppir_codegen_vec4_mul_op_ge;225break;226case ppir_op_eq:227f->op = ppir_codegen_vec4_mul_op_eq;228break;229case ppir_op_ne:230f->op = ppir_codegen_vec4_mul_op_ne;231break;232case ppir_op_not:233f->op = ppir_codegen_vec4_mul_op_not;234break;235default:236break;237}238239ppir_src *src = alu->src;240int index = ppir_target_get_src_reg_index(src);241f->arg0_source = index >> 2;242f->arg0_swizzle = encode_swizzle(src->swizzle, index & 0x3, dest_shift);243f->arg0_absolute = src->absolute;244f->arg0_negate = src->negate;245246if (alu->num_src == 2) {247src = alu->src + 1;248index = ppir_target_get_src_reg_index(src);249f->arg1_source = index >> 2;250f->arg1_swizzle = encode_swizzle(src->swizzle, index & 0x3, dest_shift);251f->arg1_absolute = src->absolute;252f->arg1_negate = src->negate;253}254}255256static void ppir_codegen_encode_scl_mul(ppir_node *node, void *code)257{258ppir_codegen_field_float_mul *f = code;259ppir_alu_node *alu = ppir_node_to_alu(node);260261ppir_dest *dest = &alu->dest;262int dest_component = ffs(dest->write_mask) - 1;263assert(dest_component >= 0);264265if (dest->type != ppir_target_pipeline) {266f->dest = ppir_target_get_dest_reg_index(dest) + dest_component;267f->output_en = true;268}269f->dest_modifier = dest->modifier;270271switch (node->op) {272case ppir_op_mul:273f->op = shift_to_op(alu->shift);274break;275case ppir_op_mov:276f->op = ppir_codegen_float_mul_op_mov;277break;278case ppir_op_max:279f->op = ppir_codegen_float_mul_op_max;280break;281case ppir_op_min:282f->op = ppir_codegen_float_mul_op_min;283break;284case ppir_op_and:285f->op = ppir_codegen_float_mul_op_and;286break;287case ppir_op_or:288f->op = ppir_codegen_float_mul_op_or;289break;290case ppir_op_xor:291f->op = ppir_codegen_float_mul_op_xor;292break;293case ppir_op_gt:294f->op = ppir_codegen_float_mul_op_gt;295break;296case ppir_op_ge:297f->op = ppir_codegen_float_mul_op_ge;298break;299case ppir_op_eq:300f->op = ppir_codegen_float_mul_op_eq;301break;302case ppir_op_ne:303f->op = ppir_codegen_float_mul_op_ne;304break;305case ppir_op_not:306f->op = ppir_codegen_float_mul_op_not;307break;308default:309break;310}311312ppir_src *src = alu->src;313f->arg0_source = get_scl_reg_index(src, dest_component);314f->arg0_absolute = src->absolute;315f->arg0_negate = src->negate;316317if (alu->num_src == 2) {318src = alu->src + 1;319f->arg1_source = get_scl_reg_index(src, dest_component);320f->arg1_absolute = src->absolute;321f->arg1_negate = src->negate;322}323}324325static void ppir_codegen_encode_vec_add(ppir_node *node, void *code)326{327ppir_codegen_field_vec4_acc *f = code;328ppir_alu_node *alu = ppir_node_to_alu(node);329330ppir_dest *dest = &alu->dest;331int index = ppir_target_get_dest_reg_index(dest);332int dest_shift = index & 0x3;333f->dest = index >> 2;334f->mask = dest->write_mask << dest_shift;335f->dest_modifier = dest->modifier;336337switch (node->op) {338case ppir_op_add:339f->op = ppir_codegen_vec4_acc_op_add;340break;341case ppir_op_mov:342f->op = ppir_codegen_vec4_acc_op_mov;343break;344case ppir_op_sum3:345f->op = ppir_codegen_vec4_acc_op_sum3;346dest_shift = 0;347break;348case ppir_op_sum4:349f->op = ppir_codegen_vec4_acc_op_sum4;350dest_shift = 0;351break;352case ppir_op_floor:353f->op = ppir_codegen_vec4_acc_op_floor;354break;355case ppir_op_ceil:356f->op = ppir_codegen_vec4_acc_op_ceil;357break;358case ppir_op_fract:359f->op = ppir_codegen_vec4_acc_op_fract;360break;361case ppir_op_gt:362f->op = ppir_codegen_vec4_acc_op_gt;363break;364case ppir_op_ge:365f->op = ppir_codegen_vec4_acc_op_ge;366break;367case ppir_op_eq:368f->op = ppir_codegen_vec4_acc_op_eq;369break;370case ppir_op_ne:371f->op = ppir_codegen_vec4_acc_op_ne;372break;373case ppir_op_select:374f->op = ppir_codegen_vec4_acc_op_sel;375break;376case ppir_op_max:377f->op = ppir_codegen_vec4_acc_op_max;378break;379case ppir_op_min:380f->op = ppir_codegen_vec4_acc_op_min;381break;382case ppir_op_ddx:383f->op = ppir_codegen_vec4_acc_op_dFdx;384break;385case ppir_op_ddy:386f->op = ppir_codegen_vec4_acc_op_dFdy;387break;388default:389break;390}391392ppir_src *src = node->op == ppir_op_select ? alu->src + 1 : alu->src;393index = ppir_target_get_src_reg_index(src);394395if (src->type == ppir_target_pipeline &&396src->pipeline == ppir_pipeline_reg_vmul)397f->mul_in = true;398else399f->arg0_source = index >> 2;400401f->arg0_swizzle = encode_swizzle(src->swizzle, index & 0x3, dest_shift);402f->arg0_absolute = src->absolute;403f->arg0_negate = src->negate;404405if (++src < alu->src + alu->num_src) {406index = ppir_target_get_src_reg_index(src);407f->arg1_source = index >> 2;408f->arg1_swizzle = encode_swizzle(src->swizzle, index & 0x3, dest_shift);409f->arg1_absolute = src->absolute;410f->arg1_negate = src->negate;411}412}413414static void ppir_codegen_encode_scl_add(ppir_node *node, void *code)415{416ppir_codegen_field_float_acc *f = code;417ppir_alu_node *alu = ppir_node_to_alu(node);418419ppir_dest *dest = &alu->dest;420int dest_component = ffs(dest->write_mask) - 1;421assert(dest_component >= 0);422423f->dest = ppir_target_get_dest_reg_index(dest) + dest_component;424f->output_en = true;425f->dest_modifier = dest->modifier;426427switch (node->op) {428case ppir_op_add:429f->op = shift_to_op(alu->shift);430break;431case ppir_op_mov:432f->op = ppir_codegen_float_acc_op_mov;433break;434case ppir_op_max:435f->op = ppir_codegen_float_acc_op_max;436break;437case ppir_op_min:438f->op = ppir_codegen_float_acc_op_min;439break;440case ppir_op_floor:441f->op = ppir_codegen_float_acc_op_floor;442break;443case ppir_op_ceil:444f->op = ppir_codegen_float_acc_op_ceil;445break;446case ppir_op_fract:447f->op = ppir_codegen_float_acc_op_fract;448break;449case ppir_op_gt:450f->op = ppir_codegen_float_acc_op_gt;451break;452case ppir_op_ge:453f->op = ppir_codegen_float_acc_op_ge;454break;455case ppir_op_eq:456f->op = ppir_codegen_float_acc_op_eq;457break;458case ppir_op_ne:459f->op = ppir_codegen_float_acc_op_ne;460break;461case ppir_op_select:462f->op = ppir_codegen_float_acc_op_sel;463break;464case ppir_op_ddx:465f->op = ppir_codegen_float_acc_op_dFdx;466break;467case ppir_op_ddy:468f->op = ppir_codegen_float_acc_op_dFdy;469break;470default:471break;472}473474ppir_src *src = node->op == ppir_op_select ? alu->src + 1: alu->src;475if (src->type == ppir_target_pipeline &&476src->pipeline == ppir_pipeline_reg_fmul)477f->mul_in = true;478else479f->arg0_source = get_scl_reg_index(src, dest_component);480f->arg0_absolute = src->absolute;481f->arg0_negate = src->negate;482483if (++src < alu->src + alu->num_src) {484f->arg1_source = get_scl_reg_index(src, dest_component);485f->arg1_absolute = src->absolute;486f->arg1_negate = src->negate;487}488}489490static void ppir_codegen_encode_combine(ppir_node *node, void *code)491{492ppir_codegen_field_combine *f = code;493ppir_alu_node *alu = ppir_node_to_alu(node);494495switch (node->op) {496case ppir_op_rsqrt:497case ppir_op_log2:498case ppir_op_exp2:499case ppir_op_rcp:500case ppir_op_sqrt:501case ppir_op_sin:502case ppir_op_cos:503{504f->scalar.dest_vec = false;505f->scalar.arg1_en = false;506507ppir_dest *dest = &alu->dest;508int dest_component = ffs(dest->write_mask) - 1;509assert(dest_component >= 0);510f->scalar.dest = ppir_target_get_dest_reg_index(dest) + dest_component;511f->scalar.dest_modifier = dest->modifier;512513ppir_src *src = alu->src;514f->scalar.arg0_src = get_scl_reg_index(src, dest_component);515f->scalar.arg0_absolute = src->absolute;516f->scalar.arg0_negate = src->negate;517518switch (node->op) {519case ppir_op_rsqrt:520f->scalar.op = ppir_codegen_combine_scalar_op_rsqrt;521break;522case ppir_op_log2:523f->scalar.op = ppir_codegen_combine_scalar_op_log2;524break;525case ppir_op_exp2:526f->scalar.op = ppir_codegen_combine_scalar_op_exp2;527break;528case ppir_op_rcp:529f->scalar.op = ppir_codegen_combine_scalar_op_rcp;530break;531case ppir_op_sqrt:532f->scalar.op = ppir_codegen_combine_scalar_op_sqrt;533break;534case ppir_op_sin:535f->scalar.op = ppir_codegen_combine_scalar_op_sin;536break;537case ppir_op_cos:538f->scalar.op = ppir_codegen_combine_scalar_op_cos;539break;540default:541break;542}543break;544}545default:546break;547}548}549550static void ppir_codegen_encode_store_temp(ppir_node *node, void *code)551{552assert(node->op == ppir_op_store_temp);553554ppir_codegen_field_temp_write *f = code;555ppir_store_node *snode = ppir_node_to_store(node);556int num_components = snode->num_components;557558f->temp_write.dest = 0x03; // 11 - temporary559f->temp_write.source = snode->src.reg->index;560561int alignment = num_components == 4 ? 2 : num_components - 1;562f->temp_write.alignment = alignment;563f->temp_write.index = snode->index << (2 - alignment);564565f->temp_write.offset_reg = snode->index >> 2;566}567568static void ppir_codegen_encode_const(ppir_const *constant, uint16_t *code)569{570for (int i = 0; i < constant->num; i++)571code[i] = _mesa_float_to_half(constant->value[i].f);572}573574static void ppir_codegen_encode_discard(ppir_node *node, void *code)575{576ppir_codegen_field_branch *b = code;577assert(node->op == ppir_op_discard);578579b->discard.word0 = PPIR_CODEGEN_DISCARD_WORD0;580b->discard.word1 = PPIR_CODEGEN_DISCARD_WORD1;581b->discard.word2 = PPIR_CODEGEN_DISCARD_WORD2;582}583584static void ppir_codegen_encode_branch(ppir_node *node, void *code)585{586ppir_codegen_field_branch *b = code;587ppir_branch_node *branch;588ppir_instr *target_instr;589ppir_block *target;590if (node->op == ppir_op_discard) {591ppir_codegen_encode_discard(node, code);592return;593}594595assert(node->op == ppir_op_branch);596branch = ppir_node_to_branch(node);597598b->branch.unknown_0 = 0x0;599b->branch.unknown_1 = 0x0;600601if (branch->num_src == 2) {602b->branch.arg0_source = get_scl_reg_index(&branch->src[0], 0);603b->branch.arg1_source = get_scl_reg_index(&branch->src[1], 0);604b->branch.cond_gt = branch->cond_gt;605b->branch.cond_eq = branch->cond_eq;606b->branch.cond_lt = branch->cond_lt;607} else if (branch->num_src == 0) {608/* Unconditional branch */609b->branch.arg0_source = 0;610b->branch.arg1_source = 0;611b->branch.cond_gt = true;612b->branch.cond_eq = true;613b->branch.cond_lt = true;614} else {615assert(false);616}617618target = branch->target;619while (list_is_empty(&target->instr_list)) {620if (!target->list.next)621break;622target = LIST_ENTRY(ppir_block, target->list.next, list);623}624625assert(!list_is_empty(&target->instr_list));626627target_instr = list_first_entry(&target->instr_list, ppir_instr, list);628b->branch.target = target_instr->offset - node->instr->offset;629b->branch.next_count = target_instr->encode_size;630}631632typedef void (*ppir_codegen_instr_slot_encode_func)(ppir_node *, void *);633634static const ppir_codegen_instr_slot_encode_func635ppir_codegen_encode_slot[PPIR_INSTR_SLOT_NUM] = {636[PPIR_INSTR_SLOT_VARYING] = ppir_codegen_encode_varying,637[PPIR_INSTR_SLOT_TEXLD] = ppir_codegen_encode_texld,638[PPIR_INSTR_SLOT_UNIFORM] = ppir_codegen_encode_uniform,639[PPIR_INSTR_SLOT_ALU_VEC_MUL] = ppir_codegen_encode_vec_mul,640[PPIR_INSTR_SLOT_ALU_SCL_MUL] = ppir_codegen_encode_scl_mul,641[PPIR_INSTR_SLOT_ALU_VEC_ADD] = ppir_codegen_encode_vec_add,642[PPIR_INSTR_SLOT_ALU_SCL_ADD] = ppir_codegen_encode_scl_add,643[PPIR_INSTR_SLOT_ALU_COMBINE] = ppir_codegen_encode_combine,644[PPIR_INSTR_SLOT_STORE_TEMP] = ppir_codegen_encode_store_temp,645[PPIR_INSTR_SLOT_BRANCH] = ppir_codegen_encode_branch,646};647648static const int ppir_codegen_field_size[] = {64934, 62, 41, 43, 30, 44, 31, 30, 41, 73650};651652static inline int align_to_word(int size)653{654return ((size + 0x1f) >> 5);655}656657static int get_instr_encode_size(ppir_instr *instr)658{659int size = 0;660661for (int i = 0; i < PPIR_INSTR_SLOT_NUM; i++) {662if (instr->slots[i])663size += ppir_codegen_field_size[i];664}665666for (int i = 0; i < 2; i++) {667if (instr->constant[i].num)668size += 64;669}670671return align_to_word(size) + 1;672}673674static void bitcopy(void *dst, int dst_offset, void *src, int src_size)675{676int off1 = dst_offset & 0x1f;677uint32_t *cpy_dst = dst, *cpy_src = src;678679cpy_dst += (dst_offset >> 5);680681if (off1) {682int off2 = 32 - off1;683int cpy_size = 0;684while (1) {685*cpy_dst |= *cpy_src << off1;686cpy_dst++;687688cpy_size += off2;689if (cpy_size >= src_size)690break;691692*cpy_dst |= *cpy_src >> off2;693cpy_src++;694695cpy_size += off1;696if (cpy_size >= src_size)697break;698}699}700else701memcpy(cpy_dst, cpy_src, align_to_word(src_size) * 4);702}703704static int encode_instr(ppir_instr *instr, void *code, void *last_code)705{706int size = 0;707ppir_codegen_ctrl *ctrl = code;708709for (int i = 0; i < PPIR_INSTR_SLOT_NUM; i++) {710if (instr->slots[i]) {711/* max field size (73), align to dword */712uint8_t output[12] = {0};713714ppir_codegen_encode_slot[i](instr->slots[i], output);715bitcopy(ctrl + 1, size, output, ppir_codegen_field_size[i]);716717size += ppir_codegen_field_size[i];718ctrl->fields |= 1 << i;719}720}721722if (instr->slots[PPIR_INSTR_SLOT_TEXLD])723ctrl->sync = true;724725if (instr->slots[PPIR_INSTR_SLOT_ALU_VEC_ADD]) {726ppir_node *node = instr->slots[PPIR_INSTR_SLOT_ALU_VEC_ADD];727if (node->op == ppir_op_ddx || node->op == ppir_op_ddy)728ctrl->sync = true;729}730731if (instr->slots[PPIR_INSTR_SLOT_ALU_SCL_ADD]) {732ppir_node *node = instr->slots[PPIR_INSTR_SLOT_ALU_SCL_ADD];733if (node->op == ppir_op_ddx || node->op == ppir_op_ddy)734ctrl->sync = true;735}736737for (int i = 0; i < 2; i++) {738if (instr->constant[i].num) {739uint16_t output[4] = {0};740741ppir_codegen_encode_const(instr->constant + i, output);742bitcopy(ctrl + 1, size, output, instr->constant[i].num * 16);743744size += 64;745ctrl->fields |= 1 << (ppir_codegen_field_shift_vec4_const_0 + i);746}747}748749size = align_to_word(size) + 1;750751ctrl->count = size;752if (instr->is_end)753ctrl->stop = true;754755if (last_code) {756ppir_codegen_ctrl *last_ctrl = last_code;757last_ctrl->next_count = size;758last_ctrl->prefetch = true;759}760761return size;762}763764static void ppir_codegen_print_prog(ppir_compiler *comp)765{766uint32_t *prog = comp->prog->shader;767unsigned offset = 0;768769printf("========ppir codegen========\n");770list_for_each_entry(ppir_block, block, &comp->block_list, list) {771list_for_each_entry(ppir_instr, instr, &block->instr_list, list) {772printf("%03d (@%6d): ", instr->index, instr->offset);773int n = prog[0] & 0x1f;774for (int i = 0; i < n; i++) {775if (i && i % 6 == 0)776printf("\n ");777printf("%08x ", prog[i]);778}779printf("\n");780ppir_disassemble_instr(prog, offset);781prog += n;782offset += n;783}784}785printf("-----------------------\n");786}787788bool ppir_codegen_prog(ppir_compiler *comp)789{790int size = 0;791list_for_each_entry(ppir_block, block, &comp->block_list, list) {792list_for_each_entry(ppir_instr, instr, &block->instr_list, list) {793instr->offset = size;794instr->encode_size = get_instr_encode_size(instr);795size += instr->encode_size;796}797}798799uint32_t *prog = rzalloc_size(comp->prog, size * sizeof(uint32_t));800if (!prog)801return false;802803uint32_t *code = prog, *last_code = NULL;804list_for_each_entry(ppir_block, block, &comp->block_list, list) {805list_for_each_entry(ppir_instr, instr, &block->instr_list, list) {806int offset = encode_instr(instr, code, last_code);807last_code = code;808code += offset;809}810}811812if (comp->prog->shader)813ralloc_free(comp->prog->shader);814815comp->prog->shader = prog;816comp->prog->state.shader_size = size * sizeof(uint32_t);817818if (lima_debug & LIMA_DEBUG_PP)819ppir_codegen_print_prog(comp);820821return true;822}823824825