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