2 * Copyright 2009 Nicolai Hähnle <nhaehnle@gmail.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
23 #include "radeon_compiler.h"
25 #include "shader/prog_parameter.h"
26 #include "shader/prog_print.h"
27 #include "shader/prog_statevars.h"
29 #include "radeon_nqssadce.h"
30 #include "radeon_program_alu.h"
31 #include "r300_fragprog.h"
32 #include "r300_fragprog_swizzle.h"
33 #include "r500_fragprog.h"
36 static void nqssadce_init(struct nqssadce_state
* s
)
38 struct r300_fragment_program_compiler
* c
= s
->UserData
;
39 s
->Outputs
[c
->OutputColor
].Sourced
= WRITEMASK_XYZW
;
40 s
->Outputs
[c
->OutputDepth
].Sourced
= WRITEMASK_W
;
43 static void rewrite_depth_out(struct r300_fragment_program_compiler
* c
)
45 struct rc_instruction
*rci
;
47 for (rci
= c
->Base
.Program
.Instructions
.Next
; rci
!= &c
->Base
.Program
.Instructions
; rci
= rci
->Next
) {
48 struct prog_instruction
* inst
= &rci
->I
;
50 if (inst
->DstReg
.File
!= PROGRAM_OUTPUT
|| inst
->DstReg
.Index
!= c
->OutputDepth
)
53 if (inst
->DstReg
.WriteMask
& WRITEMASK_Z
) {
54 inst
->DstReg
.WriteMask
= WRITEMASK_W
;
56 inst
->DstReg
.WriteMask
= 0;
60 switch (inst
->Opcode
) {
63 inst
->SrcReg
[0] = lmul_swizzle(SWIZZLE_ZZZZ
, inst
->SrcReg
[0]);
69 inst
->SrcReg
[0] = lmul_swizzle(SWIZZLE_ZZZZ
, inst
->SrcReg
[0]);
70 inst
->SrcReg
[1] = lmul_swizzle(SWIZZLE_ZZZZ
, inst
->SrcReg
[1]);
74 inst
->SrcReg
[0] = lmul_swizzle(SWIZZLE_ZZZZ
, inst
->SrcReg
[0]);
75 inst
->SrcReg
[1] = lmul_swizzle(SWIZZLE_ZZZZ
, inst
->SrcReg
[1]);
76 inst
->SrcReg
[2] = lmul_swizzle(SWIZZLE_ZZZZ
, inst
->SrcReg
[2]);
79 // Scalar instructions needn't be reswizzled
85 void r3xx_compile_fragment_program(struct r300_fragment_program_compiler
* c
)
90 struct radeon_program_transformation transformations
[] = {
91 { &r500_transform_TEX
, c
},
92 { &radeonTransformALU
, 0 },
93 { &radeonTransformDeriv
, 0 },
94 { &radeonTransformTrigScale
, 0 }
96 radeonLocalTransform(&c
->Base
, 4, transformations
);
98 struct radeon_program_transformation transformations
[] = {
99 { &r300_transform_TEX
, c
},
100 { &radeonTransformALU
, 0 },
101 { &radeonTransformTrigSimple
, 0 }
103 radeonLocalTransform(&c
->Base
, 3, transformations
);
107 _mesa_printf("Fragment Program: After native rewrite:\n");
108 rc_print_program(&c
->Base
.Program
);
113 struct radeon_nqssadce_descr nqssadce
= {
114 .Init
= &nqssadce_init
,
115 .IsNativeSwizzle
= &r500FPIsNativeSwizzle
,
116 .BuildSwizzle
= &r500FPBuildSwizzle
118 radeonNqssaDce(&c
->Base
, &nqssadce
, c
);
120 struct radeon_nqssadce_descr nqssadce
= {
121 .Init
= &nqssadce_init
,
122 .IsNativeSwizzle
= &r300FPIsNativeSwizzle
,
123 .BuildSwizzle
= &r300FPBuildSwizzle
125 radeonNqssaDce(&c
->Base
, &nqssadce
, c
);
129 _mesa_printf("Compiler: after NqSSA-DCE:\n");
130 rc_print_program(&c
->Base
.Program
);
135 r500BuildFragmentProgramHwCode(c
);
137 r300BuildFragmentProgramHwCode(c
);
140 rc_constants_copy(&c
->code
->constants
, &c
->Base
.Program
.Constants
);
144 r500FragmentProgramDump(c
->code
);
146 r300FragmentProgramDump(c
->code
);