1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
33 #include "i915_context.h"
38 #define I915_PROGRAM_SIZE 192
40 /* Use those indices for pos/face routing, must be >= I915_TEX_UNITS */
41 #define I915_SEMANTIC_POS 10
42 #define I915_SEMANTIC_FACE 11
46 * Program translation state
48 struct i915_fp_compile
{
49 struct i915_fragment_shader
*shader
; /* the shader we're compiling */
51 boolean used_constants
[I915_MAX_CONSTANT
];
53 /** maps TGSI immediate index to constant slot */
55 uint immediates_map
[I915_MAX_CONSTANT
];
56 float immediates
[I915_MAX_CONSTANT
][4];
58 boolean first_instruction
;
60 uint declarations
[I915_PROGRAM_SIZE
];
61 uint program
[I915_PROGRAM_SIZE
];
63 uint
*csr
; /**< Cursor, points into program. */
65 uint
*decl
; /**< Cursor, points into declarations. */
67 uint decl_s
; /**< flags for which s regs need to be decl'd */
68 uint decl_t
; /**< flags for which t regs need to be decl'd */
70 uint temp_flag
; /**< Tracks temporary regs which are in use */
71 uint utemp_flag
; /**< Tracks TYPE_U temporary regs which are in use */
73 uint register_phases
[16];
79 boolean error
; /**< Set if i915_program_error() is called */
80 uint NumNativeInstructions
;
81 uint NumNativeAluInstructions
;
82 uint NumNativeTexInstructions
;
83 uint NumNativeTexIndirections
;
87 /* Having zero and one in here makes the definition of swizzle a lot
90 #define UREG_TYPE_SHIFT 29
91 #define UREG_NR_SHIFT 24
92 #define UREG_CHANNEL_X_NEGATE_SHIFT 23
93 #define UREG_CHANNEL_X_SHIFT 20
94 #define UREG_CHANNEL_Y_NEGATE_SHIFT 19
95 #define UREG_CHANNEL_Y_SHIFT 16
96 #define UREG_CHANNEL_Z_NEGATE_SHIFT 15
97 #define UREG_CHANNEL_Z_SHIFT 12
98 #define UREG_CHANNEL_W_NEGATE_SHIFT 11
99 #define UREG_CHANNEL_W_SHIFT 8
100 #define UREG_CHANNEL_ZERO_NEGATE_MBZ 5
101 #define UREG_CHANNEL_ZERO_SHIFT 4
102 #define UREG_CHANNEL_ONE_NEGATE_MBZ 1
103 #define UREG_CHANNEL_ONE_SHIFT 0
105 #define UREG_BAD 0xffffffff /* not a valid ureg */
111 #define ZERO SRC_ZERO
116 #define UREG( type, nr ) (((type)<< UREG_TYPE_SHIFT) | \
117 ((nr) << UREG_NR_SHIFT) | \
118 (X << UREG_CHANNEL_X_SHIFT) | \
119 (Y << UREG_CHANNEL_Y_SHIFT) | \
120 (Z << UREG_CHANNEL_Z_SHIFT) | \
121 (W << UREG_CHANNEL_W_SHIFT) | \
122 (ZERO << UREG_CHANNEL_ZERO_SHIFT) | \
123 (ONE << UREG_CHANNEL_ONE_SHIFT))
125 #define GET_CHANNEL_SRC( reg, channel ) ((reg<<(channel*4)) & (0xf<<20))
126 #define CHANNEL_SRC( src, channel ) (src>>(channel*4))
128 #define GET_UREG_TYPE(reg) (((reg)>>UREG_TYPE_SHIFT)®_TYPE_MASK)
129 #define GET_UREG_NR(reg) (((reg)>>UREG_NR_SHIFT)®_NR_MASK)
133 #define UREG_XYZW_CHANNEL_MASK 0x00ffff00
135 /* One neat thing about the UREG representation:
138 swizzle(int reg
, uint x
, uint y
, uint z
, uint w
)
140 assert(x
<= SRC_ONE
);
141 assert(y
<= SRC_ONE
);
142 assert(z
<= SRC_ONE
);
143 assert(w
<= SRC_ONE
);
144 return ((reg
& ~UREG_XYZW_CHANNEL_MASK
) |
145 CHANNEL_SRC(GET_CHANNEL_SRC(reg
, x
), 0) |
146 CHANNEL_SRC(GET_CHANNEL_SRC(reg
, y
), 1) |
147 CHANNEL_SRC(GET_CHANNEL_SRC(reg
, z
), 2) |
148 CHANNEL_SRC(GET_CHANNEL_SRC(reg
, w
), 3));
153 /***********************************************************************
154 * Public interface for the compiler
157 i915_translate_fragment_program( struct i915_context
*i915
,
158 struct i915_fragment_shader
*fs
);
162 extern uint
i915_get_temp(struct i915_fp_compile
*p
);
163 extern uint
i915_get_utemp(struct i915_fp_compile
*p
);
164 extern void i915_release_utemps(struct i915_fp_compile
*p
);
167 extern uint
i915_emit_texld(struct i915_fp_compile
*p
,
170 uint sampler
, uint coord
, uint op
);
172 extern uint
i915_emit_arith(struct i915_fp_compile
*p
,
177 uint src0
, uint src1
, uint src2
);
179 extern uint
i915_emit_decl(struct i915_fp_compile
*p
,
180 uint type
, uint nr
, uint d0_flags
);
183 extern uint
i915_emit_const1f(struct i915_fp_compile
*p
, float c0
);
185 extern uint
i915_emit_const2f(struct i915_fp_compile
*p
,
188 extern uint
i915_emit_const4fv(struct i915_fp_compile
*p
,
191 extern uint
i915_emit_const4f(struct i915_fp_compile
*p
,
196 /*======================================================================
199 extern void i915_disassemble_program(const uint
* program
, uint sz
);
202 /*======================================================================
203 * i915_fpc_translate.c
207 i915_program_error(struct i915_fp_compile
*p
, const char *msg
, ...);