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