jscript: Use already running interpreter for execution of member source function.
[wine.git] / dlls / dxgi / utils.c
blobc0c1fcd8a8daf0985f66362ac5954e8829ac81a3
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_B8G8R8A8_TYPELESS);
141 WINE_DXGI_TO_STR(DXGI_FORMAT_B8G8R8A8_UNORM_SRGB);
142 WINE_DXGI_TO_STR(DXGI_FORMAT_B8G8R8X8_TYPELESS);
143 WINE_DXGI_TO_STR(DXGI_FORMAT_B8G8R8X8_UNORM_SRGB);
144 WINE_DXGI_TO_STR(DXGI_FORMAT_BC7_TYPELESS);
145 WINE_DXGI_TO_STR(DXGI_FORMAT_BC7_UNORM);
146 WINE_DXGI_TO_STR(DXGI_FORMAT_BC7_UNORM_SRGB);
147 default:
148 FIXME("Unrecognized DXGI_FORMAT %#x.\n", format);
149 return "unrecognized";
153 #undef WINE_DXGI_TO_STR
155 DXGI_FORMAT dxgi_format_from_wined3dformat(enum wined3d_format_id format)
157 switch(format)
159 case WINED3DFMT_UNKNOWN: return DXGI_FORMAT_UNKNOWN;
160 case WINED3DFMT_R32G32B32A32_TYPELESS: return DXGI_FORMAT_R32G32B32A32_TYPELESS;
161 case WINED3DFMT_R32G32B32A32_FLOAT: return DXGI_FORMAT_R32G32B32A32_FLOAT;
162 case WINED3DFMT_R32G32B32A32_UINT: return DXGI_FORMAT_R32G32B32A32_UINT;
163 case WINED3DFMT_R32G32B32A32_SINT: return DXGI_FORMAT_R32G32B32A32_SINT;
164 case WINED3DFMT_R32G32B32_TYPELESS: return DXGI_FORMAT_R32G32B32_TYPELESS;
165 case WINED3DFMT_R32G32B32_FLOAT: return DXGI_FORMAT_R32G32B32_FLOAT;
166 case WINED3DFMT_R32G32B32_UINT: return DXGI_FORMAT_R32G32B32_UINT;
167 case WINED3DFMT_R32G32B32_SINT: return DXGI_FORMAT_R32G32B32_SINT;
168 case WINED3DFMT_R16G16B16A16_TYPELESS: return DXGI_FORMAT_R16G16B16A16_TYPELESS;
169 case WINED3DFMT_R16G16B16A16_FLOAT: return DXGI_FORMAT_R16G16B16A16_FLOAT;
170 case WINED3DFMT_R16G16B16A16_UNORM: return DXGI_FORMAT_R16G16B16A16_UNORM;
171 case WINED3DFMT_R16G16B16A16_UINT: return DXGI_FORMAT_R16G16B16A16_UINT;
172 case WINED3DFMT_R16G16B16A16_SNORM: return DXGI_FORMAT_R16G16B16A16_SNORM;
173 case WINED3DFMT_R16G16B16A16_SINT: return DXGI_FORMAT_R16G16B16A16_SINT;
174 case WINED3DFMT_R32G32_TYPELESS: return DXGI_FORMAT_R32G32_TYPELESS;
175 case WINED3DFMT_R32G32_FLOAT: return DXGI_FORMAT_R32G32_FLOAT;
176 case WINED3DFMT_R32G32_UINT: return DXGI_FORMAT_R32G32_UINT;
177 case WINED3DFMT_R32G32_SINT: return DXGI_FORMAT_R32G32_SINT;
178 case WINED3DFMT_R32G8X24_TYPELESS: return DXGI_FORMAT_R32G8X24_TYPELESS;
179 case WINED3DFMT_D32_FLOAT_S8X24_UINT: return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
180 case WINED3DFMT_R32_FLOAT_X8X24_TYPELESS: return DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS;
181 case WINED3DFMT_X32_TYPELESS_G8X24_UINT: return DXGI_FORMAT_X32_TYPELESS_G8X24_UINT;
182 case WINED3DFMT_R10G10B10A2_TYPELESS: return DXGI_FORMAT_R10G10B10A2_TYPELESS;
183 case WINED3DFMT_R10G10B10A2_UNORM: return DXGI_FORMAT_R10G10B10A2_UNORM;
184 case WINED3DFMT_R10G10B10A2_UINT: return DXGI_FORMAT_R10G10B10A2_UINT;
185 case WINED3DFMT_R11G11B10_FLOAT: return DXGI_FORMAT_R11G11B10_FLOAT;
186 case WINED3DFMT_R8G8B8A8_TYPELESS: return DXGI_FORMAT_R8G8B8A8_TYPELESS;
187 case WINED3DFMT_R8G8B8A8_UNORM: return DXGI_FORMAT_R8G8B8A8_UNORM;
188 case WINED3DFMT_R8G8B8A8_UNORM_SRGB: return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
189 case WINED3DFMT_R8G8B8A8_UINT: return DXGI_FORMAT_R8G8B8A8_UINT;
190 case WINED3DFMT_R8G8B8A8_SNORM: return DXGI_FORMAT_R8G8B8A8_SNORM;
191 case WINED3DFMT_R8G8B8A8_SINT: return DXGI_FORMAT_R8G8B8A8_SINT;
192 case WINED3DFMT_R16G16_TYPELESS: return DXGI_FORMAT_R16G16_TYPELESS;
193 case WINED3DFMT_R16G16_FLOAT: return DXGI_FORMAT_R16G16_FLOAT;
194 case WINED3DFMT_R16G16_UNORM: return DXGI_FORMAT_R16G16_UNORM;
195 case WINED3DFMT_R16G16_UINT: return DXGI_FORMAT_R16G16_UINT;
196 case WINED3DFMT_R16G16_SNORM: return DXGI_FORMAT_R16G16_SNORM;
197 case WINED3DFMT_R16G16_SINT: return DXGI_FORMAT_R16G16_SINT;
198 case WINED3DFMT_R32_TYPELESS: return DXGI_FORMAT_R32_TYPELESS;
199 case WINED3DFMT_D32_FLOAT: return DXGI_FORMAT_D32_FLOAT;
200 case WINED3DFMT_R32_FLOAT: return DXGI_FORMAT_R32_FLOAT;
201 case WINED3DFMT_R32_UINT: return DXGI_FORMAT_R32_UINT;
202 case WINED3DFMT_R32_SINT: return DXGI_FORMAT_R32_SINT;
203 case WINED3DFMT_R24G8_TYPELESS: return DXGI_FORMAT_R24G8_TYPELESS;
204 case WINED3DFMT_D24_UNORM_S8_UINT: return DXGI_FORMAT_D24_UNORM_S8_UINT;
205 case WINED3DFMT_R24_UNORM_X8_TYPELESS: return DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
206 case WINED3DFMT_X24_TYPELESS_G8_UINT: return DXGI_FORMAT_X24_TYPELESS_G8_UINT;
207 case WINED3DFMT_R8G8_TYPELESS: return DXGI_FORMAT_R8G8_TYPELESS;
208 case WINED3DFMT_R8G8_UNORM: return DXGI_FORMAT_R8G8_UNORM;
209 case WINED3DFMT_R8G8_UINT: return DXGI_FORMAT_R8G8_UINT;
210 case WINED3DFMT_R8G8_SNORM: return DXGI_FORMAT_R8G8_SNORM;
211 case WINED3DFMT_R8G8_SINT: return DXGI_FORMAT_R8G8_SINT;
212 case WINED3DFMT_R16_TYPELESS: return DXGI_FORMAT_R16_TYPELESS;
213 case WINED3DFMT_R16_FLOAT: return DXGI_FORMAT_R16_FLOAT;
214 case WINED3DFMT_D16_UNORM: return DXGI_FORMAT_D16_UNORM;
215 case WINED3DFMT_R16_UNORM: return DXGI_FORMAT_R16_UNORM;
216 case WINED3DFMT_R16_UINT: return DXGI_FORMAT_R16_UINT;
217 case WINED3DFMT_R16_SNORM: return DXGI_FORMAT_R16_SNORM;
218 case WINED3DFMT_R16_SINT: return DXGI_FORMAT_R16_SINT;
219 case WINED3DFMT_R8_TYPELESS: return DXGI_FORMAT_R8_TYPELESS;
220 case WINED3DFMT_R8_UNORM: return DXGI_FORMAT_R8_UNORM;
221 case WINED3DFMT_R8_UINT: return DXGI_FORMAT_R8_UINT;
222 case WINED3DFMT_R8_SNORM: return DXGI_FORMAT_R8_SNORM;
223 case WINED3DFMT_R8_SINT: return DXGI_FORMAT_R8_SINT;
224 case WINED3DFMT_A8_UNORM: return DXGI_FORMAT_A8_UNORM;
225 case WINED3DFMT_R1_UNORM: return DXGI_FORMAT_R1_UNORM;
226 case WINED3DFMT_R9G9B9E5_SHAREDEXP: return DXGI_FORMAT_R9G9B9E5_SHAREDEXP;
227 case WINED3DFMT_R8G8_B8G8_UNORM: return DXGI_FORMAT_R8G8_B8G8_UNORM;
228 case WINED3DFMT_G8R8_G8B8_UNORM: return DXGI_FORMAT_G8R8_G8B8_UNORM;
229 case WINED3DFMT_BC1_TYPELESS: return DXGI_FORMAT_BC1_TYPELESS;
230 case WINED3DFMT_BC1_UNORM: return DXGI_FORMAT_BC1_UNORM;
231 case WINED3DFMT_BC1_UNORM_SRGB: return DXGI_FORMAT_BC1_UNORM_SRGB;
232 case WINED3DFMT_BC2_TYPELESS: return DXGI_FORMAT_BC2_TYPELESS;
233 case WINED3DFMT_BC2_UNORM: return DXGI_FORMAT_BC2_UNORM;
234 case WINED3DFMT_BC2_UNORM_SRGB: return DXGI_FORMAT_BC2_UNORM_SRGB;
235 case WINED3DFMT_BC3_TYPELESS: return DXGI_FORMAT_BC3_TYPELESS;
236 case WINED3DFMT_BC3_UNORM: return DXGI_FORMAT_BC3_UNORM;
237 case WINED3DFMT_BC3_UNORM_SRGB: return DXGI_FORMAT_BC3_UNORM_SRGB;
238 case WINED3DFMT_BC4_TYPELESS: return DXGI_FORMAT_BC4_TYPELESS;
239 case WINED3DFMT_BC4_UNORM: return DXGI_FORMAT_BC4_UNORM;
240 case WINED3DFMT_BC4_SNORM: return DXGI_FORMAT_BC4_SNORM;
241 case WINED3DFMT_BC5_TYPELESS: return DXGI_FORMAT_BC5_TYPELESS;
242 case WINED3DFMT_BC5_UNORM: return DXGI_FORMAT_BC5_UNORM;
243 case WINED3DFMT_BC5_SNORM: return DXGI_FORMAT_BC5_SNORM;
244 case WINED3DFMT_B5G6R5_UNORM: return DXGI_FORMAT_B5G6R5_UNORM;
245 case WINED3DFMT_B5G5R5A1_UNORM: return DXGI_FORMAT_B5G5R5A1_UNORM;
246 case WINED3DFMT_B8G8R8A8_UNORM: return DXGI_FORMAT_B8G8R8A8_UNORM;
247 case WINED3DFMT_B8G8R8X8_UNORM: return DXGI_FORMAT_B8G8R8X8_UNORM;
248 case WINED3DFMT_B8G8R8A8_TYPELESS: return DXGI_FORMAT_B8G8R8A8_TYPELESS;
249 case WINED3DFMT_B8G8R8A8_UNORM_SRGB: return DXGI_FORMAT_B8G8R8A8_UNORM_SRGB;
250 case WINED3DFMT_B8G8R8X8_TYPELESS: return DXGI_FORMAT_B8G8R8X8_TYPELESS;
251 case WINED3DFMT_B8G8R8X8_UNORM_SRGB: return DXGI_FORMAT_B8G8R8X8_UNORM_SRGB;
252 case WINED3DFMT_BC7_TYPELESS: return DXGI_FORMAT_BC7_TYPELESS;
253 case WINED3DFMT_BC7_UNORM: return DXGI_FORMAT_BC7_UNORM;
254 case WINED3DFMT_BC7_UNORM_SRGB: return DXGI_FORMAT_BC7_UNORM_SRGB;
255 default:
256 FIXME("Unhandled wined3d format %#x.\n", format);
257 return DXGI_FORMAT_UNKNOWN;
261 enum wined3d_format_id wined3dformat_from_dxgi_format(DXGI_FORMAT format)
263 switch(format)
265 case DXGI_FORMAT_UNKNOWN: return WINED3DFMT_UNKNOWN;
266 case DXGI_FORMAT_R32G32B32A32_TYPELESS: return WINED3DFMT_R32G32B32A32_TYPELESS;
267 case DXGI_FORMAT_R32G32B32A32_FLOAT: return WINED3DFMT_R32G32B32A32_FLOAT;
268 case DXGI_FORMAT_R32G32B32A32_UINT: return WINED3DFMT_R32G32B32A32_UINT;
269 case DXGI_FORMAT_R32G32B32A32_SINT: return WINED3DFMT_R32G32B32A32_SINT;
270 case DXGI_FORMAT_R32G32B32_TYPELESS: return WINED3DFMT_R32G32B32_TYPELESS;
271 case DXGI_FORMAT_R32G32B32_FLOAT: return WINED3DFMT_R32G32B32_FLOAT;
272 case DXGI_FORMAT_R32G32B32_UINT: return WINED3DFMT_R32G32B32_UINT;
273 case DXGI_FORMAT_R32G32B32_SINT: return WINED3DFMT_R32G32B32_SINT;
274 case DXGI_FORMAT_R16G16B16A16_TYPELESS: return WINED3DFMT_R16G16B16A16_TYPELESS;
275 case DXGI_FORMAT_R16G16B16A16_FLOAT: return WINED3DFMT_R16G16B16A16_FLOAT;
276 case DXGI_FORMAT_R16G16B16A16_UNORM: return WINED3DFMT_R16G16B16A16_UNORM;
277 case DXGI_FORMAT_R16G16B16A16_UINT: return WINED3DFMT_R16G16B16A16_UINT;
278 case DXGI_FORMAT_R16G16B16A16_SNORM: return WINED3DFMT_R16G16B16A16_SNORM;
279 case DXGI_FORMAT_R16G16B16A16_SINT: return WINED3DFMT_R16G16B16A16_SINT;
280 case DXGI_FORMAT_R32G32_TYPELESS: return WINED3DFMT_R32G32_TYPELESS;
281 case DXGI_FORMAT_R32G32_FLOAT: return WINED3DFMT_R32G32_FLOAT;
282 case DXGI_FORMAT_R32G32_UINT: return WINED3DFMT_R32G32_UINT;
283 case DXGI_FORMAT_R32G32_SINT: return WINED3DFMT_R32G32_SINT;
284 case DXGI_FORMAT_R32G8X24_TYPELESS: return WINED3DFMT_R32G8X24_TYPELESS;
285 case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: return WINED3DFMT_D32_FLOAT_S8X24_UINT;
286 case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: return WINED3DFMT_R32_FLOAT_X8X24_TYPELESS;
287 case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: return WINED3DFMT_X32_TYPELESS_G8X24_UINT;
288 case DXGI_FORMAT_R10G10B10A2_TYPELESS: return WINED3DFMT_R10G10B10A2_TYPELESS;
289 case DXGI_FORMAT_R10G10B10A2_UNORM: return WINED3DFMT_R10G10B10A2_UNORM;
290 case DXGI_FORMAT_R10G10B10A2_UINT: return WINED3DFMT_R10G10B10A2_UINT;
291 case DXGI_FORMAT_R11G11B10_FLOAT: return WINED3DFMT_R11G11B10_FLOAT;
292 case DXGI_FORMAT_R8G8B8A8_TYPELESS: return WINED3DFMT_R8G8B8A8_TYPELESS;
293 case DXGI_FORMAT_R8G8B8A8_UNORM: return WINED3DFMT_R8G8B8A8_UNORM;
294 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: return WINED3DFMT_R8G8B8A8_UNORM_SRGB;
295 case DXGI_FORMAT_R8G8B8A8_UINT: return WINED3DFMT_R8G8B8A8_UINT;
296 case DXGI_FORMAT_R8G8B8A8_SNORM: return WINED3DFMT_R8G8B8A8_SNORM;
297 case DXGI_FORMAT_R8G8B8A8_SINT: return WINED3DFMT_R8G8B8A8_SINT;
298 case DXGI_FORMAT_R16G16_TYPELESS: return WINED3DFMT_R16G16_TYPELESS;
299 case DXGI_FORMAT_R16G16_FLOAT: return WINED3DFMT_R16G16_FLOAT;
300 case DXGI_FORMAT_R16G16_UNORM: return WINED3DFMT_R16G16_UNORM;
301 case DXGI_FORMAT_R16G16_UINT: return WINED3DFMT_R16G16_UINT;
302 case DXGI_FORMAT_R16G16_SNORM: return WINED3DFMT_R16G16_SNORM;
303 case DXGI_FORMAT_R16G16_SINT: return WINED3DFMT_R16G16_SINT;
304 case DXGI_FORMAT_R32_TYPELESS: return WINED3DFMT_R32_TYPELESS;
305 case DXGI_FORMAT_D32_FLOAT: return WINED3DFMT_D32_FLOAT;
306 case DXGI_FORMAT_R32_FLOAT: return WINED3DFMT_R32_FLOAT;
307 case DXGI_FORMAT_R32_UINT: return WINED3DFMT_R32_UINT;
308 case DXGI_FORMAT_R32_SINT: return WINED3DFMT_R32_SINT;
309 case DXGI_FORMAT_R24G8_TYPELESS: return WINED3DFMT_R24G8_TYPELESS;
310 case DXGI_FORMAT_D24_UNORM_S8_UINT: return WINED3DFMT_D24_UNORM_S8_UINT;
311 case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: return WINED3DFMT_R24_UNORM_X8_TYPELESS;
312 case DXGI_FORMAT_X24_TYPELESS_G8_UINT: return WINED3DFMT_X24_TYPELESS_G8_UINT;
313 case DXGI_FORMAT_R8G8_TYPELESS: return WINED3DFMT_R8G8_TYPELESS;
314 case DXGI_FORMAT_R8G8_UNORM: return WINED3DFMT_R8G8_UNORM;
315 case DXGI_FORMAT_R8G8_UINT: return WINED3DFMT_R8G8_UINT;
316 case DXGI_FORMAT_R8G8_SNORM: return WINED3DFMT_R8G8_SNORM;
317 case DXGI_FORMAT_R8G8_SINT: return WINED3DFMT_R8G8_SINT;
318 case DXGI_FORMAT_R16_TYPELESS: return WINED3DFMT_R16_TYPELESS;
319 case DXGI_FORMAT_R16_FLOAT: return WINED3DFMT_R16_FLOAT;
320 case DXGI_FORMAT_D16_UNORM: return WINED3DFMT_D16_UNORM;
321 case DXGI_FORMAT_R16_UNORM: return WINED3DFMT_R16_UNORM;
322 case DXGI_FORMAT_R16_UINT: return WINED3DFMT_R16_UINT;
323 case DXGI_FORMAT_R16_SNORM: return WINED3DFMT_R16_SNORM;
324 case DXGI_FORMAT_R16_SINT: return WINED3DFMT_R16_SINT;
325 case DXGI_FORMAT_R8_TYPELESS: return WINED3DFMT_R8_TYPELESS;
326 case DXGI_FORMAT_R8_UNORM: return WINED3DFMT_R8_UNORM;
327 case DXGI_FORMAT_R8_UINT: return WINED3DFMT_R8_UINT;
328 case DXGI_FORMAT_R8_SNORM: return WINED3DFMT_R8_SNORM;
329 case DXGI_FORMAT_R8_SINT: return WINED3DFMT_R8_SINT;
330 case DXGI_FORMAT_A8_UNORM: return WINED3DFMT_A8_UNORM;
331 case DXGI_FORMAT_R1_UNORM: return WINED3DFMT_R1_UNORM;
332 case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: return WINED3DFMT_R9G9B9E5_SHAREDEXP;
333 case DXGI_FORMAT_R8G8_B8G8_UNORM: return WINED3DFMT_R8G8_B8G8_UNORM;
334 case DXGI_FORMAT_G8R8_G8B8_UNORM: return WINED3DFMT_G8R8_G8B8_UNORM;
335 case DXGI_FORMAT_BC1_TYPELESS: return WINED3DFMT_BC1_TYPELESS;
336 case DXGI_FORMAT_BC1_UNORM: return WINED3DFMT_BC1_UNORM;
337 case DXGI_FORMAT_BC1_UNORM_SRGB: return WINED3DFMT_BC1_UNORM_SRGB;
338 case DXGI_FORMAT_BC2_TYPELESS: return WINED3DFMT_BC2_TYPELESS;
339 case DXGI_FORMAT_BC2_UNORM: return WINED3DFMT_BC2_UNORM;
340 case DXGI_FORMAT_BC2_UNORM_SRGB: return WINED3DFMT_BC2_UNORM_SRGB;
341 case DXGI_FORMAT_BC3_TYPELESS: return WINED3DFMT_BC3_TYPELESS;
342 case DXGI_FORMAT_BC3_UNORM: return WINED3DFMT_BC3_UNORM;
343 case DXGI_FORMAT_BC3_UNORM_SRGB: return WINED3DFMT_BC3_UNORM_SRGB;
344 case DXGI_FORMAT_BC4_TYPELESS: return WINED3DFMT_BC4_TYPELESS;
345 case DXGI_FORMAT_BC4_UNORM: return WINED3DFMT_BC4_UNORM;
346 case DXGI_FORMAT_BC4_SNORM: return WINED3DFMT_BC4_SNORM;
347 case DXGI_FORMAT_BC5_TYPELESS: return WINED3DFMT_BC5_TYPELESS;
348 case DXGI_FORMAT_BC5_UNORM: return WINED3DFMT_BC5_UNORM;
349 case DXGI_FORMAT_BC5_SNORM: return WINED3DFMT_BC5_SNORM;
350 case DXGI_FORMAT_B5G6R5_UNORM: return WINED3DFMT_B5G6R5_UNORM;
351 case DXGI_FORMAT_B5G5R5A1_UNORM: return WINED3DFMT_B5G5R5A1_UNORM;
352 case DXGI_FORMAT_B8G8R8A8_UNORM: return WINED3DFMT_B8G8R8A8_UNORM;
353 case DXGI_FORMAT_B8G8R8X8_UNORM: return WINED3DFMT_B8G8R8X8_UNORM;
354 case DXGI_FORMAT_B8G8R8A8_TYPELESS: return WINED3DFMT_B8G8R8A8_TYPELESS;
355 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: return WINED3DFMT_B8G8R8A8_UNORM_SRGB;
356 case DXGI_FORMAT_B8G8R8X8_TYPELESS: return WINED3DFMT_B8G8R8X8_TYPELESS;
357 case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: return WINED3DFMT_B8G8R8X8_UNORM_SRGB;
358 case DXGI_FORMAT_BC7_TYPELESS: return WINED3DFMT_BC7_TYPELESS;
359 case DXGI_FORMAT_BC7_UNORM: return WINED3DFMT_BC7_UNORM;
360 case DXGI_FORMAT_BC7_UNORM_SRGB: return WINED3DFMT_BC7_UNORM_SRGB;
361 default:
362 FIXME("Unhandled DXGI_FORMAT %#x.\n", format);
363 return WINED3DFMT_UNKNOWN;
367 void dxgi_sample_desc_from_wined3d(DXGI_SAMPLE_DESC *desc,
368 enum wined3d_multisample_type wined3d_type, unsigned int wined3d_quality)
370 desc->Count = wined3d_type == WINED3D_MULTISAMPLE_NONE ? 1 : wined3d_type;
371 desc->Quality = wined3d_quality;
374 void wined3d_sample_desc_from_dxgi(enum wined3d_multisample_type *wined3d_type,
375 unsigned int *wined3d_quality, const DXGI_SAMPLE_DESC *dxgi_desc)
377 if (dxgi_desc->Count > 1)
379 *wined3d_type = dxgi_desc->Count;
380 *wined3d_quality = dxgi_desc->Quality;
382 else
384 *wined3d_type = WINED3D_MULTISAMPLE_NONE;
385 *wined3d_quality = 0;
389 HRESULT dxgi_get_private_data(struct wined3d_private_store *store,
390 REFGUID guid, UINT *data_size, void *data)
392 const struct wined3d_private_data *stored_data;
393 DWORD size_in;
394 HRESULT hr;
396 if (!data_size)
397 return E_INVALIDARG;
399 wined3d_mutex_lock();
400 if (!(stored_data = wined3d_private_store_get_private_data(store, guid)))
402 hr = DXGI_ERROR_NOT_FOUND;
403 *data_size = 0;
404 goto done;
407 size_in = *data_size;
408 *data_size = stored_data->size;
409 if (!data)
411 hr = S_OK;
412 goto done;
414 if (size_in < stored_data->size)
416 hr = DXGI_ERROR_MORE_DATA;
417 goto done;
420 if (stored_data->flags & WINED3DSPD_IUNKNOWN)
421 IUnknown_AddRef(stored_data->content.object);
422 memcpy(data, stored_data->content.data, stored_data->size);
423 hr = S_OK;
425 done:
426 wined3d_mutex_unlock();
428 return hr;
431 HRESULT dxgi_set_private_data(struct wined3d_private_store *store,
432 REFGUID guid, UINT data_size, const void *data)
434 struct wined3d_private_data *entry;
435 HRESULT hr;
437 if (!data)
439 wined3d_mutex_lock();
440 if (!(entry = wined3d_private_store_get_private_data(store, guid)))
442 wined3d_mutex_unlock();
443 return S_FALSE;
446 wined3d_private_store_free_private_data(store, entry);
447 wined3d_mutex_unlock();
449 return S_OK;
452 wined3d_mutex_lock();
453 hr = wined3d_private_store_set_private_data(store, guid, data, data_size, 0);
454 wined3d_mutex_unlock();
456 return hr;
459 HRESULT dxgi_set_private_data_interface(struct wined3d_private_store *store,
460 REFGUID guid, const IUnknown *object)
462 HRESULT hr;
464 if (!object)
465 return dxgi_set_private_data(store, guid, sizeof(object), &object);
467 wined3d_mutex_lock();
468 hr = wined3d_private_store_set_private_data(store,
469 guid, object, sizeof(object), WINED3DSPD_IUNKNOWN);
470 wined3d_mutex_unlock();
472 return hr;
475 D3D_FEATURE_LEVEL dxgi_check_feature_level_support(struct dxgi_factory *factory, struct dxgi_adapter *adapter,
476 const D3D_FEATURE_LEVEL *feature_levels, unsigned int level_count)
478 static const struct
480 D3D_FEATURE_LEVEL feature_level;
481 unsigned int sm;
483 feature_levels_sm[] =
485 {D3D_FEATURE_LEVEL_11_1, 5},
486 {D3D_FEATURE_LEVEL_11_0, 5},
487 {D3D_FEATURE_LEVEL_10_1, 4},
488 {D3D_FEATURE_LEVEL_10_0, 4},
489 {D3D_FEATURE_LEVEL_9_3, 3},
490 {D3D_FEATURE_LEVEL_9_2, 2},
491 {D3D_FEATURE_LEVEL_9_1, 2},
493 D3D_FEATURE_LEVEL selected_feature_level = 0;
494 unsigned int shader_model;
495 unsigned int i, j;
496 WINED3DCAPS caps;
497 HRESULT hr;
499 FIXME("Ignoring adapter type.\n");
501 wined3d_mutex_lock();
502 hr = wined3d_get_device_caps(factory->wined3d, adapter->ordinal, WINED3D_DEVICE_TYPE_HAL, &caps);
503 wined3d_mutex_unlock();
505 if (FAILED(hr))
506 level_count = 0;
508 shader_model = min(caps.VertexShaderVersion, caps.PixelShaderVersion);
509 for (i = 0; i < level_count; ++i)
511 for (j = 0; j < sizeof(feature_levels_sm) / sizeof(feature_levels_sm[0]); ++j)
513 if (feature_levels[i] == feature_levels_sm[j].feature_level)
515 if (shader_model >= feature_levels_sm[j].sm)
517 selected_feature_level = feature_levels[i];
518 TRACE("Choosing supported feature level %s (SM%u).\n",
519 debug_feature_level(selected_feature_level), feature_levels_sm[j].sm);
521 break;
524 if (selected_feature_level)
525 break;
527 if (j == sizeof(feature_levels_sm) / sizeof(feature_levels_sm[0]))
528 FIXME("Unexpected feature level %#x.\n", feature_levels[i]);
529 else
530 TRACE("Feature level %s not supported, trying next fallback if available.\n",
531 debug_feature_level(feature_levels[i]));
533 if (!selected_feature_level)
534 FIXME_(winediag)("None of the requested D3D feature levels is supported on this GPU "
535 "with the current shader backend.\n");
537 return selected_feature_level;