xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/r300/compiler/radeon_program_tex.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 2010 Corbin Simpson
3  * Copyright 2010 Marek Olšák <[email protected]>
4  * SPDX-License-Identifier: MIT
5  */
6 
7 #include "radeon_program_tex.h"
8 
9 #include "radeon_compiler_util.h"
10 
11 /* Series of transformations to be done on textures. */
12 
shadow_fail_value(struct r300_fragment_program_compiler * compiler,int tmu)13 static struct rc_src_register shadow_fail_value(struct r300_fragment_program_compiler *compiler,
14 						int tmu)
15 {
16 	struct rc_src_register reg = { 0, 0, 0, 0, 0, 0 };
17 
18 	reg.File = RC_FILE_NONE;
19 	reg.Swizzle = combine_swizzles(RC_SWIZZLE_0000,
20 				compiler->state.unit[tmu].texture_swizzle);
21 	return reg;
22 }
23 
shadow_pass_value(struct r300_fragment_program_compiler * compiler,int tmu)24 static struct rc_src_register shadow_pass_value(struct r300_fragment_program_compiler *compiler,
25 						int tmu)
26 {
27 	struct rc_src_register reg = { 0, 0, 0, 0, 0, 0 };
28 
29 	reg.File = RC_FILE_NONE;
30 	reg.Swizzle = combine_swizzles(RC_SWIZZLE_1111,
31 				compiler->state.unit[tmu].texture_swizzle);
32 	return reg;
33 }
34 
scale_texcoords(struct r300_fragment_program_compiler * compiler,struct rc_instruction * inst,unsigned state_constant)35 static void scale_texcoords(struct r300_fragment_program_compiler *compiler,
36 			    struct rc_instruction *inst,
37 			    unsigned state_constant)
38 {
39 	struct rc_instruction *inst_mov;
40 
41 	unsigned temp = rc_find_free_temporary(&compiler->Base);
42 
43 	inst_mov = rc_insert_new_instruction(&compiler->Base, inst->Prev);
44 
45 	inst_mov->U.I.Opcode = RC_OPCODE_MUL;
46 	inst_mov->U.I.DstReg.File = RC_FILE_TEMPORARY;
47 	inst_mov->U.I.DstReg.Index = temp;
48 	inst_mov->U.I.SrcReg[0] = inst->U.I.SrcReg[0];
49 	inst_mov->U.I.SrcReg[1].File = RC_FILE_CONSTANT;
50 	inst_mov->U.I.SrcReg[1].Index =
51 			rc_constants_add_state(&compiler->Base.Program.Constants,
52 					       state_constant, inst->U.I.TexSrcUnit);
53 
54 	reset_srcreg(&inst->U.I.SrcReg[0]);
55 	inst->U.I.SrcReg[0].File = RC_FILE_TEMPORARY;
56 	inst->U.I.SrcReg[0].Index = temp;
57 }
58 
projective_divide(struct r300_fragment_program_compiler * compiler,struct rc_instruction * inst)59 static void projective_divide(struct r300_fragment_program_compiler *compiler,
60 			      struct rc_instruction *inst)
61 {
62 	struct rc_instruction *inst_mul, *inst_rcp;
63 
64 	unsigned temp = rc_find_free_temporary(&compiler->Base);
65 
66 	inst_rcp = rc_insert_new_instruction(&compiler->Base, inst->Prev);
67 	inst_rcp->U.I.Opcode = RC_OPCODE_RCP;
68 	inst_rcp->U.I.DstReg.File = RC_FILE_TEMPORARY;
69 	inst_rcp->U.I.DstReg.Index = temp;
70 	inst_rcp->U.I.DstReg.WriteMask = RC_MASK_W;
71 	inst_rcp->U.I.SrcReg[0] = inst->U.I.SrcReg[0];
72 	/* Because the input can be arbitrarily swizzled,
73 	 * read the component mapped to W. */
74 	inst_rcp->U.I.SrcReg[0].Swizzle =
75 		RC_MAKE_SWIZZLE_SMEAR(GET_SWZ(inst->U.I.SrcReg[0].Swizzle, 3));
76 
77 	inst_mul = rc_insert_new_instruction(&compiler->Base, inst->Prev);
78 	inst_mul->U.I.Opcode = RC_OPCODE_MUL;
79 	inst_mul->U.I.DstReg.File = RC_FILE_TEMPORARY;
80 	inst_mul->U.I.DstReg.Index = temp;
81 	inst_mul->U.I.SrcReg[0] = inst->U.I.SrcReg[0];
82 	inst_mul->U.I.SrcReg[1].File = RC_FILE_TEMPORARY;
83 	inst_mul->U.I.SrcReg[1].Index = temp;
84 	inst_mul->U.I.SrcReg[1].Swizzle = RC_SWIZZLE_WWWW;
85 
86 	reset_srcreg(&inst->U.I.SrcReg[0]);
87 	inst->U.I.Opcode = RC_OPCODE_TEX;
88 	inst->U.I.SrcReg[0].File = RC_FILE_TEMPORARY;
89 	inst->U.I.SrcReg[0].Index = temp;
90 }
91 
92 /**
93  * Transform TEX, TXP, TXB, and KIL instructions in the following ways:
94  *  - implement texture compare (shadow extensions)
95  *  - extract non-native source / destination operands
96  *  - premultiply texture coordinates for RECT
97  *  - extract operand swizzles
98  *  - introduce a temporary register when write masks are needed
99  */
radeonTransformTEX(struct radeon_compiler * c,struct rc_instruction * inst,void * data)100 int radeonTransformTEX(
101 	struct radeon_compiler * c,
102 	struct rc_instruction * inst,
103 	void* data)
104 {
105 	struct r300_fragment_program_compiler *compiler =
106 		(struct r300_fragment_program_compiler*)data;
107 	rc_wrap_mode wrapmode = compiler->state.unit[inst->U.I.TexSrcUnit].wrap_mode;
108 	int is_rect = inst->U.I.TexSrcTarget == RC_TEXTURE_RECT;
109 
110 	if (inst->U.I.Opcode != RC_OPCODE_TEX &&
111 		inst->U.I.Opcode != RC_OPCODE_TXB &&
112 		inst->U.I.Opcode != RC_OPCODE_TXP &&
113 		inst->U.I.Opcode != RC_OPCODE_TXD &&
114 		inst->U.I.Opcode != RC_OPCODE_TXL &&
115 		inst->U.I.Opcode != RC_OPCODE_KIL)
116 		return 0;
117 
118 	/* ARB_shadow & EXT_shadow_funcs */
119 	if (inst->U.I.Opcode != RC_OPCODE_KIL &&
120 		((c->Program.ShadowSamplers & (1U << inst->U.I.TexSrcUnit)) ||
121 		 (compiler->state.unit[inst->U.I.TexSrcUnit].compare_mode_enabled))) {
122 		rc_compare_func comparefunc = compiler->state.unit[inst->U.I.TexSrcUnit].texture_compare_func;
123 
124 		if (comparefunc == RC_COMPARE_FUNC_NEVER || comparefunc == RC_COMPARE_FUNC_ALWAYS) {
125 			inst->U.I.Opcode = RC_OPCODE_MOV;
126 
127 			if (comparefunc == RC_COMPARE_FUNC_ALWAYS) {
128 				inst->U.I.SrcReg[0] = shadow_pass_value(compiler, inst->U.I.TexSrcUnit);
129 			} else {
130 				inst->U.I.SrcReg[0] = shadow_fail_value(compiler, inst->U.I.TexSrcUnit);
131 			}
132 
133 			return 1;
134 		} else {
135 			struct rc_instruction * inst_rcp = NULL;
136 			struct rc_instruction *inst_mul, *inst_add, *inst_cmp;
137 			unsigned tmp_texsample;
138 			unsigned tmp_sum;
139 			int pass, fail;
140 
141 			/* Save the output register. */
142 			struct rc_dst_register output_reg = inst->U.I.DstReg;
143 			unsigned saturate_mode = inst->U.I.SaturateMode;
144 
145 			/* Redirect TEX to a new temp. */
146 			tmp_texsample = rc_find_free_temporary(c);
147 			inst->U.I.SaturateMode = 0;
148 			inst->U.I.DstReg.File = RC_FILE_TEMPORARY;
149 			inst->U.I.DstReg.Index = tmp_texsample;
150 			inst->U.I.DstReg.WriteMask = RC_MASK_XYZW;
151 
152 			tmp_sum = rc_find_free_temporary(c);
153 
154 			if (inst->U.I.Opcode == RC_OPCODE_TXP) {
155 				/* Compute 1/W. */
156 				inst_rcp = rc_insert_new_instruction(c, inst);
157 				inst_rcp->U.I.Opcode = RC_OPCODE_RCP;
158 				inst_rcp->U.I.DstReg.File = RC_FILE_TEMPORARY;
159 				inst_rcp->U.I.DstReg.Index = tmp_sum;
160 				inst_rcp->U.I.DstReg.WriteMask = RC_MASK_W;
161 				inst_rcp->U.I.SrcReg[0] = inst->U.I.SrcReg[0];
162 				inst_rcp->U.I.SrcReg[0].Swizzle =
163 					RC_MAKE_SWIZZLE_SMEAR(GET_SWZ(inst->U.I.SrcReg[0].Swizzle, 3));
164 			}
165 
166 			/* Divide Z by W (if it's TXP) and saturate. */
167 			inst_mul = rc_insert_new_instruction(c, inst_rcp ? inst_rcp : inst);
168 			inst_mul->U.I.Opcode = inst->U.I.Opcode == RC_OPCODE_TXP ? RC_OPCODE_MUL : RC_OPCODE_MOV;
169 			inst_mul->U.I.DstReg.File = RC_FILE_TEMPORARY;
170 			inst_mul->U.I.DstReg.Index = tmp_sum;
171 			inst_mul->U.I.DstReg.WriteMask = RC_MASK_W;
172 			inst_mul->U.I.SaturateMode = RC_SATURATE_ZERO_ONE;
173 			inst_mul->U.I.SrcReg[0] = inst->U.I.SrcReg[0];
174 			inst_mul->U.I.SrcReg[0].Swizzle =
175 				RC_MAKE_SWIZZLE_SMEAR(GET_SWZ(inst->U.I.SrcReg[0].Swizzle, 2));
176 			if (inst->U.I.Opcode == RC_OPCODE_TXP) {
177 				inst_mul->U.I.SrcReg[1].File = RC_FILE_TEMPORARY;
178 				inst_mul->U.I.SrcReg[1].Index = tmp_sum;
179 				inst_mul->U.I.SrcReg[1].Swizzle = RC_SWIZZLE_WWWW;
180 			}
181 
182 			/* Add the depth texture value. */
183 			inst_add = rc_insert_new_instruction(c, inst_mul);
184 			inst_add->U.I.Opcode = RC_OPCODE_ADD;
185 			inst_add->U.I.DstReg.File = RC_FILE_TEMPORARY;
186 			inst_add->U.I.DstReg.Index = tmp_sum;
187 			inst_add->U.I.DstReg.WriteMask = RC_MASK_W;
188 			inst_add->U.I.SrcReg[0].File = RC_FILE_TEMPORARY;
189 			inst_add->U.I.SrcReg[0].Index = tmp_sum;
190 			inst_add->U.I.SrcReg[0].Swizzle = RC_SWIZZLE_WWWW;
191 			inst_add->U.I.SrcReg[1].File = RC_FILE_TEMPORARY;
192 			inst_add->U.I.SrcReg[1].Index = tmp_texsample;
193 			inst_add->U.I.SrcReg[1].Swizzle = RC_SWIZZLE_XXXX;
194 
195 			/* Note that SrcReg[0] is r, SrcReg[1] is tex and:
196 			 *   LESS:    r  < tex  <=>      -tex+r < 0
197 			 *   GEQUAL:  r >= tex  <=> not (-tex+r < 0)
198 			 *   GREATER: r  > tex  <=>       tex-r < 0
199 			 *   LEQUAL:  r <= tex  <=> not ( tex-r < 0)
200 			 *   EQUAL:   GEQUAL
201 			 *   NOTEQUAL:LESS
202 			 */
203 
204 			/* This negates either r or tex: */
205 			if (comparefunc == RC_COMPARE_FUNC_LESS || comparefunc == RC_COMPARE_FUNC_GEQUAL ||
206 			    comparefunc == RC_COMPARE_FUNC_EQUAL || comparefunc == RC_COMPARE_FUNC_NOTEQUAL)
207 				inst_add->U.I.SrcReg[1].Negate = inst_add->U.I.SrcReg[1].Negate ^ RC_MASK_XYZW;
208 			else
209 				inst_add->U.I.SrcReg[0].Negate = inst_add->U.I.SrcReg[0].Negate ^ RC_MASK_XYZW;
210 
211 			/* This negates the whole expression: */
212 			if (comparefunc == RC_COMPARE_FUNC_LESS || comparefunc == RC_COMPARE_FUNC_GREATER ||
213 			    comparefunc == RC_COMPARE_FUNC_NOTEQUAL) {
214 				pass = 1;
215 				fail = 2;
216 			} else {
217 				pass = 2;
218 				fail = 1;
219 			}
220 
221 			inst_cmp = rc_insert_new_instruction(c, inst_add);
222 			inst_cmp->U.I.Opcode = RC_OPCODE_CMP;
223 			inst_cmp->U.I.SaturateMode = saturate_mode;
224 			inst_cmp->U.I.DstReg = output_reg;
225 			inst_cmp->U.I.SrcReg[0].File = RC_FILE_TEMPORARY;
226 			inst_cmp->U.I.SrcReg[0].Index = tmp_sum;
227 			inst_cmp->U.I.SrcReg[0].Swizzle =
228 					combine_swizzles(RC_SWIZZLE_WWWW,
229 							 compiler->state.unit[inst->U.I.TexSrcUnit].texture_swizzle);
230 			inst_cmp->U.I.SrcReg[pass] = shadow_pass_value(compiler, inst->U.I.TexSrcUnit);
231 			inst_cmp->U.I.SrcReg[fail] = shadow_fail_value(compiler, inst->U.I.TexSrcUnit);
232 
233 			assert(tmp_texsample != tmp_sum);
234 		}
235 	}
236 
237 	/* R300 cannot sample from rectangles and the wrap mode fallback needs
238 	 * normalized coordinates anyway. */
239 	if (inst->U.I.Opcode != RC_OPCODE_KIL &&
240 	    is_rect && (!c->is_r500 || wrapmode != RC_WRAP_NONE)) {
241 		scale_texcoords(compiler, inst, RC_STATE_R300_TEXRECT_FACTOR);
242 		inst->U.I.TexSrcTarget = RC_TEXTURE_2D;
243 	}
244 
245 	/* Divide by W if needed. */
246 	if (inst->U.I.Opcode == RC_OPCODE_TXP &&
247 	    (wrapmode == RC_WRAP_REPEAT || wrapmode == RC_WRAP_MIRRORED_REPEAT ||
248 	     compiler->state.unit[inst->U.I.TexSrcUnit].clamp_and_scale_before_fetch)) {
249 		projective_divide(compiler, inst);
250 	}
251 
252 	/* Texture wrap modes don't work on NPOT textures.
253 	 *
254 	 * Non-wrapped/clamped texcoords with NPOT are free in HW. Repeat and
255 	 * mirroring are not. If we need to repeat, we do:
256 	 *
257 	 * MUL temp, texcoord, <scaling factor constant>
258 	 * FRC temp, temp ; Discard integer portion of coords
259 	 *
260 	 * This gives us coords in [0, 1].
261 	 *
262 	 * Mirroring is trickier. We're going to start out like repeat:
263 	 *
264 	 * MUL temp, texcoord, <scaling factor constant> ; De-mirror across axes
265 	 * MUL temp, temp, 0.5 ; Pattern repeats in [0, 2]
266 	 *                            ; so scale to [0, 1]
267 	 * FRC temp, temp ; Make the pattern repeat
268 	 * MAD temp, temp, 2, -1 ; Move the pattern to [-1, 1]
269 	 * ADD temp, 1, -abs(temp) ; Now comes a neat trick: use abs to mirror the pattern.
270 	 *				; The pattern is backwards, so reverse it (1-x).
271 	 *
272 	 * This gives us coords in [0, 1].
273 	 *
274 	 * ~ C & M. ;)
275 	 */
276 	if (inst->U.I.Opcode != RC_OPCODE_KIL &&
277 	    wrapmode != RC_WRAP_NONE) {
278 		struct rc_instruction *inst_mov;
279 		unsigned temp = rc_find_free_temporary(c);
280 
281 		if (wrapmode == RC_WRAP_REPEAT) {
282 			/* Both instructions will be paired up. */
283 			struct rc_instruction *inst_frc = rc_insert_new_instruction(c, inst->Prev);
284 
285 			inst_frc->U.I.Opcode = RC_OPCODE_FRC;
286 			inst_frc->U.I.DstReg.File = RC_FILE_TEMPORARY;
287 			inst_frc->U.I.DstReg.Index = temp;
288 			inst_frc->U.I.DstReg.WriteMask = RC_MASK_XYZ;
289 			inst_frc->U.I.SrcReg[0] = inst->U.I.SrcReg[0];
290 		} else if (wrapmode == RC_WRAP_MIRRORED_REPEAT) {
291 			/*
292 			 * Function:
293 			 *   f(v) = 1 - abs(frac(v * 0.5) * 2 - 1)
294 			 *
295 			 * Code:
296 			 *   MUL temp, src0, 0.5
297 			 *   FRC temp, temp
298 			 *   MAD temp, temp, 2, -1
299 			 *   ADD temp, 1, -abs(temp)
300 			 */
301 
302 			struct rc_instruction *inst_mul, *inst_frc, *inst_mad, *inst_add;
303 			unsigned two, two_swizzle;
304 
305 			inst_mul = rc_insert_new_instruction(c, inst->Prev);
306 
307 			inst_mul->U.I.Opcode = RC_OPCODE_MUL;
308 			inst_mul->U.I.DstReg.File = RC_FILE_TEMPORARY;
309 			inst_mul->U.I.DstReg.Index = temp;
310 			inst_mul->U.I.DstReg.WriteMask = RC_MASK_XYZ;
311 			inst_mul->U.I.SrcReg[0] = inst->U.I.SrcReg[0];
312 			inst_mul->U.I.SrcReg[1].Swizzle = RC_SWIZZLE_HHHH;
313 
314 			inst_frc = rc_insert_new_instruction(c, inst->Prev);
315 
316 			inst_frc->U.I.Opcode = RC_OPCODE_FRC;
317 			inst_frc->U.I.DstReg.File = RC_FILE_TEMPORARY;
318 			inst_frc->U.I.DstReg.Index = temp;
319 			inst_frc->U.I.DstReg.WriteMask = RC_MASK_XYZ;
320 			inst_frc->U.I.SrcReg[0].File = RC_FILE_TEMPORARY;
321 			inst_frc->U.I.SrcReg[0].Index = temp;
322 			inst_frc->U.I.SrcReg[0].Swizzle = RC_SWIZZLE_XYZ0;
323 
324 			two = rc_constants_add_immediate_scalar(&c->Program.Constants, 2, &two_swizzle);
325 			inst_mad = rc_insert_new_instruction(c, inst->Prev);
326 
327 			inst_mad->U.I.Opcode = RC_OPCODE_MAD;
328 			inst_mad->U.I.DstReg.File = RC_FILE_TEMPORARY;
329 			inst_mad->U.I.DstReg.Index = temp;
330 			inst_mad->U.I.DstReg.WriteMask = RC_MASK_XYZ;
331 			inst_mad->U.I.SrcReg[0].File = RC_FILE_TEMPORARY;
332 			inst_mad->U.I.SrcReg[0].Index = temp;
333 			inst_mad->U.I.SrcReg[0].Swizzle = RC_SWIZZLE_XYZ0;
334 			inst_mad->U.I.SrcReg[1].File = RC_FILE_CONSTANT;
335 			inst_mad->U.I.SrcReg[1].Index = two;
336 			inst_mad->U.I.SrcReg[1].Swizzle = two_swizzle;
337 			inst_mad->U.I.SrcReg[2].Swizzle = RC_SWIZZLE_1111;
338 			inst_mad->U.I.SrcReg[2].Negate = RC_MASK_XYZ;
339 
340 			inst_add = rc_insert_new_instruction(c, inst->Prev);
341 
342 			inst_add->U.I.Opcode = RC_OPCODE_ADD;
343 			inst_add->U.I.DstReg.File = RC_FILE_TEMPORARY;
344 			inst_add->U.I.DstReg.Index = temp;
345 			inst_add->U.I.DstReg.WriteMask = RC_MASK_XYZ;
346 			inst_add->U.I.SrcReg[0].Swizzle = RC_SWIZZLE_1111;
347 			inst_add->U.I.SrcReg[1].File = RC_FILE_TEMPORARY;
348 			inst_add->U.I.SrcReg[1].Index = temp;
349 			inst_add->U.I.SrcReg[1].Swizzle = RC_SWIZZLE_XYZ0;
350 			inst_add->U.I.SrcReg[1].Abs = 1;
351 			inst_add->U.I.SrcReg[1].Negate = RC_MASK_XYZ;
352 		} else if (wrapmode == RC_WRAP_MIRRORED_CLAMP) {
353 			/*
354 			 * Mirrored clamp modes are bloody simple, we just use abs
355 			 * to mirror [0, 1] into [-1, 0]. This works for
356 			 * all modes i.e. CLAMP, CLAMP_TO_EDGE, and CLAMP_TO_BORDER.
357 			 */
358 			struct rc_instruction *inst_mov;
359 
360 			inst_mov = rc_insert_new_instruction(c, inst->Prev);
361 
362 			inst_mov->U.I.Opcode = RC_OPCODE_MOV;
363 			inst_mov->U.I.DstReg.File = RC_FILE_TEMPORARY;
364 			inst_mov->U.I.DstReg.Index = temp;
365 			inst_mov->U.I.DstReg.WriteMask = RC_MASK_XYZ;
366 			inst_mov->U.I.SrcReg[0] = inst->U.I.SrcReg[0];
367 			inst_mov->U.I.SrcReg[0].Abs = 1;
368 		}
369 
370 		/* Preserve W for TXP/TXB. */
371 		inst_mov = rc_insert_new_instruction(c, inst->Prev);
372 
373 		inst_mov->U.I.Opcode = RC_OPCODE_MOV;
374 		inst_mov->U.I.DstReg.File = RC_FILE_TEMPORARY;
375 		inst_mov->U.I.DstReg.Index = temp;
376 		inst_mov->U.I.DstReg.WriteMask = RC_MASK_W;
377 		inst_mov->U.I.SrcReg[0] = inst->U.I.SrcReg[0];
378 
379 		reset_srcreg(&inst->U.I.SrcReg[0]);
380 		inst->U.I.SrcReg[0].File = RC_FILE_TEMPORARY;
381 		inst->U.I.SrcReg[0].Index = temp;
382 	}
383 
384 	/* NPOT -> POT conversion for 3D textures. */
385 	if (inst->U.I.Opcode != RC_OPCODE_KIL &&
386 	    compiler->state.unit[inst->U.I.TexSrcUnit].clamp_and_scale_before_fetch) {
387 		struct rc_instruction *inst_mov;
388 		unsigned temp = rc_find_free_temporary(c);
389 
390 		/* Saturate XYZ. */
391 		inst_mov = rc_insert_new_instruction(c, inst->Prev);
392 		inst_mov->U.I.Opcode = RC_OPCODE_MOV;
393 		inst_mov->U.I.SaturateMode = RC_SATURATE_ZERO_ONE;
394 		inst_mov->U.I.DstReg.File = RC_FILE_TEMPORARY;
395 		inst_mov->U.I.DstReg.Index = temp;
396 		inst_mov->U.I.DstReg.WriteMask = RC_MASK_XYZ;
397 		inst_mov->U.I.SrcReg[0] = inst->U.I.SrcReg[0];
398 
399 		/* Copy W. */
400 		inst_mov = rc_insert_new_instruction(c, inst->Prev);
401 		inst_mov->U.I.Opcode = RC_OPCODE_MOV;
402 		inst_mov->U.I.DstReg.File = RC_FILE_TEMPORARY;
403 		inst_mov->U.I.DstReg.Index = temp;
404 		inst_mov->U.I.DstReg.WriteMask = RC_MASK_W;
405 		inst_mov->U.I.SrcReg[0] = inst->U.I.SrcReg[0];
406 
407 		reset_srcreg(&inst->U.I.SrcReg[0]);
408 		inst->U.I.SrcReg[0].File = RC_FILE_TEMPORARY;
409 		inst->U.I.SrcReg[0].Index = temp;
410 
411 		scale_texcoords(compiler, inst, RC_STATE_R300_TEXSCALE_FACTOR);
412 	}
413 
414 	/* Cannot write texture to output registers or with saturate (all chips),
415 	 * or with masks (non-r500). */
416 	if (inst->U.I.Opcode != RC_OPCODE_KIL &&
417 		(inst->U.I.DstReg.File != RC_FILE_TEMPORARY ||
418 		 inst->U.I.SaturateMode ||
419 		 (!c->is_r500 && inst->U.I.DstReg.WriteMask != RC_MASK_XYZW))) {
420 		struct rc_instruction * inst_mov = rc_insert_new_instruction(c, inst);
421 
422 		inst_mov->U.I.Opcode = RC_OPCODE_MOV;
423 		inst_mov->U.I.SaturateMode = inst->U.I.SaturateMode;
424 		inst_mov->U.I.DstReg = inst->U.I.DstReg;
425 		inst_mov->U.I.SrcReg[0].File = RC_FILE_TEMPORARY;
426 		inst_mov->U.I.SrcReg[0].Index = rc_find_free_temporary(c);
427 
428 		inst->U.I.SaturateMode = 0;
429 		inst->U.I.DstReg.File = RC_FILE_TEMPORARY;
430 		inst->U.I.DstReg.Index = inst_mov->U.I.SrcReg[0].Index;
431 		inst->U.I.DstReg.WriteMask = RC_MASK_XYZW;
432 	}
433 
434 	/* Cannot read texture coordinate from constants file */
435 	if (inst->U.I.SrcReg[0].File != RC_FILE_TEMPORARY && inst->U.I.SrcReg[0].File != RC_FILE_INPUT) {
436 		struct rc_instruction * inst_mov = rc_insert_new_instruction(c, inst->Prev);
437 
438 		inst_mov->U.I.Opcode = RC_OPCODE_MOV;
439 		inst_mov->U.I.DstReg.File = RC_FILE_TEMPORARY;
440 		inst_mov->U.I.DstReg.Index = rc_find_free_temporary(c);
441 		inst_mov->U.I.SrcReg[0] = inst->U.I.SrcReg[0];
442 
443 		reset_srcreg(&inst->U.I.SrcReg[0]);
444 		inst->U.I.SrcReg[0].File = RC_FILE_TEMPORARY;
445 		inst->U.I.SrcReg[0].Index = inst_mov->U.I.DstReg.Index;
446 	}
447 
448 	return 1;
449 }
450