/** * Compile the shader. */ static bool gs_compile(struct gs_compile_context *gcc) { struct toy_compiler *tc = &gcc->tc; struct ilo_shader *sh = gcc->shader; get_num_prims_static(gcc); if (gcc->is_static) { tc_head(tc); gs_init_vars(gcc); gs_ff_sync(gcc, tdst_d(gcc->vars.tmp), tsrc_imm_d(gcc->static_data.total_prims)); gs_COPY1(tc, gcc->vars.urb_write_header, 0, tsrc_from(tdst_d(gcc->vars.tmp)), 0); if (gcc->write_so) gs_COPY4(tc, gcc->vars.so_index, 0, tsrc_from(tdst_d(gcc->vars.tmp)), 1); tc_tail(tc); } else { tc_fail(tc, "no control flow support"); return false; } if (!gcc->write_vue) gs_discard(gcc); gs_lower_virtual_opcodes(gcc); toy_compiler_legalize_for_ra(tc); toy_compiler_optimize(tc); toy_compiler_allocate_registers(tc, gcc->first_free_grf, gcc->last_free_grf, 1); toy_compiler_legalize_for_asm(tc); if (tc->fail) { ilo_err("failed to legalize GS instructions: %s\n", tc->reason); return false; } if (ilo_debug & ILO_DEBUG_GS) { ilo_printf("legalized instructions:\n"); toy_compiler_dump(tc); ilo_printf("\n"); } sh->kernel = toy_compiler_assemble(tc, &sh->kernel_size); if (!sh->kernel) return false; if (ilo_debug & ILO_DEBUG_GS) { ilo_printf("disassembly:\n"); toy_compiler_disassemble(tc->dev, sh->kernel, sh->kernel_size, false); ilo_printf("\n"); } return true; }
static void writer_decode_kernel(const struct ilo_builder *builder, enum ilo_builder_writer_type which, const struct ilo_builder_item *item) { const void *kernel; ilo_printf("0x%08x:\n", item->offset); kernel = (const void *) writer_pointer(builder, which, item->offset); toy_compiler_disassemble(builder->dev, kernel, item->size, true); }
static bool gs_compile_passthrough(struct gs_compile_context *gcc) { struct toy_compiler *tc = &gcc->tc; struct ilo_shader *sh = gcc->shader; gcc->is_static = true; gcc->static_data.total_vertices = gcc->in_vue_count; gcc->static_data.total_prims = 1; gcc->static_data.last_vertex[0] = 1 << (gcc->in_vue_count - 1); gs_init_vars(gcc); gs_ff_sync(gcc, tdst_d(gcc->vars.tmp), tsrc_imm_d(gcc->static_data.total_prims)); gs_COPY1(tc, gcc->vars.urb_write_header, 0, tsrc_from(tdst_d(gcc->vars.tmp)), 0); if (gcc->write_so) gs_COPY4(tc, gcc->vars.so_index, 0, tsrc_from(tdst_d(gcc->vars.tmp)), 1); { int vert, attr; for (vert = 0; vert < gcc->out_vue_min_count; vert++) { for (attr = 0; attr < gcc->shader->out.count; attr++) { tc_MOV(tc, tdst_from(gcc->vars.tgsi_outs[attr]), tsrc_offset(gcc->payload.vues[vert], attr / 2, (attr % 2) * 4)); } gs_lower_opcode_emit(gcc, NULL); } gs_lower_opcode_endprim(gcc, NULL); } if (!gcc->write_vue) gs_discard(gcc); gs_lower_virtual_opcodes(gcc); toy_compiler_legalize_for_ra(tc); toy_compiler_optimize(tc); toy_compiler_allocate_registers(tc, gcc->first_free_grf, gcc->last_free_grf, 1); toy_compiler_legalize_for_asm(tc); if (tc->fail) { ilo_err("failed to translate GS TGSI tokens: %s\n", tc->reason); return false; } if (ilo_debug & ILO_DEBUG_GS) { int i; ilo_printf("VUE count %d, VUE size %d\n", gcc->in_vue_count, gcc->in_vue_size); ilo_printf("%srasterizer discard\n", (gcc->variant->u.gs.rasterizer_discard) ? "" : "no "); for (i = 0; i < gcc->so_info->num_outputs; i++) { ilo_printf("SO[%d] = OUT[%d]\n", i, gcc->so_info->output[i].register_index); } ilo_printf("legalized instructions:\n"); toy_compiler_dump(tc); ilo_printf("\n"); } sh->kernel = toy_compiler_assemble(tc, &sh->kernel_size); if (!sh->kernel) { ilo_err("failed to compile GS: %s\n", tc->reason); return false; } if (ilo_debug & ILO_DEBUG_GS) { ilo_printf("disassembly:\n"); toy_compiler_disassemble(tc->dev, sh->kernel, sh->kernel_size, false); ilo_printf("\n"); } return true; }
/** * Compile the shader. */ static bool vs_compile(struct vs_compile_context *vcc) { struct toy_compiler *tc = &vcc->tc; struct ilo_shader *sh = vcc->shader; vs_lower_virtual_opcodes(vcc); toy_compiler_legalize_for_ra(tc); toy_compiler_optimize(tc); toy_compiler_allocate_registers(tc, vcc->first_free_grf, vcc->last_free_grf, vcc->num_grf_per_vrf); toy_compiler_legalize_for_asm(tc); if (tc->fail) { ilo_err("failed to legalize VS instructions: %s\n", tc->reason); return false; } if (ilo_debug & ILO_DEBUG_VS) { ilo_printf("legalized instructions:\n"); toy_compiler_dump(tc); ilo_printf("\n"); } if (true) { sh->kernel = toy_compiler_assemble(tc, &sh->kernel_size); } else { static const uint32_t microcode[] = { /* fill in the microcode here */ 0x0, 0x0, 0x0, 0x0, }; const bool swap = true; sh->kernel_size = sizeof(microcode); sh->kernel = MALLOC(sh->kernel_size); if (sh->kernel) { const int num_dwords = sizeof(microcode) / 4; const uint32_t *src = microcode; uint32_t *dst = (uint32_t *) sh->kernel; int i; for (i = 0; i < num_dwords; i += 4) { if (swap) { dst[i + 0] = src[i + 3]; dst[i + 1] = src[i + 2]; dst[i + 2] = src[i + 1]; dst[i + 3] = src[i + 0]; } else { memcpy(dst, src, 16); } } } } if (!sh->kernel) { ilo_err("failed to compile VS: %s\n", tc->reason); return false; } if (ilo_debug & ILO_DEBUG_VS) { ilo_printf("disassembly:\n"); toy_compiler_disassemble(tc->dev, sh->kernel, sh->kernel_size, false); ilo_printf("\n"); } return true; }