28daebaf14fe6fcdc3bc12996f16d96d0d448553
[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 =
1687 !This->screen->is_format_supported(This->screen, surf->base.info.format,
1688 surf->base.info.target,
1689 surf->base.info.nr_samples,
1690 PIPE_BIND_RENDER_TARGET);
1691 if (!fallback) {
1692 psurf = NineSurface9_GetSurface(surf, 0);
1693 if (!psurf)
1694 fallback = TRUE;
1695 }
1696
1697 if (!fallback) {
1698 pipe->clear_render_target(pipe, psurf, &rgba, x, y, w, h);
1699 } else {
1700 D3DLOCKED_RECT lock;
1701 union util_color uc;
1702 HRESULT hr;
1703 /* XXX: lock pRect and fix util_fill_rect */
1704 hr = NineSurface9_LockRect(surf, &lock, NULL, 0);
1705 if (FAILED(hr))
1706 return hr;
1707 util_pack_color_ub(color >> 16, color >> 8, color >> 0, color >> 24,
1708 surf->base.info.format, &uc);
1709 util_fill_rect(lock.pBits, surf->base.info.format,lock.Pitch,
1710 x, y, w, h, &uc);
1711 NineSurface9_UnlockRect(surf);
1712 }
1713
1714 return D3D_OK;
1715 }
1716
1717 HRESULT WINAPI
1718 NineDevice9_CreateOffscreenPlainSurface( struct NineDevice9 *This,
1719 UINT Width,
1720 UINT Height,
1721 D3DFORMAT Format,
1722 D3DPOOL Pool,
1723 IDirect3DSurface9 **ppSurface,
1724 HANDLE *pSharedHandle )
1725 {
1726 HRESULT hr;
1727
1728 DBG("This=%p Width=%u Height=%u Format=%s(0x%x) Pool=%u "
1729 "ppSurface=%p pSharedHandle=%p\n", This,
1730 Width, Height, d3dformat_to_string(Format), Format, Pool,
1731 ppSurface, pSharedHandle);
1732
1733 *ppSurface = NULL;
1734 user_assert(!pSharedHandle || Pool == D3DPOOL_DEFAULT
1735 || Pool == D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL);
1736 user_assert(Pool != D3DPOOL_MANAGED, D3DERR_INVALIDCALL);
1737
1738 /* Can be used with StretchRect and ColorFill. It's also always lockable.
1739 */
1740 hr = create_zs_or_rt_surface(This, 2, Pool, Width, Height,
1741 Format,
1742 D3DMULTISAMPLE_NONE, 0,
1743 TRUE,
1744 ppSurface, pSharedHandle);
1745 if (FAILED(hr))
1746 DBG("Failed to create surface.\n");
1747 return hr;
1748 }
1749
1750 HRESULT WINAPI
1751 NineDevice9_SetRenderTarget( struct NineDevice9 *This,
1752 DWORD RenderTargetIndex,
1753 IDirect3DSurface9 *pRenderTarget )
1754 {
1755 struct NineSurface9 *rt = NineSurface9(pRenderTarget);
1756 const unsigned i = RenderTargetIndex;
1757
1758 DBG("This=%p RenderTargetIndex=%u pRenderTarget=%p\n", This,
1759 RenderTargetIndex, pRenderTarget);
1760
1761 user_assert(i < This->caps.NumSimultaneousRTs, D3DERR_INVALIDCALL);
1762 user_assert(i != 0 || pRenderTarget, D3DERR_INVALIDCALL);
1763 user_assert(!pRenderTarget ||
1764 rt->desc.Usage & D3DUSAGE_RENDERTARGET, D3DERR_INVALIDCALL);
1765
1766 if (i == 0) {
1767 This->state.viewport.X = 0;
1768 This->state.viewport.Y = 0;
1769 This->state.viewport.Width = rt->desc.Width;
1770 This->state.viewport.Height = rt->desc.Height;
1771 This->state.viewport.MinZ = 0.0f;
1772 This->state.viewport.MaxZ = 1.0f;
1773
1774 This->state.scissor.minx = 0;
1775 This->state.scissor.miny = 0;
1776 This->state.scissor.maxx = rt->desc.Width;
1777 This->state.scissor.maxy = rt->desc.Height;
1778
1779 This->state.changed.group |= NINE_STATE_VIEWPORT | NINE_STATE_SCISSOR;
1780 }
1781
1782 if (This->state.rt[i] != NineSurface9(pRenderTarget)) {
1783 nine_bind(&This->state.rt[i], pRenderTarget);
1784 This->state.changed.group |= NINE_STATE_FB;
1785 }
1786 return D3D_OK;
1787 }
1788
1789 HRESULT WINAPI
1790 NineDevice9_GetRenderTarget( struct NineDevice9 *This,
1791 DWORD RenderTargetIndex,
1792 IDirect3DSurface9 **ppRenderTarget )
1793 {
1794 const unsigned i = RenderTargetIndex;
1795
1796 user_assert(i < This->caps.NumSimultaneousRTs, D3DERR_INVALIDCALL);
1797 user_assert(ppRenderTarget, D3DERR_INVALIDCALL);
1798
1799 *ppRenderTarget = (IDirect3DSurface9 *)This->state.rt[i];
1800 if (!This->state.rt[i])
1801 return D3DERR_NOTFOUND;
1802
1803 NineUnknown_AddRef(NineUnknown(This->state.rt[i]));
1804 return D3D_OK;
1805 }
1806
1807 HRESULT WINAPI
1808 NineDevice9_SetDepthStencilSurface( struct NineDevice9 *This,
1809 IDirect3DSurface9 *pNewZStencil )
1810 {
1811 DBG("This=%p pNewZStencil=%p\n", This, pNewZStencil);
1812
1813 if (This->state.ds != NineSurface9(pNewZStencil)) {
1814 nine_bind(&This->state.ds, pNewZStencil);
1815 This->state.changed.group |= NINE_STATE_FB;
1816 }
1817 return D3D_OK;
1818 }
1819
1820 HRESULT WINAPI
1821 NineDevice9_GetDepthStencilSurface( struct NineDevice9 *This,
1822 IDirect3DSurface9 **ppZStencilSurface )
1823 {
1824 user_assert(ppZStencilSurface, D3DERR_INVALIDCALL);
1825
1826 *ppZStencilSurface = (IDirect3DSurface9 *)This->state.ds;
1827 if (!This->state.ds)
1828 return D3DERR_NOTFOUND;
1829
1830 NineUnknown_AddRef(NineUnknown(This->state.ds));
1831 return D3D_OK;
1832 }
1833
1834 HRESULT WINAPI
1835 NineDevice9_BeginScene( struct NineDevice9 *This )
1836 {
1837 DBG("This=%p\n", This);
1838 user_assert(!This->in_scene, D3DERR_INVALIDCALL);
1839 This->in_scene = TRUE;
1840 /* Do we want to do anything else here ? */
1841 return D3D_OK;
1842 }
1843
1844 HRESULT WINAPI
1845 NineDevice9_EndScene( struct NineDevice9 *This )
1846 {
1847 DBG("This=%p\n", This);
1848 user_assert(This->in_scene, D3DERR_INVALIDCALL);
1849 This->in_scene = FALSE;
1850 return D3D_OK;
1851 }
1852
1853 HRESULT WINAPI
1854 NineDevice9_Clear( struct NineDevice9 *This,
1855 DWORD Count,
1856 const D3DRECT *pRects,
1857 DWORD Flags,
1858 D3DCOLOR Color,
1859 float Z,
1860 DWORD Stencil )
1861 {
1862 const int sRGB = This->state.rs[D3DRS_SRGBWRITEENABLE] ? 1 : 0;
1863 struct pipe_surface *cbuf, *zsbuf;
1864 struct pipe_context *pipe = This->pipe;
1865 struct NineSurface9 *zsbuf_surf = This->state.ds;
1866 struct NineSurface9 *rt;
1867 unsigned bufs = 0;
1868 unsigned r, i;
1869 union pipe_color_union rgba;
1870 unsigned rt_mask = 0;
1871 D3DRECT rect;
1872
1873 DBG("This=%p Count=%u pRects=%p Flags=%x Color=%08x Z=%f Stencil=%x\n",
1874 This, Count, pRects, Flags, Color, Z, Stencil);
1875
1876 user_assert(This->state.ds || !(Flags & NINED3DCLEAR_DEPTHSTENCIL),
1877 D3DERR_INVALIDCALL);
1878 user_assert(!(Flags & D3DCLEAR_STENCIL) ||
1879 (zsbuf_surf &&
1880 util_format_is_depth_and_stencil(zsbuf_surf->base.info.format)),
1881 D3DERR_INVALIDCALL);
1882 #ifdef NINE_STRICT
1883 user_assert((Count && pRects) || (!Count && !pRects), D3DERR_INVALIDCALL);
1884 #else
1885 user_warn((pRects && !Count) || (!pRects && Count));
1886 if (pRects && !Count)
1887 return D3D_OK;
1888 if (!pRects)
1889 Count = 0;
1890 #endif
1891
1892 if (Flags & D3DCLEAR_TARGET) bufs |= PIPE_CLEAR_COLOR;
1893 if (Flags & D3DCLEAR_ZBUFFER) bufs |= PIPE_CLEAR_DEPTH;
1894 if (Flags & D3DCLEAR_STENCIL) bufs |= PIPE_CLEAR_STENCIL;
1895 if (!bufs)
1896 return D3D_OK;
1897 d3dcolor_to_pipe_color_union(&rgba, Color);
1898
1899 nine_update_state(This, NINE_STATE_FB);
1900
1901 rect.x1 = This->state.viewport.X;
1902 rect.y1 = This->state.viewport.Y;
1903 rect.x2 = This->state.viewport.Width + rect.x1;
1904 rect.y2 = This->state.viewport.Height + rect.y1;
1905
1906 /* Both rectangles apply, which is weird, but that's D3D9. */
1907 if (This->state.rs[D3DRS_SCISSORTESTENABLE]) {
1908 rect.x1 = MAX2(rect.x1, This->state.scissor.minx);
1909 rect.y1 = MAX2(rect.y1, This->state.scissor.miny);
1910 rect.x2 = MIN2(rect.x2, This->state.scissor.maxx);
1911 rect.y2 = MIN2(rect.y2, This->state.scissor.maxy);
1912 }
1913
1914 if (Count) {
1915 /* Maybe apps like to specify a large rect ? */
1916 if (pRects[0].x1 <= rect.x1 && pRects[0].x2 >= rect.x2 &&
1917 pRects[0].y1 <= rect.y1 && pRects[0].y2 >= rect.y2) {
1918 DBG("First rect covers viewport.\n");
1919 Count = 0;
1920 pRects = NULL;
1921 }
1922 }
1923
1924 if (rect.x1 >= This->state.fb.width || rect.y1 >= This->state.fb.height)
1925 return D3D_OK;
1926
1927 for (i = 0; i < This->caps.NumSimultaneousRTs; ++i) {
1928 if (This->state.rt[i] && This->state.rt[i]->desc.Format != D3DFMT_NULL)
1929 rt_mask |= 1 << i;
1930 }
1931
1932 /* fast path, clears everything at once */
1933 if (!Count &&
1934 (!(bufs & PIPE_CLEAR_COLOR) || (rt_mask == This->state.rt_mask)) &&
1935 rect.x1 == 0 && rect.y1 == 0 &&
1936 /* Case we clear only render target. Check clear region vs rt. */
1937 ((!(bufs & (PIPE_CLEAR_DEPTH | PIPE_CLEAR_STENCIL)) &&
1938 rect.x2 >= This->state.fb.width &&
1939 rect.y2 >= This->state.fb.height) ||
1940 /* Case we clear depth buffer (and eventually rt too).
1941 * depth buffer size is always >= rt size. Compare to clear region */
1942 ((bufs & (PIPE_CLEAR_DEPTH | PIPE_CLEAR_STENCIL)) &&
1943 This->state.fb.zsbuf != NULL &&
1944 rect.x2 >= zsbuf_surf->desc.Width &&
1945 rect.y2 >= zsbuf_surf->desc.Height))) {
1946 DBG("Clear fast path\n");
1947 pipe->clear(pipe, bufs, &rgba, Z, Stencil);
1948 return D3D_OK;
1949 }
1950
1951 if (!Count) {
1952 Count = 1;
1953 pRects = &rect;
1954 }
1955
1956 for (i = 0; i < This->caps.NumSimultaneousRTs; ++i) {
1957 rt = This->state.rt[i];
1958 if (!rt || rt->desc.Format == D3DFMT_NULL ||
1959 !(Flags & D3DCLEAR_TARGET))
1960 continue; /* save space, compiler should hoist this */
1961 cbuf = NineSurface9_GetSurface(rt, sRGB);
1962 for (r = 0; r < Count; ++r) {
1963 /* Don't trust users to pass these in the right order. */
1964 unsigned x1 = MIN2(pRects[r].x1, pRects[r].x2);
1965 unsigned y1 = MIN2(pRects[r].y1, pRects[r].y2);
1966 unsigned x2 = MAX2(pRects[r].x1, pRects[r].x2);
1967 unsigned y2 = MAX2(pRects[r].y1, pRects[r].y2);
1968 #ifndef NINE_LAX
1969 /* Drop negative rectangles (like wine expects). */
1970 if (pRects[r].x1 > pRects[r].x2) continue;
1971 if (pRects[r].y1 > pRects[r].y2) continue;
1972 #endif
1973
1974 x1 = MAX2(x1, rect.x1);
1975 y1 = MAX2(y1, rect.y1);
1976 x2 = MIN3(x2, rect.x2, rt->desc.Width);
1977 y2 = MIN3(y2, rect.y2, rt->desc.Height);
1978
1979 DBG("Clearing (%u..%u)x(%u..%u)\n", x1, x2, y1, y2);
1980 pipe->clear_render_target(pipe, cbuf, &rgba,
1981 x1, y1, x2 - x1, y2 - y1);
1982 }
1983 }
1984 if (!(Flags & NINED3DCLEAR_DEPTHSTENCIL))
1985 return D3D_OK;
1986
1987 bufs &= PIPE_CLEAR_DEPTHSTENCIL;
1988
1989 for (r = 0; r < Count; ++r) {
1990 unsigned x1 = MIN2(pRects[r].x1, pRects[r].x2);
1991 unsigned y1 = MIN2(pRects[r].y1, pRects[r].y2);
1992 unsigned x2 = MAX2(pRects[r].x1, pRects[r].x2);
1993 unsigned y2 = MAX2(pRects[r].y1, pRects[r].y2);
1994 #ifndef NINE_LAX
1995 /* Drop negative rectangles. */
1996 if (pRects[r].x1 > pRects[r].x2) continue;
1997 if (pRects[r].y1 > pRects[r].y2) continue;
1998 #endif
1999
2000 x1 = MIN2(x1, rect.x1);
2001 y1 = MIN2(y1, rect.y1);
2002 x2 = MIN3(x2, rect.x2, zsbuf_surf->desc.Width);
2003 y2 = MIN3(y2, rect.y2, zsbuf_surf->desc.Height);
2004
2005 zsbuf = NineSurface9_GetSurface(zsbuf_surf, 0);
2006 assert(zsbuf);
2007 pipe->clear_depth_stencil(pipe, zsbuf, bufs, Z, Stencil,
2008 x1, y1, x2 - x1, y2 - y1);
2009 }
2010 return D3D_OK;
2011 }
2012
2013 HRESULT WINAPI
2014 NineDevice9_SetTransform( struct NineDevice9 *This,
2015 D3DTRANSFORMSTATETYPE State,
2016 const D3DMATRIX *pMatrix )
2017 {
2018 struct nine_state *state = This->update;
2019 D3DMATRIX *M = nine_state_access_transform(state, State, TRUE);
2020
2021 DBG("This=%p State=%d pMatrix=%p\n", This, State, pMatrix);
2022
2023 user_assert(M, D3DERR_INVALIDCALL);
2024
2025 *M = *pMatrix;
2026 state->ff.changed.transform[State / 32] |= 1 << (State % 32);
2027 state->changed.group |= NINE_STATE_FF;
2028
2029 return D3D_OK;
2030 }
2031
2032 HRESULT WINAPI
2033 NineDevice9_GetTransform( struct NineDevice9 *This,
2034 D3DTRANSFORMSTATETYPE State,
2035 D3DMATRIX *pMatrix )
2036 {
2037 D3DMATRIX *M = nine_state_access_transform(&This->state, State, FALSE);
2038 user_assert(M, D3DERR_INVALIDCALL);
2039 *pMatrix = *M;
2040 return D3D_OK;
2041 }
2042
2043 HRESULT WINAPI
2044 NineDevice9_MultiplyTransform( struct NineDevice9 *This,
2045 D3DTRANSFORMSTATETYPE State,
2046 const D3DMATRIX *pMatrix )
2047 {
2048 struct nine_state *state = This->update;
2049 D3DMATRIX T;
2050 D3DMATRIX *M = nine_state_access_transform(state, State, TRUE);
2051
2052 DBG("This=%p State=%d pMatrix=%p\n", This, State, pMatrix);
2053
2054 user_assert(M, D3DERR_INVALIDCALL);
2055
2056 nine_d3d_matrix_matrix_mul(&T, pMatrix, M);
2057 return NineDevice9_SetTransform(This, State, &T);
2058 }
2059
2060 HRESULT WINAPI
2061 NineDevice9_SetViewport( struct NineDevice9 *This,
2062 const D3DVIEWPORT9 *pViewport )
2063 {
2064 struct nine_state *state = This->update;
2065
2066 DBG("X=%u Y=%u W=%u H=%u MinZ=%f MaxZ=%f\n",
2067 pViewport->X, pViewport->Y, pViewport->Width, pViewport->Height,
2068 pViewport->MinZ, pViewport->MaxZ);
2069
2070 state->viewport = *pViewport;
2071 state->changed.group |= NINE_STATE_VIEWPORT;
2072
2073 return D3D_OK;
2074 }
2075
2076 HRESULT WINAPI
2077 NineDevice9_GetViewport( struct NineDevice9 *This,
2078 D3DVIEWPORT9 *pViewport )
2079 {
2080 *pViewport = This->state.viewport;
2081 return D3D_OK;
2082 }
2083
2084 HRESULT WINAPI
2085 NineDevice9_SetMaterial( struct NineDevice9 *This,
2086 const D3DMATERIAL9 *pMaterial )
2087 {
2088 struct nine_state *state = This->update;
2089
2090 DBG("This=%p pMaterial=%p\n", This, pMaterial);
2091 if (pMaterial)
2092 nine_dump_D3DMATERIAL9(DBG_FF, pMaterial);
2093
2094 user_assert(pMaterial, E_POINTER);
2095
2096 state->ff.material = *pMaterial;
2097 state->changed.group |= NINE_STATE_FF_MATERIAL;
2098
2099 return D3D_OK;
2100 }
2101
2102 HRESULT WINAPI
2103 NineDevice9_GetMaterial( struct NineDevice9 *This,
2104 D3DMATERIAL9 *pMaterial )
2105 {
2106 user_assert(pMaterial, E_POINTER);
2107 *pMaterial = This->state.ff.material;
2108 return D3D_OK;
2109 }
2110
2111 HRESULT WINAPI
2112 NineDevice9_SetLight( struct NineDevice9 *This,
2113 DWORD Index,
2114 const D3DLIGHT9 *pLight )
2115 {
2116 struct nine_state *state = This->update;
2117
2118 DBG("This=%p Index=%u pLight=%p\n", This, Index, pLight);
2119 if (pLight)
2120 nine_dump_D3DLIGHT9(DBG_FF, pLight);
2121
2122 user_assert(pLight, D3DERR_INVALIDCALL);
2123 user_assert(pLight->Type < NINED3DLIGHT_INVALID, D3DERR_INVALIDCALL);
2124
2125 user_assert(Index < NINE_MAX_LIGHTS, D3DERR_INVALIDCALL); /* sanity */
2126
2127 if (Index >= state->ff.num_lights) {
2128 unsigned n = state->ff.num_lights;
2129 unsigned N = Index + 1;
2130
2131 state->ff.light = REALLOC(state->ff.light, n * sizeof(D3DLIGHT9),
2132 N * sizeof(D3DLIGHT9));
2133 if (!state->ff.light)
2134 return E_OUTOFMEMORY;
2135 state->ff.num_lights = N;
2136
2137 for (; n < Index; ++n)
2138 state->ff.light[n].Type = (D3DLIGHTTYPE)NINED3DLIGHT_INVALID;
2139 }
2140 state->ff.light[Index] = *pLight;
2141
2142 if (pLight->Type == D3DLIGHT_SPOT && pLight->Theta >= pLight->Phi) {
2143 DBG("Warning: clamping D3DLIGHT9.Theta\n");
2144 state->ff.light[Index].Theta = state->ff.light[Index].Phi;
2145 }
2146 if (pLight->Type != D3DLIGHT_DIRECTIONAL &&
2147 pLight->Attenuation0 == 0.0f &&
2148 pLight->Attenuation1 == 0.0f &&
2149 pLight->Attenuation2 == 0.0f) {
2150 DBG("Warning: all D3DLIGHT9.Attenuation[i] are 0\n");
2151 }
2152
2153 state->changed.group |= NINE_STATE_FF_LIGHTING;
2154
2155 return D3D_OK;
2156 }
2157
2158 HRESULT WINAPI
2159 NineDevice9_GetLight( struct NineDevice9 *This,
2160 DWORD Index,
2161 D3DLIGHT9 *pLight )
2162 {
2163 const struct nine_state *state = &This->state;
2164
2165 user_assert(pLight, D3DERR_INVALIDCALL);
2166 user_assert(Index < state->ff.num_lights, D3DERR_INVALIDCALL);
2167 user_assert(state->ff.light[Index].Type < NINED3DLIGHT_INVALID,
2168 D3DERR_INVALIDCALL);
2169
2170 *pLight = state->ff.light[Index];
2171
2172 return D3D_OK;
2173 }
2174
2175 HRESULT WINAPI
2176 NineDevice9_LightEnable( struct NineDevice9 *This,
2177 DWORD Index,
2178 BOOL Enable )
2179 {
2180 struct nine_state *state = This->update;
2181 unsigned i;
2182
2183 DBG("This=%p Index=%u Enable=%i\n", This, Index, Enable);
2184
2185 if (Index >= state->ff.num_lights ||
2186 state->ff.light[Index].Type == NINED3DLIGHT_INVALID) {
2187 /* This should create a default light. */
2188 D3DLIGHT9 light;
2189 memset(&light, 0, sizeof(light));
2190 light.Type = D3DLIGHT_DIRECTIONAL;
2191 light.Diffuse.r = 1.0f;
2192 light.Diffuse.g = 1.0f;
2193 light.Diffuse.b = 1.0f;
2194 light.Direction.z = 1.0f;
2195 NineDevice9_SetLight(This, Index, &light);
2196 }
2197 user_assert(Index < state->ff.num_lights, D3DERR_INVALIDCALL);
2198
2199 for (i = 0; i < state->ff.num_lights_active; ++i) {
2200 if (state->ff.active_light[i] == Index)
2201 break;
2202 }
2203
2204 if (Enable) {
2205 if (i < state->ff.num_lights_active)
2206 return D3D_OK;
2207 /* XXX wine thinks this should still succeed:
2208 */
2209 user_assert(i < NINE_MAX_LIGHTS_ACTIVE, D3DERR_INVALIDCALL);
2210
2211 state->ff.active_light[i] = Index;
2212 state->ff.num_lights_active++;
2213 } else {
2214 if (i == state->ff.num_lights_active)
2215 return D3D_OK;
2216 --state->ff.num_lights_active;
2217 for (; i < state->ff.num_lights_active; ++i)
2218 state->ff.active_light[i] = state->ff.active_light[i + 1];
2219 }
2220 state->changed.group |= NINE_STATE_FF_LIGHTING;
2221
2222 return D3D_OK;
2223 }
2224
2225 HRESULT WINAPI
2226 NineDevice9_GetLightEnable( struct NineDevice9 *This,
2227 DWORD Index,
2228 BOOL *pEnable )
2229 {
2230 const struct nine_state *state = &This->state;
2231 unsigned i;
2232
2233 user_assert(Index < state->ff.num_lights, D3DERR_INVALIDCALL);
2234 user_assert(state->ff.light[Index].Type < NINED3DLIGHT_INVALID,
2235 D3DERR_INVALIDCALL);
2236
2237 for (i = 0; i < state->ff.num_lights_active; ++i)
2238 if (state->ff.active_light[i] == Index)
2239 break;
2240
2241 *pEnable = i != state->ff.num_lights_active ? 128 : 0; // Taken from wine
2242
2243 return D3D_OK;
2244 }
2245
2246 HRESULT WINAPI
2247 NineDevice9_SetClipPlane( struct NineDevice9 *This,
2248 DWORD Index,
2249 const float *pPlane )
2250 {
2251 struct nine_state *state = This->update;
2252
2253 user_assert(pPlane, D3DERR_INVALIDCALL);
2254
2255 DBG("This=%p Index=%u pPlane=%f %f %f %f\n", This, Index,
2256 pPlane[0], pPlane[1],
2257 pPlane[2], pPlane[3]);
2258
2259 user_assert(Index < PIPE_MAX_CLIP_PLANES, D3DERR_INVALIDCALL);
2260
2261 memcpy(&state->clip.ucp[Index][0], pPlane, sizeof(state->clip.ucp[0]));
2262 state->changed.ucp |= 1 << Index;
2263
2264 return D3D_OK;
2265 }
2266
2267 HRESULT WINAPI
2268 NineDevice9_GetClipPlane( struct NineDevice9 *This,
2269 DWORD Index,
2270 float *pPlane )
2271 {
2272 const struct nine_state *state = &This->state;
2273
2274 user_assert(Index < PIPE_MAX_CLIP_PLANES, D3DERR_INVALIDCALL);
2275
2276 memcpy(pPlane, &state->clip.ucp[Index][0], sizeof(state->clip.ucp[0]));
2277 return D3D_OK;
2278 }
2279
2280 #define RESZ_CODE 0x7fa05000
2281
2282 static HRESULT
2283 NineDevice9_ResolveZ( struct NineDevice9 *This )
2284 {
2285 struct nine_state *state = &This->state;
2286 const struct util_format_description *desc;
2287 struct NineSurface9 *source = state->ds;
2288 struct NineBaseTexture9 *destination = state->texture[0];
2289 struct pipe_resource *src, *dst;
2290 struct pipe_blit_info blit;
2291
2292 DBG("RESZ resolve\n");
2293
2294 user_assert(source && destination &&
2295 destination->base.type == D3DRTYPE_TEXTURE, D3DERR_INVALIDCALL);
2296
2297 src = source->base.resource;
2298 dst = destination->base.resource;
2299
2300 user_assert(src && dst, D3DERR_INVALIDCALL);
2301
2302 /* check dst is depth format. we know already for src */
2303 desc = util_format_description(dst->format);
2304 user_assert(desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS, D3DERR_INVALIDCALL);
2305
2306 memset(&blit, 0, sizeof(blit));
2307 blit.src.resource = src;
2308 blit.src.level = 0;
2309 blit.src.format = src->format;
2310 blit.src.box.z = 0;
2311 blit.src.box.depth = 1;
2312 blit.src.box.x = 0;
2313 blit.src.box.y = 0;
2314 blit.src.box.width = src->width0;
2315 blit.src.box.height = src->height0;
2316
2317 blit.dst.resource = dst;
2318 blit.dst.level = 0;
2319 blit.dst.format = dst->format;
2320 blit.dst.box.z = 0;
2321 blit.dst.box.depth = 1;
2322 blit.dst.box.x = 0;
2323 blit.dst.box.y = 0;
2324 blit.dst.box.width = dst->width0;
2325 blit.dst.box.height = dst->height0;
2326
2327 blit.mask = PIPE_MASK_ZS;
2328 blit.filter = PIPE_TEX_FILTER_NEAREST;
2329 blit.scissor_enable = FALSE;
2330
2331 This->pipe->blit(This->pipe, &blit);
2332 return D3D_OK;
2333 }
2334
2335 #define ALPHA_TO_COVERAGE_ENABLE MAKEFOURCC('A', '2', 'M', '1')
2336 #define ALPHA_TO_COVERAGE_DISABLE MAKEFOURCC('A', '2', 'M', '0')
2337
2338 HRESULT WINAPI
2339 NineDevice9_SetRenderState( struct NineDevice9 *This,
2340 D3DRENDERSTATETYPE State,
2341 DWORD Value )
2342 {
2343 struct nine_state *state = This->update;
2344
2345 DBG("This=%p State=%u(%s) Value=%08x\n", This,
2346 State, nine_d3drs_to_string(State), Value);
2347
2348 /* Amd hacks (equivalent to GL extensions) */
2349 if (State == D3DRS_POINTSIZE) {
2350 if (Value == RESZ_CODE)
2351 return NineDevice9_ResolveZ(This);
2352
2353 if (Value == ALPHA_TO_COVERAGE_ENABLE ||
2354 Value == ALPHA_TO_COVERAGE_DISABLE) {
2355 state->rs[NINED3DRS_ALPHACOVERAGE] = (Value == ALPHA_TO_COVERAGE_ENABLE);
2356 state->changed.group |= NINE_STATE_BLEND;
2357 return D3D_OK;
2358 }
2359 }
2360
2361 /* NV hack */
2362 if (State == D3DRS_ADAPTIVETESS_Y &&
2363 (Value == D3DFMT_ATOC || (Value == D3DFMT_UNKNOWN && state->rs[NINED3DRS_ALPHACOVERAGE]))) {
2364 state->rs[NINED3DRS_ALPHACOVERAGE] = (Value == D3DFMT_ATOC);
2365 state->changed.group |= NINE_STATE_BLEND;
2366 return D3D_OK;
2367 }
2368
2369 user_assert(State < Elements(state->rs), D3DERR_INVALIDCALL);
2370
2371 if (likely(state->rs[State] != Value) || unlikely(This->is_recording)) {
2372 state->rs[State] = Value;
2373 state->changed.rs[State / 32] |= 1 << (State % 32);
2374 state->changed.group |= nine_render_state_group[State];
2375 }
2376
2377 return D3D_OK;
2378 }
2379
2380 HRESULT WINAPI
2381 NineDevice9_GetRenderState( struct NineDevice9 *This,
2382 D3DRENDERSTATETYPE State,
2383 DWORD *pValue )
2384 {
2385 user_assert(State < Elements(This->state.rs), D3DERR_INVALIDCALL);
2386
2387 *pValue = This->state.rs[State];
2388 return D3D_OK;
2389 }
2390
2391 HRESULT WINAPI
2392 NineDevice9_CreateStateBlock( struct NineDevice9 *This,
2393 D3DSTATEBLOCKTYPE Type,
2394 IDirect3DStateBlock9 **ppSB )
2395 {
2396 struct NineStateBlock9 *nsb;
2397 struct nine_state *dst;
2398 HRESULT hr;
2399 enum nine_stateblock_type type;
2400 unsigned s;
2401
2402 DBG("This=%p Type=%u ppSB=%p\n", This, Type, ppSB);
2403
2404 user_assert(Type == D3DSBT_ALL ||
2405 Type == D3DSBT_VERTEXSTATE ||
2406 Type == D3DSBT_PIXELSTATE, D3DERR_INVALIDCALL);
2407
2408 switch (Type) {
2409 case D3DSBT_VERTEXSTATE: type = NINESBT_VERTEXSTATE; break;
2410 case D3DSBT_PIXELSTATE: type = NINESBT_PIXELSTATE; break;
2411 default:
2412 type = NINESBT_ALL;
2413 break;
2414 }
2415
2416 hr = NineStateBlock9_new(This, &nsb, type);
2417 if (FAILED(hr))
2418 return hr;
2419 *ppSB = (IDirect3DStateBlock9 *)nsb;
2420 dst = &nsb->state;
2421
2422 dst->changed.group =
2423 NINE_STATE_TEXTURE |
2424 NINE_STATE_SAMPLER;
2425
2426 if (Type == D3DSBT_ALL || Type == D3DSBT_VERTEXSTATE) {
2427 dst->changed.group |=
2428 NINE_STATE_FF_LIGHTING |
2429 NINE_STATE_VS | NINE_STATE_VS_CONST |
2430 NINE_STATE_VDECL;
2431 /* TODO: texture/sampler state */
2432 memcpy(dst->changed.rs,
2433 nine_render_states_vertex, sizeof(dst->changed.rs));
2434 nine_ranges_insert(&dst->changed.vs_const_f, 0, This->max_vs_const_f,
2435 &This->range_pool);
2436 dst->changed.vs_const_i = 0xffff;
2437 dst->changed.vs_const_b = 0xffff;
2438 for (s = 0; s < NINE_MAX_SAMPLERS; ++s)
2439 dst->changed.sampler[s] |= 1 << D3DSAMP_DMAPOFFSET;
2440 if (This->state.ff.num_lights) {
2441 dst->ff.num_lights = This->state.ff.num_lights;
2442 /* zero'd -> light type won't be NINED3DLIGHT_INVALID, so
2443 * all currently existing lights will be captured
2444 */
2445 dst->ff.light = CALLOC(This->state.ff.num_lights,
2446 sizeof(D3DLIGHT9));
2447 if (!dst->ff.light) {
2448 nine_bind(ppSB, NULL);
2449 return E_OUTOFMEMORY;
2450 }
2451 }
2452 }
2453 if (Type == D3DSBT_ALL || Type == D3DSBT_PIXELSTATE) {
2454 dst->changed.group |=
2455 NINE_STATE_PS | NINE_STATE_PS_CONST;
2456 /* TODO: texture/sampler state */
2457 memcpy(dst->changed.rs,
2458 nine_render_states_pixel, sizeof(dst->changed.rs));
2459 nine_ranges_insert(&dst->changed.ps_const_f, 0, This->max_ps_const_f,
2460 &This->range_pool);
2461 dst->changed.ps_const_i = 0xffff;
2462 dst->changed.ps_const_b = 0xffff;
2463 for (s = 0; s < NINE_MAX_SAMPLERS; ++s)
2464 dst->changed.sampler[s] |= 0x1ffe;
2465 }
2466 if (Type == D3DSBT_ALL) {
2467 dst->changed.group |=
2468 NINE_STATE_VIEWPORT |
2469 NINE_STATE_SCISSOR |
2470 NINE_STATE_RASTERIZER |
2471 NINE_STATE_BLEND |
2472 NINE_STATE_DSA |
2473 NINE_STATE_IDXBUF |
2474 NINE_STATE_MATERIAL |
2475 NINE_STATE_BLEND_COLOR |
2476 NINE_STATE_SAMPLE_MASK;
2477 memset(dst->changed.rs, ~0, (D3DRS_COUNT / 32) * sizeof(uint32_t));
2478 dst->changed.rs[D3DRS_LAST / 32] |= (1 << (D3DRS_COUNT % 32)) - 1;
2479 dst->changed.vtxbuf = (1ULL << This->caps.MaxStreams) - 1;
2480 dst->changed.stream_freq = dst->changed.vtxbuf;
2481 dst->changed.ucp = (1 << PIPE_MAX_CLIP_PLANES) - 1;
2482 dst->changed.texture = (1 << NINE_MAX_SAMPLERS) - 1;
2483 }
2484 NineStateBlock9_Capture(NineStateBlock9(*ppSB));
2485
2486 /* TODO: fixed function state */
2487
2488 return D3D_OK;
2489 }
2490
2491 HRESULT WINAPI
2492 NineDevice9_BeginStateBlock( struct NineDevice9 *This )
2493 {
2494 HRESULT hr;
2495
2496 DBG("This=%p\n", This);
2497
2498 user_assert(!This->record, D3DERR_INVALIDCALL);
2499
2500 hr = NineStateBlock9_new(This, &This->record, NINESBT_CUSTOM);
2501 if (FAILED(hr))
2502 return hr;
2503 NineUnknown_ConvertRefToBind(NineUnknown(This->record));
2504
2505 This->update = &This->record->state;
2506 This->is_recording = TRUE;
2507
2508 return D3D_OK;
2509 }
2510
2511 HRESULT WINAPI
2512 NineDevice9_EndStateBlock( struct NineDevice9 *This,
2513 IDirect3DStateBlock9 **ppSB )
2514 {
2515 DBG("This=%p ppSB=%p\n", This, ppSB);
2516
2517 user_assert(This->record, D3DERR_INVALIDCALL);
2518
2519 This->update = &This->state;
2520 This->is_recording = FALSE;
2521
2522 NineUnknown_AddRef(NineUnknown(This->record));
2523 *ppSB = (IDirect3DStateBlock9 *)This->record;
2524 NineUnknown_Unbind(NineUnknown(This->record));
2525 This->record = NULL;
2526
2527 return D3D_OK;
2528 }
2529
2530 HRESULT WINAPI
2531 NineDevice9_SetClipStatus( struct NineDevice9 *This,
2532 const D3DCLIPSTATUS9 *pClipStatus )
2533 {
2534 STUB(D3DERR_INVALIDCALL);
2535 }
2536
2537 HRESULT WINAPI
2538 NineDevice9_GetClipStatus( struct NineDevice9 *This,
2539 D3DCLIPSTATUS9 *pClipStatus )
2540 {
2541 STUB(D3DERR_INVALIDCALL);
2542 }
2543
2544 HRESULT WINAPI
2545 NineDevice9_GetTexture( struct NineDevice9 *This,
2546 DWORD Stage,
2547 IDirect3DBaseTexture9 **ppTexture )
2548 {
2549 user_assert(Stage < This->caps.MaxSimultaneousTextures ||
2550 Stage == D3DDMAPSAMPLER ||
2551 (Stage >= D3DVERTEXTEXTURESAMPLER0 &&
2552 Stage <= D3DVERTEXTEXTURESAMPLER3), D3DERR_INVALIDCALL);
2553 user_assert(ppTexture, D3DERR_INVALIDCALL);
2554
2555 if (Stage >= D3DDMAPSAMPLER)
2556 Stage = Stage - D3DDMAPSAMPLER + NINE_MAX_SAMPLERS_PS;
2557
2558 *ppTexture = (IDirect3DBaseTexture9 *)This->state.texture[Stage];
2559
2560 if (This->state.texture[Stage])
2561 NineUnknown_AddRef(NineUnknown(This->state.texture[Stage]));
2562 return D3D_OK;
2563 }
2564
2565 HRESULT WINAPI
2566 NineDevice9_SetTexture( struct NineDevice9 *This,
2567 DWORD Stage,
2568 IDirect3DBaseTexture9 *pTexture )
2569 {
2570 struct nine_state *state = This->update;
2571 struct NineBaseTexture9 *tex = NineBaseTexture9(pTexture);
2572
2573 DBG("This=%p Stage=%u pTexture=%p\n", This, Stage, pTexture);
2574
2575 user_assert(Stage < This->caps.MaxSimultaneousTextures ||
2576 Stage == D3DDMAPSAMPLER ||
2577 (Stage >= D3DVERTEXTEXTURESAMPLER0 &&
2578 Stage <= D3DVERTEXTEXTURESAMPLER3), D3DERR_INVALIDCALL);
2579 user_assert(!tex || (tex->base.pool != D3DPOOL_SCRATCH &&
2580 tex->base.pool != D3DPOOL_SYSTEMMEM), D3DERR_INVALIDCALL);
2581
2582 if (Stage >= D3DDMAPSAMPLER)
2583 Stage = Stage - D3DDMAPSAMPLER + NINE_MAX_SAMPLERS_PS;
2584
2585 if (!This->is_recording) {
2586 struct NineBaseTexture9 *old = state->texture[Stage];
2587 if (old == tex)
2588 return D3D_OK;
2589
2590 state->samplers_shadow &= ~(1 << Stage);
2591 if (tex) {
2592 state->samplers_shadow |= tex->shadow << Stage;
2593
2594 if ((tex->managed.dirty | tex->dirty_mip) && LIST_IS_EMPTY(&tex->list))
2595 list_add(&tex->list, &This->update_textures);
2596
2597 tex->bind_count++;
2598 }
2599 if (old)
2600 old->bind_count--;
2601 }
2602 nine_bind(&state->texture[Stage], pTexture);
2603
2604 state->changed.texture |= 1 << Stage;
2605 state->changed.group |= NINE_STATE_TEXTURE;
2606
2607 return D3D_OK;
2608 }
2609
2610 HRESULT WINAPI
2611 NineDevice9_GetTextureStageState( struct NineDevice9 *This,
2612 DWORD Stage,
2613 D3DTEXTURESTAGESTATETYPE Type,
2614 DWORD *pValue )
2615 {
2616 const struct nine_state *state = &This->state;
2617
2618 user_assert(Stage < Elements(state->ff.tex_stage), D3DERR_INVALIDCALL);
2619 user_assert(Type < Elements(state->ff.tex_stage[0]), D3DERR_INVALIDCALL);
2620
2621 *pValue = state->ff.tex_stage[Stage][Type];
2622
2623 return D3D_OK;
2624 }
2625
2626 HRESULT WINAPI
2627 NineDevice9_SetTextureStageState( struct NineDevice9 *This,
2628 DWORD Stage,
2629 D3DTEXTURESTAGESTATETYPE Type,
2630 DWORD Value )
2631 {
2632 struct nine_state *state = This->update;
2633
2634 DBG("Stage=%u Type=%u Value=%08x\n", Stage, Type, Value);
2635 nine_dump_D3DTSS_value(DBG_FF, Type, Value);
2636
2637 user_assert(Stage < Elements(state->ff.tex_stage), D3DERR_INVALIDCALL);
2638 user_assert(Type < Elements(state->ff.tex_stage[0]), D3DERR_INVALIDCALL);
2639
2640 state->ff.tex_stage[Stage][Type] = Value;
2641
2642 state->changed.group |= NINE_STATE_FF_PSSTAGES;
2643 state->ff.changed.tex_stage[Stage][Type / 32] |= 1 << (Type % 32);
2644
2645 return D3D_OK;
2646 }
2647
2648 HRESULT WINAPI
2649 NineDevice9_GetSamplerState( struct NineDevice9 *This,
2650 DWORD Sampler,
2651 D3DSAMPLERSTATETYPE Type,
2652 DWORD *pValue )
2653 {
2654 user_assert(Sampler < This->caps.MaxSimultaneousTextures ||
2655 Sampler == D3DDMAPSAMPLER ||
2656 (Sampler >= D3DVERTEXTEXTURESAMPLER0 &&
2657 Sampler <= D3DVERTEXTEXTURESAMPLER3), D3DERR_INVALIDCALL);
2658
2659 if (Sampler >= D3DDMAPSAMPLER)
2660 Sampler = Sampler - D3DDMAPSAMPLER + NINE_MAX_SAMPLERS_PS;
2661
2662 *pValue = This->state.samp[Sampler][Type];
2663 return D3D_OK;
2664 }
2665
2666 HRESULT WINAPI
2667 NineDevice9_SetSamplerState( struct NineDevice9 *This,
2668 DWORD Sampler,
2669 D3DSAMPLERSTATETYPE Type,
2670 DWORD Value )
2671 {
2672 struct nine_state *state = This->update;
2673
2674 DBG("This=%p Sampler=%u Type=%s Value=%08x\n", This,
2675 Sampler, nine_D3DSAMP_to_str(Type), Value);
2676
2677 user_assert(Sampler < This->caps.MaxSimultaneousTextures ||
2678 Sampler == D3DDMAPSAMPLER ||
2679 (Sampler >= D3DVERTEXTEXTURESAMPLER0 &&
2680 Sampler <= D3DVERTEXTEXTURESAMPLER3), D3DERR_INVALIDCALL);
2681
2682 if (Sampler >= D3DDMAPSAMPLER)
2683 Sampler = Sampler - D3DDMAPSAMPLER + NINE_MAX_SAMPLERS_PS;
2684
2685 state->samp[Sampler][Type] = Value;
2686 state->changed.group |= NINE_STATE_SAMPLER;
2687 state->changed.sampler[Sampler] |= 1 << Type;
2688
2689 if (Type == D3DSAMP_SRGBTEXTURE)
2690 state->changed.srgb = TRUE;
2691
2692 return D3D_OK;
2693 }
2694
2695 HRESULT WINAPI
2696 NineDevice9_ValidateDevice( struct NineDevice9 *This,
2697 DWORD *pNumPasses )
2698 {
2699 const struct nine_state *state = &This->state;
2700 unsigned i;
2701 unsigned w = 0, h = 0;
2702
2703 DBG("This=%p pNumPasses=%p\n", This, pNumPasses);
2704
2705 for (i = 0; i < Elements(state->samp); ++i) {
2706 if (state->samp[i][D3DSAMP_MINFILTER] == D3DTEXF_NONE ||
2707 state->samp[i][D3DSAMP_MAGFILTER] == D3DTEXF_NONE)
2708 return D3DERR_UNSUPPORTEDTEXTUREFILTER;
2709 }
2710
2711 for (i = 0; i < This->caps.NumSimultaneousRTs; ++i) {
2712 if (!state->rt[i])
2713 continue;
2714 if (w == 0) {
2715 w = state->rt[i]->desc.Width;
2716 h = state->rt[i]->desc.Height;
2717 } else
2718 if (state->rt[i]->desc.Width != w || state->rt[i]->desc.Height != h) {
2719 return D3DERR_CONFLICTINGRENDERSTATE;
2720 }
2721 }
2722 if (state->ds &&
2723 (state->rs[D3DRS_ZENABLE] || state->rs[D3DRS_STENCILENABLE])) {
2724 if (w != 0 &&
2725 (state->ds->desc.Width != w || state->ds->desc.Height != h))
2726 return D3DERR_CONFLICTINGRENDERSTATE;
2727 }
2728
2729 if (pNumPasses)
2730 *pNumPasses = 1;
2731
2732 return D3D_OK;
2733 }
2734
2735 HRESULT WINAPI
2736 NineDevice9_SetPaletteEntries( struct NineDevice9 *This,
2737 UINT PaletteNumber,
2738 const PALETTEENTRY *pEntries )
2739 {
2740 STUB(D3D_OK); /* like wine */
2741 }
2742
2743 HRESULT WINAPI
2744 NineDevice9_GetPaletteEntries( struct NineDevice9 *This,
2745 UINT PaletteNumber,
2746 PALETTEENTRY *pEntries )
2747 {
2748 STUB(D3DERR_INVALIDCALL);
2749 }
2750
2751 HRESULT WINAPI
2752 NineDevice9_SetCurrentTexturePalette( struct NineDevice9 *This,
2753 UINT PaletteNumber )
2754 {
2755 STUB(D3D_OK); /* like wine */
2756 }
2757
2758 HRESULT WINAPI
2759 NineDevice9_GetCurrentTexturePalette( struct NineDevice9 *This,
2760 UINT *PaletteNumber )
2761 {
2762 STUB(D3DERR_INVALIDCALL);
2763 }
2764
2765 HRESULT WINAPI
2766 NineDevice9_SetScissorRect( struct NineDevice9 *This,
2767 const RECT *pRect )
2768 {
2769 struct nine_state *state = This->update;
2770
2771 DBG("x=(%u..%u) y=(%u..%u)\n",
2772 pRect->left, pRect->top, pRect->right, pRect->bottom);
2773
2774 state->scissor.minx = pRect->left;
2775 state->scissor.miny = pRect->top;
2776 state->scissor.maxx = pRect->right;
2777 state->scissor.maxy = pRect->bottom;
2778
2779 state->changed.group |= NINE_STATE_SCISSOR;
2780
2781 return D3D_OK;
2782 }
2783
2784 HRESULT WINAPI
2785 NineDevice9_GetScissorRect( struct NineDevice9 *This,
2786 RECT *pRect )
2787 {
2788 pRect->left = This->state.scissor.minx;
2789 pRect->top = This->state.scissor.miny;
2790 pRect->right = This->state.scissor.maxx;
2791 pRect->bottom = This->state.scissor.maxy;
2792
2793 return D3D_OK;
2794 }
2795
2796 HRESULT WINAPI
2797 NineDevice9_SetSoftwareVertexProcessing( struct NineDevice9 *This,
2798 BOOL bSoftware )
2799 {
2800 STUB(D3DERR_INVALIDCALL);
2801 }
2802
2803 BOOL WINAPI
2804 NineDevice9_GetSoftwareVertexProcessing( struct NineDevice9 *This )
2805 {
2806 return !!(This->params.BehaviorFlags & D3DCREATE_SOFTWARE_VERTEXPROCESSING);
2807 }
2808
2809 HRESULT WINAPI
2810 NineDevice9_SetNPatchMode( struct NineDevice9 *This,
2811 float nSegments )
2812 {
2813 STUB(D3DERR_INVALIDCALL);
2814 }
2815
2816 float WINAPI
2817 NineDevice9_GetNPatchMode( struct NineDevice9 *This )
2818 {
2819 STUB(0);
2820 }
2821
2822 static inline void
2823 init_draw_info(struct pipe_draw_info *info,
2824 struct NineDevice9 *dev, D3DPRIMITIVETYPE type, UINT count)
2825 {
2826 info->mode = d3dprimitivetype_to_pipe_prim(type);
2827 info->count = prim_count_to_vertex_count(type, count);
2828 info->start_instance = 0;
2829 info->instance_count = 1;
2830 if (dev->state.stream_instancedata_mask & dev->state.stream_usage_mask)
2831 info->instance_count = MAX2(dev->state.stream_freq[0] & 0x7FFFFF, 1);
2832 info->primitive_restart = FALSE;
2833 info->restart_index = 0;
2834 info->count_from_stream_output = NULL;
2835 info->indirect = NULL;
2836 }
2837
2838 HRESULT WINAPI
2839 NineDevice9_DrawPrimitive( struct NineDevice9 *This,
2840 D3DPRIMITIVETYPE PrimitiveType,
2841 UINT StartVertex,
2842 UINT PrimitiveCount )
2843 {
2844 struct pipe_draw_info info;
2845
2846 DBG("iface %p, PrimitiveType %u, StartVertex %u, PrimitiveCount %u\n",
2847 This, PrimitiveType, StartVertex, PrimitiveCount);
2848
2849 nine_update_state(This, ~0);
2850
2851 init_draw_info(&info, This, PrimitiveType, PrimitiveCount);
2852 info.indexed = FALSE;
2853 info.start = StartVertex;
2854 info.index_bias = 0;
2855 info.min_index = info.start;
2856 info.max_index = info.count - 1;
2857
2858 This->pipe->draw_vbo(This->pipe, &info);
2859
2860 return D3D_OK;
2861 }
2862
2863 HRESULT WINAPI
2864 NineDevice9_DrawIndexedPrimitive( struct NineDevice9 *This,
2865 D3DPRIMITIVETYPE PrimitiveType,
2866 INT BaseVertexIndex,
2867 UINT MinVertexIndex,
2868 UINT NumVertices,
2869 UINT StartIndex,
2870 UINT PrimitiveCount )
2871 {
2872 struct pipe_draw_info info;
2873
2874 DBG("iface %p, PrimitiveType %u, BaseVertexIndex %u, MinVertexIndex %u "
2875 "NumVertices %u, StartIndex %u, PrimitiveCount %u\n",
2876 This, PrimitiveType, BaseVertexIndex, MinVertexIndex, NumVertices,
2877 StartIndex, PrimitiveCount);
2878
2879 user_assert(This->state.idxbuf, D3DERR_INVALIDCALL);
2880 user_assert(This->state.vdecl, D3DERR_INVALIDCALL);
2881
2882 nine_update_state(This, ~0);
2883
2884 init_draw_info(&info, This, PrimitiveType, PrimitiveCount);
2885 info.indexed = TRUE;
2886 info.start = StartIndex;
2887 info.index_bias = BaseVertexIndex;
2888 /* These don't include index bias: */
2889 info.min_index = MinVertexIndex;
2890 info.max_index = MinVertexIndex + NumVertices - 1;
2891
2892 This->pipe->draw_vbo(This->pipe, &info);
2893
2894 return D3D_OK;
2895 }
2896
2897 HRESULT WINAPI
2898 NineDevice9_DrawPrimitiveUP( struct NineDevice9 *This,
2899 D3DPRIMITIVETYPE PrimitiveType,
2900 UINT PrimitiveCount,
2901 const void *pVertexStreamZeroData,
2902 UINT VertexStreamZeroStride )
2903 {
2904 struct pipe_vertex_buffer vtxbuf;
2905 struct pipe_draw_info info;
2906
2907 DBG("iface %p, PrimitiveType %u, PrimitiveCount %u, data %p, stride %u\n",
2908 This, PrimitiveType, PrimitiveCount,
2909 pVertexStreamZeroData, VertexStreamZeroStride);
2910
2911 user_assert(pVertexStreamZeroData && VertexStreamZeroStride,
2912 D3DERR_INVALIDCALL);
2913
2914 nine_update_state(This, ~0);
2915
2916 init_draw_info(&info, This, PrimitiveType, PrimitiveCount);
2917 info.indexed = FALSE;
2918 info.start = 0;
2919 info.index_bias = 0;
2920 info.min_index = 0;
2921 info.max_index = info.count - 1;
2922
2923 vtxbuf.stride = VertexStreamZeroStride;
2924 vtxbuf.buffer_offset = 0;
2925 vtxbuf.buffer = NULL;
2926 vtxbuf.user_buffer = pVertexStreamZeroData;
2927
2928 if (!This->driver_caps.user_vbufs)
2929 u_upload_data(This->upload,
2930 0,
2931 (info.max_index + 1) * VertexStreamZeroStride, /* XXX */
2932 vtxbuf.user_buffer,
2933 &vtxbuf.buffer_offset,
2934 &vtxbuf.buffer);
2935
2936 This->pipe->set_vertex_buffers(This->pipe, 0, 1, &vtxbuf);
2937
2938 This->pipe->draw_vbo(This->pipe, &info);
2939
2940 NineDevice9_PauseRecording(This);
2941 NineDevice9_SetStreamSource(This, 0, NULL, 0, 0);
2942 NineDevice9_ResumeRecording(This);
2943
2944 pipe_resource_reference(&vtxbuf.buffer, NULL);
2945
2946 return D3D_OK;
2947 }
2948
2949 HRESULT WINAPI
2950 NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9 *This,
2951 D3DPRIMITIVETYPE PrimitiveType,
2952 UINT MinVertexIndex,
2953 UINT NumVertices,
2954 UINT PrimitiveCount,
2955 const void *pIndexData,
2956 D3DFORMAT IndexDataFormat,
2957 const void *pVertexStreamZeroData,
2958 UINT VertexStreamZeroStride )
2959 {
2960 struct pipe_draw_info info;
2961 struct pipe_vertex_buffer vbuf;
2962 struct pipe_index_buffer ibuf;
2963
2964 DBG("iface %p, PrimitiveType %u, MinVertexIndex %u, NumVertices %u "
2965 "PrimitiveCount %u, pIndexData %p, IndexDataFormat %u "
2966 "pVertexStreamZeroData %p, VertexStreamZeroStride %u\n",
2967 This, PrimitiveType, MinVertexIndex, NumVertices, PrimitiveCount,
2968 pIndexData, IndexDataFormat,
2969 pVertexStreamZeroData, VertexStreamZeroStride);
2970
2971 user_assert(pIndexData && pVertexStreamZeroData, D3DERR_INVALIDCALL);
2972 user_assert(VertexStreamZeroStride, D3DERR_INVALIDCALL);
2973 user_assert(IndexDataFormat == D3DFMT_INDEX16 ||
2974 IndexDataFormat == D3DFMT_INDEX32, D3DERR_INVALIDCALL);
2975
2976 nine_update_state(This, ~0);
2977
2978 init_draw_info(&info, This, PrimitiveType, PrimitiveCount);
2979 info.indexed = TRUE;
2980 info.start = 0;
2981 info.index_bias = 0;
2982 info.min_index = MinVertexIndex;
2983 info.max_index = MinVertexIndex + NumVertices - 1;
2984
2985 vbuf.stride = VertexStreamZeroStride;
2986 vbuf.buffer_offset = 0;
2987 vbuf.buffer = NULL;
2988 vbuf.user_buffer = pVertexStreamZeroData;
2989
2990 ibuf.index_size = (IndexDataFormat == D3DFMT_INDEX16) ? 2 : 4;
2991 ibuf.offset = 0;
2992 ibuf.buffer = NULL;
2993 ibuf.user_buffer = pIndexData;
2994
2995 if (!This->driver_caps.user_vbufs) {
2996 const unsigned base = info.min_index * VertexStreamZeroStride;
2997 u_upload_data(This->upload,
2998 base,
2999 (info.max_index -
3000 info.min_index + 1) * VertexStreamZeroStride, /* XXX */
3001 (const uint8_t *)vbuf.user_buffer + base,
3002 &vbuf.buffer_offset,
3003 &vbuf.buffer);
3004 /* Won't be used: */
3005 vbuf.buffer_offset -= base;
3006 }
3007 if (!This->driver_caps.user_ibufs)
3008 u_upload_data(This->upload,
3009 0,
3010 info.count * ibuf.index_size,
3011 ibuf.user_buffer,
3012 &ibuf.offset,
3013 &ibuf.buffer);
3014
3015 This->pipe->set_vertex_buffers(This->pipe, 0, 1, &vbuf);
3016 This->pipe->set_index_buffer(This->pipe, &ibuf);
3017
3018 This->pipe->draw_vbo(This->pipe, &info);
3019
3020 pipe_resource_reference(&vbuf.buffer, NULL);
3021 pipe_resource_reference(&ibuf.buffer, NULL);
3022
3023 NineDevice9_PauseRecording(This);
3024 NineDevice9_SetIndices(This, NULL);
3025 NineDevice9_SetStreamSource(This, 0, NULL, 0, 0);
3026 NineDevice9_ResumeRecording(This);
3027
3028 return D3D_OK;
3029 }
3030
3031 /* TODO: Write to pDestBuffer directly if vertex declaration contains
3032 * only f32 formats.
3033 */
3034 HRESULT WINAPI
3035 NineDevice9_ProcessVertices( struct NineDevice9 *This,
3036 UINT SrcStartIndex,
3037 UINT DestIndex,
3038 UINT VertexCount,
3039 IDirect3DVertexBuffer9 *pDestBuffer,
3040 IDirect3DVertexDeclaration9 *pVertexDecl,
3041 DWORD Flags )
3042 {
3043 struct pipe_screen *screen = This->screen;
3044 struct NineVertexDeclaration9 *vdecl = NineVertexDeclaration9(pVertexDecl);
3045 struct NineVertexShader9 *vs;
3046 struct pipe_resource *resource;
3047 struct pipe_stream_output_target *target;
3048 struct pipe_draw_info draw;
3049 HRESULT hr;
3050 unsigned buffer_offset, buffer_size;
3051
3052 DBG("This=%p SrcStartIndex=%u DestIndex=%u VertexCount=%u "
3053 "pDestBuffer=%p pVertexDecl=%p Flags=%d\n",
3054 This, SrcStartIndex, DestIndex, VertexCount, pDestBuffer,
3055 pVertexDecl, Flags);
3056
3057 if (!screen->get_param(screen, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS))
3058 STUB(D3DERR_INVALIDCALL);
3059
3060 nine_update_state(This, ~0);
3061
3062 /* TODO: Create shader with stream output. */
3063 STUB(D3DERR_INVALIDCALL);
3064 struct NineVertexBuffer9 *dst = NineVertexBuffer9(pDestBuffer);
3065
3066 vs = This->state.vs ? This->state.vs : This->ff.vs;
3067
3068 buffer_size = VertexCount * vs->so->stride[0];
3069 if (1) {
3070 struct pipe_resource templ;
3071
3072 templ.target = PIPE_BUFFER;
3073 templ.format = PIPE_FORMAT_R8_UNORM;
3074 templ.width0 = buffer_size;
3075 templ.flags = 0;
3076 templ.bind = PIPE_BIND_STREAM_OUTPUT;
3077 templ.usage = PIPE_USAGE_STREAM;
3078 templ.height0 = templ.depth0 = templ.array_size = 1;
3079 templ.last_level = templ.nr_samples = 0;
3080
3081 resource = This->screen->resource_create(This->screen, &templ);
3082 if (!resource)
3083 return E_OUTOFMEMORY;
3084 buffer_offset = 0;
3085 } else {
3086 /* SO matches vertex declaration */
3087 resource = dst->base.resource;
3088 buffer_offset = DestIndex * vs->so->stride[0];
3089 }
3090 target = This->pipe->create_stream_output_target(This->pipe, resource,
3091 buffer_offset,
3092 buffer_size);
3093 if (!target) {
3094 pipe_resource_reference(&resource, NULL);
3095 return D3DERR_DRIVERINTERNALERROR;
3096 }
3097
3098 if (!vdecl) {
3099 hr = NineVertexDeclaration9_new_from_fvf(This, dst->desc.FVF, &vdecl);
3100 if (FAILED(hr))
3101 goto out;
3102 }
3103
3104 init_draw_info(&draw, This, D3DPT_POINTLIST, VertexCount);
3105 draw.instance_count = 1;
3106 draw.indexed = FALSE;
3107 draw.start = SrcStartIndex;
3108 draw.index_bias = 0;
3109 draw.min_index = SrcStartIndex;
3110 draw.max_index = SrcStartIndex + VertexCount - 1;
3111
3112 This->pipe->set_stream_output_targets(This->pipe, 1, &target, 0);
3113 This->pipe->draw_vbo(This->pipe, &draw);
3114 This->pipe->set_stream_output_targets(This->pipe, 0, NULL, 0);
3115 This->pipe->stream_output_target_destroy(This->pipe, target);
3116
3117 hr = NineVertexDeclaration9_ConvertStreamOutput(vdecl,
3118 dst, DestIndex, VertexCount,
3119 resource, vs->so);
3120 out:
3121 pipe_resource_reference(&resource, NULL);
3122 if (!pVertexDecl)
3123 NineUnknown_Release(NineUnknown(vdecl));
3124 return hr;
3125 }
3126
3127 HRESULT WINAPI
3128 NineDevice9_CreateVertexDeclaration( struct NineDevice9 *This,
3129 const D3DVERTEXELEMENT9 *pVertexElements,
3130 IDirect3DVertexDeclaration9 **ppDecl )
3131 {
3132 struct NineVertexDeclaration9 *vdecl;
3133
3134 DBG("This=%p pVertexElements=%p ppDecl=%p\n",
3135 This, pVertexElements, ppDecl);
3136
3137 HRESULT hr = NineVertexDeclaration9_new(This, pVertexElements, &vdecl);
3138 if (SUCCEEDED(hr))
3139 *ppDecl = (IDirect3DVertexDeclaration9 *)vdecl;
3140
3141 return hr;
3142 }
3143
3144 HRESULT WINAPI
3145 NineDevice9_SetVertexDeclaration( struct NineDevice9 *This,
3146 IDirect3DVertexDeclaration9 *pDecl )
3147 {
3148 struct nine_state *state = This->update;
3149
3150 DBG("This=%p pDecl=%p\n", This, pDecl);
3151
3152 if (likely(!This->is_recording) && state->vdecl == NineVertexDeclaration9(pDecl))
3153 return D3D_OK;
3154 nine_bind(&state->vdecl, pDecl);
3155
3156 state->changed.group |= NINE_STATE_VDECL;
3157
3158 return D3D_OK;
3159 }
3160
3161 HRESULT WINAPI
3162 NineDevice9_GetVertexDeclaration( struct NineDevice9 *This,
3163 IDirect3DVertexDeclaration9 **ppDecl )
3164 {
3165 user_assert(ppDecl, D3DERR_INVALIDCALL);
3166
3167 *ppDecl = (IDirect3DVertexDeclaration9 *)This->state.vdecl;
3168 if (*ppDecl)
3169 NineUnknown_AddRef(NineUnknown(*ppDecl));
3170 return D3D_OK;
3171 }
3172
3173 HRESULT WINAPI
3174 NineDevice9_SetFVF( struct NineDevice9 *This,
3175 DWORD FVF )
3176 {
3177 struct NineVertexDeclaration9 *vdecl;
3178 HRESULT hr;
3179
3180 DBG("FVF = %08x\n", FVF);
3181 if (!FVF)
3182 return D3D_OK; /* like wine */
3183
3184 vdecl = util_hash_table_get(This->ff.ht_fvf, &FVF);
3185 if (!vdecl) {
3186 hr = NineVertexDeclaration9_new_from_fvf(This, FVF, &vdecl);
3187 if (FAILED(hr))
3188 return hr;
3189 vdecl->fvf = FVF;
3190 util_hash_table_set(This->ff.ht_fvf, &vdecl->fvf, vdecl);
3191 NineUnknown_ConvertRefToBind(NineUnknown(vdecl));
3192 }
3193 return NineDevice9_SetVertexDeclaration(
3194 This, (IDirect3DVertexDeclaration9 *)vdecl);
3195 }
3196
3197 HRESULT WINAPI
3198 NineDevice9_GetFVF( struct NineDevice9 *This,
3199 DWORD *pFVF )
3200 {
3201 *pFVF = This->state.vdecl ? This->state.vdecl->fvf : 0;
3202 return D3D_OK;
3203 }
3204
3205 HRESULT WINAPI
3206 NineDevice9_CreateVertexShader( struct NineDevice9 *This,
3207 const DWORD *pFunction,
3208 IDirect3DVertexShader9 **ppShader )
3209 {
3210 struct NineVertexShader9 *vs;
3211 HRESULT hr;
3212
3213 DBG("This=%p pFunction=%p ppShader=%p\n", This, pFunction, ppShader);
3214
3215 hr = NineVertexShader9_new(This, &vs, pFunction, NULL);
3216 if (FAILED(hr))
3217 return hr;
3218 *ppShader = (IDirect3DVertexShader9 *)vs;
3219 return D3D_OK;
3220 }
3221
3222 HRESULT WINAPI
3223 NineDevice9_SetVertexShader( struct NineDevice9 *This,
3224 IDirect3DVertexShader9 *pShader )
3225 {
3226 struct nine_state *state = This->update;
3227
3228 DBG("This=%p pShader=%p\n", This, pShader);
3229
3230 nine_bind(&state->vs, pShader);
3231
3232 state->changed.group |= NINE_STATE_VS;
3233
3234 return D3D_OK;
3235 }
3236
3237 HRESULT WINAPI
3238 NineDevice9_GetVertexShader( struct NineDevice9 *This,
3239 IDirect3DVertexShader9 **ppShader )
3240 {
3241 user_assert(ppShader, D3DERR_INVALIDCALL);
3242 nine_reference_set(ppShader, This->state.vs);
3243 return D3D_OK;
3244 }
3245
3246 HRESULT WINAPI
3247 NineDevice9_SetVertexShaderConstantF( struct NineDevice9 *This,
3248 UINT StartRegister,
3249 const float *pConstantData,
3250 UINT Vector4fCount )
3251 {
3252 struct nine_state *state = This->update;
3253
3254 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3255 This, StartRegister, pConstantData, Vector4fCount);
3256
3257 user_assert(StartRegister < This->caps.MaxVertexShaderConst, D3DERR_INVALIDCALL);
3258 user_assert(StartRegister + Vector4fCount <= This->caps.MaxVertexShaderConst, D3DERR_INVALIDCALL);
3259
3260 if (!Vector4fCount)
3261 return D3D_OK;
3262 user_assert(pConstantData, D3DERR_INVALIDCALL);
3263
3264 memcpy(&state->vs_const_f[StartRegister * 4],
3265 pConstantData,
3266 Vector4fCount * 4 * sizeof(state->vs_const_f[0]));
3267
3268 nine_ranges_insert(&state->changed.vs_const_f,
3269 StartRegister, StartRegister + Vector4fCount,
3270 &This->range_pool);
3271
3272 state->changed.group |= NINE_STATE_VS_CONST;
3273
3274 return D3D_OK;
3275 }
3276
3277 HRESULT WINAPI
3278 NineDevice9_GetVertexShaderConstantF( struct NineDevice9 *This,
3279 UINT StartRegister,
3280 float *pConstantData,
3281 UINT Vector4fCount )
3282 {
3283 const struct nine_state *state = &This->state;
3284
3285 user_assert(StartRegister < This->caps.MaxVertexShaderConst, D3DERR_INVALIDCALL);
3286 user_assert(StartRegister + Vector4fCount <= This->caps.MaxVertexShaderConst, D3DERR_INVALIDCALL);
3287 user_assert(pConstantData, D3DERR_INVALIDCALL);
3288
3289 memcpy(pConstantData,
3290 &state->vs_const_f[StartRegister * 4],
3291 Vector4fCount * 4 * sizeof(state->vs_const_f[0]));
3292
3293 return D3D_OK;
3294 }
3295
3296 HRESULT WINAPI
3297 NineDevice9_SetVertexShaderConstantI( struct NineDevice9 *This,
3298 UINT StartRegister,
3299 const int *pConstantData,
3300 UINT Vector4iCount )
3301 {
3302 struct nine_state *state = This->update;
3303 int i;
3304
3305 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3306 This, StartRegister, pConstantData, Vector4iCount);
3307
3308 user_assert(StartRegister < NINE_MAX_CONST_I, D3DERR_INVALIDCALL);
3309 user_assert(StartRegister + Vector4iCount <= NINE_MAX_CONST_I, D3DERR_INVALIDCALL);
3310 user_assert(pConstantData, D3DERR_INVALIDCALL);
3311
3312 if (This->driver_caps.vs_integer) {
3313 memcpy(&state->vs_const_i[StartRegister][0],
3314 pConstantData,
3315 Vector4iCount * sizeof(state->vs_const_i[0]));
3316 } else {
3317 for (i = 0; i < Vector4iCount; i++) {
3318 state->vs_const_i[StartRegister+i][0] = fui((float)(pConstantData[4*i]));
3319 state->vs_const_i[StartRegister+i][1] = fui((float)(pConstantData[4*i+1]));
3320 state->vs_const_i[StartRegister+i][2] = fui((float)(pConstantData[4*i+2]));
3321 state->vs_const_i[StartRegister+i][3] = fui((float)(pConstantData[4*i+3]));
3322 }
3323 }
3324
3325 state->changed.vs_const_i |= ((1 << Vector4iCount) - 1) << StartRegister;
3326 state->changed.group |= NINE_STATE_VS_CONST;
3327
3328 return D3D_OK;
3329 }
3330
3331 HRESULT WINAPI
3332 NineDevice9_GetVertexShaderConstantI( struct NineDevice9 *This,
3333 UINT StartRegister,
3334 int *pConstantData,
3335 UINT Vector4iCount )
3336 {
3337 const struct nine_state *state = &This->state;
3338 int i;
3339
3340 user_assert(StartRegister < NINE_MAX_CONST_I, D3DERR_INVALIDCALL);
3341 user_assert(StartRegister + Vector4iCount <= NINE_MAX_CONST_I, D3DERR_INVALIDCALL);
3342 user_assert(pConstantData, D3DERR_INVALIDCALL);
3343
3344 if (This->driver_caps.vs_integer) {
3345 memcpy(pConstantData,
3346 &state->vs_const_i[StartRegister][0],
3347 Vector4iCount * sizeof(state->vs_const_i[0]));
3348 } else {
3349 for (i = 0; i < Vector4iCount; i++) {
3350 pConstantData[4*i] = (int32_t) uif(state->vs_const_i[StartRegister+i][0]);
3351 pConstantData[4*i+1] = (int32_t) uif(state->vs_const_i[StartRegister+i][1]);
3352 pConstantData[4*i+2] = (int32_t) uif(state->vs_const_i[StartRegister+i][2]);
3353 pConstantData[4*i+3] = (int32_t) uif(state->vs_const_i[StartRegister+i][3]);
3354 }
3355 }
3356
3357 return D3D_OK;
3358 }
3359
3360 HRESULT WINAPI
3361 NineDevice9_SetVertexShaderConstantB( struct NineDevice9 *This,
3362 UINT StartRegister,
3363 const BOOL *pConstantData,
3364 UINT BoolCount )
3365 {
3366 struct nine_state *state = This->update;
3367 int i;
3368 uint32_t bool_true = This->driver_caps.vs_integer ? 0xFFFFFFFF : fui(1.0f);
3369
3370 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3371 This, StartRegister, pConstantData, BoolCount);
3372
3373 user_assert(StartRegister < NINE_MAX_CONST_B, D3DERR_INVALIDCALL);
3374 user_assert(StartRegister + BoolCount <= NINE_MAX_CONST_B, D3DERR_INVALIDCALL);
3375 user_assert(pConstantData, D3DERR_INVALIDCALL);
3376
3377 for (i = 0; i < BoolCount; i++)
3378 state->vs_const_b[StartRegister + i] = pConstantData[i] ? bool_true : 0;
3379
3380 state->changed.vs_const_b |= ((1 << BoolCount) - 1) << StartRegister;
3381 state->changed.group |= NINE_STATE_VS_CONST;
3382
3383 return D3D_OK;
3384 }
3385
3386 HRESULT WINAPI
3387 NineDevice9_GetVertexShaderConstantB( struct NineDevice9 *This,
3388 UINT StartRegister,
3389 BOOL *pConstantData,
3390 UINT BoolCount )
3391 {
3392 const struct nine_state *state = &This->state;
3393 int i;
3394
3395 user_assert(StartRegister < NINE_MAX_CONST_B, D3DERR_INVALIDCALL);
3396 user_assert(StartRegister + BoolCount <= NINE_MAX_CONST_B, D3DERR_INVALIDCALL);
3397 user_assert(pConstantData, D3DERR_INVALIDCALL);
3398
3399 for (i = 0; i < BoolCount; i++)
3400 pConstantData[i] = state->vs_const_b[StartRegister + i] != 0 ? TRUE : FALSE;
3401
3402 return D3D_OK;
3403 }
3404
3405 HRESULT WINAPI
3406 NineDevice9_SetStreamSource( struct NineDevice9 *This,
3407 UINT StreamNumber,
3408 IDirect3DVertexBuffer9 *pStreamData,
3409 UINT OffsetInBytes,
3410 UINT Stride )
3411 {
3412 struct nine_state *state = This->update;
3413 struct NineVertexBuffer9 *pVBuf9 = NineVertexBuffer9(pStreamData);
3414 const unsigned i = StreamNumber;
3415
3416 DBG("This=%p StreamNumber=%u pStreamData=%p OffsetInBytes=%u Stride=%u\n",
3417 This, StreamNumber, pStreamData, OffsetInBytes, Stride);
3418
3419 user_assert(StreamNumber < This->caps.MaxStreams, D3DERR_INVALIDCALL);
3420 user_assert(Stride <= This->caps.MaxStreamStride, D3DERR_INVALIDCALL);
3421
3422 if (likely(!This->is_recording)) {
3423 if (state->stream[i] == NineVertexBuffer9(pStreamData) &&
3424 state->vtxbuf[i].stride == Stride &&
3425 state->vtxbuf[i].buffer_offset == OffsetInBytes)
3426 return D3D_OK;
3427 }
3428 nine_bind(&state->stream[i], pStreamData);
3429
3430 state->changed.vtxbuf |= 1 << StreamNumber;
3431
3432 if (pStreamData) {
3433 state->vtxbuf[i].stride = Stride;
3434 state->vtxbuf[i].buffer_offset = OffsetInBytes;
3435 }
3436 state->vtxbuf[i].buffer = pStreamData ? pVBuf9->base.resource : NULL;
3437
3438 return D3D_OK;
3439 }
3440
3441 HRESULT WINAPI
3442 NineDevice9_GetStreamSource( struct NineDevice9 *This,
3443 UINT StreamNumber,
3444 IDirect3DVertexBuffer9 **ppStreamData,
3445 UINT *pOffsetInBytes,
3446 UINT *pStride )
3447 {
3448 const struct nine_state *state = &This->state;
3449 const unsigned i = StreamNumber;
3450
3451 user_assert(StreamNumber < This->caps.MaxStreams, D3DERR_INVALIDCALL);
3452 user_assert(ppStreamData, D3DERR_INVALIDCALL);
3453
3454 nine_reference_set(ppStreamData, state->stream[i]);
3455 *pStride = state->vtxbuf[i].stride;
3456 *pOffsetInBytes = state->vtxbuf[i].buffer_offset;
3457
3458 return D3D_OK;
3459 }
3460
3461 HRESULT WINAPI
3462 NineDevice9_SetStreamSourceFreq( struct NineDevice9 *This,
3463 UINT StreamNumber,
3464 UINT Setting )
3465 {
3466 struct nine_state *state = This->update;
3467 /* const UINT freq = Setting & 0x7FFFFF; */
3468
3469 DBG("This=%p StreamNumber=%u FrequencyParameter=0x%x\n", This,
3470 StreamNumber, Setting);
3471
3472 user_assert(StreamNumber < This->caps.MaxStreams, D3DERR_INVALIDCALL);
3473 user_assert(StreamNumber != 0 || !(Setting & D3DSTREAMSOURCE_INSTANCEDATA),
3474 D3DERR_INVALIDCALL);
3475 user_assert(!((Setting & D3DSTREAMSOURCE_INSTANCEDATA) &&
3476 (Setting & D3DSTREAMSOURCE_INDEXEDDATA)), D3DERR_INVALIDCALL);
3477 user_assert(Setting, D3DERR_INVALIDCALL);
3478
3479 state->stream_freq[StreamNumber] = Setting;
3480
3481 if (Setting & D3DSTREAMSOURCE_INSTANCEDATA)
3482 state->stream_instancedata_mask |= 1 << StreamNumber;
3483 else
3484 state->stream_instancedata_mask &= ~(1 << StreamNumber);
3485
3486 state->changed.stream_freq |= 1 << StreamNumber;
3487 return D3D_OK;
3488 }
3489
3490 HRESULT WINAPI
3491 NineDevice9_GetStreamSourceFreq( struct NineDevice9 *This,
3492 UINT StreamNumber,
3493 UINT *pSetting )
3494 {
3495 user_assert(StreamNumber < This->caps.MaxStreams, D3DERR_INVALIDCALL);
3496 *pSetting = This->state.stream_freq[StreamNumber];
3497 return D3D_OK;
3498 }
3499
3500 HRESULT WINAPI
3501 NineDevice9_SetIndices( struct NineDevice9 *This,
3502 IDirect3DIndexBuffer9 *pIndexData )
3503 {
3504 struct nine_state *state = This->update;
3505
3506 DBG("This=%p pIndexData=%p\n", This, pIndexData);
3507
3508 if (likely(!This->is_recording))
3509 if (state->idxbuf == NineIndexBuffer9(pIndexData))
3510 return D3D_OK;
3511 nine_bind(&state->idxbuf, pIndexData);
3512
3513 state->changed.group |= NINE_STATE_IDXBUF;
3514
3515 return D3D_OK;
3516 }
3517
3518 /* XXX: wine/d3d9 doesn't have pBaseVertexIndex, and it doesn't make sense
3519 * here because it's an argument passed to the Draw calls.
3520 */
3521 HRESULT WINAPI
3522 NineDevice9_GetIndices( struct NineDevice9 *This,
3523 IDirect3DIndexBuffer9 **ppIndexData /*,
3524 UINT *pBaseVertexIndex */ )
3525 {
3526 user_assert(ppIndexData, D3DERR_INVALIDCALL);
3527 nine_reference_set(ppIndexData, This->state.idxbuf);
3528 return D3D_OK;
3529 }
3530
3531 HRESULT WINAPI
3532 NineDevice9_CreatePixelShader( struct NineDevice9 *This,
3533 const DWORD *pFunction,
3534 IDirect3DPixelShader9 **ppShader )
3535 {
3536 struct NinePixelShader9 *ps;
3537 HRESULT hr;
3538
3539 DBG("This=%p pFunction=%p ppShader=%p\n", This, pFunction, ppShader);
3540
3541 hr = NinePixelShader9_new(This, &ps, pFunction, NULL);
3542 if (FAILED(hr))
3543 return hr;
3544 *ppShader = (IDirect3DPixelShader9 *)ps;
3545 return D3D_OK;
3546 }
3547
3548 HRESULT WINAPI
3549 NineDevice9_SetPixelShader( struct NineDevice9 *This,
3550 IDirect3DPixelShader9 *pShader )
3551 {
3552 struct nine_state *state = This->update;
3553 unsigned old_mask = state->ps ? state->ps->rt_mask : 1;
3554 unsigned mask;
3555
3556 DBG("This=%p pShader=%p\n", This, pShader);
3557
3558 nine_bind(&state->ps, pShader);
3559
3560 state->changed.group |= NINE_STATE_PS;
3561
3562 mask = state->ps ? state->ps->rt_mask : 1;
3563 /* We need to update cbufs if the pixel shader would
3564 * write to different render targets */
3565 if (mask != old_mask)
3566 state->changed.group |= NINE_STATE_FB;
3567
3568 return D3D_OK;
3569 }
3570
3571 HRESULT WINAPI
3572 NineDevice9_GetPixelShader( struct NineDevice9 *This,
3573 IDirect3DPixelShader9 **ppShader )
3574 {
3575 user_assert(ppShader, D3DERR_INVALIDCALL);
3576 nine_reference_set(ppShader, This->state.ps);
3577 return D3D_OK;
3578 }
3579
3580 HRESULT WINAPI
3581 NineDevice9_SetPixelShaderConstantF( struct NineDevice9 *This,
3582 UINT StartRegister,
3583 const float *pConstantData,
3584 UINT Vector4fCount )
3585 {
3586 struct nine_state *state = This->update;
3587
3588 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3589 This, StartRegister, pConstantData, Vector4fCount);
3590
3591 user_assert(StartRegister < NINE_MAX_CONST_F_PS3, D3DERR_INVALIDCALL);
3592 user_assert(StartRegister + Vector4fCount <= NINE_MAX_CONST_F_PS3, D3DERR_INVALIDCALL);
3593
3594 if (!Vector4fCount)
3595 return D3D_OK;
3596 user_assert(pConstantData, D3DERR_INVALIDCALL);
3597
3598 memcpy(&state->ps_const_f[StartRegister * 4],
3599 pConstantData,
3600 Vector4fCount * 4 * sizeof(state->ps_const_f[0]));
3601
3602 nine_ranges_insert(&state->changed.ps_const_f,
3603 StartRegister, StartRegister + Vector4fCount,
3604 &This->range_pool);
3605
3606 state->changed.group |= NINE_STATE_PS_CONST;
3607
3608 return D3D_OK;
3609 }
3610
3611 HRESULT WINAPI
3612 NineDevice9_GetPixelShaderConstantF( struct NineDevice9 *This,
3613 UINT StartRegister,
3614 float *pConstantData,
3615 UINT Vector4fCount )
3616 {
3617 const struct nine_state *state = &This->state;
3618
3619 user_assert(StartRegister < NINE_MAX_CONST_F_PS3, D3DERR_INVALIDCALL);
3620 user_assert(StartRegister + Vector4fCount <= NINE_MAX_CONST_F_PS3, D3DERR_INVALIDCALL);
3621 user_assert(pConstantData, D3DERR_INVALIDCALL);
3622
3623 memcpy(pConstantData,
3624 &state->ps_const_f[StartRegister * 4],
3625 Vector4fCount * 4 * sizeof(state->ps_const_f[0]));
3626
3627 return D3D_OK;
3628 }
3629
3630 HRESULT WINAPI
3631 NineDevice9_SetPixelShaderConstantI( struct NineDevice9 *This,
3632 UINT StartRegister,
3633 const int *pConstantData,
3634 UINT Vector4iCount )
3635 {
3636 struct nine_state *state = This->update;
3637 int i;
3638
3639 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3640 This, StartRegister, pConstantData, Vector4iCount);
3641
3642 user_assert(StartRegister < NINE_MAX_CONST_I, D3DERR_INVALIDCALL);
3643 user_assert(StartRegister + Vector4iCount <= NINE_MAX_CONST_I, D3DERR_INVALIDCALL);
3644 user_assert(pConstantData, D3DERR_INVALIDCALL);
3645
3646 if (This->driver_caps.ps_integer) {
3647 memcpy(&state->ps_const_i[StartRegister][0],
3648 pConstantData,
3649 Vector4iCount * sizeof(state->ps_const_i[0]));
3650 } else {
3651 for (i = 0; i < Vector4iCount; i++) {
3652 state->ps_const_i[StartRegister+i][0] = fui((float)(pConstantData[4*i]));
3653 state->ps_const_i[StartRegister+i][1] = fui((float)(pConstantData[4*i+1]));
3654 state->ps_const_i[StartRegister+i][2] = fui((float)(pConstantData[4*i+2]));
3655 state->ps_const_i[StartRegister+i][3] = fui((float)(pConstantData[4*i+3]));
3656 }
3657 }
3658 state->changed.ps_const_i |= ((1 << Vector4iCount) - 1) << StartRegister;
3659 state->changed.group |= NINE_STATE_PS_CONST;
3660
3661 return D3D_OK;
3662 }
3663
3664 HRESULT WINAPI
3665 NineDevice9_GetPixelShaderConstantI( struct NineDevice9 *This,
3666 UINT StartRegister,
3667 int *pConstantData,
3668 UINT Vector4iCount )
3669 {
3670 const struct nine_state *state = &This->state;
3671 int i;
3672
3673 user_assert(StartRegister < NINE_MAX_CONST_I, D3DERR_INVALIDCALL);
3674 user_assert(StartRegister + Vector4iCount <= NINE_MAX_CONST_I, D3DERR_INVALIDCALL);
3675 user_assert(pConstantData, D3DERR_INVALIDCALL);
3676
3677 if (This->driver_caps.ps_integer) {
3678 memcpy(pConstantData,
3679 &state->ps_const_i[StartRegister][0],
3680 Vector4iCount * sizeof(state->ps_const_i[0]));
3681 } else {
3682 for (i = 0; i < Vector4iCount; i++) {
3683 pConstantData[4*i] = (int32_t) uif(state->ps_const_i[StartRegister+i][0]);
3684 pConstantData[4*i+1] = (int32_t) uif(state->ps_const_i[StartRegister+i][1]);
3685 pConstantData[4*i+2] = (int32_t) uif(state->ps_const_i[StartRegister+i][2]);
3686 pConstantData[4*i+3] = (int32_t) uif(state->ps_const_i[StartRegister+i][3]);
3687 }
3688 }
3689
3690 return D3D_OK;
3691 }
3692
3693 HRESULT WINAPI
3694 NineDevice9_SetPixelShaderConstantB( struct NineDevice9 *This,
3695 UINT StartRegister,
3696 const BOOL *pConstantData,
3697 UINT BoolCount )
3698 {
3699 struct nine_state *state = This->update;
3700 int i;
3701 uint32_t bool_true = This->driver_caps.ps_integer ? 0xFFFFFFFF : fui(1.0f);
3702
3703 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3704 This, StartRegister, pConstantData, BoolCount);
3705
3706 user_assert(StartRegister < NINE_MAX_CONST_B, D3DERR_INVALIDCALL);
3707 user_assert(StartRegister + BoolCount <= NINE_MAX_CONST_B, D3DERR_INVALIDCALL);
3708 user_assert(pConstantData, D3DERR_INVALIDCALL);
3709
3710 for (i = 0; i < BoolCount; i++)
3711 state->ps_const_b[StartRegister + i] = pConstantData[i] ? bool_true : 0;
3712
3713 state->changed.ps_const_b |= ((1 << BoolCount) - 1) << StartRegister;
3714 state->changed.group |= NINE_STATE_PS_CONST;
3715
3716 return D3D_OK;
3717 }
3718
3719 HRESULT WINAPI
3720 NineDevice9_GetPixelShaderConstantB( struct NineDevice9 *This,
3721 UINT StartRegister,
3722 BOOL *pConstantData,
3723 UINT BoolCount )
3724 {
3725 const struct nine_state *state = &This->state;
3726 int i;
3727
3728 user_assert(StartRegister < NINE_MAX_CONST_B, D3DERR_INVALIDCALL);
3729 user_assert(StartRegister + BoolCount <= NINE_MAX_CONST_B, D3DERR_INVALIDCALL);
3730 user_assert(pConstantData, D3DERR_INVALIDCALL);
3731
3732 for (i = 0; i < BoolCount; i++)
3733 pConstantData[i] = state->ps_const_b[StartRegister + i] ? TRUE : FALSE;
3734
3735 return D3D_OK;
3736 }
3737
3738 HRESULT WINAPI
3739 NineDevice9_DrawRectPatch( struct NineDevice9 *This,
3740 UINT Handle,
3741 const float *pNumSegs,
3742 const D3DRECTPATCH_INFO *pRectPatchInfo )
3743 {
3744 STUB(D3DERR_INVALIDCALL);
3745 }
3746
3747 HRESULT WINAPI
3748 NineDevice9_DrawTriPatch( struct NineDevice9 *This,
3749 UINT Handle,
3750 const float *pNumSegs,
3751 const D3DTRIPATCH_INFO *pTriPatchInfo )
3752 {
3753 STUB(D3DERR_INVALIDCALL);
3754 }
3755
3756 HRESULT WINAPI
3757 NineDevice9_DeletePatch( struct NineDevice9 *This,
3758 UINT Handle )
3759 {
3760 STUB(D3DERR_INVALIDCALL);
3761 }
3762
3763 HRESULT WINAPI
3764 NineDevice9_CreateQuery( struct NineDevice9 *This,
3765 D3DQUERYTYPE Type,
3766 IDirect3DQuery9 **ppQuery )
3767 {
3768 struct NineQuery9 *query;
3769 HRESULT hr;
3770
3771 DBG("This=%p Type=%d ppQuery=%p\n", This, Type, ppQuery);
3772
3773 hr = nine_is_query_supported(This->screen, Type);
3774 if (!ppQuery || hr != D3D_OK)
3775 return hr;
3776
3777 hr = NineQuery9_new(This, &query, Type);
3778 if (FAILED(hr))
3779 return hr;
3780 *ppQuery = (IDirect3DQuery9 *)query;
3781 return D3D_OK;
3782 }
3783
3784 IDirect3DDevice9Vtbl NineDevice9_vtable = {
3785 (void *)NineUnknown_QueryInterface,
3786 (void *)NineUnknown_AddRef,
3787 (void *)NineUnknown_Release,
3788 (void *)NineDevice9_TestCooperativeLevel,
3789 (void *)NineDevice9_GetAvailableTextureMem,
3790 (void *)NineDevice9_EvictManagedResources,
3791 (void *)NineDevice9_GetDirect3D,
3792 (void *)NineDevice9_GetDeviceCaps,
3793 (void *)NineDevice9_GetDisplayMode,
3794 (void *)NineDevice9_GetCreationParameters,
3795 (void *)NineDevice9_SetCursorProperties,
3796 (void *)NineDevice9_SetCursorPosition,
3797 (void *)NineDevice9_ShowCursor,
3798 (void *)NineDevice9_CreateAdditionalSwapChain,
3799 (void *)NineDevice9_GetSwapChain,
3800 (void *)NineDevice9_GetNumberOfSwapChains,
3801 (void *)NineDevice9_Reset,
3802 (void *)NineDevice9_Present,
3803 (void *)NineDevice9_GetBackBuffer,
3804 (void *)NineDevice9_GetRasterStatus,
3805 (void *)NineDevice9_SetDialogBoxMode,
3806 (void *)NineDevice9_SetGammaRamp,
3807 (void *)NineDevice9_GetGammaRamp,
3808 (void *)NineDevice9_CreateTexture,
3809 (void *)NineDevice9_CreateVolumeTexture,
3810 (void *)NineDevice9_CreateCubeTexture,
3811 (void *)NineDevice9_CreateVertexBuffer,
3812 (void *)NineDevice9_CreateIndexBuffer,
3813 (void *)NineDevice9_CreateRenderTarget,
3814 (void *)NineDevice9_CreateDepthStencilSurface,
3815 (void *)NineDevice9_UpdateSurface,
3816 (void *)NineDevice9_UpdateTexture,
3817 (void *)NineDevice9_GetRenderTargetData,
3818 (void *)NineDevice9_GetFrontBufferData,
3819 (void *)NineDevice9_StretchRect,
3820 (void *)NineDevice9_ColorFill,
3821 (void *)NineDevice9_CreateOffscreenPlainSurface,
3822 (void *)NineDevice9_SetRenderTarget,
3823 (void *)NineDevice9_GetRenderTarget,
3824 (void *)NineDevice9_SetDepthStencilSurface,
3825 (void *)NineDevice9_GetDepthStencilSurface,
3826 (void *)NineDevice9_BeginScene,
3827 (void *)NineDevice9_EndScene,
3828 (void *)NineDevice9_Clear,
3829 (void *)NineDevice9_SetTransform,
3830 (void *)NineDevice9_GetTransform,
3831 (void *)NineDevice9_MultiplyTransform,
3832 (void *)NineDevice9_SetViewport,
3833 (void *)NineDevice9_GetViewport,
3834 (void *)NineDevice9_SetMaterial,
3835 (void *)NineDevice9_GetMaterial,
3836 (void *)NineDevice9_SetLight,
3837 (void *)NineDevice9_GetLight,
3838 (void *)NineDevice9_LightEnable,
3839 (void *)NineDevice9_GetLightEnable,
3840 (void *)NineDevice9_SetClipPlane,
3841 (void *)NineDevice9_GetClipPlane,
3842 (void *)NineDevice9_SetRenderState,
3843 (void *)NineDevice9_GetRenderState,
3844 (void *)NineDevice9_CreateStateBlock,
3845 (void *)NineDevice9_BeginStateBlock,
3846 (void *)NineDevice9_EndStateBlock,
3847 (void *)NineDevice9_SetClipStatus,
3848 (void *)NineDevice9_GetClipStatus,
3849 (void *)NineDevice9_GetTexture,
3850 (void *)NineDevice9_SetTexture,
3851 (void *)NineDevice9_GetTextureStageState,
3852 (void *)NineDevice9_SetTextureStageState,
3853 (void *)NineDevice9_GetSamplerState,
3854 (void *)NineDevice9_SetSamplerState,
3855 (void *)NineDevice9_ValidateDevice,
3856 (void *)NineDevice9_SetPaletteEntries,
3857 (void *)NineDevice9_GetPaletteEntries,
3858 (void *)NineDevice9_SetCurrentTexturePalette,
3859 (void *)NineDevice9_GetCurrentTexturePalette,
3860 (void *)NineDevice9_SetScissorRect,
3861 (void *)NineDevice9_GetScissorRect,
3862 (void *)NineDevice9_SetSoftwareVertexProcessing,
3863 (void *)NineDevice9_GetSoftwareVertexProcessing,
3864 (void *)NineDevice9_SetNPatchMode,
3865 (void *)NineDevice9_GetNPatchMode,
3866 (void *)NineDevice9_DrawPrimitive,
3867 (void *)NineDevice9_DrawIndexedPrimitive,
3868 (void *)NineDevice9_DrawPrimitiveUP,
3869 (void *)NineDevice9_DrawIndexedPrimitiveUP,
3870 (void *)NineDevice9_ProcessVertices,
3871 (void *)NineDevice9_CreateVertexDeclaration,
3872 (void *)NineDevice9_SetVertexDeclaration,
3873 (void *)NineDevice9_GetVertexDeclaration,
3874 (void *)NineDevice9_SetFVF,
3875 (void *)NineDevice9_GetFVF,
3876 (void *)NineDevice9_CreateVertexShader,
3877 (void *)NineDevice9_SetVertexShader,
3878 (void *)NineDevice9_GetVertexShader,
3879 (void *)NineDevice9_SetVertexShaderConstantF,
3880 (void *)NineDevice9_GetVertexShaderConstantF,
3881 (void *)NineDevice9_SetVertexShaderConstantI,
3882 (void *)NineDevice9_GetVertexShaderConstantI,
3883 (void *)NineDevice9_SetVertexShaderConstantB,
3884 (void *)NineDevice9_GetVertexShaderConstantB,
3885 (void *)NineDevice9_SetStreamSource,
3886 (void *)NineDevice9_GetStreamSource,
3887 (void *)NineDevice9_SetStreamSourceFreq,
3888 (void *)NineDevice9_GetStreamSourceFreq,
3889 (void *)NineDevice9_SetIndices,
3890 (void *)NineDevice9_GetIndices,
3891 (void *)NineDevice9_CreatePixelShader,
3892 (void *)NineDevice9_SetPixelShader,
3893 (void *)NineDevice9_GetPixelShader,
3894 (void *)NineDevice9_SetPixelShaderConstantF,
3895 (void *)NineDevice9_GetPixelShaderConstantF,
3896 (void *)NineDevice9_SetPixelShaderConstantI,
3897 (void *)NineDevice9_GetPixelShaderConstantI,
3898 (void *)NineDevice9_SetPixelShaderConstantB,
3899 (void *)NineDevice9_GetPixelShaderConstantB,
3900 (void *)NineDevice9_DrawRectPatch,
3901 (void *)NineDevice9_DrawTriPatch,
3902 (void *)NineDevice9_DeletePatch,
3903 (void *)NineDevice9_CreateQuery
3904 };
3905
3906 static const GUID *NineDevice9_IIDs[] = {
3907 &IID_IDirect3DDevice9,
3908 &IID_IUnknown,
3909 NULL
3910 };
3911
3912 HRESULT
3913 NineDevice9_new( struct pipe_screen *pScreen,
3914 D3DDEVICE_CREATION_PARAMETERS *pCreationParameters,
3915 D3DCAPS9 *pCaps,
3916 D3DPRESENT_PARAMETERS *pPresentationParameters,
3917 IDirect3D9 *pD3D9,
3918 ID3DPresentGroup *pPresentationGroup,
3919 struct d3dadapter9_context *pCTX,
3920 boolean ex,
3921 D3DDISPLAYMODEEX *pFullscreenDisplayMode,
3922 struct NineDevice9 **ppOut )
3923 {
3924 BOOL lock;
3925 lock = !!(pCreationParameters->BehaviorFlags & D3DCREATE_MULTITHREADED);
3926
3927 NINE_NEW(Device9, ppOut, lock, /* args */
3928 pScreen, pCreationParameters, pCaps,
3929 pPresentationParameters, pD3D9, pPresentationGroup, pCTX,
3930 ex, pFullscreenDisplayMode);
3931 }