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