msvcrt: Use WINAPIV calling convention for variadic functions.
[wine.git] / dlls / dxgi / utils.c
blobdb74a487f2ee2f40648f318d5abcf2f7d0268d35
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 "dxgi_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(dxgi);
26 WINE_DECLARE_DEBUG_CHANNEL(winediag);
28 #define WINE_DXGI_TO_STR(x) case x: return #x
30 static const char *debug_feature_level(D3D_FEATURE_LEVEL feature_level)
32 switch (feature_level)
34 WINE_DXGI_TO_STR(D3D_FEATURE_LEVEL_9_1);
35 WINE_DXGI_TO_STR(D3D_FEATURE_LEVEL_9_2);
36 WINE_DXGI_TO_STR(D3D_FEATURE_LEVEL_9_3);
37 WINE_DXGI_TO_STR(D3D_FEATURE_LEVEL_10_0);
38 WINE_DXGI_TO_STR(D3D_FEATURE_LEVEL_10_1);
39 WINE_DXGI_TO_STR(D3D_FEATURE_LEVEL_11_0);
40 WINE_DXGI_TO_STR(D3D_FEATURE_LEVEL_11_1);
41 default:
42 FIXME("Unrecognized D3D_FEATURE_LEVEL %#x.\n", feature_level);
43 return "unrecognized";
47 const char *debug_dxgi_format(DXGI_FORMAT format)
49 switch(format)
51 WINE_DXGI_TO_STR(DXGI_FORMAT_UNKNOWN);
52 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32B32A32_TYPELESS);
53 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32B32A32_FLOAT);
54 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32B32A32_UINT);
55 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32B32A32_SINT);
56 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32B32_TYPELESS);
57 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32B32_FLOAT);
58 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32B32_UINT);
59 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32B32_SINT);
60 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16B16A16_TYPELESS);
61 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16B16A16_FLOAT);
62 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16B16A16_UNORM);
63 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16B16A16_UINT);
64 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16B16A16_SNORM);
65 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16B16A16_SINT);
66 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32_TYPELESS);
67 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32_FLOAT);
68 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32_UINT);
69 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32_SINT);
70 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G8X24_TYPELESS);
71 WINE_DXGI_TO_STR(DXGI_FORMAT_D32_FLOAT_S8X24_UINT);
72 WINE_DXGI_TO_STR(DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS);
73 WINE_DXGI_TO_STR(DXGI_FORMAT_X32_TYPELESS_G8X24_UINT);
74 WINE_DXGI_TO_STR(DXGI_FORMAT_R10G10B10A2_TYPELESS);
75 WINE_DXGI_TO_STR(DXGI_FORMAT_R10G10B10A2_UNORM);
76 WINE_DXGI_TO_STR(DXGI_FORMAT_R10G10B10A2_UINT);
77 WINE_DXGI_TO_STR(DXGI_FORMAT_R11G11B10_FLOAT);
78 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8B8A8_TYPELESS);
79 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8B8A8_UNORM);
80 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB);
81 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8B8A8_UINT);
82 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8B8A8_SNORM);
83 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8B8A8_SINT);
84 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16_TYPELESS);
85 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16_FLOAT);
86 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16_UNORM);
87 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16_UINT);
88 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16_SNORM);
89 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16_SINT);
90 WINE_DXGI_TO_STR(DXGI_FORMAT_R32_TYPELESS);
91 WINE_DXGI_TO_STR(DXGI_FORMAT_D32_FLOAT);
92 WINE_DXGI_TO_STR(DXGI_FORMAT_R32_FLOAT);
93 WINE_DXGI_TO_STR(DXGI_FORMAT_R32_UINT);
94 WINE_DXGI_TO_STR(DXGI_FORMAT_R32_SINT);
95 WINE_DXGI_TO_STR(DXGI_FORMAT_R24G8_TYPELESS);
96 WINE_DXGI_TO_STR(DXGI_FORMAT_D24_UNORM_S8_UINT);
97 WINE_DXGI_TO_STR(DXGI_FORMAT_R24_UNORM_X8_TYPELESS);
98 WINE_DXGI_TO_STR(DXGI_FORMAT_X24_TYPELESS_G8_UINT);
99 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8_TYPELESS);
100 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8_UNORM);
101 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8_UINT);
102 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8_SNORM);
103 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8_SINT);
104 WINE_DXGI_TO_STR(DXGI_FORMAT_R16_TYPELESS);
105 WINE_DXGI_TO_STR(DXGI_FORMAT_R16_FLOAT);
106 WINE_DXGI_TO_STR(DXGI_FORMAT_D16_UNORM);
107 WINE_DXGI_TO_STR(DXGI_FORMAT_R16_UNORM);
108 WINE_DXGI_TO_STR(DXGI_FORMAT_R16_UINT);
109 WINE_DXGI_TO_STR(DXGI_FORMAT_R16_SNORM);
110 WINE_DXGI_TO_STR(DXGI_FORMAT_R16_SINT);
111 WINE_DXGI_TO_STR(DXGI_FORMAT_R8_TYPELESS);
112 WINE_DXGI_TO_STR(DXGI_FORMAT_R8_UNORM);
113 WINE_DXGI_TO_STR(DXGI_FORMAT_R8_UINT);
114 WINE_DXGI_TO_STR(DXGI_FORMAT_R8_SNORM);
115 WINE_DXGI_TO_STR(DXGI_FORMAT_R8_SINT);
116 WINE_DXGI_TO_STR(DXGI_FORMAT_A8_UNORM);
117 WINE_DXGI_TO_STR(DXGI_FORMAT_R1_UNORM);
118 WINE_DXGI_TO_STR(DXGI_FORMAT_R9G9B9E5_SHAREDEXP);
119 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8_B8G8_UNORM);
120 WINE_DXGI_TO_STR(DXGI_FORMAT_G8R8_G8B8_UNORM);
121 WINE_DXGI_TO_STR(DXGI_FORMAT_BC1_TYPELESS);
122 WINE_DXGI_TO_STR(DXGI_FORMAT_BC1_UNORM);
123 WINE_DXGI_TO_STR(DXGI_FORMAT_BC1_UNORM_SRGB);
124 WINE_DXGI_TO_STR(DXGI_FORMAT_BC2_TYPELESS);
125 WINE_DXGI_TO_STR(DXGI_FORMAT_BC2_UNORM);
126 WINE_DXGI_TO_STR(DXGI_FORMAT_BC2_UNORM_SRGB);
127 WINE_DXGI_TO_STR(DXGI_FORMAT_BC3_TYPELESS);
128 WINE_DXGI_TO_STR(DXGI_FORMAT_BC3_UNORM);
129 WINE_DXGI_TO_STR(DXGI_FORMAT_BC3_UNORM_SRGB);
130 WINE_DXGI_TO_STR(DXGI_FORMAT_BC4_TYPELESS);
131 WINE_DXGI_TO_STR(DXGI_FORMAT_BC4_UNORM);
132 WINE_DXGI_TO_STR(DXGI_FORMAT_BC4_SNORM);
133 WINE_DXGI_TO_STR(DXGI_FORMAT_BC5_TYPELESS);
134 WINE_DXGI_TO_STR(DXGI_FORMAT_BC5_UNORM);
135 WINE_DXGI_TO_STR(DXGI_FORMAT_BC5_SNORM);
136 WINE_DXGI_TO_STR(DXGI_FORMAT_B5G6R5_UNORM);
137 WINE_DXGI_TO_STR(DXGI_FORMAT_B5G5R5A1_UNORM);
138 WINE_DXGI_TO_STR(DXGI_FORMAT_B8G8R8A8_UNORM);
139 WINE_DXGI_TO_STR(DXGI_FORMAT_B8G8R8X8_UNORM);
140 WINE_DXGI_TO_STR(DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM);
141 WINE_DXGI_TO_STR(DXGI_FORMAT_B8G8R8A8_TYPELESS);
142 WINE_DXGI_TO_STR(DXGI_FORMAT_B8G8R8A8_UNORM_SRGB);
143 WINE_DXGI_TO_STR(DXGI_FORMAT_B8G8R8X8_TYPELESS);
144 WINE_DXGI_TO_STR(DXGI_FORMAT_B8G8R8X8_UNORM_SRGB);
145 WINE_DXGI_TO_STR(DXGI_FORMAT_BC6H_TYPELESS);
146 WINE_DXGI_TO_STR(DXGI_FORMAT_BC6H_UF16);
147 WINE_DXGI_TO_STR(DXGI_FORMAT_BC6H_SF16);
148 WINE_DXGI_TO_STR(DXGI_FORMAT_BC7_TYPELESS);
149 WINE_DXGI_TO_STR(DXGI_FORMAT_BC7_UNORM);
150 WINE_DXGI_TO_STR(DXGI_FORMAT_BC7_UNORM_SRGB);
151 default:
152 FIXME("Unrecognized DXGI_FORMAT %#x.\n", format);
153 return "unrecognized";
157 #undef WINE_DXGI_TO_STR
159 DXGI_FORMAT dxgi_format_from_wined3dformat(enum wined3d_format_id format)
161 switch(format)
163 case WINED3DFMT_UNKNOWN: return DXGI_FORMAT_UNKNOWN;
164 case WINED3DFMT_R32G32B32A32_TYPELESS: return DXGI_FORMAT_R32G32B32A32_TYPELESS;
165 case WINED3DFMT_R32G32B32A32_FLOAT: return DXGI_FORMAT_R32G32B32A32_FLOAT;
166 case WINED3DFMT_R32G32B32A32_UINT: return DXGI_FORMAT_R32G32B32A32_UINT;
167 case WINED3DFMT_R32G32B32A32_SINT: return DXGI_FORMAT_R32G32B32A32_SINT;
168 case WINED3DFMT_R32G32B32_TYPELESS: return DXGI_FORMAT_R32G32B32_TYPELESS;
169 case WINED3DFMT_R32G32B32_FLOAT: return DXGI_FORMAT_R32G32B32_FLOAT;
170 case WINED3DFMT_R32G32B32_UINT: return DXGI_FORMAT_R32G32B32_UINT;
171 case WINED3DFMT_R32G32B32_SINT: return DXGI_FORMAT_R32G32B32_SINT;
172 case WINED3DFMT_R16G16B16A16_TYPELESS: return DXGI_FORMAT_R16G16B16A16_TYPELESS;
173 case WINED3DFMT_R16G16B16A16_FLOAT: return DXGI_FORMAT_R16G16B16A16_FLOAT;
174 case WINED3DFMT_R16G16B16A16_UNORM: return DXGI_FORMAT_R16G16B16A16_UNORM;
175 case WINED3DFMT_R16G16B16A16_UINT: return DXGI_FORMAT_R16G16B16A16_UINT;
176 case WINED3DFMT_R16G16B16A16_SNORM: return DXGI_FORMAT_R16G16B16A16_SNORM;
177 case WINED3DFMT_R16G16B16A16_SINT: return DXGI_FORMAT_R16G16B16A16_SINT;
178 case WINED3DFMT_R32G32_TYPELESS: return DXGI_FORMAT_R32G32_TYPELESS;
179 case WINED3DFMT_R32G32_FLOAT: return DXGI_FORMAT_R32G32_FLOAT;
180 case WINED3DFMT_R32G32_UINT: return DXGI_FORMAT_R32G32_UINT;
181 case WINED3DFMT_R32G32_SINT: return DXGI_FORMAT_R32G32_SINT;
182 case WINED3DFMT_R32G8X24_TYPELESS: return DXGI_FORMAT_R32G8X24_TYPELESS;
183 case WINED3DFMT_D32_FLOAT_S8X24_UINT: return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
184 case WINED3DFMT_R32_FLOAT_X8X24_TYPELESS: return DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS;
185 case WINED3DFMT_X32_TYPELESS_G8X24_UINT: return DXGI_FORMAT_X32_TYPELESS_G8X24_UINT;
186 case WINED3DFMT_R10G10B10A2_TYPELESS: return DXGI_FORMAT_R10G10B10A2_TYPELESS;
187 case WINED3DFMT_R10G10B10A2_UNORM: return DXGI_FORMAT_R10G10B10A2_UNORM;
188 case WINED3DFMT_R10G10B10A2_UINT: return DXGI_FORMAT_R10G10B10A2_UINT;
189 case WINED3DFMT_R11G11B10_FLOAT: return DXGI_FORMAT_R11G11B10_FLOAT;
190 case WINED3DFMT_R8G8B8A8_TYPELESS: return DXGI_FORMAT_R8G8B8A8_TYPELESS;
191 case WINED3DFMT_R8G8B8A8_UNORM: return DXGI_FORMAT_R8G8B8A8_UNORM;
192 case WINED3DFMT_R8G8B8A8_UNORM_SRGB: return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
193 case WINED3DFMT_R8G8B8A8_UINT: return DXGI_FORMAT_R8G8B8A8_UINT;
194 case WINED3DFMT_R8G8B8A8_SNORM: return DXGI_FORMAT_R8G8B8A8_SNORM;
195 case WINED3DFMT_R8G8B8A8_SINT: return DXGI_FORMAT_R8G8B8A8_SINT;
196 case WINED3DFMT_R16G16_TYPELESS: return DXGI_FORMAT_R16G16_TYPELESS;
197 case WINED3DFMT_R16G16_FLOAT: return DXGI_FORMAT_R16G16_FLOAT;
198 case WINED3DFMT_R16G16_UNORM: return DXGI_FORMAT_R16G16_UNORM;
199 case WINED3DFMT_R16G16_UINT: return DXGI_FORMAT_R16G16_UINT;
200 case WINED3DFMT_R16G16_SNORM: return DXGI_FORMAT_R16G16_SNORM;
201 case WINED3DFMT_R16G16_SINT: return DXGI_FORMAT_R16G16_SINT;
202 case WINED3DFMT_R32_TYPELESS: return DXGI_FORMAT_R32_TYPELESS;
203 case WINED3DFMT_D32_FLOAT: return DXGI_FORMAT_D32_FLOAT;
204 case WINED3DFMT_R32_FLOAT: return DXGI_FORMAT_R32_FLOAT;
205 case WINED3DFMT_R32_UINT: return DXGI_FORMAT_R32_UINT;
206 case WINED3DFMT_R32_SINT: return DXGI_FORMAT_R32_SINT;
207 case WINED3DFMT_R24G8_TYPELESS: return DXGI_FORMAT_R24G8_TYPELESS;
208 case WINED3DFMT_D24_UNORM_S8_UINT: return DXGI_FORMAT_D24_UNORM_S8_UINT;
209 case WINED3DFMT_R24_UNORM_X8_TYPELESS: return DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
210 case WINED3DFMT_X24_TYPELESS_G8_UINT: return DXGI_FORMAT_X24_TYPELESS_G8_UINT;
211 case WINED3DFMT_R8G8_TYPELESS: return DXGI_FORMAT_R8G8_TYPELESS;
212 case WINED3DFMT_R8G8_UNORM: return DXGI_FORMAT_R8G8_UNORM;
213 case WINED3DFMT_R8G8_UINT: return DXGI_FORMAT_R8G8_UINT;
214 case WINED3DFMT_R8G8_SNORM: return DXGI_FORMAT_R8G8_SNORM;
215 case WINED3DFMT_R8G8_SINT: return DXGI_FORMAT_R8G8_SINT;
216 case WINED3DFMT_R16_TYPELESS: return DXGI_FORMAT_R16_TYPELESS;
217 case WINED3DFMT_R16_FLOAT: return DXGI_FORMAT_R16_FLOAT;
218 case WINED3DFMT_D16_UNORM: return DXGI_FORMAT_D16_UNORM;
219 case WINED3DFMT_R16_UNORM: return DXGI_FORMAT_R16_UNORM;
220 case WINED3DFMT_R16_UINT: return DXGI_FORMAT_R16_UINT;
221 case WINED3DFMT_R16_SNORM: return DXGI_FORMAT_R16_SNORM;
222 case WINED3DFMT_R16_SINT: return DXGI_FORMAT_R16_SINT;
223 case WINED3DFMT_R8_TYPELESS: return DXGI_FORMAT_R8_TYPELESS;
224 case WINED3DFMT_R8_UNORM: return DXGI_FORMAT_R8_UNORM;
225 case WINED3DFMT_R8_UINT: return DXGI_FORMAT_R8_UINT;
226 case WINED3DFMT_R8_SNORM: return DXGI_FORMAT_R8_SNORM;
227 case WINED3DFMT_R8_SINT: return DXGI_FORMAT_R8_SINT;
228 case WINED3DFMT_A8_UNORM: return DXGI_FORMAT_A8_UNORM;
229 case WINED3DFMT_R1_UNORM: return DXGI_FORMAT_R1_UNORM;
230 case WINED3DFMT_R9G9B9E5_SHAREDEXP: return DXGI_FORMAT_R9G9B9E5_SHAREDEXP;
231 case WINED3DFMT_R8G8_B8G8_UNORM: return DXGI_FORMAT_R8G8_B8G8_UNORM;
232 case WINED3DFMT_G8R8_G8B8_UNORM: return DXGI_FORMAT_G8R8_G8B8_UNORM;
233 case WINED3DFMT_BC1_TYPELESS: return DXGI_FORMAT_BC1_TYPELESS;
234 case WINED3DFMT_BC1_UNORM: return DXGI_FORMAT_BC1_UNORM;
235 case WINED3DFMT_BC1_UNORM_SRGB: return DXGI_FORMAT_BC1_UNORM_SRGB;
236 case WINED3DFMT_BC2_TYPELESS: return DXGI_FORMAT_BC2_TYPELESS;
237 case WINED3DFMT_BC2_UNORM: return DXGI_FORMAT_BC2_UNORM;
238 case WINED3DFMT_BC2_UNORM_SRGB: return DXGI_FORMAT_BC2_UNORM_SRGB;
239 case WINED3DFMT_BC3_TYPELESS: return DXGI_FORMAT_BC3_TYPELESS;
240 case WINED3DFMT_BC3_UNORM: return DXGI_FORMAT_BC3_UNORM;
241 case WINED3DFMT_BC3_UNORM_SRGB: return DXGI_FORMAT_BC3_UNORM_SRGB;
242 case WINED3DFMT_BC4_TYPELESS: return DXGI_FORMAT_BC4_TYPELESS;
243 case WINED3DFMT_BC4_UNORM: return DXGI_FORMAT_BC4_UNORM;
244 case WINED3DFMT_BC4_SNORM: return DXGI_FORMAT_BC4_SNORM;
245 case WINED3DFMT_BC5_TYPELESS: return DXGI_FORMAT_BC5_TYPELESS;
246 case WINED3DFMT_BC5_UNORM: return DXGI_FORMAT_BC5_UNORM;
247 case WINED3DFMT_BC5_SNORM: return DXGI_FORMAT_BC5_SNORM;
248 case WINED3DFMT_B5G6R5_UNORM: return DXGI_FORMAT_B5G6R5_UNORM;
249 case WINED3DFMT_B5G5R5A1_UNORM: return DXGI_FORMAT_B5G5R5A1_UNORM;
250 case WINED3DFMT_B8G8R8A8_UNORM: return DXGI_FORMAT_B8G8R8A8_UNORM;
251 case WINED3DFMT_B8G8R8X8_UNORM: return DXGI_FORMAT_B8G8R8X8_UNORM;
252 case WINED3DFMT_R10G10B10_XR_BIAS_A2_UNORM: return DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM;
253 case WINED3DFMT_B8G8R8A8_TYPELESS: return DXGI_FORMAT_B8G8R8A8_TYPELESS;
254 case WINED3DFMT_B8G8R8A8_UNORM_SRGB: return DXGI_FORMAT_B8G8R8A8_UNORM_SRGB;
255 case WINED3DFMT_B8G8R8X8_TYPELESS: return DXGI_FORMAT_B8G8R8X8_TYPELESS;
256 case WINED3DFMT_B8G8R8X8_UNORM_SRGB: return DXGI_FORMAT_B8G8R8X8_UNORM_SRGB;
257 case WINED3DFMT_BC6H_TYPELESS: return DXGI_FORMAT_BC6H_TYPELESS;
258 case WINED3DFMT_BC6H_UF16: return DXGI_FORMAT_BC6H_UF16;
259 case WINED3DFMT_BC6H_SF16: return DXGI_FORMAT_BC6H_SF16;
260 case WINED3DFMT_BC7_TYPELESS: return DXGI_FORMAT_BC7_TYPELESS;
261 case WINED3DFMT_BC7_UNORM: return DXGI_FORMAT_BC7_UNORM;
262 case WINED3DFMT_BC7_UNORM_SRGB: return DXGI_FORMAT_BC7_UNORM_SRGB;
263 default:
264 FIXME("Unhandled wined3d format %#x.\n", format);
265 return DXGI_FORMAT_UNKNOWN;
269 enum wined3d_format_id wined3dformat_from_dxgi_format(DXGI_FORMAT format)
271 switch(format)
273 case DXGI_FORMAT_UNKNOWN: return WINED3DFMT_UNKNOWN;
274 case DXGI_FORMAT_R32G32B32A32_TYPELESS: return WINED3DFMT_R32G32B32A32_TYPELESS;
275 case DXGI_FORMAT_R32G32B32A32_FLOAT: return WINED3DFMT_R32G32B32A32_FLOAT;
276 case DXGI_FORMAT_R32G32B32A32_UINT: return WINED3DFMT_R32G32B32A32_UINT;
277 case DXGI_FORMAT_R32G32B32A32_SINT: return WINED3DFMT_R32G32B32A32_SINT;
278 case DXGI_FORMAT_R32G32B32_TYPELESS: return WINED3DFMT_R32G32B32_TYPELESS;
279 case DXGI_FORMAT_R32G32B32_FLOAT: return WINED3DFMT_R32G32B32_FLOAT;
280 case DXGI_FORMAT_R32G32B32_UINT: return WINED3DFMT_R32G32B32_UINT;
281 case DXGI_FORMAT_R32G32B32_SINT: return WINED3DFMT_R32G32B32_SINT;
282 case DXGI_FORMAT_R16G16B16A16_TYPELESS: return WINED3DFMT_R16G16B16A16_TYPELESS;
283 case DXGI_FORMAT_R16G16B16A16_FLOAT: return WINED3DFMT_R16G16B16A16_FLOAT;
284 case DXGI_FORMAT_R16G16B16A16_UNORM: return WINED3DFMT_R16G16B16A16_UNORM;
285 case DXGI_FORMAT_R16G16B16A16_UINT: return WINED3DFMT_R16G16B16A16_UINT;
286 case DXGI_FORMAT_R16G16B16A16_SNORM: return WINED3DFMT_R16G16B16A16_SNORM;
287 case DXGI_FORMAT_R16G16B16A16_SINT: return WINED3DFMT_R16G16B16A16_SINT;
288 case DXGI_FORMAT_R32G32_TYPELESS: return WINED3DFMT_R32G32_TYPELESS;
289 case DXGI_FORMAT_R32G32_FLOAT: return WINED3DFMT_R32G32_FLOAT;
290 case DXGI_FORMAT_R32G32_UINT: return WINED3DFMT_R32G32_UINT;
291 case DXGI_FORMAT_R32G32_SINT: return WINED3DFMT_R32G32_SINT;
292 case DXGI_FORMAT_R32G8X24_TYPELESS: return WINED3DFMT_R32G8X24_TYPELESS;
293 case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: return WINED3DFMT_D32_FLOAT_S8X24_UINT;
294 case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: return WINED3DFMT_R32_FLOAT_X8X24_TYPELESS;
295 case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: return WINED3DFMT_X32_TYPELESS_G8X24_UINT;
296 case DXGI_FORMAT_R10G10B10A2_TYPELESS: return WINED3DFMT_R10G10B10A2_TYPELESS;
297 case DXGI_FORMAT_R10G10B10A2_UNORM: return WINED3DFMT_R10G10B10A2_UNORM;
298 case DXGI_FORMAT_R10G10B10A2_UINT: return WINED3DFMT_R10G10B10A2_UINT;
299 case DXGI_FORMAT_R11G11B10_FLOAT: return WINED3DFMT_R11G11B10_FLOAT;
300 case DXGI_FORMAT_R8G8B8A8_TYPELESS: return WINED3DFMT_R8G8B8A8_TYPELESS;
301 case DXGI_FORMAT_R8G8B8A8_UNORM: return WINED3DFMT_R8G8B8A8_UNORM;
302 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: return WINED3DFMT_R8G8B8A8_UNORM_SRGB;
303 case DXGI_FORMAT_R8G8B8A8_UINT: return WINED3DFMT_R8G8B8A8_UINT;
304 case DXGI_FORMAT_R8G8B8A8_SNORM: return WINED3DFMT_R8G8B8A8_SNORM;
305 case DXGI_FORMAT_R8G8B8A8_SINT: return WINED3DFMT_R8G8B8A8_SINT;
306 case DXGI_FORMAT_R16G16_TYPELESS: return WINED3DFMT_R16G16_TYPELESS;
307 case DXGI_FORMAT_R16G16_FLOAT: return WINED3DFMT_R16G16_FLOAT;
308 case DXGI_FORMAT_R16G16_UNORM: return WINED3DFMT_R16G16_UNORM;
309 case DXGI_FORMAT_R16G16_UINT: return WINED3DFMT_R16G16_UINT;
310 case DXGI_FORMAT_R16G16_SNORM: return WINED3DFMT_R16G16_SNORM;
311 case DXGI_FORMAT_R16G16_SINT: return WINED3DFMT_R16G16_SINT;
312 case DXGI_FORMAT_R32_TYPELESS: return WINED3DFMT_R32_TYPELESS;
313 case DXGI_FORMAT_D32_FLOAT: return WINED3DFMT_D32_FLOAT;
314 case DXGI_FORMAT_R32_FLOAT: return WINED3DFMT_R32_FLOAT;
315 case DXGI_FORMAT_R32_UINT: return WINED3DFMT_R32_UINT;
316 case DXGI_FORMAT_R32_SINT: return WINED3DFMT_R32_SINT;
317 case DXGI_FORMAT_R24G8_TYPELESS: return WINED3DFMT_R24G8_TYPELESS;
318 case DXGI_FORMAT_D24_UNORM_S8_UINT: return WINED3DFMT_D24_UNORM_S8_UINT;
319 case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: return WINED3DFMT_R24_UNORM_X8_TYPELESS;
320 case DXGI_FORMAT_X24_TYPELESS_G8_UINT: return WINED3DFMT_X24_TYPELESS_G8_UINT;
321 case DXGI_FORMAT_R8G8_TYPELESS: return WINED3DFMT_R8G8_TYPELESS;
322 case DXGI_FORMAT_R8G8_UNORM: return WINED3DFMT_R8G8_UNORM;
323 case DXGI_FORMAT_R8G8_UINT: return WINED3DFMT_R8G8_UINT;
324 case DXGI_FORMAT_R8G8_SNORM: return WINED3DFMT_R8G8_SNORM;
325 case DXGI_FORMAT_R8G8_SINT: return WINED3DFMT_R8G8_SINT;
326 case DXGI_FORMAT_R16_TYPELESS: return WINED3DFMT_R16_TYPELESS;
327 case DXGI_FORMAT_R16_FLOAT: return WINED3DFMT_R16_FLOAT;
328 case DXGI_FORMAT_D16_UNORM: return WINED3DFMT_D16_UNORM;
329 case DXGI_FORMAT_R16_UNORM: return WINED3DFMT_R16_UNORM;
330 case DXGI_FORMAT_R16_UINT: return WINED3DFMT_R16_UINT;
331 case DXGI_FORMAT_R16_SNORM: return WINED3DFMT_R16_SNORM;
332 case DXGI_FORMAT_R16_SINT: return WINED3DFMT_R16_SINT;
333 case DXGI_FORMAT_R8_TYPELESS: return WINED3DFMT_R8_TYPELESS;
334 case DXGI_FORMAT_R8_UNORM: return WINED3DFMT_R8_UNORM;
335 case DXGI_FORMAT_R8_UINT: return WINED3DFMT_R8_UINT;
336 case DXGI_FORMAT_R8_SNORM: return WINED3DFMT_R8_SNORM;
337 case DXGI_FORMAT_R8_SINT: return WINED3DFMT_R8_SINT;
338 case DXGI_FORMAT_A8_UNORM: return WINED3DFMT_A8_UNORM;
339 case DXGI_FORMAT_R1_UNORM: return WINED3DFMT_R1_UNORM;
340 case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: return WINED3DFMT_R9G9B9E5_SHAREDEXP;
341 case DXGI_FORMAT_R8G8_B8G8_UNORM: return WINED3DFMT_R8G8_B8G8_UNORM;
342 case DXGI_FORMAT_G8R8_G8B8_UNORM: return WINED3DFMT_G8R8_G8B8_UNORM;
343 case DXGI_FORMAT_BC1_TYPELESS: return WINED3DFMT_BC1_TYPELESS;
344 case DXGI_FORMAT_BC1_UNORM: return WINED3DFMT_BC1_UNORM;
345 case DXGI_FORMAT_BC1_UNORM_SRGB: return WINED3DFMT_BC1_UNORM_SRGB;
346 case DXGI_FORMAT_BC2_TYPELESS: return WINED3DFMT_BC2_TYPELESS;
347 case DXGI_FORMAT_BC2_UNORM: return WINED3DFMT_BC2_UNORM;
348 case DXGI_FORMAT_BC2_UNORM_SRGB: return WINED3DFMT_BC2_UNORM_SRGB;
349 case DXGI_FORMAT_BC3_TYPELESS: return WINED3DFMT_BC3_TYPELESS;
350 case DXGI_FORMAT_BC3_UNORM: return WINED3DFMT_BC3_UNORM;
351 case DXGI_FORMAT_BC3_UNORM_SRGB: return WINED3DFMT_BC3_UNORM_SRGB;
352 case DXGI_FORMAT_BC4_TYPELESS: return WINED3DFMT_BC4_TYPELESS;
353 case DXGI_FORMAT_BC4_UNORM: return WINED3DFMT_BC4_UNORM;
354 case DXGI_FORMAT_BC4_SNORM: return WINED3DFMT_BC4_SNORM;
355 case DXGI_FORMAT_BC5_TYPELESS: return WINED3DFMT_BC5_TYPELESS;
356 case DXGI_FORMAT_BC5_UNORM: return WINED3DFMT_BC5_UNORM;
357 case DXGI_FORMAT_BC5_SNORM: return WINED3DFMT_BC5_SNORM;
358 case DXGI_FORMAT_B5G6R5_UNORM: return WINED3DFMT_B5G6R5_UNORM;
359 case DXGI_FORMAT_B5G5R5A1_UNORM: return WINED3DFMT_B5G5R5A1_UNORM;
360 case DXGI_FORMAT_B8G8R8A8_UNORM: return WINED3DFMT_B8G8R8A8_UNORM;
361 case DXGI_FORMAT_B8G8R8X8_UNORM: return WINED3DFMT_B8G8R8X8_UNORM;
362 case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM: return WINED3DFMT_R10G10B10_XR_BIAS_A2_UNORM;
363 case DXGI_FORMAT_B8G8R8A8_TYPELESS: return WINED3DFMT_B8G8R8A8_TYPELESS;
364 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: return WINED3DFMT_B8G8R8A8_UNORM_SRGB;
365 case DXGI_FORMAT_B8G8R8X8_TYPELESS: return WINED3DFMT_B8G8R8X8_TYPELESS;
366 case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: return WINED3DFMT_B8G8R8X8_UNORM_SRGB;
367 case DXGI_FORMAT_BC6H_TYPELESS: return WINED3DFMT_BC6H_TYPELESS;
368 case DXGI_FORMAT_BC6H_UF16: return WINED3DFMT_BC6H_UF16;
369 case DXGI_FORMAT_BC6H_SF16: return WINED3DFMT_BC6H_SF16;
370 case DXGI_FORMAT_BC7_TYPELESS: return WINED3DFMT_BC7_TYPELESS;
371 case DXGI_FORMAT_BC7_UNORM: return WINED3DFMT_BC7_UNORM;
372 case DXGI_FORMAT_BC7_UNORM_SRGB: return WINED3DFMT_BC7_UNORM_SRGB;
373 default:
374 FIXME("Unhandled DXGI_FORMAT %#x.\n", format);
375 return WINED3DFMT_UNKNOWN;
379 const char *debug_dxgi_mode(const DXGI_MODE_DESC *desc)
381 return wine_dbg_sprintf("resolution %ux%u, refresh rate %u / %u, "
382 "format %s, scanline ordering %#x, scaling %#x",
383 desc->Width, desc->Height, desc->RefreshRate.Numerator, desc->RefreshRate.Denominator,
384 debug_dxgi_format(desc->Format), desc->ScanlineOrdering, desc->Scaling);
387 void dump_feature_levels(const D3D_FEATURE_LEVEL *feature_levels, unsigned int level_count)
389 unsigned int i;
391 if (!feature_levels || !level_count)
393 TRACE("Feature levels: (null).\n");
394 return;
397 TRACE("Feature levels (count = %u):\n", level_count);
398 for (i = 0; i < level_count; ++i)
399 TRACE(" [%u] = %s.\n", i, debug_feature_level(feature_levels[i]));
402 UINT dxgi_rational_to_uint(const DXGI_RATIONAL *rational)
404 if (rational->Denominator)
405 return rational->Numerator / rational->Denominator;
406 else
407 return rational->Numerator;
410 static enum wined3d_scanline_ordering wined3d_scanline_ordering_from_dxgi(DXGI_MODE_SCANLINE_ORDER scanline_order)
412 switch (scanline_order)
414 case DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED:
415 return WINED3D_SCANLINE_ORDERING_UNKNOWN;
416 case DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE:
417 return WINED3D_SCANLINE_ORDERING_PROGRESSIVE;
418 default:
419 FIXME("Unhandled scanline ordering %#x.\n", scanline_order);
420 return WINED3D_SCANLINE_ORDERING_UNKNOWN;
424 void dxgi_sample_desc_from_wined3d(DXGI_SAMPLE_DESC *desc,
425 enum wined3d_multisample_type wined3d_type, unsigned int wined3d_quality)
427 desc->Count = wined3d_type == WINED3D_MULTISAMPLE_NONE ? 1 : wined3d_type;
428 desc->Quality = wined3d_quality;
431 void wined3d_sample_desc_from_dxgi(enum wined3d_multisample_type *wined3d_type,
432 unsigned int *wined3d_quality, const DXGI_SAMPLE_DESC *dxgi_desc)
434 if (dxgi_desc->Count > 1)
436 *wined3d_type = dxgi_desc->Count;
437 *wined3d_quality = dxgi_desc->Quality;
439 else
441 *wined3d_type = WINED3D_MULTISAMPLE_NONE;
442 *wined3d_quality = 0;
446 void wined3d_display_mode_from_dxgi(struct wined3d_display_mode *wined3d_mode,
447 const DXGI_MODE_DESC *mode)
449 wined3d_mode->width = mode->Width;
450 wined3d_mode->height = mode->Height;
451 wined3d_mode->refresh_rate = dxgi_rational_to_uint(&mode->RefreshRate);
452 wined3d_mode->format_id = wined3dformat_from_dxgi_format(mode->Format);
453 wined3d_mode->scanline_ordering = wined3d_scanline_ordering_from_dxgi(mode->ScanlineOrdering);
456 #define DXGI_WINED3D_SWAPCHAIN_FLAGS \
457 (WINED3D_SWAPCHAIN_USE_CLOSEST_MATCHING_MODE | WINED3D_SWAPCHAIN_RESTORE_WINDOW_RECT)
459 unsigned int dxgi_swapchain_flags_from_wined3d(unsigned int wined3d_flags)
461 unsigned int flags = 0;
463 wined3d_flags &= ~DXGI_WINED3D_SWAPCHAIN_FLAGS;
465 if (wined3d_flags & WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH)
467 wined3d_flags &= ~WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH;
468 flags |= DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
471 if (wined3d_flags & WINED3D_SWAPCHAIN_GDI_COMPATIBLE)
473 wined3d_flags &= ~WINED3D_SWAPCHAIN_GDI_COMPATIBLE;
474 flags |= DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE;
477 if (wined3d_flags)
478 FIXME("Unhandled flags %#x.\n", flags);
480 return flags;
483 unsigned int wined3d_swapchain_flags_from_dxgi(unsigned int flags)
485 unsigned int wined3d_flags = DXGI_WINED3D_SWAPCHAIN_FLAGS; /* WINED3D_SWAPCHAIN_DISCARD_DEPTHSTENCIL? */
487 if (flags & DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH)
489 flags &= ~DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
490 wined3d_flags |= WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH;
493 if (flags & DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE)
495 flags &= ~DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE;
496 wined3d_flags |= WINED3D_SWAPCHAIN_GDI_COMPATIBLE;
499 if (flags)
500 FIXME("Unhandled flags %#x.\n", flags);
502 return wined3d_flags;
505 HRESULT dxgi_get_private_data(struct wined3d_private_store *store,
506 REFGUID guid, UINT *data_size, void *data)
508 const struct wined3d_private_data *stored_data;
509 DWORD size_in;
510 HRESULT hr;
512 if (!data_size)
513 return E_INVALIDARG;
515 wined3d_mutex_lock();
516 if (!(stored_data = wined3d_private_store_get_private_data(store, guid)))
518 hr = DXGI_ERROR_NOT_FOUND;
519 *data_size = 0;
520 goto done;
523 size_in = *data_size;
524 *data_size = stored_data->size;
525 if (!data)
527 hr = S_OK;
528 goto done;
530 if (size_in < stored_data->size)
532 hr = DXGI_ERROR_MORE_DATA;
533 goto done;
536 if (stored_data->flags & WINED3DSPD_IUNKNOWN)
537 IUnknown_AddRef(stored_data->content.object);
538 memcpy(data, stored_data->content.data, stored_data->size);
539 hr = S_OK;
541 done:
542 wined3d_mutex_unlock();
544 return hr;
547 HRESULT dxgi_set_private_data(struct wined3d_private_store *store,
548 REFGUID guid, UINT data_size, const void *data)
550 struct wined3d_private_data *entry;
551 HRESULT hr;
553 if (!data)
555 wined3d_mutex_lock();
556 if (!(entry = wined3d_private_store_get_private_data(store, guid)))
558 wined3d_mutex_unlock();
559 return S_FALSE;
562 wined3d_private_store_free_private_data(store, entry);
563 wined3d_mutex_unlock();
565 return S_OK;
568 wined3d_mutex_lock();
569 hr = wined3d_private_store_set_private_data(store, guid, data, data_size, 0);
570 wined3d_mutex_unlock();
572 return hr;
575 HRESULT dxgi_set_private_data_interface(struct wined3d_private_store *store,
576 REFGUID guid, const IUnknown *object)
578 HRESULT hr;
580 if (!object)
581 return dxgi_set_private_data(store, guid, sizeof(object), &object);
583 wined3d_mutex_lock();
584 hr = wined3d_private_store_set_private_data(store,
585 guid, object, sizeof(object), WINED3DSPD_IUNKNOWN);
586 wined3d_mutex_unlock();
588 return hr;
591 D3D_FEATURE_LEVEL dxgi_check_feature_level_support(struct dxgi_factory *factory, struct dxgi_adapter *adapter,
592 const D3D_FEATURE_LEVEL *feature_levels, unsigned int level_count)
594 static const struct
596 D3D_FEATURE_LEVEL feature_level;
597 unsigned int sm;
599 feature_levels_sm[] =
601 {D3D_FEATURE_LEVEL_11_1, 5},
602 {D3D_FEATURE_LEVEL_11_0, 5},
603 {D3D_FEATURE_LEVEL_10_1, 4},
604 {D3D_FEATURE_LEVEL_10_0, 4},
605 {D3D_FEATURE_LEVEL_9_3, 3},
606 {D3D_FEATURE_LEVEL_9_2, 2},
607 {D3D_FEATURE_LEVEL_9_1, 2},
609 D3D_FEATURE_LEVEL selected_feature_level = 0;
610 unsigned int shader_model;
611 unsigned int i, j;
612 WINED3DCAPS caps;
613 HRESULT hr;
615 FIXME("Ignoring adapter type.\n");
617 wined3d_mutex_lock();
618 hr = wined3d_get_device_caps(factory->wined3d, adapter->ordinal, WINED3D_DEVICE_TYPE_HAL, &caps);
619 wined3d_mutex_unlock();
621 if (FAILED(hr))
622 level_count = 0;
624 shader_model = min(caps.VertexShaderVersion, caps.PixelShaderVersion);
625 for (i = 0; i < level_count; ++i)
627 for (j = 0; j < sizeof(feature_levels_sm) / sizeof(feature_levels_sm[0]); ++j)
629 if (feature_levels[i] == feature_levels_sm[j].feature_level)
631 if (shader_model >= feature_levels_sm[j].sm)
633 selected_feature_level = feature_levels[i];
634 TRACE("Choosing supported feature level %s (SM%u).\n",
635 debug_feature_level(selected_feature_level), feature_levels_sm[j].sm);
637 break;
640 if (selected_feature_level)
641 break;
643 if (j == sizeof(feature_levels_sm) / sizeof(feature_levels_sm[0]))
644 FIXME("Unexpected feature level %#x.\n", feature_levels[i]);
645 else
646 TRACE("Feature level %s not supported, trying next fallback if available.\n",
647 debug_feature_level(feature_levels[i]));
649 if (!selected_feature_level)
650 FIXME_(winediag)("None of the requested D3D feature levels is supported on this GPU "
651 "with the current shader backend.\n");
653 return selected_feature_level;