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"
41 #include "nine_limits.h"
43 #include "pipe/p_screen.h"
44 #include "pipe/p_context.h"
45 #include "pipe/p_config.h"
46 #include "util/u_math.h"
47 #include "util/u_inlines.h"
48 #include "util/u_hash_table.h"
49 #include "util/u_format.h"
50 #include "util/u_surface.h"
51 #include "util/u_upload_mgr.h"
52 #include "hud/hud_context.h"
54 #include "cso_cache/cso_context.h"
56 #define DBG_CHANNEL DBG_DEVICE
58 #if defined(PIPE_CC_GCC) && (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64))
60 static void nine_setup_fpu()
64 __asm__
__volatile__ ("fnstcw %0" : "=m" (*&c
));
66 /* clear the control word */
68 /* d3d9 doc/wine tests: mask all exceptions, use single-precision
69 * and round to nearest */
72 __asm__
__volatile__ ("fldcw %0" : : "m" (*&c
));
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 This
->state
.rs_advertised
[D3DRS_ZENABLE
] = TRUE
;
119 if (This
->state
.rs
[D3DRS_ZENABLE
])
120 NineDevice9_SetDepthStencilSurface(
121 This
, (IDirect3DSurface9
*)This
->swapchains
[0]->zsbuf
);
124 #define GET_PCAP(n) pScreen->get_param(pScreen, PIPE_CAP_##n)
126 NineDevice9_ctor( struct NineDevice9
*This
,
127 struct NineUnknownParams
*pParams
,
128 struct pipe_screen
*pScreen
,
129 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
131 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
133 ID3DPresentGroup
*pPresentationGroup
,
134 struct d3dadapter9_context
*pCTX
,
136 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
137 int minorVersionNum
)
140 HRESULT hr
= NineUnknown_ctor(&This
->base
, pParams
);
142 DBG("This=%p pParams=%p pScreen=%p pCreationParameters=%p pCaps=%p pPresentationParameters=%p "
143 "pD3D9=%p pPresentationGroup=%p pCTX=%p ex=%d pFullscreenDisplayMode=%p\n",
144 This
, pParams
, pScreen
, pCreationParameters
, pCaps
, pPresentationParameters
, pD3D9
,
145 pPresentationGroup
, pCTX
, (int) ex
, pFullscreenDisplayMode
);
147 if (FAILED(hr
)) { return hr
; }
149 list_inithead(&This
->update_buffers
);
150 list_inithead(&This
->update_textures
);
151 list_inithead(&This
->managed_buffers
);
152 list_inithead(&This
->managed_textures
);
154 This
->screen
= pScreen
;
157 This
->params
= *pCreationParameters
;
159 This
->present
= pPresentationGroup
;
160 This
->minor_version_num
= minorVersionNum
;
162 IDirect3D9_AddRef(This
->d3d9
);
163 ID3DPresentGroup_AddRef(This
->present
);
165 if (!(This
->params
.BehaviorFlags
& D3DCREATE_FPU_PRESERVE
))
168 if (This
->params
.BehaviorFlags
& D3DCREATE_SOFTWARE_VERTEXPROCESSING
)
169 DBG("Application asked full Software Vertex Processing. Ignoring.\n");
170 if (This
->params
.BehaviorFlags
& D3DCREATE_MIXED_VERTEXPROCESSING
)
171 DBG("Application asked mixed Software Vertex Processing. Ignoring.\n");
173 This
->pipe
= This
->screen
->context_create(This
->screen
, NULL
, 0);
174 if (!This
->pipe
) { return E_OUTOFMEMORY
; } /* guess */
176 This
->cso
= cso_create_context(This
->pipe
);
177 if (!This
->cso
) { return E_OUTOFMEMORY
; } /* also a guess */
179 /* Create first, it messes up our state. */
180 This
->hud
= hud_create(This
->pipe
, This
->cso
); /* NULL result is fine */
182 /* Available memory counter. Updated only for allocations with this device
183 * instance. This is the Win 7 behavior.
184 * Win XP shares this counter across multiple devices. */
185 This
->available_texture_mem
= This
->screen
->get_param(This
->screen
, PIPE_CAP_VIDEO_MEMORY
);
186 if (This
->available_texture_mem
< 4096)
187 This
->available_texture_mem
<<= 20;
189 This
->available_texture_mem
= UINT_MAX
;
190 /* We cap texture memory usage to 80% of what is reported free initially
191 * This helps get closer Win behaviour. For example VertexBuffer allocation
192 * still succeeds when texture allocation fails. */
193 This
->available_texture_limit
= This
->available_texture_mem
* 20LL / 100LL;
195 /* create implicit swapchains */
196 This
->nswapchains
= ID3DPresentGroup_GetMultiheadCount(This
->present
);
197 This
->swapchains
= CALLOC(This
->nswapchains
,
198 sizeof(struct NineSwapChain9
*));
199 if (!This
->swapchains
) { return E_OUTOFMEMORY
; }
201 for (i
= 0; i
< This
->nswapchains
; ++i
) {
202 ID3DPresent
*present
;
204 hr
= ID3DPresentGroup_GetPresent(This
->present
, i
, &present
);
209 D3DDISPLAYMODEEX
*mode
= NULL
;
210 struct NineSwapChain9Ex
**ret
=
211 (struct NineSwapChain9Ex
**)&This
->swapchains
[i
];
213 if (pFullscreenDisplayMode
) mode
= &(pFullscreenDisplayMode
[i
]);
214 /* when this is a Device9Ex, it should create SwapChain9Exs */
215 hr
= NineSwapChain9Ex_new(This
, TRUE
, present
,
216 &pPresentationParameters
[i
], pCTX
,
217 This
->params
.hFocusWindow
, mode
, ret
);
219 hr
= NineSwapChain9_new(This
, TRUE
, present
,
220 &pPresentationParameters
[i
], pCTX
,
221 This
->params
.hFocusWindow
,
222 &This
->swapchains
[i
]);
225 ID3DPresent_Release(present
);
228 NineUnknown_ConvertRefToBind(NineUnknown(This
->swapchains
[i
]));
230 hr
= NineSwapChain9_GetBackBuffer(This
->swapchains
[i
], 0,
231 D3DBACKBUFFER_TYPE_MONO
,
232 (IDirect3DSurface9
**)
236 NineUnknown_ConvertRefToBind(NineUnknown(This
->state
.rt
[i
]));
239 /* Initialize a dummy VBO to be used when a vertex declaration does not
240 * specify all the inputs needed by vertex shader, on win default behavior
241 * is to pass 0,0,0,0 to the shader */
243 struct pipe_transfer
*transfer
;
244 struct pipe_resource tmpl
;
248 tmpl
.target
= PIPE_BUFFER
;
249 tmpl
.format
= PIPE_FORMAT_R8_UNORM
;
250 tmpl
.width0
= 16; /* 4 floats */
256 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
257 tmpl
.bind
= PIPE_BIND_VERTEX_BUFFER
| PIPE_BIND_TRANSFER_WRITE
;
259 This
->dummy_vbo
= pScreen
->resource_create(pScreen
, &tmpl
);
261 if (!This
->dummy_vbo
)
262 return D3DERR_OUTOFVIDEOMEMORY
;
264 u_box_1d(0, 16, &box
);
265 data
= This
->pipe
->transfer_map(This
->pipe
, This
->dummy_vbo
, 0,
266 PIPE_TRANSFER_WRITE
|
267 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
272 This
->pipe
->transfer_unmap(This
->pipe
, transfer
);
275 This
->cursor
.software
= FALSE
;
276 This
->cursor
.hotspot
.x
= -1;
277 This
->cursor
.hotspot
.y
= -1;
279 struct pipe_resource tmpl
;
280 tmpl
.target
= PIPE_TEXTURE_2D
;
281 tmpl
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
288 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
289 tmpl
.bind
= PIPE_BIND_CURSOR
| PIPE_BIND_SAMPLER_VIEW
;
292 This
->cursor
.image
= pScreen
->resource_create(pScreen
, &tmpl
);
293 if (!This
->cursor
.image
)
294 return D3DERR_OUTOFVIDEOMEMORY
;
297 /* Create constant buffers. */
299 struct pipe_resource tmpl
;
300 unsigned max_const_vs
, max_const_ps
;
302 /* vs 3.0: >= 256 float constants, but for cards with exactly 256 slots,
303 * we have to take in some more slots for int and bool*/
304 max_const_vs
= _min(pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
,
305 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
) /
308 /* ps 3.0: 224 float constants. All cards supported support at least
309 * 256 constants for ps */
310 max_const_ps
= NINE_MAX_CONST_F_PS3
+ (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
312 This
->max_vs_const_f
= max_const_vs
-
313 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
314 This
->max_ps_const_f
= max_const_ps
-
315 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
317 This
->vs_const_size
= max_const_vs
* sizeof(float[4]);
318 This
->ps_const_size
= max_const_ps
* sizeof(float[4]);
319 /* Include space for I,B constants for user constbuf. */
320 This
->state
.vs_const_f
= CALLOC(This
->vs_const_size
, 1);
321 This
->state
.ps_const_f
= CALLOC(This
->ps_const_size
, 1);
322 This
->state
.vs_lconstf_temp
= CALLOC(This
->vs_const_size
,1);
323 This
->state
.ps_lconstf_temp
= CALLOC(This
->ps_const_size
,1);
324 if (!This
->state
.vs_const_f
|| !This
->state
.ps_const_f
||
325 !This
->state
.vs_lconstf_temp
|| !This
->state
.ps_lconstf_temp
)
326 return E_OUTOFMEMORY
;
328 if (strstr(pScreen
->get_name(pScreen
), "AMD") ||
329 strstr(pScreen
->get_name(pScreen
), "ATI")) {
330 This
->driver_bugs
.buggy_barycentrics
= TRUE
;
333 /* Disable NV path for now, needs some fixes */
334 This
->prefer_user_constbuf
= TRUE
;
336 tmpl
.target
= PIPE_BUFFER
;
337 tmpl
.format
= PIPE_FORMAT_R8_UNORM
;
343 tmpl
.usage
= PIPE_USAGE_DYNAMIC
;
344 tmpl
.bind
= PIPE_BIND_CONSTANT_BUFFER
;
347 tmpl
.width0
= This
->vs_const_size
;
348 This
->constbuf_vs
= pScreen
->resource_create(pScreen
, &tmpl
);
350 tmpl
.width0
= This
->ps_const_size
;
351 This
->constbuf_ps
= pScreen
->resource_create(pScreen
, &tmpl
);
353 if (!This
->constbuf_vs
|| !This
->constbuf_ps
)
354 return E_OUTOFMEMORY
;
357 /* allocate dummy texture/sampler for when there are missing ones bound */
359 struct pipe_resource tmplt
;
360 struct pipe_sampler_view templ
;
361 struct pipe_sampler_state samp
;
362 memset(&samp
, 0, sizeof(samp
));
364 tmplt
.target
= PIPE_TEXTURE_2D
;
368 tmplt
.last_level
= 0;
369 tmplt
.array_size
= 1;
370 tmplt
.usage
= PIPE_USAGE_DEFAULT
;
372 tmplt
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
373 tmplt
.bind
= PIPE_BIND_SAMPLER_VIEW
;
374 tmplt
.nr_samples
= 0;
376 This
->dummy_texture
= This
->screen
->resource_create(This
->screen
, &tmplt
);
377 if (!This
->dummy_texture
)
378 return D3DERR_DRIVERINTERNALERROR
;
380 templ
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
381 templ
.u
.tex
.first_layer
= 0;
382 templ
.u
.tex
.last_layer
= 0;
383 templ
.u
.tex
.first_level
= 0;
384 templ
.u
.tex
.last_level
= 0;
385 templ
.swizzle_r
= PIPE_SWIZZLE_0
;
386 templ
.swizzle_g
= PIPE_SWIZZLE_0
;
387 templ
.swizzle_b
= PIPE_SWIZZLE_0
;
388 templ
.swizzle_a
= PIPE_SWIZZLE_1
;
389 templ
.target
= This
->dummy_texture
->target
;
391 This
->dummy_sampler_view
= This
->pipe
->create_sampler_view(This
->pipe
, This
->dummy_texture
, &templ
);
392 if (!This
->dummy_sampler_view
)
393 return D3DERR_DRIVERINTERNALERROR
;
395 samp
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
396 samp
.max_lod
= 15.0f
;
397 samp
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
398 samp
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
399 samp
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
400 samp
.min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
401 samp
.mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
402 samp
.compare_mode
= PIPE_TEX_COMPARE_NONE
;
403 samp
.compare_func
= PIPE_FUNC_LEQUAL
;
404 samp
.normalized_coords
= 1;
405 samp
.seamless_cube_map
= 1;
406 This
->dummy_sampler_state
= samp
;
409 /* Allocate upload helper for drivers that suck (from st pov ;). */
411 This
->driver_caps
.user_vbufs
= GET_PCAP(USER_VERTEX_BUFFERS
);
412 This
->driver_caps
.user_ibufs
= GET_PCAP(USER_INDEX_BUFFERS
);
413 This
->driver_caps
.user_cbufs
= GET_PCAP(USER_CONSTANT_BUFFERS
);
415 if (!This
->driver_caps
.user_vbufs
)
416 This
->vertex_uploader
= u_upload_create(This
->pipe
, 65536,
417 PIPE_BIND_VERTEX_BUFFER
, PIPE_USAGE_STREAM
);
418 if (!This
->driver_caps
.user_ibufs
)
419 This
->index_uploader
= u_upload_create(This
->pipe
, 128 * 1024,
420 PIPE_BIND_INDEX_BUFFER
, PIPE_USAGE_STREAM
);
421 if (!This
->driver_caps
.user_cbufs
) {
422 This
->constbuf_alignment
= GET_PCAP(CONSTANT_BUFFER_OFFSET_ALIGNMENT
);
423 This
->constbuf_uploader
= u_upload_create(This
->pipe
, This
->vs_const_size
,
424 PIPE_BIND_CONSTANT_BUFFER
, PIPE_USAGE_STREAM
);
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
);
430 This
->driver_caps
.offset_units_unscaled
= GET_PCAP(POLYGON_OFFSET_UNITS_UNSCALED
);
432 nine_ff_init(This
); /* initialize fixed function code */
434 NineDevice9_SetDefaultState(This
, FALSE
);
437 struct pipe_poly_stipple stipple
;
438 memset(&stipple
, ~0, sizeof(stipple
));
439 This
->pipe
->set_polygon_stipple(This
->pipe
, &stipple
);
442 This
->update
= &This
->state
;
443 nine_update_state(This
);
445 ID3DPresentGroup_Release(This
->present
);
452 NineDevice9_dtor( struct NineDevice9
*This
)
456 DBG("This=%p\n", This
);
458 if (This
->pipe
&& This
->cso
)
459 nine_pipe_context_clear(This
);
461 nine_state_clear(&This
->state
, TRUE
);
463 if (This
->vertex_uploader
)
464 u_upload_destroy(This
->vertex_uploader
);
465 if (This
->index_uploader
)
466 u_upload_destroy(This
->index_uploader
);
467 if (This
->constbuf_uploader
)
468 u_upload_destroy(This
->constbuf_uploader
);
470 nine_bind(&This
->record
, NULL
);
472 pipe_sampler_view_reference(&This
->dummy_sampler_view
, NULL
);
473 pipe_resource_reference(&This
->dummy_texture
, NULL
);
474 pipe_resource_reference(&This
->constbuf_vs
, NULL
);
475 pipe_resource_reference(&This
->constbuf_ps
, NULL
);
476 pipe_resource_reference(&This
->dummy_vbo
, NULL
);
477 FREE(This
->state
.vs_const_f
);
478 FREE(This
->state
.ps_const_f
);
479 FREE(This
->state
.vs_lconstf_temp
);
480 FREE(This
->state
.ps_lconstf_temp
);
482 if (This
->swapchains
) {
483 for (i
= 0; i
< This
->nswapchains
; ++i
)
484 if (This
->swapchains
[i
])
485 NineUnknown_Unbind(NineUnknown(This
->swapchains
[i
]));
486 FREE(This
->swapchains
);
492 cso_destroy_context(This
->cso
);
494 if (This
->pipe
->destroy
) { This
->pipe
->destroy(This
->pipe
); }
497 if (This
->present
) { ID3DPresentGroup_Release(This
->present
); }
498 if (This
->d3d9
) { IDirect3D9_Release(This
->d3d9
); }
500 NineUnknown_dtor(&This
->base
);
504 NineDevice9_GetScreen( struct NineDevice9
*This
)
509 struct pipe_context
*
510 NineDevice9_GetPipe( struct NineDevice9
*This
)
516 NineDevice9_GetCSO( struct NineDevice9
*This
)
522 NineDevice9_GetCaps( struct NineDevice9
*This
)
528 NineDevice9_PauseRecording( struct NineDevice9
*This
)
531 This
->update
= &This
->state
;
532 This
->is_recording
= FALSE
;
537 NineDevice9_ResumeRecording( struct NineDevice9
*This
)
540 This
->update
= &This
->record
->state
;
541 This
->is_recording
= TRUE
;
546 NineDevice9_TestCooperativeLevel( struct NineDevice9
*This
)
548 if (NineSwapChain9_GetOccluded(This
->swapchains
[0])) {
549 This
->device_needs_reset
= TRUE
;
550 return D3DERR_DEVICELOST
;
551 } else if (NineSwapChain9_ResolutionMismatch(This
->swapchains
[0])) {
552 This
->device_needs_reset
= TRUE
;
553 return D3DERR_DEVICENOTRESET
;
554 } else if (This
->device_needs_reset
) {
555 return D3DERR_DEVICENOTRESET
;
562 NineDevice9_GetAvailableTextureMem( struct NineDevice9
*This
)
564 return This
->available_texture_mem
;
568 NineDevice9_EvictManagedResources( struct NineDevice9
*This
)
570 struct NineBaseTexture9
*tex
;
571 struct NineBuffer9
*buf
;
573 DBG("This=%p\n", This
);
574 LIST_FOR_EACH_ENTRY(tex
, &This
->managed_textures
, list2
) {
575 NineBaseTexture9_UnLoad(tex
);
577 /* Vertex/index buffers don't take a lot of space and aren't accounted
578 * for d3d memory usage. Instead of actually freeing from memory,
579 * just mark the buffer dirty to trigger a re-upload later. We
580 * could just ignore, but some bad behaving apps could rely on it (if
581 * they write outside the locked regions typically). */
582 LIST_FOR_EACH_ENTRY(buf
, &This
->managed_buffers
, managed
.list2
) {
583 NineBuffer9_SetDirty(buf
);
590 NineDevice9_GetDirect3D( struct NineDevice9
*This
,
591 IDirect3D9
**ppD3D9
)
593 user_assert(ppD3D9
!= NULL
, E_POINTER
);
594 IDirect3D9_AddRef(This
->d3d9
);
595 *ppD3D9
= This
->d3d9
;
600 NineDevice9_GetDeviceCaps( struct NineDevice9
*This
,
603 user_assert(pCaps
!= NULL
, D3DERR_INVALIDCALL
);
609 NineDevice9_GetDisplayMode( struct NineDevice9
*This
,
611 D3DDISPLAYMODE
*pMode
)
613 DBG("This=%p iSwapChain=%u pMode=%p\n", This
, iSwapChain
, pMode
);
615 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
617 return NineSwapChain9_GetDisplayMode(This
->swapchains
[iSwapChain
], pMode
);
621 NineDevice9_GetCreationParameters( struct NineDevice9
*This
,
622 D3DDEVICE_CREATION_PARAMETERS
*pParameters
)
624 user_assert(pParameters
!= NULL
, D3DERR_INVALIDCALL
);
625 *pParameters
= This
->params
;
630 NineDevice9_SetCursorProperties( struct NineDevice9
*This
,
633 IDirect3DSurface9
*pCursorBitmap
)
635 struct NineSurface9
*surf
= NineSurface9(pCursorBitmap
);
636 struct pipe_context
*pipe
= This
->pipe
;
638 struct pipe_transfer
*transfer
;
642 DBG_FLAG(DBG_SWAPCHAIN
, "This=%p XHotSpot=%u YHotSpot=%u "
643 "pCursorBitmap=%p\n", This
, XHotSpot
, YHotSpot
, pCursorBitmap
);
645 user_assert(pCursorBitmap
, D3DERR_INVALIDCALL
);
646 user_assert(surf
->desc
.Format
== D3DFMT_A8R8G8B8
, D3DERR_INVALIDCALL
);
648 if (This
->swapchains
[0]->params
.Windowed
) {
649 This
->cursor
.w
= MIN2(surf
->desc
.Width
, 32);
650 This
->cursor
.h
= MIN2(surf
->desc
.Height
, 32);
651 hw_cursor
= 1; /* always use hw cursor for windowed mode */
653 This
->cursor
.w
= MIN2(surf
->desc
.Width
, This
->cursor
.image
->width0
);
654 This
->cursor
.h
= MIN2(surf
->desc
.Height
, This
->cursor
.image
->height0
);
655 hw_cursor
= This
->cursor
.w
== 32 && This
->cursor
.h
== 32;
658 u_box_origin_2d(This
->cursor
.w
, This
->cursor
.h
, &box
);
660 ptr
= pipe
->transfer_map(pipe
, This
->cursor
.image
, 0,
661 PIPE_TRANSFER_WRITE
|
662 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
665 ret_err("Failed to update cursor image.\n", D3DERR_DRIVERINTERNALERROR
);
667 This
->cursor
.hotspot
.x
= XHotSpot
;
668 This
->cursor
.hotspot
.y
= YHotSpot
;
670 /* Copy cursor image to internal storage. */
674 const struct util_format_description
*sfmt
=
675 util_format_description(surf
->base
.info
.format
);
678 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, D3DLOCK_READONLY
);
680 ret_err("Failed to map cursor source image.\n",
681 D3DERR_DRIVERINTERNALERROR
);
683 sfmt
->unpack_rgba_8unorm(ptr
, transfer
->stride
,
684 lock
.pBits
, lock
.Pitch
,
685 This
->cursor
.w
, This
->cursor
.h
);
688 hw_cursor
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
,
690 &This
->cursor
.hotspot
,
691 This
->cursor
.visible
) == D3D_OK
;
693 NineSurface9_UnlockRect(surf
);
695 pipe
->transfer_unmap(pipe
, transfer
);
697 /* hide cursor if we emulate it */
699 ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, FALSE
);
700 This
->cursor
.software
= !hw_cursor
;
706 NineDevice9_SetCursorPosition( struct NineDevice9
*This
,
711 struct NineSwapChain9
*swap
= This
->swapchains
[0];
713 DBG("This=%p X=%d Y=%d Flags=%d\n", This
, X
, Y
, Flags
);
715 This
->cursor
.pos
.x
= X
;
716 This
->cursor
.pos
.y
= Y
;
718 if (!This
->cursor
.software
)
719 This
->cursor
.software
= ID3DPresent_SetCursorPos(swap
->present
, &This
->cursor
.pos
) != D3D_OK
;
723 NineDevice9_ShowCursor( struct NineDevice9
*This
,
726 BOOL old
= This
->cursor
.visible
;
728 DBG("This=%p bShow=%d\n", This
, (int) bShow
);
730 This
->cursor
.visible
= bShow
&& (This
->cursor
.hotspot
.x
!= -1);
731 if (!This
->cursor
.software
)
732 This
->cursor
.software
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, bShow
) != D3D_OK
;
738 NineDevice9_CreateAdditionalSwapChain( struct NineDevice9
*This
,
739 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
740 IDirect3DSwapChain9
**pSwapChain
)
742 struct NineSwapChain9
*swapchain
, *tmplt
= This
->swapchains
[0];
743 ID3DPresent
*present
;
746 DBG("This=%p pPresentationParameters=%p pSwapChain=%p\n",
747 This
, pPresentationParameters
, pSwapChain
);
749 user_assert(pPresentationParameters
, D3DERR_INVALIDCALL
);
750 user_assert(tmplt
->params
.Windowed
&& pPresentationParameters
->Windowed
, D3DERR_INVALIDCALL
);
752 /* TODO: this deserves more tests */
753 if (!pPresentationParameters
->hDeviceWindow
)
754 pPresentationParameters
->hDeviceWindow
= This
->params
.hFocusWindow
;
756 hr
= ID3DPresentGroup_CreateAdditionalPresent(This
->present
, pPresentationParameters
, &present
);
761 hr
= NineSwapChain9_new(This
, FALSE
, present
, pPresentationParameters
,
763 tmplt
->params
.hDeviceWindow
,
768 *pSwapChain
= (IDirect3DSwapChain9
*)swapchain
;
773 NineDevice9_GetSwapChain( struct NineDevice9
*This
,
775 IDirect3DSwapChain9
**pSwapChain
)
777 user_assert(pSwapChain
!= NULL
, D3DERR_INVALIDCALL
);
780 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
782 NineUnknown_AddRef(NineUnknown(This
->swapchains
[iSwapChain
]));
783 *pSwapChain
= (IDirect3DSwapChain9
*)This
->swapchains
[iSwapChain
];
789 NineDevice9_GetNumberOfSwapChains( struct NineDevice9
*This
)
791 return This
->nswapchains
;
795 NineDevice9_Reset( struct NineDevice9
*This
,
796 D3DPRESENT_PARAMETERS
*pPresentationParameters
)
801 DBG("This=%p pPresentationParameters=%p\n", This
, pPresentationParameters
);
803 if (NineSwapChain9_GetOccluded(This
->swapchains
[0])) {
804 This
->device_needs_reset
= TRUE
;
805 return D3DERR_DEVICELOST
;
808 for (i
= 0; i
< This
->nswapchains
; ++i
) {
809 D3DPRESENT_PARAMETERS
*params
= &pPresentationParameters
[i
];
810 hr
= NineSwapChain9_Resize(This
->swapchains
[i
], params
, NULL
);
815 nine_pipe_context_clear(This
);
816 nine_state_clear(&This
->state
, TRUE
);
818 NineDevice9_SetDefaultState(This
, TRUE
);
819 NineDevice9_SetRenderTarget(
820 This
, 0, (IDirect3DSurface9
*)This
->swapchains
[0]->buffers
[0]);
821 /* XXX: better use GetBackBuffer here ? */
823 This
->device_needs_reset
= (hr
!= D3D_OK
);
828 NineDevice9_Present( struct NineDevice9
*This
,
829 const RECT
*pSourceRect
,
830 const RECT
*pDestRect
,
831 HWND hDestWindowOverride
,
832 const RGNDATA
*pDirtyRegion
)
837 DBG("This=%p pSourceRect=%p pDestRect=%p hDestWindowOverride=%p pDirtyRegion=%p\n",
838 This
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
840 /* XXX is this right? */
841 for (i
= 0; i
< This
->nswapchains
; ++i
) {
842 hr
= NineSwapChain9_Present(This
->swapchains
[i
], pSourceRect
, pDestRect
,
843 hDestWindowOverride
, pDirtyRegion
, 0);
844 if (FAILED(hr
)) { return hr
; }
851 NineDevice9_GetBackBuffer( struct NineDevice9
*This
,
854 D3DBACKBUFFER_TYPE Type
,
855 IDirect3DSurface9
**ppBackBuffer
)
857 user_assert(ppBackBuffer
!= NULL
, D3DERR_INVALIDCALL
);
858 /* return NULL on error */
859 *ppBackBuffer
= NULL
;
860 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
862 return NineSwapChain9_GetBackBuffer(This
->swapchains
[iSwapChain
],
863 iBackBuffer
, Type
, ppBackBuffer
);
867 NineDevice9_GetRasterStatus( struct NineDevice9
*This
,
869 D3DRASTER_STATUS
*pRasterStatus
)
871 user_assert(pRasterStatus
!= NULL
, D3DERR_INVALIDCALL
);
872 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
874 return NineSwapChain9_GetRasterStatus(This
->swapchains
[iSwapChain
],
879 NineDevice9_SetDialogBoxMode( struct NineDevice9
*This
,
880 BOOL bEnableDialogs
)
882 STUB(D3DERR_INVALIDCALL
);
886 NineDevice9_SetGammaRamp( struct NineDevice9
*This
,
889 const D3DGAMMARAMP
*pRamp
)
891 DBG("This=%p iSwapChain=%u Flags=%x pRamp=%p\n", This
,
892 iSwapChain
, Flags
, pRamp
);
894 user_warn(iSwapChain
>= This
->nswapchains
);
897 if (pRamp
&& (iSwapChain
< This
->nswapchains
)) {
898 struct NineSwapChain9
*swap
= This
->swapchains
[iSwapChain
];
899 swap
->gamma
= *pRamp
;
900 ID3DPresent_SetGammaRamp(swap
->present
, pRamp
, swap
->params
.hDeviceWindow
);
905 NineDevice9_GetGammaRamp( struct NineDevice9
*This
,
907 D3DGAMMARAMP
*pRamp
)
909 DBG("This=%p iSwapChain=%u pRamp=%p\n", This
, iSwapChain
, pRamp
);
911 user_warn(iSwapChain
>= This
->nswapchains
);
914 if (pRamp
&& (iSwapChain
< This
->nswapchains
))
915 *pRamp
= This
->swapchains
[iSwapChain
]->gamma
;
919 NineDevice9_CreateTexture( struct NineDevice9
*This
,
926 IDirect3DTexture9
**ppTexture
,
927 HANDLE
*pSharedHandle
)
929 struct NineTexture9
*tex
;
932 DBG("This=%p Width=%u Height=%u Levels=%u Usage=%s Format=%s Pool=%s "
933 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Levels
,
934 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
935 nine_D3DPOOL_to_str(Pool
), ppTexture
, pSharedHandle
);
937 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DMAP
|
938 D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
939 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
;
943 hr
= NineTexture9_new(This
, Width
, Height
, Levels
, Usage
, Format
, Pool
,
944 &tex
, pSharedHandle
);
946 *ppTexture
= (IDirect3DTexture9
*)tex
;
952 NineDevice9_CreateVolumeTexture( struct NineDevice9
*This
,
960 IDirect3DVolumeTexture9
**ppVolumeTexture
,
961 HANDLE
*pSharedHandle
)
963 struct NineVolumeTexture9
*tex
;
966 DBG("This=%p Width=%u Height=%u Depth=%u Levels=%u Usage=%s Format=%s Pool=%s "
967 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Depth
, Levels
,
968 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
969 nine_D3DPOOL_to_str(Pool
), ppVolumeTexture
, pSharedHandle
);
971 Usage
&= D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
972 D3DUSAGE_SOFTWAREPROCESSING
;
974 *ppVolumeTexture
= NULL
;
976 hr
= NineVolumeTexture9_new(This
, Width
, Height
, Depth
, Levels
,
977 Usage
, Format
, Pool
, &tex
, pSharedHandle
);
979 *ppVolumeTexture
= (IDirect3DVolumeTexture9
*)tex
;
985 NineDevice9_CreateCubeTexture( struct NineDevice9
*This
,
991 IDirect3DCubeTexture9
**ppCubeTexture
,
992 HANDLE
*pSharedHandle
)
994 struct NineCubeTexture9
*tex
;
997 DBG("This=%p EdgeLength=%u Levels=%u Usage=%s Format=%s Pool=%s ppOut=%p "
998 "pSharedHandle=%p\n", This
, EdgeLength
, Levels
,
999 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
1000 nine_D3DPOOL_to_str(Pool
), ppCubeTexture
, pSharedHandle
);
1002 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DYNAMIC
|
1003 D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
1004 D3DUSAGE_SOFTWAREPROCESSING
;
1006 *ppCubeTexture
= NULL
;
1008 hr
= NineCubeTexture9_new(This
, EdgeLength
, Levels
, Usage
, Format
, Pool
,
1009 &tex
, pSharedHandle
);
1011 *ppCubeTexture
= (IDirect3DCubeTexture9
*)tex
;
1017 NineDevice9_CreateVertexBuffer( struct NineDevice9
*This
,
1022 IDirect3DVertexBuffer9
**ppVertexBuffer
,
1023 HANDLE
*pSharedHandle
)
1025 struct NineVertexBuffer9
*buf
;
1027 D3DVERTEXBUFFER_DESC desc
;
1029 DBG("This=%p Length=%u Usage=%x FVF=%x Pool=%u ppOut=%p pSharedHandle=%p\n",
1030 This
, Length
, Usage
, FVF
, Pool
, ppVertexBuffer
, pSharedHandle
);
1032 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1034 desc
.Format
= D3DFMT_VERTEXDATA
;
1035 desc
.Type
= D3DRTYPE_VERTEXBUFFER
;
1036 desc
.Usage
= Usage
&
1037 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1038 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1039 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
|
1040 D3DUSAGE_WRITEONLY
);
1045 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1046 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1048 hr
= NineVertexBuffer9_new(This
, &desc
, &buf
);
1050 *ppVertexBuffer
= (IDirect3DVertexBuffer9
*)buf
;
1055 NineDevice9_CreateIndexBuffer( struct NineDevice9
*This
,
1060 IDirect3DIndexBuffer9
**ppIndexBuffer
,
1061 HANDLE
*pSharedHandle
)
1063 struct NineIndexBuffer9
*buf
;
1065 D3DINDEXBUFFER_DESC desc
;
1067 DBG("This=%p Length=%u Usage=%x Format=%s Pool=%u ppOut=%p "
1068 "pSharedHandle=%p\n", This
, Length
, Usage
,
1069 d3dformat_to_string(Format
), Pool
, ppIndexBuffer
, pSharedHandle
);
1071 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1073 desc
.Format
= Format
;
1074 desc
.Type
= D3DRTYPE_INDEXBUFFER
;
1075 desc
.Usage
= Usage
&
1076 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1077 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1078 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_WRITEONLY
);
1082 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1083 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1085 hr
= NineIndexBuffer9_new(This
, &desc
, &buf
);
1087 *ppIndexBuffer
= (IDirect3DIndexBuffer9
*)buf
;
1092 create_zs_or_rt_surface(struct NineDevice9
*This
,
1093 unsigned type
, /* 0 = RT, 1 = ZS, 2 = plain */
1095 UINT Width
, UINT Height
,
1097 D3DMULTISAMPLE_TYPE MultiSample
,
1098 DWORD MultisampleQuality
,
1099 BOOL Discard_or_Lockable
,
1100 IDirect3DSurface9
**ppSurface
,
1101 HANDLE
*pSharedHandle
)
1103 struct NineSurface9
*surface
;
1104 struct pipe_screen
*screen
= This
->screen
;
1105 struct pipe_resource
*resource
= NULL
;
1107 D3DSURFACE_DESC desc
;
1108 struct pipe_resource templ
;
1110 DBG("This=%p type=%u Pool=%s Width=%u Height=%u Format=%s MS=%u Quality=%u "
1111 "Discard_or_Lockable=%i ppSurface=%p pSharedHandle=%p\n",
1112 This
, type
, nine_D3DPOOL_to_str(Pool
), Width
, Height
,
1113 d3dformat_to_string(Format
), MultiSample
, MultisampleQuality
,
1114 Discard_or_Lockable
, ppSurface
, pSharedHandle
);
1117 DBG("FIXME Used shared handle! This option isn't probably handled correctly!\n");
1119 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
1120 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1122 templ
.target
= PIPE_TEXTURE_2D
;
1123 templ
.width0
= Width
;
1124 templ
.height0
= Height
;
1126 templ
.array_size
= 1;
1127 templ
.last_level
= 0;
1128 templ
.nr_samples
= (unsigned)MultiSample
;
1129 templ
.usage
= PIPE_USAGE_DEFAULT
;
1131 templ
.bind
= PIPE_BIND_SAMPLER_VIEW
; /* StretchRect */
1133 case 0: templ
.bind
|= PIPE_BIND_RENDER_TARGET
; break;
1134 case 1: templ
.bind
= d3d9_get_pipe_depth_format_bindings(Format
); break;
1139 templ
.format
= d3d9_to_pipe_format_checked(screen
, Format
, templ
.target
,
1140 templ
.nr_samples
, templ
.bind
,
1141 FALSE
, Pool
== D3DPOOL_SCRATCH
);
1143 if (templ
.format
== PIPE_FORMAT_NONE
&& Format
!= D3DFMT_NULL
)
1144 return D3DERR_INVALIDCALL
;
1146 desc
.Format
= Format
;
1147 desc
.Type
= D3DRTYPE_SURFACE
;
1150 desc
.MultiSampleType
= MultiSample
;
1151 desc
.MultiSampleQuality
= MultisampleQuality
;
1153 desc
.Height
= Height
;
1155 case 0: desc
.Usage
= D3DUSAGE_RENDERTARGET
; break;
1156 case 1: desc
.Usage
= D3DUSAGE_DEPTHSTENCIL
; break;
1160 if (compressed_format(Format
)) {
1161 const unsigned w
= util_format_get_blockwidth(templ
.format
);
1162 const unsigned h
= util_format_get_blockheight(templ
.format
);
1164 user_assert(!(Width
% w
) && !(Height
% h
), D3DERR_INVALIDCALL
);
1167 if (Pool
== D3DPOOL_DEFAULT
&& Format
!= D3DFMT_NULL
) {
1168 /* resource_create doesn't return an error code, so check format here */
1169 user_assert(templ
.format
!= PIPE_FORMAT_NONE
, D3DERR_INVALIDCALL
);
1170 resource
= screen
->resource_create(screen
, &templ
);
1171 user_assert(resource
, D3DERR_OUTOFVIDEOMEMORY
);
1172 if (Discard_or_Lockable
&& (desc
.Usage
& D3DUSAGE_RENDERTARGET
))
1173 resource
->flags
|= NINE_RESOURCE_FLAG_LOCKABLE
;
1177 hr
= NineSurface9_new(This
, NULL
, resource
, NULL
, 0, 0, 0, &desc
, &surface
);
1178 pipe_resource_reference(&resource
, NULL
);
1181 *ppSurface
= (IDirect3DSurface9
*)surface
;
1186 NineDevice9_CreateRenderTarget( struct NineDevice9
*This
,
1190 D3DMULTISAMPLE_TYPE MultiSample
,
1191 DWORD MultisampleQuality
,
1193 IDirect3DSurface9
**ppSurface
,
1194 HANDLE
*pSharedHandle
)
1197 return create_zs_or_rt_surface(This
, 0, D3DPOOL_DEFAULT
,
1198 Width
, Height
, Format
,
1199 MultiSample
, MultisampleQuality
,
1200 Lockable
, ppSurface
, pSharedHandle
);
1204 NineDevice9_CreateDepthStencilSurface( struct NineDevice9
*This
,
1208 D3DMULTISAMPLE_TYPE MultiSample
,
1209 DWORD MultisampleQuality
,
1211 IDirect3DSurface9
**ppSurface
,
1212 HANDLE
*pSharedHandle
)
1215 if (!depth_stencil_format(Format
))
1216 return D3DERR_NOTAVAILABLE
;
1217 return create_zs_or_rt_surface(This
, 1, D3DPOOL_DEFAULT
,
1218 Width
, Height
, Format
,
1219 MultiSample
, MultisampleQuality
,
1220 Discard
, ppSurface
, pSharedHandle
);
1224 NineDevice9_UpdateSurface( struct NineDevice9
*This
,
1225 IDirect3DSurface9
*pSourceSurface
,
1226 const RECT
*pSourceRect
,
1227 IDirect3DSurface9
*pDestinationSurface
,
1228 const POINT
*pDestPoint
)
1230 struct NineSurface9
*dst
= NineSurface9(pDestinationSurface
);
1231 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1232 int copy_width
, copy_height
;
1235 DBG("This=%p pSourceSurface=%p pDestinationSurface=%p "
1236 "pSourceRect=%p pDestPoint=%p\n", This
,
1237 pSourceSurface
, pDestinationSurface
, pSourceRect
, pDestPoint
);
1239 DBG("pSourceRect = (%u,%u)-(%u,%u)\n",
1240 pSourceRect
->left
, pSourceRect
->top
,
1241 pSourceRect
->right
, pSourceRect
->bottom
);
1243 DBG("pDestPoint = (%u,%u)\n", pDestPoint
->x
, pDestPoint
->y
);
1245 user_assert(dst
&& src
, D3DERR_INVALIDCALL
);
1247 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1248 user_assert(src
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1250 user_assert(dst
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1251 user_assert(src
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1253 user_assert(!src
->lock_count
, D3DERR_INVALIDCALL
);
1254 user_assert(!dst
->lock_count
, D3DERR_INVALIDCALL
);
1256 user_assert(dst
->desc
.Format
== src
->desc
.Format
, D3DERR_INVALIDCALL
);
1257 user_assert(!depth_stencil_format(dst
->desc
.Format
), D3DERR_INVALIDCALL
);
1260 copy_width
= pSourceRect
->right
- pSourceRect
->left
;
1261 copy_height
= pSourceRect
->bottom
- pSourceRect
->top
;
1263 user_assert(pSourceRect
->left
>= 0 &&
1265 pSourceRect
->right
<= src
->desc
.Width
&&
1266 pSourceRect
->top
>= 0 &&
1268 pSourceRect
->bottom
<= src
->desc
.Height
,
1269 D3DERR_INVALIDCALL
);
1271 copy_width
= src
->desc
.Width
;
1272 copy_height
= src
->desc
.Height
;
1275 destRect
.right
= copy_width
;
1276 destRect
.bottom
= copy_height
;
1279 user_assert(pDestPoint
->x
>= 0 && pDestPoint
->y
>= 0,
1280 D3DERR_INVALIDCALL
);
1281 destRect
.right
+= pDestPoint
->x
;
1282 destRect
.bottom
+= pDestPoint
->y
;
1285 user_assert(destRect
.right
<= dst
->desc
.Width
&&
1286 destRect
.bottom
<= dst
->desc
.Height
,
1287 D3DERR_INVALIDCALL
);
1289 if (compressed_format(dst
->desc
.Format
)) {
1290 const unsigned w
= util_format_get_blockwidth(dst
->base
.info
.format
);
1291 const unsigned h
= util_format_get_blockheight(dst
->base
.info
.format
);
1294 user_assert(!(pDestPoint
->x
% w
) && !(pDestPoint
->y
% h
),
1295 D3DERR_INVALIDCALL
);
1299 user_assert(!(pSourceRect
->left
% w
) && !(pSourceRect
->top
% h
),
1300 D3DERR_INVALIDCALL
);
1302 if (!(copy_width
== src
->desc
.Width
&&
1303 copy_width
== dst
->desc
.Width
&&
1304 copy_height
== src
->desc
.Height
&&
1305 copy_height
== dst
->desc
.Height
)) {
1306 user_assert(!(copy_width
% w
) && !(copy_height
% h
),
1307 D3DERR_INVALIDCALL
);
1311 NineSurface9_CopyMemToDefault(dst
, src
, pDestPoint
, pSourceRect
);
1317 NineDevice9_UpdateTexture( struct NineDevice9
*This
,
1318 IDirect3DBaseTexture9
*pSourceTexture
,
1319 IDirect3DBaseTexture9
*pDestinationTexture
)
1321 struct NineBaseTexture9
*dstb
= NineBaseTexture9(pDestinationTexture
);
1322 struct NineBaseTexture9
*srcb
= NineBaseTexture9(pSourceTexture
);
1324 unsigned last_src_level
, last_dst_level
;
1327 DBG("This=%p pSourceTexture=%p pDestinationTexture=%p\n", This
,
1328 pSourceTexture
, pDestinationTexture
);
1330 user_assert(pSourceTexture
&& pDestinationTexture
, D3DERR_INVALIDCALL
);
1331 user_assert(pSourceTexture
!= pDestinationTexture
, D3DERR_INVALIDCALL
);
1333 user_assert(dstb
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1334 user_assert(srcb
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1335 user_assert(dstb
->base
.type
== srcb
->base
.type
, D3DERR_INVALIDCALL
);
1336 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ||
1337 dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
, D3DERR_INVALIDCALL
);
1340 * . Different formats
1341 * . Fewer src levels than dst levels (if the opposite, only matching levels
1342 * are supposed to be copied)
1343 * . Levels do not match
1344 * DDI: Actually the above should pass because of legacy applications
1345 * Do what you want about these, but you shouldn't crash.
1346 * However driver can expect that the top dimension is greater for src than dst.
1347 * Wine tests: Every combination that passes the initial checks should pass.
1348 * . Different formats => conversion driver and format dependent.
1349 * . 1 level, but size not matching => copy is done (and even crash if src bigger
1350 * than dst. For the case where dst bigger, wine doesn't test if a stretch is applied
1351 * or if a subrect is copied).
1352 * . 8x8 4 sublevels -> 7x7 2 sublevels => driver dependent, On NV seems to be 4x4 subrect
1355 * From these, the proposal is:
1356 * . Different formats -> use util_format_translate to translate if possible for surfaces.
1357 * Accept ARGB/XRGB for Volumes. Do nothing for the other combinations
1358 * . First level copied -> the first level such that src is smaller or equal to dst first level
1359 * . number of levels copied -> as long as it fits and textures have levels
1360 * That should satisfy the constraints (and instead of crashing for some cases we return D3D_OK)
1363 last_src_level
= (srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ? 0 : srcb
->base
.info
.last_level
;
1364 last_dst_level
= (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ? 0 : dstb
->base
.info
.last_level
;
1366 for (m
= 0; m
<= last_src_level
; ++m
) {
1367 unsigned w
= u_minify(srcb
->base
.info
.width0
, m
);
1368 unsigned h
= u_minify(srcb
->base
.info
.height0
, m
);
1369 unsigned d
= u_minify(srcb
->base
.info
.depth0
, m
);
1371 if (w
<= dstb
->base
.info
.width0
&&
1372 h
<= dstb
->base
.info
.height0
&&
1373 d
<= dstb
->base
.info
.depth0
)
1376 user_assert(m
<= last_src_level
, D3D_OK
);
1378 last_dst_level
= MIN2(srcb
->base
.info
.last_level
- m
, last_dst_level
);
1380 if (dstb
->base
.type
== D3DRTYPE_TEXTURE
) {
1381 struct NineTexture9
*dst
= NineTexture9(dstb
);
1382 struct NineTexture9
*src
= NineTexture9(srcb
);
1384 if (src
->dirty_rect
.width
== 0)
1387 pipe_box_to_rect(&rect
, &src
->dirty_rect
);
1388 for (l
= 0; l
< m
; ++l
)
1389 rect_minify_inclusive(&rect
);
1391 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
) {
1392 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1394 dst
->surfaces
[l
]->desc
.Width
,
1395 dst
->surfaces
[l
]->desc
.Height
);
1396 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
],
1400 rect_minify_inclusive(&rect
);
1402 u_box_origin_2d(0, 0, &src
->dirty_rect
);
1404 if (dstb
->base
.type
== D3DRTYPE_CUBETEXTURE
) {
1405 struct NineCubeTexture9
*dst
= NineCubeTexture9(dstb
);
1406 struct NineCubeTexture9
*src
= NineCubeTexture9(srcb
);
1409 /* GPUs usually have them stored as arrays of mip-mapped 2D textures. */
1410 for (z
= 0; z
< 6; ++z
) {
1411 if (src
->dirty_rect
[z
].width
== 0)
1414 pipe_box_to_rect(&rect
, &src
->dirty_rect
[z
]);
1415 for (l
= 0; l
< m
; ++l
)
1416 rect_minify_inclusive(&rect
);
1418 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
) {
1419 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1421 dst
->surfaces
[l
* 6 + z
]->desc
.Width
,
1422 dst
->surfaces
[l
* 6 + z
]->desc
.Height
);
1423 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
* 6 + z
],
1424 src
->surfaces
[m
* 6 + z
],
1427 rect_minify_inclusive(&rect
);
1429 u_box_origin_2d(0, 0, &src
->dirty_rect
[z
]);
1433 if (dstb
->base
.type
== D3DRTYPE_VOLUMETEXTURE
) {
1434 struct NineVolumeTexture9
*dst
= NineVolumeTexture9(dstb
);
1435 struct NineVolumeTexture9
*src
= NineVolumeTexture9(srcb
);
1437 if (src
->dirty_box
.width
== 0)
1439 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
)
1440 NineVolume9_CopyMemToDefault(dst
->volumes
[l
],
1441 src
->volumes
[m
], 0, 0, 0, NULL
);
1442 u_box_3d(0, 0, 0, 0, 0, 0, &src
->dirty_box
);
1444 assert(!"invalid texture type");
1447 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1448 dstb
->dirty_mip
= TRUE
;
1449 NineBaseTexture9_GenerateMipSubLevels(dstb
);
1456 NineDevice9_GetRenderTargetData( struct NineDevice9
*This
,
1457 IDirect3DSurface9
*pRenderTarget
,
1458 IDirect3DSurface9
*pDestSurface
)
1460 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1461 struct NineSurface9
*src
= NineSurface9(pRenderTarget
);
1463 DBG("This=%p pRenderTarget=%p pDestSurface=%p\n",
1464 This
, pRenderTarget
, pDestSurface
);
1466 user_assert(dst
->desc
.Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1467 user_assert(src
->desc
.Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1469 user_assert(dst
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1470 user_assert(src
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1472 user_assert(src
->desc
.Width
== dst
->desc
.Width
, D3DERR_INVALIDCALL
);
1473 user_assert(src
->desc
.Height
== dst
->desc
.Height
, D3DERR_INVALIDCALL
);
1475 NineSurface9_CopyDefaultToMem(dst
, src
);
1481 NineDevice9_GetFrontBufferData( struct NineDevice9
*This
,
1483 IDirect3DSurface9
*pDestSurface
)
1485 DBG("This=%p iSwapChain=%u pDestSurface=%p\n", This
,
1486 iSwapChain
, pDestSurface
);
1488 user_assert(pDestSurface
!= NULL
, D3DERR_INVALIDCALL
);
1489 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
1491 return NineSwapChain9_GetFrontBufferData(This
->swapchains
[iSwapChain
],
1496 NineDevice9_StretchRect( struct NineDevice9
*This
,
1497 IDirect3DSurface9
*pSourceSurface
,
1498 const RECT
*pSourceRect
,
1499 IDirect3DSurface9
*pDestSurface
,
1500 const RECT
*pDestRect
,
1501 D3DTEXTUREFILTERTYPE Filter
)
1503 struct pipe_screen
*screen
= This
->screen
;
1504 struct pipe_context
*pipe
= This
->pipe
;
1505 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1506 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1507 struct pipe_resource
*dst_res
= NineSurface9_GetResource(dst
);
1508 struct pipe_resource
*src_res
= NineSurface9_GetResource(src
);
1510 struct pipe_blit_info blit
;
1511 boolean scaled
, clamped
, ms
, flip_x
= FALSE
, flip_y
= FALSE
;
1513 DBG("This=%p pSourceSurface=%p pSourceRect=%p pDestSurface=%p "
1514 "pDestRect=%p Filter=%u\n",
1515 This
, pSourceSurface
, pSourceRect
, pDestSurface
, pDestRect
, Filter
);
1517 DBG("pSourceRect=(%u,%u)-(%u,%u)\n",
1518 pSourceRect
->left
, pSourceRect
->top
,
1519 pSourceRect
->right
, pSourceRect
->bottom
);
1521 DBG("pDestRect=(%u,%u)-(%u,%u)\n", pDestRect
->left
, pDestRect
->top
,
1522 pDestRect
->right
, pDestRect
->bottom
);
1524 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
&&
1525 src
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1526 zs
= util_format_is_depth_or_stencil(dst_res
->format
);
1527 user_assert(!zs
|| !This
->in_scene
, D3DERR_INVALIDCALL
);
1528 user_assert(!zs
|| !pSourceRect
||
1529 (pSourceRect
->left
== 0 &&
1530 pSourceRect
->top
== 0 &&
1531 pSourceRect
->right
== src
->desc
.Width
&&
1532 pSourceRect
->bottom
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1533 user_assert(!zs
|| !pDestRect
||
1534 (pDestRect
->left
== 0 &&
1535 pDestRect
->top
== 0 &&
1536 pDestRect
->right
== dst
->desc
.Width
&&
1537 pDestRect
->bottom
== dst
->desc
.Height
), D3DERR_INVALIDCALL
);
1539 (dst
->desc
.Width
== src
->desc
.Width
&&
1540 dst
->desc
.Height
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1541 user_assert(zs
|| !util_format_is_depth_or_stencil(src_res
->format
),
1542 D3DERR_INVALIDCALL
);
1543 user_assert(!zs
|| dst
->desc
.Format
== src
->desc
.Format
,
1544 D3DERR_INVALIDCALL
);
1545 user_assert(screen
->is_format_supported(screen
, src_res
->format
,
1547 src_res
->nr_samples
,
1548 PIPE_BIND_SAMPLER_VIEW
),
1549 D3DERR_INVALIDCALL
);
1551 /* We might want to permit these, but wine thinks we shouldn't. */
1552 user_assert(!pDestRect
||
1553 (pDestRect
->left
<= pDestRect
->right
&&
1554 pDestRect
->top
<= pDestRect
->bottom
), D3DERR_INVALIDCALL
);
1555 user_assert(!pSourceRect
||
1556 (pSourceRect
->left
<= pSourceRect
->right
&&
1557 pSourceRect
->top
<= pSourceRect
->bottom
), D3DERR_INVALIDCALL
);
1559 memset(&blit
, 0, sizeof(blit
));
1560 blit
.dst
.resource
= dst_res
;
1561 blit
.dst
.level
= dst
->level
;
1562 blit
.dst
.box
.z
= dst
->layer
;
1563 blit
.dst
.box
.depth
= 1;
1564 blit
.dst
.format
= dst_res
->format
;
1566 flip_x
= pDestRect
->left
> pDestRect
->right
;
1568 blit
.dst
.box
.x
= pDestRect
->right
;
1569 blit
.dst
.box
.width
= pDestRect
->left
- pDestRect
->right
;
1571 blit
.dst
.box
.x
= pDestRect
->left
;
1572 blit
.dst
.box
.width
= pDestRect
->right
- pDestRect
->left
;
1574 flip_y
= pDestRect
->top
> pDestRect
->bottom
;
1576 blit
.dst
.box
.y
= pDestRect
->bottom
;
1577 blit
.dst
.box
.height
= pDestRect
->top
- pDestRect
->bottom
;
1579 blit
.dst
.box
.y
= pDestRect
->top
;
1580 blit
.dst
.box
.height
= pDestRect
->bottom
- pDestRect
->top
;
1585 blit
.dst
.box
.width
= dst
->desc
.Width
;
1586 blit
.dst
.box
.height
= dst
->desc
.Height
;
1588 blit
.src
.resource
= src_res
;
1589 blit
.src
.level
= src
->level
;
1590 blit
.src
.box
.z
= src
->layer
;
1591 blit
.src
.box
.depth
= 1;
1592 blit
.src
.format
= src_res
->format
;
1594 if (flip_x
^ (pSourceRect
->left
> pSourceRect
->right
)) {
1595 blit
.src
.box
.x
= pSourceRect
->right
;
1596 blit
.src
.box
.width
= pSourceRect
->left
- pSourceRect
->right
;
1598 blit
.src
.box
.x
= pSourceRect
->left
;
1599 blit
.src
.box
.width
= pSourceRect
->right
- pSourceRect
->left
;
1601 if (flip_y
^ (pSourceRect
->top
> pSourceRect
->bottom
)) {
1602 blit
.src
.box
.y
= pSourceRect
->bottom
;
1603 blit
.src
.box
.height
= pSourceRect
->top
- pSourceRect
->bottom
;
1605 blit
.src
.box
.y
= pSourceRect
->top
;
1606 blit
.src
.box
.height
= pSourceRect
->bottom
- pSourceRect
->top
;
1609 blit
.src
.box
.x
= flip_x
? src
->desc
.Width
: 0;
1610 blit
.src
.box
.y
= flip_y
? src
->desc
.Height
: 0;
1611 blit
.src
.box
.width
= flip_x
? -src
->desc
.Width
: src
->desc
.Width
;
1612 blit
.src
.box
.height
= flip_y
? -src
->desc
.Height
: src
->desc
.Height
;
1614 blit
.mask
= zs
? PIPE_MASK_ZS
: PIPE_MASK_RGBA
;
1615 blit
.filter
= Filter
== D3DTEXF_LINEAR
?
1616 PIPE_TEX_FILTER_LINEAR
: PIPE_TEX_FILTER_NEAREST
;
1617 blit
.scissor_enable
= FALSE
;
1618 blit
.alpha_blend
= FALSE
;
1620 /* If both of a src and dst dimension are negative, flip them. */
1621 if (blit
.dst
.box
.width
< 0 && blit
.src
.box
.width
< 0) {
1622 blit
.dst
.box
.width
= -blit
.dst
.box
.width
;
1623 blit
.src
.box
.width
= -blit
.src
.box
.width
;
1625 if (blit
.dst
.box
.height
< 0 && blit
.src
.box
.height
< 0) {
1626 blit
.dst
.box
.height
= -blit
.dst
.box
.height
;
1627 blit
.src
.box
.height
= -blit
.src
.box
.height
;
1630 blit
.dst
.box
.width
!= blit
.src
.box
.width
||
1631 blit
.dst
.box
.height
!= blit
.src
.box
.height
;
1633 user_assert(!scaled
|| dst
!= src
, D3DERR_INVALIDCALL
);
1634 user_assert(!scaled
||
1635 !NineSurface9_IsOffscreenPlain(dst
), D3DERR_INVALIDCALL
);
1636 user_assert(!NineSurface9_IsOffscreenPlain(dst
) ||
1637 NineSurface9_IsOffscreenPlain(src
), D3DERR_INVALIDCALL
);
1638 user_assert(NineSurface9_IsOffscreenPlain(dst
) ||
1639 dst
->desc
.Usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
),
1640 D3DERR_INVALIDCALL
);
1641 user_assert(!scaled
||
1642 (!util_format_is_compressed(dst
->base
.info
.format
) &&
1643 !util_format_is_compressed(src
->base
.info
.format
)),
1644 D3DERR_INVALIDCALL
);
1646 user_warn(src
== dst
&&
1647 u_box_test_intersection_2d(&blit
.src
.box
, &blit
.dst
.box
));
1649 /* Check for clipping/clamping: */
1651 struct pipe_box box
;
1654 xy
= u_box_clip_2d(&box
, &blit
.dst
.box
,
1655 dst
->desc
.Width
, dst
->desc
.Height
);
1659 xy
= u_box_clip_2d(&box
, &blit
.src
.box
,
1660 src
->desc
.Width
, src
->desc
.Height
);
1664 ms
= (dst
->desc
.MultiSampleType
| 1) != (src
->desc
.MultiSampleType
| 1);
1666 if (clamped
|| scaled
|| (blit
.dst
.format
!= blit
.src
.format
) || ms
) {
1667 DBG("using pipe->blit()\n");
1668 /* TODO: software scaling */
1669 user_assert(screen
->is_format_supported(screen
, dst_res
->format
,
1671 dst_res
->nr_samples
,
1672 zs
? PIPE_BIND_DEPTH_STENCIL
:
1673 PIPE_BIND_RENDER_TARGET
),
1674 D3DERR_INVALIDCALL
);
1676 pipe
->blit(pipe
, &blit
);
1678 assert(blit
.dst
.box
.x
>= 0 && blit
.dst
.box
.y
>= 0 &&
1679 blit
.src
.box
.x
>= 0 && blit
.src
.box
.y
>= 0 &&
1680 blit
.dst
.box
.x
+ blit
.dst
.box
.width
<= dst
->desc
.Width
&&
1681 blit
.src
.box
.x
+ blit
.src
.box
.width
<= src
->desc
.Width
&&
1682 blit
.dst
.box
.y
+ blit
.dst
.box
.height
<= dst
->desc
.Height
&&
1683 blit
.src
.box
.y
+ blit
.src
.box
.height
<= src
->desc
.Height
);
1684 /* Or drivers might crash ... */
1685 DBG("Using resource_copy_region.\n");
1686 pipe
->resource_copy_region(pipe
,
1687 blit
.dst
.resource
, blit
.dst
.level
,
1688 blit
.dst
.box
.x
, blit
.dst
.box
.y
, blit
.dst
.box
.z
,
1689 blit
.src
.resource
, blit
.src
.level
,
1693 /* Communicate the container it needs to update sublevels - if apply */
1694 NineSurface9_MarkContainerDirty(dst
);
1700 NineDevice9_ColorFill( struct NineDevice9
*This
,
1701 IDirect3DSurface9
*pSurface
,
1705 struct pipe_context
*pipe
= This
->pipe
;
1706 struct NineSurface9
*surf
= NineSurface9(pSurface
);
1707 struct pipe_surface
*psurf
;
1708 unsigned x
, y
, w
, h
;
1709 union pipe_color_union rgba
;
1712 DBG("This=%p pSurface=%p pRect=%p color=%08x\n", This
,
1713 pSurface
, pRect
, color
);
1715 DBG("pRect=(%u,%u)-(%u,%u)\n", pRect
->left
, pRect
->top
,
1716 pRect
->right
, pRect
->bottom
);
1718 user_assert(surf
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1720 user_assert((surf
->base
.usage
& D3DUSAGE_RENDERTARGET
) ||
1721 NineSurface9_IsOffscreenPlain(surf
), D3DERR_INVALIDCALL
);
1723 user_assert(surf
->desc
.Format
!= D3DFMT_NULL
, D3D_OK
);
1728 w
= pRect
->right
- pRect
->left
;
1729 h
= pRect
->bottom
- pRect
->top
;
1731 if (compressed_format(surf
->desc
.Format
)) {
1732 const unsigned bw
= util_format_get_blockwidth(surf
->base
.info
.format
);
1733 const unsigned bh
= util_format_get_blockheight(surf
->base
.info
.format
);
1735 user_assert(!(x
% bw
) && !(y
% bh
) && !(w
% bw
) && !(h
% bh
),
1736 D3DERR_INVALIDCALL
);
1741 w
= surf
->desc
.Width
;
1742 h
= surf
->desc
.Height
;
1744 d3dcolor_to_pipe_color_union(&rgba
, color
);
1746 fallback
= !(surf
->base
.info
.bind
& PIPE_BIND_RENDER_TARGET
);
1749 psurf
= NineSurface9_GetSurface(surf
, 0);
1755 pipe
->clear_render_target(pipe
, psurf
, &rgba
, x
, y
, w
, h
, false);
1757 D3DLOCKED_RECT lock
;
1758 union util_color uc
;
1760 /* XXX: lock pRect and fix util_fill_rect */
1761 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, 0);
1764 util_pack_color_ub(color
>> 16, color
>> 8, color
>> 0, color
>> 24,
1765 surf
->base
.info
.format
, &uc
);
1766 util_fill_rect(lock
.pBits
, surf
->base
.info
.format
,lock
.Pitch
,
1768 NineSurface9_UnlockRect(surf
);
1775 NineDevice9_CreateOffscreenPlainSurface( struct NineDevice9
*This
,
1780 IDirect3DSurface9
**ppSurface
,
1781 HANDLE
*pSharedHandle
)
1785 DBG("This=%p Width=%u Height=%u Format=%s(0x%x) Pool=%u "
1786 "ppSurface=%p pSharedHandle=%p\n", This
,
1787 Width
, Height
, d3dformat_to_string(Format
), Format
, Pool
,
1788 ppSurface
, pSharedHandle
);
1791 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
1792 || Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1793 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1795 /* Can be used with StretchRect and ColorFill. It's also always lockable.
1797 hr
= create_zs_or_rt_surface(This
, 2, Pool
, Width
, Height
,
1799 D3DMULTISAMPLE_NONE
, 0,
1801 ppSurface
, pSharedHandle
);
1803 DBG("Failed to create surface.\n");
1808 NineDevice9_SetRenderTarget( struct NineDevice9
*This
,
1809 DWORD RenderTargetIndex
,
1810 IDirect3DSurface9
*pRenderTarget
)
1812 struct NineSurface9
*rt
= NineSurface9(pRenderTarget
);
1813 const unsigned i
= RenderTargetIndex
;
1815 DBG("This=%p RenderTargetIndex=%u pRenderTarget=%p\n", This
,
1816 RenderTargetIndex
, pRenderTarget
);
1818 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1819 user_assert(i
!= 0 || pRenderTarget
, D3DERR_INVALIDCALL
);
1820 user_assert(!pRenderTarget
||
1821 rt
->desc
.Usage
& D3DUSAGE_RENDERTARGET
, D3DERR_INVALIDCALL
);
1824 This
->state
.viewport
.X
= 0;
1825 This
->state
.viewport
.Y
= 0;
1826 This
->state
.viewport
.Width
= rt
->desc
.Width
;
1827 This
->state
.viewport
.Height
= rt
->desc
.Height
;
1828 This
->state
.viewport
.MinZ
= 0.0f
;
1829 This
->state
.viewport
.MaxZ
= 1.0f
;
1831 This
->state
.scissor
.minx
= 0;
1832 This
->state
.scissor
.miny
= 0;
1833 This
->state
.scissor
.maxx
= rt
->desc
.Width
;
1834 This
->state
.scissor
.maxy
= rt
->desc
.Height
;
1836 This
->state
.changed
.group
|= NINE_STATE_VIEWPORT
| NINE_STATE_SCISSOR
| NINE_STATE_MULTISAMPLE
;
1839 if (This
->state
.rt
[i
] != NineSurface9(pRenderTarget
)) {
1840 nine_bind(&This
->state
.rt
[i
], pRenderTarget
);
1841 This
->state
.changed
.group
|= NINE_STATE_FB
;
1847 NineDevice9_GetRenderTarget( struct NineDevice9
*This
,
1848 DWORD RenderTargetIndex
,
1849 IDirect3DSurface9
**ppRenderTarget
)
1851 const unsigned i
= RenderTargetIndex
;
1853 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1854 user_assert(ppRenderTarget
, D3DERR_INVALIDCALL
);
1856 *ppRenderTarget
= (IDirect3DSurface9
*)This
->state
.rt
[i
];
1857 if (!This
->state
.rt
[i
])
1858 return D3DERR_NOTFOUND
;
1860 NineUnknown_AddRef(NineUnknown(This
->state
.rt
[i
]));
1865 NineDevice9_SetDepthStencilSurface( struct NineDevice9
*This
,
1866 IDirect3DSurface9
*pNewZStencil
)
1868 DBG("This=%p pNewZStencil=%p\n", This
, pNewZStencil
);
1870 if (This
->state
.ds
!= NineSurface9(pNewZStencil
)) {
1871 nine_bind(&This
->state
.ds
, pNewZStencil
);
1872 This
->state
.changed
.group
|= NINE_STATE_FB
;
1878 NineDevice9_GetDepthStencilSurface( struct NineDevice9
*This
,
1879 IDirect3DSurface9
**ppZStencilSurface
)
1881 user_assert(ppZStencilSurface
, D3DERR_INVALIDCALL
);
1883 *ppZStencilSurface
= (IDirect3DSurface9
*)This
->state
.ds
;
1884 if (!This
->state
.ds
)
1885 return D3DERR_NOTFOUND
;
1887 NineUnknown_AddRef(NineUnknown(This
->state
.ds
));
1892 NineDevice9_BeginScene( struct NineDevice9
*This
)
1894 DBG("This=%p\n", This
);
1895 user_assert(!This
->in_scene
, D3DERR_INVALIDCALL
);
1896 This
->in_scene
= TRUE
;
1897 /* Do we want to do anything else here ? */
1902 NineDevice9_EndScene( struct NineDevice9
*This
)
1904 DBG("This=%p\n", This
);
1905 user_assert(This
->in_scene
, D3DERR_INVALIDCALL
);
1906 This
->in_scene
= FALSE
;
1911 NineDevice9_Clear( struct NineDevice9
*This
,
1913 const D3DRECT
*pRects
,
1919 const int sRGB
= This
->state
.rs
[D3DRS_SRGBWRITEENABLE
] ? 1 : 0;
1920 struct pipe_surface
*cbuf
, *zsbuf
;
1921 struct pipe_context
*pipe
= This
->pipe
;
1922 struct NineSurface9
*zsbuf_surf
= This
->state
.ds
;
1923 struct NineSurface9
*rt
;
1926 union pipe_color_union rgba
;
1927 unsigned rt_mask
= 0;
1930 DBG("This=%p Count=%u pRects=%p Flags=%x Color=%08x Z=%f Stencil=%x\n",
1931 This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1933 user_assert(This
->state
.ds
|| !(Flags
& NINED3DCLEAR_DEPTHSTENCIL
),
1934 D3DERR_INVALIDCALL
);
1935 user_assert(!(Flags
& D3DCLEAR_STENCIL
) ||
1937 util_format_is_depth_and_stencil(zsbuf_surf
->base
.info
.format
)),
1938 D3DERR_INVALIDCALL
);
1940 user_assert((Count
&& pRects
) || (!Count
&& !pRects
), D3DERR_INVALIDCALL
);
1942 user_warn((pRects
&& !Count
) || (!pRects
&& Count
));
1943 if (pRects
&& !Count
)
1949 nine_update_state_framebuffer_clear(This
);
1951 if (Flags
& D3DCLEAR_TARGET
) bufs
|= PIPE_CLEAR_COLOR
;
1952 /* Ignore Z buffer if not bound */
1953 if (This
->state
.fb
.zsbuf
!= NULL
) {
1954 if (Flags
& D3DCLEAR_ZBUFFER
) bufs
|= PIPE_CLEAR_DEPTH
;
1955 if (Flags
& D3DCLEAR_STENCIL
) bufs
|= PIPE_CLEAR_STENCIL
;
1959 d3dcolor_to_pipe_color_union(&rgba
, Color
);
1961 rect
.x1
= This
->state
.viewport
.X
;
1962 rect
.y1
= This
->state
.viewport
.Y
;
1963 rect
.x2
= This
->state
.viewport
.Width
+ rect
.x1
;
1964 rect
.y2
= This
->state
.viewport
.Height
+ rect
.y1
;
1966 /* Both rectangles apply, which is weird, but that's D3D9. */
1967 if (This
->state
.rs
[D3DRS_SCISSORTESTENABLE
]) {
1968 rect
.x1
= MAX2(rect
.x1
, This
->state
.scissor
.minx
);
1969 rect
.y1
= MAX2(rect
.y1
, This
->state
.scissor
.miny
);
1970 rect
.x2
= MIN2(rect
.x2
, This
->state
.scissor
.maxx
);
1971 rect
.y2
= MIN2(rect
.y2
, This
->state
.scissor
.maxy
);
1975 /* Maybe apps like to specify a large rect ? */
1976 if (pRects
[0].x1
<= rect
.x1
&& pRects
[0].x2
>= rect
.x2
&&
1977 pRects
[0].y1
<= rect
.y1
&& pRects
[0].y2
>= rect
.y2
) {
1978 DBG("First rect covers viewport.\n");
1984 if (rect
.x1
>= This
->state
.fb
.width
|| rect
.y1
>= This
->state
.fb
.height
)
1987 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
1988 if (This
->state
.rt
[i
] && This
->state
.rt
[i
]->desc
.Format
!= D3DFMT_NULL
)
1992 /* fast path, clears everything at once */
1994 (!(bufs
& PIPE_CLEAR_COLOR
) || (rt_mask
== This
->state
.rt_mask
)) &&
1995 rect
.x1
== 0 && rect
.y1
== 0 &&
1996 /* Case we clear only render target. Check clear region vs rt. */
1997 ((!(bufs
& (PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
)) &&
1998 rect
.x2
>= This
->state
.fb
.width
&&
1999 rect
.y2
>= This
->state
.fb
.height
) ||
2000 /* Case we clear depth buffer (and eventually rt too).
2001 * depth buffer size is always >= rt size. Compare to clear region */
2002 ((bufs
& (PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
)) &&
2003 rect
.x2
>= zsbuf_surf
->desc
.Width
&&
2004 rect
.y2
>= zsbuf_surf
->desc
.Height
))) {
2005 DBG("Clear fast path\n");
2006 pipe
->clear(pipe
, bufs
, &rgba
, Z
, Stencil
);
2015 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2016 rt
= This
->state
.rt
[i
];
2017 if (!rt
|| rt
->desc
.Format
== D3DFMT_NULL
||
2018 !(bufs
& PIPE_CLEAR_COLOR
))
2019 continue; /* save space, compiler should hoist this */
2020 cbuf
= NineSurface9_GetSurface(rt
, sRGB
);
2021 for (r
= 0; r
< Count
; ++r
) {
2022 /* Don't trust users to pass these in the right order. */
2023 unsigned x1
= MIN2(pRects
[r
].x1
, pRects
[r
].x2
);
2024 unsigned y1
= MIN2(pRects
[r
].y1
, pRects
[r
].y2
);
2025 unsigned x2
= MAX2(pRects
[r
].x1
, pRects
[r
].x2
);
2026 unsigned y2
= MAX2(pRects
[r
].y1
, pRects
[r
].y2
);
2028 /* Drop negative rectangles (like wine expects). */
2029 if (pRects
[r
].x1
> pRects
[r
].x2
) continue;
2030 if (pRects
[r
].y1
> pRects
[r
].y2
) continue;
2033 x1
= MAX2(x1
, rect
.x1
);
2034 y1
= MAX2(y1
, rect
.y1
);
2035 x2
= MIN3(x2
, rect
.x2
, rt
->desc
.Width
);
2036 y2
= MIN3(y2
, rect
.y2
, rt
->desc
.Height
);
2038 DBG("Clearing (%u..%u)x(%u..%u)\n", x1
, x2
, y1
, y2
);
2039 pipe
->clear_render_target(pipe
, cbuf
, &rgba
,
2040 x1
, y1
, x2
- x1
, y2
- y1
, false);
2043 if (!(bufs
& PIPE_CLEAR_DEPTHSTENCIL
))
2046 bufs
&= PIPE_CLEAR_DEPTHSTENCIL
;
2048 for (r
= 0; r
< Count
; ++r
) {
2049 unsigned x1
= MIN2(pRects
[r
].x1
, pRects
[r
].x2
);
2050 unsigned y1
= MIN2(pRects
[r
].y1
, pRects
[r
].y2
);
2051 unsigned x2
= MAX2(pRects
[r
].x1
, pRects
[r
].x2
);
2052 unsigned y2
= MAX2(pRects
[r
].y1
, pRects
[r
].y2
);
2054 /* Drop negative rectangles. */
2055 if (pRects
[r
].x1
> pRects
[r
].x2
) continue;
2056 if (pRects
[r
].y1
> pRects
[r
].y2
) continue;
2059 x1
= MIN2(x1
, rect
.x1
);
2060 y1
= MIN2(y1
, rect
.y1
);
2061 x2
= MIN3(x2
, rect
.x2
, zsbuf_surf
->desc
.Width
);
2062 y2
= MIN3(y2
, rect
.y2
, zsbuf_surf
->desc
.Height
);
2064 zsbuf
= NineSurface9_GetSurface(zsbuf_surf
, 0);
2066 pipe
->clear_depth_stencil(pipe
, zsbuf
, bufs
, Z
, Stencil
,
2067 x1
, y1
, x2
- x1
, y2
- y1
, false);
2073 NineDevice9_SetTransform( struct NineDevice9
*This
,
2074 D3DTRANSFORMSTATETYPE State
,
2075 const D3DMATRIX
*pMatrix
)
2077 struct nine_state
*state
= This
->update
;
2078 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
2080 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2082 user_assert(M
, D3DERR_INVALIDCALL
);
2085 state
->ff
.changed
.transform
[State
/ 32] |= 1 << (State
% 32);
2086 state
->changed
.group
|= NINE_STATE_FF
;
2092 NineDevice9_GetTransform( struct NineDevice9
*This
,
2093 D3DTRANSFORMSTATETYPE State
,
2094 D3DMATRIX
*pMatrix
)
2096 D3DMATRIX
*M
= nine_state_access_transform(&This
->state
, State
, FALSE
);
2097 user_assert(M
, D3DERR_INVALIDCALL
);
2103 NineDevice9_MultiplyTransform( struct NineDevice9
*This
,
2104 D3DTRANSFORMSTATETYPE State
,
2105 const D3DMATRIX
*pMatrix
)
2107 struct nine_state
*state
= This
->update
;
2109 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
2111 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2113 user_assert(M
, D3DERR_INVALIDCALL
);
2115 nine_d3d_matrix_matrix_mul(&T
, pMatrix
, M
);
2116 return NineDevice9_SetTransform(This
, State
, &T
);
2120 NineDevice9_SetViewport( struct NineDevice9
*This
,
2121 const D3DVIEWPORT9
*pViewport
)
2123 struct nine_state
*state
= This
->update
;
2125 DBG("X=%u Y=%u W=%u H=%u MinZ=%f MaxZ=%f\n",
2126 pViewport
->X
, pViewport
->Y
, pViewport
->Width
, pViewport
->Height
,
2127 pViewport
->MinZ
, pViewport
->MaxZ
);
2129 state
->viewport
= *pViewport
;
2130 state
->changed
.group
|= NINE_STATE_VIEWPORT
;
2136 NineDevice9_GetViewport( struct NineDevice9
*This
,
2137 D3DVIEWPORT9
*pViewport
)
2139 *pViewport
= This
->state
.viewport
;
2144 NineDevice9_SetMaterial( struct NineDevice9
*This
,
2145 const D3DMATERIAL9
*pMaterial
)
2147 struct nine_state
*state
= This
->update
;
2149 DBG("This=%p pMaterial=%p\n", This
, pMaterial
);
2151 nine_dump_D3DMATERIAL9(DBG_FF
, pMaterial
);
2153 user_assert(pMaterial
, E_POINTER
);
2155 state
->ff
.material
= *pMaterial
;
2156 state
->changed
.group
|= NINE_STATE_FF_MATERIAL
;
2162 NineDevice9_GetMaterial( struct NineDevice9
*This
,
2163 D3DMATERIAL9
*pMaterial
)
2165 user_assert(pMaterial
, E_POINTER
);
2166 *pMaterial
= This
->state
.ff
.material
;
2171 NineDevice9_SetLight( struct NineDevice9
*This
,
2173 const D3DLIGHT9
*pLight
)
2175 struct nine_state
*state
= This
->update
;
2177 DBG("This=%p Index=%u pLight=%p\n", This
, Index
, pLight
);
2179 nine_dump_D3DLIGHT9(DBG_FF
, pLight
);
2181 user_assert(pLight
, D3DERR_INVALIDCALL
);
2182 user_assert(pLight
->Type
< NINED3DLIGHT_INVALID
, D3DERR_INVALIDCALL
);
2184 user_assert(Index
< NINE_MAX_LIGHTS
, D3DERR_INVALIDCALL
); /* sanity */
2186 if (Index
>= state
->ff
.num_lights
) {
2187 unsigned n
= state
->ff
.num_lights
;
2188 unsigned N
= Index
+ 1;
2190 state
->ff
.light
= REALLOC(state
->ff
.light
, n
* sizeof(D3DLIGHT9
),
2191 N
* sizeof(D3DLIGHT9
));
2192 if (!state
->ff
.light
)
2193 return E_OUTOFMEMORY
;
2194 state
->ff
.num_lights
= N
;
2196 for (; n
< Index
; ++n
) {
2197 memset(&state
->ff
.light
[n
], 0, sizeof(D3DLIGHT9
));
2198 state
->ff
.light
[n
].Type
= (D3DLIGHTTYPE
)NINED3DLIGHT_INVALID
;
2201 state
->ff
.light
[Index
] = *pLight
;
2203 if (pLight
->Type
== D3DLIGHT_SPOT
&& pLight
->Theta
>= pLight
->Phi
) {
2204 DBG("Warning: clamping D3DLIGHT9.Theta\n");
2205 state
->ff
.light
[Index
].Theta
= state
->ff
.light
[Index
].Phi
;
2207 if (pLight
->Type
!= D3DLIGHT_DIRECTIONAL
&&
2208 pLight
->Attenuation0
== 0.0f
&&
2209 pLight
->Attenuation1
== 0.0f
&&
2210 pLight
->Attenuation2
== 0.0f
) {
2211 DBG("Warning: all D3DLIGHT9.Attenuation[i] are 0\n");
2214 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2220 NineDevice9_GetLight( struct NineDevice9
*This
,
2224 const struct nine_state
*state
= &This
->state
;
2226 user_assert(pLight
, D3DERR_INVALIDCALL
);
2227 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2228 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2229 D3DERR_INVALIDCALL
);
2231 *pLight
= state
->ff
.light
[Index
];
2237 NineDevice9_LightEnable( struct NineDevice9
*This
,
2241 struct nine_state
*state
= This
->update
;
2244 DBG("This=%p Index=%u Enable=%i\n", This
, Index
, Enable
);
2246 if (Index
>= state
->ff
.num_lights
||
2247 state
->ff
.light
[Index
].Type
== NINED3DLIGHT_INVALID
) {
2248 /* This should create a default light. */
2250 memset(&light
, 0, sizeof(light
));
2251 light
.Type
= D3DLIGHT_DIRECTIONAL
;
2252 light
.Diffuse
.r
= 1.0f
;
2253 light
.Diffuse
.g
= 1.0f
;
2254 light
.Diffuse
.b
= 1.0f
;
2255 light
.Direction
.z
= 1.0f
;
2256 NineDevice9_SetLight(This
, Index
, &light
);
2258 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2260 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
) {
2261 if (state
->ff
.active_light
[i
] == Index
)
2266 if (i
< state
->ff
.num_lights_active
)
2268 /* XXX wine thinks this should still succeed:
2270 user_assert(i
< NINE_MAX_LIGHTS_ACTIVE
, D3DERR_INVALIDCALL
);
2272 state
->ff
.active_light
[i
] = Index
;
2273 state
->ff
.num_lights_active
++;
2275 if (i
== state
->ff
.num_lights_active
)
2277 --state
->ff
.num_lights_active
;
2278 for (; i
< state
->ff
.num_lights_active
; ++i
)
2279 state
->ff
.active_light
[i
] = state
->ff
.active_light
[i
+ 1];
2281 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2287 NineDevice9_GetLightEnable( struct NineDevice9
*This
,
2291 const struct nine_state
*state
= &This
->state
;
2294 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2295 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2296 D3DERR_INVALIDCALL
);
2298 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
)
2299 if (state
->ff
.active_light
[i
] == Index
)
2302 *pEnable
= i
!= state
->ff
.num_lights_active
? 128 : 0; // Taken from wine
2308 NineDevice9_SetClipPlane( struct NineDevice9
*This
,
2310 const float *pPlane
)
2312 struct nine_state
*state
= This
->update
;
2314 user_assert(pPlane
, D3DERR_INVALIDCALL
);
2316 DBG("This=%p Index=%u pPlane=%f %f %f %f\n", This
, Index
,
2317 pPlane
[0], pPlane
[1],
2318 pPlane
[2], pPlane
[3]);
2320 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2322 memcpy(&state
->clip
.ucp
[Index
][0], pPlane
, sizeof(state
->clip
.ucp
[0]));
2323 state
->changed
.ucp
|= 1 << Index
;
2329 NineDevice9_GetClipPlane( struct NineDevice9
*This
,
2333 const struct nine_state
*state
= &This
->state
;
2335 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2337 memcpy(pPlane
, &state
->clip
.ucp
[Index
][0], sizeof(state
->clip
.ucp
[0]));
2341 #define RESZ_CODE 0x7fa05000
2344 NineDevice9_ResolveZ( struct NineDevice9
*This
)
2346 struct nine_state
*state
= &This
->state
;
2347 const struct util_format_description
*desc
;
2348 struct NineSurface9
*source
= state
->ds
;
2349 struct NineBaseTexture9
*destination
= state
->texture
[0];
2350 struct pipe_resource
*src
, *dst
;
2351 struct pipe_blit_info blit
;
2353 DBG("RESZ resolve\n");
2355 user_assert(source
&& destination
&&
2356 destination
->base
.type
== D3DRTYPE_TEXTURE
, D3DERR_INVALIDCALL
);
2358 src
= source
->base
.resource
;
2359 dst
= destination
->base
.resource
;
2361 user_assert(src
&& dst
, D3DERR_INVALIDCALL
);
2363 /* check dst is depth format. we know already for src */
2364 desc
= util_format_description(dst
->format
);
2365 user_assert(desc
->colorspace
== UTIL_FORMAT_COLORSPACE_ZS
, D3DERR_INVALIDCALL
);
2367 memset(&blit
, 0, sizeof(blit
));
2368 blit
.src
.resource
= src
;
2370 blit
.src
.format
= src
->format
;
2372 blit
.src
.box
.depth
= 1;
2375 blit
.src
.box
.width
= src
->width0
;
2376 blit
.src
.box
.height
= src
->height0
;
2378 blit
.dst
.resource
= dst
;
2380 blit
.dst
.format
= dst
->format
;
2382 blit
.dst
.box
.depth
= 1;
2385 blit
.dst
.box
.width
= dst
->width0
;
2386 blit
.dst
.box
.height
= dst
->height0
;
2388 blit
.mask
= PIPE_MASK_ZS
;
2389 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
2390 blit
.scissor_enable
= FALSE
;
2392 This
->pipe
->blit(This
->pipe
, &blit
);
2396 #define ALPHA_TO_COVERAGE_ENABLE MAKEFOURCC('A', '2', 'M', '1')
2397 #define ALPHA_TO_COVERAGE_DISABLE MAKEFOURCC('A', '2', 'M', '0')
2400 NineDevice9_SetRenderState( struct NineDevice9
*This
,
2401 D3DRENDERSTATETYPE State
,
2404 struct nine_state
*state
= This
->update
;
2406 DBG("This=%p State=%u(%s) Value=%08x\n", This
,
2407 State
, nine_d3drs_to_string(State
), Value
);
2409 user_assert(State
< D3DRS_COUNT
, D3DERR_INVALIDCALL
);
2411 if (state
->rs_advertised
[State
] == Value
&& likely(!This
->is_recording
))
2414 state
->rs_advertised
[State
] = Value
;
2416 /* Amd hacks (equivalent to GL extensions) */
2417 if (unlikely(State
== D3DRS_POINTSIZE
)) {
2418 if (Value
== RESZ_CODE
)
2419 return NineDevice9_ResolveZ(This
);
2421 if (Value
== ALPHA_TO_COVERAGE_ENABLE
||
2422 Value
== ALPHA_TO_COVERAGE_DISABLE
) {
2423 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
== ALPHA_TO_COVERAGE_ENABLE
);
2424 state
->changed
.group
|= NINE_STATE_BLEND
;
2430 if (unlikely(State
== D3DRS_ADAPTIVETESS_Y
)) {
2431 if (Value
== D3DFMT_ATOC
|| (Value
== D3DFMT_UNKNOWN
&& state
->rs
[NINED3DRS_ALPHACOVERAGE
])) {
2432 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
== D3DFMT_ATOC
) ? 3 : 0;
2433 state
->rs
[NINED3DRS_ALPHACOVERAGE
] &= state
->rs
[D3DRS_ALPHATESTENABLE
] ? 3 : 2;
2434 state
->changed
.group
|= NINE_STATE_BLEND
;
2438 if (unlikely(State
== D3DRS_ALPHATESTENABLE
&& (state
->rs
[NINED3DRS_ALPHACOVERAGE
] & 2))) {
2439 DWORD alphacoverage_prev
= state
->rs
[NINED3DRS_ALPHACOVERAGE
];
2440 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
? 3 : 2);
2441 if (state
->rs
[NINED3DRS_ALPHACOVERAGE
] != alphacoverage_prev
)
2442 state
->changed
.group
|= NINE_STATE_BLEND
;
2445 state
->rs
[State
] = nine_fix_render_state_value(State
, Value
);
2446 state
->changed
.rs
[State
/ 32] |= 1 << (State
% 32);
2447 state
->changed
.group
|= nine_render_state_group
[State
];
2453 NineDevice9_GetRenderState( struct NineDevice9
*This
,
2454 D3DRENDERSTATETYPE State
,
2457 user_assert(State
< D3DRS_COUNT
, D3DERR_INVALIDCALL
);
2459 *pValue
= This
->state
.rs_advertised
[State
];
2464 NineDevice9_CreateStateBlock( struct NineDevice9
*This
,
2465 D3DSTATEBLOCKTYPE Type
,
2466 IDirect3DStateBlock9
**ppSB
)
2468 struct NineStateBlock9
*nsb
;
2469 struct nine_state
*dst
;
2471 enum nine_stateblock_type type
;
2474 DBG("This=%p Type=%u ppSB=%p\n", This
, Type
, ppSB
);
2476 user_assert(Type
== D3DSBT_ALL
||
2477 Type
== D3DSBT_VERTEXSTATE
||
2478 Type
== D3DSBT_PIXELSTATE
, D3DERR_INVALIDCALL
);
2481 case D3DSBT_VERTEXSTATE
: type
= NINESBT_VERTEXSTATE
; break;
2482 case D3DSBT_PIXELSTATE
: type
= NINESBT_PIXELSTATE
; break;
2488 hr
= NineStateBlock9_new(This
, &nsb
, type
);
2491 *ppSB
= (IDirect3DStateBlock9
*)nsb
;
2494 dst
->changed
.group
=
2495 NINE_STATE_TEXTURE
|
2498 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_VERTEXSTATE
) {
2499 dst
->changed
.group
|=
2500 NINE_STATE_FF_LIGHTING
|
2501 NINE_STATE_VS
| NINE_STATE_VS_CONST
|
2503 /* TODO: texture/sampler state */
2504 memcpy(dst
->changed
.rs
,
2505 nine_render_states_vertex
, sizeof(dst
->changed
.rs
));
2506 nine_ranges_insert(&dst
->changed
.vs_const_f
, 0, This
->max_vs_const_f
,
2508 dst
->changed
.vs_const_i
= 0xffff;
2509 dst
->changed
.vs_const_b
= 0xffff;
2510 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2511 dst
->changed
.sampler
[s
] |= 1 << D3DSAMP_DMAPOFFSET
;
2512 if (This
->state
.ff
.num_lights
) {
2513 dst
->ff
.num_lights
= This
->state
.ff
.num_lights
;
2514 /* zero'd -> light type won't be NINED3DLIGHT_INVALID, so
2515 * all currently existing lights will be captured
2517 dst
->ff
.light
= CALLOC(This
->state
.ff
.num_lights
,
2519 if (!dst
->ff
.light
) {
2520 nine_bind(ppSB
, NULL
);
2521 return E_OUTOFMEMORY
;
2525 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_PIXELSTATE
) {
2526 dst
->changed
.group
|=
2527 NINE_STATE_PS
| NINE_STATE_PS_CONST
;
2528 /* TODO: texture/sampler state */
2529 memcpy(dst
->changed
.rs
,
2530 nine_render_states_pixel
, sizeof(dst
->changed
.rs
));
2531 nine_ranges_insert(&dst
->changed
.ps_const_f
, 0, This
->max_ps_const_f
,
2533 dst
->changed
.ps_const_i
= 0xffff;
2534 dst
->changed
.ps_const_b
= 0xffff;
2535 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2536 dst
->changed
.sampler
[s
] |= 0x1ffe;
2538 if (Type
== D3DSBT_ALL
) {
2539 dst
->changed
.group
|=
2540 NINE_STATE_VIEWPORT
|
2541 NINE_STATE_SCISSOR
|
2542 NINE_STATE_RASTERIZER
|
2546 NINE_STATE_MATERIAL
|
2547 NINE_STATE_BLEND_COLOR
|
2548 NINE_STATE_SAMPLE_MASK
;
2549 memset(dst
->changed
.rs
, ~0, (D3DRS_COUNT
/ 32) * sizeof(uint32_t));
2550 dst
->changed
.rs
[D3DRS_LAST
/ 32] |= (1 << (D3DRS_COUNT
% 32)) - 1;
2551 dst
->changed
.vtxbuf
= (1ULL << This
->caps
.MaxStreams
) - 1;
2552 dst
->changed
.stream_freq
= dst
->changed
.vtxbuf
;
2553 dst
->changed
.ucp
= (1 << PIPE_MAX_CLIP_PLANES
) - 1;
2554 dst
->changed
.texture
= (1 << NINE_MAX_SAMPLERS
) - 1;
2556 NineStateBlock9_Capture(NineStateBlock9(*ppSB
));
2558 /* TODO: fixed function state */
2564 NineDevice9_BeginStateBlock( struct NineDevice9
*This
)
2568 DBG("This=%p\n", This
);
2570 user_assert(!This
->record
, D3DERR_INVALIDCALL
);
2572 hr
= NineStateBlock9_new(This
, &This
->record
, NINESBT_CUSTOM
);
2575 NineUnknown_ConvertRefToBind(NineUnknown(This
->record
));
2577 This
->update
= &This
->record
->state
;
2578 This
->is_recording
= TRUE
;
2584 NineDevice9_EndStateBlock( struct NineDevice9
*This
,
2585 IDirect3DStateBlock9
**ppSB
)
2587 DBG("This=%p ppSB=%p\n", This
, ppSB
);
2589 user_assert(This
->record
, D3DERR_INVALIDCALL
);
2591 This
->update
= &This
->state
;
2592 This
->is_recording
= FALSE
;
2594 NineUnknown_AddRef(NineUnknown(This
->record
));
2595 *ppSB
= (IDirect3DStateBlock9
*)This
->record
;
2596 NineUnknown_Unbind(NineUnknown(This
->record
));
2597 This
->record
= NULL
;
2603 NineDevice9_SetClipStatus( struct NineDevice9
*This
,
2604 const D3DCLIPSTATUS9
*pClipStatus
)
2606 STUB(D3DERR_INVALIDCALL
);
2610 NineDevice9_GetClipStatus( struct NineDevice9
*This
,
2611 D3DCLIPSTATUS9
*pClipStatus
)
2613 STUB(D3DERR_INVALIDCALL
);
2617 NineDevice9_GetTexture( struct NineDevice9
*This
,
2619 IDirect3DBaseTexture9
**ppTexture
)
2621 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2622 Stage
== D3DDMAPSAMPLER
||
2623 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2624 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2625 user_assert(ppTexture
, D3DERR_INVALIDCALL
);
2627 if (Stage
>= D3DDMAPSAMPLER
)
2628 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2630 *ppTexture
= (IDirect3DBaseTexture9
*)This
->state
.texture
[Stage
];
2632 if (This
->state
.texture
[Stage
])
2633 NineUnknown_AddRef(NineUnknown(This
->state
.texture
[Stage
]));
2638 NineDevice9_SetTexture( struct NineDevice9
*This
,
2640 IDirect3DBaseTexture9
*pTexture
)
2642 struct nine_state
*state
= This
->update
;
2643 struct NineBaseTexture9
*tex
= NineBaseTexture9(pTexture
);
2645 DBG("This=%p Stage=%u pTexture=%p\n", This
, Stage
, pTexture
);
2647 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2648 Stage
== D3DDMAPSAMPLER
||
2649 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2650 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2651 user_assert(!tex
|| (tex
->base
.pool
!= D3DPOOL_SCRATCH
&&
2652 tex
->base
.pool
!= D3DPOOL_SYSTEMMEM
), D3DERR_INVALIDCALL
);
2654 if (Stage
>= D3DDMAPSAMPLER
)
2655 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2657 if (!This
->is_recording
) {
2658 struct NineBaseTexture9
*old
= state
->texture
[Stage
];
2662 state
->samplers_shadow
&= ~(1 << Stage
);
2664 state
->samplers_shadow
|= tex
->shadow
<< Stage
;
2666 if ((tex
->managed
.dirty
| tex
->dirty_mip
) && LIST_IS_EMPTY(&tex
->list
))
2667 list_add(&tex
->list
, &This
->update_textures
);
2674 nine_bind(&state
->texture
[Stage
], pTexture
);
2676 state
->changed
.texture
|= 1 << Stage
;
2677 state
->changed
.group
|= NINE_STATE_TEXTURE
;
2683 NineDevice9_GetTextureStageState( struct NineDevice9
*This
,
2685 D3DTEXTURESTAGESTATETYPE Type
,
2688 const struct nine_state
*state
= &This
->state
;
2690 user_assert(Stage
< ARRAY_SIZE(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2691 user_assert(Type
< ARRAY_SIZE(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2693 *pValue
= state
->ff
.tex_stage
[Stage
][Type
];
2699 NineDevice9_SetTextureStageState( struct NineDevice9
*This
,
2701 D3DTEXTURESTAGESTATETYPE Type
,
2704 struct nine_state
*state
= This
->update
;
2705 int bumpmap_index
= -1;
2707 DBG("Stage=%u Type=%u Value=%08x\n", Stage
, Type
, Value
);
2708 nine_dump_D3DTSS_value(DBG_FF
, Type
, Value
);
2710 user_assert(Stage
< ARRAY_SIZE(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2711 user_assert(Type
< ARRAY_SIZE(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2713 state
->ff
.tex_stage
[Stage
][Type
] = Value
;
2715 case D3DTSS_BUMPENVMAT00
:
2716 bumpmap_index
= 4 * Stage
;
2718 case D3DTSS_BUMPENVMAT10
:
2719 bumpmap_index
= 4 * Stage
+ 1;
2721 case D3DTSS_BUMPENVMAT01
:
2722 bumpmap_index
= 4 * Stage
+ 2;
2724 case D3DTSS_BUMPENVMAT11
:
2725 bumpmap_index
= 4 * Stage
+ 3;
2727 case D3DTSS_BUMPENVLSCALE
:
2728 bumpmap_index
= 4 * 8 + 2 * Stage
;
2730 case D3DTSS_BUMPENVLOFFSET
:
2731 bumpmap_index
= 4 * 8 + 2 * Stage
+ 1;
2733 case D3DTSS_TEXTURETRANSFORMFLAGS
:
2734 state
->changed
.group
|= NINE_STATE_PS1X_SHADER
;
2740 if (bumpmap_index
>= 0) {
2741 state
->bumpmap_vars
[bumpmap_index
] = Value
;
2742 state
->changed
.group
|= NINE_STATE_PS_CONST
;
2745 state
->changed
.group
|= NINE_STATE_FF_PSSTAGES
;
2746 state
->ff
.changed
.tex_stage
[Stage
][Type
/ 32] |= 1 << (Type
% 32);
2752 NineDevice9_GetSamplerState( struct NineDevice9
*This
,
2754 D3DSAMPLERSTATETYPE Type
,
2757 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2758 Sampler
== D3DDMAPSAMPLER
||
2759 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2760 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2762 if (Sampler
>= D3DDMAPSAMPLER
)
2763 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2765 *pValue
= This
->state
.samp
[Sampler
][Type
];
2770 NineDevice9_SetSamplerState( struct NineDevice9
*This
,
2772 D3DSAMPLERSTATETYPE Type
,
2775 struct nine_state
*state
= This
->update
;
2777 DBG("This=%p Sampler=%u Type=%s Value=%08x\n", This
,
2778 Sampler
, nine_D3DSAMP_to_str(Type
), Value
);
2780 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2781 Sampler
== D3DDMAPSAMPLER
||
2782 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2783 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2785 if (Sampler
>= D3DDMAPSAMPLER
)
2786 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2788 if (state
->samp
[Sampler
][Type
] != Value
|| unlikely(This
->is_recording
)) {
2789 state
->samp
[Sampler
][Type
] = Value
;
2790 state
->changed
.group
|= NINE_STATE_SAMPLER
;
2791 state
->changed
.sampler
[Sampler
] |= 1 << Type
;
2798 NineDevice9_ValidateDevice( struct NineDevice9
*This
,
2801 const struct nine_state
*state
= &This
->state
;
2803 unsigned w
= 0, h
= 0;
2805 DBG("This=%p pNumPasses=%p\n", This
, pNumPasses
);
2807 for (i
= 0; i
< ARRAY_SIZE(state
->samp
); ++i
) {
2808 if (state
->samp
[i
][D3DSAMP_MINFILTER
] == D3DTEXF_NONE
||
2809 state
->samp
[i
][D3DSAMP_MAGFILTER
] == D3DTEXF_NONE
)
2810 return D3DERR_UNSUPPORTEDTEXTUREFILTER
;
2813 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2817 w
= state
->rt
[i
]->desc
.Width
;
2818 h
= state
->rt
[i
]->desc
.Height
;
2820 if (state
->rt
[i
]->desc
.Width
!= w
|| state
->rt
[i
]->desc
.Height
!= h
) {
2821 return D3DERR_CONFLICTINGRENDERSTATE
;
2825 (state
->rs
[D3DRS_ZENABLE
] || state
->rs
[D3DRS_STENCILENABLE
])) {
2827 (state
->ds
->desc
.Width
!= w
|| state
->ds
->desc
.Height
!= h
))
2828 return D3DERR_CONFLICTINGRENDERSTATE
;
2838 NineDevice9_SetPaletteEntries( struct NineDevice9
*This
,
2840 const PALETTEENTRY
*pEntries
)
2842 STUB(D3D_OK
); /* like wine */
2846 NineDevice9_GetPaletteEntries( struct NineDevice9
*This
,
2848 PALETTEENTRY
*pEntries
)
2850 STUB(D3DERR_INVALIDCALL
);
2854 NineDevice9_SetCurrentTexturePalette( struct NineDevice9
*This
,
2855 UINT PaletteNumber
)
2857 STUB(D3D_OK
); /* like wine */
2861 NineDevice9_GetCurrentTexturePalette( struct NineDevice9
*This
,
2862 UINT
*PaletteNumber
)
2864 STUB(D3DERR_INVALIDCALL
);
2868 NineDevice9_SetScissorRect( struct NineDevice9
*This
,
2871 struct nine_state
*state
= This
->update
;
2873 DBG("x=(%u..%u) y=(%u..%u)\n",
2874 pRect
->left
, pRect
->top
, pRect
->right
, pRect
->bottom
);
2876 state
->scissor
.minx
= pRect
->left
;
2877 state
->scissor
.miny
= pRect
->top
;
2878 state
->scissor
.maxx
= pRect
->right
;
2879 state
->scissor
.maxy
= pRect
->bottom
;
2881 state
->changed
.group
|= NINE_STATE_SCISSOR
;
2887 NineDevice9_GetScissorRect( struct NineDevice9
*This
,
2890 pRect
->left
= This
->state
.scissor
.minx
;
2891 pRect
->top
= This
->state
.scissor
.miny
;
2892 pRect
->right
= This
->state
.scissor
.maxx
;
2893 pRect
->bottom
= This
->state
.scissor
.maxy
;
2899 NineDevice9_SetSoftwareVertexProcessing( struct NineDevice9
*This
,
2902 STUB(D3DERR_INVALIDCALL
);
2906 NineDevice9_GetSoftwareVertexProcessing( struct NineDevice9
*This
)
2908 return !!(This
->params
.BehaviorFlags
& D3DCREATE_SOFTWARE_VERTEXPROCESSING
);
2912 NineDevice9_SetNPatchMode( struct NineDevice9
*This
,
2915 STUB(D3DERR_INVALIDCALL
);
2919 NineDevice9_GetNPatchMode( struct NineDevice9
*This
)
2925 init_draw_info(struct pipe_draw_info
*info
,
2926 struct NineDevice9
*dev
, D3DPRIMITIVETYPE type
, UINT count
)
2928 info
->mode
= d3dprimitivetype_to_pipe_prim(type
);
2929 info
->count
= prim_count_to_vertex_count(type
, count
);
2930 info
->start_instance
= 0;
2931 info
->instance_count
= 1;
2932 if (dev
->state
.stream_instancedata_mask
& dev
->state
.stream_usage_mask
)
2933 info
->instance_count
= MAX2(dev
->state
.stream_freq
[0] & 0x7FFFFF, 1);
2934 info
->primitive_restart
= FALSE
;
2935 info
->restart_index
= 0;
2936 info
->count_from_stream_output
= NULL
;
2937 info
->indirect
= NULL
;
2938 info
->indirect_params
= NULL
;
2942 NineDevice9_DrawPrimitive( struct NineDevice9
*This
,
2943 D3DPRIMITIVETYPE PrimitiveType
,
2945 UINT PrimitiveCount
)
2947 struct pipe_draw_info info
;
2949 DBG("iface %p, PrimitiveType %u, StartVertex %u, PrimitiveCount %u\n",
2950 This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2952 nine_update_state(This
);
2954 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2955 info
.indexed
= FALSE
;
2956 info
.start
= StartVertex
;
2957 info
.index_bias
= 0;
2958 info
.min_index
= info
.start
;
2959 info
.max_index
= info
.count
- 1;
2961 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2967 NineDevice9_DrawIndexedPrimitive( struct NineDevice9
*This
,
2968 D3DPRIMITIVETYPE PrimitiveType
,
2969 INT BaseVertexIndex
,
2970 UINT MinVertexIndex
,
2973 UINT PrimitiveCount
)
2975 struct pipe_draw_info info
;
2977 DBG("iface %p, PrimitiveType %u, BaseVertexIndex %u, MinVertexIndex %u "
2978 "NumVertices %u, StartIndex %u, PrimitiveCount %u\n",
2979 This
, PrimitiveType
, BaseVertexIndex
, MinVertexIndex
, NumVertices
,
2980 StartIndex
, PrimitiveCount
);
2982 user_assert(This
->state
.idxbuf
, D3DERR_INVALIDCALL
);
2983 user_assert(This
->state
.vdecl
, D3DERR_INVALIDCALL
);
2985 nine_update_state(This
);
2987 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2988 info
.indexed
= TRUE
;
2989 info
.start
= StartIndex
;
2990 info
.index_bias
= BaseVertexIndex
;
2991 /* These don't include index bias: */
2992 info
.min_index
= MinVertexIndex
;
2993 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
2995 This
->pipe
->draw_vbo(This
->pipe
, &info
);
3001 NineDevice9_DrawPrimitiveUP( struct NineDevice9
*This
,
3002 D3DPRIMITIVETYPE PrimitiveType
,
3003 UINT PrimitiveCount
,
3004 const void *pVertexStreamZeroData
,
3005 UINT VertexStreamZeroStride
)
3007 struct pipe_vertex_buffer vtxbuf
;
3008 struct pipe_draw_info info
;
3010 DBG("iface %p, PrimitiveType %u, PrimitiveCount %u, data %p, stride %u\n",
3011 This
, PrimitiveType
, PrimitiveCount
,
3012 pVertexStreamZeroData
, VertexStreamZeroStride
);
3014 user_assert(pVertexStreamZeroData
&& VertexStreamZeroStride
,
3015 D3DERR_INVALIDCALL
);
3017 nine_update_state(This
);
3019 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
3020 info
.indexed
= FALSE
;
3022 info
.index_bias
= 0;
3024 info
.max_index
= info
.count
- 1;
3026 vtxbuf
.stride
= VertexStreamZeroStride
;
3027 vtxbuf
.buffer_offset
= 0;
3028 vtxbuf
.buffer
= NULL
;
3029 vtxbuf
.user_buffer
= pVertexStreamZeroData
;
3031 if (!This
->driver_caps
.user_vbufs
) {
3032 u_upload_data(This
->vertex_uploader
,
3034 (info
.max_index
+ 1) * VertexStreamZeroStride
, /* XXX */
3037 &vtxbuf
.buffer_offset
,
3039 u_upload_unmap(This
->vertex_uploader
);
3040 vtxbuf
.user_buffer
= NULL
;
3043 This
->pipe
->set_vertex_buffers(This
->pipe
, 0, 1, &vtxbuf
);
3045 This
->pipe
->draw_vbo(This
->pipe
, &info
);
3047 NineDevice9_PauseRecording(This
);
3048 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
3049 NineDevice9_ResumeRecording(This
);
3051 pipe_resource_reference(&vtxbuf
.buffer
, NULL
);
3057 NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9
*This
,
3058 D3DPRIMITIVETYPE PrimitiveType
,
3059 UINT MinVertexIndex
,
3061 UINT PrimitiveCount
,
3062 const void *pIndexData
,
3063 D3DFORMAT IndexDataFormat
,
3064 const void *pVertexStreamZeroData
,
3065 UINT VertexStreamZeroStride
)
3067 struct pipe_draw_info info
;
3068 struct pipe_vertex_buffer vbuf
;
3069 struct pipe_index_buffer ibuf
;
3071 DBG("iface %p, PrimitiveType %u, MinVertexIndex %u, NumVertices %u "
3072 "PrimitiveCount %u, pIndexData %p, IndexDataFormat %u "
3073 "pVertexStreamZeroData %p, VertexStreamZeroStride %u\n",
3074 This
, PrimitiveType
, MinVertexIndex
, NumVertices
, PrimitiveCount
,
3075 pIndexData
, IndexDataFormat
,
3076 pVertexStreamZeroData
, VertexStreamZeroStride
);
3078 user_assert(pIndexData
&& pVertexStreamZeroData
, D3DERR_INVALIDCALL
);
3079 user_assert(VertexStreamZeroStride
, D3DERR_INVALIDCALL
);
3080 user_assert(IndexDataFormat
== D3DFMT_INDEX16
||
3081 IndexDataFormat
== D3DFMT_INDEX32
, D3DERR_INVALIDCALL
);
3083 nine_update_state(This
);
3085 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
3086 info
.indexed
= TRUE
;
3088 info
.index_bias
= 0;
3089 info
.min_index
= MinVertexIndex
;
3090 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
3092 vbuf
.stride
= VertexStreamZeroStride
;
3093 vbuf
.buffer_offset
= 0;
3095 vbuf
.user_buffer
= pVertexStreamZeroData
;
3097 ibuf
.index_size
= (IndexDataFormat
== D3DFMT_INDEX16
) ? 2 : 4;
3100 ibuf
.user_buffer
= pIndexData
;
3102 if (!This
->driver_caps
.user_vbufs
) {
3103 const unsigned base
= info
.min_index
* VertexStreamZeroStride
;
3104 u_upload_data(This
->vertex_uploader
,
3107 info
.min_index
+ 1) * VertexStreamZeroStride
, /* XXX */
3109 (const uint8_t *)vbuf
.user_buffer
+ base
,
3110 &vbuf
.buffer_offset
,
3112 u_upload_unmap(This
->vertex_uploader
);
3113 /* Won't be used: */
3114 vbuf
.buffer_offset
-= base
;
3115 vbuf
.user_buffer
= NULL
;
3117 if (!This
->driver_caps
.user_ibufs
) {
3118 u_upload_data(This
->index_uploader
,
3120 info
.count
* ibuf
.index_size
,
3125 u_upload_unmap(This
->index_uploader
);
3126 ibuf
.user_buffer
= NULL
;
3129 This
->pipe
->set_vertex_buffers(This
->pipe
, 0, 1, &vbuf
);
3130 This
->pipe
->set_index_buffer(This
->pipe
, &ibuf
);
3132 This
->pipe
->draw_vbo(This
->pipe
, &info
);
3134 pipe_resource_reference(&vbuf
.buffer
, NULL
);
3135 pipe_resource_reference(&ibuf
.buffer
, NULL
);
3137 NineDevice9_PauseRecording(This
);
3138 NineDevice9_SetIndices(This
, NULL
);
3139 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
3140 NineDevice9_ResumeRecording(This
);
3145 /* TODO: Write to pDestBuffer directly if vertex declaration contains
3149 NineDevice9_ProcessVertices( struct NineDevice9
*This
,
3153 IDirect3DVertexBuffer9
*pDestBuffer
,
3154 IDirect3DVertexDeclaration9
*pVertexDecl
,
3157 struct pipe_screen
*screen
= This
->screen
;
3158 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pVertexDecl
);
3159 struct NineVertexShader9
*vs
;
3160 struct pipe_resource
*resource
;
3161 struct pipe_stream_output_target
*target
;
3162 struct pipe_draw_info draw
;
3164 unsigned buffer_offset
, buffer_size
;
3166 DBG("This=%p SrcStartIndex=%u DestIndex=%u VertexCount=%u "
3167 "pDestBuffer=%p pVertexDecl=%p Flags=%d\n",
3168 This
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
,
3169 pVertexDecl
, Flags
);
3171 if (!screen
->get_param(screen
, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
))
3172 STUB(D3DERR_INVALIDCALL
);
3174 nine_update_state(This
);
3176 /* TODO: Create shader with stream output. */
3177 STUB(D3DERR_INVALIDCALL
);
3178 struct NineVertexBuffer9
*dst
= NineVertexBuffer9(pDestBuffer
);
3180 vs
= This
->state
.vs
? This
->state
.vs
: This
->ff
.vs
;
3182 buffer_size
= VertexCount
* vs
->so
->stride
[0];
3184 struct pipe_resource templ
;
3186 templ
.target
= PIPE_BUFFER
;
3187 templ
.format
= PIPE_FORMAT_R8_UNORM
;
3188 templ
.width0
= buffer_size
;
3190 templ
.bind
= PIPE_BIND_STREAM_OUTPUT
;
3191 templ
.usage
= PIPE_USAGE_STREAM
;
3192 templ
.height0
= templ
.depth0
= templ
.array_size
= 1;
3193 templ
.last_level
= templ
.nr_samples
= 0;
3195 resource
= This
->screen
->resource_create(This
->screen
, &templ
);
3197 return E_OUTOFMEMORY
;
3200 /* SO matches vertex declaration */
3201 resource
= NineVertexBuffer9_GetResource(dst
);
3202 buffer_offset
= DestIndex
* vs
->so
->stride
[0];
3204 target
= This
->pipe
->create_stream_output_target(This
->pipe
, resource
,
3208 pipe_resource_reference(&resource
, NULL
);
3209 return D3DERR_DRIVERINTERNALERROR
;
3213 hr
= NineVertexDeclaration9_new_from_fvf(This
, dst
->desc
.FVF
, &vdecl
);
3218 init_draw_info(&draw
, This
, D3DPT_POINTLIST
, VertexCount
);
3219 draw
.instance_count
= 1;
3220 draw
.indexed
= FALSE
;
3221 draw
.start
= SrcStartIndex
;
3222 draw
.index_bias
= 0;
3223 draw
.min_index
= SrcStartIndex
;
3224 draw
.max_index
= SrcStartIndex
+ VertexCount
- 1;
3226 This
->pipe
->set_stream_output_targets(This
->pipe
, 1, &target
, 0);
3227 This
->pipe
->draw_vbo(This
->pipe
, &draw
);
3228 This
->pipe
->set_stream_output_targets(This
->pipe
, 0, NULL
, 0);
3229 This
->pipe
->stream_output_target_destroy(This
->pipe
, target
);
3231 hr
= NineVertexDeclaration9_ConvertStreamOutput(vdecl
,
3232 dst
, DestIndex
, VertexCount
,
3235 pipe_resource_reference(&resource
, NULL
);
3237 NineUnknown_Release(NineUnknown(vdecl
));
3242 NineDevice9_CreateVertexDeclaration( struct NineDevice9
*This
,
3243 const D3DVERTEXELEMENT9
*pVertexElements
,
3244 IDirect3DVertexDeclaration9
**ppDecl
)
3246 struct NineVertexDeclaration9
*vdecl
;
3248 DBG("This=%p pVertexElements=%p ppDecl=%p\n",
3249 This
, pVertexElements
, ppDecl
);
3251 HRESULT hr
= NineVertexDeclaration9_new(This
, pVertexElements
, &vdecl
);
3253 *ppDecl
= (IDirect3DVertexDeclaration9
*)vdecl
;
3259 NineDevice9_SetVertexDeclaration( struct NineDevice9
*This
,
3260 IDirect3DVertexDeclaration9
*pDecl
)
3262 struct nine_state
*state
= This
->update
;
3263 BOOL was_programmable_vs
= This
->state
.programmable_vs
;
3265 DBG("This=%p pDecl=%p\n", This
, pDecl
);
3267 if (likely(!This
->is_recording
) && state
->vdecl
== NineVertexDeclaration9(pDecl
))
3270 nine_bind(&state
->vdecl
, pDecl
);
3272 This
->state
.programmable_vs
= This
->state
.vs
&& !(This
->state
.vdecl
&& This
->state
.vdecl
->position_t
);
3273 if (likely(!This
->is_recording
) && was_programmable_vs
!= This
->state
.programmable_vs
) {
3274 state
->commit
|= NINE_STATE_COMMIT_CONST_VS
;
3275 state
->changed
.group
|= NINE_STATE_VS
;
3278 state
->changed
.group
|= NINE_STATE_VDECL
;
3284 NineDevice9_GetVertexDeclaration( struct NineDevice9
*This
,
3285 IDirect3DVertexDeclaration9
**ppDecl
)
3287 user_assert(ppDecl
, D3DERR_INVALIDCALL
);
3289 *ppDecl
= (IDirect3DVertexDeclaration9
*)This
->state
.vdecl
;
3291 NineUnknown_AddRef(NineUnknown(*ppDecl
));
3296 NineDevice9_SetFVF( struct NineDevice9
*This
,
3299 struct NineVertexDeclaration9
*vdecl
;
3302 DBG("FVF = %08x\n", FVF
);
3304 return D3D_OK
; /* like wine */
3306 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
3308 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
3312 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
3313 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
3315 return NineDevice9_SetVertexDeclaration(
3316 This
, (IDirect3DVertexDeclaration9
*)vdecl
);
3320 NineDevice9_GetFVF( struct NineDevice9
*This
,
3323 *pFVF
= This
->state
.vdecl
? This
->state
.vdecl
->fvf
: 0;
3328 NineDevice9_CreateVertexShader( struct NineDevice9
*This
,
3329 const DWORD
*pFunction
,
3330 IDirect3DVertexShader9
**ppShader
)
3332 struct NineVertexShader9
*vs
;
3335 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3337 hr
= NineVertexShader9_new(This
, &vs
, pFunction
, NULL
);
3340 *ppShader
= (IDirect3DVertexShader9
*)vs
;
3345 NineDevice9_SetVertexShader( struct NineDevice9
*This
,
3346 IDirect3DVertexShader9
*pShader
)
3348 struct nine_state
*state
= This
->update
;
3349 BOOL was_programmable_vs
= This
->state
.programmable_vs
;
3351 DBG("This=%p pShader=%p\n", This
, pShader
);
3353 if (!This
->is_recording
&& state
->vs
== (struct NineVertexShader9
*)pShader
)
3356 nine_bind(&state
->vs
, pShader
);
3358 This
->state
.programmable_vs
= This
->state
.vs
&& !(This
->state
.vdecl
&& This
->state
.vdecl
->position_t
);
3360 /* ff -> non-ff: commit back non-ff constants */
3361 if (!was_programmable_vs
&& This
->state
.programmable_vs
)
3362 state
->commit
|= NINE_STATE_COMMIT_CONST_VS
;
3364 state
->changed
.group
|= NINE_STATE_VS
;
3370 NineDevice9_GetVertexShader( struct NineDevice9
*This
,
3371 IDirect3DVertexShader9
**ppShader
)
3373 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3374 nine_reference_set(ppShader
, This
->state
.vs
);
3379 NineDevice9_SetVertexShaderConstantF( struct NineDevice9
*This
,
3381 const float *pConstantData
,
3382 UINT Vector4fCount
)
3384 struct nine_state
*state
= This
->update
;
3386 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3387 This
, StartRegister
, pConstantData
, Vector4fCount
);
3389 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3390 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3394 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3396 if (!This
->is_recording
) {
3397 if (!memcmp(&state
->vs_const_f
[StartRegister
* 4], pConstantData
,
3398 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0])))
3402 memcpy(&state
->vs_const_f
[StartRegister
* 4],
3404 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3406 nine_ranges_insert(&state
->changed
.vs_const_f
,
3407 StartRegister
, StartRegister
+ Vector4fCount
,
3410 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3416 NineDevice9_GetVertexShaderConstantF( struct NineDevice9
*This
,
3418 float *pConstantData
,
3419 UINT Vector4fCount
)
3421 const struct nine_state
*state
= &This
->state
;
3423 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3424 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3425 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3427 memcpy(pConstantData
,
3428 &state
->vs_const_f
[StartRegister
* 4],
3429 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3435 NineDevice9_SetVertexShaderConstantI( struct NineDevice9
*This
,
3437 const int *pConstantData
,
3438 UINT Vector4iCount
)
3440 struct nine_state
*state
= This
->update
;
3443 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3444 This
, StartRegister
, pConstantData
, Vector4iCount
);
3446 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3447 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3448 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3450 if (This
->driver_caps
.vs_integer
) {
3451 if (!This
->is_recording
) {
3452 if (!memcmp(&state
->vs_const_i
[StartRegister
][0], pConstantData
,
3453 Vector4iCount
* sizeof(state
->vs_const_i
[0])))
3456 memcpy(&state
->vs_const_i
[StartRegister
][0],
3458 Vector4iCount
* sizeof(state
->vs_const_i
[0]));
3460 for (i
= 0; i
< Vector4iCount
; i
++) {
3461 state
->vs_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3462 state
->vs_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3463 state
->vs_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3464 state
->vs_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3468 state
->changed
.vs_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3469 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3475 NineDevice9_GetVertexShaderConstantI( struct NineDevice9
*This
,
3478 UINT Vector4iCount
)
3480 const struct nine_state
*state
= &This
->state
;
3483 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3484 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3485 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3487 if (This
->driver_caps
.vs_integer
) {
3488 memcpy(pConstantData
,
3489 &state
->vs_const_i
[StartRegister
][0],
3490 Vector4iCount
* sizeof(state
->vs_const_i
[0]));
3492 for (i
= 0; i
< Vector4iCount
; i
++) {
3493 pConstantData
[4*i
] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][0]);
3494 pConstantData
[4*i
+1] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][1]);
3495 pConstantData
[4*i
+2] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][2]);
3496 pConstantData
[4*i
+3] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][3]);
3504 NineDevice9_SetVertexShaderConstantB( struct NineDevice9
*This
,
3506 const BOOL
*pConstantData
,
3509 struct nine_state
*state
= This
->update
;
3511 uint32_t bool_true
= This
->driver_caps
.vs_integer
? 0xFFFFFFFF : fui(1.0f
);
3513 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3514 This
, StartRegister
, pConstantData
, BoolCount
);
3516 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3517 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3518 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3520 if (!This
->is_recording
) {
3521 bool noChange
= true;
3522 for (i
= 0; i
< BoolCount
; i
++) {
3523 if (!!state
->vs_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3530 for (i
= 0; i
< BoolCount
; i
++)
3531 state
->vs_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3533 state
->changed
.vs_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3534 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3540 NineDevice9_GetVertexShaderConstantB( struct NineDevice9
*This
,
3542 BOOL
*pConstantData
,
3545 const struct nine_state
*state
= &This
->state
;
3548 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3549 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3550 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3552 for (i
= 0; i
< BoolCount
; i
++)
3553 pConstantData
[i
] = state
->vs_const_b
[StartRegister
+ i
] != 0 ? TRUE
: FALSE
;
3559 NineDevice9_SetStreamSource( struct NineDevice9
*This
,
3561 IDirect3DVertexBuffer9
*pStreamData
,
3565 struct nine_state
*state
= This
->update
;
3566 struct NineVertexBuffer9
*pVBuf9
= NineVertexBuffer9(pStreamData
);
3567 const unsigned i
= StreamNumber
;
3569 DBG("This=%p StreamNumber=%u pStreamData=%p OffsetInBytes=%u Stride=%u\n",
3570 This
, StreamNumber
, pStreamData
, OffsetInBytes
, Stride
);
3572 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3573 user_assert(Stride
<= This
->caps
.MaxStreamStride
, D3DERR_INVALIDCALL
);
3575 if (likely(!This
->is_recording
)) {
3576 if (state
->stream
[i
] == NineVertexBuffer9(pStreamData
) &&
3577 state
->vtxbuf
[i
].stride
== Stride
&&
3578 state
->vtxbuf
[i
].buffer_offset
== OffsetInBytes
)
3581 nine_bind(&state
->stream
[i
], pStreamData
);
3583 state
->changed
.vtxbuf
|= 1 << StreamNumber
;
3586 state
->vtxbuf
[i
].stride
= Stride
;
3587 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3589 pipe_resource_reference(&state
->vtxbuf
[i
].buffer
,
3590 pStreamData
? NineVertexBuffer9_GetResource(pVBuf9
) : NULL
);
3596 NineDevice9_GetStreamSource( struct NineDevice9
*This
,
3598 IDirect3DVertexBuffer9
**ppStreamData
,
3599 UINT
*pOffsetInBytes
,
3602 const struct nine_state
*state
= &This
->state
;
3603 const unsigned i
= StreamNumber
;
3605 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3606 user_assert(ppStreamData
, D3DERR_INVALIDCALL
);
3608 nine_reference_set(ppStreamData
, state
->stream
[i
]);
3609 *pStride
= state
->vtxbuf
[i
].stride
;
3610 *pOffsetInBytes
= state
->vtxbuf
[i
].buffer_offset
;
3616 NineDevice9_SetStreamSourceFreq( struct NineDevice9
*This
,
3620 struct nine_state
*state
= This
->update
;
3621 /* const UINT freq = Setting & 0x7FFFFF; */
3623 DBG("This=%p StreamNumber=%u FrequencyParameter=0x%x\n", This
,
3624 StreamNumber
, Setting
);
3626 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3627 user_assert(StreamNumber
!= 0 || !(Setting
& D3DSTREAMSOURCE_INSTANCEDATA
),
3628 D3DERR_INVALIDCALL
);
3629 user_assert(!((Setting
& D3DSTREAMSOURCE_INSTANCEDATA
) &&
3630 (Setting
& D3DSTREAMSOURCE_INDEXEDDATA
)), D3DERR_INVALIDCALL
);
3631 user_assert(Setting
, D3DERR_INVALIDCALL
);
3633 if (likely(!This
->is_recording
) && state
->stream_freq
[StreamNumber
] == Setting
)
3636 state
->stream_freq
[StreamNumber
] = Setting
;
3638 if (Setting
& D3DSTREAMSOURCE_INSTANCEDATA
)
3639 state
->stream_instancedata_mask
|= 1 << StreamNumber
;
3641 state
->stream_instancedata_mask
&= ~(1 << StreamNumber
);
3643 state
->changed
.stream_freq
|= 1 << StreamNumber
; /* Used for stateblocks */
3644 if (StreamNumber
!= 0)
3645 state
->changed
.group
|= NINE_STATE_STREAMFREQ
;
3650 NineDevice9_GetStreamSourceFreq( struct NineDevice9
*This
,
3654 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3655 *pSetting
= This
->state
.stream_freq
[StreamNumber
];
3660 NineDevice9_SetIndices( struct NineDevice9
*This
,
3661 IDirect3DIndexBuffer9
*pIndexData
)
3663 struct nine_state
*state
= This
->update
;
3665 DBG("This=%p pIndexData=%p\n", This
, pIndexData
);
3667 if (likely(!This
->is_recording
))
3668 if (state
->idxbuf
== NineIndexBuffer9(pIndexData
))
3670 nine_bind(&state
->idxbuf
, pIndexData
);
3672 state
->changed
.group
|= NINE_STATE_IDXBUF
;
3677 /* XXX: wine/d3d9 doesn't have pBaseVertexIndex, and it doesn't make sense
3678 * here because it's an argument passed to the Draw calls.
3681 NineDevice9_GetIndices( struct NineDevice9
*This
,
3682 IDirect3DIndexBuffer9
**ppIndexData
)
3684 user_assert(ppIndexData
, D3DERR_INVALIDCALL
);
3685 nine_reference_set(ppIndexData
, This
->state
.idxbuf
);
3690 NineDevice9_CreatePixelShader( struct NineDevice9
*This
,
3691 const DWORD
*pFunction
,
3692 IDirect3DPixelShader9
**ppShader
)
3694 struct NinePixelShader9
*ps
;
3697 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3699 hr
= NinePixelShader9_new(This
, &ps
, pFunction
, NULL
);
3702 *ppShader
= (IDirect3DPixelShader9
*)ps
;
3707 NineDevice9_SetPixelShader( struct NineDevice9
*This
,
3708 IDirect3DPixelShader9
*pShader
)
3710 struct nine_state
*state
= This
->update
;
3711 unsigned old_mask
= state
->ps
? state
->ps
->rt_mask
: 1;
3714 DBG("This=%p pShader=%p\n", This
, pShader
);
3716 if (!This
->is_recording
&& state
->ps
== (struct NinePixelShader9
*)pShader
)
3719 /* ff -> non-ff: commit back non-ff constants */
3720 if (!state
->ps
&& pShader
)
3721 state
->commit
|= NINE_STATE_COMMIT_CONST_PS
;
3723 nine_bind(&state
->ps
, pShader
);
3725 state
->changed
.group
|= NINE_STATE_PS
;
3727 mask
= state
->ps
? state
->ps
->rt_mask
: 1;
3728 /* We need to update cbufs if the pixel shader would
3729 * write to different render targets */
3730 if (mask
!= old_mask
)
3731 state
->changed
.group
|= NINE_STATE_FB
;
3737 NineDevice9_GetPixelShader( struct NineDevice9
*This
,
3738 IDirect3DPixelShader9
**ppShader
)
3740 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3741 nine_reference_set(ppShader
, This
->state
.ps
);
3746 NineDevice9_SetPixelShaderConstantF( struct NineDevice9
*This
,
3748 const float *pConstantData
,
3749 UINT Vector4fCount
)
3751 struct nine_state
*state
= This
->update
;
3753 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3754 This
, StartRegister
, pConstantData
, Vector4fCount
);
3756 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3757 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3761 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3763 if (!This
->is_recording
) {
3764 if (!memcmp(&state
->ps_const_f
[StartRegister
* 4], pConstantData
,
3765 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0])))
3769 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3771 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3773 nine_ranges_insert(&state
->changed
.ps_const_f
,
3774 StartRegister
, StartRegister
+ Vector4fCount
,
3777 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3783 NineDevice9_GetPixelShaderConstantF( struct NineDevice9
*This
,
3785 float *pConstantData
,
3786 UINT Vector4fCount
)
3788 const struct nine_state
*state
= &This
->state
;
3790 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3791 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3792 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3794 memcpy(pConstantData
,
3795 &state
->ps_const_f
[StartRegister
* 4],
3796 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3802 NineDevice9_SetPixelShaderConstantI( struct NineDevice9
*This
,
3804 const int *pConstantData
,
3805 UINT Vector4iCount
)
3807 struct nine_state
*state
= This
->update
;
3810 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3811 This
, StartRegister
, pConstantData
, Vector4iCount
);
3813 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3814 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3815 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3817 if (This
->driver_caps
.ps_integer
) {
3818 if (!This
->is_recording
) {
3819 if (!memcmp(&state
->ps_const_i
[StartRegister
][0], pConstantData
,
3820 Vector4iCount
* sizeof(state
->ps_const_i
[0])))
3823 memcpy(&state
->ps_const_i
[StartRegister
][0],
3825 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3827 for (i
= 0; i
< Vector4iCount
; i
++) {
3828 state
->ps_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3829 state
->ps_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3830 state
->ps_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3831 state
->ps_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3834 state
->changed
.ps_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3835 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3841 NineDevice9_GetPixelShaderConstantI( struct NineDevice9
*This
,
3844 UINT Vector4iCount
)
3846 const struct nine_state
*state
= &This
->state
;
3849 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3850 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3851 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3853 if (This
->driver_caps
.ps_integer
) {
3854 memcpy(pConstantData
,
3855 &state
->ps_const_i
[StartRegister
][0],
3856 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3858 for (i
= 0; i
< Vector4iCount
; i
++) {
3859 pConstantData
[4*i
] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][0]);
3860 pConstantData
[4*i
+1] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][1]);
3861 pConstantData
[4*i
+2] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][2]);
3862 pConstantData
[4*i
+3] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][3]);
3870 NineDevice9_SetPixelShaderConstantB( struct NineDevice9
*This
,
3872 const BOOL
*pConstantData
,
3875 struct nine_state
*state
= This
->update
;
3877 uint32_t bool_true
= This
->driver_caps
.ps_integer
? 0xFFFFFFFF : fui(1.0f
);
3879 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3880 This
, StartRegister
, pConstantData
, BoolCount
);
3882 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3883 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3884 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3886 if (!This
->is_recording
) {
3887 bool noChange
= true;
3888 for (i
= 0; i
< BoolCount
; i
++) {
3889 if (!!state
->ps_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3896 for (i
= 0; i
< BoolCount
; i
++)
3897 state
->ps_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3899 state
->changed
.ps_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3900 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3906 NineDevice9_GetPixelShaderConstantB( struct NineDevice9
*This
,
3908 BOOL
*pConstantData
,
3911 const struct nine_state
*state
= &This
->state
;
3914 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3915 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3916 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3918 for (i
= 0; i
< BoolCount
; i
++)
3919 pConstantData
[i
] = state
->ps_const_b
[StartRegister
+ i
] ? TRUE
: FALSE
;
3925 NineDevice9_DrawRectPatch( struct NineDevice9
*This
,
3927 const float *pNumSegs
,
3928 const D3DRECTPATCH_INFO
*pRectPatchInfo
)
3930 STUB(D3DERR_INVALIDCALL
);
3934 NineDevice9_DrawTriPatch( struct NineDevice9
*This
,
3936 const float *pNumSegs
,
3937 const D3DTRIPATCH_INFO
*pTriPatchInfo
)
3939 STUB(D3DERR_INVALIDCALL
);
3943 NineDevice9_DeletePatch( struct NineDevice9
*This
,
3946 STUB(D3DERR_INVALIDCALL
);
3950 NineDevice9_CreateQuery( struct NineDevice9
*This
,
3952 IDirect3DQuery9
**ppQuery
)
3954 struct NineQuery9
*query
;
3957 DBG("This=%p Type=%d ppQuery=%p\n", This
, Type
, ppQuery
);
3959 hr
= nine_is_query_supported(This
->screen
, Type
);
3960 if (!ppQuery
|| hr
!= D3D_OK
)
3963 hr
= NineQuery9_new(This
, &query
, Type
);
3966 *ppQuery
= (IDirect3DQuery9
*)query
;
3970 IDirect3DDevice9Vtbl NineDevice9_vtable
= {
3971 (void *)NineUnknown_QueryInterface
,
3972 (void *)NineUnknown_AddRef
,
3973 (void *)NineUnknown_Release
,
3974 (void *)NineDevice9_TestCooperativeLevel
,
3975 (void *)NineDevice9_GetAvailableTextureMem
,
3976 (void *)NineDevice9_EvictManagedResources
,
3977 (void *)NineDevice9_GetDirect3D
,
3978 (void *)NineDevice9_GetDeviceCaps
,
3979 (void *)NineDevice9_GetDisplayMode
,
3980 (void *)NineDevice9_GetCreationParameters
,
3981 (void *)NineDevice9_SetCursorProperties
,
3982 (void *)NineDevice9_SetCursorPosition
,
3983 (void *)NineDevice9_ShowCursor
,
3984 (void *)NineDevice9_CreateAdditionalSwapChain
,
3985 (void *)NineDevice9_GetSwapChain
,
3986 (void *)NineDevice9_GetNumberOfSwapChains
,
3987 (void *)NineDevice9_Reset
,
3988 (void *)NineDevice9_Present
,
3989 (void *)NineDevice9_GetBackBuffer
,
3990 (void *)NineDevice9_GetRasterStatus
,
3991 (void *)NineDevice9_SetDialogBoxMode
,
3992 (void *)NineDevice9_SetGammaRamp
,
3993 (void *)NineDevice9_GetGammaRamp
,
3994 (void *)NineDevice9_CreateTexture
,
3995 (void *)NineDevice9_CreateVolumeTexture
,
3996 (void *)NineDevice9_CreateCubeTexture
,
3997 (void *)NineDevice9_CreateVertexBuffer
,
3998 (void *)NineDevice9_CreateIndexBuffer
,
3999 (void *)NineDevice9_CreateRenderTarget
,
4000 (void *)NineDevice9_CreateDepthStencilSurface
,
4001 (void *)NineDevice9_UpdateSurface
,
4002 (void *)NineDevice9_UpdateTexture
,
4003 (void *)NineDevice9_GetRenderTargetData
,
4004 (void *)NineDevice9_GetFrontBufferData
,
4005 (void *)NineDevice9_StretchRect
,
4006 (void *)NineDevice9_ColorFill
,
4007 (void *)NineDevice9_CreateOffscreenPlainSurface
,
4008 (void *)NineDevice9_SetRenderTarget
,
4009 (void *)NineDevice9_GetRenderTarget
,
4010 (void *)NineDevice9_SetDepthStencilSurface
,
4011 (void *)NineDevice9_GetDepthStencilSurface
,
4012 (void *)NineDevice9_BeginScene
,
4013 (void *)NineDevice9_EndScene
,
4014 (void *)NineDevice9_Clear
,
4015 (void *)NineDevice9_SetTransform
,
4016 (void *)NineDevice9_GetTransform
,
4017 (void *)NineDevice9_MultiplyTransform
,
4018 (void *)NineDevice9_SetViewport
,
4019 (void *)NineDevice9_GetViewport
,
4020 (void *)NineDevice9_SetMaterial
,
4021 (void *)NineDevice9_GetMaterial
,
4022 (void *)NineDevice9_SetLight
,
4023 (void *)NineDevice9_GetLight
,
4024 (void *)NineDevice9_LightEnable
,
4025 (void *)NineDevice9_GetLightEnable
,
4026 (void *)NineDevice9_SetClipPlane
,
4027 (void *)NineDevice9_GetClipPlane
,
4028 (void *)NineDevice9_SetRenderState
,
4029 (void *)NineDevice9_GetRenderState
,
4030 (void *)NineDevice9_CreateStateBlock
,
4031 (void *)NineDevice9_BeginStateBlock
,
4032 (void *)NineDevice9_EndStateBlock
,
4033 (void *)NineDevice9_SetClipStatus
,
4034 (void *)NineDevice9_GetClipStatus
,
4035 (void *)NineDevice9_GetTexture
,
4036 (void *)NineDevice9_SetTexture
,
4037 (void *)NineDevice9_GetTextureStageState
,
4038 (void *)NineDevice9_SetTextureStageState
,
4039 (void *)NineDevice9_GetSamplerState
,
4040 (void *)NineDevice9_SetSamplerState
,
4041 (void *)NineDevice9_ValidateDevice
,
4042 (void *)NineDevice9_SetPaletteEntries
,
4043 (void *)NineDevice9_GetPaletteEntries
,
4044 (void *)NineDevice9_SetCurrentTexturePalette
,
4045 (void *)NineDevice9_GetCurrentTexturePalette
,
4046 (void *)NineDevice9_SetScissorRect
,
4047 (void *)NineDevice9_GetScissorRect
,
4048 (void *)NineDevice9_SetSoftwareVertexProcessing
,
4049 (void *)NineDevice9_GetSoftwareVertexProcessing
,
4050 (void *)NineDevice9_SetNPatchMode
,
4051 (void *)NineDevice9_GetNPatchMode
,
4052 (void *)NineDevice9_DrawPrimitive
,
4053 (void *)NineDevice9_DrawIndexedPrimitive
,
4054 (void *)NineDevice9_DrawPrimitiveUP
,
4055 (void *)NineDevice9_DrawIndexedPrimitiveUP
,
4056 (void *)NineDevice9_ProcessVertices
,
4057 (void *)NineDevice9_CreateVertexDeclaration
,
4058 (void *)NineDevice9_SetVertexDeclaration
,
4059 (void *)NineDevice9_GetVertexDeclaration
,
4060 (void *)NineDevice9_SetFVF
,
4061 (void *)NineDevice9_GetFVF
,
4062 (void *)NineDevice9_CreateVertexShader
,
4063 (void *)NineDevice9_SetVertexShader
,
4064 (void *)NineDevice9_GetVertexShader
,
4065 (void *)NineDevice9_SetVertexShaderConstantF
,
4066 (void *)NineDevice9_GetVertexShaderConstantF
,
4067 (void *)NineDevice9_SetVertexShaderConstantI
,
4068 (void *)NineDevice9_GetVertexShaderConstantI
,
4069 (void *)NineDevice9_SetVertexShaderConstantB
,
4070 (void *)NineDevice9_GetVertexShaderConstantB
,
4071 (void *)NineDevice9_SetStreamSource
,
4072 (void *)NineDevice9_GetStreamSource
,
4073 (void *)NineDevice9_SetStreamSourceFreq
,
4074 (void *)NineDevice9_GetStreamSourceFreq
,
4075 (void *)NineDevice9_SetIndices
,
4076 (void *)NineDevice9_GetIndices
,
4077 (void *)NineDevice9_CreatePixelShader
,
4078 (void *)NineDevice9_SetPixelShader
,
4079 (void *)NineDevice9_GetPixelShader
,
4080 (void *)NineDevice9_SetPixelShaderConstantF
,
4081 (void *)NineDevice9_GetPixelShaderConstantF
,
4082 (void *)NineDevice9_SetPixelShaderConstantI
,
4083 (void *)NineDevice9_GetPixelShaderConstantI
,
4084 (void *)NineDevice9_SetPixelShaderConstantB
,
4085 (void *)NineDevice9_GetPixelShaderConstantB
,
4086 (void *)NineDevice9_DrawRectPatch
,
4087 (void *)NineDevice9_DrawTriPatch
,
4088 (void *)NineDevice9_DeletePatch
,
4089 (void *)NineDevice9_CreateQuery
4092 static const GUID
*NineDevice9_IIDs
[] = {
4093 &IID_IDirect3DDevice9
,
4099 NineDevice9_new( struct pipe_screen
*pScreen
,
4100 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
4102 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
4104 ID3DPresentGroup
*pPresentationGroup
,
4105 struct d3dadapter9_context
*pCTX
,
4107 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
4108 struct NineDevice9
**ppOut
,
4109 int minorVersionNum
)
4112 lock
= !!(pCreationParameters
->BehaviorFlags
& D3DCREATE_MULTITHREADED
);
4114 NINE_NEW(Device9
, ppOut
, lock
, /* args */
4115 pScreen
, pCreationParameters
, pCaps
,
4116 pPresentationParameters
, pD3D9
, pPresentationGroup
, pCTX
,
4117 ex
, pFullscreenDisplayMode
, minorVersionNum
);