Path: blob/21.2-virgl/src/gallium/drivers/r300/compiler/r300_fragprog.c
4574 views
/*1* Copyright (C) 2005 Ben Skeggs.2*3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining6* a copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sublicense, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial15* portions of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,18* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.20* IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE21* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION22* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION23* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25*/2627#include "r300_fragprog.h"2829#include <stdio.h>3031#include "r300_reg.h"3233static void presub_string(char out[10], unsigned int inst)34{35switch(inst & 0x600000){36case R300_ALU_SRCP_1_MINUS_2_SRC0:37sprintf(out, "bias");38break;39case R300_ALU_SRCP_SRC1_MINUS_SRC0:40sprintf(out, "sub");41break;42case R300_ALU_SRCP_SRC1_PLUS_SRC0:43sprintf(out, "add");44break;45case R300_ALU_SRCP_1_MINUS_SRC0:46sprintf(out, "inv ");47break;48}49}5051static int get_msb(unsigned int bit, unsigned int r400_ext_addr)52{53return (r400_ext_addr & bit) ? 1 << 5 : 0;54}5556/* just some random things... */57void r300FragmentProgramDump(struct radeon_compiler *c, void *user)58{59struct r300_fragment_program_compiler *compiler = (struct r300_fragment_program_compiler*)c;60struct r300_fragment_program_code *code = &compiler->code->code.r300;61int n, i, j;62static int pc = 0;6364fprintf(stderr, "pc=%d*************************************\n", pc++);6566fprintf(stderr, "Hardware program\n");67fprintf(stderr, "----------------\n");68if (c->is_r400) {69fprintf(stderr, "code_offset_ext: %08x\n", code->r400_code_offset_ext);70}7172for (n = 0; n <= (code->config & 3); n++) {73uint32_t code_addr = code->code_addr[3 - (code->config & 3) + n];74unsigned int alu_offset = ((code_addr & R300_ALU_START_MASK) >> R300_ALU_START_SHIFT) +75(((code->r400_code_offset_ext >> (24 - (n * 6))) & 0x7) << 6);76unsigned int alu_end = ((code_addr & R300_ALU_SIZE_MASK) >> R300_ALU_SIZE_SHIFT) +77(((code->r400_code_offset_ext >> (27 - (n * 6))) & 0x7) << 6);78int tex_offset = (code_addr & R300_TEX_START_MASK) >> R300_TEX_START_SHIFT;79int tex_end = (code_addr & R300_TEX_SIZE_MASK) >> R300_TEX_SIZE_SHIFT;8081fprintf(stderr, "NODE %d: alu_offset: %u, tex_offset: %d, "82"alu_end: %u, tex_end: %d (code_addr: %08x)\n", n,83alu_offset, tex_offset, alu_end, tex_end, code_addr);8485if (n > 0 || (code->config & R300_PFS_CNTL_FIRST_NODE_HAS_TEX)) {86fprintf(stderr, " TEX:\n");87for (i = tex_offset;88i <= tex_offset + tex_end;89++i) {90const char *instr;9192switch ((code->tex.93inst[i] >> R300_TEX_INST_SHIFT) &9415) {95case R300_TEX_OP_LD:96instr = "TEX";97break;98case R300_TEX_OP_KIL:99instr = "KIL";100break;101case R300_TEX_OP_TXP:102instr = "TXP";103break;104case R300_TEX_OP_TXB:105instr = "TXB";106break;107default:108instr = "UNKNOWN";109}110111fprintf(stderr,112" %s t%i, %c%i, texture[%i] (%08x)\n",113instr,114(code->tex.115inst[i] >> R300_DST_ADDR_SHIFT) & 31,116't',117(code->tex.118inst[i] >> R300_SRC_ADDR_SHIFT) & 31,119(code->tex.120inst[i] & R300_TEX_ID_MASK) >>121R300_TEX_ID_SHIFT,122code->tex.inst[i]);123}124}125126for (i = alu_offset;127i <= alu_offset + alu_end; ++i) {128char srcc[4][10], dstc[20];129char srca[4][10], dsta[20];130char argc[3][20];131char arga[3][20];132char flags[5], tmp[10];133134for (j = 0; j < 3; ++j) {135int regc = code->alu.inst[i].rgb_addr >> (j * 6);136int rega = code->alu.inst[i].alpha_addr >> (j * 6);137int msbc = get_msb(R400_ADDR_EXT_RGB_MSB_BIT(j),138code->alu.inst[i].r400_ext_addr);139int msba = get_msb(R400_ADDR_EXT_A_MSB_BIT(j),140code->alu.inst[i].r400_ext_addr);141142sprintf(srcc[j], "%c%i",143(regc & 32) ? 'c' : 't', (regc & 31) | msbc);144sprintf(srca[j], "%c%i",145(rega & 32) ? 'c' : 't', (rega & 31) | msba);146}147148dstc[0] = 0;149sprintf(flags, "%s%s%s",150(code->alu.inst[i].151rgb_addr & R300_ALU_DSTC_REG_X) ? "x" : "",152(code->alu.inst[i].153rgb_addr & R300_ALU_DSTC_REG_Y) ? "y" : "",154(code->alu.inst[i].155rgb_addr & R300_ALU_DSTC_REG_Z) ? "z" : "");156if (flags[0] != 0) {157unsigned int msb = get_msb(158R400_ADDRD_EXT_RGB_MSB_BIT,159code->alu.inst[i].r400_ext_addr);160161sprintf(dstc, "t%i.%s ",162((code->alu.inst[i].163rgb_addr >> R300_ALU_DSTC_SHIFT)164& 31) | msb,165flags);166}167sprintf(flags, "%s%s%s",168(code->alu.inst[i].169rgb_addr & R300_ALU_DSTC_OUTPUT_X) ? "x" : "",170(code->alu.inst[i].171rgb_addr & R300_ALU_DSTC_OUTPUT_Y) ? "y" : "",172(code->alu.inst[i].173rgb_addr & R300_ALU_DSTC_OUTPUT_Z) ? "z" : "");174if (flags[0] != 0) {175sprintf(tmp, "o%i.%s",176(code->alu.inst[i].177rgb_addr >> 29) & 3,178flags);179strcat(dstc, tmp);180}181/* Presub */182presub_string(srcc[3], code->alu.inst[i].rgb_inst);183presub_string(srca[3], code->alu.inst[i].alpha_inst);184185dsta[0] = 0;186if (code->alu.inst[i].alpha_addr & R300_ALU_DSTA_REG) {187unsigned int msb = get_msb(188R400_ADDRD_EXT_A_MSB_BIT,189code->alu.inst[i].r400_ext_addr);190sprintf(dsta, "t%i.w ",191((code->alu.inst[i].192alpha_addr >> R300_ALU_DSTA_SHIFT) & 31)193| msb);194}195if (code->alu.inst[i].alpha_addr & R300_ALU_DSTA_OUTPUT) {196sprintf(tmp, "o%i.w ",197(code->alu.inst[i].198alpha_addr >> 25) & 3);199strcat(dsta, tmp);200}201if (code->alu.inst[i].alpha_addr & R300_ALU_DSTA_DEPTH) {202strcat(dsta, "Z");203}204205fprintf(stderr,206"%3i: xyz: %3s %3s %3s %5s-> %-20s (%08x)\n"207" w: %3s %3s %3s %5s-> %-20s (%08x)\n", i,208srcc[0], srcc[1], srcc[2], srcc[3], dstc,209code->alu.inst[i].rgb_addr, srca[0], srca[1],210srca[2], srca[3], dsta,211code->alu.inst[i].alpha_addr);212213for (j = 0; j < 3; ++j) {214int regc = code->alu.inst[i].rgb_inst >> (j * 7);215int rega = code->alu.inst[i].alpha_inst >> (j * 7);216int d;217char buf[20];218219d = regc & 31;220if (d < 12) {221switch (d % 4) {222case R300_ALU_ARGC_SRC0C_XYZ:223sprintf(buf, "%s.xyz",224srcc[d / 4]);225break;226case R300_ALU_ARGC_SRC0C_XXX:227sprintf(buf, "%s.xxx",228srcc[d / 4]);229break;230case R300_ALU_ARGC_SRC0C_YYY:231sprintf(buf, "%s.yyy",232srcc[d / 4]);233break;234case R300_ALU_ARGC_SRC0C_ZZZ:235sprintf(buf, "%s.zzz",236srcc[d / 4]);237break;238}239} else if (d < 15) {240sprintf(buf, "%s.www", srca[d - 12]);241} else if (d < 20 ) {242switch(d) {243case R300_ALU_ARGC_SRCP_XYZ:244sprintf(buf, "srcp.xyz");245break;246case R300_ALU_ARGC_SRCP_XXX:247sprintf(buf, "srcp.xxx");248break;249case R300_ALU_ARGC_SRCP_YYY:250sprintf(buf, "srcp.yyy");251break;252case R300_ALU_ARGC_SRCP_ZZZ:253sprintf(buf, "srcp.zzz");254break;255case R300_ALU_ARGC_SRCP_WWW:256sprintf(buf, "srcp.www");257break;258}259} else if (d == 20) {260sprintf(buf, "0.0");261} else if (d == 21) {262sprintf(buf, "1.0");263} else if (d == 22) {264sprintf(buf, "0.5");265} else if (d >= 23 && d < 32) {266d -= 23;267switch (d / 3) {268case 0:269sprintf(buf, "%s.yzx",270srcc[d % 3]);271break;272case 1:273sprintf(buf, "%s.zxy",274srcc[d % 3]);275break;276case 2:277sprintf(buf, "%s.Wzy",278srcc[d % 3]);279break;280}281} else {282sprintf(buf, "%i", d);283}284285sprintf(argc[j], "%s%s%s%s",286(regc & 32) ? "-" : "",287(regc & 64) ? "|" : "",288buf, (regc & 64) ? "|" : "");289290d = rega & 31;291if (d < 9) {292sprintf(buf, "%s.%c", srcc[d / 3],293'x' + (char)(d % 3));294} else if (d < 12) {295sprintf(buf, "%s.w", srca[d - 9]);296} else if (d < 16) {297switch(d) {298case R300_ALU_ARGA_SRCP_X:299sprintf(buf, "srcp.x");300break;301case R300_ALU_ARGA_SRCP_Y:302sprintf(buf, "srcp.y");303break;304case R300_ALU_ARGA_SRCP_Z:305sprintf(buf, "srcp.z");306break;307case R300_ALU_ARGA_SRCP_W:308sprintf(buf, "srcp.w");309break;310}311} else if (d == 16) {312sprintf(buf, "0.0");313} else if (d == 17) {314sprintf(buf, "1.0");315} else if (d == 18) {316sprintf(buf, "0.5");317} else {318sprintf(buf, "%i", d);319}320321sprintf(arga[j], "%s%s%s%s",322(rega & 32) ? "-" : "",323(rega & 64) ? "|" : "",324buf, (rega & 64) ? "|" : "");325}326327fprintf(stderr, " xyz: %8s %8s %8s op: %08x %s\n"328" w: %8s %8s %8s op: %08x\n",329argc[0], argc[1], argc[2],330code->alu.inst[i].rgb_inst,331code->alu.inst[i].rgb_inst & R300_ALU_INSERT_NOP ?332"NOP" : "",333arga[0], arga[1],arga[2],334code->alu.inst[i].alpha_inst);335}336}337}338339340