2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a 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, sublicense, 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
16 * portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include "r500_fragprog.h"
30 #include "radeon_nqssadce.h"
31 #include "radeon_program_alu.h"
34 static void reset_srcreg(struct prog_src_register
* reg
)
36 _mesa_bzero(reg
, sizeof(*reg
));
37 reg
->Swizzle
= SWIZZLE_NOOP
;
40 static struct prog_src_register
shadow_ambient(struct gl_program
*program
, int tmu
)
42 gl_state_index fail_value_tokens
[STATE_LENGTH
] = {
43 STATE_INTERNAL
, STATE_SHADOW_AMBIENT
, 0, 0, 0
45 struct prog_src_register reg
= { 0, };
47 fail_value_tokens
[2] = tmu
;
48 reg
.File
= PROGRAM_STATE_VAR
;
49 reg
.Index
= _mesa_add_state_reference(program
->Parameters
, fail_value_tokens
);
50 reg
.Swizzle
= SWIZZLE_WWWW
;
55 * Transform TEX, TXP, TXB, and KIL instructions in the following way:
56 * - premultiply texture coordinates for RECT
57 * - extract operand swizzles
58 * - introduce a temporary register when write masks are needed
61 static GLboolean
transform_TEX(
62 struct radeon_transform_context
*t
,
63 struct prog_instruction
* orig_inst
, void* data
)
65 struct r500_fragment_program_compiler
*compiler
=
66 (struct r500_fragment_program_compiler
*)data
;
67 struct prog_instruction inst
= *orig_inst
;
68 struct prog_instruction
* tgt
;
69 GLboolean destredirect
= GL_FALSE
;
71 if (inst
.Opcode
!= OPCODE_TEX
&&
72 inst
.Opcode
!= OPCODE_TXB
&&
73 inst
.Opcode
!= OPCODE_TXP
&&
74 inst
.Opcode
!= OPCODE_KIL
)
77 /* ARB_shadow & EXT_shadow_funcs */
78 if (inst
.Opcode
!= OPCODE_KIL
&&
79 t
->Program
->ShadowSamplers
& (1 << inst
.TexSrcUnit
)) {
80 GLuint comparefunc
= GL_NEVER
+ compiler
->fp
->state
.unit
[inst
.TexSrcUnit
].texture_compare_func
;
82 if (comparefunc
== GL_NEVER
|| comparefunc
== GL_ALWAYS
) {
83 tgt
= radeonAppendInstructions(t
->Program
, 1);
85 tgt
->Opcode
= OPCODE_MOV
;
86 tgt
->DstReg
= inst
.DstReg
;
87 if (comparefunc
== GL_ALWAYS
) {
88 tgt
->SrcReg
[0].File
= PROGRAM_BUILTIN
;
89 tgt
->SrcReg
[0].Swizzle
= SWIZZLE_1111
;
91 tgt
->SrcReg
[0] = shadow_ambient(t
->Program
, inst
.TexSrcUnit
);
96 inst
.DstReg
.File
= PROGRAM_TEMPORARY
;
97 inst
.DstReg
.Index
= radeonFindFreeTemporary(t
);
98 inst
.DstReg
.WriteMask
= WRITEMASK_XYZW
;
99 } else if (inst
.Opcode
!= OPCODE_KIL
&& inst
.DstReg
.File
!= PROGRAM_TEMPORARY
) {
100 int tempreg
= radeonFindFreeTemporary(t
);
102 inst
.DstReg
.File
= PROGRAM_TEMPORARY
;
103 inst
.DstReg
.Index
= tempreg
;
104 inst
.DstReg
.WriteMask
= WRITEMASK_XYZW
;
105 destredirect
= GL_TRUE
;
108 if (inst
.SrcReg
[0].File
!= PROGRAM_TEMPORARY
&& inst
.SrcReg
[0].File
!= PROGRAM_INPUT
) {
109 int tmpreg
= radeonFindFreeTemporary(t
);
110 tgt
= radeonAppendInstructions(t
->Program
, 1);
111 tgt
->Opcode
= OPCODE_MOV
;
112 tgt
->DstReg
.File
= PROGRAM_TEMPORARY
;
113 tgt
->DstReg
.Index
= tmpreg
;
114 tgt
->SrcReg
[0] = inst
.SrcReg
[0];
116 reset_srcreg(&inst
.SrcReg
[0]);
117 inst
.SrcReg
[0].File
= PROGRAM_TEMPORARY
;
118 inst
.SrcReg
[0].Index
= tmpreg
;
121 tgt
= radeonAppendInstructions(t
->Program
, 1);
122 _mesa_copy_instructions(tgt
, &inst
, 1);
124 if (inst
.Opcode
!= OPCODE_KIL
&&
125 t
->Program
->ShadowSamplers
& (1 << inst
.TexSrcUnit
)) {
126 GLuint comparefunc
= GL_NEVER
+ compiler
->fp
->state
.unit
[inst
.TexSrcUnit
].texture_compare_func
;
127 GLuint depthmode
= compiler
->fp
->state
.unit
[inst
.TexSrcUnit
].depth_texture_mode
;
128 int rcptemp
= radeonFindFreeTemporary(t
);
131 tgt
= radeonAppendInstructions(t
->Program
, 3);
133 tgt
[0].Opcode
= OPCODE_RCP
;
134 tgt
[0].DstReg
.File
= PROGRAM_TEMPORARY
;
135 tgt
[0].DstReg
.Index
= rcptemp
;
136 tgt
[0].DstReg
.WriteMask
= WRITEMASK_W
;
137 tgt
[0].SrcReg
[0] = inst
.SrcReg
[0];
138 tgt
[0].SrcReg
[0].Swizzle
= SWIZZLE_WWWW
;
140 tgt
[1].Opcode
= OPCODE_MAD
;
141 tgt
[1].DstReg
= inst
.DstReg
;
142 tgt
[1].DstReg
.WriteMask
= orig_inst
->DstReg
.WriteMask
;
143 tgt
[1].SrcReg
[0] = inst
.SrcReg
[0];
144 tgt
[1].SrcReg
[0].Swizzle
= SWIZZLE_ZZZZ
;
145 tgt
[1].SrcReg
[1].File
= PROGRAM_TEMPORARY
;
146 tgt
[1].SrcReg
[1].Index
= rcptemp
;
147 tgt
[1].SrcReg
[1].Swizzle
= SWIZZLE_WWWW
;
148 tgt
[1].SrcReg
[2].File
= PROGRAM_TEMPORARY
;
149 tgt
[1].SrcReg
[2].Index
= inst
.DstReg
.Index
;
150 if (depthmode
== 0) /* GL_LUMINANCE */
151 tgt
[1].SrcReg
[2].Swizzle
= MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_Z
, SWIZZLE_Z
);
152 else if (depthmode
== 2) /* GL_ALPHA */
153 tgt
[1].SrcReg
[2].Swizzle
= SWIZZLE_WWWW
;
155 /* Recall that SrcReg[0] is tex, SrcReg[2] is r and:
156 * r < tex <=> -tex+r < 0
157 * r >= tex <=> not (-tex+r < 0 */
158 if (comparefunc
== GL_LESS
|| comparefunc
== GL_GEQUAL
)
159 tgt
[1].SrcReg
[2].Negate
= tgt
[0].SrcReg
[2].Negate
^ NEGATE_XYZW
;
161 tgt
[1].SrcReg
[0].Negate
= tgt
[0].SrcReg
[0].Negate
^ NEGATE_XYZW
;
163 tgt
[2].Opcode
= OPCODE_CMP
;
164 tgt
[2].DstReg
= orig_inst
->DstReg
;
165 tgt
[2].SrcReg
[0].File
= PROGRAM_TEMPORARY
;
166 tgt
[2].SrcReg
[0].Index
= tgt
[1].DstReg
.Index
;
168 if (comparefunc
== GL_LESS
|| comparefunc
== GL_GREATER
) {
176 tgt
[2].SrcReg
[pass
].File
= PROGRAM_BUILTIN
;
177 tgt
[2].SrcReg
[pass
].Swizzle
= SWIZZLE_1111
;
178 tgt
[2].SrcReg
[fail
] = shadow_ambient(t
->Program
, inst
.TexSrcUnit
);
179 } else if (destredirect
) {
180 tgt
= radeonAppendInstructions(t
->Program
, 1);
182 tgt
->Opcode
= OPCODE_MOV
;
183 tgt
->DstReg
= orig_inst
->DstReg
;
184 tgt
->SrcReg
[0].File
= PROGRAM_TEMPORARY
;
185 tgt
->SrcReg
[0].Index
= inst
.DstReg
.Index
;
192 static void update_params(r300ContextPtr r300
, struct r500_fragment_program
*fp
)
194 struct gl_fragment_program
*mp
= &fp
->mesa_program
;
196 /* Ask Mesa nicely to fill in ParameterValues for us */
197 if (mp
->Base
.Parameters
)
198 _mesa_load_state_parameters(r300
->radeon
.glCtx
, mp
->Base
.Parameters
);
203 * Transform the program to support fragment.position.
205 * Introduce a small fragment at the start of the program that will be
206 * the only code that directly reads the FRAG_ATTRIB_WPOS input.
207 * All other code pieces that reference that input will be rewritten
208 * to read from a newly allocated temporary.
210 * \todo if/when r5xx supports the radeon_program architecture, this is a
211 * likely candidate for code sharing.
213 static void insert_WPOS_trailer(struct r500_fragment_program_compiler
*compiler
)
215 GLuint InputsRead
= compiler
->fp
->mesa_program
.Base
.InputsRead
;
217 if (!(InputsRead
& FRAG_BIT_WPOS
))
220 static gl_state_index tokens
[STATE_LENGTH
] = {
221 STATE_INTERNAL
, STATE_R300_WINDOW_DIMENSION
, 0, 0, 0
223 struct prog_instruction
*fpi
;
226 GLuint tempregi
= _mesa_find_free_register(compiler
->program
, PROGRAM_TEMPORARY
);
228 _mesa_insert_instructions(compiler
->program
, 0, 3);
229 fpi
= compiler
->program
->Instructions
;
231 /* perspective divide */
232 fpi
[i
].Opcode
= OPCODE_RCP
;
234 fpi
[i
].DstReg
.File
= PROGRAM_TEMPORARY
;
235 fpi
[i
].DstReg
.Index
= tempregi
;
236 fpi
[i
].DstReg
.WriteMask
= WRITEMASK_W
;
237 fpi
[i
].DstReg
.CondMask
= COND_TR
;
239 fpi
[i
].SrcReg
[0].File
= PROGRAM_INPUT
;
240 fpi
[i
].SrcReg
[0].Index
= FRAG_ATTRIB_WPOS
;
241 fpi
[i
].SrcReg
[0].Swizzle
= SWIZZLE_WWWW
;
244 fpi
[i
].Opcode
= OPCODE_MUL
;
246 fpi
[i
].DstReg
.File
= PROGRAM_TEMPORARY
;
247 fpi
[i
].DstReg
.Index
= tempregi
;
248 fpi
[i
].DstReg
.WriteMask
= WRITEMASK_XYZ
;
249 fpi
[i
].DstReg
.CondMask
= COND_TR
;
251 fpi
[i
].SrcReg
[0].File
= PROGRAM_INPUT
;
252 fpi
[i
].SrcReg
[0].Index
= FRAG_ATTRIB_WPOS
;
253 fpi
[i
].SrcReg
[0].Swizzle
= SWIZZLE_XYZW
;
255 fpi
[i
].SrcReg
[1].File
= PROGRAM_TEMPORARY
;
256 fpi
[i
].SrcReg
[1].Index
= tempregi
;
257 fpi
[i
].SrcReg
[1].Swizzle
= SWIZZLE_WWWW
;
260 /* viewport transformation */
261 window_index
= _mesa_add_state_reference(compiler
->program
->Parameters
, tokens
);
263 fpi
[i
].Opcode
= OPCODE_MAD
;
265 fpi
[i
].DstReg
.File
= PROGRAM_TEMPORARY
;
266 fpi
[i
].DstReg
.Index
= tempregi
;
267 fpi
[i
].DstReg
.WriteMask
= WRITEMASK_XYZ
;
268 fpi
[i
].DstReg
.CondMask
= COND_TR
;
270 fpi
[i
].SrcReg
[0].File
= PROGRAM_TEMPORARY
;
271 fpi
[i
].SrcReg
[0].Index
= tempregi
;
272 fpi
[i
].SrcReg
[0].Swizzle
=
273 MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_Z
, SWIZZLE_ZERO
);
275 fpi
[i
].SrcReg
[1].File
= PROGRAM_STATE_VAR
;
276 fpi
[i
].SrcReg
[1].Index
= window_index
;
277 fpi
[i
].SrcReg
[1].Swizzle
=
278 MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_Z
, SWIZZLE_ZERO
);
280 fpi
[i
].SrcReg
[2].File
= PROGRAM_STATE_VAR
;
281 fpi
[i
].SrcReg
[2].Index
= window_index
;
282 fpi
[i
].SrcReg
[2].Swizzle
=
283 MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_Z
, SWIZZLE_ZERO
);
286 for (; i
< compiler
->program
->NumInstructions
; ++i
) {
288 for (reg
= 0; reg
< 3; reg
++) {
289 if (fpi
[i
].SrcReg
[reg
].File
== PROGRAM_INPUT
&&
290 fpi
[i
].SrcReg
[reg
].Index
== FRAG_ATTRIB_WPOS
) {
291 fpi
[i
].SrcReg
[reg
].File
= PROGRAM_TEMPORARY
;
292 fpi
[i
].SrcReg
[reg
].Index
= tempregi
;
299 static void nqssadce_init(struct nqssadce_state
* s
)
301 s
->Outputs
[FRAG_RESULT_COLOR
].Sourced
= WRITEMASK_XYZW
;
302 s
->Outputs
[FRAG_RESULT_DEPTH
].Sourced
= WRITEMASK_W
;
305 static GLboolean
is_native_swizzle(GLuint opcode
, struct prog_src_register reg
)
310 if (opcode
== OPCODE_TEX
||
311 opcode
== OPCODE_TXB
||
312 opcode
== OPCODE_TXP
||
313 opcode
== OPCODE_KIL
) {
318 reg
.Negate
^= NEGATE_XYZW
;
320 if (opcode
== OPCODE_KIL
) {
321 if (reg
.Swizzle
!= SWIZZLE_NOOP
)
324 for(i
= 0; i
< 4; ++i
) {
325 GLuint swz
= GET_SWZ(reg
.Swizzle
, i
);
326 if (swz
== SWIZZLE_NIL
) {
327 reg
.Negate
&= ~(1 << i
);
339 } else if (opcode
== OPCODE_DDX
|| opcode
== OPCODE_DDY
) {
340 /* DDX/MDH and DDY/MDV explicitly ignore incoming swizzles;
341 * if it doesn't fit perfectly into a .xyzw case... */
342 if (reg
.Swizzle
== SWIZZLE_NOOP
&& !reg
.Abs
&& !reg
.Negate
)
347 /* ALU instructions support almost everything */
352 for(i
= 0; i
< 3; ++i
) {
353 GLuint swz
= GET_SWZ(reg
.Swizzle
, i
);
354 if (swz
!= SWIZZLE_NIL
&& swz
!= SWIZZLE_ZERO
)
357 if ((reg
.Negate
& relevant
) && ((reg
.Negate
& relevant
) != relevant
))
365 * Implement a MOV with a potentially non-native swizzle.
367 * The only thing we *cannot* do in an ALU instruction is per-component
368 * negation. Therefore, we split the MOV into two instructions when necessary.
370 static void nqssadce_build_swizzle(struct nqssadce_state
*s
,
371 struct prog_dst_register dst
, struct prog_src_register src
)
373 struct prog_instruction
*inst
;
374 GLuint negatebase
[2] = { 0, 0 };
377 for(i
= 0; i
< 4; ++i
) {
378 GLuint swz
= GET_SWZ(src
.Swizzle
, i
);
379 if (swz
== SWIZZLE_NIL
)
381 negatebase
[GET_BIT(src
.Negate
, i
)] |= 1 << i
;
384 _mesa_insert_instructions(s
->Program
, s
->IP
, (negatebase
[0] ? 1 : 0) + (negatebase
[1] ? 1 : 0));
385 inst
= s
->Program
->Instructions
+ s
->IP
;
387 for(i
= 0; i
<= 1; ++i
) {
391 inst
->Opcode
= OPCODE_MOV
;
393 inst
->DstReg
.WriteMask
= negatebase
[i
];
394 inst
->SrcReg
[0] = src
;
400 static GLuint
build_dtm(GLuint depthmode
)
404 case GL_LUMINANCE
: return 0;
405 case GL_INTENSITY
: return 1;
406 case GL_ALPHA
: return 2;
410 static GLuint
build_func(GLuint comparefunc
)
412 return comparefunc
- GL_NEVER
;
417 * Collect all external state that is relevant for compiling the given
420 static void build_state(
422 struct r500_fragment_program
*fp
,
423 struct r500_fragment_program_external_state
*state
)
427 _mesa_bzero(state
, sizeof(*state
));
429 for(unit
= 0; unit
< 16; ++unit
) {
430 if (fp
->mesa_program
.Base
.ShadowSamplers
& (1 << unit
)) {
431 struct gl_texture_object
* tex
= r300
->radeon
.glCtx
->Texture
.Unit
[unit
]._Current
;
433 state
->unit
[unit
].depth_texture_mode
= build_dtm(tex
->DepthMode
);
434 state
->unit
[unit
].texture_compare_func
= build_func(tex
->CompareFunc
);
439 static void dump_program(struct r500_fragment_program_code
*code
);
441 void r500TranslateFragmentShader(r300ContextPtr r300
,
442 struct r500_fragment_program
*fp
)
444 struct r500_fragment_program_external_state state
;
446 build_state(r300
, fp
, &state
);
447 if (_mesa_memcmp(&fp
->state
, &state
, sizeof(state
))) {
448 /* TODO: cache compiled programs */
449 fp
->translated
= GL_FALSE
;
450 _mesa_memcpy(&fp
->state
, &state
, sizeof(state
));
453 if (!fp
->translated
) {
454 struct r500_fragment_program_compiler compiler
;
456 compiler
.r300
= r300
;
458 compiler
.code
= &fp
->code
;
459 compiler
.program
= _mesa_clone_program(r300
->radeon
.glCtx
, &fp
->mesa_program
.Base
);
461 if (RADEON_DEBUG
& DEBUG_PIXEL
) {
462 _mesa_printf("Compiler: Initial program:\n");
463 _mesa_print_program(compiler
.program
);
466 insert_WPOS_trailer(&compiler
);
468 struct radeon_program_transformation transformations
[] = {
469 { &transform_TEX
, &compiler
},
470 { &radeonTransformALU
, 0 },
471 { &radeonTransformDeriv
, 0 },
472 { &radeonTransformTrigScale
, 0 }
474 radeonLocalTransform(r300
->radeon
.glCtx
, compiler
.program
,
477 if (RADEON_DEBUG
& DEBUG_PIXEL
) {
478 _mesa_printf("Compiler: after native rewrite:\n");
479 _mesa_print_program(compiler
.program
);
482 struct radeon_nqssadce_descr nqssadce
= {
483 .Init
= &nqssadce_init
,
484 .IsNativeSwizzle
= &is_native_swizzle
,
485 .BuildSwizzle
= &nqssadce_build_swizzle
,
486 .RewriteDepthOut
= GL_TRUE
488 radeonNqssaDce(r300
->radeon
.glCtx
, compiler
.program
, &nqssadce
);
490 if (RADEON_DEBUG
& DEBUG_PIXEL
) {
491 _mesa_printf("Compiler: after NqSSA-DCE:\n");
492 _mesa_print_program(compiler
.program
);
495 fp
->translated
= r500FragmentProgramEmit(&compiler
);
497 /* Subtle: Rescue any parameters that have been added during transformations */
498 _mesa_free_parameter_list(fp
->mesa_program
.Base
.Parameters
);
499 fp
->mesa_program
.Base
.Parameters
= compiler
.program
->Parameters
;
500 compiler
.program
->Parameters
= 0;
502 _mesa_reference_program(r300
->radeon
.glCtx
, &compiler
.program
, 0);
504 r300UpdateStateParameters(r300
->radeon
.glCtx
, _NEW_PROGRAM
);
506 if (RADEON_DEBUG
& DEBUG_PIXEL
) {
507 if (fp
->translated
) {
508 _mesa_printf("Machine-readable code:\n");
509 dump_program(&fp
->code
);
515 update_params(r300
, fp
);
519 static char *toswiz(int swiz_val
) {
526 case 5: return "1/2";
533 static char *toop(int op_val
)
537 case 0: str
= "MAD"; break;
538 case 1: str
= "DP3"; break;
539 case 2: str
= "DP4"; break;
540 case 3: str
= "D2A"; break;
541 case 4: str
= "MIN"; break;
542 case 5: str
= "MAX"; break;
543 case 6: str
= "Reserved"; break;
544 case 7: str
= "CND"; break;
545 case 8: str
= "CMP"; break;
546 case 9: str
= "FRC"; break;
547 case 10: str
= "SOP"; break;
548 case 11: str
= "MDH"; break;
549 case 12: str
= "MDV"; break;
554 static char *to_alpha_op(int op_val
)
558 case 0: str
= "MAD"; break;
559 case 1: str
= "DP"; break;
560 case 2: str
= "MIN"; break;
561 case 3: str
= "MAX"; break;
562 case 4: str
= "Reserved"; break;
563 case 5: str
= "CND"; break;
564 case 6: str
= "CMP"; break;
565 case 7: str
= "FRC"; break;
566 case 8: str
= "EX2"; break;
567 case 9: str
= "LN2"; break;
568 case 10: str
= "RCP"; break;
569 case 11: str
= "RSQ"; break;
570 case 12: str
= "SIN"; break;
571 case 13: str
= "COS"; break;
572 case 14: str
= "MDH"; break;
573 case 15: str
= "MDV"; break;
578 static char *to_mask(int val
)
582 case 0: str
= "NONE"; break;
583 case 1: str
= "R"; break;
584 case 2: str
= "G"; break;
585 case 3: str
= "RG"; break;
586 case 4: str
= "B"; break;
587 case 5: str
= "RB"; break;
588 case 6: str
= "GB"; break;
589 case 7: str
= "RGB"; break;
590 case 8: str
= "A"; break;
591 case 9: str
= "AR"; break;
592 case 10: str
= "AG"; break;
593 case 11: str
= "ARG"; break;
594 case 12: str
= "AB"; break;
595 case 13: str
= "ARB"; break;
596 case 14: str
= "AGB"; break;
597 case 15: str
= "ARGB"; break;
602 static char *to_texop(int val
)
605 case 0: return "NOP";
607 case 2: return "TEXKILL";
608 case 3: return "PROJ";
609 case 4: return "LODBIAS";
610 case 5: return "LOD";
611 case 6: return "DXDY";
616 static void dump_program(struct r500_fragment_program_code
*code
)
619 fprintf(stderr
, "R500 Fragment Program:\n--------\n");
626 if (code
->const_nr
) {
627 fprintf(stderr
, "--------\nConstants:\n");
628 for (n
= 0; n
< code
->const_nr
; n
++) {
629 fprintf(stderr
, "Constant %d: %i[%i]\n", n
,
630 code
->constant
[n
].File
, code
->constant
[n
].Index
);
632 fprintf(stderr
, "--------\n");
635 for (n
= 0; n
< code
->inst_end
+1; n
++) {
636 inst0
= inst
= code
->inst
[n
].inst0
;
637 fprintf(stderr
,"%d\t0:CMN_INST 0x%08x:", n
, inst
);
639 case R500_INST_TYPE_ALU
: str
= "ALU"; break;
640 case R500_INST_TYPE_OUT
: str
= "OUT"; break;
641 case R500_INST_TYPE_FC
: str
= "FC"; break;
642 case R500_INST_TYPE_TEX
: str
= "TEX"; break;
644 fprintf(stderr
,"%s %s %s %s %s ", str
,
645 inst
& R500_INST_TEX_SEM_WAIT
? "TEX_WAIT" : "",
646 inst
& R500_INST_LAST
? "LAST" : "",
647 inst
& R500_INST_NOP
? "NOP" : "",
648 inst
& R500_INST_ALU_WAIT
? "ALU WAIT" : "");
649 fprintf(stderr
,"wmask: %s omask: %s\n", to_mask((inst
>> 11) & 0xf),
650 to_mask((inst
>> 15) & 0xf));
652 switch(inst0
& 0x3) {
655 fprintf(stderr
,"\t1:RGB_ADDR 0x%08x:", code
->inst
[n
].inst1
);
656 inst
= code
->inst
[n
].inst1
;
658 fprintf(stderr
,"Addr0: %d%c, Addr1: %d%c, Addr2: %d%c, srcp:%d\n",
659 inst
& 0xff, (inst
& (1<<8)) ? 'c' : 't',
660 (inst
>> 10) & 0xff, (inst
& (1<<18)) ? 'c' : 't',
661 (inst
>> 20) & 0xff, (inst
& (1<<28)) ? 'c' : 't',
664 fprintf(stderr
,"\t2:ALPHA_ADDR 0x%08x:", code
->inst
[n
].inst2
);
665 inst
= code
->inst
[n
].inst2
;
666 fprintf(stderr
,"Addr0: %d%c, Addr1: %d%c, Addr2: %d%c, srcp:%d\n",
667 inst
& 0xff, (inst
& (1<<8)) ? 'c' : 't',
668 (inst
>> 10) & 0xff, (inst
& (1<<18)) ? 'c' : 't',
669 (inst
>> 20) & 0xff, (inst
& (1<<28)) ? 'c' : 't',
671 fprintf(stderr
,"\t3 RGB_INST: 0x%08x:", code
->inst
[n
].inst3
);
672 inst
= code
->inst
[n
].inst3
;
673 fprintf(stderr
,"rgb_A_src:%d %s/%s/%s %d rgb_B_src:%d %s/%s/%s %d\n",
674 (inst
) & 0x3, toswiz((inst
>> 2) & 0x7), toswiz((inst
>> 5) & 0x7), toswiz((inst
>> 8) & 0x7),
676 (inst
>> 13) & 0x3, toswiz((inst
>> 15) & 0x7), toswiz((inst
>> 18) & 0x7), toswiz((inst
>> 21) & 0x7),
680 fprintf(stderr
,"\t4 ALPHA_INST:0x%08x:", code
->inst
[n
].inst4
);
681 inst
= code
->inst
[n
].inst4
;
682 fprintf(stderr
,"%s dest:%d%s alp_A_src:%d %s %d alp_B_src:%d %s %d w:%d\n", to_alpha_op(inst
& 0xf),
683 (inst
>> 4) & 0x7f, inst
& (1<<11) ? "(rel)":"",
684 (inst
>> 12) & 0x3, toswiz((inst
>> 14) & 0x7), (inst
>> 17) & 0x3,
685 (inst
>> 19) & 0x3, toswiz((inst
>> 21) & 0x7), (inst
>> 24) & 0x3,
688 fprintf(stderr
,"\t5 RGBA_INST: 0x%08x:", code
->inst
[n
].inst5
);
689 inst
= code
->inst
[n
].inst5
;
690 fprintf(stderr
,"%s dest:%d%s rgb_C_src:%d %s/%s/%s %d alp_C_src:%d %s %d\n", toop(inst
& 0xf),
691 (inst
>> 4) & 0x7f, inst
& (1<<11) ? "(rel)":"",
692 (inst
>> 12) & 0x3, toswiz((inst
>> 14) & 0x7), toswiz((inst
>> 17) & 0x7), toswiz((inst
>> 20) & 0x7),
694 (inst
>> 25) & 0x3, toswiz((inst
>> 27) & 0x7), (inst
>> 30) & 0x3);
699 inst
= code
->inst
[n
].inst1
;
700 fprintf(stderr
,"\t1:TEX_INST: 0x%08x: id: %d op:%s, %s, %s %s\n", inst
, (inst
>> 16) & 0xf,
701 to_texop((inst
>> 22) & 0x7), (inst
& (1<<25)) ? "ACQ" : "",
702 (inst
& (1<<26)) ? "IGNUNC" : "", (inst
& (1<<27)) ? "UNSCALED" : "SCALED");
703 inst
= code
->inst
[n
].inst2
;
704 fprintf(stderr
,"\t2:TEX_ADDR: 0x%08x: src: %d%s %s/%s/%s/%s dst: %d%s %s/%s/%s/%s\n", inst
,
705 inst
& 127, inst
& (1<<7) ? "(rel)" : "",
706 toswiz((inst
>> 8) & 0x3), toswiz((inst
>> 10) & 0x3),
707 toswiz((inst
>> 12) & 0x3), toswiz((inst
>> 14) & 0x3),
708 (inst
>> 16) & 127, inst
& (1<<23) ? "(rel)" : "",
709 toswiz((inst
>> 24) & 0x3), toswiz((inst
>> 26) & 0x3),
710 toswiz((inst
>> 28) & 0x3), toswiz((inst
>> 30) & 0x3));
712 fprintf(stderr
,"\t3:TEX_DXDY: 0x%08x\n", code
->inst
[n
].inst3
);
715 fprintf(stderr
,"\n");