r300_tgsi_to_rc.c revision 2c046034dc5c95dd2fe84d0b4fd44f25235480b9
1188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle/* 2188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle * Copyright 2009 Nicolai Hähnle <nhaehnle@gmail.com> 3188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle * 4188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle * Permission is hereby granted, free of charge, to any person obtaining a 5188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle * copy of this software and associated documentation files (the "Software"), 6188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle * to deal in the Software without restriction, including without limitation 7188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle * on the rights to use, copy, modify, merge, publish, distribute, sub 8188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle * license, and/or sell copies of the Software, and to permit persons to whom 9188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle * the Software is furnished to do so, subject to the following conditions: 10188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle * 11188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle * The above copyright notice and this permission notice (including the next 12188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle * paragraph) shall be included in all copies or substantial portions of the 13188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle * Software. 14188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle * 15188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle * THE COPYRIGHT HOLDER(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 19188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle * USE OR OTHER DEALINGS IN THE SOFTWARE. */ 22188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 23188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle#include "r300_tgsi_to_rc.h" 24188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 25188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle#include "radeon_compiler.h" 26188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle#include "radeon_program.h" 27188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 28188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle#include "tgsi/tgsi_parse.h" 29188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle#include "tgsi/tgsi_scan.h" 30188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle#include "tgsi/tgsi_util.h" 31188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 32188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 33188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnlestatic unsigned translate_opcode(unsigned opcode) 34188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle{ 35188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle switch(opcode) { 36d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_ARL: return RC_OPCODE_ARL; 37d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_MOV: return RC_OPCODE_MOV; 38d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_LIT: return RC_OPCODE_LIT; 39d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_RCP: return RC_OPCODE_RCP; 40d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_RSQ: return RC_OPCODE_RSQ; 41d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_EXP: return RC_OPCODE_EXP; 42d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_LOG: return RC_OPCODE_LOG; 43d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_MUL: return RC_OPCODE_MUL; 44d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_ADD: return RC_OPCODE_ADD; 45d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_DP3: return RC_OPCODE_DP3; 46d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_DP4: return RC_OPCODE_DP4; 47d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_DST: return RC_OPCODE_DST; 48d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_MIN: return RC_OPCODE_MIN; 49d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_MAX: return RC_OPCODE_MAX; 50d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_SLT: return RC_OPCODE_SLT; 51d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_SGE: return RC_OPCODE_SGE; 52d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_MAD: return RC_OPCODE_MAD; 53d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_SUB: return RC_OPCODE_SUB; 54d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_LRP: return RC_OPCODE_LRP; 55d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_CND: return RC_OPCODE_CND; */ 56d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_CND0: return RC_OPCODE_CND0; */ 57d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_DP2A: return RC_OPCODE_DP2A; */ 58188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle /* gap */ 59d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_FRC: return RC_OPCODE_FRC; 60d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_CLAMP: return RC_OPCODE_CLAMP; */ 61d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_FLR: return RC_OPCODE_FLR; 62d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_ROUND: return RC_OPCODE_ROUND; */ 63d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_EX2: return RC_OPCODE_EX2; 64d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_LG2: return RC_OPCODE_LG2; 65d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_POW: return RC_OPCODE_POW; 66d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_XPD: return RC_OPCODE_XPD; 67188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle /* gap */ 68d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_ABS: return RC_OPCODE_ABS; 69d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_RCC: return RC_OPCODE_RCC; */ 70d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_DPH: return RC_OPCODE_DPH; 71d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_COS: return RC_OPCODE_COS; 72d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_DDX: return RC_OPCODE_DDX; 73d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_DDY: return RC_OPCODE_DDY; 74d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_KILP: return RC_OPCODE_KILP; */ 75d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_PK2H: return RC_OPCODE_PK2H; */ 76d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_PK2US: return RC_OPCODE_PK2US; */ 77d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_PK4B: return RC_OPCODE_PK4B; */ 78d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_PK4UB: return RC_OPCODE_PK4UB; */ 79d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_RFL: return RC_OPCODE_RFL; */ 80d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_SEQ: return RC_OPCODE_SEQ; 81d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_SFL: return RC_OPCODE_SFL; 82d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_SGT: return RC_OPCODE_SGT; 83d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_SIN: return RC_OPCODE_SIN; 84d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_SLE: return RC_OPCODE_SLE; 85d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_SNE: return RC_OPCODE_SNE; 86d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_STR: return RC_OPCODE_STR; */ 87d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_TEX: return RC_OPCODE_TEX; 88d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_TXD: return RC_OPCODE_TXD; 89d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_TXP: return RC_OPCODE_TXP; 90d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_UP2H: return RC_OPCODE_UP2H; */ 91d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_UP2US: return RC_OPCODE_UP2US; */ 92d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_UP4B: return RC_OPCODE_UP4B; */ 93d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_UP4UB: return RC_OPCODE_UP4UB; */ 94d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_X2D: return RC_OPCODE_X2D; */ 95d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_ARA: return RC_OPCODE_ARA; */ 96d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_ARR: return RC_OPCODE_ARR; */ 97d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_BRA: return RC_OPCODE_BRA; */ 98d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_CAL: return RC_OPCODE_CAL; */ 99d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_RET: return RC_OPCODE_RET; */ 100d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_SSG: return RC_OPCODE_SSG; */ 101d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_CMP: return RC_OPCODE_CMP; 102d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_SCS: return RC_OPCODE_SCS; 103d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_TXB: return RC_OPCODE_TXB; 104d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_NRM: return RC_OPCODE_NRM; */ 105d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_DIV: return RC_OPCODE_DIV; */ 106d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_DP2: return RC_OPCODE_DP2; */ 107d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_TXL: return RC_OPCODE_TXL; 108d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_BRK: return RC_OPCODE_BRK; */ 109b7cf887ca74561469c144f1d12227e1bcf277e7eNicolai Hähnle case TGSI_OPCODE_IF: return RC_OPCODE_IF; 110d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_LOOP: return RC_OPCODE_LOOP; */ 111d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_REP: return RC_OPCODE_REP; */ 112b7cf887ca74561469c144f1d12227e1bcf277e7eNicolai Hähnle case TGSI_OPCODE_ELSE: return RC_OPCODE_ELSE; 113b7cf887ca74561469c144f1d12227e1bcf277e7eNicolai Hähnle case TGSI_OPCODE_ENDIF: return RC_OPCODE_ENDIF; 114d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_ENDLOOP: return RC_OPCODE_ENDLOOP; */ 115d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_ENDREP: return RC_OPCODE_ENDREP; */ 116d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_PUSHA: return RC_OPCODE_PUSHA; */ 117d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_POPA: return RC_OPCODE_POPA; */ 118d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_CEIL: return RC_OPCODE_CEIL; */ 119d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_I2F: return RC_OPCODE_I2F; */ 120d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_NOT: return RC_OPCODE_NOT; */ 121d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_TRUNC: return RC_OPCODE_TRUNC; */ 122d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_SHL: return RC_OPCODE_SHL; */ 1232c046034dc5c95dd2fe84d0b4fd44f25235480b9Michal Krol /* case TGSI_OPCODE_ISHR: return RC_OPCODE_SHR; */ 124d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_AND: return RC_OPCODE_AND; */ 125d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_OR: return RC_OPCODE_OR; */ 126d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_MOD: return RC_OPCODE_MOD; */ 127d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_XOR: return RC_OPCODE_XOR; */ 128d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_SAD: return RC_OPCODE_SAD; */ 129d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_TXF: return RC_OPCODE_TXF; */ 130d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_TXQ: return RC_OPCODE_TXQ; */ 131d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_CONT: return RC_OPCODE_CONT; */ 132d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_EMIT: return RC_OPCODE_EMIT; */ 133d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_ENDPRIM: return RC_OPCODE_ENDPRIM; */ 134d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_BGNLOOP2: return RC_OPCODE_BGNLOOP2; */ 135d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_BGNSUB: return RC_OPCODE_BGNSUB; */ 136d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_ENDLOOP2: return RC_OPCODE_ENDLOOP2; */ 137d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_ENDSUB: return RC_OPCODE_ENDSUB; */ 138d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_NOP: return RC_OPCODE_NOP; 139188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle /* gap */ 140d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_NRM4: return RC_OPCODE_NRM4; */ 141d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_CALLNZ: return RC_OPCODE_CALLNZ; */ 142d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_IFC: return RC_OPCODE_IFC; */ 143d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* case TGSI_OPCODE_BREAKC: return RC_OPCODE_BREAKC; */ 144d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_OPCODE_KIL: return RC_OPCODE_KIL; 145188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle } 146188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 147188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle fprintf(stderr, "Unknown opcode: %i\n", opcode); 148d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle return RC_OPCODE_ILLEGAL_OPCODE; 149188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle} 150188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 151188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnlestatic unsigned translate_saturate(unsigned saturate) 152188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle{ 153188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle switch(saturate) { 154d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle default: 155d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle fprintf(stderr, "Unknown saturate mode: %i\n", saturate); 156d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* fall-through */ 157d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_SAT_NONE: return RC_SATURATE_NONE; 158d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_SAT_ZERO_ONE: return RC_SATURATE_ZERO_ONE; 159188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle } 160188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle} 161188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 162188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnlestatic unsigned translate_register_file(unsigned file) 163188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle{ 164188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle switch(file) { 165d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_FILE_CONSTANT: return RC_FILE_CONSTANT; 166d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_FILE_IMMEDIATE: return RC_FILE_CONSTANT; 167d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_FILE_INPUT: return RC_FILE_INPUT; 168d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_FILE_OUTPUT: return RC_FILE_OUTPUT; 169d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle default: 170d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle fprintf(stderr, "Unhandled register file: %i\n", file); 171d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle /* fall-through */ 172d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_FILE_TEMPORARY: return RC_FILE_TEMPORARY; 173d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle case TGSI_FILE_ADDRESS: return RC_FILE_ADDRESS; 174188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle } 175188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle} 176188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 177188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnlestatic int translate_register_index( 178188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle struct tgsi_to_rc * ttr, 179188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle unsigned file, 180188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle int index) 181188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle{ 182188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle if (file == TGSI_FILE_IMMEDIATE) 183188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle return ttr->immediate_offset + index; 184188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 185188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle return index; 186188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle} 187188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 188188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnlestatic void transform_dstreg( 189188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle struct tgsi_to_rc * ttr, 190d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle struct rc_dst_register * dst, 191188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle struct tgsi_full_dst_register * src) 192188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle{ 1935b0824dfe5eaf59fa87134e7482b3d147b262901Keith Whitwell dst->File = translate_register_file(src->Register.File); 1945b0824dfe5eaf59fa87134e7482b3d147b262901Keith Whitwell dst->Index = translate_register_index(ttr, src->Register.File, src->Register.Index); 1955b0824dfe5eaf59fa87134e7482b3d147b262901Keith Whitwell dst->WriteMask = src->Register.WriteMask; 1965b0824dfe5eaf59fa87134e7482b3d147b262901Keith Whitwell dst->RelAddr = src->Register.Indirect; 197188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle} 198188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 199188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnlestatic void transform_srcreg( 200188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle struct tgsi_to_rc * ttr, 201d1b4351e603522be11061522cb6b685da9ef1feeNicolai Hähnle struct rc_src_register * dst, 202188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle struct tgsi_full_src_register * src) 203188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle{ 20491a4e6d53f83c45c1da9240b6325011d96b61386Keith Whitwell dst->File = translate_register_file(src->Register.File); 20591a4e6d53f83c45c1da9240b6325011d96b61386Keith Whitwell dst->Index = translate_register_index(ttr, src->Register.File, src->Register.Index); 20691a4e6d53f83c45c1da9240b6325011d96b61386Keith Whitwell dst->RelAddr = src->Register.Indirect; 207b9cb74c7f826dfd320f5e5b54aa933898f7ddd3dKeith Whitwell dst->Swizzle = tgsi_util_get_full_src_register_swizzle(src, 0); 208b9cb74c7f826dfd320f5e5b54aa933898f7ddd3dKeith Whitwell dst->Swizzle |= tgsi_util_get_full_src_register_swizzle(src, 1) << 3; 209b9cb74c7f826dfd320f5e5b54aa933898f7ddd3dKeith Whitwell dst->Swizzle |= tgsi_util_get_full_src_register_swizzle(src, 2) << 6; 210b9cb74c7f826dfd320f5e5b54aa933898f7ddd3dKeith Whitwell dst->Swizzle |= tgsi_util_get_full_src_register_swizzle(src, 3) << 9; 21191a4e6d53f83c45c1da9240b6325011d96b61386Keith Whitwell dst->Abs = src->Register.Absolute; 21291a4e6d53f83c45c1da9240b6325011d96b61386Keith Whitwell dst->Negate = src->Register.Negate ? RC_MASK_XYZW : 0; 213188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle} 214188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 2156ba83cd63f84a4d74dd679d62662d59533fd1bdbMarek Olšákstatic void transform_texture(struct rc_instruction * dst, struct tgsi_instruction_texture src, 2166ba83cd63f84a4d74dd679d62662d59533fd1bdbMarek Olšák uint32_t *shadowSamplers) 217d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle{ 218d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle switch(src.Texture) { 219d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle case TGSI_TEXTURE_1D: 220995135479d5662d1b1970c0f233c3c3d944d8b4dNicolai Hähnle dst->U.I.TexSrcTarget = RC_TEXTURE_1D; 221d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle break; 222d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle case TGSI_TEXTURE_2D: 223995135479d5662d1b1970c0f233c3c3d944d8b4dNicolai Hähnle dst->U.I.TexSrcTarget = RC_TEXTURE_2D; 224d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle break; 225d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle case TGSI_TEXTURE_3D: 226995135479d5662d1b1970c0f233c3c3d944d8b4dNicolai Hähnle dst->U.I.TexSrcTarget = RC_TEXTURE_3D; 227d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle break; 228d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle case TGSI_TEXTURE_CUBE: 229995135479d5662d1b1970c0f233c3c3d944d8b4dNicolai Hähnle dst->U.I.TexSrcTarget = RC_TEXTURE_CUBE; 230d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle break; 231d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle case TGSI_TEXTURE_RECT: 232995135479d5662d1b1970c0f233c3c3d944d8b4dNicolai Hähnle dst->U.I.TexSrcTarget = RC_TEXTURE_RECT; 233d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle break; 234d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle case TGSI_TEXTURE_SHADOW1D: 235995135479d5662d1b1970c0f233c3c3d944d8b4dNicolai Hähnle dst->U.I.TexSrcTarget = RC_TEXTURE_1D; 236995135479d5662d1b1970c0f233c3c3d944d8b4dNicolai Hähnle dst->U.I.TexShadow = 1; 2376ba83cd63f84a4d74dd679d62662d59533fd1bdbMarek Olšák *shadowSamplers |= 1 << dst->U.I.TexSrcUnit; 238d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle break; 239d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle case TGSI_TEXTURE_SHADOW2D: 240995135479d5662d1b1970c0f233c3c3d944d8b4dNicolai Hähnle dst->U.I.TexSrcTarget = RC_TEXTURE_2D; 241995135479d5662d1b1970c0f233c3c3d944d8b4dNicolai Hähnle dst->U.I.TexShadow = 1; 2426ba83cd63f84a4d74dd679d62662d59533fd1bdbMarek Olšák *shadowSamplers |= 1 << dst->U.I.TexSrcUnit; 243d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle break; 244d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle case TGSI_TEXTURE_SHADOWRECT: 245995135479d5662d1b1970c0f233c3c3d944d8b4dNicolai Hähnle dst->U.I.TexSrcTarget = RC_TEXTURE_RECT; 246995135479d5662d1b1970c0f233c3c3d944d8b4dNicolai Hähnle dst->U.I.TexShadow = 1; 2476ba83cd63f84a4d74dd679d62662d59533fd1bdbMarek Olšák *shadowSamplers |= 1 << dst->U.I.TexSrcUnit; 248d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle break; 249d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle } 250d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle} 251d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle 252188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnlestatic void transform_instruction(struct tgsi_to_rc * ttr, struct tgsi_full_instruction * src) 253188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle{ 2541f39d59a2996e2acf6893a8dd1a0293bd8790cc2Joakim Sindholt struct rc_instruction * dst; 2551f39d59a2996e2acf6893a8dd1a0293bd8790cc2Joakim Sindholt int i; 2561f39d59a2996e2acf6893a8dd1a0293bd8790cc2Joakim Sindholt 257188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle if (src->Instruction.Opcode == TGSI_OPCODE_END) 258188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle return; 259188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 2601f39d59a2996e2acf6893a8dd1a0293bd8790cc2Joakim Sindholt dst = rc_insert_new_instruction(ttr->compiler, ttr->compiler->Program.Instructions.Prev); 261995135479d5662d1b1970c0f233c3c3d944d8b4dNicolai Hähnle dst->U.I.Opcode = translate_opcode(src->Instruction.Opcode); 262995135479d5662d1b1970c0f233c3c3d944d8b4dNicolai Hähnle dst->U.I.SaturateMode = translate_saturate(src->Instruction.Saturate); 263188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 264188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle if (src->Instruction.NumDstRegs) 2657d6c8f980d1e23ad6f557d650e89c715861a3b0cKeith Whitwell transform_dstreg(ttr, &dst->U.I.DstReg, &src->Dst[0]); 266188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 267d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle for(i = 0; i < src->Instruction.NumSrcRegs; ++i) { 26891a4e6d53f83c45c1da9240b6325011d96b61386Keith Whitwell if (src->Src[i].Register.File == TGSI_FILE_SAMPLER) 26991a4e6d53f83c45c1da9240b6325011d96b61386Keith Whitwell dst->U.I.TexSrcUnit = src->Src[i].Register.Index; 270d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle else 2717d6c8f980d1e23ad6f557d650e89c715861a3b0cKeith Whitwell transform_srcreg(ttr, &dst->U.I.SrcReg[i], &src->Src[i]); 272d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle } 273188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 274d0c398a8e2985b855f923aec3470cef8734a622aNicolai Hähnle /* Texturing. */ 27556ee132f9671f70ff2b3ee04659beac0dfc6126dKeith Whitwell if (src->Instruction.Texture) 2766ba83cd63f84a4d74dd679d62662d59533fd1bdbMarek Olšák transform_texture(dst, src->Texture, 2776ba83cd63f84a4d74dd679d62662d59533fd1bdbMarek Olšák &ttr->compiler->Program.ShadowSamplers); 278188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle} 279188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 280188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnlestatic void handle_immediate(struct tgsi_to_rc * ttr, struct tgsi_full_immediate * imm) 281188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle{ 282188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle struct rc_constant constant; 283188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle int i; 284188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 285188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle constant.Type = RC_CONSTANT_IMMEDIATE; 286188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle constant.Size = 4; 287188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle for(i = 0; i < 4; ++i) 288188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle constant.u.Immediate[i] = imm->u[i].Float; 289188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle rc_constants_add(&ttr->compiler->Program.Constants, &constant); 290188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle} 291188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 292188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnlevoid r300_tgsi_to_rc(struct tgsi_to_rc * ttr, const struct tgsi_token * tokens) 293188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle{ 294188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle struct tgsi_parse_context parser; 295188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle int i; 296188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 297188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle /* Allocate constants placeholders. 298188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle * 299188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle * Note: What if declared constants are not contiguous? */ 300188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle for(i = 0; i <= ttr->info->file_max[TGSI_FILE_CONSTANT]; ++i) { 301188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle struct rc_constant constant; 302188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle memset(&constant, 0, sizeof(constant)); 303188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle constant.Type = RC_CONSTANT_EXTERNAL; 304188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle constant.Size = 4; 305188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle constant.u.External = i; 306188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle rc_constants_add(&ttr->compiler->Program.Constants, &constant); 307188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle } 308188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 309188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle ttr->immediate_offset = ttr->compiler->Program.Constants.Count; 310188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 311188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle tgsi_parse_init(&parser, tokens); 312188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 313188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle while (!tgsi_parse_end_of_tokens(&parser)) { 314188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle tgsi_parse_token(&parser); 315188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 316188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle switch (parser.FullToken.Token.Type) { 317188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle case TGSI_TOKEN_TYPE_DECLARATION: 318188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle break; 319188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle case TGSI_TOKEN_TYPE_IMMEDIATE: 320188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle handle_immediate(ttr, &parser.FullToken.FullImmediate); 321188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle break; 322188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle case TGSI_TOKEN_TYPE_INSTRUCTION: 323188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle transform_instruction(ttr, &parser.FullToken.FullInstruction); 324188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle break; 325188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle } 326188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle } 327188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 328188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle tgsi_parse_free(&parser); 329188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 330188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle rc_calculate_inputs_outputs(ttr->compiler); 331188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle} 332188f8c679254f193cdcfcd4ef338f3c8c5e1146dNicolai Hähnle 333