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 #include <fpu_control.h>
62 static void nine_setup_fpu()
67 /* clear the control word */
69 /* d3d9 doc/wine tests: mask all exceptions, use single-precision
70 * and round to nearest */
71 c
|= _FPU_MASK_IM
| _FPU_MASK_DM
| _FPU_MASK_ZM
| _FPU_MASK_OM
|
72 _FPU_MASK_UM
| _FPU_MASK_PM
| _FPU_SINGLE
| _FPU_RC_NEAREST
;
78 static void nine_setup_fpu(void)
80 WARN_ONCE("FPU setup not supported on non-x86 platforms\n");
86 NineDevice9_SetDefaultState( struct NineDevice9
*This
, boolean is_reset
)
88 struct NineSurface9
*refSurf
= NULL
;
90 DBG("This=%p is_reset=%d\n", This
, (int) is_reset
);
92 assert(!This
->is_recording
);
94 nine_state_set_defaults(This
, &This
->caps
, is_reset
);
96 This
->state
.viewport
.X
= 0;
97 This
->state
.viewport
.Y
= 0;
98 This
->state
.viewport
.Width
= 0;
99 This
->state
.viewport
.Height
= 0;
101 This
->state
.scissor
.minx
= 0;
102 This
->state
.scissor
.miny
= 0;
103 This
->state
.scissor
.maxx
= 0xffff;
104 This
->state
.scissor
.maxy
= 0xffff;
106 if (This
->nswapchains
&& This
->swapchains
[0]->params
.BackBufferCount
)
107 refSurf
= This
->swapchains
[0]->buffers
[0];
110 This
->state
.viewport
.Width
= refSurf
->desc
.Width
;
111 This
->state
.viewport
.Height
= refSurf
->desc
.Height
;
112 This
->state
.scissor
.maxx
= refSurf
->desc
.Width
;
113 This
->state
.scissor
.maxy
= refSurf
->desc
.Height
;
116 if (This
->nswapchains
&& This
->swapchains
[0]->params
.EnableAutoDepthStencil
) {
117 This
->state
.rs
[D3DRS_ZENABLE
] = TRUE
;
118 This
->state
.rs_advertised
[D3DRS_ZENABLE
] = TRUE
;
120 if (This
->state
.rs
[D3DRS_ZENABLE
])
121 NineDevice9_SetDepthStencilSurface(
122 This
, (IDirect3DSurface9
*)This
->swapchains
[0]->zsbuf
);
125 #define GET_PCAP(n) pScreen->get_param(pScreen, PIPE_CAP_##n)
127 NineDevice9_ctor( struct NineDevice9
*This
,
128 struct NineUnknownParams
*pParams
,
129 struct pipe_screen
*pScreen
,
130 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
132 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
134 ID3DPresentGroup
*pPresentationGroup
,
135 struct d3dadapter9_context
*pCTX
,
137 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
138 int minorVersionNum
)
141 HRESULT hr
= NineUnknown_ctor(&This
->base
, pParams
);
143 DBG("This=%p pParams=%p pScreen=%p pCreationParameters=%p pCaps=%p pPresentationParameters=%p "
144 "pD3D9=%p pPresentationGroup=%p pCTX=%p ex=%d pFullscreenDisplayMode=%p\n",
145 This
, pParams
, pScreen
, pCreationParameters
, pCaps
, pPresentationParameters
, pD3D9
,
146 pPresentationGroup
, pCTX
, (int) ex
, pFullscreenDisplayMode
);
148 if (FAILED(hr
)) { return hr
; }
150 list_inithead(&This
->update_textures
);
151 list_inithead(&This
->managed_textures
);
153 This
->screen
= pScreen
;
156 This
->params
= *pCreationParameters
;
158 This
->present
= pPresentationGroup
;
159 This
->minor_version_num
= minorVersionNum
;
161 IDirect3D9_AddRef(This
->d3d9
);
162 ID3DPresentGroup_AddRef(This
->present
);
164 if (!(This
->params
.BehaviorFlags
& D3DCREATE_FPU_PRESERVE
))
167 if (This
->params
.BehaviorFlags
& D3DCREATE_SOFTWARE_VERTEXPROCESSING
)
168 DBG("Application asked full Software Vertex Processing. Ignoring.\n");
169 if (This
->params
.BehaviorFlags
& D3DCREATE_MIXED_VERTEXPROCESSING
)
170 DBG("Application asked mixed Software Vertex Processing. Ignoring.\n");
172 This
->pipe
= This
->screen
->context_create(This
->screen
, NULL
, 0);
173 if (!This
->pipe
) { return E_OUTOFMEMORY
; } /* guess */
175 This
->cso
= cso_create_context(This
->pipe
);
176 if (!This
->cso
) { return E_OUTOFMEMORY
; } /* also a guess */
178 /* Create first, it messes up our state. */
179 This
->hud
= hud_create(This
->pipe
, This
->cso
); /* NULL result is fine */
181 /* Available memory counter. Updated only for allocations with this device
182 * instance. This is the Win 7 behavior.
183 * Win XP shares this counter across multiple devices. */
184 This
->available_texture_mem
= This
->screen
->get_param(This
->screen
, PIPE_CAP_VIDEO_MEMORY
);
185 if (This
->available_texture_mem
< 4096)
186 This
->available_texture_mem
<<= 20;
188 This
->available_texture_mem
= UINT_MAX
;
189 /* We cap texture memory usage to 80% of what is reported free initially
190 * This helps get closer Win behaviour. For example VertexBuffer allocation
191 * still succeeds when texture allocation fails. */
192 This
->available_texture_limit
= This
->available_texture_mem
* 20LL / 100LL;
194 /* create implicit swapchains */
195 This
->nswapchains
= ID3DPresentGroup_GetMultiheadCount(This
->present
);
196 This
->swapchains
= CALLOC(This
->nswapchains
,
197 sizeof(struct NineSwapChain9
*));
198 if (!This
->swapchains
) { return E_OUTOFMEMORY
; }
200 for (i
= 0; i
< This
->nswapchains
; ++i
) {
201 ID3DPresent
*present
;
203 hr
= ID3DPresentGroup_GetPresent(This
->present
, i
, &present
);
208 D3DDISPLAYMODEEX
*mode
= NULL
;
209 struct NineSwapChain9Ex
**ret
=
210 (struct NineSwapChain9Ex
**)&This
->swapchains
[i
];
212 if (pFullscreenDisplayMode
) mode
= &(pFullscreenDisplayMode
[i
]);
213 /* when this is a Device9Ex, it should create SwapChain9Exs */
214 hr
= NineSwapChain9Ex_new(This
, TRUE
, present
,
215 &pPresentationParameters
[i
], pCTX
,
216 This
->params
.hFocusWindow
, mode
, ret
);
218 hr
= NineSwapChain9_new(This
, TRUE
, present
,
219 &pPresentationParameters
[i
], pCTX
,
220 This
->params
.hFocusWindow
,
221 &This
->swapchains
[i
]);
224 ID3DPresent_Release(present
);
227 NineUnknown_ConvertRefToBind(NineUnknown(This
->swapchains
[i
]));
229 hr
= NineSwapChain9_GetBackBuffer(This
->swapchains
[i
], 0,
230 D3DBACKBUFFER_TYPE_MONO
,
231 (IDirect3DSurface9
**)
235 NineUnknown_ConvertRefToBind(NineUnknown(This
->state
.rt
[i
]));
238 /* Initialize a dummy VBO to be used when a a vertex declaration does not
239 * specify all the inputs needed by vertex shader, on win default behavior
240 * is to pass 0,0,0,0 to the shader */
242 struct pipe_transfer
*transfer
;
243 struct pipe_resource tmpl
;
247 tmpl
.target
= PIPE_BUFFER
;
248 tmpl
.format
= PIPE_FORMAT_R8_UNORM
;
249 tmpl
.width0
= 16; /* 4 floats */
255 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
256 tmpl
.bind
= PIPE_BIND_VERTEX_BUFFER
| PIPE_BIND_TRANSFER_WRITE
;
258 This
->dummy_vbo
= pScreen
->resource_create(pScreen
, &tmpl
);
260 if (!This
->dummy_vbo
)
261 return D3DERR_OUTOFVIDEOMEMORY
;
263 u_box_1d(0, 16, &box
);
264 data
= This
->pipe
->transfer_map(This
->pipe
, This
->dummy_vbo
, 0,
265 PIPE_TRANSFER_WRITE
|
266 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
271 This
->pipe
->transfer_unmap(This
->pipe
, transfer
);
274 This
->cursor
.software
= FALSE
;
275 This
->cursor
.hotspot
.x
= -1;
276 This
->cursor
.hotspot
.y
= -1;
278 struct pipe_resource tmpl
;
279 tmpl
.target
= PIPE_TEXTURE_2D
;
280 tmpl
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
287 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
288 tmpl
.bind
= PIPE_BIND_CURSOR
| PIPE_BIND_SAMPLER_VIEW
;
291 This
->cursor
.image
= pScreen
->resource_create(pScreen
, &tmpl
);
292 if (!This
->cursor
.image
)
293 return D3DERR_OUTOFVIDEOMEMORY
;
296 /* Create constant buffers. */
298 struct pipe_resource tmpl
;
299 unsigned max_const_vs
, max_const_ps
;
301 /* vs 3.0: >= 256 float constants, but for cards with exactly 256 slots,
302 * we have to take in some more slots for int and bool*/
303 max_const_vs
= _min(pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
,
304 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
) /
307 /* ps 3.0: 224 float constants. All cards supported support at least
308 * 256 constants for ps */
309 max_const_ps
= NINE_MAX_CONST_F_PS3
+ (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
311 This
->max_vs_const_f
= max_const_vs
-
312 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
313 This
->max_ps_const_f
= max_const_ps
-
314 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
316 This
->vs_const_size
= max_const_vs
* sizeof(float[4]);
317 This
->ps_const_size
= max_const_ps
* sizeof(float[4]);
318 /* Include space for I,B constants for user constbuf. */
319 This
->state
.vs_const_f
= CALLOC(This
->vs_const_size
, 1);
320 This
->state
.ps_const_f
= CALLOC(This
->ps_const_size
, 1);
321 This
->state
.vs_lconstf_temp
= CALLOC(This
->vs_const_size
,1);
322 This
->state
.ps_lconstf_temp
= CALLOC(This
->ps_const_size
,1);
323 if (!This
->state
.vs_const_f
|| !This
->state
.ps_const_f
||
324 !This
->state
.vs_lconstf_temp
|| !This
->state
.ps_lconstf_temp
)
325 return E_OUTOFMEMORY
;
327 if (strstr(pScreen
->get_name(pScreen
), "AMD") ||
328 strstr(pScreen
->get_name(pScreen
), "ATI")) {
329 This
->driver_bugs
.buggy_barycentrics
= TRUE
;
332 /* Disable NV path for now, needs some fixes */
333 This
->prefer_user_constbuf
= TRUE
;
335 tmpl
.target
= PIPE_BUFFER
;
336 tmpl
.format
= PIPE_FORMAT_R8_UNORM
;
342 tmpl
.usage
= PIPE_USAGE_DYNAMIC
;
343 tmpl
.bind
= PIPE_BIND_CONSTANT_BUFFER
;
346 tmpl
.width0
= This
->vs_const_size
;
347 This
->constbuf_vs
= pScreen
->resource_create(pScreen
, &tmpl
);
349 tmpl
.width0
= This
->ps_const_size
;
350 This
->constbuf_ps
= pScreen
->resource_create(pScreen
, &tmpl
);
352 if (!This
->constbuf_vs
|| !This
->constbuf_ps
)
353 return E_OUTOFMEMORY
;
356 /* allocate dummy texture/sampler for when there are missing ones bound */
358 struct pipe_resource tmplt
;
359 struct pipe_sampler_view templ
;
360 struct pipe_sampler_state samp
;
361 memset(&samp
, 0, sizeof(samp
));
363 tmplt
.target
= PIPE_TEXTURE_2D
;
367 tmplt
.last_level
= 0;
368 tmplt
.array_size
= 1;
369 tmplt
.usage
= PIPE_USAGE_DEFAULT
;
371 tmplt
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
372 tmplt
.bind
= PIPE_BIND_SAMPLER_VIEW
;
373 tmplt
.nr_samples
= 0;
375 This
->dummy_texture
= This
->screen
->resource_create(This
->screen
, &tmplt
);
376 if (!This
->dummy_texture
)
377 return D3DERR_DRIVERINTERNALERROR
;
379 templ
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
380 templ
.u
.tex
.first_layer
= 0;
381 templ
.u
.tex
.last_layer
= 0;
382 templ
.u
.tex
.first_level
= 0;
383 templ
.u
.tex
.last_level
= 0;
384 templ
.swizzle_r
= PIPE_SWIZZLE_ZERO
;
385 templ
.swizzle_g
= PIPE_SWIZZLE_ZERO
;
386 templ
.swizzle_b
= PIPE_SWIZZLE_ZERO
;
387 templ
.swizzle_a
= PIPE_SWIZZLE_ONE
;
388 templ
.target
= This
->dummy_texture
->target
;
390 This
->dummy_sampler_view
= This
->pipe
->create_sampler_view(This
->pipe
, This
->dummy_texture
, &templ
);
391 if (!This
->dummy_sampler_view
)
392 return D3DERR_DRIVERINTERNALERROR
;
394 samp
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
395 samp
.max_lod
= 15.0f
;
396 samp
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
397 samp
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
398 samp
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
399 samp
.min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
400 samp
.mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
401 samp
.compare_mode
= PIPE_TEX_COMPARE_NONE
;
402 samp
.compare_func
= PIPE_FUNC_LEQUAL
;
403 samp
.normalized_coords
= 1;
404 samp
.seamless_cube_map
= 1;
405 This
->dummy_sampler_state
= samp
;
408 /* Allocate upload helper for drivers that suck (from st pov ;). */
410 This
->driver_caps
.user_vbufs
= GET_PCAP(USER_VERTEX_BUFFERS
);
411 This
->driver_caps
.user_ibufs
= GET_PCAP(USER_INDEX_BUFFERS
);
412 This
->driver_caps
.user_cbufs
= GET_PCAP(USER_CONSTANT_BUFFERS
);
414 if (!This
->driver_caps
.user_vbufs
)
415 This
->vertex_uploader
= u_upload_create(This
->pipe
, 65536,
416 PIPE_BIND_VERTEX_BUFFER
, PIPE_USAGE_STREAM
);
417 if (!This
->driver_caps
.user_ibufs
)
418 This
->index_uploader
= u_upload_create(This
->pipe
, 128 * 1024,
419 PIPE_BIND_INDEX_BUFFER
, PIPE_USAGE_STREAM
);
420 if (!This
->driver_caps
.user_cbufs
) {
421 This
->constbuf_alignment
= GET_PCAP(CONSTANT_BUFFER_OFFSET_ALIGNMENT
);
422 This
->constbuf_uploader
= u_upload_create(This
->pipe
, This
->vs_const_size
,
423 PIPE_BIND_CONSTANT_BUFFER
, PIPE_USAGE_STREAM
);
426 This
->driver_caps
.window_space_position_support
= GET_PCAP(TGSI_VS_WINDOW_SPACE_POSITION
);
427 This
->driver_caps
.vs_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
, PIPE_SHADER_CAP_INTEGERS
);
428 This
->driver_caps
.ps_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_FRAGMENT
, PIPE_SHADER_CAP_INTEGERS
);
430 nine_ff_init(This
); /* initialize fixed function code */
432 NineDevice9_SetDefaultState(This
, FALSE
);
435 struct pipe_poly_stipple stipple
;
436 memset(&stipple
, ~0, sizeof(stipple
));
437 This
->pipe
->set_polygon_stipple(This
->pipe
, &stipple
);
440 This
->update
= &This
->state
;
441 nine_update_state(This
);
443 ID3DPresentGroup_Release(This
->present
);
450 NineDevice9_dtor( struct NineDevice9
*This
)
454 DBG("This=%p\n", This
);
456 if (This
->pipe
&& This
->cso
)
457 nine_pipe_context_clear(This
);
459 nine_state_clear(&This
->state
, TRUE
);
461 if (This
->vertex_uploader
)
462 u_upload_destroy(This
->vertex_uploader
);
463 if (This
->index_uploader
)
464 u_upload_destroy(This
->index_uploader
);
465 if (This
->constbuf_uploader
)
466 u_upload_destroy(This
->constbuf_uploader
);
468 nine_bind(&This
->record
, NULL
);
470 pipe_sampler_view_reference(&This
->dummy_sampler_view
, NULL
);
471 pipe_resource_reference(&This
->dummy_texture
, NULL
);
472 pipe_resource_reference(&This
->constbuf_vs
, NULL
);
473 pipe_resource_reference(&This
->constbuf_ps
, NULL
);
474 pipe_resource_reference(&This
->dummy_vbo
, NULL
);
475 FREE(This
->state
.vs_const_f
);
476 FREE(This
->state
.ps_const_f
);
477 FREE(This
->state
.vs_lconstf_temp
);
478 FREE(This
->state
.ps_lconstf_temp
);
480 if (This
->swapchains
) {
481 for (i
= 0; i
< This
->nswapchains
; ++i
)
482 if (This
->swapchains
[i
])
483 NineUnknown_Unbind(NineUnknown(This
->swapchains
[i
]));
484 FREE(This
->swapchains
);
490 cso_destroy_context(This
->cso
);
492 if (This
->pipe
->destroy
) { This
->pipe
->destroy(This
->pipe
); }
495 if (This
->present
) { ID3DPresentGroup_Release(This
->present
); }
496 if (This
->d3d9
) { IDirect3D9_Release(This
->d3d9
); }
498 NineUnknown_dtor(&This
->base
);
502 NineDevice9_GetScreen( struct NineDevice9
*This
)
507 struct pipe_context
*
508 NineDevice9_GetPipe( struct NineDevice9
*This
)
514 NineDevice9_GetCSO( struct NineDevice9
*This
)
520 NineDevice9_GetCaps( struct NineDevice9
*This
)
526 NineDevice9_PauseRecording( struct NineDevice9
*This
)
529 This
->update
= &This
->state
;
530 This
->is_recording
= FALSE
;
535 NineDevice9_ResumeRecording( struct NineDevice9
*This
)
538 This
->update
= &This
->record
->state
;
539 This
->is_recording
= TRUE
;
544 NineDevice9_TestCooperativeLevel( struct NineDevice9
*This
)
546 if (NineSwapChain9_GetOccluded(This
->swapchains
[0])) {
547 This
->device_needs_reset
= TRUE
;
548 return D3DERR_DEVICELOST
;
549 } else if (This
->device_needs_reset
) {
550 return D3DERR_DEVICENOTRESET
;
557 NineDevice9_GetAvailableTextureMem( struct NineDevice9
*This
)
559 return This
->available_texture_mem
;
563 NineDevice9_EvictManagedResources( struct NineDevice9
*This
)
565 struct NineBaseTexture9
*tex
;
567 DBG("This=%p\n", This
);
568 LIST_FOR_EACH_ENTRY(tex
, &This
->managed_textures
, list2
) {
569 NineBaseTexture9_UnLoad(tex
);
576 NineDevice9_GetDirect3D( struct NineDevice9
*This
,
577 IDirect3D9
**ppD3D9
)
579 user_assert(ppD3D9
!= NULL
, E_POINTER
);
580 IDirect3D9_AddRef(This
->d3d9
);
581 *ppD3D9
= This
->d3d9
;
586 NineDevice9_GetDeviceCaps( struct NineDevice9
*This
,
589 user_assert(pCaps
!= NULL
, D3DERR_INVALIDCALL
);
595 NineDevice9_GetDisplayMode( struct NineDevice9
*This
,
597 D3DDISPLAYMODE
*pMode
)
599 DBG("This=%p iSwapChain=%u pMode=%p\n", This
, iSwapChain
, pMode
);
601 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
603 return NineSwapChain9_GetDisplayMode(This
->swapchains
[iSwapChain
], pMode
);
607 NineDevice9_GetCreationParameters( struct NineDevice9
*This
,
608 D3DDEVICE_CREATION_PARAMETERS
*pParameters
)
610 user_assert(pParameters
!= NULL
, D3DERR_INVALIDCALL
);
611 *pParameters
= This
->params
;
616 NineDevice9_SetCursorProperties( struct NineDevice9
*This
,
619 IDirect3DSurface9
*pCursorBitmap
)
621 struct NineSurface9
*surf
= NineSurface9(pCursorBitmap
);
622 struct pipe_context
*pipe
= This
->pipe
;
624 struct pipe_transfer
*transfer
;
628 DBG_FLAG(DBG_SWAPCHAIN
, "This=%p XHotSpot=%u YHotSpot=%u "
629 "pCursorBitmap=%p\n", This
, XHotSpot
, YHotSpot
, pCursorBitmap
);
631 user_assert(pCursorBitmap
, D3DERR_INVALIDCALL
);
633 if (This
->swapchains
[0]->params
.Windowed
) {
634 This
->cursor
.w
= MIN2(surf
->desc
.Width
, 32);
635 This
->cursor
.h
= MIN2(surf
->desc
.Height
, 32);
636 hw_cursor
= 1; /* always use hw cursor for windowed mode */
638 This
->cursor
.w
= MIN2(surf
->desc
.Width
, This
->cursor
.image
->width0
);
639 This
->cursor
.h
= MIN2(surf
->desc
.Height
, This
->cursor
.image
->height0
);
640 hw_cursor
= This
->cursor
.w
== 32 && This
->cursor
.h
== 32;
643 u_box_origin_2d(This
->cursor
.w
, This
->cursor
.h
, &box
);
645 ptr
= pipe
->transfer_map(pipe
, This
->cursor
.image
, 0,
646 PIPE_TRANSFER_WRITE
|
647 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
650 ret_err("Failed to update cursor image.\n", D3DERR_DRIVERINTERNALERROR
);
652 This
->cursor
.hotspot
.x
= XHotSpot
;
653 This
->cursor
.hotspot
.y
= YHotSpot
;
655 /* Copy cursor image to internal storage. */
659 const struct util_format_description
*sfmt
=
660 util_format_description(surf
->base
.info
.format
);
663 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, D3DLOCK_READONLY
);
665 ret_err("Failed to map cursor source image.\n",
666 D3DERR_DRIVERINTERNALERROR
);
668 sfmt
->unpack_rgba_8unorm(ptr
, transfer
->stride
,
669 lock
.pBits
, lock
.Pitch
,
670 This
->cursor
.w
, This
->cursor
.h
);
673 hw_cursor
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
,
675 &This
->cursor
.hotspot
,
676 This
->cursor
.visible
) == D3D_OK
;
678 NineSurface9_UnlockRect(surf
);
680 pipe
->transfer_unmap(pipe
, transfer
);
682 /* hide cursor if we emulate it */
684 ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, FALSE
);
685 This
->cursor
.software
= !hw_cursor
;
691 NineDevice9_SetCursorPosition( struct NineDevice9
*This
,
696 struct NineSwapChain9
*swap
= This
->swapchains
[0];
698 DBG("This=%p X=%d Y=%d Flags=%d\n", This
, X
, Y
, Flags
);
700 This
->cursor
.pos
.x
= X
;
701 This
->cursor
.pos
.y
= Y
;
703 if (!This
->cursor
.software
)
704 This
->cursor
.software
= ID3DPresent_SetCursorPos(swap
->present
, &This
->cursor
.pos
) != D3D_OK
;
708 NineDevice9_ShowCursor( struct NineDevice9
*This
,
711 BOOL old
= This
->cursor
.visible
;
713 DBG("This=%p bShow=%d\n", This
, (int) bShow
);
715 This
->cursor
.visible
= bShow
&& (This
->cursor
.hotspot
.x
!= -1);
716 if (!This
->cursor
.software
)
717 This
->cursor
.software
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, bShow
) != D3D_OK
;
723 NineDevice9_CreateAdditionalSwapChain( struct NineDevice9
*This
,
724 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
725 IDirect3DSwapChain9
**pSwapChain
)
727 struct NineSwapChain9
*swapchain
, *tmplt
= This
->swapchains
[0];
728 ID3DPresent
*present
;
731 DBG("This=%p pPresentationParameters=%p pSwapChain=%p\n",
732 This
, pPresentationParameters
, pSwapChain
);
734 user_assert(pPresentationParameters
, D3DERR_INVALIDCALL
);
735 user_assert(tmplt
->params
.Windowed
&& pPresentationParameters
->Windowed
, D3DERR_INVALIDCALL
);
737 /* TODO: this deserves more tests */
738 if (!pPresentationParameters
->hDeviceWindow
)
739 pPresentationParameters
->hDeviceWindow
= This
->params
.hFocusWindow
;
741 hr
= ID3DPresentGroup_CreateAdditionalPresent(This
->present
, pPresentationParameters
, &present
);
746 hr
= NineSwapChain9_new(This
, FALSE
, present
, pPresentationParameters
,
748 tmplt
->params
.hDeviceWindow
,
753 *pSwapChain
= (IDirect3DSwapChain9
*)swapchain
;
758 NineDevice9_GetSwapChain( struct NineDevice9
*This
,
760 IDirect3DSwapChain9
**pSwapChain
)
762 user_assert(pSwapChain
!= NULL
, D3DERR_INVALIDCALL
);
765 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
767 NineUnknown_AddRef(NineUnknown(This
->swapchains
[iSwapChain
]));
768 *pSwapChain
= (IDirect3DSwapChain9
*)This
->swapchains
[iSwapChain
];
774 NineDevice9_GetNumberOfSwapChains( struct NineDevice9
*This
)
776 return This
->nswapchains
;
780 NineDevice9_Reset( struct NineDevice9
*This
,
781 D3DPRESENT_PARAMETERS
*pPresentationParameters
)
786 DBG("This=%p pPresentationParameters=%p\n", This
, pPresentationParameters
);
788 if (NineSwapChain9_GetOccluded(This
->swapchains
[0])) {
789 This
->device_needs_reset
= TRUE
;
790 return D3DERR_DEVICELOST
;
793 for (i
= 0; i
< This
->nswapchains
; ++i
) {
794 D3DPRESENT_PARAMETERS
*params
= &pPresentationParameters
[i
];
795 hr
= NineSwapChain9_Resize(This
->swapchains
[i
], params
, NULL
);
800 nine_pipe_context_clear(This
);
801 nine_state_clear(&This
->state
, TRUE
);
803 NineDevice9_SetDefaultState(This
, TRUE
);
804 NineDevice9_SetRenderTarget(
805 This
, 0, (IDirect3DSurface9
*)This
->swapchains
[0]->buffers
[0]);
806 /* XXX: better use GetBackBuffer here ? */
808 This
->device_needs_reset
= (hr
!= D3D_OK
);
813 NineDevice9_Present( struct NineDevice9
*This
,
814 const RECT
*pSourceRect
,
815 const RECT
*pDestRect
,
816 HWND hDestWindowOverride
,
817 const RGNDATA
*pDirtyRegion
)
822 DBG("This=%p pSourceRect=%p pDestRect=%p hDestWindowOverride=%p pDirtyRegion=%p\n",
823 This
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
825 /* XXX is this right? */
826 for (i
= 0; i
< This
->nswapchains
; ++i
) {
827 hr
= NineSwapChain9_Present(This
->swapchains
[i
], pSourceRect
, pDestRect
,
828 hDestWindowOverride
, pDirtyRegion
, 0);
829 if (FAILED(hr
)) { return hr
; }
836 NineDevice9_GetBackBuffer( struct NineDevice9
*This
,
839 D3DBACKBUFFER_TYPE Type
,
840 IDirect3DSurface9
**ppBackBuffer
)
842 user_assert(ppBackBuffer
!= NULL
, D3DERR_INVALIDCALL
);
843 /* return NULL on error */
844 *ppBackBuffer
= NULL
;
845 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
847 return NineSwapChain9_GetBackBuffer(This
->swapchains
[iSwapChain
],
848 iBackBuffer
, Type
, ppBackBuffer
);
852 NineDevice9_GetRasterStatus( struct NineDevice9
*This
,
854 D3DRASTER_STATUS
*pRasterStatus
)
856 user_assert(pRasterStatus
!= NULL
, D3DERR_INVALIDCALL
);
857 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
859 return NineSwapChain9_GetRasterStatus(This
->swapchains
[iSwapChain
],
864 NineDevice9_SetDialogBoxMode( struct NineDevice9
*This
,
865 BOOL bEnableDialogs
)
867 STUB(D3DERR_INVALIDCALL
);
871 NineDevice9_SetGammaRamp( struct NineDevice9
*This
,
874 const D3DGAMMARAMP
*pRamp
)
876 DBG("This=%p iSwapChain=%u Flags=%x pRamp=%p\n", This
,
877 iSwapChain
, Flags
, pRamp
);
879 user_warn(iSwapChain
>= This
->nswapchains
);
882 if (pRamp
&& (iSwapChain
< This
->nswapchains
)) {
883 struct NineSwapChain9
*swap
= This
->swapchains
[iSwapChain
];
884 swap
->gamma
= *pRamp
;
885 ID3DPresent_SetGammaRamp(swap
->present
, pRamp
, swap
->params
.hDeviceWindow
);
890 NineDevice9_GetGammaRamp( struct NineDevice9
*This
,
892 D3DGAMMARAMP
*pRamp
)
894 DBG("This=%p iSwapChain=%u pRamp=%p\n", This
, iSwapChain
, pRamp
);
896 user_warn(iSwapChain
>= This
->nswapchains
);
899 if (pRamp
&& (iSwapChain
< This
->nswapchains
))
900 *pRamp
= This
->swapchains
[iSwapChain
]->gamma
;
904 NineDevice9_CreateTexture( struct NineDevice9
*This
,
911 IDirect3DTexture9
**ppTexture
,
912 HANDLE
*pSharedHandle
)
914 struct NineTexture9
*tex
;
917 DBG("This=%p Width=%u Height=%u Levels=%u Usage=%s Format=%s Pool=%s "
918 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Levels
,
919 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
920 nine_D3DPOOL_to_str(Pool
), ppTexture
, pSharedHandle
);
922 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DMAP
|
923 D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
924 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
;
927 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
928 user_assert(!pSharedHandle
|| This
->ex
, D3DERR_INVALIDCALL
);
929 /* When is used shared handle, Pool must be
930 * SYSTEMMEM with Levels 1 or DEFAULT with any Levels */
931 user_assert(!pSharedHandle
|| Pool
!= D3DPOOL_SYSTEMMEM
|| Levels
== 1,
933 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_SYSTEMMEM
|| Pool
== D3DPOOL_DEFAULT
,
935 user_assert((Usage
!= D3DUSAGE_AUTOGENMIPMAP
|| Levels
<= 1), D3DERR_INVALIDCALL
);
937 hr
= NineTexture9_new(This
, Width
, Height
, Levels
, Usage
, Format
, Pool
,
938 &tex
, pSharedHandle
);
940 *ppTexture
= (IDirect3DTexture9
*)tex
;
946 NineDevice9_CreateVolumeTexture( struct NineDevice9
*This
,
954 IDirect3DVolumeTexture9
**ppVolumeTexture
,
955 HANDLE
*pSharedHandle
)
957 struct NineVolumeTexture9
*tex
;
960 DBG("This=%p Width=%u Height=%u Depth=%u Levels=%u Usage=%s Format=%s Pool=%s "
961 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Depth
, Levels
,
962 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
963 nine_D3DPOOL_to_str(Pool
), ppVolumeTexture
, pSharedHandle
);
965 Usage
&= D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
966 D3DUSAGE_SOFTWAREPROCESSING
;
968 *ppVolumeTexture
= NULL
;
969 user_assert(Width
&& Height
&& Depth
, D3DERR_INVALIDCALL
);
970 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
972 hr
= NineVolumeTexture9_new(This
, Width
, Height
, Depth
, Levels
,
973 Usage
, Format
, Pool
, &tex
, pSharedHandle
);
975 *ppVolumeTexture
= (IDirect3DVolumeTexture9
*)tex
;
981 NineDevice9_CreateCubeTexture( struct NineDevice9
*This
,
987 IDirect3DCubeTexture9
**ppCubeTexture
,
988 HANDLE
*pSharedHandle
)
990 struct NineCubeTexture9
*tex
;
993 DBG("This=%p EdgeLength=%u Levels=%u Usage=%s Format=%s Pool=%s ppOut=%p "
994 "pSharedHandle=%p\n", This
, EdgeLength
, Levels
,
995 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
996 nine_D3DPOOL_to_str(Pool
), ppCubeTexture
, pSharedHandle
);
998 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DYNAMIC
|
999 D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
1000 D3DUSAGE_SOFTWAREPROCESSING
;
1002 *ppCubeTexture
= NULL
;
1003 user_assert(EdgeLength
, D3DERR_INVALIDCALL
);
1004 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1006 hr
= NineCubeTexture9_new(This
, EdgeLength
, Levels
, Usage
, Format
, Pool
,
1007 &tex
, pSharedHandle
);
1009 *ppCubeTexture
= (IDirect3DCubeTexture9
*)tex
;
1015 NineDevice9_CreateVertexBuffer( struct NineDevice9
*This
,
1020 IDirect3DVertexBuffer9
**ppVertexBuffer
,
1021 HANDLE
*pSharedHandle
)
1023 struct NineVertexBuffer9
*buf
;
1025 D3DVERTEXBUFFER_DESC desc
;
1027 DBG("This=%p Length=%u Usage=%x FVF=%x Pool=%u ppOut=%p pSharedHandle=%p\n",
1028 This
, Length
, Usage
, FVF
, Pool
, ppVertexBuffer
, pSharedHandle
);
1030 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1032 desc
.Format
= D3DFMT_VERTEXDATA
;
1033 desc
.Type
= D3DRTYPE_VERTEXBUFFER
;
1034 desc
.Usage
= Usage
&
1035 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1036 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1037 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
|
1038 D3DUSAGE_WRITEONLY
);
1043 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1044 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1046 hr
= NineVertexBuffer9_new(This
, &desc
, &buf
);
1048 *ppVertexBuffer
= (IDirect3DVertexBuffer9
*)buf
;
1053 NineDevice9_CreateIndexBuffer( struct NineDevice9
*This
,
1058 IDirect3DIndexBuffer9
**ppIndexBuffer
,
1059 HANDLE
*pSharedHandle
)
1061 struct NineIndexBuffer9
*buf
;
1063 D3DINDEXBUFFER_DESC desc
;
1065 DBG("This=%p Length=%u Usage=%x Format=%s Pool=%u ppOut=%p "
1066 "pSharedHandle=%p\n", This
, Length
, Usage
,
1067 d3dformat_to_string(Format
), Pool
, ppIndexBuffer
, pSharedHandle
);
1069 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1071 desc
.Format
= Format
;
1072 desc
.Type
= D3DRTYPE_INDEXBUFFER
;
1073 desc
.Usage
= Usage
&
1074 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1075 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1076 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_WRITEONLY
);
1080 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1081 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1083 hr
= NineIndexBuffer9_new(This
, &desc
, &buf
);
1085 *ppIndexBuffer
= (IDirect3DIndexBuffer9
*)buf
;
1090 create_zs_or_rt_surface(struct NineDevice9
*This
,
1091 unsigned type
, /* 0 = RT, 1 = ZS, 2 = plain */
1093 UINT Width
, UINT Height
,
1095 D3DMULTISAMPLE_TYPE MultiSample
,
1096 DWORD MultisampleQuality
,
1097 BOOL Discard_or_Lockable
,
1098 IDirect3DSurface9
**ppSurface
,
1099 HANDLE
*pSharedHandle
)
1101 struct NineSurface9
*surface
;
1102 struct pipe_screen
*screen
= This
->screen
;
1103 struct pipe_resource
*resource
= NULL
;
1105 D3DSURFACE_DESC desc
;
1106 struct pipe_resource templ
;
1108 DBG("This=%p type=%u Pool=%s Width=%u Height=%u Format=%s MS=%u Quality=%u "
1109 "Discard_or_Lockable=%i ppSurface=%p pSharedHandle=%p\n",
1110 This
, type
, nine_D3DPOOL_to_str(Pool
), Width
, Height
,
1111 d3dformat_to_string(Format
), MultiSample
, MultisampleQuality
,
1112 Discard_or_Lockable
, ppSurface
, pSharedHandle
);
1115 DBG("FIXME Used shared handle! This option isn't probably handled correctly!\n");
1117 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
1118 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1120 templ
.target
= PIPE_TEXTURE_2D
;
1121 templ
.width0
= Width
;
1122 templ
.height0
= Height
;
1124 templ
.array_size
= 1;
1125 templ
.last_level
= 0;
1126 templ
.nr_samples
= (unsigned)MultiSample
;
1127 templ
.usage
= PIPE_USAGE_DEFAULT
;
1129 templ
.bind
= PIPE_BIND_SAMPLER_VIEW
; /* StretchRect */
1131 case 0: templ
.bind
|= PIPE_BIND_RENDER_TARGET
; break;
1132 case 1: templ
.bind
= d3d9_get_pipe_depth_format_bindings(Format
); break;
1137 templ
.format
= d3d9_to_pipe_format_checked(screen
, Format
, templ
.target
,
1138 templ
.nr_samples
, templ
.bind
,
1141 desc
.Format
= Format
;
1142 desc
.Type
= D3DRTYPE_SURFACE
;
1145 desc
.MultiSampleType
= MultiSample
;
1146 desc
.MultiSampleQuality
= MultisampleQuality
;
1148 desc
.Height
= Height
;
1150 case 0: desc
.Usage
= D3DUSAGE_RENDERTARGET
; break;
1151 case 1: desc
.Usage
= D3DUSAGE_DEPTHSTENCIL
; break;
1155 if (compressed_format(Format
)) {
1156 const unsigned w
= util_format_get_blockwidth(templ
.format
);
1157 const unsigned h
= util_format_get_blockheight(templ
.format
);
1159 user_assert(!(Width
% w
) && !(Height
% h
), D3DERR_INVALIDCALL
);
1162 if (Pool
== D3DPOOL_DEFAULT
&& Format
!= D3DFMT_NULL
) {
1163 /* resource_create doesn't return an error code, so check format here */
1164 user_assert(templ
.format
!= PIPE_FORMAT_NONE
, D3DERR_INVALIDCALL
);
1165 resource
= screen
->resource_create(screen
, &templ
);
1166 user_assert(resource
, D3DERR_OUTOFVIDEOMEMORY
);
1167 if (Discard_or_Lockable
&& (desc
.Usage
& D3DUSAGE_RENDERTARGET
))
1168 resource
->flags
|= NINE_RESOURCE_FLAG_LOCKABLE
;
1172 hr
= NineSurface9_new(This
, NULL
, resource
, NULL
, 0, 0, 0, &desc
, &surface
);
1173 pipe_resource_reference(&resource
, NULL
);
1176 *ppSurface
= (IDirect3DSurface9
*)surface
;
1181 NineDevice9_CreateRenderTarget( struct NineDevice9
*This
,
1185 D3DMULTISAMPLE_TYPE MultiSample
,
1186 DWORD MultisampleQuality
,
1188 IDirect3DSurface9
**ppSurface
,
1189 HANDLE
*pSharedHandle
)
1192 return create_zs_or_rt_surface(This
, 0, D3DPOOL_DEFAULT
,
1193 Width
, Height
, Format
,
1194 MultiSample
, MultisampleQuality
,
1195 Lockable
, ppSurface
, pSharedHandle
);
1199 NineDevice9_CreateDepthStencilSurface( struct NineDevice9
*This
,
1203 D3DMULTISAMPLE_TYPE MultiSample
,
1204 DWORD MultisampleQuality
,
1206 IDirect3DSurface9
**ppSurface
,
1207 HANDLE
*pSharedHandle
)
1210 if (!depth_stencil_format(Format
))
1211 return D3DERR_NOTAVAILABLE
;
1212 return create_zs_or_rt_surface(This
, 1, D3DPOOL_DEFAULT
,
1213 Width
, Height
, Format
,
1214 MultiSample
, MultisampleQuality
,
1215 Discard
, ppSurface
, pSharedHandle
);
1219 NineDevice9_UpdateSurface( struct NineDevice9
*This
,
1220 IDirect3DSurface9
*pSourceSurface
,
1221 const RECT
*pSourceRect
,
1222 IDirect3DSurface9
*pDestinationSurface
,
1223 const POINT
*pDestPoint
)
1225 struct NineSurface9
*dst
= NineSurface9(pDestinationSurface
);
1226 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1227 int copy_width
, copy_height
;
1230 DBG("This=%p pSourceSurface=%p pDestinationSurface=%p "
1231 "pSourceRect=%p pDestPoint=%p\n", This
,
1232 pSourceSurface
, pDestinationSurface
, pSourceRect
, pDestPoint
);
1234 DBG("pSourceRect = (%u,%u)-(%u,%u)\n",
1235 pSourceRect
->left
, pSourceRect
->top
,
1236 pSourceRect
->right
, pSourceRect
->bottom
);
1238 DBG("pDestPoint = (%u,%u)\n", pDestPoint
->x
, pDestPoint
->y
);
1240 user_assert(dst
&& src
, D3DERR_INVALIDCALL
);
1242 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1243 user_assert(src
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1245 user_assert(dst
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1246 user_assert(src
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1248 user_assert(!src
->lock_count
, D3DERR_INVALIDCALL
);
1249 user_assert(!dst
->lock_count
, D3DERR_INVALIDCALL
);
1251 user_assert(dst
->desc
.Format
== src
->desc
.Format
, D3DERR_INVALIDCALL
);
1252 user_assert(!depth_stencil_format(dst
->desc
.Format
), D3DERR_INVALIDCALL
);
1255 copy_width
= pSourceRect
->right
- pSourceRect
->left
;
1256 copy_height
= pSourceRect
->bottom
- pSourceRect
->top
;
1258 user_assert(pSourceRect
->left
>= 0 &&
1260 pSourceRect
->right
<= src
->desc
.Width
&&
1261 pSourceRect
->top
>= 0 &&
1263 pSourceRect
->bottom
<= src
->desc
.Height
,
1264 D3DERR_INVALIDCALL
);
1266 copy_width
= src
->desc
.Width
;
1267 copy_height
= src
->desc
.Height
;
1270 destRect
.right
= copy_width
;
1271 destRect
.bottom
= copy_height
;
1274 user_assert(pDestPoint
->x
>= 0 && pDestPoint
->y
>= 0,
1275 D3DERR_INVALIDCALL
);
1276 destRect
.right
+= pDestPoint
->x
;
1277 destRect
.bottom
+= pDestPoint
->y
;
1280 user_assert(destRect
.right
<= dst
->desc
.Width
&&
1281 destRect
.bottom
<= dst
->desc
.Height
,
1282 D3DERR_INVALIDCALL
);
1284 if (compressed_format(dst
->desc
.Format
)) {
1285 const unsigned w
= util_format_get_blockwidth(dst
->base
.info
.format
);
1286 const unsigned h
= util_format_get_blockheight(dst
->base
.info
.format
);
1289 user_assert(!(pDestPoint
->x
% w
) && !(pDestPoint
->y
% h
),
1290 D3DERR_INVALIDCALL
);
1294 user_assert(!(pSourceRect
->left
% w
) && !(pSourceRect
->top
% h
),
1295 D3DERR_INVALIDCALL
);
1297 if (!(copy_width
== src
->desc
.Width
&&
1298 copy_width
== dst
->desc
.Width
&&
1299 copy_height
== src
->desc
.Height
&&
1300 copy_height
== dst
->desc
.Height
)) {
1301 user_assert(!(copy_width
% w
) && !(copy_height
% h
),
1302 D3DERR_INVALIDCALL
);
1306 NineSurface9_CopyMemToDefault(dst
, src
, pDestPoint
, pSourceRect
);
1312 NineDevice9_UpdateTexture( struct NineDevice9
*This
,
1313 IDirect3DBaseTexture9
*pSourceTexture
,
1314 IDirect3DBaseTexture9
*pDestinationTexture
)
1316 struct NineBaseTexture9
*dstb
= NineBaseTexture9(pDestinationTexture
);
1317 struct NineBaseTexture9
*srcb
= NineBaseTexture9(pSourceTexture
);
1319 unsigned last_level
= dstb
->base
.info
.last_level
;
1322 DBG("This=%p pSourceTexture=%p pDestinationTexture=%p\n", This
,
1323 pSourceTexture
, pDestinationTexture
);
1325 user_assert(pSourceTexture
!= pDestinationTexture
, D3DERR_INVALIDCALL
);
1327 user_assert(dstb
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1328 user_assert(srcb
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1330 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1331 /* Only the first level is updated, the others regenerated. */
1333 /* if the source has D3DUSAGE_AUTOGENMIPMAP, we have to ignore
1334 * the sublevels, thus level 0 has to match */
1335 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ||
1336 (srcb
->base
.info
.width0
== dstb
->base
.info
.width0
&&
1337 srcb
->base
.info
.height0
== dstb
->base
.info
.height0
&&
1338 srcb
->base
.info
.depth0
== dstb
->base
.info
.depth0
),
1339 D3DERR_INVALIDCALL
);
1341 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
), D3DERR_INVALIDCALL
);
1344 user_assert(dstb
->base
.type
== srcb
->base
.type
, D3DERR_INVALIDCALL
);
1346 /* Find src level that matches dst level 0: */
1347 user_assert(srcb
->base
.info
.width0
>= dstb
->base
.info
.width0
&&
1348 srcb
->base
.info
.height0
>= dstb
->base
.info
.height0
&&
1349 srcb
->base
.info
.depth0
>= dstb
->base
.info
.depth0
,
1350 D3DERR_INVALIDCALL
);
1351 for (m
= 0; m
<= srcb
->base
.info
.last_level
; ++m
) {
1352 unsigned w
= u_minify(srcb
->base
.info
.width0
, m
);
1353 unsigned h
= u_minify(srcb
->base
.info
.height0
, m
);
1354 unsigned d
= u_minify(srcb
->base
.info
.depth0
, m
);
1356 if (w
== dstb
->base
.info
.width0
&&
1357 h
== dstb
->base
.info
.height0
&&
1358 d
== dstb
->base
.info
.depth0
)
1361 user_assert(m
<= srcb
->base
.info
.last_level
, D3DERR_INVALIDCALL
);
1363 last_level
= MIN2(last_level
, srcb
->base
.info
.last_level
- m
);
1365 if (dstb
->base
.type
== D3DRTYPE_TEXTURE
) {
1366 struct NineTexture9
*dst
= NineTexture9(dstb
);
1367 struct NineTexture9
*src
= NineTexture9(srcb
);
1369 if (src
->dirty_rect
.width
== 0)
1372 pipe_box_to_rect(&rect
, &src
->dirty_rect
);
1373 for (l
= 0; l
< m
; ++l
)
1374 rect_minify_inclusive(&rect
);
1376 for (l
= 0; l
<= last_level
; ++l
, ++m
) {
1377 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1379 dst
->surfaces
[l
]->desc
.Width
,
1380 dst
->surfaces
[l
]->desc
.Height
);
1381 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
],
1385 rect_minify_inclusive(&rect
);
1387 u_box_origin_2d(0, 0, &src
->dirty_rect
);
1389 if (dstb
->base
.type
== D3DRTYPE_CUBETEXTURE
) {
1390 struct NineCubeTexture9
*dst
= NineCubeTexture9(dstb
);
1391 struct NineCubeTexture9
*src
= NineCubeTexture9(srcb
);
1394 /* GPUs usually have them stored as arrays of mip-mapped 2D textures. */
1395 for (z
= 0; z
< 6; ++z
) {
1396 if (src
->dirty_rect
[z
].width
== 0)
1399 pipe_box_to_rect(&rect
, &src
->dirty_rect
[z
]);
1400 for (l
= 0; l
< m
; ++l
)
1401 rect_minify_inclusive(&rect
);
1403 for (l
= 0; l
<= last_level
; ++l
, ++m
) {
1404 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1406 dst
->surfaces
[l
* 6 + z
]->desc
.Width
,
1407 dst
->surfaces
[l
* 6 + z
]->desc
.Height
);
1408 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
* 6 + z
],
1409 src
->surfaces
[m
* 6 + z
],
1412 rect_minify_inclusive(&rect
);
1414 u_box_origin_2d(0, 0, &src
->dirty_rect
[z
]);
1418 if (dstb
->base
.type
== D3DRTYPE_VOLUMETEXTURE
) {
1419 struct NineVolumeTexture9
*dst
= NineVolumeTexture9(dstb
);
1420 struct NineVolumeTexture9
*src
= NineVolumeTexture9(srcb
);
1422 if (src
->dirty_box
.width
== 0)
1424 for (l
= 0; l
<= last_level
; ++l
, ++m
)
1425 NineVolume9_CopyMemToDefault(dst
->volumes
[l
],
1426 src
->volumes
[m
], 0, 0, 0, NULL
);
1427 u_box_3d(0, 0, 0, 0, 0, 0, &src
->dirty_box
);
1429 assert(!"invalid texture type");
1432 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1433 dstb
->dirty_mip
= TRUE
;
1434 NineBaseTexture9_GenerateMipSubLevels(dstb
);
1441 NineDevice9_GetRenderTargetData( struct NineDevice9
*This
,
1442 IDirect3DSurface9
*pRenderTarget
,
1443 IDirect3DSurface9
*pDestSurface
)
1445 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1446 struct NineSurface9
*src
= NineSurface9(pRenderTarget
);
1448 DBG("This=%p pRenderTarget=%p pDestSurface=%p\n",
1449 This
, pRenderTarget
, pDestSurface
);
1451 user_assert(dst
->desc
.Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1452 user_assert(src
->desc
.Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1454 user_assert(dst
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1455 user_assert(src
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1457 user_assert(src
->desc
.Width
== dst
->desc
.Width
, D3DERR_INVALIDCALL
);
1458 user_assert(src
->desc
.Height
== dst
->desc
.Height
, D3DERR_INVALIDCALL
);
1460 NineSurface9_CopyDefaultToMem(dst
, src
);
1466 NineDevice9_GetFrontBufferData( struct NineDevice9
*This
,
1468 IDirect3DSurface9
*pDestSurface
)
1470 DBG("This=%p iSwapChain=%u pDestSurface=%p\n", This
,
1471 iSwapChain
, pDestSurface
);
1473 user_assert(pDestSurface
!= NULL
, D3DERR_INVALIDCALL
);
1474 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
1476 return NineSwapChain9_GetFrontBufferData(This
->swapchains
[iSwapChain
],
1481 NineDevice9_StretchRect( struct NineDevice9
*This
,
1482 IDirect3DSurface9
*pSourceSurface
,
1483 const RECT
*pSourceRect
,
1484 IDirect3DSurface9
*pDestSurface
,
1485 const RECT
*pDestRect
,
1486 D3DTEXTUREFILTERTYPE Filter
)
1488 struct pipe_screen
*screen
= This
->screen
;
1489 struct pipe_context
*pipe
= This
->pipe
;
1490 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1491 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1492 struct pipe_resource
*dst_res
= NineSurface9_GetResource(dst
);
1493 struct pipe_resource
*src_res
= NineSurface9_GetResource(src
);
1495 struct pipe_blit_info blit
;
1496 boolean scaled
, clamped
, ms
, flip_x
= FALSE
, flip_y
= FALSE
;
1498 DBG("This=%p pSourceSurface=%p pSourceRect=%p pDestSurface=%p "
1499 "pDestRect=%p Filter=%u\n",
1500 This
, pSourceSurface
, pSourceRect
, pDestSurface
, pDestRect
, Filter
);
1502 DBG("pSourceRect=(%u,%u)-(%u,%u)\n",
1503 pSourceRect
->left
, pSourceRect
->top
,
1504 pSourceRect
->right
, pSourceRect
->bottom
);
1506 DBG("pDestRect=(%u,%u)-(%u,%u)\n", pDestRect
->left
, pDestRect
->top
,
1507 pDestRect
->right
, pDestRect
->bottom
);
1509 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
&&
1510 src
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1511 zs
= util_format_is_depth_or_stencil(dst_res
->format
);
1512 user_assert(!zs
|| !This
->in_scene
, D3DERR_INVALIDCALL
);
1513 user_assert(!zs
|| !pSourceRect
||
1514 (pSourceRect
->left
== 0 &&
1515 pSourceRect
->top
== 0 &&
1516 pSourceRect
->right
== src
->desc
.Width
&&
1517 pSourceRect
->bottom
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1518 user_assert(!zs
|| !pDestRect
||
1519 (pDestRect
->left
== 0 &&
1520 pDestRect
->top
== 0 &&
1521 pDestRect
->right
== dst
->desc
.Width
&&
1522 pDestRect
->bottom
== dst
->desc
.Height
), D3DERR_INVALIDCALL
);
1524 (dst
->desc
.Width
== src
->desc
.Width
&&
1525 dst
->desc
.Height
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1526 user_assert(zs
|| !util_format_is_depth_or_stencil(src_res
->format
),
1527 D3DERR_INVALIDCALL
);
1528 user_assert(!zs
|| dst
->desc
.Format
== src
->desc
.Format
,
1529 D3DERR_INVALIDCALL
);
1530 user_assert(screen
->is_format_supported(screen
, src_res
->format
,
1532 src_res
->nr_samples
,
1533 PIPE_BIND_SAMPLER_VIEW
),
1534 D3DERR_INVALIDCALL
);
1536 /* We might want to permit these, but wine thinks we shouldn't. */
1537 user_assert(!pDestRect
||
1538 (pDestRect
->left
<= pDestRect
->right
&&
1539 pDestRect
->top
<= pDestRect
->bottom
), D3DERR_INVALIDCALL
);
1540 user_assert(!pSourceRect
||
1541 (pSourceRect
->left
<= pSourceRect
->right
&&
1542 pSourceRect
->top
<= pSourceRect
->bottom
), D3DERR_INVALIDCALL
);
1544 memset(&blit
, 0, sizeof(blit
));
1545 blit
.dst
.resource
= dst_res
;
1546 blit
.dst
.level
= dst
->level
;
1547 blit
.dst
.box
.z
= dst
->layer
;
1548 blit
.dst
.box
.depth
= 1;
1549 blit
.dst
.format
= dst_res
->format
;
1551 flip_x
= pDestRect
->left
> pDestRect
->right
;
1553 blit
.dst
.box
.x
= pDestRect
->right
;
1554 blit
.dst
.box
.width
= pDestRect
->left
- pDestRect
->right
;
1556 blit
.dst
.box
.x
= pDestRect
->left
;
1557 blit
.dst
.box
.width
= pDestRect
->right
- pDestRect
->left
;
1559 flip_y
= pDestRect
->top
> pDestRect
->bottom
;
1561 blit
.dst
.box
.y
= pDestRect
->bottom
;
1562 blit
.dst
.box
.height
= pDestRect
->top
- pDestRect
->bottom
;
1564 blit
.dst
.box
.y
= pDestRect
->top
;
1565 blit
.dst
.box
.height
= pDestRect
->bottom
- pDestRect
->top
;
1570 blit
.dst
.box
.width
= dst
->desc
.Width
;
1571 blit
.dst
.box
.height
= dst
->desc
.Height
;
1573 blit
.src
.resource
= src_res
;
1574 blit
.src
.level
= src
->level
;
1575 blit
.src
.box
.z
= src
->layer
;
1576 blit
.src
.box
.depth
= 1;
1577 blit
.src
.format
= src_res
->format
;
1579 if (flip_x
^ (pSourceRect
->left
> pSourceRect
->right
)) {
1580 blit
.src
.box
.x
= pSourceRect
->right
;
1581 blit
.src
.box
.width
= pSourceRect
->left
- pSourceRect
->right
;
1583 blit
.src
.box
.x
= pSourceRect
->left
;
1584 blit
.src
.box
.width
= pSourceRect
->right
- pSourceRect
->left
;
1586 if (flip_y
^ (pSourceRect
->top
> pSourceRect
->bottom
)) {
1587 blit
.src
.box
.y
= pSourceRect
->bottom
;
1588 blit
.src
.box
.height
= pSourceRect
->top
- pSourceRect
->bottom
;
1590 blit
.src
.box
.y
= pSourceRect
->top
;
1591 blit
.src
.box
.height
= pSourceRect
->bottom
- pSourceRect
->top
;
1594 blit
.src
.box
.x
= flip_x
? src
->desc
.Width
: 0;
1595 blit
.src
.box
.y
= flip_y
? src
->desc
.Height
: 0;
1596 blit
.src
.box
.width
= flip_x
? -src
->desc
.Width
: src
->desc
.Width
;
1597 blit
.src
.box
.height
= flip_y
? -src
->desc
.Height
: src
->desc
.Height
;
1599 blit
.mask
= zs
? PIPE_MASK_ZS
: PIPE_MASK_RGBA
;
1600 blit
.filter
= Filter
== D3DTEXF_LINEAR
?
1601 PIPE_TEX_FILTER_LINEAR
: PIPE_TEX_FILTER_NEAREST
;
1602 blit
.scissor_enable
= FALSE
;
1603 blit
.alpha_blend
= FALSE
;
1605 /* If both of a src and dst dimension are negative, flip them. */
1606 if (blit
.dst
.box
.width
< 0 && blit
.src
.box
.width
< 0) {
1607 blit
.dst
.box
.width
= -blit
.dst
.box
.width
;
1608 blit
.src
.box
.width
= -blit
.src
.box
.width
;
1610 if (blit
.dst
.box
.height
< 0 && blit
.src
.box
.height
< 0) {
1611 blit
.dst
.box
.height
= -blit
.dst
.box
.height
;
1612 blit
.src
.box
.height
= -blit
.src
.box
.height
;
1615 blit
.dst
.box
.width
!= blit
.src
.box
.width
||
1616 blit
.dst
.box
.height
!= blit
.src
.box
.height
;
1618 user_assert(!scaled
|| dst
!= src
, D3DERR_INVALIDCALL
);
1619 user_assert(!scaled
||
1620 !NineSurface9_IsOffscreenPlain(dst
), D3DERR_INVALIDCALL
);
1621 user_assert(!NineSurface9_IsOffscreenPlain(dst
) ||
1622 NineSurface9_IsOffscreenPlain(src
), D3DERR_INVALIDCALL
);
1623 user_assert(NineSurface9_IsOffscreenPlain(dst
) ||
1624 dst
->desc
.Usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
),
1625 D3DERR_INVALIDCALL
);
1626 user_assert(!scaled
||
1627 (!util_format_is_compressed(dst
->base
.info
.format
) &&
1628 !util_format_is_compressed(src
->base
.info
.format
)),
1629 D3DERR_INVALIDCALL
);
1631 user_warn(src
== dst
&&
1632 u_box_test_intersection_2d(&blit
.src
.box
, &blit
.dst
.box
));
1634 /* Check for clipping/clamping: */
1636 struct pipe_box box
;
1639 xy
= u_box_clip_2d(&box
, &blit
.dst
.box
,
1640 dst
->desc
.Width
, dst
->desc
.Height
);
1644 xy
= u_box_clip_2d(&box
, &blit
.src
.box
,
1645 src
->desc
.Width
, src
->desc
.Height
);
1649 ms
= (dst
->desc
.MultiSampleType
| 1) != (src
->desc
.MultiSampleType
| 1);
1651 if (clamped
|| scaled
|| (blit
.dst
.format
!= blit
.src
.format
) || ms
) {
1652 DBG("using pipe->blit()\n");
1653 /* TODO: software scaling */
1654 user_assert(screen
->is_format_supported(screen
, dst_res
->format
,
1656 dst_res
->nr_samples
,
1657 zs
? PIPE_BIND_DEPTH_STENCIL
:
1658 PIPE_BIND_RENDER_TARGET
),
1659 D3DERR_INVALIDCALL
);
1661 pipe
->blit(pipe
, &blit
);
1663 assert(blit
.dst
.box
.x
>= 0 && blit
.dst
.box
.y
>= 0 &&
1664 blit
.src
.box
.x
>= 0 && blit
.src
.box
.y
>= 0 &&
1665 blit
.dst
.box
.x
+ blit
.dst
.box
.width
<= dst
->desc
.Width
&&
1666 blit
.src
.box
.x
+ blit
.src
.box
.width
<= src
->desc
.Width
&&
1667 blit
.dst
.box
.y
+ blit
.dst
.box
.height
<= dst
->desc
.Height
&&
1668 blit
.src
.box
.y
+ blit
.src
.box
.height
<= src
->desc
.Height
);
1669 /* Or drivers might crash ... */
1670 DBG("Using resource_copy_region.\n");
1671 pipe
->resource_copy_region(pipe
,
1672 blit
.dst
.resource
, blit
.dst
.level
,
1673 blit
.dst
.box
.x
, blit
.dst
.box
.y
, blit
.dst
.box
.z
,
1674 blit
.src
.resource
, blit
.src
.level
,
1678 /* Communicate the container it needs to update sublevels - if apply */
1679 NineSurface9_MarkContainerDirty(dst
);
1685 NineDevice9_ColorFill( struct NineDevice9
*This
,
1686 IDirect3DSurface9
*pSurface
,
1690 struct pipe_context
*pipe
= This
->pipe
;
1691 struct NineSurface9
*surf
= NineSurface9(pSurface
);
1692 struct pipe_surface
*psurf
;
1693 unsigned x
, y
, w
, h
;
1694 union pipe_color_union rgba
;
1697 DBG("This=%p pSurface=%p pRect=%p color=%08x\n", This
,
1698 pSurface
, pRect
, color
);
1700 DBG("pRect=(%u,%u)-(%u,%u)\n", pRect
->left
, pRect
->top
,
1701 pRect
->right
, pRect
->bottom
);
1703 user_assert(surf
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1705 user_assert((surf
->base
.usage
& D3DUSAGE_RENDERTARGET
) ||
1706 NineSurface9_IsOffscreenPlain(surf
), D3DERR_INVALIDCALL
);
1708 user_assert(surf
->desc
.Format
!= D3DFMT_NULL
, D3D_OK
);
1713 w
= pRect
->right
- pRect
->left
;
1714 h
= pRect
->bottom
- pRect
->top
;
1718 w
= surf
->desc
.Width
;
1719 h
= surf
->desc
.Height
;
1721 d3dcolor_to_pipe_color_union(&rgba
, color
);
1723 fallback
= !(surf
->base
.info
.bind
& PIPE_BIND_RENDER_TARGET
);
1726 psurf
= NineSurface9_GetSurface(surf
, 0);
1732 pipe
->clear_render_target(pipe
, psurf
, &rgba
, x
, y
, w
, h
);
1734 D3DLOCKED_RECT lock
;
1735 union util_color uc
;
1737 /* XXX: lock pRect and fix util_fill_rect */
1738 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, 0);
1741 util_pack_color_ub(color
>> 16, color
>> 8, color
>> 0, color
>> 24,
1742 surf
->base
.info
.format
, &uc
);
1743 util_fill_rect(lock
.pBits
, surf
->base
.info
.format
,lock
.Pitch
,
1745 NineSurface9_UnlockRect(surf
);
1752 NineDevice9_CreateOffscreenPlainSurface( struct NineDevice9
*This
,
1757 IDirect3DSurface9
**ppSurface
,
1758 HANDLE
*pSharedHandle
)
1762 DBG("This=%p Width=%u Height=%u Format=%s(0x%x) Pool=%u "
1763 "ppSurface=%p pSharedHandle=%p\n", This
,
1764 Width
, Height
, d3dformat_to_string(Format
), Format
, Pool
,
1765 ppSurface
, pSharedHandle
);
1768 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
1769 || Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1770 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1772 /* Can be used with StretchRect and ColorFill. It's also always lockable.
1774 hr
= create_zs_or_rt_surface(This
, 2, Pool
, Width
, Height
,
1776 D3DMULTISAMPLE_NONE
, 0,
1778 ppSurface
, pSharedHandle
);
1780 DBG("Failed to create surface.\n");
1785 NineDevice9_SetRenderTarget( struct NineDevice9
*This
,
1786 DWORD RenderTargetIndex
,
1787 IDirect3DSurface9
*pRenderTarget
)
1789 struct NineSurface9
*rt
= NineSurface9(pRenderTarget
);
1790 const unsigned i
= RenderTargetIndex
;
1792 DBG("This=%p RenderTargetIndex=%u pRenderTarget=%p\n", This
,
1793 RenderTargetIndex
, pRenderTarget
);
1795 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1796 user_assert(i
!= 0 || pRenderTarget
, D3DERR_INVALIDCALL
);
1797 user_assert(!pRenderTarget
||
1798 rt
->desc
.Usage
& D3DUSAGE_RENDERTARGET
, D3DERR_INVALIDCALL
);
1801 This
->state
.viewport
.X
= 0;
1802 This
->state
.viewport
.Y
= 0;
1803 This
->state
.viewport
.Width
= rt
->desc
.Width
;
1804 This
->state
.viewport
.Height
= rt
->desc
.Height
;
1805 This
->state
.viewport
.MinZ
= 0.0f
;
1806 This
->state
.viewport
.MaxZ
= 1.0f
;
1808 This
->state
.scissor
.minx
= 0;
1809 This
->state
.scissor
.miny
= 0;
1810 This
->state
.scissor
.maxx
= rt
->desc
.Width
;
1811 This
->state
.scissor
.maxy
= rt
->desc
.Height
;
1813 This
->state
.changed
.group
|= NINE_STATE_VIEWPORT
| NINE_STATE_SCISSOR
;
1816 if (This
->state
.rt
[i
] != NineSurface9(pRenderTarget
)) {
1817 nine_bind(&This
->state
.rt
[i
], pRenderTarget
);
1818 This
->state
.changed
.group
|= NINE_STATE_FB
;
1824 NineDevice9_GetRenderTarget( struct NineDevice9
*This
,
1825 DWORD RenderTargetIndex
,
1826 IDirect3DSurface9
**ppRenderTarget
)
1828 const unsigned i
= RenderTargetIndex
;
1830 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1831 user_assert(ppRenderTarget
, D3DERR_INVALIDCALL
);
1833 *ppRenderTarget
= (IDirect3DSurface9
*)This
->state
.rt
[i
];
1834 if (!This
->state
.rt
[i
])
1835 return D3DERR_NOTFOUND
;
1837 NineUnknown_AddRef(NineUnknown(This
->state
.rt
[i
]));
1842 NineDevice9_SetDepthStencilSurface( struct NineDevice9
*This
,
1843 IDirect3DSurface9
*pNewZStencil
)
1845 DBG("This=%p pNewZStencil=%p\n", This
, pNewZStencil
);
1847 if (This
->state
.ds
!= NineSurface9(pNewZStencil
)) {
1848 nine_bind(&This
->state
.ds
, pNewZStencil
);
1849 This
->state
.changed
.group
|= NINE_STATE_FB
;
1855 NineDevice9_GetDepthStencilSurface( struct NineDevice9
*This
,
1856 IDirect3DSurface9
**ppZStencilSurface
)
1858 user_assert(ppZStencilSurface
, D3DERR_INVALIDCALL
);
1860 *ppZStencilSurface
= (IDirect3DSurface9
*)This
->state
.ds
;
1861 if (!This
->state
.ds
)
1862 return D3DERR_NOTFOUND
;
1864 NineUnknown_AddRef(NineUnknown(This
->state
.ds
));
1869 NineDevice9_BeginScene( struct NineDevice9
*This
)
1871 DBG("This=%p\n", This
);
1872 user_assert(!This
->in_scene
, D3DERR_INVALIDCALL
);
1873 This
->in_scene
= TRUE
;
1874 /* Do we want to do anything else here ? */
1879 NineDevice9_EndScene( struct NineDevice9
*This
)
1881 DBG("This=%p\n", This
);
1882 user_assert(This
->in_scene
, D3DERR_INVALIDCALL
);
1883 This
->in_scene
= FALSE
;
1888 NineDevice9_Clear( struct NineDevice9
*This
,
1890 const D3DRECT
*pRects
,
1896 const int sRGB
= This
->state
.rs
[D3DRS_SRGBWRITEENABLE
] ? 1 : 0;
1897 struct pipe_surface
*cbuf
, *zsbuf
;
1898 struct pipe_context
*pipe
= This
->pipe
;
1899 struct NineSurface9
*zsbuf_surf
= This
->state
.ds
;
1900 struct NineSurface9
*rt
;
1903 union pipe_color_union rgba
;
1904 unsigned rt_mask
= 0;
1907 DBG("This=%p Count=%u pRects=%p Flags=%x Color=%08x Z=%f Stencil=%x\n",
1908 This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1910 user_assert(This
->state
.ds
|| !(Flags
& NINED3DCLEAR_DEPTHSTENCIL
),
1911 D3DERR_INVALIDCALL
);
1912 user_assert(!(Flags
& D3DCLEAR_STENCIL
) ||
1914 util_format_is_depth_and_stencil(zsbuf_surf
->base
.info
.format
)),
1915 D3DERR_INVALIDCALL
);
1917 user_assert((Count
&& pRects
) || (!Count
&& !pRects
), D3DERR_INVALIDCALL
);
1919 user_warn((pRects
&& !Count
) || (!pRects
&& Count
));
1920 if (pRects
&& !Count
)
1926 nine_update_state_framebuffer(This
);
1928 if (Flags
& D3DCLEAR_TARGET
) bufs
|= PIPE_CLEAR_COLOR
;
1929 /* Ignore Z buffer if not bound */
1930 if (This
->state
.fb
.zsbuf
!= NULL
) {
1931 if (Flags
& D3DCLEAR_ZBUFFER
) bufs
|= PIPE_CLEAR_DEPTH
;
1932 if (Flags
& D3DCLEAR_STENCIL
) bufs
|= PIPE_CLEAR_STENCIL
;
1936 d3dcolor_to_pipe_color_union(&rgba
, Color
);
1938 rect
.x1
= This
->state
.viewport
.X
;
1939 rect
.y1
= This
->state
.viewport
.Y
;
1940 rect
.x2
= This
->state
.viewport
.Width
+ rect
.x1
;
1941 rect
.y2
= This
->state
.viewport
.Height
+ rect
.y1
;
1943 /* Both rectangles apply, which is weird, but that's D3D9. */
1944 if (This
->state
.rs
[D3DRS_SCISSORTESTENABLE
]) {
1945 rect
.x1
= MAX2(rect
.x1
, This
->state
.scissor
.minx
);
1946 rect
.y1
= MAX2(rect
.y1
, This
->state
.scissor
.miny
);
1947 rect
.x2
= MIN2(rect
.x2
, This
->state
.scissor
.maxx
);
1948 rect
.y2
= MIN2(rect
.y2
, This
->state
.scissor
.maxy
);
1952 /* Maybe apps like to specify a large rect ? */
1953 if (pRects
[0].x1
<= rect
.x1
&& pRects
[0].x2
>= rect
.x2
&&
1954 pRects
[0].y1
<= rect
.y1
&& pRects
[0].y2
>= rect
.y2
) {
1955 DBG("First rect covers viewport.\n");
1961 if (rect
.x1
>= This
->state
.fb
.width
|| rect
.y1
>= This
->state
.fb
.height
)
1964 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
1965 if (This
->state
.rt
[i
] && This
->state
.rt
[i
]->desc
.Format
!= D3DFMT_NULL
)
1969 /* fast path, clears everything at once */
1971 (!(bufs
& PIPE_CLEAR_COLOR
) || (rt_mask
== This
->state
.rt_mask
)) &&
1972 rect
.x1
== 0 && rect
.y1
== 0 &&
1973 /* Case we clear only render target. Check clear region vs rt. */
1974 ((!(bufs
& (PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
)) &&
1975 rect
.x2
>= This
->state
.fb
.width
&&
1976 rect
.y2
>= This
->state
.fb
.height
) ||
1977 /* Case we clear depth buffer (and eventually rt too).
1978 * depth buffer size is always >= rt size. Compare to clear region */
1979 ((bufs
& (PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
)) &&
1980 rect
.x2
>= zsbuf_surf
->desc
.Width
&&
1981 rect
.y2
>= zsbuf_surf
->desc
.Height
))) {
1982 DBG("Clear fast path\n");
1983 pipe
->clear(pipe
, bufs
, &rgba
, Z
, Stencil
);
1992 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
1993 rt
= This
->state
.rt
[i
];
1994 if (!rt
|| rt
->desc
.Format
== D3DFMT_NULL
||
1995 !(Flags
& D3DCLEAR_TARGET
))
1996 continue; /* save space, compiler should hoist this */
1997 cbuf
= NineSurface9_GetSurface(rt
, sRGB
);
1998 for (r
= 0; r
< Count
; ++r
) {
1999 /* Don't trust users to pass these in the right order. */
2000 unsigned x1
= MIN2(pRects
[r
].x1
, pRects
[r
].x2
);
2001 unsigned y1
= MIN2(pRects
[r
].y1
, pRects
[r
].y2
);
2002 unsigned x2
= MAX2(pRects
[r
].x1
, pRects
[r
].x2
);
2003 unsigned y2
= MAX2(pRects
[r
].y1
, pRects
[r
].y2
);
2005 /* Drop negative rectangles (like wine expects). */
2006 if (pRects
[r
].x1
> pRects
[r
].x2
) continue;
2007 if (pRects
[r
].y1
> pRects
[r
].y2
) continue;
2010 x1
= MAX2(x1
, rect
.x1
);
2011 y1
= MAX2(y1
, rect
.y1
);
2012 x2
= MIN3(x2
, rect
.x2
, rt
->desc
.Width
);
2013 y2
= MIN3(y2
, rect
.y2
, rt
->desc
.Height
);
2015 DBG("Clearing (%u..%u)x(%u..%u)\n", x1
, x2
, y1
, y2
);
2016 pipe
->clear_render_target(pipe
, cbuf
, &rgba
,
2017 x1
, y1
, x2
- x1
, y2
- y1
);
2020 if (!(Flags
& NINED3DCLEAR_DEPTHSTENCIL
))
2023 bufs
&= PIPE_CLEAR_DEPTHSTENCIL
;
2025 for (r
= 0; r
< Count
; ++r
) {
2026 unsigned x1
= MIN2(pRects
[r
].x1
, pRects
[r
].x2
);
2027 unsigned y1
= MIN2(pRects
[r
].y1
, pRects
[r
].y2
);
2028 unsigned x2
= MAX2(pRects
[r
].x1
, pRects
[r
].x2
);
2029 unsigned y2
= MAX2(pRects
[r
].y1
, pRects
[r
].y2
);
2031 /* Drop negative rectangles. */
2032 if (pRects
[r
].x1
> pRects
[r
].x2
) continue;
2033 if (pRects
[r
].y1
> pRects
[r
].y2
) continue;
2036 x1
= MIN2(x1
, rect
.x1
);
2037 y1
= MIN2(y1
, rect
.y1
);
2038 x2
= MIN3(x2
, rect
.x2
, zsbuf_surf
->desc
.Width
);
2039 y2
= MIN3(y2
, rect
.y2
, zsbuf_surf
->desc
.Height
);
2041 zsbuf
= NineSurface9_GetSurface(zsbuf_surf
, 0);
2043 pipe
->clear_depth_stencil(pipe
, zsbuf
, bufs
, Z
, Stencil
,
2044 x1
, y1
, x2
- x1
, y2
- y1
);
2050 NineDevice9_SetTransform( struct NineDevice9
*This
,
2051 D3DTRANSFORMSTATETYPE State
,
2052 const D3DMATRIX
*pMatrix
)
2054 struct nine_state
*state
= This
->update
;
2055 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
2057 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2059 user_assert(M
, D3DERR_INVALIDCALL
);
2062 state
->ff
.changed
.transform
[State
/ 32] |= 1 << (State
% 32);
2063 state
->changed
.group
|= NINE_STATE_FF
;
2069 NineDevice9_GetTransform( struct NineDevice9
*This
,
2070 D3DTRANSFORMSTATETYPE State
,
2071 D3DMATRIX
*pMatrix
)
2073 D3DMATRIX
*M
= nine_state_access_transform(&This
->state
, State
, FALSE
);
2074 user_assert(M
, D3DERR_INVALIDCALL
);
2080 NineDevice9_MultiplyTransform( struct NineDevice9
*This
,
2081 D3DTRANSFORMSTATETYPE State
,
2082 const D3DMATRIX
*pMatrix
)
2084 struct nine_state
*state
= This
->update
;
2086 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
2088 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2090 user_assert(M
, D3DERR_INVALIDCALL
);
2092 nine_d3d_matrix_matrix_mul(&T
, pMatrix
, M
);
2093 return NineDevice9_SetTransform(This
, State
, &T
);
2097 NineDevice9_SetViewport( struct NineDevice9
*This
,
2098 const D3DVIEWPORT9
*pViewport
)
2100 struct nine_state
*state
= This
->update
;
2102 DBG("X=%u Y=%u W=%u H=%u MinZ=%f MaxZ=%f\n",
2103 pViewport
->X
, pViewport
->Y
, pViewport
->Width
, pViewport
->Height
,
2104 pViewport
->MinZ
, pViewport
->MaxZ
);
2106 state
->viewport
= *pViewport
;
2107 state
->changed
.group
|= NINE_STATE_VIEWPORT
;
2113 NineDevice9_GetViewport( struct NineDevice9
*This
,
2114 D3DVIEWPORT9
*pViewport
)
2116 *pViewport
= This
->state
.viewport
;
2121 NineDevice9_SetMaterial( struct NineDevice9
*This
,
2122 const D3DMATERIAL9
*pMaterial
)
2124 struct nine_state
*state
= This
->update
;
2126 DBG("This=%p pMaterial=%p\n", This
, pMaterial
);
2128 nine_dump_D3DMATERIAL9(DBG_FF
, pMaterial
);
2130 user_assert(pMaterial
, E_POINTER
);
2132 state
->ff
.material
= *pMaterial
;
2133 state
->changed
.group
|= NINE_STATE_FF_MATERIAL
;
2139 NineDevice9_GetMaterial( struct NineDevice9
*This
,
2140 D3DMATERIAL9
*pMaterial
)
2142 user_assert(pMaterial
, E_POINTER
);
2143 *pMaterial
= This
->state
.ff
.material
;
2148 NineDevice9_SetLight( struct NineDevice9
*This
,
2150 const D3DLIGHT9
*pLight
)
2152 struct nine_state
*state
= This
->update
;
2154 DBG("This=%p Index=%u pLight=%p\n", This
, Index
, pLight
);
2156 nine_dump_D3DLIGHT9(DBG_FF
, pLight
);
2158 user_assert(pLight
, D3DERR_INVALIDCALL
);
2159 user_assert(pLight
->Type
< NINED3DLIGHT_INVALID
, D3DERR_INVALIDCALL
);
2161 user_assert(Index
< NINE_MAX_LIGHTS
, D3DERR_INVALIDCALL
); /* sanity */
2163 if (Index
>= state
->ff
.num_lights
) {
2164 unsigned n
= state
->ff
.num_lights
;
2165 unsigned N
= Index
+ 1;
2167 state
->ff
.light
= REALLOC(state
->ff
.light
, n
* sizeof(D3DLIGHT9
),
2168 N
* sizeof(D3DLIGHT9
));
2169 if (!state
->ff
.light
)
2170 return E_OUTOFMEMORY
;
2171 state
->ff
.num_lights
= N
;
2173 for (; n
< Index
; ++n
) {
2174 memset(&state
->ff
.light
[n
], 0, sizeof(D3DLIGHT9
));
2175 state
->ff
.light
[n
].Type
= (D3DLIGHTTYPE
)NINED3DLIGHT_INVALID
;
2178 state
->ff
.light
[Index
] = *pLight
;
2180 if (pLight
->Type
== D3DLIGHT_SPOT
&& pLight
->Theta
>= pLight
->Phi
) {
2181 DBG("Warning: clamping D3DLIGHT9.Theta\n");
2182 state
->ff
.light
[Index
].Theta
= state
->ff
.light
[Index
].Phi
;
2184 if (pLight
->Type
!= D3DLIGHT_DIRECTIONAL
&&
2185 pLight
->Attenuation0
== 0.0f
&&
2186 pLight
->Attenuation1
== 0.0f
&&
2187 pLight
->Attenuation2
== 0.0f
) {
2188 DBG("Warning: all D3DLIGHT9.Attenuation[i] are 0\n");
2191 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2197 NineDevice9_GetLight( struct NineDevice9
*This
,
2201 const struct nine_state
*state
= &This
->state
;
2203 user_assert(pLight
, D3DERR_INVALIDCALL
);
2204 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2205 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2206 D3DERR_INVALIDCALL
);
2208 *pLight
= state
->ff
.light
[Index
];
2214 NineDevice9_LightEnable( struct NineDevice9
*This
,
2218 struct nine_state
*state
= This
->update
;
2221 DBG("This=%p Index=%u Enable=%i\n", This
, Index
, Enable
);
2223 if (Index
>= state
->ff
.num_lights
||
2224 state
->ff
.light
[Index
].Type
== NINED3DLIGHT_INVALID
) {
2225 /* This should create a default light. */
2227 memset(&light
, 0, sizeof(light
));
2228 light
.Type
= D3DLIGHT_DIRECTIONAL
;
2229 light
.Diffuse
.r
= 1.0f
;
2230 light
.Diffuse
.g
= 1.0f
;
2231 light
.Diffuse
.b
= 1.0f
;
2232 light
.Direction
.z
= 1.0f
;
2233 NineDevice9_SetLight(This
, Index
, &light
);
2235 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2237 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
) {
2238 if (state
->ff
.active_light
[i
] == Index
)
2243 if (i
< state
->ff
.num_lights_active
)
2245 /* XXX wine thinks this should still succeed:
2247 user_assert(i
< NINE_MAX_LIGHTS_ACTIVE
, D3DERR_INVALIDCALL
);
2249 state
->ff
.active_light
[i
] = Index
;
2250 state
->ff
.num_lights_active
++;
2252 if (i
== state
->ff
.num_lights_active
)
2254 --state
->ff
.num_lights_active
;
2255 for (; i
< state
->ff
.num_lights_active
; ++i
)
2256 state
->ff
.active_light
[i
] = state
->ff
.active_light
[i
+ 1];
2258 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2264 NineDevice9_GetLightEnable( struct NineDevice9
*This
,
2268 const struct nine_state
*state
= &This
->state
;
2271 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2272 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2273 D3DERR_INVALIDCALL
);
2275 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
)
2276 if (state
->ff
.active_light
[i
] == Index
)
2279 *pEnable
= i
!= state
->ff
.num_lights_active
? 128 : 0; // Taken from wine
2285 NineDevice9_SetClipPlane( struct NineDevice9
*This
,
2287 const float *pPlane
)
2289 struct nine_state
*state
= This
->update
;
2291 user_assert(pPlane
, D3DERR_INVALIDCALL
);
2293 DBG("This=%p Index=%u pPlane=%f %f %f %f\n", This
, Index
,
2294 pPlane
[0], pPlane
[1],
2295 pPlane
[2], pPlane
[3]);
2297 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2299 memcpy(&state
->clip
.ucp
[Index
][0], pPlane
, sizeof(state
->clip
.ucp
[0]));
2300 state
->changed
.ucp
|= 1 << Index
;
2306 NineDevice9_GetClipPlane( struct NineDevice9
*This
,
2310 const struct nine_state
*state
= &This
->state
;
2312 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2314 memcpy(pPlane
, &state
->clip
.ucp
[Index
][0], sizeof(state
->clip
.ucp
[0]));
2318 #define RESZ_CODE 0x7fa05000
2321 NineDevice9_ResolveZ( struct NineDevice9
*This
)
2323 struct nine_state
*state
= &This
->state
;
2324 const struct util_format_description
*desc
;
2325 struct NineSurface9
*source
= state
->ds
;
2326 struct NineBaseTexture9
*destination
= state
->texture
[0];
2327 struct pipe_resource
*src
, *dst
;
2328 struct pipe_blit_info blit
;
2330 DBG("RESZ resolve\n");
2332 user_assert(source
&& destination
&&
2333 destination
->base
.type
== D3DRTYPE_TEXTURE
, D3DERR_INVALIDCALL
);
2335 src
= source
->base
.resource
;
2336 dst
= destination
->base
.resource
;
2338 user_assert(src
&& dst
, D3DERR_INVALIDCALL
);
2340 /* check dst is depth format. we know already for src */
2341 desc
= util_format_description(dst
->format
);
2342 user_assert(desc
->colorspace
== UTIL_FORMAT_COLORSPACE_ZS
, D3DERR_INVALIDCALL
);
2344 memset(&blit
, 0, sizeof(blit
));
2345 blit
.src
.resource
= src
;
2347 blit
.src
.format
= src
->format
;
2349 blit
.src
.box
.depth
= 1;
2352 blit
.src
.box
.width
= src
->width0
;
2353 blit
.src
.box
.height
= src
->height0
;
2355 blit
.dst
.resource
= dst
;
2357 blit
.dst
.format
= dst
->format
;
2359 blit
.dst
.box
.depth
= 1;
2362 blit
.dst
.box
.width
= dst
->width0
;
2363 blit
.dst
.box
.height
= dst
->height0
;
2365 blit
.mask
= PIPE_MASK_ZS
;
2366 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
2367 blit
.scissor_enable
= FALSE
;
2369 This
->pipe
->blit(This
->pipe
, &blit
);
2373 #define ALPHA_TO_COVERAGE_ENABLE MAKEFOURCC('A', '2', 'M', '1')
2374 #define ALPHA_TO_COVERAGE_DISABLE MAKEFOURCC('A', '2', 'M', '0')
2377 NineDevice9_SetRenderState( struct NineDevice9
*This
,
2378 D3DRENDERSTATETYPE State
,
2381 struct nine_state
*state
= This
->update
;
2383 DBG("This=%p State=%u(%s) Value=%08x\n", This
,
2384 State
, nine_d3drs_to_string(State
), Value
);
2386 user_assert(State
< D3DRS_COUNT
, D3DERR_INVALIDCALL
);
2388 if (state
->rs_advertised
[State
] == Value
&& likely(!This
->is_recording
))
2391 state
->rs_advertised
[State
] = Value
;
2393 /* Amd hacks (equivalent to GL extensions) */
2394 if (unlikely(State
== D3DRS_POINTSIZE
)) {
2395 if (Value
== RESZ_CODE
)
2396 return NineDevice9_ResolveZ(This
);
2398 if (Value
== ALPHA_TO_COVERAGE_ENABLE
||
2399 Value
== ALPHA_TO_COVERAGE_DISABLE
) {
2400 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
== ALPHA_TO_COVERAGE_ENABLE
);
2401 state
->changed
.group
|= NINE_STATE_BLEND
;
2407 if (unlikely(State
== D3DRS_ADAPTIVETESS_Y
)) {
2408 if (Value
== D3DFMT_ATOC
|| (Value
== D3DFMT_UNKNOWN
&& state
->rs
[NINED3DRS_ALPHACOVERAGE
])) {
2409 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
== D3DFMT_ATOC
);
2410 state
->changed
.group
|= NINE_STATE_BLEND
;
2415 state
->rs
[State
] = nine_fix_render_state_value(State
, Value
);
2416 state
->changed
.rs
[State
/ 32] |= 1 << (State
% 32);
2417 state
->changed
.group
|= nine_render_state_group
[State
];
2423 NineDevice9_GetRenderState( struct NineDevice9
*This
,
2424 D3DRENDERSTATETYPE State
,
2427 user_assert(State
< D3DRS_COUNT
, D3DERR_INVALIDCALL
);
2429 *pValue
= This
->state
.rs_advertised
[State
];
2434 NineDevice9_CreateStateBlock( struct NineDevice9
*This
,
2435 D3DSTATEBLOCKTYPE Type
,
2436 IDirect3DStateBlock9
**ppSB
)
2438 struct NineStateBlock9
*nsb
;
2439 struct nine_state
*dst
;
2441 enum nine_stateblock_type type
;
2444 DBG("This=%p Type=%u ppSB=%p\n", This
, Type
, ppSB
);
2446 user_assert(Type
== D3DSBT_ALL
||
2447 Type
== D3DSBT_VERTEXSTATE
||
2448 Type
== D3DSBT_PIXELSTATE
, D3DERR_INVALIDCALL
);
2451 case D3DSBT_VERTEXSTATE
: type
= NINESBT_VERTEXSTATE
; break;
2452 case D3DSBT_PIXELSTATE
: type
= NINESBT_PIXELSTATE
; break;
2458 hr
= NineStateBlock9_new(This
, &nsb
, type
);
2461 *ppSB
= (IDirect3DStateBlock9
*)nsb
;
2464 dst
->changed
.group
=
2465 NINE_STATE_TEXTURE
|
2468 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_VERTEXSTATE
) {
2469 dst
->changed
.group
|=
2470 NINE_STATE_FF_LIGHTING
|
2471 NINE_STATE_VS
| NINE_STATE_VS_CONST
|
2473 /* TODO: texture/sampler state */
2474 memcpy(dst
->changed
.rs
,
2475 nine_render_states_vertex
, sizeof(dst
->changed
.rs
));
2476 nine_ranges_insert(&dst
->changed
.vs_const_f
, 0, This
->max_vs_const_f
,
2478 dst
->changed
.vs_const_i
= 0xffff;
2479 dst
->changed
.vs_const_b
= 0xffff;
2480 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2481 dst
->changed
.sampler
[s
] |= 1 << D3DSAMP_DMAPOFFSET
;
2482 if (This
->state
.ff
.num_lights
) {
2483 dst
->ff
.num_lights
= This
->state
.ff
.num_lights
;
2484 /* zero'd -> light type won't be NINED3DLIGHT_INVALID, so
2485 * all currently existing lights will be captured
2487 dst
->ff
.light
= CALLOC(This
->state
.ff
.num_lights
,
2489 if (!dst
->ff
.light
) {
2490 nine_bind(ppSB
, NULL
);
2491 return E_OUTOFMEMORY
;
2495 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_PIXELSTATE
) {
2496 dst
->changed
.group
|=
2497 NINE_STATE_PS
| NINE_STATE_PS_CONST
;
2498 /* TODO: texture/sampler state */
2499 memcpy(dst
->changed
.rs
,
2500 nine_render_states_pixel
, sizeof(dst
->changed
.rs
));
2501 nine_ranges_insert(&dst
->changed
.ps_const_f
, 0, This
->max_ps_const_f
,
2503 dst
->changed
.ps_const_i
= 0xffff;
2504 dst
->changed
.ps_const_b
= 0xffff;
2505 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2506 dst
->changed
.sampler
[s
] |= 0x1ffe;
2508 if (Type
== D3DSBT_ALL
) {
2509 dst
->changed
.group
|=
2510 NINE_STATE_VIEWPORT
|
2511 NINE_STATE_SCISSOR
|
2512 NINE_STATE_RASTERIZER
|
2516 NINE_STATE_MATERIAL
|
2517 NINE_STATE_BLEND_COLOR
|
2518 NINE_STATE_SAMPLE_MASK
;
2519 memset(dst
->changed
.rs
, ~0, (D3DRS_COUNT
/ 32) * sizeof(uint32_t));
2520 dst
->changed
.rs
[D3DRS_LAST
/ 32] |= (1 << (D3DRS_COUNT
% 32)) - 1;
2521 dst
->changed
.vtxbuf
= (1ULL << This
->caps
.MaxStreams
) - 1;
2522 dst
->changed
.stream_freq
= dst
->changed
.vtxbuf
;
2523 dst
->changed
.ucp
= (1 << PIPE_MAX_CLIP_PLANES
) - 1;
2524 dst
->changed
.texture
= (1 << NINE_MAX_SAMPLERS
) - 1;
2526 NineStateBlock9_Capture(NineStateBlock9(*ppSB
));
2528 /* TODO: fixed function state */
2534 NineDevice9_BeginStateBlock( struct NineDevice9
*This
)
2538 DBG("This=%p\n", This
);
2540 user_assert(!This
->record
, D3DERR_INVALIDCALL
);
2542 hr
= NineStateBlock9_new(This
, &This
->record
, NINESBT_CUSTOM
);
2545 NineUnknown_ConvertRefToBind(NineUnknown(This
->record
));
2547 This
->update
= &This
->record
->state
;
2548 This
->is_recording
= TRUE
;
2554 NineDevice9_EndStateBlock( struct NineDevice9
*This
,
2555 IDirect3DStateBlock9
**ppSB
)
2557 DBG("This=%p ppSB=%p\n", This
, ppSB
);
2559 user_assert(This
->record
, D3DERR_INVALIDCALL
);
2561 This
->update
= &This
->state
;
2562 This
->is_recording
= FALSE
;
2564 NineUnknown_AddRef(NineUnknown(This
->record
));
2565 *ppSB
= (IDirect3DStateBlock9
*)This
->record
;
2566 NineUnknown_Unbind(NineUnknown(This
->record
));
2567 This
->record
= NULL
;
2573 NineDevice9_SetClipStatus( struct NineDevice9
*This
,
2574 const D3DCLIPSTATUS9
*pClipStatus
)
2576 STUB(D3DERR_INVALIDCALL
);
2580 NineDevice9_GetClipStatus( struct NineDevice9
*This
,
2581 D3DCLIPSTATUS9
*pClipStatus
)
2583 STUB(D3DERR_INVALIDCALL
);
2587 NineDevice9_GetTexture( struct NineDevice9
*This
,
2589 IDirect3DBaseTexture9
**ppTexture
)
2591 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2592 Stage
== D3DDMAPSAMPLER
||
2593 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2594 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2595 user_assert(ppTexture
, D3DERR_INVALIDCALL
);
2597 if (Stage
>= D3DDMAPSAMPLER
)
2598 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2600 *ppTexture
= (IDirect3DBaseTexture9
*)This
->state
.texture
[Stage
];
2602 if (This
->state
.texture
[Stage
])
2603 NineUnknown_AddRef(NineUnknown(This
->state
.texture
[Stage
]));
2608 NineDevice9_SetTexture( struct NineDevice9
*This
,
2610 IDirect3DBaseTexture9
*pTexture
)
2612 struct nine_state
*state
= This
->update
;
2613 struct NineBaseTexture9
*tex
= NineBaseTexture9(pTexture
);
2615 DBG("This=%p Stage=%u pTexture=%p\n", This
, Stage
, pTexture
);
2617 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2618 Stage
== D3DDMAPSAMPLER
||
2619 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2620 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2621 user_assert(!tex
|| (tex
->base
.pool
!= D3DPOOL_SCRATCH
&&
2622 tex
->base
.pool
!= D3DPOOL_SYSTEMMEM
), D3DERR_INVALIDCALL
);
2624 if (Stage
>= D3DDMAPSAMPLER
)
2625 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2627 if (!This
->is_recording
) {
2628 struct NineBaseTexture9
*old
= state
->texture
[Stage
];
2632 state
->samplers_shadow
&= ~(1 << Stage
);
2634 state
->samplers_shadow
|= tex
->shadow
<< Stage
;
2636 if ((tex
->managed
.dirty
| tex
->dirty_mip
) && LIST_IS_EMPTY(&tex
->list
))
2637 list_add(&tex
->list
, &This
->update_textures
);
2644 nine_bind(&state
->texture
[Stage
], pTexture
);
2646 state
->changed
.texture
|= 1 << Stage
;
2647 state
->changed
.group
|= NINE_STATE_TEXTURE
;
2653 NineDevice9_GetTextureStageState( struct NineDevice9
*This
,
2655 D3DTEXTURESTAGESTATETYPE Type
,
2658 const struct nine_state
*state
= &This
->state
;
2660 user_assert(Stage
< Elements(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2661 user_assert(Type
< Elements(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2663 *pValue
= state
->ff
.tex_stage
[Stage
][Type
];
2669 NineDevice9_SetTextureStageState( struct NineDevice9
*This
,
2671 D3DTEXTURESTAGESTATETYPE Type
,
2674 struct nine_state
*state
= This
->update
;
2675 int bumpmap_index
= -1;
2677 DBG("Stage=%u Type=%u Value=%08x\n", Stage
, Type
, Value
);
2678 nine_dump_D3DTSS_value(DBG_FF
, Type
, Value
);
2680 user_assert(Stage
< Elements(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2681 user_assert(Type
< Elements(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2683 state
->ff
.tex_stage
[Stage
][Type
] = Value
;
2685 case D3DTSS_BUMPENVMAT00
:
2686 bumpmap_index
= 4 * Stage
;
2688 case D3DTSS_BUMPENVMAT10
:
2689 bumpmap_index
= 4 * Stage
+ 1;
2691 case D3DTSS_BUMPENVMAT01
:
2692 bumpmap_index
= 4 * Stage
+ 2;
2694 case D3DTSS_BUMPENVMAT11
:
2695 bumpmap_index
= 4 * Stage
+ 3;
2697 case D3DTSS_BUMPENVLSCALE
:
2698 bumpmap_index
= 4 * 8 + 2 * Stage
;
2700 case D3DTSS_BUMPENVLOFFSET
:
2701 bumpmap_index
= 4 * 8 + 2 * Stage
+ 1;
2703 case D3DTSS_TEXTURETRANSFORMFLAGS
:
2704 state
->changed
.group
|= NINE_STATE_PS1X_SHADER
;
2710 if (bumpmap_index
>= 0) {
2711 state
->bumpmap_vars
[bumpmap_index
] = Value
;
2712 state
->changed
.group
|= NINE_STATE_PS_CONST
;
2715 state
->changed
.group
|= NINE_STATE_FF_PSSTAGES
;
2716 state
->ff
.changed
.tex_stage
[Stage
][Type
/ 32] |= 1 << (Type
% 32);
2722 NineDevice9_GetSamplerState( struct NineDevice9
*This
,
2724 D3DSAMPLERSTATETYPE Type
,
2727 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2728 Sampler
== D3DDMAPSAMPLER
||
2729 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2730 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2732 if (Sampler
>= D3DDMAPSAMPLER
)
2733 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2735 *pValue
= This
->state
.samp
[Sampler
][Type
];
2740 NineDevice9_SetSamplerState( struct NineDevice9
*This
,
2742 D3DSAMPLERSTATETYPE Type
,
2745 struct nine_state
*state
= This
->update
;
2747 DBG("This=%p Sampler=%u Type=%s Value=%08x\n", This
,
2748 Sampler
, nine_D3DSAMP_to_str(Type
), Value
);
2750 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2751 Sampler
== D3DDMAPSAMPLER
||
2752 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2753 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2755 if (Sampler
>= D3DDMAPSAMPLER
)
2756 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2758 if (state
->samp
[Sampler
][Type
] != Value
|| unlikely(This
->is_recording
)) {
2759 state
->samp
[Sampler
][Type
] = Value
;
2760 state
->changed
.group
|= NINE_STATE_SAMPLER
;
2761 state
->changed
.sampler
[Sampler
] |= 1 << Type
;
2768 NineDevice9_ValidateDevice( struct NineDevice9
*This
,
2771 const struct nine_state
*state
= &This
->state
;
2773 unsigned w
= 0, h
= 0;
2775 DBG("This=%p pNumPasses=%p\n", This
, pNumPasses
);
2777 for (i
= 0; i
< Elements(state
->samp
); ++i
) {
2778 if (state
->samp
[i
][D3DSAMP_MINFILTER
] == D3DTEXF_NONE
||
2779 state
->samp
[i
][D3DSAMP_MAGFILTER
] == D3DTEXF_NONE
)
2780 return D3DERR_UNSUPPORTEDTEXTUREFILTER
;
2783 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2787 w
= state
->rt
[i
]->desc
.Width
;
2788 h
= state
->rt
[i
]->desc
.Height
;
2790 if (state
->rt
[i
]->desc
.Width
!= w
|| state
->rt
[i
]->desc
.Height
!= h
) {
2791 return D3DERR_CONFLICTINGRENDERSTATE
;
2795 (state
->rs
[D3DRS_ZENABLE
] || state
->rs
[D3DRS_STENCILENABLE
])) {
2797 (state
->ds
->desc
.Width
!= w
|| state
->ds
->desc
.Height
!= h
))
2798 return D3DERR_CONFLICTINGRENDERSTATE
;
2808 NineDevice9_SetPaletteEntries( struct NineDevice9
*This
,
2810 const PALETTEENTRY
*pEntries
)
2812 STUB(D3D_OK
); /* like wine */
2816 NineDevice9_GetPaletteEntries( struct NineDevice9
*This
,
2818 PALETTEENTRY
*pEntries
)
2820 STUB(D3DERR_INVALIDCALL
);
2824 NineDevice9_SetCurrentTexturePalette( struct NineDevice9
*This
,
2825 UINT PaletteNumber
)
2827 STUB(D3D_OK
); /* like wine */
2831 NineDevice9_GetCurrentTexturePalette( struct NineDevice9
*This
,
2832 UINT
*PaletteNumber
)
2834 STUB(D3DERR_INVALIDCALL
);
2838 NineDevice9_SetScissorRect( struct NineDevice9
*This
,
2841 struct nine_state
*state
= This
->update
;
2843 DBG("x=(%u..%u) y=(%u..%u)\n",
2844 pRect
->left
, pRect
->top
, pRect
->right
, pRect
->bottom
);
2846 state
->scissor
.minx
= pRect
->left
;
2847 state
->scissor
.miny
= pRect
->top
;
2848 state
->scissor
.maxx
= pRect
->right
;
2849 state
->scissor
.maxy
= pRect
->bottom
;
2851 state
->changed
.group
|= NINE_STATE_SCISSOR
;
2857 NineDevice9_GetScissorRect( struct NineDevice9
*This
,
2860 pRect
->left
= This
->state
.scissor
.minx
;
2861 pRect
->top
= This
->state
.scissor
.miny
;
2862 pRect
->right
= This
->state
.scissor
.maxx
;
2863 pRect
->bottom
= This
->state
.scissor
.maxy
;
2869 NineDevice9_SetSoftwareVertexProcessing( struct NineDevice9
*This
,
2872 STUB(D3DERR_INVALIDCALL
);
2876 NineDevice9_GetSoftwareVertexProcessing( struct NineDevice9
*This
)
2878 return !!(This
->params
.BehaviorFlags
& D3DCREATE_SOFTWARE_VERTEXPROCESSING
);
2882 NineDevice9_SetNPatchMode( struct NineDevice9
*This
,
2885 STUB(D3DERR_INVALIDCALL
);
2889 NineDevice9_GetNPatchMode( struct NineDevice9
*This
)
2895 init_draw_info(struct pipe_draw_info
*info
,
2896 struct NineDevice9
*dev
, D3DPRIMITIVETYPE type
, UINT count
)
2898 info
->mode
= d3dprimitivetype_to_pipe_prim(type
);
2899 info
->count
= prim_count_to_vertex_count(type
, count
);
2900 info
->start_instance
= 0;
2901 info
->instance_count
= 1;
2902 if (dev
->state
.stream_instancedata_mask
& dev
->state
.stream_usage_mask
)
2903 info
->instance_count
= MAX2(dev
->state
.stream_freq
[0] & 0x7FFFFF, 1);
2904 info
->primitive_restart
= FALSE
;
2905 info
->restart_index
= 0;
2906 info
->count_from_stream_output
= NULL
;
2907 info
->indirect
= NULL
;
2911 NineDevice9_DrawPrimitive( struct NineDevice9
*This
,
2912 D3DPRIMITIVETYPE PrimitiveType
,
2914 UINT PrimitiveCount
)
2916 struct pipe_draw_info info
;
2918 DBG("iface %p, PrimitiveType %u, StartVertex %u, PrimitiveCount %u\n",
2919 This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2921 nine_update_state(This
);
2923 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2924 info
.indexed
= FALSE
;
2925 info
.start
= StartVertex
;
2926 info
.index_bias
= 0;
2927 info
.min_index
= info
.start
;
2928 info
.max_index
= info
.count
- 1;
2930 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2936 NineDevice9_DrawIndexedPrimitive( struct NineDevice9
*This
,
2937 D3DPRIMITIVETYPE PrimitiveType
,
2938 INT BaseVertexIndex
,
2939 UINT MinVertexIndex
,
2942 UINT PrimitiveCount
)
2944 struct pipe_draw_info info
;
2946 DBG("iface %p, PrimitiveType %u, BaseVertexIndex %u, MinVertexIndex %u "
2947 "NumVertices %u, StartIndex %u, PrimitiveCount %u\n",
2948 This
, PrimitiveType
, BaseVertexIndex
, MinVertexIndex
, NumVertices
,
2949 StartIndex
, PrimitiveCount
);
2951 user_assert(This
->state
.idxbuf
, D3DERR_INVALIDCALL
);
2952 user_assert(This
->state
.vdecl
, D3DERR_INVALIDCALL
);
2954 nine_update_state(This
);
2956 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2957 info
.indexed
= TRUE
;
2958 info
.start
= StartIndex
;
2959 info
.index_bias
= BaseVertexIndex
;
2960 /* These don't include index bias: */
2961 info
.min_index
= MinVertexIndex
;
2962 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
2964 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2970 NineDevice9_DrawPrimitiveUP( struct NineDevice9
*This
,
2971 D3DPRIMITIVETYPE PrimitiveType
,
2972 UINT PrimitiveCount
,
2973 const void *pVertexStreamZeroData
,
2974 UINT VertexStreamZeroStride
)
2976 struct pipe_vertex_buffer vtxbuf
;
2977 struct pipe_draw_info info
;
2979 DBG("iface %p, PrimitiveType %u, PrimitiveCount %u, data %p, stride %u\n",
2980 This
, PrimitiveType
, PrimitiveCount
,
2981 pVertexStreamZeroData
, VertexStreamZeroStride
);
2983 user_assert(pVertexStreamZeroData
&& VertexStreamZeroStride
,
2984 D3DERR_INVALIDCALL
);
2986 nine_update_state(This
);
2988 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2989 info
.indexed
= FALSE
;
2991 info
.index_bias
= 0;
2993 info
.max_index
= info
.count
- 1;
2995 vtxbuf
.stride
= VertexStreamZeroStride
;
2996 vtxbuf
.buffer_offset
= 0;
2997 vtxbuf
.buffer
= NULL
;
2998 vtxbuf
.user_buffer
= pVertexStreamZeroData
;
3000 if (!This
->driver_caps
.user_vbufs
) {
3001 u_upload_data(This
->vertex_uploader
,
3003 (info
.max_index
+ 1) * VertexStreamZeroStride
, /* XXX */
3006 &vtxbuf
.buffer_offset
,
3008 u_upload_unmap(This
->vertex_uploader
);
3009 vtxbuf
.user_buffer
= NULL
;
3012 This
->pipe
->set_vertex_buffers(This
->pipe
, 0, 1, &vtxbuf
);
3014 This
->pipe
->draw_vbo(This
->pipe
, &info
);
3016 NineDevice9_PauseRecording(This
);
3017 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
3018 NineDevice9_ResumeRecording(This
);
3020 pipe_resource_reference(&vtxbuf
.buffer
, NULL
);
3026 NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9
*This
,
3027 D3DPRIMITIVETYPE PrimitiveType
,
3028 UINT MinVertexIndex
,
3030 UINT PrimitiveCount
,
3031 const void *pIndexData
,
3032 D3DFORMAT IndexDataFormat
,
3033 const void *pVertexStreamZeroData
,
3034 UINT VertexStreamZeroStride
)
3036 struct pipe_draw_info info
;
3037 struct pipe_vertex_buffer vbuf
;
3038 struct pipe_index_buffer ibuf
;
3040 DBG("iface %p, PrimitiveType %u, MinVertexIndex %u, NumVertices %u "
3041 "PrimitiveCount %u, pIndexData %p, IndexDataFormat %u "
3042 "pVertexStreamZeroData %p, VertexStreamZeroStride %u\n",
3043 This
, PrimitiveType
, MinVertexIndex
, NumVertices
, PrimitiveCount
,
3044 pIndexData
, IndexDataFormat
,
3045 pVertexStreamZeroData
, VertexStreamZeroStride
);
3047 user_assert(pIndexData
&& pVertexStreamZeroData
, D3DERR_INVALIDCALL
);
3048 user_assert(VertexStreamZeroStride
, D3DERR_INVALIDCALL
);
3049 user_assert(IndexDataFormat
== D3DFMT_INDEX16
||
3050 IndexDataFormat
== D3DFMT_INDEX32
, D3DERR_INVALIDCALL
);
3052 nine_update_state(This
);
3054 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
3055 info
.indexed
= TRUE
;
3057 info
.index_bias
= 0;
3058 info
.min_index
= MinVertexIndex
;
3059 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
3061 vbuf
.stride
= VertexStreamZeroStride
;
3062 vbuf
.buffer_offset
= 0;
3064 vbuf
.user_buffer
= pVertexStreamZeroData
;
3066 ibuf
.index_size
= (IndexDataFormat
== D3DFMT_INDEX16
) ? 2 : 4;
3069 ibuf
.user_buffer
= pIndexData
;
3071 if (!This
->driver_caps
.user_vbufs
) {
3072 const unsigned base
= info
.min_index
* VertexStreamZeroStride
;
3073 u_upload_data(This
->vertex_uploader
,
3076 info
.min_index
+ 1) * VertexStreamZeroStride
, /* XXX */
3078 (const uint8_t *)vbuf
.user_buffer
+ base
,
3079 &vbuf
.buffer_offset
,
3081 u_upload_unmap(This
->vertex_uploader
);
3082 /* Won't be used: */
3083 vbuf
.buffer_offset
-= base
;
3084 vbuf
.user_buffer
= NULL
;
3086 if (!This
->driver_caps
.user_ibufs
) {
3087 u_upload_data(This
->index_uploader
,
3089 info
.count
* ibuf
.index_size
,
3094 u_upload_unmap(This
->index_uploader
);
3095 ibuf
.user_buffer
= NULL
;
3098 This
->pipe
->set_vertex_buffers(This
->pipe
, 0, 1, &vbuf
);
3099 This
->pipe
->set_index_buffer(This
->pipe
, &ibuf
);
3101 This
->pipe
->draw_vbo(This
->pipe
, &info
);
3103 pipe_resource_reference(&vbuf
.buffer
, NULL
);
3104 pipe_resource_reference(&ibuf
.buffer
, NULL
);
3106 NineDevice9_PauseRecording(This
);
3107 NineDevice9_SetIndices(This
, NULL
);
3108 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
3109 NineDevice9_ResumeRecording(This
);
3114 /* TODO: Write to pDestBuffer directly if vertex declaration contains
3118 NineDevice9_ProcessVertices( struct NineDevice9
*This
,
3122 IDirect3DVertexBuffer9
*pDestBuffer
,
3123 IDirect3DVertexDeclaration9
*pVertexDecl
,
3126 struct pipe_screen
*screen
= This
->screen
;
3127 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pVertexDecl
);
3128 struct NineVertexShader9
*vs
;
3129 struct pipe_resource
*resource
;
3130 struct pipe_stream_output_target
*target
;
3131 struct pipe_draw_info draw
;
3133 unsigned buffer_offset
, buffer_size
;
3135 DBG("This=%p SrcStartIndex=%u DestIndex=%u VertexCount=%u "
3136 "pDestBuffer=%p pVertexDecl=%p Flags=%d\n",
3137 This
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
,
3138 pVertexDecl
, Flags
);
3140 if (!screen
->get_param(screen
, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
))
3141 STUB(D3DERR_INVALIDCALL
);
3143 nine_update_state(This
);
3145 /* TODO: Create shader with stream output. */
3146 STUB(D3DERR_INVALIDCALL
);
3147 struct NineVertexBuffer9
*dst
= NineVertexBuffer9(pDestBuffer
);
3149 vs
= This
->state
.vs
? This
->state
.vs
: This
->ff
.vs
;
3151 buffer_size
= VertexCount
* vs
->so
->stride
[0];
3153 struct pipe_resource templ
;
3155 templ
.target
= PIPE_BUFFER
;
3156 templ
.format
= PIPE_FORMAT_R8_UNORM
;
3157 templ
.width0
= buffer_size
;
3159 templ
.bind
= PIPE_BIND_STREAM_OUTPUT
;
3160 templ
.usage
= PIPE_USAGE_STREAM
;
3161 templ
.height0
= templ
.depth0
= templ
.array_size
= 1;
3162 templ
.last_level
= templ
.nr_samples
= 0;
3164 resource
= This
->screen
->resource_create(This
->screen
, &templ
);
3166 return E_OUTOFMEMORY
;
3169 /* SO matches vertex declaration */
3170 resource
= NineVertexBuffer9_GetResource(dst
);
3171 buffer_offset
= DestIndex
* vs
->so
->stride
[0];
3173 target
= This
->pipe
->create_stream_output_target(This
->pipe
, resource
,
3177 pipe_resource_reference(&resource
, NULL
);
3178 return D3DERR_DRIVERINTERNALERROR
;
3182 hr
= NineVertexDeclaration9_new_from_fvf(This
, dst
->desc
.FVF
, &vdecl
);
3187 init_draw_info(&draw
, This
, D3DPT_POINTLIST
, VertexCount
);
3188 draw
.instance_count
= 1;
3189 draw
.indexed
= FALSE
;
3190 draw
.start
= SrcStartIndex
;
3191 draw
.index_bias
= 0;
3192 draw
.min_index
= SrcStartIndex
;
3193 draw
.max_index
= SrcStartIndex
+ VertexCount
- 1;
3195 This
->pipe
->set_stream_output_targets(This
->pipe
, 1, &target
, 0);
3196 This
->pipe
->draw_vbo(This
->pipe
, &draw
);
3197 This
->pipe
->set_stream_output_targets(This
->pipe
, 0, NULL
, 0);
3198 This
->pipe
->stream_output_target_destroy(This
->pipe
, target
);
3200 hr
= NineVertexDeclaration9_ConvertStreamOutput(vdecl
,
3201 dst
, DestIndex
, VertexCount
,
3204 pipe_resource_reference(&resource
, NULL
);
3206 NineUnknown_Release(NineUnknown(vdecl
));
3211 NineDevice9_CreateVertexDeclaration( struct NineDevice9
*This
,
3212 const D3DVERTEXELEMENT9
*pVertexElements
,
3213 IDirect3DVertexDeclaration9
**ppDecl
)
3215 struct NineVertexDeclaration9
*vdecl
;
3217 DBG("This=%p pVertexElements=%p ppDecl=%p\n",
3218 This
, pVertexElements
, ppDecl
);
3220 HRESULT hr
= NineVertexDeclaration9_new(This
, pVertexElements
, &vdecl
);
3222 *ppDecl
= (IDirect3DVertexDeclaration9
*)vdecl
;
3228 NineDevice9_SetVertexDeclaration( struct NineDevice9
*This
,
3229 IDirect3DVertexDeclaration9
*pDecl
)
3231 struct nine_state
*state
= This
->update
;
3232 BOOL was_programmable_vs
= This
->state
.programmable_vs
;
3234 DBG("This=%p pDecl=%p\n", This
, pDecl
);
3236 if (likely(!This
->is_recording
) && state
->vdecl
== NineVertexDeclaration9(pDecl
))
3239 nine_bind(&state
->vdecl
, pDecl
);
3241 This
->state
.programmable_vs
= This
->state
.vs
&& !(This
->state
.vdecl
&& This
->state
.vdecl
->position_t
);
3242 if (likely(!This
->is_recording
) && was_programmable_vs
!= This
->state
.programmable_vs
) {
3243 state
->commit
|= NINE_STATE_COMMIT_CONST_VS
;
3244 state
->changed
.group
|= NINE_STATE_VS
;
3247 state
->changed
.group
|= NINE_STATE_VDECL
;
3253 NineDevice9_GetVertexDeclaration( struct NineDevice9
*This
,
3254 IDirect3DVertexDeclaration9
**ppDecl
)
3256 user_assert(ppDecl
, D3DERR_INVALIDCALL
);
3258 *ppDecl
= (IDirect3DVertexDeclaration9
*)This
->state
.vdecl
;
3260 NineUnknown_AddRef(NineUnknown(*ppDecl
));
3265 NineDevice9_SetFVF( struct NineDevice9
*This
,
3268 struct NineVertexDeclaration9
*vdecl
;
3271 DBG("FVF = %08x\n", FVF
);
3273 return D3D_OK
; /* like wine */
3275 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
3277 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
3281 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
3282 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
3284 return NineDevice9_SetVertexDeclaration(
3285 This
, (IDirect3DVertexDeclaration9
*)vdecl
);
3289 NineDevice9_GetFVF( struct NineDevice9
*This
,
3292 *pFVF
= This
->state
.vdecl
? This
->state
.vdecl
->fvf
: 0;
3297 NineDevice9_CreateVertexShader( struct NineDevice9
*This
,
3298 const DWORD
*pFunction
,
3299 IDirect3DVertexShader9
**ppShader
)
3301 struct NineVertexShader9
*vs
;
3304 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3306 hr
= NineVertexShader9_new(This
, &vs
, pFunction
, NULL
);
3309 *ppShader
= (IDirect3DVertexShader9
*)vs
;
3314 NineDevice9_SetVertexShader( struct NineDevice9
*This
,
3315 IDirect3DVertexShader9
*pShader
)
3317 struct nine_state
*state
= This
->update
;
3318 BOOL was_programmable_vs
= This
->state
.programmable_vs
;
3320 DBG("This=%p pShader=%p\n", This
, pShader
);
3322 if (!This
->is_recording
&& state
->vs
== (struct NineVertexShader9
*)pShader
)
3325 nine_bind(&state
->vs
, pShader
);
3327 This
->state
.programmable_vs
= This
->state
.vs
&& !(This
->state
.vdecl
&& This
->state
.vdecl
->position_t
);
3329 /* ff -> non-ff: commit back non-ff constants */
3330 if (!was_programmable_vs
&& This
->state
.programmable_vs
)
3331 state
->commit
|= NINE_STATE_COMMIT_CONST_VS
;
3333 state
->changed
.group
|= NINE_STATE_VS
;
3339 NineDevice9_GetVertexShader( struct NineDevice9
*This
,
3340 IDirect3DVertexShader9
**ppShader
)
3342 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3343 nine_reference_set(ppShader
, This
->state
.vs
);
3348 NineDevice9_SetVertexShaderConstantF( struct NineDevice9
*This
,
3350 const float *pConstantData
,
3351 UINT Vector4fCount
)
3353 struct nine_state
*state
= This
->update
;
3355 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3356 This
, StartRegister
, pConstantData
, Vector4fCount
);
3358 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3359 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3363 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3365 if (!This
->is_recording
) {
3366 if (!memcmp(&state
->vs_const_f
[StartRegister
* 4], pConstantData
,
3367 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0])))
3371 memcpy(&state
->vs_const_f
[StartRegister
* 4],
3373 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3375 nine_ranges_insert(&state
->changed
.vs_const_f
,
3376 StartRegister
, StartRegister
+ Vector4fCount
,
3379 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3385 NineDevice9_GetVertexShaderConstantF( struct NineDevice9
*This
,
3387 float *pConstantData
,
3388 UINT Vector4fCount
)
3390 const struct nine_state
*state
= &This
->state
;
3392 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3393 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3394 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3396 memcpy(pConstantData
,
3397 &state
->vs_const_f
[StartRegister
* 4],
3398 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3404 NineDevice9_SetVertexShaderConstantI( struct NineDevice9
*This
,
3406 const int *pConstantData
,
3407 UINT Vector4iCount
)
3409 struct nine_state
*state
= This
->update
;
3412 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3413 This
, StartRegister
, pConstantData
, Vector4iCount
);
3415 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3416 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3417 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3419 if (This
->driver_caps
.vs_integer
) {
3420 if (!This
->is_recording
) {
3421 if (!memcmp(&state
->vs_const_i
[StartRegister
][0], pConstantData
,
3422 Vector4iCount
* sizeof(state
->vs_const_i
[0])))
3425 memcpy(&state
->vs_const_i
[StartRegister
][0],
3427 Vector4iCount
* sizeof(state
->vs_const_i
[0]));
3429 for (i
= 0; i
< Vector4iCount
; i
++) {
3430 state
->vs_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3431 state
->vs_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3432 state
->vs_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3433 state
->vs_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3437 state
->changed
.vs_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3438 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3444 NineDevice9_GetVertexShaderConstantI( struct NineDevice9
*This
,
3447 UINT Vector4iCount
)
3449 const struct nine_state
*state
= &This
->state
;
3452 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3453 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3454 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3456 if (This
->driver_caps
.vs_integer
) {
3457 memcpy(pConstantData
,
3458 &state
->vs_const_i
[StartRegister
][0],
3459 Vector4iCount
* sizeof(state
->vs_const_i
[0]));
3461 for (i
= 0; i
< Vector4iCount
; i
++) {
3462 pConstantData
[4*i
] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][0]);
3463 pConstantData
[4*i
+1] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][1]);
3464 pConstantData
[4*i
+2] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][2]);
3465 pConstantData
[4*i
+3] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][3]);
3473 NineDevice9_SetVertexShaderConstantB( struct NineDevice9
*This
,
3475 const BOOL
*pConstantData
,
3478 struct nine_state
*state
= This
->update
;
3480 uint32_t bool_true
= This
->driver_caps
.vs_integer
? 0xFFFFFFFF : fui(1.0f
);
3482 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3483 This
, StartRegister
, pConstantData
, BoolCount
);
3485 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3486 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3487 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3489 if (!This
->is_recording
) {
3490 bool noChange
= true;
3491 for (i
= 0; i
< BoolCount
; i
++) {
3492 if (!!state
->vs_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3499 for (i
= 0; i
< BoolCount
; i
++)
3500 state
->vs_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3502 state
->changed
.vs_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3503 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3509 NineDevice9_GetVertexShaderConstantB( struct NineDevice9
*This
,
3511 BOOL
*pConstantData
,
3514 const struct nine_state
*state
= &This
->state
;
3517 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3518 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3519 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3521 for (i
= 0; i
< BoolCount
; i
++)
3522 pConstantData
[i
] = state
->vs_const_b
[StartRegister
+ i
] != 0 ? TRUE
: FALSE
;
3528 NineDevice9_SetStreamSource( struct NineDevice9
*This
,
3530 IDirect3DVertexBuffer9
*pStreamData
,
3534 struct nine_state
*state
= This
->update
;
3535 struct NineVertexBuffer9
*pVBuf9
= NineVertexBuffer9(pStreamData
);
3536 const unsigned i
= StreamNumber
;
3538 DBG("This=%p StreamNumber=%u pStreamData=%p OffsetInBytes=%u Stride=%u\n",
3539 This
, StreamNumber
, pStreamData
, OffsetInBytes
, Stride
);
3541 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3542 user_assert(Stride
<= This
->caps
.MaxStreamStride
, D3DERR_INVALIDCALL
);
3544 if (likely(!This
->is_recording
)) {
3545 if (state
->stream
[i
] == NineVertexBuffer9(pStreamData
) &&
3546 state
->vtxbuf
[i
].stride
== Stride
&&
3547 state
->vtxbuf
[i
].buffer_offset
== OffsetInBytes
)
3550 nine_bind(&state
->stream
[i
], pStreamData
);
3552 state
->changed
.vtxbuf
|= 1 << StreamNumber
;
3555 state
->vtxbuf
[i
].stride
= Stride
;
3556 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3558 pipe_resource_reference(&state
->vtxbuf
[i
].buffer
,
3559 pStreamData
? NineVertexBuffer9_GetResource(pVBuf9
) : NULL
);
3565 NineDevice9_GetStreamSource( struct NineDevice9
*This
,
3567 IDirect3DVertexBuffer9
**ppStreamData
,
3568 UINT
*pOffsetInBytes
,
3571 const struct nine_state
*state
= &This
->state
;
3572 const unsigned i
= StreamNumber
;
3574 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3575 user_assert(ppStreamData
, D3DERR_INVALIDCALL
);
3577 nine_reference_set(ppStreamData
, state
->stream
[i
]);
3578 *pStride
= state
->vtxbuf
[i
].stride
;
3579 *pOffsetInBytes
= state
->vtxbuf
[i
].buffer_offset
;
3585 NineDevice9_SetStreamSourceFreq( struct NineDevice9
*This
,
3589 struct nine_state
*state
= This
->update
;
3590 /* const UINT freq = Setting & 0x7FFFFF; */
3592 DBG("This=%p StreamNumber=%u FrequencyParameter=0x%x\n", This
,
3593 StreamNumber
, Setting
);
3595 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3596 user_assert(StreamNumber
!= 0 || !(Setting
& D3DSTREAMSOURCE_INSTANCEDATA
),
3597 D3DERR_INVALIDCALL
);
3598 user_assert(!((Setting
& D3DSTREAMSOURCE_INSTANCEDATA
) &&
3599 (Setting
& D3DSTREAMSOURCE_INDEXEDDATA
)), D3DERR_INVALIDCALL
);
3600 user_assert(Setting
, D3DERR_INVALIDCALL
);
3602 if (likely(!This
->is_recording
) && state
->stream_freq
[StreamNumber
] == Setting
)
3605 state
->stream_freq
[StreamNumber
] = Setting
;
3607 if (Setting
& D3DSTREAMSOURCE_INSTANCEDATA
)
3608 state
->stream_instancedata_mask
|= 1 << StreamNumber
;
3610 state
->stream_instancedata_mask
&= ~(1 << StreamNumber
);
3612 state
->changed
.stream_freq
|= 1 << StreamNumber
; /* Used for stateblocks */
3613 if (StreamNumber
!= 0)
3614 state
->changed
.group
|= NINE_STATE_STREAMFREQ
;
3619 NineDevice9_GetStreamSourceFreq( struct NineDevice9
*This
,
3623 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3624 *pSetting
= This
->state
.stream_freq
[StreamNumber
];
3629 NineDevice9_SetIndices( struct NineDevice9
*This
,
3630 IDirect3DIndexBuffer9
*pIndexData
)
3632 struct nine_state
*state
= This
->update
;
3634 DBG("This=%p pIndexData=%p\n", This
, pIndexData
);
3636 if (likely(!This
->is_recording
))
3637 if (state
->idxbuf
== NineIndexBuffer9(pIndexData
))
3639 nine_bind(&state
->idxbuf
, pIndexData
);
3641 state
->changed
.group
|= NINE_STATE_IDXBUF
;
3646 /* XXX: wine/d3d9 doesn't have pBaseVertexIndex, and it doesn't make sense
3647 * here because it's an argument passed to the Draw calls.
3650 NineDevice9_GetIndices( struct NineDevice9
*This
,
3651 IDirect3DIndexBuffer9
**ppIndexData
/*,
3652 UINT *pBaseVertexIndex */ )
3654 user_assert(ppIndexData
, D3DERR_INVALIDCALL
);
3655 nine_reference_set(ppIndexData
, This
->state
.idxbuf
);
3660 NineDevice9_CreatePixelShader( struct NineDevice9
*This
,
3661 const DWORD
*pFunction
,
3662 IDirect3DPixelShader9
**ppShader
)
3664 struct NinePixelShader9
*ps
;
3667 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3669 hr
= NinePixelShader9_new(This
, &ps
, pFunction
, NULL
);
3672 *ppShader
= (IDirect3DPixelShader9
*)ps
;
3677 NineDevice9_SetPixelShader( struct NineDevice9
*This
,
3678 IDirect3DPixelShader9
*pShader
)
3680 struct nine_state
*state
= This
->update
;
3681 unsigned old_mask
= state
->ps
? state
->ps
->rt_mask
: 1;
3684 DBG("This=%p pShader=%p\n", This
, pShader
);
3686 if (!This
->is_recording
&& state
->ps
== (struct NinePixelShader9
*)pShader
)
3689 /* ff -> non-ff: commit back non-ff constants */
3690 if (!state
->ps
&& pShader
)
3691 state
->commit
|= NINE_STATE_COMMIT_CONST_PS
;
3693 nine_bind(&state
->ps
, pShader
);
3695 state
->changed
.group
|= NINE_STATE_PS
;
3697 mask
= state
->ps
? state
->ps
->rt_mask
: 1;
3698 /* We need to update cbufs if the pixel shader would
3699 * write to different render targets */
3700 if (mask
!= old_mask
)
3701 state
->changed
.group
|= NINE_STATE_FB
;
3707 NineDevice9_GetPixelShader( struct NineDevice9
*This
,
3708 IDirect3DPixelShader9
**ppShader
)
3710 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3711 nine_reference_set(ppShader
, This
->state
.ps
);
3716 NineDevice9_SetPixelShaderConstantF( struct NineDevice9
*This
,
3718 const float *pConstantData
,
3719 UINT Vector4fCount
)
3721 struct nine_state
*state
= This
->update
;
3723 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3724 This
, StartRegister
, pConstantData
, Vector4fCount
);
3726 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3727 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3731 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3733 if (!This
->is_recording
) {
3734 if (!memcmp(&state
->ps_const_f
[StartRegister
* 4], pConstantData
,
3735 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0])))
3739 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3741 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3743 nine_ranges_insert(&state
->changed
.ps_const_f
,
3744 StartRegister
, StartRegister
+ Vector4fCount
,
3747 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3753 NineDevice9_GetPixelShaderConstantF( struct NineDevice9
*This
,
3755 float *pConstantData
,
3756 UINT Vector4fCount
)
3758 const struct nine_state
*state
= &This
->state
;
3760 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3761 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3762 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3764 memcpy(pConstantData
,
3765 &state
->ps_const_f
[StartRegister
* 4],
3766 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3772 NineDevice9_SetPixelShaderConstantI( struct NineDevice9
*This
,
3774 const int *pConstantData
,
3775 UINT Vector4iCount
)
3777 struct nine_state
*state
= This
->update
;
3780 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3781 This
, StartRegister
, pConstantData
, Vector4iCount
);
3783 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3784 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3785 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3787 if (This
->driver_caps
.ps_integer
) {
3788 if (!This
->is_recording
) {
3789 if (!memcmp(&state
->ps_const_i
[StartRegister
][0], pConstantData
,
3790 Vector4iCount
* sizeof(state
->ps_const_i
[0])))
3793 memcpy(&state
->ps_const_i
[StartRegister
][0],
3795 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3797 for (i
= 0; i
< Vector4iCount
; i
++) {
3798 state
->ps_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3799 state
->ps_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3800 state
->ps_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3801 state
->ps_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3804 state
->changed
.ps_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3805 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3811 NineDevice9_GetPixelShaderConstantI( struct NineDevice9
*This
,
3814 UINT Vector4iCount
)
3816 const struct nine_state
*state
= &This
->state
;
3819 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3820 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3821 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3823 if (This
->driver_caps
.ps_integer
) {
3824 memcpy(pConstantData
,
3825 &state
->ps_const_i
[StartRegister
][0],
3826 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3828 for (i
= 0; i
< Vector4iCount
; i
++) {
3829 pConstantData
[4*i
] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][0]);
3830 pConstantData
[4*i
+1] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][1]);
3831 pConstantData
[4*i
+2] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][2]);
3832 pConstantData
[4*i
+3] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][3]);
3840 NineDevice9_SetPixelShaderConstantB( struct NineDevice9
*This
,
3842 const BOOL
*pConstantData
,
3845 struct nine_state
*state
= This
->update
;
3847 uint32_t bool_true
= This
->driver_caps
.ps_integer
? 0xFFFFFFFF : fui(1.0f
);
3849 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3850 This
, StartRegister
, pConstantData
, BoolCount
);
3852 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3853 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3854 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3856 if (!This
->is_recording
) {
3857 bool noChange
= true;
3858 for (i
= 0; i
< BoolCount
; i
++) {
3859 if (!!state
->ps_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3866 for (i
= 0; i
< BoolCount
; i
++)
3867 state
->ps_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3869 state
->changed
.ps_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3870 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3876 NineDevice9_GetPixelShaderConstantB( struct NineDevice9
*This
,
3878 BOOL
*pConstantData
,
3881 const struct nine_state
*state
= &This
->state
;
3884 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3885 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3886 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3888 for (i
= 0; i
< BoolCount
; i
++)
3889 pConstantData
[i
] = state
->ps_const_b
[StartRegister
+ i
] ? TRUE
: FALSE
;
3895 NineDevice9_DrawRectPatch( struct NineDevice9
*This
,
3897 const float *pNumSegs
,
3898 const D3DRECTPATCH_INFO
*pRectPatchInfo
)
3900 STUB(D3DERR_INVALIDCALL
);
3904 NineDevice9_DrawTriPatch( struct NineDevice9
*This
,
3906 const float *pNumSegs
,
3907 const D3DTRIPATCH_INFO
*pTriPatchInfo
)
3909 STUB(D3DERR_INVALIDCALL
);
3913 NineDevice9_DeletePatch( struct NineDevice9
*This
,
3916 STUB(D3DERR_INVALIDCALL
);
3920 NineDevice9_CreateQuery( struct NineDevice9
*This
,
3922 IDirect3DQuery9
**ppQuery
)
3924 struct NineQuery9
*query
;
3927 DBG("This=%p Type=%d ppQuery=%p\n", This
, Type
, ppQuery
);
3929 hr
= nine_is_query_supported(This
->screen
, Type
);
3930 if (!ppQuery
|| hr
!= D3D_OK
)
3933 hr
= NineQuery9_new(This
, &query
, Type
);
3936 *ppQuery
= (IDirect3DQuery9
*)query
;
3940 IDirect3DDevice9Vtbl NineDevice9_vtable
= {
3941 (void *)NineUnknown_QueryInterface
,
3942 (void *)NineUnknown_AddRef
,
3943 (void *)NineUnknown_Release
,
3944 (void *)NineDevice9_TestCooperativeLevel
,
3945 (void *)NineDevice9_GetAvailableTextureMem
,
3946 (void *)NineDevice9_EvictManagedResources
,
3947 (void *)NineDevice9_GetDirect3D
,
3948 (void *)NineDevice9_GetDeviceCaps
,
3949 (void *)NineDevice9_GetDisplayMode
,
3950 (void *)NineDevice9_GetCreationParameters
,
3951 (void *)NineDevice9_SetCursorProperties
,
3952 (void *)NineDevice9_SetCursorPosition
,
3953 (void *)NineDevice9_ShowCursor
,
3954 (void *)NineDevice9_CreateAdditionalSwapChain
,
3955 (void *)NineDevice9_GetSwapChain
,
3956 (void *)NineDevice9_GetNumberOfSwapChains
,
3957 (void *)NineDevice9_Reset
,
3958 (void *)NineDevice9_Present
,
3959 (void *)NineDevice9_GetBackBuffer
,
3960 (void *)NineDevice9_GetRasterStatus
,
3961 (void *)NineDevice9_SetDialogBoxMode
,
3962 (void *)NineDevice9_SetGammaRamp
,
3963 (void *)NineDevice9_GetGammaRamp
,
3964 (void *)NineDevice9_CreateTexture
,
3965 (void *)NineDevice9_CreateVolumeTexture
,
3966 (void *)NineDevice9_CreateCubeTexture
,
3967 (void *)NineDevice9_CreateVertexBuffer
,
3968 (void *)NineDevice9_CreateIndexBuffer
,
3969 (void *)NineDevice9_CreateRenderTarget
,
3970 (void *)NineDevice9_CreateDepthStencilSurface
,
3971 (void *)NineDevice9_UpdateSurface
,
3972 (void *)NineDevice9_UpdateTexture
,
3973 (void *)NineDevice9_GetRenderTargetData
,
3974 (void *)NineDevice9_GetFrontBufferData
,
3975 (void *)NineDevice9_StretchRect
,
3976 (void *)NineDevice9_ColorFill
,
3977 (void *)NineDevice9_CreateOffscreenPlainSurface
,
3978 (void *)NineDevice9_SetRenderTarget
,
3979 (void *)NineDevice9_GetRenderTarget
,
3980 (void *)NineDevice9_SetDepthStencilSurface
,
3981 (void *)NineDevice9_GetDepthStencilSurface
,
3982 (void *)NineDevice9_BeginScene
,
3983 (void *)NineDevice9_EndScene
,
3984 (void *)NineDevice9_Clear
,
3985 (void *)NineDevice9_SetTransform
,
3986 (void *)NineDevice9_GetTransform
,
3987 (void *)NineDevice9_MultiplyTransform
,
3988 (void *)NineDevice9_SetViewport
,
3989 (void *)NineDevice9_GetViewport
,
3990 (void *)NineDevice9_SetMaterial
,
3991 (void *)NineDevice9_GetMaterial
,
3992 (void *)NineDevice9_SetLight
,
3993 (void *)NineDevice9_GetLight
,
3994 (void *)NineDevice9_LightEnable
,
3995 (void *)NineDevice9_GetLightEnable
,
3996 (void *)NineDevice9_SetClipPlane
,
3997 (void *)NineDevice9_GetClipPlane
,
3998 (void *)NineDevice9_SetRenderState
,
3999 (void *)NineDevice9_GetRenderState
,
4000 (void *)NineDevice9_CreateStateBlock
,
4001 (void *)NineDevice9_BeginStateBlock
,
4002 (void *)NineDevice9_EndStateBlock
,
4003 (void *)NineDevice9_SetClipStatus
,
4004 (void *)NineDevice9_GetClipStatus
,
4005 (void *)NineDevice9_GetTexture
,
4006 (void *)NineDevice9_SetTexture
,
4007 (void *)NineDevice9_GetTextureStageState
,
4008 (void *)NineDevice9_SetTextureStageState
,
4009 (void *)NineDevice9_GetSamplerState
,
4010 (void *)NineDevice9_SetSamplerState
,
4011 (void *)NineDevice9_ValidateDevice
,
4012 (void *)NineDevice9_SetPaletteEntries
,
4013 (void *)NineDevice9_GetPaletteEntries
,
4014 (void *)NineDevice9_SetCurrentTexturePalette
,
4015 (void *)NineDevice9_GetCurrentTexturePalette
,
4016 (void *)NineDevice9_SetScissorRect
,
4017 (void *)NineDevice9_GetScissorRect
,
4018 (void *)NineDevice9_SetSoftwareVertexProcessing
,
4019 (void *)NineDevice9_GetSoftwareVertexProcessing
,
4020 (void *)NineDevice9_SetNPatchMode
,
4021 (void *)NineDevice9_GetNPatchMode
,
4022 (void *)NineDevice9_DrawPrimitive
,
4023 (void *)NineDevice9_DrawIndexedPrimitive
,
4024 (void *)NineDevice9_DrawPrimitiveUP
,
4025 (void *)NineDevice9_DrawIndexedPrimitiveUP
,
4026 (void *)NineDevice9_ProcessVertices
,
4027 (void *)NineDevice9_CreateVertexDeclaration
,
4028 (void *)NineDevice9_SetVertexDeclaration
,
4029 (void *)NineDevice9_GetVertexDeclaration
,
4030 (void *)NineDevice9_SetFVF
,
4031 (void *)NineDevice9_GetFVF
,
4032 (void *)NineDevice9_CreateVertexShader
,
4033 (void *)NineDevice9_SetVertexShader
,
4034 (void *)NineDevice9_GetVertexShader
,
4035 (void *)NineDevice9_SetVertexShaderConstantF
,
4036 (void *)NineDevice9_GetVertexShaderConstantF
,
4037 (void *)NineDevice9_SetVertexShaderConstantI
,
4038 (void *)NineDevice9_GetVertexShaderConstantI
,
4039 (void *)NineDevice9_SetVertexShaderConstantB
,
4040 (void *)NineDevice9_GetVertexShaderConstantB
,
4041 (void *)NineDevice9_SetStreamSource
,
4042 (void *)NineDevice9_GetStreamSource
,
4043 (void *)NineDevice9_SetStreamSourceFreq
,
4044 (void *)NineDevice9_GetStreamSourceFreq
,
4045 (void *)NineDevice9_SetIndices
,
4046 (void *)NineDevice9_GetIndices
,
4047 (void *)NineDevice9_CreatePixelShader
,
4048 (void *)NineDevice9_SetPixelShader
,
4049 (void *)NineDevice9_GetPixelShader
,
4050 (void *)NineDevice9_SetPixelShaderConstantF
,
4051 (void *)NineDevice9_GetPixelShaderConstantF
,
4052 (void *)NineDevice9_SetPixelShaderConstantI
,
4053 (void *)NineDevice9_GetPixelShaderConstantI
,
4054 (void *)NineDevice9_SetPixelShaderConstantB
,
4055 (void *)NineDevice9_GetPixelShaderConstantB
,
4056 (void *)NineDevice9_DrawRectPatch
,
4057 (void *)NineDevice9_DrawTriPatch
,
4058 (void *)NineDevice9_DeletePatch
,
4059 (void *)NineDevice9_CreateQuery
4062 static const GUID
*NineDevice9_IIDs
[] = {
4063 &IID_IDirect3DDevice9
,
4069 NineDevice9_new( struct pipe_screen
*pScreen
,
4070 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
4072 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
4074 ID3DPresentGroup
*pPresentationGroup
,
4075 struct d3dadapter9_context
*pCTX
,
4077 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
4078 struct NineDevice9
**ppOut
,
4079 int minorVersionNum
)
4082 lock
= !!(pCreationParameters
->BehaviorFlags
& D3DCREATE_MULTITHREADED
);
4084 NINE_NEW(Device9
, ppOut
, lock
, /* args */
4085 pScreen
, pCreationParameters
, pCaps
,
4086 pPresentationParameters
, pD3D9
, pPresentationGroup
, pCTX
,
4087 ex
, pFullscreenDisplayMode
, minorVersionNum
);