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 This
->state
.ps_lconstf_temp
= CALLOC(This
->ps_const_size
,1);
346 if (!This
->state
.vs_const_f
|| !This
->state
.ps_const_f
||
347 !This
->state
.vs_lconstf_temp
|| !This
->state
.ps_lconstf_temp
)
348 return E_OUTOFMEMORY
;
350 if (strstr(pScreen
->get_name(pScreen
), "AMD") ||
351 strstr(pScreen
->get_name(pScreen
), "ATI")) {
352 This
->prefer_user_constbuf
= TRUE
;
353 This
->driver_bugs
.buggy_barycentrics
= TRUE
;
356 tmpl
.target
= PIPE_BUFFER
;
357 tmpl
.format
= PIPE_FORMAT_R8_UNORM
;
363 tmpl
.usage
= PIPE_USAGE_DYNAMIC
;
364 tmpl
.bind
= PIPE_BIND_CONSTANT_BUFFER
;
367 tmpl
.width0
= This
->vs_const_size
;
368 This
->constbuf_vs
= pScreen
->resource_create(pScreen
, &tmpl
);
370 tmpl
.width0
= This
->ps_const_size
;
371 This
->constbuf_ps
= pScreen
->resource_create(pScreen
, &tmpl
);
373 if (!This
->constbuf_vs
|| !This
->constbuf_ps
)
374 return E_OUTOFMEMORY
;
377 /* allocate dummy texture/sampler for when there are missing ones bound */
379 struct pipe_resource tmplt
;
380 struct pipe_sampler_view templ
;
382 tmplt
.target
= PIPE_TEXTURE_2D
;
386 tmplt
.last_level
= 0;
387 tmplt
.array_size
= 1;
388 tmplt
.usage
= PIPE_USAGE_DEFAULT
;
390 tmplt
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
391 tmplt
.bind
= PIPE_BIND_SAMPLER_VIEW
;
392 tmplt
.nr_samples
= 0;
394 This
->dummy_texture
= This
->screen
->resource_create(This
->screen
, &tmplt
);
395 if (!This
->dummy_texture
)
396 return D3DERR_DRIVERINTERNALERROR
;
398 templ
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
399 templ
.u
.tex
.first_layer
= 0;
400 templ
.u
.tex
.last_layer
= 0;
401 templ
.u
.tex
.first_level
= 0;
402 templ
.u
.tex
.last_level
= 0;
403 templ
.swizzle_r
= PIPE_SWIZZLE_ZERO
;
404 templ
.swizzle_g
= PIPE_SWIZZLE_ZERO
;
405 templ
.swizzle_b
= PIPE_SWIZZLE_ZERO
;
406 templ
.swizzle_a
= PIPE_SWIZZLE_ONE
;
407 templ
.target
= This
->dummy_texture
->target
;
409 This
->dummy_sampler
= This
->pipe
->create_sampler_view(This
->pipe
, This
->dummy_texture
, &templ
);
410 if (!This
->dummy_sampler
)
411 return D3DERR_DRIVERINTERNALERROR
;
414 /* Allocate upload helper for drivers that suck (from st pov ;). */
418 This
->driver_caps
.user_vbufs
= GET_PCAP(USER_VERTEX_BUFFERS
);
419 This
->driver_caps
.user_ibufs
= GET_PCAP(USER_INDEX_BUFFERS
);
421 if (!This
->driver_caps
.user_vbufs
) bind
|= PIPE_BIND_VERTEX_BUFFER
;
422 if (!This
->driver_caps
.user_ibufs
) bind
|= PIPE_BIND_INDEX_BUFFER
;
424 This
->upload
= u_upload_create(This
->pipe
, 1 << 20, 4, bind
);
427 This
->driver_caps
.window_space_position_support
= GET_PCAP(TGSI_VS_WINDOW_SPACE_POSITION
);
428 This
->driver_caps
.vs_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
, PIPE_SHADER_CAP_INTEGERS
);
429 This
->driver_caps
.ps_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_FRAGMENT
, PIPE_SHADER_CAP_INTEGERS
);
431 nine_ff_init(This
); /* initialize fixed function code */
433 NineDevice9_SetDefaultState(This
, FALSE
);
434 NineDevice9_RestoreNonCSOState(This
, ~0);
436 This
->update
= &This
->state
;
437 nine_update_state(This
);
439 ID3DPresentGroup_Release(This
->present
);
446 NineDevice9_dtor( struct NineDevice9
*This
)
450 DBG("This=%p\n", This
);
452 if (This
->pipe
&& This
->cso
)
453 nine_pipe_context_clear(This
);
455 nine_state_clear(&This
->state
, TRUE
);
458 u_upload_destroy(This
->upload
);
460 nine_bind(&This
->record
, NULL
);
462 pipe_sampler_view_reference(&This
->dummy_sampler
, NULL
);
463 pipe_resource_reference(&This
->dummy_texture
, NULL
);
464 pipe_resource_reference(&This
->constbuf_vs
, NULL
);
465 pipe_resource_reference(&This
->constbuf_ps
, NULL
);
466 pipe_resource_reference(&This
->dummy_vbo
, NULL
);
467 FREE(This
->state
.vs_const_f
);
468 FREE(This
->state
.ps_const_f
);
469 FREE(This
->state
.vs_lconstf_temp
);
470 FREE(This
->state
.ps_lconstf_temp
);
472 if (This
->swapchains
) {
473 for (i
= 0; i
< This
->nswapchains
; ++i
)
474 NineUnknown_Unbind(NineUnknown(This
->swapchains
[i
]));
475 FREE(This
->swapchains
);
481 cso_destroy_context(This
->cso
);
483 if (This
->pipe
->destroy
) { This
->pipe
->destroy(This
->pipe
); }
486 if (This
->present
) { ID3DPresentGroup_Release(This
->present
); }
487 if (This
->d3d9
) { IDirect3D9_Release(This
->d3d9
); }
489 NineUnknown_dtor(&This
->base
);
493 NineDevice9_GetScreen( struct NineDevice9
*This
)
498 struct pipe_context
*
499 NineDevice9_GetPipe( struct NineDevice9
*This
)
505 NineDevice9_GetCSO( struct NineDevice9
*This
)
511 NineDevice9_GetCaps( struct NineDevice9
*This
)
517 NineDevice9_PauseRecording( struct NineDevice9
*This
)
520 This
->update
= &This
->state
;
521 This
->is_recording
= FALSE
;
526 NineDevice9_ResumeRecording( struct NineDevice9
*This
)
529 This
->update
= &This
->record
->state
;
530 This
->is_recording
= TRUE
;
535 NineDevice9_TestCooperativeLevel( struct NineDevice9
*This
)
537 return D3D_OK
; /* TODO */
541 NineDevice9_GetAvailableTextureMem( struct NineDevice9
*This
)
543 const unsigned mem
= This
->screen
->get_param(This
->screen
, PIPE_CAP_VIDEO_MEMORY
);
551 NineDevice9_EvictManagedResources( struct NineDevice9
*This
)
553 struct NineBaseTexture9
*tex
;
555 DBG("This=%p\n", This
);
556 LIST_FOR_EACH_ENTRY(tex
, &This
->managed_textures
, list2
) {
557 NineBaseTexture9_UnLoad(tex
);
564 NineDevice9_GetDirect3D( struct NineDevice9
*This
,
565 IDirect3D9
**ppD3D9
)
567 user_assert(ppD3D9
!= NULL
, E_POINTER
);
568 IDirect3D9_AddRef(This
->d3d9
);
569 *ppD3D9
= This
->d3d9
;
574 NineDevice9_GetDeviceCaps( struct NineDevice9
*This
,
577 user_assert(pCaps
!= NULL
, D3DERR_INVALIDCALL
);
583 NineDevice9_GetDisplayMode( struct NineDevice9
*This
,
585 D3DDISPLAYMODE
*pMode
)
587 DBG("This=%p iSwapChain=%u pMode=%p\n", This
, iSwapChain
, pMode
);
589 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
591 return NineSwapChain9_GetDisplayMode(This
->swapchains
[iSwapChain
], pMode
);
595 NineDevice9_GetCreationParameters( struct NineDevice9
*This
,
596 D3DDEVICE_CREATION_PARAMETERS
*pParameters
)
598 user_assert(pParameters
!= NULL
, D3DERR_INVALIDCALL
);
599 *pParameters
= This
->params
;
604 NineDevice9_SetCursorProperties( struct NineDevice9
*This
,
607 IDirect3DSurface9
*pCursorBitmap
)
609 struct NineSurface9
*surf
= NineSurface9(pCursorBitmap
);
610 struct pipe_context
*pipe
= This
->pipe
;
612 struct pipe_transfer
*transfer
;
616 DBG_FLAG(DBG_SWAPCHAIN
, "This=%p XHotSpot=%u YHotSpot=%u "
617 "pCursorBitmap=%p\n", This
, XHotSpot
, YHotSpot
, pCursorBitmap
);
619 user_assert(pCursorBitmap
, D3DERR_INVALIDCALL
);
621 if (This
->swapchains
[0]->params
.Windowed
) {
622 This
->cursor
.w
= MIN2(surf
->desc
.Width
, 32);
623 This
->cursor
.h
= MIN2(surf
->desc
.Height
, 32);
624 hw_cursor
= 1; /* always use hw cursor for windowed mode */
626 This
->cursor
.w
= MIN2(surf
->desc
.Width
, This
->cursor
.image
->width0
);
627 This
->cursor
.h
= MIN2(surf
->desc
.Height
, This
->cursor
.image
->height0
);
628 hw_cursor
= This
->cursor
.w
== 32 && This
->cursor
.h
== 32;
631 u_box_origin_2d(This
->cursor
.w
, This
->cursor
.h
, &box
);
633 ptr
= pipe
->transfer_map(pipe
, This
->cursor
.image
, 0,
634 PIPE_TRANSFER_WRITE
|
635 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
638 ret_err("Failed to update cursor image.\n", D3DERR_DRIVERINTERNALERROR
);
640 This
->cursor
.hotspot
.x
= XHotSpot
;
641 This
->cursor
.hotspot
.y
= YHotSpot
;
643 /* Copy cursor image to internal storage. */
647 const struct util_format_description
*sfmt
=
648 util_format_description(surf
->base
.info
.format
);
651 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, D3DLOCK_READONLY
);
653 ret_err("Failed to map cursor source image.\n",
654 D3DERR_DRIVERINTERNALERROR
);
656 sfmt
->unpack_rgba_8unorm(ptr
, transfer
->stride
,
657 lock
.pBits
, lock
.Pitch
,
658 This
->cursor
.w
, This
->cursor
.h
);
661 hw_cursor
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
,
663 &This
->cursor
.hotspot
,
664 This
->cursor
.visible
) == D3D_OK
;
666 NineSurface9_UnlockRect(surf
);
668 pipe
->transfer_unmap(pipe
, transfer
);
670 /* hide cursor if we emulate it */
672 ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, FALSE
);
673 This
->cursor
.software
= !hw_cursor
;
679 NineDevice9_SetCursorPosition( struct NineDevice9
*This
,
684 struct NineSwapChain9
*swap
= This
->swapchains
[0];
686 DBG("This=%p X=%d Y=%d Flags=%d\n", This
, X
, Y
, Flags
);
688 This
->cursor
.pos
.x
= X
;
689 This
->cursor
.pos
.y
= Y
;
691 if (!This
->cursor
.software
)
692 This
->cursor
.software
= ID3DPresent_SetCursorPos(swap
->present
, &This
->cursor
.pos
) != D3D_OK
;
696 NineDevice9_ShowCursor( struct NineDevice9
*This
,
699 BOOL old
= This
->cursor
.visible
;
701 DBG("This=%p bShow=%d\n", This
, (int) bShow
);
703 This
->cursor
.visible
= bShow
&& (This
->cursor
.hotspot
.x
!= -1);
704 if (!This
->cursor
.software
)
705 This
->cursor
.software
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, bShow
) != D3D_OK
;
711 NineDevice9_CreateAdditionalSwapChain( struct NineDevice9
*This
,
712 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
713 IDirect3DSwapChain9
**pSwapChain
)
715 struct NineSwapChain9
*swapchain
, *tmplt
= This
->swapchains
[0];
716 ID3DPresent
*present
;
719 DBG("This=%p pPresentationParameters=%p pSwapChain=%p\n",
720 This
, pPresentationParameters
, pSwapChain
);
722 user_assert(pPresentationParameters
, D3DERR_INVALIDCALL
);
724 hr
= ID3DPresentGroup_CreateAdditionalPresent(This
->present
, pPresentationParameters
, &present
);
729 hr
= NineSwapChain9_new(This
, FALSE
, present
, pPresentationParameters
,
731 tmplt
->params
.hDeviceWindow
,
736 *pSwapChain
= (IDirect3DSwapChain9
*)swapchain
;
741 NineDevice9_GetSwapChain( struct NineDevice9
*This
,
743 IDirect3DSwapChain9
**pSwapChain
)
745 user_assert(pSwapChain
!= NULL
, D3DERR_INVALIDCALL
);
748 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
750 NineUnknown_AddRef(NineUnknown(This
->swapchains
[iSwapChain
]));
751 *pSwapChain
= (IDirect3DSwapChain9
*)This
->swapchains
[iSwapChain
];
757 NineDevice9_GetNumberOfSwapChains( struct NineDevice9
*This
)
759 return This
->nswapchains
;
763 NineDevice9_Reset( struct NineDevice9
*This
,
764 D3DPRESENT_PARAMETERS
*pPresentationParameters
)
769 DBG("This=%p pPresentationParameters=%p\n", This
, pPresentationParameters
);
771 for (i
= 0; i
< This
->nswapchains
; ++i
) {
772 D3DPRESENT_PARAMETERS
*params
= &pPresentationParameters
[i
];
773 hr
= NineSwapChain9_Resize(This
->swapchains
[i
], params
, NULL
);
778 nine_pipe_context_clear(This
);
779 nine_state_clear(&This
->state
, TRUE
);
781 NineDevice9_SetDefaultState(This
, TRUE
);
782 NineDevice9_SetRenderTarget(
783 This
, 0, (IDirect3DSurface9
*)This
->swapchains
[0]->buffers
[0]);
784 /* XXX: better use GetBackBuffer here ? */
790 NineDevice9_Present( struct NineDevice9
*This
,
791 const RECT
*pSourceRect
,
792 const RECT
*pDestRect
,
793 HWND hDestWindowOverride
,
794 const RGNDATA
*pDirtyRegion
)
799 DBG("This=%p pSourceRect=%p pDestRect=%p hDestWindowOverride=%p pDirtyRegion=%p\n",
800 This
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
802 /* XXX is this right? */
803 for (i
= 0; i
< This
->nswapchains
; ++i
) {
804 hr
= NineSwapChain9_Present(This
->swapchains
[i
], pSourceRect
, pDestRect
,
805 hDestWindowOverride
, pDirtyRegion
, 0);
806 if (FAILED(hr
)) { return hr
; }
813 NineDevice9_GetBackBuffer( struct NineDevice9
*This
,
816 D3DBACKBUFFER_TYPE Type
,
817 IDirect3DSurface9
**ppBackBuffer
)
819 user_assert(ppBackBuffer
!= NULL
, D3DERR_INVALIDCALL
);
820 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
822 return NineSwapChain9_GetBackBuffer(This
->swapchains
[iSwapChain
],
823 iBackBuffer
, Type
, ppBackBuffer
);
827 NineDevice9_GetRasterStatus( struct NineDevice9
*This
,
829 D3DRASTER_STATUS
*pRasterStatus
)
831 user_assert(pRasterStatus
!= NULL
, D3DERR_INVALIDCALL
);
832 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
834 return NineSwapChain9_GetRasterStatus(This
->swapchains
[iSwapChain
],
839 NineDevice9_SetDialogBoxMode( struct NineDevice9
*This
,
840 BOOL bEnableDialogs
)
842 STUB(D3DERR_INVALIDCALL
);
846 NineDevice9_SetGammaRamp( struct NineDevice9
*This
,
849 const D3DGAMMARAMP
*pRamp
)
851 DBG("This=%p iSwapChain=%u Flags=%x pRamp=%p\n", This
,
852 iSwapChain
, Flags
, pRamp
);
854 user_warn(iSwapChain
>= This
->nswapchains
);
857 if (pRamp
&& (iSwapChain
< This
->nswapchains
)) {
858 struct NineSwapChain9
*swap
= This
->swapchains
[iSwapChain
];
859 swap
->gamma
= *pRamp
;
860 ID3DPresent_SetGammaRamp(swap
->present
, pRamp
, swap
->params
.hDeviceWindow
);
865 NineDevice9_GetGammaRamp( struct NineDevice9
*This
,
867 D3DGAMMARAMP
*pRamp
)
869 DBG("This=%p iSwapChain=%u pRamp=%p\n", This
, iSwapChain
, pRamp
);
871 user_warn(iSwapChain
>= This
->nswapchains
);
874 if (pRamp
&& (iSwapChain
< This
->nswapchains
))
875 *pRamp
= This
->swapchains
[iSwapChain
]->gamma
;
879 NineDevice9_CreateTexture( struct NineDevice9
*This
,
886 IDirect3DTexture9
**ppTexture
,
887 HANDLE
*pSharedHandle
)
889 struct NineTexture9
*tex
;
892 DBG("This=%p Width=%u Height=%u Levels=%u Usage=%s Format=%s Pool=%s "
893 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Levels
,
894 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
895 nine_D3DPOOL_to_str(Pool
), ppTexture
, pSharedHandle
);
897 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DMAP
|
898 D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
899 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
;
902 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
903 user_assert(!pSharedHandle
|| This
->ex
, D3DERR_INVALIDCALL
);
904 /* When is used shared handle, Pool must be
905 * SYSTEMMEM with Levels 1 or DEFAULT with any Levels */
906 user_assert(!pSharedHandle
|| Pool
!= D3DPOOL_SYSTEMMEM
|| Levels
== 1,
908 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_SYSTEMMEM
|| Pool
== D3DPOOL_DEFAULT
,
910 user_assert((Usage
!= D3DUSAGE_AUTOGENMIPMAP
|| Levels
<= 1), D3DERR_INVALIDCALL
);
912 hr
= NineTexture9_new(This
, Width
, Height
, Levels
, Usage
, Format
, Pool
,
913 &tex
, pSharedHandle
);
915 *ppTexture
= (IDirect3DTexture9
*)tex
;
921 NineDevice9_CreateVolumeTexture( struct NineDevice9
*This
,
929 IDirect3DVolumeTexture9
**ppVolumeTexture
,
930 HANDLE
*pSharedHandle
)
932 struct NineVolumeTexture9
*tex
;
935 DBG("This=%p Width=%u Height=%u Depth=%u Levels=%u Usage=%s Format=%s Pool=%s "
936 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Depth
, Levels
,
937 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
938 nine_D3DPOOL_to_str(Pool
), ppVolumeTexture
, pSharedHandle
);
940 Usage
&= D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
941 D3DUSAGE_SOFTWAREPROCESSING
;
943 *ppVolumeTexture
= NULL
;
944 user_assert(Width
&& Height
&& Depth
, D3DERR_INVALIDCALL
);
945 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
947 hr
= NineVolumeTexture9_new(This
, Width
, Height
, Depth
, Levels
,
948 Usage
, Format
, Pool
, &tex
, pSharedHandle
);
950 *ppVolumeTexture
= (IDirect3DVolumeTexture9
*)tex
;
956 NineDevice9_CreateCubeTexture( struct NineDevice9
*This
,
962 IDirect3DCubeTexture9
**ppCubeTexture
,
963 HANDLE
*pSharedHandle
)
965 struct NineCubeTexture9
*tex
;
968 DBG("This=%p EdgeLength=%u Levels=%u Usage=%s Format=%s Pool=%s ppOut=%p "
969 "pSharedHandle=%p\n", This
, EdgeLength
, Levels
,
970 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
971 nine_D3DPOOL_to_str(Pool
), ppCubeTexture
, pSharedHandle
);
973 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DYNAMIC
|
974 D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
975 D3DUSAGE_SOFTWAREPROCESSING
;
977 *ppCubeTexture
= NULL
;
978 user_assert(EdgeLength
, D3DERR_INVALIDCALL
);
979 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
981 hr
= NineCubeTexture9_new(This
, EdgeLength
, Levels
, Usage
, Format
, Pool
,
982 &tex
, pSharedHandle
);
984 *ppCubeTexture
= (IDirect3DCubeTexture9
*)tex
;
990 NineDevice9_CreateVertexBuffer( struct NineDevice9
*This
,
995 IDirect3DVertexBuffer9
**ppVertexBuffer
,
996 HANDLE
*pSharedHandle
)
998 struct NineVertexBuffer9
*buf
;
1000 D3DVERTEXBUFFER_DESC desc
;
1002 DBG("This=%p Length=%u Usage=%x FVF=%x Pool=%u ppOut=%p pSharedHandle=%p\n",
1003 This
, Length
, Usage
, FVF
, Pool
, ppVertexBuffer
, pSharedHandle
);
1005 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1007 desc
.Format
= D3DFMT_VERTEXDATA
;
1008 desc
.Type
= D3DRTYPE_VERTEXBUFFER
;
1009 desc
.Usage
= Usage
&
1010 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1011 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1012 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
|
1013 D3DUSAGE_WRITEONLY
);
1018 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1019 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1021 hr
= NineVertexBuffer9_new(This
, &desc
, &buf
);
1023 *ppVertexBuffer
= (IDirect3DVertexBuffer9
*)buf
;
1028 NineDevice9_CreateIndexBuffer( struct NineDevice9
*This
,
1033 IDirect3DIndexBuffer9
**ppIndexBuffer
,
1034 HANDLE
*pSharedHandle
)
1036 struct NineIndexBuffer9
*buf
;
1038 D3DINDEXBUFFER_DESC desc
;
1040 DBG("This=%p Length=%u Usage=%x Format=%s Pool=%u ppOut=%p "
1041 "pSharedHandle=%p\n", This
, Length
, Usage
,
1042 d3dformat_to_string(Format
), Pool
, ppIndexBuffer
, pSharedHandle
);
1044 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1046 desc
.Format
= Format
;
1047 desc
.Type
= D3DRTYPE_INDEXBUFFER
;
1048 desc
.Usage
= Usage
&
1049 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1050 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1051 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_WRITEONLY
);
1055 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1056 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1058 hr
= NineIndexBuffer9_new(This
, &desc
, &buf
);
1060 *ppIndexBuffer
= (IDirect3DIndexBuffer9
*)buf
;
1065 create_zs_or_rt_surface(struct NineDevice9
*This
,
1066 unsigned type
, /* 0 = RT, 1 = ZS, 2 = plain */
1068 UINT Width
, UINT Height
,
1070 D3DMULTISAMPLE_TYPE MultiSample
,
1071 DWORD MultisampleQuality
,
1072 BOOL Discard_or_Lockable
,
1073 IDirect3DSurface9
**ppSurface
,
1074 HANDLE
*pSharedHandle
)
1076 struct NineSurface9
*surface
;
1077 struct pipe_screen
*screen
= This
->screen
;
1078 struct pipe_resource
*resource
= NULL
;
1080 D3DSURFACE_DESC desc
;
1081 struct pipe_resource templ
;
1083 DBG("This=%p type=%u Pool=%s Width=%u Height=%u Format=%s MS=%u Quality=%u "
1084 "Discard_or_Lockable=%i ppSurface=%p pSharedHandle=%p\n",
1085 This
, type
, nine_D3DPOOL_to_str(Pool
), Width
, Height
,
1086 d3dformat_to_string(Format
), MultiSample
, MultisampleQuality
,
1087 Discard_or_Lockable
, ppSurface
, pSharedHandle
);
1090 DBG("FIXME Used shared handle! This option isn't probably handled correctly!\n");
1092 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
1093 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1095 templ
.target
= PIPE_TEXTURE_2D
;
1096 templ
.width0
= Width
;
1097 templ
.height0
= Height
;
1099 templ
.array_size
= 1;
1100 templ
.last_level
= 0;
1101 templ
.nr_samples
= (unsigned)MultiSample
;
1102 templ
.usage
= PIPE_USAGE_DEFAULT
;
1104 templ
.bind
= PIPE_BIND_SAMPLER_VIEW
; /* StretchRect */
1106 case 0: templ
.bind
|= PIPE_BIND_RENDER_TARGET
; break;
1107 case 1: templ
.bind
= d3d9_get_pipe_depth_format_bindings(Format
); break;
1112 templ
.format
= d3d9_to_pipe_format_checked(screen
, Format
, templ
.target
,
1113 templ
.nr_samples
, templ
.bind
,
1116 desc
.Format
= Format
;
1117 desc
.Type
= D3DRTYPE_SURFACE
;
1120 desc
.MultiSampleType
= MultiSample
;
1121 desc
.MultiSampleQuality
= MultisampleQuality
;
1123 desc
.Height
= Height
;
1125 case 0: desc
.Usage
= D3DUSAGE_RENDERTARGET
; break;
1126 case 1: desc
.Usage
= D3DUSAGE_DEPTHSTENCIL
; break;
1130 if (compressed_format(Format
)) {
1131 const unsigned w
= util_format_get_blockwidth(templ
.format
);
1132 const unsigned h
= util_format_get_blockheight(templ
.format
);
1134 user_assert(!(Width
% w
) && !(Height
% h
), D3DERR_INVALIDCALL
);
1137 if (Pool
== D3DPOOL_DEFAULT
&& Format
!= D3DFMT_NULL
) {
1138 /* resource_create doesn't return an error code, so check format here */
1139 user_assert(templ
.format
!= PIPE_FORMAT_NONE
, D3DERR_INVALIDCALL
);
1140 resource
= screen
->resource_create(screen
, &templ
);
1141 user_assert(resource
, D3DERR_OUTOFVIDEOMEMORY
);
1142 if (Discard_or_Lockable
&& (desc
.Usage
& D3DUSAGE_RENDERTARGET
))
1143 resource
->flags
|= NINE_RESOURCE_FLAG_LOCKABLE
;
1147 hr
= NineSurface9_new(This
, NULL
, resource
, NULL
, 0, 0, 0, &desc
, &surface
);
1148 pipe_resource_reference(&resource
, NULL
);
1151 *ppSurface
= (IDirect3DSurface9
*)surface
;
1156 NineDevice9_CreateRenderTarget( struct NineDevice9
*This
,
1160 D3DMULTISAMPLE_TYPE MultiSample
,
1161 DWORD MultisampleQuality
,
1163 IDirect3DSurface9
**ppSurface
,
1164 HANDLE
*pSharedHandle
)
1167 return create_zs_or_rt_surface(This
, 0, D3DPOOL_DEFAULT
,
1168 Width
, Height
, Format
,
1169 MultiSample
, MultisampleQuality
,
1170 Lockable
, ppSurface
, pSharedHandle
);
1174 NineDevice9_CreateDepthStencilSurface( struct NineDevice9
*This
,
1178 D3DMULTISAMPLE_TYPE MultiSample
,
1179 DWORD MultisampleQuality
,
1181 IDirect3DSurface9
**ppSurface
,
1182 HANDLE
*pSharedHandle
)
1185 if (!depth_stencil_format(Format
))
1186 return D3DERR_NOTAVAILABLE
;
1187 return create_zs_or_rt_surface(This
, 1, D3DPOOL_DEFAULT
,
1188 Width
, Height
, Format
,
1189 MultiSample
, MultisampleQuality
,
1190 Discard
, ppSurface
, pSharedHandle
);
1194 NineDevice9_UpdateSurface( struct NineDevice9
*This
,
1195 IDirect3DSurface9
*pSourceSurface
,
1196 const RECT
*pSourceRect
,
1197 IDirect3DSurface9
*pDestinationSurface
,
1198 const POINT
*pDestPoint
)
1200 struct NineSurface9
*dst
= NineSurface9(pDestinationSurface
);
1201 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1202 int copy_width
, copy_height
;
1205 DBG("This=%p pSourceSurface=%p pDestinationSurface=%p "
1206 "pSourceRect=%p pDestPoint=%p\n", This
,
1207 pSourceSurface
, pDestinationSurface
, pSourceRect
, pDestPoint
);
1209 DBG("pSourceRect = (%u,%u)-(%u,%u)\n",
1210 pSourceRect
->left
, pSourceRect
->top
,
1211 pSourceRect
->right
, pSourceRect
->bottom
);
1213 DBG("pDestPoint = (%u,%u)\n", pDestPoint
->x
, pDestPoint
->y
);
1215 user_assert(dst
&& src
, D3DERR_INVALIDCALL
);
1217 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1218 user_assert(src
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1220 user_assert(dst
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1221 user_assert(src
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1223 user_assert(!src
->lock_count
, D3DERR_INVALIDCALL
);
1224 user_assert(!dst
->lock_count
, D3DERR_INVALIDCALL
);
1226 user_assert(dst
->desc
.Format
== src
->desc
.Format
, D3DERR_INVALIDCALL
);
1227 user_assert(!depth_stencil_format(dst
->desc
.Format
), D3DERR_INVALIDCALL
);
1230 copy_width
= pSourceRect
->right
- pSourceRect
->left
;
1231 copy_height
= pSourceRect
->bottom
- pSourceRect
->top
;
1233 user_assert(pSourceRect
->left
>= 0 &&
1235 pSourceRect
->right
<= src
->desc
.Width
&&
1236 pSourceRect
->top
>= 0 &&
1238 pSourceRect
->bottom
<= src
->desc
.Height
,
1239 D3DERR_INVALIDCALL
);
1241 copy_width
= src
->desc
.Width
;
1242 copy_height
= src
->desc
.Height
;
1245 destRect
.right
= copy_width
;
1246 destRect
.bottom
= copy_height
;
1249 user_assert(pDestPoint
->x
>= 0 && pDestPoint
->y
>= 0,
1250 D3DERR_INVALIDCALL
);
1251 destRect
.right
+= pDestPoint
->x
;
1252 destRect
.bottom
+= pDestPoint
->y
;
1255 user_assert(destRect
.right
<= dst
->desc
.Width
&&
1256 destRect
.bottom
<= dst
->desc
.Height
,
1257 D3DERR_INVALIDCALL
);
1259 if (compressed_format(dst
->desc
.Format
)) {
1260 const unsigned w
= util_format_get_blockwidth(dst
->base
.info
.format
);
1261 const unsigned h
= util_format_get_blockheight(dst
->base
.info
.format
);
1264 user_assert(!(pDestPoint
->x
% w
) && !(pDestPoint
->y
% h
),
1265 D3DERR_INVALIDCALL
);
1269 user_assert(!(pSourceRect
->left
% w
) && !(pSourceRect
->top
% h
),
1270 D3DERR_INVALIDCALL
);
1272 if (!(copy_width
== src
->desc
.Width
&&
1273 copy_width
== dst
->desc
.Width
&&
1274 copy_height
== src
->desc
.Height
&&
1275 copy_height
== dst
->desc
.Height
)) {
1276 user_assert(!(copy_width
% w
) && !(copy_height
% h
),
1277 D3DERR_INVALIDCALL
);
1281 NineSurface9_CopyMemToDefault(dst
, src
, pDestPoint
, pSourceRect
);
1287 NineDevice9_UpdateTexture( struct NineDevice9
*This
,
1288 IDirect3DBaseTexture9
*pSourceTexture
,
1289 IDirect3DBaseTexture9
*pDestinationTexture
)
1291 struct NineBaseTexture9
*dstb
= NineBaseTexture9(pDestinationTexture
);
1292 struct NineBaseTexture9
*srcb
= NineBaseTexture9(pSourceTexture
);
1294 unsigned last_level
= dstb
->base
.info
.last_level
;
1297 DBG("This=%p pSourceTexture=%p pDestinationTexture=%p\n", This
,
1298 pSourceTexture
, pDestinationTexture
);
1300 user_assert(pSourceTexture
!= pDestinationTexture
, D3DERR_INVALIDCALL
);
1302 user_assert(dstb
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1303 user_assert(srcb
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1305 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1306 /* Only the first level is updated, the others regenerated. */
1308 /* if the source has D3DUSAGE_AUTOGENMIPMAP, we have to ignore
1309 * the sublevels, thus level 0 has to match */
1310 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ||
1311 (srcb
->base
.info
.width0
== dstb
->base
.info
.width0
&&
1312 srcb
->base
.info
.height0
== dstb
->base
.info
.height0
&&
1313 srcb
->base
.info
.depth0
== dstb
->base
.info
.depth0
),
1314 D3DERR_INVALIDCALL
);
1316 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
), D3DERR_INVALIDCALL
);
1319 user_assert(dstb
->base
.type
== srcb
->base
.type
, D3DERR_INVALIDCALL
);
1321 /* Find src level that matches dst level 0: */
1322 user_assert(srcb
->base
.info
.width0
>= dstb
->base
.info
.width0
&&
1323 srcb
->base
.info
.height0
>= dstb
->base
.info
.height0
&&
1324 srcb
->base
.info
.depth0
>= dstb
->base
.info
.depth0
,
1325 D3DERR_INVALIDCALL
);
1326 for (m
= 0; m
<= srcb
->base
.info
.last_level
; ++m
) {
1327 unsigned w
= u_minify(srcb
->base
.info
.width0
, m
);
1328 unsigned h
= u_minify(srcb
->base
.info
.height0
, m
);
1329 unsigned d
= u_minify(srcb
->base
.info
.depth0
, m
);
1331 if (w
== dstb
->base
.info
.width0
&&
1332 h
== dstb
->base
.info
.height0
&&
1333 d
== dstb
->base
.info
.depth0
)
1336 user_assert(m
<= srcb
->base
.info
.last_level
, D3DERR_INVALIDCALL
);
1338 last_level
= MIN2(last_level
, srcb
->base
.info
.last_level
- m
);
1340 if (dstb
->base
.type
== D3DRTYPE_TEXTURE
) {
1341 struct NineTexture9
*dst
= NineTexture9(dstb
);
1342 struct NineTexture9
*src
= NineTexture9(srcb
);
1344 if (src
->dirty_rect
.width
== 0)
1347 pipe_box_to_rect(&rect
, &src
->dirty_rect
);
1348 for (l
= 0; l
< m
; ++l
)
1349 rect_minify_inclusive(&rect
);
1351 for (l
= 0; l
<= last_level
; ++l
, ++m
) {
1352 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1354 dst
->surfaces
[l
]->desc
.Width
,
1355 dst
->surfaces
[l
]->desc
.Height
);
1356 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
],
1360 rect_minify_inclusive(&rect
);
1362 u_box_origin_2d(0, 0, &src
->dirty_rect
);
1364 if (dstb
->base
.type
== D3DRTYPE_CUBETEXTURE
) {
1365 struct NineCubeTexture9
*dst
= NineCubeTexture9(dstb
);
1366 struct NineCubeTexture9
*src
= NineCubeTexture9(srcb
);
1369 /* GPUs usually have them stored as arrays of mip-mapped 2D textures. */
1370 for (z
= 0; z
< 6; ++z
) {
1371 if (src
->dirty_rect
[z
].width
== 0)
1374 pipe_box_to_rect(&rect
, &src
->dirty_rect
[z
]);
1375 for (l
= 0; l
< m
; ++l
)
1376 rect_minify_inclusive(&rect
);
1378 for (l
= 0; l
<= last_level
; ++l
, ++m
) {
1379 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1381 dst
->surfaces
[l
* 6 + z
]->desc
.Width
,
1382 dst
->surfaces
[l
* 6 + z
]->desc
.Height
);
1383 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
* 6 + z
],
1384 src
->surfaces
[m
* 6 + z
],
1387 rect_minify_inclusive(&rect
);
1389 u_box_origin_2d(0, 0, &src
->dirty_rect
[z
]);
1393 if (dstb
->base
.type
== D3DRTYPE_VOLUMETEXTURE
) {
1394 struct NineVolumeTexture9
*dst
= NineVolumeTexture9(dstb
);
1395 struct NineVolumeTexture9
*src
= NineVolumeTexture9(srcb
);
1397 if (src
->dirty_box
.width
== 0)
1399 for (l
= 0; l
<= last_level
; ++l
, ++m
)
1400 NineVolume9_CopyMemToDefault(dst
->volumes
[l
],
1401 src
->volumes
[m
], 0, 0, 0, NULL
);
1402 u_box_3d(0, 0, 0, 0, 0, 0, &src
->dirty_box
);
1404 assert(!"invalid texture type");
1407 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1408 dstb
->dirty_mip
= TRUE
;
1409 NineBaseTexture9_GenerateMipSubLevels(dstb
);
1416 NineDevice9_GetRenderTargetData( struct NineDevice9
*This
,
1417 IDirect3DSurface9
*pRenderTarget
,
1418 IDirect3DSurface9
*pDestSurface
)
1420 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1421 struct NineSurface9
*src
= NineSurface9(pRenderTarget
);
1423 DBG("This=%p pRenderTarget=%p pDestSurface=%p\n",
1424 This
, pRenderTarget
, pDestSurface
);
1426 user_assert(dst
->desc
.Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1427 user_assert(src
->desc
.Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1429 user_assert(dst
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1430 user_assert(src
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1432 user_assert(src
->desc
.Width
== dst
->desc
.Width
, D3DERR_INVALIDCALL
);
1433 user_assert(src
->desc
.Height
== dst
->desc
.Height
, D3DERR_INVALIDCALL
);
1435 NineSurface9_CopyDefaultToMem(dst
, src
);
1441 NineDevice9_GetFrontBufferData( struct NineDevice9
*This
,
1443 IDirect3DSurface9
*pDestSurface
)
1445 DBG("This=%p iSwapChain=%u pDestSurface=%p\n", This
,
1446 iSwapChain
, pDestSurface
);
1448 user_assert(pDestSurface
!= NULL
, D3DERR_INVALIDCALL
);
1449 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
1451 return NineSwapChain9_GetFrontBufferData(This
->swapchains
[iSwapChain
],
1456 NineDevice9_StretchRect( struct NineDevice9
*This
,
1457 IDirect3DSurface9
*pSourceSurface
,
1458 const RECT
*pSourceRect
,
1459 IDirect3DSurface9
*pDestSurface
,
1460 const RECT
*pDestRect
,
1461 D3DTEXTUREFILTERTYPE Filter
)
1463 struct pipe_screen
*screen
= This
->screen
;
1464 struct pipe_context
*pipe
= This
->pipe
;
1465 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1466 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1467 struct pipe_resource
*dst_res
= NineSurface9_GetResource(dst
);
1468 struct pipe_resource
*src_res
= NineSurface9_GetResource(src
);
1469 const boolean zs
= util_format_is_depth_or_stencil(dst_res
->format
);
1470 struct pipe_blit_info blit
;
1471 boolean scaled
, clamped
, ms
, flip_x
= FALSE
, flip_y
= FALSE
;
1473 DBG("This=%p pSourceSurface=%p pSourceRect=%p pDestSurface=%p "
1474 "pDestRect=%p Filter=%u\n",
1475 This
, pSourceSurface
, pSourceRect
, pDestSurface
, pDestRect
, Filter
);
1477 DBG("pSourceRect=(%u,%u)-(%u,%u)\n",
1478 pSourceRect
->left
, pSourceRect
->top
,
1479 pSourceRect
->right
, pSourceRect
->bottom
);
1481 DBG("pDestRect=(%u,%u)-(%u,%u)\n", pDestRect
->left
, pDestRect
->top
,
1482 pDestRect
->right
, pDestRect
->bottom
);
1484 user_assert(!zs
|| !This
->in_scene
, D3DERR_INVALIDCALL
);
1485 user_assert(!zs
|| !pSourceRect
||
1486 (pSourceRect
->left
== 0 &&
1487 pSourceRect
->top
== 0 &&
1488 pSourceRect
->right
== src
->desc
.Width
&&
1489 pSourceRect
->bottom
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1490 user_assert(!zs
|| !pDestRect
||
1491 (pDestRect
->left
== 0 &&
1492 pDestRect
->top
== 0 &&
1493 pDestRect
->right
== dst
->desc
.Width
&&
1494 pDestRect
->bottom
== dst
->desc
.Height
), D3DERR_INVALIDCALL
);
1496 (dst
->desc
.Width
== src
->desc
.Width
&&
1497 dst
->desc
.Height
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1498 user_assert(zs
|| !util_format_is_depth_or_stencil(src_res
->format
),
1499 D3DERR_INVALIDCALL
);
1500 user_assert(!zs
|| dst
->desc
.Format
== src
->desc
.Format
,
1501 D3DERR_INVALIDCALL
);
1502 user_assert(screen
->is_format_supported(screen
, src_res
->format
,
1504 src_res
->nr_samples
,
1505 PIPE_BIND_SAMPLER_VIEW
),
1506 D3DERR_INVALIDCALL
);
1507 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
&&
1508 src
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1510 /* We might want to permit these, but wine thinks we shouldn't. */
1511 user_assert(!pDestRect
||
1512 (pDestRect
->left
<= pDestRect
->right
&&
1513 pDestRect
->top
<= pDestRect
->bottom
), D3DERR_INVALIDCALL
);
1514 user_assert(!pSourceRect
||
1515 (pSourceRect
->left
<= pSourceRect
->right
&&
1516 pSourceRect
->top
<= pSourceRect
->bottom
), D3DERR_INVALIDCALL
);
1518 memset(&blit
, 0, sizeof(blit
));
1519 blit
.dst
.resource
= dst_res
;
1520 blit
.dst
.level
= dst
->level
;
1521 blit
.dst
.box
.z
= dst
->layer
;
1522 blit
.dst
.box
.depth
= 1;
1523 blit
.dst
.format
= dst_res
->format
;
1525 flip_x
= pDestRect
->left
> pDestRect
->right
;
1527 blit
.dst
.box
.x
= pDestRect
->right
;
1528 blit
.dst
.box
.width
= pDestRect
->left
- pDestRect
->right
;
1530 blit
.dst
.box
.x
= pDestRect
->left
;
1531 blit
.dst
.box
.width
= pDestRect
->right
- pDestRect
->left
;
1533 flip_y
= pDestRect
->top
> pDestRect
->bottom
;
1535 blit
.dst
.box
.y
= pDestRect
->bottom
;
1536 blit
.dst
.box
.height
= pDestRect
->top
- pDestRect
->bottom
;
1538 blit
.dst
.box
.y
= pDestRect
->top
;
1539 blit
.dst
.box
.height
= pDestRect
->bottom
- pDestRect
->top
;
1544 blit
.dst
.box
.width
= dst
->desc
.Width
;
1545 blit
.dst
.box
.height
= dst
->desc
.Height
;
1547 blit
.src
.resource
= src_res
;
1548 blit
.src
.level
= src
->level
;
1549 blit
.src
.box
.z
= src
->layer
;
1550 blit
.src
.box
.depth
= 1;
1551 blit
.src
.format
= src_res
->format
;
1553 if (flip_x
^ (pSourceRect
->left
> pSourceRect
->right
)) {
1554 blit
.src
.box
.x
= pSourceRect
->right
;
1555 blit
.src
.box
.width
= pSourceRect
->left
- pSourceRect
->right
;
1557 blit
.src
.box
.x
= pSourceRect
->left
;
1558 blit
.src
.box
.width
= pSourceRect
->right
- pSourceRect
->left
;
1560 if (flip_y
^ (pSourceRect
->top
> pSourceRect
->bottom
)) {
1561 blit
.src
.box
.y
= pSourceRect
->bottom
;
1562 blit
.src
.box
.height
= pSourceRect
->top
- pSourceRect
->bottom
;
1564 blit
.src
.box
.y
= pSourceRect
->top
;
1565 blit
.src
.box
.height
= pSourceRect
->bottom
- pSourceRect
->top
;
1568 blit
.src
.box
.x
= flip_x
? src
->desc
.Width
: 0;
1569 blit
.src
.box
.y
= flip_y
? src
->desc
.Height
: 0;
1570 blit
.src
.box
.width
= flip_x
? -src
->desc
.Width
: src
->desc
.Width
;
1571 blit
.src
.box
.height
= flip_y
? -src
->desc
.Height
: src
->desc
.Height
;
1573 blit
.mask
= zs
? PIPE_MASK_ZS
: PIPE_MASK_RGBA
;
1574 blit
.filter
= Filter
== D3DTEXF_LINEAR
?
1575 PIPE_TEX_FILTER_LINEAR
: PIPE_TEX_FILTER_NEAREST
;
1576 blit
.scissor_enable
= FALSE
;
1577 blit
.alpha_blend
= FALSE
;
1579 /* If both of a src and dst dimension are negative, flip them. */
1580 if (blit
.dst
.box
.width
< 0 && blit
.src
.box
.width
< 0) {
1581 blit
.dst
.box
.width
= -blit
.dst
.box
.width
;
1582 blit
.src
.box
.width
= -blit
.src
.box
.width
;
1584 if (blit
.dst
.box
.height
< 0 && blit
.src
.box
.height
< 0) {
1585 blit
.dst
.box
.height
= -blit
.dst
.box
.height
;
1586 blit
.src
.box
.height
= -blit
.src
.box
.height
;
1589 blit
.dst
.box
.width
!= blit
.src
.box
.width
||
1590 blit
.dst
.box
.height
!= blit
.src
.box
.height
;
1592 user_assert(!scaled
|| dst
!= src
, D3DERR_INVALIDCALL
);
1593 user_assert(!scaled
||
1594 !NineSurface9_IsOffscreenPlain(dst
), D3DERR_INVALIDCALL
);
1595 user_assert(!NineSurface9_IsOffscreenPlain(dst
) ||
1596 NineSurface9_IsOffscreenPlain(src
), D3DERR_INVALIDCALL
);
1597 user_assert(NineSurface9_IsOffscreenPlain(dst
) ||
1598 dst
->desc
.Usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
),
1599 D3DERR_INVALIDCALL
);
1600 user_assert(!scaled
||
1601 (!util_format_is_compressed(dst
->base
.info
.format
) &&
1602 !util_format_is_compressed(src
->base
.info
.format
)),
1603 D3DERR_INVALIDCALL
);
1605 user_warn(src
== dst
&&
1606 u_box_test_intersection_2d(&blit
.src
.box
, &blit
.dst
.box
));
1608 /* Check for clipping/clamping: */
1610 struct pipe_box box
;
1613 xy
= u_box_clip_2d(&box
, &blit
.dst
.box
,
1614 dst
->desc
.Width
, dst
->desc
.Height
);
1618 xy
= u_box_clip_2d(&box
, &blit
.src
.box
,
1619 src
->desc
.Width
, src
->desc
.Height
);
1623 ms
= (dst
->desc
.MultiSampleType
| 1) != (src
->desc
.MultiSampleType
| 1);
1625 if (clamped
|| scaled
|| (blit
.dst
.format
!= blit
.src
.format
) || ms
) {
1626 DBG("using pipe->blit()\n");
1627 /* TODO: software scaling */
1628 user_assert(screen
->is_format_supported(screen
, dst_res
->format
,
1630 dst_res
->nr_samples
,
1631 zs
? PIPE_BIND_DEPTH_STENCIL
:
1632 PIPE_BIND_RENDER_TARGET
),
1633 D3DERR_INVALIDCALL
);
1635 pipe
->blit(pipe
, &blit
);
1637 assert(blit
.dst
.box
.x
>= 0 && blit
.dst
.box
.y
>= 0 &&
1638 blit
.src
.box
.x
>= 0 && blit
.src
.box
.y
>= 0 &&
1639 blit
.dst
.box
.x
+ blit
.dst
.box
.width
<= dst
->desc
.Width
&&
1640 blit
.src
.box
.x
+ blit
.src
.box
.width
<= src
->desc
.Width
&&
1641 blit
.dst
.box
.y
+ blit
.dst
.box
.height
<= dst
->desc
.Height
&&
1642 blit
.src
.box
.y
+ blit
.src
.box
.height
<= src
->desc
.Height
);
1643 /* Or drivers might crash ... */
1644 DBG("Using resource_copy_region.\n");
1645 pipe
->resource_copy_region(pipe
,
1646 blit
.dst
.resource
, blit
.dst
.level
,
1647 blit
.dst
.box
.x
, blit
.dst
.box
.y
, blit
.dst
.box
.z
,
1648 blit
.src
.resource
, blit
.src
.level
,
1652 /* Communicate the container it needs to update sublevels - if apply */
1653 NineSurface9_MarkContainerDirty(dst
);
1659 NineDevice9_ColorFill( struct NineDevice9
*This
,
1660 IDirect3DSurface9
*pSurface
,
1664 struct pipe_context
*pipe
= This
->pipe
;
1665 struct NineSurface9
*surf
= NineSurface9(pSurface
);
1666 struct pipe_surface
*psurf
;
1667 unsigned x
, y
, w
, h
;
1668 union pipe_color_union rgba
;
1671 DBG("This=%p pSurface=%p pRect=%p color=%08x\n", This
,
1672 pSurface
, pRect
, color
);
1674 DBG("pRect=(%u,%u)-(%u,%u)\n", pRect
->left
, pRect
->top
,
1675 pRect
->right
, pRect
->bottom
);
1677 user_assert(surf
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1679 user_assert((surf
->base
.usage
& D3DUSAGE_RENDERTARGET
) ||
1680 NineSurface9_IsOffscreenPlain(surf
), D3DERR_INVALIDCALL
);
1685 w
= pRect
->right
- pRect
->left
;
1686 h
= pRect
->bottom
- pRect
->top
;
1690 w
= surf
->desc
.Width
;
1691 h
= surf
->desc
.Height
;
1693 d3dcolor_to_pipe_color_union(&rgba
, color
);
1695 fallback
= !(surf
->base
.info
.bind
& PIPE_BIND_RENDER_TARGET
);
1698 psurf
= NineSurface9_GetSurface(surf
, 0);
1704 pipe
->clear_render_target(pipe
, psurf
, &rgba
, x
, y
, w
, h
);
1706 D3DLOCKED_RECT lock
;
1707 union util_color uc
;
1709 /* XXX: lock pRect and fix util_fill_rect */
1710 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, 0);
1713 util_pack_color_ub(color
>> 16, color
>> 8, color
>> 0, color
>> 24,
1714 surf
->base
.info
.format
, &uc
);
1715 util_fill_rect(lock
.pBits
, surf
->base
.info
.format
,lock
.Pitch
,
1717 NineSurface9_UnlockRect(surf
);
1724 NineDevice9_CreateOffscreenPlainSurface( struct NineDevice9
*This
,
1729 IDirect3DSurface9
**ppSurface
,
1730 HANDLE
*pSharedHandle
)
1734 DBG("This=%p Width=%u Height=%u Format=%s(0x%x) Pool=%u "
1735 "ppSurface=%p pSharedHandle=%p\n", This
,
1736 Width
, Height
, d3dformat_to_string(Format
), Format
, Pool
,
1737 ppSurface
, pSharedHandle
);
1740 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
1741 || Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1742 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1744 /* Can be used with StretchRect and ColorFill. It's also always lockable.
1746 hr
= create_zs_or_rt_surface(This
, 2, Pool
, Width
, Height
,
1748 D3DMULTISAMPLE_NONE
, 0,
1750 ppSurface
, pSharedHandle
);
1752 DBG("Failed to create surface.\n");
1757 NineDevice9_SetRenderTarget( struct NineDevice9
*This
,
1758 DWORD RenderTargetIndex
,
1759 IDirect3DSurface9
*pRenderTarget
)
1761 struct NineSurface9
*rt
= NineSurface9(pRenderTarget
);
1762 const unsigned i
= RenderTargetIndex
;
1764 DBG("This=%p RenderTargetIndex=%u pRenderTarget=%p\n", This
,
1765 RenderTargetIndex
, pRenderTarget
);
1767 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1768 user_assert(i
!= 0 || pRenderTarget
, D3DERR_INVALIDCALL
);
1769 user_assert(!pRenderTarget
||
1770 rt
->desc
.Usage
& D3DUSAGE_RENDERTARGET
, D3DERR_INVALIDCALL
);
1773 This
->state
.viewport
.X
= 0;
1774 This
->state
.viewport
.Y
= 0;
1775 This
->state
.viewport
.Width
= rt
->desc
.Width
;
1776 This
->state
.viewport
.Height
= rt
->desc
.Height
;
1777 This
->state
.viewport
.MinZ
= 0.0f
;
1778 This
->state
.viewport
.MaxZ
= 1.0f
;
1780 This
->state
.scissor
.minx
= 0;
1781 This
->state
.scissor
.miny
= 0;
1782 This
->state
.scissor
.maxx
= rt
->desc
.Width
;
1783 This
->state
.scissor
.maxy
= rt
->desc
.Height
;
1785 This
->state
.changed
.group
|= NINE_STATE_VIEWPORT
| NINE_STATE_SCISSOR
;
1788 if (This
->state
.rt
[i
] != NineSurface9(pRenderTarget
)) {
1789 nine_bind(&This
->state
.rt
[i
], pRenderTarget
);
1790 This
->state
.changed
.group
|= NINE_STATE_FB
;
1796 NineDevice9_GetRenderTarget( struct NineDevice9
*This
,
1797 DWORD RenderTargetIndex
,
1798 IDirect3DSurface9
**ppRenderTarget
)
1800 const unsigned i
= RenderTargetIndex
;
1802 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1803 user_assert(ppRenderTarget
, D3DERR_INVALIDCALL
);
1805 *ppRenderTarget
= (IDirect3DSurface9
*)This
->state
.rt
[i
];
1806 if (!This
->state
.rt
[i
])
1807 return D3DERR_NOTFOUND
;
1809 NineUnknown_AddRef(NineUnknown(This
->state
.rt
[i
]));
1814 NineDevice9_SetDepthStencilSurface( struct NineDevice9
*This
,
1815 IDirect3DSurface9
*pNewZStencil
)
1817 DBG("This=%p pNewZStencil=%p\n", This
, pNewZStencil
);
1819 if (This
->state
.ds
!= NineSurface9(pNewZStencil
)) {
1820 nine_bind(&This
->state
.ds
, pNewZStencil
);
1821 This
->state
.changed
.group
|= NINE_STATE_FB
;
1827 NineDevice9_GetDepthStencilSurface( struct NineDevice9
*This
,
1828 IDirect3DSurface9
**ppZStencilSurface
)
1830 user_assert(ppZStencilSurface
, D3DERR_INVALIDCALL
);
1832 *ppZStencilSurface
= (IDirect3DSurface9
*)This
->state
.ds
;
1833 if (!This
->state
.ds
)
1834 return D3DERR_NOTFOUND
;
1836 NineUnknown_AddRef(NineUnknown(This
->state
.ds
));
1841 NineDevice9_BeginScene( struct NineDevice9
*This
)
1843 DBG("This=%p\n", This
);
1844 user_assert(!This
->in_scene
, D3DERR_INVALIDCALL
);
1845 This
->in_scene
= TRUE
;
1846 /* Do we want to do anything else here ? */
1851 NineDevice9_EndScene( struct NineDevice9
*This
)
1853 DBG("This=%p\n", This
);
1854 user_assert(This
->in_scene
, D3DERR_INVALIDCALL
);
1855 This
->in_scene
= FALSE
;
1860 NineDevice9_Clear( struct NineDevice9
*This
,
1862 const D3DRECT
*pRects
,
1868 const int sRGB
= This
->state
.rs
[D3DRS_SRGBWRITEENABLE
] ? 1 : 0;
1869 struct pipe_surface
*cbuf
, *zsbuf
;
1870 struct pipe_context
*pipe
= This
->pipe
;
1871 struct NineSurface9
*zsbuf_surf
= This
->state
.ds
;
1872 struct NineSurface9
*rt
;
1875 union pipe_color_union rgba
;
1876 unsigned rt_mask
= 0;
1879 DBG("This=%p Count=%u pRects=%p Flags=%x Color=%08x Z=%f Stencil=%x\n",
1880 This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1882 user_assert(This
->state
.ds
|| !(Flags
& NINED3DCLEAR_DEPTHSTENCIL
),
1883 D3DERR_INVALIDCALL
);
1884 user_assert(!(Flags
& D3DCLEAR_STENCIL
) ||
1886 util_format_is_depth_and_stencil(zsbuf_surf
->base
.info
.format
)),
1887 D3DERR_INVALIDCALL
);
1889 user_assert((Count
&& pRects
) || (!Count
&& !pRects
), D3DERR_INVALIDCALL
);
1891 user_warn((pRects
&& !Count
) || (!pRects
&& Count
));
1892 if (pRects
&& !Count
)
1898 if (Flags
& D3DCLEAR_TARGET
) bufs
|= PIPE_CLEAR_COLOR
;
1899 if (Flags
& D3DCLEAR_ZBUFFER
) bufs
|= PIPE_CLEAR_DEPTH
;
1900 if (Flags
& D3DCLEAR_STENCIL
) bufs
|= PIPE_CLEAR_STENCIL
;
1903 d3dcolor_to_pipe_color_union(&rgba
, Color
);
1905 nine_update_state_framebuffer(This
);
1907 rect
.x1
= This
->state
.viewport
.X
;
1908 rect
.y1
= This
->state
.viewport
.Y
;
1909 rect
.x2
= This
->state
.viewport
.Width
+ rect
.x1
;
1910 rect
.y2
= This
->state
.viewport
.Height
+ rect
.y1
;
1912 /* Both rectangles apply, which is weird, but that's D3D9. */
1913 if (This
->state
.rs
[D3DRS_SCISSORTESTENABLE
]) {
1914 rect
.x1
= MAX2(rect
.x1
, This
->state
.scissor
.minx
);
1915 rect
.y1
= MAX2(rect
.y1
, This
->state
.scissor
.miny
);
1916 rect
.x2
= MIN2(rect
.x2
, This
->state
.scissor
.maxx
);
1917 rect
.y2
= MIN2(rect
.y2
, This
->state
.scissor
.maxy
);
1921 /* Maybe apps like to specify a large rect ? */
1922 if (pRects
[0].x1
<= rect
.x1
&& pRects
[0].x2
>= rect
.x2
&&
1923 pRects
[0].y1
<= rect
.y1
&& pRects
[0].y2
>= rect
.y2
) {
1924 DBG("First rect covers viewport.\n");
1930 if (rect
.x1
>= This
->state
.fb
.width
|| rect
.y1
>= This
->state
.fb
.height
)
1933 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
1934 if (This
->state
.rt
[i
] && This
->state
.rt
[i
]->desc
.Format
!= D3DFMT_NULL
)
1938 /* fast path, clears everything at once */
1940 (!(bufs
& PIPE_CLEAR_COLOR
) || (rt_mask
== This
->state
.rt_mask
)) &&
1941 rect
.x1
== 0 && rect
.y1
== 0 &&
1942 /* Case we clear only render target. Check clear region vs rt. */
1943 ((!(bufs
& (PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
)) &&
1944 rect
.x2
>= This
->state
.fb
.width
&&
1945 rect
.y2
>= This
->state
.fb
.height
) ||
1946 /* Case we clear depth buffer (and eventually rt too).
1947 * depth buffer size is always >= rt size. Compare to clear region */
1948 ((bufs
& (PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
)) &&
1949 This
->state
.fb
.zsbuf
!= NULL
&&
1950 rect
.x2
>= zsbuf_surf
->desc
.Width
&&
1951 rect
.y2
>= zsbuf_surf
->desc
.Height
))) {
1952 DBG("Clear fast path\n");
1953 pipe
->clear(pipe
, bufs
, &rgba
, Z
, Stencil
);
1962 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
1963 rt
= This
->state
.rt
[i
];
1964 if (!rt
|| rt
->desc
.Format
== D3DFMT_NULL
||
1965 !(Flags
& D3DCLEAR_TARGET
))
1966 continue; /* save space, compiler should hoist this */
1967 cbuf
= NineSurface9_GetSurface(rt
, sRGB
);
1968 for (r
= 0; r
< Count
; ++r
) {
1969 /* Don't trust users to pass these in the right order. */
1970 unsigned x1
= MIN2(pRects
[r
].x1
, pRects
[r
].x2
);
1971 unsigned y1
= MIN2(pRects
[r
].y1
, pRects
[r
].y2
);
1972 unsigned x2
= MAX2(pRects
[r
].x1
, pRects
[r
].x2
);
1973 unsigned y2
= MAX2(pRects
[r
].y1
, pRects
[r
].y2
);
1975 /* Drop negative rectangles (like wine expects). */
1976 if (pRects
[r
].x1
> pRects
[r
].x2
) continue;
1977 if (pRects
[r
].y1
> pRects
[r
].y2
) continue;
1980 x1
= MAX2(x1
, rect
.x1
);
1981 y1
= MAX2(y1
, rect
.y1
);
1982 x2
= MIN3(x2
, rect
.x2
, rt
->desc
.Width
);
1983 y2
= MIN3(y2
, rect
.y2
, rt
->desc
.Height
);
1985 DBG("Clearing (%u..%u)x(%u..%u)\n", x1
, x2
, y1
, y2
);
1986 pipe
->clear_render_target(pipe
, cbuf
, &rgba
,
1987 x1
, y1
, x2
- x1
, y2
- y1
);
1990 if (!(Flags
& NINED3DCLEAR_DEPTHSTENCIL
))
1993 bufs
&= PIPE_CLEAR_DEPTHSTENCIL
;
1995 for (r
= 0; r
< Count
; ++r
) {
1996 unsigned x1
= MIN2(pRects
[r
].x1
, pRects
[r
].x2
);
1997 unsigned y1
= MIN2(pRects
[r
].y1
, pRects
[r
].y2
);
1998 unsigned x2
= MAX2(pRects
[r
].x1
, pRects
[r
].x2
);
1999 unsigned y2
= MAX2(pRects
[r
].y1
, pRects
[r
].y2
);
2001 /* Drop negative rectangles. */
2002 if (pRects
[r
].x1
> pRects
[r
].x2
) continue;
2003 if (pRects
[r
].y1
> pRects
[r
].y2
) continue;
2006 x1
= MIN2(x1
, rect
.x1
);
2007 y1
= MIN2(y1
, rect
.y1
);
2008 x2
= MIN3(x2
, rect
.x2
, zsbuf_surf
->desc
.Width
);
2009 y2
= MIN3(y2
, rect
.y2
, zsbuf_surf
->desc
.Height
);
2011 zsbuf
= NineSurface9_GetSurface(zsbuf_surf
, 0);
2013 pipe
->clear_depth_stencil(pipe
, zsbuf
, bufs
, Z
, Stencil
,
2014 x1
, y1
, x2
- x1
, y2
- y1
);
2020 NineDevice9_SetTransform( struct NineDevice9
*This
,
2021 D3DTRANSFORMSTATETYPE State
,
2022 const D3DMATRIX
*pMatrix
)
2024 struct nine_state
*state
= This
->update
;
2025 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
2027 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2029 user_assert(M
, D3DERR_INVALIDCALL
);
2032 state
->ff
.changed
.transform
[State
/ 32] |= 1 << (State
% 32);
2033 state
->changed
.group
|= NINE_STATE_FF
;
2039 NineDevice9_GetTransform( struct NineDevice9
*This
,
2040 D3DTRANSFORMSTATETYPE State
,
2041 D3DMATRIX
*pMatrix
)
2043 D3DMATRIX
*M
= nine_state_access_transform(&This
->state
, State
, FALSE
);
2044 user_assert(M
, D3DERR_INVALIDCALL
);
2050 NineDevice9_MultiplyTransform( struct NineDevice9
*This
,
2051 D3DTRANSFORMSTATETYPE State
,
2052 const D3DMATRIX
*pMatrix
)
2054 struct nine_state
*state
= This
->update
;
2056 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
2058 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2060 user_assert(M
, D3DERR_INVALIDCALL
);
2062 nine_d3d_matrix_matrix_mul(&T
, pMatrix
, M
);
2063 return NineDevice9_SetTransform(This
, State
, &T
);
2067 NineDevice9_SetViewport( struct NineDevice9
*This
,
2068 const D3DVIEWPORT9
*pViewport
)
2070 struct nine_state
*state
= This
->update
;
2072 DBG("X=%u Y=%u W=%u H=%u MinZ=%f MaxZ=%f\n",
2073 pViewport
->X
, pViewport
->Y
, pViewport
->Width
, pViewport
->Height
,
2074 pViewport
->MinZ
, pViewport
->MaxZ
);
2076 state
->viewport
= *pViewport
;
2077 state
->changed
.group
|= NINE_STATE_VIEWPORT
;
2083 NineDevice9_GetViewport( struct NineDevice9
*This
,
2084 D3DVIEWPORT9
*pViewport
)
2086 *pViewport
= This
->state
.viewport
;
2091 NineDevice9_SetMaterial( struct NineDevice9
*This
,
2092 const D3DMATERIAL9
*pMaterial
)
2094 struct nine_state
*state
= This
->update
;
2096 DBG("This=%p pMaterial=%p\n", This
, pMaterial
);
2098 nine_dump_D3DMATERIAL9(DBG_FF
, pMaterial
);
2100 user_assert(pMaterial
, E_POINTER
);
2102 state
->ff
.material
= *pMaterial
;
2103 state
->changed
.group
|= NINE_STATE_FF_MATERIAL
;
2109 NineDevice9_GetMaterial( struct NineDevice9
*This
,
2110 D3DMATERIAL9
*pMaterial
)
2112 user_assert(pMaterial
, E_POINTER
);
2113 *pMaterial
= This
->state
.ff
.material
;
2118 NineDevice9_SetLight( struct NineDevice9
*This
,
2120 const D3DLIGHT9
*pLight
)
2122 struct nine_state
*state
= This
->update
;
2124 DBG("This=%p Index=%u pLight=%p\n", This
, Index
, pLight
);
2126 nine_dump_D3DLIGHT9(DBG_FF
, pLight
);
2128 user_assert(pLight
, D3DERR_INVALIDCALL
);
2129 user_assert(pLight
->Type
< NINED3DLIGHT_INVALID
, D3DERR_INVALIDCALL
);
2131 user_assert(Index
< NINE_MAX_LIGHTS
, D3DERR_INVALIDCALL
); /* sanity */
2133 if (Index
>= state
->ff
.num_lights
) {
2134 unsigned n
= state
->ff
.num_lights
;
2135 unsigned N
= Index
+ 1;
2137 state
->ff
.light
= REALLOC(state
->ff
.light
, n
* sizeof(D3DLIGHT9
),
2138 N
* sizeof(D3DLIGHT9
));
2139 if (!state
->ff
.light
)
2140 return E_OUTOFMEMORY
;
2141 state
->ff
.num_lights
= N
;
2143 for (; n
< Index
; ++n
) {
2144 memset(&state
->ff
.light
[n
], 0, sizeof(D3DLIGHT9
));
2145 state
->ff
.light
[n
].Type
= (D3DLIGHTTYPE
)NINED3DLIGHT_INVALID
;
2148 state
->ff
.light
[Index
] = *pLight
;
2150 if (pLight
->Type
== D3DLIGHT_SPOT
&& pLight
->Theta
>= pLight
->Phi
) {
2151 DBG("Warning: clamping D3DLIGHT9.Theta\n");
2152 state
->ff
.light
[Index
].Theta
= state
->ff
.light
[Index
].Phi
;
2154 if (pLight
->Type
!= D3DLIGHT_DIRECTIONAL
&&
2155 pLight
->Attenuation0
== 0.0f
&&
2156 pLight
->Attenuation1
== 0.0f
&&
2157 pLight
->Attenuation2
== 0.0f
) {
2158 DBG("Warning: all D3DLIGHT9.Attenuation[i] are 0\n");
2161 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2167 NineDevice9_GetLight( struct NineDevice9
*This
,
2171 const struct nine_state
*state
= &This
->state
;
2173 user_assert(pLight
, D3DERR_INVALIDCALL
);
2174 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2175 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2176 D3DERR_INVALIDCALL
);
2178 *pLight
= state
->ff
.light
[Index
];
2184 NineDevice9_LightEnable( struct NineDevice9
*This
,
2188 struct nine_state
*state
= This
->update
;
2191 DBG("This=%p Index=%u Enable=%i\n", This
, Index
, Enable
);
2193 if (Index
>= state
->ff
.num_lights
||
2194 state
->ff
.light
[Index
].Type
== NINED3DLIGHT_INVALID
) {
2195 /* This should create a default light. */
2197 memset(&light
, 0, sizeof(light
));
2198 light
.Type
= D3DLIGHT_DIRECTIONAL
;
2199 light
.Diffuse
.r
= 1.0f
;
2200 light
.Diffuse
.g
= 1.0f
;
2201 light
.Diffuse
.b
= 1.0f
;
2202 light
.Direction
.z
= 1.0f
;
2203 NineDevice9_SetLight(This
, Index
, &light
);
2205 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2207 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
) {
2208 if (state
->ff
.active_light
[i
] == Index
)
2213 if (i
< state
->ff
.num_lights_active
)
2215 /* XXX wine thinks this should still succeed:
2217 user_assert(i
< NINE_MAX_LIGHTS_ACTIVE
, D3DERR_INVALIDCALL
);
2219 state
->ff
.active_light
[i
] = Index
;
2220 state
->ff
.num_lights_active
++;
2222 if (i
== state
->ff
.num_lights_active
)
2224 --state
->ff
.num_lights_active
;
2225 for (; i
< state
->ff
.num_lights_active
; ++i
)
2226 state
->ff
.active_light
[i
] = state
->ff
.active_light
[i
+ 1];
2228 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2234 NineDevice9_GetLightEnable( struct NineDevice9
*This
,
2238 const struct nine_state
*state
= &This
->state
;
2241 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2242 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2243 D3DERR_INVALIDCALL
);
2245 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
)
2246 if (state
->ff
.active_light
[i
] == Index
)
2249 *pEnable
= i
!= state
->ff
.num_lights_active
? 128 : 0; // Taken from wine
2255 NineDevice9_SetClipPlane( struct NineDevice9
*This
,
2257 const float *pPlane
)
2259 struct nine_state
*state
= This
->update
;
2261 user_assert(pPlane
, D3DERR_INVALIDCALL
);
2263 DBG("This=%p Index=%u pPlane=%f %f %f %f\n", This
, Index
,
2264 pPlane
[0], pPlane
[1],
2265 pPlane
[2], pPlane
[3]);
2267 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2269 memcpy(&state
->clip
.ucp
[Index
][0], pPlane
, sizeof(state
->clip
.ucp
[0]));
2270 state
->changed
.ucp
|= 1 << Index
;
2276 NineDevice9_GetClipPlane( struct NineDevice9
*This
,
2280 const struct nine_state
*state
= &This
->state
;
2282 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2284 memcpy(pPlane
, &state
->clip
.ucp
[Index
][0], sizeof(state
->clip
.ucp
[0]));
2288 #define RESZ_CODE 0x7fa05000
2291 NineDevice9_ResolveZ( struct NineDevice9
*This
)
2293 struct nine_state
*state
= &This
->state
;
2294 const struct util_format_description
*desc
;
2295 struct NineSurface9
*source
= state
->ds
;
2296 struct NineBaseTexture9
*destination
= state
->texture
[0];
2297 struct pipe_resource
*src
, *dst
;
2298 struct pipe_blit_info blit
;
2300 DBG("RESZ resolve\n");
2302 user_assert(source
&& destination
&&
2303 destination
->base
.type
== D3DRTYPE_TEXTURE
, D3DERR_INVALIDCALL
);
2305 src
= source
->base
.resource
;
2306 dst
= destination
->base
.resource
;
2308 user_assert(src
&& dst
, D3DERR_INVALIDCALL
);
2310 /* check dst is depth format. we know already for src */
2311 desc
= util_format_description(dst
->format
);
2312 user_assert(desc
->colorspace
== UTIL_FORMAT_COLORSPACE_ZS
, D3DERR_INVALIDCALL
);
2314 memset(&blit
, 0, sizeof(blit
));
2315 blit
.src
.resource
= src
;
2317 blit
.src
.format
= src
->format
;
2319 blit
.src
.box
.depth
= 1;
2322 blit
.src
.box
.width
= src
->width0
;
2323 blit
.src
.box
.height
= src
->height0
;
2325 blit
.dst
.resource
= dst
;
2327 blit
.dst
.format
= dst
->format
;
2329 blit
.dst
.box
.depth
= 1;
2332 blit
.dst
.box
.width
= dst
->width0
;
2333 blit
.dst
.box
.height
= dst
->height0
;
2335 blit
.mask
= PIPE_MASK_ZS
;
2336 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
2337 blit
.scissor_enable
= FALSE
;
2339 This
->pipe
->blit(This
->pipe
, &blit
);
2343 #define ALPHA_TO_COVERAGE_ENABLE MAKEFOURCC('A', '2', 'M', '1')
2344 #define ALPHA_TO_COVERAGE_DISABLE MAKEFOURCC('A', '2', 'M', '0')
2347 NineDevice9_SetRenderState( struct NineDevice9
*This
,
2348 D3DRENDERSTATETYPE State
,
2351 struct nine_state
*state
= This
->update
;
2353 DBG("This=%p State=%u(%s) Value=%08x\n", This
,
2354 State
, nine_d3drs_to_string(State
), Value
);
2356 /* Amd hacks (equivalent to GL extensions) */
2357 if (State
== D3DRS_POINTSIZE
) {
2358 if (Value
== RESZ_CODE
)
2359 return NineDevice9_ResolveZ(This
);
2361 if (Value
== ALPHA_TO_COVERAGE_ENABLE
||
2362 Value
== ALPHA_TO_COVERAGE_DISABLE
) {
2363 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
== ALPHA_TO_COVERAGE_ENABLE
);
2364 state
->changed
.group
|= NINE_STATE_BLEND
;
2370 if (State
== D3DRS_ADAPTIVETESS_Y
&&
2371 (Value
== D3DFMT_ATOC
|| (Value
== D3DFMT_UNKNOWN
&& state
->rs
[NINED3DRS_ALPHACOVERAGE
]))) {
2372 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
== D3DFMT_ATOC
);
2373 state
->changed
.group
|= NINE_STATE_BLEND
;
2377 user_assert(State
< Elements(state
->rs
), D3DERR_INVALIDCALL
);
2379 if (likely(state
->rs
[State
] != Value
) || unlikely(This
->is_recording
)) {
2380 state
->rs
[State
] = Value
;
2381 state
->changed
.rs
[State
/ 32] |= 1 << (State
% 32);
2382 state
->changed
.group
|= nine_render_state_group
[State
];
2389 NineDevice9_GetRenderState( struct NineDevice9
*This
,
2390 D3DRENDERSTATETYPE State
,
2393 user_assert(State
< Elements(This
->state
.rs
), D3DERR_INVALIDCALL
);
2395 *pValue
= This
->state
.rs
[State
];
2400 NineDevice9_CreateStateBlock( struct NineDevice9
*This
,
2401 D3DSTATEBLOCKTYPE Type
,
2402 IDirect3DStateBlock9
**ppSB
)
2404 struct NineStateBlock9
*nsb
;
2405 struct nine_state
*dst
;
2407 enum nine_stateblock_type type
;
2410 DBG("This=%p Type=%u ppSB=%p\n", This
, Type
, ppSB
);
2412 user_assert(Type
== D3DSBT_ALL
||
2413 Type
== D3DSBT_VERTEXSTATE
||
2414 Type
== D3DSBT_PIXELSTATE
, D3DERR_INVALIDCALL
);
2417 case D3DSBT_VERTEXSTATE
: type
= NINESBT_VERTEXSTATE
; break;
2418 case D3DSBT_PIXELSTATE
: type
= NINESBT_PIXELSTATE
; break;
2424 hr
= NineStateBlock9_new(This
, &nsb
, type
);
2427 *ppSB
= (IDirect3DStateBlock9
*)nsb
;
2430 dst
->changed
.group
=
2431 NINE_STATE_TEXTURE
|
2434 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_VERTEXSTATE
) {
2435 dst
->changed
.group
|=
2436 NINE_STATE_FF_LIGHTING
|
2437 NINE_STATE_VS
| NINE_STATE_VS_CONST
|
2439 /* TODO: texture/sampler state */
2440 memcpy(dst
->changed
.rs
,
2441 nine_render_states_vertex
, sizeof(dst
->changed
.rs
));
2442 nine_ranges_insert(&dst
->changed
.vs_const_f
, 0, This
->max_vs_const_f
,
2444 dst
->changed
.vs_const_i
= 0xffff;
2445 dst
->changed
.vs_const_b
= 0xffff;
2446 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2447 dst
->changed
.sampler
[s
] |= 1 << D3DSAMP_DMAPOFFSET
;
2448 if (This
->state
.ff
.num_lights
) {
2449 dst
->ff
.num_lights
= This
->state
.ff
.num_lights
;
2450 /* zero'd -> light type won't be NINED3DLIGHT_INVALID, so
2451 * all currently existing lights will be captured
2453 dst
->ff
.light
= CALLOC(This
->state
.ff
.num_lights
,
2455 if (!dst
->ff
.light
) {
2456 nine_bind(ppSB
, NULL
);
2457 return E_OUTOFMEMORY
;
2461 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_PIXELSTATE
) {
2462 dst
->changed
.group
|=
2463 NINE_STATE_PS
| NINE_STATE_PS_CONST
;
2464 /* TODO: texture/sampler state */
2465 memcpy(dst
->changed
.rs
,
2466 nine_render_states_pixel
, sizeof(dst
->changed
.rs
));
2467 nine_ranges_insert(&dst
->changed
.ps_const_f
, 0, This
->max_ps_const_f
,
2469 dst
->changed
.ps_const_i
= 0xffff;
2470 dst
->changed
.ps_const_b
= 0xffff;
2471 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2472 dst
->changed
.sampler
[s
] |= 0x1ffe;
2474 if (Type
== D3DSBT_ALL
) {
2475 dst
->changed
.group
|=
2476 NINE_STATE_VIEWPORT
|
2477 NINE_STATE_SCISSOR
|
2478 NINE_STATE_RASTERIZER
|
2482 NINE_STATE_MATERIAL
|
2483 NINE_STATE_BLEND_COLOR
|
2484 NINE_STATE_SAMPLE_MASK
;
2485 memset(dst
->changed
.rs
, ~0, (D3DRS_COUNT
/ 32) * sizeof(uint32_t));
2486 dst
->changed
.rs
[D3DRS_LAST
/ 32] |= (1 << (D3DRS_COUNT
% 32)) - 1;
2487 dst
->changed
.vtxbuf
= (1ULL << This
->caps
.MaxStreams
) - 1;
2488 dst
->changed
.stream_freq
= dst
->changed
.vtxbuf
;
2489 dst
->changed
.ucp
= (1 << PIPE_MAX_CLIP_PLANES
) - 1;
2490 dst
->changed
.texture
= (1 << NINE_MAX_SAMPLERS
) - 1;
2492 NineStateBlock9_Capture(NineStateBlock9(*ppSB
));
2494 /* TODO: fixed function state */
2500 NineDevice9_BeginStateBlock( struct NineDevice9
*This
)
2504 DBG("This=%p\n", This
);
2506 user_assert(!This
->record
, D3DERR_INVALIDCALL
);
2508 hr
= NineStateBlock9_new(This
, &This
->record
, NINESBT_CUSTOM
);
2511 NineUnknown_ConvertRefToBind(NineUnknown(This
->record
));
2513 This
->update
= &This
->record
->state
;
2514 This
->is_recording
= TRUE
;
2520 NineDevice9_EndStateBlock( struct NineDevice9
*This
,
2521 IDirect3DStateBlock9
**ppSB
)
2523 DBG("This=%p ppSB=%p\n", This
, ppSB
);
2525 user_assert(This
->record
, D3DERR_INVALIDCALL
);
2527 This
->update
= &This
->state
;
2528 This
->is_recording
= FALSE
;
2530 NineUnknown_AddRef(NineUnknown(This
->record
));
2531 *ppSB
= (IDirect3DStateBlock9
*)This
->record
;
2532 NineUnknown_Unbind(NineUnknown(This
->record
));
2533 This
->record
= NULL
;
2539 NineDevice9_SetClipStatus( struct NineDevice9
*This
,
2540 const D3DCLIPSTATUS9
*pClipStatus
)
2542 STUB(D3DERR_INVALIDCALL
);
2546 NineDevice9_GetClipStatus( struct NineDevice9
*This
,
2547 D3DCLIPSTATUS9
*pClipStatus
)
2549 STUB(D3DERR_INVALIDCALL
);
2553 NineDevice9_GetTexture( struct NineDevice9
*This
,
2555 IDirect3DBaseTexture9
**ppTexture
)
2557 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2558 Stage
== D3DDMAPSAMPLER
||
2559 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2560 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2561 user_assert(ppTexture
, D3DERR_INVALIDCALL
);
2563 if (Stage
>= D3DDMAPSAMPLER
)
2564 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2566 *ppTexture
= (IDirect3DBaseTexture9
*)This
->state
.texture
[Stage
];
2568 if (This
->state
.texture
[Stage
])
2569 NineUnknown_AddRef(NineUnknown(This
->state
.texture
[Stage
]));
2574 NineDevice9_SetTexture( struct NineDevice9
*This
,
2576 IDirect3DBaseTexture9
*pTexture
)
2578 struct nine_state
*state
= This
->update
;
2579 struct NineBaseTexture9
*tex
= NineBaseTexture9(pTexture
);
2581 DBG("This=%p Stage=%u pTexture=%p\n", This
, Stage
, pTexture
);
2583 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2584 Stage
== D3DDMAPSAMPLER
||
2585 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2586 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2587 user_assert(!tex
|| (tex
->base
.pool
!= D3DPOOL_SCRATCH
&&
2588 tex
->base
.pool
!= D3DPOOL_SYSTEMMEM
), D3DERR_INVALIDCALL
);
2590 if (Stage
>= D3DDMAPSAMPLER
)
2591 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2593 if (!This
->is_recording
) {
2594 struct NineBaseTexture9
*old
= state
->texture
[Stage
];
2598 state
->samplers_shadow
&= ~(1 << Stage
);
2600 state
->samplers_shadow
|= tex
->shadow
<< Stage
;
2602 if ((tex
->managed
.dirty
| tex
->dirty_mip
) && LIST_IS_EMPTY(&tex
->list
))
2603 list_add(&tex
->list
, &This
->update_textures
);
2610 nine_bind(&state
->texture
[Stage
], pTexture
);
2612 state
->changed
.texture
|= 1 << Stage
;
2613 state
->changed
.group
|= NINE_STATE_TEXTURE
;
2619 NineDevice9_GetTextureStageState( struct NineDevice9
*This
,
2621 D3DTEXTURESTAGESTATETYPE Type
,
2624 const struct nine_state
*state
= &This
->state
;
2626 user_assert(Stage
< Elements(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2627 user_assert(Type
< Elements(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2629 *pValue
= state
->ff
.tex_stage
[Stage
][Type
];
2635 NineDevice9_SetTextureStageState( struct NineDevice9
*This
,
2637 D3DTEXTURESTAGESTATETYPE Type
,
2640 struct nine_state
*state
= This
->update
;
2641 int bumpmap_index
= -1;
2643 DBG("Stage=%u Type=%u Value=%08x\n", Stage
, Type
, Value
);
2644 nine_dump_D3DTSS_value(DBG_FF
, Type
, Value
);
2646 user_assert(Stage
< Elements(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2647 user_assert(Type
< Elements(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2649 state
->ff
.tex_stage
[Stage
][Type
] = Value
;
2651 case D3DTSS_BUMPENVMAT00
:
2652 bumpmap_index
= 4 * Stage
;
2654 case D3DTSS_BUMPENVMAT10
:
2655 bumpmap_index
= 4 * Stage
+ 1;
2657 case D3DTSS_BUMPENVMAT01
:
2658 bumpmap_index
= 4 * Stage
+ 2;
2660 case D3DTSS_BUMPENVMAT11
:
2661 bumpmap_index
= 4 * Stage
+ 3;
2663 case D3DTSS_BUMPENVLSCALE
:
2664 bumpmap_index
= 4 * 8 + 2 * Stage
;
2666 case D3DTSS_BUMPENVLOFFSET
:
2667 bumpmap_index
= 4 * 8 + 2 * Stage
+ 1;
2673 if (bumpmap_index
>= 0) {
2674 state
->bumpmap_vars
[bumpmap_index
] = Value
;
2675 state
->changed
.group
|= NINE_STATE_PS_CONST
;
2678 state
->changed
.group
|= NINE_STATE_FF_PSSTAGES
;
2679 state
->ff
.changed
.tex_stage
[Stage
][Type
/ 32] |= 1 << (Type
% 32);
2685 NineDevice9_GetSamplerState( struct NineDevice9
*This
,
2687 D3DSAMPLERSTATETYPE Type
,
2690 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2691 Sampler
== D3DDMAPSAMPLER
||
2692 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2693 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2695 if (Sampler
>= D3DDMAPSAMPLER
)
2696 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2698 *pValue
= This
->state
.samp
[Sampler
][Type
];
2703 NineDevice9_SetSamplerState( struct NineDevice9
*This
,
2705 D3DSAMPLERSTATETYPE Type
,
2708 struct nine_state
*state
= This
->update
;
2710 DBG("This=%p Sampler=%u Type=%s Value=%08x\n", This
,
2711 Sampler
, nine_D3DSAMP_to_str(Type
), Value
);
2713 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2714 Sampler
== D3DDMAPSAMPLER
||
2715 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2716 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2718 if (Sampler
>= D3DDMAPSAMPLER
)
2719 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2721 state
->samp
[Sampler
][Type
] = Value
;
2722 state
->changed
.group
|= NINE_STATE_SAMPLER
;
2723 state
->changed
.sampler
[Sampler
] |= 1 << Type
;
2725 if (Type
== D3DSAMP_SRGBTEXTURE
)
2726 state
->changed
.srgb
= TRUE
;
2732 NineDevice9_ValidateDevice( struct NineDevice9
*This
,
2735 const struct nine_state
*state
= &This
->state
;
2737 unsigned w
= 0, h
= 0;
2739 DBG("This=%p pNumPasses=%p\n", This
, pNumPasses
);
2741 for (i
= 0; i
< Elements(state
->samp
); ++i
) {
2742 if (state
->samp
[i
][D3DSAMP_MINFILTER
] == D3DTEXF_NONE
||
2743 state
->samp
[i
][D3DSAMP_MAGFILTER
] == D3DTEXF_NONE
)
2744 return D3DERR_UNSUPPORTEDTEXTUREFILTER
;
2747 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2751 w
= state
->rt
[i
]->desc
.Width
;
2752 h
= state
->rt
[i
]->desc
.Height
;
2754 if (state
->rt
[i
]->desc
.Width
!= w
|| state
->rt
[i
]->desc
.Height
!= h
) {
2755 return D3DERR_CONFLICTINGRENDERSTATE
;
2759 (state
->rs
[D3DRS_ZENABLE
] || state
->rs
[D3DRS_STENCILENABLE
])) {
2761 (state
->ds
->desc
.Width
!= w
|| state
->ds
->desc
.Height
!= h
))
2762 return D3DERR_CONFLICTINGRENDERSTATE
;
2772 NineDevice9_SetPaletteEntries( struct NineDevice9
*This
,
2774 const PALETTEENTRY
*pEntries
)
2776 STUB(D3D_OK
); /* like wine */
2780 NineDevice9_GetPaletteEntries( struct NineDevice9
*This
,
2782 PALETTEENTRY
*pEntries
)
2784 STUB(D3DERR_INVALIDCALL
);
2788 NineDevice9_SetCurrentTexturePalette( struct NineDevice9
*This
,
2789 UINT PaletteNumber
)
2791 STUB(D3D_OK
); /* like wine */
2795 NineDevice9_GetCurrentTexturePalette( struct NineDevice9
*This
,
2796 UINT
*PaletteNumber
)
2798 STUB(D3DERR_INVALIDCALL
);
2802 NineDevice9_SetScissorRect( struct NineDevice9
*This
,
2805 struct nine_state
*state
= This
->update
;
2807 DBG("x=(%u..%u) y=(%u..%u)\n",
2808 pRect
->left
, pRect
->top
, pRect
->right
, pRect
->bottom
);
2810 state
->scissor
.minx
= pRect
->left
;
2811 state
->scissor
.miny
= pRect
->top
;
2812 state
->scissor
.maxx
= pRect
->right
;
2813 state
->scissor
.maxy
= pRect
->bottom
;
2815 state
->changed
.group
|= NINE_STATE_SCISSOR
;
2821 NineDevice9_GetScissorRect( struct NineDevice9
*This
,
2824 pRect
->left
= This
->state
.scissor
.minx
;
2825 pRect
->top
= This
->state
.scissor
.miny
;
2826 pRect
->right
= This
->state
.scissor
.maxx
;
2827 pRect
->bottom
= This
->state
.scissor
.maxy
;
2833 NineDevice9_SetSoftwareVertexProcessing( struct NineDevice9
*This
,
2836 STUB(D3DERR_INVALIDCALL
);
2840 NineDevice9_GetSoftwareVertexProcessing( struct NineDevice9
*This
)
2842 return !!(This
->params
.BehaviorFlags
& D3DCREATE_SOFTWARE_VERTEXPROCESSING
);
2846 NineDevice9_SetNPatchMode( struct NineDevice9
*This
,
2849 STUB(D3DERR_INVALIDCALL
);
2853 NineDevice9_GetNPatchMode( struct NineDevice9
*This
)
2859 init_draw_info(struct pipe_draw_info
*info
,
2860 struct NineDevice9
*dev
, D3DPRIMITIVETYPE type
, UINT count
)
2862 info
->mode
= d3dprimitivetype_to_pipe_prim(type
);
2863 info
->count
= prim_count_to_vertex_count(type
, count
);
2864 info
->start_instance
= 0;
2865 info
->instance_count
= 1;
2866 if (dev
->state
.stream_instancedata_mask
& dev
->state
.stream_usage_mask
)
2867 info
->instance_count
= MAX2(dev
->state
.stream_freq
[0] & 0x7FFFFF, 1);
2868 info
->primitive_restart
= FALSE
;
2869 info
->restart_index
= 0;
2870 info
->count_from_stream_output
= NULL
;
2871 info
->indirect
= NULL
;
2875 NineDevice9_DrawPrimitive( struct NineDevice9
*This
,
2876 D3DPRIMITIVETYPE PrimitiveType
,
2878 UINT PrimitiveCount
)
2880 struct pipe_draw_info info
;
2882 DBG("iface %p, PrimitiveType %u, StartVertex %u, PrimitiveCount %u\n",
2883 This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2885 nine_update_state(This
);
2887 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2888 info
.indexed
= FALSE
;
2889 info
.start
= StartVertex
;
2890 info
.index_bias
= 0;
2891 info
.min_index
= info
.start
;
2892 info
.max_index
= info
.count
- 1;
2894 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2900 NineDevice9_DrawIndexedPrimitive( struct NineDevice9
*This
,
2901 D3DPRIMITIVETYPE PrimitiveType
,
2902 INT BaseVertexIndex
,
2903 UINT MinVertexIndex
,
2906 UINT PrimitiveCount
)
2908 struct pipe_draw_info info
;
2910 DBG("iface %p, PrimitiveType %u, BaseVertexIndex %u, MinVertexIndex %u "
2911 "NumVertices %u, StartIndex %u, PrimitiveCount %u\n",
2912 This
, PrimitiveType
, BaseVertexIndex
, MinVertexIndex
, NumVertices
,
2913 StartIndex
, PrimitiveCount
);
2915 user_assert(This
->state
.idxbuf
, D3DERR_INVALIDCALL
);
2916 user_assert(This
->state
.vdecl
, D3DERR_INVALIDCALL
);
2918 nine_update_state(This
);
2920 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2921 info
.indexed
= TRUE
;
2922 info
.start
= StartIndex
;
2923 info
.index_bias
= BaseVertexIndex
;
2924 /* These don't include index bias: */
2925 info
.min_index
= MinVertexIndex
;
2926 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
2928 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2934 NineDevice9_DrawPrimitiveUP( struct NineDevice9
*This
,
2935 D3DPRIMITIVETYPE PrimitiveType
,
2936 UINT PrimitiveCount
,
2937 const void *pVertexStreamZeroData
,
2938 UINT VertexStreamZeroStride
)
2940 struct pipe_vertex_buffer vtxbuf
;
2941 struct pipe_draw_info info
;
2943 DBG("iface %p, PrimitiveType %u, PrimitiveCount %u, data %p, stride %u\n",
2944 This
, PrimitiveType
, PrimitiveCount
,
2945 pVertexStreamZeroData
, VertexStreamZeroStride
);
2947 user_assert(pVertexStreamZeroData
&& VertexStreamZeroStride
,
2948 D3DERR_INVALIDCALL
);
2950 nine_update_state(This
);
2952 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2953 info
.indexed
= FALSE
;
2955 info
.index_bias
= 0;
2957 info
.max_index
= info
.count
- 1;
2959 vtxbuf
.stride
= VertexStreamZeroStride
;
2960 vtxbuf
.buffer_offset
= 0;
2961 vtxbuf
.buffer
= NULL
;
2962 vtxbuf
.user_buffer
= pVertexStreamZeroData
;
2964 if (!This
->driver_caps
.user_vbufs
)
2965 u_upload_data(This
->upload
,
2967 (info
.max_index
+ 1) * VertexStreamZeroStride
, /* XXX */
2969 &vtxbuf
.buffer_offset
,
2972 This
->pipe
->set_vertex_buffers(This
->pipe
, 0, 1, &vtxbuf
);
2974 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2976 NineDevice9_PauseRecording(This
);
2977 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
2978 NineDevice9_ResumeRecording(This
);
2980 pipe_resource_reference(&vtxbuf
.buffer
, NULL
);
2986 NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9
*This
,
2987 D3DPRIMITIVETYPE PrimitiveType
,
2988 UINT MinVertexIndex
,
2990 UINT PrimitiveCount
,
2991 const void *pIndexData
,
2992 D3DFORMAT IndexDataFormat
,
2993 const void *pVertexStreamZeroData
,
2994 UINT VertexStreamZeroStride
)
2996 struct pipe_draw_info info
;
2997 struct pipe_vertex_buffer vbuf
;
2998 struct pipe_index_buffer ibuf
;
3000 DBG("iface %p, PrimitiveType %u, MinVertexIndex %u, NumVertices %u "
3001 "PrimitiveCount %u, pIndexData %p, IndexDataFormat %u "
3002 "pVertexStreamZeroData %p, VertexStreamZeroStride %u\n",
3003 This
, PrimitiveType
, MinVertexIndex
, NumVertices
, PrimitiveCount
,
3004 pIndexData
, IndexDataFormat
,
3005 pVertexStreamZeroData
, VertexStreamZeroStride
);
3007 user_assert(pIndexData
&& pVertexStreamZeroData
, D3DERR_INVALIDCALL
);
3008 user_assert(VertexStreamZeroStride
, D3DERR_INVALIDCALL
);
3009 user_assert(IndexDataFormat
== D3DFMT_INDEX16
||
3010 IndexDataFormat
== D3DFMT_INDEX32
, D3DERR_INVALIDCALL
);
3012 nine_update_state(This
);
3014 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
3015 info
.indexed
= TRUE
;
3017 info
.index_bias
= 0;
3018 info
.min_index
= MinVertexIndex
;
3019 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
3021 vbuf
.stride
= VertexStreamZeroStride
;
3022 vbuf
.buffer_offset
= 0;
3024 vbuf
.user_buffer
= pVertexStreamZeroData
;
3026 ibuf
.index_size
= (IndexDataFormat
== D3DFMT_INDEX16
) ? 2 : 4;
3029 ibuf
.user_buffer
= pIndexData
;
3031 if (!This
->driver_caps
.user_vbufs
) {
3032 const unsigned base
= info
.min_index
* VertexStreamZeroStride
;
3033 u_upload_data(This
->upload
,
3036 info
.min_index
+ 1) * VertexStreamZeroStride
, /* XXX */
3037 (const uint8_t *)vbuf
.user_buffer
+ base
,
3038 &vbuf
.buffer_offset
,
3040 /* Won't be used: */
3041 vbuf
.buffer_offset
-= base
;
3043 if (!This
->driver_caps
.user_ibufs
)
3044 u_upload_data(This
->upload
,
3046 info
.count
* ibuf
.index_size
,
3051 This
->pipe
->set_vertex_buffers(This
->pipe
, 0, 1, &vbuf
);
3052 This
->pipe
->set_index_buffer(This
->pipe
, &ibuf
);
3054 This
->pipe
->draw_vbo(This
->pipe
, &info
);
3056 pipe_resource_reference(&vbuf
.buffer
, NULL
);
3057 pipe_resource_reference(&ibuf
.buffer
, NULL
);
3059 NineDevice9_PauseRecording(This
);
3060 NineDevice9_SetIndices(This
, NULL
);
3061 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
3062 NineDevice9_ResumeRecording(This
);
3067 /* TODO: Write to pDestBuffer directly if vertex declaration contains
3071 NineDevice9_ProcessVertices( struct NineDevice9
*This
,
3075 IDirect3DVertexBuffer9
*pDestBuffer
,
3076 IDirect3DVertexDeclaration9
*pVertexDecl
,
3079 struct pipe_screen
*screen
= This
->screen
;
3080 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pVertexDecl
);
3081 struct NineVertexShader9
*vs
;
3082 struct pipe_resource
*resource
;
3083 struct pipe_stream_output_target
*target
;
3084 struct pipe_draw_info draw
;
3086 unsigned buffer_offset
, buffer_size
;
3088 DBG("This=%p SrcStartIndex=%u DestIndex=%u VertexCount=%u "
3089 "pDestBuffer=%p pVertexDecl=%p Flags=%d\n",
3090 This
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
,
3091 pVertexDecl
, Flags
);
3093 if (!screen
->get_param(screen
, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
))
3094 STUB(D3DERR_INVALIDCALL
);
3096 nine_update_state(This
);
3098 /* TODO: Create shader with stream output. */
3099 STUB(D3DERR_INVALIDCALL
);
3100 struct NineVertexBuffer9
*dst
= NineVertexBuffer9(pDestBuffer
);
3102 vs
= This
->state
.vs
? This
->state
.vs
: This
->ff
.vs
;
3104 buffer_size
= VertexCount
* vs
->so
->stride
[0];
3106 struct pipe_resource templ
;
3108 templ
.target
= PIPE_BUFFER
;
3109 templ
.format
= PIPE_FORMAT_R8_UNORM
;
3110 templ
.width0
= buffer_size
;
3112 templ
.bind
= PIPE_BIND_STREAM_OUTPUT
;
3113 templ
.usage
= PIPE_USAGE_STREAM
;
3114 templ
.height0
= templ
.depth0
= templ
.array_size
= 1;
3115 templ
.last_level
= templ
.nr_samples
= 0;
3117 resource
= This
->screen
->resource_create(This
->screen
, &templ
);
3119 return E_OUTOFMEMORY
;
3122 /* SO matches vertex declaration */
3123 resource
= dst
->base
.resource
;
3124 buffer_offset
= DestIndex
* vs
->so
->stride
[0];
3126 target
= This
->pipe
->create_stream_output_target(This
->pipe
, resource
,
3130 pipe_resource_reference(&resource
, NULL
);
3131 return D3DERR_DRIVERINTERNALERROR
;
3135 hr
= NineVertexDeclaration9_new_from_fvf(This
, dst
->desc
.FVF
, &vdecl
);
3140 init_draw_info(&draw
, This
, D3DPT_POINTLIST
, VertexCount
);
3141 draw
.instance_count
= 1;
3142 draw
.indexed
= FALSE
;
3143 draw
.start
= SrcStartIndex
;
3144 draw
.index_bias
= 0;
3145 draw
.min_index
= SrcStartIndex
;
3146 draw
.max_index
= SrcStartIndex
+ VertexCount
- 1;
3148 This
->pipe
->set_stream_output_targets(This
->pipe
, 1, &target
, 0);
3149 This
->pipe
->draw_vbo(This
->pipe
, &draw
);
3150 This
->pipe
->set_stream_output_targets(This
->pipe
, 0, NULL
, 0);
3151 This
->pipe
->stream_output_target_destroy(This
->pipe
, target
);
3153 hr
= NineVertexDeclaration9_ConvertStreamOutput(vdecl
,
3154 dst
, DestIndex
, VertexCount
,
3157 pipe_resource_reference(&resource
, NULL
);
3159 NineUnknown_Release(NineUnknown(vdecl
));
3164 NineDevice9_CreateVertexDeclaration( struct NineDevice9
*This
,
3165 const D3DVERTEXELEMENT9
*pVertexElements
,
3166 IDirect3DVertexDeclaration9
**ppDecl
)
3168 struct NineVertexDeclaration9
*vdecl
;
3170 DBG("This=%p pVertexElements=%p ppDecl=%p\n",
3171 This
, pVertexElements
, ppDecl
);
3173 HRESULT hr
= NineVertexDeclaration9_new(This
, pVertexElements
, &vdecl
);
3175 *ppDecl
= (IDirect3DVertexDeclaration9
*)vdecl
;
3181 NineDevice9_SetVertexDeclaration( struct NineDevice9
*This
,
3182 IDirect3DVertexDeclaration9
*pDecl
)
3184 struct nine_state
*state
= This
->update
;
3186 DBG("This=%p pDecl=%p\n", This
, pDecl
);
3188 if (likely(!This
->is_recording
) && state
->vdecl
== NineVertexDeclaration9(pDecl
))
3190 nine_bind(&state
->vdecl
, pDecl
);
3192 state
->changed
.group
|= NINE_STATE_VDECL
;
3198 NineDevice9_GetVertexDeclaration( struct NineDevice9
*This
,
3199 IDirect3DVertexDeclaration9
**ppDecl
)
3201 user_assert(ppDecl
, D3DERR_INVALIDCALL
);
3203 *ppDecl
= (IDirect3DVertexDeclaration9
*)This
->state
.vdecl
;
3205 NineUnknown_AddRef(NineUnknown(*ppDecl
));
3210 NineDevice9_SetFVF( struct NineDevice9
*This
,
3213 struct NineVertexDeclaration9
*vdecl
;
3216 DBG("FVF = %08x\n", FVF
);
3218 return D3D_OK
; /* like wine */
3220 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
3222 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
3226 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
3227 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
3229 return NineDevice9_SetVertexDeclaration(
3230 This
, (IDirect3DVertexDeclaration9
*)vdecl
);
3234 NineDevice9_GetFVF( struct NineDevice9
*This
,
3237 *pFVF
= This
->state
.vdecl
? This
->state
.vdecl
->fvf
: 0;
3242 NineDevice9_CreateVertexShader( struct NineDevice9
*This
,
3243 const DWORD
*pFunction
,
3244 IDirect3DVertexShader9
**ppShader
)
3246 struct NineVertexShader9
*vs
;
3249 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3251 hr
= NineVertexShader9_new(This
, &vs
, pFunction
, NULL
);
3254 *ppShader
= (IDirect3DVertexShader9
*)vs
;
3259 NineDevice9_SetVertexShader( struct NineDevice9
*This
,
3260 IDirect3DVertexShader9
*pShader
)
3262 struct nine_state
*state
= This
->update
;
3264 DBG("This=%p pShader=%p\n", This
, pShader
);
3266 nine_bind(&state
->vs
, pShader
);
3268 state
->changed
.group
|= NINE_STATE_VS
;
3274 NineDevice9_GetVertexShader( struct NineDevice9
*This
,
3275 IDirect3DVertexShader9
**ppShader
)
3277 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3278 nine_reference_set(ppShader
, This
->state
.vs
);
3283 NineDevice9_SetVertexShaderConstantF( struct NineDevice9
*This
,
3285 const float *pConstantData
,
3286 UINT Vector4fCount
)
3288 struct nine_state
*state
= This
->update
;
3290 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3291 This
, StartRegister
, pConstantData
, Vector4fCount
);
3293 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3294 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3298 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3300 memcpy(&state
->vs_const_f
[StartRegister
* 4],
3302 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3304 nine_ranges_insert(&state
->changed
.vs_const_f
,
3305 StartRegister
, StartRegister
+ Vector4fCount
,
3308 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3314 NineDevice9_GetVertexShaderConstantF( struct NineDevice9
*This
,
3316 float *pConstantData
,
3317 UINT Vector4fCount
)
3319 const struct nine_state
*state
= &This
->state
;
3321 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3322 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3323 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3325 memcpy(pConstantData
,
3326 &state
->vs_const_f
[StartRegister
* 4],
3327 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3333 NineDevice9_SetVertexShaderConstantI( struct NineDevice9
*This
,
3335 const int *pConstantData
,
3336 UINT Vector4iCount
)
3338 struct nine_state
*state
= This
->update
;
3341 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3342 This
, StartRegister
, pConstantData
, Vector4iCount
);
3344 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3345 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3346 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3348 if (This
->driver_caps
.vs_integer
) {
3349 memcpy(&state
->vs_const_i
[StartRegister
][0],
3351 Vector4iCount
* sizeof(state
->vs_const_i
[0]));
3353 for (i
= 0; i
< Vector4iCount
; i
++) {
3354 state
->vs_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3355 state
->vs_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3356 state
->vs_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3357 state
->vs_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3361 state
->changed
.vs_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3362 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3368 NineDevice9_GetVertexShaderConstantI( struct NineDevice9
*This
,
3371 UINT Vector4iCount
)
3373 const struct nine_state
*state
= &This
->state
;
3376 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3377 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3378 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3380 if (This
->driver_caps
.vs_integer
) {
3381 memcpy(pConstantData
,
3382 &state
->vs_const_i
[StartRegister
][0],
3383 Vector4iCount
* sizeof(state
->vs_const_i
[0]));
3385 for (i
= 0; i
< Vector4iCount
; i
++) {
3386 pConstantData
[4*i
] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][0]);
3387 pConstantData
[4*i
+1] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][1]);
3388 pConstantData
[4*i
+2] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][2]);
3389 pConstantData
[4*i
+3] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][3]);
3397 NineDevice9_SetVertexShaderConstantB( struct NineDevice9
*This
,
3399 const BOOL
*pConstantData
,
3402 struct nine_state
*state
= This
->update
;
3404 uint32_t bool_true
= This
->driver_caps
.vs_integer
? 0xFFFFFFFF : fui(1.0f
);
3406 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3407 This
, StartRegister
, pConstantData
, BoolCount
);
3409 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3410 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3411 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3413 for (i
= 0; i
< BoolCount
; i
++)
3414 state
->vs_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3416 state
->changed
.vs_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3417 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3423 NineDevice9_GetVertexShaderConstantB( struct NineDevice9
*This
,
3425 BOOL
*pConstantData
,
3428 const struct nine_state
*state
= &This
->state
;
3431 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3432 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3433 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3435 for (i
= 0; i
< BoolCount
; i
++)
3436 pConstantData
[i
] = state
->vs_const_b
[StartRegister
+ i
] != 0 ? TRUE
: FALSE
;
3442 NineDevice9_SetStreamSource( struct NineDevice9
*This
,
3444 IDirect3DVertexBuffer9
*pStreamData
,
3448 struct nine_state
*state
= This
->update
;
3449 struct NineVertexBuffer9
*pVBuf9
= NineVertexBuffer9(pStreamData
);
3450 const unsigned i
= StreamNumber
;
3452 DBG("This=%p StreamNumber=%u pStreamData=%p OffsetInBytes=%u Stride=%u\n",
3453 This
, StreamNumber
, pStreamData
, OffsetInBytes
, Stride
);
3455 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3456 user_assert(Stride
<= This
->caps
.MaxStreamStride
, D3DERR_INVALIDCALL
);
3458 if (likely(!This
->is_recording
)) {
3459 if (state
->stream
[i
] == NineVertexBuffer9(pStreamData
) &&
3460 state
->vtxbuf
[i
].stride
== Stride
&&
3461 state
->vtxbuf
[i
].buffer_offset
== OffsetInBytes
)
3464 nine_bind(&state
->stream
[i
], pStreamData
);
3466 state
->changed
.vtxbuf
|= 1 << StreamNumber
;
3469 state
->vtxbuf
[i
].stride
= Stride
;
3470 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3472 state
->vtxbuf
[i
].buffer
= pStreamData
? pVBuf9
->base
.resource
: NULL
;
3478 NineDevice9_GetStreamSource( struct NineDevice9
*This
,
3480 IDirect3DVertexBuffer9
**ppStreamData
,
3481 UINT
*pOffsetInBytes
,
3484 const struct nine_state
*state
= &This
->state
;
3485 const unsigned i
= StreamNumber
;
3487 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3488 user_assert(ppStreamData
, D3DERR_INVALIDCALL
);
3490 nine_reference_set(ppStreamData
, state
->stream
[i
]);
3491 *pStride
= state
->vtxbuf
[i
].stride
;
3492 *pOffsetInBytes
= state
->vtxbuf
[i
].buffer_offset
;
3498 NineDevice9_SetStreamSourceFreq( struct NineDevice9
*This
,
3502 struct nine_state
*state
= This
->update
;
3503 /* const UINT freq = Setting & 0x7FFFFF; */
3505 DBG("This=%p StreamNumber=%u FrequencyParameter=0x%x\n", This
,
3506 StreamNumber
, Setting
);
3508 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3509 user_assert(StreamNumber
!= 0 || !(Setting
& D3DSTREAMSOURCE_INSTANCEDATA
),
3510 D3DERR_INVALIDCALL
);
3511 user_assert(!((Setting
& D3DSTREAMSOURCE_INSTANCEDATA
) &&
3512 (Setting
& D3DSTREAMSOURCE_INDEXEDDATA
)), D3DERR_INVALIDCALL
);
3513 user_assert(Setting
, D3DERR_INVALIDCALL
);
3515 state
->stream_freq
[StreamNumber
] = Setting
;
3517 if (Setting
& D3DSTREAMSOURCE_INSTANCEDATA
)
3518 state
->stream_instancedata_mask
|= 1 << StreamNumber
;
3520 state
->stream_instancedata_mask
&= ~(1 << StreamNumber
);
3522 state
->changed
.stream_freq
|= 1 << StreamNumber
;
3527 NineDevice9_GetStreamSourceFreq( struct NineDevice9
*This
,
3531 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3532 *pSetting
= This
->state
.stream_freq
[StreamNumber
];
3537 NineDevice9_SetIndices( struct NineDevice9
*This
,
3538 IDirect3DIndexBuffer9
*pIndexData
)
3540 struct nine_state
*state
= This
->update
;
3542 DBG("This=%p pIndexData=%p\n", This
, pIndexData
);
3544 if (likely(!This
->is_recording
))
3545 if (state
->idxbuf
== NineIndexBuffer9(pIndexData
))
3547 nine_bind(&state
->idxbuf
, pIndexData
);
3549 state
->changed
.group
|= NINE_STATE_IDXBUF
;
3554 /* XXX: wine/d3d9 doesn't have pBaseVertexIndex, and it doesn't make sense
3555 * here because it's an argument passed to the Draw calls.
3558 NineDevice9_GetIndices( struct NineDevice9
*This
,
3559 IDirect3DIndexBuffer9
**ppIndexData
/*,
3560 UINT *pBaseVertexIndex */ )
3562 user_assert(ppIndexData
, D3DERR_INVALIDCALL
);
3563 nine_reference_set(ppIndexData
, This
->state
.idxbuf
);
3568 NineDevice9_CreatePixelShader( struct NineDevice9
*This
,
3569 const DWORD
*pFunction
,
3570 IDirect3DPixelShader9
**ppShader
)
3572 struct NinePixelShader9
*ps
;
3575 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3577 hr
= NinePixelShader9_new(This
, &ps
, pFunction
, NULL
);
3580 *ppShader
= (IDirect3DPixelShader9
*)ps
;
3585 NineDevice9_SetPixelShader( struct NineDevice9
*This
,
3586 IDirect3DPixelShader9
*pShader
)
3588 struct nine_state
*state
= This
->update
;
3589 unsigned old_mask
= state
->ps
? state
->ps
->rt_mask
: 1;
3592 DBG("This=%p pShader=%p\n", This
, pShader
);
3594 nine_bind(&state
->ps
, pShader
);
3596 state
->changed
.group
|= NINE_STATE_PS
;
3598 mask
= state
->ps
? state
->ps
->rt_mask
: 1;
3599 /* We need to update cbufs if the pixel shader would
3600 * write to different render targets */
3601 if (mask
!= old_mask
)
3602 state
->changed
.group
|= NINE_STATE_FB
;
3608 NineDevice9_GetPixelShader( struct NineDevice9
*This
,
3609 IDirect3DPixelShader9
**ppShader
)
3611 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3612 nine_reference_set(ppShader
, This
->state
.ps
);
3617 NineDevice9_SetPixelShaderConstantF( struct NineDevice9
*This
,
3619 const float *pConstantData
,
3620 UINT Vector4fCount
)
3622 struct nine_state
*state
= This
->update
;
3624 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3625 This
, StartRegister
, pConstantData
, Vector4fCount
);
3627 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3628 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3632 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3634 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3636 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3638 nine_ranges_insert(&state
->changed
.ps_const_f
,
3639 StartRegister
, StartRegister
+ Vector4fCount
,
3642 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3648 NineDevice9_GetPixelShaderConstantF( struct NineDevice9
*This
,
3650 float *pConstantData
,
3651 UINT Vector4fCount
)
3653 const struct nine_state
*state
= &This
->state
;
3655 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3656 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3657 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3659 memcpy(pConstantData
,
3660 &state
->ps_const_f
[StartRegister
* 4],
3661 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3667 NineDevice9_SetPixelShaderConstantI( struct NineDevice9
*This
,
3669 const int *pConstantData
,
3670 UINT Vector4iCount
)
3672 struct nine_state
*state
= This
->update
;
3675 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3676 This
, StartRegister
, pConstantData
, Vector4iCount
);
3678 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3679 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3680 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3682 if (This
->driver_caps
.ps_integer
) {
3683 memcpy(&state
->ps_const_i
[StartRegister
][0],
3685 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3687 for (i
= 0; i
< Vector4iCount
; i
++) {
3688 state
->ps_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3689 state
->ps_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3690 state
->ps_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3691 state
->ps_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3694 state
->changed
.ps_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3695 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3701 NineDevice9_GetPixelShaderConstantI( struct NineDevice9
*This
,
3704 UINT Vector4iCount
)
3706 const struct nine_state
*state
= &This
->state
;
3709 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3710 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3711 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3713 if (This
->driver_caps
.ps_integer
) {
3714 memcpy(pConstantData
,
3715 &state
->ps_const_i
[StartRegister
][0],
3716 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3718 for (i
= 0; i
< Vector4iCount
; i
++) {
3719 pConstantData
[4*i
] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][0]);
3720 pConstantData
[4*i
+1] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][1]);
3721 pConstantData
[4*i
+2] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][2]);
3722 pConstantData
[4*i
+3] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][3]);
3730 NineDevice9_SetPixelShaderConstantB( struct NineDevice9
*This
,
3732 const BOOL
*pConstantData
,
3735 struct nine_state
*state
= This
->update
;
3737 uint32_t bool_true
= This
->driver_caps
.ps_integer
? 0xFFFFFFFF : fui(1.0f
);
3739 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3740 This
, StartRegister
, pConstantData
, BoolCount
);
3742 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3743 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3744 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3746 for (i
= 0; i
< BoolCount
; i
++)
3747 state
->ps_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3749 state
->changed
.ps_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3750 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3756 NineDevice9_GetPixelShaderConstantB( struct NineDevice9
*This
,
3758 BOOL
*pConstantData
,
3761 const struct nine_state
*state
= &This
->state
;
3764 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3765 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3766 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3768 for (i
= 0; i
< BoolCount
; i
++)
3769 pConstantData
[i
] = state
->ps_const_b
[StartRegister
+ i
] ? TRUE
: FALSE
;
3775 NineDevice9_DrawRectPatch( struct NineDevice9
*This
,
3777 const float *pNumSegs
,
3778 const D3DRECTPATCH_INFO
*pRectPatchInfo
)
3780 STUB(D3DERR_INVALIDCALL
);
3784 NineDevice9_DrawTriPatch( struct NineDevice9
*This
,
3786 const float *pNumSegs
,
3787 const D3DTRIPATCH_INFO
*pTriPatchInfo
)
3789 STUB(D3DERR_INVALIDCALL
);
3793 NineDevice9_DeletePatch( struct NineDevice9
*This
,
3796 STUB(D3DERR_INVALIDCALL
);
3800 NineDevice9_CreateQuery( struct NineDevice9
*This
,
3802 IDirect3DQuery9
**ppQuery
)
3804 struct NineQuery9
*query
;
3807 DBG("This=%p Type=%d ppQuery=%p\n", This
, Type
, ppQuery
);
3809 hr
= nine_is_query_supported(This
->screen
, Type
);
3810 if (!ppQuery
|| hr
!= D3D_OK
)
3813 hr
= NineQuery9_new(This
, &query
, Type
);
3816 *ppQuery
= (IDirect3DQuery9
*)query
;
3820 IDirect3DDevice9Vtbl NineDevice9_vtable
= {
3821 (void *)NineUnknown_QueryInterface
,
3822 (void *)NineUnknown_AddRef
,
3823 (void *)NineUnknown_Release
,
3824 (void *)NineDevice9_TestCooperativeLevel
,
3825 (void *)NineDevice9_GetAvailableTextureMem
,
3826 (void *)NineDevice9_EvictManagedResources
,
3827 (void *)NineDevice9_GetDirect3D
,
3828 (void *)NineDevice9_GetDeviceCaps
,
3829 (void *)NineDevice9_GetDisplayMode
,
3830 (void *)NineDevice9_GetCreationParameters
,
3831 (void *)NineDevice9_SetCursorProperties
,
3832 (void *)NineDevice9_SetCursorPosition
,
3833 (void *)NineDevice9_ShowCursor
,
3834 (void *)NineDevice9_CreateAdditionalSwapChain
,
3835 (void *)NineDevice9_GetSwapChain
,
3836 (void *)NineDevice9_GetNumberOfSwapChains
,
3837 (void *)NineDevice9_Reset
,
3838 (void *)NineDevice9_Present
,
3839 (void *)NineDevice9_GetBackBuffer
,
3840 (void *)NineDevice9_GetRasterStatus
,
3841 (void *)NineDevice9_SetDialogBoxMode
,
3842 (void *)NineDevice9_SetGammaRamp
,
3843 (void *)NineDevice9_GetGammaRamp
,
3844 (void *)NineDevice9_CreateTexture
,
3845 (void *)NineDevice9_CreateVolumeTexture
,
3846 (void *)NineDevice9_CreateCubeTexture
,
3847 (void *)NineDevice9_CreateVertexBuffer
,
3848 (void *)NineDevice9_CreateIndexBuffer
,
3849 (void *)NineDevice9_CreateRenderTarget
,
3850 (void *)NineDevice9_CreateDepthStencilSurface
,
3851 (void *)NineDevice9_UpdateSurface
,
3852 (void *)NineDevice9_UpdateTexture
,
3853 (void *)NineDevice9_GetRenderTargetData
,
3854 (void *)NineDevice9_GetFrontBufferData
,
3855 (void *)NineDevice9_StretchRect
,
3856 (void *)NineDevice9_ColorFill
,
3857 (void *)NineDevice9_CreateOffscreenPlainSurface
,
3858 (void *)NineDevice9_SetRenderTarget
,
3859 (void *)NineDevice9_GetRenderTarget
,
3860 (void *)NineDevice9_SetDepthStencilSurface
,
3861 (void *)NineDevice9_GetDepthStencilSurface
,
3862 (void *)NineDevice9_BeginScene
,
3863 (void *)NineDevice9_EndScene
,
3864 (void *)NineDevice9_Clear
,
3865 (void *)NineDevice9_SetTransform
,
3866 (void *)NineDevice9_GetTransform
,
3867 (void *)NineDevice9_MultiplyTransform
,
3868 (void *)NineDevice9_SetViewport
,
3869 (void *)NineDevice9_GetViewport
,
3870 (void *)NineDevice9_SetMaterial
,
3871 (void *)NineDevice9_GetMaterial
,
3872 (void *)NineDevice9_SetLight
,
3873 (void *)NineDevice9_GetLight
,
3874 (void *)NineDevice9_LightEnable
,
3875 (void *)NineDevice9_GetLightEnable
,
3876 (void *)NineDevice9_SetClipPlane
,
3877 (void *)NineDevice9_GetClipPlane
,
3878 (void *)NineDevice9_SetRenderState
,
3879 (void *)NineDevice9_GetRenderState
,
3880 (void *)NineDevice9_CreateStateBlock
,
3881 (void *)NineDevice9_BeginStateBlock
,
3882 (void *)NineDevice9_EndStateBlock
,
3883 (void *)NineDevice9_SetClipStatus
,
3884 (void *)NineDevice9_GetClipStatus
,
3885 (void *)NineDevice9_GetTexture
,
3886 (void *)NineDevice9_SetTexture
,
3887 (void *)NineDevice9_GetTextureStageState
,
3888 (void *)NineDevice9_SetTextureStageState
,
3889 (void *)NineDevice9_GetSamplerState
,
3890 (void *)NineDevice9_SetSamplerState
,
3891 (void *)NineDevice9_ValidateDevice
,
3892 (void *)NineDevice9_SetPaletteEntries
,
3893 (void *)NineDevice9_GetPaletteEntries
,
3894 (void *)NineDevice9_SetCurrentTexturePalette
,
3895 (void *)NineDevice9_GetCurrentTexturePalette
,
3896 (void *)NineDevice9_SetScissorRect
,
3897 (void *)NineDevice9_GetScissorRect
,
3898 (void *)NineDevice9_SetSoftwareVertexProcessing
,
3899 (void *)NineDevice9_GetSoftwareVertexProcessing
,
3900 (void *)NineDevice9_SetNPatchMode
,
3901 (void *)NineDevice9_GetNPatchMode
,
3902 (void *)NineDevice9_DrawPrimitive
,
3903 (void *)NineDevice9_DrawIndexedPrimitive
,
3904 (void *)NineDevice9_DrawPrimitiveUP
,
3905 (void *)NineDevice9_DrawIndexedPrimitiveUP
,
3906 (void *)NineDevice9_ProcessVertices
,
3907 (void *)NineDevice9_CreateVertexDeclaration
,
3908 (void *)NineDevice9_SetVertexDeclaration
,
3909 (void *)NineDevice9_GetVertexDeclaration
,
3910 (void *)NineDevice9_SetFVF
,
3911 (void *)NineDevice9_GetFVF
,
3912 (void *)NineDevice9_CreateVertexShader
,
3913 (void *)NineDevice9_SetVertexShader
,
3914 (void *)NineDevice9_GetVertexShader
,
3915 (void *)NineDevice9_SetVertexShaderConstantF
,
3916 (void *)NineDevice9_GetVertexShaderConstantF
,
3917 (void *)NineDevice9_SetVertexShaderConstantI
,
3918 (void *)NineDevice9_GetVertexShaderConstantI
,
3919 (void *)NineDevice9_SetVertexShaderConstantB
,
3920 (void *)NineDevice9_GetVertexShaderConstantB
,
3921 (void *)NineDevice9_SetStreamSource
,
3922 (void *)NineDevice9_GetStreamSource
,
3923 (void *)NineDevice9_SetStreamSourceFreq
,
3924 (void *)NineDevice9_GetStreamSourceFreq
,
3925 (void *)NineDevice9_SetIndices
,
3926 (void *)NineDevice9_GetIndices
,
3927 (void *)NineDevice9_CreatePixelShader
,
3928 (void *)NineDevice9_SetPixelShader
,
3929 (void *)NineDevice9_GetPixelShader
,
3930 (void *)NineDevice9_SetPixelShaderConstantF
,
3931 (void *)NineDevice9_GetPixelShaderConstantF
,
3932 (void *)NineDevice9_SetPixelShaderConstantI
,
3933 (void *)NineDevice9_GetPixelShaderConstantI
,
3934 (void *)NineDevice9_SetPixelShaderConstantB
,
3935 (void *)NineDevice9_GetPixelShaderConstantB
,
3936 (void *)NineDevice9_DrawRectPatch
,
3937 (void *)NineDevice9_DrawTriPatch
,
3938 (void *)NineDevice9_DeletePatch
,
3939 (void *)NineDevice9_CreateQuery
3942 static const GUID
*NineDevice9_IIDs
[] = {
3943 &IID_IDirect3DDevice9
,
3949 NineDevice9_new( struct pipe_screen
*pScreen
,
3950 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
3952 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
3954 ID3DPresentGroup
*pPresentationGroup
,
3955 struct d3dadapter9_context
*pCTX
,
3957 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
3958 struct NineDevice9
**ppOut
)
3961 lock
= !!(pCreationParameters
->BehaviorFlags
& D3DCREATE_MULTITHREADED
);
3963 NINE_NEW(Device9
, ppOut
, lock
, /* args */
3964 pScreen
, pCreationParameters
, pCaps
,
3965 pPresentationParameters
, pD3D9
, pPresentationGroup
, pCTX
,
3966 ex
, pFullscreenDisplayMode
);