2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
24 #include "stateblock9.h"
26 #include "swapchain9.h"
27 #include "swapchain9ex.h"
28 #include "indexbuffer9.h"
29 #include "vertexbuffer9.h"
30 #include "vertexdeclaration9.h"
31 #include "vertexshader9.h"
32 #include "pixelshader9.h"
35 #include "cubetexture9.h"
36 #include "volumetexture9.h"
37 #include "nine_helpers.h"
38 #include "nine_pipe.h"
40 #include "nine_dump.h"
41 #include "nine_limits.h"
43 #include "pipe/p_screen.h"
44 #include "pipe/p_context.h"
45 #include "pipe/p_config.h"
46 #include "util/u_math.h"
47 #include "util/u_inlines.h"
48 #include "util/u_hash_table.h"
49 #include "util/u_format.h"
50 #include "util/u_surface.h"
51 #include "util/u_upload_mgr.h"
52 #include "hud/hud_context.h"
54 #include "cso_cache/cso_context.h"
56 #define DBG_CHANNEL DBG_DEVICE
58 #if defined(PIPE_CC_GCC) && (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64))
60 static void nine_setup_fpu()
64 __asm__
__volatile__ ("fnstcw %0" : "=m" (*&c
));
66 /* clear the control word */
68 /* d3d9 doc/wine tests: mask all exceptions, use single-precision
69 * and round to nearest */
72 __asm__
__volatile__ ("fldcw %0" : : "m" (*&c
));
77 static void nine_setup_fpu(void)
79 WARN_ONCE("FPU setup not supported on non-x86 platforms\n");
85 NineDevice9_SetDefaultState( struct NineDevice9
*This
, boolean is_reset
)
87 struct NineSurface9
*refSurf
= NULL
;
89 DBG("This=%p is_reset=%d\n", This
, (int) is_reset
);
91 assert(!This
->is_recording
);
93 nine_state_set_defaults(This
, &This
->caps
, is_reset
);
95 refSurf
= This
->swapchains
[0]->buffers
[0];
98 This
->state
.viewport
.X
= 0;
99 This
->state
.viewport
.Y
= 0;
100 This
->state
.viewport
.Width
= refSurf
->desc
.Width
;
101 This
->state
.viewport
.Height
= refSurf
->desc
.Height
;
103 nine_context_set_viewport(This
, &This
->state
.viewport
);
105 This
->state
.scissor
.minx
= 0;
106 This
->state
.scissor
.miny
= 0;
107 This
->state
.scissor
.maxx
= refSurf
->desc
.Width
;
108 This
->state
.scissor
.maxy
= refSurf
->desc
.Height
;
110 nine_context_set_scissor(This
, &This
->state
.scissor
);
112 if (This
->nswapchains
&& This
->swapchains
[0]->params
.EnableAutoDepthStencil
) {
113 nine_context_set_render_state(This
, D3DRS_ZENABLE
, TRUE
);
114 This
->state
.rs_advertised
[D3DRS_ZENABLE
] = TRUE
;
116 if (This
->state
.rs_advertised
[D3DRS_ZENABLE
])
117 NineDevice9_SetDepthStencilSurface(
118 This
, (IDirect3DSurface9
*)This
->swapchains
[0]->zsbuf
);
121 #define GET_PCAP(n) pScreen->get_param(pScreen, PIPE_CAP_##n)
123 NineDevice9_ctor( struct NineDevice9
*This
,
124 struct NineUnknownParams
*pParams
,
125 struct pipe_screen
*pScreen
,
126 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
128 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
130 ID3DPresentGroup
*pPresentationGroup
,
131 struct d3dadapter9_context
*pCTX
,
133 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
134 int minorVersionNum
)
137 HRESULT hr
= NineUnknown_ctor(&This
->base
, pParams
);
139 DBG("This=%p pParams=%p pScreen=%p pCreationParameters=%p pCaps=%p pPresentationParameters=%p "
140 "pD3D9=%p pPresentationGroup=%p pCTX=%p ex=%d pFullscreenDisplayMode=%p\n",
141 This
, pParams
, pScreen
, pCreationParameters
, pCaps
, pPresentationParameters
, pD3D9
,
142 pPresentationGroup
, pCTX
, (int) ex
, pFullscreenDisplayMode
);
144 if (FAILED(hr
)) { return hr
; }
146 list_inithead(&This
->update_buffers
);
147 list_inithead(&This
->update_textures
);
148 list_inithead(&This
->managed_buffers
);
149 list_inithead(&This
->managed_textures
);
151 This
->screen
= pScreen
;
152 This
->screen_sw
= pCTX
->ref
;
155 This
->params
= *pCreationParameters
;
157 This
->present
= pPresentationGroup
;
158 This
->minor_version_num
= minorVersionNum
;
160 IDirect3D9_AddRef(This
->d3d9
);
161 ID3DPresentGroup_AddRef(This
->present
);
163 if (!(This
->params
.BehaviorFlags
& D3DCREATE_FPU_PRESERVE
))
166 if (This
->params
.BehaviorFlags
& D3DCREATE_SOFTWARE_VERTEXPROCESSING
) {
167 DBG("Application asked full Software Vertex Processing.\n");
169 This
->may_swvp
= true;
172 if (This
->params
.BehaviorFlags
& D3DCREATE_MIXED_VERTEXPROCESSING
) {
173 DBG("Application asked mixed Software Vertex Processing.\n");
174 This
->may_swvp
= true;
176 This
->context
.swvp
= This
->swvp
;
177 /* TODO: check if swvp is resetted by device Resets */
179 if (This
->may_swvp
&&
180 (This
->screen
->get_shader_param(This
->screen
, PIPE_SHADER_VERTEX
,
181 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
)
182 < (NINE_MAX_CONST_F_SWVP
/2) * sizeof(float[4]) ||
183 This
->screen
->get_shader_param(This
->screen
, PIPE_SHADER_VERTEX
,
184 PIPE_SHADER_CAP_MAX_CONST_BUFFERS
) < 5)) {
185 /* Note: We just go on, some apps never use the abilities of
186 * swvp, and just set more constants than allowed at init.
187 * Only cards we support that are affected are the r500 */
188 WARN("Card unable to handle Software Vertex Processing. Game may fail\n");
191 /* When may_swvp, SetConstant* limits are different */
193 This
->caps
.MaxVertexShaderConst
= NINE_MAX_CONST_F_SWVP
;
195 This
->context
.pipe
= This
->screen
->context_create(This
->screen
, NULL
, 0);
196 This
->pipe_secondary
= This
->screen
->context_create(This
->screen
, NULL
, 0);
197 if (!This
->context
.pipe
|| !This
->pipe_secondary
) { return E_OUTOFMEMORY
; } /* guess */
198 This
->pipe_sw
= This
->screen_sw
->context_create(This
->screen_sw
, NULL
, 0);
199 if (!This
->pipe_sw
) { return E_OUTOFMEMORY
; }
201 This
->context
.cso
= cso_create_context(This
->context
.pipe
);
202 if (!This
->context
.cso
) { return E_OUTOFMEMORY
; } /* also a guess */
203 This
->cso_sw
= cso_create_context(This
->pipe_sw
);
204 if (!This
->cso_sw
) { return E_OUTOFMEMORY
; }
206 /* Create first, it messes up our state. */
207 This
->hud
= hud_create(This
->context
.pipe
, This
->context
.cso
); /* NULL result is fine */
209 /* Available memory counter. Updated only for allocations with this device
210 * instance. This is the Win 7 behavior.
211 * Win XP shares this counter across multiple devices. */
212 This
->available_texture_mem
= This
->screen
->get_param(This
->screen
, PIPE_CAP_VIDEO_MEMORY
);
213 if (This
->available_texture_mem
< 4096)
214 This
->available_texture_mem
<<= 20;
216 This
->available_texture_mem
= UINT_MAX
;
217 /* We cap texture memory usage to 80% of what is reported free initially
218 * This helps get closer Win behaviour. For example VertexBuffer allocation
219 * still succeeds when texture allocation fails. */
220 This
->available_texture_limit
= This
->available_texture_mem
* 20LL / 100LL;
222 /* create implicit swapchains */
223 This
->nswapchains
= ID3DPresentGroup_GetMultiheadCount(This
->present
);
224 This
->swapchains
= CALLOC(This
->nswapchains
,
225 sizeof(struct NineSwapChain9
*));
226 if (!This
->swapchains
) { return E_OUTOFMEMORY
; }
228 for (i
= 0; i
< This
->nswapchains
; ++i
) {
229 ID3DPresent
*present
;
231 hr
= ID3DPresentGroup_GetPresent(This
->present
, i
, &present
);
236 D3DDISPLAYMODEEX
*mode
= NULL
;
237 struct NineSwapChain9Ex
**ret
=
238 (struct NineSwapChain9Ex
**)&This
->swapchains
[i
];
240 if (pFullscreenDisplayMode
) mode
= &(pFullscreenDisplayMode
[i
]);
241 /* when this is a Device9Ex, it should create SwapChain9Exs */
242 hr
= NineSwapChain9Ex_new(This
, TRUE
, present
,
243 &pPresentationParameters
[i
], pCTX
,
244 This
->params
.hFocusWindow
, mode
, ret
);
246 hr
= NineSwapChain9_new(This
, TRUE
, present
,
247 &pPresentationParameters
[i
], pCTX
,
248 This
->params
.hFocusWindow
,
249 &This
->swapchains
[i
]);
252 ID3DPresent_Release(present
);
255 NineUnknown_ConvertRefToBind(NineUnknown(This
->swapchains
[i
]));
257 hr
= NineSwapChain9_GetBackBuffer(This
->swapchains
[i
], 0,
258 D3DBACKBUFFER_TYPE_MONO
,
259 (IDirect3DSurface9
**)
263 NineUnknown_ConvertRefToBind(NineUnknown(This
->state
.rt
[i
]));
264 nine_bind(&This
->context
.rt
[i
], This
->state
.rt
[i
]);
267 /* Initialize CSMT */
268 if (pCTX
->csmt_force
== 1)
269 This
->csmt_active
= true;
270 else if (pCTX
->csmt_force
== 0)
271 This
->csmt_active
= false;
273 /* r600 and radeonsi are thread safe. */
274 This
->csmt_active
= strstr(pScreen
->get_name(pScreen
), "AMD") != NULL
;
276 if (This
->csmt_active
) {
277 This
->csmt_ctx
= nine_csmt_create(This
);
279 return E_OUTOFMEMORY
;
282 if (This
->csmt_active
)
283 DBG("\033[1;32mCSMT is active\033[0m\n");
285 /* Initialize a dummy VBO to be used when a vertex declaration does not
286 * specify all the inputs needed by vertex shader, on win default behavior
287 * is to pass 0,0,0,0 to the shader */
289 struct pipe_transfer
*transfer
;
290 struct pipe_resource tmpl
;
294 memset(&tmpl
, 0, sizeof(tmpl
));
295 tmpl
.target
= PIPE_BUFFER
;
296 tmpl
.format
= PIPE_FORMAT_R8_UNORM
;
297 tmpl
.width0
= 16; /* 4 floats */
303 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
304 tmpl
.bind
= PIPE_BIND_VERTEX_BUFFER
;
306 This
->dummy_vbo
= pScreen
->resource_create(pScreen
, &tmpl
);
308 if (!This
->dummy_vbo
)
309 return D3DERR_OUTOFVIDEOMEMORY
;
311 u_box_1d(0, 16, &box
);
312 data
= This
->context
.pipe
->transfer_map(This
->context
.pipe
, This
->dummy_vbo
, 0,
313 PIPE_TRANSFER_WRITE
|
314 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
319 This
->context
.pipe
->transfer_unmap(This
->context
.pipe
, transfer
);
322 This
->cursor
.software
= FALSE
;
323 This
->cursor
.hotspot
.x
= -1;
324 This
->cursor
.hotspot
.y
= -1;
326 struct pipe_resource tmpl
;
327 memset(&tmpl
, 0, sizeof(tmpl
));
328 tmpl
.target
= PIPE_TEXTURE_2D
;
329 tmpl
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
336 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
337 tmpl
.bind
= PIPE_BIND_CURSOR
| PIPE_BIND_SAMPLER_VIEW
;
340 This
->cursor
.image
= pScreen
->resource_create(pScreen
, &tmpl
);
341 if (!This
->cursor
.image
)
342 return D3DERR_OUTOFVIDEOMEMORY
;
344 /* For uploading 32x32 (argb) cursor */
345 This
->cursor
.hw_upload_temp
= MALLOC(32 * 4 * 32);
346 if (!This
->cursor
.hw_upload_temp
)
347 return D3DERR_OUTOFVIDEOMEMORY
;
350 /* Create constant buffers. */
352 unsigned max_const_vs
, max_const_ps
;
354 /* vs 3.0: >= 256 float constants, but for cards with exactly 256 slots,
355 * we have to take in some more slots for int and bool*/
356 max_const_vs
= _min(pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
,
357 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
) /
360 /* ps 3.0: 224 float constants. All cards supported support at least
361 * 256 constants for ps */
362 max_const_ps
= NINE_MAX_CONST_F_PS3
+ (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
364 This
->max_vs_const_f
= max_const_vs
-
365 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
366 This
->max_ps_const_f
= max_const_ps
-
367 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
369 This
->vs_const_size
= max_const_vs
* sizeof(float[4]);
370 This
->ps_const_size
= max_const_ps
* sizeof(float[4]);
371 /* Include space for I,B constants for user constbuf. */
372 if (This
->may_swvp
) {
373 This
->state
.vs_const_f
= CALLOC(NINE_MAX_CONST_F_SWVP
* sizeof(float[4]),1);
374 This
->context
.vs_const_f_swvp
= CALLOC(NINE_MAX_CONST_F_SWVP
* sizeof(float[4]),1);
375 if (!This
->context
.vs_const_f_swvp
)
376 return E_OUTOFMEMORY
;
377 This
->state
.vs_lconstf_temp
= CALLOC(NINE_MAX_CONST_F_SWVP
* sizeof(float[4]),1);
378 This
->context
.vs_lconstf_temp
= CALLOC(NINE_MAX_CONST_F_SWVP
* sizeof(float[4]),1);
379 This
->state
.vs_const_i
= CALLOC(NINE_MAX_CONST_I_SWVP
* sizeof(int[4]), 1);
380 This
->context
.vs_const_i
= CALLOC(NINE_MAX_CONST_I_SWVP
* sizeof(int[4]), 1);
381 This
->state
.vs_const_b
= CALLOC(NINE_MAX_CONST_B_SWVP
* sizeof(BOOL
), 1);
382 This
->context
.vs_const_b
= CALLOC(NINE_MAX_CONST_B_SWVP
* sizeof(BOOL
), 1);
384 This
->state
.vs_const_f
= CALLOC(NINE_MAX_CONST_F
* sizeof(float[4]), 1);
385 This
->context
.vs_const_f_swvp
= NULL
;
386 This
->state
.vs_lconstf_temp
= CALLOC(This
->vs_const_size
,1);
387 This
->context
.vs_lconstf_temp
= CALLOC(This
->vs_const_size
,1);
388 This
->state
.vs_const_i
= CALLOC(NINE_MAX_CONST_I
* sizeof(int[4]), 1);
389 This
->context
.vs_const_i
= CALLOC(NINE_MAX_CONST_I
* sizeof(int[4]), 1);
390 This
->state
.vs_const_b
= CALLOC(NINE_MAX_CONST_B
* sizeof(BOOL
), 1);
391 This
->context
.vs_const_b
= CALLOC(NINE_MAX_CONST_B
* sizeof(BOOL
), 1);
393 This
->context
.vs_const_f
= CALLOC(This
->vs_const_size
, 1);
394 This
->state
.ps_const_f
= CALLOC(This
->ps_const_size
, 1);
395 This
->context
.ps_const_f
= CALLOC(This
->ps_const_size
, 1);
396 This
->context
.ps_lconstf_temp
= CALLOC(This
->ps_const_size
,1);
397 if (!This
->state
.vs_const_f
|| !This
->context
.vs_const_f
||
398 !This
->state
.ps_const_f
|| !This
->context
.ps_const_f
||
399 !This
->state
.vs_lconstf_temp
|| !This
->context
.vs_lconstf_temp
||
400 !This
->context
.ps_lconstf_temp
||
401 !This
->state
.vs_const_i
|| !This
->context
.vs_const_i
||
402 !This
->state
.vs_const_b
|| !This
->context
.vs_const_b
)
403 return E_OUTOFMEMORY
;
405 if (strstr(pScreen
->get_name(pScreen
), "AMD") ||
406 strstr(pScreen
->get_name(pScreen
), "ATI")) {
407 This
->driver_bugs
.buggy_barycentrics
= TRUE
;
411 /* allocate dummy texture/sampler for when there are missing ones bound */
413 struct pipe_resource tmplt
;
414 struct pipe_sampler_view templ
;
415 struct pipe_sampler_state samp
;
416 memset(&tmplt
, 0, sizeof(tmplt
));
417 memset(&samp
, 0, sizeof(samp
));
419 tmplt
.target
= PIPE_TEXTURE_2D
;
423 tmplt
.last_level
= 0;
424 tmplt
.array_size
= 1;
425 tmplt
.usage
= PIPE_USAGE_DEFAULT
;
427 tmplt
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
428 tmplt
.bind
= PIPE_BIND_SAMPLER_VIEW
;
429 tmplt
.nr_samples
= 0;
431 This
->dummy_texture
= This
->screen
->resource_create(This
->screen
, &tmplt
);
432 if (!This
->dummy_texture
)
433 return D3DERR_DRIVERINTERNALERROR
;
435 templ
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
436 templ
.u
.tex
.first_layer
= 0;
437 templ
.u
.tex
.last_layer
= 0;
438 templ
.u
.tex
.first_level
= 0;
439 templ
.u
.tex
.last_level
= 0;
440 templ
.swizzle_r
= PIPE_SWIZZLE_0
;
441 templ
.swizzle_g
= PIPE_SWIZZLE_0
;
442 templ
.swizzle_b
= PIPE_SWIZZLE_0
;
443 templ
.swizzle_a
= PIPE_SWIZZLE_1
;
444 templ
.target
= This
->dummy_texture
->target
;
446 This
->dummy_sampler_view
= This
->context
.pipe
->create_sampler_view(This
->context
.pipe
, This
->dummy_texture
, &templ
);
447 if (!This
->dummy_sampler_view
)
448 return D3DERR_DRIVERINTERNALERROR
;
450 samp
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
451 samp
.max_lod
= 15.0f
;
452 samp
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
453 samp
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
454 samp
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
455 samp
.min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
456 samp
.mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
457 samp
.compare_mode
= PIPE_TEX_COMPARE_NONE
;
458 samp
.compare_func
= PIPE_FUNC_LEQUAL
;
459 samp
.normalized_coords
= 1;
460 samp
.seamless_cube_map
= 0;
461 This
->dummy_sampler_state
= samp
;
464 /* Allocate upload helper for drivers that suck (from st pov ;). */
466 This
->driver_caps
.user_vbufs
= GET_PCAP(USER_VERTEX_BUFFERS
) && !This
->csmt_active
;
467 This
->driver_caps
.user_ibufs
= GET_PCAP(USER_INDEX_BUFFERS
) && !This
->csmt_active
;
468 This
->driver_caps
.user_cbufs
= GET_PCAP(USER_CONSTANT_BUFFERS
);
469 This
->driver_caps
.user_sw_vbufs
= This
->screen_sw
->get_param(This
->screen_sw
, PIPE_CAP_USER_VERTEX_BUFFERS
);
470 This
->driver_caps
.user_sw_cbufs
= This
->screen_sw
->get_param(This
->screen_sw
, PIPE_CAP_USER_CONSTANT_BUFFERS
);
472 if (!This
->driver_caps
.user_vbufs
)
473 This
->vertex_uploader
= u_upload_create(This
->context
.pipe
, 65536,
474 PIPE_BIND_VERTEX_BUFFER
, PIPE_USAGE_STREAM
);
475 This
->vertex_sw_uploader
= u_upload_create(This
->pipe_sw
, 65536,
476 PIPE_BIND_VERTEX_BUFFER
, PIPE_USAGE_STREAM
);
477 if (!This
->driver_caps
.user_ibufs
)
478 This
->index_uploader
= u_upload_create(This
->context
.pipe
, 128 * 1024,
479 PIPE_BIND_INDEX_BUFFER
, PIPE_USAGE_STREAM
);
480 if (!This
->driver_caps
.user_cbufs
) {
481 This
->constbuf_alignment
= GET_PCAP(CONSTANT_BUFFER_OFFSET_ALIGNMENT
);
482 This
->constbuf_uploader
= u_upload_create(This
->context
.pipe
, This
->vs_const_size
,
483 PIPE_BIND_CONSTANT_BUFFER
, PIPE_USAGE_STREAM
);
486 This
->constbuf_sw_uploader
= u_upload_create(This
->pipe_sw
, 128 * 1024,
487 PIPE_BIND_CONSTANT_BUFFER
, PIPE_USAGE_STREAM
);
489 This
->driver_caps
.window_space_position_support
= GET_PCAP(TGSI_VS_WINDOW_SPACE_POSITION
);
490 This
->driver_caps
.vs_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
, PIPE_SHADER_CAP_INTEGERS
);
491 This
->driver_caps
.ps_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_FRAGMENT
, PIPE_SHADER_CAP_INTEGERS
);
492 This
->driver_caps
.offset_units_unscaled
= GET_PCAP(POLYGON_OFFSET_UNITS_UNSCALED
);
494 nine_ff_init(This
); /* initialize fixed function code */
496 NineDevice9_SetDefaultState(This
, FALSE
);
499 struct pipe_poly_stipple stipple
;
500 memset(&stipple
, ~0, sizeof(stipple
));
501 This
->context
.pipe
->set_polygon_stipple(This
->context
.pipe
, &stipple
);
504 This
->update
= &This
->state
;
506 nine_state_init_sw(This
);
508 ID3DPresentGroup_Release(This
->present
);
509 if (This
->csmt_active
)
510 nine_csmt_process(This
);
517 NineDevice9_dtor( struct NineDevice9
*This
)
521 DBG("This=%p\n", This
);
523 /* Do not call nine_csmt_process here. The device is dead! */
524 if (This
->csmt_active
&& This
->csmt_ctx
) {
525 nine_csmt_destroy(This
, This
->csmt_ctx
);
526 This
->csmt_active
= FALSE
;
527 This
->csmt_ctx
= NULL
;
531 nine_state_destroy_sw(This
);
532 nine_state_clear(&This
->state
, TRUE
);
533 nine_context_clear(This
);
535 if (This
->vertex_uploader
)
536 u_upload_destroy(This
->vertex_uploader
);
537 if (This
->index_uploader
)
538 u_upload_destroy(This
->index_uploader
);
539 if (This
->constbuf_uploader
)
540 u_upload_destroy(This
->constbuf_uploader
);
541 if (This
->vertex_sw_uploader
)
542 u_upload_destroy(This
->vertex_sw_uploader
);
543 if (This
->constbuf_sw_uploader
)
544 u_upload_destroy(This
->constbuf_sw_uploader
);
546 nine_bind(&This
->record
, NULL
);
548 pipe_sampler_view_reference(&This
->dummy_sampler_view
, NULL
);
549 pipe_resource_reference(&This
->dummy_texture
, NULL
);
550 pipe_resource_reference(&This
->dummy_vbo
, NULL
);
551 FREE(This
->state
.vs_const_f
);
552 FREE(This
->context
.vs_const_f
);
553 FREE(This
->state
.ps_const_f
);
554 FREE(This
->context
.ps_const_f
);
555 FREE(This
->state
.vs_lconstf_temp
);
556 FREE(This
->context
.vs_lconstf_temp
);
557 FREE(This
->context
.ps_lconstf_temp
);
558 FREE(This
->state
.vs_const_i
);
559 FREE(This
->context
.vs_const_i
);
560 FREE(This
->state
.vs_const_b
);
561 FREE(This
->context
.vs_const_b
);
562 FREE(This
->context
.vs_const_f_swvp
);
564 pipe_resource_reference(&This
->cursor
.image
, NULL
);
565 FREE(This
->cursor
.hw_upload_temp
);
567 if (This
->swapchains
) {
568 for (i
= 0; i
< This
->nswapchains
; ++i
)
569 if (This
->swapchains
[i
])
570 NineUnknown_Unbind(NineUnknown(This
->swapchains
[i
]));
571 FREE(This
->swapchains
);
574 /* Destroy cso first */
575 if (This
->context
.cso
) { cso_destroy_context(This
->context
.cso
); }
576 if (This
->cso_sw
) { cso_destroy_context(This
->cso_sw
); }
577 if (This
->context
.pipe
&& This
->context
.pipe
->destroy
) { This
->context
.pipe
->destroy(This
->context
.pipe
); }
578 if (This
->pipe_secondary
&& This
->pipe_secondary
->destroy
) { This
->pipe_secondary
->destroy(This
->pipe_secondary
); }
579 if (This
->pipe_sw
&& This
->pipe_sw
->destroy
) { This
->pipe_sw
->destroy(This
->pipe_sw
); }
581 if (This
->present
) { ID3DPresentGroup_Release(This
->present
); }
582 if (This
->d3d9
) { IDirect3D9_Release(This
->d3d9
); }
584 NineUnknown_dtor(&This
->base
);
588 NineDevice9_GetScreen( struct NineDevice9
*This
)
593 struct pipe_context
*
594 NineDevice9_GetPipe( struct NineDevice9
*This
)
596 return nine_context_get_pipe(This
);
600 NineDevice9_GetCaps( struct NineDevice9
*This
)
606 NineDevice9_PauseRecording( struct NineDevice9
*This
)
609 This
->update
= &This
->state
;
610 This
->is_recording
= FALSE
;
615 NineDevice9_ResumeRecording( struct NineDevice9
*This
)
618 This
->update
= &This
->record
->state
;
619 This
->is_recording
= TRUE
;
624 NineDevice9_TestCooperativeLevel( struct NineDevice9
*This
)
626 if (NineSwapChain9_GetOccluded(This
->swapchains
[0])) {
627 This
->device_needs_reset
= TRUE
;
628 return D3DERR_DEVICELOST
;
629 } else if (NineSwapChain9_ResolutionMismatch(This
->swapchains
[0])) {
630 This
->device_needs_reset
= TRUE
;
631 return D3DERR_DEVICENOTRESET
;
632 } else if (This
->device_needs_reset
) {
633 return D3DERR_DEVICENOTRESET
;
640 NineDevice9_GetAvailableTextureMem( struct NineDevice9
*This
)
642 return This
->available_texture_mem
;
646 NineDevice9_EvictManagedResources( struct NineDevice9
*This
)
648 struct NineBaseTexture9
*tex
;
649 struct NineBuffer9
*buf
;
651 DBG("This=%p\n", This
);
652 LIST_FOR_EACH_ENTRY(tex
, &This
->managed_textures
, list2
) {
653 NineBaseTexture9_UnLoad(tex
);
655 /* Vertex/index buffers don't take a lot of space and aren't accounted
656 * for d3d memory usage. Instead of actually freeing from memory,
657 * just mark the buffer dirty to trigger a re-upload later. We
658 * could just ignore, but some bad behaving apps could rely on it (if
659 * they write outside the locked regions typically). */
660 LIST_FOR_EACH_ENTRY(buf
, &This
->managed_buffers
, managed
.list2
) {
661 NineBuffer9_SetDirty(buf
);
668 NineDevice9_GetDirect3D( struct NineDevice9
*This
,
669 IDirect3D9
**ppD3D9
)
671 user_assert(ppD3D9
!= NULL
, E_POINTER
);
672 IDirect3D9_AddRef(This
->d3d9
);
673 *ppD3D9
= This
->d3d9
;
678 NineDevice9_GetDeviceCaps( struct NineDevice9
*This
,
681 user_assert(pCaps
!= NULL
, D3DERR_INVALIDCALL
);
687 NineDevice9_GetDisplayMode( struct NineDevice9
*This
,
689 D3DDISPLAYMODE
*pMode
)
691 DBG("This=%p iSwapChain=%u pMode=%p\n", This
, iSwapChain
, pMode
);
693 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
695 return NineSwapChain9_GetDisplayMode(This
->swapchains
[iSwapChain
], pMode
);
699 NineDevice9_GetCreationParameters( struct NineDevice9
*This
,
700 D3DDEVICE_CREATION_PARAMETERS
*pParameters
)
702 user_assert(pParameters
!= NULL
, D3DERR_INVALIDCALL
);
703 *pParameters
= This
->params
;
708 NineDevice9_SetCursorProperties( struct NineDevice9
*This
,
711 IDirect3DSurface9
*pCursorBitmap
)
713 struct NineSurface9
*surf
= NineSurface9(pCursorBitmap
);
714 struct pipe_context
*pipe
= NineDevice9_GetPipe(This
);
716 struct pipe_transfer
*transfer
;
720 DBG_FLAG(DBG_SWAPCHAIN
, "This=%p XHotSpot=%u YHotSpot=%u "
721 "pCursorBitmap=%p\n", This
, XHotSpot
, YHotSpot
, pCursorBitmap
);
723 user_assert(pCursorBitmap
, D3DERR_INVALIDCALL
);
724 user_assert(surf
->desc
.Format
== D3DFMT_A8R8G8B8
, D3DERR_INVALIDCALL
);
726 if (This
->swapchains
[0]->params
.Windowed
) {
727 This
->cursor
.w
= MIN2(surf
->desc
.Width
, 32);
728 This
->cursor
.h
= MIN2(surf
->desc
.Height
, 32);
729 hw_cursor
= 1; /* always use hw cursor for windowed mode */
731 This
->cursor
.w
= MIN2(surf
->desc
.Width
, This
->cursor
.image
->width0
);
732 This
->cursor
.h
= MIN2(surf
->desc
.Height
, This
->cursor
.image
->height0
);
733 hw_cursor
= This
->cursor
.w
== 32 && This
->cursor
.h
== 32;
736 u_box_origin_2d(This
->cursor
.w
, This
->cursor
.h
, &box
);
738 ptr
= pipe
->transfer_map(pipe
, This
->cursor
.image
, 0,
739 PIPE_TRANSFER_WRITE
|
740 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
743 ret_err("Failed to update cursor image.\n", D3DERR_DRIVERINTERNALERROR
);
745 This
->cursor
.hotspot
.x
= XHotSpot
;
746 This
->cursor
.hotspot
.y
= YHotSpot
;
748 /* Copy cursor image to internal storage. */
752 const struct util_format_description
*sfmt
=
753 util_format_description(surf
->base
.info
.format
);
756 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, D3DLOCK_READONLY
);
758 ret_err("Failed to map cursor source image.\n",
759 D3DERR_DRIVERINTERNALERROR
);
761 sfmt
->unpack_rgba_8unorm(ptr
, transfer
->stride
,
762 lock
.pBits
, lock
.Pitch
,
763 This
->cursor
.w
, This
->cursor
.h
);
766 void *data
= lock
.pBits
;
767 /* SetCursor assumes 32x32 argb with pitch 128 */
768 if (lock
.Pitch
!= 128) {
769 sfmt
->unpack_rgba_8unorm(This
->cursor
.hw_upload_temp
, 128,
770 lock
.pBits
, lock
.Pitch
,
772 data
= This
->cursor
.hw_upload_temp
;
774 hw_cursor
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
,
776 &This
->cursor
.hotspot
,
777 This
->cursor
.visible
) == D3D_OK
;
780 NineSurface9_UnlockRect(surf
);
782 pipe
->transfer_unmap(pipe
, transfer
);
784 /* hide cursor if we emulate it */
786 ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, FALSE
);
787 This
->cursor
.software
= !hw_cursor
;
793 NineDevice9_SetCursorPosition( struct NineDevice9
*This
,
798 struct NineSwapChain9
*swap
= This
->swapchains
[0];
800 DBG("This=%p X=%d Y=%d Flags=%d\n", This
, X
, Y
, Flags
);
802 This
->cursor
.pos
.x
= X
;
803 This
->cursor
.pos
.y
= Y
;
805 if (!This
->cursor
.software
)
806 This
->cursor
.software
= ID3DPresent_SetCursorPos(swap
->present
, &This
->cursor
.pos
) != D3D_OK
;
810 NineDevice9_ShowCursor( struct NineDevice9
*This
,
813 BOOL old
= This
->cursor
.visible
;
815 DBG("This=%p bShow=%d\n", This
, (int) bShow
);
817 This
->cursor
.visible
= bShow
&& (This
->cursor
.hotspot
.x
!= -1);
818 if (!This
->cursor
.software
)
819 This
->cursor
.software
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, bShow
) != D3D_OK
;
825 NineDevice9_CreateAdditionalSwapChain( struct NineDevice9
*This
,
826 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
827 IDirect3DSwapChain9
**pSwapChain
)
829 struct NineSwapChain9
*swapchain
, *tmplt
= This
->swapchains
[0];
830 ID3DPresent
*present
;
833 DBG("This=%p pPresentationParameters=%p pSwapChain=%p\n",
834 This
, pPresentationParameters
, pSwapChain
);
836 user_assert(pPresentationParameters
, D3DERR_INVALIDCALL
);
837 user_assert(tmplt
->params
.Windowed
&& pPresentationParameters
->Windowed
, D3DERR_INVALIDCALL
);
839 /* TODO: this deserves more tests */
840 if (!pPresentationParameters
->hDeviceWindow
)
841 pPresentationParameters
->hDeviceWindow
= This
->params
.hFocusWindow
;
843 hr
= ID3DPresentGroup_CreateAdditionalPresent(This
->present
, pPresentationParameters
, &present
);
848 hr
= NineSwapChain9_new(This
, FALSE
, present
, pPresentationParameters
,
850 tmplt
->params
.hDeviceWindow
,
855 *pSwapChain
= (IDirect3DSwapChain9
*)swapchain
;
860 NineDevice9_GetSwapChain( struct NineDevice9
*This
,
862 IDirect3DSwapChain9
**pSwapChain
)
864 user_assert(pSwapChain
!= NULL
, D3DERR_INVALIDCALL
);
867 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
869 NineUnknown_AddRef(NineUnknown(This
->swapchains
[iSwapChain
]));
870 *pSwapChain
= (IDirect3DSwapChain9
*)This
->swapchains
[iSwapChain
];
876 NineDevice9_GetNumberOfSwapChains( struct NineDevice9
*This
)
878 return This
->nswapchains
;
882 NineDevice9_Reset( struct NineDevice9
*This
,
883 D3DPRESENT_PARAMETERS
*pPresentationParameters
)
888 DBG("This=%p pPresentationParameters=%p\n", This
, pPresentationParameters
);
890 if (NineSwapChain9_GetOccluded(This
->swapchains
[0])) {
891 This
->device_needs_reset
= TRUE
;
892 return D3DERR_DEVICELOST
;
895 for (i
= 0; i
< This
->nswapchains
; ++i
) {
896 D3DPRESENT_PARAMETERS
*params
= &pPresentationParameters
[i
];
897 hr
= NineSwapChain9_Resize(This
->swapchains
[i
], params
, NULL
);
902 nine_state_clear(&This
->state
, TRUE
);
903 nine_context_clear(This
);
905 NineDevice9_SetDefaultState(This
, TRUE
);
906 NineDevice9_SetRenderTarget(
907 This
, 0, (IDirect3DSurface9
*)This
->swapchains
[0]->buffers
[0]);
908 /* XXX: better use GetBackBuffer here ? */
910 This
->device_needs_reset
= (hr
!= D3D_OK
);
915 NineDevice9_Present( struct NineDevice9
*This
,
916 const RECT
*pSourceRect
,
917 const RECT
*pDestRect
,
918 HWND hDestWindowOverride
,
919 const RGNDATA
*pDirtyRegion
)
924 DBG("This=%p pSourceRect=%p pDestRect=%p hDestWindowOverride=%p pDirtyRegion=%p\n",
925 This
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
927 /* XXX is this right? */
928 for (i
= 0; i
< This
->nswapchains
; ++i
) {
929 hr
= NineSwapChain9_Present(This
->swapchains
[i
], pSourceRect
, pDestRect
,
930 hDestWindowOverride
, pDirtyRegion
, 0);
931 if (FAILED(hr
)) { return hr
; }
938 NineDevice9_GetBackBuffer( struct NineDevice9
*This
,
941 D3DBACKBUFFER_TYPE Type
,
942 IDirect3DSurface9
**ppBackBuffer
)
944 user_assert(ppBackBuffer
!= NULL
, D3DERR_INVALIDCALL
);
945 /* return NULL on error */
946 *ppBackBuffer
= NULL
;
947 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
949 return NineSwapChain9_GetBackBuffer(This
->swapchains
[iSwapChain
],
950 iBackBuffer
, Type
, ppBackBuffer
);
954 NineDevice9_GetRasterStatus( struct NineDevice9
*This
,
956 D3DRASTER_STATUS
*pRasterStatus
)
958 user_assert(pRasterStatus
!= NULL
, D3DERR_INVALIDCALL
);
959 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
961 return NineSwapChain9_GetRasterStatus(This
->swapchains
[iSwapChain
],
966 NineDevice9_SetDialogBoxMode( struct NineDevice9
*This
,
967 BOOL bEnableDialogs
)
969 STUB(D3DERR_INVALIDCALL
);
973 NineDevice9_SetGammaRamp( struct NineDevice9
*This
,
976 const D3DGAMMARAMP
*pRamp
)
978 DBG("This=%p iSwapChain=%u Flags=%x pRamp=%p\n", This
,
979 iSwapChain
, Flags
, pRamp
);
981 user_warn(iSwapChain
>= This
->nswapchains
);
984 if (pRamp
&& (iSwapChain
< This
->nswapchains
)) {
985 struct NineSwapChain9
*swap
= This
->swapchains
[iSwapChain
];
986 swap
->gamma
= *pRamp
;
987 ID3DPresent_SetGammaRamp(swap
->present
, pRamp
, swap
->params
.hDeviceWindow
);
992 NineDevice9_GetGammaRamp( struct NineDevice9
*This
,
994 D3DGAMMARAMP
*pRamp
)
996 DBG("This=%p iSwapChain=%u pRamp=%p\n", This
, iSwapChain
, pRamp
);
998 user_warn(iSwapChain
>= This
->nswapchains
);
1001 if (pRamp
&& (iSwapChain
< This
->nswapchains
))
1002 *pRamp
= This
->swapchains
[iSwapChain
]->gamma
;
1006 NineDevice9_CreateTexture( struct NineDevice9
*This
,
1013 IDirect3DTexture9
**ppTexture
,
1014 HANDLE
*pSharedHandle
)
1016 struct NineTexture9
*tex
;
1019 DBG("This=%p Width=%u Height=%u Levels=%u Usage=%s Format=%s Pool=%s "
1020 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Levels
,
1021 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
1022 nine_D3DPOOL_to_str(Pool
), ppTexture
, pSharedHandle
);
1024 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DMAP
|
1025 D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
1026 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
;
1030 hr
= NineTexture9_new(This
, Width
, Height
, Levels
, Usage
, Format
, Pool
,
1031 &tex
, pSharedHandle
);
1033 *ppTexture
= (IDirect3DTexture9
*)tex
;
1039 NineDevice9_CreateVolumeTexture( struct NineDevice9
*This
,
1047 IDirect3DVolumeTexture9
**ppVolumeTexture
,
1048 HANDLE
*pSharedHandle
)
1050 struct NineVolumeTexture9
*tex
;
1053 DBG("This=%p Width=%u Height=%u Depth=%u Levels=%u Usage=%s Format=%s Pool=%s "
1054 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Depth
, Levels
,
1055 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
1056 nine_D3DPOOL_to_str(Pool
), ppVolumeTexture
, pSharedHandle
);
1058 Usage
&= D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1059 D3DUSAGE_SOFTWAREPROCESSING
;
1061 *ppVolumeTexture
= NULL
;
1063 hr
= NineVolumeTexture9_new(This
, Width
, Height
, Depth
, Levels
,
1064 Usage
, Format
, Pool
, &tex
, pSharedHandle
);
1066 *ppVolumeTexture
= (IDirect3DVolumeTexture9
*)tex
;
1072 NineDevice9_CreateCubeTexture( struct NineDevice9
*This
,
1078 IDirect3DCubeTexture9
**ppCubeTexture
,
1079 HANDLE
*pSharedHandle
)
1081 struct NineCubeTexture9
*tex
;
1084 DBG("This=%p EdgeLength=%u Levels=%u Usage=%s Format=%s Pool=%s ppOut=%p "
1085 "pSharedHandle=%p\n", This
, EdgeLength
, Levels
,
1086 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
1087 nine_D3DPOOL_to_str(Pool
), ppCubeTexture
, pSharedHandle
);
1089 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DYNAMIC
|
1090 D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
1091 D3DUSAGE_SOFTWAREPROCESSING
;
1093 *ppCubeTexture
= NULL
;
1095 hr
= NineCubeTexture9_new(This
, EdgeLength
, Levels
, Usage
, Format
, Pool
,
1096 &tex
, pSharedHandle
);
1098 *ppCubeTexture
= (IDirect3DCubeTexture9
*)tex
;
1104 NineDevice9_CreateVertexBuffer( struct NineDevice9
*This
,
1109 IDirect3DVertexBuffer9
**ppVertexBuffer
,
1110 HANDLE
*pSharedHandle
)
1112 struct NineVertexBuffer9
*buf
;
1114 D3DVERTEXBUFFER_DESC desc
;
1116 DBG("This=%p Length=%u Usage=%x FVF=%x Pool=%u ppOut=%p pSharedHandle=%p\n",
1117 This
, Length
, Usage
, FVF
, Pool
, ppVertexBuffer
, pSharedHandle
);
1119 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1121 desc
.Format
= D3DFMT_VERTEXDATA
;
1122 desc
.Type
= D3DRTYPE_VERTEXBUFFER
;
1123 desc
.Usage
= Usage
&
1124 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1125 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1126 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
|
1127 D3DUSAGE_WRITEONLY
);
1132 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1133 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1135 hr
= NineVertexBuffer9_new(This
, &desc
, &buf
);
1137 *ppVertexBuffer
= (IDirect3DVertexBuffer9
*)buf
;
1142 NineDevice9_CreateIndexBuffer( struct NineDevice9
*This
,
1147 IDirect3DIndexBuffer9
**ppIndexBuffer
,
1148 HANDLE
*pSharedHandle
)
1150 struct NineIndexBuffer9
*buf
;
1152 D3DINDEXBUFFER_DESC desc
;
1154 DBG("This=%p Length=%u Usage=%x Format=%s Pool=%u ppOut=%p "
1155 "pSharedHandle=%p\n", This
, Length
, Usage
,
1156 d3dformat_to_string(Format
), Pool
, ppIndexBuffer
, pSharedHandle
);
1158 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1160 desc
.Format
= Format
;
1161 desc
.Type
= D3DRTYPE_INDEXBUFFER
;
1162 desc
.Usage
= Usage
&
1163 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1164 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1165 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_WRITEONLY
);
1169 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1170 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1172 hr
= NineIndexBuffer9_new(This
, &desc
, &buf
);
1174 *ppIndexBuffer
= (IDirect3DIndexBuffer9
*)buf
;
1179 create_zs_or_rt_surface(struct NineDevice9
*This
,
1180 unsigned type
, /* 0 = RT, 1 = ZS, 2 = plain */
1182 UINT Width
, UINT Height
,
1184 D3DMULTISAMPLE_TYPE MultiSample
,
1185 DWORD MultisampleQuality
,
1186 BOOL Discard_or_Lockable
,
1187 IDirect3DSurface9
**ppSurface
,
1188 HANDLE
*pSharedHandle
)
1190 struct NineSurface9
*surface
;
1192 D3DSURFACE_DESC desc
;
1194 DBG("This=%p type=%u Pool=%s Width=%u Height=%u Format=%s MS=%u Quality=%u "
1195 "Discard_or_Lockable=%i ppSurface=%p pSharedHandle=%p\n",
1196 This
, type
, nine_D3DPOOL_to_str(Pool
), Width
, Height
,
1197 d3dformat_to_string(Format
), MultiSample
, MultisampleQuality
,
1198 Discard_or_Lockable
, ppSurface
, pSharedHandle
);
1201 DBG("FIXME Used shared handle! This option isn't probably handled correctly!\n");
1203 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
1204 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1206 desc
.Format
= Format
;
1207 desc
.Type
= D3DRTYPE_SURFACE
;
1210 desc
.MultiSampleType
= MultiSample
;
1211 desc
.MultiSampleQuality
= MultisampleQuality
;
1213 desc
.Height
= Height
;
1215 case 0: desc
.Usage
= D3DUSAGE_RENDERTARGET
; break;
1216 case 1: desc
.Usage
= D3DUSAGE_DEPTHSTENCIL
; break;
1217 default: assert(type
== 2); break;
1220 hr
= NineSurface9_new(This
, NULL
, NULL
, NULL
, 0, 0, 0, &desc
, &surface
);
1221 if (SUCCEEDED(hr
)) {
1222 *ppSurface
= (IDirect3DSurface9
*)surface
;
1224 if (surface
->base
.resource
&& Discard_or_Lockable
&& (type
!= 1))
1225 surface
->base
.resource
->flags
|= NINE_RESOURCE_FLAG_LOCKABLE
;
1232 NineDevice9_CreateRenderTarget( struct NineDevice9
*This
,
1236 D3DMULTISAMPLE_TYPE MultiSample
,
1237 DWORD MultisampleQuality
,
1239 IDirect3DSurface9
**ppSurface
,
1240 HANDLE
*pSharedHandle
)
1243 return create_zs_or_rt_surface(This
, 0, D3DPOOL_DEFAULT
,
1244 Width
, Height
, Format
,
1245 MultiSample
, MultisampleQuality
,
1246 Lockable
, ppSurface
, pSharedHandle
);
1250 NineDevice9_CreateDepthStencilSurface( struct NineDevice9
*This
,
1254 D3DMULTISAMPLE_TYPE MultiSample
,
1255 DWORD MultisampleQuality
,
1257 IDirect3DSurface9
**ppSurface
,
1258 HANDLE
*pSharedHandle
)
1261 if (!depth_stencil_format(Format
))
1262 return D3DERR_NOTAVAILABLE
;
1263 return create_zs_or_rt_surface(This
, 1, D3DPOOL_DEFAULT
,
1264 Width
, Height
, Format
,
1265 MultiSample
, MultisampleQuality
,
1266 Discard
, ppSurface
, pSharedHandle
);
1270 NineDevice9_UpdateSurface( struct NineDevice9
*This
,
1271 IDirect3DSurface9
*pSourceSurface
,
1272 const RECT
*pSourceRect
,
1273 IDirect3DSurface9
*pDestinationSurface
,
1274 const POINT
*pDestPoint
)
1276 struct NineSurface9
*dst
= NineSurface9(pDestinationSurface
);
1277 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1278 int copy_width
, copy_height
;
1281 DBG("This=%p pSourceSurface=%p pDestinationSurface=%p "
1282 "pSourceRect=%p pDestPoint=%p\n", This
,
1283 pSourceSurface
, pDestinationSurface
, pSourceRect
, pDestPoint
);
1285 DBG("pSourceRect = (%u,%u)-(%u,%u)\n",
1286 pSourceRect
->left
, pSourceRect
->top
,
1287 pSourceRect
->right
, pSourceRect
->bottom
);
1289 DBG("pDestPoint = (%u,%u)\n", pDestPoint
->x
, pDestPoint
->y
);
1291 user_assert(dst
&& src
, D3DERR_INVALIDCALL
);
1293 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1294 user_assert(src
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1296 user_assert(dst
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1297 user_assert(src
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1299 user_assert(!src
->lock_count
, D3DERR_INVALIDCALL
);
1300 user_assert(!dst
->lock_count
, D3DERR_INVALIDCALL
);
1302 user_assert(dst
->desc
.Format
== src
->desc
.Format
, D3DERR_INVALIDCALL
);
1303 user_assert(!depth_stencil_format(dst
->desc
.Format
), D3DERR_INVALIDCALL
);
1306 copy_width
= pSourceRect
->right
- pSourceRect
->left
;
1307 copy_height
= pSourceRect
->bottom
- pSourceRect
->top
;
1309 user_assert(pSourceRect
->left
>= 0 &&
1311 pSourceRect
->right
<= src
->desc
.Width
&&
1312 pSourceRect
->top
>= 0 &&
1314 pSourceRect
->bottom
<= src
->desc
.Height
,
1315 D3DERR_INVALIDCALL
);
1317 copy_width
= src
->desc
.Width
;
1318 copy_height
= src
->desc
.Height
;
1321 destRect
.right
= copy_width
;
1322 destRect
.bottom
= copy_height
;
1325 user_assert(pDestPoint
->x
>= 0 && pDestPoint
->y
>= 0,
1326 D3DERR_INVALIDCALL
);
1327 destRect
.right
+= pDestPoint
->x
;
1328 destRect
.bottom
+= pDestPoint
->y
;
1331 user_assert(destRect
.right
<= dst
->desc
.Width
&&
1332 destRect
.bottom
<= dst
->desc
.Height
,
1333 D3DERR_INVALIDCALL
);
1335 if (compressed_format(dst
->desc
.Format
)) {
1336 const unsigned w
= util_format_get_blockwidth(dst
->base
.info
.format
);
1337 const unsigned h
= util_format_get_blockheight(dst
->base
.info
.format
);
1340 user_assert(!(pDestPoint
->x
% w
) && !(pDestPoint
->y
% h
),
1341 D3DERR_INVALIDCALL
);
1345 user_assert(!(pSourceRect
->left
% w
) && !(pSourceRect
->top
% h
),
1346 D3DERR_INVALIDCALL
);
1348 if (!(copy_width
== src
->desc
.Width
&&
1349 copy_width
== dst
->desc
.Width
&&
1350 copy_height
== src
->desc
.Height
&&
1351 copy_height
== dst
->desc
.Height
)) {
1352 user_assert(!(copy_width
% w
) && !(copy_height
% h
),
1353 D3DERR_INVALIDCALL
);
1357 NineSurface9_CopyMemToDefault(dst
, src
, pDestPoint
, pSourceRect
);
1363 NineDevice9_UpdateTexture( struct NineDevice9
*This
,
1364 IDirect3DBaseTexture9
*pSourceTexture
,
1365 IDirect3DBaseTexture9
*pDestinationTexture
)
1367 struct NineBaseTexture9
*dstb
= NineBaseTexture9(pDestinationTexture
);
1368 struct NineBaseTexture9
*srcb
= NineBaseTexture9(pSourceTexture
);
1370 unsigned last_src_level
, last_dst_level
;
1373 DBG("This=%p pSourceTexture=%p pDestinationTexture=%p\n", This
,
1374 pSourceTexture
, pDestinationTexture
);
1376 user_assert(pSourceTexture
&& pDestinationTexture
, D3DERR_INVALIDCALL
);
1377 user_assert(pSourceTexture
!= pDestinationTexture
, D3DERR_INVALIDCALL
);
1379 user_assert(dstb
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1380 user_assert(srcb
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1381 user_assert(dstb
->base
.type
== srcb
->base
.type
, D3DERR_INVALIDCALL
);
1382 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ||
1383 dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
, D3DERR_INVALIDCALL
);
1386 * . Different formats
1387 * . Fewer src levels than dst levels (if the opposite, only matching levels
1388 * are supposed to be copied)
1389 * . Levels do not match
1390 * DDI: Actually the above should pass because of legacy applications
1391 * Do what you want about these, but you shouldn't crash.
1392 * However driver can expect that the top dimension is greater for src than dst.
1393 * Wine tests: Every combination that passes the initial checks should pass.
1394 * . Different formats => conversion driver and format dependent.
1395 * . 1 level, but size not matching => copy is done (and even crash if src bigger
1396 * than dst. For the case where dst bigger, wine doesn't test if a stretch is applied
1397 * or if a subrect is copied).
1398 * . 8x8 4 sublevels -> 7x7 2 sublevels => driver dependent, On NV seems to be 4x4 subrect
1401 * From these, the proposal is:
1402 * . Different formats -> use util_format_translate to translate if possible for surfaces.
1403 * Accept ARGB/XRGB for Volumes. Do nothing for the other combinations
1404 * . First level copied -> the first level such that src is smaller or equal to dst first level
1405 * . number of levels copied -> as long as it fits and textures have levels
1406 * That should satisfy the constraints (and instead of crashing for some cases we return D3D_OK)
1409 last_src_level
= (srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ? 0 : srcb
->base
.info
.last_level
;
1410 last_dst_level
= (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ? 0 : dstb
->base
.info
.last_level
;
1412 for (m
= 0; m
<= last_src_level
; ++m
) {
1413 unsigned w
= u_minify(srcb
->base
.info
.width0
, m
);
1414 unsigned h
= u_minify(srcb
->base
.info
.height0
, m
);
1415 unsigned d
= u_minify(srcb
->base
.info
.depth0
, m
);
1417 if (w
<= dstb
->base
.info
.width0
&&
1418 h
<= dstb
->base
.info
.height0
&&
1419 d
<= dstb
->base
.info
.depth0
)
1422 user_assert(m
<= last_src_level
, D3D_OK
);
1424 last_dst_level
= MIN2(srcb
->base
.info
.last_level
- m
, last_dst_level
);
1426 if (dstb
->base
.type
== D3DRTYPE_TEXTURE
) {
1427 struct NineTexture9
*dst
= NineTexture9(dstb
);
1428 struct NineTexture9
*src
= NineTexture9(srcb
);
1430 if (src
->dirty_rect
.width
== 0)
1433 pipe_box_to_rect(&rect
, &src
->dirty_rect
);
1434 for (l
= 0; l
< m
; ++l
)
1435 rect_minify_inclusive(&rect
);
1437 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
) {
1438 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1440 dst
->surfaces
[l
]->desc
.Width
,
1441 dst
->surfaces
[l
]->desc
.Height
);
1442 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
],
1446 rect_minify_inclusive(&rect
);
1448 u_box_origin_2d(0, 0, &src
->dirty_rect
);
1450 if (dstb
->base
.type
== D3DRTYPE_CUBETEXTURE
) {
1451 struct NineCubeTexture9
*dst
= NineCubeTexture9(dstb
);
1452 struct NineCubeTexture9
*src
= NineCubeTexture9(srcb
);
1455 /* GPUs usually have them stored as arrays of mip-mapped 2D textures. */
1456 for (z
= 0; z
< 6; ++z
) {
1457 if (src
->dirty_rect
[z
].width
== 0)
1460 pipe_box_to_rect(&rect
, &src
->dirty_rect
[z
]);
1461 for (l
= 0; l
< m
; ++l
)
1462 rect_minify_inclusive(&rect
);
1464 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
) {
1465 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1467 dst
->surfaces
[l
* 6 + z
]->desc
.Width
,
1468 dst
->surfaces
[l
* 6 + z
]->desc
.Height
);
1469 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
* 6 + z
],
1470 src
->surfaces
[m
* 6 + z
],
1473 rect_minify_inclusive(&rect
);
1475 u_box_origin_2d(0, 0, &src
->dirty_rect
[z
]);
1479 if (dstb
->base
.type
== D3DRTYPE_VOLUMETEXTURE
) {
1480 struct NineVolumeTexture9
*dst
= NineVolumeTexture9(dstb
);
1481 struct NineVolumeTexture9
*src
= NineVolumeTexture9(srcb
);
1483 if (src
->dirty_box
.width
== 0)
1485 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
)
1486 NineVolume9_CopyMemToDefault(dst
->volumes
[l
],
1487 src
->volumes
[m
], 0, 0, 0, NULL
);
1488 u_box_3d(0, 0, 0, 0, 0, 0, &src
->dirty_box
);
1490 assert(!"invalid texture type");
1493 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1494 dstb
->dirty_mip
= TRUE
;
1495 NineBaseTexture9_GenerateMipSubLevels(dstb
);
1502 NineDevice9_GetRenderTargetData( struct NineDevice9
*This
,
1503 IDirect3DSurface9
*pRenderTarget
,
1504 IDirect3DSurface9
*pDestSurface
)
1506 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1507 struct NineSurface9
*src
= NineSurface9(pRenderTarget
);
1509 DBG("This=%p pRenderTarget=%p pDestSurface=%p\n",
1510 This
, pRenderTarget
, pDestSurface
);
1512 user_assert(pRenderTarget
&& pDestSurface
, D3DERR_INVALIDCALL
);
1514 user_assert(dst
->desc
.Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1515 user_assert(src
->desc
.Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1517 user_assert(dst
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1518 user_assert(src
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1520 user_assert(src
->desc
.Width
== dst
->desc
.Width
, D3DERR_INVALIDCALL
);
1521 user_assert(src
->desc
.Height
== dst
->desc
.Height
, D3DERR_INVALIDCALL
);
1523 user_assert(src
->desc
.Format
!= D3DFMT_NULL
, D3DERR_INVALIDCALL
);
1525 NineSurface9_CopyDefaultToMem(dst
, src
);
1531 NineDevice9_GetFrontBufferData( struct NineDevice9
*This
,
1533 IDirect3DSurface9
*pDestSurface
)
1535 DBG("This=%p iSwapChain=%u pDestSurface=%p\n", This
,
1536 iSwapChain
, pDestSurface
);
1538 user_assert(pDestSurface
!= NULL
, D3DERR_INVALIDCALL
);
1539 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
1541 return NineSwapChain9_GetFrontBufferData(This
->swapchains
[iSwapChain
],
1546 NineDevice9_StretchRect( struct NineDevice9
*This
,
1547 IDirect3DSurface9
*pSourceSurface
,
1548 const RECT
*pSourceRect
,
1549 IDirect3DSurface9
*pDestSurface
,
1550 const RECT
*pDestRect
,
1551 D3DTEXTUREFILTERTYPE Filter
)
1553 struct pipe_screen
*screen
= This
->screen
;
1554 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1555 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1556 struct pipe_resource
*dst_res
= NineSurface9_GetResource(dst
);
1557 struct pipe_resource
*src_res
= NineSurface9_GetResource(src
);
1559 struct pipe_blit_info blit
;
1560 boolean scaled
, clamped
, ms
, flip_x
= FALSE
, flip_y
= FALSE
;
1562 DBG("This=%p pSourceSurface=%p pSourceRect=%p pDestSurface=%p "
1563 "pDestRect=%p Filter=%u\n",
1564 This
, pSourceSurface
, pSourceRect
, pDestSurface
, pDestRect
, Filter
);
1566 DBG("pSourceRect=(%u,%u)-(%u,%u)\n",
1567 pSourceRect
->left
, pSourceRect
->top
,
1568 pSourceRect
->right
, pSourceRect
->bottom
);
1570 DBG("pDestRect=(%u,%u)-(%u,%u)\n", pDestRect
->left
, pDestRect
->top
,
1571 pDestRect
->right
, pDestRect
->bottom
);
1573 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
&&
1574 src
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1575 zs
= util_format_is_depth_or_stencil(dst_res
->format
);
1576 user_assert(!zs
|| !This
->in_scene
, D3DERR_INVALIDCALL
);
1577 user_assert(!zs
|| !pSourceRect
||
1578 (pSourceRect
->left
== 0 &&
1579 pSourceRect
->top
== 0 &&
1580 pSourceRect
->right
== src
->desc
.Width
&&
1581 pSourceRect
->bottom
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1582 user_assert(!zs
|| !pDestRect
||
1583 (pDestRect
->left
== 0 &&
1584 pDestRect
->top
== 0 &&
1585 pDestRect
->right
== dst
->desc
.Width
&&
1586 pDestRect
->bottom
== dst
->desc
.Height
), D3DERR_INVALIDCALL
);
1588 (dst
->desc
.Width
== src
->desc
.Width
&&
1589 dst
->desc
.Height
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1590 user_assert(zs
|| !util_format_is_depth_or_stencil(src_res
->format
),
1591 D3DERR_INVALIDCALL
);
1592 user_assert(!zs
|| dst
->desc
.Format
== src
->desc
.Format
,
1593 D3DERR_INVALIDCALL
);
1594 user_assert(screen
->is_format_supported(screen
, src_res
->format
,
1596 src_res
->nr_samples
,
1597 PIPE_BIND_SAMPLER_VIEW
),
1598 D3DERR_INVALIDCALL
);
1600 /* We might want to permit these, but wine thinks we shouldn't. */
1601 user_assert(!pDestRect
||
1602 (pDestRect
->left
<= pDestRect
->right
&&
1603 pDestRect
->top
<= pDestRect
->bottom
), D3DERR_INVALIDCALL
);
1604 user_assert(!pSourceRect
||
1605 (pSourceRect
->left
<= pSourceRect
->right
&&
1606 pSourceRect
->top
<= pSourceRect
->bottom
), D3DERR_INVALIDCALL
);
1608 memset(&blit
, 0, sizeof(blit
));
1609 blit
.dst
.resource
= dst_res
;
1610 blit
.dst
.level
= dst
->level
;
1611 blit
.dst
.box
.z
= dst
->layer
;
1612 blit
.dst
.box
.depth
= 1;
1613 blit
.dst
.format
= dst_res
->format
;
1615 flip_x
= pDestRect
->left
> pDestRect
->right
;
1617 blit
.dst
.box
.x
= pDestRect
->right
;
1618 blit
.dst
.box
.width
= pDestRect
->left
- pDestRect
->right
;
1620 blit
.dst
.box
.x
= pDestRect
->left
;
1621 blit
.dst
.box
.width
= pDestRect
->right
- pDestRect
->left
;
1623 flip_y
= pDestRect
->top
> pDestRect
->bottom
;
1625 blit
.dst
.box
.y
= pDestRect
->bottom
;
1626 blit
.dst
.box
.height
= pDestRect
->top
- pDestRect
->bottom
;
1628 blit
.dst
.box
.y
= pDestRect
->top
;
1629 blit
.dst
.box
.height
= pDestRect
->bottom
- pDestRect
->top
;
1634 blit
.dst
.box
.width
= dst
->desc
.Width
;
1635 blit
.dst
.box
.height
= dst
->desc
.Height
;
1637 blit
.src
.resource
= src_res
;
1638 blit
.src
.level
= src
->level
;
1639 blit
.src
.box
.z
= src
->layer
;
1640 blit
.src
.box
.depth
= 1;
1641 blit
.src
.format
= src_res
->format
;
1643 if (flip_x
^ (pSourceRect
->left
> pSourceRect
->right
)) {
1644 blit
.src
.box
.x
= pSourceRect
->right
;
1645 blit
.src
.box
.width
= pSourceRect
->left
- pSourceRect
->right
;
1647 blit
.src
.box
.x
= pSourceRect
->left
;
1648 blit
.src
.box
.width
= pSourceRect
->right
- pSourceRect
->left
;
1650 if (flip_y
^ (pSourceRect
->top
> pSourceRect
->bottom
)) {
1651 blit
.src
.box
.y
= pSourceRect
->bottom
;
1652 blit
.src
.box
.height
= pSourceRect
->top
- pSourceRect
->bottom
;
1654 blit
.src
.box
.y
= pSourceRect
->top
;
1655 blit
.src
.box
.height
= pSourceRect
->bottom
- pSourceRect
->top
;
1658 blit
.src
.box
.x
= flip_x
? src
->desc
.Width
: 0;
1659 blit
.src
.box
.y
= flip_y
? src
->desc
.Height
: 0;
1660 blit
.src
.box
.width
= flip_x
? -src
->desc
.Width
: src
->desc
.Width
;
1661 blit
.src
.box
.height
= flip_y
? -src
->desc
.Height
: src
->desc
.Height
;
1663 blit
.mask
= zs
? PIPE_MASK_ZS
: PIPE_MASK_RGBA
;
1664 blit
.filter
= Filter
== D3DTEXF_LINEAR
?
1665 PIPE_TEX_FILTER_LINEAR
: PIPE_TEX_FILTER_NEAREST
;
1666 blit
.scissor_enable
= FALSE
;
1667 blit
.alpha_blend
= FALSE
;
1669 /* If both of a src and dst dimension are negative, flip them. */
1670 if (blit
.dst
.box
.width
< 0 && blit
.src
.box
.width
< 0) {
1671 blit
.dst
.box
.width
= -blit
.dst
.box
.width
;
1672 blit
.src
.box
.width
= -blit
.src
.box
.width
;
1674 if (blit
.dst
.box
.height
< 0 && blit
.src
.box
.height
< 0) {
1675 blit
.dst
.box
.height
= -blit
.dst
.box
.height
;
1676 blit
.src
.box
.height
= -blit
.src
.box
.height
;
1679 blit
.dst
.box
.width
!= blit
.src
.box
.width
||
1680 blit
.dst
.box
.height
!= blit
.src
.box
.height
;
1682 user_assert(!scaled
|| dst
!= src
, D3DERR_INVALIDCALL
);
1683 user_assert(!scaled
||
1684 !NineSurface9_IsOffscreenPlain(dst
), D3DERR_INVALIDCALL
);
1685 user_assert(!NineSurface9_IsOffscreenPlain(dst
) ||
1686 NineSurface9_IsOffscreenPlain(src
), D3DERR_INVALIDCALL
);
1687 user_assert(NineSurface9_IsOffscreenPlain(dst
) ||
1688 dst
->desc
.Usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
),
1689 D3DERR_INVALIDCALL
);
1690 user_assert(!scaled
||
1691 (!util_format_is_compressed(dst
->base
.info
.format
) &&
1692 !util_format_is_compressed(src
->base
.info
.format
)),
1693 D3DERR_INVALIDCALL
);
1695 user_warn(src
== dst
&&
1696 u_box_test_intersection_2d(&blit
.src
.box
, &blit
.dst
.box
));
1698 /* Check for clipping/clamping: */
1700 struct pipe_box box
;
1703 xy
= u_box_clip_2d(&box
, &blit
.dst
.box
,
1704 dst
->desc
.Width
, dst
->desc
.Height
);
1708 xy
= u_box_clip_2d(&box
, &blit
.src
.box
,
1709 src
->desc
.Width
, src
->desc
.Height
);
1713 ms
= (dst
->desc
.MultiSampleType
!= src
->desc
.MultiSampleType
) ||
1714 (dst
->desc
.MultiSampleQuality
!= src
->desc
.MultiSampleQuality
);
1716 if (clamped
|| scaled
|| (blit
.dst
.format
!= blit
.src
.format
) || ms
) {
1717 DBG("using pipe->blit()\n");
1718 /* TODO: software scaling */
1719 user_assert(screen
->is_format_supported(screen
, dst_res
->format
,
1721 dst_res
->nr_samples
,
1722 zs
? PIPE_BIND_DEPTH_STENCIL
:
1723 PIPE_BIND_RENDER_TARGET
),
1724 D3DERR_INVALIDCALL
);
1726 nine_context_blit(This
, &blit
);
1728 assert(blit
.dst
.box
.x
>= 0 && blit
.dst
.box
.y
>= 0 &&
1729 blit
.src
.box
.x
>= 0 && blit
.src
.box
.y
>= 0 &&
1730 blit
.dst
.box
.x
+ blit
.dst
.box
.width
<= dst
->desc
.Width
&&
1731 blit
.src
.box
.x
+ blit
.src
.box
.width
<= src
->desc
.Width
&&
1732 blit
.dst
.box
.y
+ blit
.dst
.box
.height
<= dst
->desc
.Height
&&
1733 blit
.src
.box
.y
+ blit
.src
.box
.height
<= src
->desc
.Height
);
1734 /* Or drivers might crash ... */
1735 DBG("Using resource_copy_region.\n");
1736 nine_context_resource_copy_region(This
,
1737 blit
.dst
.resource
, blit
.dst
.level
,
1739 blit
.src
.resource
, blit
.src
.level
,
1743 /* Communicate the container it needs to update sublevels - if apply */
1744 NineSurface9_MarkContainerDirty(dst
);
1750 NineDevice9_ColorFill( struct NineDevice9
*This
,
1751 IDirect3DSurface9
*pSurface
,
1755 struct pipe_context
*pipe
= NineDevice9_GetPipe(This
);
1756 struct NineSurface9
*surf
= NineSurface9(pSurface
);
1757 struct pipe_surface
*psurf
;
1758 unsigned x
, y
, w
, h
;
1759 union pipe_color_union rgba
;
1761 DBG("This=%p pSurface=%p pRect=%p color=%08x\n", This
,
1762 pSurface
, pRect
, color
);
1764 DBG("pRect=(%u,%u)-(%u,%u)\n", pRect
->left
, pRect
->top
,
1765 pRect
->right
, pRect
->bottom
);
1767 user_assert(surf
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1769 user_assert((surf
->base
.usage
& D3DUSAGE_RENDERTARGET
) ||
1770 NineSurface9_IsOffscreenPlain(surf
), D3DERR_INVALIDCALL
);
1772 user_assert(surf
->desc
.Format
!= D3DFMT_NULL
, D3D_OK
);
1777 w
= pRect
->right
- pRect
->left
;
1778 h
= pRect
->bottom
- pRect
->top
;
1780 if (compressed_format(surf
->desc
.Format
)) {
1781 const unsigned bw
= util_format_get_blockwidth(surf
->base
.info
.format
);
1782 const unsigned bh
= util_format_get_blockheight(surf
->base
.info
.format
);
1784 user_assert(!(x
% bw
) && !(y
% bh
) && !(w
% bw
) && !(h
% bh
),
1785 D3DERR_INVALIDCALL
);
1790 w
= surf
->desc
.Width
;
1791 h
= surf
->desc
.Height
;
1793 d3dcolor_to_pipe_color_union(&rgba
, color
);
1795 if (surf
->base
.info
.bind
& PIPE_BIND_RENDER_TARGET
) {
1796 psurf
= NineSurface9_GetSurface(surf
, 0);
1797 pipe
->clear_render_target(pipe
, psurf
, &rgba
, x
, y
, w
, h
, false);
1799 D3DLOCKED_RECT lock
;
1800 union util_color uc
;
1802 /* XXX: lock pRect and fix util_fill_rect */
1803 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, 0);
1806 util_pack_color_ub(color
>> 16, color
>> 8, color
>> 0, color
>> 24,
1807 surf
->base
.info
.format
, &uc
);
1808 util_fill_rect(lock
.pBits
, surf
->base
.info
.format
,lock
.Pitch
,
1810 NineSurface9_UnlockRect(surf
);
1817 NineDevice9_CreateOffscreenPlainSurface( struct NineDevice9
*This
,
1822 IDirect3DSurface9
**ppSurface
,
1823 HANDLE
*pSharedHandle
)
1827 DBG("This=%p Width=%u Height=%u Format=%s(0x%x) Pool=%u "
1828 "ppSurface=%p pSharedHandle=%p\n", This
,
1829 Width
, Height
, d3dformat_to_string(Format
), Format
, Pool
,
1830 ppSurface
, pSharedHandle
);
1833 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
1834 || Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1835 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1837 /* Can be used with StretchRect and ColorFill. It's also always lockable.
1839 hr
= create_zs_or_rt_surface(This
, 2, Pool
, Width
, Height
,
1841 D3DMULTISAMPLE_NONE
, 0,
1843 ppSurface
, pSharedHandle
);
1845 DBG("Failed to create surface.\n");
1850 NineDevice9_SetRenderTarget( struct NineDevice9
*This
,
1851 DWORD RenderTargetIndex
,
1852 IDirect3DSurface9
*pRenderTarget
)
1854 struct NineSurface9
*rt
= NineSurface9(pRenderTarget
);
1855 const unsigned i
= RenderTargetIndex
;
1857 DBG("This=%p RenderTargetIndex=%u pRenderTarget=%p\n", This
,
1858 RenderTargetIndex
, pRenderTarget
);
1860 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1861 user_assert(i
!= 0 || pRenderTarget
, D3DERR_INVALIDCALL
);
1862 user_assert(!pRenderTarget
||
1863 rt
->desc
.Usage
& D3DUSAGE_RENDERTARGET
, D3DERR_INVALIDCALL
);
1866 This
->state
.viewport
.X
= 0;
1867 This
->state
.viewport
.Y
= 0;
1868 This
->state
.viewport
.Width
= rt
->desc
.Width
;
1869 This
->state
.viewport
.Height
= rt
->desc
.Height
;
1870 This
->state
.viewport
.MinZ
= 0.0f
;
1871 This
->state
.viewport
.MaxZ
= 1.0f
;
1873 This
->state
.scissor
.minx
= 0;
1874 This
->state
.scissor
.miny
= 0;
1875 This
->state
.scissor
.maxx
= rt
->desc
.Width
;
1876 This
->state
.scissor
.maxy
= rt
->desc
.Height
;
1879 if (This
->state
.rt
[i
] != NineSurface9(pRenderTarget
))
1880 nine_bind(&This
->state
.rt
[i
], pRenderTarget
);
1882 nine_context_set_render_target(This
, i
, rt
);
1887 NineDevice9_GetRenderTarget( struct NineDevice9
*This
,
1888 DWORD RenderTargetIndex
,
1889 IDirect3DSurface9
**ppRenderTarget
)
1891 const unsigned i
= RenderTargetIndex
;
1893 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1894 user_assert(ppRenderTarget
, D3DERR_INVALIDCALL
);
1896 *ppRenderTarget
= (IDirect3DSurface9
*)This
->state
.rt
[i
];
1897 if (!This
->state
.rt
[i
])
1898 return D3DERR_NOTFOUND
;
1900 NineUnknown_AddRef(NineUnknown(This
->state
.rt
[i
]));
1905 NineDevice9_SetDepthStencilSurface( struct NineDevice9
*This
,
1906 IDirect3DSurface9
*pNewZStencil
)
1908 struct NineSurface9
*ds
= NineSurface9(pNewZStencil
);
1909 DBG("This=%p pNewZStencil=%p\n", This
, pNewZStencil
);
1911 if (This
->state
.ds
!= ds
) {
1912 nine_bind(&This
->state
.ds
, ds
);
1913 nine_context_set_depth_stencil(This
, ds
);
1919 NineDevice9_GetDepthStencilSurface( struct NineDevice9
*This
,
1920 IDirect3DSurface9
**ppZStencilSurface
)
1922 user_assert(ppZStencilSurface
, D3DERR_INVALIDCALL
);
1924 *ppZStencilSurface
= (IDirect3DSurface9
*)This
->state
.ds
;
1925 if (!This
->state
.ds
)
1926 return D3DERR_NOTFOUND
;
1928 NineUnknown_AddRef(NineUnknown(This
->state
.ds
));
1933 NineDevice9_BeginScene( struct NineDevice9
*This
)
1935 DBG("This=%p\n", This
);
1936 user_assert(!This
->in_scene
, D3DERR_INVALIDCALL
);
1937 This
->in_scene
= TRUE
;
1938 /* Do we want to do anything else here ? */
1943 NineDevice9_EndScene( struct NineDevice9
*This
)
1945 DBG("This=%p\n", This
);
1946 user_assert(This
->in_scene
, D3DERR_INVALIDCALL
);
1947 This
->in_scene
= FALSE
;
1952 NineDevice9_Clear( struct NineDevice9
*This
,
1954 const D3DRECT
*pRects
,
1960 struct NineSurface9
*zsbuf_surf
= This
->state
.ds
;
1962 DBG("This=%p Count=%u pRects=%p Flags=%x Color=%08x Z=%f Stencil=%x\n",
1963 This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1965 user_assert(This
->state
.ds
|| !(Flags
& NINED3DCLEAR_DEPTHSTENCIL
),
1966 D3DERR_INVALIDCALL
);
1967 user_assert(!(Flags
& D3DCLEAR_STENCIL
) ||
1969 util_format_is_depth_and_stencil(zsbuf_surf
->base
.info
.format
)),
1970 D3DERR_INVALIDCALL
);
1972 user_assert((Count
&& pRects
) || (!Count
&& !pRects
), D3DERR_INVALIDCALL
);
1974 user_warn((pRects
&& !Count
) || (!pRects
&& Count
));
1975 if (pRects
&& !Count
)
1981 nine_context_clear_fb(This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1986 NineDevice9_SetTransform( struct NineDevice9
*This
,
1987 D3DTRANSFORMSTATETYPE State
,
1988 const D3DMATRIX
*pMatrix
)
1990 struct nine_state
*state
= This
->update
;
1991 D3DMATRIX
*M
= nine_state_access_transform(&state
->ff
, State
, TRUE
);
1993 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
1995 user_assert(M
, D3DERR_INVALIDCALL
);
1998 if (unlikely(This
->is_recording
)) {
1999 state
->ff
.changed
.transform
[State
/ 32] |= 1 << (State
% 32);
2000 state
->changed
.group
|= NINE_STATE_FF
;
2002 nine_context_set_transform(This
, State
, pMatrix
);
2008 NineDevice9_GetTransform( struct NineDevice9
*This
,
2009 D3DTRANSFORMSTATETYPE State
,
2010 D3DMATRIX
*pMatrix
)
2012 D3DMATRIX
*M
= nine_state_access_transform(&This
->state
.ff
, State
, FALSE
);
2013 user_assert(M
, D3DERR_INVALIDCALL
);
2019 NineDevice9_MultiplyTransform( struct NineDevice9
*This
,
2020 D3DTRANSFORMSTATETYPE State
,
2021 const D3DMATRIX
*pMatrix
)
2023 struct nine_state
*state
= This
->update
;
2025 D3DMATRIX
*M
= nine_state_access_transform(&state
->ff
, State
, TRUE
);
2027 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2029 user_assert(M
, D3DERR_INVALIDCALL
);
2031 nine_d3d_matrix_matrix_mul(&T
, pMatrix
, M
);
2032 return NineDevice9_SetTransform(This
, State
, &T
);
2036 NineDevice9_SetViewport( struct NineDevice9
*This
,
2037 const D3DVIEWPORT9
*pViewport
)
2039 struct nine_state
*state
= This
->update
;
2041 DBG("X=%u Y=%u W=%u H=%u MinZ=%f MaxZ=%f\n",
2042 pViewport
->X
, pViewport
->Y
, pViewport
->Width
, pViewport
->Height
,
2043 pViewport
->MinZ
, pViewport
->MaxZ
);
2045 state
->viewport
= *pViewport
;
2046 nine_context_set_viewport(This
, pViewport
);
2052 NineDevice9_GetViewport( struct NineDevice9
*This
,
2053 D3DVIEWPORT9
*pViewport
)
2055 *pViewport
= This
->state
.viewport
;
2060 NineDevice9_SetMaterial( struct NineDevice9
*This
,
2061 const D3DMATERIAL9
*pMaterial
)
2063 struct nine_state
*state
= This
->update
;
2065 DBG("This=%p pMaterial=%p\n", This
, pMaterial
);
2067 nine_dump_D3DMATERIAL9(DBG_FF
, pMaterial
);
2069 user_assert(pMaterial
, E_POINTER
);
2071 state
->ff
.material
= *pMaterial
;
2072 if (unlikely(This
->is_recording
))
2073 state
->changed
.group
|= NINE_STATE_FF_MATERIAL
;
2075 nine_context_set_material(This
, pMaterial
);
2081 NineDevice9_GetMaterial( struct NineDevice9
*This
,
2082 D3DMATERIAL9
*pMaterial
)
2084 user_assert(pMaterial
, E_POINTER
);
2085 *pMaterial
= This
->state
.ff
.material
;
2090 NineDevice9_SetLight( struct NineDevice9
*This
,
2092 const D3DLIGHT9
*pLight
)
2094 struct nine_state
*state
= This
->update
;
2097 DBG("This=%p Index=%u pLight=%p\n", This
, Index
, pLight
);
2099 nine_dump_D3DLIGHT9(DBG_FF
, pLight
);
2101 user_assert(pLight
, D3DERR_INVALIDCALL
);
2102 user_assert(pLight
->Type
< NINED3DLIGHT_INVALID
, D3DERR_INVALIDCALL
);
2104 user_assert(Index
< NINE_MAX_LIGHTS
, D3DERR_INVALIDCALL
); /* sanity */
2106 hr
= nine_state_set_light(&state
->ff
, Index
, pLight
);
2110 if (pLight
->Type
!= D3DLIGHT_DIRECTIONAL
&&
2111 pLight
->Attenuation0
== 0.0f
&&
2112 pLight
->Attenuation1
== 0.0f
&&
2113 pLight
->Attenuation2
== 0.0f
) {
2114 DBG("Warning: all D3DLIGHT9.Attenuation[i] are 0\n");
2117 if (unlikely(This
->is_recording
))
2118 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2120 nine_context_set_light(This
, Index
, pLight
);
2126 NineDevice9_GetLight( struct NineDevice9
*This
,
2130 const struct nine_state
*state
= &This
->state
;
2132 user_assert(pLight
, D3DERR_INVALIDCALL
);
2133 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2134 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2135 D3DERR_INVALIDCALL
);
2137 *pLight
= state
->ff
.light
[Index
];
2143 NineDevice9_LightEnable( struct NineDevice9
*This
,
2147 struct nine_state
*state
= This
->update
;
2149 DBG("This=%p Index=%u Enable=%i\n", This
, Index
, Enable
);
2151 if (Index
>= state
->ff
.num_lights
||
2152 state
->ff
.light
[Index
].Type
== NINED3DLIGHT_INVALID
) {
2153 /* This should create a default light. */
2155 memset(&light
, 0, sizeof(light
));
2156 light
.Type
= D3DLIGHT_DIRECTIONAL
;
2157 light
.Diffuse
.r
= 1.0f
;
2158 light
.Diffuse
.g
= 1.0f
;
2159 light
.Diffuse
.b
= 1.0f
;
2160 light
.Direction
.z
= 1.0f
;
2161 NineDevice9_SetLight(This
, Index
, &light
);
2164 nine_state_light_enable(&state
->ff
, &state
->changed
.group
, Index
, Enable
);
2165 if (likely(!This
->is_recording
))
2166 nine_context_light_enable(This
, Index
, Enable
);
2172 NineDevice9_GetLightEnable( struct NineDevice9
*This
,
2176 const struct nine_state
*state
= &This
->state
;
2179 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2180 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2181 D3DERR_INVALIDCALL
);
2183 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
)
2184 if (state
->ff
.active_light
[i
] == Index
)
2187 *pEnable
= i
!= state
->ff
.num_lights_active
? 128 : 0; // Taken from wine
2193 NineDevice9_SetClipPlane( struct NineDevice9
*This
,
2195 const float *pPlane
)
2197 struct nine_state
*state
= This
->update
;
2199 user_assert(pPlane
, D3DERR_INVALIDCALL
);
2201 DBG("This=%p Index=%u pPlane=%f %f %f %f\n", This
, Index
,
2202 pPlane
[0], pPlane
[1],
2203 pPlane
[2], pPlane
[3]);
2205 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2207 memcpy(&state
->clip
.ucp
[Index
][0], pPlane
, sizeof(state
->clip
.ucp
[0]));
2208 if (unlikely(This
->is_recording
))
2209 state
->changed
.ucp
|= 1 << Index
;
2211 nine_context_set_clip_plane(This
, Index
, (struct nine_clipplane
*)pPlane
);
2217 NineDevice9_GetClipPlane( struct NineDevice9
*This
,
2221 const struct nine_state
*state
= &This
->state
;
2223 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2225 memcpy(pPlane
, &state
->clip
.ucp
[Index
][0], sizeof(state
->clip
.ucp
[0]));
2230 NineDevice9_SetRenderState( struct NineDevice9
*This
,
2231 D3DRENDERSTATETYPE State
,
2234 struct nine_state
*state
= This
->update
;
2236 DBG("This=%p State=%u(%s) Value=%08x\n", This
,
2237 State
, nine_d3drs_to_string(State
), Value
);
2239 user_assert(State
< D3DRS_COUNT
, D3DERR_INVALIDCALL
);
2241 if (unlikely(This
->is_recording
)) {
2242 state
->rs_advertised
[State
] = Value
;
2243 /* only need to record changed render states for stateblocks */
2244 state
->changed
.rs
[State
/ 32] |= 1 << (State
% 32);
2245 state
->changed
.group
|= nine_render_state_group
[State
];
2249 if (state
->rs_advertised
[State
] == Value
)
2252 state
->rs_advertised
[State
] = Value
;
2253 nine_context_set_render_state(This
, State
, Value
);
2259 NineDevice9_GetRenderState( struct NineDevice9
*This
,
2260 D3DRENDERSTATETYPE State
,
2263 user_assert(State
< D3DRS_COUNT
, D3DERR_INVALIDCALL
);
2265 *pValue
= This
->state
.rs_advertised
[State
];
2270 NineDevice9_CreateStateBlock( struct NineDevice9
*This
,
2271 D3DSTATEBLOCKTYPE Type
,
2272 IDirect3DStateBlock9
**ppSB
)
2274 struct NineStateBlock9
*nsb
;
2275 struct nine_state
*dst
;
2277 enum nine_stateblock_type type
;
2280 DBG("This=%p Type=%u ppSB=%p\n", This
, Type
, ppSB
);
2282 user_assert(Type
== D3DSBT_ALL
||
2283 Type
== D3DSBT_VERTEXSTATE
||
2284 Type
== D3DSBT_PIXELSTATE
, D3DERR_INVALIDCALL
);
2287 case D3DSBT_VERTEXSTATE
: type
= NINESBT_VERTEXSTATE
; break;
2288 case D3DSBT_PIXELSTATE
: type
= NINESBT_PIXELSTATE
; break;
2294 hr
= NineStateBlock9_new(This
, &nsb
, type
);
2297 *ppSB
= (IDirect3DStateBlock9
*)nsb
;
2300 dst
->changed
.group
=
2301 NINE_STATE_TEXTURE
|
2304 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_VERTEXSTATE
) {
2305 dst
->changed
.group
|=
2306 NINE_STATE_FF_LIGHTING
|
2307 NINE_STATE_VS
| NINE_STATE_VS_CONST
|
2309 /* TODO: texture/sampler state */
2310 memcpy(dst
->changed
.rs
,
2311 nine_render_states_vertex
, sizeof(dst
->changed
.rs
));
2312 nine_ranges_insert(&dst
->changed
.vs_const_f
, 0, This
->may_swvp
? NINE_MAX_CONST_F_SWVP
: This
->max_vs_const_f
,
2314 nine_ranges_insert(&dst
->changed
.vs_const_i
, 0, This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
,
2316 nine_ranges_insert(&dst
->changed
.vs_const_b
, 0, This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
,
2318 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2319 dst
->changed
.sampler
[s
] |= 1 << D3DSAMP_DMAPOFFSET
;
2320 if (This
->state
.ff
.num_lights
) {
2321 dst
->ff
.num_lights
= This
->state
.ff
.num_lights
;
2322 /* zero'd -> light type won't be NINED3DLIGHT_INVALID, so
2323 * all currently existing lights will be captured
2325 dst
->ff
.light
= CALLOC(This
->state
.ff
.num_lights
,
2327 if (!dst
->ff
.light
) {
2328 nine_bind(ppSB
, NULL
);
2329 return E_OUTOFMEMORY
;
2333 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_PIXELSTATE
) {
2334 dst
->changed
.group
|=
2335 NINE_STATE_PS
| NINE_STATE_PS_CONST
| NINE_STATE_BLEND
|
2336 NINE_STATE_FF_OTHER
| NINE_STATE_FF_PSSTAGES
| NINE_STATE_PS_CONST
|
2337 NINE_STATE_FB
| NINE_STATE_DSA
| NINE_STATE_MULTISAMPLE
|
2338 NINE_STATE_RASTERIZER
| NINE_STATE_STENCIL_REF
;
2339 memcpy(dst
->changed
.rs
,
2340 nine_render_states_pixel
, sizeof(dst
->changed
.rs
));
2341 nine_ranges_insert(&dst
->changed
.ps_const_f
, 0, This
->max_ps_const_f
,
2343 dst
->changed
.ps_const_i
= 0xffff;
2344 dst
->changed
.ps_const_b
= 0xffff;
2345 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2346 dst
->changed
.sampler
[s
] |= 0x1ffe;
2347 for (s
= 0; s
< NINE_MAX_TEXTURE_STAGES
; ++s
) {
2348 dst
->ff
.changed
.tex_stage
[s
][0] |= 0xffffffff;
2349 dst
->ff
.changed
.tex_stage
[s
][1] |= 0xffffffff;
2352 if (Type
== D3DSBT_ALL
) {
2353 dst
->changed
.group
|=
2354 NINE_STATE_VIEWPORT
|
2355 NINE_STATE_SCISSOR
|
2356 NINE_STATE_RASTERIZER
|
2360 NINE_STATE_MATERIAL
|
2361 NINE_STATE_BLEND_COLOR
|
2362 NINE_STATE_SAMPLE_MASK
;
2363 memset(dst
->changed
.rs
, ~0, (D3DRS_COUNT
/ 32) * sizeof(uint32_t));
2364 dst
->changed
.rs
[D3DRS_LAST
/ 32] |= (1 << (D3DRS_COUNT
% 32)) - 1;
2365 dst
->changed
.vtxbuf
= (1ULL << This
->caps
.MaxStreams
) - 1;
2366 dst
->changed
.stream_freq
= dst
->changed
.vtxbuf
;
2367 dst
->changed
.ucp
= (1 << PIPE_MAX_CLIP_PLANES
) - 1;
2368 dst
->changed
.texture
= (1 << NINE_MAX_SAMPLERS
) - 1;
2370 NineStateBlock9_Capture(NineStateBlock9(*ppSB
));
2372 /* TODO: fixed function state */
2378 NineDevice9_BeginStateBlock( struct NineDevice9
*This
)
2382 DBG("This=%p\n", This
);
2384 user_assert(!This
->record
, D3DERR_INVALIDCALL
);
2386 hr
= NineStateBlock9_new(This
, &This
->record
, NINESBT_CUSTOM
);
2389 NineUnknown_ConvertRefToBind(NineUnknown(This
->record
));
2391 This
->update
= &This
->record
->state
;
2392 This
->is_recording
= TRUE
;
2398 NineDevice9_EndStateBlock( struct NineDevice9
*This
,
2399 IDirect3DStateBlock9
**ppSB
)
2401 DBG("This=%p ppSB=%p\n", This
, ppSB
);
2403 user_assert(This
->record
, D3DERR_INVALIDCALL
);
2405 This
->update
= &This
->state
;
2406 This
->is_recording
= FALSE
;
2408 NineUnknown_AddRef(NineUnknown(This
->record
));
2409 *ppSB
= (IDirect3DStateBlock9
*)This
->record
;
2410 NineUnknown_Unbind(NineUnknown(This
->record
));
2411 This
->record
= NULL
;
2417 NineDevice9_SetClipStatus( struct NineDevice9
*This
,
2418 const D3DCLIPSTATUS9
*pClipStatus
)
2420 STUB(D3DERR_INVALIDCALL
);
2424 NineDevice9_GetClipStatus( struct NineDevice9
*This
,
2425 D3DCLIPSTATUS9
*pClipStatus
)
2427 STUB(D3DERR_INVALIDCALL
);
2431 NineDevice9_GetTexture( struct NineDevice9
*This
,
2433 IDirect3DBaseTexture9
**ppTexture
)
2435 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2436 Stage
== D3DDMAPSAMPLER
||
2437 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2438 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2439 user_assert(ppTexture
, D3DERR_INVALIDCALL
);
2441 if (Stage
>= D3DDMAPSAMPLER
)
2442 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2444 *ppTexture
= (IDirect3DBaseTexture9
*)This
->state
.texture
[Stage
];
2446 if (This
->state
.texture
[Stage
])
2447 NineUnknown_AddRef(NineUnknown(This
->state
.texture
[Stage
]));
2452 NineDevice9_SetTexture( struct NineDevice9
*This
,
2454 IDirect3DBaseTexture9
*pTexture
)
2456 struct nine_state
*state
= This
->update
;
2457 struct NineBaseTexture9
*tex
= NineBaseTexture9(pTexture
);
2458 struct NineBaseTexture9
*old
;
2460 DBG("This=%p Stage=%u pTexture=%p\n", This
, Stage
, pTexture
);
2462 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2463 Stage
== D3DDMAPSAMPLER
||
2464 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2465 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2466 user_assert(!tex
|| (tex
->base
.pool
!= D3DPOOL_SCRATCH
&&
2467 tex
->base
.pool
!= D3DPOOL_SYSTEMMEM
), D3DERR_INVALIDCALL
);
2469 if (Stage
>= D3DDMAPSAMPLER
)
2470 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2472 if (This
->is_recording
) {
2473 state
->changed
.texture
|= 1 << Stage
;
2474 state
->changed
.group
|= NINE_STATE_TEXTURE
;
2475 nine_bind(&state
->texture
[Stage
], pTexture
);
2479 old
= state
->texture
[Stage
];
2483 NineBindTextureToDevice(This
, &state
->texture
[Stage
], tex
);
2485 nine_context_set_texture(This
, Stage
, tex
);
2491 NineDevice9_GetTextureStageState( struct NineDevice9
*This
,
2493 D3DTEXTURESTAGESTATETYPE Type
,
2496 const struct nine_state
*state
= &This
->state
;
2498 user_assert(Stage
< ARRAY_SIZE(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2499 user_assert(Type
< ARRAY_SIZE(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2501 *pValue
= state
->ff
.tex_stage
[Stage
][Type
];
2507 NineDevice9_SetTextureStageState( struct NineDevice9
*This
,
2509 D3DTEXTURESTAGESTATETYPE Type
,
2512 struct nine_state
*state
= This
->update
;
2514 DBG("Stage=%u Type=%u Value=%08x\n", Stage
, Type
, Value
);
2515 nine_dump_D3DTSS_value(DBG_FF
, Type
, Value
);
2517 user_assert(Stage
< ARRAY_SIZE(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2518 user_assert(Type
< ARRAY_SIZE(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2520 state
->ff
.tex_stage
[Stage
][Type
] = Value
;
2522 if (unlikely(This
->is_recording
)) {
2523 if (Type
== D3DTSS_TEXTURETRANSFORMFLAGS
)
2524 state
->changed
.group
|= NINE_STATE_PS1X_SHADER
;
2525 state
->changed
.group
|= NINE_STATE_FF_PSSTAGES
;
2526 state
->ff
.changed
.tex_stage
[Stage
][Type
/ 32] |= 1 << (Type
% 32);
2528 nine_context_set_texture_stage_state(This
, Stage
, Type
, Value
);
2534 NineDevice9_GetSamplerState( struct NineDevice9
*This
,
2536 D3DSAMPLERSTATETYPE Type
,
2539 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2540 Sampler
== D3DDMAPSAMPLER
||
2541 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2542 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2544 if (Sampler
>= D3DDMAPSAMPLER
)
2545 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2547 *pValue
= This
->state
.samp_advertised
[Sampler
][Type
];
2552 NineDevice9_SetSamplerState( struct NineDevice9
*This
,
2554 D3DSAMPLERSTATETYPE Type
,
2557 struct nine_state
*state
= This
->update
;
2559 DBG("This=%p Sampler=%u Type=%s Value=%08x\n", This
,
2560 Sampler
, nine_D3DSAMP_to_str(Type
), Value
);
2562 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2563 Sampler
== D3DDMAPSAMPLER
||
2564 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2565 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2567 if (Sampler
>= D3DDMAPSAMPLER
)
2568 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2570 if (unlikely(This
->is_recording
)) {
2571 state
->samp_advertised
[Sampler
][Type
] = Value
;
2572 state
->changed
.group
|= NINE_STATE_SAMPLER
;
2573 state
->changed
.sampler
[Sampler
] |= 1 << Type
;
2577 if (state
->samp_advertised
[Sampler
][Type
] == Value
)
2580 state
->samp_advertised
[Sampler
][Type
] = Value
;
2581 nine_context_set_sampler_state(This
, Sampler
, Type
, Value
);
2587 NineDevice9_ValidateDevice( struct NineDevice9
*This
,
2590 const struct nine_state
*state
= &This
->state
;
2592 unsigned w
= 0, h
= 0;
2594 DBG("This=%p pNumPasses=%p\n", This
, pNumPasses
);
2596 for (i
= 0; i
< ARRAY_SIZE(state
->samp_advertised
); ++i
) {
2597 if (state
->samp_advertised
[i
][D3DSAMP_MINFILTER
] == D3DTEXF_NONE
||
2598 state
->samp_advertised
[i
][D3DSAMP_MAGFILTER
] == D3DTEXF_NONE
)
2599 return D3DERR_UNSUPPORTEDTEXTUREFILTER
;
2602 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2606 w
= state
->rt
[i
]->desc
.Width
;
2607 h
= state
->rt
[i
]->desc
.Height
;
2609 if (state
->rt
[i
]->desc
.Width
!= w
|| state
->rt
[i
]->desc
.Height
!= h
) {
2610 return D3DERR_CONFLICTINGRENDERSTATE
;
2614 (state
->rs_advertised
[D3DRS_ZENABLE
] || state
->rs_advertised
[D3DRS_STENCILENABLE
])) {
2616 (state
->ds
->desc
.Width
!= w
|| state
->ds
->desc
.Height
!= h
))
2617 return D3DERR_CONFLICTINGRENDERSTATE
;
2627 NineDevice9_SetPaletteEntries( struct NineDevice9
*This
,
2629 const PALETTEENTRY
*pEntries
)
2631 STUB(D3D_OK
); /* like wine */
2635 NineDevice9_GetPaletteEntries( struct NineDevice9
*This
,
2637 PALETTEENTRY
*pEntries
)
2639 STUB(D3DERR_INVALIDCALL
);
2643 NineDevice9_SetCurrentTexturePalette( struct NineDevice9
*This
,
2644 UINT PaletteNumber
)
2646 STUB(D3D_OK
); /* like wine */
2650 NineDevice9_GetCurrentTexturePalette( struct NineDevice9
*This
,
2651 UINT
*PaletteNumber
)
2653 STUB(D3DERR_INVALIDCALL
);
2657 NineDevice9_SetScissorRect( struct NineDevice9
*This
,
2660 struct nine_state
*state
= This
->update
;
2662 DBG("x=(%u..%u) y=(%u..%u)\n",
2663 pRect
->left
, pRect
->top
, pRect
->right
, pRect
->bottom
);
2665 state
->scissor
.minx
= pRect
->left
;
2666 state
->scissor
.miny
= pRect
->top
;
2667 state
->scissor
.maxx
= pRect
->right
;
2668 state
->scissor
.maxy
= pRect
->bottom
;
2670 if (unlikely(This
->is_recording
))
2671 state
->changed
.group
|= NINE_STATE_SCISSOR
;
2673 nine_context_set_scissor(This
, &state
->scissor
);
2679 NineDevice9_GetScissorRect( struct NineDevice9
*This
,
2682 pRect
->left
= This
->state
.scissor
.minx
;
2683 pRect
->top
= This
->state
.scissor
.miny
;
2684 pRect
->right
= This
->state
.scissor
.maxx
;
2685 pRect
->bottom
= This
->state
.scissor
.maxy
;
2691 NineDevice9_SetSoftwareVertexProcessing( struct NineDevice9
*This
,
2694 if (This
->params
.BehaviorFlags
& D3DCREATE_MIXED_VERTEXPROCESSING
) {
2695 This
->swvp
= bSoftware
;
2696 nine_context_set_swvp(This
, bSoftware
);
2699 return D3DERR_INVALIDCALL
; /* msdn. TODO: check in practice */
2703 NineDevice9_GetSoftwareVertexProcessing( struct NineDevice9
*This
)
2709 NineDevice9_SetNPatchMode( struct NineDevice9
*This
,
2712 return D3D_OK
; /* Nothing to do because we don't advertise NPatch support */
2716 NineDevice9_GetNPatchMode( struct NineDevice9
*This
)
2721 /* TODO: only go through dirty textures */
2723 validate_textures(struct NineDevice9
*device
)
2725 struct NineBaseTexture9
*tex
, *ptr
;
2726 LIST_FOR_EACH_ENTRY_SAFE(tex
, ptr
, &device
->update_textures
, list
) {
2727 list_delinit(&tex
->list
);
2728 NineBaseTexture9_Validate(tex
);
2733 update_managed_buffers(struct NineDevice9
*device
)
2735 struct NineBuffer9
*buf
, *ptr
;
2736 LIST_FOR_EACH_ENTRY_SAFE(buf
, ptr
, &device
->update_buffers
, managed
.list
) {
2737 list_delinit(&buf
->managed
.list
);
2738 NineBuffer9_Upload(buf
);
2743 NineBeforeDraw( struct NineDevice9
*This
)
2745 /* Upload Managed dirty content */
2746 validate_textures(This
); /* may clobber state */
2747 update_managed_buffers(This
);
2751 NineAfterDraw( struct NineDevice9
*This
)
2754 struct nine_state
*state
= &This
->state
;
2755 unsigned ps_mask
= state
->ps
? state
->ps
->rt_mask
: 1;
2757 /* Flag render-targets with autogenmipmap for mipmap regeneration */
2758 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2759 struct NineSurface9
*rt
= state
->rt
[i
];
2761 if (rt
&& rt
->desc
.Format
!= D3DFMT_NULL
&& (ps_mask
& (1 << i
)) &&
2762 rt
->desc
.Usage
& D3DUSAGE_AUTOGENMIPMAP
) {
2763 assert(rt
->texture
== D3DRTYPE_TEXTURE
||
2764 rt
->texture
== D3DRTYPE_CUBETEXTURE
);
2765 NineBaseTexture9(rt
->base
.base
.container
)->dirty_mip
= TRUE
;
2771 NineDevice9_DrawPrimitive( struct NineDevice9
*This
,
2772 D3DPRIMITIVETYPE PrimitiveType
,
2774 UINT PrimitiveCount
)
2776 DBG("iface %p, PrimitiveType %u, StartVertex %u, PrimitiveCount %u\n",
2777 This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2779 NineBeforeDraw(This
);
2780 nine_context_draw_primitive(This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2781 NineAfterDraw(This
);
2787 NineDevice9_DrawIndexedPrimitive( struct NineDevice9
*This
,
2788 D3DPRIMITIVETYPE PrimitiveType
,
2789 INT BaseVertexIndex
,
2790 UINT MinVertexIndex
,
2793 UINT PrimitiveCount
)
2795 DBG("iface %p, PrimitiveType %u, BaseVertexIndex %u, MinVertexIndex %u "
2796 "NumVertices %u, StartIndex %u, PrimitiveCount %u\n",
2797 This
, PrimitiveType
, BaseVertexIndex
, MinVertexIndex
, NumVertices
,
2798 StartIndex
, PrimitiveCount
);
2800 user_assert(This
->state
.idxbuf
, D3DERR_INVALIDCALL
);
2801 user_assert(This
->state
.vdecl
, D3DERR_INVALIDCALL
);
2803 NineBeforeDraw(This
);
2804 nine_context_draw_indexed_primitive(This
, PrimitiveType
, BaseVertexIndex
,
2805 MinVertexIndex
, NumVertices
, StartIndex
,
2807 NineAfterDraw(This
);
2813 NineDevice9_DrawPrimitiveUP( struct NineDevice9
*This
,
2814 D3DPRIMITIVETYPE PrimitiveType
,
2815 UINT PrimitiveCount
,
2816 const void *pVertexStreamZeroData
,
2817 UINT VertexStreamZeroStride
)
2819 struct pipe_vertex_buffer vtxbuf
;
2821 DBG("iface %p, PrimitiveType %u, PrimitiveCount %u, data %p, stride %u\n",
2822 This
, PrimitiveType
, PrimitiveCount
,
2823 pVertexStreamZeroData
, VertexStreamZeroStride
);
2825 user_assert(pVertexStreamZeroData
&& VertexStreamZeroStride
,
2826 D3DERR_INVALIDCALL
);
2827 user_assert(PrimitiveCount
, D3D_OK
);
2829 vtxbuf
.stride
= VertexStreamZeroStride
;
2830 vtxbuf
.buffer_offset
= 0;
2831 vtxbuf
.buffer
= NULL
;
2832 vtxbuf
.user_buffer
= pVertexStreamZeroData
;
2834 if (!This
->driver_caps
.user_vbufs
) {
2835 /* Implicit use of context pipe */
2836 (void)NineDevice9_GetPipe(This
);
2837 u_upload_data(This
->vertex_uploader
,
2839 (prim_count_to_vertex_count(PrimitiveType
, PrimitiveCount
)) * VertexStreamZeroStride
, /* XXX */
2842 &vtxbuf
.buffer_offset
,
2844 u_upload_unmap(This
->vertex_uploader
);
2845 vtxbuf
.user_buffer
= NULL
;
2848 NineBeforeDraw(This
);
2849 nine_context_draw_primitive_from_vtxbuf(This
, PrimitiveType
, PrimitiveCount
, &vtxbuf
);
2850 NineAfterDraw(This
);
2852 pipe_resource_reference(&vtxbuf
.buffer
, NULL
);
2854 NineDevice9_PauseRecording(This
);
2855 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
2856 NineDevice9_ResumeRecording(This
);
2862 NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9
*This
,
2863 D3DPRIMITIVETYPE PrimitiveType
,
2864 UINT MinVertexIndex
,
2866 UINT PrimitiveCount
,
2867 const void *pIndexData
,
2868 D3DFORMAT IndexDataFormat
,
2869 const void *pVertexStreamZeroData
,
2870 UINT VertexStreamZeroStride
)
2872 struct pipe_vertex_buffer vbuf
;
2873 struct pipe_index_buffer ibuf
;
2875 DBG("iface %p, PrimitiveType %u, MinVertexIndex %u, NumVertices %u "
2876 "PrimitiveCount %u, pIndexData %p, IndexDataFormat %u "
2877 "pVertexStreamZeroData %p, VertexStreamZeroStride %u\n",
2878 This
, PrimitiveType
, MinVertexIndex
, NumVertices
, PrimitiveCount
,
2879 pIndexData
, IndexDataFormat
,
2880 pVertexStreamZeroData
, VertexStreamZeroStride
);
2882 user_assert(pIndexData
&& pVertexStreamZeroData
, D3DERR_INVALIDCALL
);
2883 user_assert(VertexStreamZeroStride
, D3DERR_INVALIDCALL
);
2884 user_assert(IndexDataFormat
== D3DFMT_INDEX16
||
2885 IndexDataFormat
== D3DFMT_INDEX32
, D3DERR_INVALIDCALL
);
2886 user_assert(PrimitiveCount
, D3D_OK
);
2888 vbuf
.stride
= VertexStreamZeroStride
;
2889 vbuf
.buffer_offset
= 0;
2891 vbuf
.user_buffer
= pVertexStreamZeroData
;
2893 ibuf
.index_size
= (IndexDataFormat
== D3DFMT_INDEX16
) ? 2 : 4;
2896 ibuf
.user_buffer
= pIndexData
;
2898 if (!This
->driver_caps
.user_vbufs
) {
2899 const unsigned base
= MinVertexIndex
* VertexStreamZeroStride
;
2900 /* Implicit use of context pipe */
2901 (void)NineDevice9_GetPipe(This
);
2902 u_upload_data(This
->vertex_uploader
,
2904 NumVertices
* VertexStreamZeroStride
, /* XXX */
2906 (const uint8_t *)vbuf
.user_buffer
+ base
,
2907 &vbuf
.buffer_offset
,
2909 u_upload_unmap(This
->vertex_uploader
);
2910 /* Won't be used: */
2911 vbuf
.buffer_offset
-= base
;
2912 vbuf
.user_buffer
= NULL
;
2914 if (!This
->driver_caps
.user_ibufs
) {
2915 /* Implicit use of context pipe */
2916 (void)NineDevice9_GetPipe(This
);
2917 u_upload_data(This
->index_uploader
,
2919 (prim_count_to_vertex_count(PrimitiveType
, PrimitiveCount
)) * ibuf
.index_size
,
2924 u_upload_unmap(This
->index_uploader
);
2925 ibuf
.user_buffer
= NULL
;
2928 NineBeforeDraw(This
);
2929 nine_context_draw_indexed_primitive_from_vtxbuf_idxbuf(This
, PrimitiveType
,
2935 NineAfterDraw(This
);
2937 pipe_resource_reference(&vbuf
.buffer
, NULL
);
2938 pipe_resource_reference(&ibuf
.buffer
, NULL
);
2940 NineDevice9_PauseRecording(This
);
2941 NineDevice9_SetIndices(This
, NULL
);
2942 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
2943 NineDevice9_ResumeRecording(This
);
2949 NineDevice9_ProcessVertices( struct NineDevice9
*This
,
2953 IDirect3DVertexBuffer9
*pDestBuffer
,
2954 IDirect3DVertexDeclaration9
*pVertexDecl
,
2957 struct pipe_screen
*screen_sw
= This
->screen_sw
;
2958 struct pipe_context
*pipe_sw
= This
->pipe_sw
;
2959 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pVertexDecl
);
2960 struct NineVertexBuffer9
*dst
= NineVertexBuffer9(pDestBuffer
);
2961 struct NineVertexShader9
*vs
;
2962 struct pipe_resource
*resource
;
2963 struct pipe_transfer
*transfer
= NULL
;
2964 struct pipe_stream_output_info so
;
2965 struct pipe_stream_output_target
*target
;
2966 struct pipe_draw_info draw
;
2967 struct pipe_box box
;
2968 bool programmable_vs
= This
->state
.vs
&& !(This
->state
.vdecl
&& This
->state
.vdecl
->position_t
);
2969 unsigned offsets
[1] = {0};
2971 unsigned buffer_size
;
2974 DBG("This=%p SrcStartIndex=%u DestIndex=%u VertexCount=%u "
2975 "pDestBuffer=%p pVertexDecl=%p Flags=%d\n",
2976 This
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
,
2977 pVertexDecl
, Flags
);
2979 if (!screen_sw
->get_param(screen_sw
, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
)) {
2980 DBG("ProcessVertices not supported\n");
2981 return D3DERR_INVALIDCALL
;
2985 vs
= programmable_vs
? This
->state
.vs
: This
->ff
.vs
;
2986 /* Note: version is 0 for ff */
2987 user_assert(vdecl
|| (vs
->byte_code
.version
< 0x30 && dst
->desc
.FVF
),
2988 D3DERR_INVALIDCALL
);
2990 DWORD FVF
= dst
->desc
.FVF
;
2991 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
2993 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
2997 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
2998 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
3002 /* Flags: Can be 0 or D3DPV_DONOTCOPYDATA, and/or lock flags
3003 * D3DPV_DONOTCOPYDATA -> Has effect only for ff. In particular
3004 * if not set, everything from src will be used, and dst
3005 * must match exactly the ff vs outputs.
3006 * TODO: Handle all the checks, etc for ff */
3007 user_assert(vdecl
->position_t
|| programmable_vs
,
3008 D3DERR_INVALIDCALL
);
3010 /* TODO: Support vs < 3 and ff */
3011 user_assert(vs
->byte_code
.version
== 0x30,
3012 D3DERR_INVALIDCALL
);
3013 /* TODO: Not hardcode the constant buffers for swvp */
3014 user_assert(This
->may_swvp
,
3015 D3DERR_INVALIDCALL
);
3017 nine_state_prepare_draw_sw(This
, vdecl
, SrcStartIndex
, VertexCount
, &so
);
3019 buffer_size
= VertexCount
* so
.stride
[0] * 4;
3021 struct pipe_resource templ
;
3023 memset(&templ
, 0, sizeof(templ
));
3024 templ
.target
= PIPE_BUFFER
;
3025 templ
.format
= PIPE_FORMAT_R8_UNORM
;
3026 templ
.width0
= buffer_size
;
3028 templ
.bind
= PIPE_BIND_STREAM_OUTPUT
;
3029 templ
.usage
= PIPE_USAGE_STREAM
;
3030 templ
.height0
= templ
.depth0
= templ
.array_size
= 1;
3031 templ
.last_level
= templ
.nr_samples
= 0;
3033 resource
= screen_sw
->resource_create(screen_sw
, &templ
);
3035 return E_OUTOFMEMORY
;
3037 target
= pipe_sw
->create_stream_output_target(pipe_sw
, resource
,
3040 pipe_resource_reference(&resource
, NULL
);
3041 return D3DERR_DRIVERINTERNALERROR
;
3044 draw
.mode
= PIPE_PRIM_POINTS
;
3045 draw
.count
= VertexCount
;
3046 draw
.start_instance
= 0;
3047 draw
.primitive_restart
= FALSE
;
3048 draw
.restart_index
= 0;
3049 draw
.count_from_stream_output
= NULL
;
3050 draw
.indirect
= NULL
;
3051 draw
.indirect_params
= NULL
;
3052 draw
.instance_count
= 1;
3053 draw
.indexed
= FALSE
;
3055 draw
.index_bias
= 0;
3057 draw
.max_index
= VertexCount
- 1;
3060 pipe_sw
->set_stream_output_targets(pipe_sw
, 1, &target
, offsets
);
3062 pipe_sw
->draw_vbo(pipe_sw
, &draw
);
3064 pipe_sw
->set_stream_output_targets(pipe_sw
, 0, NULL
, 0);
3065 pipe_sw
->stream_output_target_destroy(pipe_sw
, target
);
3067 u_box_1d(0, VertexCount
* so
.stride
[0] * 4, &box
);
3068 map
= pipe_sw
->transfer_map(pipe_sw
, resource
, 0, PIPE_TRANSFER_READ
, &box
,
3071 hr
= D3DERR_DRIVERINTERNALERROR
;
3075 hr
= NineVertexDeclaration9_ConvertStreamOutput(vdecl
,
3076 dst
, DestIndex
, VertexCount
,
3079 pipe_sw
->transfer_unmap(pipe_sw
, transfer
);
3082 nine_state_after_draw_sw(This
);
3083 pipe_resource_reference(&resource
, NULL
);
3088 NineDevice9_CreateVertexDeclaration( struct NineDevice9
*This
,
3089 const D3DVERTEXELEMENT9
*pVertexElements
,
3090 IDirect3DVertexDeclaration9
**ppDecl
)
3092 struct NineVertexDeclaration9
*vdecl
;
3094 DBG("This=%p pVertexElements=%p ppDecl=%p\n",
3095 This
, pVertexElements
, ppDecl
);
3097 HRESULT hr
= NineVertexDeclaration9_new(This
, pVertexElements
, &vdecl
);
3099 *ppDecl
= (IDirect3DVertexDeclaration9
*)vdecl
;
3105 NineDevice9_SetVertexDeclaration( struct NineDevice9
*This
,
3106 IDirect3DVertexDeclaration9
*pDecl
)
3108 struct nine_state
*state
= This
->update
;
3109 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pDecl
);
3111 DBG("This=%p pDecl=%p\n", This
, pDecl
);
3113 if (unlikely(This
->is_recording
)) {
3114 nine_bind(&state
->vdecl
, vdecl
);
3115 state
->changed
.group
|= NINE_STATE_VDECL
;
3119 if (state
->vdecl
== vdecl
)
3122 nine_bind(&state
->vdecl
, vdecl
);
3124 nine_context_set_vertex_declaration(This
, vdecl
);
3130 NineDevice9_GetVertexDeclaration( struct NineDevice9
*This
,
3131 IDirect3DVertexDeclaration9
**ppDecl
)
3133 user_assert(ppDecl
, D3DERR_INVALIDCALL
);
3135 *ppDecl
= (IDirect3DVertexDeclaration9
*)This
->state
.vdecl
;
3137 NineUnknown_AddRef(NineUnknown(*ppDecl
));
3142 NineDevice9_SetFVF( struct NineDevice9
*This
,
3145 struct NineVertexDeclaration9
*vdecl
;
3148 DBG("FVF = %08x\n", FVF
);
3150 return D3D_OK
; /* like wine */
3152 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
3154 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
3158 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
3159 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
3161 return NineDevice9_SetVertexDeclaration(
3162 This
, (IDirect3DVertexDeclaration9
*)vdecl
);
3166 NineDevice9_GetFVF( struct NineDevice9
*This
,
3169 *pFVF
= This
->state
.vdecl
? This
->state
.vdecl
->fvf
: 0;
3174 NineDevice9_CreateVertexShader( struct NineDevice9
*This
,
3175 const DWORD
*pFunction
,
3176 IDirect3DVertexShader9
**ppShader
)
3178 struct NineVertexShader9
*vs
;
3181 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3183 hr
= NineVertexShader9_new(This
, &vs
, pFunction
, NULL
);
3186 *ppShader
= (IDirect3DVertexShader9
*)vs
;
3191 NineDevice9_SetVertexShader( struct NineDevice9
*This
,
3192 IDirect3DVertexShader9
*pShader
)
3194 struct nine_state
*state
= This
->update
;
3195 struct NineVertexShader9
*vs_shader
= (struct NineVertexShader9
*)pShader
;
3197 DBG("This=%p pShader=%p\n", This
, pShader
);
3199 if (unlikely(This
->is_recording
)) {
3200 nine_bind(&state
->vs
, vs_shader
);
3201 state
->changed
.group
|= NINE_STATE_VS
;
3205 if (state
->vs
== vs_shader
)
3208 nine_bind(&state
->vs
, vs_shader
);
3210 nine_context_set_vertex_shader(This
, vs_shader
);
3216 NineDevice9_GetVertexShader( struct NineDevice9
*This
,
3217 IDirect3DVertexShader9
**ppShader
)
3219 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3220 nine_reference_set(ppShader
, This
->state
.vs
);
3225 NineDevice9_SetVertexShaderConstantF( struct NineDevice9
*This
,
3227 const float *pConstantData
,
3228 UINT Vector4fCount
)
3230 struct nine_state
*state
= This
->update
;
3231 float *vs_const_f
= state
->vs_const_f
;
3233 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3234 This
, StartRegister
, pConstantData
, Vector4fCount
);
3236 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3237 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3241 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3243 if (unlikely(This
->is_recording
)) {
3244 memcpy(&vs_const_f
[StartRegister
* 4],
3246 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3248 nine_ranges_insert(&state
->changed
.vs_const_f
,
3249 StartRegister
, StartRegister
+ Vector4fCount
,
3252 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3257 if (!memcmp(&vs_const_f
[StartRegister
* 4], pConstantData
,
3258 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0])))
3261 memcpy(&vs_const_f
[StartRegister
* 4],
3263 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3265 nine_context_set_vertex_shader_constant_f(This
, StartRegister
, pConstantData
,
3266 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]),
3273 NineDevice9_GetVertexShaderConstantF( struct NineDevice9
*This
,
3275 float *pConstantData
,
3276 UINT Vector4fCount
)
3278 const struct nine_state
*state
= &This
->state
;
3280 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3281 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3282 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3284 memcpy(pConstantData
,
3285 &state
->vs_const_f
[StartRegister
* 4],
3286 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3292 NineDevice9_SetVertexShaderConstantI( struct NineDevice9
*This
,
3294 const int *pConstantData
,
3295 UINT Vector4iCount
)
3297 struct nine_state
*state
= This
->update
;
3300 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3301 This
, StartRegister
, pConstantData
, Vector4iCount
);
3303 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3304 D3DERR_INVALIDCALL
);
3305 user_assert(StartRegister
+ Vector4iCount
<= (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3306 D3DERR_INVALIDCALL
);
3307 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3309 if (This
->driver_caps
.vs_integer
) {
3310 if (!This
->is_recording
) {
3311 if (!memcmp(&state
->vs_const_i
[4 * StartRegister
], pConstantData
,
3312 Vector4iCount
* sizeof(int[4])))
3315 memcpy(&state
->vs_const_i
[4 * StartRegister
],
3317 Vector4iCount
* sizeof(int[4]));
3319 for (i
= 0; i
< Vector4iCount
; i
++) {
3320 state
->vs_const_i
[4 * (StartRegister
+ i
)] = fui((float)(pConstantData
[4 * i
]));
3321 state
->vs_const_i
[4 * (StartRegister
+ i
) + 1] = fui((float)(pConstantData
[4 * i
+ 1]));
3322 state
->vs_const_i
[4 * (StartRegister
+ i
) + 2] = fui((float)(pConstantData
[4 * i
+ 2]));
3323 state
->vs_const_i
[4 * (StartRegister
+ i
) + 3] = fui((float)(pConstantData
[4 * i
+ 3]));
3327 if (unlikely(This
->is_recording
)) {
3328 nine_ranges_insert(&state
->changed
.vs_const_i
,
3329 StartRegister
, StartRegister
+ Vector4iCount
,
3331 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3333 nine_context_set_vertex_shader_constant_i(This
, StartRegister
, pConstantData
,
3334 Vector4iCount
* sizeof(int[4]), Vector4iCount
);
3340 NineDevice9_GetVertexShaderConstantI( struct NineDevice9
*This
,
3343 UINT Vector4iCount
)
3345 const struct nine_state
*state
= &This
->state
;
3348 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3349 D3DERR_INVALIDCALL
);
3350 user_assert(StartRegister
+ Vector4iCount
<= (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3351 D3DERR_INVALIDCALL
);
3352 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3354 if (This
->driver_caps
.vs_integer
) {
3355 memcpy(pConstantData
,
3356 &state
->vs_const_i
[4 * StartRegister
],
3357 Vector4iCount
* sizeof(int[4]));
3359 for (i
= 0; i
< Vector4iCount
; i
++) {
3360 pConstantData
[4 * i
] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
)]);
3361 pConstantData
[4 * i
+ 1] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
) + 1]);
3362 pConstantData
[4 * i
+ 2] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
) + 2]);
3363 pConstantData
[4 * i
+ 3] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
) + 3]);
3371 NineDevice9_SetVertexShaderConstantB( struct NineDevice9
*This
,
3373 const BOOL
*pConstantData
,
3376 struct nine_state
*state
= This
->update
;
3378 uint32_t bool_true
= This
->driver_caps
.vs_integer
? 0xFFFFFFFF : fui(1.0f
);
3380 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3381 This
, StartRegister
, pConstantData
, BoolCount
);
3383 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3384 D3DERR_INVALIDCALL
);
3385 user_assert(StartRegister
+ BoolCount
<= (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3386 D3DERR_INVALIDCALL
);
3387 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3389 if (!This
->is_recording
) {
3390 bool noChange
= true;
3391 for (i
= 0; i
< BoolCount
; i
++) {
3392 if (!!state
->vs_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3399 for (i
= 0; i
< BoolCount
; i
++)
3400 state
->vs_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3402 if (unlikely(This
->is_recording
)) {
3403 nine_ranges_insert(&state
->changed
.vs_const_b
,
3404 StartRegister
, StartRegister
+ BoolCount
,
3406 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3408 nine_context_set_vertex_shader_constant_b(This
, StartRegister
, pConstantData
,
3409 sizeof(BOOL
) * BoolCount
, BoolCount
);
3415 NineDevice9_GetVertexShaderConstantB( struct NineDevice9
*This
,
3417 BOOL
*pConstantData
,
3420 const struct nine_state
*state
= &This
->state
;
3423 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3424 D3DERR_INVALIDCALL
);
3425 user_assert(StartRegister
+ BoolCount
<= (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3426 D3DERR_INVALIDCALL
);
3427 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3429 for (i
= 0; i
< BoolCount
; i
++)
3430 pConstantData
[i
] = state
->vs_const_b
[StartRegister
+ i
] != 0 ? TRUE
: FALSE
;
3436 NineDevice9_SetStreamSource( struct NineDevice9
*This
,
3438 IDirect3DVertexBuffer9
*pStreamData
,
3442 struct nine_state
*state
= This
->update
;
3443 struct NineVertexBuffer9
*pVBuf9
= NineVertexBuffer9(pStreamData
);
3444 const unsigned i
= StreamNumber
;
3446 DBG("This=%p StreamNumber=%u pStreamData=%p OffsetInBytes=%u Stride=%u\n",
3447 This
, StreamNumber
, pStreamData
, OffsetInBytes
, Stride
);
3449 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3450 user_assert(Stride
<= This
->caps
.MaxStreamStride
, D3DERR_INVALIDCALL
);
3452 if (unlikely(This
->is_recording
)) {
3453 nine_bind(&state
->stream
[i
], pStreamData
);
3454 state
->changed
.vtxbuf
|= 1 << StreamNumber
;
3455 state
->vtxbuf
[i
].stride
= Stride
;
3456 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3460 if (state
->stream
[i
] == NineVertexBuffer9(pStreamData
) &&
3461 state
->vtxbuf
[i
].stride
== Stride
&&
3462 state
->vtxbuf
[i
].buffer_offset
== OffsetInBytes
)
3465 state
->vtxbuf
[i
].stride
= Stride
;
3466 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3468 NineBindBufferToDevice(This
,
3469 (struct NineBuffer9
**)&state
->stream
[i
],
3470 (struct NineBuffer9
*)pVBuf9
);
3472 nine_context_set_stream_source(This
,
3482 NineDevice9_GetStreamSource( struct NineDevice9
*This
,
3484 IDirect3DVertexBuffer9
**ppStreamData
,
3485 UINT
*pOffsetInBytes
,
3488 const struct nine_state
*state
= &This
->state
;
3489 const unsigned i
= StreamNumber
;
3491 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3492 user_assert(ppStreamData
, D3DERR_INVALIDCALL
);
3494 nine_reference_set(ppStreamData
, state
->stream
[i
]);
3495 *pStride
= state
->vtxbuf
[i
].stride
;
3496 *pOffsetInBytes
= state
->vtxbuf
[i
].buffer_offset
;
3502 NineDevice9_SetStreamSourceFreq( struct NineDevice9
*This
,
3506 struct nine_state
*state
= This
->update
;
3507 /* const UINT freq = Setting & 0x7FFFFF; */
3509 DBG("This=%p StreamNumber=%u FrequencyParameter=0x%x\n", This
,
3510 StreamNumber
, Setting
);
3512 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3513 user_assert(StreamNumber
!= 0 || !(Setting
& D3DSTREAMSOURCE_INSTANCEDATA
),
3514 D3DERR_INVALIDCALL
);
3515 user_assert(!((Setting
& D3DSTREAMSOURCE_INSTANCEDATA
) &&
3516 (Setting
& D3DSTREAMSOURCE_INDEXEDDATA
)), D3DERR_INVALIDCALL
);
3517 user_assert(Setting
, D3DERR_INVALIDCALL
);
3519 if (unlikely(This
->is_recording
)) {
3520 state
->stream_freq
[StreamNumber
] = Setting
;
3521 state
->changed
.stream_freq
|= 1 << StreamNumber
;
3522 if (StreamNumber
!= 0)
3523 state
->changed
.group
|= NINE_STATE_STREAMFREQ
;
3527 if (state
->stream_freq
[StreamNumber
] == Setting
)
3530 state
->stream_freq
[StreamNumber
] = Setting
;
3532 nine_context_set_stream_source_freq(This
, StreamNumber
, Setting
);
3537 NineDevice9_GetStreamSourceFreq( struct NineDevice9
*This
,
3541 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3542 *pSetting
= This
->state
.stream_freq
[StreamNumber
];
3547 NineDevice9_SetIndices( struct NineDevice9
*This
,
3548 IDirect3DIndexBuffer9
*pIndexData
)
3550 struct nine_state
*state
= This
->update
;
3551 struct NineIndexBuffer9
*idxbuf
= NineIndexBuffer9(pIndexData
);
3553 DBG("This=%p pIndexData=%p\n", This
, pIndexData
);
3555 if (unlikely(This
->is_recording
)) {
3556 nine_bind(&state
->idxbuf
, idxbuf
);
3557 state
->changed
.group
|= NINE_STATE_IDXBUF
;
3561 if (state
->idxbuf
== idxbuf
)
3564 NineBindBufferToDevice(This
,
3565 (struct NineBuffer9
**)&state
->idxbuf
,
3566 (struct NineBuffer9
*)idxbuf
);
3568 nine_context_set_indices(This
, idxbuf
);
3573 /* XXX: wine/d3d9 doesn't have pBaseVertexIndex, and it doesn't make sense
3574 * here because it's an argument passed to the Draw calls.
3577 NineDevice9_GetIndices( struct NineDevice9
*This
,
3578 IDirect3DIndexBuffer9
**ppIndexData
)
3580 user_assert(ppIndexData
, D3DERR_INVALIDCALL
);
3581 nine_reference_set(ppIndexData
, This
->state
.idxbuf
);
3586 NineDevice9_CreatePixelShader( struct NineDevice9
*This
,
3587 const DWORD
*pFunction
,
3588 IDirect3DPixelShader9
**ppShader
)
3590 struct NinePixelShader9
*ps
;
3593 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3595 hr
= NinePixelShader9_new(This
, &ps
, pFunction
, NULL
);
3598 *ppShader
= (IDirect3DPixelShader9
*)ps
;
3603 NineDevice9_SetPixelShader( struct NineDevice9
*This
,
3604 IDirect3DPixelShader9
*pShader
)
3606 struct nine_state
*state
= This
->update
;
3607 struct NinePixelShader9
*ps
= (struct NinePixelShader9
*)pShader
;
3609 DBG("This=%p pShader=%p\n", This
, pShader
);
3611 if (unlikely(This
->is_recording
)) {
3612 /* Technically we need NINE_STATE_FB only
3613 * if the ps mask changes, but put it always
3615 nine_bind(&state
->ps
, pShader
);
3616 state
->changed
.group
|= NINE_STATE_PS
| NINE_STATE_FB
;
3620 if (state
->ps
== ps
)
3623 nine_bind(&state
->ps
, ps
);
3625 nine_context_set_pixel_shader(This
, ps
);
3631 NineDevice9_GetPixelShader( struct NineDevice9
*This
,
3632 IDirect3DPixelShader9
**ppShader
)
3634 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3635 nine_reference_set(ppShader
, This
->state
.ps
);
3640 NineDevice9_SetPixelShaderConstantF( struct NineDevice9
*This
,
3642 const float *pConstantData
,
3643 UINT Vector4fCount
)
3645 struct nine_state
*state
= This
->update
;
3647 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3648 This
, StartRegister
, pConstantData
, Vector4fCount
);
3650 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3651 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3655 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3657 if (unlikely(This
->is_recording
)) {
3658 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3660 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3662 nine_ranges_insert(&state
->changed
.ps_const_f
,
3663 StartRegister
, StartRegister
+ Vector4fCount
,
3666 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3670 if (!memcmp(&state
->ps_const_f
[StartRegister
* 4], pConstantData
,
3671 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0])))
3674 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3676 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3678 nine_context_set_pixel_shader_constant_f(This
, StartRegister
, pConstantData
,
3679 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]),
3686 NineDevice9_GetPixelShaderConstantF( struct NineDevice9
*This
,
3688 float *pConstantData
,
3689 UINT Vector4fCount
)
3691 const struct nine_state
*state
= &This
->state
;
3693 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3694 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3695 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3697 memcpy(pConstantData
,
3698 &state
->ps_const_f
[StartRegister
* 4],
3699 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3705 NineDevice9_SetPixelShaderConstantI( struct NineDevice9
*This
,
3707 const int *pConstantData
,
3708 UINT Vector4iCount
)
3710 struct nine_state
*state
= This
->update
;
3713 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3714 This
, StartRegister
, pConstantData
, Vector4iCount
);
3716 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3717 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3718 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3720 if (This
->driver_caps
.ps_integer
) {
3721 if (!This
->is_recording
) {
3722 if (!memcmp(&state
->ps_const_i
[StartRegister
][0], pConstantData
,
3723 Vector4iCount
* sizeof(state
->ps_const_i
[0])))
3726 memcpy(&state
->ps_const_i
[StartRegister
][0],
3728 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3730 for (i
= 0; i
< Vector4iCount
; i
++) {
3731 state
->ps_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3732 state
->ps_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3733 state
->ps_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3734 state
->ps_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3738 if (unlikely(This
->is_recording
)) {
3739 state
->changed
.ps_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3740 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3742 nine_context_set_pixel_shader_constant_i(This
, StartRegister
, pConstantData
,
3743 sizeof(state
->ps_const_i
[0]) * Vector4iCount
, Vector4iCount
);
3749 NineDevice9_GetPixelShaderConstantI( struct NineDevice9
*This
,
3752 UINT Vector4iCount
)
3754 const struct nine_state
*state
= &This
->state
;
3757 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3758 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3759 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3761 if (This
->driver_caps
.ps_integer
) {
3762 memcpy(pConstantData
,
3763 &state
->ps_const_i
[StartRegister
][0],
3764 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3766 for (i
= 0; i
< Vector4iCount
; i
++) {
3767 pConstantData
[4*i
] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][0]);
3768 pConstantData
[4*i
+1] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][1]);
3769 pConstantData
[4*i
+2] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][2]);
3770 pConstantData
[4*i
+3] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][3]);
3778 NineDevice9_SetPixelShaderConstantB( struct NineDevice9
*This
,
3780 const BOOL
*pConstantData
,
3783 struct nine_state
*state
= This
->update
;
3785 uint32_t bool_true
= This
->driver_caps
.ps_integer
? 0xFFFFFFFF : fui(1.0f
);
3787 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3788 This
, StartRegister
, pConstantData
, BoolCount
);
3790 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3791 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3792 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3794 if (!This
->is_recording
) {
3795 bool noChange
= true;
3796 for (i
= 0; i
< BoolCount
; i
++) {
3797 if (!!state
->ps_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3804 for (i
= 0; i
< BoolCount
; i
++)
3805 state
->ps_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3807 if (unlikely(This
->is_recording
)) {
3808 state
->changed
.ps_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3809 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3811 nine_context_set_pixel_shader_constant_b(This
, StartRegister
, pConstantData
,
3812 sizeof(BOOL
) * BoolCount
, BoolCount
);
3818 NineDevice9_GetPixelShaderConstantB( struct NineDevice9
*This
,
3820 BOOL
*pConstantData
,
3823 const struct nine_state
*state
= &This
->state
;
3826 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3827 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3828 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3830 for (i
= 0; i
< BoolCount
; i
++)
3831 pConstantData
[i
] = state
->ps_const_b
[StartRegister
+ i
] ? TRUE
: FALSE
;
3837 NineDevice9_DrawRectPatch( struct NineDevice9
*This
,
3839 const float *pNumSegs
,
3840 const D3DRECTPATCH_INFO
*pRectPatchInfo
)
3842 STUB(D3DERR_INVALIDCALL
);
3846 NineDevice9_DrawTriPatch( struct NineDevice9
*This
,
3848 const float *pNumSegs
,
3849 const D3DTRIPATCH_INFO
*pTriPatchInfo
)
3851 STUB(D3DERR_INVALIDCALL
);
3855 NineDevice9_DeletePatch( struct NineDevice9
*This
,
3858 STUB(D3DERR_INVALIDCALL
);
3862 NineDevice9_CreateQuery( struct NineDevice9
*This
,
3864 IDirect3DQuery9
**ppQuery
)
3866 struct NineQuery9
*query
;
3869 DBG("This=%p Type=%d ppQuery=%p\n", This
, Type
, ppQuery
);
3871 hr
= nine_is_query_supported(This
->screen
, Type
);
3872 if (!ppQuery
|| hr
!= D3D_OK
)
3875 hr
= NineQuery9_new(This
, &query
, Type
);
3878 *ppQuery
= (IDirect3DQuery9
*)query
;
3882 IDirect3DDevice9Vtbl NineDevice9_vtable
= {
3883 (void *)NineUnknown_QueryInterface
,
3884 (void *)NineUnknown_AddRef
,
3885 (void *)NineUnknown_Release
,
3886 (void *)NineDevice9_TestCooperativeLevel
,
3887 (void *)NineDevice9_GetAvailableTextureMem
,
3888 (void *)NineDevice9_EvictManagedResources
,
3889 (void *)NineDevice9_GetDirect3D
,
3890 (void *)NineDevice9_GetDeviceCaps
,
3891 (void *)NineDevice9_GetDisplayMode
,
3892 (void *)NineDevice9_GetCreationParameters
,
3893 (void *)NineDevice9_SetCursorProperties
,
3894 (void *)NineDevice9_SetCursorPosition
,
3895 (void *)NineDevice9_ShowCursor
,
3896 (void *)NineDevice9_CreateAdditionalSwapChain
,
3897 (void *)NineDevice9_GetSwapChain
,
3898 (void *)NineDevice9_GetNumberOfSwapChains
,
3899 (void *)NineDevice9_Reset
,
3900 (void *)NineDevice9_Present
,
3901 (void *)NineDevice9_GetBackBuffer
,
3902 (void *)NineDevice9_GetRasterStatus
,
3903 (void *)NineDevice9_SetDialogBoxMode
,
3904 (void *)NineDevice9_SetGammaRamp
,
3905 (void *)NineDevice9_GetGammaRamp
,
3906 (void *)NineDevice9_CreateTexture
,
3907 (void *)NineDevice9_CreateVolumeTexture
,
3908 (void *)NineDevice9_CreateCubeTexture
,
3909 (void *)NineDevice9_CreateVertexBuffer
,
3910 (void *)NineDevice9_CreateIndexBuffer
,
3911 (void *)NineDevice9_CreateRenderTarget
,
3912 (void *)NineDevice9_CreateDepthStencilSurface
,
3913 (void *)NineDevice9_UpdateSurface
,
3914 (void *)NineDevice9_UpdateTexture
,
3915 (void *)NineDevice9_GetRenderTargetData
,
3916 (void *)NineDevice9_GetFrontBufferData
,
3917 (void *)NineDevice9_StretchRect
,
3918 (void *)NineDevice9_ColorFill
,
3919 (void *)NineDevice9_CreateOffscreenPlainSurface
,
3920 (void *)NineDevice9_SetRenderTarget
,
3921 (void *)NineDevice9_GetRenderTarget
,
3922 (void *)NineDevice9_SetDepthStencilSurface
,
3923 (void *)NineDevice9_GetDepthStencilSurface
,
3924 (void *)NineDevice9_BeginScene
,
3925 (void *)NineDevice9_EndScene
,
3926 (void *)NineDevice9_Clear
,
3927 (void *)NineDevice9_SetTransform
,
3928 (void *)NineDevice9_GetTransform
,
3929 (void *)NineDevice9_MultiplyTransform
,
3930 (void *)NineDevice9_SetViewport
,
3931 (void *)NineDevice9_GetViewport
,
3932 (void *)NineDevice9_SetMaterial
,
3933 (void *)NineDevice9_GetMaterial
,
3934 (void *)NineDevice9_SetLight
,
3935 (void *)NineDevice9_GetLight
,
3936 (void *)NineDevice9_LightEnable
,
3937 (void *)NineDevice9_GetLightEnable
,
3938 (void *)NineDevice9_SetClipPlane
,
3939 (void *)NineDevice9_GetClipPlane
,
3940 (void *)NineDevice9_SetRenderState
,
3941 (void *)NineDevice9_GetRenderState
,
3942 (void *)NineDevice9_CreateStateBlock
,
3943 (void *)NineDevice9_BeginStateBlock
,
3944 (void *)NineDevice9_EndStateBlock
,
3945 (void *)NineDevice9_SetClipStatus
,
3946 (void *)NineDevice9_GetClipStatus
,
3947 (void *)NineDevice9_GetTexture
,
3948 (void *)NineDevice9_SetTexture
,
3949 (void *)NineDevice9_GetTextureStageState
,
3950 (void *)NineDevice9_SetTextureStageState
,
3951 (void *)NineDevice9_GetSamplerState
,
3952 (void *)NineDevice9_SetSamplerState
,
3953 (void *)NineDevice9_ValidateDevice
,
3954 (void *)NineDevice9_SetPaletteEntries
,
3955 (void *)NineDevice9_GetPaletteEntries
,
3956 (void *)NineDevice9_SetCurrentTexturePalette
,
3957 (void *)NineDevice9_GetCurrentTexturePalette
,
3958 (void *)NineDevice9_SetScissorRect
,
3959 (void *)NineDevice9_GetScissorRect
,
3960 (void *)NineDevice9_SetSoftwareVertexProcessing
,
3961 (void *)NineDevice9_GetSoftwareVertexProcessing
,
3962 (void *)NineDevice9_SetNPatchMode
,
3963 (void *)NineDevice9_GetNPatchMode
,
3964 (void *)NineDevice9_DrawPrimitive
,
3965 (void *)NineDevice9_DrawIndexedPrimitive
,
3966 (void *)NineDevice9_DrawPrimitiveUP
,
3967 (void *)NineDevice9_DrawIndexedPrimitiveUP
,
3968 (void *)NineDevice9_ProcessVertices
,
3969 (void *)NineDevice9_CreateVertexDeclaration
,
3970 (void *)NineDevice9_SetVertexDeclaration
,
3971 (void *)NineDevice9_GetVertexDeclaration
,
3972 (void *)NineDevice9_SetFVF
,
3973 (void *)NineDevice9_GetFVF
,
3974 (void *)NineDevice9_CreateVertexShader
,
3975 (void *)NineDevice9_SetVertexShader
,
3976 (void *)NineDevice9_GetVertexShader
,
3977 (void *)NineDevice9_SetVertexShaderConstantF
,
3978 (void *)NineDevice9_GetVertexShaderConstantF
,
3979 (void *)NineDevice9_SetVertexShaderConstantI
,
3980 (void *)NineDevice9_GetVertexShaderConstantI
,
3981 (void *)NineDevice9_SetVertexShaderConstantB
,
3982 (void *)NineDevice9_GetVertexShaderConstantB
,
3983 (void *)NineDevice9_SetStreamSource
,
3984 (void *)NineDevice9_GetStreamSource
,
3985 (void *)NineDevice9_SetStreamSourceFreq
,
3986 (void *)NineDevice9_GetStreamSourceFreq
,
3987 (void *)NineDevice9_SetIndices
,
3988 (void *)NineDevice9_GetIndices
,
3989 (void *)NineDevice9_CreatePixelShader
,
3990 (void *)NineDevice9_SetPixelShader
,
3991 (void *)NineDevice9_GetPixelShader
,
3992 (void *)NineDevice9_SetPixelShaderConstantF
,
3993 (void *)NineDevice9_GetPixelShaderConstantF
,
3994 (void *)NineDevice9_SetPixelShaderConstantI
,
3995 (void *)NineDevice9_GetPixelShaderConstantI
,
3996 (void *)NineDevice9_SetPixelShaderConstantB
,
3997 (void *)NineDevice9_GetPixelShaderConstantB
,
3998 (void *)NineDevice9_DrawRectPatch
,
3999 (void *)NineDevice9_DrawTriPatch
,
4000 (void *)NineDevice9_DeletePatch
,
4001 (void *)NineDevice9_CreateQuery
4004 static const GUID
*NineDevice9_IIDs
[] = {
4005 &IID_IDirect3DDevice9
,
4011 NineDevice9_new( struct pipe_screen
*pScreen
,
4012 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
4014 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
4016 ID3DPresentGroup
*pPresentationGroup
,
4017 struct d3dadapter9_context
*pCTX
,
4019 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
4020 struct NineDevice9
**ppOut
,
4021 int minorVersionNum
)
4024 lock
= !!(pCreationParameters
->BehaviorFlags
& D3DCREATE_MULTITHREADED
);
4026 NINE_NEW(Device9
, ppOut
, lock
, /* args */
4027 pScreen
, pCreationParameters
, pCaps
,
4028 pPresentationParameters
, pD3D9
, pPresentationGroup
, pCTX
,
4029 ex
, pFullscreenDisplayMode
, minorVersionNum
);