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