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 **************************************************************************/
32 #include "pipe/p_util.h"
34 #include "i915_context.h"
39 #define I915_PROGRAM_SIZE 192
55 FRAG_ATTRIB_TEX6
= 10,
56 FRAG_ATTRIB_TEX7
= 11,
57 FRAG_ATTRIB_VAR0
= 12, /**< shader varying */
58 FRAG_ATTRIB_MAX
= (FRAG_ATTRIB_VAR0
+ MAX_VARYING
)
62 * Bitflags for fragment program input attributes.
65 #define FRAG_BIT_WPOS (1 << FRAG_ATTRIB_WPOS)
66 #define FRAG_BIT_COL0 (1 << FRAG_ATTRIB_COL0)
67 #define FRAG_BIT_COL1 (1 << FRAG_ATTRIB_COL1)
68 #define FRAG_BIT_FOGC (1 << FRAG_ATTRIB_FOGC)
69 #define FRAG_BIT_TEX0 (1 << FRAG_ATTRIB_TEX0)
70 #define FRAG_BIT_TEX1 (1 << FRAG_ATTRIB_TEX1)
71 #define FRAG_BIT_TEX2 (1 << FRAG_ATTRIB_TEX2)
72 #define FRAG_BIT_TEX3 (1 << FRAG_ATTRIB_TEX3)
73 #define FRAG_BIT_TEX4 (1 << FRAG_ATTRIB_TEX4)
74 #define FRAG_BIT_TEX5 (1 << FRAG_ATTRIB_TEX5)
75 #define FRAG_BIT_TEX6 (1 << FRAG_ATTRIB_TEX6)
76 #define FRAG_BIT_TEX7 (1 << FRAG_ATTRIB_TEX7)
77 #define FRAG_BIT_VAR0 (1 << FRAG_ATTRIB_VAR0)
79 #define MAX_DRAW_BUFFERS 4
86 FRAG_RESULT_DATA0
= 3,
87 FRAG_RESULT_MAX
= (FRAG_RESULT_DATA0
+ MAX_DRAW_BUFFERS
)
93 * Program translation state
95 struct i915_fp_compile
{
96 struct pipe_shader_state
*shader
;
98 uint declarations
[I915_PROGRAM_SIZE
];
99 uint program
[I915_PROGRAM_SIZE
];
101 /** points into the i915->current.constants array: */
102 float (*constants
)[4];
104 uint constant_flags
[I915_MAX_CONSTANT
]; /**< status of each constant */
106 uint
*csr
; /* Cursor, points into program.
109 uint
*decl
; /* Cursor, points into declarations.
112 uint decl_s
; /* flags for which s regs need to be decl'd */
113 uint decl_t
; /* flags for which t regs need to be decl'd */
115 uint temp_flag
; /* Tracks temporary regs which are in
119 uint utemp_flag
; /* Tracks TYPE_U temporary regs which are in
123 uint nr_tex_indirect
;
128 boolean error
; /**< Set if i915_program_error() is called */
130 uint NumNativeInstructions
;
131 uint NumNativeAluInstructions
;
132 uint NumNativeTexInstructions
;
133 uint NumNativeTexIndirections
;
137 /* Having zero and one in here makes the definition of swizzle a lot
140 #define UREG_TYPE_SHIFT 29
141 #define UREG_NR_SHIFT 24
142 #define UREG_CHANNEL_X_NEGATE_SHIFT 23
143 #define UREG_CHANNEL_X_SHIFT 20
144 #define UREG_CHANNEL_Y_NEGATE_SHIFT 19
145 #define UREG_CHANNEL_Y_SHIFT 16
146 #define UREG_CHANNEL_Z_NEGATE_SHIFT 15
147 #define UREG_CHANNEL_Z_SHIFT 12
148 #define UREG_CHANNEL_W_NEGATE_SHIFT 11
149 #define UREG_CHANNEL_W_SHIFT 8
150 #define UREG_CHANNEL_ZERO_NEGATE_MBZ 5
151 #define UREG_CHANNEL_ZERO_SHIFT 4
152 #define UREG_CHANNEL_ONE_NEGATE_MBZ 1
153 #define UREG_CHANNEL_ONE_SHIFT 0
155 #define UREG_BAD 0xffffffff /* not a valid ureg */
161 #define ZERO SRC_ZERO
166 #define UREG( type, nr ) (((type)<< UREG_TYPE_SHIFT) | \
167 ((nr) << UREG_NR_SHIFT) | \
168 (X << UREG_CHANNEL_X_SHIFT) | \
169 (Y << UREG_CHANNEL_Y_SHIFT) | \
170 (Z << UREG_CHANNEL_Z_SHIFT) | \
171 (W << UREG_CHANNEL_W_SHIFT) | \
172 (ZERO << UREG_CHANNEL_ZERO_SHIFT) | \
173 (ONE << UREG_CHANNEL_ONE_SHIFT))
175 #define GET_CHANNEL_SRC( reg, channel ) ((reg<<(channel*4)) & (0xf<<20))
176 #define CHANNEL_SRC( src, channel ) (src>>(channel*4))
178 #define GET_UREG_TYPE(reg) (((reg)>>UREG_TYPE_SHIFT)®_TYPE_MASK)
179 #define GET_UREG_NR(reg) (((reg)>>UREG_NR_SHIFT)®_NR_MASK)
183 #define UREG_XYZW_CHANNEL_MASK 0x00ffff00
185 /* One neat thing about the UREG representation:
188 swizzle(int reg
, uint x
, uint y
, uint z
, uint w
)
190 assert(x
<= SRC_ONE
);
191 assert(y
<= SRC_ONE
);
192 assert(z
<= SRC_ONE
);
193 assert(w
<= SRC_ONE
);
194 return ((reg
& ~UREG_XYZW_CHANNEL_MASK
) |
195 CHANNEL_SRC(GET_CHANNEL_SRC(reg
, x
), 0) |
196 CHANNEL_SRC(GET_CHANNEL_SRC(reg
, y
), 1) |
197 CHANNEL_SRC(GET_CHANNEL_SRC(reg
, z
), 2) |
198 CHANNEL_SRC(GET_CHANNEL_SRC(reg
, w
), 3));
203 /***********************************************************************
204 * Public interface for the compiler
206 extern void i915_translate_fragment_program( struct i915_context
*i915
);
210 extern uint
i915_get_temp(struct i915_fp_compile
*p
);
211 extern uint
i915_get_utemp(struct i915_fp_compile
*p
);
212 extern void i915_release_utemps(struct i915_fp_compile
*p
);
215 extern uint
i915_emit_texld(struct i915_fp_compile
*p
,
218 uint sampler
, uint coord
, uint op
);
220 extern uint
i915_emit_arith(struct i915_fp_compile
*p
,
225 uint src0
, uint src1
, uint src2
);
227 extern uint
i915_emit_decl(struct i915_fp_compile
*p
,
228 uint type
, uint nr
, uint d0_flags
);
231 extern uint
i915_emit_const1f(struct i915_fp_compile
*p
, float c0
);
233 extern uint
i915_emit_const2f(struct i915_fp_compile
*p
,
236 extern uint
i915_emit_const4fv(struct i915_fp_compile
*p
,
239 extern uint
i915_emit_const4f(struct i915_fp_compile
*p
,
244 /*======================================================================
247 extern void i915_disassemble_program(const uint
* program
, uint sz
);
250 /*======================================================================
251 * i915_fpc_translate.c
255 i915_program_error(struct i915_fp_compile
*p
, const char *msg
);
258 i915_translate_fragment_program(struct i915_context
*i915
);