• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
3  * Copyright 2013 Christoph Bumiller
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * on the rights to use, copy, modify, merge, publish, distribute, sub
9  * license, and/or sell copies of the Software, and to permit persons to whom
10  * the Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22  * USE OR OTHER DEALINGS IN THE SOFTWARE. */
23 
24 #include "device9.h"
25 #include "nine_pipe.h"
26 
27 #include "cso_cache/cso_context.h"
28 
29 void
nine_convert_dsa_state(struct pipe_depth_stencil_alpha_state * dsa_state,const DWORD * rs)30 nine_convert_dsa_state(struct pipe_depth_stencil_alpha_state *dsa_state,
31                        const DWORD *rs)
32 {
33     struct pipe_depth_stencil_alpha_state dsa;
34 
35     memset(&dsa, 0, sizeof(dsa)); /* memcmp safety */
36 
37     if (rs[D3DRS_ZENABLE]) {
38         dsa.depth.enabled = 1;
39         dsa.depth.func = d3dcmpfunc_to_pipe_func(rs[D3DRS_ZFUNC]);
40         /* Disable depth write if no change can occur */
41         dsa.depth.writemask = !!rs[D3DRS_ZWRITEENABLE] &&
42             dsa.depth.func != PIPE_FUNC_EQUAL &&
43             dsa.depth.func != PIPE_FUNC_NEVER;
44     }
45 
46     if (rs[D3DRS_STENCILENABLE]) {
47         dsa.stencil[0].enabled = 1;
48         dsa.stencil[0].func = d3dcmpfunc_to_pipe_func(rs[D3DRS_STENCILFUNC]);
49         dsa.stencil[0].fail_op = d3dstencilop_to_pipe_stencil_op(rs[D3DRS_STENCILFAIL]);
50         dsa.stencil[0].zpass_op = d3dstencilop_to_pipe_stencil_op(rs[D3DRS_STENCILPASS]);
51         dsa.stencil[0].zfail_op = d3dstencilop_to_pipe_stencil_op(rs[D3DRS_STENCILZFAIL]);
52         dsa.stencil[0].valuemask = rs[D3DRS_STENCILMASK];
53         dsa.stencil[0].writemask = rs[D3DRS_STENCILWRITEMASK];
54 
55         if (rs[D3DRS_TWOSIDEDSTENCILMODE]) {
56             dsa.stencil[1].enabled = 1;
57             dsa.stencil[1].func = d3dcmpfunc_to_pipe_func(rs[D3DRS_CCW_STENCILFUNC]);
58             dsa.stencil[1].fail_op = d3dstencilop_to_pipe_stencil_op(rs[D3DRS_CCW_STENCILFAIL]);
59             dsa.stencil[1].zpass_op = d3dstencilop_to_pipe_stencil_op(rs[D3DRS_CCW_STENCILPASS]);
60             dsa.stencil[1].zfail_op = d3dstencilop_to_pipe_stencil_op(rs[D3DRS_CCW_STENCILZFAIL]);
61             dsa.stencil[1].valuemask = dsa.stencil[0].valuemask;
62             dsa.stencil[1].writemask = dsa.stencil[0].writemask;
63         }
64     }
65 
66     if (rs[D3DRS_ALPHATESTENABLE]) {
67         dsa.alpha.enabled = 1;
68         dsa.alpha.func = d3dcmpfunc_to_pipe_func(rs[D3DRS_ALPHAFUNC]);
69         dsa.alpha.ref_value = (float)rs[D3DRS_ALPHAREF] / 255.0f;
70     }
71 
72     *dsa_state = dsa;
73 }
74 
75 void
nine_convert_rasterizer_state(struct NineDevice9 * device,struct pipe_rasterizer_state * rast_state,const DWORD * rs)76 nine_convert_rasterizer_state(struct NineDevice9 *device,
77                               struct pipe_rasterizer_state *rast_state,
78                               const DWORD *rs)
79 {
80     struct pipe_rasterizer_state rast;
81 
82     memset(&rast, 0, sizeof(rast));
83 
84     rast.flatshade = rs[D3DRS_SHADEMODE] == D3DSHADE_FLAT;
85  /* rast.light_twoside = 0; */
86  /* rast.clamp_fragment_color = 0; */
87  /* rast.clamp_vertex_color = 0; */
88  /* rast.front_ccw = 0; */
89     rast.cull_face = d3dcull_to_pipe_face(rs[D3DRS_CULLMODE]);
90     rast.fill_front = d3dfillmode_to_pipe_polygon_mode(rs[D3DRS_FILLMODE]);
91     rast.fill_back = rast.fill_front;
92     rast.offset_tri = !!(rs[D3DRS_DEPTHBIAS] | rs[D3DRS_SLOPESCALEDEPTHBIAS]);
93     rast.offset_line = rast.offset_tri; /* triangles in wireframe mode */
94     rast.offset_point = 0; /* XXX ? */
95     rast.scissor = !!rs[D3DRS_SCISSORTESTENABLE];
96  /* rast.poly_smooth = 0; */
97  /* rast.poly_stipple_enable = 0; */
98  /* rast.point_smooth = 0; */
99     rast.sprite_coord_mode = PIPE_SPRITE_COORD_UPPER_LEFT;
100     rast.point_quad_rasterization = 1;
101     rast.point_size_per_vertex = rs[NINED3DRS_VSPOINTSIZE];
102     rast.multisample = rs[NINED3DRS_MULTISAMPLE];
103     rast.line_smooth = !!rs[D3DRS_ANTIALIASEDLINEENABLE];
104  /* rast.line_stipple_enable = 0; */
105     rast.line_last_pixel = !!rs[D3DRS_LASTPIXEL];
106     rast.flatshade_first = 1;
107  /* rast.half_pixel_center = 0; */
108  /* rast.lower_left_origin = 0; */
109  /* rast.bottom_edge_rule = 0; */
110  /* rast.rasterizer_discard = 0; */
111     rast.depth_clip_near = 1;
112     rast.depth_clip_far = 1;
113     rast.clip_halfz = 1;
114     rast.clip_plane_enable = rs[D3DRS_CLIPPLANEENABLE];
115  /* rast.line_stipple_factor = 0; */
116  /* rast.line_stipple_pattern = 0; */
117     rast.sprite_coord_enable = rs[D3DRS_POINTSPRITEENABLE] ? 0xff : 0x00;
118     rast.line_width = 1.0f;
119     if (rs[NINED3DRS_VSPOINTSIZE]) {
120         rast.point_size = 1.0f;
121     } else {
122         rast.point_size = CLAMP(asfloat(rs[D3DRS_POINTSIZE]),
123                 asfloat(rs[D3DRS_POINTSIZE_MIN]),
124                 asfloat(rs[D3DRS_POINTSIZE_MAX]));
125     }
126     /* offset_units has the ogl/d3d11 meaning.
127      * d3d9: offset = scale * dz + bias
128      * ogl/d3d11: offset = scale * dz + r * bias
129      * with r implementation dependent (+ different formula for float depth
130      * buffers). r=2^-23 is often the right value for gallium drivers.
131      * If possible, use offset_units_unscaled, which gives the d3d9
132      * behaviour, else scale by 1 << 23 */
133     rast.offset_units = asfloat(rs[D3DRS_DEPTHBIAS]) * (device->driver_caps.offset_units_unscaled ? 1.0f : (float)(1 << 23));
134     rast.offset_units_unscaled = device->driver_caps.offset_units_unscaled;
135     rast.offset_scale = asfloat(rs[D3DRS_SLOPESCALEDEPTHBIAS]);
136  /* rast.offset_clamp = 0.0f; */
137 
138     *rast_state = rast;
139 }
140 
141 static inline void
nine_convert_blend_state_fixup(struct pipe_blend_state * blend,const DWORD * rs)142 nine_convert_blend_state_fixup(struct pipe_blend_state *blend, const DWORD *rs)
143 {
144     if (unlikely(rs[D3DRS_SRCBLEND] == D3DBLEND_BOTHSRCALPHA ||
145                  rs[D3DRS_SRCBLEND] == D3DBLEND_BOTHINVSRCALPHA)) {
146         blend->rt[0].rgb_dst_factor = (rs[D3DRS_SRCBLEND] == D3DBLEND_BOTHSRCALPHA) ?
147             PIPE_BLENDFACTOR_INV_SRC_ALPHA : PIPE_BLENDFACTOR_SRC_ALPHA;
148         if (!rs[D3DRS_SEPARATEALPHABLENDENABLE])
149             blend->rt[0].alpha_dst_factor = blend->rt[0].rgb_dst_factor;
150     } else
151     if (unlikely(rs[D3DRS_SEPARATEALPHABLENDENABLE] &&
152                  (rs[D3DRS_SRCBLENDALPHA] == D3DBLEND_BOTHSRCALPHA ||
153                   rs[D3DRS_SRCBLENDALPHA] == D3DBLEND_BOTHINVSRCALPHA))) {
154         blend->rt[0].alpha_dst_factor = (rs[D3DRS_SRCBLENDALPHA] == D3DBLEND_BOTHSRCALPHA) ?
155             PIPE_BLENDFACTOR_INV_SRC_ALPHA : PIPE_BLENDFACTOR_SRC_ALPHA;
156     }
157 }
158 
159 void
nine_convert_blend_state(struct pipe_blend_state * blend_state,const DWORD * rs)160 nine_convert_blend_state(struct pipe_blend_state *blend_state, const DWORD *rs)
161 {
162     struct pipe_blend_state blend;
163 
164     memset(&blend, 0, sizeof(blend)); /* memcmp safety */
165 
166     blend.dither = !!rs[D3DRS_DITHERENABLE];
167 
168  /* blend.alpha_to_one = 0; */
169     blend.alpha_to_coverage = rs[NINED3DRS_ALPHACOVERAGE] & 1;
170 
171     blend.rt[0].blend_enable = !!rs[D3DRS_ALPHABLENDENABLE];
172     if (blend.rt[0].blend_enable) {
173         blend.rt[0].rgb_func = d3dblendop_to_pipe_blend(rs[D3DRS_BLENDOP]);
174         blend.rt[0].rgb_src_factor = d3dblend_color_to_pipe_blendfactor(rs[D3DRS_SRCBLEND]);
175         blend.rt[0].rgb_dst_factor = d3dblend_color_to_pipe_blendfactor(rs[D3DRS_DESTBLEND]);
176         if (rs[D3DRS_SEPARATEALPHABLENDENABLE]) {
177             blend.rt[0].alpha_func = d3dblendop_to_pipe_blend(rs[D3DRS_BLENDOPALPHA]);
178             blend.rt[0].alpha_src_factor = d3dblend_alpha_to_pipe_blendfactor(rs[D3DRS_SRCBLENDALPHA]);
179             blend.rt[0].alpha_dst_factor = d3dblend_alpha_to_pipe_blendfactor(rs[D3DRS_DESTBLENDALPHA]);
180         } else {
181             /* TODO: Just copy the rgb values ? SRC1_x may differ ... */
182             blend.rt[0].alpha_func = blend.rt[0].rgb_func;
183             blend.rt[0].alpha_src_factor = d3dblend_alpha_to_pipe_blendfactor(rs[D3DRS_SRCBLEND]);
184             blend.rt[0].alpha_dst_factor = d3dblend_alpha_to_pipe_blendfactor(rs[D3DRS_DESTBLEND]);
185         }
186         nine_convert_blend_state_fixup(&blend, rs); /* for BOTH[INV]SRCALPHA */
187     }
188 
189     blend.max_rt = 3; /* Upper bound. Could be optimized to fb->nr_cbufs for example */
190     blend.rt[0].colormask = rs[D3DRS_COLORWRITEENABLE];
191 
192     if (rs[D3DRS_COLORWRITEENABLE1] != rs[D3DRS_COLORWRITEENABLE] ||
193         rs[D3DRS_COLORWRITEENABLE2] != rs[D3DRS_COLORWRITEENABLE] ||
194         rs[D3DRS_COLORWRITEENABLE3] != rs[D3DRS_COLORWRITEENABLE]) {
195         unsigned i;
196         blend.independent_blend_enable = TRUE;
197         for (i = 1; i < 4; ++i)
198             blend.rt[i] = blend.rt[0];
199         blend.rt[1].colormask = rs[D3DRS_COLORWRITEENABLE1];
200         blend.rt[2].colormask = rs[D3DRS_COLORWRITEENABLE2];
201         blend.rt[3].colormask = rs[D3DRS_COLORWRITEENABLE3];
202     }
203 
204     /* blend.force_srgb = !!rs[D3DRS_SRGBWRITEENABLE]; */
205 
206     *blend_state = blend;
207 }
208 
209 void
nine_convert_sampler_state(struct cso_context * ctx,int idx,const DWORD * ss)210 nine_convert_sampler_state(struct cso_context *ctx, int idx, const DWORD *ss)
211 {
212     struct pipe_sampler_state samp;
213 
214     assert(idx >= 0 &&
215            (idx < NINE_MAX_SAMPLERS_PS || idx >= NINE_SAMPLER_VS(0)) &&
216            (idx < NINE_MAX_SAMPLERS));
217 
218     memset(&samp, 0, sizeof(samp)); /* memcmp safety */
219 
220     if (ss[D3DSAMP_MIPFILTER] != D3DTEXF_NONE) {
221         samp.lod_bias = asfloat(ss[D3DSAMP_MIPMAPLODBIAS]);
222         samp.min_lod = ss[NINED3DSAMP_MINLOD];
223         samp.min_mip_filter = (ss[D3DSAMP_MIPFILTER] == D3DTEXF_POINT) ? PIPE_TEX_FILTER_NEAREST : PIPE_TEX_FILTER_LINEAR;
224     } else {
225         samp.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
226     }
227     samp.max_lod = 15.0f;
228 
229     if (ss[NINED3DSAMP_CUBETEX]) {
230         /* Cube textures are always clamped to edge on D3D */
231         samp.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
232         samp.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
233         samp.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
234     } else {
235         samp.wrap_s = d3dtextureaddress_to_pipe_tex_wrap(ss[D3DSAMP_ADDRESSU]);
236         samp.wrap_t = d3dtextureaddress_to_pipe_tex_wrap(ss[D3DSAMP_ADDRESSV]);
237         samp.wrap_r = d3dtextureaddress_to_pipe_tex_wrap(ss[D3DSAMP_ADDRESSW]);
238     }
239     samp.min_img_filter = (ss[D3DSAMP_MINFILTER] == D3DTEXF_POINT && !ss[NINED3DSAMP_SHADOW]) ? PIPE_TEX_FILTER_NEAREST : PIPE_TEX_FILTER_LINEAR;
240     samp.mag_img_filter = (ss[D3DSAMP_MAGFILTER] == D3DTEXF_POINT && !ss[NINED3DSAMP_SHADOW]) ? PIPE_TEX_FILTER_NEAREST : PIPE_TEX_FILTER_LINEAR;
241     if (ss[D3DSAMP_MINFILTER] == D3DTEXF_ANISOTROPIC ||
242         ss[D3DSAMP_MAGFILTER] == D3DTEXF_ANISOTROPIC)
243         samp.max_anisotropy = ss[D3DSAMP_MAXANISOTROPY];
244     samp.compare_mode = ss[NINED3DSAMP_SHADOW] ? PIPE_TEX_COMPARE_R_TO_TEXTURE : PIPE_TEX_COMPARE_NONE;
245     samp.compare_func = PIPE_FUNC_LEQUAL;
246     samp.normalized_coords = 1;
247     samp.seamless_cube_map = 0;
248     d3dcolor_to_pipe_color_union(&samp.border_color, ss[D3DSAMP_BORDERCOLOR]);
249 
250     /* see nine_state.h */
251     if (idx < NINE_MAX_SAMPLERS_PS)
252         cso_single_sampler(ctx, PIPE_SHADER_FRAGMENT, idx - NINE_SAMPLER_PS(0), &samp);
253     else
254         cso_single_sampler(ctx, PIPE_SHADER_VERTEX, idx - NINE_SAMPLER_VS(0), &samp);
255 }
256 
257 const enum pipe_format nine_d3d9_to_pipe_format_map[120] =
258 {
259    [D3DFMT_UNKNOWN]       = PIPE_FORMAT_NONE,
260    [D3DFMT_R8G8B8]        = PIPE_FORMAT_R8G8B8_UNORM,
261    [D3DFMT_A8R8G8B8]      = PIPE_FORMAT_B8G8R8A8_UNORM,
262    [D3DFMT_X8R8G8B8]      = PIPE_FORMAT_B8G8R8X8_UNORM,
263    [D3DFMT_R5G6B5]        = PIPE_FORMAT_B5G6R5_UNORM,
264    [D3DFMT_X1R5G5B5]      = PIPE_FORMAT_B5G5R5X1_UNORM,
265    [D3DFMT_A1R5G5B5]      = PIPE_FORMAT_B5G5R5A1_UNORM,
266    [D3DFMT_A4R4G4B4]      = PIPE_FORMAT_B4G4R4A4_UNORM,
267    [D3DFMT_R3G3B2]        = PIPE_FORMAT_B2G3R3_UNORM,
268    [D3DFMT_A8]            = PIPE_FORMAT_A8_UNORM,
269    [D3DFMT_A8R3G3B2]      = PIPE_FORMAT_NONE,
270    [D3DFMT_X4R4G4B4]      = PIPE_FORMAT_B4G4R4X4_UNORM,
271    [D3DFMT_A2B10G10R10]   = PIPE_FORMAT_R10G10B10A2_UNORM,
272    [D3DFMT_A8B8G8R8]      = PIPE_FORMAT_R8G8B8A8_UNORM,
273    [D3DFMT_X8B8G8R8]      = PIPE_FORMAT_R8G8B8X8_UNORM,
274    [D3DFMT_G16R16]        = PIPE_FORMAT_R16G16_UNORM,
275    [D3DFMT_A2R10G10B10]   = PIPE_FORMAT_B10G10R10A2_UNORM,
276    [D3DFMT_A16B16G16R16]  = PIPE_FORMAT_R16G16B16A16_UNORM,
277    [D3DFMT_A8P8]          = PIPE_FORMAT_NONE,
278    [D3DFMT_P8]            = PIPE_FORMAT_NONE,
279    [D3DFMT_L8]            = PIPE_FORMAT_L8_UNORM,
280    [D3DFMT_A8L8]          = PIPE_FORMAT_L8A8_UNORM,
281    [D3DFMT_A4L4]          = PIPE_FORMAT_L4A4_UNORM,
282    [D3DFMT_V8U8]          = PIPE_FORMAT_R8G8_SNORM,
283    [D3DFMT_L6V5U5]        = PIPE_FORMAT_NONE, /* Should be PIPE_FORMAT_R5SG5SB6U_NORM, but interpretation of the data differs a bit. */
284    [D3DFMT_X8L8V8U8]      = PIPE_FORMAT_R8SG8SB8UX8U_NORM,
285    [D3DFMT_Q8W8V8U8]      = PIPE_FORMAT_R8G8B8A8_SNORM,
286    [D3DFMT_V16U16]        = PIPE_FORMAT_R16G16_SNORM,
287    [D3DFMT_A2W10V10U10]   = PIPE_FORMAT_R10SG10SB10SA2U_NORM,
288    [D3DFMT_D16_LOCKABLE]  = PIPE_FORMAT_Z16_UNORM,
289    [D3DFMT_D32]           = PIPE_FORMAT_Z32_UNORM,
290    [D3DFMT_D15S1]         = PIPE_FORMAT_NONE,
291    [D3DFMT_D24S8]         = PIPE_FORMAT_S8_UINT_Z24_UNORM,
292    [D3DFMT_D24X8]         = PIPE_FORMAT_X8Z24_UNORM,
293    [D3DFMT_D24X4S4]       = PIPE_FORMAT_NONE,
294    [D3DFMT_D16]           = PIPE_FORMAT_Z16_UNORM,
295    [D3DFMT_D32F_LOCKABLE] = PIPE_FORMAT_Z32_FLOAT,
296    [D3DFMT_D24FS8]        = PIPE_FORMAT_Z32_FLOAT_S8X24_UINT,
297    [D3DFMT_D32_LOCKABLE]  = PIPE_FORMAT_NONE,
298    [D3DFMT_S8_LOCKABLE]   = PIPE_FORMAT_NONE,
299    [D3DFMT_L16]           = PIPE_FORMAT_L16_UNORM,
300    [D3DFMT_VERTEXDATA]    = PIPE_FORMAT_NONE,
301    [D3DFMT_INDEX16]       = PIPE_FORMAT_R16_UINT,
302    [D3DFMT_INDEX32]       = PIPE_FORMAT_R32_UINT,
303    [D3DFMT_Q16W16V16U16]  = PIPE_FORMAT_R16G16B16A16_SNORM,
304    [D3DFMT_R16F]          = PIPE_FORMAT_R16_FLOAT,
305    [D3DFMT_G16R16F]       = PIPE_FORMAT_R16G16_FLOAT,
306    [D3DFMT_A16B16G16R16F] = PIPE_FORMAT_R16G16B16A16_FLOAT,
307    [D3DFMT_R32F]          = PIPE_FORMAT_R32_FLOAT,
308    [D3DFMT_G32R32F]       = PIPE_FORMAT_R32G32_FLOAT,
309    [D3DFMT_A32B32G32R32F] = PIPE_FORMAT_R32G32B32A32_FLOAT,
310    [D3DFMT_CxV8U8]        = PIPE_FORMAT_NONE,
311    [D3DFMT_A1]            = PIPE_FORMAT_NONE,
312    [D3DFMT_A2B10G10R10_XR_BIAS] = PIPE_FORMAT_NONE,
313 };
314 
315 const D3DFORMAT nine_pipe_to_d3d9_format_map[PIPE_FORMAT_COUNT] =
316 {
317    [PIPE_FORMAT_NONE]               = D3DFMT_UNKNOWN,
318    /* TODO: rename PIPE_FORMAT_R8G8B8_UNORM to PIPE_FORMAT_B8G8R8_UNORM */
319    [PIPE_FORMAT_R8G8B8_UNORM]       = D3DFMT_R8G8B8,
320    [PIPE_FORMAT_B8G8R8A8_UNORM]     = D3DFMT_A8R8G8B8,
321    [PIPE_FORMAT_B8G8R8X8_UNORM]     = D3DFMT_X8R8G8B8,
322    [PIPE_FORMAT_B5G6R5_UNORM]       = D3DFMT_R5G6B5,
323    [PIPE_FORMAT_B5G5R5X1_UNORM]     = D3DFMT_X1R5G5B5,
324    [PIPE_FORMAT_B5G5R5A1_UNORM]     = D3DFMT_A1R5G5B5,
325    [PIPE_FORMAT_B4G4R4A4_UNORM]     = D3DFMT_A4R4G4B4,
326    [PIPE_FORMAT_B2G3R3_UNORM]       = D3DFMT_R3G3B2,
327    [PIPE_FORMAT_A8_UNORM]           = D3DFMT_A8,
328 /* [PIPE_FORMAT_B2G3R3A8_UNORM]     = D3DFMT_A8R3G3B2, */
329    [PIPE_FORMAT_B4G4R4X4_UNORM]     = D3DFMT_X4R4G4B4,
330    [PIPE_FORMAT_R10G10B10A2_UNORM]  = D3DFMT_A2B10G10R10,
331    [PIPE_FORMAT_R8G8B8A8_UNORM]     = D3DFMT_A8B8G8R8,
332    [PIPE_FORMAT_R8G8B8X8_UNORM]     = D3DFMT_X8B8G8R8,
333    [PIPE_FORMAT_R16G16_UNORM]       = D3DFMT_G16R16,
334    [PIPE_FORMAT_B10G10R10A2_UNORM]  = D3DFMT_A2R10G10B10,
335    [PIPE_FORMAT_R16G16B16A16_UNORM] = D3DFMT_A16B16G16R16,
336 
337    [PIPE_FORMAT_R8_UINT]            = D3DFMT_P8,
338    [PIPE_FORMAT_R8A8_UINT]          = D3DFMT_A8P8,
339 
340    [PIPE_FORMAT_L8_UNORM]           = D3DFMT_L8,
341    [PIPE_FORMAT_L8A8_UNORM]         = D3DFMT_A8L8,
342    [PIPE_FORMAT_L4A4_UNORM]         = D3DFMT_A4L4,
343 
344    [PIPE_FORMAT_R8G8_SNORM]           = D3DFMT_V8U8,
345 /* [PIPE_FORMAT_?]                    = D3DFMT_L6V5U5, */
346 /* [PIPE_FORMAT_?]                    = D3DFMT_X8L8V8U8, */
347    [PIPE_FORMAT_R8G8B8A8_SNORM]       = D3DFMT_Q8W8V8U8,
348    [PIPE_FORMAT_R16G16_SNORM]         = D3DFMT_V16U16,
349    [PIPE_FORMAT_R10SG10SB10SA2U_NORM] = D3DFMT_A2W10V10U10,
350 
351    [PIPE_FORMAT_YUYV]               = D3DFMT_UYVY,
352 /* [PIPE_FORMAT_YUY2]               = D3DFMT_YUY2, */
353    [PIPE_FORMAT_DXT1_RGBA]          = D3DFMT_DXT1,
354 /* [PIPE_FORMAT_DXT2_RGBA]          = D3DFMT_DXT2, */
355    [PIPE_FORMAT_DXT3_RGBA]          = D3DFMT_DXT3,
356 /* [PIPE_FORMAT_DXT4_RGBA]          = D3DFMT_DXT4, */
357    [PIPE_FORMAT_DXT5_RGBA]          = D3DFMT_DXT5,
358 /* [PIPE_FORMAT_?]                  = D3DFMT_MULTI2_ARGB8, (MET) */
359    [PIPE_FORMAT_R8G8_B8G8_UNORM]    = D3DFMT_R8G8_B8G8, /* XXX: order */
360    [PIPE_FORMAT_G8R8_G8B8_UNORM]    = D3DFMT_G8R8_G8B8,
361 
362    [PIPE_FORMAT_Z16_UNORM]          = D3DFMT_D16_LOCKABLE,
363    [PIPE_FORMAT_Z32_UNORM]          = D3DFMT_D32,
364 /* [PIPE_FORMAT_Z15_UNORM_S1_UINT]  = D3DFMT_D15S1, */
365    [PIPE_FORMAT_S8_UINT_Z24_UNORM]  = D3DFMT_D24S8,
366    [PIPE_FORMAT_X8Z24_UNORM]        = D3DFMT_D24X8,
367    [PIPE_FORMAT_L16_UNORM]          = D3DFMT_L16,
368    [PIPE_FORMAT_Z32_FLOAT]          = D3DFMT_D32F_LOCKABLE,
369 /* [PIPE_FORMAT_Z24_FLOAT_S8_UINT]  = D3DFMT_D24FS8, */
370 
371    [PIPE_FORMAT_R16_UINT]           = D3DFMT_INDEX16,
372    [PIPE_FORMAT_R32_UINT]           = D3DFMT_INDEX32,
373    [PIPE_FORMAT_R16G16B16A16_SNORM] = D3DFMT_Q16W16V16U16,
374 
375    [PIPE_FORMAT_R16_FLOAT]          = D3DFMT_R16F,
376    [PIPE_FORMAT_R32_FLOAT]          = D3DFMT_R32F,
377    [PIPE_FORMAT_R16G16_FLOAT]       = D3DFMT_G16R16F,
378    [PIPE_FORMAT_R32G32_FLOAT]       = D3DFMT_G32R32F,
379    [PIPE_FORMAT_R16G16B16A16_FLOAT] = D3DFMT_A16B16G16R16F,
380    [PIPE_FORMAT_R32G32B32A32_FLOAT] = D3DFMT_A32B32G32R32F,
381 
382 /* [PIPE_FORMAT_?]                  = D3DFMT_CxV8U8, */
383 };
384