2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
24 #include "stateblock9.h"
26 #include "swapchain9.h"
27 #include "swapchain9ex.h"
28 #include "indexbuffer9.h"
29 #include "vertexbuffer9.h"
30 #include "vertexdeclaration9.h"
31 #include "vertexshader9.h"
32 #include "pixelshader9.h"
35 #include "cubetexture9.h"
36 #include "volumetexture9.h"
37 #include "nine_helpers.h"
38 #include "nine_pipe.h"
40 #include "nine_dump.h"
42 #include "pipe/p_screen.h"
43 #include "pipe/p_context.h"
44 #include "pipe/p_config.h"
45 #include "util/u_math.h"
46 #include "util/u_inlines.h"
47 #include "util/u_hash_table.h"
48 #include "util/u_format.h"
49 #include "util/u_surface.h"
50 #include "util/u_upload_mgr.h"
51 #include "hud/hud_context.h"
53 #include "cso_cache/cso_context.h"
55 #define DBG_CHANNEL DBG_DEVICE
57 #if defined(PIPE_CC_GCC) && (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64))
59 #include <fpu_control.h>
61 static void nine_setup_fpu()
66 /* clear the control word */
68 /* d3d9 doc/wine tests: mask all exceptions, use single-precision
69 * and round to nearest */
70 c
|= _FPU_MASK_IM
| _FPU_MASK_DM
| _FPU_MASK_ZM
| _FPU_MASK_OM
|
71 _FPU_MASK_UM
| _FPU_MASK_PM
| _FPU_SINGLE
| _FPU_RC_NEAREST
;
77 static void nine_setup_fpu(void)
79 WARN_ONCE("FPU setup not supported on non-x86 platforms\n");
85 NineDevice9_SetDefaultState( struct NineDevice9
*This
, boolean is_reset
)
87 struct NineSurface9
*refSurf
= NULL
;
89 DBG("This=%p is_reset=%d\n", This
, (int) is_reset
);
91 assert(!This
->is_recording
);
93 nine_state_set_defaults(This
, &This
->caps
, is_reset
);
95 This
->state
.viewport
.X
= 0;
96 This
->state
.viewport
.Y
= 0;
97 This
->state
.viewport
.Width
= 0;
98 This
->state
.viewport
.Height
= 0;
100 This
->state
.scissor
.minx
= 0;
101 This
->state
.scissor
.miny
= 0;
102 This
->state
.scissor
.maxx
= 0xffff;
103 This
->state
.scissor
.maxy
= 0xffff;
105 if (This
->nswapchains
&& This
->swapchains
[0]->params
.BackBufferCount
)
106 refSurf
= This
->swapchains
[0]->buffers
[0];
109 This
->state
.viewport
.Width
= refSurf
->desc
.Width
;
110 This
->state
.viewport
.Height
= refSurf
->desc
.Height
;
111 This
->state
.scissor
.maxx
= refSurf
->desc
.Width
;
112 This
->state
.scissor
.maxy
= refSurf
->desc
.Height
;
115 if (This
->nswapchains
&& This
->swapchains
[0]->params
.EnableAutoDepthStencil
)
116 This
->state
.rs
[D3DRS_ZENABLE
] = TRUE
;
117 if (This
->state
.rs
[D3DRS_ZENABLE
])
118 NineDevice9_SetDepthStencilSurface(
119 This
, (IDirect3DSurface9
*)This
->swapchains
[0]->zsbuf
);
122 #define GET_PCAP(n) pScreen->get_param(pScreen, PIPE_CAP_##n)
124 NineDevice9_ctor( struct NineDevice9
*This
,
125 struct NineUnknownParams
*pParams
,
126 struct pipe_screen
*pScreen
,
127 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
129 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
131 ID3DPresentGroup
*pPresentationGroup
,
132 struct d3dadapter9_context
*pCTX
,
134 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
)
137 HRESULT hr
= NineUnknown_ctor(&This
->base
, pParams
);
139 DBG("This=%p pParams=%p pScreen=%p pCreationParameters=%p pCaps=%p pPresentationParameters=%p "
140 "pD3D9=%p pPresentationGroup=%p pCTX=%p ex=%d pFullscreenDisplayMode=%p\n",
141 This
, pParams
, pScreen
, pCreationParameters
, pCaps
, pPresentationParameters
, pD3D9
,
142 pPresentationGroup
, pCTX
, (int) ex
, pFullscreenDisplayMode
);
144 if (FAILED(hr
)) { return hr
; }
146 list_inithead(&This
->update_textures
);
147 list_inithead(&This
->managed_textures
);
149 This
->screen
= pScreen
;
152 This
->params
= *pCreationParameters
;
154 This
->present
= pPresentationGroup
;
155 IDirect3D9_AddRef(This
->d3d9
);
156 ID3DPresentGroup_AddRef(This
->present
);
158 if (!(This
->params
.BehaviorFlags
& D3DCREATE_FPU_PRESERVE
))
161 if (This
->params
.BehaviorFlags
& D3DCREATE_SOFTWARE_VERTEXPROCESSING
)
162 DBG("Application asked full Software Vertex Processing. Ignoring.\n");
163 if (This
->params
.BehaviorFlags
& D3DCREATE_MIXED_VERTEXPROCESSING
)
164 DBG("Application asked mixed Software Vertex Processing. Ignoring.\n");
166 This
->pipe
= This
->screen
->context_create(This
->screen
, NULL
);
167 if (!This
->pipe
) { return E_OUTOFMEMORY
; } /* guess */
169 This
->cso
= cso_create_context(This
->pipe
);
170 if (!This
->cso
) { return E_OUTOFMEMORY
; } /* also a guess */
172 /* Create first, it messes up our state. */
173 This
->hud
= hud_create(This
->pipe
, This
->cso
); /* NULL result is fine */
175 /* create implicit swapchains */
176 This
->nswapchains
= ID3DPresentGroup_GetMultiheadCount(This
->present
);
177 This
->swapchains
= CALLOC(This
->nswapchains
,
178 sizeof(struct NineSwapChain9
*));
179 if (!This
->swapchains
) { return E_OUTOFMEMORY
; }
181 for (i
= 0; i
< This
->nswapchains
; ++i
) {
182 ID3DPresent
*present
;
184 hr
= ID3DPresentGroup_GetPresent(This
->present
, i
, &present
);
189 D3DDISPLAYMODEEX
*mode
= NULL
;
190 struct NineSwapChain9Ex
**ret
=
191 (struct NineSwapChain9Ex
**)&This
->swapchains
[i
];
193 if (pFullscreenDisplayMode
) mode
= &(pFullscreenDisplayMode
[i
]);
194 /* when this is a Device9Ex, it should create SwapChain9Exs */
195 hr
= NineSwapChain9Ex_new(This
, TRUE
, present
,
196 &pPresentationParameters
[i
], pCTX
,
197 This
->params
.hFocusWindow
, mode
, ret
);
199 hr
= NineSwapChain9_new(This
, TRUE
, present
,
200 &pPresentationParameters
[i
], pCTX
,
201 This
->params
.hFocusWindow
,
202 &This
->swapchains
[i
]);
205 ID3DPresent_Release(present
);
208 NineUnknown_ConvertRefToBind(NineUnknown(This
->swapchains
[i
]));
210 hr
= NineSwapChain9_GetBackBuffer(This
->swapchains
[i
], 0,
211 D3DBACKBUFFER_TYPE_MONO
,
212 (IDirect3DSurface9
**)
216 NineUnknown_ConvertRefToBind(NineUnknown(This
->state
.rt
[i
]));
219 /* Initialize a dummy VBO to be used when a a vertex declaration does not
220 * specify all the inputs needed by vertex shader, on win default behavior
221 * is to pass 0,0,0,0 to the shader */
223 struct pipe_transfer
*transfer
;
224 struct pipe_resource tmpl
;
228 tmpl
.target
= PIPE_BUFFER
;
229 tmpl
.format
= PIPE_FORMAT_R8_UNORM
;
230 tmpl
.width0
= 16; /* 4 floats */
236 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
237 tmpl
.bind
= PIPE_BIND_VERTEX_BUFFER
| PIPE_BIND_TRANSFER_WRITE
;
239 This
->dummy_vbo
= pScreen
->resource_create(pScreen
, &tmpl
);
241 if (!This
->dummy_vbo
)
242 return D3DERR_OUTOFVIDEOMEMORY
;
244 u_box_1d(0, 16, &box
);
245 data
= This
->pipe
->transfer_map(This
->pipe
, This
->dummy_vbo
, 0,
246 PIPE_TRANSFER_WRITE
|
247 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
252 This
->pipe
->transfer_unmap(This
->pipe
, transfer
);
255 This
->cursor
.software
= FALSE
;
256 This
->cursor
.hotspot
.x
= -1;
257 This
->cursor
.hotspot
.y
= -1;
259 struct pipe_resource tmpl
;
260 tmpl
.target
= PIPE_TEXTURE_2D
;
261 tmpl
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
268 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
269 tmpl
.bind
= PIPE_BIND_CURSOR
| PIPE_BIND_SAMPLER_VIEW
;
272 This
->cursor
.image
= pScreen
->resource_create(pScreen
, &tmpl
);
273 if (!This
->cursor
.image
)
274 return D3DERR_OUTOFVIDEOMEMORY
;
277 /* Create constant buffers. */
279 struct pipe_resource tmpl
;
280 unsigned max_const_vs
, max_const_ps
;
282 /* vs 3.0: >= 256 float constants, but for cards with exactly 256 slots,
283 * we have to take in some more slots for int and bool*/
284 max_const_vs
= _min(pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
,
285 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
) /
288 /* ps 3.0: 224 float constants. All cards supported support at least
289 * 256 constants for ps */
290 max_const_ps
= NINE_MAX_CONST_F_PS3
+ (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
292 This
->max_vs_const_f
= max_const_vs
-
293 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
294 This
->max_ps_const_f
= max_const_ps
-
295 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
297 This
->vs_const_size
= max_const_vs
* sizeof(float[4]);
298 This
->ps_const_size
= max_const_ps
* sizeof(float[4]);
299 /* Include space for I,B constants for user constbuf. */
300 This
->state
.vs_const_f
= CALLOC(This
->vs_const_size
, 1);
301 This
->state
.ps_const_f
= CALLOC(This
->ps_const_size
, 1);
302 This
->state
.vs_lconstf_temp
= CALLOC(This
->vs_const_size
,1);
303 This
->state
.ps_lconstf_temp
= CALLOC(This
->ps_const_size
,1);
304 if (!This
->state
.vs_const_f
|| !This
->state
.ps_const_f
||
305 !This
->state
.vs_lconstf_temp
|| !This
->state
.ps_lconstf_temp
)
306 return E_OUTOFMEMORY
;
308 if (strstr(pScreen
->get_name(pScreen
), "AMD") ||
309 strstr(pScreen
->get_name(pScreen
), "ATI")) {
310 This
->prefer_user_constbuf
= TRUE
;
311 This
->driver_bugs
.buggy_barycentrics
= TRUE
;
314 tmpl
.target
= PIPE_BUFFER
;
315 tmpl
.format
= PIPE_FORMAT_R8_UNORM
;
321 tmpl
.usage
= PIPE_USAGE_DYNAMIC
;
322 tmpl
.bind
= PIPE_BIND_CONSTANT_BUFFER
;
325 tmpl
.width0
= This
->vs_const_size
;
326 This
->constbuf_vs
= pScreen
->resource_create(pScreen
, &tmpl
);
328 tmpl
.width0
= This
->ps_const_size
;
329 This
->constbuf_ps
= pScreen
->resource_create(pScreen
, &tmpl
);
331 if (!This
->constbuf_vs
|| !This
->constbuf_ps
)
332 return E_OUTOFMEMORY
;
335 /* allocate dummy texture/sampler for when there are missing ones bound */
337 struct pipe_resource tmplt
;
338 struct pipe_sampler_view templ
;
339 struct pipe_sampler_state samp
;
340 memset(&samp
, 0, sizeof(samp
));
342 tmplt
.target
= PIPE_TEXTURE_2D
;
346 tmplt
.last_level
= 0;
347 tmplt
.array_size
= 1;
348 tmplt
.usage
= PIPE_USAGE_DEFAULT
;
350 tmplt
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
351 tmplt
.bind
= PIPE_BIND_SAMPLER_VIEW
;
352 tmplt
.nr_samples
= 0;
354 This
->dummy_texture
= This
->screen
->resource_create(This
->screen
, &tmplt
);
355 if (!This
->dummy_texture
)
356 return D3DERR_DRIVERINTERNALERROR
;
358 templ
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
359 templ
.u
.tex
.first_layer
= 0;
360 templ
.u
.tex
.last_layer
= 0;
361 templ
.u
.tex
.first_level
= 0;
362 templ
.u
.tex
.last_level
= 0;
363 templ
.swizzle_r
= PIPE_SWIZZLE_ZERO
;
364 templ
.swizzle_g
= PIPE_SWIZZLE_ZERO
;
365 templ
.swizzle_b
= PIPE_SWIZZLE_ZERO
;
366 templ
.swizzle_a
= PIPE_SWIZZLE_ONE
;
367 templ
.target
= This
->dummy_texture
->target
;
369 This
->dummy_sampler_view
= This
->pipe
->create_sampler_view(This
->pipe
, This
->dummy_texture
, &templ
);
370 if (!This
->dummy_sampler_view
)
371 return D3DERR_DRIVERINTERNALERROR
;
373 samp
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
374 samp
.max_lod
= 15.0f
;
375 samp
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
376 samp
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
377 samp
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
378 samp
.min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
379 samp
.mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
380 samp
.compare_mode
= PIPE_TEX_COMPARE_NONE
;
381 samp
.compare_func
= PIPE_FUNC_LEQUAL
;
382 samp
.normalized_coords
= 1;
383 samp
.seamless_cube_map
= 1;
384 This
->dummy_sampler_state
= samp
;
387 /* Allocate upload helper for drivers that suck (from st pov ;). */
389 This
->driver_caps
.user_vbufs
= GET_PCAP(USER_VERTEX_BUFFERS
);
390 This
->driver_caps
.user_ibufs
= GET_PCAP(USER_INDEX_BUFFERS
);
391 This
->driver_caps
.user_cbufs
= GET_PCAP(USER_CONSTANT_BUFFERS
);
393 if (!This
->driver_caps
.user_vbufs
)
394 This
->vertex_uploader
= u_upload_create(This
->pipe
, 65536, 4, PIPE_BIND_VERTEX_BUFFER
);
395 if (!This
->driver_caps
.user_ibufs
)
396 This
->index_uploader
= u_upload_create(This
->pipe
, 128 * 1024, 4, PIPE_BIND_INDEX_BUFFER
);
397 if (!This
->driver_caps
.user_cbufs
) {
398 unsigned alignment
= GET_PCAP(CONSTANT_BUFFER_OFFSET_ALIGNMENT
);
400 This
->constbuf_uploader
= u_upload_create(This
->pipe
, This
->vs_const_size
,
401 alignment
, PIPE_BIND_CONSTANT_BUFFER
);
404 This
->driver_caps
.window_space_position_support
= GET_PCAP(TGSI_VS_WINDOW_SPACE_POSITION
);
405 This
->driver_caps
.vs_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
, PIPE_SHADER_CAP_INTEGERS
);
406 This
->driver_caps
.ps_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_FRAGMENT
, PIPE_SHADER_CAP_INTEGERS
);
408 nine_ff_init(This
); /* initialize fixed function code */
410 NineDevice9_SetDefaultState(This
, FALSE
);
413 struct pipe_poly_stipple stipple
;
414 memset(&stipple
, ~0, sizeof(stipple
));
415 This
->pipe
->set_polygon_stipple(This
->pipe
, &stipple
);
418 This
->update
= &This
->state
;
419 nine_update_state(This
);
421 ID3DPresentGroup_Release(This
->present
);
428 NineDevice9_dtor( struct NineDevice9
*This
)
432 DBG("This=%p\n", This
);
434 if (This
->pipe
&& This
->cso
)
435 nine_pipe_context_clear(This
);
437 nine_state_clear(&This
->state
, TRUE
);
439 if (This
->vertex_uploader
)
440 u_upload_destroy(This
->vertex_uploader
);
441 if (This
->index_uploader
)
442 u_upload_destroy(This
->index_uploader
);
443 if (This
->constbuf_uploader
)
444 u_upload_destroy(This
->constbuf_uploader
);
446 nine_bind(&This
->record
, NULL
);
448 pipe_sampler_view_reference(&This
->dummy_sampler_view
, NULL
);
449 pipe_resource_reference(&This
->dummy_texture
, NULL
);
450 pipe_resource_reference(&This
->constbuf_vs
, NULL
);
451 pipe_resource_reference(&This
->constbuf_ps
, NULL
);
452 pipe_resource_reference(&This
->dummy_vbo
, NULL
);
453 FREE(This
->state
.vs_const_f
);
454 FREE(This
->state
.ps_const_f
);
455 FREE(This
->state
.vs_lconstf_temp
);
456 FREE(This
->state
.ps_lconstf_temp
);
458 if (This
->swapchains
) {
459 for (i
= 0; i
< This
->nswapchains
; ++i
)
460 NineUnknown_Unbind(NineUnknown(This
->swapchains
[i
]));
461 FREE(This
->swapchains
);
467 cso_destroy_context(This
->cso
);
469 if (This
->pipe
->destroy
) { This
->pipe
->destroy(This
->pipe
); }
472 if (This
->present
) { ID3DPresentGroup_Release(This
->present
); }
473 if (This
->d3d9
) { IDirect3D9_Release(This
->d3d9
); }
475 NineUnknown_dtor(&This
->base
);
479 NineDevice9_GetScreen( struct NineDevice9
*This
)
484 struct pipe_context
*
485 NineDevice9_GetPipe( struct NineDevice9
*This
)
491 NineDevice9_GetCSO( struct NineDevice9
*This
)
497 NineDevice9_GetCaps( struct NineDevice9
*This
)
503 NineDevice9_PauseRecording( struct NineDevice9
*This
)
506 This
->update
= &This
->state
;
507 This
->is_recording
= FALSE
;
512 NineDevice9_ResumeRecording( struct NineDevice9
*This
)
515 This
->update
= &This
->record
->state
;
516 This
->is_recording
= TRUE
;
521 NineDevice9_TestCooperativeLevel( struct NineDevice9
*This
)
523 return D3D_OK
; /* TODO */
527 NineDevice9_GetAvailableTextureMem( struct NineDevice9
*This
)
529 const unsigned mem
= This
->screen
->get_param(This
->screen
, PIPE_CAP_VIDEO_MEMORY
);
537 NineDevice9_EvictManagedResources( struct NineDevice9
*This
)
539 struct NineBaseTexture9
*tex
;
541 DBG("This=%p\n", This
);
542 LIST_FOR_EACH_ENTRY(tex
, &This
->managed_textures
, list2
) {
543 NineBaseTexture9_UnLoad(tex
);
550 NineDevice9_GetDirect3D( struct NineDevice9
*This
,
551 IDirect3D9
**ppD3D9
)
553 user_assert(ppD3D9
!= NULL
, E_POINTER
);
554 IDirect3D9_AddRef(This
->d3d9
);
555 *ppD3D9
= This
->d3d9
;
560 NineDevice9_GetDeviceCaps( struct NineDevice9
*This
,
563 user_assert(pCaps
!= NULL
, D3DERR_INVALIDCALL
);
569 NineDevice9_GetDisplayMode( struct NineDevice9
*This
,
571 D3DDISPLAYMODE
*pMode
)
573 DBG("This=%p iSwapChain=%u pMode=%p\n", This
, iSwapChain
, pMode
);
575 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
577 return NineSwapChain9_GetDisplayMode(This
->swapchains
[iSwapChain
], pMode
);
581 NineDevice9_GetCreationParameters( struct NineDevice9
*This
,
582 D3DDEVICE_CREATION_PARAMETERS
*pParameters
)
584 user_assert(pParameters
!= NULL
, D3DERR_INVALIDCALL
);
585 *pParameters
= This
->params
;
590 NineDevice9_SetCursorProperties( struct NineDevice9
*This
,
593 IDirect3DSurface9
*pCursorBitmap
)
595 struct NineSurface9
*surf
= NineSurface9(pCursorBitmap
);
596 struct pipe_context
*pipe
= This
->pipe
;
598 struct pipe_transfer
*transfer
;
602 DBG_FLAG(DBG_SWAPCHAIN
, "This=%p XHotSpot=%u YHotSpot=%u "
603 "pCursorBitmap=%p\n", This
, XHotSpot
, YHotSpot
, pCursorBitmap
);
605 user_assert(pCursorBitmap
, D3DERR_INVALIDCALL
);
607 if (This
->swapchains
[0]->params
.Windowed
) {
608 This
->cursor
.w
= MIN2(surf
->desc
.Width
, 32);
609 This
->cursor
.h
= MIN2(surf
->desc
.Height
, 32);
610 hw_cursor
= 1; /* always use hw cursor for windowed mode */
612 This
->cursor
.w
= MIN2(surf
->desc
.Width
, This
->cursor
.image
->width0
);
613 This
->cursor
.h
= MIN2(surf
->desc
.Height
, This
->cursor
.image
->height0
);
614 hw_cursor
= This
->cursor
.w
== 32 && This
->cursor
.h
== 32;
617 u_box_origin_2d(This
->cursor
.w
, This
->cursor
.h
, &box
);
619 ptr
= pipe
->transfer_map(pipe
, This
->cursor
.image
, 0,
620 PIPE_TRANSFER_WRITE
|
621 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
624 ret_err("Failed to update cursor image.\n", D3DERR_DRIVERINTERNALERROR
);
626 This
->cursor
.hotspot
.x
= XHotSpot
;
627 This
->cursor
.hotspot
.y
= YHotSpot
;
629 /* Copy cursor image to internal storage. */
633 const struct util_format_description
*sfmt
=
634 util_format_description(surf
->base
.info
.format
);
637 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, D3DLOCK_READONLY
);
639 ret_err("Failed to map cursor source image.\n",
640 D3DERR_DRIVERINTERNALERROR
);
642 sfmt
->unpack_rgba_8unorm(ptr
, transfer
->stride
,
643 lock
.pBits
, lock
.Pitch
,
644 This
->cursor
.w
, This
->cursor
.h
);
647 hw_cursor
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
,
649 &This
->cursor
.hotspot
,
650 This
->cursor
.visible
) == D3D_OK
;
652 NineSurface9_UnlockRect(surf
);
654 pipe
->transfer_unmap(pipe
, transfer
);
656 /* hide cursor if we emulate it */
658 ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, FALSE
);
659 This
->cursor
.software
= !hw_cursor
;
665 NineDevice9_SetCursorPosition( struct NineDevice9
*This
,
670 struct NineSwapChain9
*swap
= This
->swapchains
[0];
672 DBG("This=%p X=%d Y=%d Flags=%d\n", This
, X
, Y
, Flags
);
674 This
->cursor
.pos
.x
= X
;
675 This
->cursor
.pos
.y
= Y
;
677 if (!This
->cursor
.software
)
678 This
->cursor
.software
= ID3DPresent_SetCursorPos(swap
->present
, &This
->cursor
.pos
) != D3D_OK
;
682 NineDevice9_ShowCursor( struct NineDevice9
*This
,
685 BOOL old
= This
->cursor
.visible
;
687 DBG("This=%p bShow=%d\n", This
, (int) bShow
);
689 This
->cursor
.visible
= bShow
&& (This
->cursor
.hotspot
.x
!= -1);
690 if (!This
->cursor
.software
)
691 This
->cursor
.software
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, bShow
) != D3D_OK
;
697 NineDevice9_CreateAdditionalSwapChain( struct NineDevice9
*This
,
698 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
699 IDirect3DSwapChain9
**pSwapChain
)
701 struct NineSwapChain9
*swapchain
, *tmplt
= This
->swapchains
[0];
702 ID3DPresent
*present
;
705 DBG("This=%p pPresentationParameters=%p pSwapChain=%p\n",
706 This
, pPresentationParameters
, pSwapChain
);
708 user_assert(pPresentationParameters
, D3DERR_INVALIDCALL
);
710 hr
= ID3DPresentGroup_CreateAdditionalPresent(This
->present
, pPresentationParameters
, &present
);
715 hr
= NineSwapChain9_new(This
, FALSE
, present
, pPresentationParameters
,
717 tmplt
->params
.hDeviceWindow
,
722 *pSwapChain
= (IDirect3DSwapChain9
*)swapchain
;
727 NineDevice9_GetSwapChain( struct NineDevice9
*This
,
729 IDirect3DSwapChain9
**pSwapChain
)
731 user_assert(pSwapChain
!= NULL
, D3DERR_INVALIDCALL
);
734 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
736 NineUnknown_AddRef(NineUnknown(This
->swapchains
[iSwapChain
]));
737 *pSwapChain
= (IDirect3DSwapChain9
*)This
->swapchains
[iSwapChain
];
743 NineDevice9_GetNumberOfSwapChains( struct NineDevice9
*This
)
745 return This
->nswapchains
;
749 NineDevice9_Reset( struct NineDevice9
*This
,
750 D3DPRESENT_PARAMETERS
*pPresentationParameters
)
755 DBG("This=%p pPresentationParameters=%p\n", This
, pPresentationParameters
);
757 for (i
= 0; i
< This
->nswapchains
; ++i
) {
758 D3DPRESENT_PARAMETERS
*params
= &pPresentationParameters
[i
];
759 hr
= NineSwapChain9_Resize(This
->swapchains
[i
], params
, NULL
);
764 nine_pipe_context_clear(This
);
765 nine_state_clear(&This
->state
, TRUE
);
767 NineDevice9_SetDefaultState(This
, TRUE
);
768 NineDevice9_SetRenderTarget(
769 This
, 0, (IDirect3DSurface9
*)This
->swapchains
[0]->buffers
[0]);
770 /* XXX: better use GetBackBuffer here ? */
776 NineDevice9_Present( struct NineDevice9
*This
,
777 const RECT
*pSourceRect
,
778 const RECT
*pDestRect
,
779 HWND hDestWindowOverride
,
780 const RGNDATA
*pDirtyRegion
)
785 DBG("This=%p pSourceRect=%p pDestRect=%p hDestWindowOverride=%p pDirtyRegion=%p\n",
786 This
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
788 /* XXX is this right? */
789 for (i
= 0; i
< This
->nswapchains
; ++i
) {
790 hr
= NineSwapChain9_Present(This
->swapchains
[i
], pSourceRect
, pDestRect
,
791 hDestWindowOverride
, pDirtyRegion
, 0);
792 if (FAILED(hr
)) { return hr
; }
799 NineDevice9_GetBackBuffer( struct NineDevice9
*This
,
802 D3DBACKBUFFER_TYPE Type
,
803 IDirect3DSurface9
**ppBackBuffer
)
805 user_assert(ppBackBuffer
!= NULL
, D3DERR_INVALIDCALL
);
806 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
808 return NineSwapChain9_GetBackBuffer(This
->swapchains
[iSwapChain
],
809 iBackBuffer
, Type
, ppBackBuffer
);
813 NineDevice9_GetRasterStatus( struct NineDevice9
*This
,
815 D3DRASTER_STATUS
*pRasterStatus
)
817 user_assert(pRasterStatus
!= NULL
, D3DERR_INVALIDCALL
);
818 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
820 return NineSwapChain9_GetRasterStatus(This
->swapchains
[iSwapChain
],
825 NineDevice9_SetDialogBoxMode( struct NineDevice9
*This
,
826 BOOL bEnableDialogs
)
828 STUB(D3DERR_INVALIDCALL
);
832 NineDevice9_SetGammaRamp( struct NineDevice9
*This
,
835 const D3DGAMMARAMP
*pRamp
)
837 DBG("This=%p iSwapChain=%u Flags=%x pRamp=%p\n", This
,
838 iSwapChain
, Flags
, pRamp
);
840 user_warn(iSwapChain
>= This
->nswapchains
);
843 if (pRamp
&& (iSwapChain
< This
->nswapchains
)) {
844 struct NineSwapChain9
*swap
= This
->swapchains
[iSwapChain
];
845 swap
->gamma
= *pRamp
;
846 ID3DPresent_SetGammaRamp(swap
->present
, pRamp
, swap
->params
.hDeviceWindow
);
851 NineDevice9_GetGammaRamp( struct NineDevice9
*This
,
853 D3DGAMMARAMP
*pRamp
)
855 DBG("This=%p iSwapChain=%u pRamp=%p\n", This
, iSwapChain
, pRamp
);
857 user_warn(iSwapChain
>= This
->nswapchains
);
860 if (pRamp
&& (iSwapChain
< This
->nswapchains
))
861 *pRamp
= This
->swapchains
[iSwapChain
]->gamma
;
865 NineDevice9_CreateTexture( struct NineDevice9
*This
,
872 IDirect3DTexture9
**ppTexture
,
873 HANDLE
*pSharedHandle
)
875 struct NineTexture9
*tex
;
878 DBG("This=%p Width=%u Height=%u Levels=%u Usage=%s Format=%s Pool=%s "
879 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Levels
,
880 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
881 nine_D3DPOOL_to_str(Pool
), ppTexture
, pSharedHandle
);
883 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DMAP
|
884 D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
885 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
;
888 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
889 user_assert(!pSharedHandle
|| This
->ex
, D3DERR_INVALIDCALL
);
890 /* When is used shared handle, Pool must be
891 * SYSTEMMEM with Levels 1 or DEFAULT with any Levels */
892 user_assert(!pSharedHandle
|| Pool
!= D3DPOOL_SYSTEMMEM
|| Levels
== 1,
894 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_SYSTEMMEM
|| Pool
== D3DPOOL_DEFAULT
,
896 user_assert((Usage
!= D3DUSAGE_AUTOGENMIPMAP
|| Levels
<= 1), D3DERR_INVALIDCALL
);
898 hr
= NineTexture9_new(This
, Width
, Height
, Levels
, Usage
, Format
, Pool
,
899 &tex
, pSharedHandle
);
901 *ppTexture
= (IDirect3DTexture9
*)tex
;
907 NineDevice9_CreateVolumeTexture( struct NineDevice9
*This
,
915 IDirect3DVolumeTexture9
**ppVolumeTexture
,
916 HANDLE
*pSharedHandle
)
918 struct NineVolumeTexture9
*tex
;
921 DBG("This=%p Width=%u Height=%u Depth=%u Levels=%u Usage=%s Format=%s Pool=%s "
922 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Depth
, Levels
,
923 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
924 nine_D3DPOOL_to_str(Pool
), ppVolumeTexture
, pSharedHandle
);
926 Usage
&= D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
927 D3DUSAGE_SOFTWAREPROCESSING
;
929 *ppVolumeTexture
= NULL
;
930 user_assert(Width
&& Height
&& Depth
, D3DERR_INVALIDCALL
);
931 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
933 hr
= NineVolumeTexture9_new(This
, Width
, Height
, Depth
, Levels
,
934 Usage
, Format
, Pool
, &tex
, pSharedHandle
);
936 *ppVolumeTexture
= (IDirect3DVolumeTexture9
*)tex
;
942 NineDevice9_CreateCubeTexture( struct NineDevice9
*This
,
948 IDirect3DCubeTexture9
**ppCubeTexture
,
949 HANDLE
*pSharedHandle
)
951 struct NineCubeTexture9
*tex
;
954 DBG("This=%p EdgeLength=%u Levels=%u Usage=%s Format=%s Pool=%s ppOut=%p "
955 "pSharedHandle=%p\n", This
, EdgeLength
, Levels
,
956 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
957 nine_D3DPOOL_to_str(Pool
), ppCubeTexture
, pSharedHandle
);
959 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DYNAMIC
|
960 D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
961 D3DUSAGE_SOFTWAREPROCESSING
;
963 *ppCubeTexture
= NULL
;
964 user_assert(EdgeLength
, D3DERR_INVALIDCALL
);
965 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
967 hr
= NineCubeTexture9_new(This
, EdgeLength
, Levels
, Usage
, Format
, Pool
,
968 &tex
, pSharedHandle
);
970 *ppCubeTexture
= (IDirect3DCubeTexture9
*)tex
;
976 NineDevice9_CreateVertexBuffer( struct NineDevice9
*This
,
981 IDirect3DVertexBuffer9
**ppVertexBuffer
,
982 HANDLE
*pSharedHandle
)
984 struct NineVertexBuffer9
*buf
;
986 D3DVERTEXBUFFER_DESC desc
;
988 DBG("This=%p Length=%u Usage=%x FVF=%x Pool=%u ppOut=%p pSharedHandle=%p\n",
989 This
, Length
, Usage
, FVF
, Pool
, ppVertexBuffer
, pSharedHandle
);
991 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
993 desc
.Format
= D3DFMT_VERTEXDATA
;
994 desc
.Type
= D3DRTYPE_VERTEXBUFFER
;
996 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
997 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
998 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
|
1004 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1005 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1007 hr
= NineVertexBuffer9_new(This
, &desc
, &buf
);
1009 *ppVertexBuffer
= (IDirect3DVertexBuffer9
*)buf
;
1014 NineDevice9_CreateIndexBuffer( struct NineDevice9
*This
,
1019 IDirect3DIndexBuffer9
**ppIndexBuffer
,
1020 HANDLE
*pSharedHandle
)
1022 struct NineIndexBuffer9
*buf
;
1024 D3DINDEXBUFFER_DESC desc
;
1026 DBG("This=%p Length=%u Usage=%x Format=%s Pool=%u ppOut=%p "
1027 "pSharedHandle=%p\n", This
, Length
, Usage
,
1028 d3dformat_to_string(Format
), Pool
, ppIndexBuffer
, pSharedHandle
);
1030 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1032 desc
.Format
= Format
;
1033 desc
.Type
= D3DRTYPE_INDEXBUFFER
;
1034 desc
.Usage
= Usage
&
1035 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1036 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1037 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_WRITEONLY
);
1041 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1042 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1044 hr
= NineIndexBuffer9_new(This
, &desc
, &buf
);
1046 *ppIndexBuffer
= (IDirect3DIndexBuffer9
*)buf
;
1051 create_zs_or_rt_surface(struct NineDevice9
*This
,
1052 unsigned type
, /* 0 = RT, 1 = ZS, 2 = plain */
1054 UINT Width
, UINT Height
,
1056 D3DMULTISAMPLE_TYPE MultiSample
,
1057 DWORD MultisampleQuality
,
1058 BOOL Discard_or_Lockable
,
1059 IDirect3DSurface9
**ppSurface
,
1060 HANDLE
*pSharedHandle
)
1062 struct NineSurface9
*surface
;
1063 struct pipe_screen
*screen
= This
->screen
;
1064 struct pipe_resource
*resource
= NULL
;
1066 D3DSURFACE_DESC desc
;
1067 struct pipe_resource templ
;
1069 DBG("This=%p type=%u Pool=%s Width=%u Height=%u Format=%s MS=%u Quality=%u "
1070 "Discard_or_Lockable=%i ppSurface=%p pSharedHandle=%p\n",
1071 This
, type
, nine_D3DPOOL_to_str(Pool
), Width
, Height
,
1072 d3dformat_to_string(Format
), MultiSample
, MultisampleQuality
,
1073 Discard_or_Lockable
, ppSurface
, pSharedHandle
);
1076 DBG("FIXME Used shared handle! This option isn't probably handled correctly!\n");
1078 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
1079 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1081 templ
.target
= PIPE_TEXTURE_2D
;
1082 templ
.width0
= Width
;
1083 templ
.height0
= Height
;
1085 templ
.array_size
= 1;
1086 templ
.last_level
= 0;
1087 templ
.nr_samples
= (unsigned)MultiSample
;
1088 templ
.usage
= PIPE_USAGE_DEFAULT
;
1090 templ
.bind
= PIPE_BIND_SAMPLER_VIEW
; /* StretchRect */
1092 case 0: templ
.bind
|= PIPE_BIND_RENDER_TARGET
; break;
1093 case 1: templ
.bind
= d3d9_get_pipe_depth_format_bindings(Format
); break;
1098 templ
.format
= d3d9_to_pipe_format_checked(screen
, Format
, templ
.target
,
1099 templ
.nr_samples
, templ
.bind
,
1102 desc
.Format
= Format
;
1103 desc
.Type
= D3DRTYPE_SURFACE
;
1106 desc
.MultiSampleType
= MultiSample
;
1107 desc
.MultiSampleQuality
= MultisampleQuality
;
1109 desc
.Height
= Height
;
1111 case 0: desc
.Usage
= D3DUSAGE_RENDERTARGET
; break;
1112 case 1: desc
.Usage
= D3DUSAGE_DEPTHSTENCIL
; break;
1116 if (compressed_format(Format
)) {
1117 const unsigned w
= util_format_get_blockwidth(templ
.format
);
1118 const unsigned h
= util_format_get_blockheight(templ
.format
);
1120 user_assert(!(Width
% w
) && !(Height
% h
), D3DERR_INVALIDCALL
);
1123 if (Pool
== D3DPOOL_DEFAULT
&& Format
!= D3DFMT_NULL
) {
1124 /* resource_create doesn't return an error code, so check format here */
1125 user_assert(templ
.format
!= PIPE_FORMAT_NONE
, D3DERR_INVALIDCALL
);
1126 resource
= screen
->resource_create(screen
, &templ
);
1127 user_assert(resource
, D3DERR_OUTOFVIDEOMEMORY
);
1128 if (Discard_or_Lockable
&& (desc
.Usage
& D3DUSAGE_RENDERTARGET
))
1129 resource
->flags
|= NINE_RESOURCE_FLAG_LOCKABLE
;
1133 hr
= NineSurface9_new(This
, NULL
, resource
, NULL
, 0, 0, 0, &desc
, &surface
);
1134 pipe_resource_reference(&resource
, NULL
);
1137 *ppSurface
= (IDirect3DSurface9
*)surface
;
1142 NineDevice9_CreateRenderTarget( struct NineDevice9
*This
,
1146 D3DMULTISAMPLE_TYPE MultiSample
,
1147 DWORD MultisampleQuality
,
1149 IDirect3DSurface9
**ppSurface
,
1150 HANDLE
*pSharedHandle
)
1153 return create_zs_or_rt_surface(This
, 0, D3DPOOL_DEFAULT
,
1154 Width
, Height
, Format
,
1155 MultiSample
, MultisampleQuality
,
1156 Lockable
, ppSurface
, pSharedHandle
);
1160 NineDevice9_CreateDepthStencilSurface( struct NineDevice9
*This
,
1164 D3DMULTISAMPLE_TYPE MultiSample
,
1165 DWORD MultisampleQuality
,
1167 IDirect3DSurface9
**ppSurface
,
1168 HANDLE
*pSharedHandle
)
1171 if (!depth_stencil_format(Format
))
1172 return D3DERR_NOTAVAILABLE
;
1173 return create_zs_or_rt_surface(This
, 1, D3DPOOL_DEFAULT
,
1174 Width
, Height
, Format
,
1175 MultiSample
, MultisampleQuality
,
1176 Discard
, ppSurface
, pSharedHandle
);
1180 NineDevice9_UpdateSurface( struct NineDevice9
*This
,
1181 IDirect3DSurface9
*pSourceSurface
,
1182 const RECT
*pSourceRect
,
1183 IDirect3DSurface9
*pDestinationSurface
,
1184 const POINT
*pDestPoint
)
1186 struct NineSurface9
*dst
= NineSurface9(pDestinationSurface
);
1187 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1188 int copy_width
, copy_height
;
1191 DBG("This=%p pSourceSurface=%p pDestinationSurface=%p "
1192 "pSourceRect=%p pDestPoint=%p\n", This
,
1193 pSourceSurface
, pDestinationSurface
, pSourceRect
, pDestPoint
);
1195 DBG("pSourceRect = (%u,%u)-(%u,%u)\n",
1196 pSourceRect
->left
, pSourceRect
->top
,
1197 pSourceRect
->right
, pSourceRect
->bottom
);
1199 DBG("pDestPoint = (%u,%u)\n", pDestPoint
->x
, pDestPoint
->y
);
1201 user_assert(dst
&& src
, D3DERR_INVALIDCALL
);
1203 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1204 user_assert(src
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1206 user_assert(dst
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1207 user_assert(src
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1209 user_assert(!src
->lock_count
, D3DERR_INVALIDCALL
);
1210 user_assert(!dst
->lock_count
, D3DERR_INVALIDCALL
);
1212 user_assert(dst
->desc
.Format
== src
->desc
.Format
, D3DERR_INVALIDCALL
);
1213 user_assert(!depth_stencil_format(dst
->desc
.Format
), D3DERR_INVALIDCALL
);
1216 copy_width
= pSourceRect
->right
- pSourceRect
->left
;
1217 copy_height
= pSourceRect
->bottom
- pSourceRect
->top
;
1219 user_assert(pSourceRect
->left
>= 0 &&
1221 pSourceRect
->right
<= src
->desc
.Width
&&
1222 pSourceRect
->top
>= 0 &&
1224 pSourceRect
->bottom
<= src
->desc
.Height
,
1225 D3DERR_INVALIDCALL
);
1227 copy_width
= src
->desc
.Width
;
1228 copy_height
= src
->desc
.Height
;
1231 destRect
.right
= copy_width
;
1232 destRect
.bottom
= copy_height
;
1235 user_assert(pDestPoint
->x
>= 0 && pDestPoint
->y
>= 0,
1236 D3DERR_INVALIDCALL
);
1237 destRect
.right
+= pDestPoint
->x
;
1238 destRect
.bottom
+= pDestPoint
->y
;
1241 user_assert(destRect
.right
<= dst
->desc
.Width
&&
1242 destRect
.bottom
<= dst
->desc
.Height
,
1243 D3DERR_INVALIDCALL
);
1245 if (compressed_format(dst
->desc
.Format
)) {
1246 const unsigned w
= util_format_get_blockwidth(dst
->base
.info
.format
);
1247 const unsigned h
= util_format_get_blockheight(dst
->base
.info
.format
);
1250 user_assert(!(pDestPoint
->x
% w
) && !(pDestPoint
->y
% h
),
1251 D3DERR_INVALIDCALL
);
1255 user_assert(!(pSourceRect
->left
% w
) && !(pSourceRect
->top
% h
),
1256 D3DERR_INVALIDCALL
);
1258 if (!(copy_width
== src
->desc
.Width
&&
1259 copy_width
== dst
->desc
.Width
&&
1260 copy_height
== src
->desc
.Height
&&
1261 copy_height
== dst
->desc
.Height
)) {
1262 user_assert(!(copy_width
% w
) && !(copy_height
% h
),
1263 D3DERR_INVALIDCALL
);
1267 NineSurface9_CopyMemToDefault(dst
, src
, pDestPoint
, pSourceRect
);
1273 NineDevice9_UpdateTexture( struct NineDevice9
*This
,
1274 IDirect3DBaseTexture9
*pSourceTexture
,
1275 IDirect3DBaseTexture9
*pDestinationTexture
)
1277 struct NineBaseTexture9
*dstb
= NineBaseTexture9(pDestinationTexture
);
1278 struct NineBaseTexture9
*srcb
= NineBaseTexture9(pSourceTexture
);
1280 unsigned last_level
= dstb
->base
.info
.last_level
;
1283 DBG("This=%p pSourceTexture=%p pDestinationTexture=%p\n", This
,
1284 pSourceTexture
, pDestinationTexture
);
1286 user_assert(pSourceTexture
!= pDestinationTexture
, D3DERR_INVALIDCALL
);
1288 user_assert(dstb
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1289 user_assert(srcb
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1291 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1292 /* Only the first level is updated, the others regenerated. */
1294 /* if the source has D3DUSAGE_AUTOGENMIPMAP, we have to ignore
1295 * the sublevels, thus level 0 has to match */
1296 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ||
1297 (srcb
->base
.info
.width0
== dstb
->base
.info
.width0
&&
1298 srcb
->base
.info
.height0
== dstb
->base
.info
.height0
&&
1299 srcb
->base
.info
.depth0
== dstb
->base
.info
.depth0
),
1300 D3DERR_INVALIDCALL
);
1302 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
), D3DERR_INVALIDCALL
);
1305 user_assert(dstb
->base
.type
== srcb
->base
.type
, D3DERR_INVALIDCALL
);
1307 /* Find src level that matches dst level 0: */
1308 user_assert(srcb
->base
.info
.width0
>= dstb
->base
.info
.width0
&&
1309 srcb
->base
.info
.height0
>= dstb
->base
.info
.height0
&&
1310 srcb
->base
.info
.depth0
>= dstb
->base
.info
.depth0
,
1311 D3DERR_INVALIDCALL
);
1312 for (m
= 0; m
<= srcb
->base
.info
.last_level
; ++m
) {
1313 unsigned w
= u_minify(srcb
->base
.info
.width0
, m
);
1314 unsigned h
= u_minify(srcb
->base
.info
.height0
, m
);
1315 unsigned d
= u_minify(srcb
->base
.info
.depth0
, m
);
1317 if (w
== dstb
->base
.info
.width0
&&
1318 h
== dstb
->base
.info
.height0
&&
1319 d
== dstb
->base
.info
.depth0
)
1322 user_assert(m
<= srcb
->base
.info
.last_level
, D3DERR_INVALIDCALL
);
1324 last_level
= MIN2(last_level
, srcb
->base
.info
.last_level
- m
);
1326 if (dstb
->base
.type
== D3DRTYPE_TEXTURE
) {
1327 struct NineTexture9
*dst
= NineTexture9(dstb
);
1328 struct NineTexture9
*src
= NineTexture9(srcb
);
1330 if (src
->dirty_rect
.width
== 0)
1333 pipe_box_to_rect(&rect
, &src
->dirty_rect
);
1334 for (l
= 0; l
< m
; ++l
)
1335 rect_minify_inclusive(&rect
);
1337 for (l
= 0; l
<= last_level
; ++l
, ++m
) {
1338 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1340 dst
->surfaces
[l
]->desc
.Width
,
1341 dst
->surfaces
[l
]->desc
.Height
);
1342 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
],
1346 rect_minify_inclusive(&rect
);
1348 u_box_origin_2d(0, 0, &src
->dirty_rect
);
1350 if (dstb
->base
.type
== D3DRTYPE_CUBETEXTURE
) {
1351 struct NineCubeTexture9
*dst
= NineCubeTexture9(dstb
);
1352 struct NineCubeTexture9
*src
= NineCubeTexture9(srcb
);
1355 /* GPUs usually have them stored as arrays of mip-mapped 2D textures. */
1356 for (z
= 0; z
< 6; ++z
) {
1357 if (src
->dirty_rect
[z
].width
== 0)
1360 pipe_box_to_rect(&rect
, &src
->dirty_rect
[z
]);
1361 for (l
= 0; l
< m
; ++l
)
1362 rect_minify_inclusive(&rect
);
1364 for (l
= 0; l
<= last_level
; ++l
, ++m
) {
1365 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1367 dst
->surfaces
[l
* 6 + z
]->desc
.Width
,
1368 dst
->surfaces
[l
* 6 + z
]->desc
.Height
);
1369 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
* 6 + z
],
1370 src
->surfaces
[m
* 6 + z
],
1373 rect_minify_inclusive(&rect
);
1375 u_box_origin_2d(0, 0, &src
->dirty_rect
[z
]);
1379 if (dstb
->base
.type
== D3DRTYPE_VOLUMETEXTURE
) {
1380 struct NineVolumeTexture9
*dst
= NineVolumeTexture9(dstb
);
1381 struct NineVolumeTexture9
*src
= NineVolumeTexture9(srcb
);
1383 if (src
->dirty_box
.width
== 0)
1385 for (l
= 0; l
<= last_level
; ++l
, ++m
)
1386 NineVolume9_CopyMemToDefault(dst
->volumes
[l
],
1387 src
->volumes
[m
], 0, 0, 0, NULL
);
1388 u_box_3d(0, 0, 0, 0, 0, 0, &src
->dirty_box
);
1390 assert(!"invalid texture type");
1393 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1394 dstb
->dirty_mip
= TRUE
;
1395 NineBaseTexture9_GenerateMipSubLevels(dstb
);
1402 NineDevice9_GetRenderTargetData( struct NineDevice9
*This
,
1403 IDirect3DSurface9
*pRenderTarget
,
1404 IDirect3DSurface9
*pDestSurface
)
1406 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1407 struct NineSurface9
*src
= NineSurface9(pRenderTarget
);
1409 DBG("This=%p pRenderTarget=%p pDestSurface=%p\n",
1410 This
, pRenderTarget
, pDestSurface
);
1412 user_assert(dst
->desc
.Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1413 user_assert(src
->desc
.Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1415 user_assert(dst
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1416 user_assert(src
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1418 user_assert(src
->desc
.Width
== dst
->desc
.Width
, D3DERR_INVALIDCALL
);
1419 user_assert(src
->desc
.Height
== dst
->desc
.Height
, D3DERR_INVALIDCALL
);
1421 NineSurface9_CopyDefaultToMem(dst
, src
);
1427 NineDevice9_GetFrontBufferData( struct NineDevice9
*This
,
1429 IDirect3DSurface9
*pDestSurface
)
1431 DBG("This=%p iSwapChain=%u pDestSurface=%p\n", This
,
1432 iSwapChain
, pDestSurface
);
1434 user_assert(pDestSurface
!= NULL
, D3DERR_INVALIDCALL
);
1435 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
1437 return NineSwapChain9_GetFrontBufferData(This
->swapchains
[iSwapChain
],
1442 NineDevice9_StretchRect( struct NineDevice9
*This
,
1443 IDirect3DSurface9
*pSourceSurface
,
1444 const RECT
*pSourceRect
,
1445 IDirect3DSurface9
*pDestSurface
,
1446 const RECT
*pDestRect
,
1447 D3DTEXTUREFILTERTYPE Filter
)
1449 struct pipe_screen
*screen
= This
->screen
;
1450 struct pipe_context
*pipe
= This
->pipe
;
1451 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1452 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1453 struct pipe_resource
*dst_res
= NineSurface9_GetResource(dst
);
1454 struct pipe_resource
*src_res
= NineSurface9_GetResource(src
);
1455 const boolean zs
= util_format_is_depth_or_stencil(dst_res
->format
);
1456 struct pipe_blit_info blit
;
1457 boolean scaled
, clamped
, ms
, flip_x
= FALSE
, flip_y
= FALSE
;
1459 DBG("This=%p pSourceSurface=%p pSourceRect=%p pDestSurface=%p "
1460 "pDestRect=%p Filter=%u\n",
1461 This
, pSourceSurface
, pSourceRect
, pDestSurface
, pDestRect
, Filter
);
1463 DBG("pSourceRect=(%u,%u)-(%u,%u)\n",
1464 pSourceRect
->left
, pSourceRect
->top
,
1465 pSourceRect
->right
, pSourceRect
->bottom
);
1467 DBG("pDestRect=(%u,%u)-(%u,%u)\n", pDestRect
->left
, pDestRect
->top
,
1468 pDestRect
->right
, pDestRect
->bottom
);
1470 user_assert(!zs
|| !This
->in_scene
, D3DERR_INVALIDCALL
);
1471 user_assert(!zs
|| !pSourceRect
||
1472 (pSourceRect
->left
== 0 &&
1473 pSourceRect
->top
== 0 &&
1474 pSourceRect
->right
== src
->desc
.Width
&&
1475 pSourceRect
->bottom
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1476 user_assert(!zs
|| !pDestRect
||
1477 (pDestRect
->left
== 0 &&
1478 pDestRect
->top
== 0 &&
1479 pDestRect
->right
== dst
->desc
.Width
&&
1480 pDestRect
->bottom
== dst
->desc
.Height
), D3DERR_INVALIDCALL
);
1482 (dst
->desc
.Width
== src
->desc
.Width
&&
1483 dst
->desc
.Height
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1484 user_assert(zs
|| !util_format_is_depth_or_stencil(src_res
->format
),
1485 D3DERR_INVALIDCALL
);
1486 user_assert(!zs
|| dst
->desc
.Format
== src
->desc
.Format
,
1487 D3DERR_INVALIDCALL
);
1488 user_assert(screen
->is_format_supported(screen
, src_res
->format
,
1490 src_res
->nr_samples
,
1491 PIPE_BIND_SAMPLER_VIEW
),
1492 D3DERR_INVALIDCALL
);
1493 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
&&
1494 src
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1496 /* We might want to permit these, but wine thinks we shouldn't. */
1497 user_assert(!pDestRect
||
1498 (pDestRect
->left
<= pDestRect
->right
&&
1499 pDestRect
->top
<= pDestRect
->bottom
), D3DERR_INVALIDCALL
);
1500 user_assert(!pSourceRect
||
1501 (pSourceRect
->left
<= pSourceRect
->right
&&
1502 pSourceRect
->top
<= pSourceRect
->bottom
), D3DERR_INVALIDCALL
);
1504 memset(&blit
, 0, sizeof(blit
));
1505 blit
.dst
.resource
= dst_res
;
1506 blit
.dst
.level
= dst
->level
;
1507 blit
.dst
.box
.z
= dst
->layer
;
1508 blit
.dst
.box
.depth
= 1;
1509 blit
.dst
.format
= dst_res
->format
;
1511 flip_x
= pDestRect
->left
> pDestRect
->right
;
1513 blit
.dst
.box
.x
= pDestRect
->right
;
1514 blit
.dst
.box
.width
= pDestRect
->left
- pDestRect
->right
;
1516 blit
.dst
.box
.x
= pDestRect
->left
;
1517 blit
.dst
.box
.width
= pDestRect
->right
- pDestRect
->left
;
1519 flip_y
= pDestRect
->top
> pDestRect
->bottom
;
1521 blit
.dst
.box
.y
= pDestRect
->bottom
;
1522 blit
.dst
.box
.height
= pDestRect
->top
- pDestRect
->bottom
;
1524 blit
.dst
.box
.y
= pDestRect
->top
;
1525 blit
.dst
.box
.height
= pDestRect
->bottom
- pDestRect
->top
;
1530 blit
.dst
.box
.width
= dst
->desc
.Width
;
1531 blit
.dst
.box
.height
= dst
->desc
.Height
;
1533 blit
.src
.resource
= src_res
;
1534 blit
.src
.level
= src
->level
;
1535 blit
.src
.box
.z
= src
->layer
;
1536 blit
.src
.box
.depth
= 1;
1537 blit
.src
.format
= src_res
->format
;
1539 if (flip_x
^ (pSourceRect
->left
> pSourceRect
->right
)) {
1540 blit
.src
.box
.x
= pSourceRect
->right
;
1541 blit
.src
.box
.width
= pSourceRect
->left
- pSourceRect
->right
;
1543 blit
.src
.box
.x
= pSourceRect
->left
;
1544 blit
.src
.box
.width
= pSourceRect
->right
- pSourceRect
->left
;
1546 if (flip_y
^ (pSourceRect
->top
> pSourceRect
->bottom
)) {
1547 blit
.src
.box
.y
= pSourceRect
->bottom
;
1548 blit
.src
.box
.height
= pSourceRect
->top
- pSourceRect
->bottom
;
1550 blit
.src
.box
.y
= pSourceRect
->top
;
1551 blit
.src
.box
.height
= pSourceRect
->bottom
- pSourceRect
->top
;
1554 blit
.src
.box
.x
= flip_x
? src
->desc
.Width
: 0;
1555 blit
.src
.box
.y
= flip_y
? src
->desc
.Height
: 0;
1556 blit
.src
.box
.width
= flip_x
? -src
->desc
.Width
: src
->desc
.Width
;
1557 blit
.src
.box
.height
= flip_y
? -src
->desc
.Height
: src
->desc
.Height
;
1559 blit
.mask
= zs
? PIPE_MASK_ZS
: PIPE_MASK_RGBA
;
1560 blit
.filter
= Filter
== D3DTEXF_LINEAR
?
1561 PIPE_TEX_FILTER_LINEAR
: PIPE_TEX_FILTER_NEAREST
;
1562 blit
.scissor_enable
= FALSE
;
1563 blit
.alpha_blend
= FALSE
;
1565 /* If both of a src and dst dimension are negative, flip them. */
1566 if (blit
.dst
.box
.width
< 0 && blit
.src
.box
.width
< 0) {
1567 blit
.dst
.box
.width
= -blit
.dst
.box
.width
;
1568 blit
.src
.box
.width
= -blit
.src
.box
.width
;
1570 if (blit
.dst
.box
.height
< 0 && blit
.src
.box
.height
< 0) {
1571 blit
.dst
.box
.height
= -blit
.dst
.box
.height
;
1572 blit
.src
.box
.height
= -blit
.src
.box
.height
;
1575 blit
.dst
.box
.width
!= blit
.src
.box
.width
||
1576 blit
.dst
.box
.height
!= blit
.src
.box
.height
;
1578 user_assert(!scaled
|| dst
!= src
, D3DERR_INVALIDCALL
);
1579 user_assert(!scaled
||
1580 !NineSurface9_IsOffscreenPlain(dst
), D3DERR_INVALIDCALL
);
1581 user_assert(!NineSurface9_IsOffscreenPlain(dst
) ||
1582 NineSurface9_IsOffscreenPlain(src
), D3DERR_INVALIDCALL
);
1583 user_assert(NineSurface9_IsOffscreenPlain(dst
) ||
1584 dst
->desc
.Usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
),
1585 D3DERR_INVALIDCALL
);
1586 user_assert(!scaled
||
1587 (!util_format_is_compressed(dst
->base
.info
.format
) &&
1588 !util_format_is_compressed(src
->base
.info
.format
)),
1589 D3DERR_INVALIDCALL
);
1591 user_warn(src
== dst
&&
1592 u_box_test_intersection_2d(&blit
.src
.box
, &blit
.dst
.box
));
1594 /* Check for clipping/clamping: */
1596 struct pipe_box box
;
1599 xy
= u_box_clip_2d(&box
, &blit
.dst
.box
,
1600 dst
->desc
.Width
, dst
->desc
.Height
);
1604 xy
= u_box_clip_2d(&box
, &blit
.src
.box
,
1605 src
->desc
.Width
, src
->desc
.Height
);
1609 ms
= (dst
->desc
.MultiSampleType
| 1) != (src
->desc
.MultiSampleType
| 1);
1611 if (clamped
|| scaled
|| (blit
.dst
.format
!= blit
.src
.format
) || ms
) {
1612 DBG("using pipe->blit()\n");
1613 /* TODO: software scaling */
1614 user_assert(screen
->is_format_supported(screen
, dst_res
->format
,
1616 dst_res
->nr_samples
,
1617 zs
? PIPE_BIND_DEPTH_STENCIL
:
1618 PIPE_BIND_RENDER_TARGET
),
1619 D3DERR_INVALIDCALL
);
1621 pipe
->blit(pipe
, &blit
);
1623 assert(blit
.dst
.box
.x
>= 0 && blit
.dst
.box
.y
>= 0 &&
1624 blit
.src
.box
.x
>= 0 && blit
.src
.box
.y
>= 0 &&
1625 blit
.dst
.box
.x
+ blit
.dst
.box
.width
<= dst
->desc
.Width
&&
1626 blit
.src
.box
.x
+ blit
.src
.box
.width
<= src
->desc
.Width
&&
1627 blit
.dst
.box
.y
+ blit
.dst
.box
.height
<= dst
->desc
.Height
&&
1628 blit
.src
.box
.y
+ blit
.src
.box
.height
<= src
->desc
.Height
);
1629 /* Or drivers might crash ... */
1630 DBG("Using resource_copy_region.\n");
1631 pipe
->resource_copy_region(pipe
,
1632 blit
.dst
.resource
, blit
.dst
.level
,
1633 blit
.dst
.box
.x
, blit
.dst
.box
.y
, blit
.dst
.box
.z
,
1634 blit
.src
.resource
, blit
.src
.level
,
1638 /* Communicate the container it needs to update sublevels - if apply */
1639 NineSurface9_MarkContainerDirty(dst
);
1645 NineDevice9_ColorFill( struct NineDevice9
*This
,
1646 IDirect3DSurface9
*pSurface
,
1650 struct pipe_context
*pipe
= This
->pipe
;
1651 struct NineSurface9
*surf
= NineSurface9(pSurface
);
1652 struct pipe_surface
*psurf
;
1653 unsigned x
, y
, w
, h
;
1654 union pipe_color_union rgba
;
1657 DBG("This=%p pSurface=%p pRect=%p color=%08x\n", This
,
1658 pSurface
, pRect
, color
);
1660 DBG("pRect=(%u,%u)-(%u,%u)\n", pRect
->left
, pRect
->top
,
1661 pRect
->right
, pRect
->bottom
);
1663 user_assert(surf
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1665 user_assert((surf
->base
.usage
& D3DUSAGE_RENDERTARGET
) ||
1666 NineSurface9_IsOffscreenPlain(surf
), D3DERR_INVALIDCALL
);
1671 w
= pRect
->right
- pRect
->left
;
1672 h
= pRect
->bottom
- pRect
->top
;
1676 w
= surf
->desc
.Width
;
1677 h
= surf
->desc
.Height
;
1679 d3dcolor_to_pipe_color_union(&rgba
, color
);
1681 fallback
= !(surf
->base
.info
.bind
& PIPE_BIND_RENDER_TARGET
);
1684 psurf
= NineSurface9_GetSurface(surf
, 0);
1690 pipe
->clear_render_target(pipe
, psurf
, &rgba
, x
, y
, w
, h
);
1692 D3DLOCKED_RECT lock
;
1693 union util_color uc
;
1695 /* XXX: lock pRect and fix util_fill_rect */
1696 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, 0);
1699 util_pack_color_ub(color
>> 16, color
>> 8, color
>> 0, color
>> 24,
1700 surf
->base
.info
.format
, &uc
);
1701 util_fill_rect(lock
.pBits
, surf
->base
.info
.format
,lock
.Pitch
,
1703 NineSurface9_UnlockRect(surf
);
1710 NineDevice9_CreateOffscreenPlainSurface( struct NineDevice9
*This
,
1715 IDirect3DSurface9
**ppSurface
,
1716 HANDLE
*pSharedHandle
)
1720 DBG("This=%p Width=%u Height=%u Format=%s(0x%x) Pool=%u "
1721 "ppSurface=%p pSharedHandle=%p\n", This
,
1722 Width
, Height
, d3dformat_to_string(Format
), Format
, Pool
,
1723 ppSurface
, pSharedHandle
);
1726 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
1727 || Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1728 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1730 /* Can be used with StretchRect and ColorFill. It's also always lockable.
1732 hr
= create_zs_or_rt_surface(This
, 2, Pool
, Width
, Height
,
1734 D3DMULTISAMPLE_NONE
, 0,
1736 ppSurface
, pSharedHandle
);
1738 DBG("Failed to create surface.\n");
1743 NineDevice9_SetRenderTarget( struct NineDevice9
*This
,
1744 DWORD RenderTargetIndex
,
1745 IDirect3DSurface9
*pRenderTarget
)
1747 struct NineSurface9
*rt
= NineSurface9(pRenderTarget
);
1748 const unsigned i
= RenderTargetIndex
;
1750 DBG("This=%p RenderTargetIndex=%u pRenderTarget=%p\n", This
,
1751 RenderTargetIndex
, pRenderTarget
);
1753 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1754 user_assert(i
!= 0 || pRenderTarget
, D3DERR_INVALIDCALL
);
1755 user_assert(!pRenderTarget
||
1756 rt
->desc
.Usage
& D3DUSAGE_RENDERTARGET
, D3DERR_INVALIDCALL
);
1759 This
->state
.viewport
.X
= 0;
1760 This
->state
.viewport
.Y
= 0;
1761 This
->state
.viewport
.Width
= rt
->desc
.Width
;
1762 This
->state
.viewport
.Height
= rt
->desc
.Height
;
1763 This
->state
.viewport
.MinZ
= 0.0f
;
1764 This
->state
.viewport
.MaxZ
= 1.0f
;
1766 This
->state
.scissor
.minx
= 0;
1767 This
->state
.scissor
.miny
= 0;
1768 This
->state
.scissor
.maxx
= rt
->desc
.Width
;
1769 This
->state
.scissor
.maxy
= rt
->desc
.Height
;
1771 This
->state
.changed
.group
|= NINE_STATE_VIEWPORT
| NINE_STATE_SCISSOR
;
1774 if (This
->state
.rt
[i
] != NineSurface9(pRenderTarget
)) {
1775 nine_bind(&This
->state
.rt
[i
], pRenderTarget
);
1776 This
->state
.changed
.group
|= NINE_STATE_FB
;
1782 NineDevice9_GetRenderTarget( struct NineDevice9
*This
,
1783 DWORD RenderTargetIndex
,
1784 IDirect3DSurface9
**ppRenderTarget
)
1786 const unsigned i
= RenderTargetIndex
;
1788 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1789 user_assert(ppRenderTarget
, D3DERR_INVALIDCALL
);
1791 *ppRenderTarget
= (IDirect3DSurface9
*)This
->state
.rt
[i
];
1792 if (!This
->state
.rt
[i
])
1793 return D3DERR_NOTFOUND
;
1795 NineUnknown_AddRef(NineUnknown(This
->state
.rt
[i
]));
1800 NineDevice9_SetDepthStencilSurface( struct NineDevice9
*This
,
1801 IDirect3DSurface9
*pNewZStencil
)
1803 DBG("This=%p pNewZStencil=%p\n", This
, pNewZStencil
);
1805 if (This
->state
.ds
!= NineSurface9(pNewZStencil
)) {
1806 nine_bind(&This
->state
.ds
, pNewZStencil
);
1807 This
->state
.changed
.group
|= NINE_STATE_FB
;
1813 NineDevice9_GetDepthStencilSurface( struct NineDevice9
*This
,
1814 IDirect3DSurface9
**ppZStencilSurface
)
1816 user_assert(ppZStencilSurface
, D3DERR_INVALIDCALL
);
1818 *ppZStencilSurface
= (IDirect3DSurface9
*)This
->state
.ds
;
1819 if (!This
->state
.ds
)
1820 return D3DERR_NOTFOUND
;
1822 NineUnknown_AddRef(NineUnknown(This
->state
.ds
));
1827 NineDevice9_BeginScene( struct NineDevice9
*This
)
1829 DBG("This=%p\n", This
);
1830 user_assert(!This
->in_scene
, D3DERR_INVALIDCALL
);
1831 This
->in_scene
= TRUE
;
1832 /* Do we want to do anything else here ? */
1837 NineDevice9_EndScene( struct NineDevice9
*This
)
1839 DBG("This=%p\n", This
);
1840 user_assert(This
->in_scene
, D3DERR_INVALIDCALL
);
1841 This
->in_scene
= FALSE
;
1846 NineDevice9_Clear( struct NineDevice9
*This
,
1848 const D3DRECT
*pRects
,
1854 const int sRGB
= This
->state
.rs
[D3DRS_SRGBWRITEENABLE
] ? 1 : 0;
1855 struct pipe_surface
*cbuf
, *zsbuf
;
1856 struct pipe_context
*pipe
= This
->pipe
;
1857 struct NineSurface9
*zsbuf_surf
= This
->state
.ds
;
1858 struct NineSurface9
*rt
;
1861 union pipe_color_union rgba
;
1862 unsigned rt_mask
= 0;
1865 DBG("This=%p Count=%u pRects=%p Flags=%x Color=%08x Z=%f Stencil=%x\n",
1866 This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1868 user_assert(This
->state
.ds
|| !(Flags
& NINED3DCLEAR_DEPTHSTENCIL
),
1869 D3DERR_INVALIDCALL
);
1870 user_assert(!(Flags
& D3DCLEAR_STENCIL
) ||
1872 util_format_is_depth_and_stencil(zsbuf_surf
->base
.info
.format
)),
1873 D3DERR_INVALIDCALL
);
1875 user_assert((Count
&& pRects
) || (!Count
&& !pRects
), D3DERR_INVALIDCALL
);
1877 user_warn((pRects
&& !Count
) || (!pRects
&& Count
));
1878 if (pRects
&& !Count
)
1884 if (Flags
& D3DCLEAR_TARGET
) bufs
|= PIPE_CLEAR_COLOR
;
1885 if (Flags
& D3DCLEAR_ZBUFFER
) bufs
|= PIPE_CLEAR_DEPTH
;
1886 if (Flags
& D3DCLEAR_STENCIL
) bufs
|= PIPE_CLEAR_STENCIL
;
1889 d3dcolor_to_pipe_color_union(&rgba
, Color
);
1891 nine_update_state_framebuffer(This
);
1893 rect
.x1
= This
->state
.viewport
.X
;
1894 rect
.y1
= This
->state
.viewport
.Y
;
1895 rect
.x2
= This
->state
.viewport
.Width
+ rect
.x1
;
1896 rect
.y2
= This
->state
.viewport
.Height
+ rect
.y1
;
1898 /* Both rectangles apply, which is weird, but that's D3D9. */
1899 if (This
->state
.rs
[D3DRS_SCISSORTESTENABLE
]) {
1900 rect
.x1
= MAX2(rect
.x1
, This
->state
.scissor
.minx
);
1901 rect
.y1
= MAX2(rect
.y1
, This
->state
.scissor
.miny
);
1902 rect
.x2
= MIN2(rect
.x2
, This
->state
.scissor
.maxx
);
1903 rect
.y2
= MIN2(rect
.y2
, This
->state
.scissor
.maxy
);
1907 /* Maybe apps like to specify a large rect ? */
1908 if (pRects
[0].x1
<= rect
.x1
&& pRects
[0].x2
>= rect
.x2
&&
1909 pRects
[0].y1
<= rect
.y1
&& pRects
[0].y2
>= rect
.y2
) {
1910 DBG("First rect covers viewport.\n");
1916 if (rect
.x1
>= This
->state
.fb
.width
|| rect
.y1
>= This
->state
.fb
.height
)
1919 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
1920 if (This
->state
.rt
[i
] && This
->state
.rt
[i
]->desc
.Format
!= D3DFMT_NULL
)
1924 /* fast path, clears everything at once */
1926 (!(bufs
& PIPE_CLEAR_COLOR
) || (rt_mask
== This
->state
.rt_mask
)) &&
1927 rect
.x1
== 0 && rect
.y1
== 0 &&
1928 /* Case we clear only render target. Check clear region vs rt. */
1929 ((!(bufs
& (PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
)) &&
1930 rect
.x2
>= This
->state
.fb
.width
&&
1931 rect
.y2
>= This
->state
.fb
.height
) ||
1932 /* Case we clear depth buffer (and eventually rt too).
1933 * depth buffer size is always >= rt size. Compare to clear region */
1934 ((bufs
& (PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
)) &&
1935 This
->state
.fb
.zsbuf
!= NULL
&&
1936 rect
.x2
>= zsbuf_surf
->desc
.Width
&&
1937 rect
.y2
>= zsbuf_surf
->desc
.Height
))) {
1938 DBG("Clear fast path\n");
1939 pipe
->clear(pipe
, bufs
, &rgba
, Z
, Stencil
);
1948 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
1949 rt
= This
->state
.rt
[i
];
1950 if (!rt
|| rt
->desc
.Format
== D3DFMT_NULL
||
1951 !(Flags
& D3DCLEAR_TARGET
))
1952 continue; /* save space, compiler should hoist this */
1953 cbuf
= NineSurface9_GetSurface(rt
, sRGB
);
1954 for (r
= 0; r
< Count
; ++r
) {
1955 /* Don't trust users to pass these in the right order. */
1956 unsigned x1
= MIN2(pRects
[r
].x1
, pRects
[r
].x2
);
1957 unsigned y1
= MIN2(pRects
[r
].y1
, pRects
[r
].y2
);
1958 unsigned x2
= MAX2(pRects
[r
].x1
, pRects
[r
].x2
);
1959 unsigned y2
= MAX2(pRects
[r
].y1
, pRects
[r
].y2
);
1961 /* Drop negative rectangles (like wine expects). */
1962 if (pRects
[r
].x1
> pRects
[r
].x2
) continue;
1963 if (pRects
[r
].y1
> pRects
[r
].y2
) continue;
1966 x1
= MAX2(x1
, rect
.x1
);
1967 y1
= MAX2(y1
, rect
.y1
);
1968 x2
= MIN3(x2
, rect
.x2
, rt
->desc
.Width
);
1969 y2
= MIN3(y2
, rect
.y2
, rt
->desc
.Height
);
1971 DBG("Clearing (%u..%u)x(%u..%u)\n", x1
, x2
, y1
, y2
);
1972 pipe
->clear_render_target(pipe
, cbuf
, &rgba
,
1973 x1
, y1
, x2
- x1
, y2
- y1
);
1976 if (!(Flags
& NINED3DCLEAR_DEPTHSTENCIL
))
1979 bufs
&= PIPE_CLEAR_DEPTHSTENCIL
;
1981 for (r
= 0; r
< Count
; ++r
) {
1982 unsigned x1
= MIN2(pRects
[r
].x1
, pRects
[r
].x2
);
1983 unsigned y1
= MIN2(pRects
[r
].y1
, pRects
[r
].y2
);
1984 unsigned x2
= MAX2(pRects
[r
].x1
, pRects
[r
].x2
);
1985 unsigned y2
= MAX2(pRects
[r
].y1
, pRects
[r
].y2
);
1987 /* Drop negative rectangles. */
1988 if (pRects
[r
].x1
> pRects
[r
].x2
) continue;
1989 if (pRects
[r
].y1
> pRects
[r
].y2
) continue;
1992 x1
= MIN2(x1
, rect
.x1
);
1993 y1
= MIN2(y1
, rect
.y1
);
1994 x2
= MIN3(x2
, rect
.x2
, zsbuf_surf
->desc
.Width
);
1995 y2
= MIN3(y2
, rect
.y2
, zsbuf_surf
->desc
.Height
);
1997 zsbuf
= NineSurface9_GetSurface(zsbuf_surf
, 0);
1999 pipe
->clear_depth_stencil(pipe
, zsbuf
, bufs
, Z
, Stencil
,
2000 x1
, y1
, x2
- x1
, y2
- y1
);
2006 NineDevice9_SetTransform( struct NineDevice9
*This
,
2007 D3DTRANSFORMSTATETYPE State
,
2008 const D3DMATRIX
*pMatrix
)
2010 struct nine_state
*state
= This
->update
;
2011 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
2013 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2015 user_assert(M
, D3DERR_INVALIDCALL
);
2018 state
->ff
.changed
.transform
[State
/ 32] |= 1 << (State
% 32);
2019 state
->changed
.group
|= NINE_STATE_FF
;
2025 NineDevice9_GetTransform( struct NineDevice9
*This
,
2026 D3DTRANSFORMSTATETYPE State
,
2027 D3DMATRIX
*pMatrix
)
2029 D3DMATRIX
*M
= nine_state_access_transform(&This
->state
, State
, FALSE
);
2030 user_assert(M
, D3DERR_INVALIDCALL
);
2036 NineDevice9_MultiplyTransform( struct NineDevice9
*This
,
2037 D3DTRANSFORMSTATETYPE State
,
2038 const D3DMATRIX
*pMatrix
)
2040 struct nine_state
*state
= This
->update
;
2042 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
2044 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2046 user_assert(M
, D3DERR_INVALIDCALL
);
2048 nine_d3d_matrix_matrix_mul(&T
, pMatrix
, M
);
2049 return NineDevice9_SetTransform(This
, State
, &T
);
2053 NineDevice9_SetViewport( struct NineDevice9
*This
,
2054 const D3DVIEWPORT9
*pViewport
)
2056 struct nine_state
*state
= This
->update
;
2058 DBG("X=%u Y=%u W=%u H=%u MinZ=%f MaxZ=%f\n",
2059 pViewport
->X
, pViewport
->Y
, pViewport
->Width
, pViewport
->Height
,
2060 pViewport
->MinZ
, pViewport
->MaxZ
);
2062 state
->viewport
= *pViewport
;
2063 state
->changed
.group
|= NINE_STATE_VIEWPORT
;
2069 NineDevice9_GetViewport( struct NineDevice9
*This
,
2070 D3DVIEWPORT9
*pViewport
)
2072 *pViewport
= This
->state
.viewport
;
2077 NineDevice9_SetMaterial( struct NineDevice9
*This
,
2078 const D3DMATERIAL9
*pMaterial
)
2080 struct nine_state
*state
= This
->update
;
2082 DBG("This=%p pMaterial=%p\n", This
, pMaterial
);
2084 nine_dump_D3DMATERIAL9(DBG_FF
, pMaterial
);
2086 user_assert(pMaterial
, E_POINTER
);
2088 state
->ff
.material
= *pMaterial
;
2089 state
->changed
.group
|= NINE_STATE_FF_MATERIAL
;
2095 NineDevice9_GetMaterial( struct NineDevice9
*This
,
2096 D3DMATERIAL9
*pMaterial
)
2098 user_assert(pMaterial
, E_POINTER
);
2099 *pMaterial
= This
->state
.ff
.material
;
2104 NineDevice9_SetLight( struct NineDevice9
*This
,
2106 const D3DLIGHT9
*pLight
)
2108 struct nine_state
*state
= This
->update
;
2110 DBG("This=%p Index=%u pLight=%p\n", This
, Index
, pLight
);
2112 nine_dump_D3DLIGHT9(DBG_FF
, pLight
);
2114 user_assert(pLight
, D3DERR_INVALIDCALL
);
2115 user_assert(pLight
->Type
< NINED3DLIGHT_INVALID
, D3DERR_INVALIDCALL
);
2117 user_assert(Index
< NINE_MAX_LIGHTS
, D3DERR_INVALIDCALL
); /* sanity */
2119 if (Index
>= state
->ff
.num_lights
) {
2120 unsigned n
= state
->ff
.num_lights
;
2121 unsigned N
= Index
+ 1;
2123 state
->ff
.light
= REALLOC(state
->ff
.light
, n
* sizeof(D3DLIGHT9
),
2124 N
* sizeof(D3DLIGHT9
));
2125 if (!state
->ff
.light
)
2126 return E_OUTOFMEMORY
;
2127 state
->ff
.num_lights
= N
;
2129 for (; n
< Index
; ++n
) {
2130 memset(&state
->ff
.light
[n
], 0, sizeof(D3DLIGHT9
));
2131 state
->ff
.light
[n
].Type
= (D3DLIGHTTYPE
)NINED3DLIGHT_INVALID
;
2134 state
->ff
.light
[Index
] = *pLight
;
2136 if (pLight
->Type
== D3DLIGHT_SPOT
&& pLight
->Theta
>= pLight
->Phi
) {
2137 DBG("Warning: clamping D3DLIGHT9.Theta\n");
2138 state
->ff
.light
[Index
].Theta
= state
->ff
.light
[Index
].Phi
;
2140 if (pLight
->Type
!= D3DLIGHT_DIRECTIONAL
&&
2141 pLight
->Attenuation0
== 0.0f
&&
2142 pLight
->Attenuation1
== 0.0f
&&
2143 pLight
->Attenuation2
== 0.0f
) {
2144 DBG("Warning: all D3DLIGHT9.Attenuation[i] are 0\n");
2147 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2153 NineDevice9_GetLight( struct NineDevice9
*This
,
2157 const struct nine_state
*state
= &This
->state
;
2159 user_assert(pLight
, D3DERR_INVALIDCALL
);
2160 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2161 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2162 D3DERR_INVALIDCALL
);
2164 *pLight
= state
->ff
.light
[Index
];
2170 NineDevice9_LightEnable( struct NineDevice9
*This
,
2174 struct nine_state
*state
= This
->update
;
2177 DBG("This=%p Index=%u Enable=%i\n", This
, Index
, Enable
);
2179 if (Index
>= state
->ff
.num_lights
||
2180 state
->ff
.light
[Index
].Type
== NINED3DLIGHT_INVALID
) {
2181 /* This should create a default light. */
2183 memset(&light
, 0, sizeof(light
));
2184 light
.Type
= D3DLIGHT_DIRECTIONAL
;
2185 light
.Diffuse
.r
= 1.0f
;
2186 light
.Diffuse
.g
= 1.0f
;
2187 light
.Diffuse
.b
= 1.0f
;
2188 light
.Direction
.z
= 1.0f
;
2189 NineDevice9_SetLight(This
, Index
, &light
);
2191 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2193 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
) {
2194 if (state
->ff
.active_light
[i
] == Index
)
2199 if (i
< state
->ff
.num_lights_active
)
2201 /* XXX wine thinks this should still succeed:
2203 user_assert(i
< NINE_MAX_LIGHTS_ACTIVE
, D3DERR_INVALIDCALL
);
2205 state
->ff
.active_light
[i
] = Index
;
2206 state
->ff
.num_lights_active
++;
2208 if (i
== state
->ff
.num_lights_active
)
2210 --state
->ff
.num_lights_active
;
2211 for (; i
< state
->ff
.num_lights_active
; ++i
)
2212 state
->ff
.active_light
[i
] = state
->ff
.active_light
[i
+ 1];
2214 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2220 NineDevice9_GetLightEnable( struct NineDevice9
*This
,
2224 const struct nine_state
*state
= &This
->state
;
2227 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2228 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2229 D3DERR_INVALIDCALL
);
2231 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
)
2232 if (state
->ff
.active_light
[i
] == Index
)
2235 *pEnable
= i
!= state
->ff
.num_lights_active
? 128 : 0; // Taken from wine
2241 NineDevice9_SetClipPlane( struct NineDevice9
*This
,
2243 const float *pPlane
)
2245 struct nine_state
*state
= This
->update
;
2247 user_assert(pPlane
, D3DERR_INVALIDCALL
);
2249 DBG("This=%p Index=%u pPlane=%f %f %f %f\n", This
, Index
,
2250 pPlane
[0], pPlane
[1],
2251 pPlane
[2], pPlane
[3]);
2253 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2255 memcpy(&state
->clip
.ucp
[Index
][0], pPlane
, sizeof(state
->clip
.ucp
[0]));
2256 state
->changed
.ucp
|= 1 << Index
;
2262 NineDevice9_GetClipPlane( struct NineDevice9
*This
,
2266 const struct nine_state
*state
= &This
->state
;
2268 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2270 memcpy(pPlane
, &state
->clip
.ucp
[Index
][0], sizeof(state
->clip
.ucp
[0]));
2274 #define RESZ_CODE 0x7fa05000
2277 NineDevice9_ResolveZ( struct NineDevice9
*This
)
2279 struct nine_state
*state
= &This
->state
;
2280 const struct util_format_description
*desc
;
2281 struct NineSurface9
*source
= state
->ds
;
2282 struct NineBaseTexture9
*destination
= state
->texture
[0];
2283 struct pipe_resource
*src
, *dst
;
2284 struct pipe_blit_info blit
;
2286 DBG("RESZ resolve\n");
2288 user_assert(source
&& destination
&&
2289 destination
->base
.type
== D3DRTYPE_TEXTURE
, D3DERR_INVALIDCALL
);
2291 src
= source
->base
.resource
;
2292 dst
= destination
->base
.resource
;
2294 user_assert(src
&& dst
, D3DERR_INVALIDCALL
);
2296 /* check dst is depth format. we know already for src */
2297 desc
= util_format_description(dst
->format
);
2298 user_assert(desc
->colorspace
== UTIL_FORMAT_COLORSPACE_ZS
, D3DERR_INVALIDCALL
);
2300 memset(&blit
, 0, sizeof(blit
));
2301 blit
.src
.resource
= src
;
2303 blit
.src
.format
= src
->format
;
2305 blit
.src
.box
.depth
= 1;
2308 blit
.src
.box
.width
= src
->width0
;
2309 blit
.src
.box
.height
= src
->height0
;
2311 blit
.dst
.resource
= dst
;
2313 blit
.dst
.format
= dst
->format
;
2315 blit
.dst
.box
.depth
= 1;
2318 blit
.dst
.box
.width
= dst
->width0
;
2319 blit
.dst
.box
.height
= dst
->height0
;
2321 blit
.mask
= PIPE_MASK_ZS
;
2322 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
2323 blit
.scissor_enable
= FALSE
;
2325 This
->pipe
->blit(This
->pipe
, &blit
);
2329 #define ALPHA_TO_COVERAGE_ENABLE MAKEFOURCC('A', '2', 'M', '1')
2330 #define ALPHA_TO_COVERAGE_DISABLE MAKEFOURCC('A', '2', 'M', '0')
2333 NineDevice9_SetRenderState( struct NineDevice9
*This
,
2334 D3DRENDERSTATETYPE State
,
2337 struct nine_state
*state
= This
->update
;
2339 DBG("This=%p State=%u(%s) Value=%08x\n", This
,
2340 State
, nine_d3drs_to_string(State
), Value
);
2342 /* Amd hacks (equivalent to GL extensions) */
2343 if (State
== D3DRS_POINTSIZE
) {
2344 if (Value
== RESZ_CODE
)
2345 return NineDevice9_ResolveZ(This
);
2347 if (Value
== ALPHA_TO_COVERAGE_ENABLE
||
2348 Value
== ALPHA_TO_COVERAGE_DISABLE
) {
2349 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
== ALPHA_TO_COVERAGE_ENABLE
);
2350 state
->changed
.group
|= NINE_STATE_BLEND
;
2356 if (State
== D3DRS_ADAPTIVETESS_Y
&&
2357 (Value
== D3DFMT_ATOC
|| (Value
== D3DFMT_UNKNOWN
&& state
->rs
[NINED3DRS_ALPHACOVERAGE
]))) {
2358 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
== D3DFMT_ATOC
);
2359 state
->changed
.group
|= NINE_STATE_BLEND
;
2363 user_assert(State
< Elements(state
->rs
), D3DERR_INVALIDCALL
);
2365 if (likely(state
->rs
[State
] != Value
) || unlikely(This
->is_recording
)) {
2366 state
->rs
[State
] = Value
;
2367 state
->changed
.rs
[State
/ 32] |= 1 << (State
% 32);
2368 state
->changed
.group
|= nine_render_state_group
[State
];
2375 NineDevice9_GetRenderState( struct NineDevice9
*This
,
2376 D3DRENDERSTATETYPE State
,
2379 user_assert(State
< Elements(This
->state
.rs
), D3DERR_INVALIDCALL
);
2381 *pValue
= This
->state
.rs
[State
];
2386 NineDevice9_CreateStateBlock( struct NineDevice9
*This
,
2387 D3DSTATEBLOCKTYPE Type
,
2388 IDirect3DStateBlock9
**ppSB
)
2390 struct NineStateBlock9
*nsb
;
2391 struct nine_state
*dst
;
2393 enum nine_stateblock_type type
;
2396 DBG("This=%p Type=%u ppSB=%p\n", This
, Type
, ppSB
);
2398 user_assert(Type
== D3DSBT_ALL
||
2399 Type
== D3DSBT_VERTEXSTATE
||
2400 Type
== D3DSBT_PIXELSTATE
, D3DERR_INVALIDCALL
);
2403 case D3DSBT_VERTEXSTATE
: type
= NINESBT_VERTEXSTATE
; break;
2404 case D3DSBT_PIXELSTATE
: type
= NINESBT_PIXELSTATE
; break;
2410 hr
= NineStateBlock9_new(This
, &nsb
, type
);
2413 *ppSB
= (IDirect3DStateBlock9
*)nsb
;
2416 dst
->changed
.group
=
2417 NINE_STATE_TEXTURE
|
2420 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_VERTEXSTATE
) {
2421 dst
->changed
.group
|=
2422 NINE_STATE_FF_LIGHTING
|
2423 NINE_STATE_VS
| NINE_STATE_VS_CONST
|
2425 /* TODO: texture/sampler state */
2426 memcpy(dst
->changed
.rs
,
2427 nine_render_states_vertex
, sizeof(dst
->changed
.rs
));
2428 nine_ranges_insert(&dst
->changed
.vs_const_f
, 0, This
->max_vs_const_f
,
2430 dst
->changed
.vs_const_i
= 0xffff;
2431 dst
->changed
.vs_const_b
= 0xffff;
2432 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2433 dst
->changed
.sampler
[s
] |= 1 << D3DSAMP_DMAPOFFSET
;
2434 if (This
->state
.ff
.num_lights
) {
2435 dst
->ff
.num_lights
= This
->state
.ff
.num_lights
;
2436 /* zero'd -> light type won't be NINED3DLIGHT_INVALID, so
2437 * all currently existing lights will be captured
2439 dst
->ff
.light
= CALLOC(This
->state
.ff
.num_lights
,
2441 if (!dst
->ff
.light
) {
2442 nine_bind(ppSB
, NULL
);
2443 return E_OUTOFMEMORY
;
2447 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_PIXELSTATE
) {
2448 dst
->changed
.group
|=
2449 NINE_STATE_PS
| NINE_STATE_PS_CONST
;
2450 /* TODO: texture/sampler state */
2451 memcpy(dst
->changed
.rs
,
2452 nine_render_states_pixel
, sizeof(dst
->changed
.rs
));
2453 nine_ranges_insert(&dst
->changed
.ps_const_f
, 0, This
->max_ps_const_f
,
2455 dst
->changed
.ps_const_i
= 0xffff;
2456 dst
->changed
.ps_const_b
= 0xffff;
2457 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2458 dst
->changed
.sampler
[s
] |= 0x1ffe;
2460 if (Type
== D3DSBT_ALL
) {
2461 dst
->changed
.group
|=
2462 NINE_STATE_VIEWPORT
|
2463 NINE_STATE_SCISSOR
|
2464 NINE_STATE_RASTERIZER
|
2468 NINE_STATE_MATERIAL
|
2469 NINE_STATE_BLEND_COLOR
|
2470 NINE_STATE_SAMPLE_MASK
;
2471 memset(dst
->changed
.rs
, ~0, (D3DRS_COUNT
/ 32) * sizeof(uint32_t));
2472 dst
->changed
.rs
[D3DRS_LAST
/ 32] |= (1 << (D3DRS_COUNT
% 32)) - 1;
2473 dst
->changed
.vtxbuf
= (1ULL << This
->caps
.MaxStreams
) - 1;
2474 dst
->changed
.stream_freq
= dst
->changed
.vtxbuf
;
2475 dst
->changed
.ucp
= (1 << PIPE_MAX_CLIP_PLANES
) - 1;
2476 dst
->changed
.texture
= (1 << NINE_MAX_SAMPLERS
) - 1;
2478 NineStateBlock9_Capture(NineStateBlock9(*ppSB
));
2480 /* TODO: fixed function state */
2486 NineDevice9_BeginStateBlock( struct NineDevice9
*This
)
2490 DBG("This=%p\n", This
);
2492 user_assert(!This
->record
, D3DERR_INVALIDCALL
);
2494 hr
= NineStateBlock9_new(This
, &This
->record
, NINESBT_CUSTOM
);
2497 NineUnknown_ConvertRefToBind(NineUnknown(This
->record
));
2499 This
->update
= &This
->record
->state
;
2500 This
->is_recording
= TRUE
;
2506 NineDevice9_EndStateBlock( struct NineDevice9
*This
,
2507 IDirect3DStateBlock9
**ppSB
)
2509 DBG("This=%p ppSB=%p\n", This
, ppSB
);
2511 user_assert(This
->record
, D3DERR_INVALIDCALL
);
2513 This
->update
= &This
->state
;
2514 This
->is_recording
= FALSE
;
2516 NineUnknown_AddRef(NineUnknown(This
->record
));
2517 *ppSB
= (IDirect3DStateBlock9
*)This
->record
;
2518 NineUnknown_Unbind(NineUnknown(This
->record
));
2519 This
->record
= NULL
;
2525 NineDevice9_SetClipStatus( struct NineDevice9
*This
,
2526 const D3DCLIPSTATUS9
*pClipStatus
)
2528 STUB(D3DERR_INVALIDCALL
);
2532 NineDevice9_GetClipStatus( struct NineDevice9
*This
,
2533 D3DCLIPSTATUS9
*pClipStatus
)
2535 STUB(D3DERR_INVALIDCALL
);
2539 NineDevice9_GetTexture( struct NineDevice9
*This
,
2541 IDirect3DBaseTexture9
**ppTexture
)
2543 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2544 Stage
== D3DDMAPSAMPLER
||
2545 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2546 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2547 user_assert(ppTexture
, D3DERR_INVALIDCALL
);
2549 if (Stage
>= D3DDMAPSAMPLER
)
2550 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2552 *ppTexture
= (IDirect3DBaseTexture9
*)This
->state
.texture
[Stage
];
2554 if (This
->state
.texture
[Stage
])
2555 NineUnknown_AddRef(NineUnknown(This
->state
.texture
[Stage
]));
2560 NineDevice9_SetTexture( struct NineDevice9
*This
,
2562 IDirect3DBaseTexture9
*pTexture
)
2564 struct nine_state
*state
= This
->update
;
2565 struct NineBaseTexture9
*tex
= NineBaseTexture9(pTexture
);
2567 DBG("This=%p Stage=%u pTexture=%p\n", This
, Stage
, pTexture
);
2569 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2570 Stage
== D3DDMAPSAMPLER
||
2571 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2572 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2573 user_assert(!tex
|| (tex
->base
.pool
!= D3DPOOL_SCRATCH
&&
2574 tex
->base
.pool
!= D3DPOOL_SYSTEMMEM
), D3DERR_INVALIDCALL
);
2576 if (Stage
>= D3DDMAPSAMPLER
)
2577 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2579 if (!This
->is_recording
) {
2580 struct NineBaseTexture9
*old
= state
->texture
[Stage
];
2584 state
->samplers_shadow
&= ~(1 << Stage
);
2586 state
->samplers_shadow
|= tex
->shadow
<< Stage
;
2588 if ((tex
->managed
.dirty
| tex
->dirty_mip
) && LIST_IS_EMPTY(&tex
->list
))
2589 list_add(&tex
->list
, &This
->update_textures
);
2596 nine_bind(&state
->texture
[Stage
], pTexture
);
2598 state
->changed
.texture
|= 1 << Stage
;
2599 state
->changed
.group
|= NINE_STATE_TEXTURE
;
2605 NineDevice9_GetTextureStageState( struct NineDevice9
*This
,
2607 D3DTEXTURESTAGESTATETYPE Type
,
2610 const struct nine_state
*state
= &This
->state
;
2612 user_assert(Stage
< Elements(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2613 user_assert(Type
< Elements(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2615 *pValue
= state
->ff
.tex_stage
[Stage
][Type
];
2621 NineDevice9_SetTextureStageState( struct NineDevice9
*This
,
2623 D3DTEXTURESTAGESTATETYPE Type
,
2626 struct nine_state
*state
= This
->update
;
2627 int bumpmap_index
= -1;
2629 DBG("Stage=%u Type=%u Value=%08x\n", Stage
, Type
, Value
);
2630 nine_dump_D3DTSS_value(DBG_FF
, Type
, Value
);
2632 user_assert(Stage
< Elements(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2633 user_assert(Type
< Elements(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2635 state
->ff
.tex_stage
[Stage
][Type
] = Value
;
2637 case D3DTSS_BUMPENVMAT00
:
2638 bumpmap_index
= 4 * Stage
;
2640 case D3DTSS_BUMPENVMAT10
:
2641 bumpmap_index
= 4 * Stage
+ 1;
2643 case D3DTSS_BUMPENVMAT01
:
2644 bumpmap_index
= 4 * Stage
+ 2;
2646 case D3DTSS_BUMPENVMAT11
:
2647 bumpmap_index
= 4 * Stage
+ 3;
2649 case D3DTSS_BUMPENVLSCALE
:
2650 bumpmap_index
= 4 * 8 + 2 * Stage
;
2652 case D3DTSS_BUMPENVLOFFSET
:
2653 bumpmap_index
= 4 * 8 + 2 * Stage
+ 1;
2655 case D3DTSS_TEXTURETRANSFORMFLAGS
:
2656 state
->changed
.group
|= NINE_STATE_PS1X_SHADER
;
2662 if (bumpmap_index
>= 0) {
2663 state
->bumpmap_vars
[bumpmap_index
] = Value
;
2664 state
->changed
.group
|= NINE_STATE_PS_CONST
;
2667 state
->changed
.group
|= NINE_STATE_FF_PSSTAGES
;
2668 state
->ff
.changed
.tex_stage
[Stage
][Type
/ 32] |= 1 << (Type
% 32);
2674 NineDevice9_GetSamplerState( struct NineDevice9
*This
,
2676 D3DSAMPLERSTATETYPE Type
,
2679 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2680 Sampler
== D3DDMAPSAMPLER
||
2681 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2682 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2684 if (Sampler
>= D3DDMAPSAMPLER
)
2685 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2687 *pValue
= This
->state
.samp
[Sampler
][Type
];
2692 NineDevice9_SetSamplerState( struct NineDevice9
*This
,
2694 D3DSAMPLERSTATETYPE Type
,
2697 struct nine_state
*state
= This
->update
;
2699 DBG("This=%p Sampler=%u Type=%s Value=%08x\n", This
,
2700 Sampler
, nine_D3DSAMP_to_str(Type
), Value
);
2702 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2703 Sampler
== D3DDMAPSAMPLER
||
2704 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2705 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2707 if (Sampler
>= D3DDMAPSAMPLER
)
2708 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2710 if (state
->samp
[Sampler
][Type
] != Value
|| unlikely(This
->is_recording
)) {
2711 state
->samp
[Sampler
][Type
] = Value
;
2712 state
->changed
.group
|= NINE_STATE_SAMPLER
;
2713 state
->changed
.sampler
[Sampler
] |= 1 << Type
;
2720 NineDevice9_ValidateDevice( struct NineDevice9
*This
,
2723 const struct nine_state
*state
= &This
->state
;
2725 unsigned w
= 0, h
= 0;
2727 DBG("This=%p pNumPasses=%p\n", This
, pNumPasses
);
2729 for (i
= 0; i
< Elements(state
->samp
); ++i
) {
2730 if (state
->samp
[i
][D3DSAMP_MINFILTER
] == D3DTEXF_NONE
||
2731 state
->samp
[i
][D3DSAMP_MAGFILTER
] == D3DTEXF_NONE
)
2732 return D3DERR_UNSUPPORTEDTEXTUREFILTER
;
2735 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2739 w
= state
->rt
[i
]->desc
.Width
;
2740 h
= state
->rt
[i
]->desc
.Height
;
2742 if (state
->rt
[i
]->desc
.Width
!= w
|| state
->rt
[i
]->desc
.Height
!= h
) {
2743 return D3DERR_CONFLICTINGRENDERSTATE
;
2747 (state
->rs
[D3DRS_ZENABLE
] || state
->rs
[D3DRS_STENCILENABLE
])) {
2749 (state
->ds
->desc
.Width
!= w
|| state
->ds
->desc
.Height
!= h
))
2750 return D3DERR_CONFLICTINGRENDERSTATE
;
2760 NineDevice9_SetPaletteEntries( struct NineDevice9
*This
,
2762 const PALETTEENTRY
*pEntries
)
2764 STUB(D3D_OK
); /* like wine */
2768 NineDevice9_GetPaletteEntries( struct NineDevice9
*This
,
2770 PALETTEENTRY
*pEntries
)
2772 STUB(D3DERR_INVALIDCALL
);
2776 NineDevice9_SetCurrentTexturePalette( struct NineDevice9
*This
,
2777 UINT PaletteNumber
)
2779 STUB(D3D_OK
); /* like wine */
2783 NineDevice9_GetCurrentTexturePalette( struct NineDevice9
*This
,
2784 UINT
*PaletteNumber
)
2786 STUB(D3DERR_INVALIDCALL
);
2790 NineDevice9_SetScissorRect( struct NineDevice9
*This
,
2793 struct nine_state
*state
= This
->update
;
2795 DBG("x=(%u..%u) y=(%u..%u)\n",
2796 pRect
->left
, pRect
->top
, pRect
->right
, pRect
->bottom
);
2798 state
->scissor
.minx
= pRect
->left
;
2799 state
->scissor
.miny
= pRect
->top
;
2800 state
->scissor
.maxx
= pRect
->right
;
2801 state
->scissor
.maxy
= pRect
->bottom
;
2803 state
->changed
.group
|= NINE_STATE_SCISSOR
;
2809 NineDevice9_GetScissorRect( struct NineDevice9
*This
,
2812 pRect
->left
= This
->state
.scissor
.minx
;
2813 pRect
->top
= This
->state
.scissor
.miny
;
2814 pRect
->right
= This
->state
.scissor
.maxx
;
2815 pRect
->bottom
= This
->state
.scissor
.maxy
;
2821 NineDevice9_SetSoftwareVertexProcessing( struct NineDevice9
*This
,
2824 STUB(D3DERR_INVALIDCALL
);
2828 NineDevice9_GetSoftwareVertexProcessing( struct NineDevice9
*This
)
2830 return !!(This
->params
.BehaviorFlags
& D3DCREATE_SOFTWARE_VERTEXPROCESSING
);
2834 NineDevice9_SetNPatchMode( struct NineDevice9
*This
,
2837 STUB(D3DERR_INVALIDCALL
);
2841 NineDevice9_GetNPatchMode( struct NineDevice9
*This
)
2847 init_draw_info(struct pipe_draw_info
*info
,
2848 struct NineDevice9
*dev
, D3DPRIMITIVETYPE type
, UINT count
)
2850 info
->mode
= d3dprimitivetype_to_pipe_prim(type
);
2851 info
->count
= prim_count_to_vertex_count(type
, count
);
2852 info
->start_instance
= 0;
2853 info
->instance_count
= 1;
2854 if (dev
->state
.stream_instancedata_mask
& dev
->state
.stream_usage_mask
)
2855 info
->instance_count
= MAX2(dev
->state
.stream_freq
[0] & 0x7FFFFF, 1);
2856 info
->primitive_restart
= FALSE
;
2857 info
->restart_index
= 0;
2858 info
->count_from_stream_output
= NULL
;
2859 info
->indirect
= NULL
;
2863 NineDevice9_DrawPrimitive( struct NineDevice9
*This
,
2864 D3DPRIMITIVETYPE PrimitiveType
,
2866 UINT PrimitiveCount
)
2868 struct pipe_draw_info info
;
2870 DBG("iface %p, PrimitiveType %u, StartVertex %u, PrimitiveCount %u\n",
2871 This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2873 nine_update_state(This
);
2875 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2876 info
.indexed
= FALSE
;
2877 info
.start
= StartVertex
;
2878 info
.index_bias
= 0;
2879 info
.min_index
= info
.start
;
2880 info
.max_index
= info
.count
- 1;
2882 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2888 NineDevice9_DrawIndexedPrimitive( struct NineDevice9
*This
,
2889 D3DPRIMITIVETYPE PrimitiveType
,
2890 INT BaseVertexIndex
,
2891 UINT MinVertexIndex
,
2894 UINT PrimitiveCount
)
2896 struct pipe_draw_info info
;
2898 DBG("iface %p, PrimitiveType %u, BaseVertexIndex %u, MinVertexIndex %u "
2899 "NumVertices %u, StartIndex %u, PrimitiveCount %u\n",
2900 This
, PrimitiveType
, BaseVertexIndex
, MinVertexIndex
, NumVertices
,
2901 StartIndex
, PrimitiveCount
);
2903 user_assert(This
->state
.idxbuf
, D3DERR_INVALIDCALL
);
2904 user_assert(This
->state
.vdecl
, D3DERR_INVALIDCALL
);
2906 nine_update_state(This
);
2908 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2909 info
.indexed
= TRUE
;
2910 info
.start
= StartIndex
;
2911 info
.index_bias
= BaseVertexIndex
;
2912 /* These don't include index bias: */
2913 info
.min_index
= MinVertexIndex
;
2914 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
2916 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2922 NineDevice9_DrawPrimitiveUP( struct NineDevice9
*This
,
2923 D3DPRIMITIVETYPE PrimitiveType
,
2924 UINT PrimitiveCount
,
2925 const void *pVertexStreamZeroData
,
2926 UINT VertexStreamZeroStride
)
2928 struct pipe_vertex_buffer vtxbuf
;
2929 struct pipe_draw_info info
;
2931 DBG("iface %p, PrimitiveType %u, PrimitiveCount %u, data %p, stride %u\n",
2932 This
, PrimitiveType
, PrimitiveCount
,
2933 pVertexStreamZeroData
, VertexStreamZeroStride
);
2935 user_assert(pVertexStreamZeroData
&& VertexStreamZeroStride
,
2936 D3DERR_INVALIDCALL
);
2938 nine_update_state(This
);
2940 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2941 info
.indexed
= FALSE
;
2943 info
.index_bias
= 0;
2945 info
.max_index
= info
.count
- 1;
2947 vtxbuf
.stride
= VertexStreamZeroStride
;
2948 vtxbuf
.buffer_offset
= 0;
2949 vtxbuf
.buffer
= NULL
;
2950 vtxbuf
.user_buffer
= pVertexStreamZeroData
;
2952 if (!This
->driver_caps
.user_vbufs
) {
2953 u_upload_data(This
->vertex_uploader
,
2955 (info
.max_index
+ 1) * VertexStreamZeroStride
, /* XXX */
2957 &vtxbuf
.buffer_offset
,
2959 u_upload_unmap(This
->vertex_uploader
);
2960 vtxbuf
.user_buffer
= NULL
;
2963 This
->pipe
->set_vertex_buffers(This
->pipe
, 0, 1, &vtxbuf
);
2965 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2967 NineDevice9_PauseRecording(This
);
2968 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
2969 NineDevice9_ResumeRecording(This
);
2971 pipe_resource_reference(&vtxbuf
.buffer
, NULL
);
2977 NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9
*This
,
2978 D3DPRIMITIVETYPE PrimitiveType
,
2979 UINT MinVertexIndex
,
2981 UINT PrimitiveCount
,
2982 const void *pIndexData
,
2983 D3DFORMAT IndexDataFormat
,
2984 const void *pVertexStreamZeroData
,
2985 UINT VertexStreamZeroStride
)
2987 struct pipe_draw_info info
;
2988 struct pipe_vertex_buffer vbuf
;
2989 struct pipe_index_buffer ibuf
;
2991 DBG("iface %p, PrimitiveType %u, MinVertexIndex %u, NumVertices %u "
2992 "PrimitiveCount %u, pIndexData %p, IndexDataFormat %u "
2993 "pVertexStreamZeroData %p, VertexStreamZeroStride %u\n",
2994 This
, PrimitiveType
, MinVertexIndex
, NumVertices
, PrimitiveCount
,
2995 pIndexData
, IndexDataFormat
,
2996 pVertexStreamZeroData
, VertexStreamZeroStride
);
2998 user_assert(pIndexData
&& pVertexStreamZeroData
, D3DERR_INVALIDCALL
);
2999 user_assert(VertexStreamZeroStride
, D3DERR_INVALIDCALL
);
3000 user_assert(IndexDataFormat
== D3DFMT_INDEX16
||
3001 IndexDataFormat
== D3DFMT_INDEX32
, D3DERR_INVALIDCALL
);
3003 nine_update_state(This
);
3005 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
3006 info
.indexed
= TRUE
;
3008 info
.index_bias
= 0;
3009 info
.min_index
= MinVertexIndex
;
3010 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
3012 vbuf
.stride
= VertexStreamZeroStride
;
3013 vbuf
.buffer_offset
= 0;
3015 vbuf
.user_buffer
= pVertexStreamZeroData
;
3017 ibuf
.index_size
= (IndexDataFormat
== D3DFMT_INDEX16
) ? 2 : 4;
3020 ibuf
.user_buffer
= pIndexData
;
3022 if (!This
->driver_caps
.user_vbufs
) {
3023 const unsigned base
= info
.min_index
* VertexStreamZeroStride
;
3024 u_upload_data(This
->vertex_uploader
,
3027 info
.min_index
+ 1) * VertexStreamZeroStride
, /* XXX */
3028 (const uint8_t *)vbuf
.user_buffer
+ base
,
3029 &vbuf
.buffer_offset
,
3031 u_upload_unmap(This
->vertex_uploader
);
3032 /* Won't be used: */
3033 vbuf
.buffer_offset
-= base
;
3034 vbuf
.user_buffer
= NULL
;
3036 if (!This
->driver_caps
.user_ibufs
) {
3037 u_upload_data(This
->index_uploader
,
3039 info
.count
* ibuf
.index_size
,
3043 u_upload_unmap(This
->index_uploader
);
3044 ibuf
.user_buffer
= NULL
;
3047 This
->pipe
->set_vertex_buffers(This
->pipe
, 0, 1, &vbuf
);
3048 This
->pipe
->set_index_buffer(This
->pipe
, &ibuf
);
3050 This
->pipe
->draw_vbo(This
->pipe
, &info
);
3052 pipe_resource_reference(&vbuf
.buffer
, NULL
);
3053 pipe_resource_reference(&ibuf
.buffer
, NULL
);
3055 NineDevice9_PauseRecording(This
);
3056 NineDevice9_SetIndices(This
, NULL
);
3057 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
3058 NineDevice9_ResumeRecording(This
);
3063 /* TODO: Write to pDestBuffer directly if vertex declaration contains
3067 NineDevice9_ProcessVertices( struct NineDevice9
*This
,
3071 IDirect3DVertexBuffer9
*pDestBuffer
,
3072 IDirect3DVertexDeclaration9
*pVertexDecl
,
3075 struct pipe_screen
*screen
= This
->screen
;
3076 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pVertexDecl
);
3077 struct NineVertexShader9
*vs
;
3078 struct pipe_resource
*resource
;
3079 struct pipe_stream_output_target
*target
;
3080 struct pipe_draw_info draw
;
3082 unsigned buffer_offset
, buffer_size
;
3084 DBG("This=%p SrcStartIndex=%u DestIndex=%u VertexCount=%u "
3085 "pDestBuffer=%p pVertexDecl=%p Flags=%d\n",
3086 This
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
,
3087 pVertexDecl
, Flags
);
3089 if (!screen
->get_param(screen
, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
))
3090 STUB(D3DERR_INVALIDCALL
);
3092 nine_update_state(This
);
3094 /* TODO: Create shader with stream output. */
3095 STUB(D3DERR_INVALIDCALL
);
3096 struct NineVertexBuffer9
*dst
= NineVertexBuffer9(pDestBuffer
);
3098 vs
= This
->state
.vs
? This
->state
.vs
: This
->ff
.vs
;
3100 buffer_size
= VertexCount
* vs
->so
->stride
[0];
3102 struct pipe_resource templ
;
3104 templ
.target
= PIPE_BUFFER
;
3105 templ
.format
= PIPE_FORMAT_R8_UNORM
;
3106 templ
.width0
= buffer_size
;
3108 templ
.bind
= PIPE_BIND_STREAM_OUTPUT
;
3109 templ
.usage
= PIPE_USAGE_STREAM
;
3110 templ
.height0
= templ
.depth0
= templ
.array_size
= 1;
3111 templ
.last_level
= templ
.nr_samples
= 0;
3113 resource
= This
->screen
->resource_create(This
->screen
, &templ
);
3115 return E_OUTOFMEMORY
;
3118 /* SO matches vertex declaration */
3119 resource
= dst
->base
.resource
;
3120 buffer_offset
= DestIndex
* vs
->so
->stride
[0];
3122 target
= This
->pipe
->create_stream_output_target(This
->pipe
, resource
,
3126 pipe_resource_reference(&resource
, NULL
);
3127 return D3DERR_DRIVERINTERNALERROR
;
3131 hr
= NineVertexDeclaration9_new_from_fvf(This
, dst
->desc
.FVF
, &vdecl
);
3136 init_draw_info(&draw
, This
, D3DPT_POINTLIST
, VertexCount
);
3137 draw
.instance_count
= 1;
3138 draw
.indexed
= FALSE
;
3139 draw
.start
= SrcStartIndex
;
3140 draw
.index_bias
= 0;
3141 draw
.min_index
= SrcStartIndex
;
3142 draw
.max_index
= SrcStartIndex
+ VertexCount
- 1;
3144 This
->pipe
->set_stream_output_targets(This
->pipe
, 1, &target
, 0);
3145 This
->pipe
->draw_vbo(This
->pipe
, &draw
);
3146 This
->pipe
->set_stream_output_targets(This
->pipe
, 0, NULL
, 0);
3147 This
->pipe
->stream_output_target_destroy(This
->pipe
, target
);
3149 hr
= NineVertexDeclaration9_ConvertStreamOutput(vdecl
,
3150 dst
, DestIndex
, VertexCount
,
3153 pipe_resource_reference(&resource
, NULL
);
3155 NineUnknown_Release(NineUnknown(vdecl
));
3160 NineDevice9_CreateVertexDeclaration( struct NineDevice9
*This
,
3161 const D3DVERTEXELEMENT9
*pVertexElements
,
3162 IDirect3DVertexDeclaration9
**ppDecl
)
3164 struct NineVertexDeclaration9
*vdecl
;
3166 DBG("This=%p pVertexElements=%p ppDecl=%p\n",
3167 This
, pVertexElements
, ppDecl
);
3169 HRESULT hr
= NineVertexDeclaration9_new(This
, pVertexElements
, &vdecl
);
3171 *ppDecl
= (IDirect3DVertexDeclaration9
*)vdecl
;
3177 NineDevice9_SetVertexDeclaration( struct NineDevice9
*This
,
3178 IDirect3DVertexDeclaration9
*pDecl
)
3180 struct nine_state
*state
= This
->update
;
3182 DBG("This=%p pDecl=%p\n", This
, pDecl
);
3184 if (likely(!This
->is_recording
) && state
->vdecl
== NineVertexDeclaration9(pDecl
))
3186 nine_bind(&state
->vdecl
, pDecl
);
3188 state
->changed
.group
|= NINE_STATE_VDECL
;
3194 NineDevice9_GetVertexDeclaration( struct NineDevice9
*This
,
3195 IDirect3DVertexDeclaration9
**ppDecl
)
3197 user_assert(ppDecl
, D3DERR_INVALIDCALL
);
3199 *ppDecl
= (IDirect3DVertexDeclaration9
*)This
->state
.vdecl
;
3201 NineUnknown_AddRef(NineUnknown(*ppDecl
));
3206 NineDevice9_SetFVF( struct NineDevice9
*This
,
3209 struct NineVertexDeclaration9
*vdecl
;
3212 DBG("FVF = %08x\n", FVF
);
3214 return D3D_OK
; /* like wine */
3216 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
3218 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
3222 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
3223 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
3225 return NineDevice9_SetVertexDeclaration(
3226 This
, (IDirect3DVertexDeclaration9
*)vdecl
);
3230 NineDevice9_GetFVF( struct NineDevice9
*This
,
3233 *pFVF
= This
->state
.vdecl
? This
->state
.vdecl
->fvf
: 0;
3238 NineDevice9_CreateVertexShader( struct NineDevice9
*This
,
3239 const DWORD
*pFunction
,
3240 IDirect3DVertexShader9
**ppShader
)
3242 struct NineVertexShader9
*vs
;
3245 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3247 hr
= NineVertexShader9_new(This
, &vs
, pFunction
, NULL
);
3250 *ppShader
= (IDirect3DVertexShader9
*)vs
;
3255 NineDevice9_SetVertexShader( struct NineDevice9
*This
,
3256 IDirect3DVertexShader9
*pShader
)
3258 struct nine_state
*state
= This
->update
;
3260 DBG("This=%p pShader=%p\n", This
, pShader
);
3262 /* ff -> non-ff: commit back non-ff constants */
3263 if (!state
->vs
&& pShader
)
3264 state
->commit
|= NINE_STATE_COMMIT_CONST_VS
;
3266 nine_bind(&state
->vs
, pShader
);
3268 state
->changed
.group
|= NINE_STATE_VS
;
3274 NineDevice9_GetVertexShader( struct NineDevice9
*This
,
3275 IDirect3DVertexShader9
**ppShader
)
3277 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3278 nine_reference_set(ppShader
, This
->state
.vs
);
3283 NineDevice9_SetVertexShaderConstantF( struct NineDevice9
*This
,
3285 const float *pConstantData
,
3286 UINT Vector4fCount
)
3288 struct nine_state
*state
= This
->update
;
3290 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3291 This
, StartRegister
, pConstantData
, Vector4fCount
);
3293 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3294 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3298 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3300 if (!This
->is_recording
) {
3301 if (!memcmp(&state
->vs_const_f
[StartRegister
* 4], pConstantData
,
3302 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0])))
3306 memcpy(&state
->vs_const_f
[StartRegister
* 4],
3308 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3310 nine_ranges_insert(&state
->changed
.vs_const_f
,
3311 StartRegister
, StartRegister
+ Vector4fCount
,
3314 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3320 NineDevice9_GetVertexShaderConstantF( struct NineDevice9
*This
,
3322 float *pConstantData
,
3323 UINT Vector4fCount
)
3325 const struct nine_state
*state
= &This
->state
;
3327 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3328 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3329 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3331 memcpy(pConstantData
,
3332 &state
->vs_const_f
[StartRegister
* 4],
3333 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3339 NineDevice9_SetVertexShaderConstantI( struct NineDevice9
*This
,
3341 const int *pConstantData
,
3342 UINT Vector4iCount
)
3344 struct nine_state
*state
= This
->update
;
3347 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3348 This
, StartRegister
, pConstantData
, Vector4iCount
);
3350 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3351 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3352 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3354 if (This
->driver_caps
.vs_integer
) {
3355 if (!This
->is_recording
) {
3356 if (!memcmp(&state
->vs_const_i
[StartRegister
][0], pConstantData
,
3357 Vector4iCount
* sizeof(state
->vs_const_i
[0])))
3360 memcpy(&state
->vs_const_i
[StartRegister
][0],
3362 Vector4iCount
* sizeof(state
->vs_const_i
[0]));
3364 for (i
= 0; i
< Vector4iCount
; i
++) {
3365 state
->vs_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3366 state
->vs_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3367 state
->vs_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3368 state
->vs_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3372 state
->changed
.vs_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3373 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3379 NineDevice9_GetVertexShaderConstantI( struct NineDevice9
*This
,
3382 UINT Vector4iCount
)
3384 const struct nine_state
*state
= &This
->state
;
3387 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3388 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3389 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3391 if (This
->driver_caps
.vs_integer
) {
3392 memcpy(pConstantData
,
3393 &state
->vs_const_i
[StartRegister
][0],
3394 Vector4iCount
* sizeof(state
->vs_const_i
[0]));
3396 for (i
= 0; i
< Vector4iCount
; i
++) {
3397 pConstantData
[4*i
] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][0]);
3398 pConstantData
[4*i
+1] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][1]);
3399 pConstantData
[4*i
+2] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][2]);
3400 pConstantData
[4*i
+3] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][3]);
3408 NineDevice9_SetVertexShaderConstantB( struct NineDevice9
*This
,
3410 const BOOL
*pConstantData
,
3413 struct nine_state
*state
= This
->update
;
3415 uint32_t bool_true
= This
->driver_caps
.vs_integer
? 0xFFFFFFFF : fui(1.0f
);
3417 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3418 This
, StartRegister
, pConstantData
, BoolCount
);
3420 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3421 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3422 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3424 if (!This
->is_recording
) {
3425 bool noChange
= true;
3426 for (i
= 0; i
< BoolCount
; i
++) {
3427 if (!!state
->vs_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3434 for (i
= 0; i
< BoolCount
; i
++)
3435 state
->vs_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3437 state
->changed
.vs_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3438 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3444 NineDevice9_GetVertexShaderConstantB( struct NineDevice9
*This
,
3446 BOOL
*pConstantData
,
3449 const struct nine_state
*state
= &This
->state
;
3452 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3453 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3454 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3456 for (i
= 0; i
< BoolCount
; i
++)
3457 pConstantData
[i
] = state
->vs_const_b
[StartRegister
+ i
] != 0 ? TRUE
: FALSE
;
3463 NineDevice9_SetStreamSource( struct NineDevice9
*This
,
3465 IDirect3DVertexBuffer9
*pStreamData
,
3469 struct nine_state
*state
= This
->update
;
3470 struct NineVertexBuffer9
*pVBuf9
= NineVertexBuffer9(pStreamData
);
3471 const unsigned i
= StreamNumber
;
3473 DBG("This=%p StreamNumber=%u pStreamData=%p OffsetInBytes=%u Stride=%u\n",
3474 This
, StreamNumber
, pStreamData
, OffsetInBytes
, Stride
);
3476 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3477 user_assert(Stride
<= This
->caps
.MaxStreamStride
, D3DERR_INVALIDCALL
);
3479 if (likely(!This
->is_recording
)) {
3480 if (state
->stream
[i
] == NineVertexBuffer9(pStreamData
) &&
3481 state
->vtxbuf
[i
].stride
== Stride
&&
3482 state
->vtxbuf
[i
].buffer_offset
== OffsetInBytes
)
3485 nine_bind(&state
->stream
[i
], pStreamData
);
3487 state
->changed
.vtxbuf
|= 1 << StreamNumber
;
3490 state
->vtxbuf
[i
].stride
= Stride
;
3491 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3493 state
->vtxbuf
[i
].buffer
= pStreamData
? pVBuf9
->base
.resource
: NULL
;
3499 NineDevice9_GetStreamSource( struct NineDevice9
*This
,
3501 IDirect3DVertexBuffer9
**ppStreamData
,
3502 UINT
*pOffsetInBytes
,
3505 const struct nine_state
*state
= &This
->state
;
3506 const unsigned i
= StreamNumber
;
3508 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3509 user_assert(ppStreamData
, D3DERR_INVALIDCALL
);
3511 nine_reference_set(ppStreamData
, state
->stream
[i
]);
3512 *pStride
= state
->vtxbuf
[i
].stride
;
3513 *pOffsetInBytes
= state
->vtxbuf
[i
].buffer_offset
;
3519 NineDevice9_SetStreamSourceFreq( struct NineDevice9
*This
,
3523 struct nine_state
*state
= This
->update
;
3524 /* const UINT freq = Setting & 0x7FFFFF; */
3526 DBG("This=%p StreamNumber=%u FrequencyParameter=0x%x\n", This
,
3527 StreamNumber
, Setting
);
3529 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3530 user_assert(StreamNumber
!= 0 || !(Setting
& D3DSTREAMSOURCE_INSTANCEDATA
),
3531 D3DERR_INVALIDCALL
);
3532 user_assert(!((Setting
& D3DSTREAMSOURCE_INSTANCEDATA
) &&
3533 (Setting
& D3DSTREAMSOURCE_INDEXEDDATA
)), D3DERR_INVALIDCALL
);
3534 user_assert(Setting
, D3DERR_INVALIDCALL
);
3536 state
->stream_freq
[StreamNumber
] = Setting
;
3538 if (Setting
& D3DSTREAMSOURCE_INSTANCEDATA
)
3539 state
->stream_instancedata_mask
|= 1 << StreamNumber
;
3541 state
->stream_instancedata_mask
&= ~(1 << StreamNumber
);
3543 state
->changed
.stream_freq
|= 1 << StreamNumber
;
3548 NineDevice9_GetStreamSourceFreq( struct NineDevice9
*This
,
3552 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3553 *pSetting
= This
->state
.stream_freq
[StreamNumber
];
3558 NineDevice9_SetIndices( struct NineDevice9
*This
,
3559 IDirect3DIndexBuffer9
*pIndexData
)
3561 struct nine_state
*state
= This
->update
;
3563 DBG("This=%p pIndexData=%p\n", This
, pIndexData
);
3565 if (likely(!This
->is_recording
))
3566 if (state
->idxbuf
== NineIndexBuffer9(pIndexData
))
3568 nine_bind(&state
->idxbuf
, pIndexData
);
3570 state
->changed
.group
|= NINE_STATE_IDXBUF
;
3575 /* XXX: wine/d3d9 doesn't have pBaseVertexIndex, and it doesn't make sense
3576 * here because it's an argument passed to the Draw calls.
3579 NineDevice9_GetIndices( struct NineDevice9
*This
,
3580 IDirect3DIndexBuffer9
**ppIndexData
/*,
3581 UINT *pBaseVertexIndex */ )
3583 user_assert(ppIndexData
, D3DERR_INVALIDCALL
);
3584 nine_reference_set(ppIndexData
, This
->state
.idxbuf
);
3589 NineDevice9_CreatePixelShader( struct NineDevice9
*This
,
3590 const DWORD
*pFunction
,
3591 IDirect3DPixelShader9
**ppShader
)
3593 struct NinePixelShader9
*ps
;
3596 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3598 hr
= NinePixelShader9_new(This
, &ps
, pFunction
, NULL
);
3601 *ppShader
= (IDirect3DPixelShader9
*)ps
;
3606 NineDevice9_SetPixelShader( struct NineDevice9
*This
,
3607 IDirect3DPixelShader9
*pShader
)
3609 struct nine_state
*state
= This
->update
;
3610 unsigned old_mask
= state
->ps
? state
->ps
->rt_mask
: 1;
3613 DBG("This=%p pShader=%p\n", This
, pShader
);
3615 /* ff -> non-ff: commit back non-ff constants */
3616 if (!state
->ps
&& pShader
)
3617 state
->commit
|= NINE_STATE_COMMIT_CONST_PS
;
3619 nine_bind(&state
->ps
, pShader
);
3621 state
->changed
.group
|= NINE_STATE_PS
;
3623 mask
= state
->ps
? state
->ps
->rt_mask
: 1;
3624 /* We need to update cbufs if the pixel shader would
3625 * write to different render targets */
3626 if (mask
!= old_mask
)
3627 state
->changed
.group
|= NINE_STATE_FB
;
3633 NineDevice9_GetPixelShader( struct NineDevice9
*This
,
3634 IDirect3DPixelShader9
**ppShader
)
3636 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3637 nine_reference_set(ppShader
, This
->state
.ps
);
3642 NineDevice9_SetPixelShaderConstantF( struct NineDevice9
*This
,
3644 const float *pConstantData
,
3645 UINT Vector4fCount
)
3647 struct nine_state
*state
= This
->update
;
3649 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3650 This
, StartRegister
, pConstantData
, Vector4fCount
);
3652 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3653 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3657 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3659 if (!This
->is_recording
) {
3660 if (!memcmp(&state
->ps_const_f
[StartRegister
* 4], pConstantData
,
3661 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0])))
3665 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3667 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3669 nine_ranges_insert(&state
->changed
.ps_const_f
,
3670 StartRegister
, StartRegister
+ Vector4fCount
,
3673 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3679 NineDevice9_GetPixelShaderConstantF( struct NineDevice9
*This
,
3681 float *pConstantData
,
3682 UINT Vector4fCount
)
3684 const struct nine_state
*state
= &This
->state
;
3686 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3687 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3688 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3690 memcpy(pConstantData
,
3691 &state
->ps_const_f
[StartRegister
* 4],
3692 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3698 NineDevice9_SetPixelShaderConstantI( struct NineDevice9
*This
,
3700 const int *pConstantData
,
3701 UINT Vector4iCount
)
3703 struct nine_state
*state
= This
->update
;
3706 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3707 This
, StartRegister
, pConstantData
, Vector4iCount
);
3709 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3710 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3711 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3713 if (This
->driver_caps
.ps_integer
) {
3714 if (!This
->is_recording
) {
3715 if (!memcmp(&state
->ps_const_i
[StartRegister
][0], pConstantData
,
3716 Vector4iCount
* sizeof(state
->ps_const_i
[0])))
3719 memcpy(&state
->ps_const_i
[StartRegister
][0],
3721 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3723 for (i
= 0; i
< Vector4iCount
; i
++) {
3724 state
->ps_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3725 state
->ps_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3726 state
->ps_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3727 state
->ps_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3730 state
->changed
.ps_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3731 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3737 NineDevice9_GetPixelShaderConstantI( struct NineDevice9
*This
,
3740 UINT Vector4iCount
)
3742 const struct nine_state
*state
= &This
->state
;
3745 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3746 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3747 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3749 if (This
->driver_caps
.ps_integer
) {
3750 memcpy(pConstantData
,
3751 &state
->ps_const_i
[StartRegister
][0],
3752 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3754 for (i
= 0; i
< Vector4iCount
; i
++) {
3755 pConstantData
[4*i
] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][0]);
3756 pConstantData
[4*i
+1] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][1]);
3757 pConstantData
[4*i
+2] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][2]);
3758 pConstantData
[4*i
+3] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][3]);
3766 NineDevice9_SetPixelShaderConstantB( struct NineDevice9
*This
,
3768 const BOOL
*pConstantData
,
3771 struct nine_state
*state
= This
->update
;
3773 uint32_t bool_true
= This
->driver_caps
.ps_integer
? 0xFFFFFFFF : fui(1.0f
);
3775 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3776 This
, StartRegister
, pConstantData
, BoolCount
);
3778 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3779 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3780 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3782 if (!This
->is_recording
) {
3783 bool noChange
= true;
3784 for (i
= 0; i
< BoolCount
; i
++) {
3785 if (!!state
->ps_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3792 for (i
= 0; i
< BoolCount
; i
++)
3793 state
->ps_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3795 state
->changed
.ps_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3796 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3802 NineDevice9_GetPixelShaderConstantB( struct NineDevice9
*This
,
3804 BOOL
*pConstantData
,
3807 const struct nine_state
*state
= &This
->state
;
3810 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3811 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3812 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3814 for (i
= 0; i
< BoolCount
; i
++)
3815 pConstantData
[i
] = state
->ps_const_b
[StartRegister
+ i
] ? TRUE
: FALSE
;
3821 NineDevice9_DrawRectPatch( struct NineDevice9
*This
,
3823 const float *pNumSegs
,
3824 const D3DRECTPATCH_INFO
*pRectPatchInfo
)
3826 STUB(D3DERR_INVALIDCALL
);
3830 NineDevice9_DrawTriPatch( struct NineDevice9
*This
,
3832 const float *pNumSegs
,
3833 const D3DTRIPATCH_INFO
*pTriPatchInfo
)
3835 STUB(D3DERR_INVALIDCALL
);
3839 NineDevice9_DeletePatch( struct NineDevice9
*This
,
3842 STUB(D3DERR_INVALIDCALL
);
3846 NineDevice9_CreateQuery( struct NineDevice9
*This
,
3848 IDirect3DQuery9
**ppQuery
)
3850 struct NineQuery9
*query
;
3853 DBG("This=%p Type=%d ppQuery=%p\n", This
, Type
, ppQuery
);
3855 hr
= nine_is_query_supported(This
->screen
, Type
);
3856 if (!ppQuery
|| hr
!= D3D_OK
)
3859 hr
= NineQuery9_new(This
, &query
, Type
);
3862 *ppQuery
= (IDirect3DQuery9
*)query
;
3866 IDirect3DDevice9Vtbl NineDevice9_vtable
= {
3867 (void *)NineUnknown_QueryInterface
,
3868 (void *)NineUnknown_AddRef
,
3869 (void *)NineUnknown_Release
,
3870 (void *)NineDevice9_TestCooperativeLevel
,
3871 (void *)NineDevice9_GetAvailableTextureMem
,
3872 (void *)NineDevice9_EvictManagedResources
,
3873 (void *)NineDevice9_GetDirect3D
,
3874 (void *)NineDevice9_GetDeviceCaps
,
3875 (void *)NineDevice9_GetDisplayMode
,
3876 (void *)NineDevice9_GetCreationParameters
,
3877 (void *)NineDevice9_SetCursorProperties
,
3878 (void *)NineDevice9_SetCursorPosition
,
3879 (void *)NineDevice9_ShowCursor
,
3880 (void *)NineDevice9_CreateAdditionalSwapChain
,
3881 (void *)NineDevice9_GetSwapChain
,
3882 (void *)NineDevice9_GetNumberOfSwapChains
,
3883 (void *)NineDevice9_Reset
,
3884 (void *)NineDevice9_Present
,
3885 (void *)NineDevice9_GetBackBuffer
,
3886 (void *)NineDevice9_GetRasterStatus
,
3887 (void *)NineDevice9_SetDialogBoxMode
,
3888 (void *)NineDevice9_SetGammaRamp
,
3889 (void *)NineDevice9_GetGammaRamp
,
3890 (void *)NineDevice9_CreateTexture
,
3891 (void *)NineDevice9_CreateVolumeTexture
,
3892 (void *)NineDevice9_CreateCubeTexture
,
3893 (void *)NineDevice9_CreateVertexBuffer
,
3894 (void *)NineDevice9_CreateIndexBuffer
,
3895 (void *)NineDevice9_CreateRenderTarget
,
3896 (void *)NineDevice9_CreateDepthStencilSurface
,
3897 (void *)NineDevice9_UpdateSurface
,
3898 (void *)NineDevice9_UpdateTexture
,
3899 (void *)NineDevice9_GetRenderTargetData
,
3900 (void *)NineDevice9_GetFrontBufferData
,
3901 (void *)NineDevice9_StretchRect
,
3902 (void *)NineDevice9_ColorFill
,
3903 (void *)NineDevice9_CreateOffscreenPlainSurface
,
3904 (void *)NineDevice9_SetRenderTarget
,
3905 (void *)NineDevice9_GetRenderTarget
,
3906 (void *)NineDevice9_SetDepthStencilSurface
,
3907 (void *)NineDevice9_GetDepthStencilSurface
,
3908 (void *)NineDevice9_BeginScene
,
3909 (void *)NineDevice9_EndScene
,
3910 (void *)NineDevice9_Clear
,
3911 (void *)NineDevice9_SetTransform
,
3912 (void *)NineDevice9_GetTransform
,
3913 (void *)NineDevice9_MultiplyTransform
,
3914 (void *)NineDevice9_SetViewport
,
3915 (void *)NineDevice9_GetViewport
,
3916 (void *)NineDevice9_SetMaterial
,
3917 (void *)NineDevice9_GetMaterial
,
3918 (void *)NineDevice9_SetLight
,
3919 (void *)NineDevice9_GetLight
,
3920 (void *)NineDevice9_LightEnable
,
3921 (void *)NineDevice9_GetLightEnable
,
3922 (void *)NineDevice9_SetClipPlane
,
3923 (void *)NineDevice9_GetClipPlane
,
3924 (void *)NineDevice9_SetRenderState
,
3925 (void *)NineDevice9_GetRenderState
,
3926 (void *)NineDevice9_CreateStateBlock
,
3927 (void *)NineDevice9_BeginStateBlock
,
3928 (void *)NineDevice9_EndStateBlock
,
3929 (void *)NineDevice9_SetClipStatus
,
3930 (void *)NineDevice9_GetClipStatus
,
3931 (void *)NineDevice9_GetTexture
,
3932 (void *)NineDevice9_SetTexture
,
3933 (void *)NineDevice9_GetTextureStageState
,
3934 (void *)NineDevice9_SetTextureStageState
,
3935 (void *)NineDevice9_GetSamplerState
,
3936 (void *)NineDevice9_SetSamplerState
,
3937 (void *)NineDevice9_ValidateDevice
,
3938 (void *)NineDevice9_SetPaletteEntries
,
3939 (void *)NineDevice9_GetPaletteEntries
,
3940 (void *)NineDevice9_SetCurrentTexturePalette
,
3941 (void *)NineDevice9_GetCurrentTexturePalette
,
3942 (void *)NineDevice9_SetScissorRect
,
3943 (void *)NineDevice9_GetScissorRect
,
3944 (void *)NineDevice9_SetSoftwareVertexProcessing
,
3945 (void *)NineDevice9_GetSoftwareVertexProcessing
,
3946 (void *)NineDevice9_SetNPatchMode
,
3947 (void *)NineDevice9_GetNPatchMode
,
3948 (void *)NineDevice9_DrawPrimitive
,
3949 (void *)NineDevice9_DrawIndexedPrimitive
,
3950 (void *)NineDevice9_DrawPrimitiveUP
,
3951 (void *)NineDevice9_DrawIndexedPrimitiveUP
,
3952 (void *)NineDevice9_ProcessVertices
,
3953 (void *)NineDevice9_CreateVertexDeclaration
,
3954 (void *)NineDevice9_SetVertexDeclaration
,
3955 (void *)NineDevice9_GetVertexDeclaration
,
3956 (void *)NineDevice9_SetFVF
,
3957 (void *)NineDevice9_GetFVF
,
3958 (void *)NineDevice9_CreateVertexShader
,
3959 (void *)NineDevice9_SetVertexShader
,
3960 (void *)NineDevice9_GetVertexShader
,
3961 (void *)NineDevice9_SetVertexShaderConstantF
,
3962 (void *)NineDevice9_GetVertexShaderConstantF
,
3963 (void *)NineDevice9_SetVertexShaderConstantI
,
3964 (void *)NineDevice9_GetVertexShaderConstantI
,
3965 (void *)NineDevice9_SetVertexShaderConstantB
,
3966 (void *)NineDevice9_GetVertexShaderConstantB
,
3967 (void *)NineDevice9_SetStreamSource
,
3968 (void *)NineDevice9_GetStreamSource
,
3969 (void *)NineDevice9_SetStreamSourceFreq
,
3970 (void *)NineDevice9_GetStreamSourceFreq
,
3971 (void *)NineDevice9_SetIndices
,
3972 (void *)NineDevice9_GetIndices
,
3973 (void *)NineDevice9_CreatePixelShader
,
3974 (void *)NineDevice9_SetPixelShader
,
3975 (void *)NineDevice9_GetPixelShader
,
3976 (void *)NineDevice9_SetPixelShaderConstantF
,
3977 (void *)NineDevice9_GetPixelShaderConstantF
,
3978 (void *)NineDevice9_SetPixelShaderConstantI
,
3979 (void *)NineDevice9_GetPixelShaderConstantI
,
3980 (void *)NineDevice9_SetPixelShaderConstantB
,
3981 (void *)NineDevice9_GetPixelShaderConstantB
,
3982 (void *)NineDevice9_DrawRectPatch
,
3983 (void *)NineDevice9_DrawTriPatch
,
3984 (void *)NineDevice9_DeletePatch
,
3985 (void *)NineDevice9_CreateQuery
3988 static const GUID
*NineDevice9_IIDs
[] = {
3989 &IID_IDirect3DDevice9
,
3995 NineDevice9_new( struct pipe_screen
*pScreen
,
3996 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
3998 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
4000 ID3DPresentGroup
*pPresentationGroup
,
4001 struct d3dadapter9_context
*pCTX
,
4003 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
4004 struct NineDevice9
**ppOut
)
4007 lock
= !!(pCreationParameters
->BehaviorFlags
& D3DCREATE_MULTITHREADED
);
4009 NINE_NEW(Device9
, ppOut
, lock
, /* args */
4010 pScreen
, pCreationParameters
, pCaps
,
4011 pPresentationParameters
, pD3D9
, pPresentationGroup
, pCTX
,
4012 ex
, pFullscreenDisplayMode
);