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