d07c171f |
1 | /* |
2 | Copyright (C) 2003 Rice1964 |
3 | |
4 | This program is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU General Public License |
6 | as published by the Free Software Foundation; either version 2 |
7 | of the License, or (at your option) any later version. |
8 | |
9 | This program is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | GNU General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU General Public License |
15 | along with this program; if not, write to the Free Software |
16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
17 | */ |
18 | |
19 | #include "Combiner.h" |
20 | #include "DirectXDecodedMux.h" |
21 | #include <algorithm> |
22 | |
23 | #ifdef min |
24 | #undef min |
25 | #endif |
26 | #ifdef max |
27 | #undef max |
28 | #endif |
29 | |
30 | //This function is called after Reformat to handel two texels in 1 cycle, D3D can not handle |
31 | //two texels in a single stage, the texels must be splited into multiple stages |
32 | void CDirectXDecodedMux::ReformatAgainWithTwoTexels(void) |
33 | { |
34 | if( CountTexels() < 2 ) |
35 | return; |
36 | |
37 | for( int i=0; i<2; i++ ) |
38 | { |
39 | N64CombinerType &m = m_n64Combiners[i]; |
40 | if( CountTexel1Cycle(m) < 2 ) |
41 | { |
42 | continue; //1st cycle does not have two texels, do nothing here |
43 | } |
44 | else |
45 | { |
46 | N64CombinerType &m2 = m_n64Combiners[i+2]; |
47 | |
48 | if( splitType[i] == CM_FMT_TYPE_A_MOD_C ) //Texel0*Texel1 |
49 | { |
50 | if( splitType[i+2] == CM_FMT_TYPE_NOT_USED ) |
51 | { |
52 | //Change Texel1*Texel0 to (SEL(tex1), MOD(tex0)) |
53 | m.d = m.a; |
54 | m.a = MUX_0; |
55 | m2.a = m.c; |
56 | m2.c = MUX_COMBINED; |
57 | m2.d = m2.b = MUX_0; |
58 | m.c = MUX_0; |
59 | splitType[i+2] = CM_FMT_TYPE_A_MOD_C; |
60 | splitType[i] = CM_FMT_TYPE_D; |
61 | } |
62 | else if( splitType[i+2] == CM_FMT_TYPE_A_MOD_C ) |
63 | { |
64 | if( m2.a == MUX_COMBINED ) |
65 | { |
66 | swap(m2.a, m2.c); |
67 | } |
68 | |
69 | if( m2.a != MUX_TEXEL0 && m2.a != MUX_TEXEL1 ) |
70 | { |
71 | //cool, we can swap m2.a to cycle1 and swap texel from cycle 1 to cycle 2 |
72 | swap(m.a, m2.a); |
73 | } |
74 | else |
75 | { |
76 | if( m.a == m2.a ) |
77 | { |
78 | swap(m.c, m2.a); |
79 | } |
80 | else |
81 | { |
82 | swap(m.a, m2.a); |
83 | } |
84 | } |
85 | } |
86 | else if( splitType[i+2] == CM_FMT_TYPE_A_MOD_C_ADD_D ) |
87 | { |
88 | if( m2.a == MUX_COMBINED ) |
89 | { |
90 | swap(m2.a, m2.c); |
91 | } |
92 | |
93 | if( m2.c == MUX_COMBINED && m2.d != MUX_COMBINED ) |
94 | { |
95 | //Cycle1: texel0*texel1 |
96 | //Cycle2: a*cmd+d |
97 | if( m2.a != MUX_TEXEL0 && m2.a != MUX_TEXEL1 ) |
98 | { |
99 | //cool, we can swap m2.a to cycle1 and swap texel from cycle 1 to cycle 2 |
100 | swap(m.a, m2.a); |
101 | } |
102 | else |
103 | { |
104 | if( m.a == m2.a ) |
105 | { |
106 | swap(m.c, m2.a); |
107 | } |
108 | else |
109 | { |
110 | swap(m.a, m2.a); |
111 | } |
112 | } |
113 | } |
114 | } |
115 | else if( splitType[i] == CM_FMT_TYPE_A_ADD_D ) //Texel0+Texel1 |
116 | { |
117 | if( splitType[i+2] == CM_FMT_TYPE_NOT_USED ) |
118 | { |
119 | //Change Texel1*Texel0 to (SEL(tex1), MOD(tex0)) |
120 | m2.a = m.d; |
121 | m2.d = MUX_COMBINED; |
122 | m2.b = m2.c = MUX_0; |
123 | m.d = m.a; |
124 | m.a = MUX_0; |
125 | splitType[i+2] = CM_FMT_TYPE_A_ADD_D; |
126 | splitType[i] = CM_FMT_TYPE_D; |
127 | } |
128 | else if( splitType[i+2] == CM_FMT_TYPE_A_ADD_D ) |
129 | { |
130 | if( m2.a == MUX_COMBINED ) |
131 | { |
132 | swap(m2.a, m2.d); |
133 | } |
134 | |
135 | if( m2.a != MUX_TEXEL0 && m2.a != MUX_TEXEL1 ) |
136 | { |
137 | swap(m2.a, m.a); |
138 | } |
139 | else |
140 | { |
141 | if( m.a == m2.a ) |
142 | { |
143 | swap(m.d, m2.a); |
144 | } |
145 | else |
146 | { |
147 | swap(m.a, m2.a); |
148 | } |
149 | } |
150 | } |
151 | } |
152 | } |
153 | |
154 | if( CountTexel1Cycle(m2) < 2 ) |
155 | { |
156 | continue; //2nd cycle does not have two texels |
157 | } |
158 | } |
159 | } |
160 | } |
161 | |
162 | void CDirectXDecodedMux::Reformat(bool do_complement) |
163 | { |
164 | DecodedMux::Reformat(do_complement); |
165 | ReformatAgainWithTwoTexels(); |
166 | mType = std::max(std::max(std::max(splitType[0], splitType[1]),splitType[2]),splitType[3]); |
167 | } |
168 | |
169 | |