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 "stateblock9.h"
26 #include "swapchain9.h"
27 #include "swapchain9ex.h"
28 #include "indexbuffer9.h"
29 #include "vertexbuffer9.h"
30 #include "vertexdeclaration9.h"
31 #include "vertexshader9.h"
32 #include "pixelshader9.h"
35 #include "cubetexture9.h"
36 #include "volumetexture9.h"
37 #include "nine_helpers.h"
38 #include "nine_pipe.h"
40 #include "nine_dump.h"
42 #include "pipe/p_screen.h"
43 #include "pipe/p_context.h"
44 #include "util/u_math.h"
45 #include "util/u_inlines.h"
46 #include "util/u_hash_table.h"
47 #include "util/u_format.h"
48 #include "util/u_surface.h"
49 #include "util/u_upload_mgr.h"
50 #include "hud/hud_context.h"
52 #include "cso_cache/cso_context.h"
54 #define DBG_CHANNEL DBG_DEVICE
57 NineDevice9_SetDefaultState( struct NineDevice9
*This
, boolean is_reset
)
59 struct NineSurface9
*refSurf
= NULL
;
61 DBG("This=%p is_reset=%d\n", This
, (int) is_reset
);
63 assert(!This
->is_recording
);
65 nine_state_set_defaults(This
, &This
->caps
, is_reset
);
67 This
->state
.viewport
.X
= 0;
68 This
->state
.viewport
.Y
= 0;
69 This
->state
.viewport
.Width
= 0;
70 This
->state
.viewport
.Height
= 0;
72 This
->state
.scissor
.minx
= 0;
73 This
->state
.scissor
.miny
= 0;
74 This
->state
.scissor
.maxx
= 0xffff;
75 This
->state
.scissor
.maxy
= 0xffff;
77 if (This
->nswapchains
&& This
->swapchains
[0]->params
.BackBufferCount
)
78 refSurf
= This
->swapchains
[0]->buffers
[0];
81 This
->state
.viewport
.Width
= refSurf
->desc
.Width
;
82 This
->state
.viewport
.Height
= refSurf
->desc
.Height
;
83 This
->state
.scissor
.maxx
= refSurf
->desc
.Width
;
84 This
->state
.scissor
.maxy
= refSurf
->desc
.Height
;
87 if (This
->nswapchains
&& This
->swapchains
[0]->params
.EnableAutoDepthStencil
)
88 This
->state
.rs
[D3DRS_ZENABLE
] = TRUE
;
89 if (This
->state
.rs
[D3DRS_ZENABLE
])
90 NineDevice9_SetDepthStencilSurface(
91 This
, (IDirect3DSurface9
*)This
->swapchains
[0]->zsbuf
);
95 NineDevice9_RestoreNonCSOState( struct NineDevice9
*This
, unsigned mask
)
97 struct pipe_context
*pipe
= This
->pipe
;
99 DBG("This=%p mask=%u\n", This
, mask
);
102 struct pipe_constant_buffer cb
;
103 cb
.buffer_offset
= 0;
105 if (This
->prefer_user_constbuf
) {
107 cb
.user_buffer
= This
->state
.vs_const_f
;
109 cb
.buffer
= This
->constbuf_vs
;
110 cb
.user_buffer
= NULL
;
112 cb
.buffer_size
= This
->vs_const_size
;
113 pipe
->set_constant_buffer(pipe
, PIPE_SHADER_VERTEX
, 0, &cb
);
115 if (This
->prefer_user_constbuf
) {
116 cb
.user_buffer
= This
->state
.ps_const_f
;
118 cb
.buffer
= This
->constbuf_ps
;
120 cb
.buffer_size
= This
->ps_const_size
;
121 pipe
->set_constant_buffer(pipe
, PIPE_SHADER_FRAGMENT
, 0, &cb
);
125 struct pipe_poly_stipple stipple
;
126 memset(&stipple
, ~0, sizeof(stipple
));
127 pipe
->set_polygon_stipple(pipe
, &stipple
);
130 This
->state
.changed
.group
= NINE_STATE_ALL
;
131 This
->state
.changed
.vtxbuf
= (1ULL << This
->caps
.MaxStreams
) - 1;
132 This
->state
.changed
.ucp
= (1 << PIPE_MAX_CLIP_PLANES
) - 1;
133 This
->state
.changed
.texture
= NINE_PS_SAMPLERS_MASK
| NINE_VS_SAMPLERS_MASK
;
136 #define GET_PCAP(n) pScreen->get_param(pScreen, PIPE_CAP_##n)
138 NineDevice9_ctor( struct NineDevice9
*This
,
139 struct NineUnknownParams
*pParams
,
140 struct pipe_screen
*pScreen
,
141 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
143 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
145 ID3DPresentGroup
*pPresentationGroup
,
146 struct d3dadapter9_context
*pCTX
,
148 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
)
151 HRESULT hr
= NineUnknown_ctor(&This
->base
, pParams
);
153 DBG("This=%p pParams=%p pScreen=%p pCreationParameters=%p pCaps=%p pPresentationParameters=%p "
154 "pD3D9=%p pPresentationGroup=%p pCTX=%p ex=%d pFullscreenDisplayMode=%p\n",
155 This
, pParams
, pScreen
, pCreationParameters
, pCaps
, pPresentationParameters
, pD3D9
,
156 pPresentationGroup
, pCTX
, (int) ex
, pFullscreenDisplayMode
);
158 if (FAILED(hr
)) { return hr
; }
160 list_inithead(&This
->update_textures
);
162 This
->screen
= pScreen
;
165 This
->params
= *pCreationParameters
;
167 This
->present
= pPresentationGroup
;
168 IDirect3D9_AddRef(This
->d3d9
);
169 ID3DPresentGroup_AddRef(This
->present
);
171 This
->pipe
= This
->screen
->context_create(This
->screen
, NULL
);
172 if (!This
->pipe
) { return E_OUTOFMEMORY
; } /* guess */
174 This
->cso
= cso_create_context(This
->pipe
);
175 if (!This
->cso
) { return E_OUTOFMEMORY
; } /* also a guess */
177 /* Create first, it messes up our state. */
178 This
->hud
= hud_create(This
->pipe
, This
->cso
); /* NULL result is fine */
180 /* create implicit swapchains */
181 This
->nswapchains
= ID3DPresentGroup_GetMultiheadCount(This
->present
);
182 This
->swapchains
= CALLOC(This
->nswapchains
,
183 sizeof(struct NineSwapChain9
*));
184 if (!This
->swapchains
) { return E_OUTOFMEMORY
; }
186 for (i
= 0; i
< This
->nswapchains
; ++i
) {
187 ID3DPresent
*present
;
189 hr
= ID3DPresentGroup_GetPresent(This
->present
, i
, &present
);
194 D3DDISPLAYMODEEX
*mode
= NULL
;
195 struct NineSwapChain9Ex
**ret
=
196 (struct NineSwapChain9Ex
**)&This
->swapchains
[i
];
198 if (pFullscreenDisplayMode
) mode
= &(pFullscreenDisplayMode
[i
]);
199 /* when this is a Device9Ex, it should create SwapChain9Exs */
200 hr
= NineSwapChain9Ex_new(This
, TRUE
, present
,
201 &pPresentationParameters
[i
], pCTX
,
202 This
->params
.hFocusWindow
, mode
, ret
);
204 hr
= NineSwapChain9_new(This
, TRUE
, present
,
205 &pPresentationParameters
[i
], pCTX
,
206 This
->params
.hFocusWindow
,
207 &This
->swapchains
[i
]);
210 ID3DPresent_Release(present
);
213 NineUnknown_ConvertRefToBind(NineUnknown(This
->swapchains
[i
]));
215 hr
= NineSwapChain9_GetBackBuffer(This
->swapchains
[i
], 0,
216 D3DBACKBUFFER_TYPE_MONO
,
217 (IDirect3DSurface9
**)
221 NineUnknown_ConvertRefToBind(NineUnknown(This
->state
.rt
[i
]));
224 This
->cursor
.software
= FALSE
;
225 This
->cursor
.hotspot
.x
= -1;
226 This
->cursor
.hotspot
.y
= -1;
228 struct pipe_resource tmpl
;
229 tmpl
.target
= PIPE_TEXTURE_2D
;
230 tmpl
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
237 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
238 tmpl
.bind
= PIPE_BIND_CURSOR
| PIPE_BIND_SAMPLER_VIEW
;
241 This
->cursor
.image
= pScreen
->resource_create(pScreen
, &tmpl
);
242 if (!This
->cursor
.image
)
243 return D3DERR_OUTOFVIDEOMEMORY
;
246 /* Create constant buffers. */
248 struct pipe_resource tmpl
;
249 unsigned max_const_vs
, max_const_ps
;
251 /* vs 3.0: >= 256 float constants, but for cards with exactly 256 slots,
252 * we have to take in some more slots for int and bool*/
253 max_const_vs
= _min(pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
,
254 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
) /
257 /* ps 3.0: 224 float constants. All cards supported support at least
258 * 256 constants for ps */
259 max_const_ps
= NINE_MAX_CONST_F_PS3
+ (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
261 This
->max_vs_const_f
= max_const_vs
-
262 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
263 This
->max_ps_const_f
= max_const_ps
-
264 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
266 This
->vs_const_size
= max_const_vs
* sizeof(float[4]);
267 This
->ps_const_size
= max_const_ps
* sizeof(float[4]);
268 /* Include space for I,B constants for user constbuf. */
269 This
->state
.vs_const_f
= CALLOC(This
->vs_const_size
, 1);
270 This
->state
.ps_const_f
= CALLOC(This
->ps_const_size
, 1);
271 This
->state
.vs_lconstf_temp
= CALLOC(This
->vs_const_size
,1);
272 if (!This
->state
.vs_const_f
|| !This
->state
.ps_const_f
||
273 !This
->state
.vs_lconstf_temp
)
274 return E_OUTOFMEMORY
;
276 if (strstr(pScreen
->get_name(pScreen
), "AMD") ||
277 strstr(pScreen
->get_name(pScreen
), "ATI"))
278 This
->prefer_user_constbuf
= TRUE
;
280 tmpl
.target
= PIPE_BUFFER
;
281 tmpl
.format
= PIPE_FORMAT_R8_UNORM
;
287 tmpl
.usage
= PIPE_USAGE_DYNAMIC
;
288 tmpl
.bind
= PIPE_BIND_CONSTANT_BUFFER
;
291 tmpl
.width0
= This
->vs_const_size
;
292 This
->constbuf_vs
= pScreen
->resource_create(pScreen
, &tmpl
);
294 tmpl
.width0
= This
->ps_const_size
;
295 This
->constbuf_ps
= pScreen
->resource_create(pScreen
, &tmpl
);
297 if (!This
->constbuf_vs
|| !This
->constbuf_ps
)
298 return E_OUTOFMEMORY
;
301 /* allocate dummy texture/sampler for when there are missing ones bound */
303 struct pipe_resource tmplt
;
304 struct pipe_sampler_view templ
;
306 tmplt
.target
= PIPE_TEXTURE_2D
;
310 tmplt
.last_level
= 0;
311 tmplt
.array_size
= 1;
312 tmplt
.usage
= PIPE_USAGE_DEFAULT
;
314 tmplt
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
315 tmplt
.bind
= PIPE_BIND_SAMPLER_VIEW
;
316 tmplt
.nr_samples
= 0;
318 This
->dummy_texture
= This
->screen
->resource_create(This
->screen
, &tmplt
);
319 if (!This
->dummy_texture
)
320 return D3DERR_DRIVERINTERNALERROR
;
322 templ
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
323 templ
.u
.tex
.first_layer
= 0;
324 templ
.u
.tex
.last_layer
= 0;
325 templ
.u
.tex
.first_level
= 0;
326 templ
.u
.tex
.last_level
= 0;
327 templ
.swizzle_r
= PIPE_SWIZZLE_ZERO
;
328 templ
.swizzle_g
= PIPE_SWIZZLE_ZERO
;
329 templ
.swizzle_b
= PIPE_SWIZZLE_ZERO
;
330 templ
.swizzle_a
= PIPE_SWIZZLE_ONE
;
331 templ
.target
= This
->dummy_texture
->target
;
333 This
->dummy_sampler
= This
->pipe
->create_sampler_view(This
->pipe
, This
->dummy_texture
, &templ
);
334 if (!This
->dummy_sampler
)
335 return D3DERR_DRIVERINTERNALERROR
;
338 /* Allocate upload helper for drivers that suck (from st pov ;). */
342 This
->driver_caps
.user_vbufs
= GET_PCAP(USER_VERTEX_BUFFERS
);
343 This
->driver_caps
.user_ibufs
= GET_PCAP(USER_INDEX_BUFFERS
);
345 if (!This
->driver_caps
.user_vbufs
) bind
|= PIPE_BIND_VERTEX_BUFFER
;
346 if (!This
->driver_caps
.user_ibufs
) bind
|= PIPE_BIND_INDEX_BUFFER
;
348 This
->upload
= u_upload_create(This
->pipe
, 1 << 20, 4, bind
);
351 This
->driver_caps
.window_space_position_support
= GET_PCAP(TGSI_VS_WINDOW_SPACE_POSITION
);
352 This
->driver_caps
.vs_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
, PIPE_SHADER_CAP_INTEGERS
);
353 This
->driver_caps
.ps_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_FRAGMENT
, PIPE_SHADER_CAP_INTEGERS
);
355 nine_ff_init(This
); /* initialize fixed function code */
357 NineDevice9_SetDefaultState(This
, FALSE
);
358 NineDevice9_RestoreNonCSOState(This
, ~0);
360 This
->update
= &This
->state
;
361 nine_update_state(This
, ~0);
363 ID3DPresentGroup_Release(This
->present
);
370 NineDevice9_dtor( struct NineDevice9
*This
)
374 DBG("This=%p\n", This
);
376 if (This
->pipe
&& This
->cso
)
377 nine_pipe_context_clear(This
);
379 nine_state_clear(&This
->state
, TRUE
);
382 u_upload_destroy(This
->upload
);
384 nine_bind(&This
->record
, NULL
);
386 pipe_sampler_view_reference(&This
->dummy_sampler
, NULL
);
387 pipe_resource_reference(&This
->dummy_texture
, NULL
);
388 pipe_resource_reference(&This
->constbuf_vs
, NULL
);
389 pipe_resource_reference(&This
->constbuf_ps
, NULL
);
390 FREE(This
->state
.vs_const_f
);
391 FREE(This
->state
.ps_const_f
);
392 FREE(This
->state
.vs_lconstf_temp
);
394 if (This
->swapchains
) {
395 for (i
= 0; i
< This
->nswapchains
; ++i
)
396 NineUnknown_Unbind(NineUnknown(This
->swapchains
[i
]));
397 FREE(This
->swapchains
);
403 cso_destroy_context(This
->cso
);
405 if (This
->pipe
->destroy
) { This
->pipe
->destroy(This
->pipe
); }
408 if (This
->present
) { ID3DPresentGroup_Release(This
->present
); }
409 if (This
->d3d9
) { IDirect3D9_Release(This
->d3d9
); }
411 NineUnknown_dtor(&This
->base
);
415 NineDevice9_GetScreen( struct NineDevice9
*This
)
420 struct pipe_context
*
421 NineDevice9_GetPipe( struct NineDevice9
*This
)
427 NineDevice9_GetCSO( struct NineDevice9
*This
)
433 NineDevice9_GetCaps( struct NineDevice9
*This
)
439 NineDevice9_PauseRecording( struct NineDevice9
*This
)
442 This
->update
= &This
->state
;
443 This
->is_recording
= FALSE
;
448 NineDevice9_ResumeRecording( struct NineDevice9
*This
)
451 This
->update
= &This
->record
->state
;
452 This
->is_recording
= TRUE
;
457 NineDevice9_TestCooperativeLevel( struct NineDevice9
*This
)
459 return D3D_OK
; /* TODO */
463 NineDevice9_GetAvailableTextureMem( struct NineDevice9
*This
)
465 const unsigned mem
= This
->screen
->get_param(This
->screen
, PIPE_CAP_VIDEO_MEMORY
);
473 NineDevice9_EvictManagedResources( struct NineDevice9
*This
)
475 /* We don't really need to do anything here, but might want to free up
476 * the GPU virtual address space by killing pipe_resources.
482 NineDevice9_GetDirect3D( struct NineDevice9
*This
,
483 IDirect3D9
**ppD3D9
)
485 user_assert(ppD3D9
!= NULL
, E_POINTER
);
486 IDirect3D9_AddRef(This
->d3d9
);
487 *ppD3D9
= This
->d3d9
;
492 NineDevice9_GetDeviceCaps( struct NineDevice9
*This
,
495 user_assert(pCaps
!= NULL
, D3DERR_INVALIDCALL
);
501 NineDevice9_GetDisplayMode( struct NineDevice9
*This
,
503 D3DDISPLAYMODE
*pMode
)
505 DBG("This=%p iSwapChain=%u pMode=%p\n", This
, iSwapChain
, pMode
);
507 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
509 return NineSwapChain9_GetDisplayMode(This
->swapchains
[iSwapChain
], pMode
);
513 NineDevice9_GetCreationParameters( struct NineDevice9
*This
,
514 D3DDEVICE_CREATION_PARAMETERS
*pParameters
)
516 user_assert(pParameters
!= NULL
, D3DERR_INVALIDCALL
);
517 *pParameters
= This
->params
;
522 NineDevice9_SetCursorProperties( struct NineDevice9
*This
,
525 IDirect3DSurface9
*pCursorBitmap
)
527 /* TODO: hardware cursor */
528 struct NineSurface9
*surf
= NineSurface9(pCursorBitmap
);
529 struct pipe_context
*pipe
= This
->pipe
;
531 struct pipe_transfer
*transfer
;
534 DBG_FLAG(DBG_SWAPCHAIN
, "This=%p XHotSpot=%u YHotSpot=%u "
535 "pCursorBitmap=%p\n", This
, XHotSpot
, YHotSpot
, pCursorBitmap
);
537 user_assert(pCursorBitmap
, D3DERR_INVALIDCALL
);
539 This
->cursor
.w
= MIN2(surf
->desc
.Width
, This
->cursor
.image
->width0
);
540 This
->cursor
.h
= MIN2(surf
->desc
.Height
, This
->cursor
.image
->height0
);
542 u_box_origin_2d(This
->cursor
.w
, This
->cursor
.h
, &box
);
544 ptr
= pipe
->transfer_map(pipe
, This
->cursor
.image
, 0,
545 PIPE_TRANSFER_WRITE
|
546 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
549 ret_err("Failed to update cursor image.\n", D3DERR_DRIVERINTERNALERROR
);
551 This
->cursor
.hotspot
.x
= XHotSpot
;
552 This
->cursor
.hotspot
.y
= YHotSpot
;
554 /* Copy cursor image to internal storage. */
558 const struct util_format_description
*sfmt
=
559 util_format_description(surf
->base
.info
.format
);
562 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, D3DLOCK_READONLY
);
564 ret_err("Failed to map cursor source image.\n",
565 D3DERR_DRIVERINTERNALERROR
);
567 sfmt
->unpack_rgba_8unorm(ptr
, transfer
->stride
,
568 lock
.pBits
, lock
.Pitch
,
569 This
->cursor
.w
, This
->cursor
.h
);
571 if (!This
->cursor
.software
&&
572 This
->cursor
.w
== 32 && This
->cursor
.h
== 32)
573 ID3DPresent_SetCursor(This
->swapchains
[0]->present
,
574 lock
.pBits
, &This
->cursor
.hotspot
,
575 This
->cursor
.visible
);
577 NineSurface9_UnlockRect(surf
);
579 pipe
->transfer_unmap(pipe
, transfer
);
585 NineDevice9_SetCursorPosition( struct NineDevice9
*This
,
590 struct NineSwapChain9
*swap
= This
->swapchains
[0];
592 DBG("This=%p X=%d Y=%d Flags=%d\n", This
, X
, Y
, Flags
);
594 This
->cursor
.pos
.x
= X
;
595 This
->cursor
.pos
.y
= Y
;
597 if (!This
->cursor
.software
)
598 ID3DPresent_SetCursorPos(swap
->present
, &This
->cursor
.pos
);
602 NineDevice9_ShowCursor( struct NineDevice9
*This
,
605 BOOL old
= This
->cursor
.visible
;
607 DBG("This=%p bShow=%d\n", This
, (int) bShow
);
609 This
->cursor
.visible
= bShow
&& (This
->cursor
.hotspot
.x
!= -1);
610 if (!This
->cursor
.software
)
611 ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, bShow
);
617 NineDevice9_CreateAdditionalSwapChain( struct NineDevice9
*This
,
618 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
619 IDirect3DSwapChain9
**pSwapChain
)
621 struct NineSwapChain9
*swapchain
, *tmplt
= This
->swapchains
[0];
622 ID3DPresent
*present
;
625 DBG("This=%p pPresentationParameters=%p pSwapChain=%p\n",
626 This
, pPresentationParameters
, pSwapChain
);
628 user_assert(pPresentationParameters
, D3DERR_INVALIDCALL
);
630 hr
= ID3DPresentGroup_CreateAdditionalPresent(This
->present
, pPresentationParameters
, &present
);
635 hr
= NineSwapChain9_new(This
, FALSE
, present
, pPresentationParameters
,
637 tmplt
->params
.hDeviceWindow
,
642 *pSwapChain
= (IDirect3DSwapChain9
*)swapchain
;
647 NineDevice9_GetSwapChain( struct NineDevice9
*This
,
649 IDirect3DSwapChain9
**pSwapChain
)
651 user_assert(pSwapChain
!= NULL
, D3DERR_INVALIDCALL
);
654 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
656 NineUnknown_AddRef(NineUnknown(This
->swapchains
[iSwapChain
]));
657 *pSwapChain
= (IDirect3DSwapChain9
*)This
->swapchains
[iSwapChain
];
663 NineDevice9_GetNumberOfSwapChains( struct NineDevice9
*This
)
665 return This
->nswapchains
;
669 NineDevice9_Reset( struct NineDevice9
*This
,
670 D3DPRESENT_PARAMETERS
*pPresentationParameters
)
675 DBG("This=%p pPresentationParameters=%p\n", This
, pPresentationParameters
);
677 for (i
= 0; i
< This
->nswapchains
; ++i
) {
678 D3DPRESENT_PARAMETERS
*params
= &pPresentationParameters
[i
];
679 hr
= NineSwapChain9_Resize(This
->swapchains
[i
], params
, NULL
);
681 return (hr
== D3DERR_OUTOFVIDEOMEMORY
) ? hr
: D3DERR_DEVICELOST
;
684 nine_pipe_context_clear(This
);
685 nine_state_clear(&This
->state
, TRUE
);
687 NineDevice9_SetDefaultState(This
, TRUE
);
688 NineDevice9_SetRenderTarget(
689 This
, 0, (IDirect3DSurface9
*)This
->swapchains
[0]->buffers
[0]);
690 /* XXX: better use GetBackBuffer here ? */
696 NineDevice9_Present( struct NineDevice9
*This
,
697 const RECT
*pSourceRect
,
698 const RECT
*pDestRect
,
699 HWND hDestWindowOverride
,
700 const RGNDATA
*pDirtyRegion
)
705 DBG("This=%p pSourceRect=%p pDestRect=%p hDestWindowOverride=%p pDirtyRegion=%p\n",
706 This
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
708 /* XXX is this right? */
709 for (i
= 0; i
< This
->nswapchains
; ++i
) {
710 hr
= NineSwapChain9_Present(This
->swapchains
[i
], pSourceRect
, pDestRect
,
711 hDestWindowOverride
, pDirtyRegion
, 0);
712 if (FAILED(hr
)) { return hr
; }
719 NineDevice9_GetBackBuffer( struct NineDevice9
*This
,
722 D3DBACKBUFFER_TYPE Type
,
723 IDirect3DSurface9
**ppBackBuffer
)
725 user_assert(ppBackBuffer
!= NULL
, D3DERR_INVALIDCALL
);
726 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
728 return NineSwapChain9_GetBackBuffer(This
->swapchains
[iSwapChain
],
729 iBackBuffer
, Type
, ppBackBuffer
);
733 NineDevice9_GetRasterStatus( struct NineDevice9
*This
,
735 D3DRASTER_STATUS
*pRasterStatus
)
737 user_assert(pRasterStatus
!= NULL
, D3DERR_INVALIDCALL
);
738 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
740 return NineSwapChain9_GetRasterStatus(This
->swapchains
[iSwapChain
],
745 NineDevice9_SetDialogBoxMode( struct NineDevice9
*This
,
746 BOOL bEnableDialogs
)
748 STUB(D3DERR_INVALIDCALL
);
752 NineDevice9_SetGammaRamp( struct NineDevice9
*This
,
755 const D3DGAMMARAMP
*pRamp
)
757 DBG("This=%p iSwapChain=%u Flags=%x pRamp=%p\n", This
,
758 iSwapChain
, Flags
, pRamp
);
760 user_warn(iSwapChain
>= This
->nswapchains
);
763 if (pRamp
&& (iSwapChain
< This
->nswapchains
)) {
764 struct NineSwapChain9
*swap
= This
->swapchains
[iSwapChain
];
765 swap
->gamma
= *pRamp
;
766 ID3DPresent_SetGammaRamp(swap
->present
, pRamp
, swap
->params
.hDeviceWindow
);
771 NineDevice9_GetGammaRamp( struct NineDevice9
*This
,
773 D3DGAMMARAMP
*pRamp
)
775 DBG("This=%p iSwapChain=%u pRamp=%p\n", This
, iSwapChain
, pRamp
);
777 user_warn(iSwapChain
>= This
->nswapchains
);
780 if (pRamp
&& (iSwapChain
< This
->nswapchains
))
781 *pRamp
= This
->swapchains
[iSwapChain
]->gamma
;
785 NineDevice9_CreateTexture( struct NineDevice9
*This
,
792 IDirect3DTexture9
**ppTexture
,
793 HANDLE
*pSharedHandle
)
795 struct NineTexture9
*tex
;
798 DBG("This=%p Width=%u Height=%u Levels=%u Usage=%s Format=%s Pool=%s "
799 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Levels
,
800 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
801 nine_D3DPOOL_to_str(Pool
), ppTexture
, pSharedHandle
);
803 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DMAP
|
804 D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
805 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
;
808 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
809 user_assert(!pSharedHandle
|| This
->ex
, D3DERR_INVALIDCALL
);
810 /* When is used shared handle, Pool must be
811 * SYSTEMMEM with Levels 1 or DEFAULT with any Levels */
812 user_assert(!pSharedHandle
|| Pool
!= D3DPOOL_SYSTEMMEM
|| Levels
== 1,
814 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_SYSTEMMEM
|| Pool
== D3DPOOL_DEFAULT
,
816 user_assert((Usage
!= D3DUSAGE_AUTOGENMIPMAP
|| Levels
<= 1), D3DERR_INVALIDCALL
);
818 hr
= NineTexture9_new(This
, Width
, Height
, Levels
, Usage
, Format
, Pool
,
819 &tex
, pSharedHandle
);
821 *ppTexture
= (IDirect3DTexture9
*)tex
;
827 NineDevice9_CreateVolumeTexture( struct NineDevice9
*This
,
835 IDirect3DVolumeTexture9
**ppVolumeTexture
,
836 HANDLE
*pSharedHandle
)
838 struct NineVolumeTexture9
*tex
;
841 DBG("This=%p Width=%u Height=%u Depth=%u Levels=%u Usage=%s Format=%s Pool=%s "
842 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Depth
, Levels
,
843 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
844 nine_D3DPOOL_to_str(Pool
), ppVolumeTexture
, pSharedHandle
);
846 Usage
&= D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
847 D3DUSAGE_SOFTWAREPROCESSING
;
849 *ppVolumeTexture
= NULL
;
850 user_assert(Width
&& Height
&& Depth
, D3DERR_INVALIDCALL
);
851 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
853 hr
= NineVolumeTexture9_new(This
, Width
, Height
, Depth
, Levels
,
854 Usage
, Format
, Pool
, &tex
, pSharedHandle
);
856 *ppVolumeTexture
= (IDirect3DVolumeTexture9
*)tex
;
862 NineDevice9_CreateCubeTexture( struct NineDevice9
*This
,
868 IDirect3DCubeTexture9
**ppCubeTexture
,
869 HANDLE
*pSharedHandle
)
871 struct NineCubeTexture9
*tex
;
874 DBG("This=%p EdgeLength=%u Levels=%u Usage=%s Format=%s Pool=%s ppOut=%p "
875 "pSharedHandle=%p\n", This
, EdgeLength
, Levels
,
876 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
877 nine_D3DPOOL_to_str(Pool
), ppCubeTexture
, pSharedHandle
);
879 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DYNAMIC
|
880 D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
881 D3DUSAGE_SOFTWAREPROCESSING
;
883 *ppCubeTexture
= NULL
;
884 user_assert(EdgeLength
, D3DERR_INVALIDCALL
);
885 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
887 hr
= NineCubeTexture9_new(This
, EdgeLength
, Levels
, Usage
, Format
, Pool
,
888 &tex
, pSharedHandle
);
890 *ppCubeTexture
= (IDirect3DCubeTexture9
*)tex
;
896 NineDevice9_CreateVertexBuffer( struct NineDevice9
*This
,
901 IDirect3DVertexBuffer9
**ppVertexBuffer
,
902 HANDLE
*pSharedHandle
)
904 struct NineVertexBuffer9
*buf
;
906 D3DVERTEXBUFFER_DESC desc
;
908 DBG("This=%p Length=%u Usage=%x FVF=%x Pool=%u ppOut=%p pSharedHandle=%p\n",
909 This
, Length
, Usage
, FVF
, Pool
, ppVertexBuffer
, pSharedHandle
);
911 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
913 desc
.Format
= D3DFMT_VERTEXDATA
;
914 desc
.Type
= D3DRTYPE_VERTEXBUFFER
;
916 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
917 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
918 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
|
924 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
925 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
927 hr
= NineVertexBuffer9_new(This
, &desc
, &buf
);
929 *ppVertexBuffer
= (IDirect3DVertexBuffer9
*)buf
;
934 NineDevice9_CreateIndexBuffer( struct NineDevice9
*This
,
939 IDirect3DIndexBuffer9
**ppIndexBuffer
,
940 HANDLE
*pSharedHandle
)
942 struct NineIndexBuffer9
*buf
;
944 D3DINDEXBUFFER_DESC desc
;
946 DBG("This=%p Length=%u Usage=%x Format=%s Pool=%u ppOut=%p "
947 "pSharedHandle=%p\n", This
, Length
, Usage
,
948 d3dformat_to_string(Format
), Pool
, ppIndexBuffer
, pSharedHandle
);
950 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
952 desc
.Format
= Format
;
953 desc
.Type
= D3DRTYPE_INDEXBUFFER
;
955 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
956 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
957 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_WRITEONLY
);
961 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
962 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
964 hr
= NineIndexBuffer9_new(This
, &desc
, &buf
);
966 *ppIndexBuffer
= (IDirect3DIndexBuffer9
*)buf
;
971 create_zs_or_rt_surface(struct NineDevice9
*This
,
972 unsigned type
, /* 0 = RT, 1 = ZS, 2 = plain */
974 UINT Width
, UINT Height
,
976 D3DMULTISAMPLE_TYPE MultiSample
,
977 DWORD MultisampleQuality
,
978 BOOL Discard_or_Lockable
,
979 IDirect3DSurface9
**ppSurface
,
980 HANDLE
*pSharedHandle
)
982 struct NineSurface9
*surface
;
983 struct pipe_screen
*screen
= This
->screen
;
984 struct pipe_resource
*resource
= NULL
;
986 D3DSURFACE_DESC desc
;
987 struct pipe_resource templ
;
989 DBG("This=%p type=%u Pool=%s Width=%u Height=%u Format=%s MS=%u Quality=%u "
990 "Discard_or_Lockable=%i ppSurface=%p pSharedHandle=%p\n",
991 This
, type
, nine_D3DPOOL_to_str(Pool
), Width
, Height
,
992 d3dformat_to_string(Format
), MultiSample
, MultisampleQuality
,
993 Discard_or_Lockable
, ppSurface
, pSharedHandle
);
996 DBG("FIXME Used shared handle! This option isn't probably handled correctly!\n");
998 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
999 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1001 templ
.target
= PIPE_TEXTURE_2D
;
1002 templ
.width0
= Width
;
1003 templ
.height0
= Height
;
1005 templ
.array_size
= 1;
1006 templ
.last_level
= 0;
1007 templ
.nr_samples
= (unsigned)MultiSample
;
1008 templ
.usage
= PIPE_USAGE_DEFAULT
;
1010 templ
.bind
= PIPE_BIND_SAMPLER_VIEW
; /* StretchRect */
1012 case 0: templ
.bind
|= PIPE_BIND_RENDER_TARGET
; break;
1013 case 1: templ
.bind
= d3d9_get_pipe_depth_format_bindings(Format
); break;
1018 templ
.format
= d3d9_to_pipe_format_checked(screen
, Format
, templ
.target
,
1019 templ
.nr_samples
, templ
.bind
,
1022 desc
.Format
= Format
;
1023 desc
.Type
= D3DRTYPE_SURFACE
;
1026 desc
.MultiSampleType
= MultiSample
;
1027 desc
.MultiSampleQuality
= MultisampleQuality
;
1029 desc
.Height
= Height
;
1031 case 0: desc
.Usage
= D3DUSAGE_RENDERTARGET
; break;
1032 case 1: desc
.Usage
= D3DUSAGE_DEPTHSTENCIL
; break;
1036 if (Pool
== D3DPOOL_DEFAULT
&& Format
!= D3DFMT_NULL
) {
1037 /* resource_create doesn't return an error code, so check format here */
1038 user_assert(templ
.format
!= PIPE_FORMAT_NONE
, D3DERR_INVALIDCALL
);
1039 resource
= screen
->resource_create(screen
, &templ
);
1040 user_assert(resource
, D3DERR_OUTOFVIDEOMEMORY
);
1041 if (Discard_or_Lockable
&& (desc
.Usage
& D3DUSAGE_RENDERTARGET
))
1042 resource
->flags
|= NINE_RESOURCE_FLAG_LOCKABLE
;
1046 hr
= NineSurface9_new(This
, NULL
, resource
, NULL
, 0, 0, 0, &desc
, &surface
);
1047 pipe_resource_reference(&resource
, NULL
);
1050 *ppSurface
= (IDirect3DSurface9
*)surface
;
1055 NineDevice9_CreateRenderTarget( struct NineDevice9
*This
,
1059 D3DMULTISAMPLE_TYPE MultiSample
,
1060 DWORD MultisampleQuality
,
1062 IDirect3DSurface9
**ppSurface
,
1063 HANDLE
*pSharedHandle
)
1066 return create_zs_or_rt_surface(This
, 0, D3DPOOL_DEFAULT
,
1067 Width
, Height
, Format
,
1068 MultiSample
, MultisampleQuality
,
1069 Lockable
, ppSurface
, pSharedHandle
);
1073 NineDevice9_CreateDepthStencilSurface( struct NineDevice9
*This
,
1077 D3DMULTISAMPLE_TYPE MultiSample
,
1078 DWORD MultisampleQuality
,
1080 IDirect3DSurface9
**ppSurface
,
1081 HANDLE
*pSharedHandle
)
1084 if (!depth_stencil_format(Format
))
1085 return D3DERR_NOTAVAILABLE
;
1086 return create_zs_or_rt_surface(This
, 1, D3DPOOL_DEFAULT
,
1087 Width
, Height
, Format
,
1088 MultiSample
, MultisampleQuality
,
1089 Discard
, ppSurface
, pSharedHandle
);
1093 NineDevice9_UpdateSurface( struct NineDevice9
*This
,
1094 IDirect3DSurface9
*pSourceSurface
,
1095 const RECT
*pSourceRect
,
1096 IDirect3DSurface9
*pDestinationSurface
,
1097 const POINT
*pDestPoint
)
1099 struct NineSurface9
*dst
= NineSurface9(pDestinationSurface
);
1100 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1102 DBG("This=%p pSourceSurface=%p pDestinationSurface=%p "
1103 "pSourceRect=%p pDestPoint=%p\n", This
,
1104 pSourceSurface
, pDestinationSurface
, pSourceRect
, pDestPoint
);
1106 DBG("pSourceRect = (%u,%u)-(%u,%u)\n",
1107 pSourceRect
->left
, pSourceRect
->top
,
1108 pSourceRect
->right
, pSourceRect
->bottom
);
1110 DBG("pDestPoint = (%u,%u)\n", pDestPoint
->x
, pDestPoint
->y
);
1112 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1113 user_assert(src
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1115 user_assert(dst
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1116 user_assert(src
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1118 return NineSurface9_CopySurface(dst
, src
, pDestPoint
, pSourceRect
);
1122 NineDevice9_UpdateTexture( struct NineDevice9
*This
,
1123 IDirect3DBaseTexture9
*pSourceTexture
,
1124 IDirect3DBaseTexture9
*pDestinationTexture
)
1126 struct NineBaseTexture9
*dstb
= NineBaseTexture9(pDestinationTexture
);
1127 struct NineBaseTexture9
*srcb
= NineBaseTexture9(pSourceTexture
);
1129 unsigned last_level
= dstb
->base
.info
.last_level
;
1131 DBG("This=%p pSourceTexture=%p pDestinationTexture=%p\n", This
,
1132 pSourceTexture
, pDestinationTexture
);
1134 user_assert(pSourceTexture
!= pDestinationTexture
, D3DERR_INVALIDCALL
);
1136 user_assert(dstb
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1137 user_assert(srcb
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1139 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1140 /* Only the first level is updated, the others regenerated. */
1143 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
), D3DERR_INVALIDCALL
);
1146 user_assert(dstb
->base
.type
== srcb
->base
.type
, D3DERR_INVALIDCALL
);
1148 /* TODO: We can restrict the update to the dirty portions of the source.
1149 * Yes, this seems silly, but it's what MSDN says ...
1152 /* Find src level that matches dst level 0: */
1153 user_assert(srcb
->base
.info
.width0
>= dstb
->base
.info
.width0
&&
1154 srcb
->base
.info
.height0
>= dstb
->base
.info
.height0
&&
1155 srcb
->base
.info
.depth0
>= dstb
->base
.info
.depth0
,
1156 D3DERR_INVALIDCALL
);
1157 for (m
= 0; m
<= srcb
->base
.info
.last_level
; ++m
) {
1158 unsigned w
= u_minify(srcb
->base
.info
.width0
, m
);
1159 unsigned h
= u_minify(srcb
->base
.info
.height0
, m
);
1160 unsigned d
= u_minify(srcb
->base
.info
.depth0
, m
);
1162 if (w
== dstb
->base
.info
.width0
&&
1163 h
== dstb
->base
.info
.height0
&&
1164 d
== dstb
->base
.info
.depth0
)
1167 user_assert(m
<= srcb
->base
.info
.last_level
, D3DERR_INVALIDCALL
);
1169 last_level
= MIN2(last_level
, srcb
->base
.info
.last_level
- m
);
1171 if (dstb
->base
.type
== D3DRTYPE_TEXTURE
) {
1172 struct NineTexture9
*dst
= NineTexture9(dstb
);
1173 struct NineTexture9
*src
= NineTexture9(srcb
);
1175 for (l
= 0; l
<= last_level
; ++l
, ++m
)
1176 NineSurface9_CopySurface(dst
->surfaces
[l
],
1177 src
->surfaces
[m
], NULL
, NULL
);
1179 if (dstb
->base
.type
== D3DRTYPE_CUBETEXTURE
) {
1180 struct NineCubeTexture9
*dst
= NineCubeTexture9(dstb
);
1181 struct NineCubeTexture9
*src
= NineCubeTexture9(srcb
);
1184 /* GPUs usually have them stored as arrays of mip-mapped 2D textures. */
1185 for (z
= 0; z
< 6; ++z
) {
1186 for (l
= 0; l
<= last_level
; ++l
, ++m
) {
1187 NineSurface9_CopySurface(dst
->surfaces
[l
* 6 + z
],
1188 src
->surfaces
[m
* 6 + z
], NULL
, NULL
);
1193 if (dstb
->base
.type
== D3DRTYPE_VOLUMETEXTURE
) {
1194 struct NineVolumeTexture9
*dst
= NineVolumeTexture9(dstb
);
1195 struct NineVolumeTexture9
*src
= NineVolumeTexture9(srcb
);
1197 for (l
= 0; l
<= last_level
; ++l
, ++m
)
1198 NineVolume9_CopyVolume(dst
->volumes
[l
],
1199 src
->volumes
[m
], 0, 0, 0, NULL
);
1201 assert(!"invalid texture type");
1204 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
)
1205 NineBaseTexture9_GenerateMipSubLevels(dstb
);
1211 NineDevice9_GetRenderTargetData( struct NineDevice9
*This
,
1212 IDirect3DSurface9
*pRenderTarget
,
1213 IDirect3DSurface9
*pDestSurface
)
1215 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1216 struct NineSurface9
*src
= NineSurface9(pRenderTarget
);
1218 DBG("This=%p pRenderTarget=%p pDestSurface=%p\n",
1219 This
, pRenderTarget
, pDestSurface
);
1221 user_assert(dst
->desc
.Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1222 user_assert(src
->desc
.Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1224 user_assert(dst
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1225 user_assert(src
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1227 return NineSurface9_CopySurface(dst
, src
, NULL
, NULL
);
1231 NineDevice9_GetFrontBufferData( struct NineDevice9
*This
,
1233 IDirect3DSurface9
*pDestSurface
)
1235 DBG("This=%p iSwapChain=%u pDestSurface=%p\n", This
,
1236 iSwapChain
, pDestSurface
);
1238 user_assert(pDestSurface
!= NULL
, D3DERR_INVALIDCALL
);
1239 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
1241 return NineSwapChain9_GetFrontBufferData(This
->swapchains
[iSwapChain
],
1246 NineDevice9_StretchRect( struct NineDevice9
*This
,
1247 IDirect3DSurface9
*pSourceSurface
,
1248 const RECT
*pSourceRect
,
1249 IDirect3DSurface9
*pDestSurface
,
1250 const RECT
*pDestRect
,
1251 D3DTEXTUREFILTERTYPE Filter
)
1253 struct pipe_screen
*screen
= This
->screen
;
1254 struct pipe_context
*pipe
= This
->pipe
;
1255 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1256 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1257 struct pipe_resource
*dst_res
= NineSurface9_GetResource(dst
);
1258 struct pipe_resource
*src_res
= NineSurface9_GetResource(src
);
1259 const boolean zs
= util_format_is_depth_or_stencil(dst_res
->format
);
1260 struct pipe_blit_info blit
;
1261 boolean scaled
, clamped
, ms
, flip_x
= FALSE
, flip_y
= FALSE
;
1263 DBG("This=%p pSourceSurface=%p pSourceRect=%p pDestSurface=%p "
1264 "pDestRect=%p Filter=%u\n",
1265 This
, pSourceSurface
, pSourceRect
, pDestSurface
, pDestRect
, Filter
);
1267 DBG("pSourceRect=(%u,%u)-(%u,%u)\n",
1268 pSourceRect
->left
, pSourceRect
->top
,
1269 pSourceRect
->right
, pSourceRect
->bottom
);
1271 DBG("pDestRect=(%u,%u)-(%u,%u)\n", pDestRect
->left
, pDestRect
->top
,
1272 pDestRect
->right
, pDestRect
->bottom
);
1274 user_assert(!zs
|| !This
->in_scene
, D3DERR_INVALIDCALL
);
1275 user_assert(!zs
|| !pSourceRect
||
1276 (pSourceRect
->left
== 0 &&
1277 pSourceRect
->top
== 0 &&
1278 pSourceRect
->right
== src
->desc
.Width
&&
1279 pSourceRect
->bottom
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1280 user_assert(!zs
|| !pDestRect
||
1281 (pDestRect
->left
== 0 &&
1282 pDestRect
->top
== 0 &&
1283 pDestRect
->right
== dst
->desc
.Width
&&
1284 pDestRect
->bottom
== dst
->desc
.Height
), D3DERR_INVALIDCALL
);
1286 (dst
->desc
.Width
== src
->desc
.Width
&&
1287 dst
->desc
.Height
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1288 user_assert(zs
|| !util_format_is_depth_or_stencil(src_res
->format
),
1289 D3DERR_INVALIDCALL
);
1290 user_assert(!zs
|| dst
->desc
.Format
== src
->desc
.Format
,
1291 D3DERR_INVALIDCALL
);
1292 user_assert(screen
->is_format_supported(screen
, src_res
->format
,
1294 src_res
->nr_samples
,
1295 PIPE_BIND_SAMPLER_VIEW
),
1296 D3DERR_INVALIDCALL
);
1297 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
&&
1298 src
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1300 /* We might want to permit these, but wine thinks we shouldn't. */
1301 user_assert(!pDestRect
||
1302 (pDestRect
->left
<= pDestRect
->right
&&
1303 pDestRect
->top
<= pDestRect
->bottom
), D3DERR_INVALIDCALL
);
1304 user_assert(!pSourceRect
||
1305 (pSourceRect
->left
<= pSourceRect
->right
&&
1306 pSourceRect
->top
<= pSourceRect
->bottom
), D3DERR_INVALIDCALL
);
1308 blit
.dst
.resource
= dst_res
;
1309 blit
.dst
.level
= dst
->level
;
1310 blit
.dst
.box
.z
= dst
->layer
;
1311 blit
.dst
.box
.depth
= 1;
1312 blit
.dst
.format
= dst_res
->format
;
1314 flip_x
= pDestRect
->left
> pDestRect
->right
;
1316 blit
.dst
.box
.x
= pDestRect
->right
;
1317 blit
.dst
.box
.width
= pDestRect
->left
- pDestRect
->right
;
1319 blit
.dst
.box
.x
= pDestRect
->left
;
1320 blit
.dst
.box
.width
= pDestRect
->right
- pDestRect
->left
;
1322 flip_y
= pDestRect
->top
> pDestRect
->bottom
;
1324 blit
.dst
.box
.y
= pDestRect
->bottom
;
1325 blit
.dst
.box
.height
= pDestRect
->top
- pDestRect
->bottom
;
1327 blit
.dst
.box
.y
= pDestRect
->top
;
1328 blit
.dst
.box
.height
= pDestRect
->bottom
- pDestRect
->top
;
1333 blit
.dst
.box
.width
= dst
->desc
.Width
;
1334 blit
.dst
.box
.height
= dst
->desc
.Height
;
1336 blit
.src
.resource
= src_res
;
1337 blit
.src
.level
= src
->level
;
1338 blit
.src
.box
.z
= src
->layer
;
1339 blit
.src
.box
.depth
= 1;
1340 blit
.src
.format
= src_res
->format
;
1342 if (flip_x
^ (pSourceRect
->left
> pSourceRect
->right
)) {
1343 blit
.src
.box
.x
= pSourceRect
->right
;
1344 blit
.src
.box
.width
= pSourceRect
->left
- pSourceRect
->right
;
1346 blit
.src
.box
.x
= pSourceRect
->left
;
1347 blit
.src
.box
.width
= pSourceRect
->right
- pSourceRect
->left
;
1349 if (flip_y
^ (pSourceRect
->top
> pSourceRect
->bottom
)) {
1350 blit
.src
.box
.y
= pSourceRect
->bottom
;
1351 blit
.src
.box
.height
= pSourceRect
->top
- pSourceRect
->bottom
;
1353 blit
.src
.box
.y
= pSourceRect
->top
;
1354 blit
.src
.box
.height
= pSourceRect
->bottom
- pSourceRect
->top
;
1357 blit
.src
.box
.x
= flip_x
? src
->desc
.Width
: 0;
1358 blit
.src
.box
.y
= flip_y
? src
->desc
.Height
: 0;
1359 blit
.src
.box
.width
= flip_x
? -src
->desc
.Width
: src
->desc
.Width
;
1360 blit
.src
.box
.height
= flip_y
? -src
->desc
.Height
: src
->desc
.Height
;
1362 blit
.mask
= zs
? PIPE_MASK_ZS
: PIPE_MASK_RGBA
;
1363 blit
.filter
= Filter
== D3DTEXF_LINEAR
?
1364 PIPE_TEX_FILTER_LINEAR
: PIPE_TEX_FILTER_NEAREST
;
1365 blit
.scissor_enable
= FALSE
;
1367 /* If both of a src and dst dimension are negative, flip them. */
1368 if (blit
.dst
.box
.width
< 0 && blit
.src
.box
.width
< 0) {
1369 blit
.dst
.box
.width
= -blit
.dst
.box
.width
;
1370 blit
.src
.box
.width
= -blit
.src
.box
.width
;
1372 if (blit
.dst
.box
.height
< 0 && blit
.src
.box
.height
< 0) {
1373 blit
.dst
.box
.height
= -blit
.dst
.box
.height
;
1374 blit
.src
.box
.height
= -blit
.src
.box
.height
;
1377 blit
.dst
.box
.width
!= blit
.src
.box
.width
||
1378 blit
.dst
.box
.height
!= blit
.src
.box
.height
;
1380 user_assert(!scaled
|| dst
!= src
, D3DERR_INVALIDCALL
);
1381 user_assert(!scaled
||
1382 !NineSurface9_IsOffscreenPlain(dst
) ||
1383 NineSurface9_IsOffscreenPlain(src
), D3DERR_INVALIDCALL
);
1384 user_assert(!scaled
||
1385 (!util_format_is_compressed(dst
->base
.info
.format
) &&
1386 !util_format_is_compressed(src
->base
.info
.format
)),
1387 D3DERR_INVALIDCALL
);
1389 user_warn(src
== dst
&&
1390 u_box_test_intersection_2d(&blit
.src
.box
, &blit
.dst
.box
));
1392 /* Check for clipping/clamping: */
1394 struct pipe_box box
;
1397 xy
= u_box_clip_2d(&box
, &blit
.dst
.box
,
1398 dst
->desc
.Width
, dst
->desc
.Height
);
1402 xy
= u_box_clip_2d(&box
, &blit
.src
.box
,
1403 src
->desc
.Width
, src
->desc
.Height
);
1407 ms
= (dst
->desc
.MultiSampleType
| 1) != (src
->desc
.MultiSampleType
| 1);
1409 if (clamped
|| scaled
|| (blit
.dst
.format
!= blit
.src
.format
) || ms
) {
1410 DBG("using pipe->blit()\n");
1411 /* TODO: software scaling */
1412 user_assert(screen
->is_format_supported(screen
, dst_res
->format
,
1414 dst_res
->nr_samples
,
1415 zs
? PIPE_BIND_DEPTH_STENCIL
:
1416 PIPE_BIND_RENDER_TARGET
),
1417 D3DERR_INVALIDCALL
);
1419 pipe
->blit(pipe
, &blit
);
1421 assert(blit
.dst
.box
.x
>= 0 && blit
.dst
.box
.y
>= 0 &&
1422 blit
.src
.box
.x
>= 0 && blit
.src
.box
.y
>= 0 &&
1423 blit
.dst
.box
.x
+ blit
.dst
.box
.width
<= dst
->desc
.Width
&&
1424 blit
.src
.box
.x
+ blit
.src
.box
.width
<= src
->desc
.Width
&&
1425 blit
.dst
.box
.y
+ blit
.dst
.box
.height
<= dst
->desc
.Height
&&
1426 blit
.src
.box
.y
+ blit
.src
.box
.height
<= src
->desc
.Height
);
1427 /* Or drivers might crash ... */
1428 DBG("Using resource_copy_region.\n");
1429 pipe
->resource_copy_region(pipe
,
1430 blit
.dst
.resource
, blit
.dst
.level
,
1431 blit
.dst
.box
.x
, blit
.dst
.box
.y
, blit
.dst
.box
.z
,
1432 blit
.src
.resource
, blit
.src
.level
,
1440 NineDevice9_ColorFill( struct NineDevice9
*This
,
1441 IDirect3DSurface9
*pSurface
,
1445 struct pipe_context
*pipe
= This
->pipe
;
1446 struct NineSurface9
*surf
= NineSurface9(pSurface
);
1447 struct pipe_surface
*psurf
;
1448 unsigned x
, y
, w
, h
;
1449 union pipe_color_union rgba
;
1452 DBG("This=%p pSurface=%p pRect=%p color=%08x\n", This
,
1453 pSurface
, pRect
, color
);
1455 DBG("pRect=(%u,%u)-(%u,%u)\n", pRect
->left
, pRect
->top
,
1456 pRect
->right
, pRect
->bottom
);
1458 user_assert(surf
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1460 user_assert((surf
->base
.usage
& D3DUSAGE_RENDERTARGET
) ||
1461 NineSurface9_IsOffscreenPlain(surf
), D3DERR_INVALIDCALL
);
1466 w
= pRect
->right
- pRect
->left
;
1467 h
= pRect
->bottom
- pRect
->top
;
1471 w
= surf
->desc
.Width
;
1472 h
= surf
->desc
.Height
;
1474 d3dcolor_to_pipe_color_union(&rgba
, color
);
1477 !This
->screen
->is_format_supported(This
->screen
, surf
->base
.info
.format
,
1478 surf
->base
.info
.target
,
1479 surf
->base
.info
.nr_samples
,
1480 PIPE_BIND_RENDER_TARGET
);
1482 psurf
= NineSurface9_GetSurface(surf
, 0);
1488 pipe
->clear_render_target(pipe
, psurf
, &rgba
, x
, y
, w
, h
);
1490 D3DLOCKED_RECT lock
;
1491 union util_color uc
;
1493 /* XXX: lock pRect and fix util_fill_rect */
1494 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, 0);
1497 util_pack_color_ub(color
>> 16, color
>> 8, color
>> 0, color
>> 24,
1498 surf
->base
.info
.format
, &uc
);
1499 util_fill_rect(lock
.pBits
, surf
->base
.info
.format
,lock
.Pitch
,
1501 NineSurface9_UnlockRect(surf
);
1508 NineDevice9_CreateOffscreenPlainSurface( struct NineDevice9
*This
,
1513 IDirect3DSurface9
**ppSurface
,
1514 HANDLE
*pSharedHandle
)
1518 DBG("This=%p Width=%u Height=%u Format=%s(0x%x) Pool=%u "
1519 "ppSurface=%p pSharedHandle=%p\n", This
,
1520 Width
, Height
, d3dformat_to_string(Format
), Format
, Pool
,
1521 ppSurface
, pSharedHandle
);
1524 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
1525 || Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1526 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1528 /* Can be used with StretchRect and ColorFill. It's also always lockable.
1530 hr
= create_zs_or_rt_surface(This
, 2, Pool
, Width
, Height
,
1532 D3DMULTISAMPLE_NONE
, 0,
1534 ppSurface
, pSharedHandle
);
1536 DBG("Failed to create surface.\n");
1541 NineDevice9_SetRenderTarget( struct NineDevice9
*This
,
1542 DWORD RenderTargetIndex
,
1543 IDirect3DSurface9
*pRenderTarget
)
1545 struct NineSurface9
*rt
= NineSurface9(pRenderTarget
);
1546 const unsigned i
= RenderTargetIndex
;
1548 DBG("This=%p RenderTargetIndex=%u pRenderTarget=%p\n", This
,
1549 RenderTargetIndex
, pRenderTarget
);
1551 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1552 user_assert(i
!= 0 || pRenderTarget
, D3DERR_INVALIDCALL
);
1553 user_assert(!pRenderTarget
||
1554 rt
->desc
.Usage
& D3DUSAGE_RENDERTARGET
, D3DERR_INVALIDCALL
);
1557 This
->state
.viewport
.X
= 0;
1558 This
->state
.viewport
.Y
= 0;
1559 This
->state
.viewport
.Width
= rt
->desc
.Width
;
1560 This
->state
.viewport
.Height
= rt
->desc
.Height
;
1561 This
->state
.viewport
.MinZ
= 0.0f
;
1562 This
->state
.viewport
.MaxZ
= 1.0f
;
1564 This
->state
.scissor
.minx
= 0;
1565 This
->state
.scissor
.miny
= 0;
1566 This
->state
.scissor
.maxx
= rt
->desc
.Width
;
1567 This
->state
.scissor
.maxy
= rt
->desc
.Height
;
1569 This
->state
.changed
.group
|= NINE_STATE_VIEWPORT
| NINE_STATE_SCISSOR
;
1572 if (This
->state
.rt
[i
] != NineSurface9(pRenderTarget
)) {
1573 nine_bind(&This
->state
.rt
[i
], pRenderTarget
);
1574 This
->state
.changed
.group
|= NINE_STATE_FB
;
1580 NineDevice9_GetRenderTarget( struct NineDevice9
*This
,
1581 DWORD RenderTargetIndex
,
1582 IDirect3DSurface9
**ppRenderTarget
)
1584 const unsigned i
= RenderTargetIndex
;
1586 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1587 user_assert(ppRenderTarget
, D3DERR_INVALIDCALL
);
1589 *ppRenderTarget
= (IDirect3DSurface9
*)This
->state
.rt
[i
];
1590 if (!This
->state
.rt
[i
])
1591 return D3DERR_NOTFOUND
;
1593 NineUnknown_AddRef(NineUnknown(This
->state
.rt
[i
]));
1598 NineDevice9_SetDepthStencilSurface( struct NineDevice9
*This
,
1599 IDirect3DSurface9
*pNewZStencil
)
1601 DBG("This=%p pNewZStencil=%p\n", This
, pNewZStencil
);
1603 if (This
->state
.ds
!= NineSurface9(pNewZStencil
)) {
1604 nine_bind(&This
->state
.ds
, pNewZStencil
);
1605 This
->state
.changed
.group
|= NINE_STATE_FB
;
1611 NineDevice9_GetDepthStencilSurface( struct NineDevice9
*This
,
1612 IDirect3DSurface9
**ppZStencilSurface
)
1614 user_assert(ppZStencilSurface
, D3DERR_INVALIDCALL
);
1616 *ppZStencilSurface
= (IDirect3DSurface9
*)This
->state
.ds
;
1617 if (!This
->state
.ds
)
1618 return D3DERR_NOTFOUND
;
1620 NineUnknown_AddRef(NineUnknown(This
->state
.ds
));
1625 NineDevice9_BeginScene( struct NineDevice9
*This
)
1627 DBG("This=%p\n", This
);
1628 user_assert(!This
->in_scene
, D3DERR_INVALIDCALL
);
1629 This
->in_scene
= TRUE
;
1630 /* Do we want to do anything else here ? */
1635 NineDevice9_EndScene( struct NineDevice9
*This
)
1637 DBG("This=%p\n", This
);
1638 user_assert(This
->in_scene
, D3DERR_INVALIDCALL
);
1639 This
->in_scene
= FALSE
;
1644 NineDevice9_Clear( struct NineDevice9
*This
,
1646 const D3DRECT
*pRects
,
1652 const int sRGB
= This
->state
.rs
[D3DRS_SRGBWRITEENABLE
] ? 1 : 0;
1653 struct pipe_surface
*cbuf
, *zsbuf
;
1654 struct pipe_context
*pipe
= This
->pipe
;
1655 struct NineSurface9
*zsbuf_surf
= This
->state
.ds
;
1656 struct NineSurface9
*rt
;
1659 union pipe_color_union rgba
;
1660 unsigned rt_mask
= 0;
1663 DBG("This=%p Count=%u pRects=%p Flags=%x Color=%08x Z=%f Stencil=%x\n",
1664 This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1666 user_assert(This
->state
.ds
|| !(Flags
& NINED3DCLEAR_DEPTHSTENCIL
),
1667 D3DERR_INVALIDCALL
);
1668 user_assert(!(Flags
& D3DCLEAR_STENCIL
) ||
1670 util_format_is_depth_and_stencil(zsbuf_surf
->base
.info
.format
)),
1671 D3DERR_INVALIDCALL
);
1673 user_assert((Count
&& pRects
) || (!Count
&& !pRects
), D3DERR_INVALIDCALL
);
1675 user_warn((pRects
&& !Count
) || (!pRects
&& Count
));
1676 if (pRects
&& !Count
)
1682 if (Flags
& D3DCLEAR_TARGET
) bufs
|= PIPE_CLEAR_COLOR
;
1683 if (Flags
& D3DCLEAR_ZBUFFER
) bufs
|= PIPE_CLEAR_DEPTH
;
1684 if (Flags
& D3DCLEAR_STENCIL
) bufs
|= PIPE_CLEAR_STENCIL
;
1687 d3dcolor_to_pipe_color_union(&rgba
, Color
);
1689 nine_update_state(This
, NINE_STATE_FB
);
1691 rect
.x1
= This
->state
.viewport
.X
;
1692 rect
.y1
= This
->state
.viewport
.Y
;
1693 rect
.x2
= This
->state
.viewport
.Width
+ rect
.x1
;
1694 rect
.y2
= This
->state
.viewport
.Height
+ rect
.y1
;
1696 /* Both rectangles apply, which is weird, but that's D3D9. */
1697 if (This
->state
.rs
[D3DRS_SCISSORTESTENABLE
]) {
1698 rect
.x1
= MAX2(rect
.x1
, This
->state
.scissor
.minx
);
1699 rect
.y1
= MAX2(rect
.y1
, This
->state
.scissor
.miny
);
1700 rect
.x2
= MIN2(rect
.x2
, This
->state
.scissor
.maxx
);
1701 rect
.y2
= MIN2(rect
.y2
, This
->state
.scissor
.maxy
);
1705 /* Maybe apps like to specify a large rect ? */
1706 if (pRects
[0].x1
<= rect
.x1
&& pRects
[0].x2
>= rect
.x2
&&
1707 pRects
[0].y1
<= rect
.y1
&& pRects
[0].y2
>= rect
.y2
) {
1708 DBG("First rect covers viewport.\n");
1714 if (rect
.x1
>= This
->state
.fb
.width
|| rect
.y1
>= This
->state
.fb
.height
)
1717 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
1718 if (This
->state
.rt
[i
] && This
->state
.rt
[i
]->desc
.Format
!= D3DFMT_NULL
)
1723 (!(bufs
& PIPE_CLEAR_COLOR
) || (rt_mask
== This
->state
.rt_mask
)) &&
1724 rect
.x1
== 0 && rect
.x2
>= This
->state
.fb
.width
&&
1725 rect
.y1
== 0 && rect
.y2
>= This
->state
.fb
.height
) {
1726 /* fast path, clears everything at once */
1728 pipe
->clear(pipe
, bufs
, &rgba
, Z
, Stencil
);
1737 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
1738 rt
= This
->state
.rt
[i
];
1739 if (!rt
|| rt
->desc
.Format
== D3DFMT_NULL
||
1740 !(Flags
& D3DCLEAR_TARGET
))
1741 continue; /* save space, compiler should hoist this */
1742 cbuf
= NineSurface9_GetSurface(rt
, sRGB
);
1743 for (r
= 0; r
< Count
; ++r
) {
1744 /* Don't trust users to pass these in the right order. */
1745 unsigned x1
= MIN2(pRects
[r
].x1
, pRects
[r
].x2
);
1746 unsigned y1
= MIN2(pRects
[r
].y1
, pRects
[r
].y2
);
1747 unsigned x2
= MAX2(pRects
[r
].x1
, pRects
[r
].x2
);
1748 unsigned y2
= MAX2(pRects
[r
].y1
, pRects
[r
].y2
);
1750 /* Drop negative rectangles (like wine expects). */
1751 if (pRects
[r
].x1
> pRects
[r
].x2
) continue;
1752 if (pRects
[r
].y1
> pRects
[r
].y2
) continue;
1755 x1
= MAX2(x1
, rect
.x1
);
1756 y1
= MAX2(y1
, rect
.y1
);
1757 x2
= MIN3(x2
, rect
.x2
, rt
->desc
.Width
);
1758 y2
= MIN3(y2
, rect
.y2
, rt
->desc
.Height
);
1760 DBG("Clearing (%u..%u)x(%u..%u)\n", x1
, x2
, y1
, y2
);
1761 pipe
->clear_render_target(pipe
, cbuf
, &rgba
,
1762 x1
, y1
, x2
- x1
, y2
- y1
);
1765 if (!(Flags
& NINED3DCLEAR_DEPTHSTENCIL
))
1768 bufs
&= PIPE_CLEAR_DEPTHSTENCIL
;
1770 for (r
= 0; r
< Count
; ++r
) {
1771 unsigned x1
= MIN2(pRects
[r
].x1
, pRects
[r
].x2
);
1772 unsigned y1
= MIN2(pRects
[r
].y1
, pRects
[r
].y2
);
1773 unsigned x2
= MAX2(pRects
[r
].x1
, pRects
[r
].x2
);
1774 unsigned y2
= MAX2(pRects
[r
].y1
, pRects
[r
].y2
);
1776 /* Drop negative rectangles. */
1777 if (pRects
[r
].x1
> pRects
[r
].x2
) continue;
1778 if (pRects
[r
].y1
> pRects
[r
].y2
) continue;
1781 x1
= MIN2(x1
, rect
.x1
);
1782 y1
= MIN2(y1
, rect
.y1
);
1783 x2
= MIN3(x2
, rect
.x2
, zsbuf_surf
->desc
.Width
);
1784 y2
= MIN3(y2
, rect
.y2
, zsbuf_surf
->desc
.Height
);
1786 zsbuf
= NineSurface9_GetSurface(zsbuf_surf
, 0);
1788 pipe
->clear_depth_stencil(pipe
, zsbuf
, bufs
, Z
, Stencil
,
1789 x1
, y1
, x2
- x1
, y2
- y1
);
1795 NineDevice9_SetTransform( struct NineDevice9
*This
,
1796 D3DTRANSFORMSTATETYPE State
,
1797 const D3DMATRIX
*pMatrix
)
1799 struct nine_state
*state
= This
->update
;
1800 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
1802 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
1804 user_assert(M
, D3DERR_INVALIDCALL
);
1807 state
->ff
.changed
.transform
[State
/ 32] |= 1 << (State
% 32);
1808 state
->changed
.group
|= NINE_STATE_FF
;
1814 NineDevice9_GetTransform( struct NineDevice9
*This
,
1815 D3DTRANSFORMSTATETYPE State
,
1816 D3DMATRIX
*pMatrix
)
1818 D3DMATRIX
*M
= nine_state_access_transform(&This
->state
, State
, FALSE
);
1819 user_assert(M
, D3DERR_INVALIDCALL
);
1825 NineDevice9_MultiplyTransform( struct NineDevice9
*This
,
1826 D3DTRANSFORMSTATETYPE State
,
1827 const D3DMATRIX
*pMatrix
)
1829 struct nine_state
*state
= This
->update
;
1831 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
1833 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
1835 user_assert(M
, D3DERR_INVALIDCALL
);
1837 nine_d3d_matrix_matrix_mul(&T
, pMatrix
, M
);
1838 return NineDevice9_SetTransform(This
, State
, &T
);
1842 NineDevice9_SetViewport( struct NineDevice9
*This
,
1843 const D3DVIEWPORT9
*pViewport
)
1845 struct nine_state
*state
= This
->update
;
1847 DBG("X=%u Y=%u W=%u H=%u MinZ=%f MaxZ=%f\n",
1848 pViewport
->X
, pViewport
->Y
, pViewport
->Width
, pViewport
->Height
,
1849 pViewport
->MinZ
, pViewport
->MaxZ
);
1851 state
->viewport
= *pViewport
;
1852 state
->changed
.group
|= NINE_STATE_VIEWPORT
;
1858 NineDevice9_GetViewport( struct NineDevice9
*This
,
1859 D3DVIEWPORT9
*pViewport
)
1861 *pViewport
= This
->state
.viewport
;
1866 NineDevice9_SetMaterial( struct NineDevice9
*This
,
1867 const D3DMATERIAL9
*pMaterial
)
1869 struct nine_state
*state
= This
->update
;
1871 DBG("This=%p pMaterial=%p\n", This
, pMaterial
);
1873 nine_dump_D3DMATERIAL9(DBG_FF
, pMaterial
);
1875 user_assert(pMaterial
, E_POINTER
);
1877 state
->ff
.material
= *pMaterial
;
1878 state
->changed
.group
|= NINE_STATE_FF_MATERIAL
;
1884 NineDevice9_GetMaterial( struct NineDevice9
*This
,
1885 D3DMATERIAL9
*pMaterial
)
1887 user_assert(pMaterial
, E_POINTER
);
1888 *pMaterial
= This
->state
.ff
.material
;
1893 NineDevice9_SetLight( struct NineDevice9
*This
,
1895 const D3DLIGHT9
*pLight
)
1897 struct nine_state
*state
= This
->update
;
1899 DBG("This=%p Index=%u pLight=%p\n", This
, Index
, pLight
);
1901 nine_dump_D3DLIGHT9(DBG_FF
, pLight
);
1903 user_assert(pLight
, D3DERR_INVALIDCALL
);
1904 user_assert(pLight
->Type
< NINED3DLIGHT_INVALID
, D3DERR_INVALIDCALL
);
1906 user_assert(Index
< NINE_MAX_LIGHTS
, D3DERR_INVALIDCALL
); /* sanity */
1908 if (Index
>= state
->ff
.num_lights
) {
1909 unsigned n
= state
->ff
.num_lights
;
1910 unsigned N
= Index
+ 1;
1912 state
->ff
.light
= REALLOC(state
->ff
.light
, n
* sizeof(D3DLIGHT9
),
1913 N
* sizeof(D3DLIGHT9
));
1914 if (!state
->ff
.light
)
1915 return E_OUTOFMEMORY
;
1916 state
->ff
.num_lights
= N
;
1918 for (; n
< Index
; ++n
)
1919 state
->ff
.light
[n
].Type
= (D3DLIGHTTYPE
)NINED3DLIGHT_INVALID
;
1921 state
->ff
.light
[Index
] = *pLight
;
1923 if (pLight
->Type
== D3DLIGHT_SPOT
&& pLight
->Theta
>= pLight
->Phi
) {
1924 DBG("Warning: clamping D3DLIGHT9.Theta\n");
1925 state
->ff
.light
[Index
].Theta
= state
->ff
.light
[Index
].Phi
;
1927 if (pLight
->Type
!= D3DLIGHT_DIRECTIONAL
&&
1928 pLight
->Attenuation0
== 0.0f
&&
1929 pLight
->Attenuation1
== 0.0f
&&
1930 pLight
->Attenuation2
== 0.0f
) {
1931 DBG("Warning: all D3DLIGHT9.Attenuation[i] are 0\n");
1934 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
1940 NineDevice9_GetLight( struct NineDevice9
*This
,
1944 const struct nine_state
*state
= &This
->state
;
1946 user_assert(pLight
, D3DERR_INVALIDCALL
);
1947 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
1948 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
1949 D3DERR_INVALIDCALL
);
1951 *pLight
= state
->ff
.light
[Index
];
1957 NineDevice9_LightEnable( struct NineDevice9
*This
,
1961 struct nine_state
*state
= This
->update
;
1964 DBG("This=%p Index=%u Enable=%i\n", This
, Index
, Enable
);
1966 if (Index
>= state
->ff
.num_lights
||
1967 state
->ff
.light
[Index
].Type
== NINED3DLIGHT_INVALID
) {
1968 /* This should create a default light. */
1970 memset(&light
, 0, sizeof(light
));
1971 light
.Type
= D3DLIGHT_DIRECTIONAL
;
1972 light
.Diffuse
.r
= 1.0f
;
1973 light
.Diffuse
.g
= 1.0f
;
1974 light
.Diffuse
.b
= 1.0f
;
1975 light
.Direction
.z
= 1.0f
;
1976 NineDevice9_SetLight(This
, Index
, &light
);
1978 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
1980 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
) {
1981 if (state
->ff
.active_light
[i
] == Index
)
1986 if (i
< state
->ff
.num_lights_active
)
1988 /* XXX wine thinks this should still succeed:
1990 user_assert(i
< NINE_MAX_LIGHTS_ACTIVE
, D3DERR_INVALIDCALL
);
1992 state
->ff
.active_light
[i
] = Index
;
1993 state
->ff
.num_lights_active
++;
1995 if (i
== state
->ff
.num_lights_active
)
1997 --state
->ff
.num_lights_active
;
1998 for (; i
< state
->ff
.num_lights_active
; ++i
)
1999 state
->ff
.active_light
[i
] = state
->ff
.active_light
[i
+ 1];
2001 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2007 NineDevice9_GetLightEnable( struct NineDevice9
*This
,
2011 const struct nine_state
*state
= &This
->state
;
2014 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2015 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2016 D3DERR_INVALIDCALL
);
2018 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
)
2019 if (state
->ff
.active_light
[i
] == Index
)
2022 *pEnable
= i
!= state
->ff
.num_lights_active
? 128 : 0; // Taken from wine
2028 NineDevice9_SetClipPlane( struct NineDevice9
*This
,
2030 const float *pPlane
)
2032 struct nine_state
*state
= This
->update
;
2034 user_assert(pPlane
, D3DERR_INVALIDCALL
);
2036 DBG("This=%p Index=%u pPlane=%f %f %f %f\n", This
, Index
,
2037 pPlane
[0], pPlane
[1],
2038 pPlane
[2], pPlane
[3]);
2040 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2042 memcpy(&state
->clip
.ucp
[Index
][0], pPlane
, sizeof(state
->clip
.ucp
[0]));
2043 state
->changed
.ucp
|= 1 << Index
;
2049 NineDevice9_GetClipPlane( struct NineDevice9
*This
,
2053 const struct nine_state
*state
= &This
->state
;
2055 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2057 memcpy(pPlane
, &state
->clip
.ucp
[Index
][0], sizeof(state
->clip
.ucp
[0]));
2061 #define RESZ_CODE 0x7fa05000
2064 NineDevice9_ResolveZ( struct NineDevice9
*This
)
2066 struct nine_state
*state
= &This
->state
;
2067 const struct util_format_description
*desc
;
2068 struct NineSurface9
*source
= state
->ds
;
2069 struct NineBaseTexture9
*destination
= state
->texture
[0];
2070 struct pipe_resource
*src
, *dst
;
2071 struct pipe_blit_info blit
;
2073 DBG("RESZ resolve\n");
2075 user_assert(source
&& destination
&&
2076 destination
->base
.type
== D3DRTYPE_TEXTURE
, D3DERR_INVALIDCALL
);
2078 src
= source
->base
.resource
;
2079 dst
= destination
->base
.resource
;
2081 user_assert(src
&& dst
, D3DERR_INVALIDCALL
);
2083 /* check dst is depth format. we know already for src */
2084 desc
= util_format_description(dst
->format
);
2085 user_assert(desc
->colorspace
== UTIL_FORMAT_COLORSPACE_ZS
, D3DERR_INVALIDCALL
);
2087 blit
.src
.resource
= src
;
2089 blit
.src
.format
= src
->format
;
2091 blit
.src
.box
.depth
= 1;
2094 blit
.src
.box
.width
= src
->width0
;
2095 blit
.src
.box
.height
= src
->height0
;
2097 blit
.dst
.resource
= dst
;
2099 blit
.dst
.format
= dst
->format
;
2101 blit
.dst
.box
.depth
= 1;
2104 blit
.dst
.box
.width
= dst
->width0
;
2105 blit
.dst
.box
.height
= dst
->height0
;
2107 blit
.mask
= PIPE_MASK_ZS
;
2108 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
2109 blit
.scissor_enable
= FALSE
;
2111 This
->pipe
->blit(This
->pipe
, &blit
);
2115 #define ALPHA_TO_COVERAGE_ENABLE MAKEFOURCC('A', '2', 'M', '1')
2116 #define ALPHA_TO_COVERAGE_DISABLE MAKEFOURCC('A', '2', 'M', '0')
2119 NineDevice9_SetRenderState( struct NineDevice9
*This
,
2120 D3DRENDERSTATETYPE State
,
2123 struct nine_state
*state
= This
->update
;
2125 DBG("This=%p State=%u(%s) Value=%08x\n", This
,
2126 State
, nine_d3drs_to_string(State
), Value
);
2128 /* Amd hacks (equivalent to GL extensions) */
2129 if (State
== D3DRS_POINTSIZE
) {
2130 if (Value
== RESZ_CODE
)
2131 return NineDevice9_ResolveZ(This
);
2133 if (Value
== ALPHA_TO_COVERAGE_ENABLE
||
2134 Value
== ALPHA_TO_COVERAGE_DISABLE
) {
2135 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
== ALPHA_TO_COVERAGE_ENABLE
);
2136 state
->changed
.group
|= NINE_STATE_BLEND
;
2142 if (State
== D3DRS_ADAPTIVETESS_Y
&&
2143 (Value
== D3DFMT_ATOC
|| (Value
== D3DFMT_UNKNOWN
&& state
->rs
[NINED3DRS_ALPHACOVERAGE
]))) {
2144 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
== D3DFMT_ATOC
);
2145 state
->changed
.group
|= NINE_STATE_BLEND
;
2149 user_assert(State
< Elements(state
->rs
), D3DERR_INVALIDCALL
);
2151 if (likely(state
->rs
[State
] != Value
) || unlikely(This
->is_recording
)) {
2152 state
->rs
[State
] = Value
;
2153 state
->changed
.rs
[State
/ 32] |= 1 << (State
% 32);
2154 state
->changed
.group
|= nine_render_state_group
[State
];
2161 NineDevice9_GetRenderState( struct NineDevice9
*This
,
2162 D3DRENDERSTATETYPE State
,
2165 user_assert(State
< Elements(This
->state
.rs
), D3DERR_INVALIDCALL
);
2167 *pValue
= This
->state
.rs
[State
];
2172 NineDevice9_CreateStateBlock( struct NineDevice9
*This
,
2173 D3DSTATEBLOCKTYPE Type
,
2174 IDirect3DStateBlock9
**ppSB
)
2176 struct NineStateBlock9
*nsb
;
2177 struct nine_state
*dst
;
2179 enum nine_stateblock_type type
;
2182 DBG("This=%p Type=%u ppSB=%p\n", This
, Type
, ppSB
);
2184 user_assert(Type
== D3DSBT_ALL
||
2185 Type
== D3DSBT_VERTEXSTATE
||
2186 Type
== D3DSBT_PIXELSTATE
, D3DERR_INVALIDCALL
);
2189 case D3DSBT_VERTEXSTATE
: type
= NINESBT_VERTEXSTATE
; break;
2190 case D3DSBT_PIXELSTATE
: type
= NINESBT_PIXELSTATE
; break;
2196 hr
= NineStateBlock9_new(This
, &nsb
, type
);
2199 *ppSB
= (IDirect3DStateBlock9
*)nsb
;
2202 dst
->changed
.group
=
2203 NINE_STATE_TEXTURE
|
2206 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_VERTEXSTATE
) {
2207 dst
->changed
.group
|=
2208 NINE_STATE_FF_LIGHTING
|
2209 NINE_STATE_VS
| NINE_STATE_VS_CONST
|
2211 /* TODO: texture/sampler state */
2212 memcpy(dst
->changed
.rs
,
2213 nine_render_states_vertex
, sizeof(dst
->changed
.rs
));
2214 nine_ranges_insert(&dst
->changed
.vs_const_f
, 0, This
->max_vs_const_f
,
2216 dst
->changed
.vs_const_i
= 0xffff;
2217 dst
->changed
.vs_const_b
= 0xffff;
2218 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2219 dst
->changed
.sampler
[s
] |= 1 << D3DSAMP_DMAPOFFSET
;
2220 if (This
->state
.ff
.num_lights
) {
2221 dst
->ff
.num_lights
= This
->state
.ff
.num_lights
;
2222 /* zero'd -> light type won't be NINED3DLIGHT_INVALID, so
2223 * all currently existing lights will be captured
2225 dst
->ff
.light
= CALLOC(This
->state
.ff
.num_lights
,
2227 if (!dst
->ff
.light
) {
2228 nine_bind(ppSB
, NULL
);
2229 return E_OUTOFMEMORY
;
2233 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_PIXELSTATE
) {
2234 dst
->changed
.group
|=
2235 NINE_STATE_PS
| NINE_STATE_PS_CONST
;
2236 /* TODO: texture/sampler state */
2237 memcpy(dst
->changed
.rs
,
2238 nine_render_states_pixel
, sizeof(dst
->changed
.rs
));
2239 nine_ranges_insert(&dst
->changed
.ps_const_f
, 0, This
->max_ps_const_f
,
2241 dst
->changed
.ps_const_i
= 0xffff;
2242 dst
->changed
.ps_const_b
= 0xffff;
2243 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2244 dst
->changed
.sampler
[s
] |= 0x1ffe;
2246 if (Type
== D3DSBT_ALL
) {
2247 dst
->changed
.group
|=
2248 NINE_STATE_VIEWPORT
|
2249 NINE_STATE_SCISSOR
|
2250 NINE_STATE_RASTERIZER
|
2254 NINE_STATE_MATERIAL
|
2255 NINE_STATE_BLEND_COLOR
|
2256 NINE_STATE_SAMPLE_MASK
;
2257 memset(dst
->changed
.rs
, ~0, (D3DRS_COUNT
/ 32) * sizeof(uint32_t));
2258 dst
->changed
.rs
[D3DRS_LAST
/ 32] |= (1 << (D3DRS_COUNT
% 32)) - 1;
2259 dst
->changed
.vtxbuf
= (1ULL << This
->caps
.MaxStreams
) - 1;
2260 dst
->changed
.stream_freq
= dst
->changed
.vtxbuf
;
2261 dst
->changed
.ucp
= (1 << PIPE_MAX_CLIP_PLANES
) - 1;
2262 dst
->changed
.texture
= (1 << NINE_MAX_SAMPLERS
) - 1;
2264 NineStateBlock9_Capture(NineStateBlock9(*ppSB
));
2266 /* TODO: fixed function state */
2272 NineDevice9_BeginStateBlock( struct NineDevice9
*This
)
2276 DBG("This=%p\n", This
);
2278 user_assert(!This
->record
, D3DERR_INVALIDCALL
);
2280 hr
= NineStateBlock9_new(This
, &This
->record
, NINESBT_CUSTOM
);
2283 NineUnknown_ConvertRefToBind(NineUnknown(This
->record
));
2285 This
->update
= &This
->record
->state
;
2286 This
->is_recording
= TRUE
;
2292 NineDevice9_EndStateBlock( struct NineDevice9
*This
,
2293 IDirect3DStateBlock9
**ppSB
)
2295 DBG("This=%p ppSB=%p\n", This
, ppSB
);
2297 user_assert(This
->record
, D3DERR_INVALIDCALL
);
2299 This
->update
= &This
->state
;
2300 This
->is_recording
= FALSE
;
2302 NineUnknown_AddRef(NineUnknown(This
->record
));
2303 *ppSB
= (IDirect3DStateBlock9
*)This
->record
;
2304 NineUnknown_Unbind(NineUnknown(This
->record
));
2305 This
->record
= NULL
;
2311 NineDevice9_SetClipStatus( struct NineDevice9
*This
,
2312 const D3DCLIPSTATUS9
*pClipStatus
)
2314 STUB(D3DERR_INVALIDCALL
);
2318 NineDevice9_GetClipStatus( struct NineDevice9
*This
,
2319 D3DCLIPSTATUS9
*pClipStatus
)
2321 STUB(D3DERR_INVALIDCALL
);
2325 NineDevice9_GetTexture( struct NineDevice9
*This
,
2327 IDirect3DBaseTexture9
**ppTexture
)
2329 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2330 Stage
== D3DDMAPSAMPLER
||
2331 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2332 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2333 user_assert(ppTexture
, D3DERR_INVALIDCALL
);
2335 if (Stage
>= D3DDMAPSAMPLER
)
2336 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2338 *ppTexture
= (IDirect3DBaseTexture9
*)This
->state
.texture
[Stage
];
2340 if (This
->state
.texture
[Stage
])
2341 NineUnknown_AddRef(NineUnknown(This
->state
.texture
[Stage
]));
2346 NineDevice9_SetTexture( struct NineDevice9
*This
,
2348 IDirect3DBaseTexture9
*pTexture
)
2350 struct nine_state
*state
= This
->update
;
2351 struct NineBaseTexture9
*tex
= NineBaseTexture9(pTexture
);
2353 DBG("This=%p Stage=%u pTexture=%p\n", This
, Stage
, pTexture
);
2355 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2356 Stage
== D3DDMAPSAMPLER
||
2357 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2358 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2359 user_assert(!tex
|| tex
->base
.pool
!= D3DPOOL_SCRATCH
, D3DERR_INVALIDCALL
);
2361 if (unlikely(tex
&& tex
->base
.pool
== D3DPOOL_SYSTEMMEM
)) {
2362 /* TODO: Currently not implemented. Better return error
2363 * with message telling what's wrong */
2364 ERR("This=%p D3DPOOL_SYSTEMMEM not implemented for SetTexture\n", This
);
2365 user_assert(tex
->base
.pool
!= D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
2368 if (Stage
>= D3DDMAPSAMPLER
)
2369 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2371 if (!This
->is_recording
) {
2372 struct NineBaseTexture9
*old
= state
->texture
[Stage
];
2376 state
->samplers_shadow
&= ~(1 << Stage
);
2378 state
->samplers_shadow
|= tex
->shadow
<< Stage
;
2380 if ((tex
->dirty
| tex
->dirty_mip
) && LIST_IS_EMPTY(&tex
->list
))
2381 list_add(&tex
->list
, &This
->update_textures
);
2388 nine_bind(&state
->texture
[Stage
], pTexture
);
2390 state
->changed
.texture
|= 1 << Stage
;
2391 state
->changed
.group
|= NINE_STATE_TEXTURE
;
2397 NineDevice9_GetTextureStageState( struct NineDevice9
*This
,
2399 D3DTEXTURESTAGESTATETYPE Type
,
2402 const struct nine_state
*state
= &This
->state
;
2404 user_assert(Stage
< Elements(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2405 user_assert(Type
< Elements(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2407 *pValue
= state
->ff
.tex_stage
[Stage
][Type
];
2413 NineDevice9_SetTextureStageState( struct NineDevice9
*This
,
2415 D3DTEXTURESTAGESTATETYPE Type
,
2418 struct nine_state
*state
= This
->update
;
2420 DBG("Stage=%u Type=%u Value=%08x\n", Stage
, Type
, Value
);
2421 nine_dump_D3DTSS_value(DBG_FF
, Type
, Value
);
2423 user_assert(Stage
< Elements(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2424 user_assert(Type
< Elements(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2426 state
->ff
.tex_stage
[Stage
][Type
] = Value
;
2428 state
->changed
.group
|= NINE_STATE_FF_PSSTAGES
;
2429 state
->ff
.changed
.tex_stage
[Stage
][Type
/ 32] |= 1 << (Type
% 32);
2435 NineDevice9_GetSamplerState( struct NineDevice9
*This
,
2437 D3DSAMPLERSTATETYPE Type
,
2440 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2441 Sampler
== D3DDMAPSAMPLER
||
2442 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2443 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2445 if (Sampler
>= D3DDMAPSAMPLER
)
2446 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2448 *pValue
= This
->state
.samp
[Sampler
][Type
];
2453 NineDevice9_SetSamplerState( struct NineDevice9
*This
,
2455 D3DSAMPLERSTATETYPE Type
,
2458 struct nine_state
*state
= This
->update
;
2460 DBG("This=%p Sampler=%u Type=%s Value=%08x\n", This
,
2461 Sampler
, nine_D3DSAMP_to_str(Type
), Value
);
2463 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2464 Sampler
== D3DDMAPSAMPLER
||
2465 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2466 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2468 if (Sampler
>= D3DDMAPSAMPLER
)
2469 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2471 state
->samp
[Sampler
][Type
] = Value
;
2472 state
->changed
.group
|= NINE_STATE_SAMPLER
;
2473 state
->changed
.sampler
[Sampler
] |= 1 << Type
;
2475 if (Type
== D3DSAMP_SRGBTEXTURE
)
2476 state
->changed
.srgb
= TRUE
;
2482 NineDevice9_ValidateDevice( struct NineDevice9
*This
,
2485 const struct nine_state
*state
= &This
->state
;
2487 unsigned w
= 0, h
= 0;
2489 DBG("This=%p pNumPasses=%p\n", This
, pNumPasses
);
2491 for (i
= 0; i
< Elements(state
->samp
); ++i
) {
2492 if (state
->samp
[i
][D3DSAMP_MINFILTER
] == D3DTEXF_NONE
||
2493 state
->samp
[i
][D3DSAMP_MAGFILTER
] == D3DTEXF_NONE
)
2494 return D3DERR_UNSUPPORTEDTEXTUREFILTER
;
2497 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2501 w
= state
->rt
[i
]->desc
.Width
;
2502 h
= state
->rt
[i
]->desc
.Height
;
2504 if (state
->rt
[i
]->desc
.Width
!= w
|| state
->rt
[i
]->desc
.Height
!= h
) {
2505 return D3DERR_CONFLICTINGRENDERSTATE
;
2509 (state
->rs
[D3DRS_ZENABLE
] || state
->rs
[D3DRS_STENCILENABLE
])) {
2511 (state
->ds
->desc
.Width
!= w
|| state
->ds
->desc
.Height
!= h
))
2512 return D3DERR_CONFLICTINGRENDERSTATE
;
2522 NineDevice9_SetPaletteEntries( struct NineDevice9
*This
,
2524 const PALETTEENTRY
*pEntries
)
2526 STUB(D3D_OK
); /* like wine */
2530 NineDevice9_GetPaletteEntries( struct NineDevice9
*This
,
2532 PALETTEENTRY
*pEntries
)
2534 STUB(D3DERR_INVALIDCALL
);
2538 NineDevice9_SetCurrentTexturePalette( struct NineDevice9
*This
,
2539 UINT PaletteNumber
)
2541 STUB(D3D_OK
); /* like wine */
2545 NineDevice9_GetCurrentTexturePalette( struct NineDevice9
*This
,
2546 UINT
*PaletteNumber
)
2548 STUB(D3DERR_INVALIDCALL
);
2552 NineDevice9_SetScissorRect( struct NineDevice9
*This
,
2555 struct nine_state
*state
= This
->update
;
2557 DBG("x=(%u..%u) y=(%u..%u)\n",
2558 pRect
->left
, pRect
->top
, pRect
->right
, pRect
->bottom
);
2560 state
->scissor
.minx
= pRect
->left
;
2561 state
->scissor
.miny
= pRect
->top
;
2562 state
->scissor
.maxx
= pRect
->right
;
2563 state
->scissor
.maxy
= pRect
->bottom
;
2565 state
->changed
.group
|= NINE_STATE_SCISSOR
;
2571 NineDevice9_GetScissorRect( struct NineDevice9
*This
,
2574 pRect
->left
= This
->state
.scissor
.minx
;
2575 pRect
->top
= This
->state
.scissor
.miny
;
2576 pRect
->right
= This
->state
.scissor
.maxx
;
2577 pRect
->bottom
= This
->state
.scissor
.maxy
;
2583 NineDevice9_SetSoftwareVertexProcessing( struct NineDevice9
*This
,
2586 STUB(D3DERR_INVALIDCALL
);
2590 NineDevice9_GetSoftwareVertexProcessing( struct NineDevice9
*This
)
2592 return !!(This
->params
.BehaviorFlags
& D3DCREATE_SOFTWARE_VERTEXPROCESSING
);
2596 NineDevice9_SetNPatchMode( struct NineDevice9
*This
,
2599 STUB(D3DERR_INVALIDCALL
);
2603 NineDevice9_GetNPatchMode( struct NineDevice9
*This
)
2609 init_draw_info(struct pipe_draw_info
*info
,
2610 struct NineDevice9
*dev
, D3DPRIMITIVETYPE type
, UINT count
)
2612 info
->mode
= d3dprimitivetype_to_pipe_prim(type
);
2613 info
->count
= prim_count_to_vertex_count(type
, count
);
2614 info
->start_instance
= 0;
2615 info
->instance_count
= 1;
2616 if (dev
->state
.stream_instancedata_mask
& dev
->state
.stream_usage_mask
)
2617 info
->instance_count
= MAX2(dev
->state
.stream_freq
[0] & 0x7FFFFF, 1);
2618 info
->primitive_restart
= FALSE
;
2619 info
->restart_index
= 0;
2620 info
->count_from_stream_output
= NULL
;
2621 info
->indirect
= NULL
;
2625 NineDevice9_DrawPrimitive( struct NineDevice9
*This
,
2626 D3DPRIMITIVETYPE PrimitiveType
,
2628 UINT PrimitiveCount
)
2630 struct pipe_draw_info info
;
2632 DBG("iface %p, PrimitiveType %u, StartVertex %u, PrimitiveCount %u\n",
2633 This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2635 nine_update_state(This
, ~0);
2637 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2638 info
.indexed
= FALSE
;
2639 info
.start
= StartVertex
;
2640 info
.index_bias
= 0;
2641 info
.min_index
= info
.start
;
2642 info
.max_index
= info
.count
- 1;
2644 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2650 NineDevice9_DrawIndexedPrimitive( struct NineDevice9
*This
,
2651 D3DPRIMITIVETYPE PrimitiveType
,
2652 INT BaseVertexIndex
,
2653 UINT MinVertexIndex
,
2656 UINT PrimitiveCount
)
2658 struct pipe_draw_info info
;
2660 DBG("iface %p, PrimitiveType %u, BaseVertexIndex %u, MinVertexIndex %u "
2661 "NumVertices %u, StartIndex %u, PrimitiveCount %u\n",
2662 This
, PrimitiveType
, BaseVertexIndex
, MinVertexIndex
, NumVertices
,
2663 StartIndex
, PrimitiveCount
);
2665 user_assert(This
->state
.idxbuf
, D3DERR_INVALIDCALL
);
2666 user_assert(This
->state
.vdecl
, D3DERR_INVALIDCALL
);
2668 nine_update_state(This
, ~0);
2670 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2671 info
.indexed
= TRUE
;
2672 info
.start
= StartIndex
;
2673 info
.index_bias
= BaseVertexIndex
;
2674 /* These don't include index bias: */
2675 info
.min_index
= MinVertexIndex
;
2676 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
2678 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2684 NineDevice9_DrawPrimitiveUP( struct NineDevice9
*This
,
2685 D3DPRIMITIVETYPE PrimitiveType
,
2686 UINT PrimitiveCount
,
2687 const void *pVertexStreamZeroData
,
2688 UINT VertexStreamZeroStride
)
2690 struct pipe_vertex_buffer vtxbuf
;
2691 struct pipe_draw_info info
;
2693 DBG("iface %p, PrimitiveType %u, PrimitiveCount %u, data %p, stride %u\n",
2694 This
, PrimitiveType
, PrimitiveCount
,
2695 pVertexStreamZeroData
, VertexStreamZeroStride
);
2697 user_assert(pVertexStreamZeroData
&& VertexStreamZeroStride
,
2698 D3DERR_INVALIDCALL
);
2700 nine_update_state(This
, ~0);
2702 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2703 info
.indexed
= FALSE
;
2705 info
.index_bias
= 0;
2707 info
.max_index
= info
.count
- 1;
2709 vtxbuf
.stride
= VertexStreamZeroStride
;
2710 vtxbuf
.buffer_offset
= 0;
2711 vtxbuf
.buffer
= NULL
;
2712 vtxbuf
.user_buffer
= pVertexStreamZeroData
;
2714 if (!This
->driver_caps
.user_vbufs
)
2715 u_upload_data(This
->upload
,
2717 (info
.max_index
+ 1) * VertexStreamZeroStride
, /* XXX */
2719 &vtxbuf
.buffer_offset
,
2722 This
->pipe
->set_vertex_buffers(This
->pipe
, 0, 1, &vtxbuf
);
2724 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2726 NineDevice9_PauseRecording(This
);
2727 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
2728 NineDevice9_ResumeRecording(This
);
2730 pipe_resource_reference(&vtxbuf
.buffer
, NULL
);
2736 NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9
*This
,
2737 D3DPRIMITIVETYPE PrimitiveType
,
2738 UINT MinVertexIndex
,
2740 UINT PrimitiveCount
,
2741 const void *pIndexData
,
2742 D3DFORMAT IndexDataFormat
,
2743 const void *pVertexStreamZeroData
,
2744 UINT VertexStreamZeroStride
)
2746 struct pipe_draw_info info
;
2747 struct pipe_vertex_buffer vbuf
;
2748 struct pipe_index_buffer ibuf
;
2750 DBG("iface %p, PrimitiveType %u, MinVertexIndex %u, NumVertices %u "
2751 "PrimitiveCount %u, pIndexData %p, IndexDataFormat %u "
2752 "pVertexStreamZeroData %p, VertexStreamZeroStride %u\n",
2753 This
, PrimitiveType
, MinVertexIndex
, NumVertices
, PrimitiveCount
,
2754 pIndexData
, IndexDataFormat
,
2755 pVertexStreamZeroData
, VertexStreamZeroStride
);
2757 user_assert(pIndexData
&& pVertexStreamZeroData
, D3DERR_INVALIDCALL
);
2758 user_assert(VertexStreamZeroStride
, D3DERR_INVALIDCALL
);
2759 user_assert(IndexDataFormat
== D3DFMT_INDEX16
||
2760 IndexDataFormat
== D3DFMT_INDEX32
, D3DERR_INVALIDCALL
);
2762 nine_update_state(This
, ~0);
2764 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2765 info
.indexed
= TRUE
;
2767 info
.index_bias
= 0;
2768 info
.min_index
= MinVertexIndex
;
2769 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
2771 vbuf
.stride
= VertexStreamZeroStride
;
2772 vbuf
.buffer_offset
= 0;
2774 vbuf
.user_buffer
= pVertexStreamZeroData
;
2776 ibuf
.index_size
= (IndexDataFormat
== D3DFMT_INDEX16
) ? 2 : 4;
2779 ibuf
.user_buffer
= pIndexData
;
2781 if (!This
->driver_caps
.user_vbufs
) {
2782 const unsigned base
= info
.min_index
* VertexStreamZeroStride
;
2783 u_upload_data(This
->upload
,
2786 info
.min_index
+ 1) * VertexStreamZeroStride
, /* XXX */
2787 (const uint8_t *)vbuf
.user_buffer
+ base
,
2788 &vbuf
.buffer_offset
,
2790 /* Won't be used: */
2791 vbuf
.buffer_offset
-= base
;
2793 if (!This
->driver_caps
.user_ibufs
)
2794 u_upload_data(This
->upload
,
2796 info
.count
* ibuf
.index_size
,
2801 This
->pipe
->set_vertex_buffers(This
->pipe
, 0, 1, &vbuf
);
2802 This
->pipe
->set_index_buffer(This
->pipe
, &ibuf
);
2804 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2806 pipe_resource_reference(&vbuf
.buffer
, NULL
);
2807 pipe_resource_reference(&ibuf
.buffer
, NULL
);
2809 NineDevice9_PauseRecording(This
);
2810 NineDevice9_SetIndices(This
, NULL
);
2811 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
2812 NineDevice9_ResumeRecording(This
);
2817 /* TODO: Write to pDestBuffer directly if vertex declaration contains
2821 NineDevice9_ProcessVertices( struct NineDevice9
*This
,
2825 IDirect3DVertexBuffer9
*pDestBuffer
,
2826 IDirect3DVertexDeclaration9
*pVertexDecl
,
2829 struct pipe_screen
*screen
= This
->screen
;
2830 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pVertexDecl
);
2831 struct NineVertexShader9
*vs
;
2832 struct pipe_resource
*resource
;
2833 struct pipe_stream_output_target
*target
;
2834 struct pipe_draw_info draw
;
2836 unsigned buffer_offset
, buffer_size
;
2838 DBG("This=%p SrcStartIndex=%u DestIndex=%u VertexCount=%u "
2839 "pDestBuffer=%p pVertexDecl=%p Flags=%d\n",
2840 This
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
,
2841 pVertexDecl
, Flags
);
2843 if (!screen
->get_param(screen
, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
))
2844 STUB(D3DERR_INVALIDCALL
);
2846 nine_update_state(This
, ~0);
2848 /* TODO: Create shader with stream output. */
2849 STUB(D3DERR_INVALIDCALL
);
2850 struct NineVertexBuffer9
*dst
= NineVertexBuffer9(pDestBuffer
);
2852 vs
= This
->state
.vs
? This
->state
.vs
: This
->ff
.vs
;
2854 buffer_size
= VertexCount
* vs
->so
->stride
[0];
2856 struct pipe_resource templ
;
2858 templ
.target
= PIPE_BUFFER
;
2859 templ
.format
= PIPE_FORMAT_R8_UNORM
;
2860 templ
.width0
= buffer_size
;
2862 templ
.bind
= PIPE_BIND_STREAM_OUTPUT
;
2863 templ
.usage
= PIPE_USAGE_STREAM
;
2864 templ
.height0
= templ
.depth0
= templ
.array_size
= 1;
2865 templ
.last_level
= templ
.nr_samples
= 0;
2867 resource
= This
->screen
->resource_create(This
->screen
, &templ
);
2869 return E_OUTOFMEMORY
;
2872 /* SO matches vertex declaration */
2873 resource
= dst
->base
.resource
;
2874 buffer_offset
= DestIndex
* vs
->so
->stride
[0];
2876 target
= This
->pipe
->create_stream_output_target(This
->pipe
, resource
,
2880 pipe_resource_reference(&resource
, NULL
);
2881 return D3DERR_DRIVERINTERNALERROR
;
2885 hr
= NineVertexDeclaration9_new_from_fvf(This
, dst
->desc
.FVF
, &vdecl
);
2890 init_draw_info(&draw
, This
, D3DPT_POINTLIST
, VertexCount
);
2891 draw
.instance_count
= 1;
2892 draw
.indexed
= FALSE
;
2893 draw
.start
= SrcStartIndex
;
2894 draw
.index_bias
= 0;
2895 draw
.min_index
= SrcStartIndex
;
2896 draw
.max_index
= SrcStartIndex
+ VertexCount
- 1;
2898 This
->pipe
->set_stream_output_targets(This
->pipe
, 1, &target
, 0);
2899 This
->pipe
->draw_vbo(This
->pipe
, &draw
);
2900 This
->pipe
->set_stream_output_targets(This
->pipe
, 0, NULL
, 0);
2901 This
->pipe
->stream_output_target_destroy(This
->pipe
, target
);
2903 hr
= NineVertexDeclaration9_ConvertStreamOutput(vdecl
,
2904 dst
, DestIndex
, VertexCount
,
2907 pipe_resource_reference(&resource
, NULL
);
2909 NineUnknown_Release(NineUnknown(vdecl
));
2914 NineDevice9_CreateVertexDeclaration( struct NineDevice9
*This
,
2915 const D3DVERTEXELEMENT9
*pVertexElements
,
2916 IDirect3DVertexDeclaration9
**ppDecl
)
2918 struct NineVertexDeclaration9
*vdecl
;
2920 DBG("This=%p pVertexElements=%p ppDecl=%p\n",
2921 This
, pVertexElements
, ppDecl
);
2923 HRESULT hr
= NineVertexDeclaration9_new(This
, pVertexElements
, &vdecl
);
2925 *ppDecl
= (IDirect3DVertexDeclaration9
*)vdecl
;
2931 NineDevice9_SetVertexDeclaration( struct NineDevice9
*This
,
2932 IDirect3DVertexDeclaration9
*pDecl
)
2934 struct nine_state
*state
= This
->update
;
2936 DBG("This=%p pDecl=%p\n", This
, pDecl
);
2938 if (likely(!This
->is_recording
) && state
->vdecl
== NineVertexDeclaration9(pDecl
))
2940 nine_bind(&state
->vdecl
, pDecl
);
2942 state
->changed
.group
|= NINE_STATE_VDECL
;
2948 NineDevice9_GetVertexDeclaration( struct NineDevice9
*This
,
2949 IDirect3DVertexDeclaration9
**ppDecl
)
2951 user_assert(ppDecl
, D3DERR_INVALIDCALL
);
2953 *ppDecl
= (IDirect3DVertexDeclaration9
*)This
->state
.vdecl
;
2955 NineUnknown_AddRef(NineUnknown(*ppDecl
));
2960 NineDevice9_SetFVF( struct NineDevice9
*This
,
2963 struct NineVertexDeclaration9
*vdecl
;
2966 DBG("FVF = %08x\n", FVF
);
2968 return D3D_OK
; /* like wine */
2970 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
2972 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
2976 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
2977 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
2979 return NineDevice9_SetVertexDeclaration(
2980 This
, (IDirect3DVertexDeclaration9
*)vdecl
);
2984 NineDevice9_GetFVF( struct NineDevice9
*This
,
2987 *pFVF
= This
->state
.vdecl
? This
->state
.vdecl
->fvf
: 0;
2992 NineDevice9_CreateVertexShader( struct NineDevice9
*This
,
2993 const DWORD
*pFunction
,
2994 IDirect3DVertexShader9
**ppShader
)
2996 struct NineVertexShader9
*vs
;
2999 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3001 hr
= NineVertexShader9_new(This
, &vs
, pFunction
, NULL
);
3004 *ppShader
= (IDirect3DVertexShader9
*)vs
;
3009 NineDevice9_SetVertexShader( struct NineDevice9
*This
,
3010 IDirect3DVertexShader9
*pShader
)
3012 struct nine_state
*state
= This
->update
;
3014 DBG("This=%p pShader=%p\n", This
, pShader
);
3016 nine_bind(&state
->vs
, pShader
);
3018 state
->changed
.group
|= NINE_STATE_VS
;
3024 NineDevice9_GetVertexShader( struct NineDevice9
*This
,
3025 IDirect3DVertexShader9
**ppShader
)
3027 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3028 nine_reference_set(ppShader
, This
->state
.vs
);
3033 NineDevice9_SetVertexShaderConstantF( struct NineDevice9
*This
,
3035 const float *pConstantData
,
3036 UINT Vector4fCount
)
3038 struct nine_state
*state
= This
->update
;
3040 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3041 This
, StartRegister
, pConstantData
, Vector4fCount
);
3043 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3044 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3048 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3050 memcpy(&state
->vs_const_f
[StartRegister
* 4],
3052 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3054 nine_ranges_insert(&state
->changed
.vs_const_f
,
3055 StartRegister
, StartRegister
+ Vector4fCount
,
3058 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3064 NineDevice9_GetVertexShaderConstantF( struct NineDevice9
*This
,
3066 float *pConstantData
,
3067 UINT Vector4fCount
)
3069 const struct nine_state
*state
= &This
->state
;
3071 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3072 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3073 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3075 memcpy(pConstantData
,
3076 &state
->vs_const_f
[StartRegister
* 4],
3077 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3083 NineDevice9_SetVertexShaderConstantI( struct NineDevice9
*This
,
3085 const int *pConstantData
,
3086 UINT Vector4iCount
)
3088 struct nine_state
*state
= This
->update
;
3091 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3092 This
, StartRegister
, pConstantData
, Vector4iCount
);
3094 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3095 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3096 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3098 if (This
->driver_caps
.vs_integer
) {
3099 memcpy(&state
->vs_const_i
[StartRegister
][0],
3101 Vector4iCount
* sizeof(state
->vs_const_i
[0]));
3103 for (i
= 0; i
< Vector4iCount
; i
++) {
3104 state
->vs_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3105 state
->vs_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3106 state
->vs_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3107 state
->vs_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3111 state
->changed
.vs_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3112 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3118 NineDevice9_GetVertexShaderConstantI( struct NineDevice9
*This
,
3121 UINT Vector4iCount
)
3123 const struct nine_state
*state
= &This
->state
;
3126 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3127 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3128 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3130 if (This
->driver_caps
.vs_integer
) {
3131 memcpy(pConstantData
,
3132 &state
->vs_const_i
[StartRegister
][0],
3133 Vector4iCount
* sizeof(state
->vs_const_i
[0]));
3135 for (i
= 0; i
< Vector4iCount
; i
++) {
3136 pConstantData
[4*i
] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][0]);
3137 pConstantData
[4*i
+1] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][1]);
3138 pConstantData
[4*i
+2] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][2]);
3139 pConstantData
[4*i
+3] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][3]);
3147 NineDevice9_SetVertexShaderConstantB( struct NineDevice9
*This
,
3149 const BOOL
*pConstantData
,
3152 struct nine_state
*state
= This
->update
;
3154 uint32_t bool_true
= This
->driver_caps
.vs_integer
? 0xFFFFFFFF : fui(1.0f
);
3156 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3157 This
, StartRegister
, pConstantData
, BoolCount
);
3159 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3160 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3161 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3163 for (i
= 0; i
< BoolCount
; i
++)
3164 state
->vs_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3166 state
->changed
.vs_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3167 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3173 NineDevice9_GetVertexShaderConstantB( struct NineDevice9
*This
,
3175 BOOL
*pConstantData
,
3178 const struct nine_state
*state
= &This
->state
;
3181 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3182 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3183 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3185 for (i
= 0; i
< BoolCount
; i
++)
3186 pConstantData
[i
] = state
->vs_const_b
[StartRegister
+ i
] != 0 ? TRUE
: FALSE
;
3192 NineDevice9_SetStreamSource( struct NineDevice9
*This
,
3194 IDirect3DVertexBuffer9
*pStreamData
,
3198 struct nine_state
*state
= This
->update
;
3199 struct NineVertexBuffer9
*pVBuf9
= NineVertexBuffer9(pStreamData
);
3200 const unsigned i
= StreamNumber
;
3202 DBG("This=%p StreamNumber=%u pStreamData=%p OffsetInBytes=%u Stride=%u\n",
3203 This
, StreamNumber
, pStreamData
, OffsetInBytes
, Stride
);
3205 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3206 user_assert(Stride
<= This
->caps
.MaxStreamStride
, D3DERR_INVALIDCALL
);
3208 if (likely(!This
->is_recording
)) {
3209 if (state
->stream
[i
] == NineVertexBuffer9(pStreamData
) &&
3210 state
->vtxbuf
[i
].stride
== Stride
&&
3211 state
->vtxbuf
[i
].buffer_offset
== OffsetInBytes
)
3214 nine_bind(&state
->stream
[i
], pStreamData
);
3216 state
->changed
.vtxbuf
|= 1 << StreamNumber
;
3219 state
->vtxbuf
[i
].stride
= Stride
;
3220 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3222 state
->vtxbuf
[i
].buffer
= pStreamData
? pVBuf9
->base
.resource
: NULL
;
3228 NineDevice9_GetStreamSource( struct NineDevice9
*This
,
3230 IDirect3DVertexBuffer9
**ppStreamData
,
3231 UINT
*pOffsetInBytes
,
3234 const struct nine_state
*state
= &This
->state
;
3235 const unsigned i
= StreamNumber
;
3237 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3238 user_assert(ppStreamData
, D3DERR_INVALIDCALL
);
3240 nine_reference_set(ppStreamData
, state
->stream
[i
]);
3241 *pStride
= state
->vtxbuf
[i
].stride
;
3242 *pOffsetInBytes
= state
->vtxbuf
[i
].buffer_offset
;
3248 NineDevice9_SetStreamSourceFreq( struct NineDevice9
*This
,
3252 struct nine_state
*state
= This
->update
;
3253 /* const UINT freq = Setting & 0x7FFFFF; */
3255 DBG("This=%p StreamNumber=%u FrequencyParameter=0x%x\n", This
,
3256 StreamNumber
, Setting
);
3258 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3259 user_assert(StreamNumber
!= 0 || !(Setting
& D3DSTREAMSOURCE_INSTANCEDATA
),
3260 D3DERR_INVALIDCALL
);
3261 user_assert(!((Setting
& D3DSTREAMSOURCE_INSTANCEDATA
) &&
3262 (Setting
& D3DSTREAMSOURCE_INDEXEDDATA
)), D3DERR_INVALIDCALL
);
3263 user_assert(Setting
, D3DERR_INVALIDCALL
);
3265 state
->stream_freq
[StreamNumber
] = Setting
;
3267 if (Setting
& D3DSTREAMSOURCE_INSTANCEDATA
)
3268 state
->stream_instancedata_mask
|= 1 << StreamNumber
;
3270 state
->stream_instancedata_mask
&= ~(1 << StreamNumber
);
3272 state
->changed
.stream_freq
|= 1 << StreamNumber
;
3277 NineDevice9_GetStreamSourceFreq( struct NineDevice9
*This
,
3281 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3282 *pSetting
= This
->state
.stream_freq
[StreamNumber
];
3287 NineDevice9_SetIndices( struct NineDevice9
*This
,
3288 IDirect3DIndexBuffer9
*pIndexData
)
3290 struct nine_state
*state
= This
->update
;
3292 DBG("This=%p pIndexData=%p\n", This
, pIndexData
);
3294 if (likely(!This
->is_recording
))
3295 if (state
->idxbuf
== NineIndexBuffer9(pIndexData
))
3297 nine_bind(&state
->idxbuf
, pIndexData
);
3299 state
->changed
.group
|= NINE_STATE_IDXBUF
;
3304 /* XXX: wine/d3d9 doesn't have pBaseVertexIndex, and it doesn't make sense
3305 * here because it's an argument passed to the Draw calls.
3308 NineDevice9_GetIndices( struct NineDevice9
*This
,
3309 IDirect3DIndexBuffer9
**ppIndexData
/*,
3310 UINT *pBaseVertexIndex */ )
3312 user_assert(ppIndexData
, D3DERR_INVALIDCALL
);
3313 nine_reference_set(ppIndexData
, This
->state
.idxbuf
);
3318 NineDevice9_CreatePixelShader( struct NineDevice9
*This
,
3319 const DWORD
*pFunction
,
3320 IDirect3DPixelShader9
**ppShader
)
3322 struct NinePixelShader9
*ps
;
3325 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3327 hr
= NinePixelShader9_new(This
, &ps
, pFunction
, NULL
);
3330 *ppShader
= (IDirect3DPixelShader9
*)ps
;
3335 NineDevice9_SetPixelShader( struct NineDevice9
*This
,
3336 IDirect3DPixelShader9
*pShader
)
3338 struct nine_state
*state
= This
->update
;
3339 unsigned old_mask
= state
->ps
? state
->ps
->rt_mask
: 1;
3342 DBG("This=%p pShader=%p\n", This
, pShader
);
3344 nine_bind(&state
->ps
, pShader
);
3346 state
->changed
.group
|= NINE_STATE_PS
;
3348 mask
= state
->ps
? state
->ps
->rt_mask
: 1;
3349 /* We need to update cbufs if the pixel shader would
3350 * write to different render targets */
3351 if (mask
!= old_mask
)
3352 state
->changed
.group
|= NINE_STATE_FB
;
3358 NineDevice9_GetPixelShader( struct NineDevice9
*This
,
3359 IDirect3DPixelShader9
**ppShader
)
3361 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3362 nine_reference_set(ppShader
, This
->state
.ps
);
3367 NineDevice9_SetPixelShaderConstantF( struct NineDevice9
*This
,
3369 const float *pConstantData
,
3370 UINT Vector4fCount
)
3372 struct nine_state
*state
= This
->update
;
3374 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3375 This
, StartRegister
, pConstantData
, Vector4fCount
);
3377 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3378 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3382 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3384 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3386 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3388 nine_ranges_insert(&state
->changed
.ps_const_f
,
3389 StartRegister
, StartRegister
+ Vector4fCount
,
3392 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3398 NineDevice9_GetPixelShaderConstantF( struct NineDevice9
*This
,
3400 float *pConstantData
,
3401 UINT Vector4fCount
)
3403 const struct nine_state
*state
= &This
->state
;
3405 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3406 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3407 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3409 memcpy(pConstantData
,
3410 &state
->ps_const_f
[StartRegister
* 4],
3411 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3417 NineDevice9_SetPixelShaderConstantI( struct NineDevice9
*This
,
3419 const int *pConstantData
,
3420 UINT Vector4iCount
)
3422 struct nine_state
*state
= This
->update
;
3425 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3426 This
, StartRegister
, pConstantData
, Vector4iCount
);
3428 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3429 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3430 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3432 if (This
->driver_caps
.ps_integer
) {
3433 memcpy(&state
->ps_const_i
[StartRegister
][0],
3435 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3437 for (i
= 0; i
< Vector4iCount
; i
++) {
3438 state
->ps_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3439 state
->ps_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3440 state
->ps_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3441 state
->ps_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3444 state
->changed
.ps_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3445 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3451 NineDevice9_GetPixelShaderConstantI( struct NineDevice9
*This
,
3454 UINT Vector4iCount
)
3456 const struct nine_state
*state
= &This
->state
;
3459 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3460 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3461 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3463 if (This
->driver_caps
.ps_integer
) {
3464 memcpy(pConstantData
,
3465 &state
->ps_const_i
[StartRegister
][0],
3466 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3468 for (i
= 0; i
< Vector4iCount
; i
++) {
3469 pConstantData
[4*i
] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][0]);
3470 pConstantData
[4*i
+1] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][1]);
3471 pConstantData
[4*i
+2] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][2]);
3472 pConstantData
[4*i
+3] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][3]);
3480 NineDevice9_SetPixelShaderConstantB( struct NineDevice9
*This
,
3482 const BOOL
*pConstantData
,
3485 struct nine_state
*state
= This
->update
;
3487 uint32_t bool_true
= This
->driver_caps
.ps_integer
? 0xFFFFFFFF : fui(1.0f
);
3489 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3490 This
, StartRegister
, pConstantData
, BoolCount
);
3492 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3493 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3494 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3496 for (i
= 0; i
< BoolCount
; i
++)
3497 state
->ps_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3499 state
->changed
.ps_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3500 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3506 NineDevice9_GetPixelShaderConstantB( struct NineDevice9
*This
,
3508 BOOL
*pConstantData
,
3511 const struct nine_state
*state
= &This
->state
;
3514 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3515 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3516 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3518 for (i
= 0; i
< BoolCount
; i
++)
3519 pConstantData
[i
] = state
->ps_const_b
[StartRegister
+ i
] ? TRUE
: FALSE
;
3525 NineDevice9_DrawRectPatch( struct NineDevice9
*This
,
3527 const float *pNumSegs
,
3528 const D3DRECTPATCH_INFO
*pRectPatchInfo
)
3530 STUB(D3DERR_INVALIDCALL
);
3534 NineDevice9_DrawTriPatch( struct NineDevice9
*This
,
3536 const float *pNumSegs
,
3537 const D3DTRIPATCH_INFO
*pTriPatchInfo
)
3539 STUB(D3DERR_INVALIDCALL
);
3543 NineDevice9_DeletePatch( struct NineDevice9
*This
,
3546 STUB(D3DERR_INVALIDCALL
);
3550 NineDevice9_CreateQuery( struct NineDevice9
*This
,
3552 IDirect3DQuery9
**ppQuery
)
3554 struct NineQuery9
*query
;
3557 DBG("This=%p Type=%d ppQuery=%p\n", This
, Type
, ppQuery
);
3559 hr
= nine_is_query_supported(This
->screen
, Type
);
3560 if (!ppQuery
|| hr
!= D3D_OK
)
3563 hr
= NineQuery9_new(This
, &query
, Type
);
3566 *ppQuery
= (IDirect3DQuery9
*)query
;
3570 IDirect3DDevice9Vtbl NineDevice9_vtable
= {
3571 (void *)NineUnknown_QueryInterface
,
3572 (void *)NineUnknown_AddRef
,
3573 (void *)NineUnknown_Release
,
3574 (void *)NineDevice9_TestCooperativeLevel
,
3575 (void *)NineDevice9_GetAvailableTextureMem
,
3576 (void *)NineDevice9_EvictManagedResources
,
3577 (void *)NineDevice9_GetDirect3D
,
3578 (void *)NineDevice9_GetDeviceCaps
,
3579 (void *)NineDevice9_GetDisplayMode
,
3580 (void *)NineDevice9_GetCreationParameters
,
3581 (void *)NineDevice9_SetCursorProperties
,
3582 (void *)NineDevice9_SetCursorPosition
,
3583 (void *)NineDevice9_ShowCursor
,
3584 (void *)NineDevice9_CreateAdditionalSwapChain
,
3585 (void *)NineDevice9_GetSwapChain
,
3586 (void *)NineDevice9_GetNumberOfSwapChains
,
3587 (void *)NineDevice9_Reset
,
3588 (void *)NineDevice9_Present
,
3589 (void *)NineDevice9_GetBackBuffer
,
3590 (void *)NineDevice9_GetRasterStatus
,
3591 (void *)NineDevice9_SetDialogBoxMode
,
3592 (void *)NineDevice9_SetGammaRamp
,
3593 (void *)NineDevice9_GetGammaRamp
,
3594 (void *)NineDevice9_CreateTexture
,
3595 (void *)NineDevice9_CreateVolumeTexture
,
3596 (void *)NineDevice9_CreateCubeTexture
,
3597 (void *)NineDevice9_CreateVertexBuffer
,
3598 (void *)NineDevice9_CreateIndexBuffer
,
3599 (void *)NineDevice9_CreateRenderTarget
,
3600 (void *)NineDevice9_CreateDepthStencilSurface
,
3601 (void *)NineDevice9_UpdateSurface
,
3602 (void *)NineDevice9_UpdateTexture
,
3603 (void *)NineDevice9_GetRenderTargetData
,
3604 (void *)NineDevice9_GetFrontBufferData
,
3605 (void *)NineDevice9_StretchRect
,
3606 (void *)NineDevice9_ColorFill
,
3607 (void *)NineDevice9_CreateOffscreenPlainSurface
,
3608 (void *)NineDevice9_SetRenderTarget
,
3609 (void *)NineDevice9_GetRenderTarget
,
3610 (void *)NineDevice9_SetDepthStencilSurface
,
3611 (void *)NineDevice9_GetDepthStencilSurface
,
3612 (void *)NineDevice9_BeginScene
,
3613 (void *)NineDevice9_EndScene
,
3614 (void *)NineDevice9_Clear
,
3615 (void *)NineDevice9_SetTransform
,
3616 (void *)NineDevice9_GetTransform
,
3617 (void *)NineDevice9_MultiplyTransform
,
3618 (void *)NineDevice9_SetViewport
,
3619 (void *)NineDevice9_GetViewport
,
3620 (void *)NineDevice9_SetMaterial
,
3621 (void *)NineDevice9_GetMaterial
,
3622 (void *)NineDevice9_SetLight
,
3623 (void *)NineDevice9_GetLight
,
3624 (void *)NineDevice9_LightEnable
,
3625 (void *)NineDevice9_GetLightEnable
,
3626 (void *)NineDevice9_SetClipPlane
,
3627 (void *)NineDevice9_GetClipPlane
,
3628 (void *)NineDevice9_SetRenderState
,
3629 (void *)NineDevice9_GetRenderState
,
3630 (void *)NineDevice9_CreateStateBlock
,
3631 (void *)NineDevice9_BeginStateBlock
,
3632 (void *)NineDevice9_EndStateBlock
,
3633 (void *)NineDevice9_SetClipStatus
,
3634 (void *)NineDevice9_GetClipStatus
,
3635 (void *)NineDevice9_GetTexture
,
3636 (void *)NineDevice9_SetTexture
,
3637 (void *)NineDevice9_GetTextureStageState
,
3638 (void *)NineDevice9_SetTextureStageState
,
3639 (void *)NineDevice9_GetSamplerState
,
3640 (void *)NineDevice9_SetSamplerState
,
3641 (void *)NineDevice9_ValidateDevice
,
3642 (void *)NineDevice9_SetPaletteEntries
,
3643 (void *)NineDevice9_GetPaletteEntries
,
3644 (void *)NineDevice9_SetCurrentTexturePalette
,
3645 (void *)NineDevice9_GetCurrentTexturePalette
,
3646 (void *)NineDevice9_SetScissorRect
,
3647 (void *)NineDevice9_GetScissorRect
,
3648 (void *)NineDevice9_SetSoftwareVertexProcessing
,
3649 (void *)NineDevice9_GetSoftwareVertexProcessing
,
3650 (void *)NineDevice9_SetNPatchMode
,
3651 (void *)NineDevice9_GetNPatchMode
,
3652 (void *)NineDevice9_DrawPrimitive
,
3653 (void *)NineDevice9_DrawIndexedPrimitive
,
3654 (void *)NineDevice9_DrawPrimitiveUP
,
3655 (void *)NineDevice9_DrawIndexedPrimitiveUP
,
3656 (void *)NineDevice9_ProcessVertices
,
3657 (void *)NineDevice9_CreateVertexDeclaration
,
3658 (void *)NineDevice9_SetVertexDeclaration
,
3659 (void *)NineDevice9_GetVertexDeclaration
,
3660 (void *)NineDevice9_SetFVF
,
3661 (void *)NineDevice9_GetFVF
,
3662 (void *)NineDevice9_CreateVertexShader
,
3663 (void *)NineDevice9_SetVertexShader
,
3664 (void *)NineDevice9_GetVertexShader
,
3665 (void *)NineDevice9_SetVertexShaderConstantF
,
3666 (void *)NineDevice9_GetVertexShaderConstantF
,
3667 (void *)NineDevice9_SetVertexShaderConstantI
,
3668 (void *)NineDevice9_GetVertexShaderConstantI
,
3669 (void *)NineDevice9_SetVertexShaderConstantB
,
3670 (void *)NineDevice9_GetVertexShaderConstantB
,
3671 (void *)NineDevice9_SetStreamSource
,
3672 (void *)NineDevice9_GetStreamSource
,
3673 (void *)NineDevice9_SetStreamSourceFreq
,
3674 (void *)NineDevice9_GetStreamSourceFreq
,
3675 (void *)NineDevice9_SetIndices
,
3676 (void *)NineDevice9_GetIndices
,
3677 (void *)NineDevice9_CreatePixelShader
,
3678 (void *)NineDevice9_SetPixelShader
,
3679 (void *)NineDevice9_GetPixelShader
,
3680 (void *)NineDevice9_SetPixelShaderConstantF
,
3681 (void *)NineDevice9_GetPixelShaderConstantF
,
3682 (void *)NineDevice9_SetPixelShaderConstantI
,
3683 (void *)NineDevice9_GetPixelShaderConstantI
,
3684 (void *)NineDevice9_SetPixelShaderConstantB
,
3685 (void *)NineDevice9_GetPixelShaderConstantB
,
3686 (void *)NineDevice9_DrawRectPatch
,
3687 (void *)NineDevice9_DrawTriPatch
,
3688 (void *)NineDevice9_DeletePatch
,
3689 (void *)NineDevice9_CreateQuery
3692 static const GUID
*NineDevice9_IIDs
[] = {
3693 &IID_IDirect3DDevice9
,
3699 NineDevice9_new( struct pipe_screen
*pScreen
,
3700 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
3702 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
3704 ID3DPresentGroup
*pPresentationGroup
,
3705 struct d3dadapter9_context
*pCTX
,
3707 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
3708 struct NineDevice9
**ppOut
)
3711 lock
= !!(pCreationParameters
->BehaviorFlags
& D3DCREATE_MULTITHREADED
);
3713 NINE_NEW(Device9
, ppOut
, lock
, /* args */
3714 pScreen
, pCreationParameters
, pCaps
,
3715 pPresentationParameters
, pD3D9
, pPresentationGroup
, pCTX
,
3716 ex
, pFullscreenDisplayMode
);