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 nine_context_set_viewport(This
, &This
->state
.viewport
);
105 This
->state
.scissor
.minx
= 0;
106 This
->state
.scissor
.miny
= 0;
107 This
->state
.scissor
.maxx
= refSurf
->desc
.Width
;
108 This
->state
.scissor
.maxy
= refSurf
->desc
.Height
;
110 nine_context_set_scissor(This
, &This
->state
.scissor
);
112 if (This
->nswapchains
&& This
->swapchains
[0]->params
.EnableAutoDepthStencil
) {
113 nine_context_set_render_state(This
, D3DRS_ZENABLE
, TRUE
);
114 This
->state
.rs_advertised
[D3DRS_ZENABLE
] = TRUE
;
116 if (This
->state
.rs_advertised
[D3DRS_ZENABLE
])
117 NineDevice9_SetDepthStencilSurface(
118 This
, (IDirect3DSurface9
*)This
->swapchains
[0]->zsbuf
);
121 #define GET_PCAP(n) pScreen->get_param(pScreen, PIPE_CAP_##n)
123 NineDevice9_ctor( struct NineDevice9
*This
,
124 struct NineUnknownParams
*pParams
,
125 struct pipe_screen
*pScreen
,
126 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
128 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
130 ID3DPresentGroup
*pPresentationGroup
,
131 struct d3dadapter9_context
*pCTX
,
133 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
134 int minorVersionNum
)
137 HRESULT hr
= NineUnknown_ctor(&This
->base
, pParams
);
139 DBG("This=%p pParams=%p pScreen=%p pCreationParameters=%p pCaps=%p pPresentationParameters=%p "
140 "pD3D9=%p pPresentationGroup=%p pCTX=%p ex=%d pFullscreenDisplayMode=%p\n",
141 This
, pParams
, pScreen
, pCreationParameters
, pCaps
, pPresentationParameters
, pD3D9
,
142 pPresentationGroup
, pCTX
, (int) ex
, pFullscreenDisplayMode
);
144 if (FAILED(hr
)) { return hr
; }
146 list_inithead(&This
->update_buffers
);
147 list_inithead(&This
->update_textures
);
148 list_inithead(&This
->managed_buffers
);
149 list_inithead(&This
->managed_textures
);
151 This
->screen
= pScreen
;
152 This
->screen_sw
= pCTX
->ref
;
155 This
->params
= *pCreationParameters
;
157 This
->present
= pPresentationGroup
;
158 This
->minor_version_num
= minorVersionNum
;
160 IDirect3D9_AddRef(This
->d3d9
);
161 ID3DPresentGroup_AddRef(This
->present
);
163 if (!(This
->params
.BehaviorFlags
& D3DCREATE_FPU_PRESERVE
))
166 if (This
->params
.BehaviorFlags
& D3DCREATE_SOFTWARE_VERTEXPROCESSING
) {
167 DBG("Application asked full Software Vertex Processing.\n");
169 This
->may_swvp
= true;
172 if (This
->params
.BehaviorFlags
& D3DCREATE_MIXED_VERTEXPROCESSING
) {
173 DBG("Application asked mixed Software Vertex Processing.\n");
174 This
->may_swvp
= true;
176 This
->context
.swvp
= This
->swvp
;
177 /* TODO: check if swvp is resetted by device Resets */
179 if (This
->may_swvp
&&
180 (This
->screen
->get_shader_param(This
->screen
, PIPE_SHADER_VERTEX
,
181 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
)
182 < (NINE_MAX_CONST_F_SWVP
/2) * sizeof(float[4]) ||
183 This
->screen
->get_shader_param(This
->screen
, PIPE_SHADER_VERTEX
,
184 PIPE_SHADER_CAP_MAX_CONST_BUFFERS
) < 5)) {
185 /* Note: We just go on, some apps never use the abilities of
186 * swvp, and just set more constants than allowed at init.
187 * Only cards we support that are affected are the r500 */
188 WARN("Card unable to handle Software Vertex Processing. Game may fail\n");
191 /* When may_swvp, SetConstant* limits are different */
193 This
->caps
.MaxVertexShaderConst
= NINE_MAX_CONST_F_SWVP
;
195 This
->context
.pipe
= This
->screen
->context_create(This
->screen
, NULL
, 0);
196 if (!This
->context
.pipe
) { return E_OUTOFMEMORY
; } /* guess */
197 This
->pipe_sw
= This
->screen_sw
->context_create(This
->screen_sw
, NULL
, 0);
198 if (!This
->pipe_sw
) { return E_OUTOFMEMORY
; }
200 This
->context
.cso
= cso_create_context(This
->context
.pipe
);
201 if (!This
->context
.cso
) { return E_OUTOFMEMORY
; } /* also a guess */
202 This
->cso_sw
= cso_create_context(This
->pipe_sw
);
203 if (!This
->cso_sw
) { return E_OUTOFMEMORY
; }
205 /* Create first, it messes up our state. */
206 This
->hud
= hud_create(This
->context
.pipe
, This
->context
.cso
); /* NULL result is fine */
208 /* Available memory counter. Updated only for allocations with this device
209 * instance. This is the Win 7 behavior.
210 * Win XP shares this counter across multiple devices. */
211 This
->available_texture_mem
= This
->screen
->get_param(This
->screen
, PIPE_CAP_VIDEO_MEMORY
);
212 if (This
->available_texture_mem
< 4096)
213 This
->available_texture_mem
<<= 20;
215 This
->available_texture_mem
= UINT_MAX
;
216 /* We cap texture memory usage to 80% of what is reported free initially
217 * This helps get closer Win behaviour. For example VertexBuffer allocation
218 * still succeeds when texture allocation fails. */
219 This
->available_texture_limit
= This
->available_texture_mem
* 20LL / 100LL;
221 /* create implicit swapchains */
222 This
->nswapchains
= ID3DPresentGroup_GetMultiheadCount(This
->present
);
223 This
->swapchains
= CALLOC(This
->nswapchains
,
224 sizeof(struct NineSwapChain9
*));
225 if (!This
->swapchains
) { return E_OUTOFMEMORY
; }
227 for (i
= 0; i
< This
->nswapchains
; ++i
) {
228 ID3DPresent
*present
;
230 hr
= ID3DPresentGroup_GetPresent(This
->present
, i
, &present
);
235 D3DDISPLAYMODEEX
*mode
= NULL
;
236 struct NineSwapChain9Ex
**ret
=
237 (struct NineSwapChain9Ex
**)&This
->swapchains
[i
];
239 if (pFullscreenDisplayMode
) mode
= &(pFullscreenDisplayMode
[i
]);
240 /* when this is a Device9Ex, it should create SwapChain9Exs */
241 hr
= NineSwapChain9Ex_new(This
, TRUE
, present
,
242 &pPresentationParameters
[i
], pCTX
,
243 This
->params
.hFocusWindow
, mode
, ret
);
245 hr
= NineSwapChain9_new(This
, TRUE
, present
,
246 &pPresentationParameters
[i
], pCTX
,
247 This
->params
.hFocusWindow
,
248 &This
->swapchains
[i
]);
251 ID3DPresent_Release(present
);
254 NineUnknown_ConvertRefToBind(NineUnknown(This
->swapchains
[i
]));
256 hr
= NineSwapChain9_GetBackBuffer(This
->swapchains
[i
], 0,
257 D3DBACKBUFFER_TYPE_MONO
,
258 (IDirect3DSurface9
**)
262 NineUnknown_ConvertRefToBind(NineUnknown(This
->state
.rt
[i
]));
263 nine_bind(&This
->context
.rt
[i
], This
->state
.rt
[i
]);
266 /* Initialize CSMT */
267 if (pCTX
->csmt_force
== 1)
268 This
->csmt_active
= true;
269 else if (pCTX
->csmt_force
== 0)
270 This
->csmt_active
= false;
272 /* r600 and radeonsi are thread safe. */
273 This
->csmt_active
= strstr(pScreen
->get_name(pScreen
), "AMD") != NULL
;
275 if (This
->csmt_active
) {
276 This
->csmt_ctx
= nine_csmt_create(This
);
278 return E_OUTOFMEMORY
;
281 if (This
->csmt_active
)
282 DBG("\033[1;32mCSMT is active\033[0m\n");
284 /* Initialize a dummy VBO to be used when a vertex declaration does not
285 * specify all the inputs needed by vertex shader, on win default behavior
286 * is to pass 0,0,0,0 to the shader */
288 struct pipe_transfer
*transfer
;
289 struct pipe_resource tmpl
;
293 memset(&tmpl
, 0, sizeof(tmpl
));
294 tmpl
.target
= PIPE_BUFFER
;
295 tmpl
.format
= PIPE_FORMAT_R8_UNORM
;
296 tmpl
.width0
= 16; /* 4 floats */
302 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
303 tmpl
.bind
= PIPE_BIND_VERTEX_BUFFER
;
305 This
->dummy_vbo
= pScreen
->resource_create(pScreen
, &tmpl
);
307 if (!This
->dummy_vbo
)
308 return D3DERR_OUTOFVIDEOMEMORY
;
310 u_box_1d(0, 16, &box
);
311 data
= This
->context
.pipe
->transfer_map(This
->context
.pipe
, This
->dummy_vbo
, 0,
312 PIPE_TRANSFER_WRITE
|
313 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
318 This
->context
.pipe
->transfer_unmap(This
->context
.pipe
, transfer
);
321 This
->cursor
.software
= FALSE
;
322 This
->cursor
.hotspot
.x
= -1;
323 This
->cursor
.hotspot
.y
= -1;
325 struct pipe_resource tmpl
;
326 memset(&tmpl
, 0, sizeof(tmpl
));
327 tmpl
.target
= PIPE_TEXTURE_2D
;
328 tmpl
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
335 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
336 tmpl
.bind
= PIPE_BIND_CURSOR
| PIPE_BIND_SAMPLER_VIEW
;
339 This
->cursor
.image
= pScreen
->resource_create(pScreen
, &tmpl
);
340 if (!This
->cursor
.image
)
341 return D3DERR_OUTOFVIDEOMEMORY
;
343 /* For uploading 32x32 (argb) cursor */
344 This
->cursor
.hw_upload_temp
= MALLOC(32 * 4 * 32);
345 if (!This
->cursor
.hw_upload_temp
)
346 return D3DERR_OUTOFVIDEOMEMORY
;
349 /* Create constant buffers. */
351 unsigned max_const_vs
, max_const_ps
;
353 /* vs 3.0: >= 256 float constants, but for cards with exactly 256 slots,
354 * we have to take in some more slots for int and bool*/
355 max_const_vs
= _min(pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
,
356 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
) /
359 /* ps 3.0: 224 float constants. All cards supported support at least
360 * 256 constants for ps */
361 max_const_ps
= NINE_MAX_CONST_F_PS3
+ (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
363 This
->max_vs_const_f
= max_const_vs
-
364 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
365 This
->max_ps_const_f
= max_const_ps
-
366 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
368 This
->vs_const_size
= max_const_vs
* sizeof(float[4]);
369 This
->ps_const_size
= max_const_ps
* sizeof(float[4]);
370 /* Include space for I,B constants for user constbuf. */
371 if (This
->may_swvp
) {
372 This
->state
.vs_const_f
= CALLOC(NINE_MAX_CONST_F_SWVP
* sizeof(float[4]),1);
373 This
->context
.vs_const_f_swvp
= CALLOC(NINE_MAX_CONST_F_SWVP
* sizeof(float[4]),1);
374 if (!This
->context
.vs_const_f_swvp
)
375 return E_OUTOFMEMORY
;
376 This
->state
.vs_lconstf_temp
= CALLOC(NINE_MAX_CONST_F_SWVP
* sizeof(float[4]),1);
377 This
->context
.vs_lconstf_temp
= CALLOC(NINE_MAX_CONST_F_SWVP
* sizeof(float[4]),1);
378 This
->state
.vs_const_i
= CALLOC(NINE_MAX_CONST_I_SWVP
* sizeof(int[4]), 1);
379 This
->context
.vs_const_i
= CALLOC(NINE_MAX_CONST_I_SWVP
* sizeof(int[4]), 1);
380 This
->state
.vs_const_b
= CALLOC(NINE_MAX_CONST_B_SWVP
* sizeof(BOOL
), 1);
381 This
->context
.vs_const_b
= CALLOC(NINE_MAX_CONST_B_SWVP
* sizeof(BOOL
), 1);
383 This
->state
.vs_const_f
= CALLOC(NINE_MAX_CONST_F
* sizeof(float[4]), 1);
384 This
->context
.vs_const_f_swvp
= NULL
;
385 This
->state
.vs_lconstf_temp
= CALLOC(This
->vs_const_size
,1);
386 This
->context
.vs_lconstf_temp
= CALLOC(This
->vs_const_size
,1);
387 This
->state
.vs_const_i
= CALLOC(NINE_MAX_CONST_I
* sizeof(int[4]), 1);
388 This
->context
.vs_const_i
= CALLOC(NINE_MAX_CONST_I
* sizeof(int[4]), 1);
389 This
->state
.vs_const_b
= CALLOC(NINE_MAX_CONST_B
* sizeof(BOOL
), 1);
390 This
->context
.vs_const_b
= CALLOC(NINE_MAX_CONST_B
* sizeof(BOOL
), 1);
392 This
->context
.vs_const_f
= CALLOC(This
->vs_const_size
, 1);
393 This
->state
.ps_const_f
= CALLOC(This
->ps_const_size
, 1);
394 This
->context
.ps_const_f
= CALLOC(This
->ps_const_size
, 1);
395 This
->context
.ps_lconstf_temp
= CALLOC(This
->ps_const_size
,1);
396 if (!This
->state
.vs_const_f
|| !This
->context
.vs_const_f
||
397 !This
->state
.ps_const_f
|| !This
->context
.ps_const_f
||
398 !This
->state
.vs_lconstf_temp
|| !This
->context
.vs_lconstf_temp
||
399 !This
->context
.ps_lconstf_temp
||
400 !This
->state
.vs_const_i
|| !This
->context
.vs_const_i
||
401 !This
->state
.vs_const_b
|| !This
->context
.vs_const_b
)
402 return E_OUTOFMEMORY
;
404 if (strstr(pScreen
->get_name(pScreen
), "AMD") ||
405 strstr(pScreen
->get_name(pScreen
), "ATI")) {
406 This
->driver_bugs
.buggy_barycentrics
= TRUE
;
410 /* allocate dummy texture/sampler for when there are missing ones bound */
412 struct pipe_resource tmplt
;
413 struct pipe_sampler_view templ
;
414 struct pipe_sampler_state samp
;
415 memset(&tmplt
, 0, sizeof(tmplt
));
416 memset(&samp
, 0, sizeof(samp
));
418 tmplt
.target
= PIPE_TEXTURE_2D
;
422 tmplt
.last_level
= 0;
423 tmplt
.array_size
= 1;
424 tmplt
.usage
= PIPE_USAGE_DEFAULT
;
426 tmplt
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
427 tmplt
.bind
= PIPE_BIND_SAMPLER_VIEW
;
428 tmplt
.nr_samples
= 0;
430 This
->dummy_texture
= This
->screen
->resource_create(This
->screen
, &tmplt
);
431 if (!This
->dummy_texture
)
432 return D3DERR_DRIVERINTERNALERROR
;
434 templ
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
435 templ
.u
.tex
.first_layer
= 0;
436 templ
.u
.tex
.last_layer
= 0;
437 templ
.u
.tex
.first_level
= 0;
438 templ
.u
.tex
.last_level
= 0;
439 templ
.swizzle_r
= PIPE_SWIZZLE_0
;
440 templ
.swizzle_g
= PIPE_SWIZZLE_0
;
441 templ
.swizzle_b
= PIPE_SWIZZLE_0
;
442 templ
.swizzle_a
= PIPE_SWIZZLE_1
;
443 templ
.target
= This
->dummy_texture
->target
;
445 This
->dummy_sampler_view
= This
->context
.pipe
->create_sampler_view(This
->context
.pipe
, This
->dummy_texture
, &templ
);
446 if (!This
->dummy_sampler_view
)
447 return D3DERR_DRIVERINTERNALERROR
;
449 samp
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
450 samp
.max_lod
= 15.0f
;
451 samp
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
452 samp
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
453 samp
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
454 samp
.min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
455 samp
.mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
456 samp
.compare_mode
= PIPE_TEX_COMPARE_NONE
;
457 samp
.compare_func
= PIPE_FUNC_LEQUAL
;
458 samp
.normalized_coords
= 1;
459 samp
.seamless_cube_map
= 0;
460 This
->dummy_sampler_state
= samp
;
463 /* Allocate upload helper for drivers that suck (from st pov ;). */
465 This
->driver_caps
.user_vbufs
= GET_PCAP(USER_VERTEX_BUFFERS
) && !This
->csmt_active
;
466 This
->driver_caps
.user_ibufs
= GET_PCAP(USER_INDEX_BUFFERS
) && !This
->csmt_active
;
467 This
->driver_caps
.user_cbufs
= GET_PCAP(USER_CONSTANT_BUFFERS
);
468 This
->driver_caps
.user_sw_vbufs
= This
->screen_sw
->get_param(This
->screen_sw
, PIPE_CAP_USER_VERTEX_BUFFERS
);
469 This
->driver_caps
.user_sw_cbufs
= This
->screen_sw
->get_param(This
->screen_sw
, PIPE_CAP_USER_CONSTANT_BUFFERS
);
471 if (!This
->driver_caps
.user_vbufs
)
472 This
->vertex_uploader
= u_upload_create(This
->context
.pipe
, 65536,
473 PIPE_BIND_VERTEX_BUFFER
, PIPE_USAGE_STREAM
);
474 This
->vertex_sw_uploader
= u_upload_create(This
->pipe_sw
, 65536,
475 PIPE_BIND_VERTEX_BUFFER
, PIPE_USAGE_STREAM
);
476 if (!This
->driver_caps
.user_ibufs
)
477 This
->index_uploader
= u_upload_create(This
->context
.pipe
, 128 * 1024,
478 PIPE_BIND_INDEX_BUFFER
, PIPE_USAGE_STREAM
);
479 if (!This
->driver_caps
.user_cbufs
) {
480 This
->constbuf_alignment
= GET_PCAP(CONSTANT_BUFFER_OFFSET_ALIGNMENT
);
481 This
->constbuf_uploader
= u_upload_create(This
->context
.pipe
, This
->vs_const_size
,
482 PIPE_BIND_CONSTANT_BUFFER
, PIPE_USAGE_STREAM
);
485 This
->constbuf_sw_uploader
= u_upload_create(This
->pipe_sw
, 128 * 1024,
486 PIPE_BIND_CONSTANT_BUFFER
, PIPE_USAGE_STREAM
);
488 This
->driver_caps
.window_space_position_support
= GET_PCAP(TGSI_VS_WINDOW_SPACE_POSITION
);
489 This
->driver_caps
.vs_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
, PIPE_SHADER_CAP_INTEGERS
);
490 This
->driver_caps
.ps_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_FRAGMENT
, PIPE_SHADER_CAP_INTEGERS
);
491 This
->driver_caps
.offset_units_unscaled
= GET_PCAP(POLYGON_OFFSET_UNITS_UNSCALED
);
493 nine_ff_init(This
); /* initialize fixed function code */
495 NineDevice9_SetDefaultState(This
, FALSE
);
498 struct pipe_poly_stipple stipple
;
499 memset(&stipple
, ~0, sizeof(stipple
));
500 This
->context
.pipe
->set_polygon_stipple(This
->context
.pipe
, &stipple
);
503 This
->update
= &This
->state
;
505 nine_state_init_sw(This
);
507 ID3DPresentGroup_Release(This
->present
);
508 if (This
->csmt_active
)
509 nine_csmt_process(This
);
516 NineDevice9_dtor( struct NineDevice9
*This
)
520 DBG("This=%p\n", This
);
522 /* Do not call nine_csmt_process here. The device is dead! */
523 if (This
->csmt_active
&& This
->csmt_ctx
) {
524 nine_csmt_destroy(This
, This
->csmt_ctx
);
525 This
->csmt_active
= FALSE
;
526 This
->csmt_ctx
= NULL
;
530 nine_state_destroy_sw(This
);
531 nine_state_clear(&This
->state
, TRUE
);
532 nine_context_clear(This
);
534 if (This
->vertex_uploader
)
535 u_upload_destroy(This
->vertex_uploader
);
536 if (This
->index_uploader
)
537 u_upload_destroy(This
->index_uploader
);
538 if (This
->constbuf_uploader
)
539 u_upload_destroy(This
->constbuf_uploader
);
540 if (This
->vertex_sw_uploader
)
541 u_upload_destroy(This
->vertex_sw_uploader
);
542 if (This
->constbuf_sw_uploader
)
543 u_upload_destroy(This
->constbuf_sw_uploader
);
545 nine_bind(&This
->record
, NULL
);
547 pipe_sampler_view_reference(&This
->dummy_sampler_view
, NULL
);
548 pipe_resource_reference(&This
->dummy_texture
, NULL
);
549 pipe_resource_reference(&This
->dummy_vbo
, NULL
);
550 FREE(This
->state
.vs_const_f
);
551 FREE(This
->context
.vs_const_f
);
552 FREE(This
->state
.ps_const_f
);
553 FREE(This
->context
.ps_const_f
);
554 FREE(This
->state
.vs_lconstf_temp
);
555 FREE(This
->context
.vs_lconstf_temp
);
556 FREE(This
->context
.ps_lconstf_temp
);
557 FREE(This
->state
.vs_const_i
);
558 FREE(This
->context
.vs_const_i
);
559 FREE(This
->state
.vs_const_b
);
560 FREE(This
->context
.vs_const_b
);
561 FREE(This
->context
.vs_const_f_swvp
);
563 pipe_resource_reference(&This
->cursor
.image
, NULL
);
564 FREE(This
->cursor
.hw_upload_temp
);
566 if (This
->swapchains
) {
567 for (i
= 0; i
< This
->nswapchains
; ++i
)
568 if (This
->swapchains
[i
])
569 NineUnknown_Unbind(NineUnknown(This
->swapchains
[i
]));
570 FREE(This
->swapchains
);
573 /* Destroy cso first */
574 if (This
->context
.cso
) { cso_destroy_context(This
->context
.cso
); }
575 if (This
->cso_sw
) { cso_destroy_context(This
->cso_sw
); }
576 if (This
->context
.pipe
&& This
->context
.pipe
->destroy
) { This
->context
.pipe
->destroy(This
->context
.pipe
); }
577 if (This
->pipe_sw
&& This
->pipe_sw
->destroy
) { This
->pipe_sw
->destroy(This
->pipe_sw
); }
579 if (This
->present
) { ID3DPresentGroup_Release(This
->present
); }
580 if (This
->d3d9
) { IDirect3D9_Release(This
->d3d9
); }
582 NineUnknown_dtor(&This
->base
);
586 NineDevice9_GetScreen( struct NineDevice9
*This
)
591 struct pipe_context
*
592 NineDevice9_GetPipe( struct NineDevice9
*This
)
594 return nine_context_get_pipe(This
);
598 NineDevice9_GetCaps( struct NineDevice9
*This
)
604 NineDevice9_PauseRecording( struct NineDevice9
*This
)
607 This
->update
= &This
->state
;
608 This
->is_recording
= FALSE
;
613 NineDevice9_ResumeRecording( struct NineDevice9
*This
)
616 This
->update
= &This
->record
->state
;
617 This
->is_recording
= TRUE
;
622 NineDevice9_TestCooperativeLevel( struct NineDevice9
*This
)
624 if (NineSwapChain9_GetOccluded(This
->swapchains
[0])) {
625 This
->device_needs_reset
= TRUE
;
626 return D3DERR_DEVICELOST
;
627 } else if (NineSwapChain9_ResolutionMismatch(This
->swapchains
[0])) {
628 This
->device_needs_reset
= TRUE
;
629 return D3DERR_DEVICENOTRESET
;
630 } else if (This
->device_needs_reset
) {
631 return D3DERR_DEVICENOTRESET
;
638 NineDevice9_GetAvailableTextureMem( struct NineDevice9
*This
)
640 return This
->available_texture_mem
;
644 NineDevice9_EvictManagedResources( struct NineDevice9
*This
)
646 struct NineBaseTexture9
*tex
;
647 struct NineBuffer9
*buf
;
649 DBG("This=%p\n", This
);
650 LIST_FOR_EACH_ENTRY(tex
, &This
->managed_textures
, list2
) {
651 NineBaseTexture9_UnLoad(tex
);
653 /* Vertex/index buffers don't take a lot of space and aren't accounted
654 * for d3d memory usage. Instead of actually freeing from memory,
655 * just mark the buffer dirty to trigger a re-upload later. We
656 * could just ignore, but some bad behaving apps could rely on it (if
657 * they write outside the locked regions typically). */
658 LIST_FOR_EACH_ENTRY(buf
, &This
->managed_buffers
, managed
.list2
) {
659 NineBuffer9_SetDirty(buf
);
666 NineDevice9_GetDirect3D( struct NineDevice9
*This
,
667 IDirect3D9
**ppD3D9
)
669 user_assert(ppD3D9
!= NULL
, E_POINTER
);
670 IDirect3D9_AddRef(This
->d3d9
);
671 *ppD3D9
= This
->d3d9
;
676 NineDevice9_GetDeviceCaps( struct NineDevice9
*This
,
679 user_assert(pCaps
!= NULL
, D3DERR_INVALIDCALL
);
685 NineDevice9_GetDisplayMode( struct NineDevice9
*This
,
687 D3DDISPLAYMODE
*pMode
)
689 DBG("This=%p iSwapChain=%u pMode=%p\n", This
, iSwapChain
, pMode
);
691 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
693 return NineSwapChain9_GetDisplayMode(This
->swapchains
[iSwapChain
], pMode
);
697 NineDevice9_GetCreationParameters( struct NineDevice9
*This
,
698 D3DDEVICE_CREATION_PARAMETERS
*pParameters
)
700 user_assert(pParameters
!= NULL
, D3DERR_INVALIDCALL
);
701 *pParameters
= This
->params
;
706 NineDevice9_SetCursorProperties( struct NineDevice9
*This
,
709 IDirect3DSurface9
*pCursorBitmap
)
711 struct NineSurface9
*surf
= NineSurface9(pCursorBitmap
);
712 struct pipe_context
*pipe
= NineDevice9_GetPipe(This
);
714 struct pipe_transfer
*transfer
;
718 DBG_FLAG(DBG_SWAPCHAIN
, "This=%p XHotSpot=%u YHotSpot=%u "
719 "pCursorBitmap=%p\n", This
, XHotSpot
, YHotSpot
, pCursorBitmap
);
721 user_assert(pCursorBitmap
, D3DERR_INVALIDCALL
);
722 user_assert(surf
->desc
.Format
== D3DFMT_A8R8G8B8
, D3DERR_INVALIDCALL
);
724 if (This
->swapchains
[0]->params
.Windowed
) {
725 This
->cursor
.w
= MIN2(surf
->desc
.Width
, 32);
726 This
->cursor
.h
= MIN2(surf
->desc
.Height
, 32);
727 hw_cursor
= 1; /* always use hw cursor for windowed mode */
729 This
->cursor
.w
= MIN2(surf
->desc
.Width
, This
->cursor
.image
->width0
);
730 This
->cursor
.h
= MIN2(surf
->desc
.Height
, This
->cursor
.image
->height0
);
731 hw_cursor
= This
->cursor
.w
== 32 && This
->cursor
.h
== 32;
734 u_box_origin_2d(This
->cursor
.w
, This
->cursor
.h
, &box
);
736 ptr
= pipe
->transfer_map(pipe
, This
->cursor
.image
, 0,
737 PIPE_TRANSFER_WRITE
|
738 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
741 ret_err("Failed to update cursor image.\n", D3DERR_DRIVERINTERNALERROR
);
743 This
->cursor
.hotspot
.x
= XHotSpot
;
744 This
->cursor
.hotspot
.y
= YHotSpot
;
746 /* Copy cursor image to internal storage. */
750 const struct util_format_description
*sfmt
=
751 util_format_description(surf
->base
.info
.format
);
754 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, D3DLOCK_READONLY
);
756 ret_err("Failed to map cursor source image.\n",
757 D3DERR_DRIVERINTERNALERROR
);
759 sfmt
->unpack_rgba_8unorm(ptr
, transfer
->stride
,
760 lock
.pBits
, lock
.Pitch
,
761 This
->cursor
.w
, This
->cursor
.h
);
764 void *data
= lock
.pBits
;
765 /* SetCursor assumes 32x32 argb with pitch 128 */
766 if (lock
.Pitch
!= 128) {
767 sfmt
->unpack_rgba_8unorm(This
->cursor
.hw_upload_temp
, 128,
768 lock
.pBits
, lock
.Pitch
,
770 data
= This
->cursor
.hw_upload_temp
;
772 hw_cursor
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
,
774 &This
->cursor
.hotspot
,
775 This
->cursor
.visible
) == D3D_OK
;
778 NineSurface9_UnlockRect(surf
);
780 pipe
->transfer_unmap(pipe
, transfer
);
782 /* hide cursor if we emulate it */
784 ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, FALSE
);
785 This
->cursor
.software
= !hw_cursor
;
791 NineDevice9_SetCursorPosition( struct NineDevice9
*This
,
796 struct NineSwapChain9
*swap
= This
->swapchains
[0];
798 DBG("This=%p X=%d Y=%d Flags=%d\n", This
, X
, Y
, Flags
);
800 This
->cursor
.pos
.x
= X
;
801 This
->cursor
.pos
.y
= Y
;
803 if (!This
->cursor
.software
)
804 This
->cursor
.software
= ID3DPresent_SetCursorPos(swap
->present
, &This
->cursor
.pos
) != D3D_OK
;
808 NineDevice9_ShowCursor( struct NineDevice9
*This
,
811 BOOL old
= This
->cursor
.visible
;
813 DBG("This=%p bShow=%d\n", This
, (int) bShow
);
815 This
->cursor
.visible
= bShow
&& (This
->cursor
.hotspot
.x
!= -1);
816 if (!This
->cursor
.software
)
817 This
->cursor
.software
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, bShow
) != D3D_OK
;
823 NineDevice9_CreateAdditionalSwapChain( struct NineDevice9
*This
,
824 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
825 IDirect3DSwapChain9
**pSwapChain
)
827 struct NineSwapChain9
*swapchain
, *tmplt
= This
->swapchains
[0];
828 ID3DPresent
*present
;
831 DBG("This=%p pPresentationParameters=%p pSwapChain=%p\n",
832 This
, pPresentationParameters
, pSwapChain
);
834 user_assert(pPresentationParameters
, D3DERR_INVALIDCALL
);
835 user_assert(tmplt
->params
.Windowed
&& pPresentationParameters
->Windowed
, D3DERR_INVALIDCALL
);
837 /* TODO: this deserves more tests */
838 if (!pPresentationParameters
->hDeviceWindow
)
839 pPresentationParameters
->hDeviceWindow
= This
->params
.hFocusWindow
;
841 hr
= ID3DPresentGroup_CreateAdditionalPresent(This
->present
, pPresentationParameters
, &present
);
846 hr
= NineSwapChain9_new(This
, FALSE
, present
, pPresentationParameters
,
848 tmplt
->params
.hDeviceWindow
,
853 *pSwapChain
= (IDirect3DSwapChain9
*)swapchain
;
858 NineDevice9_GetSwapChain( struct NineDevice9
*This
,
860 IDirect3DSwapChain9
**pSwapChain
)
862 user_assert(pSwapChain
!= NULL
, D3DERR_INVALIDCALL
);
865 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
867 NineUnknown_AddRef(NineUnknown(This
->swapchains
[iSwapChain
]));
868 *pSwapChain
= (IDirect3DSwapChain9
*)This
->swapchains
[iSwapChain
];
874 NineDevice9_GetNumberOfSwapChains( struct NineDevice9
*This
)
876 return This
->nswapchains
;
880 NineDevice9_Reset( struct NineDevice9
*This
,
881 D3DPRESENT_PARAMETERS
*pPresentationParameters
)
886 DBG("This=%p pPresentationParameters=%p\n", This
, pPresentationParameters
);
888 if (NineSwapChain9_GetOccluded(This
->swapchains
[0])) {
889 This
->device_needs_reset
= TRUE
;
890 return D3DERR_DEVICELOST
;
893 for (i
= 0; i
< This
->nswapchains
; ++i
) {
894 D3DPRESENT_PARAMETERS
*params
= &pPresentationParameters
[i
];
895 hr
= NineSwapChain9_Resize(This
->swapchains
[i
], params
, NULL
);
900 nine_state_clear(&This
->state
, TRUE
);
901 nine_context_clear(This
);
903 NineDevice9_SetDefaultState(This
, TRUE
);
904 NineDevice9_SetRenderTarget(
905 This
, 0, (IDirect3DSurface9
*)This
->swapchains
[0]->buffers
[0]);
906 /* XXX: better use GetBackBuffer here ? */
908 This
->device_needs_reset
= (hr
!= D3D_OK
);
913 NineDevice9_Present( struct NineDevice9
*This
,
914 const RECT
*pSourceRect
,
915 const RECT
*pDestRect
,
916 HWND hDestWindowOverride
,
917 const RGNDATA
*pDirtyRegion
)
922 DBG("This=%p pSourceRect=%p pDestRect=%p hDestWindowOverride=%p pDirtyRegion=%p\n",
923 This
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
925 /* XXX is this right? */
926 for (i
= 0; i
< This
->nswapchains
; ++i
) {
927 hr
= NineSwapChain9_Present(This
->swapchains
[i
], pSourceRect
, pDestRect
,
928 hDestWindowOverride
, pDirtyRegion
, 0);
929 if (FAILED(hr
)) { return hr
; }
936 NineDevice9_GetBackBuffer( struct NineDevice9
*This
,
939 D3DBACKBUFFER_TYPE Type
,
940 IDirect3DSurface9
**ppBackBuffer
)
942 user_assert(ppBackBuffer
!= NULL
, D3DERR_INVALIDCALL
);
943 /* return NULL on error */
944 *ppBackBuffer
= NULL
;
945 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
947 return NineSwapChain9_GetBackBuffer(This
->swapchains
[iSwapChain
],
948 iBackBuffer
, Type
, ppBackBuffer
);
952 NineDevice9_GetRasterStatus( struct NineDevice9
*This
,
954 D3DRASTER_STATUS
*pRasterStatus
)
956 user_assert(pRasterStatus
!= NULL
, D3DERR_INVALIDCALL
);
957 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
959 return NineSwapChain9_GetRasterStatus(This
->swapchains
[iSwapChain
],
964 NineDevice9_SetDialogBoxMode( struct NineDevice9
*This
,
965 BOOL bEnableDialogs
)
967 STUB(D3DERR_INVALIDCALL
);
971 NineDevice9_SetGammaRamp( struct NineDevice9
*This
,
974 const D3DGAMMARAMP
*pRamp
)
976 DBG("This=%p iSwapChain=%u Flags=%x pRamp=%p\n", This
,
977 iSwapChain
, Flags
, pRamp
);
979 user_warn(iSwapChain
>= This
->nswapchains
);
982 if (pRamp
&& (iSwapChain
< This
->nswapchains
)) {
983 struct NineSwapChain9
*swap
= This
->swapchains
[iSwapChain
];
984 swap
->gamma
= *pRamp
;
985 ID3DPresent_SetGammaRamp(swap
->present
, pRamp
, swap
->params
.hDeviceWindow
);
990 NineDevice9_GetGammaRamp( struct NineDevice9
*This
,
992 D3DGAMMARAMP
*pRamp
)
994 DBG("This=%p iSwapChain=%u pRamp=%p\n", This
, iSwapChain
, pRamp
);
996 user_warn(iSwapChain
>= This
->nswapchains
);
999 if (pRamp
&& (iSwapChain
< This
->nswapchains
))
1000 *pRamp
= This
->swapchains
[iSwapChain
]->gamma
;
1004 NineDevice9_CreateTexture( struct NineDevice9
*This
,
1011 IDirect3DTexture9
**ppTexture
,
1012 HANDLE
*pSharedHandle
)
1014 struct NineTexture9
*tex
;
1017 DBG("This=%p Width=%u Height=%u Levels=%u Usage=%s Format=%s Pool=%s "
1018 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Levels
,
1019 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
1020 nine_D3DPOOL_to_str(Pool
), ppTexture
, pSharedHandle
);
1022 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DMAP
|
1023 D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
1024 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
;
1028 hr
= NineTexture9_new(This
, Width
, Height
, Levels
, Usage
, Format
, Pool
,
1029 &tex
, pSharedHandle
);
1031 *ppTexture
= (IDirect3DTexture9
*)tex
;
1037 NineDevice9_CreateVolumeTexture( struct NineDevice9
*This
,
1045 IDirect3DVolumeTexture9
**ppVolumeTexture
,
1046 HANDLE
*pSharedHandle
)
1048 struct NineVolumeTexture9
*tex
;
1051 DBG("This=%p Width=%u Height=%u Depth=%u Levels=%u Usage=%s Format=%s Pool=%s "
1052 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Depth
, Levels
,
1053 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
1054 nine_D3DPOOL_to_str(Pool
), ppVolumeTexture
, pSharedHandle
);
1056 Usage
&= D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1057 D3DUSAGE_SOFTWAREPROCESSING
;
1059 *ppVolumeTexture
= NULL
;
1061 hr
= NineVolumeTexture9_new(This
, Width
, Height
, Depth
, Levels
,
1062 Usage
, Format
, Pool
, &tex
, pSharedHandle
);
1064 *ppVolumeTexture
= (IDirect3DVolumeTexture9
*)tex
;
1070 NineDevice9_CreateCubeTexture( struct NineDevice9
*This
,
1076 IDirect3DCubeTexture9
**ppCubeTexture
,
1077 HANDLE
*pSharedHandle
)
1079 struct NineCubeTexture9
*tex
;
1082 DBG("This=%p EdgeLength=%u Levels=%u Usage=%s Format=%s Pool=%s ppOut=%p "
1083 "pSharedHandle=%p\n", This
, EdgeLength
, Levels
,
1084 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
1085 nine_D3DPOOL_to_str(Pool
), ppCubeTexture
, pSharedHandle
);
1087 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DYNAMIC
|
1088 D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
1089 D3DUSAGE_SOFTWAREPROCESSING
;
1091 *ppCubeTexture
= NULL
;
1093 hr
= NineCubeTexture9_new(This
, EdgeLength
, Levels
, Usage
, Format
, Pool
,
1094 &tex
, pSharedHandle
);
1096 *ppCubeTexture
= (IDirect3DCubeTexture9
*)tex
;
1102 NineDevice9_CreateVertexBuffer( struct NineDevice9
*This
,
1107 IDirect3DVertexBuffer9
**ppVertexBuffer
,
1108 HANDLE
*pSharedHandle
)
1110 struct NineVertexBuffer9
*buf
;
1112 D3DVERTEXBUFFER_DESC desc
;
1114 DBG("This=%p Length=%u Usage=%x FVF=%x Pool=%u ppOut=%p pSharedHandle=%p\n",
1115 This
, Length
, Usage
, FVF
, Pool
, ppVertexBuffer
, pSharedHandle
);
1117 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1119 desc
.Format
= D3DFMT_VERTEXDATA
;
1120 desc
.Type
= D3DRTYPE_VERTEXBUFFER
;
1121 desc
.Usage
= Usage
&
1122 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1123 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1124 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
|
1125 D3DUSAGE_WRITEONLY
);
1130 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1131 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1133 hr
= NineVertexBuffer9_new(This
, &desc
, &buf
);
1135 *ppVertexBuffer
= (IDirect3DVertexBuffer9
*)buf
;
1140 NineDevice9_CreateIndexBuffer( struct NineDevice9
*This
,
1145 IDirect3DIndexBuffer9
**ppIndexBuffer
,
1146 HANDLE
*pSharedHandle
)
1148 struct NineIndexBuffer9
*buf
;
1150 D3DINDEXBUFFER_DESC desc
;
1152 DBG("This=%p Length=%u Usage=%x Format=%s Pool=%u ppOut=%p "
1153 "pSharedHandle=%p\n", This
, Length
, Usage
,
1154 d3dformat_to_string(Format
), Pool
, ppIndexBuffer
, pSharedHandle
);
1156 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1158 desc
.Format
= Format
;
1159 desc
.Type
= D3DRTYPE_INDEXBUFFER
;
1160 desc
.Usage
= Usage
&
1161 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1162 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1163 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_WRITEONLY
);
1167 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1168 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1170 hr
= NineIndexBuffer9_new(This
, &desc
, &buf
);
1172 *ppIndexBuffer
= (IDirect3DIndexBuffer9
*)buf
;
1177 create_zs_or_rt_surface(struct NineDevice9
*This
,
1178 unsigned type
, /* 0 = RT, 1 = ZS, 2 = plain */
1180 UINT Width
, UINT Height
,
1182 D3DMULTISAMPLE_TYPE MultiSample
,
1183 DWORD MultisampleQuality
,
1184 BOOL Discard_or_Lockable
,
1185 IDirect3DSurface9
**ppSurface
,
1186 HANDLE
*pSharedHandle
)
1188 struct NineSurface9
*surface
;
1190 D3DSURFACE_DESC desc
;
1192 DBG("This=%p type=%u Pool=%s Width=%u Height=%u Format=%s MS=%u Quality=%u "
1193 "Discard_or_Lockable=%i ppSurface=%p pSharedHandle=%p\n",
1194 This
, type
, nine_D3DPOOL_to_str(Pool
), Width
, Height
,
1195 d3dformat_to_string(Format
), MultiSample
, MultisampleQuality
,
1196 Discard_or_Lockable
, ppSurface
, pSharedHandle
);
1199 DBG("FIXME Used shared handle! This option isn't probably handled correctly!\n");
1201 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
1202 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1204 desc
.Format
= Format
;
1205 desc
.Type
= D3DRTYPE_SURFACE
;
1208 desc
.MultiSampleType
= MultiSample
;
1209 desc
.MultiSampleQuality
= MultisampleQuality
;
1211 desc
.Height
= Height
;
1213 case 0: desc
.Usage
= D3DUSAGE_RENDERTARGET
; break;
1214 case 1: desc
.Usage
= D3DUSAGE_DEPTHSTENCIL
; break;
1215 default: assert(type
== 2); break;
1218 hr
= NineSurface9_new(This
, NULL
, NULL
, NULL
, 0, 0, 0, &desc
, &surface
);
1219 if (SUCCEEDED(hr
)) {
1220 *ppSurface
= (IDirect3DSurface9
*)surface
;
1222 if (surface
->base
.resource
&& Discard_or_Lockable
&& (type
!= 1))
1223 surface
->base
.resource
->flags
|= NINE_RESOURCE_FLAG_LOCKABLE
;
1230 NineDevice9_CreateRenderTarget( struct NineDevice9
*This
,
1234 D3DMULTISAMPLE_TYPE MultiSample
,
1235 DWORD MultisampleQuality
,
1237 IDirect3DSurface9
**ppSurface
,
1238 HANDLE
*pSharedHandle
)
1241 return create_zs_or_rt_surface(This
, 0, D3DPOOL_DEFAULT
,
1242 Width
, Height
, Format
,
1243 MultiSample
, MultisampleQuality
,
1244 Lockable
, ppSurface
, pSharedHandle
);
1248 NineDevice9_CreateDepthStencilSurface( struct NineDevice9
*This
,
1252 D3DMULTISAMPLE_TYPE MultiSample
,
1253 DWORD MultisampleQuality
,
1255 IDirect3DSurface9
**ppSurface
,
1256 HANDLE
*pSharedHandle
)
1259 if (!depth_stencil_format(Format
))
1260 return D3DERR_NOTAVAILABLE
;
1261 return create_zs_or_rt_surface(This
, 1, D3DPOOL_DEFAULT
,
1262 Width
, Height
, Format
,
1263 MultiSample
, MultisampleQuality
,
1264 Discard
, ppSurface
, pSharedHandle
);
1268 NineDevice9_UpdateSurface( struct NineDevice9
*This
,
1269 IDirect3DSurface9
*pSourceSurface
,
1270 const RECT
*pSourceRect
,
1271 IDirect3DSurface9
*pDestinationSurface
,
1272 const POINT
*pDestPoint
)
1274 struct NineSurface9
*dst
= NineSurface9(pDestinationSurface
);
1275 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1276 int copy_width
, copy_height
;
1279 DBG("This=%p pSourceSurface=%p pDestinationSurface=%p "
1280 "pSourceRect=%p pDestPoint=%p\n", This
,
1281 pSourceSurface
, pDestinationSurface
, pSourceRect
, pDestPoint
);
1283 DBG("pSourceRect = (%u,%u)-(%u,%u)\n",
1284 pSourceRect
->left
, pSourceRect
->top
,
1285 pSourceRect
->right
, pSourceRect
->bottom
);
1287 DBG("pDestPoint = (%u,%u)\n", pDestPoint
->x
, pDestPoint
->y
);
1289 user_assert(dst
&& src
, D3DERR_INVALIDCALL
);
1291 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1292 user_assert(src
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1294 user_assert(dst
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1295 user_assert(src
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1297 user_assert(!src
->lock_count
, D3DERR_INVALIDCALL
);
1298 user_assert(!dst
->lock_count
, D3DERR_INVALIDCALL
);
1300 user_assert(dst
->desc
.Format
== src
->desc
.Format
, D3DERR_INVALIDCALL
);
1301 user_assert(!depth_stencil_format(dst
->desc
.Format
), D3DERR_INVALIDCALL
);
1304 copy_width
= pSourceRect
->right
- pSourceRect
->left
;
1305 copy_height
= pSourceRect
->bottom
- pSourceRect
->top
;
1307 user_assert(pSourceRect
->left
>= 0 &&
1309 pSourceRect
->right
<= src
->desc
.Width
&&
1310 pSourceRect
->top
>= 0 &&
1312 pSourceRect
->bottom
<= src
->desc
.Height
,
1313 D3DERR_INVALIDCALL
);
1315 copy_width
= src
->desc
.Width
;
1316 copy_height
= src
->desc
.Height
;
1319 destRect
.right
= copy_width
;
1320 destRect
.bottom
= copy_height
;
1323 user_assert(pDestPoint
->x
>= 0 && pDestPoint
->y
>= 0,
1324 D3DERR_INVALIDCALL
);
1325 destRect
.right
+= pDestPoint
->x
;
1326 destRect
.bottom
+= pDestPoint
->y
;
1329 user_assert(destRect
.right
<= dst
->desc
.Width
&&
1330 destRect
.bottom
<= dst
->desc
.Height
,
1331 D3DERR_INVALIDCALL
);
1333 if (compressed_format(dst
->desc
.Format
)) {
1334 const unsigned w
= util_format_get_blockwidth(dst
->base
.info
.format
);
1335 const unsigned h
= util_format_get_blockheight(dst
->base
.info
.format
);
1338 user_assert(!(pDestPoint
->x
% w
) && !(pDestPoint
->y
% h
),
1339 D3DERR_INVALIDCALL
);
1343 user_assert(!(pSourceRect
->left
% w
) && !(pSourceRect
->top
% h
),
1344 D3DERR_INVALIDCALL
);
1346 if (!(copy_width
== src
->desc
.Width
&&
1347 copy_width
== dst
->desc
.Width
&&
1348 copy_height
== src
->desc
.Height
&&
1349 copy_height
== dst
->desc
.Height
)) {
1350 user_assert(!(copy_width
% w
) && !(copy_height
% h
),
1351 D3DERR_INVALIDCALL
);
1355 NineSurface9_CopyMemToDefault(dst
, src
, pDestPoint
, pSourceRect
);
1361 NineDevice9_UpdateTexture( struct NineDevice9
*This
,
1362 IDirect3DBaseTexture9
*pSourceTexture
,
1363 IDirect3DBaseTexture9
*pDestinationTexture
)
1365 struct NineBaseTexture9
*dstb
= NineBaseTexture9(pDestinationTexture
);
1366 struct NineBaseTexture9
*srcb
= NineBaseTexture9(pSourceTexture
);
1368 unsigned last_src_level
, last_dst_level
;
1371 DBG("This=%p pSourceTexture=%p pDestinationTexture=%p\n", This
,
1372 pSourceTexture
, pDestinationTexture
);
1374 user_assert(pSourceTexture
&& pDestinationTexture
, D3DERR_INVALIDCALL
);
1375 user_assert(pSourceTexture
!= pDestinationTexture
, D3DERR_INVALIDCALL
);
1377 user_assert(dstb
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1378 user_assert(srcb
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1379 user_assert(dstb
->base
.type
== srcb
->base
.type
, D3DERR_INVALIDCALL
);
1380 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ||
1381 dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
, D3DERR_INVALIDCALL
);
1384 * . Different formats
1385 * . Fewer src levels than dst levels (if the opposite, only matching levels
1386 * are supposed to be copied)
1387 * . Levels do not match
1388 * DDI: Actually the above should pass because of legacy applications
1389 * Do what you want about these, but you shouldn't crash.
1390 * However driver can expect that the top dimension is greater for src than dst.
1391 * Wine tests: Every combination that passes the initial checks should pass.
1392 * . Different formats => conversion driver and format dependent.
1393 * . 1 level, but size not matching => copy is done (and even crash if src bigger
1394 * than dst. For the case where dst bigger, wine doesn't test if a stretch is applied
1395 * or if a subrect is copied).
1396 * . 8x8 4 sublevels -> 7x7 2 sublevels => driver dependent, On NV seems to be 4x4 subrect
1399 * From these, the proposal is:
1400 * . Different formats -> use util_format_translate to translate if possible for surfaces.
1401 * Accept ARGB/XRGB for Volumes. Do nothing for the other combinations
1402 * . First level copied -> the first level such that src is smaller or equal to dst first level
1403 * . number of levels copied -> as long as it fits and textures have levels
1404 * That should satisfy the constraints (and instead of crashing for some cases we return D3D_OK)
1407 last_src_level
= (srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ? 0 : srcb
->base
.info
.last_level
;
1408 last_dst_level
= (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ? 0 : dstb
->base
.info
.last_level
;
1410 for (m
= 0; m
<= last_src_level
; ++m
) {
1411 unsigned w
= u_minify(srcb
->base
.info
.width0
, m
);
1412 unsigned h
= u_minify(srcb
->base
.info
.height0
, m
);
1413 unsigned d
= u_minify(srcb
->base
.info
.depth0
, m
);
1415 if (w
<= dstb
->base
.info
.width0
&&
1416 h
<= dstb
->base
.info
.height0
&&
1417 d
<= dstb
->base
.info
.depth0
)
1420 user_assert(m
<= last_src_level
, D3D_OK
);
1422 last_dst_level
= MIN2(srcb
->base
.info
.last_level
- m
, last_dst_level
);
1424 if (dstb
->base
.type
== D3DRTYPE_TEXTURE
) {
1425 struct NineTexture9
*dst
= NineTexture9(dstb
);
1426 struct NineTexture9
*src
= NineTexture9(srcb
);
1428 if (src
->dirty_rect
.width
== 0)
1431 pipe_box_to_rect(&rect
, &src
->dirty_rect
);
1432 for (l
= 0; l
< m
; ++l
)
1433 rect_minify_inclusive(&rect
);
1435 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
) {
1436 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1438 dst
->surfaces
[l
]->desc
.Width
,
1439 dst
->surfaces
[l
]->desc
.Height
);
1440 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
],
1444 rect_minify_inclusive(&rect
);
1446 u_box_origin_2d(0, 0, &src
->dirty_rect
);
1448 if (dstb
->base
.type
== D3DRTYPE_CUBETEXTURE
) {
1449 struct NineCubeTexture9
*dst
= NineCubeTexture9(dstb
);
1450 struct NineCubeTexture9
*src
= NineCubeTexture9(srcb
);
1453 /* GPUs usually have them stored as arrays of mip-mapped 2D textures. */
1454 for (z
= 0; z
< 6; ++z
) {
1455 if (src
->dirty_rect
[z
].width
== 0)
1458 pipe_box_to_rect(&rect
, &src
->dirty_rect
[z
]);
1459 for (l
= 0; l
< m
; ++l
)
1460 rect_minify_inclusive(&rect
);
1462 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
) {
1463 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1465 dst
->surfaces
[l
* 6 + z
]->desc
.Width
,
1466 dst
->surfaces
[l
* 6 + z
]->desc
.Height
);
1467 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
* 6 + z
],
1468 src
->surfaces
[m
* 6 + z
],
1471 rect_minify_inclusive(&rect
);
1473 u_box_origin_2d(0, 0, &src
->dirty_rect
[z
]);
1477 if (dstb
->base
.type
== D3DRTYPE_VOLUMETEXTURE
) {
1478 struct NineVolumeTexture9
*dst
= NineVolumeTexture9(dstb
);
1479 struct NineVolumeTexture9
*src
= NineVolumeTexture9(srcb
);
1481 if (src
->dirty_box
.width
== 0)
1483 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
)
1484 NineVolume9_CopyMemToDefault(dst
->volumes
[l
],
1485 src
->volumes
[m
], 0, 0, 0, NULL
);
1486 u_box_3d(0, 0, 0, 0, 0, 0, &src
->dirty_box
);
1488 assert(!"invalid texture type");
1491 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1492 dstb
->dirty_mip
= TRUE
;
1493 NineBaseTexture9_GenerateMipSubLevels(dstb
);
1500 NineDevice9_GetRenderTargetData( struct NineDevice9
*This
,
1501 IDirect3DSurface9
*pRenderTarget
,
1502 IDirect3DSurface9
*pDestSurface
)
1504 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1505 struct NineSurface9
*src
= NineSurface9(pRenderTarget
);
1507 DBG("This=%p pRenderTarget=%p pDestSurface=%p\n",
1508 This
, pRenderTarget
, pDestSurface
);
1510 user_assert(pRenderTarget
&& pDestSurface
, D3DERR_INVALIDCALL
);
1512 user_assert(dst
->desc
.Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1513 user_assert(src
->desc
.Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1515 user_assert(dst
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1516 user_assert(src
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1518 user_assert(src
->desc
.Width
== dst
->desc
.Width
, D3DERR_INVALIDCALL
);
1519 user_assert(src
->desc
.Height
== dst
->desc
.Height
, D3DERR_INVALIDCALL
);
1521 user_assert(src
->desc
.Format
!= D3DFMT_NULL
, D3DERR_INVALIDCALL
);
1523 NineSurface9_CopyDefaultToMem(dst
, src
);
1529 NineDevice9_GetFrontBufferData( struct NineDevice9
*This
,
1531 IDirect3DSurface9
*pDestSurface
)
1533 DBG("This=%p iSwapChain=%u pDestSurface=%p\n", This
,
1534 iSwapChain
, pDestSurface
);
1536 user_assert(pDestSurface
!= NULL
, D3DERR_INVALIDCALL
);
1537 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
1539 return NineSwapChain9_GetFrontBufferData(This
->swapchains
[iSwapChain
],
1544 NineDevice9_StretchRect( struct NineDevice9
*This
,
1545 IDirect3DSurface9
*pSourceSurface
,
1546 const RECT
*pSourceRect
,
1547 IDirect3DSurface9
*pDestSurface
,
1548 const RECT
*pDestRect
,
1549 D3DTEXTUREFILTERTYPE Filter
)
1551 struct pipe_screen
*screen
= This
->screen
;
1552 struct pipe_context
*pipe
;
1553 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1554 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1555 struct pipe_resource
*dst_res
= NineSurface9_GetResource(dst
);
1556 struct pipe_resource
*src_res
= NineSurface9_GetResource(src
);
1558 struct pipe_blit_info blit
;
1559 boolean scaled
, clamped
, ms
, flip_x
= FALSE
, flip_y
= FALSE
;
1561 DBG("This=%p pSourceSurface=%p pSourceRect=%p pDestSurface=%p "
1562 "pDestRect=%p Filter=%u\n",
1563 This
, pSourceSurface
, pSourceRect
, pDestSurface
, pDestRect
, Filter
);
1565 DBG("pSourceRect=(%u,%u)-(%u,%u)\n",
1566 pSourceRect
->left
, pSourceRect
->top
,
1567 pSourceRect
->right
, pSourceRect
->bottom
);
1569 DBG("pDestRect=(%u,%u)-(%u,%u)\n", pDestRect
->left
, pDestRect
->top
,
1570 pDestRect
->right
, pDestRect
->bottom
);
1572 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
&&
1573 src
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1574 zs
= util_format_is_depth_or_stencil(dst_res
->format
);
1575 user_assert(!zs
|| !This
->in_scene
, D3DERR_INVALIDCALL
);
1576 user_assert(!zs
|| !pSourceRect
||
1577 (pSourceRect
->left
== 0 &&
1578 pSourceRect
->top
== 0 &&
1579 pSourceRect
->right
== src
->desc
.Width
&&
1580 pSourceRect
->bottom
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1581 user_assert(!zs
|| !pDestRect
||
1582 (pDestRect
->left
== 0 &&
1583 pDestRect
->top
== 0 &&
1584 pDestRect
->right
== dst
->desc
.Width
&&
1585 pDestRect
->bottom
== dst
->desc
.Height
), D3DERR_INVALIDCALL
);
1587 (dst
->desc
.Width
== src
->desc
.Width
&&
1588 dst
->desc
.Height
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1589 user_assert(zs
|| !util_format_is_depth_or_stencil(src_res
->format
),
1590 D3DERR_INVALIDCALL
);
1591 user_assert(!zs
|| dst
->desc
.Format
== src
->desc
.Format
,
1592 D3DERR_INVALIDCALL
);
1593 user_assert(screen
->is_format_supported(screen
, src_res
->format
,
1595 src_res
->nr_samples
,
1596 PIPE_BIND_SAMPLER_VIEW
),
1597 D3DERR_INVALIDCALL
);
1599 /* We might want to permit these, but wine thinks we shouldn't. */
1600 user_assert(!pDestRect
||
1601 (pDestRect
->left
<= pDestRect
->right
&&
1602 pDestRect
->top
<= pDestRect
->bottom
), D3DERR_INVALIDCALL
);
1603 user_assert(!pSourceRect
||
1604 (pSourceRect
->left
<= pSourceRect
->right
&&
1605 pSourceRect
->top
<= pSourceRect
->bottom
), D3DERR_INVALIDCALL
);
1607 memset(&blit
, 0, sizeof(blit
));
1608 blit
.dst
.resource
= dst_res
;
1609 blit
.dst
.level
= dst
->level
;
1610 blit
.dst
.box
.z
= dst
->layer
;
1611 blit
.dst
.box
.depth
= 1;
1612 blit
.dst
.format
= dst_res
->format
;
1614 flip_x
= pDestRect
->left
> pDestRect
->right
;
1616 blit
.dst
.box
.x
= pDestRect
->right
;
1617 blit
.dst
.box
.width
= pDestRect
->left
- pDestRect
->right
;
1619 blit
.dst
.box
.x
= pDestRect
->left
;
1620 blit
.dst
.box
.width
= pDestRect
->right
- pDestRect
->left
;
1622 flip_y
= pDestRect
->top
> pDestRect
->bottom
;
1624 blit
.dst
.box
.y
= pDestRect
->bottom
;
1625 blit
.dst
.box
.height
= pDestRect
->top
- pDestRect
->bottom
;
1627 blit
.dst
.box
.y
= pDestRect
->top
;
1628 blit
.dst
.box
.height
= pDestRect
->bottom
- pDestRect
->top
;
1633 blit
.dst
.box
.width
= dst
->desc
.Width
;
1634 blit
.dst
.box
.height
= dst
->desc
.Height
;
1636 blit
.src
.resource
= src_res
;
1637 blit
.src
.level
= src
->level
;
1638 blit
.src
.box
.z
= src
->layer
;
1639 blit
.src
.box
.depth
= 1;
1640 blit
.src
.format
= src_res
->format
;
1642 if (flip_x
^ (pSourceRect
->left
> pSourceRect
->right
)) {
1643 blit
.src
.box
.x
= pSourceRect
->right
;
1644 blit
.src
.box
.width
= pSourceRect
->left
- pSourceRect
->right
;
1646 blit
.src
.box
.x
= pSourceRect
->left
;
1647 blit
.src
.box
.width
= pSourceRect
->right
- pSourceRect
->left
;
1649 if (flip_y
^ (pSourceRect
->top
> pSourceRect
->bottom
)) {
1650 blit
.src
.box
.y
= pSourceRect
->bottom
;
1651 blit
.src
.box
.height
= pSourceRect
->top
- pSourceRect
->bottom
;
1653 blit
.src
.box
.y
= pSourceRect
->top
;
1654 blit
.src
.box
.height
= pSourceRect
->bottom
- pSourceRect
->top
;
1657 blit
.src
.box
.x
= flip_x
? src
->desc
.Width
: 0;
1658 blit
.src
.box
.y
= flip_y
? src
->desc
.Height
: 0;
1659 blit
.src
.box
.width
= flip_x
? -src
->desc
.Width
: src
->desc
.Width
;
1660 blit
.src
.box
.height
= flip_y
? -src
->desc
.Height
: src
->desc
.Height
;
1662 blit
.mask
= zs
? PIPE_MASK_ZS
: PIPE_MASK_RGBA
;
1663 blit
.filter
= Filter
== D3DTEXF_LINEAR
?
1664 PIPE_TEX_FILTER_LINEAR
: PIPE_TEX_FILTER_NEAREST
;
1665 blit
.scissor_enable
= FALSE
;
1666 blit
.alpha_blend
= FALSE
;
1668 /* If both of a src and dst dimension are negative, flip them. */
1669 if (blit
.dst
.box
.width
< 0 && blit
.src
.box
.width
< 0) {
1670 blit
.dst
.box
.width
= -blit
.dst
.box
.width
;
1671 blit
.src
.box
.width
= -blit
.src
.box
.width
;
1673 if (blit
.dst
.box
.height
< 0 && blit
.src
.box
.height
< 0) {
1674 blit
.dst
.box
.height
= -blit
.dst
.box
.height
;
1675 blit
.src
.box
.height
= -blit
.src
.box
.height
;
1678 blit
.dst
.box
.width
!= blit
.src
.box
.width
||
1679 blit
.dst
.box
.height
!= blit
.src
.box
.height
;
1681 user_assert(!scaled
|| dst
!= src
, D3DERR_INVALIDCALL
);
1682 user_assert(!scaled
||
1683 !NineSurface9_IsOffscreenPlain(dst
), D3DERR_INVALIDCALL
);
1684 user_assert(!NineSurface9_IsOffscreenPlain(dst
) ||
1685 NineSurface9_IsOffscreenPlain(src
), D3DERR_INVALIDCALL
);
1686 user_assert(NineSurface9_IsOffscreenPlain(dst
) ||
1687 dst
->desc
.Usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
),
1688 D3DERR_INVALIDCALL
);
1689 user_assert(!scaled
||
1690 (!util_format_is_compressed(dst
->base
.info
.format
) &&
1691 !util_format_is_compressed(src
->base
.info
.format
)),
1692 D3DERR_INVALIDCALL
);
1694 user_warn(src
== dst
&&
1695 u_box_test_intersection_2d(&blit
.src
.box
, &blit
.dst
.box
));
1697 /* Check for clipping/clamping: */
1699 struct pipe_box box
;
1702 xy
= u_box_clip_2d(&box
, &blit
.dst
.box
,
1703 dst
->desc
.Width
, dst
->desc
.Height
);
1707 xy
= u_box_clip_2d(&box
, &blit
.src
.box
,
1708 src
->desc
.Width
, src
->desc
.Height
);
1712 ms
= (dst
->desc
.MultiSampleType
!= src
->desc
.MultiSampleType
) ||
1713 (dst
->desc
.MultiSampleQuality
!= src
->desc
.MultiSampleQuality
);
1715 if (clamped
|| scaled
|| (blit
.dst
.format
!= blit
.src
.format
) || ms
) {
1716 DBG("using pipe->blit()\n");
1717 /* TODO: software scaling */
1718 user_assert(screen
->is_format_supported(screen
, dst_res
->format
,
1720 dst_res
->nr_samples
,
1721 zs
? PIPE_BIND_DEPTH_STENCIL
:
1722 PIPE_BIND_RENDER_TARGET
),
1723 D3DERR_INVALIDCALL
);
1725 nine_context_blit(This
, &blit
);
1727 assert(blit
.dst
.box
.x
>= 0 && blit
.dst
.box
.y
>= 0 &&
1728 blit
.src
.box
.x
>= 0 && blit
.src
.box
.y
>= 0 &&
1729 blit
.dst
.box
.x
+ blit
.dst
.box
.width
<= dst
->desc
.Width
&&
1730 blit
.src
.box
.x
+ blit
.src
.box
.width
<= src
->desc
.Width
&&
1731 blit
.dst
.box
.y
+ blit
.dst
.box
.height
<= dst
->desc
.Height
&&
1732 blit
.src
.box
.y
+ blit
.src
.box
.height
<= src
->desc
.Height
);
1733 /* Or drivers might crash ... */
1734 DBG("Using resource_copy_region.\n");
1735 pipe
= NineDevice9_GetPipe(This
);
1736 pipe
->resource_copy_region(pipe
,
1737 blit
.dst
.resource
, blit
.dst
.level
,
1738 blit
.dst
.box
.x
, blit
.dst
.box
.y
, blit
.dst
.box
.z
,
1739 blit
.src
.resource
, blit
.src
.level
,
1743 /* Communicate the container it needs to update sublevels - if apply */
1744 NineSurface9_MarkContainerDirty(dst
);
1750 NineDevice9_ColorFill( struct NineDevice9
*This
,
1751 IDirect3DSurface9
*pSurface
,
1755 struct pipe_context
*pipe
= NineDevice9_GetPipe(This
);
1756 struct NineSurface9
*surf
= NineSurface9(pSurface
);
1757 struct pipe_surface
*psurf
;
1758 unsigned x
, y
, w
, h
;
1759 union pipe_color_union rgba
;
1762 DBG("This=%p pSurface=%p pRect=%p color=%08x\n", This
,
1763 pSurface
, pRect
, color
);
1765 DBG("pRect=(%u,%u)-(%u,%u)\n", pRect
->left
, pRect
->top
,
1766 pRect
->right
, pRect
->bottom
);
1768 user_assert(surf
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1770 user_assert((surf
->base
.usage
& D3DUSAGE_RENDERTARGET
) ||
1771 NineSurface9_IsOffscreenPlain(surf
), D3DERR_INVALIDCALL
);
1773 user_assert(surf
->desc
.Format
!= D3DFMT_NULL
, D3D_OK
);
1778 w
= pRect
->right
- pRect
->left
;
1779 h
= pRect
->bottom
- pRect
->top
;
1781 if (compressed_format(surf
->desc
.Format
)) {
1782 const unsigned bw
= util_format_get_blockwidth(surf
->base
.info
.format
);
1783 const unsigned bh
= util_format_get_blockheight(surf
->base
.info
.format
);
1785 user_assert(!(x
% bw
) && !(y
% bh
) && !(w
% bw
) && !(h
% bh
),
1786 D3DERR_INVALIDCALL
);
1791 w
= surf
->desc
.Width
;
1792 h
= surf
->desc
.Height
;
1794 d3dcolor_to_pipe_color_union(&rgba
, color
);
1796 fallback
= !(surf
->base
.info
.bind
& PIPE_BIND_RENDER_TARGET
);
1799 psurf
= NineSurface9_GetSurface(surf
, 0);
1805 pipe
->clear_render_target(pipe
, psurf
, &rgba
, x
, y
, w
, h
, false);
1807 D3DLOCKED_RECT lock
;
1808 union util_color uc
;
1810 /* XXX: lock pRect and fix util_fill_rect */
1811 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, 0);
1814 util_pack_color_ub(color
>> 16, color
>> 8, color
>> 0, color
>> 24,
1815 surf
->base
.info
.format
, &uc
);
1816 util_fill_rect(lock
.pBits
, surf
->base
.info
.format
,lock
.Pitch
,
1818 NineSurface9_UnlockRect(surf
);
1825 NineDevice9_CreateOffscreenPlainSurface( struct NineDevice9
*This
,
1830 IDirect3DSurface9
**ppSurface
,
1831 HANDLE
*pSharedHandle
)
1835 DBG("This=%p Width=%u Height=%u Format=%s(0x%x) Pool=%u "
1836 "ppSurface=%p pSharedHandle=%p\n", This
,
1837 Width
, Height
, d3dformat_to_string(Format
), Format
, Pool
,
1838 ppSurface
, pSharedHandle
);
1841 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
1842 || Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1843 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1845 /* Can be used with StretchRect and ColorFill. It's also always lockable.
1847 hr
= create_zs_or_rt_surface(This
, 2, Pool
, Width
, Height
,
1849 D3DMULTISAMPLE_NONE
, 0,
1851 ppSurface
, pSharedHandle
);
1853 DBG("Failed to create surface.\n");
1858 NineDevice9_SetRenderTarget( struct NineDevice9
*This
,
1859 DWORD RenderTargetIndex
,
1860 IDirect3DSurface9
*pRenderTarget
)
1862 struct NineSurface9
*rt
= NineSurface9(pRenderTarget
);
1863 const unsigned i
= RenderTargetIndex
;
1865 DBG("This=%p RenderTargetIndex=%u pRenderTarget=%p\n", This
,
1866 RenderTargetIndex
, pRenderTarget
);
1868 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1869 user_assert(i
!= 0 || pRenderTarget
, D3DERR_INVALIDCALL
);
1870 user_assert(!pRenderTarget
||
1871 rt
->desc
.Usage
& D3DUSAGE_RENDERTARGET
, D3DERR_INVALIDCALL
);
1874 This
->state
.viewport
.X
= 0;
1875 This
->state
.viewport
.Y
= 0;
1876 This
->state
.viewport
.Width
= rt
->desc
.Width
;
1877 This
->state
.viewport
.Height
= rt
->desc
.Height
;
1878 This
->state
.viewport
.MinZ
= 0.0f
;
1879 This
->state
.viewport
.MaxZ
= 1.0f
;
1881 This
->state
.scissor
.minx
= 0;
1882 This
->state
.scissor
.miny
= 0;
1883 This
->state
.scissor
.maxx
= rt
->desc
.Width
;
1884 This
->state
.scissor
.maxy
= rt
->desc
.Height
;
1887 if (This
->state
.rt
[i
] != NineSurface9(pRenderTarget
))
1888 nine_bind(&This
->state
.rt
[i
], pRenderTarget
);
1890 nine_context_set_render_target(This
, i
, rt
);
1895 NineDevice9_GetRenderTarget( struct NineDevice9
*This
,
1896 DWORD RenderTargetIndex
,
1897 IDirect3DSurface9
**ppRenderTarget
)
1899 const unsigned i
= RenderTargetIndex
;
1901 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1902 user_assert(ppRenderTarget
, D3DERR_INVALIDCALL
);
1904 *ppRenderTarget
= (IDirect3DSurface9
*)This
->state
.rt
[i
];
1905 if (!This
->state
.rt
[i
])
1906 return D3DERR_NOTFOUND
;
1908 NineUnknown_AddRef(NineUnknown(This
->state
.rt
[i
]));
1913 NineDevice9_SetDepthStencilSurface( struct NineDevice9
*This
,
1914 IDirect3DSurface9
*pNewZStencil
)
1916 struct NineSurface9
*ds
= NineSurface9(pNewZStencil
);
1917 DBG("This=%p pNewZStencil=%p\n", This
, pNewZStencil
);
1919 if (This
->state
.ds
!= ds
) {
1920 nine_bind(&This
->state
.ds
, ds
);
1921 nine_context_set_depth_stencil(This
, ds
);
1927 NineDevice9_GetDepthStencilSurface( struct NineDevice9
*This
,
1928 IDirect3DSurface9
**ppZStencilSurface
)
1930 user_assert(ppZStencilSurface
, D3DERR_INVALIDCALL
);
1932 *ppZStencilSurface
= (IDirect3DSurface9
*)This
->state
.ds
;
1933 if (!This
->state
.ds
)
1934 return D3DERR_NOTFOUND
;
1936 NineUnknown_AddRef(NineUnknown(This
->state
.ds
));
1941 NineDevice9_BeginScene( struct NineDevice9
*This
)
1943 DBG("This=%p\n", This
);
1944 user_assert(!This
->in_scene
, D3DERR_INVALIDCALL
);
1945 This
->in_scene
= TRUE
;
1946 /* Do we want to do anything else here ? */
1951 NineDevice9_EndScene( struct NineDevice9
*This
)
1953 DBG("This=%p\n", This
);
1954 user_assert(This
->in_scene
, D3DERR_INVALIDCALL
);
1955 This
->in_scene
= FALSE
;
1960 NineDevice9_Clear( struct NineDevice9
*This
,
1962 const D3DRECT
*pRects
,
1968 struct NineSurface9
*zsbuf_surf
= This
->state
.ds
;
1970 DBG("This=%p Count=%u pRects=%p Flags=%x Color=%08x Z=%f Stencil=%x\n",
1971 This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1973 user_assert(This
->state
.ds
|| !(Flags
& NINED3DCLEAR_DEPTHSTENCIL
),
1974 D3DERR_INVALIDCALL
);
1975 user_assert(!(Flags
& D3DCLEAR_STENCIL
) ||
1977 util_format_is_depth_and_stencil(zsbuf_surf
->base
.info
.format
)),
1978 D3DERR_INVALIDCALL
);
1980 user_assert((Count
&& pRects
) || (!Count
&& !pRects
), D3DERR_INVALIDCALL
);
1982 user_warn((pRects
&& !Count
) || (!pRects
&& Count
));
1983 if (pRects
&& !Count
)
1989 nine_context_clear_fb(This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1994 NineDevice9_SetTransform( struct NineDevice9
*This
,
1995 D3DTRANSFORMSTATETYPE State
,
1996 const D3DMATRIX
*pMatrix
)
1998 struct nine_state
*state
= This
->update
;
1999 D3DMATRIX
*M
= nine_state_access_transform(&state
->ff
, State
, TRUE
);
2001 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2003 user_assert(M
, D3DERR_INVALIDCALL
);
2006 if (unlikely(This
->is_recording
)) {
2007 state
->ff
.changed
.transform
[State
/ 32] |= 1 << (State
% 32);
2008 state
->changed
.group
|= NINE_STATE_FF
;
2010 nine_context_set_transform(This
, State
, pMatrix
);
2016 NineDevice9_GetTransform( struct NineDevice9
*This
,
2017 D3DTRANSFORMSTATETYPE State
,
2018 D3DMATRIX
*pMatrix
)
2020 D3DMATRIX
*M
= nine_state_access_transform(&This
->state
.ff
, State
, FALSE
);
2021 user_assert(M
, D3DERR_INVALIDCALL
);
2027 NineDevice9_MultiplyTransform( struct NineDevice9
*This
,
2028 D3DTRANSFORMSTATETYPE State
,
2029 const D3DMATRIX
*pMatrix
)
2031 struct nine_state
*state
= This
->update
;
2033 D3DMATRIX
*M
= nine_state_access_transform(&state
->ff
, State
, TRUE
);
2035 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2037 user_assert(M
, D3DERR_INVALIDCALL
);
2039 nine_d3d_matrix_matrix_mul(&T
, pMatrix
, M
);
2040 return NineDevice9_SetTransform(This
, State
, &T
);
2044 NineDevice9_SetViewport( struct NineDevice9
*This
,
2045 const D3DVIEWPORT9
*pViewport
)
2047 struct nine_state
*state
= This
->update
;
2049 DBG("X=%u Y=%u W=%u H=%u MinZ=%f MaxZ=%f\n",
2050 pViewport
->X
, pViewport
->Y
, pViewport
->Width
, pViewport
->Height
,
2051 pViewport
->MinZ
, pViewport
->MaxZ
);
2053 state
->viewport
= *pViewport
;
2054 nine_context_set_viewport(This
, pViewport
);
2060 NineDevice9_GetViewport( struct NineDevice9
*This
,
2061 D3DVIEWPORT9
*pViewport
)
2063 *pViewport
= This
->state
.viewport
;
2068 NineDevice9_SetMaterial( struct NineDevice9
*This
,
2069 const D3DMATERIAL9
*pMaterial
)
2071 struct nine_state
*state
= This
->update
;
2073 DBG("This=%p pMaterial=%p\n", This
, pMaterial
);
2075 nine_dump_D3DMATERIAL9(DBG_FF
, pMaterial
);
2077 user_assert(pMaterial
, E_POINTER
);
2079 state
->ff
.material
= *pMaterial
;
2080 if (unlikely(This
->is_recording
))
2081 state
->changed
.group
|= NINE_STATE_FF_MATERIAL
;
2083 nine_context_set_material(This
, pMaterial
);
2089 NineDevice9_GetMaterial( struct NineDevice9
*This
,
2090 D3DMATERIAL9
*pMaterial
)
2092 user_assert(pMaterial
, E_POINTER
);
2093 *pMaterial
= This
->state
.ff
.material
;
2098 NineDevice9_SetLight( struct NineDevice9
*This
,
2100 const D3DLIGHT9
*pLight
)
2102 struct nine_state
*state
= This
->update
;
2105 DBG("This=%p Index=%u pLight=%p\n", This
, Index
, pLight
);
2107 nine_dump_D3DLIGHT9(DBG_FF
, pLight
);
2109 user_assert(pLight
, D3DERR_INVALIDCALL
);
2110 user_assert(pLight
->Type
< NINED3DLIGHT_INVALID
, D3DERR_INVALIDCALL
);
2112 user_assert(Index
< NINE_MAX_LIGHTS
, D3DERR_INVALIDCALL
); /* sanity */
2114 hr
= nine_state_set_light(&state
->ff
, Index
, pLight
);
2118 if (pLight
->Type
!= D3DLIGHT_DIRECTIONAL
&&
2119 pLight
->Attenuation0
== 0.0f
&&
2120 pLight
->Attenuation1
== 0.0f
&&
2121 pLight
->Attenuation2
== 0.0f
) {
2122 DBG("Warning: all D3DLIGHT9.Attenuation[i] are 0\n");
2125 if (unlikely(This
->is_recording
))
2126 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2128 nine_context_set_light(This
, Index
, pLight
);
2134 NineDevice9_GetLight( struct NineDevice9
*This
,
2138 const struct nine_state
*state
= &This
->state
;
2140 user_assert(pLight
, D3DERR_INVALIDCALL
);
2141 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2142 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2143 D3DERR_INVALIDCALL
);
2145 *pLight
= state
->ff
.light
[Index
];
2151 NineDevice9_LightEnable( struct NineDevice9
*This
,
2155 struct nine_state
*state
= This
->update
;
2157 DBG("This=%p Index=%u Enable=%i\n", This
, Index
, Enable
);
2159 if (Index
>= state
->ff
.num_lights
||
2160 state
->ff
.light
[Index
].Type
== NINED3DLIGHT_INVALID
) {
2161 /* This should create a default light. */
2163 memset(&light
, 0, sizeof(light
));
2164 light
.Type
= D3DLIGHT_DIRECTIONAL
;
2165 light
.Diffuse
.r
= 1.0f
;
2166 light
.Diffuse
.g
= 1.0f
;
2167 light
.Diffuse
.b
= 1.0f
;
2168 light
.Direction
.z
= 1.0f
;
2169 NineDevice9_SetLight(This
, Index
, &light
);
2172 nine_state_light_enable(&state
->ff
, &state
->changed
.group
, Index
, Enable
);
2173 if (likely(!This
->is_recording
))
2174 nine_context_light_enable(This
, Index
, Enable
);
2180 NineDevice9_GetLightEnable( struct NineDevice9
*This
,
2184 const struct nine_state
*state
= &This
->state
;
2187 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2188 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2189 D3DERR_INVALIDCALL
);
2191 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
)
2192 if (state
->ff
.active_light
[i
] == Index
)
2195 *pEnable
= i
!= state
->ff
.num_lights_active
? 128 : 0; // Taken from wine
2201 NineDevice9_SetClipPlane( struct NineDevice9
*This
,
2203 const float *pPlane
)
2205 struct nine_state
*state
= This
->update
;
2207 user_assert(pPlane
, D3DERR_INVALIDCALL
);
2209 DBG("This=%p Index=%u pPlane=%f %f %f %f\n", This
, Index
,
2210 pPlane
[0], pPlane
[1],
2211 pPlane
[2], pPlane
[3]);
2213 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2215 memcpy(&state
->clip
.ucp
[Index
][0], pPlane
, sizeof(state
->clip
.ucp
[0]));
2216 if (unlikely(This
->is_recording
))
2217 state
->changed
.ucp
|= 1 << Index
;
2219 nine_context_set_clip_plane(This
, Index
, (struct nine_clipplane
*)pPlane
);
2225 NineDevice9_GetClipPlane( struct NineDevice9
*This
,
2229 const struct nine_state
*state
= &This
->state
;
2231 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2233 memcpy(pPlane
, &state
->clip
.ucp
[Index
][0], sizeof(state
->clip
.ucp
[0]));
2238 NineDevice9_SetRenderState( struct NineDevice9
*This
,
2239 D3DRENDERSTATETYPE State
,
2242 struct nine_state
*state
= This
->update
;
2244 DBG("This=%p State=%u(%s) Value=%08x\n", This
,
2245 State
, nine_d3drs_to_string(State
), Value
);
2247 user_assert(State
< D3DRS_COUNT
, D3DERR_INVALIDCALL
);
2249 if (unlikely(This
->is_recording
)) {
2250 state
->rs_advertised
[State
] = Value
;
2251 /* only need to record changed render states for stateblocks */
2252 state
->changed
.rs
[State
/ 32] |= 1 << (State
% 32);
2253 state
->changed
.group
|= nine_render_state_group
[State
];
2257 if (state
->rs_advertised
[State
] == Value
)
2260 state
->rs_advertised
[State
] = Value
;
2261 nine_context_set_render_state(This
, State
, Value
);
2267 NineDevice9_GetRenderState( struct NineDevice9
*This
,
2268 D3DRENDERSTATETYPE State
,
2271 user_assert(State
< D3DRS_COUNT
, D3DERR_INVALIDCALL
);
2273 *pValue
= This
->state
.rs_advertised
[State
];
2278 NineDevice9_CreateStateBlock( struct NineDevice9
*This
,
2279 D3DSTATEBLOCKTYPE Type
,
2280 IDirect3DStateBlock9
**ppSB
)
2282 struct NineStateBlock9
*nsb
;
2283 struct nine_state
*dst
;
2285 enum nine_stateblock_type type
;
2288 DBG("This=%p Type=%u ppSB=%p\n", This
, Type
, ppSB
);
2290 user_assert(Type
== D3DSBT_ALL
||
2291 Type
== D3DSBT_VERTEXSTATE
||
2292 Type
== D3DSBT_PIXELSTATE
, D3DERR_INVALIDCALL
);
2295 case D3DSBT_VERTEXSTATE
: type
= NINESBT_VERTEXSTATE
; break;
2296 case D3DSBT_PIXELSTATE
: type
= NINESBT_PIXELSTATE
; break;
2302 hr
= NineStateBlock9_new(This
, &nsb
, type
);
2305 *ppSB
= (IDirect3DStateBlock9
*)nsb
;
2308 dst
->changed
.group
=
2309 NINE_STATE_TEXTURE
|
2312 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_VERTEXSTATE
) {
2313 dst
->changed
.group
|=
2314 NINE_STATE_FF_LIGHTING
|
2315 NINE_STATE_VS
| NINE_STATE_VS_CONST
|
2317 /* TODO: texture/sampler state */
2318 memcpy(dst
->changed
.rs
,
2319 nine_render_states_vertex
, sizeof(dst
->changed
.rs
));
2320 nine_ranges_insert(&dst
->changed
.vs_const_f
, 0, This
->may_swvp
? NINE_MAX_CONST_F_SWVP
: This
->max_vs_const_f
,
2322 nine_ranges_insert(&dst
->changed
.vs_const_i
, 0, This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
,
2324 nine_ranges_insert(&dst
->changed
.vs_const_b
, 0, This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
,
2326 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2327 dst
->changed
.sampler
[s
] |= 1 << D3DSAMP_DMAPOFFSET
;
2328 if (This
->state
.ff
.num_lights
) {
2329 dst
->ff
.num_lights
= This
->state
.ff
.num_lights
;
2330 /* zero'd -> light type won't be NINED3DLIGHT_INVALID, so
2331 * all currently existing lights will be captured
2333 dst
->ff
.light
= CALLOC(This
->state
.ff
.num_lights
,
2335 if (!dst
->ff
.light
) {
2336 nine_bind(ppSB
, NULL
);
2337 return E_OUTOFMEMORY
;
2341 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_PIXELSTATE
) {
2342 dst
->changed
.group
|=
2343 NINE_STATE_PS
| NINE_STATE_PS_CONST
| NINE_STATE_BLEND
|
2344 NINE_STATE_FF_OTHER
| NINE_STATE_FF_PSSTAGES
| NINE_STATE_PS_CONST
|
2345 NINE_STATE_FB
| NINE_STATE_DSA
| NINE_STATE_MULTISAMPLE
|
2346 NINE_STATE_RASTERIZER
| NINE_STATE_STENCIL_REF
;
2347 memcpy(dst
->changed
.rs
,
2348 nine_render_states_pixel
, sizeof(dst
->changed
.rs
));
2349 nine_ranges_insert(&dst
->changed
.ps_const_f
, 0, This
->max_ps_const_f
,
2351 dst
->changed
.ps_const_i
= 0xffff;
2352 dst
->changed
.ps_const_b
= 0xffff;
2353 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2354 dst
->changed
.sampler
[s
] |= 0x1ffe;
2355 for (s
= 0; s
< NINE_MAX_TEXTURE_STAGES
; ++s
) {
2356 dst
->ff
.changed
.tex_stage
[s
][0] |= 0xffffffff;
2357 dst
->ff
.changed
.tex_stage
[s
][1] |= 0xffffffff;
2360 if (Type
== D3DSBT_ALL
) {
2361 dst
->changed
.group
|=
2362 NINE_STATE_VIEWPORT
|
2363 NINE_STATE_SCISSOR
|
2364 NINE_STATE_RASTERIZER
|
2368 NINE_STATE_MATERIAL
|
2369 NINE_STATE_BLEND_COLOR
|
2370 NINE_STATE_SAMPLE_MASK
;
2371 memset(dst
->changed
.rs
, ~0, (D3DRS_COUNT
/ 32) * sizeof(uint32_t));
2372 dst
->changed
.rs
[D3DRS_LAST
/ 32] |= (1 << (D3DRS_COUNT
% 32)) - 1;
2373 dst
->changed
.vtxbuf
= (1ULL << This
->caps
.MaxStreams
) - 1;
2374 dst
->changed
.stream_freq
= dst
->changed
.vtxbuf
;
2375 dst
->changed
.ucp
= (1 << PIPE_MAX_CLIP_PLANES
) - 1;
2376 dst
->changed
.texture
= (1 << NINE_MAX_SAMPLERS
) - 1;
2378 NineStateBlock9_Capture(NineStateBlock9(*ppSB
));
2380 /* TODO: fixed function state */
2386 NineDevice9_BeginStateBlock( struct NineDevice9
*This
)
2390 DBG("This=%p\n", This
);
2392 user_assert(!This
->record
, D3DERR_INVALIDCALL
);
2394 hr
= NineStateBlock9_new(This
, &This
->record
, NINESBT_CUSTOM
);
2397 NineUnknown_ConvertRefToBind(NineUnknown(This
->record
));
2399 This
->update
= &This
->record
->state
;
2400 This
->is_recording
= TRUE
;
2406 NineDevice9_EndStateBlock( struct NineDevice9
*This
,
2407 IDirect3DStateBlock9
**ppSB
)
2409 DBG("This=%p ppSB=%p\n", This
, ppSB
);
2411 user_assert(This
->record
, D3DERR_INVALIDCALL
);
2413 This
->update
= &This
->state
;
2414 This
->is_recording
= FALSE
;
2416 NineUnknown_AddRef(NineUnknown(This
->record
));
2417 *ppSB
= (IDirect3DStateBlock9
*)This
->record
;
2418 NineUnknown_Unbind(NineUnknown(This
->record
));
2419 This
->record
= NULL
;
2425 NineDevice9_SetClipStatus( struct NineDevice9
*This
,
2426 const D3DCLIPSTATUS9
*pClipStatus
)
2428 STUB(D3DERR_INVALIDCALL
);
2432 NineDevice9_GetClipStatus( struct NineDevice9
*This
,
2433 D3DCLIPSTATUS9
*pClipStatus
)
2435 STUB(D3DERR_INVALIDCALL
);
2439 NineDevice9_GetTexture( struct NineDevice9
*This
,
2441 IDirect3DBaseTexture9
**ppTexture
)
2443 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2444 Stage
== D3DDMAPSAMPLER
||
2445 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2446 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2447 user_assert(ppTexture
, D3DERR_INVALIDCALL
);
2449 if (Stage
>= D3DDMAPSAMPLER
)
2450 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2452 *ppTexture
= (IDirect3DBaseTexture9
*)This
->state
.texture
[Stage
];
2454 if (This
->state
.texture
[Stage
])
2455 NineUnknown_AddRef(NineUnknown(This
->state
.texture
[Stage
]));
2460 NineDevice9_SetTexture( struct NineDevice9
*This
,
2462 IDirect3DBaseTexture9
*pTexture
)
2464 struct nine_state
*state
= This
->update
;
2465 struct NineBaseTexture9
*tex
= NineBaseTexture9(pTexture
);
2466 struct NineBaseTexture9
*old
;
2468 DBG("This=%p Stage=%u pTexture=%p\n", This
, Stage
, pTexture
);
2470 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2471 Stage
== D3DDMAPSAMPLER
||
2472 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2473 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2474 user_assert(!tex
|| (tex
->base
.pool
!= D3DPOOL_SCRATCH
&&
2475 tex
->base
.pool
!= D3DPOOL_SYSTEMMEM
), D3DERR_INVALIDCALL
);
2477 if (Stage
>= D3DDMAPSAMPLER
)
2478 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2480 if (This
->is_recording
) {
2481 state
->changed
.texture
|= 1 << Stage
;
2482 state
->changed
.group
|= NINE_STATE_TEXTURE
;
2483 nine_bind(&state
->texture
[Stage
], pTexture
);
2487 old
= state
->texture
[Stage
];
2492 if ((tex
->managed
.dirty
| tex
->dirty_mip
) && LIST_IS_EMPTY(&tex
->list
))
2493 list_add(&tex
->list
, &This
->update_textures
);
2500 nine_context_set_texture(This
, Stage
, tex
);
2502 nine_bind(&state
->texture
[Stage
], pTexture
);
2508 NineDevice9_GetTextureStageState( struct NineDevice9
*This
,
2510 D3DTEXTURESTAGESTATETYPE Type
,
2513 const struct nine_state
*state
= &This
->state
;
2515 user_assert(Stage
< ARRAY_SIZE(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2516 user_assert(Type
< ARRAY_SIZE(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2518 *pValue
= state
->ff
.tex_stage
[Stage
][Type
];
2524 NineDevice9_SetTextureStageState( struct NineDevice9
*This
,
2526 D3DTEXTURESTAGESTATETYPE Type
,
2529 struct nine_state
*state
= This
->update
;
2531 DBG("Stage=%u Type=%u Value=%08x\n", Stage
, Type
, Value
);
2532 nine_dump_D3DTSS_value(DBG_FF
, Type
, Value
);
2534 user_assert(Stage
< ARRAY_SIZE(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2535 user_assert(Type
< ARRAY_SIZE(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2537 state
->ff
.tex_stage
[Stage
][Type
] = Value
;
2539 if (unlikely(This
->is_recording
)) {
2540 if (Type
== D3DTSS_TEXTURETRANSFORMFLAGS
)
2541 state
->changed
.group
|= NINE_STATE_PS1X_SHADER
;
2542 state
->changed
.group
|= NINE_STATE_FF_PSSTAGES
;
2543 state
->ff
.changed
.tex_stage
[Stage
][Type
/ 32] |= 1 << (Type
% 32);
2545 nine_context_set_texture_stage_state(This
, Stage
, Type
, Value
);
2551 NineDevice9_GetSamplerState( struct NineDevice9
*This
,
2553 D3DSAMPLERSTATETYPE Type
,
2556 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2557 Sampler
== D3DDMAPSAMPLER
||
2558 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2559 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2561 if (Sampler
>= D3DDMAPSAMPLER
)
2562 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2564 *pValue
= This
->state
.samp_advertised
[Sampler
][Type
];
2569 NineDevice9_SetSamplerState( struct NineDevice9
*This
,
2571 D3DSAMPLERSTATETYPE Type
,
2574 struct nine_state
*state
= This
->update
;
2576 DBG("This=%p Sampler=%u Type=%s Value=%08x\n", This
,
2577 Sampler
, nine_D3DSAMP_to_str(Type
), Value
);
2579 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2580 Sampler
== D3DDMAPSAMPLER
||
2581 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2582 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2584 if (Sampler
>= D3DDMAPSAMPLER
)
2585 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2587 if (unlikely(This
->is_recording
)) {
2588 state
->samp_advertised
[Sampler
][Type
] = Value
;
2589 state
->changed
.group
|= NINE_STATE_SAMPLER
;
2590 state
->changed
.sampler
[Sampler
] |= 1 << Type
;
2594 if (state
->samp_advertised
[Sampler
][Type
] == Value
)
2597 state
->samp_advertised
[Sampler
][Type
] = Value
;
2598 nine_context_set_sampler_state(This
, Sampler
, Type
, Value
);
2604 NineDevice9_ValidateDevice( struct NineDevice9
*This
,
2607 const struct nine_state
*state
= &This
->state
;
2609 unsigned w
= 0, h
= 0;
2611 DBG("This=%p pNumPasses=%p\n", This
, pNumPasses
);
2613 for (i
= 0; i
< ARRAY_SIZE(state
->samp_advertised
); ++i
) {
2614 if (state
->samp_advertised
[i
][D3DSAMP_MINFILTER
] == D3DTEXF_NONE
||
2615 state
->samp_advertised
[i
][D3DSAMP_MAGFILTER
] == D3DTEXF_NONE
)
2616 return D3DERR_UNSUPPORTEDTEXTUREFILTER
;
2619 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2623 w
= state
->rt
[i
]->desc
.Width
;
2624 h
= state
->rt
[i
]->desc
.Height
;
2626 if (state
->rt
[i
]->desc
.Width
!= w
|| state
->rt
[i
]->desc
.Height
!= h
) {
2627 return D3DERR_CONFLICTINGRENDERSTATE
;
2631 (state
->rs_advertised
[D3DRS_ZENABLE
] || state
->rs_advertised
[D3DRS_STENCILENABLE
])) {
2633 (state
->ds
->desc
.Width
!= w
|| state
->ds
->desc
.Height
!= h
))
2634 return D3DERR_CONFLICTINGRENDERSTATE
;
2644 NineDevice9_SetPaletteEntries( struct NineDevice9
*This
,
2646 const PALETTEENTRY
*pEntries
)
2648 STUB(D3D_OK
); /* like wine */
2652 NineDevice9_GetPaletteEntries( struct NineDevice9
*This
,
2654 PALETTEENTRY
*pEntries
)
2656 STUB(D3DERR_INVALIDCALL
);
2660 NineDevice9_SetCurrentTexturePalette( struct NineDevice9
*This
,
2661 UINT PaletteNumber
)
2663 STUB(D3D_OK
); /* like wine */
2667 NineDevice9_GetCurrentTexturePalette( struct NineDevice9
*This
,
2668 UINT
*PaletteNumber
)
2670 STUB(D3DERR_INVALIDCALL
);
2674 NineDevice9_SetScissorRect( struct NineDevice9
*This
,
2677 struct nine_state
*state
= This
->update
;
2679 DBG("x=(%u..%u) y=(%u..%u)\n",
2680 pRect
->left
, pRect
->top
, pRect
->right
, pRect
->bottom
);
2682 state
->scissor
.minx
= pRect
->left
;
2683 state
->scissor
.miny
= pRect
->top
;
2684 state
->scissor
.maxx
= pRect
->right
;
2685 state
->scissor
.maxy
= pRect
->bottom
;
2687 if (unlikely(This
->is_recording
))
2688 state
->changed
.group
|= NINE_STATE_SCISSOR
;
2690 nine_context_set_scissor(This
, &state
->scissor
);
2696 NineDevice9_GetScissorRect( struct NineDevice9
*This
,
2699 pRect
->left
= This
->state
.scissor
.minx
;
2700 pRect
->top
= This
->state
.scissor
.miny
;
2701 pRect
->right
= This
->state
.scissor
.maxx
;
2702 pRect
->bottom
= This
->state
.scissor
.maxy
;
2708 NineDevice9_SetSoftwareVertexProcessing( struct NineDevice9
*This
,
2711 if (This
->params
.BehaviorFlags
& D3DCREATE_MIXED_VERTEXPROCESSING
) {
2712 This
->swvp
= bSoftware
;
2713 nine_context_set_swvp(This
, bSoftware
);
2716 return D3DERR_INVALIDCALL
; /* msdn. TODO: check in practice */
2720 NineDevice9_GetSoftwareVertexProcessing( struct NineDevice9
*This
)
2726 NineDevice9_SetNPatchMode( struct NineDevice9
*This
,
2729 return D3D_OK
; /* Nothing to do because we don't advertise NPatch support */
2733 NineDevice9_GetNPatchMode( struct NineDevice9
*This
)
2738 /* TODO: only go through dirty textures */
2740 validate_textures(struct NineDevice9
*device
)
2742 struct NineBaseTexture9
*tex
, *ptr
;
2743 LIST_FOR_EACH_ENTRY_SAFE(tex
, ptr
, &device
->update_textures
, list
) {
2744 list_delinit(&tex
->list
);
2745 NineBaseTexture9_Validate(tex
);
2750 update_managed_buffers(struct NineDevice9
*device
)
2752 struct NineBuffer9
*buf
, *ptr
;
2753 LIST_FOR_EACH_ENTRY_SAFE(buf
, ptr
, &device
->update_buffers
, managed
.list
) {
2754 list_delinit(&buf
->managed
.list
);
2755 NineBuffer9_Upload(buf
);
2760 NineBeforeDraw( struct NineDevice9
*This
)
2762 /* Upload Managed dirty content */
2763 validate_textures(This
); /* may clobber state */
2764 update_managed_buffers(This
);
2768 NineAfterDraw( struct NineDevice9
*This
)
2771 struct nine_state
*state
= &This
->state
;
2772 unsigned ps_mask
= state
->ps
? state
->ps
->rt_mask
: 1;
2774 /* Flag render-targets with autogenmipmap for mipmap regeneration */
2775 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2776 struct NineSurface9
*rt
= state
->rt
[i
];
2778 if (rt
&& rt
->desc
.Format
!= D3DFMT_NULL
&& (ps_mask
& (1 << i
)) &&
2779 rt
->desc
.Usage
& D3DUSAGE_AUTOGENMIPMAP
) {
2780 assert(rt
->texture
== D3DRTYPE_TEXTURE
||
2781 rt
->texture
== D3DRTYPE_CUBETEXTURE
);
2782 NineBaseTexture9(rt
->base
.base
.container
)->dirty_mip
= TRUE
;
2788 NineDevice9_DrawPrimitive( struct NineDevice9
*This
,
2789 D3DPRIMITIVETYPE PrimitiveType
,
2791 UINT PrimitiveCount
)
2793 DBG("iface %p, PrimitiveType %u, StartVertex %u, PrimitiveCount %u\n",
2794 This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2796 NineBeforeDraw(This
);
2797 nine_context_draw_primitive(This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2798 NineAfterDraw(This
);
2804 NineDevice9_DrawIndexedPrimitive( struct NineDevice9
*This
,
2805 D3DPRIMITIVETYPE PrimitiveType
,
2806 INT BaseVertexIndex
,
2807 UINT MinVertexIndex
,
2810 UINT PrimitiveCount
)
2812 DBG("iface %p, PrimitiveType %u, BaseVertexIndex %u, MinVertexIndex %u "
2813 "NumVertices %u, StartIndex %u, PrimitiveCount %u\n",
2814 This
, PrimitiveType
, BaseVertexIndex
, MinVertexIndex
, NumVertices
,
2815 StartIndex
, PrimitiveCount
);
2817 user_assert(This
->state
.idxbuf
, D3DERR_INVALIDCALL
);
2818 user_assert(This
->state
.vdecl
, D3DERR_INVALIDCALL
);
2820 NineBeforeDraw(This
);
2821 nine_context_draw_indexed_primitive(This
, PrimitiveType
, BaseVertexIndex
,
2822 MinVertexIndex
, NumVertices
, StartIndex
,
2824 NineAfterDraw(This
);
2830 NineDevice9_DrawPrimitiveUP( struct NineDevice9
*This
,
2831 D3DPRIMITIVETYPE PrimitiveType
,
2832 UINT PrimitiveCount
,
2833 const void *pVertexStreamZeroData
,
2834 UINT VertexStreamZeroStride
)
2836 struct pipe_vertex_buffer vtxbuf
;
2838 DBG("iface %p, PrimitiveType %u, PrimitiveCount %u, data %p, stride %u\n",
2839 This
, PrimitiveType
, PrimitiveCount
,
2840 pVertexStreamZeroData
, VertexStreamZeroStride
);
2842 user_assert(pVertexStreamZeroData
&& VertexStreamZeroStride
,
2843 D3DERR_INVALIDCALL
);
2844 user_assert(PrimitiveCount
, D3D_OK
);
2846 vtxbuf
.stride
= VertexStreamZeroStride
;
2847 vtxbuf
.buffer_offset
= 0;
2848 vtxbuf
.buffer
= NULL
;
2849 vtxbuf
.user_buffer
= pVertexStreamZeroData
;
2851 if (!This
->driver_caps
.user_vbufs
) {
2852 /* Implicit use of context pipe */
2853 (void)NineDevice9_GetPipe(This
);
2854 u_upload_data(This
->vertex_uploader
,
2856 (prim_count_to_vertex_count(PrimitiveType
, PrimitiveCount
)) * VertexStreamZeroStride
, /* XXX */
2859 &vtxbuf
.buffer_offset
,
2861 u_upload_unmap(This
->vertex_uploader
);
2862 vtxbuf
.user_buffer
= NULL
;
2865 NineBeforeDraw(This
);
2866 nine_context_draw_primitive_from_vtxbuf(This
, PrimitiveType
, PrimitiveCount
, &vtxbuf
);
2867 NineAfterDraw(This
);
2869 pipe_resource_reference(&vtxbuf
.buffer
, NULL
);
2871 NineDevice9_PauseRecording(This
);
2872 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
2873 NineDevice9_ResumeRecording(This
);
2879 NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9
*This
,
2880 D3DPRIMITIVETYPE PrimitiveType
,
2881 UINT MinVertexIndex
,
2883 UINT PrimitiveCount
,
2884 const void *pIndexData
,
2885 D3DFORMAT IndexDataFormat
,
2886 const void *pVertexStreamZeroData
,
2887 UINT VertexStreamZeroStride
)
2889 struct pipe_vertex_buffer vbuf
;
2890 struct pipe_index_buffer ibuf
;
2892 DBG("iface %p, PrimitiveType %u, MinVertexIndex %u, NumVertices %u "
2893 "PrimitiveCount %u, pIndexData %p, IndexDataFormat %u "
2894 "pVertexStreamZeroData %p, VertexStreamZeroStride %u\n",
2895 This
, PrimitiveType
, MinVertexIndex
, NumVertices
, PrimitiveCount
,
2896 pIndexData
, IndexDataFormat
,
2897 pVertexStreamZeroData
, VertexStreamZeroStride
);
2899 user_assert(pIndexData
&& pVertexStreamZeroData
, D3DERR_INVALIDCALL
);
2900 user_assert(VertexStreamZeroStride
, D3DERR_INVALIDCALL
);
2901 user_assert(IndexDataFormat
== D3DFMT_INDEX16
||
2902 IndexDataFormat
== D3DFMT_INDEX32
, D3DERR_INVALIDCALL
);
2903 user_assert(PrimitiveCount
, D3D_OK
);
2905 vbuf
.stride
= VertexStreamZeroStride
;
2906 vbuf
.buffer_offset
= 0;
2908 vbuf
.user_buffer
= pVertexStreamZeroData
;
2910 ibuf
.index_size
= (IndexDataFormat
== D3DFMT_INDEX16
) ? 2 : 4;
2913 ibuf
.user_buffer
= pIndexData
;
2915 if (!This
->driver_caps
.user_vbufs
) {
2916 const unsigned base
= MinVertexIndex
* VertexStreamZeroStride
;
2917 /* Implicit use of context pipe */
2918 (void)NineDevice9_GetPipe(This
);
2919 u_upload_data(This
->vertex_uploader
,
2921 NumVertices
* VertexStreamZeroStride
, /* XXX */
2923 (const uint8_t *)vbuf
.user_buffer
+ base
,
2924 &vbuf
.buffer_offset
,
2926 u_upload_unmap(This
->vertex_uploader
);
2927 /* Won't be used: */
2928 vbuf
.buffer_offset
-= base
;
2929 vbuf
.user_buffer
= NULL
;
2931 if (!This
->driver_caps
.user_ibufs
) {
2932 /* Implicit use of context pipe */
2933 (void)NineDevice9_GetPipe(This
);
2934 u_upload_data(This
->index_uploader
,
2936 (prim_count_to_vertex_count(PrimitiveType
, PrimitiveCount
)) * ibuf
.index_size
,
2941 u_upload_unmap(This
->index_uploader
);
2942 ibuf
.user_buffer
= NULL
;
2945 NineBeforeDraw(This
);
2946 nine_context_draw_indexed_primitive_from_vtxbuf_idxbuf(This
, PrimitiveType
,
2952 NineAfterDraw(This
);
2954 pipe_resource_reference(&vbuf
.buffer
, NULL
);
2955 pipe_resource_reference(&ibuf
.buffer
, NULL
);
2957 NineDevice9_PauseRecording(This
);
2958 NineDevice9_SetIndices(This
, NULL
);
2959 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
2960 NineDevice9_ResumeRecording(This
);
2966 NineDevice9_ProcessVertices( struct NineDevice9
*This
,
2970 IDirect3DVertexBuffer9
*pDestBuffer
,
2971 IDirect3DVertexDeclaration9
*pVertexDecl
,
2974 struct pipe_screen
*screen_sw
= This
->screen_sw
;
2975 struct pipe_context
*pipe_sw
= This
->pipe_sw
;
2976 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pVertexDecl
);
2977 struct NineVertexBuffer9
*dst
= NineVertexBuffer9(pDestBuffer
);
2978 struct NineVertexShader9
*vs
;
2979 struct pipe_resource
*resource
;
2980 struct pipe_transfer
*transfer
= NULL
;
2981 struct pipe_stream_output_info so
;
2982 struct pipe_stream_output_target
*target
;
2983 struct pipe_draw_info draw
;
2984 struct pipe_box box
;
2985 bool programmable_vs
= This
->state
.vs
&& !(This
->state
.vdecl
&& This
->state
.vdecl
->position_t
);
2986 unsigned offsets
[1] = {0};
2988 unsigned buffer_size
;
2991 DBG("This=%p SrcStartIndex=%u DestIndex=%u VertexCount=%u "
2992 "pDestBuffer=%p pVertexDecl=%p Flags=%d\n",
2993 This
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
,
2994 pVertexDecl
, Flags
);
2996 if (!screen_sw
->get_param(screen_sw
, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
)) {
2997 DBG("ProcessVertices not supported\n");
2998 return D3DERR_INVALIDCALL
;
3002 vs
= programmable_vs
? This
->state
.vs
: This
->ff
.vs
;
3003 /* Note: version is 0 for ff */
3004 user_assert(vdecl
|| (vs
->byte_code
.version
< 0x30 && dst
->desc
.FVF
),
3005 D3DERR_INVALIDCALL
);
3007 DWORD FVF
= dst
->desc
.FVF
;
3008 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
3010 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
3014 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
3015 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
3019 /* Flags: Can be 0 or D3DPV_DONOTCOPYDATA, and/or lock flags
3020 * D3DPV_DONOTCOPYDATA -> Has effect only for ff. In particular
3021 * if not set, everything from src will be used, and dst
3022 * must match exactly the ff vs outputs.
3023 * TODO: Handle all the checks, etc for ff */
3024 user_assert(vdecl
->position_t
|| programmable_vs
,
3025 D3DERR_INVALIDCALL
);
3027 /* TODO: Support vs < 3 and ff */
3028 user_assert(vs
->byte_code
.version
== 0x30,
3029 D3DERR_INVALIDCALL
);
3030 /* TODO: Not hardcode the constant buffers for swvp */
3031 user_assert(This
->may_swvp
,
3032 D3DERR_INVALIDCALL
);
3034 nine_state_prepare_draw_sw(This
, vdecl
, SrcStartIndex
, VertexCount
, &so
);
3036 buffer_size
= VertexCount
* so
.stride
[0] * 4;
3038 struct pipe_resource templ
;
3040 memset(&templ
, 0, sizeof(templ
));
3041 templ
.target
= PIPE_BUFFER
;
3042 templ
.format
= PIPE_FORMAT_R8_UNORM
;
3043 templ
.width0
= buffer_size
;
3045 templ
.bind
= PIPE_BIND_STREAM_OUTPUT
;
3046 templ
.usage
= PIPE_USAGE_STREAM
;
3047 templ
.height0
= templ
.depth0
= templ
.array_size
= 1;
3048 templ
.last_level
= templ
.nr_samples
= 0;
3050 resource
= screen_sw
->resource_create(screen_sw
, &templ
);
3052 return E_OUTOFMEMORY
;
3054 target
= pipe_sw
->create_stream_output_target(pipe_sw
, resource
,
3057 pipe_resource_reference(&resource
, NULL
);
3058 return D3DERR_DRIVERINTERNALERROR
;
3061 draw
.mode
= PIPE_PRIM_POINTS
;
3062 draw
.count
= VertexCount
;
3063 draw
.start_instance
= 0;
3064 draw
.primitive_restart
= FALSE
;
3065 draw
.restart_index
= 0;
3066 draw
.count_from_stream_output
= NULL
;
3067 draw
.indirect
= NULL
;
3068 draw
.indirect_params
= NULL
;
3069 draw
.instance_count
= 1;
3070 draw
.indexed
= FALSE
;
3072 draw
.index_bias
= 0;
3074 draw
.max_index
= VertexCount
- 1;
3077 pipe_sw
->set_stream_output_targets(pipe_sw
, 1, &target
, offsets
);
3079 pipe_sw
->draw_vbo(pipe_sw
, &draw
);
3081 pipe_sw
->set_stream_output_targets(pipe_sw
, 0, NULL
, 0);
3082 pipe_sw
->stream_output_target_destroy(pipe_sw
, target
);
3084 u_box_1d(0, VertexCount
* so
.stride
[0] * 4, &box
);
3085 map
= pipe_sw
->transfer_map(pipe_sw
, resource
, 0, PIPE_TRANSFER_READ
, &box
,
3088 hr
= D3DERR_DRIVERINTERNALERROR
;
3092 hr
= NineVertexDeclaration9_ConvertStreamOutput(vdecl
,
3093 dst
, DestIndex
, VertexCount
,
3096 pipe_sw
->transfer_unmap(pipe_sw
, transfer
);
3099 nine_state_after_draw_sw(This
);
3100 pipe_resource_reference(&resource
, NULL
);
3105 NineDevice9_CreateVertexDeclaration( struct NineDevice9
*This
,
3106 const D3DVERTEXELEMENT9
*pVertexElements
,
3107 IDirect3DVertexDeclaration9
**ppDecl
)
3109 struct NineVertexDeclaration9
*vdecl
;
3111 DBG("This=%p pVertexElements=%p ppDecl=%p\n",
3112 This
, pVertexElements
, ppDecl
);
3114 HRESULT hr
= NineVertexDeclaration9_new(This
, pVertexElements
, &vdecl
);
3116 *ppDecl
= (IDirect3DVertexDeclaration9
*)vdecl
;
3122 NineDevice9_SetVertexDeclaration( struct NineDevice9
*This
,
3123 IDirect3DVertexDeclaration9
*pDecl
)
3125 struct nine_state
*state
= This
->update
;
3126 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pDecl
);
3128 DBG("This=%p pDecl=%p\n", This
, pDecl
);
3130 if (unlikely(This
->is_recording
)) {
3131 nine_bind(&state
->vdecl
, vdecl
);
3132 state
->changed
.group
|= NINE_STATE_VDECL
;
3136 if (state
->vdecl
== vdecl
)
3139 nine_bind(&state
->vdecl
, vdecl
);
3141 nine_context_set_vertex_declaration(This
, vdecl
);
3147 NineDevice9_GetVertexDeclaration( struct NineDevice9
*This
,
3148 IDirect3DVertexDeclaration9
**ppDecl
)
3150 user_assert(ppDecl
, D3DERR_INVALIDCALL
);
3152 *ppDecl
= (IDirect3DVertexDeclaration9
*)This
->state
.vdecl
;
3154 NineUnknown_AddRef(NineUnknown(*ppDecl
));
3159 NineDevice9_SetFVF( struct NineDevice9
*This
,
3162 struct NineVertexDeclaration9
*vdecl
;
3165 DBG("FVF = %08x\n", FVF
);
3167 return D3D_OK
; /* like wine */
3169 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
3171 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
3175 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
3176 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
3178 return NineDevice9_SetVertexDeclaration(
3179 This
, (IDirect3DVertexDeclaration9
*)vdecl
);
3183 NineDevice9_GetFVF( struct NineDevice9
*This
,
3186 *pFVF
= This
->state
.vdecl
? This
->state
.vdecl
->fvf
: 0;
3191 NineDevice9_CreateVertexShader( struct NineDevice9
*This
,
3192 const DWORD
*pFunction
,
3193 IDirect3DVertexShader9
**ppShader
)
3195 struct NineVertexShader9
*vs
;
3198 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3200 hr
= NineVertexShader9_new(This
, &vs
, pFunction
, NULL
);
3203 *ppShader
= (IDirect3DVertexShader9
*)vs
;
3208 NineDevice9_SetVertexShader( struct NineDevice9
*This
,
3209 IDirect3DVertexShader9
*pShader
)
3211 struct nine_state
*state
= This
->update
;
3212 struct NineVertexShader9
*vs_shader
= (struct NineVertexShader9
*)pShader
;
3214 DBG("This=%p pShader=%p\n", This
, pShader
);
3216 if (unlikely(This
->is_recording
)) {
3217 nine_bind(&state
->vs
, vs_shader
);
3218 state
->changed
.group
|= NINE_STATE_VS
;
3222 if (state
->vs
== vs_shader
)
3225 nine_bind(&state
->vs
, vs_shader
);
3227 nine_context_set_vertex_shader(This
, vs_shader
);
3233 NineDevice9_GetVertexShader( struct NineDevice9
*This
,
3234 IDirect3DVertexShader9
**ppShader
)
3236 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3237 nine_reference_set(ppShader
, This
->state
.vs
);
3242 NineDevice9_SetVertexShaderConstantF( struct NineDevice9
*This
,
3244 const float *pConstantData
,
3245 UINT Vector4fCount
)
3247 struct nine_state
*state
= This
->update
;
3248 float *vs_const_f
= state
->vs_const_f
;
3250 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3251 This
, StartRegister
, pConstantData
, Vector4fCount
);
3253 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3254 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3258 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3260 if (unlikely(This
->is_recording
)) {
3261 memcpy(&vs_const_f
[StartRegister
* 4],
3263 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3265 nine_ranges_insert(&state
->changed
.vs_const_f
,
3266 StartRegister
, StartRegister
+ Vector4fCount
,
3269 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3274 if (!memcmp(&vs_const_f
[StartRegister
* 4], pConstantData
,
3275 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0])))
3278 memcpy(&vs_const_f
[StartRegister
* 4],
3280 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3282 nine_context_set_vertex_shader_constant_f(This
, StartRegister
, pConstantData
,
3283 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]),
3290 NineDevice9_GetVertexShaderConstantF( struct NineDevice9
*This
,
3292 float *pConstantData
,
3293 UINT Vector4fCount
)
3295 const struct nine_state
*state
= &This
->state
;
3297 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3298 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3299 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3301 memcpy(pConstantData
,
3302 &state
->vs_const_f
[StartRegister
* 4],
3303 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3309 NineDevice9_SetVertexShaderConstantI( struct NineDevice9
*This
,
3311 const int *pConstantData
,
3312 UINT Vector4iCount
)
3314 struct nine_state
*state
= This
->update
;
3317 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3318 This
, StartRegister
, pConstantData
, Vector4iCount
);
3320 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3321 D3DERR_INVALIDCALL
);
3322 user_assert(StartRegister
+ Vector4iCount
<= (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3323 D3DERR_INVALIDCALL
);
3324 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3326 if (This
->driver_caps
.vs_integer
) {
3327 if (!This
->is_recording
) {
3328 if (!memcmp(&state
->vs_const_i
[4 * StartRegister
], pConstantData
,
3329 Vector4iCount
* sizeof(int[4])))
3332 memcpy(&state
->vs_const_i
[4 * StartRegister
],
3334 Vector4iCount
* sizeof(int[4]));
3336 for (i
= 0; i
< Vector4iCount
; i
++) {
3337 state
->vs_const_i
[4 * (StartRegister
+ i
)] = fui((float)(pConstantData
[4 * i
]));
3338 state
->vs_const_i
[4 * (StartRegister
+ i
) + 1] = fui((float)(pConstantData
[4 * i
+ 1]));
3339 state
->vs_const_i
[4 * (StartRegister
+ i
) + 2] = fui((float)(pConstantData
[4 * i
+ 2]));
3340 state
->vs_const_i
[4 * (StartRegister
+ i
) + 3] = fui((float)(pConstantData
[4 * i
+ 3]));
3344 if (unlikely(This
->is_recording
)) {
3345 nine_ranges_insert(&state
->changed
.vs_const_i
,
3346 StartRegister
, StartRegister
+ Vector4iCount
,
3348 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3350 nine_context_set_vertex_shader_constant_i(This
, StartRegister
, pConstantData
,
3351 Vector4iCount
* sizeof(int[4]), Vector4iCount
);
3357 NineDevice9_GetVertexShaderConstantI( struct NineDevice9
*This
,
3360 UINT Vector4iCount
)
3362 const struct nine_state
*state
= &This
->state
;
3365 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3366 D3DERR_INVALIDCALL
);
3367 user_assert(StartRegister
+ Vector4iCount
<= (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3368 D3DERR_INVALIDCALL
);
3369 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3371 if (This
->driver_caps
.vs_integer
) {
3372 memcpy(pConstantData
,
3373 &state
->vs_const_i
[4 * StartRegister
],
3374 Vector4iCount
* sizeof(int[4]));
3376 for (i
= 0; i
< Vector4iCount
; i
++) {
3377 pConstantData
[4 * i
] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
)]);
3378 pConstantData
[4 * i
+ 1] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
) + 1]);
3379 pConstantData
[4 * i
+ 2] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
) + 2]);
3380 pConstantData
[4 * i
+ 3] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
) + 3]);
3388 NineDevice9_SetVertexShaderConstantB( struct NineDevice9
*This
,
3390 const BOOL
*pConstantData
,
3393 struct nine_state
*state
= This
->update
;
3395 uint32_t bool_true
= This
->driver_caps
.vs_integer
? 0xFFFFFFFF : fui(1.0f
);
3397 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3398 This
, StartRegister
, pConstantData
, BoolCount
);
3400 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3401 D3DERR_INVALIDCALL
);
3402 user_assert(StartRegister
+ BoolCount
<= (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3403 D3DERR_INVALIDCALL
);
3404 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3406 if (!This
->is_recording
) {
3407 bool noChange
= true;
3408 for (i
= 0; i
< BoolCount
; i
++) {
3409 if (!!state
->vs_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3416 for (i
= 0; i
< BoolCount
; i
++)
3417 state
->vs_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3419 if (unlikely(This
->is_recording
)) {
3420 nine_ranges_insert(&state
->changed
.vs_const_b
,
3421 StartRegister
, StartRegister
+ BoolCount
,
3423 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3425 nine_context_set_vertex_shader_constant_b(This
, StartRegister
, pConstantData
,
3426 sizeof(BOOL
) * BoolCount
, BoolCount
);
3432 NineDevice9_GetVertexShaderConstantB( struct NineDevice9
*This
,
3434 BOOL
*pConstantData
,
3437 const struct nine_state
*state
= &This
->state
;
3440 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3441 D3DERR_INVALIDCALL
);
3442 user_assert(StartRegister
+ BoolCount
<= (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3443 D3DERR_INVALIDCALL
);
3444 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3446 for (i
= 0; i
< BoolCount
; i
++)
3447 pConstantData
[i
] = state
->vs_const_b
[StartRegister
+ i
] != 0 ? TRUE
: FALSE
;
3453 NineDevice9_SetStreamSource( struct NineDevice9
*This
,
3455 IDirect3DVertexBuffer9
*pStreamData
,
3459 struct nine_state
*state
= This
->update
;
3460 struct NineVertexBuffer9
*pVBuf9
= NineVertexBuffer9(pStreamData
);
3461 const unsigned i
= StreamNumber
;
3463 DBG("This=%p StreamNumber=%u pStreamData=%p OffsetInBytes=%u Stride=%u\n",
3464 This
, StreamNumber
, pStreamData
, OffsetInBytes
, Stride
);
3466 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3467 user_assert(Stride
<= This
->caps
.MaxStreamStride
, D3DERR_INVALIDCALL
);
3469 if (unlikely(This
->is_recording
)) {
3470 nine_bind(&state
->stream
[i
], pStreamData
);
3471 state
->changed
.vtxbuf
|= 1 << StreamNumber
;
3472 state
->vtxbuf
[i
].stride
= Stride
;
3473 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3477 if (state
->stream
[i
] == NineVertexBuffer9(pStreamData
) &&
3478 state
->vtxbuf
[i
].stride
== Stride
&&
3479 state
->vtxbuf
[i
].buffer_offset
== OffsetInBytes
)
3482 state
->vtxbuf
[i
].stride
= Stride
;
3483 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3485 nine_bind(&state
->stream
[i
], pStreamData
);
3487 nine_context_set_stream_source(This
,
3497 NineDevice9_GetStreamSource( struct NineDevice9
*This
,
3499 IDirect3DVertexBuffer9
**ppStreamData
,
3500 UINT
*pOffsetInBytes
,
3503 const struct nine_state
*state
= &This
->state
;
3504 const unsigned i
= StreamNumber
;
3506 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3507 user_assert(ppStreamData
, D3DERR_INVALIDCALL
);
3509 nine_reference_set(ppStreamData
, state
->stream
[i
]);
3510 *pStride
= state
->vtxbuf
[i
].stride
;
3511 *pOffsetInBytes
= state
->vtxbuf
[i
].buffer_offset
;
3517 NineDevice9_SetStreamSourceFreq( struct NineDevice9
*This
,
3521 struct nine_state
*state
= This
->update
;
3522 /* const UINT freq = Setting & 0x7FFFFF; */
3524 DBG("This=%p StreamNumber=%u FrequencyParameter=0x%x\n", This
,
3525 StreamNumber
, Setting
);
3527 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3528 user_assert(StreamNumber
!= 0 || !(Setting
& D3DSTREAMSOURCE_INSTANCEDATA
),
3529 D3DERR_INVALIDCALL
);
3530 user_assert(!((Setting
& D3DSTREAMSOURCE_INSTANCEDATA
) &&
3531 (Setting
& D3DSTREAMSOURCE_INDEXEDDATA
)), D3DERR_INVALIDCALL
);
3532 user_assert(Setting
, D3DERR_INVALIDCALL
);
3534 if (unlikely(This
->is_recording
)) {
3535 state
->stream_freq
[StreamNumber
] = Setting
;
3536 state
->changed
.stream_freq
|= 1 << StreamNumber
;
3537 if (StreamNumber
!= 0)
3538 state
->changed
.group
|= NINE_STATE_STREAMFREQ
;
3542 if (state
->stream_freq
[StreamNumber
] == Setting
)
3545 state
->stream_freq
[StreamNumber
] = Setting
;
3547 nine_context_set_stream_source_freq(This
, StreamNumber
, Setting
);
3552 NineDevice9_GetStreamSourceFreq( struct NineDevice9
*This
,
3556 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3557 *pSetting
= This
->state
.stream_freq
[StreamNumber
];
3562 NineDevice9_SetIndices( struct NineDevice9
*This
,
3563 IDirect3DIndexBuffer9
*pIndexData
)
3565 struct nine_state
*state
= This
->update
;
3566 struct NineIndexBuffer9
*idxbuf
= NineIndexBuffer9(pIndexData
);
3568 DBG("This=%p pIndexData=%p\n", This
, pIndexData
);
3570 if (unlikely(This
->is_recording
)) {
3571 nine_bind(&state
->idxbuf
, idxbuf
);
3572 state
->changed
.group
|= NINE_STATE_IDXBUF
;
3576 if (state
->idxbuf
== idxbuf
)
3578 nine_bind(&state
->idxbuf
, idxbuf
);
3580 nine_context_set_indices(This
, idxbuf
);
3585 /* XXX: wine/d3d9 doesn't have pBaseVertexIndex, and it doesn't make sense
3586 * here because it's an argument passed to the Draw calls.
3589 NineDevice9_GetIndices( struct NineDevice9
*This
,
3590 IDirect3DIndexBuffer9
**ppIndexData
)
3592 user_assert(ppIndexData
, D3DERR_INVALIDCALL
);
3593 nine_reference_set(ppIndexData
, This
->state
.idxbuf
);
3598 NineDevice9_CreatePixelShader( struct NineDevice9
*This
,
3599 const DWORD
*pFunction
,
3600 IDirect3DPixelShader9
**ppShader
)
3602 struct NinePixelShader9
*ps
;
3605 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3607 hr
= NinePixelShader9_new(This
, &ps
, pFunction
, NULL
);
3610 *ppShader
= (IDirect3DPixelShader9
*)ps
;
3615 NineDevice9_SetPixelShader( struct NineDevice9
*This
,
3616 IDirect3DPixelShader9
*pShader
)
3618 struct nine_state
*state
= This
->update
;
3619 struct NinePixelShader9
*ps
= (struct NinePixelShader9
*)pShader
;
3621 DBG("This=%p pShader=%p\n", This
, pShader
);
3623 if (unlikely(This
->is_recording
)) {
3624 /* Technically we need NINE_STATE_FB only
3625 * if the ps mask changes, but put it always
3627 nine_bind(&state
->ps
, pShader
);
3628 state
->changed
.group
|= NINE_STATE_PS
| NINE_STATE_FB
;
3632 if (state
->ps
== ps
)
3635 nine_bind(&state
->ps
, ps
);
3637 nine_context_set_pixel_shader(This
, ps
);
3643 NineDevice9_GetPixelShader( struct NineDevice9
*This
,
3644 IDirect3DPixelShader9
**ppShader
)
3646 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3647 nine_reference_set(ppShader
, This
->state
.ps
);
3652 NineDevice9_SetPixelShaderConstantF( struct NineDevice9
*This
,
3654 const float *pConstantData
,
3655 UINT Vector4fCount
)
3657 struct nine_state
*state
= This
->update
;
3659 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3660 This
, StartRegister
, pConstantData
, Vector4fCount
);
3662 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3663 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3667 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3669 if (unlikely(This
->is_recording
)) {
3670 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3672 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3674 nine_ranges_insert(&state
->changed
.ps_const_f
,
3675 StartRegister
, StartRegister
+ Vector4fCount
,
3678 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3682 if (!memcmp(&state
->ps_const_f
[StartRegister
* 4], pConstantData
,
3683 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0])))
3686 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3688 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3690 nine_context_set_pixel_shader_constant_f(This
, StartRegister
, pConstantData
,
3691 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]),
3698 NineDevice9_GetPixelShaderConstantF( struct NineDevice9
*This
,
3700 float *pConstantData
,
3701 UINT Vector4fCount
)
3703 const struct nine_state
*state
= &This
->state
;
3705 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3706 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3707 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3709 memcpy(pConstantData
,
3710 &state
->ps_const_f
[StartRegister
* 4],
3711 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3717 NineDevice9_SetPixelShaderConstantI( struct NineDevice9
*This
,
3719 const int *pConstantData
,
3720 UINT Vector4iCount
)
3722 struct nine_state
*state
= This
->update
;
3725 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3726 This
, StartRegister
, pConstantData
, Vector4iCount
);
3728 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3729 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3730 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3732 if (This
->driver_caps
.ps_integer
) {
3733 if (!This
->is_recording
) {
3734 if (!memcmp(&state
->ps_const_i
[StartRegister
][0], pConstantData
,
3735 Vector4iCount
* sizeof(state
->ps_const_i
[0])))
3738 memcpy(&state
->ps_const_i
[StartRegister
][0],
3740 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3742 for (i
= 0; i
< Vector4iCount
; i
++) {
3743 state
->ps_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3744 state
->ps_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3745 state
->ps_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3746 state
->ps_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3750 if (unlikely(This
->is_recording
)) {
3751 state
->changed
.ps_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3752 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3754 nine_context_set_pixel_shader_constant_i(This
, StartRegister
, pConstantData
,
3755 sizeof(state
->ps_const_i
[0]) * Vector4iCount
, Vector4iCount
);
3761 NineDevice9_GetPixelShaderConstantI( struct NineDevice9
*This
,
3764 UINT Vector4iCount
)
3766 const struct nine_state
*state
= &This
->state
;
3769 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3770 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3771 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3773 if (This
->driver_caps
.ps_integer
) {
3774 memcpy(pConstantData
,
3775 &state
->ps_const_i
[StartRegister
][0],
3776 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3778 for (i
= 0; i
< Vector4iCount
; i
++) {
3779 pConstantData
[4*i
] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][0]);
3780 pConstantData
[4*i
+1] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][1]);
3781 pConstantData
[4*i
+2] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][2]);
3782 pConstantData
[4*i
+3] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][3]);
3790 NineDevice9_SetPixelShaderConstantB( struct NineDevice9
*This
,
3792 const BOOL
*pConstantData
,
3795 struct nine_state
*state
= This
->update
;
3797 uint32_t bool_true
= This
->driver_caps
.ps_integer
? 0xFFFFFFFF : fui(1.0f
);
3799 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3800 This
, StartRegister
, pConstantData
, BoolCount
);
3802 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3803 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3804 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3806 if (!This
->is_recording
) {
3807 bool noChange
= true;
3808 for (i
= 0; i
< BoolCount
; i
++) {
3809 if (!!state
->ps_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3816 for (i
= 0; i
< BoolCount
; i
++)
3817 state
->ps_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3819 if (unlikely(This
->is_recording
)) {
3820 state
->changed
.ps_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3821 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3823 nine_context_set_pixel_shader_constant_b(This
, StartRegister
, pConstantData
,
3824 sizeof(BOOL
) * BoolCount
, BoolCount
);
3830 NineDevice9_GetPixelShaderConstantB( struct NineDevice9
*This
,
3832 BOOL
*pConstantData
,
3835 const struct nine_state
*state
= &This
->state
;
3838 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3839 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3840 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3842 for (i
= 0; i
< BoolCount
; i
++)
3843 pConstantData
[i
] = state
->ps_const_b
[StartRegister
+ i
] ? TRUE
: FALSE
;
3849 NineDevice9_DrawRectPatch( struct NineDevice9
*This
,
3851 const float *pNumSegs
,
3852 const D3DRECTPATCH_INFO
*pRectPatchInfo
)
3854 STUB(D3DERR_INVALIDCALL
);
3858 NineDevice9_DrawTriPatch( struct NineDevice9
*This
,
3860 const float *pNumSegs
,
3861 const D3DTRIPATCH_INFO
*pTriPatchInfo
)
3863 STUB(D3DERR_INVALIDCALL
);
3867 NineDevice9_DeletePatch( struct NineDevice9
*This
,
3870 STUB(D3DERR_INVALIDCALL
);
3874 NineDevice9_CreateQuery( struct NineDevice9
*This
,
3876 IDirect3DQuery9
**ppQuery
)
3878 struct NineQuery9
*query
;
3881 DBG("This=%p Type=%d ppQuery=%p\n", This
, Type
, ppQuery
);
3883 hr
= nine_is_query_supported(This
->screen
, Type
);
3884 if (!ppQuery
|| hr
!= D3D_OK
)
3887 hr
= NineQuery9_new(This
, &query
, Type
);
3890 *ppQuery
= (IDirect3DQuery9
*)query
;
3894 IDirect3DDevice9Vtbl NineDevice9_vtable
= {
3895 (void *)NineUnknown_QueryInterface
,
3896 (void *)NineUnknown_AddRef
,
3897 (void *)NineUnknown_Release
,
3898 (void *)NineDevice9_TestCooperativeLevel
,
3899 (void *)NineDevice9_GetAvailableTextureMem
,
3900 (void *)NineDevice9_EvictManagedResources
,
3901 (void *)NineDevice9_GetDirect3D
,
3902 (void *)NineDevice9_GetDeviceCaps
,
3903 (void *)NineDevice9_GetDisplayMode
,
3904 (void *)NineDevice9_GetCreationParameters
,
3905 (void *)NineDevice9_SetCursorProperties
,
3906 (void *)NineDevice9_SetCursorPosition
,
3907 (void *)NineDevice9_ShowCursor
,
3908 (void *)NineDevice9_CreateAdditionalSwapChain
,
3909 (void *)NineDevice9_GetSwapChain
,
3910 (void *)NineDevice9_GetNumberOfSwapChains
,
3911 (void *)NineDevice9_Reset
,
3912 (void *)NineDevice9_Present
,
3913 (void *)NineDevice9_GetBackBuffer
,
3914 (void *)NineDevice9_GetRasterStatus
,
3915 (void *)NineDevice9_SetDialogBoxMode
,
3916 (void *)NineDevice9_SetGammaRamp
,
3917 (void *)NineDevice9_GetGammaRamp
,
3918 (void *)NineDevice9_CreateTexture
,
3919 (void *)NineDevice9_CreateVolumeTexture
,
3920 (void *)NineDevice9_CreateCubeTexture
,
3921 (void *)NineDevice9_CreateVertexBuffer
,
3922 (void *)NineDevice9_CreateIndexBuffer
,
3923 (void *)NineDevice9_CreateRenderTarget
,
3924 (void *)NineDevice9_CreateDepthStencilSurface
,
3925 (void *)NineDevice9_UpdateSurface
,
3926 (void *)NineDevice9_UpdateTexture
,
3927 (void *)NineDevice9_GetRenderTargetData
,
3928 (void *)NineDevice9_GetFrontBufferData
,
3929 (void *)NineDevice9_StretchRect
,
3930 (void *)NineDevice9_ColorFill
,
3931 (void *)NineDevice9_CreateOffscreenPlainSurface
,
3932 (void *)NineDevice9_SetRenderTarget
,
3933 (void *)NineDevice9_GetRenderTarget
,
3934 (void *)NineDevice9_SetDepthStencilSurface
,
3935 (void *)NineDevice9_GetDepthStencilSurface
,
3936 (void *)NineDevice9_BeginScene
,
3937 (void *)NineDevice9_EndScene
,
3938 (void *)NineDevice9_Clear
,
3939 (void *)NineDevice9_SetTransform
,
3940 (void *)NineDevice9_GetTransform
,
3941 (void *)NineDevice9_MultiplyTransform
,
3942 (void *)NineDevice9_SetViewport
,
3943 (void *)NineDevice9_GetViewport
,
3944 (void *)NineDevice9_SetMaterial
,
3945 (void *)NineDevice9_GetMaterial
,
3946 (void *)NineDevice9_SetLight
,
3947 (void *)NineDevice9_GetLight
,
3948 (void *)NineDevice9_LightEnable
,
3949 (void *)NineDevice9_GetLightEnable
,
3950 (void *)NineDevice9_SetClipPlane
,
3951 (void *)NineDevice9_GetClipPlane
,
3952 (void *)NineDevice9_SetRenderState
,
3953 (void *)NineDevice9_GetRenderState
,
3954 (void *)NineDevice9_CreateStateBlock
,
3955 (void *)NineDevice9_BeginStateBlock
,
3956 (void *)NineDevice9_EndStateBlock
,
3957 (void *)NineDevice9_SetClipStatus
,
3958 (void *)NineDevice9_GetClipStatus
,
3959 (void *)NineDevice9_GetTexture
,
3960 (void *)NineDevice9_SetTexture
,
3961 (void *)NineDevice9_GetTextureStageState
,
3962 (void *)NineDevice9_SetTextureStageState
,
3963 (void *)NineDevice9_GetSamplerState
,
3964 (void *)NineDevice9_SetSamplerState
,
3965 (void *)NineDevice9_ValidateDevice
,
3966 (void *)NineDevice9_SetPaletteEntries
,
3967 (void *)NineDevice9_GetPaletteEntries
,
3968 (void *)NineDevice9_SetCurrentTexturePalette
,
3969 (void *)NineDevice9_GetCurrentTexturePalette
,
3970 (void *)NineDevice9_SetScissorRect
,
3971 (void *)NineDevice9_GetScissorRect
,
3972 (void *)NineDevice9_SetSoftwareVertexProcessing
,
3973 (void *)NineDevice9_GetSoftwareVertexProcessing
,
3974 (void *)NineDevice9_SetNPatchMode
,
3975 (void *)NineDevice9_GetNPatchMode
,
3976 (void *)NineDevice9_DrawPrimitive
,
3977 (void *)NineDevice9_DrawIndexedPrimitive
,
3978 (void *)NineDevice9_DrawPrimitiveUP
,
3979 (void *)NineDevice9_DrawIndexedPrimitiveUP
,
3980 (void *)NineDevice9_ProcessVertices
,
3981 (void *)NineDevice9_CreateVertexDeclaration
,
3982 (void *)NineDevice9_SetVertexDeclaration
,
3983 (void *)NineDevice9_GetVertexDeclaration
,
3984 (void *)NineDevice9_SetFVF
,
3985 (void *)NineDevice9_GetFVF
,
3986 (void *)NineDevice9_CreateVertexShader
,
3987 (void *)NineDevice9_SetVertexShader
,
3988 (void *)NineDevice9_GetVertexShader
,
3989 (void *)NineDevice9_SetVertexShaderConstantF
,
3990 (void *)NineDevice9_GetVertexShaderConstantF
,
3991 (void *)NineDevice9_SetVertexShaderConstantI
,
3992 (void *)NineDevice9_GetVertexShaderConstantI
,
3993 (void *)NineDevice9_SetVertexShaderConstantB
,
3994 (void *)NineDevice9_GetVertexShaderConstantB
,
3995 (void *)NineDevice9_SetStreamSource
,
3996 (void *)NineDevice9_GetStreamSource
,
3997 (void *)NineDevice9_SetStreamSourceFreq
,
3998 (void *)NineDevice9_GetStreamSourceFreq
,
3999 (void *)NineDevice9_SetIndices
,
4000 (void *)NineDevice9_GetIndices
,
4001 (void *)NineDevice9_CreatePixelShader
,
4002 (void *)NineDevice9_SetPixelShader
,
4003 (void *)NineDevice9_GetPixelShader
,
4004 (void *)NineDevice9_SetPixelShaderConstantF
,
4005 (void *)NineDevice9_GetPixelShaderConstantF
,
4006 (void *)NineDevice9_SetPixelShaderConstantI
,
4007 (void *)NineDevice9_GetPixelShaderConstantI
,
4008 (void *)NineDevice9_SetPixelShaderConstantB
,
4009 (void *)NineDevice9_GetPixelShaderConstantB
,
4010 (void *)NineDevice9_DrawRectPatch
,
4011 (void *)NineDevice9_DrawTriPatch
,
4012 (void *)NineDevice9_DeletePatch
,
4013 (void *)NineDevice9_CreateQuery
4016 static const GUID
*NineDevice9_IIDs
[] = {
4017 &IID_IDirect3DDevice9
,
4023 NineDevice9_new( struct pipe_screen
*pScreen
,
4024 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
4026 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
4028 ID3DPresentGroup
*pPresentationGroup
,
4029 struct d3dadapter9_context
*pCTX
,
4031 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
4032 struct NineDevice9
**ppOut
,
4033 int minorVersionNum
)
4036 lock
= !!(pCreationParameters
->BehaviorFlags
& D3DCREATE_MULTITHREADED
);
4038 NINE_NEW(Device9
, ppOut
, lock
, /* args */
4039 pScreen
, pCreationParameters
, pCaps
,
4040 pPresentationParameters
, pD3D9
, pPresentationGroup
, pCTX
,
4041 ex
, pFullscreenDisplayMode
, minorVersionNum
);