st/nine: Rework constant buffer state handling
[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 default:
2641 break;
2642 }
2643
2644 if (bumpmap_index >= 0) {
2645 state->bumpmap_vars[bumpmap_index] = Value;
2646 state->changed.group |= NINE_STATE_PS_CONST;
2647 }
2648
2649 state->changed.group |= NINE_STATE_FF_PSSTAGES;
2650 state->ff.changed.tex_stage[Stage][Type / 32] |= 1 << (Type % 32);
2651
2652 return D3D_OK;
2653 }
2654
2655 HRESULT WINAPI
2656 NineDevice9_GetSamplerState( struct NineDevice9 *This,
2657 DWORD Sampler,
2658 D3DSAMPLERSTATETYPE Type,
2659 DWORD *pValue )
2660 {
2661 user_assert(Sampler < This->caps.MaxSimultaneousTextures ||
2662 Sampler == D3DDMAPSAMPLER ||
2663 (Sampler >= D3DVERTEXTEXTURESAMPLER0 &&
2664 Sampler <= D3DVERTEXTEXTURESAMPLER3), D3DERR_INVALIDCALL);
2665
2666 if (Sampler >= D3DDMAPSAMPLER)
2667 Sampler = Sampler - D3DDMAPSAMPLER + NINE_MAX_SAMPLERS_PS;
2668
2669 *pValue = This->state.samp[Sampler][Type];
2670 return D3D_OK;
2671 }
2672
2673 HRESULT WINAPI
2674 NineDevice9_SetSamplerState( struct NineDevice9 *This,
2675 DWORD Sampler,
2676 D3DSAMPLERSTATETYPE Type,
2677 DWORD Value )
2678 {
2679 struct nine_state *state = This->update;
2680
2681 DBG("This=%p Sampler=%u Type=%s Value=%08x\n", This,
2682 Sampler, nine_D3DSAMP_to_str(Type), Value);
2683
2684 user_assert(Sampler < This->caps.MaxSimultaneousTextures ||
2685 Sampler == D3DDMAPSAMPLER ||
2686 (Sampler >= D3DVERTEXTEXTURESAMPLER0 &&
2687 Sampler <= D3DVERTEXTEXTURESAMPLER3), D3DERR_INVALIDCALL);
2688
2689 if (Sampler >= D3DDMAPSAMPLER)
2690 Sampler = Sampler - D3DDMAPSAMPLER + NINE_MAX_SAMPLERS_PS;
2691
2692 if (state->samp[Sampler][Type] != Value || unlikely(This->is_recording)) {
2693 state->samp[Sampler][Type] = Value;
2694 state->changed.group |= NINE_STATE_SAMPLER;
2695 state->changed.sampler[Sampler] |= 1 << Type;
2696
2697 if (Type == D3DSAMP_SRGBTEXTURE)
2698 state->changed.srgb = TRUE;
2699 }
2700
2701 return D3D_OK;
2702 }
2703
2704 HRESULT WINAPI
2705 NineDevice9_ValidateDevice( struct NineDevice9 *This,
2706 DWORD *pNumPasses )
2707 {
2708 const struct nine_state *state = &This->state;
2709 unsigned i;
2710 unsigned w = 0, h = 0;
2711
2712 DBG("This=%p pNumPasses=%p\n", This, pNumPasses);
2713
2714 for (i = 0; i < Elements(state->samp); ++i) {
2715 if (state->samp[i][D3DSAMP_MINFILTER] == D3DTEXF_NONE ||
2716 state->samp[i][D3DSAMP_MAGFILTER] == D3DTEXF_NONE)
2717 return D3DERR_UNSUPPORTEDTEXTUREFILTER;
2718 }
2719
2720 for (i = 0; i < This->caps.NumSimultaneousRTs; ++i) {
2721 if (!state->rt[i])
2722 continue;
2723 if (w == 0) {
2724 w = state->rt[i]->desc.Width;
2725 h = state->rt[i]->desc.Height;
2726 } else
2727 if (state->rt[i]->desc.Width != w || state->rt[i]->desc.Height != h) {
2728 return D3DERR_CONFLICTINGRENDERSTATE;
2729 }
2730 }
2731 if (state->ds &&
2732 (state->rs[D3DRS_ZENABLE] || state->rs[D3DRS_STENCILENABLE])) {
2733 if (w != 0 &&
2734 (state->ds->desc.Width != w || state->ds->desc.Height != h))
2735 return D3DERR_CONFLICTINGRENDERSTATE;
2736 }
2737
2738 if (pNumPasses)
2739 *pNumPasses = 1;
2740
2741 return D3D_OK;
2742 }
2743
2744 HRESULT WINAPI
2745 NineDevice9_SetPaletteEntries( struct NineDevice9 *This,
2746 UINT PaletteNumber,
2747 const PALETTEENTRY *pEntries )
2748 {
2749 STUB(D3D_OK); /* like wine */
2750 }
2751
2752 HRESULT WINAPI
2753 NineDevice9_GetPaletteEntries( struct NineDevice9 *This,
2754 UINT PaletteNumber,
2755 PALETTEENTRY *pEntries )
2756 {
2757 STUB(D3DERR_INVALIDCALL);
2758 }
2759
2760 HRESULT WINAPI
2761 NineDevice9_SetCurrentTexturePalette( struct NineDevice9 *This,
2762 UINT PaletteNumber )
2763 {
2764 STUB(D3D_OK); /* like wine */
2765 }
2766
2767 HRESULT WINAPI
2768 NineDevice9_GetCurrentTexturePalette( struct NineDevice9 *This,
2769 UINT *PaletteNumber )
2770 {
2771 STUB(D3DERR_INVALIDCALL);
2772 }
2773
2774 HRESULT WINAPI
2775 NineDevice9_SetScissorRect( struct NineDevice9 *This,
2776 const RECT *pRect )
2777 {
2778 struct nine_state *state = This->update;
2779
2780 DBG("x=(%u..%u) y=(%u..%u)\n",
2781 pRect->left, pRect->top, pRect->right, pRect->bottom);
2782
2783 state->scissor.minx = pRect->left;
2784 state->scissor.miny = pRect->top;
2785 state->scissor.maxx = pRect->right;
2786 state->scissor.maxy = pRect->bottom;
2787
2788 state->changed.group |= NINE_STATE_SCISSOR;
2789
2790 return D3D_OK;
2791 }
2792
2793 HRESULT WINAPI
2794 NineDevice9_GetScissorRect( struct NineDevice9 *This,
2795 RECT *pRect )
2796 {
2797 pRect->left = This->state.scissor.minx;
2798 pRect->top = This->state.scissor.miny;
2799 pRect->right = This->state.scissor.maxx;
2800 pRect->bottom = This->state.scissor.maxy;
2801
2802 return D3D_OK;
2803 }
2804
2805 HRESULT WINAPI
2806 NineDevice9_SetSoftwareVertexProcessing( struct NineDevice9 *This,
2807 BOOL bSoftware )
2808 {
2809 STUB(D3DERR_INVALIDCALL);
2810 }
2811
2812 BOOL WINAPI
2813 NineDevice9_GetSoftwareVertexProcessing( struct NineDevice9 *This )
2814 {
2815 return !!(This->params.BehaviorFlags & D3DCREATE_SOFTWARE_VERTEXPROCESSING);
2816 }
2817
2818 HRESULT WINAPI
2819 NineDevice9_SetNPatchMode( struct NineDevice9 *This,
2820 float nSegments )
2821 {
2822 STUB(D3DERR_INVALIDCALL);
2823 }
2824
2825 float WINAPI
2826 NineDevice9_GetNPatchMode( struct NineDevice9 *This )
2827 {
2828 STUB(0);
2829 }
2830
2831 static inline void
2832 init_draw_info(struct pipe_draw_info *info,
2833 struct NineDevice9 *dev, D3DPRIMITIVETYPE type, UINT count)
2834 {
2835 info->mode = d3dprimitivetype_to_pipe_prim(type);
2836 info->count = prim_count_to_vertex_count(type, count);
2837 info->start_instance = 0;
2838 info->instance_count = 1;
2839 if (dev->state.stream_instancedata_mask & dev->state.stream_usage_mask)
2840 info->instance_count = MAX2(dev->state.stream_freq[0] & 0x7FFFFF, 1);
2841 info->primitive_restart = FALSE;
2842 info->restart_index = 0;
2843 info->count_from_stream_output = NULL;
2844 info->indirect = NULL;
2845 }
2846
2847 HRESULT WINAPI
2848 NineDevice9_DrawPrimitive( struct NineDevice9 *This,
2849 D3DPRIMITIVETYPE PrimitiveType,
2850 UINT StartVertex,
2851 UINT PrimitiveCount )
2852 {
2853 struct pipe_draw_info info;
2854
2855 DBG("iface %p, PrimitiveType %u, StartVertex %u, PrimitiveCount %u\n",
2856 This, PrimitiveType, StartVertex, PrimitiveCount);
2857
2858 nine_update_state(This);
2859
2860 init_draw_info(&info, This, PrimitiveType, PrimitiveCount);
2861 info.indexed = FALSE;
2862 info.start = StartVertex;
2863 info.index_bias = 0;
2864 info.min_index = info.start;
2865 info.max_index = info.count - 1;
2866
2867 This->pipe->draw_vbo(This->pipe, &info);
2868
2869 return D3D_OK;
2870 }
2871
2872 HRESULT WINAPI
2873 NineDevice9_DrawIndexedPrimitive( struct NineDevice9 *This,
2874 D3DPRIMITIVETYPE PrimitiveType,
2875 INT BaseVertexIndex,
2876 UINT MinVertexIndex,
2877 UINT NumVertices,
2878 UINT StartIndex,
2879 UINT PrimitiveCount )
2880 {
2881 struct pipe_draw_info info;
2882
2883 DBG("iface %p, PrimitiveType %u, BaseVertexIndex %u, MinVertexIndex %u "
2884 "NumVertices %u, StartIndex %u, PrimitiveCount %u\n",
2885 This, PrimitiveType, BaseVertexIndex, MinVertexIndex, NumVertices,
2886 StartIndex, PrimitiveCount);
2887
2888 user_assert(This->state.idxbuf, D3DERR_INVALIDCALL);
2889 user_assert(This->state.vdecl, D3DERR_INVALIDCALL);
2890
2891 nine_update_state(This);
2892
2893 init_draw_info(&info, This, PrimitiveType, PrimitiveCount);
2894 info.indexed = TRUE;
2895 info.start = StartIndex;
2896 info.index_bias = BaseVertexIndex;
2897 /* These don't include index bias: */
2898 info.min_index = MinVertexIndex;
2899 info.max_index = MinVertexIndex + NumVertices - 1;
2900
2901 This->pipe->draw_vbo(This->pipe, &info);
2902
2903 return D3D_OK;
2904 }
2905
2906 HRESULT WINAPI
2907 NineDevice9_DrawPrimitiveUP( struct NineDevice9 *This,
2908 D3DPRIMITIVETYPE PrimitiveType,
2909 UINT PrimitiveCount,
2910 const void *pVertexStreamZeroData,
2911 UINT VertexStreamZeroStride )
2912 {
2913 struct pipe_vertex_buffer vtxbuf;
2914 struct pipe_draw_info info;
2915
2916 DBG("iface %p, PrimitiveType %u, PrimitiveCount %u, data %p, stride %u\n",
2917 This, PrimitiveType, PrimitiveCount,
2918 pVertexStreamZeroData, VertexStreamZeroStride);
2919
2920 user_assert(pVertexStreamZeroData && VertexStreamZeroStride,
2921 D3DERR_INVALIDCALL);
2922
2923 nine_update_state(This);
2924
2925 init_draw_info(&info, This, PrimitiveType, PrimitiveCount);
2926 info.indexed = FALSE;
2927 info.start = 0;
2928 info.index_bias = 0;
2929 info.min_index = 0;
2930 info.max_index = info.count - 1;
2931
2932 vtxbuf.stride = VertexStreamZeroStride;
2933 vtxbuf.buffer_offset = 0;
2934 vtxbuf.buffer = NULL;
2935 vtxbuf.user_buffer = pVertexStreamZeroData;
2936
2937 if (!This->driver_caps.user_vbufs) {
2938 u_upload_data(This->vertex_uploader,
2939 0,
2940 (info.max_index + 1) * VertexStreamZeroStride, /* XXX */
2941 vtxbuf.user_buffer,
2942 &vtxbuf.buffer_offset,
2943 &vtxbuf.buffer);
2944 u_upload_unmap(This->vertex_uploader);
2945 vtxbuf.user_buffer = NULL;
2946 }
2947
2948 This->pipe->set_vertex_buffers(This->pipe, 0, 1, &vtxbuf);
2949
2950 This->pipe->draw_vbo(This->pipe, &info);
2951
2952 NineDevice9_PauseRecording(This);
2953 NineDevice9_SetStreamSource(This, 0, NULL, 0, 0);
2954 NineDevice9_ResumeRecording(This);
2955
2956 pipe_resource_reference(&vtxbuf.buffer, NULL);
2957
2958 return D3D_OK;
2959 }
2960
2961 HRESULT WINAPI
2962 NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9 *This,
2963 D3DPRIMITIVETYPE PrimitiveType,
2964 UINT MinVertexIndex,
2965 UINT NumVertices,
2966 UINT PrimitiveCount,
2967 const void *pIndexData,
2968 D3DFORMAT IndexDataFormat,
2969 const void *pVertexStreamZeroData,
2970 UINT VertexStreamZeroStride )
2971 {
2972 struct pipe_draw_info info;
2973 struct pipe_vertex_buffer vbuf;
2974 struct pipe_index_buffer ibuf;
2975
2976 DBG("iface %p, PrimitiveType %u, MinVertexIndex %u, NumVertices %u "
2977 "PrimitiveCount %u, pIndexData %p, IndexDataFormat %u "
2978 "pVertexStreamZeroData %p, VertexStreamZeroStride %u\n",
2979 This, PrimitiveType, MinVertexIndex, NumVertices, PrimitiveCount,
2980 pIndexData, IndexDataFormat,
2981 pVertexStreamZeroData, VertexStreamZeroStride);
2982
2983 user_assert(pIndexData && pVertexStreamZeroData, D3DERR_INVALIDCALL);
2984 user_assert(VertexStreamZeroStride, D3DERR_INVALIDCALL);
2985 user_assert(IndexDataFormat == D3DFMT_INDEX16 ||
2986 IndexDataFormat == D3DFMT_INDEX32, D3DERR_INVALIDCALL);
2987
2988 nine_update_state(This);
2989
2990 init_draw_info(&info, This, PrimitiveType, PrimitiveCount);
2991 info.indexed = TRUE;
2992 info.start = 0;
2993 info.index_bias = 0;
2994 info.min_index = MinVertexIndex;
2995 info.max_index = MinVertexIndex + NumVertices - 1;
2996
2997 vbuf.stride = VertexStreamZeroStride;
2998 vbuf.buffer_offset = 0;
2999 vbuf.buffer = NULL;
3000 vbuf.user_buffer = pVertexStreamZeroData;
3001
3002 ibuf.index_size = (IndexDataFormat == D3DFMT_INDEX16) ? 2 : 4;
3003 ibuf.offset = 0;
3004 ibuf.buffer = NULL;
3005 ibuf.user_buffer = pIndexData;
3006
3007 if (!This->driver_caps.user_vbufs) {
3008 const unsigned base = info.min_index * VertexStreamZeroStride;
3009 u_upload_data(This->vertex_uploader,
3010 base,
3011 (info.max_index -
3012 info.min_index + 1) * VertexStreamZeroStride, /* XXX */
3013 (const uint8_t *)vbuf.user_buffer + base,
3014 &vbuf.buffer_offset,
3015 &vbuf.buffer);
3016 u_upload_unmap(This->vertex_uploader);
3017 /* Won't be used: */
3018 vbuf.buffer_offset -= base;
3019 vbuf.user_buffer = NULL;
3020 }
3021 if (!This->driver_caps.user_ibufs) {
3022 u_upload_data(This->index_uploader,
3023 0,
3024 info.count * ibuf.index_size,
3025 ibuf.user_buffer,
3026 &ibuf.offset,
3027 &ibuf.buffer);
3028 u_upload_unmap(This->index_uploader);
3029 ibuf.user_buffer = NULL;
3030 }
3031
3032 This->pipe->set_vertex_buffers(This->pipe, 0, 1, &vbuf);
3033 This->pipe->set_index_buffer(This->pipe, &ibuf);
3034
3035 This->pipe->draw_vbo(This->pipe, &info);
3036
3037 pipe_resource_reference(&vbuf.buffer, NULL);
3038 pipe_resource_reference(&ibuf.buffer, NULL);
3039
3040 NineDevice9_PauseRecording(This);
3041 NineDevice9_SetIndices(This, NULL);
3042 NineDevice9_SetStreamSource(This, 0, NULL, 0, 0);
3043 NineDevice9_ResumeRecording(This);
3044
3045 return D3D_OK;
3046 }
3047
3048 /* TODO: Write to pDestBuffer directly if vertex declaration contains
3049 * only f32 formats.
3050 */
3051 HRESULT WINAPI
3052 NineDevice9_ProcessVertices( struct NineDevice9 *This,
3053 UINT SrcStartIndex,
3054 UINT DestIndex,
3055 UINT VertexCount,
3056 IDirect3DVertexBuffer9 *pDestBuffer,
3057 IDirect3DVertexDeclaration9 *pVertexDecl,
3058 DWORD Flags )
3059 {
3060 struct pipe_screen *screen = This->screen;
3061 struct NineVertexDeclaration9 *vdecl = NineVertexDeclaration9(pVertexDecl);
3062 struct NineVertexShader9 *vs;
3063 struct pipe_resource *resource;
3064 struct pipe_stream_output_target *target;
3065 struct pipe_draw_info draw;
3066 HRESULT hr;
3067 unsigned buffer_offset, buffer_size;
3068
3069 DBG("This=%p SrcStartIndex=%u DestIndex=%u VertexCount=%u "
3070 "pDestBuffer=%p pVertexDecl=%p Flags=%d\n",
3071 This, SrcStartIndex, DestIndex, VertexCount, pDestBuffer,
3072 pVertexDecl, Flags);
3073
3074 if (!screen->get_param(screen, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS))
3075 STUB(D3DERR_INVALIDCALL);
3076
3077 nine_update_state(This);
3078
3079 /* TODO: Create shader with stream output. */
3080 STUB(D3DERR_INVALIDCALL);
3081 struct NineVertexBuffer9 *dst = NineVertexBuffer9(pDestBuffer);
3082
3083 vs = This->state.vs ? This->state.vs : This->ff.vs;
3084
3085 buffer_size = VertexCount * vs->so->stride[0];
3086 if (1) {
3087 struct pipe_resource templ;
3088
3089 templ.target = PIPE_BUFFER;
3090 templ.format = PIPE_FORMAT_R8_UNORM;
3091 templ.width0 = buffer_size;
3092 templ.flags = 0;
3093 templ.bind = PIPE_BIND_STREAM_OUTPUT;
3094 templ.usage = PIPE_USAGE_STREAM;
3095 templ.height0 = templ.depth0 = templ.array_size = 1;
3096 templ.last_level = templ.nr_samples = 0;
3097
3098 resource = This->screen->resource_create(This->screen, &templ);
3099 if (!resource)
3100 return E_OUTOFMEMORY;
3101 buffer_offset = 0;
3102 } else {
3103 /* SO matches vertex declaration */
3104 resource = dst->base.resource;
3105 buffer_offset = DestIndex * vs->so->stride[0];
3106 }
3107 target = This->pipe->create_stream_output_target(This->pipe, resource,
3108 buffer_offset,
3109 buffer_size);
3110 if (!target) {
3111 pipe_resource_reference(&resource, NULL);
3112 return D3DERR_DRIVERINTERNALERROR;
3113 }
3114
3115 if (!vdecl) {
3116 hr = NineVertexDeclaration9_new_from_fvf(This, dst->desc.FVF, &vdecl);
3117 if (FAILED(hr))
3118 goto out;
3119 }
3120
3121 init_draw_info(&draw, This, D3DPT_POINTLIST, VertexCount);
3122 draw.instance_count = 1;
3123 draw.indexed = FALSE;
3124 draw.start = SrcStartIndex;
3125 draw.index_bias = 0;
3126 draw.min_index = SrcStartIndex;
3127 draw.max_index = SrcStartIndex + VertexCount - 1;
3128
3129 This->pipe->set_stream_output_targets(This->pipe, 1, &target, 0);
3130 This->pipe->draw_vbo(This->pipe, &draw);
3131 This->pipe->set_stream_output_targets(This->pipe, 0, NULL, 0);
3132 This->pipe->stream_output_target_destroy(This->pipe, target);
3133
3134 hr = NineVertexDeclaration9_ConvertStreamOutput(vdecl,
3135 dst, DestIndex, VertexCount,
3136 resource, vs->so);
3137 out:
3138 pipe_resource_reference(&resource, NULL);
3139 if (!pVertexDecl)
3140 NineUnknown_Release(NineUnknown(vdecl));
3141 return hr;
3142 }
3143
3144 HRESULT WINAPI
3145 NineDevice9_CreateVertexDeclaration( struct NineDevice9 *This,
3146 const D3DVERTEXELEMENT9 *pVertexElements,
3147 IDirect3DVertexDeclaration9 **ppDecl )
3148 {
3149 struct NineVertexDeclaration9 *vdecl;
3150
3151 DBG("This=%p pVertexElements=%p ppDecl=%p\n",
3152 This, pVertexElements, ppDecl);
3153
3154 HRESULT hr = NineVertexDeclaration9_new(This, pVertexElements, &vdecl);
3155 if (SUCCEEDED(hr))
3156 *ppDecl = (IDirect3DVertexDeclaration9 *)vdecl;
3157
3158 return hr;
3159 }
3160
3161 HRESULT WINAPI
3162 NineDevice9_SetVertexDeclaration( struct NineDevice9 *This,
3163 IDirect3DVertexDeclaration9 *pDecl )
3164 {
3165 struct nine_state *state = This->update;
3166
3167 DBG("This=%p pDecl=%p\n", This, pDecl);
3168
3169 if (likely(!This->is_recording) && state->vdecl == NineVertexDeclaration9(pDecl))
3170 return D3D_OK;
3171 nine_bind(&state->vdecl, pDecl);
3172
3173 state->changed.group |= NINE_STATE_VDECL;
3174
3175 return D3D_OK;
3176 }
3177
3178 HRESULT WINAPI
3179 NineDevice9_GetVertexDeclaration( struct NineDevice9 *This,
3180 IDirect3DVertexDeclaration9 **ppDecl )
3181 {
3182 user_assert(ppDecl, D3DERR_INVALIDCALL);
3183
3184 *ppDecl = (IDirect3DVertexDeclaration9 *)This->state.vdecl;
3185 if (*ppDecl)
3186 NineUnknown_AddRef(NineUnknown(*ppDecl));
3187 return D3D_OK;
3188 }
3189
3190 HRESULT WINAPI
3191 NineDevice9_SetFVF( struct NineDevice9 *This,
3192 DWORD FVF )
3193 {
3194 struct NineVertexDeclaration9 *vdecl;
3195 HRESULT hr;
3196
3197 DBG("FVF = %08x\n", FVF);
3198 if (!FVF)
3199 return D3D_OK; /* like wine */
3200
3201 vdecl = util_hash_table_get(This->ff.ht_fvf, &FVF);
3202 if (!vdecl) {
3203 hr = NineVertexDeclaration9_new_from_fvf(This, FVF, &vdecl);
3204 if (FAILED(hr))
3205 return hr;
3206 vdecl->fvf = FVF;
3207 util_hash_table_set(This->ff.ht_fvf, &vdecl->fvf, vdecl);
3208 NineUnknown_ConvertRefToBind(NineUnknown(vdecl));
3209 }
3210 return NineDevice9_SetVertexDeclaration(
3211 This, (IDirect3DVertexDeclaration9 *)vdecl);
3212 }
3213
3214 HRESULT WINAPI
3215 NineDevice9_GetFVF( struct NineDevice9 *This,
3216 DWORD *pFVF )
3217 {
3218 *pFVF = This->state.vdecl ? This->state.vdecl->fvf : 0;
3219 return D3D_OK;
3220 }
3221
3222 HRESULT WINAPI
3223 NineDevice9_CreateVertexShader( struct NineDevice9 *This,
3224 const DWORD *pFunction,
3225 IDirect3DVertexShader9 **ppShader )
3226 {
3227 struct NineVertexShader9 *vs;
3228 HRESULT hr;
3229
3230 DBG("This=%p pFunction=%p ppShader=%p\n", This, pFunction, ppShader);
3231
3232 hr = NineVertexShader9_new(This, &vs, pFunction, NULL);
3233 if (FAILED(hr))
3234 return hr;
3235 *ppShader = (IDirect3DVertexShader9 *)vs;
3236 return D3D_OK;
3237 }
3238
3239 HRESULT WINAPI
3240 NineDevice9_SetVertexShader( struct NineDevice9 *This,
3241 IDirect3DVertexShader9 *pShader )
3242 {
3243 struct nine_state *state = This->update;
3244
3245 DBG("This=%p pShader=%p\n", This, pShader);
3246
3247 nine_bind(&state->vs, pShader);
3248
3249 state->changed.group |= NINE_STATE_VS;
3250
3251 return D3D_OK;
3252 }
3253
3254 HRESULT WINAPI
3255 NineDevice9_GetVertexShader( struct NineDevice9 *This,
3256 IDirect3DVertexShader9 **ppShader )
3257 {
3258 user_assert(ppShader, D3DERR_INVALIDCALL);
3259 nine_reference_set(ppShader, This->state.vs);
3260 return D3D_OK;
3261 }
3262
3263 HRESULT WINAPI
3264 NineDevice9_SetVertexShaderConstantF( struct NineDevice9 *This,
3265 UINT StartRegister,
3266 const float *pConstantData,
3267 UINT Vector4fCount )
3268 {
3269 struct nine_state *state = This->update;
3270
3271 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3272 This, StartRegister, pConstantData, Vector4fCount);
3273
3274 user_assert(StartRegister < This->caps.MaxVertexShaderConst, D3DERR_INVALIDCALL);
3275 user_assert(StartRegister + Vector4fCount <= This->caps.MaxVertexShaderConst, D3DERR_INVALIDCALL);
3276
3277 if (!Vector4fCount)
3278 return D3D_OK;
3279 user_assert(pConstantData, D3DERR_INVALIDCALL);
3280
3281 memcpy(&state->vs_const_f[StartRegister * 4],
3282 pConstantData,
3283 Vector4fCount * 4 * sizeof(state->vs_const_f[0]));
3284
3285 nine_ranges_insert(&state->changed.vs_const_f,
3286 StartRegister, StartRegister + Vector4fCount,
3287 &This->range_pool);
3288
3289 state->changed.group |= NINE_STATE_VS_CONST;
3290
3291 return D3D_OK;
3292 }
3293
3294 HRESULT WINAPI
3295 NineDevice9_GetVertexShaderConstantF( struct NineDevice9 *This,
3296 UINT StartRegister,
3297 float *pConstantData,
3298 UINT Vector4fCount )
3299 {
3300 const struct nine_state *state = &This->state;
3301
3302 user_assert(StartRegister < This->caps.MaxVertexShaderConst, D3DERR_INVALIDCALL);
3303 user_assert(StartRegister + Vector4fCount <= This->caps.MaxVertexShaderConst, D3DERR_INVALIDCALL);
3304 user_assert(pConstantData, D3DERR_INVALIDCALL);
3305
3306 memcpy(pConstantData,
3307 &state->vs_const_f[StartRegister * 4],
3308 Vector4fCount * 4 * sizeof(state->vs_const_f[0]));
3309
3310 return D3D_OK;
3311 }
3312
3313 HRESULT WINAPI
3314 NineDevice9_SetVertexShaderConstantI( struct NineDevice9 *This,
3315 UINT StartRegister,
3316 const int *pConstantData,
3317 UINT Vector4iCount )
3318 {
3319 struct nine_state *state = This->update;
3320 int i;
3321
3322 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3323 This, StartRegister, pConstantData, Vector4iCount);
3324
3325 user_assert(StartRegister < NINE_MAX_CONST_I, D3DERR_INVALIDCALL);
3326 user_assert(StartRegister + Vector4iCount <= NINE_MAX_CONST_I, D3DERR_INVALIDCALL);
3327 user_assert(pConstantData, D3DERR_INVALIDCALL);
3328
3329 if (This->driver_caps.vs_integer) {
3330 memcpy(&state->vs_const_i[StartRegister][0],
3331 pConstantData,
3332 Vector4iCount * sizeof(state->vs_const_i[0]));
3333 } else {
3334 for (i = 0; i < Vector4iCount; i++) {
3335 state->vs_const_i[StartRegister+i][0] = fui((float)(pConstantData[4*i]));
3336 state->vs_const_i[StartRegister+i][1] = fui((float)(pConstantData[4*i+1]));
3337 state->vs_const_i[StartRegister+i][2] = fui((float)(pConstantData[4*i+2]));
3338 state->vs_const_i[StartRegister+i][3] = fui((float)(pConstantData[4*i+3]));
3339 }
3340 }
3341
3342 state->changed.vs_const_i |= ((1 << Vector4iCount) - 1) << StartRegister;
3343 state->changed.group |= NINE_STATE_VS_CONST;
3344
3345 return D3D_OK;
3346 }
3347
3348 HRESULT WINAPI
3349 NineDevice9_GetVertexShaderConstantI( struct NineDevice9 *This,
3350 UINT StartRegister,
3351 int *pConstantData,
3352 UINT Vector4iCount )
3353 {
3354 const struct nine_state *state = &This->state;
3355 int i;
3356
3357 user_assert(StartRegister < NINE_MAX_CONST_I, D3DERR_INVALIDCALL);
3358 user_assert(StartRegister + Vector4iCount <= NINE_MAX_CONST_I, D3DERR_INVALIDCALL);
3359 user_assert(pConstantData, D3DERR_INVALIDCALL);
3360
3361 if (This->driver_caps.vs_integer) {
3362 memcpy(pConstantData,
3363 &state->vs_const_i[StartRegister][0],
3364 Vector4iCount * sizeof(state->vs_const_i[0]));
3365 } else {
3366 for (i = 0; i < Vector4iCount; i++) {
3367 pConstantData[4*i] = (int32_t) uif(state->vs_const_i[StartRegister+i][0]);
3368 pConstantData[4*i+1] = (int32_t) uif(state->vs_const_i[StartRegister+i][1]);
3369 pConstantData[4*i+2] = (int32_t) uif(state->vs_const_i[StartRegister+i][2]);
3370 pConstantData[4*i+3] = (int32_t) uif(state->vs_const_i[StartRegister+i][3]);
3371 }
3372 }
3373
3374 return D3D_OK;
3375 }
3376
3377 HRESULT WINAPI
3378 NineDevice9_SetVertexShaderConstantB( struct NineDevice9 *This,
3379 UINT StartRegister,
3380 const BOOL *pConstantData,
3381 UINT BoolCount )
3382 {
3383 struct nine_state *state = This->update;
3384 int i;
3385 uint32_t bool_true = This->driver_caps.vs_integer ? 0xFFFFFFFF : fui(1.0f);
3386
3387 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3388 This, StartRegister, pConstantData, BoolCount);
3389
3390 user_assert(StartRegister < NINE_MAX_CONST_B, D3DERR_INVALIDCALL);
3391 user_assert(StartRegister + BoolCount <= NINE_MAX_CONST_B, D3DERR_INVALIDCALL);
3392 user_assert(pConstantData, D3DERR_INVALIDCALL);
3393
3394 for (i = 0; i < BoolCount; i++)
3395 state->vs_const_b[StartRegister + i] = pConstantData[i] ? bool_true : 0;
3396
3397 state->changed.vs_const_b |= ((1 << BoolCount) - 1) << StartRegister;
3398 state->changed.group |= NINE_STATE_VS_CONST;
3399
3400 return D3D_OK;
3401 }
3402
3403 HRESULT WINAPI
3404 NineDevice9_GetVertexShaderConstantB( struct NineDevice9 *This,
3405 UINT StartRegister,
3406 BOOL *pConstantData,
3407 UINT BoolCount )
3408 {
3409 const struct nine_state *state = &This->state;
3410 int i;
3411
3412 user_assert(StartRegister < NINE_MAX_CONST_B, D3DERR_INVALIDCALL);
3413 user_assert(StartRegister + BoolCount <= NINE_MAX_CONST_B, D3DERR_INVALIDCALL);
3414 user_assert(pConstantData, D3DERR_INVALIDCALL);
3415
3416 for (i = 0; i < BoolCount; i++)
3417 pConstantData[i] = state->vs_const_b[StartRegister + i] != 0 ? TRUE : FALSE;
3418
3419 return D3D_OK;
3420 }
3421
3422 HRESULT WINAPI
3423 NineDevice9_SetStreamSource( struct NineDevice9 *This,
3424 UINT StreamNumber,
3425 IDirect3DVertexBuffer9 *pStreamData,
3426 UINT OffsetInBytes,
3427 UINT Stride )
3428 {
3429 struct nine_state *state = This->update;
3430 struct NineVertexBuffer9 *pVBuf9 = NineVertexBuffer9(pStreamData);
3431 const unsigned i = StreamNumber;
3432
3433 DBG("This=%p StreamNumber=%u pStreamData=%p OffsetInBytes=%u Stride=%u\n",
3434 This, StreamNumber, pStreamData, OffsetInBytes, Stride);
3435
3436 user_assert(StreamNumber < This->caps.MaxStreams, D3DERR_INVALIDCALL);
3437 user_assert(Stride <= This->caps.MaxStreamStride, D3DERR_INVALIDCALL);
3438
3439 if (likely(!This->is_recording)) {
3440 if (state->stream[i] == NineVertexBuffer9(pStreamData) &&
3441 state->vtxbuf[i].stride == Stride &&
3442 state->vtxbuf[i].buffer_offset == OffsetInBytes)
3443 return D3D_OK;
3444 }
3445 nine_bind(&state->stream[i], pStreamData);
3446
3447 state->changed.vtxbuf |= 1 << StreamNumber;
3448
3449 if (pStreamData) {
3450 state->vtxbuf[i].stride = Stride;
3451 state->vtxbuf[i].buffer_offset = OffsetInBytes;
3452 }
3453 state->vtxbuf[i].buffer = pStreamData ? pVBuf9->base.resource : NULL;
3454
3455 return D3D_OK;
3456 }
3457
3458 HRESULT WINAPI
3459 NineDevice9_GetStreamSource( struct NineDevice9 *This,
3460 UINT StreamNumber,
3461 IDirect3DVertexBuffer9 **ppStreamData,
3462 UINT *pOffsetInBytes,
3463 UINT *pStride )
3464 {
3465 const struct nine_state *state = &This->state;
3466 const unsigned i = StreamNumber;
3467
3468 user_assert(StreamNumber < This->caps.MaxStreams, D3DERR_INVALIDCALL);
3469 user_assert(ppStreamData, D3DERR_INVALIDCALL);
3470
3471 nine_reference_set(ppStreamData, state->stream[i]);
3472 *pStride = state->vtxbuf[i].stride;
3473 *pOffsetInBytes = state->vtxbuf[i].buffer_offset;
3474
3475 return D3D_OK;
3476 }
3477
3478 HRESULT WINAPI
3479 NineDevice9_SetStreamSourceFreq( struct NineDevice9 *This,
3480 UINT StreamNumber,
3481 UINT Setting )
3482 {
3483 struct nine_state *state = This->update;
3484 /* const UINT freq = Setting & 0x7FFFFF; */
3485
3486 DBG("This=%p StreamNumber=%u FrequencyParameter=0x%x\n", This,
3487 StreamNumber, Setting);
3488
3489 user_assert(StreamNumber < This->caps.MaxStreams, D3DERR_INVALIDCALL);
3490 user_assert(StreamNumber != 0 || !(Setting & D3DSTREAMSOURCE_INSTANCEDATA),
3491 D3DERR_INVALIDCALL);
3492 user_assert(!((Setting & D3DSTREAMSOURCE_INSTANCEDATA) &&
3493 (Setting & D3DSTREAMSOURCE_INDEXEDDATA)), D3DERR_INVALIDCALL);
3494 user_assert(Setting, D3DERR_INVALIDCALL);
3495
3496 state->stream_freq[StreamNumber] = Setting;
3497
3498 if (Setting & D3DSTREAMSOURCE_INSTANCEDATA)
3499 state->stream_instancedata_mask |= 1 << StreamNumber;
3500 else
3501 state->stream_instancedata_mask &= ~(1 << StreamNumber);
3502
3503 state->changed.stream_freq |= 1 << StreamNumber;
3504 return D3D_OK;
3505 }
3506
3507 HRESULT WINAPI
3508 NineDevice9_GetStreamSourceFreq( struct NineDevice9 *This,
3509 UINT StreamNumber,
3510 UINT *pSetting )
3511 {
3512 user_assert(StreamNumber < This->caps.MaxStreams, D3DERR_INVALIDCALL);
3513 *pSetting = This->state.stream_freq[StreamNumber];
3514 return D3D_OK;
3515 }
3516
3517 HRESULT WINAPI
3518 NineDevice9_SetIndices( struct NineDevice9 *This,
3519 IDirect3DIndexBuffer9 *pIndexData )
3520 {
3521 struct nine_state *state = This->update;
3522
3523 DBG("This=%p pIndexData=%p\n", This, pIndexData);
3524
3525 if (likely(!This->is_recording))
3526 if (state->idxbuf == NineIndexBuffer9(pIndexData))
3527 return D3D_OK;
3528 nine_bind(&state->idxbuf, pIndexData);
3529
3530 state->changed.group |= NINE_STATE_IDXBUF;
3531
3532 return D3D_OK;
3533 }
3534
3535 /* XXX: wine/d3d9 doesn't have pBaseVertexIndex, and it doesn't make sense
3536 * here because it's an argument passed to the Draw calls.
3537 */
3538 HRESULT WINAPI
3539 NineDevice9_GetIndices( struct NineDevice9 *This,
3540 IDirect3DIndexBuffer9 **ppIndexData /*,
3541 UINT *pBaseVertexIndex */ )
3542 {
3543 user_assert(ppIndexData, D3DERR_INVALIDCALL);
3544 nine_reference_set(ppIndexData, This->state.idxbuf);
3545 return D3D_OK;
3546 }
3547
3548 HRESULT WINAPI
3549 NineDevice9_CreatePixelShader( struct NineDevice9 *This,
3550 const DWORD *pFunction,
3551 IDirect3DPixelShader9 **ppShader )
3552 {
3553 struct NinePixelShader9 *ps;
3554 HRESULT hr;
3555
3556 DBG("This=%p pFunction=%p ppShader=%p\n", This, pFunction, ppShader);
3557
3558 hr = NinePixelShader9_new(This, &ps, pFunction, NULL);
3559 if (FAILED(hr))
3560 return hr;
3561 *ppShader = (IDirect3DPixelShader9 *)ps;
3562 return D3D_OK;
3563 }
3564
3565 HRESULT WINAPI
3566 NineDevice9_SetPixelShader( struct NineDevice9 *This,
3567 IDirect3DPixelShader9 *pShader )
3568 {
3569 struct nine_state *state = This->update;
3570 unsigned old_mask = state->ps ? state->ps->rt_mask : 1;
3571 unsigned mask;
3572
3573 DBG("This=%p pShader=%p\n", This, pShader);
3574
3575 nine_bind(&state->ps, pShader);
3576
3577 state->changed.group |= NINE_STATE_PS;
3578
3579 mask = state->ps ? state->ps->rt_mask : 1;
3580 /* We need to update cbufs if the pixel shader would
3581 * write to different render targets */
3582 if (mask != old_mask)
3583 state->changed.group |= NINE_STATE_FB;
3584
3585 return D3D_OK;
3586 }
3587
3588 HRESULT WINAPI
3589 NineDevice9_GetPixelShader( struct NineDevice9 *This,
3590 IDirect3DPixelShader9 **ppShader )
3591 {
3592 user_assert(ppShader, D3DERR_INVALIDCALL);
3593 nine_reference_set(ppShader, This->state.ps);
3594 return D3D_OK;
3595 }
3596
3597 HRESULT WINAPI
3598 NineDevice9_SetPixelShaderConstantF( struct NineDevice9 *This,
3599 UINT StartRegister,
3600 const float *pConstantData,
3601 UINT Vector4fCount )
3602 {
3603 struct nine_state *state = This->update;
3604
3605 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3606 This, StartRegister, pConstantData, Vector4fCount);
3607
3608 user_assert(StartRegister < NINE_MAX_CONST_F_PS3, D3DERR_INVALIDCALL);
3609 user_assert(StartRegister + Vector4fCount <= NINE_MAX_CONST_F_PS3, D3DERR_INVALIDCALL);
3610
3611 if (!Vector4fCount)
3612 return D3D_OK;
3613 user_assert(pConstantData, D3DERR_INVALIDCALL);
3614
3615 memcpy(&state->ps_const_f[StartRegister * 4],
3616 pConstantData,
3617 Vector4fCount * 4 * sizeof(state->ps_const_f[0]));
3618
3619 nine_ranges_insert(&state->changed.ps_const_f,
3620 StartRegister, StartRegister + Vector4fCount,
3621 &This->range_pool);
3622
3623 state->changed.group |= NINE_STATE_PS_CONST;
3624
3625 return D3D_OK;
3626 }
3627
3628 HRESULT WINAPI
3629 NineDevice9_GetPixelShaderConstantF( struct NineDevice9 *This,
3630 UINT StartRegister,
3631 float *pConstantData,
3632 UINT Vector4fCount )
3633 {
3634 const struct nine_state *state = &This->state;
3635
3636 user_assert(StartRegister < NINE_MAX_CONST_F_PS3, D3DERR_INVALIDCALL);
3637 user_assert(StartRegister + Vector4fCount <= NINE_MAX_CONST_F_PS3, D3DERR_INVALIDCALL);
3638 user_assert(pConstantData, D3DERR_INVALIDCALL);
3639
3640 memcpy(pConstantData,
3641 &state->ps_const_f[StartRegister * 4],
3642 Vector4fCount * 4 * sizeof(state->ps_const_f[0]));
3643
3644 return D3D_OK;
3645 }
3646
3647 HRESULT WINAPI
3648 NineDevice9_SetPixelShaderConstantI( struct NineDevice9 *This,
3649 UINT StartRegister,
3650 const int *pConstantData,
3651 UINT Vector4iCount )
3652 {
3653 struct nine_state *state = This->update;
3654 int i;
3655
3656 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3657 This, StartRegister, pConstantData, Vector4iCount);
3658
3659 user_assert(StartRegister < NINE_MAX_CONST_I, D3DERR_INVALIDCALL);
3660 user_assert(StartRegister + Vector4iCount <= NINE_MAX_CONST_I, D3DERR_INVALIDCALL);
3661 user_assert(pConstantData, D3DERR_INVALIDCALL);
3662
3663 if (This->driver_caps.ps_integer) {
3664 memcpy(&state->ps_const_i[StartRegister][0],
3665 pConstantData,
3666 Vector4iCount * sizeof(state->ps_const_i[0]));
3667 } else {
3668 for (i = 0; i < Vector4iCount; i++) {
3669 state->ps_const_i[StartRegister+i][0] = fui((float)(pConstantData[4*i]));
3670 state->ps_const_i[StartRegister+i][1] = fui((float)(pConstantData[4*i+1]));
3671 state->ps_const_i[StartRegister+i][2] = fui((float)(pConstantData[4*i+2]));
3672 state->ps_const_i[StartRegister+i][3] = fui((float)(pConstantData[4*i+3]));
3673 }
3674 }
3675 state->changed.ps_const_i |= ((1 << Vector4iCount) - 1) << StartRegister;
3676 state->changed.group |= NINE_STATE_PS_CONST;
3677
3678 return D3D_OK;
3679 }
3680
3681 HRESULT WINAPI
3682 NineDevice9_GetPixelShaderConstantI( struct NineDevice9 *This,
3683 UINT StartRegister,
3684 int *pConstantData,
3685 UINT Vector4iCount )
3686 {
3687 const struct nine_state *state = &This->state;
3688 int i;
3689
3690 user_assert(StartRegister < NINE_MAX_CONST_I, D3DERR_INVALIDCALL);
3691 user_assert(StartRegister + Vector4iCount <= NINE_MAX_CONST_I, D3DERR_INVALIDCALL);
3692 user_assert(pConstantData, D3DERR_INVALIDCALL);
3693
3694 if (This->driver_caps.ps_integer) {
3695 memcpy(pConstantData,
3696 &state->ps_const_i[StartRegister][0],
3697 Vector4iCount * sizeof(state->ps_const_i[0]));
3698 } else {
3699 for (i = 0; i < Vector4iCount; i++) {
3700 pConstantData[4*i] = (int32_t) uif(state->ps_const_i[StartRegister+i][0]);
3701 pConstantData[4*i+1] = (int32_t) uif(state->ps_const_i[StartRegister+i][1]);
3702 pConstantData[4*i+2] = (int32_t) uif(state->ps_const_i[StartRegister+i][2]);
3703 pConstantData[4*i+3] = (int32_t) uif(state->ps_const_i[StartRegister+i][3]);
3704 }
3705 }
3706
3707 return D3D_OK;
3708 }
3709
3710 HRESULT WINAPI
3711 NineDevice9_SetPixelShaderConstantB( struct NineDevice9 *This,
3712 UINT StartRegister,
3713 const BOOL *pConstantData,
3714 UINT BoolCount )
3715 {
3716 struct nine_state *state = This->update;
3717 int i;
3718 uint32_t bool_true = This->driver_caps.ps_integer ? 0xFFFFFFFF : fui(1.0f);
3719
3720 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3721 This, StartRegister, pConstantData, BoolCount);
3722
3723 user_assert(StartRegister < NINE_MAX_CONST_B, D3DERR_INVALIDCALL);
3724 user_assert(StartRegister + BoolCount <= NINE_MAX_CONST_B, D3DERR_INVALIDCALL);
3725 user_assert(pConstantData, D3DERR_INVALIDCALL);
3726
3727 for (i = 0; i < BoolCount; i++)
3728 state->ps_const_b[StartRegister + i] = pConstantData[i] ? bool_true : 0;
3729
3730 state->changed.ps_const_b |= ((1 << BoolCount) - 1) << StartRegister;
3731 state->changed.group |= NINE_STATE_PS_CONST;
3732
3733 return D3D_OK;
3734 }
3735
3736 HRESULT WINAPI
3737 NineDevice9_GetPixelShaderConstantB( struct NineDevice9 *This,
3738 UINT StartRegister,
3739 BOOL *pConstantData,
3740 UINT BoolCount )
3741 {
3742 const struct nine_state *state = &This->state;
3743 int i;
3744
3745 user_assert(StartRegister < NINE_MAX_CONST_B, D3DERR_INVALIDCALL);
3746 user_assert(StartRegister + BoolCount <= NINE_MAX_CONST_B, D3DERR_INVALIDCALL);
3747 user_assert(pConstantData, D3DERR_INVALIDCALL);
3748
3749 for (i = 0; i < BoolCount; i++)
3750 pConstantData[i] = state->ps_const_b[StartRegister + i] ? TRUE : FALSE;
3751
3752 return D3D_OK;
3753 }
3754
3755 HRESULT WINAPI
3756 NineDevice9_DrawRectPatch( struct NineDevice9 *This,
3757 UINT Handle,
3758 const float *pNumSegs,
3759 const D3DRECTPATCH_INFO *pRectPatchInfo )
3760 {
3761 STUB(D3DERR_INVALIDCALL);
3762 }
3763
3764 HRESULT WINAPI
3765 NineDevice9_DrawTriPatch( struct NineDevice9 *This,
3766 UINT Handle,
3767 const float *pNumSegs,
3768 const D3DTRIPATCH_INFO *pTriPatchInfo )
3769 {
3770 STUB(D3DERR_INVALIDCALL);
3771 }
3772
3773 HRESULT WINAPI
3774 NineDevice9_DeletePatch( struct NineDevice9 *This,
3775 UINT Handle )
3776 {
3777 STUB(D3DERR_INVALIDCALL);
3778 }
3779
3780 HRESULT WINAPI
3781 NineDevice9_CreateQuery( struct NineDevice9 *This,
3782 D3DQUERYTYPE Type,
3783 IDirect3DQuery9 **ppQuery )
3784 {
3785 struct NineQuery9 *query;
3786 HRESULT hr;
3787
3788 DBG("This=%p Type=%d ppQuery=%p\n", This, Type, ppQuery);
3789
3790 hr = nine_is_query_supported(This->screen, Type);
3791 if (!ppQuery || hr != D3D_OK)
3792 return hr;
3793
3794 hr = NineQuery9_new(This, &query, Type);
3795 if (FAILED(hr))
3796 return hr;
3797 *ppQuery = (IDirect3DQuery9 *)query;
3798 return D3D_OK;
3799 }
3800
3801 IDirect3DDevice9Vtbl NineDevice9_vtable = {
3802 (void *)NineUnknown_QueryInterface,
3803 (void *)NineUnknown_AddRef,
3804 (void *)NineUnknown_Release,
3805 (void *)NineDevice9_TestCooperativeLevel,
3806 (void *)NineDevice9_GetAvailableTextureMem,
3807 (void *)NineDevice9_EvictManagedResources,
3808 (void *)NineDevice9_GetDirect3D,
3809 (void *)NineDevice9_GetDeviceCaps,
3810 (void *)NineDevice9_GetDisplayMode,
3811 (void *)NineDevice9_GetCreationParameters,
3812 (void *)NineDevice9_SetCursorProperties,
3813 (void *)NineDevice9_SetCursorPosition,
3814 (void *)NineDevice9_ShowCursor,
3815 (void *)NineDevice9_CreateAdditionalSwapChain,
3816 (void *)NineDevice9_GetSwapChain,
3817 (void *)NineDevice9_GetNumberOfSwapChains,
3818 (void *)NineDevice9_Reset,
3819 (void *)NineDevice9_Present,
3820 (void *)NineDevice9_GetBackBuffer,
3821 (void *)NineDevice9_GetRasterStatus,
3822 (void *)NineDevice9_SetDialogBoxMode,
3823 (void *)NineDevice9_SetGammaRamp,
3824 (void *)NineDevice9_GetGammaRamp,
3825 (void *)NineDevice9_CreateTexture,
3826 (void *)NineDevice9_CreateVolumeTexture,
3827 (void *)NineDevice9_CreateCubeTexture,
3828 (void *)NineDevice9_CreateVertexBuffer,
3829 (void *)NineDevice9_CreateIndexBuffer,
3830 (void *)NineDevice9_CreateRenderTarget,
3831 (void *)NineDevice9_CreateDepthStencilSurface,
3832 (void *)NineDevice9_UpdateSurface,
3833 (void *)NineDevice9_UpdateTexture,
3834 (void *)NineDevice9_GetRenderTargetData,
3835 (void *)NineDevice9_GetFrontBufferData,
3836 (void *)NineDevice9_StretchRect,
3837 (void *)NineDevice9_ColorFill,
3838 (void *)NineDevice9_CreateOffscreenPlainSurface,
3839 (void *)NineDevice9_SetRenderTarget,
3840 (void *)NineDevice9_GetRenderTarget,
3841 (void *)NineDevice9_SetDepthStencilSurface,
3842 (void *)NineDevice9_GetDepthStencilSurface,
3843 (void *)NineDevice9_BeginScene,
3844 (void *)NineDevice9_EndScene,
3845 (void *)NineDevice9_Clear,
3846 (void *)NineDevice9_SetTransform,
3847 (void *)NineDevice9_GetTransform,
3848 (void *)NineDevice9_MultiplyTransform,
3849 (void *)NineDevice9_SetViewport,
3850 (void *)NineDevice9_GetViewport,
3851 (void *)NineDevice9_SetMaterial,
3852 (void *)NineDevice9_GetMaterial,
3853 (void *)NineDevice9_SetLight,
3854 (void *)NineDevice9_GetLight,
3855 (void *)NineDevice9_LightEnable,
3856 (void *)NineDevice9_GetLightEnable,
3857 (void *)NineDevice9_SetClipPlane,
3858 (void *)NineDevice9_GetClipPlane,
3859 (void *)NineDevice9_SetRenderState,
3860 (void *)NineDevice9_GetRenderState,
3861 (void *)NineDevice9_CreateStateBlock,
3862 (void *)NineDevice9_BeginStateBlock,
3863 (void *)NineDevice9_EndStateBlock,
3864 (void *)NineDevice9_SetClipStatus,
3865 (void *)NineDevice9_GetClipStatus,
3866 (void *)NineDevice9_GetTexture,
3867 (void *)NineDevice9_SetTexture,
3868 (void *)NineDevice9_GetTextureStageState,
3869 (void *)NineDevice9_SetTextureStageState,
3870 (void *)NineDevice9_GetSamplerState,
3871 (void *)NineDevice9_SetSamplerState,
3872 (void *)NineDevice9_ValidateDevice,
3873 (void *)NineDevice9_SetPaletteEntries,
3874 (void *)NineDevice9_GetPaletteEntries,
3875 (void *)NineDevice9_SetCurrentTexturePalette,
3876 (void *)NineDevice9_GetCurrentTexturePalette,
3877 (void *)NineDevice9_SetScissorRect,
3878 (void *)NineDevice9_GetScissorRect,
3879 (void *)NineDevice9_SetSoftwareVertexProcessing,
3880 (void *)NineDevice9_GetSoftwareVertexProcessing,
3881 (void *)NineDevice9_SetNPatchMode,
3882 (void *)NineDevice9_GetNPatchMode,
3883 (void *)NineDevice9_DrawPrimitive,
3884 (void *)NineDevice9_DrawIndexedPrimitive,
3885 (void *)NineDevice9_DrawPrimitiveUP,
3886 (void *)NineDevice9_DrawIndexedPrimitiveUP,
3887 (void *)NineDevice9_ProcessVertices,
3888 (void *)NineDevice9_CreateVertexDeclaration,
3889 (void *)NineDevice9_SetVertexDeclaration,
3890 (void *)NineDevice9_GetVertexDeclaration,
3891 (void *)NineDevice9_SetFVF,
3892 (void *)NineDevice9_GetFVF,
3893 (void *)NineDevice9_CreateVertexShader,
3894 (void *)NineDevice9_SetVertexShader,
3895 (void *)NineDevice9_GetVertexShader,
3896 (void *)NineDevice9_SetVertexShaderConstantF,
3897 (void *)NineDevice9_GetVertexShaderConstantF,
3898 (void *)NineDevice9_SetVertexShaderConstantI,
3899 (void *)NineDevice9_GetVertexShaderConstantI,
3900 (void *)NineDevice9_SetVertexShaderConstantB,
3901 (void *)NineDevice9_GetVertexShaderConstantB,
3902 (void *)NineDevice9_SetStreamSource,
3903 (void *)NineDevice9_GetStreamSource,
3904 (void *)NineDevice9_SetStreamSourceFreq,
3905 (void *)NineDevice9_GetStreamSourceFreq,
3906 (void *)NineDevice9_SetIndices,
3907 (void *)NineDevice9_GetIndices,
3908 (void *)NineDevice9_CreatePixelShader,
3909 (void *)NineDevice9_SetPixelShader,
3910 (void *)NineDevice9_GetPixelShader,
3911 (void *)NineDevice9_SetPixelShaderConstantF,
3912 (void *)NineDevice9_GetPixelShaderConstantF,
3913 (void *)NineDevice9_SetPixelShaderConstantI,
3914 (void *)NineDevice9_GetPixelShaderConstantI,
3915 (void *)NineDevice9_SetPixelShaderConstantB,
3916 (void *)NineDevice9_GetPixelShaderConstantB,
3917 (void *)NineDevice9_DrawRectPatch,
3918 (void *)NineDevice9_DrawTriPatch,
3919 (void *)NineDevice9_DeletePatch,
3920 (void *)NineDevice9_CreateQuery
3921 };
3922
3923 static const GUID *NineDevice9_IIDs[] = {
3924 &IID_IDirect3DDevice9,
3925 &IID_IUnknown,
3926 NULL
3927 };
3928
3929 HRESULT
3930 NineDevice9_new( struct pipe_screen *pScreen,
3931 D3DDEVICE_CREATION_PARAMETERS *pCreationParameters,
3932 D3DCAPS9 *pCaps,
3933 D3DPRESENT_PARAMETERS *pPresentationParameters,
3934 IDirect3D9 *pD3D9,
3935 ID3DPresentGroup *pPresentationGroup,
3936 struct d3dadapter9_context *pCTX,
3937 boolean ex,
3938 D3DDISPLAYMODEEX *pFullscreenDisplayMode,
3939 struct NineDevice9 **ppOut )
3940 {
3941 BOOL lock;
3942 lock = !!(pCreationParameters->BehaviorFlags & D3DCREATE_MULTITHREADED);
3943
3944 NINE_NEW(Device9, ppOut, lock, /* args */
3945 pScreen, pCreationParameters, pCaps,
3946 pPresentationParameters, pD3D9, pPresentationGroup, pCTX,
3947 ex, pFullscreenDisplayMode);
3948 }