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_GetCSO( struct NineDevice9
*This
)
578 NineDevice9_GetCaps( struct NineDevice9
*This
)
584 NineDevice9_PauseRecording( struct NineDevice9
*This
)
587 This
->update
= &This
->state
;
588 This
->is_recording
= FALSE
;
593 NineDevice9_ResumeRecording( struct NineDevice9
*This
)
596 This
->update
= &This
->record
->state
;
597 This
->is_recording
= TRUE
;
602 NineDevice9_TestCooperativeLevel( struct NineDevice9
*This
)
604 if (NineSwapChain9_GetOccluded(This
->swapchains
[0])) {
605 This
->device_needs_reset
= TRUE
;
606 return D3DERR_DEVICELOST
;
607 } else if (NineSwapChain9_ResolutionMismatch(This
->swapchains
[0])) {
608 This
->device_needs_reset
= TRUE
;
609 return D3DERR_DEVICENOTRESET
;
610 } else if (This
->device_needs_reset
) {
611 return D3DERR_DEVICENOTRESET
;
618 NineDevice9_GetAvailableTextureMem( struct NineDevice9
*This
)
620 return This
->available_texture_mem
;
624 NineDevice9_EvictManagedResources( struct NineDevice9
*This
)
626 struct NineBaseTexture9
*tex
;
627 struct NineBuffer9
*buf
;
629 DBG("This=%p\n", This
);
630 LIST_FOR_EACH_ENTRY(tex
, &This
->managed_textures
, list2
) {
631 NineBaseTexture9_UnLoad(tex
);
633 /* Vertex/index buffers don't take a lot of space and aren't accounted
634 * for d3d memory usage. Instead of actually freeing from memory,
635 * just mark the buffer dirty to trigger a re-upload later. We
636 * could just ignore, but some bad behaving apps could rely on it (if
637 * they write outside the locked regions typically). */
638 LIST_FOR_EACH_ENTRY(buf
, &This
->managed_buffers
, managed
.list2
) {
639 NineBuffer9_SetDirty(buf
);
646 NineDevice9_GetDirect3D( struct NineDevice9
*This
,
647 IDirect3D9
**ppD3D9
)
649 user_assert(ppD3D9
!= NULL
, E_POINTER
);
650 IDirect3D9_AddRef(This
->d3d9
);
651 *ppD3D9
= This
->d3d9
;
656 NineDevice9_GetDeviceCaps( struct NineDevice9
*This
,
659 user_assert(pCaps
!= NULL
, D3DERR_INVALIDCALL
);
665 NineDevice9_GetDisplayMode( struct NineDevice9
*This
,
667 D3DDISPLAYMODE
*pMode
)
669 DBG("This=%p iSwapChain=%u pMode=%p\n", This
, iSwapChain
, pMode
);
671 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
673 return NineSwapChain9_GetDisplayMode(This
->swapchains
[iSwapChain
], pMode
);
677 NineDevice9_GetCreationParameters( struct NineDevice9
*This
,
678 D3DDEVICE_CREATION_PARAMETERS
*pParameters
)
680 user_assert(pParameters
!= NULL
, D3DERR_INVALIDCALL
);
681 *pParameters
= This
->params
;
686 NineDevice9_SetCursorProperties( struct NineDevice9
*This
,
689 IDirect3DSurface9
*pCursorBitmap
)
691 struct NineSurface9
*surf
= NineSurface9(pCursorBitmap
);
692 struct pipe_context
*pipe
= This
->pipe
;
694 struct pipe_transfer
*transfer
;
698 DBG_FLAG(DBG_SWAPCHAIN
, "This=%p XHotSpot=%u YHotSpot=%u "
699 "pCursorBitmap=%p\n", This
, XHotSpot
, YHotSpot
, pCursorBitmap
);
701 user_assert(pCursorBitmap
, D3DERR_INVALIDCALL
);
702 user_assert(surf
->desc
.Format
== D3DFMT_A8R8G8B8
, D3DERR_INVALIDCALL
);
704 if (This
->swapchains
[0]->params
.Windowed
) {
705 This
->cursor
.w
= MIN2(surf
->desc
.Width
, 32);
706 This
->cursor
.h
= MIN2(surf
->desc
.Height
, 32);
707 hw_cursor
= 1; /* always use hw cursor for windowed mode */
709 This
->cursor
.w
= MIN2(surf
->desc
.Width
, This
->cursor
.image
->width0
);
710 This
->cursor
.h
= MIN2(surf
->desc
.Height
, This
->cursor
.image
->height0
);
711 hw_cursor
= This
->cursor
.w
== 32 && This
->cursor
.h
== 32;
714 u_box_origin_2d(This
->cursor
.w
, This
->cursor
.h
, &box
);
716 ptr
= pipe
->transfer_map(pipe
, This
->cursor
.image
, 0,
717 PIPE_TRANSFER_WRITE
|
718 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
721 ret_err("Failed to update cursor image.\n", D3DERR_DRIVERINTERNALERROR
);
723 This
->cursor
.hotspot
.x
= XHotSpot
;
724 This
->cursor
.hotspot
.y
= YHotSpot
;
726 /* Copy cursor image to internal storage. */
730 const struct util_format_description
*sfmt
=
731 util_format_description(surf
->base
.info
.format
);
734 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, D3DLOCK_READONLY
);
736 ret_err("Failed to map cursor source image.\n",
737 D3DERR_DRIVERINTERNALERROR
);
739 sfmt
->unpack_rgba_8unorm(ptr
, transfer
->stride
,
740 lock
.pBits
, lock
.Pitch
,
741 This
->cursor
.w
, This
->cursor
.h
);
744 void *data
= lock
.pBits
;
745 /* SetCursor assumes 32x32 argb with pitch 128 */
746 if (lock
.Pitch
!= 128) {
747 sfmt
->unpack_rgba_8unorm(This
->cursor
.hw_upload_temp
, 128,
748 lock
.pBits
, lock
.Pitch
,
750 data
= This
->cursor
.hw_upload_temp
;
752 hw_cursor
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
,
754 &This
->cursor
.hotspot
,
755 This
->cursor
.visible
) == D3D_OK
;
758 NineSurface9_UnlockRect(surf
);
760 pipe
->transfer_unmap(pipe
, transfer
);
762 /* hide cursor if we emulate it */
764 ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, FALSE
);
765 This
->cursor
.software
= !hw_cursor
;
771 NineDevice9_SetCursorPosition( struct NineDevice9
*This
,
776 struct NineSwapChain9
*swap
= This
->swapchains
[0];
778 DBG("This=%p X=%d Y=%d Flags=%d\n", This
, X
, Y
, Flags
);
780 This
->cursor
.pos
.x
= X
;
781 This
->cursor
.pos
.y
= Y
;
783 if (!This
->cursor
.software
)
784 This
->cursor
.software
= ID3DPresent_SetCursorPos(swap
->present
, &This
->cursor
.pos
) != D3D_OK
;
788 NineDevice9_ShowCursor( struct NineDevice9
*This
,
791 BOOL old
= This
->cursor
.visible
;
793 DBG("This=%p bShow=%d\n", This
, (int) bShow
);
795 This
->cursor
.visible
= bShow
&& (This
->cursor
.hotspot
.x
!= -1);
796 if (!This
->cursor
.software
)
797 This
->cursor
.software
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, bShow
) != D3D_OK
;
803 NineDevice9_CreateAdditionalSwapChain( struct NineDevice9
*This
,
804 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
805 IDirect3DSwapChain9
**pSwapChain
)
807 struct NineSwapChain9
*swapchain
, *tmplt
= This
->swapchains
[0];
808 ID3DPresent
*present
;
811 DBG("This=%p pPresentationParameters=%p pSwapChain=%p\n",
812 This
, pPresentationParameters
, pSwapChain
);
814 user_assert(pPresentationParameters
, D3DERR_INVALIDCALL
);
815 user_assert(tmplt
->params
.Windowed
&& pPresentationParameters
->Windowed
, D3DERR_INVALIDCALL
);
817 /* TODO: this deserves more tests */
818 if (!pPresentationParameters
->hDeviceWindow
)
819 pPresentationParameters
->hDeviceWindow
= This
->params
.hFocusWindow
;
821 hr
= ID3DPresentGroup_CreateAdditionalPresent(This
->present
, pPresentationParameters
, &present
);
826 hr
= NineSwapChain9_new(This
, FALSE
, present
, pPresentationParameters
,
828 tmplt
->params
.hDeviceWindow
,
833 *pSwapChain
= (IDirect3DSwapChain9
*)swapchain
;
838 NineDevice9_GetSwapChain( struct NineDevice9
*This
,
840 IDirect3DSwapChain9
**pSwapChain
)
842 user_assert(pSwapChain
!= NULL
, D3DERR_INVALIDCALL
);
845 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
847 NineUnknown_AddRef(NineUnknown(This
->swapchains
[iSwapChain
]));
848 *pSwapChain
= (IDirect3DSwapChain9
*)This
->swapchains
[iSwapChain
];
854 NineDevice9_GetNumberOfSwapChains( struct NineDevice9
*This
)
856 return This
->nswapchains
;
860 NineDevice9_Reset( struct NineDevice9
*This
,
861 D3DPRESENT_PARAMETERS
*pPresentationParameters
)
866 DBG("This=%p pPresentationParameters=%p\n", This
, pPresentationParameters
);
868 if (NineSwapChain9_GetOccluded(This
->swapchains
[0])) {
869 This
->device_needs_reset
= TRUE
;
870 return D3DERR_DEVICELOST
;
873 for (i
= 0; i
< This
->nswapchains
; ++i
) {
874 D3DPRESENT_PARAMETERS
*params
= &pPresentationParameters
[i
];
875 hr
= NineSwapChain9_Resize(This
->swapchains
[i
], params
, NULL
);
880 nine_pipe_context_clear(This
);
881 nine_state_clear(&This
->state
, TRUE
);
882 nine_context_clear(&This
->context
);
884 NineDevice9_SetDefaultState(This
, TRUE
);
885 NineDevice9_SetRenderTarget(
886 This
, 0, (IDirect3DSurface9
*)This
->swapchains
[0]->buffers
[0]);
887 /* XXX: better use GetBackBuffer here ? */
889 This
->device_needs_reset
= (hr
!= D3D_OK
);
894 NineDevice9_Present( struct NineDevice9
*This
,
895 const RECT
*pSourceRect
,
896 const RECT
*pDestRect
,
897 HWND hDestWindowOverride
,
898 const RGNDATA
*pDirtyRegion
)
903 DBG("This=%p pSourceRect=%p pDestRect=%p hDestWindowOverride=%p pDirtyRegion=%p\n",
904 This
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
906 /* XXX is this right? */
907 for (i
= 0; i
< This
->nswapchains
; ++i
) {
908 hr
= NineSwapChain9_Present(This
->swapchains
[i
], pSourceRect
, pDestRect
,
909 hDestWindowOverride
, pDirtyRegion
, 0);
910 if (FAILED(hr
)) { return hr
; }
917 NineDevice9_GetBackBuffer( struct NineDevice9
*This
,
920 D3DBACKBUFFER_TYPE Type
,
921 IDirect3DSurface9
**ppBackBuffer
)
923 user_assert(ppBackBuffer
!= NULL
, D3DERR_INVALIDCALL
);
924 /* return NULL on error */
925 *ppBackBuffer
= NULL
;
926 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
928 return NineSwapChain9_GetBackBuffer(This
->swapchains
[iSwapChain
],
929 iBackBuffer
, Type
, ppBackBuffer
);
933 NineDevice9_GetRasterStatus( struct NineDevice9
*This
,
935 D3DRASTER_STATUS
*pRasterStatus
)
937 user_assert(pRasterStatus
!= NULL
, D3DERR_INVALIDCALL
);
938 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
940 return NineSwapChain9_GetRasterStatus(This
->swapchains
[iSwapChain
],
945 NineDevice9_SetDialogBoxMode( struct NineDevice9
*This
,
946 BOOL bEnableDialogs
)
948 STUB(D3DERR_INVALIDCALL
);
952 NineDevice9_SetGammaRamp( struct NineDevice9
*This
,
955 const D3DGAMMARAMP
*pRamp
)
957 DBG("This=%p iSwapChain=%u Flags=%x pRamp=%p\n", This
,
958 iSwapChain
, Flags
, pRamp
);
960 user_warn(iSwapChain
>= This
->nswapchains
);
963 if (pRamp
&& (iSwapChain
< This
->nswapchains
)) {
964 struct NineSwapChain9
*swap
= This
->swapchains
[iSwapChain
];
965 swap
->gamma
= *pRamp
;
966 ID3DPresent_SetGammaRamp(swap
->present
, pRamp
, swap
->params
.hDeviceWindow
);
971 NineDevice9_GetGammaRamp( struct NineDevice9
*This
,
973 D3DGAMMARAMP
*pRamp
)
975 DBG("This=%p iSwapChain=%u pRamp=%p\n", This
, iSwapChain
, pRamp
);
977 user_warn(iSwapChain
>= This
->nswapchains
);
980 if (pRamp
&& (iSwapChain
< This
->nswapchains
))
981 *pRamp
= This
->swapchains
[iSwapChain
]->gamma
;
985 NineDevice9_CreateTexture( struct NineDevice9
*This
,
992 IDirect3DTexture9
**ppTexture
,
993 HANDLE
*pSharedHandle
)
995 struct NineTexture9
*tex
;
998 DBG("This=%p Width=%u Height=%u Levels=%u Usage=%s Format=%s Pool=%s "
999 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Levels
,
1000 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
1001 nine_D3DPOOL_to_str(Pool
), ppTexture
, pSharedHandle
);
1003 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DMAP
|
1004 D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
1005 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
;
1009 hr
= NineTexture9_new(This
, Width
, Height
, Levels
, Usage
, Format
, Pool
,
1010 &tex
, pSharedHandle
);
1012 *ppTexture
= (IDirect3DTexture9
*)tex
;
1018 NineDevice9_CreateVolumeTexture( struct NineDevice9
*This
,
1026 IDirect3DVolumeTexture9
**ppVolumeTexture
,
1027 HANDLE
*pSharedHandle
)
1029 struct NineVolumeTexture9
*tex
;
1032 DBG("This=%p Width=%u Height=%u Depth=%u Levels=%u Usage=%s Format=%s Pool=%s "
1033 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Depth
, Levels
,
1034 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
1035 nine_D3DPOOL_to_str(Pool
), ppVolumeTexture
, pSharedHandle
);
1037 Usage
&= D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1038 D3DUSAGE_SOFTWAREPROCESSING
;
1040 *ppVolumeTexture
= NULL
;
1042 hr
= NineVolumeTexture9_new(This
, Width
, Height
, Depth
, Levels
,
1043 Usage
, Format
, Pool
, &tex
, pSharedHandle
);
1045 *ppVolumeTexture
= (IDirect3DVolumeTexture9
*)tex
;
1051 NineDevice9_CreateCubeTexture( struct NineDevice9
*This
,
1057 IDirect3DCubeTexture9
**ppCubeTexture
,
1058 HANDLE
*pSharedHandle
)
1060 struct NineCubeTexture9
*tex
;
1063 DBG("This=%p EdgeLength=%u Levels=%u Usage=%s Format=%s Pool=%s ppOut=%p "
1064 "pSharedHandle=%p\n", This
, EdgeLength
, Levels
,
1065 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
1066 nine_D3DPOOL_to_str(Pool
), ppCubeTexture
, pSharedHandle
);
1068 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DYNAMIC
|
1069 D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
1070 D3DUSAGE_SOFTWAREPROCESSING
;
1072 *ppCubeTexture
= NULL
;
1074 hr
= NineCubeTexture9_new(This
, EdgeLength
, Levels
, Usage
, Format
, Pool
,
1075 &tex
, pSharedHandle
);
1077 *ppCubeTexture
= (IDirect3DCubeTexture9
*)tex
;
1083 NineDevice9_CreateVertexBuffer( struct NineDevice9
*This
,
1088 IDirect3DVertexBuffer9
**ppVertexBuffer
,
1089 HANDLE
*pSharedHandle
)
1091 struct NineVertexBuffer9
*buf
;
1093 D3DVERTEXBUFFER_DESC desc
;
1095 DBG("This=%p Length=%u Usage=%x FVF=%x Pool=%u ppOut=%p pSharedHandle=%p\n",
1096 This
, Length
, Usage
, FVF
, Pool
, ppVertexBuffer
, pSharedHandle
);
1098 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1100 desc
.Format
= D3DFMT_VERTEXDATA
;
1101 desc
.Type
= D3DRTYPE_VERTEXBUFFER
;
1102 desc
.Usage
= Usage
&
1103 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1104 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1105 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
|
1106 D3DUSAGE_WRITEONLY
);
1111 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1112 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1114 hr
= NineVertexBuffer9_new(This
, &desc
, &buf
);
1116 *ppVertexBuffer
= (IDirect3DVertexBuffer9
*)buf
;
1121 NineDevice9_CreateIndexBuffer( struct NineDevice9
*This
,
1126 IDirect3DIndexBuffer9
**ppIndexBuffer
,
1127 HANDLE
*pSharedHandle
)
1129 struct NineIndexBuffer9
*buf
;
1131 D3DINDEXBUFFER_DESC desc
;
1133 DBG("This=%p Length=%u Usage=%x Format=%s Pool=%u ppOut=%p "
1134 "pSharedHandle=%p\n", This
, Length
, Usage
,
1135 d3dformat_to_string(Format
), Pool
, ppIndexBuffer
, pSharedHandle
);
1137 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1139 desc
.Format
= Format
;
1140 desc
.Type
= D3DRTYPE_INDEXBUFFER
;
1141 desc
.Usage
= Usage
&
1142 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1143 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1144 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_WRITEONLY
);
1148 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1149 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1151 hr
= NineIndexBuffer9_new(This
, &desc
, &buf
);
1153 *ppIndexBuffer
= (IDirect3DIndexBuffer9
*)buf
;
1158 create_zs_or_rt_surface(struct NineDevice9
*This
,
1159 unsigned type
, /* 0 = RT, 1 = ZS, 2 = plain */
1161 UINT Width
, UINT Height
,
1163 D3DMULTISAMPLE_TYPE MultiSample
,
1164 DWORD MultisampleQuality
,
1165 BOOL Discard_or_Lockable
,
1166 IDirect3DSurface9
**ppSurface
,
1167 HANDLE
*pSharedHandle
)
1169 struct NineSurface9
*surface
;
1171 D3DSURFACE_DESC desc
;
1173 DBG("This=%p type=%u Pool=%s Width=%u Height=%u Format=%s MS=%u Quality=%u "
1174 "Discard_or_Lockable=%i ppSurface=%p pSharedHandle=%p\n",
1175 This
, type
, nine_D3DPOOL_to_str(Pool
), Width
, Height
,
1176 d3dformat_to_string(Format
), MultiSample
, MultisampleQuality
,
1177 Discard_or_Lockable
, ppSurface
, pSharedHandle
);
1180 DBG("FIXME Used shared handle! This option isn't probably handled correctly!\n");
1182 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
1183 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1185 desc
.Format
= Format
;
1186 desc
.Type
= D3DRTYPE_SURFACE
;
1189 desc
.MultiSampleType
= MultiSample
;
1190 desc
.MultiSampleQuality
= MultisampleQuality
;
1192 desc
.Height
= Height
;
1194 case 0: desc
.Usage
= D3DUSAGE_RENDERTARGET
; break;
1195 case 1: desc
.Usage
= D3DUSAGE_DEPTHSTENCIL
; break;
1196 default: assert(type
== 2); break;
1199 hr
= NineSurface9_new(This
, NULL
, NULL
, NULL
, 0, 0, 0, &desc
, &surface
);
1200 if (SUCCEEDED(hr
)) {
1201 *ppSurface
= (IDirect3DSurface9
*)surface
;
1203 if (surface
->base
.resource
&& Discard_or_Lockable
&& (type
!= 1))
1204 surface
->base
.resource
->flags
|= NINE_RESOURCE_FLAG_LOCKABLE
;
1211 NineDevice9_CreateRenderTarget( struct NineDevice9
*This
,
1215 D3DMULTISAMPLE_TYPE MultiSample
,
1216 DWORD MultisampleQuality
,
1218 IDirect3DSurface9
**ppSurface
,
1219 HANDLE
*pSharedHandle
)
1222 return create_zs_or_rt_surface(This
, 0, D3DPOOL_DEFAULT
,
1223 Width
, Height
, Format
,
1224 MultiSample
, MultisampleQuality
,
1225 Lockable
, ppSurface
, pSharedHandle
);
1229 NineDevice9_CreateDepthStencilSurface( struct NineDevice9
*This
,
1233 D3DMULTISAMPLE_TYPE MultiSample
,
1234 DWORD MultisampleQuality
,
1236 IDirect3DSurface9
**ppSurface
,
1237 HANDLE
*pSharedHandle
)
1240 if (!depth_stencil_format(Format
))
1241 return D3DERR_NOTAVAILABLE
;
1242 return create_zs_or_rt_surface(This
, 1, D3DPOOL_DEFAULT
,
1243 Width
, Height
, Format
,
1244 MultiSample
, MultisampleQuality
,
1245 Discard
, ppSurface
, pSharedHandle
);
1249 NineDevice9_UpdateSurface( struct NineDevice9
*This
,
1250 IDirect3DSurface9
*pSourceSurface
,
1251 const RECT
*pSourceRect
,
1252 IDirect3DSurface9
*pDestinationSurface
,
1253 const POINT
*pDestPoint
)
1255 struct NineSurface9
*dst
= NineSurface9(pDestinationSurface
);
1256 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1257 int copy_width
, copy_height
;
1260 DBG("This=%p pSourceSurface=%p pDestinationSurface=%p "
1261 "pSourceRect=%p pDestPoint=%p\n", This
,
1262 pSourceSurface
, pDestinationSurface
, pSourceRect
, pDestPoint
);
1264 DBG("pSourceRect = (%u,%u)-(%u,%u)\n",
1265 pSourceRect
->left
, pSourceRect
->top
,
1266 pSourceRect
->right
, pSourceRect
->bottom
);
1268 DBG("pDestPoint = (%u,%u)\n", pDestPoint
->x
, pDestPoint
->y
);
1270 user_assert(dst
&& src
, D3DERR_INVALIDCALL
);
1272 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1273 user_assert(src
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1275 user_assert(dst
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1276 user_assert(src
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1278 user_assert(!src
->lock_count
, D3DERR_INVALIDCALL
);
1279 user_assert(!dst
->lock_count
, D3DERR_INVALIDCALL
);
1281 user_assert(dst
->desc
.Format
== src
->desc
.Format
, D3DERR_INVALIDCALL
);
1282 user_assert(!depth_stencil_format(dst
->desc
.Format
), D3DERR_INVALIDCALL
);
1285 copy_width
= pSourceRect
->right
- pSourceRect
->left
;
1286 copy_height
= pSourceRect
->bottom
- pSourceRect
->top
;
1288 user_assert(pSourceRect
->left
>= 0 &&
1290 pSourceRect
->right
<= src
->desc
.Width
&&
1291 pSourceRect
->top
>= 0 &&
1293 pSourceRect
->bottom
<= src
->desc
.Height
,
1294 D3DERR_INVALIDCALL
);
1296 copy_width
= src
->desc
.Width
;
1297 copy_height
= src
->desc
.Height
;
1300 destRect
.right
= copy_width
;
1301 destRect
.bottom
= copy_height
;
1304 user_assert(pDestPoint
->x
>= 0 && pDestPoint
->y
>= 0,
1305 D3DERR_INVALIDCALL
);
1306 destRect
.right
+= pDestPoint
->x
;
1307 destRect
.bottom
+= pDestPoint
->y
;
1310 user_assert(destRect
.right
<= dst
->desc
.Width
&&
1311 destRect
.bottom
<= dst
->desc
.Height
,
1312 D3DERR_INVALIDCALL
);
1314 if (compressed_format(dst
->desc
.Format
)) {
1315 const unsigned w
= util_format_get_blockwidth(dst
->base
.info
.format
);
1316 const unsigned h
= util_format_get_blockheight(dst
->base
.info
.format
);
1319 user_assert(!(pDestPoint
->x
% w
) && !(pDestPoint
->y
% h
),
1320 D3DERR_INVALIDCALL
);
1324 user_assert(!(pSourceRect
->left
% w
) && !(pSourceRect
->top
% h
),
1325 D3DERR_INVALIDCALL
);
1327 if (!(copy_width
== src
->desc
.Width
&&
1328 copy_width
== dst
->desc
.Width
&&
1329 copy_height
== src
->desc
.Height
&&
1330 copy_height
== dst
->desc
.Height
)) {
1331 user_assert(!(copy_width
% w
) && !(copy_height
% h
),
1332 D3DERR_INVALIDCALL
);
1336 NineSurface9_CopyMemToDefault(dst
, src
, pDestPoint
, pSourceRect
);
1342 NineDevice9_UpdateTexture( struct NineDevice9
*This
,
1343 IDirect3DBaseTexture9
*pSourceTexture
,
1344 IDirect3DBaseTexture9
*pDestinationTexture
)
1346 struct NineBaseTexture9
*dstb
= NineBaseTexture9(pDestinationTexture
);
1347 struct NineBaseTexture9
*srcb
= NineBaseTexture9(pSourceTexture
);
1349 unsigned last_src_level
, last_dst_level
;
1352 DBG("This=%p pSourceTexture=%p pDestinationTexture=%p\n", This
,
1353 pSourceTexture
, pDestinationTexture
);
1355 user_assert(pSourceTexture
&& pDestinationTexture
, D3DERR_INVALIDCALL
);
1356 user_assert(pSourceTexture
!= pDestinationTexture
, D3DERR_INVALIDCALL
);
1358 user_assert(dstb
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1359 user_assert(srcb
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1360 user_assert(dstb
->base
.type
== srcb
->base
.type
, D3DERR_INVALIDCALL
);
1361 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ||
1362 dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
, D3DERR_INVALIDCALL
);
1365 * . Different formats
1366 * . Fewer src levels than dst levels (if the opposite, only matching levels
1367 * are supposed to be copied)
1368 * . Levels do not match
1369 * DDI: Actually the above should pass because of legacy applications
1370 * Do what you want about these, but you shouldn't crash.
1371 * However driver can expect that the top dimension is greater for src than dst.
1372 * Wine tests: Every combination that passes the initial checks should pass.
1373 * . Different formats => conversion driver and format dependent.
1374 * . 1 level, but size not matching => copy is done (and even crash if src bigger
1375 * than dst. For the case where dst bigger, wine doesn't test if a stretch is applied
1376 * or if a subrect is copied).
1377 * . 8x8 4 sublevels -> 7x7 2 sublevels => driver dependent, On NV seems to be 4x4 subrect
1380 * From these, the proposal is:
1381 * . Different formats -> use util_format_translate to translate if possible for surfaces.
1382 * Accept ARGB/XRGB for Volumes. Do nothing for the other combinations
1383 * . First level copied -> the first level such that src is smaller or equal to dst first level
1384 * . number of levels copied -> as long as it fits and textures have levels
1385 * That should satisfy the constraints (and instead of crashing for some cases we return D3D_OK)
1388 last_src_level
= (srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ? 0 : srcb
->base
.info
.last_level
;
1389 last_dst_level
= (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ? 0 : dstb
->base
.info
.last_level
;
1391 for (m
= 0; m
<= last_src_level
; ++m
) {
1392 unsigned w
= u_minify(srcb
->base
.info
.width0
, m
);
1393 unsigned h
= u_minify(srcb
->base
.info
.height0
, m
);
1394 unsigned d
= u_minify(srcb
->base
.info
.depth0
, m
);
1396 if (w
<= dstb
->base
.info
.width0
&&
1397 h
<= dstb
->base
.info
.height0
&&
1398 d
<= dstb
->base
.info
.depth0
)
1401 user_assert(m
<= last_src_level
, D3D_OK
);
1403 last_dst_level
= MIN2(srcb
->base
.info
.last_level
- m
, last_dst_level
);
1405 if (dstb
->base
.type
== D3DRTYPE_TEXTURE
) {
1406 struct NineTexture9
*dst
= NineTexture9(dstb
);
1407 struct NineTexture9
*src
= NineTexture9(srcb
);
1409 if (src
->dirty_rect
.width
== 0)
1412 pipe_box_to_rect(&rect
, &src
->dirty_rect
);
1413 for (l
= 0; l
< m
; ++l
)
1414 rect_minify_inclusive(&rect
);
1416 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
) {
1417 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1419 dst
->surfaces
[l
]->desc
.Width
,
1420 dst
->surfaces
[l
]->desc
.Height
);
1421 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
],
1425 rect_minify_inclusive(&rect
);
1427 u_box_origin_2d(0, 0, &src
->dirty_rect
);
1429 if (dstb
->base
.type
== D3DRTYPE_CUBETEXTURE
) {
1430 struct NineCubeTexture9
*dst
= NineCubeTexture9(dstb
);
1431 struct NineCubeTexture9
*src
= NineCubeTexture9(srcb
);
1434 /* GPUs usually have them stored as arrays of mip-mapped 2D textures. */
1435 for (z
= 0; z
< 6; ++z
) {
1436 if (src
->dirty_rect
[z
].width
== 0)
1439 pipe_box_to_rect(&rect
, &src
->dirty_rect
[z
]);
1440 for (l
= 0; l
< m
; ++l
)
1441 rect_minify_inclusive(&rect
);
1443 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
) {
1444 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1446 dst
->surfaces
[l
* 6 + z
]->desc
.Width
,
1447 dst
->surfaces
[l
* 6 + z
]->desc
.Height
);
1448 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
* 6 + z
],
1449 src
->surfaces
[m
* 6 + z
],
1452 rect_minify_inclusive(&rect
);
1454 u_box_origin_2d(0, 0, &src
->dirty_rect
[z
]);
1458 if (dstb
->base
.type
== D3DRTYPE_VOLUMETEXTURE
) {
1459 struct NineVolumeTexture9
*dst
= NineVolumeTexture9(dstb
);
1460 struct NineVolumeTexture9
*src
= NineVolumeTexture9(srcb
);
1462 if (src
->dirty_box
.width
== 0)
1464 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
)
1465 NineVolume9_CopyMemToDefault(dst
->volumes
[l
],
1466 src
->volumes
[m
], 0, 0, 0, NULL
);
1467 u_box_3d(0, 0, 0, 0, 0, 0, &src
->dirty_box
);
1469 assert(!"invalid texture type");
1472 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1473 dstb
->dirty_mip
= TRUE
;
1474 NineBaseTexture9_GenerateMipSubLevels(dstb
);
1481 NineDevice9_GetRenderTargetData( struct NineDevice9
*This
,
1482 IDirect3DSurface9
*pRenderTarget
,
1483 IDirect3DSurface9
*pDestSurface
)
1485 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1486 struct NineSurface9
*src
= NineSurface9(pRenderTarget
);
1488 DBG("This=%p pRenderTarget=%p pDestSurface=%p\n",
1489 This
, pRenderTarget
, pDestSurface
);
1491 user_assert(pRenderTarget
&& pDestSurface
, D3DERR_INVALIDCALL
);
1493 user_assert(dst
->desc
.Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1494 user_assert(src
->desc
.Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1496 user_assert(dst
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1497 user_assert(src
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1499 user_assert(src
->desc
.Width
== dst
->desc
.Width
, D3DERR_INVALIDCALL
);
1500 user_assert(src
->desc
.Height
== dst
->desc
.Height
, D3DERR_INVALIDCALL
);
1502 user_assert(src
->desc
.Format
!= D3DFMT_NULL
, D3DERR_INVALIDCALL
);
1504 NineSurface9_CopyDefaultToMem(dst
, src
);
1510 NineDevice9_GetFrontBufferData( struct NineDevice9
*This
,
1512 IDirect3DSurface9
*pDestSurface
)
1514 DBG("This=%p iSwapChain=%u pDestSurface=%p\n", This
,
1515 iSwapChain
, pDestSurface
);
1517 user_assert(pDestSurface
!= NULL
, D3DERR_INVALIDCALL
);
1518 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
1520 return NineSwapChain9_GetFrontBufferData(This
->swapchains
[iSwapChain
],
1525 NineDevice9_StretchRect( struct NineDevice9
*This
,
1526 IDirect3DSurface9
*pSourceSurface
,
1527 const RECT
*pSourceRect
,
1528 IDirect3DSurface9
*pDestSurface
,
1529 const RECT
*pDestRect
,
1530 D3DTEXTUREFILTERTYPE Filter
)
1532 struct pipe_screen
*screen
= This
->screen
;
1533 struct pipe_context
*pipe
= This
->pipe
;
1534 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1535 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1536 struct pipe_resource
*dst_res
= NineSurface9_GetResource(dst
);
1537 struct pipe_resource
*src_res
= NineSurface9_GetResource(src
);
1539 struct pipe_blit_info blit
;
1540 boolean scaled
, clamped
, ms
, flip_x
= FALSE
, flip_y
= FALSE
;
1542 DBG("This=%p pSourceSurface=%p pSourceRect=%p pDestSurface=%p "
1543 "pDestRect=%p Filter=%u\n",
1544 This
, pSourceSurface
, pSourceRect
, pDestSurface
, pDestRect
, Filter
);
1546 DBG("pSourceRect=(%u,%u)-(%u,%u)\n",
1547 pSourceRect
->left
, pSourceRect
->top
,
1548 pSourceRect
->right
, pSourceRect
->bottom
);
1550 DBG("pDestRect=(%u,%u)-(%u,%u)\n", pDestRect
->left
, pDestRect
->top
,
1551 pDestRect
->right
, pDestRect
->bottom
);
1553 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
&&
1554 src
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1555 zs
= util_format_is_depth_or_stencil(dst_res
->format
);
1556 user_assert(!zs
|| !This
->in_scene
, D3DERR_INVALIDCALL
);
1557 user_assert(!zs
|| !pSourceRect
||
1558 (pSourceRect
->left
== 0 &&
1559 pSourceRect
->top
== 0 &&
1560 pSourceRect
->right
== src
->desc
.Width
&&
1561 pSourceRect
->bottom
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1562 user_assert(!zs
|| !pDestRect
||
1563 (pDestRect
->left
== 0 &&
1564 pDestRect
->top
== 0 &&
1565 pDestRect
->right
== dst
->desc
.Width
&&
1566 pDestRect
->bottom
== dst
->desc
.Height
), D3DERR_INVALIDCALL
);
1568 (dst
->desc
.Width
== src
->desc
.Width
&&
1569 dst
->desc
.Height
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1570 user_assert(zs
|| !util_format_is_depth_or_stencil(src_res
->format
),
1571 D3DERR_INVALIDCALL
);
1572 user_assert(!zs
|| dst
->desc
.Format
== src
->desc
.Format
,
1573 D3DERR_INVALIDCALL
);
1574 user_assert(screen
->is_format_supported(screen
, src_res
->format
,
1576 src_res
->nr_samples
,
1577 PIPE_BIND_SAMPLER_VIEW
),
1578 D3DERR_INVALIDCALL
);
1580 /* We might want to permit these, but wine thinks we shouldn't. */
1581 user_assert(!pDestRect
||
1582 (pDestRect
->left
<= pDestRect
->right
&&
1583 pDestRect
->top
<= pDestRect
->bottom
), D3DERR_INVALIDCALL
);
1584 user_assert(!pSourceRect
||
1585 (pSourceRect
->left
<= pSourceRect
->right
&&
1586 pSourceRect
->top
<= pSourceRect
->bottom
), D3DERR_INVALIDCALL
);
1588 memset(&blit
, 0, sizeof(blit
));
1589 blit
.dst
.resource
= dst_res
;
1590 blit
.dst
.level
= dst
->level
;
1591 blit
.dst
.box
.z
= dst
->layer
;
1592 blit
.dst
.box
.depth
= 1;
1593 blit
.dst
.format
= dst_res
->format
;
1595 flip_x
= pDestRect
->left
> pDestRect
->right
;
1597 blit
.dst
.box
.x
= pDestRect
->right
;
1598 blit
.dst
.box
.width
= pDestRect
->left
- pDestRect
->right
;
1600 blit
.dst
.box
.x
= pDestRect
->left
;
1601 blit
.dst
.box
.width
= pDestRect
->right
- pDestRect
->left
;
1603 flip_y
= pDestRect
->top
> pDestRect
->bottom
;
1605 blit
.dst
.box
.y
= pDestRect
->bottom
;
1606 blit
.dst
.box
.height
= pDestRect
->top
- pDestRect
->bottom
;
1608 blit
.dst
.box
.y
= pDestRect
->top
;
1609 blit
.dst
.box
.height
= pDestRect
->bottom
- pDestRect
->top
;
1614 blit
.dst
.box
.width
= dst
->desc
.Width
;
1615 blit
.dst
.box
.height
= dst
->desc
.Height
;
1617 blit
.src
.resource
= src_res
;
1618 blit
.src
.level
= src
->level
;
1619 blit
.src
.box
.z
= src
->layer
;
1620 blit
.src
.box
.depth
= 1;
1621 blit
.src
.format
= src_res
->format
;
1623 if (flip_x
^ (pSourceRect
->left
> pSourceRect
->right
)) {
1624 blit
.src
.box
.x
= pSourceRect
->right
;
1625 blit
.src
.box
.width
= pSourceRect
->left
- pSourceRect
->right
;
1627 blit
.src
.box
.x
= pSourceRect
->left
;
1628 blit
.src
.box
.width
= pSourceRect
->right
- pSourceRect
->left
;
1630 if (flip_y
^ (pSourceRect
->top
> pSourceRect
->bottom
)) {
1631 blit
.src
.box
.y
= pSourceRect
->bottom
;
1632 blit
.src
.box
.height
= pSourceRect
->top
- pSourceRect
->bottom
;
1634 blit
.src
.box
.y
= pSourceRect
->top
;
1635 blit
.src
.box
.height
= pSourceRect
->bottom
- pSourceRect
->top
;
1638 blit
.src
.box
.x
= flip_x
? src
->desc
.Width
: 0;
1639 blit
.src
.box
.y
= flip_y
? src
->desc
.Height
: 0;
1640 blit
.src
.box
.width
= flip_x
? -src
->desc
.Width
: src
->desc
.Width
;
1641 blit
.src
.box
.height
= flip_y
? -src
->desc
.Height
: src
->desc
.Height
;
1643 blit
.mask
= zs
? PIPE_MASK_ZS
: PIPE_MASK_RGBA
;
1644 blit
.filter
= Filter
== D3DTEXF_LINEAR
?
1645 PIPE_TEX_FILTER_LINEAR
: PIPE_TEX_FILTER_NEAREST
;
1646 blit
.scissor_enable
= FALSE
;
1647 blit
.alpha_blend
= FALSE
;
1649 /* If both of a src and dst dimension are negative, flip them. */
1650 if (blit
.dst
.box
.width
< 0 && blit
.src
.box
.width
< 0) {
1651 blit
.dst
.box
.width
= -blit
.dst
.box
.width
;
1652 blit
.src
.box
.width
= -blit
.src
.box
.width
;
1654 if (blit
.dst
.box
.height
< 0 && blit
.src
.box
.height
< 0) {
1655 blit
.dst
.box
.height
= -blit
.dst
.box
.height
;
1656 blit
.src
.box
.height
= -blit
.src
.box
.height
;
1659 blit
.dst
.box
.width
!= blit
.src
.box
.width
||
1660 blit
.dst
.box
.height
!= blit
.src
.box
.height
;
1662 user_assert(!scaled
|| dst
!= src
, D3DERR_INVALIDCALL
);
1663 user_assert(!scaled
||
1664 !NineSurface9_IsOffscreenPlain(dst
), D3DERR_INVALIDCALL
);
1665 user_assert(!NineSurface9_IsOffscreenPlain(dst
) ||
1666 NineSurface9_IsOffscreenPlain(src
), D3DERR_INVALIDCALL
);
1667 user_assert(NineSurface9_IsOffscreenPlain(dst
) ||
1668 dst
->desc
.Usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
),
1669 D3DERR_INVALIDCALL
);
1670 user_assert(!scaled
||
1671 (!util_format_is_compressed(dst
->base
.info
.format
) &&
1672 !util_format_is_compressed(src
->base
.info
.format
)),
1673 D3DERR_INVALIDCALL
);
1675 user_warn(src
== dst
&&
1676 u_box_test_intersection_2d(&blit
.src
.box
, &blit
.dst
.box
));
1678 /* Check for clipping/clamping: */
1680 struct pipe_box box
;
1683 xy
= u_box_clip_2d(&box
, &blit
.dst
.box
,
1684 dst
->desc
.Width
, dst
->desc
.Height
);
1688 xy
= u_box_clip_2d(&box
, &blit
.src
.box
,
1689 src
->desc
.Width
, src
->desc
.Height
);
1693 ms
= (dst
->desc
.MultiSampleType
!= src
->desc
.MultiSampleType
) ||
1694 (dst
->desc
.MultiSampleQuality
!= src
->desc
.MultiSampleQuality
);
1696 if (clamped
|| scaled
|| (blit
.dst
.format
!= blit
.src
.format
) || ms
) {
1697 DBG("using pipe->blit()\n");
1698 /* TODO: software scaling */
1699 user_assert(screen
->is_format_supported(screen
, dst_res
->format
,
1701 dst_res
->nr_samples
,
1702 zs
? PIPE_BIND_DEPTH_STENCIL
:
1703 PIPE_BIND_RENDER_TARGET
),
1704 D3DERR_INVALIDCALL
);
1706 pipe
->blit(pipe
, &blit
);
1708 assert(blit
.dst
.box
.x
>= 0 && blit
.dst
.box
.y
>= 0 &&
1709 blit
.src
.box
.x
>= 0 && blit
.src
.box
.y
>= 0 &&
1710 blit
.dst
.box
.x
+ blit
.dst
.box
.width
<= dst
->desc
.Width
&&
1711 blit
.src
.box
.x
+ blit
.src
.box
.width
<= src
->desc
.Width
&&
1712 blit
.dst
.box
.y
+ blit
.dst
.box
.height
<= dst
->desc
.Height
&&
1713 blit
.src
.box
.y
+ blit
.src
.box
.height
<= src
->desc
.Height
);
1714 /* Or drivers might crash ... */
1715 DBG("Using resource_copy_region.\n");
1716 pipe
->resource_copy_region(pipe
,
1717 blit
.dst
.resource
, blit
.dst
.level
,
1718 blit
.dst
.box
.x
, blit
.dst
.box
.y
, blit
.dst
.box
.z
,
1719 blit
.src
.resource
, blit
.src
.level
,
1723 /* Communicate the container it needs to update sublevels - if apply */
1724 NineSurface9_MarkContainerDirty(dst
);
1730 NineDevice9_ColorFill( struct NineDevice9
*This
,
1731 IDirect3DSurface9
*pSurface
,
1735 struct pipe_context
*pipe
= This
->pipe
;
1736 struct NineSurface9
*surf
= NineSurface9(pSurface
);
1737 struct pipe_surface
*psurf
;
1738 unsigned x
, y
, w
, h
;
1739 union pipe_color_union rgba
;
1742 DBG("This=%p pSurface=%p pRect=%p color=%08x\n", This
,
1743 pSurface
, pRect
, color
);
1745 DBG("pRect=(%u,%u)-(%u,%u)\n", pRect
->left
, pRect
->top
,
1746 pRect
->right
, pRect
->bottom
);
1748 user_assert(surf
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1750 user_assert((surf
->base
.usage
& D3DUSAGE_RENDERTARGET
) ||
1751 NineSurface9_IsOffscreenPlain(surf
), D3DERR_INVALIDCALL
);
1753 user_assert(surf
->desc
.Format
!= D3DFMT_NULL
, D3D_OK
);
1758 w
= pRect
->right
- pRect
->left
;
1759 h
= pRect
->bottom
- pRect
->top
;
1761 if (compressed_format(surf
->desc
.Format
)) {
1762 const unsigned bw
= util_format_get_blockwidth(surf
->base
.info
.format
);
1763 const unsigned bh
= util_format_get_blockheight(surf
->base
.info
.format
);
1765 user_assert(!(x
% bw
) && !(y
% bh
) && !(w
% bw
) && !(h
% bh
),
1766 D3DERR_INVALIDCALL
);
1771 w
= surf
->desc
.Width
;
1772 h
= surf
->desc
.Height
;
1774 d3dcolor_to_pipe_color_union(&rgba
, color
);
1776 fallback
= !(surf
->base
.info
.bind
& PIPE_BIND_RENDER_TARGET
);
1779 psurf
= NineSurface9_GetSurface(surf
, 0);
1785 pipe
->clear_render_target(pipe
, psurf
, &rgba
, x
, y
, w
, h
, false);
1787 D3DLOCKED_RECT lock
;
1788 union util_color uc
;
1790 /* XXX: lock pRect and fix util_fill_rect */
1791 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, 0);
1794 util_pack_color_ub(color
>> 16, color
>> 8, color
>> 0, color
>> 24,
1795 surf
->base
.info
.format
, &uc
);
1796 util_fill_rect(lock
.pBits
, surf
->base
.info
.format
,lock
.Pitch
,
1798 NineSurface9_UnlockRect(surf
);
1805 NineDevice9_CreateOffscreenPlainSurface( struct NineDevice9
*This
,
1810 IDirect3DSurface9
**ppSurface
,
1811 HANDLE
*pSharedHandle
)
1815 DBG("This=%p Width=%u Height=%u Format=%s(0x%x) Pool=%u "
1816 "ppSurface=%p pSharedHandle=%p\n", This
,
1817 Width
, Height
, d3dformat_to_string(Format
), Format
, Pool
,
1818 ppSurface
, pSharedHandle
);
1821 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
1822 || Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1823 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1825 /* Can be used with StretchRect and ColorFill. It's also always lockable.
1827 hr
= create_zs_or_rt_surface(This
, 2, Pool
, Width
, Height
,
1829 D3DMULTISAMPLE_NONE
, 0,
1831 ppSurface
, pSharedHandle
);
1833 DBG("Failed to create surface.\n");
1838 NineDevice9_SetRenderTarget( struct NineDevice9
*This
,
1839 DWORD RenderTargetIndex
,
1840 IDirect3DSurface9
*pRenderTarget
)
1842 struct NineSurface9
*rt
= NineSurface9(pRenderTarget
);
1843 const unsigned i
= RenderTargetIndex
;
1845 DBG("This=%p RenderTargetIndex=%u pRenderTarget=%p\n", This
,
1846 RenderTargetIndex
, pRenderTarget
);
1848 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1849 user_assert(i
!= 0 || pRenderTarget
, D3DERR_INVALIDCALL
);
1850 user_assert(!pRenderTarget
||
1851 rt
->desc
.Usage
& D3DUSAGE_RENDERTARGET
, D3DERR_INVALIDCALL
);
1854 This
->state
.viewport
.X
= 0;
1855 This
->state
.viewport
.Y
= 0;
1856 This
->state
.viewport
.Width
= rt
->desc
.Width
;
1857 This
->state
.viewport
.Height
= rt
->desc
.Height
;
1858 This
->state
.viewport
.MinZ
= 0.0f
;
1859 This
->state
.viewport
.MaxZ
= 1.0f
;
1861 This
->state
.scissor
.minx
= 0;
1862 This
->state
.scissor
.miny
= 0;
1863 This
->state
.scissor
.maxx
= rt
->desc
.Width
;
1864 This
->state
.scissor
.maxy
= rt
->desc
.Height
;
1867 if (This
->state
.rt
[i
] != NineSurface9(pRenderTarget
))
1868 nine_bind(&This
->state
.rt
[i
], pRenderTarget
);
1870 nine_context_set_render_target(This
, i
, rt
);
1875 NineDevice9_GetRenderTarget( struct NineDevice9
*This
,
1876 DWORD RenderTargetIndex
,
1877 IDirect3DSurface9
**ppRenderTarget
)
1879 const unsigned i
= RenderTargetIndex
;
1881 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1882 user_assert(ppRenderTarget
, D3DERR_INVALIDCALL
);
1884 *ppRenderTarget
= (IDirect3DSurface9
*)This
->state
.rt
[i
];
1885 if (!This
->state
.rt
[i
])
1886 return D3DERR_NOTFOUND
;
1888 NineUnknown_AddRef(NineUnknown(This
->state
.rt
[i
]));
1893 NineDevice9_SetDepthStencilSurface( struct NineDevice9
*This
,
1894 IDirect3DSurface9
*pNewZStencil
)
1896 DBG("This=%p pNewZStencil=%p\n", This
, pNewZStencil
);
1898 if (This
->state
.ds
!= NineSurface9(pNewZStencil
)) {
1899 nine_bind(&This
->state
.ds
, pNewZStencil
);
1900 This
->state
.changed
.group
|= NINE_STATE_FB
;
1906 NineDevice9_GetDepthStencilSurface( struct NineDevice9
*This
,
1907 IDirect3DSurface9
**ppZStencilSurface
)
1909 user_assert(ppZStencilSurface
, D3DERR_INVALIDCALL
);
1911 *ppZStencilSurface
= (IDirect3DSurface9
*)This
->state
.ds
;
1912 if (!This
->state
.ds
)
1913 return D3DERR_NOTFOUND
;
1915 NineUnknown_AddRef(NineUnknown(This
->state
.ds
));
1920 NineDevice9_BeginScene( struct NineDevice9
*This
)
1922 DBG("This=%p\n", This
);
1923 user_assert(!This
->in_scene
, D3DERR_INVALIDCALL
);
1924 This
->in_scene
= TRUE
;
1925 /* Do we want to do anything else here ? */
1930 NineDevice9_EndScene( struct NineDevice9
*This
)
1932 DBG("This=%p\n", This
);
1933 user_assert(This
->in_scene
, D3DERR_INVALIDCALL
);
1934 This
->in_scene
= FALSE
;
1939 NineDevice9_Clear( struct NineDevice9
*This
,
1941 const D3DRECT
*pRects
,
1947 struct NineSurface9
*zsbuf_surf
= This
->state
.ds
;
1949 DBG("This=%p Count=%u pRects=%p Flags=%x Color=%08x Z=%f Stencil=%x\n",
1950 This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1952 user_assert(This
->state
.ds
|| !(Flags
& NINED3DCLEAR_DEPTHSTENCIL
),
1953 D3DERR_INVALIDCALL
);
1954 user_assert(!(Flags
& D3DCLEAR_STENCIL
) ||
1956 util_format_is_depth_and_stencil(zsbuf_surf
->base
.info
.format
)),
1957 D3DERR_INVALIDCALL
);
1959 user_assert((Count
&& pRects
) || (!Count
&& !pRects
), D3DERR_INVALIDCALL
);
1961 user_warn((pRects
&& !Count
) || (!pRects
&& Count
));
1962 if (pRects
&& !Count
)
1968 nine_context_clear_fb(This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1973 NineDevice9_SetTransform( struct NineDevice9
*This
,
1974 D3DTRANSFORMSTATETYPE State
,
1975 const D3DMATRIX
*pMatrix
)
1977 struct nine_state
*state
= This
->update
;
1978 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
1980 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
1982 user_assert(M
, D3DERR_INVALIDCALL
);
1985 state
->ff
.changed
.transform
[State
/ 32] |= 1 << (State
% 32);
1986 state
->changed
.group
|= NINE_STATE_FF
;
1992 NineDevice9_GetTransform( struct NineDevice9
*This
,
1993 D3DTRANSFORMSTATETYPE State
,
1994 D3DMATRIX
*pMatrix
)
1996 D3DMATRIX
*M
= nine_state_access_transform(&This
->state
, State
, FALSE
);
1997 user_assert(M
, D3DERR_INVALIDCALL
);
2003 NineDevice9_MultiplyTransform( struct NineDevice9
*This
,
2004 D3DTRANSFORMSTATETYPE State
,
2005 const D3DMATRIX
*pMatrix
)
2007 struct nine_state
*state
= This
->update
;
2009 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
2011 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2013 user_assert(M
, D3DERR_INVALIDCALL
);
2015 nine_d3d_matrix_matrix_mul(&T
, pMatrix
, M
);
2016 return NineDevice9_SetTransform(This
, State
, &T
);
2020 NineDevice9_SetViewport( struct NineDevice9
*This
,
2021 const D3DVIEWPORT9
*pViewport
)
2023 struct nine_state
*state
= This
->update
;
2025 DBG("X=%u Y=%u W=%u H=%u MinZ=%f MaxZ=%f\n",
2026 pViewport
->X
, pViewport
->Y
, pViewport
->Width
, pViewport
->Height
,
2027 pViewport
->MinZ
, pViewport
->MaxZ
);
2029 state
->viewport
= *pViewport
;
2030 nine_context_set_viewport(This
, pViewport
);
2036 NineDevice9_GetViewport( struct NineDevice9
*This
,
2037 D3DVIEWPORT9
*pViewport
)
2039 *pViewport
= This
->state
.viewport
;
2044 NineDevice9_SetMaterial( struct NineDevice9
*This
,
2045 const D3DMATERIAL9
*pMaterial
)
2047 struct nine_state
*state
= This
->update
;
2049 DBG("This=%p pMaterial=%p\n", This
, pMaterial
);
2051 nine_dump_D3DMATERIAL9(DBG_FF
, pMaterial
);
2053 user_assert(pMaterial
, E_POINTER
);
2055 state
->ff
.material
= *pMaterial
;
2056 state
->changed
.group
|= NINE_STATE_FF_MATERIAL
;
2062 NineDevice9_GetMaterial( struct NineDevice9
*This
,
2063 D3DMATERIAL9
*pMaterial
)
2065 user_assert(pMaterial
, E_POINTER
);
2066 *pMaterial
= This
->state
.ff
.material
;
2071 NineDevice9_SetLight( struct NineDevice9
*This
,
2073 const D3DLIGHT9
*pLight
)
2075 struct nine_state
*state
= This
->update
;
2077 DBG("This=%p Index=%u pLight=%p\n", This
, Index
, pLight
);
2079 nine_dump_D3DLIGHT9(DBG_FF
, pLight
);
2081 user_assert(pLight
, D3DERR_INVALIDCALL
);
2082 user_assert(pLight
->Type
< NINED3DLIGHT_INVALID
, D3DERR_INVALIDCALL
);
2084 user_assert(Index
< NINE_MAX_LIGHTS
, D3DERR_INVALIDCALL
); /* sanity */
2086 if (Index
>= state
->ff
.num_lights
) {
2087 unsigned n
= state
->ff
.num_lights
;
2088 unsigned N
= Index
+ 1;
2090 state
->ff
.light
= REALLOC(state
->ff
.light
, n
* sizeof(D3DLIGHT9
),
2091 N
* sizeof(D3DLIGHT9
));
2092 if (!state
->ff
.light
)
2093 return E_OUTOFMEMORY
;
2094 state
->ff
.num_lights
= N
;
2096 for (; n
< Index
; ++n
) {
2097 memset(&state
->ff
.light
[n
], 0, sizeof(D3DLIGHT9
));
2098 state
->ff
.light
[n
].Type
= (D3DLIGHTTYPE
)NINED3DLIGHT_INVALID
;
2101 state
->ff
.light
[Index
] = *pLight
;
2103 if (pLight
->Type
== D3DLIGHT_SPOT
&& pLight
->Theta
>= pLight
->Phi
) {
2104 DBG("Warning: clamping D3DLIGHT9.Theta\n");
2105 state
->ff
.light
[Index
].Theta
= state
->ff
.light
[Index
].Phi
;
2107 if (pLight
->Type
!= D3DLIGHT_DIRECTIONAL
&&
2108 pLight
->Attenuation0
== 0.0f
&&
2109 pLight
->Attenuation1
== 0.0f
&&
2110 pLight
->Attenuation2
== 0.0f
) {
2111 DBG("Warning: all D3DLIGHT9.Attenuation[i] are 0\n");
2114 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2120 NineDevice9_GetLight( struct NineDevice9
*This
,
2124 const struct nine_state
*state
= &This
->state
;
2126 user_assert(pLight
, D3DERR_INVALIDCALL
);
2127 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2128 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2129 D3DERR_INVALIDCALL
);
2131 *pLight
= state
->ff
.light
[Index
];
2137 NineDevice9_LightEnable( struct NineDevice9
*This
,
2141 struct nine_state
*state
= This
->update
;
2144 DBG("This=%p Index=%u Enable=%i\n", This
, Index
, Enable
);
2146 if (Index
>= state
->ff
.num_lights
||
2147 state
->ff
.light
[Index
].Type
== NINED3DLIGHT_INVALID
) {
2148 /* This should create a default light. */
2150 memset(&light
, 0, sizeof(light
));
2151 light
.Type
= D3DLIGHT_DIRECTIONAL
;
2152 light
.Diffuse
.r
= 1.0f
;
2153 light
.Diffuse
.g
= 1.0f
;
2154 light
.Diffuse
.b
= 1.0f
;
2155 light
.Direction
.z
= 1.0f
;
2156 NineDevice9_SetLight(This
, Index
, &light
);
2158 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2160 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
) {
2161 if (state
->ff
.active_light
[i
] == Index
)
2166 if (i
< state
->ff
.num_lights_active
)
2168 /* XXX wine thinks this should still succeed:
2170 user_assert(i
< NINE_MAX_LIGHTS_ACTIVE
, D3DERR_INVALIDCALL
);
2172 state
->ff
.active_light
[i
] = Index
;
2173 state
->ff
.num_lights_active
++;
2175 if (i
== state
->ff
.num_lights_active
)
2177 --state
->ff
.num_lights_active
;
2178 for (; i
< state
->ff
.num_lights_active
; ++i
)
2179 state
->ff
.active_light
[i
] = state
->ff
.active_light
[i
+ 1];
2181 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2187 NineDevice9_GetLightEnable( struct NineDevice9
*This
,
2191 const struct nine_state
*state
= &This
->state
;
2194 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2195 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2196 D3DERR_INVALIDCALL
);
2198 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
)
2199 if (state
->ff
.active_light
[i
] == Index
)
2202 *pEnable
= i
!= state
->ff
.num_lights_active
? 128 : 0; // Taken from wine
2208 NineDevice9_SetClipPlane( struct NineDevice9
*This
,
2210 const float *pPlane
)
2212 struct nine_state
*state
= This
->update
;
2214 user_assert(pPlane
, D3DERR_INVALIDCALL
);
2216 DBG("This=%p Index=%u pPlane=%f %f %f %f\n", This
, Index
,
2217 pPlane
[0], pPlane
[1],
2218 pPlane
[2], pPlane
[3]);
2220 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2222 memcpy(&state
->clip
.ucp
[Index
][0], pPlane
, sizeof(state
->clip
.ucp
[0]));
2223 state
->changed
.ucp
|= 1 << Index
;
2229 NineDevice9_GetClipPlane( struct NineDevice9
*This
,
2233 const struct nine_state
*state
= &This
->state
;
2235 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2237 memcpy(pPlane
, &state
->clip
.ucp
[Index
][0], sizeof(state
->clip
.ucp
[0]));
2242 NineDevice9_SetRenderState( struct NineDevice9
*This
,
2243 D3DRENDERSTATETYPE State
,
2246 struct nine_state
*state
= This
->update
;
2248 DBG("This=%p State=%u(%s) Value=%08x\n", This
,
2249 State
, nine_d3drs_to_string(State
), Value
);
2251 user_assert(State
< D3DRS_COUNT
, D3DERR_INVALIDCALL
);
2253 if (unlikely(This
->is_recording
)) {
2254 state
->rs_advertised
[State
] = Value
;
2255 /* only need to record changed render states for stateblocks */
2256 state
->changed
.rs
[State
/ 32] |= 1 << (State
% 32);
2257 state
->changed
.group
|= nine_render_state_group
[State
];
2261 if (state
->rs_advertised
[State
] == Value
)
2264 state
->rs_advertised
[State
] = Value
;
2265 nine_context_set_render_state(This
, State
, Value
);
2271 NineDevice9_GetRenderState( struct NineDevice9
*This
,
2272 D3DRENDERSTATETYPE State
,
2275 user_assert(State
< D3DRS_COUNT
, D3DERR_INVALIDCALL
);
2277 *pValue
= This
->state
.rs_advertised
[State
];
2282 NineDevice9_CreateStateBlock( struct NineDevice9
*This
,
2283 D3DSTATEBLOCKTYPE Type
,
2284 IDirect3DStateBlock9
**ppSB
)
2286 struct NineStateBlock9
*nsb
;
2287 struct nine_state
*dst
;
2289 enum nine_stateblock_type type
;
2292 DBG("This=%p Type=%u ppSB=%p\n", This
, Type
, ppSB
);
2294 user_assert(Type
== D3DSBT_ALL
||
2295 Type
== D3DSBT_VERTEXSTATE
||
2296 Type
== D3DSBT_PIXELSTATE
, D3DERR_INVALIDCALL
);
2299 case D3DSBT_VERTEXSTATE
: type
= NINESBT_VERTEXSTATE
; break;
2300 case D3DSBT_PIXELSTATE
: type
= NINESBT_PIXELSTATE
; break;
2306 hr
= NineStateBlock9_new(This
, &nsb
, type
);
2309 *ppSB
= (IDirect3DStateBlock9
*)nsb
;
2312 dst
->changed
.group
=
2313 NINE_STATE_TEXTURE
|
2316 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_VERTEXSTATE
) {
2317 dst
->changed
.group
|=
2318 NINE_STATE_FF_LIGHTING
|
2319 NINE_STATE_VS
| NINE_STATE_VS_CONST
|
2321 /* TODO: texture/sampler state */
2322 memcpy(dst
->changed
.rs
,
2323 nine_render_states_vertex
, sizeof(dst
->changed
.rs
));
2324 nine_ranges_insert(&dst
->changed
.vs_const_f
, 0, This
->may_swvp
? NINE_MAX_CONST_F_SWVP
: This
->max_vs_const_f
,
2326 nine_ranges_insert(&dst
->changed
.vs_const_i
, 0, This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
,
2328 nine_ranges_insert(&dst
->changed
.vs_const_b
, 0, This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
,
2330 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2331 dst
->changed
.sampler
[s
] |= 1 << D3DSAMP_DMAPOFFSET
;
2332 if (This
->state
.ff
.num_lights
) {
2333 dst
->ff
.num_lights
= This
->state
.ff
.num_lights
;
2334 /* zero'd -> light type won't be NINED3DLIGHT_INVALID, so
2335 * all currently existing lights will be captured
2337 dst
->ff
.light
= CALLOC(This
->state
.ff
.num_lights
,
2339 if (!dst
->ff
.light
) {
2340 nine_bind(ppSB
, NULL
);
2341 return E_OUTOFMEMORY
;
2345 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_PIXELSTATE
) {
2346 dst
->changed
.group
|=
2347 NINE_STATE_PS
| NINE_STATE_PS_CONST
| NINE_STATE_BLEND
|
2348 NINE_STATE_FF_OTHER
| NINE_STATE_FF_PSSTAGES
| NINE_STATE_PS_CONST
|
2349 NINE_STATE_FB
| NINE_STATE_DSA
| NINE_STATE_MULTISAMPLE
|
2350 NINE_STATE_RASTERIZER
| NINE_STATE_STENCIL_REF
;
2351 memcpy(dst
->changed
.rs
,
2352 nine_render_states_pixel
, sizeof(dst
->changed
.rs
));
2353 nine_ranges_insert(&dst
->changed
.ps_const_f
, 0, This
->max_ps_const_f
,
2355 dst
->changed
.ps_const_i
= 0xffff;
2356 dst
->changed
.ps_const_b
= 0xffff;
2357 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2358 dst
->changed
.sampler
[s
] |= 0x1ffe;
2359 for (s
= 0; s
< NINE_MAX_TEXTURE_STAGES
; ++s
) {
2360 dst
->ff
.changed
.tex_stage
[s
][0] |= 0xffffffff;
2361 dst
->ff
.changed
.tex_stage
[s
][1] |= 0xffffffff;
2364 if (Type
== D3DSBT_ALL
) {
2365 dst
->changed
.group
|=
2366 NINE_STATE_VIEWPORT
|
2367 NINE_STATE_SCISSOR
|
2368 NINE_STATE_RASTERIZER
|
2372 NINE_STATE_MATERIAL
|
2373 NINE_STATE_BLEND_COLOR
|
2374 NINE_STATE_SAMPLE_MASK
;
2375 memset(dst
->changed
.rs
, ~0, (D3DRS_COUNT
/ 32) * sizeof(uint32_t));
2376 dst
->changed
.rs
[D3DRS_LAST
/ 32] |= (1 << (D3DRS_COUNT
% 32)) - 1;
2377 dst
->changed
.vtxbuf
= (1ULL << This
->caps
.MaxStreams
) - 1;
2378 dst
->changed
.stream_freq
= dst
->changed
.vtxbuf
;
2379 dst
->changed
.ucp
= (1 << PIPE_MAX_CLIP_PLANES
) - 1;
2380 dst
->changed
.texture
= (1 << NINE_MAX_SAMPLERS
) - 1;
2382 NineStateBlock9_Capture(NineStateBlock9(*ppSB
));
2384 /* TODO: fixed function state */
2390 NineDevice9_BeginStateBlock( struct NineDevice9
*This
)
2394 DBG("This=%p\n", This
);
2396 user_assert(!This
->record
, D3DERR_INVALIDCALL
);
2398 hr
= NineStateBlock9_new(This
, &This
->record
, NINESBT_CUSTOM
);
2401 NineUnknown_ConvertRefToBind(NineUnknown(This
->record
));
2403 This
->update
= &This
->record
->state
;
2404 This
->is_recording
= TRUE
;
2410 NineDevice9_EndStateBlock( struct NineDevice9
*This
,
2411 IDirect3DStateBlock9
**ppSB
)
2413 DBG("This=%p ppSB=%p\n", This
, ppSB
);
2415 user_assert(This
->record
, D3DERR_INVALIDCALL
);
2417 This
->update
= &This
->state
;
2418 This
->is_recording
= FALSE
;
2420 NineUnknown_AddRef(NineUnknown(This
->record
));
2421 *ppSB
= (IDirect3DStateBlock9
*)This
->record
;
2422 NineUnknown_Unbind(NineUnknown(This
->record
));
2423 This
->record
= NULL
;
2429 NineDevice9_SetClipStatus( struct NineDevice9
*This
,
2430 const D3DCLIPSTATUS9
*pClipStatus
)
2432 STUB(D3DERR_INVALIDCALL
);
2436 NineDevice9_GetClipStatus( struct NineDevice9
*This
,
2437 D3DCLIPSTATUS9
*pClipStatus
)
2439 STUB(D3DERR_INVALIDCALL
);
2443 NineDevice9_GetTexture( struct NineDevice9
*This
,
2445 IDirect3DBaseTexture9
**ppTexture
)
2447 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2448 Stage
== D3DDMAPSAMPLER
||
2449 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2450 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2451 user_assert(ppTexture
, D3DERR_INVALIDCALL
);
2453 if (Stage
>= D3DDMAPSAMPLER
)
2454 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2456 *ppTexture
= (IDirect3DBaseTexture9
*)This
->state
.texture
[Stage
];
2458 if (This
->state
.texture
[Stage
])
2459 NineUnknown_AddRef(NineUnknown(This
->state
.texture
[Stage
]));
2464 NineDevice9_SetTexture( struct NineDevice9
*This
,
2466 IDirect3DBaseTexture9
*pTexture
)
2468 struct nine_state
*state
= This
->update
;
2469 struct NineBaseTexture9
*tex
= NineBaseTexture9(pTexture
);
2470 struct NineBaseTexture9
*old
;
2472 DBG("This=%p Stage=%u pTexture=%p\n", This
, Stage
, pTexture
);
2474 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2475 Stage
== D3DDMAPSAMPLER
||
2476 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2477 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2478 user_assert(!tex
|| (tex
->base
.pool
!= D3DPOOL_SCRATCH
&&
2479 tex
->base
.pool
!= D3DPOOL_SYSTEMMEM
), D3DERR_INVALIDCALL
);
2481 if (Stage
>= D3DDMAPSAMPLER
)
2482 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2484 if (This
->is_recording
) {
2485 state
->changed
.texture
|= 1 << Stage
;
2486 state
->changed
.group
|= NINE_STATE_TEXTURE
;
2487 nine_bind(&state
->texture
[Stage
], pTexture
);
2491 old
= state
->texture
[Stage
];
2496 if ((tex
->managed
.dirty
| tex
->dirty_mip
) && LIST_IS_EMPTY(&tex
->list
))
2497 list_add(&tex
->list
, &This
->update_textures
);
2504 nine_context_set_texture(This
, Stage
, tex
);
2506 nine_bind(&state
->texture
[Stage
], pTexture
);
2512 NineDevice9_GetTextureStageState( struct NineDevice9
*This
,
2514 D3DTEXTURESTAGESTATETYPE Type
,
2517 const struct nine_state
*state
= &This
->state
;
2519 user_assert(Stage
< ARRAY_SIZE(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2520 user_assert(Type
< ARRAY_SIZE(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2522 *pValue
= state
->ff
.tex_stage
[Stage
][Type
];
2528 NineDevice9_SetTextureStageState( struct NineDevice9
*This
,
2530 D3DTEXTURESTAGESTATETYPE Type
,
2533 struct nine_state
*state
= This
->update
;
2534 struct nine_context
*context
= &This
->context
;
2535 int bumpmap_index
= -1;
2537 DBG("Stage=%u Type=%u Value=%08x\n", Stage
, Type
, Value
);
2538 nine_dump_D3DTSS_value(DBG_FF
, Type
, Value
);
2540 user_assert(Stage
< ARRAY_SIZE(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2541 user_assert(Type
< ARRAY_SIZE(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2543 state
->ff
.tex_stage
[Stage
][Type
] = Value
;
2545 case D3DTSS_BUMPENVMAT00
:
2546 bumpmap_index
= 4 * Stage
;
2548 case D3DTSS_BUMPENVMAT01
:
2549 bumpmap_index
= 4 * Stage
+ 1;
2551 case D3DTSS_BUMPENVMAT10
:
2552 bumpmap_index
= 4 * Stage
+ 2;
2554 case D3DTSS_BUMPENVMAT11
:
2555 bumpmap_index
= 4 * Stage
+ 3;
2557 case D3DTSS_BUMPENVLSCALE
:
2558 bumpmap_index
= 4 * 8 + 2 * Stage
;
2560 case D3DTSS_BUMPENVLOFFSET
:
2561 bumpmap_index
= 4 * 8 + 2 * Stage
+ 1;
2563 case D3DTSS_TEXTURETRANSFORMFLAGS
:
2564 state
->changed
.group
|= NINE_STATE_PS1X_SHADER
;
2570 if (bumpmap_index
>= 0 && !This
->is_recording
) {
2571 context
->bumpmap_vars
[bumpmap_index
] = Value
;
2572 state
->changed
.group
|= NINE_STATE_PS_CONST
;
2575 state
->changed
.group
|= NINE_STATE_FF_PSSTAGES
;
2576 state
->ff
.changed
.tex_stage
[Stage
][Type
/ 32] |= 1 << (Type
% 32);
2582 NineDevice9_GetSamplerState( struct NineDevice9
*This
,
2584 D3DSAMPLERSTATETYPE Type
,
2587 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2588 Sampler
== D3DDMAPSAMPLER
||
2589 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2590 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2592 if (Sampler
>= D3DDMAPSAMPLER
)
2593 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2595 *pValue
= This
->state
.samp_advertised
[Sampler
][Type
];
2600 NineDevice9_SetSamplerState( struct NineDevice9
*This
,
2602 D3DSAMPLERSTATETYPE Type
,
2605 struct nine_state
*state
= This
->update
;
2607 DBG("This=%p Sampler=%u Type=%s Value=%08x\n", This
,
2608 Sampler
, nine_D3DSAMP_to_str(Type
), Value
);
2610 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2611 Sampler
== D3DDMAPSAMPLER
||
2612 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2613 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2615 if (Sampler
>= D3DDMAPSAMPLER
)
2616 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2618 if (unlikely(This
->is_recording
)) {
2619 state
->samp_advertised
[Sampler
][Type
] = Value
;
2620 state
->changed
.group
|= NINE_STATE_SAMPLER
;
2621 state
->changed
.sampler
[Sampler
] |= 1 << Type
;
2625 if (state
->samp_advertised
[Sampler
][Type
] == Value
)
2628 state
->samp_advertised
[Sampler
][Type
] = Value
;
2629 nine_context_set_sampler_state(This
, Sampler
, Type
, Value
);
2635 NineDevice9_ValidateDevice( struct NineDevice9
*This
,
2638 const struct nine_state
*state
= &This
->state
;
2640 unsigned w
= 0, h
= 0;
2642 DBG("This=%p pNumPasses=%p\n", This
, pNumPasses
);
2644 for (i
= 0; i
< ARRAY_SIZE(state
->samp_advertised
); ++i
) {
2645 if (state
->samp_advertised
[i
][D3DSAMP_MINFILTER
] == D3DTEXF_NONE
||
2646 state
->samp_advertised
[i
][D3DSAMP_MAGFILTER
] == D3DTEXF_NONE
)
2647 return D3DERR_UNSUPPORTEDTEXTUREFILTER
;
2650 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2654 w
= state
->rt
[i
]->desc
.Width
;
2655 h
= state
->rt
[i
]->desc
.Height
;
2657 if (state
->rt
[i
]->desc
.Width
!= w
|| state
->rt
[i
]->desc
.Height
!= h
) {
2658 return D3DERR_CONFLICTINGRENDERSTATE
;
2662 (state
->rs_advertised
[D3DRS_ZENABLE
] || state
->rs_advertised
[D3DRS_STENCILENABLE
])) {
2664 (state
->ds
->desc
.Width
!= w
|| state
->ds
->desc
.Height
!= h
))
2665 return D3DERR_CONFLICTINGRENDERSTATE
;
2675 NineDevice9_SetPaletteEntries( struct NineDevice9
*This
,
2677 const PALETTEENTRY
*pEntries
)
2679 STUB(D3D_OK
); /* like wine */
2683 NineDevice9_GetPaletteEntries( struct NineDevice9
*This
,
2685 PALETTEENTRY
*pEntries
)
2687 STUB(D3DERR_INVALIDCALL
);
2691 NineDevice9_SetCurrentTexturePalette( struct NineDevice9
*This
,
2692 UINT PaletteNumber
)
2694 STUB(D3D_OK
); /* like wine */
2698 NineDevice9_GetCurrentTexturePalette( struct NineDevice9
*This
,
2699 UINT
*PaletteNumber
)
2701 STUB(D3DERR_INVALIDCALL
);
2705 NineDevice9_SetScissorRect( struct NineDevice9
*This
,
2708 struct nine_state
*state
= This
->update
;
2710 DBG("x=(%u..%u) y=(%u..%u)\n",
2711 pRect
->left
, pRect
->top
, pRect
->right
, pRect
->bottom
);
2713 state
->scissor
.minx
= pRect
->left
;
2714 state
->scissor
.miny
= pRect
->top
;
2715 state
->scissor
.maxx
= pRect
->right
;
2716 state
->scissor
.maxy
= pRect
->bottom
;
2718 if (unlikely(This
->is_recording
))
2719 state
->changed
.group
|= NINE_STATE_SCISSOR
;
2721 nine_context_set_scissor(This
, &state
->scissor
);
2727 NineDevice9_GetScissorRect( struct NineDevice9
*This
,
2730 pRect
->left
= This
->state
.scissor
.minx
;
2731 pRect
->top
= This
->state
.scissor
.miny
;
2732 pRect
->right
= This
->state
.scissor
.maxx
;
2733 pRect
->bottom
= This
->state
.scissor
.maxy
;
2739 NineDevice9_SetSoftwareVertexProcessing( struct NineDevice9
*This
,
2742 if (This
->params
.BehaviorFlags
& D3DCREATE_MIXED_VERTEXPROCESSING
) {
2743 This
->swvp
= bSoftware
;
2744 This
->state
.changed
.group
|= NINE_STATE_SWVP
;
2747 return D3DERR_INVALIDCALL
; /* msdn. TODO: check in practice */
2751 NineDevice9_GetSoftwareVertexProcessing( struct NineDevice9
*This
)
2757 NineDevice9_SetNPatchMode( struct NineDevice9
*This
,
2760 return D3D_OK
; /* Nothing to do because we don't advertise NPatch support */
2764 NineDevice9_GetNPatchMode( struct NineDevice9
*This
)
2770 NineDevice9_DrawPrimitive( struct NineDevice9
*This
,
2771 D3DPRIMITIVETYPE PrimitiveType
,
2773 UINT PrimitiveCount
)
2775 DBG("iface %p, PrimitiveType %u, StartVertex %u, PrimitiveCount %u\n",
2776 This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2778 nine_context_draw_primitive(This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2784 NineDevice9_DrawIndexedPrimitive( struct NineDevice9
*This
,
2785 D3DPRIMITIVETYPE PrimitiveType
,
2786 INT BaseVertexIndex
,
2787 UINT MinVertexIndex
,
2790 UINT PrimitiveCount
)
2792 DBG("iface %p, PrimitiveType %u, BaseVertexIndex %u, MinVertexIndex %u "
2793 "NumVertices %u, StartIndex %u, PrimitiveCount %u\n",
2794 This
, PrimitiveType
, BaseVertexIndex
, MinVertexIndex
, NumVertices
,
2795 StartIndex
, PrimitiveCount
);
2797 user_assert(This
->state
.idxbuf
, D3DERR_INVALIDCALL
);
2798 user_assert(This
->state
.vdecl
, D3DERR_INVALIDCALL
);
2800 nine_context_draw_indexed_primitive(This
, PrimitiveType
, BaseVertexIndex
,
2801 MinVertexIndex
, NumVertices
, StartIndex
,
2808 NineDevice9_DrawPrimitiveUP( struct NineDevice9
*This
,
2809 D3DPRIMITIVETYPE PrimitiveType
,
2810 UINT PrimitiveCount
,
2811 const void *pVertexStreamZeroData
,
2812 UINT VertexStreamZeroStride
)
2814 struct pipe_vertex_buffer vtxbuf
;
2816 DBG("iface %p, PrimitiveType %u, PrimitiveCount %u, data %p, stride %u\n",
2817 This
, PrimitiveType
, PrimitiveCount
,
2818 pVertexStreamZeroData
, VertexStreamZeroStride
);
2820 user_assert(pVertexStreamZeroData
&& VertexStreamZeroStride
,
2821 D3DERR_INVALIDCALL
);
2822 user_assert(PrimitiveCount
, D3D_OK
);
2824 vtxbuf
.stride
= VertexStreamZeroStride
;
2825 vtxbuf
.buffer_offset
= 0;
2826 vtxbuf
.buffer
= NULL
;
2827 vtxbuf
.user_buffer
= pVertexStreamZeroData
;
2829 if (!This
->driver_caps
.user_vbufs
) {
2830 u_upload_data(This
->vertex_uploader
,
2832 (prim_count_to_vertex_count(PrimitiveType
, PrimitiveCount
)) * VertexStreamZeroStride
, /* XXX */
2835 &vtxbuf
.buffer_offset
,
2837 u_upload_unmap(This
->vertex_uploader
);
2838 vtxbuf
.user_buffer
= NULL
;
2841 nine_context_draw_primitive_from_vtxbuf(This
, PrimitiveType
, PrimitiveCount
, &vtxbuf
);
2843 pipe_resource_reference(&vtxbuf
.buffer
, NULL
);
2845 NineDevice9_PauseRecording(This
);
2846 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
2847 NineDevice9_ResumeRecording(This
);
2853 NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9
*This
,
2854 D3DPRIMITIVETYPE PrimitiveType
,
2855 UINT MinVertexIndex
,
2857 UINT PrimitiveCount
,
2858 const void *pIndexData
,
2859 D3DFORMAT IndexDataFormat
,
2860 const void *pVertexStreamZeroData
,
2861 UINT VertexStreamZeroStride
)
2863 struct pipe_vertex_buffer vbuf
;
2864 struct pipe_index_buffer ibuf
;
2866 DBG("iface %p, PrimitiveType %u, MinVertexIndex %u, NumVertices %u "
2867 "PrimitiveCount %u, pIndexData %p, IndexDataFormat %u "
2868 "pVertexStreamZeroData %p, VertexStreamZeroStride %u\n",
2869 This
, PrimitiveType
, MinVertexIndex
, NumVertices
, PrimitiveCount
,
2870 pIndexData
, IndexDataFormat
,
2871 pVertexStreamZeroData
, VertexStreamZeroStride
);
2873 user_assert(pIndexData
&& pVertexStreamZeroData
, D3DERR_INVALIDCALL
);
2874 user_assert(VertexStreamZeroStride
, D3DERR_INVALIDCALL
);
2875 user_assert(IndexDataFormat
== D3DFMT_INDEX16
||
2876 IndexDataFormat
== D3DFMT_INDEX32
, D3DERR_INVALIDCALL
);
2877 user_assert(PrimitiveCount
, D3D_OK
);
2879 vbuf
.stride
= VertexStreamZeroStride
;
2880 vbuf
.buffer_offset
= 0;
2882 vbuf
.user_buffer
= pVertexStreamZeroData
;
2884 ibuf
.index_size
= (IndexDataFormat
== D3DFMT_INDEX16
) ? 2 : 4;
2887 ibuf
.user_buffer
= pIndexData
;
2889 if (!This
->driver_caps
.user_vbufs
) {
2890 const unsigned base
= MinVertexIndex
* VertexStreamZeroStride
;
2891 u_upload_data(This
->vertex_uploader
,
2893 NumVertices
* VertexStreamZeroStride
, /* XXX */
2895 (const uint8_t *)vbuf
.user_buffer
+ base
,
2896 &vbuf
.buffer_offset
,
2898 u_upload_unmap(This
->vertex_uploader
);
2899 /* Won't be used: */
2900 vbuf
.buffer_offset
-= base
;
2901 vbuf
.user_buffer
= NULL
;
2903 if (!This
->driver_caps
.user_ibufs
) {
2904 u_upload_data(This
->index_uploader
,
2906 (prim_count_to_vertex_count(PrimitiveType
, PrimitiveCount
)) * ibuf
.index_size
,
2911 u_upload_unmap(This
->index_uploader
);
2912 ibuf
.user_buffer
= NULL
;
2915 nine_context_draw_indexed_primitive_from_vtxbuf_idxbuf(This
, PrimitiveType
,
2922 pipe_resource_reference(&vbuf
.buffer
, NULL
);
2923 pipe_resource_reference(&ibuf
.buffer
, NULL
);
2925 NineDevice9_PauseRecording(This
);
2926 NineDevice9_SetIndices(This
, NULL
);
2927 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
2928 NineDevice9_ResumeRecording(This
);
2934 NineDevice9_ProcessVertices( struct NineDevice9
*This
,
2938 IDirect3DVertexBuffer9
*pDestBuffer
,
2939 IDirect3DVertexDeclaration9
*pVertexDecl
,
2942 struct pipe_screen
*screen_sw
= This
->screen_sw
;
2943 struct pipe_context
*pipe_sw
= This
->pipe_sw
;
2944 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pVertexDecl
);
2945 struct NineVertexBuffer9
*dst
= NineVertexBuffer9(pDestBuffer
);
2946 struct NineVertexShader9
*vs
;
2947 struct pipe_resource
*resource
;
2948 struct pipe_transfer
*transfer
= NULL
;
2949 struct pipe_stream_output_info so
;
2950 struct pipe_stream_output_target
*target
;
2951 struct pipe_draw_info draw
;
2952 struct pipe_box box
;
2953 bool programmable_vs
= This
->state
.vs
&& !(This
->state
.vdecl
&& This
->state
.vdecl
->position_t
);
2954 unsigned offsets
[1] = {0};
2956 unsigned buffer_size
;
2959 DBG("This=%p SrcStartIndex=%u DestIndex=%u VertexCount=%u "
2960 "pDestBuffer=%p pVertexDecl=%p Flags=%d\n",
2961 This
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
,
2962 pVertexDecl
, Flags
);
2964 if (!screen_sw
->get_param(screen_sw
, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
)) {
2965 DBG("ProcessVertices not supported\n");
2966 return D3DERR_INVALIDCALL
;
2970 vs
= programmable_vs
? This
->state
.vs
: This
->ff
.vs
;
2971 /* Note: version is 0 for ff */
2972 user_assert(vdecl
|| (vs
->byte_code
.version
< 0x30 && dst
->desc
.FVF
),
2973 D3DERR_INVALIDCALL
);
2975 DWORD FVF
= dst
->desc
.FVF
;
2976 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
2978 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
2982 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
2983 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
2987 /* Flags: Can be 0 or D3DPV_DONOTCOPYDATA, and/or lock flags
2988 * D3DPV_DONOTCOPYDATA -> Has effect only for ff. In particular
2989 * if not set, everything from src will be used, and dst
2990 * must match exactly the ff vs outputs.
2991 * TODO: Handle all the checks, etc for ff */
2992 user_assert(vdecl
->position_t
|| programmable_vs
,
2993 D3DERR_INVALIDCALL
);
2995 /* TODO: Support vs < 3 and ff */
2996 user_assert(vs
->byte_code
.version
== 0x30,
2997 D3DERR_INVALIDCALL
);
2998 /* TODO: Not hardcode the constant buffers for swvp */
2999 user_assert(This
->may_swvp
,
3000 D3DERR_INVALIDCALL
);
3002 nine_state_prepare_draw_sw(This
, vdecl
, SrcStartIndex
, VertexCount
, &so
);
3004 buffer_size
= VertexCount
* so
.stride
[0] * 4;
3006 struct pipe_resource templ
;
3008 memset(&templ
, 0, sizeof(templ
));
3009 templ
.target
= PIPE_BUFFER
;
3010 templ
.format
= PIPE_FORMAT_R8_UNORM
;
3011 templ
.width0
= buffer_size
;
3013 templ
.bind
= PIPE_BIND_STREAM_OUTPUT
;
3014 templ
.usage
= PIPE_USAGE_STREAM
;
3015 templ
.height0
= templ
.depth0
= templ
.array_size
= 1;
3016 templ
.last_level
= templ
.nr_samples
= 0;
3018 resource
= screen_sw
->resource_create(screen_sw
, &templ
);
3020 return E_OUTOFMEMORY
;
3022 target
= pipe_sw
->create_stream_output_target(pipe_sw
, resource
,
3025 pipe_resource_reference(&resource
, NULL
);
3026 return D3DERR_DRIVERINTERNALERROR
;
3029 draw
.mode
= PIPE_PRIM_POINTS
;
3030 draw
.count
= VertexCount
;
3031 draw
.start_instance
= 0;
3032 draw
.primitive_restart
= FALSE
;
3033 draw
.restart_index
= 0;
3034 draw
.count_from_stream_output
= NULL
;
3035 draw
.indirect
= NULL
;
3036 draw
.indirect_params
= NULL
;
3037 draw
.instance_count
= 1;
3038 draw
.indexed
= FALSE
;
3040 draw
.index_bias
= 0;
3042 draw
.max_index
= VertexCount
- 1;
3045 pipe_sw
->set_stream_output_targets(pipe_sw
, 1, &target
, offsets
);
3047 pipe_sw
->draw_vbo(pipe_sw
, &draw
);
3049 pipe_sw
->set_stream_output_targets(pipe_sw
, 0, NULL
, 0);
3050 pipe_sw
->stream_output_target_destroy(pipe_sw
, target
);
3052 u_box_1d(0, VertexCount
* so
.stride
[0] * 4, &box
);
3053 map
= pipe_sw
->transfer_map(pipe_sw
, resource
, 0, PIPE_TRANSFER_READ
, &box
,
3056 hr
= D3DERR_DRIVERINTERNALERROR
;
3060 hr
= NineVertexDeclaration9_ConvertStreamOutput(vdecl
,
3061 dst
, DestIndex
, VertexCount
,
3064 pipe_sw
->transfer_unmap(pipe_sw
, transfer
);
3067 nine_state_after_draw_sw(This
);
3068 pipe_resource_reference(&resource
, NULL
);
3073 NineDevice9_CreateVertexDeclaration( struct NineDevice9
*This
,
3074 const D3DVERTEXELEMENT9
*pVertexElements
,
3075 IDirect3DVertexDeclaration9
**ppDecl
)
3077 struct NineVertexDeclaration9
*vdecl
;
3079 DBG("This=%p pVertexElements=%p ppDecl=%p\n",
3080 This
, pVertexElements
, ppDecl
);
3082 HRESULT hr
= NineVertexDeclaration9_new(This
, pVertexElements
, &vdecl
);
3084 *ppDecl
= (IDirect3DVertexDeclaration9
*)vdecl
;
3090 NineDevice9_SetVertexDeclaration( struct NineDevice9
*This
,
3091 IDirect3DVertexDeclaration9
*pDecl
)
3093 struct nine_state
*state
= This
->update
;
3094 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pDecl
);
3096 DBG("This=%p pDecl=%p\n", This
, pDecl
);
3098 if (unlikely(This
->is_recording
)) {
3099 nine_bind(&state
->vdecl
, vdecl
);
3100 state
->changed
.group
|= NINE_STATE_VDECL
;
3104 if (state
->vdecl
== vdecl
)
3107 nine_bind(&state
->vdecl
, vdecl
);
3109 nine_context_set_vertex_declaration(This
, vdecl
);
3115 NineDevice9_GetVertexDeclaration( struct NineDevice9
*This
,
3116 IDirect3DVertexDeclaration9
**ppDecl
)
3118 user_assert(ppDecl
, D3DERR_INVALIDCALL
);
3120 *ppDecl
= (IDirect3DVertexDeclaration9
*)This
->state
.vdecl
;
3122 NineUnknown_AddRef(NineUnknown(*ppDecl
));
3127 NineDevice9_SetFVF( struct NineDevice9
*This
,
3130 struct NineVertexDeclaration9
*vdecl
;
3133 DBG("FVF = %08x\n", FVF
);
3135 return D3D_OK
; /* like wine */
3137 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
3139 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
3143 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
3144 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
3146 return NineDevice9_SetVertexDeclaration(
3147 This
, (IDirect3DVertexDeclaration9
*)vdecl
);
3151 NineDevice9_GetFVF( struct NineDevice9
*This
,
3154 *pFVF
= This
->state
.vdecl
? This
->state
.vdecl
->fvf
: 0;
3159 NineDevice9_CreateVertexShader( struct NineDevice9
*This
,
3160 const DWORD
*pFunction
,
3161 IDirect3DVertexShader9
**ppShader
)
3163 struct NineVertexShader9
*vs
;
3166 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3168 hr
= NineVertexShader9_new(This
, &vs
, pFunction
, NULL
);
3171 *ppShader
= (IDirect3DVertexShader9
*)vs
;
3176 NineDevice9_SetVertexShader( struct NineDevice9
*This
,
3177 IDirect3DVertexShader9
*pShader
)
3179 struct nine_state
*state
= This
->update
;
3180 struct NineVertexShader9
*vs_shader
= (struct NineVertexShader9
*)pShader
;
3182 DBG("This=%p pShader=%p\n", This
, pShader
);
3184 if (unlikely(This
->is_recording
)) {
3185 nine_bind(&state
->vs
, vs_shader
);
3186 state
->changed
.group
|= NINE_STATE_VS
;
3190 if (state
->vs
== vs_shader
)
3193 nine_bind(&state
->vs
, vs_shader
);
3195 nine_context_set_vertex_shader(This
, vs_shader
);
3201 NineDevice9_GetVertexShader( struct NineDevice9
*This
,
3202 IDirect3DVertexShader9
**ppShader
)
3204 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3205 nine_reference_set(ppShader
, This
->state
.vs
);
3210 NineDevice9_SetVertexShaderConstantF( struct NineDevice9
*This
,
3212 const float *pConstantData
,
3213 UINT Vector4fCount
)
3215 struct nine_state
*state
= This
->update
;
3216 float *vs_const_f
= state
->vs_const_f
;
3218 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3219 This
, StartRegister
, pConstantData
, Vector4fCount
);
3221 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3222 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3226 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3228 if (unlikely(This
->is_recording
)) {
3229 memcpy(&vs_const_f
[StartRegister
* 4],
3231 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3233 nine_ranges_insert(&state
->changed
.vs_const_f
,
3234 StartRegister
, StartRegister
+ Vector4fCount
,
3237 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3242 if (!memcmp(&vs_const_f
[StartRegister
* 4], pConstantData
,
3243 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0])))
3246 memcpy(&vs_const_f
[StartRegister
* 4],
3248 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3250 nine_context_set_vertex_shader_constant_f(This
, StartRegister
, pConstantData
, Vector4fCount
);
3256 NineDevice9_GetVertexShaderConstantF( struct NineDevice9
*This
,
3258 float *pConstantData
,
3259 UINT Vector4fCount
)
3261 const struct nine_state
*state
= &This
->state
;
3263 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3264 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3265 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3267 memcpy(pConstantData
,
3268 &state
->vs_const_f
[StartRegister
* 4],
3269 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3275 NineDevice9_SetVertexShaderConstantI( struct NineDevice9
*This
,
3277 const int *pConstantData
,
3278 UINT Vector4iCount
)
3280 struct nine_state
*state
= This
->update
;
3283 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3284 This
, StartRegister
, pConstantData
, Vector4iCount
);
3286 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3287 D3DERR_INVALIDCALL
);
3288 user_assert(StartRegister
+ Vector4iCount
<= (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3289 D3DERR_INVALIDCALL
);
3290 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3292 if (This
->driver_caps
.vs_integer
) {
3293 if (!This
->is_recording
) {
3294 if (!memcmp(&state
->vs_const_i
[4 * StartRegister
], pConstantData
,
3295 Vector4iCount
* sizeof(int[4])))
3298 memcpy(&state
->vs_const_i
[4 * StartRegister
],
3300 Vector4iCount
* sizeof(int[4]));
3302 for (i
= 0; i
< Vector4iCount
; i
++) {
3303 state
->vs_const_i
[4 * (StartRegister
+ i
)] = fui((float)(pConstantData
[4 * i
]));
3304 state
->vs_const_i
[4 * (StartRegister
+ i
) + 1] = fui((float)(pConstantData
[4 * i
+ 1]));
3305 state
->vs_const_i
[4 * (StartRegister
+ i
) + 2] = fui((float)(pConstantData
[4 * i
+ 2]));
3306 state
->vs_const_i
[4 * (StartRegister
+ i
) + 3] = fui((float)(pConstantData
[4 * i
+ 3]));
3310 if (unlikely(This
->is_recording
)) {
3311 nine_ranges_insert(&state
->changed
.vs_const_i
,
3312 StartRegister
, StartRegister
+ Vector4iCount
,
3314 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3316 nine_context_set_vertex_shader_constant_i(This
, StartRegister
, pConstantData
, Vector4iCount
);
3322 NineDevice9_GetVertexShaderConstantI( struct NineDevice9
*This
,
3325 UINT Vector4iCount
)
3327 const struct nine_state
*state
= &This
->state
;
3330 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3331 D3DERR_INVALIDCALL
);
3332 user_assert(StartRegister
+ Vector4iCount
<= (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3333 D3DERR_INVALIDCALL
);
3334 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3336 if (This
->driver_caps
.vs_integer
) {
3337 memcpy(pConstantData
,
3338 &state
->vs_const_i
[4 * StartRegister
],
3339 Vector4iCount
* sizeof(int[4]));
3341 for (i
= 0; i
< Vector4iCount
; i
++) {
3342 pConstantData
[4 * i
] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
)]);
3343 pConstantData
[4 * i
+ 1] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
) + 1]);
3344 pConstantData
[4 * i
+ 2] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
) + 2]);
3345 pConstantData
[4 * i
+ 3] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
) + 3]);
3353 NineDevice9_SetVertexShaderConstantB( struct NineDevice9
*This
,
3355 const BOOL
*pConstantData
,
3358 struct nine_state
*state
= This
->update
;
3360 uint32_t bool_true
= This
->driver_caps
.vs_integer
? 0xFFFFFFFF : fui(1.0f
);
3362 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3363 This
, StartRegister
, pConstantData
, BoolCount
);
3365 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3366 D3DERR_INVALIDCALL
);
3367 user_assert(StartRegister
+ BoolCount
<= (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3368 D3DERR_INVALIDCALL
);
3369 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3371 if (!This
->is_recording
) {
3372 bool noChange
= true;
3373 for (i
= 0; i
< BoolCount
; i
++) {
3374 if (!!state
->vs_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3381 for (i
= 0; i
< BoolCount
; i
++)
3382 state
->vs_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3384 if (unlikely(This
->is_recording
)) {
3385 nine_ranges_insert(&state
->changed
.vs_const_b
,
3386 StartRegister
, StartRegister
+ BoolCount
,
3388 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3390 nine_context_set_vertex_shader_constant_b(This
, StartRegister
, pConstantData
, BoolCount
);
3396 NineDevice9_GetVertexShaderConstantB( struct NineDevice9
*This
,
3398 BOOL
*pConstantData
,
3401 const struct nine_state
*state
= &This
->state
;
3404 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3405 D3DERR_INVALIDCALL
);
3406 user_assert(StartRegister
+ BoolCount
<= (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3407 D3DERR_INVALIDCALL
);
3408 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3410 for (i
= 0; i
< BoolCount
; i
++)
3411 pConstantData
[i
] = state
->vs_const_b
[StartRegister
+ i
] != 0 ? TRUE
: FALSE
;
3417 NineDevice9_SetStreamSource( struct NineDevice9
*This
,
3419 IDirect3DVertexBuffer9
*pStreamData
,
3423 struct nine_state
*state
= This
->update
;
3424 struct NineVertexBuffer9
*pVBuf9
= NineVertexBuffer9(pStreamData
);
3425 const unsigned i
= StreamNumber
;
3427 DBG("This=%p StreamNumber=%u pStreamData=%p OffsetInBytes=%u Stride=%u\n",
3428 This
, StreamNumber
, pStreamData
, OffsetInBytes
, Stride
);
3430 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3431 user_assert(Stride
<= This
->caps
.MaxStreamStride
, D3DERR_INVALIDCALL
);
3433 if (unlikely(This
->is_recording
)) {
3434 nine_bind(&state
->stream
[i
], pStreamData
);
3435 state
->changed
.vtxbuf
|= 1 << StreamNumber
;
3436 state
->vtxbuf
[i
].stride
= Stride
;
3437 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3441 if (state
->stream
[i
] == NineVertexBuffer9(pStreamData
) &&
3442 state
->vtxbuf
[i
].stride
== Stride
&&
3443 state
->vtxbuf
[i
].buffer_offset
== OffsetInBytes
)
3446 state
->vtxbuf
[i
].stride
= Stride
;
3447 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3449 nine_bind(&state
->stream
[i
], pStreamData
);
3451 nine_context_set_stream_source(This
,
3461 NineDevice9_GetStreamSource( struct NineDevice9
*This
,
3463 IDirect3DVertexBuffer9
**ppStreamData
,
3464 UINT
*pOffsetInBytes
,
3467 const struct nine_state
*state
= &This
->state
;
3468 const unsigned i
= StreamNumber
;
3470 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3471 user_assert(ppStreamData
, D3DERR_INVALIDCALL
);
3473 nine_reference_set(ppStreamData
, state
->stream
[i
]);
3474 *pStride
= state
->vtxbuf
[i
].stride
;
3475 *pOffsetInBytes
= state
->vtxbuf
[i
].buffer_offset
;
3481 NineDevice9_SetStreamSourceFreq( struct NineDevice9
*This
,
3485 struct nine_state
*state
= This
->update
;
3486 /* const UINT freq = Setting & 0x7FFFFF; */
3488 DBG("This=%p StreamNumber=%u FrequencyParameter=0x%x\n", This
,
3489 StreamNumber
, Setting
);
3491 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3492 user_assert(StreamNumber
!= 0 || !(Setting
& D3DSTREAMSOURCE_INSTANCEDATA
),
3493 D3DERR_INVALIDCALL
);
3494 user_assert(!((Setting
& D3DSTREAMSOURCE_INSTANCEDATA
) &&
3495 (Setting
& D3DSTREAMSOURCE_INDEXEDDATA
)), D3DERR_INVALIDCALL
);
3496 user_assert(Setting
, D3DERR_INVALIDCALL
);
3498 if (unlikely(This
->is_recording
)) {
3499 state
->stream_freq
[StreamNumber
] = Setting
;
3500 state
->changed
.stream_freq
|= 1 << StreamNumber
;
3501 if (StreamNumber
!= 0)
3502 state
->changed
.group
|= NINE_STATE_STREAMFREQ
;
3506 if (state
->stream_freq
[StreamNumber
] == Setting
)
3509 state
->stream_freq
[StreamNumber
] = Setting
;
3511 nine_context_set_stream_source_freq(This
, StreamNumber
, Setting
);
3516 NineDevice9_GetStreamSourceFreq( struct NineDevice9
*This
,
3520 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3521 *pSetting
= This
->state
.stream_freq
[StreamNumber
];
3526 NineDevice9_SetIndices( struct NineDevice9
*This
,
3527 IDirect3DIndexBuffer9
*pIndexData
)
3529 struct nine_state
*state
= This
->update
;
3530 struct NineIndexBuffer9
*idxbuf
= NineIndexBuffer9(pIndexData
);
3532 DBG("This=%p pIndexData=%p\n", This
, pIndexData
);
3534 if (unlikely(This
->is_recording
)) {
3535 nine_bind(&state
->idxbuf
, idxbuf
);
3536 state
->changed
.group
|= NINE_STATE_IDXBUF
;
3540 if (state
->idxbuf
== idxbuf
)
3542 nine_bind(&state
->idxbuf
, idxbuf
);
3544 nine_context_set_indices(This
, idxbuf
);
3549 /* XXX: wine/d3d9 doesn't have pBaseVertexIndex, and it doesn't make sense
3550 * here because it's an argument passed to the Draw calls.
3553 NineDevice9_GetIndices( struct NineDevice9
*This
,
3554 IDirect3DIndexBuffer9
**ppIndexData
)
3556 user_assert(ppIndexData
, D3DERR_INVALIDCALL
);
3557 nine_reference_set(ppIndexData
, This
->state
.idxbuf
);
3562 NineDevice9_CreatePixelShader( struct NineDevice9
*This
,
3563 const DWORD
*pFunction
,
3564 IDirect3DPixelShader9
**ppShader
)
3566 struct NinePixelShader9
*ps
;
3569 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3571 hr
= NinePixelShader9_new(This
, &ps
, pFunction
, NULL
);
3574 *ppShader
= (IDirect3DPixelShader9
*)ps
;
3579 NineDevice9_SetPixelShader( struct NineDevice9
*This
,
3580 IDirect3DPixelShader9
*pShader
)
3582 struct nine_state
*state
= This
->update
;
3583 struct nine_context
*context
= &This
->context
;
3584 unsigned old_mask
= state
->ps
? state
->ps
->rt_mask
: 1;
3587 DBG("This=%p pShader=%p\n", This
, pShader
);
3589 if (!This
->is_recording
&& state
->ps
== (struct NinePixelShader9
*)pShader
)
3592 /* ff -> non-ff: commit back non-ff constants */
3593 if (!state
->ps
&& pShader
)
3594 context
->commit
|= NINE_STATE_COMMIT_CONST_PS
;
3596 nine_bind(&state
->ps
, pShader
);
3598 state
->changed
.group
|= NINE_STATE_PS
;
3600 mask
= state
->ps
? state
->ps
->rt_mask
: 1;
3601 /* We need to update cbufs if the pixel shader would
3602 * write to different render targets */
3603 if (mask
!= old_mask
)
3604 state
->changed
.group
|= NINE_STATE_FB
;
3610 NineDevice9_GetPixelShader( struct NineDevice9
*This
,
3611 IDirect3DPixelShader9
**ppShader
)
3613 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3614 nine_reference_set(ppShader
, This
->state
.ps
);
3619 NineDevice9_SetPixelShaderConstantF( struct NineDevice9
*This
,
3621 const float *pConstantData
,
3622 UINT Vector4fCount
)
3624 struct nine_state
*state
= This
->update
;
3626 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3627 This
, StartRegister
, pConstantData
, Vector4fCount
);
3629 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3630 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3634 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3636 if (unlikely(This
->is_recording
)) {
3637 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3639 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3641 nine_ranges_insert(&state
->changed
.ps_const_f
,
3642 StartRegister
, StartRegister
+ Vector4fCount
,
3645 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3649 if (!memcmp(&state
->ps_const_f
[StartRegister
* 4], pConstantData
,
3650 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0])))
3653 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3655 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3657 nine_context_set_pixel_shader_constant_f(This
, StartRegister
, pConstantData
, Vector4fCount
);
3663 NineDevice9_GetPixelShaderConstantF( struct NineDevice9
*This
,
3665 float *pConstantData
,
3666 UINT Vector4fCount
)
3668 const struct nine_state
*state
= &This
->state
;
3670 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3671 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3672 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3674 memcpy(pConstantData
,
3675 &state
->ps_const_f
[StartRegister
* 4],
3676 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3682 NineDevice9_SetPixelShaderConstantI( struct NineDevice9
*This
,
3684 const int *pConstantData
,
3685 UINT Vector4iCount
)
3687 struct nine_state
*state
= This
->update
;
3690 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3691 This
, StartRegister
, pConstantData
, Vector4iCount
);
3693 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3694 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3695 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3697 if (This
->driver_caps
.ps_integer
) {
3698 if (!This
->is_recording
) {
3699 if (!memcmp(&state
->ps_const_i
[StartRegister
][0], pConstantData
,
3700 Vector4iCount
* sizeof(state
->ps_const_i
[0])))
3703 memcpy(&state
->ps_const_i
[StartRegister
][0],
3705 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3707 for (i
= 0; i
< Vector4iCount
; i
++) {
3708 state
->ps_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3709 state
->ps_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3710 state
->ps_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3711 state
->ps_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3715 if (unlikely(This
->is_recording
)) {
3716 state
->changed
.ps_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3717 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3719 nine_context_set_pixel_shader_constant_i(This
, StartRegister
, pConstantData
, Vector4iCount
);
3725 NineDevice9_GetPixelShaderConstantI( struct NineDevice9
*This
,
3728 UINT Vector4iCount
)
3730 const struct nine_state
*state
= &This
->state
;
3733 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3734 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3735 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3737 if (This
->driver_caps
.ps_integer
) {
3738 memcpy(pConstantData
,
3739 &state
->ps_const_i
[StartRegister
][0],
3740 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3742 for (i
= 0; i
< Vector4iCount
; i
++) {
3743 pConstantData
[4*i
] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][0]);
3744 pConstantData
[4*i
+1] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][1]);
3745 pConstantData
[4*i
+2] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][2]);
3746 pConstantData
[4*i
+3] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][3]);
3754 NineDevice9_SetPixelShaderConstantB( struct NineDevice9
*This
,
3756 const BOOL
*pConstantData
,
3759 struct nine_state
*state
= This
->update
;
3761 uint32_t bool_true
= This
->driver_caps
.ps_integer
? 0xFFFFFFFF : fui(1.0f
);
3763 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3764 This
, StartRegister
, pConstantData
, BoolCount
);
3766 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3767 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3768 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3770 if (!This
->is_recording
) {
3771 bool noChange
= true;
3772 for (i
= 0; i
< BoolCount
; i
++) {
3773 if (!!state
->ps_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3780 for (i
= 0; i
< BoolCount
; i
++)
3781 state
->ps_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3783 if (unlikely(This
->is_recording
)) {
3784 state
->changed
.ps_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3785 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3787 nine_context_set_pixel_shader_constant_b(This
, StartRegister
, pConstantData
, BoolCount
);
3793 NineDevice9_GetPixelShaderConstantB( struct NineDevice9
*This
,
3795 BOOL
*pConstantData
,
3798 const struct nine_state
*state
= &This
->state
;
3801 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3802 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3803 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3805 for (i
= 0; i
< BoolCount
; i
++)
3806 pConstantData
[i
] = state
->ps_const_b
[StartRegister
+ i
] ? TRUE
: FALSE
;
3812 NineDevice9_DrawRectPatch( struct NineDevice9
*This
,
3814 const float *pNumSegs
,
3815 const D3DRECTPATCH_INFO
*pRectPatchInfo
)
3817 STUB(D3DERR_INVALIDCALL
);
3821 NineDevice9_DrawTriPatch( struct NineDevice9
*This
,
3823 const float *pNumSegs
,
3824 const D3DTRIPATCH_INFO
*pTriPatchInfo
)
3826 STUB(D3DERR_INVALIDCALL
);
3830 NineDevice9_DeletePatch( struct NineDevice9
*This
,
3833 STUB(D3DERR_INVALIDCALL
);
3837 NineDevice9_CreateQuery( struct NineDevice9
*This
,
3839 IDirect3DQuery9
**ppQuery
)
3841 struct NineQuery9
*query
;
3844 DBG("This=%p Type=%d ppQuery=%p\n", This
, Type
, ppQuery
);
3846 hr
= nine_is_query_supported(This
->screen
, Type
);
3847 if (!ppQuery
|| hr
!= D3D_OK
)
3850 hr
= NineQuery9_new(This
, &query
, Type
);
3853 *ppQuery
= (IDirect3DQuery9
*)query
;
3857 IDirect3DDevice9Vtbl NineDevice9_vtable
= {
3858 (void *)NineUnknown_QueryInterface
,
3859 (void *)NineUnknown_AddRef
,
3860 (void *)NineUnknown_Release
,
3861 (void *)NineDevice9_TestCooperativeLevel
,
3862 (void *)NineDevice9_GetAvailableTextureMem
,
3863 (void *)NineDevice9_EvictManagedResources
,
3864 (void *)NineDevice9_GetDirect3D
,
3865 (void *)NineDevice9_GetDeviceCaps
,
3866 (void *)NineDevice9_GetDisplayMode
,
3867 (void *)NineDevice9_GetCreationParameters
,
3868 (void *)NineDevice9_SetCursorProperties
,
3869 (void *)NineDevice9_SetCursorPosition
,
3870 (void *)NineDevice9_ShowCursor
,
3871 (void *)NineDevice9_CreateAdditionalSwapChain
,
3872 (void *)NineDevice9_GetSwapChain
,
3873 (void *)NineDevice9_GetNumberOfSwapChains
,
3874 (void *)NineDevice9_Reset
,
3875 (void *)NineDevice9_Present
,
3876 (void *)NineDevice9_GetBackBuffer
,
3877 (void *)NineDevice9_GetRasterStatus
,
3878 (void *)NineDevice9_SetDialogBoxMode
,
3879 (void *)NineDevice9_SetGammaRamp
,
3880 (void *)NineDevice9_GetGammaRamp
,
3881 (void *)NineDevice9_CreateTexture
,
3882 (void *)NineDevice9_CreateVolumeTexture
,
3883 (void *)NineDevice9_CreateCubeTexture
,
3884 (void *)NineDevice9_CreateVertexBuffer
,
3885 (void *)NineDevice9_CreateIndexBuffer
,
3886 (void *)NineDevice9_CreateRenderTarget
,
3887 (void *)NineDevice9_CreateDepthStencilSurface
,
3888 (void *)NineDevice9_UpdateSurface
,
3889 (void *)NineDevice9_UpdateTexture
,
3890 (void *)NineDevice9_GetRenderTargetData
,
3891 (void *)NineDevice9_GetFrontBufferData
,
3892 (void *)NineDevice9_StretchRect
,
3893 (void *)NineDevice9_ColorFill
,
3894 (void *)NineDevice9_CreateOffscreenPlainSurface
,
3895 (void *)NineDevice9_SetRenderTarget
,
3896 (void *)NineDevice9_GetRenderTarget
,
3897 (void *)NineDevice9_SetDepthStencilSurface
,
3898 (void *)NineDevice9_GetDepthStencilSurface
,
3899 (void *)NineDevice9_BeginScene
,
3900 (void *)NineDevice9_EndScene
,
3901 (void *)NineDevice9_Clear
,
3902 (void *)NineDevice9_SetTransform
,
3903 (void *)NineDevice9_GetTransform
,
3904 (void *)NineDevice9_MultiplyTransform
,
3905 (void *)NineDevice9_SetViewport
,
3906 (void *)NineDevice9_GetViewport
,
3907 (void *)NineDevice9_SetMaterial
,
3908 (void *)NineDevice9_GetMaterial
,
3909 (void *)NineDevice9_SetLight
,
3910 (void *)NineDevice9_GetLight
,
3911 (void *)NineDevice9_LightEnable
,
3912 (void *)NineDevice9_GetLightEnable
,
3913 (void *)NineDevice9_SetClipPlane
,
3914 (void *)NineDevice9_GetClipPlane
,
3915 (void *)NineDevice9_SetRenderState
,
3916 (void *)NineDevice9_GetRenderState
,
3917 (void *)NineDevice9_CreateStateBlock
,
3918 (void *)NineDevice9_BeginStateBlock
,
3919 (void *)NineDevice9_EndStateBlock
,
3920 (void *)NineDevice9_SetClipStatus
,
3921 (void *)NineDevice9_GetClipStatus
,
3922 (void *)NineDevice9_GetTexture
,
3923 (void *)NineDevice9_SetTexture
,
3924 (void *)NineDevice9_GetTextureStageState
,
3925 (void *)NineDevice9_SetTextureStageState
,
3926 (void *)NineDevice9_GetSamplerState
,
3927 (void *)NineDevice9_SetSamplerState
,
3928 (void *)NineDevice9_ValidateDevice
,
3929 (void *)NineDevice9_SetPaletteEntries
,
3930 (void *)NineDevice9_GetPaletteEntries
,
3931 (void *)NineDevice9_SetCurrentTexturePalette
,
3932 (void *)NineDevice9_GetCurrentTexturePalette
,
3933 (void *)NineDevice9_SetScissorRect
,
3934 (void *)NineDevice9_GetScissorRect
,
3935 (void *)NineDevice9_SetSoftwareVertexProcessing
,
3936 (void *)NineDevice9_GetSoftwareVertexProcessing
,
3937 (void *)NineDevice9_SetNPatchMode
,
3938 (void *)NineDevice9_GetNPatchMode
,
3939 (void *)NineDevice9_DrawPrimitive
,
3940 (void *)NineDevice9_DrawIndexedPrimitive
,
3941 (void *)NineDevice9_DrawPrimitiveUP
,
3942 (void *)NineDevice9_DrawIndexedPrimitiveUP
,
3943 (void *)NineDevice9_ProcessVertices
,
3944 (void *)NineDevice9_CreateVertexDeclaration
,
3945 (void *)NineDevice9_SetVertexDeclaration
,
3946 (void *)NineDevice9_GetVertexDeclaration
,
3947 (void *)NineDevice9_SetFVF
,
3948 (void *)NineDevice9_GetFVF
,
3949 (void *)NineDevice9_CreateVertexShader
,
3950 (void *)NineDevice9_SetVertexShader
,
3951 (void *)NineDevice9_GetVertexShader
,
3952 (void *)NineDevice9_SetVertexShaderConstantF
,
3953 (void *)NineDevice9_GetVertexShaderConstantF
,
3954 (void *)NineDevice9_SetVertexShaderConstantI
,
3955 (void *)NineDevice9_GetVertexShaderConstantI
,
3956 (void *)NineDevice9_SetVertexShaderConstantB
,
3957 (void *)NineDevice9_GetVertexShaderConstantB
,
3958 (void *)NineDevice9_SetStreamSource
,
3959 (void *)NineDevice9_GetStreamSource
,
3960 (void *)NineDevice9_SetStreamSourceFreq
,
3961 (void *)NineDevice9_GetStreamSourceFreq
,
3962 (void *)NineDevice9_SetIndices
,
3963 (void *)NineDevice9_GetIndices
,
3964 (void *)NineDevice9_CreatePixelShader
,
3965 (void *)NineDevice9_SetPixelShader
,
3966 (void *)NineDevice9_GetPixelShader
,
3967 (void *)NineDevice9_SetPixelShaderConstantF
,
3968 (void *)NineDevice9_GetPixelShaderConstantF
,
3969 (void *)NineDevice9_SetPixelShaderConstantI
,
3970 (void *)NineDevice9_GetPixelShaderConstantI
,
3971 (void *)NineDevice9_SetPixelShaderConstantB
,
3972 (void *)NineDevice9_GetPixelShaderConstantB
,
3973 (void *)NineDevice9_DrawRectPatch
,
3974 (void *)NineDevice9_DrawTriPatch
,
3975 (void *)NineDevice9_DeletePatch
,
3976 (void *)NineDevice9_CreateQuery
3979 static const GUID
*NineDevice9_IIDs
[] = {
3980 &IID_IDirect3DDevice9
,
3986 NineDevice9_new( struct pipe_screen
*pScreen
,
3987 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
3989 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
3991 ID3DPresentGroup
*pPresentationGroup
,
3992 struct d3dadapter9_context
*pCTX
,
3994 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
3995 struct NineDevice9
**ppOut
,
3996 int minorVersionNum
)
3999 lock
= !!(pCreationParameters
->BehaviorFlags
& D3DCREATE_MULTITHREADED
);
4001 NINE_NEW(Device9
, ppOut
, lock
, /* args */
4002 pScreen
, pCreationParameters
, pCaps
,
4003 pPresentationParameters
, pD3D9
, pPresentationGroup
, pCTX
,
4004 ex
, pFullscreenDisplayMode
, minorVersionNum
);