2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
24 #include "stateblock9.h"
26 #include "swapchain9.h"
27 #include "swapchain9ex.h"
28 #include "indexbuffer9.h"
29 #include "vertexbuffer9.h"
30 #include "vertexdeclaration9.h"
31 #include "vertexshader9.h"
32 #include "pixelshader9.h"
35 #include "cubetexture9.h"
36 #include "volumetexture9.h"
37 #include "nine_helpers.h"
38 #include "nine_pipe.h"
40 #include "nine_dump.h"
42 #include "pipe/p_screen.h"
43 #include "pipe/p_context.h"
44 #include "pipe/p_config.h"
45 #include "util/u_math.h"
46 #include "util/u_inlines.h"
47 #include "util/u_hash_table.h"
48 #include "util/u_format.h"
49 #include "util/u_surface.h"
50 #include "util/u_upload_mgr.h"
51 #include "hud/hud_context.h"
53 #include "cso_cache/cso_context.h"
55 #define DBG_CHANNEL DBG_DEVICE
57 #if defined(PIPE_CC_GCC) && (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64))
59 #include <fpu_control.h>
61 static void nine_setup_fpu()
66 /* clear the control word */
68 /* d3d9 doc/wine tests: mask all exceptions, use single-precision
69 * and round to nearest */
70 c
|= _FPU_MASK_IM
| _FPU_MASK_DM
| _FPU_MASK_ZM
| _FPU_MASK_OM
|
71 _FPU_MASK_UM
| _FPU_MASK_PM
| _FPU_SINGLE
| _FPU_RC_NEAREST
;
77 static void nine_setup_fpu(void)
79 WARN_ONCE("FPU setup not supported on non-x86 platforms\n");
85 NineDevice9_SetDefaultState( struct NineDevice9
*This
, boolean is_reset
)
87 struct NineSurface9
*refSurf
= NULL
;
89 DBG("This=%p is_reset=%d\n", This
, (int) is_reset
);
91 assert(!This
->is_recording
);
93 nine_state_set_defaults(This
, &This
->caps
, is_reset
);
95 This
->state
.viewport
.X
= 0;
96 This
->state
.viewport
.Y
= 0;
97 This
->state
.viewport
.Width
= 0;
98 This
->state
.viewport
.Height
= 0;
100 This
->state
.scissor
.minx
= 0;
101 This
->state
.scissor
.miny
= 0;
102 This
->state
.scissor
.maxx
= 0xffff;
103 This
->state
.scissor
.maxy
= 0xffff;
105 if (This
->nswapchains
&& This
->swapchains
[0]->params
.BackBufferCount
)
106 refSurf
= This
->swapchains
[0]->buffers
[0];
109 This
->state
.viewport
.Width
= refSurf
->desc
.Width
;
110 This
->state
.viewport
.Height
= refSurf
->desc
.Height
;
111 This
->state
.scissor
.maxx
= refSurf
->desc
.Width
;
112 This
->state
.scissor
.maxy
= refSurf
->desc
.Height
;
115 if (This
->nswapchains
&& This
->swapchains
[0]->params
.EnableAutoDepthStencil
)
116 This
->state
.rs
[D3DRS_ZENABLE
] = TRUE
;
117 if (This
->state
.rs
[D3DRS_ZENABLE
])
118 NineDevice9_SetDepthStencilSurface(
119 This
, (IDirect3DSurface9
*)This
->swapchains
[0]->zsbuf
);
122 #define GET_PCAP(n) pScreen->get_param(pScreen, PIPE_CAP_##n)
124 NineDevice9_ctor( struct NineDevice9
*This
,
125 struct NineUnknownParams
*pParams
,
126 struct pipe_screen
*pScreen
,
127 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
129 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
131 ID3DPresentGroup
*pPresentationGroup
,
132 struct d3dadapter9_context
*pCTX
,
134 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
)
137 HRESULT hr
= NineUnknown_ctor(&This
->base
, pParams
);
139 DBG("This=%p pParams=%p pScreen=%p pCreationParameters=%p pCaps=%p pPresentationParameters=%p "
140 "pD3D9=%p pPresentationGroup=%p pCTX=%p ex=%d pFullscreenDisplayMode=%p\n",
141 This
, pParams
, pScreen
, pCreationParameters
, pCaps
, pPresentationParameters
, pD3D9
,
142 pPresentationGroup
, pCTX
, (int) ex
, pFullscreenDisplayMode
);
144 if (FAILED(hr
)) { return hr
; }
146 list_inithead(&This
->update_textures
);
147 list_inithead(&This
->managed_textures
);
149 This
->screen
= pScreen
;
152 This
->params
= *pCreationParameters
;
154 This
->present
= pPresentationGroup
;
155 IDirect3D9_AddRef(This
->d3d9
);
156 ID3DPresentGroup_AddRef(This
->present
);
158 if (!(This
->params
.BehaviorFlags
& D3DCREATE_FPU_PRESERVE
))
161 if (This
->params
.BehaviorFlags
& D3DCREATE_SOFTWARE_VERTEXPROCESSING
)
162 DBG("Application asked full Software Vertex Processing. Ignoring.\n");
163 if (This
->params
.BehaviorFlags
& D3DCREATE_MIXED_VERTEXPROCESSING
)
164 DBG("Application asked mixed Software Vertex Processing. Ignoring.\n");
166 This
->pipe
= This
->screen
->context_create(This
->screen
, NULL
);
167 if (!This
->pipe
) { return E_OUTOFMEMORY
; } /* guess */
169 This
->cso
= cso_create_context(This
->pipe
);
170 if (!This
->cso
) { return E_OUTOFMEMORY
; } /* also a guess */
172 /* Create first, it messes up our state. */
173 This
->hud
= hud_create(This
->pipe
, This
->cso
); /* NULL result is fine */
175 /* create implicit swapchains */
176 This
->nswapchains
= ID3DPresentGroup_GetMultiheadCount(This
->present
);
177 This
->swapchains
= CALLOC(This
->nswapchains
,
178 sizeof(struct NineSwapChain9
*));
179 if (!This
->swapchains
) { return E_OUTOFMEMORY
; }
181 for (i
= 0; i
< This
->nswapchains
; ++i
) {
182 ID3DPresent
*present
;
184 hr
= ID3DPresentGroup_GetPresent(This
->present
, i
, &present
);
189 D3DDISPLAYMODEEX
*mode
= NULL
;
190 struct NineSwapChain9Ex
**ret
=
191 (struct NineSwapChain9Ex
**)&This
->swapchains
[i
];
193 if (pFullscreenDisplayMode
) mode
= &(pFullscreenDisplayMode
[i
]);
194 /* when this is a Device9Ex, it should create SwapChain9Exs */
195 hr
= NineSwapChain9Ex_new(This
, TRUE
, present
,
196 &pPresentationParameters
[i
], pCTX
,
197 This
->params
.hFocusWindow
, mode
, ret
);
199 hr
= NineSwapChain9_new(This
, TRUE
, present
,
200 &pPresentationParameters
[i
], pCTX
,
201 This
->params
.hFocusWindow
,
202 &This
->swapchains
[i
]);
205 ID3DPresent_Release(present
);
208 NineUnknown_ConvertRefToBind(NineUnknown(This
->swapchains
[i
]));
210 hr
= NineSwapChain9_GetBackBuffer(This
->swapchains
[i
], 0,
211 D3DBACKBUFFER_TYPE_MONO
,
212 (IDirect3DSurface9
**)
216 NineUnknown_ConvertRefToBind(NineUnknown(This
->state
.rt
[i
]));
219 /* Initialize a dummy VBO to be used when a a vertex declaration does not
220 * specify all the inputs needed by vertex shader, on win default behavior
221 * is to pass 0,0,0,0 to the shader */
223 struct pipe_transfer
*transfer
;
224 struct pipe_resource tmpl
;
228 tmpl
.target
= PIPE_BUFFER
;
229 tmpl
.format
= PIPE_FORMAT_R8_UNORM
;
230 tmpl
.width0
= 16; /* 4 floats */
236 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
237 tmpl
.bind
= PIPE_BIND_VERTEX_BUFFER
| PIPE_BIND_TRANSFER_WRITE
;
239 This
->dummy_vbo
= pScreen
->resource_create(pScreen
, &tmpl
);
241 if (!This
->dummy_vbo
)
242 return D3DERR_OUTOFVIDEOMEMORY
;
244 u_box_1d(0, 16, &box
);
245 data
= This
->pipe
->transfer_map(This
->pipe
, This
->dummy_vbo
, 0,
246 PIPE_TRANSFER_WRITE
|
247 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
252 This
->pipe
->transfer_unmap(This
->pipe
, transfer
);
255 This
->cursor
.software
= FALSE
;
256 This
->cursor
.hotspot
.x
= -1;
257 This
->cursor
.hotspot
.y
= -1;
259 struct pipe_resource tmpl
;
260 tmpl
.target
= PIPE_TEXTURE_2D
;
261 tmpl
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
268 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
269 tmpl
.bind
= PIPE_BIND_CURSOR
| PIPE_BIND_SAMPLER_VIEW
;
272 This
->cursor
.image
= pScreen
->resource_create(pScreen
, &tmpl
);
273 if (!This
->cursor
.image
)
274 return D3DERR_OUTOFVIDEOMEMORY
;
277 /* Create constant buffers. */
279 struct pipe_resource tmpl
;
280 unsigned max_const_vs
, max_const_ps
;
282 /* vs 3.0: >= 256 float constants, but for cards with exactly 256 slots,
283 * we have to take in some more slots for int and bool*/
284 max_const_vs
= _min(pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
,
285 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
) /
288 /* ps 3.0: 224 float constants. All cards supported support at least
289 * 256 constants for ps */
290 max_const_ps
= NINE_MAX_CONST_F_PS3
+ (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
292 This
->max_vs_const_f
= max_const_vs
-
293 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
294 This
->max_ps_const_f
= max_const_ps
-
295 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
297 This
->vs_const_size
= max_const_vs
* sizeof(float[4]);
298 This
->ps_const_size
= max_const_ps
* sizeof(float[4]);
299 /* Include space for I,B constants for user constbuf. */
300 This
->state
.vs_const_f
= CALLOC(This
->vs_const_size
, 1);
301 This
->state
.ps_const_f
= CALLOC(This
->ps_const_size
, 1);
302 This
->state
.vs_lconstf_temp
= CALLOC(This
->vs_const_size
,1);
303 This
->state
.ps_lconstf_temp
= CALLOC(This
->ps_const_size
,1);
304 if (!This
->state
.vs_const_f
|| !This
->state
.ps_const_f
||
305 !This
->state
.vs_lconstf_temp
|| !This
->state
.ps_lconstf_temp
)
306 return E_OUTOFMEMORY
;
308 if (strstr(pScreen
->get_name(pScreen
), "AMD") ||
309 strstr(pScreen
->get_name(pScreen
), "ATI")) {
310 This
->prefer_user_constbuf
= TRUE
;
311 This
->driver_bugs
.buggy_barycentrics
= TRUE
;
314 tmpl
.target
= PIPE_BUFFER
;
315 tmpl
.format
= PIPE_FORMAT_R8_UNORM
;
321 tmpl
.usage
= PIPE_USAGE_DYNAMIC
;
322 tmpl
.bind
= PIPE_BIND_CONSTANT_BUFFER
;
325 tmpl
.width0
= This
->vs_const_size
;
326 This
->constbuf_vs
= pScreen
->resource_create(pScreen
, &tmpl
);
328 tmpl
.width0
= This
->ps_const_size
;
329 This
->constbuf_ps
= pScreen
->resource_create(pScreen
, &tmpl
);
331 if (!This
->constbuf_vs
|| !This
->constbuf_ps
)
332 return E_OUTOFMEMORY
;
335 /* allocate dummy texture/sampler for when there are missing ones bound */
337 struct pipe_resource tmplt
;
338 struct pipe_sampler_view templ
;
340 tmplt
.target
= PIPE_TEXTURE_2D
;
344 tmplt
.last_level
= 0;
345 tmplt
.array_size
= 1;
346 tmplt
.usage
= PIPE_USAGE_DEFAULT
;
348 tmplt
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
349 tmplt
.bind
= PIPE_BIND_SAMPLER_VIEW
;
350 tmplt
.nr_samples
= 0;
352 This
->dummy_texture
= This
->screen
->resource_create(This
->screen
, &tmplt
);
353 if (!This
->dummy_texture
)
354 return D3DERR_DRIVERINTERNALERROR
;
356 templ
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
357 templ
.u
.tex
.first_layer
= 0;
358 templ
.u
.tex
.last_layer
= 0;
359 templ
.u
.tex
.first_level
= 0;
360 templ
.u
.tex
.last_level
= 0;
361 templ
.swizzle_r
= PIPE_SWIZZLE_ZERO
;
362 templ
.swizzle_g
= PIPE_SWIZZLE_ZERO
;
363 templ
.swizzle_b
= PIPE_SWIZZLE_ZERO
;
364 templ
.swizzle_a
= PIPE_SWIZZLE_ONE
;
365 templ
.target
= This
->dummy_texture
->target
;
367 This
->dummy_sampler
= This
->pipe
->create_sampler_view(This
->pipe
, This
->dummy_texture
, &templ
);
368 if (!This
->dummy_sampler
)
369 return D3DERR_DRIVERINTERNALERROR
;
372 /* Allocate upload helper for drivers that suck (from st pov ;). */
374 This
->driver_caps
.user_vbufs
= GET_PCAP(USER_VERTEX_BUFFERS
);
375 This
->driver_caps
.user_ibufs
= GET_PCAP(USER_INDEX_BUFFERS
);
376 This
->driver_caps
.user_cbufs
= GET_PCAP(USER_CONSTANT_BUFFERS
);
378 if (!This
->driver_caps
.user_vbufs
)
379 This
->vertex_uploader
= u_upload_create(This
->pipe
, 65536, 4, PIPE_BIND_VERTEX_BUFFER
);
380 if (!This
->driver_caps
.user_ibufs
)
381 This
->index_uploader
= u_upload_create(This
->pipe
, 128 * 1024, 4, PIPE_BIND_INDEX_BUFFER
);
382 if (!This
->driver_caps
.user_cbufs
) {
383 unsigned alignment
= GET_PCAP(CONSTANT_BUFFER_OFFSET_ALIGNMENT
);
385 This
->constbuf_uploader
= u_upload_create(This
->pipe
, This
->vs_const_size
,
386 alignment
, PIPE_BIND_CONSTANT_BUFFER
);
389 This
->driver_caps
.window_space_position_support
= GET_PCAP(TGSI_VS_WINDOW_SPACE_POSITION
);
390 This
->driver_caps
.vs_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
, PIPE_SHADER_CAP_INTEGERS
);
391 This
->driver_caps
.ps_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_FRAGMENT
, PIPE_SHADER_CAP_INTEGERS
);
393 nine_ff_init(This
); /* initialize fixed function code */
395 NineDevice9_SetDefaultState(This
, FALSE
);
398 struct pipe_poly_stipple stipple
;
399 memset(&stipple
, ~0, sizeof(stipple
));
400 This
->pipe
->set_polygon_stipple(This
->pipe
, &stipple
);
403 This
->update
= &This
->state
;
404 nine_update_state(This
);
406 ID3DPresentGroup_Release(This
->present
);
413 NineDevice9_dtor( struct NineDevice9
*This
)
417 DBG("This=%p\n", This
);
419 if (This
->pipe
&& This
->cso
)
420 nine_pipe_context_clear(This
);
422 nine_state_clear(&This
->state
, TRUE
);
424 if (This
->vertex_uploader
)
425 u_upload_destroy(This
->vertex_uploader
);
426 if (This
->index_uploader
)
427 u_upload_destroy(This
->index_uploader
);
428 if (This
->constbuf_uploader
)
429 u_upload_destroy(This
->constbuf_uploader
);
431 nine_bind(&This
->record
, NULL
);
433 pipe_sampler_view_reference(&This
->dummy_sampler
, NULL
);
434 pipe_resource_reference(&This
->dummy_texture
, NULL
);
435 pipe_resource_reference(&This
->constbuf_vs
, NULL
);
436 pipe_resource_reference(&This
->constbuf_ps
, NULL
);
437 pipe_resource_reference(&This
->dummy_vbo
, NULL
);
438 FREE(This
->state
.vs_const_f
);
439 FREE(This
->state
.ps_const_f
);
440 FREE(This
->state
.vs_lconstf_temp
);
441 FREE(This
->state
.ps_lconstf_temp
);
443 if (This
->swapchains
) {
444 for (i
= 0; i
< This
->nswapchains
; ++i
)
445 NineUnknown_Unbind(NineUnknown(This
->swapchains
[i
]));
446 FREE(This
->swapchains
);
452 cso_destroy_context(This
->cso
);
454 if (This
->pipe
->destroy
) { This
->pipe
->destroy(This
->pipe
); }
457 if (This
->present
) { ID3DPresentGroup_Release(This
->present
); }
458 if (This
->d3d9
) { IDirect3D9_Release(This
->d3d9
); }
460 NineUnknown_dtor(&This
->base
);
464 NineDevice9_GetScreen( struct NineDevice9
*This
)
469 struct pipe_context
*
470 NineDevice9_GetPipe( struct NineDevice9
*This
)
476 NineDevice9_GetCSO( struct NineDevice9
*This
)
482 NineDevice9_GetCaps( struct NineDevice9
*This
)
488 NineDevice9_PauseRecording( struct NineDevice9
*This
)
491 This
->update
= &This
->state
;
492 This
->is_recording
= FALSE
;
497 NineDevice9_ResumeRecording( struct NineDevice9
*This
)
500 This
->update
= &This
->record
->state
;
501 This
->is_recording
= TRUE
;
506 NineDevice9_TestCooperativeLevel( struct NineDevice9
*This
)
508 return D3D_OK
; /* TODO */
512 NineDevice9_GetAvailableTextureMem( struct NineDevice9
*This
)
514 const unsigned mem
= This
->screen
->get_param(This
->screen
, PIPE_CAP_VIDEO_MEMORY
);
522 NineDevice9_EvictManagedResources( struct NineDevice9
*This
)
524 struct NineBaseTexture9
*tex
;
526 DBG("This=%p\n", This
);
527 LIST_FOR_EACH_ENTRY(tex
, &This
->managed_textures
, list2
) {
528 NineBaseTexture9_UnLoad(tex
);
535 NineDevice9_GetDirect3D( struct NineDevice9
*This
,
536 IDirect3D9
**ppD3D9
)
538 user_assert(ppD3D9
!= NULL
, E_POINTER
);
539 IDirect3D9_AddRef(This
->d3d9
);
540 *ppD3D9
= This
->d3d9
;
545 NineDevice9_GetDeviceCaps( struct NineDevice9
*This
,
548 user_assert(pCaps
!= NULL
, D3DERR_INVALIDCALL
);
554 NineDevice9_GetDisplayMode( struct NineDevice9
*This
,
556 D3DDISPLAYMODE
*pMode
)
558 DBG("This=%p iSwapChain=%u pMode=%p\n", This
, iSwapChain
, pMode
);
560 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
562 return NineSwapChain9_GetDisplayMode(This
->swapchains
[iSwapChain
], pMode
);
566 NineDevice9_GetCreationParameters( struct NineDevice9
*This
,
567 D3DDEVICE_CREATION_PARAMETERS
*pParameters
)
569 user_assert(pParameters
!= NULL
, D3DERR_INVALIDCALL
);
570 *pParameters
= This
->params
;
575 NineDevice9_SetCursorProperties( struct NineDevice9
*This
,
578 IDirect3DSurface9
*pCursorBitmap
)
580 struct NineSurface9
*surf
= NineSurface9(pCursorBitmap
);
581 struct pipe_context
*pipe
= This
->pipe
;
583 struct pipe_transfer
*transfer
;
587 DBG_FLAG(DBG_SWAPCHAIN
, "This=%p XHotSpot=%u YHotSpot=%u "
588 "pCursorBitmap=%p\n", This
, XHotSpot
, YHotSpot
, pCursorBitmap
);
590 user_assert(pCursorBitmap
, D3DERR_INVALIDCALL
);
592 if (This
->swapchains
[0]->params
.Windowed
) {
593 This
->cursor
.w
= MIN2(surf
->desc
.Width
, 32);
594 This
->cursor
.h
= MIN2(surf
->desc
.Height
, 32);
595 hw_cursor
= 1; /* always use hw cursor for windowed mode */
597 This
->cursor
.w
= MIN2(surf
->desc
.Width
, This
->cursor
.image
->width0
);
598 This
->cursor
.h
= MIN2(surf
->desc
.Height
, This
->cursor
.image
->height0
);
599 hw_cursor
= This
->cursor
.w
== 32 && This
->cursor
.h
== 32;
602 u_box_origin_2d(This
->cursor
.w
, This
->cursor
.h
, &box
);
604 ptr
= pipe
->transfer_map(pipe
, This
->cursor
.image
, 0,
605 PIPE_TRANSFER_WRITE
|
606 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
609 ret_err("Failed to update cursor image.\n", D3DERR_DRIVERINTERNALERROR
);
611 This
->cursor
.hotspot
.x
= XHotSpot
;
612 This
->cursor
.hotspot
.y
= YHotSpot
;
614 /* Copy cursor image to internal storage. */
618 const struct util_format_description
*sfmt
=
619 util_format_description(surf
->base
.info
.format
);
622 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, D3DLOCK_READONLY
);
624 ret_err("Failed to map cursor source image.\n",
625 D3DERR_DRIVERINTERNALERROR
);
627 sfmt
->unpack_rgba_8unorm(ptr
, transfer
->stride
,
628 lock
.pBits
, lock
.Pitch
,
629 This
->cursor
.w
, This
->cursor
.h
);
632 hw_cursor
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
,
634 &This
->cursor
.hotspot
,
635 This
->cursor
.visible
) == D3D_OK
;
637 NineSurface9_UnlockRect(surf
);
639 pipe
->transfer_unmap(pipe
, transfer
);
641 /* hide cursor if we emulate it */
643 ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, FALSE
);
644 This
->cursor
.software
= !hw_cursor
;
650 NineDevice9_SetCursorPosition( struct NineDevice9
*This
,
655 struct NineSwapChain9
*swap
= This
->swapchains
[0];
657 DBG("This=%p X=%d Y=%d Flags=%d\n", This
, X
, Y
, Flags
);
659 This
->cursor
.pos
.x
= X
;
660 This
->cursor
.pos
.y
= Y
;
662 if (!This
->cursor
.software
)
663 This
->cursor
.software
= ID3DPresent_SetCursorPos(swap
->present
, &This
->cursor
.pos
) != D3D_OK
;
667 NineDevice9_ShowCursor( struct NineDevice9
*This
,
670 BOOL old
= This
->cursor
.visible
;
672 DBG("This=%p bShow=%d\n", This
, (int) bShow
);
674 This
->cursor
.visible
= bShow
&& (This
->cursor
.hotspot
.x
!= -1);
675 if (!This
->cursor
.software
)
676 This
->cursor
.software
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, bShow
) != D3D_OK
;
682 NineDevice9_CreateAdditionalSwapChain( struct NineDevice9
*This
,
683 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
684 IDirect3DSwapChain9
**pSwapChain
)
686 struct NineSwapChain9
*swapchain
, *tmplt
= This
->swapchains
[0];
687 ID3DPresent
*present
;
690 DBG("This=%p pPresentationParameters=%p pSwapChain=%p\n",
691 This
, pPresentationParameters
, pSwapChain
);
693 user_assert(pPresentationParameters
, D3DERR_INVALIDCALL
);
695 hr
= ID3DPresentGroup_CreateAdditionalPresent(This
->present
, pPresentationParameters
, &present
);
700 hr
= NineSwapChain9_new(This
, FALSE
, present
, pPresentationParameters
,
702 tmplt
->params
.hDeviceWindow
,
707 *pSwapChain
= (IDirect3DSwapChain9
*)swapchain
;
712 NineDevice9_GetSwapChain( struct NineDevice9
*This
,
714 IDirect3DSwapChain9
**pSwapChain
)
716 user_assert(pSwapChain
!= NULL
, D3DERR_INVALIDCALL
);
719 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
721 NineUnknown_AddRef(NineUnknown(This
->swapchains
[iSwapChain
]));
722 *pSwapChain
= (IDirect3DSwapChain9
*)This
->swapchains
[iSwapChain
];
728 NineDevice9_GetNumberOfSwapChains( struct NineDevice9
*This
)
730 return This
->nswapchains
;
734 NineDevice9_Reset( struct NineDevice9
*This
,
735 D3DPRESENT_PARAMETERS
*pPresentationParameters
)
740 DBG("This=%p pPresentationParameters=%p\n", This
, pPresentationParameters
);
742 for (i
= 0; i
< This
->nswapchains
; ++i
) {
743 D3DPRESENT_PARAMETERS
*params
= &pPresentationParameters
[i
];
744 hr
= NineSwapChain9_Resize(This
->swapchains
[i
], params
, NULL
);
749 nine_pipe_context_clear(This
);
750 nine_state_clear(&This
->state
, TRUE
);
752 NineDevice9_SetDefaultState(This
, TRUE
);
753 NineDevice9_SetRenderTarget(
754 This
, 0, (IDirect3DSurface9
*)This
->swapchains
[0]->buffers
[0]);
755 /* XXX: better use GetBackBuffer here ? */
761 NineDevice9_Present( struct NineDevice9
*This
,
762 const RECT
*pSourceRect
,
763 const RECT
*pDestRect
,
764 HWND hDestWindowOverride
,
765 const RGNDATA
*pDirtyRegion
)
770 DBG("This=%p pSourceRect=%p pDestRect=%p hDestWindowOverride=%p pDirtyRegion=%p\n",
771 This
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
773 /* XXX is this right? */
774 for (i
= 0; i
< This
->nswapchains
; ++i
) {
775 hr
= NineSwapChain9_Present(This
->swapchains
[i
], pSourceRect
, pDestRect
,
776 hDestWindowOverride
, pDirtyRegion
, 0);
777 if (FAILED(hr
)) { return hr
; }
784 NineDevice9_GetBackBuffer( struct NineDevice9
*This
,
787 D3DBACKBUFFER_TYPE Type
,
788 IDirect3DSurface9
**ppBackBuffer
)
790 user_assert(ppBackBuffer
!= NULL
, D3DERR_INVALIDCALL
);
791 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
793 return NineSwapChain9_GetBackBuffer(This
->swapchains
[iSwapChain
],
794 iBackBuffer
, Type
, ppBackBuffer
);
798 NineDevice9_GetRasterStatus( struct NineDevice9
*This
,
800 D3DRASTER_STATUS
*pRasterStatus
)
802 user_assert(pRasterStatus
!= NULL
, D3DERR_INVALIDCALL
);
803 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
805 return NineSwapChain9_GetRasterStatus(This
->swapchains
[iSwapChain
],
810 NineDevice9_SetDialogBoxMode( struct NineDevice9
*This
,
811 BOOL bEnableDialogs
)
813 STUB(D3DERR_INVALIDCALL
);
817 NineDevice9_SetGammaRamp( struct NineDevice9
*This
,
820 const D3DGAMMARAMP
*pRamp
)
822 DBG("This=%p iSwapChain=%u Flags=%x pRamp=%p\n", This
,
823 iSwapChain
, Flags
, pRamp
);
825 user_warn(iSwapChain
>= This
->nswapchains
);
828 if (pRamp
&& (iSwapChain
< This
->nswapchains
)) {
829 struct NineSwapChain9
*swap
= This
->swapchains
[iSwapChain
];
830 swap
->gamma
= *pRamp
;
831 ID3DPresent_SetGammaRamp(swap
->present
, pRamp
, swap
->params
.hDeviceWindow
);
836 NineDevice9_GetGammaRamp( struct NineDevice9
*This
,
838 D3DGAMMARAMP
*pRamp
)
840 DBG("This=%p iSwapChain=%u pRamp=%p\n", This
, iSwapChain
, pRamp
);
842 user_warn(iSwapChain
>= This
->nswapchains
);
845 if (pRamp
&& (iSwapChain
< This
->nswapchains
))
846 *pRamp
= This
->swapchains
[iSwapChain
]->gamma
;
850 NineDevice9_CreateTexture( struct NineDevice9
*This
,
857 IDirect3DTexture9
**ppTexture
,
858 HANDLE
*pSharedHandle
)
860 struct NineTexture9
*tex
;
863 DBG("This=%p Width=%u Height=%u Levels=%u Usage=%s Format=%s Pool=%s "
864 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Levels
,
865 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
866 nine_D3DPOOL_to_str(Pool
), ppTexture
, pSharedHandle
);
868 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DMAP
|
869 D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
870 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
;
873 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
874 user_assert(!pSharedHandle
|| This
->ex
, D3DERR_INVALIDCALL
);
875 /* When is used shared handle, Pool must be
876 * SYSTEMMEM with Levels 1 or DEFAULT with any Levels */
877 user_assert(!pSharedHandle
|| Pool
!= D3DPOOL_SYSTEMMEM
|| Levels
== 1,
879 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_SYSTEMMEM
|| Pool
== D3DPOOL_DEFAULT
,
881 user_assert((Usage
!= D3DUSAGE_AUTOGENMIPMAP
|| Levels
<= 1), D3DERR_INVALIDCALL
);
883 hr
= NineTexture9_new(This
, Width
, Height
, Levels
, Usage
, Format
, Pool
,
884 &tex
, pSharedHandle
);
886 *ppTexture
= (IDirect3DTexture9
*)tex
;
892 NineDevice9_CreateVolumeTexture( struct NineDevice9
*This
,
900 IDirect3DVolumeTexture9
**ppVolumeTexture
,
901 HANDLE
*pSharedHandle
)
903 struct NineVolumeTexture9
*tex
;
906 DBG("This=%p Width=%u Height=%u Depth=%u Levels=%u Usage=%s Format=%s Pool=%s "
907 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Depth
, Levels
,
908 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
909 nine_D3DPOOL_to_str(Pool
), ppVolumeTexture
, pSharedHandle
);
911 Usage
&= D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
912 D3DUSAGE_SOFTWAREPROCESSING
;
914 *ppVolumeTexture
= NULL
;
915 user_assert(Width
&& Height
&& Depth
, D3DERR_INVALIDCALL
);
916 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
918 hr
= NineVolumeTexture9_new(This
, Width
, Height
, Depth
, Levels
,
919 Usage
, Format
, Pool
, &tex
, pSharedHandle
);
921 *ppVolumeTexture
= (IDirect3DVolumeTexture9
*)tex
;
927 NineDevice9_CreateCubeTexture( struct NineDevice9
*This
,
933 IDirect3DCubeTexture9
**ppCubeTexture
,
934 HANDLE
*pSharedHandle
)
936 struct NineCubeTexture9
*tex
;
939 DBG("This=%p EdgeLength=%u Levels=%u Usage=%s Format=%s Pool=%s ppOut=%p "
940 "pSharedHandle=%p\n", This
, EdgeLength
, Levels
,
941 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
942 nine_D3DPOOL_to_str(Pool
), ppCubeTexture
, pSharedHandle
);
944 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DYNAMIC
|
945 D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
946 D3DUSAGE_SOFTWAREPROCESSING
;
948 *ppCubeTexture
= NULL
;
949 user_assert(EdgeLength
, D3DERR_INVALIDCALL
);
950 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
952 hr
= NineCubeTexture9_new(This
, EdgeLength
, Levels
, Usage
, Format
, Pool
,
953 &tex
, pSharedHandle
);
955 *ppCubeTexture
= (IDirect3DCubeTexture9
*)tex
;
961 NineDevice9_CreateVertexBuffer( struct NineDevice9
*This
,
966 IDirect3DVertexBuffer9
**ppVertexBuffer
,
967 HANDLE
*pSharedHandle
)
969 struct NineVertexBuffer9
*buf
;
971 D3DVERTEXBUFFER_DESC desc
;
973 DBG("This=%p Length=%u Usage=%x FVF=%x Pool=%u ppOut=%p pSharedHandle=%p\n",
974 This
, Length
, Usage
, FVF
, Pool
, ppVertexBuffer
, pSharedHandle
);
976 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
978 desc
.Format
= D3DFMT_VERTEXDATA
;
979 desc
.Type
= D3DRTYPE_VERTEXBUFFER
;
981 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
982 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
983 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
|
989 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
990 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
992 hr
= NineVertexBuffer9_new(This
, &desc
, &buf
);
994 *ppVertexBuffer
= (IDirect3DVertexBuffer9
*)buf
;
999 NineDevice9_CreateIndexBuffer( struct NineDevice9
*This
,
1004 IDirect3DIndexBuffer9
**ppIndexBuffer
,
1005 HANDLE
*pSharedHandle
)
1007 struct NineIndexBuffer9
*buf
;
1009 D3DINDEXBUFFER_DESC desc
;
1011 DBG("This=%p Length=%u Usage=%x Format=%s Pool=%u ppOut=%p "
1012 "pSharedHandle=%p\n", This
, Length
, Usage
,
1013 d3dformat_to_string(Format
), Pool
, ppIndexBuffer
, pSharedHandle
);
1015 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1017 desc
.Format
= Format
;
1018 desc
.Type
= D3DRTYPE_INDEXBUFFER
;
1019 desc
.Usage
= Usage
&
1020 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1021 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1022 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_WRITEONLY
);
1026 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1027 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1029 hr
= NineIndexBuffer9_new(This
, &desc
, &buf
);
1031 *ppIndexBuffer
= (IDirect3DIndexBuffer9
*)buf
;
1036 create_zs_or_rt_surface(struct NineDevice9
*This
,
1037 unsigned type
, /* 0 = RT, 1 = ZS, 2 = plain */
1039 UINT Width
, UINT Height
,
1041 D3DMULTISAMPLE_TYPE MultiSample
,
1042 DWORD MultisampleQuality
,
1043 BOOL Discard_or_Lockable
,
1044 IDirect3DSurface9
**ppSurface
,
1045 HANDLE
*pSharedHandle
)
1047 struct NineSurface9
*surface
;
1048 struct pipe_screen
*screen
= This
->screen
;
1049 struct pipe_resource
*resource
= NULL
;
1051 D3DSURFACE_DESC desc
;
1052 struct pipe_resource templ
;
1054 DBG("This=%p type=%u Pool=%s Width=%u Height=%u Format=%s MS=%u Quality=%u "
1055 "Discard_or_Lockable=%i ppSurface=%p pSharedHandle=%p\n",
1056 This
, type
, nine_D3DPOOL_to_str(Pool
), Width
, Height
,
1057 d3dformat_to_string(Format
), MultiSample
, MultisampleQuality
,
1058 Discard_or_Lockable
, ppSurface
, pSharedHandle
);
1061 DBG("FIXME Used shared handle! This option isn't probably handled correctly!\n");
1063 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
1064 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1066 templ
.target
= PIPE_TEXTURE_2D
;
1067 templ
.width0
= Width
;
1068 templ
.height0
= Height
;
1070 templ
.array_size
= 1;
1071 templ
.last_level
= 0;
1072 templ
.nr_samples
= (unsigned)MultiSample
;
1073 templ
.usage
= PIPE_USAGE_DEFAULT
;
1075 templ
.bind
= PIPE_BIND_SAMPLER_VIEW
; /* StretchRect */
1077 case 0: templ
.bind
|= PIPE_BIND_RENDER_TARGET
; break;
1078 case 1: templ
.bind
= d3d9_get_pipe_depth_format_bindings(Format
); break;
1083 templ
.format
= d3d9_to_pipe_format_checked(screen
, Format
, templ
.target
,
1084 templ
.nr_samples
, templ
.bind
,
1087 desc
.Format
= Format
;
1088 desc
.Type
= D3DRTYPE_SURFACE
;
1091 desc
.MultiSampleType
= MultiSample
;
1092 desc
.MultiSampleQuality
= MultisampleQuality
;
1094 desc
.Height
= Height
;
1096 case 0: desc
.Usage
= D3DUSAGE_RENDERTARGET
; break;
1097 case 1: desc
.Usage
= D3DUSAGE_DEPTHSTENCIL
; break;
1101 if (compressed_format(Format
)) {
1102 const unsigned w
= util_format_get_blockwidth(templ
.format
);
1103 const unsigned h
= util_format_get_blockheight(templ
.format
);
1105 user_assert(!(Width
% w
) && !(Height
% h
), D3DERR_INVALIDCALL
);
1108 if (Pool
== D3DPOOL_DEFAULT
&& Format
!= D3DFMT_NULL
) {
1109 /* resource_create doesn't return an error code, so check format here */
1110 user_assert(templ
.format
!= PIPE_FORMAT_NONE
, D3DERR_INVALIDCALL
);
1111 resource
= screen
->resource_create(screen
, &templ
);
1112 user_assert(resource
, D3DERR_OUTOFVIDEOMEMORY
);
1113 if (Discard_or_Lockable
&& (desc
.Usage
& D3DUSAGE_RENDERTARGET
))
1114 resource
->flags
|= NINE_RESOURCE_FLAG_LOCKABLE
;
1118 hr
= NineSurface9_new(This
, NULL
, resource
, NULL
, 0, 0, 0, &desc
, &surface
);
1119 pipe_resource_reference(&resource
, NULL
);
1122 *ppSurface
= (IDirect3DSurface9
*)surface
;
1127 NineDevice9_CreateRenderTarget( struct NineDevice9
*This
,
1131 D3DMULTISAMPLE_TYPE MultiSample
,
1132 DWORD MultisampleQuality
,
1134 IDirect3DSurface9
**ppSurface
,
1135 HANDLE
*pSharedHandle
)
1138 return create_zs_or_rt_surface(This
, 0, D3DPOOL_DEFAULT
,
1139 Width
, Height
, Format
,
1140 MultiSample
, MultisampleQuality
,
1141 Lockable
, ppSurface
, pSharedHandle
);
1145 NineDevice9_CreateDepthStencilSurface( struct NineDevice9
*This
,
1149 D3DMULTISAMPLE_TYPE MultiSample
,
1150 DWORD MultisampleQuality
,
1152 IDirect3DSurface9
**ppSurface
,
1153 HANDLE
*pSharedHandle
)
1156 if (!depth_stencil_format(Format
))
1157 return D3DERR_NOTAVAILABLE
;
1158 return create_zs_or_rt_surface(This
, 1, D3DPOOL_DEFAULT
,
1159 Width
, Height
, Format
,
1160 MultiSample
, MultisampleQuality
,
1161 Discard
, ppSurface
, pSharedHandle
);
1165 NineDevice9_UpdateSurface( struct NineDevice9
*This
,
1166 IDirect3DSurface9
*pSourceSurface
,
1167 const RECT
*pSourceRect
,
1168 IDirect3DSurface9
*pDestinationSurface
,
1169 const POINT
*pDestPoint
)
1171 struct NineSurface9
*dst
= NineSurface9(pDestinationSurface
);
1172 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1173 int copy_width
, copy_height
;
1176 DBG("This=%p pSourceSurface=%p pDestinationSurface=%p "
1177 "pSourceRect=%p pDestPoint=%p\n", This
,
1178 pSourceSurface
, pDestinationSurface
, pSourceRect
, pDestPoint
);
1180 DBG("pSourceRect = (%u,%u)-(%u,%u)\n",
1181 pSourceRect
->left
, pSourceRect
->top
,
1182 pSourceRect
->right
, pSourceRect
->bottom
);
1184 DBG("pDestPoint = (%u,%u)\n", pDestPoint
->x
, pDestPoint
->y
);
1186 user_assert(dst
&& src
, D3DERR_INVALIDCALL
);
1188 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1189 user_assert(src
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1191 user_assert(dst
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1192 user_assert(src
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1194 user_assert(!src
->lock_count
, D3DERR_INVALIDCALL
);
1195 user_assert(!dst
->lock_count
, D3DERR_INVALIDCALL
);
1197 user_assert(dst
->desc
.Format
== src
->desc
.Format
, D3DERR_INVALIDCALL
);
1198 user_assert(!depth_stencil_format(dst
->desc
.Format
), D3DERR_INVALIDCALL
);
1201 copy_width
= pSourceRect
->right
- pSourceRect
->left
;
1202 copy_height
= pSourceRect
->bottom
- pSourceRect
->top
;
1204 user_assert(pSourceRect
->left
>= 0 &&
1206 pSourceRect
->right
<= src
->desc
.Width
&&
1207 pSourceRect
->top
>= 0 &&
1209 pSourceRect
->bottom
<= src
->desc
.Height
,
1210 D3DERR_INVALIDCALL
);
1212 copy_width
= src
->desc
.Width
;
1213 copy_height
= src
->desc
.Height
;
1216 destRect
.right
= copy_width
;
1217 destRect
.bottom
= copy_height
;
1220 user_assert(pDestPoint
->x
>= 0 && pDestPoint
->y
>= 0,
1221 D3DERR_INVALIDCALL
);
1222 destRect
.right
+= pDestPoint
->x
;
1223 destRect
.bottom
+= pDestPoint
->y
;
1226 user_assert(destRect
.right
<= dst
->desc
.Width
&&
1227 destRect
.bottom
<= dst
->desc
.Height
,
1228 D3DERR_INVALIDCALL
);
1230 if (compressed_format(dst
->desc
.Format
)) {
1231 const unsigned w
= util_format_get_blockwidth(dst
->base
.info
.format
);
1232 const unsigned h
= util_format_get_blockheight(dst
->base
.info
.format
);
1235 user_assert(!(pDestPoint
->x
% w
) && !(pDestPoint
->y
% h
),
1236 D3DERR_INVALIDCALL
);
1240 user_assert(!(pSourceRect
->left
% w
) && !(pSourceRect
->top
% h
),
1241 D3DERR_INVALIDCALL
);
1243 if (!(copy_width
== src
->desc
.Width
&&
1244 copy_width
== dst
->desc
.Width
&&
1245 copy_height
== src
->desc
.Height
&&
1246 copy_height
== dst
->desc
.Height
)) {
1247 user_assert(!(copy_width
% w
) && !(copy_height
% h
),
1248 D3DERR_INVALIDCALL
);
1252 NineSurface9_CopyMemToDefault(dst
, src
, pDestPoint
, pSourceRect
);
1258 NineDevice9_UpdateTexture( struct NineDevice9
*This
,
1259 IDirect3DBaseTexture9
*pSourceTexture
,
1260 IDirect3DBaseTexture9
*pDestinationTexture
)
1262 struct NineBaseTexture9
*dstb
= NineBaseTexture9(pDestinationTexture
);
1263 struct NineBaseTexture9
*srcb
= NineBaseTexture9(pSourceTexture
);
1265 unsigned last_level
= dstb
->base
.info
.last_level
;
1268 DBG("This=%p pSourceTexture=%p pDestinationTexture=%p\n", This
,
1269 pSourceTexture
, pDestinationTexture
);
1271 user_assert(pSourceTexture
!= pDestinationTexture
, D3DERR_INVALIDCALL
);
1273 user_assert(dstb
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1274 user_assert(srcb
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1276 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1277 /* Only the first level is updated, the others regenerated. */
1279 /* if the source has D3DUSAGE_AUTOGENMIPMAP, we have to ignore
1280 * the sublevels, thus level 0 has to match */
1281 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ||
1282 (srcb
->base
.info
.width0
== dstb
->base
.info
.width0
&&
1283 srcb
->base
.info
.height0
== dstb
->base
.info
.height0
&&
1284 srcb
->base
.info
.depth0
== dstb
->base
.info
.depth0
),
1285 D3DERR_INVALIDCALL
);
1287 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
), D3DERR_INVALIDCALL
);
1290 user_assert(dstb
->base
.type
== srcb
->base
.type
, D3DERR_INVALIDCALL
);
1292 /* Find src level that matches dst level 0: */
1293 user_assert(srcb
->base
.info
.width0
>= dstb
->base
.info
.width0
&&
1294 srcb
->base
.info
.height0
>= dstb
->base
.info
.height0
&&
1295 srcb
->base
.info
.depth0
>= dstb
->base
.info
.depth0
,
1296 D3DERR_INVALIDCALL
);
1297 for (m
= 0; m
<= srcb
->base
.info
.last_level
; ++m
) {
1298 unsigned w
= u_minify(srcb
->base
.info
.width0
, m
);
1299 unsigned h
= u_minify(srcb
->base
.info
.height0
, m
);
1300 unsigned d
= u_minify(srcb
->base
.info
.depth0
, m
);
1302 if (w
== dstb
->base
.info
.width0
&&
1303 h
== dstb
->base
.info
.height0
&&
1304 d
== dstb
->base
.info
.depth0
)
1307 user_assert(m
<= srcb
->base
.info
.last_level
, D3DERR_INVALIDCALL
);
1309 last_level
= MIN2(last_level
, srcb
->base
.info
.last_level
- m
);
1311 if (dstb
->base
.type
== D3DRTYPE_TEXTURE
) {
1312 struct NineTexture9
*dst
= NineTexture9(dstb
);
1313 struct NineTexture9
*src
= NineTexture9(srcb
);
1315 if (src
->dirty_rect
.width
== 0)
1318 pipe_box_to_rect(&rect
, &src
->dirty_rect
);
1319 for (l
= 0; l
< m
; ++l
)
1320 rect_minify_inclusive(&rect
);
1322 for (l
= 0; l
<= last_level
; ++l
, ++m
) {
1323 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1325 dst
->surfaces
[l
]->desc
.Width
,
1326 dst
->surfaces
[l
]->desc
.Height
);
1327 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
],
1331 rect_minify_inclusive(&rect
);
1333 u_box_origin_2d(0, 0, &src
->dirty_rect
);
1335 if (dstb
->base
.type
== D3DRTYPE_CUBETEXTURE
) {
1336 struct NineCubeTexture9
*dst
= NineCubeTexture9(dstb
);
1337 struct NineCubeTexture9
*src
= NineCubeTexture9(srcb
);
1340 /* GPUs usually have them stored as arrays of mip-mapped 2D textures. */
1341 for (z
= 0; z
< 6; ++z
) {
1342 if (src
->dirty_rect
[z
].width
== 0)
1345 pipe_box_to_rect(&rect
, &src
->dirty_rect
[z
]);
1346 for (l
= 0; l
< m
; ++l
)
1347 rect_minify_inclusive(&rect
);
1349 for (l
= 0; l
<= last_level
; ++l
, ++m
) {
1350 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1352 dst
->surfaces
[l
* 6 + z
]->desc
.Width
,
1353 dst
->surfaces
[l
* 6 + z
]->desc
.Height
);
1354 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
* 6 + z
],
1355 src
->surfaces
[m
* 6 + z
],
1358 rect_minify_inclusive(&rect
);
1360 u_box_origin_2d(0, 0, &src
->dirty_rect
[z
]);
1364 if (dstb
->base
.type
== D3DRTYPE_VOLUMETEXTURE
) {
1365 struct NineVolumeTexture9
*dst
= NineVolumeTexture9(dstb
);
1366 struct NineVolumeTexture9
*src
= NineVolumeTexture9(srcb
);
1368 if (src
->dirty_box
.width
== 0)
1370 for (l
= 0; l
<= last_level
; ++l
, ++m
)
1371 NineVolume9_CopyMemToDefault(dst
->volumes
[l
],
1372 src
->volumes
[m
], 0, 0, 0, NULL
);
1373 u_box_3d(0, 0, 0, 0, 0, 0, &src
->dirty_box
);
1375 assert(!"invalid texture type");
1378 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1379 dstb
->dirty_mip
= TRUE
;
1380 NineBaseTexture9_GenerateMipSubLevels(dstb
);
1387 NineDevice9_GetRenderTargetData( struct NineDevice9
*This
,
1388 IDirect3DSurface9
*pRenderTarget
,
1389 IDirect3DSurface9
*pDestSurface
)
1391 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1392 struct NineSurface9
*src
= NineSurface9(pRenderTarget
);
1394 DBG("This=%p pRenderTarget=%p pDestSurface=%p\n",
1395 This
, pRenderTarget
, pDestSurface
);
1397 user_assert(dst
->desc
.Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1398 user_assert(src
->desc
.Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1400 user_assert(dst
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1401 user_assert(src
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1403 user_assert(src
->desc
.Width
== dst
->desc
.Width
, D3DERR_INVALIDCALL
);
1404 user_assert(src
->desc
.Height
== dst
->desc
.Height
, D3DERR_INVALIDCALL
);
1406 NineSurface9_CopyDefaultToMem(dst
, src
);
1412 NineDevice9_GetFrontBufferData( struct NineDevice9
*This
,
1414 IDirect3DSurface9
*pDestSurface
)
1416 DBG("This=%p iSwapChain=%u pDestSurface=%p\n", This
,
1417 iSwapChain
, pDestSurface
);
1419 user_assert(pDestSurface
!= NULL
, D3DERR_INVALIDCALL
);
1420 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
1422 return NineSwapChain9_GetFrontBufferData(This
->swapchains
[iSwapChain
],
1427 NineDevice9_StretchRect( struct NineDevice9
*This
,
1428 IDirect3DSurface9
*pSourceSurface
,
1429 const RECT
*pSourceRect
,
1430 IDirect3DSurface9
*pDestSurface
,
1431 const RECT
*pDestRect
,
1432 D3DTEXTUREFILTERTYPE Filter
)
1434 struct pipe_screen
*screen
= This
->screen
;
1435 struct pipe_context
*pipe
= This
->pipe
;
1436 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1437 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1438 struct pipe_resource
*dst_res
= NineSurface9_GetResource(dst
);
1439 struct pipe_resource
*src_res
= NineSurface9_GetResource(src
);
1440 const boolean zs
= util_format_is_depth_or_stencil(dst_res
->format
);
1441 struct pipe_blit_info blit
;
1442 boolean scaled
, clamped
, ms
, flip_x
= FALSE
, flip_y
= FALSE
;
1444 DBG("This=%p pSourceSurface=%p pSourceRect=%p pDestSurface=%p "
1445 "pDestRect=%p Filter=%u\n",
1446 This
, pSourceSurface
, pSourceRect
, pDestSurface
, pDestRect
, Filter
);
1448 DBG("pSourceRect=(%u,%u)-(%u,%u)\n",
1449 pSourceRect
->left
, pSourceRect
->top
,
1450 pSourceRect
->right
, pSourceRect
->bottom
);
1452 DBG("pDestRect=(%u,%u)-(%u,%u)\n", pDestRect
->left
, pDestRect
->top
,
1453 pDestRect
->right
, pDestRect
->bottom
);
1455 user_assert(!zs
|| !This
->in_scene
, D3DERR_INVALIDCALL
);
1456 user_assert(!zs
|| !pSourceRect
||
1457 (pSourceRect
->left
== 0 &&
1458 pSourceRect
->top
== 0 &&
1459 pSourceRect
->right
== src
->desc
.Width
&&
1460 pSourceRect
->bottom
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1461 user_assert(!zs
|| !pDestRect
||
1462 (pDestRect
->left
== 0 &&
1463 pDestRect
->top
== 0 &&
1464 pDestRect
->right
== dst
->desc
.Width
&&
1465 pDestRect
->bottom
== dst
->desc
.Height
), D3DERR_INVALIDCALL
);
1467 (dst
->desc
.Width
== src
->desc
.Width
&&
1468 dst
->desc
.Height
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1469 user_assert(zs
|| !util_format_is_depth_or_stencil(src_res
->format
),
1470 D3DERR_INVALIDCALL
);
1471 user_assert(!zs
|| dst
->desc
.Format
== src
->desc
.Format
,
1472 D3DERR_INVALIDCALL
);
1473 user_assert(screen
->is_format_supported(screen
, src_res
->format
,
1475 src_res
->nr_samples
,
1476 PIPE_BIND_SAMPLER_VIEW
),
1477 D3DERR_INVALIDCALL
);
1478 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
&&
1479 src
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1481 /* We might want to permit these, but wine thinks we shouldn't. */
1482 user_assert(!pDestRect
||
1483 (pDestRect
->left
<= pDestRect
->right
&&
1484 pDestRect
->top
<= pDestRect
->bottom
), D3DERR_INVALIDCALL
);
1485 user_assert(!pSourceRect
||
1486 (pSourceRect
->left
<= pSourceRect
->right
&&
1487 pSourceRect
->top
<= pSourceRect
->bottom
), D3DERR_INVALIDCALL
);
1489 memset(&blit
, 0, sizeof(blit
));
1490 blit
.dst
.resource
= dst_res
;
1491 blit
.dst
.level
= dst
->level
;
1492 blit
.dst
.box
.z
= dst
->layer
;
1493 blit
.dst
.box
.depth
= 1;
1494 blit
.dst
.format
= dst_res
->format
;
1496 flip_x
= pDestRect
->left
> pDestRect
->right
;
1498 blit
.dst
.box
.x
= pDestRect
->right
;
1499 blit
.dst
.box
.width
= pDestRect
->left
- pDestRect
->right
;
1501 blit
.dst
.box
.x
= pDestRect
->left
;
1502 blit
.dst
.box
.width
= pDestRect
->right
- pDestRect
->left
;
1504 flip_y
= pDestRect
->top
> pDestRect
->bottom
;
1506 blit
.dst
.box
.y
= pDestRect
->bottom
;
1507 blit
.dst
.box
.height
= pDestRect
->top
- pDestRect
->bottom
;
1509 blit
.dst
.box
.y
= pDestRect
->top
;
1510 blit
.dst
.box
.height
= pDestRect
->bottom
- pDestRect
->top
;
1515 blit
.dst
.box
.width
= dst
->desc
.Width
;
1516 blit
.dst
.box
.height
= dst
->desc
.Height
;
1518 blit
.src
.resource
= src_res
;
1519 blit
.src
.level
= src
->level
;
1520 blit
.src
.box
.z
= src
->layer
;
1521 blit
.src
.box
.depth
= 1;
1522 blit
.src
.format
= src_res
->format
;
1524 if (flip_x
^ (pSourceRect
->left
> pSourceRect
->right
)) {
1525 blit
.src
.box
.x
= pSourceRect
->right
;
1526 blit
.src
.box
.width
= pSourceRect
->left
- pSourceRect
->right
;
1528 blit
.src
.box
.x
= pSourceRect
->left
;
1529 blit
.src
.box
.width
= pSourceRect
->right
- pSourceRect
->left
;
1531 if (flip_y
^ (pSourceRect
->top
> pSourceRect
->bottom
)) {
1532 blit
.src
.box
.y
= pSourceRect
->bottom
;
1533 blit
.src
.box
.height
= pSourceRect
->top
- pSourceRect
->bottom
;
1535 blit
.src
.box
.y
= pSourceRect
->top
;
1536 blit
.src
.box
.height
= pSourceRect
->bottom
- pSourceRect
->top
;
1539 blit
.src
.box
.x
= flip_x
? src
->desc
.Width
: 0;
1540 blit
.src
.box
.y
= flip_y
? src
->desc
.Height
: 0;
1541 blit
.src
.box
.width
= flip_x
? -src
->desc
.Width
: src
->desc
.Width
;
1542 blit
.src
.box
.height
= flip_y
? -src
->desc
.Height
: src
->desc
.Height
;
1544 blit
.mask
= zs
? PIPE_MASK_ZS
: PIPE_MASK_RGBA
;
1545 blit
.filter
= Filter
== D3DTEXF_LINEAR
?
1546 PIPE_TEX_FILTER_LINEAR
: PIPE_TEX_FILTER_NEAREST
;
1547 blit
.scissor_enable
= FALSE
;
1548 blit
.alpha_blend
= FALSE
;
1550 /* If both of a src and dst dimension are negative, flip them. */
1551 if (blit
.dst
.box
.width
< 0 && blit
.src
.box
.width
< 0) {
1552 blit
.dst
.box
.width
= -blit
.dst
.box
.width
;
1553 blit
.src
.box
.width
= -blit
.src
.box
.width
;
1555 if (blit
.dst
.box
.height
< 0 && blit
.src
.box
.height
< 0) {
1556 blit
.dst
.box
.height
= -blit
.dst
.box
.height
;
1557 blit
.src
.box
.height
= -blit
.src
.box
.height
;
1560 blit
.dst
.box
.width
!= blit
.src
.box
.width
||
1561 blit
.dst
.box
.height
!= blit
.src
.box
.height
;
1563 user_assert(!scaled
|| dst
!= src
, D3DERR_INVALIDCALL
);
1564 user_assert(!scaled
||
1565 !NineSurface9_IsOffscreenPlain(dst
), D3DERR_INVALIDCALL
);
1566 user_assert(!NineSurface9_IsOffscreenPlain(dst
) ||
1567 NineSurface9_IsOffscreenPlain(src
), D3DERR_INVALIDCALL
);
1568 user_assert(NineSurface9_IsOffscreenPlain(dst
) ||
1569 dst
->desc
.Usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
),
1570 D3DERR_INVALIDCALL
);
1571 user_assert(!scaled
||
1572 (!util_format_is_compressed(dst
->base
.info
.format
) &&
1573 !util_format_is_compressed(src
->base
.info
.format
)),
1574 D3DERR_INVALIDCALL
);
1576 user_warn(src
== dst
&&
1577 u_box_test_intersection_2d(&blit
.src
.box
, &blit
.dst
.box
));
1579 /* Check for clipping/clamping: */
1581 struct pipe_box box
;
1584 xy
= u_box_clip_2d(&box
, &blit
.dst
.box
,
1585 dst
->desc
.Width
, dst
->desc
.Height
);
1589 xy
= u_box_clip_2d(&box
, &blit
.src
.box
,
1590 src
->desc
.Width
, src
->desc
.Height
);
1594 ms
= (dst
->desc
.MultiSampleType
| 1) != (src
->desc
.MultiSampleType
| 1);
1596 if (clamped
|| scaled
|| (blit
.dst
.format
!= blit
.src
.format
) || ms
) {
1597 DBG("using pipe->blit()\n");
1598 /* TODO: software scaling */
1599 user_assert(screen
->is_format_supported(screen
, dst_res
->format
,
1601 dst_res
->nr_samples
,
1602 zs
? PIPE_BIND_DEPTH_STENCIL
:
1603 PIPE_BIND_RENDER_TARGET
),
1604 D3DERR_INVALIDCALL
);
1606 pipe
->blit(pipe
, &blit
);
1608 assert(blit
.dst
.box
.x
>= 0 && blit
.dst
.box
.y
>= 0 &&
1609 blit
.src
.box
.x
>= 0 && blit
.src
.box
.y
>= 0 &&
1610 blit
.dst
.box
.x
+ blit
.dst
.box
.width
<= dst
->desc
.Width
&&
1611 blit
.src
.box
.x
+ blit
.src
.box
.width
<= src
->desc
.Width
&&
1612 blit
.dst
.box
.y
+ blit
.dst
.box
.height
<= dst
->desc
.Height
&&
1613 blit
.src
.box
.y
+ blit
.src
.box
.height
<= src
->desc
.Height
);
1614 /* Or drivers might crash ... */
1615 DBG("Using resource_copy_region.\n");
1616 pipe
->resource_copy_region(pipe
,
1617 blit
.dst
.resource
, blit
.dst
.level
,
1618 blit
.dst
.box
.x
, blit
.dst
.box
.y
, blit
.dst
.box
.z
,
1619 blit
.src
.resource
, blit
.src
.level
,
1623 /* Communicate the container it needs to update sublevels - if apply */
1624 NineSurface9_MarkContainerDirty(dst
);
1630 NineDevice9_ColorFill( struct NineDevice9
*This
,
1631 IDirect3DSurface9
*pSurface
,
1635 struct pipe_context
*pipe
= This
->pipe
;
1636 struct NineSurface9
*surf
= NineSurface9(pSurface
);
1637 struct pipe_surface
*psurf
;
1638 unsigned x
, y
, w
, h
;
1639 union pipe_color_union rgba
;
1642 DBG("This=%p pSurface=%p pRect=%p color=%08x\n", This
,
1643 pSurface
, pRect
, color
);
1645 DBG("pRect=(%u,%u)-(%u,%u)\n", pRect
->left
, pRect
->top
,
1646 pRect
->right
, pRect
->bottom
);
1648 user_assert(surf
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1650 user_assert((surf
->base
.usage
& D3DUSAGE_RENDERTARGET
) ||
1651 NineSurface9_IsOffscreenPlain(surf
), D3DERR_INVALIDCALL
);
1656 w
= pRect
->right
- pRect
->left
;
1657 h
= pRect
->bottom
- pRect
->top
;
1661 w
= surf
->desc
.Width
;
1662 h
= surf
->desc
.Height
;
1664 d3dcolor_to_pipe_color_union(&rgba
, color
);
1666 fallback
= !(surf
->base
.info
.bind
& PIPE_BIND_RENDER_TARGET
);
1669 psurf
= NineSurface9_GetSurface(surf
, 0);
1675 pipe
->clear_render_target(pipe
, psurf
, &rgba
, x
, y
, w
, h
);
1677 D3DLOCKED_RECT lock
;
1678 union util_color uc
;
1680 /* XXX: lock pRect and fix util_fill_rect */
1681 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, 0);
1684 util_pack_color_ub(color
>> 16, color
>> 8, color
>> 0, color
>> 24,
1685 surf
->base
.info
.format
, &uc
);
1686 util_fill_rect(lock
.pBits
, surf
->base
.info
.format
,lock
.Pitch
,
1688 NineSurface9_UnlockRect(surf
);
1695 NineDevice9_CreateOffscreenPlainSurface( struct NineDevice9
*This
,
1700 IDirect3DSurface9
**ppSurface
,
1701 HANDLE
*pSharedHandle
)
1705 DBG("This=%p Width=%u Height=%u Format=%s(0x%x) Pool=%u "
1706 "ppSurface=%p pSharedHandle=%p\n", This
,
1707 Width
, Height
, d3dformat_to_string(Format
), Format
, Pool
,
1708 ppSurface
, pSharedHandle
);
1711 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
1712 || Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1713 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1715 /* Can be used with StretchRect and ColorFill. It's also always lockable.
1717 hr
= create_zs_or_rt_surface(This
, 2, Pool
, Width
, Height
,
1719 D3DMULTISAMPLE_NONE
, 0,
1721 ppSurface
, pSharedHandle
);
1723 DBG("Failed to create surface.\n");
1728 NineDevice9_SetRenderTarget( struct NineDevice9
*This
,
1729 DWORD RenderTargetIndex
,
1730 IDirect3DSurface9
*pRenderTarget
)
1732 struct NineSurface9
*rt
= NineSurface9(pRenderTarget
);
1733 const unsigned i
= RenderTargetIndex
;
1735 DBG("This=%p RenderTargetIndex=%u pRenderTarget=%p\n", This
,
1736 RenderTargetIndex
, pRenderTarget
);
1738 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1739 user_assert(i
!= 0 || pRenderTarget
, D3DERR_INVALIDCALL
);
1740 user_assert(!pRenderTarget
||
1741 rt
->desc
.Usage
& D3DUSAGE_RENDERTARGET
, D3DERR_INVALIDCALL
);
1744 This
->state
.viewport
.X
= 0;
1745 This
->state
.viewport
.Y
= 0;
1746 This
->state
.viewport
.Width
= rt
->desc
.Width
;
1747 This
->state
.viewport
.Height
= rt
->desc
.Height
;
1748 This
->state
.viewport
.MinZ
= 0.0f
;
1749 This
->state
.viewport
.MaxZ
= 1.0f
;
1751 This
->state
.scissor
.minx
= 0;
1752 This
->state
.scissor
.miny
= 0;
1753 This
->state
.scissor
.maxx
= rt
->desc
.Width
;
1754 This
->state
.scissor
.maxy
= rt
->desc
.Height
;
1756 This
->state
.changed
.group
|= NINE_STATE_VIEWPORT
| NINE_STATE_SCISSOR
;
1759 if (This
->state
.rt
[i
] != NineSurface9(pRenderTarget
)) {
1760 nine_bind(&This
->state
.rt
[i
], pRenderTarget
);
1761 This
->state
.changed
.group
|= NINE_STATE_FB
;
1767 NineDevice9_GetRenderTarget( struct NineDevice9
*This
,
1768 DWORD RenderTargetIndex
,
1769 IDirect3DSurface9
**ppRenderTarget
)
1771 const unsigned i
= RenderTargetIndex
;
1773 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1774 user_assert(ppRenderTarget
, D3DERR_INVALIDCALL
);
1776 *ppRenderTarget
= (IDirect3DSurface9
*)This
->state
.rt
[i
];
1777 if (!This
->state
.rt
[i
])
1778 return D3DERR_NOTFOUND
;
1780 NineUnknown_AddRef(NineUnknown(This
->state
.rt
[i
]));
1785 NineDevice9_SetDepthStencilSurface( struct NineDevice9
*This
,
1786 IDirect3DSurface9
*pNewZStencil
)
1788 DBG("This=%p pNewZStencil=%p\n", This
, pNewZStencil
);
1790 if (This
->state
.ds
!= NineSurface9(pNewZStencil
)) {
1791 nine_bind(&This
->state
.ds
, pNewZStencil
);
1792 This
->state
.changed
.group
|= NINE_STATE_FB
;
1798 NineDevice9_GetDepthStencilSurface( struct NineDevice9
*This
,
1799 IDirect3DSurface9
**ppZStencilSurface
)
1801 user_assert(ppZStencilSurface
, D3DERR_INVALIDCALL
);
1803 *ppZStencilSurface
= (IDirect3DSurface9
*)This
->state
.ds
;
1804 if (!This
->state
.ds
)
1805 return D3DERR_NOTFOUND
;
1807 NineUnknown_AddRef(NineUnknown(This
->state
.ds
));
1812 NineDevice9_BeginScene( struct NineDevice9
*This
)
1814 DBG("This=%p\n", This
);
1815 user_assert(!This
->in_scene
, D3DERR_INVALIDCALL
);
1816 This
->in_scene
= TRUE
;
1817 /* Do we want to do anything else here ? */
1822 NineDevice9_EndScene( struct NineDevice9
*This
)
1824 DBG("This=%p\n", This
);
1825 user_assert(This
->in_scene
, D3DERR_INVALIDCALL
);
1826 This
->in_scene
= FALSE
;
1831 NineDevice9_Clear( struct NineDevice9
*This
,
1833 const D3DRECT
*pRects
,
1839 const int sRGB
= This
->state
.rs
[D3DRS_SRGBWRITEENABLE
] ? 1 : 0;
1840 struct pipe_surface
*cbuf
, *zsbuf
;
1841 struct pipe_context
*pipe
= This
->pipe
;
1842 struct NineSurface9
*zsbuf_surf
= This
->state
.ds
;
1843 struct NineSurface9
*rt
;
1846 union pipe_color_union rgba
;
1847 unsigned rt_mask
= 0;
1850 DBG("This=%p Count=%u pRects=%p Flags=%x Color=%08x Z=%f Stencil=%x\n",
1851 This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1853 user_assert(This
->state
.ds
|| !(Flags
& NINED3DCLEAR_DEPTHSTENCIL
),
1854 D3DERR_INVALIDCALL
);
1855 user_assert(!(Flags
& D3DCLEAR_STENCIL
) ||
1857 util_format_is_depth_and_stencil(zsbuf_surf
->base
.info
.format
)),
1858 D3DERR_INVALIDCALL
);
1860 user_assert((Count
&& pRects
) || (!Count
&& !pRects
), D3DERR_INVALIDCALL
);
1862 user_warn((pRects
&& !Count
) || (!pRects
&& Count
));
1863 if (pRects
&& !Count
)
1869 if (Flags
& D3DCLEAR_TARGET
) bufs
|= PIPE_CLEAR_COLOR
;
1870 if (Flags
& D3DCLEAR_ZBUFFER
) bufs
|= PIPE_CLEAR_DEPTH
;
1871 if (Flags
& D3DCLEAR_STENCIL
) bufs
|= PIPE_CLEAR_STENCIL
;
1874 d3dcolor_to_pipe_color_union(&rgba
, Color
);
1876 nine_update_state_framebuffer(This
);
1878 rect
.x1
= This
->state
.viewport
.X
;
1879 rect
.y1
= This
->state
.viewport
.Y
;
1880 rect
.x2
= This
->state
.viewport
.Width
+ rect
.x1
;
1881 rect
.y2
= This
->state
.viewport
.Height
+ rect
.y1
;
1883 /* Both rectangles apply, which is weird, but that's D3D9. */
1884 if (This
->state
.rs
[D3DRS_SCISSORTESTENABLE
]) {
1885 rect
.x1
= MAX2(rect
.x1
, This
->state
.scissor
.minx
);
1886 rect
.y1
= MAX2(rect
.y1
, This
->state
.scissor
.miny
);
1887 rect
.x2
= MIN2(rect
.x2
, This
->state
.scissor
.maxx
);
1888 rect
.y2
= MIN2(rect
.y2
, This
->state
.scissor
.maxy
);
1892 /* Maybe apps like to specify a large rect ? */
1893 if (pRects
[0].x1
<= rect
.x1
&& pRects
[0].x2
>= rect
.x2
&&
1894 pRects
[0].y1
<= rect
.y1
&& pRects
[0].y2
>= rect
.y2
) {
1895 DBG("First rect covers viewport.\n");
1901 if (rect
.x1
>= This
->state
.fb
.width
|| rect
.y1
>= This
->state
.fb
.height
)
1904 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
1905 if (This
->state
.rt
[i
] && This
->state
.rt
[i
]->desc
.Format
!= D3DFMT_NULL
)
1909 /* fast path, clears everything at once */
1911 (!(bufs
& PIPE_CLEAR_COLOR
) || (rt_mask
== This
->state
.rt_mask
)) &&
1912 rect
.x1
== 0 && rect
.y1
== 0 &&
1913 /* Case we clear only render target. Check clear region vs rt. */
1914 ((!(bufs
& (PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
)) &&
1915 rect
.x2
>= This
->state
.fb
.width
&&
1916 rect
.y2
>= This
->state
.fb
.height
) ||
1917 /* Case we clear depth buffer (and eventually rt too).
1918 * depth buffer size is always >= rt size. Compare to clear region */
1919 ((bufs
& (PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
)) &&
1920 This
->state
.fb
.zsbuf
!= NULL
&&
1921 rect
.x2
>= zsbuf_surf
->desc
.Width
&&
1922 rect
.y2
>= zsbuf_surf
->desc
.Height
))) {
1923 DBG("Clear fast path\n");
1924 pipe
->clear(pipe
, bufs
, &rgba
, Z
, Stencil
);
1933 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
1934 rt
= This
->state
.rt
[i
];
1935 if (!rt
|| rt
->desc
.Format
== D3DFMT_NULL
||
1936 !(Flags
& D3DCLEAR_TARGET
))
1937 continue; /* save space, compiler should hoist this */
1938 cbuf
= NineSurface9_GetSurface(rt
, sRGB
);
1939 for (r
= 0; r
< Count
; ++r
) {
1940 /* Don't trust users to pass these in the right order. */
1941 unsigned x1
= MIN2(pRects
[r
].x1
, pRects
[r
].x2
);
1942 unsigned y1
= MIN2(pRects
[r
].y1
, pRects
[r
].y2
);
1943 unsigned x2
= MAX2(pRects
[r
].x1
, pRects
[r
].x2
);
1944 unsigned y2
= MAX2(pRects
[r
].y1
, pRects
[r
].y2
);
1946 /* Drop negative rectangles (like wine expects). */
1947 if (pRects
[r
].x1
> pRects
[r
].x2
) continue;
1948 if (pRects
[r
].y1
> pRects
[r
].y2
) continue;
1951 x1
= MAX2(x1
, rect
.x1
);
1952 y1
= MAX2(y1
, rect
.y1
);
1953 x2
= MIN3(x2
, rect
.x2
, rt
->desc
.Width
);
1954 y2
= MIN3(y2
, rect
.y2
, rt
->desc
.Height
);
1956 DBG("Clearing (%u..%u)x(%u..%u)\n", x1
, x2
, y1
, y2
);
1957 pipe
->clear_render_target(pipe
, cbuf
, &rgba
,
1958 x1
, y1
, x2
- x1
, y2
- y1
);
1961 if (!(Flags
& NINED3DCLEAR_DEPTHSTENCIL
))
1964 bufs
&= PIPE_CLEAR_DEPTHSTENCIL
;
1966 for (r
= 0; r
< Count
; ++r
) {
1967 unsigned x1
= MIN2(pRects
[r
].x1
, pRects
[r
].x2
);
1968 unsigned y1
= MIN2(pRects
[r
].y1
, pRects
[r
].y2
);
1969 unsigned x2
= MAX2(pRects
[r
].x1
, pRects
[r
].x2
);
1970 unsigned y2
= MAX2(pRects
[r
].y1
, pRects
[r
].y2
);
1972 /* Drop negative rectangles. */
1973 if (pRects
[r
].x1
> pRects
[r
].x2
) continue;
1974 if (pRects
[r
].y1
> pRects
[r
].y2
) continue;
1977 x1
= MIN2(x1
, rect
.x1
);
1978 y1
= MIN2(y1
, rect
.y1
);
1979 x2
= MIN3(x2
, rect
.x2
, zsbuf_surf
->desc
.Width
);
1980 y2
= MIN3(y2
, rect
.y2
, zsbuf_surf
->desc
.Height
);
1982 zsbuf
= NineSurface9_GetSurface(zsbuf_surf
, 0);
1984 pipe
->clear_depth_stencil(pipe
, zsbuf
, bufs
, Z
, Stencil
,
1985 x1
, y1
, x2
- x1
, y2
- y1
);
1991 NineDevice9_SetTransform( struct NineDevice9
*This
,
1992 D3DTRANSFORMSTATETYPE State
,
1993 const D3DMATRIX
*pMatrix
)
1995 struct nine_state
*state
= This
->update
;
1996 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
1998 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2000 user_assert(M
, D3DERR_INVALIDCALL
);
2003 state
->ff
.changed
.transform
[State
/ 32] |= 1 << (State
% 32);
2004 state
->changed
.group
|= NINE_STATE_FF
;
2010 NineDevice9_GetTransform( struct NineDevice9
*This
,
2011 D3DTRANSFORMSTATETYPE State
,
2012 D3DMATRIX
*pMatrix
)
2014 D3DMATRIX
*M
= nine_state_access_transform(&This
->state
, State
, FALSE
);
2015 user_assert(M
, D3DERR_INVALIDCALL
);
2021 NineDevice9_MultiplyTransform( struct NineDevice9
*This
,
2022 D3DTRANSFORMSTATETYPE State
,
2023 const D3DMATRIX
*pMatrix
)
2025 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
);
2033 nine_d3d_matrix_matrix_mul(&T
, pMatrix
, M
);
2034 return NineDevice9_SetTransform(This
, State
, &T
);
2038 NineDevice9_SetViewport( struct NineDevice9
*This
,
2039 const D3DVIEWPORT9
*pViewport
)
2041 struct nine_state
*state
= This
->update
;
2043 DBG("X=%u Y=%u W=%u H=%u MinZ=%f MaxZ=%f\n",
2044 pViewport
->X
, pViewport
->Y
, pViewport
->Width
, pViewport
->Height
,
2045 pViewport
->MinZ
, pViewport
->MaxZ
);
2047 state
->viewport
= *pViewport
;
2048 state
->changed
.group
|= NINE_STATE_VIEWPORT
;
2054 NineDevice9_GetViewport( struct NineDevice9
*This
,
2055 D3DVIEWPORT9
*pViewport
)
2057 *pViewport
= This
->state
.viewport
;
2062 NineDevice9_SetMaterial( struct NineDevice9
*This
,
2063 const D3DMATERIAL9
*pMaterial
)
2065 struct nine_state
*state
= This
->update
;
2067 DBG("This=%p pMaterial=%p\n", This
, pMaterial
);
2069 nine_dump_D3DMATERIAL9(DBG_FF
, pMaterial
);
2071 user_assert(pMaterial
, E_POINTER
);
2073 state
->ff
.material
= *pMaterial
;
2074 state
->changed
.group
|= NINE_STATE_FF_MATERIAL
;
2080 NineDevice9_GetMaterial( struct NineDevice9
*This
,
2081 D3DMATERIAL9
*pMaterial
)
2083 user_assert(pMaterial
, E_POINTER
);
2084 *pMaterial
= This
->state
.ff
.material
;
2089 NineDevice9_SetLight( struct NineDevice9
*This
,
2091 const D3DLIGHT9
*pLight
)
2093 struct nine_state
*state
= This
->update
;
2095 DBG("This=%p Index=%u pLight=%p\n", This
, Index
, pLight
);
2097 nine_dump_D3DLIGHT9(DBG_FF
, pLight
);
2099 user_assert(pLight
, D3DERR_INVALIDCALL
);
2100 user_assert(pLight
->Type
< NINED3DLIGHT_INVALID
, D3DERR_INVALIDCALL
);
2102 user_assert(Index
< NINE_MAX_LIGHTS
, D3DERR_INVALIDCALL
); /* sanity */
2104 if (Index
>= state
->ff
.num_lights
) {
2105 unsigned n
= state
->ff
.num_lights
;
2106 unsigned N
= Index
+ 1;
2108 state
->ff
.light
= REALLOC(state
->ff
.light
, n
* sizeof(D3DLIGHT9
),
2109 N
* sizeof(D3DLIGHT9
));
2110 if (!state
->ff
.light
)
2111 return E_OUTOFMEMORY
;
2112 state
->ff
.num_lights
= N
;
2114 for (; n
< Index
; ++n
) {
2115 memset(&state
->ff
.light
[n
], 0, sizeof(D3DLIGHT9
));
2116 state
->ff
.light
[n
].Type
= (D3DLIGHTTYPE
)NINED3DLIGHT_INVALID
;
2119 state
->ff
.light
[Index
] = *pLight
;
2121 if (pLight
->Type
== D3DLIGHT_SPOT
&& pLight
->Theta
>= pLight
->Phi
) {
2122 DBG("Warning: clamping D3DLIGHT9.Theta\n");
2123 state
->ff
.light
[Index
].Theta
= state
->ff
.light
[Index
].Phi
;
2125 if (pLight
->Type
!= D3DLIGHT_DIRECTIONAL
&&
2126 pLight
->Attenuation0
== 0.0f
&&
2127 pLight
->Attenuation1
== 0.0f
&&
2128 pLight
->Attenuation2
== 0.0f
) {
2129 DBG("Warning: all D3DLIGHT9.Attenuation[i] are 0\n");
2132 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2138 NineDevice9_GetLight( struct NineDevice9
*This
,
2142 const struct nine_state
*state
= &This
->state
;
2144 user_assert(pLight
, D3DERR_INVALIDCALL
);
2145 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2146 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2147 D3DERR_INVALIDCALL
);
2149 *pLight
= state
->ff
.light
[Index
];
2155 NineDevice9_LightEnable( struct NineDevice9
*This
,
2159 struct nine_state
*state
= This
->update
;
2162 DBG("This=%p Index=%u Enable=%i\n", This
, Index
, Enable
);
2164 if (Index
>= state
->ff
.num_lights
||
2165 state
->ff
.light
[Index
].Type
== NINED3DLIGHT_INVALID
) {
2166 /* This should create a default light. */
2168 memset(&light
, 0, sizeof(light
));
2169 light
.Type
= D3DLIGHT_DIRECTIONAL
;
2170 light
.Diffuse
.r
= 1.0f
;
2171 light
.Diffuse
.g
= 1.0f
;
2172 light
.Diffuse
.b
= 1.0f
;
2173 light
.Direction
.z
= 1.0f
;
2174 NineDevice9_SetLight(This
, Index
, &light
);
2176 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2178 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
) {
2179 if (state
->ff
.active_light
[i
] == Index
)
2184 if (i
< state
->ff
.num_lights_active
)
2186 /* XXX wine thinks this should still succeed:
2188 user_assert(i
< NINE_MAX_LIGHTS_ACTIVE
, D3DERR_INVALIDCALL
);
2190 state
->ff
.active_light
[i
] = Index
;
2191 state
->ff
.num_lights_active
++;
2193 if (i
== state
->ff
.num_lights_active
)
2195 --state
->ff
.num_lights_active
;
2196 for (; i
< state
->ff
.num_lights_active
; ++i
)
2197 state
->ff
.active_light
[i
] = state
->ff
.active_light
[i
+ 1];
2199 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2205 NineDevice9_GetLightEnable( struct NineDevice9
*This
,
2209 const struct nine_state
*state
= &This
->state
;
2212 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2213 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2214 D3DERR_INVALIDCALL
);
2216 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
)
2217 if (state
->ff
.active_light
[i
] == Index
)
2220 *pEnable
= i
!= state
->ff
.num_lights_active
? 128 : 0; // Taken from wine
2226 NineDevice9_SetClipPlane( struct NineDevice9
*This
,
2228 const float *pPlane
)
2230 struct nine_state
*state
= This
->update
;
2232 user_assert(pPlane
, D3DERR_INVALIDCALL
);
2234 DBG("This=%p Index=%u pPlane=%f %f %f %f\n", This
, Index
,
2235 pPlane
[0], pPlane
[1],
2236 pPlane
[2], pPlane
[3]);
2238 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2240 memcpy(&state
->clip
.ucp
[Index
][0], pPlane
, sizeof(state
->clip
.ucp
[0]));
2241 state
->changed
.ucp
|= 1 << Index
;
2247 NineDevice9_GetClipPlane( struct NineDevice9
*This
,
2251 const struct nine_state
*state
= &This
->state
;
2253 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2255 memcpy(pPlane
, &state
->clip
.ucp
[Index
][0], sizeof(state
->clip
.ucp
[0]));
2259 #define RESZ_CODE 0x7fa05000
2262 NineDevice9_ResolveZ( struct NineDevice9
*This
)
2264 struct nine_state
*state
= &This
->state
;
2265 const struct util_format_description
*desc
;
2266 struct NineSurface9
*source
= state
->ds
;
2267 struct NineBaseTexture9
*destination
= state
->texture
[0];
2268 struct pipe_resource
*src
, *dst
;
2269 struct pipe_blit_info blit
;
2271 DBG("RESZ resolve\n");
2273 user_assert(source
&& destination
&&
2274 destination
->base
.type
== D3DRTYPE_TEXTURE
, D3DERR_INVALIDCALL
);
2276 src
= source
->base
.resource
;
2277 dst
= destination
->base
.resource
;
2279 user_assert(src
&& dst
, D3DERR_INVALIDCALL
);
2281 /* check dst is depth format. we know already for src */
2282 desc
= util_format_description(dst
->format
);
2283 user_assert(desc
->colorspace
== UTIL_FORMAT_COLORSPACE_ZS
, D3DERR_INVALIDCALL
);
2285 memset(&blit
, 0, sizeof(blit
));
2286 blit
.src
.resource
= src
;
2288 blit
.src
.format
= src
->format
;
2290 blit
.src
.box
.depth
= 1;
2293 blit
.src
.box
.width
= src
->width0
;
2294 blit
.src
.box
.height
= src
->height0
;
2296 blit
.dst
.resource
= dst
;
2298 blit
.dst
.format
= dst
->format
;
2300 blit
.dst
.box
.depth
= 1;
2303 blit
.dst
.box
.width
= dst
->width0
;
2304 blit
.dst
.box
.height
= dst
->height0
;
2306 blit
.mask
= PIPE_MASK_ZS
;
2307 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
2308 blit
.scissor_enable
= FALSE
;
2310 This
->pipe
->blit(This
->pipe
, &blit
);
2314 #define ALPHA_TO_COVERAGE_ENABLE MAKEFOURCC('A', '2', 'M', '1')
2315 #define ALPHA_TO_COVERAGE_DISABLE MAKEFOURCC('A', '2', 'M', '0')
2318 NineDevice9_SetRenderState( struct NineDevice9
*This
,
2319 D3DRENDERSTATETYPE State
,
2322 struct nine_state
*state
= This
->update
;
2324 DBG("This=%p State=%u(%s) Value=%08x\n", This
,
2325 State
, nine_d3drs_to_string(State
), Value
);
2327 /* Amd hacks (equivalent to GL extensions) */
2328 if (State
== D3DRS_POINTSIZE
) {
2329 if (Value
== RESZ_CODE
)
2330 return NineDevice9_ResolveZ(This
);
2332 if (Value
== ALPHA_TO_COVERAGE_ENABLE
||
2333 Value
== ALPHA_TO_COVERAGE_DISABLE
) {
2334 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
== ALPHA_TO_COVERAGE_ENABLE
);
2335 state
->changed
.group
|= NINE_STATE_BLEND
;
2341 if (State
== D3DRS_ADAPTIVETESS_Y
&&
2342 (Value
== D3DFMT_ATOC
|| (Value
== D3DFMT_UNKNOWN
&& state
->rs
[NINED3DRS_ALPHACOVERAGE
]))) {
2343 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
== D3DFMT_ATOC
);
2344 state
->changed
.group
|= NINE_STATE_BLEND
;
2348 user_assert(State
< Elements(state
->rs
), D3DERR_INVALIDCALL
);
2350 if (likely(state
->rs
[State
] != Value
) || unlikely(This
->is_recording
)) {
2351 state
->rs
[State
] = Value
;
2352 state
->changed
.rs
[State
/ 32] |= 1 << (State
% 32);
2353 state
->changed
.group
|= nine_render_state_group
[State
];
2360 NineDevice9_GetRenderState( struct NineDevice9
*This
,
2361 D3DRENDERSTATETYPE State
,
2364 user_assert(State
< Elements(This
->state
.rs
), D3DERR_INVALIDCALL
);
2366 *pValue
= This
->state
.rs
[State
];
2371 NineDevice9_CreateStateBlock( struct NineDevice9
*This
,
2372 D3DSTATEBLOCKTYPE Type
,
2373 IDirect3DStateBlock9
**ppSB
)
2375 struct NineStateBlock9
*nsb
;
2376 struct nine_state
*dst
;
2378 enum nine_stateblock_type type
;
2381 DBG("This=%p Type=%u ppSB=%p\n", This
, Type
, ppSB
);
2383 user_assert(Type
== D3DSBT_ALL
||
2384 Type
== D3DSBT_VERTEXSTATE
||
2385 Type
== D3DSBT_PIXELSTATE
, D3DERR_INVALIDCALL
);
2388 case D3DSBT_VERTEXSTATE
: type
= NINESBT_VERTEXSTATE
; break;
2389 case D3DSBT_PIXELSTATE
: type
= NINESBT_PIXELSTATE
; break;
2395 hr
= NineStateBlock9_new(This
, &nsb
, type
);
2398 *ppSB
= (IDirect3DStateBlock9
*)nsb
;
2401 dst
->changed
.group
=
2402 NINE_STATE_TEXTURE
|
2405 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_VERTEXSTATE
) {
2406 dst
->changed
.group
|=
2407 NINE_STATE_FF_LIGHTING
|
2408 NINE_STATE_VS
| NINE_STATE_VS_CONST
|
2410 /* TODO: texture/sampler state */
2411 memcpy(dst
->changed
.rs
,
2412 nine_render_states_vertex
, sizeof(dst
->changed
.rs
));
2413 nine_ranges_insert(&dst
->changed
.vs_const_f
, 0, This
->max_vs_const_f
,
2415 dst
->changed
.vs_const_i
= 0xffff;
2416 dst
->changed
.vs_const_b
= 0xffff;
2417 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2418 dst
->changed
.sampler
[s
] |= 1 << D3DSAMP_DMAPOFFSET
;
2419 if (This
->state
.ff
.num_lights
) {
2420 dst
->ff
.num_lights
= This
->state
.ff
.num_lights
;
2421 /* zero'd -> light type won't be NINED3DLIGHT_INVALID, so
2422 * all currently existing lights will be captured
2424 dst
->ff
.light
= CALLOC(This
->state
.ff
.num_lights
,
2426 if (!dst
->ff
.light
) {
2427 nine_bind(ppSB
, NULL
);
2428 return E_OUTOFMEMORY
;
2432 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_PIXELSTATE
) {
2433 dst
->changed
.group
|=
2434 NINE_STATE_PS
| NINE_STATE_PS_CONST
;
2435 /* TODO: texture/sampler state */
2436 memcpy(dst
->changed
.rs
,
2437 nine_render_states_pixel
, sizeof(dst
->changed
.rs
));
2438 nine_ranges_insert(&dst
->changed
.ps_const_f
, 0, This
->max_ps_const_f
,
2440 dst
->changed
.ps_const_i
= 0xffff;
2441 dst
->changed
.ps_const_b
= 0xffff;
2442 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2443 dst
->changed
.sampler
[s
] |= 0x1ffe;
2445 if (Type
== D3DSBT_ALL
) {
2446 dst
->changed
.group
|=
2447 NINE_STATE_VIEWPORT
|
2448 NINE_STATE_SCISSOR
|
2449 NINE_STATE_RASTERIZER
|
2453 NINE_STATE_MATERIAL
|
2454 NINE_STATE_BLEND_COLOR
|
2455 NINE_STATE_SAMPLE_MASK
;
2456 memset(dst
->changed
.rs
, ~0, (D3DRS_COUNT
/ 32) * sizeof(uint32_t));
2457 dst
->changed
.rs
[D3DRS_LAST
/ 32] |= (1 << (D3DRS_COUNT
% 32)) - 1;
2458 dst
->changed
.vtxbuf
= (1ULL << This
->caps
.MaxStreams
) - 1;
2459 dst
->changed
.stream_freq
= dst
->changed
.vtxbuf
;
2460 dst
->changed
.ucp
= (1 << PIPE_MAX_CLIP_PLANES
) - 1;
2461 dst
->changed
.texture
= (1 << NINE_MAX_SAMPLERS
) - 1;
2463 NineStateBlock9_Capture(NineStateBlock9(*ppSB
));
2465 /* TODO: fixed function state */
2471 NineDevice9_BeginStateBlock( struct NineDevice9
*This
)
2475 DBG("This=%p\n", This
);
2477 user_assert(!This
->record
, D3DERR_INVALIDCALL
);
2479 hr
= NineStateBlock9_new(This
, &This
->record
, NINESBT_CUSTOM
);
2482 NineUnknown_ConvertRefToBind(NineUnknown(This
->record
));
2484 This
->update
= &This
->record
->state
;
2485 This
->is_recording
= TRUE
;
2491 NineDevice9_EndStateBlock( struct NineDevice9
*This
,
2492 IDirect3DStateBlock9
**ppSB
)
2494 DBG("This=%p ppSB=%p\n", This
, ppSB
);
2496 user_assert(This
->record
, D3DERR_INVALIDCALL
);
2498 This
->update
= &This
->state
;
2499 This
->is_recording
= FALSE
;
2501 NineUnknown_AddRef(NineUnknown(This
->record
));
2502 *ppSB
= (IDirect3DStateBlock9
*)This
->record
;
2503 NineUnknown_Unbind(NineUnknown(This
->record
));
2504 This
->record
= NULL
;
2510 NineDevice9_SetClipStatus( struct NineDevice9
*This
,
2511 const D3DCLIPSTATUS9
*pClipStatus
)
2513 STUB(D3DERR_INVALIDCALL
);
2517 NineDevice9_GetClipStatus( struct NineDevice9
*This
,
2518 D3DCLIPSTATUS9
*pClipStatus
)
2520 STUB(D3DERR_INVALIDCALL
);
2524 NineDevice9_GetTexture( struct NineDevice9
*This
,
2526 IDirect3DBaseTexture9
**ppTexture
)
2528 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2529 Stage
== D3DDMAPSAMPLER
||
2530 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2531 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2532 user_assert(ppTexture
, D3DERR_INVALIDCALL
);
2534 if (Stage
>= D3DDMAPSAMPLER
)
2535 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2537 *ppTexture
= (IDirect3DBaseTexture9
*)This
->state
.texture
[Stage
];
2539 if (This
->state
.texture
[Stage
])
2540 NineUnknown_AddRef(NineUnknown(This
->state
.texture
[Stage
]));
2545 NineDevice9_SetTexture( struct NineDevice9
*This
,
2547 IDirect3DBaseTexture9
*pTexture
)
2549 struct nine_state
*state
= This
->update
;
2550 struct NineBaseTexture9
*tex
= NineBaseTexture9(pTexture
);
2552 DBG("This=%p Stage=%u pTexture=%p\n", This
, Stage
, pTexture
);
2554 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2555 Stage
== D3DDMAPSAMPLER
||
2556 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2557 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2558 user_assert(!tex
|| (tex
->base
.pool
!= D3DPOOL_SCRATCH
&&
2559 tex
->base
.pool
!= D3DPOOL_SYSTEMMEM
), D3DERR_INVALIDCALL
);
2561 if (Stage
>= D3DDMAPSAMPLER
)
2562 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2564 if (!This
->is_recording
) {
2565 struct NineBaseTexture9
*old
= state
->texture
[Stage
];
2569 state
->samplers_shadow
&= ~(1 << Stage
);
2571 state
->samplers_shadow
|= tex
->shadow
<< Stage
;
2573 if ((tex
->managed
.dirty
| tex
->dirty_mip
) && LIST_IS_EMPTY(&tex
->list
))
2574 list_add(&tex
->list
, &This
->update_textures
);
2581 nine_bind(&state
->texture
[Stage
], pTexture
);
2583 state
->changed
.texture
|= 1 << Stage
;
2584 state
->changed
.group
|= NINE_STATE_TEXTURE
;
2590 NineDevice9_GetTextureStageState( struct NineDevice9
*This
,
2592 D3DTEXTURESTAGESTATETYPE Type
,
2595 const struct nine_state
*state
= &This
->state
;
2597 user_assert(Stage
< Elements(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2598 user_assert(Type
< Elements(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2600 *pValue
= state
->ff
.tex_stage
[Stage
][Type
];
2606 NineDevice9_SetTextureStageState( struct NineDevice9
*This
,
2608 D3DTEXTURESTAGESTATETYPE Type
,
2611 struct nine_state
*state
= This
->update
;
2612 int bumpmap_index
= -1;
2614 DBG("Stage=%u Type=%u Value=%08x\n", Stage
, Type
, Value
);
2615 nine_dump_D3DTSS_value(DBG_FF
, Type
, Value
);
2617 user_assert(Stage
< Elements(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2618 user_assert(Type
< Elements(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2620 state
->ff
.tex_stage
[Stage
][Type
] = Value
;
2622 case D3DTSS_BUMPENVMAT00
:
2623 bumpmap_index
= 4 * Stage
;
2625 case D3DTSS_BUMPENVMAT10
:
2626 bumpmap_index
= 4 * Stage
+ 1;
2628 case D3DTSS_BUMPENVMAT01
:
2629 bumpmap_index
= 4 * Stage
+ 2;
2631 case D3DTSS_BUMPENVMAT11
:
2632 bumpmap_index
= 4 * Stage
+ 3;
2634 case D3DTSS_BUMPENVLSCALE
:
2635 bumpmap_index
= 4 * 8 + 2 * Stage
;
2637 case D3DTSS_BUMPENVLOFFSET
:
2638 bumpmap_index
= 4 * 8 + 2 * Stage
+ 1;
2640 case D3DTSS_TEXTURETRANSFORMFLAGS
:
2641 state
->changed
.group
|= NINE_STATE_PS1X_SHADER
;
2647 if (bumpmap_index
>= 0) {
2648 state
->bumpmap_vars
[bumpmap_index
] = Value
;
2649 state
->changed
.group
|= NINE_STATE_PS_CONST
;
2652 state
->changed
.group
|= NINE_STATE_FF_PSSTAGES
;
2653 state
->ff
.changed
.tex_stage
[Stage
][Type
/ 32] |= 1 << (Type
% 32);
2659 NineDevice9_GetSamplerState( struct NineDevice9
*This
,
2661 D3DSAMPLERSTATETYPE Type
,
2664 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2665 Sampler
== D3DDMAPSAMPLER
||
2666 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2667 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2669 if (Sampler
>= D3DDMAPSAMPLER
)
2670 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2672 *pValue
= This
->state
.samp
[Sampler
][Type
];
2677 NineDevice9_SetSamplerState( struct NineDevice9
*This
,
2679 D3DSAMPLERSTATETYPE Type
,
2682 struct nine_state
*state
= This
->update
;
2684 DBG("This=%p Sampler=%u Type=%s Value=%08x\n", This
,
2685 Sampler
, nine_D3DSAMP_to_str(Type
), Value
);
2687 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2688 Sampler
== D3DDMAPSAMPLER
||
2689 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2690 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2692 if (Sampler
>= D3DDMAPSAMPLER
)
2693 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2695 if (state
->samp
[Sampler
][Type
] != Value
|| unlikely(This
->is_recording
)) {
2696 state
->samp
[Sampler
][Type
] = Value
;
2697 state
->changed
.group
|= NINE_STATE_SAMPLER
;
2698 state
->changed
.sampler
[Sampler
] |= 1 << Type
;
2700 if (Type
== D3DSAMP_SRGBTEXTURE
)
2701 state
->changed
.srgb
= TRUE
;
2708 NineDevice9_ValidateDevice( struct NineDevice9
*This
,
2711 const struct nine_state
*state
= &This
->state
;
2713 unsigned w
= 0, h
= 0;
2715 DBG("This=%p pNumPasses=%p\n", This
, pNumPasses
);
2717 for (i
= 0; i
< Elements(state
->samp
); ++i
) {
2718 if (state
->samp
[i
][D3DSAMP_MINFILTER
] == D3DTEXF_NONE
||
2719 state
->samp
[i
][D3DSAMP_MAGFILTER
] == D3DTEXF_NONE
)
2720 return D3DERR_UNSUPPORTEDTEXTUREFILTER
;
2723 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2727 w
= state
->rt
[i
]->desc
.Width
;
2728 h
= state
->rt
[i
]->desc
.Height
;
2730 if (state
->rt
[i
]->desc
.Width
!= w
|| state
->rt
[i
]->desc
.Height
!= h
) {
2731 return D3DERR_CONFLICTINGRENDERSTATE
;
2735 (state
->rs
[D3DRS_ZENABLE
] || state
->rs
[D3DRS_STENCILENABLE
])) {
2737 (state
->ds
->desc
.Width
!= w
|| state
->ds
->desc
.Height
!= h
))
2738 return D3DERR_CONFLICTINGRENDERSTATE
;
2748 NineDevice9_SetPaletteEntries( struct NineDevice9
*This
,
2750 const PALETTEENTRY
*pEntries
)
2752 STUB(D3D_OK
); /* like wine */
2756 NineDevice9_GetPaletteEntries( struct NineDevice9
*This
,
2758 PALETTEENTRY
*pEntries
)
2760 STUB(D3DERR_INVALIDCALL
);
2764 NineDevice9_SetCurrentTexturePalette( struct NineDevice9
*This
,
2765 UINT PaletteNumber
)
2767 STUB(D3D_OK
); /* like wine */
2771 NineDevice9_GetCurrentTexturePalette( struct NineDevice9
*This
,
2772 UINT
*PaletteNumber
)
2774 STUB(D3DERR_INVALIDCALL
);
2778 NineDevice9_SetScissorRect( struct NineDevice9
*This
,
2781 struct nine_state
*state
= This
->update
;
2783 DBG("x=(%u..%u) y=(%u..%u)\n",
2784 pRect
->left
, pRect
->top
, pRect
->right
, pRect
->bottom
);
2786 state
->scissor
.minx
= pRect
->left
;
2787 state
->scissor
.miny
= pRect
->top
;
2788 state
->scissor
.maxx
= pRect
->right
;
2789 state
->scissor
.maxy
= pRect
->bottom
;
2791 state
->changed
.group
|= NINE_STATE_SCISSOR
;
2797 NineDevice9_GetScissorRect( struct NineDevice9
*This
,
2800 pRect
->left
= This
->state
.scissor
.minx
;
2801 pRect
->top
= This
->state
.scissor
.miny
;
2802 pRect
->right
= This
->state
.scissor
.maxx
;
2803 pRect
->bottom
= This
->state
.scissor
.maxy
;
2809 NineDevice9_SetSoftwareVertexProcessing( struct NineDevice9
*This
,
2812 STUB(D3DERR_INVALIDCALL
);
2816 NineDevice9_GetSoftwareVertexProcessing( struct NineDevice9
*This
)
2818 return !!(This
->params
.BehaviorFlags
& D3DCREATE_SOFTWARE_VERTEXPROCESSING
);
2822 NineDevice9_SetNPatchMode( struct NineDevice9
*This
,
2825 STUB(D3DERR_INVALIDCALL
);
2829 NineDevice9_GetNPatchMode( struct NineDevice9
*This
)
2835 init_draw_info(struct pipe_draw_info
*info
,
2836 struct NineDevice9
*dev
, D3DPRIMITIVETYPE type
, UINT count
)
2838 info
->mode
= d3dprimitivetype_to_pipe_prim(type
);
2839 info
->count
= prim_count_to_vertex_count(type
, count
);
2840 info
->start_instance
= 0;
2841 info
->instance_count
= 1;
2842 if (dev
->state
.stream_instancedata_mask
& dev
->state
.stream_usage_mask
)
2843 info
->instance_count
= MAX2(dev
->state
.stream_freq
[0] & 0x7FFFFF, 1);
2844 info
->primitive_restart
= FALSE
;
2845 info
->restart_index
= 0;
2846 info
->count_from_stream_output
= NULL
;
2847 info
->indirect
= NULL
;
2851 NineDevice9_DrawPrimitive( struct NineDevice9
*This
,
2852 D3DPRIMITIVETYPE PrimitiveType
,
2854 UINT PrimitiveCount
)
2856 struct pipe_draw_info info
;
2858 DBG("iface %p, PrimitiveType %u, StartVertex %u, PrimitiveCount %u\n",
2859 This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2861 nine_update_state(This
);
2863 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2864 info
.indexed
= FALSE
;
2865 info
.start
= StartVertex
;
2866 info
.index_bias
= 0;
2867 info
.min_index
= info
.start
;
2868 info
.max_index
= info
.count
- 1;
2870 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2876 NineDevice9_DrawIndexedPrimitive( struct NineDevice9
*This
,
2877 D3DPRIMITIVETYPE PrimitiveType
,
2878 INT BaseVertexIndex
,
2879 UINT MinVertexIndex
,
2882 UINT PrimitiveCount
)
2884 struct pipe_draw_info info
;
2886 DBG("iface %p, PrimitiveType %u, BaseVertexIndex %u, MinVertexIndex %u "
2887 "NumVertices %u, StartIndex %u, PrimitiveCount %u\n",
2888 This
, PrimitiveType
, BaseVertexIndex
, MinVertexIndex
, NumVertices
,
2889 StartIndex
, PrimitiveCount
);
2891 user_assert(This
->state
.idxbuf
, D3DERR_INVALIDCALL
);
2892 user_assert(This
->state
.vdecl
, D3DERR_INVALIDCALL
);
2894 nine_update_state(This
);
2896 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2897 info
.indexed
= TRUE
;
2898 info
.start
= StartIndex
;
2899 info
.index_bias
= BaseVertexIndex
;
2900 /* These don't include index bias: */
2901 info
.min_index
= MinVertexIndex
;
2902 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
2904 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2910 NineDevice9_DrawPrimitiveUP( struct NineDevice9
*This
,
2911 D3DPRIMITIVETYPE PrimitiveType
,
2912 UINT PrimitiveCount
,
2913 const void *pVertexStreamZeroData
,
2914 UINT VertexStreamZeroStride
)
2916 struct pipe_vertex_buffer vtxbuf
;
2917 struct pipe_draw_info info
;
2919 DBG("iface %p, PrimitiveType %u, PrimitiveCount %u, data %p, stride %u\n",
2920 This
, PrimitiveType
, PrimitiveCount
,
2921 pVertexStreamZeroData
, VertexStreamZeroStride
);
2923 user_assert(pVertexStreamZeroData
&& VertexStreamZeroStride
,
2924 D3DERR_INVALIDCALL
);
2926 nine_update_state(This
);
2928 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2929 info
.indexed
= FALSE
;
2931 info
.index_bias
= 0;
2933 info
.max_index
= info
.count
- 1;
2935 vtxbuf
.stride
= VertexStreamZeroStride
;
2936 vtxbuf
.buffer_offset
= 0;
2937 vtxbuf
.buffer
= NULL
;
2938 vtxbuf
.user_buffer
= pVertexStreamZeroData
;
2940 if (!This
->driver_caps
.user_vbufs
) {
2941 u_upload_data(This
->vertex_uploader
,
2943 (info
.max_index
+ 1) * VertexStreamZeroStride
, /* XXX */
2945 &vtxbuf
.buffer_offset
,
2947 u_upload_unmap(This
->vertex_uploader
);
2948 vtxbuf
.user_buffer
= NULL
;
2951 This
->pipe
->set_vertex_buffers(This
->pipe
, 0, 1, &vtxbuf
);
2953 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2955 NineDevice9_PauseRecording(This
);
2956 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
2957 NineDevice9_ResumeRecording(This
);
2959 pipe_resource_reference(&vtxbuf
.buffer
, NULL
);
2965 NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9
*This
,
2966 D3DPRIMITIVETYPE PrimitiveType
,
2967 UINT MinVertexIndex
,
2969 UINT PrimitiveCount
,
2970 const void *pIndexData
,
2971 D3DFORMAT IndexDataFormat
,
2972 const void *pVertexStreamZeroData
,
2973 UINT VertexStreamZeroStride
)
2975 struct pipe_draw_info info
;
2976 struct pipe_vertex_buffer vbuf
;
2977 struct pipe_index_buffer ibuf
;
2979 DBG("iface %p, PrimitiveType %u, MinVertexIndex %u, NumVertices %u "
2980 "PrimitiveCount %u, pIndexData %p, IndexDataFormat %u "
2981 "pVertexStreamZeroData %p, VertexStreamZeroStride %u\n",
2982 This
, PrimitiveType
, MinVertexIndex
, NumVertices
, PrimitiveCount
,
2983 pIndexData
, IndexDataFormat
,
2984 pVertexStreamZeroData
, VertexStreamZeroStride
);
2986 user_assert(pIndexData
&& pVertexStreamZeroData
, D3DERR_INVALIDCALL
);
2987 user_assert(VertexStreamZeroStride
, D3DERR_INVALIDCALL
);
2988 user_assert(IndexDataFormat
== D3DFMT_INDEX16
||
2989 IndexDataFormat
== D3DFMT_INDEX32
, D3DERR_INVALIDCALL
);
2991 nine_update_state(This
);
2993 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2994 info
.indexed
= TRUE
;
2996 info
.index_bias
= 0;
2997 info
.min_index
= MinVertexIndex
;
2998 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
3000 vbuf
.stride
= VertexStreamZeroStride
;
3001 vbuf
.buffer_offset
= 0;
3003 vbuf
.user_buffer
= pVertexStreamZeroData
;
3005 ibuf
.index_size
= (IndexDataFormat
== D3DFMT_INDEX16
) ? 2 : 4;
3008 ibuf
.user_buffer
= pIndexData
;
3010 if (!This
->driver_caps
.user_vbufs
) {
3011 const unsigned base
= info
.min_index
* VertexStreamZeroStride
;
3012 u_upload_data(This
->vertex_uploader
,
3015 info
.min_index
+ 1) * VertexStreamZeroStride
, /* XXX */
3016 (const uint8_t *)vbuf
.user_buffer
+ base
,
3017 &vbuf
.buffer_offset
,
3019 u_upload_unmap(This
->vertex_uploader
);
3020 /* Won't be used: */
3021 vbuf
.buffer_offset
-= base
;
3022 vbuf
.user_buffer
= NULL
;
3024 if (!This
->driver_caps
.user_ibufs
) {
3025 u_upload_data(This
->index_uploader
,
3027 info
.count
* ibuf
.index_size
,
3031 u_upload_unmap(This
->index_uploader
);
3032 ibuf
.user_buffer
= NULL
;
3035 This
->pipe
->set_vertex_buffers(This
->pipe
, 0, 1, &vbuf
);
3036 This
->pipe
->set_index_buffer(This
->pipe
, &ibuf
);
3038 This
->pipe
->draw_vbo(This
->pipe
, &info
);
3040 pipe_resource_reference(&vbuf
.buffer
, NULL
);
3041 pipe_resource_reference(&ibuf
.buffer
, NULL
);
3043 NineDevice9_PauseRecording(This
);
3044 NineDevice9_SetIndices(This
, NULL
);
3045 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
3046 NineDevice9_ResumeRecording(This
);
3051 /* TODO: Write to pDestBuffer directly if vertex declaration contains
3055 NineDevice9_ProcessVertices( struct NineDevice9
*This
,
3059 IDirect3DVertexBuffer9
*pDestBuffer
,
3060 IDirect3DVertexDeclaration9
*pVertexDecl
,
3063 struct pipe_screen
*screen
= This
->screen
;
3064 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pVertexDecl
);
3065 struct NineVertexShader9
*vs
;
3066 struct pipe_resource
*resource
;
3067 struct pipe_stream_output_target
*target
;
3068 struct pipe_draw_info draw
;
3070 unsigned buffer_offset
, buffer_size
;
3072 DBG("This=%p SrcStartIndex=%u DestIndex=%u VertexCount=%u "
3073 "pDestBuffer=%p pVertexDecl=%p Flags=%d\n",
3074 This
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
,
3075 pVertexDecl
, Flags
);
3077 if (!screen
->get_param(screen
, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
))
3078 STUB(D3DERR_INVALIDCALL
);
3080 nine_update_state(This
);
3082 /* TODO: Create shader with stream output. */
3083 STUB(D3DERR_INVALIDCALL
);
3084 struct NineVertexBuffer9
*dst
= NineVertexBuffer9(pDestBuffer
);
3086 vs
= This
->state
.vs
? This
->state
.vs
: This
->ff
.vs
;
3088 buffer_size
= VertexCount
* vs
->so
->stride
[0];
3090 struct pipe_resource templ
;
3092 templ
.target
= PIPE_BUFFER
;
3093 templ
.format
= PIPE_FORMAT_R8_UNORM
;
3094 templ
.width0
= buffer_size
;
3096 templ
.bind
= PIPE_BIND_STREAM_OUTPUT
;
3097 templ
.usage
= PIPE_USAGE_STREAM
;
3098 templ
.height0
= templ
.depth0
= templ
.array_size
= 1;
3099 templ
.last_level
= templ
.nr_samples
= 0;
3101 resource
= This
->screen
->resource_create(This
->screen
, &templ
);
3103 return E_OUTOFMEMORY
;
3106 /* SO matches vertex declaration */
3107 resource
= dst
->base
.resource
;
3108 buffer_offset
= DestIndex
* vs
->so
->stride
[0];
3110 target
= This
->pipe
->create_stream_output_target(This
->pipe
, resource
,
3114 pipe_resource_reference(&resource
, NULL
);
3115 return D3DERR_DRIVERINTERNALERROR
;
3119 hr
= NineVertexDeclaration9_new_from_fvf(This
, dst
->desc
.FVF
, &vdecl
);
3124 init_draw_info(&draw
, This
, D3DPT_POINTLIST
, VertexCount
);
3125 draw
.instance_count
= 1;
3126 draw
.indexed
= FALSE
;
3127 draw
.start
= SrcStartIndex
;
3128 draw
.index_bias
= 0;
3129 draw
.min_index
= SrcStartIndex
;
3130 draw
.max_index
= SrcStartIndex
+ VertexCount
- 1;
3132 This
->pipe
->set_stream_output_targets(This
->pipe
, 1, &target
, 0);
3133 This
->pipe
->draw_vbo(This
->pipe
, &draw
);
3134 This
->pipe
->set_stream_output_targets(This
->pipe
, 0, NULL
, 0);
3135 This
->pipe
->stream_output_target_destroy(This
->pipe
, target
);
3137 hr
= NineVertexDeclaration9_ConvertStreamOutput(vdecl
,
3138 dst
, DestIndex
, VertexCount
,
3141 pipe_resource_reference(&resource
, NULL
);
3143 NineUnknown_Release(NineUnknown(vdecl
));
3148 NineDevice9_CreateVertexDeclaration( struct NineDevice9
*This
,
3149 const D3DVERTEXELEMENT9
*pVertexElements
,
3150 IDirect3DVertexDeclaration9
**ppDecl
)
3152 struct NineVertexDeclaration9
*vdecl
;
3154 DBG("This=%p pVertexElements=%p ppDecl=%p\n",
3155 This
, pVertexElements
, ppDecl
);
3157 HRESULT hr
= NineVertexDeclaration9_new(This
, pVertexElements
, &vdecl
);
3159 *ppDecl
= (IDirect3DVertexDeclaration9
*)vdecl
;
3165 NineDevice9_SetVertexDeclaration( struct NineDevice9
*This
,
3166 IDirect3DVertexDeclaration9
*pDecl
)
3168 struct nine_state
*state
= This
->update
;
3170 DBG("This=%p pDecl=%p\n", This
, pDecl
);
3172 if (likely(!This
->is_recording
) && state
->vdecl
== NineVertexDeclaration9(pDecl
))
3174 nine_bind(&state
->vdecl
, pDecl
);
3176 state
->changed
.group
|= NINE_STATE_VDECL
;
3182 NineDevice9_GetVertexDeclaration( struct NineDevice9
*This
,
3183 IDirect3DVertexDeclaration9
**ppDecl
)
3185 user_assert(ppDecl
, D3DERR_INVALIDCALL
);
3187 *ppDecl
= (IDirect3DVertexDeclaration9
*)This
->state
.vdecl
;
3189 NineUnknown_AddRef(NineUnknown(*ppDecl
));
3194 NineDevice9_SetFVF( struct NineDevice9
*This
,
3197 struct NineVertexDeclaration9
*vdecl
;
3200 DBG("FVF = %08x\n", FVF
);
3202 return D3D_OK
; /* like wine */
3204 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
3206 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
3210 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
3211 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
3213 return NineDevice9_SetVertexDeclaration(
3214 This
, (IDirect3DVertexDeclaration9
*)vdecl
);
3218 NineDevice9_GetFVF( struct NineDevice9
*This
,
3221 *pFVF
= This
->state
.vdecl
? This
->state
.vdecl
->fvf
: 0;
3226 NineDevice9_CreateVertexShader( struct NineDevice9
*This
,
3227 const DWORD
*pFunction
,
3228 IDirect3DVertexShader9
**ppShader
)
3230 struct NineVertexShader9
*vs
;
3233 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3235 hr
= NineVertexShader9_new(This
, &vs
, pFunction
, NULL
);
3238 *ppShader
= (IDirect3DVertexShader9
*)vs
;
3243 NineDevice9_SetVertexShader( struct NineDevice9
*This
,
3244 IDirect3DVertexShader9
*pShader
)
3246 struct nine_state
*state
= This
->update
;
3248 DBG("This=%p pShader=%p\n", This
, pShader
);
3250 /* ff -> non-ff: commit back non-ff constants */
3251 if (!state
->vs
&& pShader
)
3252 state
->commit
|= NINE_STATE_COMMIT_CONST_VS
;
3254 nine_bind(&state
->vs
, pShader
);
3256 state
->changed
.group
|= NINE_STATE_VS
;
3262 NineDevice9_GetVertexShader( struct NineDevice9
*This
,
3263 IDirect3DVertexShader9
**ppShader
)
3265 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3266 nine_reference_set(ppShader
, This
->state
.vs
);
3271 NineDevice9_SetVertexShaderConstantF( struct NineDevice9
*This
,
3273 const float *pConstantData
,
3274 UINT Vector4fCount
)
3276 struct nine_state
*state
= This
->update
;
3278 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3279 This
, StartRegister
, pConstantData
, Vector4fCount
);
3281 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3282 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3286 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3288 memcpy(&state
->vs_const_f
[StartRegister
* 4],
3290 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3292 nine_ranges_insert(&state
->changed
.vs_const_f
,
3293 StartRegister
, StartRegister
+ Vector4fCount
,
3296 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3302 NineDevice9_GetVertexShaderConstantF( struct NineDevice9
*This
,
3304 float *pConstantData
,
3305 UINT Vector4fCount
)
3307 const struct nine_state
*state
= &This
->state
;
3309 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3310 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3311 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3313 memcpy(pConstantData
,
3314 &state
->vs_const_f
[StartRegister
* 4],
3315 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3321 NineDevice9_SetVertexShaderConstantI( struct NineDevice9
*This
,
3323 const int *pConstantData
,
3324 UINT Vector4iCount
)
3326 struct nine_state
*state
= This
->update
;
3329 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3330 This
, StartRegister
, pConstantData
, Vector4iCount
);
3332 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3333 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3334 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3336 if (This
->driver_caps
.vs_integer
) {
3337 memcpy(&state
->vs_const_i
[StartRegister
][0],
3339 Vector4iCount
* sizeof(state
->vs_const_i
[0]));
3341 for (i
= 0; i
< Vector4iCount
; i
++) {
3342 state
->vs_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3343 state
->vs_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3344 state
->vs_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3345 state
->vs_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3349 state
->changed
.vs_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3350 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3356 NineDevice9_GetVertexShaderConstantI( struct NineDevice9
*This
,
3359 UINT Vector4iCount
)
3361 const struct nine_state
*state
= &This
->state
;
3364 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3365 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3366 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3368 if (This
->driver_caps
.vs_integer
) {
3369 memcpy(pConstantData
,
3370 &state
->vs_const_i
[StartRegister
][0],
3371 Vector4iCount
* sizeof(state
->vs_const_i
[0]));
3373 for (i
= 0; i
< Vector4iCount
; i
++) {
3374 pConstantData
[4*i
] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][0]);
3375 pConstantData
[4*i
+1] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][1]);
3376 pConstantData
[4*i
+2] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][2]);
3377 pConstantData
[4*i
+3] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][3]);
3385 NineDevice9_SetVertexShaderConstantB( struct NineDevice9
*This
,
3387 const BOOL
*pConstantData
,
3390 struct nine_state
*state
= This
->update
;
3392 uint32_t bool_true
= This
->driver_caps
.vs_integer
? 0xFFFFFFFF : fui(1.0f
);
3394 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3395 This
, StartRegister
, pConstantData
, BoolCount
);
3397 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3398 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3399 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3401 for (i
= 0; i
< BoolCount
; i
++)
3402 state
->vs_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3404 state
->changed
.vs_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3405 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3411 NineDevice9_GetVertexShaderConstantB( struct NineDevice9
*This
,
3413 BOOL
*pConstantData
,
3416 const struct nine_state
*state
= &This
->state
;
3419 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3420 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3421 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3423 for (i
= 0; i
< BoolCount
; i
++)
3424 pConstantData
[i
] = state
->vs_const_b
[StartRegister
+ i
] != 0 ? TRUE
: FALSE
;
3430 NineDevice9_SetStreamSource( struct NineDevice9
*This
,
3432 IDirect3DVertexBuffer9
*pStreamData
,
3436 struct nine_state
*state
= This
->update
;
3437 struct NineVertexBuffer9
*pVBuf9
= NineVertexBuffer9(pStreamData
);
3438 const unsigned i
= StreamNumber
;
3440 DBG("This=%p StreamNumber=%u pStreamData=%p OffsetInBytes=%u Stride=%u\n",
3441 This
, StreamNumber
, pStreamData
, OffsetInBytes
, Stride
);
3443 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3444 user_assert(Stride
<= This
->caps
.MaxStreamStride
, D3DERR_INVALIDCALL
);
3446 if (likely(!This
->is_recording
)) {
3447 if (state
->stream
[i
] == NineVertexBuffer9(pStreamData
) &&
3448 state
->vtxbuf
[i
].stride
== Stride
&&
3449 state
->vtxbuf
[i
].buffer_offset
== OffsetInBytes
)
3452 nine_bind(&state
->stream
[i
], pStreamData
);
3454 state
->changed
.vtxbuf
|= 1 << StreamNumber
;
3457 state
->vtxbuf
[i
].stride
= Stride
;
3458 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3460 state
->vtxbuf
[i
].buffer
= pStreamData
? pVBuf9
->base
.resource
: NULL
;
3466 NineDevice9_GetStreamSource( struct NineDevice9
*This
,
3468 IDirect3DVertexBuffer9
**ppStreamData
,
3469 UINT
*pOffsetInBytes
,
3472 const struct nine_state
*state
= &This
->state
;
3473 const unsigned i
= StreamNumber
;
3475 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3476 user_assert(ppStreamData
, D3DERR_INVALIDCALL
);
3478 nine_reference_set(ppStreamData
, state
->stream
[i
]);
3479 *pStride
= state
->vtxbuf
[i
].stride
;
3480 *pOffsetInBytes
= state
->vtxbuf
[i
].buffer_offset
;
3486 NineDevice9_SetStreamSourceFreq( struct NineDevice9
*This
,
3490 struct nine_state
*state
= This
->update
;
3491 /* const UINT freq = Setting & 0x7FFFFF; */
3493 DBG("This=%p StreamNumber=%u FrequencyParameter=0x%x\n", This
,
3494 StreamNumber
, Setting
);
3496 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3497 user_assert(StreamNumber
!= 0 || !(Setting
& D3DSTREAMSOURCE_INSTANCEDATA
),
3498 D3DERR_INVALIDCALL
);
3499 user_assert(!((Setting
& D3DSTREAMSOURCE_INSTANCEDATA
) &&
3500 (Setting
& D3DSTREAMSOURCE_INDEXEDDATA
)), D3DERR_INVALIDCALL
);
3501 user_assert(Setting
, D3DERR_INVALIDCALL
);
3503 state
->stream_freq
[StreamNumber
] = Setting
;
3505 if (Setting
& D3DSTREAMSOURCE_INSTANCEDATA
)
3506 state
->stream_instancedata_mask
|= 1 << StreamNumber
;
3508 state
->stream_instancedata_mask
&= ~(1 << StreamNumber
);
3510 state
->changed
.stream_freq
|= 1 << StreamNumber
;
3515 NineDevice9_GetStreamSourceFreq( struct NineDevice9
*This
,
3519 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3520 *pSetting
= This
->state
.stream_freq
[StreamNumber
];
3525 NineDevice9_SetIndices( struct NineDevice9
*This
,
3526 IDirect3DIndexBuffer9
*pIndexData
)
3528 struct nine_state
*state
= This
->update
;
3530 DBG("This=%p pIndexData=%p\n", This
, pIndexData
);
3532 if (likely(!This
->is_recording
))
3533 if (state
->idxbuf
== NineIndexBuffer9(pIndexData
))
3535 nine_bind(&state
->idxbuf
, pIndexData
);
3537 state
->changed
.group
|= NINE_STATE_IDXBUF
;
3542 /* XXX: wine/d3d9 doesn't have pBaseVertexIndex, and it doesn't make sense
3543 * here because it's an argument passed to the Draw calls.
3546 NineDevice9_GetIndices( struct NineDevice9
*This
,
3547 IDirect3DIndexBuffer9
**ppIndexData
/*,
3548 UINT *pBaseVertexIndex */ )
3550 user_assert(ppIndexData
, D3DERR_INVALIDCALL
);
3551 nine_reference_set(ppIndexData
, This
->state
.idxbuf
);
3556 NineDevice9_CreatePixelShader( struct NineDevice9
*This
,
3557 const DWORD
*pFunction
,
3558 IDirect3DPixelShader9
**ppShader
)
3560 struct NinePixelShader9
*ps
;
3563 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3565 hr
= NinePixelShader9_new(This
, &ps
, pFunction
, NULL
);
3568 *ppShader
= (IDirect3DPixelShader9
*)ps
;
3573 NineDevice9_SetPixelShader( struct NineDevice9
*This
,
3574 IDirect3DPixelShader9
*pShader
)
3576 struct nine_state
*state
= This
->update
;
3577 unsigned old_mask
= state
->ps
? state
->ps
->rt_mask
: 1;
3580 DBG("This=%p pShader=%p\n", This
, pShader
);
3582 /* ff -> non-ff: commit back non-ff constants */
3583 if (!state
->ps
&& pShader
)
3584 state
->commit
|= NINE_STATE_COMMIT_CONST_PS
;
3586 nine_bind(&state
->ps
, pShader
);
3588 state
->changed
.group
|= NINE_STATE_PS
;
3590 mask
= state
->ps
? state
->ps
->rt_mask
: 1;
3591 /* We need to update cbufs if the pixel shader would
3592 * write to different render targets */
3593 if (mask
!= old_mask
)
3594 state
->changed
.group
|= NINE_STATE_FB
;
3600 NineDevice9_GetPixelShader( struct NineDevice9
*This
,
3601 IDirect3DPixelShader9
**ppShader
)
3603 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3604 nine_reference_set(ppShader
, This
->state
.ps
);
3609 NineDevice9_SetPixelShaderConstantF( struct NineDevice9
*This
,
3611 const float *pConstantData
,
3612 UINT Vector4fCount
)
3614 struct nine_state
*state
= This
->update
;
3616 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3617 This
, StartRegister
, pConstantData
, Vector4fCount
);
3619 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3620 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3624 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3626 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3628 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3630 nine_ranges_insert(&state
->changed
.ps_const_f
,
3631 StartRegister
, StartRegister
+ Vector4fCount
,
3634 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3640 NineDevice9_GetPixelShaderConstantF( struct NineDevice9
*This
,
3642 float *pConstantData
,
3643 UINT Vector4fCount
)
3645 const struct nine_state
*state
= &This
->state
;
3647 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3648 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3649 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3651 memcpy(pConstantData
,
3652 &state
->ps_const_f
[StartRegister
* 4],
3653 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3659 NineDevice9_SetPixelShaderConstantI( struct NineDevice9
*This
,
3661 const int *pConstantData
,
3662 UINT Vector4iCount
)
3664 struct nine_state
*state
= This
->update
;
3667 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3668 This
, StartRegister
, pConstantData
, Vector4iCount
);
3670 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3671 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3672 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3674 if (This
->driver_caps
.ps_integer
) {
3675 memcpy(&state
->ps_const_i
[StartRegister
][0],
3677 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3679 for (i
= 0; i
< Vector4iCount
; i
++) {
3680 state
->ps_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3681 state
->ps_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3682 state
->ps_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3683 state
->ps_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3686 state
->changed
.ps_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3687 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3693 NineDevice9_GetPixelShaderConstantI( struct NineDevice9
*This
,
3696 UINT Vector4iCount
)
3698 const struct nine_state
*state
= &This
->state
;
3701 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3702 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3703 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3705 if (This
->driver_caps
.ps_integer
) {
3706 memcpy(pConstantData
,
3707 &state
->ps_const_i
[StartRegister
][0],
3708 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3710 for (i
= 0; i
< Vector4iCount
; i
++) {
3711 pConstantData
[4*i
] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][0]);
3712 pConstantData
[4*i
+1] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][1]);
3713 pConstantData
[4*i
+2] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][2]);
3714 pConstantData
[4*i
+3] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][3]);
3722 NineDevice9_SetPixelShaderConstantB( struct NineDevice9
*This
,
3724 const BOOL
*pConstantData
,
3727 struct nine_state
*state
= This
->update
;
3729 uint32_t bool_true
= This
->driver_caps
.ps_integer
? 0xFFFFFFFF : fui(1.0f
);
3731 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3732 This
, StartRegister
, pConstantData
, BoolCount
);
3734 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3735 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3736 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3738 for (i
= 0; i
< BoolCount
; i
++)
3739 state
->ps_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3741 state
->changed
.ps_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3742 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3748 NineDevice9_GetPixelShaderConstantB( struct NineDevice9
*This
,
3750 BOOL
*pConstantData
,
3753 const struct nine_state
*state
= &This
->state
;
3756 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3757 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3758 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3760 for (i
= 0; i
< BoolCount
; i
++)
3761 pConstantData
[i
] = state
->ps_const_b
[StartRegister
+ i
] ? TRUE
: FALSE
;
3767 NineDevice9_DrawRectPatch( struct NineDevice9
*This
,
3769 const float *pNumSegs
,
3770 const D3DRECTPATCH_INFO
*pRectPatchInfo
)
3772 STUB(D3DERR_INVALIDCALL
);
3776 NineDevice9_DrawTriPatch( struct NineDevice9
*This
,
3778 const float *pNumSegs
,
3779 const D3DTRIPATCH_INFO
*pTriPatchInfo
)
3781 STUB(D3DERR_INVALIDCALL
);
3785 NineDevice9_DeletePatch( struct NineDevice9
*This
,
3788 STUB(D3DERR_INVALIDCALL
);
3792 NineDevice9_CreateQuery( struct NineDevice9
*This
,
3794 IDirect3DQuery9
**ppQuery
)
3796 struct NineQuery9
*query
;
3799 DBG("This=%p Type=%d ppQuery=%p\n", This
, Type
, ppQuery
);
3801 hr
= nine_is_query_supported(This
->screen
, Type
);
3802 if (!ppQuery
|| hr
!= D3D_OK
)
3805 hr
= NineQuery9_new(This
, &query
, Type
);
3808 *ppQuery
= (IDirect3DQuery9
*)query
;
3812 IDirect3DDevice9Vtbl NineDevice9_vtable
= {
3813 (void *)NineUnknown_QueryInterface
,
3814 (void *)NineUnknown_AddRef
,
3815 (void *)NineUnknown_Release
,
3816 (void *)NineDevice9_TestCooperativeLevel
,
3817 (void *)NineDevice9_GetAvailableTextureMem
,
3818 (void *)NineDevice9_EvictManagedResources
,
3819 (void *)NineDevice9_GetDirect3D
,
3820 (void *)NineDevice9_GetDeviceCaps
,
3821 (void *)NineDevice9_GetDisplayMode
,
3822 (void *)NineDevice9_GetCreationParameters
,
3823 (void *)NineDevice9_SetCursorProperties
,
3824 (void *)NineDevice9_SetCursorPosition
,
3825 (void *)NineDevice9_ShowCursor
,
3826 (void *)NineDevice9_CreateAdditionalSwapChain
,
3827 (void *)NineDevice9_GetSwapChain
,
3828 (void *)NineDevice9_GetNumberOfSwapChains
,
3829 (void *)NineDevice9_Reset
,
3830 (void *)NineDevice9_Present
,
3831 (void *)NineDevice9_GetBackBuffer
,
3832 (void *)NineDevice9_GetRasterStatus
,
3833 (void *)NineDevice9_SetDialogBoxMode
,
3834 (void *)NineDevice9_SetGammaRamp
,
3835 (void *)NineDevice9_GetGammaRamp
,
3836 (void *)NineDevice9_CreateTexture
,
3837 (void *)NineDevice9_CreateVolumeTexture
,
3838 (void *)NineDevice9_CreateCubeTexture
,
3839 (void *)NineDevice9_CreateVertexBuffer
,
3840 (void *)NineDevice9_CreateIndexBuffer
,
3841 (void *)NineDevice9_CreateRenderTarget
,
3842 (void *)NineDevice9_CreateDepthStencilSurface
,
3843 (void *)NineDevice9_UpdateSurface
,
3844 (void *)NineDevice9_UpdateTexture
,
3845 (void *)NineDevice9_GetRenderTargetData
,
3846 (void *)NineDevice9_GetFrontBufferData
,
3847 (void *)NineDevice9_StretchRect
,
3848 (void *)NineDevice9_ColorFill
,
3849 (void *)NineDevice9_CreateOffscreenPlainSurface
,
3850 (void *)NineDevice9_SetRenderTarget
,
3851 (void *)NineDevice9_GetRenderTarget
,
3852 (void *)NineDevice9_SetDepthStencilSurface
,
3853 (void *)NineDevice9_GetDepthStencilSurface
,
3854 (void *)NineDevice9_BeginScene
,
3855 (void *)NineDevice9_EndScene
,
3856 (void *)NineDevice9_Clear
,
3857 (void *)NineDevice9_SetTransform
,
3858 (void *)NineDevice9_GetTransform
,
3859 (void *)NineDevice9_MultiplyTransform
,
3860 (void *)NineDevice9_SetViewport
,
3861 (void *)NineDevice9_GetViewport
,
3862 (void *)NineDevice9_SetMaterial
,
3863 (void *)NineDevice9_GetMaterial
,
3864 (void *)NineDevice9_SetLight
,
3865 (void *)NineDevice9_GetLight
,
3866 (void *)NineDevice9_LightEnable
,
3867 (void *)NineDevice9_GetLightEnable
,
3868 (void *)NineDevice9_SetClipPlane
,
3869 (void *)NineDevice9_GetClipPlane
,
3870 (void *)NineDevice9_SetRenderState
,
3871 (void *)NineDevice9_GetRenderState
,
3872 (void *)NineDevice9_CreateStateBlock
,
3873 (void *)NineDevice9_BeginStateBlock
,
3874 (void *)NineDevice9_EndStateBlock
,
3875 (void *)NineDevice9_SetClipStatus
,
3876 (void *)NineDevice9_GetClipStatus
,
3877 (void *)NineDevice9_GetTexture
,
3878 (void *)NineDevice9_SetTexture
,
3879 (void *)NineDevice9_GetTextureStageState
,
3880 (void *)NineDevice9_SetTextureStageState
,
3881 (void *)NineDevice9_GetSamplerState
,
3882 (void *)NineDevice9_SetSamplerState
,
3883 (void *)NineDevice9_ValidateDevice
,
3884 (void *)NineDevice9_SetPaletteEntries
,
3885 (void *)NineDevice9_GetPaletteEntries
,
3886 (void *)NineDevice9_SetCurrentTexturePalette
,
3887 (void *)NineDevice9_GetCurrentTexturePalette
,
3888 (void *)NineDevice9_SetScissorRect
,
3889 (void *)NineDevice9_GetScissorRect
,
3890 (void *)NineDevice9_SetSoftwareVertexProcessing
,
3891 (void *)NineDevice9_GetSoftwareVertexProcessing
,
3892 (void *)NineDevice9_SetNPatchMode
,
3893 (void *)NineDevice9_GetNPatchMode
,
3894 (void *)NineDevice9_DrawPrimitive
,
3895 (void *)NineDevice9_DrawIndexedPrimitive
,
3896 (void *)NineDevice9_DrawPrimitiveUP
,
3897 (void *)NineDevice9_DrawIndexedPrimitiveUP
,
3898 (void *)NineDevice9_ProcessVertices
,
3899 (void *)NineDevice9_CreateVertexDeclaration
,
3900 (void *)NineDevice9_SetVertexDeclaration
,
3901 (void *)NineDevice9_GetVertexDeclaration
,
3902 (void *)NineDevice9_SetFVF
,
3903 (void *)NineDevice9_GetFVF
,
3904 (void *)NineDevice9_CreateVertexShader
,
3905 (void *)NineDevice9_SetVertexShader
,
3906 (void *)NineDevice9_GetVertexShader
,
3907 (void *)NineDevice9_SetVertexShaderConstantF
,
3908 (void *)NineDevice9_GetVertexShaderConstantF
,
3909 (void *)NineDevice9_SetVertexShaderConstantI
,
3910 (void *)NineDevice9_GetVertexShaderConstantI
,
3911 (void *)NineDevice9_SetVertexShaderConstantB
,
3912 (void *)NineDevice9_GetVertexShaderConstantB
,
3913 (void *)NineDevice9_SetStreamSource
,
3914 (void *)NineDevice9_GetStreamSource
,
3915 (void *)NineDevice9_SetStreamSourceFreq
,
3916 (void *)NineDevice9_GetStreamSourceFreq
,
3917 (void *)NineDevice9_SetIndices
,
3918 (void *)NineDevice9_GetIndices
,
3919 (void *)NineDevice9_CreatePixelShader
,
3920 (void *)NineDevice9_SetPixelShader
,
3921 (void *)NineDevice9_GetPixelShader
,
3922 (void *)NineDevice9_SetPixelShaderConstantF
,
3923 (void *)NineDevice9_GetPixelShaderConstantF
,
3924 (void *)NineDevice9_SetPixelShaderConstantI
,
3925 (void *)NineDevice9_GetPixelShaderConstantI
,
3926 (void *)NineDevice9_SetPixelShaderConstantB
,
3927 (void *)NineDevice9_GetPixelShaderConstantB
,
3928 (void *)NineDevice9_DrawRectPatch
,
3929 (void *)NineDevice9_DrawTriPatch
,
3930 (void *)NineDevice9_DeletePatch
,
3931 (void *)NineDevice9_CreateQuery
3934 static const GUID
*NineDevice9_IIDs
[] = {
3935 &IID_IDirect3DDevice9
,
3941 NineDevice9_new( struct pipe_screen
*pScreen
,
3942 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
3944 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
3946 ID3DPresentGroup
*pPresentationGroup
,
3947 struct d3dadapter9_context
*pCTX
,
3949 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
3950 struct NineDevice9
**ppOut
)
3953 lock
= !!(pCreationParameters
->BehaviorFlags
& D3DCREATE_MULTITHREADED
);
3955 NINE_NEW(Device9
, ppOut
, lock
, /* args */
3956 pScreen
, pCreationParameters
, pCaps
,
3957 pPresentationParameters
, pD3D9
, pPresentationGroup
, pCTX
,
3958 ex
, pFullscreenDisplayMode
);