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 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
);
431 nine_ff_init(This
); /* initialize fixed function code */
433 NineDevice9_SetDefaultState(This
, FALSE
);
436 struct pipe_poly_stipple stipple
;
437 memset(&stipple
, ~0, sizeof(stipple
));
438 This
->pipe
->set_polygon_stipple(This
->pipe
, &stipple
);
441 This
->update
= &This
->state
;
442 nine_update_state(This
);
444 ID3DPresentGroup_Release(This
->present
);
451 NineDevice9_dtor( struct NineDevice9
*This
)
455 DBG("This=%p\n", This
);
457 if (This
->pipe
&& This
->cso
)
458 nine_pipe_context_clear(This
);
460 nine_state_clear(&This
->state
, TRUE
);
462 if (This
->vertex_uploader
)
463 u_upload_destroy(This
->vertex_uploader
);
464 if (This
->index_uploader
)
465 u_upload_destroy(This
->index_uploader
);
466 if (This
->constbuf_uploader
)
467 u_upload_destroy(This
->constbuf_uploader
);
469 nine_bind(&This
->record
, NULL
);
471 pipe_sampler_view_reference(&This
->dummy_sampler_view
, NULL
);
472 pipe_resource_reference(&This
->dummy_texture
, NULL
);
473 pipe_resource_reference(&This
->constbuf_vs
, NULL
);
474 pipe_resource_reference(&This
->constbuf_ps
, NULL
);
475 pipe_resource_reference(&This
->dummy_vbo
, NULL
);
476 FREE(This
->state
.vs_const_f
);
477 FREE(This
->state
.ps_const_f
);
478 FREE(This
->state
.vs_lconstf_temp
);
479 FREE(This
->state
.ps_lconstf_temp
);
481 if (This
->swapchains
) {
482 for (i
= 0; i
< This
->nswapchains
; ++i
)
483 if (This
->swapchains
[i
])
484 NineUnknown_Unbind(NineUnknown(This
->swapchains
[i
]));
485 FREE(This
->swapchains
);
491 cso_destroy_context(This
->cso
);
493 if (This
->pipe
->destroy
) { This
->pipe
->destroy(This
->pipe
); }
496 if (This
->present
) { ID3DPresentGroup_Release(This
->present
); }
497 if (This
->d3d9
) { IDirect3D9_Release(This
->d3d9
); }
499 NineUnknown_dtor(&This
->base
);
503 NineDevice9_GetScreen( struct NineDevice9
*This
)
508 struct pipe_context
*
509 NineDevice9_GetPipe( struct NineDevice9
*This
)
515 NineDevice9_GetCSO( struct NineDevice9
*This
)
521 NineDevice9_GetCaps( struct NineDevice9
*This
)
527 NineDevice9_PauseRecording( struct NineDevice9
*This
)
530 This
->update
= &This
->state
;
531 This
->is_recording
= FALSE
;
536 NineDevice9_ResumeRecording( struct NineDevice9
*This
)
539 This
->update
= &This
->record
->state
;
540 This
->is_recording
= TRUE
;
545 NineDevice9_TestCooperativeLevel( struct NineDevice9
*This
)
547 if (NineSwapChain9_GetOccluded(This
->swapchains
[0])) {
548 This
->device_needs_reset
= TRUE
;
549 return D3DERR_DEVICELOST
;
550 } else if (NineSwapChain9_ResolutionMismatch(This
->swapchains
[0])) {
551 This
->device_needs_reset
= TRUE
;
552 return D3DERR_DEVICENOTRESET
;
553 } else if (This
->device_needs_reset
) {
554 return D3DERR_DEVICENOTRESET
;
561 NineDevice9_GetAvailableTextureMem( struct NineDevice9
*This
)
563 return This
->available_texture_mem
;
567 NineDevice9_EvictManagedResources( struct NineDevice9
*This
)
569 struct NineBaseTexture9
*tex
;
570 struct NineBuffer9
*buf
;
572 DBG("This=%p\n", This
);
573 LIST_FOR_EACH_ENTRY(tex
, &This
->managed_textures
, list2
) {
574 NineBaseTexture9_UnLoad(tex
);
576 /* Vertex/index buffers don't take a lot of space and aren't accounted
577 * for d3d memory usage. Instead of actually freeing from memory,
578 * just mark the buffer dirty to trigger a re-upload later. We
579 * could just ignore, but some bad behaving apps could rely on it (if
580 * they write outside the locked regions typically). */
581 LIST_FOR_EACH_ENTRY(buf
, &This
->managed_buffers
, managed
.list2
) {
582 NineBuffer9_SetDirty(buf
);
589 NineDevice9_GetDirect3D( struct NineDevice9
*This
,
590 IDirect3D9
**ppD3D9
)
592 user_assert(ppD3D9
!= NULL
, E_POINTER
);
593 IDirect3D9_AddRef(This
->d3d9
);
594 *ppD3D9
= This
->d3d9
;
599 NineDevice9_GetDeviceCaps( struct NineDevice9
*This
,
602 user_assert(pCaps
!= NULL
, D3DERR_INVALIDCALL
);
608 NineDevice9_GetDisplayMode( struct NineDevice9
*This
,
610 D3DDISPLAYMODE
*pMode
)
612 DBG("This=%p iSwapChain=%u pMode=%p\n", This
, iSwapChain
, pMode
);
614 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
616 return NineSwapChain9_GetDisplayMode(This
->swapchains
[iSwapChain
], pMode
);
620 NineDevice9_GetCreationParameters( struct NineDevice9
*This
,
621 D3DDEVICE_CREATION_PARAMETERS
*pParameters
)
623 user_assert(pParameters
!= NULL
, D3DERR_INVALIDCALL
);
624 *pParameters
= This
->params
;
629 NineDevice9_SetCursorProperties( struct NineDevice9
*This
,
632 IDirect3DSurface9
*pCursorBitmap
)
634 struct NineSurface9
*surf
= NineSurface9(pCursorBitmap
);
635 struct pipe_context
*pipe
= This
->pipe
;
637 struct pipe_transfer
*transfer
;
641 DBG_FLAG(DBG_SWAPCHAIN
, "This=%p XHotSpot=%u YHotSpot=%u "
642 "pCursorBitmap=%p\n", This
, XHotSpot
, YHotSpot
, pCursorBitmap
);
644 user_assert(pCursorBitmap
, D3DERR_INVALIDCALL
);
645 user_assert(surf
->desc
.Format
== D3DFMT_A8R8G8B8
, D3DERR_INVALIDCALL
);
647 if (This
->swapchains
[0]->params
.Windowed
) {
648 This
->cursor
.w
= MIN2(surf
->desc
.Width
, 32);
649 This
->cursor
.h
= MIN2(surf
->desc
.Height
, 32);
650 hw_cursor
= 1; /* always use hw cursor for windowed mode */
652 This
->cursor
.w
= MIN2(surf
->desc
.Width
, This
->cursor
.image
->width0
);
653 This
->cursor
.h
= MIN2(surf
->desc
.Height
, This
->cursor
.image
->height0
);
654 hw_cursor
= This
->cursor
.w
== 32 && This
->cursor
.h
== 32;
657 u_box_origin_2d(This
->cursor
.w
, This
->cursor
.h
, &box
);
659 ptr
= pipe
->transfer_map(pipe
, This
->cursor
.image
, 0,
660 PIPE_TRANSFER_WRITE
|
661 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
664 ret_err("Failed to update cursor image.\n", D3DERR_DRIVERINTERNALERROR
);
666 This
->cursor
.hotspot
.x
= XHotSpot
;
667 This
->cursor
.hotspot
.y
= YHotSpot
;
669 /* Copy cursor image to internal storage. */
673 const struct util_format_description
*sfmt
=
674 util_format_description(surf
->base
.info
.format
);
677 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, D3DLOCK_READONLY
);
679 ret_err("Failed to map cursor source image.\n",
680 D3DERR_DRIVERINTERNALERROR
);
682 sfmt
->unpack_rgba_8unorm(ptr
, transfer
->stride
,
683 lock
.pBits
, lock
.Pitch
,
684 This
->cursor
.w
, This
->cursor
.h
);
687 hw_cursor
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
,
689 &This
->cursor
.hotspot
,
690 This
->cursor
.visible
) == D3D_OK
;
692 NineSurface9_UnlockRect(surf
);
694 pipe
->transfer_unmap(pipe
, transfer
);
696 /* hide cursor if we emulate it */
698 ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, FALSE
);
699 This
->cursor
.software
= !hw_cursor
;
705 NineDevice9_SetCursorPosition( struct NineDevice9
*This
,
710 struct NineSwapChain9
*swap
= This
->swapchains
[0];
712 DBG("This=%p X=%d Y=%d Flags=%d\n", This
, X
, Y
, Flags
);
714 This
->cursor
.pos
.x
= X
;
715 This
->cursor
.pos
.y
= Y
;
717 if (!This
->cursor
.software
)
718 This
->cursor
.software
= ID3DPresent_SetCursorPos(swap
->present
, &This
->cursor
.pos
) != D3D_OK
;
722 NineDevice9_ShowCursor( struct NineDevice9
*This
,
725 BOOL old
= This
->cursor
.visible
;
727 DBG("This=%p bShow=%d\n", This
, (int) bShow
);
729 This
->cursor
.visible
= bShow
&& (This
->cursor
.hotspot
.x
!= -1);
730 if (!This
->cursor
.software
)
731 This
->cursor
.software
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, bShow
) != D3D_OK
;
737 NineDevice9_CreateAdditionalSwapChain( struct NineDevice9
*This
,
738 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
739 IDirect3DSwapChain9
**pSwapChain
)
741 struct NineSwapChain9
*swapchain
, *tmplt
= This
->swapchains
[0];
742 ID3DPresent
*present
;
745 DBG("This=%p pPresentationParameters=%p pSwapChain=%p\n",
746 This
, pPresentationParameters
, pSwapChain
);
748 user_assert(pPresentationParameters
, D3DERR_INVALIDCALL
);
749 user_assert(tmplt
->params
.Windowed
&& pPresentationParameters
->Windowed
, D3DERR_INVALIDCALL
);
751 /* TODO: this deserves more tests */
752 if (!pPresentationParameters
->hDeviceWindow
)
753 pPresentationParameters
->hDeviceWindow
= This
->params
.hFocusWindow
;
755 hr
= ID3DPresentGroup_CreateAdditionalPresent(This
->present
, pPresentationParameters
, &present
);
760 hr
= NineSwapChain9_new(This
, FALSE
, present
, pPresentationParameters
,
762 tmplt
->params
.hDeviceWindow
,
767 *pSwapChain
= (IDirect3DSwapChain9
*)swapchain
;
772 NineDevice9_GetSwapChain( struct NineDevice9
*This
,
774 IDirect3DSwapChain9
**pSwapChain
)
776 user_assert(pSwapChain
!= NULL
, D3DERR_INVALIDCALL
);
779 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
781 NineUnknown_AddRef(NineUnknown(This
->swapchains
[iSwapChain
]));
782 *pSwapChain
= (IDirect3DSwapChain9
*)This
->swapchains
[iSwapChain
];
788 NineDevice9_GetNumberOfSwapChains( struct NineDevice9
*This
)
790 return This
->nswapchains
;
794 NineDevice9_Reset( struct NineDevice9
*This
,
795 D3DPRESENT_PARAMETERS
*pPresentationParameters
)
800 DBG("This=%p pPresentationParameters=%p\n", This
, pPresentationParameters
);
802 if (NineSwapChain9_GetOccluded(This
->swapchains
[0])) {
803 This
->device_needs_reset
= TRUE
;
804 return D3DERR_DEVICELOST
;
807 for (i
= 0; i
< This
->nswapchains
; ++i
) {
808 D3DPRESENT_PARAMETERS
*params
= &pPresentationParameters
[i
];
809 hr
= NineSwapChain9_Resize(This
->swapchains
[i
], params
, NULL
);
814 nine_pipe_context_clear(This
);
815 nine_state_clear(&This
->state
, TRUE
);
817 NineDevice9_SetDefaultState(This
, TRUE
);
818 NineDevice9_SetRenderTarget(
819 This
, 0, (IDirect3DSurface9
*)This
->swapchains
[0]->buffers
[0]);
820 /* XXX: better use GetBackBuffer here ? */
822 This
->device_needs_reset
= (hr
!= D3D_OK
);
827 NineDevice9_Present( struct NineDevice9
*This
,
828 const RECT
*pSourceRect
,
829 const RECT
*pDestRect
,
830 HWND hDestWindowOverride
,
831 const RGNDATA
*pDirtyRegion
)
836 DBG("This=%p pSourceRect=%p pDestRect=%p hDestWindowOverride=%p pDirtyRegion=%p\n",
837 This
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
839 /* XXX is this right? */
840 for (i
= 0; i
< This
->nswapchains
; ++i
) {
841 hr
= NineSwapChain9_Present(This
->swapchains
[i
], pSourceRect
, pDestRect
,
842 hDestWindowOverride
, pDirtyRegion
, 0);
843 if (FAILED(hr
)) { return hr
; }
850 NineDevice9_GetBackBuffer( struct NineDevice9
*This
,
853 D3DBACKBUFFER_TYPE Type
,
854 IDirect3DSurface9
**ppBackBuffer
)
856 user_assert(ppBackBuffer
!= NULL
, D3DERR_INVALIDCALL
);
857 /* return NULL on error */
858 *ppBackBuffer
= NULL
;
859 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
861 return NineSwapChain9_GetBackBuffer(This
->swapchains
[iSwapChain
],
862 iBackBuffer
, Type
, ppBackBuffer
);
866 NineDevice9_GetRasterStatus( struct NineDevice9
*This
,
868 D3DRASTER_STATUS
*pRasterStatus
)
870 user_assert(pRasterStatus
!= NULL
, D3DERR_INVALIDCALL
);
871 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
873 return NineSwapChain9_GetRasterStatus(This
->swapchains
[iSwapChain
],
878 NineDevice9_SetDialogBoxMode( struct NineDevice9
*This
,
879 BOOL bEnableDialogs
)
881 STUB(D3DERR_INVALIDCALL
);
885 NineDevice9_SetGammaRamp( struct NineDevice9
*This
,
888 const D3DGAMMARAMP
*pRamp
)
890 DBG("This=%p iSwapChain=%u Flags=%x pRamp=%p\n", This
,
891 iSwapChain
, Flags
, pRamp
);
893 user_warn(iSwapChain
>= This
->nswapchains
);
896 if (pRamp
&& (iSwapChain
< This
->nswapchains
)) {
897 struct NineSwapChain9
*swap
= This
->swapchains
[iSwapChain
];
898 swap
->gamma
= *pRamp
;
899 ID3DPresent_SetGammaRamp(swap
->present
, pRamp
, swap
->params
.hDeviceWindow
);
904 NineDevice9_GetGammaRamp( struct NineDevice9
*This
,
906 D3DGAMMARAMP
*pRamp
)
908 DBG("This=%p iSwapChain=%u pRamp=%p\n", This
, iSwapChain
, pRamp
);
910 user_warn(iSwapChain
>= This
->nswapchains
);
913 if (pRamp
&& (iSwapChain
< This
->nswapchains
))
914 *pRamp
= This
->swapchains
[iSwapChain
]->gamma
;
918 NineDevice9_CreateTexture( struct NineDevice9
*This
,
925 IDirect3DTexture9
**ppTexture
,
926 HANDLE
*pSharedHandle
)
928 struct NineTexture9
*tex
;
931 DBG("This=%p Width=%u Height=%u Levels=%u Usage=%s Format=%s Pool=%s "
932 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Levels
,
933 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
934 nine_D3DPOOL_to_str(Pool
), ppTexture
, pSharedHandle
);
936 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DMAP
|
937 D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
938 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
;
942 hr
= NineTexture9_new(This
, Width
, Height
, Levels
, Usage
, Format
, Pool
,
943 &tex
, pSharedHandle
);
945 *ppTexture
= (IDirect3DTexture9
*)tex
;
951 NineDevice9_CreateVolumeTexture( struct NineDevice9
*This
,
959 IDirect3DVolumeTexture9
**ppVolumeTexture
,
960 HANDLE
*pSharedHandle
)
962 struct NineVolumeTexture9
*tex
;
965 DBG("This=%p Width=%u Height=%u Depth=%u Levels=%u Usage=%s Format=%s Pool=%s "
966 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Depth
, Levels
,
967 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
968 nine_D3DPOOL_to_str(Pool
), ppVolumeTexture
, pSharedHandle
);
970 Usage
&= D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
971 D3DUSAGE_SOFTWAREPROCESSING
;
973 *ppVolumeTexture
= NULL
;
975 hr
= NineVolumeTexture9_new(This
, Width
, Height
, Depth
, Levels
,
976 Usage
, Format
, Pool
, &tex
, pSharedHandle
);
978 *ppVolumeTexture
= (IDirect3DVolumeTexture9
*)tex
;
984 NineDevice9_CreateCubeTexture( struct NineDevice9
*This
,
990 IDirect3DCubeTexture9
**ppCubeTexture
,
991 HANDLE
*pSharedHandle
)
993 struct NineCubeTexture9
*tex
;
996 DBG("This=%p EdgeLength=%u Levels=%u Usage=%s Format=%s Pool=%s ppOut=%p "
997 "pSharedHandle=%p\n", This
, EdgeLength
, Levels
,
998 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
999 nine_D3DPOOL_to_str(Pool
), ppCubeTexture
, pSharedHandle
);
1001 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DYNAMIC
|
1002 D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
1003 D3DUSAGE_SOFTWAREPROCESSING
;
1005 *ppCubeTexture
= NULL
;
1007 hr
= NineCubeTexture9_new(This
, EdgeLength
, Levels
, Usage
, Format
, Pool
,
1008 &tex
, pSharedHandle
);
1010 *ppCubeTexture
= (IDirect3DCubeTexture9
*)tex
;
1016 NineDevice9_CreateVertexBuffer( struct NineDevice9
*This
,
1021 IDirect3DVertexBuffer9
**ppVertexBuffer
,
1022 HANDLE
*pSharedHandle
)
1024 struct NineVertexBuffer9
*buf
;
1026 D3DVERTEXBUFFER_DESC desc
;
1028 DBG("This=%p Length=%u Usage=%x FVF=%x Pool=%u ppOut=%p pSharedHandle=%p\n",
1029 This
, Length
, Usage
, FVF
, Pool
, ppVertexBuffer
, pSharedHandle
);
1031 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1033 desc
.Format
= D3DFMT_VERTEXDATA
;
1034 desc
.Type
= D3DRTYPE_VERTEXBUFFER
;
1035 desc
.Usage
= Usage
&
1036 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1037 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1038 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
|
1039 D3DUSAGE_WRITEONLY
);
1044 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1045 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1047 hr
= NineVertexBuffer9_new(This
, &desc
, &buf
);
1049 *ppVertexBuffer
= (IDirect3DVertexBuffer9
*)buf
;
1054 NineDevice9_CreateIndexBuffer( struct NineDevice9
*This
,
1059 IDirect3DIndexBuffer9
**ppIndexBuffer
,
1060 HANDLE
*pSharedHandle
)
1062 struct NineIndexBuffer9
*buf
;
1064 D3DINDEXBUFFER_DESC desc
;
1066 DBG("This=%p Length=%u Usage=%x Format=%s Pool=%u ppOut=%p "
1067 "pSharedHandle=%p\n", This
, Length
, Usage
,
1068 d3dformat_to_string(Format
), Pool
, ppIndexBuffer
, pSharedHandle
);
1070 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1072 desc
.Format
= Format
;
1073 desc
.Type
= D3DRTYPE_INDEXBUFFER
;
1074 desc
.Usage
= Usage
&
1075 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1076 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1077 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_WRITEONLY
);
1081 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1082 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1084 hr
= NineIndexBuffer9_new(This
, &desc
, &buf
);
1086 *ppIndexBuffer
= (IDirect3DIndexBuffer9
*)buf
;
1091 create_zs_or_rt_surface(struct NineDevice9
*This
,
1092 unsigned type
, /* 0 = RT, 1 = ZS, 2 = plain */
1094 UINT Width
, UINT Height
,
1096 D3DMULTISAMPLE_TYPE MultiSample
,
1097 DWORD MultisampleQuality
,
1098 BOOL Discard_or_Lockable
,
1099 IDirect3DSurface9
**ppSurface
,
1100 HANDLE
*pSharedHandle
)
1102 struct NineSurface9
*surface
;
1103 struct pipe_screen
*screen
= This
->screen
;
1104 struct pipe_resource
*resource
= NULL
;
1106 D3DSURFACE_DESC desc
;
1107 struct pipe_resource templ
;
1109 DBG("This=%p type=%u Pool=%s Width=%u Height=%u Format=%s MS=%u Quality=%u "
1110 "Discard_or_Lockable=%i ppSurface=%p pSharedHandle=%p\n",
1111 This
, type
, nine_D3DPOOL_to_str(Pool
), Width
, Height
,
1112 d3dformat_to_string(Format
), MultiSample
, MultisampleQuality
,
1113 Discard_or_Lockable
, ppSurface
, pSharedHandle
);
1116 DBG("FIXME Used shared handle! This option isn't probably handled correctly!\n");
1118 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
1119 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1121 templ
.target
= PIPE_TEXTURE_2D
;
1122 templ
.width0
= Width
;
1123 templ
.height0
= Height
;
1125 templ
.array_size
= 1;
1126 templ
.last_level
= 0;
1127 templ
.nr_samples
= (unsigned)MultiSample
;
1128 templ
.usage
= PIPE_USAGE_DEFAULT
;
1130 templ
.bind
= PIPE_BIND_SAMPLER_VIEW
; /* StretchRect */
1132 case 0: templ
.bind
|= PIPE_BIND_RENDER_TARGET
; break;
1133 case 1: templ
.bind
= d3d9_get_pipe_depth_format_bindings(Format
); break;
1138 templ
.format
= d3d9_to_pipe_format_checked(screen
, Format
, templ
.target
,
1139 templ
.nr_samples
, templ
.bind
,
1140 FALSE
, Pool
== D3DPOOL_SCRATCH
);
1142 if (templ
.format
== PIPE_FORMAT_NONE
&& Format
!= D3DFMT_NULL
)
1143 return D3DERR_INVALIDCALL
;
1145 desc
.Format
= Format
;
1146 desc
.Type
= D3DRTYPE_SURFACE
;
1149 desc
.MultiSampleType
= MultiSample
;
1150 desc
.MultiSampleQuality
= MultisampleQuality
;
1152 desc
.Height
= Height
;
1154 case 0: desc
.Usage
= D3DUSAGE_RENDERTARGET
; break;
1155 case 1: desc
.Usage
= D3DUSAGE_DEPTHSTENCIL
; break;
1159 if (compressed_format(Format
)) {
1160 const unsigned w
= util_format_get_blockwidth(templ
.format
);
1161 const unsigned h
= util_format_get_blockheight(templ
.format
);
1163 user_assert(!(Width
% w
) && !(Height
% h
), D3DERR_INVALIDCALL
);
1166 if (Pool
== D3DPOOL_DEFAULT
&& Format
!= D3DFMT_NULL
) {
1167 /* resource_create doesn't return an error code, so check format here */
1168 user_assert(templ
.format
!= PIPE_FORMAT_NONE
, D3DERR_INVALIDCALL
);
1169 resource
= screen
->resource_create(screen
, &templ
);
1170 user_assert(resource
, D3DERR_OUTOFVIDEOMEMORY
);
1171 if (Discard_or_Lockable
&& (desc
.Usage
& D3DUSAGE_RENDERTARGET
))
1172 resource
->flags
|= NINE_RESOURCE_FLAG_LOCKABLE
;
1176 hr
= NineSurface9_new(This
, NULL
, resource
, NULL
, 0, 0, 0, &desc
, &surface
);
1177 pipe_resource_reference(&resource
, NULL
);
1180 *ppSurface
= (IDirect3DSurface9
*)surface
;
1185 NineDevice9_CreateRenderTarget( struct NineDevice9
*This
,
1189 D3DMULTISAMPLE_TYPE MultiSample
,
1190 DWORD MultisampleQuality
,
1192 IDirect3DSurface9
**ppSurface
,
1193 HANDLE
*pSharedHandle
)
1196 return create_zs_or_rt_surface(This
, 0, D3DPOOL_DEFAULT
,
1197 Width
, Height
, Format
,
1198 MultiSample
, MultisampleQuality
,
1199 Lockable
, ppSurface
, pSharedHandle
);
1203 NineDevice9_CreateDepthStencilSurface( struct NineDevice9
*This
,
1207 D3DMULTISAMPLE_TYPE MultiSample
,
1208 DWORD MultisampleQuality
,
1210 IDirect3DSurface9
**ppSurface
,
1211 HANDLE
*pSharedHandle
)
1214 if (!depth_stencil_format(Format
))
1215 return D3DERR_NOTAVAILABLE
;
1216 return create_zs_or_rt_surface(This
, 1, D3DPOOL_DEFAULT
,
1217 Width
, Height
, Format
,
1218 MultiSample
, MultisampleQuality
,
1219 Discard
, ppSurface
, pSharedHandle
);
1223 NineDevice9_UpdateSurface( struct NineDevice9
*This
,
1224 IDirect3DSurface9
*pSourceSurface
,
1225 const RECT
*pSourceRect
,
1226 IDirect3DSurface9
*pDestinationSurface
,
1227 const POINT
*pDestPoint
)
1229 struct NineSurface9
*dst
= NineSurface9(pDestinationSurface
);
1230 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1231 int copy_width
, copy_height
;
1234 DBG("This=%p pSourceSurface=%p pDestinationSurface=%p "
1235 "pSourceRect=%p pDestPoint=%p\n", This
,
1236 pSourceSurface
, pDestinationSurface
, pSourceRect
, pDestPoint
);
1238 DBG("pSourceRect = (%u,%u)-(%u,%u)\n",
1239 pSourceRect
->left
, pSourceRect
->top
,
1240 pSourceRect
->right
, pSourceRect
->bottom
);
1242 DBG("pDestPoint = (%u,%u)\n", pDestPoint
->x
, pDestPoint
->y
);
1244 user_assert(dst
&& src
, D3DERR_INVALIDCALL
);
1246 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1247 user_assert(src
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1249 user_assert(dst
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1250 user_assert(src
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1252 user_assert(!src
->lock_count
, D3DERR_INVALIDCALL
);
1253 user_assert(!dst
->lock_count
, D3DERR_INVALIDCALL
);
1255 user_assert(dst
->desc
.Format
== src
->desc
.Format
, D3DERR_INVALIDCALL
);
1256 user_assert(!depth_stencil_format(dst
->desc
.Format
), D3DERR_INVALIDCALL
);
1259 copy_width
= pSourceRect
->right
- pSourceRect
->left
;
1260 copy_height
= pSourceRect
->bottom
- pSourceRect
->top
;
1262 user_assert(pSourceRect
->left
>= 0 &&
1264 pSourceRect
->right
<= src
->desc
.Width
&&
1265 pSourceRect
->top
>= 0 &&
1267 pSourceRect
->bottom
<= src
->desc
.Height
,
1268 D3DERR_INVALIDCALL
);
1270 copy_width
= src
->desc
.Width
;
1271 copy_height
= src
->desc
.Height
;
1274 destRect
.right
= copy_width
;
1275 destRect
.bottom
= copy_height
;
1278 user_assert(pDestPoint
->x
>= 0 && pDestPoint
->y
>= 0,
1279 D3DERR_INVALIDCALL
);
1280 destRect
.right
+= pDestPoint
->x
;
1281 destRect
.bottom
+= pDestPoint
->y
;
1284 user_assert(destRect
.right
<= dst
->desc
.Width
&&
1285 destRect
.bottom
<= dst
->desc
.Height
,
1286 D3DERR_INVALIDCALL
);
1288 if (compressed_format(dst
->desc
.Format
)) {
1289 const unsigned w
= util_format_get_blockwidth(dst
->base
.info
.format
);
1290 const unsigned h
= util_format_get_blockheight(dst
->base
.info
.format
);
1293 user_assert(!(pDestPoint
->x
% w
) && !(pDestPoint
->y
% h
),
1294 D3DERR_INVALIDCALL
);
1298 user_assert(!(pSourceRect
->left
% w
) && !(pSourceRect
->top
% h
),
1299 D3DERR_INVALIDCALL
);
1301 if (!(copy_width
== src
->desc
.Width
&&
1302 copy_width
== dst
->desc
.Width
&&
1303 copy_height
== src
->desc
.Height
&&
1304 copy_height
== dst
->desc
.Height
)) {
1305 user_assert(!(copy_width
% w
) && !(copy_height
% h
),
1306 D3DERR_INVALIDCALL
);
1310 NineSurface9_CopyMemToDefault(dst
, src
, pDestPoint
, pSourceRect
);
1316 NineDevice9_UpdateTexture( struct NineDevice9
*This
,
1317 IDirect3DBaseTexture9
*pSourceTexture
,
1318 IDirect3DBaseTexture9
*pDestinationTexture
)
1320 struct NineBaseTexture9
*dstb
= NineBaseTexture9(pDestinationTexture
);
1321 struct NineBaseTexture9
*srcb
= NineBaseTexture9(pSourceTexture
);
1323 unsigned last_src_level
, last_dst_level
;
1326 DBG("This=%p pSourceTexture=%p pDestinationTexture=%p\n", This
,
1327 pSourceTexture
, pDestinationTexture
);
1329 user_assert(pSourceTexture
&& pDestinationTexture
, D3DERR_INVALIDCALL
);
1330 user_assert(pSourceTexture
!= pDestinationTexture
, D3DERR_INVALIDCALL
);
1332 user_assert(dstb
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1333 user_assert(srcb
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1334 user_assert(dstb
->base
.type
== srcb
->base
.type
, D3DERR_INVALIDCALL
);
1335 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ||
1336 dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
, D3DERR_INVALIDCALL
);
1339 * . Different formats
1340 * . Fewer src levels than dst levels (if the opposite, only matching levels
1341 * are supposed to be copied)
1342 * . Levels do not match
1343 * DDI: Actually the above should pass because of legacy applications
1344 * Do what you want about these, but you shouldn't crash.
1345 * However driver can expect that the top dimension is greater for src than dst.
1346 * Wine tests: Every combination that passes the initial checks should pass.
1347 * . Different formats => conversion driver and format dependent.
1348 * . 1 level, but size not matching => copy is done (and even crash if src bigger
1349 * than dst. For the case where dst bigger, wine doesn't test if a stretch is applied
1350 * or if a subrect is copied).
1351 * . 8x8 4 sublevels -> 7x7 2 sublevels => driver dependent, On NV seems to be 4x4 subrect
1354 * From these, the proposal is:
1355 * . Different formats -> use util_format_translate to translate if possible for surfaces.
1356 * Accept ARGB/XRGB for Volumes. Do nothing for the other combinations
1357 * . First level copied -> the first level such that src is smaller or equal to dst first level
1358 * . number of levels copied -> as long as it fits and textures have levels
1359 * That should satisfy the constraints (and instead of crashing for some cases we return D3D_OK)
1362 last_src_level
= (srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ? 0 : srcb
->base
.info
.last_level
;
1363 last_dst_level
= (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ? 0 : dstb
->base
.info
.last_level
;
1365 for (m
= 0; m
<= last_src_level
; ++m
) {
1366 unsigned w
= u_minify(srcb
->base
.info
.width0
, m
);
1367 unsigned h
= u_minify(srcb
->base
.info
.height0
, m
);
1368 unsigned d
= u_minify(srcb
->base
.info
.depth0
, m
);
1370 if (w
<= dstb
->base
.info
.width0
&&
1371 h
<= dstb
->base
.info
.height0
&&
1372 d
<= dstb
->base
.info
.depth0
)
1375 user_assert(m
<= last_src_level
, D3D_OK
);
1377 last_dst_level
= MIN2(srcb
->base
.info
.last_level
- m
, last_dst_level
);
1379 if (dstb
->base
.type
== D3DRTYPE_TEXTURE
) {
1380 struct NineTexture9
*dst
= NineTexture9(dstb
);
1381 struct NineTexture9
*src
= NineTexture9(srcb
);
1383 if (src
->dirty_rect
.width
== 0)
1386 pipe_box_to_rect(&rect
, &src
->dirty_rect
);
1387 for (l
= 0; l
< m
; ++l
)
1388 rect_minify_inclusive(&rect
);
1390 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
) {
1391 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1393 dst
->surfaces
[l
]->desc
.Width
,
1394 dst
->surfaces
[l
]->desc
.Height
);
1395 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
],
1399 rect_minify_inclusive(&rect
);
1401 u_box_origin_2d(0, 0, &src
->dirty_rect
);
1403 if (dstb
->base
.type
== D3DRTYPE_CUBETEXTURE
) {
1404 struct NineCubeTexture9
*dst
= NineCubeTexture9(dstb
);
1405 struct NineCubeTexture9
*src
= NineCubeTexture9(srcb
);
1408 /* GPUs usually have them stored as arrays of mip-mapped 2D textures. */
1409 for (z
= 0; z
< 6; ++z
) {
1410 if (src
->dirty_rect
[z
].width
== 0)
1413 pipe_box_to_rect(&rect
, &src
->dirty_rect
[z
]);
1414 for (l
= 0; l
< m
; ++l
)
1415 rect_minify_inclusive(&rect
);
1417 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
) {
1418 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1420 dst
->surfaces
[l
* 6 + z
]->desc
.Width
,
1421 dst
->surfaces
[l
* 6 + z
]->desc
.Height
);
1422 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
* 6 + z
],
1423 src
->surfaces
[m
* 6 + z
],
1426 rect_minify_inclusive(&rect
);
1428 u_box_origin_2d(0, 0, &src
->dirty_rect
[z
]);
1432 if (dstb
->base
.type
== D3DRTYPE_VOLUMETEXTURE
) {
1433 struct NineVolumeTexture9
*dst
= NineVolumeTexture9(dstb
);
1434 struct NineVolumeTexture9
*src
= NineVolumeTexture9(srcb
);
1436 if (src
->dirty_box
.width
== 0)
1438 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
)
1439 NineVolume9_CopyMemToDefault(dst
->volumes
[l
],
1440 src
->volumes
[m
], 0, 0, 0, NULL
);
1441 u_box_3d(0, 0, 0, 0, 0, 0, &src
->dirty_box
);
1443 assert(!"invalid texture type");
1446 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1447 dstb
->dirty_mip
= TRUE
;
1448 NineBaseTexture9_GenerateMipSubLevels(dstb
);
1455 NineDevice9_GetRenderTargetData( struct NineDevice9
*This
,
1456 IDirect3DSurface9
*pRenderTarget
,
1457 IDirect3DSurface9
*pDestSurface
)
1459 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1460 struct NineSurface9
*src
= NineSurface9(pRenderTarget
);
1462 DBG("This=%p pRenderTarget=%p pDestSurface=%p\n",
1463 This
, pRenderTarget
, pDestSurface
);
1465 user_assert(dst
->desc
.Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1466 user_assert(src
->desc
.Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1468 user_assert(dst
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1469 user_assert(src
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1471 user_assert(src
->desc
.Width
== dst
->desc
.Width
, D3DERR_INVALIDCALL
);
1472 user_assert(src
->desc
.Height
== dst
->desc
.Height
, D3DERR_INVALIDCALL
);
1474 NineSurface9_CopyDefaultToMem(dst
, src
);
1480 NineDevice9_GetFrontBufferData( struct NineDevice9
*This
,
1482 IDirect3DSurface9
*pDestSurface
)
1484 DBG("This=%p iSwapChain=%u pDestSurface=%p\n", This
,
1485 iSwapChain
, pDestSurface
);
1487 user_assert(pDestSurface
!= NULL
, D3DERR_INVALIDCALL
);
1488 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
1490 return NineSwapChain9_GetFrontBufferData(This
->swapchains
[iSwapChain
],
1495 NineDevice9_StretchRect( struct NineDevice9
*This
,
1496 IDirect3DSurface9
*pSourceSurface
,
1497 const RECT
*pSourceRect
,
1498 IDirect3DSurface9
*pDestSurface
,
1499 const RECT
*pDestRect
,
1500 D3DTEXTUREFILTERTYPE Filter
)
1502 struct pipe_screen
*screen
= This
->screen
;
1503 struct pipe_context
*pipe
= This
->pipe
;
1504 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1505 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1506 struct pipe_resource
*dst_res
= NineSurface9_GetResource(dst
);
1507 struct pipe_resource
*src_res
= NineSurface9_GetResource(src
);
1509 struct pipe_blit_info blit
;
1510 boolean scaled
, clamped
, ms
, flip_x
= FALSE
, flip_y
= FALSE
;
1512 DBG("This=%p pSourceSurface=%p pSourceRect=%p pDestSurface=%p "
1513 "pDestRect=%p Filter=%u\n",
1514 This
, pSourceSurface
, pSourceRect
, pDestSurface
, pDestRect
, Filter
);
1516 DBG("pSourceRect=(%u,%u)-(%u,%u)\n",
1517 pSourceRect
->left
, pSourceRect
->top
,
1518 pSourceRect
->right
, pSourceRect
->bottom
);
1520 DBG("pDestRect=(%u,%u)-(%u,%u)\n", pDestRect
->left
, pDestRect
->top
,
1521 pDestRect
->right
, pDestRect
->bottom
);
1523 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
&&
1524 src
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1525 zs
= util_format_is_depth_or_stencil(dst_res
->format
);
1526 user_assert(!zs
|| !This
->in_scene
, D3DERR_INVALIDCALL
);
1527 user_assert(!zs
|| !pSourceRect
||
1528 (pSourceRect
->left
== 0 &&
1529 pSourceRect
->top
== 0 &&
1530 pSourceRect
->right
== src
->desc
.Width
&&
1531 pSourceRect
->bottom
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1532 user_assert(!zs
|| !pDestRect
||
1533 (pDestRect
->left
== 0 &&
1534 pDestRect
->top
== 0 &&
1535 pDestRect
->right
== dst
->desc
.Width
&&
1536 pDestRect
->bottom
== dst
->desc
.Height
), D3DERR_INVALIDCALL
);
1538 (dst
->desc
.Width
== src
->desc
.Width
&&
1539 dst
->desc
.Height
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1540 user_assert(zs
|| !util_format_is_depth_or_stencil(src_res
->format
),
1541 D3DERR_INVALIDCALL
);
1542 user_assert(!zs
|| dst
->desc
.Format
== src
->desc
.Format
,
1543 D3DERR_INVALIDCALL
);
1544 user_assert(screen
->is_format_supported(screen
, src_res
->format
,
1546 src_res
->nr_samples
,
1547 PIPE_BIND_SAMPLER_VIEW
),
1548 D3DERR_INVALIDCALL
);
1550 /* We might want to permit these, but wine thinks we shouldn't. */
1551 user_assert(!pDestRect
||
1552 (pDestRect
->left
<= pDestRect
->right
&&
1553 pDestRect
->top
<= pDestRect
->bottom
), D3DERR_INVALIDCALL
);
1554 user_assert(!pSourceRect
||
1555 (pSourceRect
->left
<= pSourceRect
->right
&&
1556 pSourceRect
->top
<= pSourceRect
->bottom
), D3DERR_INVALIDCALL
);
1558 memset(&blit
, 0, sizeof(blit
));
1559 blit
.dst
.resource
= dst_res
;
1560 blit
.dst
.level
= dst
->level
;
1561 blit
.dst
.box
.z
= dst
->layer
;
1562 blit
.dst
.box
.depth
= 1;
1563 blit
.dst
.format
= dst_res
->format
;
1565 flip_x
= pDestRect
->left
> pDestRect
->right
;
1567 blit
.dst
.box
.x
= pDestRect
->right
;
1568 blit
.dst
.box
.width
= pDestRect
->left
- pDestRect
->right
;
1570 blit
.dst
.box
.x
= pDestRect
->left
;
1571 blit
.dst
.box
.width
= pDestRect
->right
- pDestRect
->left
;
1573 flip_y
= pDestRect
->top
> pDestRect
->bottom
;
1575 blit
.dst
.box
.y
= pDestRect
->bottom
;
1576 blit
.dst
.box
.height
= pDestRect
->top
- pDestRect
->bottom
;
1578 blit
.dst
.box
.y
= pDestRect
->top
;
1579 blit
.dst
.box
.height
= pDestRect
->bottom
- pDestRect
->top
;
1584 blit
.dst
.box
.width
= dst
->desc
.Width
;
1585 blit
.dst
.box
.height
= dst
->desc
.Height
;
1587 blit
.src
.resource
= src_res
;
1588 blit
.src
.level
= src
->level
;
1589 blit
.src
.box
.z
= src
->layer
;
1590 blit
.src
.box
.depth
= 1;
1591 blit
.src
.format
= src_res
->format
;
1593 if (flip_x
^ (pSourceRect
->left
> pSourceRect
->right
)) {
1594 blit
.src
.box
.x
= pSourceRect
->right
;
1595 blit
.src
.box
.width
= pSourceRect
->left
- pSourceRect
->right
;
1597 blit
.src
.box
.x
= pSourceRect
->left
;
1598 blit
.src
.box
.width
= pSourceRect
->right
- pSourceRect
->left
;
1600 if (flip_y
^ (pSourceRect
->top
> pSourceRect
->bottom
)) {
1601 blit
.src
.box
.y
= pSourceRect
->bottom
;
1602 blit
.src
.box
.height
= pSourceRect
->top
- pSourceRect
->bottom
;
1604 blit
.src
.box
.y
= pSourceRect
->top
;
1605 blit
.src
.box
.height
= pSourceRect
->bottom
- pSourceRect
->top
;
1608 blit
.src
.box
.x
= flip_x
? src
->desc
.Width
: 0;
1609 blit
.src
.box
.y
= flip_y
? src
->desc
.Height
: 0;
1610 blit
.src
.box
.width
= flip_x
? -src
->desc
.Width
: src
->desc
.Width
;
1611 blit
.src
.box
.height
= flip_y
? -src
->desc
.Height
: src
->desc
.Height
;
1613 blit
.mask
= zs
? PIPE_MASK_ZS
: PIPE_MASK_RGBA
;
1614 blit
.filter
= Filter
== D3DTEXF_LINEAR
?
1615 PIPE_TEX_FILTER_LINEAR
: PIPE_TEX_FILTER_NEAREST
;
1616 blit
.scissor_enable
= FALSE
;
1617 blit
.alpha_blend
= FALSE
;
1619 /* If both of a src and dst dimension are negative, flip them. */
1620 if (blit
.dst
.box
.width
< 0 && blit
.src
.box
.width
< 0) {
1621 blit
.dst
.box
.width
= -blit
.dst
.box
.width
;
1622 blit
.src
.box
.width
= -blit
.src
.box
.width
;
1624 if (blit
.dst
.box
.height
< 0 && blit
.src
.box
.height
< 0) {
1625 blit
.dst
.box
.height
= -blit
.dst
.box
.height
;
1626 blit
.src
.box
.height
= -blit
.src
.box
.height
;
1629 blit
.dst
.box
.width
!= blit
.src
.box
.width
||
1630 blit
.dst
.box
.height
!= blit
.src
.box
.height
;
1632 user_assert(!scaled
|| dst
!= src
, D3DERR_INVALIDCALL
);
1633 user_assert(!scaled
||
1634 !NineSurface9_IsOffscreenPlain(dst
), D3DERR_INVALIDCALL
);
1635 user_assert(!NineSurface9_IsOffscreenPlain(dst
) ||
1636 NineSurface9_IsOffscreenPlain(src
), D3DERR_INVALIDCALL
);
1637 user_assert(NineSurface9_IsOffscreenPlain(dst
) ||
1638 dst
->desc
.Usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
),
1639 D3DERR_INVALIDCALL
);
1640 user_assert(!scaled
||
1641 (!util_format_is_compressed(dst
->base
.info
.format
) &&
1642 !util_format_is_compressed(src
->base
.info
.format
)),
1643 D3DERR_INVALIDCALL
);
1645 user_warn(src
== dst
&&
1646 u_box_test_intersection_2d(&blit
.src
.box
, &blit
.dst
.box
));
1648 /* Check for clipping/clamping: */
1650 struct pipe_box box
;
1653 xy
= u_box_clip_2d(&box
, &blit
.dst
.box
,
1654 dst
->desc
.Width
, dst
->desc
.Height
);
1658 xy
= u_box_clip_2d(&box
, &blit
.src
.box
,
1659 src
->desc
.Width
, src
->desc
.Height
);
1663 ms
= (dst
->desc
.MultiSampleType
| 1) != (src
->desc
.MultiSampleType
| 1);
1665 if (clamped
|| scaled
|| (blit
.dst
.format
!= blit
.src
.format
) || ms
) {
1666 DBG("using pipe->blit()\n");
1667 /* TODO: software scaling */
1668 user_assert(screen
->is_format_supported(screen
, dst_res
->format
,
1670 dst_res
->nr_samples
,
1671 zs
? PIPE_BIND_DEPTH_STENCIL
:
1672 PIPE_BIND_RENDER_TARGET
),
1673 D3DERR_INVALIDCALL
);
1675 pipe
->blit(pipe
, &blit
);
1677 assert(blit
.dst
.box
.x
>= 0 && blit
.dst
.box
.y
>= 0 &&
1678 blit
.src
.box
.x
>= 0 && blit
.src
.box
.y
>= 0 &&
1679 blit
.dst
.box
.x
+ blit
.dst
.box
.width
<= dst
->desc
.Width
&&
1680 blit
.src
.box
.x
+ blit
.src
.box
.width
<= src
->desc
.Width
&&
1681 blit
.dst
.box
.y
+ blit
.dst
.box
.height
<= dst
->desc
.Height
&&
1682 blit
.src
.box
.y
+ blit
.src
.box
.height
<= src
->desc
.Height
);
1683 /* Or drivers might crash ... */
1684 DBG("Using resource_copy_region.\n");
1685 pipe
->resource_copy_region(pipe
,
1686 blit
.dst
.resource
, blit
.dst
.level
,
1687 blit
.dst
.box
.x
, blit
.dst
.box
.y
, blit
.dst
.box
.z
,
1688 blit
.src
.resource
, blit
.src
.level
,
1692 /* Communicate the container it needs to update sublevels - if apply */
1693 NineSurface9_MarkContainerDirty(dst
);
1699 NineDevice9_ColorFill( struct NineDevice9
*This
,
1700 IDirect3DSurface9
*pSurface
,
1704 struct pipe_context
*pipe
= This
->pipe
;
1705 struct NineSurface9
*surf
= NineSurface9(pSurface
);
1706 struct pipe_surface
*psurf
;
1707 unsigned x
, y
, w
, h
;
1708 union pipe_color_union rgba
;
1711 DBG("This=%p pSurface=%p pRect=%p color=%08x\n", This
,
1712 pSurface
, pRect
, color
);
1714 DBG("pRect=(%u,%u)-(%u,%u)\n", pRect
->left
, pRect
->top
,
1715 pRect
->right
, pRect
->bottom
);
1717 user_assert(surf
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1719 user_assert((surf
->base
.usage
& D3DUSAGE_RENDERTARGET
) ||
1720 NineSurface9_IsOffscreenPlain(surf
), D3DERR_INVALIDCALL
);
1722 user_assert(surf
->desc
.Format
!= D3DFMT_NULL
, D3D_OK
);
1727 w
= pRect
->right
- pRect
->left
;
1728 h
= pRect
->bottom
- pRect
->top
;
1730 if (compressed_format(surf
->desc
.Format
)) {
1731 const unsigned bw
= util_format_get_blockwidth(surf
->base
.info
.format
);
1732 const unsigned bh
= util_format_get_blockheight(surf
->base
.info
.format
);
1734 user_assert(!(x
% bw
) && !(y
% bh
) && !(w
% bw
) && !(h
% bh
),
1735 D3DERR_INVALIDCALL
);
1740 w
= surf
->desc
.Width
;
1741 h
= surf
->desc
.Height
;
1743 d3dcolor_to_pipe_color_union(&rgba
, color
);
1745 fallback
= !(surf
->base
.info
.bind
& PIPE_BIND_RENDER_TARGET
);
1748 psurf
= NineSurface9_GetSurface(surf
, 0);
1754 pipe
->clear_render_target(pipe
, psurf
, &rgba
, x
, y
, w
, h
);
1756 D3DLOCKED_RECT lock
;
1757 union util_color uc
;
1759 /* XXX: lock pRect and fix util_fill_rect */
1760 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, 0);
1763 util_pack_color_ub(color
>> 16, color
>> 8, color
>> 0, color
>> 24,
1764 surf
->base
.info
.format
, &uc
);
1765 util_fill_rect(lock
.pBits
, surf
->base
.info
.format
,lock
.Pitch
,
1767 NineSurface9_UnlockRect(surf
);
1774 NineDevice9_CreateOffscreenPlainSurface( struct NineDevice9
*This
,
1779 IDirect3DSurface9
**ppSurface
,
1780 HANDLE
*pSharedHandle
)
1784 DBG("This=%p Width=%u Height=%u Format=%s(0x%x) Pool=%u "
1785 "ppSurface=%p pSharedHandle=%p\n", This
,
1786 Width
, Height
, d3dformat_to_string(Format
), Format
, Pool
,
1787 ppSurface
, pSharedHandle
);
1790 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
1791 || Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1792 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1794 /* Can be used with StretchRect and ColorFill. It's also always lockable.
1796 hr
= create_zs_or_rt_surface(This
, 2, Pool
, Width
, Height
,
1798 D3DMULTISAMPLE_NONE
, 0,
1800 ppSurface
, pSharedHandle
);
1802 DBG("Failed to create surface.\n");
1807 NineDevice9_SetRenderTarget( struct NineDevice9
*This
,
1808 DWORD RenderTargetIndex
,
1809 IDirect3DSurface9
*pRenderTarget
)
1811 struct NineSurface9
*rt
= NineSurface9(pRenderTarget
);
1812 const unsigned i
= RenderTargetIndex
;
1814 DBG("This=%p RenderTargetIndex=%u pRenderTarget=%p\n", This
,
1815 RenderTargetIndex
, pRenderTarget
);
1817 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1818 user_assert(i
!= 0 || pRenderTarget
, D3DERR_INVALIDCALL
);
1819 user_assert(!pRenderTarget
||
1820 rt
->desc
.Usage
& D3DUSAGE_RENDERTARGET
, D3DERR_INVALIDCALL
);
1823 This
->state
.viewport
.X
= 0;
1824 This
->state
.viewport
.Y
= 0;
1825 This
->state
.viewport
.Width
= rt
->desc
.Width
;
1826 This
->state
.viewport
.Height
= rt
->desc
.Height
;
1827 This
->state
.viewport
.MinZ
= 0.0f
;
1828 This
->state
.viewport
.MaxZ
= 1.0f
;
1830 This
->state
.scissor
.minx
= 0;
1831 This
->state
.scissor
.miny
= 0;
1832 This
->state
.scissor
.maxx
= rt
->desc
.Width
;
1833 This
->state
.scissor
.maxy
= rt
->desc
.Height
;
1835 This
->state
.changed
.group
|= NINE_STATE_VIEWPORT
| NINE_STATE_SCISSOR
| NINE_STATE_MULTISAMPLE
;
1838 if (This
->state
.rt
[i
] != NineSurface9(pRenderTarget
)) {
1839 nine_bind(&This
->state
.rt
[i
], pRenderTarget
);
1840 This
->state
.changed
.group
|= NINE_STATE_FB
;
1846 NineDevice9_GetRenderTarget( struct NineDevice9
*This
,
1847 DWORD RenderTargetIndex
,
1848 IDirect3DSurface9
**ppRenderTarget
)
1850 const unsigned i
= RenderTargetIndex
;
1852 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1853 user_assert(ppRenderTarget
, D3DERR_INVALIDCALL
);
1855 *ppRenderTarget
= (IDirect3DSurface9
*)This
->state
.rt
[i
];
1856 if (!This
->state
.rt
[i
])
1857 return D3DERR_NOTFOUND
;
1859 NineUnknown_AddRef(NineUnknown(This
->state
.rt
[i
]));
1864 NineDevice9_SetDepthStencilSurface( struct NineDevice9
*This
,
1865 IDirect3DSurface9
*pNewZStencil
)
1867 DBG("This=%p pNewZStencil=%p\n", This
, pNewZStencil
);
1869 if (This
->state
.ds
!= NineSurface9(pNewZStencil
)) {
1870 nine_bind(&This
->state
.ds
, pNewZStencil
);
1871 This
->state
.changed
.group
|= NINE_STATE_FB
;
1877 NineDevice9_GetDepthStencilSurface( struct NineDevice9
*This
,
1878 IDirect3DSurface9
**ppZStencilSurface
)
1880 user_assert(ppZStencilSurface
, D3DERR_INVALIDCALL
);
1882 *ppZStencilSurface
= (IDirect3DSurface9
*)This
->state
.ds
;
1883 if (!This
->state
.ds
)
1884 return D3DERR_NOTFOUND
;
1886 NineUnknown_AddRef(NineUnknown(This
->state
.ds
));
1891 NineDevice9_BeginScene( struct NineDevice9
*This
)
1893 DBG("This=%p\n", This
);
1894 user_assert(!This
->in_scene
, D3DERR_INVALIDCALL
);
1895 This
->in_scene
= TRUE
;
1896 /* Do we want to do anything else here ? */
1901 NineDevice9_EndScene( struct NineDevice9
*This
)
1903 DBG("This=%p\n", This
);
1904 user_assert(This
->in_scene
, D3DERR_INVALIDCALL
);
1905 This
->in_scene
= FALSE
;
1910 NineDevice9_Clear( struct NineDevice9
*This
,
1912 const D3DRECT
*pRects
,
1918 const int sRGB
= This
->state
.rs
[D3DRS_SRGBWRITEENABLE
] ? 1 : 0;
1919 struct pipe_surface
*cbuf
, *zsbuf
;
1920 struct pipe_context
*pipe
= This
->pipe
;
1921 struct NineSurface9
*zsbuf_surf
= This
->state
.ds
;
1922 struct NineSurface9
*rt
;
1925 union pipe_color_union rgba
;
1926 unsigned rt_mask
= 0;
1929 DBG("This=%p Count=%u pRects=%p Flags=%x Color=%08x Z=%f Stencil=%x\n",
1930 This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1932 user_assert(This
->state
.ds
|| !(Flags
& NINED3DCLEAR_DEPTHSTENCIL
),
1933 D3DERR_INVALIDCALL
);
1934 user_assert(!(Flags
& D3DCLEAR_STENCIL
) ||
1936 util_format_is_depth_and_stencil(zsbuf_surf
->base
.info
.format
)),
1937 D3DERR_INVALIDCALL
);
1939 user_assert((Count
&& pRects
) || (!Count
&& !pRects
), D3DERR_INVALIDCALL
);
1941 user_warn((pRects
&& !Count
) || (!pRects
&& Count
));
1942 if (pRects
&& !Count
)
1948 nine_update_state_framebuffer_clear(This
);
1950 if (Flags
& D3DCLEAR_TARGET
) bufs
|= PIPE_CLEAR_COLOR
;
1951 /* Ignore Z buffer if not bound */
1952 if (This
->state
.fb
.zsbuf
!= NULL
) {
1953 if (Flags
& D3DCLEAR_ZBUFFER
) bufs
|= PIPE_CLEAR_DEPTH
;
1954 if (Flags
& D3DCLEAR_STENCIL
) bufs
|= PIPE_CLEAR_STENCIL
;
1958 d3dcolor_to_pipe_color_union(&rgba
, Color
);
1960 rect
.x1
= This
->state
.viewport
.X
;
1961 rect
.y1
= This
->state
.viewport
.Y
;
1962 rect
.x2
= This
->state
.viewport
.Width
+ rect
.x1
;
1963 rect
.y2
= This
->state
.viewport
.Height
+ rect
.y1
;
1965 /* Both rectangles apply, which is weird, but that's D3D9. */
1966 if (This
->state
.rs
[D3DRS_SCISSORTESTENABLE
]) {
1967 rect
.x1
= MAX2(rect
.x1
, This
->state
.scissor
.minx
);
1968 rect
.y1
= MAX2(rect
.y1
, This
->state
.scissor
.miny
);
1969 rect
.x2
= MIN2(rect
.x2
, This
->state
.scissor
.maxx
);
1970 rect
.y2
= MIN2(rect
.y2
, This
->state
.scissor
.maxy
);
1974 /* Maybe apps like to specify a large rect ? */
1975 if (pRects
[0].x1
<= rect
.x1
&& pRects
[0].x2
>= rect
.x2
&&
1976 pRects
[0].y1
<= rect
.y1
&& pRects
[0].y2
>= rect
.y2
) {
1977 DBG("First rect covers viewport.\n");
1983 if (rect
.x1
>= This
->state
.fb
.width
|| rect
.y1
>= This
->state
.fb
.height
)
1986 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
1987 if (This
->state
.rt
[i
] && This
->state
.rt
[i
]->desc
.Format
!= D3DFMT_NULL
)
1991 /* fast path, clears everything at once */
1993 (!(bufs
& PIPE_CLEAR_COLOR
) || (rt_mask
== This
->state
.rt_mask
)) &&
1994 rect
.x1
== 0 && rect
.y1
== 0 &&
1995 /* Case we clear only render target. Check clear region vs rt. */
1996 ((!(bufs
& (PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
)) &&
1997 rect
.x2
>= This
->state
.fb
.width
&&
1998 rect
.y2
>= This
->state
.fb
.height
) ||
1999 /* Case we clear depth buffer (and eventually rt too).
2000 * depth buffer size is always >= rt size. Compare to clear region */
2001 ((bufs
& (PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
)) &&
2002 rect
.x2
>= zsbuf_surf
->desc
.Width
&&
2003 rect
.y2
>= zsbuf_surf
->desc
.Height
))) {
2004 DBG("Clear fast path\n");
2005 pipe
->clear(pipe
, bufs
, &rgba
, Z
, Stencil
);
2014 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2015 rt
= This
->state
.rt
[i
];
2016 if (!rt
|| rt
->desc
.Format
== D3DFMT_NULL
||
2017 !(bufs
& PIPE_CLEAR_COLOR
))
2018 continue; /* save space, compiler should hoist this */
2019 cbuf
= NineSurface9_GetSurface(rt
, sRGB
);
2020 for (r
= 0; r
< Count
; ++r
) {
2021 /* Don't trust users to pass these in the right order. */
2022 unsigned x1
= MIN2(pRects
[r
].x1
, pRects
[r
].x2
);
2023 unsigned y1
= MIN2(pRects
[r
].y1
, pRects
[r
].y2
);
2024 unsigned x2
= MAX2(pRects
[r
].x1
, pRects
[r
].x2
);
2025 unsigned y2
= MAX2(pRects
[r
].y1
, pRects
[r
].y2
);
2027 /* Drop negative rectangles (like wine expects). */
2028 if (pRects
[r
].x1
> pRects
[r
].x2
) continue;
2029 if (pRects
[r
].y1
> pRects
[r
].y2
) continue;
2032 x1
= MAX2(x1
, rect
.x1
);
2033 y1
= MAX2(y1
, rect
.y1
);
2034 x2
= MIN3(x2
, rect
.x2
, rt
->desc
.Width
);
2035 y2
= MIN3(y2
, rect
.y2
, rt
->desc
.Height
);
2037 DBG("Clearing (%u..%u)x(%u..%u)\n", x1
, x2
, y1
, y2
);
2038 pipe
->clear_render_target(pipe
, cbuf
, &rgba
,
2039 x1
, y1
, x2
- x1
, y2
- y1
);
2042 if (!(bufs
& PIPE_CLEAR_DEPTHSTENCIL
))
2045 bufs
&= PIPE_CLEAR_DEPTHSTENCIL
;
2047 for (r
= 0; r
< Count
; ++r
) {
2048 unsigned x1
= MIN2(pRects
[r
].x1
, pRects
[r
].x2
);
2049 unsigned y1
= MIN2(pRects
[r
].y1
, pRects
[r
].y2
);
2050 unsigned x2
= MAX2(pRects
[r
].x1
, pRects
[r
].x2
);
2051 unsigned y2
= MAX2(pRects
[r
].y1
, pRects
[r
].y2
);
2053 /* Drop negative rectangles. */
2054 if (pRects
[r
].x1
> pRects
[r
].x2
) continue;
2055 if (pRects
[r
].y1
> pRects
[r
].y2
) continue;
2058 x1
= MIN2(x1
, rect
.x1
);
2059 y1
= MIN2(y1
, rect
.y1
);
2060 x2
= MIN3(x2
, rect
.x2
, zsbuf_surf
->desc
.Width
);
2061 y2
= MIN3(y2
, rect
.y2
, zsbuf_surf
->desc
.Height
);
2063 zsbuf
= NineSurface9_GetSurface(zsbuf_surf
, 0);
2065 pipe
->clear_depth_stencil(pipe
, zsbuf
, bufs
, Z
, Stencil
,
2066 x1
, y1
, x2
- x1
, y2
- y1
);
2072 NineDevice9_SetTransform( struct NineDevice9
*This
,
2073 D3DTRANSFORMSTATETYPE State
,
2074 const D3DMATRIX
*pMatrix
)
2076 struct nine_state
*state
= This
->update
;
2077 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
2079 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2081 user_assert(M
, D3DERR_INVALIDCALL
);
2084 state
->ff
.changed
.transform
[State
/ 32] |= 1 << (State
% 32);
2085 state
->changed
.group
|= NINE_STATE_FF
;
2091 NineDevice9_GetTransform( struct NineDevice9
*This
,
2092 D3DTRANSFORMSTATETYPE State
,
2093 D3DMATRIX
*pMatrix
)
2095 D3DMATRIX
*M
= nine_state_access_transform(&This
->state
, State
, FALSE
);
2096 user_assert(M
, D3DERR_INVALIDCALL
);
2102 NineDevice9_MultiplyTransform( struct NineDevice9
*This
,
2103 D3DTRANSFORMSTATETYPE State
,
2104 const D3DMATRIX
*pMatrix
)
2106 struct nine_state
*state
= This
->update
;
2108 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
2110 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2112 user_assert(M
, D3DERR_INVALIDCALL
);
2114 nine_d3d_matrix_matrix_mul(&T
, pMatrix
, M
);
2115 return NineDevice9_SetTransform(This
, State
, &T
);
2119 NineDevice9_SetViewport( struct NineDevice9
*This
,
2120 const D3DVIEWPORT9
*pViewport
)
2122 struct nine_state
*state
= This
->update
;
2124 DBG("X=%u Y=%u W=%u H=%u MinZ=%f MaxZ=%f\n",
2125 pViewport
->X
, pViewport
->Y
, pViewport
->Width
, pViewport
->Height
,
2126 pViewport
->MinZ
, pViewport
->MaxZ
);
2128 state
->viewport
= *pViewport
;
2129 state
->changed
.group
|= NINE_STATE_VIEWPORT
;
2135 NineDevice9_GetViewport( struct NineDevice9
*This
,
2136 D3DVIEWPORT9
*pViewport
)
2138 *pViewport
= This
->state
.viewport
;
2143 NineDevice9_SetMaterial( struct NineDevice9
*This
,
2144 const D3DMATERIAL9
*pMaterial
)
2146 struct nine_state
*state
= This
->update
;
2148 DBG("This=%p pMaterial=%p\n", This
, pMaterial
);
2150 nine_dump_D3DMATERIAL9(DBG_FF
, pMaterial
);
2152 user_assert(pMaterial
, E_POINTER
);
2154 state
->ff
.material
= *pMaterial
;
2155 state
->changed
.group
|= NINE_STATE_FF_MATERIAL
;
2161 NineDevice9_GetMaterial( struct NineDevice9
*This
,
2162 D3DMATERIAL9
*pMaterial
)
2164 user_assert(pMaterial
, E_POINTER
);
2165 *pMaterial
= This
->state
.ff
.material
;
2170 NineDevice9_SetLight( struct NineDevice9
*This
,
2172 const D3DLIGHT9
*pLight
)
2174 struct nine_state
*state
= This
->update
;
2176 DBG("This=%p Index=%u pLight=%p\n", This
, Index
, pLight
);
2178 nine_dump_D3DLIGHT9(DBG_FF
, pLight
);
2180 user_assert(pLight
, D3DERR_INVALIDCALL
);
2181 user_assert(pLight
->Type
< NINED3DLIGHT_INVALID
, D3DERR_INVALIDCALL
);
2183 user_assert(Index
< NINE_MAX_LIGHTS
, D3DERR_INVALIDCALL
); /* sanity */
2185 if (Index
>= state
->ff
.num_lights
) {
2186 unsigned n
= state
->ff
.num_lights
;
2187 unsigned N
= Index
+ 1;
2189 state
->ff
.light
= REALLOC(state
->ff
.light
, n
* sizeof(D3DLIGHT9
),
2190 N
* sizeof(D3DLIGHT9
));
2191 if (!state
->ff
.light
)
2192 return E_OUTOFMEMORY
;
2193 state
->ff
.num_lights
= N
;
2195 for (; n
< Index
; ++n
) {
2196 memset(&state
->ff
.light
[n
], 0, sizeof(D3DLIGHT9
));
2197 state
->ff
.light
[n
].Type
= (D3DLIGHTTYPE
)NINED3DLIGHT_INVALID
;
2200 state
->ff
.light
[Index
] = *pLight
;
2202 if (pLight
->Type
== D3DLIGHT_SPOT
&& pLight
->Theta
>= pLight
->Phi
) {
2203 DBG("Warning: clamping D3DLIGHT9.Theta\n");
2204 state
->ff
.light
[Index
].Theta
= state
->ff
.light
[Index
].Phi
;
2206 if (pLight
->Type
!= D3DLIGHT_DIRECTIONAL
&&
2207 pLight
->Attenuation0
== 0.0f
&&
2208 pLight
->Attenuation1
== 0.0f
&&
2209 pLight
->Attenuation2
== 0.0f
) {
2210 DBG("Warning: all D3DLIGHT9.Attenuation[i] are 0\n");
2213 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2219 NineDevice9_GetLight( struct NineDevice9
*This
,
2223 const struct nine_state
*state
= &This
->state
;
2225 user_assert(pLight
, D3DERR_INVALIDCALL
);
2226 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2227 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2228 D3DERR_INVALIDCALL
);
2230 *pLight
= state
->ff
.light
[Index
];
2236 NineDevice9_LightEnable( struct NineDevice9
*This
,
2240 struct nine_state
*state
= This
->update
;
2243 DBG("This=%p Index=%u Enable=%i\n", This
, Index
, Enable
);
2245 if (Index
>= state
->ff
.num_lights
||
2246 state
->ff
.light
[Index
].Type
== NINED3DLIGHT_INVALID
) {
2247 /* This should create a default light. */
2249 memset(&light
, 0, sizeof(light
));
2250 light
.Type
= D3DLIGHT_DIRECTIONAL
;
2251 light
.Diffuse
.r
= 1.0f
;
2252 light
.Diffuse
.g
= 1.0f
;
2253 light
.Diffuse
.b
= 1.0f
;
2254 light
.Direction
.z
= 1.0f
;
2255 NineDevice9_SetLight(This
, Index
, &light
);
2257 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2259 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
) {
2260 if (state
->ff
.active_light
[i
] == Index
)
2265 if (i
< state
->ff
.num_lights_active
)
2267 /* XXX wine thinks this should still succeed:
2269 user_assert(i
< NINE_MAX_LIGHTS_ACTIVE
, D3DERR_INVALIDCALL
);
2271 state
->ff
.active_light
[i
] = Index
;
2272 state
->ff
.num_lights_active
++;
2274 if (i
== state
->ff
.num_lights_active
)
2276 --state
->ff
.num_lights_active
;
2277 for (; i
< state
->ff
.num_lights_active
; ++i
)
2278 state
->ff
.active_light
[i
] = state
->ff
.active_light
[i
+ 1];
2280 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2286 NineDevice9_GetLightEnable( struct NineDevice9
*This
,
2290 const struct nine_state
*state
= &This
->state
;
2293 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2294 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2295 D3DERR_INVALIDCALL
);
2297 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
)
2298 if (state
->ff
.active_light
[i
] == Index
)
2301 *pEnable
= i
!= state
->ff
.num_lights_active
? 128 : 0; // Taken from wine
2307 NineDevice9_SetClipPlane( struct NineDevice9
*This
,
2309 const float *pPlane
)
2311 struct nine_state
*state
= This
->update
;
2313 user_assert(pPlane
, D3DERR_INVALIDCALL
);
2315 DBG("This=%p Index=%u pPlane=%f %f %f %f\n", This
, Index
,
2316 pPlane
[0], pPlane
[1],
2317 pPlane
[2], pPlane
[3]);
2319 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2321 memcpy(&state
->clip
.ucp
[Index
][0], pPlane
, sizeof(state
->clip
.ucp
[0]));
2322 state
->changed
.ucp
|= 1 << Index
;
2328 NineDevice9_GetClipPlane( struct NineDevice9
*This
,
2332 const struct nine_state
*state
= &This
->state
;
2334 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2336 memcpy(pPlane
, &state
->clip
.ucp
[Index
][0], sizeof(state
->clip
.ucp
[0]));
2340 #define RESZ_CODE 0x7fa05000
2343 NineDevice9_ResolveZ( struct NineDevice9
*This
)
2345 struct nine_state
*state
= &This
->state
;
2346 const struct util_format_description
*desc
;
2347 struct NineSurface9
*source
= state
->ds
;
2348 struct NineBaseTexture9
*destination
= state
->texture
[0];
2349 struct pipe_resource
*src
, *dst
;
2350 struct pipe_blit_info blit
;
2352 DBG("RESZ resolve\n");
2354 user_assert(source
&& destination
&&
2355 destination
->base
.type
== D3DRTYPE_TEXTURE
, D3DERR_INVALIDCALL
);
2357 src
= source
->base
.resource
;
2358 dst
= destination
->base
.resource
;
2360 user_assert(src
&& dst
, D3DERR_INVALIDCALL
);
2362 /* check dst is depth format. we know already for src */
2363 desc
= util_format_description(dst
->format
);
2364 user_assert(desc
->colorspace
== UTIL_FORMAT_COLORSPACE_ZS
, D3DERR_INVALIDCALL
);
2366 memset(&blit
, 0, sizeof(blit
));
2367 blit
.src
.resource
= src
;
2369 blit
.src
.format
= src
->format
;
2371 blit
.src
.box
.depth
= 1;
2374 blit
.src
.box
.width
= src
->width0
;
2375 blit
.src
.box
.height
= src
->height0
;
2377 blit
.dst
.resource
= dst
;
2379 blit
.dst
.format
= dst
->format
;
2381 blit
.dst
.box
.depth
= 1;
2384 blit
.dst
.box
.width
= dst
->width0
;
2385 blit
.dst
.box
.height
= dst
->height0
;
2387 blit
.mask
= PIPE_MASK_ZS
;
2388 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
2389 blit
.scissor_enable
= FALSE
;
2391 This
->pipe
->blit(This
->pipe
, &blit
);
2395 #define ALPHA_TO_COVERAGE_ENABLE MAKEFOURCC('A', '2', 'M', '1')
2396 #define ALPHA_TO_COVERAGE_DISABLE MAKEFOURCC('A', '2', 'M', '0')
2399 NineDevice9_SetRenderState( struct NineDevice9
*This
,
2400 D3DRENDERSTATETYPE State
,
2403 struct nine_state
*state
= This
->update
;
2405 DBG("This=%p State=%u(%s) Value=%08x\n", This
,
2406 State
, nine_d3drs_to_string(State
), Value
);
2408 user_assert(State
< D3DRS_COUNT
, D3DERR_INVALIDCALL
);
2410 if (state
->rs_advertised
[State
] == Value
&& likely(!This
->is_recording
))
2413 state
->rs_advertised
[State
] = Value
;
2415 /* Amd hacks (equivalent to GL extensions) */
2416 if (unlikely(State
== D3DRS_POINTSIZE
)) {
2417 if (Value
== RESZ_CODE
)
2418 return NineDevice9_ResolveZ(This
);
2420 if (Value
== ALPHA_TO_COVERAGE_ENABLE
||
2421 Value
== ALPHA_TO_COVERAGE_DISABLE
) {
2422 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
== ALPHA_TO_COVERAGE_ENABLE
);
2423 state
->changed
.group
|= NINE_STATE_BLEND
;
2429 if (unlikely(State
== D3DRS_ADAPTIVETESS_Y
)) {
2430 if (Value
== D3DFMT_ATOC
|| (Value
== D3DFMT_UNKNOWN
&& state
->rs
[NINED3DRS_ALPHACOVERAGE
])) {
2431 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
== D3DFMT_ATOC
) ? 3 : 0;
2432 state
->rs
[NINED3DRS_ALPHACOVERAGE
] &= state
->rs
[D3DRS_ALPHATESTENABLE
] ? 3 : 2;
2433 state
->changed
.group
|= NINE_STATE_BLEND
;
2437 if (unlikely(State
== D3DRS_ALPHATESTENABLE
&& (state
->rs
[NINED3DRS_ALPHACOVERAGE
] & 2))) {
2438 DWORD alphacoverage_prev
= state
->rs
[NINED3DRS_ALPHACOVERAGE
];
2439 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
? 3 : 2);
2440 if (state
->rs
[NINED3DRS_ALPHACOVERAGE
] != alphacoverage_prev
)
2441 state
->changed
.group
|= NINE_STATE_BLEND
;
2444 state
->rs
[State
] = nine_fix_render_state_value(State
, Value
);
2445 state
->changed
.rs
[State
/ 32] |= 1 << (State
% 32);
2446 state
->changed
.group
|= nine_render_state_group
[State
];
2452 NineDevice9_GetRenderState( struct NineDevice9
*This
,
2453 D3DRENDERSTATETYPE State
,
2456 user_assert(State
< D3DRS_COUNT
, D3DERR_INVALIDCALL
);
2458 *pValue
= This
->state
.rs_advertised
[State
];
2463 NineDevice9_CreateStateBlock( struct NineDevice9
*This
,
2464 D3DSTATEBLOCKTYPE Type
,
2465 IDirect3DStateBlock9
**ppSB
)
2467 struct NineStateBlock9
*nsb
;
2468 struct nine_state
*dst
;
2470 enum nine_stateblock_type type
;
2473 DBG("This=%p Type=%u ppSB=%p\n", This
, Type
, ppSB
);
2475 user_assert(Type
== D3DSBT_ALL
||
2476 Type
== D3DSBT_VERTEXSTATE
||
2477 Type
== D3DSBT_PIXELSTATE
, D3DERR_INVALIDCALL
);
2480 case D3DSBT_VERTEXSTATE
: type
= NINESBT_VERTEXSTATE
; break;
2481 case D3DSBT_PIXELSTATE
: type
= NINESBT_PIXELSTATE
; break;
2487 hr
= NineStateBlock9_new(This
, &nsb
, type
);
2490 *ppSB
= (IDirect3DStateBlock9
*)nsb
;
2493 dst
->changed
.group
=
2494 NINE_STATE_TEXTURE
|
2497 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_VERTEXSTATE
) {
2498 dst
->changed
.group
|=
2499 NINE_STATE_FF_LIGHTING
|
2500 NINE_STATE_VS
| NINE_STATE_VS_CONST
|
2502 /* TODO: texture/sampler state */
2503 memcpy(dst
->changed
.rs
,
2504 nine_render_states_vertex
, sizeof(dst
->changed
.rs
));
2505 nine_ranges_insert(&dst
->changed
.vs_const_f
, 0, This
->max_vs_const_f
,
2507 dst
->changed
.vs_const_i
= 0xffff;
2508 dst
->changed
.vs_const_b
= 0xffff;
2509 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2510 dst
->changed
.sampler
[s
] |= 1 << D3DSAMP_DMAPOFFSET
;
2511 if (This
->state
.ff
.num_lights
) {
2512 dst
->ff
.num_lights
= This
->state
.ff
.num_lights
;
2513 /* zero'd -> light type won't be NINED3DLIGHT_INVALID, so
2514 * all currently existing lights will be captured
2516 dst
->ff
.light
= CALLOC(This
->state
.ff
.num_lights
,
2518 if (!dst
->ff
.light
) {
2519 nine_bind(ppSB
, NULL
);
2520 return E_OUTOFMEMORY
;
2524 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_PIXELSTATE
) {
2525 dst
->changed
.group
|=
2526 NINE_STATE_PS
| NINE_STATE_PS_CONST
;
2527 /* TODO: texture/sampler state */
2528 memcpy(dst
->changed
.rs
,
2529 nine_render_states_pixel
, sizeof(dst
->changed
.rs
));
2530 nine_ranges_insert(&dst
->changed
.ps_const_f
, 0, This
->max_ps_const_f
,
2532 dst
->changed
.ps_const_i
= 0xffff;
2533 dst
->changed
.ps_const_b
= 0xffff;
2534 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2535 dst
->changed
.sampler
[s
] |= 0x1ffe;
2537 if (Type
== D3DSBT_ALL
) {
2538 dst
->changed
.group
|=
2539 NINE_STATE_VIEWPORT
|
2540 NINE_STATE_SCISSOR
|
2541 NINE_STATE_RASTERIZER
|
2545 NINE_STATE_MATERIAL
|
2546 NINE_STATE_BLEND_COLOR
|
2547 NINE_STATE_SAMPLE_MASK
;
2548 memset(dst
->changed
.rs
, ~0, (D3DRS_COUNT
/ 32) * sizeof(uint32_t));
2549 dst
->changed
.rs
[D3DRS_LAST
/ 32] |= (1 << (D3DRS_COUNT
% 32)) - 1;
2550 dst
->changed
.vtxbuf
= (1ULL << This
->caps
.MaxStreams
) - 1;
2551 dst
->changed
.stream_freq
= dst
->changed
.vtxbuf
;
2552 dst
->changed
.ucp
= (1 << PIPE_MAX_CLIP_PLANES
) - 1;
2553 dst
->changed
.texture
= (1 << NINE_MAX_SAMPLERS
) - 1;
2555 NineStateBlock9_Capture(NineStateBlock9(*ppSB
));
2557 /* TODO: fixed function state */
2563 NineDevice9_BeginStateBlock( struct NineDevice9
*This
)
2567 DBG("This=%p\n", This
);
2569 user_assert(!This
->record
, D3DERR_INVALIDCALL
);
2571 hr
= NineStateBlock9_new(This
, &This
->record
, NINESBT_CUSTOM
);
2574 NineUnknown_ConvertRefToBind(NineUnknown(This
->record
));
2576 This
->update
= &This
->record
->state
;
2577 This
->is_recording
= TRUE
;
2583 NineDevice9_EndStateBlock( struct NineDevice9
*This
,
2584 IDirect3DStateBlock9
**ppSB
)
2586 DBG("This=%p ppSB=%p\n", This
, ppSB
);
2588 user_assert(This
->record
, D3DERR_INVALIDCALL
);
2590 This
->update
= &This
->state
;
2591 This
->is_recording
= FALSE
;
2593 NineUnknown_AddRef(NineUnknown(This
->record
));
2594 *ppSB
= (IDirect3DStateBlock9
*)This
->record
;
2595 NineUnknown_Unbind(NineUnknown(This
->record
));
2596 This
->record
= NULL
;
2602 NineDevice9_SetClipStatus( struct NineDevice9
*This
,
2603 const D3DCLIPSTATUS9
*pClipStatus
)
2605 STUB(D3DERR_INVALIDCALL
);
2609 NineDevice9_GetClipStatus( struct NineDevice9
*This
,
2610 D3DCLIPSTATUS9
*pClipStatus
)
2612 STUB(D3DERR_INVALIDCALL
);
2616 NineDevice9_GetTexture( struct NineDevice9
*This
,
2618 IDirect3DBaseTexture9
**ppTexture
)
2620 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2621 Stage
== D3DDMAPSAMPLER
||
2622 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2623 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2624 user_assert(ppTexture
, D3DERR_INVALIDCALL
);
2626 if (Stage
>= D3DDMAPSAMPLER
)
2627 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2629 *ppTexture
= (IDirect3DBaseTexture9
*)This
->state
.texture
[Stage
];
2631 if (This
->state
.texture
[Stage
])
2632 NineUnknown_AddRef(NineUnknown(This
->state
.texture
[Stage
]));
2637 NineDevice9_SetTexture( struct NineDevice9
*This
,
2639 IDirect3DBaseTexture9
*pTexture
)
2641 struct nine_state
*state
= This
->update
;
2642 struct NineBaseTexture9
*tex
= NineBaseTexture9(pTexture
);
2644 DBG("This=%p Stage=%u pTexture=%p\n", This
, Stage
, pTexture
);
2646 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2647 Stage
== D3DDMAPSAMPLER
||
2648 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2649 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2650 user_assert(!tex
|| (tex
->base
.pool
!= D3DPOOL_SCRATCH
&&
2651 tex
->base
.pool
!= D3DPOOL_SYSTEMMEM
), D3DERR_INVALIDCALL
);
2653 if (Stage
>= D3DDMAPSAMPLER
)
2654 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2656 if (!This
->is_recording
) {
2657 struct NineBaseTexture9
*old
= state
->texture
[Stage
];
2661 state
->samplers_shadow
&= ~(1 << Stage
);
2663 state
->samplers_shadow
|= tex
->shadow
<< Stage
;
2665 if ((tex
->managed
.dirty
| tex
->dirty_mip
) && LIST_IS_EMPTY(&tex
->list
))
2666 list_add(&tex
->list
, &This
->update_textures
);
2673 nine_bind(&state
->texture
[Stage
], pTexture
);
2675 state
->changed
.texture
|= 1 << Stage
;
2676 state
->changed
.group
|= NINE_STATE_TEXTURE
;
2682 NineDevice9_GetTextureStageState( struct NineDevice9
*This
,
2684 D3DTEXTURESTAGESTATETYPE Type
,
2687 const struct nine_state
*state
= &This
->state
;
2689 user_assert(Stage
< ARRAY_SIZE(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2690 user_assert(Type
< ARRAY_SIZE(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2692 *pValue
= state
->ff
.tex_stage
[Stage
][Type
];
2698 NineDevice9_SetTextureStageState( struct NineDevice9
*This
,
2700 D3DTEXTURESTAGESTATETYPE Type
,
2703 struct nine_state
*state
= This
->update
;
2704 int bumpmap_index
= -1;
2706 DBG("Stage=%u Type=%u Value=%08x\n", Stage
, Type
, Value
);
2707 nine_dump_D3DTSS_value(DBG_FF
, Type
, Value
);
2709 user_assert(Stage
< ARRAY_SIZE(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2710 user_assert(Type
< ARRAY_SIZE(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2712 state
->ff
.tex_stage
[Stage
][Type
] = Value
;
2714 case D3DTSS_BUMPENVMAT00
:
2715 bumpmap_index
= 4 * Stage
;
2717 case D3DTSS_BUMPENVMAT10
:
2718 bumpmap_index
= 4 * Stage
+ 1;
2720 case D3DTSS_BUMPENVMAT01
:
2721 bumpmap_index
= 4 * Stage
+ 2;
2723 case D3DTSS_BUMPENVMAT11
:
2724 bumpmap_index
= 4 * Stage
+ 3;
2726 case D3DTSS_BUMPENVLSCALE
:
2727 bumpmap_index
= 4 * 8 + 2 * Stage
;
2729 case D3DTSS_BUMPENVLOFFSET
:
2730 bumpmap_index
= 4 * 8 + 2 * Stage
+ 1;
2732 case D3DTSS_TEXTURETRANSFORMFLAGS
:
2733 state
->changed
.group
|= NINE_STATE_PS1X_SHADER
;
2739 if (bumpmap_index
>= 0) {
2740 state
->bumpmap_vars
[bumpmap_index
] = Value
;
2741 state
->changed
.group
|= NINE_STATE_PS_CONST
;
2744 state
->changed
.group
|= NINE_STATE_FF_PSSTAGES
;
2745 state
->ff
.changed
.tex_stage
[Stage
][Type
/ 32] |= 1 << (Type
% 32);
2751 NineDevice9_GetSamplerState( struct NineDevice9
*This
,
2753 D3DSAMPLERSTATETYPE Type
,
2756 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2757 Sampler
== D3DDMAPSAMPLER
||
2758 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2759 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2761 if (Sampler
>= D3DDMAPSAMPLER
)
2762 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2764 *pValue
= This
->state
.samp
[Sampler
][Type
];
2769 NineDevice9_SetSamplerState( struct NineDevice9
*This
,
2771 D3DSAMPLERSTATETYPE Type
,
2774 struct nine_state
*state
= This
->update
;
2776 DBG("This=%p Sampler=%u Type=%s Value=%08x\n", This
,
2777 Sampler
, nine_D3DSAMP_to_str(Type
), Value
);
2779 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2780 Sampler
== D3DDMAPSAMPLER
||
2781 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2782 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2784 if (Sampler
>= D3DDMAPSAMPLER
)
2785 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2787 if (state
->samp
[Sampler
][Type
] != Value
|| unlikely(This
->is_recording
)) {
2788 state
->samp
[Sampler
][Type
] = Value
;
2789 state
->changed
.group
|= NINE_STATE_SAMPLER
;
2790 state
->changed
.sampler
[Sampler
] |= 1 << Type
;
2797 NineDevice9_ValidateDevice( struct NineDevice9
*This
,
2800 const struct nine_state
*state
= &This
->state
;
2802 unsigned w
= 0, h
= 0;
2804 DBG("This=%p pNumPasses=%p\n", This
, pNumPasses
);
2806 for (i
= 0; i
< ARRAY_SIZE(state
->samp
); ++i
) {
2807 if (state
->samp
[i
][D3DSAMP_MINFILTER
] == D3DTEXF_NONE
||
2808 state
->samp
[i
][D3DSAMP_MAGFILTER
] == D3DTEXF_NONE
)
2809 return D3DERR_UNSUPPORTEDTEXTUREFILTER
;
2812 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2816 w
= state
->rt
[i
]->desc
.Width
;
2817 h
= state
->rt
[i
]->desc
.Height
;
2819 if (state
->rt
[i
]->desc
.Width
!= w
|| state
->rt
[i
]->desc
.Height
!= h
) {
2820 return D3DERR_CONFLICTINGRENDERSTATE
;
2824 (state
->rs
[D3DRS_ZENABLE
] || state
->rs
[D3DRS_STENCILENABLE
])) {
2826 (state
->ds
->desc
.Width
!= w
|| state
->ds
->desc
.Height
!= h
))
2827 return D3DERR_CONFLICTINGRENDERSTATE
;
2837 NineDevice9_SetPaletteEntries( struct NineDevice9
*This
,
2839 const PALETTEENTRY
*pEntries
)
2841 STUB(D3D_OK
); /* like wine */
2845 NineDevice9_GetPaletteEntries( struct NineDevice9
*This
,
2847 PALETTEENTRY
*pEntries
)
2849 STUB(D3DERR_INVALIDCALL
);
2853 NineDevice9_SetCurrentTexturePalette( struct NineDevice9
*This
,
2854 UINT PaletteNumber
)
2856 STUB(D3D_OK
); /* like wine */
2860 NineDevice9_GetCurrentTexturePalette( struct NineDevice9
*This
,
2861 UINT
*PaletteNumber
)
2863 STUB(D3DERR_INVALIDCALL
);
2867 NineDevice9_SetScissorRect( struct NineDevice9
*This
,
2870 struct nine_state
*state
= This
->update
;
2872 DBG("x=(%u..%u) y=(%u..%u)\n",
2873 pRect
->left
, pRect
->top
, pRect
->right
, pRect
->bottom
);
2875 state
->scissor
.minx
= pRect
->left
;
2876 state
->scissor
.miny
= pRect
->top
;
2877 state
->scissor
.maxx
= pRect
->right
;
2878 state
->scissor
.maxy
= pRect
->bottom
;
2880 state
->changed
.group
|= NINE_STATE_SCISSOR
;
2886 NineDevice9_GetScissorRect( struct NineDevice9
*This
,
2889 pRect
->left
= This
->state
.scissor
.minx
;
2890 pRect
->top
= This
->state
.scissor
.miny
;
2891 pRect
->right
= This
->state
.scissor
.maxx
;
2892 pRect
->bottom
= This
->state
.scissor
.maxy
;
2898 NineDevice9_SetSoftwareVertexProcessing( struct NineDevice9
*This
,
2901 STUB(D3DERR_INVALIDCALL
);
2905 NineDevice9_GetSoftwareVertexProcessing( struct NineDevice9
*This
)
2907 return !!(This
->params
.BehaviorFlags
& D3DCREATE_SOFTWARE_VERTEXPROCESSING
);
2911 NineDevice9_SetNPatchMode( struct NineDevice9
*This
,
2914 STUB(D3DERR_INVALIDCALL
);
2918 NineDevice9_GetNPatchMode( struct NineDevice9
*This
)
2924 init_draw_info(struct pipe_draw_info
*info
,
2925 struct NineDevice9
*dev
, D3DPRIMITIVETYPE type
, UINT count
)
2927 info
->mode
= d3dprimitivetype_to_pipe_prim(type
);
2928 info
->count
= prim_count_to_vertex_count(type
, count
);
2929 info
->start_instance
= 0;
2930 info
->instance_count
= 1;
2931 if (dev
->state
.stream_instancedata_mask
& dev
->state
.stream_usage_mask
)
2932 info
->instance_count
= MAX2(dev
->state
.stream_freq
[0] & 0x7FFFFF, 1);
2933 info
->primitive_restart
= FALSE
;
2934 info
->restart_index
= 0;
2935 info
->count_from_stream_output
= NULL
;
2936 info
->indirect
= NULL
;
2940 NineDevice9_DrawPrimitive( struct NineDevice9
*This
,
2941 D3DPRIMITIVETYPE PrimitiveType
,
2943 UINT PrimitiveCount
)
2945 struct pipe_draw_info info
;
2947 DBG("iface %p, PrimitiveType %u, StartVertex %u, PrimitiveCount %u\n",
2948 This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2950 nine_update_state(This
);
2952 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2953 info
.indexed
= FALSE
;
2954 info
.start
= StartVertex
;
2955 info
.index_bias
= 0;
2956 info
.min_index
= info
.start
;
2957 info
.max_index
= info
.count
- 1;
2959 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2965 NineDevice9_DrawIndexedPrimitive( struct NineDevice9
*This
,
2966 D3DPRIMITIVETYPE PrimitiveType
,
2967 INT BaseVertexIndex
,
2968 UINT MinVertexIndex
,
2971 UINT PrimitiveCount
)
2973 struct pipe_draw_info info
;
2975 DBG("iface %p, PrimitiveType %u, BaseVertexIndex %u, MinVertexIndex %u "
2976 "NumVertices %u, StartIndex %u, PrimitiveCount %u\n",
2977 This
, PrimitiveType
, BaseVertexIndex
, MinVertexIndex
, NumVertices
,
2978 StartIndex
, PrimitiveCount
);
2980 user_assert(This
->state
.idxbuf
, D3DERR_INVALIDCALL
);
2981 user_assert(This
->state
.vdecl
, D3DERR_INVALIDCALL
);
2983 nine_update_state(This
);
2985 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2986 info
.indexed
= TRUE
;
2987 info
.start
= StartIndex
;
2988 info
.index_bias
= BaseVertexIndex
;
2989 /* These don't include index bias: */
2990 info
.min_index
= MinVertexIndex
;
2991 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
2993 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2999 NineDevice9_DrawPrimitiveUP( struct NineDevice9
*This
,
3000 D3DPRIMITIVETYPE PrimitiveType
,
3001 UINT PrimitiveCount
,
3002 const void *pVertexStreamZeroData
,
3003 UINT VertexStreamZeroStride
)
3005 struct pipe_vertex_buffer vtxbuf
;
3006 struct pipe_draw_info info
;
3008 DBG("iface %p, PrimitiveType %u, PrimitiveCount %u, data %p, stride %u\n",
3009 This
, PrimitiveType
, PrimitiveCount
,
3010 pVertexStreamZeroData
, VertexStreamZeroStride
);
3012 user_assert(pVertexStreamZeroData
&& VertexStreamZeroStride
,
3013 D3DERR_INVALIDCALL
);
3015 nine_update_state(This
);
3017 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
3018 info
.indexed
= FALSE
;
3020 info
.index_bias
= 0;
3022 info
.max_index
= info
.count
- 1;
3024 vtxbuf
.stride
= VertexStreamZeroStride
;
3025 vtxbuf
.buffer_offset
= 0;
3026 vtxbuf
.buffer
= NULL
;
3027 vtxbuf
.user_buffer
= pVertexStreamZeroData
;
3029 if (!This
->driver_caps
.user_vbufs
) {
3030 u_upload_data(This
->vertex_uploader
,
3032 (info
.max_index
+ 1) * VertexStreamZeroStride
, /* XXX */
3035 &vtxbuf
.buffer_offset
,
3037 u_upload_unmap(This
->vertex_uploader
);
3038 vtxbuf
.user_buffer
= NULL
;
3041 This
->pipe
->set_vertex_buffers(This
->pipe
, 0, 1, &vtxbuf
);
3043 This
->pipe
->draw_vbo(This
->pipe
, &info
);
3045 NineDevice9_PauseRecording(This
);
3046 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
3047 NineDevice9_ResumeRecording(This
);
3049 pipe_resource_reference(&vtxbuf
.buffer
, NULL
);
3055 NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9
*This
,
3056 D3DPRIMITIVETYPE PrimitiveType
,
3057 UINT MinVertexIndex
,
3059 UINT PrimitiveCount
,
3060 const void *pIndexData
,
3061 D3DFORMAT IndexDataFormat
,
3062 const void *pVertexStreamZeroData
,
3063 UINT VertexStreamZeroStride
)
3065 struct pipe_draw_info info
;
3066 struct pipe_vertex_buffer vbuf
;
3067 struct pipe_index_buffer ibuf
;
3069 DBG("iface %p, PrimitiveType %u, MinVertexIndex %u, NumVertices %u "
3070 "PrimitiveCount %u, pIndexData %p, IndexDataFormat %u "
3071 "pVertexStreamZeroData %p, VertexStreamZeroStride %u\n",
3072 This
, PrimitiveType
, MinVertexIndex
, NumVertices
, PrimitiveCount
,
3073 pIndexData
, IndexDataFormat
,
3074 pVertexStreamZeroData
, VertexStreamZeroStride
);
3076 user_assert(pIndexData
&& pVertexStreamZeroData
, D3DERR_INVALIDCALL
);
3077 user_assert(VertexStreamZeroStride
, D3DERR_INVALIDCALL
);
3078 user_assert(IndexDataFormat
== D3DFMT_INDEX16
||
3079 IndexDataFormat
== D3DFMT_INDEX32
, D3DERR_INVALIDCALL
);
3081 nine_update_state(This
);
3083 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
3084 info
.indexed
= TRUE
;
3086 info
.index_bias
= 0;
3087 info
.min_index
= MinVertexIndex
;
3088 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
3090 vbuf
.stride
= VertexStreamZeroStride
;
3091 vbuf
.buffer_offset
= 0;
3093 vbuf
.user_buffer
= pVertexStreamZeroData
;
3095 ibuf
.index_size
= (IndexDataFormat
== D3DFMT_INDEX16
) ? 2 : 4;
3098 ibuf
.user_buffer
= pIndexData
;
3100 if (!This
->driver_caps
.user_vbufs
) {
3101 const unsigned base
= info
.min_index
* VertexStreamZeroStride
;
3102 u_upload_data(This
->vertex_uploader
,
3105 info
.min_index
+ 1) * VertexStreamZeroStride
, /* XXX */
3107 (const uint8_t *)vbuf
.user_buffer
+ base
,
3108 &vbuf
.buffer_offset
,
3110 u_upload_unmap(This
->vertex_uploader
);
3111 /* Won't be used: */
3112 vbuf
.buffer_offset
-= base
;
3113 vbuf
.user_buffer
= NULL
;
3115 if (!This
->driver_caps
.user_ibufs
) {
3116 u_upload_data(This
->index_uploader
,
3118 info
.count
* ibuf
.index_size
,
3123 u_upload_unmap(This
->index_uploader
);
3124 ibuf
.user_buffer
= NULL
;
3127 This
->pipe
->set_vertex_buffers(This
->pipe
, 0, 1, &vbuf
);
3128 This
->pipe
->set_index_buffer(This
->pipe
, &ibuf
);
3130 This
->pipe
->draw_vbo(This
->pipe
, &info
);
3132 pipe_resource_reference(&vbuf
.buffer
, NULL
);
3133 pipe_resource_reference(&ibuf
.buffer
, NULL
);
3135 NineDevice9_PauseRecording(This
);
3136 NineDevice9_SetIndices(This
, NULL
);
3137 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
3138 NineDevice9_ResumeRecording(This
);
3143 /* TODO: Write to pDestBuffer directly if vertex declaration contains
3147 NineDevice9_ProcessVertices( struct NineDevice9
*This
,
3151 IDirect3DVertexBuffer9
*pDestBuffer
,
3152 IDirect3DVertexDeclaration9
*pVertexDecl
,
3155 struct pipe_screen
*screen
= This
->screen
;
3156 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pVertexDecl
);
3157 struct NineVertexShader9
*vs
;
3158 struct pipe_resource
*resource
;
3159 struct pipe_stream_output_target
*target
;
3160 struct pipe_draw_info draw
;
3162 unsigned buffer_offset
, buffer_size
;
3164 DBG("This=%p SrcStartIndex=%u DestIndex=%u VertexCount=%u "
3165 "pDestBuffer=%p pVertexDecl=%p Flags=%d\n",
3166 This
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
,
3167 pVertexDecl
, Flags
);
3169 if (!screen
->get_param(screen
, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
))
3170 STUB(D3DERR_INVALIDCALL
);
3172 nine_update_state(This
);
3174 /* TODO: Create shader with stream output. */
3175 STUB(D3DERR_INVALIDCALL
);
3176 struct NineVertexBuffer9
*dst
= NineVertexBuffer9(pDestBuffer
);
3178 vs
= This
->state
.vs
? This
->state
.vs
: This
->ff
.vs
;
3180 buffer_size
= VertexCount
* vs
->so
->stride
[0];
3182 struct pipe_resource templ
;
3184 templ
.target
= PIPE_BUFFER
;
3185 templ
.format
= PIPE_FORMAT_R8_UNORM
;
3186 templ
.width0
= buffer_size
;
3188 templ
.bind
= PIPE_BIND_STREAM_OUTPUT
;
3189 templ
.usage
= PIPE_USAGE_STREAM
;
3190 templ
.height0
= templ
.depth0
= templ
.array_size
= 1;
3191 templ
.last_level
= templ
.nr_samples
= 0;
3193 resource
= This
->screen
->resource_create(This
->screen
, &templ
);
3195 return E_OUTOFMEMORY
;
3198 /* SO matches vertex declaration */
3199 resource
= NineVertexBuffer9_GetResource(dst
);
3200 buffer_offset
= DestIndex
* vs
->so
->stride
[0];
3202 target
= This
->pipe
->create_stream_output_target(This
->pipe
, resource
,
3206 pipe_resource_reference(&resource
, NULL
);
3207 return D3DERR_DRIVERINTERNALERROR
;
3211 hr
= NineVertexDeclaration9_new_from_fvf(This
, dst
->desc
.FVF
, &vdecl
);
3216 init_draw_info(&draw
, This
, D3DPT_POINTLIST
, VertexCount
);
3217 draw
.instance_count
= 1;
3218 draw
.indexed
= FALSE
;
3219 draw
.start
= SrcStartIndex
;
3220 draw
.index_bias
= 0;
3221 draw
.min_index
= SrcStartIndex
;
3222 draw
.max_index
= SrcStartIndex
+ VertexCount
- 1;
3224 This
->pipe
->set_stream_output_targets(This
->pipe
, 1, &target
, 0);
3225 This
->pipe
->draw_vbo(This
->pipe
, &draw
);
3226 This
->pipe
->set_stream_output_targets(This
->pipe
, 0, NULL
, 0);
3227 This
->pipe
->stream_output_target_destroy(This
->pipe
, target
);
3229 hr
= NineVertexDeclaration9_ConvertStreamOutput(vdecl
,
3230 dst
, DestIndex
, VertexCount
,
3233 pipe_resource_reference(&resource
, NULL
);
3235 NineUnknown_Release(NineUnknown(vdecl
));
3240 NineDevice9_CreateVertexDeclaration( struct NineDevice9
*This
,
3241 const D3DVERTEXELEMENT9
*pVertexElements
,
3242 IDirect3DVertexDeclaration9
**ppDecl
)
3244 struct NineVertexDeclaration9
*vdecl
;
3246 DBG("This=%p pVertexElements=%p ppDecl=%p\n",
3247 This
, pVertexElements
, ppDecl
);
3249 HRESULT hr
= NineVertexDeclaration9_new(This
, pVertexElements
, &vdecl
);
3251 *ppDecl
= (IDirect3DVertexDeclaration9
*)vdecl
;
3257 NineDevice9_SetVertexDeclaration( struct NineDevice9
*This
,
3258 IDirect3DVertexDeclaration9
*pDecl
)
3260 struct nine_state
*state
= This
->update
;
3261 BOOL was_programmable_vs
= This
->state
.programmable_vs
;
3263 DBG("This=%p pDecl=%p\n", This
, pDecl
);
3265 if (likely(!This
->is_recording
) && state
->vdecl
== NineVertexDeclaration9(pDecl
))
3268 nine_bind(&state
->vdecl
, pDecl
);
3270 This
->state
.programmable_vs
= This
->state
.vs
&& !(This
->state
.vdecl
&& This
->state
.vdecl
->position_t
);
3271 if (likely(!This
->is_recording
) && was_programmable_vs
!= This
->state
.programmable_vs
) {
3272 state
->commit
|= NINE_STATE_COMMIT_CONST_VS
;
3273 state
->changed
.group
|= NINE_STATE_VS
;
3276 state
->changed
.group
|= NINE_STATE_VDECL
;
3282 NineDevice9_GetVertexDeclaration( struct NineDevice9
*This
,
3283 IDirect3DVertexDeclaration9
**ppDecl
)
3285 user_assert(ppDecl
, D3DERR_INVALIDCALL
);
3287 *ppDecl
= (IDirect3DVertexDeclaration9
*)This
->state
.vdecl
;
3289 NineUnknown_AddRef(NineUnknown(*ppDecl
));
3294 NineDevice9_SetFVF( struct NineDevice9
*This
,
3297 struct NineVertexDeclaration9
*vdecl
;
3300 DBG("FVF = %08x\n", FVF
);
3302 return D3D_OK
; /* like wine */
3304 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
3306 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
3310 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
3311 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
3313 return NineDevice9_SetVertexDeclaration(
3314 This
, (IDirect3DVertexDeclaration9
*)vdecl
);
3318 NineDevice9_GetFVF( struct NineDevice9
*This
,
3321 *pFVF
= This
->state
.vdecl
? This
->state
.vdecl
->fvf
: 0;
3326 NineDevice9_CreateVertexShader( struct NineDevice9
*This
,
3327 const DWORD
*pFunction
,
3328 IDirect3DVertexShader9
**ppShader
)
3330 struct NineVertexShader9
*vs
;
3333 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3335 hr
= NineVertexShader9_new(This
, &vs
, pFunction
, NULL
);
3338 *ppShader
= (IDirect3DVertexShader9
*)vs
;
3343 NineDevice9_SetVertexShader( struct NineDevice9
*This
,
3344 IDirect3DVertexShader9
*pShader
)
3346 struct nine_state
*state
= This
->update
;
3347 BOOL was_programmable_vs
= This
->state
.programmable_vs
;
3349 DBG("This=%p pShader=%p\n", This
, pShader
);
3351 if (!This
->is_recording
&& state
->vs
== (struct NineVertexShader9
*)pShader
)
3354 nine_bind(&state
->vs
, pShader
);
3356 This
->state
.programmable_vs
= This
->state
.vs
&& !(This
->state
.vdecl
&& This
->state
.vdecl
->position_t
);
3358 /* ff -> non-ff: commit back non-ff constants */
3359 if (!was_programmable_vs
&& This
->state
.programmable_vs
)
3360 state
->commit
|= NINE_STATE_COMMIT_CONST_VS
;
3362 state
->changed
.group
|= NINE_STATE_VS
;
3368 NineDevice9_GetVertexShader( struct NineDevice9
*This
,
3369 IDirect3DVertexShader9
**ppShader
)
3371 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3372 nine_reference_set(ppShader
, This
->state
.vs
);
3377 NineDevice9_SetVertexShaderConstantF( struct NineDevice9
*This
,
3379 const float *pConstantData
,
3380 UINT Vector4fCount
)
3382 struct nine_state
*state
= This
->update
;
3384 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3385 This
, StartRegister
, pConstantData
, Vector4fCount
);
3387 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3388 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3392 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3394 if (!This
->is_recording
) {
3395 if (!memcmp(&state
->vs_const_f
[StartRegister
* 4], pConstantData
,
3396 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0])))
3400 memcpy(&state
->vs_const_f
[StartRegister
* 4],
3402 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3404 nine_ranges_insert(&state
->changed
.vs_const_f
,
3405 StartRegister
, StartRegister
+ Vector4fCount
,
3408 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3414 NineDevice9_GetVertexShaderConstantF( struct NineDevice9
*This
,
3416 float *pConstantData
,
3417 UINT Vector4fCount
)
3419 const struct nine_state
*state
= &This
->state
;
3421 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3422 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3423 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3425 memcpy(pConstantData
,
3426 &state
->vs_const_f
[StartRegister
* 4],
3427 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3433 NineDevice9_SetVertexShaderConstantI( struct NineDevice9
*This
,
3435 const int *pConstantData
,
3436 UINT Vector4iCount
)
3438 struct nine_state
*state
= This
->update
;
3441 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3442 This
, StartRegister
, pConstantData
, Vector4iCount
);
3444 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3445 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3446 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3448 if (This
->driver_caps
.vs_integer
) {
3449 if (!This
->is_recording
) {
3450 if (!memcmp(&state
->vs_const_i
[StartRegister
][0], pConstantData
,
3451 Vector4iCount
* sizeof(state
->vs_const_i
[0])))
3454 memcpy(&state
->vs_const_i
[StartRegister
][0],
3456 Vector4iCount
* sizeof(state
->vs_const_i
[0]));
3458 for (i
= 0; i
< Vector4iCount
; i
++) {
3459 state
->vs_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3460 state
->vs_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3461 state
->vs_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3462 state
->vs_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3466 state
->changed
.vs_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3467 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3473 NineDevice9_GetVertexShaderConstantI( struct NineDevice9
*This
,
3476 UINT Vector4iCount
)
3478 const struct nine_state
*state
= &This
->state
;
3481 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3482 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3483 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3485 if (This
->driver_caps
.vs_integer
) {
3486 memcpy(pConstantData
,
3487 &state
->vs_const_i
[StartRegister
][0],
3488 Vector4iCount
* sizeof(state
->vs_const_i
[0]));
3490 for (i
= 0; i
< Vector4iCount
; i
++) {
3491 pConstantData
[4*i
] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][0]);
3492 pConstantData
[4*i
+1] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][1]);
3493 pConstantData
[4*i
+2] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][2]);
3494 pConstantData
[4*i
+3] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][3]);
3502 NineDevice9_SetVertexShaderConstantB( struct NineDevice9
*This
,
3504 const BOOL
*pConstantData
,
3507 struct nine_state
*state
= This
->update
;
3509 uint32_t bool_true
= This
->driver_caps
.vs_integer
? 0xFFFFFFFF : fui(1.0f
);
3511 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3512 This
, StartRegister
, pConstantData
, BoolCount
);
3514 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3515 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3516 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3518 if (!This
->is_recording
) {
3519 bool noChange
= true;
3520 for (i
= 0; i
< BoolCount
; i
++) {
3521 if (!!state
->vs_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3528 for (i
= 0; i
< BoolCount
; i
++)
3529 state
->vs_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3531 state
->changed
.vs_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3532 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3538 NineDevice9_GetVertexShaderConstantB( struct NineDevice9
*This
,
3540 BOOL
*pConstantData
,
3543 const struct nine_state
*state
= &This
->state
;
3546 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3547 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3548 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3550 for (i
= 0; i
< BoolCount
; i
++)
3551 pConstantData
[i
] = state
->vs_const_b
[StartRegister
+ i
] != 0 ? TRUE
: FALSE
;
3557 NineDevice9_SetStreamSource( struct NineDevice9
*This
,
3559 IDirect3DVertexBuffer9
*pStreamData
,
3563 struct nine_state
*state
= This
->update
;
3564 struct NineVertexBuffer9
*pVBuf9
= NineVertexBuffer9(pStreamData
);
3565 const unsigned i
= StreamNumber
;
3567 DBG("This=%p StreamNumber=%u pStreamData=%p OffsetInBytes=%u Stride=%u\n",
3568 This
, StreamNumber
, pStreamData
, OffsetInBytes
, Stride
);
3570 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3571 user_assert(Stride
<= This
->caps
.MaxStreamStride
, D3DERR_INVALIDCALL
);
3573 if (likely(!This
->is_recording
)) {
3574 if (state
->stream
[i
] == NineVertexBuffer9(pStreamData
) &&
3575 state
->vtxbuf
[i
].stride
== Stride
&&
3576 state
->vtxbuf
[i
].buffer_offset
== OffsetInBytes
)
3579 nine_bind(&state
->stream
[i
], pStreamData
);
3581 state
->changed
.vtxbuf
|= 1 << StreamNumber
;
3584 state
->vtxbuf
[i
].stride
= Stride
;
3585 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3587 pipe_resource_reference(&state
->vtxbuf
[i
].buffer
,
3588 pStreamData
? NineVertexBuffer9_GetResource(pVBuf9
) : NULL
);
3594 NineDevice9_GetStreamSource( struct NineDevice9
*This
,
3596 IDirect3DVertexBuffer9
**ppStreamData
,
3597 UINT
*pOffsetInBytes
,
3600 const struct nine_state
*state
= &This
->state
;
3601 const unsigned i
= StreamNumber
;
3603 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3604 user_assert(ppStreamData
, D3DERR_INVALIDCALL
);
3606 nine_reference_set(ppStreamData
, state
->stream
[i
]);
3607 *pStride
= state
->vtxbuf
[i
].stride
;
3608 *pOffsetInBytes
= state
->vtxbuf
[i
].buffer_offset
;
3614 NineDevice9_SetStreamSourceFreq( struct NineDevice9
*This
,
3618 struct nine_state
*state
= This
->update
;
3619 /* const UINT freq = Setting & 0x7FFFFF; */
3621 DBG("This=%p StreamNumber=%u FrequencyParameter=0x%x\n", This
,
3622 StreamNumber
, Setting
);
3624 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3625 user_assert(StreamNumber
!= 0 || !(Setting
& D3DSTREAMSOURCE_INSTANCEDATA
),
3626 D3DERR_INVALIDCALL
);
3627 user_assert(!((Setting
& D3DSTREAMSOURCE_INSTANCEDATA
) &&
3628 (Setting
& D3DSTREAMSOURCE_INDEXEDDATA
)), D3DERR_INVALIDCALL
);
3629 user_assert(Setting
, D3DERR_INVALIDCALL
);
3631 if (likely(!This
->is_recording
) && state
->stream_freq
[StreamNumber
] == Setting
)
3634 state
->stream_freq
[StreamNumber
] = Setting
;
3636 if (Setting
& D3DSTREAMSOURCE_INSTANCEDATA
)
3637 state
->stream_instancedata_mask
|= 1 << StreamNumber
;
3639 state
->stream_instancedata_mask
&= ~(1 << StreamNumber
);
3641 state
->changed
.stream_freq
|= 1 << StreamNumber
; /* Used for stateblocks */
3642 if (StreamNumber
!= 0)
3643 state
->changed
.group
|= NINE_STATE_STREAMFREQ
;
3648 NineDevice9_GetStreamSourceFreq( struct NineDevice9
*This
,
3652 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3653 *pSetting
= This
->state
.stream_freq
[StreamNumber
];
3658 NineDevice9_SetIndices( struct NineDevice9
*This
,
3659 IDirect3DIndexBuffer9
*pIndexData
)
3661 struct nine_state
*state
= This
->update
;
3663 DBG("This=%p pIndexData=%p\n", This
, pIndexData
);
3665 if (likely(!This
->is_recording
))
3666 if (state
->idxbuf
== NineIndexBuffer9(pIndexData
))
3668 nine_bind(&state
->idxbuf
, pIndexData
);
3670 state
->changed
.group
|= NINE_STATE_IDXBUF
;
3675 /* XXX: wine/d3d9 doesn't have pBaseVertexIndex, and it doesn't make sense
3676 * here because it's an argument passed to the Draw calls.
3679 NineDevice9_GetIndices( struct NineDevice9
*This
,
3680 IDirect3DIndexBuffer9
**ppIndexData
)
3682 user_assert(ppIndexData
, D3DERR_INVALIDCALL
);
3683 nine_reference_set(ppIndexData
, This
->state
.idxbuf
);
3688 NineDevice9_CreatePixelShader( struct NineDevice9
*This
,
3689 const DWORD
*pFunction
,
3690 IDirect3DPixelShader9
**ppShader
)
3692 struct NinePixelShader9
*ps
;
3695 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3697 hr
= NinePixelShader9_new(This
, &ps
, pFunction
, NULL
);
3700 *ppShader
= (IDirect3DPixelShader9
*)ps
;
3705 NineDevice9_SetPixelShader( struct NineDevice9
*This
,
3706 IDirect3DPixelShader9
*pShader
)
3708 struct nine_state
*state
= This
->update
;
3709 unsigned old_mask
= state
->ps
? state
->ps
->rt_mask
: 1;
3712 DBG("This=%p pShader=%p\n", This
, pShader
);
3714 if (!This
->is_recording
&& state
->ps
== (struct NinePixelShader9
*)pShader
)
3717 /* ff -> non-ff: commit back non-ff constants */
3718 if (!state
->ps
&& pShader
)
3719 state
->commit
|= NINE_STATE_COMMIT_CONST_PS
;
3721 nine_bind(&state
->ps
, pShader
);
3723 state
->changed
.group
|= NINE_STATE_PS
;
3725 mask
= state
->ps
? state
->ps
->rt_mask
: 1;
3726 /* We need to update cbufs if the pixel shader would
3727 * write to different render targets */
3728 if (mask
!= old_mask
)
3729 state
->changed
.group
|= NINE_STATE_FB
;
3735 NineDevice9_GetPixelShader( struct NineDevice9
*This
,
3736 IDirect3DPixelShader9
**ppShader
)
3738 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3739 nine_reference_set(ppShader
, This
->state
.ps
);
3744 NineDevice9_SetPixelShaderConstantF( struct NineDevice9
*This
,
3746 const float *pConstantData
,
3747 UINT Vector4fCount
)
3749 struct nine_state
*state
= This
->update
;
3751 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3752 This
, StartRegister
, pConstantData
, Vector4fCount
);
3754 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3755 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3759 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3761 if (!This
->is_recording
) {
3762 if (!memcmp(&state
->ps_const_f
[StartRegister
* 4], pConstantData
,
3763 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0])))
3767 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3769 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3771 nine_ranges_insert(&state
->changed
.ps_const_f
,
3772 StartRegister
, StartRegister
+ Vector4fCount
,
3775 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3781 NineDevice9_GetPixelShaderConstantF( struct NineDevice9
*This
,
3783 float *pConstantData
,
3784 UINT Vector4fCount
)
3786 const struct nine_state
*state
= &This
->state
;
3788 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3789 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3790 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3792 memcpy(pConstantData
,
3793 &state
->ps_const_f
[StartRegister
* 4],
3794 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3800 NineDevice9_SetPixelShaderConstantI( struct NineDevice9
*This
,
3802 const int *pConstantData
,
3803 UINT Vector4iCount
)
3805 struct nine_state
*state
= This
->update
;
3808 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3809 This
, StartRegister
, pConstantData
, Vector4iCount
);
3811 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3812 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3813 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3815 if (This
->driver_caps
.ps_integer
) {
3816 if (!This
->is_recording
) {
3817 if (!memcmp(&state
->ps_const_i
[StartRegister
][0], pConstantData
,
3818 Vector4iCount
* sizeof(state
->ps_const_i
[0])))
3821 memcpy(&state
->ps_const_i
[StartRegister
][0],
3823 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3825 for (i
= 0; i
< Vector4iCount
; i
++) {
3826 state
->ps_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3827 state
->ps_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3828 state
->ps_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3829 state
->ps_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3832 state
->changed
.ps_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3833 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3839 NineDevice9_GetPixelShaderConstantI( struct NineDevice9
*This
,
3842 UINT Vector4iCount
)
3844 const struct nine_state
*state
= &This
->state
;
3847 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3848 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3849 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3851 if (This
->driver_caps
.ps_integer
) {
3852 memcpy(pConstantData
,
3853 &state
->ps_const_i
[StartRegister
][0],
3854 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3856 for (i
= 0; i
< Vector4iCount
; i
++) {
3857 pConstantData
[4*i
] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][0]);
3858 pConstantData
[4*i
+1] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][1]);
3859 pConstantData
[4*i
+2] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][2]);
3860 pConstantData
[4*i
+3] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][3]);
3868 NineDevice9_SetPixelShaderConstantB( struct NineDevice9
*This
,
3870 const BOOL
*pConstantData
,
3873 struct nine_state
*state
= This
->update
;
3875 uint32_t bool_true
= This
->driver_caps
.ps_integer
? 0xFFFFFFFF : fui(1.0f
);
3877 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3878 This
, StartRegister
, pConstantData
, BoolCount
);
3880 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3881 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3882 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3884 if (!This
->is_recording
) {
3885 bool noChange
= true;
3886 for (i
= 0; i
< BoolCount
; i
++) {
3887 if (!!state
->ps_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3894 for (i
= 0; i
< BoolCount
; i
++)
3895 state
->ps_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3897 state
->changed
.ps_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3898 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3904 NineDevice9_GetPixelShaderConstantB( struct NineDevice9
*This
,
3906 BOOL
*pConstantData
,
3909 const struct nine_state
*state
= &This
->state
;
3912 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3913 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3914 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3916 for (i
= 0; i
< BoolCount
; i
++)
3917 pConstantData
[i
] = state
->ps_const_b
[StartRegister
+ i
] ? TRUE
: FALSE
;
3923 NineDevice9_DrawRectPatch( struct NineDevice9
*This
,
3925 const float *pNumSegs
,
3926 const D3DRECTPATCH_INFO
*pRectPatchInfo
)
3928 STUB(D3DERR_INVALIDCALL
);
3932 NineDevice9_DrawTriPatch( struct NineDevice9
*This
,
3934 const float *pNumSegs
,
3935 const D3DTRIPATCH_INFO
*pTriPatchInfo
)
3937 STUB(D3DERR_INVALIDCALL
);
3941 NineDevice9_DeletePatch( struct NineDevice9
*This
,
3944 STUB(D3DERR_INVALIDCALL
);
3948 NineDevice9_CreateQuery( struct NineDevice9
*This
,
3950 IDirect3DQuery9
**ppQuery
)
3952 struct NineQuery9
*query
;
3955 DBG("This=%p Type=%d ppQuery=%p\n", This
, Type
, ppQuery
);
3957 hr
= nine_is_query_supported(This
->screen
, Type
);
3958 if (!ppQuery
|| hr
!= D3D_OK
)
3961 hr
= NineQuery9_new(This
, &query
, Type
);
3964 *ppQuery
= (IDirect3DQuery9
*)query
;
3968 IDirect3DDevice9Vtbl NineDevice9_vtable
= {
3969 (void *)NineUnknown_QueryInterface
,
3970 (void *)NineUnknown_AddRef
,
3971 (void *)NineUnknown_Release
,
3972 (void *)NineDevice9_TestCooperativeLevel
,
3973 (void *)NineDevice9_GetAvailableTextureMem
,
3974 (void *)NineDevice9_EvictManagedResources
,
3975 (void *)NineDevice9_GetDirect3D
,
3976 (void *)NineDevice9_GetDeviceCaps
,
3977 (void *)NineDevice9_GetDisplayMode
,
3978 (void *)NineDevice9_GetCreationParameters
,
3979 (void *)NineDevice9_SetCursorProperties
,
3980 (void *)NineDevice9_SetCursorPosition
,
3981 (void *)NineDevice9_ShowCursor
,
3982 (void *)NineDevice9_CreateAdditionalSwapChain
,
3983 (void *)NineDevice9_GetSwapChain
,
3984 (void *)NineDevice9_GetNumberOfSwapChains
,
3985 (void *)NineDevice9_Reset
,
3986 (void *)NineDevice9_Present
,
3987 (void *)NineDevice9_GetBackBuffer
,
3988 (void *)NineDevice9_GetRasterStatus
,
3989 (void *)NineDevice9_SetDialogBoxMode
,
3990 (void *)NineDevice9_SetGammaRamp
,
3991 (void *)NineDevice9_GetGammaRamp
,
3992 (void *)NineDevice9_CreateTexture
,
3993 (void *)NineDevice9_CreateVolumeTexture
,
3994 (void *)NineDevice9_CreateCubeTexture
,
3995 (void *)NineDevice9_CreateVertexBuffer
,
3996 (void *)NineDevice9_CreateIndexBuffer
,
3997 (void *)NineDevice9_CreateRenderTarget
,
3998 (void *)NineDevice9_CreateDepthStencilSurface
,
3999 (void *)NineDevice9_UpdateSurface
,
4000 (void *)NineDevice9_UpdateTexture
,
4001 (void *)NineDevice9_GetRenderTargetData
,
4002 (void *)NineDevice9_GetFrontBufferData
,
4003 (void *)NineDevice9_StretchRect
,
4004 (void *)NineDevice9_ColorFill
,
4005 (void *)NineDevice9_CreateOffscreenPlainSurface
,
4006 (void *)NineDevice9_SetRenderTarget
,
4007 (void *)NineDevice9_GetRenderTarget
,
4008 (void *)NineDevice9_SetDepthStencilSurface
,
4009 (void *)NineDevice9_GetDepthStencilSurface
,
4010 (void *)NineDevice9_BeginScene
,
4011 (void *)NineDevice9_EndScene
,
4012 (void *)NineDevice9_Clear
,
4013 (void *)NineDevice9_SetTransform
,
4014 (void *)NineDevice9_GetTransform
,
4015 (void *)NineDevice9_MultiplyTransform
,
4016 (void *)NineDevice9_SetViewport
,
4017 (void *)NineDevice9_GetViewport
,
4018 (void *)NineDevice9_SetMaterial
,
4019 (void *)NineDevice9_GetMaterial
,
4020 (void *)NineDevice9_SetLight
,
4021 (void *)NineDevice9_GetLight
,
4022 (void *)NineDevice9_LightEnable
,
4023 (void *)NineDevice9_GetLightEnable
,
4024 (void *)NineDevice9_SetClipPlane
,
4025 (void *)NineDevice9_GetClipPlane
,
4026 (void *)NineDevice9_SetRenderState
,
4027 (void *)NineDevice9_GetRenderState
,
4028 (void *)NineDevice9_CreateStateBlock
,
4029 (void *)NineDevice9_BeginStateBlock
,
4030 (void *)NineDevice9_EndStateBlock
,
4031 (void *)NineDevice9_SetClipStatus
,
4032 (void *)NineDevice9_GetClipStatus
,
4033 (void *)NineDevice9_GetTexture
,
4034 (void *)NineDevice9_SetTexture
,
4035 (void *)NineDevice9_GetTextureStageState
,
4036 (void *)NineDevice9_SetTextureStageState
,
4037 (void *)NineDevice9_GetSamplerState
,
4038 (void *)NineDevice9_SetSamplerState
,
4039 (void *)NineDevice9_ValidateDevice
,
4040 (void *)NineDevice9_SetPaletteEntries
,
4041 (void *)NineDevice9_GetPaletteEntries
,
4042 (void *)NineDevice9_SetCurrentTexturePalette
,
4043 (void *)NineDevice9_GetCurrentTexturePalette
,
4044 (void *)NineDevice9_SetScissorRect
,
4045 (void *)NineDevice9_GetScissorRect
,
4046 (void *)NineDevice9_SetSoftwareVertexProcessing
,
4047 (void *)NineDevice9_GetSoftwareVertexProcessing
,
4048 (void *)NineDevice9_SetNPatchMode
,
4049 (void *)NineDevice9_GetNPatchMode
,
4050 (void *)NineDevice9_DrawPrimitive
,
4051 (void *)NineDevice9_DrawIndexedPrimitive
,
4052 (void *)NineDevice9_DrawPrimitiveUP
,
4053 (void *)NineDevice9_DrawIndexedPrimitiveUP
,
4054 (void *)NineDevice9_ProcessVertices
,
4055 (void *)NineDevice9_CreateVertexDeclaration
,
4056 (void *)NineDevice9_SetVertexDeclaration
,
4057 (void *)NineDevice9_GetVertexDeclaration
,
4058 (void *)NineDevice9_SetFVF
,
4059 (void *)NineDevice9_GetFVF
,
4060 (void *)NineDevice9_CreateVertexShader
,
4061 (void *)NineDevice9_SetVertexShader
,
4062 (void *)NineDevice9_GetVertexShader
,
4063 (void *)NineDevice9_SetVertexShaderConstantF
,
4064 (void *)NineDevice9_GetVertexShaderConstantF
,
4065 (void *)NineDevice9_SetVertexShaderConstantI
,
4066 (void *)NineDevice9_GetVertexShaderConstantI
,
4067 (void *)NineDevice9_SetVertexShaderConstantB
,
4068 (void *)NineDevice9_GetVertexShaderConstantB
,
4069 (void *)NineDevice9_SetStreamSource
,
4070 (void *)NineDevice9_GetStreamSource
,
4071 (void *)NineDevice9_SetStreamSourceFreq
,
4072 (void *)NineDevice9_GetStreamSourceFreq
,
4073 (void *)NineDevice9_SetIndices
,
4074 (void *)NineDevice9_GetIndices
,
4075 (void *)NineDevice9_CreatePixelShader
,
4076 (void *)NineDevice9_SetPixelShader
,
4077 (void *)NineDevice9_GetPixelShader
,
4078 (void *)NineDevice9_SetPixelShaderConstantF
,
4079 (void *)NineDevice9_GetPixelShaderConstantF
,
4080 (void *)NineDevice9_SetPixelShaderConstantI
,
4081 (void *)NineDevice9_GetPixelShaderConstantI
,
4082 (void *)NineDevice9_SetPixelShaderConstantB
,
4083 (void *)NineDevice9_GetPixelShaderConstantB
,
4084 (void *)NineDevice9_DrawRectPatch
,
4085 (void *)NineDevice9_DrawTriPatch
,
4086 (void *)NineDevice9_DeletePatch
,
4087 (void *)NineDevice9_CreateQuery
4090 static const GUID
*NineDevice9_IIDs
[] = {
4091 &IID_IDirect3DDevice9
,
4097 NineDevice9_new( struct pipe_screen
*pScreen
,
4098 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
4100 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
4102 ID3DPresentGroup
*pPresentationGroup
,
4103 struct d3dadapter9_context
*pCTX
,
4105 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
4106 struct NineDevice9
**ppOut
,
4107 int minorVersionNum
)
4110 lock
= !!(pCreationParameters
->BehaviorFlags
& D3DCREATE_MULTITHREADED
);
4112 NINE_NEW(Device9
, ppOut
, lock
, /* args */
4113 pScreen
, pCreationParameters
, pCaps
,
4114 pPresentationParameters
, pD3D9
, pPresentationGroup
, pCTX
,
4115 ex
, pFullscreenDisplayMode
, minorVersionNum
);