ucrtbase: Add __current_exception() implementation.
[wine.git] / dlls / dxgi / utils.c
blob74f0ae0529dcf0a7530c96d5a3c0a467649d031d
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 WINE_DXGI_TO_STR(DXGI_FORMAT_B4G4R4A4_UNORM);
152 default:
153 FIXME("Unrecognized DXGI_FORMAT %#x.\n", format);
154 return "unrecognized";
158 #undef WINE_DXGI_TO_STR
160 DXGI_FORMAT dxgi_format_from_wined3dformat(enum wined3d_format_id format)
162 switch(format)
164 case WINED3DFMT_UNKNOWN: return DXGI_FORMAT_UNKNOWN;
165 case WINED3DFMT_R32G32B32A32_TYPELESS: return DXGI_FORMAT_R32G32B32A32_TYPELESS;
166 case WINED3DFMT_R32G32B32A32_FLOAT: return DXGI_FORMAT_R32G32B32A32_FLOAT;
167 case WINED3DFMT_R32G32B32A32_UINT: return DXGI_FORMAT_R32G32B32A32_UINT;
168 case WINED3DFMT_R32G32B32A32_SINT: return DXGI_FORMAT_R32G32B32A32_SINT;
169 case WINED3DFMT_R32G32B32_TYPELESS: return DXGI_FORMAT_R32G32B32_TYPELESS;
170 case WINED3DFMT_R32G32B32_FLOAT: return DXGI_FORMAT_R32G32B32_FLOAT;
171 case WINED3DFMT_R32G32B32_UINT: return DXGI_FORMAT_R32G32B32_UINT;
172 case WINED3DFMT_R32G32B32_SINT: return DXGI_FORMAT_R32G32B32_SINT;
173 case WINED3DFMT_R16G16B16A16_TYPELESS: return DXGI_FORMAT_R16G16B16A16_TYPELESS;
174 case WINED3DFMT_R16G16B16A16_FLOAT: return DXGI_FORMAT_R16G16B16A16_FLOAT;
175 case WINED3DFMT_R16G16B16A16_UNORM: return DXGI_FORMAT_R16G16B16A16_UNORM;
176 case WINED3DFMT_R16G16B16A16_UINT: return DXGI_FORMAT_R16G16B16A16_UINT;
177 case WINED3DFMT_R16G16B16A16_SNORM: return DXGI_FORMAT_R16G16B16A16_SNORM;
178 case WINED3DFMT_R16G16B16A16_SINT: return DXGI_FORMAT_R16G16B16A16_SINT;
179 case WINED3DFMT_R32G32_TYPELESS: return DXGI_FORMAT_R32G32_TYPELESS;
180 case WINED3DFMT_R32G32_FLOAT: return DXGI_FORMAT_R32G32_FLOAT;
181 case WINED3DFMT_R32G32_UINT: return DXGI_FORMAT_R32G32_UINT;
182 case WINED3DFMT_R32G32_SINT: return DXGI_FORMAT_R32G32_SINT;
183 case WINED3DFMT_R32G8X24_TYPELESS: return DXGI_FORMAT_R32G8X24_TYPELESS;
184 case WINED3DFMT_D32_FLOAT_S8X24_UINT: return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
185 case WINED3DFMT_R32_FLOAT_X8X24_TYPELESS: return DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS;
186 case WINED3DFMT_X32_TYPELESS_G8X24_UINT: return DXGI_FORMAT_X32_TYPELESS_G8X24_UINT;
187 case WINED3DFMT_R10G10B10A2_TYPELESS: return DXGI_FORMAT_R10G10B10A2_TYPELESS;
188 case WINED3DFMT_R10G10B10A2_UNORM: return DXGI_FORMAT_R10G10B10A2_UNORM;
189 case WINED3DFMT_R10G10B10A2_UINT: return DXGI_FORMAT_R10G10B10A2_UINT;
190 case WINED3DFMT_R11G11B10_FLOAT: return DXGI_FORMAT_R11G11B10_FLOAT;
191 case WINED3DFMT_R8G8B8A8_TYPELESS: return DXGI_FORMAT_R8G8B8A8_TYPELESS;
192 case WINED3DFMT_R8G8B8A8_UNORM: return DXGI_FORMAT_R8G8B8A8_UNORM;
193 case WINED3DFMT_R8G8B8A8_UNORM_SRGB: return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
194 case WINED3DFMT_R8G8B8A8_UINT: return DXGI_FORMAT_R8G8B8A8_UINT;
195 case WINED3DFMT_R8G8B8A8_SNORM: return DXGI_FORMAT_R8G8B8A8_SNORM;
196 case WINED3DFMT_R8G8B8A8_SINT: return DXGI_FORMAT_R8G8B8A8_SINT;
197 case WINED3DFMT_R16G16_TYPELESS: return DXGI_FORMAT_R16G16_TYPELESS;
198 case WINED3DFMT_R16G16_FLOAT: return DXGI_FORMAT_R16G16_FLOAT;
199 case WINED3DFMT_R16G16_UNORM: return DXGI_FORMAT_R16G16_UNORM;
200 case WINED3DFMT_R16G16_UINT: return DXGI_FORMAT_R16G16_UINT;
201 case WINED3DFMT_R16G16_SNORM: return DXGI_FORMAT_R16G16_SNORM;
202 case WINED3DFMT_R16G16_SINT: return DXGI_FORMAT_R16G16_SINT;
203 case WINED3DFMT_R32_TYPELESS: return DXGI_FORMAT_R32_TYPELESS;
204 case WINED3DFMT_D32_FLOAT: return DXGI_FORMAT_D32_FLOAT;
205 case WINED3DFMT_R32_FLOAT: return DXGI_FORMAT_R32_FLOAT;
206 case WINED3DFMT_R32_UINT: return DXGI_FORMAT_R32_UINT;
207 case WINED3DFMT_R32_SINT: return DXGI_FORMAT_R32_SINT;
208 case WINED3DFMT_R24G8_TYPELESS: return DXGI_FORMAT_R24G8_TYPELESS;
209 case WINED3DFMT_D24_UNORM_S8_UINT: return DXGI_FORMAT_D24_UNORM_S8_UINT;
210 case WINED3DFMT_R24_UNORM_X8_TYPELESS: return DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
211 case WINED3DFMT_X24_TYPELESS_G8_UINT: return DXGI_FORMAT_X24_TYPELESS_G8_UINT;
212 case WINED3DFMT_R8G8_TYPELESS: return DXGI_FORMAT_R8G8_TYPELESS;
213 case WINED3DFMT_R8G8_UNORM: return DXGI_FORMAT_R8G8_UNORM;
214 case WINED3DFMT_R8G8_UINT: return DXGI_FORMAT_R8G8_UINT;
215 case WINED3DFMT_R8G8_SNORM: return DXGI_FORMAT_R8G8_SNORM;
216 case WINED3DFMT_R8G8_SINT: return DXGI_FORMAT_R8G8_SINT;
217 case WINED3DFMT_R16_TYPELESS: return DXGI_FORMAT_R16_TYPELESS;
218 case WINED3DFMT_R16_FLOAT: return DXGI_FORMAT_R16_FLOAT;
219 case WINED3DFMT_D16_UNORM: return DXGI_FORMAT_D16_UNORM;
220 case WINED3DFMT_R16_UNORM: return DXGI_FORMAT_R16_UNORM;
221 case WINED3DFMT_R16_UINT: return DXGI_FORMAT_R16_UINT;
222 case WINED3DFMT_R16_SNORM: return DXGI_FORMAT_R16_SNORM;
223 case WINED3DFMT_R16_SINT: return DXGI_FORMAT_R16_SINT;
224 case WINED3DFMT_R8_TYPELESS: return DXGI_FORMAT_R8_TYPELESS;
225 case WINED3DFMT_R8_UNORM: return DXGI_FORMAT_R8_UNORM;
226 case WINED3DFMT_R8_UINT: return DXGI_FORMAT_R8_UINT;
227 case WINED3DFMT_R8_SNORM: return DXGI_FORMAT_R8_SNORM;
228 case WINED3DFMT_R8_SINT: return DXGI_FORMAT_R8_SINT;
229 case WINED3DFMT_A8_UNORM: return DXGI_FORMAT_A8_UNORM;
230 case WINED3DFMT_R1_UNORM: return DXGI_FORMAT_R1_UNORM;
231 case WINED3DFMT_R9G9B9E5_SHAREDEXP: return DXGI_FORMAT_R9G9B9E5_SHAREDEXP;
232 case WINED3DFMT_R8G8_B8G8_UNORM: return DXGI_FORMAT_R8G8_B8G8_UNORM;
233 case WINED3DFMT_G8R8_G8B8_UNORM: return DXGI_FORMAT_G8R8_G8B8_UNORM;
234 case WINED3DFMT_BC1_TYPELESS: return DXGI_FORMAT_BC1_TYPELESS;
235 case WINED3DFMT_BC1_UNORM: return DXGI_FORMAT_BC1_UNORM;
236 case WINED3DFMT_BC1_UNORM_SRGB: return DXGI_FORMAT_BC1_UNORM_SRGB;
237 case WINED3DFMT_BC2_TYPELESS: return DXGI_FORMAT_BC2_TYPELESS;
238 case WINED3DFMT_BC2_UNORM: return DXGI_FORMAT_BC2_UNORM;
239 case WINED3DFMT_BC2_UNORM_SRGB: return DXGI_FORMAT_BC2_UNORM_SRGB;
240 case WINED3DFMT_BC3_TYPELESS: return DXGI_FORMAT_BC3_TYPELESS;
241 case WINED3DFMT_BC3_UNORM: return DXGI_FORMAT_BC3_UNORM;
242 case WINED3DFMT_BC3_UNORM_SRGB: return DXGI_FORMAT_BC3_UNORM_SRGB;
243 case WINED3DFMT_BC4_TYPELESS: return DXGI_FORMAT_BC4_TYPELESS;
244 case WINED3DFMT_BC4_UNORM: return DXGI_FORMAT_BC4_UNORM;
245 case WINED3DFMT_BC4_SNORM: return DXGI_FORMAT_BC4_SNORM;
246 case WINED3DFMT_BC5_TYPELESS: return DXGI_FORMAT_BC5_TYPELESS;
247 case WINED3DFMT_BC5_UNORM: return DXGI_FORMAT_BC5_UNORM;
248 case WINED3DFMT_BC5_SNORM: return DXGI_FORMAT_BC5_SNORM;
249 case WINED3DFMT_B5G6R5_UNORM: return DXGI_FORMAT_B5G6R5_UNORM;
250 case WINED3DFMT_B5G5R5A1_UNORM: return DXGI_FORMAT_B5G5R5A1_UNORM;
251 case WINED3DFMT_B8G8R8A8_UNORM: return DXGI_FORMAT_B8G8R8A8_UNORM;
252 case WINED3DFMT_B8G8R8X8_UNORM: return DXGI_FORMAT_B8G8R8X8_UNORM;
253 case WINED3DFMT_R10G10B10_XR_BIAS_A2_UNORM: return DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM;
254 case WINED3DFMT_B8G8R8A8_TYPELESS: return DXGI_FORMAT_B8G8R8A8_TYPELESS;
255 case WINED3DFMT_B8G8R8A8_UNORM_SRGB: return DXGI_FORMAT_B8G8R8A8_UNORM_SRGB;
256 case WINED3DFMT_B8G8R8X8_TYPELESS: return DXGI_FORMAT_B8G8R8X8_TYPELESS;
257 case WINED3DFMT_B8G8R8X8_UNORM_SRGB: return DXGI_FORMAT_B8G8R8X8_UNORM_SRGB;
258 case WINED3DFMT_BC6H_TYPELESS: return DXGI_FORMAT_BC6H_TYPELESS;
259 case WINED3DFMT_BC6H_UF16: return DXGI_FORMAT_BC6H_UF16;
260 case WINED3DFMT_BC6H_SF16: return DXGI_FORMAT_BC6H_SF16;
261 case WINED3DFMT_BC7_TYPELESS: return DXGI_FORMAT_BC7_TYPELESS;
262 case WINED3DFMT_BC7_UNORM: return DXGI_FORMAT_BC7_UNORM;
263 case WINED3DFMT_BC7_UNORM_SRGB: return DXGI_FORMAT_BC7_UNORM_SRGB;
264 case WINED3DFMT_B4G4R4A4_UNORM: return DXGI_FORMAT_B4G4R4A4_UNORM;
265 default:
266 FIXME("Unhandled wined3d format %#x.\n", format);
267 return DXGI_FORMAT_UNKNOWN;
271 enum wined3d_format_id wined3dformat_from_dxgi_format(DXGI_FORMAT format)
273 switch(format)
275 case DXGI_FORMAT_UNKNOWN: return WINED3DFMT_UNKNOWN;
276 case DXGI_FORMAT_R32G32B32A32_TYPELESS: return WINED3DFMT_R32G32B32A32_TYPELESS;
277 case DXGI_FORMAT_R32G32B32A32_FLOAT: return WINED3DFMT_R32G32B32A32_FLOAT;
278 case DXGI_FORMAT_R32G32B32A32_UINT: return WINED3DFMT_R32G32B32A32_UINT;
279 case DXGI_FORMAT_R32G32B32A32_SINT: return WINED3DFMT_R32G32B32A32_SINT;
280 case DXGI_FORMAT_R32G32B32_TYPELESS: return WINED3DFMT_R32G32B32_TYPELESS;
281 case DXGI_FORMAT_R32G32B32_FLOAT: return WINED3DFMT_R32G32B32_FLOAT;
282 case DXGI_FORMAT_R32G32B32_UINT: return WINED3DFMT_R32G32B32_UINT;
283 case DXGI_FORMAT_R32G32B32_SINT: return WINED3DFMT_R32G32B32_SINT;
284 case DXGI_FORMAT_R16G16B16A16_TYPELESS: return WINED3DFMT_R16G16B16A16_TYPELESS;
285 case DXGI_FORMAT_R16G16B16A16_FLOAT: return WINED3DFMT_R16G16B16A16_FLOAT;
286 case DXGI_FORMAT_R16G16B16A16_UNORM: return WINED3DFMT_R16G16B16A16_UNORM;
287 case DXGI_FORMAT_R16G16B16A16_UINT: return WINED3DFMT_R16G16B16A16_UINT;
288 case DXGI_FORMAT_R16G16B16A16_SNORM: return WINED3DFMT_R16G16B16A16_SNORM;
289 case DXGI_FORMAT_R16G16B16A16_SINT: return WINED3DFMT_R16G16B16A16_SINT;
290 case DXGI_FORMAT_R32G32_TYPELESS: return WINED3DFMT_R32G32_TYPELESS;
291 case DXGI_FORMAT_R32G32_FLOAT: return WINED3DFMT_R32G32_FLOAT;
292 case DXGI_FORMAT_R32G32_UINT: return WINED3DFMT_R32G32_UINT;
293 case DXGI_FORMAT_R32G32_SINT: return WINED3DFMT_R32G32_SINT;
294 case DXGI_FORMAT_R32G8X24_TYPELESS: return WINED3DFMT_R32G8X24_TYPELESS;
295 case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: return WINED3DFMT_D32_FLOAT_S8X24_UINT;
296 case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: return WINED3DFMT_R32_FLOAT_X8X24_TYPELESS;
297 case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: return WINED3DFMT_X32_TYPELESS_G8X24_UINT;
298 case DXGI_FORMAT_R10G10B10A2_TYPELESS: return WINED3DFMT_R10G10B10A2_TYPELESS;
299 case DXGI_FORMAT_R10G10B10A2_UNORM: return WINED3DFMT_R10G10B10A2_UNORM;
300 case DXGI_FORMAT_R10G10B10A2_UINT: return WINED3DFMT_R10G10B10A2_UINT;
301 case DXGI_FORMAT_R11G11B10_FLOAT: return WINED3DFMT_R11G11B10_FLOAT;
302 case DXGI_FORMAT_R8G8B8A8_TYPELESS: return WINED3DFMT_R8G8B8A8_TYPELESS;
303 case DXGI_FORMAT_R8G8B8A8_UNORM: return WINED3DFMT_R8G8B8A8_UNORM;
304 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: return WINED3DFMT_R8G8B8A8_UNORM_SRGB;
305 case DXGI_FORMAT_R8G8B8A8_UINT: return WINED3DFMT_R8G8B8A8_UINT;
306 case DXGI_FORMAT_R8G8B8A8_SNORM: return WINED3DFMT_R8G8B8A8_SNORM;
307 case DXGI_FORMAT_R8G8B8A8_SINT: return WINED3DFMT_R8G8B8A8_SINT;
308 case DXGI_FORMAT_R16G16_TYPELESS: return WINED3DFMT_R16G16_TYPELESS;
309 case DXGI_FORMAT_R16G16_FLOAT: return WINED3DFMT_R16G16_FLOAT;
310 case DXGI_FORMAT_R16G16_UNORM: return WINED3DFMT_R16G16_UNORM;
311 case DXGI_FORMAT_R16G16_UINT: return WINED3DFMT_R16G16_UINT;
312 case DXGI_FORMAT_R16G16_SNORM: return WINED3DFMT_R16G16_SNORM;
313 case DXGI_FORMAT_R16G16_SINT: return WINED3DFMT_R16G16_SINT;
314 case DXGI_FORMAT_R32_TYPELESS: return WINED3DFMT_R32_TYPELESS;
315 case DXGI_FORMAT_D32_FLOAT: return WINED3DFMT_D32_FLOAT;
316 case DXGI_FORMAT_R32_FLOAT: return WINED3DFMT_R32_FLOAT;
317 case DXGI_FORMAT_R32_UINT: return WINED3DFMT_R32_UINT;
318 case DXGI_FORMAT_R32_SINT: return WINED3DFMT_R32_SINT;
319 case DXGI_FORMAT_R24G8_TYPELESS: return WINED3DFMT_R24G8_TYPELESS;
320 case DXGI_FORMAT_D24_UNORM_S8_UINT: return WINED3DFMT_D24_UNORM_S8_UINT;
321 case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: return WINED3DFMT_R24_UNORM_X8_TYPELESS;
322 case DXGI_FORMAT_X24_TYPELESS_G8_UINT: return WINED3DFMT_X24_TYPELESS_G8_UINT;
323 case DXGI_FORMAT_R8G8_TYPELESS: return WINED3DFMT_R8G8_TYPELESS;
324 case DXGI_FORMAT_R8G8_UNORM: return WINED3DFMT_R8G8_UNORM;
325 case DXGI_FORMAT_R8G8_UINT: return WINED3DFMT_R8G8_UINT;
326 case DXGI_FORMAT_R8G8_SNORM: return WINED3DFMT_R8G8_SNORM;
327 case DXGI_FORMAT_R8G8_SINT: return WINED3DFMT_R8G8_SINT;
328 case DXGI_FORMAT_R16_TYPELESS: return WINED3DFMT_R16_TYPELESS;
329 case DXGI_FORMAT_R16_FLOAT: return WINED3DFMT_R16_FLOAT;
330 case DXGI_FORMAT_D16_UNORM: return WINED3DFMT_D16_UNORM;
331 case DXGI_FORMAT_R16_UNORM: return WINED3DFMT_R16_UNORM;
332 case DXGI_FORMAT_R16_UINT: return WINED3DFMT_R16_UINT;
333 case DXGI_FORMAT_R16_SNORM: return WINED3DFMT_R16_SNORM;
334 case DXGI_FORMAT_R16_SINT: return WINED3DFMT_R16_SINT;
335 case DXGI_FORMAT_R8_TYPELESS: return WINED3DFMT_R8_TYPELESS;
336 case DXGI_FORMAT_R8_UNORM: return WINED3DFMT_R8_UNORM;
337 case DXGI_FORMAT_R8_UINT: return WINED3DFMT_R8_UINT;
338 case DXGI_FORMAT_R8_SNORM: return WINED3DFMT_R8_SNORM;
339 case DXGI_FORMAT_R8_SINT: return WINED3DFMT_R8_SINT;
340 case DXGI_FORMAT_A8_UNORM: return WINED3DFMT_A8_UNORM;
341 case DXGI_FORMAT_R1_UNORM: return WINED3DFMT_R1_UNORM;
342 case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: return WINED3DFMT_R9G9B9E5_SHAREDEXP;
343 case DXGI_FORMAT_R8G8_B8G8_UNORM: return WINED3DFMT_R8G8_B8G8_UNORM;
344 case DXGI_FORMAT_G8R8_G8B8_UNORM: return WINED3DFMT_G8R8_G8B8_UNORM;
345 case DXGI_FORMAT_BC1_TYPELESS: return WINED3DFMT_BC1_TYPELESS;
346 case DXGI_FORMAT_BC1_UNORM: return WINED3DFMT_BC1_UNORM;
347 case DXGI_FORMAT_BC1_UNORM_SRGB: return WINED3DFMT_BC1_UNORM_SRGB;
348 case DXGI_FORMAT_BC2_TYPELESS: return WINED3DFMT_BC2_TYPELESS;
349 case DXGI_FORMAT_BC2_UNORM: return WINED3DFMT_BC2_UNORM;
350 case DXGI_FORMAT_BC2_UNORM_SRGB: return WINED3DFMT_BC2_UNORM_SRGB;
351 case DXGI_FORMAT_BC3_TYPELESS: return WINED3DFMT_BC3_TYPELESS;
352 case DXGI_FORMAT_BC3_UNORM: return WINED3DFMT_BC3_UNORM;
353 case DXGI_FORMAT_BC3_UNORM_SRGB: return WINED3DFMT_BC3_UNORM_SRGB;
354 case DXGI_FORMAT_BC4_TYPELESS: return WINED3DFMT_BC4_TYPELESS;
355 case DXGI_FORMAT_BC4_UNORM: return WINED3DFMT_BC4_UNORM;
356 case DXGI_FORMAT_BC4_SNORM: return WINED3DFMT_BC4_SNORM;
357 case DXGI_FORMAT_BC5_TYPELESS: return WINED3DFMT_BC5_TYPELESS;
358 case DXGI_FORMAT_BC5_UNORM: return WINED3DFMT_BC5_UNORM;
359 case DXGI_FORMAT_BC5_SNORM: return WINED3DFMT_BC5_SNORM;
360 case DXGI_FORMAT_B5G6R5_UNORM: return WINED3DFMT_B5G6R5_UNORM;
361 case DXGI_FORMAT_B5G5R5A1_UNORM: return WINED3DFMT_B5G5R5A1_UNORM;
362 case DXGI_FORMAT_B8G8R8A8_UNORM: return WINED3DFMT_B8G8R8A8_UNORM;
363 case DXGI_FORMAT_B8G8R8X8_UNORM: return WINED3DFMT_B8G8R8X8_UNORM;
364 case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM: return WINED3DFMT_R10G10B10_XR_BIAS_A2_UNORM;
365 case DXGI_FORMAT_B8G8R8A8_TYPELESS: return WINED3DFMT_B8G8R8A8_TYPELESS;
366 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: return WINED3DFMT_B8G8R8A8_UNORM_SRGB;
367 case DXGI_FORMAT_B8G8R8X8_TYPELESS: return WINED3DFMT_B8G8R8X8_TYPELESS;
368 case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: return WINED3DFMT_B8G8R8X8_UNORM_SRGB;
369 case DXGI_FORMAT_BC6H_TYPELESS: return WINED3DFMT_BC6H_TYPELESS;
370 case DXGI_FORMAT_BC6H_UF16: return WINED3DFMT_BC6H_UF16;
371 case DXGI_FORMAT_BC6H_SF16: return WINED3DFMT_BC6H_SF16;
372 case DXGI_FORMAT_BC7_TYPELESS: return WINED3DFMT_BC7_TYPELESS;
373 case DXGI_FORMAT_BC7_UNORM: return WINED3DFMT_BC7_UNORM;
374 case DXGI_FORMAT_BC7_UNORM_SRGB: return WINED3DFMT_BC7_UNORM_SRGB;
375 case DXGI_FORMAT_B4G4R4A4_UNORM: return WINED3DFMT_B4G4R4A4_UNORM;
376 default:
377 FIXME("Unhandled DXGI_FORMAT %#x.\n", format);
378 return WINED3DFMT_UNKNOWN;
382 const char *debug_dxgi_mode(const DXGI_MODE_DESC *desc)
384 return wine_dbg_sprintf("resolution %ux%u, refresh rate %u / %u, "
385 "format %s, scanline ordering %#x, scaling %#x",
386 desc->Width, desc->Height, desc->RefreshRate.Numerator, desc->RefreshRate.Denominator,
387 debug_dxgi_format(desc->Format), desc->ScanlineOrdering, desc->Scaling);
390 void dump_feature_levels(const D3D_FEATURE_LEVEL *feature_levels, unsigned int level_count)
392 unsigned int i;
394 if (!feature_levels || !level_count)
396 TRACE("Feature levels: (null).\n");
397 return;
400 TRACE("Feature levels (count = %u):\n", level_count);
401 for (i = 0; i < level_count; ++i)
402 TRACE(" [%u] = %s.\n", i, debug_feature_level(feature_levels[i]));
405 UINT dxgi_rational_to_uint(const DXGI_RATIONAL *rational)
407 if (rational->Denominator)
408 return rational->Numerator / rational->Denominator;
409 else
410 return rational->Numerator;
413 static enum wined3d_scanline_ordering wined3d_scanline_ordering_from_dxgi(DXGI_MODE_SCANLINE_ORDER scanline_order)
415 switch (scanline_order)
417 case DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED:
418 return WINED3D_SCANLINE_ORDERING_UNKNOWN;
419 case DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE:
420 return WINED3D_SCANLINE_ORDERING_PROGRESSIVE;
421 default:
422 FIXME("Unhandled scanline ordering %#x.\n", scanline_order);
423 return WINED3D_SCANLINE_ORDERING_UNKNOWN;
427 void dxgi_sample_desc_from_wined3d(DXGI_SAMPLE_DESC *desc,
428 enum wined3d_multisample_type wined3d_type, unsigned int wined3d_quality)
430 desc->Count = wined3d_type == WINED3D_MULTISAMPLE_NONE ? 1 : wined3d_type;
431 desc->Quality = wined3d_quality;
434 void wined3d_sample_desc_from_dxgi(enum wined3d_multisample_type *wined3d_type,
435 unsigned int *wined3d_quality, const DXGI_SAMPLE_DESC *dxgi_desc)
437 if (dxgi_desc->Count > 1)
439 *wined3d_type = dxgi_desc->Count;
440 *wined3d_quality = dxgi_desc->Quality;
442 else
444 *wined3d_type = WINED3D_MULTISAMPLE_NONE;
445 *wined3d_quality = 0;
449 void wined3d_display_mode_from_dxgi(struct wined3d_display_mode *wined3d_mode,
450 const DXGI_MODE_DESC *mode)
452 wined3d_mode->width = mode->Width;
453 wined3d_mode->height = mode->Height;
454 wined3d_mode->refresh_rate = dxgi_rational_to_uint(&mode->RefreshRate);
455 wined3d_mode->format_id = wined3dformat_from_dxgi_format(mode->Format);
456 wined3d_mode->scanline_ordering = wined3d_scanline_ordering_from_dxgi(mode->ScanlineOrdering);
459 DXGI_USAGE dxgi_usage_from_wined3d_usage(DWORD wined3d_usage)
461 DXGI_USAGE dxgi_usage = 0;
463 if (wined3d_usage & WINED3DUSAGE_TEXTURE)
464 dxgi_usage |= DXGI_USAGE_SHADER_INPUT;
465 if (wined3d_usage & WINED3DUSAGE_RENDERTARGET)
466 dxgi_usage |= DXGI_USAGE_RENDER_TARGET_OUTPUT;
468 wined3d_usage &= ~(WINED3DUSAGE_TEXTURE | WINED3DUSAGE_RENDERTARGET);
469 if (wined3d_usage)
470 FIXME("Unhandled wined3d usage %#x.\n", wined3d_usage);
471 return dxgi_usage;
474 DWORD wined3d_usage_from_dxgi_usage(DXGI_USAGE dxgi_usage)
476 DWORD wined3d_usage = 0;
478 if (dxgi_usage & DXGI_USAGE_SHADER_INPUT)
479 wined3d_usage |= WINED3DUSAGE_TEXTURE;
480 if (dxgi_usage & DXGI_USAGE_RENDER_TARGET_OUTPUT)
481 wined3d_usage |= WINED3DUSAGE_RENDERTARGET;
483 dxgi_usage &= ~(DXGI_USAGE_SHADER_INPUT | DXGI_USAGE_RENDER_TARGET_OUTPUT);
484 if (dxgi_usage)
485 FIXME("Unhandled DXGI usage %#x.\n", dxgi_usage);
486 return wined3d_usage;
489 #define DXGI_WINED3D_SWAPCHAIN_FLAGS \
490 (WINED3D_SWAPCHAIN_USE_CLOSEST_MATCHING_MODE | WINED3D_SWAPCHAIN_RESTORE_WINDOW_RECT)
492 unsigned int dxgi_swapchain_flags_from_wined3d(unsigned int wined3d_flags)
494 unsigned int flags = 0;
496 wined3d_flags &= ~DXGI_WINED3D_SWAPCHAIN_FLAGS;
498 if (wined3d_flags & WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH)
500 wined3d_flags &= ~WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH;
501 flags |= DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
504 if (wined3d_flags & WINED3D_SWAPCHAIN_GDI_COMPATIBLE)
506 wined3d_flags &= ~WINED3D_SWAPCHAIN_GDI_COMPATIBLE;
507 flags |= DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE;
510 if (wined3d_flags)
511 FIXME("Unhandled flags %#x.\n", flags);
513 return flags;
516 unsigned int wined3d_swapchain_flags_from_dxgi(unsigned int flags)
518 unsigned int wined3d_flags = DXGI_WINED3D_SWAPCHAIN_FLAGS; /* WINED3D_SWAPCHAIN_DISCARD_DEPTHSTENCIL? */
520 if (flags & DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH)
522 flags &= ~DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
523 wined3d_flags |= WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH;
526 if (flags & DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE)
528 flags &= ~DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE;
529 wined3d_flags |= WINED3D_SWAPCHAIN_GDI_COMPATIBLE;
532 if (flags)
533 FIXME("Unhandled flags %#x.\n", flags);
535 return wined3d_flags;
538 HRESULT dxgi_get_private_data(struct wined3d_private_store *store,
539 REFGUID guid, UINT *data_size, void *data)
541 const struct wined3d_private_data *stored_data;
542 DWORD size_in;
543 HRESULT hr;
545 if (!data_size)
546 return E_INVALIDARG;
548 wined3d_mutex_lock();
549 if (!(stored_data = wined3d_private_store_get_private_data(store, guid)))
551 hr = DXGI_ERROR_NOT_FOUND;
552 *data_size = 0;
553 goto done;
556 size_in = *data_size;
557 *data_size = stored_data->size;
558 if (!data)
560 hr = S_OK;
561 goto done;
563 if (size_in < stored_data->size)
565 hr = DXGI_ERROR_MORE_DATA;
566 goto done;
569 if (stored_data->flags & WINED3DSPD_IUNKNOWN)
570 IUnknown_AddRef(stored_data->content.object);
571 memcpy(data, stored_data->content.data, stored_data->size);
572 hr = S_OK;
574 done:
575 wined3d_mutex_unlock();
577 return hr;
580 HRESULT dxgi_set_private_data(struct wined3d_private_store *store,
581 REFGUID guid, UINT data_size, const void *data)
583 struct wined3d_private_data *entry;
584 HRESULT hr;
586 if (!data)
588 wined3d_mutex_lock();
589 if (!(entry = wined3d_private_store_get_private_data(store, guid)))
591 wined3d_mutex_unlock();
592 return S_FALSE;
595 wined3d_private_store_free_private_data(store, entry);
596 wined3d_mutex_unlock();
598 return S_OK;
601 wined3d_mutex_lock();
602 hr = wined3d_private_store_set_private_data(store, guid, data, data_size, 0);
603 wined3d_mutex_unlock();
605 return hr;
608 HRESULT dxgi_set_private_data_interface(struct wined3d_private_store *store,
609 REFGUID guid, const IUnknown *object)
611 HRESULT hr;
613 if (!object)
614 return dxgi_set_private_data(store, guid, sizeof(object), &object);
616 wined3d_mutex_lock();
617 hr = wined3d_private_store_set_private_data(store,
618 guid, object, sizeof(object), WINED3DSPD_IUNKNOWN);
619 wined3d_mutex_unlock();
621 return hr;
624 D3D_FEATURE_LEVEL dxgi_check_feature_level_support(struct dxgi_factory *factory, struct dxgi_adapter *adapter,
625 const D3D_FEATURE_LEVEL *feature_levels, unsigned int level_count)
627 static const struct
629 D3D_FEATURE_LEVEL feature_level;
630 unsigned int sm;
632 feature_levels_sm[] =
634 {D3D_FEATURE_LEVEL_11_1, 5},
635 {D3D_FEATURE_LEVEL_11_0, 5},
636 {D3D_FEATURE_LEVEL_10_1, 4},
637 {D3D_FEATURE_LEVEL_10_0, 4},
638 {D3D_FEATURE_LEVEL_9_3, 3},
639 {D3D_FEATURE_LEVEL_9_2, 2},
640 {D3D_FEATURE_LEVEL_9_1, 2},
642 D3D_FEATURE_LEVEL selected_feature_level = 0;
643 unsigned int shader_model;
644 unsigned int i, j;
645 WINED3DCAPS caps;
646 HRESULT hr;
648 FIXME("Ignoring adapter type.\n");
650 wined3d_mutex_lock();
651 hr = wined3d_get_device_caps(factory->wined3d, adapter->ordinal, WINED3D_DEVICE_TYPE_HAL, &caps);
652 wined3d_mutex_unlock();
654 if (FAILED(hr))
655 level_count = 0;
657 shader_model = min(caps.VertexShaderVersion, caps.PixelShaderVersion);
658 for (i = 0; i < level_count; ++i)
660 for (j = 0; j < sizeof(feature_levels_sm) / sizeof(feature_levels_sm[0]); ++j)
662 if (feature_levels[i] == feature_levels_sm[j].feature_level)
664 if (shader_model >= feature_levels_sm[j].sm)
666 selected_feature_level = feature_levels[i];
667 TRACE("Choosing supported feature level %s (SM%u).\n",
668 debug_feature_level(selected_feature_level), feature_levels_sm[j].sm);
670 break;
673 if (selected_feature_level)
674 break;
676 if (j == sizeof(feature_levels_sm) / sizeof(feature_levels_sm[0]))
677 FIXME("Unexpected feature level %#x.\n", feature_levels[i]);
678 else
679 TRACE("Feature level %s not supported, trying next fallback if available.\n",
680 debug_feature_level(feature_levels[i]));
682 if (!selected_feature_level)
683 FIXME_(winediag)("None of the requested D3D feature levels is supported on this GPU "
684 "with the current shader backend.\n");
686 return selected_feature_level;