Path: blob/21.2-virgl/src/gallium/drivers/r300/compiler/radeon_code.h
4574 views
/*1* Copyright 2009 Nicolai Hähnle <[email protected]>2*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* on the rights to use, copy, modify, merge, publish, distribute, sub7* license, and/or sell copies of the Software, and to permit persons to whom8* the Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* 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 AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE. */2122#ifndef RADEON_CODE_H23#define RADEON_CODE_H2425#include <stdint.h>2627#define R300_PFS_MAX_ALU_INST 6428#define R300_PFS_MAX_TEX_INST 3229#define R300_PFS_MAX_TEX_INDIRECT 430#define R300_PFS_NUM_TEMP_REGS 3231#define R300_PFS_NUM_CONST_REGS 323233#define R400_PFS_MAX_ALU_INST 51234#define R400_PFS_MAX_TEX_INST 5123536#define R500_PFS_MAX_INST 51237#define R500_PFS_NUM_TEMP_REGS 12838#define R500_PFS_NUM_CONST_REGS 25639#define R500_PFS_MAX_BRANCH_DEPTH_FULL 3240#define R500_PFS_MAX_BRANCH_DEPTH_PARTIAL 44142/* The r500 maximum depth is not just for loops, but any combination of loops43* and subroutine jumps. */44#define R500_PVS_MAX_LOOP_DEPTH 84546#define STATE_R300_WINDOW_DIMENSION (STATE_INTERNAL_DRIVER+0)4748enum {49/**50* External constants are constants whose meaning is unknown to this51* compiler. For example, a Mesa gl_program's constants are turned52* into external constants.53*/54RC_CONSTANT_EXTERNAL = 0,5556RC_CONSTANT_IMMEDIATE,5758/**59* Constant referring to state that is known by this compiler,60* see RC_STATE_xxx, i.e. *not* arbitrary Mesa (or other) state.61*/62RC_CONSTANT_STATE63};6465enum {66RC_STATE_SHADOW_AMBIENT = 0,6768RC_STATE_R300_WINDOW_DIMENSION,69RC_STATE_R300_TEXRECT_FACTOR,70RC_STATE_R300_TEXSCALE_FACTOR,71RC_STATE_R300_VIEWPORT_SCALE,72RC_STATE_R300_VIEWPORT_OFFSET73};7475struct rc_constant {76unsigned Type:2; /**< RC_CONSTANT_xxx */77unsigned Size:3;7879union {80unsigned External;81float Immediate[4];82unsigned State[2];83} u;84};8586struct rc_constant_list {87struct rc_constant * Constants;88unsigned Count;8990unsigned _Reserved;91};9293void rc_constants_init(struct rc_constant_list * c);94void rc_constants_copy(struct rc_constant_list * dst, struct rc_constant_list * src);95void rc_constants_destroy(struct rc_constant_list * c);96unsigned rc_constants_add(struct rc_constant_list * c, struct rc_constant * constant);97unsigned rc_constants_add_state(struct rc_constant_list * c, unsigned state1, unsigned state2);98unsigned rc_constants_add_immediate_vec4(struct rc_constant_list * c, const float * data);99unsigned rc_constants_add_immediate_scalar(struct rc_constant_list * c, float data, unsigned * swizzle);100void rc_constants_print(struct rc_constant_list * c);101102/**103* Compare functions.104*105* \note By design, RC_COMPARE_FUNC_xxx + GL_NEVER gives you106* the correct GL compare function.107*/108typedef enum {109RC_COMPARE_FUNC_NEVER = 0,110RC_COMPARE_FUNC_LESS,111RC_COMPARE_FUNC_EQUAL,112RC_COMPARE_FUNC_LEQUAL,113RC_COMPARE_FUNC_GREATER,114RC_COMPARE_FUNC_NOTEQUAL,115RC_COMPARE_FUNC_GEQUAL,116RC_COMPARE_FUNC_ALWAYS117} rc_compare_func;118119/**120* Coordinate wrapping modes.121*122* These are not quite the same as their GL counterparts yet.123*/124typedef enum {125RC_WRAP_NONE = 0,126RC_WRAP_REPEAT,127RC_WRAP_MIRRORED_REPEAT,128RC_WRAP_MIRRORED_CLAMP129} rc_wrap_mode;130131/**132* Stores state that influences the compilation of a fragment program.133*/134struct r300_fragment_program_external_state {135struct {136/**137* This field contains swizzle for some lowering passes138* (shadow comparison, unorm->snorm conversion)139*/140unsigned texture_swizzle:12;141142/**143* If the sampler is used as a shadow sampler,144* this field specifies the compare function.145*146* Otherwise, this field is \ref RC_COMPARE_FUNC_NEVER (aka 0).147* \sa rc_compare_func148*/149unsigned texture_compare_func : 3;150151/**152* No matter what the sampler type is,153* this field turns it into a shadow sampler.154*/155unsigned compare_mode_enabled : 1;156157/**158* If the sampler will receive non-normalized coords,159* this field is set. The scaling factor is given by160* RC_STATE_R300_TEXRECT_FACTOR.161*/162unsigned non_normalized_coords : 1;163164/**165* This field specifies wrapping modes for the sampler.166*167* If this field is \ref RC_WRAP_NONE (aka 0), no wrapping maths168* will be performed on the coordinates.169*/170unsigned wrap_mode : 3;171172/**173* The coords are scaled after applying the wrap mode emulation174* and right before texture fetch. The scaling factor is given by175* RC_STATE_R300_TEXSCALE_FACTOR. */176unsigned clamp_and_scale_before_fetch : 1;177} unit[16];178179unsigned alpha_to_one:1;180};181182183184struct r300_fragment_program_node {185int tex_offset; /**< first tex instruction */186int tex_end; /**< last tex instruction, relative to tex_offset */187int alu_offset; /**< first ALU instruction */188int alu_end; /**< last ALU instruction, relative to alu_offset */189int flags;190};191192/**193* Stores an R300 fragment program in its compiled-to-hardware form.194*/195struct r300_fragment_program_code {196struct {197unsigned int length; /**< total # of texture instructions used */198uint32_t inst[R400_PFS_MAX_TEX_INST];199} tex;200201struct {202unsigned int length; /**< total # of ALU instructions used */203struct {204uint32_t rgb_inst;205uint32_t rgb_addr;206uint32_t alpha_inst;207uint32_t alpha_addr;208uint32_t r400_ext_addr;209} inst[R400_PFS_MAX_ALU_INST];210} alu;211212uint32_t config; /* US_CONFIG */213uint32_t pixsize; /* US_PIXSIZE */214uint32_t code_offset; /* US_CODE_OFFSET */215uint32_t r400_code_offset_ext; /* US_CODE_EXT */216uint32_t code_addr[4]; /* US_CODE_ADDR */217/*US_CODE_BANK.R390_MODE: Enables 512 instructions and 64 temporaries218* for r400 cards */219unsigned int r390_mode:1;220};221222223struct r500_fragment_program_code {224struct {225uint32_t inst0;226uint32_t inst1;227uint32_t inst2;228uint32_t inst3;229uint32_t inst4;230uint32_t inst5;231} inst[R500_PFS_MAX_INST];232233int inst_end; /* Number of instructions - 1; also, last instruction to be executed */234235int max_temp_idx;236237uint32_t us_fc_ctrl;238239uint32_t int_constants[32];240uint32_t int_constant_count;241};242243struct rX00_fragment_program_code {244union {245struct r300_fragment_program_code r300;246struct r500_fragment_program_code r500;247} code;248249unsigned writes_depth:1;250251struct rc_constant_list constants;252unsigned *constants_remap_table;253};254255256#define R300_VS_MAX_ALU 256257#define R300_VS_MAX_ALU_DWORDS (R300_VS_MAX_ALU * 4)258#define R500_VS_MAX_ALU 1024259#define R500_VS_MAX_ALU_DWORDS (R500_VS_MAX_ALU * 4)260#define R300_VS_MAX_TEMPS 32261/* This is the max for all chipsets (r300-r500) */262#define R300_VS_MAX_FC_OPS 16263#define R300_VS_MAX_LOOP_DEPTH 1264265#define VSF_MAX_INPUTS 32266#define VSF_MAX_OUTPUTS 32267268struct r300_vertex_program_code {269int length;270union {271uint32_t d[R500_VS_MAX_ALU_DWORDS];272float f[R500_VS_MAX_ALU_DWORDS];273} body;274275int pos_end;276int num_temporaries; /* Number of temp vars used by program */277int inputs[VSF_MAX_INPUTS];278int outputs[VSF_MAX_OUTPUTS];279280struct rc_constant_list constants;281unsigned *constants_remap_table;282283uint32_t InputsRead;284uint32_t OutputsWritten;285286unsigned int num_fc_ops;287uint32_t fc_ops;288union {289uint32_t r300[R300_VS_MAX_FC_OPS];290struct {291uint32_t lw;292uint32_t uw;293} r500[R300_VS_MAX_FC_OPS];294} fc_op_addrs;295int32_t fc_loop_index[R300_VS_MAX_FC_OPS];296};297298#endif /* RADEON_CODE_H */299300301302