2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
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:
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
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. */
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/format/u_format.h"
31 #include "util/u_dump.h"
33 #include "pipe/p_screen.h"
35 #define DBG_CHANNEL DBG_ADAPTER
38 has_sm3(struct pipe_screen
*hal
)
40 return hal
->get_param(hal
, PIPE_CAP_FRAGMENT_SHADER_TEXTURE_LOD
) &&
41 hal
->get_param(hal
, PIPE_CAP_FRAGMENT_SHADER_DERIVATIVES
) &&
42 hal
->get_param(hal
, PIPE_CAP_VERTEX_SHADER_SATURATE
);
46 NineAdapter9_ctor( struct NineAdapter9
*This
,
47 struct NineUnknownParams
*pParams
,
48 struct d3dadapter9_context
*pCTX
)
50 struct pipe_screen
*hal
= pCTX
->hal
;
51 HRESULT hr
= NineUnknown_ctor(&This
->base
, pParams
);
52 if (FAILED(hr
)) { return hr
; }
54 DBG("This=%p pParams=%p pCTX=%p\n", This
, pParams
, pCTX
);
55 nine_dump_D3DADAPTER_IDENTIFIER9(DBG_CHANNEL
, &pCTX
->identifier
);
58 if (!hal
->get_param(hal
, PIPE_CAP_CLIP_HALFZ
)) {
59 ERR("Driver doesn't support d3d9 coordinates\n");
60 return D3DERR_DRIVERINTERNALERROR
;
63 !This
->ctx
->ref
->get_param(This
->ctx
->ref
, PIPE_CAP_CLIP_HALFZ
)) {
64 ERR("Warning: Sotware rendering driver doesn't support d3d9 coordinates\n");
66 /* Old cards had tricks to bypass some restrictions to implement
67 * everything and fit tight the requirements: number of constants,
68 * number of temp registers, special behaviours, etc. Since we don't
69 * have access to all this, we need a bit more than what dx9 required.
70 * For example we have to use more than 32 temp registers to emulate
71 * behaviours, while some dx9 hw don't have more. As for sm2 hardware,
72 * we could support vs2 / ps2 for them but it needs some more care, and
73 * as these are very old, we choose to drop support for them */
75 /* checks minimum requirements, most are vs3/ps3 strict requirements */
77 hal
->get_shader_param(hal
, PIPE_SHADER_VERTEX
,
78 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
) < 256 * sizeof(float[4]) ||
79 hal
->get_shader_param(hal
, PIPE_SHADER_FRAGMENT
,
80 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
) < 244 * sizeof(float[4]) ||
81 hal
->get_shader_param(hal
, PIPE_SHADER_VERTEX
,
82 PIPE_SHADER_CAP_MAX_TEMPS
) < 32 ||
83 hal
->get_shader_param(hal
, PIPE_SHADER_FRAGMENT
,
84 PIPE_SHADER_CAP_MAX_TEMPS
) < 32 ||
85 hal
->get_shader_param(hal
, PIPE_SHADER_VERTEX
,
86 PIPE_SHADER_CAP_MAX_INPUTS
) < 16 ||
87 hal
->get_shader_param(hal
, PIPE_SHADER_FRAGMENT
,
88 PIPE_SHADER_CAP_MAX_INPUTS
) < 10 ||
89 hal
->get_shader_param(hal
, PIPE_SHADER_FRAGMENT
,
90 PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS
) < 16) {
91 ERR("Your card is not supported by Gallium Nine. Minimum requirement "
92 "is >= r500, >= nv50, >= i965\n");
93 return D3DERR_DRIVERINTERNALERROR
;
96 if (hal
->get_shader_param(hal
, PIPE_SHADER_VERTEX
,
97 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
) < 276 * sizeof(float[4]) || /* we put bool and int constants with float constants */
98 hal
->get_shader_param(hal
, PIPE_SHADER_VERTEX
,
99 PIPE_SHADER_CAP_MAX_TEMPS
) < 40 || /* we use some more temp registers */
100 hal
->get_shader_param(hal
, PIPE_SHADER_FRAGMENT
,
101 PIPE_SHADER_CAP_MAX_TEMPS
) < 40 ||
102 hal
->get_shader_param(hal
, PIPE_SHADER_FRAGMENT
,
103 PIPE_SHADER_CAP_MAX_INPUTS
) < 20) /* we don't pack inputs as much as we could */
104 ERR("Your card is at the limit of Gallium Nine requirements. Some games "
105 "may run into issues because requirements are too tight\n");
110 NineAdapter9_dtor( struct NineAdapter9
*This
)
112 struct d3dadapter9_context
*ctx
= This
->ctx
;
114 DBG("This=%p\n", This
);
116 NineUnknown_dtor(&This
->base
);
118 /* special case, call backend-specific dtor AFTER destroying this object
121 if (ctx
->destroy
) { ctx
->destroy(ctx
); }
126 NineAdapter9_GetScreen( struct NineAdapter9
*This
,
128 struct pipe_screen
**ppScreen
)
130 const char *force_sw
= getenv("D3D_ALWAYS_SOFTWARE");
133 if (force_sw
&& !strcmp(force_sw
, "1") && This
->ctx
->ref
) {
134 *ppScreen
= This
->ctx
->ref
;
137 *ppScreen
= This
->ctx
->hal
;
141 case D3DDEVTYPE_NULLREF
:
143 if (force_sw
&& !strcmp(force_sw
, "0")) {
144 *ppScreen
= This
->ctx
->hal
;
147 *ppScreen
= This
->ctx
->ref
;
151 user_assert(!"Invalid device type", D3DERR_INVALIDCALL
);
154 if (!*ppScreen
) { return D3DERR_NOTAVAILABLE
; }
160 NineAdapter9_GetAdapterIdentifier( struct NineAdapter9
*This
,
162 D3DADAPTER_IDENTIFIER9
*pIdentifier
)
164 DBG("This=%p Flags=%x pIdentifier=%p\n", This
, Flags
, pIdentifier
);
166 /* regarding flags, MSDN has this to say:
167 * Flags sets the WHQLLevel member of D3DADAPTER_IDENTIFIER9. Flags can be
168 * set to either 0 or D3DENUM_WHQL_LEVEL. If D3DENUM_WHQL_LEVEL is
169 * specified, this call can connect to the Internet to download new
170 * Microsoft Windows Hardware Quality Labs (WHQL) certificates.
171 * so let's just ignore it. */
172 *pIdentifier
= This
->ctx
->identifier
;
176 static inline boolean
177 backbuffer_format( D3DFORMAT dfmt
,
181 if (dfmt
== D3DFMT_A2R10G10B10
&& win
) { return FALSE
; }
183 if ((dfmt
== D3DFMT_A2R10G10B10
&& bfmt
== dfmt
) ||
184 (dfmt
== D3DFMT_X8R8G8B8
&& (bfmt
== dfmt
||
185 bfmt
== D3DFMT_A8R8G8B8
)) ||
186 (dfmt
== D3DFMT_X1R5G5B5
&& (bfmt
== dfmt
||
187 bfmt
== D3DFMT_A1R5G5B5
)) ||
188 (dfmt
== D3DFMT_R5G6B5
&& bfmt
== dfmt
)) {
196 NineAdapter9_CheckDeviceType( struct NineAdapter9
*This
,
198 D3DFORMAT AdapterFormat
,
199 D3DFORMAT BackBufferFormat
,
202 struct pipe_screen
*screen
;
203 enum pipe_format dfmt
, bfmt
;
206 DBG("This=%p DevType=%s AdapterFormat=%s BackBufferFormat=%s "
207 "bWindowed=%i\n", This
, nine_D3DDEVTYPE_to_str(DevType
),
208 d3dformat_to_string(AdapterFormat
),
209 d3dformat_to_string(BackBufferFormat
), bWindowed
);
211 user_assert(backbuffer_format(AdapterFormat
, BackBufferFormat
, bWindowed
),
212 D3DERR_NOTAVAILABLE
);
214 hr
= NineAdapter9_GetScreen(This
, DevType
, &screen
);
215 if (FAILED(hr
)) { return hr
; }
217 /* The display format is not handled in Nine. We always present an XRGB8888
218 * buffer (and the display server will eventually do the conversion). We probably
219 * don't need to check for anything for the adapter format support, since if the
220 * display server advertise support, it will likely be able to do the conversion.
221 * We do the approximation that a format is available in the display server if
222 * the format passes with NINE_BIND_BACKBUFFER_FLAGS */
223 dfmt
= d3d9_to_pipe_format_checked(screen
, AdapterFormat
, PIPE_TEXTURE_2D
,
225 NINE_BIND_BACKBUFFER_FLAGS
, FALSE
, FALSE
);
226 bfmt
= d3d9_to_pipe_format_checked(screen
, BackBufferFormat
, PIPE_TEXTURE_2D
,
228 NINE_BIND_BACKBUFFER_FLAGS
, FALSE
, FALSE
);
229 if (dfmt
== PIPE_FORMAT_NONE
|| bfmt
== PIPE_FORMAT_NONE
) {
230 DBG("Unsupported Adapter/BackBufferFormat.\n");
231 return D3DERR_NOTAVAILABLE
;
237 static inline boolean
238 display_format( D3DFORMAT fmt
,
241 /* http://msdn.microsoft.com/en-us/library/bb172558(v=VS.85).aspx#BackBuffer_or_Display_Formats */
242 static const D3DFORMAT allowed
[] = {
250 if (fmt
== D3DFMT_A2R10G10B10
&& win
) { return FALSE
; }
252 for (i
= 0; i
< sizeof(allowed
)/sizeof(D3DFORMAT
); i
++) {
253 if (fmt
== allowed
[i
]) { return TRUE
; }
259 NineAdapter9_CheckDeviceFormat( struct NineAdapter9
*This
,
260 D3DDEVTYPE DeviceType
,
261 D3DFORMAT AdapterFormat
,
263 D3DRESOURCETYPE RType
,
264 D3DFORMAT CheckFormat
)
266 struct pipe_screen
*screen
;
269 enum pipe_texture_target target
;
273 /* Check adapter format. */
275 DBG("This=%p DeviceType=%s AdapterFormat=%s\n", This
,
276 nine_D3DDEVTYPE_to_str(DeviceType
), d3dformat_to_string(AdapterFormat
));
277 DBG("Usage=%x RType=%u CheckFormat=%s\n", Usage
, RType
,
278 d3dformat_to_string(CheckFormat
));
280 user_assert(display_format(AdapterFormat
, FALSE
), D3DERR_INVALIDCALL
);
282 hr
= NineAdapter9_GetScreen(This
, DeviceType
, &screen
);
285 pf
= d3d9_to_pipe_format_checked(screen
, AdapterFormat
, PIPE_TEXTURE_2D
, 0,
286 PIPE_BIND_DISPLAY_TARGET
|
287 PIPE_BIND_SHARED
, FALSE
, FALSE
);
288 if (pf
== PIPE_FORMAT_NONE
) {
289 DBG("AdapterFormat %s not available.\n",
290 d3dformat_to_string(AdapterFormat
));
291 return D3DERR_NOTAVAILABLE
;
294 /* Check actual format. */
297 case D3DRTYPE_SURFACE
: target
= PIPE_TEXTURE_2D
; break;
298 case D3DRTYPE_TEXTURE
: target
= PIPE_TEXTURE_2D
; break;
299 case D3DRTYPE_CUBETEXTURE
: target
= PIPE_TEXTURE_CUBE
; break;
300 case D3DRTYPE_VOLUME
: target
= PIPE_TEXTURE_3D
; break;
301 case D3DRTYPE_VOLUMETEXTURE
: target
= PIPE_TEXTURE_3D
; break;
302 case D3DRTYPE_VERTEXBUFFER
: target
= PIPE_BUFFER
; break;
303 case D3DRTYPE_INDEXBUFFER
: target
= PIPE_BUFFER
; break;
305 user_assert(0, D3DERR_INVALIDCALL
);
309 if (Usage
& D3DUSAGE_RENDERTARGET
) bind
|= PIPE_BIND_RENDER_TARGET
;
310 if (Usage
& D3DUSAGE_DEPTHSTENCIL
) {
311 if (!depth_stencil_format(CheckFormat
))
312 return D3DERR_NOTAVAILABLE
;
313 bind
|= d3d9_get_pipe_depth_format_bindings(CheckFormat
);
316 /* API hack because setting RT[0] to NULL is forbidden */
317 if (CheckFormat
== D3DFMT_NULL
&& bind
== PIPE_BIND_RENDER_TARGET
&&
318 (RType
== D3DRTYPE_SURFACE
||
319 RType
== D3DRTYPE_TEXTURE
))
323 if (CheckFormat
== D3DFMT_RESZ
&& bind
== PIPE_BIND_RENDER_TARGET
&&
324 RType
== D3DRTYPE_SURFACE
)
325 return screen
->get_param(screen
, PIPE_CAP_MULTISAMPLE_Z_RESOLVE
) ?
326 D3D_OK
: D3DERR_NOTAVAILABLE
;
329 if (CheckFormat
== D3DFMT_ATOC
&& RType
== D3DRTYPE_SURFACE
)
332 if ((Usage
& D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
) &&
333 (Usage
& D3DUSAGE_RENDERTARGET
))
334 bind
|= PIPE_BIND_BLENDABLE
;
336 if (Usage
& D3DUSAGE_DMAP
) {
337 DBG("D3DUSAGE_DMAP not available\n");
338 return D3DERR_NOTAVAILABLE
; /* TODO: displacement mapping */
342 case D3DRTYPE_TEXTURE
: bind
|= PIPE_BIND_SAMPLER_VIEW
; break;
343 case D3DRTYPE_CUBETEXTURE
: bind
|= PIPE_BIND_SAMPLER_VIEW
; break;
344 case D3DRTYPE_VOLUMETEXTURE
: bind
|= PIPE_BIND_SAMPLER_VIEW
; break;
345 case D3DRTYPE_VERTEXBUFFER
: bind
|= PIPE_BIND_VERTEX_BUFFER
; break;
346 case D3DRTYPE_INDEXBUFFER
: bind
|= PIPE_BIND_INDEX_BUFFER
; break;
347 case D3DRTYPE_SURFACE
:
348 if (!(Usage
& D3DUSAGE_DEPTHSTENCIL
))
349 bind
|= PIPE_BIND_SAMPLER_VIEW
; /* StretchRect */
350 /* Offscreen surface support: Usage = 0.
351 * In practice drivers are very restrictive on the formats supported.
352 * Basically a few common formats + YUV and compressed formats. The
353 * reason is that offscreen surface are useful only for directdraw
354 * compatibility (a WONTIMPL of nine) + format conversion (useful in
355 * particular for YUV because the format was not advertised for textures
358 bind
|= PIPE_BIND_RENDER_TARGET
; /* A current requirement of our impl, which we should get rid of. */
364 srgb
= (Usage
& (D3DUSAGE_QUERY_SRGBREAD
| D3DUSAGE_QUERY_SRGBWRITE
)) != 0;
365 pf
= d3d9_to_pipe_format_checked(screen
, CheckFormat
, target
,
366 0, bind
, srgb
, FALSE
);
367 if (pf
== PIPE_FORMAT_NONE
) {
368 DBG("NOT AVAILABLE\n");
369 return D3DERR_NOTAVAILABLE
;
372 /* we support ATI1 and ATI2 hack only for 2D and Cube textures */
373 if (RType
!= D3DRTYPE_TEXTURE
&& RType
!= D3DRTYPE_CUBETEXTURE
&&
374 (CheckFormat
== D3DFMT_ATI1
|| CheckFormat
== D3DFMT_ATI2
))
375 return D3DERR_NOTAVAILABLE
;
376 /* if (Usage & D3DUSAGE_NONSECURE) { don't know the implications of this } */
377 /* if (Usage & D3DUSAGE_SOFTWAREPROCESSING) { we can always support this } */
379 if ((Usage
& D3DUSAGE_AUTOGENMIPMAP
) && !(bind
& PIPE_BIND_SAMPLER_VIEW
))
380 return D3DOK_NOAUTOGEN
;
385 NineAdapter9_CheckDeviceMultiSampleType( struct NineAdapter9
*This
,
386 D3DDEVTYPE DeviceType
,
387 D3DFORMAT SurfaceFormat
,
389 D3DMULTISAMPLE_TYPE MultiSampleType
,
390 DWORD
*pQualityLevels
)
392 struct pipe_screen
*screen
;
397 DBG("This=%p DeviceType=%s SurfaceFormat=%s Windowed=%i MultiSampleType=%u "
398 "pQualityLevels=%p\n", This
, nine_D3DDEVTYPE_to_str(DeviceType
),
399 d3dformat_to_string(SurfaceFormat
), Windowed
, MultiSampleType
,
402 if (pQualityLevels
) {
403 /* In error cases return only 1 quality level supported */
406 user_assert(MultiSampleType
<= D3DMULTISAMPLE_16_SAMPLES
, D3DERR_INVALIDCALL
);
408 hr
= NineAdapter9_GetScreen(This
, DeviceType
, &screen
);
412 if (depth_stencil_format(SurfaceFormat
))
413 bind
= d3d9_get_pipe_depth_format_bindings(SurfaceFormat
);
414 else /* render-target */
415 bind
= PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
;
417 pf
= d3d9_to_pipe_format_checked(screen
, SurfaceFormat
, PIPE_TEXTURE_2D
,
418 0, PIPE_BIND_SAMPLER_VIEW
, FALSE
, FALSE
);
420 if (pf
== PIPE_FORMAT_NONE
&& SurfaceFormat
!= D3DFMT_NULL
) {
421 DBG("%s not available.\n", d3dformat_to_string(SurfaceFormat
));
422 return D3DERR_INVALIDCALL
;
425 pf
= d3d9_to_pipe_format_checked(screen
, SurfaceFormat
, PIPE_TEXTURE_2D
,
426 MultiSampleType
, bind
, FALSE
, FALSE
);
428 if (pf
== PIPE_FORMAT_NONE
&& SurfaceFormat
!= D3DFMT_NULL
) {
429 DBG("%s with %u samples not available.\n",
430 d3dformat_to_string(SurfaceFormat
), MultiSampleType
);
431 return D3DERR_NOTAVAILABLE
;
434 if (pQualityLevels
) {
435 /* NONMASKABLE MultiSampleType might have more than one quality level,
436 * while MASKABLE MultiSampleTypes have only one level.
437 * Advertise quality levels and map each level to a sample count. */
438 (void ) d3dmultisample_type_check(screen
, SurfaceFormat
,
439 &MultiSampleType
, D3DMULTISAMPLE_16_SAMPLES
, pQualityLevels
);
440 DBG("advertising %u quality levels\n", *pQualityLevels
);
447 NineAdapter9_CheckDepthStencilMatch( struct NineAdapter9
*This
,
448 D3DDEVTYPE DeviceType
,
449 D3DFORMAT AdapterFormat
,
450 D3DFORMAT RenderTargetFormat
,
451 D3DFORMAT DepthStencilFormat
)
453 struct pipe_screen
*screen
;
454 enum pipe_format dfmt
, bfmt
, zsfmt
;
457 DBG("This=%p DeviceType=%s AdapterFormat=%s "
458 "RenderTargetFormat=%s DepthStencilFormat=%s\n", This
,
459 nine_D3DDEVTYPE_to_str(DeviceType
), d3dformat_to_string(AdapterFormat
),
460 d3dformat_to_string(RenderTargetFormat
),
461 d3dformat_to_string(DepthStencilFormat
));
463 user_assert(display_format(AdapterFormat
, FALSE
), D3DERR_NOTAVAILABLE
);
464 user_assert(depth_stencil_format(DepthStencilFormat
), D3DERR_NOTAVAILABLE
);
466 hr
= NineAdapter9_GetScreen(This
, DeviceType
, &screen
);
467 if (FAILED(hr
)) { return hr
; }
469 dfmt
= d3d9_to_pipe_format_checked(screen
, AdapterFormat
, PIPE_TEXTURE_2D
, 0,
470 NINE_BIND_BACKBUFFER_FLAGS
, FALSE
, FALSE
);
471 bfmt
= d3d9_to_pipe_format_checked(screen
, RenderTargetFormat
,
473 NINE_BIND_BACKBUFFER_FLAGS
, FALSE
, FALSE
);
474 if (RenderTargetFormat
== D3DFMT_NULL
)
476 zsfmt
= d3d9_to_pipe_format_checked(screen
, DepthStencilFormat
,
478 d3d9_get_pipe_depth_format_bindings(DepthStencilFormat
),
480 if (dfmt
== PIPE_FORMAT_NONE
||
481 bfmt
== PIPE_FORMAT_NONE
||
482 zsfmt
== PIPE_FORMAT_NONE
) {
483 return D3DERR_NOTAVAILABLE
;
490 NineAdapter9_CheckDeviceFormatConversion( struct NineAdapter9
*This
,
491 D3DDEVTYPE DeviceType
,
492 D3DFORMAT SourceFormat
,
493 D3DFORMAT TargetFormat
)
495 /* MSDN says this tests whether a certain backbuffer format can be used in
496 * conjunction with a certain front buffer format. It's a little confusing
497 * but some one wiser might be able to figure this one out. XXX */
498 struct pipe_screen
*screen
;
499 enum pipe_format dfmt
, bfmt
;
502 DBG("This=%p DeviceType=%s SourceFormat=%s TargetFormat=%s\n", This
,
503 nine_D3DDEVTYPE_to_str(DeviceType
),
504 d3dformat_to_string(SourceFormat
), d3dformat_to_string(TargetFormat
));
506 user_assert(backbuffer_format(TargetFormat
, SourceFormat
, FALSE
),
507 D3DERR_NOTAVAILABLE
);
509 hr
= NineAdapter9_GetScreen(This
, DeviceType
, &screen
);
510 if (FAILED(hr
)) { return hr
; }
512 dfmt
= d3d9_to_pipe_format_checked(screen
, TargetFormat
, PIPE_TEXTURE_2D
, 1,
513 NINE_BIND_BACKBUFFER_FLAGS
, FALSE
, FALSE
);
514 bfmt
= d3d9_to_pipe_format_checked(screen
, SourceFormat
, PIPE_TEXTURE_2D
, 1,
515 NINE_BIND_BACKBUFFER_FLAGS
, FALSE
, FALSE
);
517 if (dfmt
== PIPE_FORMAT_NONE
|| bfmt
== PIPE_FORMAT_NONE
) {
518 DBG("%s to %s not supported.\n",
519 d3dformat_to_string(SourceFormat
),
520 d3dformat_to_string(TargetFormat
));
521 return D3DERR_NOTAVAILABLE
;
528 NineAdapter9_GetDeviceCaps( struct NineAdapter9
*This
,
529 D3DDEVTYPE DeviceType
,
532 struct pipe_screen
*screen
;
535 DBG("This=%p DeviceType=%s pCaps=%p\n", This
,
536 nine_D3DDEVTYPE_to_str(DeviceType
), pCaps
);
538 user_assert(pCaps
, D3DERR_INVALIDCALL
);
540 hr
= NineAdapter9_GetScreen(This
, DeviceType
, &screen
);
542 DBG("Failed to get pipe_screen.\n");
546 #define D3DPIPECAP(pcap, d3dcap) \
547 (screen->get_param(screen, PIPE_CAP_##pcap) ? (d3dcap) : 0)
549 #define D3DNPIPECAP(pcap, d3dcap) \
550 (screen->get_param(screen, PIPE_CAP_##pcap) ? 0 : (d3dcap))
552 pCaps
->DeviceType
= DeviceType
;
554 pCaps
->AdapterOrdinal
= 0;
556 pCaps
->Caps
= D3DCAPS_READ_SCANLINE
;
558 pCaps
->Caps2
= /* D3DCAPS2_CANMANAGERESOURCE | */
559 /* D3DCAPS2_CANSHARERESOURCE | */
560 /* D3DCAPS2_CANCALIBRATEGAMMA | */
561 D3DCAPS2_DYNAMICTEXTURES
|
562 D3DCAPS2_FULLSCREENGAMMA
|
563 D3DCAPS2_CANAUTOGENMIPMAP
;
565 /* Note: D3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD just means the
566 * backbuffer can be ARGB (instead of only XRGB) when we are fullscreen
567 * and in discard mode. */
568 pCaps
->Caps3
= D3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD
|
569 D3DCAPS3_COPY_TO_VIDMEM
|
570 D3DCAPS3_COPY_TO_SYSTEMMEM
|
571 D3DCAPS3_LINEAR_TO_SRGB_PRESENTATION
;
573 pCaps
->PresentationIntervals
= D3DPRESENT_INTERVAL_DEFAULT
|
574 D3DPRESENT_INTERVAL_ONE
|
575 D3DPRESENT_INTERVAL_TWO
|
576 D3DPRESENT_INTERVAL_THREE
|
577 D3DPRESENT_INTERVAL_FOUR
|
578 D3DPRESENT_INTERVAL_IMMEDIATE
;
579 pCaps
->CursorCaps
= D3DCURSORCAPS_COLOR
/* | D3DCURSORCAPS_LOWRES*/;
581 pCaps
->DevCaps
= D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
582 D3DDEVCAPS_CANRENDERAFTERFLIP
|
583 D3DDEVCAPS_DRAWPRIMITIVES2
|
584 D3DDEVCAPS_DRAWPRIMITIVES2EX
|
585 D3DDEVCAPS_DRAWPRIMTLVERTEX
|
586 D3DDEVCAPS_EXECUTESYSTEMMEMORY
|
587 D3DDEVCAPS_EXECUTEVIDEOMEMORY
|
588 D3DDEVCAPS_HWRASTERIZATION
|
589 D3DDEVCAPS_HWTRANSFORMANDLIGHT
|
590 /*D3DDEVCAPS_NPATCHES |*/
591 D3DDEVCAPS_PUREDEVICE
|
592 /*D3DDEVCAPS_QUINTICRTPATCHES |*/
593 /*D3DDEVCAPS_RTPATCHES |*/
594 /*D3DDEVCAPS_RTPATCHHANDLEZERO |*/
595 /*D3DDEVCAPS_SEPARATETEXTUREMEMORIES |*/
596 D3DDEVCAPS_TEXTURENONLOCALVIDMEM
|
597 /* D3DDEVCAPS_TEXTURESYSTEMMEMORY |*/
598 D3DDEVCAPS_TEXTUREVIDEOMEMORY
|
599 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
|
600 D3DDEVCAPS_TLVERTEXVIDEOMEMORY
;
602 pCaps
->PrimitiveMiscCaps
= D3DPMISCCAPS_MASKZ
|
603 D3DPMISCCAPS_CULLNONE
| /* XXX */
604 D3DPMISCCAPS_CULLCW
|
605 D3DPMISCCAPS_CULLCCW
|
606 D3DPMISCCAPS_COLORWRITEENABLE
|
607 D3DPMISCCAPS_CLIPPLANESCALEDPOINTS
|
608 /*D3DPMISCCAPS_CLIPTLVERTS |*/
609 D3DPMISCCAPS_TSSARGTEMP
|
610 D3DPMISCCAPS_BLENDOP
|
611 D3DPIPECAP(INDEP_BLEND_ENABLE
, D3DPMISCCAPS_INDEPENDENTWRITEMASKS
) |
612 D3DPMISCCAPS_PERSTAGECONSTANT
|
613 /*D3DPMISCCAPS_POSTBLENDSRGBCONVERT |*/ /* TODO: advertise if Ex and dx10 able card */
614 D3DPMISCCAPS_FOGANDSPECULARALPHA
| /* Note: documentation of the flag is wrong */
615 D3DPIPECAP(BLEND_EQUATION_SEPARATE
, D3DPMISCCAPS_SEPARATEALPHABLEND
) |
616 D3DPIPECAP(MIXED_COLORBUFFER_FORMATS
, D3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS
) |
617 D3DPMISCCAPS_MRTPOSTPIXELSHADERBLENDING
|
618 D3DPMISCCAPS_FOGVERTEXCLAMPED
;
619 if (!screen
->get_param(screen
, PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION
))
620 pCaps
->PrimitiveMiscCaps
|= D3DPMISCCAPS_CLIPTLVERTS
;
623 D3DPIPECAP(ANISOTROPIC_FILTER
, D3DPRASTERCAPS_ANISOTROPY
) |
624 D3DPRASTERCAPS_COLORPERSPECTIVE
|
625 D3DPRASTERCAPS_DITHER
|
626 D3DPRASTERCAPS_DEPTHBIAS
|
627 D3DPRASTERCAPS_FOGRANGE
|
628 D3DPRASTERCAPS_FOGTABLE
|
629 D3DPRASTERCAPS_FOGVERTEX
|
630 D3DPRASTERCAPS_MIPMAPLODBIAS
|
631 D3DPRASTERCAPS_MULTISAMPLE_TOGGLE
|
632 D3DPRASTERCAPS_SCISSORTEST
|
633 D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS
|
634 /*D3DPRASTERCAPS_WBUFFER |*/
635 D3DPRASTERCAPS_WFOG
|
636 /*D3DPRASTERCAPS_ZBUFFERLESSHSR |*/
637 D3DPRASTERCAPS_ZFOG
|
638 D3DPRASTERCAPS_ZTEST
;
640 pCaps
->ZCmpCaps
= D3DPCMPCAPS_NEVER
|
643 D3DPCMPCAPS_LESSEQUAL
|
644 D3DPCMPCAPS_GREATER
|
645 D3DPCMPCAPS_NOTEQUAL
|
646 D3DPCMPCAPS_GREATEREQUAL
|
649 pCaps
->SrcBlendCaps
= D3DPBLENDCAPS_ZERO
|
651 D3DPBLENDCAPS_SRCCOLOR
|
652 D3DPBLENDCAPS_INVSRCCOLOR
|
653 D3DPBLENDCAPS_SRCALPHA
|
654 D3DPBLENDCAPS_INVSRCALPHA
|
655 D3DPBLENDCAPS_DESTALPHA
|
656 D3DPBLENDCAPS_INVDESTALPHA
|
657 D3DPBLENDCAPS_DESTCOLOR
|
658 D3DPBLENDCAPS_INVDESTCOLOR
|
659 D3DPBLENDCAPS_SRCALPHASAT
|
660 D3DPBLENDCAPS_BOTHSRCALPHA
|
661 D3DPBLENDCAPS_BOTHINVSRCALPHA
|
662 D3DPBLENDCAPS_BLENDFACTOR
|
663 D3DPIPECAP(MAX_DUAL_SOURCE_RENDER_TARGETS
,
664 D3DPBLENDCAPS_INVSRCCOLOR2
|
665 D3DPBLENDCAPS_SRCCOLOR2
);
667 pCaps
->DestBlendCaps
= pCaps
->SrcBlendCaps
;
669 pCaps
->AlphaCmpCaps
= D3DPCMPCAPS_NEVER
|
672 D3DPCMPCAPS_LESSEQUAL
|
673 D3DPCMPCAPS_GREATER
|
674 D3DPCMPCAPS_NOTEQUAL
|
675 D3DPCMPCAPS_GREATEREQUAL
|
678 /* FLAT caps not legal for D3D9. */
679 pCaps
->ShadeCaps
= D3DPSHADECAPS_COLORGOURAUDRGB
|
680 D3DPSHADECAPS_SPECULARGOURAUDRGB
|
681 D3DPSHADECAPS_ALPHAGOURAUDBLEND
|
682 D3DPSHADECAPS_FOGGOURAUD
;
685 D3DPTEXTURECAPS_ALPHA
|
686 D3DPTEXTURECAPS_ALPHAPALETTE
|
687 D3DPTEXTURECAPS_PERSPECTIVE
|
688 D3DPTEXTURECAPS_PROJECTED
|
689 D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
|
690 D3DPTEXTURECAPS_CUBEMAP
|
691 D3DPTEXTURECAPS_VOLUMEMAP
|
692 D3DNPIPECAP(NPOT_TEXTURES
, D3DPTEXTURECAPS_POW2
) |
693 D3DNPIPECAP(NPOT_TEXTURES
, D3DPTEXTURECAPS_NONPOW2CONDITIONAL
) |
694 D3DNPIPECAP(NPOT_TEXTURES
, D3DPTEXTURECAPS_CUBEMAP_POW2
) |
695 D3DNPIPECAP(NPOT_TEXTURES
, D3DPTEXTURECAPS_VOLUMEMAP_POW2
) |
696 D3DPIPECAP(MAX_TEXTURE_2D_SIZE
, D3DPTEXTURECAPS_MIPMAP
) |
697 D3DPIPECAP(MAX_TEXTURE_3D_LEVELS
, D3DPTEXTURECAPS_MIPVOLUMEMAP
) |
698 D3DPIPECAP(MAX_TEXTURE_CUBE_LEVELS
, D3DPTEXTURECAPS_MIPCUBEMAP
);
700 pCaps
->TextureFilterCaps
=
701 D3DPTFILTERCAPS_MINFPOINT
|
702 D3DPTFILTERCAPS_MINFLINEAR
|
703 D3DPIPECAP(ANISOTROPIC_FILTER
, D3DPTFILTERCAPS_MINFANISOTROPIC
) |
704 /*D3DPTFILTERCAPS_MINFPYRAMIDALQUAD |*/
705 /*D3DPTFILTERCAPS_MINFGAUSSIANQUAD |*/
706 D3DPTFILTERCAPS_MIPFPOINT
|
707 D3DPTFILTERCAPS_MIPFLINEAR
|
708 D3DPTFILTERCAPS_MAGFPOINT
|
709 D3DPTFILTERCAPS_MAGFLINEAR
|
710 D3DPIPECAP(ANISOTROPIC_FILTER
, D3DPTFILTERCAPS_MAGFANISOTROPIC
) |
711 /*D3DPTFILTERCAPS_MAGFPYRAMIDALQUAD |*/
712 /*D3DPTFILTERCAPS_MAGFGAUSSIANQUAD*/0;
714 pCaps
->CubeTextureFilterCaps
= pCaps
->TextureFilterCaps
;
715 pCaps
->VolumeTextureFilterCaps
= pCaps
->TextureFilterCaps
;
717 pCaps
->TextureAddressCaps
=
718 D3DPTADDRESSCAPS_BORDER
|
719 D3DPTADDRESSCAPS_INDEPENDENTUV
|
720 D3DPTADDRESSCAPS_WRAP
|
721 D3DPTADDRESSCAPS_MIRROR
|
722 D3DPTADDRESSCAPS_CLAMP
|
723 D3DPIPECAP(TEXTURE_MIRROR_CLAMP
, D3DPTADDRESSCAPS_MIRRORONCE
);
725 pCaps
->VolumeTextureAddressCaps
= pCaps
->TextureAddressCaps
;
728 D3DLINECAPS_ALPHACMP
|
730 D3DLINECAPS_TEXTURE
|
733 if (screen
->get_paramf(screen
, PIPE_CAPF_MAX_LINE_WIDTH_AA
) > 0.0) {
734 pCaps
->LineCaps
|= D3DLINECAPS_ANTIALIAS
;
737 pCaps
->MaxTextureWidth
=screen
->get_param(screen
,
738 PIPE_CAP_MAX_TEXTURE_2D_SIZE
);
739 pCaps
->MaxTextureHeight
= pCaps
->MaxTextureWidth
;
740 pCaps
->MaxVolumeExtent
=
741 1 << (screen
->get_param(screen
, PIPE_CAP_MAX_TEXTURE_3D_LEVELS
) - 1);
742 /* XXX values from wine */
743 pCaps
->MaxTextureRepeat
= 32768;
744 pCaps
->MaxTextureAspectRatio
= pCaps
->MaxTextureWidth
;
746 pCaps
->MaxAnisotropy
=
747 (DWORD
)screen
->get_paramf(screen
, PIPE_CAPF_MAX_TEXTURE_ANISOTROPY
);
749 /* Values for GeForce 9600 GT */
750 pCaps
->MaxVertexW
= 1e10f
;
751 pCaps
->GuardBandLeft
= -1e9f
;
752 pCaps
->GuardBandTop
= -1e9f
;
753 pCaps
->GuardBandRight
= 1e9f
;
754 pCaps
->GuardBandBottom
= 1e9f
;
755 pCaps
->ExtentsAdjust
= 0.0f
;
758 D3DSTENCILCAPS_KEEP
|
759 D3DSTENCILCAPS_ZERO
|
760 D3DSTENCILCAPS_REPLACE
|
761 D3DSTENCILCAPS_INCRSAT
|
762 D3DSTENCILCAPS_DECRSAT
|
763 D3DSTENCILCAPS_INVERT
|
764 D3DSTENCILCAPS_INCR
|
765 D3DSTENCILCAPS_DECR
|
766 D3DSTENCILCAPS_TWOSIDED
;
769 8 | /* 8 textures max */
770 /*D3DFVFCAPS_DONOTSTRIPELEMENTS |*/
773 pCaps
->TextureOpCaps
= D3DTEXOPCAPS_DISABLE
|
774 D3DTEXOPCAPS_SELECTARG1
|
775 D3DTEXOPCAPS_SELECTARG2
|
776 D3DTEXOPCAPS_MODULATE
|
777 D3DTEXOPCAPS_MODULATE2X
|
778 D3DTEXOPCAPS_MODULATE4X
|
780 D3DTEXOPCAPS_ADDSIGNED
|
781 D3DTEXOPCAPS_ADDSIGNED2X
|
782 D3DTEXOPCAPS_SUBTRACT
|
783 D3DTEXOPCAPS_ADDSMOOTH
|
784 D3DTEXOPCAPS_BLENDDIFFUSEALPHA
|
785 D3DTEXOPCAPS_BLENDTEXTUREALPHA
|
786 D3DTEXOPCAPS_BLENDFACTORALPHA
|
787 D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
|
788 D3DTEXOPCAPS_BLENDCURRENTALPHA
|
789 D3DTEXOPCAPS_PREMODULATE
|
790 D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
|
791 D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
792 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
|
793 D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
|
794 D3DTEXOPCAPS_BUMPENVMAP
|
795 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
|
796 D3DTEXOPCAPS_DOTPRODUCT3
|
797 D3DTEXOPCAPS_MULTIPLYADD
|
800 pCaps
->MaxTextureBlendStages
= 8; /* XXX wine */
801 (DWORD
)screen
->get_param(screen
, PIPE_CAP_BLEND_EQUATION_SEPARATE
);
802 pCaps
->MaxSimultaneousTextures
= 8;
804 pCaps
->VertexProcessingCaps
= D3DVTXPCAPS_TEXGEN
|
805 D3DVTXPCAPS_TEXGEN_SPHEREMAP
|
806 D3DVTXPCAPS_MATERIALSOURCE7
|
807 D3DVTXPCAPS_DIRECTIONALLIGHTS
|
808 D3DVTXPCAPS_POSITIONALLIGHTS
|
809 D3DVTXPCAPS_LOCALVIEWER
|
810 D3DVTXPCAPS_TWEENING
|
811 /*D3DVTXPCAPS_NO_TEXGEN_NONLOCALVIEWER*/0;
813 pCaps
->MaxActiveLights
= NINE_MAX_LIGHTS_ACTIVE
; /* like GL_LIGHTi */
814 pCaps
->MaxUserClipPlanes
= PIPE_MAX_CLIP_PLANES
;
815 pCaps
->MaxVertexBlendMatrices
= 4; /* 1 vec4 BLENDWEIGHT/INDICES input */
816 pCaps
->MaxVertexBlendMatrixIndex
= 8; /* D3DTS_WORLDMATRIX(0..8) */
818 pCaps
->MaxPointSize
= screen
->get_paramf(screen
, PIPE_CAPF_MAX_POINT_WIDTH
);
820 pCaps
->MaxPrimitiveCount
= 0x555555; /* <- wine, really 0xFFFFFFFF; */
821 pCaps
->MaxVertexIndex
= 0xFFFFFF; /* <- wine, really 0xFFFFFFFF */
823 _min(screen
->get_shader_param(screen
,
824 PIPE_SHADER_VERTEX
, PIPE_SHADER_CAP_MAX_INPUTS
),
827 pCaps
->MaxStreamStride
= screen
->get_param(screen
,
828 PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE
);
830 pCaps
->VertexShaderVersion
= D3DVS_VERSION(3,0);
832 /* VS 2 as well as 3.0 supports a minimum of 256 consts.
833 * Wine and d3d9 drivers for dx1x hw advertise 256. Just as them,
834 * advertise 256. Problem is with hw that can only do 256, because
835 * we need take a few slots for boolean and integer constants. For these
836 * we'll have to fail later if they use complex shaders. */
837 pCaps
->MaxVertexShaderConst
= NINE_MAX_CONST_F
;
839 pCaps
->PixelShaderVersion
= D3DPS_VERSION(3,0);
840 /* Value for GeForce 9600 GT */
841 pCaps
->PixelShader1xMaxValue
= 65504.f
;
843 pCaps
->DevCaps2
= D3DDEVCAPS2_STREAMOFFSET
|
844 D3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET
|
845 D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES
|
846 /*D3DDEVCAPS2_DMAPNPATCH |*/
847 /*D3DDEVCAPS2_ADAPTIVETESSRTPATCH |*/
848 /*D3DDEVCAPS2_ADAPTIVETESSNPATCH |*/
849 /*D3DDEVCAPS2_PRESAMPLEDDMAPNPATCH*/0;
851 pCaps
->MasterAdapterOrdinal
= 0;
852 pCaps
->AdapterOrdinalInGroup
= 0;
853 pCaps
->NumberOfAdaptersInGroup
= 1;
856 pCaps
->MaxNpatchTessellationLevel
= 0.0f
;
857 pCaps
->Reserved5
= 0;
859 /* XXX: use is_format_supported */
860 pCaps
->DeclTypes
= D3DDTCAPS_UBYTE4
|
868 D3DDTCAPS_FLOAT16_2
|
871 pCaps
->NumSimultaneousRTs
=
872 screen
->get_param(screen
, PIPE_CAP_MAX_RENDER_TARGETS
);
873 if (pCaps
->NumSimultaneousRTs
> NINE_MAX_SIMULTANEOUS_RENDERTARGETS
)
874 pCaps
->NumSimultaneousRTs
= NINE_MAX_SIMULTANEOUS_RENDERTARGETS
;
876 pCaps
->StretchRectFilterCaps
= D3DPTFILTERCAPS_MINFPOINT
|
877 D3DPTFILTERCAPS_MINFLINEAR
|
878 D3DPTFILTERCAPS_MAGFPOINT
|
879 D3DPTFILTERCAPS_MAGFLINEAR
;
882 pCaps
->VS20Caps
.Caps
= D3DVS20CAPS_PREDICATION
;
883 pCaps
->VS20Caps
.DynamicFlowControlDepth
= /* XXX is this dynamic ? */
884 screen
->get_shader_param(screen
, PIPE_SHADER_VERTEX
,
885 PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH
);
886 pCaps
->VS20Caps
.NumTemps
=
887 screen
->get_shader_param(screen
, PIPE_SHADER_VERTEX
,
888 PIPE_SHADER_CAP_MAX_TEMPS
);
889 pCaps
->VS20Caps
.StaticFlowControlDepth
= /* XXX is this static ? */
890 screen
->get_shader_param(screen
, PIPE_SHADER_VERTEX
,
891 PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH
);
893 /* also check for values < 0, because get_shader_param may return unsigned */
894 if (pCaps
->VS20Caps
.DynamicFlowControlDepth
> D3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH
895 || pCaps
->VS20Caps
.DynamicFlowControlDepth
< 0)
896 pCaps
->VS20Caps
.DynamicFlowControlDepth
= D3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH
;
897 if (pCaps
->VS20Caps
.StaticFlowControlDepth
> D3DVS20_MAX_STATICFLOWCONTROLDEPTH
898 || pCaps
->VS20Caps
.StaticFlowControlDepth
< 0)
899 pCaps
->VS20Caps
.StaticFlowControlDepth
= D3DVS20_MAX_STATICFLOWCONTROLDEPTH
;
900 if (pCaps
->VS20Caps
.NumTemps
> D3DVS20_MAX_NUMTEMPS
)
901 pCaps
->VS20Caps
.NumTemps
= D3DVS20_MAX_NUMTEMPS
;
902 assert(pCaps
->VS20Caps
.DynamicFlowControlDepth
>= D3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH
);
903 assert(pCaps
->VS20Caps
.StaticFlowControlDepth
>= D3DVS20_MIN_STATICFLOWCONTROLDEPTH
);
904 assert(pCaps
->VS20Caps
.NumTemps
>= D3DVS20_MIN_NUMTEMPS
);
907 pCaps
->PS20Caps
.Caps
= D3DPS20CAPS_ARBITRARYSWIZZLE
|
908 D3DPS20CAPS_GRADIENTINSTRUCTIONS
|
909 D3DPS20CAPS_PREDICATION
;
910 if (screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
911 PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS
) ==
912 screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
913 PIPE_SHADER_CAP_MAX_INSTRUCTIONS
))
914 pCaps
->PS20Caps
.Caps
|= D3DPS20CAPS_NOTEXINSTRUCTIONLIMIT
;
915 if (screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
916 PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS
) ==
917 screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
918 PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS
))
919 pCaps
->PS20Caps
.Caps
|= D3DPS20CAPS_NODEPENDENTREADLIMIT
;
920 pCaps
->PS20Caps
.DynamicFlowControlDepth
= /* XXX is this dynamic ? */
921 screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
922 PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH
);
923 pCaps
->PS20Caps
.NumTemps
=
924 screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
925 PIPE_SHADER_CAP_MAX_TEMPS
);
926 pCaps
->PS20Caps
.StaticFlowControlDepth
= /* XXX is this static ? */
927 screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
928 PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH
);
929 pCaps
->PS20Caps
.NumInstructionSlots
=
930 screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
931 PIPE_SHADER_CAP_MAX_INSTRUCTIONS
);
933 if (pCaps
->PS20Caps
.DynamicFlowControlDepth
> D3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH
934 || pCaps
->PS20Caps
.DynamicFlowControlDepth
< 0)
935 pCaps
->PS20Caps
.DynamicFlowControlDepth
= D3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH
;
936 if (pCaps
->PS20Caps
.StaticFlowControlDepth
> D3DPS20_MAX_STATICFLOWCONTROLDEPTH
937 || pCaps
->PS20Caps
.StaticFlowControlDepth
< 0)
938 pCaps
->PS20Caps
.StaticFlowControlDepth
= D3DPS20_MAX_STATICFLOWCONTROLDEPTH
;
939 if (pCaps
->PS20Caps
.NumTemps
> D3DPS20_MAX_NUMTEMPS
)
940 pCaps
->PS20Caps
.NumTemps
= D3DPS20_MAX_NUMTEMPS
;
941 if (pCaps
->PS20Caps
.NumInstructionSlots
> D3DPS20_MAX_NUMINSTRUCTIONSLOTS
)
942 pCaps
->PS20Caps
.NumInstructionSlots
= D3DPS20_MAX_NUMINSTRUCTIONSLOTS
;
943 assert(pCaps
->PS20Caps
.DynamicFlowControlDepth
>= D3DPS20_MIN_DYNAMICFLOWCONTROLDEPTH
);
944 assert(pCaps
->PS20Caps
.StaticFlowControlDepth
>= D3DPS20_MIN_STATICFLOWCONTROLDEPTH
);
945 assert(pCaps
->PS20Caps
.NumTemps
>= D3DPS20_MIN_NUMTEMPS
);
946 assert(pCaps
->PS20Caps
.NumInstructionSlots
>= D3DPS20_MIN_NUMINSTRUCTIONSLOTS
);
949 if (screen
->get_shader_param(screen
, PIPE_SHADER_VERTEX
,
950 PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS
))
951 pCaps
->VertexTextureFilterCaps
= pCaps
->TextureFilterCaps
&
952 ~(D3DPTFILTERCAPS_MIPFPOINT
|
953 D3DPTFILTERCAPS_MIPFPOINT
); /* XXX */
955 pCaps
->VertexTextureFilterCaps
= 0;
957 pCaps
->MaxVertexShader30InstructionSlots
=
958 screen
->get_shader_param(screen
, PIPE_SHADER_VERTEX
,
959 PIPE_SHADER_CAP_MAX_INSTRUCTIONS
);
960 pCaps
->MaxPixelShader30InstructionSlots
=
961 screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
962 PIPE_SHADER_CAP_MAX_INSTRUCTIONS
);
963 if (pCaps
->MaxVertexShader30InstructionSlots
> D3DMAX30SHADERINSTRUCTIONS
)
964 pCaps
->MaxVertexShader30InstructionSlots
= D3DMAX30SHADERINSTRUCTIONS
;
965 if (pCaps
->MaxPixelShader30InstructionSlots
> D3DMAX30SHADERINSTRUCTIONS
)
966 pCaps
->MaxPixelShader30InstructionSlots
= D3DMAX30SHADERINSTRUCTIONS
;
967 assert(pCaps
->MaxVertexShader30InstructionSlots
>= D3DMIN30SHADERINSTRUCTIONS
);
968 assert(pCaps
->MaxPixelShader30InstructionSlots
>= D3DMIN30SHADERINSTRUCTIONS
);
970 /* 65535 is required, advertise more for GPUs with >= 2048 instruction slots */
971 pCaps
->MaxVShaderInstructionsExecuted
= MAX2(65535, pCaps
->MaxVertexShader30InstructionSlots
* 32);
972 pCaps
->MaxPShaderInstructionsExecuted
= MAX2(65535, pCaps
->MaxPixelShader30InstructionSlots
* 32);
974 if (debug_get_bool_option("NINE_DUMP_CAPS", FALSE
))
975 nine_dump_D3DCAPS9(DBG_CHANNEL
, pCaps
);
981 NineAdapter9_CreateDevice( struct NineAdapter9
*This
,
983 D3DDEVTYPE DeviceType
,
986 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
988 ID3DPresentGroup
*pPresentationGroup
,
989 IDirect3DDevice9
**ppReturnedDeviceInterface
)
991 struct pipe_screen
*screen
;
992 D3DDEVICE_CREATION_PARAMETERS params
;
997 DBG("This=%p RealAdapter=%u DeviceType=%s hFocusWindow=%p "
998 "BehaviourFlags=%x " "pD3D9=%p pPresentationGroup=%p "
999 "ppReturnedDeviceInterface=%p\n", This
,
1000 RealAdapter
, nine_D3DDEVTYPE_to_str(DeviceType
), hFocusWindow
,
1001 BehaviorFlags
, pD3D9
, pPresentationGroup
, ppReturnedDeviceInterface
);
1003 ID3DPresentGroup_GetVersion(pPresentationGroup
, &major
, &minor
);
1005 ERR("Doesn't support the ID3DPresentGroup version %d %d. Expected 1\n",
1007 return D3DERR_NOTAVAILABLE
;
1010 hr
= NineAdapter9_GetScreen(This
, DeviceType
, &screen
);
1012 DBG("Failed to get pipe_screen.\n");
1016 hr
= NineAdapter9_GetDeviceCaps(This
, DeviceType
, &caps
);
1018 DBG("Failed to get device caps.\n");
1022 params
.AdapterOrdinal
= RealAdapter
;
1023 params
.DeviceType
= DeviceType
;
1024 params
.hFocusWindow
= hFocusWindow
;
1025 params
.BehaviorFlags
= BehaviorFlags
;
1027 hr
= NineDevice9_new(screen
, ¶ms
, &caps
, pPresentationParameters
,
1028 pD3D9
, pPresentationGroup
, This
->ctx
, FALSE
, NULL
,
1029 (struct NineDevice9
**)ppReturnedDeviceInterface
,
1032 DBG("Failed to create device.\n");
1035 DBG("NineDevice9 created successfully.\n");
1041 NineAdapter9_CreateDeviceEx( struct NineAdapter9
*This
,
1043 D3DDEVTYPE DeviceType
,
1045 DWORD BehaviorFlags
,
1046 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
1047 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
1048 IDirect3D9Ex
*pD3D9Ex
,
1049 ID3DPresentGroup
*pPresentationGroup
,
1050 IDirect3DDevice9Ex
**ppReturnedDeviceInterface
)
1052 struct pipe_screen
*screen
;
1053 D3DDEVICE_CREATION_PARAMETERS params
;
1058 DBG("This=%p RealAdapter=%u DeviceType=%s hFocusWindow=%p "
1059 "BehaviourFlags=%x " "pD3D9Ex=%p pPresentationGroup=%p "
1060 "ppReturnedDeviceInterface=%p\n", This
,
1061 RealAdapter
, nine_D3DDEVTYPE_to_str(DeviceType
), hFocusWindow
,
1062 BehaviorFlags
, pD3D9Ex
, pPresentationGroup
, ppReturnedDeviceInterface
);
1064 ID3DPresentGroup_GetVersion(pPresentationGroup
, &major
, &minor
);
1066 ERR("Doesn't support the ID3DPresentGroup version %d %d. Expected 1\n",
1068 return D3DERR_NOTAVAILABLE
;
1071 hr
= NineAdapter9_GetScreen(This
, DeviceType
, &screen
);
1073 DBG("Failed to get pipe_screen.\n");
1077 hr
= NineAdapter9_GetDeviceCaps(This
, DeviceType
, &caps
);
1079 DBG("Failed to get device caps.\n");
1083 params
.AdapterOrdinal
= RealAdapter
;
1084 params
.DeviceType
= DeviceType
;
1085 params
.hFocusWindow
= hFocusWindow
;
1086 params
.BehaviorFlags
= BehaviorFlags
;
1088 hr
= NineDevice9Ex_new(screen
, ¶ms
, &caps
, pPresentationParameters
,
1089 pFullscreenDisplayMode
,
1090 pD3D9Ex
, pPresentationGroup
, This
->ctx
,
1091 (struct NineDevice9Ex
**)ppReturnedDeviceInterface
,
1094 DBG("Failed to create device.\n");
1097 DBG("NineDevice9Ex created successfully.\n");
1102 ID3DAdapter9Vtbl NineAdapter9_vtable
= {
1103 (void *)NineUnknown_QueryInterface
,
1104 (void *)NineUnknown_AddRef
,
1105 (void *)NineUnknown_Release
,
1106 (void *)NineAdapter9_GetAdapterIdentifier
,
1107 (void *)NineAdapter9_CheckDeviceType
,
1108 (void *)NineAdapter9_CheckDeviceFormat
,
1109 (void *)NineAdapter9_CheckDeviceMultiSampleType
,
1110 (void *)NineAdapter9_CheckDepthStencilMatch
,
1111 (void *)NineAdapter9_CheckDeviceFormatConversion
,
1112 (void *)NineAdapter9_GetDeviceCaps
,
1113 (void *)NineAdapter9_CreateDevice
,
1114 (void *)NineAdapter9_CreateDeviceEx
1117 static const GUID
*NineAdapter9_IIDs
[] = {
1124 NineAdapter9_new( struct d3dadapter9_context
*pCTX
,
1125 struct NineAdapter9
**ppOut
)
1127 NINE_NEW(Adapter9
, ppOut
, FALSE
, /* args */ pCTX
);