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