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