gdiplus: Set correct color space flags for grayscale images.
[wine.git] / dlls / d3d11 / utils.c
blobe919c58da452c4ee8f0d3ee3f248e6ec70627f82
1 /*
2 * Copyright 2008 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
21 #include "wine/port.h"
23 #include "d3d11_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
27 #define WINE_D3D_TO_STR(x) case x: return #x
29 const char *debug_d3d10_primitive_topology(D3D10_PRIMITIVE_TOPOLOGY topology)
31 switch (topology)
33 WINE_D3D_TO_STR(D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED);
34 WINE_D3D_TO_STR(D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
35 WINE_D3D_TO_STR(D3D10_PRIMITIVE_TOPOLOGY_LINELIST);
36 WINE_D3D_TO_STR(D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP);
37 WINE_D3D_TO_STR(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
38 WINE_D3D_TO_STR(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
39 WINE_D3D_TO_STR(D3D10_PRIMITIVE_TOPOLOGY_LINELIST_ADJ);
40 WINE_D3D_TO_STR(D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ);
41 WINE_D3D_TO_STR(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ);
42 WINE_D3D_TO_STR(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ);
43 default:
44 FIXME("Unrecognized D3D10_PRIMITIVE_TOPOLOGY %#x\n", topology);
45 return "unrecognized";
49 const char *debug_dxgi_format(DXGI_FORMAT format)
51 switch(format)
53 WINE_D3D_TO_STR(DXGI_FORMAT_UNKNOWN);
54 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32B32A32_TYPELESS);
55 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32B32A32_FLOAT);
56 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32B32A32_UINT);
57 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32B32A32_SINT);
58 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32B32_TYPELESS);
59 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32B32_FLOAT);
60 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32B32_UINT);
61 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32B32_SINT);
62 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16B16A16_TYPELESS);
63 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16B16A16_FLOAT);
64 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16B16A16_UNORM);
65 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16B16A16_UINT);
66 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16B16A16_SNORM);
67 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16B16A16_SINT);
68 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32_TYPELESS);
69 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32_FLOAT);
70 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32_UINT);
71 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32_SINT);
72 WINE_D3D_TO_STR(DXGI_FORMAT_R32G8X24_TYPELESS);
73 WINE_D3D_TO_STR(DXGI_FORMAT_D32_FLOAT_S8X24_UINT);
74 WINE_D3D_TO_STR(DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS);
75 WINE_D3D_TO_STR(DXGI_FORMAT_X32_TYPELESS_G8X24_UINT);
76 WINE_D3D_TO_STR(DXGI_FORMAT_R10G10B10A2_TYPELESS);
77 WINE_D3D_TO_STR(DXGI_FORMAT_R10G10B10A2_UNORM);
78 WINE_D3D_TO_STR(DXGI_FORMAT_R10G10B10A2_UINT);
79 WINE_D3D_TO_STR(DXGI_FORMAT_R11G11B10_FLOAT);
80 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8B8A8_TYPELESS);
81 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8B8A8_UNORM);
82 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB);
83 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8B8A8_UINT);
84 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8B8A8_SNORM);
85 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8B8A8_SINT);
86 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16_TYPELESS);
87 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16_FLOAT);
88 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16_UNORM);
89 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16_UINT);
90 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16_SNORM);
91 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16_SINT);
92 WINE_D3D_TO_STR(DXGI_FORMAT_R32_TYPELESS);
93 WINE_D3D_TO_STR(DXGI_FORMAT_D32_FLOAT);
94 WINE_D3D_TO_STR(DXGI_FORMAT_R32_FLOAT);
95 WINE_D3D_TO_STR(DXGI_FORMAT_R32_UINT);
96 WINE_D3D_TO_STR(DXGI_FORMAT_R32_SINT);
97 WINE_D3D_TO_STR(DXGI_FORMAT_R24G8_TYPELESS);
98 WINE_D3D_TO_STR(DXGI_FORMAT_D24_UNORM_S8_UINT);
99 WINE_D3D_TO_STR(DXGI_FORMAT_R24_UNORM_X8_TYPELESS);
100 WINE_D3D_TO_STR(DXGI_FORMAT_X24_TYPELESS_G8_UINT);
101 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8_TYPELESS);
102 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8_UNORM);
103 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8_UINT);
104 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8_SNORM);
105 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8_SINT);
106 WINE_D3D_TO_STR(DXGI_FORMAT_R16_TYPELESS);
107 WINE_D3D_TO_STR(DXGI_FORMAT_R16_FLOAT);
108 WINE_D3D_TO_STR(DXGI_FORMAT_D16_UNORM);
109 WINE_D3D_TO_STR(DXGI_FORMAT_R16_UNORM);
110 WINE_D3D_TO_STR(DXGI_FORMAT_R16_UINT);
111 WINE_D3D_TO_STR(DXGI_FORMAT_R16_SNORM);
112 WINE_D3D_TO_STR(DXGI_FORMAT_R16_SINT);
113 WINE_D3D_TO_STR(DXGI_FORMAT_R8_TYPELESS);
114 WINE_D3D_TO_STR(DXGI_FORMAT_R8_UNORM);
115 WINE_D3D_TO_STR(DXGI_FORMAT_R8_UINT);
116 WINE_D3D_TO_STR(DXGI_FORMAT_R8_SNORM);
117 WINE_D3D_TO_STR(DXGI_FORMAT_R8_SINT);
118 WINE_D3D_TO_STR(DXGI_FORMAT_A8_UNORM);
119 WINE_D3D_TO_STR(DXGI_FORMAT_R1_UNORM);
120 WINE_D3D_TO_STR(DXGI_FORMAT_R9G9B9E5_SHAREDEXP);
121 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8_B8G8_UNORM);
122 WINE_D3D_TO_STR(DXGI_FORMAT_G8R8_G8B8_UNORM);
123 WINE_D3D_TO_STR(DXGI_FORMAT_BC1_TYPELESS);
124 WINE_D3D_TO_STR(DXGI_FORMAT_BC1_UNORM);
125 WINE_D3D_TO_STR(DXGI_FORMAT_BC1_UNORM_SRGB);
126 WINE_D3D_TO_STR(DXGI_FORMAT_BC2_TYPELESS);
127 WINE_D3D_TO_STR(DXGI_FORMAT_BC2_UNORM);
128 WINE_D3D_TO_STR(DXGI_FORMAT_BC2_UNORM_SRGB);
129 WINE_D3D_TO_STR(DXGI_FORMAT_BC3_TYPELESS);
130 WINE_D3D_TO_STR(DXGI_FORMAT_BC3_UNORM);
131 WINE_D3D_TO_STR(DXGI_FORMAT_BC3_UNORM_SRGB);
132 WINE_D3D_TO_STR(DXGI_FORMAT_BC4_TYPELESS);
133 WINE_D3D_TO_STR(DXGI_FORMAT_BC4_UNORM);
134 WINE_D3D_TO_STR(DXGI_FORMAT_BC4_SNORM);
135 WINE_D3D_TO_STR(DXGI_FORMAT_BC5_TYPELESS);
136 WINE_D3D_TO_STR(DXGI_FORMAT_BC5_UNORM);
137 WINE_D3D_TO_STR(DXGI_FORMAT_BC5_SNORM);
138 WINE_D3D_TO_STR(DXGI_FORMAT_B5G6R5_UNORM);
139 WINE_D3D_TO_STR(DXGI_FORMAT_B5G5R5A1_UNORM);
140 WINE_D3D_TO_STR(DXGI_FORMAT_B8G8R8A8_UNORM);
141 WINE_D3D_TO_STR(DXGI_FORMAT_B8G8R8X8_UNORM);
142 WINE_D3D_TO_STR(DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM);
143 WINE_D3D_TO_STR(DXGI_FORMAT_B8G8R8A8_TYPELESS);
144 WINE_D3D_TO_STR(DXGI_FORMAT_B8G8R8A8_UNORM_SRGB);
145 WINE_D3D_TO_STR(DXGI_FORMAT_B8G8R8X8_TYPELESS);
146 WINE_D3D_TO_STR(DXGI_FORMAT_B8G8R8X8_UNORM_SRGB);
147 WINE_D3D_TO_STR(DXGI_FORMAT_BC6H_TYPELESS);
148 WINE_D3D_TO_STR(DXGI_FORMAT_BC6H_UF16);
149 WINE_D3D_TO_STR(DXGI_FORMAT_BC6H_SF16);
150 WINE_D3D_TO_STR(DXGI_FORMAT_BC7_TYPELESS);
151 WINE_D3D_TO_STR(DXGI_FORMAT_BC7_UNORM);
152 WINE_D3D_TO_STR(DXGI_FORMAT_BC7_UNORM_SRGB);
153 default:
154 FIXME("Unrecognized DXGI_FORMAT %#x.\n", format);
155 return "unrecognized";
159 #undef WINE_D3D_TO_STR
161 const char *debug_float4(const float *values)
163 if (!values)
164 return "(null)";
165 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}",
166 values[0], values[1], values[2], values[3]);
169 void d3d11_primitive_topology_from_wined3d_primitive_type(enum wined3d_primitive_type primitive_type,
170 unsigned int patch_vertex_count, D3D11_PRIMITIVE_TOPOLOGY *topology)
172 if (primitive_type <= WINED3D_PT_TRIANGLESTRIP_ADJ)
174 *topology = (D3D11_PRIMITIVE_TOPOLOGY)primitive_type;
175 return;
178 if (primitive_type == WINED3D_PT_PATCH)
180 *topology = D3D11_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST + patch_vertex_count - 1;
181 return;
184 *topology = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED;
187 void wined3d_primitive_type_from_d3d11_primitive_topology(D3D11_PRIMITIVE_TOPOLOGY topology,
188 enum wined3d_primitive_type *type, unsigned int *patch_vertex_count)
190 if (topology <= D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ)
192 *type = (enum wined3d_primitive_type)topology;
193 *patch_vertex_count = 0;
194 return;
197 if (D3D11_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST <= topology
198 && topology <= D3D11_PRIMITIVE_TOPOLOGY_32_CONTROL_POINT_PATCHLIST)
200 *type = WINED3D_PT_PATCH;
201 *patch_vertex_count = topology - D3D11_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST + 1;
202 return;
205 WARN("Invalid primitive topology %#x.\n", topology);
206 *type = WINED3D_PT_UNDEFINED;
207 *patch_vertex_count = 0;
210 DXGI_FORMAT dxgi_format_from_wined3dformat(enum wined3d_format_id format)
212 switch(format)
214 case WINED3DFMT_UNKNOWN: return DXGI_FORMAT_UNKNOWN;
215 case WINED3DFMT_R32G32B32A32_TYPELESS: return DXGI_FORMAT_R32G32B32A32_TYPELESS;
216 case WINED3DFMT_R32G32B32A32_FLOAT: return DXGI_FORMAT_R32G32B32A32_FLOAT;
217 case WINED3DFMT_R32G32B32A32_UINT: return DXGI_FORMAT_R32G32B32A32_UINT;
218 case WINED3DFMT_R32G32B32A32_SINT: return DXGI_FORMAT_R32G32B32A32_SINT;
219 case WINED3DFMT_R32G32B32_TYPELESS: return DXGI_FORMAT_R32G32B32_TYPELESS;
220 case WINED3DFMT_R32G32B32_FLOAT: return DXGI_FORMAT_R32G32B32_FLOAT;
221 case WINED3DFMT_R32G32B32_UINT: return DXGI_FORMAT_R32G32B32_UINT;
222 case WINED3DFMT_R32G32B32_SINT: return DXGI_FORMAT_R32G32B32_SINT;
223 case WINED3DFMT_R16G16B16A16_TYPELESS: return DXGI_FORMAT_R16G16B16A16_TYPELESS;
224 case WINED3DFMT_R16G16B16A16_FLOAT: return DXGI_FORMAT_R16G16B16A16_FLOAT;
225 case WINED3DFMT_R16G16B16A16_UNORM: return DXGI_FORMAT_R16G16B16A16_UNORM;
226 case WINED3DFMT_R16G16B16A16_UINT: return DXGI_FORMAT_R16G16B16A16_UINT;
227 case WINED3DFMT_R16G16B16A16_SNORM: return DXGI_FORMAT_R16G16B16A16_SNORM;
228 case WINED3DFMT_R16G16B16A16_SINT: return DXGI_FORMAT_R16G16B16A16_SINT;
229 case WINED3DFMT_R32G32_TYPELESS: return DXGI_FORMAT_R32G32_TYPELESS;
230 case WINED3DFMT_R32G32_FLOAT: return DXGI_FORMAT_R32G32_FLOAT;
231 case WINED3DFMT_R32G32_UINT: return DXGI_FORMAT_R32G32_UINT;
232 case WINED3DFMT_R32G32_SINT: return DXGI_FORMAT_R32G32_SINT;
233 case WINED3DFMT_R32G8X24_TYPELESS: return DXGI_FORMAT_R32G8X24_TYPELESS;
234 case WINED3DFMT_D32_FLOAT_S8X24_UINT: return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
235 case WINED3DFMT_R32_FLOAT_X8X24_TYPELESS: return DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS;
236 case WINED3DFMT_X32_TYPELESS_G8X24_UINT: return DXGI_FORMAT_X32_TYPELESS_G8X24_UINT;
237 case WINED3DFMT_R10G10B10A2_TYPELESS: return DXGI_FORMAT_R10G10B10A2_TYPELESS;
238 case WINED3DFMT_R10G10B10A2_UNORM: return DXGI_FORMAT_R10G10B10A2_UNORM;
239 case WINED3DFMT_R10G10B10A2_UINT: return DXGI_FORMAT_R10G10B10A2_UINT;
240 case WINED3DFMT_R11G11B10_FLOAT: return DXGI_FORMAT_R11G11B10_FLOAT;
241 case WINED3DFMT_R8G8B8A8_TYPELESS: return DXGI_FORMAT_R8G8B8A8_TYPELESS;
242 case WINED3DFMT_R8G8B8A8_UNORM: return DXGI_FORMAT_R8G8B8A8_UNORM;
243 case WINED3DFMT_R8G8B8A8_UNORM_SRGB: return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
244 case WINED3DFMT_R8G8B8A8_UINT: return DXGI_FORMAT_R8G8B8A8_UINT;
245 case WINED3DFMT_R8G8B8A8_SNORM: return DXGI_FORMAT_R8G8B8A8_SNORM;
246 case WINED3DFMT_R8G8B8A8_SINT: return DXGI_FORMAT_R8G8B8A8_SINT;
247 case WINED3DFMT_R16G16_TYPELESS: return DXGI_FORMAT_R16G16_TYPELESS;
248 case WINED3DFMT_R16G16_FLOAT: return DXGI_FORMAT_R16G16_FLOAT;
249 case WINED3DFMT_R16G16_UNORM: return DXGI_FORMAT_R16G16_UNORM;
250 case WINED3DFMT_R16G16_UINT: return DXGI_FORMAT_R16G16_UINT;
251 case WINED3DFMT_R16G16_SNORM: return DXGI_FORMAT_R16G16_SNORM;
252 case WINED3DFMT_R16G16_SINT: return DXGI_FORMAT_R16G16_SINT;
253 case WINED3DFMT_R32_TYPELESS: return DXGI_FORMAT_R32_TYPELESS;
254 case WINED3DFMT_D32_FLOAT: return DXGI_FORMAT_D32_FLOAT;
255 case WINED3DFMT_R32_FLOAT: return DXGI_FORMAT_R32_FLOAT;
256 case WINED3DFMT_R32_UINT: return DXGI_FORMAT_R32_UINT;
257 case WINED3DFMT_R32_SINT: return DXGI_FORMAT_R32_SINT;
258 case WINED3DFMT_R24G8_TYPELESS: return DXGI_FORMAT_R24G8_TYPELESS;
259 case WINED3DFMT_D24_UNORM_S8_UINT: return DXGI_FORMAT_D24_UNORM_S8_UINT;
260 case WINED3DFMT_R24_UNORM_X8_TYPELESS: return DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
261 case WINED3DFMT_X24_TYPELESS_G8_UINT: return DXGI_FORMAT_X24_TYPELESS_G8_UINT;
262 case WINED3DFMT_R8G8_TYPELESS: return DXGI_FORMAT_R8G8_TYPELESS;
263 case WINED3DFMT_R8G8_UNORM: return DXGI_FORMAT_R8G8_UNORM;
264 case WINED3DFMT_R8G8_UINT: return DXGI_FORMAT_R8G8_UINT;
265 case WINED3DFMT_R8G8_SNORM: return DXGI_FORMAT_R8G8_SNORM;
266 case WINED3DFMT_R8G8_SINT: return DXGI_FORMAT_R8G8_SINT;
267 case WINED3DFMT_R16_TYPELESS: return DXGI_FORMAT_R16_TYPELESS;
268 case WINED3DFMT_R16_FLOAT: return DXGI_FORMAT_R16_FLOAT;
269 case WINED3DFMT_D16_UNORM: return DXGI_FORMAT_D16_UNORM;
270 case WINED3DFMT_R16_UNORM: return DXGI_FORMAT_R16_UNORM;
271 case WINED3DFMT_R16_UINT: return DXGI_FORMAT_R16_UINT;
272 case WINED3DFMT_R16_SNORM: return DXGI_FORMAT_R16_SNORM;
273 case WINED3DFMT_R16_SINT: return DXGI_FORMAT_R16_SINT;
274 case WINED3DFMT_R8_TYPELESS: return DXGI_FORMAT_R8_TYPELESS;
275 case WINED3DFMT_R8_UNORM: return DXGI_FORMAT_R8_UNORM;
276 case WINED3DFMT_R8_UINT: return DXGI_FORMAT_R8_UINT;
277 case WINED3DFMT_R8_SNORM: return DXGI_FORMAT_R8_SNORM;
278 case WINED3DFMT_R8_SINT: return DXGI_FORMAT_R8_SINT;
279 case WINED3DFMT_A8_UNORM: return DXGI_FORMAT_A8_UNORM;
280 case WINED3DFMT_R1_UNORM: return DXGI_FORMAT_R1_UNORM;
281 case WINED3DFMT_R9G9B9E5_SHAREDEXP: return DXGI_FORMAT_R9G9B9E5_SHAREDEXP;
282 case WINED3DFMT_R8G8_B8G8_UNORM: return DXGI_FORMAT_R8G8_B8G8_UNORM;
283 case WINED3DFMT_G8R8_G8B8_UNORM: return DXGI_FORMAT_G8R8_G8B8_UNORM;
284 case WINED3DFMT_BC1_TYPELESS: return DXGI_FORMAT_BC1_TYPELESS;
285 case WINED3DFMT_BC1_UNORM: return DXGI_FORMAT_BC1_UNORM;
286 case WINED3DFMT_BC1_UNORM_SRGB: return DXGI_FORMAT_BC1_UNORM_SRGB;
287 case WINED3DFMT_BC2_TYPELESS: return DXGI_FORMAT_BC2_TYPELESS;
288 case WINED3DFMT_BC2_UNORM: return DXGI_FORMAT_BC2_UNORM;
289 case WINED3DFMT_BC2_UNORM_SRGB: return DXGI_FORMAT_BC2_UNORM_SRGB;
290 case WINED3DFMT_BC3_TYPELESS: return DXGI_FORMAT_BC3_TYPELESS;
291 case WINED3DFMT_BC3_UNORM: return DXGI_FORMAT_BC3_UNORM;
292 case WINED3DFMT_BC3_UNORM_SRGB: return DXGI_FORMAT_BC3_UNORM_SRGB;
293 case WINED3DFMT_BC4_TYPELESS: return DXGI_FORMAT_BC4_TYPELESS;
294 case WINED3DFMT_BC4_UNORM: return DXGI_FORMAT_BC4_UNORM;
295 case WINED3DFMT_BC4_SNORM: return DXGI_FORMAT_BC4_SNORM;
296 case WINED3DFMT_BC5_TYPELESS: return DXGI_FORMAT_BC5_TYPELESS;
297 case WINED3DFMT_BC5_UNORM: return DXGI_FORMAT_BC5_UNORM;
298 case WINED3DFMT_BC5_SNORM: return DXGI_FORMAT_BC5_SNORM;
299 case WINED3DFMT_B5G6R5_UNORM: return DXGI_FORMAT_B5G6R5_UNORM;
300 case WINED3DFMT_B5G5R5A1_UNORM: return DXGI_FORMAT_B5G5R5A1_UNORM;
301 case WINED3DFMT_B8G8R8A8_UNORM: return DXGI_FORMAT_B8G8R8A8_UNORM;
302 case WINED3DFMT_B8G8R8X8_UNORM: return DXGI_FORMAT_B8G8R8X8_UNORM;
303 case WINED3DFMT_R10G10B10_XR_BIAS_A2_UNORM: return DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM;
304 case WINED3DFMT_B8G8R8A8_TYPELESS: return DXGI_FORMAT_B8G8R8A8_TYPELESS;
305 case WINED3DFMT_B8G8R8A8_UNORM_SRGB: return DXGI_FORMAT_B8G8R8A8_UNORM_SRGB;
306 case WINED3DFMT_B8G8R8X8_TYPELESS: return DXGI_FORMAT_B8G8R8X8_TYPELESS;
307 case WINED3DFMT_B8G8R8X8_UNORM_SRGB: return DXGI_FORMAT_B8G8R8X8_UNORM_SRGB;
308 case WINED3DFMT_BC6H_TYPELESS: return DXGI_FORMAT_BC6H_TYPELESS;
309 case WINED3DFMT_BC6H_UF16: return DXGI_FORMAT_BC6H_UF16;
310 case WINED3DFMT_BC6H_SF16: return DXGI_FORMAT_BC6H_SF16;
311 case WINED3DFMT_BC7_TYPELESS: return DXGI_FORMAT_BC7_TYPELESS;
312 case WINED3DFMT_BC7_UNORM: return DXGI_FORMAT_BC7_UNORM;
313 case WINED3DFMT_BC7_UNORM_SRGB: return DXGI_FORMAT_BC7_UNORM_SRGB;
314 default:
315 FIXME("Unhandled wined3d format %#x.\n", format);
316 return DXGI_FORMAT_UNKNOWN;
320 enum wined3d_format_id wined3dformat_from_dxgi_format(DXGI_FORMAT format)
322 switch(format)
324 case DXGI_FORMAT_UNKNOWN: return WINED3DFMT_UNKNOWN;
325 case DXGI_FORMAT_R32G32B32A32_TYPELESS: return WINED3DFMT_R32G32B32A32_TYPELESS;
326 case DXGI_FORMAT_R32G32B32A32_FLOAT: return WINED3DFMT_R32G32B32A32_FLOAT;
327 case DXGI_FORMAT_R32G32B32A32_UINT: return WINED3DFMT_R32G32B32A32_UINT;
328 case DXGI_FORMAT_R32G32B32A32_SINT: return WINED3DFMT_R32G32B32A32_SINT;
329 case DXGI_FORMAT_R32G32B32_TYPELESS: return WINED3DFMT_R32G32B32_TYPELESS;
330 case DXGI_FORMAT_R32G32B32_FLOAT: return WINED3DFMT_R32G32B32_FLOAT;
331 case DXGI_FORMAT_R32G32B32_UINT: return WINED3DFMT_R32G32B32_UINT;
332 case DXGI_FORMAT_R32G32B32_SINT: return WINED3DFMT_R32G32B32_SINT;
333 case DXGI_FORMAT_R16G16B16A16_TYPELESS: return WINED3DFMT_R16G16B16A16_TYPELESS;
334 case DXGI_FORMAT_R16G16B16A16_FLOAT: return WINED3DFMT_R16G16B16A16_FLOAT;
335 case DXGI_FORMAT_R16G16B16A16_UNORM: return WINED3DFMT_R16G16B16A16_UNORM;
336 case DXGI_FORMAT_R16G16B16A16_UINT: return WINED3DFMT_R16G16B16A16_UINT;
337 case DXGI_FORMAT_R16G16B16A16_SNORM: return WINED3DFMT_R16G16B16A16_SNORM;
338 case DXGI_FORMAT_R16G16B16A16_SINT: return WINED3DFMT_R16G16B16A16_SINT;
339 case DXGI_FORMAT_R32G32_TYPELESS: return WINED3DFMT_R32G32_TYPELESS;
340 case DXGI_FORMAT_R32G32_FLOAT: return WINED3DFMT_R32G32_FLOAT;
341 case DXGI_FORMAT_R32G32_UINT: return WINED3DFMT_R32G32_UINT;
342 case DXGI_FORMAT_R32G32_SINT: return WINED3DFMT_R32G32_SINT;
343 case DXGI_FORMAT_R32G8X24_TYPELESS: return WINED3DFMT_R32G8X24_TYPELESS;
344 case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: return WINED3DFMT_D32_FLOAT_S8X24_UINT;
345 case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: return WINED3DFMT_R32_FLOAT_X8X24_TYPELESS;
346 case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: return WINED3DFMT_X32_TYPELESS_G8X24_UINT;
347 case DXGI_FORMAT_R10G10B10A2_TYPELESS: return WINED3DFMT_R10G10B10A2_TYPELESS;
348 case DXGI_FORMAT_R10G10B10A2_UNORM: return WINED3DFMT_R10G10B10A2_UNORM;
349 case DXGI_FORMAT_R10G10B10A2_UINT: return WINED3DFMT_R10G10B10A2_UINT;
350 case DXGI_FORMAT_R11G11B10_FLOAT: return WINED3DFMT_R11G11B10_FLOAT;
351 case DXGI_FORMAT_R8G8B8A8_TYPELESS: return WINED3DFMT_R8G8B8A8_TYPELESS;
352 case DXGI_FORMAT_R8G8B8A8_UNORM: return WINED3DFMT_R8G8B8A8_UNORM;
353 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: return WINED3DFMT_R8G8B8A8_UNORM_SRGB;
354 case DXGI_FORMAT_R8G8B8A8_UINT: return WINED3DFMT_R8G8B8A8_UINT;
355 case DXGI_FORMAT_R8G8B8A8_SNORM: return WINED3DFMT_R8G8B8A8_SNORM;
356 case DXGI_FORMAT_R8G8B8A8_SINT: return WINED3DFMT_R8G8B8A8_SINT;
357 case DXGI_FORMAT_R16G16_TYPELESS: return WINED3DFMT_R16G16_TYPELESS;
358 case DXGI_FORMAT_R16G16_FLOAT: return WINED3DFMT_R16G16_FLOAT;
359 case DXGI_FORMAT_R16G16_UNORM: return WINED3DFMT_R16G16_UNORM;
360 case DXGI_FORMAT_R16G16_UINT: return WINED3DFMT_R16G16_UINT;
361 case DXGI_FORMAT_R16G16_SNORM: return WINED3DFMT_R16G16_SNORM;
362 case DXGI_FORMAT_R16G16_SINT: return WINED3DFMT_R16G16_SINT;
363 case DXGI_FORMAT_R32_TYPELESS: return WINED3DFMT_R32_TYPELESS;
364 case DXGI_FORMAT_D32_FLOAT: return WINED3DFMT_D32_FLOAT;
365 case DXGI_FORMAT_R32_FLOAT: return WINED3DFMT_R32_FLOAT;
366 case DXGI_FORMAT_R32_UINT: return WINED3DFMT_R32_UINT;
367 case DXGI_FORMAT_R32_SINT: return WINED3DFMT_R32_SINT;
368 case DXGI_FORMAT_R24G8_TYPELESS: return WINED3DFMT_R24G8_TYPELESS;
369 case DXGI_FORMAT_D24_UNORM_S8_UINT: return WINED3DFMT_D24_UNORM_S8_UINT;
370 case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: return WINED3DFMT_R24_UNORM_X8_TYPELESS;
371 case DXGI_FORMAT_X24_TYPELESS_G8_UINT: return WINED3DFMT_X24_TYPELESS_G8_UINT;
372 case DXGI_FORMAT_R8G8_TYPELESS: return WINED3DFMT_R8G8_TYPELESS;
373 case DXGI_FORMAT_R8G8_UNORM: return WINED3DFMT_R8G8_UNORM;
374 case DXGI_FORMAT_R8G8_UINT: return WINED3DFMT_R8G8_UINT;
375 case DXGI_FORMAT_R8G8_SNORM: return WINED3DFMT_R8G8_SNORM;
376 case DXGI_FORMAT_R8G8_SINT: return WINED3DFMT_R8G8_SINT;
377 case DXGI_FORMAT_R16_TYPELESS: return WINED3DFMT_R16_TYPELESS;
378 case DXGI_FORMAT_R16_FLOAT: return WINED3DFMT_R16_FLOAT;
379 case DXGI_FORMAT_D16_UNORM: return WINED3DFMT_D16_UNORM;
380 case DXGI_FORMAT_R16_UNORM: return WINED3DFMT_R16_UNORM;
381 case DXGI_FORMAT_R16_UINT: return WINED3DFMT_R16_UINT;
382 case DXGI_FORMAT_R16_SNORM: return WINED3DFMT_R16_SNORM;
383 case DXGI_FORMAT_R16_SINT: return WINED3DFMT_R16_SINT;
384 case DXGI_FORMAT_R8_TYPELESS: return WINED3DFMT_R8_TYPELESS;
385 case DXGI_FORMAT_R8_UNORM: return WINED3DFMT_R8_UNORM;
386 case DXGI_FORMAT_R8_UINT: return WINED3DFMT_R8_UINT;
387 case DXGI_FORMAT_R8_SNORM: return WINED3DFMT_R8_SNORM;
388 case DXGI_FORMAT_R8_SINT: return WINED3DFMT_R8_SINT;
389 case DXGI_FORMAT_A8_UNORM: return WINED3DFMT_A8_UNORM;
390 case DXGI_FORMAT_R1_UNORM: return WINED3DFMT_R1_UNORM;
391 case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: return WINED3DFMT_R9G9B9E5_SHAREDEXP;
392 case DXGI_FORMAT_R8G8_B8G8_UNORM: return WINED3DFMT_R8G8_B8G8_UNORM;
393 case DXGI_FORMAT_G8R8_G8B8_UNORM: return WINED3DFMT_G8R8_G8B8_UNORM;
394 case DXGI_FORMAT_BC1_TYPELESS: return WINED3DFMT_BC1_TYPELESS;
395 case DXGI_FORMAT_BC1_UNORM: return WINED3DFMT_BC1_UNORM;
396 case DXGI_FORMAT_BC1_UNORM_SRGB: return WINED3DFMT_BC1_UNORM_SRGB;
397 case DXGI_FORMAT_BC2_TYPELESS: return WINED3DFMT_BC2_TYPELESS;
398 case DXGI_FORMAT_BC2_UNORM: return WINED3DFMT_BC2_UNORM;
399 case DXGI_FORMAT_BC2_UNORM_SRGB: return WINED3DFMT_BC2_UNORM_SRGB;
400 case DXGI_FORMAT_BC3_TYPELESS: return WINED3DFMT_BC3_TYPELESS;
401 case DXGI_FORMAT_BC3_UNORM: return WINED3DFMT_BC3_UNORM;
402 case DXGI_FORMAT_BC3_UNORM_SRGB: return WINED3DFMT_BC3_UNORM_SRGB;
403 case DXGI_FORMAT_BC4_TYPELESS: return WINED3DFMT_BC4_TYPELESS;
404 case DXGI_FORMAT_BC4_UNORM: return WINED3DFMT_BC4_UNORM;
405 case DXGI_FORMAT_BC4_SNORM: return WINED3DFMT_BC4_SNORM;
406 case DXGI_FORMAT_BC5_TYPELESS: return WINED3DFMT_BC5_TYPELESS;
407 case DXGI_FORMAT_BC5_UNORM: return WINED3DFMT_BC5_UNORM;
408 case DXGI_FORMAT_BC5_SNORM: return WINED3DFMT_BC5_SNORM;
409 case DXGI_FORMAT_B5G6R5_UNORM: return WINED3DFMT_B5G6R5_UNORM;
410 case DXGI_FORMAT_B5G5R5A1_UNORM: return WINED3DFMT_B5G5R5A1_UNORM;
411 case DXGI_FORMAT_B8G8R8A8_UNORM: return WINED3DFMT_B8G8R8A8_UNORM;
412 case DXGI_FORMAT_B8G8R8X8_UNORM: return WINED3DFMT_B8G8R8X8_UNORM;
413 case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM: return WINED3DFMT_R10G10B10_XR_BIAS_A2_UNORM;
414 case DXGI_FORMAT_B8G8R8A8_TYPELESS: return WINED3DFMT_B8G8R8A8_TYPELESS;
415 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: return WINED3DFMT_B8G8R8A8_UNORM_SRGB;
416 case DXGI_FORMAT_B8G8R8X8_TYPELESS: return WINED3DFMT_B8G8R8X8_TYPELESS;
417 case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: return WINED3DFMT_B8G8R8X8_UNORM_SRGB;
418 case DXGI_FORMAT_BC6H_TYPELESS: return WINED3DFMT_BC6H_TYPELESS;
419 case DXGI_FORMAT_BC6H_UF16: return WINED3DFMT_BC6H_UF16;
420 case DXGI_FORMAT_BC6H_SF16: return WINED3DFMT_BC6H_SF16;
421 case DXGI_FORMAT_BC7_TYPELESS: return WINED3DFMT_BC7_TYPELESS;
422 case DXGI_FORMAT_BC7_UNORM: return WINED3DFMT_BC7_UNORM;
423 case DXGI_FORMAT_BC7_UNORM_SRGB: return WINED3DFMT_BC7_UNORM_SRGB;
424 default:
425 FIXME("Unhandled DXGI_FORMAT %#x.\n", format);
426 return WINED3DFMT_UNKNOWN;
430 unsigned int wined3d_getdata_flags_from_d3d11_async_getdata_flags(unsigned int d3d11_flags)
432 if (d3d11_flags & ~D3D11_ASYNC_GETDATA_DONOTFLUSH)
433 FIXME("Unhandled async getdata flags %#x.\n", d3d11_flags);
435 if (d3d11_flags & D3D11_ASYNC_GETDATA_DONOTFLUSH)
436 return 0;
438 return WINED3DGETDATA_FLUSH;
441 DWORD wined3d_usage_from_d3d11(UINT bind_flags, enum D3D11_USAGE usage)
443 static const DWORD handled = D3D11_BIND_SHADER_RESOURCE
444 | D3D11_BIND_RENDER_TARGET
445 | D3D11_BIND_DEPTH_STENCIL;
446 DWORD wined3d_usage = 0;
448 if (bind_flags & D3D11_BIND_SHADER_RESOURCE)
449 wined3d_usage |= WINED3DUSAGE_TEXTURE;
450 if (bind_flags & D3D11_BIND_RENDER_TARGET)
451 wined3d_usage |= WINED3DUSAGE_RENDERTARGET;
452 if (bind_flags & D3D11_BIND_DEPTH_STENCIL)
453 wined3d_usage |= WINED3DUSAGE_DEPTHSTENCIL;
454 if (bind_flags & ~handled)
455 FIXME("Unhandled bind flags %#x.\n", bind_flags & ~handled);
457 if (usage == D3D11_USAGE_DYNAMIC)
458 wined3d_usage |= WINED3DUSAGE_DYNAMIC;
460 return wined3d_usage;
463 enum D3D11_USAGE d3d11_usage_from_d3d10_usage(enum D3D10_USAGE usage)
465 switch (usage)
467 case D3D10_USAGE_DEFAULT: return D3D11_USAGE_DEFAULT;
468 case D3D10_USAGE_IMMUTABLE: return D3D11_USAGE_IMMUTABLE;
469 case D3D10_USAGE_DYNAMIC: return D3D11_USAGE_DYNAMIC;
470 case D3D10_USAGE_STAGING: return D3D11_USAGE_STAGING;
471 default:
472 FIXME("Unhandled usage %#x.\n", usage);
473 return D3D11_USAGE_DEFAULT;
477 enum D3D10_USAGE d3d10_usage_from_d3d11_usage(enum D3D11_USAGE usage)
479 switch (usage)
481 case D3D11_USAGE_DEFAULT: return D3D10_USAGE_DEFAULT;
482 case D3D11_USAGE_IMMUTABLE: return D3D10_USAGE_IMMUTABLE;
483 case D3D11_USAGE_DYNAMIC: return D3D10_USAGE_DYNAMIC;
484 case D3D11_USAGE_STAGING: return D3D10_USAGE_STAGING;
485 default:
486 FIXME("Unhandled usage %#x.\n", usage);
487 return D3D10_USAGE_DEFAULT;
491 UINT d3d11_bind_flags_from_d3d10_bind_flags(UINT bind_flags)
493 static const UINT handled_flags = D3D10_BIND_VERTEX_BUFFER
494 | D3D10_BIND_INDEX_BUFFER
495 | D3D10_BIND_CONSTANT_BUFFER
496 | D3D10_BIND_SHADER_RESOURCE
497 | D3D10_BIND_STREAM_OUTPUT
498 | D3D10_BIND_RENDER_TARGET
499 | D3D10_BIND_DEPTH_STENCIL;
500 UINT d3d11_bind_flags = bind_flags & handled_flags;
502 if (bind_flags & ~handled_flags)
503 FIXME("Unhandled bind flags %#x.\n", bind_flags & ~handled_flags);
505 return d3d11_bind_flags;
508 UINT d3d10_bind_flags_from_d3d11_bind_flags(UINT bind_flags)
510 static const UINT handled_flags = D3D11_BIND_VERTEX_BUFFER
511 | D3D11_BIND_INDEX_BUFFER
512 | D3D11_BIND_CONSTANT_BUFFER
513 | D3D11_BIND_SHADER_RESOURCE
514 | D3D11_BIND_STREAM_OUTPUT
515 | D3D11_BIND_RENDER_TARGET
516 | D3D11_BIND_DEPTH_STENCIL
517 | D3D11_BIND_UNORDERED_ACCESS
518 | D3D11_BIND_DECODER
519 | D3D11_BIND_VIDEO_ENCODER;
520 UINT d3d10_bind_flags = bind_flags & handled_flags;
522 if (bind_flags & ~handled_flags)
523 FIXME("Unhandled bind flags %#x.\n", bind_flags & ~handled_flags);
525 return d3d10_bind_flags;
528 UINT d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(UINT cpu_access_flags)
530 static const UINT handled_flags = D3D10_CPU_ACCESS_WRITE
531 | D3D10_CPU_ACCESS_READ;
532 UINT d3d11_cpu_access_flags = cpu_access_flags & handled_flags;
534 if (cpu_access_flags & ~handled_flags)
535 FIXME("Unhandled cpu access flags %#x.\n", cpu_access_flags & ~handled_flags);
537 return d3d11_cpu_access_flags;
540 UINT d3d10_cpu_access_flags_from_d3d11_cpu_access_flags(UINT cpu_access_flags)
542 static const UINT handled_flags = D3D11_CPU_ACCESS_WRITE
543 | D3D11_CPU_ACCESS_READ;
544 UINT d3d10_cpu_access_flags = cpu_access_flags & handled_flags;
546 if (cpu_access_flags & ~handled_flags)
547 FIXME("Unhandled cpu access flags %#x.\n", cpu_access_flags & ~handled_flags);
549 return d3d10_cpu_access_flags;
552 UINT d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(UINT resource_misc_flags)
554 static const UINT bitwise_identical_flags = D3D10_RESOURCE_MISC_GENERATE_MIPS
555 | D3D10_RESOURCE_MISC_SHARED
556 | D3D10_RESOURCE_MISC_TEXTURECUBE;
557 const UINT handled_flags = bitwise_identical_flags
558 | D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
559 | D3D10_RESOURCE_MISC_GDI_COMPATIBLE;
560 UINT d3d11_resource_misc_flags = resource_misc_flags & bitwise_identical_flags;
562 if (resource_misc_flags & D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX)
563 d3d11_resource_misc_flags |= D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
564 if (resource_misc_flags & D3D10_RESOURCE_MISC_GDI_COMPATIBLE)
565 d3d11_resource_misc_flags |= D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
567 if (resource_misc_flags & ~handled_flags)
568 FIXME("Unhandled resource misc flags %#x.\n", resource_misc_flags & ~handled_flags);
570 return d3d11_resource_misc_flags;
573 UINT d3d10_resource_misc_flags_from_d3d11_resource_misc_flags(UINT resource_misc_flags)
575 static const UINT bitwise_identical_flags = D3D11_RESOURCE_MISC_GENERATE_MIPS
576 | D3D11_RESOURCE_MISC_SHARED
577 | D3D11_RESOURCE_MISC_TEXTURECUBE;
578 const UINT handled_flags = bitwise_identical_flags
579 | D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS
580 | D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS
581 | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
582 | D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX
583 | D3D11_RESOURCE_MISC_GDI_COMPATIBLE
584 | D3D11_RESOURCE_MISC_SHARED_NTHANDLE;
585 UINT d3d10_resource_misc_flags = resource_misc_flags & bitwise_identical_flags;
587 if (resource_misc_flags & D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX)
588 d3d10_resource_misc_flags |= D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX;
589 if (resource_misc_flags & D3D11_RESOURCE_MISC_GDI_COMPATIBLE)
590 d3d10_resource_misc_flags |= D3D10_RESOURCE_MISC_GDI_COMPATIBLE;
592 if (resource_misc_flags & ~handled_flags)
593 FIXME("Unhandled resource misc flags #%x.\n", resource_misc_flags & ~handled_flags);
595 return d3d10_resource_misc_flags;
598 struct wined3d_resource *wined3d_resource_from_d3d11_resource(ID3D11Resource *resource)
600 D3D11_RESOURCE_DIMENSION dimension;
602 ID3D11Resource_GetType(resource, &dimension);
604 switch (dimension)
606 case D3D11_RESOURCE_DIMENSION_BUFFER:
607 return wined3d_buffer_get_resource(unsafe_impl_from_ID3D11Buffer(
608 (ID3D11Buffer *)resource)->wined3d_buffer);
610 case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
611 return wined3d_texture_get_resource(unsafe_impl_from_ID3D11Texture2D(
612 (ID3D11Texture2D *)resource)->wined3d_texture);
614 case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
615 return wined3d_texture_get_resource(unsafe_impl_from_ID3D11Texture3D(
616 (ID3D11Texture3D *)resource)->wined3d_texture);
618 default:
619 FIXME("Unhandled resource dimension %#x.\n", dimension);
620 return NULL;
624 struct wined3d_resource *wined3d_resource_from_d3d10_resource(ID3D10Resource *resource)
626 D3D10_RESOURCE_DIMENSION dimension;
628 ID3D10Resource_GetType(resource, &dimension);
630 switch (dimension)
632 case D3D10_RESOURCE_DIMENSION_BUFFER:
633 return wined3d_buffer_get_resource(unsafe_impl_from_ID3D10Buffer(
634 (ID3D10Buffer *)resource)->wined3d_buffer);
636 case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
637 return wined3d_texture_get_resource(unsafe_impl_from_ID3D10Texture2D(
638 (ID3D10Texture2D *)resource)->wined3d_texture);
640 default:
641 FIXME("Unhandled resource dimension %#x.\n", dimension);
642 return NULL;
646 DWORD wined3d_map_flags_from_d3d11_map_type(D3D11_MAP map_type)
648 switch (map_type)
650 case D3D11_MAP_WRITE:
651 case D3D11_MAP_READ_WRITE:
652 return 0;
654 case D3D11_MAP_READ:
655 return WINED3D_MAP_READONLY;
657 case D3D11_MAP_WRITE_DISCARD:
658 return WINED3D_MAP_DISCARD;
660 case D3D11_MAP_WRITE_NO_OVERWRITE:
661 return WINED3D_MAP_NOOVERWRITE;
663 default:
664 FIXME("Unhandled map_type %#x.\n", map_type);
665 return 0;
669 DWORD wined3d_clear_flags_from_d3d11_clear_flags(UINT clear_flags)
671 DWORD wined3d_clear_flags = 0;
673 if (clear_flags & D3D11_CLEAR_DEPTH)
674 wined3d_clear_flags |= WINED3DCLEAR_ZBUFFER;
675 if (clear_flags & D3D11_CLEAR_STENCIL)
676 wined3d_clear_flags |= WINED3DCLEAR_STENCIL;
678 if (clear_flags & ~(D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL))
680 FIXME("Unhandled clear flags %#x.\n",
681 clear_flags & ~(D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL));
684 return wined3d_clear_flags;
687 HRESULT d3d_get_private_data(struct wined3d_private_store *store,
688 REFGUID guid, UINT *data_size, void *data)
690 const struct wined3d_private_data *stored_data;
691 DWORD size_in;
693 if (!data_size)
694 return E_INVALIDARG;
696 wined3d_mutex_lock();
697 if (!(stored_data = wined3d_private_store_get_private_data(store, guid)))
699 *data_size = 0;
700 wined3d_mutex_unlock();
701 return DXGI_ERROR_NOT_FOUND;
704 size_in = *data_size;
705 *data_size = stored_data->size;
706 if (!data)
708 wined3d_mutex_unlock();
709 return S_OK;
711 if (size_in < stored_data->size)
713 wined3d_mutex_unlock();
714 return DXGI_ERROR_MORE_DATA;
717 if (stored_data->flags & WINED3DSPD_IUNKNOWN)
718 IUnknown_AddRef(stored_data->content.object);
719 memcpy(data, stored_data->content.data, stored_data->size);
721 wined3d_mutex_unlock();
722 return S_OK;
725 HRESULT d3d_set_private_data(struct wined3d_private_store *store,
726 REFGUID guid, UINT data_size, const void *data)
728 struct wined3d_private_data *entry;
729 HRESULT hr;
731 wined3d_mutex_lock();
732 if (!data)
734 if (!(entry = wined3d_private_store_get_private_data(store, guid)))
736 wined3d_mutex_unlock();
737 return S_FALSE;
739 wined3d_private_store_free_private_data(store, entry);
740 wined3d_mutex_unlock();
742 return S_OK;
745 hr = wined3d_private_store_set_private_data(store, guid, data, data_size, 0);
746 wined3d_mutex_unlock();
748 return hr;
751 HRESULT d3d_set_private_data_interface(struct wined3d_private_store *store,
752 REFGUID guid, const IUnknown *object)
754 HRESULT hr;
756 if (!object)
757 return d3d_set_private_data(store, guid, sizeof(object), &object);
759 wined3d_mutex_lock();
760 hr = wined3d_private_store_set_private_data(store,
761 guid, object, sizeof(object), WINED3DSPD_IUNKNOWN);
762 wined3d_mutex_unlock();
764 return hr;
767 void skip_dword_unknown(const char **ptr, unsigned int count)
769 unsigned int i;
770 DWORD d;
772 WARN("Skipping %u unknown DWORDs:\n", count);
773 for (i = 0; i < count; ++i)
775 read_dword(ptr, &d);
776 WARN("\t0x%08x\n", d);
780 HRESULT parse_dxbc(const char *data, SIZE_T data_size,
781 HRESULT (*chunk_handler)(const char *data, DWORD data_size, DWORD tag, void *ctx), void *ctx)
783 const char *ptr = data;
784 HRESULT hr = S_OK;
785 DWORD chunk_count;
786 DWORD total_size;
787 unsigned int i;
788 DWORD tag;
790 read_dword(&ptr, &tag);
791 TRACE("tag: %s.\n", debugstr_an((const char *)&tag, 4));
793 if (tag != TAG_DXBC)
795 WARN("Wrong tag.\n");
796 return E_INVALIDARG;
799 WARN("Ignoring DXBC checksum.\n");
800 skip_dword_unknown(&ptr, 4);
802 skip_dword_unknown(&ptr, 1); /* It seems to always be 0x00000001. */
804 read_dword(&ptr, &total_size);
805 TRACE("total size: %#x\n", total_size);
807 read_dword(&ptr, &chunk_count);
808 TRACE("chunk count: %#x\n", chunk_count);
810 for (i = 0; i < chunk_count; ++i)
812 DWORD chunk_tag, chunk_size;
813 const char *chunk_ptr;
814 DWORD chunk_offset;
816 read_dword(&ptr, &chunk_offset);
817 TRACE("chunk %u at offset %#x\n", i, chunk_offset);
819 if (chunk_offset >= data_size || !require_space(chunk_offset, 2, sizeof(DWORD), data_size))
821 WARN("Invalid chunk offset %#x (data size %#lx).\n", chunk_offset, data_size);
822 return E_FAIL;
825 chunk_ptr = data + chunk_offset;
827 read_dword(&chunk_ptr, &chunk_tag);
828 read_dword(&chunk_ptr, &chunk_size);
830 if (!require_space(chunk_ptr - data, 1, chunk_size, data_size))
832 WARN("Invalid chunk size %#x (data size %#lx, chunk offset %#x).\n", chunk_size, data_size, chunk_offset);
833 return E_FAIL;
836 hr = chunk_handler(chunk_ptr, chunk_size, chunk_tag, ctx);
837 if (FAILED(hr)) break;
840 return hr;