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
, 0);
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
->driver_bugs
.buggy_barycentrics
= TRUE
;
313 /* Disable NV path for now, needs some fixes */
314 This
->prefer_user_constbuf
= TRUE
;
316 tmpl
.target
= PIPE_BUFFER
;
317 tmpl
.format
= PIPE_FORMAT_R8_UNORM
;
323 tmpl
.usage
= PIPE_USAGE_DYNAMIC
;
324 tmpl
.bind
= PIPE_BIND_CONSTANT_BUFFER
;
327 tmpl
.width0
= This
->vs_const_size
;
328 This
->constbuf_vs
= pScreen
->resource_create(pScreen
, &tmpl
);
330 tmpl
.width0
= This
->ps_const_size
;
331 This
->constbuf_ps
= pScreen
->resource_create(pScreen
, &tmpl
);
333 if (!This
->constbuf_vs
|| !This
->constbuf_ps
)
334 return E_OUTOFMEMORY
;
337 /* allocate dummy texture/sampler for when there are missing ones bound */
339 struct pipe_resource tmplt
;
340 struct pipe_sampler_view templ
;
341 struct pipe_sampler_state samp
;
342 memset(&samp
, 0, sizeof(samp
));
344 tmplt
.target
= PIPE_TEXTURE_2D
;
348 tmplt
.last_level
= 0;
349 tmplt
.array_size
= 1;
350 tmplt
.usage
= PIPE_USAGE_DEFAULT
;
352 tmplt
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
353 tmplt
.bind
= PIPE_BIND_SAMPLER_VIEW
;
354 tmplt
.nr_samples
= 0;
356 This
->dummy_texture
= This
->screen
->resource_create(This
->screen
, &tmplt
);
357 if (!This
->dummy_texture
)
358 return D3DERR_DRIVERINTERNALERROR
;
360 templ
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
361 templ
.u
.tex
.first_layer
= 0;
362 templ
.u
.tex
.last_layer
= 0;
363 templ
.u
.tex
.first_level
= 0;
364 templ
.u
.tex
.last_level
= 0;
365 templ
.swizzle_r
= PIPE_SWIZZLE_ZERO
;
366 templ
.swizzle_g
= PIPE_SWIZZLE_ZERO
;
367 templ
.swizzle_b
= PIPE_SWIZZLE_ZERO
;
368 templ
.swizzle_a
= PIPE_SWIZZLE_ONE
;
369 templ
.target
= This
->dummy_texture
->target
;
371 This
->dummy_sampler_view
= This
->pipe
->create_sampler_view(This
->pipe
, This
->dummy_texture
, &templ
);
372 if (!This
->dummy_sampler_view
)
373 return D3DERR_DRIVERINTERNALERROR
;
375 samp
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
376 samp
.max_lod
= 15.0f
;
377 samp
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
378 samp
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
379 samp
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
380 samp
.min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
381 samp
.mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
382 samp
.compare_mode
= PIPE_TEX_COMPARE_NONE
;
383 samp
.compare_func
= PIPE_FUNC_LEQUAL
;
384 samp
.normalized_coords
= 1;
385 samp
.seamless_cube_map
= 1;
386 This
->dummy_sampler_state
= samp
;
389 /* Allocate upload helper for drivers that suck (from st pov ;). */
391 This
->driver_caps
.user_vbufs
= GET_PCAP(USER_VERTEX_BUFFERS
);
392 This
->driver_caps
.user_ibufs
= GET_PCAP(USER_INDEX_BUFFERS
);
393 This
->driver_caps
.user_cbufs
= GET_PCAP(USER_CONSTANT_BUFFERS
);
395 if (!This
->driver_caps
.user_vbufs
)
396 This
->vertex_uploader
= u_upload_create(This
->pipe
, 65536,
397 PIPE_BIND_VERTEX_BUFFER
, PIPE_USAGE_STREAM
);
398 if (!This
->driver_caps
.user_ibufs
)
399 This
->index_uploader
= u_upload_create(This
->pipe
, 128 * 1024,
400 PIPE_BIND_INDEX_BUFFER
, PIPE_USAGE_STREAM
);
401 if (!This
->driver_caps
.user_cbufs
) {
402 This
->constbuf_alignment
= GET_PCAP(CONSTANT_BUFFER_OFFSET_ALIGNMENT
);
403 This
->constbuf_uploader
= u_upload_create(This
->pipe
, This
->vs_const_size
,
404 PIPE_BIND_CONSTANT_BUFFER
, PIPE_USAGE_STREAM
);
407 This
->driver_caps
.window_space_position_support
= GET_PCAP(TGSI_VS_WINDOW_SPACE_POSITION
);
408 This
->driver_caps
.vs_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
, PIPE_SHADER_CAP_INTEGERS
);
409 This
->driver_caps
.ps_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_FRAGMENT
, PIPE_SHADER_CAP_INTEGERS
);
411 nine_ff_init(This
); /* initialize fixed function code */
413 NineDevice9_SetDefaultState(This
, FALSE
);
416 struct pipe_poly_stipple stipple
;
417 memset(&stipple
, ~0, sizeof(stipple
));
418 This
->pipe
->set_polygon_stipple(This
->pipe
, &stipple
);
421 This
->update
= &This
->state
;
422 nine_update_state(This
);
424 ID3DPresentGroup_Release(This
->present
);
431 NineDevice9_dtor( struct NineDevice9
*This
)
435 DBG("This=%p\n", This
);
437 if (This
->pipe
&& This
->cso
)
438 nine_pipe_context_clear(This
);
440 nine_state_clear(&This
->state
, TRUE
);
442 if (This
->vertex_uploader
)
443 u_upload_destroy(This
->vertex_uploader
);
444 if (This
->index_uploader
)
445 u_upload_destroy(This
->index_uploader
);
446 if (This
->constbuf_uploader
)
447 u_upload_destroy(This
->constbuf_uploader
);
449 nine_bind(&This
->record
, NULL
);
451 pipe_sampler_view_reference(&This
->dummy_sampler_view
, NULL
);
452 pipe_resource_reference(&This
->dummy_texture
, NULL
);
453 pipe_resource_reference(&This
->constbuf_vs
, NULL
);
454 pipe_resource_reference(&This
->constbuf_ps
, NULL
);
455 pipe_resource_reference(&This
->dummy_vbo
, NULL
);
456 FREE(This
->state
.vs_const_f
);
457 FREE(This
->state
.ps_const_f
);
458 FREE(This
->state
.vs_lconstf_temp
);
459 FREE(This
->state
.ps_lconstf_temp
);
461 if (This
->swapchains
) {
462 for (i
= 0; i
< This
->nswapchains
; ++i
)
463 if (This
->swapchains
[i
])
464 NineUnknown_Unbind(NineUnknown(This
->swapchains
[i
]));
465 FREE(This
->swapchains
);
471 cso_destroy_context(This
->cso
);
473 if (This
->pipe
->destroy
) { This
->pipe
->destroy(This
->pipe
); }
476 if (This
->present
) { ID3DPresentGroup_Release(This
->present
); }
477 if (This
->d3d9
) { IDirect3D9_Release(This
->d3d9
); }
479 NineUnknown_dtor(&This
->base
);
483 NineDevice9_GetScreen( struct NineDevice9
*This
)
488 struct pipe_context
*
489 NineDevice9_GetPipe( struct NineDevice9
*This
)
495 NineDevice9_GetCSO( struct NineDevice9
*This
)
501 NineDevice9_GetCaps( struct NineDevice9
*This
)
507 NineDevice9_PauseRecording( struct NineDevice9
*This
)
510 This
->update
= &This
->state
;
511 This
->is_recording
= FALSE
;
516 NineDevice9_ResumeRecording( struct NineDevice9
*This
)
519 This
->update
= &This
->record
->state
;
520 This
->is_recording
= TRUE
;
525 NineDevice9_TestCooperativeLevel( struct NineDevice9
*This
)
527 return D3D_OK
; /* TODO */
531 NineDevice9_GetAvailableTextureMem( struct NineDevice9
*This
)
533 const unsigned mem
= This
->screen
->get_param(This
->screen
, PIPE_CAP_VIDEO_MEMORY
);
541 NineDevice9_EvictManagedResources( struct NineDevice9
*This
)
543 struct NineBaseTexture9
*tex
;
545 DBG("This=%p\n", This
);
546 LIST_FOR_EACH_ENTRY(tex
, &This
->managed_textures
, list2
) {
547 NineBaseTexture9_UnLoad(tex
);
554 NineDevice9_GetDirect3D( struct NineDevice9
*This
,
555 IDirect3D9
**ppD3D9
)
557 user_assert(ppD3D9
!= NULL
, E_POINTER
);
558 IDirect3D9_AddRef(This
->d3d9
);
559 *ppD3D9
= This
->d3d9
;
564 NineDevice9_GetDeviceCaps( struct NineDevice9
*This
,
567 user_assert(pCaps
!= NULL
, D3DERR_INVALIDCALL
);
573 NineDevice9_GetDisplayMode( struct NineDevice9
*This
,
575 D3DDISPLAYMODE
*pMode
)
577 DBG("This=%p iSwapChain=%u pMode=%p\n", This
, iSwapChain
, pMode
);
579 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
581 return NineSwapChain9_GetDisplayMode(This
->swapchains
[iSwapChain
], pMode
);
585 NineDevice9_GetCreationParameters( struct NineDevice9
*This
,
586 D3DDEVICE_CREATION_PARAMETERS
*pParameters
)
588 user_assert(pParameters
!= NULL
, D3DERR_INVALIDCALL
);
589 *pParameters
= This
->params
;
594 NineDevice9_SetCursorProperties( struct NineDevice9
*This
,
597 IDirect3DSurface9
*pCursorBitmap
)
599 struct NineSurface9
*surf
= NineSurface9(pCursorBitmap
);
600 struct pipe_context
*pipe
= This
->pipe
;
602 struct pipe_transfer
*transfer
;
606 DBG_FLAG(DBG_SWAPCHAIN
, "This=%p XHotSpot=%u YHotSpot=%u "
607 "pCursorBitmap=%p\n", This
, XHotSpot
, YHotSpot
, pCursorBitmap
);
609 user_assert(pCursorBitmap
, D3DERR_INVALIDCALL
);
611 if (This
->swapchains
[0]->params
.Windowed
) {
612 This
->cursor
.w
= MIN2(surf
->desc
.Width
, 32);
613 This
->cursor
.h
= MIN2(surf
->desc
.Height
, 32);
614 hw_cursor
= 1; /* always use hw cursor for windowed mode */
616 This
->cursor
.w
= MIN2(surf
->desc
.Width
, This
->cursor
.image
->width0
);
617 This
->cursor
.h
= MIN2(surf
->desc
.Height
, This
->cursor
.image
->height0
);
618 hw_cursor
= This
->cursor
.w
== 32 && This
->cursor
.h
== 32;
621 u_box_origin_2d(This
->cursor
.w
, This
->cursor
.h
, &box
);
623 ptr
= pipe
->transfer_map(pipe
, This
->cursor
.image
, 0,
624 PIPE_TRANSFER_WRITE
|
625 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
628 ret_err("Failed to update cursor image.\n", D3DERR_DRIVERINTERNALERROR
);
630 This
->cursor
.hotspot
.x
= XHotSpot
;
631 This
->cursor
.hotspot
.y
= YHotSpot
;
633 /* Copy cursor image to internal storage. */
637 const struct util_format_description
*sfmt
=
638 util_format_description(surf
->base
.info
.format
);
641 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, D3DLOCK_READONLY
);
643 ret_err("Failed to map cursor source image.\n",
644 D3DERR_DRIVERINTERNALERROR
);
646 sfmt
->unpack_rgba_8unorm(ptr
, transfer
->stride
,
647 lock
.pBits
, lock
.Pitch
,
648 This
->cursor
.w
, This
->cursor
.h
);
651 hw_cursor
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
,
653 &This
->cursor
.hotspot
,
654 This
->cursor
.visible
) == D3D_OK
;
656 NineSurface9_UnlockRect(surf
);
658 pipe
->transfer_unmap(pipe
, transfer
);
660 /* hide cursor if we emulate it */
662 ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, FALSE
);
663 This
->cursor
.software
= !hw_cursor
;
669 NineDevice9_SetCursorPosition( struct NineDevice9
*This
,
674 struct NineSwapChain9
*swap
= This
->swapchains
[0];
676 DBG("This=%p X=%d Y=%d Flags=%d\n", This
, X
, Y
, Flags
);
678 This
->cursor
.pos
.x
= X
;
679 This
->cursor
.pos
.y
= Y
;
681 if (!This
->cursor
.software
)
682 This
->cursor
.software
= ID3DPresent_SetCursorPos(swap
->present
, &This
->cursor
.pos
) != D3D_OK
;
686 NineDevice9_ShowCursor( struct NineDevice9
*This
,
689 BOOL old
= This
->cursor
.visible
;
691 DBG("This=%p bShow=%d\n", This
, (int) bShow
);
693 This
->cursor
.visible
= bShow
&& (This
->cursor
.hotspot
.x
!= -1);
694 if (!This
->cursor
.software
)
695 This
->cursor
.software
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, bShow
) != D3D_OK
;
701 NineDevice9_CreateAdditionalSwapChain( struct NineDevice9
*This
,
702 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
703 IDirect3DSwapChain9
**pSwapChain
)
705 struct NineSwapChain9
*swapchain
, *tmplt
= This
->swapchains
[0];
706 ID3DPresent
*present
;
709 DBG("This=%p pPresentationParameters=%p pSwapChain=%p\n",
710 This
, pPresentationParameters
, pSwapChain
);
712 user_assert(pPresentationParameters
, D3DERR_INVALIDCALL
);
713 user_assert(tmplt
->params
.Windowed
&& pPresentationParameters
->Windowed
, D3DERR_INVALIDCALL
);
715 /* TODO: this deserves more tests */
716 if (!pPresentationParameters
->hDeviceWindow
)
717 pPresentationParameters
->hDeviceWindow
= This
->params
.hFocusWindow
;
719 hr
= ID3DPresentGroup_CreateAdditionalPresent(This
->present
, pPresentationParameters
, &present
);
724 hr
= NineSwapChain9_new(This
, FALSE
, present
, pPresentationParameters
,
726 tmplt
->params
.hDeviceWindow
,
731 *pSwapChain
= (IDirect3DSwapChain9
*)swapchain
;
736 NineDevice9_GetSwapChain( struct NineDevice9
*This
,
738 IDirect3DSwapChain9
**pSwapChain
)
740 user_assert(pSwapChain
!= NULL
, D3DERR_INVALIDCALL
);
743 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
745 NineUnknown_AddRef(NineUnknown(This
->swapchains
[iSwapChain
]));
746 *pSwapChain
= (IDirect3DSwapChain9
*)This
->swapchains
[iSwapChain
];
752 NineDevice9_GetNumberOfSwapChains( struct NineDevice9
*This
)
754 return This
->nswapchains
;
758 NineDevice9_Reset( struct NineDevice9
*This
,
759 D3DPRESENT_PARAMETERS
*pPresentationParameters
)
764 DBG("This=%p pPresentationParameters=%p\n", This
, pPresentationParameters
);
766 for (i
= 0; i
< This
->nswapchains
; ++i
) {
767 D3DPRESENT_PARAMETERS
*params
= &pPresentationParameters
[i
];
768 hr
= NineSwapChain9_Resize(This
->swapchains
[i
], params
, NULL
);
773 nine_pipe_context_clear(This
);
774 nine_state_clear(&This
->state
, TRUE
);
776 NineDevice9_SetDefaultState(This
, TRUE
);
777 NineDevice9_SetRenderTarget(
778 This
, 0, (IDirect3DSurface9
*)This
->swapchains
[0]->buffers
[0]);
779 /* XXX: better use GetBackBuffer here ? */
785 NineDevice9_Present( struct NineDevice9
*This
,
786 const RECT
*pSourceRect
,
787 const RECT
*pDestRect
,
788 HWND hDestWindowOverride
,
789 const RGNDATA
*pDirtyRegion
)
794 DBG("This=%p pSourceRect=%p pDestRect=%p hDestWindowOverride=%p pDirtyRegion=%p\n",
795 This
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
797 /* XXX is this right? */
798 for (i
= 0; i
< This
->nswapchains
; ++i
) {
799 hr
= NineSwapChain9_Present(This
->swapchains
[i
], pSourceRect
, pDestRect
,
800 hDestWindowOverride
, pDirtyRegion
, 0);
801 if (FAILED(hr
)) { return hr
; }
808 NineDevice9_GetBackBuffer( struct NineDevice9
*This
,
811 D3DBACKBUFFER_TYPE Type
,
812 IDirect3DSurface9
**ppBackBuffer
)
814 user_assert(ppBackBuffer
!= NULL
, D3DERR_INVALIDCALL
);
815 /* return NULL on error */
816 *ppBackBuffer
= NULL
;
817 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
819 return NineSwapChain9_GetBackBuffer(This
->swapchains
[iSwapChain
],
820 iBackBuffer
, Type
, ppBackBuffer
);
824 NineDevice9_GetRasterStatus( struct NineDevice9
*This
,
826 D3DRASTER_STATUS
*pRasterStatus
)
828 user_assert(pRasterStatus
!= NULL
, D3DERR_INVALIDCALL
);
829 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
831 return NineSwapChain9_GetRasterStatus(This
->swapchains
[iSwapChain
],
836 NineDevice9_SetDialogBoxMode( struct NineDevice9
*This
,
837 BOOL bEnableDialogs
)
839 STUB(D3DERR_INVALIDCALL
);
843 NineDevice9_SetGammaRamp( struct NineDevice9
*This
,
846 const D3DGAMMARAMP
*pRamp
)
848 DBG("This=%p iSwapChain=%u Flags=%x pRamp=%p\n", This
,
849 iSwapChain
, Flags
, pRamp
);
851 user_warn(iSwapChain
>= This
->nswapchains
);
854 if (pRamp
&& (iSwapChain
< This
->nswapchains
)) {
855 struct NineSwapChain9
*swap
= This
->swapchains
[iSwapChain
];
856 swap
->gamma
= *pRamp
;
857 ID3DPresent_SetGammaRamp(swap
->present
, pRamp
, swap
->params
.hDeviceWindow
);
862 NineDevice9_GetGammaRamp( struct NineDevice9
*This
,
864 D3DGAMMARAMP
*pRamp
)
866 DBG("This=%p iSwapChain=%u pRamp=%p\n", This
, iSwapChain
, pRamp
);
868 user_warn(iSwapChain
>= This
->nswapchains
);
871 if (pRamp
&& (iSwapChain
< This
->nswapchains
))
872 *pRamp
= This
->swapchains
[iSwapChain
]->gamma
;
876 NineDevice9_CreateTexture( struct NineDevice9
*This
,
883 IDirect3DTexture9
**ppTexture
,
884 HANDLE
*pSharedHandle
)
886 struct NineTexture9
*tex
;
889 DBG("This=%p Width=%u Height=%u Levels=%u Usage=%s Format=%s Pool=%s "
890 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Levels
,
891 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
892 nine_D3DPOOL_to_str(Pool
), ppTexture
, pSharedHandle
);
894 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DMAP
|
895 D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
896 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
;
899 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
900 user_assert(!pSharedHandle
|| This
->ex
, D3DERR_INVALIDCALL
);
901 /* When is used shared handle, Pool must be
902 * SYSTEMMEM with Levels 1 or DEFAULT with any Levels */
903 user_assert(!pSharedHandle
|| Pool
!= D3DPOOL_SYSTEMMEM
|| Levels
== 1,
905 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_SYSTEMMEM
|| Pool
== D3DPOOL_DEFAULT
,
907 user_assert((Usage
!= D3DUSAGE_AUTOGENMIPMAP
|| Levels
<= 1), D3DERR_INVALIDCALL
);
909 hr
= NineTexture9_new(This
, Width
, Height
, Levels
, Usage
, Format
, Pool
,
910 &tex
, pSharedHandle
);
912 *ppTexture
= (IDirect3DTexture9
*)tex
;
918 NineDevice9_CreateVolumeTexture( struct NineDevice9
*This
,
926 IDirect3DVolumeTexture9
**ppVolumeTexture
,
927 HANDLE
*pSharedHandle
)
929 struct NineVolumeTexture9
*tex
;
932 DBG("This=%p Width=%u Height=%u Depth=%u Levels=%u Usage=%s Format=%s Pool=%s "
933 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Depth
, Levels
,
934 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
935 nine_D3DPOOL_to_str(Pool
), ppVolumeTexture
, pSharedHandle
);
937 Usage
&= D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
938 D3DUSAGE_SOFTWAREPROCESSING
;
940 *ppVolumeTexture
= NULL
;
941 user_assert(Width
&& Height
&& Depth
, D3DERR_INVALIDCALL
);
942 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
944 hr
= NineVolumeTexture9_new(This
, Width
, Height
, Depth
, Levels
,
945 Usage
, Format
, Pool
, &tex
, pSharedHandle
);
947 *ppVolumeTexture
= (IDirect3DVolumeTexture9
*)tex
;
953 NineDevice9_CreateCubeTexture( struct NineDevice9
*This
,
959 IDirect3DCubeTexture9
**ppCubeTexture
,
960 HANDLE
*pSharedHandle
)
962 struct NineCubeTexture9
*tex
;
965 DBG("This=%p EdgeLength=%u Levels=%u Usage=%s Format=%s Pool=%s ppOut=%p "
966 "pSharedHandle=%p\n", This
, EdgeLength
, Levels
,
967 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
968 nine_D3DPOOL_to_str(Pool
), ppCubeTexture
, pSharedHandle
);
970 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DYNAMIC
|
971 D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
972 D3DUSAGE_SOFTWAREPROCESSING
;
974 *ppCubeTexture
= NULL
;
975 user_assert(EdgeLength
, D3DERR_INVALIDCALL
);
976 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
978 hr
= NineCubeTexture9_new(This
, EdgeLength
, Levels
, Usage
, Format
, Pool
,
979 &tex
, pSharedHandle
);
981 *ppCubeTexture
= (IDirect3DCubeTexture9
*)tex
;
987 NineDevice9_CreateVertexBuffer( struct NineDevice9
*This
,
992 IDirect3DVertexBuffer9
**ppVertexBuffer
,
993 HANDLE
*pSharedHandle
)
995 struct NineVertexBuffer9
*buf
;
997 D3DVERTEXBUFFER_DESC desc
;
999 DBG("This=%p Length=%u Usage=%x FVF=%x Pool=%u ppOut=%p pSharedHandle=%p\n",
1000 This
, Length
, Usage
, FVF
, Pool
, ppVertexBuffer
, pSharedHandle
);
1002 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1004 desc
.Format
= D3DFMT_VERTEXDATA
;
1005 desc
.Type
= D3DRTYPE_VERTEXBUFFER
;
1006 desc
.Usage
= Usage
&
1007 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1008 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1009 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
|
1010 D3DUSAGE_WRITEONLY
);
1015 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1016 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1018 hr
= NineVertexBuffer9_new(This
, &desc
, &buf
);
1020 *ppVertexBuffer
= (IDirect3DVertexBuffer9
*)buf
;
1025 NineDevice9_CreateIndexBuffer( struct NineDevice9
*This
,
1030 IDirect3DIndexBuffer9
**ppIndexBuffer
,
1031 HANDLE
*pSharedHandle
)
1033 struct NineIndexBuffer9
*buf
;
1035 D3DINDEXBUFFER_DESC desc
;
1037 DBG("This=%p Length=%u Usage=%x Format=%s Pool=%u ppOut=%p "
1038 "pSharedHandle=%p\n", This
, Length
, Usage
,
1039 d3dformat_to_string(Format
), Pool
, ppIndexBuffer
, pSharedHandle
);
1041 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1043 desc
.Format
= Format
;
1044 desc
.Type
= D3DRTYPE_INDEXBUFFER
;
1045 desc
.Usage
= Usage
&
1046 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1047 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1048 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_WRITEONLY
);
1052 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1053 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1055 hr
= NineIndexBuffer9_new(This
, &desc
, &buf
);
1057 *ppIndexBuffer
= (IDirect3DIndexBuffer9
*)buf
;
1062 create_zs_or_rt_surface(struct NineDevice9
*This
,
1063 unsigned type
, /* 0 = RT, 1 = ZS, 2 = plain */
1065 UINT Width
, UINT Height
,
1067 D3DMULTISAMPLE_TYPE MultiSample
,
1068 DWORD MultisampleQuality
,
1069 BOOL Discard_or_Lockable
,
1070 IDirect3DSurface9
**ppSurface
,
1071 HANDLE
*pSharedHandle
)
1073 struct NineSurface9
*surface
;
1074 struct pipe_screen
*screen
= This
->screen
;
1075 struct pipe_resource
*resource
= NULL
;
1077 D3DSURFACE_DESC desc
;
1078 struct pipe_resource templ
;
1080 DBG("This=%p type=%u Pool=%s Width=%u Height=%u Format=%s MS=%u Quality=%u "
1081 "Discard_or_Lockable=%i ppSurface=%p pSharedHandle=%p\n",
1082 This
, type
, nine_D3DPOOL_to_str(Pool
), Width
, Height
,
1083 d3dformat_to_string(Format
), MultiSample
, MultisampleQuality
,
1084 Discard_or_Lockable
, ppSurface
, pSharedHandle
);
1087 DBG("FIXME Used shared handle! This option isn't probably handled correctly!\n");
1089 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
1090 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1092 templ
.target
= PIPE_TEXTURE_2D
;
1093 templ
.width0
= Width
;
1094 templ
.height0
= Height
;
1096 templ
.array_size
= 1;
1097 templ
.last_level
= 0;
1098 templ
.nr_samples
= (unsigned)MultiSample
;
1099 templ
.usage
= PIPE_USAGE_DEFAULT
;
1101 templ
.bind
= PIPE_BIND_SAMPLER_VIEW
; /* StretchRect */
1103 case 0: templ
.bind
|= PIPE_BIND_RENDER_TARGET
; break;
1104 case 1: templ
.bind
= d3d9_get_pipe_depth_format_bindings(Format
); break;
1109 templ
.format
= d3d9_to_pipe_format_checked(screen
, Format
, templ
.target
,
1110 templ
.nr_samples
, templ
.bind
,
1113 desc
.Format
= Format
;
1114 desc
.Type
= D3DRTYPE_SURFACE
;
1117 desc
.MultiSampleType
= MultiSample
;
1118 desc
.MultiSampleQuality
= MultisampleQuality
;
1120 desc
.Height
= Height
;
1122 case 0: desc
.Usage
= D3DUSAGE_RENDERTARGET
; break;
1123 case 1: desc
.Usage
= D3DUSAGE_DEPTHSTENCIL
; break;
1127 if (compressed_format(Format
)) {
1128 const unsigned w
= util_format_get_blockwidth(templ
.format
);
1129 const unsigned h
= util_format_get_blockheight(templ
.format
);
1131 user_assert(!(Width
% w
) && !(Height
% h
), D3DERR_INVALIDCALL
);
1134 if (Pool
== D3DPOOL_DEFAULT
&& Format
!= D3DFMT_NULL
) {
1135 /* resource_create doesn't return an error code, so check format here */
1136 user_assert(templ
.format
!= PIPE_FORMAT_NONE
, D3DERR_INVALIDCALL
);
1137 resource
= screen
->resource_create(screen
, &templ
);
1138 user_assert(resource
, D3DERR_OUTOFVIDEOMEMORY
);
1139 if (Discard_or_Lockable
&& (desc
.Usage
& D3DUSAGE_RENDERTARGET
))
1140 resource
->flags
|= NINE_RESOURCE_FLAG_LOCKABLE
;
1144 hr
= NineSurface9_new(This
, NULL
, resource
, NULL
, 0, 0, 0, &desc
, &surface
);
1145 pipe_resource_reference(&resource
, NULL
);
1148 *ppSurface
= (IDirect3DSurface9
*)surface
;
1153 NineDevice9_CreateRenderTarget( struct NineDevice9
*This
,
1157 D3DMULTISAMPLE_TYPE MultiSample
,
1158 DWORD MultisampleQuality
,
1160 IDirect3DSurface9
**ppSurface
,
1161 HANDLE
*pSharedHandle
)
1164 return create_zs_or_rt_surface(This
, 0, D3DPOOL_DEFAULT
,
1165 Width
, Height
, Format
,
1166 MultiSample
, MultisampleQuality
,
1167 Lockable
, ppSurface
, pSharedHandle
);
1171 NineDevice9_CreateDepthStencilSurface( struct NineDevice9
*This
,
1175 D3DMULTISAMPLE_TYPE MultiSample
,
1176 DWORD MultisampleQuality
,
1178 IDirect3DSurface9
**ppSurface
,
1179 HANDLE
*pSharedHandle
)
1182 if (!depth_stencil_format(Format
))
1183 return D3DERR_NOTAVAILABLE
;
1184 return create_zs_or_rt_surface(This
, 1, D3DPOOL_DEFAULT
,
1185 Width
, Height
, Format
,
1186 MultiSample
, MultisampleQuality
,
1187 Discard
, ppSurface
, pSharedHandle
);
1191 NineDevice9_UpdateSurface( struct NineDevice9
*This
,
1192 IDirect3DSurface9
*pSourceSurface
,
1193 const RECT
*pSourceRect
,
1194 IDirect3DSurface9
*pDestinationSurface
,
1195 const POINT
*pDestPoint
)
1197 struct NineSurface9
*dst
= NineSurface9(pDestinationSurface
);
1198 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1199 int copy_width
, copy_height
;
1202 DBG("This=%p pSourceSurface=%p pDestinationSurface=%p "
1203 "pSourceRect=%p pDestPoint=%p\n", This
,
1204 pSourceSurface
, pDestinationSurface
, pSourceRect
, pDestPoint
);
1206 DBG("pSourceRect = (%u,%u)-(%u,%u)\n",
1207 pSourceRect
->left
, pSourceRect
->top
,
1208 pSourceRect
->right
, pSourceRect
->bottom
);
1210 DBG("pDestPoint = (%u,%u)\n", pDestPoint
->x
, pDestPoint
->y
);
1212 user_assert(dst
&& src
, D3DERR_INVALIDCALL
);
1214 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1215 user_assert(src
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1217 user_assert(dst
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1218 user_assert(src
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1220 user_assert(!src
->lock_count
, D3DERR_INVALIDCALL
);
1221 user_assert(!dst
->lock_count
, D3DERR_INVALIDCALL
);
1223 user_assert(dst
->desc
.Format
== src
->desc
.Format
, D3DERR_INVALIDCALL
);
1224 user_assert(!depth_stencil_format(dst
->desc
.Format
), D3DERR_INVALIDCALL
);
1227 copy_width
= pSourceRect
->right
- pSourceRect
->left
;
1228 copy_height
= pSourceRect
->bottom
- pSourceRect
->top
;
1230 user_assert(pSourceRect
->left
>= 0 &&
1232 pSourceRect
->right
<= src
->desc
.Width
&&
1233 pSourceRect
->top
>= 0 &&
1235 pSourceRect
->bottom
<= src
->desc
.Height
,
1236 D3DERR_INVALIDCALL
);
1238 copy_width
= src
->desc
.Width
;
1239 copy_height
= src
->desc
.Height
;
1242 destRect
.right
= copy_width
;
1243 destRect
.bottom
= copy_height
;
1246 user_assert(pDestPoint
->x
>= 0 && pDestPoint
->y
>= 0,
1247 D3DERR_INVALIDCALL
);
1248 destRect
.right
+= pDestPoint
->x
;
1249 destRect
.bottom
+= pDestPoint
->y
;
1252 user_assert(destRect
.right
<= dst
->desc
.Width
&&
1253 destRect
.bottom
<= dst
->desc
.Height
,
1254 D3DERR_INVALIDCALL
);
1256 if (compressed_format(dst
->desc
.Format
)) {
1257 const unsigned w
= util_format_get_blockwidth(dst
->base
.info
.format
);
1258 const unsigned h
= util_format_get_blockheight(dst
->base
.info
.format
);
1261 user_assert(!(pDestPoint
->x
% w
) && !(pDestPoint
->y
% h
),
1262 D3DERR_INVALIDCALL
);
1266 user_assert(!(pSourceRect
->left
% w
) && !(pSourceRect
->top
% h
),
1267 D3DERR_INVALIDCALL
);
1269 if (!(copy_width
== src
->desc
.Width
&&
1270 copy_width
== dst
->desc
.Width
&&
1271 copy_height
== src
->desc
.Height
&&
1272 copy_height
== dst
->desc
.Height
)) {
1273 user_assert(!(copy_width
% w
) && !(copy_height
% h
),
1274 D3DERR_INVALIDCALL
);
1278 NineSurface9_CopyMemToDefault(dst
, src
, pDestPoint
, pSourceRect
);
1284 NineDevice9_UpdateTexture( struct NineDevice9
*This
,
1285 IDirect3DBaseTexture9
*pSourceTexture
,
1286 IDirect3DBaseTexture9
*pDestinationTexture
)
1288 struct NineBaseTexture9
*dstb
= NineBaseTexture9(pDestinationTexture
);
1289 struct NineBaseTexture9
*srcb
= NineBaseTexture9(pSourceTexture
);
1291 unsigned last_level
= dstb
->base
.info
.last_level
;
1294 DBG("This=%p pSourceTexture=%p pDestinationTexture=%p\n", This
,
1295 pSourceTexture
, pDestinationTexture
);
1297 user_assert(pSourceTexture
!= pDestinationTexture
, D3DERR_INVALIDCALL
);
1299 user_assert(dstb
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1300 user_assert(srcb
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1302 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1303 /* Only the first level is updated, the others regenerated. */
1305 /* if the source has D3DUSAGE_AUTOGENMIPMAP, we have to ignore
1306 * the sublevels, thus level 0 has to match */
1307 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ||
1308 (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
);
1313 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
), D3DERR_INVALIDCALL
);
1316 user_assert(dstb
->base
.type
== srcb
->base
.type
, D3DERR_INVALIDCALL
);
1318 /* Find src level that matches dst level 0: */
1319 user_assert(srcb
->base
.info
.width0
>= dstb
->base
.info
.width0
&&
1320 srcb
->base
.info
.height0
>= dstb
->base
.info
.height0
&&
1321 srcb
->base
.info
.depth0
>= dstb
->base
.info
.depth0
,
1322 D3DERR_INVALIDCALL
);
1323 for (m
= 0; m
<= srcb
->base
.info
.last_level
; ++m
) {
1324 unsigned w
= u_minify(srcb
->base
.info
.width0
, m
);
1325 unsigned h
= u_minify(srcb
->base
.info
.height0
, m
);
1326 unsigned d
= u_minify(srcb
->base
.info
.depth0
, m
);
1328 if (w
== dstb
->base
.info
.width0
&&
1329 h
== dstb
->base
.info
.height0
&&
1330 d
== dstb
->base
.info
.depth0
)
1333 user_assert(m
<= srcb
->base
.info
.last_level
, D3DERR_INVALIDCALL
);
1335 last_level
= MIN2(last_level
, srcb
->base
.info
.last_level
- m
);
1337 if (dstb
->base
.type
== D3DRTYPE_TEXTURE
) {
1338 struct NineTexture9
*dst
= NineTexture9(dstb
);
1339 struct NineTexture9
*src
= NineTexture9(srcb
);
1341 if (src
->dirty_rect
.width
== 0)
1344 pipe_box_to_rect(&rect
, &src
->dirty_rect
);
1345 for (l
= 0; l
< m
; ++l
)
1346 rect_minify_inclusive(&rect
);
1348 for (l
= 0; l
<= last_level
; ++l
, ++m
) {
1349 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1351 dst
->surfaces
[l
]->desc
.Width
,
1352 dst
->surfaces
[l
]->desc
.Height
);
1353 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
],
1357 rect_minify_inclusive(&rect
);
1359 u_box_origin_2d(0, 0, &src
->dirty_rect
);
1361 if (dstb
->base
.type
== D3DRTYPE_CUBETEXTURE
) {
1362 struct NineCubeTexture9
*dst
= NineCubeTexture9(dstb
);
1363 struct NineCubeTexture9
*src
= NineCubeTexture9(srcb
);
1366 /* GPUs usually have them stored as arrays of mip-mapped 2D textures. */
1367 for (z
= 0; z
< 6; ++z
) {
1368 if (src
->dirty_rect
[z
].width
== 0)
1371 pipe_box_to_rect(&rect
, &src
->dirty_rect
[z
]);
1372 for (l
= 0; l
< m
; ++l
)
1373 rect_minify_inclusive(&rect
);
1375 for (l
= 0; l
<= last_level
; ++l
, ++m
) {
1376 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1378 dst
->surfaces
[l
* 6 + z
]->desc
.Width
,
1379 dst
->surfaces
[l
* 6 + z
]->desc
.Height
);
1380 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
* 6 + z
],
1381 src
->surfaces
[m
* 6 + z
],
1384 rect_minify_inclusive(&rect
);
1386 u_box_origin_2d(0, 0, &src
->dirty_rect
[z
]);
1390 if (dstb
->base
.type
== D3DRTYPE_VOLUMETEXTURE
) {
1391 struct NineVolumeTexture9
*dst
= NineVolumeTexture9(dstb
);
1392 struct NineVolumeTexture9
*src
= NineVolumeTexture9(srcb
);
1394 if (src
->dirty_box
.width
== 0)
1396 for (l
= 0; l
<= last_level
; ++l
, ++m
)
1397 NineVolume9_CopyMemToDefault(dst
->volumes
[l
],
1398 src
->volumes
[m
], 0, 0, 0, NULL
);
1399 u_box_3d(0, 0, 0, 0, 0, 0, &src
->dirty_box
);
1401 assert(!"invalid texture type");
1404 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1405 dstb
->dirty_mip
= TRUE
;
1406 NineBaseTexture9_GenerateMipSubLevels(dstb
);
1413 NineDevice9_GetRenderTargetData( struct NineDevice9
*This
,
1414 IDirect3DSurface9
*pRenderTarget
,
1415 IDirect3DSurface9
*pDestSurface
)
1417 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1418 struct NineSurface9
*src
= NineSurface9(pRenderTarget
);
1420 DBG("This=%p pRenderTarget=%p pDestSurface=%p\n",
1421 This
, pRenderTarget
, pDestSurface
);
1423 user_assert(dst
->desc
.Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1424 user_assert(src
->desc
.Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1426 user_assert(dst
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1427 user_assert(src
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1429 user_assert(src
->desc
.Width
== dst
->desc
.Width
, D3DERR_INVALIDCALL
);
1430 user_assert(src
->desc
.Height
== dst
->desc
.Height
, D3DERR_INVALIDCALL
);
1432 NineSurface9_CopyDefaultToMem(dst
, src
);
1438 NineDevice9_GetFrontBufferData( struct NineDevice9
*This
,
1440 IDirect3DSurface9
*pDestSurface
)
1442 DBG("This=%p iSwapChain=%u pDestSurface=%p\n", This
,
1443 iSwapChain
, pDestSurface
);
1445 user_assert(pDestSurface
!= NULL
, D3DERR_INVALIDCALL
);
1446 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
1448 return NineSwapChain9_GetFrontBufferData(This
->swapchains
[iSwapChain
],
1453 NineDevice9_StretchRect( struct NineDevice9
*This
,
1454 IDirect3DSurface9
*pSourceSurface
,
1455 const RECT
*pSourceRect
,
1456 IDirect3DSurface9
*pDestSurface
,
1457 const RECT
*pDestRect
,
1458 D3DTEXTUREFILTERTYPE Filter
)
1460 struct pipe_screen
*screen
= This
->screen
;
1461 struct pipe_context
*pipe
= This
->pipe
;
1462 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1463 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1464 struct pipe_resource
*dst_res
= NineSurface9_GetResource(dst
);
1465 struct pipe_resource
*src_res
= NineSurface9_GetResource(src
);
1467 struct pipe_blit_info blit
;
1468 boolean scaled
, clamped
, ms
, flip_x
= FALSE
, flip_y
= FALSE
;
1470 DBG("This=%p pSourceSurface=%p pSourceRect=%p pDestSurface=%p "
1471 "pDestRect=%p Filter=%u\n",
1472 This
, pSourceSurface
, pSourceRect
, pDestSurface
, pDestRect
, Filter
);
1474 DBG("pSourceRect=(%u,%u)-(%u,%u)\n",
1475 pSourceRect
->left
, pSourceRect
->top
,
1476 pSourceRect
->right
, pSourceRect
->bottom
);
1478 DBG("pDestRect=(%u,%u)-(%u,%u)\n", pDestRect
->left
, pDestRect
->top
,
1479 pDestRect
->right
, pDestRect
->bottom
);
1481 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
&&
1482 src
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1483 zs
= util_format_is_depth_or_stencil(dst_res
->format
);
1484 user_assert(!zs
|| !This
->in_scene
, D3DERR_INVALIDCALL
);
1485 user_assert(!zs
|| !pSourceRect
||
1486 (pSourceRect
->left
== 0 &&
1487 pSourceRect
->top
== 0 &&
1488 pSourceRect
->right
== src
->desc
.Width
&&
1489 pSourceRect
->bottom
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1490 user_assert(!zs
|| !pDestRect
||
1491 (pDestRect
->left
== 0 &&
1492 pDestRect
->top
== 0 &&
1493 pDestRect
->right
== dst
->desc
.Width
&&
1494 pDestRect
->bottom
== dst
->desc
.Height
), D3DERR_INVALIDCALL
);
1496 (dst
->desc
.Width
== src
->desc
.Width
&&
1497 dst
->desc
.Height
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1498 user_assert(zs
|| !util_format_is_depth_or_stencil(src_res
->format
),
1499 D3DERR_INVALIDCALL
);
1500 user_assert(!zs
|| dst
->desc
.Format
== src
->desc
.Format
,
1501 D3DERR_INVALIDCALL
);
1502 user_assert(screen
->is_format_supported(screen
, src_res
->format
,
1504 src_res
->nr_samples
,
1505 PIPE_BIND_SAMPLER_VIEW
),
1506 D3DERR_INVALIDCALL
);
1508 /* We might want to permit these, but wine thinks we shouldn't. */
1509 user_assert(!pDestRect
||
1510 (pDestRect
->left
<= pDestRect
->right
&&
1511 pDestRect
->top
<= pDestRect
->bottom
), D3DERR_INVALIDCALL
);
1512 user_assert(!pSourceRect
||
1513 (pSourceRect
->left
<= pSourceRect
->right
&&
1514 pSourceRect
->top
<= pSourceRect
->bottom
), D3DERR_INVALIDCALL
);
1516 memset(&blit
, 0, sizeof(blit
));
1517 blit
.dst
.resource
= dst_res
;
1518 blit
.dst
.level
= dst
->level
;
1519 blit
.dst
.box
.z
= dst
->layer
;
1520 blit
.dst
.box
.depth
= 1;
1521 blit
.dst
.format
= dst_res
->format
;
1523 flip_x
= pDestRect
->left
> pDestRect
->right
;
1525 blit
.dst
.box
.x
= pDestRect
->right
;
1526 blit
.dst
.box
.width
= pDestRect
->left
- pDestRect
->right
;
1528 blit
.dst
.box
.x
= pDestRect
->left
;
1529 blit
.dst
.box
.width
= pDestRect
->right
- pDestRect
->left
;
1531 flip_y
= pDestRect
->top
> pDestRect
->bottom
;
1533 blit
.dst
.box
.y
= pDestRect
->bottom
;
1534 blit
.dst
.box
.height
= pDestRect
->top
- pDestRect
->bottom
;
1536 blit
.dst
.box
.y
= pDestRect
->top
;
1537 blit
.dst
.box
.height
= pDestRect
->bottom
- pDestRect
->top
;
1542 blit
.dst
.box
.width
= dst
->desc
.Width
;
1543 blit
.dst
.box
.height
= dst
->desc
.Height
;
1545 blit
.src
.resource
= src_res
;
1546 blit
.src
.level
= src
->level
;
1547 blit
.src
.box
.z
= src
->layer
;
1548 blit
.src
.box
.depth
= 1;
1549 blit
.src
.format
= src_res
->format
;
1551 if (flip_x
^ (pSourceRect
->left
> pSourceRect
->right
)) {
1552 blit
.src
.box
.x
= pSourceRect
->right
;
1553 blit
.src
.box
.width
= pSourceRect
->left
- pSourceRect
->right
;
1555 blit
.src
.box
.x
= pSourceRect
->left
;
1556 blit
.src
.box
.width
= pSourceRect
->right
- pSourceRect
->left
;
1558 if (flip_y
^ (pSourceRect
->top
> pSourceRect
->bottom
)) {
1559 blit
.src
.box
.y
= pSourceRect
->bottom
;
1560 blit
.src
.box
.height
= pSourceRect
->top
- pSourceRect
->bottom
;
1562 blit
.src
.box
.y
= pSourceRect
->top
;
1563 blit
.src
.box
.height
= pSourceRect
->bottom
- pSourceRect
->top
;
1566 blit
.src
.box
.x
= flip_x
? src
->desc
.Width
: 0;
1567 blit
.src
.box
.y
= flip_y
? src
->desc
.Height
: 0;
1568 blit
.src
.box
.width
= flip_x
? -src
->desc
.Width
: src
->desc
.Width
;
1569 blit
.src
.box
.height
= flip_y
? -src
->desc
.Height
: src
->desc
.Height
;
1571 blit
.mask
= zs
? PIPE_MASK_ZS
: PIPE_MASK_RGBA
;
1572 blit
.filter
= Filter
== D3DTEXF_LINEAR
?
1573 PIPE_TEX_FILTER_LINEAR
: PIPE_TEX_FILTER_NEAREST
;
1574 blit
.scissor_enable
= FALSE
;
1575 blit
.alpha_blend
= FALSE
;
1577 /* If both of a src and dst dimension are negative, flip them. */
1578 if (blit
.dst
.box
.width
< 0 && blit
.src
.box
.width
< 0) {
1579 blit
.dst
.box
.width
= -blit
.dst
.box
.width
;
1580 blit
.src
.box
.width
= -blit
.src
.box
.width
;
1582 if (blit
.dst
.box
.height
< 0 && blit
.src
.box
.height
< 0) {
1583 blit
.dst
.box
.height
= -blit
.dst
.box
.height
;
1584 blit
.src
.box
.height
= -blit
.src
.box
.height
;
1587 blit
.dst
.box
.width
!= blit
.src
.box
.width
||
1588 blit
.dst
.box
.height
!= blit
.src
.box
.height
;
1590 user_assert(!scaled
|| dst
!= src
, D3DERR_INVALIDCALL
);
1591 user_assert(!scaled
||
1592 !NineSurface9_IsOffscreenPlain(dst
), D3DERR_INVALIDCALL
);
1593 user_assert(!NineSurface9_IsOffscreenPlain(dst
) ||
1594 NineSurface9_IsOffscreenPlain(src
), D3DERR_INVALIDCALL
);
1595 user_assert(NineSurface9_IsOffscreenPlain(dst
) ||
1596 dst
->desc
.Usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
),
1597 D3DERR_INVALIDCALL
);
1598 user_assert(!scaled
||
1599 (!util_format_is_compressed(dst
->base
.info
.format
) &&
1600 !util_format_is_compressed(src
->base
.info
.format
)),
1601 D3DERR_INVALIDCALL
);
1603 user_warn(src
== dst
&&
1604 u_box_test_intersection_2d(&blit
.src
.box
, &blit
.dst
.box
));
1606 /* Check for clipping/clamping: */
1608 struct pipe_box box
;
1611 xy
= u_box_clip_2d(&box
, &blit
.dst
.box
,
1612 dst
->desc
.Width
, dst
->desc
.Height
);
1616 xy
= u_box_clip_2d(&box
, &blit
.src
.box
,
1617 src
->desc
.Width
, src
->desc
.Height
);
1621 ms
= (dst
->desc
.MultiSampleType
| 1) != (src
->desc
.MultiSampleType
| 1);
1623 if (clamped
|| scaled
|| (blit
.dst
.format
!= blit
.src
.format
) || ms
) {
1624 DBG("using pipe->blit()\n");
1625 /* TODO: software scaling */
1626 user_assert(screen
->is_format_supported(screen
, dst_res
->format
,
1628 dst_res
->nr_samples
,
1629 zs
? PIPE_BIND_DEPTH_STENCIL
:
1630 PIPE_BIND_RENDER_TARGET
),
1631 D3DERR_INVALIDCALL
);
1633 pipe
->blit(pipe
, &blit
);
1635 assert(blit
.dst
.box
.x
>= 0 && blit
.dst
.box
.y
>= 0 &&
1636 blit
.src
.box
.x
>= 0 && blit
.src
.box
.y
>= 0 &&
1637 blit
.dst
.box
.x
+ blit
.dst
.box
.width
<= dst
->desc
.Width
&&
1638 blit
.src
.box
.x
+ blit
.src
.box
.width
<= src
->desc
.Width
&&
1639 blit
.dst
.box
.y
+ blit
.dst
.box
.height
<= dst
->desc
.Height
&&
1640 blit
.src
.box
.y
+ blit
.src
.box
.height
<= src
->desc
.Height
);
1641 /* Or drivers might crash ... */
1642 DBG("Using resource_copy_region.\n");
1643 pipe
->resource_copy_region(pipe
,
1644 blit
.dst
.resource
, blit
.dst
.level
,
1645 blit
.dst
.box
.x
, blit
.dst
.box
.y
, blit
.dst
.box
.z
,
1646 blit
.src
.resource
, blit
.src
.level
,
1650 /* Communicate the container it needs to update sublevels - if apply */
1651 NineSurface9_MarkContainerDirty(dst
);
1657 NineDevice9_ColorFill( struct NineDevice9
*This
,
1658 IDirect3DSurface9
*pSurface
,
1662 struct pipe_context
*pipe
= This
->pipe
;
1663 struct NineSurface9
*surf
= NineSurface9(pSurface
);
1664 struct pipe_surface
*psurf
;
1665 unsigned x
, y
, w
, h
;
1666 union pipe_color_union rgba
;
1669 DBG("This=%p pSurface=%p pRect=%p color=%08x\n", This
,
1670 pSurface
, pRect
, color
);
1672 DBG("pRect=(%u,%u)-(%u,%u)\n", pRect
->left
, pRect
->top
,
1673 pRect
->right
, pRect
->bottom
);
1675 user_assert(surf
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1677 user_assert((surf
->base
.usage
& D3DUSAGE_RENDERTARGET
) ||
1678 NineSurface9_IsOffscreenPlain(surf
), D3DERR_INVALIDCALL
);
1680 user_assert(surf
->desc
.Format
!= D3DFMT_NULL
, D3D_OK
);
1685 w
= pRect
->right
- pRect
->left
;
1686 h
= pRect
->bottom
- pRect
->top
;
1690 w
= surf
->desc
.Width
;
1691 h
= surf
->desc
.Height
;
1693 d3dcolor_to_pipe_color_union(&rgba
, color
);
1695 fallback
= !(surf
->base
.info
.bind
& PIPE_BIND_RENDER_TARGET
);
1698 psurf
= NineSurface9_GetSurface(surf
, 0);
1704 pipe
->clear_render_target(pipe
, psurf
, &rgba
, x
, y
, w
, h
);
1706 D3DLOCKED_RECT lock
;
1707 union util_color uc
;
1709 /* XXX: lock pRect and fix util_fill_rect */
1710 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, 0);
1713 util_pack_color_ub(color
>> 16, color
>> 8, color
>> 0, color
>> 24,
1714 surf
->base
.info
.format
, &uc
);
1715 util_fill_rect(lock
.pBits
, surf
->base
.info
.format
,lock
.Pitch
,
1717 NineSurface9_UnlockRect(surf
);
1724 NineDevice9_CreateOffscreenPlainSurface( struct NineDevice9
*This
,
1729 IDirect3DSurface9
**ppSurface
,
1730 HANDLE
*pSharedHandle
)
1734 DBG("This=%p Width=%u Height=%u Format=%s(0x%x) Pool=%u "
1735 "ppSurface=%p pSharedHandle=%p\n", This
,
1736 Width
, Height
, d3dformat_to_string(Format
), Format
, Pool
,
1737 ppSurface
, pSharedHandle
);
1740 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
1741 || Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1742 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1744 /* Can be used with StretchRect and ColorFill. It's also always lockable.
1746 hr
= create_zs_or_rt_surface(This
, 2, Pool
, Width
, Height
,
1748 D3DMULTISAMPLE_NONE
, 0,
1750 ppSurface
, pSharedHandle
);
1752 DBG("Failed to create surface.\n");
1757 NineDevice9_SetRenderTarget( struct NineDevice9
*This
,
1758 DWORD RenderTargetIndex
,
1759 IDirect3DSurface9
*pRenderTarget
)
1761 struct NineSurface9
*rt
= NineSurface9(pRenderTarget
);
1762 const unsigned i
= RenderTargetIndex
;
1764 DBG("This=%p RenderTargetIndex=%u pRenderTarget=%p\n", This
,
1765 RenderTargetIndex
, pRenderTarget
);
1767 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1768 user_assert(i
!= 0 || pRenderTarget
, D3DERR_INVALIDCALL
);
1769 user_assert(!pRenderTarget
||
1770 rt
->desc
.Usage
& D3DUSAGE_RENDERTARGET
, D3DERR_INVALIDCALL
);
1773 This
->state
.viewport
.X
= 0;
1774 This
->state
.viewport
.Y
= 0;
1775 This
->state
.viewport
.Width
= rt
->desc
.Width
;
1776 This
->state
.viewport
.Height
= rt
->desc
.Height
;
1777 This
->state
.viewport
.MinZ
= 0.0f
;
1778 This
->state
.viewport
.MaxZ
= 1.0f
;
1780 This
->state
.scissor
.minx
= 0;
1781 This
->state
.scissor
.miny
= 0;
1782 This
->state
.scissor
.maxx
= rt
->desc
.Width
;
1783 This
->state
.scissor
.maxy
= rt
->desc
.Height
;
1785 This
->state
.changed
.group
|= NINE_STATE_VIEWPORT
| NINE_STATE_SCISSOR
;
1788 if (This
->state
.rt
[i
] != NineSurface9(pRenderTarget
)) {
1789 nine_bind(&This
->state
.rt
[i
], pRenderTarget
);
1790 This
->state
.changed
.group
|= NINE_STATE_FB
;
1796 NineDevice9_GetRenderTarget( struct NineDevice9
*This
,
1797 DWORD RenderTargetIndex
,
1798 IDirect3DSurface9
**ppRenderTarget
)
1800 const unsigned i
= RenderTargetIndex
;
1802 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1803 user_assert(ppRenderTarget
, D3DERR_INVALIDCALL
);
1805 *ppRenderTarget
= (IDirect3DSurface9
*)This
->state
.rt
[i
];
1806 if (!This
->state
.rt
[i
])
1807 return D3DERR_NOTFOUND
;
1809 NineUnknown_AddRef(NineUnknown(This
->state
.rt
[i
]));
1814 NineDevice9_SetDepthStencilSurface( struct NineDevice9
*This
,
1815 IDirect3DSurface9
*pNewZStencil
)
1817 DBG("This=%p pNewZStencil=%p\n", This
, pNewZStencil
);
1819 if (This
->state
.ds
!= NineSurface9(pNewZStencil
)) {
1820 nine_bind(&This
->state
.ds
, pNewZStencil
);
1821 This
->state
.changed
.group
|= NINE_STATE_FB
;
1827 NineDevice9_GetDepthStencilSurface( struct NineDevice9
*This
,
1828 IDirect3DSurface9
**ppZStencilSurface
)
1830 user_assert(ppZStencilSurface
, D3DERR_INVALIDCALL
);
1832 *ppZStencilSurface
= (IDirect3DSurface9
*)This
->state
.ds
;
1833 if (!This
->state
.ds
)
1834 return D3DERR_NOTFOUND
;
1836 NineUnknown_AddRef(NineUnknown(This
->state
.ds
));
1841 NineDevice9_BeginScene( struct NineDevice9
*This
)
1843 DBG("This=%p\n", This
);
1844 user_assert(!This
->in_scene
, D3DERR_INVALIDCALL
);
1845 This
->in_scene
= TRUE
;
1846 /* Do we want to do anything else here ? */
1851 NineDevice9_EndScene( struct NineDevice9
*This
)
1853 DBG("This=%p\n", This
);
1854 user_assert(This
->in_scene
, D3DERR_INVALIDCALL
);
1855 This
->in_scene
= FALSE
;
1860 NineDevice9_Clear( struct NineDevice9
*This
,
1862 const D3DRECT
*pRects
,
1868 const int sRGB
= This
->state
.rs
[D3DRS_SRGBWRITEENABLE
] ? 1 : 0;
1869 struct pipe_surface
*cbuf
, *zsbuf
;
1870 struct pipe_context
*pipe
= This
->pipe
;
1871 struct NineSurface9
*zsbuf_surf
= This
->state
.ds
;
1872 struct NineSurface9
*rt
;
1875 union pipe_color_union rgba
;
1876 unsigned rt_mask
= 0;
1879 DBG("This=%p Count=%u pRects=%p Flags=%x Color=%08x Z=%f Stencil=%x\n",
1880 This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1882 user_assert(This
->state
.ds
|| !(Flags
& NINED3DCLEAR_DEPTHSTENCIL
),
1883 D3DERR_INVALIDCALL
);
1884 user_assert(!(Flags
& D3DCLEAR_STENCIL
) ||
1886 util_format_is_depth_and_stencil(zsbuf_surf
->base
.info
.format
)),
1887 D3DERR_INVALIDCALL
);
1889 user_assert((Count
&& pRects
) || (!Count
&& !pRects
), D3DERR_INVALIDCALL
);
1891 user_warn((pRects
&& !Count
) || (!pRects
&& Count
));
1892 if (pRects
&& !Count
)
1898 nine_update_state_framebuffer(This
);
1900 if (Flags
& D3DCLEAR_TARGET
) bufs
|= PIPE_CLEAR_COLOR
;
1901 /* Ignore Z buffer if not bound */
1902 if (This
->state
.fb
.zsbuf
!= NULL
) {
1903 if (Flags
& D3DCLEAR_ZBUFFER
) bufs
|= PIPE_CLEAR_DEPTH
;
1904 if (Flags
& D3DCLEAR_STENCIL
) bufs
|= PIPE_CLEAR_STENCIL
;
1908 d3dcolor_to_pipe_color_union(&rgba
, Color
);
1910 rect
.x1
= This
->state
.viewport
.X
;
1911 rect
.y1
= This
->state
.viewport
.Y
;
1912 rect
.x2
= This
->state
.viewport
.Width
+ rect
.x1
;
1913 rect
.y2
= This
->state
.viewport
.Height
+ rect
.y1
;
1915 /* Both rectangles apply, which is weird, but that's D3D9. */
1916 if (This
->state
.rs
[D3DRS_SCISSORTESTENABLE
]) {
1917 rect
.x1
= MAX2(rect
.x1
, This
->state
.scissor
.minx
);
1918 rect
.y1
= MAX2(rect
.y1
, This
->state
.scissor
.miny
);
1919 rect
.x2
= MIN2(rect
.x2
, This
->state
.scissor
.maxx
);
1920 rect
.y2
= MIN2(rect
.y2
, This
->state
.scissor
.maxy
);
1924 /* Maybe apps like to specify a large rect ? */
1925 if (pRects
[0].x1
<= rect
.x1
&& pRects
[0].x2
>= rect
.x2
&&
1926 pRects
[0].y1
<= rect
.y1
&& pRects
[0].y2
>= rect
.y2
) {
1927 DBG("First rect covers viewport.\n");
1933 if (rect
.x1
>= This
->state
.fb
.width
|| rect
.y1
>= This
->state
.fb
.height
)
1936 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
1937 if (This
->state
.rt
[i
] && This
->state
.rt
[i
]->desc
.Format
!= D3DFMT_NULL
)
1941 /* fast path, clears everything at once */
1943 (!(bufs
& PIPE_CLEAR_COLOR
) || (rt_mask
== This
->state
.rt_mask
)) &&
1944 rect
.x1
== 0 && rect
.y1
== 0 &&
1945 /* Case we clear only render target. Check clear region vs rt. */
1946 ((!(bufs
& (PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
)) &&
1947 rect
.x2
>= This
->state
.fb
.width
&&
1948 rect
.y2
>= This
->state
.fb
.height
) ||
1949 /* Case we clear depth buffer (and eventually rt too).
1950 * depth buffer size is always >= rt size. Compare to clear region */
1951 ((bufs
& (PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
)) &&
1952 rect
.x2
>= zsbuf_surf
->desc
.Width
&&
1953 rect
.y2
>= zsbuf_surf
->desc
.Height
))) {
1954 DBG("Clear fast path\n");
1955 pipe
->clear(pipe
, bufs
, &rgba
, Z
, Stencil
);
1964 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
1965 rt
= This
->state
.rt
[i
];
1966 if (!rt
|| rt
->desc
.Format
== D3DFMT_NULL
||
1967 !(Flags
& D3DCLEAR_TARGET
))
1968 continue; /* save space, compiler should hoist this */
1969 cbuf
= NineSurface9_GetSurface(rt
, sRGB
);
1970 for (r
= 0; r
< Count
; ++r
) {
1971 /* Don't trust users to pass these in the right order. */
1972 unsigned x1
= MIN2(pRects
[r
].x1
, pRects
[r
].x2
);
1973 unsigned y1
= MIN2(pRects
[r
].y1
, pRects
[r
].y2
);
1974 unsigned x2
= MAX2(pRects
[r
].x1
, pRects
[r
].x2
);
1975 unsigned y2
= MAX2(pRects
[r
].y1
, pRects
[r
].y2
);
1977 /* Drop negative rectangles (like wine expects). */
1978 if (pRects
[r
].x1
> pRects
[r
].x2
) continue;
1979 if (pRects
[r
].y1
> pRects
[r
].y2
) continue;
1982 x1
= MAX2(x1
, rect
.x1
);
1983 y1
= MAX2(y1
, rect
.y1
);
1984 x2
= MIN3(x2
, rect
.x2
, rt
->desc
.Width
);
1985 y2
= MIN3(y2
, rect
.y2
, rt
->desc
.Height
);
1987 DBG("Clearing (%u..%u)x(%u..%u)\n", x1
, x2
, y1
, y2
);
1988 pipe
->clear_render_target(pipe
, cbuf
, &rgba
,
1989 x1
, y1
, x2
- x1
, y2
- y1
);
1992 if (!(Flags
& NINED3DCLEAR_DEPTHSTENCIL
))
1995 bufs
&= PIPE_CLEAR_DEPTHSTENCIL
;
1997 for (r
= 0; r
< Count
; ++r
) {
1998 unsigned x1
= MIN2(pRects
[r
].x1
, pRects
[r
].x2
);
1999 unsigned y1
= MIN2(pRects
[r
].y1
, pRects
[r
].y2
);
2000 unsigned x2
= MAX2(pRects
[r
].x1
, pRects
[r
].x2
);
2001 unsigned y2
= MAX2(pRects
[r
].y1
, pRects
[r
].y2
);
2003 /* Drop negative rectangles. */
2004 if (pRects
[r
].x1
> pRects
[r
].x2
) continue;
2005 if (pRects
[r
].y1
> pRects
[r
].y2
) continue;
2008 x1
= MIN2(x1
, rect
.x1
);
2009 y1
= MIN2(y1
, rect
.y1
);
2010 x2
= MIN3(x2
, rect
.x2
, zsbuf_surf
->desc
.Width
);
2011 y2
= MIN3(y2
, rect
.y2
, zsbuf_surf
->desc
.Height
);
2013 zsbuf
= NineSurface9_GetSurface(zsbuf_surf
, 0);
2015 pipe
->clear_depth_stencil(pipe
, zsbuf
, bufs
, Z
, Stencil
,
2016 x1
, y1
, x2
- x1
, y2
- y1
);
2022 NineDevice9_SetTransform( struct NineDevice9
*This
,
2023 D3DTRANSFORMSTATETYPE State
,
2024 const D3DMATRIX
*pMatrix
)
2026 struct nine_state
*state
= This
->update
;
2027 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
2029 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2031 user_assert(M
, D3DERR_INVALIDCALL
);
2034 state
->ff
.changed
.transform
[State
/ 32] |= 1 << (State
% 32);
2035 state
->changed
.group
|= NINE_STATE_FF
;
2041 NineDevice9_GetTransform( struct NineDevice9
*This
,
2042 D3DTRANSFORMSTATETYPE State
,
2043 D3DMATRIX
*pMatrix
)
2045 D3DMATRIX
*M
= nine_state_access_transform(&This
->state
, State
, FALSE
);
2046 user_assert(M
, D3DERR_INVALIDCALL
);
2052 NineDevice9_MultiplyTransform( struct NineDevice9
*This
,
2053 D3DTRANSFORMSTATETYPE State
,
2054 const D3DMATRIX
*pMatrix
)
2056 struct nine_state
*state
= This
->update
;
2058 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
2060 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2062 user_assert(M
, D3DERR_INVALIDCALL
);
2064 nine_d3d_matrix_matrix_mul(&T
, pMatrix
, M
);
2065 return NineDevice9_SetTransform(This
, State
, &T
);
2069 NineDevice9_SetViewport( struct NineDevice9
*This
,
2070 const D3DVIEWPORT9
*pViewport
)
2072 struct nine_state
*state
= This
->update
;
2074 DBG("X=%u Y=%u W=%u H=%u MinZ=%f MaxZ=%f\n",
2075 pViewport
->X
, pViewport
->Y
, pViewport
->Width
, pViewport
->Height
,
2076 pViewport
->MinZ
, pViewport
->MaxZ
);
2078 state
->viewport
= *pViewport
;
2079 state
->changed
.group
|= NINE_STATE_VIEWPORT
;
2085 NineDevice9_GetViewport( struct NineDevice9
*This
,
2086 D3DVIEWPORT9
*pViewport
)
2088 *pViewport
= This
->state
.viewport
;
2093 NineDevice9_SetMaterial( struct NineDevice9
*This
,
2094 const D3DMATERIAL9
*pMaterial
)
2096 struct nine_state
*state
= This
->update
;
2098 DBG("This=%p pMaterial=%p\n", This
, pMaterial
);
2100 nine_dump_D3DMATERIAL9(DBG_FF
, pMaterial
);
2102 user_assert(pMaterial
, E_POINTER
);
2104 state
->ff
.material
= *pMaterial
;
2105 state
->changed
.group
|= NINE_STATE_FF_MATERIAL
;
2111 NineDevice9_GetMaterial( struct NineDevice9
*This
,
2112 D3DMATERIAL9
*pMaterial
)
2114 user_assert(pMaterial
, E_POINTER
);
2115 *pMaterial
= This
->state
.ff
.material
;
2120 NineDevice9_SetLight( struct NineDevice9
*This
,
2122 const D3DLIGHT9
*pLight
)
2124 struct nine_state
*state
= This
->update
;
2126 DBG("This=%p Index=%u pLight=%p\n", This
, Index
, pLight
);
2128 nine_dump_D3DLIGHT9(DBG_FF
, pLight
);
2130 user_assert(pLight
, D3DERR_INVALIDCALL
);
2131 user_assert(pLight
->Type
< NINED3DLIGHT_INVALID
, D3DERR_INVALIDCALL
);
2133 user_assert(Index
< NINE_MAX_LIGHTS
, D3DERR_INVALIDCALL
); /* sanity */
2135 if (Index
>= state
->ff
.num_lights
) {
2136 unsigned n
= state
->ff
.num_lights
;
2137 unsigned N
= Index
+ 1;
2139 state
->ff
.light
= REALLOC(state
->ff
.light
, n
* sizeof(D3DLIGHT9
),
2140 N
* sizeof(D3DLIGHT9
));
2141 if (!state
->ff
.light
)
2142 return E_OUTOFMEMORY
;
2143 state
->ff
.num_lights
= N
;
2145 for (; n
< Index
; ++n
) {
2146 memset(&state
->ff
.light
[n
], 0, sizeof(D3DLIGHT9
));
2147 state
->ff
.light
[n
].Type
= (D3DLIGHTTYPE
)NINED3DLIGHT_INVALID
;
2150 state
->ff
.light
[Index
] = *pLight
;
2152 if (pLight
->Type
== D3DLIGHT_SPOT
&& pLight
->Theta
>= pLight
->Phi
) {
2153 DBG("Warning: clamping D3DLIGHT9.Theta\n");
2154 state
->ff
.light
[Index
].Theta
= state
->ff
.light
[Index
].Phi
;
2156 if (pLight
->Type
!= D3DLIGHT_DIRECTIONAL
&&
2157 pLight
->Attenuation0
== 0.0f
&&
2158 pLight
->Attenuation1
== 0.0f
&&
2159 pLight
->Attenuation2
== 0.0f
) {
2160 DBG("Warning: all D3DLIGHT9.Attenuation[i] are 0\n");
2163 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2169 NineDevice9_GetLight( struct NineDevice9
*This
,
2173 const struct nine_state
*state
= &This
->state
;
2175 user_assert(pLight
, D3DERR_INVALIDCALL
);
2176 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2177 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2178 D3DERR_INVALIDCALL
);
2180 *pLight
= state
->ff
.light
[Index
];
2186 NineDevice9_LightEnable( struct NineDevice9
*This
,
2190 struct nine_state
*state
= This
->update
;
2193 DBG("This=%p Index=%u Enable=%i\n", This
, Index
, Enable
);
2195 if (Index
>= state
->ff
.num_lights
||
2196 state
->ff
.light
[Index
].Type
== NINED3DLIGHT_INVALID
) {
2197 /* This should create a default light. */
2199 memset(&light
, 0, sizeof(light
));
2200 light
.Type
= D3DLIGHT_DIRECTIONAL
;
2201 light
.Diffuse
.r
= 1.0f
;
2202 light
.Diffuse
.g
= 1.0f
;
2203 light
.Diffuse
.b
= 1.0f
;
2204 light
.Direction
.z
= 1.0f
;
2205 NineDevice9_SetLight(This
, Index
, &light
);
2207 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2209 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
) {
2210 if (state
->ff
.active_light
[i
] == Index
)
2215 if (i
< state
->ff
.num_lights_active
)
2217 /* XXX wine thinks this should still succeed:
2219 user_assert(i
< NINE_MAX_LIGHTS_ACTIVE
, D3DERR_INVALIDCALL
);
2221 state
->ff
.active_light
[i
] = Index
;
2222 state
->ff
.num_lights_active
++;
2224 if (i
== state
->ff
.num_lights_active
)
2226 --state
->ff
.num_lights_active
;
2227 for (; i
< state
->ff
.num_lights_active
; ++i
)
2228 state
->ff
.active_light
[i
] = state
->ff
.active_light
[i
+ 1];
2230 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2236 NineDevice9_GetLightEnable( struct NineDevice9
*This
,
2240 const struct nine_state
*state
= &This
->state
;
2243 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2244 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2245 D3DERR_INVALIDCALL
);
2247 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
)
2248 if (state
->ff
.active_light
[i
] == Index
)
2251 *pEnable
= i
!= state
->ff
.num_lights_active
? 128 : 0; // Taken from wine
2257 NineDevice9_SetClipPlane( struct NineDevice9
*This
,
2259 const float *pPlane
)
2261 struct nine_state
*state
= This
->update
;
2263 user_assert(pPlane
, D3DERR_INVALIDCALL
);
2265 DBG("This=%p Index=%u pPlane=%f %f %f %f\n", This
, Index
,
2266 pPlane
[0], pPlane
[1],
2267 pPlane
[2], pPlane
[3]);
2269 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2271 memcpy(&state
->clip
.ucp
[Index
][0], pPlane
, sizeof(state
->clip
.ucp
[0]));
2272 state
->changed
.ucp
|= 1 << Index
;
2278 NineDevice9_GetClipPlane( struct NineDevice9
*This
,
2282 const struct nine_state
*state
= &This
->state
;
2284 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2286 memcpy(pPlane
, &state
->clip
.ucp
[Index
][0], sizeof(state
->clip
.ucp
[0]));
2290 #define RESZ_CODE 0x7fa05000
2293 NineDevice9_ResolveZ( struct NineDevice9
*This
)
2295 struct nine_state
*state
= &This
->state
;
2296 const struct util_format_description
*desc
;
2297 struct NineSurface9
*source
= state
->ds
;
2298 struct NineBaseTexture9
*destination
= state
->texture
[0];
2299 struct pipe_resource
*src
, *dst
;
2300 struct pipe_blit_info blit
;
2302 DBG("RESZ resolve\n");
2304 user_assert(source
&& destination
&&
2305 destination
->base
.type
== D3DRTYPE_TEXTURE
, D3DERR_INVALIDCALL
);
2307 src
= source
->base
.resource
;
2308 dst
= destination
->base
.resource
;
2310 user_assert(src
&& dst
, D3DERR_INVALIDCALL
);
2312 /* check dst is depth format. we know already for src */
2313 desc
= util_format_description(dst
->format
);
2314 user_assert(desc
->colorspace
== UTIL_FORMAT_COLORSPACE_ZS
, D3DERR_INVALIDCALL
);
2316 memset(&blit
, 0, sizeof(blit
));
2317 blit
.src
.resource
= src
;
2319 blit
.src
.format
= src
->format
;
2321 blit
.src
.box
.depth
= 1;
2324 blit
.src
.box
.width
= src
->width0
;
2325 blit
.src
.box
.height
= src
->height0
;
2327 blit
.dst
.resource
= dst
;
2329 blit
.dst
.format
= dst
->format
;
2331 blit
.dst
.box
.depth
= 1;
2334 blit
.dst
.box
.width
= dst
->width0
;
2335 blit
.dst
.box
.height
= dst
->height0
;
2337 blit
.mask
= PIPE_MASK_ZS
;
2338 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
2339 blit
.scissor_enable
= FALSE
;
2341 This
->pipe
->blit(This
->pipe
, &blit
);
2345 #define ALPHA_TO_COVERAGE_ENABLE MAKEFOURCC('A', '2', 'M', '1')
2346 #define ALPHA_TO_COVERAGE_DISABLE MAKEFOURCC('A', '2', 'M', '0')
2349 NineDevice9_SetRenderState( struct NineDevice9
*This
,
2350 D3DRENDERSTATETYPE State
,
2353 struct nine_state
*state
= This
->update
;
2355 DBG("This=%p State=%u(%s) Value=%08x\n", This
,
2356 State
, nine_d3drs_to_string(State
), Value
);
2358 /* Amd hacks (equivalent to GL extensions) */
2359 if (State
== D3DRS_POINTSIZE
) {
2360 if (Value
== RESZ_CODE
)
2361 return NineDevice9_ResolveZ(This
);
2363 if (Value
== ALPHA_TO_COVERAGE_ENABLE
||
2364 Value
== ALPHA_TO_COVERAGE_DISABLE
) {
2365 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
== ALPHA_TO_COVERAGE_ENABLE
);
2366 state
->changed
.group
|= NINE_STATE_BLEND
;
2372 if (State
== D3DRS_ADAPTIVETESS_Y
&&
2373 (Value
== D3DFMT_ATOC
|| (Value
== D3DFMT_UNKNOWN
&& state
->rs
[NINED3DRS_ALPHACOVERAGE
]))) {
2374 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
== D3DFMT_ATOC
);
2375 state
->changed
.group
|= NINE_STATE_BLEND
;
2379 user_assert(State
< Elements(state
->rs
), D3DERR_INVALIDCALL
);
2381 if (likely(state
->rs
[State
] != Value
) || unlikely(This
->is_recording
)) {
2382 state
->rs
[State
] = Value
;
2383 state
->changed
.rs
[State
/ 32] |= 1 << (State
% 32);
2384 state
->changed
.group
|= nine_render_state_group
[State
];
2391 NineDevice9_GetRenderState( struct NineDevice9
*This
,
2392 D3DRENDERSTATETYPE State
,
2395 user_assert(State
< Elements(This
->state
.rs
), D3DERR_INVALIDCALL
);
2397 *pValue
= This
->state
.rs
[State
];
2402 NineDevice9_CreateStateBlock( struct NineDevice9
*This
,
2403 D3DSTATEBLOCKTYPE Type
,
2404 IDirect3DStateBlock9
**ppSB
)
2406 struct NineStateBlock9
*nsb
;
2407 struct nine_state
*dst
;
2409 enum nine_stateblock_type type
;
2412 DBG("This=%p Type=%u ppSB=%p\n", This
, Type
, ppSB
);
2414 user_assert(Type
== D3DSBT_ALL
||
2415 Type
== D3DSBT_VERTEXSTATE
||
2416 Type
== D3DSBT_PIXELSTATE
, D3DERR_INVALIDCALL
);
2419 case D3DSBT_VERTEXSTATE
: type
= NINESBT_VERTEXSTATE
; break;
2420 case D3DSBT_PIXELSTATE
: type
= NINESBT_PIXELSTATE
; break;
2426 hr
= NineStateBlock9_new(This
, &nsb
, type
);
2429 *ppSB
= (IDirect3DStateBlock9
*)nsb
;
2432 dst
->changed
.group
=
2433 NINE_STATE_TEXTURE
|
2436 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_VERTEXSTATE
) {
2437 dst
->changed
.group
|=
2438 NINE_STATE_FF_LIGHTING
|
2439 NINE_STATE_VS
| NINE_STATE_VS_CONST
|
2441 /* TODO: texture/sampler state */
2442 memcpy(dst
->changed
.rs
,
2443 nine_render_states_vertex
, sizeof(dst
->changed
.rs
));
2444 nine_ranges_insert(&dst
->changed
.vs_const_f
, 0, This
->max_vs_const_f
,
2446 dst
->changed
.vs_const_i
= 0xffff;
2447 dst
->changed
.vs_const_b
= 0xffff;
2448 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2449 dst
->changed
.sampler
[s
] |= 1 << D3DSAMP_DMAPOFFSET
;
2450 if (This
->state
.ff
.num_lights
) {
2451 dst
->ff
.num_lights
= This
->state
.ff
.num_lights
;
2452 /* zero'd -> light type won't be NINED3DLIGHT_INVALID, so
2453 * all currently existing lights will be captured
2455 dst
->ff
.light
= CALLOC(This
->state
.ff
.num_lights
,
2457 if (!dst
->ff
.light
) {
2458 nine_bind(ppSB
, NULL
);
2459 return E_OUTOFMEMORY
;
2463 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_PIXELSTATE
) {
2464 dst
->changed
.group
|=
2465 NINE_STATE_PS
| NINE_STATE_PS_CONST
;
2466 /* TODO: texture/sampler state */
2467 memcpy(dst
->changed
.rs
,
2468 nine_render_states_pixel
, sizeof(dst
->changed
.rs
));
2469 nine_ranges_insert(&dst
->changed
.ps_const_f
, 0, This
->max_ps_const_f
,
2471 dst
->changed
.ps_const_i
= 0xffff;
2472 dst
->changed
.ps_const_b
= 0xffff;
2473 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2474 dst
->changed
.sampler
[s
] |= 0x1ffe;
2476 if (Type
== D3DSBT_ALL
) {
2477 dst
->changed
.group
|=
2478 NINE_STATE_VIEWPORT
|
2479 NINE_STATE_SCISSOR
|
2480 NINE_STATE_RASTERIZER
|
2484 NINE_STATE_MATERIAL
|
2485 NINE_STATE_BLEND_COLOR
|
2486 NINE_STATE_SAMPLE_MASK
;
2487 memset(dst
->changed
.rs
, ~0, (D3DRS_COUNT
/ 32) * sizeof(uint32_t));
2488 dst
->changed
.rs
[D3DRS_LAST
/ 32] |= (1 << (D3DRS_COUNT
% 32)) - 1;
2489 dst
->changed
.vtxbuf
= (1ULL << This
->caps
.MaxStreams
) - 1;
2490 dst
->changed
.stream_freq
= dst
->changed
.vtxbuf
;
2491 dst
->changed
.ucp
= (1 << PIPE_MAX_CLIP_PLANES
) - 1;
2492 dst
->changed
.texture
= (1 << NINE_MAX_SAMPLERS
) - 1;
2494 NineStateBlock9_Capture(NineStateBlock9(*ppSB
));
2496 /* TODO: fixed function state */
2502 NineDevice9_BeginStateBlock( struct NineDevice9
*This
)
2506 DBG("This=%p\n", This
);
2508 user_assert(!This
->record
, D3DERR_INVALIDCALL
);
2510 hr
= NineStateBlock9_new(This
, &This
->record
, NINESBT_CUSTOM
);
2513 NineUnknown_ConvertRefToBind(NineUnknown(This
->record
));
2515 This
->update
= &This
->record
->state
;
2516 This
->is_recording
= TRUE
;
2522 NineDevice9_EndStateBlock( struct NineDevice9
*This
,
2523 IDirect3DStateBlock9
**ppSB
)
2525 DBG("This=%p ppSB=%p\n", This
, ppSB
);
2527 user_assert(This
->record
, D3DERR_INVALIDCALL
);
2529 This
->update
= &This
->state
;
2530 This
->is_recording
= FALSE
;
2532 NineUnknown_AddRef(NineUnknown(This
->record
));
2533 *ppSB
= (IDirect3DStateBlock9
*)This
->record
;
2534 NineUnknown_Unbind(NineUnknown(This
->record
));
2535 This
->record
= NULL
;
2541 NineDevice9_SetClipStatus( struct NineDevice9
*This
,
2542 const D3DCLIPSTATUS9
*pClipStatus
)
2544 STUB(D3DERR_INVALIDCALL
);
2548 NineDevice9_GetClipStatus( struct NineDevice9
*This
,
2549 D3DCLIPSTATUS9
*pClipStatus
)
2551 STUB(D3DERR_INVALIDCALL
);
2555 NineDevice9_GetTexture( struct NineDevice9
*This
,
2557 IDirect3DBaseTexture9
**ppTexture
)
2559 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2560 Stage
== D3DDMAPSAMPLER
||
2561 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2562 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2563 user_assert(ppTexture
, D3DERR_INVALIDCALL
);
2565 if (Stage
>= D3DDMAPSAMPLER
)
2566 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2568 *ppTexture
= (IDirect3DBaseTexture9
*)This
->state
.texture
[Stage
];
2570 if (This
->state
.texture
[Stage
])
2571 NineUnknown_AddRef(NineUnknown(This
->state
.texture
[Stage
]));
2576 NineDevice9_SetTexture( struct NineDevice9
*This
,
2578 IDirect3DBaseTexture9
*pTexture
)
2580 struct nine_state
*state
= This
->update
;
2581 struct NineBaseTexture9
*tex
= NineBaseTexture9(pTexture
);
2583 DBG("This=%p Stage=%u pTexture=%p\n", This
, Stage
, pTexture
);
2585 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2586 Stage
== D3DDMAPSAMPLER
||
2587 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2588 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2589 user_assert(!tex
|| (tex
->base
.pool
!= D3DPOOL_SCRATCH
&&
2590 tex
->base
.pool
!= D3DPOOL_SYSTEMMEM
), D3DERR_INVALIDCALL
);
2592 if (Stage
>= D3DDMAPSAMPLER
)
2593 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2595 if (!This
->is_recording
) {
2596 struct NineBaseTexture9
*old
= state
->texture
[Stage
];
2600 state
->samplers_shadow
&= ~(1 << Stage
);
2602 state
->samplers_shadow
|= tex
->shadow
<< Stage
;
2604 if ((tex
->managed
.dirty
| tex
->dirty_mip
) && LIST_IS_EMPTY(&tex
->list
))
2605 list_add(&tex
->list
, &This
->update_textures
);
2612 nine_bind(&state
->texture
[Stage
], pTexture
);
2614 state
->changed
.texture
|= 1 << Stage
;
2615 state
->changed
.group
|= NINE_STATE_TEXTURE
;
2621 NineDevice9_GetTextureStageState( struct NineDevice9
*This
,
2623 D3DTEXTURESTAGESTATETYPE Type
,
2626 const struct nine_state
*state
= &This
->state
;
2628 user_assert(Stage
< Elements(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2629 user_assert(Type
< Elements(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2631 *pValue
= state
->ff
.tex_stage
[Stage
][Type
];
2637 NineDevice9_SetTextureStageState( struct NineDevice9
*This
,
2639 D3DTEXTURESTAGESTATETYPE Type
,
2642 struct nine_state
*state
= This
->update
;
2643 int bumpmap_index
= -1;
2645 DBG("Stage=%u Type=%u Value=%08x\n", Stage
, Type
, Value
);
2646 nine_dump_D3DTSS_value(DBG_FF
, Type
, Value
);
2648 user_assert(Stage
< Elements(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2649 user_assert(Type
< Elements(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2651 state
->ff
.tex_stage
[Stage
][Type
] = Value
;
2653 case D3DTSS_BUMPENVMAT00
:
2654 bumpmap_index
= 4 * Stage
;
2656 case D3DTSS_BUMPENVMAT10
:
2657 bumpmap_index
= 4 * Stage
+ 1;
2659 case D3DTSS_BUMPENVMAT01
:
2660 bumpmap_index
= 4 * Stage
+ 2;
2662 case D3DTSS_BUMPENVMAT11
:
2663 bumpmap_index
= 4 * Stage
+ 3;
2665 case D3DTSS_BUMPENVLSCALE
:
2666 bumpmap_index
= 4 * 8 + 2 * Stage
;
2668 case D3DTSS_BUMPENVLOFFSET
:
2669 bumpmap_index
= 4 * 8 + 2 * Stage
+ 1;
2671 case D3DTSS_TEXTURETRANSFORMFLAGS
:
2672 state
->changed
.group
|= NINE_STATE_PS1X_SHADER
;
2678 if (bumpmap_index
>= 0) {
2679 state
->bumpmap_vars
[bumpmap_index
] = Value
;
2680 state
->changed
.group
|= NINE_STATE_PS_CONST
;
2683 state
->changed
.group
|= NINE_STATE_FF_PSSTAGES
;
2684 state
->ff
.changed
.tex_stage
[Stage
][Type
/ 32] |= 1 << (Type
% 32);
2690 NineDevice9_GetSamplerState( struct NineDevice9
*This
,
2692 D3DSAMPLERSTATETYPE Type
,
2695 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2696 Sampler
== D3DDMAPSAMPLER
||
2697 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2698 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2700 if (Sampler
>= D3DDMAPSAMPLER
)
2701 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2703 *pValue
= This
->state
.samp
[Sampler
][Type
];
2708 NineDevice9_SetSamplerState( struct NineDevice9
*This
,
2710 D3DSAMPLERSTATETYPE Type
,
2713 struct nine_state
*state
= This
->update
;
2715 DBG("This=%p Sampler=%u Type=%s Value=%08x\n", This
,
2716 Sampler
, nine_D3DSAMP_to_str(Type
), Value
);
2718 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2719 Sampler
== D3DDMAPSAMPLER
||
2720 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2721 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2723 if (Sampler
>= D3DDMAPSAMPLER
)
2724 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2726 if (state
->samp
[Sampler
][Type
] != Value
|| unlikely(This
->is_recording
)) {
2727 state
->samp
[Sampler
][Type
] = Value
;
2728 state
->changed
.group
|= NINE_STATE_SAMPLER
;
2729 state
->changed
.sampler
[Sampler
] |= 1 << Type
;
2736 NineDevice9_ValidateDevice( struct NineDevice9
*This
,
2739 const struct nine_state
*state
= &This
->state
;
2741 unsigned w
= 0, h
= 0;
2743 DBG("This=%p pNumPasses=%p\n", This
, pNumPasses
);
2745 for (i
= 0; i
< Elements(state
->samp
); ++i
) {
2746 if (state
->samp
[i
][D3DSAMP_MINFILTER
] == D3DTEXF_NONE
||
2747 state
->samp
[i
][D3DSAMP_MAGFILTER
] == D3DTEXF_NONE
)
2748 return D3DERR_UNSUPPORTEDTEXTUREFILTER
;
2751 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2755 w
= state
->rt
[i
]->desc
.Width
;
2756 h
= state
->rt
[i
]->desc
.Height
;
2758 if (state
->rt
[i
]->desc
.Width
!= w
|| state
->rt
[i
]->desc
.Height
!= h
) {
2759 return D3DERR_CONFLICTINGRENDERSTATE
;
2763 (state
->rs
[D3DRS_ZENABLE
] || state
->rs
[D3DRS_STENCILENABLE
])) {
2765 (state
->ds
->desc
.Width
!= w
|| state
->ds
->desc
.Height
!= h
))
2766 return D3DERR_CONFLICTINGRENDERSTATE
;
2776 NineDevice9_SetPaletteEntries( struct NineDevice9
*This
,
2778 const PALETTEENTRY
*pEntries
)
2780 STUB(D3D_OK
); /* like wine */
2784 NineDevice9_GetPaletteEntries( struct NineDevice9
*This
,
2786 PALETTEENTRY
*pEntries
)
2788 STUB(D3DERR_INVALIDCALL
);
2792 NineDevice9_SetCurrentTexturePalette( struct NineDevice9
*This
,
2793 UINT PaletteNumber
)
2795 STUB(D3D_OK
); /* like wine */
2799 NineDevice9_GetCurrentTexturePalette( struct NineDevice9
*This
,
2800 UINT
*PaletteNumber
)
2802 STUB(D3DERR_INVALIDCALL
);
2806 NineDevice9_SetScissorRect( struct NineDevice9
*This
,
2809 struct nine_state
*state
= This
->update
;
2811 DBG("x=(%u..%u) y=(%u..%u)\n",
2812 pRect
->left
, pRect
->top
, pRect
->right
, pRect
->bottom
);
2814 state
->scissor
.minx
= pRect
->left
;
2815 state
->scissor
.miny
= pRect
->top
;
2816 state
->scissor
.maxx
= pRect
->right
;
2817 state
->scissor
.maxy
= pRect
->bottom
;
2819 state
->changed
.group
|= NINE_STATE_SCISSOR
;
2825 NineDevice9_GetScissorRect( struct NineDevice9
*This
,
2828 pRect
->left
= This
->state
.scissor
.minx
;
2829 pRect
->top
= This
->state
.scissor
.miny
;
2830 pRect
->right
= This
->state
.scissor
.maxx
;
2831 pRect
->bottom
= This
->state
.scissor
.maxy
;
2837 NineDevice9_SetSoftwareVertexProcessing( struct NineDevice9
*This
,
2840 STUB(D3DERR_INVALIDCALL
);
2844 NineDevice9_GetSoftwareVertexProcessing( struct NineDevice9
*This
)
2846 return !!(This
->params
.BehaviorFlags
& D3DCREATE_SOFTWARE_VERTEXPROCESSING
);
2850 NineDevice9_SetNPatchMode( struct NineDevice9
*This
,
2853 STUB(D3DERR_INVALIDCALL
);
2857 NineDevice9_GetNPatchMode( struct NineDevice9
*This
)
2863 init_draw_info(struct pipe_draw_info
*info
,
2864 struct NineDevice9
*dev
, D3DPRIMITIVETYPE type
, UINT count
)
2866 info
->mode
= d3dprimitivetype_to_pipe_prim(type
);
2867 info
->count
= prim_count_to_vertex_count(type
, count
);
2868 info
->start_instance
= 0;
2869 info
->instance_count
= 1;
2870 if (dev
->state
.stream_instancedata_mask
& dev
->state
.stream_usage_mask
)
2871 info
->instance_count
= MAX2(dev
->state
.stream_freq
[0] & 0x7FFFFF, 1);
2872 info
->primitive_restart
= FALSE
;
2873 info
->restart_index
= 0;
2874 info
->count_from_stream_output
= NULL
;
2875 info
->indirect
= NULL
;
2879 NineDevice9_DrawPrimitive( struct NineDevice9
*This
,
2880 D3DPRIMITIVETYPE PrimitiveType
,
2882 UINT PrimitiveCount
)
2884 struct pipe_draw_info info
;
2886 DBG("iface %p, PrimitiveType %u, StartVertex %u, PrimitiveCount %u\n",
2887 This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2889 nine_update_state(This
);
2891 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2892 info
.indexed
= FALSE
;
2893 info
.start
= StartVertex
;
2894 info
.index_bias
= 0;
2895 info
.min_index
= info
.start
;
2896 info
.max_index
= info
.count
- 1;
2898 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2904 NineDevice9_DrawIndexedPrimitive( struct NineDevice9
*This
,
2905 D3DPRIMITIVETYPE PrimitiveType
,
2906 INT BaseVertexIndex
,
2907 UINT MinVertexIndex
,
2910 UINT PrimitiveCount
)
2912 struct pipe_draw_info info
;
2914 DBG("iface %p, PrimitiveType %u, BaseVertexIndex %u, MinVertexIndex %u "
2915 "NumVertices %u, StartIndex %u, PrimitiveCount %u\n",
2916 This
, PrimitiveType
, BaseVertexIndex
, MinVertexIndex
, NumVertices
,
2917 StartIndex
, PrimitiveCount
);
2919 user_assert(This
->state
.idxbuf
, D3DERR_INVALIDCALL
);
2920 user_assert(This
->state
.vdecl
, D3DERR_INVALIDCALL
);
2922 nine_update_state(This
);
2924 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2925 info
.indexed
= TRUE
;
2926 info
.start
= StartIndex
;
2927 info
.index_bias
= BaseVertexIndex
;
2928 /* These don't include index bias: */
2929 info
.min_index
= MinVertexIndex
;
2930 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
2932 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2938 NineDevice9_DrawPrimitiveUP( struct NineDevice9
*This
,
2939 D3DPRIMITIVETYPE PrimitiveType
,
2940 UINT PrimitiveCount
,
2941 const void *pVertexStreamZeroData
,
2942 UINT VertexStreamZeroStride
)
2944 struct pipe_vertex_buffer vtxbuf
;
2945 struct pipe_draw_info info
;
2947 DBG("iface %p, PrimitiveType %u, PrimitiveCount %u, data %p, stride %u\n",
2948 This
, PrimitiveType
, PrimitiveCount
,
2949 pVertexStreamZeroData
, VertexStreamZeroStride
);
2951 user_assert(pVertexStreamZeroData
&& VertexStreamZeroStride
,
2952 D3DERR_INVALIDCALL
);
2954 nine_update_state(This
);
2956 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2957 info
.indexed
= FALSE
;
2959 info
.index_bias
= 0;
2961 info
.max_index
= info
.count
- 1;
2963 vtxbuf
.stride
= VertexStreamZeroStride
;
2964 vtxbuf
.buffer_offset
= 0;
2965 vtxbuf
.buffer
= NULL
;
2966 vtxbuf
.user_buffer
= pVertexStreamZeroData
;
2968 if (!This
->driver_caps
.user_vbufs
) {
2969 u_upload_data(This
->vertex_uploader
,
2971 (info
.max_index
+ 1) * VertexStreamZeroStride
, /* XXX */
2974 &vtxbuf
.buffer_offset
,
2976 u_upload_unmap(This
->vertex_uploader
);
2977 vtxbuf
.user_buffer
= NULL
;
2980 This
->pipe
->set_vertex_buffers(This
->pipe
, 0, 1, &vtxbuf
);
2982 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2984 NineDevice9_PauseRecording(This
);
2985 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
2986 NineDevice9_ResumeRecording(This
);
2988 pipe_resource_reference(&vtxbuf
.buffer
, NULL
);
2994 NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9
*This
,
2995 D3DPRIMITIVETYPE PrimitiveType
,
2996 UINT MinVertexIndex
,
2998 UINT PrimitiveCount
,
2999 const void *pIndexData
,
3000 D3DFORMAT IndexDataFormat
,
3001 const void *pVertexStreamZeroData
,
3002 UINT VertexStreamZeroStride
)
3004 struct pipe_draw_info info
;
3005 struct pipe_vertex_buffer vbuf
;
3006 struct pipe_index_buffer ibuf
;
3008 DBG("iface %p, PrimitiveType %u, MinVertexIndex %u, NumVertices %u "
3009 "PrimitiveCount %u, pIndexData %p, IndexDataFormat %u "
3010 "pVertexStreamZeroData %p, VertexStreamZeroStride %u\n",
3011 This
, PrimitiveType
, MinVertexIndex
, NumVertices
, PrimitiveCount
,
3012 pIndexData
, IndexDataFormat
,
3013 pVertexStreamZeroData
, VertexStreamZeroStride
);
3015 user_assert(pIndexData
&& pVertexStreamZeroData
, D3DERR_INVALIDCALL
);
3016 user_assert(VertexStreamZeroStride
, D3DERR_INVALIDCALL
);
3017 user_assert(IndexDataFormat
== D3DFMT_INDEX16
||
3018 IndexDataFormat
== D3DFMT_INDEX32
, D3DERR_INVALIDCALL
);
3020 nine_update_state(This
);
3022 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
3023 info
.indexed
= TRUE
;
3025 info
.index_bias
= 0;
3026 info
.min_index
= MinVertexIndex
;
3027 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
3029 vbuf
.stride
= VertexStreamZeroStride
;
3030 vbuf
.buffer_offset
= 0;
3032 vbuf
.user_buffer
= pVertexStreamZeroData
;
3034 ibuf
.index_size
= (IndexDataFormat
== D3DFMT_INDEX16
) ? 2 : 4;
3037 ibuf
.user_buffer
= pIndexData
;
3039 if (!This
->driver_caps
.user_vbufs
) {
3040 const unsigned base
= info
.min_index
* VertexStreamZeroStride
;
3041 u_upload_data(This
->vertex_uploader
,
3044 info
.min_index
+ 1) * VertexStreamZeroStride
, /* XXX */
3046 (const uint8_t *)vbuf
.user_buffer
+ base
,
3047 &vbuf
.buffer_offset
,
3049 u_upload_unmap(This
->vertex_uploader
);
3050 /* Won't be used: */
3051 vbuf
.buffer_offset
-= base
;
3052 vbuf
.user_buffer
= NULL
;
3054 if (!This
->driver_caps
.user_ibufs
) {
3055 u_upload_data(This
->index_uploader
,
3057 info
.count
* ibuf
.index_size
,
3062 u_upload_unmap(This
->index_uploader
);
3063 ibuf
.user_buffer
= NULL
;
3066 This
->pipe
->set_vertex_buffers(This
->pipe
, 0, 1, &vbuf
);
3067 This
->pipe
->set_index_buffer(This
->pipe
, &ibuf
);
3069 This
->pipe
->draw_vbo(This
->pipe
, &info
);
3071 pipe_resource_reference(&vbuf
.buffer
, NULL
);
3072 pipe_resource_reference(&ibuf
.buffer
, NULL
);
3074 NineDevice9_PauseRecording(This
);
3075 NineDevice9_SetIndices(This
, NULL
);
3076 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
3077 NineDevice9_ResumeRecording(This
);
3082 /* TODO: Write to pDestBuffer directly if vertex declaration contains
3086 NineDevice9_ProcessVertices( struct NineDevice9
*This
,
3090 IDirect3DVertexBuffer9
*pDestBuffer
,
3091 IDirect3DVertexDeclaration9
*pVertexDecl
,
3094 struct pipe_screen
*screen
= This
->screen
;
3095 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pVertexDecl
);
3096 struct NineVertexShader9
*vs
;
3097 struct pipe_resource
*resource
;
3098 struct pipe_stream_output_target
*target
;
3099 struct pipe_draw_info draw
;
3101 unsigned buffer_offset
, buffer_size
;
3103 DBG("This=%p SrcStartIndex=%u DestIndex=%u VertexCount=%u "
3104 "pDestBuffer=%p pVertexDecl=%p Flags=%d\n",
3105 This
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
,
3106 pVertexDecl
, Flags
);
3108 if (!screen
->get_param(screen
, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
))
3109 STUB(D3DERR_INVALIDCALL
);
3111 nine_update_state(This
);
3113 /* TODO: Create shader with stream output. */
3114 STUB(D3DERR_INVALIDCALL
);
3115 struct NineVertexBuffer9
*dst
= NineVertexBuffer9(pDestBuffer
);
3117 vs
= This
->state
.vs
? This
->state
.vs
: This
->ff
.vs
;
3119 buffer_size
= VertexCount
* vs
->so
->stride
[0];
3121 struct pipe_resource templ
;
3123 templ
.target
= PIPE_BUFFER
;
3124 templ
.format
= PIPE_FORMAT_R8_UNORM
;
3125 templ
.width0
= buffer_size
;
3127 templ
.bind
= PIPE_BIND_STREAM_OUTPUT
;
3128 templ
.usage
= PIPE_USAGE_STREAM
;
3129 templ
.height0
= templ
.depth0
= templ
.array_size
= 1;
3130 templ
.last_level
= templ
.nr_samples
= 0;
3132 resource
= This
->screen
->resource_create(This
->screen
, &templ
);
3134 return E_OUTOFMEMORY
;
3137 /* SO matches vertex declaration */
3138 resource
= NineVertexBuffer9_GetResource(dst
);
3139 buffer_offset
= DestIndex
* vs
->so
->stride
[0];
3141 target
= This
->pipe
->create_stream_output_target(This
->pipe
, resource
,
3145 pipe_resource_reference(&resource
, NULL
);
3146 return D3DERR_DRIVERINTERNALERROR
;
3150 hr
= NineVertexDeclaration9_new_from_fvf(This
, dst
->desc
.FVF
, &vdecl
);
3155 init_draw_info(&draw
, This
, D3DPT_POINTLIST
, VertexCount
);
3156 draw
.instance_count
= 1;
3157 draw
.indexed
= FALSE
;
3158 draw
.start
= SrcStartIndex
;
3159 draw
.index_bias
= 0;
3160 draw
.min_index
= SrcStartIndex
;
3161 draw
.max_index
= SrcStartIndex
+ VertexCount
- 1;
3163 This
->pipe
->set_stream_output_targets(This
->pipe
, 1, &target
, 0);
3164 This
->pipe
->draw_vbo(This
->pipe
, &draw
);
3165 This
->pipe
->set_stream_output_targets(This
->pipe
, 0, NULL
, 0);
3166 This
->pipe
->stream_output_target_destroy(This
->pipe
, target
);
3168 hr
= NineVertexDeclaration9_ConvertStreamOutput(vdecl
,
3169 dst
, DestIndex
, VertexCount
,
3172 pipe_resource_reference(&resource
, NULL
);
3174 NineUnknown_Release(NineUnknown(vdecl
));
3179 NineDevice9_CreateVertexDeclaration( struct NineDevice9
*This
,
3180 const D3DVERTEXELEMENT9
*pVertexElements
,
3181 IDirect3DVertexDeclaration9
**ppDecl
)
3183 struct NineVertexDeclaration9
*vdecl
;
3185 DBG("This=%p pVertexElements=%p ppDecl=%p\n",
3186 This
, pVertexElements
, ppDecl
);
3188 HRESULT hr
= NineVertexDeclaration9_new(This
, pVertexElements
, &vdecl
);
3190 *ppDecl
= (IDirect3DVertexDeclaration9
*)vdecl
;
3196 NineDevice9_SetVertexDeclaration( struct NineDevice9
*This
,
3197 IDirect3DVertexDeclaration9
*pDecl
)
3199 struct nine_state
*state
= This
->update
;
3200 BOOL was_programmable_vs
= This
->state
.programmable_vs
;
3202 DBG("This=%p pDecl=%p\n", This
, pDecl
);
3204 if (likely(!This
->is_recording
) && state
->vdecl
== NineVertexDeclaration9(pDecl
))
3207 nine_bind(&state
->vdecl
, pDecl
);
3209 This
->state
.programmable_vs
= This
->state
.vs
&& !(This
->state
.vdecl
&& This
->state
.vdecl
->position_t
);
3210 if (likely(!This
->is_recording
) && was_programmable_vs
!= This
->state
.programmable_vs
) {
3211 state
->commit
|= NINE_STATE_COMMIT_CONST_VS
;
3212 state
->changed
.group
|= NINE_STATE_VS
;
3215 state
->changed
.group
|= NINE_STATE_VDECL
;
3221 NineDevice9_GetVertexDeclaration( struct NineDevice9
*This
,
3222 IDirect3DVertexDeclaration9
**ppDecl
)
3224 user_assert(ppDecl
, D3DERR_INVALIDCALL
);
3226 *ppDecl
= (IDirect3DVertexDeclaration9
*)This
->state
.vdecl
;
3228 NineUnknown_AddRef(NineUnknown(*ppDecl
));
3233 NineDevice9_SetFVF( struct NineDevice9
*This
,
3236 struct NineVertexDeclaration9
*vdecl
;
3239 DBG("FVF = %08x\n", FVF
);
3241 return D3D_OK
; /* like wine */
3243 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
3245 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
3249 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
3250 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
3252 return NineDevice9_SetVertexDeclaration(
3253 This
, (IDirect3DVertexDeclaration9
*)vdecl
);
3257 NineDevice9_GetFVF( struct NineDevice9
*This
,
3260 *pFVF
= This
->state
.vdecl
? This
->state
.vdecl
->fvf
: 0;
3265 NineDevice9_CreateVertexShader( struct NineDevice9
*This
,
3266 const DWORD
*pFunction
,
3267 IDirect3DVertexShader9
**ppShader
)
3269 struct NineVertexShader9
*vs
;
3272 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3274 hr
= NineVertexShader9_new(This
, &vs
, pFunction
, NULL
);
3277 *ppShader
= (IDirect3DVertexShader9
*)vs
;
3282 NineDevice9_SetVertexShader( struct NineDevice9
*This
,
3283 IDirect3DVertexShader9
*pShader
)
3285 struct nine_state
*state
= This
->update
;
3286 BOOL was_programmable_vs
= This
->state
.programmable_vs
;
3288 DBG("This=%p pShader=%p\n", This
, pShader
);
3290 if (!This
->is_recording
&& state
->vs
== (struct NineVertexShader9
*)pShader
)
3293 nine_bind(&state
->vs
, pShader
);
3295 This
->state
.programmable_vs
= This
->state
.vs
&& !(This
->state
.vdecl
&& This
->state
.vdecl
->position_t
);
3297 /* ff -> non-ff: commit back non-ff constants */
3298 if (!was_programmable_vs
&& This
->state
.programmable_vs
)
3299 state
->commit
|= NINE_STATE_COMMIT_CONST_VS
;
3301 state
->changed
.group
|= NINE_STATE_VS
;
3307 NineDevice9_GetVertexShader( struct NineDevice9
*This
,
3308 IDirect3DVertexShader9
**ppShader
)
3310 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3311 nine_reference_set(ppShader
, This
->state
.vs
);
3316 NineDevice9_SetVertexShaderConstantF( struct NineDevice9
*This
,
3318 const float *pConstantData
,
3319 UINT Vector4fCount
)
3321 struct nine_state
*state
= This
->update
;
3323 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3324 This
, StartRegister
, pConstantData
, Vector4fCount
);
3326 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3327 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3331 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3333 if (!This
->is_recording
) {
3334 if (!memcmp(&state
->vs_const_f
[StartRegister
* 4], pConstantData
,
3335 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0])))
3339 memcpy(&state
->vs_const_f
[StartRegister
* 4],
3341 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3343 nine_ranges_insert(&state
->changed
.vs_const_f
,
3344 StartRegister
, StartRegister
+ Vector4fCount
,
3347 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3353 NineDevice9_GetVertexShaderConstantF( struct NineDevice9
*This
,
3355 float *pConstantData
,
3356 UINT Vector4fCount
)
3358 const struct nine_state
*state
= &This
->state
;
3360 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3361 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3362 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3364 memcpy(pConstantData
,
3365 &state
->vs_const_f
[StartRegister
* 4],
3366 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3372 NineDevice9_SetVertexShaderConstantI( struct NineDevice9
*This
,
3374 const int *pConstantData
,
3375 UINT Vector4iCount
)
3377 struct nine_state
*state
= This
->update
;
3380 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3381 This
, StartRegister
, pConstantData
, Vector4iCount
);
3383 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3384 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3385 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3387 if (This
->driver_caps
.vs_integer
) {
3388 if (!This
->is_recording
) {
3389 if (!memcmp(&state
->vs_const_i
[StartRegister
][0], pConstantData
,
3390 Vector4iCount
* sizeof(state
->vs_const_i
[0])))
3393 memcpy(&state
->vs_const_i
[StartRegister
][0],
3395 Vector4iCount
* sizeof(state
->vs_const_i
[0]));
3397 for (i
= 0; i
< Vector4iCount
; i
++) {
3398 state
->vs_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3399 state
->vs_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3400 state
->vs_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3401 state
->vs_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3405 state
->changed
.vs_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3406 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3412 NineDevice9_GetVertexShaderConstantI( struct NineDevice9
*This
,
3415 UINT Vector4iCount
)
3417 const struct nine_state
*state
= &This
->state
;
3420 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3421 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3422 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3424 if (This
->driver_caps
.vs_integer
) {
3425 memcpy(pConstantData
,
3426 &state
->vs_const_i
[StartRegister
][0],
3427 Vector4iCount
* sizeof(state
->vs_const_i
[0]));
3429 for (i
= 0; i
< Vector4iCount
; i
++) {
3430 pConstantData
[4*i
] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][0]);
3431 pConstantData
[4*i
+1] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][1]);
3432 pConstantData
[4*i
+2] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][2]);
3433 pConstantData
[4*i
+3] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][3]);
3441 NineDevice9_SetVertexShaderConstantB( struct NineDevice9
*This
,
3443 const BOOL
*pConstantData
,
3446 struct nine_state
*state
= This
->update
;
3448 uint32_t bool_true
= This
->driver_caps
.vs_integer
? 0xFFFFFFFF : fui(1.0f
);
3450 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3451 This
, StartRegister
, pConstantData
, BoolCount
);
3453 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3454 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3455 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3457 if (!This
->is_recording
) {
3458 bool noChange
= true;
3459 for (i
= 0; i
< BoolCount
; i
++) {
3460 if (!!state
->vs_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3467 for (i
= 0; i
< BoolCount
; i
++)
3468 state
->vs_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3470 state
->changed
.vs_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3471 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3477 NineDevice9_GetVertexShaderConstantB( struct NineDevice9
*This
,
3479 BOOL
*pConstantData
,
3482 const struct nine_state
*state
= &This
->state
;
3485 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3486 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3487 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3489 for (i
= 0; i
< BoolCount
; i
++)
3490 pConstantData
[i
] = state
->vs_const_b
[StartRegister
+ i
] != 0 ? TRUE
: FALSE
;
3496 NineDevice9_SetStreamSource( struct NineDevice9
*This
,
3498 IDirect3DVertexBuffer9
*pStreamData
,
3502 struct nine_state
*state
= This
->update
;
3503 struct NineVertexBuffer9
*pVBuf9
= NineVertexBuffer9(pStreamData
);
3504 const unsigned i
= StreamNumber
;
3506 DBG("This=%p StreamNumber=%u pStreamData=%p OffsetInBytes=%u Stride=%u\n",
3507 This
, StreamNumber
, pStreamData
, OffsetInBytes
, Stride
);
3509 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3510 user_assert(Stride
<= This
->caps
.MaxStreamStride
, D3DERR_INVALIDCALL
);
3512 if (likely(!This
->is_recording
)) {
3513 if (state
->stream
[i
] == NineVertexBuffer9(pStreamData
) &&
3514 state
->vtxbuf
[i
].stride
== Stride
&&
3515 state
->vtxbuf
[i
].buffer_offset
== OffsetInBytes
)
3518 nine_bind(&state
->stream
[i
], pStreamData
);
3520 state
->changed
.vtxbuf
|= 1 << StreamNumber
;
3523 state
->vtxbuf
[i
].stride
= Stride
;
3524 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3526 pipe_resource_reference(&state
->vtxbuf
[i
].buffer
,
3527 pStreamData
? NineVertexBuffer9_GetResource(pVBuf9
) : NULL
);
3533 NineDevice9_GetStreamSource( struct NineDevice9
*This
,
3535 IDirect3DVertexBuffer9
**ppStreamData
,
3536 UINT
*pOffsetInBytes
,
3539 const struct nine_state
*state
= &This
->state
;
3540 const unsigned i
= StreamNumber
;
3542 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3543 user_assert(ppStreamData
, D3DERR_INVALIDCALL
);
3545 nine_reference_set(ppStreamData
, state
->stream
[i
]);
3546 *pStride
= state
->vtxbuf
[i
].stride
;
3547 *pOffsetInBytes
= state
->vtxbuf
[i
].buffer_offset
;
3553 NineDevice9_SetStreamSourceFreq( struct NineDevice9
*This
,
3557 struct nine_state
*state
= This
->update
;
3558 /* const UINT freq = Setting & 0x7FFFFF; */
3560 DBG("This=%p StreamNumber=%u FrequencyParameter=0x%x\n", This
,
3561 StreamNumber
, Setting
);
3563 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3564 user_assert(StreamNumber
!= 0 || !(Setting
& D3DSTREAMSOURCE_INSTANCEDATA
),
3565 D3DERR_INVALIDCALL
);
3566 user_assert(!((Setting
& D3DSTREAMSOURCE_INSTANCEDATA
) &&
3567 (Setting
& D3DSTREAMSOURCE_INDEXEDDATA
)), D3DERR_INVALIDCALL
);
3568 user_assert(Setting
, D3DERR_INVALIDCALL
);
3570 if (likely(!This
->is_recording
) && state
->stream_freq
[StreamNumber
] == Setting
)
3573 state
->stream_freq
[StreamNumber
] = Setting
;
3575 if (Setting
& D3DSTREAMSOURCE_INSTANCEDATA
)
3576 state
->stream_instancedata_mask
|= 1 << StreamNumber
;
3578 state
->stream_instancedata_mask
&= ~(1 << StreamNumber
);
3580 state
->changed
.stream_freq
|= 1 << StreamNumber
; /* Used for stateblocks */
3581 if (StreamNumber
!= 0)
3582 state
->changed
.group
|= NINE_STATE_STREAMFREQ
;
3587 NineDevice9_GetStreamSourceFreq( struct NineDevice9
*This
,
3591 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3592 *pSetting
= This
->state
.stream_freq
[StreamNumber
];
3597 NineDevice9_SetIndices( struct NineDevice9
*This
,
3598 IDirect3DIndexBuffer9
*pIndexData
)
3600 struct nine_state
*state
= This
->update
;
3602 DBG("This=%p pIndexData=%p\n", This
, pIndexData
);
3604 if (likely(!This
->is_recording
))
3605 if (state
->idxbuf
== NineIndexBuffer9(pIndexData
))
3607 nine_bind(&state
->idxbuf
, pIndexData
);
3609 state
->changed
.group
|= NINE_STATE_IDXBUF
;
3614 /* XXX: wine/d3d9 doesn't have pBaseVertexIndex, and it doesn't make sense
3615 * here because it's an argument passed to the Draw calls.
3618 NineDevice9_GetIndices( struct NineDevice9
*This
,
3619 IDirect3DIndexBuffer9
**ppIndexData
/*,
3620 UINT *pBaseVertexIndex */ )
3622 user_assert(ppIndexData
, D3DERR_INVALIDCALL
);
3623 nine_reference_set(ppIndexData
, This
->state
.idxbuf
);
3628 NineDevice9_CreatePixelShader( struct NineDevice9
*This
,
3629 const DWORD
*pFunction
,
3630 IDirect3DPixelShader9
**ppShader
)
3632 struct NinePixelShader9
*ps
;
3635 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3637 hr
= NinePixelShader9_new(This
, &ps
, pFunction
, NULL
);
3640 *ppShader
= (IDirect3DPixelShader9
*)ps
;
3645 NineDevice9_SetPixelShader( struct NineDevice9
*This
,
3646 IDirect3DPixelShader9
*pShader
)
3648 struct nine_state
*state
= This
->update
;
3649 unsigned old_mask
= state
->ps
? state
->ps
->rt_mask
: 1;
3652 DBG("This=%p pShader=%p\n", This
, pShader
);
3654 if (!This
->is_recording
&& state
->ps
== (struct NinePixelShader9
*)pShader
)
3657 /* ff -> non-ff: commit back non-ff constants */
3658 if (!state
->ps
&& pShader
)
3659 state
->commit
|= NINE_STATE_COMMIT_CONST_PS
;
3661 nine_bind(&state
->ps
, pShader
);
3663 state
->changed
.group
|= NINE_STATE_PS
;
3665 mask
= state
->ps
? state
->ps
->rt_mask
: 1;
3666 /* We need to update cbufs if the pixel shader would
3667 * write to different render targets */
3668 if (mask
!= old_mask
)
3669 state
->changed
.group
|= NINE_STATE_FB
;
3675 NineDevice9_GetPixelShader( struct NineDevice9
*This
,
3676 IDirect3DPixelShader9
**ppShader
)
3678 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3679 nine_reference_set(ppShader
, This
->state
.ps
);
3684 NineDevice9_SetPixelShaderConstantF( struct NineDevice9
*This
,
3686 const float *pConstantData
,
3687 UINT Vector4fCount
)
3689 struct nine_state
*state
= This
->update
;
3691 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3692 This
, StartRegister
, pConstantData
, Vector4fCount
);
3694 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3695 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3699 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3701 if (!This
->is_recording
) {
3702 if (!memcmp(&state
->ps_const_f
[StartRegister
* 4], pConstantData
,
3703 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0])))
3707 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3709 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3711 nine_ranges_insert(&state
->changed
.ps_const_f
,
3712 StartRegister
, StartRegister
+ Vector4fCount
,
3715 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3721 NineDevice9_GetPixelShaderConstantF( struct NineDevice9
*This
,
3723 float *pConstantData
,
3724 UINT Vector4fCount
)
3726 const struct nine_state
*state
= &This
->state
;
3728 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3729 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3730 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3732 memcpy(pConstantData
,
3733 &state
->ps_const_f
[StartRegister
* 4],
3734 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3740 NineDevice9_SetPixelShaderConstantI( struct NineDevice9
*This
,
3742 const int *pConstantData
,
3743 UINT Vector4iCount
)
3745 struct nine_state
*state
= This
->update
;
3748 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3749 This
, StartRegister
, pConstantData
, Vector4iCount
);
3751 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3752 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3753 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3755 if (This
->driver_caps
.ps_integer
) {
3756 if (!This
->is_recording
) {
3757 if (!memcmp(&state
->ps_const_i
[StartRegister
][0], pConstantData
,
3758 Vector4iCount
* sizeof(state
->ps_const_i
[0])))
3761 memcpy(&state
->ps_const_i
[StartRegister
][0],
3763 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3765 for (i
= 0; i
< Vector4iCount
; i
++) {
3766 state
->ps_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3767 state
->ps_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3768 state
->ps_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3769 state
->ps_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3772 state
->changed
.ps_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3773 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3779 NineDevice9_GetPixelShaderConstantI( struct NineDevice9
*This
,
3782 UINT Vector4iCount
)
3784 const struct nine_state
*state
= &This
->state
;
3787 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3788 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3789 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3791 if (This
->driver_caps
.ps_integer
) {
3792 memcpy(pConstantData
,
3793 &state
->ps_const_i
[StartRegister
][0],
3794 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3796 for (i
= 0; i
< Vector4iCount
; i
++) {
3797 pConstantData
[4*i
] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][0]);
3798 pConstantData
[4*i
+1] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][1]);
3799 pConstantData
[4*i
+2] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][2]);
3800 pConstantData
[4*i
+3] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][3]);
3808 NineDevice9_SetPixelShaderConstantB( struct NineDevice9
*This
,
3810 const BOOL
*pConstantData
,
3813 struct nine_state
*state
= This
->update
;
3815 uint32_t bool_true
= This
->driver_caps
.ps_integer
? 0xFFFFFFFF : fui(1.0f
);
3817 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3818 This
, StartRegister
, pConstantData
, BoolCount
);
3820 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3821 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3822 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3824 if (!This
->is_recording
) {
3825 bool noChange
= true;
3826 for (i
= 0; i
< BoolCount
; i
++) {
3827 if (!!state
->ps_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3834 for (i
= 0; i
< BoolCount
; i
++)
3835 state
->ps_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3837 state
->changed
.ps_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3838 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3844 NineDevice9_GetPixelShaderConstantB( struct NineDevice9
*This
,
3846 BOOL
*pConstantData
,
3849 const struct nine_state
*state
= &This
->state
;
3852 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3853 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3854 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3856 for (i
= 0; i
< BoolCount
; i
++)
3857 pConstantData
[i
] = state
->ps_const_b
[StartRegister
+ i
] ? TRUE
: FALSE
;
3863 NineDevice9_DrawRectPatch( struct NineDevice9
*This
,
3865 const float *pNumSegs
,
3866 const D3DRECTPATCH_INFO
*pRectPatchInfo
)
3868 STUB(D3DERR_INVALIDCALL
);
3872 NineDevice9_DrawTriPatch( struct NineDevice9
*This
,
3874 const float *pNumSegs
,
3875 const D3DTRIPATCH_INFO
*pTriPatchInfo
)
3877 STUB(D3DERR_INVALIDCALL
);
3881 NineDevice9_DeletePatch( struct NineDevice9
*This
,
3884 STUB(D3DERR_INVALIDCALL
);
3888 NineDevice9_CreateQuery( struct NineDevice9
*This
,
3890 IDirect3DQuery9
**ppQuery
)
3892 struct NineQuery9
*query
;
3895 DBG("This=%p Type=%d ppQuery=%p\n", This
, Type
, ppQuery
);
3897 hr
= nine_is_query_supported(This
->screen
, Type
);
3898 if (!ppQuery
|| hr
!= D3D_OK
)
3901 hr
= NineQuery9_new(This
, &query
, Type
);
3904 *ppQuery
= (IDirect3DQuery9
*)query
;
3908 IDirect3DDevice9Vtbl NineDevice9_vtable
= {
3909 (void *)NineUnknown_QueryInterface
,
3910 (void *)NineUnknown_AddRef
,
3911 (void *)NineUnknown_Release
,
3912 (void *)NineDevice9_TestCooperativeLevel
,
3913 (void *)NineDevice9_GetAvailableTextureMem
,
3914 (void *)NineDevice9_EvictManagedResources
,
3915 (void *)NineDevice9_GetDirect3D
,
3916 (void *)NineDevice9_GetDeviceCaps
,
3917 (void *)NineDevice9_GetDisplayMode
,
3918 (void *)NineDevice9_GetCreationParameters
,
3919 (void *)NineDevice9_SetCursorProperties
,
3920 (void *)NineDevice9_SetCursorPosition
,
3921 (void *)NineDevice9_ShowCursor
,
3922 (void *)NineDevice9_CreateAdditionalSwapChain
,
3923 (void *)NineDevice9_GetSwapChain
,
3924 (void *)NineDevice9_GetNumberOfSwapChains
,
3925 (void *)NineDevice9_Reset
,
3926 (void *)NineDevice9_Present
,
3927 (void *)NineDevice9_GetBackBuffer
,
3928 (void *)NineDevice9_GetRasterStatus
,
3929 (void *)NineDevice9_SetDialogBoxMode
,
3930 (void *)NineDevice9_SetGammaRamp
,
3931 (void *)NineDevice9_GetGammaRamp
,
3932 (void *)NineDevice9_CreateTexture
,
3933 (void *)NineDevice9_CreateVolumeTexture
,
3934 (void *)NineDevice9_CreateCubeTexture
,
3935 (void *)NineDevice9_CreateVertexBuffer
,
3936 (void *)NineDevice9_CreateIndexBuffer
,
3937 (void *)NineDevice9_CreateRenderTarget
,
3938 (void *)NineDevice9_CreateDepthStencilSurface
,
3939 (void *)NineDevice9_UpdateSurface
,
3940 (void *)NineDevice9_UpdateTexture
,
3941 (void *)NineDevice9_GetRenderTargetData
,
3942 (void *)NineDevice9_GetFrontBufferData
,
3943 (void *)NineDevice9_StretchRect
,
3944 (void *)NineDevice9_ColorFill
,
3945 (void *)NineDevice9_CreateOffscreenPlainSurface
,
3946 (void *)NineDevice9_SetRenderTarget
,
3947 (void *)NineDevice9_GetRenderTarget
,
3948 (void *)NineDevice9_SetDepthStencilSurface
,
3949 (void *)NineDevice9_GetDepthStencilSurface
,
3950 (void *)NineDevice9_BeginScene
,
3951 (void *)NineDevice9_EndScene
,
3952 (void *)NineDevice9_Clear
,
3953 (void *)NineDevice9_SetTransform
,
3954 (void *)NineDevice9_GetTransform
,
3955 (void *)NineDevice9_MultiplyTransform
,
3956 (void *)NineDevice9_SetViewport
,
3957 (void *)NineDevice9_GetViewport
,
3958 (void *)NineDevice9_SetMaterial
,
3959 (void *)NineDevice9_GetMaterial
,
3960 (void *)NineDevice9_SetLight
,
3961 (void *)NineDevice9_GetLight
,
3962 (void *)NineDevice9_LightEnable
,
3963 (void *)NineDevice9_GetLightEnable
,
3964 (void *)NineDevice9_SetClipPlane
,
3965 (void *)NineDevice9_GetClipPlane
,
3966 (void *)NineDevice9_SetRenderState
,
3967 (void *)NineDevice9_GetRenderState
,
3968 (void *)NineDevice9_CreateStateBlock
,
3969 (void *)NineDevice9_BeginStateBlock
,
3970 (void *)NineDevice9_EndStateBlock
,
3971 (void *)NineDevice9_SetClipStatus
,
3972 (void *)NineDevice9_GetClipStatus
,
3973 (void *)NineDevice9_GetTexture
,
3974 (void *)NineDevice9_SetTexture
,
3975 (void *)NineDevice9_GetTextureStageState
,
3976 (void *)NineDevice9_SetTextureStageState
,
3977 (void *)NineDevice9_GetSamplerState
,
3978 (void *)NineDevice9_SetSamplerState
,
3979 (void *)NineDevice9_ValidateDevice
,
3980 (void *)NineDevice9_SetPaletteEntries
,
3981 (void *)NineDevice9_GetPaletteEntries
,
3982 (void *)NineDevice9_SetCurrentTexturePalette
,
3983 (void *)NineDevice9_GetCurrentTexturePalette
,
3984 (void *)NineDevice9_SetScissorRect
,
3985 (void *)NineDevice9_GetScissorRect
,
3986 (void *)NineDevice9_SetSoftwareVertexProcessing
,
3987 (void *)NineDevice9_GetSoftwareVertexProcessing
,
3988 (void *)NineDevice9_SetNPatchMode
,
3989 (void *)NineDevice9_GetNPatchMode
,
3990 (void *)NineDevice9_DrawPrimitive
,
3991 (void *)NineDevice9_DrawIndexedPrimitive
,
3992 (void *)NineDevice9_DrawPrimitiveUP
,
3993 (void *)NineDevice9_DrawIndexedPrimitiveUP
,
3994 (void *)NineDevice9_ProcessVertices
,
3995 (void *)NineDevice9_CreateVertexDeclaration
,
3996 (void *)NineDevice9_SetVertexDeclaration
,
3997 (void *)NineDevice9_GetVertexDeclaration
,
3998 (void *)NineDevice9_SetFVF
,
3999 (void *)NineDevice9_GetFVF
,
4000 (void *)NineDevice9_CreateVertexShader
,
4001 (void *)NineDevice9_SetVertexShader
,
4002 (void *)NineDevice9_GetVertexShader
,
4003 (void *)NineDevice9_SetVertexShaderConstantF
,
4004 (void *)NineDevice9_GetVertexShaderConstantF
,
4005 (void *)NineDevice9_SetVertexShaderConstantI
,
4006 (void *)NineDevice9_GetVertexShaderConstantI
,
4007 (void *)NineDevice9_SetVertexShaderConstantB
,
4008 (void *)NineDevice9_GetVertexShaderConstantB
,
4009 (void *)NineDevice9_SetStreamSource
,
4010 (void *)NineDevice9_GetStreamSource
,
4011 (void *)NineDevice9_SetStreamSourceFreq
,
4012 (void *)NineDevice9_GetStreamSourceFreq
,
4013 (void *)NineDevice9_SetIndices
,
4014 (void *)NineDevice9_GetIndices
,
4015 (void *)NineDevice9_CreatePixelShader
,
4016 (void *)NineDevice9_SetPixelShader
,
4017 (void *)NineDevice9_GetPixelShader
,
4018 (void *)NineDevice9_SetPixelShaderConstantF
,
4019 (void *)NineDevice9_GetPixelShaderConstantF
,
4020 (void *)NineDevice9_SetPixelShaderConstantI
,
4021 (void *)NineDevice9_GetPixelShaderConstantI
,
4022 (void *)NineDevice9_SetPixelShaderConstantB
,
4023 (void *)NineDevice9_GetPixelShaderConstantB
,
4024 (void *)NineDevice9_DrawRectPatch
,
4025 (void *)NineDevice9_DrawTriPatch
,
4026 (void *)NineDevice9_DeletePatch
,
4027 (void *)NineDevice9_CreateQuery
4030 static const GUID
*NineDevice9_IIDs
[] = {
4031 &IID_IDirect3DDevice9
,
4037 NineDevice9_new( struct pipe_screen
*pScreen
,
4038 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
4040 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
4042 ID3DPresentGroup
*pPresentationGroup
,
4043 struct d3dadapter9_context
*pCTX
,
4045 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
4046 struct NineDevice9
**ppOut
)
4049 lock
= !!(pCreationParameters
->BehaviorFlags
& D3DCREATE_MULTITHREADED
);
4051 NINE_NEW(Device9
, ppOut
, lock
, /* args */
4052 pScreen
, pCreationParameters
, pCaps
,
4053 pPresentationParameters
, pD3D9
, pPresentationGroup
, pCTX
,
4054 ex
, pFullscreenDisplayMode
);