winspool/tests: Add tests for GetFormA().
[wine.git] / dlls / d3d11 / utils.c
blob1a0be470f3865d329bf24c0210e82e04066bb609
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 "d3d11_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
24 #define WINE_D3D_TO_STR(x) case x: return #x
26 const char *debug_d3d10_primitive_topology(D3D10_PRIMITIVE_TOPOLOGY topology)
28 switch (topology)
30 WINE_D3D_TO_STR(D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED);
31 WINE_D3D_TO_STR(D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
32 WINE_D3D_TO_STR(D3D10_PRIMITIVE_TOPOLOGY_LINELIST);
33 WINE_D3D_TO_STR(D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP);
34 WINE_D3D_TO_STR(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
35 WINE_D3D_TO_STR(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
36 WINE_D3D_TO_STR(D3D10_PRIMITIVE_TOPOLOGY_LINELIST_ADJ);
37 WINE_D3D_TO_STR(D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ);
38 WINE_D3D_TO_STR(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ);
39 WINE_D3D_TO_STR(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ);
40 default:
41 FIXME("Unrecognized D3D10_PRIMITIVE_TOPOLOGY %#x\n", topology);
42 return "unrecognized";
46 const char *debug_dxgi_format(DXGI_FORMAT format)
48 switch(format)
50 WINE_D3D_TO_STR(DXGI_FORMAT_UNKNOWN);
51 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32B32A32_TYPELESS);
52 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32B32A32_FLOAT);
53 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32B32A32_UINT);
54 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32B32A32_SINT);
55 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32B32_TYPELESS);
56 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32B32_FLOAT);
57 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32B32_UINT);
58 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32B32_SINT);
59 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16B16A16_TYPELESS);
60 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16B16A16_FLOAT);
61 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16B16A16_UNORM);
62 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16B16A16_UINT);
63 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16B16A16_SNORM);
64 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16B16A16_SINT);
65 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32_TYPELESS);
66 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32_FLOAT);
67 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32_UINT);
68 WINE_D3D_TO_STR(DXGI_FORMAT_R32G32_SINT);
69 WINE_D3D_TO_STR(DXGI_FORMAT_R32G8X24_TYPELESS);
70 WINE_D3D_TO_STR(DXGI_FORMAT_D32_FLOAT_S8X24_UINT);
71 WINE_D3D_TO_STR(DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS);
72 WINE_D3D_TO_STR(DXGI_FORMAT_X32_TYPELESS_G8X24_UINT);
73 WINE_D3D_TO_STR(DXGI_FORMAT_R10G10B10A2_TYPELESS);
74 WINE_D3D_TO_STR(DXGI_FORMAT_R10G10B10A2_UNORM);
75 WINE_D3D_TO_STR(DXGI_FORMAT_R10G10B10A2_UINT);
76 WINE_D3D_TO_STR(DXGI_FORMAT_R11G11B10_FLOAT);
77 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8B8A8_TYPELESS);
78 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8B8A8_UNORM);
79 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB);
80 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8B8A8_UINT);
81 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8B8A8_SNORM);
82 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8B8A8_SINT);
83 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16_TYPELESS);
84 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16_FLOAT);
85 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16_UNORM);
86 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16_UINT);
87 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16_SNORM);
88 WINE_D3D_TO_STR(DXGI_FORMAT_R16G16_SINT);
89 WINE_D3D_TO_STR(DXGI_FORMAT_R32_TYPELESS);
90 WINE_D3D_TO_STR(DXGI_FORMAT_D32_FLOAT);
91 WINE_D3D_TO_STR(DXGI_FORMAT_R32_FLOAT);
92 WINE_D3D_TO_STR(DXGI_FORMAT_R32_UINT);
93 WINE_D3D_TO_STR(DXGI_FORMAT_R32_SINT);
94 WINE_D3D_TO_STR(DXGI_FORMAT_R24G8_TYPELESS);
95 WINE_D3D_TO_STR(DXGI_FORMAT_D24_UNORM_S8_UINT);
96 WINE_D3D_TO_STR(DXGI_FORMAT_R24_UNORM_X8_TYPELESS);
97 WINE_D3D_TO_STR(DXGI_FORMAT_X24_TYPELESS_G8_UINT);
98 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8_TYPELESS);
99 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8_UNORM);
100 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8_UINT);
101 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8_SNORM);
102 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8_SINT);
103 WINE_D3D_TO_STR(DXGI_FORMAT_R16_TYPELESS);
104 WINE_D3D_TO_STR(DXGI_FORMAT_R16_FLOAT);
105 WINE_D3D_TO_STR(DXGI_FORMAT_D16_UNORM);
106 WINE_D3D_TO_STR(DXGI_FORMAT_R16_UNORM);
107 WINE_D3D_TO_STR(DXGI_FORMAT_R16_UINT);
108 WINE_D3D_TO_STR(DXGI_FORMAT_R16_SNORM);
109 WINE_D3D_TO_STR(DXGI_FORMAT_R16_SINT);
110 WINE_D3D_TO_STR(DXGI_FORMAT_R8_TYPELESS);
111 WINE_D3D_TO_STR(DXGI_FORMAT_R8_UNORM);
112 WINE_D3D_TO_STR(DXGI_FORMAT_R8_UINT);
113 WINE_D3D_TO_STR(DXGI_FORMAT_R8_SNORM);
114 WINE_D3D_TO_STR(DXGI_FORMAT_R8_SINT);
115 WINE_D3D_TO_STR(DXGI_FORMAT_A8_UNORM);
116 WINE_D3D_TO_STR(DXGI_FORMAT_R1_UNORM);
117 WINE_D3D_TO_STR(DXGI_FORMAT_R9G9B9E5_SHAREDEXP);
118 WINE_D3D_TO_STR(DXGI_FORMAT_R8G8_B8G8_UNORM);
119 WINE_D3D_TO_STR(DXGI_FORMAT_G8R8_G8B8_UNORM);
120 WINE_D3D_TO_STR(DXGI_FORMAT_BC1_TYPELESS);
121 WINE_D3D_TO_STR(DXGI_FORMAT_BC1_UNORM);
122 WINE_D3D_TO_STR(DXGI_FORMAT_BC1_UNORM_SRGB);
123 WINE_D3D_TO_STR(DXGI_FORMAT_BC2_TYPELESS);
124 WINE_D3D_TO_STR(DXGI_FORMAT_BC2_UNORM);
125 WINE_D3D_TO_STR(DXGI_FORMAT_BC2_UNORM_SRGB);
126 WINE_D3D_TO_STR(DXGI_FORMAT_BC3_TYPELESS);
127 WINE_D3D_TO_STR(DXGI_FORMAT_BC3_UNORM);
128 WINE_D3D_TO_STR(DXGI_FORMAT_BC3_UNORM_SRGB);
129 WINE_D3D_TO_STR(DXGI_FORMAT_BC4_TYPELESS);
130 WINE_D3D_TO_STR(DXGI_FORMAT_BC4_UNORM);
131 WINE_D3D_TO_STR(DXGI_FORMAT_BC4_SNORM);
132 WINE_D3D_TO_STR(DXGI_FORMAT_BC5_TYPELESS);
133 WINE_D3D_TO_STR(DXGI_FORMAT_BC5_UNORM);
134 WINE_D3D_TO_STR(DXGI_FORMAT_BC5_SNORM);
135 WINE_D3D_TO_STR(DXGI_FORMAT_B5G6R5_UNORM);
136 WINE_D3D_TO_STR(DXGI_FORMAT_B5G5R5A1_UNORM);
137 WINE_D3D_TO_STR(DXGI_FORMAT_B8G8R8A8_UNORM);
138 WINE_D3D_TO_STR(DXGI_FORMAT_B8G8R8X8_UNORM);
139 WINE_D3D_TO_STR(DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM);
140 WINE_D3D_TO_STR(DXGI_FORMAT_B8G8R8A8_TYPELESS);
141 WINE_D3D_TO_STR(DXGI_FORMAT_B8G8R8A8_UNORM_SRGB);
142 WINE_D3D_TO_STR(DXGI_FORMAT_B8G8R8X8_TYPELESS);
143 WINE_D3D_TO_STR(DXGI_FORMAT_B8G8R8X8_UNORM_SRGB);
144 WINE_D3D_TO_STR(DXGI_FORMAT_BC6H_TYPELESS);
145 WINE_D3D_TO_STR(DXGI_FORMAT_BC6H_UF16);
146 WINE_D3D_TO_STR(DXGI_FORMAT_BC6H_SF16);
147 WINE_D3D_TO_STR(DXGI_FORMAT_BC7_TYPELESS);
148 WINE_D3D_TO_STR(DXGI_FORMAT_BC7_UNORM);
149 WINE_D3D_TO_STR(DXGI_FORMAT_BC7_UNORM_SRGB);
150 WINE_D3D_TO_STR(DXGI_FORMAT_NV12);
151 WINE_D3D_TO_STR(DXGI_FORMAT_YUY2);
152 WINE_D3D_TO_STR(DXGI_FORMAT_B4G4R4A4_UNORM);
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 case WINED3DFMT_NV12: return DXGI_FORMAT_NV12;
315 case WINED3DFMT_YUY2: return DXGI_FORMAT_YUY2;
316 case WINED3DFMT_B4G4R4A4_UNORM: return DXGI_FORMAT_B4G4R4A4_UNORM;
317 default:
318 FIXME("Unhandled wined3d format %#x.\n", format);
319 return DXGI_FORMAT_UNKNOWN;
323 enum wined3d_format_id wined3dformat_from_dxgi_format(DXGI_FORMAT format)
325 switch(format)
327 case DXGI_FORMAT_UNKNOWN: return WINED3DFMT_UNKNOWN;
328 case DXGI_FORMAT_R32G32B32A32_TYPELESS: return WINED3DFMT_R32G32B32A32_TYPELESS;
329 case DXGI_FORMAT_R32G32B32A32_FLOAT: return WINED3DFMT_R32G32B32A32_FLOAT;
330 case DXGI_FORMAT_R32G32B32A32_UINT: return WINED3DFMT_R32G32B32A32_UINT;
331 case DXGI_FORMAT_R32G32B32A32_SINT: return WINED3DFMT_R32G32B32A32_SINT;
332 case DXGI_FORMAT_R32G32B32_TYPELESS: return WINED3DFMT_R32G32B32_TYPELESS;
333 case DXGI_FORMAT_R32G32B32_FLOAT: return WINED3DFMT_R32G32B32_FLOAT;
334 case DXGI_FORMAT_R32G32B32_UINT: return WINED3DFMT_R32G32B32_UINT;
335 case DXGI_FORMAT_R32G32B32_SINT: return WINED3DFMT_R32G32B32_SINT;
336 case DXGI_FORMAT_R16G16B16A16_TYPELESS: return WINED3DFMT_R16G16B16A16_TYPELESS;
337 case DXGI_FORMAT_R16G16B16A16_FLOAT: return WINED3DFMT_R16G16B16A16_FLOAT;
338 case DXGI_FORMAT_R16G16B16A16_UNORM: return WINED3DFMT_R16G16B16A16_UNORM;
339 case DXGI_FORMAT_R16G16B16A16_UINT: return WINED3DFMT_R16G16B16A16_UINT;
340 case DXGI_FORMAT_R16G16B16A16_SNORM: return WINED3DFMT_R16G16B16A16_SNORM;
341 case DXGI_FORMAT_R16G16B16A16_SINT: return WINED3DFMT_R16G16B16A16_SINT;
342 case DXGI_FORMAT_R32G32_TYPELESS: return WINED3DFMT_R32G32_TYPELESS;
343 case DXGI_FORMAT_R32G32_FLOAT: return WINED3DFMT_R32G32_FLOAT;
344 case DXGI_FORMAT_R32G32_UINT: return WINED3DFMT_R32G32_UINT;
345 case DXGI_FORMAT_R32G32_SINT: return WINED3DFMT_R32G32_SINT;
346 case DXGI_FORMAT_R32G8X24_TYPELESS: return WINED3DFMT_R32G8X24_TYPELESS;
347 case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: return WINED3DFMT_D32_FLOAT_S8X24_UINT;
348 case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: return WINED3DFMT_R32_FLOAT_X8X24_TYPELESS;
349 case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: return WINED3DFMT_X32_TYPELESS_G8X24_UINT;
350 case DXGI_FORMAT_R10G10B10A2_TYPELESS: return WINED3DFMT_R10G10B10A2_TYPELESS;
351 case DXGI_FORMAT_R10G10B10A2_UNORM: return WINED3DFMT_R10G10B10A2_UNORM;
352 case DXGI_FORMAT_R10G10B10A2_UINT: return WINED3DFMT_R10G10B10A2_UINT;
353 case DXGI_FORMAT_R11G11B10_FLOAT: return WINED3DFMT_R11G11B10_FLOAT;
354 case DXGI_FORMAT_R8G8B8A8_TYPELESS: return WINED3DFMT_R8G8B8A8_TYPELESS;
355 case DXGI_FORMAT_R8G8B8A8_UNORM: return WINED3DFMT_R8G8B8A8_UNORM;
356 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: return WINED3DFMT_R8G8B8A8_UNORM_SRGB;
357 case DXGI_FORMAT_R8G8B8A8_UINT: return WINED3DFMT_R8G8B8A8_UINT;
358 case DXGI_FORMAT_R8G8B8A8_SNORM: return WINED3DFMT_R8G8B8A8_SNORM;
359 case DXGI_FORMAT_R8G8B8A8_SINT: return WINED3DFMT_R8G8B8A8_SINT;
360 case DXGI_FORMAT_R16G16_TYPELESS: return WINED3DFMT_R16G16_TYPELESS;
361 case DXGI_FORMAT_R16G16_FLOAT: return WINED3DFMT_R16G16_FLOAT;
362 case DXGI_FORMAT_R16G16_UNORM: return WINED3DFMT_R16G16_UNORM;
363 case DXGI_FORMAT_R16G16_UINT: return WINED3DFMT_R16G16_UINT;
364 case DXGI_FORMAT_R16G16_SNORM: return WINED3DFMT_R16G16_SNORM;
365 case DXGI_FORMAT_R16G16_SINT: return WINED3DFMT_R16G16_SINT;
366 case DXGI_FORMAT_R32_TYPELESS: return WINED3DFMT_R32_TYPELESS;
367 case DXGI_FORMAT_D32_FLOAT: return WINED3DFMT_D32_FLOAT;
368 case DXGI_FORMAT_R32_FLOAT: return WINED3DFMT_R32_FLOAT;
369 case DXGI_FORMAT_R32_UINT: return WINED3DFMT_R32_UINT;
370 case DXGI_FORMAT_R32_SINT: return WINED3DFMT_R32_SINT;
371 case DXGI_FORMAT_R24G8_TYPELESS: return WINED3DFMT_R24G8_TYPELESS;
372 case DXGI_FORMAT_D24_UNORM_S8_UINT: return WINED3DFMT_D24_UNORM_S8_UINT;
373 case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: return WINED3DFMT_R24_UNORM_X8_TYPELESS;
374 case DXGI_FORMAT_X24_TYPELESS_G8_UINT: return WINED3DFMT_X24_TYPELESS_G8_UINT;
375 case DXGI_FORMAT_R8G8_TYPELESS: return WINED3DFMT_R8G8_TYPELESS;
376 case DXGI_FORMAT_R8G8_UNORM: return WINED3DFMT_R8G8_UNORM;
377 case DXGI_FORMAT_R8G8_UINT: return WINED3DFMT_R8G8_UINT;
378 case DXGI_FORMAT_R8G8_SNORM: return WINED3DFMT_R8G8_SNORM;
379 case DXGI_FORMAT_R8G8_SINT: return WINED3DFMT_R8G8_SINT;
380 case DXGI_FORMAT_R16_TYPELESS: return WINED3DFMT_R16_TYPELESS;
381 case DXGI_FORMAT_R16_FLOAT: return WINED3DFMT_R16_FLOAT;
382 case DXGI_FORMAT_D16_UNORM: return WINED3DFMT_D16_UNORM;
383 case DXGI_FORMAT_R16_UNORM: return WINED3DFMT_R16_UNORM;
384 case DXGI_FORMAT_R16_UINT: return WINED3DFMT_R16_UINT;
385 case DXGI_FORMAT_R16_SNORM: return WINED3DFMT_R16_SNORM;
386 case DXGI_FORMAT_R16_SINT: return WINED3DFMT_R16_SINT;
387 case DXGI_FORMAT_R8_TYPELESS: return WINED3DFMT_R8_TYPELESS;
388 case DXGI_FORMAT_R8_UNORM: return WINED3DFMT_R8_UNORM;
389 case DXGI_FORMAT_R8_UINT: return WINED3DFMT_R8_UINT;
390 case DXGI_FORMAT_R8_SNORM: return WINED3DFMT_R8_SNORM;
391 case DXGI_FORMAT_R8_SINT: return WINED3DFMT_R8_SINT;
392 case DXGI_FORMAT_A8_UNORM: return WINED3DFMT_A8_UNORM;
393 case DXGI_FORMAT_R1_UNORM: return WINED3DFMT_R1_UNORM;
394 case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: return WINED3DFMT_R9G9B9E5_SHAREDEXP;
395 case DXGI_FORMAT_R8G8_B8G8_UNORM: return WINED3DFMT_R8G8_B8G8_UNORM;
396 case DXGI_FORMAT_G8R8_G8B8_UNORM: return WINED3DFMT_G8R8_G8B8_UNORM;
397 case DXGI_FORMAT_BC1_TYPELESS: return WINED3DFMT_BC1_TYPELESS;
398 case DXGI_FORMAT_BC1_UNORM: return WINED3DFMT_BC1_UNORM;
399 case DXGI_FORMAT_BC1_UNORM_SRGB: return WINED3DFMT_BC1_UNORM_SRGB;
400 case DXGI_FORMAT_BC2_TYPELESS: return WINED3DFMT_BC2_TYPELESS;
401 case DXGI_FORMAT_BC2_UNORM: return WINED3DFMT_BC2_UNORM;
402 case DXGI_FORMAT_BC2_UNORM_SRGB: return WINED3DFMT_BC2_UNORM_SRGB;
403 case DXGI_FORMAT_BC3_TYPELESS: return WINED3DFMT_BC3_TYPELESS;
404 case DXGI_FORMAT_BC3_UNORM: return WINED3DFMT_BC3_UNORM;
405 case DXGI_FORMAT_BC3_UNORM_SRGB: return WINED3DFMT_BC3_UNORM_SRGB;
406 case DXGI_FORMAT_BC4_TYPELESS: return WINED3DFMT_BC4_TYPELESS;
407 case DXGI_FORMAT_BC4_UNORM: return WINED3DFMT_BC4_UNORM;
408 case DXGI_FORMAT_BC4_SNORM: return WINED3DFMT_BC4_SNORM;
409 case DXGI_FORMAT_BC5_TYPELESS: return WINED3DFMT_BC5_TYPELESS;
410 case DXGI_FORMAT_BC5_UNORM: return WINED3DFMT_BC5_UNORM;
411 case DXGI_FORMAT_BC5_SNORM: return WINED3DFMT_BC5_SNORM;
412 case DXGI_FORMAT_B5G6R5_UNORM: return WINED3DFMT_B5G6R5_UNORM;
413 case DXGI_FORMAT_B5G5R5A1_UNORM: return WINED3DFMT_B5G5R5A1_UNORM;
414 case DXGI_FORMAT_B8G8R8A8_UNORM: return WINED3DFMT_B8G8R8A8_UNORM;
415 case DXGI_FORMAT_B8G8R8X8_UNORM: return WINED3DFMT_B8G8R8X8_UNORM;
416 case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM: return WINED3DFMT_R10G10B10_XR_BIAS_A2_UNORM;
417 case DXGI_FORMAT_B8G8R8A8_TYPELESS: return WINED3DFMT_B8G8R8A8_TYPELESS;
418 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: return WINED3DFMT_B8G8R8A8_UNORM_SRGB;
419 case DXGI_FORMAT_B8G8R8X8_TYPELESS: return WINED3DFMT_B8G8R8X8_TYPELESS;
420 case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: return WINED3DFMT_B8G8R8X8_UNORM_SRGB;
421 case DXGI_FORMAT_BC6H_TYPELESS: return WINED3DFMT_BC6H_TYPELESS;
422 case DXGI_FORMAT_BC6H_UF16: return WINED3DFMT_BC6H_UF16;
423 case DXGI_FORMAT_BC6H_SF16: return WINED3DFMT_BC6H_SF16;
424 case DXGI_FORMAT_BC7_TYPELESS: return WINED3DFMT_BC7_TYPELESS;
425 case DXGI_FORMAT_BC7_UNORM: return WINED3DFMT_BC7_UNORM;
426 case DXGI_FORMAT_BC7_UNORM_SRGB: return WINED3DFMT_BC7_UNORM_SRGB;
427 case DXGI_FORMAT_NV12: return WINED3DFMT_NV12;
428 case DXGI_FORMAT_YUY2: return WINED3DFMT_YUY2;
429 case DXGI_FORMAT_B4G4R4A4_UNORM: return WINED3DFMT_B4G4R4A4_UNORM;
430 default:
431 FIXME("Unhandled DXGI_FORMAT %#x.\n", format);
432 return WINED3DFMT_UNKNOWN;
436 unsigned int wined3d_getdata_flags_from_d3d11_async_getdata_flags(unsigned int d3d11_flags)
438 if (d3d11_flags & ~D3D11_ASYNC_GETDATA_DONOTFLUSH)
439 FIXME("Unhandled async getdata flags %#x.\n", d3d11_flags);
441 if (d3d11_flags & D3D11_ASYNC_GETDATA_DONOTFLUSH)
442 return 0;
444 return WINED3DGETDATA_FLUSH;
447 DWORD wined3d_usage_from_d3d11(enum D3D11_USAGE usage)
449 DWORD wined3d_usage = 0;
451 if (usage == D3D11_USAGE_DYNAMIC)
452 wined3d_usage |= WINED3DUSAGE_DYNAMIC;
454 return wined3d_usage;
457 enum D3D11_USAGE d3d11_usage_from_d3d10_usage(enum D3D10_USAGE usage)
459 switch (usage)
461 case D3D10_USAGE_DEFAULT: return D3D11_USAGE_DEFAULT;
462 case D3D10_USAGE_IMMUTABLE: return D3D11_USAGE_IMMUTABLE;
463 case D3D10_USAGE_DYNAMIC: return D3D11_USAGE_DYNAMIC;
464 case D3D10_USAGE_STAGING: return D3D11_USAGE_STAGING;
465 default:
466 FIXME("Unhandled usage %#x.\n", usage);
467 return D3D11_USAGE_DEFAULT;
471 enum D3D10_USAGE d3d10_usage_from_d3d11_usage(enum D3D11_USAGE usage)
473 switch (usage)
475 case D3D11_USAGE_DEFAULT: return D3D10_USAGE_DEFAULT;
476 case D3D11_USAGE_IMMUTABLE: return D3D10_USAGE_IMMUTABLE;
477 case D3D11_USAGE_DYNAMIC: return D3D10_USAGE_DYNAMIC;
478 case D3D11_USAGE_STAGING: return D3D10_USAGE_STAGING;
479 default:
480 FIXME("Unhandled usage %#x.\n", usage);
481 return D3D10_USAGE_DEFAULT;
485 UINT d3d11_bind_flags_from_d3d10_bind_flags(UINT bind_flags)
487 static const UINT handled_flags = D3D10_BIND_VERTEX_BUFFER
488 | D3D10_BIND_INDEX_BUFFER
489 | D3D10_BIND_CONSTANT_BUFFER
490 | D3D10_BIND_SHADER_RESOURCE
491 | D3D10_BIND_STREAM_OUTPUT
492 | D3D10_BIND_RENDER_TARGET
493 | D3D10_BIND_DEPTH_STENCIL;
494 UINT d3d11_bind_flags = bind_flags & handled_flags;
496 if (bind_flags & ~handled_flags)
497 FIXME("Unhandled bind flags %#x.\n", bind_flags & ~handled_flags);
499 return d3d11_bind_flags;
502 UINT d3d10_bind_flags_from_d3d11_bind_flags(UINT bind_flags)
504 static const UINT handled_flags = D3D11_BIND_VERTEX_BUFFER
505 | D3D11_BIND_INDEX_BUFFER
506 | D3D11_BIND_CONSTANT_BUFFER
507 | D3D11_BIND_SHADER_RESOURCE
508 | D3D11_BIND_STREAM_OUTPUT
509 | D3D11_BIND_RENDER_TARGET
510 | D3D11_BIND_DEPTH_STENCIL
511 | D3D11_BIND_UNORDERED_ACCESS
512 | D3D11_BIND_DECODER
513 | D3D11_BIND_VIDEO_ENCODER;
514 UINT d3d10_bind_flags = bind_flags & handled_flags;
516 if (bind_flags & ~handled_flags)
517 FIXME("Unhandled bind flags %#x.\n", bind_flags & ~handled_flags);
519 return d3d10_bind_flags;
522 UINT d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(UINT cpu_access_flags)
524 static const UINT handled_flags = D3D10_CPU_ACCESS_WRITE
525 | D3D10_CPU_ACCESS_READ;
526 UINT d3d11_cpu_access_flags = cpu_access_flags & handled_flags;
528 if (cpu_access_flags & ~handled_flags)
529 FIXME("Unhandled cpu access flags %#x.\n", cpu_access_flags & ~handled_flags);
531 return d3d11_cpu_access_flags;
534 UINT d3d10_cpu_access_flags_from_d3d11_cpu_access_flags(UINT cpu_access_flags)
536 static const UINT handled_flags = D3D11_CPU_ACCESS_WRITE
537 | D3D11_CPU_ACCESS_READ;
538 UINT d3d10_cpu_access_flags = cpu_access_flags & handled_flags;
540 if (cpu_access_flags & ~handled_flags)
541 FIXME("Unhandled cpu access flags %#x.\n", cpu_access_flags & ~handled_flags);
543 return d3d10_cpu_access_flags;
546 UINT d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(UINT resource_misc_flags)
548 static const UINT bitwise_identical_flags = D3D10_RESOURCE_MISC_GENERATE_MIPS
549 | D3D10_RESOURCE_MISC_SHARED
550 | D3D10_RESOURCE_MISC_TEXTURECUBE;
551 const UINT handled_flags = bitwise_identical_flags
552 | D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
553 | D3D10_RESOURCE_MISC_GDI_COMPATIBLE;
554 UINT d3d11_resource_misc_flags = resource_misc_flags & bitwise_identical_flags;
556 if (resource_misc_flags & D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX)
557 d3d11_resource_misc_flags |= D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
558 if (resource_misc_flags & D3D10_RESOURCE_MISC_GDI_COMPATIBLE)
559 d3d11_resource_misc_flags |= D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
561 if (resource_misc_flags & ~handled_flags)
562 FIXME("Unhandled resource misc flags %#x.\n", resource_misc_flags & ~handled_flags);
564 return d3d11_resource_misc_flags;
567 UINT d3d10_resource_misc_flags_from_d3d11_resource_misc_flags(UINT resource_misc_flags)
569 static const UINT bitwise_identical_flags = D3D11_RESOURCE_MISC_GENERATE_MIPS
570 | D3D11_RESOURCE_MISC_SHARED
571 | D3D11_RESOURCE_MISC_TEXTURECUBE;
572 const UINT handled_flags = bitwise_identical_flags
573 | D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS
574 | D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS
575 | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
576 | D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX
577 | D3D11_RESOURCE_MISC_GDI_COMPATIBLE
578 | D3D11_RESOURCE_MISC_SHARED_NTHANDLE;
579 UINT d3d10_resource_misc_flags = resource_misc_flags & bitwise_identical_flags;
581 if (resource_misc_flags & D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX)
582 d3d10_resource_misc_flags |= D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX;
583 if (resource_misc_flags & D3D11_RESOURCE_MISC_GDI_COMPATIBLE)
584 d3d10_resource_misc_flags |= D3D10_RESOURCE_MISC_GDI_COMPATIBLE;
586 if (resource_misc_flags & ~handled_flags)
587 FIXME("Unhandled resource misc flags #%x.\n", resource_misc_flags & ~handled_flags);
589 return d3d10_resource_misc_flags;
592 static BOOL d3d11_bind_flags_are_gpu_read_only(UINT bind_flags)
594 static const BOOL read_only_bind_flags = D3D11_BIND_VERTEX_BUFFER
595 | D3D11_BIND_INDEX_BUFFER | D3D11_BIND_CONSTANT_BUFFER
596 | D3D11_BIND_SHADER_RESOURCE;
598 return !(bind_flags & ~read_only_bind_flags);
601 BOOL validate_d3d11_resource_access_flags(D3D11_RESOURCE_DIMENSION resource_dimension,
602 D3D11_USAGE usage, UINT bind_flags, UINT cpu_access_flags, D3D_FEATURE_LEVEL feature_level)
604 const BOOL is_texture = resource_dimension != D3D11_RESOURCE_DIMENSION_BUFFER;
606 switch (usage)
608 case D3D11_USAGE_DEFAULT:
609 if ((bind_flags == D3D11_BIND_SHADER_RESOURCE && feature_level >= D3D_FEATURE_LEVEL_11_0)
610 || (is_texture && bind_flags == D3D11_BIND_RENDER_TARGET)
611 || bind_flags == D3D11_BIND_UNORDERED_ACCESS)
612 break;
613 if (cpu_access_flags)
615 WARN("Default resources are not CPU accessible.\n");
616 return FALSE;
618 break;
620 case D3D11_USAGE_IMMUTABLE:
621 if (!bind_flags)
623 WARN("Bind flags must be non-zero for immutable resources.\n");
624 return FALSE;
626 if (!d3d11_bind_flags_are_gpu_read_only(bind_flags))
628 WARN("Immutable resources cannot be writable by GPU.\n");
629 return FALSE;
632 if (cpu_access_flags)
634 WARN("Immutable resources are not CPU accessible.\n");
635 return FALSE;
637 break;
639 case D3D11_USAGE_DYNAMIC:
640 if (!bind_flags)
642 WARN("Bind flags must be non-zero for dynamic resources.\n");
643 return FALSE;
645 if (!d3d11_bind_flags_are_gpu_read_only(bind_flags))
647 WARN("Dynamic resources cannot be writable by GPU.\n");
648 return FALSE;
651 if (cpu_access_flags != D3D11_CPU_ACCESS_WRITE)
653 WARN("CPU access must be D3D11_CPU_ACCESS_WRITE for dynamic resources.\n");
654 return FALSE;
656 break;
658 case D3D11_USAGE_STAGING:
659 if (bind_flags)
661 WARN("Invalid bind flags %#x for staging resources.\n", bind_flags);
662 return FALSE;
665 if (!cpu_access_flags)
667 WARN("CPU access must be non-zero for staging resources.\n");
668 return FALSE;
670 break;
672 default:
673 WARN("Invalid usage %#x.\n", usage);
674 return FALSE;
677 return TRUE;
680 struct wined3d_resource *wined3d_resource_from_d3d11_resource(ID3D11Resource *resource)
682 D3D11_RESOURCE_DIMENSION dimension;
684 ID3D11Resource_GetType(resource, &dimension);
686 switch (dimension)
688 case D3D11_RESOURCE_DIMENSION_BUFFER:
689 return wined3d_buffer_get_resource(unsafe_impl_from_ID3D11Buffer(
690 (ID3D11Buffer *)resource)->wined3d_buffer);
692 case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
693 return wined3d_texture_get_resource(unsafe_impl_from_ID3D11Texture1D(
694 (ID3D11Texture1D *)resource)->wined3d_texture);
696 case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
697 return wined3d_texture_get_resource(unsafe_impl_from_ID3D11Texture2D(
698 (ID3D11Texture2D *)resource)->wined3d_texture);
700 case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
701 return wined3d_texture_get_resource(unsafe_impl_from_ID3D11Texture3D(
702 (ID3D11Texture3D *)resource)->wined3d_texture);
704 default:
705 FIXME("Unhandled resource dimension %#x.\n", dimension);
706 return NULL;
710 struct wined3d_resource *wined3d_resource_from_d3d10_resource(ID3D10Resource *resource)
712 D3D10_RESOURCE_DIMENSION dimension;
714 ID3D10Resource_GetType(resource, &dimension);
716 switch (dimension)
718 case D3D10_RESOURCE_DIMENSION_BUFFER:
719 return wined3d_buffer_get_resource(unsafe_impl_from_ID3D10Buffer(
720 (ID3D10Buffer *)resource)->wined3d_buffer);
722 case D3D10_RESOURCE_DIMENSION_TEXTURE1D:
723 return wined3d_texture_get_resource(unsafe_impl_from_ID3D10Texture1D(
724 (ID3D10Texture1D *)resource)->wined3d_texture);
726 case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
727 return wined3d_texture_get_resource(unsafe_impl_from_ID3D10Texture2D(
728 (ID3D10Texture2D *)resource)->wined3d_texture);
730 case D3D10_RESOURCE_DIMENSION_TEXTURE3D:
731 return wined3d_texture_get_resource(unsafe_impl_from_ID3D10Texture3D(
732 (ID3D10Texture3D *)resource)->wined3d_texture);
734 default:
735 FIXME("Unhandled resource dimension %#x.\n", dimension);
736 return NULL;
740 DWORD wined3d_map_flags_from_d3d11_map_type(D3D11_MAP map_type)
742 switch (map_type)
744 case D3D11_MAP_WRITE:
745 return WINED3D_MAP_WRITE;
747 case D3D11_MAP_READ_WRITE:
748 return WINED3D_MAP_READ | WINED3D_MAP_WRITE;
750 case D3D11_MAP_READ:
751 return WINED3D_MAP_READ;
753 case D3D11_MAP_WRITE_DISCARD:
754 return WINED3D_MAP_WRITE | WINED3D_MAP_DISCARD;
756 case D3D11_MAP_WRITE_NO_OVERWRITE:
757 return WINED3D_MAP_WRITE | WINED3D_MAP_NOOVERWRITE;
759 default:
760 FIXME("Unhandled map_type %#x.\n", map_type);
761 return WINED3D_MAP_READ | WINED3D_MAP_WRITE;
765 DWORD wined3d_map_flags_from_d3d10_map_type(D3D10_MAP map_type)
767 return wined3d_map_flags_from_d3d11_map_type((D3D11_MAP)map_type);
770 DWORD wined3d_clear_flags_from_d3d11_clear_flags(UINT clear_flags)
772 DWORD wined3d_clear_flags = 0;
774 if (clear_flags & D3D11_CLEAR_DEPTH)
775 wined3d_clear_flags |= WINED3DCLEAR_ZBUFFER;
776 if (clear_flags & D3D11_CLEAR_STENCIL)
777 wined3d_clear_flags |= WINED3DCLEAR_STENCIL;
779 if (clear_flags & ~(D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL))
781 FIXME("Unhandled clear flags %#x.\n",
782 clear_flags & ~(D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL));
785 return wined3d_clear_flags;
788 unsigned int wined3d_access_from_d3d11(D3D11_USAGE usage, UINT cpu_access)
790 unsigned int access;
792 access = usage == D3D11_USAGE_STAGING ? WINED3D_RESOURCE_ACCESS_CPU : WINED3D_RESOURCE_ACCESS_GPU;
793 if (cpu_access & D3D11_CPU_ACCESS_WRITE)
794 access |= WINED3D_RESOURCE_ACCESS_MAP_W;
795 if (cpu_access & D3D11_CPU_ACCESS_READ)
796 access |= WINED3D_RESOURCE_ACCESS_MAP_R;
797 if (cpu_access &= ~(D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ))
798 FIXME("Unhandled CPU access flags %#x.\n", cpu_access);
800 return access;
803 HRESULT d3d_get_private_data(struct wined3d_private_store *store,
804 REFGUID guid, UINT *data_size, void *data)
806 const struct wined3d_private_data *stored_data;
807 DWORD size_in;
809 if (!data_size)
810 return E_INVALIDARG;
812 wined3d_mutex_lock();
813 if (!(stored_data = wined3d_private_store_get_private_data(store, guid)))
815 *data_size = 0;
816 wined3d_mutex_unlock();
817 return DXGI_ERROR_NOT_FOUND;
820 size_in = *data_size;
821 *data_size = stored_data->size;
822 if (!data)
824 wined3d_mutex_unlock();
825 return S_OK;
827 if (size_in < stored_data->size)
829 wined3d_mutex_unlock();
830 return DXGI_ERROR_MORE_DATA;
833 if (stored_data->flags & WINED3DSPD_IUNKNOWN)
834 IUnknown_AddRef(stored_data->content.object);
835 memcpy(data, stored_data->content.data, stored_data->size);
837 wined3d_mutex_unlock();
838 return S_OK;
841 HRESULT d3d_set_private_data(struct wined3d_private_store *store,
842 REFGUID guid, UINT data_size, const void *data)
844 struct wined3d_private_data *entry;
845 HRESULT hr;
847 wined3d_mutex_lock();
848 if (!data)
850 if (!(entry = wined3d_private_store_get_private_data(store, guid)))
852 wined3d_mutex_unlock();
853 return S_FALSE;
855 wined3d_private_store_free_private_data(store, entry);
856 wined3d_mutex_unlock();
858 return S_OK;
861 hr = wined3d_private_store_set_private_data(store, guid, data, data_size, 0);
862 wined3d_mutex_unlock();
864 return hr;
867 HRESULT d3d_set_private_data_interface(struct wined3d_private_store *store,
868 REFGUID guid, const IUnknown *object)
870 HRESULT hr;
872 if (!object)
873 return d3d_set_private_data(store, guid, sizeof(object), &object);
875 wined3d_mutex_lock();
876 hr = wined3d_private_store_set_private_data(store,
877 guid, object, sizeof(object), WINED3DSPD_IUNKNOWN);
878 wined3d_mutex_unlock();
880 return hr;