2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
24 #include "stateblock9.h"
26 #include "swapchain9.h"
27 #include "swapchain9ex.h"
28 #include "indexbuffer9.h"
29 #include "vertexbuffer9.h"
30 #include "vertexdeclaration9.h"
31 #include "vertexshader9.h"
32 #include "pixelshader9.h"
35 #include "cubetexture9.h"
36 #include "volumetexture9.h"
37 #include "nine_helpers.h"
38 #include "nine_pipe.h"
40 #include "nine_dump.h"
41 #include "nine_limits.h"
43 #include "pipe/p_screen.h"
44 #include "pipe/p_context.h"
45 #include "pipe/p_config.h"
46 #include "util/u_math.h"
47 #include "util/u_inlines.h"
48 #include "util/u_hash_table.h"
49 #include "util/u_format.h"
50 #include "util/u_surface.h"
51 #include "util/u_upload_mgr.h"
52 #include "hud/hud_context.h"
54 #include "cso_cache/cso_context.h"
56 #define DBG_CHANNEL DBG_DEVICE
58 #if defined(PIPE_CC_GCC) && (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64))
60 static void nine_setup_fpu()
64 __asm__
__volatile__ ("fnstcw %0" : "=m" (*&c
));
66 /* clear the control word */
68 /* d3d9 doc/wine tests: mask all exceptions, use single-precision
69 * and round to nearest */
72 __asm__
__volatile__ ("fldcw %0" : : "m" (*&c
));
77 static void nine_setup_fpu(void)
79 WARN_ONCE("FPU setup not supported on non-x86 platforms\n");
85 NineDevice9_SetDefaultState( struct NineDevice9
*This
, boolean is_reset
)
87 struct NineSurface9
*refSurf
= NULL
;
89 DBG("This=%p is_reset=%d\n", This
, (int) is_reset
);
91 assert(!This
->is_recording
);
93 nine_state_set_defaults(This
, &This
->caps
, is_reset
);
95 refSurf
= This
->swapchains
[0]->buffers
[0];
98 This
->state
.viewport
.X
= 0;
99 This
->state
.viewport
.Y
= 0;
100 This
->state
.viewport
.Width
= refSurf
->desc
.Width
;
101 This
->state
.viewport
.Height
= refSurf
->desc
.Height
;
103 This
->state
.scissor
.minx
= 0;
104 This
->state
.scissor
.miny
= 0;
105 This
->state
.scissor
.maxx
= refSurf
->desc
.Width
;
106 This
->state
.scissor
.maxy
= refSurf
->desc
.Height
;
108 if (This
->nswapchains
&& This
->swapchains
[0]->params
.EnableAutoDepthStencil
) {
109 This
->state
.rs
[D3DRS_ZENABLE
] = TRUE
;
110 This
->state
.rs_advertised
[D3DRS_ZENABLE
] = TRUE
;
112 if (This
->state
.rs
[D3DRS_ZENABLE
])
113 NineDevice9_SetDepthStencilSurface(
114 This
, (IDirect3DSurface9
*)This
->swapchains
[0]->zsbuf
);
117 #define GET_PCAP(n) pScreen->get_param(pScreen, PIPE_CAP_##n)
119 NineDevice9_ctor( struct NineDevice9
*This
,
120 struct NineUnknownParams
*pParams
,
121 struct pipe_screen
*pScreen
,
122 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
124 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
126 ID3DPresentGroup
*pPresentationGroup
,
127 struct d3dadapter9_context
*pCTX
,
129 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
130 int minorVersionNum
)
133 HRESULT hr
= NineUnknown_ctor(&This
->base
, pParams
);
135 DBG("This=%p pParams=%p pScreen=%p pCreationParameters=%p pCaps=%p pPresentationParameters=%p "
136 "pD3D9=%p pPresentationGroup=%p pCTX=%p ex=%d pFullscreenDisplayMode=%p\n",
137 This
, pParams
, pScreen
, pCreationParameters
, pCaps
, pPresentationParameters
, pD3D9
,
138 pPresentationGroup
, pCTX
, (int) ex
, pFullscreenDisplayMode
);
140 if (FAILED(hr
)) { return hr
; }
142 list_inithead(&This
->update_buffers
);
143 list_inithead(&This
->update_textures
);
144 list_inithead(&This
->managed_buffers
);
145 list_inithead(&This
->managed_textures
);
147 This
->screen
= pScreen
;
148 This
->screen_sw
= pCTX
->ref
;
151 This
->params
= *pCreationParameters
;
153 This
->present
= pPresentationGroup
;
154 This
->minor_version_num
= minorVersionNum
;
156 IDirect3D9_AddRef(This
->d3d9
);
157 ID3DPresentGroup_AddRef(This
->present
);
159 if (!(This
->params
.BehaviorFlags
& D3DCREATE_FPU_PRESERVE
))
162 if (This
->params
.BehaviorFlags
& D3DCREATE_SOFTWARE_VERTEXPROCESSING
) {
163 DBG("Application asked full Software Vertex Processing.\n");
165 This
->may_swvp
= true;
168 if (This
->params
.BehaviorFlags
& D3DCREATE_MIXED_VERTEXPROCESSING
) {
169 DBG("Application asked mixed Software Vertex Processing.\n");
170 This
->may_swvp
= true;
172 /* TODO: check if swvp is resetted by device Resets */
174 if (This
->may_swvp
&&
175 (This
->screen
->get_shader_param(This
->screen
, PIPE_SHADER_VERTEX
,
176 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
)
177 < (NINE_MAX_CONST_F_SWVP
/2) * sizeof(float[4]) ||
178 This
->screen
->get_shader_param(This
->screen
, PIPE_SHADER_VERTEX
,
179 PIPE_SHADER_CAP_MAX_CONST_BUFFERS
) < 5)) {
180 /* Note: We just go on, some apps never use the abilities of
181 * swvp, and just set more constants than allowed at init.
182 * Only cards we support that are affected are the r500 */
183 WARN("Card unable to handle Software Vertex Processing. Game may fail\n");
186 /* When may_swvp, SetConstant* limits are different */
188 This
->caps
.MaxVertexShaderConst
= NINE_MAX_CONST_F_SWVP
;
190 This
->pipe
= This
->screen
->context_create(This
->screen
, NULL
, 0);
191 if (!This
->pipe
) { return E_OUTOFMEMORY
; } /* guess */
192 This
->pipe_sw
= This
->screen_sw
->context_create(This
->screen_sw
, NULL
, 0);
193 if (!This
->pipe_sw
) { return E_OUTOFMEMORY
; }
195 This
->cso
= cso_create_context(This
->pipe
);
196 if (!This
->cso
) { return E_OUTOFMEMORY
; } /* also a guess */
197 This
->cso_sw
= cso_create_context(This
->pipe_sw
);
198 if (!This
->cso_sw
) { return E_OUTOFMEMORY
; }
200 /* Create first, it messes up our state. */
201 This
->hud
= hud_create(This
->pipe
, This
->cso
); /* NULL result is fine */
203 /* Available memory counter. Updated only for allocations with this device
204 * instance. This is the Win 7 behavior.
205 * Win XP shares this counter across multiple devices. */
206 This
->available_texture_mem
= This
->screen
->get_param(This
->screen
, PIPE_CAP_VIDEO_MEMORY
);
207 if (This
->available_texture_mem
< 4096)
208 This
->available_texture_mem
<<= 20;
210 This
->available_texture_mem
= UINT_MAX
;
211 /* We cap texture memory usage to 80% of what is reported free initially
212 * This helps get closer Win behaviour. For example VertexBuffer allocation
213 * still succeeds when texture allocation fails. */
214 This
->available_texture_limit
= This
->available_texture_mem
* 20LL / 100LL;
216 /* create implicit swapchains */
217 This
->nswapchains
= ID3DPresentGroup_GetMultiheadCount(This
->present
);
218 This
->swapchains
= CALLOC(This
->nswapchains
,
219 sizeof(struct NineSwapChain9
*));
220 if (!This
->swapchains
) { return E_OUTOFMEMORY
; }
222 for (i
= 0; i
< This
->nswapchains
; ++i
) {
223 ID3DPresent
*present
;
225 hr
= ID3DPresentGroup_GetPresent(This
->present
, i
, &present
);
230 D3DDISPLAYMODEEX
*mode
= NULL
;
231 struct NineSwapChain9Ex
**ret
=
232 (struct NineSwapChain9Ex
**)&This
->swapchains
[i
];
234 if (pFullscreenDisplayMode
) mode
= &(pFullscreenDisplayMode
[i
]);
235 /* when this is a Device9Ex, it should create SwapChain9Exs */
236 hr
= NineSwapChain9Ex_new(This
, TRUE
, present
,
237 &pPresentationParameters
[i
], pCTX
,
238 This
->params
.hFocusWindow
, mode
, ret
);
240 hr
= NineSwapChain9_new(This
, TRUE
, present
,
241 &pPresentationParameters
[i
], pCTX
,
242 This
->params
.hFocusWindow
,
243 &This
->swapchains
[i
]);
246 ID3DPresent_Release(present
);
249 NineUnknown_ConvertRefToBind(NineUnknown(This
->swapchains
[i
]));
251 hr
= NineSwapChain9_GetBackBuffer(This
->swapchains
[i
], 0,
252 D3DBACKBUFFER_TYPE_MONO
,
253 (IDirect3DSurface9
**)
257 NineUnknown_ConvertRefToBind(NineUnknown(This
->state
.rt
[i
]));
260 /* Initialize a dummy VBO to be used when a vertex declaration does not
261 * specify all the inputs needed by vertex shader, on win default behavior
262 * is to pass 0,0,0,0 to the shader */
264 struct pipe_transfer
*transfer
;
265 struct pipe_resource tmpl
;
269 memset(&tmpl
, 0, sizeof(tmpl
));
270 tmpl
.target
= PIPE_BUFFER
;
271 tmpl
.format
= PIPE_FORMAT_R8_UNORM
;
272 tmpl
.width0
= 16; /* 4 floats */
278 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
279 tmpl
.bind
= PIPE_BIND_VERTEX_BUFFER
;
281 This
->dummy_vbo
= pScreen
->resource_create(pScreen
, &tmpl
);
283 if (!This
->dummy_vbo
)
284 return D3DERR_OUTOFVIDEOMEMORY
;
286 u_box_1d(0, 16, &box
);
287 data
= This
->pipe
->transfer_map(This
->pipe
, This
->dummy_vbo
, 0,
288 PIPE_TRANSFER_WRITE
|
289 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
294 This
->pipe
->transfer_unmap(This
->pipe
, transfer
);
297 This
->cursor
.software
= FALSE
;
298 This
->cursor
.hotspot
.x
= -1;
299 This
->cursor
.hotspot
.y
= -1;
301 struct pipe_resource tmpl
;
302 memset(&tmpl
, 0, sizeof(tmpl
));
303 tmpl
.target
= PIPE_TEXTURE_2D
;
304 tmpl
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
311 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
312 tmpl
.bind
= PIPE_BIND_CURSOR
| PIPE_BIND_SAMPLER_VIEW
;
315 This
->cursor
.image
= pScreen
->resource_create(pScreen
, &tmpl
);
316 if (!This
->cursor
.image
)
317 return D3DERR_OUTOFVIDEOMEMORY
;
319 /* For uploading 32x32 (argb) cursor */
320 This
->cursor
.hw_upload_temp
= MALLOC(32 * 4 * 32);
321 if (!This
->cursor
.hw_upload_temp
)
322 return D3DERR_OUTOFVIDEOMEMORY
;
325 /* Create constant buffers. */
327 unsigned max_const_vs
, max_const_ps
;
329 /* vs 3.0: >= 256 float constants, but for cards with exactly 256 slots,
330 * we have to take in some more slots for int and bool*/
331 max_const_vs
= _min(pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
,
332 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
) /
335 /* ps 3.0: 224 float constants. All cards supported support at least
336 * 256 constants for ps */
337 max_const_ps
= NINE_MAX_CONST_F_PS3
+ (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
339 This
->max_vs_const_f
= max_const_vs
-
340 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
341 This
->max_ps_const_f
= max_const_ps
-
342 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
344 This
->vs_const_size
= max_const_vs
* sizeof(float[4]);
345 This
->ps_const_size
= max_const_ps
* sizeof(float[4]);
346 /* Include space for I,B constants for user constbuf. */
347 if (This
->may_swvp
) {
348 This
->state
.vs_const_f_swvp
= CALLOC(NINE_MAX_CONST_F_SWVP
* sizeof(float[4]),1);
349 if (!This
->state
.vs_const_f_swvp
)
350 return E_OUTOFMEMORY
;
351 This
->state
.vs_lconstf_temp
= CALLOC(NINE_MAX_CONST_F_SWVP
* sizeof(float[4]),1);
352 This
->state
.vs_const_i
= CALLOC(NINE_MAX_CONST_I_SWVP
* sizeof(int[4]), 1);
353 This
->state
.vs_const_b
= CALLOC(NINE_MAX_CONST_B_SWVP
* sizeof(BOOL
), 1);
355 This
->state
.vs_const_f_swvp
= NULL
;
356 This
->state
.vs_lconstf_temp
= CALLOC(This
->vs_const_size
,1);
357 This
->state
.vs_const_i
= CALLOC(NINE_MAX_CONST_I
* sizeof(int[4]), 1);
358 This
->state
.vs_const_b
= CALLOC(NINE_MAX_CONST_B
* sizeof(BOOL
), 1);
360 This
->state
.vs_const_f
= CALLOC(This
->vs_const_size
, 1);
361 This
->state
.ps_const_f
= CALLOC(This
->ps_const_size
, 1);
362 This
->state
.ps_lconstf_temp
= CALLOC(This
->ps_const_size
,1);
363 if (!This
->state
.vs_const_f
|| !This
->state
.ps_const_f
||
364 !This
->state
.vs_lconstf_temp
|| !This
->state
.ps_lconstf_temp
||
365 !This
->state
.vs_const_i
|| !This
->state
.vs_const_b
)
366 return E_OUTOFMEMORY
;
368 if (strstr(pScreen
->get_name(pScreen
), "AMD") ||
369 strstr(pScreen
->get_name(pScreen
), "ATI")) {
370 This
->driver_bugs
.buggy_barycentrics
= TRUE
;
374 /* allocate dummy texture/sampler for when there are missing ones bound */
376 struct pipe_resource tmplt
;
377 struct pipe_sampler_view templ
;
378 struct pipe_sampler_state samp
;
379 memset(&tmplt
, 0, sizeof(tmplt
));
380 memset(&samp
, 0, sizeof(samp
));
382 tmplt
.target
= PIPE_TEXTURE_2D
;
386 tmplt
.last_level
= 0;
387 tmplt
.array_size
= 1;
388 tmplt
.usage
= PIPE_USAGE_DEFAULT
;
390 tmplt
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
391 tmplt
.bind
= PIPE_BIND_SAMPLER_VIEW
;
392 tmplt
.nr_samples
= 0;
394 This
->dummy_texture
= This
->screen
->resource_create(This
->screen
, &tmplt
);
395 if (!This
->dummy_texture
)
396 return D3DERR_DRIVERINTERNALERROR
;
398 templ
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
399 templ
.u
.tex
.first_layer
= 0;
400 templ
.u
.tex
.last_layer
= 0;
401 templ
.u
.tex
.first_level
= 0;
402 templ
.u
.tex
.last_level
= 0;
403 templ
.swizzle_r
= PIPE_SWIZZLE_0
;
404 templ
.swizzle_g
= PIPE_SWIZZLE_0
;
405 templ
.swizzle_b
= PIPE_SWIZZLE_0
;
406 templ
.swizzle_a
= PIPE_SWIZZLE_1
;
407 templ
.target
= This
->dummy_texture
->target
;
409 This
->dummy_sampler_view
= This
->pipe
->create_sampler_view(This
->pipe
, This
->dummy_texture
, &templ
);
410 if (!This
->dummy_sampler_view
)
411 return D3DERR_DRIVERINTERNALERROR
;
413 samp
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
414 samp
.max_lod
= 15.0f
;
415 samp
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
416 samp
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
417 samp
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
418 samp
.min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
419 samp
.mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
420 samp
.compare_mode
= PIPE_TEX_COMPARE_NONE
;
421 samp
.compare_func
= PIPE_FUNC_LEQUAL
;
422 samp
.normalized_coords
= 1;
423 samp
.seamless_cube_map
= 0;
424 This
->dummy_sampler_state
= samp
;
427 /* Allocate upload helper for drivers that suck (from st pov ;). */
429 This
->driver_caps
.user_vbufs
= GET_PCAP(USER_VERTEX_BUFFERS
);
430 This
->driver_caps
.user_ibufs
= GET_PCAP(USER_INDEX_BUFFERS
);
431 This
->driver_caps
.user_cbufs
= GET_PCAP(USER_CONSTANT_BUFFERS
);
432 This
->driver_caps
.user_sw_vbufs
= This
->screen_sw
->get_param(This
->screen_sw
, PIPE_CAP_USER_VERTEX_BUFFERS
);
433 This
->driver_caps
.user_sw_cbufs
= This
->screen_sw
->get_param(This
->screen_sw
, PIPE_CAP_USER_CONSTANT_BUFFERS
);
435 if (!This
->driver_caps
.user_vbufs
)
436 This
->vertex_uploader
= u_upload_create(This
->pipe
, 65536,
437 PIPE_BIND_VERTEX_BUFFER
, PIPE_USAGE_STREAM
);
438 This
->vertex_sw_uploader
= u_upload_create(This
->pipe_sw
, 65536,
439 PIPE_BIND_VERTEX_BUFFER
, PIPE_USAGE_STREAM
);
440 if (!This
->driver_caps
.user_ibufs
)
441 This
->index_uploader
= u_upload_create(This
->pipe
, 128 * 1024,
442 PIPE_BIND_INDEX_BUFFER
, PIPE_USAGE_STREAM
);
443 if (!This
->driver_caps
.user_cbufs
) {
444 This
->constbuf_alignment
= GET_PCAP(CONSTANT_BUFFER_OFFSET_ALIGNMENT
);
445 This
->constbuf_uploader
= u_upload_create(This
->pipe
, This
->vs_const_size
,
446 PIPE_BIND_CONSTANT_BUFFER
, PIPE_USAGE_STREAM
);
449 This
->constbuf_sw_uploader
= u_upload_create(This
->pipe_sw
, 128 * 1024,
450 PIPE_BIND_CONSTANT_BUFFER
, PIPE_USAGE_STREAM
);
452 This
->driver_caps
.window_space_position_support
= GET_PCAP(TGSI_VS_WINDOW_SPACE_POSITION
);
453 This
->driver_caps
.vs_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
, PIPE_SHADER_CAP_INTEGERS
);
454 This
->driver_caps
.ps_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_FRAGMENT
, PIPE_SHADER_CAP_INTEGERS
);
455 This
->driver_caps
.offset_units_unscaled
= GET_PCAP(POLYGON_OFFSET_UNITS_UNSCALED
);
457 nine_ff_init(This
); /* initialize fixed function code */
459 NineDevice9_SetDefaultState(This
, FALSE
);
462 struct pipe_poly_stipple stipple
;
463 memset(&stipple
, ~0, sizeof(stipple
));
464 This
->pipe
->set_polygon_stipple(This
->pipe
, &stipple
);
467 This
->update
= &This
->state
;
469 nine_state_init_sw(This
);
471 ID3DPresentGroup_Release(This
->present
);
478 NineDevice9_dtor( struct NineDevice9
*This
)
482 DBG("This=%p\n", This
);
484 if (This
->pipe
&& This
->cso
)
485 nine_pipe_context_clear(This
);
487 nine_state_destroy_sw(This
);
488 nine_state_clear(&This
->state
, TRUE
);
490 if (This
->vertex_uploader
)
491 u_upload_destroy(This
->vertex_uploader
);
492 if (This
->index_uploader
)
493 u_upload_destroy(This
->index_uploader
);
494 if (This
->constbuf_uploader
)
495 u_upload_destroy(This
->constbuf_uploader
);
496 if (This
->vertex_sw_uploader
)
497 u_upload_destroy(This
->vertex_sw_uploader
);
498 if (This
->constbuf_sw_uploader
)
499 u_upload_destroy(This
->constbuf_sw_uploader
);
501 nine_bind(&This
->record
, NULL
);
503 pipe_sampler_view_reference(&This
->dummy_sampler_view
, NULL
);
504 pipe_resource_reference(&This
->dummy_texture
, NULL
);
505 pipe_resource_reference(&This
->dummy_vbo
, NULL
);
506 FREE(This
->state
.vs_const_f
);
507 FREE(This
->state
.ps_const_f
);
508 FREE(This
->state
.vs_lconstf_temp
);
509 FREE(This
->state
.ps_lconstf_temp
);
510 FREE(This
->state
.vs_const_i
);
511 FREE(This
->state
.vs_const_b
);
512 FREE(This
->state
.vs_const_f_swvp
);
514 pipe_resource_reference(&This
->cursor
.image
, NULL
);
515 FREE(This
->cursor
.hw_upload_temp
);
517 if (This
->swapchains
) {
518 for (i
= 0; i
< This
->nswapchains
; ++i
)
519 if (This
->swapchains
[i
])
520 NineUnknown_Unbind(NineUnknown(This
->swapchains
[i
]));
521 FREE(This
->swapchains
);
524 /* Destroy cso first */
525 if (This
->cso
) { cso_destroy_context(This
->cso
); }
526 if (This
->cso_sw
) { cso_destroy_context(This
->cso_sw
); }
527 if (This
->pipe
&& This
->pipe
->destroy
) { This
->pipe
->destroy(This
->pipe
); }
528 if (This
->pipe_sw
&& This
->pipe_sw
->destroy
) { This
->pipe_sw
->destroy(This
->pipe_sw
); }
530 if (This
->present
) { ID3DPresentGroup_Release(This
->present
); }
531 if (This
->d3d9
) { IDirect3D9_Release(This
->d3d9
); }
533 NineUnknown_dtor(&This
->base
);
537 NineDevice9_GetScreen( struct NineDevice9
*This
)
542 struct pipe_context
*
543 NineDevice9_GetPipe( struct NineDevice9
*This
)
549 NineDevice9_GetCSO( struct NineDevice9
*This
)
555 NineDevice9_GetCaps( struct NineDevice9
*This
)
561 NineDevice9_PauseRecording( struct NineDevice9
*This
)
564 This
->update
= &This
->state
;
565 This
->is_recording
= FALSE
;
570 NineDevice9_ResumeRecording( struct NineDevice9
*This
)
573 This
->update
= &This
->record
->state
;
574 This
->is_recording
= TRUE
;
579 NineDevice9_TestCooperativeLevel( struct NineDevice9
*This
)
581 if (NineSwapChain9_GetOccluded(This
->swapchains
[0])) {
582 This
->device_needs_reset
= TRUE
;
583 return D3DERR_DEVICELOST
;
584 } else if (NineSwapChain9_ResolutionMismatch(This
->swapchains
[0])) {
585 This
->device_needs_reset
= TRUE
;
586 return D3DERR_DEVICENOTRESET
;
587 } else if (This
->device_needs_reset
) {
588 return D3DERR_DEVICENOTRESET
;
595 NineDevice9_GetAvailableTextureMem( struct NineDevice9
*This
)
597 return This
->available_texture_mem
;
601 NineDevice9_EvictManagedResources( struct NineDevice9
*This
)
603 struct NineBaseTexture9
*tex
;
604 struct NineBuffer9
*buf
;
606 DBG("This=%p\n", This
);
607 LIST_FOR_EACH_ENTRY(tex
, &This
->managed_textures
, list2
) {
608 NineBaseTexture9_UnLoad(tex
);
610 /* Vertex/index buffers don't take a lot of space and aren't accounted
611 * for d3d memory usage. Instead of actually freeing from memory,
612 * just mark the buffer dirty to trigger a re-upload later. We
613 * could just ignore, but some bad behaving apps could rely on it (if
614 * they write outside the locked regions typically). */
615 LIST_FOR_EACH_ENTRY(buf
, &This
->managed_buffers
, managed
.list2
) {
616 NineBuffer9_SetDirty(buf
);
623 NineDevice9_GetDirect3D( struct NineDevice9
*This
,
624 IDirect3D9
**ppD3D9
)
626 user_assert(ppD3D9
!= NULL
, E_POINTER
);
627 IDirect3D9_AddRef(This
->d3d9
);
628 *ppD3D9
= This
->d3d9
;
633 NineDevice9_GetDeviceCaps( struct NineDevice9
*This
,
636 user_assert(pCaps
!= NULL
, D3DERR_INVALIDCALL
);
642 NineDevice9_GetDisplayMode( struct NineDevice9
*This
,
644 D3DDISPLAYMODE
*pMode
)
646 DBG("This=%p iSwapChain=%u pMode=%p\n", This
, iSwapChain
, pMode
);
648 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
650 return NineSwapChain9_GetDisplayMode(This
->swapchains
[iSwapChain
], pMode
);
654 NineDevice9_GetCreationParameters( struct NineDevice9
*This
,
655 D3DDEVICE_CREATION_PARAMETERS
*pParameters
)
657 user_assert(pParameters
!= NULL
, D3DERR_INVALIDCALL
);
658 *pParameters
= This
->params
;
663 NineDevice9_SetCursorProperties( struct NineDevice9
*This
,
666 IDirect3DSurface9
*pCursorBitmap
)
668 struct NineSurface9
*surf
= NineSurface9(pCursorBitmap
);
669 struct pipe_context
*pipe
= This
->pipe
;
671 struct pipe_transfer
*transfer
;
675 DBG_FLAG(DBG_SWAPCHAIN
, "This=%p XHotSpot=%u YHotSpot=%u "
676 "pCursorBitmap=%p\n", This
, XHotSpot
, YHotSpot
, pCursorBitmap
);
678 user_assert(pCursorBitmap
, D3DERR_INVALIDCALL
);
679 user_assert(surf
->desc
.Format
== D3DFMT_A8R8G8B8
, D3DERR_INVALIDCALL
);
681 if (This
->swapchains
[0]->params
.Windowed
) {
682 This
->cursor
.w
= MIN2(surf
->desc
.Width
, 32);
683 This
->cursor
.h
= MIN2(surf
->desc
.Height
, 32);
684 hw_cursor
= 1; /* always use hw cursor for windowed mode */
686 This
->cursor
.w
= MIN2(surf
->desc
.Width
, This
->cursor
.image
->width0
);
687 This
->cursor
.h
= MIN2(surf
->desc
.Height
, This
->cursor
.image
->height0
);
688 hw_cursor
= This
->cursor
.w
== 32 && This
->cursor
.h
== 32;
691 u_box_origin_2d(This
->cursor
.w
, This
->cursor
.h
, &box
);
693 ptr
= pipe
->transfer_map(pipe
, This
->cursor
.image
, 0,
694 PIPE_TRANSFER_WRITE
|
695 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
698 ret_err("Failed to update cursor image.\n", D3DERR_DRIVERINTERNALERROR
);
700 This
->cursor
.hotspot
.x
= XHotSpot
;
701 This
->cursor
.hotspot
.y
= YHotSpot
;
703 /* Copy cursor image to internal storage. */
707 const struct util_format_description
*sfmt
=
708 util_format_description(surf
->base
.info
.format
);
711 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, D3DLOCK_READONLY
);
713 ret_err("Failed to map cursor source image.\n",
714 D3DERR_DRIVERINTERNALERROR
);
716 sfmt
->unpack_rgba_8unorm(ptr
, transfer
->stride
,
717 lock
.pBits
, lock
.Pitch
,
718 This
->cursor
.w
, This
->cursor
.h
);
721 void *data
= lock
.pBits
;
722 /* SetCursor assumes 32x32 argb with pitch 128 */
723 if (lock
.Pitch
!= 128) {
724 sfmt
->unpack_rgba_8unorm(This
->cursor
.hw_upload_temp
, 128,
725 lock
.pBits
, lock
.Pitch
,
727 data
= This
->cursor
.hw_upload_temp
;
729 hw_cursor
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
,
731 &This
->cursor
.hotspot
,
732 This
->cursor
.visible
) == D3D_OK
;
735 NineSurface9_UnlockRect(surf
);
737 pipe
->transfer_unmap(pipe
, transfer
);
739 /* hide cursor if we emulate it */
741 ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, FALSE
);
742 This
->cursor
.software
= !hw_cursor
;
748 NineDevice9_SetCursorPosition( struct NineDevice9
*This
,
753 struct NineSwapChain9
*swap
= This
->swapchains
[0];
755 DBG("This=%p X=%d Y=%d Flags=%d\n", This
, X
, Y
, Flags
);
757 This
->cursor
.pos
.x
= X
;
758 This
->cursor
.pos
.y
= Y
;
760 if (!This
->cursor
.software
)
761 This
->cursor
.software
= ID3DPresent_SetCursorPos(swap
->present
, &This
->cursor
.pos
) != D3D_OK
;
765 NineDevice9_ShowCursor( struct NineDevice9
*This
,
768 BOOL old
= This
->cursor
.visible
;
770 DBG("This=%p bShow=%d\n", This
, (int) bShow
);
772 This
->cursor
.visible
= bShow
&& (This
->cursor
.hotspot
.x
!= -1);
773 if (!This
->cursor
.software
)
774 This
->cursor
.software
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, bShow
) != D3D_OK
;
780 NineDevice9_CreateAdditionalSwapChain( struct NineDevice9
*This
,
781 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
782 IDirect3DSwapChain9
**pSwapChain
)
784 struct NineSwapChain9
*swapchain
, *tmplt
= This
->swapchains
[0];
785 ID3DPresent
*present
;
788 DBG("This=%p pPresentationParameters=%p pSwapChain=%p\n",
789 This
, pPresentationParameters
, pSwapChain
);
791 user_assert(pPresentationParameters
, D3DERR_INVALIDCALL
);
792 user_assert(tmplt
->params
.Windowed
&& pPresentationParameters
->Windowed
, D3DERR_INVALIDCALL
);
794 /* TODO: this deserves more tests */
795 if (!pPresentationParameters
->hDeviceWindow
)
796 pPresentationParameters
->hDeviceWindow
= This
->params
.hFocusWindow
;
798 hr
= ID3DPresentGroup_CreateAdditionalPresent(This
->present
, pPresentationParameters
, &present
);
803 hr
= NineSwapChain9_new(This
, FALSE
, present
, pPresentationParameters
,
805 tmplt
->params
.hDeviceWindow
,
810 *pSwapChain
= (IDirect3DSwapChain9
*)swapchain
;
815 NineDevice9_GetSwapChain( struct NineDevice9
*This
,
817 IDirect3DSwapChain9
**pSwapChain
)
819 user_assert(pSwapChain
!= NULL
, D3DERR_INVALIDCALL
);
822 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
824 NineUnknown_AddRef(NineUnknown(This
->swapchains
[iSwapChain
]));
825 *pSwapChain
= (IDirect3DSwapChain9
*)This
->swapchains
[iSwapChain
];
831 NineDevice9_GetNumberOfSwapChains( struct NineDevice9
*This
)
833 return This
->nswapchains
;
837 NineDevice9_Reset( struct NineDevice9
*This
,
838 D3DPRESENT_PARAMETERS
*pPresentationParameters
)
843 DBG("This=%p pPresentationParameters=%p\n", This
, pPresentationParameters
);
845 if (NineSwapChain9_GetOccluded(This
->swapchains
[0])) {
846 This
->device_needs_reset
= TRUE
;
847 return D3DERR_DEVICELOST
;
850 for (i
= 0; i
< This
->nswapchains
; ++i
) {
851 D3DPRESENT_PARAMETERS
*params
= &pPresentationParameters
[i
];
852 hr
= NineSwapChain9_Resize(This
->swapchains
[i
], params
, NULL
);
857 nine_pipe_context_clear(This
);
858 nine_state_clear(&This
->state
, TRUE
);
860 NineDevice9_SetDefaultState(This
, TRUE
);
861 NineDevice9_SetRenderTarget(
862 This
, 0, (IDirect3DSurface9
*)This
->swapchains
[0]->buffers
[0]);
863 /* XXX: better use GetBackBuffer here ? */
865 This
->device_needs_reset
= (hr
!= D3D_OK
);
870 NineDevice9_Present( struct NineDevice9
*This
,
871 const RECT
*pSourceRect
,
872 const RECT
*pDestRect
,
873 HWND hDestWindowOverride
,
874 const RGNDATA
*pDirtyRegion
)
879 DBG("This=%p pSourceRect=%p pDestRect=%p hDestWindowOverride=%p pDirtyRegion=%p\n",
880 This
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
882 /* XXX is this right? */
883 for (i
= 0; i
< This
->nswapchains
; ++i
) {
884 hr
= NineSwapChain9_Present(This
->swapchains
[i
], pSourceRect
, pDestRect
,
885 hDestWindowOverride
, pDirtyRegion
, 0);
886 if (FAILED(hr
)) { return hr
; }
893 NineDevice9_GetBackBuffer( struct NineDevice9
*This
,
896 D3DBACKBUFFER_TYPE Type
,
897 IDirect3DSurface9
**ppBackBuffer
)
899 user_assert(ppBackBuffer
!= NULL
, D3DERR_INVALIDCALL
);
900 /* return NULL on error */
901 *ppBackBuffer
= NULL
;
902 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
904 return NineSwapChain9_GetBackBuffer(This
->swapchains
[iSwapChain
],
905 iBackBuffer
, Type
, ppBackBuffer
);
909 NineDevice9_GetRasterStatus( struct NineDevice9
*This
,
911 D3DRASTER_STATUS
*pRasterStatus
)
913 user_assert(pRasterStatus
!= NULL
, D3DERR_INVALIDCALL
);
914 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
916 return NineSwapChain9_GetRasterStatus(This
->swapchains
[iSwapChain
],
921 NineDevice9_SetDialogBoxMode( struct NineDevice9
*This
,
922 BOOL bEnableDialogs
)
924 STUB(D3DERR_INVALIDCALL
);
928 NineDevice9_SetGammaRamp( struct NineDevice9
*This
,
931 const D3DGAMMARAMP
*pRamp
)
933 DBG("This=%p iSwapChain=%u Flags=%x pRamp=%p\n", This
,
934 iSwapChain
, Flags
, pRamp
);
936 user_warn(iSwapChain
>= This
->nswapchains
);
939 if (pRamp
&& (iSwapChain
< This
->nswapchains
)) {
940 struct NineSwapChain9
*swap
= This
->swapchains
[iSwapChain
];
941 swap
->gamma
= *pRamp
;
942 ID3DPresent_SetGammaRamp(swap
->present
, pRamp
, swap
->params
.hDeviceWindow
);
947 NineDevice9_GetGammaRamp( struct NineDevice9
*This
,
949 D3DGAMMARAMP
*pRamp
)
951 DBG("This=%p iSwapChain=%u pRamp=%p\n", This
, iSwapChain
, pRamp
);
953 user_warn(iSwapChain
>= This
->nswapchains
);
956 if (pRamp
&& (iSwapChain
< This
->nswapchains
))
957 *pRamp
= This
->swapchains
[iSwapChain
]->gamma
;
961 NineDevice9_CreateTexture( struct NineDevice9
*This
,
968 IDirect3DTexture9
**ppTexture
,
969 HANDLE
*pSharedHandle
)
971 struct NineTexture9
*tex
;
974 DBG("This=%p Width=%u Height=%u Levels=%u Usage=%s Format=%s Pool=%s "
975 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Levels
,
976 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
977 nine_D3DPOOL_to_str(Pool
), ppTexture
, pSharedHandle
);
979 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DMAP
|
980 D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
981 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
;
985 hr
= NineTexture9_new(This
, Width
, Height
, Levels
, Usage
, Format
, Pool
,
986 &tex
, pSharedHandle
);
988 *ppTexture
= (IDirect3DTexture9
*)tex
;
994 NineDevice9_CreateVolumeTexture( struct NineDevice9
*This
,
1002 IDirect3DVolumeTexture9
**ppVolumeTexture
,
1003 HANDLE
*pSharedHandle
)
1005 struct NineVolumeTexture9
*tex
;
1008 DBG("This=%p Width=%u Height=%u Depth=%u Levels=%u Usage=%s Format=%s Pool=%s "
1009 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Depth
, Levels
,
1010 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
1011 nine_D3DPOOL_to_str(Pool
), ppVolumeTexture
, pSharedHandle
);
1013 Usage
&= D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1014 D3DUSAGE_SOFTWAREPROCESSING
;
1016 *ppVolumeTexture
= NULL
;
1018 hr
= NineVolumeTexture9_new(This
, Width
, Height
, Depth
, Levels
,
1019 Usage
, Format
, Pool
, &tex
, pSharedHandle
);
1021 *ppVolumeTexture
= (IDirect3DVolumeTexture9
*)tex
;
1027 NineDevice9_CreateCubeTexture( struct NineDevice9
*This
,
1033 IDirect3DCubeTexture9
**ppCubeTexture
,
1034 HANDLE
*pSharedHandle
)
1036 struct NineCubeTexture9
*tex
;
1039 DBG("This=%p EdgeLength=%u Levels=%u Usage=%s Format=%s Pool=%s ppOut=%p "
1040 "pSharedHandle=%p\n", This
, EdgeLength
, Levels
,
1041 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
1042 nine_D3DPOOL_to_str(Pool
), ppCubeTexture
, pSharedHandle
);
1044 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DYNAMIC
|
1045 D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
1046 D3DUSAGE_SOFTWAREPROCESSING
;
1048 *ppCubeTexture
= NULL
;
1050 hr
= NineCubeTexture9_new(This
, EdgeLength
, Levels
, Usage
, Format
, Pool
,
1051 &tex
, pSharedHandle
);
1053 *ppCubeTexture
= (IDirect3DCubeTexture9
*)tex
;
1059 NineDevice9_CreateVertexBuffer( struct NineDevice9
*This
,
1064 IDirect3DVertexBuffer9
**ppVertexBuffer
,
1065 HANDLE
*pSharedHandle
)
1067 struct NineVertexBuffer9
*buf
;
1069 D3DVERTEXBUFFER_DESC desc
;
1071 DBG("This=%p Length=%u Usage=%x FVF=%x Pool=%u ppOut=%p pSharedHandle=%p\n",
1072 This
, Length
, Usage
, FVF
, Pool
, ppVertexBuffer
, pSharedHandle
);
1074 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1076 desc
.Format
= D3DFMT_VERTEXDATA
;
1077 desc
.Type
= D3DRTYPE_VERTEXBUFFER
;
1078 desc
.Usage
= Usage
&
1079 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1080 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1081 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
|
1082 D3DUSAGE_WRITEONLY
);
1087 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1088 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1090 hr
= NineVertexBuffer9_new(This
, &desc
, &buf
);
1092 *ppVertexBuffer
= (IDirect3DVertexBuffer9
*)buf
;
1097 NineDevice9_CreateIndexBuffer( struct NineDevice9
*This
,
1102 IDirect3DIndexBuffer9
**ppIndexBuffer
,
1103 HANDLE
*pSharedHandle
)
1105 struct NineIndexBuffer9
*buf
;
1107 D3DINDEXBUFFER_DESC desc
;
1109 DBG("This=%p Length=%u Usage=%x Format=%s Pool=%u ppOut=%p "
1110 "pSharedHandle=%p\n", This
, Length
, Usage
,
1111 d3dformat_to_string(Format
), Pool
, ppIndexBuffer
, pSharedHandle
);
1113 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1115 desc
.Format
= Format
;
1116 desc
.Type
= D3DRTYPE_INDEXBUFFER
;
1117 desc
.Usage
= Usage
&
1118 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1119 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1120 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_WRITEONLY
);
1124 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1125 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1127 hr
= NineIndexBuffer9_new(This
, &desc
, &buf
);
1129 *ppIndexBuffer
= (IDirect3DIndexBuffer9
*)buf
;
1134 create_zs_or_rt_surface(struct NineDevice9
*This
,
1135 unsigned type
, /* 0 = RT, 1 = ZS, 2 = plain */
1137 UINT Width
, UINT Height
,
1139 D3DMULTISAMPLE_TYPE MultiSample
,
1140 DWORD MultisampleQuality
,
1141 BOOL Discard_or_Lockable
,
1142 IDirect3DSurface9
**ppSurface
,
1143 HANDLE
*pSharedHandle
)
1145 struct NineSurface9
*surface
;
1147 D3DSURFACE_DESC desc
;
1149 DBG("This=%p type=%u Pool=%s Width=%u Height=%u Format=%s MS=%u Quality=%u "
1150 "Discard_or_Lockable=%i ppSurface=%p pSharedHandle=%p\n",
1151 This
, type
, nine_D3DPOOL_to_str(Pool
), Width
, Height
,
1152 d3dformat_to_string(Format
), MultiSample
, MultisampleQuality
,
1153 Discard_or_Lockable
, ppSurface
, pSharedHandle
);
1156 DBG("FIXME Used shared handle! This option isn't probably handled correctly!\n");
1158 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
1159 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1161 desc
.Format
= Format
;
1162 desc
.Type
= D3DRTYPE_SURFACE
;
1165 desc
.MultiSampleType
= MultiSample
;
1166 desc
.MultiSampleQuality
= MultisampleQuality
;
1168 desc
.Height
= Height
;
1170 case 0: desc
.Usage
= D3DUSAGE_RENDERTARGET
; break;
1171 case 1: desc
.Usage
= D3DUSAGE_DEPTHSTENCIL
; break;
1172 default: assert(type
== 2); break;
1175 hr
= NineSurface9_new(This
, NULL
, NULL
, NULL
, 0, 0, 0, &desc
, &surface
);
1176 if (SUCCEEDED(hr
)) {
1177 *ppSurface
= (IDirect3DSurface9
*)surface
;
1179 if (surface
->base
.resource
&& Discard_or_Lockable
&& (type
!= 1))
1180 surface
->base
.resource
->flags
|= NINE_RESOURCE_FLAG_LOCKABLE
;
1187 NineDevice9_CreateRenderTarget( struct NineDevice9
*This
,
1191 D3DMULTISAMPLE_TYPE MultiSample
,
1192 DWORD MultisampleQuality
,
1194 IDirect3DSurface9
**ppSurface
,
1195 HANDLE
*pSharedHandle
)
1198 return create_zs_or_rt_surface(This
, 0, D3DPOOL_DEFAULT
,
1199 Width
, Height
, Format
,
1200 MultiSample
, MultisampleQuality
,
1201 Lockable
, ppSurface
, pSharedHandle
);
1205 NineDevice9_CreateDepthStencilSurface( struct NineDevice9
*This
,
1209 D3DMULTISAMPLE_TYPE MultiSample
,
1210 DWORD MultisampleQuality
,
1212 IDirect3DSurface9
**ppSurface
,
1213 HANDLE
*pSharedHandle
)
1216 if (!depth_stencil_format(Format
))
1217 return D3DERR_NOTAVAILABLE
;
1218 return create_zs_or_rt_surface(This
, 1, D3DPOOL_DEFAULT
,
1219 Width
, Height
, Format
,
1220 MultiSample
, MultisampleQuality
,
1221 Discard
, ppSurface
, pSharedHandle
);
1225 NineDevice9_UpdateSurface( struct NineDevice9
*This
,
1226 IDirect3DSurface9
*pSourceSurface
,
1227 const RECT
*pSourceRect
,
1228 IDirect3DSurface9
*pDestinationSurface
,
1229 const POINT
*pDestPoint
)
1231 struct NineSurface9
*dst
= NineSurface9(pDestinationSurface
);
1232 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1233 int copy_width
, copy_height
;
1236 DBG("This=%p pSourceSurface=%p pDestinationSurface=%p "
1237 "pSourceRect=%p pDestPoint=%p\n", This
,
1238 pSourceSurface
, pDestinationSurface
, pSourceRect
, pDestPoint
);
1240 DBG("pSourceRect = (%u,%u)-(%u,%u)\n",
1241 pSourceRect
->left
, pSourceRect
->top
,
1242 pSourceRect
->right
, pSourceRect
->bottom
);
1244 DBG("pDestPoint = (%u,%u)\n", pDestPoint
->x
, pDestPoint
->y
);
1246 user_assert(dst
&& src
, D3DERR_INVALIDCALL
);
1248 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1249 user_assert(src
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1251 user_assert(dst
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1252 user_assert(src
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1254 user_assert(!src
->lock_count
, D3DERR_INVALIDCALL
);
1255 user_assert(!dst
->lock_count
, D3DERR_INVALIDCALL
);
1257 user_assert(dst
->desc
.Format
== src
->desc
.Format
, D3DERR_INVALIDCALL
);
1258 user_assert(!depth_stencil_format(dst
->desc
.Format
), D3DERR_INVALIDCALL
);
1261 copy_width
= pSourceRect
->right
- pSourceRect
->left
;
1262 copy_height
= pSourceRect
->bottom
- pSourceRect
->top
;
1264 user_assert(pSourceRect
->left
>= 0 &&
1266 pSourceRect
->right
<= src
->desc
.Width
&&
1267 pSourceRect
->top
>= 0 &&
1269 pSourceRect
->bottom
<= src
->desc
.Height
,
1270 D3DERR_INVALIDCALL
);
1272 copy_width
= src
->desc
.Width
;
1273 copy_height
= src
->desc
.Height
;
1276 destRect
.right
= copy_width
;
1277 destRect
.bottom
= copy_height
;
1280 user_assert(pDestPoint
->x
>= 0 && pDestPoint
->y
>= 0,
1281 D3DERR_INVALIDCALL
);
1282 destRect
.right
+= pDestPoint
->x
;
1283 destRect
.bottom
+= pDestPoint
->y
;
1286 user_assert(destRect
.right
<= dst
->desc
.Width
&&
1287 destRect
.bottom
<= dst
->desc
.Height
,
1288 D3DERR_INVALIDCALL
);
1290 if (compressed_format(dst
->desc
.Format
)) {
1291 const unsigned w
= util_format_get_blockwidth(dst
->base
.info
.format
);
1292 const unsigned h
= util_format_get_blockheight(dst
->base
.info
.format
);
1295 user_assert(!(pDestPoint
->x
% w
) && !(pDestPoint
->y
% h
),
1296 D3DERR_INVALIDCALL
);
1300 user_assert(!(pSourceRect
->left
% w
) && !(pSourceRect
->top
% h
),
1301 D3DERR_INVALIDCALL
);
1303 if (!(copy_width
== src
->desc
.Width
&&
1304 copy_width
== dst
->desc
.Width
&&
1305 copy_height
== src
->desc
.Height
&&
1306 copy_height
== dst
->desc
.Height
)) {
1307 user_assert(!(copy_width
% w
) && !(copy_height
% h
),
1308 D3DERR_INVALIDCALL
);
1312 NineSurface9_CopyMemToDefault(dst
, src
, pDestPoint
, pSourceRect
);
1318 NineDevice9_UpdateTexture( struct NineDevice9
*This
,
1319 IDirect3DBaseTexture9
*pSourceTexture
,
1320 IDirect3DBaseTexture9
*pDestinationTexture
)
1322 struct NineBaseTexture9
*dstb
= NineBaseTexture9(pDestinationTexture
);
1323 struct NineBaseTexture9
*srcb
= NineBaseTexture9(pSourceTexture
);
1325 unsigned last_src_level
, last_dst_level
;
1328 DBG("This=%p pSourceTexture=%p pDestinationTexture=%p\n", This
,
1329 pSourceTexture
, pDestinationTexture
);
1331 user_assert(pSourceTexture
&& pDestinationTexture
, D3DERR_INVALIDCALL
);
1332 user_assert(pSourceTexture
!= pDestinationTexture
, D3DERR_INVALIDCALL
);
1334 user_assert(dstb
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1335 user_assert(srcb
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1336 user_assert(dstb
->base
.type
== srcb
->base
.type
, D3DERR_INVALIDCALL
);
1337 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ||
1338 dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
, D3DERR_INVALIDCALL
);
1341 * . Different formats
1342 * . Fewer src levels than dst levels (if the opposite, only matching levels
1343 * are supposed to be copied)
1344 * . Levels do not match
1345 * DDI: Actually the above should pass because of legacy applications
1346 * Do what you want about these, but you shouldn't crash.
1347 * However driver can expect that the top dimension is greater for src than dst.
1348 * Wine tests: Every combination that passes the initial checks should pass.
1349 * . Different formats => conversion driver and format dependent.
1350 * . 1 level, but size not matching => copy is done (and even crash if src bigger
1351 * than dst. For the case where dst bigger, wine doesn't test if a stretch is applied
1352 * or if a subrect is copied).
1353 * . 8x8 4 sublevels -> 7x7 2 sublevels => driver dependent, On NV seems to be 4x4 subrect
1356 * From these, the proposal is:
1357 * . Different formats -> use util_format_translate to translate if possible for surfaces.
1358 * Accept ARGB/XRGB for Volumes. Do nothing for the other combinations
1359 * . First level copied -> the first level such that src is smaller or equal to dst first level
1360 * . number of levels copied -> as long as it fits and textures have levels
1361 * That should satisfy the constraints (and instead of crashing for some cases we return D3D_OK)
1364 last_src_level
= (srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ? 0 : srcb
->base
.info
.last_level
;
1365 last_dst_level
= (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ? 0 : dstb
->base
.info
.last_level
;
1367 for (m
= 0; m
<= last_src_level
; ++m
) {
1368 unsigned w
= u_minify(srcb
->base
.info
.width0
, m
);
1369 unsigned h
= u_minify(srcb
->base
.info
.height0
, m
);
1370 unsigned d
= u_minify(srcb
->base
.info
.depth0
, m
);
1372 if (w
<= dstb
->base
.info
.width0
&&
1373 h
<= dstb
->base
.info
.height0
&&
1374 d
<= dstb
->base
.info
.depth0
)
1377 user_assert(m
<= last_src_level
, D3D_OK
);
1379 last_dst_level
= MIN2(srcb
->base
.info
.last_level
- m
, last_dst_level
);
1381 if (dstb
->base
.type
== D3DRTYPE_TEXTURE
) {
1382 struct NineTexture9
*dst
= NineTexture9(dstb
);
1383 struct NineTexture9
*src
= NineTexture9(srcb
);
1385 if (src
->dirty_rect
.width
== 0)
1388 pipe_box_to_rect(&rect
, &src
->dirty_rect
);
1389 for (l
= 0; l
< m
; ++l
)
1390 rect_minify_inclusive(&rect
);
1392 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
) {
1393 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1395 dst
->surfaces
[l
]->desc
.Width
,
1396 dst
->surfaces
[l
]->desc
.Height
);
1397 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
],
1401 rect_minify_inclusive(&rect
);
1403 u_box_origin_2d(0, 0, &src
->dirty_rect
);
1405 if (dstb
->base
.type
== D3DRTYPE_CUBETEXTURE
) {
1406 struct NineCubeTexture9
*dst
= NineCubeTexture9(dstb
);
1407 struct NineCubeTexture9
*src
= NineCubeTexture9(srcb
);
1410 /* GPUs usually have them stored as arrays of mip-mapped 2D textures. */
1411 for (z
= 0; z
< 6; ++z
) {
1412 if (src
->dirty_rect
[z
].width
== 0)
1415 pipe_box_to_rect(&rect
, &src
->dirty_rect
[z
]);
1416 for (l
= 0; l
< m
; ++l
)
1417 rect_minify_inclusive(&rect
);
1419 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
) {
1420 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1422 dst
->surfaces
[l
* 6 + z
]->desc
.Width
,
1423 dst
->surfaces
[l
* 6 + z
]->desc
.Height
);
1424 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
* 6 + z
],
1425 src
->surfaces
[m
* 6 + z
],
1428 rect_minify_inclusive(&rect
);
1430 u_box_origin_2d(0, 0, &src
->dirty_rect
[z
]);
1434 if (dstb
->base
.type
== D3DRTYPE_VOLUMETEXTURE
) {
1435 struct NineVolumeTexture9
*dst
= NineVolumeTexture9(dstb
);
1436 struct NineVolumeTexture9
*src
= NineVolumeTexture9(srcb
);
1438 if (src
->dirty_box
.width
== 0)
1440 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
)
1441 NineVolume9_CopyMemToDefault(dst
->volumes
[l
],
1442 src
->volumes
[m
], 0, 0, 0, NULL
);
1443 u_box_3d(0, 0, 0, 0, 0, 0, &src
->dirty_box
);
1445 assert(!"invalid texture type");
1448 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1449 dstb
->dirty_mip
= TRUE
;
1450 NineBaseTexture9_GenerateMipSubLevels(dstb
);
1457 NineDevice9_GetRenderTargetData( struct NineDevice9
*This
,
1458 IDirect3DSurface9
*pRenderTarget
,
1459 IDirect3DSurface9
*pDestSurface
)
1461 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1462 struct NineSurface9
*src
= NineSurface9(pRenderTarget
);
1464 DBG("This=%p pRenderTarget=%p pDestSurface=%p\n",
1465 This
, pRenderTarget
, pDestSurface
);
1467 user_assert(pRenderTarget
&& pDestSurface
, D3DERR_INVALIDCALL
);
1469 user_assert(dst
->desc
.Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1470 user_assert(src
->desc
.Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1472 user_assert(dst
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1473 user_assert(src
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1475 user_assert(src
->desc
.Width
== dst
->desc
.Width
, D3DERR_INVALIDCALL
);
1476 user_assert(src
->desc
.Height
== dst
->desc
.Height
, D3DERR_INVALIDCALL
);
1478 user_assert(src
->desc
.Format
!= D3DFMT_NULL
, D3DERR_INVALIDCALL
);
1480 NineSurface9_CopyDefaultToMem(dst
, src
);
1486 NineDevice9_GetFrontBufferData( struct NineDevice9
*This
,
1488 IDirect3DSurface9
*pDestSurface
)
1490 DBG("This=%p iSwapChain=%u pDestSurface=%p\n", This
,
1491 iSwapChain
, pDestSurface
);
1493 user_assert(pDestSurface
!= NULL
, D3DERR_INVALIDCALL
);
1494 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
1496 return NineSwapChain9_GetFrontBufferData(This
->swapchains
[iSwapChain
],
1501 NineDevice9_StretchRect( struct NineDevice9
*This
,
1502 IDirect3DSurface9
*pSourceSurface
,
1503 const RECT
*pSourceRect
,
1504 IDirect3DSurface9
*pDestSurface
,
1505 const RECT
*pDestRect
,
1506 D3DTEXTUREFILTERTYPE Filter
)
1508 struct pipe_screen
*screen
= This
->screen
;
1509 struct pipe_context
*pipe
= This
->pipe
;
1510 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1511 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1512 struct pipe_resource
*dst_res
= NineSurface9_GetResource(dst
);
1513 struct pipe_resource
*src_res
= NineSurface9_GetResource(src
);
1515 struct pipe_blit_info blit
;
1516 boolean scaled
, clamped
, ms
, flip_x
= FALSE
, flip_y
= FALSE
;
1518 DBG("This=%p pSourceSurface=%p pSourceRect=%p pDestSurface=%p "
1519 "pDestRect=%p Filter=%u\n",
1520 This
, pSourceSurface
, pSourceRect
, pDestSurface
, pDestRect
, Filter
);
1522 DBG("pSourceRect=(%u,%u)-(%u,%u)\n",
1523 pSourceRect
->left
, pSourceRect
->top
,
1524 pSourceRect
->right
, pSourceRect
->bottom
);
1526 DBG("pDestRect=(%u,%u)-(%u,%u)\n", pDestRect
->left
, pDestRect
->top
,
1527 pDestRect
->right
, pDestRect
->bottom
);
1529 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
&&
1530 src
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1531 zs
= util_format_is_depth_or_stencil(dst_res
->format
);
1532 user_assert(!zs
|| !This
->in_scene
, D3DERR_INVALIDCALL
);
1533 user_assert(!zs
|| !pSourceRect
||
1534 (pSourceRect
->left
== 0 &&
1535 pSourceRect
->top
== 0 &&
1536 pSourceRect
->right
== src
->desc
.Width
&&
1537 pSourceRect
->bottom
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1538 user_assert(!zs
|| !pDestRect
||
1539 (pDestRect
->left
== 0 &&
1540 pDestRect
->top
== 0 &&
1541 pDestRect
->right
== dst
->desc
.Width
&&
1542 pDestRect
->bottom
== dst
->desc
.Height
), D3DERR_INVALIDCALL
);
1544 (dst
->desc
.Width
== src
->desc
.Width
&&
1545 dst
->desc
.Height
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1546 user_assert(zs
|| !util_format_is_depth_or_stencil(src_res
->format
),
1547 D3DERR_INVALIDCALL
);
1548 user_assert(!zs
|| dst
->desc
.Format
== src
->desc
.Format
,
1549 D3DERR_INVALIDCALL
);
1550 user_assert(screen
->is_format_supported(screen
, src_res
->format
,
1552 src_res
->nr_samples
,
1553 PIPE_BIND_SAMPLER_VIEW
),
1554 D3DERR_INVALIDCALL
);
1556 /* We might want to permit these, but wine thinks we shouldn't. */
1557 user_assert(!pDestRect
||
1558 (pDestRect
->left
<= pDestRect
->right
&&
1559 pDestRect
->top
<= pDestRect
->bottom
), D3DERR_INVALIDCALL
);
1560 user_assert(!pSourceRect
||
1561 (pSourceRect
->left
<= pSourceRect
->right
&&
1562 pSourceRect
->top
<= pSourceRect
->bottom
), D3DERR_INVALIDCALL
);
1564 memset(&blit
, 0, sizeof(blit
));
1565 blit
.dst
.resource
= dst_res
;
1566 blit
.dst
.level
= dst
->level
;
1567 blit
.dst
.box
.z
= dst
->layer
;
1568 blit
.dst
.box
.depth
= 1;
1569 blit
.dst
.format
= dst_res
->format
;
1571 flip_x
= pDestRect
->left
> pDestRect
->right
;
1573 blit
.dst
.box
.x
= pDestRect
->right
;
1574 blit
.dst
.box
.width
= pDestRect
->left
- pDestRect
->right
;
1576 blit
.dst
.box
.x
= pDestRect
->left
;
1577 blit
.dst
.box
.width
= pDestRect
->right
- pDestRect
->left
;
1579 flip_y
= pDestRect
->top
> pDestRect
->bottom
;
1581 blit
.dst
.box
.y
= pDestRect
->bottom
;
1582 blit
.dst
.box
.height
= pDestRect
->top
- pDestRect
->bottom
;
1584 blit
.dst
.box
.y
= pDestRect
->top
;
1585 blit
.dst
.box
.height
= pDestRect
->bottom
- pDestRect
->top
;
1590 blit
.dst
.box
.width
= dst
->desc
.Width
;
1591 blit
.dst
.box
.height
= dst
->desc
.Height
;
1593 blit
.src
.resource
= src_res
;
1594 blit
.src
.level
= src
->level
;
1595 blit
.src
.box
.z
= src
->layer
;
1596 blit
.src
.box
.depth
= 1;
1597 blit
.src
.format
= src_res
->format
;
1599 if (flip_x
^ (pSourceRect
->left
> pSourceRect
->right
)) {
1600 blit
.src
.box
.x
= pSourceRect
->right
;
1601 blit
.src
.box
.width
= pSourceRect
->left
- pSourceRect
->right
;
1603 blit
.src
.box
.x
= pSourceRect
->left
;
1604 blit
.src
.box
.width
= pSourceRect
->right
- pSourceRect
->left
;
1606 if (flip_y
^ (pSourceRect
->top
> pSourceRect
->bottom
)) {
1607 blit
.src
.box
.y
= pSourceRect
->bottom
;
1608 blit
.src
.box
.height
= pSourceRect
->top
- pSourceRect
->bottom
;
1610 blit
.src
.box
.y
= pSourceRect
->top
;
1611 blit
.src
.box
.height
= pSourceRect
->bottom
- pSourceRect
->top
;
1614 blit
.src
.box
.x
= flip_x
? src
->desc
.Width
: 0;
1615 blit
.src
.box
.y
= flip_y
? src
->desc
.Height
: 0;
1616 blit
.src
.box
.width
= flip_x
? -src
->desc
.Width
: src
->desc
.Width
;
1617 blit
.src
.box
.height
= flip_y
? -src
->desc
.Height
: src
->desc
.Height
;
1619 blit
.mask
= zs
? PIPE_MASK_ZS
: PIPE_MASK_RGBA
;
1620 blit
.filter
= Filter
== D3DTEXF_LINEAR
?
1621 PIPE_TEX_FILTER_LINEAR
: PIPE_TEX_FILTER_NEAREST
;
1622 blit
.scissor_enable
= FALSE
;
1623 blit
.alpha_blend
= FALSE
;
1625 /* If both of a src and dst dimension are negative, flip them. */
1626 if (blit
.dst
.box
.width
< 0 && blit
.src
.box
.width
< 0) {
1627 blit
.dst
.box
.width
= -blit
.dst
.box
.width
;
1628 blit
.src
.box
.width
= -blit
.src
.box
.width
;
1630 if (blit
.dst
.box
.height
< 0 && blit
.src
.box
.height
< 0) {
1631 blit
.dst
.box
.height
= -blit
.dst
.box
.height
;
1632 blit
.src
.box
.height
= -blit
.src
.box
.height
;
1635 blit
.dst
.box
.width
!= blit
.src
.box
.width
||
1636 blit
.dst
.box
.height
!= blit
.src
.box
.height
;
1638 user_assert(!scaled
|| dst
!= src
, D3DERR_INVALIDCALL
);
1639 user_assert(!scaled
||
1640 !NineSurface9_IsOffscreenPlain(dst
), D3DERR_INVALIDCALL
);
1641 user_assert(!NineSurface9_IsOffscreenPlain(dst
) ||
1642 NineSurface9_IsOffscreenPlain(src
), D3DERR_INVALIDCALL
);
1643 user_assert(NineSurface9_IsOffscreenPlain(dst
) ||
1644 dst
->desc
.Usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
),
1645 D3DERR_INVALIDCALL
);
1646 user_assert(!scaled
||
1647 (!util_format_is_compressed(dst
->base
.info
.format
) &&
1648 !util_format_is_compressed(src
->base
.info
.format
)),
1649 D3DERR_INVALIDCALL
);
1651 user_warn(src
== dst
&&
1652 u_box_test_intersection_2d(&blit
.src
.box
, &blit
.dst
.box
));
1654 /* Check for clipping/clamping: */
1656 struct pipe_box box
;
1659 xy
= u_box_clip_2d(&box
, &blit
.dst
.box
,
1660 dst
->desc
.Width
, dst
->desc
.Height
);
1664 xy
= u_box_clip_2d(&box
, &blit
.src
.box
,
1665 src
->desc
.Width
, src
->desc
.Height
);
1669 ms
= (dst
->desc
.MultiSampleType
!= src
->desc
.MultiSampleType
) ||
1670 (dst
->desc
.MultiSampleQuality
!= src
->desc
.MultiSampleQuality
);
1672 if (clamped
|| scaled
|| (blit
.dst
.format
!= blit
.src
.format
) || ms
) {
1673 DBG("using pipe->blit()\n");
1674 /* TODO: software scaling */
1675 user_assert(screen
->is_format_supported(screen
, dst_res
->format
,
1677 dst_res
->nr_samples
,
1678 zs
? PIPE_BIND_DEPTH_STENCIL
:
1679 PIPE_BIND_RENDER_TARGET
),
1680 D3DERR_INVALIDCALL
);
1682 pipe
->blit(pipe
, &blit
);
1684 assert(blit
.dst
.box
.x
>= 0 && blit
.dst
.box
.y
>= 0 &&
1685 blit
.src
.box
.x
>= 0 && blit
.src
.box
.y
>= 0 &&
1686 blit
.dst
.box
.x
+ blit
.dst
.box
.width
<= dst
->desc
.Width
&&
1687 blit
.src
.box
.x
+ blit
.src
.box
.width
<= src
->desc
.Width
&&
1688 blit
.dst
.box
.y
+ blit
.dst
.box
.height
<= dst
->desc
.Height
&&
1689 blit
.src
.box
.y
+ blit
.src
.box
.height
<= src
->desc
.Height
);
1690 /* Or drivers might crash ... */
1691 DBG("Using resource_copy_region.\n");
1692 pipe
->resource_copy_region(pipe
,
1693 blit
.dst
.resource
, blit
.dst
.level
,
1694 blit
.dst
.box
.x
, blit
.dst
.box
.y
, blit
.dst
.box
.z
,
1695 blit
.src
.resource
, blit
.src
.level
,
1699 /* Communicate the container it needs to update sublevels - if apply */
1700 NineSurface9_MarkContainerDirty(dst
);
1706 NineDevice9_ColorFill( struct NineDevice9
*This
,
1707 IDirect3DSurface9
*pSurface
,
1711 struct pipe_context
*pipe
= This
->pipe
;
1712 struct NineSurface9
*surf
= NineSurface9(pSurface
);
1713 struct pipe_surface
*psurf
;
1714 unsigned x
, y
, w
, h
;
1715 union pipe_color_union rgba
;
1718 DBG("This=%p pSurface=%p pRect=%p color=%08x\n", This
,
1719 pSurface
, pRect
, color
);
1721 DBG("pRect=(%u,%u)-(%u,%u)\n", pRect
->left
, pRect
->top
,
1722 pRect
->right
, pRect
->bottom
);
1724 user_assert(surf
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1726 user_assert((surf
->base
.usage
& D3DUSAGE_RENDERTARGET
) ||
1727 NineSurface9_IsOffscreenPlain(surf
), D3DERR_INVALIDCALL
);
1729 user_assert(surf
->desc
.Format
!= D3DFMT_NULL
, D3D_OK
);
1734 w
= pRect
->right
- pRect
->left
;
1735 h
= pRect
->bottom
- pRect
->top
;
1737 if (compressed_format(surf
->desc
.Format
)) {
1738 const unsigned bw
= util_format_get_blockwidth(surf
->base
.info
.format
);
1739 const unsigned bh
= util_format_get_blockheight(surf
->base
.info
.format
);
1741 user_assert(!(x
% bw
) && !(y
% bh
) && !(w
% bw
) && !(h
% bh
),
1742 D3DERR_INVALIDCALL
);
1747 w
= surf
->desc
.Width
;
1748 h
= surf
->desc
.Height
;
1750 d3dcolor_to_pipe_color_union(&rgba
, color
);
1752 fallback
= !(surf
->base
.info
.bind
& PIPE_BIND_RENDER_TARGET
);
1755 psurf
= NineSurface9_GetSurface(surf
, 0);
1761 pipe
->clear_render_target(pipe
, psurf
, &rgba
, x
, y
, w
, h
, false);
1763 D3DLOCKED_RECT lock
;
1764 union util_color uc
;
1766 /* XXX: lock pRect and fix util_fill_rect */
1767 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, 0);
1770 util_pack_color_ub(color
>> 16, color
>> 8, color
>> 0, color
>> 24,
1771 surf
->base
.info
.format
, &uc
);
1772 util_fill_rect(lock
.pBits
, surf
->base
.info
.format
,lock
.Pitch
,
1774 NineSurface9_UnlockRect(surf
);
1781 NineDevice9_CreateOffscreenPlainSurface( struct NineDevice9
*This
,
1786 IDirect3DSurface9
**ppSurface
,
1787 HANDLE
*pSharedHandle
)
1791 DBG("This=%p Width=%u Height=%u Format=%s(0x%x) Pool=%u "
1792 "ppSurface=%p pSharedHandle=%p\n", This
,
1793 Width
, Height
, d3dformat_to_string(Format
), Format
, Pool
,
1794 ppSurface
, pSharedHandle
);
1797 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
1798 || Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1799 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1801 /* Can be used with StretchRect and ColorFill. It's also always lockable.
1803 hr
= create_zs_or_rt_surface(This
, 2, Pool
, Width
, Height
,
1805 D3DMULTISAMPLE_NONE
, 0,
1807 ppSurface
, pSharedHandle
);
1809 DBG("Failed to create surface.\n");
1814 NineDevice9_SetRenderTarget( struct NineDevice9
*This
,
1815 DWORD RenderTargetIndex
,
1816 IDirect3DSurface9
*pRenderTarget
)
1818 struct NineSurface9
*rt
= NineSurface9(pRenderTarget
);
1819 const unsigned i
= RenderTargetIndex
;
1821 DBG("This=%p RenderTargetIndex=%u pRenderTarget=%p\n", This
,
1822 RenderTargetIndex
, pRenderTarget
);
1824 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1825 user_assert(i
!= 0 || pRenderTarget
, D3DERR_INVALIDCALL
);
1826 user_assert(!pRenderTarget
||
1827 rt
->desc
.Usage
& D3DUSAGE_RENDERTARGET
, D3DERR_INVALIDCALL
);
1830 This
->state
.viewport
.X
= 0;
1831 This
->state
.viewport
.Y
= 0;
1832 This
->state
.viewport
.Width
= rt
->desc
.Width
;
1833 This
->state
.viewport
.Height
= rt
->desc
.Height
;
1834 This
->state
.viewport
.MinZ
= 0.0f
;
1835 This
->state
.viewport
.MaxZ
= 1.0f
;
1837 This
->state
.scissor
.minx
= 0;
1838 This
->state
.scissor
.miny
= 0;
1839 This
->state
.scissor
.maxx
= rt
->desc
.Width
;
1840 This
->state
.scissor
.maxy
= rt
->desc
.Height
;
1842 This
->state
.changed
.group
|= NINE_STATE_VIEWPORT
| NINE_STATE_SCISSOR
| NINE_STATE_MULTISAMPLE
;
1844 if (This
->state
.rt
[0] &&
1845 (This
->state
.rt
[0]->desc
.MultiSampleType
<= D3DMULTISAMPLE_NONMASKABLE
) !=
1846 (rt
->desc
.MultiSampleType
<= D3DMULTISAMPLE_NONMASKABLE
))
1847 This
->state
.changed
.group
|= NINE_STATE_SAMPLE_MASK
;
1850 if (This
->state
.rt
[i
] != NineSurface9(pRenderTarget
)) {
1851 nine_bind(&This
->state
.rt
[i
], pRenderTarget
);
1852 This
->state
.changed
.group
|= NINE_STATE_FB
;
1858 NineDevice9_GetRenderTarget( struct NineDevice9
*This
,
1859 DWORD RenderTargetIndex
,
1860 IDirect3DSurface9
**ppRenderTarget
)
1862 const unsigned i
= RenderTargetIndex
;
1864 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1865 user_assert(ppRenderTarget
, D3DERR_INVALIDCALL
);
1867 *ppRenderTarget
= (IDirect3DSurface9
*)This
->state
.rt
[i
];
1868 if (!This
->state
.rt
[i
])
1869 return D3DERR_NOTFOUND
;
1871 NineUnknown_AddRef(NineUnknown(This
->state
.rt
[i
]));
1876 NineDevice9_SetDepthStencilSurface( struct NineDevice9
*This
,
1877 IDirect3DSurface9
*pNewZStencil
)
1879 DBG("This=%p pNewZStencil=%p\n", This
, pNewZStencil
);
1881 if (This
->state
.ds
!= NineSurface9(pNewZStencil
)) {
1882 nine_bind(&This
->state
.ds
, pNewZStencil
);
1883 This
->state
.changed
.group
|= NINE_STATE_FB
;
1889 NineDevice9_GetDepthStencilSurface( struct NineDevice9
*This
,
1890 IDirect3DSurface9
**ppZStencilSurface
)
1892 user_assert(ppZStencilSurface
, D3DERR_INVALIDCALL
);
1894 *ppZStencilSurface
= (IDirect3DSurface9
*)This
->state
.ds
;
1895 if (!This
->state
.ds
)
1896 return D3DERR_NOTFOUND
;
1898 NineUnknown_AddRef(NineUnknown(This
->state
.ds
));
1903 NineDevice9_BeginScene( struct NineDevice9
*This
)
1905 DBG("This=%p\n", This
);
1906 user_assert(!This
->in_scene
, D3DERR_INVALIDCALL
);
1907 This
->in_scene
= TRUE
;
1908 /* Do we want to do anything else here ? */
1913 NineDevice9_EndScene( struct NineDevice9
*This
)
1915 DBG("This=%p\n", This
);
1916 user_assert(This
->in_scene
, D3DERR_INVALIDCALL
);
1917 This
->in_scene
= FALSE
;
1922 NineDevice9_Clear( struct NineDevice9
*This
,
1924 const D3DRECT
*pRects
,
1930 struct NineSurface9
*zsbuf_surf
= This
->state
.ds
;
1932 DBG("This=%p Count=%u pRects=%p Flags=%x Color=%08x Z=%f Stencil=%x\n",
1933 This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1935 user_assert(This
->state
.ds
|| !(Flags
& NINED3DCLEAR_DEPTHSTENCIL
),
1936 D3DERR_INVALIDCALL
);
1937 user_assert(!(Flags
& D3DCLEAR_STENCIL
) ||
1939 util_format_is_depth_and_stencil(zsbuf_surf
->base
.info
.format
)),
1940 D3DERR_INVALIDCALL
);
1942 user_assert((Count
&& pRects
) || (!Count
&& !pRects
), D3DERR_INVALIDCALL
);
1944 user_warn((pRects
&& !Count
) || (!pRects
&& Count
));
1945 if (pRects
&& !Count
)
1951 nine_context_clear_fb(This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1956 NineDevice9_SetTransform( struct NineDevice9
*This
,
1957 D3DTRANSFORMSTATETYPE State
,
1958 const D3DMATRIX
*pMatrix
)
1960 struct nine_state
*state
= This
->update
;
1961 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
1963 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
1965 user_assert(M
, D3DERR_INVALIDCALL
);
1968 state
->ff
.changed
.transform
[State
/ 32] |= 1 << (State
% 32);
1969 state
->changed
.group
|= NINE_STATE_FF
;
1975 NineDevice9_GetTransform( struct NineDevice9
*This
,
1976 D3DTRANSFORMSTATETYPE State
,
1977 D3DMATRIX
*pMatrix
)
1979 D3DMATRIX
*M
= nine_state_access_transform(&This
->state
, State
, FALSE
);
1980 user_assert(M
, D3DERR_INVALIDCALL
);
1986 NineDevice9_MultiplyTransform( struct NineDevice9
*This
,
1987 D3DTRANSFORMSTATETYPE State
,
1988 const D3DMATRIX
*pMatrix
)
1990 struct nine_state
*state
= This
->update
;
1992 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
1994 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
1996 user_assert(M
, D3DERR_INVALIDCALL
);
1998 nine_d3d_matrix_matrix_mul(&T
, pMatrix
, M
);
1999 return NineDevice9_SetTransform(This
, State
, &T
);
2003 NineDevice9_SetViewport( struct NineDevice9
*This
,
2004 const D3DVIEWPORT9
*pViewport
)
2006 struct nine_state
*state
= This
->update
;
2008 DBG("X=%u Y=%u W=%u H=%u MinZ=%f MaxZ=%f\n",
2009 pViewport
->X
, pViewport
->Y
, pViewport
->Width
, pViewport
->Height
,
2010 pViewport
->MinZ
, pViewport
->MaxZ
);
2012 state
->viewport
= *pViewport
;
2013 state
->changed
.group
|= NINE_STATE_VIEWPORT
;
2019 NineDevice9_GetViewport( struct NineDevice9
*This
,
2020 D3DVIEWPORT9
*pViewport
)
2022 *pViewport
= This
->state
.viewport
;
2027 NineDevice9_SetMaterial( struct NineDevice9
*This
,
2028 const D3DMATERIAL9
*pMaterial
)
2030 struct nine_state
*state
= This
->update
;
2032 DBG("This=%p pMaterial=%p\n", This
, pMaterial
);
2034 nine_dump_D3DMATERIAL9(DBG_FF
, pMaterial
);
2036 user_assert(pMaterial
, E_POINTER
);
2038 state
->ff
.material
= *pMaterial
;
2039 state
->changed
.group
|= NINE_STATE_FF_MATERIAL
;
2045 NineDevice9_GetMaterial( struct NineDevice9
*This
,
2046 D3DMATERIAL9
*pMaterial
)
2048 user_assert(pMaterial
, E_POINTER
);
2049 *pMaterial
= This
->state
.ff
.material
;
2054 NineDevice9_SetLight( struct NineDevice9
*This
,
2056 const D3DLIGHT9
*pLight
)
2058 struct nine_state
*state
= This
->update
;
2060 DBG("This=%p Index=%u pLight=%p\n", This
, Index
, pLight
);
2062 nine_dump_D3DLIGHT9(DBG_FF
, pLight
);
2064 user_assert(pLight
, D3DERR_INVALIDCALL
);
2065 user_assert(pLight
->Type
< NINED3DLIGHT_INVALID
, D3DERR_INVALIDCALL
);
2067 user_assert(Index
< NINE_MAX_LIGHTS
, D3DERR_INVALIDCALL
); /* sanity */
2069 if (Index
>= state
->ff
.num_lights
) {
2070 unsigned n
= state
->ff
.num_lights
;
2071 unsigned N
= Index
+ 1;
2073 state
->ff
.light
= REALLOC(state
->ff
.light
, n
* sizeof(D3DLIGHT9
),
2074 N
* sizeof(D3DLIGHT9
));
2075 if (!state
->ff
.light
)
2076 return E_OUTOFMEMORY
;
2077 state
->ff
.num_lights
= N
;
2079 for (; n
< Index
; ++n
) {
2080 memset(&state
->ff
.light
[n
], 0, sizeof(D3DLIGHT9
));
2081 state
->ff
.light
[n
].Type
= (D3DLIGHTTYPE
)NINED3DLIGHT_INVALID
;
2084 state
->ff
.light
[Index
] = *pLight
;
2086 if (pLight
->Type
== D3DLIGHT_SPOT
&& pLight
->Theta
>= pLight
->Phi
) {
2087 DBG("Warning: clamping D3DLIGHT9.Theta\n");
2088 state
->ff
.light
[Index
].Theta
= state
->ff
.light
[Index
].Phi
;
2090 if (pLight
->Type
!= D3DLIGHT_DIRECTIONAL
&&
2091 pLight
->Attenuation0
== 0.0f
&&
2092 pLight
->Attenuation1
== 0.0f
&&
2093 pLight
->Attenuation2
== 0.0f
) {
2094 DBG("Warning: all D3DLIGHT9.Attenuation[i] are 0\n");
2097 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2103 NineDevice9_GetLight( struct NineDevice9
*This
,
2107 const struct nine_state
*state
= &This
->state
;
2109 user_assert(pLight
, D3DERR_INVALIDCALL
);
2110 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2111 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2112 D3DERR_INVALIDCALL
);
2114 *pLight
= state
->ff
.light
[Index
];
2120 NineDevice9_LightEnable( struct NineDevice9
*This
,
2124 struct nine_state
*state
= This
->update
;
2127 DBG("This=%p Index=%u Enable=%i\n", This
, Index
, Enable
);
2129 if (Index
>= state
->ff
.num_lights
||
2130 state
->ff
.light
[Index
].Type
== NINED3DLIGHT_INVALID
) {
2131 /* This should create a default light. */
2133 memset(&light
, 0, sizeof(light
));
2134 light
.Type
= D3DLIGHT_DIRECTIONAL
;
2135 light
.Diffuse
.r
= 1.0f
;
2136 light
.Diffuse
.g
= 1.0f
;
2137 light
.Diffuse
.b
= 1.0f
;
2138 light
.Direction
.z
= 1.0f
;
2139 NineDevice9_SetLight(This
, Index
, &light
);
2141 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2143 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
) {
2144 if (state
->ff
.active_light
[i
] == Index
)
2149 if (i
< state
->ff
.num_lights_active
)
2151 /* XXX wine thinks this should still succeed:
2153 user_assert(i
< NINE_MAX_LIGHTS_ACTIVE
, D3DERR_INVALIDCALL
);
2155 state
->ff
.active_light
[i
] = Index
;
2156 state
->ff
.num_lights_active
++;
2158 if (i
== state
->ff
.num_lights_active
)
2160 --state
->ff
.num_lights_active
;
2161 for (; i
< state
->ff
.num_lights_active
; ++i
)
2162 state
->ff
.active_light
[i
] = state
->ff
.active_light
[i
+ 1];
2164 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2170 NineDevice9_GetLightEnable( struct NineDevice9
*This
,
2174 const struct nine_state
*state
= &This
->state
;
2177 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2178 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2179 D3DERR_INVALIDCALL
);
2181 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
)
2182 if (state
->ff
.active_light
[i
] == Index
)
2185 *pEnable
= i
!= state
->ff
.num_lights_active
? 128 : 0; // Taken from wine
2191 NineDevice9_SetClipPlane( struct NineDevice9
*This
,
2193 const float *pPlane
)
2195 struct nine_state
*state
= This
->update
;
2197 user_assert(pPlane
, D3DERR_INVALIDCALL
);
2199 DBG("This=%p Index=%u pPlane=%f %f %f %f\n", This
, Index
,
2200 pPlane
[0], pPlane
[1],
2201 pPlane
[2], pPlane
[3]);
2203 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2205 memcpy(&state
->clip
.ucp
[Index
][0], pPlane
, sizeof(state
->clip
.ucp
[0]));
2206 state
->changed
.ucp
|= 1 << Index
;
2212 NineDevice9_GetClipPlane( struct NineDevice9
*This
,
2216 const struct nine_state
*state
= &This
->state
;
2218 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2220 memcpy(pPlane
, &state
->clip
.ucp
[Index
][0], sizeof(state
->clip
.ucp
[0]));
2224 #define RESZ_CODE 0x7fa05000
2227 NineDevice9_ResolveZ( struct NineDevice9
*This
)
2229 struct nine_state
*state
= &This
->state
;
2230 const struct util_format_description
*desc
;
2231 struct NineSurface9
*source
= state
->ds
;
2232 struct NineBaseTexture9
*destination
= state
->texture
[0];
2233 struct pipe_resource
*src
, *dst
;
2234 struct pipe_blit_info blit
;
2236 DBG("RESZ resolve\n");
2238 user_assert(source
&& destination
&&
2239 destination
->base
.type
== D3DRTYPE_TEXTURE
, D3DERR_INVALIDCALL
);
2241 src
= source
->base
.resource
;
2242 dst
= destination
->base
.resource
;
2244 user_assert(src
&& dst
, D3DERR_INVALIDCALL
);
2246 /* check dst is depth format. we know already for src */
2247 desc
= util_format_description(dst
->format
);
2248 user_assert(desc
->colorspace
== UTIL_FORMAT_COLORSPACE_ZS
, D3DERR_INVALIDCALL
);
2250 memset(&blit
, 0, sizeof(blit
));
2251 blit
.src
.resource
= src
;
2253 blit
.src
.format
= src
->format
;
2255 blit
.src
.box
.depth
= 1;
2258 blit
.src
.box
.width
= src
->width0
;
2259 blit
.src
.box
.height
= src
->height0
;
2261 blit
.dst
.resource
= dst
;
2263 blit
.dst
.format
= dst
->format
;
2265 blit
.dst
.box
.depth
= 1;
2268 blit
.dst
.box
.width
= dst
->width0
;
2269 blit
.dst
.box
.height
= dst
->height0
;
2271 blit
.mask
= PIPE_MASK_ZS
;
2272 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
2273 blit
.scissor_enable
= FALSE
;
2275 This
->pipe
->blit(This
->pipe
, &blit
);
2279 #define ALPHA_TO_COVERAGE_ENABLE MAKEFOURCC('A', '2', 'M', '1')
2280 #define ALPHA_TO_COVERAGE_DISABLE MAKEFOURCC('A', '2', 'M', '0')
2283 NineDevice9_SetRenderState( struct NineDevice9
*This
,
2284 D3DRENDERSTATETYPE State
,
2287 struct nine_state
*state
= This
->update
;
2289 DBG("This=%p State=%u(%s) Value=%08x\n", This
,
2290 State
, nine_d3drs_to_string(State
), Value
);
2292 user_assert(State
< D3DRS_COUNT
, D3DERR_INVALIDCALL
);
2294 if (state
->rs_advertised
[State
] == Value
&& likely(!This
->is_recording
))
2297 state
->rs_advertised
[State
] = Value
;
2299 /* Amd hacks (equivalent to GL extensions) */
2300 if (unlikely(State
== D3DRS_POINTSIZE
)) {
2301 if (Value
== RESZ_CODE
)
2302 return NineDevice9_ResolveZ(This
);
2304 if (Value
== ALPHA_TO_COVERAGE_ENABLE
||
2305 Value
== ALPHA_TO_COVERAGE_DISABLE
) {
2306 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
== ALPHA_TO_COVERAGE_ENABLE
);
2307 state
->changed
.group
|= NINE_STATE_BLEND
;
2313 if (unlikely(State
== D3DRS_ADAPTIVETESS_Y
)) {
2314 if (Value
== D3DFMT_ATOC
|| (Value
== D3DFMT_UNKNOWN
&& state
->rs
[NINED3DRS_ALPHACOVERAGE
])) {
2315 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
== D3DFMT_ATOC
) ? 3 : 0;
2316 state
->rs
[NINED3DRS_ALPHACOVERAGE
] &= state
->rs
[D3DRS_ALPHATESTENABLE
] ? 3 : 2;
2317 state
->changed
.group
|= NINE_STATE_BLEND
;
2321 if (unlikely(State
== D3DRS_ALPHATESTENABLE
&& (state
->rs
[NINED3DRS_ALPHACOVERAGE
] & 2))) {
2322 DWORD alphacoverage_prev
= state
->rs
[NINED3DRS_ALPHACOVERAGE
];
2323 state
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
? 3 : 2);
2324 if (state
->rs
[NINED3DRS_ALPHACOVERAGE
] != alphacoverage_prev
)
2325 state
->changed
.group
|= NINE_STATE_BLEND
;
2328 state
->rs
[State
] = nine_fix_render_state_value(State
, Value
);
2329 state
->changed
.rs
[State
/ 32] |= 1 << (State
% 32);
2330 state
->changed
.group
|= nine_render_state_group
[State
];
2336 NineDevice9_GetRenderState( struct NineDevice9
*This
,
2337 D3DRENDERSTATETYPE State
,
2340 user_assert(State
< D3DRS_COUNT
, D3DERR_INVALIDCALL
);
2342 *pValue
= This
->state
.rs_advertised
[State
];
2347 NineDevice9_CreateStateBlock( struct NineDevice9
*This
,
2348 D3DSTATEBLOCKTYPE Type
,
2349 IDirect3DStateBlock9
**ppSB
)
2351 struct NineStateBlock9
*nsb
;
2352 struct nine_state
*dst
;
2354 enum nine_stateblock_type type
;
2357 DBG("This=%p Type=%u ppSB=%p\n", This
, Type
, ppSB
);
2359 user_assert(Type
== D3DSBT_ALL
||
2360 Type
== D3DSBT_VERTEXSTATE
||
2361 Type
== D3DSBT_PIXELSTATE
, D3DERR_INVALIDCALL
);
2364 case D3DSBT_VERTEXSTATE
: type
= NINESBT_VERTEXSTATE
; break;
2365 case D3DSBT_PIXELSTATE
: type
= NINESBT_PIXELSTATE
; break;
2371 hr
= NineStateBlock9_new(This
, &nsb
, type
);
2374 *ppSB
= (IDirect3DStateBlock9
*)nsb
;
2377 dst
->changed
.group
=
2378 NINE_STATE_TEXTURE
|
2381 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_VERTEXSTATE
) {
2382 dst
->changed
.group
|=
2383 NINE_STATE_FF_LIGHTING
|
2384 NINE_STATE_VS
| NINE_STATE_VS_CONST
|
2386 /* TODO: texture/sampler state */
2387 memcpy(dst
->changed
.rs
,
2388 nine_render_states_vertex
, sizeof(dst
->changed
.rs
));
2389 nine_ranges_insert(&dst
->changed
.vs_const_f
, 0, This
->may_swvp
? NINE_MAX_CONST_F_SWVP
: This
->max_vs_const_f
,
2391 nine_ranges_insert(&dst
->changed
.vs_const_i
, 0, This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
,
2393 nine_ranges_insert(&dst
->changed
.vs_const_b
, 0, This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
,
2395 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2396 dst
->changed
.sampler
[s
] |= 1 << D3DSAMP_DMAPOFFSET
;
2397 if (This
->state
.ff
.num_lights
) {
2398 dst
->ff
.num_lights
= This
->state
.ff
.num_lights
;
2399 /* zero'd -> light type won't be NINED3DLIGHT_INVALID, so
2400 * all currently existing lights will be captured
2402 dst
->ff
.light
= CALLOC(This
->state
.ff
.num_lights
,
2404 if (!dst
->ff
.light
) {
2405 nine_bind(ppSB
, NULL
);
2406 return E_OUTOFMEMORY
;
2410 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_PIXELSTATE
) {
2411 dst
->changed
.group
|=
2412 NINE_STATE_PS
| NINE_STATE_PS_CONST
| NINE_STATE_BLEND
|
2413 NINE_STATE_FF_OTHER
| NINE_STATE_FF_PSSTAGES
| NINE_STATE_PS_CONST
|
2414 NINE_STATE_FB
| NINE_STATE_DSA
| NINE_STATE_MULTISAMPLE
|
2415 NINE_STATE_RASTERIZER
| NINE_STATE_STENCIL_REF
;
2416 memcpy(dst
->changed
.rs
,
2417 nine_render_states_pixel
, sizeof(dst
->changed
.rs
));
2418 nine_ranges_insert(&dst
->changed
.ps_const_f
, 0, This
->max_ps_const_f
,
2420 dst
->changed
.ps_const_i
= 0xffff;
2421 dst
->changed
.ps_const_b
= 0xffff;
2422 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2423 dst
->changed
.sampler
[s
] |= 0x1ffe;
2424 for (s
= 0; s
< NINE_MAX_TEXTURE_STAGES
; ++s
) {
2425 dst
->ff
.changed
.tex_stage
[s
][0] |= 0xffffffff;
2426 dst
->ff
.changed
.tex_stage
[s
][1] |= 0xffffffff;
2429 if (Type
== D3DSBT_ALL
) {
2430 dst
->changed
.group
|=
2431 NINE_STATE_VIEWPORT
|
2432 NINE_STATE_SCISSOR
|
2433 NINE_STATE_RASTERIZER
|
2437 NINE_STATE_MATERIAL
|
2438 NINE_STATE_BLEND_COLOR
|
2439 NINE_STATE_SAMPLE_MASK
;
2440 memset(dst
->changed
.rs
, ~0, (D3DRS_COUNT
/ 32) * sizeof(uint32_t));
2441 dst
->changed
.rs
[D3DRS_LAST
/ 32] |= (1 << (D3DRS_COUNT
% 32)) - 1;
2442 dst
->changed
.vtxbuf
= (1ULL << This
->caps
.MaxStreams
) - 1;
2443 dst
->changed
.stream_freq
= dst
->changed
.vtxbuf
;
2444 dst
->changed
.ucp
= (1 << PIPE_MAX_CLIP_PLANES
) - 1;
2445 dst
->changed
.texture
= (1 << NINE_MAX_SAMPLERS
) - 1;
2447 NineStateBlock9_Capture(NineStateBlock9(*ppSB
));
2449 /* TODO: fixed function state */
2455 NineDevice9_BeginStateBlock( struct NineDevice9
*This
)
2459 DBG("This=%p\n", This
);
2461 user_assert(!This
->record
, D3DERR_INVALIDCALL
);
2463 hr
= NineStateBlock9_new(This
, &This
->record
, NINESBT_CUSTOM
);
2466 NineUnknown_ConvertRefToBind(NineUnknown(This
->record
));
2468 This
->update
= &This
->record
->state
;
2469 This
->is_recording
= TRUE
;
2475 NineDevice9_EndStateBlock( struct NineDevice9
*This
,
2476 IDirect3DStateBlock9
**ppSB
)
2478 DBG("This=%p ppSB=%p\n", This
, ppSB
);
2480 user_assert(This
->record
, D3DERR_INVALIDCALL
);
2482 This
->update
= &This
->state
;
2483 This
->is_recording
= FALSE
;
2485 NineUnknown_AddRef(NineUnknown(This
->record
));
2486 *ppSB
= (IDirect3DStateBlock9
*)This
->record
;
2487 NineUnknown_Unbind(NineUnknown(This
->record
));
2488 This
->record
= NULL
;
2494 NineDevice9_SetClipStatus( struct NineDevice9
*This
,
2495 const D3DCLIPSTATUS9
*pClipStatus
)
2497 STUB(D3DERR_INVALIDCALL
);
2501 NineDevice9_GetClipStatus( struct NineDevice9
*This
,
2502 D3DCLIPSTATUS9
*pClipStatus
)
2504 STUB(D3DERR_INVALIDCALL
);
2508 NineDevice9_GetTexture( struct NineDevice9
*This
,
2510 IDirect3DBaseTexture9
**ppTexture
)
2512 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2513 Stage
== D3DDMAPSAMPLER
||
2514 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2515 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2516 user_assert(ppTexture
, D3DERR_INVALIDCALL
);
2518 if (Stage
>= D3DDMAPSAMPLER
)
2519 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2521 *ppTexture
= (IDirect3DBaseTexture9
*)This
->state
.texture
[Stage
];
2523 if (This
->state
.texture
[Stage
])
2524 NineUnknown_AddRef(NineUnknown(This
->state
.texture
[Stage
]));
2529 NineDevice9_SetTexture( struct NineDevice9
*This
,
2531 IDirect3DBaseTexture9
*pTexture
)
2533 struct nine_state
*state
= This
->update
;
2534 struct NineBaseTexture9
*tex
= NineBaseTexture9(pTexture
);
2536 DBG("This=%p Stage=%u pTexture=%p\n", This
, Stage
, pTexture
);
2538 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2539 Stage
== D3DDMAPSAMPLER
||
2540 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2541 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2542 user_assert(!tex
|| (tex
->base
.pool
!= D3DPOOL_SCRATCH
&&
2543 tex
->base
.pool
!= D3DPOOL_SYSTEMMEM
), D3DERR_INVALIDCALL
);
2545 if (Stage
>= D3DDMAPSAMPLER
)
2546 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2548 if (!This
->is_recording
) {
2549 struct NineBaseTexture9
*old
= state
->texture
[Stage
];
2553 state
->samplers_shadow
&= ~(1 << Stage
);
2555 state
->samplers_shadow
|= tex
->shadow
<< Stage
;
2557 if ((tex
->managed
.dirty
| tex
->dirty_mip
) && LIST_IS_EMPTY(&tex
->list
))
2558 list_add(&tex
->list
, &This
->update_textures
);
2565 nine_bind(&state
->texture
[Stage
], pTexture
);
2567 state
->changed
.texture
|= 1 << Stage
;
2568 state
->changed
.group
|= NINE_STATE_TEXTURE
;
2574 NineDevice9_GetTextureStageState( struct NineDevice9
*This
,
2576 D3DTEXTURESTAGESTATETYPE Type
,
2579 const struct nine_state
*state
= &This
->state
;
2581 user_assert(Stage
< ARRAY_SIZE(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2582 user_assert(Type
< ARRAY_SIZE(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2584 *pValue
= state
->ff
.tex_stage
[Stage
][Type
];
2590 NineDevice9_SetTextureStageState( struct NineDevice9
*This
,
2592 D3DTEXTURESTAGESTATETYPE Type
,
2595 struct nine_state
*state
= This
->update
;
2596 struct nine_context
*context
= &This
->context
;
2597 int bumpmap_index
= -1;
2599 DBG("Stage=%u Type=%u Value=%08x\n", Stage
, Type
, Value
);
2600 nine_dump_D3DTSS_value(DBG_FF
, Type
, Value
);
2602 user_assert(Stage
< ARRAY_SIZE(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2603 user_assert(Type
< ARRAY_SIZE(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2605 state
->ff
.tex_stage
[Stage
][Type
] = Value
;
2607 case D3DTSS_BUMPENVMAT00
:
2608 bumpmap_index
= 4 * Stage
;
2610 case D3DTSS_BUMPENVMAT01
:
2611 bumpmap_index
= 4 * Stage
+ 1;
2613 case D3DTSS_BUMPENVMAT10
:
2614 bumpmap_index
= 4 * Stage
+ 2;
2616 case D3DTSS_BUMPENVMAT11
:
2617 bumpmap_index
= 4 * Stage
+ 3;
2619 case D3DTSS_BUMPENVLSCALE
:
2620 bumpmap_index
= 4 * 8 + 2 * Stage
;
2622 case D3DTSS_BUMPENVLOFFSET
:
2623 bumpmap_index
= 4 * 8 + 2 * Stage
+ 1;
2625 case D3DTSS_TEXTURETRANSFORMFLAGS
:
2626 state
->changed
.group
|= NINE_STATE_PS1X_SHADER
;
2632 if (bumpmap_index
>= 0 && !This
->is_recording
) {
2633 context
->bumpmap_vars
[bumpmap_index
] = Value
;
2634 state
->changed
.group
|= NINE_STATE_PS_CONST
;
2637 state
->changed
.group
|= NINE_STATE_FF_PSSTAGES
;
2638 state
->ff
.changed
.tex_stage
[Stage
][Type
/ 32] |= 1 << (Type
% 32);
2644 NineDevice9_GetSamplerState( struct NineDevice9
*This
,
2646 D3DSAMPLERSTATETYPE Type
,
2649 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2650 Sampler
== D3DDMAPSAMPLER
||
2651 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2652 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2654 if (Sampler
>= D3DDMAPSAMPLER
)
2655 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2657 *pValue
= This
->state
.samp_advertised
[Sampler
][Type
];
2662 NineDevice9_SetSamplerState( struct NineDevice9
*This
,
2664 D3DSAMPLERSTATETYPE Type
,
2667 struct nine_state
*state
= This
->update
;
2669 DBG("This=%p Sampler=%u Type=%s Value=%08x\n", This
,
2670 Sampler
, nine_D3DSAMP_to_str(Type
), Value
);
2672 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2673 Sampler
== D3DDMAPSAMPLER
||
2674 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2675 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2677 if (Sampler
>= D3DDMAPSAMPLER
)
2678 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2680 if (state
->samp_advertised
[Sampler
][Type
] != Value
|| unlikely(This
->is_recording
)) {
2681 /* Contrary to render states, old value is kept if new value is wrong (except intel + Value == 0) */
2682 if (likely(nine_check_sampler_state_value(Type
, Value
)))
2683 state
->samp
[Sampler
][Type
] = Value
;
2684 state
->samp_advertised
[Sampler
][Type
] = Value
;
2685 state
->changed
.group
|= NINE_STATE_SAMPLER
;
2686 state
->changed
.sampler
[Sampler
] |= 1 << Type
;
2693 NineDevice9_ValidateDevice( struct NineDevice9
*This
,
2696 const struct nine_state
*state
= &This
->state
;
2698 unsigned w
= 0, h
= 0;
2700 DBG("This=%p pNumPasses=%p\n", This
, pNumPasses
);
2702 for (i
= 0; i
< ARRAY_SIZE(state
->samp
); ++i
) {
2703 if (state
->samp
[i
][D3DSAMP_MINFILTER
] == D3DTEXF_NONE
||
2704 state
->samp
[i
][D3DSAMP_MAGFILTER
] == D3DTEXF_NONE
)
2705 return D3DERR_UNSUPPORTEDTEXTUREFILTER
;
2708 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2712 w
= state
->rt
[i
]->desc
.Width
;
2713 h
= state
->rt
[i
]->desc
.Height
;
2715 if (state
->rt
[i
]->desc
.Width
!= w
|| state
->rt
[i
]->desc
.Height
!= h
) {
2716 return D3DERR_CONFLICTINGRENDERSTATE
;
2720 (state
->rs
[D3DRS_ZENABLE
] || state
->rs
[D3DRS_STENCILENABLE
])) {
2722 (state
->ds
->desc
.Width
!= w
|| state
->ds
->desc
.Height
!= h
))
2723 return D3DERR_CONFLICTINGRENDERSTATE
;
2733 NineDevice9_SetPaletteEntries( struct NineDevice9
*This
,
2735 const PALETTEENTRY
*pEntries
)
2737 STUB(D3D_OK
); /* like wine */
2741 NineDevice9_GetPaletteEntries( struct NineDevice9
*This
,
2743 PALETTEENTRY
*pEntries
)
2745 STUB(D3DERR_INVALIDCALL
);
2749 NineDevice9_SetCurrentTexturePalette( struct NineDevice9
*This
,
2750 UINT PaletteNumber
)
2752 STUB(D3D_OK
); /* like wine */
2756 NineDevice9_GetCurrentTexturePalette( struct NineDevice9
*This
,
2757 UINT
*PaletteNumber
)
2759 STUB(D3DERR_INVALIDCALL
);
2763 NineDevice9_SetScissorRect( struct NineDevice9
*This
,
2766 struct nine_state
*state
= This
->update
;
2768 DBG("x=(%u..%u) y=(%u..%u)\n",
2769 pRect
->left
, pRect
->top
, pRect
->right
, pRect
->bottom
);
2771 state
->scissor
.minx
= pRect
->left
;
2772 state
->scissor
.miny
= pRect
->top
;
2773 state
->scissor
.maxx
= pRect
->right
;
2774 state
->scissor
.maxy
= pRect
->bottom
;
2776 state
->changed
.group
|= NINE_STATE_SCISSOR
;
2782 NineDevice9_GetScissorRect( struct NineDevice9
*This
,
2785 pRect
->left
= This
->state
.scissor
.minx
;
2786 pRect
->top
= This
->state
.scissor
.miny
;
2787 pRect
->right
= This
->state
.scissor
.maxx
;
2788 pRect
->bottom
= This
->state
.scissor
.maxy
;
2794 NineDevice9_SetSoftwareVertexProcessing( struct NineDevice9
*This
,
2797 if (This
->params
.BehaviorFlags
& D3DCREATE_MIXED_VERTEXPROCESSING
) {
2798 This
->swvp
= bSoftware
;
2799 This
->state
.changed
.group
|= NINE_STATE_SWVP
;
2802 return D3DERR_INVALIDCALL
; /* msdn. TODO: check in practice */
2806 NineDevice9_GetSoftwareVertexProcessing( struct NineDevice9
*This
)
2812 NineDevice9_SetNPatchMode( struct NineDevice9
*This
,
2815 return D3D_OK
; /* Nothing to do because we don't advertise NPatch support */
2819 NineDevice9_GetNPatchMode( struct NineDevice9
*This
)
2825 init_draw_info(struct pipe_draw_info
*info
,
2826 struct NineDevice9
*dev
, D3DPRIMITIVETYPE type
, UINT count
)
2828 info
->mode
= d3dprimitivetype_to_pipe_prim(type
);
2829 info
->count
= prim_count_to_vertex_count(type
, count
);
2830 info
->start_instance
= 0;
2831 info
->instance_count
= 1;
2832 if (dev
->state
.stream_instancedata_mask
& dev
->state
.stream_usage_mask
)
2833 info
->instance_count
= MAX2(dev
->state
.stream_freq
[0] & 0x7FFFFF, 1);
2834 info
->primitive_restart
= FALSE
;
2835 info
->restart_index
= 0;
2836 info
->count_from_stream_output
= NULL
;
2837 info
->indirect
= NULL
;
2838 info
->indirect_params
= NULL
;
2842 NineDevice9_DrawPrimitive( struct NineDevice9
*This
,
2843 D3DPRIMITIVETYPE PrimitiveType
,
2845 UINT PrimitiveCount
)
2847 struct pipe_draw_info info
;
2849 DBG("iface %p, PrimitiveType %u, StartVertex %u, PrimitiveCount %u\n",
2850 This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2852 nine_update_state(This
);
2854 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2855 info
.indexed
= FALSE
;
2856 info
.start
= StartVertex
;
2857 info
.index_bias
= 0;
2858 info
.min_index
= info
.start
;
2859 info
.max_index
= info
.count
- 1;
2861 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2867 NineDevice9_DrawIndexedPrimitive( struct NineDevice9
*This
,
2868 D3DPRIMITIVETYPE PrimitiveType
,
2869 INT BaseVertexIndex
,
2870 UINT MinVertexIndex
,
2873 UINT PrimitiveCount
)
2875 struct pipe_draw_info info
;
2877 DBG("iface %p, PrimitiveType %u, BaseVertexIndex %u, MinVertexIndex %u "
2878 "NumVertices %u, StartIndex %u, PrimitiveCount %u\n",
2879 This
, PrimitiveType
, BaseVertexIndex
, MinVertexIndex
, NumVertices
,
2880 StartIndex
, PrimitiveCount
);
2882 user_assert(This
->state
.idxbuf
, D3DERR_INVALIDCALL
);
2883 user_assert(This
->state
.vdecl
, D3DERR_INVALIDCALL
);
2885 nine_update_state(This
);
2887 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2888 info
.indexed
= TRUE
;
2889 info
.start
= StartIndex
;
2890 info
.index_bias
= BaseVertexIndex
;
2891 /* These don't include index bias: */
2892 info
.min_index
= MinVertexIndex
;
2893 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
2895 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2901 NineDevice9_DrawPrimitiveUP( struct NineDevice9
*This
,
2902 D3DPRIMITIVETYPE PrimitiveType
,
2903 UINT PrimitiveCount
,
2904 const void *pVertexStreamZeroData
,
2905 UINT VertexStreamZeroStride
)
2907 struct pipe_vertex_buffer vtxbuf
;
2908 struct pipe_draw_info info
;
2910 DBG("iface %p, PrimitiveType %u, PrimitiveCount %u, data %p, stride %u\n",
2911 This
, PrimitiveType
, PrimitiveCount
,
2912 pVertexStreamZeroData
, VertexStreamZeroStride
);
2914 user_assert(pVertexStreamZeroData
&& VertexStreamZeroStride
,
2915 D3DERR_INVALIDCALL
);
2916 user_assert(PrimitiveCount
, D3D_OK
);
2918 nine_update_state(This
);
2920 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2921 info
.indexed
= FALSE
;
2923 info
.index_bias
= 0;
2925 info
.max_index
= info
.count
- 1;
2927 vtxbuf
.stride
= VertexStreamZeroStride
;
2928 vtxbuf
.buffer_offset
= 0;
2929 vtxbuf
.buffer
= NULL
;
2930 vtxbuf
.user_buffer
= pVertexStreamZeroData
;
2932 if (!This
->driver_caps
.user_vbufs
) {
2933 u_upload_data(This
->vertex_uploader
,
2935 (info
.max_index
+ 1) * VertexStreamZeroStride
, /* XXX */
2938 &vtxbuf
.buffer_offset
,
2940 u_upload_unmap(This
->vertex_uploader
);
2941 vtxbuf
.user_buffer
= NULL
;
2944 This
->pipe
->set_vertex_buffers(This
->pipe
, 0, 1, &vtxbuf
);
2946 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2948 NineDevice9_PauseRecording(This
);
2949 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
2950 NineDevice9_ResumeRecording(This
);
2952 pipe_resource_reference(&vtxbuf
.buffer
, NULL
);
2958 NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9
*This
,
2959 D3DPRIMITIVETYPE PrimitiveType
,
2960 UINT MinVertexIndex
,
2962 UINT PrimitiveCount
,
2963 const void *pIndexData
,
2964 D3DFORMAT IndexDataFormat
,
2965 const void *pVertexStreamZeroData
,
2966 UINT VertexStreamZeroStride
)
2968 struct pipe_draw_info info
;
2969 struct pipe_vertex_buffer vbuf
;
2970 struct pipe_index_buffer ibuf
;
2972 DBG("iface %p, PrimitiveType %u, MinVertexIndex %u, NumVertices %u "
2973 "PrimitiveCount %u, pIndexData %p, IndexDataFormat %u "
2974 "pVertexStreamZeroData %p, VertexStreamZeroStride %u\n",
2975 This
, PrimitiveType
, MinVertexIndex
, NumVertices
, PrimitiveCount
,
2976 pIndexData
, IndexDataFormat
,
2977 pVertexStreamZeroData
, VertexStreamZeroStride
);
2979 user_assert(pIndexData
&& pVertexStreamZeroData
, D3DERR_INVALIDCALL
);
2980 user_assert(VertexStreamZeroStride
, D3DERR_INVALIDCALL
);
2981 user_assert(IndexDataFormat
== D3DFMT_INDEX16
||
2982 IndexDataFormat
== D3DFMT_INDEX32
, D3DERR_INVALIDCALL
);
2983 user_assert(PrimitiveCount
, D3D_OK
);
2985 nine_update_state(This
);
2987 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2988 info
.indexed
= TRUE
;
2990 info
.index_bias
= 0;
2991 info
.min_index
= MinVertexIndex
;
2992 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
2994 vbuf
.stride
= VertexStreamZeroStride
;
2995 vbuf
.buffer_offset
= 0;
2997 vbuf
.user_buffer
= pVertexStreamZeroData
;
2999 ibuf
.index_size
= (IndexDataFormat
== D3DFMT_INDEX16
) ? 2 : 4;
3002 ibuf
.user_buffer
= pIndexData
;
3004 if (!This
->driver_caps
.user_vbufs
) {
3005 const unsigned base
= info
.min_index
* VertexStreamZeroStride
;
3006 u_upload_data(This
->vertex_uploader
,
3009 info
.min_index
+ 1) * VertexStreamZeroStride
, /* XXX */
3011 (const uint8_t *)vbuf
.user_buffer
+ base
,
3012 &vbuf
.buffer_offset
,
3014 u_upload_unmap(This
->vertex_uploader
);
3015 /* Won't be used: */
3016 vbuf
.buffer_offset
-= base
;
3017 vbuf
.user_buffer
= NULL
;
3019 if (!This
->driver_caps
.user_ibufs
) {
3020 u_upload_data(This
->index_uploader
,
3022 info
.count
* ibuf
.index_size
,
3027 u_upload_unmap(This
->index_uploader
);
3028 ibuf
.user_buffer
= NULL
;
3031 This
->pipe
->set_vertex_buffers(This
->pipe
, 0, 1, &vbuf
);
3032 This
->pipe
->set_index_buffer(This
->pipe
, &ibuf
);
3034 This
->pipe
->draw_vbo(This
->pipe
, &info
);
3036 pipe_resource_reference(&vbuf
.buffer
, NULL
);
3037 pipe_resource_reference(&ibuf
.buffer
, NULL
);
3039 NineDevice9_PauseRecording(This
);
3040 NineDevice9_SetIndices(This
, NULL
);
3041 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
3042 NineDevice9_ResumeRecording(This
);
3048 NineDevice9_ProcessVertices( struct NineDevice9
*This
,
3052 IDirect3DVertexBuffer9
*pDestBuffer
,
3053 IDirect3DVertexDeclaration9
*pVertexDecl
,
3056 struct pipe_screen
*screen_sw
= This
->screen_sw
;
3057 struct pipe_context
*pipe_sw
= This
->pipe_sw
;
3058 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pVertexDecl
);
3059 struct NineVertexBuffer9
*dst
= NineVertexBuffer9(pDestBuffer
);
3060 struct NineVertexShader9
*vs
;
3061 struct pipe_resource
*resource
;
3062 struct pipe_transfer
*transfer
= NULL
;
3063 struct pipe_stream_output_info so
;
3064 struct pipe_stream_output_target
*target
;
3065 struct pipe_draw_info draw
;
3066 struct pipe_box box
;
3067 unsigned offsets
[1] = {0};
3069 unsigned buffer_size
;
3072 DBG("This=%p SrcStartIndex=%u DestIndex=%u VertexCount=%u "
3073 "pDestBuffer=%p pVertexDecl=%p Flags=%d\n",
3074 This
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
,
3075 pVertexDecl
, Flags
);
3077 if (!screen_sw
->get_param(screen_sw
, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
)) {
3078 DBG("ProcessVertices not supported\n");
3079 return D3DERR_INVALIDCALL
;
3083 vs
= This
->state
.programmable_vs
? This
->state
.vs
: This
->ff
.vs
;
3084 /* Note: version is 0 for ff */
3085 user_assert(vdecl
|| (vs
->byte_code
.version
< 0x30 && dst
->desc
.FVF
),
3086 D3DERR_INVALIDCALL
);
3088 DWORD FVF
= dst
->desc
.FVF
;
3089 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
3091 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
3095 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
3096 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
3100 /* Flags: Can be 0 or D3DPV_DONOTCOPYDATA, and/or lock flags
3101 * D3DPV_DONOTCOPYDATA -> Has effect only for ff. In particular
3102 * if not set, everything from src will be used, and dst
3103 * must match exactly the ff vs outputs.
3104 * TODO: Handle all the checks, etc for ff */
3105 user_assert(vdecl
->position_t
|| This
->state
.programmable_vs
,
3106 D3DERR_INVALIDCALL
);
3108 /* TODO: Support vs < 3 and ff */
3109 user_assert(vs
->byte_code
.version
== 0x30,
3110 D3DERR_INVALIDCALL
);
3111 /* TODO: Not hardcode the constant buffers for swvp */
3112 user_assert(This
->may_swvp
,
3113 D3DERR_INVALIDCALL
);
3115 nine_state_prepare_draw_sw(This
, vdecl
, SrcStartIndex
, VertexCount
, &so
);
3117 buffer_size
= VertexCount
* so
.stride
[0] * 4;
3119 struct pipe_resource templ
;
3121 memset(&templ
, 0, sizeof(templ
));
3122 templ
.target
= PIPE_BUFFER
;
3123 templ
.format
= PIPE_FORMAT_R8_UNORM
;
3124 templ
.width0
= buffer_size
;
3126 templ
.bind
= PIPE_BIND_STREAM_OUTPUT
;
3127 templ
.usage
= PIPE_USAGE_STREAM
;
3128 templ
.height0
= templ
.depth0
= templ
.array_size
= 1;
3129 templ
.last_level
= templ
.nr_samples
= 0;
3131 resource
= screen_sw
->resource_create(screen_sw
, &templ
);
3133 return E_OUTOFMEMORY
;
3135 target
= pipe_sw
->create_stream_output_target(pipe_sw
, resource
,
3138 pipe_resource_reference(&resource
, NULL
);
3139 return D3DERR_DRIVERINTERNALERROR
;
3142 init_draw_info(&draw
, This
, D3DPT_POINTLIST
, VertexCount
);
3143 draw
.instance_count
= 1;
3144 draw
.indexed
= FALSE
;
3146 draw
.index_bias
= 0;
3148 draw
.max_index
= VertexCount
- 1;
3151 pipe_sw
->set_stream_output_targets(pipe_sw
, 1, &target
, offsets
);
3153 pipe_sw
->draw_vbo(pipe_sw
, &draw
);
3155 pipe_sw
->set_stream_output_targets(pipe_sw
, 0, NULL
, 0);
3156 pipe_sw
->stream_output_target_destroy(pipe_sw
, target
);
3158 u_box_1d(0, VertexCount
* so
.stride
[0] * 4, &box
);
3159 map
= pipe_sw
->transfer_map(pipe_sw
, resource
, 0, PIPE_TRANSFER_READ
, &box
,
3162 hr
= D3DERR_DRIVERINTERNALERROR
;
3166 hr
= NineVertexDeclaration9_ConvertStreamOutput(vdecl
,
3167 dst
, DestIndex
, VertexCount
,
3170 pipe_sw
->transfer_unmap(pipe_sw
, transfer
);
3173 nine_state_after_draw_sw(This
);
3174 pipe_resource_reference(&resource
, NULL
);
3179 NineDevice9_CreateVertexDeclaration( struct NineDevice9
*This
,
3180 const D3DVERTEXELEMENT9
*pVertexElements
,
3181 IDirect3DVertexDeclaration9
**ppDecl
)
3183 struct NineVertexDeclaration9
*vdecl
;
3185 DBG("This=%p pVertexElements=%p ppDecl=%p\n",
3186 This
, pVertexElements
, ppDecl
);
3188 HRESULT hr
= NineVertexDeclaration9_new(This
, pVertexElements
, &vdecl
);
3190 *ppDecl
= (IDirect3DVertexDeclaration9
*)vdecl
;
3196 NineDevice9_SetVertexDeclaration( struct NineDevice9
*This
,
3197 IDirect3DVertexDeclaration9
*pDecl
)
3199 struct nine_state
*state
= This
->update
;
3200 struct nine_context
*context
= &This
->context
;
3201 BOOL was_programmable_vs
= This
->state
.programmable_vs
;
3203 DBG("This=%p pDecl=%p\n", This
, pDecl
);
3205 if (likely(!This
->is_recording
) && state
->vdecl
== NineVertexDeclaration9(pDecl
))
3208 nine_bind(&state
->vdecl
, pDecl
);
3210 This
->state
.programmable_vs
= This
->state
.vs
&& !(This
->state
.vdecl
&& This
->state
.vdecl
->position_t
);
3211 if (likely(!This
->is_recording
) && was_programmable_vs
!= This
->state
.programmable_vs
) {
3212 context
->commit
|= NINE_STATE_COMMIT_CONST_VS
;
3213 state
->changed
.group
|= NINE_STATE_VS
;
3216 state
->changed
.group
|= NINE_STATE_VDECL
;
3222 NineDevice9_GetVertexDeclaration( struct NineDevice9
*This
,
3223 IDirect3DVertexDeclaration9
**ppDecl
)
3225 user_assert(ppDecl
, D3DERR_INVALIDCALL
);
3227 *ppDecl
= (IDirect3DVertexDeclaration9
*)This
->state
.vdecl
;
3229 NineUnknown_AddRef(NineUnknown(*ppDecl
));
3234 NineDevice9_SetFVF( struct NineDevice9
*This
,
3237 struct NineVertexDeclaration9
*vdecl
;
3240 DBG("FVF = %08x\n", FVF
);
3242 return D3D_OK
; /* like wine */
3244 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
3246 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
3250 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
3251 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
3253 return NineDevice9_SetVertexDeclaration(
3254 This
, (IDirect3DVertexDeclaration9
*)vdecl
);
3258 NineDevice9_GetFVF( struct NineDevice9
*This
,
3261 *pFVF
= This
->state
.vdecl
? This
->state
.vdecl
->fvf
: 0;
3266 NineDevice9_CreateVertexShader( struct NineDevice9
*This
,
3267 const DWORD
*pFunction
,
3268 IDirect3DVertexShader9
**ppShader
)
3270 struct NineVertexShader9
*vs
;
3273 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3275 hr
= NineVertexShader9_new(This
, &vs
, pFunction
, NULL
);
3278 *ppShader
= (IDirect3DVertexShader9
*)vs
;
3283 NineDevice9_SetVertexShader( struct NineDevice9
*This
,
3284 IDirect3DVertexShader9
*pShader
)
3286 struct nine_state
*state
= This
->update
;
3287 struct nine_context
*context
= &This
->context
;
3288 BOOL was_programmable_vs
= This
->state
.programmable_vs
;
3290 DBG("This=%p pShader=%p\n", This
, pShader
);
3292 if (!This
->is_recording
&& state
->vs
== (struct NineVertexShader9
*)pShader
)
3295 nine_bind(&state
->vs
, pShader
);
3297 This
->state
.programmable_vs
= This
->state
.vs
&& !(This
->state
.vdecl
&& This
->state
.vdecl
->position_t
);
3299 /* ff -> non-ff: commit back non-ff constants */
3300 if (!was_programmable_vs
&& This
->state
.programmable_vs
)
3301 context
->commit
|= NINE_STATE_COMMIT_CONST_VS
;
3303 state
->changed
.group
|= NINE_STATE_VS
;
3309 NineDevice9_GetVertexShader( struct NineDevice9
*This
,
3310 IDirect3DVertexShader9
**ppShader
)
3312 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3313 nine_reference_set(ppShader
, This
->state
.vs
);
3318 NineDevice9_SetVertexShaderConstantF( struct NineDevice9
*This
,
3320 const float *pConstantData
,
3321 UINT Vector4fCount
)
3323 struct nine_state
*state
= This
->update
;
3324 float *vs_const_f
= This
->may_swvp
? state
->vs_const_f_swvp
: state
->vs_const_f
;
3326 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3327 This
, StartRegister
, pConstantData
, Vector4fCount
);
3329 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3330 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3334 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3336 if (!This
->is_recording
) {
3337 if (!memcmp(&vs_const_f
[StartRegister
* 4], pConstantData
,
3338 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0])))
3342 memcpy(&vs_const_f
[StartRegister
* 4],
3344 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3346 nine_ranges_insert(&state
->changed
.vs_const_f
,
3347 StartRegister
, StartRegister
+ Vector4fCount
,
3350 if (This
->may_swvp
) {
3351 Vector4fCount
= MIN2(StartRegister
+ Vector4fCount
, NINE_MAX_CONST_F
) - StartRegister
;
3352 if (StartRegister
< NINE_MAX_CONST_F
)
3353 memcpy(&state
->vs_const_f
[StartRegister
* 4],
3355 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3358 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3364 NineDevice9_GetVertexShaderConstantF( struct NineDevice9
*This
,
3366 float *pConstantData
,
3367 UINT Vector4fCount
)
3369 const struct nine_state
*state
= &This
->state
;
3370 float *vs_const_f
= This
->may_swvp
? state
->vs_const_f_swvp
: state
->vs_const_f
;
3372 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3373 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3374 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3376 memcpy(pConstantData
,
3377 &vs_const_f
[StartRegister
* 4],
3378 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3384 NineDevice9_SetVertexShaderConstantI( struct NineDevice9
*This
,
3386 const int *pConstantData
,
3387 UINT Vector4iCount
)
3389 struct nine_state
*state
= This
->update
;
3392 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3393 This
, StartRegister
, pConstantData
, Vector4iCount
);
3395 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3396 D3DERR_INVALIDCALL
);
3397 user_assert(StartRegister
+ Vector4iCount
<= (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3398 D3DERR_INVALIDCALL
);
3399 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3401 if (This
->driver_caps
.vs_integer
) {
3402 if (!This
->is_recording
) {
3403 if (!memcmp(&state
->vs_const_i
[4 * StartRegister
], pConstantData
,
3404 Vector4iCount
* sizeof(int[4])))
3407 memcpy(&state
->vs_const_i
[4 * StartRegister
],
3409 Vector4iCount
* sizeof(int[4]));
3411 for (i
= 0; i
< Vector4iCount
; i
++) {
3412 state
->vs_const_i
[4 * (StartRegister
+ i
)] = fui((float)(pConstantData
[4 * i
]));
3413 state
->vs_const_i
[4 * (StartRegister
+ i
) + 1] = fui((float)(pConstantData
[4 * i
+ 1]));
3414 state
->vs_const_i
[4 * (StartRegister
+ i
) + 2] = fui((float)(pConstantData
[4 * i
+ 2]));
3415 state
->vs_const_i
[4 * (StartRegister
+ i
) + 3] = fui((float)(pConstantData
[4 * i
+ 3]));
3419 nine_ranges_insert(&state
->changed
.vs_const_i
,
3420 StartRegister
, StartRegister
+ Vector4iCount
,
3422 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3428 NineDevice9_GetVertexShaderConstantI( struct NineDevice9
*This
,
3431 UINT Vector4iCount
)
3433 const struct nine_state
*state
= &This
->state
;
3436 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3437 D3DERR_INVALIDCALL
);
3438 user_assert(StartRegister
+ Vector4iCount
<= (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3439 D3DERR_INVALIDCALL
);
3440 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3442 if (This
->driver_caps
.vs_integer
) {
3443 memcpy(pConstantData
,
3444 &state
->vs_const_i
[4 * StartRegister
],
3445 Vector4iCount
* sizeof(int[4]));
3447 for (i
= 0; i
< Vector4iCount
; i
++) {
3448 pConstantData
[4 * i
] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
)]);
3449 pConstantData
[4 * i
+ 1] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
) + 1]);
3450 pConstantData
[4 * i
+ 2] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
) + 2]);
3451 pConstantData
[4 * i
+ 3] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
) + 3]);
3459 NineDevice9_SetVertexShaderConstantB( struct NineDevice9
*This
,
3461 const BOOL
*pConstantData
,
3464 struct nine_state
*state
= This
->update
;
3466 uint32_t bool_true
= This
->driver_caps
.vs_integer
? 0xFFFFFFFF : fui(1.0f
);
3468 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3469 This
, StartRegister
, pConstantData
, BoolCount
);
3471 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3472 D3DERR_INVALIDCALL
);
3473 user_assert(StartRegister
+ BoolCount
<= (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3474 D3DERR_INVALIDCALL
);
3475 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3477 if (!This
->is_recording
) {
3478 bool noChange
= true;
3479 for (i
= 0; i
< BoolCount
; i
++) {
3480 if (!!state
->vs_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3487 for (i
= 0; i
< BoolCount
; i
++)
3488 state
->vs_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3490 nine_ranges_insert(&state
->changed
.vs_const_b
,
3491 StartRegister
, StartRegister
+ BoolCount
,
3493 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3499 NineDevice9_GetVertexShaderConstantB( struct NineDevice9
*This
,
3501 BOOL
*pConstantData
,
3504 const struct nine_state
*state
= &This
->state
;
3507 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3508 D3DERR_INVALIDCALL
);
3509 user_assert(StartRegister
+ BoolCount
<= (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3510 D3DERR_INVALIDCALL
);
3511 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3513 for (i
= 0; i
< BoolCount
; i
++)
3514 pConstantData
[i
] = state
->vs_const_b
[StartRegister
+ i
] != 0 ? TRUE
: FALSE
;
3520 NineDevice9_SetStreamSource( struct NineDevice9
*This
,
3522 IDirect3DVertexBuffer9
*pStreamData
,
3526 struct nine_state
*state
= This
->update
;
3527 struct NineVertexBuffer9
*pVBuf9
= NineVertexBuffer9(pStreamData
);
3528 const unsigned i
= StreamNumber
;
3530 DBG("This=%p StreamNumber=%u pStreamData=%p OffsetInBytes=%u Stride=%u\n",
3531 This
, StreamNumber
, pStreamData
, OffsetInBytes
, Stride
);
3533 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3534 user_assert(Stride
<= This
->caps
.MaxStreamStride
, D3DERR_INVALIDCALL
);
3536 if (likely(!This
->is_recording
)) {
3537 if (state
->stream
[i
] == NineVertexBuffer9(pStreamData
) &&
3538 state
->vtxbuf
[i
].stride
== Stride
&&
3539 state
->vtxbuf
[i
].buffer_offset
== OffsetInBytes
)
3542 nine_bind(&state
->stream
[i
], pStreamData
);
3544 state
->changed
.vtxbuf
|= 1 << StreamNumber
;
3547 state
->vtxbuf
[i
].stride
= Stride
;
3548 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3550 pipe_resource_reference(&state
->vtxbuf
[i
].buffer
,
3551 pStreamData
? NineVertexBuffer9_GetResource(pVBuf9
) : NULL
);
3557 NineDevice9_GetStreamSource( struct NineDevice9
*This
,
3559 IDirect3DVertexBuffer9
**ppStreamData
,
3560 UINT
*pOffsetInBytes
,
3563 const struct nine_state
*state
= &This
->state
;
3564 const unsigned i
= StreamNumber
;
3566 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3567 user_assert(ppStreamData
, D3DERR_INVALIDCALL
);
3569 nine_reference_set(ppStreamData
, state
->stream
[i
]);
3570 *pStride
= state
->vtxbuf
[i
].stride
;
3571 *pOffsetInBytes
= state
->vtxbuf
[i
].buffer_offset
;
3577 NineDevice9_SetStreamSourceFreq( struct NineDevice9
*This
,
3581 struct nine_state
*state
= This
->update
;
3582 /* const UINT freq = Setting & 0x7FFFFF; */
3584 DBG("This=%p StreamNumber=%u FrequencyParameter=0x%x\n", This
,
3585 StreamNumber
, Setting
);
3587 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3588 user_assert(StreamNumber
!= 0 || !(Setting
& D3DSTREAMSOURCE_INSTANCEDATA
),
3589 D3DERR_INVALIDCALL
);
3590 user_assert(!((Setting
& D3DSTREAMSOURCE_INSTANCEDATA
) &&
3591 (Setting
& D3DSTREAMSOURCE_INDEXEDDATA
)), D3DERR_INVALIDCALL
);
3592 user_assert(Setting
, D3DERR_INVALIDCALL
);
3594 if (likely(!This
->is_recording
) && state
->stream_freq
[StreamNumber
] == Setting
)
3597 state
->stream_freq
[StreamNumber
] = Setting
;
3599 if (Setting
& D3DSTREAMSOURCE_INSTANCEDATA
)
3600 state
->stream_instancedata_mask
|= 1 << StreamNumber
;
3602 state
->stream_instancedata_mask
&= ~(1 << StreamNumber
);
3604 state
->changed
.stream_freq
|= 1 << StreamNumber
; /* Used for stateblocks */
3605 if (StreamNumber
!= 0)
3606 state
->changed
.group
|= NINE_STATE_STREAMFREQ
;
3611 NineDevice9_GetStreamSourceFreq( struct NineDevice9
*This
,
3615 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3616 *pSetting
= This
->state
.stream_freq
[StreamNumber
];
3621 NineDevice9_SetIndices( struct NineDevice9
*This
,
3622 IDirect3DIndexBuffer9
*pIndexData
)
3624 struct nine_state
*state
= This
->update
;
3626 DBG("This=%p pIndexData=%p\n", This
, pIndexData
);
3628 if (likely(!This
->is_recording
))
3629 if (state
->idxbuf
== NineIndexBuffer9(pIndexData
))
3631 nine_bind(&state
->idxbuf
, pIndexData
);
3633 state
->changed
.group
|= NINE_STATE_IDXBUF
;
3638 /* XXX: wine/d3d9 doesn't have pBaseVertexIndex, and it doesn't make sense
3639 * here because it's an argument passed to the Draw calls.
3642 NineDevice9_GetIndices( struct NineDevice9
*This
,
3643 IDirect3DIndexBuffer9
**ppIndexData
)
3645 user_assert(ppIndexData
, D3DERR_INVALIDCALL
);
3646 nine_reference_set(ppIndexData
, This
->state
.idxbuf
);
3651 NineDevice9_CreatePixelShader( struct NineDevice9
*This
,
3652 const DWORD
*pFunction
,
3653 IDirect3DPixelShader9
**ppShader
)
3655 struct NinePixelShader9
*ps
;
3658 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3660 hr
= NinePixelShader9_new(This
, &ps
, pFunction
, NULL
);
3663 *ppShader
= (IDirect3DPixelShader9
*)ps
;
3668 NineDevice9_SetPixelShader( struct NineDevice9
*This
,
3669 IDirect3DPixelShader9
*pShader
)
3671 struct nine_state
*state
= This
->update
;
3672 struct nine_context
*context
= &This
->context
;
3673 unsigned old_mask
= state
->ps
? state
->ps
->rt_mask
: 1;
3676 DBG("This=%p pShader=%p\n", This
, pShader
);
3678 if (!This
->is_recording
&& state
->ps
== (struct NinePixelShader9
*)pShader
)
3681 /* ff -> non-ff: commit back non-ff constants */
3682 if (!state
->ps
&& pShader
)
3683 context
->commit
|= NINE_STATE_COMMIT_CONST_PS
;
3685 nine_bind(&state
->ps
, pShader
);
3687 state
->changed
.group
|= NINE_STATE_PS
;
3689 mask
= state
->ps
? state
->ps
->rt_mask
: 1;
3690 /* We need to update cbufs if the pixel shader would
3691 * write to different render targets */
3692 if (mask
!= old_mask
)
3693 state
->changed
.group
|= NINE_STATE_FB
;
3699 NineDevice9_GetPixelShader( struct NineDevice9
*This
,
3700 IDirect3DPixelShader9
**ppShader
)
3702 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3703 nine_reference_set(ppShader
, This
->state
.ps
);
3708 NineDevice9_SetPixelShaderConstantF( struct NineDevice9
*This
,
3710 const float *pConstantData
,
3711 UINT Vector4fCount
)
3713 struct nine_state
*state
= This
->update
;
3715 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3716 This
, StartRegister
, pConstantData
, Vector4fCount
);
3718 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3719 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3723 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3725 if (!This
->is_recording
) {
3726 if (!memcmp(&state
->ps_const_f
[StartRegister
* 4], pConstantData
,
3727 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0])))
3731 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3733 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3735 nine_ranges_insert(&state
->changed
.ps_const_f
,
3736 StartRegister
, StartRegister
+ Vector4fCount
,
3739 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3745 NineDevice9_GetPixelShaderConstantF( struct NineDevice9
*This
,
3747 float *pConstantData
,
3748 UINT Vector4fCount
)
3750 const struct nine_state
*state
= &This
->state
;
3752 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3753 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3754 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3756 memcpy(pConstantData
,
3757 &state
->ps_const_f
[StartRegister
* 4],
3758 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3764 NineDevice9_SetPixelShaderConstantI( struct NineDevice9
*This
,
3766 const int *pConstantData
,
3767 UINT Vector4iCount
)
3769 struct nine_state
*state
= This
->update
;
3772 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3773 This
, StartRegister
, pConstantData
, Vector4iCount
);
3775 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3776 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3777 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3779 if (This
->driver_caps
.ps_integer
) {
3780 if (!This
->is_recording
) {
3781 if (!memcmp(&state
->ps_const_i
[StartRegister
][0], pConstantData
,
3782 Vector4iCount
* sizeof(state
->ps_const_i
[0])))
3785 memcpy(&state
->ps_const_i
[StartRegister
][0],
3787 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3789 for (i
= 0; i
< Vector4iCount
; i
++) {
3790 state
->ps_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3791 state
->ps_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3792 state
->ps_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3793 state
->ps_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3796 state
->changed
.ps_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3797 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3803 NineDevice9_GetPixelShaderConstantI( struct NineDevice9
*This
,
3806 UINT Vector4iCount
)
3808 const struct nine_state
*state
= &This
->state
;
3811 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3812 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3813 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3815 if (This
->driver_caps
.ps_integer
) {
3816 memcpy(pConstantData
,
3817 &state
->ps_const_i
[StartRegister
][0],
3818 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3820 for (i
= 0; i
< Vector4iCount
; i
++) {
3821 pConstantData
[4*i
] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][0]);
3822 pConstantData
[4*i
+1] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][1]);
3823 pConstantData
[4*i
+2] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][2]);
3824 pConstantData
[4*i
+3] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][3]);
3832 NineDevice9_SetPixelShaderConstantB( struct NineDevice9
*This
,
3834 const BOOL
*pConstantData
,
3837 struct nine_state
*state
= This
->update
;
3839 uint32_t bool_true
= This
->driver_caps
.ps_integer
? 0xFFFFFFFF : fui(1.0f
);
3841 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3842 This
, StartRegister
, pConstantData
, BoolCount
);
3844 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3845 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3846 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3848 if (!This
->is_recording
) {
3849 bool noChange
= true;
3850 for (i
= 0; i
< BoolCount
; i
++) {
3851 if (!!state
->ps_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3858 for (i
= 0; i
< BoolCount
; i
++)
3859 state
->ps_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3861 state
->changed
.ps_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3862 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3868 NineDevice9_GetPixelShaderConstantB( struct NineDevice9
*This
,
3870 BOOL
*pConstantData
,
3873 const struct nine_state
*state
= &This
->state
;
3876 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3877 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3878 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3880 for (i
= 0; i
< BoolCount
; i
++)
3881 pConstantData
[i
] = state
->ps_const_b
[StartRegister
+ i
] ? TRUE
: FALSE
;
3887 NineDevice9_DrawRectPatch( struct NineDevice9
*This
,
3889 const float *pNumSegs
,
3890 const D3DRECTPATCH_INFO
*pRectPatchInfo
)
3892 STUB(D3DERR_INVALIDCALL
);
3896 NineDevice9_DrawTriPatch( struct NineDevice9
*This
,
3898 const float *pNumSegs
,
3899 const D3DTRIPATCH_INFO
*pTriPatchInfo
)
3901 STUB(D3DERR_INVALIDCALL
);
3905 NineDevice9_DeletePatch( struct NineDevice9
*This
,
3908 STUB(D3DERR_INVALIDCALL
);
3912 NineDevice9_CreateQuery( struct NineDevice9
*This
,
3914 IDirect3DQuery9
**ppQuery
)
3916 struct NineQuery9
*query
;
3919 DBG("This=%p Type=%d ppQuery=%p\n", This
, Type
, ppQuery
);
3921 hr
= nine_is_query_supported(This
->screen
, Type
);
3922 if (!ppQuery
|| hr
!= D3D_OK
)
3925 hr
= NineQuery9_new(This
, &query
, Type
);
3928 *ppQuery
= (IDirect3DQuery9
*)query
;
3932 IDirect3DDevice9Vtbl NineDevice9_vtable
= {
3933 (void *)NineUnknown_QueryInterface
,
3934 (void *)NineUnknown_AddRef
,
3935 (void *)NineUnknown_Release
,
3936 (void *)NineDevice9_TestCooperativeLevel
,
3937 (void *)NineDevice9_GetAvailableTextureMem
,
3938 (void *)NineDevice9_EvictManagedResources
,
3939 (void *)NineDevice9_GetDirect3D
,
3940 (void *)NineDevice9_GetDeviceCaps
,
3941 (void *)NineDevice9_GetDisplayMode
,
3942 (void *)NineDevice9_GetCreationParameters
,
3943 (void *)NineDevice9_SetCursorProperties
,
3944 (void *)NineDevice9_SetCursorPosition
,
3945 (void *)NineDevice9_ShowCursor
,
3946 (void *)NineDevice9_CreateAdditionalSwapChain
,
3947 (void *)NineDevice9_GetSwapChain
,
3948 (void *)NineDevice9_GetNumberOfSwapChains
,
3949 (void *)NineDevice9_Reset
,
3950 (void *)NineDevice9_Present
,
3951 (void *)NineDevice9_GetBackBuffer
,
3952 (void *)NineDevice9_GetRasterStatus
,
3953 (void *)NineDevice9_SetDialogBoxMode
,
3954 (void *)NineDevice9_SetGammaRamp
,
3955 (void *)NineDevice9_GetGammaRamp
,
3956 (void *)NineDevice9_CreateTexture
,
3957 (void *)NineDevice9_CreateVolumeTexture
,
3958 (void *)NineDevice9_CreateCubeTexture
,
3959 (void *)NineDevice9_CreateVertexBuffer
,
3960 (void *)NineDevice9_CreateIndexBuffer
,
3961 (void *)NineDevice9_CreateRenderTarget
,
3962 (void *)NineDevice9_CreateDepthStencilSurface
,
3963 (void *)NineDevice9_UpdateSurface
,
3964 (void *)NineDevice9_UpdateTexture
,
3965 (void *)NineDevice9_GetRenderTargetData
,
3966 (void *)NineDevice9_GetFrontBufferData
,
3967 (void *)NineDevice9_StretchRect
,
3968 (void *)NineDevice9_ColorFill
,
3969 (void *)NineDevice9_CreateOffscreenPlainSurface
,
3970 (void *)NineDevice9_SetRenderTarget
,
3971 (void *)NineDevice9_GetRenderTarget
,
3972 (void *)NineDevice9_SetDepthStencilSurface
,
3973 (void *)NineDevice9_GetDepthStencilSurface
,
3974 (void *)NineDevice9_BeginScene
,
3975 (void *)NineDevice9_EndScene
,
3976 (void *)NineDevice9_Clear
,
3977 (void *)NineDevice9_SetTransform
,
3978 (void *)NineDevice9_GetTransform
,
3979 (void *)NineDevice9_MultiplyTransform
,
3980 (void *)NineDevice9_SetViewport
,
3981 (void *)NineDevice9_GetViewport
,
3982 (void *)NineDevice9_SetMaterial
,
3983 (void *)NineDevice9_GetMaterial
,
3984 (void *)NineDevice9_SetLight
,
3985 (void *)NineDevice9_GetLight
,
3986 (void *)NineDevice9_LightEnable
,
3987 (void *)NineDevice9_GetLightEnable
,
3988 (void *)NineDevice9_SetClipPlane
,
3989 (void *)NineDevice9_GetClipPlane
,
3990 (void *)NineDevice9_SetRenderState
,
3991 (void *)NineDevice9_GetRenderState
,
3992 (void *)NineDevice9_CreateStateBlock
,
3993 (void *)NineDevice9_BeginStateBlock
,
3994 (void *)NineDevice9_EndStateBlock
,
3995 (void *)NineDevice9_SetClipStatus
,
3996 (void *)NineDevice9_GetClipStatus
,
3997 (void *)NineDevice9_GetTexture
,
3998 (void *)NineDevice9_SetTexture
,
3999 (void *)NineDevice9_GetTextureStageState
,
4000 (void *)NineDevice9_SetTextureStageState
,
4001 (void *)NineDevice9_GetSamplerState
,
4002 (void *)NineDevice9_SetSamplerState
,
4003 (void *)NineDevice9_ValidateDevice
,
4004 (void *)NineDevice9_SetPaletteEntries
,
4005 (void *)NineDevice9_GetPaletteEntries
,
4006 (void *)NineDevice9_SetCurrentTexturePalette
,
4007 (void *)NineDevice9_GetCurrentTexturePalette
,
4008 (void *)NineDevice9_SetScissorRect
,
4009 (void *)NineDevice9_GetScissorRect
,
4010 (void *)NineDevice9_SetSoftwareVertexProcessing
,
4011 (void *)NineDevice9_GetSoftwareVertexProcessing
,
4012 (void *)NineDevice9_SetNPatchMode
,
4013 (void *)NineDevice9_GetNPatchMode
,
4014 (void *)NineDevice9_DrawPrimitive
,
4015 (void *)NineDevice9_DrawIndexedPrimitive
,
4016 (void *)NineDevice9_DrawPrimitiveUP
,
4017 (void *)NineDevice9_DrawIndexedPrimitiveUP
,
4018 (void *)NineDevice9_ProcessVertices
,
4019 (void *)NineDevice9_CreateVertexDeclaration
,
4020 (void *)NineDevice9_SetVertexDeclaration
,
4021 (void *)NineDevice9_GetVertexDeclaration
,
4022 (void *)NineDevice9_SetFVF
,
4023 (void *)NineDevice9_GetFVF
,
4024 (void *)NineDevice9_CreateVertexShader
,
4025 (void *)NineDevice9_SetVertexShader
,
4026 (void *)NineDevice9_GetVertexShader
,
4027 (void *)NineDevice9_SetVertexShaderConstantF
,
4028 (void *)NineDevice9_GetVertexShaderConstantF
,
4029 (void *)NineDevice9_SetVertexShaderConstantI
,
4030 (void *)NineDevice9_GetVertexShaderConstantI
,
4031 (void *)NineDevice9_SetVertexShaderConstantB
,
4032 (void *)NineDevice9_GetVertexShaderConstantB
,
4033 (void *)NineDevice9_SetStreamSource
,
4034 (void *)NineDevice9_GetStreamSource
,
4035 (void *)NineDevice9_SetStreamSourceFreq
,
4036 (void *)NineDevice9_GetStreamSourceFreq
,
4037 (void *)NineDevice9_SetIndices
,
4038 (void *)NineDevice9_GetIndices
,
4039 (void *)NineDevice9_CreatePixelShader
,
4040 (void *)NineDevice9_SetPixelShader
,
4041 (void *)NineDevice9_GetPixelShader
,
4042 (void *)NineDevice9_SetPixelShaderConstantF
,
4043 (void *)NineDevice9_GetPixelShaderConstantF
,
4044 (void *)NineDevice9_SetPixelShaderConstantI
,
4045 (void *)NineDevice9_GetPixelShaderConstantI
,
4046 (void *)NineDevice9_SetPixelShaderConstantB
,
4047 (void *)NineDevice9_GetPixelShaderConstantB
,
4048 (void *)NineDevice9_DrawRectPatch
,
4049 (void *)NineDevice9_DrawTriPatch
,
4050 (void *)NineDevice9_DeletePatch
,
4051 (void *)NineDevice9_CreateQuery
4054 static const GUID
*NineDevice9_IIDs
[] = {
4055 &IID_IDirect3DDevice9
,
4061 NineDevice9_new( struct pipe_screen
*pScreen
,
4062 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
4064 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
4066 ID3DPresentGroup
*pPresentationGroup
,
4067 struct d3dadapter9_context
*pCTX
,
4069 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
4070 struct NineDevice9
**ppOut
,
4071 int minorVersionNum
)
4074 lock
= !!(pCreationParameters
->BehaviorFlags
& D3DCREATE_MULTITHREADED
);
4076 NINE_NEW(Device9
, ppOut
, lock
, /* args */
4077 pScreen
, pCreationParameters
, pCaps
,
4078 pPresentationParameters
, pD3D9
, pPresentationGroup
, pCTX
,
4079 ex
, pFullscreenDisplayMode
, minorVersionNum
);