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_buffer_upload.h"
38 #include "nine_helpers.h"
39 #include "nine_pipe.h"
41 #include "nine_dump.h"
42 #include "nine_limits.h"
44 #include "pipe/p_screen.h"
45 #include "pipe/p_context.h"
46 #include "pipe/p_config.h"
47 #include "util/u_math.h"
48 #include "util/u_inlines.h"
49 #include "util/u_hash_table.h"
50 #include "util/u_format.h"
51 #include "util/u_surface.h"
52 #include "util/u_upload_mgr.h"
53 #include "hud/hud_context.h"
55 #include "cso_cache/cso_context.h"
57 #define DBG_CHANNEL DBG_DEVICE
59 #if defined(PIPE_CC_GCC) && (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64))
61 static void nine_setup_fpu()
65 __asm__
__volatile__ ("fnstcw %0" : "=m" (*&c
));
67 /* clear the control word */
69 /* d3d9 doc/wine tests: mask all exceptions, use single-precision
70 * and round to nearest */
73 __asm__
__volatile__ ("fldcw %0" : : "m" (*&c
));
78 static void nine_setup_fpu(void)
80 WARN_ONCE("FPU setup not supported on non-x86 platforms\n");
86 NineDevice9_SetDefaultState( struct NineDevice9
*This
, boolean is_reset
)
88 struct NineSurface9
*refSurf
= NULL
;
90 DBG("This=%p is_reset=%d\n", This
, (int) is_reset
);
92 assert(!This
->is_recording
);
94 nine_state_set_defaults(This
, &This
->caps
, is_reset
);
96 refSurf
= This
->swapchains
[0]->buffers
[0];
99 This
->state
.viewport
.X
= 0;
100 This
->state
.viewport
.Y
= 0;
101 This
->state
.viewport
.Width
= refSurf
->desc
.Width
;
102 This
->state
.viewport
.Height
= refSurf
->desc
.Height
;
104 nine_context_set_viewport(This
, &This
->state
.viewport
);
106 This
->state
.scissor
.minx
= 0;
107 This
->state
.scissor
.miny
= 0;
108 This
->state
.scissor
.maxx
= refSurf
->desc
.Width
;
109 This
->state
.scissor
.maxy
= refSurf
->desc
.Height
;
111 nine_context_set_scissor(This
, &This
->state
.scissor
);
113 if (This
->nswapchains
&& This
->swapchains
[0]->params
.EnableAutoDepthStencil
) {
114 nine_context_set_render_state(This
, D3DRS_ZENABLE
, TRUE
);
115 This
->state
.rs_advertised
[D3DRS_ZENABLE
] = TRUE
;
117 if (This
->state
.rs_advertised
[D3DRS_ZENABLE
])
118 NineDevice9_SetDepthStencilSurface(
119 This
, (IDirect3DSurface9
*)This
->swapchains
[0]->zsbuf
);
122 #define GET_PCAP(n) pScreen->get_param(pScreen, PIPE_CAP_##n)
124 NineDevice9_ctor( struct NineDevice9
*This
,
125 struct NineUnknownParams
*pParams
,
126 struct pipe_screen
*pScreen
,
127 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
129 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
131 ID3DPresentGroup
*pPresentationGroup
,
132 struct d3dadapter9_context
*pCTX
,
134 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
135 int minorVersionNum
)
138 HRESULT hr
= NineUnknown_ctor(&This
->base
, pParams
);
140 DBG("This=%p pParams=%p pScreen=%p pCreationParameters=%p pCaps=%p pPresentationParameters=%p "
141 "pD3D9=%p pPresentationGroup=%p pCTX=%p ex=%d pFullscreenDisplayMode=%p\n",
142 This
, pParams
, pScreen
, pCreationParameters
, pCaps
, pPresentationParameters
, pD3D9
,
143 pPresentationGroup
, pCTX
, (int) ex
, pFullscreenDisplayMode
);
145 if (FAILED(hr
)) { return hr
; }
147 list_inithead(&This
->update_buffers
);
148 list_inithead(&This
->update_textures
);
149 list_inithead(&This
->managed_buffers
);
150 list_inithead(&This
->managed_textures
);
152 This
->screen
= pScreen
;
153 This
->screen_sw
= pCTX
->ref
;
156 This
->params
= *pCreationParameters
;
158 This
->present
= pPresentationGroup
;
159 This
->minor_version_num
= minorVersionNum
;
161 IDirect3D9_AddRef(This
->d3d9
);
162 ID3DPresentGroup_AddRef(This
->present
);
164 if (!(This
->params
.BehaviorFlags
& D3DCREATE_FPU_PRESERVE
))
167 if (This
->params
.BehaviorFlags
& D3DCREATE_SOFTWARE_VERTEXPROCESSING
) {
168 DBG("Application asked full Software Vertex Processing.\n");
170 This
->may_swvp
= true;
173 if (This
->params
.BehaviorFlags
& D3DCREATE_MIXED_VERTEXPROCESSING
) {
174 DBG("Application asked mixed Software Vertex Processing.\n");
175 This
->may_swvp
= true;
177 This
->context
.swvp
= This
->swvp
;
178 /* TODO: check if swvp is resetted by device Resets */
180 if (This
->may_swvp
&&
181 (This
->screen
->get_shader_param(This
->screen
, PIPE_SHADER_VERTEX
,
182 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
)
183 < (NINE_MAX_CONST_F_SWVP
/2) * sizeof(float[4]) ||
184 This
->screen
->get_shader_param(This
->screen
, PIPE_SHADER_VERTEX
,
185 PIPE_SHADER_CAP_MAX_CONST_BUFFERS
) < 5)) {
186 /* Note: We just go on, some apps never use the abilities of
187 * swvp, and just set more constants than allowed at init.
188 * Only cards we support that are affected are the r500 */
189 WARN("Card unable to handle Software Vertex Processing. Game may fail\n");
192 /* When may_swvp, SetConstant* limits are different */
194 This
->caps
.MaxVertexShaderConst
= NINE_MAX_CONST_F_SWVP
;
196 This
->context
.pipe
= This
->screen
->context_create(This
->screen
, NULL
, 0);
197 This
->pipe_secondary
= This
->screen
->context_create(This
->screen
, NULL
, 0);
198 if (!This
->context
.pipe
|| !This
->pipe_secondary
) { return E_OUTOFMEMORY
; } /* guess */
199 This
->pipe_sw
= This
->screen_sw
->context_create(This
->screen_sw
, NULL
, 0);
200 if (!This
->pipe_sw
) { return E_OUTOFMEMORY
; }
202 This
->context
.cso
= cso_create_context(This
->context
.pipe
);
203 if (!This
->context
.cso
) { return E_OUTOFMEMORY
; } /* also a guess */
204 This
->cso_sw
= cso_create_context(This
->pipe_sw
);
205 if (!This
->cso_sw
) { return E_OUTOFMEMORY
; }
207 /* Create first, it messes up our state. */
208 This
->hud
= hud_create(This
->context
.pipe
, This
->context
.cso
); /* NULL result is fine */
210 /* Available memory counter. Updated only for allocations with this device
211 * instance. This is the Win 7 behavior.
212 * Win XP shares this counter across multiple devices. */
213 This
->available_texture_mem
= This
->screen
->get_param(This
->screen
, PIPE_CAP_VIDEO_MEMORY
);
214 if (This
->available_texture_mem
< 4096)
215 This
->available_texture_mem
<<= 20;
217 This
->available_texture_mem
= UINT_MAX
;
218 /* We cap texture memory usage to 80% of what is reported free initially
219 * This helps get closer Win behaviour. For example VertexBuffer allocation
220 * still succeeds when texture allocation fails. */
221 This
->available_texture_limit
= This
->available_texture_mem
* 20LL / 100LL;
223 /* create implicit swapchains */
224 This
->nswapchains
= ID3DPresentGroup_GetMultiheadCount(This
->present
);
225 This
->swapchains
= CALLOC(This
->nswapchains
,
226 sizeof(struct NineSwapChain9
*));
227 if (!This
->swapchains
) { return E_OUTOFMEMORY
; }
229 for (i
= 0; i
< This
->nswapchains
; ++i
) {
230 ID3DPresent
*present
;
232 hr
= ID3DPresentGroup_GetPresent(This
->present
, i
, &present
);
237 D3DDISPLAYMODEEX
*mode
= NULL
;
238 struct NineSwapChain9Ex
**ret
=
239 (struct NineSwapChain9Ex
**)&This
->swapchains
[i
];
241 if (pFullscreenDisplayMode
) mode
= &(pFullscreenDisplayMode
[i
]);
242 /* when this is a Device9Ex, it should create SwapChain9Exs */
243 hr
= NineSwapChain9Ex_new(This
, TRUE
, present
,
244 &pPresentationParameters
[i
], pCTX
,
245 This
->params
.hFocusWindow
, mode
, ret
);
247 hr
= NineSwapChain9_new(This
, TRUE
, present
,
248 &pPresentationParameters
[i
], pCTX
,
249 This
->params
.hFocusWindow
,
250 &This
->swapchains
[i
]);
253 ID3DPresent_Release(present
);
256 NineUnknown_ConvertRefToBind(NineUnknown(This
->swapchains
[i
]));
258 hr
= NineSwapChain9_GetBackBuffer(This
->swapchains
[i
], 0,
259 D3DBACKBUFFER_TYPE_MONO
,
260 (IDirect3DSurface9
**)
264 NineUnknown_ConvertRefToBind(NineUnknown(This
->state
.rt
[i
]));
265 nine_bind(&This
->context
.rt
[i
], This
->state
.rt
[i
]);
268 /* Initialize CSMT */
269 if (pCTX
->csmt_force
== 1)
270 This
->csmt_active
= true;
271 else if (pCTX
->csmt_force
== 0)
272 This
->csmt_active
= false;
274 /* r600 and radeonsi are thread safe. */
275 This
->csmt_active
= strstr(pScreen
->get_name(pScreen
), "AMD") != NULL
;
277 /* We rely on u_upload_mgr using persistent coherent buffers (which don't
278 * require flush to work in multi-pipe_context scenario) for vertex and
280 if (!GET_PCAP(BUFFER_MAP_PERSISTENT_COHERENT
))
281 This
->csmt_active
= false;
283 if (This
->csmt_active
) {
284 This
->csmt_ctx
= nine_csmt_create(This
);
286 return E_OUTOFMEMORY
;
289 if (This
->csmt_active
)
290 DBG("\033[1;32mCSMT is active\033[0m\n");
292 This
->buffer_upload
= nine_upload_create(This
->pipe_secondary
, 4 * 1024 * 1024, 4);
294 /* Initialize a dummy VBO to be used when a vertex declaration does not
295 * specify all the inputs needed by vertex shader, on win default behavior
296 * is to pass 0,0,0,0 to the shader */
298 struct pipe_transfer
*transfer
;
299 struct pipe_resource tmpl
;
303 memset(&tmpl
, 0, sizeof(tmpl
));
304 tmpl
.target
= PIPE_BUFFER
;
305 tmpl
.format
= PIPE_FORMAT_R8_UNORM
;
306 tmpl
.width0
= 16; /* 4 floats */
312 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
313 tmpl
.bind
= PIPE_BIND_VERTEX_BUFFER
;
315 This
->dummy_vbo
= pScreen
->resource_create(pScreen
, &tmpl
);
317 if (!This
->dummy_vbo
)
318 return D3DERR_OUTOFVIDEOMEMORY
;
320 u_box_1d(0, 16, &box
);
321 data
= This
->context
.pipe
->transfer_map(This
->context
.pipe
, This
->dummy_vbo
, 0,
322 PIPE_TRANSFER_WRITE
|
323 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
328 This
->context
.pipe
->transfer_unmap(This
->context
.pipe
, transfer
);
331 This
->cursor
.software
= FALSE
;
332 This
->cursor
.hotspot
.x
= -1;
333 This
->cursor
.hotspot
.y
= -1;
335 struct pipe_resource tmpl
;
336 memset(&tmpl
, 0, sizeof(tmpl
));
337 tmpl
.target
= PIPE_TEXTURE_2D
;
338 tmpl
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
345 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
346 tmpl
.bind
= PIPE_BIND_CURSOR
| PIPE_BIND_SAMPLER_VIEW
;
349 This
->cursor
.image
= pScreen
->resource_create(pScreen
, &tmpl
);
350 if (!This
->cursor
.image
)
351 return D3DERR_OUTOFVIDEOMEMORY
;
353 /* For uploading 32x32 (argb) cursor */
354 This
->cursor
.hw_upload_temp
= MALLOC(32 * 4 * 32);
355 if (!This
->cursor
.hw_upload_temp
)
356 return D3DERR_OUTOFVIDEOMEMORY
;
359 /* Create constant buffers. */
361 unsigned max_const_vs
, max_const_ps
;
363 /* vs 3.0: >= 256 float constants, but for cards with exactly 256 slots,
364 * we have to take in some more slots for int and bool*/
365 max_const_vs
= _min(pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
,
366 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
) /
369 /* ps 3.0: 224 float constants. All cards supported support at least
370 * 256 constants for ps */
371 max_const_ps
= NINE_MAX_CONST_F_PS3
+ (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
373 This
->max_vs_const_f
= max_const_vs
-
374 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
375 This
->max_ps_const_f
= max_const_ps
-
376 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
378 This
->vs_const_size
= max_const_vs
* sizeof(float[4]);
379 This
->ps_const_size
= max_const_ps
* sizeof(float[4]);
380 /* Include space for I,B constants for user constbuf. */
381 if (This
->may_swvp
) {
382 This
->state
.vs_const_f
= CALLOC(NINE_MAX_CONST_F_SWVP
* sizeof(float[4]),1);
383 This
->context
.vs_const_f_swvp
= CALLOC(NINE_MAX_CONST_F_SWVP
* sizeof(float[4]),1);
384 if (!This
->context
.vs_const_f_swvp
)
385 return E_OUTOFMEMORY
;
386 This
->state
.vs_lconstf_temp
= CALLOC(NINE_MAX_CONST_F_SWVP
* sizeof(float[4]),1);
387 This
->context
.vs_lconstf_temp
= CALLOC(NINE_MAX_CONST_F_SWVP
* sizeof(float[4]),1);
388 This
->state
.vs_const_i
= CALLOC(NINE_MAX_CONST_I_SWVP
* sizeof(int[4]), 1);
389 This
->context
.vs_const_i
= CALLOC(NINE_MAX_CONST_I_SWVP
* sizeof(int[4]), 1);
390 This
->state
.vs_const_b
= CALLOC(NINE_MAX_CONST_B_SWVP
* sizeof(BOOL
), 1);
391 This
->context
.vs_const_b
= CALLOC(NINE_MAX_CONST_B_SWVP
* sizeof(BOOL
), 1);
393 This
->state
.vs_const_f
= CALLOC(NINE_MAX_CONST_F
* sizeof(float[4]), 1);
394 This
->context
.vs_const_f_swvp
= NULL
;
395 This
->state
.vs_lconstf_temp
= CALLOC(This
->vs_const_size
,1);
396 This
->context
.vs_lconstf_temp
= CALLOC(This
->vs_const_size
,1);
397 This
->state
.vs_const_i
= CALLOC(NINE_MAX_CONST_I
* sizeof(int[4]), 1);
398 This
->context
.vs_const_i
= CALLOC(NINE_MAX_CONST_I
* sizeof(int[4]), 1);
399 This
->state
.vs_const_b
= CALLOC(NINE_MAX_CONST_B
* sizeof(BOOL
), 1);
400 This
->context
.vs_const_b
= CALLOC(NINE_MAX_CONST_B
* sizeof(BOOL
), 1);
402 This
->context
.vs_const_f
= CALLOC(This
->vs_const_size
, 1);
403 This
->state
.ps_const_f
= CALLOC(This
->ps_const_size
, 1);
404 This
->context
.ps_const_f
= CALLOC(This
->ps_const_size
, 1);
405 This
->context
.ps_lconstf_temp
= CALLOC(This
->ps_const_size
,1);
406 if (!This
->state
.vs_const_f
|| !This
->context
.vs_const_f
||
407 !This
->state
.ps_const_f
|| !This
->context
.ps_const_f
||
408 !This
->state
.vs_lconstf_temp
|| !This
->context
.vs_lconstf_temp
||
409 !This
->context
.ps_lconstf_temp
||
410 !This
->state
.vs_const_i
|| !This
->context
.vs_const_i
||
411 !This
->state
.vs_const_b
|| !This
->context
.vs_const_b
)
412 return E_OUTOFMEMORY
;
414 if (strstr(pScreen
->get_name(pScreen
), "AMD") ||
415 strstr(pScreen
->get_name(pScreen
), "ATI")) {
416 This
->driver_bugs
.buggy_barycentrics
= TRUE
;
420 /* allocate dummy texture/sampler for when there are missing ones bound */
422 struct pipe_resource tmplt
;
423 struct pipe_sampler_view templ
;
424 struct pipe_sampler_state samp
;
425 memset(&tmplt
, 0, sizeof(tmplt
));
426 memset(&samp
, 0, sizeof(samp
));
428 tmplt
.target
= PIPE_TEXTURE_2D
;
432 tmplt
.last_level
= 0;
433 tmplt
.array_size
= 1;
434 tmplt
.usage
= PIPE_USAGE_DEFAULT
;
436 tmplt
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
437 tmplt
.bind
= PIPE_BIND_SAMPLER_VIEW
;
438 tmplt
.nr_samples
= 0;
440 This
->dummy_texture
= This
->screen
->resource_create(This
->screen
, &tmplt
);
441 if (!This
->dummy_texture
)
442 return D3DERR_DRIVERINTERNALERROR
;
444 templ
.format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
445 templ
.u
.tex
.first_layer
= 0;
446 templ
.u
.tex
.last_layer
= 0;
447 templ
.u
.tex
.first_level
= 0;
448 templ
.u
.tex
.last_level
= 0;
449 templ
.swizzle_r
= PIPE_SWIZZLE_0
;
450 templ
.swizzle_g
= PIPE_SWIZZLE_0
;
451 templ
.swizzle_b
= PIPE_SWIZZLE_0
;
452 templ
.swizzle_a
= PIPE_SWIZZLE_1
;
453 templ
.target
= This
->dummy_texture
->target
;
455 This
->dummy_sampler_view
= This
->context
.pipe
->create_sampler_view(This
->context
.pipe
, This
->dummy_texture
, &templ
);
456 if (!This
->dummy_sampler_view
)
457 return D3DERR_DRIVERINTERNALERROR
;
459 samp
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
460 samp
.max_lod
= 15.0f
;
461 samp
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
462 samp
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
463 samp
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
464 samp
.min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
465 samp
.mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
466 samp
.compare_mode
= PIPE_TEX_COMPARE_NONE
;
467 samp
.compare_func
= PIPE_FUNC_LEQUAL
;
468 samp
.normalized_coords
= 1;
469 samp
.seamless_cube_map
= 0;
470 This
->dummy_sampler_state
= samp
;
473 /* Allocate upload helper for drivers that suck (from st pov ;). */
475 This
->driver_caps
.user_vbufs
= GET_PCAP(USER_VERTEX_BUFFERS
) && !This
->csmt_active
;
476 This
->driver_caps
.user_ibufs
= GET_PCAP(USER_INDEX_BUFFERS
) && !This
->csmt_active
;
477 This
->driver_caps
.user_cbufs
= GET_PCAP(USER_CONSTANT_BUFFERS
);
478 This
->driver_caps
.user_sw_vbufs
= This
->screen_sw
->get_param(This
->screen_sw
, PIPE_CAP_USER_VERTEX_BUFFERS
);
479 This
->driver_caps
.user_sw_cbufs
= This
->screen_sw
->get_param(This
->screen_sw
, PIPE_CAP_USER_CONSTANT_BUFFERS
);
481 /* Implicit use of context pipe for vertex and index uploaded when
482 * csmt is not active. Does not need to sync since csmt is unactive,
483 * thus no need to call NineDevice9_GetPipe at each upload. */
484 if (!This
->driver_caps
.user_vbufs
)
485 This
->vertex_uploader
= u_upload_create(This
->csmt_active
?
486 This
->pipe_secondary
: This
->context
.pipe
,
488 PIPE_BIND_VERTEX_BUFFER
, PIPE_USAGE_STREAM
);
489 This
->vertex_sw_uploader
= u_upload_create(This
->pipe_sw
, 65536,
490 PIPE_BIND_VERTEX_BUFFER
, PIPE_USAGE_STREAM
);
491 if (!This
->driver_caps
.user_ibufs
)
492 This
->index_uploader
= u_upload_create(This
->csmt_active
?
493 This
->pipe_secondary
: This
->context
.pipe
,
495 PIPE_BIND_INDEX_BUFFER
, PIPE_USAGE_STREAM
);
496 if (!This
->driver_caps
.user_cbufs
) {
497 This
->constbuf_alignment
= GET_PCAP(CONSTANT_BUFFER_OFFSET_ALIGNMENT
);
498 This
->constbuf_uploader
= u_upload_create(This
->context
.pipe
, This
->vs_const_size
,
499 PIPE_BIND_CONSTANT_BUFFER
, PIPE_USAGE_STREAM
);
502 This
->constbuf_sw_uploader
= u_upload_create(This
->pipe_sw
, 128 * 1024,
503 PIPE_BIND_CONSTANT_BUFFER
, PIPE_USAGE_STREAM
);
505 This
->driver_caps
.window_space_position_support
= GET_PCAP(TGSI_VS_WINDOW_SPACE_POSITION
);
506 This
->driver_caps
.vs_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
, PIPE_SHADER_CAP_INTEGERS
);
507 This
->driver_caps
.ps_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_FRAGMENT
, PIPE_SHADER_CAP_INTEGERS
);
508 This
->driver_caps
.offset_units_unscaled
= GET_PCAP(POLYGON_OFFSET_UNITS_UNSCALED
);
510 nine_ff_init(This
); /* initialize fixed function code */
512 NineDevice9_SetDefaultState(This
, FALSE
);
515 struct pipe_poly_stipple stipple
;
516 memset(&stipple
, ~0, sizeof(stipple
));
517 This
->context
.pipe
->set_polygon_stipple(This
->context
.pipe
, &stipple
);
520 This
->update
= &This
->state
;
522 nine_state_init_sw(This
);
524 ID3DPresentGroup_Release(This
->present
);
525 if (This
->csmt_active
)
526 nine_csmt_process(This
);
533 NineDevice9_dtor( struct NineDevice9
*This
)
537 DBG("This=%p\n", This
);
539 /* Do not call nine_csmt_process here. The device is dead! */
540 if (This
->csmt_active
&& This
->csmt_ctx
) {
541 nine_csmt_destroy(This
, This
->csmt_ctx
);
542 This
->csmt_active
= FALSE
;
543 This
->csmt_ctx
= NULL
;
547 nine_state_destroy_sw(This
);
548 nine_state_clear(&This
->state
, TRUE
);
549 nine_context_clear(This
);
551 if (This
->vertex_uploader
)
552 u_upload_destroy(This
->vertex_uploader
);
553 if (This
->index_uploader
)
554 u_upload_destroy(This
->index_uploader
);
555 if (This
->constbuf_uploader
)
556 u_upload_destroy(This
->constbuf_uploader
);
557 if (This
->vertex_sw_uploader
)
558 u_upload_destroy(This
->vertex_sw_uploader
);
559 if (This
->constbuf_sw_uploader
)
560 u_upload_destroy(This
->constbuf_sw_uploader
);
562 nine_bind(&This
->record
, NULL
);
564 pipe_sampler_view_reference(&This
->dummy_sampler_view
, NULL
);
565 pipe_resource_reference(&This
->dummy_texture
, NULL
);
566 pipe_resource_reference(&This
->dummy_vbo
, NULL
);
567 FREE(This
->state
.vs_const_f
);
568 FREE(This
->context
.vs_const_f
);
569 FREE(This
->state
.ps_const_f
);
570 FREE(This
->context
.ps_const_f
);
571 FREE(This
->state
.vs_lconstf_temp
);
572 FREE(This
->context
.vs_lconstf_temp
);
573 FREE(This
->context
.ps_lconstf_temp
);
574 FREE(This
->state
.vs_const_i
);
575 FREE(This
->context
.vs_const_i
);
576 FREE(This
->state
.vs_const_b
);
577 FREE(This
->context
.vs_const_b
);
578 FREE(This
->context
.vs_const_f_swvp
);
580 pipe_resource_reference(&This
->cursor
.image
, NULL
);
581 FREE(This
->cursor
.hw_upload_temp
);
583 if (This
->swapchains
) {
584 for (i
= 0; i
< This
->nswapchains
; ++i
)
585 if (This
->swapchains
[i
])
586 NineUnknown_Unbind(NineUnknown(This
->swapchains
[i
]));
587 FREE(This
->swapchains
);
590 if (This
->buffer_upload
)
591 nine_upload_destroy(This
->buffer_upload
);
593 /* Destroy cso first */
594 if (This
->context
.cso
) { cso_destroy_context(This
->context
.cso
); }
595 if (This
->cso_sw
) { cso_destroy_context(This
->cso_sw
); }
596 if (This
->context
.pipe
&& This
->context
.pipe
->destroy
) { This
->context
.pipe
->destroy(This
->context
.pipe
); }
597 if (This
->pipe_secondary
&& This
->pipe_secondary
->destroy
) { This
->pipe_secondary
->destroy(This
->pipe_secondary
); }
598 if (This
->pipe_sw
&& This
->pipe_sw
->destroy
) { This
->pipe_sw
->destroy(This
->pipe_sw
); }
600 if (This
->present
) { ID3DPresentGroup_Release(This
->present
); }
601 if (This
->d3d9
) { IDirect3D9_Release(This
->d3d9
); }
603 NineUnknown_dtor(&This
->base
);
607 NineDevice9_GetScreen( struct NineDevice9
*This
)
612 struct pipe_context
*
613 NineDevice9_GetPipe( struct NineDevice9
*This
)
615 return nine_context_get_pipe(This
);
619 NineDevice9_GetCaps( struct NineDevice9
*This
)
625 NineDevice9_PauseRecording( struct NineDevice9
*This
)
628 This
->update
= &This
->state
;
629 This
->is_recording
= FALSE
;
634 NineDevice9_ResumeRecording( struct NineDevice9
*This
)
637 This
->update
= &This
->record
->state
;
638 This
->is_recording
= TRUE
;
643 NineDevice9_TestCooperativeLevel( struct NineDevice9
*This
)
645 if (NineSwapChain9_GetOccluded(This
->swapchains
[0])) {
646 This
->device_needs_reset
= TRUE
;
647 return D3DERR_DEVICELOST
;
648 } else if (NineSwapChain9_ResolutionMismatch(This
->swapchains
[0])) {
649 This
->device_needs_reset
= TRUE
;
650 return D3DERR_DEVICENOTRESET
;
651 } else if (This
->device_needs_reset
) {
652 return D3DERR_DEVICENOTRESET
;
659 NineDevice9_GetAvailableTextureMem( struct NineDevice9
*This
)
661 return This
->available_texture_mem
;
665 NineDevice9_EvictManagedResources( struct NineDevice9
*This
)
667 struct NineBaseTexture9
*tex
;
668 struct NineBuffer9
*buf
;
670 DBG("This=%p\n", This
);
671 LIST_FOR_EACH_ENTRY(tex
, &This
->managed_textures
, list2
) {
672 NineBaseTexture9_UnLoad(tex
);
674 /* Vertex/index buffers don't take a lot of space and aren't accounted
675 * for d3d memory usage. Instead of actually freeing from memory,
676 * just mark the buffer dirty to trigger a re-upload later. We
677 * could just ignore, but some bad behaving apps could rely on it (if
678 * they write outside the locked regions typically). */
679 LIST_FOR_EACH_ENTRY(buf
, &This
->managed_buffers
, managed
.list2
) {
680 NineBuffer9_SetDirty(buf
);
687 NineDevice9_GetDirect3D( struct NineDevice9
*This
,
688 IDirect3D9
**ppD3D9
)
690 user_assert(ppD3D9
!= NULL
, E_POINTER
);
691 IDirect3D9_AddRef(This
->d3d9
);
692 *ppD3D9
= This
->d3d9
;
697 NineDevice9_GetDeviceCaps( struct NineDevice9
*This
,
700 user_assert(pCaps
!= NULL
, D3DERR_INVALIDCALL
);
706 NineDevice9_GetDisplayMode( struct NineDevice9
*This
,
708 D3DDISPLAYMODE
*pMode
)
710 DBG("This=%p iSwapChain=%u pMode=%p\n", This
, iSwapChain
, pMode
);
712 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
714 return NineSwapChain9_GetDisplayMode(This
->swapchains
[iSwapChain
], pMode
);
718 NineDevice9_GetCreationParameters( struct NineDevice9
*This
,
719 D3DDEVICE_CREATION_PARAMETERS
*pParameters
)
721 user_assert(pParameters
!= NULL
, D3DERR_INVALIDCALL
);
722 *pParameters
= This
->params
;
727 NineDevice9_SetCursorProperties( struct NineDevice9
*This
,
730 IDirect3DSurface9
*pCursorBitmap
)
732 struct NineSurface9
*surf
= NineSurface9(pCursorBitmap
);
733 struct pipe_context
*pipe
= NineDevice9_GetPipe(This
);
735 struct pipe_transfer
*transfer
;
739 DBG_FLAG(DBG_SWAPCHAIN
, "This=%p XHotSpot=%u YHotSpot=%u "
740 "pCursorBitmap=%p\n", This
, XHotSpot
, YHotSpot
, pCursorBitmap
);
742 user_assert(pCursorBitmap
, D3DERR_INVALIDCALL
);
743 user_assert(surf
->desc
.Format
== D3DFMT_A8R8G8B8
, D3DERR_INVALIDCALL
);
745 if (This
->swapchains
[0]->params
.Windowed
) {
746 This
->cursor
.w
= MIN2(surf
->desc
.Width
, 32);
747 This
->cursor
.h
= MIN2(surf
->desc
.Height
, 32);
748 hw_cursor
= 1; /* always use hw cursor for windowed mode */
750 This
->cursor
.w
= MIN2(surf
->desc
.Width
, This
->cursor
.image
->width0
);
751 This
->cursor
.h
= MIN2(surf
->desc
.Height
, This
->cursor
.image
->height0
);
752 hw_cursor
= This
->cursor
.w
== 32 && This
->cursor
.h
== 32;
755 u_box_origin_2d(This
->cursor
.w
, This
->cursor
.h
, &box
);
757 ptr
= pipe
->transfer_map(pipe
, This
->cursor
.image
, 0,
758 PIPE_TRANSFER_WRITE
|
759 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
762 ret_err("Failed to update cursor image.\n", D3DERR_DRIVERINTERNALERROR
);
764 This
->cursor
.hotspot
.x
= XHotSpot
;
765 This
->cursor
.hotspot
.y
= YHotSpot
;
767 /* Copy cursor image to internal storage. */
771 const struct util_format_description
*sfmt
=
772 util_format_description(surf
->base
.info
.format
);
775 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, D3DLOCK_READONLY
);
777 ret_err("Failed to map cursor source image.\n",
778 D3DERR_DRIVERINTERNALERROR
);
780 sfmt
->unpack_rgba_8unorm(ptr
, transfer
->stride
,
781 lock
.pBits
, lock
.Pitch
,
782 This
->cursor
.w
, This
->cursor
.h
);
785 void *data
= lock
.pBits
;
786 /* SetCursor assumes 32x32 argb with pitch 128 */
787 if (lock
.Pitch
!= 128) {
788 sfmt
->unpack_rgba_8unorm(This
->cursor
.hw_upload_temp
, 128,
789 lock
.pBits
, lock
.Pitch
,
791 data
= This
->cursor
.hw_upload_temp
;
793 hw_cursor
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
,
795 &This
->cursor
.hotspot
,
796 This
->cursor
.visible
) == D3D_OK
;
799 NineSurface9_UnlockRect(surf
);
801 pipe
->transfer_unmap(pipe
, transfer
);
803 /* hide cursor if we emulate it */
805 ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, FALSE
);
806 This
->cursor
.software
= !hw_cursor
;
812 NineDevice9_SetCursorPosition( struct NineDevice9
*This
,
817 struct NineSwapChain9
*swap
= This
->swapchains
[0];
819 DBG("This=%p X=%d Y=%d Flags=%d\n", This
, X
, Y
, Flags
);
821 This
->cursor
.pos
.x
= X
;
822 This
->cursor
.pos
.y
= Y
;
824 if (!This
->cursor
.software
)
825 This
->cursor
.software
= ID3DPresent_SetCursorPos(swap
->present
, &This
->cursor
.pos
) != D3D_OK
;
829 NineDevice9_ShowCursor( struct NineDevice9
*This
,
832 BOOL old
= This
->cursor
.visible
;
834 DBG("This=%p bShow=%d\n", This
, (int) bShow
);
836 This
->cursor
.visible
= bShow
&& (This
->cursor
.hotspot
.x
!= -1);
837 if (!This
->cursor
.software
)
838 This
->cursor
.software
= ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, bShow
) != D3D_OK
;
844 NineDevice9_CreateAdditionalSwapChain( struct NineDevice9
*This
,
845 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
846 IDirect3DSwapChain9
**pSwapChain
)
848 struct NineSwapChain9
*swapchain
, *tmplt
= This
->swapchains
[0];
849 ID3DPresent
*present
;
852 DBG("This=%p pPresentationParameters=%p pSwapChain=%p\n",
853 This
, pPresentationParameters
, pSwapChain
);
855 user_assert(pPresentationParameters
, D3DERR_INVALIDCALL
);
856 user_assert(tmplt
->params
.Windowed
&& pPresentationParameters
->Windowed
, D3DERR_INVALIDCALL
);
858 /* TODO: this deserves more tests */
859 if (!pPresentationParameters
->hDeviceWindow
)
860 pPresentationParameters
->hDeviceWindow
= This
->params
.hFocusWindow
;
862 hr
= ID3DPresentGroup_CreateAdditionalPresent(This
->present
, pPresentationParameters
, &present
);
867 hr
= NineSwapChain9_new(This
, FALSE
, present
, pPresentationParameters
,
869 tmplt
->params
.hDeviceWindow
,
874 *pSwapChain
= (IDirect3DSwapChain9
*)swapchain
;
879 NineDevice9_GetSwapChain( struct NineDevice9
*This
,
881 IDirect3DSwapChain9
**pSwapChain
)
883 user_assert(pSwapChain
!= NULL
, D3DERR_INVALIDCALL
);
886 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
888 NineUnknown_AddRef(NineUnknown(This
->swapchains
[iSwapChain
]));
889 *pSwapChain
= (IDirect3DSwapChain9
*)This
->swapchains
[iSwapChain
];
895 NineDevice9_GetNumberOfSwapChains( struct NineDevice9
*This
)
897 return This
->nswapchains
;
901 NineDevice9_Reset( struct NineDevice9
*This
,
902 D3DPRESENT_PARAMETERS
*pPresentationParameters
)
907 DBG("This=%p pPresentationParameters=%p\n", This
, pPresentationParameters
);
909 if (NineSwapChain9_GetOccluded(This
->swapchains
[0])) {
910 This
->device_needs_reset
= TRUE
;
911 return D3DERR_DEVICELOST
;
914 for (i
= 0; i
< This
->nswapchains
; ++i
) {
915 D3DPRESENT_PARAMETERS
*params
= &pPresentationParameters
[i
];
916 hr
= NineSwapChain9_Resize(This
->swapchains
[i
], params
, NULL
);
921 nine_state_clear(&This
->state
, TRUE
);
922 nine_context_clear(This
);
924 NineDevice9_SetDefaultState(This
, TRUE
);
925 NineDevice9_SetRenderTarget(
926 This
, 0, (IDirect3DSurface9
*)This
->swapchains
[0]->buffers
[0]);
927 /* XXX: better use GetBackBuffer here ? */
929 This
->device_needs_reset
= (hr
!= D3D_OK
);
934 NineDevice9_Present( struct NineDevice9
*This
,
935 const RECT
*pSourceRect
,
936 const RECT
*pDestRect
,
937 HWND hDestWindowOverride
,
938 const RGNDATA
*pDirtyRegion
)
943 DBG("This=%p pSourceRect=%p pDestRect=%p hDestWindowOverride=%p pDirtyRegion=%p\n",
944 This
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
946 /* XXX is this right? */
947 for (i
= 0; i
< This
->nswapchains
; ++i
) {
948 hr
= NineSwapChain9_Present(This
->swapchains
[i
], pSourceRect
, pDestRect
,
949 hDestWindowOverride
, pDirtyRegion
, 0);
950 if (FAILED(hr
)) { return hr
; }
957 NineDevice9_GetBackBuffer( struct NineDevice9
*This
,
960 D3DBACKBUFFER_TYPE Type
,
961 IDirect3DSurface9
**ppBackBuffer
)
963 user_assert(ppBackBuffer
!= NULL
, D3DERR_INVALIDCALL
);
964 /* return NULL on error */
965 *ppBackBuffer
= NULL
;
966 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
968 return NineSwapChain9_GetBackBuffer(This
->swapchains
[iSwapChain
],
969 iBackBuffer
, Type
, ppBackBuffer
);
973 NineDevice9_GetRasterStatus( struct NineDevice9
*This
,
975 D3DRASTER_STATUS
*pRasterStatus
)
977 user_assert(pRasterStatus
!= NULL
, D3DERR_INVALIDCALL
);
978 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
980 return NineSwapChain9_GetRasterStatus(This
->swapchains
[iSwapChain
],
985 NineDevice9_SetDialogBoxMode( struct NineDevice9
*This
,
986 BOOL bEnableDialogs
)
988 STUB(D3DERR_INVALIDCALL
);
992 NineDevice9_SetGammaRamp( struct NineDevice9
*This
,
995 const D3DGAMMARAMP
*pRamp
)
997 DBG("This=%p iSwapChain=%u Flags=%x pRamp=%p\n", This
,
998 iSwapChain
, Flags
, pRamp
);
1000 user_warn(iSwapChain
>= This
->nswapchains
);
1003 if (pRamp
&& (iSwapChain
< This
->nswapchains
)) {
1004 struct NineSwapChain9
*swap
= This
->swapchains
[iSwapChain
];
1005 swap
->gamma
= *pRamp
;
1006 ID3DPresent_SetGammaRamp(swap
->present
, pRamp
, swap
->params
.hDeviceWindow
);
1011 NineDevice9_GetGammaRamp( struct NineDevice9
*This
,
1013 D3DGAMMARAMP
*pRamp
)
1015 DBG("This=%p iSwapChain=%u pRamp=%p\n", This
, iSwapChain
, pRamp
);
1017 user_warn(iSwapChain
>= This
->nswapchains
);
1020 if (pRamp
&& (iSwapChain
< This
->nswapchains
))
1021 *pRamp
= This
->swapchains
[iSwapChain
]->gamma
;
1025 NineDevice9_CreateTexture( struct NineDevice9
*This
,
1032 IDirect3DTexture9
**ppTexture
,
1033 HANDLE
*pSharedHandle
)
1035 struct NineTexture9
*tex
;
1038 DBG("This=%p Width=%u Height=%u Levels=%u Usage=%s Format=%s Pool=%s "
1039 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Levels
,
1040 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
1041 nine_D3DPOOL_to_str(Pool
), ppTexture
, pSharedHandle
);
1043 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DMAP
|
1044 D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
1045 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
;
1049 hr
= NineTexture9_new(This
, Width
, Height
, Levels
, Usage
, Format
, Pool
,
1050 &tex
, pSharedHandle
);
1052 *ppTexture
= (IDirect3DTexture9
*)tex
;
1058 NineDevice9_CreateVolumeTexture( struct NineDevice9
*This
,
1066 IDirect3DVolumeTexture9
**ppVolumeTexture
,
1067 HANDLE
*pSharedHandle
)
1069 struct NineVolumeTexture9
*tex
;
1072 DBG("This=%p Width=%u Height=%u Depth=%u Levels=%u Usage=%s Format=%s Pool=%s "
1073 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Depth
, Levels
,
1074 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
1075 nine_D3DPOOL_to_str(Pool
), ppVolumeTexture
, pSharedHandle
);
1077 Usage
&= D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1078 D3DUSAGE_SOFTWAREPROCESSING
;
1080 *ppVolumeTexture
= NULL
;
1082 hr
= NineVolumeTexture9_new(This
, Width
, Height
, Depth
, Levels
,
1083 Usage
, Format
, Pool
, &tex
, pSharedHandle
);
1085 *ppVolumeTexture
= (IDirect3DVolumeTexture9
*)tex
;
1091 NineDevice9_CreateCubeTexture( struct NineDevice9
*This
,
1097 IDirect3DCubeTexture9
**ppCubeTexture
,
1098 HANDLE
*pSharedHandle
)
1100 struct NineCubeTexture9
*tex
;
1103 DBG("This=%p EdgeLength=%u Levels=%u Usage=%s Format=%s Pool=%s ppOut=%p "
1104 "pSharedHandle=%p\n", This
, EdgeLength
, Levels
,
1105 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
1106 nine_D3DPOOL_to_str(Pool
), ppCubeTexture
, pSharedHandle
);
1108 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DYNAMIC
|
1109 D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
1110 D3DUSAGE_SOFTWAREPROCESSING
;
1112 *ppCubeTexture
= NULL
;
1114 hr
= NineCubeTexture9_new(This
, EdgeLength
, Levels
, Usage
, Format
, Pool
,
1115 &tex
, pSharedHandle
);
1117 *ppCubeTexture
= (IDirect3DCubeTexture9
*)tex
;
1123 NineDevice9_CreateVertexBuffer( struct NineDevice9
*This
,
1128 IDirect3DVertexBuffer9
**ppVertexBuffer
,
1129 HANDLE
*pSharedHandle
)
1131 struct NineVertexBuffer9
*buf
;
1133 D3DVERTEXBUFFER_DESC desc
;
1135 DBG("This=%p Length=%u Usage=%x FVF=%x Pool=%u ppOut=%p pSharedHandle=%p\n",
1136 This
, Length
, Usage
, FVF
, Pool
, ppVertexBuffer
, pSharedHandle
);
1138 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1140 desc
.Format
= D3DFMT_VERTEXDATA
;
1141 desc
.Type
= D3DRTYPE_VERTEXBUFFER
;
1142 desc
.Usage
= Usage
&
1143 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1144 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1145 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
|
1146 D3DUSAGE_WRITEONLY
);
1151 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1152 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1154 hr
= NineVertexBuffer9_new(This
, &desc
, &buf
);
1156 *ppVertexBuffer
= (IDirect3DVertexBuffer9
*)buf
;
1161 NineDevice9_CreateIndexBuffer( struct NineDevice9
*This
,
1166 IDirect3DIndexBuffer9
**ppIndexBuffer
,
1167 HANDLE
*pSharedHandle
)
1169 struct NineIndexBuffer9
*buf
;
1171 D3DINDEXBUFFER_DESC desc
;
1173 DBG("This=%p Length=%u Usage=%x Format=%s Pool=%u ppOut=%p "
1174 "pSharedHandle=%p\n", This
, Length
, Usage
,
1175 d3dformat_to_string(Format
), Pool
, ppIndexBuffer
, pSharedHandle
);
1177 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
1179 desc
.Format
= Format
;
1180 desc
.Type
= D3DRTYPE_INDEXBUFFER
;
1181 desc
.Usage
= Usage
&
1182 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
1183 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
1184 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_WRITEONLY
);
1188 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1189 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
1191 hr
= NineIndexBuffer9_new(This
, &desc
, &buf
);
1193 *ppIndexBuffer
= (IDirect3DIndexBuffer9
*)buf
;
1198 create_zs_or_rt_surface(struct NineDevice9
*This
,
1199 unsigned type
, /* 0 = RT, 1 = ZS, 2 = plain */
1201 UINT Width
, UINT Height
,
1203 D3DMULTISAMPLE_TYPE MultiSample
,
1204 DWORD MultisampleQuality
,
1205 BOOL Discard_or_Lockable
,
1206 IDirect3DSurface9
**ppSurface
,
1207 HANDLE
*pSharedHandle
)
1209 struct NineSurface9
*surface
;
1211 D3DSURFACE_DESC desc
;
1213 DBG("This=%p type=%u Pool=%s Width=%u Height=%u Format=%s MS=%u Quality=%u "
1214 "Discard_or_Lockable=%i ppSurface=%p pSharedHandle=%p\n",
1215 This
, type
, nine_D3DPOOL_to_str(Pool
), Width
, Height
,
1216 d3dformat_to_string(Format
), MultiSample
, MultisampleQuality
,
1217 Discard_or_Lockable
, ppSurface
, pSharedHandle
);
1220 DBG("FIXME Used shared handle! This option isn't probably handled correctly!\n");
1222 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
1223 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1225 desc
.Format
= Format
;
1226 desc
.Type
= D3DRTYPE_SURFACE
;
1229 desc
.MultiSampleType
= MultiSample
;
1230 desc
.MultiSampleQuality
= MultisampleQuality
;
1232 desc
.Height
= Height
;
1234 case 0: desc
.Usage
= D3DUSAGE_RENDERTARGET
; break;
1235 case 1: desc
.Usage
= D3DUSAGE_DEPTHSTENCIL
; break;
1236 default: assert(type
== 2); break;
1239 hr
= NineSurface9_new(This
, NULL
, NULL
, NULL
, 0, 0, 0, &desc
, &surface
);
1240 if (SUCCEEDED(hr
)) {
1241 *ppSurface
= (IDirect3DSurface9
*)surface
;
1243 if (surface
->base
.resource
&& Discard_or_Lockable
&& (type
!= 1))
1244 surface
->base
.resource
->flags
|= NINE_RESOURCE_FLAG_LOCKABLE
;
1251 NineDevice9_CreateRenderTarget( struct NineDevice9
*This
,
1255 D3DMULTISAMPLE_TYPE MultiSample
,
1256 DWORD MultisampleQuality
,
1258 IDirect3DSurface9
**ppSurface
,
1259 HANDLE
*pSharedHandle
)
1262 return create_zs_or_rt_surface(This
, 0, D3DPOOL_DEFAULT
,
1263 Width
, Height
, Format
,
1264 MultiSample
, MultisampleQuality
,
1265 Lockable
, ppSurface
, pSharedHandle
);
1269 NineDevice9_CreateDepthStencilSurface( struct NineDevice9
*This
,
1273 D3DMULTISAMPLE_TYPE MultiSample
,
1274 DWORD MultisampleQuality
,
1276 IDirect3DSurface9
**ppSurface
,
1277 HANDLE
*pSharedHandle
)
1280 if (!depth_stencil_format(Format
))
1281 return D3DERR_NOTAVAILABLE
;
1282 return create_zs_or_rt_surface(This
, 1, D3DPOOL_DEFAULT
,
1283 Width
, Height
, Format
,
1284 MultiSample
, MultisampleQuality
,
1285 Discard
, ppSurface
, pSharedHandle
);
1289 NineDevice9_UpdateSurface( struct NineDevice9
*This
,
1290 IDirect3DSurface9
*pSourceSurface
,
1291 const RECT
*pSourceRect
,
1292 IDirect3DSurface9
*pDestinationSurface
,
1293 const POINT
*pDestPoint
)
1295 struct NineSurface9
*dst
= NineSurface9(pDestinationSurface
);
1296 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1297 int copy_width
, copy_height
;
1300 DBG("This=%p pSourceSurface=%p pDestinationSurface=%p "
1301 "pSourceRect=%p pDestPoint=%p\n", This
,
1302 pSourceSurface
, pDestinationSurface
, pSourceRect
, pDestPoint
);
1304 DBG("pSourceRect = (%u,%u)-(%u,%u)\n",
1305 pSourceRect
->left
, pSourceRect
->top
,
1306 pSourceRect
->right
, pSourceRect
->bottom
);
1308 DBG("pDestPoint = (%u,%u)\n", pDestPoint
->x
, pDestPoint
->y
);
1310 user_assert(dst
&& src
, D3DERR_INVALIDCALL
);
1312 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1313 user_assert(src
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1315 user_assert(dst
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1316 user_assert(src
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1318 user_assert(!src
->lock_count
, D3DERR_INVALIDCALL
);
1319 user_assert(!dst
->lock_count
, D3DERR_INVALIDCALL
);
1321 user_assert(dst
->desc
.Format
== src
->desc
.Format
, D3DERR_INVALIDCALL
);
1322 user_assert(!depth_stencil_format(dst
->desc
.Format
), D3DERR_INVALIDCALL
);
1325 copy_width
= pSourceRect
->right
- pSourceRect
->left
;
1326 copy_height
= pSourceRect
->bottom
- pSourceRect
->top
;
1328 user_assert(pSourceRect
->left
>= 0 &&
1330 pSourceRect
->right
<= src
->desc
.Width
&&
1331 pSourceRect
->top
>= 0 &&
1333 pSourceRect
->bottom
<= src
->desc
.Height
,
1334 D3DERR_INVALIDCALL
);
1336 copy_width
= src
->desc
.Width
;
1337 copy_height
= src
->desc
.Height
;
1340 destRect
.right
= copy_width
;
1341 destRect
.bottom
= copy_height
;
1344 user_assert(pDestPoint
->x
>= 0 && pDestPoint
->y
>= 0,
1345 D3DERR_INVALIDCALL
);
1346 destRect
.right
+= pDestPoint
->x
;
1347 destRect
.bottom
+= pDestPoint
->y
;
1350 user_assert(destRect
.right
<= dst
->desc
.Width
&&
1351 destRect
.bottom
<= dst
->desc
.Height
,
1352 D3DERR_INVALIDCALL
);
1354 if (compressed_format(dst
->desc
.Format
)) {
1355 const unsigned w
= util_format_get_blockwidth(dst
->base
.info
.format
);
1356 const unsigned h
= util_format_get_blockheight(dst
->base
.info
.format
);
1359 user_assert(!(pDestPoint
->x
% w
) && !(pDestPoint
->y
% h
),
1360 D3DERR_INVALIDCALL
);
1364 user_assert(!(pSourceRect
->left
% w
) && !(pSourceRect
->top
% h
),
1365 D3DERR_INVALIDCALL
);
1367 if (!(copy_width
== src
->desc
.Width
&&
1368 copy_width
== dst
->desc
.Width
&&
1369 copy_height
== src
->desc
.Height
&&
1370 copy_height
== dst
->desc
.Height
)) {
1371 user_assert(!(copy_width
% w
) && !(copy_height
% h
),
1372 D3DERR_INVALIDCALL
);
1376 NineSurface9_CopyMemToDefault(dst
, src
, pDestPoint
, pSourceRect
);
1382 NineDevice9_UpdateTexture( struct NineDevice9
*This
,
1383 IDirect3DBaseTexture9
*pSourceTexture
,
1384 IDirect3DBaseTexture9
*pDestinationTexture
)
1386 struct NineBaseTexture9
*dstb
= NineBaseTexture9(pDestinationTexture
);
1387 struct NineBaseTexture9
*srcb
= NineBaseTexture9(pSourceTexture
);
1389 unsigned last_src_level
, last_dst_level
;
1392 DBG("This=%p pSourceTexture=%p pDestinationTexture=%p\n", This
,
1393 pSourceTexture
, pDestinationTexture
);
1395 user_assert(pSourceTexture
&& pDestinationTexture
, D3DERR_INVALIDCALL
);
1396 user_assert(pSourceTexture
!= pDestinationTexture
, D3DERR_INVALIDCALL
);
1398 user_assert(dstb
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1399 user_assert(srcb
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1400 user_assert(dstb
->base
.type
== srcb
->base
.type
, D3DERR_INVALIDCALL
);
1401 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ||
1402 dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
, D3DERR_INVALIDCALL
);
1405 * . Different formats
1406 * . Fewer src levels than dst levels (if the opposite, only matching levels
1407 * are supposed to be copied)
1408 * . Levels do not match
1409 * DDI: Actually the above should pass because of legacy applications
1410 * Do what you want about these, but you shouldn't crash.
1411 * However driver can expect that the top dimension is greater for src than dst.
1412 * Wine tests: Every combination that passes the initial checks should pass.
1413 * . Different formats => conversion driver and format dependent.
1414 * . 1 level, but size not matching => copy is done (and even crash if src bigger
1415 * than dst. For the case where dst bigger, wine doesn't test if a stretch is applied
1416 * or if a subrect is copied).
1417 * . 8x8 4 sublevels -> 7x7 2 sublevels => driver dependent, On NV seems to be 4x4 subrect
1420 * From these, the proposal is:
1421 * . Different formats -> use util_format_translate to translate if possible for surfaces.
1422 * Accept ARGB/XRGB for Volumes. Do nothing for the other combinations
1423 * . First level copied -> the first level such that src is smaller or equal to dst first level
1424 * . number of levels copied -> as long as it fits and textures have levels
1425 * That should satisfy the constraints (and instead of crashing for some cases we return D3D_OK)
1428 last_src_level
= (srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ? 0 : srcb
->base
.info
.last_level
;
1429 last_dst_level
= (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) ? 0 : dstb
->base
.info
.last_level
;
1431 for (m
= 0; m
<= last_src_level
; ++m
) {
1432 unsigned w
= u_minify(srcb
->base
.info
.width0
, m
);
1433 unsigned h
= u_minify(srcb
->base
.info
.height0
, m
);
1434 unsigned d
= u_minify(srcb
->base
.info
.depth0
, m
);
1436 if (w
<= dstb
->base
.info
.width0
&&
1437 h
<= dstb
->base
.info
.height0
&&
1438 d
<= dstb
->base
.info
.depth0
)
1441 user_assert(m
<= last_src_level
, D3D_OK
);
1443 last_dst_level
= MIN2(srcb
->base
.info
.last_level
- m
, last_dst_level
);
1445 if (dstb
->base
.type
== D3DRTYPE_TEXTURE
) {
1446 struct NineTexture9
*dst
= NineTexture9(dstb
);
1447 struct NineTexture9
*src
= NineTexture9(srcb
);
1449 if (src
->dirty_rect
.width
== 0)
1452 pipe_box_to_rect(&rect
, &src
->dirty_rect
);
1453 for (l
= 0; l
< m
; ++l
)
1454 rect_minify_inclusive(&rect
);
1456 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
) {
1457 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1459 dst
->surfaces
[l
]->desc
.Width
,
1460 dst
->surfaces
[l
]->desc
.Height
);
1461 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
],
1465 rect_minify_inclusive(&rect
);
1467 u_box_origin_2d(0, 0, &src
->dirty_rect
);
1469 if (dstb
->base
.type
== D3DRTYPE_CUBETEXTURE
) {
1470 struct NineCubeTexture9
*dst
= NineCubeTexture9(dstb
);
1471 struct NineCubeTexture9
*src
= NineCubeTexture9(srcb
);
1474 /* GPUs usually have them stored as arrays of mip-mapped 2D textures. */
1475 for (z
= 0; z
< 6; ++z
) {
1476 if (src
->dirty_rect
[z
].width
== 0)
1479 pipe_box_to_rect(&rect
, &src
->dirty_rect
[z
]);
1480 for (l
= 0; l
< m
; ++l
)
1481 rect_minify_inclusive(&rect
);
1483 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
) {
1484 fit_rect_format_inclusive(dst
->base
.base
.info
.format
,
1486 dst
->surfaces
[l
* 6 + z
]->desc
.Width
,
1487 dst
->surfaces
[l
* 6 + z
]->desc
.Height
);
1488 NineSurface9_CopyMemToDefault(dst
->surfaces
[l
* 6 + z
],
1489 src
->surfaces
[m
* 6 + z
],
1492 rect_minify_inclusive(&rect
);
1494 u_box_origin_2d(0, 0, &src
->dirty_rect
[z
]);
1498 if (dstb
->base
.type
== D3DRTYPE_VOLUMETEXTURE
) {
1499 struct NineVolumeTexture9
*dst
= NineVolumeTexture9(dstb
);
1500 struct NineVolumeTexture9
*src
= NineVolumeTexture9(srcb
);
1502 if (src
->dirty_box
.width
== 0)
1504 for (l
= 0; l
<= last_dst_level
; ++l
, ++m
)
1505 NineVolume9_CopyMemToDefault(dst
->volumes
[l
],
1506 src
->volumes
[m
], 0, 0, 0, NULL
);
1507 u_box_3d(0, 0, 0, 0, 0, 0, &src
->dirty_box
);
1509 assert(!"invalid texture type");
1512 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1513 dstb
->dirty_mip
= TRUE
;
1514 NineBaseTexture9_GenerateMipSubLevels(dstb
);
1521 NineDevice9_GetRenderTargetData( struct NineDevice9
*This
,
1522 IDirect3DSurface9
*pRenderTarget
,
1523 IDirect3DSurface9
*pDestSurface
)
1525 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1526 struct NineSurface9
*src
= NineSurface9(pRenderTarget
);
1528 DBG("This=%p pRenderTarget=%p pDestSurface=%p\n",
1529 This
, pRenderTarget
, pDestSurface
);
1531 user_assert(pRenderTarget
&& pDestSurface
, D3DERR_INVALIDCALL
);
1533 user_assert(dst
->desc
.Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1534 user_assert(src
->desc
.Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1536 user_assert(dst
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1537 user_assert(src
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1539 user_assert(src
->desc
.Width
== dst
->desc
.Width
, D3DERR_INVALIDCALL
);
1540 user_assert(src
->desc
.Height
== dst
->desc
.Height
, D3DERR_INVALIDCALL
);
1542 user_assert(src
->desc
.Format
!= D3DFMT_NULL
, D3DERR_INVALIDCALL
);
1544 NineSurface9_CopyDefaultToMem(dst
, src
);
1550 NineDevice9_GetFrontBufferData( struct NineDevice9
*This
,
1552 IDirect3DSurface9
*pDestSurface
)
1554 DBG("This=%p iSwapChain=%u pDestSurface=%p\n", This
,
1555 iSwapChain
, pDestSurface
);
1557 user_assert(pDestSurface
!= NULL
, D3DERR_INVALIDCALL
);
1558 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
1560 return NineSwapChain9_GetFrontBufferData(This
->swapchains
[iSwapChain
],
1565 NineDevice9_StretchRect( struct NineDevice9
*This
,
1566 IDirect3DSurface9
*pSourceSurface
,
1567 const RECT
*pSourceRect
,
1568 IDirect3DSurface9
*pDestSurface
,
1569 const RECT
*pDestRect
,
1570 D3DTEXTUREFILTERTYPE Filter
)
1572 struct pipe_screen
*screen
= This
->screen
;
1573 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1574 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1575 struct pipe_resource
*dst_res
= NineSurface9_GetResource(dst
);
1576 struct pipe_resource
*src_res
= NineSurface9_GetResource(src
);
1578 struct pipe_blit_info blit
;
1579 boolean scaled
, clamped
, ms
, flip_x
= FALSE
, flip_y
= FALSE
;
1581 DBG("This=%p pSourceSurface=%p pSourceRect=%p pDestSurface=%p "
1582 "pDestRect=%p Filter=%u\n",
1583 This
, pSourceSurface
, pSourceRect
, pDestSurface
, pDestRect
, Filter
);
1585 DBG("pSourceRect=(%u,%u)-(%u,%u)\n",
1586 pSourceRect
->left
, pSourceRect
->top
,
1587 pSourceRect
->right
, pSourceRect
->bottom
);
1589 DBG("pDestRect=(%u,%u)-(%u,%u)\n", pDestRect
->left
, pDestRect
->top
,
1590 pDestRect
->right
, pDestRect
->bottom
);
1592 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
&&
1593 src
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1594 zs
= util_format_is_depth_or_stencil(dst_res
->format
);
1595 user_assert(!zs
|| !This
->in_scene
, D3DERR_INVALIDCALL
);
1596 user_assert(!zs
|| !pSourceRect
||
1597 (pSourceRect
->left
== 0 &&
1598 pSourceRect
->top
== 0 &&
1599 pSourceRect
->right
== src
->desc
.Width
&&
1600 pSourceRect
->bottom
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1601 user_assert(!zs
|| !pDestRect
||
1602 (pDestRect
->left
== 0 &&
1603 pDestRect
->top
== 0 &&
1604 pDestRect
->right
== dst
->desc
.Width
&&
1605 pDestRect
->bottom
== dst
->desc
.Height
), D3DERR_INVALIDCALL
);
1607 (dst
->desc
.Width
== src
->desc
.Width
&&
1608 dst
->desc
.Height
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1609 user_assert(zs
|| !util_format_is_depth_or_stencil(src_res
->format
),
1610 D3DERR_INVALIDCALL
);
1611 user_assert(!zs
|| dst
->desc
.Format
== src
->desc
.Format
,
1612 D3DERR_INVALIDCALL
);
1613 user_assert(screen
->is_format_supported(screen
, src_res
->format
,
1615 src_res
->nr_samples
,
1616 PIPE_BIND_SAMPLER_VIEW
),
1617 D3DERR_INVALIDCALL
);
1619 /* We might want to permit these, but wine thinks we shouldn't. */
1620 user_assert(!pDestRect
||
1621 (pDestRect
->left
<= pDestRect
->right
&&
1622 pDestRect
->top
<= pDestRect
->bottom
), D3DERR_INVALIDCALL
);
1623 user_assert(!pSourceRect
||
1624 (pSourceRect
->left
<= pSourceRect
->right
&&
1625 pSourceRect
->top
<= pSourceRect
->bottom
), D3DERR_INVALIDCALL
);
1627 memset(&blit
, 0, sizeof(blit
));
1628 blit
.dst
.resource
= dst_res
;
1629 blit
.dst
.level
= dst
->level
;
1630 blit
.dst
.box
.z
= dst
->layer
;
1631 blit
.dst
.box
.depth
= 1;
1632 blit
.dst
.format
= dst_res
->format
;
1634 flip_x
= pDestRect
->left
> pDestRect
->right
;
1636 blit
.dst
.box
.x
= pDestRect
->right
;
1637 blit
.dst
.box
.width
= pDestRect
->left
- pDestRect
->right
;
1639 blit
.dst
.box
.x
= pDestRect
->left
;
1640 blit
.dst
.box
.width
= pDestRect
->right
- pDestRect
->left
;
1642 flip_y
= pDestRect
->top
> pDestRect
->bottom
;
1644 blit
.dst
.box
.y
= pDestRect
->bottom
;
1645 blit
.dst
.box
.height
= pDestRect
->top
- pDestRect
->bottom
;
1647 blit
.dst
.box
.y
= pDestRect
->top
;
1648 blit
.dst
.box
.height
= pDestRect
->bottom
- pDestRect
->top
;
1653 blit
.dst
.box
.width
= dst
->desc
.Width
;
1654 blit
.dst
.box
.height
= dst
->desc
.Height
;
1656 blit
.src
.resource
= src_res
;
1657 blit
.src
.level
= src
->level
;
1658 blit
.src
.box
.z
= src
->layer
;
1659 blit
.src
.box
.depth
= 1;
1660 blit
.src
.format
= src_res
->format
;
1662 if (flip_x
^ (pSourceRect
->left
> pSourceRect
->right
)) {
1663 blit
.src
.box
.x
= pSourceRect
->right
;
1664 blit
.src
.box
.width
= pSourceRect
->left
- pSourceRect
->right
;
1666 blit
.src
.box
.x
= pSourceRect
->left
;
1667 blit
.src
.box
.width
= pSourceRect
->right
- pSourceRect
->left
;
1669 if (flip_y
^ (pSourceRect
->top
> pSourceRect
->bottom
)) {
1670 blit
.src
.box
.y
= pSourceRect
->bottom
;
1671 blit
.src
.box
.height
= pSourceRect
->top
- pSourceRect
->bottom
;
1673 blit
.src
.box
.y
= pSourceRect
->top
;
1674 blit
.src
.box
.height
= pSourceRect
->bottom
- pSourceRect
->top
;
1677 blit
.src
.box
.x
= flip_x
? src
->desc
.Width
: 0;
1678 blit
.src
.box
.y
= flip_y
? src
->desc
.Height
: 0;
1679 blit
.src
.box
.width
= flip_x
? -src
->desc
.Width
: src
->desc
.Width
;
1680 blit
.src
.box
.height
= flip_y
? -src
->desc
.Height
: src
->desc
.Height
;
1682 blit
.mask
= zs
? PIPE_MASK_ZS
: PIPE_MASK_RGBA
;
1683 blit
.filter
= Filter
== D3DTEXF_LINEAR
?
1684 PIPE_TEX_FILTER_LINEAR
: PIPE_TEX_FILTER_NEAREST
;
1685 blit
.scissor_enable
= FALSE
;
1686 blit
.alpha_blend
= FALSE
;
1688 /* If both of a src and dst dimension are negative, flip them. */
1689 if (blit
.dst
.box
.width
< 0 && blit
.src
.box
.width
< 0) {
1690 blit
.dst
.box
.width
= -blit
.dst
.box
.width
;
1691 blit
.src
.box
.width
= -blit
.src
.box
.width
;
1693 if (blit
.dst
.box
.height
< 0 && blit
.src
.box
.height
< 0) {
1694 blit
.dst
.box
.height
= -blit
.dst
.box
.height
;
1695 blit
.src
.box
.height
= -blit
.src
.box
.height
;
1698 blit
.dst
.box
.width
!= blit
.src
.box
.width
||
1699 blit
.dst
.box
.height
!= blit
.src
.box
.height
;
1701 user_assert(!scaled
|| dst
!= src
, D3DERR_INVALIDCALL
);
1702 user_assert(!scaled
||
1703 !NineSurface9_IsOffscreenPlain(dst
), D3DERR_INVALIDCALL
);
1704 user_assert(!NineSurface9_IsOffscreenPlain(dst
) ||
1705 NineSurface9_IsOffscreenPlain(src
), D3DERR_INVALIDCALL
);
1706 user_assert(NineSurface9_IsOffscreenPlain(dst
) ||
1707 dst
->desc
.Usage
& (D3DUSAGE_RENDERTARGET
| D3DUSAGE_DEPTHSTENCIL
),
1708 D3DERR_INVALIDCALL
);
1709 user_assert(!scaled
||
1710 (!util_format_is_compressed(dst
->base
.info
.format
) &&
1711 !util_format_is_compressed(src
->base
.info
.format
)),
1712 D3DERR_INVALIDCALL
);
1714 user_warn(src
== dst
&&
1715 u_box_test_intersection_2d(&blit
.src
.box
, &blit
.dst
.box
));
1717 /* Check for clipping/clamping: */
1719 struct pipe_box box
;
1722 xy
= u_box_clip_2d(&box
, &blit
.dst
.box
,
1723 dst
->desc
.Width
, dst
->desc
.Height
);
1727 xy
= u_box_clip_2d(&box
, &blit
.src
.box
,
1728 src
->desc
.Width
, src
->desc
.Height
);
1732 ms
= (dst
->desc
.MultiSampleType
!= src
->desc
.MultiSampleType
) ||
1733 (dst
->desc
.MultiSampleQuality
!= src
->desc
.MultiSampleQuality
);
1735 if (clamped
|| scaled
|| (blit
.dst
.format
!= blit
.src
.format
) || ms
) {
1736 DBG("using pipe->blit()\n");
1737 /* TODO: software scaling */
1738 user_assert(screen
->is_format_supported(screen
, dst_res
->format
,
1740 dst_res
->nr_samples
,
1741 zs
? PIPE_BIND_DEPTH_STENCIL
:
1742 PIPE_BIND_RENDER_TARGET
),
1743 D3DERR_INVALIDCALL
);
1745 nine_context_blit(This
, (struct NineUnknown
*)dst
,
1746 (struct NineUnknown
*)src
, &blit
);
1748 assert(blit
.dst
.box
.x
>= 0 && blit
.dst
.box
.y
>= 0 &&
1749 blit
.src
.box
.x
>= 0 && blit
.src
.box
.y
>= 0 &&
1750 blit
.dst
.box
.x
+ blit
.dst
.box
.width
<= dst
->desc
.Width
&&
1751 blit
.src
.box
.x
+ blit
.src
.box
.width
<= src
->desc
.Width
&&
1752 blit
.dst
.box
.y
+ blit
.dst
.box
.height
<= dst
->desc
.Height
&&
1753 blit
.src
.box
.y
+ blit
.src
.box
.height
<= src
->desc
.Height
);
1754 /* Or drivers might crash ... */
1755 DBG("Using resource_copy_region.\n");
1756 nine_context_resource_copy_region(This
, (struct NineUnknown
*)dst
,
1757 (struct NineUnknown
*)src
,
1758 blit
.dst
.resource
, blit
.dst
.level
,
1760 blit
.src
.resource
, blit
.src
.level
,
1764 /* Communicate the container it needs to update sublevels - if apply */
1765 NineSurface9_MarkContainerDirty(dst
);
1771 NineDevice9_ColorFill( struct NineDevice9
*This
,
1772 IDirect3DSurface9
*pSurface
,
1776 struct NineSurface9
*surf
= NineSurface9(pSurface
);
1777 unsigned x
, y
, w
, h
;
1779 DBG("This=%p pSurface=%p pRect=%p color=%08x\n", This
,
1780 pSurface
, pRect
, color
);
1782 DBG("pRect=(%u,%u)-(%u,%u)\n", pRect
->left
, pRect
->top
,
1783 pRect
->right
, pRect
->bottom
);
1785 user_assert(surf
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1787 user_assert((surf
->base
.usage
& D3DUSAGE_RENDERTARGET
) ||
1788 NineSurface9_IsOffscreenPlain(surf
), D3DERR_INVALIDCALL
);
1790 user_assert(surf
->desc
.Format
!= D3DFMT_NULL
, D3D_OK
);
1795 w
= pRect
->right
- pRect
->left
;
1796 h
= pRect
->bottom
- pRect
->top
;
1798 if (compressed_format(surf
->desc
.Format
)) {
1799 const unsigned bw
= util_format_get_blockwidth(surf
->base
.info
.format
);
1800 const unsigned bh
= util_format_get_blockheight(surf
->base
.info
.format
);
1802 user_assert(!(x
% bw
) && !(y
% bh
) && !(w
% bw
) && !(h
% bh
),
1803 D3DERR_INVALIDCALL
);
1808 w
= surf
->desc
.Width
;
1809 h
= surf
->desc
.Height
;
1812 if (surf
->base
.info
.bind
& PIPE_BIND_RENDER_TARGET
) {
1813 nine_context_clear_render_target(This
, surf
, color
, x
, y
, w
, h
);
1815 D3DLOCKED_RECT lock
;
1816 union util_color uc
;
1818 /* XXX: lock pRect and fix util_fill_rect */
1819 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, pRect
? 0 : D3DLOCK_DISCARD
);
1822 util_pack_color_ub(color
>> 16, color
>> 8, color
>> 0, color
>> 24,
1823 surf
->base
.info
.format
, &uc
);
1824 util_fill_rect(lock
.pBits
, surf
->base
.info
.format
,lock
.Pitch
,
1826 NineSurface9_UnlockRect(surf
);
1833 NineDevice9_CreateOffscreenPlainSurface( struct NineDevice9
*This
,
1838 IDirect3DSurface9
**ppSurface
,
1839 HANDLE
*pSharedHandle
)
1843 DBG("This=%p Width=%u Height=%u Format=%s(0x%x) Pool=%u "
1844 "ppSurface=%p pSharedHandle=%p\n", This
,
1845 Width
, Height
, d3dformat_to_string(Format
), Format
, Pool
,
1846 ppSurface
, pSharedHandle
);
1849 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
1850 || Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1851 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1853 /* Can be used with StretchRect and ColorFill. It's also always lockable.
1855 hr
= create_zs_or_rt_surface(This
, 2, Pool
, Width
, Height
,
1857 D3DMULTISAMPLE_NONE
, 0,
1859 ppSurface
, pSharedHandle
);
1861 DBG("Failed to create surface.\n");
1866 NineDevice9_SetRenderTarget( struct NineDevice9
*This
,
1867 DWORD RenderTargetIndex
,
1868 IDirect3DSurface9
*pRenderTarget
)
1870 struct NineSurface9
*rt
= NineSurface9(pRenderTarget
);
1871 const unsigned i
= RenderTargetIndex
;
1873 DBG("This=%p RenderTargetIndex=%u pRenderTarget=%p\n", This
,
1874 RenderTargetIndex
, pRenderTarget
);
1876 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1877 user_assert(i
!= 0 || pRenderTarget
, D3DERR_INVALIDCALL
);
1878 user_assert(!pRenderTarget
||
1879 rt
->desc
.Usage
& D3DUSAGE_RENDERTARGET
, D3DERR_INVALIDCALL
);
1882 This
->state
.viewport
.X
= 0;
1883 This
->state
.viewport
.Y
= 0;
1884 This
->state
.viewport
.Width
= rt
->desc
.Width
;
1885 This
->state
.viewport
.Height
= rt
->desc
.Height
;
1886 This
->state
.viewport
.MinZ
= 0.0f
;
1887 This
->state
.viewport
.MaxZ
= 1.0f
;
1889 This
->state
.scissor
.minx
= 0;
1890 This
->state
.scissor
.miny
= 0;
1891 This
->state
.scissor
.maxx
= rt
->desc
.Width
;
1892 This
->state
.scissor
.maxy
= rt
->desc
.Height
;
1895 if (This
->state
.rt
[i
] != NineSurface9(pRenderTarget
))
1896 nine_bind(&This
->state
.rt
[i
], pRenderTarget
);
1898 nine_context_set_render_target(This
, i
, rt
);
1903 NineDevice9_GetRenderTarget( struct NineDevice9
*This
,
1904 DWORD RenderTargetIndex
,
1905 IDirect3DSurface9
**ppRenderTarget
)
1907 const unsigned i
= RenderTargetIndex
;
1909 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1910 user_assert(ppRenderTarget
, D3DERR_INVALIDCALL
);
1912 *ppRenderTarget
= (IDirect3DSurface9
*)This
->state
.rt
[i
];
1913 if (!This
->state
.rt
[i
])
1914 return D3DERR_NOTFOUND
;
1916 NineUnknown_AddRef(NineUnknown(This
->state
.rt
[i
]));
1921 NineDevice9_SetDepthStencilSurface( struct NineDevice9
*This
,
1922 IDirect3DSurface9
*pNewZStencil
)
1924 struct NineSurface9
*ds
= NineSurface9(pNewZStencil
);
1925 DBG("This=%p pNewZStencil=%p\n", This
, pNewZStencil
);
1927 if (This
->state
.ds
!= ds
) {
1928 nine_bind(&This
->state
.ds
, ds
);
1929 nine_context_set_depth_stencil(This
, ds
);
1935 NineDevice9_GetDepthStencilSurface( struct NineDevice9
*This
,
1936 IDirect3DSurface9
**ppZStencilSurface
)
1938 user_assert(ppZStencilSurface
, D3DERR_INVALIDCALL
);
1940 *ppZStencilSurface
= (IDirect3DSurface9
*)This
->state
.ds
;
1941 if (!This
->state
.ds
)
1942 return D3DERR_NOTFOUND
;
1944 NineUnknown_AddRef(NineUnknown(This
->state
.ds
));
1949 NineDevice9_BeginScene( struct NineDevice9
*This
)
1951 DBG("This=%p\n", This
);
1952 user_assert(!This
->in_scene
, D3DERR_INVALIDCALL
);
1953 This
->in_scene
= TRUE
;
1954 /* Do we want to do anything else here ? */
1959 NineDevice9_EndScene( struct NineDevice9
*This
)
1961 DBG("This=%p\n", This
);
1962 user_assert(This
->in_scene
, D3DERR_INVALIDCALL
);
1963 This
->in_scene
= FALSE
;
1968 NineDevice9_Clear( struct NineDevice9
*This
,
1970 const D3DRECT
*pRects
,
1976 struct NineSurface9
*zsbuf_surf
= This
->state
.ds
;
1978 DBG("This=%p Count=%u pRects=%p Flags=%x Color=%08x Z=%f Stencil=%x\n",
1979 This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1981 user_assert(This
->state
.ds
|| !(Flags
& NINED3DCLEAR_DEPTHSTENCIL
),
1982 D3DERR_INVALIDCALL
);
1983 user_assert(!(Flags
& D3DCLEAR_STENCIL
) ||
1985 util_format_is_depth_and_stencil(zsbuf_surf
->base
.info
.format
)),
1986 D3DERR_INVALIDCALL
);
1988 user_assert((Count
&& pRects
) || (!Count
&& !pRects
), D3DERR_INVALIDCALL
);
1990 user_warn((pRects
&& !Count
) || (!pRects
&& Count
));
1991 if (pRects
&& !Count
)
1997 nine_context_clear_fb(This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
2002 NineDevice9_SetTransform( struct NineDevice9
*This
,
2003 D3DTRANSFORMSTATETYPE State
,
2004 const D3DMATRIX
*pMatrix
)
2006 struct nine_state
*state
= This
->update
;
2007 D3DMATRIX
*M
= nine_state_access_transform(&state
->ff
, State
, TRUE
);
2009 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2011 user_assert(M
, D3DERR_INVALIDCALL
);
2014 if (unlikely(This
->is_recording
)) {
2015 state
->ff
.changed
.transform
[State
/ 32] |= 1 << (State
% 32);
2016 state
->changed
.group
|= NINE_STATE_FF
;
2018 nine_context_set_transform(This
, State
, pMatrix
);
2024 NineDevice9_GetTransform( struct NineDevice9
*This
,
2025 D3DTRANSFORMSTATETYPE State
,
2026 D3DMATRIX
*pMatrix
)
2028 D3DMATRIX
*M
= nine_state_access_transform(&This
->state
.ff
, State
, FALSE
);
2029 user_assert(M
, D3DERR_INVALIDCALL
);
2035 NineDevice9_MultiplyTransform( struct NineDevice9
*This
,
2036 D3DTRANSFORMSTATETYPE State
,
2037 const D3DMATRIX
*pMatrix
)
2039 struct nine_state
*state
= This
->update
;
2041 D3DMATRIX
*M
= nine_state_access_transform(&state
->ff
, State
, TRUE
);
2043 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
2045 user_assert(M
, D3DERR_INVALIDCALL
);
2047 nine_d3d_matrix_matrix_mul(&T
, pMatrix
, M
);
2048 return NineDevice9_SetTransform(This
, State
, &T
);
2052 NineDevice9_SetViewport( struct NineDevice9
*This
,
2053 const D3DVIEWPORT9
*pViewport
)
2055 struct nine_state
*state
= This
->update
;
2057 DBG("X=%u Y=%u W=%u H=%u MinZ=%f MaxZ=%f\n",
2058 pViewport
->X
, pViewport
->Y
, pViewport
->Width
, pViewport
->Height
,
2059 pViewport
->MinZ
, pViewport
->MaxZ
);
2061 state
->viewport
= *pViewport
;
2062 nine_context_set_viewport(This
, pViewport
);
2068 NineDevice9_GetViewport( struct NineDevice9
*This
,
2069 D3DVIEWPORT9
*pViewport
)
2071 *pViewport
= This
->state
.viewport
;
2076 NineDevice9_SetMaterial( struct NineDevice9
*This
,
2077 const D3DMATERIAL9
*pMaterial
)
2079 struct nine_state
*state
= This
->update
;
2081 DBG("This=%p pMaterial=%p\n", This
, pMaterial
);
2083 nine_dump_D3DMATERIAL9(DBG_FF
, pMaterial
);
2085 user_assert(pMaterial
, E_POINTER
);
2087 state
->ff
.material
= *pMaterial
;
2088 if (unlikely(This
->is_recording
))
2089 state
->changed
.group
|= NINE_STATE_FF_MATERIAL
;
2091 nine_context_set_material(This
, pMaterial
);
2097 NineDevice9_GetMaterial( struct NineDevice9
*This
,
2098 D3DMATERIAL9
*pMaterial
)
2100 user_assert(pMaterial
, E_POINTER
);
2101 *pMaterial
= This
->state
.ff
.material
;
2106 NineDevice9_SetLight( struct NineDevice9
*This
,
2108 const D3DLIGHT9
*pLight
)
2110 struct nine_state
*state
= This
->update
;
2113 DBG("This=%p Index=%u pLight=%p\n", This
, Index
, pLight
);
2115 nine_dump_D3DLIGHT9(DBG_FF
, pLight
);
2117 user_assert(pLight
, D3DERR_INVALIDCALL
);
2118 user_assert(pLight
->Type
< NINED3DLIGHT_INVALID
, D3DERR_INVALIDCALL
);
2120 user_assert(Index
< NINE_MAX_LIGHTS
, D3DERR_INVALIDCALL
); /* sanity */
2122 hr
= nine_state_set_light(&state
->ff
, Index
, pLight
);
2126 if (pLight
->Type
!= D3DLIGHT_DIRECTIONAL
&&
2127 pLight
->Attenuation0
== 0.0f
&&
2128 pLight
->Attenuation1
== 0.0f
&&
2129 pLight
->Attenuation2
== 0.0f
) {
2130 DBG("Warning: all D3DLIGHT9.Attenuation[i] are 0\n");
2133 if (unlikely(This
->is_recording
))
2134 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
2136 nine_context_set_light(This
, Index
, pLight
);
2142 NineDevice9_GetLight( struct NineDevice9
*This
,
2146 const struct nine_state
*state
= &This
->state
;
2148 user_assert(pLight
, D3DERR_INVALIDCALL
);
2149 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2150 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2151 D3DERR_INVALIDCALL
);
2153 *pLight
= state
->ff
.light
[Index
];
2159 NineDevice9_LightEnable( struct NineDevice9
*This
,
2163 struct nine_state
*state
= This
->update
;
2165 DBG("This=%p Index=%u Enable=%i\n", This
, Index
, Enable
);
2167 if (Index
>= state
->ff
.num_lights
||
2168 state
->ff
.light
[Index
].Type
== NINED3DLIGHT_INVALID
) {
2169 /* This should create a default light. */
2171 memset(&light
, 0, sizeof(light
));
2172 light
.Type
= D3DLIGHT_DIRECTIONAL
;
2173 light
.Diffuse
.r
= 1.0f
;
2174 light
.Diffuse
.g
= 1.0f
;
2175 light
.Diffuse
.b
= 1.0f
;
2176 light
.Direction
.z
= 1.0f
;
2177 NineDevice9_SetLight(This
, Index
, &light
);
2180 nine_state_light_enable(&state
->ff
, &state
->changed
.group
, Index
, Enable
);
2181 if (likely(!This
->is_recording
))
2182 nine_context_light_enable(This
, Index
, Enable
);
2188 NineDevice9_GetLightEnable( struct NineDevice9
*This
,
2192 const struct nine_state
*state
= &This
->state
;
2195 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
2196 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
2197 D3DERR_INVALIDCALL
);
2199 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
)
2200 if (state
->ff
.active_light
[i
] == Index
)
2203 *pEnable
= i
!= state
->ff
.num_lights_active
? 128 : 0; // Taken from wine
2209 NineDevice9_SetClipPlane( struct NineDevice9
*This
,
2211 const float *pPlane
)
2213 struct nine_state
*state
= This
->update
;
2215 user_assert(pPlane
, D3DERR_INVALIDCALL
);
2217 DBG("This=%p Index=%u pPlane=%f %f %f %f\n", This
, Index
,
2218 pPlane
[0], pPlane
[1],
2219 pPlane
[2], pPlane
[3]);
2221 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2223 memcpy(&state
->clip
.ucp
[Index
][0], pPlane
, sizeof(state
->clip
.ucp
[0]));
2224 if (unlikely(This
->is_recording
))
2225 state
->changed
.ucp
|= 1 << Index
;
2227 nine_context_set_clip_plane(This
, Index
, (struct nine_clipplane
*)pPlane
);
2233 NineDevice9_GetClipPlane( struct NineDevice9
*This
,
2237 const struct nine_state
*state
= &This
->state
;
2239 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
2241 memcpy(pPlane
, &state
->clip
.ucp
[Index
][0], sizeof(state
->clip
.ucp
[0]));
2246 NineDevice9_SetRenderState( struct NineDevice9
*This
,
2247 D3DRENDERSTATETYPE State
,
2250 struct nine_state
*state
= This
->update
;
2252 DBG("This=%p State=%u(%s) Value=%08x\n", This
,
2253 State
, nine_d3drs_to_string(State
), Value
);
2255 user_assert(State
< D3DRS_COUNT
, D3DERR_INVALIDCALL
);
2257 if (unlikely(This
->is_recording
)) {
2258 state
->rs_advertised
[State
] = Value
;
2259 /* only need to record changed render states for stateblocks */
2260 state
->changed
.rs
[State
/ 32] |= 1 << (State
% 32);
2261 state
->changed
.group
|= nine_render_state_group
[State
];
2265 if (state
->rs_advertised
[State
] == Value
)
2268 state
->rs_advertised
[State
] = Value
;
2269 nine_context_set_render_state(This
, State
, Value
);
2275 NineDevice9_GetRenderState( struct NineDevice9
*This
,
2276 D3DRENDERSTATETYPE State
,
2279 user_assert(State
< D3DRS_COUNT
, D3DERR_INVALIDCALL
);
2281 *pValue
= This
->state
.rs_advertised
[State
];
2286 NineDevice9_CreateStateBlock( struct NineDevice9
*This
,
2287 D3DSTATEBLOCKTYPE Type
,
2288 IDirect3DStateBlock9
**ppSB
)
2290 struct NineStateBlock9
*nsb
;
2291 struct nine_state
*dst
;
2293 enum nine_stateblock_type type
;
2296 DBG("This=%p Type=%u ppSB=%p\n", This
, Type
, ppSB
);
2298 user_assert(Type
== D3DSBT_ALL
||
2299 Type
== D3DSBT_VERTEXSTATE
||
2300 Type
== D3DSBT_PIXELSTATE
, D3DERR_INVALIDCALL
);
2303 case D3DSBT_VERTEXSTATE
: type
= NINESBT_VERTEXSTATE
; break;
2304 case D3DSBT_PIXELSTATE
: type
= NINESBT_PIXELSTATE
; break;
2310 hr
= NineStateBlock9_new(This
, &nsb
, type
);
2313 *ppSB
= (IDirect3DStateBlock9
*)nsb
;
2316 dst
->changed
.group
=
2317 NINE_STATE_TEXTURE
|
2320 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_VERTEXSTATE
) {
2321 dst
->changed
.group
|=
2322 NINE_STATE_FF_LIGHTING
|
2323 NINE_STATE_VS
| NINE_STATE_VS_CONST
|
2325 /* TODO: texture/sampler state */
2326 memcpy(dst
->changed
.rs
,
2327 nine_render_states_vertex
, sizeof(dst
->changed
.rs
));
2328 nine_ranges_insert(&dst
->changed
.vs_const_f
, 0, This
->may_swvp
? NINE_MAX_CONST_F_SWVP
: This
->max_vs_const_f
,
2330 nine_ranges_insert(&dst
->changed
.vs_const_i
, 0, This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
,
2332 nine_ranges_insert(&dst
->changed
.vs_const_b
, 0, This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
,
2334 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2335 dst
->changed
.sampler
[s
] |= 1 << D3DSAMP_DMAPOFFSET
;
2336 if (This
->state
.ff
.num_lights
) {
2337 dst
->ff
.num_lights
= This
->state
.ff
.num_lights
;
2338 /* zero'd -> light type won't be NINED3DLIGHT_INVALID, so
2339 * all currently existing lights will be captured
2341 dst
->ff
.light
= CALLOC(This
->state
.ff
.num_lights
,
2343 if (!dst
->ff
.light
) {
2344 nine_bind(ppSB
, NULL
);
2345 return E_OUTOFMEMORY
;
2349 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_PIXELSTATE
) {
2350 dst
->changed
.group
|=
2351 NINE_STATE_PS
| NINE_STATE_PS_CONST
| NINE_STATE_BLEND
|
2352 NINE_STATE_FF_OTHER
| NINE_STATE_FF_PSSTAGES
| NINE_STATE_PS_CONST
|
2353 NINE_STATE_FB
| NINE_STATE_DSA
| NINE_STATE_MULTISAMPLE
|
2354 NINE_STATE_RASTERIZER
| NINE_STATE_STENCIL_REF
;
2355 memcpy(dst
->changed
.rs
,
2356 nine_render_states_pixel
, sizeof(dst
->changed
.rs
));
2357 nine_ranges_insert(&dst
->changed
.ps_const_f
, 0, This
->max_ps_const_f
,
2359 dst
->changed
.ps_const_i
= 0xffff;
2360 dst
->changed
.ps_const_b
= 0xffff;
2361 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2362 dst
->changed
.sampler
[s
] |= 0x1ffe;
2363 for (s
= 0; s
< NINE_MAX_TEXTURE_STAGES
; ++s
) {
2364 dst
->ff
.changed
.tex_stage
[s
][0] |= 0xffffffff;
2365 dst
->ff
.changed
.tex_stage
[s
][1] |= 0xffffffff;
2368 if (Type
== D3DSBT_ALL
) {
2369 dst
->changed
.group
|=
2370 NINE_STATE_VIEWPORT
|
2371 NINE_STATE_SCISSOR
|
2372 NINE_STATE_RASTERIZER
|
2376 NINE_STATE_MATERIAL
|
2377 NINE_STATE_BLEND_COLOR
|
2378 NINE_STATE_SAMPLE_MASK
;
2379 memset(dst
->changed
.rs
, ~0, (D3DRS_COUNT
/ 32) * sizeof(uint32_t));
2380 dst
->changed
.rs
[D3DRS_LAST
/ 32] |= (1 << (D3DRS_COUNT
% 32)) - 1;
2381 dst
->changed
.vtxbuf
= (1ULL << This
->caps
.MaxStreams
) - 1;
2382 dst
->changed
.stream_freq
= dst
->changed
.vtxbuf
;
2383 dst
->changed
.ucp
= (1 << PIPE_MAX_CLIP_PLANES
) - 1;
2384 dst
->changed
.texture
= (1 << NINE_MAX_SAMPLERS
) - 1;
2386 NineStateBlock9_Capture(NineStateBlock9(*ppSB
));
2388 /* TODO: fixed function state */
2394 NineDevice9_BeginStateBlock( struct NineDevice9
*This
)
2398 DBG("This=%p\n", This
);
2400 user_assert(!This
->record
, D3DERR_INVALIDCALL
);
2402 hr
= NineStateBlock9_new(This
, &This
->record
, NINESBT_CUSTOM
);
2405 NineUnknown_ConvertRefToBind(NineUnknown(This
->record
));
2407 This
->update
= &This
->record
->state
;
2408 This
->is_recording
= TRUE
;
2414 NineDevice9_EndStateBlock( struct NineDevice9
*This
,
2415 IDirect3DStateBlock9
**ppSB
)
2417 DBG("This=%p ppSB=%p\n", This
, ppSB
);
2419 user_assert(This
->record
, D3DERR_INVALIDCALL
);
2421 This
->update
= &This
->state
;
2422 This
->is_recording
= FALSE
;
2424 NineUnknown_AddRef(NineUnknown(This
->record
));
2425 *ppSB
= (IDirect3DStateBlock9
*)This
->record
;
2426 NineUnknown_Unbind(NineUnknown(This
->record
));
2427 This
->record
= NULL
;
2433 NineDevice9_SetClipStatus( struct NineDevice9
*This
,
2434 const D3DCLIPSTATUS9
*pClipStatus
)
2436 STUB(D3DERR_INVALIDCALL
);
2440 NineDevice9_GetClipStatus( struct NineDevice9
*This
,
2441 D3DCLIPSTATUS9
*pClipStatus
)
2443 STUB(D3DERR_INVALIDCALL
);
2447 NineDevice9_GetTexture( struct NineDevice9
*This
,
2449 IDirect3DBaseTexture9
**ppTexture
)
2451 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2452 Stage
== D3DDMAPSAMPLER
||
2453 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2454 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2455 user_assert(ppTexture
, D3DERR_INVALIDCALL
);
2457 if (Stage
>= D3DDMAPSAMPLER
)
2458 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2460 *ppTexture
= (IDirect3DBaseTexture9
*)This
->state
.texture
[Stage
];
2462 if (This
->state
.texture
[Stage
])
2463 NineUnknown_AddRef(NineUnknown(This
->state
.texture
[Stage
]));
2468 NineDevice9_SetTexture( struct NineDevice9
*This
,
2470 IDirect3DBaseTexture9
*pTexture
)
2472 struct nine_state
*state
= This
->update
;
2473 struct NineBaseTexture9
*tex
= NineBaseTexture9(pTexture
);
2474 struct NineBaseTexture9
*old
;
2476 DBG("This=%p Stage=%u pTexture=%p\n", This
, Stage
, pTexture
);
2478 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2479 Stage
== D3DDMAPSAMPLER
||
2480 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2481 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2482 user_assert(!tex
|| (tex
->base
.pool
!= D3DPOOL_SCRATCH
&&
2483 tex
->base
.pool
!= D3DPOOL_SYSTEMMEM
), D3DERR_INVALIDCALL
);
2485 if (Stage
>= D3DDMAPSAMPLER
)
2486 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2488 if (This
->is_recording
) {
2489 state
->changed
.texture
|= 1 << Stage
;
2490 state
->changed
.group
|= NINE_STATE_TEXTURE
;
2491 nine_bind(&state
->texture
[Stage
], pTexture
);
2495 old
= state
->texture
[Stage
];
2499 NineBindTextureToDevice(This
, &state
->texture
[Stage
], tex
);
2501 nine_context_set_texture(This
, Stage
, tex
);
2507 NineDevice9_GetTextureStageState( struct NineDevice9
*This
,
2509 D3DTEXTURESTAGESTATETYPE Type
,
2512 const struct nine_state
*state
= &This
->state
;
2514 user_assert(Stage
< ARRAY_SIZE(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2515 user_assert(Type
< ARRAY_SIZE(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2517 *pValue
= state
->ff
.tex_stage
[Stage
][Type
];
2523 NineDevice9_SetTextureStageState( struct NineDevice9
*This
,
2525 D3DTEXTURESTAGESTATETYPE Type
,
2528 struct nine_state
*state
= This
->update
;
2530 DBG("Stage=%u Type=%u Value=%08x\n", Stage
, Type
, Value
);
2531 nine_dump_D3DTSS_value(DBG_FF
, Type
, Value
);
2533 user_assert(Stage
< ARRAY_SIZE(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2534 user_assert(Type
< ARRAY_SIZE(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2536 state
->ff
.tex_stage
[Stage
][Type
] = Value
;
2538 if (unlikely(This
->is_recording
)) {
2539 if (Type
== D3DTSS_TEXTURETRANSFORMFLAGS
)
2540 state
->changed
.group
|= NINE_STATE_PS1X_SHADER
;
2541 state
->changed
.group
|= NINE_STATE_FF_PSSTAGES
;
2542 state
->ff
.changed
.tex_stage
[Stage
][Type
/ 32] |= 1 << (Type
% 32);
2544 nine_context_set_texture_stage_state(This
, Stage
, Type
, Value
);
2550 NineDevice9_GetSamplerState( struct NineDevice9
*This
,
2552 D3DSAMPLERSTATETYPE Type
,
2555 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2556 Sampler
== D3DDMAPSAMPLER
||
2557 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2558 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2560 if (Sampler
>= D3DDMAPSAMPLER
)
2561 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2563 *pValue
= This
->state
.samp_advertised
[Sampler
][Type
];
2568 NineDevice9_SetSamplerState( struct NineDevice9
*This
,
2570 D3DSAMPLERSTATETYPE Type
,
2573 struct nine_state
*state
= This
->update
;
2575 DBG("This=%p Sampler=%u Type=%s Value=%08x\n", This
,
2576 Sampler
, nine_D3DSAMP_to_str(Type
), Value
);
2578 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2579 Sampler
== D3DDMAPSAMPLER
||
2580 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2581 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2583 if (Sampler
>= D3DDMAPSAMPLER
)
2584 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2586 if (unlikely(This
->is_recording
)) {
2587 state
->samp_advertised
[Sampler
][Type
] = Value
;
2588 state
->changed
.group
|= NINE_STATE_SAMPLER
;
2589 state
->changed
.sampler
[Sampler
] |= 1 << Type
;
2593 if (state
->samp_advertised
[Sampler
][Type
] == Value
)
2596 state
->samp_advertised
[Sampler
][Type
] = Value
;
2597 nine_context_set_sampler_state(This
, Sampler
, Type
, Value
);
2603 NineDevice9_ValidateDevice( struct NineDevice9
*This
,
2606 const struct nine_state
*state
= &This
->state
;
2608 unsigned w
= 0, h
= 0;
2610 DBG("This=%p pNumPasses=%p\n", This
, pNumPasses
);
2612 for (i
= 0; i
< ARRAY_SIZE(state
->samp_advertised
); ++i
) {
2613 if (state
->samp_advertised
[i
][D3DSAMP_MINFILTER
] == D3DTEXF_NONE
||
2614 state
->samp_advertised
[i
][D3DSAMP_MAGFILTER
] == D3DTEXF_NONE
)
2615 return D3DERR_UNSUPPORTEDTEXTUREFILTER
;
2618 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2622 w
= state
->rt
[i
]->desc
.Width
;
2623 h
= state
->rt
[i
]->desc
.Height
;
2625 if (state
->rt
[i
]->desc
.Width
!= w
|| state
->rt
[i
]->desc
.Height
!= h
) {
2626 return D3DERR_CONFLICTINGRENDERSTATE
;
2630 (state
->rs_advertised
[D3DRS_ZENABLE
] || state
->rs_advertised
[D3DRS_STENCILENABLE
])) {
2632 (state
->ds
->desc
.Width
!= w
|| state
->ds
->desc
.Height
!= h
))
2633 return D3DERR_CONFLICTINGRENDERSTATE
;
2643 NineDevice9_SetPaletteEntries( struct NineDevice9
*This
,
2645 const PALETTEENTRY
*pEntries
)
2647 STUB(D3D_OK
); /* like wine */
2651 NineDevice9_GetPaletteEntries( struct NineDevice9
*This
,
2653 PALETTEENTRY
*pEntries
)
2655 STUB(D3DERR_INVALIDCALL
);
2659 NineDevice9_SetCurrentTexturePalette( struct NineDevice9
*This
,
2660 UINT PaletteNumber
)
2662 STUB(D3D_OK
); /* like wine */
2666 NineDevice9_GetCurrentTexturePalette( struct NineDevice9
*This
,
2667 UINT
*PaletteNumber
)
2669 STUB(D3DERR_INVALIDCALL
);
2673 NineDevice9_SetScissorRect( struct NineDevice9
*This
,
2676 struct nine_state
*state
= This
->update
;
2678 DBG("x=(%u..%u) y=(%u..%u)\n",
2679 pRect
->left
, pRect
->top
, pRect
->right
, pRect
->bottom
);
2681 state
->scissor
.minx
= pRect
->left
;
2682 state
->scissor
.miny
= pRect
->top
;
2683 state
->scissor
.maxx
= pRect
->right
;
2684 state
->scissor
.maxy
= pRect
->bottom
;
2686 if (unlikely(This
->is_recording
))
2687 state
->changed
.group
|= NINE_STATE_SCISSOR
;
2689 nine_context_set_scissor(This
, &state
->scissor
);
2695 NineDevice9_GetScissorRect( struct NineDevice9
*This
,
2698 pRect
->left
= This
->state
.scissor
.minx
;
2699 pRect
->top
= This
->state
.scissor
.miny
;
2700 pRect
->right
= This
->state
.scissor
.maxx
;
2701 pRect
->bottom
= This
->state
.scissor
.maxy
;
2707 NineDevice9_SetSoftwareVertexProcessing( struct NineDevice9
*This
,
2710 if (This
->params
.BehaviorFlags
& D3DCREATE_MIXED_VERTEXPROCESSING
) {
2711 This
->swvp
= bSoftware
;
2712 nine_context_set_swvp(This
, bSoftware
);
2715 return D3DERR_INVALIDCALL
; /* msdn. TODO: check in practice */
2719 NineDevice9_GetSoftwareVertexProcessing( struct NineDevice9
*This
)
2725 NineDevice9_SetNPatchMode( struct NineDevice9
*This
,
2728 return D3D_OK
; /* Nothing to do because we don't advertise NPatch support */
2732 NineDevice9_GetNPatchMode( struct NineDevice9
*This
)
2737 /* TODO: only go through dirty textures */
2739 validate_textures(struct NineDevice9
*device
)
2741 struct NineBaseTexture9
*tex
, *ptr
;
2742 LIST_FOR_EACH_ENTRY_SAFE(tex
, ptr
, &device
->update_textures
, list
) {
2743 list_delinit(&tex
->list
);
2744 NineBaseTexture9_Validate(tex
);
2749 update_managed_buffers(struct NineDevice9
*device
)
2751 struct NineBuffer9
*buf
, *ptr
;
2752 LIST_FOR_EACH_ENTRY_SAFE(buf
, ptr
, &device
->update_buffers
, managed
.list
) {
2753 list_delinit(&buf
->managed
.list
);
2754 NineBuffer9_Upload(buf
);
2759 NineBeforeDraw( struct NineDevice9
*This
)
2761 /* Upload Managed dirty content */
2762 validate_textures(This
); /* may clobber state */
2763 update_managed_buffers(This
);
2767 NineAfterDraw( struct NineDevice9
*This
)
2770 struct nine_state
*state
= &This
->state
;
2771 unsigned ps_mask
= state
->ps
? state
->ps
->rt_mask
: 1;
2773 /* Flag render-targets with autogenmipmap for mipmap regeneration */
2774 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2775 struct NineSurface9
*rt
= state
->rt
[i
];
2777 if (rt
&& rt
->desc
.Format
!= D3DFMT_NULL
&& (ps_mask
& (1 << i
)) &&
2778 rt
->desc
.Usage
& D3DUSAGE_AUTOGENMIPMAP
) {
2779 assert(rt
->texture
== D3DRTYPE_TEXTURE
||
2780 rt
->texture
== D3DRTYPE_CUBETEXTURE
);
2781 NineBaseTexture9(rt
->base
.base
.container
)->dirty_mip
= TRUE
;
2787 NineDevice9_DrawPrimitive( struct NineDevice9
*This
,
2788 D3DPRIMITIVETYPE PrimitiveType
,
2790 UINT PrimitiveCount
)
2792 DBG("iface %p, PrimitiveType %u, StartVertex %u, PrimitiveCount %u\n",
2793 This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2795 NineBeforeDraw(This
);
2796 nine_context_draw_primitive(This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2797 NineAfterDraw(This
);
2803 NineDevice9_DrawIndexedPrimitive( struct NineDevice9
*This
,
2804 D3DPRIMITIVETYPE PrimitiveType
,
2805 INT BaseVertexIndex
,
2806 UINT MinVertexIndex
,
2809 UINT PrimitiveCount
)
2811 DBG("iface %p, PrimitiveType %u, BaseVertexIndex %u, MinVertexIndex %u "
2812 "NumVertices %u, StartIndex %u, PrimitiveCount %u\n",
2813 This
, PrimitiveType
, BaseVertexIndex
, MinVertexIndex
, NumVertices
,
2814 StartIndex
, PrimitiveCount
);
2816 user_assert(This
->state
.idxbuf
, D3DERR_INVALIDCALL
);
2817 user_assert(This
->state
.vdecl
, D3DERR_INVALIDCALL
);
2819 NineBeforeDraw(This
);
2820 nine_context_draw_indexed_primitive(This
, PrimitiveType
, BaseVertexIndex
,
2821 MinVertexIndex
, NumVertices
, StartIndex
,
2823 NineAfterDraw(This
);
2829 NineDevice9_DrawPrimitiveUP( struct NineDevice9
*This
,
2830 D3DPRIMITIVETYPE PrimitiveType
,
2831 UINT PrimitiveCount
,
2832 const void *pVertexStreamZeroData
,
2833 UINT VertexStreamZeroStride
)
2835 struct pipe_vertex_buffer vtxbuf
;
2837 DBG("iface %p, PrimitiveType %u, PrimitiveCount %u, data %p, stride %u\n",
2838 This
, PrimitiveType
, PrimitiveCount
,
2839 pVertexStreamZeroData
, VertexStreamZeroStride
);
2841 user_assert(pVertexStreamZeroData
&& VertexStreamZeroStride
,
2842 D3DERR_INVALIDCALL
);
2843 user_assert(PrimitiveCount
, D3D_OK
);
2845 vtxbuf
.stride
= VertexStreamZeroStride
;
2846 vtxbuf
.buffer_offset
= 0;
2847 vtxbuf
.buffer
= NULL
;
2848 vtxbuf
.user_buffer
= pVertexStreamZeroData
;
2850 if (!This
->driver_caps
.user_vbufs
) {
2851 u_upload_data(This
->vertex_uploader
,
2853 (prim_count_to_vertex_count(PrimitiveType
, PrimitiveCount
)) * VertexStreamZeroStride
, /* XXX */
2856 &vtxbuf
.buffer_offset
,
2858 u_upload_unmap(This
->vertex_uploader
);
2859 vtxbuf
.user_buffer
= NULL
;
2862 NineBeforeDraw(This
);
2863 nine_context_draw_primitive_from_vtxbuf(This
, PrimitiveType
, PrimitiveCount
, &vtxbuf
);
2864 NineAfterDraw(This
);
2866 pipe_resource_reference(&vtxbuf
.buffer
, NULL
);
2868 NineDevice9_PauseRecording(This
);
2869 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
2870 NineDevice9_ResumeRecording(This
);
2876 NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9
*This
,
2877 D3DPRIMITIVETYPE PrimitiveType
,
2878 UINT MinVertexIndex
,
2880 UINT PrimitiveCount
,
2881 const void *pIndexData
,
2882 D3DFORMAT IndexDataFormat
,
2883 const void *pVertexStreamZeroData
,
2884 UINT VertexStreamZeroStride
)
2886 struct pipe_vertex_buffer vbuf
;
2887 struct pipe_index_buffer ibuf
;
2889 DBG("iface %p, PrimitiveType %u, MinVertexIndex %u, NumVertices %u "
2890 "PrimitiveCount %u, pIndexData %p, IndexDataFormat %u "
2891 "pVertexStreamZeroData %p, VertexStreamZeroStride %u\n",
2892 This
, PrimitiveType
, MinVertexIndex
, NumVertices
, PrimitiveCount
,
2893 pIndexData
, IndexDataFormat
,
2894 pVertexStreamZeroData
, VertexStreamZeroStride
);
2896 user_assert(pIndexData
&& pVertexStreamZeroData
, D3DERR_INVALIDCALL
);
2897 user_assert(VertexStreamZeroStride
, D3DERR_INVALIDCALL
);
2898 user_assert(IndexDataFormat
== D3DFMT_INDEX16
||
2899 IndexDataFormat
== D3DFMT_INDEX32
, D3DERR_INVALIDCALL
);
2900 user_assert(PrimitiveCount
, D3D_OK
);
2902 vbuf
.stride
= VertexStreamZeroStride
;
2903 vbuf
.buffer_offset
= 0;
2905 vbuf
.user_buffer
= pVertexStreamZeroData
;
2907 ibuf
.index_size
= (IndexDataFormat
== D3DFMT_INDEX16
) ? 2 : 4;
2910 ibuf
.user_buffer
= pIndexData
;
2912 if (!This
->driver_caps
.user_vbufs
) {
2913 const unsigned base
= MinVertexIndex
* VertexStreamZeroStride
;
2914 u_upload_data(This
->vertex_uploader
,
2916 NumVertices
* VertexStreamZeroStride
, /* XXX */
2918 (const uint8_t *)vbuf
.user_buffer
+ base
,
2919 &vbuf
.buffer_offset
,
2921 u_upload_unmap(This
->vertex_uploader
);
2922 /* Won't be used: */
2923 vbuf
.buffer_offset
-= base
;
2924 vbuf
.user_buffer
= NULL
;
2926 if (!This
->driver_caps
.user_ibufs
) {
2927 u_upload_data(This
->index_uploader
,
2929 (prim_count_to_vertex_count(PrimitiveType
, PrimitiveCount
)) * ibuf
.index_size
,
2934 u_upload_unmap(This
->index_uploader
);
2935 ibuf
.user_buffer
= NULL
;
2938 NineBeforeDraw(This
);
2939 nine_context_draw_indexed_primitive_from_vtxbuf_idxbuf(This
, PrimitiveType
,
2945 NineAfterDraw(This
);
2947 pipe_resource_reference(&vbuf
.buffer
, NULL
);
2948 pipe_resource_reference(&ibuf
.buffer
, NULL
);
2950 NineDevice9_PauseRecording(This
);
2951 NineDevice9_SetIndices(This
, NULL
);
2952 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
2953 NineDevice9_ResumeRecording(This
);
2959 NineDevice9_ProcessVertices( struct NineDevice9
*This
,
2963 IDirect3DVertexBuffer9
*pDestBuffer
,
2964 IDirect3DVertexDeclaration9
*pVertexDecl
,
2967 struct pipe_screen
*screen_sw
= This
->screen_sw
;
2968 struct pipe_context
*pipe_sw
= This
->pipe_sw
;
2969 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pVertexDecl
);
2970 struct NineVertexBuffer9
*dst
= NineVertexBuffer9(pDestBuffer
);
2971 struct NineVertexShader9
*vs
;
2972 struct pipe_resource
*resource
;
2973 struct pipe_transfer
*transfer
= NULL
;
2974 struct pipe_stream_output_info so
;
2975 struct pipe_stream_output_target
*target
;
2976 struct pipe_draw_info draw
;
2977 struct pipe_box box
;
2978 bool programmable_vs
= This
->state
.vs
&& !(This
->state
.vdecl
&& This
->state
.vdecl
->position_t
);
2979 unsigned offsets
[1] = {0};
2981 unsigned buffer_size
;
2984 DBG("This=%p SrcStartIndex=%u DestIndex=%u VertexCount=%u "
2985 "pDestBuffer=%p pVertexDecl=%p Flags=%d\n",
2986 This
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
,
2987 pVertexDecl
, Flags
);
2989 if (!screen_sw
->get_param(screen_sw
, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
)) {
2990 DBG("ProcessVertices not supported\n");
2991 return D3DERR_INVALIDCALL
;
2995 vs
= programmable_vs
? This
->state
.vs
: This
->ff
.vs
;
2996 /* Note: version is 0 for ff */
2997 user_assert(vdecl
|| (vs
->byte_code
.version
< 0x30 && dst
->desc
.FVF
),
2998 D3DERR_INVALIDCALL
);
3000 DWORD FVF
= dst
->desc
.FVF
;
3001 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
3003 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
3007 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
3008 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
3012 /* Flags: Can be 0 or D3DPV_DONOTCOPYDATA, and/or lock flags
3013 * D3DPV_DONOTCOPYDATA -> Has effect only for ff. In particular
3014 * if not set, everything from src will be used, and dst
3015 * must match exactly the ff vs outputs.
3016 * TODO: Handle all the checks, etc for ff */
3017 user_assert(vdecl
->position_t
|| programmable_vs
,
3018 D3DERR_INVALIDCALL
);
3020 /* TODO: Support vs < 3 and ff */
3021 user_assert(vs
->byte_code
.version
== 0x30,
3022 D3DERR_INVALIDCALL
);
3023 /* TODO: Not hardcode the constant buffers for swvp */
3024 user_assert(This
->may_swvp
,
3025 D3DERR_INVALIDCALL
);
3027 nine_state_prepare_draw_sw(This
, vdecl
, SrcStartIndex
, VertexCount
, &so
);
3029 buffer_size
= VertexCount
* so
.stride
[0] * 4;
3031 struct pipe_resource templ
;
3033 memset(&templ
, 0, sizeof(templ
));
3034 templ
.target
= PIPE_BUFFER
;
3035 templ
.format
= PIPE_FORMAT_R8_UNORM
;
3036 templ
.width0
= buffer_size
;
3038 templ
.bind
= PIPE_BIND_STREAM_OUTPUT
;
3039 templ
.usage
= PIPE_USAGE_STREAM
;
3040 templ
.height0
= templ
.depth0
= templ
.array_size
= 1;
3041 templ
.last_level
= templ
.nr_samples
= 0;
3043 resource
= screen_sw
->resource_create(screen_sw
, &templ
);
3045 return E_OUTOFMEMORY
;
3047 target
= pipe_sw
->create_stream_output_target(pipe_sw
, resource
,
3050 pipe_resource_reference(&resource
, NULL
);
3051 return D3DERR_DRIVERINTERNALERROR
;
3054 draw
.mode
= PIPE_PRIM_POINTS
;
3055 draw
.count
= VertexCount
;
3056 draw
.start_instance
= 0;
3057 draw
.primitive_restart
= FALSE
;
3058 draw
.restart_index
= 0;
3059 draw
.count_from_stream_output
= NULL
;
3060 draw
.indirect
= NULL
;
3061 draw
.indirect_params
= NULL
;
3062 draw
.instance_count
= 1;
3063 draw
.indexed
= FALSE
;
3065 draw
.index_bias
= 0;
3067 draw
.max_index
= VertexCount
- 1;
3070 pipe_sw
->set_stream_output_targets(pipe_sw
, 1, &target
, offsets
);
3072 pipe_sw
->draw_vbo(pipe_sw
, &draw
);
3074 pipe_sw
->set_stream_output_targets(pipe_sw
, 0, NULL
, 0);
3075 pipe_sw
->stream_output_target_destroy(pipe_sw
, target
);
3077 u_box_1d(0, VertexCount
* so
.stride
[0] * 4, &box
);
3078 map
= pipe_sw
->transfer_map(pipe_sw
, resource
, 0, PIPE_TRANSFER_READ
, &box
,
3081 hr
= D3DERR_DRIVERINTERNALERROR
;
3085 hr
= NineVertexDeclaration9_ConvertStreamOutput(vdecl
,
3086 dst
, DestIndex
, VertexCount
,
3089 pipe_sw
->transfer_unmap(pipe_sw
, transfer
);
3092 nine_state_after_draw_sw(This
);
3093 pipe_resource_reference(&resource
, NULL
);
3098 NineDevice9_CreateVertexDeclaration( struct NineDevice9
*This
,
3099 const D3DVERTEXELEMENT9
*pVertexElements
,
3100 IDirect3DVertexDeclaration9
**ppDecl
)
3102 struct NineVertexDeclaration9
*vdecl
;
3104 DBG("This=%p pVertexElements=%p ppDecl=%p\n",
3105 This
, pVertexElements
, ppDecl
);
3107 HRESULT hr
= NineVertexDeclaration9_new(This
, pVertexElements
, &vdecl
);
3109 *ppDecl
= (IDirect3DVertexDeclaration9
*)vdecl
;
3115 NineDevice9_SetVertexDeclaration( struct NineDevice9
*This
,
3116 IDirect3DVertexDeclaration9
*pDecl
)
3118 struct nine_state
*state
= This
->update
;
3119 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pDecl
);
3121 DBG("This=%p pDecl=%p\n", This
, pDecl
);
3123 if (unlikely(This
->is_recording
)) {
3124 nine_bind(&state
->vdecl
, vdecl
);
3125 state
->changed
.group
|= NINE_STATE_VDECL
;
3129 if (state
->vdecl
== vdecl
)
3132 nine_bind(&state
->vdecl
, vdecl
);
3134 nine_context_set_vertex_declaration(This
, vdecl
);
3140 NineDevice9_GetVertexDeclaration( struct NineDevice9
*This
,
3141 IDirect3DVertexDeclaration9
**ppDecl
)
3143 user_assert(ppDecl
, D3DERR_INVALIDCALL
);
3145 *ppDecl
= (IDirect3DVertexDeclaration9
*)This
->state
.vdecl
;
3147 NineUnknown_AddRef(NineUnknown(*ppDecl
));
3152 NineDevice9_SetFVF( struct NineDevice9
*This
,
3155 struct NineVertexDeclaration9
*vdecl
;
3158 DBG("FVF = %08x\n", FVF
);
3160 return D3D_OK
; /* like wine */
3162 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
3164 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
3168 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
3169 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
3171 return NineDevice9_SetVertexDeclaration(
3172 This
, (IDirect3DVertexDeclaration9
*)vdecl
);
3176 NineDevice9_GetFVF( struct NineDevice9
*This
,
3179 *pFVF
= This
->state
.vdecl
? This
->state
.vdecl
->fvf
: 0;
3184 NineDevice9_CreateVertexShader( struct NineDevice9
*This
,
3185 const DWORD
*pFunction
,
3186 IDirect3DVertexShader9
**ppShader
)
3188 struct NineVertexShader9
*vs
;
3191 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3193 hr
= NineVertexShader9_new(This
, &vs
, pFunction
, NULL
);
3196 *ppShader
= (IDirect3DVertexShader9
*)vs
;
3201 NineDevice9_SetVertexShader( struct NineDevice9
*This
,
3202 IDirect3DVertexShader9
*pShader
)
3204 struct nine_state
*state
= This
->update
;
3205 struct NineVertexShader9
*vs_shader
= (struct NineVertexShader9
*)pShader
;
3207 DBG("This=%p pShader=%p\n", This
, pShader
);
3209 if (unlikely(This
->is_recording
)) {
3210 nine_bind(&state
->vs
, vs_shader
);
3211 state
->changed
.group
|= NINE_STATE_VS
;
3215 if (state
->vs
== vs_shader
)
3218 nine_bind(&state
->vs
, vs_shader
);
3220 nine_context_set_vertex_shader(This
, vs_shader
);
3226 NineDevice9_GetVertexShader( struct NineDevice9
*This
,
3227 IDirect3DVertexShader9
**ppShader
)
3229 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3230 nine_reference_set(ppShader
, This
->state
.vs
);
3235 NineDevice9_SetVertexShaderConstantF( struct NineDevice9
*This
,
3237 const float *pConstantData
,
3238 UINT Vector4fCount
)
3240 struct nine_state
*state
= This
->update
;
3241 float *vs_const_f
= state
->vs_const_f
;
3243 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3244 This
, StartRegister
, pConstantData
, Vector4fCount
);
3246 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3247 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3251 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3253 if (unlikely(This
->is_recording
)) {
3254 memcpy(&vs_const_f
[StartRegister
* 4],
3256 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3258 nine_ranges_insert(&state
->changed
.vs_const_f
,
3259 StartRegister
, StartRegister
+ Vector4fCount
,
3262 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3267 if (!memcmp(&vs_const_f
[StartRegister
* 4], pConstantData
,
3268 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0])))
3271 memcpy(&vs_const_f
[StartRegister
* 4],
3273 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3275 nine_context_set_vertex_shader_constant_f(This
, StartRegister
, pConstantData
,
3276 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]),
3283 NineDevice9_GetVertexShaderConstantF( struct NineDevice9
*This
,
3285 float *pConstantData
,
3286 UINT Vector4fCount
)
3288 const struct nine_state
*state
= &This
->state
;
3290 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3291 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
3292 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3294 memcpy(pConstantData
,
3295 &state
->vs_const_f
[StartRegister
* 4],
3296 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
3302 NineDevice9_SetVertexShaderConstantI( struct NineDevice9
*This
,
3304 const int *pConstantData
,
3305 UINT Vector4iCount
)
3307 struct nine_state
*state
= This
->update
;
3310 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3311 This
, StartRegister
, pConstantData
, Vector4iCount
);
3313 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3314 D3DERR_INVALIDCALL
);
3315 user_assert(StartRegister
+ Vector4iCount
<= (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3316 D3DERR_INVALIDCALL
);
3317 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3319 if (This
->driver_caps
.vs_integer
) {
3320 if (!This
->is_recording
) {
3321 if (!memcmp(&state
->vs_const_i
[4 * StartRegister
], pConstantData
,
3322 Vector4iCount
* sizeof(int[4])))
3325 memcpy(&state
->vs_const_i
[4 * StartRegister
],
3327 Vector4iCount
* sizeof(int[4]));
3329 for (i
= 0; i
< Vector4iCount
; i
++) {
3330 state
->vs_const_i
[4 * (StartRegister
+ i
)] = fui((float)(pConstantData
[4 * i
]));
3331 state
->vs_const_i
[4 * (StartRegister
+ i
) + 1] = fui((float)(pConstantData
[4 * i
+ 1]));
3332 state
->vs_const_i
[4 * (StartRegister
+ i
) + 2] = fui((float)(pConstantData
[4 * i
+ 2]));
3333 state
->vs_const_i
[4 * (StartRegister
+ i
) + 3] = fui((float)(pConstantData
[4 * i
+ 3]));
3337 if (unlikely(This
->is_recording
)) {
3338 nine_ranges_insert(&state
->changed
.vs_const_i
,
3339 StartRegister
, StartRegister
+ Vector4iCount
,
3341 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3343 nine_context_set_vertex_shader_constant_i(This
, StartRegister
, pConstantData
,
3344 Vector4iCount
* sizeof(int[4]), Vector4iCount
);
3350 NineDevice9_GetVertexShaderConstantI( struct NineDevice9
*This
,
3353 UINT Vector4iCount
)
3355 const struct nine_state
*state
= &This
->state
;
3358 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3359 D3DERR_INVALIDCALL
);
3360 user_assert(StartRegister
+ Vector4iCount
<= (This
->may_swvp
? NINE_MAX_CONST_I_SWVP
: NINE_MAX_CONST_I
),
3361 D3DERR_INVALIDCALL
);
3362 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3364 if (This
->driver_caps
.vs_integer
) {
3365 memcpy(pConstantData
,
3366 &state
->vs_const_i
[4 * StartRegister
],
3367 Vector4iCount
* sizeof(int[4]));
3369 for (i
= 0; i
< Vector4iCount
; i
++) {
3370 pConstantData
[4 * i
] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
)]);
3371 pConstantData
[4 * i
+ 1] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
) + 1]);
3372 pConstantData
[4 * i
+ 2] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
) + 2]);
3373 pConstantData
[4 * i
+ 3] = (int32_t) uif(state
->vs_const_i
[4 * (StartRegister
+ i
) + 3]);
3381 NineDevice9_SetVertexShaderConstantB( struct NineDevice9
*This
,
3383 const BOOL
*pConstantData
,
3386 struct nine_state
*state
= This
->update
;
3388 uint32_t bool_true
= This
->driver_caps
.vs_integer
? 0xFFFFFFFF : fui(1.0f
);
3390 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3391 This
, StartRegister
, pConstantData
, BoolCount
);
3393 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3394 D3DERR_INVALIDCALL
);
3395 user_assert(StartRegister
+ BoolCount
<= (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3396 D3DERR_INVALIDCALL
);
3397 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3399 if (!This
->is_recording
) {
3400 bool noChange
= true;
3401 for (i
= 0; i
< BoolCount
; i
++) {
3402 if (!!state
->vs_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3409 for (i
= 0; i
< BoolCount
; i
++)
3410 state
->vs_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3412 if (unlikely(This
->is_recording
)) {
3413 nine_ranges_insert(&state
->changed
.vs_const_b
,
3414 StartRegister
, StartRegister
+ BoolCount
,
3416 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3418 nine_context_set_vertex_shader_constant_b(This
, StartRegister
, pConstantData
,
3419 sizeof(BOOL
) * BoolCount
, BoolCount
);
3425 NineDevice9_GetVertexShaderConstantB( struct NineDevice9
*This
,
3427 BOOL
*pConstantData
,
3430 const struct nine_state
*state
= &This
->state
;
3433 user_assert(StartRegister
< (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3434 D3DERR_INVALIDCALL
);
3435 user_assert(StartRegister
+ BoolCount
<= (This
->may_swvp
? NINE_MAX_CONST_B_SWVP
: NINE_MAX_CONST_B
),
3436 D3DERR_INVALIDCALL
);
3437 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3439 for (i
= 0; i
< BoolCount
; i
++)
3440 pConstantData
[i
] = state
->vs_const_b
[StartRegister
+ i
] != 0 ? TRUE
: FALSE
;
3446 NineDevice9_SetStreamSource( struct NineDevice9
*This
,
3448 IDirect3DVertexBuffer9
*pStreamData
,
3452 struct nine_state
*state
= This
->update
;
3453 struct NineVertexBuffer9
*pVBuf9
= NineVertexBuffer9(pStreamData
);
3454 const unsigned i
= StreamNumber
;
3456 DBG("This=%p StreamNumber=%u pStreamData=%p OffsetInBytes=%u Stride=%u\n",
3457 This
, StreamNumber
, pStreamData
, OffsetInBytes
, Stride
);
3459 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3460 user_assert(Stride
<= This
->caps
.MaxStreamStride
, D3DERR_INVALIDCALL
);
3462 if (unlikely(This
->is_recording
)) {
3463 nine_bind(&state
->stream
[i
], pStreamData
);
3464 state
->changed
.vtxbuf
|= 1 << StreamNumber
;
3465 state
->vtxbuf
[i
].stride
= Stride
;
3466 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3470 if (state
->stream
[i
] == NineVertexBuffer9(pStreamData
) &&
3471 state
->vtxbuf
[i
].stride
== Stride
&&
3472 state
->vtxbuf
[i
].buffer_offset
== OffsetInBytes
)
3475 state
->vtxbuf
[i
].stride
= Stride
;
3476 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3478 NineBindBufferToDevice(This
,
3479 (struct NineBuffer9
**)&state
->stream
[i
],
3480 (struct NineBuffer9
*)pVBuf9
);
3482 nine_context_set_stream_source(This
,
3492 NineDevice9_GetStreamSource( struct NineDevice9
*This
,
3494 IDirect3DVertexBuffer9
**ppStreamData
,
3495 UINT
*pOffsetInBytes
,
3498 const struct nine_state
*state
= &This
->state
;
3499 const unsigned i
= StreamNumber
;
3501 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3502 user_assert(ppStreamData
, D3DERR_INVALIDCALL
);
3504 nine_reference_set(ppStreamData
, state
->stream
[i
]);
3505 *pStride
= state
->vtxbuf
[i
].stride
;
3506 *pOffsetInBytes
= state
->vtxbuf
[i
].buffer_offset
;
3512 NineDevice9_SetStreamSourceFreq( struct NineDevice9
*This
,
3516 struct nine_state
*state
= This
->update
;
3517 /* const UINT freq = Setting & 0x7FFFFF; */
3519 DBG("This=%p StreamNumber=%u FrequencyParameter=0x%x\n", This
,
3520 StreamNumber
, Setting
);
3522 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3523 user_assert(StreamNumber
!= 0 || !(Setting
& D3DSTREAMSOURCE_INSTANCEDATA
),
3524 D3DERR_INVALIDCALL
);
3525 user_assert(!((Setting
& D3DSTREAMSOURCE_INSTANCEDATA
) &&
3526 (Setting
& D3DSTREAMSOURCE_INDEXEDDATA
)), D3DERR_INVALIDCALL
);
3527 user_assert(Setting
, D3DERR_INVALIDCALL
);
3529 if (unlikely(This
->is_recording
)) {
3530 state
->stream_freq
[StreamNumber
] = Setting
;
3531 state
->changed
.stream_freq
|= 1 << StreamNumber
;
3532 if (StreamNumber
!= 0)
3533 state
->changed
.group
|= NINE_STATE_STREAMFREQ
;
3537 if (state
->stream_freq
[StreamNumber
] == Setting
)
3540 state
->stream_freq
[StreamNumber
] = Setting
;
3542 nine_context_set_stream_source_freq(This
, StreamNumber
, Setting
);
3547 NineDevice9_GetStreamSourceFreq( struct NineDevice9
*This
,
3551 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3552 *pSetting
= This
->state
.stream_freq
[StreamNumber
];
3557 NineDevice9_SetIndices( struct NineDevice9
*This
,
3558 IDirect3DIndexBuffer9
*pIndexData
)
3560 struct nine_state
*state
= This
->update
;
3561 struct NineIndexBuffer9
*idxbuf
= NineIndexBuffer9(pIndexData
);
3563 DBG("This=%p pIndexData=%p\n", This
, pIndexData
);
3565 if (unlikely(This
->is_recording
)) {
3566 nine_bind(&state
->idxbuf
, idxbuf
);
3567 state
->changed
.group
|= NINE_STATE_IDXBUF
;
3571 if (state
->idxbuf
== idxbuf
)
3574 NineBindBufferToDevice(This
,
3575 (struct NineBuffer9
**)&state
->idxbuf
,
3576 (struct NineBuffer9
*)idxbuf
);
3578 nine_context_set_indices(This
, idxbuf
);
3583 /* XXX: wine/d3d9 doesn't have pBaseVertexIndex, and it doesn't make sense
3584 * here because it's an argument passed to the Draw calls.
3587 NineDevice9_GetIndices( struct NineDevice9
*This
,
3588 IDirect3DIndexBuffer9
**ppIndexData
)
3590 user_assert(ppIndexData
, D3DERR_INVALIDCALL
);
3591 nine_reference_set(ppIndexData
, This
->state
.idxbuf
);
3596 NineDevice9_CreatePixelShader( struct NineDevice9
*This
,
3597 const DWORD
*pFunction
,
3598 IDirect3DPixelShader9
**ppShader
)
3600 struct NinePixelShader9
*ps
;
3603 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3605 hr
= NinePixelShader9_new(This
, &ps
, pFunction
, NULL
);
3608 *ppShader
= (IDirect3DPixelShader9
*)ps
;
3613 NineDevice9_SetPixelShader( struct NineDevice9
*This
,
3614 IDirect3DPixelShader9
*pShader
)
3616 struct nine_state
*state
= This
->update
;
3617 struct NinePixelShader9
*ps
= (struct NinePixelShader9
*)pShader
;
3619 DBG("This=%p pShader=%p\n", This
, pShader
);
3621 if (unlikely(This
->is_recording
)) {
3622 /* Technically we need NINE_STATE_FB only
3623 * if the ps mask changes, but put it always
3625 nine_bind(&state
->ps
, pShader
);
3626 state
->changed
.group
|= NINE_STATE_PS
| NINE_STATE_FB
;
3630 if (state
->ps
== ps
)
3633 nine_bind(&state
->ps
, ps
);
3635 nine_context_set_pixel_shader(This
, ps
);
3641 NineDevice9_GetPixelShader( struct NineDevice9
*This
,
3642 IDirect3DPixelShader9
**ppShader
)
3644 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3645 nine_reference_set(ppShader
, This
->state
.ps
);
3650 NineDevice9_SetPixelShaderConstantF( struct NineDevice9
*This
,
3652 const float *pConstantData
,
3653 UINT Vector4fCount
)
3655 struct nine_state
*state
= This
->update
;
3657 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3658 This
, StartRegister
, pConstantData
, Vector4fCount
);
3660 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3661 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3665 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3667 if (unlikely(This
->is_recording
)) {
3668 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3670 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3672 nine_ranges_insert(&state
->changed
.ps_const_f
,
3673 StartRegister
, StartRegister
+ Vector4fCount
,
3676 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3680 if (!memcmp(&state
->ps_const_f
[StartRegister
* 4], pConstantData
,
3681 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0])))
3684 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3686 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3688 nine_context_set_pixel_shader_constant_f(This
, StartRegister
, pConstantData
,
3689 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]),
3696 NineDevice9_GetPixelShaderConstantF( struct NineDevice9
*This
,
3698 float *pConstantData
,
3699 UINT Vector4fCount
)
3701 const struct nine_state
*state
= &This
->state
;
3703 user_assert(StartRegister
< NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3704 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F_PS3
, D3DERR_INVALIDCALL
);
3705 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3707 memcpy(pConstantData
,
3708 &state
->ps_const_f
[StartRegister
* 4],
3709 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3715 NineDevice9_SetPixelShaderConstantI( struct NineDevice9
*This
,
3717 const int *pConstantData
,
3718 UINT Vector4iCount
)
3720 struct nine_state
*state
= This
->update
;
3723 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3724 This
, StartRegister
, pConstantData
, Vector4iCount
);
3726 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3727 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3728 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3730 if (This
->driver_caps
.ps_integer
) {
3731 if (!This
->is_recording
) {
3732 if (!memcmp(&state
->ps_const_i
[StartRegister
][0], pConstantData
,
3733 Vector4iCount
* sizeof(state
->ps_const_i
[0])))
3736 memcpy(&state
->ps_const_i
[StartRegister
][0],
3738 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3740 for (i
= 0; i
< Vector4iCount
; i
++) {
3741 state
->ps_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3742 state
->ps_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3743 state
->ps_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3744 state
->ps_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3748 if (unlikely(This
->is_recording
)) {
3749 state
->changed
.ps_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3750 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3752 nine_context_set_pixel_shader_constant_i(This
, StartRegister
, pConstantData
,
3753 sizeof(state
->ps_const_i
[0]) * Vector4iCount
, Vector4iCount
);
3759 NineDevice9_GetPixelShaderConstantI( struct NineDevice9
*This
,
3762 UINT Vector4iCount
)
3764 const struct nine_state
*state
= &This
->state
;
3767 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3768 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3769 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3771 if (This
->driver_caps
.ps_integer
) {
3772 memcpy(pConstantData
,
3773 &state
->ps_const_i
[StartRegister
][0],
3774 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3776 for (i
= 0; i
< Vector4iCount
; i
++) {
3777 pConstantData
[4*i
] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][0]);
3778 pConstantData
[4*i
+1] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][1]);
3779 pConstantData
[4*i
+2] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][2]);
3780 pConstantData
[4*i
+3] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][3]);
3788 NineDevice9_SetPixelShaderConstantB( struct NineDevice9
*This
,
3790 const BOOL
*pConstantData
,
3793 struct nine_state
*state
= This
->update
;
3795 uint32_t bool_true
= This
->driver_caps
.ps_integer
? 0xFFFFFFFF : fui(1.0f
);
3797 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3798 This
, StartRegister
, pConstantData
, BoolCount
);
3800 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3801 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3802 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3804 if (!This
->is_recording
) {
3805 bool noChange
= true;
3806 for (i
= 0; i
< BoolCount
; i
++) {
3807 if (!!state
->ps_const_b
[StartRegister
+ i
] != !!pConstantData
[i
])
3814 for (i
= 0; i
< BoolCount
; i
++)
3815 state
->ps_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3817 if (unlikely(This
->is_recording
)) {
3818 state
->changed
.ps_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3819 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3821 nine_context_set_pixel_shader_constant_b(This
, StartRegister
, pConstantData
,
3822 sizeof(BOOL
) * BoolCount
, BoolCount
);
3828 NineDevice9_GetPixelShaderConstantB( struct NineDevice9
*This
,
3830 BOOL
*pConstantData
,
3833 const struct nine_state
*state
= &This
->state
;
3836 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3837 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3838 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3840 for (i
= 0; i
< BoolCount
; i
++)
3841 pConstantData
[i
] = state
->ps_const_b
[StartRegister
+ i
] ? TRUE
: FALSE
;
3847 NineDevice9_DrawRectPatch( struct NineDevice9
*This
,
3849 const float *pNumSegs
,
3850 const D3DRECTPATCH_INFO
*pRectPatchInfo
)
3852 STUB(D3DERR_INVALIDCALL
);
3856 NineDevice9_DrawTriPatch( struct NineDevice9
*This
,
3858 const float *pNumSegs
,
3859 const D3DTRIPATCH_INFO
*pTriPatchInfo
)
3861 STUB(D3DERR_INVALIDCALL
);
3865 NineDevice9_DeletePatch( struct NineDevice9
*This
,
3868 STUB(D3DERR_INVALIDCALL
);
3872 NineDevice9_CreateQuery( struct NineDevice9
*This
,
3874 IDirect3DQuery9
**ppQuery
)
3876 struct NineQuery9
*query
;
3879 DBG("This=%p Type=%d ppQuery=%p\n", This
, Type
, ppQuery
);
3881 hr
= nine_is_query_supported(This
->screen
, Type
);
3882 if (!ppQuery
|| hr
!= D3D_OK
)
3885 hr
= NineQuery9_new(This
, &query
, Type
);
3888 *ppQuery
= (IDirect3DQuery9
*)query
;
3892 IDirect3DDevice9Vtbl NineDevice9_vtable
= {
3893 (void *)NineUnknown_QueryInterface
,
3894 (void *)NineUnknown_AddRef
,
3895 (void *)NineUnknown_Release
,
3896 (void *)NineDevice9_TestCooperativeLevel
,
3897 (void *)NineDevice9_GetAvailableTextureMem
,
3898 (void *)NineDevice9_EvictManagedResources
,
3899 (void *)NineDevice9_GetDirect3D
,
3900 (void *)NineDevice9_GetDeviceCaps
,
3901 (void *)NineDevice9_GetDisplayMode
,
3902 (void *)NineDevice9_GetCreationParameters
,
3903 (void *)NineDevice9_SetCursorProperties
,
3904 (void *)NineDevice9_SetCursorPosition
,
3905 (void *)NineDevice9_ShowCursor
,
3906 (void *)NineDevice9_CreateAdditionalSwapChain
,
3907 (void *)NineDevice9_GetSwapChain
,
3908 (void *)NineDevice9_GetNumberOfSwapChains
,
3909 (void *)NineDevice9_Reset
,
3910 (void *)NineDevice9_Present
,
3911 (void *)NineDevice9_GetBackBuffer
,
3912 (void *)NineDevice9_GetRasterStatus
,
3913 (void *)NineDevice9_SetDialogBoxMode
,
3914 (void *)NineDevice9_SetGammaRamp
,
3915 (void *)NineDevice9_GetGammaRamp
,
3916 (void *)NineDevice9_CreateTexture
,
3917 (void *)NineDevice9_CreateVolumeTexture
,
3918 (void *)NineDevice9_CreateCubeTexture
,
3919 (void *)NineDevice9_CreateVertexBuffer
,
3920 (void *)NineDevice9_CreateIndexBuffer
,
3921 (void *)NineDevice9_CreateRenderTarget
,
3922 (void *)NineDevice9_CreateDepthStencilSurface
,
3923 (void *)NineDevice9_UpdateSurface
,
3924 (void *)NineDevice9_UpdateTexture
,
3925 (void *)NineDevice9_GetRenderTargetData
,
3926 (void *)NineDevice9_GetFrontBufferData
,
3927 (void *)NineDevice9_StretchRect
,
3928 (void *)NineDevice9_ColorFill
,
3929 (void *)NineDevice9_CreateOffscreenPlainSurface
,
3930 (void *)NineDevice9_SetRenderTarget
,
3931 (void *)NineDevice9_GetRenderTarget
,
3932 (void *)NineDevice9_SetDepthStencilSurface
,
3933 (void *)NineDevice9_GetDepthStencilSurface
,
3934 (void *)NineDevice9_BeginScene
,
3935 (void *)NineDevice9_EndScene
,
3936 (void *)NineDevice9_Clear
,
3937 (void *)NineDevice9_SetTransform
,
3938 (void *)NineDevice9_GetTransform
,
3939 (void *)NineDevice9_MultiplyTransform
,
3940 (void *)NineDevice9_SetViewport
,
3941 (void *)NineDevice9_GetViewport
,
3942 (void *)NineDevice9_SetMaterial
,
3943 (void *)NineDevice9_GetMaterial
,
3944 (void *)NineDevice9_SetLight
,
3945 (void *)NineDevice9_GetLight
,
3946 (void *)NineDevice9_LightEnable
,
3947 (void *)NineDevice9_GetLightEnable
,
3948 (void *)NineDevice9_SetClipPlane
,
3949 (void *)NineDevice9_GetClipPlane
,
3950 (void *)NineDevice9_SetRenderState
,
3951 (void *)NineDevice9_GetRenderState
,
3952 (void *)NineDevice9_CreateStateBlock
,
3953 (void *)NineDevice9_BeginStateBlock
,
3954 (void *)NineDevice9_EndStateBlock
,
3955 (void *)NineDevice9_SetClipStatus
,
3956 (void *)NineDevice9_GetClipStatus
,
3957 (void *)NineDevice9_GetTexture
,
3958 (void *)NineDevice9_SetTexture
,
3959 (void *)NineDevice9_GetTextureStageState
,
3960 (void *)NineDevice9_SetTextureStageState
,
3961 (void *)NineDevice9_GetSamplerState
,
3962 (void *)NineDevice9_SetSamplerState
,
3963 (void *)NineDevice9_ValidateDevice
,
3964 (void *)NineDevice9_SetPaletteEntries
,
3965 (void *)NineDevice9_GetPaletteEntries
,
3966 (void *)NineDevice9_SetCurrentTexturePalette
,
3967 (void *)NineDevice9_GetCurrentTexturePalette
,
3968 (void *)NineDevice9_SetScissorRect
,
3969 (void *)NineDevice9_GetScissorRect
,
3970 (void *)NineDevice9_SetSoftwareVertexProcessing
,
3971 (void *)NineDevice9_GetSoftwareVertexProcessing
,
3972 (void *)NineDevice9_SetNPatchMode
,
3973 (void *)NineDevice9_GetNPatchMode
,
3974 (void *)NineDevice9_DrawPrimitive
,
3975 (void *)NineDevice9_DrawIndexedPrimitive
,
3976 (void *)NineDevice9_DrawPrimitiveUP
,
3977 (void *)NineDevice9_DrawIndexedPrimitiveUP
,
3978 (void *)NineDevice9_ProcessVertices
,
3979 (void *)NineDevice9_CreateVertexDeclaration
,
3980 (void *)NineDevice9_SetVertexDeclaration
,
3981 (void *)NineDevice9_GetVertexDeclaration
,
3982 (void *)NineDevice9_SetFVF
,
3983 (void *)NineDevice9_GetFVF
,
3984 (void *)NineDevice9_CreateVertexShader
,
3985 (void *)NineDevice9_SetVertexShader
,
3986 (void *)NineDevice9_GetVertexShader
,
3987 (void *)NineDevice9_SetVertexShaderConstantF
,
3988 (void *)NineDevice9_GetVertexShaderConstantF
,
3989 (void *)NineDevice9_SetVertexShaderConstantI
,
3990 (void *)NineDevice9_GetVertexShaderConstantI
,
3991 (void *)NineDevice9_SetVertexShaderConstantB
,
3992 (void *)NineDevice9_GetVertexShaderConstantB
,
3993 (void *)NineDevice9_SetStreamSource
,
3994 (void *)NineDevice9_GetStreamSource
,
3995 (void *)NineDevice9_SetStreamSourceFreq
,
3996 (void *)NineDevice9_GetStreamSourceFreq
,
3997 (void *)NineDevice9_SetIndices
,
3998 (void *)NineDevice9_GetIndices
,
3999 (void *)NineDevice9_CreatePixelShader
,
4000 (void *)NineDevice9_SetPixelShader
,
4001 (void *)NineDevice9_GetPixelShader
,
4002 (void *)NineDevice9_SetPixelShaderConstantF
,
4003 (void *)NineDevice9_GetPixelShaderConstantF
,
4004 (void *)NineDevice9_SetPixelShaderConstantI
,
4005 (void *)NineDevice9_GetPixelShaderConstantI
,
4006 (void *)NineDevice9_SetPixelShaderConstantB
,
4007 (void *)NineDevice9_GetPixelShaderConstantB
,
4008 (void *)NineDevice9_DrawRectPatch
,
4009 (void *)NineDevice9_DrawTriPatch
,
4010 (void *)NineDevice9_DeletePatch
,
4011 (void *)NineDevice9_CreateQuery
4014 static const GUID
*NineDevice9_IIDs
[] = {
4015 &IID_IDirect3DDevice9
,
4021 NineDevice9_new( struct pipe_screen
*pScreen
,
4022 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
4024 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
4026 ID3DPresentGroup
*pPresentationGroup
,
4027 struct d3dadapter9_context
*pCTX
,
4029 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
4030 struct NineDevice9
**ppOut
,
4031 int minorVersionNum
)
4034 lock
= !!(pCreationParameters
->BehaviorFlags
& D3DCREATE_MULTITHREADED
);
4036 NINE_NEW(Device9
, ppOut
, lock
, /* args */
4037 pScreen
, pCreationParameters
, pCaps
,
4038 pPresentationParameters
, pD3D9
, pPresentationGroup
, pCTX
,
4039 ex
, pFullscreenDisplayMode
, minorVersionNum
);