combase: Add stub for RoGetApartmentIdentifier.
[wine.git] / dlls / d3d11 / utils.c
blob8fdb00518ff97bef2bdeb83238f99725ae9dd37e
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 WINE_D3D_TO_STR(DXGI_FORMAT_B4G4R4A4_UNORM);
154 default:
155 FIXME("Unrecognized DXGI_FORMAT %#x.\n", format);
156 return "unrecognized";
160 #undef WINE_D3D_TO_STR
162 const char *debug_float4(const float *values)
164 if (!values)
165 return "(null)";
166 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}",
167 values[0], values[1], values[2], values[3]);
170 void d3d11_primitive_topology_from_wined3d_primitive_type(enum wined3d_primitive_type primitive_type,
171 unsigned int patch_vertex_count, D3D11_PRIMITIVE_TOPOLOGY *topology)
173 if (primitive_type <= WINED3D_PT_TRIANGLESTRIP_ADJ)
175 *topology = (D3D11_PRIMITIVE_TOPOLOGY)primitive_type;
176 return;
179 if (primitive_type == WINED3D_PT_PATCH)
181 *topology = D3D11_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST + patch_vertex_count - 1;
182 return;
185 *topology = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED;
188 void wined3d_primitive_type_from_d3d11_primitive_topology(D3D11_PRIMITIVE_TOPOLOGY topology,
189 enum wined3d_primitive_type *type, unsigned int *patch_vertex_count)
191 if (topology <= D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ)
193 *type = (enum wined3d_primitive_type)topology;
194 *patch_vertex_count = 0;
195 return;
198 if (D3D11_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST <= topology
199 && topology <= D3D11_PRIMITIVE_TOPOLOGY_32_CONTROL_POINT_PATCHLIST)
201 *type = WINED3D_PT_PATCH;
202 *patch_vertex_count = topology - D3D11_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST + 1;
203 return;
206 WARN("Invalid primitive topology %#x.\n", topology);
207 *type = WINED3D_PT_UNDEFINED;
208 *patch_vertex_count = 0;
211 DXGI_FORMAT dxgi_format_from_wined3dformat(enum wined3d_format_id format)
213 switch(format)
215 case WINED3DFMT_UNKNOWN: return DXGI_FORMAT_UNKNOWN;
216 case WINED3DFMT_R32G32B32A32_TYPELESS: return DXGI_FORMAT_R32G32B32A32_TYPELESS;
217 case WINED3DFMT_R32G32B32A32_FLOAT: return DXGI_FORMAT_R32G32B32A32_FLOAT;
218 case WINED3DFMT_R32G32B32A32_UINT: return DXGI_FORMAT_R32G32B32A32_UINT;
219 case WINED3DFMT_R32G32B32A32_SINT: return DXGI_FORMAT_R32G32B32A32_SINT;
220 case WINED3DFMT_R32G32B32_TYPELESS: return DXGI_FORMAT_R32G32B32_TYPELESS;
221 case WINED3DFMT_R32G32B32_FLOAT: return DXGI_FORMAT_R32G32B32_FLOAT;
222 case WINED3DFMT_R32G32B32_UINT: return DXGI_FORMAT_R32G32B32_UINT;
223 case WINED3DFMT_R32G32B32_SINT: return DXGI_FORMAT_R32G32B32_SINT;
224 case WINED3DFMT_R16G16B16A16_TYPELESS: return DXGI_FORMAT_R16G16B16A16_TYPELESS;
225 case WINED3DFMT_R16G16B16A16_FLOAT: return DXGI_FORMAT_R16G16B16A16_FLOAT;
226 case WINED3DFMT_R16G16B16A16_UNORM: return DXGI_FORMAT_R16G16B16A16_UNORM;
227 case WINED3DFMT_R16G16B16A16_UINT: return DXGI_FORMAT_R16G16B16A16_UINT;
228 case WINED3DFMT_R16G16B16A16_SNORM: return DXGI_FORMAT_R16G16B16A16_SNORM;
229 case WINED3DFMT_R16G16B16A16_SINT: return DXGI_FORMAT_R16G16B16A16_SINT;
230 case WINED3DFMT_R32G32_TYPELESS: return DXGI_FORMAT_R32G32_TYPELESS;
231 case WINED3DFMT_R32G32_FLOAT: return DXGI_FORMAT_R32G32_FLOAT;
232 case WINED3DFMT_R32G32_UINT: return DXGI_FORMAT_R32G32_UINT;
233 case WINED3DFMT_R32G32_SINT: return DXGI_FORMAT_R32G32_SINT;
234 case WINED3DFMT_R32G8X24_TYPELESS: return DXGI_FORMAT_R32G8X24_TYPELESS;
235 case WINED3DFMT_D32_FLOAT_S8X24_UINT: return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
236 case WINED3DFMT_R32_FLOAT_X8X24_TYPELESS: return DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS;
237 case WINED3DFMT_X32_TYPELESS_G8X24_UINT: return DXGI_FORMAT_X32_TYPELESS_G8X24_UINT;
238 case WINED3DFMT_R10G10B10A2_TYPELESS: return DXGI_FORMAT_R10G10B10A2_TYPELESS;
239 case WINED3DFMT_R10G10B10A2_UNORM: return DXGI_FORMAT_R10G10B10A2_UNORM;
240 case WINED3DFMT_R10G10B10A2_UINT: return DXGI_FORMAT_R10G10B10A2_UINT;
241 case WINED3DFMT_R11G11B10_FLOAT: return DXGI_FORMAT_R11G11B10_FLOAT;
242 case WINED3DFMT_R8G8B8A8_TYPELESS: return DXGI_FORMAT_R8G8B8A8_TYPELESS;
243 case WINED3DFMT_R8G8B8A8_UNORM: return DXGI_FORMAT_R8G8B8A8_UNORM;
244 case WINED3DFMT_R8G8B8A8_UNORM_SRGB: return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
245 case WINED3DFMT_R8G8B8A8_UINT: return DXGI_FORMAT_R8G8B8A8_UINT;
246 case WINED3DFMT_R8G8B8A8_SNORM: return DXGI_FORMAT_R8G8B8A8_SNORM;
247 case WINED3DFMT_R8G8B8A8_SINT: return DXGI_FORMAT_R8G8B8A8_SINT;
248 case WINED3DFMT_R16G16_TYPELESS: return DXGI_FORMAT_R16G16_TYPELESS;
249 case WINED3DFMT_R16G16_FLOAT: return DXGI_FORMAT_R16G16_FLOAT;
250 case WINED3DFMT_R16G16_UNORM: return DXGI_FORMAT_R16G16_UNORM;
251 case WINED3DFMT_R16G16_UINT: return DXGI_FORMAT_R16G16_UINT;
252 case WINED3DFMT_R16G16_SNORM: return DXGI_FORMAT_R16G16_SNORM;
253 case WINED3DFMT_R16G16_SINT: return DXGI_FORMAT_R16G16_SINT;
254 case WINED3DFMT_R32_TYPELESS: return DXGI_FORMAT_R32_TYPELESS;
255 case WINED3DFMT_D32_FLOAT: return DXGI_FORMAT_D32_FLOAT;
256 case WINED3DFMT_R32_FLOAT: return DXGI_FORMAT_R32_FLOAT;
257 case WINED3DFMT_R32_UINT: return DXGI_FORMAT_R32_UINT;
258 case WINED3DFMT_R32_SINT: return DXGI_FORMAT_R32_SINT;
259 case WINED3DFMT_R24G8_TYPELESS: return DXGI_FORMAT_R24G8_TYPELESS;
260 case WINED3DFMT_D24_UNORM_S8_UINT: return DXGI_FORMAT_D24_UNORM_S8_UINT;
261 case WINED3DFMT_R24_UNORM_X8_TYPELESS: return DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
262 case WINED3DFMT_X24_TYPELESS_G8_UINT: return DXGI_FORMAT_X24_TYPELESS_G8_UINT;
263 case WINED3DFMT_R8G8_TYPELESS: return DXGI_FORMAT_R8G8_TYPELESS;
264 case WINED3DFMT_R8G8_UNORM: return DXGI_FORMAT_R8G8_UNORM;
265 case WINED3DFMT_R8G8_UINT: return DXGI_FORMAT_R8G8_UINT;
266 case WINED3DFMT_R8G8_SNORM: return DXGI_FORMAT_R8G8_SNORM;
267 case WINED3DFMT_R8G8_SINT: return DXGI_FORMAT_R8G8_SINT;
268 case WINED3DFMT_R16_TYPELESS: return DXGI_FORMAT_R16_TYPELESS;
269 case WINED3DFMT_R16_FLOAT: return DXGI_FORMAT_R16_FLOAT;
270 case WINED3DFMT_D16_UNORM: return DXGI_FORMAT_D16_UNORM;
271 case WINED3DFMT_R16_UNORM: return DXGI_FORMAT_R16_UNORM;
272 case WINED3DFMT_R16_UINT: return DXGI_FORMAT_R16_UINT;
273 case WINED3DFMT_R16_SNORM: return DXGI_FORMAT_R16_SNORM;
274 case WINED3DFMT_R16_SINT: return DXGI_FORMAT_R16_SINT;
275 case WINED3DFMT_R8_TYPELESS: return DXGI_FORMAT_R8_TYPELESS;
276 case WINED3DFMT_R8_UNORM: return DXGI_FORMAT_R8_UNORM;
277 case WINED3DFMT_R8_UINT: return DXGI_FORMAT_R8_UINT;
278 case WINED3DFMT_R8_SNORM: return DXGI_FORMAT_R8_SNORM;
279 case WINED3DFMT_R8_SINT: return DXGI_FORMAT_R8_SINT;
280 case WINED3DFMT_A8_UNORM: return DXGI_FORMAT_A8_UNORM;
281 case WINED3DFMT_R1_UNORM: return DXGI_FORMAT_R1_UNORM;
282 case WINED3DFMT_R9G9B9E5_SHAREDEXP: return DXGI_FORMAT_R9G9B9E5_SHAREDEXP;
283 case WINED3DFMT_R8G8_B8G8_UNORM: return DXGI_FORMAT_R8G8_B8G8_UNORM;
284 case WINED3DFMT_G8R8_G8B8_UNORM: return DXGI_FORMAT_G8R8_G8B8_UNORM;
285 case WINED3DFMT_BC1_TYPELESS: return DXGI_FORMAT_BC1_TYPELESS;
286 case WINED3DFMT_BC1_UNORM: return DXGI_FORMAT_BC1_UNORM;
287 case WINED3DFMT_BC1_UNORM_SRGB: return DXGI_FORMAT_BC1_UNORM_SRGB;
288 case WINED3DFMT_BC2_TYPELESS: return DXGI_FORMAT_BC2_TYPELESS;
289 case WINED3DFMT_BC2_UNORM: return DXGI_FORMAT_BC2_UNORM;
290 case WINED3DFMT_BC2_UNORM_SRGB: return DXGI_FORMAT_BC2_UNORM_SRGB;
291 case WINED3DFMT_BC3_TYPELESS: return DXGI_FORMAT_BC3_TYPELESS;
292 case WINED3DFMT_BC3_UNORM: return DXGI_FORMAT_BC3_UNORM;
293 case WINED3DFMT_BC3_UNORM_SRGB: return DXGI_FORMAT_BC3_UNORM_SRGB;
294 case WINED3DFMT_BC4_TYPELESS: return DXGI_FORMAT_BC4_TYPELESS;
295 case WINED3DFMT_BC4_UNORM: return DXGI_FORMAT_BC4_UNORM;
296 case WINED3DFMT_BC4_SNORM: return DXGI_FORMAT_BC4_SNORM;
297 case WINED3DFMT_BC5_TYPELESS: return DXGI_FORMAT_BC5_TYPELESS;
298 case WINED3DFMT_BC5_UNORM: return DXGI_FORMAT_BC5_UNORM;
299 case WINED3DFMT_BC5_SNORM: return DXGI_FORMAT_BC5_SNORM;
300 case WINED3DFMT_B5G6R5_UNORM: return DXGI_FORMAT_B5G6R5_UNORM;
301 case WINED3DFMT_B5G5R5A1_UNORM: return DXGI_FORMAT_B5G5R5A1_UNORM;
302 case WINED3DFMT_B8G8R8A8_UNORM: return DXGI_FORMAT_B8G8R8A8_UNORM;
303 case WINED3DFMT_B8G8R8X8_UNORM: return DXGI_FORMAT_B8G8R8X8_UNORM;
304 case WINED3DFMT_R10G10B10_XR_BIAS_A2_UNORM: return DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM;
305 case WINED3DFMT_B8G8R8A8_TYPELESS: return DXGI_FORMAT_B8G8R8A8_TYPELESS;
306 case WINED3DFMT_B8G8R8A8_UNORM_SRGB: return DXGI_FORMAT_B8G8R8A8_UNORM_SRGB;
307 case WINED3DFMT_B8G8R8X8_TYPELESS: return DXGI_FORMAT_B8G8R8X8_TYPELESS;
308 case WINED3DFMT_B8G8R8X8_UNORM_SRGB: return DXGI_FORMAT_B8G8R8X8_UNORM_SRGB;
309 case WINED3DFMT_BC6H_TYPELESS: return DXGI_FORMAT_BC6H_TYPELESS;
310 case WINED3DFMT_BC6H_UF16: return DXGI_FORMAT_BC6H_UF16;
311 case WINED3DFMT_BC6H_SF16: return DXGI_FORMAT_BC6H_SF16;
312 case WINED3DFMT_BC7_TYPELESS: return DXGI_FORMAT_BC7_TYPELESS;
313 case WINED3DFMT_BC7_UNORM: return DXGI_FORMAT_BC7_UNORM;
314 case WINED3DFMT_BC7_UNORM_SRGB: return DXGI_FORMAT_BC7_UNORM_SRGB;
315 case WINED3DFMT_B4G4R4A4_UNORM: return DXGI_FORMAT_B4G4R4A4_UNORM;
316 default:
317 FIXME("Unhandled wined3d format %#x.\n", format);
318 return DXGI_FORMAT_UNKNOWN;
322 enum wined3d_format_id wined3dformat_from_dxgi_format(DXGI_FORMAT format)
324 switch(format)
326 case DXGI_FORMAT_UNKNOWN: return WINED3DFMT_UNKNOWN;
327 case DXGI_FORMAT_R32G32B32A32_TYPELESS: return WINED3DFMT_R32G32B32A32_TYPELESS;
328 case DXGI_FORMAT_R32G32B32A32_FLOAT: return WINED3DFMT_R32G32B32A32_FLOAT;
329 case DXGI_FORMAT_R32G32B32A32_UINT: return WINED3DFMT_R32G32B32A32_UINT;
330 case DXGI_FORMAT_R32G32B32A32_SINT: return WINED3DFMT_R32G32B32A32_SINT;
331 case DXGI_FORMAT_R32G32B32_TYPELESS: return WINED3DFMT_R32G32B32_TYPELESS;
332 case DXGI_FORMAT_R32G32B32_FLOAT: return WINED3DFMT_R32G32B32_FLOAT;
333 case DXGI_FORMAT_R32G32B32_UINT: return WINED3DFMT_R32G32B32_UINT;
334 case DXGI_FORMAT_R32G32B32_SINT: return WINED3DFMT_R32G32B32_SINT;
335 case DXGI_FORMAT_R16G16B16A16_TYPELESS: return WINED3DFMT_R16G16B16A16_TYPELESS;
336 case DXGI_FORMAT_R16G16B16A16_FLOAT: return WINED3DFMT_R16G16B16A16_FLOAT;
337 case DXGI_FORMAT_R16G16B16A16_UNORM: return WINED3DFMT_R16G16B16A16_UNORM;
338 case DXGI_FORMAT_R16G16B16A16_UINT: return WINED3DFMT_R16G16B16A16_UINT;
339 case DXGI_FORMAT_R16G16B16A16_SNORM: return WINED3DFMT_R16G16B16A16_SNORM;
340 case DXGI_FORMAT_R16G16B16A16_SINT: return WINED3DFMT_R16G16B16A16_SINT;
341 case DXGI_FORMAT_R32G32_TYPELESS: return WINED3DFMT_R32G32_TYPELESS;
342 case DXGI_FORMAT_R32G32_FLOAT: return WINED3DFMT_R32G32_FLOAT;
343 case DXGI_FORMAT_R32G32_UINT: return WINED3DFMT_R32G32_UINT;
344 case DXGI_FORMAT_R32G32_SINT: return WINED3DFMT_R32G32_SINT;
345 case DXGI_FORMAT_R32G8X24_TYPELESS: return WINED3DFMT_R32G8X24_TYPELESS;
346 case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: return WINED3DFMT_D32_FLOAT_S8X24_UINT;
347 case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: return WINED3DFMT_R32_FLOAT_X8X24_TYPELESS;
348 case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: return WINED3DFMT_X32_TYPELESS_G8X24_UINT;
349 case DXGI_FORMAT_R10G10B10A2_TYPELESS: return WINED3DFMT_R10G10B10A2_TYPELESS;
350 case DXGI_FORMAT_R10G10B10A2_UNORM: return WINED3DFMT_R10G10B10A2_UNORM;
351 case DXGI_FORMAT_R10G10B10A2_UINT: return WINED3DFMT_R10G10B10A2_UINT;
352 case DXGI_FORMAT_R11G11B10_FLOAT: return WINED3DFMT_R11G11B10_FLOAT;
353 case DXGI_FORMAT_R8G8B8A8_TYPELESS: return WINED3DFMT_R8G8B8A8_TYPELESS;
354 case DXGI_FORMAT_R8G8B8A8_UNORM: return WINED3DFMT_R8G8B8A8_UNORM;
355 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: return WINED3DFMT_R8G8B8A8_UNORM_SRGB;
356 case DXGI_FORMAT_R8G8B8A8_UINT: return WINED3DFMT_R8G8B8A8_UINT;
357 case DXGI_FORMAT_R8G8B8A8_SNORM: return WINED3DFMT_R8G8B8A8_SNORM;
358 case DXGI_FORMAT_R8G8B8A8_SINT: return WINED3DFMT_R8G8B8A8_SINT;
359 case DXGI_FORMAT_R16G16_TYPELESS: return WINED3DFMT_R16G16_TYPELESS;
360 case DXGI_FORMAT_R16G16_FLOAT: return WINED3DFMT_R16G16_FLOAT;
361 case DXGI_FORMAT_R16G16_UNORM: return WINED3DFMT_R16G16_UNORM;
362 case DXGI_FORMAT_R16G16_UINT: return WINED3DFMT_R16G16_UINT;
363 case DXGI_FORMAT_R16G16_SNORM: return WINED3DFMT_R16G16_SNORM;
364 case DXGI_FORMAT_R16G16_SINT: return WINED3DFMT_R16G16_SINT;
365 case DXGI_FORMAT_R32_TYPELESS: return WINED3DFMT_R32_TYPELESS;
366 case DXGI_FORMAT_D32_FLOAT: return WINED3DFMT_D32_FLOAT;
367 case DXGI_FORMAT_R32_FLOAT: return WINED3DFMT_R32_FLOAT;
368 case DXGI_FORMAT_R32_UINT: return WINED3DFMT_R32_UINT;
369 case DXGI_FORMAT_R32_SINT: return WINED3DFMT_R32_SINT;
370 case DXGI_FORMAT_R24G8_TYPELESS: return WINED3DFMT_R24G8_TYPELESS;
371 case DXGI_FORMAT_D24_UNORM_S8_UINT: return WINED3DFMT_D24_UNORM_S8_UINT;
372 case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: return WINED3DFMT_R24_UNORM_X8_TYPELESS;
373 case DXGI_FORMAT_X24_TYPELESS_G8_UINT: return WINED3DFMT_X24_TYPELESS_G8_UINT;
374 case DXGI_FORMAT_R8G8_TYPELESS: return WINED3DFMT_R8G8_TYPELESS;
375 case DXGI_FORMAT_R8G8_UNORM: return WINED3DFMT_R8G8_UNORM;
376 case DXGI_FORMAT_R8G8_UINT: return WINED3DFMT_R8G8_UINT;
377 case DXGI_FORMAT_R8G8_SNORM: return WINED3DFMT_R8G8_SNORM;
378 case DXGI_FORMAT_R8G8_SINT: return WINED3DFMT_R8G8_SINT;
379 case DXGI_FORMAT_R16_TYPELESS: return WINED3DFMT_R16_TYPELESS;
380 case DXGI_FORMAT_R16_FLOAT: return WINED3DFMT_R16_FLOAT;
381 case DXGI_FORMAT_D16_UNORM: return WINED3DFMT_D16_UNORM;
382 case DXGI_FORMAT_R16_UNORM: return WINED3DFMT_R16_UNORM;
383 case DXGI_FORMAT_R16_UINT: return WINED3DFMT_R16_UINT;
384 case DXGI_FORMAT_R16_SNORM: return WINED3DFMT_R16_SNORM;
385 case DXGI_FORMAT_R16_SINT: return WINED3DFMT_R16_SINT;
386 case DXGI_FORMAT_R8_TYPELESS: return WINED3DFMT_R8_TYPELESS;
387 case DXGI_FORMAT_R8_UNORM: return WINED3DFMT_R8_UNORM;
388 case DXGI_FORMAT_R8_UINT: return WINED3DFMT_R8_UINT;
389 case DXGI_FORMAT_R8_SNORM: return WINED3DFMT_R8_SNORM;
390 case DXGI_FORMAT_R8_SINT: return WINED3DFMT_R8_SINT;
391 case DXGI_FORMAT_A8_UNORM: return WINED3DFMT_A8_UNORM;
392 case DXGI_FORMAT_R1_UNORM: return WINED3DFMT_R1_UNORM;
393 case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: return WINED3DFMT_R9G9B9E5_SHAREDEXP;
394 case DXGI_FORMAT_R8G8_B8G8_UNORM: return WINED3DFMT_R8G8_B8G8_UNORM;
395 case DXGI_FORMAT_G8R8_G8B8_UNORM: return WINED3DFMT_G8R8_G8B8_UNORM;
396 case DXGI_FORMAT_BC1_TYPELESS: return WINED3DFMT_BC1_TYPELESS;
397 case DXGI_FORMAT_BC1_UNORM: return WINED3DFMT_BC1_UNORM;
398 case DXGI_FORMAT_BC1_UNORM_SRGB: return WINED3DFMT_BC1_UNORM_SRGB;
399 case DXGI_FORMAT_BC2_TYPELESS: return WINED3DFMT_BC2_TYPELESS;
400 case DXGI_FORMAT_BC2_UNORM: return WINED3DFMT_BC2_UNORM;
401 case DXGI_FORMAT_BC2_UNORM_SRGB: return WINED3DFMT_BC2_UNORM_SRGB;
402 case DXGI_FORMAT_BC3_TYPELESS: return WINED3DFMT_BC3_TYPELESS;
403 case DXGI_FORMAT_BC3_UNORM: return WINED3DFMT_BC3_UNORM;
404 case DXGI_FORMAT_BC3_UNORM_SRGB: return WINED3DFMT_BC3_UNORM_SRGB;
405 case DXGI_FORMAT_BC4_TYPELESS: return WINED3DFMT_BC4_TYPELESS;
406 case DXGI_FORMAT_BC4_UNORM: return WINED3DFMT_BC4_UNORM;
407 case DXGI_FORMAT_BC4_SNORM: return WINED3DFMT_BC4_SNORM;
408 case DXGI_FORMAT_BC5_TYPELESS: return WINED3DFMT_BC5_TYPELESS;
409 case DXGI_FORMAT_BC5_UNORM: return WINED3DFMT_BC5_UNORM;
410 case DXGI_FORMAT_BC5_SNORM: return WINED3DFMT_BC5_SNORM;
411 case DXGI_FORMAT_B5G6R5_UNORM: return WINED3DFMT_B5G6R5_UNORM;
412 case DXGI_FORMAT_B5G5R5A1_UNORM: return WINED3DFMT_B5G5R5A1_UNORM;
413 case DXGI_FORMAT_B8G8R8A8_UNORM: return WINED3DFMT_B8G8R8A8_UNORM;
414 case DXGI_FORMAT_B8G8R8X8_UNORM: return WINED3DFMT_B8G8R8X8_UNORM;
415 case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM: return WINED3DFMT_R10G10B10_XR_BIAS_A2_UNORM;
416 case DXGI_FORMAT_B8G8R8A8_TYPELESS: return WINED3DFMT_B8G8R8A8_TYPELESS;
417 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: return WINED3DFMT_B8G8R8A8_UNORM_SRGB;
418 case DXGI_FORMAT_B8G8R8X8_TYPELESS: return WINED3DFMT_B8G8R8X8_TYPELESS;
419 case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: return WINED3DFMT_B8G8R8X8_UNORM_SRGB;
420 case DXGI_FORMAT_BC6H_TYPELESS: return WINED3DFMT_BC6H_TYPELESS;
421 case DXGI_FORMAT_BC6H_UF16: return WINED3DFMT_BC6H_UF16;
422 case DXGI_FORMAT_BC6H_SF16: return WINED3DFMT_BC6H_SF16;
423 case DXGI_FORMAT_BC7_TYPELESS: return WINED3DFMT_BC7_TYPELESS;
424 case DXGI_FORMAT_BC7_UNORM: return WINED3DFMT_BC7_UNORM;
425 case DXGI_FORMAT_BC7_UNORM_SRGB: return WINED3DFMT_BC7_UNORM_SRGB;
426 case DXGI_FORMAT_B4G4R4A4_UNORM: return WINED3DFMT_B4G4R4A4_UNORM;
427 default:
428 FIXME("Unhandled DXGI_FORMAT %#x.\n", format);
429 return WINED3DFMT_UNKNOWN;
433 unsigned int wined3d_getdata_flags_from_d3d11_async_getdata_flags(unsigned int d3d11_flags)
435 if (d3d11_flags & ~D3D11_ASYNC_GETDATA_DONOTFLUSH)
436 FIXME("Unhandled async getdata flags %#x.\n", d3d11_flags);
438 if (d3d11_flags & D3D11_ASYNC_GETDATA_DONOTFLUSH)
439 return 0;
441 return WINED3DGETDATA_FLUSH;
444 UINT d3d11_bind_flags_from_wined3d_usage(DWORD wined3d_usage)
446 UINT bind_flags = 0;
448 if (wined3d_usage & WINED3DUSAGE_TEXTURE)
449 bind_flags |= D3D11_BIND_SHADER_RESOURCE;
450 if (wined3d_usage & WINED3DUSAGE_RENDERTARGET)
451 bind_flags |= D3D11_BIND_RENDER_TARGET;
453 wined3d_usage &= ~(WINED3DUSAGE_TEXTURE | WINED3DUSAGE_RENDERTARGET);
454 if (wined3d_usage)
455 FIXME("Unhandled wined3d usage %#x.\n", wined3d_usage);
456 return bind_flags;
459 DWORD wined3d_usage_from_d3d11(UINT bind_flags, enum D3D11_USAGE usage)
461 static const DWORD handled = D3D11_BIND_SHADER_RESOURCE
462 | D3D11_BIND_RENDER_TARGET
463 | D3D11_BIND_DEPTH_STENCIL;
464 DWORD wined3d_usage = 0;
466 if (bind_flags & D3D11_BIND_SHADER_RESOURCE)
467 wined3d_usage |= WINED3DUSAGE_TEXTURE;
468 if (bind_flags & D3D11_BIND_RENDER_TARGET)
469 wined3d_usage |= WINED3DUSAGE_RENDERTARGET;
470 if (bind_flags & D3D11_BIND_DEPTH_STENCIL)
471 wined3d_usage |= WINED3DUSAGE_DEPTHSTENCIL;
472 if (bind_flags & ~handled)
473 FIXME("Unhandled bind flags %#x.\n", bind_flags & ~handled);
475 if (usage == D3D11_USAGE_DYNAMIC)
476 wined3d_usage |= WINED3DUSAGE_DYNAMIC;
478 return wined3d_usage;
481 enum D3D11_USAGE d3d11_usage_from_d3d10_usage(enum D3D10_USAGE usage)
483 switch (usage)
485 case D3D10_USAGE_DEFAULT: return D3D11_USAGE_DEFAULT;
486 case D3D10_USAGE_IMMUTABLE: return D3D11_USAGE_IMMUTABLE;
487 case D3D10_USAGE_DYNAMIC: return D3D11_USAGE_DYNAMIC;
488 case D3D10_USAGE_STAGING: return D3D11_USAGE_STAGING;
489 default:
490 FIXME("Unhandled usage %#x.\n", usage);
491 return D3D11_USAGE_DEFAULT;
495 enum D3D10_USAGE d3d10_usage_from_d3d11_usage(enum D3D11_USAGE usage)
497 switch (usage)
499 case D3D11_USAGE_DEFAULT: return D3D10_USAGE_DEFAULT;
500 case D3D11_USAGE_IMMUTABLE: return D3D10_USAGE_IMMUTABLE;
501 case D3D11_USAGE_DYNAMIC: return D3D10_USAGE_DYNAMIC;
502 case D3D11_USAGE_STAGING: return D3D10_USAGE_STAGING;
503 default:
504 FIXME("Unhandled usage %#x.\n", usage);
505 return D3D10_USAGE_DEFAULT;
509 UINT d3d11_bind_flags_from_d3d10_bind_flags(UINT bind_flags)
511 static const UINT handled_flags = D3D10_BIND_VERTEX_BUFFER
512 | D3D10_BIND_INDEX_BUFFER
513 | D3D10_BIND_CONSTANT_BUFFER
514 | D3D10_BIND_SHADER_RESOURCE
515 | D3D10_BIND_STREAM_OUTPUT
516 | D3D10_BIND_RENDER_TARGET
517 | D3D10_BIND_DEPTH_STENCIL;
518 UINT d3d11_bind_flags = bind_flags & handled_flags;
520 if (bind_flags & ~handled_flags)
521 FIXME("Unhandled bind flags %#x.\n", bind_flags & ~handled_flags);
523 return d3d11_bind_flags;
526 UINT d3d10_bind_flags_from_d3d11_bind_flags(UINT bind_flags)
528 static const UINT handled_flags = D3D11_BIND_VERTEX_BUFFER
529 | D3D11_BIND_INDEX_BUFFER
530 | D3D11_BIND_CONSTANT_BUFFER
531 | D3D11_BIND_SHADER_RESOURCE
532 | D3D11_BIND_STREAM_OUTPUT
533 | D3D11_BIND_RENDER_TARGET
534 | D3D11_BIND_DEPTH_STENCIL
535 | D3D11_BIND_UNORDERED_ACCESS
536 | D3D11_BIND_DECODER
537 | D3D11_BIND_VIDEO_ENCODER;
538 UINT d3d10_bind_flags = bind_flags & handled_flags;
540 if (bind_flags & ~handled_flags)
541 FIXME("Unhandled bind flags %#x.\n", bind_flags & ~handled_flags);
543 return d3d10_bind_flags;
546 UINT d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(UINT cpu_access_flags)
548 static const UINT handled_flags = D3D10_CPU_ACCESS_WRITE
549 | D3D10_CPU_ACCESS_READ;
550 UINT d3d11_cpu_access_flags = cpu_access_flags & handled_flags;
552 if (cpu_access_flags & ~handled_flags)
553 FIXME("Unhandled cpu access flags %#x.\n", cpu_access_flags & ~handled_flags);
555 return d3d11_cpu_access_flags;
558 UINT d3d10_cpu_access_flags_from_d3d11_cpu_access_flags(UINT cpu_access_flags)
560 static const UINT handled_flags = D3D11_CPU_ACCESS_WRITE
561 | D3D11_CPU_ACCESS_READ;
562 UINT d3d10_cpu_access_flags = cpu_access_flags & handled_flags;
564 if (cpu_access_flags & ~handled_flags)
565 FIXME("Unhandled cpu access flags %#x.\n", cpu_access_flags & ~handled_flags);
567 return d3d10_cpu_access_flags;
570 UINT d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(UINT resource_misc_flags)
572 static const UINT bitwise_identical_flags = D3D10_RESOURCE_MISC_GENERATE_MIPS
573 | D3D10_RESOURCE_MISC_SHARED
574 | D3D10_RESOURCE_MISC_TEXTURECUBE;
575 const UINT handled_flags = bitwise_identical_flags
576 | D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
577 | D3D10_RESOURCE_MISC_GDI_COMPATIBLE;
578 UINT d3d11_resource_misc_flags = resource_misc_flags & bitwise_identical_flags;
580 if (resource_misc_flags & D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX)
581 d3d11_resource_misc_flags |= D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
582 if (resource_misc_flags & D3D10_RESOURCE_MISC_GDI_COMPATIBLE)
583 d3d11_resource_misc_flags |= D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
585 if (resource_misc_flags & ~handled_flags)
586 FIXME("Unhandled resource misc flags %#x.\n", resource_misc_flags & ~handled_flags);
588 return d3d11_resource_misc_flags;
591 UINT d3d10_resource_misc_flags_from_d3d11_resource_misc_flags(UINT resource_misc_flags)
593 static const UINT bitwise_identical_flags = D3D11_RESOURCE_MISC_GENERATE_MIPS
594 | D3D11_RESOURCE_MISC_SHARED
595 | D3D11_RESOURCE_MISC_TEXTURECUBE;
596 const UINT handled_flags = bitwise_identical_flags
597 | D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS
598 | D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS
599 | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
600 | D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX
601 | D3D11_RESOURCE_MISC_GDI_COMPATIBLE
602 | D3D11_RESOURCE_MISC_SHARED_NTHANDLE;
603 UINT d3d10_resource_misc_flags = resource_misc_flags & bitwise_identical_flags;
605 if (resource_misc_flags & D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX)
606 d3d10_resource_misc_flags |= D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX;
607 if (resource_misc_flags & D3D11_RESOURCE_MISC_GDI_COMPATIBLE)
608 d3d10_resource_misc_flags |= D3D10_RESOURCE_MISC_GDI_COMPATIBLE;
610 if (resource_misc_flags & ~handled_flags)
611 FIXME("Unhandled resource misc flags #%x.\n", resource_misc_flags & ~handled_flags);
613 return d3d10_resource_misc_flags;
616 static BOOL d3d11_bind_flags_are_gpu_read_only(UINT bind_flags)
618 static const BOOL read_only_bind_flags = D3D11_BIND_VERTEX_BUFFER
619 | D3D11_BIND_INDEX_BUFFER | D3D11_BIND_CONSTANT_BUFFER
620 | D3D11_BIND_SHADER_RESOURCE;
622 return !(bind_flags & ~read_only_bind_flags);
625 BOOL validate_d3d11_resource_access_flags(D3D11_RESOURCE_DIMENSION resource_dimension,
626 D3D11_USAGE usage, UINT bind_flags, UINT cpu_access_flags, D3D_FEATURE_LEVEL feature_level)
628 const BOOL is_texture = resource_dimension != D3D11_RESOURCE_DIMENSION_BUFFER;
630 switch (usage)
632 case D3D11_USAGE_DEFAULT:
633 if ((bind_flags == D3D11_BIND_SHADER_RESOURCE && feature_level >= D3D_FEATURE_LEVEL_11_0)
634 || (is_texture && bind_flags == D3D11_BIND_RENDER_TARGET)
635 || bind_flags == D3D11_BIND_UNORDERED_ACCESS)
636 break;
637 if (cpu_access_flags)
639 WARN("Default resources are not CPU accessible.\n");
640 return FALSE;
642 break;
644 case D3D11_USAGE_IMMUTABLE:
645 if (!bind_flags)
647 WARN("Bind flags must be non-zero for immutable resources.\n");
648 return FALSE;
650 if (!d3d11_bind_flags_are_gpu_read_only(bind_flags))
652 WARN("Immutable resources cannot be writable by GPU.\n");
653 return FALSE;
656 if (cpu_access_flags)
658 WARN("Immutable resources are not CPU accessible.\n");
659 return FALSE;
661 break;
663 case D3D11_USAGE_DYNAMIC:
664 if (!bind_flags)
666 WARN("Bind flags must be non-zero for dynamic resources.\n");
667 return FALSE;
669 if (!d3d11_bind_flags_are_gpu_read_only(bind_flags))
671 WARN("Dynamic resources cannot be writable by GPU.\n");
672 return FALSE;
675 if (cpu_access_flags != D3D11_CPU_ACCESS_WRITE)
677 WARN("CPU access must be D3D11_CPU_ACCESS_WRITE for dynamic resources.\n");
678 return FALSE;
680 break;
682 case D3D11_USAGE_STAGING:
683 if (bind_flags)
685 WARN("Invalid bind flags %#x for staging resources.\n", bind_flags);
686 return FALSE;
689 if (!cpu_access_flags)
691 WARN("CPU access must be non-zero for staging resources.\n");
692 return FALSE;
694 break;
696 default:
697 WARN("Invalid usage %#x.\n", usage);
698 return FALSE;
701 return TRUE;
704 struct wined3d_resource *wined3d_resource_from_d3d11_resource(ID3D11Resource *resource)
706 D3D11_RESOURCE_DIMENSION dimension;
708 ID3D11Resource_GetType(resource, &dimension);
710 switch (dimension)
712 case D3D11_RESOURCE_DIMENSION_BUFFER:
713 return wined3d_buffer_get_resource(unsafe_impl_from_ID3D11Buffer(
714 (ID3D11Buffer *)resource)->wined3d_buffer);
716 case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
717 return wined3d_texture_get_resource(unsafe_impl_from_ID3D11Texture1D(
718 (ID3D11Texture1D *)resource)->wined3d_texture);
720 case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
721 return wined3d_texture_get_resource(unsafe_impl_from_ID3D11Texture2D(
722 (ID3D11Texture2D *)resource)->wined3d_texture);
724 case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
725 return wined3d_texture_get_resource(unsafe_impl_from_ID3D11Texture3D(
726 (ID3D11Texture3D *)resource)->wined3d_texture);
728 default:
729 FIXME("Unhandled resource dimension %#x.\n", dimension);
730 return NULL;
734 struct wined3d_resource *wined3d_resource_from_d3d10_resource(ID3D10Resource *resource)
736 D3D10_RESOURCE_DIMENSION dimension;
738 ID3D10Resource_GetType(resource, &dimension);
740 switch (dimension)
742 case D3D10_RESOURCE_DIMENSION_BUFFER:
743 return wined3d_buffer_get_resource(unsafe_impl_from_ID3D10Buffer(
744 (ID3D10Buffer *)resource)->wined3d_buffer);
746 case D3D10_RESOURCE_DIMENSION_TEXTURE1D:
747 return wined3d_texture_get_resource(unsafe_impl_from_ID3D10Texture1D(
748 (ID3D10Texture1D *)resource)->wined3d_texture);
750 case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
751 return wined3d_texture_get_resource(unsafe_impl_from_ID3D10Texture2D(
752 (ID3D10Texture2D *)resource)->wined3d_texture);
754 case D3D10_RESOURCE_DIMENSION_TEXTURE3D:
755 return wined3d_texture_get_resource(unsafe_impl_from_ID3D10Texture3D(
756 (ID3D10Texture3D *)resource)->wined3d_texture);
758 default:
759 FIXME("Unhandled resource dimension %#x.\n", dimension);
760 return NULL;
764 DWORD wined3d_map_flags_from_d3d11_map_type(D3D11_MAP map_type)
766 switch (map_type)
768 case D3D11_MAP_WRITE:
769 return WINED3D_MAP_WRITE;
771 case D3D11_MAP_READ_WRITE:
772 return WINED3D_MAP_READ | WINED3D_MAP_WRITE;
774 case D3D11_MAP_READ:
775 return WINED3D_MAP_READ;
777 case D3D11_MAP_WRITE_DISCARD:
778 return WINED3D_MAP_WRITE | WINED3D_MAP_DISCARD;
780 case D3D11_MAP_WRITE_NO_OVERWRITE:
781 return WINED3D_MAP_WRITE | WINED3D_MAP_NOOVERWRITE;
783 default:
784 FIXME("Unhandled map_type %#x.\n", map_type);
785 return WINED3D_MAP_READ | WINED3D_MAP_WRITE;
789 DWORD wined3d_clear_flags_from_d3d11_clear_flags(UINT clear_flags)
791 DWORD wined3d_clear_flags = 0;
793 if (clear_flags & D3D11_CLEAR_DEPTH)
794 wined3d_clear_flags |= WINED3DCLEAR_ZBUFFER;
795 if (clear_flags & D3D11_CLEAR_STENCIL)
796 wined3d_clear_flags |= WINED3DCLEAR_STENCIL;
798 if (clear_flags & ~(D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL))
800 FIXME("Unhandled clear flags %#x.\n",
801 clear_flags & ~(D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL));
804 return wined3d_clear_flags;
807 unsigned int wined3d_access_from_d3d11(D3D11_USAGE usage, UINT cpu_access)
809 unsigned int access;
811 access = usage == D3D11_USAGE_STAGING ? WINED3D_RESOURCE_ACCESS_CPU : WINED3D_RESOURCE_ACCESS_GPU;
812 if (cpu_access & D3D11_CPU_ACCESS_WRITE)
813 access |= WINED3D_RESOURCE_ACCESS_MAP_W;
814 if (cpu_access & D3D11_CPU_ACCESS_READ)
815 access |= WINED3D_RESOURCE_ACCESS_MAP_R;
816 if (cpu_access &= ~(D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ))
817 FIXME("Unhandled CPU access flags %#x.\n", cpu_access);
819 return access;
822 HRESULT d3d_get_private_data(struct wined3d_private_store *store,
823 REFGUID guid, UINT *data_size, void *data)
825 const struct wined3d_private_data *stored_data;
826 DWORD size_in;
828 if (!data_size)
829 return E_INVALIDARG;
831 wined3d_mutex_lock();
832 if (!(stored_data = wined3d_private_store_get_private_data(store, guid)))
834 *data_size = 0;
835 wined3d_mutex_unlock();
836 return DXGI_ERROR_NOT_FOUND;
839 size_in = *data_size;
840 *data_size = stored_data->size;
841 if (!data)
843 wined3d_mutex_unlock();
844 return S_OK;
846 if (size_in < stored_data->size)
848 wined3d_mutex_unlock();
849 return DXGI_ERROR_MORE_DATA;
852 if (stored_data->flags & WINED3DSPD_IUNKNOWN)
853 IUnknown_AddRef(stored_data->content.object);
854 memcpy(data, stored_data->content.data, stored_data->size);
856 wined3d_mutex_unlock();
857 return S_OK;
860 HRESULT d3d_set_private_data(struct wined3d_private_store *store,
861 REFGUID guid, UINT data_size, const void *data)
863 struct wined3d_private_data *entry;
864 HRESULT hr;
866 wined3d_mutex_lock();
867 if (!data)
869 if (!(entry = wined3d_private_store_get_private_data(store, guid)))
871 wined3d_mutex_unlock();
872 return S_FALSE;
874 wined3d_private_store_free_private_data(store, entry);
875 wined3d_mutex_unlock();
877 return S_OK;
880 hr = wined3d_private_store_set_private_data(store, guid, data, data_size, 0);
881 wined3d_mutex_unlock();
883 return hr;
886 HRESULT d3d_set_private_data_interface(struct wined3d_private_store *store,
887 REFGUID guid, const IUnknown *object)
889 HRESULT hr;
891 if (!object)
892 return d3d_set_private_data(store, guid, sizeof(object), &object);
894 wined3d_mutex_lock();
895 hr = wined3d_private_store_set_private_data(store,
896 guid, object, sizeof(object), WINED3DSPD_IUNKNOWN);
897 wined3d_mutex_unlock();
899 return hr;
902 void skip_dword_unknown(const char **ptr, unsigned int count)
904 unsigned int i;
905 DWORD d;
907 WARN("Skipping %u unknown DWORDs:\n", count);
908 for (i = 0; i < count; ++i)
910 read_dword(ptr, &d);
911 WARN("\t0x%08x\n", d);
915 HRESULT parse_dxbc(const char *data, SIZE_T data_size,
916 HRESULT (*chunk_handler)(const char *data, DWORD data_size, DWORD tag, void *ctx), void *ctx)
918 const char *ptr = data;
919 HRESULT hr = S_OK;
920 DWORD chunk_count;
921 DWORD total_size;
922 unsigned int i;
923 DWORD version;
924 DWORD tag;
926 read_dword(&ptr, &tag);
927 TRACE("tag: %s.\n", debugstr_an((const char *)&tag, 4));
929 if (tag != TAG_DXBC)
931 WARN("Wrong tag.\n");
932 return E_INVALIDARG;
935 WARN("Ignoring DXBC checksum.\n");
936 skip_dword_unknown(&ptr, 4);
938 read_dword(&ptr, &version);
939 TRACE("version: %#x.\n", version);
940 if (version != 0x00000001)
942 WARN("Got unexpected DXBC version %#x.\n", version);
943 return E_INVALIDARG;
946 read_dword(&ptr, &total_size);
947 TRACE("total size: %#x\n", total_size);
949 read_dword(&ptr, &chunk_count);
950 TRACE("chunk count: %#x\n", chunk_count);
952 for (i = 0; i < chunk_count; ++i)
954 DWORD chunk_tag, chunk_size;
955 const char *chunk_ptr;
956 DWORD chunk_offset;
958 read_dword(&ptr, &chunk_offset);
959 TRACE("chunk %u at offset %#x\n", i, chunk_offset);
961 if (chunk_offset >= data_size || !require_space(chunk_offset, 2, sizeof(DWORD), data_size))
963 WARN("Invalid chunk offset %#x (data size %#lx).\n", chunk_offset, data_size);
964 return E_FAIL;
967 chunk_ptr = data + chunk_offset;
969 read_dword(&chunk_ptr, &chunk_tag);
970 read_dword(&chunk_ptr, &chunk_size);
972 if (!require_space(chunk_ptr - data, 1, chunk_size, data_size))
974 WARN("Invalid chunk size %#x (data size %#lx, chunk offset %#x).\n", chunk_size, data_size, chunk_offset);
975 return E_FAIL;
978 hr = chunk_handler(chunk_ptr, chunk_size, chunk_tag, ctx);
979 if (FAILED(hr)) break;
982 return hr;