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