st/nine: Fix multisampling support detection
[mesa.git] / src / gallium / state_trackers / nine / adapter9.c
1 /*
2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22
23 #include "adapter9.h"
24 #include "device9ex.h"
25 #include "nine_helpers.h"
26 #include "nine_defines.h"
27 #include "nine_pipe.h"
28 #include "nine_dump.h"
29 #include "util/u_math.h"
30 #include "util/u_format.h"
31 #include "util/u_dump.h"
32
33 #include "pipe/p_screen.h"
34
35 #define DBG_CHANNEL DBG_ADAPTER
36
37 HRESULT
38 NineAdapter9_ctor( struct NineAdapter9 *This,
39 struct NineUnknownParams *pParams,
40 struct d3dadapter9_context *pCTX )
41 {
42 struct pipe_screen *hal = pCTX->hal;
43 HRESULT hr = NineUnknown_ctor(&This->base, pParams);
44 if (FAILED(hr)) { return hr; }
45
46 DBG("This=%p pParams=%p pCTX=%p\n", This, pParams, pCTX);
47 nine_dump_D3DADAPTER_IDENTIFIER9(DBG_CHANNEL, &pCTX->identifier);
48
49 This->ctx = pCTX;
50 if (!hal->get_param(hal, PIPE_CAP_CLIP_HALFZ)) {
51 ERR("Driver doesn't support d3d9 coordinates\n");
52 return D3DERR_DRIVERINTERNALERROR;
53 }
54 if (This->ctx->ref &&
55 !This->ctx->ref->get_param(This->ctx->ref, PIPE_CAP_CLIP_HALFZ)) {
56 ERR("Warning: Sotware rendering driver doesn't support d3d9 coordinates\n");
57 }
58 /* Old cards had tricks to bypass some restrictions to implement
59 * everything and fit tight the requirements: number of constants,
60 * number of temp registers, special behaviours, etc. Since we don't
61 * have access to all this, we need a bit more than what dx9 required.
62 * For example we have to use more than 32 temp registers to emulate
63 * behaviours, while some dx9 hw don't have more. As for sm2 hardware,
64 * we could support vs2 / ps2 for them but it needs some more care, and
65 * as these are very old, we choose to drop support for them */
66
67 /* checks minimum requirements, most are vs3/ps3 strict requirements */
68 if (!hal->get_param(hal, PIPE_CAP_SM3) ||
69 hal->get_shader_param(hal, PIPE_SHADER_VERTEX,
70 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE) < 256 * sizeof(float[4]) ||
71 hal->get_shader_param(hal, PIPE_SHADER_FRAGMENT,
72 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE) < 244 * sizeof(float[4]) ||
73 hal->get_shader_param(hal, PIPE_SHADER_VERTEX,
74 PIPE_SHADER_CAP_MAX_TEMPS) < 32 ||
75 hal->get_shader_param(hal, PIPE_SHADER_FRAGMENT,
76 PIPE_SHADER_CAP_MAX_TEMPS) < 32 ||
77 hal->get_shader_param(hal, PIPE_SHADER_VERTEX,
78 PIPE_SHADER_CAP_MAX_INPUTS) < 16 ||
79 hal->get_shader_param(hal, PIPE_SHADER_FRAGMENT,
80 PIPE_SHADER_CAP_MAX_INPUTS) < 10) {
81 ERR("Your card is not supported by Gallium Nine. Minimum requirement "
82 "is >= r500, >= nv50, >= i965\n");
83 return D3DERR_DRIVERINTERNALERROR;
84 }
85 /* for r500 */
86 if (hal->get_shader_param(hal, PIPE_SHADER_VERTEX,
87 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE) < 276 * sizeof(float[4]) || /* we put bool and int constants with float constants */
88 hal->get_shader_param(hal, PIPE_SHADER_VERTEX,
89 PIPE_SHADER_CAP_MAX_TEMPS) < 40 || /* we use some more temp registers */
90 hal->get_shader_param(hal, PIPE_SHADER_FRAGMENT,
91 PIPE_SHADER_CAP_MAX_TEMPS) < 40 ||
92 hal->get_shader_param(hal, PIPE_SHADER_FRAGMENT,
93 PIPE_SHADER_CAP_MAX_INPUTS) < 20) /* we don't pack inputs as much as we could */
94 ERR("Your card is at the limit of Gallium Nine requirements. Some games "
95 "may run into issues because requirements are too tight\n");
96 return D3D_OK;
97 }
98
99 void
100 NineAdapter9_dtor( struct NineAdapter9 *This )
101 {
102 struct d3dadapter9_context *ctx = This->ctx;
103
104 DBG("This=%p\n", This);
105
106 NineUnknown_dtor(&This->base);
107
108 /* special case, call backend-specific dtor AFTER destroying this object
109 * completely. */
110 if (ctx) {
111 if (ctx->destroy) { ctx->destroy(ctx); }
112 }
113 }
114
115 static HRESULT
116 NineAdapter9_GetScreen( struct NineAdapter9 *This,
117 D3DDEVTYPE DevType,
118 struct pipe_screen **ppScreen )
119 {
120 const char *force_sw = getenv("D3D_ALWAYS_SOFTWARE");
121 switch (DevType) {
122 case D3DDEVTYPE_HAL:
123 if (force_sw && !strcmp(force_sw, "1") && This->ctx->ref) {
124 *ppScreen = This->ctx->ref;
125 break;
126 }
127 *ppScreen = This->ctx->hal;
128 break;
129
130 case D3DDEVTYPE_REF:
131 case D3DDEVTYPE_NULLREF:
132 case D3DDEVTYPE_SW:
133 if (force_sw && !strcmp(force_sw, "0")) {
134 *ppScreen = This->ctx->hal;
135 break;
136 }
137 *ppScreen = This->ctx->ref;
138 break;
139
140 default:
141 user_assert(!"Invalid device type", D3DERR_INVALIDCALL);
142 }
143
144 if (!*ppScreen) { return D3DERR_NOTAVAILABLE; }
145
146 return D3D_OK;
147 }
148
149 HRESULT WINAPI
150 NineAdapter9_GetAdapterIdentifier( struct NineAdapter9 *This,
151 DWORD Flags,
152 D3DADAPTER_IDENTIFIER9 *pIdentifier )
153 {
154 DBG("This=%p Flags=%x pIdentifier=%p\n", This, Flags, pIdentifier);
155
156 /* regarding flags, MSDN has this to say:
157 * Flags sets the WHQLLevel member of D3DADAPTER_IDENTIFIER9. Flags can be
158 * set to either 0 or D3DENUM_WHQL_LEVEL. If D3DENUM_WHQL_LEVEL is
159 * specified, this call can connect to the Internet to download new
160 * Microsoft Windows Hardware Quality Labs (WHQL) certificates.
161 * so let's just ignore it. */
162 *pIdentifier = This->ctx->identifier;
163 return D3D_OK;
164 }
165
166 static INLINE boolean
167 backbuffer_format( D3DFORMAT dfmt,
168 D3DFORMAT bfmt,
169 boolean win )
170 {
171 if (dfmt == D3DFMT_A2R10G10B10 && win) { return FALSE; }
172
173 if ((dfmt == D3DFMT_A2R10G10B10 && bfmt == dfmt) ||
174 (dfmt == D3DFMT_X8R8G8B8 && (bfmt == dfmt ||
175 bfmt == D3DFMT_A8R8G8B8)) ||
176 (dfmt == D3DFMT_X1R5G5B5 && (bfmt == dfmt ||
177 bfmt == D3DFMT_A1R5G5B5)) ||
178 (dfmt == D3DFMT_R5G6B5 && bfmt == dfmt)) {
179 return TRUE;
180 }
181
182 return FALSE;
183 }
184
185 HRESULT WINAPI
186 NineAdapter9_CheckDeviceType( struct NineAdapter9 *This,
187 D3DDEVTYPE DevType,
188 D3DFORMAT AdapterFormat,
189 D3DFORMAT BackBufferFormat,
190 BOOL bWindowed )
191 {
192 struct pipe_screen *screen;
193 enum pipe_format dfmt, bfmt;
194 HRESULT hr;
195
196 DBG("This=%p DevType=%s AdapterFormat=%s BackBufferFormat=%s "
197 "bWindowed=%i\n", This, nine_D3DDEVTYPE_to_str(DevType),
198 d3dformat_to_string(AdapterFormat),
199 d3dformat_to_string(BackBufferFormat), bWindowed);
200
201 user_assert(backbuffer_format(AdapterFormat, BackBufferFormat, bWindowed),
202 D3DERR_NOTAVAILABLE);
203
204 hr = NineAdapter9_GetScreen(This, DevType, &screen);
205 if (FAILED(hr)) { return hr; }
206
207 dfmt = d3d9_to_pipe_format_checked(screen, AdapterFormat, PIPE_TEXTURE_2D,
208 1,
209 PIPE_BIND_DISPLAY_TARGET |
210 PIPE_BIND_SHARED, FALSE);
211 bfmt = d3d9_to_pipe_format_checked(screen, BackBufferFormat, PIPE_TEXTURE_2D,
212 1,
213 PIPE_BIND_DISPLAY_TARGET |
214 PIPE_BIND_SHARED, FALSE);
215 if (dfmt == PIPE_FORMAT_NONE || bfmt == PIPE_FORMAT_NONE) {
216 DBG("Unsupported Adapter/BackBufferFormat.\n");
217 return D3DERR_NOTAVAILABLE;
218 }
219
220 return D3D_OK;
221 }
222
223 static INLINE boolean
224 display_format( D3DFORMAT fmt,
225 boolean win )
226 {
227 /* http://msdn.microsoft.com/en-us/library/bb172558(v=VS.85).aspx#BackBuffer_or_Display_Formats */
228 static const D3DFORMAT allowed[] = {
229 D3DFMT_A2R10G10B10,
230 D3DFMT_X8R8G8B8,
231 D3DFMT_X1R5G5B5,
232 D3DFMT_R5G6B5,
233 };
234 unsigned i;
235
236 if (fmt == D3DFMT_A2R10G10B10 && win) { return FALSE; }
237
238 for (i = 0; i < sizeof(allowed)/sizeof(D3DFORMAT); i++) {
239 if (fmt == allowed[i]) { return TRUE; }
240 }
241 return FALSE;
242 }
243
244 HRESULT WINAPI
245 NineAdapter9_CheckDeviceFormat( struct NineAdapter9 *This,
246 D3DDEVTYPE DeviceType,
247 D3DFORMAT AdapterFormat,
248 DWORD Usage,
249 D3DRESOURCETYPE RType,
250 D3DFORMAT CheckFormat )
251 {
252 struct pipe_screen *screen;
253 HRESULT hr;
254 enum pipe_format pf;
255 enum pipe_texture_target target;
256 unsigned bind = 0;
257 boolean srgb;
258
259 /* Check adapter format. */
260
261 DBG("This=%p DeviceType=%s AdapterFormat=%s\n", This,
262 nine_D3DDEVTYPE_to_str(DeviceType), d3dformat_to_string(AdapterFormat));
263 DBG("Usage=%x RType=%u CheckFormat=%s\n", Usage, RType,
264 d3dformat_to_string(CheckFormat));
265
266 user_assert(display_format(AdapterFormat, FALSE), D3DERR_INVALIDCALL);
267
268 hr = NineAdapter9_GetScreen(This, DeviceType, &screen);
269 if (FAILED(hr))
270 return hr;
271 pf = d3d9_to_pipe_format_checked(screen, AdapterFormat, PIPE_TEXTURE_2D, 0,
272 PIPE_BIND_DISPLAY_TARGET |
273 PIPE_BIND_SHARED, FALSE);
274 if (pf == PIPE_FORMAT_NONE) {
275 DBG("AdapterFormat %s not available.\n",
276 d3dformat_to_string(AdapterFormat));
277 return D3DERR_NOTAVAILABLE;
278 }
279
280 /* Check actual format. */
281
282 switch (RType) {
283 case D3DRTYPE_SURFACE: target = PIPE_TEXTURE_2D; break;
284 case D3DRTYPE_TEXTURE: target = PIPE_TEXTURE_2D; break;
285 case D3DRTYPE_CUBETEXTURE: target = PIPE_TEXTURE_CUBE; break;
286 case D3DRTYPE_VOLUME: target = PIPE_TEXTURE_3D; break;
287 case D3DRTYPE_VOLUMETEXTURE: target = PIPE_TEXTURE_3D; break;
288 case D3DRTYPE_VERTEXBUFFER: target = PIPE_BUFFER; break;
289 case D3DRTYPE_INDEXBUFFER: target = PIPE_BUFFER; break;
290 default:
291 user_assert(0, D3DERR_INVALIDCALL);
292 }
293
294 bind = 0;
295 if (Usage & D3DUSAGE_RENDERTARGET) bind |= PIPE_BIND_RENDER_TARGET;
296 if (Usage & D3DUSAGE_DEPTHSTENCIL) bind |= PIPE_BIND_DEPTH_STENCIL;
297
298 /* API hack because setting RT[0] to NULL is forbidden */
299 if (CheckFormat == D3DFMT_NULL && bind == PIPE_BIND_RENDER_TARGET &&
300 (RType == D3DRTYPE_SURFACE ||
301 RType == D3DRTYPE_TEXTURE))
302 return D3D_OK;
303
304 /* RESZ hack */
305 if (CheckFormat == D3DFMT_RESZ && bind == PIPE_BIND_RENDER_TARGET &&
306 RType == D3DRTYPE_SURFACE)
307 return screen->get_param(screen, PIPE_CAP_MULTISAMPLE_Z_RESOLVE) ?
308 D3D_OK : D3DERR_NOTAVAILABLE;
309
310 /* ATOC hack */
311 if (CheckFormat == D3DFMT_ATOC && RType == D3DRTYPE_SURFACE)
312 return D3D_OK;
313
314 if (Usage & D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING)
315 bind |= PIPE_BIND_BLENDABLE;
316
317 if (Usage & D3DUSAGE_DMAP) {
318 DBG("D3DUSAGE_DMAP not available\n");
319 return D3DERR_NOTAVAILABLE; /* TODO: displacement mapping */
320 }
321
322 switch (RType) {
323 case D3DRTYPE_TEXTURE: bind |= PIPE_BIND_SAMPLER_VIEW; break;
324 case D3DRTYPE_CUBETEXTURE: bind |= PIPE_BIND_SAMPLER_VIEW; break;
325 case D3DRTYPE_VOLUMETEXTURE: bind |= PIPE_BIND_SAMPLER_VIEW; break;
326 case D3DRTYPE_VERTEXBUFFER: bind |= PIPE_BIND_VERTEX_BUFFER; break;
327 case D3DRTYPE_INDEXBUFFER: bind |= PIPE_BIND_INDEX_BUFFER; break;
328 default:
329 break;
330 }
331
332
333 srgb = (Usage & (D3DUSAGE_QUERY_SRGBREAD | D3DUSAGE_QUERY_SRGBWRITE)) != 0;
334 pf = d3d9_to_pipe_format_checked(screen, CheckFormat, target, 0, bind, srgb);
335 if (pf == PIPE_FORMAT_NONE) {
336 DBG("NOT AVAILABLE\n");
337 return D3DERR_NOTAVAILABLE;
338 }
339
340 /* we support ATI1 and ATI2 hack only for 2D textures */
341 if (RType != D3DRTYPE_TEXTURE && (CheckFormat == D3DFMT_ATI1 || CheckFormat == D3DFMT_ATI2))
342 return D3DERR_NOTAVAILABLE;
343 /* if (Usage & D3DUSAGE_NONSECURE) { don't know the implications of this } */
344 /* if (Usage & D3DUSAGE_SOFTWAREPROCESSING) { we can always support this } */
345
346 if ((Usage & D3DUSAGE_AUTOGENMIPMAP) && !(bind & PIPE_BIND_SAMPLER_VIEW))
347 return D3DOK_NOAUTOGEN;
348 return D3D_OK;
349 }
350
351 HRESULT WINAPI
352 NineAdapter9_CheckDeviceMultiSampleType( struct NineAdapter9 *This,
353 D3DDEVTYPE DeviceType,
354 D3DFORMAT SurfaceFormat,
355 BOOL Windowed,
356 D3DMULTISAMPLE_TYPE MultiSampleType,
357 DWORD *pQualityLevels )
358 {
359 struct pipe_screen *screen;
360 HRESULT hr;
361 enum pipe_format pf;
362 unsigned bind;
363
364 DBG("This=%p DeviceType=%s SurfaceFormat=%s Windowed=%i MultiSampleType=%u "
365 "pQualityLevels=%p\n", This, nine_D3DDEVTYPE_to_str(DeviceType),
366 d3dformat_to_string(SurfaceFormat), Windowed, MultiSampleType,
367 pQualityLevels);
368
369 hr = NineAdapter9_GetScreen(This, DeviceType, &screen);
370 if (FAILED(hr))
371 return hr;
372
373 if (depth_stencil_format(SurfaceFormat))
374 bind = d3d9_get_pipe_depth_format_bindings(SurfaceFormat);
375 else /* render-target */
376 bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_TRANSFER_READ |
377 PIPE_BIND_TRANSFER_WRITE | PIPE_BIND_RENDER_TARGET;
378
379 pf = d3d9_to_pipe_format_checked(screen, SurfaceFormat, PIPE_TEXTURE_2D,
380 MultiSampleType, bind, FALSE);
381
382 if (pf == PIPE_FORMAT_NONE) {
383 DBG("%s with %u samples not available.\n",
384 d3dformat_to_string(SurfaceFormat), MultiSampleType);
385 return D3DERR_NOTAVAILABLE;
386 }
387
388 if (pQualityLevels)
389 *pQualityLevels = 1; /* gallium doesn't have quality levels */
390
391 return D3D_OK;
392 }
393
394 HRESULT WINAPI
395 NineAdapter9_CheckDepthStencilMatch( struct NineAdapter9 *This,
396 D3DDEVTYPE DeviceType,
397 D3DFORMAT AdapterFormat,
398 D3DFORMAT RenderTargetFormat,
399 D3DFORMAT DepthStencilFormat )
400 {
401 struct pipe_screen *screen;
402 enum pipe_format dfmt, bfmt, zsfmt;
403 HRESULT hr;
404
405 DBG("This=%p DeviceType=%s AdapterFormat=%s "
406 "RenderTargetFormat=%s DepthStencilFormat=%s\n", This,
407 nine_D3DDEVTYPE_to_str(DeviceType), d3dformat_to_string(AdapterFormat),
408 d3dformat_to_string(RenderTargetFormat),
409 d3dformat_to_string(DepthStencilFormat));
410
411 user_assert(display_format(AdapterFormat, FALSE), D3DERR_NOTAVAILABLE);
412 user_assert(depth_stencil_format(DepthStencilFormat), D3DERR_NOTAVAILABLE);
413
414 hr = NineAdapter9_GetScreen(This, DeviceType, &screen);
415 if (FAILED(hr)) { return hr; }
416
417 dfmt = d3d9_to_pipe_format_checked(screen, AdapterFormat, PIPE_TEXTURE_2D, 0,
418 PIPE_BIND_DISPLAY_TARGET |
419 PIPE_BIND_SHARED, FALSE);
420 bfmt = d3d9_to_pipe_format_checked(screen, RenderTargetFormat,
421 PIPE_TEXTURE_2D, 0,
422 PIPE_BIND_RENDER_TARGET, FALSE);
423 if (RenderTargetFormat == D3DFMT_NULL)
424 bfmt = dfmt;
425 zsfmt = d3d9_to_pipe_format_checked(screen, DepthStencilFormat,
426 PIPE_TEXTURE_2D, 0,
427 d3d9_get_pipe_depth_format_bindings(DepthStencilFormat),
428 FALSE);
429 if (dfmt == PIPE_FORMAT_NONE ||
430 bfmt == PIPE_FORMAT_NONE ||
431 zsfmt == PIPE_FORMAT_NONE) {
432 return D3DERR_NOTAVAILABLE;
433 }
434
435 return D3D_OK;
436 }
437
438 HRESULT WINAPI
439 NineAdapter9_CheckDeviceFormatConversion( struct NineAdapter9 *This,
440 D3DDEVTYPE DeviceType,
441 D3DFORMAT SourceFormat,
442 D3DFORMAT TargetFormat )
443 {
444 /* MSDN says this tests whether a certain backbuffer format can be used in
445 * conjunction with a certain front buffer format. It's a little confusing
446 * but some one wiser might be able to figure this one out. XXX */
447 struct pipe_screen *screen;
448 enum pipe_format dfmt, bfmt;
449 HRESULT hr;
450
451 DBG("This=%p DeviceType=%s SourceFormat=%s TargetFormat=%s\n", This,
452 nine_D3DDEVTYPE_to_str(DeviceType),
453 d3dformat_to_string(SourceFormat), d3dformat_to_string(TargetFormat));
454
455 user_assert(backbuffer_format(TargetFormat, SourceFormat, FALSE),
456 D3DERR_NOTAVAILABLE);
457
458 hr = NineAdapter9_GetScreen(This, DeviceType, &screen);
459 if (FAILED(hr)) { return hr; }
460
461 dfmt = d3d9_to_pipe_format_checked(screen, TargetFormat, PIPE_TEXTURE_2D, 1,
462 PIPE_BIND_DISPLAY_TARGET |
463 PIPE_BIND_SHARED, FALSE);
464 bfmt = d3d9_to_pipe_format_checked(screen, SourceFormat, PIPE_TEXTURE_2D, 1,
465 PIPE_BIND_DISPLAY_TARGET |
466 PIPE_BIND_SHARED, FALSE);
467
468 if (dfmt == PIPE_FORMAT_NONE || bfmt == PIPE_FORMAT_NONE) {
469 DBG("%s to %s not supported.\n",
470 d3dformat_to_string(SourceFormat),
471 d3dformat_to_string(TargetFormat));
472 return D3DERR_NOTAVAILABLE;
473 }
474
475 return D3D_OK;
476 }
477
478 HRESULT WINAPI
479 NineAdapter9_GetDeviceCaps( struct NineAdapter9 *This,
480 D3DDEVTYPE DeviceType,
481 D3DCAPS9 *pCaps )
482 {
483 struct pipe_screen *screen;
484 HRESULT hr;
485
486 DBG("This=%p DeviceType=%s pCaps=%p\n", This,
487 nine_D3DDEVTYPE_to_str(DeviceType), pCaps);
488
489 user_assert(pCaps, D3DERR_INVALIDCALL);
490
491 hr = NineAdapter9_GetScreen(This, DeviceType, &screen);
492 if (FAILED(hr)) {
493 DBG("Failed to get pipe_screen.\n");
494 return hr;
495 }
496
497 #define D3DPIPECAP(pcap, d3dcap) \
498 (screen->get_param(screen, PIPE_CAP_##pcap) ? (d3dcap) : 0)
499
500 #define D3DNPIPECAP(pcap, d3dcap) \
501 (screen->get_param(screen, PIPE_CAP_##pcap) ? 0 : (d3dcap))
502
503 pCaps->DeviceType = DeviceType;
504
505 pCaps->AdapterOrdinal = 0;
506
507 pCaps->Caps = 0;
508
509 pCaps->Caps2 = D3DCAPS2_CANMANAGERESOURCE |
510 /* D3DCAPS2_CANSHARERESOURCE | */
511 /* D3DCAPS2_CANCALIBRATEGAMMA | */
512 D3DCAPS2_DYNAMICTEXTURES |
513 D3DCAPS2_FULLSCREENGAMMA |
514 D3DCAPS2_CANAUTOGENMIPMAP;
515
516 /* Note: D3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD just means the
517 * backbuffer can be ARGB (instead of only XRGB) when we are fullscreen
518 * and in discard mode. */
519 pCaps->Caps3 = D3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD |
520 D3DCAPS3_COPY_TO_VIDMEM |
521 D3DCAPS3_COPY_TO_SYSTEMMEM |
522 D3DCAPS3_LINEAR_TO_SRGB_PRESENTATION;
523
524 pCaps->PresentationIntervals = D3DPRESENT_INTERVAL_DEFAULT |
525 D3DPRESENT_INTERVAL_ONE |
526 D3DPRESENT_INTERVAL_TWO |
527 D3DPRESENT_INTERVAL_THREE |
528 D3DPRESENT_INTERVAL_FOUR |
529 D3DPRESENT_INTERVAL_IMMEDIATE;
530 pCaps->CursorCaps = D3DCURSORCAPS_COLOR | D3DCURSORCAPS_LOWRES;
531
532 pCaps->DevCaps = D3DDEVCAPS_CANBLTSYSTONONLOCAL |
533 D3DDEVCAPS_CANRENDERAFTERFLIP |
534 D3DDEVCAPS_DRAWPRIMITIVES2 |
535 D3DDEVCAPS_DRAWPRIMITIVES2EX |
536 D3DDEVCAPS_DRAWPRIMTLVERTEX |
537 D3DDEVCAPS_EXECUTESYSTEMMEMORY |
538 D3DDEVCAPS_EXECUTEVIDEOMEMORY |
539 D3DDEVCAPS_HWRASTERIZATION |
540 D3DDEVCAPS_HWTRANSFORMANDLIGHT |
541 /*D3DDEVCAPS_NPATCHES |*/
542 D3DDEVCAPS_PUREDEVICE |
543 /*D3DDEVCAPS_QUINTICRTPATCHES |*/
544 /*D3DDEVCAPS_RTPATCHES |*/
545 /*D3DDEVCAPS_RTPATCHHANDLEZERO |*/
546 /*D3DDEVCAPS_SEPARATETEXTUREMEMORIES |*/
547 /*D3DDEVCAPS_TEXTURENONLOCALVIDMEM |*/
548 D3DDEVCAPS_TEXTURESYSTEMMEMORY |
549 D3DDEVCAPS_TEXTUREVIDEOMEMORY |
550 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY |
551 D3DDEVCAPS_TLVERTEXVIDEOMEMORY;
552
553 pCaps->PrimitiveMiscCaps = D3DPMISCCAPS_MASKZ |
554 D3DPMISCCAPS_CULLNONE | /* XXX */
555 D3DPMISCCAPS_CULLCW |
556 D3DPMISCCAPS_CULLCCW |
557 D3DPMISCCAPS_COLORWRITEENABLE |
558 D3DPMISCCAPS_CLIPPLANESCALEDPOINTS |
559 /*D3DPMISCCAPS_CLIPTLVERTS |*/
560 D3DPMISCCAPS_TSSARGTEMP |
561 D3DPMISCCAPS_BLENDOP |
562 D3DPIPECAP(INDEP_BLEND_ENABLE, D3DPMISCCAPS_INDEPENDENTWRITEMASKS) |
563 /*D3DPMISCCAPS_PERSTAGECONSTANT |*/
564 /*D3DPMISCCAPS_POSTBLENDSRGBCONVERT |*/ /* TODO */
565 D3DPMISCCAPS_FOGANDSPECULARALPHA |
566 D3DPIPECAP(BLEND_EQUATION_SEPARATE, D3DPMISCCAPS_SEPARATEALPHABLEND) |
567 D3DPIPECAP(MIXED_COLORBUFFER_FORMATS, D3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS) |
568 D3DPMISCCAPS_MRTPOSTPIXELSHADERBLENDING |
569 /*D3DPMISCCAPS_FOGVERTEXCLAMPED*/0;
570 if (!screen->get_param(screen, PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION))
571 pCaps->PrimitiveMiscCaps |= D3DPMISCCAPS_CLIPTLVERTS;
572
573 pCaps->RasterCaps =
574 D3DPIPECAP(ANISOTROPIC_FILTER, D3DPRASTERCAPS_ANISOTROPY) |
575 /*D3DPRASTERCAPS_COLORPERSPECTIVE |*/
576 D3DPRASTERCAPS_DITHER |
577 D3DPRASTERCAPS_DEPTHBIAS |
578 /*D3DPRASTERCAPS_FOGRANGE |*/
579 /*D3DPRASTERCAPS_FOGTABLE |*/
580 /*D3DPRASTERCAPS_FOGVERTEX |*/
581 D3DPRASTERCAPS_MIPMAPLODBIAS |
582 D3DPRASTERCAPS_MULTISAMPLE_TOGGLE |
583 D3DPRASTERCAPS_SCISSORTEST |
584 D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS |
585 /*D3DPRASTERCAPS_WBUFFER |*/
586 /*D3DPRASTERCAPS_WFOG |*/
587 /*D3DPRASTERCAPS_ZBUFFERLESSHSR |*/
588 /*D3DPRASTERCAPS_ZFOG |*/
589 D3DPRASTERCAPS_ZTEST;
590
591 pCaps->ZCmpCaps = D3DPCMPCAPS_NEVER |
592 D3DPCMPCAPS_LESS |
593 D3DPCMPCAPS_EQUAL |
594 D3DPCMPCAPS_LESSEQUAL |
595 D3DPCMPCAPS_GREATER |
596 D3DPCMPCAPS_NOTEQUAL |
597 D3DPCMPCAPS_GREATEREQUAL |
598 D3DPCMPCAPS_ALWAYS;
599
600 pCaps->SrcBlendCaps = D3DPBLENDCAPS_ZERO |
601 D3DPBLENDCAPS_ONE |
602 D3DPBLENDCAPS_SRCCOLOR |
603 D3DPBLENDCAPS_INVSRCCOLOR |
604 D3DPBLENDCAPS_SRCALPHA |
605 D3DPBLENDCAPS_INVSRCALPHA |
606 D3DPBLENDCAPS_DESTALPHA |
607 D3DPBLENDCAPS_INVDESTALPHA |
608 D3DPBLENDCAPS_DESTCOLOR |
609 D3DPBLENDCAPS_INVDESTCOLOR |
610 D3DPBLENDCAPS_SRCALPHASAT |
611 D3DPBLENDCAPS_BOTHSRCALPHA |
612 D3DPBLENDCAPS_BOTHINVSRCALPHA |
613 D3DPBLENDCAPS_BLENDFACTOR |
614 D3DPIPECAP(MAX_DUAL_SOURCE_RENDER_TARGETS,
615 D3DPBLENDCAPS_INVSRCCOLOR2 |
616 D3DPBLENDCAPS_SRCCOLOR2);
617
618 pCaps->DestBlendCaps = pCaps->SrcBlendCaps;
619
620 pCaps->AlphaCmpCaps = D3DPCMPCAPS_LESS |
621 D3DPCMPCAPS_EQUAL |
622 D3DPCMPCAPS_LESSEQUAL |
623 D3DPCMPCAPS_GREATER |
624 D3DPCMPCAPS_NOTEQUAL |
625 D3DPCMPCAPS_GREATEREQUAL |
626 D3DPCMPCAPS_ALWAYS;
627
628 /* FLAT caps not legal for D3D9. */
629 pCaps->ShadeCaps = D3DPSHADECAPS_COLORGOURAUDRGB |
630 D3DPSHADECAPS_SPECULARGOURAUDRGB |
631 D3DPSHADECAPS_ALPHAGOURAUDBLEND |
632 D3DPSHADECAPS_FOGGOURAUD;
633
634 pCaps->TextureCaps =
635 D3DPTEXTURECAPS_ALPHA |
636 D3DPTEXTURECAPS_ALPHAPALETTE |
637 D3DPTEXTURECAPS_PERSPECTIVE |
638 D3DPTEXTURECAPS_PROJECTED |
639 /*D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE |*/
640 D3DPTEXTURECAPS_CUBEMAP |
641 D3DPTEXTURECAPS_VOLUMEMAP |
642 D3DNPIPECAP(NPOT_TEXTURES, D3DPTEXTURECAPS_POW2) |
643 D3DNPIPECAP(NPOT_TEXTURES, D3DPTEXTURECAPS_NONPOW2CONDITIONAL) |
644 D3DNPIPECAP(NPOT_TEXTURES, D3DPTEXTURECAPS_CUBEMAP_POW2) |
645 D3DNPIPECAP(NPOT_TEXTURES, D3DPTEXTURECAPS_VOLUMEMAP_POW2) |
646 D3DPIPECAP(MAX_TEXTURE_2D_LEVELS, D3DPTEXTURECAPS_MIPMAP) |
647 D3DPIPECAP(MAX_TEXTURE_3D_LEVELS, D3DPTEXTURECAPS_MIPVOLUMEMAP) |
648 D3DPIPECAP(MAX_TEXTURE_CUBE_LEVELS, D3DPTEXTURECAPS_MIPCUBEMAP);
649
650 pCaps->TextureFilterCaps =
651 D3DPTFILTERCAPS_MINFPOINT |
652 D3DPTFILTERCAPS_MINFLINEAR |
653 D3DPIPECAP(ANISOTROPIC_FILTER, D3DPTFILTERCAPS_MINFANISOTROPIC) |
654 /*D3DPTFILTERCAPS_MINFPYRAMIDALQUAD |*/
655 /*D3DPTFILTERCAPS_MINFGAUSSIANQUAD |*/
656 D3DPTFILTERCAPS_MIPFPOINT |
657 D3DPTFILTERCAPS_MIPFLINEAR |
658 D3DPTFILTERCAPS_MAGFPOINT |
659 D3DPTFILTERCAPS_MAGFLINEAR |
660 D3DPIPECAP(ANISOTROPIC_FILTER, D3DPTFILTERCAPS_MAGFANISOTROPIC) |
661 /*D3DPTFILTERCAPS_MAGFPYRAMIDALQUAD |*/
662 /*D3DPTFILTERCAPS_MAGFGAUSSIANQUAD*/0;
663
664 pCaps->CubeTextureFilterCaps = pCaps->TextureFilterCaps;
665 pCaps->VolumeTextureFilterCaps = pCaps->TextureFilterCaps;
666
667 pCaps->TextureAddressCaps =
668 D3DPTADDRESSCAPS_BORDER |
669 D3DPTADDRESSCAPS_INDEPENDENTUV |
670 D3DPTADDRESSCAPS_WRAP |
671 D3DPTADDRESSCAPS_MIRROR |
672 D3DPTADDRESSCAPS_CLAMP |
673 D3DPIPECAP(TEXTURE_MIRROR_CLAMP, D3DPTADDRESSCAPS_MIRRORONCE);
674
675 pCaps->VolumeTextureAddressCaps = pCaps->TextureAddressCaps;
676
677 pCaps->LineCaps =
678 D3DLINECAPS_ALPHACMP |
679 D3DLINECAPS_BLEND |
680 D3DLINECAPS_TEXTURE |
681 D3DLINECAPS_ZTEST |
682 D3DLINECAPS_FOG;
683 if (screen->get_paramf(screen, PIPE_CAPF_MAX_LINE_WIDTH_AA) > 0.0) {
684 pCaps->LineCaps |= D3DLINECAPS_ANTIALIAS;
685 }
686
687 pCaps->MaxTextureWidth =
688 1 << (screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1);
689 pCaps->MaxTextureHeight = pCaps->MaxTextureWidth;
690 pCaps->MaxVolumeExtent =
691 1 << (screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_3D_LEVELS) - 1);
692 /* XXX values from wine */
693 pCaps->MaxTextureRepeat = 32768;
694 pCaps->MaxTextureAspectRatio = pCaps->MaxTextureWidth;
695
696 pCaps->MaxAnisotropy =
697 (DWORD)screen->get_paramf(screen, PIPE_CAPF_MAX_TEXTURE_ANISOTROPY);
698
699 pCaps->MaxVertexW = 1.0f; /* XXX */
700 pCaps->GuardBandLeft = screen->get_paramf(screen,
701 PIPE_CAPF_GUARD_BAND_LEFT);
702 pCaps->GuardBandTop = screen->get_paramf(screen,
703 PIPE_CAPF_GUARD_BAND_TOP);
704 pCaps->GuardBandRight = screen->get_paramf(screen,
705 PIPE_CAPF_GUARD_BAND_RIGHT);
706 pCaps->GuardBandBottom = screen->get_paramf(screen,
707 PIPE_CAPF_GUARD_BAND_BOTTOM);
708 pCaps->ExtentsAdjust = 0.0f;
709
710 pCaps->StencilCaps =
711 D3DSTENCILCAPS_KEEP |
712 D3DSTENCILCAPS_ZERO |
713 D3DSTENCILCAPS_REPLACE |
714 D3DSTENCILCAPS_INCRSAT |
715 D3DSTENCILCAPS_DECRSAT |
716 D3DSTENCILCAPS_INVERT |
717 D3DSTENCILCAPS_INCR |
718 D3DSTENCILCAPS_DECR |
719 D3DPIPECAP(TWO_SIDED_STENCIL, D3DSTENCILCAPS_TWOSIDED);
720
721 pCaps->FVFCaps =
722 8 | /* 8 textures max */
723 /*D3DFVFCAPS_DONOTSTRIPELEMENTS |*/
724 D3DFVFCAPS_PSIZE;
725
726 /* XXX: Some of these are probably not in SM2.0 so cap them when I figure
727 * them out. For now leave them all enabled. */
728 pCaps->TextureOpCaps = D3DTEXOPCAPS_DISABLE |
729 D3DTEXOPCAPS_SELECTARG1 |
730 D3DTEXOPCAPS_SELECTARG2 |
731 D3DTEXOPCAPS_MODULATE |
732 D3DTEXOPCAPS_MODULATE2X |
733 D3DTEXOPCAPS_MODULATE4X |
734 D3DTEXOPCAPS_ADD |
735 D3DTEXOPCAPS_ADDSIGNED |
736 D3DTEXOPCAPS_ADDSIGNED2X |
737 D3DTEXOPCAPS_SUBTRACT |
738 D3DTEXOPCAPS_ADDSMOOTH |
739 D3DTEXOPCAPS_BLENDDIFFUSEALPHA |
740 D3DTEXOPCAPS_BLENDTEXTUREALPHA |
741 D3DTEXOPCAPS_BLENDFACTORALPHA |
742 D3DTEXOPCAPS_BLENDTEXTUREALPHAPM |
743 D3DTEXOPCAPS_BLENDCURRENTALPHA |
744 D3DTEXOPCAPS_PREMODULATE |
745 D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR |
746 D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA |
747 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR |
748 D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA |
749 D3DTEXOPCAPS_BUMPENVMAP |
750 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE |
751 D3DTEXOPCAPS_DOTPRODUCT3 |
752 D3DTEXOPCAPS_MULTIPLYADD |
753 D3DTEXOPCAPS_LERP;
754
755 pCaps->MaxTextureBlendStages = 8; /* XXX wine */
756 (DWORD)screen->get_param(screen, PIPE_CAP_BLEND_EQUATION_SEPARATE);
757 pCaps->MaxSimultaneousTextures = screen->get_shader_param(screen,
758 PIPE_SHADER_FRAGMENT, PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS);
759 if (pCaps->MaxSimultaneousTextures > NINE_MAX_SAMPLERS_PS)
760 pCaps->MaxSimultaneousTextures = NINE_MAX_SAMPLERS_PS;
761
762 pCaps->VertexProcessingCaps = D3DVTXPCAPS_TEXGEN |
763 /*D3DVTXPCAPS_TEXGEN_SPHEREMAP |*/
764 D3DVTXPCAPS_MATERIALSOURCE7 |
765 D3DVTXPCAPS_DIRECTIONALLIGHTS |
766 D3DVTXPCAPS_POSITIONALLIGHTS |
767 D3DVTXPCAPS_LOCALVIEWER |
768 D3DVTXPCAPS_TWEENING |
769 /*D3DVTXPCAPS_NO_TEXGEN_NONLOCALVIEWER*/0;
770
771 pCaps->MaxActiveLights = NINE_MAX_LIGHTS_ACTIVE; /* like GL_LIGHTi */
772 pCaps->MaxUserClipPlanes = PIPE_MAX_CLIP_PLANES;
773 pCaps->MaxVertexBlendMatrices = 4; /* 1 vec4 BLENDWEIGHT/INDICES input */
774 pCaps->MaxVertexBlendMatrixIndex = 7; /* D3DTS_WORLDMATRIX(0..7) */
775
776 pCaps->MaxPointSize = screen->get_paramf(screen, PIPE_CAPF_MAX_POINT_WIDTH);
777
778 pCaps->MaxPrimitiveCount = 0x555555; /* <- wine, really 0xFFFFFFFF; */
779 pCaps->MaxVertexIndex = 0xFFFFFF; /* <- wine, really 0xFFFFFFFF */
780 pCaps->MaxStreams =
781 _min(screen->get_shader_param(screen,
782 PIPE_SHADER_VERTEX, PIPE_SHADER_CAP_MAX_INPUTS),
783 16);
784
785 pCaps->MaxStreamStride = screen->get_param(screen,
786 PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE);
787
788 pCaps->VertexShaderVersion = D3DVS_VERSION(3,0);
789
790 /* VS 2 as well as 3.0 supports a minimum of 256 consts.
791 * Wine and d3d9 drivers for dx1x hw advertise 256. Just as them,
792 * advertise 256. Problem is with hw that can only do 256, because
793 * we need take a few slots for boolean and integer constants. For these
794 * we'll have to fail later if they use complex shaders. */
795 pCaps->MaxVertexShaderConst = NINE_MAX_CONST_F;
796
797 pCaps->PixelShaderVersion = D3DPS_VERSION(3,0);
798 pCaps->PixelShader1xMaxValue = 8.0f; /* XXX: wine */
799
800 pCaps->DevCaps2 = D3DDEVCAPS2_STREAMOFFSET |
801 D3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET |
802 D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES |
803 /*D3DDEVCAPS2_DMAPNPATCH |*/
804 /*D3DDEVCAPS2_ADAPTIVETESSRTPATCH |*/
805 /*D3DDEVCAPS2_ADAPTIVETESSNPATCH |*/
806 /*D3DDEVCAPS2_PRESAMPLEDDMAPNPATCH*/0;
807
808 pCaps->MasterAdapterOrdinal = 0;
809 pCaps->AdapterOrdinalInGroup = 0;
810 pCaps->NumberOfAdaptersInGroup = 1;
811
812 /* Undocumented ? */
813 pCaps->MaxNpatchTessellationLevel = 0.0f;
814 pCaps->Reserved5 = 0;
815
816 /* XXX: use is_format_supported */
817 pCaps->DeclTypes = D3DDTCAPS_UBYTE4 |
818 D3DDTCAPS_UBYTE4N |
819 D3DDTCAPS_SHORT2N |
820 D3DDTCAPS_SHORT4N |
821 D3DDTCAPS_USHORT2N |
822 D3DDTCAPS_USHORT4N |
823 D3DDTCAPS_UDEC3 |
824 D3DDTCAPS_DEC3N |
825 D3DDTCAPS_FLOAT16_2 |
826 D3DDTCAPS_FLOAT16_4;
827
828 pCaps->NumSimultaneousRTs =
829 screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS);
830 if (pCaps->NumSimultaneousRTs > NINE_MAX_SIMULTANEOUS_RENDERTARGETS)
831 pCaps->NumSimultaneousRTs = NINE_MAX_SIMULTANEOUS_RENDERTARGETS;
832
833 pCaps->StretchRectFilterCaps = D3DPTFILTERCAPS_MINFPOINT |
834 D3DPTFILTERCAPS_MINFLINEAR |
835 D3DPTFILTERCAPS_MAGFPOINT |
836 D3DPTFILTERCAPS_MAGFLINEAR;
837
838
839 pCaps->VS20Caps.Caps = D3DVS20CAPS_PREDICATION;
840 pCaps->VS20Caps.DynamicFlowControlDepth = /* XXX is this dynamic ? */
841 screen->get_shader_param(screen, PIPE_SHADER_VERTEX,
842 PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
843 pCaps->VS20Caps.NumTemps =
844 screen->get_shader_param(screen, PIPE_SHADER_VERTEX,
845 PIPE_SHADER_CAP_MAX_TEMPS);
846 pCaps->VS20Caps.StaticFlowControlDepth = /* XXX is this static ? */
847 screen->get_shader_param(screen, PIPE_SHADER_VERTEX,
848 PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
849
850 /* also check for values < 0, because get_shader_param may return unsigned */
851 if (pCaps->VS20Caps.DynamicFlowControlDepth > D3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH
852 || pCaps->VS20Caps.DynamicFlowControlDepth < 0)
853 pCaps->VS20Caps.DynamicFlowControlDepth = D3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH;
854 if (pCaps->VS20Caps.StaticFlowControlDepth > D3DVS20_MAX_STATICFLOWCONTROLDEPTH
855 || pCaps->VS20Caps.StaticFlowControlDepth < 0)
856 pCaps->VS20Caps.StaticFlowControlDepth = D3DVS20_MAX_STATICFLOWCONTROLDEPTH;
857 if (pCaps->VS20Caps.NumTemps > D3DVS20_MAX_NUMTEMPS)
858 pCaps->VS20Caps.NumTemps = D3DVS20_MAX_NUMTEMPS;
859 assert(pCaps->VS20Caps.DynamicFlowControlDepth >= D3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH);
860 assert(pCaps->VS20Caps.StaticFlowControlDepth >= D3DVS20_MIN_STATICFLOWCONTROLDEPTH);
861 assert(pCaps->VS20Caps.NumTemps >= D3DVS20_MIN_NUMTEMPS);
862
863
864 pCaps->PS20Caps.Caps = D3DPS20CAPS_ARBITRARYSWIZZLE |
865 D3DPS20CAPS_GRADIENTINSTRUCTIONS |
866 D3DPS20CAPS_PREDICATION;
867 if (screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
868 PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS) ==
869 screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
870 PIPE_SHADER_CAP_MAX_INSTRUCTIONS))
871 pCaps->PS20Caps.Caps |= D3DPS20CAPS_NOTEXINSTRUCTIONLIMIT;
872 if (screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
873 PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS) ==
874 screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
875 PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS))
876 pCaps->PS20Caps.Caps |= D3DPS20CAPS_NODEPENDENTREADLIMIT;
877 pCaps->PS20Caps.DynamicFlowControlDepth = /* XXX is this dynamic ? */
878 screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
879 PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
880 pCaps->PS20Caps.NumTemps =
881 screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
882 PIPE_SHADER_CAP_MAX_TEMPS);
883 pCaps->PS20Caps.StaticFlowControlDepth = /* XXX is this static ? */
884 screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
885 PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
886 pCaps->PS20Caps.NumInstructionSlots =
887 screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
888 PIPE_SHADER_CAP_MAX_INSTRUCTIONS);
889
890 if (pCaps->PS20Caps.DynamicFlowControlDepth > D3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH
891 || pCaps->PS20Caps.DynamicFlowControlDepth < 0)
892 pCaps->PS20Caps.DynamicFlowControlDepth = D3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH;
893 if (pCaps->PS20Caps.StaticFlowControlDepth > D3DPS20_MAX_STATICFLOWCONTROLDEPTH
894 || pCaps->PS20Caps.StaticFlowControlDepth < 0)
895 pCaps->PS20Caps.StaticFlowControlDepth = D3DPS20_MAX_STATICFLOWCONTROLDEPTH;
896 if (pCaps->PS20Caps.NumTemps > D3DPS20_MAX_NUMTEMPS)
897 pCaps->PS20Caps.NumTemps = D3DPS20_MAX_NUMTEMPS;
898 if (pCaps->PS20Caps.NumInstructionSlots > D3DPS20_MAX_NUMINSTRUCTIONSLOTS)
899 pCaps->PS20Caps.NumInstructionSlots = D3DPS20_MAX_NUMINSTRUCTIONSLOTS;
900 assert(pCaps->PS20Caps.DynamicFlowControlDepth >= D3DPS20_MIN_DYNAMICFLOWCONTROLDEPTH);
901 assert(pCaps->PS20Caps.StaticFlowControlDepth >= D3DPS20_MIN_STATICFLOWCONTROLDEPTH);
902 assert(pCaps->PS20Caps.NumTemps >= D3DPS20_MIN_NUMTEMPS);
903 assert(pCaps->PS20Caps.NumInstructionSlots >= D3DPS20_MIN_NUMINSTRUCTIONSLOTS);
904
905
906 if (screen->get_shader_param(screen, PIPE_SHADER_VERTEX,
907 PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS))
908 pCaps->VertexTextureFilterCaps = pCaps->TextureFilterCaps &
909 ~(D3DPTFILTERCAPS_MIPFPOINT |
910 D3DPTFILTERCAPS_MIPFPOINT); /* XXX */
911 else
912 pCaps->VertexTextureFilterCaps = 0;
913
914 pCaps->MaxVertexShader30InstructionSlots =
915 screen->get_shader_param(screen, PIPE_SHADER_VERTEX,
916 PIPE_SHADER_CAP_MAX_INSTRUCTIONS);
917 pCaps->MaxPixelShader30InstructionSlots =
918 screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
919 PIPE_SHADER_CAP_MAX_INSTRUCTIONS);
920 if (pCaps->MaxVertexShader30InstructionSlots > D3DMAX30SHADERINSTRUCTIONS)
921 pCaps->MaxVertexShader30InstructionSlots = D3DMAX30SHADERINSTRUCTIONS;
922 if (pCaps->MaxPixelShader30InstructionSlots > D3DMAX30SHADERINSTRUCTIONS)
923 pCaps->MaxPixelShader30InstructionSlots = D3DMAX30SHADERINSTRUCTIONS;
924 assert(pCaps->MaxVertexShader30InstructionSlots >= D3DMIN30SHADERINSTRUCTIONS);
925 assert(pCaps->MaxPixelShader30InstructionSlots >= D3DMIN30SHADERINSTRUCTIONS);
926
927 /* 65535 is required, advertise more for GPUs with >= 2048 instruction slots */
928 pCaps->MaxVShaderInstructionsExecuted = MAX2(65535, pCaps->MaxVertexShader30InstructionSlots * 32);
929 pCaps->MaxPShaderInstructionsExecuted = MAX2(65535, pCaps->MaxPixelShader30InstructionSlots * 32);
930
931 if (debug_get_bool_option("NINE_DUMP_CAPS", FALSE))
932 nine_dump_D3DCAPS9(DBG_CHANNEL, pCaps);
933
934 return D3D_OK;
935 }
936
937 HRESULT WINAPI
938 NineAdapter9_CreateDevice( struct NineAdapter9 *This,
939 UINT RealAdapter,
940 D3DDEVTYPE DeviceType,
941 HWND hFocusWindow,
942 DWORD BehaviorFlags,
943 D3DPRESENT_PARAMETERS *pPresentationParameters,
944 IDirect3D9 *pD3D9,
945 ID3DPresentGroup *pPresentationGroup,
946 IDirect3DDevice9 **ppReturnedDeviceInterface )
947 {
948 struct pipe_screen *screen;
949 D3DDEVICE_CREATION_PARAMETERS params;
950 D3DCAPS9 caps;
951 int major, minor;
952 HRESULT hr;
953
954 DBG("This=%p RealAdapter=%u DeviceType=%s hFocusWindow=%p "
955 "BehaviourFlags=%x " "pD3D9=%p pPresentationGroup=%p "
956 "ppReturnedDeviceInterface=%p\n", This,
957 RealAdapter, nine_D3DDEVTYPE_to_str(DeviceType), hFocusWindow,
958 BehaviorFlags, pD3D9, pPresentationGroup, ppReturnedDeviceInterface);
959
960 ID3DPresentGroup_GetVersion(pPresentationGroup, &major, &minor);
961 if (major != 1) {
962 ERR("Doesn't support the ID3DPresentGroup version %d %d. Expected 1\n",
963 major, minor);
964 return D3DERR_NOTAVAILABLE;
965 }
966
967 hr = NineAdapter9_GetScreen(This, DeviceType, &screen);
968 if (FAILED(hr)) {
969 DBG("Failed to get pipe_screen.\n");
970 return hr;
971 }
972
973 hr = NineAdapter9_GetDeviceCaps(This, DeviceType, &caps);
974 if (FAILED(hr)) {
975 DBG("Failed to get device caps.\n");
976 return hr;
977 }
978
979 params.AdapterOrdinal = RealAdapter;
980 params.DeviceType = DeviceType;
981 params.hFocusWindow = hFocusWindow;
982 params.BehaviorFlags = BehaviorFlags;
983
984 hr = NineDevice9_new(screen, &params, &caps, pPresentationParameters,
985 pD3D9, pPresentationGroup, This->ctx, FALSE, NULL,
986 (struct NineDevice9 **)ppReturnedDeviceInterface);
987 if (FAILED(hr)) {
988 DBG("Failed to create device.\n");
989 return hr;
990 }
991 DBG("NineDevice9 created successfully.\n");
992
993 return D3D_OK;
994 }
995
996 HRESULT WINAPI
997 NineAdapter9_CreateDeviceEx( struct NineAdapter9 *This,
998 UINT RealAdapter,
999 D3DDEVTYPE DeviceType,
1000 HWND hFocusWindow,
1001 DWORD BehaviorFlags,
1002 D3DPRESENT_PARAMETERS *pPresentationParameters,
1003 D3DDISPLAYMODEEX *pFullscreenDisplayMode,
1004 IDirect3D9Ex *pD3D9Ex,
1005 ID3DPresentGroup *pPresentationGroup,
1006 IDirect3DDevice9Ex **ppReturnedDeviceInterface )
1007 {
1008 struct pipe_screen *screen;
1009 D3DDEVICE_CREATION_PARAMETERS params;
1010 D3DCAPS9 caps;
1011 int major, minor;
1012 HRESULT hr;
1013
1014 DBG("This=%p RealAdapter=%u DeviceType=%s hFocusWindow=%p "
1015 "BehaviourFlags=%x " "pD3D9Ex=%p pPresentationGroup=%p "
1016 "ppReturnedDeviceInterface=%p\n", This,
1017 RealAdapter, nine_D3DDEVTYPE_to_str(DeviceType), hFocusWindow,
1018 BehaviorFlags, pD3D9Ex, pPresentationGroup, ppReturnedDeviceInterface);
1019
1020 ID3DPresentGroup_GetVersion(pPresentationGroup, &major, &minor);
1021 if (major != 1) {
1022 ERR("Doesn't support the ID3DPresentGroup version %d %d. Expected 1\n",
1023 major, minor);
1024 return D3DERR_NOTAVAILABLE;
1025 }
1026
1027 hr = NineAdapter9_GetScreen(This, DeviceType, &screen);
1028 if (FAILED(hr)) {
1029 DBG("Failed to get pipe_screen.\n");
1030 return hr;
1031 }
1032
1033 hr = NineAdapter9_GetDeviceCaps(This, DeviceType, &caps);
1034 if (FAILED(hr)) {
1035 DBG("Failed to get device caps.\n");
1036 return hr;
1037 }
1038
1039 params.AdapterOrdinal = RealAdapter;
1040 params.DeviceType = DeviceType;
1041 params.hFocusWindow = hFocusWindow;
1042 params.BehaviorFlags = BehaviorFlags;
1043
1044 hr = NineDevice9Ex_new(screen, &params, &caps, pPresentationParameters,
1045 pFullscreenDisplayMode,
1046 pD3D9Ex, pPresentationGroup, This->ctx,
1047 (struct NineDevice9Ex **)ppReturnedDeviceInterface);
1048 if (FAILED(hr)) {
1049 DBG("Failed to create device.\n");
1050 return hr;
1051 }
1052 DBG("NineDevice9Ex created successfully.\n");
1053
1054 return D3D_OK;
1055 }
1056
1057 ID3DAdapter9Vtbl NineAdapter9_vtable = {
1058 (void *)NineUnknown_QueryInterface,
1059 (void *)NineUnknown_AddRef,
1060 (void *)NineUnknown_Release,
1061 (void *)NineAdapter9_GetAdapterIdentifier,
1062 (void *)NineAdapter9_CheckDeviceType,
1063 (void *)NineAdapter9_CheckDeviceFormat,
1064 (void *)NineAdapter9_CheckDeviceMultiSampleType,
1065 (void *)NineAdapter9_CheckDepthStencilMatch,
1066 (void *)NineAdapter9_CheckDeviceFormatConversion,
1067 (void *)NineAdapter9_GetDeviceCaps,
1068 (void *)NineAdapter9_CreateDevice,
1069 (void *)NineAdapter9_CreateDeviceEx
1070 };
1071
1072 static const GUID *NineAdapter9_IIDs[] = {
1073 &IID_ID3D9Adapter,
1074 &IID_IUnknown,
1075 NULL
1076 };
1077
1078 HRESULT
1079 NineAdapter9_new( struct d3dadapter9_context *pCTX,
1080 struct NineAdapter9 **ppOut )
1081 {
1082 NINE_NEW(Adapter9, ppOut, FALSE, /* args */ pCTX);
1083 }