st/nine: Back viewport to nine_context
[mesa.git] / src / gallium / state_trackers / nine / device9.c
1 /*
2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
3 *
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:
10 *
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
13 * Software.
14 *
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. */
22
23 #include "device9.h"
24 #include "stateblock9.h"
25 #include "surface9.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"
33 #include "query9.h"
34 #include "texture9.h"
35 #include "cubetexture9.h"
36 #include "volumetexture9.h"
37 #include "nine_helpers.h"
38 #include "nine_pipe.h"
39 #include "nine_ff.h"
40 #include "nine_dump.h"
41 #include "nine_limits.h"
42
43 #include "pipe/p_screen.h"
44 #include "pipe/p_context.h"
45 #include "pipe/p_config.h"
46 #include "util/u_math.h"
47 #include "util/u_inlines.h"
48 #include "util/u_hash_table.h"
49 #include "util/u_format.h"
50 #include "util/u_surface.h"
51 #include "util/u_upload_mgr.h"
52 #include "hud/hud_context.h"
53
54 #include "cso_cache/cso_context.h"
55
56 #define DBG_CHANNEL DBG_DEVICE
57
58 #if defined(PIPE_CC_GCC) && (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64))
59
60 static void nine_setup_fpu()
61 {
62 uint16_t c;
63
64 __asm__ __volatile__ ("fnstcw %0" : "=m" (*&c));
65
66 /* clear the control word */
67 c &= 0xF0C0;
68 /* d3d9 doc/wine tests: mask all exceptions, use single-precision
69 * and round to nearest */
70 c |= 0x003F;
71
72 __asm__ __volatile__ ("fldcw %0" : : "m" (*&c));
73 }
74
75 #else
76
77 static void nine_setup_fpu(void)
78 {
79 WARN_ONCE("FPU setup not supported on non-x86 platforms\n");
80 }
81
82 #endif
83
84 void
85 NineDevice9_SetDefaultState( struct NineDevice9 *This, boolean is_reset )
86 {
87 struct NineSurface9 *refSurf = NULL;
88
89 DBG("This=%p is_reset=%d\n", This, (int) is_reset);
90
91 assert(!This->is_recording);
92
93 nine_state_set_defaults(This, &This->caps, is_reset);
94
95 refSurf = This->swapchains[0]->buffers[0];
96 assert(refSurf);
97
98 This->state.viewport.X = 0;
99 This->state.viewport.Y = 0;
100 This->state.viewport.Width = refSurf->desc.Width;
101 This->state.viewport.Height = refSurf->desc.Height;
102
103 nine_context_set_viewport(This, &This->state.viewport);
104
105 This->state.scissor.minx = 0;
106 This->state.scissor.miny = 0;
107 This->state.scissor.maxx = refSurf->desc.Width;
108 This->state.scissor.maxy = refSurf->desc.Height;
109
110 nine_context_set_scissor(This, &This->state.scissor);
111
112 if (This->nswapchains && This->swapchains[0]->params.EnableAutoDepthStencil) {
113 nine_context_set_render_state(This, D3DRS_ZENABLE, TRUE);
114 This->state.rs_advertised[D3DRS_ZENABLE] = TRUE;
115 }
116 if (This->state.rs_advertised[D3DRS_ZENABLE])
117 NineDevice9_SetDepthStencilSurface(
118 This, (IDirect3DSurface9 *)This->swapchains[0]->zsbuf);
119 }
120
121 #define GET_PCAP(n) pScreen->get_param(pScreen, PIPE_CAP_##n)
122 HRESULT
123 NineDevice9_ctor( struct NineDevice9 *This,
124 struct NineUnknownParams *pParams,
125 struct pipe_screen *pScreen,
126 D3DDEVICE_CREATION_PARAMETERS *pCreationParameters,
127 D3DCAPS9 *pCaps,
128 D3DPRESENT_PARAMETERS *pPresentationParameters,
129 IDirect3D9 *pD3D9,
130 ID3DPresentGroup *pPresentationGroup,
131 struct d3dadapter9_context *pCTX,
132 boolean ex,
133 D3DDISPLAYMODEEX *pFullscreenDisplayMode,
134 int minorVersionNum )
135 {
136 unsigned i;
137 HRESULT hr = NineUnknown_ctor(&This->base, pParams);
138
139 DBG("This=%p pParams=%p pScreen=%p pCreationParameters=%p pCaps=%p pPresentationParameters=%p "
140 "pD3D9=%p pPresentationGroup=%p pCTX=%p ex=%d pFullscreenDisplayMode=%p\n",
141 This, pParams, pScreen, pCreationParameters, pCaps, pPresentationParameters, pD3D9,
142 pPresentationGroup, pCTX, (int) ex, pFullscreenDisplayMode);
143
144 if (FAILED(hr)) { return hr; }
145
146 list_inithead(&This->update_buffers);
147 list_inithead(&This->update_textures);
148 list_inithead(&This->managed_buffers);
149 list_inithead(&This->managed_textures);
150
151 This->screen = pScreen;
152 This->screen_sw = pCTX->ref;
153 This->caps = *pCaps;
154 This->d3d9 = pD3D9;
155 This->params = *pCreationParameters;
156 This->ex = ex;
157 This->present = pPresentationGroup;
158 This->minor_version_num = minorVersionNum;
159
160 IDirect3D9_AddRef(This->d3d9);
161 ID3DPresentGroup_AddRef(This->present);
162
163 if (!(This->params.BehaviorFlags & D3DCREATE_FPU_PRESERVE))
164 nine_setup_fpu();
165
166 if (This->params.BehaviorFlags & D3DCREATE_SOFTWARE_VERTEXPROCESSING) {
167 DBG("Application asked full Software Vertex Processing.\n");
168 This->swvp = true;
169 This->may_swvp = true;
170 } else
171 This->swvp = false;
172 if (This->params.BehaviorFlags & D3DCREATE_MIXED_VERTEXPROCESSING) {
173 DBG("Application asked mixed Software Vertex Processing.\n");
174 This->may_swvp = true;
175 }
176 /* TODO: check if swvp is resetted by device Resets */
177
178 if (This->may_swvp &&
179 (This->screen->get_shader_param(This->screen, PIPE_SHADER_VERTEX,
180 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE)
181 < (NINE_MAX_CONST_F_SWVP/2) * sizeof(float[4]) ||
182 This->screen->get_shader_param(This->screen, PIPE_SHADER_VERTEX,
183 PIPE_SHADER_CAP_MAX_CONST_BUFFERS) < 5)) {
184 /* Note: We just go on, some apps never use the abilities of
185 * swvp, and just set more constants than allowed at init.
186 * Only cards we support that are affected are the r500 */
187 WARN("Card unable to handle Software Vertex Processing. Game may fail\n");
188 }
189
190 /* When may_swvp, SetConstant* limits are different */
191 if (This->may_swvp)
192 This->caps.MaxVertexShaderConst = NINE_MAX_CONST_F_SWVP;
193
194 This->pipe = This->screen->context_create(This->screen, NULL, 0);
195 if (!This->pipe) { return E_OUTOFMEMORY; } /* guess */
196 This->pipe_sw = This->screen_sw->context_create(This->screen_sw, NULL, 0);
197 if (!This->pipe_sw) { return E_OUTOFMEMORY; }
198
199 This->cso = cso_create_context(This->pipe);
200 if (!This->cso) { return E_OUTOFMEMORY; } /* also a guess */
201 This->cso_sw = cso_create_context(This->pipe_sw);
202 if (!This->cso_sw) { return E_OUTOFMEMORY; }
203
204 /* Create first, it messes up our state. */
205 This->hud = hud_create(This->pipe, This->cso); /* NULL result is fine */
206
207 /* Available memory counter. Updated only for allocations with this device
208 * instance. This is the Win 7 behavior.
209 * Win XP shares this counter across multiple devices. */
210 This->available_texture_mem = This->screen->get_param(This->screen, PIPE_CAP_VIDEO_MEMORY);
211 if (This->available_texture_mem < 4096)
212 This->available_texture_mem <<= 20;
213 else
214 This->available_texture_mem = UINT_MAX;
215 /* We cap texture memory usage to 80% of what is reported free initially
216 * This helps get closer Win behaviour. For example VertexBuffer allocation
217 * still succeeds when texture allocation fails. */
218 This->available_texture_limit = This->available_texture_mem * 20LL / 100LL;
219
220 /* create implicit swapchains */
221 This->nswapchains = ID3DPresentGroup_GetMultiheadCount(This->present);
222 This->swapchains = CALLOC(This->nswapchains,
223 sizeof(struct NineSwapChain9 *));
224 if (!This->swapchains) { return E_OUTOFMEMORY; }
225
226 for (i = 0; i < This->nswapchains; ++i) {
227 ID3DPresent *present;
228
229 hr = ID3DPresentGroup_GetPresent(This->present, i, &present);
230 if (FAILED(hr))
231 return hr;
232
233 if (ex) {
234 D3DDISPLAYMODEEX *mode = NULL;
235 struct NineSwapChain9Ex **ret =
236 (struct NineSwapChain9Ex **)&This->swapchains[i];
237
238 if (pFullscreenDisplayMode) mode = &(pFullscreenDisplayMode[i]);
239 /* when this is a Device9Ex, it should create SwapChain9Exs */
240 hr = NineSwapChain9Ex_new(This, TRUE, present,
241 &pPresentationParameters[i], pCTX,
242 This->params.hFocusWindow, mode, ret);
243 } else {
244 hr = NineSwapChain9_new(This, TRUE, present,
245 &pPresentationParameters[i], pCTX,
246 This->params.hFocusWindow,
247 &This->swapchains[i]);
248 }
249
250 ID3DPresent_Release(present);
251 if (FAILED(hr))
252 return hr;
253 NineUnknown_ConvertRefToBind(NineUnknown(This->swapchains[i]));
254
255 hr = NineSwapChain9_GetBackBuffer(This->swapchains[i], 0,
256 D3DBACKBUFFER_TYPE_MONO,
257 (IDirect3DSurface9 **)
258 &This->state.rt[i]);
259 if (FAILED(hr))
260 return hr;
261 NineUnknown_ConvertRefToBind(NineUnknown(This->state.rt[i]));
262 nine_bind(&This->context.rt[i], This->state.rt[i]);
263 }
264
265 /* Initialize a dummy VBO to be used when a vertex declaration does not
266 * specify all the inputs needed by vertex shader, on win default behavior
267 * is to pass 0,0,0,0 to the shader */
268 {
269 struct pipe_transfer *transfer;
270 struct pipe_resource tmpl;
271 struct pipe_box box;
272 unsigned char *data;
273
274 memset(&tmpl, 0, sizeof(tmpl));
275 tmpl.target = PIPE_BUFFER;
276 tmpl.format = PIPE_FORMAT_R8_UNORM;
277 tmpl.width0 = 16; /* 4 floats */
278 tmpl.height0 = 1;
279 tmpl.depth0 = 1;
280 tmpl.array_size = 1;
281 tmpl.last_level = 0;
282 tmpl.nr_samples = 0;
283 tmpl.usage = PIPE_USAGE_DEFAULT;
284 tmpl.bind = PIPE_BIND_VERTEX_BUFFER;
285 tmpl.flags = 0;
286 This->dummy_vbo = pScreen->resource_create(pScreen, &tmpl);
287
288 if (!This->dummy_vbo)
289 return D3DERR_OUTOFVIDEOMEMORY;
290
291 u_box_1d(0, 16, &box);
292 data = This->pipe->transfer_map(This->pipe, This->dummy_vbo, 0,
293 PIPE_TRANSFER_WRITE |
294 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE,
295 &box, &transfer);
296 assert(data);
297 assert(transfer);
298 memset(data, 0, 16);
299 This->pipe->transfer_unmap(This->pipe, transfer);
300 }
301
302 This->cursor.software = FALSE;
303 This->cursor.hotspot.x = -1;
304 This->cursor.hotspot.y = -1;
305 {
306 struct pipe_resource tmpl;
307 memset(&tmpl, 0, sizeof(tmpl));
308 tmpl.target = PIPE_TEXTURE_2D;
309 tmpl.format = PIPE_FORMAT_R8G8B8A8_UNORM;
310 tmpl.width0 = 64;
311 tmpl.height0 = 64;
312 tmpl.depth0 = 1;
313 tmpl.array_size = 1;
314 tmpl.last_level = 0;
315 tmpl.nr_samples = 0;
316 tmpl.usage = PIPE_USAGE_DEFAULT;
317 tmpl.bind = PIPE_BIND_CURSOR | PIPE_BIND_SAMPLER_VIEW;
318 tmpl.flags = 0;
319
320 This->cursor.image = pScreen->resource_create(pScreen, &tmpl);
321 if (!This->cursor.image)
322 return D3DERR_OUTOFVIDEOMEMORY;
323
324 /* For uploading 32x32 (argb) cursor */
325 This->cursor.hw_upload_temp = MALLOC(32 * 4 * 32);
326 if (!This->cursor.hw_upload_temp)
327 return D3DERR_OUTOFVIDEOMEMORY;
328 }
329
330 /* Create constant buffers. */
331 {
332 unsigned max_const_vs, max_const_ps;
333
334 /* vs 3.0: >= 256 float constants, but for cards with exactly 256 slots,
335 * we have to take in some more slots for int and bool*/
336 max_const_vs = _min(pScreen->get_shader_param(pScreen, PIPE_SHADER_VERTEX,
337 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE) /
338 sizeof(float[4]),
339 NINE_MAX_CONST_ALL);
340 /* ps 3.0: 224 float constants. All cards supported support at least
341 * 256 constants for ps */
342 max_const_ps = NINE_MAX_CONST_F_PS3 + (NINE_MAX_CONST_I + NINE_MAX_CONST_B / 4);
343
344 This->max_vs_const_f = max_const_vs -
345 (NINE_MAX_CONST_I + NINE_MAX_CONST_B / 4);
346 This->max_ps_const_f = max_const_ps -
347 (NINE_MAX_CONST_I + NINE_MAX_CONST_B / 4);
348
349 This->vs_const_size = max_const_vs * sizeof(float[4]);
350 This->ps_const_size = max_const_ps * sizeof(float[4]);
351 /* Include space for I,B constants for user constbuf. */
352 if (This->may_swvp) {
353 This->state.vs_const_f = CALLOC(NINE_MAX_CONST_F_SWVP * sizeof(float[4]),1);
354 This->context.vs_const_f_swvp = CALLOC(NINE_MAX_CONST_F_SWVP * sizeof(float[4]),1);
355 if (!This->context.vs_const_f_swvp)
356 return E_OUTOFMEMORY;
357 This->state.vs_lconstf_temp = CALLOC(NINE_MAX_CONST_F_SWVP * sizeof(float[4]),1);
358 This->context.vs_lconstf_temp = CALLOC(NINE_MAX_CONST_F_SWVP * sizeof(float[4]),1);
359 This->state.vs_const_i = CALLOC(NINE_MAX_CONST_I_SWVP * sizeof(int[4]), 1);
360 This->context.vs_const_i = CALLOC(NINE_MAX_CONST_I_SWVP * sizeof(int[4]), 1);
361 This->state.vs_const_b = CALLOC(NINE_MAX_CONST_B_SWVP * sizeof(BOOL), 1);
362 This->context.vs_const_b = CALLOC(NINE_MAX_CONST_B_SWVP * sizeof(BOOL), 1);
363 } else {
364 This->state.vs_const_f = CALLOC(NINE_MAX_CONST_F * sizeof(float[4]), 1);
365 This->context.vs_const_f_swvp = NULL;
366 This->state.vs_lconstf_temp = CALLOC(This->vs_const_size,1);
367 This->context.vs_lconstf_temp = CALLOC(This->vs_const_size,1);
368 This->state.vs_const_i = CALLOC(NINE_MAX_CONST_I * sizeof(int[4]), 1);
369 This->context.vs_const_i = CALLOC(NINE_MAX_CONST_I * sizeof(int[4]), 1);
370 This->state.vs_const_b = CALLOC(NINE_MAX_CONST_B * sizeof(BOOL), 1);
371 This->context.vs_const_b = CALLOC(NINE_MAX_CONST_B * sizeof(BOOL), 1);
372 }
373 This->context.vs_const_f = CALLOC(This->vs_const_size, 1);
374 This->state.ps_const_f = CALLOC(This->ps_const_size, 1);
375 This->context.ps_const_f = CALLOC(This->ps_const_size, 1);
376 This->context.ps_lconstf_temp = CALLOC(This->ps_const_size,1);
377 if (!This->state.vs_const_f || !This->context.vs_const_f ||
378 !This->state.ps_const_f || !This->context.ps_const_f ||
379 !This->state.vs_lconstf_temp || !This->context.vs_lconstf_temp ||
380 !This->context.ps_lconstf_temp ||
381 !This->state.vs_const_i || !This->context.vs_const_i ||
382 !This->state.vs_const_b || !This->context.vs_const_b)
383 return E_OUTOFMEMORY;
384
385 if (strstr(pScreen->get_name(pScreen), "AMD") ||
386 strstr(pScreen->get_name(pScreen), "ATI")) {
387 This->driver_bugs.buggy_barycentrics = TRUE;
388 }
389 }
390
391 /* allocate dummy texture/sampler for when there are missing ones bound */
392 {
393 struct pipe_resource tmplt;
394 struct pipe_sampler_view templ;
395 struct pipe_sampler_state samp;
396 memset(&tmplt, 0, sizeof(tmplt));
397 memset(&samp, 0, sizeof(samp));
398
399 tmplt.target = PIPE_TEXTURE_2D;
400 tmplt.width0 = 1;
401 tmplt.height0 = 1;
402 tmplt.depth0 = 1;
403 tmplt.last_level = 0;
404 tmplt.array_size = 1;
405 tmplt.usage = PIPE_USAGE_DEFAULT;
406 tmplt.flags = 0;
407 tmplt.format = PIPE_FORMAT_B8G8R8A8_UNORM;
408 tmplt.bind = PIPE_BIND_SAMPLER_VIEW;
409 tmplt.nr_samples = 0;
410
411 This->dummy_texture = This->screen->resource_create(This->screen, &tmplt);
412 if (!This->dummy_texture)
413 return D3DERR_DRIVERINTERNALERROR;
414
415 templ.format = PIPE_FORMAT_B8G8R8A8_UNORM;
416 templ.u.tex.first_layer = 0;
417 templ.u.tex.last_layer = 0;
418 templ.u.tex.first_level = 0;
419 templ.u.tex.last_level = 0;
420 templ.swizzle_r = PIPE_SWIZZLE_0;
421 templ.swizzle_g = PIPE_SWIZZLE_0;
422 templ.swizzle_b = PIPE_SWIZZLE_0;
423 templ.swizzle_a = PIPE_SWIZZLE_1;
424 templ.target = This->dummy_texture->target;
425
426 This->dummy_sampler_view = This->pipe->create_sampler_view(This->pipe, This->dummy_texture, &templ);
427 if (!This->dummy_sampler_view)
428 return D3DERR_DRIVERINTERNALERROR;
429
430 samp.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
431 samp.max_lod = 15.0f;
432 samp.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
433 samp.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
434 samp.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
435 samp.min_img_filter = PIPE_TEX_FILTER_NEAREST;
436 samp.mag_img_filter = PIPE_TEX_FILTER_NEAREST;
437 samp.compare_mode = PIPE_TEX_COMPARE_NONE;
438 samp.compare_func = PIPE_FUNC_LEQUAL;
439 samp.normalized_coords = 1;
440 samp.seamless_cube_map = 0;
441 This->dummy_sampler_state = samp;
442 }
443
444 /* Allocate upload helper for drivers that suck (from st pov ;). */
445
446 This->driver_caps.user_vbufs = GET_PCAP(USER_VERTEX_BUFFERS);
447 This->driver_caps.user_ibufs = GET_PCAP(USER_INDEX_BUFFERS);
448 This->driver_caps.user_cbufs = GET_PCAP(USER_CONSTANT_BUFFERS);
449 This->driver_caps.user_sw_vbufs = This->screen_sw->get_param(This->screen_sw, PIPE_CAP_USER_VERTEX_BUFFERS);
450 This->driver_caps.user_sw_cbufs = This->screen_sw->get_param(This->screen_sw, PIPE_CAP_USER_CONSTANT_BUFFERS);
451
452 if (!This->driver_caps.user_vbufs)
453 This->vertex_uploader = u_upload_create(This->pipe, 65536,
454 PIPE_BIND_VERTEX_BUFFER, PIPE_USAGE_STREAM);
455 This->vertex_sw_uploader = u_upload_create(This->pipe_sw, 65536,
456 PIPE_BIND_VERTEX_BUFFER, PIPE_USAGE_STREAM);
457 if (!This->driver_caps.user_ibufs)
458 This->index_uploader = u_upload_create(This->pipe, 128 * 1024,
459 PIPE_BIND_INDEX_BUFFER, PIPE_USAGE_STREAM);
460 if (!This->driver_caps.user_cbufs) {
461 This->constbuf_alignment = GET_PCAP(CONSTANT_BUFFER_OFFSET_ALIGNMENT);
462 This->constbuf_uploader = u_upload_create(This->pipe, This->vs_const_size,
463 PIPE_BIND_CONSTANT_BUFFER, PIPE_USAGE_STREAM);
464 }
465
466 This->constbuf_sw_uploader = u_upload_create(This->pipe_sw, 128 * 1024,
467 PIPE_BIND_CONSTANT_BUFFER, PIPE_USAGE_STREAM);
468
469 This->driver_caps.window_space_position_support = GET_PCAP(TGSI_VS_WINDOW_SPACE_POSITION);
470 This->driver_caps.vs_integer = pScreen->get_shader_param(pScreen, PIPE_SHADER_VERTEX, PIPE_SHADER_CAP_INTEGERS);
471 This->driver_caps.ps_integer = pScreen->get_shader_param(pScreen, PIPE_SHADER_FRAGMENT, PIPE_SHADER_CAP_INTEGERS);
472 This->driver_caps.offset_units_unscaled = GET_PCAP(POLYGON_OFFSET_UNITS_UNSCALED);
473
474 nine_ff_init(This); /* initialize fixed function code */
475
476 NineDevice9_SetDefaultState(This, FALSE);
477
478 {
479 struct pipe_poly_stipple stipple;
480 memset(&stipple, ~0, sizeof(stipple));
481 This->pipe->set_polygon_stipple(This->pipe, &stipple);
482 }
483
484 This->update = &This->state;
485
486 nine_state_init_sw(This);
487
488 ID3DPresentGroup_Release(This->present);
489
490 return D3D_OK;
491 }
492 #undef GET_PCAP
493
494 void
495 NineDevice9_dtor( struct NineDevice9 *This )
496 {
497 unsigned i;
498
499 DBG("This=%p\n", This);
500
501 if (This->pipe && This->cso)
502 nine_pipe_context_clear(This);
503 nine_ff_fini(This);
504 nine_state_destroy_sw(This);
505 nine_state_clear(&This->state, TRUE);
506 nine_context_clear(&This->context);
507
508 if (This->vertex_uploader)
509 u_upload_destroy(This->vertex_uploader);
510 if (This->index_uploader)
511 u_upload_destroy(This->index_uploader);
512 if (This->constbuf_uploader)
513 u_upload_destroy(This->constbuf_uploader);
514 if (This->vertex_sw_uploader)
515 u_upload_destroy(This->vertex_sw_uploader);
516 if (This->constbuf_sw_uploader)
517 u_upload_destroy(This->constbuf_sw_uploader);
518
519 nine_bind(&This->record, NULL);
520
521 pipe_sampler_view_reference(&This->dummy_sampler_view, NULL);
522 pipe_resource_reference(&This->dummy_texture, NULL);
523 pipe_resource_reference(&This->dummy_vbo, NULL);
524 FREE(This->state.vs_const_f);
525 FREE(This->context.vs_const_f);
526 FREE(This->state.ps_const_f);
527 FREE(This->context.ps_const_f);
528 FREE(This->state.vs_lconstf_temp);
529 FREE(This->context.vs_lconstf_temp);
530 FREE(This->context.ps_lconstf_temp);
531 FREE(This->state.vs_const_i);
532 FREE(This->context.vs_const_i);
533 FREE(This->state.vs_const_b);
534 FREE(This->context.vs_const_b);
535 FREE(This->context.vs_const_f_swvp);
536
537 pipe_resource_reference(&This->cursor.image, NULL);
538 FREE(This->cursor.hw_upload_temp);
539
540 if (This->swapchains) {
541 for (i = 0; i < This->nswapchains; ++i)
542 if (This->swapchains[i])
543 NineUnknown_Unbind(NineUnknown(This->swapchains[i]));
544 FREE(This->swapchains);
545 }
546
547 /* Destroy cso first */
548 if (This->cso) { cso_destroy_context(This->cso); }
549 if (This->cso_sw) { cso_destroy_context(This->cso_sw); }
550 if (This->pipe && This->pipe->destroy) { This->pipe->destroy(This->pipe); }
551 if (This->pipe_sw && This->pipe_sw->destroy) { This->pipe_sw->destroy(This->pipe_sw); }
552
553 if (This->present) { ID3DPresentGroup_Release(This->present); }
554 if (This->d3d9) { IDirect3D9_Release(This->d3d9); }
555
556 NineUnknown_dtor(&This->base);
557 }
558
559 struct pipe_screen *
560 NineDevice9_GetScreen( struct NineDevice9 *This )
561 {
562 return This->screen;
563 }
564
565 struct pipe_context *
566 NineDevice9_GetPipe( struct NineDevice9 *This )
567 {
568 return This->pipe;
569 }
570
571 struct cso_context *
572 NineDevice9_GetCSO( struct NineDevice9 *This )
573 {
574 return This->cso;
575 }
576
577 const D3DCAPS9 *
578 NineDevice9_GetCaps( struct NineDevice9 *This )
579 {
580 return &This->caps;
581 }
582
583 static inline void
584 NineDevice9_PauseRecording( struct NineDevice9 *This )
585 {
586 if (This->record) {
587 This->update = &This->state;
588 This->is_recording = FALSE;
589 }
590 }
591
592 static inline void
593 NineDevice9_ResumeRecording( struct NineDevice9 *This )
594 {
595 if (This->record) {
596 This->update = &This->record->state;
597 This->is_recording = TRUE;
598 }
599 }
600
601 HRESULT NINE_WINAPI
602 NineDevice9_TestCooperativeLevel( struct NineDevice9 *This )
603 {
604 if (NineSwapChain9_GetOccluded(This->swapchains[0])) {
605 This->device_needs_reset = TRUE;
606 return D3DERR_DEVICELOST;
607 } else if (NineSwapChain9_ResolutionMismatch(This->swapchains[0])) {
608 This->device_needs_reset = TRUE;
609 return D3DERR_DEVICENOTRESET;
610 } else if (This->device_needs_reset) {
611 return D3DERR_DEVICENOTRESET;
612 }
613
614 return D3D_OK;
615 }
616
617 UINT NINE_WINAPI
618 NineDevice9_GetAvailableTextureMem( struct NineDevice9 *This )
619 {
620 return This->available_texture_mem;
621 }
622
623 HRESULT NINE_WINAPI
624 NineDevice9_EvictManagedResources( struct NineDevice9 *This )
625 {
626 struct NineBaseTexture9 *tex;
627 struct NineBuffer9 *buf;
628
629 DBG("This=%p\n", This);
630 LIST_FOR_EACH_ENTRY(tex, &This->managed_textures, list2) {
631 NineBaseTexture9_UnLoad(tex);
632 }
633 /* Vertex/index buffers don't take a lot of space and aren't accounted
634 * for d3d memory usage. Instead of actually freeing from memory,
635 * just mark the buffer dirty to trigger a re-upload later. We
636 * could just ignore, but some bad behaving apps could rely on it (if
637 * they write outside the locked regions typically). */
638 LIST_FOR_EACH_ENTRY(buf, &This->managed_buffers, managed.list2) {
639 NineBuffer9_SetDirty(buf);
640 }
641
642 return D3D_OK;
643 }
644
645 HRESULT NINE_WINAPI
646 NineDevice9_GetDirect3D( struct NineDevice9 *This,
647 IDirect3D9 **ppD3D9 )
648 {
649 user_assert(ppD3D9 != NULL, E_POINTER);
650 IDirect3D9_AddRef(This->d3d9);
651 *ppD3D9 = This->d3d9;
652 return D3D_OK;
653 }
654
655 HRESULT NINE_WINAPI
656 NineDevice9_GetDeviceCaps( struct NineDevice9 *This,
657 D3DCAPS9 *pCaps )
658 {
659 user_assert(pCaps != NULL, D3DERR_INVALIDCALL);
660 *pCaps = This->caps;
661 return D3D_OK;
662 }
663
664 HRESULT NINE_WINAPI
665 NineDevice9_GetDisplayMode( struct NineDevice9 *This,
666 UINT iSwapChain,
667 D3DDISPLAYMODE *pMode )
668 {
669 DBG("This=%p iSwapChain=%u pMode=%p\n", This, iSwapChain, pMode);
670
671 user_assert(iSwapChain < This->nswapchains, D3DERR_INVALIDCALL);
672
673 return NineSwapChain9_GetDisplayMode(This->swapchains[iSwapChain], pMode);
674 }
675
676 HRESULT NINE_WINAPI
677 NineDevice9_GetCreationParameters( struct NineDevice9 *This,
678 D3DDEVICE_CREATION_PARAMETERS *pParameters )
679 {
680 user_assert(pParameters != NULL, D3DERR_INVALIDCALL);
681 *pParameters = This->params;
682 return D3D_OK;
683 }
684
685 HRESULT NINE_WINAPI
686 NineDevice9_SetCursorProperties( struct NineDevice9 *This,
687 UINT XHotSpot,
688 UINT YHotSpot,
689 IDirect3DSurface9 *pCursorBitmap )
690 {
691 struct NineSurface9 *surf = NineSurface9(pCursorBitmap);
692 struct pipe_context *pipe = This->pipe;
693 struct pipe_box box;
694 struct pipe_transfer *transfer;
695 BOOL hw_cursor;
696 void *ptr;
697
698 DBG_FLAG(DBG_SWAPCHAIN, "This=%p XHotSpot=%u YHotSpot=%u "
699 "pCursorBitmap=%p\n", This, XHotSpot, YHotSpot, pCursorBitmap);
700
701 user_assert(pCursorBitmap, D3DERR_INVALIDCALL);
702 user_assert(surf->desc.Format == D3DFMT_A8R8G8B8, D3DERR_INVALIDCALL);
703
704 if (This->swapchains[0]->params.Windowed) {
705 This->cursor.w = MIN2(surf->desc.Width, 32);
706 This->cursor.h = MIN2(surf->desc.Height, 32);
707 hw_cursor = 1; /* always use hw cursor for windowed mode */
708 } else {
709 This->cursor.w = MIN2(surf->desc.Width, This->cursor.image->width0);
710 This->cursor.h = MIN2(surf->desc.Height, This->cursor.image->height0);
711 hw_cursor = This->cursor.w == 32 && This->cursor.h == 32;
712 }
713
714 u_box_origin_2d(This->cursor.w, This->cursor.h, &box);
715
716 ptr = pipe->transfer_map(pipe, This->cursor.image, 0,
717 PIPE_TRANSFER_WRITE |
718 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE,
719 &box, &transfer);
720 if (!ptr)
721 ret_err("Failed to update cursor image.\n", D3DERR_DRIVERINTERNALERROR);
722
723 This->cursor.hotspot.x = XHotSpot;
724 This->cursor.hotspot.y = YHotSpot;
725
726 /* Copy cursor image to internal storage. */
727 {
728 D3DLOCKED_RECT lock;
729 HRESULT hr;
730 const struct util_format_description *sfmt =
731 util_format_description(surf->base.info.format);
732 assert(sfmt);
733
734 hr = NineSurface9_LockRect(surf, &lock, NULL, D3DLOCK_READONLY);
735 if (FAILED(hr))
736 ret_err("Failed to map cursor source image.\n",
737 D3DERR_DRIVERINTERNALERROR);
738
739 sfmt->unpack_rgba_8unorm(ptr, transfer->stride,
740 lock.pBits, lock.Pitch,
741 This->cursor.w, This->cursor.h);
742
743 if (hw_cursor) {
744 void *data = lock.pBits;
745 /* SetCursor assumes 32x32 argb with pitch 128 */
746 if (lock.Pitch != 128) {
747 sfmt->unpack_rgba_8unorm(This->cursor.hw_upload_temp, 128,
748 lock.pBits, lock.Pitch,
749 32, 32);
750 data = This->cursor.hw_upload_temp;
751 }
752 hw_cursor = ID3DPresent_SetCursor(This->swapchains[0]->present,
753 data,
754 &This->cursor.hotspot,
755 This->cursor.visible) == D3D_OK;
756 }
757
758 NineSurface9_UnlockRect(surf);
759 }
760 pipe->transfer_unmap(pipe, transfer);
761
762 /* hide cursor if we emulate it */
763 if (!hw_cursor)
764 ID3DPresent_SetCursor(This->swapchains[0]->present, NULL, NULL, FALSE);
765 This->cursor.software = !hw_cursor;
766
767 return D3D_OK;
768 }
769
770 void NINE_WINAPI
771 NineDevice9_SetCursorPosition( struct NineDevice9 *This,
772 int X,
773 int Y,
774 DWORD Flags )
775 {
776 struct NineSwapChain9 *swap = This->swapchains[0];
777
778 DBG("This=%p X=%d Y=%d Flags=%d\n", This, X, Y, Flags);
779
780 This->cursor.pos.x = X;
781 This->cursor.pos.y = Y;
782
783 if (!This->cursor.software)
784 This->cursor.software = ID3DPresent_SetCursorPos(swap->present, &This->cursor.pos) != D3D_OK;
785 }
786
787 BOOL NINE_WINAPI
788 NineDevice9_ShowCursor( struct NineDevice9 *This,
789 BOOL bShow )
790 {
791 BOOL old = This->cursor.visible;
792
793 DBG("This=%p bShow=%d\n", This, (int) bShow);
794
795 This->cursor.visible = bShow && (This->cursor.hotspot.x != -1);
796 if (!This->cursor.software)
797 This->cursor.software = ID3DPresent_SetCursor(This->swapchains[0]->present, NULL, NULL, bShow) != D3D_OK;
798
799 return old;
800 }
801
802 HRESULT NINE_WINAPI
803 NineDevice9_CreateAdditionalSwapChain( struct NineDevice9 *This,
804 D3DPRESENT_PARAMETERS *pPresentationParameters,
805 IDirect3DSwapChain9 **pSwapChain )
806 {
807 struct NineSwapChain9 *swapchain, *tmplt = This->swapchains[0];
808 ID3DPresent *present;
809 HRESULT hr;
810
811 DBG("This=%p pPresentationParameters=%p pSwapChain=%p\n",
812 This, pPresentationParameters, pSwapChain);
813
814 user_assert(pPresentationParameters, D3DERR_INVALIDCALL);
815 user_assert(tmplt->params.Windowed && pPresentationParameters->Windowed, D3DERR_INVALIDCALL);
816
817 /* TODO: this deserves more tests */
818 if (!pPresentationParameters->hDeviceWindow)
819 pPresentationParameters->hDeviceWindow = This->params.hFocusWindow;
820
821 hr = ID3DPresentGroup_CreateAdditionalPresent(This->present, pPresentationParameters, &present);
822
823 if (FAILED(hr))
824 return hr;
825
826 hr = NineSwapChain9_new(This, FALSE, present, pPresentationParameters,
827 tmplt->actx,
828 tmplt->params.hDeviceWindow,
829 &swapchain);
830 if (FAILED(hr))
831 return hr;
832
833 *pSwapChain = (IDirect3DSwapChain9 *)swapchain;
834 return D3D_OK;
835 }
836
837 HRESULT NINE_WINAPI
838 NineDevice9_GetSwapChain( struct NineDevice9 *This,
839 UINT iSwapChain,
840 IDirect3DSwapChain9 **pSwapChain )
841 {
842 user_assert(pSwapChain != NULL, D3DERR_INVALIDCALL);
843
844 *pSwapChain = NULL;
845 user_assert(iSwapChain < This->nswapchains, D3DERR_INVALIDCALL);
846
847 NineUnknown_AddRef(NineUnknown(This->swapchains[iSwapChain]));
848 *pSwapChain = (IDirect3DSwapChain9 *)This->swapchains[iSwapChain];
849
850 return D3D_OK;
851 }
852
853 UINT NINE_WINAPI
854 NineDevice9_GetNumberOfSwapChains( struct NineDevice9 *This )
855 {
856 return This->nswapchains;
857 }
858
859 HRESULT NINE_WINAPI
860 NineDevice9_Reset( struct NineDevice9 *This,
861 D3DPRESENT_PARAMETERS *pPresentationParameters )
862 {
863 HRESULT hr = D3D_OK;
864 unsigned i;
865
866 DBG("This=%p pPresentationParameters=%p\n", This, pPresentationParameters);
867
868 if (NineSwapChain9_GetOccluded(This->swapchains[0])) {
869 This->device_needs_reset = TRUE;
870 return D3DERR_DEVICELOST;
871 }
872
873 for (i = 0; i < This->nswapchains; ++i) {
874 D3DPRESENT_PARAMETERS *params = &pPresentationParameters[i];
875 hr = NineSwapChain9_Resize(This->swapchains[i], params, NULL);
876 if (hr != D3D_OK)
877 break;
878 }
879
880 nine_pipe_context_clear(This);
881 nine_state_clear(&This->state, TRUE);
882 nine_context_clear(&This->context);
883
884 NineDevice9_SetDefaultState(This, TRUE);
885 NineDevice9_SetRenderTarget(
886 This, 0, (IDirect3DSurface9 *)This->swapchains[0]->buffers[0]);
887 /* XXX: better use GetBackBuffer here ? */
888
889 This->device_needs_reset = (hr != D3D_OK);
890 return hr;
891 }
892
893 HRESULT NINE_WINAPI
894 NineDevice9_Present( struct NineDevice9 *This,
895 const RECT *pSourceRect,
896 const RECT *pDestRect,
897 HWND hDestWindowOverride,
898 const RGNDATA *pDirtyRegion )
899 {
900 unsigned i;
901 HRESULT hr;
902
903 DBG("This=%p pSourceRect=%p pDestRect=%p hDestWindowOverride=%p pDirtyRegion=%p\n",
904 This, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
905
906 /* XXX is this right? */
907 for (i = 0; i < This->nswapchains; ++i) {
908 hr = NineSwapChain9_Present(This->swapchains[i], pSourceRect, pDestRect,
909 hDestWindowOverride, pDirtyRegion, 0);
910 if (FAILED(hr)) { return hr; }
911 }
912
913 return D3D_OK;
914 }
915
916 HRESULT NINE_WINAPI
917 NineDevice9_GetBackBuffer( struct NineDevice9 *This,
918 UINT iSwapChain,
919 UINT iBackBuffer,
920 D3DBACKBUFFER_TYPE Type,
921 IDirect3DSurface9 **ppBackBuffer )
922 {
923 user_assert(ppBackBuffer != NULL, D3DERR_INVALIDCALL);
924 /* return NULL on error */
925 *ppBackBuffer = NULL;
926 user_assert(iSwapChain < This->nswapchains, D3DERR_INVALIDCALL);
927
928 return NineSwapChain9_GetBackBuffer(This->swapchains[iSwapChain],
929 iBackBuffer, Type, ppBackBuffer);
930 }
931
932 HRESULT NINE_WINAPI
933 NineDevice9_GetRasterStatus( struct NineDevice9 *This,
934 UINT iSwapChain,
935 D3DRASTER_STATUS *pRasterStatus )
936 {
937 user_assert(pRasterStatus != NULL, D3DERR_INVALIDCALL);
938 user_assert(iSwapChain < This->nswapchains, D3DERR_INVALIDCALL);
939
940 return NineSwapChain9_GetRasterStatus(This->swapchains[iSwapChain],
941 pRasterStatus);
942 }
943
944 HRESULT NINE_WINAPI
945 NineDevice9_SetDialogBoxMode( struct NineDevice9 *This,
946 BOOL bEnableDialogs )
947 {
948 STUB(D3DERR_INVALIDCALL);
949 }
950
951 void NINE_WINAPI
952 NineDevice9_SetGammaRamp( struct NineDevice9 *This,
953 UINT iSwapChain,
954 DWORD Flags,
955 const D3DGAMMARAMP *pRamp )
956 {
957 DBG("This=%p iSwapChain=%u Flags=%x pRamp=%p\n", This,
958 iSwapChain, Flags, pRamp);
959
960 user_warn(iSwapChain >= This->nswapchains);
961 user_warn(!pRamp);
962
963 if (pRamp && (iSwapChain < This->nswapchains)) {
964 struct NineSwapChain9 *swap = This->swapchains[iSwapChain];
965 swap->gamma = *pRamp;
966 ID3DPresent_SetGammaRamp(swap->present, pRamp, swap->params.hDeviceWindow);
967 }
968 }
969
970 void NINE_WINAPI
971 NineDevice9_GetGammaRamp( struct NineDevice9 *This,
972 UINT iSwapChain,
973 D3DGAMMARAMP *pRamp )
974 {
975 DBG("This=%p iSwapChain=%u pRamp=%p\n", This, iSwapChain, pRamp);
976
977 user_warn(iSwapChain >= This->nswapchains);
978 user_warn(!pRamp);
979
980 if (pRamp && (iSwapChain < This->nswapchains))
981 *pRamp = This->swapchains[iSwapChain]->gamma;
982 }
983
984 HRESULT NINE_WINAPI
985 NineDevice9_CreateTexture( struct NineDevice9 *This,
986 UINT Width,
987 UINT Height,
988 UINT Levels,
989 DWORD Usage,
990 D3DFORMAT Format,
991 D3DPOOL Pool,
992 IDirect3DTexture9 **ppTexture,
993 HANDLE *pSharedHandle )
994 {
995 struct NineTexture9 *tex;
996 HRESULT hr;
997
998 DBG("This=%p Width=%u Height=%u Levels=%u Usage=%s Format=%s Pool=%s "
999 "ppOut=%p pSharedHandle=%p\n", This, Width, Height, Levels,
1000 nine_D3DUSAGE_to_str(Usage), d3dformat_to_string(Format),
1001 nine_D3DPOOL_to_str(Pool), ppTexture, pSharedHandle);
1002
1003 Usage &= D3DUSAGE_AUTOGENMIPMAP | D3DUSAGE_DEPTHSTENCIL | D3DUSAGE_DMAP |
1004 D3DUSAGE_DYNAMIC | D3DUSAGE_NONSECURE | D3DUSAGE_RENDERTARGET |
1005 D3DUSAGE_SOFTWAREPROCESSING | D3DUSAGE_TEXTAPI;
1006
1007 *ppTexture = NULL;
1008
1009 hr = NineTexture9_new(This, Width, Height, Levels, Usage, Format, Pool,
1010 &tex, pSharedHandle);
1011 if (SUCCEEDED(hr))
1012 *ppTexture = (IDirect3DTexture9 *)tex;
1013
1014 return hr;
1015 }
1016
1017 HRESULT NINE_WINAPI
1018 NineDevice9_CreateVolumeTexture( struct NineDevice9 *This,
1019 UINT Width,
1020 UINT Height,
1021 UINT Depth,
1022 UINT Levels,
1023 DWORD Usage,
1024 D3DFORMAT Format,
1025 D3DPOOL Pool,
1026 IDirect3DVolumeTexture9 **ppVolumeTexture,
1027 HANDLE *pSharedHandle )
1028 {
1029 struct NineVolumeTexture9 *tex;
1030 HRESULT hr;
1031
1032 DBG("This=%p Width=%u Height=%u Depth=%u Levels=%u Usage=%s Format=%s Pool=%s "
1033 "ppOut=%p pSharedHandle=%p\n", This, Width, Height, Depth, Levels,
1034 nine_D3DUSAGE_to_str(Usage), d3dformat_to_string(Format),
1035 nine_D3DPOOL_to_str(Pool), ppVolumeTexture, pSharedHandle);
1036
1037 Usage &= D3DUSAGE_DYNAMIC | D3DUSAGE_NONSECURE |
1038 D3DUSAGE_SOFTWAREPROCESSING;
1039
1040 *ppVolumeTexture = NULL;
1041
1042 hr = NineVolumeTexture9_new(This, Width, Height, Depth, Levels,
1043 Usage, Format, Pool, &tex, pSharedHandle);
1044 if (SUCCEEDED(hr))
1045 *ppVolumeTexture = (IDirect3DVolumeTexture9 *)tex;
1046
1047 return hr;
1048 }
1049
1050 HRESULT NINE_WINAPI
1051 NineDevice9_CreateCubeTexture( struct NineDevice9 *This,
1052 UINT EdgeLength,
1053 UINT Levels,
1054 DWORD Usage,
1055 D3DFORMAT Format,
1056 D3DPOOL Pool,
1057 IDirect3DCubeTexture9 **ppCubeTexture,
1058 HANDLE *pSharedHandle )
1059 {
1060 struct NineCubeTexture9 *tex;
1061 HRESULT hr;
1062
1063 DBG("This=%p EdgeLength=%u Levels=%u Usage=%s Format=%s Pool=%s ppOut=%p "
1064 "pSharedHandle=%p\n", This, EdgeLength, Levels,
1065 nine_D3DUSAGE_to_str(Usage), d3dformat_to_string(Format),
1066 nine_D3DPOOL_to_str(Pool), ppCubeTexture, pSharedHandle);
1067
1068 Usage &= D3DUSAGE_AUTOGENMIPMAP | D3DUSAGE_DEPTHSTENCIL | D3DUSAGE_DYNAMIC |
1069 D3DUSAGE_NONSECURE | D3DUSAGE_RENDERTARGET |
1070 D3DUSAGE_SOFTWAREPROCESSING;
1071
1072 *ppCubeTexture = NULL;
1073
1074 hr = NineCubeTexture9_new(This, EdgeLength, Levels, Usage, Format, Pool,
1075 &tex, pSharedHandle);
1076 if (SUCCEEDED(hr))
1077 *ppCubeTexture = (IDirect3DCubeTexture9 *)tex;
1078
1079 return hr;
1080 }
1081
1082 HRESULT NINE_WINAPI
1083 NineDevice9_CreateVertexBuffer( struct NineDevice9 *This,
1084 UINT Length,
1085 DWORD Usage,
1086 DWORD FVF,
1087 D3DPOOL Pool,
1088 IDirect3DVertexBuffer9 **ppVertexBuffer,
1089 HANDLE *pSharedHandle )
1090 {
1091 struct NineVertexBuffer9 *buf;
1092 HRESULT hr;
1093 D3DVERTEXBUFFER_DESC desc;
1094
1095 DBG("This=%p Length=%u Usage=%x FVF=%x Pool=%u ppOut=%p pSharedHandle=%p\n",
1096 This, Length, Usage, FVF, Pool, ppVertexBuffer, pSharedHandle);
1097
1098 user_assert(!pSharedHandle || Pool == D3DPOOL_DEFAULT, D3DERR_NOTAVAILABLE);
1099
1100 desc.Format = D3DFMT_VERTEXDATA;
1101 desc.Type = D3DRTYPE_VERTEXBUFFER;
1102 desc.Usage = Usage &
1103 (D3DUSAGE_DONOTCLIP | D3DUSAGE_DYNAMIC | D3DUSAGE_NONSECURE |
1104 D3DUSAGE_NPATCHES | D3DUSAGE_POINTS | D3DUSAGE_RTPATCHES |
1105 D3DUSAGE_SOFTWAREPROCESSING | D3DUSAGE_TEXTAPI |
1106 D3DUSAGE_WRITEONLY);
1107 desc.Pool = Pool;
1108 desc.Size = Length;
1109 desc.FVF = FVF;
1110
1111 user_assert(!pSharedHandle || Pool == D3DPOOL_DEFAULT, D3DERR_INVALIDCALL);
1112 user_assert(desc.Usage == Usage, D3DERR_INVALIDCALL);
1113
1114 hr = NineVertexBuffer9_new(This, &desc, &buf);
1115 if (SUCCEEDED(hr))
1116 *ppVertexBuffer = (IDirect3DVertexBuffer9 *)buf;
1117 return hr;
1118 }
1119
1120 HRESULT NINE_WINAPI
1121 NineDevice9_CreateIndexBuffer( struct NineDevice9 *This,
1122 UINT Length,
1123 DWORD Usage,
1124 D3DFORMAT Format,
1125 D3DPOOL Pool,
1126 IDirect3DIndexBuffer9 **ppIndexBuffer,
1127 HANDLE *pSharedHandle )
1128 {
1129 struct NineIndexBuffer9 *buf;
1130 HRESULT hr;
1131 D3DINDEXBUFFER_DESC desc;
1132
1133 DBG("This=%p Length=%u Usage=%x Format=%s Pool=%u ppOut=%p "
1134 "pSharedHandle=%p\n", This, Length, Usage,
1135 d3dformat_to_string(Format), Pool, ppIndexBuffer, pSharedHandle);
1136
1137 user_assert(!pSharedHandle || Pool == D3DPOOL_DEFAULT, D3DERR_NOTAVAILABLE);
1138
1139 desc.Format = Format;
1140 desc.Type = D3DRTYPE_INDEXBUFFER;
1141 desc.Usage = Usage &
1142 (D3DUSAGE_DONOTCLIP | D3DUSAGE_DYNAMIC | D3DUSAGE_NONSECURE |
1143 D3DUSAGE_NPATCHES | D3DUSAGE_POINTS | D3DUSAGE_RTPATCHES |
1144 D3DUSAGE_SOFTWAREPROCESSING | D3DUSAGE_WRITEONLY);
1145 desc.Pool = Pool;
1146 desc.Size = Length;
1147
1148 user_assert(!pSharedHandle || Pool == D3DPOOL_DEFAULT, D3DERR_INVALIDCALL);
1149 user_assert(desc.Usage == Usage, D3DERR_INVALIDCALL);
1150
1151 hr = NineIndexBuffer9_new(This, &desc, &buf);
1152 if (SUCCEEDED(hr))
1153 *ppIndexBuffer = (IDirect3DIndexBuffer9 *)buf;
1154 return hr;
1155 }
1156
1157 static HRESULT
1158 create_zs_or_rt_surface(struct NineDevice9 *This,
1159 unsigned type, /* 0 = RT, 1 = ZS, 2 = plain */
1160 D3DPOOL Pool,
1161 UINT Width, UINT Height,
1162 D3DFORMAT Format,
1163 D3DMULTISAMPLE_TYPE MultiSample,
1164 DWORD MultisampleQuality,
1165 BOOL Discard_or_Lockable,
1166 IDirect3DSurface9 **ppSurface,
1167 HANDLE *pSharedHandle)
1168 {
1169 struct NineSurface9 *surface;
1170 HRESULT hr;
1171 D3DSURFACE_DESC desc;
1172
1173 DBG("This=%p type=%u Pool=%s Width=%u Height=%u Format=%s MS=%u Quality=%u "
1174 "Discard_or_Lockable=%i ppSurface=%p pSharedHandle=%p\n",
1175 This, type, nine_D3DPOOL_to_str(Pool), Width, Height,
1176 d3dformat_to_string(Format), MultiSample, MultisampleQuality,
1177 Discard_or_Lockable, ppSurface, pSharedHandle);
1178
1179 if (pSharedHandle)
1180 DBG("FIXME Used shared handle! This option isn't probably handled correctly!\n");
1181
1182 user_assert(Width && Height, D3DERR_INVALIDCALL);
1183 user_assert(Pool != D3DPOOL_MANAGED, D3DERR_INVALIDCALL);
1184
1185 desc.Format = Format;
1186 desc.Type = D3DRTYPE_SURFACE;
1187 desc.Usage = 0;
1188 desc.Pool = Pool;
1189 desc.MultiSampleType = MultiSample;
1190 desc.MultiSampleQuality = MultisampleQuality;
1191 desc.Width = Width;
1192 desc.Height = Height;
1193 switch (type) {
1194 case 0: desc.Usage = D3DUSAGE_RENDERTARGET; break;
1195 case 1: desc.Usage = D3DUSAGE_DEPTHSTENCIL; break;
1196 default: assert(type == 2); break;
1197 }
1198
1199 hr = NineSurface9_new(This, NULL, NULL, NULL, 0, 0, 0, &desc, &surface);
1200 if (SUCCEEDED(hr)) {
1201 *ppSurface = (IDirect3DSurface9 *)surface;
1202
1203 if (surface->base.resource && Discard_or_Lockable && (type != 1))
1204 surface->base.resource->flags |= NINE_RESOURCE_FLAG_LOCKABLE;
1205 }
1206
1207 return hr;
1208 }
1209
1210 HRESULT NINE_WINAPI
1211 NineDevice9_CreateRenderTarget( struct NineDevice9 *This,
1212 UINT Width,
1213 UINT Height,
1214 D3DFORMAT Format,
1215 D3DMULTISAMPLE_TYPE MultiSample,
1216 DWORD MultisampleQuality,
1217 BOOL Lockable,
1218 IDirect3DSurface9 **ppSurface,
1219 HANDLE *pSharedHandle )
1220 {
1221 *ppSurface = NULL;
1222 return create_zs_or_rt_surface(This, 0, D3DPOOL_DEFAULT,
1223 Width, Height, Format,
1224 MultiSample, MultisampleQuality,
1225 Lockable, ppSurface, pSharedHandle);
1226 }
1227
1228 HRESULT NINE_WINAPI
1229 NineDevice9_CreateDepthStencilSurface( struct NineDevice9 *This,
1230 UINT Width,
1231 UINT Height,
1232 D3DFORMAT Format,
1233 D3DMULTISAMPLE_TYPE MultiSample,
1234 DWORD MultisampleQuality,
1235 BOOL Discard,
1236 IDirect3DSurface9 **ppSurface,
1237 HANDLE *pSharedHandle )
1238 {
1239 *ppSurface = NULL;
1240 if (!depth_stencil_format(Format))
1241 return D3DERR_NOTAVAILABLE;
1242 return create_zs_or_rt_surface(This, 1, D3DPOOL_DEFAULT,
1243 Width, Height, Format,
1244 MultiSample, MultisampleQuality,
1245 Discard, ppSurface, pSharedHandle);
1246 }
1247
1248 HRESULT NINE_WINAPI
1249 NineDevice9_UpdateSurface( struct NineDevice9 *This,
1250 IDirect3DSurface9 *pSourceSurface,
1251 const RECT *pSourceRect,
1252 IDirect3DSurface9 *pDestinationSurface,
1253 const POINT *pDestPoint )
1254 {
1255 struct NineSurface9 *dst = NineSurface9(pDestinationSurface);
1256 struct NineSurface9 *src = NineSurface9(pSourceSurface);
1257 int copy_width, copy_height;
1258 RECT destRect;
1259
1260 DBG("This=%p pSourceSurface=%p pDestinationSurface=%p "
1261 "pSourceRect=%p pDestPoint=%p\n", This,
1262 pSourceSurface, pDestinationSurface, pSourceRect, pDestPoint);
1263 if (pSourceRect)
1264 DBG("pSourceRect = (%u,%u)-(%u,%u)\n",
1265 pSourceRect->left, pSourceRect->top,
1266 pSourceRect->right, pSourceRect->bottom);
1267 if (pDestPoint)
1268 DBG("pDestPoint = (%u,%u)\n", pDestPoint->x, pDestPoint->y);
1269
1270 user_assert(dst && src, D3DERR_INVALIDCALL);
1271
1272 user_assert(dst->base.pool == D3DPOOL_DEFAULT, D3DERR_INVALIDCALL);
1273 user_assert(src->base.pool == D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL);
1274
1275 user_assert(dst->desc.MultiSampleType == D3DMULTISAMPLE_NONE, D3DERR_INVALIDCALL);
1276 user_assert(src->desc.MultiSampleType == D3DMULTISAMPLE_NONE, D3DERR_INVALIDCALL);
1277
1278 user_assert(!src->lock_count, D3DERR_INVALIDCALL);
1279 user_assert(!dst->lock_count, D3DERR_INVALIDCALL);
1280
1281 user_assert(dst->desc.Format == src->desc.Format, D3DERR_INVALIDCALL);
1282 user_assert(!depth_stencil_format(dst->desc.Format), D3DERR_INVALIDCALL);
1283
1284 if (pSourceRect) {
1285 copy_width = pSourceRect->right - pSourceRect->left;
1286 copy_height = pSourceRect->bottom - pSourceRect->top;
1287
1288 user_assert(pSourceRect->left >= 0 &&
1289 copy_width > 0 &&
1290 pSourceRect->right <= src->desc.Width &&
1291 pSourceRect->top >= 0 &&
1292 copy_height > 0 &&
1293 pSourceRect->bottom <= src->desc.Height,
1294 D3DERR_INVALIDCALL);
1295 } else {
1296 copy_width = src->desc.Width;
1297 copy_height = src->desc.Height;
1298 }
1299
1300 destRect.right = copy_width;
1301 destRect.bottom = copy_height;
1302
1303 if (pDestPoint) {
1304 user_assert(pDestPoint->x >= 0 && pDestPoint->y >= 0,
1305 D3DERR_INVALIDCALL);
1306 destRect.right += pDestPoint->x;
1307 destRect.bottom += pDestPoint->y;
1308 }
1309
1310 user_assert(destRect.right <= dst->desc.Width &&
1311 destRect.bottom <= dst->desc.Height,
1312 D3DERR_INVALIDCALL);
1313
1314 if (compressed_format(dst->desc.Format)) {
1315 const unsigned w = util_format_get_blockwidth(dst->base.info.format);
1316 const unsigned h = util_format_get_blockheight(dst->base.info.format);
1317
1318 if (pDestPoint) {
1319 user_assert(!(pDestPoint->x % w) && !(pDestPoint->y % h),
1320 D3DERR_INVALIDCALL);
1321 }
1322
1323 if (pSourceRect) {
1324 user_assert(!(pSourceRect->left % w) && !(pSourceRect->top % h),
1325 D3DERR_INVALIDCALL);
1326 }
1327 if (!(copy_width == src->desc.Width &&
1328 copy_width == dst->desc.Width &&
1329 copy_height == src->desc.Height &&
1330 copy_height == dst->desc.Height)) {
1331 user_assert(!(copy_width % w) && !(copy_height % h),
1332 D3DERR_INVALIDCALL);
1333 }
1334 }
1335
1336 NineSurface9_CopyMemToDefault(dst, src, pDestPoint, pSourceRect);
1337
1338 return D3D_OK;
1339 }
1340
1341 HRESULT NINE_WINAPI
1342 NineDevice9_UpdateTexture( struct NineDevice9 *This,
1343 IDirect3DBaseTexture9 *pSourceTexture,
1344 IDirect3DBaseTexture9 *pDestinationTexture )
1345 {
1346 struct NineBaseTexture9 *dstb = NineBaseTexture9(pDestinationTexture);
1347 struct NineBaseTexture9 *srcb = NineBaseTexture9(pSourceTexture);
1348 unsigned l, m;
1349 unsigned last_src_level, last_dst_level;
1350 RECT rect;
1351
1352 DBG("This=%p pSourceTexture=%p pDestinationTexture=%p\n", This,
1353 pSourceTexture, pDestinationTexture);
1354
1355 user_assert(pSourceTexture && pDestinationTexture, D3DERR_INVALIDCALL);
1356 user_assert(pSourceTexture != pDestinationTexture, D3DERR_INVALIDCALL);
1357
1358 user_assert(dstb->base.pool == D3DPOOL_DEFAULT, D3DERR_INVALIDCALL);
1359 user_assert(srcb->base.pool == D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL);
1360 user_assert(dstb->base.type == srcb->base.type, D3DERR_INVALIDCALL);
1361 user_assert(!(srcb->base.usage & D3DUSAGE_AUTOGENMIPMAP) ||
1362 dstb->base.usage & D3DUSAGE_AUTOGENMIPMAP, D3DERR_INVALIDCALL);
1363
1364 /* Spec: Failure if
1365 * . Different formats
1366 * . Fewer src levels than dst levels (if the opposite, only matching levels
1367 * are supposed to be copied)
1368 * . Levels do not match
1369 * DDI: Actually the above should pass because of legacy applications
1370 * Do what you want about these, but you shouldn't crash.
1371 * However driver can expect that the top dimension is greater for src than dst.
1372 * Wine tests: Every combination that passes the initial checks should pass.
1373 * . Different formats => conversion driver and format dependent.
1374 * . 1 level, but size not matching => copy is done (and even crash if src bigger
1375 * than dst. For the case where dst bigger, wine doesn't test if a stretch is applied
1376 * or if a subrect is copied).
1377 * . 8x8 4 sublevels -> 7x7 2 sublevels => driver dependent, On NV seems to be 4x4 subrect
1378 * copied to 7x7.
1379 *
1380 * From these, the proposal is:
1381 * . Different formats -> use util_format_translate to translate if possible for surfaces.
1382 * Accept ARGB/XRGB for Volumes. Do nothing for the other combinations
1383 * . First level copied -> the first level such that src is smaller or equal to dst first level
1384 * . number of levels copied -> as long as it fits and textures have levels
1385 * That should satisfy the constraints (and instead of crashing for some cases we return D3D_OK)
1386 */
1387
1388 last_src_level = (srcb->base.usage & D3DUSAGE_AUTOGENMIPMAP) ? 0 : srcb->base.info.last_level;
1389 last_dst_level = (dstb->base.usage & D3DUSAGE_AUTOGENMIPMAP) ? 0 : dstb->base.info.last_level;
1390
1391 for (m = 0; m <= last_src_level; ++m) {
1392 unsigned w = u_minify(srcb->base.info.width0, m);
1393 unsigned h = u_minify(srcb->base.info.height0, m);
1394 unsigned d = u_minify(srcb->base.info.depth0, m);
1395
1396 if (w <= dstb->base.info.width0 &&
1397 h <= dstb->base.info.height0 &&
1398 d <= dstb->base.info.depth0)
1399 break;
1400 }
1401 user_assert(m <= last_src_level, D3D_OK);
1402
1403 last_dst_level = MIN2(srcb->base.info.last_level - m, last_dst_level);
1404
1405 if (dstb->base.type == D3DRTYPE_TEXTURE) {
1406 struct NineTexture9 *dst = NineTexture9(dstb);
1407 struct NineTexture9 *src = NineTexture9(srcb);
1408
1409 if (src->dirty_rect.width == 0)
1410 return D3D_OK;
1411
1412 pipe_box_to_rect(&rect, &src->dirty_rect);
1413 for (l = 0; l < m; ++l)
1414 rect_minify_inclusive(&rect);
1415
1416 for (l = 0; l <= last_dst_level; ++l, ++m) {
1417 fit_rect_format_inclusive(dst->base.base.info.format,
1418 &rect,
1419 dst->surfaces[l]->desc.Width,
1420 dst->surfaces[l]->desc.Height);
1421 NineSurface9_CopyMemToDefault(dst->surfaces[l],
1422 src->surfaces[m],
1423 (POINT *)&rect,
1424 &rect);
1425 rect_minify_inclusive(&rect);
1426 }
1427 u_box_origin_2d(0, 0, &src->dirty_rect);
1428 } else
1429 if (dstb->base.type == D3DRTYPE_CUBETEXTURE) {
1430 struct NineCubeTexture9 *dst = NineCubeTexture9(dstb);
1431 struct NineCubeTexture9 *src = NineCubeTexture9(srcb);
1432 unsigned z;
1433
1434 /* GPUs usually have them stored as arrays of mip-mapped 2D textures. */
1435 for (z = 0; z < 6; ++z) {
1436 if (src->dirty_rect[z].width == 0)
1437 continue;
1438
1439 pipe_box_to_rect(&rect, &src->dirty_rect[z]);
1440 for (l = 0; l < m; ++l)
1441 rect_minify_inclusive(&rect);
1442
1443 for (l = 0; l <= last_dst_level; ++l, ++m) {
1444 fit_rect_format_inclusive(dst->base.base.info.format,
1445 &rect,
1446 dst->surfaces[l * 6 + z]->desc.Width,
1447 dst->surfaces[l * 6 + z]->desc.Height);
1448 NineSurface9_CopyMemToDefault(dst->surfaces[l * 6 + z],
1449 src->surfaces[m * 6 + z],
1450 (POINT *)&rect,
1451 &rect);
1452 rect_minify_inclusive(&rect);
1453 }
1454 u_box_origin_2d(0, 0, &src->dirty_rect[z]);
1455 m -= l;
1456 }
1457 } else
1458 if (dstb->base.type == D3DRTYPE_VOLUMETEXTURE) {
1459 struct NineVolumeTexture9 *dst = NineVolumeTexture9(dstb);
1460 struct NineVolumeTexture9 *src = NineVolumeTexture9(srcb);
1461
1462 if (src->dirty_box.width == 0)
1463 return D3D_OK;
1464 for (l = 0; l <= last_dst_level; ++l, ++m)
1465 NineVolume9_CopyMemToDefault(dst->volumes[l],
1466 src->volumes[m], 0, 0, 0, NULL);
1467 u_box_3d(0, 0, 0, 0, 0, 0, &src->dirty_box);
1468 } else{
1469 assert(!"invalid texture type");
1470 }
1471
1472 if (dstb->base.usage & D3DUSAGE_AUTOGENMIPMAP) {
1473 dstb->dirty_mip = TRUE;
1474 NineBaseTexture9_GenerateMipSubLevels(dstb);
1475 }
1476
1477 return D3D_OK;
1478 }
1479
1480 HRESULT NINE_WINAPI
1481 NineDevice9_GetRenderTargetData( struct NineDevice9 *This,
1482 IDirect3DSurface9 *pRenderTarget,
1483 IDirect3DSurface9 *pDestSurface )
1484 {
1485 struct NineSurface9 *dst = NineSurface9(pDestSurface);
1486 struct NineSurface9 *src = NineSurface9(pRenderTarget);
1487
1488 DBG("This=%p pRenderTarget=%p pDestSurface=%p\n",
1489 This, pRenderTarget, pDestSurface);
1490
1491 user_assert(pRenderTarget && pDestSurface, D3DERR_INVALIDCALL);
1492
1493 user_assert(dst->desc.Pool == D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL);
1494 user_assert(src->desc.Pool == D3DPOOL_DEFAULT, D3DERR_INVALIDCALL);
1495
1496 user_assert(dst->desc.MultiSampleType < 2, D3DERR_INVALIDCALL);
1497 user_assert(src->desc.MultiSampleType < 2, D3DERR_INVALIDCALL);
1498
1499 user_assert(src->desc.Width == dst->desc.Width, D3DERR_INVALIDCALL);
1500 user_assert(src->desc.Height == dst->desc.Height, D3DERR_INVALIDCALL);
1501
1502 user_assert(src->desc.Format != D3DFMT_NULL, D3DERR_INVALIDCALL);
1503
1504 NineSurface9_CopyDefaultToMem(dst, src);
1505
1506 return D3D_OK;
1507 }
1508
1509 HRESULT NINE_WINAPI
1510 NineDevice9_GetFrontBufferData( struct NineDevice9 *This,
1511 UINT iSwapChain,
1512 IDirect3DSurface9 *pDestSurface )
1513 {
1514 DBG("This=%p iSwapChain=%u pDestSurface=%p\n", This,
1515 iSwapChain, pDestSurface);
1516
1517 user_assert(pDestSurface != NULL, D3DERR_INVALIDCALL);
1518 user_assert(iSwapChain < This->nswapchains, D3DERR_INVALIDCALL);
1519
1520 return NineSwapChain9_GetFrontBufferData(This->swapchains[iSwapChain],
1521 pDestSurface);
1522 }
1523
1524 HRESULT NINE_WINAPI
1525 NineDevice9_StretchRect( struct NineDevice9 *This,
1526 IDirect3DSurface9 *pSourceSurface,
1527 const RECT *pSourceRect,
1528 IDirect3DSurface9 *pDestSurface,
1529 const RECT *pDestRect,
1530 D3DTEXTUREFILTERTYPE Filter )
1531 {
1532 struct pipe_screen *screen = This->screen;
1533 struct pipe_context *pipe = This->pipe;
1534 struct NineSurface9 *dst = NineSurface9(pDestSurface);
1535 struct NineSurface9 *src = NineSurface9(pSourceSurface);
1536 struct pipe_resource *dst_res = NineSurface9_GetResource(dst);
1537 struct pipe_resource *src_res = NineSurface9_GetResource(src);
1538 boolean zs;
1539 struct pipe_blit_info blit;
1540 boolean scaled, clamped, ms, flip_x = FALSE, flip_y = FALSE;
1541
1542 DBG("This=%p pSourceSurface=%p pSourceRect=%p pDestSurface=%p "
1543 "pDestRect=%p Filter=%u\n",
1544 This, pSourceSurface, pSourceRect, pDestSurface, pDestRect, Filter);
1545 if (pSourceRect)
1546 DBG("pSourceRect=(%u,%u)-(%u,%u)\n",
1547 pSourceRect->left, pSourceRect->top,
1548 pSourceRect->right, pSourceRect->bottom);
1549 if (pDestRect)
1550 DBG("pDestRect=(%u,%u)-(%u,%u)\n", pDestRect->left, pDestRect->top,
1551 pDestRect->right, pDestRect->bottom);
1552
1553 user_assert(dst->base.pool == D3DPOOL_DEFAULT &&
1554 src->base.pool == D3DPOOL_DEFAULT, D3DERR_INVALIDCALL);
1555 zs = util_format_is_depth_or_stencil(dst_res->format);
1556 user_assert(!zs || !This->in_scene, D3DERR_INVALIDCALL);
1557 user_assert(!zs || !pSourceRect ||
1558 (pSourceRect->left == 0 &&
1559 pSourceRect->top == 0 &&
1560 pSourceRect->right == src->desc.Width &&
1561 pSourceRect->bottom == src->desc.Height), D3DERR_INVALIDCALL);
1562 user_assert(!zs || !pDestRect ||
1563 (pDestRect->left == 0 &&
1564 pDestRect->top == 0 &&
1565 pDestRect->right == dst->desc.Width &&
1566 pDestRect->bottom == dst->desc.Height), D3DERR_INVALIDCALL);
1567 user_assert(!zs ||
1568 (dst->desc.Width == src->desc.Width &&
1569 dst->desc.Height == src->desc.Height), D3DERR_INVALIDCALL);
1570 user_assert(zs || !util_format_is_depth_or_stencil(src_res->format),
1571 D3DERR_INVALIDCALL);
1572 user_assert(!zs || dst->desc.Format == src->desc.Format,
1573 D3DERR_INVALIDCALL);
1574 user_assert(screen->is_format_supported(screen, src_res->format,
1575 src_res->target,
1576 src_res->nr_samples,
1577 PIPE_BIND_SAMPLER_VIEW),
1578 D3DERR_INVALIDCALL);
1579
1580 /* We might want to permit these, but wine thinks we shouldn't. */
1581 user_assert(!pDestRect ||
1582 (pDestRect->left <= pDestRect->right &&
1583 pDestRect->top <= pDestRect->bottom), D3DERR_INVALIDCALL);
1584 user_assert(!pSourceRect ||
1585 (pSourceRect->left <= pSourceRect->right &&
1586 pSourceRect->top <= pSourceRect->bottom), D3DERR_INVALIDCALL);
1587
1588 memset(&blit, 0, sizeof(blit));
1589 blit.dst.resource = dst_res;
1590 blit.dst.level = dst->level;
1591 blit.dst.box.z = dst->layer;
1592 blit.dst.box.depth = 1;
1593 blit.dst.format = dst_res->format;
1594 if (pDestRect) {
1595 flip_x = pDestRect->left > pDestRect->right;
1596 if (flip_x) {
1597 blit.dst.box.x = pDestRect->right;
1598 blit.dst.box.width = pDestRect->left - pDestRect->right;
1599 } else {
1600 blit.dst.box.x = pDestRect->left;
1601 blit.dst.box.width = pDestRect->right - pDestRect->left;
1602 }
1603 flip_y = pDestRect->top > pDestRect->bottom;
1604 if (flip_y) {
1605 blit.dst.box.y = pDestRect->bottom;
1606 blit.dst.box.height = pDestRect->top - pDestRect->bottom;
1607 } else {
1608 blit.dst.box.y = pDestRect->top;
1609 blit.dst.box.height = pDestRect->bottom - pDestRect->top;
1610 }
1611 } else {
1612 blit.dst.box.x = 0;
1613 blit.dst.box.y = 0;
1614 blit.dst.box.width = dst->desc.Width;
1615 blit.dst.box.height = dst->desc.Height;
1616 }
1617 blit.src.resource = src_res;
1618 blit.src.level = src->level;
1619 blit.src.box.z = src->layer;
1620 blit.src.box.depth = 1;
1621 blit.src.format = src_res->format;
1622 if (pSourceRect) {
1623 if (flip_x ^ (pSourceRect->left > pSourceRect->right)) {
1624 blit.src.box.x = pSourceRect->right;
1625 blit.src.box.width = pSourceRect->left - pSourceRect->right;
1626 } else {
1627 blit.src.box.x = pSourceRect->left;
1628 blit.src.box.width = pSourceRect->right - pSourceRect->left;
1629 }
1630 if (flip_y ^ (pSourceRect->top > pSourceRect->bottom)) {
1631 blit.src.box.y = pSourceRect->bottom;
1632 blit.src.box.height = pSourceRect->top - pSourceRect->bottom;
1633 } else {
1634 blit.src.box.y = pSourceRect->top;
1635 blit.src.box.height = pSourceRect->bottom - pSourceRect->top;
1636 }
1637 } else {
1638 blit.src.box.x = flip_x ? src->desc.Width : 0;
1639 blit.src.box.y = flip_y ? src->desc.Height : 0;
1640 blit.src.box.width = flip_x ? -src->desc.Width : src->desc.Width;
1641 blit.src.box.height = flip_y ? -src->desc.Height : src->desc.Height;
1642 }
1643 blit.mask = zs ? PIPE_MASK_ZS : PIPE_MASK_RGBA;
1644 blit.filter = Filter == D3DTEXF_LINEAR ?
1645 PIPE_TEX_FILTER_LINEAR : PIPE_TEX_FILTER_NEAREST;
1646 blit.scissor_enable = FALSE;
1647 blit.alpha_blend = FALSE;
1648
1649 /* If both of a src and dst dimension are negative, flip them. */
1650 if (blit.dst.box.width < 0 && blit.src.box.width < 0) {
1651 blit.dst.box.width = -blit.dst.box.width;
1652 blit.src.box.width = -blit.src.box.width;
1653 }
1654 if (blit.dst.box.height < 0 && blit.src.box.height < 0) {
1655 blit.dst.box.height = -blit.dst.box.height;
1656 blit.src.box.height = -blit.src.box.height;
1657 }
1658 scaled =
1659 blit.dst.box.width != blit.src.box.width ||
1660 blit.dst.box.height != blit.src.box.height;
1661
1662 user_assert(!scaled || dst != src, D3DERR_INVALIDCALL);
1663 user_assert(!scaled ||
1664 !NineSurface9_IsOffscreenPlain(dst), D3DERR_INVALIDCALL);
1665 user_assert(!NineSurface9_IsOffscreenPlain(dst) ||
1666 NineSurface9_IsOffscreenPlain(src), D3DERR_INVALIDCALL);
1667 user_assert(NineSurface9_IsOffscreenPlain(dst) ||
1668 dst->desc.Usage & (D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL),
1669 D3DERR_INVALIDCALL);
1670 user_assert(!scaled ||
1671 (!util_format_is_compressed(dst->base.info.format) &&
1672 !util_format_is_compressed(src->base.info.format)),
1673 D3DERR_INVALIDCALL);
1674
1675 user_warn(src == dst &&
1676 u_box_test_intersection_2d(&blit.src.box, &blit.dst.box));
1677
1678 /* Check for clipping/clamping: */
1679 {
1680 struct pipe_box box;
1681 int xy;
1682
1683 xy = u_box_clip_2d(&box, &blit.dst.box,
1684 dst->desc.Width, dst->desc.Height);
1685 if (xy < 0)
1686 return D3D_OK;
1687 if (xy == 0)
1688 xy = u_box_clip_2d(&box, &blit.src.box,
1689 src->desc.Width, src->desc.Height);
1690 clamped = !!xy;
1691 }
1692
1693 ms = (dst->desc.MultiSampleType != src->desc.MultiSampleType) ||
1694 (dst->desc.MultiSampleQuality != src->desc.MultiSampleQuality);
1695
1696 if (clamped || scaled || (blit.dst.format != blit.src.format) || ms) {
1697 DBG("using pipe->blit()\n");
1698 /* TODO: software scaling */
1699 user_assert(screen->is_format_supported(screen, dst_res->format,
1700 dst_res->target,
1701 dst_res->nr_samples,
1702 zs ? PIPE_BIND_DEPTH_STENCIL :
1703 PIPE_BIND_RENDER_TARGET),
1704 D3DERR_INVALIDCALL);
1705
1706 pipe->blit(pipe, &blit);
1707 } else {
1708 assert(blit.dst.box.x >= 0 && blit.dst.box.y >= 0 &&
1709 blit.src.box.x >= 0 && blit.src.box.y >= 0 &&
1710 blit.dst.box.x + blit.dst.box.width <= dst->desc.Width &&
1711 blit.src.box.x + blit.src.box.width <= src->desc.Width &&
1712 blit.dst.box.y + blit.dst.box.height <= dst->desc.Height &&
1713 blit.src.box.y + blit.src.box.height <= src->desc.Height);
1714 /* Or drivers might crash ... */
1715 DBG("Using resource_copy_region.\n");
1716 pipe->resource_copy_region(pipe,
1717 blit.dst.resource, blit.dst.level,
1718 blit.dst.box.x, blit.dst.box.y, blit.dst.box.z,
1719 blit.src.resource, blit.src.level,
1720 &blit.src.box);
1721 }
1722
1723 /* Communicate the container it needs to update sublevels - if apply */
1724 NineSurface9_MarkContainerDirty(dst);
1725
1726 return D3D_OK;
1727 }
1728
1729 HRESULT NINE_WINAPI
1730 NineDevice9_ColorFill( struct NineDevice9 *This,
1731 IDirect3DSurface9 *pSurface,
1732 const RECT *pRect,
1733 D3DCOLOR color )
1734 {
1735 struct pipe_context *pipe = This->pipe;
1736 struct NineSurface9 *surf = NineSurface9(pSurface);
1737 struct pipe_surface *psurf;
1738 unsigned x, y, w, h;
1739 union pipe_color_union rgba;
1740 boolean fallback;
1741
1742 DBG("This=%p pSurface=%p pRect=%p color=%08x\n", This,
1743 pSurface, pRect, color);
1744 if (pRect)
1745 DBG("pRect=(%u,%u)-(%u,%u)\n", pRect->left, pRect->top,
1746 pRect->right, pRect->bottom);
1747
1748 user_assert(surf->base.pool == D3DPOOL_DEFAULT, D3DERR_INVALIDCALL);
1749
1750 user_assert((surf->base.usage & D3DUSAGE_RENDERTARGET) ||
1751 NineSurface9_IsOffscreenPlain(surf), D3DERR_INVALIDCALL);
1752
1753 user_assert(surf->desc.Format != D3DFMT_NULL, D3D_OK);
1754
1755 if (pRect) {
1756 x = pRect->left;
1757 y = pRect->top;
1758 w = pRect->right - pRect->left;
1759 h = pRect->bottom - pRect->top;
1760 /* Wine tests: */
1761 if (compressed_format(surf->desc.Format)) {
1762 const unsigned bw = util_format_get_blockwidth(surf->base.info.format);
1763 const unsigned bh = util_format_get_blockheight(surf->base.info.format);
1764
1765 user_assert(!(x % bw) && !(y % bh) && !(w % bw) && !(h % bh),
1766 D3DERR_INVALIDCALL);
1767 }
1768 } else{
1769 x = 0;
1770 y = 0;
1771 w = surf->desc.Width;
1772 h = surf->desc.Height;
1773 }
1774 d3dcolor_to_pipe_color_union(&rgba, color);
1775
1776 fallback = !(surf->base.info.bind & PIPE_BIND_RENDER_TARGET);
1777
1778 if (!fallback) {
1779 psurf = NineSurface9_GetSurface(surf, 0);
1780 if (!psurf)
1781 fallback = TRUE;
1782 }
1783
1784 if (!fallback) {
1785 pipe->clear_render_target(pipe, psurf, &rgba, x, y, w, h, false);
1786 } else {
1787 D3DLOCKED_RECT lock;
1788 union util_color uc;
1789 HRESULT hr;
1790 /* XXX: lock pRect and fix util_fill_rect */
1791 hr = NineSurface9_LockRect(surf, &lock, NULL, 0);
1792 if (FAILED(hr))
1793 return hr;
1794 util_pack_color_ub(color >> 16, color >> 8, color >> 0, color >> 24,
1795 surf->base.info.format, &uc);
1796 util_fill_rect(lock.pBits, surf->base.info.format,lock.Pitch,
1797 x, y, w, h, &uc);
1798 NineSurface9_UnlockRect(surf);
1799 }
1800
1801 return D3D_OK;
1802 }
1803
1804 HRESULT NINE_WINAPI
1805 NineDevice9_CreateOffscreenPlainSurface( struct NineDevice9 *This,
1806 UINT Width,
1807 UINT Height,
1808 D3DFORMAT Format,
1809 D3DPOOL Pool,
1810 IDirect3DSurface9 **ppSurface,
1811 HANDLE *pSharedHandle )
1812 {
1813 HRESULT hr;
1814
1815 DBG("This=%p Width=%u Height=%u Format=%s(0x%x) Pool=%u "
1816 "ppSurface=%p pSharedHandle=%p\n", This,
1817 Width, Height, d3dformat_to_string(Format), Format, Pool,
1818 ppSurface, pSharedHandle);
1819
1820 *ppSurface = NULL;
1821 user_assert(!pSharedHandle || Pool == D3DPOOL_DEFAULT
1822 || Pool == D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL);
1823 user_assert(Pool != D3DPOOL_MANAGED, D3DERR_INVALIDCALL);
1824
1825 /* Can be used with StretchRect and ColorFill. It's also always lockable.
1826 */
1827 hr = create_zs_or_rt_surface(This, 2, Pool, Width, Height,
1828 Format,
1829 D3DMULTISAMPLE_NONE, 0,
1830 TRUE,
1831 ppSurface, pSharedHandle);
1832 if (FAILED(hr))
1833 DBG("Failed to create surface.\n");
1834 return hr;
1835 }
1836
1837 HRESULT NINE_WINAPI
1838 NineDevice9_SetRenderTarget( struct NineDevice9 *This,
1839 DWORD RenderTargetIndex,
1840 IDirect3DSurface9 *pRenderTarget )
1841 {
1842 struct NineSurface9 *rt = NineSurface9(pRenderTarget);
1843 const unsigned i = RenderTargetIndex;
1844
1845 DBG("This=%p RenderTargetIndex=%u pRenderTarget=%p\n", This,
1846 RenderTargetIndex, pRenderTarget);
1847
1848 user_assert(i < This->caps.NumSimultaneousRTs, D3DERR_INVALIDCALL);
1849 user_assert(i != 0 || pRenderTarget, D3DERR_INVALIDCALL);
1850 user_assert(!pRenderTarget ||
1851 rt->desc.Usage & D3DUSAGE_RENDERTARGET, D3DERR_INVALIDCALL);
1852
1853 if (i == 0) {
1854 This->state.viewport.X = 0;
1855 This->state.viewport.Y = 0;
1856 This->state.viewport.Width = rt->desc.Width;
1857 This->state.viewport.Height = rt->desc.Height;
1858 This->state.viewport.MinZ = 0.0f;
1859 This->state.viewport.MaxZ = 1.0f;
1860
1861 This->state.scissor.minx = 0;
1862 This->state.scissor.miny = 0;
1863 This->state.scissor.maxx = rt->desc.Width;
1864 This->state.scissor.maxy = rt->desc.Height;
1865 }
1866
1867 if (This->state.rt[i] != NineSurface9(pRenderTarget))
1868 nine_bind(&This->state.rt[i], pRenderTarget);
1869
1870 nine_context_set_render_target(This, i, rt);
1871 return D3D_OK;
1872 }
1873
1874 HRESULT NINE_WINAPI
1875 NineDevice9_GetRenderTarget( struct NineDevice9 *This,
1876 DWORD RenderTargetIndex,
1877 IDirect3DSurface9 **ppRenderTarget )
1878 {
1879 const unsigned i = RenderTargetIndex;
1880
1881 user_assert(i < This->caps.NumSimultaneousRTs, D3DERR_INVALIDCALL);
1882 user_assert(ppRenderTarget, D3DERR_INVALIDCALL);
1883
1884 *ppRenderTarget = (IDirect3DSurface9 *)This->state.rt[i];
1885 if (!This->state.rt[i])
1886 return D3DERR_NOTFOUND;
1887
1888 NineUnknown_AddRef(NineUnknown(This->state.rt[i]));
1889 return D3D_OK;
1890 }
1891
1892 HRESULT NINE_WINAPI
1893 NineDevice9_SetDepthStencilSurface( struct NineDevice9 *This,
1894 IDirect3DSurface9 *pNewZStencil )
1895 {
1896 DBG("This=%p pNewZStencil=%p\n", This, pNewZStencil);
1897
1898 if (This->state.ds != NineSurface9(pNewZStencil)) {
1899 nine_bind(&This->state.ds, pNewZStencil);
1900 This->state.changed.group |= NINE_STATE_FB;
1901 }
1902 return D3D_OK;
1903 }
1904
1905 HRESULT NINE_WINAPI
1906 NineDevice9_GetDepthStencilSurface( struct NineDevice9 *This,
1907 IDirect3DSurface9 **ppZStencilSurface )
1908 {
1909 user_assert(ppZStencilSurface, D3DERR_INVALIDCALL);
1910
1911 *ppZStencilSurface = (IDirect3DSurface9 *)This->state.ds;
1912 if (!This->state.ds)
1913 return D3DERR_NOTFOUND;
1914
1915 NineUnknown_AddRef(NineUnknown(This->state.ds));
1916 return D3D_OK;
1917 }
1918
1919 HRESULT NINE_WINAPI
1920 NineDevice9_BeginScene( struct NineDevice9 *This )
1921 {
1922 DBG("This=%p\n", This);
1923 user_assert(!This->in_scene, D3DERR_INVALIDCALL);
1924 This->in_scene = TRUE;
1925 /* Do we want to do anything else here ? */
1926 return D3D_OK;
1927 }
1928
1929 HRESULT NINE_WINAPI
1930 NineDevice9_EndScene( struct NineDevice9 *This )
1931 {
1932 DBG("This=%p\n", This);
1933 user_assert(This->in_scene, D3DERR_INVALIDCALL);
1934 This->in_scene = FALSE;
1935 return D3D_OK;
1936 }
1937
1938 HRESULT NINE_WINAPI
1939 NineDevice9_Clear( struct NineDevice9 *This,
1940 DWORD Count,
1941 const D3DRECT *pRects,
1942 DWORD Flags,
1943 D3DCOLOR Color,
1944 float Z,
1945 DWORD Stencil )
1946 {
1947 struct NineSurface9 *zsbuf_surf = This->state.ds;
1948
1949 DBG("This=%p Count=%u pRects=%p Flags=%x Color=%08x Z=%f Stencil=%x\n",
1950 This, Count, pRects, Flags, Color, Z, Stencil);
1951
1952 user_assert(This->state.ds || !(Flags & NINED3DCLEAR_DEPTHSTENCIL),
1953 D3DERR_INVALIDCALL);
1954 user_assert(!(Flags & D3DCLEAR_STENCIL) ||
1955 (zsbuf_surf &&
1956 util_format_is_depth_and_stencil(zsbuf_surf->base.info.format)),
1957 D3DERR_INVALIDCALL);
1958 #ifdef NINE_STRICT
1959 user_assert((Count && pRects) || (!Count && !pRects), D3DERR_INVALIDCALL);
1960 #else
1961 user_warn((pRects && !Count) || (!pRects && Count));
1962 if (pRects && !Count)
1963 return D3D_OK;
1964 if (!pRects)
1965 Count = 0;
1966 #endif
1967
1968 nine_context_clear_fb(This, Count, pRects, Flags, Color, Z, Stencil);
1969 return D3D_OK;
1970 }
1971
1972 HRESULT NINE_WINAPI
1973 NineDevice9_SetTransform( struct NineDevice9 *This,
1974 D3DTRANSFORMSTATETYPE State,
1975 const D3DMATRIX *pMatrix )
1976 {
1977 struct nine_state *state = This->update;
1978 D3DMATRIX *M = nine_state_access_transform(state, State, TRUE);
1979
1980 DBG("This=%p State=%d pMatrix=%p\n", This, State, pMatrix);
1981
1982 user_assert(M, D3DERR_INVALIDCALL);
1983
1984 *M = *pMatrix;
1985 state->ff.changed.transform[State / 32] |= 1 << (State % 32);
1986 state->changed.group |= NINE_STATE_FF;
1987
1988 return D3D_OK;
1989 }
1990
1991 HRESULT NINE_WINAPI
1992 NineDevice9_GetTransform( struct NineDevice9 *This,
1993 D3DTRANSFORMSTATETYPE State,
1994 D3DMATRIX *pMatrix )
1995 {
1996 D3DMATRIX *M = nine_state_access_transform(&This->state, State, FALSE);
1997 user_assert(M, D3DERR_INVALIDCALL);
1998 *pMatrix = *M;
1999 return D3D_OK;
2000 }
2001
2002 HRESULT NINE_WINAPI
2003 NineDevice9_MultiplyTransform( struct NineDevice9 *This,
2004 D3DTRANSFORMSTATETYPE State,
2005 const D3DMATRIX *pMatrix )
2006 {
2007 struct nine_state *state = This->update;
2008 D3DMATRIX T;
2009 D3DMATRIX *M = nine_state_access_transform(state, State, TRUE);
2010
2011 DBG("This=%p State=%d pMatrix=%p\n", This, State, pMatrix);
2012
2013 user_assert(M, D3DERR_INVALIDCALL);
2014
2015 nine_d3d_matrix_matrix_mul(&T, pMatrix, M);
2016 return NineDevice9_SetTransform(This, State, &T);
2017 }
2018
2019 HRESULT NINE_WINAPI
2020 NineDevice9_SetViewport( struct NineDevice9 *This,
2021 const D3DVIEWPORT9 *pViewport )
2022 {
2023 struct nine_state *state = This->update;
2024
2025 DBG("X=%u Y=%u W=%u H=%u MinZ=%f MaxZ=%f\n",
2026 pViewport->X, pViewport->Y, pViewport->Width, pViewport->Height,
2027 pViewport->MinZ, pViewport->MaxZ);
2028
2029 state->viewport = *pViewport;
2030 nine_context_set_viewport(This, pViewport);
2031
2032 return D3D_OK;
2033 }
2034
2035 HRESULT NINE_WINAPI
2036 NineDevice9_GetViewport( struct NineDevice9 *This,
2037 D3DVIEWPORT9 *pViewport )
2038 {
2039 *pViewport = This->state.viewport;
2040 return D3D_OK;
2041 }
2042
2043 HRESULT NINE_WINAPI
2044 NineDevice9_SetMaterial( struct NineDevice9 *This,
2045 const D3DMATERIAL9 *pMaterial )
2046 {
2047 struct nine_state *state = This->update;
2048
2049 DBG("This=%p pMaterial=%p\n", This, pMaterial);
2050 if (pMaterial)
2051 nine_dump_D3DMATERIAL9(DBG_FF, pMaterial);
2052
2053 user_assert(pMaterial, E_POINTER);
2054
2055 state->ff.material = *pMaterial;
2056 state->changed.group |= NINE_STATE_FF_MATERIAL;
2057
2058 return D3D_OK;
2059 }
2060
2061 HRESULT NINE_WINAPI
2062 NineDevice9_GetMaterial( struct NineDevice9 *This,
2063 D3DMATERIAL9 *pMaterial )
2064 {
2065 user_assert(pMaterial, E_POINTER);
2066 *pMaterial = This->state.ff.material;
2067 return D3D_OK;
2068 }
2069
2070 HRESULT NINE_WINAPI
2071 NineDevice9_SetLight( struct NineDevice9 *This,
2072 DWORD Index,
2073 const D3DLIGHT9 *pLight )
2074 {
2075 struct nine_state *state = This->update;
2076
2077 DBG("This=%p Index=%u pLight=%p\n", This, Index, pLight);
2078 if (pLight)
2079 nine_dump_D3DLIGHT9(DBG_FF, pLight);
2080
2081 user_assert(pLight, D3DERR_INVALIDCALL);
2082 user_assert(pLight->Type < NINED3DLIGHT_INVALID, D3DERR_INVALIDCALL);
2083
2084 user_assert(Index < NINE_MAX_LIGHTS, D3DERR_INVALIDCALL); /* sanity */
2085
2086 if (Index >= state->ff.num_lights) {
2087 unsigned n = state->ff.num_lights;
2088 unsigned N = Index + 1;
2089
2090 state->ff.light = REALLOC(state->ff.light, n * sizeof(D3DLIGHT9),
2091 N * sizeof(D3DLIGHT9));
2092 if (!state->ff.light)
2093 return E_OUTOFMEMORY;
2094 state->ff.num_lights = N;
2095
2096 for (; n < Index; ++n) {
2097 memset(&state->ff.light[n], 0, sizeof(D3DLIGHT9));
2098 state->ff.light[n].Type = (D3DLIGHTTYPE)NINED3DLIGHT_INVALID;
2099 }
2100 }
2101 state->ff.light[Index] = *pLight;
2102
2103 if (pLight->Type == D3DLIGHT_SPOT && pLight->Theta >= pLight->Phi) {
2104 DBG("Warning: clamping D3DLIGHT9.Theta\n");
2105 state->ff.light[Index].Theta = state->ff.light[Index].Phi;
2106 }
2107 if (pLight->Type != D3DLIGHT_DIRECTIONAL &&
2108 pLight->Attenuation0 == 0.0f &&
2109 pLight->Attenuation1 == 0.0f &&
2110 pLight->Attenuation2 == 0.0f) {
2111 DBG("Warning: all D3DLIGHT9.Attenuation[i] are 0\n");
2112 }
2113
2114 state->changed.group |= NINE_STATE_FF_LIGHTING;
2115
2116 return D3D_OK;
2117 }
2118
2119 HRESULT NINE_WINAPI
2120 NineDevice9_GetLight( struct NineDevice9 *This,
2121 DWORD Index,
2122 D3DLIGHT9 *pLight )
2123 {
2124 const struct nine_state *state = &This->state;
2125
2126 user_assert(pLight, D3DERR_INVALIDCALL);
2127 user_assert(Index < state->ff.num_lights, D3DERR_INVALIDCALL);
2128 user_assert(state->ff.light[Index].Type < NINED3DLIGHT_INVALID,
2129 D3DERR_INVALIDCALL);
2130
2131 *pLight = state->ff.light[Index];
2132
2133 return D3D_OK;
2134 }
2135
2136 HRESULT NINE_WINAPI
2137 NineDevice9_LightEnable( struct NineDevice9 *This,
2138 DWORD Index,
2139 BOOL Enable )
2140 {
2141 struct nine_state *state = This->update;
2142 unsigned i;
2143
2144 DBG("This=%p Index=%u Enable=%i\n", This, Index, Enable);
2145
2146 if (Index >= state->ff.num_lights ||
2147 state->ff.light[Index].Type == NINED3DLIGHT_INVALID) {
2148 /* This should create a default light. */
2149 D3DLIGHT9 light;
2150 memset(&light, 0, sizeof(light));
2151 light.Type = D3DLIGHT_DIRECTIONAL;
2152 light.Diffuse.r = 1.0f;
2153 light.Diffuse.g = 1.0f;
2154 light.Diffuse.b = 1.0f;
2155 light.Direction.z = 1.0f;
2156 NineDevice9_SetLight(This, Index, &light);
2157 }
2158 user_assert(Index < state->ff.num_lights, D3DERR_INVALIDCALL);
2159
2160 for (i = 0; i < state->ff.num_lights_active; ++i) {
2161 if (state->ff.active_light[i] == Index)
2162 break;
2163 }
2164
2165 if (Enable) {
2166 if (i < state->ff.num_lights_active)
2167 return D3D_OK;
2168 /* XXX wine thinks this should still succeed:
2169 */
2170 user_assert(i < NINE_MAX_LIGHTS_ACTIVE, D3DERR_INVALIDCALL);
2171
2172 state->ff.active_light[i] = Index;
2173 state->ff.num_lights_active++;
2174 } else {
2175 if (i == state->ff.num_lights_active)
2176 return D3D_OK;
2177 --state->ff.num_lights_active;
2178 for (; i < state->ff.num_lights_active; ++i)
2179 state->ff.active_light[i] = state->ff.active_light[i + 1];
2180 }
2181 state->changed.group |= NINE_STATE_FF_LIGHTING;
2182
2183 return D3D_OK;
2184 }
2185
2186 HRESULT NINE_WINAPI
2187 NineDevice9_GetLightEnable( struct NineDevice9 *This,
2188 DWORD Index,
2189 BOOL *pEnable )
2190 {
2191 const struct nine_state *state = &This->state;
2192 unsigned i;
2193
2194 user_assert(Index < state->ff.num_lights, D3DERR_INVALIDCALL);
2195 user_assert(state->ff.light[Index].Type < NINED3DLIGHT_INVALID,
2196 D3DERR_INVALIDCALL);
2197
2198 for (i = 0; i < state->ff.num_lights_active; ++i)
2199 if (state->ff.active_light[i] == Index)
2200 break;
2201
2202 *pEnable = i != state->ff.num_lights_active ? 128 : 0; // Taken from wine
2203
2204 return D3D_OK;
2205 }
2206
2207 HRESULT NINE_WINAPI
2208 NineDevice9_SetClipPlane( struct NineDevice9 *This,
2209 DWORD Index,
2210 const float *pPlane )
2211 {
2212 struct nine_state *state = This->update;
2213
2214 user_assert(pPlane, D3DERR_INVALIDCALL);
2215
2216 DBG("This=%p Index=%u pPlane=%f %f %f %f\n", This, Index,
2217 pPlane[0], pPlane[1],
2218 pPlane[2], pPlane[3]);
2219
2220 user_assert(Index < PIPE_MAX_CLIP_PLANES, D3DERR_INVALIDCALL);
2221
2222 memcpy(&state->clip.ucp[Index][0], pPlane, sizeof(state->clip.ucp[0]));
2223 state->changed.ucp |= 1 << Index;
2224
2225 return D3D_OK;
2226 }
2227
2228 HRESULT NINE_WINAPI
2229 NineDevice9_GetClipPlane( struct NineDevice9 *This,
2230 DWORD Index,
2231 float *pPlane )
2232 {
2233 const struct nine_state *state = &This->state;
2234
2235 user_assert(Index < PIPE_MAX_CLIP_PLANES, D3DERR_INVALIDCALL);
2236
2237 memcpy(pPlane, &state->clip.ucp[Index][0], sizeof(state->clip.ucp[0]));
2238 return D3D_OK;
2239 }
2240
2241 HRESULT NINE_WINAPI
2242 NineDevice9_SetRenderState( struct NineDevice9 *This,
2243 D3DRENDERSTATETYPE State,
2244 DWORD Value )
2245 {
2246 struct nine_state *state = This->update;
2247
2248 DBG("This=%p State=%u(%s) Value=%08x\n", This,
2249 State, nine_d3drs_to_string(State), Value);
2250
2251 user_assert(State < D3DRS_COUNT, D3DERR_INVALIDCALL);
2252
2253 if (unlikely(This->is_recording)) {
2254 state->rs_advertised[State] = Value;
2255 /* only need to record changed render states for stateblocks */
2256 state->changed.rs[State / 32] |= 1 << (State % 32);
2257 state->changed.group |= nine_render_state_group[State];
2258 return D3D_OK;
2259 }
2260
2261 if (state->rs_advertised[State] == Value)
2262 return D3D_OK;
2263
2264 state->rs_advertised[State] = Value;
2265 nine_context_set_render_state(This, State, Value);
2266
2267 return D3D_OK;
2268 }
2269
2270 HRESULT NINE_WINAPI
2271 NineDevice9_GetRenderState( struct NineDevice9 *This,
2272 D3DRENDERSTATETYPE State,
2273 DWORD *pValue )
2274 {
2275 user_assert(State < D3DRS_COUNT, D3DERR_INVALIDCALL);
2276
2277 *pValue = This->state.rs_advertised[State];
2278 return D3D_OK;
2279 }
2280
2281 HRESULT NINE_WINAPI
2282 NineDevice9_CreateStateBlock( struct NineDevice9 *This,
2283 D3DSTATEBLOCKTYPE Type,
2284 IDirect3DStateBlock9 **ppSB )
2285 {
2286 struct NineStateBlock9 *nsb;
2287 struct nine_state *dst;
2288 HRESULT hr;
2289 enum nine_stateblock_type type;
2290 unsigned s;
2291
2292 DBG("This=%p Type=%u ppSB=%p\n", This, Type, ppSB);
2293
2294 user_assert(Type == D3DSBT_ALL ||
2295 Type == D3DSBT_VERTEXSTATE ||
2296 Type == D3DSBT_PIXELSTATE, D3DERR_INVALIDCALL);
2297
2298 switch (Type) {
2299 case D3DSBT_VERTEXSTATE: type = NINESBT_VERTEXSTATE; break;
2300 case D3DSBT_PIXELSTATE: type = NINESBT_PIXELSTATE; break;
2301 default:
2302 type = NINESBT_ALL;
2303 break;
2304 }
2305
2306 hr = NineStateBlock9_new(This, &nsb, type);
2307 if (FAILED(hr))
2308 return hr;
2309 *ppSB = (IDirect3DStateBlock9 *)nsb;
2310 dst = &nsb->state;
2311
2312 dst->changed.group =
2313 NINE_STATE_TEXTURE |
2314 NINE_STATE_SAMPLER;
2315
2316 if (Type == D3DSBT_ALL || Type == D3DSBT_VERTEXSTATE) {
2317 dst->changed.group |=
2318 NINE_STATE_FF_LIGHTING |
2319 NINE_STATE_VS | NINE_STATE_VS_CONST |
2320 NINE_STATE_VDECL;
2321 /* TODO: texture/sampler state */
2322 memcpy(dst->changed.rs,
2323 nine_render_states_vertex, sizeof(dst->changed.rs));
2324 nine_ranges_insert(&dst->changed.vs_const_f, 0, This->may_swvp ? NINE_MAX_CONST_F_SWVP : This->max_vs_const_f,
2325 &This->range_pool);
2326 nine_ranges_insert(&dst->changed.vs_const_i, 0, This->may_swvp ? NINE_MAX_CONST_I_SWVP : NINE_MAX_CONST_I,
2327 &This->range_pool);
2328 nine_ranges_insert(&dst->changed.vs_const_b, 0, This->may_swvp ? NINE_MAX_CONST_B_SWVP : NINE_MAX_CONST_B,
2329 &This->range_pool);
2330 for (s = 0; s < NINE_MAX_SAMPLERS; ++s)
2331 dst->changed.sampler[s] |= 1 << D3DSAMP_DMAPOFFSET;
2332 if (This->state.ff.num_lights) {
2333 dst->ff.num_lights = This->state.ff.num_lights;
2334 /* zero'd -> light type won't be NINED3DLIGHT_INVALID, so
2335 * all currently existing lights will be captured
2336 */
2337 dst->ff.light = CALLOC(This->state.ff.num_lights,
2338 sizeof(D3DLIGHT9));
2339 if (!dst->ff.light) {
2340 nine_bind(ppSB, NULL);
2341 return E_OUTOFMEMORY;
2342 }
2343 }
2344 }
2345 if (Type == D3DSBT_ALL || Type == D3DSBT_PIXELSTATE) {
2346 dst->changed.group |=
2347 NINE_STATE_PS | NINE_STATE_PS_CONST | NINE_STATE_BLEND |
2348 NINE_STATE_FF_OTHER | NINE_STATE_FF_PSSTAGES | NINE_STATE_PS_CONST |
2349 NINE_STATE_FB | NINE_STATE_DSA | NINE_STATE_MULTISAMPLE |
2350 NINE_STATE_RASTERIZER | NINE_STATE_STENCIL_REF;
2351 memcpy(dst->changed.rs,
2352 nine_render_states_pixel, sizeof(dst->changed.rs));
2353 nine_ranges_insert(&dst->changed.ps_const_f, 0, This->max_ps_const_f,
2354 &This->range_pool);
2355 dst->changed.ps_const_i = 0xffff;
2356 dst->changed.ps_const_b = 0xffff;
2357 for (s = 0; s < NINE_MAX_SAMPLERS; ++s)
2358 dst->changed.sampler[s] |= 0x1ffe;
2359 for (s = 0; s < NINE_MAX_TEXTURE_STAGES; ++s) {
2360 dst->ff.changed.tex_stage[s][0] |= 0xffffffff;
2361 dst->ff.changed.tex_stage[s][1] |= 0xffffffff;
2362 }
2363 }
2364 if (Type == D3DSBT_ALL) {
2365 dst->changed.group |=
2366 NINE_STATE_VIEWPORT |
2367 NINE_STATE_SCISSOR |
2368 NINE_STATE_RASTERIZER |
2369 NINE_STATE_BLEND |
2370 NINE_STATE_DSA |
2371 NINE_STATE_IDXBUF |
2372 NINE_STATE_MATERIAL |
2373 NINE_STATE_BLEND_COLOR |
2374 NINE_STATE_SAMPLE_MASK;
2375 memset(dst->changed.rs, ~0, (D3DRS_COUNT / 32) * sizeof(uint32_t));
2376 dst->changed.rs[D3DRS_LAST / 32] |= (1 << (D3DRS_COUNT % 32)) - 1;
2377 dst->changed.vtxbuf = (1ULL << This->caps.MaxStreams) - 1;
2378 dst->changed.stream_freq = dst->changed.vtxbuf;
2379 dst->changed.ucp = (1 << PIPE_MAX_CLIP_PLANES) - 1;
2380 dst->changed.texture = (1 << NINE_MAX_SAMPLERS) - 1;
2381 }
2382 NineStateBlock9_Capture(NineStateBlock9(*ppSB));
2383
2384 /* TODO: fixed function state */
2385
2386 return D3D_OK;
2387 }
2388
2389 HRESULT NINE_WINAPI
2390 NineDevice9_BeginStateBlock( struct NineDevice9 *This )
2391 {
2392 HRESULT hr;
2393
2394 DBG("This=%p\n", This);
2395
2396 user_assert(!This->record, D3DERR_INVALIDCALL);
2397
2398 hr = NineStateBlock9_new(This, &This->record, NINESBT_CUSTOM);
2399 if (FAILED(hr))
2400 return hr;
2401 NineUnknown_ConvertRefToBind(NineUnknown(This->record));
2402
2403 This->update = &This->record->state;
2404 This->is_recording = TRUE;
2405
2406 return D3D_OK;
2407 }
2408
2409 HRESULT NINE_WINAPI
2410 NineDevice9_EndStateBlock( struct NineDevice9 *This,
2411 IDirect3DStateBlock9 **ppSB )
2412 {
2413 DBG("This=%p ppSB=%p\n", This, ppSB);
2414
2415 user_assert(This->record, D3DERR_INVALIDCALL);
2416
2417 This->update = &This->state;
2418 This->is_recording = FALSE;
2419
2420 NineUnknown_AddRef(NineUnknown(This->record));
2421 *ppSB = (IDirect3DStateBlock9 *)This->record;
2422 NineUnknown_Unbind(NineUnknown(This->record));
2423 This->record = NULL;
2424
2425 return D3D_OK;
2426 }
2427
2428 HRESULT NINE_WINAPI
2429 NineDevice9_SetClipStatus( struct NineDevice9 *This,
2430 const D3DCLIPSTATUS9 *pClipStatus )
2431 {
2432 STUB(D3DERR_INVALIDCALL);
2433 }
2434
2435 HRESULT NINE_WINAPI
2436 NineDevice9_GetClipStatus( struct NineDevice9 *This,
2437 D3DCLIPSTATUS9 *pClipStatus )
2438 {
2439 STUB(D3DERR_INVALIDCALL);
2440 }
2441
2442 HRESULT NINE_WINAPI
2443 NineDevice9_GetTexture( struct NineDevice9 *This,
2444 DWORD Stage,
2445 IDirect3DBaseTexture9 **ppTexture )
2446 {
2447 user_assert(Stage < This->caps.MaxSimultaneousTextures ||
2448 Stage == D3DDMAPSAMPLER ||
2449 (Stage >= D3DVERTEXTEXTURESAMPLER0 &&
2450 Stage <= D3DVERTEXTEXTURESAMPLER3), D3DERR_INVALIDCALL);
2451 user_assert(ppTexture, D3DERR_INVALIDCALL);
2452
2453 if (Stage >= D3DDMAPSAMPLER)
2454 Stage = Stage - D3DDMAPSAMPLER + NINE_MAX_SAMPLERS_PS;
2455
2456 *ppTexture = (IDirect3DBaseTexture9 *)This->state.texture[Stage];
2457
2458 if (This->state.texture[Stage])
2459 NineUnknown_AddRef(NineUnknown(This->state.texture[Stage]));
2460 return D3D_OK;
2461 }
2462
2463 HRESULT NINE_WINAPI
2464 NineDevice9_SetTexture( struct NineDevice9 *This,
2465 DWORD Stage,
2466 IDirect3DBaseTexture9 *pTexture )
2467 {
2468 struct nine_state *state = This->update;
2469 struct NineBaseTexture9 *tex = NineBaseTexture9(pTexture);
2470 struct NineBaseTexture9 *old;
2471
2472 DBG("This=%p Stage=%u pTexture=%p\n", This, Stage, pTexture);
2473
2474 user_assert(Stage < This->caps.MaxSimultaneousTextures ||
2475 Stage == D3DDMAPSAMPLER ||
2476 (Stage >= D3DVERTEXTEXTURESAMPLER0 &&
2477 Stage <= D3DVERTEXTEXTURESAMPLER3), D3DERR_INVALIDCALL);
2478 user_assert(!tex || (tex->base.pool != D3DPOOL_SCRATCH &&
2479 tex->base.pool != D3DPOOL_SYSTEMMEM), D3DERR_INVALIDCALL);
2480
2481 if (Stage >= D3DDMAPSAMPLER)
2482 Stage = Stage - D3DDMAPSAMPLER + NINE_MAX_SAMPLERS_PS;
2483
2484 if (This->is_recording) {
2485 state->changed.texture |= 1 << Stage;
2486 state->changed.group |= NINE_STATE_TEXTURE;
2487 nine_bind(&state->texture[Stage], pTexture);
2488 return D3D_OK;
2489 }
2490
2491 old = state->texture[Stage];
2492 if (old == tex)
2493 return D3D_OK;
2494
2495 if (tex) {
2496 if ((tex->managed.dirty | tex->dirty_mip) && LIST_IS_EMPTY(&tex->list))
2497 list_add(&tex->list, &This->update_textures);
2498
2499 tex->bind_count++;
2500 }
2501 if (old)
2502 old->bind_count--;
2503
2504 nine_context_set_texture(This, Stage, tex);
2505
2506 nine_bind(&state->texture[Stage], pTexture);
2507
2508 return D3D_OK;
2509 }
2510
2511 HRESULT NINE_WINAPI
2512 NineDevice9_GetTextureStageState( struct NineDevice9 *This,
2513 DWORD Stage,
2514 D3DTEXTURESTAGESTATETYPE Type,
2515 DWORD *pValue )
2516 {
2517 const struct nine_state *state = &This->state;
2518
2519 user_assert(Stage < ARRAY_SIZE(state->ff.tex_stage), D3DERR_INVALIDCALL);
2520 user_assert(Type < ARRAY_SIZE(state->ff.tex_stage[0]), D3DERR_INVALIDCALL);
2521
2522 *pValue = state->ff.tex_stage[Stage][Type];
2523
2524 return D3D_OK;
2525 }
2526
2527 HRESULT NINE_WINAPI
2528 NineDevice9_SetTextureStageState( struct NineDevice9 *This,
2529 DWORD Stage,
2530 D3DTEXTURESTAGESTATETYPE Type,
2531 DWORD Value )
2532 {
2533 struct nine_state *state = This->update;
2534 struct nine_context *context = &This->context;
2535 int bumpmap_index = -1;
2536
2537 DBG("Stage=%u Type=%u Value=%08x\n", Stage, Type, Value);
2538 nine_dump_D3DTSS_value(DBG_FF, Type, Value);
2539
2540 user_assert(Stage < ARRAY_SIZE(state->ff.tex_stage), D3DERR_INVALIDCALL);
2541 user_assert(Type < ARRAY_SIZE(state->ff.tex_stage[0]), D3DERR_INVALIDCALL);
2542
2543 state->ff.tex_stage[Stage][Type] = Value;
2544 switch (Type) {
2545 case D3DTSS_BUMPENVMAT00:
2546 bumpmap_index = 4 * Stage;
2547 break;
2548 case D3DTSS_BUMPENVMAT01:
2549 bumpmap_index = 4 * Stage + 1;
2550 break;
2551 case D3DTSS_BUMPENVMAT10:
2552 bumpmap_index = 4 * Stage + 2;
2553 break;
2554 case D3DTSS_BUMPENVMAT11:
2555 bumpmap_index = 4 * Stage + 3;
2556 break;
2557 case D3DTSS_BUMPENVLSCALE:
2558 bumpmap_index = 4 * 8 + 2 * Stage;
2559 break;
2560 case D3DTSS_BUMPENVLOFFSET:
2561 bumpmap_index = 4 * 8 + 2 * Stage + 1;
2562 break;
2563 case D3DTSS_TEXTURETRANSFORMFLAGS:
2564 state->changed.group |= NINE_STATE_PS1X_SHADER;
2565 break;
2566 default:
2567 break;
2568 }
2569
2570 if (bumpmap_index >= 0 && !This->is_recording) {
2571 context->bumpmap_vars[bumpmap_index] = Value;
2572 state->changed.group |= NINE_STATE_PS_CONST;
2573 }
2574
2575 state->changed.group |= NINE_STATE_FF_PSSTAGES;
2576 state->ff.changed.tex_stage[Stage][Type / 32] |= 1 << (Type % 32);
2577
2578 return D3D_OK;
2579 }
2580
2581 HRESULT NINE_WINAPI
2582 NineDevice9_GetSamplerState( struct NineDevice9 *This,
2583 DWORD Sampler,
2584 D3DSAMPLERSTATETYPE Type,
2585 DWORD *pValue )
2586 {
2587 user_assert(Sampler < This->caps.MaxSimultaneousTextures ||
2588 Sampler == D3DDMAPSAMPLER ||
2589 (Sampler >= D3DVERTEXTEXTURESAMPLER0 &&
2590 Sampler <= D3DVERTEXTEXTURESAMPLER3), D3DERR_INVALIDCALL);
2591
2592 if (Sampler >= D3DDMAPSAMPLER)
2593 Sampler = Sampler - D3DDMAPSAMPLER + NINE_MAX_SAMPLERS_PS;
2594
2595 *pValue = This->state.samp_advertised[Sampler][Type];
2596 return D3D_OK;
2597 }
2598
2599 HRESULT NINE_WINAPI
2600 NineDevice9_SetSamplerState( struct NineDevice9 *This,
2601 DWORD Sampler,
2602 D3DSAMPLERSTATETYPE Type,
2603 DWORD Value )
2604 {
2605 struct nine_state *state = This->update;
2606
2607 DBG("This=%p Sampler=%u Type=%s Value=%08x\n", This,
2608 Sampler, nine_D3DSAMP_to_str(Type), Value);
2609
2610 user_assert(Sampler < This->caps.MaxSimultaneousTextures ||
2611 Sampler == D3DDMAPSAMPLER ||
2612 (Sampler >= D3DVERTEXTEXTURESAMPLER0 &&
2613 Sampler <= D3DVERTEXTEXTURESAMPLER3), D3DERR_INVALIDCALL);
2614
2615 if (Sampler >= D3DDMAPSAMPLER)
2616 Sampler = Sampler - D3DDMAPSAMPLER + NINE_MAX_SAMPLERS_PS;
2617
2618 if (unlikely(This->is_recording)) {
2619 state->samp_advertised[Sampler][Type] = Value;
2620 state->changed.group |= NINE_STATE_SAMPLER;
2621 state->changed.sampler[Sampler] |= 1 << Type;
2622 return D3D_OK;
2623 }
2624
2625 if (state->samp_advertised[Sampler][Type] == Value)
2626 return D3D_OK;
2627
2628 state->samp_advertised[Sampler][Type] = Value;
2629 nine_context_set_sampler_state(This, Sampler, Type, Value);
2630
2631 return D3D_OK;
2632 }
2633
2634 HRESULT NINE_WINAPI
2635 NineDevice9_ValidateDevice( struct NineDevice9 *This,
2636 DWORD *pNumPasses )
2637 {
2638 const struct nine_state *state = &This->state;
2639 unsigned i;
2640 unsigned w = 0, h = 0;
2641
2642 DBG("This=%p pNumPasses=%p\n", This, pNumPasses);
2643
2644 for (i = 0; i < ARRAY_SIZE(state->samp_advertised); ++i) {
2645 if (state->samp_advertised[i][D3DSAMP_MINFILTER] == D3DTEXF_NONE ||
2646 state->samp_advertised[i][D3DSAMP_MAGFILTER] == D3DTEXF_NONE)
2647 return D3DERR_UNSUPPORTEDTEXTUREFILTER;
2648 }
2649
2650 for (i = 0; i < This->caps.NumSimultaneousRTs; ++i) {
2651 if (!state->rt[i])
2652 continue;
2653 if (w == 0) {
2654 w = state->rt[i]->desc.Width;
2655 h = state->rt[i]->desc.Height;
2656 } else
2657 if (state->rt[i]->desc.Width != w || state->rt[i]->desc.Height != h) {
2658 return D3DERR_CONFLICTINGRENDERSTATE;
2659 }
2660 }
2661 if (state->ds &&
2662 (state->rs_advertised[D3DRS_ZENABLE] || state->rs_advertised[D3DRS_STENCILENABLE])) {
2663 if (w != 0 &&
2664 (state->ds->desc.Width != w || state->ds->desc.Height != h))
2665 return D3DERR_CONFLICTINGRENDERSTATE;
2666 }
2667
2668 if (pNumPasses)
2669 *pNumPasses = 1;
2670
2671 return D3D_OK;
2672 }
2673
2674 HRESULT NINE_WINAPI
2675 NineDevice9_SetPaletteEntries( struct NineDevice9 *This,
2676 UINT PaletteNumber,
2677 const PALETTEENTRY *pEntries )
2678 {
2679 STUB(D3D_OK); /* like wine */
2680 }
2681
2682 HRESULT NINE_WINAPI
2683 NineDevice9_GetPaletteEntries( struct NineDevice9 *This,
2684 UINT PaletteNumber,
2685 PALETTEENTRY *pEntries )
2686 {
2687 STUB(D3DERR_INVALIDCALL);
2688 }
2689
2690 HRESULT NINE_WINAPI
2691 NineDevice9_SetCurrentTexturePalette( struct NineDevice9 *This,
2692 UINT PaletteNumber )
2693 {
2694 STUB(D3D_OK); /* like wine */
2695 }
2696
2697 HRESULT NINE_WINAPI
2698 NineDevice9_GetCurrentTexturePalette( struct NineDevice9 *This,
2699 UINT *PaletteNumber )
2700 {
2701 STUB(D3DERR_INVALIDCALL);
2702 }
2703
2704 HRESULT NINE_WINAPI
2705 NineDevice9_SetScissorRect( struct NineDevice9 *This,
2706 const RECT *pRect )
2707 {
2708 struct nine_state *state = This->update;
2709
2710 DBG("x=(%u..%u) y=(%u..%u)\n",
2711 pRect->left, pRect->top, pRect->right, pRect->bottom);
2712
2713 state->scissor.minx = pRect->left;
2714 state->scissor.miny = pRect->top;
2715 state->scissor.maxx = pRect->right;
2716 state->scissor.maxy = pRect->bottom;
2717
2718 if (unlikely(This->is_recording))
2719 state->changed.group |= NINE_STATE_SCISSOR;
2720 else
2721 nine_context_set_scissor(This, &state->scissor);
2722
2723 return D3D_OK;
2724 }
2725
2726 HRESULT NINE_WINAPI
2727 NineDevice9_GetScissorRect( struct NineDevice9 *This,
2728 RECT *pRect )
2729 {
2730 pRect->left = This->state.scissor.minx;
2731 pRect->top = This->state.scissor.miny;
2732 pRect->right = This->state.scissor.maxx;
2733 pRect->bottom = This->state.scissor.maxy;
2734
2735 return D3D_OK;
2736 }
2737
2738 HRESULT NINE_WINAPI
2739 NineDevice9_SetSoftwareVertexProcessing( struct NineDevice9 *This,
2740 BOOL bSoftware )
2741 {
2742 if (This->params.BehaviorFlags & D3DCREATE_MIXED_VERTEXPROCESSING) {
2743 This->swvp = bSoftware;
2744 This->state.changed.group |= NINE_STATE_SWVP;
2745 return D3D_OK;
2746 } else
2747 return D3DERR_INVALIDCALL; /* msdn. TODO: check in practice */
2748 }
2749
2750 BOOL NINE_WINAPI
2751 NineDevice9_GetSoftwareVertexProcessing( struct NineDevice9 *This )
2752 {
2753 return This->swvp;
2754 }
2755
2756 HRESULT NINE_WINAPI
2757 NineDevice9_SetNPatchMode( struct NineDevice9 *This,
2758 float nSegments )
2759 {
2760 return D3D_OK; /* Nothing to do because we don't advertise NPatch support */
2761 }
2762
2763 float NINE_WINAPI
2764 NineDevice9_GetNPatchMode( struct NineDevice9 *This )
2765 {
2766 STUB(0);
2767 }
2768
2769 HRESULT NINE_WINAPI
2770 NineDevice9_DrawPrimitive( struct NineDevice9 *This,
2771 D3DPRIMITIVETYPE PrimitiveType,
2772 UINT StartVertex,
2773 UINT PrimitiveCount )
2774 {
2775 DBG("iface %p, PrimitiveType %u, StartVertex %u, PrimitiveCount %u\n",
2776 This, PrimitiveType, StartVertex, PrimitiveCount);
2777
2778 nine_context_draw_primitive(This, PrimitiveType, StartVertex, PrimitiveCount);
2779
2780 return D3D_OK;
2781 }
2782
2783 HRESULT NINE_WINAPI
2784 NineDevice9_DrawIndexedPrimitive( struct NineDevice9 *This,
2785 D3DPRIMITIVETYPE PrimitiveType,
2786 INT BaseVertexIndex,
2787 UINT MinVertexIndex,
2788 UINT NumVertices,
2789 UINT StartIndex,
2790 UINT PrimitiveCount )
2791 {
2792 DBG("iface %p, PrimitiveType %u, BaseVertexIndex %u, MinVertexIndex %u "
2793 "NumVertices %u, StartIndex %u, PrimitiveCount %u\n",
2794 This, PrimitiveType, BaseVertexIndex, MinVertexIndex, NumVertices,
2795 StartIndex, PrimitiveCount);
2796
2797 user_assert(This->state.idxbuf, D3DERR_INVALIDCALL);
2798 user_assert(This->state.vdecl, D3DERR_INVALIDCALL);
2799
2800 nine_context_draw_indexed_primitive(This, PrimitiveType, BaseVertexIndex,
2801 MinVertexIndex, NumVertices, StartIndex,
2802 PrimitiveCount);
2803
2804 return D3D_OK;
2805 }
2806
2807 HRESULT NINE_WINAPI
2808 NineDevice9_DrawPrimitiveUP( struct NineDevice9 *This,
2809 D3DPRIMITIVETYPE PrimitiveType,
2810 UINT PrimitiveCount,
2811 const void *pVertexStreamZeroData,
2812 UINT VertexStreamZeroStride )
2813 {
2814 struct pipe_vertex_buffer vtxbuf;
2815
2816 DBG("iface %p, PrimitiveType %u, PrimitiveCount %u, data %p, stride %u\n",
2817 This, PrimitiveType, PrimitiveCount,
2818 pVertexStreamZeroData, VertexStreamZeroStride);
2819
2820 user_assert(pVertexStreamZeroData && VertexStreamZeroStride,
2821 D3DERR_INVALIDCALL);
2822 user_assert(PrimitiveCount, D3D_OK);
2823
2824 vtxbuf.stride = VertexStreamZeroStride;
2825 vtxbuf.buffer_offset = 0;
2826 vtxbuf.buffer = NULL;
2827 vtxbuf.user_buffer = pVertexStreamZeroData;
2828
2829 if (!This->driver_caps.user_vbufs) {
2830 u_upload_data(This->vertex_uploader,
2831 0,
2832 (prim_count_to_vertex_count(PrimitiveType, PrimitiveCount)) * VertexStreamZeroStride, /* XXX */
2833 4,
2834 vtxbuf.user_buffer,
2835 &vtxbuf.buffer_offset,
2836 &vtxbuf.buffer);
2837 u_upload_unmap(This->vertex_uploader);
2838 vtxbuf.user_buffer = NULL;
2839 }
2840
2841 nine_context_draw_primitive_from_vtxbuf(This, PrimitiveType, PrimitiveCount, &vtxbuf);
2842
2843 pipe_resource_reference(&vtxbuf.buffer, NULL);
2844
2845 NineDevice9_PauseRecording(This);
2846 NineDevice9_SetStreamSource(This, 0, NULL, 0, 0);
2847 NineDevice9_ResumeRecording(This);
2848
2849 return D3D_OK;
2850 }
2851
2852 HRESULT NINE_WINAPI
2853 NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9 *This,
2854 D3DPRIMITIVETYPE PrimitiveType,
2855 UINT MinVertexIndex,
2856 UINT NumVertices,
2857 UINT PrimitiveCount,
2858 const void *pIndexData,
2859 D3DFORMAT IndexDataFormat,
2860 const void *pVertexStreamZeroData,
2861 UINT VertexStreamZeroStride )
2862 {
2863 struct pipe_vertex_buffer vbuf;
2864 struct pipe_index_buffer ibuf;
2865
2866 DBG("iface %p, PrimitiveType %u, MinVertexIndex %u, NumVertices %u "
2867 "PrimitiveCount %u, pIndexData %p, IndexDataFormat %u "
2868 "pVertexStreamZeroData %p, VertexStreamZeroStride %u\n",
2869 This, PrimitiveType, MinVertexIndex, NumVertices, PrimitiveCount,
2870 pIndexData, IndexDataFormat,
2871 pVertexStreamZeroData, VertexStreamZeroStride);
2872
2873 user_assert(pIndexData && pVertexStreamZeroData, D3DERR_INVALIDCALL);
2874 user_assert(VertexStreamZeroStride, D3DERR_INVALIDCALL);
2875 user_assert(IndexDataFormat == D3DFMT_INDEX16 ||
2876 IndexDataFormat == D3DFMT_INDEX32, D3DERR_INVALIDCALL);
2877 user_assert(PrimitiveCount, D3D_OK);
2878
2879 vbuf.stride = VertexStreamZeroStride;
2880 vbuf.buffer_offset = 0;
2881 vbuf.buffer = NULL;
2882 vbuf.user_buffer = pVertexStreamZeroData;
2883
2884 ibuf.index_size = (IndexDataFormat == D3DFMT_INDEX16) ? 2 : 4;
2885 ibuf.offset = 0;
2886 ibuf.buffer = NULL;
2887 ibuf.user_buffer = pIndexData;
2888
2889 if (!This->driver_caps.user_vbufs) {
2890 const unsigned base = MinVertexIndex * VertexStreamZeroStride;
2891 u_upload_data(This->vertex_uploader,
2892 base,
2893 NumVertices * VertexStreamZeroStride, /* XXX */
2894 4,
2895 (const uint8_t *)vbuf.user_buffer + base,
2896 &vbuf.buffer_offset,
2897 &vbuf.buffer);
2898 u_upload_unmap(This->vertex_uploader);
2899 /* Won't be used: */
2900 vbuf.buffer_offset -= base;
2901 vbuf.user_buffer = NULL;
2902 }
2903 if (!This->driver_caps.user_ibufs) {
2904 u_upload_data(This->index_uploader,
2905 0,
2906 (prim_count_to_vertex_count(PrimitiveType, PrimitiveCount)) * ibuf.index_size,
2907 4,
2908 ibuf.user_buffer,
2909 &ibuf.offset,
2910 &ibuf.buffer);
2911 u_upload_unmap(This->index_uploader);
2912 ibuf.user_buffer = NULL;
2913 }
2914
2915 nine_context_draw_indexed_primitive_from_vtxbuf_idxbuf(This, PrimitiveType,
2916 MinVertexIndex,
2917 NumVertices,
2918 PrimitiveCount,
2919 &vbuf,
2920 &ibuf);
2921
2922 pipe_resource_reference(&vbuf.buffer, NULL);
2923 pipe_resource_reference(&ibuf.buffer, NULL);
2924
2925 NineDevice9_PauseRecording(This);
2926 NineDevice9_SetIndices(This, NULL);
2927 NineDevice9_SetStreamSource(This, 0, NULL, 0, 0);
2928 NineDevice9_ResumeRecording(This);
2929
2930 return D3D_OK;
2931 }
2932
2933 HRESULT NINE_WINAPI
2934 NineDevice9_ProcessVertices( struct NineDevice9 *This,
2935 UINT SrcStartIndex,
2936 UINT DestIndex,
2937 UINT VertexCount,
2938 IDirect3DVertexBuffer9 *pDestBuffer,
2939 IDirect3DVertexDeclaration9 *pVertexDecl,
2940 DWORD Flags )
2941 {
2942 struct pipe_screen *screen_sw = This->screen_sw;
2943 struct pipe_context *pipe_sw = This->pipe_sw;
2944 struct NineVertexDeclaration9 *vdecl = NineVertexDeclaration9(pVertexDecl);
2945 struct NineVertexBuffer9 *dst = NineVertexBuffer9(pDestBuffer);
2946 struct NineVertexShader9 *vs;
2947 struct pipe_resource *resource;
2948 struct pipe_transfer *transfer = NULL;
2949 struct pipe_stream_output_info so;
2950 struct pipe_stream_output_target *target;
2951 struct pipe_draw_info draw;
2952 struct pipe_box box;
2953 bool programmable_vs = This->state.vs && !(This->state.vdecl && This->state.vdecl->position_t);
2954 unsigned offsets[1] = {0};
2955 HRESULT hr;
2956 unsigned buffer_size;
2957 void *map;
2958
2959 DBG("This=%p SrcStartIndex=%u DestIndex=%u VertexCount=%u "
2960 "pDestBuffer=%p pVertexDecl=%p Flags=%d\n",
2961 This, SrcStartIndex, DestIndex, VertexCount, pDestBuffer,
2962 pVertexDecl, Flags);
2963
2964 if (!screen_sw->get_param(screen_sw, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS)) {
2965 DBG("ProcessVertices not supported\n");
2966 return D3DERR_INVALIDCALL;
2967 }
2968
2969
2970 vs = programmable_vs ? This->state.vs : This->ff.vs;
2971 /* Note: version is 0 for ff */
2972 user_assert(vdecl || (vs->byte_code.version < 0x30 && dst->desc.FVF),
2973 D3DERR_INVALIDCALL);
2974 if (!vdecl) {
2975 DWORD FVF = dst->desc.FVF;
2976 vdecl = util_hash_table_get(This->ff.ht_fvf, &FVF);
2977 if (!vdecl) {
2978 hr = NineVertexDeclaration9_new_from_fvf(This, FVF, &vdecl);
2979 if (FAILED(hr))
2980 return hr;
2981 vdecl->fvf = FVF;
2982 util_hash_table_set(This->ff.ht_fvf, &vdecl->fvf, vdecl);
2983 NineUnknown_ConvertRefToBind(NineUnknown(vdecl));
2984 }
2985 }
2986
2987 /* Flags: Can be 0 or D3DPV_DONOTCOPYDATA, and/or lock flags
2988 * D3DPV_DONOTCOPYDATA -> Has effect only for ff. In particular
2989 * if not set, everything from src will be used, and dst
2990 * must match exactly the ff vs outputs.
2991 * TODO: Handle all the checks, etc for ff */
2992 user_assert(vdecl->position_t || programmable_vs,
2993 D3DERR_INVALIDCALL);
2994
2995 /* TODO: Support vs < 3 and ff */
2996 user_assert(vs->byte_code.version == 0x30,
2997 D3DERR_INVALIDCALL);
2998 /* TODO: Not hardcode the constant buffers for swvp */
2999 user_assert(This->may_swvp,
3000 D3DERR_INVALIDCALL);
3001
3002 nine_state_prepare_draw_sw(This, vdecl, SrcStartIndex, VertexCount, &so);
3003
3004 buffer_size = VertexCount * so.stride[0] * 4;
3005 {
3006 struct pipe_resource templ;
3007
3008 memset(&templ, 0, sizeof(templ));
3009 templ.target = PIPE_BUFFER;
3010 templ.format = PIPE_FORMAT_R8_UNORM;
3011 templ.width0 = buffer_size;
3012 templ.flags = 0;
3013 templ.bind = PIPE_BIND_STREAM_OUTPUT;
3014 templ.usage = PIPE_USAGE_STREAM;
3015 templ.height0 = templ.depth0 = templ.array_size = 1;
3016 templ.last_level = templ.nr_samples = 0;
3017
3018 resource = screen_sw->resource_create(screen_sw, &templ);
3019 if (!resource)
3020 return E_OUTOFMEMORY;
3021 }
3022 target = pipe_sw->create_stream_output_target(pipe_sw, resource,
3023 0, buffer_size);
3024 if (!target) {
3025 pipe_resource_reference(&resource, NULL);
3026 return D3DERR_DRIVERINTERNALERROR;
3027 }
3028
3029 draw.mode = PIPE_PRIM_POINTS;
3030 draw.count = VertexCount;
3031 draw.start_instance = 0;
3032 draw.primitive_restart = FALSE;
3033 draw.restart_index = 0;
3034 draw.count_from_stream_output = NULL;
3035 draw.indirect = NULL;
3036 draw.indirect_params = NULL;
3037 draw.instance_count = 1;
3038 draw.indexed = FALSE;
3039 draw.start = 0;
3040 draw.index_bias = 0;
3041 draw.min_index = 0;
3042 draw.max_index = VertexCount - 1;
3043
3044
3045 pipe_sw->set_stream_output_targets(pipe_sw, 1, &target, offsets);
3046
3047 pipe_sw->draw_vbo(pipe_sw, &draw);
3048
3049 pipe_sw->set_stream_output_targets(pipe_sw, 0, NULL, 0);
3050 pipe_sw->stream_output_target_destroy(pipe_sw, target);
3051
3052 u_box_1d(0, VertexCount * so.stride[0] * 4, &box);
3053 map = pipe_sw->transfer_map(pipe_sw, resource, 0, PIPE_TRANSFER_READ, &box,
3054 &transfer);
3055 if (!map) {
3056 hr = D3DERR_DRIVERINTERNALERROR;
3057 goto out;
3058 }
3059
3060 hr = NineVertexDeclaration9_ConvertStreamOutput(vdecl,
3061 dst, DestIndex, VertexCount,
3062 map, &so);
3063 if (transfer)
3064 pipe_sw->transfer_unmap(pipe_sw, transfer);
3065
3066 out:
3067 nine_state_after_draw_sw(This);
3068 pipe_resource_reference(&resource, NULL);
3069 return hr;
3070 }
3071
3072 HRESULT NINE_WINAPI
3073 NineDevice9_CreateVertexDeclaration( struct NineDevice9 *This,
3074 const D3DVERTEXELEMENT9 *pVertexElements,
3075 IDirect3DVertexDeclaration9 **ppDecl )
3076 {
3077 struct NineVertexDeclaration9 *vdecl;
3078
3079 DBG("This=%p pVertexElements=%p ppDecl=%p\n",
3080 This, pVertexElements, ppDecl);
3081
3082 HRESULT hr = NineVertexDeclaration9_new(This, pVertexElements, &vdecl);
3083 if (SUCCEEDED(hr))
3084 *ppDecl = (IDirect3DVertexDeclaration9 *)vdecl;
3085
3086 return hr;
3087 }
3088
3089 HRESULT NINE_WINAPI
3090 NineDevice9_SetVertexDeclaration( struct NineDevice9 *This,
3091 IDirect3DVertexDeclaration9 *pDecl )
3092 {
3093 struct nine_state *state = This->update;
3094 struct NineVertexDeclaration9 *vdecl = NineVertexDeclaration9(pDecl);
3095
3096 DBG("This=%p pDecl=%p\n", This, pDecl);
3097
3098 if (unlikely(This->is_recording)) {
3099 nine_bind(&state->vdecl, vdecl);
3100 state->changed.group |= NINE_STATE_VDECL;
3101 return D3D_OK;
3102 }
3103
3104 if (state->vdecl == vdecl)
3105 return D3D_OK;
3106
3107 nine_bind(&state->vdecl, vdecl);
3108
3109 nine_context_set_vertex_declaration(This, vdecl);
3110
3111 return D3D_OK;
3112 }
3113
3114 HRESULT NINE_WINAPI
3115 NineDevice9_GetVertexDeclaration( struct NineDevice9 *This,
3116 IDirect3DVertexDeclaration9 **ppDecl )
3117 {
3118 user_assert(ppDecl, D3DERR_INVALIDCALL);
3119
3120 *ppDecl = (IDirect3DVertexDeclaration9 *)This->state.vdecl;
3121 if (*ppDecl)
3122 NineUnknown_AddRef(NineUnknown(*ppDecl));
3123 return D3D_OK;
3124 }
3125
3126 HRESULT NINE_WINAPI
3127 NineDevice9_SetFVF( struct NineDevice9 *This,
3128 DWORD FVF )
3129 {
3130 struct NineVertexDeclaration9 *vdecl;
3131 HRESULT hr;
3132
3133 DBG("FVF = %08x\n", FVF);
3134 if (!FVF)
3135 return D3D_OK; /* like wine */
3136
3137 vdecl = util_hash_table_get(This->ff.ht_fvf, &FVF);
3138 if (!vdecl) {
3139 hr = NineVertexDeclaration9_new_from_fvf(This, FVF, &vdecl);
3140 if (FAILED(hr))
3141 return hr;
3142 vdecl->fvf = FVF;
3143 util_hash_table_set(This->ff.ht_fvf, &vdecl->fvf, vdecl);
3144 NineUnknown_ConvertRefToBind(NineUnknown(vdecl));
3145 }
3146 return NineDevice9_SetVertexDeclaration(
3147 This, (IDirect3DVertexDeclaration9 *)vdecl);
3148 }
3149
3150 HRESULT NINE_WINAPI
3151 NineDevice9_GetFVF( struct NineDevice9 *This,
3152 DWORD *pFVF )
3153 {
3154 *pFVF = This->state.vdecl ? This->state.vdecl->fvf : 0;
3155 return D3D_OK;
3156 }
3157
3158 HRESULT NINE_WINAPI
3159 NineDevice9_CreateVertexShader( struct NineDevice9 *This,
3160 const DWORD *pFunction,
3161 IDirect3DVertexShader9 **ppShader )
3162 {
3163 struct NineVertexShader9 *vs;
3164 HRESULT hr;
3165
3166 DBG("This=%p pFunction=%p ppShader=%p\n", This, pFunction, ppShader);
3167
3168 hr = NineVertexShader9_new(This, &vs, pFunction, NULL);
3169 if (FAILED(hr))
3170 return hr;
3171 *ppShader = (IDirect3DVertexShader9 *)vs;
3172 return D3D_OK;
3173 }
3174
3175 HRESULT NINE_WINAPI
3176 NineDevice9_SetVertexShader( struct NineDevice9 *This,
3177 IDirect3DVertexShader9 *pShader )
3178 {
3179 struct nine_state *state = This->update;
3180 struct NineVertexShader9 *vs_shader = (struct NineVertexShader9*)pShader;
3181
3182 DBG("This=%p pShader=%p\n", This, pShader);
3183
3184 if (unlikely(This->is_recording)) {
3185 nine_bind(&state->vs, vs_shader);
3186 state->changed.group |= NINE_STATE_VS;
3187 return D3D_OK;
3188 }
3189
3190 if (state->vs == vs_shader)
3191 return D3D_OK;
3192
3193 nine_bind(&state->vs, vs_shader);
3194
3195 nine_context_set_vertex_shader(This, vs_shader);
3196
3197 return D3D_OK;
3198 }
3199
3200 HRESULT NINE_WINAPI
3201 NineDevice9_GetVertexShader( struct NineDevice9 *This,
3202 IDirect3DVertexShader9 **ppShader )
3203 {
3204 user_assert(ppShader, D3DERR_INVALIDCALL);
3205 nine_reference_set(ppShader, This->state.vs);
3206 return D3D_OK;
3207 }
3208
3209 HRESULT NINE_WINAPI
3210 NineDevice9_SetVertexShaderConstantF( struct NineDevice9 *This,
3211 UINT StartRegister,
3212 const float *pConstantData,
3213 UINT Vector4fCount )
3214 {
3215 struct nine_state *state = This->update;
3216 float *vs_const_f = state->vs_const_f;
3217
3218 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3219 This, StartRegister, pConstantData, Vector4fCount);
3220
3221 user_assert(StartRegister < This->caps.MaxVertexShaderConst, D3DERR_INVALIDCALL);
3222 user_assert(StartRegister + Vector4fCount <= This->caps.MaxVertexShaderConst, D3DERR_INVALIDCALL);
3223
3224 if (!Vector4fCount)
3225 return D3D_OK;
3226 user_assert(pConstantData, D3DERR_INVALIDCALL);
3227
3228 if (unlikely(This->is_recording)) {
3229 memcpy(&vs_const_f[StartRegister * 4],
3230 pConstantData,
3231 Vector4fCount * 4 * sizeof(state->vs_const_f[0]));
3232
3233 nine_ranges_insert(&state->changed.vs_const_f,
3234 StartRegister, StartRegister + Vector4fCount,
3235 &This->range_pool);
3236
3237 state->changed.group |= NINE_STATE_VS_CONST;
3238
3239 return D3D_OK;
3240 }
3241
3242 if (!memcmp(&vs_const_f[StartRegister * 4], pConstantData,
3243 Vector4fCount * 4 * sizeof(state->vs_const_f[0])))
3244 return D3D_OK;
3245
3246 memcpy(&vs_const_f[StartRegister * 4],
3247 pConstantData,
3248 Vector4fCount * 4 * sizeof(state->vs_const_f[0]));
3249
3250 nine_context_set_vertex_shader_constant_f(This, StartRegister, pConstantData, Vector4fCount);
3251
3252 return D3D_OK;
3253 }
3254
3255 HRESULT NINE_WINAPI
3256 NineDevice9_GetVertexShaderConstantF( struct NineDevice9 *This,
3257 UINT StartRegister,
3258 float *pConstantData,
3259 UINT Vector4fCount )
3260 {
3261 const struct nine_state *state = &This->state;
3262
3263 user_assert(StartRegister < This->caps.MaxVertexShaderConst, D3DERR_INVALIDCALL);
3264 user_assert(StartRegister + Vector4fCount <= This->caps.MaxVertexShaderConst, D3DERR_INVALIDCALL);
3265 user_assert(pConstantData, D3DERR_INVALIDCALL);
3266
3267 memcpy(pConstantData,
3268 &state->vs_const_f[StartRegister * 4],
3269 Vector4fCount * 4 * sizeof(state->vs_const_f[0]));
3270
3271 return D3D_OK;
3272 }
3273
3274 HRESULT NINE_WINAPI
3275 NineDevice9_SetVertexShaderConstantI( struct NineDevice9 *This,
3276 UINT StartRegister,
3277 const int *pConstantData,
3278 UINT Vector4iCount )
3279 {
3280 struct nine_state *state = This->update;
3281 int i;
3282
3283 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3284 This, StartRegister, pConstantData, Vector4iCount);
3285
3286 user_assert(StartRegister < (This->may_swvp ? NINE_MAX_CONST_I_SWVP : NINE_MAX_CONST_I),
3287 D3DERR_INVALIDCALL);
3288 user_assert(StartRegister + Vector4iCount <= (This->may_swvp ? NINE_MAX_CONST_I_SWVP : NINE_MAX_CONST_I),
3289 D3DERR_INVALIDCALL);
3290 user_assert(pConstantData, D3DERR_INVALIDCALL);
3291
3292 if (This->driver_caps.vs_integer) {
3293 if (!This->is_recording) {
3294 if (!memcmp(&state->vs_const_i[4 * StartRegister], pConstantData,
3295 Vector4iCount * sizeof(int[4])))
3296 return D3D_OK;
3297 }
3298 memcpy(&state->vs_const_i[4 * StartRegister],
3299 pConstantData,
3300 Vector4iCount * sizeof(int[4]));
3301 } else {
3302 for (i = 0; i < Vector4iCount; i++) {
3303 state->vs_const_i[4 * (StartRegister + i)] = fui((float)(pConstantData[4 * i]));
3304 state->vs_const_i[4 * (StartRegister + i) + 1] = fui((float)(pConstantData[4 * i + 1]));
3305 state->vs_const_i[4 * (StartRegister + i) + 2] = fui((float)(pConstantData[4 * i + 2]));
3306 state->vs_const_i[4 * (StartRegister + i) + 3] = fui((float)(pConstantData[4 * i + 3]));
3307 }
3308 }
3309
3310 if (unlikely(This->is_recording)) {
3311 nine_ranges_insert(&state->changed.vs_const_i,
3312 StartRegister, StartRegister + Vector4iCount,
3313 &This->range_pool);
3314 state->changed.group |= NINE_STATE_VS_CONST;
3315 } else
3316 nine_context_set_vertex_shader_constant_i(This, StartRegister, pConstantData, Vector4iCount);
3317
3318 return D3D_OK;
3319 }
3320
3321 HRESULT NINE_WINAPI
3322 NineDevice9_GetVertexShaderConstantI( struct NineDevice9 *This,
3323 UINT StartRegister,
3324 int *pConstantData,
3325 UINT Vector4iCount )
3326 {
3327 const struct nine_state *state = &This->state;
3328 int i;
3329
3330 user_assert(StartRegister < (This->may_swvp ? NINE_MAX_CONST_I_SWVP : NINE_MAX_CONST_I),
3331 D3DERR_INVALIDCALL);
3332 user_assert(StartRegister + Vector4iCount <= (This->may_swvp ? NINE_MAX_CONST_I_SWVP : NINE_MAX_CONST_I),
3333 D3DERR_INVALIDCALL);
3334 user_assert(pConstantData, D3DERR_INVALIDCALL);
3335
3336 if (This->driver_caps.vs_integer) {
3337 memcpy(pConstantData,
3338 &state->vs_const_i[4 * StartRegister],
3339 Vector4iCount * sizeof(int[4]));
3340 } else {
3341 for (i = 0; i < Vector4iCount; i++) {
3342 pConstantData[4 * i] = (int32_t) uif(state->vs_const_i[4 * (StartRegister + i)]);
3343 pConstantData[4 * i + 1] = (int32_t) uif(state->vs_const_i[4 * (StartRegister + i) + 1]);
3344 pConstantData[4 * i + 2] = (int32_t) uif(state->vs_const_i[4 * (StartRegister + i) + 2]);
3345 pConstantData[4 * i + 3] = (int32_t) uif(state->vs_const_i[4 * (StartRegister + i) + 3]);
3346 }
3347 }
3348
3349 return D3D_OK;
3350 }
3351
3352 HRESULT NINE_WINAPI
3353 NineDevice9_SetVertexShaderConstantB( struct NineDevice9 *This,
3354 UINT StartRegister,
3355 const BOOL *pConstantData,
3356 UINT BoolCount )
3357 {
3358 struct nine_state *state = This->update;
3359 int i;
3360 uint32_t bool_true = This->driver_caps.vs_integer ? 0xFFFFFFFF : fui(1.0f);
3361
3362 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3363 This, StartRegister, pConstantData, BoolCount);
3364
3365 user_assert(StartRegister < (This->may_swvp ? NINE_MAX_CONST_B_SWVP : NINE_MAX_CONST_B),
3366 D3DERR_INVALIDCALL);
3367 user_assert(StartRegister + BoolCount <= (This->may_swvp ? NINE_MAX_CONST_B_SWVP : NINE_MAX_CONST_B),
3368 D3DERR_INVALIDCALL);
3369 user_assert(pConstantData, D3DERR_INVALIDCALL);
3370
3371 if (!This->is_recording) {
3372 bool noChange = true;
3373 for (i = 0; i < BoolCount; i++) {
3374 if (!!state->vs_const_b[StartRegister + i] != !!pConstantData[i])
3375 noChange = false;
3376 }
3377 if (noChange)
3378 return D3D_OK;
3379 }
3380
3381 for (i = 0; i < BoolCount; i++)
3382 state->vs_const_b[StartRegister + i] = pConstantData[i] ? bool_true : 0;
3383
3384 if (unlikely(This->is_recording)) {
3385 nine_ranges_insert(&state->changed.vs_const_b,
3386 StartRegister, StartRegister + BoolCount,
3387 &This->range_pool);
3388 state->changed.group |= NINE_STATE_VS_CONST;
3389 } else
3390 nine_context_set_vertex_shader_constant_b(This, StartRegister, pConstantData, BoolCount);
3391
3392 return D3D_OK;
3393 }
3394
3395 HRESULT NINE_WINAPI
3396 NineDevice9_GetVertexShaderConstantB( struct NineDevice9 *This,
3397 UINT StartRegister,
3398 BOOL *pConstantData,
3399 UINT BoolCount )
3400 {
3401 const struct nine_state *state = &This->state;
3402 int i;
3403
3404 user_assert(StartRegister < (This->may_swvp ? NINE_MAX_CONST_B_SWVP : NINE_MAX_CONST_B),
3405 D3DERR_INVALIDCALL);
3406 user_assert(StartRegister + BoolCount <= (This->may_swvp ? NINE_MAX_CONST_B_SWVP : NINE_MAX_CONST_B),
3407 D3DERR_INVALIDCALL);
3408 user_assert(pConstantData, D3DERR_INVALIDCALL);
3409
3410 for (i = 0; i < BoolCount; i++)
3411 pConstantData[i] = state->vs_const_b[StartRegister + i] != 0 ? TRUE : FALSE;
3412
3413 return D3D_OK;
3414 }
3415
3416 HRESULT NINE_WINAPI
3417 NineDevice9_SetStreamSource( struct NineDevice9 *This,
3418 UINT StreamNumber,
3419 IDirect3DVertexBuffer9 *pStreamData,
3420 UINT OffsetInBytes,
3421 UINT Stride )
3422 {
3423 struct nine_state *state = This->update;
3424 struct NineVertexBuffer9 *pVBuf9 = NineVertexBuffer9(pStreamData);
3425 const unsigned i = StreamNumber;
3426
3427 DBG("This=%p StreamNumber=%u pStreamData=%p OffsetInBytes=%u Stride=%u\n",
3428 This, StreamNumber, pStreamData, OffsetInBytes, Stride);
3429
3430 user_assert(StreamNumber < This->caps.MaxStreams, D3DERR_INVALIDCALL);
3431 user_assert(Stride <= This->caps.MaxStreamStride, D3DERR_INVALIDCALL);
3432
3433 if (unlikely(This->is_recording)) {
3434 nine_bind(&state->stream[i], pStreamData);
3435 state->changed.vtxbuf |= 1 << StreamNumber;
3436 state->vtxbuf[i].stride = Stride;
3437 state->vtxbuf[i].buffer_offset = OffsetInBytes;
3438 return D3D_OK;
3439 }
3440
3441 if (state->stream[i] == NineVertexBuffer9(pStreamData) &&
3442 state->vtxbuf[i].stride == Stride &&
3443 state->vtxbuf[i].buffer_offset == OffsetInBytes)
3444 return D3D_OK;
3445
3446 state->vtxbuf[i].stride = Stride;
3447 state->vtxbuf[i].buffer_offset = OffsetInBytes;
3448
3449 nine_bind(&state->stream[i], pStreamData);
3450
3451 nine_context_set_stream_source(This,
3452 StreamNumber,
3453 pVBuf9,
3454 OffsetInBytes,
3455 Stride);
3456
3457 return D3D_OK;
3458 }
3459
3460 HRESULT NINE_WINAPI
3461 NineDevice9_GetStreamSource( struct NineDevice9 *This,
3462 UINT StreamNumber,
3463 IDirect3DVertexBuffer9 **ppStreamData,
3464 UINT *pOffsetInBytes,
3465 UINT *pStride )
3466 {
3467 const struct nine_state *state = &This->state;
3468 const unsigned i = StreamNumber;
3469
3470 user_assert(StreamNumber < This->caps.MaxStreams, D3DERR_INVALIDCALL);
3471 user_assert(ppStreamData, D3DERR_INVALIDCALL);
3472
3473 nine_reference_set(ppStreamData, state->stream[i]);
3474 *pStride = state->vtxbuf[i].stride;
3475 *pOffsetInBytes = state->vtxbuf[i].buffer_offset;
3476
3477 return D3D_OK;
3478 }
3479
3480 HRESULT NINE_WINAPI
3481 NineDevice9_SetStreamSourceFreq( struct NineDevice9 *This,
3482 UINT StreamNumber,
3483 UINT Setting )
3484 {
3485 struct nine_state *state = This->update;
3486 /* const UINT freq = Setting & 0x7FFFFF; */
3487
3488 DBG("This=%p StreamNumber=%u FrequencyParameter=0x%x\n", This,
3489 StreamNumber, Setting);
3490
3491 user_assert(StreamNumber < This->caps.MaxStreams, D3DERR_INVALIDCALL);
3492 user_assert(StreamNumber != 0 || !(Setting & D3DSTREAMSOURCE_INSTANCEDATA),
3493 D3DERR_INVALIDCALL);
3494 user_assert(!((Setting & D3DSTREAMSOURCE_INSTANCEDATA) &&
3495 (Setting & D3DSTREAMSOURCE_INDEXEDDATA)), D3DERR_INVALIDCALL);
3496 user_assert(Setting, D3DERR_INVALIDCALL);
3497
3498 if (unlikely(This->is_recording)) {
3499 state->stream_freq[StreamNumber] = Setting;
3500 state->changed.stream_freq |= 1 << StreamNumber;
3501 if (StreamNumber != 0)
3502 state->changed.group |= NINE_STATE_STREAMFREQ;
3503 return D3D_OK;
3504 }
3505
3506 if (state->stream_freq[StreamNumber] == Setting)
3507 return D3D_OK;
3508
3509 state->stream_freq[StreamNumber] = Setting;
3510
3511 nine_context_set_stream_source_freq(This, StreamNumber, Setting);
3512 return D3D_OK;
3513 }
3514
3515 HRESULT NINE_WINAPI
3516 NineDevice9_GetStreamSourceFreq( struct NineDevice9 *This,
3517 UINT StreamNumber,
3518 UINT *pSetting )
3519 {
3520 user_assert(StreamNumber < This->caps.MaxStreams, D3DERR_INVALIDCALL);
3521 *pSetting = This->state.stream_freq[StreamNumber];
3522 return D3D_OK;
3523 }
3524
3525 HRESULT NINE_WINAPI
3526 NineDevice9_SetIndices( struct NineDevice9 *This,
3527 IDirect3DIndexBuffer9 *pIndexData )
3528 {
3529 struct nine_state *state = This->update;
3530 struct NineIndexBuffer9 *idxbuf = NineIndexBuffer9(pIndexData);
3531
3532 DBG("This=%p pIndexData=%p\n", This, pIndexData);
3533
3534 if (unlikely(This->is_recording)) {
3535 nine_bind(&state->idxbuf, idxbuf);
3536 state->changed.group |= NINE_STATE_IDXBUF;
3537 return D3D_OK;
3538 }
3539
3540 if (state->idxbuf == idxbuf)
3541 return D3D_OK;
3542 nine_bind(&state->idxbuf, idxbuf);
3543
3544 nine_context_set_indices(This, idxbuf);
3545
3546 return D3D_OK;
3547 }
3548
3549 /* XXX: wine/d3d9 doesn't have pBaseVertexIndex, and it doesn't make sense
3550 * here because it's an argument passed to the Draw calls.
3551 */
3552 HRESULT NINE_WINAPI
3553 NineDevice9_GetIndices( struct NineDevice9 *This,
3554 IDirect3DIndexBuffer9 **ppIndexData)
3555 {
3556 user_assert(ppIndexData, D3DERR_INVALIDCALL);
3557 nine_reference_set(ppIndexData, This->state.idxbuf);
3558 return D3D_OK;
3559 }
3560
3561 HRESULT NINE_WINAPI
3562 NineDevice9_CreatePixelShader( struct NineDevice9 *This,
3563 const DWORD *pFunction,
3564 IDirect3DPixelShader9 **ppShader )
3565 {
3566 struct NinePixelShader9 *ps;
3567 HRESULT hr;
3568
3569 DBG("This=%p pFunction=%p ppShader=%p\n", This, pFunction, ppShader);
3570
3571 hr = NinePixelShader9_new(This, &ps, pFunction, NULL);
3572 if (FAILED(hr))
3573 return hr;
3574 *ppShader = (IDirect3DPixelShader9 *)ps;
3575 return D3D_OK;
3576 }
3577
3578 HRESULT NINE_WINAPI
3579 NineDevice9_SetPixelShader( struct NineDevice9 *This,
3580 IDirect3DPixelShader9 *pShader )
3581 {
3582 struct nine_state *state = This->update;
3583 struct nine_context *context = &This->context;
3584 unsigned old_mask = state->ps ? state->ps->rt_mask : 1;
3585 unsigned mask;
3586
3587 DBG("This=%p pShader=%p\n", This, pShader);
3588
3589 if (!This->is_recording && state->ps == (struct NinePixelShader9*)pShader)
3590 return D3D_OK;
3591
3592 /* ff -> non-ff: commit back non-ff constants */
3593 if (!state->ps && pShader)
3594 context->commit |= NINE_STATE_COMMIT_CONST_PS;
3595
3596 nine_bind(&state->ps, pShader);
3597
3598 state->changed.group |= NINE_STATE_PS;
3599
3600 mask = state->ps ? state->ps->rt_mask : 1;
3601 /* We need to update cbufs if the pixel shader would
3602 * write to different render targets */
3603 if (mask != old_mask)
3604 state->changed.group |= NINE_STATE_FB;
3605
3606 return D3D_OK;
3607 }
3608
3609 HRESULT NINE_WINAPI
3610 NineDevice9_GetPixelShader( struct NineDevice9 *This,
3611 IDirect3DPixelShader9 **ppShader )
3612 {
3613 user_assert(ppShader, D3DERR_INVALIDCALL);
3614 nine_reference_set(ppShader, This->state.ps);
3615 return D3D_OK;
3616 }
3617
3618 HRESULT NINE_WINAPI
3619 NineDevice9_SetPixelShaderConstantF( struct NineDevice9 *This,
3620 UINT StartRegister,
3621 const float *pConstantData,
3622 UINT Vector4fCount )
3623 {
3624 struct nine_state *state = This->update;
3625
3626 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3627 This, StartRegister, pConstantData, Vector4fCount);
3628
3629 user_assert(StartRegister < NINE_MAX_CONST_F_PS3, D3DERR_INVALIDCALL);
3630 user_assert(StartRegister + Vector4fCount <= NINE_MAX_CONST_F_PS3, D3DERR_INVALIDCALL);
3631
3632 if (!Vector4fCount)
3633 return D3D_OK;
3634 user_assert(pConstantData, D3DERR_INVALIDCALL);
3635
3636 if (unlikely(This->is_recording)) {
3637 memcpy(&state->ps_const_f[StartRegister * 4],
3638 pConstantData,
3639 Vector4fCount * 4 * sizeof(state->ps_const_f[0]));
3640
3641 nine_ranges_insert(&state->changed.ps_const_f,
3642 StartRegister, StartRegister + Vector4fCount,
3643 &This->range_pool);
3644
3645 state->changed.group |= NINE_STATE_PS_CONST;
3646 return D3D_OK;
3647 }
3648
3649 if (!memcmp(&state->ps_const_f[StartRegister * 4], pConstantData,
3650 Vector4fCount * 4 * sizeof(state->ps_const_f[0])))
3651 return D3D_OK;
3652
3653 memcpy(&state->ps_const_f[StartRegister * 4],
3654 pConstantData,
3655 Vector4fCount * 4 * sizeof(state->ps_const_f[0]));
3656
3657 nine_context_set_pixel_shader_constant_f(This, StartRegister, pConstantData, Vector4fCount);
3658
3659 return D3D_OK;
3660 }
3661
3662 HRESULT NINE_WINAPI
3663 NineDevice9_GetPixelShaderConstantF( struct NineDevice9 *This,
3664 UINT StartRegister,
3665 float *pConstantData,
3666 UINT Vector4fCount )
3667 {
3668 const struct nine_state *state = &This->state;
3669
3670 user_assert(StartRegister < NINE_MAX_CONST_F_PS3, D3DERR_INVALIDCALL);
3671 user_assert(StartRegister + Vector4fCount <= NINE_MAX_CONST_F_PS3, D3DERR_INVALIDCALL);
3672 user_assert(pConstantData, D3DERR_INVALIDCALL);
3673
3674 memcpy(pConstantData,
3675 &state->ps_const_f[StartRegister * 4],
3676 Vector4fCount * 4 * sizeof(state->ps_const_f[0]));
3677
3678 return D3D_OK;
3679 }
3680
3681 HRESULT NINE_WINAPI
3682 NineDevice9_SetPixelShaderConstantI( struct NineDevice9 *This,
3683 UINT StartRegister,
3684 const int *pConstantData,
3685 UINT Vector4iCount )
3686 {
3687 struct nine_state *state = This->update;
3688 int i;
3689
3690 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3691 This, StartRegister, pConstantData, Vector4iCount);
3692
3693 user_assert(StartRegister < NINE_MAX_CONST_I, D3DERR_INVALIDCALL);
3694 user_assert(StartRegister + Vector4iCount <= NINE_MAX_CONST_I, D3DERR_INVALIDCALL);
3695 user_assert(pConstantData, D3DERR_INVALIDCALL);
3696
3697 if (This->driver_caps.ps_integer) {
3698 if (!This->is_recording) {
3699 if (!memcmp(&state->ps_const_i[StartRegister][0], pConstantData,
3700 Vector4iCount * sizeof(state->ps_const_i[0])))
3701 return D3D_OK;
3702 }
3703 memcpy(&state->ps_const_i[StartRegister][0],
3704 pConstantData,
3705 Vector4iCount * sizeof(state->ps_const_i[0]));
3706 } else {
3707 for (i = 0; i < Vector4iCount; i++) {
3708 state->ps_const_i[StartRegister+i][0] = fui((float)(pConstantData[4*i]));
3709 state->ps_const_i[StartRegister+i][1] = fui((float)(pConstantData[4*i+1]));
3710 state->ps_const_i[StartRegister+i][2] = fui((float)(pConstantData[4*i+2]));
3711 state->ps_const_i[StartRegister+i][3] = fui((float)(pConstantData[4*i+3]));
3712 }
3713 }
3714
3715 if (unlikely(This->is_recording)) {
3716 state->changed.ps_const_i |= ((1 << Vector4iCount) - 1) << StartRegister;
3717 state->changed.group |= NINE_STATE_PS_CONST;
3718 } else
3719 nine_context_set_pixel_shader_constant_i(This, StartRegister, pConstantData, Vector4iCount);
3720
3721 return D3D_OK;
3722 }
3723
3724 HRESULT NINE_WINAPI
3725 NineDevice9_GetPixelShaderConstantI( struct NineDevice9 *This,
3726 UINT StartRegister,
3727 int *pConstantData,
3728 UINT Vector4iCount )
3729 {
3730 const struct nine_state *state = &This->state;
3731 int i;
3732
3733 user_assert(StartRegister < NINE_MAX_CONST_I, D3DERR_INVALIDCALL);
3734 user_assert(StartRegister + Vector4iCount <= NINE_MAX_CONST_I, D3DERR_INVALIDCALL);
3735 user_assert(pConstantData, D3DERR_INVALIDCALL);
3736
3737 if (This->driver_caps.ps_integer) {
3738 memcpy(pConstantData,
3739 &state->ps_const_i[StartRegister][0],
3740 Vector4iCount * sizeof(state->ps_const_i[0]));
3741 } else {
3742 for (i = 0; i < Vector4iCount; i++) {
3743 pConstantData[4*i] = (int32_t) uif(state->ps_const_i[StartRegister+i][0]);
3744 pConstantData[4*i+1] = (int32_t) uif(state->ps_const_i[StartRegister+i][1]);
3745 pConstantData[4*i+2] = (int32_t) uif(state->ps_const_i[StartRegister+i][2]);
3746 pConstantData[4*i+3] = (int32_t) uif(state->ps_const_i[StartRegister+i][3]);
3747 }
3748 }
3749
3750 return D3D_OK;
3751 }
3752
3753 HRESULT NINE_WINAPI
3754 NineDevice9_SetPixelShaderConstantB( struct NineDevice9 *This,
3755 UINT StartRegister,
3756 const BOOL *pConstantData,
3757 UINT BoolCount )
3758 {
3759 struct nine_state *state = This->update;
3760 int i;
3761 uint32_t bool_true = This->driver_caps.ps_integer ? 0xFFFFFFFF : fui(1.0f);
3762
3763 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3764 This, StartRegister, pConstantData, BoolCount);
3765
3766 user_assert(StartRegister < NINE_MAX_CONST_B, D3DERR_INVALIDCALL);
3767 user_assert(StartRegister + BoolCount <= NINE_MAX_CONST_B, D3DERR_INVALIDCALL);
3768 user_assert(pConstantData, D3DERR_INVALIDCALL);
3769
3770 if (!This->is_recording) {
3771 bool noChange = true;
3772 for (i = 0; i < BoolCount; i++) {
3773 if (!!state->ps_const_b[StartRegister + i] != !!pConstantData[i])
3774 noChange = false;
3775 }
3776 if (noChange)
3777 return D3D_OK;
3778 }
3779
3780 for (i = 0; i < BoolCount; i++)
3781 state->ps_const_b[StartRegister + i] = pConstantData[i] ? bool_true : 0;
3782
3783 if (unlikely(This->is_recording)) {
3784 state->changed.ps_const_b |= ((1 << BoolCount) - 1) << StartRegister;
3785 state->changed.group |= NINE_STATE_PS_CONST;
3786 } else
3787 nine_context_set_pixel_shader_constant_b(This, StartRegister, pConstantData, BoolCount);
3788
3789 return D3D_OK;
3790 }
3791
3792 HRESULT NINE_WINAPI
3793 NineDevice9_GetPixelShaderConstantB( struct NineDevice9 *This,
3794 UINT StartRegister,
3795 BOOL *pConstantData,
3796 UINT BoolCount )
3797 {
3798 const struct nine_state *state = &This->state;
3799 int i;
3800
3801 user_assert(StartRegister < NINE_MAX_CONST_B, D3DERR_INVALIDCALL);
3802 user_assert(StartRegister + BoolCount <= NINE_MAX_CONST_B, D3DERR_INVALIDCALL);
3803 user_assert(pConstantData, D3DERR_INVALIDCALL);
3804
3805 for (i = 0; i < BoolCount; i++)
3806 pConstantData[i] = state->ps_const_b[StartRegister + i] ? TRUE : FALSE;
3807
3808 return D3D_OK;
3809 }
3810
3811 HRESULT NINE_WINAPI
3812 NineDevice9_DrawRectPatch( struct NineDevice9 *This,
3813 UINT Handle,
3814 const float *pNumSegs,
3815 const D3DRECTPATCH_INFO *pRectPatchInfo )
3816 {
3817 STUB(D3DERR_INVALIDCALL);
3818 }
3819
3820 HRESULT NINE_WINAPI
3821 NineDevice9_DrawTriPatch( struct NineDevice9 *This,
3822 UINT Handle,
3823 const float *pNumSegs,
3824 const D3DTRIPATCH_INFO *pTriPatchInfo )
3825 {
3826 STUB(D3DERR_INVALIDCALL);
3827 }
3828
3829 HRESULT NINE_WINAPI
3830 NineDevice9_DeletePatch( struct NineDevice9 *This,
3831 UINT Handle )
3832 {
3833 STUB(D3DERR_INVALIDCALL);
3834 }
3835
3836 HRESULT NINE_WINAPI
3837 NineDevice9_CreateQuery( struct NineDevice9 *This,
3838 D3DQUERYTYPE Type,
3839 IDirect3DQuery9 **ppQuery )
3840 {
3841 struct NineQuery9 *query;
3842 HRESULT hr;
3843
3844 DBG("This=%p Type=%d ppQuery=%p\n", This, Type, ppQuery);
3845
3846 hr = nine_is_query_supported(This->screen, Type);
3847 if (!ppQuery || hr != D3D_OK)
3848 return hr;
3849
3850 hr = NineQuery9_new(This, &query, Type);
3851 if (FAILED(hr))
3852 return hr;
3853 *ppQuery = (IDirect3DQuery9 *)query;
3854 return D3D_OK;
3855 }
3856
3857 IDirect3DDevice9Vtbl NineDevice9_vtable = {
3858 (void *)NineUnknown_QueryInterface,
3859 (void *)NineUnknown_AddRef,
3860 (void *)NineUnknown_Release,
3861 (void *)NineDevice9_TestCooperativeLevel,
3862 (void *)NineDevice9_GetAvailableTextureMem,
3863 (void *)NineDevice9_EvictManagedResources,
3864 (void *)NineDevice9_GetDirect3D,
3865 (void *)NineDevice9_GetDeviceCaps,
3866 (void *)NineDevice9_GetDisplayMode,
3867 (void *)NineDevice9_GetCreationParameters,
3868 (void *)NineDevice9_SetCursorProperties,
3869 (void *)NineDevice9_SetCursorPosition,
3870 (void *)NineDevice9_ShowCursor,
3871 (void *)NineDevice9_CreateAdditionalSwapChain,
3872 (void *)NineDevice9_GetSwapChain,
3873 (void *)NineDevice9_GetNumberOfSwapChains,
3874 (void *)NineDevice9_Reset,
3875 (void *)NineDevice9_Present,
3876 (void *)NineDevice9_GetBackBuffer,
3877 (void *)NineDevice9_GetRasterStatus,
3878 (void *)NineDevice9_SetDialogBoxMode,
3879 (void *)NineDevice9_SetGammaRamp,
3880 (void *)NineDevice9_GetGammaRamp,
3881 (void *)NineDevice9_CreateTexture,
3882 (void *)NineDevice9_CreateVolumeTexture,
3883 (void *)NineDevice9_CreateCubeTexture,
3884 (void *)NineDevice9_CreateVertexBuffer,
3885 (void *)NineDevice9_CreateIndexBuffer,
3886 (void *)NineDevice9_CreateRenderTarget,
3887 (void *)NineDevice9_CreateDepthStencilSurface,
3888 (void *)NineDevice9_UpdateSurface,
3889 (void *)NineDevice9_UpdateTexture,
3890 (void *)NineDevice9_GetRenderTargetData,
3891 (void *)NineDevice9_GetFrontBufferData,
3892 (void *)NineDevice9_StretchRect,
3893 (void *)NineDevice9_ColorFill,
3894 (void *)NineDevice9_CreateOffscreenPlainSurface,
3895 (void *)NineDevice9_SetRenderTarget,
3896 (void *)NineDevice9_GetRenderTarget,
3897 (void *)NineDevice9_SetDepthStencilSurface,
3898 (void *)NineDevice9_GetDepthStencilSurface,
3899 (void *)NineDevice9_BeginScene,
3900 (void *)NineDevice9_EndScene,
3901 (void *)NineDevice9_Clear,
3902 (void *)NineDevice9_SetTransform,
3903 (void *)NineDevice9_GetTransform,
3904 (void *)NineDevice9_MultiplyTransform,
3905 (void *)NineDevice9_SetViewport,
3906 (void *)NineDevice9_GetViewport,
3907 (void *)NineDevice9_SetMaterial,
3908 (void *)NineDevice9_GetMaterial,
3909 (void *)NineDevice9_SetLight,
3910 (void *)NineDevice9_GetLight,
3911 (void *)NineDevice9_LightEnable,
3912 (void *)NineDevice9_GetLightEnable,
3913 (void *)NineDevice9_SetClipPlane,
3914 (void *)NineDevice9_GetClipPlane,
3915 (void *)NineDevice9_SetRenderState,
3916 (void *)NineDevice9_GetRenderState,
3917 (void *)NineDevice9_CreateStateBlock,
3918 (void *)NineDevice9_BeginStateBlock,
3919 (void *)NineDevice9_EndStateBlock,
3920 (void *)NineDevice9_SetClipStatus,
3921 (void *)NineDevice9_GetClipStatus,
3922 (void *)NineDevice9_GetTexture,
3923 (void *)NineDevice9_SetTexture,
3924 (void *)NineDevice9_GetTextureStageState,
3925 (void *)NineDevice9_SetTextureStageState,
3926 (void *)NineDevice9_GetSamplerState,
3927 (void *)NineDevice9_SetSamplerState,
3928 (void *)NineDevice9_ValidateDevice,
3929 (void *)NineDevice9_SetPaletteEntries,
3930 (void *)NineDevice9_GetPaletteEntries,
3931 (void *)NineDevice9_SetCurrentTexturePalette,
3932 (void *)NineDevice9_GetCurrentTexturePalette,
3933 (void *)NineDevice9_SetScissorRect,
3934 (void *)NineDevice9_GetScissorRect,
3935 (void *)NineDevice9_SetSoftwareVertexProcessing,
3936 (void *)NineDevice9_GetSoftwareVertexProcessing,
3937 (void *)NineDevice9_SetNPatchMode,
3938 (void *)NineDevice9_GetNPatchMode,
3939 (void *)NineDevice9_DrawPrimitive,
3940 (void *)NineDevice9_DrawIndexedPrimitive,
3941 (void *)NineDevice9_DrawPrimitiveUP,
3942 (void *)NineDevice9_DrawIndexedPrimitiveUP,
3943 (void *)NineDevice9_ProcessVertices,
3944 (void *)NineDevice9_CreateVertexDeclaration,
3945 (void *)NineDevice9_SetVertexDeclaration,
3946 (void *)NineDevice9_GetVertexDeclaration,
3947 (void *)NineDevice9_SetFVF,
3948 (void *)NineDevice9_GetFVF,
3949 (void *)NineDevice9_CreateVertexShader,
3950 (void *)NineDevice9_SetVertexShader,
3951 (void *)NineDevice9_GetVertexShader,
3952 (void *)NineDevice9_SetVertexShaderConstantF,
3953 (void *)NineDevice9_GetVertexShaderConstantF,
3954 (void *)NineDevice9_SetVertexShaderConstantI,
3955 (void *)NineDevice9_GetVertexShaderConstantI,
3956 (void *)NineDevice9_SetVertexShaderConstantB,
3957 (void *)NineDevice9_GetVertexShaderConstantB,
3958 (void *)NineDevice9_SetStreamSource,
3959 (void *)NineDevice9_GetStreamSource,
3960 (void *)NineDevice9_SetStreamSourceFreq,
3961 (void *)NineDevice9_GetStreamSourceFreq,
3962 (void *)NineDevice9_SetIndices,
3963 (void *)NineDevice9_GetIndices,
3964 (void *)NineDevice9_CreatePixelShader,
3965 (void *)NineDevice9_SetPixelShader,
3966 (void *)NineDevice9_GetPixelShader,
3967 (void *)NineDevice9_SetPixelShaderConstantF,
3968 (void *)NineDevice9_GetPixelShaderConstantF,
3969 (void *)NineDevice9_SetPixelShaderConstantI,
3970 (void *)NineDevice9_GetPixelShaderConstantI,
3971 (void *)NineDevice9_SetPixelShaderConstantB,
3972 (void *)NineDevice9_GetPixelShaderConstantB,
3973 (void *)NineDevice9_DrawRectPatch,
3974 (void *)NineDevice9_DrawTriPatch,
3975 (void *)NineDevice9_DeletePatch,
3976 (void *)NineDevice9_CreateQuery
3977 };
3978
3979 static const GUID *NineDevice9_IIDs[] = {
3980 &IID_IDirect3DDevice9,
3981 &IID_IUnknown,
3982 NULL
3983 };
3984
3985 HRESULT
3986 NineDevice9_new( struct pipe_screen *pScreen,
3987 D3DDEVICE_CREATION_PARAMETERS *pCreationParameters,
3988 D3DCAPS9 *pCaps,
3989 D3DPRESENT_PARAMETERS *pPresentationParameters,
3990 IDirect3D9 *pD3D9,
3991 ID3DPresentGroup *pPresentationGroup,
3992 struct d3dadapter9_context *pCTX,
3993 boolean ex,
3994 D3DDISPLAYMODEEX *pFullscreenDisplayMode,
3995 struct NineDevice9 **ppOut,
3996 int minorVersionNum )
3997 {
3998 BOOL lock;
3999 lock = !!(pCreationParameters->BehaviorFlags & D3DCREATE_MULTITHREADED);
4000
4001 NINE_NEW(Device9, ppOut, lock, /* args */
4002 pScreen, pCreationParameters, pCaps,
4003 pPresentationParameters, pD3D9, pPresentationGroup, pCTX,
4004 ex, pFullscreenDisplayMode, minorVersionNum );
4005 }