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"
27 #include "radeon_nqssadce.h"
28 #include "radeon_program_alu.h"
29 #include "r300_fragprog.h"
30 #include "r300_fragprog_swizzle.h"
31 #include "r500_fragprog.h"
34 static void nqssadce_init(struct nqssadce_state
* s
)
36 struct r300_fragment_program_compiler
* c
= s
->UserData
;
37 s
->Outputs
[c
->OutputColor
].Sourced
= RC_MASK_XYZW
;
38 s
->Outputs
[c
->OutputDepth
].Sourced
= RC_MASK_W
;
41 static void rewrite_depth_out(struct r300_fragment_program_compiler
* c
)
43 struct rc_instruction
*rci
;
45 for (rci
= c
->Base
.Program
.Instructions
.Next
; rci
!= &c
->Base
.Program
.Instructions
; rci
= rci
->Next
) {
46 struct rc_sub_instruction
* inst
= &rci
->I
;
48 if (inst
->DstReg
.File
!= RC_FILE_OUTPUT
|| inst
->DstReg
.Index
!= c
->OutputDepth
)
51 if (inst
->DstReg
.WriteMask
& RC_MASK_Z
) {
52 inst
->DstReg
.WriteMask
= RC_MASK_W
;
54 inst
->DstReg
.WriteMask
= 0;
58 switch (inst
->Opcode
) {
61 inst
->SrcReg
[0] = lmul_swizzle(RC_SWIZZLE_ZZZZ
, inst
->SrcReg
[0]);
67 inst
->SrcReg
[0] = lmul_swizzle(RC_SWIZZLE_ZZZZ
, inst
->SrcReg
[0]);
68 inst
->SrcReg
[1] = lmul_swizzle(RC_SWIZZLE_ZZZZ
, inst
->SrcReg
[1]);
72 inst
->SrcReg
[0] = lmul_swizzle(RC_SWIZZLE_ZZZZ
, inst
->SrcReg
[0]);
73 inst
->SrcReg
[1] = lmul_swizzle(RC_SWIZZLE_ZZZZ
, inst
->SrcReg
[1]);
74 inst
->SrcReg
[2] = lmul_swizzle(RC_SWIZZLE_ZZZZ
, inst
->SrcReg
[2]);
77 // Scalar instructions needn't be reswizzled
83 void r3xx_compile_fragment_program(struct r300_fragment_program_compiler
* c
)
88 struct radeon_program_transformation transformations
[] = {
89 { &r500_transform_TEX
, c
},
90 { &radeonTransformALU
, 0 },
91 { &radeonTransformDeriv
, 0 },
92 { &radeonTransformTrigScale
, 0 }
94 radeonLocalTransform(&c
->Base
, 4, transformations
);
96 struct radeon_program_transformation transformations
[] = {
97 { &r300_transform_TEX
, c
},
98 { &radeonTransformALU
, 0 },
99 { &radeonTransformTrigSimple
, 0 }
101 radeonLocalTransform(&c
->Base
, 3, transformations
);
105 fprintf(stderr
, "Fragment Program: After native rewrite:\n");
106 rc_print_program(&c
->Base
.Program
);
111 struct radeon_nqssadce_descr nqssadce
= {
112 .Init
= &nqssadce_init
,
113 .IsNativeSwizzle
= &r500FPIsNativeSwizzle
,
114 .BuildSwizzle
= &r500FPBuildSwizzle
116 radeonNqssaDce(&c
->Base
, &nqssadce
, c
);
118 struct radeon_nqssadce_descr nqssadce
= {
119 .Init
= &nqssadce_init
,
120 .IsNativeSwizzle
= &r300FPIsNativeSwizzle
,
121 .BuildSwizzle
= &r300FPBuildSwizzle
123 radeonNqssaDce(&c
->Base
, &nqssadce
, c
);
127 fprintf(stderr
, "Compiler: after NqSSA-DCE:\n");
128 rc_print_program(&c
->Base
.Program
);
133 r500BuildFragmentProgramHwCode(c
);
135 r300BuildFragmentProgramHwCode(c
);
138 rc_constants_copy(&c
->code
->constants
, &c
->Base
.Program
.Constants
);
142 r500FragmentProgramDump(c
->code
);
144 r300FragmentProgramDump(c
->code
);