1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright 2009 Nicolai Hähnle <nhaehnle@gmail.com> 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub 8bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom 9bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 19bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. */ 22bf215546Sopenharmony_ci 23bf215546Sopenharmony_ci#ifndef RADEON_CODE_H 24bf215546Sopenharmony_ci#define RADEON_CODE_H 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci#include <stdint.h> 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#define R300_PFS_MAX_ALU_INST 64 29bf215546Sopenharmony_ci#define R300_PFS_MAX_TEX_INST 32 30bf215546Sopenharmony_ci#define R300_PFS_MAX_TEX_INDIRECT 4 31bf215546Sopenharmony_ci#define R300_PFS_NUM_TEMP_REGS 32 32bf215546Sopenharmony_ci#define R300_PFS_NUM_CONST_REGS 32 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_ci#define R400_PFS_MAX_ALU_INST 512 35bf215546Sopenharmony_ci#define R400_PFS_MAX_TEX_INST 512 36bf215546Sopenharmony_ci 37bf215546Sopenharmony_ci#define R500_PFS_MAX_INST 512 38bf215546Sopenharmony_ci#define R500_PFS_NUM_TEMP_REGS 128 39bf215546Sopenharmony_ci#define R500_PFS_NUM_CONST_REGS 256 40bf215546Sopenharmony_ci#define R500_PFS_MAX_BRANCH_DEPTH_FULL 32 41bf215546Sopenharmony_ci#define R500_PFS_MAX_BRANCH_DEPTH_PARTIAL 4 42bf215546Sopenharmony_ci 43bf215546Sopenharmony_ci/* The r500 maximum depth is not just for loops, but any combination of loops 44bf215546Sopenharmony_ci * and subroutine jumps. */ 45bf215546Sopenharmony_ci#define R500_PVS_MAX_LOOP_DEPTH 8 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ci#define STATE_R300_WINDOW_DIMENSION (STATE_INTERNAL_DRIVER+0) 48bf215546Sopenharmony_ci 49bf215546Sopenharmony_cienum { 50bf215546Sopenharmony_ci /** 51bf215546Sopenharmony_ci * External constants are constants whose meaning is unknown to this 52bf215546Sopenharmony_ci * compiler. For example, a Mesa gl_program's constants are turned 53bf215546Sopenharmony_ci * into external constants. 54bf215546Sopenharmony_ci */ 55bf215546Sopenharmony_ci RC_CONSTANT_EXTERNAL = 0, 56bf215546Sopenharmony_ci 57bf215546Sopenharmony_ci RC_CONSTANT_IMMEDIATE, 58bf215546Sopenharmony_ci 59bf215546Sopenharmony_ci /** 60bf215546Sopenharmony_ci * Constant referring to state that is known by this compiler, 61bf215546Sopenharmony_ci * see RC_STATE_xxx, i.e. *not* arbitrary Mesa (or other) state. 62bf215546Sopenharmony_ci */ 63bf215546Sopenharmony_ci RC_CONSTANT_STATE 64bf215546Sopenharmony_ci}; 65bf215546Sopenharmony_ci 66bf215546Sopenharmony_cienum { 67bf215546Sopenharmony_ci RC_STATE_SHADOW_AMBIENT = 0, 68bf215546Sopenharmony_ci 69bf215546Sopenharmony_ci RC_STATE_R300_WINDOW_DIMENSION, 70bf215546Sopenharmony_ci RC_STATE_R300_TEXRECT_FACTOR, 71bf215546Sopenharmony_ci RC_STATE_R300_TEXSCALE_FACTOR, 72bf215546Sopenharmony_ci RC_STATE_R300_VIEWPORT_SCALE, 73bf215546Sopenharmony_ci RC_STATE_R300_VIEWPORT_OFFSET 74bf215546Sopenharmony_ci}; 75bf215546Sopenharmony_ci 76bf215546Sopenharmony_cistruct rc_constant { 77bf215546Sopenharmony_ci unsigned Type:2; /**< RC_CONSTANT_xxx */ 78bf215546Sopenharmony_ci unsigned Size:3; 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_ci union { 81bf215546Sopenharmony_ci unsigned External; 82bf215546Sopenharmony_ci float Immediate[4]; 83bf215546Sopenharmony_ci unsigned State[2]; 84bf215546Sopenharmony_ci } u; 85bf215546Sopenharmony_ci}; 86bf215546Sopenharmony_ci 87bf215546Sopenharmony_cistruct rc_constant_list { 88bf215546Sopenharmony_ci struct rc_constant * Constants; 89bf215546Sopenharmony_ci unsigned Count; 90bf215546Sopenharmony_ci 91bf215546Sopenharmony_ci unsigned _Reserved; 92bf215546Sopenharmony_ci}; 93bf215546Sopenharmony_ci 94bf215546Sopenharmony_civoid rc_constants_init(struct rc_constant_list * c); 95bf215546Sopenharmony_civoid rc_constants_copy(struct rc_constant_list * dst, struct rc_constant_list * src); 96bf215546Sopenharmony_civoid rc_constants_destroy(struct rc_constant_list * c); 97bf215546Sopenharmony_ciunsigned rc_constants_add(struct rc_constant_list * c, struct rc_constant * constant); 98bf215546Sopenharmony_ciunsigned rc_constants_add_state(struct rc_constant_list * c, unsigned state1, unsigned state2); 99bf215546Sopenharmony_ciunsigned rc_constants_add_immediate_vec4(struct rc_constant_list * c, const float * data); 100bf215546Sopenharmony_ciunsigned rc_constants_add_immediate_scalar(struct rc_constant_list * c, float data, unsigned * swizzle); 101bf215546Sopenharmony_civoid rc_constants_print(struct rc_constant_list * c); 102bf215546Sopenharmony_ci 103bf215546Sopenharmony_ci/** 104bf215546Sopenharmony_ci * Compare functions. 105bf215546Sopenharmony_ci * 106bf215546Sopenharmony_ci * \note By design, RC_COMPARE_FUNC_xxx + GL_NEVER gives you 107bf215546Sopenharmony_ci * the correct GL compare function. 108bf215546Sopenharmony_ci */ 109bf215546Sopenharmony_citypedef enum { 110bf215546Sopenharmony_ci RC_COMPARE_FUNC_NEVER = 0, 111bf215546Sopenharmony_ci RC_COMPARE_FUNC_LESS, 112bf215546Sopenharmony_ci RC_COMPARE_FUNC_EQUAL, 113bf215546Sopenharmony_ci RC_COMPARE_FUNC_LEQUAL, 114bf215546Sopenharmony_ci RC_COMPARE_FUNC_GREATER, 115bf215546Sopenharmony_ci RC_COMPARE_FUNC_NOTEQUAL, 116bf215546Sopenharmony_ci RC_COMPARE_FUNC_GEQUAL, 117bf215546Sopenharmony_ci RC_COMPARE_FUNC_ALWAYS 118bf215546Sopenharmony_ci} rc_compare_func; 119bf215546Sopenharmony_ci 120bf215546Sopenharmony_ci/** 121bf215546Sopenharmony_ci * Coordinate wrapping modes. 122bf215546Sopenharmony_ci * 123bf215546Sopenharmony_ci * These are not quite the same as their GL counterparts yet. 124bf215546Sopenharmony_ci */ 125bf215546Sopenharmony_citypedef enum { 126bf215546Sopenharmony_ci RC_WRAP_NONE = 0, 127bf215546Sopenharmony_ci RC_WRAP_REPEAT, 128bf215546Sopenharmony_ci RC_WRAP_MIRRORED_REPEAT, 129bf215546Sopenharmony_ci RC_WRAP_MIRRORED_CLAMP 130bf215546Sopenharmony_ci} rc_wrap_mode; 131bf215546Sopenharmony_ci 132bf215546Sopenharmony_ci/** 133bf215546Sopenharmony_ci * Stores state that influences the compilation of a fragment program. 134bf215546Sopenharmony_ci */ 135bf215546Sopenharmony_cistruct r300_fragment_program_external_state { 136bf215546Sopenharmony_ci struct { 137bf215546Sopenharmony_ci /** 138bf215546Sopenharmony_ci * This field contains swizzle for some lowering passes 139bf215546Sopenharmony_ci * (shadow comparison, unorm->snorm conversion) 140bf215546Sopenharmony_ci */ 141bf215546Sopenharmony_ci unsigned texture_swizzle:12; 142bf215546Sopenharmony_ci 143bf215546Sopenharmony_ci /** 144bf215546Sopenharmony_ci * If the sampler is used as a shadow sampler, 145bf215546Sopenharmony_ci * this field specifies the compare function. 146bf215546Sopenharmony_ci * 147bf215546Sopenharmony_ci * Otherwise, this field is \ref RC_COMPARE_FUNC_NEVER (aka 0). 148bf215546Sopenharmony_ci * \sa rc_compare_func 149bf215546Sopenharmony_ci */ 150bf215546Sopenharmony_ci unsigned texture_compare_func : 3; 151bf215546Sopenharmony_ci 152bf215546Sopenharmony_ci /** 153bf215546Sopenharmony_ci * No matter what the sampler type is, 154bf215546Sopenharmony_ci * this field turns it into a shadow sampler. 155bf215546Sopenharmony_ci */ 156bf215546Sopenharmony_ci unsigned compare_mode_enabled : 1; 157bf215546Sopenharmony_ci 158bf215546Sopenharmony_ci /** 159bf215546Sopenharmony_ci * This field specifies wrapping modes for the sampler. 160bf215546Sopenharmony_ci * 161bf215546Sopenharmony_ci * If this field is \ref RC_WRAP_NONE (aka 0), no wrapping maths 162bf215546Sopenharmony_ci * will be performed on the coordinates. 163bf215546Sopenharmony_ci */ 164bf215546Sopenharmony_ci unsigned wrap_mode : 3; 165bf215546Sopenharmony_ci 166bf215546Sopenharmony_ci /** 167bf215546Sopenharmony_ci * The coords are scaled after applying the wrap mode emulation 168bf215546Sopenharmony_ci * and right before texture fetch. The scaling factor is given by 169bf215546Sopenharmony_ci * RC_STATE_R300_TEXSCALE_FACTOR. */ 170bf215546Sopenharmony_ci unsigned clamp_and_scale_before_fetch : 1; 171bf215546Sopenharmony_ci } unit[16]; 172bf215546Sopenharmony_ci 173bf215546Sopenharmony_ci unsigned alpha_to_one:1; 174bf215546Sopenharmony_ci}; 175bf215546Sopenharmony_ci 176bf215546Sopenharmony_ci 177bf215546Sopenharmony_ci 178bf215546Sopenharmony_cistruct r300_fragment_program_node { 179bf215546Sopenharmony_ci int tex_offset; /**< first tex instruction */ 180bf215546Sopenharmony_ci int tex_end; /**< last tex instruction, relative to tex_offset */ 181bf215546Sopenharmony_ci int alu_offset; /**< first ALU instruction */ 182bf215546Sopenharmony_ci int alu_end; /**< last ALU instruction, relative to alu_offset */ 183bf215546Sopenharmony_ci int flags; 184bf215546Sopenharmony_ci}; 185bf215546Sopenharmony_ci 186bf215546Sopenharmony_ci/** 187bf215546Sopenharmony_ci * Stores an R300 fragment program in its compiled-to-hardware form. 188bf215546Sopenharmony_ci */ 189bf215546Sopenharmony_cistruct r300_fragment_program_code { 190bf215546Sopenharmony_ci struct { 191bf215546Sopenharmony_ci unsigned int length; /**< total # of texture instructions used */ 192bf215546Sopenharmony_ci uint32_t inst[R400_PFS_MAX_TEX_INST]; 193bf215546Sopenharmony_ci } tex; 194bf215546Sopenharmony_ci 195bf215546Sopenharmony_ci struct { 196bf215546Sopenharmony_ci unsigned int length; /**< total # of ALU instructions used */ 197bf215546Sopenharmony_ci struct { 198bf215546Sopenharmony_ci uint32_t rgb_inst; 199bf215546Sopenharmony_ci uint32_t rgb_addr; 200bf215546Sopenharmony_ci uint32_t alpha_inst; 201bf215546Sopenharmony_ci uint32_t alpha_addr; 202bf215546Sopenharmony_ci uint32_t r400_ext_addr; 203bf215546Sopenharmony_ci } inst[R400_PFS_MAX_ALU_INST]; 204bf215546Sopenharmony_ci } alu; 205bf215546Sopenharmony_ci 206bf215546Sopenharmony_ci uint32_t config; /* US_CONFIG */ 207bf215546Sopenharmony_ci uint32_t pixsize; /* US_PIXSIZE */ 208bf215546Sopenharmony_ci uint32_t code_offset; /* US_CODE_OFFSET */ 209bf215546Sopenharmony_ci uint32_t r400_code_offset_ext; /* US_CODE_EXT */ 210bf215546Sopenharmony_ci uint32_t code_addr[4]; /* US_CODE_ADDR */ 211bf215546Sopenharmony_ci /*US_CODE_BANK.R390_MODE: Enables 512 instructions and 64 temporaries 212bf215546Sopenharmony_ci * for r400 cards */ 213bf215546Sopenharmony_ci unsigned int r390_mode:1; 214bf215546Sopenharmony_ci}; 215bf215546Sopenharmony_ci 216bf215546Sopenharmony_ci 217bf215546Sopenharmony_cistruct r500_fragment_program_code { 218bf215546Sopenharmony_ci struct { 219bf215546Sopenharmony_ci uint32_t inst0; 220bf215546Sopenharmony_ci uint32_t inst1; 221bf215546Sopenharmony_ci uint32_t inst2; 222bf215546Sopenharmony_ci uint32_t inst3; 223bf215546Sopenharmony_ci uint32_t inst4; 224bf215546Sopenharmony_ci uint32_t inst5; 225bf215546Sopenharmony_ci } inst[R500_PFS_MAX_INST]; 226bf215546Sopenharmony_ci 227bf215546Sopenharmony_ci int inst_end; /* Number of instructions - 1; also, last instruction to be executed */ 228bf215546Sopenharmony_ci 229bf215546Sopenharmony_ci int max_temp_idx; 230bf215546Sopenharmony_ci 231bf215546Sopenharmony_ci uint32_t us_fc_ctrl; 232bf215546Sopenharmony_ci 233bf215546Sopenharmony_ci uint32_t int_constants[32]; 234bf215546Sopenharmony_ci uint32_t int_constant_count; 235bf215546Sopenharmony_ci}; 236bf215546Sopenharmony_ci 237bf215546Sopenharmony_cistruct rX00_fragment_program_code { 238bf215546Sopenharmony_ci union { 239bf215546Sopenharmony_ci struct r300_fragment_program_code r300; 240bf215546Sopenharmony_ci struct r500_fragment_program_code r500; 241bf215546Sopenharmony_ci } code; 242bf215546Sopenharmony_ci 243bf215546Sopenharmony_ci unsigned writes_depth:1; 244bf215546Sopenharmony_ci 245bf215546Sopenharmony_ci struct rc_constant_list constants; 246bf215546Sopenharmony_ci unsigned *constants_remap_table; 247bf215546Sopenharmony_ci}; 248bf215546Sopenharmony_ci 249bf215546Sopenharmony_ci 250bf215546Sopenharmony_ci#define R300_VS_MAX_ALU 256 251bf215546Sopenharmony_ci#define R300_VS_MAX_ALU_DWORDS (R300_VS_MAX_ALU * 4) 252bf215546Sopenharmony_ci#define R500_VS_MAX_ALU 1024 253bf215546Sopenharmony_ci#define R500_VS_MAX_ALU_DWORDS (R500_VS_MAX_ALU * 4) 254bf215546Sopenharmony_ci#define R300_VS_MAX_TEMPS 32 255bf215546Sopenharmony_ci/* This is the max for all chipsets (r300-r500) */ 256bf215546Sopenharmony_ci#define R300_VS_MAX_FC_OPS 16 257bf215546Sopenharmony_ci#define R300_VS_MAX_LOOP_DEPTH 1 258bf215546Sopenharmony_ci 259bf215546Sopenharmony_ci#define VSF_MAX_INPUTS 32 260bf215546Sopenharmony_ci#define VSF_MAX_OUTPUTS 32 261bf215546Sopenharmony_ci 262bf215546Sopenharmony_cistruct r300_vertex_program_code { 263bf215546Sopenharmony_ci int length; 264bf215546Sopenharmony_ci union { 265bf215546Sopenharmony_ci uint32_t d[R500_VS_MAX_ALU_DWORDS]; 266bf215546Sopenharmony_ci float f[R500_VS_MAX_ALU_DWORDS]; 267bf215546Sopenharmony_ci } body; 268bf215546Sopenharmony_ci 269bf215546Sopenharmony_ci int pos_end; 270bf215546Sopenharmony_ci int num_temporaries; /* Number of temp vars used by program */ 271bf215546Sopenharmony_ci int inputs[VSF_MAX_INPUTS]; 272bf215546Sopenharmony_ci int outputs[VSF_MAX_OUTPUTS]; 273bf215546Sopenharmony_ci unsigned last_input_read; 274bf215546Sopenharmony_ci unsigned last_pos_write; 275bf215546Sopenharmony_ci 276bf215546Sopenharmony_ci struct rc_constant_list constants; 277bf215546Sopenharmony_ci unsigned *constants_remap_table; 278bf215546Sopenharmony_ci 279bf215546Sopenharmony_ci uint32_t InputsRead; 280bf215546Sopenharmony_ci uint32_t OutputsWritten; 281bf215546Sopenharmony_ci 282bf215546Sopenharmony_ci unsigned int num_fc_ops; 283bf215546Sopenharmony_ci uint32_t fc_ops; 284bf215546Sopenharmony_ci union { 285bf215546Sopenharmony_ci uint32_t r300[R300_VS_MAX_FC_OPS]; 286bf215546Sopenharmony_ci struct { 287bf215546Sopenharmony_ci uint32_t lw; 288bf215546Sopenharmony_ci uint32_t uw; 289bf215546Sopenharmony_ci } r500[R300_VS_MAX_FC_OPS]; 290bf215546Sopenharmony_ci } fc_op_addrs; 291bf215546Sopenharmony_ci int32_t fc_loop_index[R300_VS_MAX_FC_OPS]; 292bf215546Sopenharmony_ci}; 293bf215546Sopenharmony_ci 294bf215546Sopenharmony_ci#endif /* RADEON_CODE_H */ 295bf215546Sopenharmony_ci 296