Path: blob/21.2-virgl/src/gallium/drivers/r300/compiler/radeon_program.h
4574 views
/*1* Copyright (C) 2008 Nicolai Haehnle.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#ifndef __RADEON_PROGRAM_H_28#define __RADEON_PROGRAM_H_2930#include <stdint.h>31#include <string.h>3233#include "radeon_opcodes.h"34#include "radeon_code.h"35#include "radeon_program_constants.h"36#include "radeon_program_pair.h"3738struct radeon_compiler;3940struct rc_src_register {41unsigned int File:4;4243/** Negative values may be used for relative addressing. */44signed int Index:(RC_REGISTER_INDEX_BITS+1);45unsigned int RelAddr:1;4647unsigned int Swizzle:12;4849/** Take the component-wise absolute value */50unsigned int Abs:1;5152/** Post-Abs negation. */53unsigned int Negate:4;54};5556struct rc_dst_register {57unsigned int File:3;58unsigned int Index:RC_REGISTER_INDEX_BITS;59unsigned int WriteMask:4;60unsigned int Pred:2;61};6263struct rc_presub_instruction {64rc_presubtract_op Opcode;65struct rc_src_register SrcReg[2];66};6768/**69* Instructions are maintained by the compiler in a doubly linked list70* of these structures.71*72* This instruction format is intended to be expanded for hardware-specific73* trickery. At different stages of compilation, a different set of74* instruction types may be valid.75*/76struct rc_sub_instruction {77struct rc_src_register SrcReg[3];78struct rc_dst_register DstReg;7980/**81* Opcode of this instruction, according to \ref rc_opcode enums.82*/83unsigned int Opcode:8;8485/**86* Saturate each value of the result to the range [0,1] or [-1,1],87* according to \ref rc_saturate_mode enums.88*/89unsigned int SaturateMode:2;9091/**92* Writing to the special register RC_SPECIAL_ALU_RESULT93*/94/*@{*/95unsigned int WriteALUResult:2;96unsigned int ALUResultCompare:3;97/*@}*/9899/**100* \name Extra fields for TEX, TXB, TXD, TXL, TXP instructions.101*/102/*@{*/103/** Source texture unit. */104unsigned int TexSrcUnit:5;105106/** Source texture target, one of the \ref rc_texture_target enums */107unsigned int TexSrcTarget:3;108109/** True if tex instruction should do shadow comparison */110unsigned int TexShadow:1;111112/**/113unsigned int TexSemWait:1;114unsigned int TexSemAcquire:1;115116/**R500 Only. How to swizzle the result of a TEX lookup*/117unsigned int TexSwizzle:12;118/*@}*/119120/** This holds information about the presubtract operation used by121* this instruction. */122struct rc_presub_instruction PreSub;123124rc_omod_op Omod;125};126127typedef enum {128RC_INSTRUCTION_NORMAL = 0,129RC_INSTRUCTION_PAIR130} rc_instruction_type;131132struct rc_instruction {133struct rc_instruction * Prev;134struct rc_instruction * Next;135136rc_instruction_type Type;137union {138struct rc_sub_instruction I;139struct rc_pair_instruction P;140} U;141142/**143* Warning: IPs are not stable. If you want to use them,144* you need to recompute them at the beginning of each pass145* using \ref rc_recompute_ips146*/147unsigned int IP;148};149150struct rc_program {151/**152* Instructions.Next points to the first instruction,153* Instructions.Prev points to the last instruction.154*/155struct rc_instruction Instructions;156157/* Long term, we should probably remove InputsRead & OutputsWritten,158* since updating dependent state can be fragile, and they aren't159* actually used very often. */160uint32_t InputsRead;161uint32_t OutputsWritten;162uint32_t ShadowSamplers; /**< Texture units used for shadow sampling. */163164struct rc_constant_list Constants;165};166167/**168* A transformation that can be passed to \ref rc_local_transform.169*170* The function will be called once for each instruction.171* It has to either emit the appropriate transformed code for the instruction172* and return true, or return false if it doesn't understand the173* instruction.174*175* The function gets passed the userData as last parameter.176*/177struct radeon_program_transformation {178int (*function)(179struct radeon_compiler*,180struct rc_instruction*,181void*);182void *userData;183};184185void rc_local_transform(186struct radeon_compiler *c,187void *user);188189void rc_get_used_temporaries(190struct radeon_compiler * c,191unsigned char * used,192unsigned int used_length);193194int rc_find_free_temporary_list(195struct radeon_compiler * c,196unsigned char * used,197unsigned int used_length,198unsigned int mask);199200unsigned int rc_find_free_temporary(struct radeon_compiler * c);201202struct rc_instruction *rc_alloc_instruction(struct radeon_compiler * c);203struct rc_instruction *rc_insert_new_instruction(struct radeon_compiler * c, struct rc_instruction * after);204void rc_insert_instruction(struct rc_instruction * after, struct rc_instruction * inst);205void rc_remove_instruction(struct rc_instruction * inst);206207unsigned int rc_recompute_ips(struct radeon_compiler * c);208209void rc_print_program(const struct rc_program *prog);210211rc_swizzle rc_mask_to_swizzle(unsigned int mask);212#endif213214215