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