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 "pipe/p_config.h"
45 #include "util/u_math.h"
46 #include "util/u_inlines.h"
47 #include "util/u_hash_table.h"
48 #include "util/u_format.h"
49 #include "util/u_surface.h"
50 #include "util/u_upload_mgr.h"
51 #include "hud/hud_context.h"
53 #include "cso_cache/cso_context.h"
55 #define DBG_CHANNEL DBG_DEVICE
57 #if defined(PIPE_CC_GCC) && (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64))
59 #include <fpu_control.h>
61 static void nine_setup_fpu()
66 /* clear the control word */
68 /* d3d9 doc/wine tests: mask all exceptions, use single-precision
69 * and round to nearest */
70 c
|= _FPU_MASK_IM
| _FPU_MASK_DM
| _FPU_MASK_ZM
| _FPU_MASK_OM
|
71 _FPU_MASK_UM
| _FPU_MASK_PM
| _FPU_SINGLE
| _FPU_RC_NEAREST
;
77 static void nine_setup_fpu(void)
79 WARN_ONCE("FPU setup not supported on non-x86 platforms\n");
85 NineDevice9_SetDefaultState( struct NineDevice9
*This
, boolean is_reset
)
87 struct NineSurface9
*refSurf
= NULL
;
89 DBG("This=%p is_reset=%d\n", This
, (int) is_reset
);
91 assert(!This
->is_recording
);
93 nine_state_set_defaults(This
, &This
->caps
, is_reset
);
95 This
->state
.viewport
.X
= 0;
96 This
->state
.viewport
.Y
= 0;
97 This
->state
.viewport
.Width
= 0;
98 This
->state
.viewport
.Height
= 0;
100 This
->state
.scissor
.minx
= 0;
101 This
->state
.scissor
.miny
= 0;
102 This
->state
.scissor
.maxx
= 0xffff;
103 This
->state
.scissor
.maxy
= 0xffff;
105 if (This
->nswapchains
&& This
->swapchains
[0]->params
.BackBufferCount
)
106 refSurf
= This
->swapchains
[0]->buffers
[0];
109 This
->state
.viewport
.Width
= refSurf
->desc
.Width
;
110 This
->state
.viewport
.Height
= refSurf
->desc
.Height
;
111 This
->state
.scissor
.maxx
= refSurf
->desc
.Width
;
112 This
->state
.scissor
.maxy
= refSurf
->desc
.Height
;
115 if (This
->nswapchains
&& This
->swapchains
[0]->params
.EnableAutoDepthStencil
)
116 This
->state
.rs
[D3DRS_ZENABLE
] = TRUE
;
117 if (This
->state
.rs
[D3DRS_ZENABLE
])
118 NineDevice9_SetDepthStencilSurface(
119 This
, (IDirect3DSurface9
*)This
->swapchains
[0]->zsbuf
);
123 NineDevice9_RestoreNonCSOState( struct NineDevice9
*This
, unsigned mask
)
125 struct pipe_context
*pipe
= This
->pipe
;
127 DBG("This=%p mask=%u\n", This
, mask
);
130 struct pipe_constant_buffer cb
;
131 cb
.buffer_offset
= 0;
133 if (This
->prefer_user_constbuf
) {
135 cb
.user_buffer
= This
->state
.vs_const_f
;
137 cb
.buffer
= This
->constbuf_vs
;
138 cb
.user_buffer
= NULL
;
140 cb
.buffer_size
= This
->vs_const_size
;
141 pipe
->set_constant_buffer(pipe
, PIPE_SHADER_VERTEX
, 0, &cb
);
143 if (This
->prefer_user_constbuf
) {
144 cb
.user_buffer
= This
->state
.ps_const_f
;
146 cb
.buffer
= This
->constbuf_ps
;
148 cb
.buffer_size
= This
->ps_const_size
;
149 pipe
->set_constant_buffer(pipe
, PIPE_SHADER_FRAGMENT
, 0, &cb
);
153 struct pipe_poly_stipple stipple
;
154 memset(&stipple
, ~0, sizeof(stipple
));
155 pipe
->set_polygon_stipple(pipe
, &stipple
);
158 This
->state
.changed
.group
= NINE_STATE_ALL
;
159 This
->state
.changed
.vtxbuf
= (1ULL << This
->caps
.MaxStreams
) - 1;
160 This
->state
.changed
.ucp
= (1 << PIPE_MAX_CLIP_PLANES
) - 1;
161 This
->state
.changed
.texture
= NINE_PS_SAMPLERS_MASK
| NINE_VS_SAMPLERS_MASK
;
164 #define GET_PCAP(n) pScreen->get_param(pScreen, PIPE_CAP_##n)
166 NineDevice9_ctor( struct NineDevice9
*This
,
167 struct NineUnknownParams
*pParams
,
168 struct pipe_screen
*pScreen
,
169 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
171 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
173 ID3DPresentGroup
*pPresentationGroup
,
174 struct d3dadapter9_context
*pCTX
,
176 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
)
179 HRESULT hr
= NineUnknown_ctor(&This
->base
, pParams
);
181 DBG("This=%p pParams=%p pScreen=%p pCreationParameters=%p pCaps=%p pPresentationParameters=%p "
182 "pD3D9=%p pPresentationGroup=%p pCTX=%p ex=%d pFullscreenDisplayMode=%p\n",
183 This
, pParams
, pScreen
, pCreationParameters
, pCaps
, pPresentationParameters
, pD3D9
,
184 pPresentationGroup
, pCTX
, (int) ex
, pFullscreenDisplayMode
);
186 if (FAILED(hr
)) { return hr
; }
188 list_inithead(&This
->update_textures
);
189 list_inithead(&This
->managed_textures
);
191 This
->screen
= pScreen
;
194 This
->params
= *pCreationParameters
;
196 This
->present
= pPresentationGroup
;
197 IDirect3D9_AddRef(This
->d3d9
);
198 ID3DPresentGroup_AddRef(This
->present
);
200 if (!(This
->params
.BehaviorFlags
& D3DCREATE_FPU_PRESERVE
))
203 if (This
->params
.BehaviorFlags
& D3DCREATE_SOFTWARE_VERTEXPROCESSING
)
204 DBG("Application asked full Software Vertex Processing. Ignoring.\n");
205 if (This
->params
.BehaviorFlags
& D3DCREATE_MIXED_VERTEXPROCESSING
)
206 DBG("Application asked mixed Software Vertex Processing. Ignoring.\n");
208 This
->pipe
= This
->screen
->context_create(This
->screen
, NULL
);
209 if (!This
->pipe
) { return E_OUTOFMEMORY
; } /* guess */
211 This
->cso
= cso_create_context(This
->pipe
);
212 if (!This
->cso
) { return E_OUTOFMEMORY
; } /* also a guess */
214 /* Create first, it messes up our state. */
215 This
->hud
= hud_create(This
->pipe
, This
->cso
); /* NULL result is fine */
217 /* create implicit swapchains */
218 This
->nswapchains
= ID3DPresentGroup_GetMultiheadCount(This
->present
);
219 This
->swapchains
= CALLOC(This
->nswapchains
,
220 sizeof(struct NineSwapChain9
*));
221 if (!This
->swapchains
) { return E_OUTOFMEMORY
; }
223 for (i
= 0; i
< This
->nswapchains
; ++i
) {
224 ID3DPresent
*present
;
226 hr
= ID3DPresentGroup_GetPresent(This
->present
, i
, &present
);
231 D3DDISPLAYMODEEX
*mode
= NULL
;
232 struct NineSwapChain9Ex
**ret
=
233 (struct NineSwapChain9Ex
**)&This
->swapchains
[i
];
235 if (pFullscreenDisplayMode
) mode
= &(pFullscreenDisplayMode
[i
]);
236 /* when this is a Device9Ex, it should create SwapChain9Exs */
237 hr
= NineSwapChain9Ex_new(This
, TRUE
, present
,
238 &pPresentationParameters
[i
], pCTX
,
239 This
->params
.hFocusWindow
, mode
, ret
);
241 hr
= NineSwapChain9_new(This
, TRUE
, present
,
242 &pPresentationParameters
[i
], pCTX
,
243 This
->params
.hFocusWindow
,
244 &This
->swapchains
[i
]);
247 ID3DPresent_Release(present
);
250 NineUnknown_ConvertRefToBind(NineUnknown(This
->swapchains
[i
]));
252 hr
= NineSwapChain9_GetBackBuffer(This
->swapchains
[i
], 0,
253 D3DBACKBUFFER_TYPE_MONO
,
254 (IDirect3DSurface9
**)
258 NineUnknown_ConvertRefToBind(NineUnknown(This
->state
.rt
[i
]));
261 /* Initialize a dummy VBO to be used when a a vertex declaration does not
262 * specify all the inputs needed by vertex shader, on win default behavior
263 * is to pass 0,0,0,0 to the shader */
265 struct pipe_transfer
*transfer
;
266 struct pipe_resource tmpl
;
270 tmpl
.target
= PIPE_BUFFER
;
271 tmpl
.format
= PIPE_FORMAT_R8_UNORM
;
272 tmpl
.width0
= 16; /* 4 floats */
278 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
279 tmpl
.bind
= PIPE_BIND_VERTEX_BUFFER
| PIPE_BIND_TRANSFER_WRITE
;
281 This
->dummy_vbo
= pScreen
->resource_create(pScreen
, &tmpl
);
283 if (!This
->dummy_vbo
)
284 return D3DERR_OUTOFVIDEOMEMORY
;
286 u_box_1d(0, 16, &box
);
287 data
= This
->pipe
->transfer_map(This
->pipe
, This
->dummy_vbo
, 0,
288 PIPE_TRANSFER_WRITE
|
289 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
294 This
->pipe
->transfer_unmap(This
->pipe
, transfer
);
297 This
->cursor
.software
= FALSE
;
298 This
->cursor
.hotspot
.x
= -1;
299 This
->cursor
.hotspot
.y
= -1;
301 struct pipe_resource tmpl
;
302 tmpl
.target
= PIPE_TEXTURE_2D
;
303 tmpl
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
310 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
311 tmpl
.bind
= PIPE_BIND_CURSOR
| PIPE_BIND_SAMPLER_VIEW
;
314 This
->cursor
.image
= pScreen
->resource_create(pScreen
, &tmpl
);
315 if (!This
->cursor
.image
)
316 return D3DERR_OUTOFVIDEOMEMORY
;
319 /* Create constant buffers. */
321 struct pipe_resource tmpl
;
322 unsigned max_const_vs
, max_const_ps
;
324 /* vs 3.0: >= 256 float constants, but for cards with exactly 256 slots,
325 * we have to take in some more slots for int and bool*/
326 max_const_vs
= _min(pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
,
327 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
) /
330 /* ps 3.0: 224 float constants. All cards supported support at least
331 * 256 constants for ps */
332 max_const_ps
= NINE_MAX_CONST_F_PS3
+ (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
334 This
->max_vs_const_f
= max_const_vs
-
335 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
336 This
->max_ps_const_f
= max_const_ps
-
337 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
339 This
->vs_const_size
= max_const_vs
* sizeof(float[4]);
340 This
->ps_const_size
= max_const_ps
* sizeof(float[4]);
341 /* Include space for I,B constants for user constbuf. */
342 This
->state
.vs_const_f
= CALLOC(This
->vs_const_size
, 1);
343 This
->state
.ps_const_f
= CALLOC(This
->ps_const_size
, 1);
344 This
->state
.vs_lconstf_temp
= CALLOC(This
->vs_const_size
,1);
345 if (!This
->state
.vs_const_f
|| !This
->state
.ps_const_f
||
346 !This
->state
.vs_lconstf_temp
)
347 return E_OUTOFMEMORY
;
349 if (strstr(pScreen
->get_name(pScreen
), "AMD") ||
350 strstr(pScreen
->get_name(pScreen
), "ATI")) {
351 This
->prefer_user_constbuf
= TRUE
;
352 This
->driver_bugs
.buggy_barycentrics
= TRUE
;
355 tmpl
.target
= PIPE_BUFFER
;
356 tmpl
.format
= PIPE_FORMAT_R8_UNORM
;
362 tmpl
.usage
= PIPE_USAGE_DYNAMIC
;
363 tmpl
.bind
= PIPE_BIND_CONSTANT_BUFFER
;
366 tmpl
.width0
= This
->vs_const_size
;
367 This
->constbuf_vs
= pScreen
->resource_create(pScreen
, &tmpl
);
369 tmpl
.width0
= This
->ps_const_size
;
370 This
->constbuf_ps
= pScreen
->resource_create(pScreen
, &tmpl
);
372 if (!This
->constbuf_vs
|| !This
->constbuf_ps
)
373 return E_OUTOFMEMORY
;
376 /* allocate dummy texture/sampler for when there are missing ones bound */
378 struct pipe_resource tmplt
;
379 struct pipe_sampler_view templ
;
381 tmplt
.target
= PIPE_TEXTURE_2D
;
385 tmplt
.last_level
= 0;
386 tmplt
.array_size
= 1;
387 tmplt
.usage
= PIPE_USAGE_DEFAULT
;
389 tmplt
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
390 tmplt
.bind
= PIPE_BIND_SAMPLER_VIEW
;
391 tmplt
.nr_samples
= 0;
393 This
->dummy_texture
= This
->screen
->resource_create(This
->screen
, &tmplt
);
394 if (!This
->dummy_texture
)
395 return D3DERR_DRIVERINTERNALERROR
;
397 templ
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
398 templ
.u
.tex
.first_layer
= 0;
399 templ
.u
.tex
.last_layer
= 0;
400 templ
.u
.tex
.first_level
= 0;
401 templ
.u
.tex
.last_level
= 0;
402 templ
.swizzle_r
= PIPE_SWIZZLE_ZERO
;
403 templ
.swizzle_g
= PIPE_SWIZZLE_ZERO
;
404 templ
.swizzle_b
= PIPE_SWIZZLE_ZERO
;
405 templ
.swizzle_a
= PIPE_SWIZZLE_ONE
;
406 templ
.target
= This
->dummy_texture
->target
;
408 This
->dummy_sampler
= This
->pipe
->create_sampler_view(This
->pipe
, This
->dummy_texture
, &templ
);
409 if (!This
->dummy_sampler
)
410 return D3DERR_DRIVERINTERNALERROR
;
413 /* Allocate upload helper for drivers that suck (from st pov ;). */
417 This
->driver_caps
.user_vbufs
= GET_PCAP(USER_VERTEX_BUFFERS
);
418 This
->driver_caps
.user_ibufs
= GET_PCAP(USER_INDEX_BUFFERS
);
420 if (!This
->driver_caps
.user_vbufs
) bind
|= PIPE_BIND_VERTEX_BUFFER
;
421 if (!This
->driver_caps
.user_ibufs
) bind
|= PIPE_BIND_INDEX_BUFFER
;
423 This
->upload
= u_upload_create(This
->pipe
, 1 << 20, 4, bind
);
426 This
->driver_caps
.window_space_position_support
= GET_PCAP(TGSI_VS_WINDOW_SPACE_POSITION
);
427 This
->driver_caps
.vs_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
, PIPE_SHADER_CAP_INTEGERS
);
428 This
->driver_caps
.ps_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_FRAGMENT
, PIPE_SHADER_CAP_INTEGERS
);
430 nine_ff_init(This
); /* initialize fixed function code */
432 NineDevice9_SetDefaultState(This
, FALSE
);
433 NineDevice9_RestoreNonCSOState(This
, ~0);
435 This
->update
= &This
->state
;
436 nine_update_state(This
, ~0);
438 ID3DPresentGroup_Release(This
->present
);
445 NineDevice9_dtor( struct NineDevice9
*This
)
449 DBG("This=%p\n", This
);
451 if (This
->pipe
&& This
->cso
)
452 nine_pipe_context_clear(This
);
454 nine_state_clear(&This
->state
, TRUE
);
457 u_upload_destroy(This
->upload
);
459 nine_bind(&This
->record
, NULL
);
461 pipe_sampler_view_reference(&This
->dummy_sampler
, NULL
);
462 pipe_resource_reference(&This
->dummy_texture
, NULL
);
463 pipe_resource_reference(&This
->constbuf_vs
, NULL
);
464 pipe_resource_reference(&This
->constbuf_ps
, NULL
);
465 pipe_resource_reference(&This
->dummy_vbo
, NULL
);
466 FREE(This
->state
.vs_const_f
);
467 FREE(This
->state
.ps_const_f
);
468 FREE(This
->state
.vs_lconstf_temp
);
470 if (This
->swapchains
) {
471 for (i
= 0; i
< This
->nswapchains
; ++i
)
472 NineUnknown_Unbind(NineUnknown(This
->swapchains
[i
]));
473 FREE(This
->swapchains
);
479 cso_destroy_context(This
->cso
);
481 if (This
->pipe
->destroy
) { This
->pipe
->destroy(This
->pipe
); }
484 if (This
->present
) { ID3DPresentGroup_Release(This
->present
); }
485 if (This
->d3d9
) { IDirect3D9_Release(This
->d3d9
); }
487 NineUnknown_dtor(&This
->base
);
491 NineDevice9_GetScreen( struct NineDevice9
*This
)
496 struct pipe_context
*
497 NineDevice9_GetPipe( struct NineDevice9
*This
)
503 NineDevice9_GetCSO( struct NineDevice9
*This
)
509 NineDevice9_GetCaps( struct NineDevice9
*This
)
515 NineDevice9_PauseRecording( struct NineDevice9
*This
)
518 This
->update
= &This
->state
;
519 This
->is_recording
= FALSE
;
524 NineDevice9_ResumeRecording( struct NineDevice9
*This
)
527 This
->update
= &This
->record
->state
;
528 This
->is_recording
= TRUE
;
533 NineDevice9_TestCooperativeLevel( struct NineDevice9
*This
)
535 return D3D_OK
; /* TODO */
539 NineDevice9_GetAvailableTextureMem( struct NineDevice9
*This
)
541 const unsigned mem
= This
->screen
->get_param(This
->screen
, PIPE_CAP_VIDEO_MEMORY
);
549 NineDevice9_EvictManagedResources( struct NineDevice9
*This
)
551 struct NineBaseTexture9
*tex
;
553 DBG("This=%p\n", This
);
554 LIST_FOR_EACH_ENTRY(tex
, &This
->managed_textures
, list2
) {
555 NineBaseTexture9_UnLoad(tex
);
562 NineDevice9_GetDirect3D( struct NineDevice9
*This
,
563 IDirect3D9
**ppD3D9
)
565 user_assert(ppD3D9
!= NULL
, E_POINTER
);
566 IDirect3D9_AddRef(This
->d3d9
);
567 *ppD3D9
= This
->d3d9
;
572 NineDevice9_GetDeviceCaps( struct NineDevice9
*This
,
575 user_assert(pCaps
!= NULL
, D3DERR_INVALIDCALL
);
581 NineDevice9_GetDisplayMode( struct NineDevice9
*This
,
583 D3DDISPLAYMODE
*pMode
)
585 DBG("This=%p iSwapChain=%u pMode=%p\n", This
, iSwapChain
, pMode
);
587 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
589 return NineSwapChain9_GetDisplayMode(This
->swapchains
[iSwapChain
], pMode
);
593 NineDevice9_GetCreationParameters( struct NineDevice9
*This
,
594 D3DDEVICE_CREATION_PARAMETERS
*pParameters
)
596 user_assert(pParameters
!= NULL
, D3DERR_INVALIDCALL
);
597 *pParameters
= This
->params
;
602 NineDevice9_SetCursorProperties( struct NineDevice9
*This
,
605 IDirect3DSurface9
*pCursorBitmap
)
607 struct NineSurface9
*surf
= NineSurface9(pCursorBitmap
);
608 struct pipe_context
*pipe
= This
->pipe
;
610 struct pipe_transfer
*transfer
;
614 DBG_FLAG(DBG_SWAPCHAIN
, "This=%p XHotSpot=%u YHotSpot=%u "
615 "pCursorBitmap=%p\n", This
, XHotSpot
, YHotSpot
, pCursorBitmap
);
617 user_assert(pCursorBitmap
, D3DERR_INVALIDCALL
);
619 if (This
->swapchains
[0]->params
.Windowed
) {
620 This
->cursor
.w
= MIN2(surf
->desc
.Width
, 32);
621 This
->cursor
.h
= MIN2(surf
->desc
.Height
, 32);
622 hw_cursor
= 1; /* always use hw cursor for windowed mode */
624 This
->cursor
.w
= MIN2(surf
->desc
.Width
, This
->cursor
.image
->width0
);
625 This
->cursor
.h
= MIN2(surf
->desc
.Height
, This
->cursor
.image
->height0
);
626 hw_cursor
= This
->cursor
.w
== 32 && This
->cursor
.h
== 32;
629 u_box_origin_2d(This
->cursor
.w
, This
->cursor
.h
, &box
);
631 ptr
= pipe
->transfer_map(pipe
, This
->cursor
.image
, 0,
632 PIPE_TRANSFER_WRITE
|
633 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
636 ret_err("Failed to update cursor image.\n", D3DERR_DRIVERINTERNALERROR
);
638 This
->cursor
.hotspot
.x
= XHotSpot
;
639 This
->cursor
.hotspot
.y
= YHotSpot
;
641 /* Copy cursor image to internal storage. */
645 const struct util_format_description
*sfmt
=
646 util_format_description(surf
->base
.info
.format
);
649 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, D3DLOCK_READONLY
);
651 ret_err("Failed to map cursor source image.\n",
652 D3DERR_DRIVERINTERNALERROR
);
654 sfmt
->unpack_rgba_8unorm(ptr
, transfer
->stride
,
655 lock
.pBits
, lock
.Pitch
,
656 This
->cursor
.w
, This
->cursor
.h
);
659 hw_cursor
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
,
661 &This
->cursor
.hotspot
,
662 This
->cursor
.visible
) == D3D_OK
;
664 NineSurface9_UnlockRect(surf
);
666 pipe
->transfer_unmap(pipe
, transfer
);
668 /* hide cursor if we emulate it */
670 ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, FALSE
);
671 This
->cursor
.software
= !hw_cursor
;
677 NineDevice9_SetCursorPosition( struct NineDevice9
*This
,
682 struct NineSwapChain9
*swap
= This
->swapchains
[0];
684 DBG("This=%p X=%d Y=%d Flags=%d\n", This
, X
, Y
, Flags
);
686 This
->cursor
.pos
.x
= X
;
687 This
->cursor
.pos
.y
= Y
;
689 if (!This
->cursor
.software
)
690 This
->cursor
.software
= ID3DPresent_SetCursorPos(swap
->present
, &This
->cursor
.pos
) != D3D_OK
;
694 NineDevice9_ShowCursor( struct NineDevice9
*This
,
697 BOOL old
= This
->cursor
.visible
;
699 DBG("This=%p bShow=%d\n", This
, (int) bShow
);
701 This
->cursor
.visible
= bShow
&& (This
->cursor
.hotspot
.x
!= -1);
702 if (!This
->cursor
.software
)
703 This
->cursor
.software
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, bShow
) != D3D_OK
;
709 NineDevice9_CreateAdditionalSwapChain( struct NineDevice9
*This
,
710 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
711 IDirect3DSwapChain9
**pSwapChain
)
713 struct NineSwapChain9
*swapchain
, *tmplt
= This
->swapchains
[0];
714 ID3DPresent
*present
;
717 DBG("This=%p pPresentationParameters=%p pSwapChain=%p\n",
718 This
, pPresentationParameters
, pSwapChain
);
720 user_assert(pPresentationParameters
, D3DERR_INVALIDCALL
);
722 hr
= ID3DPresentGroup_CreateAdditionalPresent(This
->present
, pPresentationParameters
, &present
);
727 hr
= NineSwapChain9_new(This
, FALSE
, present
, pPresentationParameters
,
729 tmplt
->params
.hDeviceWindow
,
734 *pSwapChain
= (IDirect3DSwapChain9
*)swapchain
;
739 NineDevice9_GetSwapChain( struct NineDevice9
*This
,
741 IDirect3DSwapChain9
**pSwapChain
)
743 user_assert(pSwapChain
!= NULL
, D3DERR_INVALIDCALL
);
746 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
748 NineUnknown_AddRef(NineUnknown(This
->swapchains
[iSwapChain
]));
749 *pSwapChain
= (IDirect3DSwapChain9
*)This
->swapchains
[iSwapChain
];
755 NineDevice9_GetNumberOfSwapChains( struct NineDevice9
*This
)
757 return This
->nswapchains
;
761 NineDevice9_Reset( struct NineDevice9
*This
,
762 D3DPRESENT_PARAMETERS
*pPresentationParameters
)
767 DBG("This=%p pPresentationParameters=%p\n", This
, pPresentationParameters
);
769 for (i
= 0; i
< This
->nswapchains
; ++i
) {
770 D3DPRESENT_PARAMETERS
*params
= &pPresentationParameters
[i
];
771 hr
= NineSwapChain9_Resize(This
->swapchains
[i
], params
, NULL
);
773 return (hr
== D3DERR_OUTOFVIDEOMEMORY
) ? hr
: D3DERR_DEVICELOST
;
776 nine_pipe_context_clear(This
);
777 nine_state_clear(&This
->state
, TRUE
);
779 NineDevice9_SetDefaultState(This
, TRUE
);
780 NineDevice9_SetRenderTarget(
781 This
, 0, (IDirect3DSurface9
*)This
->swapchains
[0]->buffers
[0]);
782 /* XXX: better use GetBackBuffer here ? */
788 NineDevice9_Present( struct NineDevice9
*This
,
789 const RECT
*pSourceRect
,
790 const RECT
*pDestRect
,
791 HWND hDestWindowOverride
,
792 const RGNDATA
*pDirtyRegion
)
797 DBG("This=%p pSourceRect=%p pDestRect=%p hDestWindowOverride=%p pDirtyRegion=%p\n",
798 This
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
800 /* XXX is this right? */
801 for (i
= 0; i
< This
->nswapchains
; ++i
) {
802 hr
= NineSwapChain9_Present(This
->swapchains
[i
], pSourceRect
, pDestRect
,
803 hDestWindowOverride
, pDirtyRegion
, 0);
804 if (FAILED(hr
)) { return hr
; }
811 NineDevice9_GetBackBuffer( struct NineDevice9
*This
,
814 D3DBACKBUFFER_TYPE Type
,
815 IDirect3DSurface9
**ppBackBuffer
)
817 user_assert(ppBackBuffer
!= NULL
, D3DERR_INVALIDCALL
);
818 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
820 return NineSwapChain9_GetBackBuffer(This
->swapchains
[iSwapChain
],
821 iBackBuffer
, Type
, ppBackBuffer
);
825 NineDevice9_GetRasterStatus( struct NineDevice9
*This
,
827 D3DRASTER_STATUS
*pRasterStatus
)
829 user_assert(pRasterStatus
!= NULL
, D3DERR_INVALIDCALL
);
830 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
832 return NineSwapChain9_GetRasterStatus(This
->swapchains
[iSwapChain
],
837 NineDevice9_SetDialogBoxMode( struct NineDevice9
*This
,
838 BOOL bEnableDialogs
)
840 STUB(D3DERR_INVALIDCALL
);
844 NineDevice9_SetGammaRamp( struct NineDevice9
*This
,
847 const D3DGAMMARAMP
*pRamp
)
849 DBG("This=%p iSwapChain=%u Flags=%x pRamp=%p\n", This
,
850 iSwapChain
, Flags
, pRamp
);
852 user_warn(iSwapChain
>= This
->nswapchains
);
855 if (pRamp
&& (iSwapChain
< This
->nswapchains
)) {
856 struct NineSwapChain9
*swap
= This
->swapchains
[iSwapChain
];
857 swap
->gamma
= *pRamp
;
858 ID3DPresent_SetGammaRamp(swap
->present
, pRamp
, swap
->params
.hDeviceWindow
);
863 NineDevice9_GetGammaRamp( struct NineDevice9
*This
,
865 D3DGAMMARAMP
*pRamp
)
867 DBG("This=%p iSwapChain=%u pRamp=%p\n", This
, iSwapChain
, pRamp
);
869 user_warn(iSwapChain
>= This
->nswapchains
);
872 if (pRamp
&& (iSwapChain
< This
->nswapchains
))
873 *pRamp
= This
->swapchains
[iSwapChain
]->gamma
;
877 NineDevice9_CreateTexture( struct NineDevice9
*This
,
884 IDirect3DTexture9
**ppTexture
,
885 HANDLE
*pSharedHandle
)
887 struct NineTexture9
*tex
;
890 DBG("This=%p Width=%u Height=%u Levels=%u Usage=%s Format=%s Pool=%s "
891 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Levels
,
892 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
893 nine_D3DPOOL_to_str(Pool
), ppTexture
, pSharedHandle
);
895 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DMAP
|
896 D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
897 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
;
900 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
901 user_assert(!pSharedHandle
|| This
->ex
, D3DERR_INVALIDCALL
);
902 /* When is used shared handle, Pool must be
903 * SYSTEMMEM with Levels 1 or DEFAULT with any Levels */
904 user_assert(!pSharedHandle
|| Pool
!= D3DPOOL_SYSTEMMEM
|| Levels
== 1,
906 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_SYSTEMMEM
|| Pool
== D3DPOOL_DEFAULT
,
908 user_assert((Usage
!= D3DUSAGE_AUTOGENMIPMAP
|| Levels
<= 1), D3DERR_INVALIDCALL
);
910 hr
= NineTexture9_new(This
, Width
, Height
, Levels
, Usage
, Format
, Pool
,
911 &tex
, pSharedHandle
);
913 *ppTexture
= (IDirect3DTexture9
*)tex
;
919 NineDevice9_CreateVolumeTexture( struct NineDevice9
*This
,
927 IDirect3DVolumeTexture9
**ppVolumeTexture
,
928 HANDLE
*pSharedHandle
)
930 struct NineVolumeTexture9
*tex
;
933 DBG("This=%p Width=%u Height=%u Depth=%u Levels=%u Usage=%s Format=%s Pool=%s "
934 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Depth
, Levels
,
935 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
936 nine_D3DPOOL_to_str(Pool
), ppVolumeTexture
, pSharedHandle
);
938 Usage
&= D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
939 D3DUSAGE_SOFTWAREPROCESSING
;
941 *ppVolumeTexture
= NULL
;
942 user_assert(Width
&& Height
&& Depth
, D3DERR_INVALIDCALL
);
943 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
945 hr
= NineVolumeTexture9_new(This
, Width
, Height
, Depth
, Levels
,
946 Usage
, Format
, Pool
, &tex
, pSharedHandle
);
948 *ppVolumeTexture
= (IDirect3DVolumeTexture9
*)tex
;
954 NineDevice9_CreateCubeTexture( struct NineDevice9
*This
,
960 IDirect3DCubeTexture9
**ppCubeTexture
,
961 HANDLE
*pSharedHandle
)
963 struct NineCubeTexture9
*tex
;
966 DBG("This=%p EdgeLength=%u Levels=%u Usage=%s Format=%s Pool=%s ppOut=%p "
967 "pSharedHandle=%p\n", This
, EdgeLength
, Levels
,
968 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
969 nine_D3DPOOL_to_str(Pool
), ppCubeTexture
, pSharedHandle
);
971 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DYNAMIC
|
972 D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
973 D3DUSAGE_SOFTWAREPROCESSING
;
975 *ppCubeTexture
= NULL
;
976 user_assert(EdgeLength
, D3DERR_INVALIDCALL
);
977 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
979 hr
= NineCubeTexture9_new(This
, EdgeLength
, Levels
, Usage
, Format
, Pool
,
980 &tex
, pSharedHandle
);
982 *ppCubeTexture
= (IDirect3DCubeTexture9
*)tex
;
988 NineDevice9_CreateVertexBuffer( struct NineDevice9
*This
,
993 IDirect3DVertexBuffer9
**ppVertexBuffer
,
994 HANDLE
*pSharedHandle
)
996 struct NineVertexBuffer9
*buf
;
998 D3DVERTEXBUFFER_DESC desc
;
1000 DBG("This=%p Length=%u Usage=%x FVF=%x Pool=%u ppOut=%p pSharedHandle=%p\n",
1001 This
, Length
, Usage
, FVF
, Pool
, ppVertexBuffer
, pSharedHandle
);
1003 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1005 desc
.Format
= D3DFMT_VERTEXDATA
;
1006 desc
.Type
= D3DRTYPE_VERTEXBUFFER
;
1007 desc
.Usage
= Usage
&
1008 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1009 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1010 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
|
1011 D3DUSAGE_WRITEONLY
);
1016 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1017 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1019 hr
= NineVertexBuffer9_new(This
, &desc
, &buf
);
1021 *ppVertexBuffer
= (IDirect3DVertexBuffer9
*)buf
;
1026 NineDevice9_CreateIndexBuffer( struct NineDevice9
*This
,
1031 IDirect3DIndexBuffer9
**ppIndexBuffer
,
1032 HANDLE
*pSharedHandle
)
1034 struct NineIndexBuffer9
*buf
;
1036 D3DINDEXBUFFER_DESC desc
;
1038 DBG("This=%p Length=%u Usage=%x Format=%s Pool=%u ppOut=%p "
1039 "pSharedHandle=%p\n", This
, Length
, Usage
,
1040 d3dformat_to_string(Format
), Pool
, ppIndexBuffer
, pSharedHandle
);
1042 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1044 desc
.Format
= Format
;
1045 desc
.Type
= D3DRTYPE_INDEXBUFFER
;
1046 desc
.Usage
= Usage
&
1047 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1048 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1049 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_WRITEONLY
);
1053 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1054 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1056 hr
= NineIndexBuffer9_new(This
, &desc
, &buf
);
1058 *ppIndexBuffer
= (IDirect3DIndexBuffer9
*)buf
;
1063 create_zs_or_rt_surface(struct NineDevice9
*This
,
1064 unsigned type
, /* 0 = RT, 1 = ZS, 2 = plain */
1066 UINT Width
, UINT Height
,
1068 D3DMULTISAMPLE_TYPE MultiSample
,
1069 DWORD MultisampleQuality
,
1070 BOOL Discard_or_Lockable
,
1071 IDirect3DSurface9
**ppSurface
,
1072 HANDLE
*pSharedHandle
)
1074 struct NineSurface9
*surface
;
1075 struct pipe_screen
*screen
= This
->screen
;
1076 struct pipe_resource
*resource
= NULL
;
1078 D3DSURFACE_DESC desc
;
1079 struct pipe_resource templ
;
1081 DBG("This=%p type=%u Pool=%s Width=%u Height=%u Format=%s MS=%u Quality=%u "
1082 "Discard_or_Lockable=%i ppSurface=%p pSharedHandle=%p\n",
1083 This
, type
, nine_D3DPOOL_to_str(Pool
), Width
, Height
,
1084 d3dformat_to_string(Format
), MultiSample
, MultisampleQuality
,
1085 Discard_or_Lockable
, ppSurface
, pSharedHandle
);
1088 DBG("FIXME Used shared handle! This option isn't probably handled correctly!\n");
1090 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
1091 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1093 templ
.target
= PIPE_TEXTURE_2D
;
1094 templ
.width0
= Width
;
1095 templ
.height0
= Height
;
1097 templ
.array_size
= 1;
1098 templ
.last_level
= 0;
1099 templ
.nr_samples
= (unsigned)MultiSample
;
1100 templ
.usage
= PIPE_USAGE_DEFAULT
;
1102 templ
.bind
= PIPE_BIND_SAMPLER_VIEW
; /* StretchRect */
1104 case 0: templ
.bind
|= PIPE_BIND_RENDER_TARGET
; break;
1105 case 1: templ
.bind
= d3d9_get_pipe_depth_format_bindings(Format
); break;
1110 templ
.format
= d3d9_to_pipe_format_checked(screen
, Format
, templ
.target
,
1111 templ
.nr_samples
, templ
.bind
,
1114 desc
.Format
= Format
;
1115 desc
.Type
= D3DRTYPE_SURFACE
;
1118 desc
.MultiSampleType
= MultiSample
;
1119 desc
.MultiSampleQuality
= MultisampleQuality
;
1121 desc
.Height
= Height
;
1123 case 0: desc
.Usage
= D3DUSAGE_RENDERTARGET
; break;
1124 case 1: desc
.Usage
= D3DUSAGE_DEPTHSTENCIL
; break;
1128 if (Pool
== D3DPOOL_DEFAULT
&& Format
!= D3DFMT_NULL
) {
1129 /* resource_create doesn't return an error code, so check format here */
1130 user_assert(templ
.format
!= PIPE_FORMAT_NONE
, D3DERR_INVALIDCALL
);
1131 resource
= screen
->resource_create(screen
, &templ
);
1132 user_assert(resource
, D3DERR_OUTOFVIDEOMEMORY
);
1133 if (Discard_or_Lockable
&& (desc
.Usage
& D3DUSAGE_RENDERTARGET
))
1134 resource
->flags
|= NINE_RESOURCE_FLAG_LOCKABLE
;
1138 hr
= NineSurface9_new(This
, NULL
, resource
, NULL
, 0, 0, 0, &desc
, &surface
);
1139 pipe_resource_reference(&resource
, NULL
);
1142 *ppSurface
= (IDirect3DSurface9
*)surface
;
1147 NineDevice9_CreateRenderTarget( struct NineDevice9
*This
,
1151 D3DMULTISAMPLE_TYPE MultiSample
,
1152 DWORD MultisampleQuality
,
1154 IDirect3DSurface9
**ppSurface
,
1155 HANDLE
*pSharedHandle
)
1158 return create_zs_or_rt_surface(This
, 0, D3DPOOL_DEFAULT
,
1159 Width
, Height
, Format
,
1160 MultiSample
, MultisampleQuality
,
1161 Lockable
, ppSurface
, pSharedHandle
);
1165 NineDevice9_CreateDepthStencilSurface( struct NineDevice9
*This
,
1169 D3DMULTISAMPLE_TYPE MultiSample
,
1170 DWORD MultisampleQuality
,
1172 IDirect3DSurface9
**ppSurface
,
1173 HANDLE
*pSharedHandle
)
1176 if (!depth_stencil_format(Format
))
1177 return D3DERR_NOTAVAILABLE
;
1178 return create_zs_or_rt_surface(This
, 1, D3DPOOL_DEFAULT
,
1179 Width
, Height
, Format
,
1180 MultiSample
, MultisampleQuality
,
1181 Discard
, ppSurface
, pSharedHandle
);
1185 NineDevice9_UpdateSurface( struct NineDevice9
*This
,
1186 IDirect3DSurface9
*pSourceSurface
,
1187 const RECT
*pSourceRect
,
1188 IDirect3DSurface9
*pDestinationSurface
,
1189 const POINT
*pDestPoint
)
1191 struct NineSurface9
*dst
= NineSurface9(pDestinationSurface
);
1192 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1193 int copy_width
, copy_height
;
1196 DBG("This=%p pSourceSurface=%p pDestinationSurface=%p "
1197 "pSourceRect=%p pDestPoint=%p\n", This
,
1198 pSourceSurface
, pDestinationSurface
, pSourceRect
, pDestPoint
);
1200 DBG("pSourceRect = (%u,%u)-(%u,%u)\n",
1201 pSourceRect
->left
, pSourceRect
->top
,
1202 pSourceRect
->right
, pSourceRect
->bottom
);
1204 DBG("pDestPoint = (%u,%u)\n", pDestPoint
->x
, pDestPoint
->y
);
1206 user_assert(dst
&& src
, D3DERR_INVALIDCALL
);
1208 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1209 user_assert(src
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1211 user_assert(dst
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1212 user_assert(src
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1214 user_assert(!src
->lock_count
, D3DERR_INVALIDCALL
);
1215 user_assert(!dst
->lock_count
, D3DERR_INVALIDCALL
);
1217 user_assert(dst
->desc
.Format
== src
->desc
.Format
, D3DERR_INVALIDCALL
);
1218 user_assert(!depth_stencil_format(dst
->desc
.Format
), D3DERR_INVALIDCALL
);
1221 copy_width
= pSourceRect
->right
- pSourceRect
->left
;
1222 copy_height
= pSourceRect
->bottom
- pSourceRect
->top
;
1224 user_assert(pSourceRect
->left
>= 0 &&
1226 pSourceRect
->right
<= src
->desc
.Width
&&
1227 pSourceRect
->top
>= 0 &&
1229 pSourceRect
->bottom
<= src
->desc
.Height
,
1230 D3DERR_INVALIDCALL
);
1232 copy_width
= src
->desc
.Width
;
1233 copy_height
= src
->desc
.Height
;
1236 destRect
.right
= copy_width
;
1237 destRect
.bottom
= copy_height
;
1240 user_assert(pDestPoint
->x
>= 0 && pDestPoint
->y
>= 0,
1241 D3DERR_INVALIDCALL
);
1242 destRect
.right
+= pDestPoint
->x
;
1243 destRect
.bottom
+= pDestPoint
->y
;
1246 user_assert(destRect
.right
<= dst
->desc
.Width
&&
1247 destRect
.bottom
<= dst
->desc
.Height
,
1248 D3DERR_INVALIDCALL
);
1250 if (compressed_format(dst
->desc
.Format
)) {
1251 const unsigned w
= util_format_get_blockwidth(dst
->base
.info
.format
);
1252 const unsigned h
= util_format_get_blockheight(dst
->base
.info
.format
);
1255 user_assert(!(pDestPoint
->x
% w
) && !(pDestPoint
->y
% h
),
1256 D3DERR_INVALIDCALL
);
1260 user_assert(!(pSourceRect
->left
% w
) && !(pSourceRect
->top
% h
),
1261 D3DERR_INVALIDCALL
);
1263 if (!(copy_width
== src
->desc
.Width
&&
1264 copy_width
== dst
->desc
.Width
&&
1265 copy_height
== src
->desc
.Height
&&
1266 copy_height
== dst
->desc
.Height
)) {
1267 user_assert(!(copy_width
% w
) && !(copy_height
% h
),
1268 D3DERR_INVALIDCALL
);
1272 NineSurface9_CopyMemToDefault(dst
, src
, pDestPoint
, pSourceRect
);
1278 NineDevice9_UpdateTexture( struct NineDevice9
*This
,
1279 IDirect3DBaseTexture9
*pSourceTexture
,
1280 IDirect3DBaseTexture9
*pDestinationTexture
)
1282 struct NineBaseTexture9
*dstb
= NineBaseTexture9(pDestinationTexture
);
1283 struct NineBaseTexture9
*srcb
= NineBaseTexture9(pSourceTexture
);
1285 unsigned last_level
= dstb
->base
.info
.last_level
;
1288 DBG("This=%p pSourceTexture=%p pDestinationTexture=%p\n", This
,
1289 pSourceTexture
, pDestinationTexture
);
1291 user_assert(pSourceTexture
!= pDestinationTexture
, D3DERR_INVALIDCALL
);
1293 user_assert(dstb
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1294 user_assert(srcb
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1296 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1297 /* Only the first level is updated, the others regenerated. */
1299 /* if the source has D3DUSAGE_AUTOGENMIPMAP, we have to ignore
1300 * the sublevels, thus level 0 has to match */
1301 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ||
1302 (srcb
->base
.info
.width0
== dstb
->base
.info
.width0
&&
1303 srcb
->base
.info
.height0
== dstb
->base
.info
.height0
&&
1304 srcb
->base
.info
.depth0
== dstb
->base
.info
.depth0
),
1305 D3DERR_INVALIDCALL
);
1307 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
), D3DERR_INVALIDCALL
);
1310 user_assert(dstb
->base
.type
== srcb
->base
.type
, D3DERR_INVALIDCALL
);
1312 /* Find src level that matches dst level 0: */
1313 user_assert(srcb
->base
.info
.width0
>= dstb
->base
.info
.width0
&&
1314 srcb
->base
.info
.height0
>= dstb
->base
.info
.height0
&&
1315 srcb
->base
.info
.depth0
>= dstb
->base
.info
.depth0
,
1316 D3DERR_INVALIDCALL
);
1317 for (m
= 0; m
<= srcb
->base
.info
.last_level
; ++m
) {
1318 unsigned w
= u_minify(srcb
->base
.info
.width0
, m
);
1319 unsigned h
= u_minify(srcb
->base
.info
.height0
, m
);
1320 unsigned d
= u_minify(srcb
->base
.info
.depth0
, m
);
1322 if (w
== dstb
->base
.info
.width0
&&
1323 h
== dstb
->base
.info
.height0
&&
1324 d
== dstb
->base
.info
.depth0
)
1327 user_assert(m
<= srcb
->base
.info
.last_level
, D3DERR_INVALIDCALL
);
1329 last_level
= MIN2(last_level
, srcb
->base
.info
.last_level
- m
);
1331 if (dstb
->base
.type
== D3DRTYPE_TEXTURE
) {
1332 struct NineTexture9
*dst
= NineTexture9(dstb
);
1333 struct NineTexture9
*src
= NineTexture9(srcb
);
1335 if (src
->dirty_rect
.width
== 0)
1338 pipe_box_to_rect(&rect
, &src
->dirty_rect
);
1339 for (l
= 0; l
< m
; ++l
)
1340 rect_minify_inclusive(&rect
);
1342 for (l
= 0; l
<= last_level
; ++l
, ++m
) {
1343 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1345 dst
->surfaces
[l
]->desc
.Width
,
1346 dst
->surfaces
[l
]->desc
.Height
);
1347 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
],
1351 rect_minify_inclusive(&rect
);
1353 u_box_origin_2d(0, 0, &src
->dirty_rect
);
1355 if (dstb
->base
.type
== D3DRTYPE_CUBETEXTURE
) {
1356 struct NineCubeTexture9
*dst
= NineCubeTexture9(dstb
);
1357 struct NineCubeTexture9
*src
= NineCubeTexture9(srcb
);
1360 /* GPUs usually have them stored as arrays of mip-mapped 2D textures. */
1361 for (z
= 0; z
< 6; ++z
) {
1362 if (src
->dirty_rect
[z
].width
== 0)
1365 pipe_box_to_rect(&rect
, &src
->dirty_rect
[z
]);
1366 for (l
= 0; l
< m
; ++l
)
1367 rect_minify_inclusive(&rect
);
1369 for (l
= 0; l
<= last_level
; ++l
, ++m
) {
1370 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1372 dst
->surfaces
[l
* 6 + z
]->desc
.Width
,
1373 dst
->surfaces
[l
* 6 + z
]->desc
.Height
);
1374 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
* 6 + z
],
1375 src
->surfaces
[m
* 6 + z
],
1378 rect_minify_inclusive(&rect
);
1380 u_box_origin_2d(0, 0, &src
->dirty_rect
[z
]);
1384 if (dstb
->base
.type
== D3DRTYPE_VOLUMETEXTURE
) {
1385 struct NineVolumeTexture9
*dst
= NineVolumeTexture9(dstb
);
1386 struct NineVolumeTexture9
*src
= NineVolumeTexture9(srcb
);
1388 if (src
->dirty_box
.width
== 0)
1390 for (l
= 0; l
<= last_level
; ++l
, ++m
)
1391 NineVolume9_CopyMemToDefault(dst
->volumes
[l
],
1392 src
->volumes
[m
], 0, 0, 0, NULL
);
1393 u_box_3d(0, 0, 0, 0, 0, 0, &src
->dirty_box
);
1395 assert(!"invalid texture type");
1398 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1399 dstb
->dirty_mip
= TRUE
;
1400 NineBaseTexture9_GenerateMipSubLevels(dstb
);
1407 NineDevice9_GetRenderTargetData( struct NineDevice9
*This
,
1408 IDirect3DSurface9
*pRenderTarget
,
1409 IDirect3DSurface9
*pDestSurface
)
1411 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1412 struct NineSurface9
*src
= NineSurface9(pRenderTarget
);
1414 DBG("This=%p pRenderTarget=%p pDestSurface=%p\n",
1415 This
, pRenderTarget
, pDestSurface
);
1417 user_assert(dst
->desc
.Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1418 user_assert(src
->desc
.Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1420 user_assert(dst
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1421 user_assert(src
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1423 user_assert(src
->desc
.Width
== dst
->desc
.Width
, D3DERR_INVALIDCALL
);
1424 user_assert(src
->desc
.Height
== dst
->desc
.Height
, D3DERR_INVALIDCALL
);
1426 NineSurface9_CopyDefaultToMem(dst
, src
);
1432 NineDevice9_GetFrontBufferData( struct NineDevice9
*This
,
1434 IDirect3DSurface9
*pDestSurface
)
1436 DBG("This=%p iSwapChain=%u pDestSurface=%p\n", This
,
1437 iSwapChain
, pDestSurface
);
1439 user_assert(pDestSurface
!= NULL
, D3DERR_INVALIDCALL
);
1440 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
1442 return NineSwapChain9_GetFrontBufferData(This
->swapchains
[iSwapChain
],
1447 NineDevice9_StretchRect( struct NineDevice9
*This
,
1448 IDirect3DSurface9
*pSourceSurface
,
1449 const RECT
*pSourceRect
,
1450 IDirect3DSurface9
*pDestSurface
,
1451 const RECT
*pDestRect
,
1452 D3DTEXTUREFILTERTYPE Filter
)
1454 struct pipe_screen
*screen
= This
->screen
;
1455 struct pipe_context
*pipe
= This
->pipe
;
1456 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1457 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1458 struct pipe_resource
*dst_res
= NineSurface9_GetResource(dst
);
1459 struct pipe_resource
*src_res
= NineSurface9_GetResource(src
);
1460 const boolean zs
= util_format_is_depth_or_stencil(dst_res
->format
);
1461 struct pipe_blit_info blit
;
1462 boolean scaled
, clamped
, ms
, flip_x
= FALSE
, flip_y
= FALSE
;
1464 DBG("This=%p pSourceSurface=%p pSourceRect=%p pDestSurface=%p "
1465 "pDestRect=%p Filter=%u\n",
1466 This
, pSourceSurface
, pSourceRect
, pDestSurface
, pDestRect
, Filter
);
1468 DBG("pSourceRect=(%u,%u)-(%u,%u)\n",
1469 pSourceRect
->left
, pSourceRect
->top
,
1470 pSourceRect
->right
, pSourceRect
->bottom
);
1472 DBG("pDestRect=(%u,%u)-(%u,%u)\n", pDestRect
->left
, pDestRect
->top
,
1473 pDestRect
->right
, pDestRect
->bottom
);
1475 user_assert(!zs
|| !This
->in_scene
, D3DERR_INVALIDCALL
);
1476 user_assert(!zs
|| !pSourceRect
||
1477 (pSourceRect
->left
== 0 &&
1478 pSourceRect
->top
== 0 &&
1479 pSourceRect
->right
== src
->desc
.Width
&&
1480 pSourceRect
->bottom
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1481 user_assert(!zs
|| !pDestRect
||
1482 (pDestRect
->left
== 0 &&
1483 pDestRect
->top
== 0 &&
1484 pDestRect
->right
== dst
->desc
.Width
&&
1485 pDestRect
->bottom
== dst
->desc
.Height
), D3DERR_INVALIDCALL
);
1487 (dst
->desc
.Width
== src
->desc
.Width
&&
1488 dst
->desc
.Height
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1489 user_assert(zs
|| !util_format_is_depth_or_stencil(src_res
->format
),
1490 D3DERR_INVALIDCALL
);
1491 user_assert(!zs
|| dst
->desc
.Format
== src
->desc
.Format
,
1492 D3DERR_INVALIDCALL
);
1493 user_assert(screen
->is_format_supported(screen
, src_res
->format
,
1495 src_res
->nr_samples
,
1496 PIPE_BIND_SAMPLER_VIEW
),
1497 D3DERR_INVALIDCALL
);
1498 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
&&
1499 src
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1501 /* We might want to permit these, but wine thinks we shouldn't. */
1502 user_assert(!pDestRect
||
1503 (pDestRect
->left
<= pDestRect
->right
&&
1504 pDestRect
->top
<= pDestRect
->bottom
), D3DERR_INVALIDCALL
);
1505 user_assert(!pSourceRect
||
1506 (pSourceRect
->left
<= pSourceRect
->right
&&
1507 pSourceRect
->top
<= pSourceRect
->bottom
), D3DERR_INVALIDCALL
);
1509 memset(&blit
, 0, sizeof(blit
));
1510 blit
.dst
.resource
= dst_res
;
1511 blit
.dst
.level
= dst
->level
;
1512 blit
.dst
.box
.z
= dst
->layer
;
1513 blit
.dst
.box
.depth
= 1;
1514 blit
.dst
.format
= dst_res
->format
;
1516 flip_x
= pDestRect
->left
> pDestRect
->right
;
1518 blit
.dst
.box
.x
= pDestRect
->right
;
1519 blit
.dst
.box
.width
= pDestRect
->left
- pDestRect
->right
;
1521 blit
.dst
.box
.x
= pDestRect
->left
;
1522 blit
.dst
.box
.width
= pDestRect
->right
- pDestRect
->left
;
1524 flip_y
= pDestRect
->top
> pDestRect
->bottom
;
1526 blit
.dst
.box
.y
= pDestRect
->bottom
;
1527 blit
.dst
.box
.height
= pDestRect
->top
- pDestRect
->bottom
;
1529 blit
.dst
.box
.y
= pDestRect
->top
;
1530 blit
.dst
.box
.height
= pDestRect
->bottom
- pDestRect
->top
;
1535 blit
.dst
.box
.width
= dst
->desc
.Width
;
1536 blit
.dst
.box
.height
= dst
->desc
.Height
;
1538 blit
.src
.resource
= src_res
;
1539 blit
.src
.level
= src
->level
;
1540 blit
.src
.box
.z
= src
->layer
;
1541 blit
.src
.box
.depth
= 1;
1542 blit
.src
.format
= src_res
->format
;
1544 if (flip_x
^ (pSourceRect
->left
> pSourceRect
->right
)) {
1545 blit
.src
.box
.x
= pSourceRect
->right
;
1546 blit
.src
.box
.width
= pSourceRect
->left
- pSourceRect
->right
;
1548 blit
.src
.box
.x
= pSourceRect
->left
;
1549 blit
.src
.box
.width
= pSourceRect
->right
- pSourceRect
->left
;
1551 if (flip_y
^ (pSourceRect
->top
> pSourceRect
->bottom
)) {
1552 blit
.src
.box
.y
= pSourceRect
->bottom
;
1553 blit
.src
.box
.height
= pSourceRect
->top
- pSourceRect
->bottom
;
1555 blit
.src
.box
.y
= pSourceRect
->top
;
1556 blit
.src
.box
.height
= pSourceRect
->bottom
- pSourceRect
->top
;
1559 blit
.src
.box
.x
= flip_x
? src
->desc
.Width
: 0;
1560 blit
.src
.box
.y
= flip_y
? src
->desc
.Height
: 0;
1561 blit
.src
.box
.width
= flip_x
? -src
->desc
.Width
: src
->desc
.Width
;
1562 blit
.src
.box
.height
= flip_y
? -src
->desc
.Height
: src
->desc
.Height
;
1564 blit
.mask
= zs
? PIPE_MASK_ZS
: PIPE_MASK_RGBA
;
1565 blit
.filter
= Filter
== D3DTEXF_LINEAR
?
1566 PIPE_TEX_FILTER_LINEAR
: PIPE_TEX_FILTER_NEAREST
;
1567 blit
.scissor_enable
= FALSE
;
1568 blit
.alpha_blend
= FALSE
;
1570 /* If both of a src and dst dimension are negative, flip them. */
1571 if (blit
.dst
.box
.width
< 0 && blit
.src
.box
.width
< 0) {
1572 blit
.dst
.box
.width
= -blit
.dst
.box
.width
;
1573 blit
.src
.box
.width
= -blit
.src
.box
.width
;
1575 if (blit
.dst
.box
.height
< 0 && blit
.src
.box
.height
< 0) {
1576 blit
.dst
.box
.height
= -blit
.dst
.box
.height
;
1577 blit
.src
.box
.height
= -blit
.src
.box
.height
;
1580 blit
.dst
.box
.width
!= blit
.src
.box
.width
||
1581 blit
.dst
.box
.height
!= blit
.src
.box
.height
;
1583 user_assert(!scaled
|| dst
!= src
, D3DERR_INVALIDCALL
);
1584 user_assert(!scaled
||
1585 !NineSurface9_IsOffscreenPlain(dst
), D3DERR_INVALIDCALL
);
1586 user_assert(!NineSurface9_IsOffscreenPlain(dst
) ||
1587 NineSurface9_IsOffscreenPlain(src
), D3DERR_INVALIDCALL
);
1588 user_assert(NineSurface9_IsOffscreenPlain(dst
) ||
1589 dst
->desc
.Usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
),
1590 D3DERR_INVALIDCALL
);
1591 user_assert(!scaled
||
1592 (!util_format_is_compressed(dst
->base
.info
.format
) &&
1593 !util_format_is_compressed(src
->base
.info
.format
)),
1594 D3DERR_INVALIDCALL
);
1596 user_warn(src
== dst
&&
1597 u_box_test_intersection_2d(&blit
.src
.box
, &blit
.dst
.box
));
1599 /* Check for clipping/clamping: */
1601 struct pipe_box box
;
1604 xy
= u_box_clip_2d(&box
, &blit
.dst
.box
,
1605 dst
->desc
.Width
, dst
->desc
.Height
);
1609 xy
= u_box_clip_2d(&box
, &blit
.src
.box
,
1610 src
->desc
.Width
, src
->desc
.Height
);
1614 ms
= (dst
->desc
.MultiSampleType
| 1) != (src
->desc
.MultiSampleType
| 1);
1616 if (clamped
|| scaled
|| (blit
.dst
.format
!= blit
.src
.format
) || ms
) {
1617 DBG("using pipe->blit()\n");
1618 /* TODO: software scaling */
1619 user_assert(screen
->is_format_supported(screen
, dst_res
->format
,
1621 dst_res
->nr_samples
,
1622 zs
? PIPE_BIND_DEPTH_STENCIL
:
1623 PIPE_BIND_RENDER_TARGET
),
1624 D3DERR_INVALIDCALL
);
1626 pipe
->blit(pipe
, &blit
);
1628 assert(blit
.dst
.box
.x
>= 0 && blit
.dst
.box
.y
>= 0 &&
1629 blit
.src
.box
.x
>= 0 && blit
.src
.box
.y
>= 0 &&
1630 blit
.dst
.box
.x
+ blit
.dst
.box
.width
<= dst
->desc
.Width
&&
1631 blit
.src
.box
.x
+ blit
.src
.box
.width
<= src
->desc
.Width
&&
1632 blit
.dst
.box
.y
+ blit
.dst
.box
.height
<= dst
->desc
.Height
&&
1633 blit
.src
.box
.y
+ blit
.src
.box
.height
<= src
->desc
.Height
);
1634 /* Or drivers might crash ... */
1635 DBG("Using resource_copy_region.\n");
1636 pipe
->resource_copy_region(pipe
,
1637 blit
.dst
.resource
, blit
.dst
.level
,
1638 blit
.dst
.box
.x
, blit
.dst
.box
.y
, blit
.dst
.box
.z
,
1639 blit
.src
.resource
, blit
.src
.level
,
1643 /* Communicate the container it needs to update sublevels - if apply */
1644 NineSurface9_MarkContainerDirty(dst
);
1650 NineDevice9_ColorFill( struct NineDevice9
*This
,
1651 IDirect3DSurface9
*pSurface
,
1655 struct pipe_context
*pipe
= This
->pipe
;
1656 struct NineSurface9
*surf
= NineSurface9(pSurface
);
1657 struct pipe_surface
*psurf
;
1658 unsigned x
, y
, w
, h
;
1659 union pipe_color_union rgba
;
1662 DBG("This=%p pSurface=%p pRect=%p color=%08x\n", This
,
1663 pSurface
, pRect
, color
);
1665 DBG("pRect=(%u,%u)-(%u,%u)\n", pRect
->left
, pRect
->top
,
1666 pRect
->right
, pRect
->bottom
);
1668 user_assert(surf
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1670 user_assert((surf
->base
.usage
& D3DUSAGE_RENDERTARGET
) ||
1671 NineSurface9_IsOffscreenPlain(surf
), D3DERR_INVALIDCALL
);
1676 w
= pRect
->right
- pRect
->left
;
1677 h
= pRect
->bottom
- pRect
->top
;
1681 w
= surf
->desc
.Width
;
1682 h
= surf
->desc
.Height
;
1684 d3dcolor_to_pipe_color_union(&rgba
, color
);
1686 fallback
= !(surf
->base
.info
.bind
& PIPE_BIND_RENDER_TARGET
);
1689 psurf
= NineSurface9_GetSurface(surf
, 0);
1695 pipe
->clear_render_target(pipe
, psurf
, &rgba
, x
, y
, w
, h
);
1697 D3DLOCKED_RECT lock
;
1698 union util_color uc
;
1700 /* XXX: lock pRect and fix util_fill_rect */
1701 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, 0);
1704 util_pack_color_ub(color
>> 16, color
>> 8, color
>> 0, color
>> 24,
1705 surf
->base
.info
.format
, &uc
);
1706 util_fill_rect(lock
.pBits
, surf
->base
.info
.format
,lock
.Pitch
,
1708 NineSurface9_UnlockRect(surf
);
1715 NineDevice9_CreateOffscreenPlainSurface( struct NineDevice9
*This
,
1720 IDirect3DSurface9
**ppSurface
,
1721 HANDLE
*pSharedHandle
)
1725 DBG("This=%p Width=%u Height=%u Format=%s(0x%x) Pool=%u "
1726 "ppSurface=%p pSharedHandle=%p\n", This
,
1727 Width
, Height
, d3dformat_to_string(Format
), Format
, Pool
,
1728 ppSurface
, pSharedHandle
);
1731 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
1732 || Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1733 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1735 /* Can be used with StretchRect and ColorFill. It's also always lockable.
1737 hr
= create_zs_or_rt_surface(This
, 2, Pool
, Width
, Height
,
1739 D3DMULTISAMPLE_NONE
, 0,
1741 ppSurface
, pSharedHandle
);
1743 DBG("Failed to create surface.\n");
1748 NineDevice9_SetRenderTarget( struct NineDevice9
*This
,
1749 DWORD RenderTargetIndex
,
1750 IDirect3DSurface9
*pRenderTarget
)
1752 struct NineSurface9
*rt
= NineSurface9(pRenderTarget
);
1753 const unsigned i
= RenderTargetIndex
;
1755 DBG("This=%p RenderTargetIndex=%u pRenderTarget=%p\n", This
,
1756 RenderTargetIndex
, pRenderTarget
);
1758 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1759 user_assert(i
!= 0 || pRenderTarget
, D3DERR_INVALIDCALL
);
1760 user_assert(!pRenderTarget
||
1761 rt
->desc
.Usage
& D3DUSAGE_RENDERTARGET
, D3DERR_INVALIDCALL
);
1764 This
->state
.viewport
.X
= 0;
1765 This
->state
.viewport
.Y
= 0;
1766 This
->state
.viewport
.Width
= rt
->desc
.Width
;
1767 This
->state
.viewport
.Height
= rt
->desc
.Height
;
1768 This
->state
.viewport
.MinZ
= 0.0f
;
1769 This
->state
.viewport
.MaxZ
= 1.0f
;
1771 This
->state
.scissor
.minx
= 0;
1772 This
->state
.scissor
.miny
= 0;
1773 This
->state
.scissor
.maxx
= rt
->desc
.Width
;
1774 This
->state
.scissor
.maxy
= rt
->desc
.Height
;
1776 This
->state
.changed
.group
|= NINE_STATE_VIEWPORT
| NINE_STATE_SCISSOR
;
1779 if (This
->state
.rt
[i
] != NineSurface9(pRenderTarget
)) {
1780 nine_bind(&This
->state
.rt
[i
], pRenderTarget
);
1781 This
->state
.changed
.group
|= NINE_STATE_FB
;
1787 NineDevice9_GetRenderTarget( struct NineDevice9
*This
,
1788 DWORD RenderTargetIndex
,
1789 IDirect3DSurface9
**ppRenderTarget
)
1791 const unsigned i
= RenderTargetIndex
;
1793 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1794 user_assert(ppRenderTarget
, D3DERR_INVALIDCALL
);
1796 *ppRenderTarget
= (IDirect3DSurface9
*)This
->state
.rt
[i
];
1797 if (!This
->state
.rt
[i
])
1798 return D3DERR_NOTFOUND
;
1800 NineUnknown_AddRef(NineUnknown(This
->state
.rt
[i
]));
1805 NineDevice9_SetDepthStencilSurface( struct NineDevice9
*This
,
1806 IDirect3DSurface9
*pNewZStencil
)
1808 DBG("This=%p pNewZStencil=%p\n", This
, pNewZStencil
);
1810 if (This
->state
.ds
!= NineSurface9(pNewZStencil
)) {
1811 nine_bind(&This
->state
.ds
, pNewZStencil
);
1812 This
->state
.changed
.group
|= NINE_STATE_FB
;
1818 NineDevice9_GetDepthStencilSurface( struct NineDevice9
*This
,
1819 IDirect3DSurface9
**ppZStencilSurface
)
1821 user_assert(ppZStencilSurface
, D3DERR_INVALIDCALL
);
1823 *ppZStencilSurface
= (IDirect3DSurface9
*)This
->state
.ds
;
1824 if (!This
->state
.ds
)
1825 return D3DERR_NOTFOUND
;
1827 NineUnknown_AddRef(NineUnknown(This
->state
.ds
));
1832 NineDevice9_BeginScene( struct NineDevice9
*This
)
1834 DBG("This=%p\n", This
);
1835 user_assert(!This
->in_scene
, D3DERR_INVALIDCALL
);
1836 This
->in_scene
= TRUE
;
1837 /* Do we want to do anything else here ? */
1842 NineDevice9_EndScene( struct NineDevice9
*This
)
1844 DBG("This=%p\n", This
);
1845 user_assert(This
->in_scene
, D3DERR_INVALIDCALL
);
1846 This
->in_scene
= FALSE
;
1851 NineDevice9_Clear( struct NineDevice9
*This
,
1853 const D3DRECT
*pRects
,
1859 const int sRGB
= This
->state
.rs
[D3DRS_SRGBWRITEENABLE
] ? 1 : 0;
1860 struct pipe_surface
*cbuf
, *zsbuf
;
1861 struct pipe_context
*pipe
= This
->pipe
;
1862 struct NineSurface9
*zsbuf_surf
= This
->state
.ds
;
1863 struct NineSurface9
*rt
;
1866 union pipe_color_union rgba
;
1867 unsigned rt_mask
= 0;
1870 DBG("This=%p Count=%u pRects=%p Flags=%x Color=%08x Z=%f Stencil=%x\n",
1871 This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1873 user_assert(This
->state
.ds
|| !(Flags
& NINED3DCLEAR_DEPTHSTENCIL
),
1874 D3DERR_INVALIDCALL
);
1875 user_assert(!(Flags
& D3DCLEAR_STENCIL
) ||
1877 util_format_is_depth_and_stencil(zsbuf_surf
->base
.info
.format
)),
1878 D3DERR_INVALIDCALL
);
1880 user_assert((Count
&& pRects
) || (!Count
&& !pRects
), D3DERR_INVALIDCALL
);
1882 user_warn((pRects
&& !Count
) || (!pRects
&& Count
));
1883 if (pRects
&& !Count
)
1889 if (Flags
& D3DCLEAR_TARGET
) bufs
|= PIPE_CLEAR_COLOR
;
1890 if (Flags
& D3DCLEAR_ZBUFFER
) bufs
|= PIPE_CLEAR_DEPTH
;
1891 if (Flags
& D3DCLEAR_STENCIL
) bufs
|= PIPE_CLEAR_STENCIL
;
1894 d3dcolor_to_pipe_color_union(&rgba
, Color
);
1896 nine_update_state(This
, NINE_STATE_FB
);
1898 rect
.x1
= This
->state
.viewport
.X
;
1899 rect
.y1
= This
->state
.viewport
.Y
;
1900 rect
.x2
= This
->state
.viewport
.Width
+ rect
.x1
;
1901 rect
.y2
= This
->state
.viewport
.Height
+ rect
.y1
;
1903 /* Both rectangles apply, which is weird, but that's D3D9. */
1904 if (This
->state
.rs
[D3DRS_SCISSORTESTENABLE
]) {
1905 rect
.x1
= MAX2(rect
.x1
, This
->state
.scissor
.minx
);
1906 rect
.y1
= MAX2(rect
.y1
, This
->state
.scissor
.miny
);
1907 rect
.x2
= MIN2(rect
.x2
, This
->state
.scissor
.maxx
);
1908 rect
.y2
= MIN2(rect
.y2
, This
->state
.scissor
.maxy
);
1912 /* Maybe apps like to specify a large rect ? */
1913 if (pRects
[0].x1
<= rect
.x1
&& pRects
[0].x2
>= rect
.x2
&&
1914 pRects
[0].y1
<= rect
.y1
&& pRects
[0].y2
>= rect
.y2
) {
1915 DBG("First rect covers viewport.\n");
1921 if (rect
.x1
>= This
->state
.fb
.width
|| rect
.y1
>= This
->state
.fb
.height
)
1924 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
1925 if (This
->state
.rt
[i
] && This
->state
.rt
[i
]->desc
.Format
!= D3DFMT_NULL
)
1929 /* fast path, clears everything at once */
1931 (!(bufs
& PIPE_CLEAR_COLOR
) || (rt_mask
== This
->state
.rt_mask
)) &&
1932 rect
.x1
== 0 && rect
.y1
== 0 &&
1933 /* Case we clear only render target. Check clear region vs rt. */
1934 ((!(bufs
& (PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
)) &&
1935 rect
.x2
>= This
->state
.fb
.width
&&
1936 rect
.y2
>= This
->state
.fb
.height
) ||
1937 /* Case we clear depth buffer (and eventually rt too).
1938 * depth buffer size is always >= rt size. Compare to clear region */
1939 ((bufs
& (PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
)) &&
1940 This
->state
.fb
.zsbuf
!= NULL
&&
1941 rect
.x2
>= zsbuf_surf
->desc
.Width
&&
1942 rect
.y2
>= zsbuf_surf
->desc
.Height
))) {
1943 DBG("Clear fast path\n");
1944 pipe
->clear(pipe
, bufs
, &rgba
, Z
, Stencil
);
1953 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
1954 rt
= This
->state
.rt
[i
];
1955 if (!rt
|| rt
->desc
.Format
== D3DFMT_NULL
||
1956 !(Flags
& D3DCLEAR_TARGET
))
1957 continue; /* save space, compiler should hoist this */
1958 cbuf
= NineSurface9_GetSurface(rt
, sRGB
);
1959 for (r
= 0; r
< Count
; ++r
) {
1960 /* Don't trust users to pass these in the right order. */
1961 unsigned x1
= MIN2(pRects
[r
].x1
, pRects
[r
].x2
);
1962 unsigned y1
= MIN2(pRects
[r
].y1
, pRects
[r
].y2
);
1963 unsigned x2
= MAX2(pRects
[r
].x1
, pRects
[r
].x2
);
1964 unsigned y2
= MAX2(pRects
[r
].y1
, pRects
[r
].y2
);
1966 /* Drop negative rectangles (like wine expects). */
1967 if (pRects
[r
].x1
> pRects
[r
].x2
) continue;
1968 if (pRects
[r
].y1
> pRects
[r
].y2
) continue;
1971 x1
= MAX2(x1
, rect
.x1
);
1972 y1
= MAX2(y1
, rect
.y1
);
1973 x2
= MIN3(x2
, rect
.x2
, rt
->desc
.Width
);
1974 y2
= MIN3(y2
, rect
.y2
, rt
->desc
.Height
);
1976 DBG("Clearing (%u..%u)x(%u..%u)\n", x1
, x2
, y1
, y2
);
1977 pipe
->clear_render_target(pipe
, cbuf
, &rgba
,
1978 x1
, y1
, x2
- x1
, y2
- y1
);
1981 if (!(Flags
& NINED3DCLEAR_DEPTHSTENCIL
))
1984 bufs
&= PIPE_CLEAR_DEPTHSTENCIL
;
1986 for (r
= 0; r
< Count
; ++r
) {
1987 unsigned x1
= MIN2(pRects
[r
].x1
, pRects
[r
].x2
);
1988 unsigned y1
= MIN2(pRects
[r
].y1
, pRects
[r
].y2
);
1989 unsigned x2
= MAX2(pRects
[r
].x1
, pRects
[r
].x2
);
1990 unsigned y2
= MAX2(pRects
[r
].y1
, pRects
[r
].y2
);
1992 /* Drop negative rectangles. */
1993 if (pRects
[r
].x1
> pRects
[r
].x2
) continue;
1994 if (pRects
[r
].y1
> pRects
[r
].y2
) continue;
1997 x1
= MIN2(x1
, rect
.x1
);
1998 y1
= MIN2(y1
, rect
.y1
);
1999 x2
= MIN3(x2
, rect
.x2
, zsbuf_surf
->desc
.Width
);
2000 y2
= MIN3(y2
, rect
.y2
, zsbuf_surf
->desc
.Height
);
2002 zsbuf
= NineSurface9_GetSurface(zsbuf_surf
, 0);
2004 pipe
->clear_depth_stencil(pipe
, zsbuf
, bufs
, Z
, Stencil
,
2005 x1
, y1
, x2
- x1
, y2
- y1
);
2011 NineDevice9_SetTransform( struct NineDevice9
*This
,
2012 D3DTRANSFORMSTATETYPE State
,
2013 const D3DMATRIX
*pMatrix
)
2015 struct nine_state
*state
= This
->update
;
2016 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
2018 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2020 user_assert(M
, D3DERR_INVALIDCALL
);
2023 state
->ff
.changed
.transform
[State
/ 32] |= 1 << (State
% 32);
2024 state
->changed
.group
|= NINE_STATE_FF
;
2030 NineDevice9_GetTransform( struct NineDevice9
*This
,
2031 D3DTRANSFORMSTATETYPE State
,
2032 D3DMATRIX
*pMatrix
)
2034 D3DMATRIX
*M
= nine_state_access_transform(&This
->state
, State
, FALSE
);
2035 user_assert(M
, D3DERR_INVALIDCALL
);
2041 NineDevice9_MultiplyTransform( struct NineDevice9
*This
,
2042 D3DTRANSFORMSTATETYPE State
,
2043 const D3DMATRIX
*pMatrix
)
2045 struct nine_state
*state
= This
->update
;
2047 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
2049 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2051 user_assert(M
, D3DERR_INVALIDCALL
);
2053 nine_d3d_matrix_matrix_mul(&T
, pMatrix
, M
);
2054 return NineDevice9_SetTransform(This
, State
, &T
);
2058 NineDevice9_SetViewport( struct NineDevice9
*This
,
2059 const D3DVIEWPORT9
*pViewport
)
2061 struct nine_state
*state
= This
->update
;
2063 DBG("X=%u Y=%u W=%u H=%u MinZ=%f MaxZ=%f\n",
2064 pViewport
->X
, pViewport
->Y
, pViewport
->Width
, pViewport
->Height
,
2065 pViewport
->MinZ
, pViewport
->MaxZ
);
2067 state
->viewport
= *pViewport
;
2068 state
->changed
.group
|= NINE_STATE_VIEWPORT
;
2074 NineDevice9_GetViewport( struct NineDevice9
*This
,
2075 D3DVIEWPORT9
*pViewport
)
2077 *pViewport
= This
->state
.viewport
;
2082 NineDevice9_SetMaterial( struct NineDevice9
*This
,
2083 const D3DMATERIAL9
*pMaterial
)
2085 struct nine_state
*state
= This
->update
;
2087 DBG("This=%p pMaterial=%p\n", This
, pMaterial
);
2089 nine_dump_D3DMATERIAL9(DBG_FF
, pMaterial
);
2091 user_assert(pMaterial
, E_POINTER
);
2093 state
->ff
.material
= *pMaterial
;
2094 state
->changed
.group
|= NINE_STATE_FF_MATERIAL
;
2100 NineDevice9_GetMaterial( struct NineDevice9
*This
,
2101 D3DMATERIAL9
*pMaterial
)
2103 user_assert(pMaterial
, E_POINTER
);
2104 *pMaterial
= This
->state
.ff
.material
;
2109 NineDevice9_SetLight( struct NineDevice9
*This
,
2111 const D3DLIGHT9
*pLight
)
2113 struct nine_state
*state
= This
->update
;
2115 DBG("This=%p Index=%u pLight=%p\n", This
, Index
, pLight
);
2117 nine_dump_D3DLIGHT9(DBG_FF
, pLight
);
2119 user_assert(pLight
, D3DERR_INVALIDCALL
);
2120 user_assert(pLight
->Type
< NINED3DLIGHT_INVALID
, D3DERR_INVALIDCALL
);
2122 user_assert(Index
< NINE_MAX_LIGHTS
, D3DERR_INVALIDCALL
); /* sanity */
2124 if (Index
>= state
->ff
.num_lights
) {
2125 unsigned n
= state
->ff
.num_lights
;
2126 unsigned N
= Index
+ 1;
2128 state
->ff
.light
= REALLOC(state
->ff
.light
, n
* sizeof(D3DLIGHT9
),
2129 N
* sizeof(D3DLIGHT9
));
2130 if (!state
->ff
.light
)
2131 return E_OUTOFMEMORY
;
2132 state
->ff
.num_lights
= N
;
2134 for (; n
< Index
; ++n
)
2135 state
->ff
.light
[n
].Type
= (D3DLIGHTTYPE
)NINED3DLIGHT_INVALID
;
2137 state
->ff
.light
[Index
] = *pLight
;
2139 if (pLight
->Type
== D3DLIGHT_SPOT
&& pLight
->Theta
>= pLight
->Phi
) {
2140 DBG("Warning: clamping D3DLIGHT9.Theta\n");
2141 state
->ff
.light
[Index
].Theta
= state
->ff
.light
[Index
].Phi
;
2143 if (pLight
->Type
!= D3DLIGHT_DIRECTIONAL
&&
2144 pLight
->Attenuation0
== 0.0f
&&
2145 pLight
->Attenuation1
== 0.0f
&&
2146 pLight
->Attenuation2
== 0.0f
) {
2147 DBG("Warning: all D3DLIGHT9.Attenuation[i] are 0\n");
2150 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2156 NineDevice9_GetLight( struct NineDevice9
*This
,
2160 const struct nine_state
*state
= &This
->state
;
2162 user_assert(pLight
, D3DERR_INVALIDCALL
);
2163 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2164 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2165 D3DERR_INVALIDCALL
);
2167 *pLight
= state
->ff
.light
[Index
];
2173 NineDevice9_LightEnable( struct NineDevice9
*This
,
2177 struct nine_state
*state
= This
->update
;
2180 DBG("This=%p Index=%u Enable=%i\n", This
, Index
, Enable
);
2182 if (Index
>= state
->ff
.num_lights
||
2183 state
->ff
.light
[Index
].Type
== NINED3DLIGHT_INVALID
) {
2184 /* This should create a default light. */
2186 memset(&light
, 0, sizeof(light
));
2187 light
.Type
= D3DLIGHT_DIRECTIONAL
;
2188 light
.Diffuse
.r
= 1.0f
;
2189 light
.Diffuse
.g
= 1.0f
;
2190 light
.Diffuse
.b
= 1.0f
;
2191 light
.Direction
.z
= 1.0f
;
2192 NineDevice9_SetLight(This
, Index
, &light
);
2194 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2196 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
) {
2197 if (state
->ff
.active_light
[i
] == Index
)
2202 if (i
< state
->ff
.num_lights_active
)
2204 /* XXX wine thinks this should still succeed:
2206 user_assert(i
< NINE_MAX_LIGHTS_ACTIVE
, D3DERR_INVALIDCALL
);
2208 state
->ff
.active_light
[i
] = Index
;
2209 state
->ff
.num_lights_active
++;
2211 if (i
== state
->ff
.num_lights_active
)
2213 --state
->ff
.num_lights_active
;
2214 for (; i
< state
->ff
.num_lights_active
; ++i
)
2215 state
->ff
.active_light
[i
] = state
->ff
.active_light
[i
+ 1];
2217 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2223 NineDevice9_GetLightEnable( struct NineDevice9
*This
,
2227 const struct nine_state
*state
= &This
->state
;
2230 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2231 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2232 D3DERR_INVALIDCALL
);
2234 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
)
2235 if (state
->ff
.active_light
[i
] == Index
)
2238 *pEnable
= i
!= state
->ff
.num_lights_active
? 128 : 0; // Taken from wine
2244 NineDevice9_SetClipPlane( struct NineDevice9
*This
,
2246 const float *pPlane
)
2248 struct nine_state
*state
= This
->update
;
2250 user_assert(pPlane
, D3DERR_INVALIDCALL
);
2252 DBG("This=%p Index=%u pPlane=%f %f %f %f\n", This
, Index
,
2253 pPlane
[0], pPlane
[1],
2254 pPlane
[2], pPlane
[3]);
2256 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2258 memcpy(&state
->clip
.ucp
[Index
][0], pPlane
, sizeof(state
->clip
.ucp
[0]));
2259 state
->changed
.ucp
|= 1 << Index
;
2265 NineDevice9_GetClipPlane( struct NineDevice9
*This
,
2269 const struct nine_state
*state
= &This
->state
;
2271 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2273 memcpy(pPlane
, &state
->clip
.ucp
[Index
][0], sizeof(state
->clip
.ucp
[0]));
2277 #define RESZ_CODE 0x7fa05000
2280 NineDevice9_ResolveZ( struct NineDevice9
*This
)
2282 struct nine_state
*state
= &This
->state
;
2283 const struct util_format_description
*desc
;
2284 struct NineSurface9
*source
= state
->ds
;
2285 struct NineBaseTexture9
*destination
= state
->texture
[0];
2286 struct pipe_resource
*src
, *dst
;
2287 struct pipe_blit_info blit
;
2289 DBG("RESZ resolve\n");
2291 user_assert(source
&& destination
&&
2292 destination
->base
.type
== D3DRTYPE_TEXTURE
, D3DERR_INVALIDCALL
);
2294 src
= source
->base
.resource
;
2295 dst
= destination
->base
.resource
;
2297 user_assert(src
&& dst
, D3DERR_INVALIDCALL
);
2299 /* check dst is depth format. we know already for src */
2300 desc
= util_format_description(dst
->format
);
2301 user_assert(desc
->colorspace
== UTIL_FORMAT_COLORSPACE_ZS
, D3DERR_INVALIDCALL
);
2303 memset(&blit
, 0, sizeof(blit
));
2304 blit
.src
.resource
= src
;
2306 blit
.src
.format
= src
->format
;
2308 blit
.src
.box
.depth
= 1;
2311 blit
.src
.box
.width
= src
->width0
;
2312 blit
.src
.box
.height
= src
->height0
;
2314 blit
.dst
.resource
= dst
;
2316 blit
.dst
.format
= dst
->format
;
2318 blit
.dst
.box
.depth
= 1;
2321 blit
.dst
.box
.width
= dst
->width0
;
2322 blit
.dst
.box
.height
= dst
->height0
;
2324 blit
.mask
= PIPE_MASK_ZS
;
2325 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
2326 blit
.scissor_enable
= FALSE
;
2328 This
->pipe
->blit(This
->pipe
, &blit
);
2332 #define ALPHA_TO_COVERAGE_ENABLE MAKEFOURCC('A', '2', 'M', '1')
2333 #define ALPHA_TO_COVERAGE_DISABLE MAKEFOURCC('A', '2', 'M', '0')
2336 NineDevice9_SetRenderState( struct NineDevice9
*This
,
2337 D3DRENDERSTATETYPE State
,
2340 struct nine_state
*state
= This
->update
;
2342 DBG("This=%p State=%u(%s) Value=%08x\n", This
,
2343 State
, nine_d3drs_to_string(State
), Value
);
2345 /* Amd hacks (equivalent to GL extensions) */
2346 if (State
== D3DRS_POINTSIZE
) {
2347 if (Value
== RESZ_CODE
)
2348 return NineDevice9_ResolveZ(This
);
2350 if (Value
== ALPHA_TO_COVERAGE_ENABLE
||
2351 Value
== ALPHA_TO_COVERAGE_DISABLE
) {
2352 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
== ALPHA_TO_COVERAGE_ENABLE
);
2353 state
->changed
.group
|= NINE_STATE_BLEND
;
2359 if (State
== D3DRS_ADAPTIVETESS_Y
&&
2360 (Value
== D3DFMT_ATOC
|| (Value
== D3DFMT_UNKNOWN
&& state
->rs
[NINED3DRS_ALPHACOVERAGE
]))) {
2361 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
== D3DFMT_ATOC
);
2362 state
->changed
.group
|= NINE_STATE_BLEND
;
2366 user_assert(State
< Elements(state
->rs
), D3DERR_INVALIDCALL
);
2368 if (likely(state
->rs
[State
] != Value
) || unlikely(This
->is_recording
)) {
2369 state
->rs
[State
] = Value
;
2370 state
->changed
.rs
[State
/ 32] |= 1 << (State
% 32);
2371 state
->changed
.group
|= nine_render_state_group
[State
];
2378 NineDevice9_GetRenderState( struct NineDevice9
*This
,
2379 D3DRENDERSTATETYPE State
,
2382 user_assert(State
< Elements(This
->state
.rs
), D3DERR_INVALIDCALL
);
2384 *pValue
= This
->state
.rs
[State
];
2389 NineDevice9_CreateStateBlock( struct NineDevice9
*This
,
2390 D3DSTATEBLOCKTYPE Type
,
2391 IDirect3DStateBlock9
**ppSB
)
2393 struct NineStateBlock9
*nsb
;
2394 struct nine_state
*dst
;
2396 enum nine_stateblock_type type
;
2399 DBG("This=%p Type=%u ppSB=%p\n", This
, Type
, ppSB
);
2401 user_assert(Type
== D3DSBT_ALL
||
2402 Type
== D3DSBT_VERTEXSTATE
||
2403 Type
== D3DSBT_PIXELSTATE
, D3DERR_INVALIDCALL
);
2406 case D3DSBT_VERTEXSTATE
: type
= NINESBT_VERTEXSTATE
; break;
2407 case D3DSBT_PIXELSTATE
: type
= NINESBT_PIXELSTATE
; break;
2413 hr
= NineStateBlock9_new(This
, &nsb
, type
);
2416 *ppSB
= (IDirect3DStateBlock9
*)nsb
;
2419 dst
->changed
.group
=
2420 NINE_STATE_TEXTURE
|
2423 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_VERTEXSTATE
) {
2424 dst
->changed
.group
|=
2425 NINE_STATE_FF_LIGHTING
|
2426 NINE_STATE_VS
| NINE_STATE_VS_CONST
|
2428 /* TODO: texture/sampler state */
2429 memcpy(dst
->changed
.rs
,
2430 nine_render_states_vertex
, sizeof(dst
->changed
.rs
));
2431 nine_ranges_insert(&dst
->changed
.vs_const_f
, 0, This
->max_vs_const_f
,
2433 dst
->changed
.vs_const_i
= 0xffff;
2434 dst
->changed
.vs_const_b
= 0xffff;
2435 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2436 dst
->changed
.sampler
[s
] |= 1 << D3DSAMP_DMAPOFFSET
;
2437 if (This
->state
.ff
.num_lights
) {
2438 dst
->ff
.num_lights
= This
->state
.ff
.num_lights
;
2439 /* zero'd -> light type won't be NINED3DLIGHT_INVALID, so
2440 * all currently existing lights will be captured
2442 dst
->ff
.light
= CALLOC(This
->state
.ff
.num_lights
,
2444 if (!dst
->ff
.light
) {
2445 nine_bind(ppSB
, NULL
);
2446 return E_OUTOFMEMORY
;
2450 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_PIXELSTATE
) {
2451 dst
->changed
.group
|=
2452 NINE_STATE_PS
| NINE_STATE_PS_CONST
;
2453 /* TODO: texture/sampler state */
2454 memcpy(dst
->changed
.rs
,
2455 nine_render_states_pixel
, sizeof(dst
->changed
.rs
));
2456 nine_ranges_insert(&dst
->changed
.ps_const_f
, 0, This
->max_ps_const_f
,
2458 dst
->changed
.ps_const_i
= 0xffff;
2459 dst
->changed
.ps_const_b
= 0xffff;
2460 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2461 dst
->changed
.sampler
[s
] |= 0x1ffe;
2463 if (Type
== D3DSBT_ALL
) {
2464 dst
->changed
.group
|=
2465 NINE_STATE_VIEWPORT
|
2466 NINE_STATE_SCISSOR
|
2467 NINE_STATE_RASTERIZER
|
2471 NINE_STATE_MATERIAL
|
2472 NINE_STATE_BLEND_COLOR
|
2473 NINE_STATE_SAMPLE_MASK
;
2474 memset(dst
->changed
.rs
, ~0, (D3DRS_COUNT
/ 32) * sizeof(uint32_t));
2475 dst
->changed
.rs
[D3DRS_LAST
/ 32] |= (1 << (D3DRS_COUNT
% 32)) - 1;
2476 dst
->changed
.vtxbuf
= (1ULL << This
->caps
.MaxStreams
) - 1;
2477 dst
->changed
.stream_freq
= dst
->changed
.vtxbuf
;
2478 dst
->changed
.ucp
= (1 << PIPE_MAX_CLIP_PLANES
) - 1;
2479 dst
->changed
.texture
= (1 << NINE_MAX_SAMPLERS
) - 1;
2481 NineStateBlock9_Capture(NineStateBlock9(*ppSB
));
2483 /* TODO: fixed function state */
2489 NineDevice9_BeginStateBlock( struct NineDevice9
*This
)
2493 DBG("This=%p\n", This
);
2495 user_assert(!This
->record
, D3DERR_INVALIDCALL
);
2497 hr
= NineStateBlock9_new(This
, &This
->record
, NINESBT_CUSTOM
);
2500 NineUnknown_ConvertRefToBind(NineUnknown(This
->record
));
2502 This
->update
= &This
->record
->state
;
2503 This
->is_recording
= TRUE
;
2509 NineDevice9_EndStateBlock( struct NineDevice9
*This
,
2510 IDirect3DStateBlock9
**ppSB
)
2512 DBG("This=%p ppSB=%p\n", This
, ppSB
);
2514 user_assert(This
->record
, D3DERR_INVALIDCALL
);
2516 This
->update
= &This
->state
;
2517 This
->is_recording
= FALSE
;
2519 NineUnknown_AddRef(NineUnknown(This
->record
));
2520 *ppSB
= (IDirect3DStateBlock9
*)This
->record
;
2521 NineUnknown_Unbind(NineUnknown(This
->record
));
2522 This
->record
= NULL
;
2528 NineDevice9_SetClipStatus( struct NineDevice9
*This
,
2529 const D3DCLIPSTATUS9
*pClipStatus
)
2531 STUB(D3DERR_INVALIDCALL
);
2535 NineDevice9_GetClipStatus( struct NineDevice9
*This
,
2536 D3DCLIPSTATUS9
*pClipStatus
)
2538 STUB(D3DERR_INVALIDCALL
);
2542 NineDevice9_GetTexture( struct NineDevice9
*This
,
2544 IDirect3DBaseTexture9
**ppTexture
)
2546 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2547 Stage
== D3DDMAPSAMPLER
||
2548 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2549 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2550 user_assert(ppTexture
, D3DERR_INVALIDCALL
);
2552 if (Stage
>= D3DDMAPSAMPLER
)
2553 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2555 *ppTexture
= (IDirect3DBaseTexture9
*)This
->state
.texture
[Stage
];
2557 if (This
->state
.texture
[Stage
])
2558 NineUnknown_AddRef(NineUnknown(This
->state
.texture
[Stage
]));
2563 NineDevice9_SetTexture( struct NineDevice9
*This
,
2565 IDirect3DBaseTexture9
*pTexture
)
2567 struct nine_state
*state
= This
->update
;
2568 struct NineBaseTexture9
*tex
= NineBaseTexture9(pTexture
);
2570 DBG("This=%p Stage=%u pTexture=%p\n", This
, Stage
, pTexture
);
2572 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2573 Stage
== D3DDMAPSAMPLER
||
2574 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2575 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2576 user_assert(!tex
|| (tex
->base
.pool
!= D3DPOOL_SCRATCH
&&
2577 tex
->base
.pool
!= D3DPOOL_SYSTEMMEM
), D3DERR_INVALIDCALL
);
2579 if (Stage
>= D3DDMAPSAMPLER
)
2580 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2582 if (!This
->is_recording
) {
2583 struct NineBaseTexture9
*old
= state
->texture
[Stage
];
2587 state
->samplers_shadow
&= ~(1 << Stage
);
2589 state
->samplers_shadow
|= tex
->shadow
<< Stage
;
2591 if ((tex
->managed
.dirty
| tex
->dirty_mip
) && LIST_IS_EMPTY(&tex
->list
))
2592 list_add(&tex
->list
, &This
->update_textures
);
2599 nine_bind(&state
->texture
[Stage
], pTexture
);
2601 state
->changed
.texture
|= 1 << Stage
;
2602 state
->changed
.group
|= NINE_STATE_TEXTURE
;
2608 NineDevice9_GetTextureStageState( struct NineDevice9
*This
,
2610 D3DTEXTURESTAGESTATETYPE Type
,
2613 const struct nine_state
*state
= &This
->state
;
2615 user_assert(Stage
< Elements(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2616 user_assert(Type
< Elements(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2618 *pValue
= state
->ff
.tex_stage
[Stage
][Type
];
2624 NineDevice9_SetTextureStageState( struct NineDevice9
*This
,
2626 D3DTEXTURESTAGESTATETYPE Type
,
2629 struct nine_state
*state
= This
->update
;
2631 DBG("Stage=%u Type=%u Value=%08x\n", Stage
, Type
, Value
);
2632 nine_dump_D3DTSS_value(DBG_FF
, Type
, Value
);
2634 user_assert(Stage
< Elements(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2635 user_assert(Type
< Elements(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2637 state
->ff
.tex_stage
[Stage
][Type
] = Value
;
2639 state
->changed
.group
|= NINE_STATE_FF_PSSTAGES
;
2640 state
->ff
.changed
.tex_stage
[Stage
][Type
/ 32] |= 1 << (Type
% 32);
2646 NineDevice9_GetSamplerState( struct NineDevice9
*This
,
2648 D3DSAMPLERSTATETYPE Type
,
2651 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2652 Sampler
== D3DDMAPSAMPLER
||
2653 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2654 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2656 if (Sampler
>= D3DDMAPSAMPLER
)
2657 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2659 *pValue
= This
->state
.samp
[Sampler
][Type
];
2664 NineDevice9_SetSamplerState( struct NineDevice9
*This
,
2666 D3DSAMPLERSTATETYPE Type
,
2669 struct nine_state
*state
= This
->update
;
2671 DBG("This=%p Sampler=%u Type=%s Value=%08x\n", This
,
2672 Sampler
, nine_D3DSAMP_to_str(Type
), Value
);
2674 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2675 Sampler
== D3DDMAPSAMPLER
||
2676 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2677 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2679 if (Sampler
>= D3DDMAPSAMPLER
)
2680 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2682 state
->samp
[Sampler
][Type
] = Value
;
2683 state
->changed
.group
|= NINE_STATE_SAMPLER
;
2684 state
->changed
.sampler
[Sampler
] |= 1 << Type
;
2686 if (Type
== D3DSAMP_SRGBTEXTURE
)
2687 state
->changed
.srgb
= TRUE
;
2693 NineDevice9_ValidateDevice( struct NineDevice9
*This
,
2696 const struct nine_state
*state
= &This
->state
;
2698 unsigned w
= 0, h
= 0;
2700 DBG("This=%p pNumPasses=%p\n", This
, pNumPasses
);
2702 for (i
= 0; i
< Elements(state
->samp
); ++i
) {
2703 if (state
->samp
[i
][D3DSAMP_MINFILTER
] == D3DTEXF_NONE
||
2704 state
->samp
[i
][D3DSAMP_MAGFILTER
] == D3DTEXF_NONE
)
2705 return D3DERR_UNSUPPORTEDTEXTUREFILTER
;
2708 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2712 w
= state
->rt
[i
]->desc
.Width
;
2713 h
= state
->rt
[i
]->desc
.Height
;
2715 if (state
->rt
[i
]->desc
.Width
!= w
|| state
->rt
[i
]->desc
.Height
!= h
) {
2716 return D3DERR_CONFLICTINGRENDERSTATE
;
2720 (state
->rs
[D3DRS_ZENABLE
] || state
->rs
[D3DRS_STENCILENABLE
])) {
2722 (state
->ds
->desc
.Width
!= w
|| state
->ds
->desc
.Height
!= h
))
2723 return D3DERR_CONFLICTINGRENDERSTATE
;
2733 NineDevice9_SetPaletteEntries( struct NineDevice9
*This
,
2735 const PALETTEENTRY
*pEntries
)
2737 STUB(D3D_OK
); /* like wine */
2741 NineDevice9_GetPaletteEntries( struct NineDevice9
*This
,
2743 PALETTEENTRY
*pEntries
)
2745 STUB(D3DERR_INVALIDCALL
);
2749 NineDevice9_SetCurrentTexturePalette( struct NineDevice9
*This
,
2750 UINT PaletteNumber
)
2752 STUB(D3D_OK
); /* like wine */
2756 NineDevice9_GetCurrentTexturePalette( struct NineDevice9
*This
,
2757 UINT
*PaletteNumber
)
2759 STUB(D3DERR_INVALIDCALL
);
2763 NineDevice9_SetScissorRect( struct NineDevice9
*This
,
2766 struct nine_state
*state
= This
->update
;
2768 DBG("x=(%u..%u) y=(%u..%u)\n",
2769 pRect
->left
, pRect
->top
, pRect
->right
, pRect
->bottom
);
2771 state
->scissor
.minx
= pRect
->left
;
2772 state
->scissor
.miny
= pRect
->top
;
2773 state
->scissor
.maxx
= pRect
->right
;
2774 state
->scissor
.maxy
= pRect
->bottom
;
2776 state
->changed
.group
|= NINE_STATE_SCISSOR
;
2782 NineDevice9_GetScissorRect( struct NineDevice9
*This
,
2785 pRect
->left
= This
->state
.scissor
.minx
;
2786 pRect
->top
= This
->state
.scissor
.miny
;
2787 pRect
->right
= This
->state
.scissor
.maxx
;
2788 pRect
->bottom
= This
->state
.scissor
.maxy
;
2794 NineDevice9_SetSoftwareVertexProcessing( struct NineDevice9
*This
,
2797 STUB(D3DERR_INVALIDCALL
);
2801 NineDevice9_GetSoftwareVertexProcessing( struct NineDevice9
*This
)
2803 return !!(This
->params
.BehaviorFlags
& D3DCREATE_SOFTWARE_VERTEXPROCESSING
);
2807 NineDevice9_SetNPatchMode( struct NineDevice9
*This
,
2810 STUB(D3DERR_INVALIDCALL
);
2814 NineDevice9_GetNPatchMode( struct NineDevice9
*This
)
2820 init_draw_info(struct pipe_draw_info
*info
,
2821 struct NineDevice9
*dev
, D3DPRIMITIVETYPE type
, UINT count
)
2823 info
->mode
= d3dprimitivetype_to_pipe_prim(type
);
2824 info
->count
= prim_count_to_vertex_count(type
, count
);
2825 info
->start_instance
= 0;
2826 info
->instance_count
= 1;
2827 if (dev
->state
.stream_instancedata_mask
& dev
->state
.stream_usage_mask
)
2828 info
->instance_count
= MAX2(dev
->state
.stream_freq
[0] & 0x7FFFFF, 1);
2829 info
->primitive_restart
= FALSE
;
2830 info
->restart_index
= 0;
2831 info
->count_from_stream_output
= NULL
;
2832 info
->indirect
= NULL
;
2836 NineDevice9_DrawPrimitive( struct NineDevice9
*This
,
2837 D3DPRIMITIVETYPE PrimitiveType
,
2839 UINT PrimitiveCount
)
2841 struct pipe_draw_info info
;
2843 DBG("iface %p, PrimitiveType %u, StartVertex %u, PrimitiveCount %u\n",
2844 This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2846 nine_update_state(This
, ~0);
2848 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2849 info
.indexed
= FALSE
;
2850 info
.start
= StartVertex
;
2851 info
.index_bias
= 0;
2852 info
.min_index
= info
.start
;
2853 info
.max_index
= info
.count
- 1;
2855 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2861 NineDevice9_DrawIndexedPrimitive( struct NineDevice9
*This
,
2862 D3DPRIMITIVETYPE PrimitiveType
,
2863 INT BaseVertexIndex
,
2864 UINT MinVertexIndex
,
2867 UINT PrimitiveCount
)
2869 struct pipe_draw_info info
;
2871 DBG("iface %p, PrimitiveType %u, BaseVertexIndex %u, MinVertexIndex %u "
2872 "NumVertices %u, StartIndex %u, PrimitiveCount %u\n",
2873 This
, PrimitiveType
, BaseVertexIndex
, MinVertexIndex
, NumVertices
,
2874 StartIndex
, PrimitiveCount
);
2876 user_assert(This
->state
.idxbuf
, D3DERR_INVALIDCALL
);
2877 user_assert(This
->state
.vdecl
, D3DERR_INVALIDCALL
);
2879 nine_update_state(This
, ~0);
2881 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2882 info
.indexed
= TRUE
;
2883 info
.start
= StartIndex
;
2884 info
.index_bias
= BaseVertexIndex
;
2885 /* These don't include index bias: */
2886 info
.min_index
= MinVertexIndex
;
2887 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
2889 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2895 NineDevice9_DrawPrimitiveUP( struct NineDevice9
*This
,
2896 D3DPRIMITIVETYPE PrimitiveType
,
2897 UINT PrimitiveCount
,
2898 const void *pVertexStreamZeroData
,
2899 UINT VertexStreamZeroStride
)
2901 struct pipe_vertex_buffer vtxbuf
;
2902 struct pipe_draw_info info
;
2904 DBG("iface %p, PrimitiveType %u, PrimitiveCount %u, data %p, stride %u\n",
2905 This
, PrimitiveType
, PrimitiveCount
,
2906 pVertexStreamZeroData
, VertexStreamZeroStride
);
2908 user_assert(pVertexStreamZeroData
&& VertexStreamZeroStride
,
2909 D3DERR_INVALIDCALL
);
2911 nine_update_state(This
, ~0);
2913 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2914 info
.indexed
= FALSE
;
2916 info
.index_bias
= 0;
2918 info
.max_index
= info
.count
- 1;
2920 vtxbuf
.stride
= VertexStreamZeroStride
;
2921 vtxbuf
.buffer_offset
= 0;
2922 vtxbuf
.buffer
= NULL
;
2923 vtxbuf
.user_buffer
= pVertexStreamZeroData
;
2925 if (!This
->driver_caps
.user_vbufs
)
2926 u_upload_data(This
->upload
,
2928 (info
.max_index
+ 1) * VertexStreamZeroStride
, /* XXX */
2930 &vtxbuf
.buffer_offset
,
2933 This
->pipe
->set_vertex_buffers(This
->pipe
, 0, 1, &vtxbuf
);
2935 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2937 NineDevice9_PauseRecording(This
);
2938 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
2939 NineDevice9_ResumeRecording(This
);
2941 pipe_resource_reference(&vtxbuf
.buffer
, NULL
);
2947 NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9
*This
,
2948 D3DPRIMITIVETYPE PrimitiveType
,
2949 UINT MinVertexIndex
,
2951 UINT PrimitiveCount
,
2952 const void *pIndexData
,
2953 D3DFORMAT IndexDataFormat
,
2954 const void *pVertexStreamZeroData
,
2955 UINT VertexStreamZeroStride
)
2957 struct pipe_draw_info info
;
2958 struct pipe_vertex_buffer vbuf
;
2959 struct pipe_index_buffer ibuf
;
2961 DBG("iface %p, PrimitiveType %u, MinVertexIndex %u, NumVertices %u "
2962 "PrimitiveCount %u, pIndexData %p, IndexDataFormat %u "
2963 "pVertexStreamZeroData %p, VertexStreamZeroStride %u\n",
2964 This
, PrimitiveType
, MinVertexIndex
, NumVertices
, PrimitiveCount
,
2965 pIndexData
, IndexDataFormat
,
2966 pVertexStreamZeroData
, VertexStreamZeroStride
);
2968 user_assert(pIndexData
&& pVertexStreamZeroData
, D3DERR_INVALIDCALL
);
2969 user_assert(VertexStreamZeroStride
, D3DERR_INVALIDCALL
);
2970 user_assert(IndexDataFormat
== D3DFMT_INDEX16
||
2971 IndexDataFormat
== D3DFMT_INDEX32
, D3DERR_INVALIDCALL
);
2973 nine_update_state(This
, ~0);
2975 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2976 info
.indexed
= TRUE
;
2978 info
.index_bias
= 0;
2979 info
.min_index
= MinVertexIndex
;
2980 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
2982 vbuf
.stride
= VertexStreamZeroStride
;
2983 vbuf
.buffer_offset
= 0;
2985 vbuf
.user_buffer
= pVertexStreamZeroData
;
2987 ibuf
.index_size
= (IndexDataFormat
== D3DFMT_INDEX16
) ? 2 : 4;
2990 ibuf
.user_buffer
= pIndexData
;
2992 if (!This
->driver_caps
.user_vbufs
) {
2993 const unsigned base
= info
.min_index
* VertexStreamZeroStride
;
2994 u_upload_data(This
->upload
,
2997 info
.min_index
+ 1) * VertexStreamZeroStride
, /* XXX */
2998 (const uint8_t *)vbuf
.user_buffer
+ base
,
2999 &vbuf
.buffer_offset
,
3001 /* Won't be used: */
3002 vbuf
.buffer_offset
-= base
;
3004 if (!This
->driver_caps
.user_ibufs
)
3005 u_upload_data(This
->upload
,
3007 info
.count
* ibuf
.index_size
,
3012 This
->pipe
->set_vertex_buffers(This
->pipe
, 0, 1, &vbuf
);
3013 This
->pipe
->set_index_buffer(This
->pipe
, &ibuf
);
3015 This
->pipe
->draw_vbo(This
->pipe
, &info
);
3017 pipe_resource_reference(&vbuf
.buffer
, NULL
);
3018 pipe_resource_reference(&ibuf
.buffer
, NULL
);
3020 NineDevice9_PauseRecording(This
);
3021 NineDevice9_SetIndices(This
, NULL
);
3022 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
3023 NineDevice9_ResumeRecording(This
);
3028 /* TODO: Write to pDestBuffer directly if vertex declaration contains
3032 NineDevice9_ProcessVertices( struct NineDevice9
*This
,
3036 IDirect3DVertexBuffer9
*pDestBuffer
,
3037 IDirect3DVertexDeclaration9
*pVertexDecl
,
3040 struct pipe_screen
*screen
= This
->screen
;
3041 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pVertexDecl
);
3042 struct NineVertexShader9
*vs
;
3043 struct pipe_resource
*resource
;
3044 struct pipe_stream_output_target
*target
;
3045 struct pipe_draw_info draw
;
3047 unsigned buffer_offset
, buffer_size
;
3049 DBG("This=%p SrcStartIndex=%u DestIndex=%u VertexCount=%u "
3050 "pDestBuffer=%p pVertexDecl=%p Flags=%d\n",
3051 This
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
,
3052 pVertexDecl
, Flags
);
3054 if (!screen
->get_param(screen
, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
))
3055 STUB(D3DERR_INVALIDCALL
);
3057 nine_update_state(This
, ~0);
3059 /* TODO: Create shader with stream output. */
3060 STUB(D3DERR_INVALIDCALL
);
3061 struct NineVertexBuffer9
*dst
= NineVertexBuffer9(pDestBuffer
);
3063 vs
= This
->state
.vs
? This
->state
.vs
: This
->ff
.vs
;
3065 buffer_size
= VertexCount
* vs
->so
->stride
[0];
3067 struct pipe_resource templ
;
3069 templ
.target
= PIPE_BUFFER
;
3070 templ
.format
= PIPE_FORMAT_R8_UNORM
;
3071 templ
.width0
= buffer_size
;
3073 templ
.bind
= PIPE_BIND_STREAM_OUTPUT
;
3074 templ
.usage
= PIPE_USAGE_STREAM
;
3075 templ
.height0
= templ
.depth0
= templ
.array_size
= 1;
3076 templ
.last_level
= templ
.nr_samples
= 0;
3078 resource
= This
->screen
->resource_create(This
->screen
, &templ
);
3080 return E_OUTOFMEMORY
;
3083 /* SO matches vertex declaration */
3084 resource
= dst
->base
.resource
;
3085 buffer_offset
= DestIndex
* vs
->so
->stride
[0];
3087 target
= This
->pipe
->create_stream_output_target(This
->pipe
, resource
,
3091 pipe_resource_reference(&resource
, NULL
);
3092 return D3DERR_DRIVERINTERNALERROR
;
3096 hr
= NineVertexDeclaration9_new_from_fvf(This
, dst
->desc
.FVF
, &vdecl
);
3101 init_draw_info(&draw
, This
, D3DPT_POINTLIST
, VertexCount
);
3102 draw
.instance_count
= 1;
3103 draw
.indexed
= FALSE
;
3104 draw
.start
= SrcStartIndex
;
3105 draw
.index_bias
= 0;
3106 draw
.min_index
= SrcStartIndex
;
3107 draw
.max_index
= SrcStartIndex
+ VertexCount
- 1;
3109 This
->pipe
->set_stream_output_targets(This
->pipe
, 1, &target
, 0);
3110 This
->pipe
->draw_vbo(This
->pipe
, &draw
);
3111 This
->pipe
->set_stream_output_targets(This
->pipe
, 0, NULL
, 0);
3112 This
->pipe
->stream_output_target_destroy(This
->pipe
, target
);
3114 hr
= NineVertexDeclaration9_ConvertStreamOutput(vdecl
,
3115 dst
, DestIndex
, VertexCount
,
3118 pipe_resource_reference(&resource
, NULL
);
3120 NineUnknown_Release(NineUnknown(vdecl
));
3125 NineDevice9_CreateVertexDeclaration( struct NineDevice9
*This
,
3126 const D3DVERTEXELEMENT9
*pVertexElements
,
3127 IDirect3DVertexDeclaration9
**ppDecl
)
3129 struct NineVertexDeclaration9
*vdecl
;
3131 DBG("This=%p pVertexElements=%p ppDecl=%p\n",
3132 This
, pVertexElements
, ppDecl
);
3134 HRESULT hr
= NineVertexDeclaration9_new(This
, pVertexElements
, &vdecl
);
3136 *ppDecl
= (IDirect3DVertexDeclaration9
*)vdecl
;
3142 NineDevice9_SetVertexDeclaration( struct NineDevice9
*This
,
3143 IDirect3DVertexDeclaration9
*pDecl
)
3145 struct nine_state
*state
= This
->update
;
3147 DBG("This=%p pDecl=%p\n", This
, pDecl
);
3149 if (likely(!This
->is_recording
) && state
->vdecl
== NineVertexDeclaration9(pDecl
))
3151 nine_bind(&state
->vdecl
, pDecl
);
3153 state
->changed
.group
|= NINE_STATE_VDECL
;
3159 NineDevice9_GetVertexDeclaration( struct NineDevice9
*This
,
3160 IDirect3DVertexDeclaration9
**ppDecl
)
3162 user_assert(ppDecl
, D3DERR_INVALIDCALL
);
3164 *ppDecl
= (IDirect3DVertexDeclaration9
*)This
->state
.vdecl
;
3166 NineUnknown_AddRef(NineUnknown(*ppDecl
));
3171 NineDevice9_SetFVF( struct NineDevice9
*This
,
3174 struct NineVertexDeclaration9
*vdecl
;
3177 DBG("FVF = %08x\n", FVF
);
3179 return D3D_OK
; /* like wine */
3181 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
3183 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
3187 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
3188 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
3190 return NineDevice9_SetVertexDeclaration(
3191 This
, (IDirect3DVertexDeclaration9
*)vdecl
);
3195 NineDevice9_GetFVF( struct NineDevice9
*This
,
3198 *pFVF
= This
->state
.vdecl
? This
->state
.vdecl
->fvf
: 0;
3203 NineDevice9_CreateVertexShader( struct NineDevice9
*This
,
3204 const DWORD
*pFunction
,
3205 IDirect3DVertexShader9
**ppShader
)
3207 struct NineVertexShader9
*vs
;
3210 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3212 hr
= NineVertexShader9_new(This
, &vs
, pFunction
, NULL
);
3215 *ppShader
= (IDirect3DVertexShader9
*)vs
;
3220 NineDevice9_SetVertexShader( struct NineDevice9
*This
,
3221 IDirect3DVertexShader9
*pShader
)
3223 struct nine_state
*state
= This
->update
;
3225 DBG("This=%p pShader=%p\n", This
, pShader
);
3227 nine_bind(&state
->vs
, pShader
);
3229 state
->changed
.group
|= NINE_STATE_VS
;
3235 NineDevice9_GetVertexShader( struct NineDevice9
*This
,
3236 IDirect3DVertexShader9
**ppShader
)
3238 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3239 nine_reference_set(ppShader
, This
->state
.vs
);
3244 NineDevice9_SetVertexShaderConstantF( struct NineDevice9
*This
,
3246 const float *pConstantData
,
3247 UINT Vector4fCount
)
3249 struct nine_state
*state
= This
->update
;
3251 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3252 This
, StartRegister
, pConstantData
, Vector4fCount
);
3254 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3255 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3259 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3261 memcpy(&state
->vs_const_f
[StartRegister
* 4],
3263 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3265 nine_ranges_insert(&state
->changed
.vs_const_f
,
3266 StartRegister
, StartRegister
+ Vector4fCount
,
3269 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3275 NineDevice9_GetVertexShaderConstantF( struct NineDevice9
*This
,
3277 float *pConstantData
,
3278 UINT Vector4fCount
)
3280 const struct nine_state
*state
= &This
->state
;
3282 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3283 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3284 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3286 memcpy(pConstantData
,
3287 &state
->vs_const_f
[StartRegister
* 4],
3288 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3294 NineDevice9_SetVertexShaderConstantI( struct NineDevice9
*This
,
3296 const int *pConstantData
,
3297 UINT Vector4iCount
)
3299 struct nine_state
*state
= This
->update
;
3302 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3303 This
, StartRegister
, pConstantData
, Vector4iCount
);
3305 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3306 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3307 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3309 if (This
->driver_caps
.vs_integer
) {
3310 memcpy(&state
->vs_const_i
[StartRegister
][0],
3312 Vector4iCount
* sizeof(state
->vs_const_i
[0]));
3314 for (i
= 0; i
< Vector4iCount
; i
++) {
3315 state
->vs_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3316 state
->vs_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3317 state
->vs_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3318 state
->vs_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3322 state
->changed
.vs_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3323 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3329 NineDevice9_GetVertexShaderConstantI( struct NineDevice9
*This
,
3332 UINT Vector4iCount
)
3334 const struct nine_state
*state
= &This
->state
;
3337 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3338 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3339 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3341 if (This
->driver_caps
.vs_integer
) {
3342 memcpy(pConstantData
,
3343 &state
->vs_const_i
[StartRegister
][0],
3344 Vector4iCount
* sizeof(state
->vs_const_i
[0]));
3346 for (i
= 0; i
< Vector4iCount
; i
++) {
3347 pConstantData
[4*i
] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][0]);
3348 pConstantData
[4*i
+1] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][1]);
3349 pConstantData
[4*i
+2] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][2]);
3350 pConstantData
[4*i
+3] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][3]);
3358 NineDevice9_SetVertexShaderConstantB( struct NineDevice9
*This
,
3360 const BOOL
*pConstantData
,
3363 struct nine_state
*state
= This
->update
;
3365 uint32_t bool_true
= This
->driver_caps
.vs_integer
? 0xFFFFFFFF : fui(1.0f
);
3367 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3368 This
, StartRegister
, pConstantData
, BoolCount
);
3370 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3371 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3372 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3374 for (i
= 0; i
< BoolCount
; i
++)
3375 state
->vs_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3377 state
->changed
.vs_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3378 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3384 NineDevice9_GetVertexShaderConstantB( struct NineDevice9
*This
,
3386 BOOL
*pConstantData
,
3389 const struct nine_state
*state
= &This
->state
;
3392 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3393 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3394 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3396 for (i
= 0; i
< BoolCount
; i
++)
3397 pConstantData
[i
] = state
->vs_const_b
[StartRegister
+ i
] != 0 ? TRUE
: FALSE
;
3403 NineDevice9_SetStreamSource( struct NineDevice9
*This
,
3405 IDirect3DVertexBuffer9
*pStreamData
,
3409 struct nine_state
*state
= This
->update
;
3410 struct NineVertexBuffer9
*pVBuf9
= NineVertexBuffer9(pStreamData
);
3411 const unsigned i
= StreamNumber
;
3413 DBG("This=%p StreamNumber=%u pStreamData=%p OffsetInBytes=%u Stride=%u\n",
3414 This
, StreamNumber
, pStreamData
, OffsetInBytes
, Stride
);
3416 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3417 user_assert(Stride
<= This
->caps
.MaxStreamStride
, D3DERR_INVALIDCALL
);
3419 if (likely(!This
->is_recording
)) {
3420 if (state
->stream
[i
] == NineVertexBuffer9(pStreamData
) &&
3421 state
->vtxbuf
[i
].stride
== Stride
&&
3422 state
->vtxbuf
[i
].buffer_offset
== OffsetInBytes
)
3425 nine_bind(&state
->stream
[i
], pStreamData
);
3427 state
->changed
.vtxbuf
|= 1 << StreamNumber
;
3430 state
->vtxbuf
[i
].stride
= Stride
;
3431 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3433 state
->vtxbuf
[i
].buffer
= pStreamData
? pVBuf9
->base
.resource
: NULL
;
3439 NineDevice9_GetStreamSource( struct NineDevice9
*This
,
3441 IDirect3DVertexBuffer9
**ppStreamData
,
3442 UINT
*pOffsetInBytes
,
3445 const struct nine_state
*state
= &This
->state
;
3446 const unsigned i
= StreamNumber
;
3448 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3449 user_assert(ppStreamData
, D3DERR_INVALIDCALL
);
3451 nine_reference_set(ppStreamData
, state
->stream
[i
]);
3452 *pStride
= state
->vtxbuf
[i
].stride
;
3453 *pOffsetInBytes
= state
->vtxbuf
[i
].buffer_offset
;
3459 NineDevice9_SetStreamSourceFreq( struct NineDevice9
*This
,
3463 struct nine_state
*state
= This
->update
;
3464 /* const UINT freq = Setting & 0x7FFFFF; */
3466 DBG("This=%p StreamNumber=%u FrequencyParameter=0x%x\n", This
,
3467 StreamNumber
, Setting
);
3469 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3470 user_assert(StreamNumber
!= 0 || !(Setting
& D3DSTREAMSOURCE_INSTANCEDATA
),
3471 D3DERR_INVALIDCALL
);
3472 user_assert(!((Setting
& D3DSTREAMSOURCE_INSTANCEDATA
) &&
3473 (Setting
& D3DSTREAMSOURCE_INDEXEDDATA
)), D3DERR_INVALIDCALL
);
3474 user_assert(Setting
, D3DERR_INVALIDCALL
);
3476 state
->stream_freq
[StreamNumber
] = Setting
;
3478 if (Setting
& D3DSTREAMSOURCE_INSTANCEDATA
)
3479 state
->stream_instancedata_mask
|= 1 << StreamNumber
;
3481 state
->stream_instancedata_mask
&= ~(1 << StreamNumber
);
3483 state
->changed
.stream_freq
|= 1 << StreamNumber
;
3488 NineDevice9_GetStreamSourceFreq( struct NineDevice9
*This
,
3492 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3493 *pSetting
= This
->state
.stream_freq
[StreamNumber
];
3498 NineDevice9_SetIndices( struct NineDevice9
*This
,
3499 IDirect3DIndexBuffer9
*pIndexData
)
3501 struct nine_state
*state
= This
->update
;
3503 DBG("This=%p pIndexData=%p\n", This
, pIndexData
);
3505 if (likely(!This
->is_recording
))
3506 if (state
->idxbuf
== NineIndexBuffer9(pIndexData
))
3508 nine_bind(&state
->idxbuf
, pIndexData
);
3510 state
->changed
.group
|= NINE_STATE_IDXBUF
;
3515 /* XXX: wine/d3d9 doesn't have pBaseVertexIndex, and it doesn't make sense
3516 * here because it's an argument passed to the Draw calls.
3519 NineDevice9_GetIndices( struct NineDevice9
*This
,
3520 IDirect3DIndexBuffer9
**ppIndexData
/*,
3521 UINT *pBaseVertexIndex */ )
3523 user_assert(ppIndexData
, D3DERR_INVALIDCALL
);
3524 nine_reference_set(ppIndexData
, This
->state
.idxbuf
);
3529 NineDevice9_CreatePixelShader( struct NineDevice9
*This
,
3530 const DWORD
*pFunction
,
3531 IDirect3DPixelShader9
**ppShader
)
3533 struct NinePixelShader9
*ps
;
3536 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3538 hr
= NinePixelShader9_new(This
, &ps
, pFunction
, NULL
);
3541 *ppShader
= (IDirect3DPixelShader9
*)ps
;
3546 NineDevice9_SetPixelShader( struct NineDevice9
*This
,
3547 IDirect3DPixelShader9
*pShader
)
3549 struct nine_state
*state
= This
->update
;
3550 unsigned old_mask
= state
->ps
? state
->ps
->rt_mask
: 1;
3553 DBG("This=%p pShader=%p\n", This
, pShader
);
3555 nine_bind(&state
->ps
, pShader
);
3557 state
->changed
.group
|= NINE_STATE_PS
;
3559 mask
= state
->ps
? state
->ps
->rt_mask
: 1;
3560 /* We need to update cbufs if the pixel shader would
3561 * write to different render targets */
3562 if (mask
!= old_mask
)
3563 state
->changed
.group
|= NINE_STATE_FB
;
3569 NineDevice9_GetPixelShader( struct NineDevice9
*This
,
3570 IDirect3DPixelShader9
**ppShader
)
3572 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3573 nine_reference_set(ppShader
, This
->state
.ps
);
3578 NineDevice9_SetPixelShaderConstantF( struct NineDevice9
*This
,
3580 const float *pConstantData
,
3581 UINT Vector4fCount
)
3583 struct nine_state
*state
= This
->update
;
3585 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3586 This
, StartRegister
, pConstantData
, Vector4fCount
);
3588 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3589 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3593 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3595 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3597 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3599 nine_ranges_insert(&state
->changed
.ps_const_f
,
3600 StartRegister
, StartRegister
+ Vector4fCount
,
3603 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3609 NineDevice9_GetPixelShaderConstantF( struct NineDevice9
*This
,
3611 float *pConstantData
,
3612 UINT Vector4fCount
)
3614 const struct nine_state
*state
= &This
->state
;
3616 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3617 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3618 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3620 memcpy(pConstantData
,
3621 &state
->ps_const_f
[StartRegister
* 4],
3622 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3628 NineDevice9_SetPixelShaderConstantI( struct NineDevice9
*This
,
3630 const int *pConstantData
,
3631 UINT Vector4iCount
)
3633 struct nine_state
*state
= This
->update
;
3636 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3637 This
, StartRegister
, pConstantData
, Vector4iCount
);
3639 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3640 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3641 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3643 if (This
->driver_caps
.ps_integer
) {
3644 memcpy(&state
->ps_const_i
[StartRegister
][0],
3646 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3648 for (i
= 0; i
< Vector4iCount
; i
++) {
3649 state
->ps_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3650 state
->ps_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3651 state
->ps_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3652 state
->ps_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3655 state
->changed
.ps_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3656 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3662 NineDevice9_GetPixelShaderConstantI( struct NineDevice9
*This
,
3665 UINT Vector4iCount
)
3667 const struct nine_state
*state
= &This
->state
;
3670 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3671 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3672 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3674 if (This
->driver_caps
.ps_integer
) {
3675 memcpy(pConstantData
,
3676 &state
->ps_const_i
[StartRegister
][0],
3677 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3679 for (i
= 0; i
< Vector4iCount
; i
++) {
3680 pConstantData
[4*i
] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][0]);
3681 pConstantData
[4*i
+1] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][1]);
3682 pConstantData
[4*i
+2] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][2]);
3683 pConstantData
[4*i
+3] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][3]);
3691 NineDevice9_SetPixelShaderConstantB( struct NineDevice9
*This
,
3693 const BOOL
*pConstantData
,
3696 struct nine_state
*state
= This
->update
;
3698 uint32_t bool_true
= This
->driver_caps
.ps_integer
? 0xFFFFFFFF : fui(1.0f
);
3700 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3701 This
, StartRegister
, pConstantData
, BoolCount
);
3703 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3704 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3705 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3707 for (i
= 0; i
< BoolCount
; i
++)
3708 state
->ps_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3710 state
->changed
.ps_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3711 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3717 NineDevice9_GetPixelShaderConstantB( struct NineDevice9
*This
,
3719 BOOL
*pConstantData
,
3722 const struct nine_state
*state
= &This
->state
;
3725 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3726 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3727 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3729 for (i
= 0; i
< BoolCount
; i
++)
3730 pConstantData
[i
] = state
->ps_const_b
[StartRegister
+ i
] ? TRUE
: FALSE
;
3736 NineDevice9_DrawRectPatch( struct NineDevice9
*This
,
3738 const float *pNumSegs
,
3739 const D3DRECTPATCH_INFO
*pRectPatchInfo
)
3741 STUB(D3DERR_INVALIDCALL
);
3745 NineDevice9_DrawTriPatch( struct NineDevice9
*This
,
3747 const float *pNumSegs
,
3748 const D3DTRIPATCH_INFO
*pTriPatchInfo
)
3750 STUB(D3DERR_INVALIDCALL
);
3754 NineDevice9_DeletePatch( struct NineDevice9
*This
,
3757 STUB(D3DERR_INVALIDCALL
);
3761 NineDevice9_CreateQuery( struct NineDevice9
*This
,
3763 IDirect3DQuery9
**ppQuery
)
3765 struct NineQuery9
*query
;
3768 DBG("This=%p Type=%d ppQuery=%p\n", This
, Type
, ppQuery
);
3770 hr
= nine_is_query_supported(This
->screen
, Type
);
3771 if (!ppQuery
|| hr
!= D3D_OK
)
3774 hr
= NineQuery9_new(This
, &query
, Type
);
3777 *ppQuery
= (IDirect3DQuery9
*)query
;
3781 IDirect3DDevice9Vtbl NineDevice9_vtable
= {
3782 (void *)NineUnknown_QueryInterface
,
3783 (void *)NineUnknown_AddRef
,
3784 (void *)NineUnknown_Release
,
3785 (void *)NineDevice9_TestCooperativeLevel
,
3786 (void *)NineDevice9_GetAvailableTextureMem
,
3787 (void *)NineDevice9_EvictManagedResources
,
3788 (void *)NineDevice9_GetDirect3D
,
3789 (void *)NineDevice9_GetDeviceCaps
,
3790 (void *)NineDevice9_GetDisplayMode
,
3791 (void *)NineDevice9_GetCreationParameters
,
3792 (void *)NineDevice9_SetCursorProperties
,
3793 (void *)NineDevice9_SetCursorPosition
,
3794 (void *)NineDevice9_ShowCursor
,
3795 (void *)NineDevice9_CreateAdditionalSwapChain
,
3796 (void *)NineDevice9_GetSwapChain
,
3797 (void *)NineDevice9_GetNumberOfSwapChains
,
3798 (void *)NineDevice9_Reset
,
3799 (void *)NineDevice9_Present
,
3800 (void *)NineDevice9_GetBackBuffer
,
3801 (void *)NineDevice9_GetRasterStatus
,
3802 (void *)NineDevice9_SetDialogBoxMode
,
3803 (void *)NineDevice9_SetGammaRamp
,
3804 (void *)NineDevice9_GetGammaRamp
,
3805 (void *)NineDevice9_CreateTexture
,
3806 (void *)NineDevice9_CreateVolumeTexture
,
3807 (void *)NineDevice9_CreateCubeTexture
,
3808 (void *)NineDevice9_CreateVertexBuffer
,
3809 (void *)NineDevice9_CreateIndexBuffer
,
3810 (void *)NineDevice9_CreateRenderTarget
,
3811 (void *)NineDevice9_CreateDepthStencilSurface
,
3812 (void *)NineDevice9_UpdateSurface
,
3813 (void *)NineDevice9_UpdateTexture
,
3814 (void *)NineDevice9_GetRenderTargetData
,
3815 (void *)NineDevice9_GetFrontBufferData
,
3816 (void *)NineDevice9_StretchRect
,
3817 (void *)NineDevice9_ColorFill
,
3818 (void *)NineDevice9_CreateOffscreenPlainSurface
,
3819 (void *)NineDevice9_SetRenderTarget
,
3820 (void *)NineDevice9_GetRenderTarget
,
3821 (void *)NineDevice9_SetDepthStencilSurface
,
3822 (void *)NineDevice9_GetDepthStencilSurface
,
3823 (void *)NineDevice9_BeginScene
,
3824 (void *)NineDevice9_EndScene
,
3825 (void *)NineDevice9_Clear
,
3826 (void *)NineDevice9_SetTransform
,
3827 (void *)NineDevice9_GetTransform
,
3828 (void *)NineDevice9_MultiplyTransform
,
3829 (void *)NineDevice9_SetViewport
,
3830 (void *)NineDevice9_GetViewport
,
3831 (void *)NineDevice9_SetMaterial
,
3832 (void *)NineDevice9_GetMaterial
,
3833 (void *)NineDevice9_SetLight
,
3834 (void *)NineDevice9_GetLight
,
3835 (void *)NineDevice9_LightEnable
,
3836 (void *)NineDevice9_GetLightEnable
,
3837 (void *)NineDevice9_SetClipPlane
,
3838 (void *)NineDevice9_GetClipPlane
,
3839 (void *)NineDevice9_SetRenderState
,
3840 (void *)NineDevice9_GetRenderState
,
3841 (void *)NineDevice9_CreateStateBlock
,
3842 (void *)NineDevice9_BeginStateBlock
,
3843 (void *)NineDevice9_EndStateBlock
,
3844 (void *)NineDevice9_SetClipStatus
,
3845 (void *)NineDevice9_GetClipStatus
,
3846 (void *)NineDevice9_GetTexture
,
3847 (void *)NineDevice9_SetTexture
,
3848 (void *)NineDevice9_GetTextureStageState
,
3849 (void *)NineDevice9_SetTextureStageState
,
3850 (void *)NineDevice9_GetSamplerState
,
3851 (void *)NineDevice9_SetSamplerState
,
3852 (void *)NineDevice9_ValidateDevice
,
3853 (void *)NineDevice9_SetPaletteEntries
,
3854 (void *)NineDevice9_GetPaletteEntries
,
3855 (void *)NineDevice9_SetCurrentTexturePalette
,
3856 (void *)NineDevice9_GetCurrentTexturePalette
,
3857 (void *)NineDevice9_SetScissorRect
,
3858 (void *)NineDevice9_GetScissorRect
,
3859 (void *)NineDevice9_SetSoftwareVertexProcessing
,
3860 (void *)NineDevice9_GetSoftwareVertexProcessing
,
3861 (void *)NineDevice9_SetNPatchMode
,
3862 (void *)NineDevice9_GetNPatchMode
,
3863 (void *)NineDevice9_DrawPrimitive
,
3864 (void *)NineDevice9_DrawIndexedPrimitive
,
3865 (void *)NineDevice9_DrawPrimitiveUP
,
3866 (void *)NineDevice9_DrawIndexedPrimitiveUP
,
3867 (void *)NineDevice9_ProcessVertices
,
3868 (void *)NineDevice9_CreateVertexDeclaration
,
3869 (void *)NineDevice9_SetVertexDeclaration
,
3870 (void *)NineDevice9_GetVertexDeclaration
,
3871 (void *)NineDevice9_SetFVF
,
3872 (void *)NineDevice9_GetFVF
,
3873 (void *)NineDevice9_CreateVertexShader
,
3874 (void *)NineDevice9_SetVertexShader
,
3875 (void *)NineDevice9_GetVertexShader
,
3876 (void *)NineDevice9_SetVertexShaderConstantF
,
3877 (void *)NineDevice9_GetVertexShaderConstantF
,
3878 (void *)NineDevice9_SetVertexShaderConstantI
,
3879 (void *)NineDevice9_GetVertexShaderConstantI
,
3880 (void *)NineDevice9_SetVertexShaderConstantB
,
3881 (void *)NineDevice9_GetVertexShaderConstantB
,
3882 (void *)NineDevice9_SetStreamSource
,
3883 (void *)NineDevice9_GetStreamSource
,
3884 (void *)NineDevice9_SetStreamSourceFreq
,
3885 (void *)NineDevice9_GetStreamSourceFreq
,
3886 (void *)NineDevice9_SetIndices
,
3887 (void *)NineDevice9_GetIndices
,
3888 (void *)NineDevice9_CreatePixelShader
,
3889 (void *)NineDevice9_SetPixelShader
,
3890 (void *)NineDevice9_GetPixelShader
,
3891 (void *)NineDevice9_SetPixelShaderConstantF
,
3892 (void *)NineDevice9_GetPixelShaderConstantF
,
3893 (void *)NineDevice9_SetPixelShaderConstantI
,
3894 (void *)NineDevice9_GetPixelShaderConstantI
,
3895 (void *)NineDevice9_SetPixelShaderConstantB
,
3896 (void *)NineDevice9_GetPixelShaderConstantB
,
3897 (void *)NineDevice9_DrawRectPatch
,
3898 (void *)NineDevice9_DrawTriPatch
,
3899 (void *)NineDevice9_DeletePatch
,
3900 (void *)NineDevice9_CreateQuery
3903 static const GUID
*NineDevice9_IIDs
[] = {
3904 &IID_IDirect3DDevice9
,
3910 NineDevice9_new( struct pipe_screen
*pScreen
,
3911 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
3913 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
3915 ID3DPresentGroup
*pPresentationGroup
,
3916 struct d3dadapter9_context
*pCTX
,
3918 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
3919 struct NineDevice9
**ppOut
)
3922 lock
= !!(pCreationParameters
->BehaviorFlags
& D3DCREATE_MULTITHREADED
);
3924 NINE_NEW(Device9
, ppOut
, lock
, /* args */
3925 pScreen
, pCreationParameters
, pCaps
,
3926 pPresentationParameters
, pD3D9
, pPresentationGroup
, pCTX
,
3927 ex
, pFullscreenDisplayMode
);