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