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_buffer_upload.h"
38 #include "nine_helpers.h"
39 #include "nine_pipe.h"
41 #include "nine_dump.h"
42 #include "nine_limits.h"
44 #include "pipe/p_screen.h"
45 #include "pipe/p_context.h"
46 #include "pipe/p_config.h"
47 #include "util/u_math.h"
48 #include "util/u_inlines.h"
49 #include "util/u_hash_table.h"
50 #include "util/u_format.h"
51 #include "util/u_surface.h"
52 #include "util/u_upload_mgr.h"
53 #include "hud/hud_context.h"
55 #include "cso_cache/cso_context.h"
57 #define DBG_CHANNEL DBG_DEVICE
59 #if defined(PIPE_CC_GCC) && (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64))
61 static void nine_setup_fpu()
65 __asm__
__volatile__ ("fnstcw %0" : "=m" (*&c
));
67 /* clear the control word */
69 /* d3d9 doc/wine tests: mask all exceptions, use single-precision
70 * and round to nearest */
73 __asm__
__volatile__ ("fldcw %0" : : "m" (*&c
));
78 static void nine_setup_fpu(void)
80 WARN_ONCE("FPU setup not supported on non-x86 platforms\n");
86 NineDevice9_SetDefaultState( struct NineDevice9
*This
, boolean is_reset
)
88 struct NineSurface9
*refSurf
= NULL
;
90 DBG("This=%p is_reset=%d\n", This
, (int) is_reset
);
92 assert(!This
->is_recording
);
94 nine_state_set_defaults(This
, &This
->caps
, is_reset
);
96 refSurf
= This
->swapchains
[0]->buffers
[0];
99 This
->state
.viewport
.X
= 0;
100 This
->state
.viewport
.Y
= 0;
101 This
->state
.viewport
.Width
= refSurf
->desc
.Width
;
102 This
->state
.viewport
.Height
= refSurf
->desc
.Height
;
104 nine_context_set_viewport(This
, &This
->state
.viewport
);
106 This
->state
.scissor
.minx
= 0;
107 This
->state
.scissor
.miny
= 0;
108 This
->state
.scissor
.maxx
= refSurf
->desc
.Width
;
109 This
->state
.scissor
.maxy
= refSurf
->desc
.Height
;
111 nine_context_set_scissor(This
, &This
->state
.scissor
);
113 if (This
->nswapchains
&& This
->swapchains
[0]->params
.EnableAutoDepthStencil
) {
114 nine_context_set_render_state(This
, D3DRS_ZENABLE
, TRUE
);
115 This
->state
.rs_advertised
[D3DRS_ZENABLE
] = TRUE
;
117 if (This
->state
.rs_advertised
[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
,
135 int minorVersionNum
)
138 HRESULT hr
= NineUnknown_ctor(&This
->base
, pParams
);
140 DBG("This=%p pParams=%p pScreen=%p pCreationParameters=%p pCaps=%p pPresentationParameters=%p "
141 "pD3D9=%p pPresentationGroup=%p pCTX=%p ex=%d pFullscreenDisplayMode=%p\n",
142 This
, pParams
, pScreen
, pCreationParameters
, pCaps
, pPresentationParameters
, pD3D9
,
143 pPresentationGroup
, pCTX
, (int) ex
, pFullscreenDisplayMode
);
145 if (FAILED(hr
)) { return hr
; }
147 list_inithead(&This
->update_buffers
);
148 list_inithead(&This
->update_textures
);
149 list_inithead(&This
->managed_buffers
);
150 list_inithead(&This
->managed_textures
);
152 This
->screen
= pScreen
;
153 This
->screen_sw
= pCTX
->ref
;
156 This
->params
= *pCreationParameters
;
158 This
->present
= pPresentationGroup
;
159 This
->minor_version_num
= minorVersionNum
;
161 IDirect3D9_AddRef(This
->d3d9
);
162 ID3DPresentGroup_AddRef(This
->present
);
164 if (!(This
->params
.BehaviorFlags
& D3DCREATE_FPU_PRESERVE
))
167 if (This
->params
.BehaviorFlags
& D3DCREATE_SOFTWARE_VERTEXPROCESSING
) {
168 DBG("Application asked full Software Vertex Processing.\n");
170 This
->may_swvp
= true;
173 if (This
->params
.BehaviorFlags
& D3DCREATE_MIXED_VERTEXPROCESSING
) {
174 DBG("Application asked mixed Software Vertex Processing.\n");
175 This
->may_swvp
= true;
177 This
->context
.swvp
= This
->swvp
;
178 /* TODO: check if swvp is resetted by device Resets */
180 if (This
->may_swvp
&&
181 (This
->screen
->get_shader_param(This
->screen
, PIPE_SHADER_VERTEX
,
182 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
)
183 < (NINE_MAX_CONST_F_SWVP
/2) * sizeof(float[4]) ||
184 This
->screen
->get_shader_param(This
->screen
, PIPE_SHADER_VERTEX
,
185 PIPE_SHADER_CAP_MAX_CONST_BUFFERS
) < 5)) {
186 /* Note: We just go on, some apps never use the abilities of
187 * swvp, and just set more constants than allowed at init.
188 * Only cards we support that are affected are the r500 */
189 WARN("Card unable to handle Software Vertex Processing. Game may fail\n");
192 /* When may_swvp, SetConstant* limits are different */
194 This
->caps
.MaxVertexShaderConst
= NINE_MAX_CONST_F_SWVP
;
196 This
->context
.pipe
= This
->screen
->context_create(This
->screen
, NULL
, 0);
197 This
->pipe_secondary
= This
->screen
->context_create(This
->screen
, NULL
, 0);
198 if (!This
->context
.pipe
|| !This
->pipe_secondary
) { return E_OUTOFMEMORY
; } /* guess */
199 This
->pipe_sw
= This
->screen_sw
->context_create(This
->screen_sw
, NULL
, 0);
200 if (!This
->pipe_sw
) { return E_OUTOFMEMORY
; }
202 This
->context
.cso
= cso_create_context(This
->context
.pipe
, 0);
203 if (!This
->context
.cso
) { return E_OUTOFMEMORY
; } /* also a guess */
204 This
->cso_sw
= cso_create_context(This
->pipe_sw
, 0);
205 if (!This
->cso_sw
) { return E_OUTOFMEMORY
; }
207 /* Create first, it messes up our state. */
208 This
->hud
= hud_create(This
->context
.pipe
, This
->context
.cso
); /* NULL result is fine */
210 /* Available memory counter. Updated only for allocations with this device
211 * instance. This is the Win 7 behavior.
212 * Win XP shares this counter across multiple devices. */
213 This
->available_texture_mem
= This
->screen
->get_param(This
->screen
, PIPE_CAP_VIDEO_MEMORY
);
214 if (This
->available_texture_mem
< 4096)
215 This
->available_texture_mem
<<= 20;
217 This
->available_texture_mem
= UINT_MAX
;
218 /* We cap texture memory usage to 80% of what is reported free initially
219 * This helps get closer Win behaviour. For example VertexBuffer allocation
220 * still succeeds when texture allocation fails. */
221 This
->available_texture_limit
= This
->available_texture_mem
* 20LL / 100LL;
223 /* create implicit swapchains */
224 This
->nswapchains
= ID3DPresentGroup_GetMultiheadCount(This
->present
);
225 This
->swapchains
= CALLOC(This
->nswapchains
,
226 sizeof(struct NineSwapChain9
*));
227 if (!This
->swapchains
) { return E_OUTOFMEMORY
; }
229 for (i
= 0; i
< This
->nswapchains
; ++i
) {
230 ID3DPresent
*present
;
232 hr
= ID3DPresentGroup_GetPresent(This
->present
, i
, &present
);
237 D3DDISPLAYMODEEX
*mode
= NULL
;
238 struct NineSwapChain9Ex
**ret
=
239 (struct NineSwapChain9Ex
**)&This
->swapchains
[i
];
241 if (pFullscreenDisplayMode
) mode
= &(pFullscreenDisplayMode
[i
]);
242 /* when this is a Device9Ex, it should create SwapChain9Exs */
243 hr
= NineSwapChain9Ex_new(This
, TRUE
, present
,
244 &pPresentationParameters
[i
], pCTX
,
245 This
->params
.hFocusWindow
, mode
, ret
);
247 hr
= NineSwapChain9_new(This
, TRUE
, present
,
248 &pPresentationParameters
[i
], pCTX
,
249 This
->params
.hFocusWindow
,
250 &This
->swapchains
[i
]);
253 ID3DPresent_Release(present
);
256 NineUnknown_ConvertRefToBind(NineUnknown(This
->swapchains
[i
]));
258 hr
= NineSwapChain9_GetBackBuffer(This
->swapchains
[i
], 0,
259 D3DBACKBUFFER_TYPE_MONO
,
260 (IDirect3DSurface9
**)
264 NineUnknown_ConvertRefToBind(NineUnknown(This
->state
.rt
[i
]));
265 nine_bind(&This
->context
.rt
[i
], This
->state
.rt
[i
]);
268 /* Initialize CSMT */
269 if (pCTX
->csmt_force
== 1)
270 This
->csmt_active
= true;
271 else if (pCTX
->csmt_force
== 0)
272 This
->csmt_active
= false;
274 /* r600 and radeonsi are thread safe. */
275 This
->csmt_active
= strstr(pScreen
->get_name(pScreen
), "AMD") != NULL
;
277 /* We rely on u_upload_mgr using persistent coherent buffers (which don't
278 * require flush to work in multi-pipe_context scenario) for vertex and
280 if (!GET_PCAP(BUFFER_MAP_PERSISTENT_COHERENT
))
281 This
->csmt_active
= false;
283 if (This
->csmt_active
) {
284 This
->csmt_ctx
= nine_csmt_create(This
);
286 return E_OUTOFMEMORY
;
289 if (This
->csmt_active
)
290 DBG("\033[1;32mCSMT is active\033[0m\n");
292 This
->buffer_upload
= nine_upload_create(This
->pipe_secondary
, 4 * 1024 * 1024, 4);
294 /* Initialize a dummy VBO to be used when a vertex declaration does not
295 * specify all the inputs needed by vertex shader, on win default behavior
296 * is to pass 0,0,0,0 to the shader */
298 struct pipe_transfer
*transfer
;
299 struct pipe_resource tmpl
;
303 memset(&tmpl
, 0, sizeof(tmpl
));
304 tmpl
.target
= PIPE_BUFFER
;
305 tmpl
.format
= PIPE_FORMAT_R8_UNORM
;
306 tmpl
.width0
= 16; /* 4 floats */
312 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
313 tmpl
.bind
= PIPE_BIND_VERTEX_BUFFER
;
315 This
->dummy_vbo
= pScreen
->resource_create(pScreen
, &tmpl
);
317 if (!This
->dummy_vbo
)
318 return D3DERR_OUTOFVIDEOMEMORY
;
320 u_box_1d(0, 16, &box
);
321 data
= This
->context
.pipe
->transfer_map(This
->context
.pipe
, This
->dummy_vbo
, 0,
322 PIPE_TRANSFER_WRITE
|
323 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
328 This
->context
.pipe
->transfer_unmap(This
->context
.pipe
, transfer
);
331 This
->cursor
.software
= FALSE
;
332 This
->cursor
.hotspot
.x
= -1;
333 This
->cursor
.hotspot
.y
= -1;
335 struct pipe_resource tmpl
;
336 memset(&tmpl
, 0, sizeof(tmpl
));
337 tmpl
.target
= PIPE_TEXTURE_2D
;
338 tmpl
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
345 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
346 tmpl
.bind
= PIPE_BIND_CURSOR
| PIPE_BIND_SAMPLER_VIEW
;
349 This
->cursor
.image
= pScreen
->resource_create(pScreen
, &tmpl
);
350 if (!This
->cursor
.image
)
351 return D3DERR_OUTOFVIDEOMEMORY
;
353 /* For uploading 32x32 (argb) cursor */
354 This
->cursor
.hw_upload_temp
= MALLOC(32 * 4 * 32);
355 if (!This
->cursor
.hw_upload_temp
)
356 return D3DERR_OUTOFVIDEOMEMORY
;
359 /* Create constant buffers. */
361 unsigned max_const_vs
, max_const_ps
;
363 /* vs 3.0: >= 256 float constants, but for cards with exactly 256 slots,
364 * we have to take in some more slots for int and bool*/
365 max_const_vs
= _min(pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
,
366 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
) /
369 /* ps 3.0: 224 float constants. All cards supported support at least
370 * 256 constants for ps */
371 max_const_ps
= NINE_MAX_CONST_F_PS3
+ (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
373 This
->max_vs_const_f
= max_const_vs
-
374 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
375 This
->max_ps_const_f
= max_const_ps
-
376 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
378 This
->vs_const_size
= max_const_vs
* sizeof(float[4]);
379 This
->ps_const_size
= max_const_ps
* sizeof(float[4]);
380 /* Include space for I,B constants for user constbuf. */
381 if (This
->may_swvp
) {
382 This
->state
.vs_const_f
= CALLOC(NINE_MAX_CONST_F_SWVP
* sizeof(float[4]),1);
383 This
->context
.vs_const_f_swvp
= CALLOC(NINE_MAX_CONST_F_SWVP
* sizeof(float[4]),1);
384 if (!This
->context
.vs_const_f_swvp
)
385 return E_OUTOFMEMORY
;
386 This
->state
.vs_lconstf_temp
= CALLOC(NINE_MAX_CONST_F_SWVP
* sizeof(float[4]),1);
387 This
->context
.vs_lconstf_temp
= CALLOC(NINE_MAX_CONST_F_SWVP
* sizeof(float[4]),1);
388 This
->state
.vs_const_i
= CALLOC(NINE_MAX_CONST_I_SWVP
* sizeof(int[4]), 1);
389 This
->context
.vs_const_i
= CALLOC(NINE_MAX_CONST_I_SWVP
* sizeof(int[4]), 1);
390 This
->state
.vs_const_b
= CALLOC(NINE_MAX_CONST_B_SWVP
* sizeof(BOOL
), 1);
391 This
->context
.vs_const_b
= CALLOC(NINE_MAX_CONST_B_SWVP
* sizeof(BOOL
), 1);
393 This
->state
.vs_const_f
= CALLOC(NINE_MAX_CONST_F
* sizeof(float[4]), 1);
394 This
->context
.vs_const_f_swvp
= NULL
;
395 This
->state
.vs_lconstf_temp
= CALLOC(This
->vs_const_size
,1);
396 This
->context
.vs_lconstf_temp
= CALLOC(This
->vs_const_size
,1);
397 This
->state
.vs_const_i
= CALLOC(NINE_MAX_CONST_I
* sizeof(int[4]), 1);
398 This
->context
.vs_const_i
= CALLOC(NINE_MAX_CONST_I
* sizeof(int[4]), 1);
399 This
->state
.vs_const_b
= CALLOC(NINE_MAX_CONST_B
* sizeof(BOOL
), 1);
400 This
->context
.vs_const_b
= CALLOC(NINE_MAX_CONST_B
* sizeof(BOOL
), 1);
402 This
->context
.vs_const_f
= CALLOC(This
->vs_const_size
, 1);
403 This
->state
.ps_const_f
= CALLOC(This
->ps_const_size
, 1);
404 This
->context
.ps_const_f
= CALLOC(This
->ps_const_size
, 1);
405 This
->context
.ps_lconstf_temp
= CALLOC(This
->ps_const_size
,1);
406 if (!This
->state
.vs_const_f
|| !This
->context
.vs_const_f
||
407 !This
->state
.ps_const_f
|| !This
->context
.ps_const_f
||
408 !This
->state
.vs_lconstf_temp
|| !This
->context
.vs_lconstf_temp
||
409 !This
->context
.ps_lconstf_temp
||
410 !This
->state
.vs_const_i
|| !This
->context
.vs_const_i
||
411 !This
->state
.vs_const_b
|| !This
->context
.vs_const_b
)
412 return E_OUTOFMEMORY
;
414 if (strstr(pScreen
->get_name(pScreen
), "AMD") ||
415 strstr(pScreen
->get_name(pScreen
), "ATI")) {
416 This
->driver_bugs
.buggy_barycentrics
= TRUE
;
420 /* allocate dummy texture/sampler for when there are missing ones bound */
422 struct pipe_resource tmplt
;
423 struct pipe_sampler_view templ
;
424 struct pipe_sampler_state samp
;
425 memset(&tmplt
, 0, sizeof(tmplt
));
426 memset(&samp
, 0, sizeof(samp
));
428 tmplt
.target
= PIPE_TEXTURE_2D
;
432 tmplt
.last_level
= 0;
433 tmplt
.array_size
= 1;
434 tmplt
.usage
= PIPE_USAGE_DEFAULT
;
436 tmplt
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
437 tmplt
.bind
= PIPE_BIND_SAMPLER_VIEW
;
438 tmplt
.nr_samples
= 0;
440 This
->dummy_texture
= This
->screen
->resource_create(This
->screen
, &tmplt
);
441 if (!This
->dummy_texture
)
442 return D3DERR_DRIVERINTERNALERROR
;
444 templ
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
445 templ
.u
.tex
.first_layer
= 0;
446 templ
.u
.tex
.last_layer
= 0;
447 templ
.u
.tex
.first_level
= 0;
448 templ
.u
.tex
.last_level
= 0;
449 templ
.swizzle_r
= PIPE_SWIZZLE_0
;
450 templ
.swizzle_g
= PIPE_SWIZZLE_0
;
451 templ
.swizzle_b
= PIPE_SWIZZLE_0
;
452 templ
.swizzle_a
= PIPE_SWIZZLE_1
;
453 templ
.target
= This
->dummy_texture
->target
;
455 This
->dummy_sampler_view
= This
->context
.pipe
->create_sampler_view(This
->context
.pipe
, This
->dummy_texture
, &templ
);
456 if (!This
->dummy_sampler_view
)
457 return D3DERR_DRIVERINTERNALERROR
;
459 samp
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
460 samp
.max_lod
= 15.0f
;
461 samp
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
462 samp
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
463 samp
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
464 samp
.min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
465 samp
.mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
466 samp
.compare_mode
= PIPE_TEX_COMPARE_NONE
;
467 samp
.compare_func
= PIPE_FUNC_LEQUAL
;
468 samp
.normalized_coords
= 1;
469 samp
.seamless_cube_map
= 0;
470 This
->dummy_sampler_state
= samp
;
473 /* Allocate upload helper for drivers that suck (from st pov ;). */
475 This
->driver_caps
.user_vbufs
= GET_PCAP(USER_VERTEX_BUFFERS
) && !This
->csmt_active
;
476 This
->driver_caps
.user_cbufs
= GET_PCAP(USER_CONSTANT_BUFFERS
);
477 This
->driver_caps
.user_sw_vbufs
= This
->screen_sw
->get_param(This
->screen_sw
, PIPE_CAP_USER_VERTEX_BUFFERS
);
478 This
->driver_caps
.user_sw_cbufs
= This
->screen_sw
->get_param(This
->screen_sw
, PIPE_CAP_USER_CONSTANT_BUFFERS
);
479 This
->vertex_uploader
= This
->csmt_active
? This
->pipe_secondary
->stream_uploader
: This
->context
.pipe
->stream_uploader
;
480 if (!This
->driver_caps
.user_cbufs
)
481 This
->constbuf_alignment
= GET_PCAP(CONSTANT_BUFFER_OFFSET_ALIGNMENT
);
482 This
->driver_caps
.window_space_position_support
= GET_PCAP(TGSI_VS_WINDOW_SPACE_POSITION
);
483 This
->driver_caps
.vs_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
, PIPE_SHADER_CAP_INTEGERS
);
484 This
->driver_caps
.ps_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_FRAGMENT
, PIPE_SHADER_CAP_INTEGERS
);
485 This
->driver_caps
.offset_units_unscaled
= GET_PCAP(POLYGON_OFFSET_UNITS_UNSCALED
);
487 nine_ff_init(This
); /* initialize fixed function code */
489 NineDevice9_SetDefaultState(This
, FALSE
);
492 struct pipe_poly_stipple stipple
;
493 memset(&stipple
, ~0, sizeof(stipple
));
494 This
->context
.pipe
->set_polygon_stipple(This
->context
.pipe
, &stipple
);
497 This
->update
= &This
->state
;
499 nine_state_init_sw(This
);
501 ID3DPresentGroup_Release(This
->present
);
502 nine_csmt_process(This
);
509 NineDevice9_dtor( struct NineDevice9
*This
)
513 DBG("This=%p\n", This
);
515 /* Flush all pending commands to get refcount right,
516 * and properly release bound objects. It is ok to still
517 * execute commands while we are in device dtor, because
518 * we haven't released anything yet. Note that no pending
519 * command can increase the device refcount. */
520 if (This
->csmt_active
&& This
->csmt_ctx
) {
521 nine_csmt_process(This
);
522 nine_csmt_destroy(This
, This
->csmt_ctx
);
523 This
->csmt_active
= FALSE
;
524 This
->csmt_ctx
= NULL
;
528 nine_state_destroy_sw(This
);
529 nine_state_clear(&This
->state
, TRUE
);
530 nine_context_clear(This
);
532 nine_bind(&This
->record
, NULL
);
534 pipe_sampler_view_reference(&This
->dummy_sampler_view
, NULL
);
535 pipe_resource_reference(&This
->dummy_texture
, NULL
);
536 pipe_resource_reference(&This
->dummy_vbo
, NULL
);
537 FREE(This
->state
.vs_const_f
);
538 FREE(This
->context
.vs_const_f
);
539 FREE(This
->state
.ps_const_f
);
540 FREE(This
->context
.ps_const_f
);
541 FREE(This
->state
.vs_lconstf_temp
);
542 FREE(This
->context
.vs_lconstf_temp
);
543 FREE(This
->context
.ps_lconstf_temp
);
544 FREE(This
->state
.vs_const_i
);
545 FREE(This
->context
.vs_const_i
);
546 FREE(This
->state
.vs_const_b
);
547 FREE(This
->context
.vs_const_b
);
548 FREE(This
->context
.vs_const_f_swvp
);
550 pipe_resource_reference(&This
->cursor
.image
, NULL
);
551 FREE(This
->cursor
.hw_upload_temp
);
553 if (This
->swapchains
) {
554 for (i
= 0; i
< This
->nswapchains
; ++i
)
555 if (This
->swapchains
[i
])
556 NineUnknown_Unbind(NineUnknown(This
->swapchains
[i
]));
557 FREE(This
->swapchains
);
560 if (This
->buffer_upload
)
561 nine_upload_destroy(This
->buffer_upload
);
563 /* Destroy cso first */
564 if (This
->context
.cso
) { cso_destroy_context(This
->context
.cso
); }
565 if (This
->cso_sw
) { cso_destroy_context(This
->cso_sw
); }
566 if (This
->context
.pipe
&& This
->context
.pipe
->destroy
) { This
->context
.pipe
->destroy(This
->context
.pipe
); }
567 if (This
->pipe_secondary
&& This
->pipe_secondary
->destroy
) { This
->pipe_secondary
->destroy(This
->pipe_secondary
); }
568 if (This
->pipe_sw
&& This
->pipe_sw
->destroy
) { This
->pipe_sw
->destroy(This
->pipe_sw
); }
570 if (This
->present
) { ID3DPresentGroup_Release(This
->present
); }
571 if (This
->d3d9
) { IDirect3D9_Release(This
->d3d9
); }
573 NineUnknown_dtor(&This
->base
);
577 NineDevice9_GetScreen( struct NineDevice9
*This
)
582 struct pipe_context
*
583 NineDevice9_GetPipe( struct NineDevice9
*This
)
585 return nine_context_get_pipe(This
);
589 NineDevice9_GetCaps( struct NineDevice9
*This
)
595 NineDevice9_PauseRecording( struct NineDevice9
*This
)
598 This
->update
= &This
->state
;
599 This
->is_recording
= FALSE
;
604 NineDevice9_ResumeRecording( struct NineDevice9
*This
)
607 This
->update
= &This
->record
->state
;
608 This
->is_recording
= TRUE
;
613 NineDevice9_TestCooperativeLevel( struct NineDevice9
*This
)
615 if (NineSwapChain9_GetOccluded(This
->swapchains
[0])) {
616 This
->device_needs_reset
= TRUE
;
617 return D3DERR_DEVICELOST
;
618 } else if (NineSwapChain9_ResolutionMismatch(This
->swapchains
[0])) {
619 This
->device_needs_reset
= TRUE
;
620 return D3DERR_DEVICENOTRESET
;
621 } else if (This
->device_needs_reset
) {
622 return D3DERR_DEVICENOTRESET
;
629 NineDevice9_GetAvailableTextureMem( struct NineDevice9
*This
)
631 return This
->available_texture_mem
;
635 NineDevice9_EvictManagedResources( struct NineDevice9
*This
)
637 struct NineBaseTexture9
*tex
;
638 struct NineBuffer9
*buf
;
640 DBG("This=%p\n", This
);
641 LIST_FOR_EACH_ENTRY(tex
, &This
->managed_textures
, list2
) {
642 NineBaseTexture9_UnLoad(tex
);
644 /* Vertex/index buffers don't take a lot of space and aren't accounted
645 * for d3d memory usage. Instead of actually freeing from memory,
646 * just mark the buffer dirty to trigger a re-upload later. We
647 * could just ignore, but some bad behaving apps could rely on it (if
648 * they write outside the locked regions typically). */
649 LIST_FOR_EACH_ENTRY(buf
, &This
->managed_buffers
, managed
.list2
) {
650 NineBuffer9_SetDirty(buf
);
657 NineDevice9_GetDirect3D( struct NineDevice9
*This
,
658 IDirect3D9
**ppD3D9
)
660 user_assert(ppD3D9
!= NULL
, E_POINTER
);
661 IDirect3D9_AddRef(This
->d3d9
);
662 *ppD3D9
= This
->d3d9
;
667 NineDevice9_GetDeviceCaps( struct NineDevice9
*This
,
670 user_assert(pCaps
!= NULL
, D3DERR_INVALIDCALL
);
676 NineDevice9_GetDisplayMode( struct NineDevice9
*This
,
678 D3DDISPLAYMODE
*pMode
)
680 DBG("This=%p iSwapChain=%u pMode=%p\n", This
, iSwapChain
, pMode
);
682 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
684 return NineSwapChain9_GetDisplayMode(This
->swapchains
[iSwapChain
], pMode
);
688 NineDevice9_GetCreationParameters( struct NineDevice9
*This
,
689 D3DDEVICE_CREATION_PARAMETERS
*pParameters
)
691 user_assert(pParameters
!= NULL
, D3DERR_INVALIDCALL
);
692 *pParameters
= This
->params
;
697 NineDevice9_SetCursorProperties( struct NineDevice9
*This
,
700 IDirect3DSurface9
*pCursorBitmap
)
702 struct NineSurface9
*surf
= NineSurface9(pCursorBitmap
);
703 struct pipe_context
*pipe
= NineDevice9_GetPipe(This
);
705 struct pipe_transfer
*transfer
;
709 DBG_FLAG(DBG_SWAPCHAIN
, "This=%p XHotSpot=%u YHotSpot=%u "
710 "pCursorBitmap=%p\n", This
, XHotSpot
, YHotSpot
, pCursorBitmap
);
712 user_assert(pCursorBitmap
, D3DERR_INVALIDCALL
);
713 user_assert(surf
->desc
.Format
== D3DFMT_A8R8G8B8
, D3DERR_INVALIDCALL
);
715 if (This
->swapchains
[0]->params
.Windowed
) {
716 This
->cursor
.w
= MIN2(surf
->desc
.Width
, 32);
717 This
->cursor
.h
= MIN2(surf
->desc
.Height
, 32);
718 hw_cursor
= 1; /* always use hw cursor for windowed mode */
720 This
->cursor
.w
= MIN2(surf
->desc
.Width
, This
->cursor
.image
->width0
);
721 This
->cursor
.h
= MIN2(surf
->desc
.Height
, This
->cursor
.image
->height0
);
722 hw_cursor
= This
->cursor
.w
== 32 && This
->cursor
.h
== 32;
725 u_box_origin_2d(This
->cursor
.w
, This
->cursor
.h
, &box
);
727 ptr
= pipe
->transfer_map(pipe
, This
->cursor
.image
, 0,
728 PIPE_TRANSFER_WRITE
|
729 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
732 ret_err("Failed to update cursor image.\n", D3DERR_DRIVERINTERNALERROR
);
734 This
->cursor
.hotspot
.x
= XHotSpot
;
735 This
->cursor
.hotspot
.y
= YHotSpot
;
737 /* Copy cursor image to internal storage. */
741 const struct util_format_description
*sfmt
=
742 util_format_description(surf
->base
.info
.format
);
745 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, D3DLOCK_READONLY
);
747 ret_err("Failed to map cursor source image.\n",
748 D3DERR_DRIVERINTERNALERROR
);
750 sfmt
->unpack_rgba_8unorm(ptr
, transfer
->stride
,
751 lock
.pBits
, lock
.Pitch
,
752 This
->cursor
.w
, This
->cursor
.h
);
755 void *data
= lock
.pBits
;
756 /* SetCursor assumes 32x32 argb with pitch 128 */
757 if (lock
.Pitch
!= 128) {
758 sfmt
->unpack_rgba_8unorm(This
->cursor
.hw_upload_temp
, 128,
759 lock
.pBits
, lock
.Pitch
,
761 data
= This
->cursor
.hw_upload_temp
;
763 hw_cursor
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
,
765 &This
->cursor
.hotspot
,
766 This
->cursor
.visible
) == D3D_OK
;
769 NineSurface9_UnlockRect(surf
);
771 pipe
->transfer_unmap(pipe
, transfer
);
773 /* hide cursor if we emulate it */
775 ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, FALSE
);
776 This
->cursor
.software
= !hw_cursor
;
782 NineDevice9_SetCursorPosition( struct NineDevice9
*This
,
787 struct NineSwapChain9
*swap
= This
->swapchains
[0];
789 DBG("This=%p X=%d Y=%d Flags=%d\n", This
, X
, Y
, Flags
);
791 This
->cursor
.pos
.x
= X
;
792 This
->cursor
.pos
.y
= Y
;
794 if (!This
->cursor
.software
)
795 This
->cursor
.software
= ID3DPresent_SetCursorPos(swap
->present
, &This
->cursor
.pos
) != D3D_OK
;
799 NineDevice9_ShowCursor( struct NineDevice9
*This
,
802 BOOL old
= This
->cursor
.visible
;
804 DBG("This=%p bShow=%d\n", This
, (int) bShow
);
806 This
->cursor
.visible
= bShow
&& (This
->cursor
.hotspot
.x
!= -1);
807 if (!This
->cursor
.software
)
808 This
->cursor
.software
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, bShow
) != D3D_OK
;
814 NineDevice9_CreateAdditionalSwapChain( struct NineDevice9
*This
,
815 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
816 IDirect3DSwapChain9
**pSwapChain
)
818 struct NineSwapChain9
*swapchain
, *tmplt
= This
->swapchains
[0];
819 ID3DPresent
*present
;
822 DBG("This=%p pPresentationParameters=%p pSwapChain=%p\n",
823 This
, pPresentationParameters
, pSwapChain
);
825 user_assert(pPresentationParameters
, D3DERR_INVALIDCALL
);
826 user_assert(tmplt
->params
.Windowed
&& pPresentationParameters
->Windowed
, D3DERR_INVALIDCALL
);
828 /* TODO: this deserves more tests */
829 if (!pPresentationParameters
->hDeviceWindow
)
830 pPresentationParameters
->hDeviceWindow
= This
->params
.hFocusWindow
;
832 hr
= ID3DPresentGroup_CreateAdditionalPresent(This
->present
, pPresentationParameters
, &present
);
837 hr
= NineSwapChain9_new(This
, FALSE
, present
, pPresentationParameters
,
839 tmplt
->params
.hDeviceWindow
,
844 *pSwapChain
= (IDirect3DSwapChain9
*)swapchain
;
849 NineDevice9_GetSwapChain( struct NineDevice9
*This
,
851 IDirect3DSwapChain9
**pSwapChain
)
853 user_assert(pSwapChain
!= NULL
, D3DERR_INVALIDCALL
);
856 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
858 NineUnknown_AddRef(NineUnknown(This
->swapchains
[iSwapChain
]));
859 *pSwapChain
= (IDirect3DSwapChain9
*)This
->swapchains
[iSwapChain
];
865 NineDevice9_GetNumberOfSwapChains( struct NineDevice9
*This
)
867 return This
->nswapchains
;
871 NineDevice9_Reset( struct NineDevice9
*This
,
872 D3DPRESENT_PARAMETERS
*pPresentationParameters
)
877 DBG("This=%p pPresentationParameters=%p\n", This
, pPresentationParameters
);
879 if (NineSwapChain9_GetOccluded(This
->swapchains
[0])) {
880 This
->device_needs_reset
= TRUE
;
881 return D3DERR_DEVICELOST
;
884 for (i
= 0; i
< This
->nswapchains
; ++i
) {
885 D3DPRESENT_PARAMETERS
*params
= &pPresentationParameters
[i
];
886 hr
= NineSwapChain9_Resize(This
->swapchains
[i
], params
, NULL
);
891 nine_csmt_process(This
);
892 nine_state_clear(&This
->state
, TRUE
);
893 nine_context_clear(This
);
895 NineDevice9_SetDefaultState(This
, TRUE
);
896 NineDevice9_SetRenderTarget(
897 This
, 0, (IDirect3DSurface9
*)This
->swapchains
[0]->buffers
[0]);
898 /* XXX: better use GetBackBuffer here ? */
900 This
->device_needs_reset
= (hr
!= D3D_OK
);
905 NineDevice9_Present( struct NineDevice9
*This
,
906 const RECT
*pSourceRect
,
907 const RECT
*pDestRect
,
908 HWND hDestWindowOverride
,
909 const RGNDATA
*pDirtyRegion
)
914 DBG("This=%p pSourceRect=%p pDestRect=%p hDestWindowOverride=%p pDirtyRegion=%p\n",
915 This
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
917 /* XXX is this right? */
918 for (i
= 0; i
< This
->nswapchains
; ++i
) {
919 hr
= NineSwapChain9_Present(This
->swapchains
[i
], pSourceRect
, pDestRect
,
920 hDestWindowOverride
, pDirtyRegion
, 0);
921 if (FAILED(hr
)) { return hr
; }
928 NineDevice9_GetBackBuffer( struct NineDevice9
*This
,
931 D3DBACKBUFFER_TYPE Type
,
932 IDirect3DSurface9
**ppBackBuffer
)
934 user_assert(ppBackBuffer
!= NULL
, D3DERR_INVALIDCALL
);
935 /* return NULL on error */
936 *ppBackBuffer
= NULL
;
937 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
939 return NineSwapChain9_GetBackBuffer(This
->swapchains
[iSwapChain
],
940 iBackBuffer
, Type
, ppBackBuffer
);
944 NineDevice9_GetRasterStatus( struct NineDevice9
*This
,
946 D3DRASTER_STATUS
*pRasterStatus
)
948 user_assert(pRasterStatus
!= NULL
, D3DERR_INVALIDCALL
);
949 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
951 return NineSwapChain9_GetRasterStatus(This
->swapchains
[iSwapChain
],
956 NineDevice9_SetDialogBoxMode( struct NineDevice9
*This
,
957 BOOL bEnableDialogs
)
959 STUB(D3DERR_INVALIDCALL
);
963 NineDevice9_SetGammaRamp( struct NineDevice9
*This
,
966 const D3DGAMMARAMP
*pRamp
)
968 DBG("This=%p iSwapChain=%u Flags=%x pRamp=%p\n", This
,
969 iSwapChain
, Flags
, pRamp
);
971 user_warn(iSwapChain
>= This
->nswapchains
);
974 if (pRamp
&& (iSwapChain
< This
->nswapchains
)) {
975 struct NineSwapChain9
*swap
= This
->swapchains
[iSwapChain
];
976 swap
->gamma
= *pRamp
;
977 ID3DPresent_SetGammaRamp(swap
->present
, pRamp
, swap
->params
.hDeviceWindow
);
982 NineDevice9_GetGammaRamp( struct NineDevice9
*This
,
984 D3DGAMMARAMP
*pRamp
)
986 DBG("This=%p iSwapChain=%u pRamp=%p\n", This
, iSwapChain
, pRamp
);
988 user_warn(iSwapChain
>= This
->nswapchains
);
991 if (pRamp
&& (iSwapChain
< This
->nswapchains
))
992 *pRamp
= This
->swapchains
[iSwapChain
]->gamma
;
996 NineDevice9_CreateTexture( struct NineDevice9
*This
,
1003 IDirect3DTexture9
**ppTexture
,
1004 HANDLE
*pSharedHandle
)
1006 struct NineTexture9
*tex
;
1009 DBG("This=%p Width=%u Height=%u Levels=%u Usage=%s Format=%s Pool=%s "
1010 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Levels
,
1011 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
1012 nine_D3DPOOL_to_str(Pool
), ppTexture
, pSharedHandle
);
1014 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DMAP
|
1015 D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
1016 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
;
1020 hr
= NineTexture9_new(This
, Width
, Height
, Levels
, Usage
, Format
, Pool
,
1021 &tex
, pSharedHandle
);
1023 *ppTexture
= (IDirect3DTexture9
*)tex
;
1029 NineDevice9_CreateVolumeTexture( struct NineDevice9
*This
,
1037 IDirect3DVolumeTexture9
**ppVolumeTexture
,
1038 HANDLE
*pSharedHandle
)
1040 struct NineVolumeTexture9
*tex
;
1043 DBG("This=%p Width=%u Height=%u Depth=%u Levels=%u Usage=%s Format=%s Pool=%s "
1044 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Depth
, Levels
,
1045 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
1046 nine_D3DPOOL_to_str(Pool
), ppVolumeTexture
, pSharedHandle
);
1048 Usage
&= D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1049 D3DUSAGE_SOFTWAREPROCESSING
;
1051 *ppVolumeTexture
= NULL
;
1053 hr
= NineVolumeTexture9_new(This
, Width
, Height
, Depth
, Levels
,
1054 Usage
, Format
, Pool
, &tex
, pSharedHandle
);
1056 *ppVolumeTexture
= (IDirect3DVolumeTexture9
*)tex
;
1062 NineDevice9_CreateCubeTexture( struct NineDevice9
*This
,
1068 IDirect3DCubeTexture9
**ppCubeTexture
,
1069 HANDLE
*pSharedHandle
)
1071 struct NineCubeTexture9
*tex
;
1074 DBG("This=%p EdgeLength=%u Levels=%u Usage=%s Format=%s Pool=%s ppOut=%p "
1075 "pSharedHandle=%p\n", This
, EdgeLength
, Levels
,
1076 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
1077 nine_D3DPOOL_to_str(Pool
), ppCubeTexture
, pSharedHandle
);
1079 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DYNAMIC
|
1080 D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
1081 D3DUSAGE_SOFTWAREPROCESSING
;
1083 *ppCubeTexture
= NULL
;
1085 hr
= NineCubeTexture9_new(This
, EdgeLength
, Levels
, Usage
, Format
, Pool
,
1086 &tex
, pSharedHandle
);
1088 *ppCubeTexture
= (IDirect3DCubeTexture9
*)tex
;
1094 NineDevice9_CreateVertexBuffer( struct NineDevice9
*This
,
1099 IDirect3DVertexBuffer9
**ppVertexBuffer
,
1100 HANDLE
*pSharedHandle
)
1102 struct NineVertexBuffer9
*buf
;
1104 D3DVERTEXBUFFER_DESC desc
;
1106 DBG("This=%p Length=%u Usage=%x FVF=%x Pool=%u ppOut=%p pSharedHandle=%p\n",
1107 This
, Length
, Usage
, FVF
, Pool
, ppVertexBuffer
, pSharedHandle
);
1109 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1111 desc
.Format
= D3DFMT_VERTEXDATA
;
1112 desc
.Type
= D3DRTYPE_VERTEXBUFFER
;
1113 desc
.Usage
= Usage
&
1114 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1115 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1116 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
|
1117 D3DUSAGE_WRITEONLY
);
1122 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1123 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1125 hr
= NineVertexBuffer9_new(This
, &desc
, &buf
);
1127 *ppVertexBuffer
= (IDirect3DVertexBuffer9
*)buf
;
1132 NineDevice9_CreateIndexBuffer( struct NineDevice9
*This
,
1137 IDirect3DIndexBuffer9
**ppIndexBuffer
,
1138 HANDLE
*pSharedHandle
)
1140 struct NineIndexBuffer9
*buf
;
1142 D3DINDEXBUFFER_DESC desc
;
1144 DBG("This=%p Length=%u Usage=%x Format=%s Pool=%u ppOut=%p "
1145 "pSharedHandle=%p\n", This
, Length
, Usage
,
1146 d3dformat_to_string(Format
), Pool
, ppIndexBuffer
, pSharedHandle
);
1148 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1150 desc
.Format
= Format
;
1151 desc
.Type
= D3DRTYPE_INDEXBUFFER
;
1152 desc
.Usage
= Usage
&
1153 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1154 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1155 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_WRITEONLY
);
1159 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1160 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1162 hr
= NineIndexBuffer9_new(This
, &desc
, &buf
);
1164 *ppIndexBuffer
= (IDirect3DIndexBuffer9
*)buf
;
1169 create_zs_or_rt_surface(struct NineDevice9
*This
,
1170 unsigned type
, /* 0 = RT, 1 = ZS, 2 = plain */
1172 UINT Width
, UINT Height
,
1174 D3DMULTISAMPLE_TYPE MultiSample
,
1175 DWORD MultisampleQuality
,
1176 BOOL Discard_or_Lockable
,
1177 IDirect3DSurface9
**ppSurface
,
1178 HANDLE
*pSharedHandle
)
1180 struct NineSurface9
*surface
;
1182 D3DSURFACE_DESC desc
;
1184 DBG("This=%p type=%u Pool=%s Width=%u Height=%u Format=%s MS=%u Quality=%u "
1185 "Discard_or_Lockable=%i ppSurface=%p pSharedHandle=%p\n",
1186 This
, type
, nine_D3DPOOL_to_str(Pool
), Width
, Height
,
1187 d3dformat_to_string(Format
), MultiSample
, MultisampleQuality
,
1188 Discard_or_Lockable
, ppSurface
, pSharedHandle
);
1191 DBG("FIXME Used shared handle! This option isn't probably handled correctly!\n");
1193 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
1194 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1196 desc
.Format
= Format
;
1197 desc
.Type
= D3DRTYPE_SURFACE
;
1200 desc
.MultiSampleType
= MultiSample
;
1201 desc
.MultiSampleQuality
= MultisampleQuality
;
1203 desc
.Height
= Height
;
1205 case 0: desc
.Usage
= D3DUSAGE_RENDERTARGET
; break;
1206 case 1: desc
.Usage
= D3DUSAGE_DEPTHSTENCIL
; break;
1207 default: assert(type
== 2); break;
1210 hr
= NineSurface9_new(This
, NULL
, NULL
, NULL
, 0, 0, 0, &desc
, &surface
);
1211 if (SUCCEEDED(hr
)) {
1212 *ppSurface
= (IDirect3DSurface9
*)surface
;
1214 if (surface
->base
.resource
&& Discard_or_Lockable
&& (type
!= 1))
1215 surface
->base
.resource
->flags
|= NINE_RESOURCE_FLAG_LOCKABLE
;
1222 NineDevice9_CreateRenderTarget( struct NineDevice9
*This
,
1226 D3DMULTISAMPLE_TYPE MultiSample
,
1227 DWORD MultisampleQuality
,
1229 IDirect3DSurface9
**ppSurface
,
1230 HANDLE
*pSharedHandle
)
1233 return create_zs_or_rt_surface(This
, 0, D3DPOOL_DEFAULT
,
1234 Width
, Height
, Format
,
1235 MultiSample
, MultisampleQuality
,
1236 Lockable
, ppSurface
, pSharedHandle
);
1240 NineDevice9_CreateDepthStencilSurface( struct NineDevice9
*This
,
1244 D3DMULTISAMPLE_TYPE MultiSample
,
1245 DWORD MultisampleQuality
,
1247 IDirect3DSurface9
**ppSurface
,
1248 HANDLE
*pSharedHandle
)
1251 if (!depth_stencil_format(Format
))
1252 return D3DERR_NOTAVAILABLE
;
1253 return create_zs_or_rt_surface(This
, 1, D3DPOOL_DEFAULT
,
1254 Width
, Height
, Format
,
1255 MultiSample
, MultisampleQuality
,
1256 Discard
, ppSurface
, pSharedHandle
);
1260 NineDevice9_UpdateSurface( struct NineDevice9
*This
,
1261 IDirect3DSurface9
*pSourceSurface
,
1262 const RECT
*pSourceRect
,
1263 IDirect3DSurface9
*pDestinationSurface
,
1264 const POINT
*pDestPoint
)
1266 struct NineSurface9
*dst
= NineSurface9(pDestinationSurface
);
1267 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1268 int copy_width
, copy_height
;
1271 DBG("This=%p pSourceSurface=%p pDestinationSurface=%p "
1272 "pSourceRect=%p pDestPoint=%p\n", This
,
1273 pSourceSurface
, pDestinationSurface
, pSourceRect
, pDestPoint
);
1275 DBG("pSourceRect = (%u,%u)-(%u,%u)\n",
1276 pSourceRect
->left
, pSourceRect
->top
,
1277 pSourceRect
->right
, pSourceRect
->bottom
);
1279 DBG("pDestPoint = (%u,%u)\n", pDestPoint
->x
, pDestPoint
->y
);
1281 user_assert(dst
&& src
, D3DERR_INVALIDCALL
);
1283 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1284 user_assert(src
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1286 user_assert(dst
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1287 user_assert(src
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1289 user_assert(!src
->lock_count
, D3DERR_INVALIDCALL
);
1290 user_assert(!dst
->lock_count
, D3DERR_INVALIDCALL
);
1292 user_assert(dst
->desc
.Format
== src
->desc
.Format
, D3DERR_INVALIDCALL
);
1293 user_assert(!depth_stencil_format(dst
->desc
.Format
), D3DERR_INVALIDCALL
);
1296 copy_width
= pSourceRect
->right
- pSourceRect
->left
;
1297 copy_height
= pSourceRect
->bottom
- pSourceRect
->top
;
1299 user_assert(pSourceRect
->left
>= 0 &&
1301 pSourceRect
->right
<= src
->desc
.Width
&&
1302 pSourceRect
->top
>= 0 &&
1304 pSourceRect
->bottom
<= src
->desc
.Height
,
1305 D3DERR_INVALIDCALL
);
1307 copy_width
= src
->desc
.Width
;
1308 copy_height
= src
->desc
.Height
;
1311 destRect
.right
= copy_width
;
1312 destRect
.bottom
= copy_height
;
1315 user_assert(pDestPoint
->x
>= 0 && pDestPoint
->y
>= 0,
1316 D3DERR_INVALIDCALL
);
1317 destRect
.right
+= pDestPoint
->x
;
1318 destRect
.bottom
+= pDestPoint
->y
;
1321 user_assert(destRect
.right
<= dst
->desc
.Width
&&
1322 destRect
.bottom
<= dst
->desc
.Height
,
1323 D3DERR_INVALIDCALL
);
1325 if (compressed_format(dst
->desc
.Format
)) {
1326 const unsigned w
= util_format_get_blockwidth(dst
->base
.info
.format
);
1327 const unsigned h
= util_format_get_blockheight(dst
->base
.info
.format
);
1330 user_assert(!(pDestPoint
->x
% w
) && !(pDestPoint
->y
% h
),
1331 D3DERR_INVALIDCALL
);
1335 user_assert(!(pSourceRect
->left
% w
) && !(pSourceRect
->top
% h
),
1336 D3DERR_INVALIDCALL
);
1338 if (!(copy_width
== src
->desc
.Width
&&
1339 copy_width
== dst
->desc
.Width
&&
1340 copy_height
== src
->desc
.Height
&&
1341 copy_height
== dst
->desc
.Height
)) {
1342 user_assert(!(copy_width
% w
) && !(copy_height
% h
),
1343 D3DERR_INVALIDCALL
);
1347 NineSurface9_CopyMemToDefault(dst
, src
, pDestPoint
, pSourceRect
);
1353 NineDevice9_UpdateTexture( struct NineDevice9
*This
,
1354 IDirect3DBaseTexture9
*pSourceTexture
,
1355 IDirect3DBaseTexture9
*pDestinationTexture
)
1357 struct NineBaseTexture9
*dstb
= NineBaseTexture9(pDestinationTexture
);
1358 struct NineBaseTexture9
*srcb
= NineBaseTexture9(pSourceTexture
);
1360 unsigned last_src_level
, last_dst_level
;
1363 DBG("This=%p pSourceTexture=%p pDestinationTexture=%p\n", This
,
1364 pSourceTexture
, pDestinationTexture
);
1366 user_assert(pSourceTexture
&& pDestinationTexture
, D3DERR_INVALIDCALL
);
1367 user_assert(pSourceTexture
!= pDestinationTexture
, D3DERR_INVALIDCALL
);
1369 user_assert(dstb
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1370 user_assert(srcb
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1371 user_assert(dstb
->base
.type
== srcb
->base
.type
, D3DERR_INVALIDCALL
);
1372 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ||
1373 dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
, D3DERR_INVALIDCALL
);
1376 * . Different formats
1377 * . Fewer src levels than dst levels (if the opposite, only matching levels
1378 * are supposed to be copied)
1379 * . Levels do not match
1380 * DDI: Actually the above should pass because of legacy applications
1381 * Do what you want about these, but you shouldn't crash.
1382 * However driver can expect that the top dimension is greater for src than dst.
1383 * Wine tests: Every combination that passes the initial checks should pass.
1384 * . Different formats => conversion driver and format dependent.
1385 * . 1 level, but size not matching => copy is done (and even crash if src bigger
1386 * than dst. For the case where dst bigger, wine doesn't test if a stretch is applied
1387 * or if a subrect is copied).
1388 * . 8x8 4 sublevels -> 7x7 2 sublevels => driver dependent, On NV seems to be 4x4 subrect
1391 * From these, the proposal is:
1392 * . Different formats -> use util_format_translate to translate if possible for surfaces.
1393 * Accept ARGB/XRGB for Volumes. Do nothing for the other combinations
1394 * . First level copied -> the first level such that src is smaller or equal to dst first level
1395 * . number of levels copied -> as long as it fits and textures have levels
1396 * That should satisfy the constraints (and instead of crashing for some cases we return D3D_OK)
1399 last_src_level
= (srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ? 0 : srcb
->base
.info
.last_level
;
1400 last_dst_level
= (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ? 0 : dstb
->base
.info
.last_level
;
1402 for (m
= 0; m
<= last_src_level
; ++m
) {
1403 unsigned w
= u_minify(srcb
->base
.info
.width0
, m
);
1404 unsigned h
= u_minify(srcb
->base
.info
.height0
, m
);
1405 unsigned d
= u_minify(srcb
->base
.info
.depth0
, m
);
1407 if (w
<= dstb
->base
.info
.width0
&&
1408 h
<= dstb
->base
.info
.height0
&&
1409 d
<= dstb
->base
.info
.depth0
)
1412 user_assert(m
<= last_src_level
, D3D_OK
);
1414 last_dst_level
= MIN2(srcb
->base
.info
.last_level
- m
, last_dst_level
);
1416 if (dstb
->base
.type
== D3DRTYPE_TEXTURE
) {
1417 struct NineTexture9
*dst
= NineTexture9(dstb
);
1418 struct NineTexture9
*src
= NineTexture9(srcb
);
1420 if (src
->dirty_rect
.width
== 0)
1423 pipe_box_to_rect(&rect
, &src
->dirty_rect
);
1424 for (l
= 0; l
< m
; ++l
)
1425 rect_minify_inclusive(&rect
);
1427 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
) {
1428 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1430 dst
->surfaces
[l
]->desc
.Width
,
1431 dst
->surfaces
[l
]->desc
.Height
);
1432 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
],
1436 rect_minify_inclusive(&rect
);
1438 u_box_origin_2d(0, 0, &src
->dirty_rect
);
1440 if (dstb
->base
.type
== D3DRTYPE_CUBETEXTURE
) {
1441 struct NineCubeTexture9
*dst
= NineCubeTexture9(dstb
);
1442 struct NineCubeTexture9
*src
= NineCubeTexture9(srcb
);
1445 /* GPUs usually have them stored as arrays of mip-mapped 2D textures. */
1446 for (z
= 0; z
< 6; ++z
) {
1447 if (src
->dirty_rect
[z
].width
== 0)
1450 pipe_box_to_rect(&rect
, &src
->dirty_rect
[z
]);
1451 for (l
= 0; l
< m
; ++l
)
1452 rect_minify_inclusive(&rect
);
1454 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
) {
1455 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1457 dst
->surfaces
[l
* 6 + z
]->desc
.Width
,
1458 dst
->surfaces
[l
* 6 + z
]->desc
.Height
);
1459 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
* 6 + z
],
1460 src
->surfaces
[m
* 6 + z
],
1463 rect_minify_inclusive(&rect
);
1465 u_box_origin_2d(0, 0, &src
->dirty_rect
[z
]);
1469 if (dstb
->base
.type
== D3DRTYPE_VOLUMETEXTURE
) {
1470 struct NineVolumeTexture9
*dst
= NineVolumeTexture9(dstb
);
1471 struct NineVolumeTexture9
*src
= NineVolumeTexture9(srcb
);
1473 if (src
->dirty_box
.width
== 0)
1475 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
)
1476 NineVolume9_CopyMemToDefault(dst
->volumes
[l
],
1477 src
->volumes
[m
], 0, 0, 0, NULL
);
1478 u_box_3d(0, 0, 0, 0, 0, 0, &src
->dirty_box
);
1480 assert(!"invalid texture type");
1483 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1484 dstb
->dirty_mip
= TRUE
;
1485 NineBaseTexture9_GenerateMipSubLevels(dstb
);
1492 NineDevice9_GetRenderTargetData( struct NineDevice9
*This
,
1493 IDirect3DSurface9
*pRenderTarget
,
1494 IDirect3DSurface9
*pDestSurface
)
1496 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1497 struct NineSurface9
*src
= NineSurface9(pRenderTarget
);
1499 DBG("This=%p pRenderTarget=%p pDestSurface=%p\n",
1500 This
, pRenderTarget
, pDestSurface
);
1502 user_assert(pRenderTarget
&& pDestSurface
, D3DERR_INVALIDCALL
);
1504 user_assert(dst
->desc
.Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1505 user_assert(src
->desc
.Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1507 user_assert(dst
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1508 user_assert(src
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1510 user_assert(src
->desc
.Width
== dst
->desc
.Width
, D3DERR_INVALIDCALL
);
1511 user_assert(src
->desc
.Height
== dst
->desc
.Height
, D3DERR_INVALIDCALL
);
1513 user_assert(src
->desc
.Format
!= D3DFMT_NULL
, D3DERR_INVALIDCALL
);
1515 NineSurface9_CopyDefaultToMem(dst
, src
);
1521 NineDevice9_GetFrontBufferData( struct NineDevice9
*This
,
1523 IDirect3DSurface9
*pDestSurface
)
1525 DBG("This=%p iSwapChain=%u pDestSurface=%p\n", This
,
1526 iSwapChain
, pDestSurface
);
1528 user_assert(pDestSurface
!= NULL
, D3DERR_INVALIDCALL
);
1529 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
1531 return NineSwapChain9_GetFrontBufferData(This
->swapchains
[iSwapChain
],
1536 NineDevice9_StretchRect( struct NineDevice9
*This
,
1537 IDirect3DSurface9
*pSourceSurface
,
1538 const RECT
*pSourceRect
,
1539 IDirect3DSurface9
*pDestSurface
,
1540 const RECT
*pDestRect
,
1541 D3DTEXTUREFILTERTYPE Filter
)
1543 struct pipe_screen
*screen
= This
->screen
;
1544 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1545 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1546 struct pipe_resource
*dst_res
= NineSurface9_GetResource(dst
);
1547 struct pipe_resource
*src_res
= NineSurface9_GetResource(src
);
1549 struct pipe_blit_info blit
;
1550 boolean scaled
, clamped
, ms
, flip_x
= FALSE
, flip_y
= FALSE
;
1552 DBG("This=%p pSourceSurface=%p pSourceRect=%p pDestSurface=%p "
1553 "pDestRect=%p Filter=%u\n",
1554 This
, pSourceSurface
, pSourceRect
, pDestSurface
, pDestRect
, Filter
);
1556 DBG("pSourceRect=(%u,%u)-(%u,%u)\n",
1557 pSourceRect
->left
, pSourceRect
->top
,
1558 pSourceRect
->right
, pSourceRect
->bottom
);
1560 DBG("pDestRect=(%u,%u)-(%u,%u)\n", pDestRect
->left
, pDestRect
->top
,
1561 pDestRect
->right
, pDestRect
->bottom
);
1563 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
&&
1564 src
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1565 zs
= util_format_is_depth_or_stencil(dst_res
->format
);
1566 user_assert(!zs
|| !This
->in_scene
, D3DERR_INVALIDCALL
);
1567 user_assert(!zs
|| !pSourceRect
||
1568 (pSourceRect
->left
== 0 &&
1569 pSourceRect
->top
== 0 &&
1570 pSourceRect
->right
== src
->desc
.Width
&&
1571 pSourceRect
->bottom
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1572 user_assert(!zs
|| !pDestRect
||
1573 (pDestRect
->left
== 0 &&
1574 pDestRect
->top
== 0 &&
1575 pDestRect
->right
== dst
->desc
.Width
&&
1576 pDestRect
->bottom
== dst
->desc
.Height
), D3DERR_INVALIDCALL
);
1578 (dst
->desc
.Width
== src
->desc
.Width
&&
1579 dst
->desc
.Height
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1580 user_assert(zs
|| !util_format_is_depth_or_stencil(src_res
->format
),
1581 D3DERR_INVALIDCALL
);
1582 user_assert(!zs
|| dst
->desc
.Format
== src
->desc
.Format
,
1583 D3DERR_INVALIDCALL
);
1584 user_assert(screen
->is_format_supported(screen
, src_res
->format
,
1586 src_res
->nr_samples
,
1587 PIPE_BIND_SAMPLER_VIEW
),
1588 D3DERR_INVALIDCALL
);
1590 /* We might want to permit these, but wine thinks we shouldn't. */
1591 user_assert(!pDestRect
||
1592 (pDestRect
->left
<= pDestRect
->right
&&
1593 pDestRect
->top
<= pDestRect
->bottom
), D3DERR_INVALIDCALL
);
1594 user_assert(!pSourceRect
||
1595 (pSourceRect
->left
<= pSourceRect
->right
&&
1596 pSourceRect
->top
<= pSourceRect
->bottom
), D3DERR_INVALIDCALL
);
1598 memset(&blit
, 0, sizeof(blit
));
1599 blit
.dst
.resource
= dst_res
;
1600 blit
.dst
.level
= dst
->level
;
1601 blit
.dst
.box
.z
= dst
->layer
;
1602 blit
.dst
.box
.depth
= 1;
1603 blit
.dst
.format
= dst_res
->format
;
1605 flip_x
= pDestRect
->left
> pDestRect
->right
;
1607 blit
.dst
.box
.x
= pDestRect
->right
;
1608 blit
.dst
.box
.width
= pDestRect
->left
- pDestRect
->right
;
1610 blit
.dst
.box
.x
= pDestRect
->left
;
1611 blit
.dst
.box
.width
= pDestRect
->right
- pDestRect
->left
;
1613 flip_y
= pDestRect
->top
> pDestRect
->bottom
;
1615 blit
.dst
.box
.y
= pDestRect
->bottom
;
1616 blit
.dst
.box
.height
= pDestRect
->top
- pDestRect
->bottom
;
1618 blit
.dst
.box
.y
= pDestRect
->top
;
1619 blit
.dst
.box
.height
= pDestRect
->bottom
- pDestRect
->top
;
1624 blit
.dst
.box
.width
= dst
->desc
.Width
;
1625 blit
.dst
.box
.height
= dst
->desc
.Height
;
1627 blit
.src
.resource
= src_res
;
1628 blit
.src
.level
= src
->level
;
1629 blit
.src
.box
.z
= src
->layer
;
1630 blit
.src
.box
.depth
= 1;
1631 blit
.src
.format
= src_res
->format
;
1633 if (flip_x
^ (pSourceRect
->left
> pSourceRect
->right
)) {
1634 blit
.src
.box
.x
= pSourceRect
->right
;
1635 blit
.src
.box
.width
= pSourceRect
->left
- pSourceRect
->right
;
1637 blit
.src
.box
.x
= pSourceRect
->left
;
1638 blit
.src
.box
.width
= pSourceRect
->right
- pSourceRect
->left
;
1640 if (flip_y
^ (pSourceRect
->top
> pSourceRect
->bottom
)) {
1641 blit
.src
.box
.y
= pSourceRect
->bottom
;
1642 blit
.src
.box
.height
= pSourceRect
->top
- pSourceRect
->bottom
;
1644 blit
.src
.box
.y
= pSourceRect
->top
;
1645 blit
.src
.box
.height
= pSourceRect
->bottom
- pSourceRect
->top
;
1648 blit
.src
.box
.x
= flip_x
? src
->desc
.Width
: 0;
1649 blit
.src
.box
.y
= flip_y
? src
->desc
.Height
: 0;
1650 blit
.src
.box
.width
= flip_x
? -src
->desc
.Width
: src
->desc
.Width
;
1651 blit
.src
.box
.height
= flip_y
? -src
->desc
.Height
: src
->desc
.Height
;
1653 blit
.mask
= zs
? PIPE_MASK_ZS
: PIPE_MASK_RGBA
;
1654 blit
.filter
= Filter
== D3DTEXF_LINEAR
?
1655 PIPE_TEX_FILTER_LINEAR
: PIPE_TEX_FILTER_NEAREST
;
1656 blit
.scissor_enable
= FALSE
;
1657 blit
.alpha_blend
= FALSE
;
1659 /* If both of a src and dst dimension are negative, flip them. */
1660 if (blit
.dst
.box
.width
< 0 && blit
.src
.box
.width
< 0) {
1661 blit
.dst
.box
.width
= -blit
.dst
.box
.width
;
1662 blit
.src
.box
.width
= -blit
.src
.box
.width
;
1664 if (blit
.dst
.box
.height
< 0 && blit
.src
.box
.height
< 0) {
1665 blit
.dst
.box
.height
= -blit
.dst
.box
.height
;
1666 blit
.src
.box
.height
= -blit
.src
.box
.height
;
1669 blit
.dst
.box
.width
!= blit
.src
.box
.width
||
1670 blit
.dst
.box
.height
!= blit
.src
.box
.height
;
1672 user_assert(!scaled
|| dst
!= src
, D3DERR_INVALIDCALL
);
1673 user_assert(!scaled
||
1674 !NineSurface9_IsOffscreenPlain(dst
), D3DERR_INVALIDCALL
);
1675 user_assert(!NineSurface9_IsOffscreenPlain(dst
) ||
1676 NineSurface9_IsOffscreenPlain(src
), D3DERR_INVALIDCALL
);
1677 user_assert(NineSurface9_IsOffscreenPlain(dst
) ||
1678 dst
->desc
.Usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
),
1679 D3DERR_INVALIDCALL
);
1680 user_assert(!scaled
||
1681 (!util_format_is_compressed(dst
->base
.info
.format
) &&
1682 !util_format_is_compressed(src
->base
.info
.format
)),
1683 D3DERR_INVALIDCALL
);
1685 user_warn(src
== dst
&&
1686 u_box_test_intersection_2d(&blit
.src
.box
, &blit
.dst
.box
));
1688 /* Check for clipping/clamping: */
1690 struct pipe_box box
;
1693 xy
= u_box_clip_2d(&box
, &blit
.dst
.box
,
1694 dst
->desc
.Width
, dst
->desc
.Height
);
1698 xy
= u_box_clip_2d(&box
, &blit
.src
.box
,
1699 src
->desc
.Width
, src
->desc
.Height
);
1703 ms
= (dst
->desc
.MultiSampleType
!= src
->desc
.MultiSampleType
) ||
1704 (dst
->desc
.MultiSampleQuality
!= src
->desc
.MultiSampleQuality
);
1706 if (clamped
|| scaled
|| (blit
.dst
.format
!= blit
.src
.format
) || ms
) {
1707 DBG("using pipe->blit()\n");
1708 /* TODO: software scaling */
1709 user_assert(screen
->is_format_supported(screen
, dst_res
->format
,
1711 dst_res
->nr_samples
,
1712 zs
? PIPE_BIND_DEPTH_STENCIL
:
1713 PIPE_BIND_RENDER_TARGET
),
1714 D3DERR_INVALIDCALL
);
1716 nine_context_blit(This
, (struct NineUnknown
*)dst
,
1717 (struct NineUnknown
*)src
, &blit
);
1719 assert(blit
.dst
.box
.x
>= 0 && blit
.dst
.box
.y
>= 0 &&
1720 blit
.src
.box
.x
>= 0 && blit
.src
.box
.y
>= 0 &&
1721 blit
.dst
.box
.x
+ blit
.dst
.box
.width
<= dst
->desc
.Width
&&
1722 blit
.src
.box
.x
+ blit
.src
.box
.width
<= src
->desc
.Width
&&
1723 blit
.dst
.box
.y
+ blit
.dst
.box
.height
<= dst
->desc
.Height
&&
1724 blit
.src
.box
.y
+ blit
.src
.box
.height
<= src
->desc
.Height
);
1725 /* Or drivers might crash ... */
1726 DBG("Using resource_copy_region.\n");
1727 nine_context_resource_copy_region(This
, (struct NineUnknown
*)dst
,
1728 (struct NineUnknown
*)src
,
1729 blit
.dst
.resource
, blit
.dst
.level
,
1731 blit
.src
.resource
, blit
.src
.level
,
1735 /* Communicate the container it needs to update sublevels - if apply */
1736 NineSurface9_MarkContainerDirty(dst
);
1742 NineDevice9_ColorFill( struct NineDevice9
*This
,
1743 IDirect3DSurface9
*pSurface
,
1747 struct NineSurface9
*surf
= NineSurface9(pSurface
);
1748 unsigned x
, y
, w
, h
;
1750 DBG("This=%p pSurface=%p pRect=%p color=%08x\n", This
,
1751 pSurface
, pRect
, color
);
1753 DBG("pRect=(%u,%u)-(%u,%u)\n", pRect
->left
, pRect
->top
,
1754 pRect
->right
, pRect
->bottom
);
1756 user_assert(surf
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1758 user_assert((surf
->base
.usage
& D3DUSAGE_RENDERTARGET
) ||
1759 NineSurface9_IsOffscreenPlain(surf
), D3DERR_INVALIDCALL
);
1761 user_assert(surf
->desc
.Format
!= D3DFMT_NULL
, D3D_OK
);
1766 w
= pRect
->right
- pRect
->left
;
1767 h
= pRect
->bottom
- pRect
->top
;
1769 if (compressed_format(surf
->desc
.Format
)) {
1770 const unsigned bw
= util_format_get_blockwidth(surf
->base
.info
.format
);
1771 const unsigned bh
= util_format_get_blockheight(surf
->base
.info
.format
);
1773 user_assert(!(x
% bw
) && !(y
% bh
) && !(w
% bw
) && !(h
% bh
),
1774 D3DERR_INVALIDCALL
);
1779 w
= surf
->desc
.Width
;
1780 h
= surf
->desc
.Height
;
1783 if (surf
->base
.info
.bind
& PIPE_BIND_RENDER_TARGET
) {
1784 nine_context_clear_render_target(This
, surf
, color
, x
, y
, w
, h
);
1786 D3DLOCKED_RECT lock
;
1787 union util_color uc
;
1789 /* XXX: lock pRect and fix util_fill_rect */
1790 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, pRect
? 0 : D3DLOCK_DISCARD
);
1793 util_pack_color_ub(color
>> 16, color
>> 8, color
>> 0, color
>> 24,
1794 surf
->base
.info
.format
, &uc
);
1795 util_fill_rect(lock
.pBits
, surf
->base
.info
.format
,lock
.Pitch
,
1797 NineSurface9_UnlockRect(surf
);
1804 NineDevice9_CreateOffscreenPlainSurface( struct NineDevice9
*This
,
1809 IDirect3DSurface9
**ppSurface
,
1810 HANDLE
*pSharedHandle
)
1814 DBG("This=%p Width=%u Height=%u Format=%s(0x%x) Pool=%u "
1815 "ppSurface=%p pSharedHandle=%p\n", This
,
1816 Width
, Height
, d3dformat_to_string(Format
), Format
, Pool
,
1817 ppSurface
, pSharedHandle
);
1820 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
1821 || Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1822 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1824 /* Can be used with StretchRect and ColorFill. It's also always lockable.
1826 hr
= create_zs_or_rt_surface(This
, 2, Pool
, Width
, Height
,
1828 D3DMULTISAMPLE_NONE
, 0,
1830 ppSurface
, pSharedHandle
);
1832 DBG("Failed to create surface.\n");
1837 NineDevice9_SetRenderTarget( struct NineDevice9
*This
,
1838 DWORD RenderTargetIndex
,
1839 IDirect3DSurface9
*pRenderTarget
)
1841 struct NineSurface9
*rt
= NineSurface9(pRenderTarget
);
1842 const unsigned i
= RenderTargetIndex
;
1844 DBG("This=%p RenderTargetIndex=%u pRenderTarget=%p\n", This
,
1845 RenderTargetIndex
, pRenderTarget
);
1847 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1848 user_assert(i
!= 0 || pRenderTarget
, D3DERR_INVALIDCALL
);
1849 user_assert(!pRenderTarget
||
1850 rt
->desc
.Usage
& D3DUSAGE_RENDERTARGET
, D3DERR_INVALIDCALL
);
1853 This
->state
.viewport
.X
= 0;
1854 This
->state
.viewport
.Y
= 0;
1855 This
->state
.viewport
.Width
= rt
->desc
.Width
;
1856 This
->state
.viewport
.Height
= rt
->desc
.Height
;
1857 This
->state
.viewport
.MinZ
= 0.0f
;
1858 This
->state
.viewport
.MaxZ
= 1.0f
;
1860 This
->state
.scissor
.minx
= 0;
1861 This
->state
.scissor
.miny
= 0;
1862 This
->state
.scissor
.maxx
= rt
->desc
.Width
;
1863 This
->state
.scissor
.maxy
= rt
->desc
.Height
;
1866 if (This
->state
.rt
[i
] != NineSurface9(pRenderTarget
))
1867 nine_bind(&This
->state
.rt
[i
], pRenderTarget
);
1869 nine_context_set_render_target(This
, i
, rt
);
1874 NineDevice9_GetRenderTarget( struct NineDevice9
*This
,
1875 DWORD RenderTargetIndex
,
1876 IDirect3DSurface9
**ppRenderTarget
)
1878 const unsigned i
= RenderTargetIndex
;
1880 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1881 user_assert(ppRenderTarget
, D3DERR_INVALIDCALL
);
1883 *ppRenderTarget
= (IDirect3DSurface9
*)This
->state
.rt
[i
];
1884 if (!This
->state
.rt
[i
])
1885 return D3DERR_NOTFOUND
;
1887 NineUnknown_AddRef(NineUnknown(This
->state
.rt
[i
]));
1892 NineDevice9_SetDepthStencilSurface( struct NineDevice9
*This
,
1893 IDirect3DSurface9
*pNewZStencil
)
1895 struct NineSurface9
*ds
= NineSurface9(pNewZStencil
);
1896 DBG("This=%p pNewZStencil=%p\n", This
, pNewZStencil
);
1898 if (This
->state
.ds
!= ds
) {
1899 nine_bind(&This
->state
.ds
, ds
);
1900 nine_context_set_depth_stencil(This
, ds
);
1906 NineDevice9_GetDepthStencilSurface( struct NineDevice9
*This
,
1907 IDirect3DSurface9
**ppZStencilSurface
)
1909 user_assert(ppZStencilSurface
, D3DERR_INVALIDCALL
);
1911 *ppZStencilSurface
= (IDirect3DSurface9
*)This
->state
.ds
;
1912 if (!This
->state
.ds
)
1913 return D3DERR_NOTFOUND
;
1915 NineUnknown_AddRef(NineUnknown(This
->state
.ds
));
1920 NineDevice9_BeginScene( struct NineDevice9
*This
)
1922 DBG("This=%p\n", This
);
1923 user_assert(!This
->in_scene
, D3DERR_INVALIDCALL
);
1924 This
->in_scene
= TRUE
;
1925 /* Do we want to do anything else here ? */
1930 NineDevice9_EndScene( struct NineDevice9
*This
)
1932 DBG("This=%p\n", This
);
1933 user_assert(This
->in_scene
, D3DERR_INVALIDCALL
);
1934 This
->in_scene
= FALSE
;
1939 NineDevice9_Clear( struct NineDevice9
*This
,
1941 const D3DRECT
*pRects
,
1947 struct NineSurface9
*zsbuf_surf
= This
->state
.ds
;
1949 DBG("This=%p Count=%u pRects=%p Flags=%x Color=%08x Z=%f Stencil=%x\n",
1950 This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1952 user_assert(This
->state
.ds
|| !(Flags
& NINED3DCLEAR_DEPTHSTENCIL
),
1953 D3DERR_INVALIDCALL
);
1954 user_assert(!(Flags
& D3DCLEAR_STENCIL
) ||
1956 util_format_is_depth_and_stencil(zsbuf_surf
->base
.info
.format
)),
1957 D3DERR_INVALIDCALL
);
1959 user_assert((Count
&& pRects
) || (!Count
&& !pRects
), D3DERR_INVALIDCALL
);
1961 user_warn((pRects
&& !Count
) || (!pRects
&& Count
));
1962 if (pRects
&& !Count
)
1968 nine_context_clear_fb(This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1973 NineDevice9_SetTransform( struct NineDevice9
*This
,
1974 D3DTRANSFORMSTATETYPE State
,
1975 const D3DMATRIX
*pMatrix
)
1977 struct nine_state
*state
= This
->update
;
1978 D3DMATRIX
*M
= nine_state_access_transform(&state
->ff
, State
, TRUE
);
1980 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
1982 user_assert(M
, D3DERR_INVALIDCALL
);
1985 if (unlikely(This
->is_recording
)) {
1986 state
->ff
.changed
.transform
[State
/ 32] |= 1 << (State
% 32);
1987 state
->changed
.group
|= NINE_STATE_FF
;
1989 nine_context_set_transform(This
, State
, pMatrix
);
1995 NineDevice9_GetTransform( struct NineDevice9
*This
,
1996 D3DTRANSFORMSTATETYPE State
,
1997 D3DMATRIX
*pMatrix
)
1999 D3DMATRIX
*M
= nine_state_access_transform(&This
->state
.ff
, State
, FALSE
);
2000 user_assert(M
, D3DERR_INVALIDCALL
);
2006 NineDevice9_MultiplyTransform( struct NineDevice9
*This
,
2007 D3DTRANSFORMSTATETYPE State
,
2008 const D3DMATRIX
*pMatrix
)
2010 struct nine_state
*state
= This
->update
;
2012 D3DMATRIX
*M
= nine_state_access_transform(&state
->ff
, State
, TRUE
);
2014 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2016 user_assert(M
, D3DERR_INVALIDCALL
);
2018 nine_d3d_matrix_matrix_mul(&T
, pMatrix
, M
);
2019 return NineDevice9_SetTransform(This
, State
, &T
);
2023 NineDevice9_SetViewport( struct NineDevice9
*This
,
2024 const D3DVIEWPORT9
*pViewport
)
2026 struct nine_state
*state
= This
->update
;
2028 DBG("X=%u Y=%u W=%u H=%u MinZ=%f MaxZ=%f\n",
2029 pViewport
->X
, pViewport
->Y
, pViewport
->Width
, pViewport
->Height
,
2030 pViewport
->MinZ
, pViewport
->MaxZ
);
2032 state
->viewport
= *pViewport
;
2033 nine_context_set_viewport(This
, pViewport
);
2039 NineDevice9_GetViewport( struct NineDevice9
*This
,
2040 D3DVIEWPORT9
*pViewport
)
2042 *pViewport
= This
->state
.viewport
;
2047 NineDevice9_SetMaterial( struct NineDevice9
*This
,
2048 const D3DMATERIAL9
*pMaterial
)
2050 struct nine_state
*state
= This
->update
;
2052 DBG("This=%p pMaterial=%p\n", This
, pMaterial
);
2054 nine_dump_D3DMATERIAL9(DBG_FF
, pMaterial
);
2056 user_assert(pMaterial
, E_POINTER
);
2058 state
->ff
.material
= *pMaterial
;
2059 if (unlikely(This
->is_recording
))
2060 state
->changed
.group
|= NINE_STATE_FF_MATERIAL
;
2062 nine_context_set_material(This
, pMaterial
);
2068 NineDevice9_GetMaterial( struct NineDevice9
*This
,
2069 D3DMATERIAL9
*pMaterial
)
2071 user_assert(pMaterial
, E_POINTER
);
2072 *pMaterial
= This
->state
.ff
.material
;
2077 NineDevice9_SetLight( struct NineDevice9
*This
,
2079 const D3DLIGHT9
*pLight
)
2081 struct nine_state
*state
= This
->update
;
2084 DBG("This=%p Index=%u pLight=%p\n", This
, Index
, pLight
);
2086 nine_dump_D3DLIGHT9(DBG_FF
, pLight
);
2088 user_assert(pLight
, D3DERR_INVALIDCALL
);
2089 user_assert(pLight
->Type
< NINED3DLIGHT_INVALID
, D3DERR_INVALIDCALL
);
2091 user_assert(Index
< NINE_MAX_LIGHTS
, D3DERR_INVALIDCALL
); /* sanity */
2093 hr
= nine_state_set_light(&state
->ff
, Index
, pLight
);
2097 if (pLight
->Type
!= D3DLIGHT_DIRECTIONAL
&&
2098 pLight
->Attenuation0
== 0.0f
&&
2099 pLight
->Attenuation1
== 0.0f
&&
2100 pLight
->Attenuation2
== 0.0f
) {
2101 DBG("Warning: all D3DLIGHT9.Attenuation[i] are 0\n");
2104 if (unlikely(This
->is_recording
))
2105 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2107 nine_context_set_light(This
, Index
, pLight
);
2113 NineDevice9_GetLight( struct NineDevice9
*This
,
2117 const struct nine_state
*state
= &This
->state
;
2119 user_assert(pLight
, D3DERR_INVALIDCALL
);
2120 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2121 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2122 D3DERR_INVALIDCALL
);
2124 *pLight
= state
->ff
.light
[Index
];
2130 NineDevice9_LightEnable( struct NineDevice9
*This
,
2134 struct nine_state
*state
= This
->update
;
2136 DBG("This=%p Index=%u Enable=%i\n", This
, Index
, Enable
);
2138 if (Index
>= state
->ff
.num_lights
||
2139 state
->ff
.light
[Index
].Type
== NINED3DLIGHT_INVALID
) {
2140 /* This should create a default light. */
2142 memset(&light
, 0, sizeof(light
));
2143 light
.Type
= D3DLIGHT_DIRECTIONAL
;
2144 light
.Diffuse
.r
= 1.0f
;
2145 light
.Diffuse
.g
= 1.0f
;
2146 light
.Diffuse
.b
= 1.0f
;
2147 light
.Direction
.z
= 1.0f
;
2148 NineDevice9_SetLight(This
, Index
, &light
);
2151 nine_state_light_enable(&state
->ff
, &state
->changed
.group
, Index
, Enable
);
2152 if (likely(!This
->is_recording
))
2153 nine_context_light_enable(This
, Index
, Enable
);
2159 NineDevice9_GetLightEnable( struct NineDevice9
*This
,
2163 const struct nine_state
*state
= &This
->state
;
2166 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2167 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2168 D3DERR_INVALIDCALL
);
2170 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
)
2171 if (state
->ff
.active_light
[i
] == Index
)
2174 *pEnable
= i
!= state
->ff
.num_lights_active
? 128 : 0; // Taken from wine
2180 NineDevice9_SetClipPlane( struct NineDevice9
*This
,
2182 const float *pPlane
)
2184 struct nine_state
*state
= This
->update
;
2186 user_assert(pPlane
, D3DERR_INVALIDCALL
);
2188 DBG("This=%p Index=%u pPlane=%f %f %f %f\n", This
, Index
,
2189 pPlane
[0], pPlane
[1],
2190 pPlane
[2], pPlane
[3]);
2192 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2194 memcpy(&state
->clip
.ucp
[Index
][0], pPlane
, sizeof(state
->clip
.ucp
[0]));
2195 if (unlikely(This
->is_recording
))
2196 state
->changed
.ucp
|= 1 << Index
;
2198 nine_context_set_clip_plane(This
, Index
, (struct nine_clipplane
*)pPlane
);
2204 NineDevice9_GetClipPlane( struct NineDevice9
*This
,
2208 const struct nine_state
*state
= &This
->state
;
2210 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2212 memcpy(pPlane
, &state
->clip
.ucp
[Index
][0], sizeof(state
->clip
.ucp
[0]));
2217 NineDevice9_SetRenderState( struct NineDevice9
*This
,
2218 D3DRENDERSTATETYPE State
,
2221 struct nine_state
*state
= This
->update
;
2223 DBG("This=%p State=%u(%s) Value=%08x\n", This
,
2224 State
, nine_d3drs_to_string(State
), Value
);
2226 user_assert(State
< D3DRS_COUNT
, D3DERR_INVALIDCALL
);
2228 if (unlikely(This
->is_recording
)) {
2229 state
->rs_advertised
[State
] = Value
;
2230 /* only need to record changed render states for stateblocks */
2231 state
->changed
.rs
[State
/ 32] |= 1 << (State
% 32);
2232 state
->changed
.group
|= nine_render_state_group
[State
];
2236 if (state
->rs_advertised
[State
] == Value
)
2239 state
->rs_advertised
[State
] = Value
;
2240 nine_context_set_render_state(This
, State
, Value
);
2246 NineDevice9_GetRenderState( struct NineDevice9
*This
,
2247 D3DRENDERSTATETYPE State
,
2250 user_assert(State
< D3DRS_COUNT
, D3DERR_INVALIDCALL
);
2252 *pValue
= This
->state
.rs_advertised
[State
];
2257 NineDevice9_CreateStateBlock( struct NineDevice9
*This
,
2258 D3DSTATEBLOCKTYPE Type
,
2259 IDirect3DStateBlock9
**ppSB
)
2261 struct NineStateBlock9
*nsb
;
2262 struct nine_state
*dst
;
2264 enum nine_stateblock_type type
;
2267 DBG("This=%p Type=%u ppSB=%p\n", This
, Type
, ppSB
);
2269 user_assert(Type
== D3DSBT_ALL
||
2270 Type
== D3DSBT_VERTEXSTATE
||
2271 Type
== D3DSBT_PIXELSTATE
, D3DERR_INVALIDCALL
);
2274 case D3DSBT_VERTEXSTATE
: type
= NINESBT_VERTEXSTATE
; break;
2275 case D3DSBT_PIXELSTATE
: type
= NINESBT_PIXELSTATE
; break;
2281 hr
= NineStateBlock9_new(This
, &nsb
, type
);
2284 *ppSB
= (IDirect3DStateBlock9
*)nsb
;
2287 dst
->changed
.group
=
2288 NINE_STATE_TEXTURE
|
2291 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_VERTEXSTATE
) {
2292 dst
->changed
.group
|=
2293 NINE_STATE_FF_LIGHTING
|
2294 NINE_STATE_VS
| NINE_STATE_VS_CONST
|
2296 /* TODO: texture/sampler state */
2297 memcpy(dst
->changed
.rs
,
2298 nine_render_states_vertex
, sizeof(dst
->changed
.rs
));
2299 nine_ranges_insert(&dst
->changed
.vs_const_f
, 0, This
->may_swvp
? NINE_MAX_CONST_F_SWVP
: This
->max_vs_const_f
,
2301 nine_ranges_insert(&dst
->changed
.vs_const_i
, 0, This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
,
2303 nine_ranges_insert(&dst
->changed
.vs_const_b
, 0, This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
,
2305 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2306 dst
->changed
.sampler
[s
] |= 1 << D3DSAMP_DMAPOFFSET
;
2307 if (This
->state
.ff
.num_lights
) {
2308 dst
->ff
.num_lights
= This
->state
.ff
.num_lights
;
2309 /* zero'd -> light type won't be NINED3DLIGHT_INVALID, so
2310 * all currently existing lights will be captured
2312 dst
->ff
.light
= CALLOC(This
->state
.ff
.num_lights
,
2314 if (!dst
->ff
.light
) {
2315 nine_bind(ppSB
, NULL
);
2316 return E_OUTOFMEMORY
;
2320 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_PIXELSTATE
) {
2321 dst
->changed
.group
|=
2322 NINE_STATE_PS
| NINE_STATE_PS_CONST
| NINE_STATE_BLEND
|
2323 NINE_STATE_FF_OTHER
| NINE_STATE_FF_PSSTAGES
| NINE_STATE_PS_CONST
|
2324 NINE_STATE_FB
| NINE_STATE_DSA
| NINE_STATE_MULTISAMPLE
|
2325 NINE_STATE_RASTERIZER
| NINE_STATE_STENCIL_REF
;
2326 memcpy(dst
->changed
.rs
,
2327 nine_render_states_pixel
, sizeof(dst
->changed
.rs
));
2328 nine_ranges_insert(&dst
->changed
.ps_const_f
, 0, This
->max_ps_const_f
,
2330 dst
->changed
.ps_const_i
= 0xffff;
2331 dst
->changed
.ps_const_b
= 0xffff;
2332 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2333 dst
->changed
.sampler
[s
] |= 0x1ffe;
2334 for (s
= 0; s
< NINE_MAX_TEXTURE_STAGES
; ++s
) {
2335 dst
->ff
.changed
.tex_stage
[s
][0] |= 0xffffffff;
2336 dst
->ff
.changed
.tex_stage
[s
][1] |= 0xffffffff;
2339 if (Type
== D3DSBT_ALL
) {
2340 dst
->changed
.group
|=
2341 NINE_STATE_VIEWPORT
|
2342 NINE_STATE_SCISSOR
|
2343 NINE_STATE_RASTERIZER
|
2347 NINE_STATE_MATERIAL
|
2348 NINE_STATE_BLEND_COLOR
|
2349 NINE_STATE_SAMPLE_MASK
;
2350 memset(dst
->changed
.rs
, ~0, (D3DRS_COUNT
/ 32) * sizeof(uint32_t));
2351 dst
->changed
.rs
[D3DRS_LAST
/ 32] |= (1 << (D3DRS_COUNT
% 32)) - 1;
2352 dst
->changed
.vtxbuf
= (1ULL << This
->caps
.MaxStreams
) - 1;
2353 dst
->changed
.stream_freq
= dst
->changed
.vtxbuf
;
2354 dst
->changed
.ucp
= (1 << PIPE_MAX_CLIP_PLANES
) - 1;
2355 dst
->changed
.texture
= (1 << NINE_MAX_SAMPLERS
) - 1;
2357 NineStateBlock9_Capture(NineStateBlock9(*ppSB
));
2359 /* TODO: fixed function state */
2365 NineDevice9_BeginStateBlock( struct NineDevice9
*This
)
2369 DBG("This=%p\n", This
);
2371 user_assert(!This
->record
, D3DERR_INVALIDCALL
);
2373 hr
= NineStateBlock9_new(This
, &This
->record
, NINESBT_CUSTOM
);
2376 NineUnknown_ConvertRefToBind(NineUnknown(This
->record
));
2378 This
->update
= &This
->record
->state
;
2379 This
->is_recording
= TRUE
;
2385 NineDevice9_EndStateBlock( struct NineDevice9
*This
,
2386 IDirect3DStateBlock9
**ppSB
)
2388 DBG("This=%p ppSB=%p\n", This
, ppSB
);
2390 user_assert(This
->record
, D3DERR_INVALIDCALL
);
2392 This
->update
= &This
->state
;
2393 This
->is_recording
= FALSE
;
2395 NineUnknown_AddRef(NineUnknown(This
->record
));
2396 *ppSB
= (IDirect3DStateBlock9
*)This
->record
;
2397 NineUnknown_Unbind(NineUnknown(This
->record
));
2398 This
->record
= NULL
;
2404 NineDevice9_SetClipStatus( struct NineDevice9
*This
,
2405 const D3DCLIPSTATUS9
*pClipStatus
)
2407 STUB(D3DERR_INVALIDCALL
);
2411 NineDevice9_GetClipStatus( struct NineDevice9
*This
,
2412 D3DCLIPSTATUS9
*pClipStatus
)
2414 STUB(D3DERR_INVALIDCALL
);
2418 NineDevice9_GetTexture( struct NineDevice9
*This
,
2420 IDirect3DBaseTexture9
**ppTexture
)
2422 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2423 Stage
== D3DDMAPSAMPLER
||
2424 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2425 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2426 user_assert(ppTexture
, D3DERR_INVALIDCALL
);
2428 if (Stage
>= D3DDMAPSAMPLER
)
2429 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2431 *ppTexture
= (IDirect3DBaseTexture9
*)This
->state
.texture
[Stage
];
2433 if (This
->state
.texture
[Stage
])
2434 NineUnknown_AddRef(NineUnknown(This
->state
.texture
[Stage
]));
2439 NineDevice9_SetTexture( struct NineDevice9
*This
,
2441 IDirect3DBaseTexture9
*pTexture
)
2443 struct nine_state
*state
= This
->update
;
2444 struct NineBaseTexture9
*tex
= NineBaseTexture9(pTexture
);
2445 struct NineBaseTexture9
*old
;
2447 DBG("This=%p Stage=%u pTexture=%p\n", This
, Stage
, pTexture
);
2449 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2450 Stage
== D3DDMAPSAMPLER
||
2451 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2452 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2453 user_assert(!tex
|| (tex
->base
.pool
!= D3DPOOL_SCRATCH
&&
2454 tex
->base
.pool
!= D3DPOOL_SYSTEMMEM
), D3DERR_INVALIDCALL
);
2456 if (Stage
>= D3DDMAPSAMPLER
)
2457 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2459 if (This
->is_recording
) {
2460 state
->changed
.texture
|= 1 << Stage
;
2461 state
->changed
.group
|= NINE_STATE_TEXTURE
;
2462 nine_bind(&state
->texture
[Stage
], pTexture
);
2466 old
= state
->texture
[Stage
];
2470 NineBindTextureToDevice(This
, &state
->texture
[Stage
], tex
);
2472 nine_context_set_texture(This
, Stage
, tex
);
2478 NineDevice9_GetTextureStageState( struct NineDevice9
*This
,
2480 D3DTEXTURESTAGESTATETYPE Type
,
2483 const struct nine_state
*state
= &This
->state
;
2485 user_assert(Stage
< ARRAY_SIZE(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2486 user_assert(Type
< ARRAY_SIZE(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2488 *pValue
= state
->ff
.tex_stage
[Stage
][Type
];
2494 NineDevice9_SetTextureStageState( struct NineDevice9
*This
,
2496 D3DTEXTURESTAGESTATETYPE Type
,
2499 struct nine_state
*state
= This
->update
;
2501 DBG("Stage=%u Type=%u Value=%08x\n", Stage
, Type
, Value
);
2502 nine_dump_D3DTSS_value(DBG_FF
, Type
, Value
);
2504 user_assert(Stage
< ARRAY_SIZE(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2505 user_assert(Type
< ARRAY_SIZE(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2507 state
->ff
.tex_stage
[Stage
][Type
] = Value
;
2509 if (unlikely(This
->is_recording
)) {
2510 if (Type
== D3DTSS_TEXTURETRANSFORMFLAGS
)
2511 state
->changed
.group
|= NINE_STATE_PS1X_SHADER
;
2512 state
->changed
.group
|= NINE_STATE_FF_PSSTAGES
;
2513 state
->ff
.changed
.tex_stage
[Stage
][Type
/ 32] |= 1 << (Type
% 32);
2515 nine_context_set_texture_stage_state(This
, Stage
, Type
, Value
);
2521 NineDevice9_GetSamplerState( struct NineDevice9
*This
,
2523 D3DSAMPLERSTATETYPE Type
,
2526 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2527 Sampler
== D3DDMAPSAMPLER
||
2528 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2529 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2531 if (Sampler
>= D3DDMAPSAMPLER
)
2532 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2534 *pValue
= This
->state
.samp_advertised
[Sampler
][Type
];
2539 NineDevice9_SetSamplerState( struct NineDevice9
*This
,
2541 D3DSAMPLERSTATETYPE Type
,
2544 struct nine_state
*state
= This
->update
;
2546 DBG("This=%p Sampler=%u Type=%s Value=%08x\n", This
,
2547 Sampler
, nine_D3DSAMP_to_str(Type
), Value
);
2549 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2550 Sampler
== D3DDMAPSAMPLER
||
2551 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2552 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2554 if (Sampler
>= D3DDMAPSAMPLER
)
2555 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2557 if (unlikely(This
->is_recording
)) {
2558 state
->samp_advertised
[Sampler
][Type
] = Value
;
2559 state
->changed
.group
|= NINE_STATE_SAMPLER
;
2560 state
->changed
.sampler
[Sampler
] |= 1 << Type
;
2564 if (state
->samp_advertised
[Sampler
][Type
] == Value
)
2567 state
->samp_advertised
[Sampler
][Type
] = Value
;
2568 nine_context_set_sampler_state(This
, Sampler
, Type
, Value
);
2574 NineDevice9_ValidateDevice( struct NineDevice9
*This
,
2577 const struct nine_state
*state
= &This
->state
;
2579 unsigned w
= 0, h
= 0;
2581 DBG("This=%p pNumPasses=%p\n", This
, pNumPasses
);
2583 for (i
= 0; i
< ARRAY_SIZE(state
->samp_advertised
); ++i
) {
2584 if (state
->samp_advertised
[i
][D3DSAMP_MINFILTER
] == D3DTEXF_NONE
||
2585 state
->samp_advertised
[i
][D3DSAMP_MAGFILTER
] == D3DTEXF_NONE
)
2586 return D3DERR_UNSUPPORTEDTEXTUREFILTER
;
2589 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2593 w
= state
->rt
[i
]->desc
.Width
;
2594 h
= state
->rt
[i
]->desc
.Height
;
2596 if (state
->rt
[i
]->desc
.Width
!= w
|| state
->rt
[i
]->desc
.Height
!= h
) {
2597 return D3DERR_CONFLICTINGRENDERSTATE
;
2601 (state
->rs_advertised
[D3DRS_ZENABLE
] || state
->rs_advertised
[D3DRS_STENCILENABLE
])) {
2603 (state
->ds
->desc
.Width
!= w
|| state
->ds
->desc
.Height
!= h
))
2604 return D3DERR_CONFLICTINGRENDERSTATE
;
2614 NineDevice9_SetPaletteEntries( struct NineDevice9
*This
,
2616 const PALETTEENTRY
*pEntries
)
2618 STUB(D3D_OK
); /* like wine */
2622 NineDevice9_GetPaletteEntries( struct NineDevice9
*This
,
2624 PALETTEENTRY
*pEntries
)
2626 STUB(D3DERR_INVALIDCALL
);
2630 NineDevice9_SetCurrentTexturePalette( struct NineDevice9
*This
,
2631 UINT PaletteNumber
)
2633 STUB(D3D_OK
); /* like wine */
2637 NineDevice9_GetCurrentTexturePalette( struct NineDevice9
*This
,
2638 UINT
*PaletteNumber
)
2640 STUB(D3DERR_INVALIDCALL
);
2644 NineDevice9_SetScissorRect( struct NineDevice9
*This
,
2647 struct nine_state
*state
= This
->update
;
2649 DBG("x=(%u..%u) y=(%u..%u)\n",
2650 pRect
->left
, pRect
->top
, pRect
->right
, pRect
->bottom
);
2652 state
->scissor
.minx
= pRect
->left
;
2653 state
->scissor
.miny
= pRect
->top
;
2654 state
->scissor
.maxx
= pRect
->right
;
2655 state
->scissor
.maxy
= pRect
->bottom
;
2657 if (unlikely(This
->is_recording
))
2658 state
->changed
.group
|= NINE_STATE_SCISSOR
;
2660 nine_context_set_scissor(This
, &state
->scissor
);
2666 NineDevice9_GetScissorRect( struct NineDevice9
*This
,
2669 pRect
->left
= This
->state
.scissor
.minx
;
2670 pRect
->top
= This
->state
.scissor
.miny
;
2671 pRect
->right
= This
->state
.scissor
.maxx
;
2672 pRect
->bottom
= This
->state
.scissor
.maxy
;
2678 NineDevice9_SetSoftwareVertexProcessing( struct NineDevice9
*This
,
2681 if (This
->params
.BehaviorFlags
& D3DCREATE_MIXED_VERTEXPROCESSING
) {
2682 This
->swvp
= bSoftware
;
2683 nine_context_set_swvp(This
, bSoftware
);
2686 return D3DERR_INVALIDCALL
; /* msdn. TODO: check in practice */
2690 NineDevice9_GetSoftwareVertexProcessing( struct NineDevice9
*This
)
2696 NineDevice9_SetNPatchMode( struct NineDevice9
*This
,
2699 return D3D_OK
; /* Nothing to do because we don't advertise NPatch support */
2703 NineDevice9_GetNPatchMode( struct NineDevice9
*This
)
2708 /* TODO: only go through dirty textures */
2710 validate_textures(struct NineDevice9
*device
)
2712 struct NineBaseTexture9
*tex
, *ptr
;
2713 LIST_FOR_EACH_ENTRY_SAFE(tex
, ptr
, &device
->update_textures
, list
) {
2714 list_delinit(&tex
->list
);
2715 NineBaseTexture9_Validate(tex
);
2720 update_managed_buffers(struct NineDevice9
*device
)
2722 struct NineBuffer9
*buf
, *ptr
;
2723 LIST_FOR_EACH_ENTRY_SAFE(buf
, ptr
, &device
->update_buffers
, managed
.list
) {
2724 list_delinit(&buf
->managed
.list
);
2725 NineBuffer9_Upload(buf
);
2730 NineBeforeDraw( struct NineDevice9
*This
)
2732 /* Upload Managed dirty content */
2733 validate_textures(This
); /* may clobber state */
2734 update_managed_buffers(This
);
2738 NineAfterDraw( struct NineDevice9
*This
)
2741 struct nine_state
*state
= &This
->state
;
2742 unsigned ps_mask
= state
->ps
? state
->ps
->rt_mask
: 1;
2744 /* Flag render-targets with autogenmipmap for mipmap regeneration */
2745 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2746 struct NineSurface9
*rt
= state
->rt
[i
];
2748 if (rt
&& rt
->desc
.Format
!= D3DFMT_NULL
&& (ps_mask
& (1 << i
)) &&
2749 rt
->desc
.Usage
& D3DUSAGE_AUTOGENMIPMAP
) {
2750 assert(rt
->texture
== D3DRTYPE_TEXTURE
||
2751 rt
->texture
== D3DRTYPE_CUBETEXTURE
);
2752 NineBaseTexture9(rt
->base
.base
.container
)->dirty_mip
= TRUE
;
2758 NineDevice9_DrawPrimitive( struct NineDevice9
*This
,
2759 D3DPRIMITIVETYPE PrimitiveType
,
2761 UINT PrimitiveCount
)
2763 DBG("iface %p, PrimitiveType %u, StartVertex %u, PrimitiveCount %u\n",
2764 This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2766 NineBeforeDraw(This
);
2767 nine_context_draw_primitive(This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2768 NineAfterDraw(This
);
2774 NineDevice9_DrawIndexedPrimitive( struct NineDevice9
*This
,
2775 D3DPRIMITIVETYPE PrimitiveType
,
2776 INT BaseVertexIndex
,
2777 UINT MinVertexIndex
,
2780 UINT PrimitiveCount
)
2782 DBG("iface %p, PrimitiveType %u, BaseVertexIndex %u, MinVertexIndex %u "
2783 "NumVertices %u, StartIndex %u, PrimitiveCount %u\n",
2784 This
, PrimitiveType
, BaseVertexIndex
, MinVertexIndex
, NumVertices
,
2785 StartIndex
, PrimitiveCount
);
2787 user_assert(This
->state
.idxbuf
, D3DERR_INVALIDCALL
);
2788 user_assert(This
->state
.vdecl
, D3DERR_INVALIDCALL
);
2790 NineBeforeDraw(This
);
2791 nine_context_draw_indexed_primitive(This
, PrimitiveType
, BaseVertexIndex
,
2792 MinVertexIndex
, NumVertices
, StartIndex
,
2794 NineAfterDraw(This
);
2800 NineDevice9_DrawPrimitiveUP( struct NineDevice9
*This
,
2801 D3DPRIMITIVETYPE PrimitiveType
,
2802 UINT PrimitiveCount
,
2803 const void *pVertexStreamZeroData
,
2804 UINT VertexStreamZeroStride
)
2806 struct pipe_vertex_buffer vtxbuf
;
2808 DBG("iface %p, PrimitiveType %u, PrimitiveCount %u, data %p, stride %u\n",
2809 This
, PrimitiveType
, PrimitiveCount
,
2810 pVertexStreamZeroData
, VertexStreamZeroStride
);
2812 user_assert(pVertexStreamZeroData
&& VertexStreamZeroStride
,
2813 D3DERR_INVALIDCALL
);
2814 user_assert(PrimitiveCount
, D3D_OK
);
2816 vtxbuf
.stride
= VertexStreamZeroStride
;
2817 vtxbuf
.buffer_offset
= 0;
2818 vtxbuf
.is_user_buffer
= true;
2819 vtxbuf
.buffer
.user
= pVertexStreamZeroData
;
2821 if (!This
->driver_caps
.user_vbufs
) {
2822 vtxbuf
.is_user_buffer
= false;
2823 vtxbuf
.buffer
.resource
= NULL
;
2824 u_upload_data(This
->vertex_uploader
,
2826 (prim_count_to_vertex_count(PrimitiveType
, PrimitiveCount
)) * VertexStreamZeroStride
, /* XXX */
2828 pVertexStreamZeroData
,
2829 &vtxbuf
.buffer_offset
,
2830 &vtxbuf
.buffer
.resource
);
2831 u_upload_unmap(This
->vertex_uploader
);
2834 NineBeforeDraw(This
);
2835 nine_context_draw_primitive_from_vtxbuf(This
, PrimitiveType
, PrimitiveCount
, &vtxbuf
);
2836 NineAfterDraw(This
);
2838 pipe_vertex_buffer_unreference(&vtxbuf
);
2840 NineDevice9_PauseRecording(This
);
2841 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
2842 NineDevice9_ResumeRecording(This
);
2848 NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9
*This
,
2849 D3DPRIMITIVETYPE PrimitiveType
,
2850 UINT MinVertexIndex
,
2852 UINT PrimitiveCount
,
2853 const void *pIndexData
,
2854 D3DFORMAT IndexDataFormat
,
2855 const void *pVertexStreamZeroData
,
2856 UINT VertexStreamZeroStride
)
2858 struct pipe_vertex_buffer vbuf
;
2860 DBG("iface %p, PrimitiveType %u, MinVertexIndex %u, NumVertices %u "
2861 "PrimitiveCount %u, pIndexData %p, IndexDataFormat %u "
2862 "pVertexStreamZeroData %p, VertexStreamZeroStride %u\n",
2863 This
, PrimitiveType
, MinVertexIndex
, NumVertices
, PrimitiveCount
,
2864 pIndexData
, IndexDataFormat
,
2865 pVertexStreamZeroData
, VertexStreamZeroStride
);
2867 user_assert(pIndexData
&& pVertexStreamZeroData
, D3DERR_INVALIDCALL
);
2868 user_assert(VertexStreamZeroStride
, D3DERR_INVALIDCALL
);
2869 user_assert(IndexDataFormat
== D3DFMT_INDEX16
||
2870 IndexDataFormat
== D3DFMT_INDEX32
, D3DERR_INVALIDCALL
);
2871 user_assert(PrimitiveCount
, D3D_OK
);
2873 vbuf
.stride
= VertexStreamZeroStride
;
2874 vbuf
.buffer_offset
= 0;
2875 vbuf
.is_user_buffer
= true;
2876 vbuf
.buffer
.user
= pVertexStreamZeroData
;
2878 unsigned index_size
= (IndexDataFormat
== D3DFMT_INDEX16
) ? 2 : 4;
2879 struct pipe_resource
*ibuf
= NULL
;
2881 if (!This
->driver_caps
.user_vbufs
) {
2882 const unsigned base
= MinVertexIndex
* VertexStreamZeroStride
;
2883 vbuf
.is_user_buffer
= false;
2884 vbuf
.buffer
.resource
= NULL
;
2885 u_upload_data(This
->vertex_uploader
,
2887 NumVertices
* VertexStreamZeroStride
, /* XXX */
2889 (const uint8_t *)pVertexStreamZeroData
+ base
,
2890 &vbuf
.buffer_offset
,
2891 &vbuf
.buffer
.resource
);
2892 u_upload_unmap(This
->vertex_uploader
);
2893 /* Won't be used: */
2894 vbuf
.buffer_offset
-= base
;
2897 unsigned index_offset
= 0;
2898 if (This
->csmt_active
) {
2899 u_upload_data(This
->pipe_secondary
->stream_uploader
,
2901 (prim_count_to_vertex_count(PrimitiveType
, PrimitiveCount
)) * index_size
,
2906 u_upload_unmap(This
->pipe_secondary
->stream_uploader
);
2909 NineBeforeDraw(This
);
2910 nine_context_draw_indexed_primitive_from_vtxbuf_idxbuf(This
, PrimitiveType
,
2916 ibuf
? NULL
: (void*)pIndexData
,
2919 NineAfterDraw(This
);
2921 pipe_vertex_buffer_unreference(&vbuf
);
2922 pipe_resource_reference(&ibuf
, NULL
);
2924 NineDevice9_PauseRecording(This
);
2925 NineDevice9_SetIndices(This
, NULL
);
2926 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
2927 NineDevice9_ResumeRecording(This
);
2933 NineDevice9_ProcessVertices( struct NineDevice9
*This
,
2937 IDirect3DVertexBuffer9
*pDestBuffer
,
2938 IDirect3DVertexDeclaration9
*pVertexDecl
,
2941 struct pipe_screen
*screen_sw
= This
->screen_sw
;
2942 struct pipe_context
*pipe_sw
= This
->pipe_sw
;
2943 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pVertexDecl
);
2944 struct NineVertexBuffer9
*dst
= NineVertexBuffer9(pDestBuffer
);
2945 struct NineVertexShader9
*vs
;
2946 struct pipe_resource
*resource
;
2947 struct pipe_transfer
*transfer
= NULL
;
2948 struct pipe_stream_output_info so
;
2949 struct pipe_stream_output_target
*target
;
2950 struct pipe_draw_info draw
;
2951 struct pipe_box box
;
2952 bool programmable_vs
= This
->state
.vs
&& !(This
->state
.vdecl
&& This
->state
.vdecl
->position_t
);
2953 unsigned offsets
[1] = {0};
2955 unsigned buffer_size
;
2958 DBG("This=%p SrcStartIndex=%u DestIndex=%u VertexCount=%u "
2959 "pDestBuffer=%p pVertexDecl=%p Flags=%d\n",
2960 This
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
,
2961 pVertexDecl
, Flags
);
2963 if (!screen_sw
->get_param(screen_sw
, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
)) {
2964 DBG("ProcessVertices not supported\n");
2965 return D3DERR_INVALIDCALL
;
2969 vs
= programmable_vs
? This
->state
.vs
: This
->ff
.vs
;
2970 /* Note: version is 0 for ff */
2971 user_assert(vdecl
|| (vs
->byte_code
.version
< 0x30 && dst
->desc
.FVF
),
2972 D3DERR_INVALIDCALL
);
2974 DWORD FVF
= dst
->desc
.FVF
;
2975 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
2977 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
2981 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
2982 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
2986 /* Flags: Can be 0 or D3DPV_DONOTCOPYDATA, and/or lock flags
2987 * D3DPV_DONOTCOPYDATA -> Has effect only for ff. In particular
2988 * if not set, everything from src will be used, and dst
2989 * must match exactly the ff vs outputs.
2990 * TODO: Handle all the checks, etc for ff */
2991 user_assert(vdecl
->position_t
|| programmable_vs
,
2992 D3DERR_INVALIDCALL
);
2994 /* TODO: Support vs < 3 and ff */
2995 user_assert(vs
->byte_code
.version
== 0x30,
2996 D3DERR_INVALIDCALL
);
2997 /* TODO: Not hardcode the constant buffers for swvp */
2998 user_assert(This
->may_swvp
,
2999 D3DERR_INVALIDCALL
);
3001 nine_state_prepare_draw_sw(This
, vdecl
, SrcStartIndex
, VertexCount
, &so
);
3003 buffer_size
= VertexCount
* so
.stride
[0] * 4;
3005 struct pipe_resource templ
;
3007 memset(&templ
, 0, sizeof(templ
));
3008 templ
.target
= PIPE_BUFFER
;
3009 templ
.format
= PIPE_FORMAT_R8_UNORM
;
3010 templ
.width0
= buffer_size
;
3012 templ
.bind
= PIPE_BIND_STREAM_OUTPUT
;
3013 templ
.usage
= PIPE_USAGE_STREAM
;
3014 templ
.height0
= templ
.depth0
= templ
.array_size
= 1;
3015 templ
.last_level
= templ
.nr_samples
= 0;
3017 resource
= screen_sw
->resource_create(screen_sw
, &templ
);
3019 return E_OUTOFMEMORY
;
3021 target
= pipe_sw
->create_stream_output_target(pipe_sw
, resource
,
3024 pipe_resource_reference(&resource
, NULL
);
3025 return D3DERR_DRIVERINTERNALERROR
;
3028 draw
.mode
= PIPE_PRIM_POINTS
;
3029 draw
.count
= VertexCount
;
3030 draw
.start_instance
= 0;
3031 draw
.primitive_restart
= FALSE
;
3032 draw
.restart_index
= 0;
3033 draw
.count_from_stream_output
= NULL
;
3034 draw
.indirect
= NULL
;
3035 draw
.instance_count
= 1;
3036 draw
.index_size
= 0;
3038 draw
.index_bias
= 0;
3040 draw
.max_index
= VertexCount
- 1;
3043 pipe_sw
->set_stream_output_targets(pipe_sw
, 1, &target
, offsets
);
3045 pipe_sw
->draw_vbo(pipe_sw
, &draw
);
3047 pipe_sw
->set_stream_output_targets(pipe_sw
, 0, NULL
, 0);
3048 pipe_sw
->stream_output_target_destroy(pipe_sw
, target
);
3050 u_box_1d(0, VertexCount
* so
.stride
[0] * 4, &box
);
3051 map
= pipe_sw
->transfer_map(pipe_sw
, resource
, 0, PIPE_TRANSFER_READ
, &box
,
3054 hr
= D3DERR_DRIVERINTERNALERROR
;
3058 hr
= NineVertexDeclaration9_ConvertStreamOutput(vdecl
,
3059 dst
, DestIndex
, VertexCount
,
3062 pipe_sw
->transfer_unmap(pipe_sw
, transfer
);
3065 nine_state_after_draw_sw(This
);
3066 pipe_resource_reference(&resource
, NULL
);
3071 NineDevice9_CreateVertexDeclaration( struct NineDevice9
*This
,
3072 const D3DVERTEXELEMENT9
*pVertexElements
,
3073 IDirect3DVertexDeclaration9
**ppDecl
)
3075 struct NineVertexDeclaration9
*vdecl
;
3077 DBG("This=%p pVertexElements=%p ppDecl=%p\n",
3078 This
, pVertexElements
, ppDecl
);
3080 HRESULT hr
= NineVertexDeclaration9_new(This
, pVertexElements
, &vdecl
);
3082 *ppDecl
= (IDirect3DVertexDeclaration9
*)vdecl
;
3088 NineDevice9_SetVertexDeclaration( struct NineDevice9
*This
,
3089 IDirect3DVertexDeclaration9
*pDecl
)
3091 struct nine_state
*state
= This
->update
;
3092 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pDecl
);
3094 DBG("This=%p pDecl=%p\n", This
, pDecl
);
3096 if (unlikely(This
->is_recording
)) {
3097 nine_bind(&state
->vdecl
, vdecl
);
3098 state
->changed
.group
|= NINE_STATE_VDECL
;
3102 if (state
->vdecl
== vdecl
)
3105 nine_bind(&state
->vdecl
, vdecl
);
3107 nine_context_set_vertex_declaration(This
, vdecl
);
3113 NineDevice9_GetVertexDeclaration( struct NineDevice9
*This
,
3114 IDirect3DVertexDeclaration9
**ppDecl
)
3116 user_assert(ppDecl
, D3DERR_INVALIDCALL
);
3118 *ppDecl
= (IDirect3DVertexDeclaration9
*)This
->state
.vdecl
;
3120 NineUnknown_AddRef(NineUnknown(*ppDecl
));
3125 NineDevice9_SetFVF( struct NineDevice9
*This
,
3128 struct NineVertexDeclaration9
*vdecl
;
3131 DBG("FVF = %08x\n", FVF
);
3133 return D3D_OK
; /* like wine */
3135 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
3137 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
3141 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
3142 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
3144 return NineDevice9_SetVertexDeclaration(
3145 This
, (IDirect3DVertexDeclaration9
*)vdecl
);
3149 NineDevice9_GetFVF( struct NineDevice9
*This
,
3152 *pFVF
= This
->state
.vdecl
? This
->state
.vdecl
->fvf
: 0;
3157 NineDevice9_CreateVertexShader( struct NineDevice9
*This
,
3158 const DWORD
*pFunction
,
3159 IDirect3DVertexShader9
**ppShader
)
3161 struct NineVertexShader9
*vs
;
3164 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3166 hr
= NineVertexShader9_new(This
, &vs
, pFunction
, NULL
);
3169 *ppShader
= (IDirect3DVertexShader9
*)vs
;
3174 NineDevice9_SetVertexShader( struct NineDevice9
*This
,
3175 IDirect3DVertexShader9
*pShader
)
3177 struct nine_state
*state
= This
->update
;
3178 struct NineVertexShader9
*vs_shader
= (struct NineVertexShader9
*)pShader
;
3180 DBG("This=%p pShader=%p\n", This
, pShader
);
3182 if (unlikely(This
->is_recording
)) {
3183 nine_bind(&state
->vs
, vs_shader
);
3184 state
->changed
.group
|= NINE_STATE_VS
;
3188 if (state
->vs
== vs_shader
)
3191 nine_bind(&state
->vs
, vs_shader
);
3193 nine_context_set_vertex_shader(This
, vs_shader
);
3199 NineDevice9_GetVertexShader( struct NineDevice9
*This
,
3200 IDirect3DVertexShader9
**ppShader
)
3202 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3203 nine_reference_set(ppShader
, This
->state
.vs
);
3208 NineDevice9_SetVertexShaderConstantF( struct NineDevice9
*This
,
3210 const float *pConstantData
,
3211 UINT Vector4fCount
)
3213 struct nine_state
*state
= This
->update
;
3214 float *vs_const_f
= state
->vs_const_f
;
3216 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3217 This
, StartRegister
, pConstantData
, Vector4fCount
);
3219 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3220 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3224 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3226 if (unlikely(This
->is_recording
)) {
3227 memcpy(&vs_const_f
[StartRegister
* 4],
3229 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3231 nine_ranges_insert(&state
->changed
.vs_const_f
,
3232 StartRegister
, StartRegister
+ Vector4fCount
,
3235 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3240 if (!memcmp(&vs_const_f
[StartRegister
* 4], pConstantData
,
3241 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0])))
3244 memcpy(&vs_const_f
[StartRegister
* 4],
3246 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3248 nine_context_set_vertex_shader_constant_f(This
, StartRegister
, pConstantData
,
3249 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]),
3256 NineDevice9_GetVertexShaderConstantF( struct NineDevice9
*This
,
3258 float *pConstantData
,
3259 UINT Vector4fCount
)
3261 const struct nine_state
*state
= &This
->state
;
3263 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3264 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3265 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3267 memcpy(pConstantData
,
3268 &state
->vs_const_f
[StartRegister
* 4],
3269 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3275 NineDevice9_SetVertexShaderConstantI( struct NineDevice9
*This
,
3277 const int *pConstantData
,
3278 UINT Vector4iCount
)
3280 struct nine_state
*state
= This
->update
;
3283 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3284 This
, StartRegister
, pConstantData
, Vector4iCount
);
3286 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3287 D3DERR_INVALIDCALL
);
3288 user_assert(StartRegister
+ Vector4iCount
<= (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3289 D3DERR_INVALIDCALL
);
3290 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3292 if (This
->driver_caps
.vs_integer
) {
3293 if (!This
->is_recording
) {
3294 if (!memcmp(&state
->vs_const_i
[4 * StartRegister
], pConstantData
,
3295 Vector4iCount
* sizeof(int[4])))
3298 memcpy(&state
->vs_const_i
[4 * StartRegister
],
3300 Vector4iCount
* sizeof(int[4]));
3302 for (i
= 0; i
< Vector4iCount
; i
++) {
3303 state
->vs_const_i
[4 * (StartRegister
+ i
)] = fui((float)(pConstantData
[4 * i
]));
3304 state
->vs_const_i
[4 * (StartRegister
+ i
) + 1] = fui((float)(pConstantData
[4 * i
+ 1]));
3305 state
->vs_const_i
[4 * (StartRegister
+ i
) + 2] = fui((float)(pConstantData
[4 * i
+ 2]));
3306 state
->vs_const_i
[4 * (StartRegister
+ i
) + 3] = fui((float)(pConstantData
[4 * i
+ 3]));
3310 if (unlikely(This
->is_recording
)) {
3311 nine_ranges_insert(&state
->changed
.vs_const_i
,
3312 StartRegister
, StartRegister
+ Vector4iCount
,
3314 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3316 nine_context_set_vertex_shader_constant_i(This
, StartRegister
, pConstantData
,
3317 Vector4iCount
* sizeof(int[4]), Vector4iCount
);
3323 NineDevice9_GetVertexShaderConstantI( struct NineDevice9
*This
,
3326 UINT Vector4iCount
)
3328 const struct nine_state
*state
= &This
->state
;
3331 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3332 D3DERR_INVALIDCALL
);
3333 user_assert(StartRegister
+ Vector4iCount
<= (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3334 D3DERR_INVALIDCALL
);
3335 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3337 if (This
->driver_caps
.vs_integer
) {
3338 memcpy(pConstantData
,
3339 &state
->vs_const_i
[4 * StartRegister
],
3340 Vector4iCount
* sizeof(int[4]));
3342 for (i
= 0; i
< Vector4iCount
; i
++) {
3343 pConstantData
[4 * i
] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
)]);
3344 pConstantData
[4 * i
+ 1] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
) + 1]);
3345 pConstantData
[4 * i
+ 2] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
) + 2]);
3346 pConstantData
[4 * i
+ 3] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
) + 3]);
3354 NineDevice9_SetVertexShaderConstantB( struct NineDevice9
*This
,
3356 const BOOL
*pConstantData
,
3359 struct nine_state
*state
= This
->update
;
3361 uint32_t bool_true
= This
->driver_caps
.vs_integer
? 0xFFFFFFFF : fui(1.0f
);
3363 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3364 This
, StartRegister
, pConstantData
, BoolCount
);
3366 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3367 D3DERR_INVALIDCALL
);
3368 user_assert(StartRegister
+ BoolCount
<= (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3369 D3DERR_INVALIDCALL
);
3370 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3372 if (!This
->is_recording
) {
3373 bool noChange
= true;
3374 for (i
= 0; i
< BoolCount
; i
++) {
3375 if (!!state
->vs_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3382 for (i
= 0; i
< BoolCount
; i
++)
3383 state
->vs_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3385 if (unlikely(This
->is_recording
)) {
3386 nine_ranges_insert(&state
->changed
.vs_const_b
,
3387 StartRegister
, StartRegister
+ BoolCount
,
3389 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3391 nine_context_set_vertex_shader_constant_b(This
, StartRegister
, pConstantData
,
3392 sizeof(BOOL
) * BoolCount
, BoolCount
);
3398 NineDevice9_GetVertexShaderConstantB( struct NineDevice9
*This
,
3400 BOOL
*pConstantData
,
3403 const struct nine_state
*state
= &This
->state
;
3406 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3407 D3DERR_INVALIDCALL
);
3408 user_assert(StartRegister
+ BoolCount
<= (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3409 D3DERR_INVALIDCALL
);
3410 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3412 for (i
= 0; i
< BoolCount
; i
++)
3413 pConstantData
[i
] = state
->vs_const_b
[StartRegister
+ i
] != 0 ? TRUE
: FALSE
;
3419 NineDevice9_SetStreamSource( struct NineDevice9
*This
,
3421 IDirect3DVertexBuffer9
*pStreamData
,
3425 struct nine_state
*state
= This
->update
;
3426 struct NineVertexBuffer9
*pVBuf9
= NineVertexBuffer9(pStreamData
);
3427 const unsigned i
= StreamNumber
;
3429 DBG("This=%p StreamNumber=%u pStreamData=%p OffsetInBytes=%u Stride=%u\n",
3430 This
, StreamNumber
, pStreamData
, OffsetInBytes
, Stride
);
3432 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3433 user_assert(Stride
<= This
->caps
.MaxStreamStride
, D3DERR_INVALIDCALL
);
3435 if (unlikely(This
->is_recording
)) {
3436 nine_bind(&state
->stream
[i
], pStreamData
);
3437 state
->changed
.vtxbuf
|= 1 << StreamNumber
;
3438 state
->vtxbuf
[i
].stride
= Stride
;
3439 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3443 if (state
->stream
[i
] == NineVertexBuffer9(pStreamData
) &&
3444 state
->vtxbuf
[i
].stride
== Stride
&&
3445 state
->vtxbuf
[i
].buffer_offset
== OffsetInBytes
)
3448 state
->vtxbuf
[i
].stride
= Stride
;
3449 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3451 NineBindBufferToDevice(This
,
3452 (struct NineBuffer9
**)&state
->stream
[i
],
3453 (struct NineBuffer9
*)pVBuf9
);
3455 nine_context_set_stream_source(This
,
3465 NineDevice9_GetStreamSource( struct NineDevice9
*This
,
3467 IDirect3DVertexBuffer9
**ppStreamData
,
3468 UINT
*pOffsetInBytes
,
3471 const struct nine_state
*state
= &This
->state
;
3472 const unsigned i
= StreamNumber
;
3474 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3475 user_assert(ppStreamData
, D3DERR_INVALIDCALL
);
3477 nine_reference_set(ppStreamData
, state
->stream
[i
]);
3478 *pStride
= state
->vtxbuf
[i
].stride
;
3479 *pOffsetInBytes
= state
->vtxbuf
[i
].buffer_offset
;
3485 NineDevice9_SetStreamSourceFreq( struct NineDevice9
*This
,
3489 struct nine_state
*state
= This
->update
;
3490 /* const UINT freq = Setting & 0x7FFFFF; */
3492 DBG("This=%p StreamNumber=%u FrequencyParameter=0x%x\n", This
,
3493 StreamNumber
, Setting
);
3495 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3496 user_assert(StreamNumber
!= 0 || !(Setting
& D3DSTREAMSOURCE_INSTANCEDATA
),
3497 D3DERR_INVALIDCALL
);
3498 user_assert(!((Setting
& D3DSTREAMSOURCE_INSTANCEDATA
) &&
3499 (Setting
& D3DSTREAMSOURCE_INDEXEDDATA
)), D3DERR_INVALIDCALL
);
3500 user_assert(Setting
, D3DERR_INVALIDCALL
);
3502 if (unlikely(This
->is_recording
)) {
3503 state
->stream_freq
[StreamNumber
] = Setting
;
3504 state
->changed
.stream_freq
|= 1 << StreamNumber
;
3505 if (StreamNumber
!= 0)
3506 state
->changed
.group
|= NINE_STATE_STREAMFREQ
;
3510 if (state
->stream_freq
[StreamNumber
] == Setting
)
3513 state
->stream_freq
[StreamNumber
] = Setting
;
3515 nine_context_set_stream_source_freq(This
, StreamNumber
, Setting
);
3520 NineDevice9_GetStreamSourceFreq( struct NineDevice9
*This
,
3524 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3525 *pSetting
= This
->state
.stream_freq
[StreamNumber
];
3530 NineDevice9_SetIndices( struct NineDevice9
*This
,
3531 IDirect3DIndexBuffer9
*pIndexData
)
3533 struct nine_state
*state
= This
->update
;
3534 struct NineIndexBuffer9
*idxbuf
= NineIndexBuffer9(pIndexData
);
3536 DBG("This=%p pIndexData=%p\n", This
, pIndexData
);
3538 if (unlikely(This
->is_recording
)) {
3539 nine_bind(&state
->idxbuf
, idxbuf
);
3540 state
->changed
.group
|= NINE_STATE_IDXBUF
;
3544 if (state
->idxbuf
== idxbuf
)
3547 NineBindBufferToDevice(This
,
3548 (struct NineBuffer9
**)&state
->idxbuf
,
3549 (struct NineBuffer9
*)idxbuf
);
3551 nine_context_set_indices(This
, idxbuf
);
3556 /* XXX: wine/d3d9 doesn't have pBaseVertexIndex, and it doesn't make sense
3557 * here because it's an argument passed to the Draw calls.
3560 NineDevice9_GetIndices( struct NineDevice9
*This
,
3561 IDirect3DIndexBuffer9
**ppIndexData
)
3563 user_assert(ppIndexData
, D3DERR_INVALIDCALL
);
3564 nine_reference_set(ppIndexData
, This
->state
.idxbuf
);
3569 NineDevice9_CreatePixelShader( struct NineDevice9
*This
,
3570 const DWORD
*pFunction
,
3571 IDirect3DPixelShader9
**ppShader
)
3573 struct NinePixelShader9
*ps
;
3576 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3578 hr
= NinePixelShader9_new(This
, &ps
, pFunction
, NULL
);
3581 *ppShader
= (IDirect3DPixelShader9
*)ps
;
3586 NineDevice9_SetPixelShader( struct NineDevice9
*This
,
3587 IDirect3DPixelShader9
*pShader
)
3589 struct nine_state
*state
= This
->update
;
3590 struct NinePixelShader9
*ps
= (struct NinePixelShader9
*)pShader
;
3592 DBG("This=%p pShader=%p\n", This
, pShader
);
3594 if (unlikely(This
->is_recording
)) {
3595 /* Technically we need NINE_STATE_FB only
3596 * if the ps mask changes, but put it always
3598 nine_bind(&state
->ps
, pShader
);
3599 state
->changed
.group
|= NINE_STATE_PS
| NINE_STATE_FB
;
3603 if (state
->ps
== ps
)
3606 nine_bind(&state
->ps
, ps
);
3608 nine_context_set_pixel_shader(This
, ps
);
3614 NineDevice9_GetPixelShader( struct NineDevice9
*This
,
3615 IDirect3DPixelShader9
**ppShader
)
3617 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3618 nine_reference_set(ppShader
, This
->state
.ps
);
3623 NineDevice9_SetPixelShaderConstantF( struct NineDevice9
*This
,
3625 const float *pConstantData
,
3626 UINT Vector4fCount
)
3628 struct nine_state
*state
= This
->update
;
3630 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3631 This
, StartRegister
, pConstantData
, Vector4fCount
);
3633 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3634 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3638 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3640 if (unlikely(This
->is_recording
)) {
3641 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3643 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3645 nine_ranges_insert(&state
->changed
.ps_const_f
,
3646 StartRegister
, StartRegister
+ Vector4fCount
,
3649 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3653 if (!memcmp(&state
->ps_const_f
[StartRegister
* 4], pConstantData
,
3654 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0])))
3657 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3659 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3661 nine_context_set_pixel_shader_constant_f(This
, StartRegister
, pConstantData
,
3662 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]),
3669 NineDevice9_GetPixelShaderConstantF( struct NineDevice9
*This
,
3671 float *pConstantData
,
3672 UINT Vector4fCount
)
3674 const struct nine_state
*state
= &This
->state
;
3676 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3677 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3678 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3680 memcpy(pConstantData
,
3681 &state
->ps_const_f
[StartRegister
* 4],
3682 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3688 NineDevice9_SetPixelShaderConstantI( struct NineDevice9
*This
,
3690 const int *pConstantData
,
3691 UINT Vector4iCount
)
3693 struct nine_state
*state
= This
->update
;
3696 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3697 This
, StartRegister
, pConstantData
, Vector4iCount
);
3699 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3700 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3701 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3703 if (This
->driver_caps
.ps_integer
) {
3704 if (!This
->is_recording
) {
3705 if (!memcmp(&state
->ps_const_i
[StartRegister
][0], pConstantData
,
3706 Vector4iCount
* sizeof(state
->ps_const_i
[0])))
3709 memcpy(&state
->ps_const_i
[StartRegister
][0],
3711 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3713 for (i
= 0; i
< Vector4iCount
; i
++) {
3714 state
->ps_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3715 state
->ps_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3716 state
->ps_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3717 state
->ps_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3721 if (unlikely(This
->is_recording
)) {
3722 state
->changed
.ps_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3723 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3725 nine_context_set_pixel_shader_constant_i(This
, StartRegister
, pConstantData
,
3726 sizeof(state
->ps_const_i
[0]) * Vector4iCount
, Vector4iCount
);
3732 NineDevice9_GetPixelShaderConstantI( struct NineDevice9
*This
,
3735 UINT Vector4iCount
)
3737 const struct nine_state
*state
= &This
->state
;
3740 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3741 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3742 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3744 if (This
->driver_caps
.ps_integer
) {
3745 memcpy(pConstantData
,
3746 &state
->ps_const_i
[StartRegister
][0],
3747 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3749 for (i
= 0; i
< Vector4iCount
; i
++) {
3750 pConstantData
[4*i
] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][0]);
3751 pConstantData
[4*i
+1] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][1]);
3752 pConstantData
[4*i
+2] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][2]);
3753 pConstantData
[4*i
+3] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][3]);
3761 NineDevice9_SetPixelShaderConstantB( struct NineDevice9
*This
,
3763 const BOOL
*pConstantData
,
3766 struct nine_state
*state
= This
->update
;
3768 uint32_t bool_true
= This
->driver_caps
.ps_integer
? 0xFFFFFFFF : fui(1.0f
);
3770 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3771 This
, StartRegister
, pConstantData
, BoolCount
);
3773 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3774 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3775 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3777 if (!This
->is_recording
) {
3778 bool noChange
= true;
3779 for (i
= 0; i
< BoolCount
; i
++) {
3780 if (!!state
->ps_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3787 for (i
= 0; i
< BoolCount
; i
++)
3788 state
->ps_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3790 if (unlikely(This
->is_recording
)) {
3791 state
->changed
.ps_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3792 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3794 nine_context_set_pixel_shader_constant_b(This
, StartRegister
, pConstantData
,
3795 sizeof(BOOL
) * BoolCount
, BoolCount
);
3801 NineDevice9_GetPixelShaderConstantB( struct NineDevice9
*This
,
3803 BOOL
*pConstantData
,
3806 const struct nine_state
*state
= &This
->state
;
3809 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3810 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3811 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3813 for (i
= 0; i
< BoolCount
; i
++)
3814 pConstantData
[i
] = state
->ps_const_b
[StartRegister
+ i
] ? TRUE
: FALSE
;
3820 NineDevice9_DrawRectPatch( struct NineDevice9
*This
,
3822 const float *pNumSegs
,
3823 const D3DRECTPATCH_INFO
*pRectPatchInfo
)
3825 STUB(D3DERR_INVALIDCALL
);
3829 NineDevice9_DrawTriPatch( struct NineDevice9
*This
,
3831 const float *pNumSegs
,
3832 const D3DTRIPATCH_INFO
*pTriPatchInfo
)
3834 STUB(D3DERR_INVALIDCALL
);
3838 NineDevice9_DeletePatch( struct NineDevice9
*This
,
3841 STUB(D3DERR_INVALIDCALL
);
3845 NineDevice9_CreateQuery( struct NineDevice9
*This
,
3847 IDirect3DQuery9
**ppQuery
)
3849 struct NineQuery9
*query
;
3852 DBG("This=%p Type=%d ppQuery=%p\n", This
, Type
, ppQuery
);
3854 hr
= nine_is_query_supported(This
->screen
, Type
);
3855 if (!ppQuery
|| hr
!= D3D_OK
)
3858 hr
= NineQuery9_new(This
, &query
, Type
);
3861 *ppQuery
= (IDirect3DQuery9
*)query
;
3865 IDirect3DDevice9Vtbl NineDevice9_vtable
= {
3866 (void *)NineUnknown_QueryInterface
,
3867 (void *)NineUnknown_AddRef
,
3868 (void *)NineUnknown_Release
,
3869 (void *)NineDevice9_TestCooperativeLevel
,
3870 (void *)NineDevice9_GetAvailableTextureMem
,
3871 (void *)NineDevice9_EvictManagedResources
,
3872 (void *)NineDevice9_GetDirect3D
,
3873 (void *)NineDevice9_GetDeviceCaps
,
3874 (void *)NineDevice9_GetDisplayMode
,
3875 (void *)NineDevice9_GetCreationParameters
,
3876 (void *)NineDevice9_SetCursorProperties
,
3877 (void *)NineDevice9_SetCursorPosition
,
3878 (void *)NineDevice9_ShowCursor
,
3879 (void *)NineDevice9_CreateAdditionalSwapChain
,
3880 (void *)NineDevice9_GetSwapChain
,
3881 (void *)NineDevice9_GetNumberOfSwapChains
,
3882 (void *)NineDevice9_Reset
,
3883 (void *)NineDevice9_Present
,
3884 (void *)NineDevice9_GetBackBuffer
,
3885 (void *)NineDevice9_GetRasterStatus
,
3886 (void *)NineDevice9_SetDialogBoxMode
,
3887 (void *)NineDevice9_SetGammaRamp
,
3888 (void *)NineDevice9_GetGammaRamp
,
3889 (void *)NineDevice9_CreateTexture
,
3890 (void *)NineDevice9_CreateVolumeTexture
,
3891 (void *)NineDevice9_CreateCubeTexture
,
3892 (void *)NineDevice9_CreateVertexBuffer
,
3893 (void *)NineDevice9_CreateIndexBuffer
,
3894 (void *)NineDevice9_CreateRenderTarget
,
3895 (void *)NineDevice9_CreateDepthStencilSurface
,
3896 (void *)NineDevice9_UpdateSurface
,
3897 (void *)NineDevice9_UpdateTexture
,
3898 (void *)NineDevice9_GetRenderTargetData
,
3899 (void *)NineDevice9_GetFrontBufferData
,
3900 (void *)NineDevice9_StretchRect
,
3901 (void *)NineDevice9_ColorFill
,
3902 (void *)NineDevice9_CreateOffscreenPlainSurface
,
3903 (void *)NineDevice9_SetRenderTarget
,
3904 (void *)NineDevice9_GetRenderTarget
,
3905 (void *)NineDevice9_SetDepthStencilSurface
,
3906 (void *)NineDevice9_GetDepthStencilSurface
,
3907 (void *)NineDevice9_BeginScene
,
3908 (void *)NineDevice9_EndScene
,
3909 (void *)NineDevice9_Clear
,
3910 (void *)NineDevice9_SetTransform
,
3911 (void *)NineDevice9_GetTransform
,
3912 (void *)NineDevice9_MultiplyTransform
,
3913 (void *)NineDevice9_SetViewport
,
3914 (void *)NineDevice9_GetViewport
,
3915 (void *)NineDevice9_SetMaterial
,
3916 (void *)NineDevice9_GetMaterial
,
3917 (void *)NineDevice9_SetLight
,
3918 (void *)NineDevice9_GetLight
,
3919 (void *)NineDevice9_LightEnable
,
3920 (void *)NineDevice9_GetLightEnable
,
3921 (void *)NineDevice9_SetClipPlane
,
3922 (void *)NineDevice9_GetClipPlane
,
3923 (void *)NineDevice9_SetRenderState
,
3924 (void *)NineDevice9_GetRenderState
,
3925 (void *)NineDevice9_CreateStateBlock
,
3926 (void *)NineDevice9_BeginStateBlock
,
3927 (void *)NineDevice9_EndStateBlock
,
3928 (void *)NineDevice9_SetClipStatus
,
3929 (void *)NineDevice9_GetClipStatus
,
3930 (void *)NineDevice9_GetTexture
,
3931 (void *)NineDevice9_SetTexture
,
3932 (void *)NineDevice9_GetTextureStageState
,
3933 (void *)NineDevice9_SetTextureStageState
,
3934 (void *)NineDevice9_GetSamplerState
,
3935 (void *)NineDevice9_SetSamplerState
,
3936 (void *)NineDevice9_ValidateDevice
,
3937 (void *)NineDevice9_SetPaletteEntries
,
3938 (void *)NineDevice9_GetPaletteEntries
,
3939 (void *)NineDevice9_SetCurrentTexturePalette
,
3940 (void *)NineDevice9_GetCurrentTexturePalette
,
3941 (void *)NineDevice9_SetScissorRect
,
3942 (void *)NineDevice9_GetScissorRect
,
3943 (void *)NineDevice9_SetSoftwareVertexProcessing
,
3944 (void *)NineDevice9_GetSoftwareVertexProcessing
,
3945 (void *)NineDevice9_SetNPatchMode
,
3946 (void *)NineDevice9_GetNPatchMode
,
3947 (void *)NineDevice9_DrawPrimitive
,
3948 (void *)NineDevice9_DrawIndexedPrimitive
,
3949 (void *)NineDevice9_DrawPrimitiveUP
,
3950 (void *)NineDevice9_DrawIndexedPrimitiveUP
,
3951 (void *)NineDevice9_ProcessVertices
,
3952 (void *)NineDevice9_CreateVertexDeclaration
,
3953 (void *)NineDevice9_SetVertexDeclaration
,
3954 (void *)NineDevice9_GetVertexDeclaration
,
3955 (void *)NineDevice9_SetFVF
,
3956 (void *)NineDevice9_GetFVF
,
3957 (void *)NineDevice9_CreateVertexShader
,
3958 (void *)NineDevice9_SetVertexShader
,
3959 (void *)NineDevice9_GetVertexShader
,
3960 (void *)NineDevice9_SetVertexShaderConstantF
,
3961 (void *)NineDevice9_GetVertexShaderConstantF
,
3962 (void *)NineDevice9_SetVertexShaderConstantI
,
3963 (void *)NineDevice9_GetVertexShaderConstantI
,
3964 (void *)NineDevice9_SetVertexShaderConstantB
,
3965 (void *)NineDevice9_GetVertexShaderConstantB
,
3966 (void *)NineDevice9_SetStreamSource
,
3967 (void *)NineDevice9_GetStreamSource
,
3968 (void *)NineDevice9_SetStreamSourceFreq
,
3969 (void *)NineDevice9_GetStreamSourceFreq
,
3970 (void *)NineDevice9_SetIndices
,
3971 (void *)NineDevice9_GetIndices
,
3972 (void *)NineDevice9_CreatePixelShader
,
3973 (void *)NineDevice9_SetPixelShader
,
3974 (void *)NineDevice9_GetPixelShader
,
3975 (void *)NineDevice9_SetPixelShaderConstantF
,
3976 (void *)NineDevice9_GetPixelShaderConstantF
,
3977 (void *)NineDevice9_SetPixelShaderConstantI
,
3978 (void *)NineDevice9_GetPixelShaderConstantI
,
3979 (void *)NineDevice9_SetPixelShaderConstantB
,
3980 (void *)NineDevice9_GetPixelShaderConstantB
,
3981 (void *)NineDevice9_DrawRectPatch
,
3982 (void *)NineDevice9_DrawTriPatch
,
3983 (void *)NineDevice9_DeletePatch
,
3984 (void *)NineDevice9_CreateQuery
3987 static const GUID
*NineDevice9_IIDs
[] = {
3988 &IID_IDirect3DDevice9
,
3994 NineDevice9_new( struct pipe_screen
*pScreen
,
3995 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
3997 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
3999 ID3DPresentGroup
*pPresentationGroup
,
4000 struct d3dadapter9_context
*pCTX
,
4002 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
4003 struct NineDevice9
**ppOut
,
4004 int minorVersionNum
)
4007 lock
= !!(pCreationParameters
->BehaviorFlags
& D3DCREATE_MULTITHREADED
);
4009 NINE_NEW(Device9
, ppOut
, lock
, /* args */
4010 pScreen
, pCreationParameters
, pCaps
,
4011 pPresentationParameters
, pD3D9
, pPresentationGroup
, pCTX
,
4012 ex
, pFullscreenDisplayMode
, minorVersionNum
);