/[pcsx2_0.9.7]/trunk/plugins/zzogl-pg/opengl/Mem_Swizzle.cpp
ViewVC logotype

Annotation of /trunk/plugins/zzogl-pg/opengl/Mem_Swizzle.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (hide annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (9 years, 9 months ago) by william
File size: 7005 byte(s)
committing r3113 initial commit again...
1 william 31 /* ZeroGS KOSMOS
2     * Copyright (C) 2005-2006 zerofrog@gmail.com
3     *
4     * This program is free software; you can redistribute it and/or modify
5     * it under the terms of the GNU General Public License as published by
6     * the Free Software Foundation; either version 2 of the License, or
7     * (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 "GS.h"
20     #include "Mem.h"
21     #include "Mem_Swizzle.h"
22    
23     // special swizzle macros - which I converted to functions.
24     #ifdef ZEROGS_SSE2
25    
26     __forceinline void SwizzleBlock32(u8 *dst, u8 *src, int pitch, u32 WriteMask)
27     {
28     SwizzleBlock32_sse2(dst, src, pitch, WriteMask);
29     }
30    
31     __forceinline void SwizzleBlock16(u8 *dst, u8 *src, int pitch, u32 WriteMask)
32     {
33     SwizzleBlock16_sse2(dst, src, pitch/*, WriteMask*/);
34     }
35    
36     __forceinline void SwizzleBlock8(u8 *dst, u8 *src, int pitch, u32 WriteMask)
37     {
38     SwizzleBlock8_sse2(dst, src, pitch/*, WriteMask*/);
39     }
40    
41     __forceinline void SwizzleBlock4(u8 *dst, u8 *src, int pitch, u32 WriteMask)
42     {
43     SwizzleBlock4_sse2(dst, src, pitch/*, WriteMask*/);
44     }
45    
46     __forceinline void SwizzleBlock32u(u8 *dst, u8 *src, int pitch, u32 WriteMask)
47     {
48     SwizzleBlock32u_sse2(dst, src, pitch, WriteMask);
49     }
50    
51     __forceinline void SwizzleBlock16u(u8 *dst, u8 *src, int pitch, u32 WriteMask)
52     {
53     SwizzleBlock16u_sse2(dst, src, pitch/*, WriteMask*/);
54     }
55    
56     __forceinline void SwizzleBlock8u(u8 *dst, u8 *src, int pitch, u32 WriteMask)
57     {
58     SwizzleBlock8u_sse2(dst, src, pitch/*, WriteMask*/);
59     }
60    
61     __forceinline void SwizzleBlock4u(u8 *dst, u8 *src, int pitch, u32 WriteMask)
62     {
63     SwizzleBlock4u_sse2(dst, src, pitch/*, WriteMask*/);
64     }
65    
66     #else
67    
68     __forceinline void SwizzleBlock32(u8 *dst, u8 *src, int pitch, u32 WriteMask)
69     {
70     SwizzleBlock32_c(dst, src, pitch, WriteMask);
71     }
72    
73     __forceinline void SwizzleBlock16(u8 *dst, u8 *src, int pitch, u32 WriteMask)
74     {
75     SwizzleBlock16_c(dst, src, pitch/*, WriteMask*/);
76     }
77    
78     __forceinline void SwizzleBlock8(u8 *dst, u8 *src, int pitch, u32 WriteMask)
79     {
80     SwizzleBlock8_c(dst, src, pitch/*, WriteMask*/);
81     }
82    
83     __forceinline void SwizzleBlock4(u8 *dst, u8 *src, int pitch, u32 WriteMask)
84     {
85     SwizzleBlock4_c(dst, src, pitch/*, WriteMask*/);
86     }
87    
88     __forceinline void SwizzleBlock32u(u8 *dst, u8 *src, int pitch, u32 WriteMask)
89     {
90     SwizzleBlock32_c(dst, src, pitch, WriteMask);
91     }
92    
93     __forceinline void SwizzleBlock16u(u8 *dst, u8 *src, int pitch, u32 WriteMask)
94     {
95     SwizzleBlock16_c(dst, src, pitch/*, WriteMask*/);
96     }
97    
98     __forceinline void SwizzleBlock8u(u8 *dst, u8 *src, int pitch, u32 WriteMask)
99     {
100     SwizzleBlock8_c(dst, src, pitch/*, WriteMask*/);
101     }
102    
103     __forceinline void SwizzleBlock4u(u8 *dst, u8 *src, int pitch, u32 WriteMask)
104     {
105     SwizzleBlock4_c(dst, src, pitch/*, WriteMask*/);
106     }
107    
108     __forceinline void __fastcall SwizzleBlock32_c(u8* dst, u8* src, int srcpitch, u32 WriteMask)
109     {
110     u32* d = &g_columnTable32[0][0];
111    
112     if (WriteMask == 0xffffffff)
113     {
114     for (int j = 0; j < 8; j++, d += 8, src += srcpitch)
115     for (int i = 0; i < 8; i++)
116     ((u32*)dst)[d[i]] = ((u32*)src)[i];
117     }
118     else
119     {
120     for (int j = 0; j < 8; j++, d += 8, src += srcpitch)
121     for (int i = 0; i < 8; i++)
122     ((u32*)dst)[d[i]] = (((u32*)dst)[d[i]] & ~WriteMask) | (((u32*)src)[i] & WriteMask);
123     }
124     }
125    
126    
127     __forceinline void __fastcall SwizzleBlock24_c(u8* dst, u8* src, int srcpitch, u32 WriteMask)
128     {
129     u32* d = &g_columnTable32[0][0];
130    
131     if (WriteMask == 0x00ffffff)
132     {
133     for (int j = 0; j < 8; j++, d += 8, src += srcpitch)
134     for (int i = 0; i < 8; i++)
135     ((u32*)dst)[d[i]] = ((u32*)src)[i];
136     }
137     else
138     {
139     for (int j = 0; j < 8; j++, d += 8, src += srcpitch)
140     for (int i = 0; i < 8; i++)
141     ((u32*)dst)[d[i]] = (((u32*)dst)[d[i]] & ~WriteMask) | (((u32*)src)[i] & WriteMask);
142     }
143     }
144    
145     __forceinline void __fastcall SwizzleBlock16_c(u8* dst, u8* src, int srcpitch, u32 WriteMask)
146     {
147     u32* d = &g_columnTable16[0][0];
148    
149     for (int j = 0; j < 8; j++, d += 16, src += srcpitch)
150     for (int i = 0; i < 16; i++)
151     ((u16*)dst)[d[i]] = ((u16*)src)[i];
152     }
153    
154     __forceinline void __fastcall SwizzleBlock8_c(u8* dst, u8* src, int srcpitch, u32 WriteMask)
155     {
156     u32* d = &g_columnTable8[0][0];
157    
158     for (int j = 0; j < 16; j++, d += 16, src += srcpitch)
159     for (int i = 0; i < 16; i++)
160     dst[d[i]] = src[i];
161     }
162    
163     __forceinline void __fastcall SwizzleBlock4_c(u8* dst, u8* src, int srcpitch, u32 WriteMask)
164     {
165     u32* d = &g_columnTable4[0][0];
166    
167     for (int j = 0; j < 16; j++, d += 32, src += srcpitch)
168     {
169     for (int i = 0; i < 32; i++)
170     {
171     u32 addr = d[i];
172     u8 c = (src[i>>1] >> ((i & 1) << 2)) & 0x0f;
173     u32 shift = (addr & 1) << 2;
174     dst[addr >> 1] = (dst[addr >> 1] & (0xf0 >> shift)) | (c << shift);
175     }
176     }
177     }
178    
179     #endif
180     __forceinline void SwizzleBlock24(u8 *dst, u8 *src, int pitch, u32 WriteMask)
181     {
182     u8* pnewsrc = src;
183     u32* pblock = tempblock;
184    
185     for (int by = 0; by < 7; ++by, pblock += 8, pnewsrc += pitch - 24)
186     {
187     for (int bx = 0; bx < 8; ++bx, pnewsrc += 3)
188     {
189     pblock[bx] = *(u32*)pnewsrc;
190     }
191     }
192    
193     for (int bx = 0; bx < 7; ++bx, pnewsrc += 3)
194     {
195     /* might be 1 byte out of bounds of GS memory */
196     pblock[bx] = *(u32*)pnewsrc;
197     }
198    
199     /* do 3 bytes for the last copy */
200     *((u8*)pblock + 28) = pnewsrc[0];
201    
202     *((u8*)pblock + 29) = pnewsrc[1];
203    
204     *((u8*)pblock + 30) = pnewsrc[2];
205    
206     SwizzleBlock32((u8*)dst, (u8*)tempblock, 32, 0x00ffffff);
207     }
208    
209     __forceinline void SwizzleBlock8H(u8 *dst, u8 *src, int pitch, u32 WriteMask)
210     {
211     u8* pnewsrc = src;
212     u32* pblock = tempblock;
213    
214     for (int by = 0; by < 8; ++by, pblock += 8, pnewsrc += pitch)
215     {
216     u32 u = *(u32*)pnewsrc;
217     pblock[0] = u << 24;
218     pblock[1] = u << 16;
219     pblock[2] = u << 8;
220     pblock[3] = u;
221     u = *(u32*)(pnewsrc + 4);
222     pblock[4] = u << 24;
223     pblock[5] = u << 16;
224     pblock[6] = u << 8;
225     pblock[7] = u;
226     }
227    
228     SwizzleBlock32((u8*)dst, (u8*)tempblock, 32, 0xff000000);
229     }
230    
231     __forceinline void SwizzleBlock4HH(u8 *dst, u8 *src, int pitch, u32 WriteMask)
232     {
233     u8* pnewsrc = src;
234     u32* pblock = tempblock;
235    
236     for (int by = 0; by < 8; ++by, pblock += 8, pnewsrc += pitch)
237     {
238     u32 u = *(u32*)pnewsrc;
239     pblock[0] = u << 28;
240     pblock[1] = u << 24;
241     pblock[2] = u << 20;
242     pblock[3] = u << 16;
243     pblock[4] = u << 12;
244     pblock[5] = u << 8;
245     pblock[6] = u << 4;
246     pblock[7] = u;
247     }
248    
249     SwizzleBlock32((u8*)dst, (u8*)tempblock, 32, 0xf0000000);
250     }
251    
252     __forceinline void SwizzleBlock4HL(u8 *dst, u8 *src, int pitch, u32 WriteMask)
253     {
254     u8* pnewsrc = src;
255     u32* pblock = tempblock;
256    
257     for (int by = 0; by < 8; ++by, pblock += 8, pnewsrc += pitch)
258     {
259     u32 u = *(u32*)pnewsrc;
260     pblock[0] = u << 24;
261     pblock[1] = u << 20;
262     pblock[2] = u << 16;
263     pblock[3] = u << 12;
264     pblock[4] = u << 8;
265     pblock[5] = u << 4;
266     pblock[6] = u;
267     pblock[7] = u >> 4;
268     }
269    
270     SwizzleBlock32((u8*)dst, (u8*)tempblock, 32, 0x0f000000);
271     }

  ViewVC Help
Powered by ViewVC 1.1.22