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 /* TODO: check if swvp is resetted by device Resets */
178 if (This
->may_swvp
&&
179 (This
->screen
->get_shader_param(This
->screen
, PIPE_SHADER_VERTEX
,
180 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
)
181 < (NINE_MAX_CONST_F_SWVP
/2) * sizeof(float[4]) ||
182 This
->screen
->get_shader_param(This
->screen
, PIPE_SHADER_VERTEX
,
183 PIPE_SHADER_CAP_MAX_CONST_BUFFERS
) < 5)) {
184 /* Note: We just go on, some apps never use the abilities of
185 * swvp, and just set more constants than allowed at init.
186 * Only cards we support that are affected are the r500 */
187 WARN("Card unable to handle Software Vertex Processing. Game may fail\n");
190 /* When may_swvp, SetConstant* limits are different */
192 This
->caps
.MaxVertexShaderConst
= NINE_MAX_CONST_F_SWVP
;
194 This
->pipe
= This
->screen
->context_create(This
->screen
, NULL
, 0);
195 if (!This
->pipe
) { return E_OUTOFMEMORY
; } /* guess */
196 This
->pipe_sw
= This
->screen_sw
->context_create(This
->screen_sw
, NULL
, 0);
197 if (!This
->pipe_sw
) { return E_OUTOFMEMORY
; }
199 This
->cso
= cso_create_context(This
->pipe
);
200 if (!This
->cso
) { return E_OUTOFMEMORY
; } /* also a guess */
201 This
->cso_sw
= cso_create_context(This
->pipe_sw
);
202 if (!This
->cso_sw
) { return E_OUTOFMEMORY
; }
204 /* Create first, it messes up our state. */
205 This
->hud
= hud_create(This
->pipe
, This
->cso
); /* NULL result is fine */
207 /* Available memory counter. Updated only for allocations with this device
208 * instance. This is the Win 7 behavior.
209 * Win XP shares this counter across multiple devices. */
210 This
->available_texture_mem
= This
->screen
->get_param(This
->screen
, PIPE_CAP_VIDEO_MEMORY
);
211 if (This
->available_texture_mem
< 4096)
212 This
->available_texture_mem
<<= 20;
214 This
->available_texture_mem
= UINT_MAX
;
215 /* We cap texture memory usage to 80% of what is reported free initially
216 * This helps get closer Win behaviour. For example VertexBuffer allocation
217 * still succeeds when texture allocation fails. */
218 This
->available_texture_limit
= This
->available_texture_mem
* 20LL / 100LL;
220 /* create implicit swapchains */
221 This
->nswapchains
= ID3DPresentGroup_GetMultiheadCount(This
->present
);
222 This
->swapchains
= CALLOC(This
->nswapchains
,
223 sizeof(struct NineSwapChain9
*));
224 if (!This
->swapchains
) { return E_OUTOFMEMORY
; }
226 for (i
= 0; i
< This
->nswapchains
; ++i
) {
227 ID3DPresent
*present
;
229 hr
= ID3DPresentGroup_GetPresent(This
->present
, i
, &present
);
234 D3DDISPLAYMODEEX
*mode
= NULL
;
235 struct NineSwapChain9Ex
**ret
=
236 (struct NineSwapChain9Ex
**)&This
->swapchains
[i
];
238 if (pFullscreenDisplayMode
) mode
= &(pFullscreenDisplayMode
[i
]);
239 /* when this is a Device9Ex, it should create SwapChain9Exs */
240 hr
= NineSwapChain9Ex_new(This
, TRUE
, present
,
241 &pPresentationParameters
[i
], pCTX
,
242 This
->params
.hFocusWindow
, mode
, ret
);
244 hr
= NineSwapChain9_new(This
, TRUE
, present
,
245 &pPresentationParameters
[i
], pCTX
,
246 This
->params
.hFocusWindow
,
247 &This
->swapchains
[i
]);
250 ID3DPresent_Release(present
);
253 NineUnknown_ConvertRefToBind(NineUnknown(This
->swapchains
[i
]));
255 hr
= NineSwapChain9_GetBackBuffer(This
->swapchains
[i
], 0,
256 D3DBACKBUFFER_TYPE_MONO
,
257 (IDirect3DSurface9
**)
261 NineUnknown_ConvertRefToBind(NineUnknown(This
->state
.rt
[i
]));
262 nine_bind(&This
->context
.rt
[i
], This
->state
.rt
[i
]);
265 /* Initialize a dummy VBO to be used when a vertex declaration does not
266 * specify all the inputs needed by vertex shader, on win default behavior
267 * is to pass 0,0,0,0 to the shader */
269 struct pipe_transfer
*transfer
;
270 struct pipe_resource tmpl
;
274 memset(&tmpl
, 0, sizeof(tmpl
));
275 tmpl
.target
= PIPE_BUFFER
;
276 tmpl
.format
= PIPE_FORMAT_R8_UNORM
;
277 tmpl
.width0
= 16; /* 4 floats */
283 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
284 tmpl
.bind
= PIPE_BIND_VERTEX_BUFFER
;
286 This
->dummy_vbo
= pScreen
->resource_create(pScreen
, &tmpl
);
288 if (!This
->dummy_vbo
)
289 return D3DERR_OUTOFVIDEOMEMORY
;
291 u_box_1d(0, 16, &box
);
292 data
= This
->pipe
->transfer_map(This
->pipe
, This
->dummy_vbo
, 0,
293 PIPE_TRANSFER_WRITE
|
294 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
299 This
->pipe
->transfer_unmap(This
->pipe
, transfer
);
302 This
->cursor
.software
= FALSE
;
303 This
->cursor
.hotspot
.x
= -1;
304 This
->cursor
.hotspot
.y
= -1;
306 struct pipe_resource tmpl
;
307 memset(&tmpl
, 0, sizeof(tmpl
));
308 tmpl
.target
= PIPE_TEXTURE_2D
;
309 tmpl
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
316 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
317 tmpl
.bind
= PIPE_BIND_CURSOR
| PIPE_BIND_SAMPLER_VIEW
;
320 This
->cursor
.image
= pScreen
->resource_create(pScreen
, &tmpl
);
321 if (!This
->cursor
.image
)
322 return D3DERR_OUTOFVIDEOMEMORY
;
324 /* For uploading 32x32 (argb) cursor */
325 This
->cursor
.hw_upload_temp
= MALLOC(32 * 4 * 32);
326 if (!This
->cursor
.hw_upload_temp
)
327 return D3DERR_OUTOFVIDEOMEMORY
;
330 /* Create constant buffers. */
332 unsigned max_const_vs
, max_const_ps
;
334 /* vs 3.0: >= 256 float constants, but for cards with exactly 256 slots,
335 * we have to take in some more slots for int and bool*/
336 max_const_vs
= _min(pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
,
337 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
) /
340 /* ps 3.0: 224 float constants. All cards supported support at least
341 * 256 constants for ps */
342 max_const_ps
= NINE_MAX_CONST_F_PS3
+ (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
344 This
->max_vs_const_f
= max_const_vs
-
345 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
346 This
->max_ps_const_f
= max_const_ps
-
347 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
349 This
->vs_const_size
= max_const_vs
* sizeof(float[4]);
350 This
->ps_const_size
= max_const_ps
* sizeof(float[4]);
351 /* Include space for I,B constants for user constbuf. */
352 if (This
->may_swvp
) {
353 This
->state
.vs_const_f
= CALLOC(NINE_MAX_CONST_F_SWVP
* sizeof(float[4]),1);
354 This
->context
.vs_const_f_swvp
= CALLOC(NINE_MAX_CONST_F_SWVP
* sizeof(float[4]),1);
355 if (!This
->context
.vs_const_f_swvp
)
356 return E_OUTOFMEMORY
;
357 This
->state
.vs_lconstf_temp
= CALLOC(NINE_MAX_CONST_F_SWVP
* sizeof(float[4]),1);
358 This
->context
.vs_lconstf_temp
= CALLOC(NINE_MAX_CONST_F_SWVP
* sizeof(float[4]),1);
359 This
->state
.vs_const_i
= CALLOC(NINE_MAX_CONST_I_SWVP
* sizeof(int[4]), 1);
360 This
->context
.vs_const_i
= CALLOC(NINE_MAX_CONST_I_SWVP
* sizeof(int[4]), 1);
361 This
->state
.vs_const_b
= CALLOC(NINE_MAX_CONST_B_SWVP
* sizeof(BOOL
), 1);
362 This
->context
.vs_const_b
= CALLOC(NINE_MAX_CONST_B_SWVP
* sizeof(BOOL
), 1);
364 This
->state
.vs_const_f
= CALLOC(NINE_MAX_CONST_F
* sizeof(float[4]), 1);
365 This
->context
.vs_const_f_swvp
= NULL
;
366 This
->state
.vs_lconstf_temp
= CALLOC(This
->vs_const_size
,1);
367 This
->context
.vs_lconstf_temp
= CALLOC(This
->vs_const_size
,1);
368 This
->state
.vs_const_i
= CALLOC(NINE_MAX_CONST_I
* sizeof(int[4]), 1);
369 This
->context
.vs_const_i
= CALLOC(NINE_MAX_CONST_I
* sizeof(int[4]), 1);
370 This
->state
.vs_const_b
= CALLOC(NINE_MAX_CONST_B
* sizeof(BOOL
), 1);
371 This
->context
.vs_const_b
= CALLOC(NINE_MAX_CONST_B
* sizeof(BOOL
), 1);
373 This
->context
.vs_const_f
= CALLOC(This
->vs_const_size
, 1);
374 This
->state
.ps_const_f
= CALLOC(This
->ps_const_size
, 1);
375 This
->context
.ps_const_f
= CALLOC(This
->ps_const_size
, 1);
376 This
->context
.ps_lconstf_temp
= CALLOC(This
->ps_const_size
,1);
377 if (!This
->state
.vs_const_f
|| !This
->context
.vs_const_f
||
378 !This
->state
.ps_const_f
|| !This
->context
.ps_const_f
||
379 !This
->state
.vs_lconstf_temp
|| !This
->context
.vs_lconstf_temp
||
380 !This
->context
.ps_lconstf_temp
||
381 !This
->state
.vs_const_i
|| !This
->context
.vs_const_i
||
382 !This
->state
.vs_const_b
|| !This
->context
.vs_const_b
)
383 return E_OUTOFMEMORY
;
385 if (strstr(pScreen
->get_name(pScreen
), "AMD") ||
386 strstr(pScreen
->get_name(pScreen
), "ATI")) {
387 This
->driver_bugs
.buggy_barycentrics
= TRUE
;
391 /* allocate dummy texture/sampler for when there are missing ones bound */
393 struct pipe_resource tmplt
;
394 struct pipe_sampler_view templ
;
395 struct pipe_sampler_state samp
;
396 memset(&tmplt
, 0, sizeof(tmplt
));
397 memset(&samp
, 0, sizeof(samp
));
399 tmplt
.target
= PIPE_TEXTURE_2D
;
403 tmplt
.last_level
= 0;
404 tmplt
.array_size
= 1;
405 tmplt
.usage
= PIPE_USAGE_DEFAULT
;
407 tmplt
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
408 tmplt
.bind
= PIPE_BIND_SAMPLER_VIEW
;
409 tmplt
.nr_samples
= 0;
411 This
->dummy_texture
= This
->screen
->resource_create(This
->screen
, &tmplt
);
412 if (!This
->dummy_texture
)
413 return D3DERR_DRIVERINTERNALERROR
;
415 templ
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
416 templ
.u
.tex
.first_layer
= 0;
417 templ
.u
.tex
.last_layer
= 0;
418 templ
.u
.tex
.first_level
= 0;
419 templ
.u
.tex
.last_level
= 0;
420 templ
.swizzle_r
= PIPE_SWIZZLE_0
;
421 templ
.swizzle_g
= PIPE_SWIZZLE_0
;
422 templ
.swizzle_b
= PIPE_SWIZZLE_0
;
423 templ
.swizzle_a
= PIPE_SWIZZLE_1
;
424 templ
.target
= This
->dummy_texture
->target
;
426 This
->dummy_sampler_view
= This
->pipe
->create_sampler_view(This
->pipe
, This
->dummy_texture
, &templ
);
427 if (!This
->dummy_sampler_view
)
428 return D3DERR_DRIVERINTERNALERROR
;
430 samp
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
431 samp
.max_lod
= 15.0f
;
432 samp
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
433 samp
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
434 samp
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
435 samp
.min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
436 samp
.mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
437 samp
.compare_mode
= PIPE_TEX_COMPARE_NONE
;
438 samp
.compare_func
= PIPE_FUNC_LEQUAL
;
439 samp
.normalized_coords
= 1;
440 samp
.seamless_cube_map
= 0;
441 This
->dummy_sampler_state
= samp
;
444 /* Allocate upload helper for drivers that suck (from st pov ;). */
446 This
->driver_caps
.user_vbufs
= GET_PCAP(USER_VERTEX_BUFFERS
);
447 This
->driver_caps
.user_ibufs
= GET_PCAP(USER_INDEX_BUFFERS
);
448 This
->driver_caps
.user_cbufs
= GET_PCAP(USER_CONSTANT_BUFFERS
);
449 This
->driver_caps
.user_sw_vbufs
= This
->screen_sw
->get_param(This
->screen_sw
, PIPE_CAP_USER_VERTEX_BUFFERS
);
450 This
->driver_caps
.user_sw_cbufs
= This
->screen_sw
->get_param(This
->screen_sw
, PIPE_CAP_USER_CONSTANT_BUFFERS
);
452 if (!This
->driver_caps
.user_vbufs
)
453 This
->vertex_uploader
= u_upload_create(This
->pipe
, 65536,
454 PIPE_BIND_VERTEX_BUFFER
, PIPE_USAGE_STREAM
);
455 This
->vertex_sw_uploader
= u_upload_create(This
->pipe_sw
, 65536,
456 PIPE_BIND_VERTEX_BUFFER
, PIPE_USAGE_STREAM
);
457 if (!This
->driver_caps
.user_ibufs
)
458 This
->index_uploader
= u_upload_create(This
->pipe
, 128 * 1024,
459 PIPE_BIND_INDEX_BUFFER
, PIPE_USAGE_STREAM
);
460 if (!This
->driver_caps
.user_cbufs
) {
461 This
->constbuf_alignment
= GET_PCAP(CONSTANT_BUFFER_OFFSET_ALIGNMENT
);
462 This
->constbuf_uploader
= u_upload_create(This
->pipe
, This
->vs_const_size
,
463 PIPE_BIND_CONSTANT_BUFFER
, PIPE_USAGE_STREAM
);
466 This
->constbuf_sw_uploader
= u_upload_create(This
->pipe_sw
, 128 * 1024,
467 PIPE_BIND_CONSTANT_BUFFER
, PIPE_USAGE_STREAM
);
469 This
->driver_caps
.window_space_position_support
= GET_PCAP(TGSI_VS_WINDOW_SPACE_POSITION
);
470 This
->driver_caps
.vs_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
, PIPE_SHADER_CAP_INTEGERS
);
471 This
->driver_caps
.ps_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_FRAGMENT
, PIPE_SHADER_CAP_INTEGERS
);
472 This
->driver_caps
.offset_units_unscaled
= GET_PCAP(POLYGON_OFFSET_UNITS_UNSCALED
);
474 nine_ff_init(This
); /* initialize fixed function code */
476 NineDevice9_SetDefaultState(This
, FALSE
);
479 struct pipe_poly_stipple stipple
;
480 memset(&stipple
, ~0, sizeof(stipple
));
481 This
->pipe
->set_polygon_stipple(This
->pipe
, &stipple
);
484 This
->update
= &This
->state
;
486 nine_state_init_sw(This
);
488 ID3DPresentGroup_Release(This
->present
);
495 NineDevice9_dtor( struct NineDevice9
*This
)
499 DBG("This=%p\n", This
);
501 if (This
->pipe
&& This
->cso
)
502 nine_pipe_context_clear(This
);
504 nine_state_destroy_sw(This
);
505 nine_state_clear(&This
->state
, TRUE
);
506 nine_context_clear(&This
->context
);
508 if (This
->vertex_uploader
)
509 u_upload_destroy(This
->vertex_uploader
);
510 if (This
->index_uploader
)
511 u_upload_destroy(This
->index_uploader
);
512 if (This
->constbuf_uploader
)
513 u_upload_destroy(This
->constbuf_uploader
);
514 if (This
->vertex_sw_uploader
)
515 u_upload_destroy(This
->vertex_sw_uploader
);
516 if (This
->constbuf_sw_uploader
)
517 u_upload_destroy(This
->constbuf_sw_uploader
);
519 nine_bind(&This
->record
, NULL
);
521 pipe_sampler_view_reference(&This
->dummy_sampler_view
, NULL
);
522 pipe_resource_reference(&This
->dummy_texture
, NULL
);
523 pipe_resource_reference(&This
->dummy_vbo
, NULL
);
524 FREE(This
->state
.vs_const_f
);
525 FREE(This
->context
.vs_const_f
);
526 FREE(This
->state
.ps_const_f
);
527 FREE(This
->context
.ps_const_f
);
528 FREE(This
->state
.vs_lconstf_temp
);
529 FREE(This
->context
.vs_lconstf_temp
);
530 FREE(This
->context
.ps_lconstf_temp
);
531 FREE(This
->state
.vs_const_i
);
532 FREE(This
->context
.vs_const_i
);
533 FREE(This
->state
.vs_const_b
);
534 FREE(This
->context
.vs_const_b
);
535 FREE(This
->context
.vs_const_f_swvp
);
537 pipe_resource_reference(&This
->cursor
.image
, NULL
);
538 FREE(This
->cursor
.hw_upload_temp
);
540 if (This
->swapchains
) {
541 for (i
= 0; i
< This
->nswapchains
; ++i
)
542 if (This
->swapchains
[i
])
543 NineUnknown_Unbind(NineUnknown(This
->swapchains
[i
]));
544 FREE(This
->swapchains
);
547 /* Destroy cso first */
548 if (This
->cso
) { cso_destroy_context(This
->cso
); }
549 if (This
->cso_sw
) { cso_destroy_context(This
->cso_sw
); }
550 if (This
->pipe
&& This
->pipe
->destroy
) { This
->pipe
->destroy(This
->pipe
); }
551 if (This
->pipe_sw
&& This
->pipe_sw
->destroy
) { This
->pipe_sw
->destroy(This
->pipe_sw
); }
553 if (This
->present
) { ID3DPresentGroup_Release(This
->present
); }
554 if (This
->d3d9
) { IDirect3D9_Release(This
->d3d9
); }
556 NineUnknown_dtor(&This
->base
);
560 NineDevice9_GetScreen( struct NineDevice9
*This
)
565 struct pipe_context
*
566 NineDevice9_GetPipe( struct NineDevice9
*This
)
572 NineDevice9_GetCaps( struct NineDevice9
*This
)
578 NineDevice9_PauseRecording( struct NineDevice9
*This
)
581 This
->update
= &This
->state
;
582 This
->is_recording
= FALSE
;
587 NineDevice9_ResumeRecording( struct NineDevice9
*This
)
590 This
->update
= &This
->record
->state
;
591 This
->is_recording
= TRUE
;
596 NineDevice9_TestCooperativeLevel( struct NineDevice9
*This
)
598 if (NineSwapChain9_GetOccluded(This
->swapchains
[0])) {
599 This
->device_needs_reset
= TRUE
;
600 return D3DERR_DEVICELOST
;
601 } else if (NineSwapChain9_ResolutionMismatch(This
->swapchains
[0])) {
602 This
->device_needs_reset
= TRUE
;
603 return D3DERR_DEVICENOTRESET
;
604 } else if (This
->device_needs_reset
) {
605 return D3DERR_DEVICENOTRESET
;
612 NineDevice9_GetAvailableTextureMem( struct NineDevice9
*This
)
614 return This
->available_texture_mem
;
618 NineDevice9_EvictManagedResources( struct NineDevice9
*This
)
620 struct NineBaseTexture9
*tex
;
621 struct NineBuffer9
*buf
;
623 DBG("This=%p\n", This
);
624 LIST_FOR_EACH_ENTRY(tex
, &This
->managed_textures
, list2
) {
625 NineBaseTexture9_UnLoad(tex
);
627 /* Vertex/index buffers don't take a lot of space and aren't accounted
628 * for d3d memory usage. Instead of actually freeing from memory,
629 * just mark the buffer dirty to trigger a re-upload later. We
630 * could just ignore, but some bad behaving apps could rely on it (if
631 * they write outside the locked regions typically). */
632 LIST_FOR_EACH_ENTRY(buf
, &This
->managed_buffers
, managed
.list2
) {
633 NineBuffer9_SetDirty(buf
);
640 NineDevice9_GetDirect3D( struct NineDevice9
*This
,
641 IDirect3D9
**ppD3D9
)
643 user_assert(ppD3D9
!= NULL
, E_POINTER
);
644 IDirect3D9_AddRef(This
->d3d9
);
645 *ppD3D9
= This
->d3d9
;
650 NineDevice9_GetDeviceCaps( struct NineDevice9
*This
,
653 user_assert(pCaps
!= NULL
, D3DERR_INVALIDCALL
);
659 NineDevice9_GetDisplayMode( struct NineDevice9
*This
,
661 D3DDISPLAYMODE
*pMode
)
663 DBG("This=%p iSwapChain=%u pMode=%p\n", This
, iSwapChain
, pMode
);
665 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
667 return NineSwapChain9_GetDisplayMode(This
->swapchains
[iSwapChain
], pMode
);
671 NineDevice9_GetCreationParameters( struct NineDevice9
*This
,
672 D3DDEVICE_CREATION_PARAMETERS
*pParameters
)
674 user_assert(pParameters
!= NULL
, D3DERR_INVALIDCALL
);
675 *pParameters
= This
->params
;
680 NineDevice9_SetCursorProperties( struct NineDevice9
*This
,
683 IDirect3DSurface9
*pCursorBitmap
)
685 struct NineSurface9
*surf
= NineSurface9(pCursorBitmap
);
686 struct pipe_context
*pipe
= NineDevice9_GetPipe(This
);
688 struct pipe_transfer
*transfer
;
692 DBG_FLAG(DBG_SWAPCHAIN
, "This=%p XHotSpot=%u YHotSpot=%u "
693 "pCursorBitmap=%p\n", This
, XHotSpot
, YHotSpot
, pCursorBitmap
);
695 user_assert(pCursorBitmap
, D3DERR_INVALIDCALL
);
696 user_assert(surf
->desc
.Format
== D3DFMT_A8R8G8B8
, D3DERR_INVALIDCALL
);
698 if (This
->swapchains
[0]->params
.Windowed
) {
699 This
->cursor
.w
= MIN2(surf
->desc
.Width
, 32);
700 This
->cursor
.h
= MIN2(surf
->desc
.Height
, 32);
701 hw_cursor
= 1; /* always use hw cursor for windowed mode */
703 This
->cursor
.w
= MIN2(surf
->desc
.Width
, This
->cursor
.image
->width0
);
704 This
->cursor
.h
= MIN2(surf
->desc
.Height
, This
->cursor
.image
->height0
);
705 hw_cursor
= This
->cursor
.w
== 32 && This
->cursor
.h
== 32;
708 u_box_origin_2d(This
->cursor
.w
, This
->cursor
.h
, &box
);
710 ptr
= pipe
->transfer_map(pipe
, This
->cursor
.image
, 0,
711 PIPE_TRANSFER_WRITE
|
712 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
715 ret_err("Failed to update cursor image.\n", D3DERR_DRIVERINTERNALERROR
);
717 This
->cursor
.hotspot
.x
= XHotSpot
;
718 This
->cursor
.hotspot
.y
= YHotSpot
;
720 /* Copy cursor image to internal storage. */
724 const struct util_format_description
*sfmt
=
725 util_format_description(surf
->base
.info
.format
);
728 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, D3DLOCK_READONLY
);
730 ret_err("Failed to map cursor source image.\n",
731 D3DERR_DRIVERINTERNALERROR
);
733 sfmt
->unpack_rgba_8unorm(ptr
, transfer
->stride
,
734 lock
.pBits
, lock
.Pitch
,
735 This
->cursor
.w
, This
->cursor
.h
);
738 void *data
= lock
.pBits
;
739 /* SetCursor assumes 32x32 argb with pitch 128 */
740 if (lock
.Pitch
!= 128) {
741 sfmt
->unpack_rgba_8unorm(This
->cursor
.hw_upload_temp
, 128,
742 lock
.pBits
, lock
.Pitch
,
744 data
= This
->cursor
.hw_upload_temp
;
746 hw_cursor
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
,
748 &This
->cursor
.hotspot
,
749 This
->cursor
.visible
) == D3D_OK
;
752 NineSurface9_UnlockRect(surf
);
754 pipe
->transfer_unmap(pipe
, transfer
);
756 /* hide cursor if we emulate it */
758 ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, FALSE
);
759 This
->cursor
.software
= !hw_cursor
;
765 NineDevice9_SetCursorPosition( struct NineDevice9
*This
,
770 struct NineSwapChain9
*swap
= This
->swapchains
[0];
772 DBG("This=%p X=%d Y=%d Flags=%d\n", This
, X
, Y
, Flags
);
774 This
->cursor
.pos
.x
= X
;
775 This
->cursor
.pos
.y
= Y
;
777 if (!This
->cursor
.software
)
778 This
->cursor
.software
= ID3DPresent_SetCursorPos(swap
->present
, &This
->cursor
.pos
) != D3D_OK
;
782 NineDevice9_ShowCursor( struct NineDevice9
*This
,
785 BOOL old
= This
->cursor
.visible
;
787 DBG("This=%p bShow=%d\n", This
, (int) bShow
);
789 This
->cursor
.visible
= bShow
&& (This
->cursor
.hotspot
.x
!= -1);
790 if (!This
->cursor
.software
)
791 This
->cursor
.software
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, bShow
) != D3D_OK
;
797 NineDevice9_CreateAdditionalSwapChain( struct NineDevice9
*This
,
798 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
799 IDirect3DSwapChain9
**pSwapChain
)
801 struct NineSwapChain9
*swapchain
, *tmplt
= This
->swapchains
[0];
802 ID3DPresent
*present
;
805 DBG("This=%p pPresentationParameters=%p pSwapChain=%p\n",
806 This
, pPresentationParameters
, pSwapChain
);
808 user_assert(pPresentationParameters
, D3DERR_INVALIDCALL
);
809 user_assert(tmplt
->params
.Windowed
&& pPresentationParameters
->Windowed
, D3DERR_INVALIDCALL
);
811 /* TODO: this deserves more tests */
812 if (!pPresentationParameters
->hDeviceWindow
)
813 pPresentationParameters
->hDeviceWindow
= This
->params
.hFocusWindow
;
815 hr
= ID3DPresentGroup_CreateAdditionalPresent(This
->present
, pPresentationParameters
, &present
);
820 hr
= NineSwapChain9_new(This
, FALSE
, present
, pPresentationParameters
,
822 tmplt
->params
.hDeviceWindow
,
827 *pSwapChain
= (IDirect3DSwapChain9
*)swapchain
;
832 NineDevice9_GetSwapChain( struct NineDevice9
*This
,
834 IDirect3DSwapChain9
**pSwapChain
)
836 user_assert(pSwapChain
!= NULL
, D3DERR_INVALIDCALL
);
839 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
841 NineUnknown_AddRef(NineUnknown(This
->swapchains
[iSwapChain
]));
842 *pSwapChain
= (IDirect3DSwapChain9
*)This
->swapchains
[iSwapChain
];
848 NineDevice9_GetNumberOfSwapChains( struct NineDevice9
*This
)
850 return This
->nswapchains
;
854 NineDevice9_Reset( struct NineDevice9
*This
,
855 D3DPRESENT_PARAMETERS
*pPresentationParameters
)
860 DBG("This=%p pPresentationParameters=%p\n", This
, pPresentationParameters
);
862 if (NineSwapChain9_GetOccluded(This
->swapchains
[0])) {
863 This
->device_needs_reset
= TRUE
;
864 return D3DERR_DEVICELOST
;
867 for (i
= 0; i
< This
->nswapchains
; ++i
) {
868 D3DPRESENT_PARAMETERS
*params
= &pPresentationParameters
[i
];
869 hr
= NineSwapChain9_Resize(This
->swapchains
[i
], params
, NULL
);
874 nine_pipe_context_clear(This
);
875 nine_state_clear(&This
->state
, TRUE
);
876 nine_context_clear(&This
->context
);
878 NineDevice9_SetDefaultState(This
, TRUE
);
879 NineDevice9_SetRenderTarget(
880 This
, 0, (IDirect3DSurface9
*)This
->swapchains
[0]->buffers
[0]);
881 /* XXX: better use GetBackBuffer here ? */
883 This
->device_needs_reset
= (hr
!= D3D_OK
);
888 NineDevice9_Present( struct NineDevice9
*This
,
889 const RECT
*pSourceRect
,
890 const RECT
*pDestRect
,
891 HWND hDestWindowOverride
,
892 const RGNDATA
*pDirtyRegion
)
897 DBG("This=%p pSourceRect=%p pDestRect=%p hDestWindowOverride=%p pDirtyRegion=%p\n",
898 This
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
900 /* XXX is this right? */
901 for (i
= 0; i
< This
->nswapchains
; ++i
) {
902 hr
= NineSwapChain9_Present(This
->swapchains
[i
], pSourceRect
, pDestRect
,
903 hDestWindowOverride
, pDirtyRegion
, 0);
904 if (FAILED(hr
)) { return hr
; }
911 NineDevice9_GetBackBuffer( struct NineDevice9
*This
,
914 D3DBACKBUFFER_TYPE Type
,
915 IDirect3DSurface9
**ppBackBuffer
)
917 user_assert(ppBackBuffer
!= NULL
, D3DERR_INVALIDCALL
);
918 /* return NULL on error */
919 *ppBackBuffer
= NULL
;
920 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
922 return NineSwapChain9_GetBackBuffer(This
->swapchains
[iSwapChain
],
923 iBackBuffer
, Type
, ppBackBuffer
);
927 NineDevice9_GetRasterStatus( struct NineDevice9
*This
,
929 D3DRASTER_STATUS
*pRasterStatus
)
931 user_assert(pRasterStatus
!= NULL
, D3DERR_INVALIDCALL
);
932 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
934 return NineSwapChain9_GetRasterStatus(This
->swapchains
[iSwapChain
],
939 NineDevice9_SetDialogBoxMode( struct NineDevice9
*This
,
940 BOOL bEnableDialogs
)
942 STUB(D3DERR_INVALIDCALL
);
946 NineDevice9_SetGammaRamp( struct NineDevice9
*This
,
949 const D3DGAMMARAMP
*pRamp
)
951 DBG("This=%p iSwapChain=%u Flags=%x pRamp=%p\n", This
,
952 iSwapChain
, Flags
, pRamp
);
954 user_warn(iSwapChain
>= This
->nswapchains
);
957 if (pRamp
&& (iSwapChain
< This
->nswapchains
)) {
958 struct NineSwapChain9
*swap
= This
->swapchains
[iSwapChain
];
959 swap
->gamma
= *pRamp
;
960 ID3DPresent_SetGammaRamp(swap
->present
, pRamp
, swap
->params
.hDeviceWindow
);
965 NineDevice9_GetGammaRamp( struct NineDevice9
*This
,
967 D3DGAMMARAMP
*pRamp
)
969 DBG("This=%p iSwapChain=%u pRamp=%p\n", This
, iSwapChain
, pRamp
);
971 user_warn(iSwapChain
>= This
->nswapchains
);
974 if (pRamp
&& (iSwapChain
< This
->nswapchains
))
975 *pRamp
= This
->swapchains
[iSwapChain
]->gamma
;
979 NineDevice9_CreateTexture( struct NineDevice9
*This
,
986 IDirect3DTexture9
**ppTexture
,
987 HANDLE
*pSharedHandle
)
989 struct NineTexture9
*tex
;
992 DBG("This=%p Width=%u Height=%u Levels=%u Usage=%s Format=%s Pool=%s "
993 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Levels
,
994 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
995 nine_D3DPOOL_to_str(Pool
), ppTexture
, pSharedHandle
);
997 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DMAP
|
998 D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
999 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
;
1003 hr
= NineTexture9_new(This
, Width
, Height
, Levels
, Usage
, Format
, Pool
,
1004 &tex
, pSharedHandle
);
1006 *ppTexture
= (IDirect3DTexture9
*)tex
;
1012 NineDevice9_CreateVolumeTexture( struct NineDevice9
*This
,
1020 IDirect3DVolumeTexture9
**ppVolumeTexture
,
1021 HANDLE
*pSharedHandle
)
1023 struct NineVolumeTexture9
*tex
;
1026 DBG("This=%p Width=%u Height=%u Depth=%u Levels=%u Usage=%s Format=%s Pool=%s "
1027 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Depth
, Levels
,
1028 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
1029 nine_D3DPOOL_to_str(Pool
), ppVolumeTexture
, pSharedHandle
);
1031 Usage
&= D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1032 D3DUSAGE_SOFTWAREPROCESSING
;
1034 *ppVolumeTexture
= NULL
;
1036 hr
= NineVolumeTexture9_new(This
, Width
, Height
, Depth
, Levels
,
1037 Usage
, Format
, Pool
, &tex
, pSharedHandle
);
1039 *ppVolumeTexture
= (IDirect3DVolumeTexture9
*)tex
;
1045 NineDevice9_CreateCubeTexture( struct NineDevice9
*This
,
1051 IDirect3DCubeTexture9
**ppCubeTexture
,
1052 HANDLE
*pSharedHandle
)
1054 struct NineCubeTexture9
*tex
;
1057 DBG("This=%p EdgeLength=%u Levels=%u Usage=%s Format=%s Pool=%s ppOut=%p "
1058 "pSharedHandle=%p\n", This
, EdgeLength
, Levels
,
1059 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
1060 nine_D3DPOOL_to_str(Pool
), ppCubeTexture
, pSharedHandle
);
1062 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DYNAMIC
|
1063 D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
1064 D3DUSAGE_SOFTWAREPROCESSING
;
1066 *ppCubeTexture
= NULL
;
1068 hr
= NineCubeTexture9_new(This
, EdgeLength
, Levels
, Usage
, Format
, Pool
,
1069 &tex
, pSharedHandle
);
1071 *ppCubeTexture
= (IDirect3DCubeTexture9
*)tex
;
1077 NineDevice9_CreateVertexBuffer( struct NineDevice9
*This
,
1082 IDirect3DVertexBuffer9
**ppVertexBuffer
,
1083 HANDLE
*pSharedHandle
)
1085 struct NineVertexBuffer9
*buf
;
1087 D3DVERTEXBUFFER_DESC desc
;
1089 DBG("This=%p Length=%u Usage=%x FVF=%x Pool=%u ppOut=%p pSharedHandle=%p\n",
1090 This
, Length
, Usage
, FVF
, Pool
, ppVertexBuffer
, pSharedHandle
);
1092 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1094 desc
.Format
= D3DFMT_VERTEXDATA
;
1095 desc
.Type
= D3DRTYPE_VERTEXBUFFER
;
1096 desc
.Usage
= Usage
&
1097 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1098 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1099 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
|
1100 D3DUSAGE_WRITEONLY
);
1105 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1106 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1108 hr
= NineVertexBuffer9_new(This
, &desc
, &buf
);
1110 *ppVertexBuffer
= (IDirect3DVertexBuffer9
*)buf
;
1115 NineDevice9_CreateIndexBuffer( struct NineDevice9
*This
,
1120 IDirect3DIndexBuffer9
**ppIndexBuffer
,
1121 HANDLE
*pSharedHandle
)
1123 struct NineIndexBuffer9
*buf
;
1125 D3DINDEXBUFFER_DESC desc
;
1127 DBG("This=%p Length=%u Usage=%x Format=%s Pool=%u ppOut=%p "
1128 "pSharedHandle=%p\n", This
, Length
, Usage
,
1129 d3dformat_to_string(Format
), Pool
, ppIndexBuffer
, pSharedHandle
);
1131 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1133 desc
.Format
= Format
;
1134 desc
.Type
= D3DRTYPE_INDEXBUFFER
;
1135 desc
.Usage
= Usage
&
1136 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1137 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1138 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_WRITEONLY
);
1142 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1143 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1145 hr
= NineIndexBuffer9_new(This
, &desc
, &buf
);
1147 *ppIndexBuffer
= (IDirect3DIndexBuffer9
*)buf
;
1152 create_zs_or_rt_surface(struct NineDevice9
*This
,
1153 unsigned type
, /* 0 = RT, 1 = ZS, 2 = plain */
1155 UINT Width
, UINT Height
,
1157 D3DMULTISAMPLE_TYPE MultiSample
,
1158 DWORD MultisampleQuality
,
1159 BOOL Discard_or_Lockable
,
1160 IDirect3DSurface9
**ppSurface
,
1161 HANDLE
*pSharedHandle
)
1163 struct NineSurface9
*surface
;
1165 D3DSURFACE_DESC desc
;
1167 DBG("This=%p type=%u Pool=%s Width=%u Height=%u Format=%s MS=%u Quality=%u "
1168 "Discard_or_Lockable=%i ppSurface=%p pSharedHandle=%p\n",
1169 This
, type
, nine_D3DPOOL_to_str(Pool
), Width
, Height
,
1170 d3dformat_to_string(Format
), MultiSample
, MultisampleQuality
,
1171 Discard_or_Lockable
, ppSurface
, pSharedHandle
);
1174 DBG("FIXME Used shared handle! This option isn't probably handled correctly!\n");
1176 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
1177 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1179 desc
.Format
= Format
;
1180 desc
.Type
= D3DRTYPE_SURFACE
;
1183 desc
.MultiSampleType
= MultiSample
;
1184 desc
.MultiSampleQuality
= MultisampleQuality
;
1186 desc
.Height
= Height
;
1188 case 0: desc
.Usage
= D3DUSAGE_RENDERTARGET
; break;
1189 case 1: desc
.Usage
= D3DUSAGE_DEPTHSTENCIL
; break;
1190 default: assert(type
== 2); break;
1193 hr
= NineSurface9_new(This
, NULL
, NULL
, NULL
, 0, 0, 0, &desc
, &surface
);
1194 if (SUCCEEDED(hr
)) {
1195 *ppSurface
= (IDirect3DSurface9
*)surface
;
1197 if (surface
->base
.resource
&& Discard_or_Lockable
&& (type
!= 1))
1198 surface
->base
.resource
->flags
|= NINE_RESOURCE_FLAG_LOCKABLE
;
1205 NineDevice9_CreateRenderTarget( struct NineDevice9
*This
,
1209 D3DMULTISAMPLE_TYPE MultiSample
,
1210 DWORD MultisampleQuality
,
1212 IDirect3DSurface9
**ppSurface
,
1213 HANDLE
*pSharedHandle
)
1216 return create_zs_or_rt_surface(This
, 0, D3DPOOL_DEFAULT
,
1217 Width
, Height
, Format
,
1218 MultiSample
, MultisampleQuality
,
1219 Lockable
, ppSurface
, pSharedHandle
);
1223 NineDevice9_CreateDepthStencilSurface( struct NineDevice9
*This
,
1227 D3DMULTISAMPLE_TYPE MultiSample
,
1228 DWORD MultisampleQuality
,
1230 IDirect3DSurface9
**ppSurface
,
1231 HANDLE
*pSharedHandle
)
1234 if (!depth_stencil_format(Format
))
1235 return D3DERR_NOTAVAILABLE
;
1236 return create_zs_or_rt_surface(This
, 1, D3DPOOL_DEFAULT
,
1237 Width
, Height
, Format
,
1238 MultiSample
, MultisampleQuality
,
1239 Discard
, ppSurface
, pSharedHandle
);
1243 NineDevice9_UpdateSurface( struct NineDevice9
*This
,
1244 IDirect3DSurface9
*pSourceSurface
,
1245 const RECT
*pSourceRect
,
1246 IDirect3DSurface9
*pDestinationSurface
,
1247 const POINT
*pDestPoint
)
1249 struct NineSurface9
*dst
= NineSurface9(pDestinationSurface
);
1250 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1251 int copy_width
, copy_height
;
1254 DBG("This=%p pSourceSurface=%p pDestinationSurface=%p "
1255 "pSourceRect=%p pDestPoint=%p\n", This
,
1256 pSourceSurface
, pDestinationSurface
, pSourceRect
, pDestPoint
);
1258 DBG("pSourceRect = (%u,%u)-(%u,%u)\n",
1259 pSourceRect
->left
, pSourceRect
->top
,
1260 pSourceRect
->right
, pSourceRect
->bottom
);
1262 DBG("pDestPoint = (%u,%u)\n", pDestPoint
->x
, pDestPoint
->y
);
1264 user_assert(dst
&& src
, D3DERR_INVALIDCALL
);
1266 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1267 user_assert(src
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1269 user_assert(dst
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1270 user_assert(src
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1272 user_assert(!src
->lock_count
, D3DERR_INVALIDCALL
);
1273 user_assert(!dst
->lock_count
, D3DERR_INVALIDCALL
);
1275 user_assert(dst
->desc
.Format
== src
->desc
.Format
, D3DERR_INVALIDCALL
);
1276 user_assert(!depth_stencil_format(dst
->desc
.Format
), D3DERR_INVALIDCALL
);
1279 copy_width
= pSourceRect
->right
- pSourceRect
->left
;
1280 copy_height
= pSourceRect
->bottom
- pSourceRect
->top
;
1282 user_assert(pSourceRect
->left
>= 0 &&
1284 pSourceRect
->right
<= src
->desc
.Width
&&
1285 pSourceRect
->top
>= 0 &&
1287 pSourceRect
->bottom
<= src
->desc
.Height
,
1288 D3DERR_INVALIDCALL
);
1290 copy_width
= src
->desc
.Width
;
1291 copy_height
= src
->desc
.Height
;
1294 destRect
.right
= copy_width
;
1295 destRect
.bottom
= copy_height
;
1298 user_assert(pDestPoint
->x
>= 0 && pDestPoint
->y
>= 0,
1299 D3DERR_INVALIDCALL
);
1300 destRect
.right
+= pDestPoint
->x
;
1301 destRect
.bottom
+= pDestPoint
->y
;
1304 user_assert(destRect
.right
<= dst
->desc
.Width
&&
1305 destRect
.bottom
<= dst
->desc
.Height
,
1306 D3DERR_INVALIDCALL
);
1308 if (compressed_format(dst
->desc
.Format
)) {
1309 const unsigned w
= util_format_get_blockwidth(dst
->base
.info
.format
);
1310 const unsigned h
= util_format_get_blockheight(dst
->base
.info
.format
);
1313 user_assert(!(pDestPoint
->x
% w
) && !(pDestPoint
->y
% h
),
1314 D3DERR_INVALIDCALL
);
1318 user_assert(!(pSourceRect
->left
% w
) && !(pSourceRect
->top
% h
),
1319 D3DERR_INVALIDCALL
);
1321 if (!(copy_width
== src
->desc
.Width
&&
1322 copy_width
== dst
->desc
.Width
&&
1323 copy_height
== src
->desc
.Height
&&
1324 copy_height
== dst
->desc
.Height
)) {
1325 user_assert(!(copy_width
% w
) && !(copy_height
% h
),
1326 D3DERR_INVALIDCALL
);
1330 NineSurface9_CopyMemToDefault(dst
, src
, pDestPoint
, pSourceRect
);
1336 NineDevice9_UpdateTexture( struct NineDevice9
*This
,
1337 IDirect3DBaseTexture9
*pSourceTexture
,
1338 IDirect3DBaseTexture9
*pDestinationTexture
)
1340 struct NineBaseTexture9
*dstb
= NineBaseTexture9(pDestinationTexture
);
1341 struct NineBaseTexture9
*srcb
= NineBaseTexture9(pSourceTexture
);
1343 unsigned last_src_level
, last_dst_level
;
1346 DBG("This=%p pSourceTexture=%p pDestinationTexture=%p\n", This
,
1347 pSourceTexture
, pDestinationTexture
);
1349 user_assert(pSourceTexture
&& pDestinationTexture
, D3DERR_INVALIDCALL
);
1350 user_assert(pSourceTexture
!= pDestinationTexture
, D3DERR_INVALIDCALL
);
1352 user_assert(dstb
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1353 user_assert(srcb
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1354 user_assert(dstb
->base
.type
== srcb
->base
.type
, D3DERR_INVALIDCALL
);
1355 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ||
1356 dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
, D3DERR_INVALIDCALL
);
1359 * . Different formats
1360 * . Fewer src levels than dst levels (if the opposite, only matching levels
1361 * are supposed to be copied)
1362 * . Levels do not match
1363 * DDI: Actually the above should pass because of legacy applications
1364 * Do what you want about these, but you shouldn't crash.
1365 * However driver can expect that the top dimension is greater for src than dst.
1366 * Wine tests: Every combination that passes the initial checks should pass.
1367 * . Different formats => conversion driver and format dependent.
1368 * . 1 level, but size not matching => copy is done (and even crash if src bigger
1369 * than dst. For the case where dst bigger, wine doesn't test if a stretch is applied
1370 * or if a subrect is copied).
1371 * . 8x8 4 sublevels -> 7x7 2 sublevels => driver dependent, On NV seems to be 4x4 subrect
1374 * From these, the proposal is:
1375 * . Different formats -> use util_format_translate to translate if possible for surfaces.
1376 * Accept ARGB/XRGB for Volumes. Do nothing for the other combinations
1377 * . First level copied -> the first level such that src is smaller or equal to dst first level
1378 * . number of levels copied -> as long as it fits and textures have levels
1379 * That should satisfy the constraints (and instead of crashing for some cases we return D3D_OK)
1382 last_src_level
= (srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ? 0 : srcb
->base
.info
.last_level
;
1383 last_dst_level
= (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ? 0 : dstb
->base
.info
.last_level
;
1385 for (m
= 0; m
<= last_src_level
; ++m
) {
1386 unsigned w
= u_minify(srcb
->base
.info
.width0
, m
);
1387 unsigned h
= u_minify(srcb
->base
.info
.height0
, m
);
1388 unsigned d
= u_minify(srcb
->base
.info
.depth0
, m
);
1390 if (w
<= dstb
->base
.info
.width0
&&
1391 h
<= dstb
->base
.info
.height0
&&
1392 d
<= dstb
->base
.info
.depth0
)
1395 user_assert(m
<= last_src_level
, D3D_OK
);
1397 last_dst_level
= MIN2(srcb
->base
.info
.last_level
- m
, last_dst_level
);
1399 if (dstb
->base
.type
== D3DRTYPE_TEXTURE
) {
1400 struct NineTexture9
*dst
= NineTexture9(dstb
);
1401 struct NineTexture9
*src
= NineTexture9(srcb
);
1403 if (src
->dirty_rect
.width
== 0)
1406 pipe_box_to_rect(&rect
, &src
->dirty_rect
);
1407 for (l
= 0; l
< m
; ++l
)
1408 rect_minify_inclusive(&rect
);
1410 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
) {
1411 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1413 dst
->surfaces
[l
]->desc
.Width
,
1414 dst
->surfaces
[l
]->desc
.Height
);
1415 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
],
1419 rect_minify_inclusive(&rect
);
1421 u_box_origin_2d(0, 0, &src
->dirty_rect
);
1423 if (dstb
->base
.type
== D3DRTYPE_CUBETEXTURE
) {
1424 struct NineCubeTexture9
*dst
= NineCubeTexture9(dstb
);
1425 struct NineCubeTexture9
*src
= NineCubeTexture9(srcb
);
1428 /* GPUs usually have them stored as arrays of mip-mapped 2D textures. */
1429 for (z
= 0; z
< 6; ++z
) {
1430 if (src
->dirty_rect
[z
].width
== 0)
1433 pipe_box_to_rect(&rect
, &src
->dirty_rect
[z
]);
1434 for (l
= 0; l
< m
; ++l
)
1435 rect_minify_inclusive(&rect
);
1437 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
) {
1438 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1440 dst
->surfaces
[l
* 6 + z
]->desc
.Width
,
1441 dst
->surfaces
[l
* 6 + z
]->desc
.Height
);
1442 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
* 6 + z
],
1443 src
->surfaces
[m
* 6 + z
],
1446 rect_minify_inclusive(&rect
);
1448 u_box_origin_2d(0, 0, &src
->dirty_rect
[z
]);
1452 if (dstb
->base
.type
== D3DRTYPE_VOLUMETEXTURE
) {
1453 struct NineVolumeTexture9
*dst
= NineVolumeTexture9(dstb
);
1454 struct NineVolumeTexture9
*src
= NineVolumeTexture9(srcb
);
1456 if (src
->dirty_box
.width
== 0)
1458 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
)
1459 NineVolume9_CopyMemToDefault(dst
->volumes
[l
],
1460 src
->volumes
[m
], 0, 0, 0, NULL
);
1461 u_box_3d(0, 0, 0, 0, 0, 0, &src
->dirty_box
);
1463 assert(!"invalid texture type");
1466 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1467 dstb
->dirty_mip
= TRUE
;
1468 NineBaseTexture9_GenerateMipSubLevels(dstb
);
1475 NineDevice9_GetRenderTargetData( struct NineDevice9
*This
,
1476 IDirect3DSurface9
*pRenderTarget
,
1477 IDirect3DSurface9
*pDestSurface
)
1479 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1480 struct NineSurface9
*src
= NineSurface9(pRenderTarget
);
1482 DBG("This=%p pRenderTarget=%p pDestSurface=%p\n",
1483 This
, pRenderTarget
, pDestSurface
);
1485 user_assert(pRenderTarget
&& pDestSurface
, D3DERR_INVALIDCALL
);
1487 user_assert(dst
->desc
.Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1488 user_assert(src
->desc
.Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1490 user_assert(dst
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1491 user_assert(src
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1493 user_assert(src
->desc
.Width
== dst
->desc
.Width
, D3DERR_INVALIDCALL
);
1494 user_assert(src
->desc
.Height
== dst
->desc
.Height
, D3DERR_INVALIDCALL
);
1496 user_assert(src
->desc
.Format
!= D3DFMT_NULL
, D3DERR_INVALIDCALL
);
1498 NineSurface9_CopyDefaultToMem(dst
, src
);
1504 NineDevice9_GetFrontBufferData( struct NineDevice9
*This
,
1506 IDirect3DSurface9
*pDestSurface
)
1508 DBG("This=%p iSwapChain=%u pDestSurface=%p\n", This
,
1509 iSwapChain
, pDestSurface
);
1511 user_assert(pDestSurface
!= NULL
, D3DERR_INVALIDCALL
);
1512 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
1514 return NineSwapChain9_GetFrontBufferData(This
->swapchains
[iSwapChain
],
1519 NineDevice9_StretchRect( struct NineDevice9
*This
,
1520 IDirect3DSurface9
*pSourceSurface
,
1521 const RECT
*pSourceRect
,
1522 IDirect3DSurface9
*pDestSurface
,
1523 const RECT
*pDestRect
,
1524 D3DTEXTUREFILTERTYPE Filter
)
1526 struct pipe_screen
*screen
= This
->screen
;
1527 struct pipe_context
*pipe
= NineDevice9_GetPipe(This
);
1528 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1529 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1530 struct pipe_resource
*dst_res
= NineSurface9_GetResource(dst
);
1531 struct pipe_resource
*src_res
= NineSurface9_GetResource(src
);
1533 struct pipe_blit_info blit
;
1534 boolean scaled
, clamped
, ms
, flip_x
= FALSE
, flip_y
= FALSE
;
1536 DBG("This=%p pSourceSurface=%p pSourceRect=%p pDestSurface=%p "
1537 "pDestRect=%p Filter=%u\n",
1538 This
, pSourceSurface
, pSourceRect
, pDestSurface
, pDestRect
, Filter
);
1540 DBG("pSourceRect=(%u,%u)-(%u,%u)\n",
1541 pSourceRect
->left
, pSourceRect
->top
,
1542 pSourceRect
->right
, pSourceRect
->bottom
);
1544 DBG("pDestRect=(%u,%u)-(%u,%u)\n", pDestRect
->left
, pDestRect
->top
,
1545 pDestRect
->right
, pDestRect
->bottom
);
1547 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
&&
1548 src
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1549 zs
= util_format_is_depth_or_stencil(dst_res
->format
);
1550 user_assert(!zs
|| !This
->in_scene
, D3DERR_INVALIDCALL
);
1551 user_assert(!zs
|| !pSourceRect
||
1552 (pSourceRect
->left
== 0 &&
1553 pSourceRect
->top
== 0 &&
1554 pSourceRect
->right
== src
->desc
.Width
&&
1555 pSourceRect
->bottom
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1556 user_assert(!zs
|| !pDestRect
||
1557 (pDestRect
->left
== 0 &&
1558 pDestRect
->top
== 0 &&
1559 pDestRect
->right
== dst
->desc
.Width
&&
1560 pDestRect
->bottom
== dst
->desc
.Height
), D3DERR_INVALIDCALL
);
1562 (dst
->desc
.Width
== src
->desc
.Width
&&
1563 dst
->desc
.Height
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1564 user_assert(zs
|| !util_format_is_depth_or_stencil(src_res
->format
),
1565 D3DERR_INVALIDCALL
);
1566 user_assert(!zs
|| dst
->desc
.Format
== src
->desc
.Format
,
1567 D3DERR_INVALIDCALL
);
1568 user_assert(screen
->is_format_supported(screen
, src_res
->format
,
1570 src_res
->nr_samples
,
1571 PIPE_BIND_SAMPLER_VIEW
),
1572 D3DERR_INVALIDCALL
);
1574 /* We might want to permit these, but wine thinks we shouldn't. */
1575 user_assert(!pDestRect
||
1576 (pDestRect
->left
<= pDestRect
->right
&&
1577 pDestRect
->top
<= pDestRect
->bottom
), D3DERR_INVALIDCALL
);
1578 user_assert(!pSourceRect
||
1579 (pSourceRect
->left
<= pSourceRect
->right
&&
1580 pSourceRect
->top
<= pSourceRect
->bottom
), D3DERR_INVALIDCALL
);
1582 memset(&blit
, 0, sizeof(blit
));
1583 blit
.dst
.resource
= dst_res
;
1584 blit
.dst
.level
= dst
->level
;
1585 blit
.dst
.box
.z
= dst
->layer
;
1586 blit
.dst
.box
.depth
= 1;
1587 blit
.dst
.format
= dst_res
->format
;
1589 flip_x
= pDestRect
->left
> pDestRect
->right
;
1591 blit
.dst
.box
.x
= pDestRect
->right
;
1592 blit
.dst
.box
.width
= pDestRect
->left
- pDestRect
->right
;
1594 blit
.dst
.box
.x
= pDestRect
->left
;
1595 blit
.dst
.box
.width
= pDestRect
->right
- pDestRect
->left
;
1597 flip_y
= pDestRect
->top
> pDestRect
->bottom
;
1599 blit
.dst
.box
.y
= pDestRect
->bottom
;
1600 blit
.dst
.box
.height
= pDestRect
->top
- pDestRect
->bottom
;
1602 blit
.dst
.box
.y
= pDestRect
->top
;
1603 blit
.dst
.box
.height
= pDestRect
->bottom
- pDestRect
->top
;
1608 blit
.dst
.box
.width
= dst
->desc
.Width
;
1609 blit
.dst
.box
.height
= dst
->desc
.Height
;
1611 blit
.src
.resource
= src_res
;
1612 blit
.src
.level
= src
->level
;
1613 blit
.src
.box
.z
= src
->layer
;
1614 blit
.src
.box
.depth
= 1;
1615 blit
.src
.format
= src_res
->format
;
1617 if (flip_x
^ (pSourceRect
->left
> pSourceRect
->right
)) {
1618 blit
.src
.box
.x
= pSourceRect
->right
;
1619 blit
.src
.box
.width
= pSourceRect
->left
- pSourceRect
->right
;
1621 blit
.src
.box
.x
= pSourceRect
->left
;
1622 blit
.src
.box
.width
= pSourceRect
->right
- pSourceRect
->left
;
1624 if (flip_y
^ (pSourceRect
->top
> pSourceRect
->bottom
)) {
1625 blit
.src
.box
.y
= pSourceRect
->bottom
;
1626 blit
.src
.box
.height
= pSourceRect
->top
- pSourceRect
->bottom
;
1628 blit
.src
.box
.y
= pSourceRect
->top
;
1629 blit
.src
.box
.height
= pSourceRect
->bottom
- pSourceRect
->top
;
1632 blit
.src
.box
.x
= flip_x
? src
->desc
.Width
: 0;
1633 blit
.src
.box
.y
= flip_y
? src
->desc
.Height
: 0;
1634 blit
.src
.box
.width
= flip_x
? -src
->desc
.Width
: src
->desc
.Width
;
1635 blit
.src
.box
.height
= flip_y
? -src
->desc
.Height
: src
->desc
.Height
;
1637 blit
.mask
= zs
? PIPE_MASK_ZS
: PIPE_MASK_RGBA
;
1638 blit
.filter
= Filter
== D3DTEXF_LINEAR
?
1639 PIPE_TEX_FILTER_LINEAR
: PIPE_TEX_FILTER_NEAREST
;
1640 blit
.scissor_enable
= FALSE
;
1641 blit
.alpha_blend
= FALSE
;
1643 /* If both of a src and dst dimension are negative, flip them. */
1644 if (blit
.dst
.box
.width
< 0 && blit
.src
.box
.width
< 0) {
1645 blit
.dst
.box
.width
= -blit
.dst
.box
.width
;
1646 blit
.src
.box
.width
= -blit
.src
.box
.width
;
1648 if (blit
.dst
.box
.height
< 0 && blit
.src
.box
.height
< 0) {
1649 blit
.dst
.box
.height
= -blit
.dst
.box
.height
;
1650 blit
.src
.box
.height
= -blit
.src
.box
.height
;
1653 blit
.dst
.box
.width
!= blit
.src
.box
.width
||
1654 blit
.dst
.box
.height
!= blit
.src
.box
.height
;
1656 user_assert(!scaled
|| dst
!= src
, D3DERR_INVALIDCALL
);
1657 user_assert(!scaled
||
1658 !NineSurface9_IsOffscreenPlain(dst
), D3DERR_INVALIDCALL
);
1659 user_assert(!NineSurface9_IsOffscreenPlain(dst
) ||
1660 NineSurface9_IsOffscreenPlain(src
), D3DERR_INVALIDCALL
);
1661 user_assert(NineSurface9_IsOffscreenPlain(dst
) ||
1662 dst
->desc
.Usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
),
1663 D3DERR_INVALIDCALL
);
1664 user_assert(!scaled
||
1665 (!util_format_is_compressed(dst
->base
.info
.format
) &&
1666 !util_format_is_compressed(src
->base
.info
.format
)),
1667 D3DERR_INVALIDCALL
);
1669 user_warn(src
== dst
&&
1670 u_box_test_intersection_2d(&blit
.src
.box
, &blit
.dst
.box
));
1672 /* Check for clipping/clamping: */
1674 struct pipe_box box
;
1677 xy
= u_box_clip_2d(&box
, &blit
.dst
.box
,
1678 dst
->desc
.Width
, dst
->desc
.Height
);
1682 xy
= u_box_clip_2d(&box
, &blit
.src
.box
,
1683 src
->desc
.Width
, src
->desc
.Height
);
1687 ms
= (dst
->desc
.MultiSampleType
!= src
->desc
.MultiSampleType
) ||
1688 (dst
->desc
.MultiSampleQuality
!= src
->desc
.MultiSampleQuality
);
1690 if (clamped
|| scaled
|| (blit
.dst
.format
!= blit
.src
.format
) || ms
) {
1691 DBG("using pipe->blit()\n");
1692 /* TODO: software scaling */
1693 user_assert(screen
->is_format_supported(screen
, dst_res
->format
,
1695 dst_res
->nr_samples
,
1696 zs
? PIPE_BIND_DEPTH_STENCIL
:
1697 PIPE_BIND_RENDER_TARGET
),
1698 D3DERR_INVALIDCALL
);
1700 pipe
->blit(pipe
, &blit
);
1702 assert(blit
.dst
.box
.x
>= 0 && blit
.dst
.box
.y
>= 0 &&
1703 blit
.src
.box
.x
>= 0 && blit
.src
.box
.y
>= 0 &&
1704 blit
.dst
.box
.x
+ blit
.dst
.box
.width
<= dst
->desc
.Width
&&
1705 blit
.src
.box
.x
+ blit
.src
.box
.width
<= src
->desc
.Width
&&
1706 blit
.dst
.box
.y
+ blit
.dst
.box
.height
<= dst
->desc
.Height
&&
1707 blit
.src
.box
.y
+ blit
.src
.box
.height
<= src
->desc
.Height
);
1708 /* Or drivers might crash ... */
1709 DBG("Using resource_copy_region.\n");
1710 pipe
->resource_copy_region(pipe
,
1711 blit
.dst
.resource
, blit
.dst
.level
,
1712 blit
.dst
.box
.x
, blit
.dst
.box
.y
, blit
.dst
.box
.z
,
1713 blit
.src
.resource
, blit
.src
.level
,
1717 /* Communicate the container it needs to update sublevels - if apply */
1718 NineSurface9_MarkContainerDirty(dst
);
1724 NineDevice9_ColorFill( struct NineDevice9
*This
,
1725 IDirect3DSurface9
*pSurface
,
1729 struct pipe_context
*pipe
= NineDevice9_GetPipe(This
);
1730 struct NineSurface9
*surf
= NineSurface9(pSurface
);
1731 struct pipe_surface
*psurf
;
1732 unsigned x
, y
, w
, h
;
1733 union pipe_color_union rgba
;
1736 DBG("This=%p pSurface=%p pRect=%p color=%08x\n", This
,
1737 pSurface
, pRect
, color
);
1739 DBG("pRect=(%u,%u)-(%u,%u)\n", pRect
->left
, pRect
->top
,
1740 pRect
->right
, pRect
->bottom
);
1742 user_assert(surf
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1744 user_assert((surf
->base
.usage
& D3DUSAGE_RENDERTARGET
) ||
1745 NineSurface9_IsOffscreenPlain(surf
), D3DERR_INVALIDCALL
);
1747 user_assert(surf
->desc
.Format
!= D3DFMT_NULL
, D3D_OK
);
1752 w
= pRect
->right
- pRect
->left
;
1753 h
= pRect
->bottom
- pRect
->top
;
1755 if (compressed_format(surf
->desc
.Format
)) {
1756 const unsigned bw
= util_format_get_blockwidth(surf
->base
.info
.format
);
1757 const unsigned bh
= util_format_get_blockheight(surf
->base
.info
.format
);
1759 user_assert(!(x
% bw
) && !(y
% bh
) && !(w
% bw
) && !(h
% bh
),
1760 D3DERR_INVALIDCALL
);
1765 w
= surf
->desc
.Width
;
1766 h
= surf
->desc
.Height
;
1768 d3dcolor_to_pipe_color_union(&rgba
, color
);
1770 fallback
= !(surf
->base
.info
.bind
& PIPE_BIND_RENDER_TARGET
);
1773 psurf
= NineSurface9_GetSurface(surf
, 0);
1779 pipe
->clear_render_target(pipe
, psurf
, &rgba
, x
, y
, w
, h
, false);
1781 D3DLOCKED_RECT lock
;
1782 union util_color uc
;
1784 /* XXX: lock pRect and fix util_fill_rect */
1785 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, 0);
1788 util_pack_color_ub(color
>> 16, color
>> 8, color
>> 0, color
>> 24,
1789 surf
->base
.info
.format
, &uc
);
1790 util_fill_rect(lock
.pBits
, surf
->base
.info
.format
,lock
.Pitch
,
1792 NineSurface9_UnlockRect(surf
);
1799 NineDevice9_CreateOffscreenPlainSurface( struct NineDevice9
*This
,
1804 IDirect3DSurface9
**ppSurface
,
1805 HANDLE
*pSharedHandle
)
1809 DBG("This=%p Width=%u Height=%u Format=%s(0x%x) Pool=%u "
1810 "ppSurface=%p pSharedHandle=%p\n", This
,
1811 Width
, Height
, d3dformat_to_string(Format
), Format
, Pool
,
1812 ppSurface
, pSharedHandle
);
1815 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
1816 || Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1817 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1819 /* Can be used with StretchRect and ColorFill. It's also always lockable.
1821 hr
= create_zs_or_rt_surface(This
, 2, Pool
, Width
, Height
,
1823 D3DMULTISAMPLE_NONE
, 0,
1825 ppSurface
, pSharedHandle
);
1827 DBG("Failed to create surface.\n");
1832 NineDevice9_SetRenderTarget( struct NineDevice9
*This
,
1833 DWORD RenderTargetIndex
,
1834 IDirect3DSurface9
*pRenderTarget
)
1836 struct NineSurface9
*rt
= NineSurface9(pRenderTarget
);
1837 const unsigned i
= RenderTargetIndex
;
1839 DBG("This=%p RenderTargetIndex=%u pRenderTarget=%p\n", This
,
1840 RenderTargetIndex
, pRenderTarget
);
1842 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1843 user_assert(i
!= 0 || pRenderTarget
, D3DERR_INVALIDCALL
);
1844 user_assert(!pRenderTarget
||
1845 rt
->desc
.Usage
& D3DUSAGE_RENDERTARGET
, D3DERR_INVALIDCALL
);
1848 This
->state
.viewport
.X
= 0;
1849 This
->state
.viewport
.Y
= 0;
1850 This
->state
.viewport
.Width
= rt
->desc
.Width
;
1851 This
->state
.viewport
.Height
= rt
->desc
.Height
;
1852 This
->state
.viewport
.MinZ
= 0.0f
;
1853 This
->state
.viewport
.MaxZ
= 1.0f
;
1855 This
->state
.scissor
.minx
= 0;
1856 This
->state
.scissor
.miny
= 0;
1857 This
->state
.scissor
.maxx
= rt
->desc
.Width
;
1858 This
->state
.scissor
.maxy
= rt
->desc
.Height
;
1861 if (This
->state
.rt
[i
] != NineSurface9(pRenderTarget
))
1862 nine_bind(&This
->state
.rt
[i
], pRenderTarget
);
1864 nine_context_set_render_target(This
, i
, rt
);
1869 NineDevice9_GetRenderTarget( struct NineDevice9
*This
,
1870 DWORD RenderTargetIndex
,
1871 IDirect3DSurface9
**ppRenderTarget
)
1873 const unsigned i
= RenderTargetIndex
;
1875 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1876 user_assert(ppRenderTarget
, D3DERR_INVALIDCALL
);
1878 *ppRenderTarget
= (IDirect3DSurface9
*)This
->state
.rt
[i
];
1879 if (!This
->state
.rt
[i
])
1880 return D3DERR_NOTFOUND
;
1882 NineUnknown_AddRef(NineUnknown(This
->state
.rt
[i
]));
1887 NineDevice9_SetDepthStencilSurface( struct NineDevice9
*This
,
1888 IDirect3DSurface9
*pNewZStencil
)
1890 struct NineSurface9
*ds
= NineSurface9(pNewZStencil
);
1891 DBG("This=%p pNewZStencil=%p\n", This
, pNewZStencil
);
1893 if (This
->state
.ds
!= ds
) {
1894 nine_bind(&This
->state
.ds
, ds
);
1895 nine_context_set_depth_stencil(This
, ds
);
1901 NineDevice9_GetDepthStencilSurface( struct NineDevice9
*This
,
1902 IDirect3DSurface9
**ppZStencilSurface
)
1904 user_assert(ppZStencilSurface
, D3DERR_INVALIDCALL
);
1906 *ppZStencilSurface
= (IDirect3DSurface9
*)This
->state
.ds
;
1907 if (!This
->state
.ds
)
1908 return D3DERR_NOTFOUND
;
1910 NineUnknown_AddRef(NineUnknown(This
->state
.ds
));
1915 NineDevice9_BeginScene( struct NineDevice9
*This
)
1917 DBG("This=%p\n", This
);
1918 user_assert(!This
->in_scene
, D3DERR_INVALIDCALL
);
1919 This
->in_scene
= TRUE
;
1920 /* Do we want to do anything else here ? */
1925 NineDevice9_EndScene( struct NineDevice9
*This
)
1927 DBG("This=%p\n", This
);
1928 user_assert(This
->in_scene
, D3DERR_INVALIDCALL
);
1929 This
->in_scene
= FALSE
;
1934 NineDevice9_Clear( struct NineDevice9
*This
,
1936 const D3DRECT
*pRects
,
1942 struct NineSurface9
*zsbuf_surf
= This
->state
.ds
;
1944 DBG("This=%p Count=%u pRects=%p Flags=%x Color=%08x Z=%f Stencil=%x\n",
1945 This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1947 user_assert(This
->state
.ds
|| !(Flags
& NINED3DCLEAR_DEPTHSTENCIL
),
1948 D3DERR_INVALIDCALL
);
1949 user_assert(!(Flags
& D3DCLEAR_STENCIL
) ||
1951 util_format_is_depth_and_stencil(zsbuf_surf
->base
.info
.format
)),
1952 D3DERR_INVALIDCALL
);
1954 user_assert((Count
&& pRects
) || (!Count
&& !pRects
), D3DERR_INVALIDCALL
);
1956 user_warn((pRects
&& !Count
) || (!pRects
&& Count
));
1957 if (pRects
&& !Count
)
1963 nine_context_clear_fb(This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1968 NineDevice9_SetTransform( struct NineDevice9
*This
,
1969 D3DTRANSFORMSTATETYPE State
,
1970 const D3DMATRIX
*pMatrix
)
1972 struct nine_state
*state
= This
->update
;
1973 D3DMATRIX
*M
= nine_state_access_transform(&state
->ff
, State
, TRUE
);
1975 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
1977 user_assert(M
, D3DERR_INVALIDCALL
);
1980 if (unlikely(This
->is_recording
)) {
1981 state
->ff
.changed
.transform
[State
/ 32] |= 1 << (State
% 32);
1982 state
->changed
.group
|= NINE_STATE_FF
;
1984 nine_context_set_transform(This
, State
, pMatrix
);
1990 NineDevice9_GetTransform( struct NineDevice9
*This
,
1991 D3DTRANSFORMSTATETYPE State
,
1992 D3DMATRIX
*pMatrix
)
1994 D3DMATRIX
*M
= nine_state_access_transform(&This
->state
.ff
, State
, FALSE
);
1995 user_assert(M
, D3DERR_INVALIDCALL
);
2001 NineDevice9_MultiplyTransform( struct NineDevice9
*This
,
2002 D3DTRANSFORMSTATETYPE State
,
2003 const D3DMATRIX
*pMatrix
)
2005 struct nine_state
*state
= This
->update
;
2007 D3DMATRIX
*M
= nine_state_access_transform(&state
->ff
, State
, TRUE
);
2009 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2011 user_assert(M
, D3DERR_INVALIDCALL
);
2013 nine_d3d_matrix_matrix_mul(&T
, pMatrix
, M
);
2014 return NineDevice9_SetTransform(This
, State
, &T
);
2018 NineDevice9_SetViewport( struct NineDevice9
*This
,
2019 const D3DVIEWPORT9
*pViewport
)
2021 struct nine_state
*state
= This
->update
;
2023 DBG("X=%u Y=%u W=%u H=%u MinZ=%f MaxZ=%f\n",
2024 pViewport
->X
, pViewport
->Y
, pViewport
->Width
, pViewport
->Height
,
2025 pViewport
->MinZ
, pViewport
->MaxZ
);
2027 state
->viewport
= *pViewport
;
2028 nine_context_set_viewport(This
, pViewport
);
2034 NineDevice9_GetViewport( struct NineDevice9
*This
,
2035 D3DVIEWPORT9
*pViewport
)
2037 *pViewport
= This
->state
.viewport
;
2042 NineDevice9_SetMaterial( struct NineDevice9
*This
,
2043 const D3DMATERIAL9
*pMaterial
)
2045 struct nine_state
*state
= This
->update
;
2047 DBG("This=%p pMaterial=%p\n", This
, pMaterial
);
2049 nine_dump_D3DMATERIAL9(DBG_FF
, pMaterial
);
2051 user_assert(pMaterial
, E_POINTER
);
2053 state
->ff
.material
= *pMaterial
;
2054 if (unlikely(This
->is_recording
))
2055 state
->changed
.group
|= NINE_STATE_FF_MATERIAL
;
2057 nine_context_set_material(This
, pMaterial
);
2063 NineDevice9_GetMaterial( struct NineDevice9
*This
,
2064 D3DMATERIAL9
*pMaterial
)
2066 user_assert(pMaterial
, E_POINTER
);
2067 *pMaterial
= This
->state
.ff
.material
;
2072 NineDevice9_SetLight( struct NineDevice9
*This
,
2074 const D3DLIGHT9
*pLight
)
2076 struct nine_state
*state
= This
->update
;
2079 DBG("This=%p Index=%u pLight=%p\n", This
, Index
, pLight
);
2081 nine_dump_D3DLIGHT9(DBG_FF
, pLight
);
2083 user_assert(pLight
, D3DERR_INVALIDCALL
);
2084 user_assert(pLight
->Type
< NINED3DLIGHT_INVALID
, D3DERR_INVALIDCALL
);
2086 user_assert(Index
< NINE_MAX_LIGHTS
, D3DERR_INVALIDCALL
); /* sanity */
2088 hr
= nine_state_set_light(&state
->ff
, Index
, pLight
);
2092 if (pLight
->Type
!= D3DLIGHT_DIRECTIONAL
&&
2093 pLight
->Attenuation0
== 0.0f
&&
2094 pLight
->Attenuation1
== 0.0f
&&
2095 pLight
->Attenuation2
== 0.0f
) {
2096 DBG("Warning: all D3DLIGHT9.Attenuation[i] are 0\n");
2099 if (unlikely(This
->is_recording
))
2100 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2102 nine_context_set_light(This
, Index
, pLight
);
2108 NineDevice9_GetLight( struct NineDevice9
*This
,
2112 const struct nine_state
*state
= &This
->state
;
2114 user_assert(pLight
, D3DERR_INVALIDCALL
);
2115 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2116 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2117 D3DERR_INVALIDCALL
);
2119 *pLight
= state
->ff
.light
[Index
];
2125 NineDevice9_LightEnable( struct NineDevice9
*This
,
2129 struct nine_state
*state
= This
->update
;
2131 DBG("This=%p Index=%u Enable=%i\n", This
, Index
, Enable
);
2133 if (Index
>= state
->ff
.num_lights
||
2134 state
->ff
.light
[Index
].Type
== NINED3DLIGHT_INVALID
) {
2135 /* This should create a default light. */
2137 memset(&light
, 0, sizeof(light
));
2138 light
.Type
= D3DLIGHT_DIRECTIONAL
;
2139 light
.Diffuse
.r
= 1.0f
;
2140 light
.Diffuse
.g
= 1.0f
;
2141 light
.Diffuse
.b
= 1.0f
;
2142 light
.Direction
.z
= 1.0f
;
2143 NineDevice9_SetLight(This
, Index
, &light
);
2146 nine_state_light_enable(&state
->ff
, &state
->changed
.group
, Index
, Enable
);
2147 if (likely(!This
->is_recording
))
2148 nine_context_light_enable(This
, Index
, Enable
);
2154 NineDevice9_GetLightEnable( struct NineDevice9
*This
,
2158 const struct nine_state
*state
= &This
->state
;
2161 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2162 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2163 D3DERR_INVALIDCALL
);
2165 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
)
2166 if (state
->ff
.active_light
[i
] == Index
)
2169 *pEnable
= i
!= state
->ff
.num_lights_active
? 128 : 0; // Taken from wine
2175 NineDevice9_SetClipPlane( struct NineDevice9
*This
,
2177 const float *pPlane
)
2179 struct nine_state
*state
= This
->update
;
2181 user_assert(pPlane
, D3DERR_INVALIDCALL
);
2183 DBG("This=%p Index=%u pPlane=%f %f %f %f\n", This
, Index
,
2184 pPlane
[0], pPlane
[1],
2185 pPlane
[2], pPlane
[3]);
2187 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2189 memcpy(&state
->clip
.ucp
[Index
][0], pPlane
, sizeof(state
->clip
.ucp
[0]));
2190 if (unlikely(This
->is_recording
))
2191 state
->changed
.ucp
|= 1 << Index
;
2193 nine_context_set_clip_plane(This
, Index
, pPlane
);
2199 NineDevice9_GetClipPlane( struct NineDevice9
*This
,
2203 const struct nine_state
*state
= &This
->state
;
2205 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2207 memcpy(pPlane
, &state
->clip
.ucp
[Index
][0], sizeof(state
->clip
.ucp
[0]));
2212 NineDevice9_SetRenderState( struct NineDevice9
*This
,
2213 D3DRENDERSTATETYPE State
,
2216 struct nine_state
*state
= This
->update
;
2218 DBG("This=%p State=%u(%s) Value=%08x\n", This
,
2219 State
, nine_d3drs_to_string(State
), Value
);
2221 user_assert(State
< D3DRS_COUNT
, D3DERR_INVALIDCALL
);
2223 if (unlikely(This
->is_recording
)) {
2224 state
->rs_advertised
[State
] = Value
;
2225 /* only need to record changed render states for stateblocks */
2226 state
->changed
.rs
[State
/ 32] |= 1 << (State
% 32);
2227 state
->changed
.group
|= nine_render_state_group
[State
];
2231 if (state
->rs_advertised
[State
] == Value
)
2234 state
->rs_advertised
[State
] = Value
;
2235 nine_context_set_render_state(This
, State
, Value
);
2241 NineDevice9_GetRenderState( struct NineDevice9
*This
,
2242 D3DRENDERSTATETYPE State
,
2245 user_assert(State
< D3DRS_COUNT
, D3DERR_INVALIDCALL
);
2247 *pValue
= This
->state
.rs_advertised
[State
];
2252 NineDevice9_CreateStateBlock( struct NineDevice9
*This
,
2253 D3DSTATEBLOCKTYPE Type
,
2254 IDirect3DStateBlock9
**ppSB
)
2256 struct NineStateBlock9
*nsb
;
2257 struct nine_state
*dst
;
2259 enum nine_stateblock_type type
;
2262 DBG("This=%p Type=%u ppSB=%p\n", This
, Type
, ppSB
);
2264 user_assert(Type
== D3DSBT_ALL
||
2265 Type
== D3DSBT_VERTEXSTATE
||
2266 Type
== D3DSBT_PIXELSTATE
, D3DERR_INVALIDCALL
);
2269 case D3DSBT_VERTEXSTATE
: type
= NINESBT_VERTEXSTATE
; break;
2270 case D3DSBT_PIXELSTATE
: type
= NINESBT_PIXELSTATE
; break;
2276 hr
= NineStateBlock9_new(This
, &nsb
, type
);
2279 *ppSB
= (IDirect3DStateBlock9
*)nsb
;
2282 dst
->changed
.group
=
2283 NINE_STATE_TEXTURE
|
2286 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_VERTEXSTATE
) {
2287 dst
->changed
.group
|=
2288 NINE_STATE_FF_LIGHTING
|
2289 NINE_STATE_VS
| NINE_STATE_VS_CONST
|
2291 /* TODO: texture/sampler state */
2292 memcpy(dst
->changed
.rs
,
2293 nine_render_states_vertex
, sizeof(dst
->changed
.rs
));
2294 nine_ranges_insert(&dst
->changed
.vs_const_f
, 0, This
->may_swvp
? NINE_MAX_CONST_F_SWVP
: This
->max_vs_const_f
,
2296 nine_ranges_insert(&dst
->changed
.vs_const_i
, 0, This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
,
2298 nine_ranges_insert(&dst
->changed
.vs_const_b
, 0, This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
,
2300 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2301 dst
->changed
.sampler
[s
] |= 1 << D3DSAMP_DMAPOFFSET
;
2302 if (This
->state
.ff
.num_lights
) {
2303 dst
->ff
.num_lights
= This
->state
.ff
.num_lights
;
2304 /* zero'd -> light type won't be NINED3DLIGHT_INVALID, so
2305 * all currently existing lights will be captured
2307 dst
->ff
.light
= CALLOC(This
->state
.ff
.num_lights
,
2309 if (!dst
->ff
.light
) {
2310 nine_bind(ppSB
, NULL
);
2311 return E_OUTOFMEMORY
;
2315 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_PIXELSTATE
) {
2316 dst
->changed
.group
|=
2317 NINE_STATE_PS
| NINE_STATE_PS_CONST
| NINE_STATE_BLEND
|
2318 NINE_STATE_FF_OTHER
| NINE_STATE_FF_PSSTAGES
| NINE_STATE_PS_CONST
|
2319 NINE_STATE_FB
| NINE_STATE_DSA
| NINE_STATE_MULTISAMPLE
|
2320 NINE_STATE_RASTERIZER
| NINE_STATE_STENCIL_REF
;
2321 memcpy(dst
->changed
.rs
,
2322 nine_render_states_pixel
, sizeof(dst
->changed
.rs
));
2323 nine_ranges_insert(&dst
->changed
.ps_const_f
, 0, This
->max_ps_const_f
,
2325 dst
->changed
.ps_const_i
= 0xffff;
2326 dst
->changed
.ps_const_b
= 0xffff;
2327 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2328 dst
->changed
.sampler
[s
] |= 0x1ffe;
2329 for (s
= 0; s
< NINE_MAX_TEXTURE_STAGES
; ++s
) {
2330 dst
->ff
.changed
.tex_stage
[s
][0] |= 0xffffffff;
2331 dst
->ff
.changed
.tex_stage
[s
][1] |= 0xffffffff;
2334 if (Type
== D3DSBT_ALL
) {
2335 dst
->changed
.group
|=
2336 NINE_STATE_VIEWPORT
|
2337 NINE_STATE_SCISSOR
|
2338 NINE_STATE_RASTERIZER
|
2342 NINE_STATE_MATERIAL
|
2343 NINE_STATE_BLEND_COLOR
|
2344 NINE_STATE_SAMPLE_MASK
;
2345 memset(dst
->changed
.rs
, ~0, (D3DRS_COUNT
/ 32) * sizeof(uint32_t));
2346 dst
->changed
.rs
[D3DRS_LAST
/ 32] |= (1 << (D3DRS_COUNT
% 32)) - 1;
2347 dst
->changed
.vtxbuf
= (1ULL << This
->caps
.MaxStreams
) - 1;
2348 dst
->changed
.stream_freq
= dst
->changed
.vtxbuf
;
2349 dst
->changed
.ucp
= (1 << PIPE_MAX_CLIP_PLANES
) - 1;
2350 dst
->changed
.texture
= (1 << NINE_MAX_SAMPLERS
) - 1;
2352 NineStateBlock9_Capture(NineStateBlock9(*ppSB
));
2354 /* TODO: fixed function state */
2360 NineDevice9_BeginStateBlock( struct NineDevice9
*This
)
2364 DBG("This=%p\n", This
);
2366 user_assert(!This
->record
, D3DERR_INVALIDCALL
);
2368 hr
= NineStateBlock9_new(This
, &This
->record
, NINESBT_CUSTOM
);
2371 NineUnknown_ConvertRefToBind(NineUnknown(This
->record
));
2373 This
->update
= &This
->record
->state
;
2374 This
->is_recording
= TRUE
;
2380 NineDevice9_EndStateBlock( struct NineDevice9
*This
,
2381 IDirect3DStateBlock9
**ppSB
)
2383 DBG("This=%p ppSB=%p\n", This
, ppSB
);
2385 user_assert(This
->record
, D3DERR_INVALIDCALL
);
2387 This
->update
= &This
->state
;
2388 This
->is_recording
= FALSE
;
2390 NineUnknown_AddRef(NineUnknown(This
->record
));
2391 *ppSB
= (IDirect3DStateBlock9
*)This
->record
;
2392 NineUnknown_Unbind(NineUnknown(This
->record
));
2393 This
->record
= NULL
;
2399 NineDevice9_SetClipStatus( struct NineDevice9
*This
,
2400 const D3DCLIPSTATUS9
*pClipStatus
)
2402 STUB(D3DERR_INVALIDCALL
);
2406 NineDevice9_GetClipStatus( struct NineDevice9
*This
,
2407 D3DCLIPSTATUS9
*pClipStatus
)
2409 STUB(D3DERR_INVALIDCALL
);
2413 NineDevice9_GetTexture( struct NineDevice9
*This
,
2415 IDirect3DBaseTexture9
**ppTexture
)
2417 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2418 Stage
== D3DDMAPSAMPLER
||
2419 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2420 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2421 user_assert(ppTexture
, D3DERR_INVALIDCALL
);
2423 if (Stage
>= D3DDMAPSAMPLER
)
2424 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2426 *ppTexture
= (IDirect3DBaseTexture9
*)This
->state
.texture
[Stage
];
2428 if (This
->state
.texture
[Stage
])
2429 NineUnknown_AddRef(NineUnknown(This
->state
.texture
[Stage
]));
2434 NineDevice9_SetTexture( struct NineDevice9
*This
,
2436 IDirect3DBaseTexture9
*pTexture
)
2438 struct nine_state
*state
= This
->update
;
2439 struct NineBaseTexture9
*tex
= NineBaseTexture9(pTexture
);
2440 struct NineBaseTexture9
*old
;
2442 DBG("This=%p Stage=%u pTexture=%p\n", This
, Stage
, pTexture
);
2444 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2445 Stage
== D3DDMAPSAMPLER
||
2446 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2447 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2448 user_assert(!tex
|| (tex
->base
.pool
!= D3DPOOL_SCRATCH
&&
2449 tex
->base
.pool
!= D3DPOOL_SYSTEMMEM
), D3DERR_INVALIDCALL
);
2451 if (Stage
>= D3DDMAPSAMPLER
)
2452 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2454 if (This
->is_recording
) {
2455 state
->changed
.texture
|= 1 << Stage
;
2456 state
->changed
.group
|= NINE_STATE_TEXTURE
;
2457 nine_bind(&state
->texture
[Stage
], pTexture
);
2461 old
= state
->texture
[Stage
];
2466 if ((tex
->managed
.dirty
| tex
->dirty_mip
) && LIST_IS_EMPTY(&tex
->list
))
2467 list_add(&tex
->list
, &This
->update_textures
);
2474 nine_context_set_texture(This
, Stage
, tex
);
2476 nine_bind(&state
->texture
[Stage
], pTexture
);
2482 NineDevice9_GetTextureStageState( struct NineDevice9
*This
,
2484 D3DTEXTURESTAGESTATETYPE Type
,
2487 const struct nine_state
*state
= &This
->state
;
2489 user_assert(Stage
< ARRAY_SIZE(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2490 user_assert(Type
< ARRAY_SIZE(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2492 *pValue
= state
->ff
.tex_stage
[Stage
][Type
];
2498 NineDevice9_SetTextureStageState( struct NineDevice9
*This
,
2500 D3DTEXTURESTAGESTATETYPE Type
,
2503 struct nine_state
*state
= This
->update
;
2505 DBG("Stage=%u Type=%u Value=%08x\n", Stage
, Type
, Value
);
2506 nine_dump_D3DTSS_value(DBG_FF
, Type
, Value
);
2508 user_assert(Stage
< ARRAY_SIZE(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2509 user_assert(Type
< ARRAY_SIZE(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2511 state
->ff
.tex_stage
[Stage
][Type
] = Value
;
2513 if (unlikely(This
->is_recording
)) {
2514 if (Type
== D3DTSS_TEXTURETRANSFORMFLAGS
)
2515 state
->changed
.group
|= NINE_STATE_PS1X_SHADER
;
2516 state
->changed
.group
|= NINE_STATE_FF_PSSTAGES
;
2517 state
->ff
.changed
.tex_stage
[Stage
][Type
/ 32] |= 1 << (Type
% 32);
2519 nine_context_set_texture_stage_state(This
, Stage
, Type
, Value
);
2525 NineDevice9_GetSamplerState( struct NineDevice9
*This
,
2527 D3DSAMPLERSTATETYPE Type
,
2530 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2531 Sampler
== D3DDMAPSAMPLER
||
2532 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2533 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2535 if (Sampler
>= D3DDMAPSAMPLER
)
2536 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2538 *pValue
= This
->state
.samp_advertised
[Sampler
][Type
];
2543 NineDevice9_SetSamplerState( struct NineDevice9
*This
,
2545 D3DSAMPLERSTATETYPE Type
,
2548 struct nine_state
*state
= This
->update
;
2550 DBG("This=%p Sampler=%u Type=%s Value=%08x\n", This
,
2551 Sampler
, nine_D3DSAMP_to_str(Type
), Value
);
2553 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2554 Sampler
== D3DDMAPSAMPLER
||
2555 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2556 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2558 if (Sampler
>= D3DDMAPSAMPLER
)
2559 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2561 if (unlikely(This
->is_recording
)) {
2562 state
->samp_advertised
[Sampler
][Type
] = Value
;
2563 state
->changed
.group
|= NINE_STATE_SAMPLER
;
2564 state
->changed
.sampler
[Sampler
] |= 1 << Type
;
2568 if (state
->samp_advertised
[Sampler
][Type
] == Value
)
2571 state
->samp_advertised
[Sampler
][Type
] = Value
;
2572 nine_context_set_sampler_state(This
, Sampler
, Type
, Value
);
2578 NineDevice9_ValidateDevice( struct NineDevice9
*This
,
2581 const struct nine_state
*state
= &This
->state
;
2583 unsigned w
= 0, h
= 0;
2585 DBG("This=%p pNumPasses=%p\n", This
, pNumPasses
);
2587 for (i
= 0; i
< ARRAY_SIZE(state
->samp_advertised
); ++i
) {
2588 if (state
->samp_advertised
[i
][D3DSAMP_MINFILTER
] == D3DTEXF_NONE
||
2589 state
->samp_advertised
[i
][D3DSAMP_MAGFILTER
] == D3DTEXF_NONE
)
2590 return D3DERR_UNSUPPORTEDTEXTUREFILTER
;
2593 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2597 w
= state
->rt
[i
]->desc
.Width
;
2598 h
= state
->rt
[i
]->desc
.Height
;
2600 if (state
->rt
[i
]->desc
.Width
!= w
|| state
->rt
[i
]->desc
.Height
!= h
) {
2601 return D3DERR_CONFLICTINGRENDERSTATE
;
2605 (state
->rs_advertised
[D3DRS_ZENABLE
] || state
->rs_advertised
[D3DRS_STENCILENABLE
])) {
2607 (state
->ds
->desc
.Width
!= w
|| state
->ds
->desc
.Height
!= h
))
2608 return D3DERR_CONFLICTINGRENDERSTATE
;
2618 NineDevice9_SetPaletteEntries( struct NineDevice9
*This
,
2620 const PALETTEENTRY
*pEntries
)
2622 STUB(D3D_OK
); /* like wine */
2626 NineDevice9_GetPaletteEntries( struct NineDevice9
*This
,
2628 PALETTEENTRY
*pEntries
)
2630 STUB(D3DERR_INVALIDCALL
);
2634 NineDevice9_SetCurrentTexturePalette( struct NineDevice9
*This
,
2635 UINT PaletteNumber
)
2637 STUB(D3D_OK
); /* like wine */
2641 NineDevice9_GetCurrentTexturePalette( struct NineDevice9
*This
,
2642 UINT
*PaletteNumber
)
2644 STUB(D3DERR_INVALIDCALL
);
2648 NineDevice9_SetScissorRect( struct NineDevice9
*This
,
2651 struct nine_state
*state
= This
->update
;
2653 DBG("x=(%u..%u) y=(%u..%u)\n",
2654 pRect
->left
, pRect
->top
, pRect
->right
, pRect
->bottom
);
2656 state
->scissor
.minx
= pRect
->left
;
2657 state
->scissor
.miny
= pRect
->top
;
2658 state
->scissor
.maxx
= pRect
->right
;
2659 state
->scissor
.maxy
= pRect
->bottom
;
2661 if (unlikely(This
->is_recording
))
2662 state
->changed
.group
|= NINE_STATE_SCISSOR
;
2664 nine_context_set_scissor(This
, &state
->scissor
);
2670 NineDevice9_GetScissorRect( struct NineDevice9
*This
,
2673 pRect
->left
= This
->state
.scissor
.minx
;
2674 pRect
->top
= This
->state
.scissor
.miny
;
2675 pRect
->right
= This
->state
.scissor
.maxx
;
2676 pRect
->bottom
= This
->state
.scissor
.maxy
;
2682 NineDevice9_SetSoftwareVertexProcessing( struct NineDevice9
*This
,
2685 if (This
->params
.BehaviorFlags
& D3DCREATE_MIXED_VERTEXPROCESSING
) {
2686 This
->swvp
= bSoftware
;
2687 This
->context
.changed
.group
|= NINE_STATE_SWVP
;
2690 return D3DERR_INVALIDCALL
; /* msdn. TODO: check in practice */
2694 NineDevice9_GetSoftwareVertexProcessing( struct NineDevice9
*This
)
2700 NineDevice9_SetNPatchMode( struct NineDevice9
*This
,
2703 return D3D_OK
; /* Nothing to do because we don't advertise NPatch support */
2707 NineDevice9_GetNPatchMode( struct NineDevice9
*This
)
2713 NineDevice9_DrawPrimitive( struct NineDevice9
*This
,
2714 D3DPRIMITIVETYPE PrimitiveType
,
2716 UINT PrimitiveCount
)
2718 DBG("iface %p, PrimitiveType %u, StartVertex %u, PrimitiveCount %u\n",
2719 This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2721 nine_context_draw_primitive(This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2727 NineDevice9_DrawIndexedPrimitive( struct NineDevice9
*This
,
2728 D3DPRIMITIVETYPE PrimitiveType
,
2729 INT BaseVertexIndex
,
2730 UINT MinVertexIndex
,
2733 UINT PrimitiveCount
)
2735 DBG("iface %p, PrimitiveType %u, BaseVertexIndex %u, MinVertexIndex %u "
2736 "NumVertices %u, StartIndex %u, PrimitiveCount %u\n",
2737 This
, PrimitiveType
, BaseVertexIndex
, MinVertexIndex
, NumVertices
,
2738 StartIndex
, PrimitiveCount
);
2740 user_assert(This
->state
.idxbuf
, D3DERR_INVALIDCALL
);
2741 user_assert(This
->state
.vdecl
, D3DERR_INVALIDCALL
);
2743 nine_context_draw_indexed_primitive(This
, PrimitiveType
, BaseVertexIndex
,
2744 MinVertexIndex
, NumVertices
, StartIndex
,
2751 NineDevice9_DrawPrimitiveUP( struct NineDevice9
*This
,
2752 D3DPRIMITIVETYPE PrimitiveType
,
2753 UINT PrimitiveCount
,
2754 const void *pVertexStreamZeroData
,
2755 UINT VertexStreamZeroStride
)
2757 struct pipe_vertex_buffer vtxbuf
;
2759 DBG("iface %p, PrimitiveType %u, PrimitiveCount %u, data %p, stride %u\n",
2760 This
, PrimitiveType
, PrimitiveCount
,
2761 pVertexStreamZeroData
, VertexStreamZeroStride
);
2763 user_assert(pVertexStreamZeroData
&& VertexStreamZeroStride
,
2764 D3DERR_INVALIDCALL
);
2765 user_assert(PrimitiveCount
, D3D_OK
);
2767 vtxbuf
.stride
= VertexStreamZeroStride
;
2768 vtxbuf
.buffer_offset
= 0;
2769 vtxbuf
.buffer
= NULL
;
2770 vtxbuf
.user_buffer
= pVertexStreamZeroData
;
2772 if (!This
->driver_caps
.user_vbufs
) {
2773 u_upload_data(This
->vertex_uploader
,
2775 (prim_count_to_vertex_count(PrimitiveType
, PrimitiveCount
)) * VertexStreamZeroStride
, /* XXX */
2778 &vtxbuf
.buffer_offset
,
2780 u_upload_unmap(This
->vertex_uploader
);
2781 vtxbuf
.user_buffer
= NULL
;
2784 nine_context_draw_primitive_from_vtxbuf(This
, PrimitiveType
, PrimitiveCount
, &vtxbuf
);
2786 pipe_resource_reference(&vtxbuf
.buffer
, NULL
);
2788 NineDevice9_PauseRecording(This
);
2789 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
2790 NineDevice9_ResumeRecording(This
);
2796 NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9
*This
,
2797 D3DPRIMITIVETYPE PrimitiveType
,
2798 UINT MinVertexIndex
,
2800 UINT PrimitiveCount
,
2801 const void *pIndexData
,
2802 D3DFORMAT IndexDataFormat
,
2803 const void *pVertexStreamZeroData
,
2804 UINT VertexStreamZeroStride
)
2806 struct pipe_vertex_buffer vbuf
;
2807 struct pipe_index_buffer ibuf
;
2809 DBG("iface %p, PrimitiveType %u, MinVertexIndex %u, NumVertices %u "
2810 "PrimitiveCount %u, pIndexData %p, IndexDataFormat %u "
2811 "pVertexStreamZeroData %p, VertexStreamZeroStride %u\n",
2812 This
, PrimitiveType
, MinVertexIndex
, NumVertices
, PrimitiveCount
,
2813 pIndexData
, IndexDataFormat
,
2814 pVertexStreamZeroData
, VertexStreamZeroStride
);
2816 user_assert(pIndexData
&& pVertexStreamZeroData
, D3DERR_INVALIDCALL
);
2817 user_assert(VertexStreamZeroStride
, D3DERR_INVALIDCALL
);
2818 user_assert(IndexDataFormat
== D3DFMT_INDEX16
||
2819 IndexDataFormat
== D3DFMT_INDEX32
, D3DERR_INVALIDCALL
);
2820 user_assert(PrimitiveCount
, D3D_OK
);
2822 vbuf
.stride
= VertexStreamZeroStride
;
2823 vbuf
.buffer_offset
= 0;
2825 vbuf
.user_buffer
= pVertexStreamZeroData
;
2827 ibuf
.index_size
= (IndexDataFormat
== D3DFMT_INDEX16
) ? 2 : 4;
2830 ibuf
.user_buffer
= pIndexData
;
2832 if (!This
->driver_caps
.user_vbufs
) {
2833 const unsigned base
= MinVertexIndex
* VertexStreamZeroStride
;
2834 u_upload_data(This
->vertex_uploader
,
2836 NumVertices
* VertexStreamZeroStride
, /* XXX */
2838 (const uint8_t *)vbuf
.user_buffer
+ base
,
2839 &vbuf
.buffer_offset
,
2841 u_upload_unmap(This
->vertex_uploader
);
2842 /* Won't be used: */
2843 vbuf
.buffer_offset
-= base
;
2844 vbuf
.user_buffer
= NULL
;
2846 if (!This
->driver_caps
.user_ibufs
) {
2847 u_upload_data(This
->index_uploader
,
2849 (prim_count_to_vertex_count(PrimitiveType
, PrimitiveCount
)) * ibuf
.index_size
,
2854 u_upload_unmap(This
->index_uploader
);
2855 ibuf
.user_buffer
= NULL
;
2858 nine_context_draw_indexed_primitive_from_vtxbuf_idxbuf(This
, PrimitiveType
,
2865 pipe_resource_reference(&vbuf
.buffer
, NULL
);
2866 pipe_resource_reference(&ibuf
.buffer
, NULL
);
2868 NineDevice9_PauseRecording(This
);
2869 NineDevice9_SetIndices(This
, NULL
);
2870 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
2871 NineDevice9_ResumeRecording(This
);
2877 NineDevice9_ProcessVertices( struct NineDevice9
*This
,
2881 IDirect3DVertexBuffer9
*pDestBuffer
,
2882 IDirect3DVertexDeclaration9
*pVertexDecl
,
2885 struct pipe_screen
*screen_sw
= This
->screen_sw
;
2886 struct pipe_context
*pipe_sw
= This
->pipe_sw
;
2887 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pVertexDecl
);
2888 struct NineVertexBuffer9
*dst
= NineVertexBuffer9(pDestBuffer
);
2889 struct NineVertexShader9
*vs
;
2890 struct pipe_resource
*resource
;
2891 struct pipe_transfer
*transfer
= NULL
;
2892 struct pipe_stream_output_info so
;
2893 struct pipe_stream_output_target
*target
;
2894 struct pipe_draw_info draw
;
2895 struct pipe_box box
;
2896 bool programmable_vs
= This
->state
.vs
&& !(This
->state
.vdecl
&& This
->state
.vdecl
->position_t
);
2897 unsigned offsets
[1] = {0};
2899 unsigned buffer_size
;
2902 DBG("This=%p SrcStartIndex=%u DestIndex=%u VertexCount=%u "
2903 "pDestBuffer=%p pVertexDecl=%p Flags=%d\n",
2904 This
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
,
2905 pVertexDecl
, Flags
);
2907 if (!screen_sw
->get_param(screen_sw
, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
)) {
2908 DBG("ProcessVertices not supported\n");
2909 return D3DERR_INVALIDCALL
;
2913 vs
= programmable_vs
? This
->state
.vs
: This
->ff
.vs
;
2914 /* Note: version is 0 for ff */
2915 user_assert(vdecl
|| (vs
->byte_code
.version
< 0x30 && dst
->desc
.FVF
),
2916 D3DERR_INVALIDCALL
);
2918 DWORD FVF
= dst
->desc
.FVF
;
2919 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
2921 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
2925 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
2926 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
2930 /* Flags: Can be 0 or D3DPV_DONOTCOPYDATA, and/or lock flags
2931 * D3DPV_DONOTCOPYDATA -> Has effect only for ff. In particular
2932 * if not set, everything from src will be used, and dst
2933 * must match exactly the ff vs outputs.
2934 * TODO: Handle all the checks, etc for ff */
2935 user_assert(vdecl
->position_t
|| programmable_vs
,
2936 D3DERR_INVALIDCALL
);
2938 /* TODO: Support vs < 3 and ff */
2939 user_assert(vs
->byte_code
.version
== 0x30,
2940 D3DERR_INVALIDCALL
);
2941 /* TODO: Not hardcode the constant buffers for swvp */
2942 user_assert(This
->may_swvp
,
2943 D3DERR_INVALIDCALL
);
2945 nine_state_prepare_draw_sw(This
, vdecl
, SrcStartIndex
, VertexCount
, &so
);
2947 buffer_size
= VertexCount
* so
.stride
[0] * 4;
2949 struct pipe_resource templ
;
2951 memset(&templ
, 0, sizeof(templ
));
2952 templ
.target
= PIPE_BUFFER
;
2953 templ
.format
= PIPE_FORMAT_R8_UNORM
;
2954 templ
.width0
= buffer_size
;
2956 templ
.bind
= PIPE_BIND_STREAM_OUTPUT
;
2957 templ
.usage
= PIPE_USAGE_STREAM
;
2958 templ
.height0
= templ
.depth0
= templ
.array_size
= 1;
2959 templ
.last_level
= templ
.nr_samples
= 0;
2961 resource
= screen_sw
->resource_create(screen_sw
, &templ
);
2963 return E_OUTOFMEMORY
;
2965 target
= pipe_sw
->create_stream_output_target(pipe_sw
, resource
,
2968 pipe_resource_reference(&resource
, NULL
);
2969 return D3DERR_DRIVERINTERNALERROR
;
2972 draw
.mode
= PIPE_PRIM_POINTS
;
2973 draw
.count
= VertexCount
;
2974 draw
.start_instance
= 0;
2975 draw
.primitive_restart
= FALSE
;
2976 draw
.restart_index
= 0;
2977 draw
.count_from_stream_output
= NULL
;
2978 draw
.indirect
= NULL
;
2979 draw
.indirect_params
= NULL
;
2980 draw
.instance_count
= 1;
2981 draw
.indexed
= FALSE
;
2983 draw
.index_bias
= 0;
2985 draw
.max_index
= VertexCount
- 1;
2988 pipe_sw
->set_stream_output_targets(pipe_sw
, 1, &target
, offsets
);
2990 pipe_sw
->draw_vbo(pipe_sw
, &draw
);
2992 pipe_sw
->set_stream_output_targets(pipe_sw
, 0, NULL
, 0);
2993 pipe_sw
->stream_output_target_destroy(pipe_sw
, target
);
2995 u_box_1d(0, VertexCount
* so
.stride
[0] * 4, &box
);
2996 map
= pipe_sw
->transfer_map(pipe_sw
, resource
, 0, PIPE_TRANSFER_READ
, &box
,
2999 hr
= D3DERR_DRIVERINTERNALERROR
;
3003 hr
= NineVertexDeclaration9_ConvertStreamOutput(vdecl
,
3004 dst
, DestIndex
, VertexCount
,
3007 pipe_sw
->transfer_unmap(pipe_sw
, transfer
);
3010 nine_state_after_draw_sw(This
);
3011 pipe_resource_reference(&resource
, NULL
);
3016 NineDevice9_CreateVertexDeclaration( struct NineDevice9
*This
,
3017 const D3DVERTEXELEMENT9
*pVertexElements
,
3018 IDirect3DVertexDeclaration9
**ppDecl
)
3020 struct NineVertexDeclaration9
*vdecl
;
3022 DBG("This=%p pVertexElements=%p ppDecl=%p\n",
3023 This
, pVertexElements
, ppDecl
);
3025 HRESULT hr
= NineVertexDeclaration9_new(This
, pVertexElements
, &vdecl
);
3027 *ppDecl
= (IDirect3DVertexDeclaration9
*)vdecl
;
3033 NineDevice9_SetVertexDeclaration( struct NineDevice9
*This
,
3034 IDirect3DVertexDeclaration9
*pDecl
)
3036 struct nine_state
*state
= This
->update
;
3037 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pDecl
);
3039 DBG("This=%p pDecl=%p\n", This
, pDecl
);
3041 if (unlikely(This
->is_recording
)) {
3042 nine_bind(&state
->vdecl
, vdecl
);
3043 state
->changed
.group
|= NINE_STATE_VDECL
;
3047 if (state
->vdecl
== vdecl
)
3050 nine_bind(&state
->vdecl
, vdecl
);
3052 nine_context_set_vertex_declaration(This
, vdecl
);
3058 NineDevice9_GetVertexDeclaration( struct NineDevice9
*This
,
3059 IDirect3DVertexDeclaration9
**ppDecl
)
3061 user_assert(ppDecl
, D3DERR_INVALIDCALL
);
3063 *ppDecl
= (IDirect3DVertexDeclaration9
*)This
->state
.vdecl
;
3065 NineUnknown_AddRef(NineUnknown(*ppDecl
));
3070 NineDevice9_SetFVF( struct NineDevice9
*This
,
3073 struct NineVertexDeclaration9
*vdecl
;
3076 DBG("FVF = %08x\n", FVF
);
3078 return D3D_OK
; /* like wine */
3080 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
3082 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
3086 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
3087 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
3089 return NineDevice9_SetVertexDeclaration(
3090 This
, (IDirect3DVertexDeclaration9
*)vdecl
);
3094 NineDevice9_GetFVF( struct NineDevice9
*This
,
3097 *pFVF
= This
->state
.vdecl
? This
->state
.vdecl
->fvf
: 0;
3102 NineDevice9_CreateVertexShader( struct NineDevice9
*This
,
3103 const DWORD
*pFunction
,
3104 IDirect3DVertexShader9
**ppShader
)
3106 struct NineVertexShader9
*vs
;
3109 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3111 hr
= NineVertexShader9_new(This
, &vs
, pFunction
, NULL
);
3114 *ppShader
= (IDirect3DVertexShader9
*)vs
;
3119 NineDevice9_SetVertexShader( struct NineDevice9
*This
,
3120 IDirect3DVertexShader9
*pShader
)
3122 struct nine_state
*state
= This
->update
;
3123 struct NineVertexShader9
*vs_shader
= (struct NineVertexShader9
*)pShader
;
3125 DBG("This=%p pShader=%p\n", This
, pShader
);
3127 if (unlikely(This
->is_recording
)) {
3128 nine_bind(&state
->vs
, vs_shader
);
3129 state
->changed
.group
|= NINE_STATE_VS
;
3133 if (state
->vs
== vs_shader
)
3136 nine_bind(&state
->vs
, vs_shader
);
3138 nine_context_set_vertex_shader(This
, vs_shader
);
3144 NineDevice9_GetVertexShader( struct NineDevice9
*This
,
3145 IDirect3DVertexShader9
**ppShader
)
3147 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3148 nine_reference_set(ppShader
, This
->state
.vs
);
3153 NineDevice9_SetVertexShaderConstantF( struct NineDevice9
*This
,
3155 const float *pConstantData
,
3156 UINT Vector4fCount
)
3158 struct nine_state
*state
= This
->update
;
3159 float *vs_const_f
= state
->vs_const_f
;
3161 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3162 This
, StartRegister
, pConstantData
, Vector4fCount
);
3164 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3165 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3169 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3171 if (unlikely(This
->is_recording
)) {
3172 memcpy(&vs_const_f
[StartRegister
* 4],
3174 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3176 nine_ranges_insert(&state
->changed
.vs_const_f
,
3177 StartRegister
, StartRegister
+ Vector4fCount
,
3180 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3185 if (!memcmp(&vs_const_f
[StartRegister
* 4], pConstantData
,
3186 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0])))
3189 memcpy(&vs_const_f
[StartRegister
* 4],
3191 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3193 nine_context_set_vertex_shader_constant_f(This
, StartRegister
, pConstantData
, Vector4fCount
);
3199 NineDevice9_GetVertexShaderConstantF( struct NineDevice9
*This
,
3201 float *pConstantData
,
3202 UINT Vector4fCount
)
3204 const struct nine_state
*state
= &This
->state
;
3206 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3207 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3208 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3210 memcpy(pConstantData
,
3211 &state
->vs_const_f
[StartRegister
* 4],
3212 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3218 NineDevice9_SetVertexShaderConstantI( struct NineDevice9
*This
,
3220 const int *pConstantData
,
3221 UINT Vector4iCount
)
3223 struct nine_state
*state
= This
->update
;
3226 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3227 This
, StartRegister
, pConstantData
, Vector4iCount
);
3229 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3230 D3DERR_INVALIDCALL
);
3231 user_assert(StartRegister
+ Vector4iCount
<= (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3232 D3DERR_INVALIDCALL
);
3233 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3235 if (This
->driver_caps
.vs_integer
) {
3236 if (!This
->is_recording
) {
3237 if (!memcmp(&state
->vs_const_i
[4 * StartRegister
], pConstantData
,
3238 Vector4iCount
* sizeof(int[4])))
3241 memcpy(&state
->vs_const_i
[4 * StartRegister
],
3243 Vector4iCount
* sizeof(int[4]));
3245 for (i
= 0; i
< Vector4iCount
; i
++) {
3246 state
->vs_const_i
[4 * (StartRegister
+ i
)] = fui((float)(pConstantData
[4 * i
]));
3247 state
->vs_const_i
[4 * (StartRegister
+ i
) + 1] = fui((float)(pConstantData
[4 * i
+ 1]));
3248 state
->vs_const_i
[4 * (StartRegister
+ i
) + 2] = fui((float)(pConstantData
[4 * i
+ 2]));
3249 state
->vs_const_i
[4 * (StartRegister
+ i
) + 3] = fui((float)(pConstantData
[4 * i
+ 3]));
3253 if (unlikely(This
->is_recording
)) {
3254 nine_ranges_insert(&state
->changed
.vs_const_i
,
3255 StartRegister
, StartRegister
+ Vector4iCount
,
3257 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3259 nine_context_set_vertex_shader_constant_i(This
, StartRegister
, pConstantData
, Vector4iCount
);
3265 NineDevice9_GetVertexShaderConstantI( struct NineDevice9
*This
,
3268 UINT Vector4iCount
)
3270 const struct nine_state
*state
= &This
->state
;
3273 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3274 D3DERR_INVALIDCALL
);
3275 user_assert(StartRegister
+ Vector4iCount
<= (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3276 D3DERR_INVALIDCALL
);
3277 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3279 if (This
->driver_caps
.vs_integer
) {
3280 memcpy(pConstantData
,
3281 &state
->vs_const_i
[4 * StartRegister
],
3282 Vector4iCount
* sizeof(int[4]));
3284 for (i
= 0; i
< Vector4iCount
; i
++) {
3285 pConstantData
[4 * i
] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
)]);
3286 pConstantData
[4 * i
+ 1] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
) + 1]);
3287 pConstantData
[4 * i
+ 2] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
) + 2]);
3288 pConstantData
[4 * i
+ 3] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
) + 3]);
3296 NineDevice9_SetVertexShaderConstantB( struct NineDevice9
*This
,
3298 const BOOL
*pConstantData
,
3301 struct nine_state
*state
= This
->update
;
3303 uint32_t bool_true
= This
->driver_caps
.vs_integer
? 0xFFFFFFFF : fui(1.0f
);
3305 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3306 This
, StartRegister
, pConstantData
, BoolCount
);
3308 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3309 D3DERR_INVALIDCALL
);
3310 user_assert(StartRegister
+ BoolCount
<= (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3311 D3DERR_INVALIDCALL
);
3312 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3314 if (!This
->is_recording
) {
3315 bool noChange
= true;
3316 for (i
= 0; i
< BoolCount
; i
++) {
3317 if (!!state
->vs_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3324 for (i
= 0; i
< BoolCount
; i
++)
3325 state
->vs_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3327 if (unlikely(This
->is_recording
)) {
3328 nine_ranges_insert(&state
->changed
.vs_const_b
,
3329 StartRegister
, StartRegister
+ BoolCount
,
3331 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3333 nine_context_set_vertex_shader_constant_b(This
, StartRegister
, pConstantData
, BoolCount
);
3339 NineDevice9_GetVertexShaderConstantB( struct NineDevice9
*This
,
3341 BOOL
*pConstantData
,
3344 const struct nine_state
*state
= &This
->state
;
3347 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3348 D3DERR_INVALIDCALL
);
3349 user_assert(StartRegister
+ BoolCount
<= (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3350 D3DERR_INVALIDCALL
);
3351 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3353 for (i
= 0; i
< BoolCount
; i
++)
3354 pConstantData
[i
] = state
->vs_const_b
[StartRegister
+ i
] != 0 ? TRUE
: FALSE
;
3360 NineDevice9_SetStreamSource( struct NineDevice9
*This
,
3362 IDirect3DVertexBuffer9
*pStreamData
,
3366 struct nine_state
*state
= This
->update
;
3367 struct NineVertexBuffer9
*pVBuf9
= NineVertexBuffer9(pStreamData
);
3368 const unsigned i
= StreamNumber
;
3370 DBG("This=%p StreamNumber=%u pStreamData=%p OffsetInBytes=%u Stride=%u\n",
3371 This
, StreamNumber
, pStreamData
, OffsetInBytes
, Stride
);
3373 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3374 user_assert(Stride
<= This
->caps
.MaxStreamStride
, D3DERR_INVALIDCALL
);
3376 if (unlikely(This
->is_recording
)) {
3377 nine_bind(&state
->stream
[i
], pStreamData
);
3378 state
->changed
.vtxbuf
|= 1 << StreamNumber
;
3379 state
->vtxbuf
[i
].stride
= Stride
;
3380 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3384 if (state
->stream
[i
] == NineVertexBuffer9(pStreamData
) &&
3385 state
->vtxbuf
[i
].stride
== Stride
&&
3386 state
->vtxbuf
[i
].buffer_offset
== OffsetInBytes
)
3389 state
->vtxbuf
[i
].stride
= Stride
;
3390 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3392 nine_bind(&state
->stream
[i
], pStreamData
);
3394 nine_context_set_stream_source(This
,
3404 NineDevice9_GetStreamSource( struct NineDevice9
*This
,
3406 IDirect3DVertexBuffer9
**ppStreamData
,
3407 UINT
*pOffsetInBytes
,
3410 const struct nine_state
*state
= &This
->state
;
3411 const unsigned i
= StreamNumber
;
3413 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3414 user_assert(ppStreamData
, D3DERR_INVALIDCALL
);
3416 nine_reference_set(ppStreamData
, state
->stream
[i
]);
3417 *pStride
= state
->vtxbuf
[i
].stride
;
3418 *pOffsetInBytes
= state
->vtxbuf
[i
].buffer_offset
;
3424 NineDevice9_SetStreamSourceFreq( struct NineDevice9
*This
,
3428 struct nine_state
*state
= This
->update
;
3429 /* const UINT freq = Setting & 0x7FFFFF; */
3431 DBG("This=%p StreamNumber=%u FrequencyParameter=0x%x\n", This
,
3432 StreamNumber
, Setting
);
3434 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3435 user_assert(StreamNumber
!= 0 || !(Setting
& D3DSTREAMSOURCE_INSTANCEDATA
),
3436 D3DERR_INVALIDCALL
);
3437 user_assert(!((Setting
& D3DSTREAMSOURCE_INSTANCEDATA
) &&
3438 (Setting
& D3DSTREAMSOURCE_INDEXEDDATA
)), D3DERR_INVALIDCALL
);
3439 user_assert(Setting
, D3DERR_INVALIDCALL
);
3441 if (unlikely(This
->is_recording
)) {
3442 state
->stream_freq
[StreamNumber
] = Setting
;
3443 state
->changed
.stream_freq
|= 1 << StreamNumber
;
3444 if (StreamNumber
!= 0)
3445 state
->changed
.group
|= NINE_STATE_STREAMFREQ
;
3449 if (state
->stream_freq
[StreamNumber
] == Setting
)
3452 state
->stream_freq
[StreamNumber
] = Setting
;
3454 nine_context_set_stream_source_freq(This
, StreamNumber
, Setting
);
3459 NineDevice9_GetStreamSourceFreq( struct NineDevice9
*This
,
3463 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3464 *pSetting
= This
->state
.stream_freq
[StreamNumber
];
3469 NineDevice9_SetIndices( struct NineDevice9
*This
,
3470 IDirect3DIndexBuffer9
*pIndexData
)
3472 struct nine_state
*state
= This
->update
;
3473 struct NineIndexBuffer9
*idxbuf
= NineIndexBuffer9(pIndexData
);
3475 DBG("This=%p pIndexData=%p\n", This
, pIndexData
);
3477 if (unlikely(This
->is_recording
)) {
3478 nine_bind(&state
->idxbuf
, idxbuf
);
3479 state
->changed
.group
|= NINE_STATE_IDXBUF
;
3483 if (state
->idxbuf
== idxbuf
)
3485 nine_bind(&state
->idxbuf
, idxbuf
);
3487 nine_context_set_indices(This
, idxbuf
);
3492 /* XXX: wine/d3d9 doesn't have pBaseVertexIndex, and it doesn't make sense
3493 * here because it's an argument passed to the Draw calls.
3496 NineDevice9_GetIndices( struct NineDevice9
*This
,
3497 IDirect3DIndexBuffer9
**ppIndexData
)
3499 user_assert(ppIndexData
, D3DERR_INVALIDCALL
);
3500 nine_reference_set(ppIndexData
, This
->state
.idxbuf
);
3505 NineDevice9_CreatePixelShader( struct NineDevice9
*This
,
3506 const DWORD
*pFunction
,
3507 IDirect3DPixelShader9
**ppShader
)
3509 struct NinePixelShader9
*ps
;
3512 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3514 hr
= NinePixelShader9_new(This
, &ps
, pFunction
, NULL
);
3517 *ppShader
= (IDirect3DPixelShader9
*)ps
;
3522 NineDevice9_SetPixelShader( struct NineDevice9
*This
,
3523 IDirect3DPixelShader9
*pShader
)
3525 struct nine_state
*state
= This
->update
;
3526 struct NinePixelShader9
*ps
= (struct NinePixelShader9
*)pShader
;
3528 DBG("This=%p pShader=%p\n", This
, pShader
);
3530 if (unlikely(This
->is_recording
)) {
3531 /* Technically we need NINE_STATE_FB only
3532 * if the ps mask changes, but put it always
3534 nine_bind(&state
->ps
, pShader
);
3535 state
->changed
.group
|= NINE_STATE_PS
| NINE_STATE_FB
;
3539 if (state
->ps
== ps
)
3542 nine_bind(&state
->ps
, ps
);
3544 nine_context_set_pixel_shader(This
, ps
);
3550 NineDevice9_GetPixelShader( struct NineDevice9
*This
,
3551 IDirect3DPixelShader9
**ppShader
)
3553 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3554 nine_reference_set(ppShader
, This
->state
.ps
);
3559 NineDevice9_SetPixelShaderConstantF( struct NineDevice9
*This
,
3561 const float *pConstantData
,
3562 UINT Vector4fCount
)
3564 struct nine_state
*state
= This
->update
;
3566 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3567 This
, StartRegister
, pConstantData
, Vector4fCount
);
3569 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3570 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3574 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3576 if (unlikely(This
->is_recording
)) {
3577 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3579 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3581 nine_ranges_insert(&state
->changed
.ps_const_f
,
3582 StartRegister
, StartRegister
+ Vector4fCount
,
3585 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3589 if (!memcmp(&state
->ps_const_f
[StartRegister
* 4], pConstantData
,
3590 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0])))
3593 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3595 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3597 nine_context_set_pixel_shader_constant_f(This
, StartRegister
, pConstantData
, Vector4fCount
);
3603 NineDevice9_GetPixelShaderConstantF( struct NineDevice9
*This
,
3605 float *pConstantData
,
3606 UINT Vector4fCount
)
3608 const struct nine_state
*state
= &This
->state
;
3610 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3611 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3612 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3614 memcpy(pConstantData
,
3615 &state
->ps_const_f
[StartRegister
* 4],
3616 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3622 NineDevice9_SetPixelShaderConstantI( struct NineDevice9
*This
,
3624 const int *pConstantData
,
3625 UINT Vector4iCount
)
3627 struct nine_state
*state
= This
->update
;
3630 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3631 This
, StartRegister
, pConstantData
, Vector4iCount
);
3633 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3634 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3635 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3637 if (This
->driver_caps
.ps_integer
) {
3638 if (!This
->is_recording
) {
3639 if (!memcmp(&state
->ps_const_i
[StartRegister
][0], pConstantData
,
3640 Vector4iCount
* sizeof(state
->ps_const_i
[0])))
3643 memcpy(&state
->ps_const_i
[StartRegister
][0],
3645 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3647 for (i
= 0; i
< Vector4iCount
; i
++) {
3648 state
->ps_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3649 state
->ps_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3650 state
->ps_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3651 state
->ps_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3655 if (unlikely(This
->is_recording
)) {
3656 state
->changed
.ps_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3657 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3659 nine_context_set_pixel_shader_constant_i(This
, StartRegister
, pConstantData
, Vector4iCount
);
3665 NineDevice9_GetPixelShaderConstantI( struct NineDevice9
*This
,
3668 UINT Vector4iCount
)
3670 const struct nine_state
*state
= &This
->state
;
3673 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3674 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3675 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3677 if (This
->driver_caps
.ps_integer
) {
3678 memcpy(pConstantData
,
3679 &state
->ps_const_i
[StartRegister
][0],
3680 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3682 for (i
= 0; i
< Vector4iCount
; i
++) {
3683 pConstantData
[4*i
] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][0]);
3684 pConstantData
[4*i
+1] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][1]);
3685 pConstantData
[4*i
+2] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][2]);
3686 pConstantData
[4*i
+3] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][3]);
3694 NineDevice9_SetPixelShaderConstantB( struct NineDevice9
*This
,
3696 const BOOL
*pConstantData
,
3699 struct nine_state
*state
= This
->update
;
3701 uint32_t bool_true
= This
->driver_caps
.ps_integer
? 0xFFFFFFFF : fui(1.0f
);
3703 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3704 This
, StartRegister
, pConstantData
, BoolCount
);
3706 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3707 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3708 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3710 if (!This
->is_recording
) {
3711 bool noChange
= true;
3712 for (i
= 0; i
< BoolCount
; i
++) {
3713 if (!!state
->ps_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3720 for (i
= 0; i
< BoolCount
; i
++)
3721 state
->ps_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3723 if (unlikely(This
->is_recording
)) {
3724 state
->changed
.ps_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3725 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3727 nine_context_set_pixel_shader_constant_b(This
, StartRegister
, pConstantData
, BoolCount
);
3733 NineDevice9_GetPixelShaderConstantB( struct NineDevice9
*This
,
3735 BOOL
*pConstantData
,
3738 const struct nine_state
*state
= &This
->state
;
3741 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3742 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3743 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3745 for (i
= 0; i
< BoolCount
; i
++)
3746 pConstantData
[i
] = state
->ps_const_b
[StartRegister
+ i
] ? TRUE
: FALSE
;
3752 NineDevice9_DrawRectPatch( struct NineDevice9
*This
,
3754 const float *pNumSegs
,
3755 const D3DRECTPATCH_INFO
*pRectPatchInfo
)
3757 STUB(D3DERR_INVALIDCALL
);
3761 NineDevice9_DrawTriPatch( struct NineDevice9
*This
,
3763 const float *pNumSegs
,
3764 const D3DTRIPATCH_INFO
*pTriPatchInfo
)
3766 STUB(D3DERR_INVALIDCALL
);
3770 NineDevice9_DeletePatch( struct NineDevice9
*This
,
3773 STUB(D3DERR_INVALIDCALL
);
3777 NineDevice9_CreateQuery( struct NineDevice9
*This
,
3779 IDirect3DQuery9
**ppQuery
)
3781 struct NineQuery9
*query
;
3784 DBG("This=%p Type=%d ppQuery=%p\n", This
, Type
, ppQuery
);
3786 hr
= nine_is_query_supported(This
->screen
, Type
);
3787 if (!ppQuery
|| hr
!= D3D_OK
)
3790 hr
= NineQuery9_new(This
, &query
, Type
);
3793 *ppQuery
= (IDirect3DQuery9
*)query
;
3797 IDirect3DDevice9Vtbl NineDevice9_vtable
= {
3798 (void *)NineUnknown_QueryInterface
,
3799 (void *)NineUnknown_AddRef
,
3800 (void *)NineUnknown_Release
,
3801 (void *)NineDevice9_TestCooperativeLevel
,
3802 (void *)NineDevice9_GetAvailableTextureMem
,
3803 (void *)NineDevice9_EvictManagedResources
,
3804 (void *)NineDevice9_GetDirect3D
,
3805 (void *)NineDevice9_GetDeviceCaps
,
3806 (void *)NineDevice9_GetDisplayMode
,
3807 (void *)NineDevice9_GetCreationParameters
,
3808 (void *)NineDevice9_SetCursorProperties
,
3809 (void *)NineDevice9_SetCursorPosition
,
3810 (void *)NineDevice9_ShowCursor
,
3811 (void *)NineDevice9_CreateAdditionalSwapChain
,
3812 (void *)NineDevice9_GetSwapChain
,
3813 (void *)NineDevice9_GetNumberOfSwapChains
,
3814 (void *)NineDevice9_Reset
,
3815 (void *)NineDevice9_Present
,
3816 (void *)NineDevice9_GetBackBuffer
,
3817 (void *)NineDevice9_GetRasterStatus
,
3818 (void *)NineDevice9_SetDialogBoxMode
,
3819 (void *)NineDevice9_SetGammaRamp
,
3820 (void *)NineDevice9_GetGammaRamp
,
3821 (void *)NineDevice9_CreateTexture
,
3822 (void *)NineDevice9_CreateVolumeTexture
,
3823 (void *)NineDevice9_CreateCubeTexture
,
3824 (void *)NineDevice9_CreateVertexBuffer
,
3825 (void *)NineDevice9_CreateIndexBuffer
,
3826 (void *)NineDevice9_CreateRenderTarget
,
3827 (void *)NineDevice9_CreateDepthStencilSurface
,
3828 (void *)NineDevice9_UpdateSurface
,
3829 (void *)NineDevice9_UpdateTexture
,
3830 (void *)NineDevice9_GetRenderTargetData
,
3831 (void *)NineDevice9_GetFrontBufferData
,
3832 (void *)NineDevice9_StretchRect
,
3833 (void *)NineDevice9_ColorFill
,
3834 (void *)NineDevice9_CreateOffscreenPlainSurface
,
3835 (void *)NineDevice9_SetRenderTarget
,
3836 (void *)NineDevice9_GetRenderTarget
,
3837 (void *)NineDevice9_SetDepthStencilSurface
,
3838 (void *)NineDevice9_GetDepthStencilSurface
,
3839 (void *)NineDevice9_BeginScene
,
3840 (void *)NineDevice9_EndScene
,
3841 (void *)NineDevice9_Clear
,
3842 (void *)NineDevice9_SetTransform
,
3843 (void *)NineDevice9_GetTransform
,
3844 (void *)NineDevice9_MultiplyTransform
,
3845 (void *)NineDevice9_SetViewport
,
3846 (void *)NineDevice9_GetViewport
,
3847 (void *)NineDevice9_SetMaterial
,
3848 (void *)NineDevice9_GetMaterial
,
3849 (void *)NineDevice9_SetLight
,
3850 (void *)NineDevice9_GetLight
,
3851 (void *)NineDevice9_LightEnable
,
3852 (void *)NineDevice9_GetLightEnable
,
3853 (void *)NineDevice9_SetClipPlane
,
3854 (void *)NineDevice9_GetClipPlane
,
3855 (void *)NineDevice9_SetRenderState
,
3856 (void *)NineDevice9_GetRenderState
,
3857 (void *)NineDevice9_CreateStateBlock
,
3858 (void *)NineDevice9_BeginStateBlock
,
3859 (void *)NineDevice9_EndStateBlock
,
3860 (void *)NineDevice9_SetClipStatus
,
3861 (void *)NineDevice9_GetClipStatus
,
3862 (void *)NineDevice9_GetTexture
,
3863 (void *)NineDevice9_SetTexture
,
3864 (void *)NineDevice9_GetTextureStageState
,
3865 (void *)NineDevice9_SetTextureStageState
,
3866 (void *)NineDevice9_GetSamplerState
,
3867 (void *)NineDevice9_SetSamplerState
,
3868 (void *)NineDevice9_ValidateDevice
,
3869 (void *)NineDevice9_SetPaletteEntries
,
3870 (void *)NineDevice9_GetPaletteEntries
,
3871 (void *)NineDevice9_SetCurrentTexturePalette
,
3872 (void *)NineDevice9_GetCurrentTexturePalette
,
3873 (void *)NineDevice9_SetScissorRect
,
3874 (void *)NineDevice9_GetScissorRect
,
3875 (void *)NineDevice9_SetSoftwareVertexProcessing
,
3876 (void *)NineDevice9_GetSoftwareVertexProcessing
,
3877 (void *)NineDevice9_SetNPatchMode
,
3878 (void *)NineDevice9_GetNPatchMode
,
3879 (void *)NineDevice9_DrawPrimitive
,
3880 (void *)NineDevice9_DrawIndexedPrimitive
,
3881 (void *)NineDevice9_DrawPrimitiveUP
,
3882 (void *)NineDevice9_DrawIndexedPrimitiveUP
,
3883 (void *)NineDevice9_ProcessVertices
,
3884 (void *)NineDevice9_CreateVertexDeclaration
,
3885 (void *)NineDevice9_SetVertexDeclaration
,
3886 (void *)NineDevice9_GetVertexDeclaration
,
3887 (void *)NineDevice9_SetFVF
,
3888 (void *)NineDevice9_GetFVF
,
3889 (void *)NineDevice9_CreateVertexShader
,
3890 (void *)NineDevice9_SetVertexShader
,
3891 (void *)NineDevice9_GetVertexShader
,
3892 (void *)NineDevice9_SetVertexShaderConstantF
,
3893 (void *)NineDevice9_GetVertexShaderConstantF
,
3894 (void *)NineDevice9_SetVertexShaderConstantI
,
3895 (void *)NineDevice9_GetVertexShaderConstantI
,
3896 (void *)NineDevice9_SetVertexShaderConstantB
,
3897 (void *)NineDevice9_GetVertexShaderConstantB
,
3898 (void *)NineDevice9_SetStreamSource
,
3899 (void *)NineDevice9_GetStreamSource
,
3900 (void *)NineDevice9_SetStreamSourceFreq
,
3901 (void *)NineDevice9_GetStreamSourceFreq
,
3902 (void *)NineDevice9_SetIndices
,
3903 (void *)NineDevice9_GetIndices
,
3904 (void *)NineDevice9_CreatePixelShader
,
3905 (void *)NineDevice9_SetPixelShader
,
3906 (void *)NineDevice9_GetPixelShader
,
3907 (void *)NineDevice9_SetPixelShaderConstantF
,
3908 (void *)NineDevice9_GetPixelShaderConstantF
,
3909 (void *)NineDevice9_SetPixelShaderConstantI
,
3910 (void *)NineDevice9_GetPixelShaderConstantI
,
3911 (void *)NineDevice9_SetPixelShaderConstantB
,
3912 (void *)NineDevice9_GetPixelShaderConstantB
,
3913 (void *)NineDevice9_DrawRectPatch
,
3914 (void *)NineDevice9_DrawTriPatch
,
3915 (void *)NineDevice9_DeletePatch
,
3916 (void *)NineDevice9_CreateQuery
3919 static const GUID
*NineDevice9_IIDs
[] = {
3920 &IID_IDirect3DDevice9
,
3926 NineDevice9_new( struct pipe_screen
*pScreen
,
3927 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
3929 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
3931 ID3DPresentGroup
*pPresentationGroup
,
3932 struct d3dadapter9_context
*pCTX
,
3934 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
3935 struct NineDevice9
**ppOut
,
3936 int minorVersionNum
)
3939 lock
= !!(pCreationParameters
->BehaviorFlags
& D3DCREATE_MULTITHREADED
);
3941 NINE_NEW(Device9
, ppOut
, lock
, /* args */
3942 pScreen
, pCreationParameters
, pCaps
,
3943 pPresentationParameters
, pD3D9
, pPresentationGroup
, pCTX
,
3944 ex
, pFullscreenDisplayMode
, minorVersionNum
);