2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
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:
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
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. */
24 #include "stateblock9.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"
35 #include "cubetexture9.h"
36 #include "volumetexture9.h"
37 #include "nine_helpers.h"
38 #include "nine_pipe.h"
40 #include "nine_dump.h"
42 #include "pipe/p_screen.h"
43 #include "pipe/p_context.h"
44 #include "util/u_math.h"
45 #include "util/u_inlines.h"
46 #include "util/u_hash_table.h"
47 #include "util/u_format.h"
48 #include "util/u_surface.h"
49 #include "util/u_upload_mgr.h"
50 #include "hud/hud_context.h"
52 #include "cso_cache/cso_context.h"
54 #define DBG_CHANNEL DBG_DEVICE
57 NineDevice9_SetDefaultState( struct NineDevice9
*This
, boolean is_reset
)
59 struct NineSurface9
*refSurf
= NULL
;
61 DBG("This=%p is_reset=%d\n", This
, (int) is_reset
);
63 assert(!This
->is_recording
);
65 nine_state_set_defaults(This
, &This
->caps
, is_reset
);
67 This
->state
.viewport
.X
= 0;
68 This
->state
.viewport
.Y
= 0;
69 This
->state
.viewport
.Width
= 0;
70 This
->state
.viewport
.Height
= 0;
72 This
->state
.scissor
.minx
= 0;
73 This
->state
.scissor
.miny
= 0;
74 This
->state
.scissor
.maxx
= 0xffff;
75 This
->state
.scissor
.maxy
= 0xffff;
77 if (This
->nswapchains
&& This
->swapchains
[0]->params
.BackBufferCount
)
78 refSurf
= This
->swapchains
[0]->buffers
[0];
81 This
->state
.viewport
.Width
= refSurf
->desc
.Width
;
82 This
->state
.viewport
.Height
= refSurf
->desc
.Height
;
83 This
->state
.scissor
.maxx
= refSurf
->desc
.Width
;
84 This
->state
.scissor
.maxy
= refSurf
->desc
.Height
;
87 if (This
->nswapchains
&& This
->swapchains
[0]->params
.EnableAutoDepthStencil
)
88 This
->state
.rs
[D3DRS_ZENABLE
] = TRUE
;
89 if (This
->state
.rs
[D3DRS_ZENABLE
])
90 NineDevice9_SetDepthStencilSurface(
91 This
, (IDirect3DSurface9
*)This
->swapchains
[0]->zsbuf
);
95 NineDevice9_RestoreNonCSOState( struct NineDevice9
*This
, unsigned mask
)
97 struct pipe_context
*pipe
= This
->pipe
;
99 DBG("This=%p mask=%u\n", This
, mask
);
102 struct pipe_constant_buffer cb
;
103 cb
.buffer_offset
= 0;
105 if (This
->prefer_user_constbuf
) {
107 cb
.user_buffer
= This
->state
.vs_const_f
;
109 cb
.buffer
= This
->constbuf_vs
;
110 cb
.user_buffer
= NULL
;
112 cb
.buffer_size
= This
->vs_const_size
;
113 pipe
->set_constant_buffer(pipe
, PIPE_SHADER_VERTEX
, 0, &cb
);
115 if (This
->prefer_user_constbuf
) {
116 cb
.user_buffer
= This
->state
.ps_const_f
;
118 cb
.buffer
= This
->constbuf_ps
;
120 cb
.buffer_size
= This
->ps_const_size
;
121 pipe
->set_constant_buffer(pipe
, PIPE_SHADER_FRAGMENT
, 0, &cb
);
125 struct pipe_poly_stipple stipple
;
126 memset(&stipple
, ~0, sizeof(stipple
));
127 pipe
->set_polygon_stipple(pipe
, &stipple
);
130 This
->state
.changed
.group
= NINE_STATE_ALL
;
131 This
->state
.changed
.vtxbuf
= (1ULL << This
->caps
.MaxStreams
) - 1;
132 This
->state
.changed
.ucp
= (1 << PIPE_MAX_CLIP_PLANES
) - 1;
133 This
->state
.changed
.texture
= NINE_PS_SAMPLERS_MASK
| NINE_VS_SAMPLERS_MASK
;
136 #define GET_PCAP(n) pScreen->get_param(pScreen, PIPE_CAP_##n)
138 NineDevice9_ctor( struct NineDevice9
*This
,
139 struct NineUnknownParams
*pParams
,
140 struct pipe_screen
*pScreen
,
141 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
143 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
145 ID3DPresentGroup
*pPresentationGroup
,
146 struct d3dadapter9_context
*pCTX
,
148 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
)
151 HRESULT hr
= NineUnknown_ctor(&This
->base
, pParams
);
153 DBG("This=%p pParams=%p pScreen=%p pCreationParameters=%p pCaps=%p pPresentationParameters=%p "
154 "pD3D9=%p pPresentationGroup=%p pCTX=%p ex=%d pFullscreenDisplayMode=%p\n",
155 This
, pParams
, pScreen
, pCreationParameters
, pCaps
, pPresentationParameters
, pD3D9
,
156 pPresentationGroup
, pCTX
, (int) ex
, pFullscreenDisplayMode
);
158 if (FAILED(hr
)) { return hr
; }
160 list_inithead(&This
->update_textures
);
162 This
->screen
= pScreen
;
165 This
->params
= *pCreationParameters
;
167 This
->present
= pPresentationGroup
;
168 IDirect3D9_AddRef(This
->d3d9
);
169 ID3DPresentGroup_AddRef(This
->present
);
171 This
->pipe
= This
->screen
->context_create(This
->screen
, NULL
);
172 if (!This
->pipe
) { return E_OUTOFMEMORY
; } /* guess */
174 This
->cso
= cso_create_context(This
->pipe
);
175 if (!This
->cso
) { return E_OUTOFMEMORY
; } /* also a guess */
177 /* Create first, it messes up our state. */
178 This
->hud
= hud_create(This
->pipe
, This
->cso
); /* NULL result is fine */
180 /* create implicit swapchains */
181 This
->nswapchains
= ID3DPresentGroup_GetMultiheadCount(This
->present
);
182 This
->swapchains
= CALLOC(This
->nswapchains
,
183 sizeof(struct NineSwapChain9
*));
184 if (!This
->swapchains
) { return E_OUTOFMEMORY
; }
186 for (i
= 0; i
< This
->nswapchains
; ++i
) {
187 ID3DPresent
*present
;
189 hr
= ID3DPresentGroup_GetPresent(This
->present
, i
, &present
);
194 D3DDISPLAYMODEEX
*mode
= NULL
;
195 struct NineSwapChain9Ex
**ret
=
196 (struct NineSwapChain9Ex
**)&This
->swapchains
[i
];
198 if (pFullscreenDisplayMode
) mode
= &(pFullscreenDisplayMode
[i
]);
199 /* when this is a Device9Ex, it should create SwapChain9Exs */
200 hr
= NineSwapChain9Ex_new(This
, TRUE
, present
,
201 &pPresentationParameters
[i
], pCTX
,
202 This
->params
.hFocusWindow
, mode
, ret
);
204 hr
= NineSwapChain9_new(This
, TRUE
, present
,
205 &pPresentationParameters
[i
], pCTX
,
206 This
->params
.hFocusWindow
,
207 &This
->swapchains
[i
]);
210 ID3DPresent_Release(present
);
213 NineUnknown_ConvertRefToBind(NineUnknown(This
->swapchains
[i
]));
215 hr
= NineSwapChain9_GetBackBuffer(This
->swapchains
[i
], 0,
216 D3DBACKBUFFER_TYPE_MONO
,
217 (IDirect3DSurface9
**)
221 NineUnknown_ConvertRefToBind(NineUnknown(This
->state
.rt
[i
]));
224 This
->cursor
.software
= FALSE
;
225 This
->cursor
.hotspot
.x
= -1;
226 This
->cursor
.hotspot
.y
= -1;
228 struct pipe_resource tmpl
;
229 tmpl
.target
= PIPE_TEXTURE_2D
;
230 tmpl
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
237 tmpl
.usage
= PIPE_USAGE_DEFAULT
;
238 tmpl
.bind
= PIPE_BIND_CURSOR
| PIPE_BIND_SAMPLER_VIEW
;
241 This
->cursor
.image
= pScreen
->resource_create(pScreen
, &tmpl
);
242 if (!This
->cursor
.image
)
243 return D3DERR_OUTOFVIDEOMEMORY
;
246 /* Create constant buffers. */
248 struct pipe_resource tmpl
;
249 unsigned max_const_vs
, max_const_ps
;
251 /* vs 3.0: >= 256 float constants, but for cards with exactly 256 slots,
252 * we have to take in some more slots for int and bool*/
253 max_const_vs
= _min(pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
,
254 PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
) /
257 /* ps 3.0: 224 float constants. All cards supported support at least
258 * 256 constants for ps */
259 max_const_ps
= 224 + (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
261 This
->max_vs_const_f
= max_const_vs
-
262 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
263 This
->max_ps_const_f
= max_const_ps
-
264 (NINE_MAX_CONST_I
+ NINE_MAX_CONST_B
/ 4);
266 This
->vs_const_size
= max_const_vs
* sizeof(float[4]);
267 This
->ps_const_size
= max_const_ps
* sizeof(float[4]);
268 /* Include space for I,B constants for user constbuf. */
269 This
->state
.vs_const_f
= CALLOC(This
->vs_const_size
, 1);
270 This
->state
.ps_const_f
= CALLOC(This
->ps_const_size
, 1);
271 This
->state
.vs_lconstf_temp
= CALLOC(This
->vs_const_size
,1);
272 if (!This
->state
.vs_const_f
|| !This
->state
.ps_const_f
||
273 !This
->state
.vs_lconstf_temp
)
274 return E_OUTOFMEMORY
;
276 if (strstr(pScreen
->get_name(pScreen
), "AMD") ||
277 strstr(pScreen
->get_name(pScreen
), "ATI"))
278 This
->prefer_user_constbuf
= TRUE
;
280 tmpl
.target
= PIPE_BUFFER
;
281 tmpl
.format
= PIPE_FORMAT_R8_UNORM
;
287 tmpl
.usage
= PIPE_USAGE_DYNAMIC
;
288 tmpl
.bind
= PIPE_BIND_CONSTANT_BUFFER
;
291 tmpl
.width0
= This
->vs_const_size
;
292 This
->constbuf_vs
= pScreen
->resource_create(pScreen
, &tmpl
);
294 tmpl
.width0
= This
->ps_const_size
;
295 This
->constbuf_ps
= pScreen
->resource_create(pScreen
, &tmpl
);
297 if (!This
->constbuf_vs
|| !This
->constbuf_ps
)
298 return E_OUTOFMEMORY
;
301 /* Allocate upload helper for drivers that suck (from st pov ;). */
305 This
->driver_caps
.user_vbufs
= GET_PCAP(USER_VERTEX_BUFFERS
);
306 This
->driver_caps
.user_ibufs
= GET_PCAP(USER_INDEX_BUFFERS
);
308 if (!This
->driver_caps
.user_vbufs
) bind
|= PIPE_BIND_VERTEX_BUFFER
;
309 if (!This
->driver_caps
.user_ibufs
) bind
|= PIPE_BIND_INDEX_BUFFER
;
311 This
->upload
= u_upload_create(This
->pipe
, 1 << 20, 4, bind
);
314 This
->driver_caps
.window_space_position_support
= GET_PCAP(TGSI_VS_WINDOW_SPACE_POSITION
);
315 This
->driver_caps
.vs_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_VERTEX
, PIPE_SHADER_CAP_INTEGERS
);
316 This
->driver_caps
.ps_integer
= pScreen
->get_shader_param(pScreen
, PIPE_SHADER_FRAGMENT
, PIPE_SHADER_CAP_INTEGERS
);
318 nine_ff_init(This
); /* initialize fixed function code */
320 NineDevice9_SetDefaultState(This
, FALSE
);
321 NineDevice9_RestoreNonCSOState(This
, ~0);
323 This
->update
= &This
->state
;
324 nine_update_state(This
, ~0);
326 ID3DPresentGroup_Release(This
->present
);
333 NineDevice9_dtor( struct NineDevice9
*This
)
337 DBG("This=%p\n", This
);
339 if (This
->pipe
&& This
->cso
)
340 nine_pipe_context_clear(This
);
342 nine_state_clear(&This
->state
, TRUE
);
345 u_upload_destroy(This
->upload
);
347 nine_bind(&This
->record
, NULL
);
349 pipe_resource_reference(&This
->constbuf_vs
, NULL
);
350 pipe_resource_reference(&This
->constbuf_ps
, NULL
);
351 FREE(This
->state
.vs_const_f
);
352 FREE(This
->state
.ps_const_f
);
353 FREE(This
->state
.vs_lconstf_temp
);
355 if (This
->swapchains
) {
356 for (i
= 0; i
< This
->nswapchains
; ++i
)
357 NineUnknown_Unbind(NineUnknown(This
->swapchains
[i
]));
358 FREE(This
->swapchains
);
364 cso_destroy_context(This
->cso
);
366 if (This
->pipe
->destroy
) { This
->pipe
->destroy(This
->pipe
); }
369 if (This
->present
) { ID3DPresentGroup_Release(This
->present
); }
370 if (This
->d3d9
) { IDirect3D9_Release(This
->d3d9
); }
372 NineUnknown_dtor(&This
->base
);
376 NineDevice9_GetScreen( struct NineDevice9
*This
)
381 struct pipe_context
*
382 NineDevice9_GetPipe( struct NineDevice9
*This
)
388 NineDevice9_GetCSO( struct NineDevice9
*This
)
394 NineDevice9_GetCaps( struct NineDevice9
*This
)
400 NineDevice9_PauseRecording( struct NineDevice9
*This
)
403 This
->update
= &This
->state
;
404 This
->is_recording
= FALSE
;
409 NineDevice9_ResumeRecording( struct NineDevice9
*This
)
412 This
->update
= &This
->record
->state
;
413 This
->is_recording
= TRUE
;
418 NineDevice9_TestCooperativeLevel( struct NineDevice9
*This
)
420 return D3D_OK
; /* TODO */
424 NineDevice9_GetAvailableTextureMem( struct NineDevice9
*This
)
426 const unsigned mem
= This
->screen
->get_param(This
->screen
, PIPE_CAP_VIDEO_MEMORY
);
434 NineDevice9_EvictManagedResources( struct NineDevice9
*This
)
436 /* We don't really need to do anything here, but might want to free up
437 * the GPU virtual address space by killing pipe_resources.
443 NineDevice9_GetDirect3D( struct NineDevice9
*This
,
444 IDirect3D9
**ppD3D9
)
446 user_assert(ppD3D9
!= NULL
, E_POINTER
);
447 IDirect3D9_AddRef(This
->d3d9
);
448 *ppD3D9
= This
->d3d9
;
453 NineDevice9_GetDeviceCaps( struct NineDevice9
*This
,
456 user_assert(pCaps
!= NULL
, D3DERR_INVALIDCALL
);
462 NineDevice9_GetDisplayMode( struct NineDevice9
*This
,
464 D3DDISPLAYMODE
*pMode
)
466 DBG("This=%p iSwapChain=%u pMode=%p\n", This
, iSwapChain
, pMode
);
468 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
470 return NineSwapChain9_GetDisplayMode(This
->swapchains
[iSwapChain
], pMode
);
474 NineDevice9_GetCreationParameters( struct NineDevice9
*This
,
475 D3DDEVICE_CREATION_PARAMETERS
*pParameters
)
477 user_assert(pParameters
!= NULL
, D3DERR_INVALIDCALL
);
478 *pParameters
= This
->params
;
483 NineDevice9_SetCursorProperties( struct NineDevice9
*This
,
486 IDirect3DSurface9
*pCursorBitmap
)
488 /* TODO: hardware cursor */
489 struct NineSurface9
*surf
= NineSurface9(pCursorBitmap
);
490 struct pipe_context
*pipe
= This
->pipe
;
492 struct pipe_transfer
*transfer
;
495 DBG_FLAG(DBG_SWAPCHAIN
, "This=%p XHotSpot=%u YHotSpot=%u "
496 "pCursorBitmap=%p\n", This
, XHotSpot
, YHotSpot
, pCursorBitmap
);
498 user_assert(pCursorBitmap
, D3DERR_INVALIDCALL
);
500 This
->cursor
.w
= MIN2(surf
->desc
.Width
, This
->cursor
.image
->width0
);
501 This
->cursor
.h
= MIN2(surf
->desc
.Height
, This
->cursor
.image
->height0
);
503 u_box_origin_2d(This
->cursor
.w
, This
->cursor
.h
, &box
);
505 ptr
= pipe
->transfer_map(pipe
, This
->cursor
.image
, 0,
506 PIPE_TRANSFER_WRITE
|
507 PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
,
510 ret_err("Failed to update cursor image.\n", D3DERR_DRIVERINTERNALERROR
);
512 This
->cursor
.hotspot
.x
= XHotSpot
;
513 This
->cursor
.hotspot
.y
= YHotSpot
;
515 /* Copy cursor image to internal storage. */
519 const struct util_format_description
*sfmt
=
520 util_format_description(surf
->base
.info
.format
);
523 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, D3DLOCK_READONLY
);
525 ret_err("Failed to map cursor source image.\n",
526 D3DERR_DRIVERINTERNALERROR
);
528 sfmt
->unpack_rgba_8unorm(ptr
, transfer
->stride
,
529 lock
.pBits
, lock
.Pitch
,
530 This
->cursor
.w
, This
->cursor
.h
);
532 if (!This
->cursor
.software
&&
533 This
->cursor
.w
== 32 && This
->cursor
.h
== 32)
534 ID3DPresent_SetCursor(This
->swapchains
[0]->present
,
535 lock
.pBits
, &This
->cursor
.hotspot
,
536 This
->cursor
.visible
);
538 NineSurface9_UnlockRect(surf
);
540 pipe
->transfer_unmap(pipe
, transfer
);
546 NineDevice9_SetCursorPosition( struct NineDevice9
*This
,
551 struct NineSwapChain9
*swap
= This
->swapchains
[0];
553 DBG("This=%p X=%d Y=%d Flags=%d\n", This
, X
, Y
, Flags
);
555 This
->cursor
.pos
.x
= X
;
556 This
->cursor
.pos
.y
= Y
;
558 if (!This
->cursor
.software
)
559 ID3DPresent_SetCursorPos(swap
->present
, &This
->cursor
.pos
);
563 NineDevice9_ShowCursor( struct NineDevice9
*This
,
566 BOOL old
= This
->cursor
.visible
;
568 DBG("This=%p bShow=%d\n", This
, (int) bShow
);
570 This
->cursor
.visible
= bShow
&& (This
->cursor
.hotspot
.x
!= -1);
571 if (!This
->cursor
.software
)
572 ID3DPresent_SetCursor(This
->swapchains
[0]->present
, NULL
, NULL
, bShow
);
578 NineDevice9_CreateAdditionalSwapChain( struct NineDevice9
*This
,
579 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
580 IDirect3DSwapChain9
**pSwapChain
)
582 struct NineSwapChain9
*swapchain
, *tmplt
= This
->swapchains
[0];
583 ID3DPresent
*present
;
586 DBG("This=%p pPresentationParameters=%p pSwapChain=%p\n",
587 This
, pPresentationParameters
, pSwapChain
);
589 user_assert(pPresentationParameters
, D3DERR_INVALIDCALL
);
591 hr
= ID3DPresentGroup_CreateAdditionalPresent(This
->present
, pPresentationParameters
, &present
);
596 hr
= NineSwapChain9_new(This
, FALSE
, present
, pPresentationParameters
,
598 tmplt
->params
.hDeviceWindow
,
603 *pSwapChain
= (IDirect3DSwapChain9
*)swapchain
;
608 NineDevice9_GetSwapChain( struct NineDevice9
*This
,
610 IDirect3DSwapChain9
**pSwapChain
)
612 user_assert(pSwapChain
!= NULL
, D3DERR_INVALIDCALL
);
615 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
617 NineUnknown_AddRef(NineUnknown(This
->swapchains
[iSwapChain
]));
618 *pSwapChain
= (IDirect3DSwapChain9
*)This
->swapchains
[iSwapChain
];
624 NineDevice9_GetNumberOfSwapChains( struct NineDevice9
*This
)
626 return This
->nswapchains
;
630 NineDevice9_Reset( struct NineDevice9
*This
,
631 D3DPRESENT_PARAMETERS
*pPresentationParameters
)
636 DBG("This=%p pPresentationParameters=%p\n", This
, pPresentationParameters
);
638 for (i
= 0; i
< This
->nswapchains
; ++i
) {
639 D3DPRESENT_PARAMETERS
*params
= &pPresentationParameters
[i
];
640 hr
= NineSwapChain9_Resize(This
->swapchains
[i
], params
, NULL
);
642 return (hr
== D3DERR_OUTOFVIDEOMEMORY
) ? hr
: D3DERR_DEVICELOST
;
645 nine_pipe_context_clear(This
);
646 nine_state_clear(&This
->state
, TRUE
);
648 NineDevice9_SetDefaultState(This
, TRUE
);
649 NineDevice9_SetRenderTarget(
650 This
, 0, (IDirect3DSurface9
*)This
->swapchains
[0]->buffers
[0]);
651 /* XXX: better use GetBackBuffer here ? */
657 NineDevice9_Present( struct NineDevice9
*This
,
658 const RECT
*pSourceRect
,
659 const RECT
*pDestRect
,
660 HWND hDestWindowOverride
,
661 const RGNDATA
*pDirtyRegion
)
666 DBG("This=%p pSourceRect=%p pDestRect=%p hDestWindowOverride=%p pDirtyRegion=%p\n",
667 This
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
669 /* XXX is this right? */
670 for (i
= 0; i
< This
->nswapchains
; ++i
) {
671 hr
= NineSwapChain9_Present(This
->swapchains
[i
], pSourceRect
, pDestRect
,
672 hDestWindowOverride
, pDirtyRegion
, 0);
673 if (FAILED(hr
)) { return hr
; }
680 NineDevice9_GetBackBuffer( struct NineDevice9
*This
,
683 D3DBACKBUFFER_TYPE Type
,
684 IDirect3DSurface9
**ppBackBuffer
)
686 user_assert(ppBackBuffer
!= NULL
, D3DERR_INVALIDCALL
);
687 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
689 return NineSwapChain9_GetBackBuffer(This
->swapchains
[iSwapChain
],
690 iBackBuffer
, Type
, ppBackBuffer
);
694 NineDevice9_GetRasterStatus( struct NineDevice9
*This
,
696 D3DRASTER_STATUS
*pRasterStatus
)
698 user_assert(pRasterStatus
!= NULL
, D3DERR_INVALIDCALL
);
699 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
701 return NineSwapChain9_GetRasterStatus(This
->swapchains
[iSwapChain
],
706 NineDevice9_SetDialogBoxMode( struct NineDevice9
*This
,
707 BOOL bEnableDialogs
)
709 STUB(D3DERR_INVALIDCALL
);
713 NineDevice9_SetGammaRamp( struct NineDevice9
*This
,
716 const D3DGAMMARAMP
*pRamp
)
718 DBG("This=%p iSwapChain=%u Flags=%x pRamp=%p\n", This
,
719 iSwapChain
, Flags
, pRamp
);
721 user_warn(iSwapChain
>= This
->nswapchains
);
724 if (pRamp
&& (iSwapChain
< This
->nswapchains
)) {
725 struct NineSwapChain9
*swap
= This
->swapchains
[iSwapChain
];
726 swap
->gamma
= *pRamp
;
727 ID3DPresent_SetGammaRamp(swap
->present
, pRamp
, swap
->params
.hDeviceWindow
);
732 NineDevice9_GetGammaRamp( struct NineDevice9
*This
,
734 D3DGAMMARAMP
*pRamp
)
736 DBG("This=%p iSwapChain=%u pRamp=%p\n", This
, iSwapChain
, pRamp
);
738 user_warn(iSwapChain
>= This
->nswapchains
);
741 if (pRamp
&& (iSwapChain
< This
->nswapchains
))
742 *pRamp
= This
->swapchains
[iSwapChain
]->gamma
;
746 NineDevice9_CreateTexture( struct NineDevice9
*This
,
753 IDirect3DTexture9
**ppTexture
,
754 HANDLE
*pSharedHandle
)
756 struct NineTexture9
*tex
;
759 DBG("This=%p Width=%u Height=%u Levels=%u Usage=%s Format=%s Pool=%s "
760 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Levels
,
761 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
762 nine_D3DPOOL_to_str(Pool
), ppTexture
, pSharedHandle
);
764 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DMAP
|
765 D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
766 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
;
768 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
769 user_assert(!pSharedHandle
|| This
->ex
, D3DERR_INVALIDCALL
);
770 /* When is used shared handle, Pool must be
771 * SYSTEMMEM with Levels 1 or DEFAULT with any Levels */
772 user_assert(!pSharedHandle
|| Pool
!= D3DPOOL_SYSTEMMEM
|| Levels
== 1,
774 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_SYSTEMMEM
|| Pool
== D3DPOOL_DEFAULT
,
776 user_assert((Usage
!= D3DUSAGE_AUTOGENMIPMAP
|| Levels
<= 1), D3DERR_INVALIDCALL
);
778 hr
= NineTexture9_new(This
, Width
, Height
, Levels
, Usage
, Format
, Pool
,
779 &tex
, pSharedHandle
);
781 *ppTexture
= (IDirect3DTexture9
*)tex
;
787 NineDevice9_CreateVolumeTexture( struct NineDevice9
*This
,
795 IDirect3DVolumeTexture9
**ppVolumeTexture
,
796 HANDLE
*pSharedHandle
)
798 struct NineVolumeTexture9
*tex
;
801 DBG("This=%p Width=%u Height=%u Depth=%u Levels=%u Usage=%s Format=%s Pool=%s "
802 "ppOut=%p pSharedHandle=%p\n", This
, Width
, Height
, Depth
, Levels
,
803 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
804 nine_D3DPOOL_to_str(Pool
), ppVolumeTexture
, pSharedHandle
);
806 Usage
&= D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
807 D3DUSAGE_SOFTWAREPROCESSING
;
809 user_assert(Width
&& Height
&& Depth
, D3DERR_INVALIDCALL
);
810 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
812 hr
= NineVolumeTexture9_new(This
, Width
, Height
, Depth
, Levels
,
813 Usage
, Format
, Pool
, &tex
, pSharedHandle
);
815 *ppVolumeTexture
= (IDirect3DVolumeTexture9
*)tex
;
821 NineDevice9_CreateCubeTexture( struct NineDevice9
*This
,
827 IDirect3DCubeTexture9
**ppCubeTexture
,
828 HANDLE
*pSharedHandle
)
830 struct NineCubeTexture9
*tex
;
833 DBG("This=%p EdgeLength=%u Levels=%u Usage=%s Format=%s Pool=%s ppOut=%p "
834 "pSharedHandle=%p\n", This
, EdgeLength
, Levels
,
835 nine_D3DUSAGE_to_str(Usage
), d3dformat_to_string(Format
),
836 nine_D3DPOOL_to_str(Pool
), ppCubeTexture
, pSharedHandle
);
838 Usage
&= D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_DEPTHSTENCIL
| D3DUSAGE_DYNAMIC
|
839 D3DUSAGE_NONSECURE
| D3DUSAGE_RENDERTARGET
|
840 D3DUSAGE_SOFTWAREPROCESSING
;
842 user_assert(EdgeLength
, D3DERR_INVALIDCALL
);
843 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
845 hr
= NineCubeTexture9_new(This
, EdgeLength
, Levels
, Usage
, Format
, Pool
,
846 &tex
, pSharedHandle
);
848 *ppCubeTexture
= (IDirect3DCubeTexture9
*)tex
;
854 NineDevice9_CreateVertexBuffer( struct NineDevice9
*This
,
859 IDirect3DVertexBuffer9
**ppVertexBuffer
,
860 HANDLE
*pSharedHandle
)
862 struct NineVertexBuffer9
*buf
;
864 D3DVERTEXBUFFER_DESC desc
;
866 DBG("This=%p Length=%u Usage=%x FVF=%x Pool=%u ppOut=%p pSharedHandle=%p\n",
867 This
, Length
, Usage
, FVF
, Pool
, ppVertexBuffer
, pSharedHandle
);
869 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
871 desc
.Format
= D3DFMT_VERTEXDATA
;
872 desc
.Type
= D3DRTYPE_VERTEXBUFFER
;
874 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
875 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
876 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_TEXTAPI
|
882 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
883 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
885 hr
= NineVertexBuffer9_new(This
, &desc
, &buf
);
887 *ppVertexBuffer
= (IDirect3DVertexBuffer9
*)buf
;
892 NineDevice9_CreateIndexBuffer( struct NineDevice9
*This
,
897 IDirect3DIndexBuffer9
**ppIndexBuffer
,
898 HANDLE
*pSharedHandle
)
900 struct NineIndexBuffer9
*buf
;
902 D3DINDEXBUFFER_DESC desc
;
904 DBG("This=%p Length=%u Usage=%x Format=%s Pool=%u ppOut=%p "
905 "pSharedHandle=%p\n", This
, Length
, Usage
,
906 d3dformat_to_string(Format
), Pool
, ppIndexBuffer
, pSharedHandle
);
908 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_NOTAVAILABLE
);
910 desc
.Format
= Format
;
911 desc
.Type
= D3DRTYPE_INDEXBUFFER
;
913 (D3DUSAGE_DONOTCLIP
| D3DUSAGE_DYNAMIC
| D3DUSAGE_NONSECURE
|
914 D3DUSAGE_NPATCHES
| D3DUSAGE_POINTS
| D3DUSAGE_RTPATCHES
|
915 D3DUSAGE_SOFTWAREPROCESSING
| D3DUSAGE_WRITEONLY
);
919 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
920 user_assert(desc
.Usage
== Usage
, D3DERR_INVALIDCALL
);
922 hr
= NineIndexBuffer9_new(This
, &desc
, &buf
);
924 *ppIndexBuffer
= (IDirect3DIndexBuffer9
*)buf
;
929 create_zs_or_rt_surface(struct NineDevice9
*This
,
930 unsigned type
, /* 0 = RT, 1 = ZS, 2 = plain */
932 UINT Width
, UINT Height
,
934 D3DMULTISAMPLE_TYPE MultiSample
,
935 DWORD MultisampleQuality
,
936 BOOL Discard_or_Lockable
,
937 IDirect3DSurface9
**ppSurface
,
938 HANDLE
*pSharedHandle
)
940 struct NineSurface9
*surface
;
941 struct pipe_screen
*screen
= This
->screen
;
942 struct pipe_resource
*resource
= NULL
;
944 D3DSURFACE_DESC desc
;
945 struct pipe_resource templ
;
947 DBG("This=%p type=%u Pool=%s Width=%u Height=%u Format=%s MS=%u Quality=%u "
948 "Discard_or_Lockable=%i ppSurface=%p pSharedHandle=%p\n",
949 This
, type
, nine_D3DPOOL_to_str(Pool
), Width
, Height
,
950 d3dformat_to_string(Format
), MultiSample
, MultisampleQuality
,
951 Discard_or_Lockable
, ppSurface
, pSharedHandle
);
954 DBG("FIXME Used shared handle! This option isn't probably handled correctly!\n");
956 user_assert(Width
&& Height
, D3DERR_INVALIDCALL
);
957 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
959 templ
.target
= PIPE_TEXTURE_2D
;
960 templ
.format
= d3d9_to_pipe_format(Format
);
961 templ
.width0
= Width
;
962 templ
.height0
= Height
;
964 templ
.array_size
= 1;
965 templ
.last_level
= 0;
966 templ
.nr_samples
= (unsigned)MultiSample
;
967 templ
.usage
= PIPE_USAGE_DEFAULT
;
969 templ
.bind
= PIPE_BIND_SAMPLER_VIEW
; /* StretchRect */
971 case 0: templ
.bind
|= PIPE_BIND_RENDER_TARGET
; break;
972 case 1: templ
.bind
|= PIPE_BIND_DEPTH_STENCIL
; break;
978 desc
.Format
= Format
;
979 desc
.Type
= D3DRTYPE_SURFACE
;
982 desc
.MultiSampleType
= MultiSample
;
983 desc
.MultiSampleQuality
= MultisampleQuality
;
985 desc
.Height
= Height
;
987 case 0: desc
.Usage
= D3DUSAGE_RENDERTARGET
; break;
988 case 1: desc
.Usage
= D3DUSAGE_DEPTHSTENCIL
; break;
992 if (Pool
== D3DPOOL_DEFAULT
&& Format
!= D3DFMT_NULL
) {
993 /* resource_create doesn't return an error code, so check format here */
994 user_assert(CHECK_PIPE_RESOURCE_TEMPLATE(templ
), D3DERR_INVALIDCALL
);
995 resource
= screen
->resource_create(screen
, &templ
);
996 user_assert(resource
, D3DERR_OUTOFVIDEOMEMORY
);
997 if (Discard_or_Lockable
&& (desc
.Usage
& D3DUSAGE_RENDERTARGET
))
998 resource
->flags
|= NINE_RESOURCE_FLAG_LOCKABLE
;
1002 hr
= NineSurface9_new(This
, NULL
, resource
, NULL
, 0, 0, 0, &desc
, &surface
);
1003 pipe_resource_reference(&resource
, NULL
);
1006 *ppSurface
= (IDirect3DSurface9
*)surface
;
1011 NineDevice9_CreateRenderTarget( struct NineDevice9
*This
,
1015 D3DMULTISAMPLE_TYPE MultiSample
,
1016 DWORD MultisampleQuality
,
1018 IDirect3DSurface9
**ppSurface
,
1019 HANDLE
*pSharedHandle
)
1021 return create_zs_or_rt_surface(This
, 0, D3DPOOL_DEFAULT
,
1022 Width
, Height
, Format
,
1023 MultiSample
, MultisampleQuality
,
1024 Lockable
, ppSurface
, pSharedHandle
);
1028 NineDevice9_CreateDepthStencilSurface( struct NineDevice9
*This
,
1032 D3DMULTISAMPLE_TYPE MultiSample
,
1033 DWORD MultisampleQuality
,
1035 IDirect3DSurface9
**ppSurface
,
1036 HANDLE
*pSharedHandle
)
1038 return create_zs_or_rt_surface(This
, 1, D3DPOOL_DEFAULT
,
1039 Width
, Height
, Format
,
1040 MultiSample
, MultisampleQuality
,
1041 Discard
, ppSurface
, pSharedHandle
);
1045 NineDevice9_UpdateSurface( struct NineDevice9
*This
,
1046 IDirect3DSurface9
*pSourceSurface
,
1047 const RECT
*pSourceRect
,
1048 IDirect3DSurface9
*pDestinationSurface
,
1049 const POINT
*pDestPoint
)
1051 struct NineSurface9
*dst
= NineSurface9(pDestinationSurface
);
1052 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1054 DBG("This=%p pSourceSurface=%p pDestinationSurface=%p "
1055 "pSourceRect=%p pDestPoint=%p\n", This
,
1056 pSourceSurface
, pDestinationSurface
, pSourceRect
, pDestPoint
);
1058 DBG("pSourceRect = (%u,%u)-(%u,%u)\n",
1059 pSourceRect
->left
, pSourceRect
->top
,
1060 pSourceRect
->right
, pSourceRect
->bottom
);
1062 DBG("pDestPoint = (%u,%u)\n", pDestPoint
->x
, pDestPoint
->y
);
1064 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1065 user_assert(src
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1067 user_assert(dst
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1068 user_assert(src
->desc
.MultiSampleType
== D3DMULTISAMPLE_NONE
, D3DERR_INVALIDCALL
);
1070 return NineSurface9_CopySurface(dst
, src
, pDestPoint
, pSourceRect
);
1074 NineDevice9_UpdateTexture( struct NineDevice9
*This
,
1075 IDirect3DBaseTexture9
*pSourceTexture
,
1076 IDirect3DBaseTexture9
*pDestinationTexture
)
1078 struct NineBaseTexture9
*dstb
= NineBaseTexture9(pDestinationTexture
);
1079 struct NineBaseTexture9
*srcb
= NineBaseTexture9(pSourceTexture
);
1081 unsigned last_level
= dstb
->base
.info
.last_level
;
1083 DBG("This=%p pSourceTexture=%p pDestinationTexture=%p\n", This
,
1084 pSourceTexture
, pDestinationTexture
);
1086 user_assert(pSourceTexture
!= pDestinationTexture
, D3DERR_INVALIDCALL
);
1088 user_assert(dstb
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1089 user_assert(srcb
->base
.pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1091 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
) {
1092 /* Only the first level is updated, the others regenerated. */
1095 user_assert(!(srcb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
), D3DERR_INVALIDCALL
);
1098 user_assert(dstb
->base
.type
== srcb
->base
.type
, D3DERR_INVALIDCALL
);
1100 /* TODO: We can restrict the update to the dirty portions of the source.
1101 * Yes, this seems silly, but it's what MSDN says ...
1104 /* Find src level that matches dst level 0: */
1105 user_assert(srcb
->base
.info
.width0
>= dstb
->base
.info
.width0
&&
1106 srcb
->base
.info
.height0
>= dstb
->base
.info
.height0
&&
1107 srcb
->base
.info
.depth0
>= dstb
->base
.info
.depth0
,
1108 D3DERR_INVALIDCALL
);
1109 for (m
= 0; m
<= srcb
->base
.info
.last_level
; ++m
) {
1110 unsigned w
= u_minify(srcb
->base
.info
.width0
, m
);
1111 unsigned h
= u_minify(srcb
->base
.info
.height0
, m
);
1112 unsigned d
= u_minify(srcb
->base
.info
.depth0
, m
);
1114 if (w
== dstb
->base
.info
.width0
&&
1115 h
== dstb
->base
.info
.height0
&&
1116 d
== dstb
->base
.info
.depth0
)
1119 user_assert(m
<= srcb
->base
.info
.last_level
, D3DERR_INVALIDCALL
);
1121 last_level
= MIN2(last_level
, srcb
->base
.info
.last_level
- m
);
1123 if (dstb
->base
.type
== D3DRTYPE_TEXTURE
) {
1124 struct NineTexture9
*dst
= NineTexture9(dstb
);
1125 struct NineTexture9
*src
= NineTexture9(srcb
);
1127 for (l
= 0; l
<= last_level
; ++l
, ++m
)
1128 NineSurface9_CopySurface(dst
->surfaces
[l
],
1129 src
->surfaces
[m
], NULL
, NULL
);
1131 if (dstb
->base
.type
== D3DRTYPE_CUBETEXTURE
) {
1132 struct NineCubeTexture9
*dst
= NineCubeTexture9(dstb
);
1133 struct NineCubeTexture9
*src
= NineCubeTexture9(srcb
);
1136 /* GPUs usually have them stored as arrays of mip-mapped 2D textures. */
1137 for (z
= 0; z
< 6; ++z
) {
1138 for (l
= 0; l
<= last_level
; ++l
, ++m
) {
1139 NineSurface9_CopySurface(dst
->surfaces
[l
* 6 + z
],
1140 src
->surfaces
[m
* 6 + z
], NULL
, NULL
);
1145 if (dstb
->base
.type
== D3DRTYPE_VOLUMETEXTURE
) {
1146 struct NineVolumeTexture9
*dst
= NineVolumeTexture9(dstb
);
1147 struct NineVolumeTexture9
*src
= NineVolumeTexture9(srcb
);
1149 for (l
= 0; l
<= last_level
; ++l
, ++m
)
1150 NineVolume9_CopyVolume(dst
->volumes
[l
],
1151 src
->volumes
[m
], 0, 0, 0, NULL
);
1153 assert(!"invalid texture type");
1156 if (dstb
->base
.usage
& D3DUSAGE_AUTOGENMIPMAP
)
1157 NineBaseTexture9_GenerateMipSubLevels(dstb
);
1163 NineDevice9_GetRenderTargetData( struct NineDevice9
*This
,
1164 IDirect3DSurface9
*pRenderTarget
,
1165 IDirect3DSurface9
*pDestSurface
)
1167 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1168 struct NineSurface9
*src
= NineSurface9(pRenderTarget
);
1170 DBG("This=%p pRenderTarget=%p pDestSurface=%p\n",
1171 This
, pRenderTarget
, pDestSurface
);
1173 user_assert(dst
->desc
.Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1174 user_assert(src
->desc
.Pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1176 user_assert(dst
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1177 user_assert(src
->desc
.MultiSampleType
< 2, D3DERR_INVALIDCALL
);
1179 return NineSurface9_CopySurface(dst
, src
, NULL
, NULL
);
1183 NineDevice9_GetFrontBufferData( struct NineDevice9
*This
,
1185 IDirect3DSurface9
*pDestSurface
)
1187 DBG("This=%p iSwapChain=%u pDestSurface=%p\n", This
,
1188 iSwapChain
, pDestSurface
);
1190 user_assert(pDestSurface
!= NULL
, D3DERR_INVALIDCALL
);
1191 user_assert(iSwapChain
< This
->nswapchains
, D3DERR_INVALIDCALL
);
1193 return NineSwapChain9_GetFrontBufferData(This
->swapchains
[iSwapChain
],
1198 NineDevice9_StretchRect( struct NineDevice9
*This
,
1199 IDirect3DSurface9
*pSourceSurface
,
1200 const RECT
*pSourceRect
,
1201 IDirect3DSurface9
*pDestSurface
,
1202 const RECT
*pDestRect
,
1203 D3DTEXTUREFILTERTYPE Filter
)
1205 struct pipe_screen
*screen
= This
->screen
;
1206 struct pipe_context
*pipe
= This
->pipe
;
1207 struct NineSurface9
*dst
= NineSurface9(pDestSurface
);
1208 struct NineSurface9
*src
= NineSurface9(pSourceSurface
);
1209 struct pipe_resource
*dst_res
= NineSurface9_GetResource(dst
);
1210 struct pipe_resource
*src_res
= NineSurface9_GetResource(src
);
1211 const boolean zs
= util_format_is_depth_or_stencil(dst_res
->format
);
1212 struct pipe_blit_info blit
;
1213 boolean scaled
, clamped
, ms
, flip_x
= FALSE
, flip_y
= FALSE
;
1215 DBG("This=%p pSourceSurface=%p pSourceRect=%p pDestSurface=%p "
1216 "pDestRect=%p Filter=%u\n",
1217 This
, pSourceSurface
, pSourceRect
, pDestSurface
, pDestRect
, Filter
);
1219 DBG("pSourceRect=(%u,%u)-(%u,%u)\n",
1220 pSourceRect
->left
, pSourceRect
->top
,
1221 pSourceRect
->right
, pSourceRect
->bottom
);
1223 DBG("pDestRect=(%u,%u)-(%u,%u)\n", pDestRect
->left
, pDestRect
->top
,
1224 pDestRect
->right
, pDestRect
->bottom
);
1226 user_assert(!zs
|| !This
->in_scene
, D3DERR_INVALIDCALL
);
1227 user_assert(!zs
|| !pSourceRect
||
1228 (pSourceRect
->left
== 0 &&
1229 pSourceRect
->top
== 0 &&
1230 pSourceRect
->right
== src
->desc
.Width
&&
1231 pSourceRect
->bottom
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1232 user_assert(!zs
|| !pDestRect
||
1233 (pDestRect
->left
== 0 &&
1234 pDestRect
->top
== 0 &&
1235 pDestRect
->right
== dst
->desc
.Width
&&
1236 pDestRect
->bottom
== dst
->desc
.Height
), D3DERR_INVALIDCALL
);
1238 (dst
->desc
.Width
== src
->desc
.Width
&&
1239 dst
->desc
.Height
== src
->desc
.Height
), D3DERR_INVALIDCALL
);
1240 user_assert(zs
|| !util_format_is_depth_or_stencil(src_res
->format
),
1241 D3DERR_INVALIDCALL
);
1242 user_assert(!zs
|| dst
->desc
.Format
== src
->desc
.Format
,
1243 D3DERR_INVALIDCALL
);
1244 user_assert(screen
->is_format_supported(screen
, src_res
->format
,
1246 src_res
->nr_samples
,
1247 PIPE_BIND_SAMPLER_VIEW
),
1248 D3DERR_INVALIDCALL
);
1249 user_assert(dst
->base
.pool
== D3DPOOL_DEFAULT
&&
1250 src
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1252 /* We might want to permit these, but wine thinks we shouldn't. */
1253 user_assert(!pDestRect
||
1254 (pDestRect
->left
<= pDestRect
->right
&&
1255 pDestRect
->top
<= pDestRect
->bottom
), D3DERR_INVALIDCALL
);
1256 user_assert(!pSourceRect
||
1257 (pSourceRect
->left
<= pSourceRect
->right
&&
1258 pSourceRect
->top
<= pSourceRect
->bottom
), D3DERR_INVALIDCALL
);
1260 blit
.dst
.resource
= dst_res
;
1261 blit
.dst
.level
= dst
->level
;
1262 blit
.dst
.box
.z
= dst
->layer
;
1263 blit
.dst
.box
.depth
= 1;
1264 blit
.dst
.format
= dst_res
->format
;
1266 flip_x
= pDestRect
->left
> pDestRect
->right
;
1268 blit
.dst
.box
.x
= pDestRect
->right
;
1269 blit
.dst
.box
.width
= pDestRect
->left
- pDestRect
->right
;
1271 blit
.dst
.box
.x
= pDestRect
->left
;
1272 blit
.dst
.box
.width
= pDestRect
->right
- pDestRect
->left
;
1274 flip_y
= pDestRect
->top
> pDestRect
->bottom
;
1276 blit
.dst
.box
.y
= pDestRect
->bottom
;
1277 blit
.dst
.box
.height
= pDestRect
->top
- pDestRect
->bottom
;
1279 blit
.dst
.box
.y
= pDestRect
->top
;
1280 blit
.dst
.box
.height
= pDestRect
->bottom
- pDestRect
->top
;
1285 blit
.dst
.box
.width
= dst
->desc
.Width
;
1286 blit
.dst
.box
.height
= dst
->desc
.Height
;
1288 blit
.src
.resource
= src_res
;
1289 blit
.src
.level
= src
->level
;
1290 blit
.src
.box
.z
= src
->layer
;
1291 blit
.src
.box
.depth
= 1;
1292 blit
.src
.format
= src_res
->format
;
1294 if (flip_x
^ (pSourceRect
->left
> pSourceRect
->right
)) {
1295 blit
.src
.box
.x
= pSourceRect
->right
;
1296 blit
.src
.box
.width
= pSourceRect
->left
- pSourceRect
->right
;
1298 blit
.src
.box
.x
= pSourceRect
->left
;
1299 blit
.src
.box
.width
= pSourceRect
->right
- pSourceRect
->left
;
1301 if (flip_y
^ (pSourceRect
->top
> pSourceRect
->bottom
)) {
1302 blit
.src
.box
.y
= pSourceRect
->bottom
;
1303 blit
.src
.box
.height
= pSourceRect
->top
- pSourceRect
->bottom
;
1305 blit
.src
.box
.y
= pSourceRect
->top
;
1306 blit
.src
.box
.height
= pSourceRect
->bottom
- pSourceRect
->top
;
1309 blit
.src
.box
.x
= flip_x
? src
->desc
.Width
: 0;
1310 blit
.src
.box
.y
= flip_y
? src
->desc
.Height
: 0;
1311 blit
.src
.box
.width
= flip_x
? -src
->desc
.Width
: src
->desc
.Width
;
1312 blit
.src
.box
.height
= flip_y
? -src
->desc
.Height
: src
->desc
.Height
;
1314 blit
.mask
= zs
? PIPE_MASK_ZS
: PIPE_MASK_RGBA
;
1315 blit
.filter
= Filter
== D3DTEXF_LINEAR
?
1316 PIPE_TEX_FILTER_LINEAR
: PIPE_TEX_FILTER_NEAREST
;
1317 blit
.scissor_enable
= FALSE
;
1319 /* If both of a src and dst dimension are negative, flip them. */
1320 if (blit
.dst
.box
.width
< 0 && blit
.src
.box
.width
< 0) {
1321 blit
.dst
.box
.width
= -blit
.dst
.box
.width
;
1322 blit
.src
.box
.width
= -blit
.src
.box
.width
;
1324 if (blit
.dst
.box
.height
< 0 && blit
.src
.box
.height
< 0) {
1325 blit
.dst
.box
.height
= -blit
.dst
.box
.height
;
1326 blit
.src
.box
.height
= -blit
.src
.box
.height
;
1329 blit
.dst
.box
.width
!= blit
.src
.box
.width
||
1330 blit
.dst
.box
.height
!= blit
.src
.box
.height
;
1332 user_assert(!scaled
|| dst
!= src
, D3DERR_INVALIDCALL
);
1333 user_assert(!scaled
||
1334 !NineSurface9_IsOffscreenPlain(dst
) ||
1335 NineSurface9_IsOffscreenPlain(src
), D3DERR_INVALIDCALL
);
1336 user_assert(!scaled
||
1337 (!util_format_is_compressed(dst
->base
.info
.format
) &&
1338 !util_format_is_compressed(src
->base
.info
.format
)),
1339 D3DERR_INVALIDCALL
);
1341 user_warn(src
== dst
&&
1342 u_box_test_intersection_2d(&blit
.src
.box
, &blit
.dst
.box
));
1344 /* Check for clipping/clamping: */
1346 struct pipe_box box
;
1349 xy
= u_box_clip_2d(&box
, &blit
.dst
.box
,
1350 dst
->desc
.Width
, dst
->desc
.Height
);
1354 xy
= u_box_clip_2d(&box
, &blit
.src
.box
,
1355 src
->desc
.Width
, src
->desc
.Height
);
1359 ms
= (dst
->desc
.MultiSampleType
| 1) != (src
->desc
.MultiSampleType
| 1);
1361 if (clamped
|| scaled
|| (blit
.dst
.format
!= blit
.src
.format
) || ms
) {
1362 DBG("using pipe->blit()\n");
1363 /* TODO: software scaling */
1364 user_assert(screen
->is_format_supported(screen
, dst_res
->format
,
1366 dst_res
->nr_samples
,
1367 zs
? PIPE_BIND_DEPTH_STENCIL
:
1368 PIPE_BIND_RENDER_TARGET
),
1369 D3DERR_INVALIDCALL
);
1371 pipe
->blit(pipe
, &blit
);
1373 assert(blit
.dst
.box
.x
>= 0 && blit
.dst
.box
.y
>= 0 &&
1374 blit
.src
.box
.x
>= 0 && blit
.src
.box
.y
>= 0 &&
1375 blit
.dst
.box
.x
+ blit
.dst
.box
.width
<= dst
->desc
.Width
&&
1376 blit
.src
.box
.x
+ blit
.src
.box
.width
<= src
->desc
.Width
&&
1377 blit
.dst
.box
.y
+ blit
.dst
.box
.height
<= dst
->desc
.Height
&&
1378 blit
.src
.box
.y
+ blit
.src
.box
.height
<= src
->desc
.Height
);
1379 /* Or drivers might crash ... */
1380 DBG("Using resource_copy_region.\n");
1381 pipe
->resource_copy_region(pipe
,
1382 blit
.dst
.resource
, blit
.dst
.level
,
1383 blit
.dst
.box
.x
, blit
.dst
.box
.y
, blit
.dst
.box
.z
,
1384 blit
.src
.resource
, blit
.src
.level
,
1392 NineDevice9_ColorFill( struct NineDevice9
*This
,
1393 IDirect3DSurface9
*pSurface
,
1397 struct pipe_context
*pipe
= This
->pipe
;
1398 struct NineSurface9
*surf
= NineSurface9(pSurface
);
1399 struct pipe_surface
*psurf
;
1400 unsigned x
, y
, w
, h
;
1401 union pipe_color_union rgba
;
1404 DBG("This=%p pSurface=%p pRect=%p color=%08x\n", This
,
1405 pSurface
, pRect
, color
);
1407 DBG("pRect=(%u,%u)-(%u,%u)\n", pRect
->left
, pRect
->top
,
1408 pRect
->right
, pRect
->bottom
);
1410 user_assert(surf
->base
.pool
== D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
);
1412 user_assert((surf
->base
.usage
& D3DUSAGE_RENDERTARGET
) ||
1413 NineSurface9_IsOffscreenPlain(surf
), D3DERR_INVALIDCALL
);
1418 w
= pRect
->right
- pRect
->left
;
1419 h
= pRect
->bottom
- pRect
->top
;
1423 w
= surf
->desc
.Width
;
1424 h
= surf
->desc
.Height
;
1426 d3dcolor_to_pipe_color_union(&rgba
, color
);
1429 !This
->screen
->is_format_supported(This
->screen
, surf
->base
.info
.format
,
1430 surf
->base
.info
.target
,
1431 surf
->base
.info
.nr_samples
,
1432 PIPE_BIND_RENDER_TARGET
);
1434 psurf
= NineSurface9_GetSurface(surf
, 0);
1440 pipe
->clear_render_target(pipe
, psurf
, &rgba
, x
, y
, w
, h
);
1442 D3DLOCKED_RECT lock
;
1443 union util_color uc
;
1445 /* XXX: lock pRect and fix util_fill_rect */
1446 hr
= NineSurface9_LockRect(surf
, &lock
, NULL
, 0);
1449 util_pack_color_ub(color
>> 16, color
>> 8, color
>> 0, color
>> 24,
1450 surf
->base
.info
.format
, &uc
);
1451 util_fill_rect(lock
.pBits
, surf
->base
.info
.format
,lock
.Pitch
,
1453 NineSurface9_UnlockRect(surf
);
1460 NineDevice9_CreateOffscreenPlainSurface( struct NineDevice9
*This
,
1465 IDirect3DSurface9
**ppSurface
,
1466 HANDLE
*pSharedHandle
)
1470 DBG("This=%p Width=%u Height=%u Format=%s(0x%x) Pool=%u "
1471 "ppSurface=%p pSharedHandle=%p\n", This
,
1472 Width
, Height
, d3dformat_to_string(Format
), Format
, Pool
,
1473 ppSurface
, pSharedHandle
);
1475 user_assert(!pSharedHandle
|| Pool
== D3DPOOL_DEFAULT
1476 || Pool
== D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
1477 user_assert(Pool
!= D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
);
1479 /* Can be used with StretchRect and ColorFill. It's also always lockable.
1481 hr
= create_zs_or_rt_surface(This
, 2, Pool
, Width
, Height
,
1483 D3DMULTISAMPLE_NONE
, 0,
1485 ppSurface
, pSharedHandle
);
1487 DBG("Failed to create surface.\n");
1492 NineDevice9_SetRenderTarget( struct NineDevice9
*This
,
1493 DWORD RenderTargetIndex
,
1494 IDirect3DSurface9
*pRenderTarget
)
1496 struct NineSurface9
*rt
= NineSurface9(pRenderTarget
);
1497 const unsigned i
= RenderTargetIndex
;
1499 DBG("This=%p RenderTargetIndex=%u pRenderTarget=%p\n", This
,
1500 RenderTargetIndex
, pRenderTarget
);
1502 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1503 user_assert(i
!= 0 || pRenderTarget
, D3DERR_INVALIDCALL
);
1504 user_assert(!pRenderTarget
||
1505 rt
->desc
.Usage
& D3DUSAGE_RENDERTARGET
, D3DERR_INVALIDCALL
);
1508 This
->state
.viewport
.X
= 0;
1509 This
->state
.viewport
.Y
= 0;
1510 This
->state
.viewport
.Width
= rt
->desc
.Width
;
1511 This
->state
.viewport
.Height
= rt
->desc
.Height
;
1512 This
->state
.viewport
.MinZ
= 0.0f
;
1513 This
->state
.viewport
.MaxZ
= 1.0f
;
1515 This
->state
.scissor
.minx
= 0;
1516 This
->state
.scissor
.miny
= 0;
1517 This
->state
.scissor
.maxx
= rt
->desc
.Width
;
1518 This
->state
.scissor
.maxy
= rt
->desc
.Height
;
1520 This
->state
.changed
.group
|= NINE_STATE_VIEWPORT
| NINE_STATE_SCISSOR
;
1523 if (This
->state
.rt
[i
] != NineSurface9(pRenderTarget
)) {
1524 nine_bind(&This
->state
.rt
[i
], pRenderTarget
);
1525 This
->state
.changed
.group
|= NINE_STATE_FB
;
1531 NineDevice9_GetRenderTarget( struct NineDevice9
*This
,
1532 DWORD RenderTargetIndex
,
1533 IDirect3DSurface9
**ppRenderTarget
)
1535 const unsigned i
= RenderTargetIndex
;
1537 user_assert(i
< This
->caps
.NumSimultaneousRTs
, D3DERR_INVALIDCALL
);
1538 user_assert(ppRenderTarget
, D3DERR_INVALIDCALL
);
1540 *ppRenderTarget
= (IDirect3DSurface9
*)This
->state
.rt
[i
];
1541 if (!This
->state
.rt
[i
])
1542 return D3DERR_NOTFOUND
;
1544 NineUnknown_AddRef(NineUnknown(This
->state
.rt
[i
]));
1549 NineDevice9_SetDepthStencilSurface( struct NineDevice9
*This
,
1550 IDirect3DSurface9
*pNewZStencil
)
1552 DBG("This=%p pNewZStencil=%p\n", This
, pNewZStencil
);
1554 if (This
->state
.ds
!= NineSurface9(pNewZStencil
)) {
1555 nine_bind(&This
->state
.ds
, pNewZStencil
);
1556 This
->state
.changed
.group
|= NINE_STATE_FB
;
1562 NineDevice9_GetDepthStencilSurface( struct NineDevice9
*This
,
1563 IDirect3DSurface9
**ppZStencilSurface
)
1565 user_assert(ppZStencilSurface
, D3DERR_INVALIDCALL
);
1567 *ppZStencilSurface
= (IDirect3DSurface9
*)This
->state
.ds
;
1568 if (!This
->state
.ds
)
1569 return D3DERR_NOTFOUND
;
1571 NineUnknown_AddRef(NineUnknown(This
->state
.ds
));
1576 NineDevice9_BeginScene( struct NineDevice9
*This
)
1578 DBG("This=%p\n", This
);
1579 user_assert(!This
->in_scene
, D3DERR_INVALIDCALL
);
1580 This
->in_scene
= TRUE
;
1581 /* Do we want to do anything else here ? */
1586 NineDevice9_EndScene( struct NineDevice9
*This
)
1588 DBG("This=%p\n", This
);
1589 user_assert(This
->in_scene
, D3DERR_INVALIDCALL
);
1590 This
->in_scene
= FALSE
;
1595 NineDevice9_Clear( struct NineDevice9
*This
,
1597 const D3DRECT
*pRects
,
1603 struct pipe_context
*pipe
= This
->pipe
;
1604 struct NineSurface9
*zsbuf
= This
->state
.ds
;
1607 union pipe_color_union rgba
;
1610 DBG("This=%p Count=%u pRects=%p Flags=%x Color=%08x Z=%f Stencil=%x\n",
1611 This
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1613 user_assert(This
->state
.ds
|| !(Flags
& NINED3DCLEAR_DEPTHSTENCIL
),
1614 D3DERR_INVALIDCALL
);
1615 user_assert(!(Flags
& D3DCLEAR_STENCIL
) ||
1617 util_format_is_depth_and_stencil(zsbuf
->base
.info
.format
)),
1618 D3DERR_INVALIDCALL
);
1620 user_assert((Count
&& pRects
) || (!Count
&& !pRects
), D3DERR_INVALIDCALL
);
1622 user_warn((pRects
&& !Count
) || (!pRects
&& Count
));
1623 if (pRects
&& !Count
)
1629 if (Flags
& D3DCLEAR_TARGET
) bufs
|= PIPE_CLEAR_COLOR
;
1630 if (Flags
& D3DCLEAR_ZBUFFER
) bufs
|= PIPE_CLEAR_DEPTH
;
1631 if (Flags
& D3DCLEAR_STENCIL
) bufs
|= PIPE_CLEAR_STENCIL
;
1634 d3dcolor_to_pipe_color_union(&rgba
, Color
);
1636 nine_update_state(This
, NINE_STATE_FB
);
1638 rect
.x1
= This
->state
.viewport
.X
;
1639 rect
.y1
= This
->state
.viewport
.Y
;
1640 rect
.x2
= This
->state
.viewport
.Width
+ rect
.x1
;
1641 rect
.y2
= This
->state
.viewport
.Height
+ rect
.y1
;
1643 /* Both rectangles apply, which is weird, but that's D3D9. */
1644 if (This
->state
.rs
[D3DRS_SCISSORTESTENABLE
]) {
1645 rect
.x1
= MAX2(rect
.x1
, This
->state
.scissor
.minx
);
1646 rect
.y1
= MAX2(rect
.y1
, This
->state
.scissor
.miny
);
1647 rect
.x2
= MIN2(rect
.x2
, This
->state
.scissor
.maxx
);
1648 rect
.y2
= MIN2(rect
.y2
, This
->state
.scissor
.maxy
);
1652 /* Maybe apps like to specify a large rect ? */
1653 if (pRects
[0].x1
<= rect
.x1
&& pRects
[0].x2
>= rect
.x2
&&
1654 pRects
[0].y1
<= rect
.y1
&& pRects
[0].y2
>= rect
.y2
) {
1655 DBG("First rect covers viewport.\n");
1661 if (rect
.x1
>= This
->state
.fb
.width
|| rect
.y1
>= This
->state
.fb
.height
)
1664 rect
.x1
== 0 && rect
.x2
>= This
->state
.fb
.width
&&
1665 rect
.y1
== 0 && rect
.y2
>= This
->state
.fb
.height
) {
1666 /* fast path, clears everything at once */
1668 pipe
->clear(pipe
, bufs
, &rgba
, Z
, Stencil
);
1671 rect
.x2
= MIN2(rect
.x2
, This
->state
.fb
.width
);
1672 rect
.y2
= MIN2(rect
.y2
, This
->state
.fb
.height
);
1679 for (i
= 0; (i
< This
->state
.fb
.nr_cbufs
); ++i
) {
1680 if (!This
->state
.fb
.cbufs
[i
] || !(Flags
& D3DCLEAR_TARGET
))
1681 continue; /* save space, compiler should hoist this */
1682 for (r
= 0; r
< Count
; ++r
) {
1683 /* Don't trust users to pass these in the right order. */
1684 unsigned x1
= MIN2(pRects
[r
].x1
, pRects
[r
].x2
);
1685 unsigned y1
= MIN2(pRects
[r
].y1
, pRects
[r
].y2
);
1686 unsigned x2
= MAX2(pRects
[r
].x1
, pRects
[r
].x2
);
1687 unsigned y2
= MAX2(pRects
[r
].y1
, pRects
[r
].y2
);
1689 /* Drop negative rectangles (like wine expects). */
1690 if (pRects
[r
].x1
> pRects
[r
].x2
) continue;
1691 if (pRects
[r
].y1
> pRects
[r
].y2
) continue;
1694 x1
= MAX2(x1
, rect
.x1
);
1695 y1
= MAX2(y1
, rect
.y1
);
1696 x2
= MIN2(x2
, rect
.x2
);
1697 y2
= MIN2(y2
, rect
.y2
);
1699 DBG("Clearing (%u..%u)x(%u..%u)\n", x1
, x2
, y1
, y2
);
1700 pipe
->clear_render_target(pipe
, This
->state
.fb
.cbufs
[i
], &rgba
,
1701 x1
, y1
, x2
- x1
, y2
- y1
);
1704 if (!(Flags
& NINED3DCLEAR_DEPTHSTENCIL
))
1707 bufs
&= PIPE_CLEAR_DEPTHSTENCIL
;
1709 for (r
= 0; r
< Count
; ++r
) {
1710 unsigned x1
= MIN2(pRects
[r
].x1
, pRects
[r
].x2
);
1711 unsigned y1
= MIN2(pRects
[r
].y1
, pRects
[r
].y2
);
1712 unsigned x2
= MAX2(pRects
[r
].x1
, pRects
[r
].x2
);
1713 unsigned y2
= MAX2(pRects
[r
].y1
, pRects
[r
].y2
);
1715 /* Drop negative rectangles. */
1716 if (pRects
[r
].x1
> pRects
[r
].x2
) continue;
1717 if (pRects
[r
].y1
> pRects
[r
].y2
) continue;
1720 x1
= MIN2(x1
, rect
.x1
);
1721 y1
= MIN2(y1
, rect
.y1
);
1722 x2
= MIN2(x2
, rect
.x2
);
1723 y2
= MIN2(y2
, rect
.y2
);
1725 pipe
->clear_depth_stencil(pipe
, This
->state
.fb
.zsbuf
, bufs
, Z
, Stencil
,
1726 x1
, y1
, x2
- x1
, y2
- y1
);
1732 NineDevice9_SetTransform( struct NineDevice9
*This
,
1733 D3DTRANSFORMSTATETYPE State
,
1734 const D3DMATRIX
*pMatrix
)
1736 struct nine_state
*state
= This
->update
;
1737 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
1739 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
1741 user_assert(M
, D3DERR_INVALIDCALL
);
1744 state
->ff
.changed
.transform
[State
/ 32] |= 1 << (State
% 32);
1745 state
->changed
.group
|= NINE_STATE_FF
;
1751 NineDevice9_GetTransform( struct NineDevice9
*This
,
1752 D3DTRANSFORMSTATETYPE State
,
1753 D3DMATRIX
*pMatrix
)
1755 D3DMATRIX
*M
= nine_state_access_transform(&This
->state
, State
, FALSE
);
1756 user_assert(M
, D3DERR_INVALIDCALL
);
1762 NineDevice9_MultiplyTransform( struct NineDevice9
*This
,
1763 D3DTRANSFORMSTATETYPE State
,
1764 const D3DMATRIX
*pMatrix
)
1766 struct nine_state
*state
= This
->update
;
1768 D3DMATRIX
*M
= nine_state_access_transform(state
, State
, TRUE
);
1770 DBG("This=%p State=%d pMatrix=%p\n", This
, State
, pMatrix
);
1772 user_assert(M
, D3DERR_INVALIDCALL
);
1774 nine_d3d_matrix_matrix_mul(&T
, pMatrix
, M
);
1775 return NineDevice9_SetTransform(This
, State
, &T
);
1779 NineDevice9_SetViewport( struct NineDevice9
*This
,
1780 const D3DVIEWPORT9
*pViewport
)
1782 struct nine_state
*state
= This
->update
;
1784 DBG("X=%u Y=%u W=%u H=%u MinZ=%f MaxZ=%f\n",
1785 pViewport
->X
, pViewport
->Y
, pViewport
->Width
, pViewport
->Height
,
1786 pViewport
->MinZ
, pViewport
->MaxZ
);
1788 state
->viewport
= *pViewport
;
1789 state
->changed
.group
|= NINE_STATE_VIEWPORT
;
1795 NineDevice9_GetViewport( struct NineDevice9
*This
,
1796 D3DVIEWPORT9
*pViewport
)
1798 *pViewport
= This
->state
.viewport
;
1803 NineDevice9_SetMaterial( struct NineDevice9
*This
,
1804 const D3DMATERIAL9
*pMaterial
)
1806 struct nine_state
*state
= This
->update
;
1808 DBG("This=%p pMaterial=%p\n", This
, pMaterial
);
1810 nine_dump_D3DMATERIAL9(DBG_FF
, pMaterial
);
1812 user_assert(pMaterial
, E_POINTER
);
1814 state
->ff
.material
= *pMaterial
;
1815 state
->changed
.group
|= NINE_STATE_FF_MATERIAL
;
1821 NineDevice9_GetMaterial( struct NineDevice9
*This
,
1822 D3DMATERIAL9
*pMaterial
)
1824 user_assert(pMaterial
, E_POINTER
);
1825 *pMaterial
= This
->state
.ff
.material
;
1830 NineDevice9_SetLight( struct NineDevice9
*This
,
1832 const D3DLIGHT9
*pLight
)
1834 struct nine_state
*state
= This
->update
;
1836 DBG("This=%p Index=%u pLight=%p\n", This
, Index
, pLight
);
1838 nine_dump_D3DLIGHT9(DBG_FF
, pLight
);
1840 user_assert(pLight
, D3DERR_INVALIDCALL
);
1841 user_assert(pLight
->Type
< NINED3DLIGHT_INVALID
, D3DERR_INVALIDCALL
);
1843 user_assert(Index
< NINE_MAX_LIGHTS
, D3DERR_INVALIDCALL
); /* sanity */
1845 if (Index
>= state
->ff
.num_lights
) {
1846 unsigned n
= state
->ff
.num_lights
;
1847 unsigned N
= Index
+ 1;
1849 state
->ff
.light
= REALLOC(state
->ff
.light
, n
* sizeof(D3DLIGHT9
),
1850 N
* sizeof(D3DLIGHT9
));
1851 if (!state
->ff
.light
)
1852 return E_OUTOFMEMORY
;
1853 state
->ff
.num_lights
= N
;
1855 for (; n
< Index
; ++n
)
1856 state
->ff
.light
[n
].Type
= (D3DLIGHTTYPE
)NINED3DLIGHT_INVALID
;
1858 state
->ff
.light
[Index
] = *pLight
;
1860 if (pLight
->Type
== D3DLIGHT_SPOT
&& pLight
->Theta
>= pLight
->Phi
) {
1861 DBG("Warning: clamping D3DLIGHT9.Theta\n");
1862 state
->ff
.light
[Index
].Theta
= state
->ff
.light
[Index
].Phi
;
1864 if (pLight
->Type
!= D3DLIGHT_DIRECTIONAL
&&
1865 pLight
->Attenuation0
== 0.0f
&&
1866 pLight
->Attenuation1
== 0.0f
&&
1867 pLight
->Attenuation2
== 0.0f
) {
1868 DBG("Warning: all D3DLIGHT9.Attenuation[i] are 0\n");
1871 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
1877 NineDevice9_GetLight( struct NineDevice9
*This
,
1881 const struct nine_state
*state
= &This
->state
;
1883 user_assert(pLight
, D3DERR_INVALIDCALL
);
1884 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
1885 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
1886 D3DERR_INVALIDCALL
);
1888 *pLight
= state
->ff
.light
[Index
];
1894 NineDevice9_LightEnable( struct NineDevice9
*This
,
1898 struct nine_state
*state
= This
->update
;
1901 DBG("This=%p Index=%u Enable=%i\n", This
, Index
, Enable
);
1903 if (Index
>= state
->ff
.num_lights
||
1904 state
->ff
.light
[Index
].Type
== NINED3DLIGHT_INVALID
) {
1905 /* This should create a default light. */
1907 memset(&light
, 0, sizeof(light
));
1908 light
.Type
= D3DLIGHT_DIRECTIONAL
;
1909 light
.Diffuse
.r
= 1.0f
;
1910 light
.Diffuse
.g
= 1.0f
;
1911 light
.Diffuse
.b
= 1.0f
;
1912 light
.Direction
.z
= 1.0f
;
1913 NineDevice9_SetLight(This
, Index
, &light
);
1915 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
1917 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
) {
1918 if (state
->ff
.active_light
[i
] == Index
)
1923 if (i
< state
->ff
.num_lights_active
)
1925 /* XXX wine thinks this should still succeed:
1927 user_assert(i
< NINE_MAX_LIGHTS_ACTIVE
, D3DERR_INVALIDCALL
);
1929 state
->ff
.active_light
[i
] = Index
;
1930 state
->ff
.num_lights_active
++;
1932 if (i
== state
->ff
.num_lights_active
)
1934 --state
->ff
.num_lights_active
;
1935 for (; i
< state
->ff
.num_lights_active
; ++i
)
1936 state
->ff
.active_light
[i
] = state
->ff
.active_light
[i
+ 1];
1938 state
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
1944 NineDevice9_GetLightEnable( struct NineDevice9
*This
,
1948 const struct nine_state
*state
= &This
->state
;
1951 user_assert(Index
< state
->ff
.num_lights
, D3DERR_INVALIDCALL
);
1952 user_assert(state
->ff
.light
[Index
].Type
< NINED3DLIGHT_INVALID
,
1953 D3DERR_INVALIDCALL
);
1955 for (i
= 0; i
< state
->ff
.num_lights_active
; ++i
)
1956 if (state
->ff
.active_light
[i
] == Index
)
1958 *pEnable
= i
!= state
->ff
.num_lights_active
;
1963 NineDevice9_SetClipPlane( struct NineDevice9
*This
,
1965 const float *pPlane
)
1967 struct nine_state
*state
= This
->update
;
1969 DBG("This=%p Index=%u pPlane=%p(%f %f %f %f)\n", This
, Index
, pPlane
,
1970 pPlane
? pPlane
[0] : 0.0f
, pPlane
? pPlane
[1] : 0.0f
,
1971 pPlane
? pPlane
[2] : 0.0f
, pPlane
? pPlane
[3] : 0.0f
);
1973 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
1975 memcpy(&state
->clip
.ucp
[Index
][0], pPlane
, sizeof(state
->clip
.ucp
[0]));
1976 state
->changed
.ucp
|= 1 << Index
;
1982 NineDevice9_GetClipPlane( struct NineDevice9
*This
,
1986 const struct nine_state
*state
= &This
->state
;
1988 user_assert(Index
< PIPE_MAX_CLIP_PLANES
, D3DERR_INVALIDCALL
);
1990 memcpy(pPlane
, &state
->clip
.ucp
[Index
][0], sizeof(state
->clip
.ucp
[0]));
1995 NineDevice9_SetRenderState( struct NineDevice9
*This
,
1996 D3DRENDERSTATETYPE State
,
1999 struct nine_state
*state
= This
->update
;
2001 DBG("This=%p State=%u(%s) Value=%08x\n", This
,
2002 State
, nine_d3drs_to_string(State
), Value
);
2004 user_assert(State
< Elements(state
->rs
), D3DERR_INVALIDCALL
);
2006 if (likely(state
->rs
[State
] != Value
) || unlikely(This
->is_recording
)) {
2007 state
->rs
[State
] = Value
;
2008 state
->changed
.rs
[State
/ 32] |= 1 << (State
% 32);
2009 state
->changed
.group
|= nine_render_state_group
[State
];
2016 NineDevice9_GetRenderState( struct NineDevice9
*This
,
2017 D3DRENDERSTATETYPE State
,
2020 user_assert(State
< Elements(This
->state
.rs
), D3DERR_INVALIDCALL
);
2022 *pValue
= This
->state
.rs
[State
];
2027 NineDevice9_CreateStateBlock( struct NineDevice9
*This
,
2028 D3DSTATEBLOCKTYPE Type
,
2029 IDirect3DStateBlock9
**ppSB
)
2031 struct NineStateBlock9
*nsb
;
2032 struct nine_state
*dst
;
2034 enum nine_stateblock_type type
;
2037 DBG("This=%p Type=%u ppSB=%p\n", This
, Type
, ppSB
);
2039 user_assert(Type
== D3DSBT_ALL
||
2040 Type
== D3DSBT_VERTEXSTATE
||
2041 Type
== D3DSBT_PIXELSTATE
, D3DERR_INVALIDCALL
);
2044 case D3DSBT_VERTEXSTATE
: type
= NINESBT_VERTEXSTATE
; break;
2045 case D3DSBT_PIXELSTATE
: type
= NINESBT_PIXELSTATE
; break;
2051 hr
= NineStateBlock9_new(This
, &nsb
, type
);
2054 *ppSB
= (IDirect3DStateBlock9
*)nsb
;
2057 dst
->changed
.group
=
2058 NINE_STATE_TEXTURE
|
2061 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_VERTEXSTATE
) {
2062 dst
->changed
.group
|=
2063 NINE_STATE_FF_LIGHTING
|
2064 NINE_STATE_VS
| NINE_STATE_VS_CONST
|
2066 /* TODO: texture/sampler state */
2067 memcpy(dst
->changed
.rs
,
2068 nine_render_states_vertex
, sizeof(dst
->changed
.rs
));
2069 nine_ranges_insert(&dst
->changed
.vs_const_f
, 0, This
->max_vs_const_f
,
2071 dst
->changed
.vs_const_i
= 0xffff;
2072 dst
->changed
.vs_const_b
= 0xffff;
2073 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2074 dst
->changed
.sampler
[s
] |= 1 << D3DSAMP_DMAPOFFSET
;
2075 if (This
->state
.ff
.num_lights
) {
2076 dst
->ff
.num_lights
= This
->state
.ff
.num_lights
;
2077 /* zero'd -> light type won't be NINED3DLIGHT_INVALID, so
2078 * all currently existing lights will be captured
2080 dst
->ff
.light
= CALLOC(This
->state
.ff
.num_lights
,
2082 if (!dst
->ff
.light
) {
2083 nine_bind(ppSB
, NULL
);
2084 return E_OUTOFMEMORY
;
2088 if (Type
== D3DSBT_ALL
|| Type
== D3DSBT_PIXELSTATE
) {
2089 dst
->changed
.group
|=
2090 NINE_STATE_PS
| NINE_STATE_PS_CONST
;
2091 /* TODO: texture/sampler state */
2092 memcpy(dst
->changed
.rs
,
2093 nine_render_states_pixel
, sizeof(dst
->changed
.rs
));
2094 nine_ranges_insert(&dst
->changed
.ps_const_f
, 0, This
->max_ps_const_f
,
2096 dst
->changed
.ps_const_i
= 0xffff;
2097 dst
->changed
.ps_const_b
= 0xffff;
2098 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2099 dst
->changed
.sampler
[s
] |= 0x1ffe;
2101 if (Type
== D3DSBT_ALL
) {
2102 dst
->changed
.group
|=
2103 NINE_STATE_VIEWPORT
|
2104 NINE_STATE_SCISSOR
|
2105 NINE_STATE_RASTERIZER
|
2109 NINE_STATE_MATERIAL
|
2110 NINE_STATE_BLEND_COLOR
|
2111 NINE_STATE_SAMPLE_MASK
;
2112 memset(dst
->changed
.rs
, ~0, (D3DRS_COUNT
/ 32) * sizeof(uint32_t));
2113 dst
->changed
.rs
[D3DRS_LAST
/ 32] |= (1 << (D3DRS_COUNT
% 32)) - 1;
2114 dst
->changed
.vtxbuf
= (1ULL << This
->caps
.MaxStreams
) - 1;
2115 dst
->changed
.stream_freq
= dst
->changed
.vtxbuf
;
2116 dst
->changed
.ucp
= (1 << PIPE_MAX_CLIP_PLANES
) - 1;
2117 dst
->changed
.texture
= (1 << NINE_MAX_SAMPLERS
) - 1;
2119 NineStateBlock9_Capture(NineStateBlock9(*ppSB
));
2121 /* TODO: fixed function state */
2127 NineDevice9_BeginStateBlock( struct NineDevice9
*This
)
2131 DBG("This=%p\n", This
);
2133 user_assert(!This
->record
, D3DERR_INVALIDCALL
);
2135 hr
= NineStateBlock9_new(This
, &This
->record
, NINESBT_CUSTOM
);
2138 NineUnknown_ConvertRefToBind(NineUnknown(This
->record
));
2140 This
->update
= &This
->record
->state
;
2141 This
->is_recording
= TRUE
;
2147 NineDevice9_EndStateBlock( struct NineDevice9
*This
,
2148 IDirect3DStateBlock9
**ppSB
)
2150 DBG("This=%p ppSB=%p\n", This
, ppSB
);
2152 user_assert(This
->record
, D3DERR_INVALIDCALL
);
2154 This
->update
= &This
->state
;
2155 This
->is_recording
= FALSE
;
2157 NineUnknown_AddRef(NineUnknown(This
->record
));
2158 *ppSB
= (IDirect3DStateBlock9
*)This
->record
;
2159 NineUnknown_Unbind(NineUnknown(This
->record
));
2160 This
->record
= NULL
;
2166 NineDevice9_SetClipStatus( struct NineDevice9
*This
,
2167 const D3DCLIPSTATUS9
*pClipStatus
)
2169 STUB(D3DERR_INVALIDCALL
);
2173 NineDevice9_GetClipStatus( struct NineDevice9
*This
,
2174 D3DCLIPSTATUS9
*pClipStatus
)
2176 STUB(D3DERR_INVALIDCALL
);
2180 NineDevice9_GetTexture( struct NineDevice9
*This
,
2182 IDirect3DBaseTexture9
**ppTexture
)
2184 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2185 Stage
== D3DDMAPSAMPLER
||
2186 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2187 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2188 user_assert(ppTexture
, D3DERR_INVALIDCALL
);
2190 if (Stage
>= D3DDMAPSAMPLER
)
2191 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2193 *ppTexture
= (IDirect3DBaseTexture9
*)This
->state
.texture
[Stage
];
2195 if (This
->state
.texture
[Stage
])
2196 NineUnknown_AddRef(NineUnknown(This
->state
.texture
[Stage
]));
2201 NineDevice9_SetTexture( struct NineDevice9
*This
,
2203 IDirect3DBaseTexture9
*pTexture
)
2205 struct nine_state
*state
= This
->update
;
2206 struct NineBaseTexture9
*tex
= NineBaseTexture9(pTexture
);
2208 DBG("This=%p Stage=%u pTexture=%p\n", This
, Stage
, pTexture
);
2210 user_assert(Stage
< This
->caps
.MaxSimultaneousTextures
||
2211 Stage
== D3DDMAPSAMPLER
||
2212 (Stage
>= D3DVERTEXTEXTURESAMPLER0
&&
2213 Stage
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2214 user_assert(!tex
|| tex
->base
.pool
!= D3DPOOL_SCRATCH
, D3DERR_INVALIDCALL
);
2216 if (unlikely(tex
&& tex
->base
.pool
== D3DPOOL_SYSTEMMEM
)) {
2217 /* TODO: Currently not implemented. Better return error
2218 * with message telling what's wrong */
2219 ERR("This=%p D3DPOOL_SYSTEMMEM not implemented for SetTexture\n", This
);
2220 user_assert(tex
->base
.pool
!= D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
);
2223 if (Stage
>= D3DDMAPSAMPLER
)
2224 Stage
= Stage
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2226 if (!This
->is_recording
) {
2227 struct NineBaseTexture9
*old
= state
->texture
[Stage
];
2231 state
->samplers_shadow
&= ~(1 << Stage
);
2233 state
->samplers_shadow
|= tex
->shadow
<< Stage
;
2235 if ((tex
->dirty
| tex
->dirty_mip
) && LIST_IS_EMPTY(&tex
->list
))
2236 list_add(&tex
->list
, &This
->update_textures
);
2243 nine_bind(&state
->texture
[Stage
], pTexture
);
2245 state
->changed
.texture
|= 1 << Stage
;
2246 state
->changed
.group
|= NINE_STATE_TEXTURE
;
2252 NineDevice9_GetTextureStageState( struct NineDevice9
*This
,
2254 D3DTEXTURESTAGESTATETYPE Type
,
2257 const struct nine_state
*state
= &This
->state
;
2259 user_assert(Stage
< Elements(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2260 user_assert(Type
< Elements(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2262 *pValue
= state
->ff
.tex_stage
[Stage
][Type
];
2268 NineDevice9_SetTextureStageState( struct NineDevice9
*This
,
2270 D3DTEXTURESTAGESTATETYPE Type
,
2273 struct nine_state
*state
= This
->update
;
2275 DBG("Stage=%u Type=%u Value=%08x\n", Stage
, Type
, Value
);
2276 nine_dump_D3DTSS_value(DBG_FF
, Type
, Value
);
2278 user_assert(Stage
< Elements(state
->ff
.tex_stage
), D3DERR_INVALIDCALL
);
2279 user_assert(Type
< Elements(state
->ff
.tex_stage
[0]), D3DERR_INVALIDCALL
);
2281 state
->ff
.tex_stage
[Stage
][Type
] = Value
;
2283 state
->changed
.group
|= NINE_STATE_FF_PSSTAGES
;
2284 state
->ff
.changed
.tex_stage
[Stage
][Type
/ 32] |= 1 << (Type
% 32);
2290 NineDevice9_GetSamplerState( struct NineDevice9
*This
,
2292 D3DSAMPLERSTATETYPE Type
,
2295 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2296 Sampler
== D3DDMAPSAMPLER
||
2297 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2298 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2300 if (Sampler
>= D3DDMAPSAMPLER
)
2301 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2303 *pValue
= This
->state
.samp
[Sampler
][Type
];
2308 NineDevice9_SetSamplerState( struct NineDevice9
*This
,
2310 D3DSAMPLERSTATETYPE Type
,
2313 struct nine_state
*state
= This
->update
;
2315 DBG("This=%p Sampler=%u Type=%s Value=%08x\n", This
,
2316 Sampler
, nine_D3DSAMP_to_str(Type
), Value
);
2318 user_assert(Sampler
< This
->caps
.MaxSimultaneousTextures
||
2319 Sampler
== D3DDMAPSAMPLER
||
2320 (Sampler
>= D3DVERTEXTEXTURESAMPLER0
&&
2321 Sampler
<= D3DVERTEXTEXTURESAMPLER3
), D3DERR_INVALIDCALL
);
2323 if (Sampler
>= D3DDMAPSAMPLER
)
2324 Sampler
= Sampler
- D3DDMAPSAMPLER
+ NINE_MAX_SAMPLERS_PS
;
2326 state
->samp
[Sampler
][Type
] = Value
;
2327 state
->changed
.group
|= NINE_STATE_SAMPLER
;
2328 state
->changed
.sampler
[Sampler
] |= 1 << Type
;
2334 NineDevice9_ValidateDevice( struct NineDevice9
*This
,
2337 const struct nine_state
*state
= &This
->state
;
2339 unsigned w
= 0, h
= 0;
2341 DBG("This=%p pNumPasses=%p\n", This
, pNumPasses
);
2343 for (i
= 0; i
< Elements(state
->samp
); ++i
) {
2344 if (state
->samp
[i
][D3DSAMP_MINFILTER
] == D3DTEXF_NONE
||
2345 state
->samp
[i
][D3DSAMP_MAGFILTER
] == D3DTEXF_NONE
)
2346 return D3DERR_UNSUPPORTEDTEXTUREFILTER
;
2349 for (i
= 0; i
< This
->caps
.NumSimultaneousRTs
; ++i
) {
2353 w
= state
->rt
[i
]->desc
.Width
;
2354 h
= state
->rt
[i
]->desc
.Height
;
2356 if (state
->rt
[i
]->desc
.Width
!= w
|| state
->rt
[i
]->desc
.Height
!= h
) {
2357 return D3DERR_CONFLICTINGRENDERSTATE
;
2361 (state
->rs
[D3DRS_ZENABLE
] || state
->rs
[D3DRS_STENCILENABLE
])) {
2363 (state
->ds
->desc
.Width
!= w
|| state
->ds
->desc
.Height
!= h
))
2364 return D3DERR_CONFLICTINGRENDERSTATE
;
2374 NineDevice9_SetPaletteEntries( struct NineDevice9
*This
,
2376 const PALETTEENTRY
*pEntries
)
2378 STUB(D3D_OK
); /* like wine */
2382 NineDevice9_GetPaletteEntries( struct NineDevice9
*This
,
2384 PALETTEENTRY
*pEntries
)
2386 STUB(D3DERR_INVALIDCALL
);
2390 NineDevice9_SetCurrentTexturePalette( struct NineDevice9
*This
,
2391 UINT PaletteNumber
)
2393 STUB(D3D_OK
); /* like wine */
2397 NineDevice9_GetCurrentTexturePalette( struct NineDevice9
*This
,
2398 UINT
*PaletteNumber
)
2400 STUB(D3DERR_INVALIDCALL
);
2404 NineDevice9_SetScissorRect( struct NineDevice9
*This
,
2407 struct nine_state
*state
= This
->update
;
2409 DBG("x=(%u..%u) y=(%u..%u)\n",
2410 pRect
->left
, pRect
->top
, pRect
->right
, pRect
->bottom
);
2412 state
->scissor
.minx
= pRect
->left
;
2413 state
->scissor
.miny
= pRect
->top
;
2414 state
->scissor
.maxx
= pRect
->right
;
2415 state
->scissor
.maxy
= pRect
->bottom
;
2417 state
->changed
.group
|= NINE_STATE_SCISSOR
;
2423 NineDevice9_GetScissorRect( struct NineDevice9
*This
,
2426 pRect
->left
= This
->state
.scissor
.minx
;
2427 pRect
->top
= This
->state
.scissor
.miny
;
2428 pRect
->right
= This
->state
.scissor
.maxx
;
2429 pRect
->bottom
= This
->state
.scissor
.maxy
;
2435 NineDevice9_SetSoftwareVertexProcessing( struct NineDevice9
*This
,
2438 STUB(D3DERR_INVALIDCALL
);
2442 NineDevice9_GetSoftwareVertexProcessing( struct NineDevice9
*This
)
2444 return !!(This
->params
.BehaviorFlags
& D3DCREATE_SOFTWARE_VERTEXPROCESSING
);
2448 NineDevice9_SetNPatchMode( struct NineDevice9
*This
,
2451 STUB(D3DERR_INVALIDCALL
);
2455 NineDevice9_GetNPatchMode( struct NineDevice9
*This
)
2461 init_draw_info(struct pipe_draw_info
*info
,
2462 struct NineDevice9
*dev
, D3DPRIMITIVETYPE type
, UINT count
)
2464 info
->mode
= d3dprimitivetype_to_pipe_prim(type
);
2465 info
->count
= prim_count_to_vertex_count(type
, count
);
2466 info
->start_instance
= 0;
2467 info
->instance_count
= 1;
2468 if (dev
->state
.stream_instancedata_mask
& dev
->state
.stream_usage_mask
)
2469 info
->instance_count
= MAX2(dev
->state
.stream_freq
[0] & 0x7FFFFF, 1);
2470 info
->primitive_restart
= FALSE
;
2471 info
->restart_index
= 0;
2472 info
->count_from_stream_output
= NULL
;
2473 info
->indirect
= NULL
;
2477 NineDevice9_DrawPrimitive( struct NineDevice9
*This
,
2478 D3DPRIMITIVETYPE PrimitiveType
,
2480 UINT PrimitiveCount
)
2482 struct pipe_draw_info info
;
2484 DBG("iface %p, PrimitiveType %u, StartVertex %u, PrimitiveCount %u\n",
2485 This
, PrimitiveType
, StartVertex
, PrimitiveCount
);
2487 nine_update_state(This
, ~0);
2489 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2490 info
.indexed
= FALSE
;
2491 info
.start
= StartVertex
;
2492 info
.index_bias
= 0;
2493 info
.min_index
= info
.start
;
2494 info
.max_index
= info
.count
- 1;
2496 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2502 NineDevice9_DrawIndexedPrimitive( struct NineDevice9
*This
,
2503 D3DPRIMITIVETYPE PrimitiveType
,
2504 INT BaseVertexIndex
,
2505 UINT MinVertexIndex
,
2508 UINT PrimitiveCount
)
2510 struct pipe_draw_info info
;
2512 DBG("iface %p, PrimitiveType %u, BaseVertexIndex %u, MinVertexIndex %u "
2513 "NumVertices %u, StartIndex %u, PrimitiveCount %u\n",
2514 This
, PrimitiveType
, BaseVertexIndex
, MinVertexIndex
, NumVertices
,
2515 StartIndex
, PrimitiveCount
);
2517 user_assert(This
->state
.idxbuf
, D3DERR_INVALIDCALL
);
2518 user_assert(This
->state
.vdecl
, D3DERR_INVALIDCALL
);
2520 nine_update_state(This
, ~0);
2522 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2523 info
.indexed
= TRUE
;
2524 info
.start
= StartIndex
;
2525 info
.index_bias
= BaseVertexIndex
;
2526 /* These don't include index bias: */
2527 info
.min_index
= MinVertexIndex
;
2528 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
2530 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2536 NineDevice9_DrawPrimitiveUP( struct NineDevice9
*This
,
2537 D3DPRIMITIVETYPE PrimitiveType
,
2538 UINT PrimitiveCount
,
2539 const void *pVertexStreamZeroData
,
2540 UINT VertexStreamZeroStride
)
2542 struct pipe_vertex_buffer vtxbuf
;
2543 struct pipe_draw_info info
;
2545 DBG("iface %p, PrimitiveType %u, PrimitiveCount %u, data %p, stride %u\n",
2546 This
, PrimitiveType
, PrimitiveCount
,
2547 pVertexStreamZeroData
, VertexStreamZeroStride
);
2549 user_assert(pVertexStreamZeroData
&& VertexStreamZeroStride
,
2550 D3DERR_INVALIDCALL
);
2552 nine_update_state(This
, ~0);
2554 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2555 info
.indexed
= FALSE
;
2557 info
.index_bias
= 0;
2559 info
.max_index
= info
.count
- 1;
2561 vtxbuf
.stride
= VertexStreamZeroStride
;
2562 vtxbuf
.buffer_offset
= 0;
2563 vtxbuf
.buffer
= NULL
;
2564 vtxbuf
.user_buffer
= pVertexStreamZeroData
;
2566 if (!This
->driver_caps
.user_vbufs
)
2567 u_upload_data(This
->upload
,
2569 (info
.max_index
+ 1) * VertexStreamZeroStride
, /* XXX */
2571 &vtxbuf
.buffer_offset
,
2574 This
->pipe
->set_vertex_buffers(This
->pipe
, 0, 1, &vtxbuf
);
2576 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2578 NineDevice9_PauseRecording(This
);
2579 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
2580 NineDevice9_ResumeRecording(This
);
2582 pipe_resource_reference(&vtxbuf
.buffer
, NULL
);
2588 NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9
*This
,
2589 D3DPRIMITIVETYPE PrimitiveType
,
2590 UINT MinVertexIndex
,
2592 UINT PrimitiveCount
,
2593 const void *pIndexData
,
2594 D3DFORMAT IndexDataFormat
,
2595 const void *pVertexStreamZeroData
,
2596 UINT VertexStreamZeroStride
)
2598 struct pipe_draw_info info
;
2599 struct pipe_vertex_buffer vbuf
;
2600 struct pipe_index_buffer ibuf
;
2602 DBG("iface %p, PrimitiveType %u, MinVertexIndex %u, NumVertices %u "
2603 "PrimitiveCount %u, pIndexData %p, IndexDataFormat %u "
2604 "pVertexStreamZeroData %p, VertexStreamZeroStride %u\n",
2605 This
, PrimitiveType
, MinVertexIndex
, NumVertices
, PrimitiveCount
,
2606 pIndexData
, IndexDataFormat
,
2607 pVertexStreamZeroData
, VertexStreamZeroStride
);
2609 user_assert(pIndexData
&& pVertexStreamZeroData
, D3DERR_INVALIDCALL
);
2610 user_assert(VertexStreamZeroStride
, D3DERR_INVALIDCALL
);
2611 user_assert(IndexDataFormat
== D3DFMT_INDEX16
||
2612 IndexDataFormat
== D3DFMT_INDEX32
, D3DERR_INVALIDCALL
);
2614 nine_update_state(This
, ~0);
2616 init_draw_info(&info
, This
, PrimitiveType
, PrimitiveCount
);
2617 info
.indexed
= TRUE
;
2619 info
.index_bias
= 0;
2620 info
.min_index
= MinVertexIndex
;
2621 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
2623 vbuf
.stride
= VertexStreamZeroStride
;
2624 vbuf
.buffer_offset
= 0;
2626 vbuf
.user_buffer
= pVertexStreamZeroData
;
2628 ibuf
.index_size
= (IndexDataFormat
== D3DFMT_INDEX16
) ? 2 : 4;
2631 ibuf
.user_buffer
= pIndexData
;
2633 if (!This
->driver_caps
.user_vbufs
) {
2634 const unsigned base
= info
.min_index
* VertexStreamZeroStride
;
2635 u_upload_data(This
->upload
,
2638 info
.min_index
+ 1) * VertexStreamZeroStride
, /* XXX */
2639 (const uint8_t *)vbuf
.user_buffer
+ base
,
2640 &vbuf
.buffer_offset
,
2642 /* Won't be used: */
2643 vbuf
.buffer_offset
-= base
;
2645 if (!This
->driver_caps
.user_ibufs
)
2646 u_upload_data(This
->upload
,
2648 info
.count
* ibuf
.index_size
,
2653 This
->pipe
->set_vertex_buffers(This
->pipe
, 0, 1, &vbuf
);
2654 This
->pipe
->set_index_buffer(This
->pipe
, &ibuf
);
2656 This
->pipe
->draw_vbo(This
->pipe
, &info
);
2658 pipe_resource_reference(&vbuf
.buffer
, NULL
);
2659 pipe_resource_reference(&ibuf
.buffer
, NULL
);
2661 NineDevice9_PauseRecording(This
);
2662 NineDevice9_SetIndices(This
, NULL
);
2663 NineDevice9_SetStreamSource(This
, 0, NULL
, 0, 0);
2664 NineDevice9_ResumeRecording(This
);
2669 /* TODO: Write to pDestBuffer directly if vertex declaration contains
2673 NineDevice9_ProcessVertices( struct NineDevice9
*This
,
2677 IDirect3DVertexBuffer9
*pDestBuffer
,
2678 IDirect3DVertexDeclaration9
*pVertexDecl
,
2681 struct pipe_screen
*screen
= This
->screen
;
2682 struct NineVertexDeclaration9
*vdecl
= NineVertexDeclaration9(pVertexDecl
);
2683 struct NineVertexShader9
*vs
;
2684 struct pipe_resource
*resource
;
2685 struct pipe_stream_output_target
*target
;
2686 struct pipe_draw_info draw
;
2688 unsigned buffer_offset
, buffer_size
;
2690 DBG("This=%p SrcStartIndex=%u DestIndex=%u VertexCount=%u "
2691 "pDestBuffer=%p pVertexDecl=%p Flags=%d\n",
2692 This
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
,
2693 pVertexDecl
, Flags
);
2695 if (!screen
->get_param(screen
, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
))
2696 STUB(D3DERR_INVALIDCALL
);
2698 nine_update_state(This
, ~0);
2700 /* TODO: Create shader with stream output. */
2701 STUB(D3DERR_INVALIDCALL
);
2702 struct NineVertexBuffer9
*dst
= NineVertexBuffer9(pDestBuffer
);
2704 vs
= This
->state
.vs
? This
->state
.vs
: This
->ff
.vs
;
2706 buffer_size
= VertexCount
* vs
->so
->stride
[0];
2708 struct pipe_resource templ
;
2710 templ
.target
= PIPE_BUFFER
;
2711 templ
.format
= PIPE_FORMAT_R8_UNORM
;
2712 templ
.width0
= buffer_size
;
2714 templ
.bind
= PIPE_BIND_STREAM_OUTPUT
;
2715 templ
.usage
= PIPE_USAGE_STREAM
;
2716 templ
.height0
= templ
.depth0
= templ
.array_size
= 1;
2717 templ
.last_level
= templ
.nr_samples
= 0;
2719 resource
= This
->screen
->resource_create(This
->screen
, &templ
);
2721 return E_OUTOFMEMORY
;
2724 /* SO matches vertex declaration */
2725 resource
= dst
->base
.resource
;
2726 buffer_offset
= DestIndex
* vs
->so
->stride
[0];
2728 target
= This
->pipe
->create_stream_output_target(This
->pipe
, resource
,
2732 pipe_resource_reference(&resource
, NULL
);
2733 return D3DERR_DRIVERINTERNALERROR
;
2737 hr
= NineVertexDeclaration9_new_from_fvf(This
, dst
->desc
.FVF
, &vdecl
);
2742 init_draw_info(&draw
, This
, D3DPT_POINTLIST
, VertexCount
);
2743 draw
.instance_count
= 1;
2744 draw
.indexed
= FALSE
;
2745 draw
.start
= SrcStartIndex
;
2746 draw
.index_bias
= 0;
2747 draw
.min_index
= SrcStartIndex
;
2748 draw
.max_index
= SrcStartIndex
+ VertexCount
- 1;
2750 This
->pipe
->set_stream_output_targets(This
->pipe
, 1, &target
, 0);
2751 This
->pipe
->draw_vbo(This
->pipe
, &draw
);
2752 This
->pipe
->set_stream_output_targets(This
->pipe
, 0, NULL
, 0);
2753 This
->pipe
->stream_output_target_destroy(This
->pipe
, target
);
2755 hr
= NineVertexDeclaration9_ConvertStreamOutput(vdecl
,
2756 dst
, DestIndex
, VertexCount
,
2759 pipe_resource_reference(&resource
, NULL
);
2761 NineUnknown_Release(NineUnknown(vdecl
));
2766 NineDevice9_CreateVertexDeclaration( struct NineDevice9
*This
,
2767 const D3DVERTEXELEMENT9
*pVertexElements
,
2768 IDirect3DVertexDeclaration9
**ppDecl
)
2770 struct NineVertexDeclaration9
*vdecl
;
2772 DBG("This=%p pVertexElements=%p ppDecl=%p\n",
2773 This
, pVertexElements
, ppDecl
);
2775 HRESULT hr
= NineVertexDeclaration9_new(This
, pVertexElements
, &vdecl
);
2777 *ppDecl
= (IDirect3DVertexDeclaration9
*)vdecl
;
2783 NineDevice9_SetVertexDeclaration( struct NineDevice9
*This
,
2784 IDirect3DVertexDeclaration9
*pDecl
)
2786 struct nine_state
*state
= This
->update
;
2788 DBG("This=%p pDecl=%p\n", This
, pDecl
);
2790 if (likely(!This
->is_recording
) && state
->vdecl
== NineVertexDeclaration9(pDecl
))
2792 nine_bind(&state
->vdecl
, pDecl
);
2794 state
->changed
.group
|= NINE_STATE_VDECL
;
2800 NineDevice9_GetVertexDeclaration( struct NineDevice9
*This
,
2801 IDirect3DVertexDeclaration9
**ppDecl
)
2803 user_assert(ppDecl
, D3DERR_INVALIDCALL
);
2805 *ppDecl
= (IDirect3DVertexDeclaration9
*)This
->state
.vdecl
;
2807 NineUnknown_AddRef(NineUnknown(*ppDecl
));
2812 NineDevice9_SetFVF( struct NineDevice9
*This
,
2815 struct NineVertexDeclaration9
*vdecl
;
2818 DBG("FVF = %08x\n", FVF
);
2820 return D3D_OK
; /* like wine */
2822 vdecl
= util_hash_table_get(This
->ff
.ht_fvf
, &FVF
);
2824 hr
= NineVertexDeclaration9_new_from_fvf(This
, FVF
, &vdecl
);
2828 util_hash_table_set(This
->ff
.ht_fvf
, &vdecl
->fvf
, vdecl
);
2829 NineUnknown_ConvertRefToBind(NineUnknown(vdecl
));
2831 return NineDevice9_SetVertexDeclaration(
2832 This
, (IDirect3DVertexDeclaration9
*)vdecl
);
2836 NineDevice9_GetFVF( struct NineDevice9
*This
,
2839 *pFVF
= This
->state
.vdecl
? This
->state
.vdecl
->fvf
: 0;
2844 NineDevice9_CreateVertexShader( struct NineDevice9
*This
,
2845 const DWORD
*pFunction
,
2846 IDirect3DVertexShader9
**ppShader
)
2848 struct NineVertexShader9
*vs
;
2851 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
2853 hr
= NineVertexShader9_new(This
, &vs
, pFunction
, NULL
);
2856 *ppShader
= (IDirect3DVertexShader9
*)vs
;
2861 NineDevice9_SetVertexShader( struct NineDevice9
*This
,
2862 IDirect3DVertexShader9
*pShader
)
2864 struct nine_state
*state
= This
->update
;
2866 DBG("This=%p pShader=%p\n", This
, pShader
);
2868 nine_bind(&state
->vs
, pShader
);
2870 state
->changed
.group
|= NINE_STATE_VS
;
2876 NineDevice9_GetVertexShader( struct NineDevice9
*This
,
2877 IDirect3DVertexShader9
**ppShader
)
2879 user_assert(ppShader
, D3DERR_INVALIDCALL
);
2880 nine_reference_set(ppShader
, This
->state
.vs
);
2885 NineDevice9_SetVertexShaderConstantF( struct NineDevice9
*This
,
2887 const float *pConstantData
,
2888 UINT Vector4fCount
)
2890 struct nine_state
*state
= This
->update
;
2892 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
2893 This
, StartRegister
, pConstantData
, Vector4fCount
);
2895 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
2896 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
2900 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
2902 memcpy(&state
->vs_const_f
[StartRegister
* 4],
2904 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
2906 nine_ranges_insert(&state
->changed
.vs_const_f
,
2907 StartRegister
, StartRegister
+ Vector4fCount
,
2910 state
->changed
.group
|= NINE_STATE_VS_CONST
;
2916 NineDevice9_GetVertexShaderConstantF( struct NineDevice9
*This
,
2918 float *pConstantData
,
2919 UINT Vector4fCount
)
2921 const struct nine_state
*state
= &This
->state
;
2923 user_assert(StartRegister
< This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
2924 user_assert(StartRegister
+ Vector4fCount
<= This
->caps
.MaxVertexShaderConst
, D3DERR_INVALIDCALL
);
2925 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
2927 memcpy(pConstantData
,
2928 &state
->vs_const_f
[StartRegister
* 4],
2929 Vector4fCount
* 4 * sizeof(state
->vs_const_f
[0]));
2935 NineDevice9_SetVertexShaderConstantI( struct NineDevice9
*This
,
2937 const int *pConstantData
,
2938 UINT Vector4iCount
)
2940 struct nine_state
*state
= This
->update
;
2943 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
2944 This
, StartRegister
, pConstantData
, Vector4iCount
);
2946 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
2947 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
2948 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
2950 if (This
->driver_caps
.vs_integer
) {
2951 memcpy(&state
->vs_const_i
[StartRegister
][0],
2953 Vector4iCount
* sizeof(state
->vs_const_i
[0]));
2955 for (i
= 0; i
< Vector4iCount
; i
++) {
2956 state
->vs_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
2957 state
->vs_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
2958 state
->vs_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
2959 state
->vs_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
2963 state
->changed
.vs_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
2964 state
->changed
.group
|= NINE_STATE_VS_CONST
;
2970 NineDevice9_GetVertexShaderConstantI( struct NineDevice9
*This
,
2973 UINT Vector4iCount
)
2975 const struct nine_state
*state
= &This
->state
;
2978 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
2979 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
2980 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
2982 if (This
->driver_caps
.vs_integer
) {
2983 memcpy(pConstantData
,
2984 &state
->vs_const_i
[StartRegister
][0],
2985 Vector4iCount
* sizeof(state
->vs_const_i
[0]));
2987 for (i
= 0; i
< Vector4iCount
; i
++) {
2988 pConstantData
[4*i
] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][0]);
2989 pConstantData
[4*i
+1] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][1]);
2990 pConstantData
[4*i
+2] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][2]);
2991 pConstantData
[4*i
+3] = (int32_t) uif(state
->vs_const_i
[StartRegister
+i
][3]);
2999 NineDevice9_SetVertexShaderConstantB( struct NineDevice9
*This
,
3001 const BOOL
*pConstantData
,
3004 struct nine_state
*state
= This
->update
;
3006 uint32_t bool_true
= This
->driver_caps
.vs_integer
? 0xFFFFFFFF : fui(1.0f
);
3008 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3009 This
, StartRegister
, pConstantData
, BoolCount
);
3011 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3012 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3013 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3015 for (i
= 0; i
< BoolCount
; i
++)
3016 state
->vs_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3018 state
->changed
.vs_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3019 state
->changed
.group
|= NINE_STATE_VS_CONST
;
3025 NineDevice9_GetVertexShaderConstantB( struct NineDevice9
*This
,
3027 BOOL
*pConstantData
,
3030 const struct nine_state
*state
= &This
->state
;
3033 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3034 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3035 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3037 for (i
= 0; i
< BoolCount
; i
++)
3038 pConstantData
[i
] = state
->vs_const_b
[StartRegister
+ i
] != 0 ? TRUE
: FALSE
;
3044 NineDevice9_SetStreamSource( struct NineDevice9
*This
,
3046 IDirect3DVertexBuffer9
*pStreamData
,
3050 struct nine_state
*state
= This
->update
;
3051 struct NineVertexBuffer9
*pVBuf9
= NineVertexBuffer9(pStreamData
);
3052 const unsigned i
= StreamNumber
;
3054 DBG("This=%p StreamNumber=%u pStreamData=%p OffsetInBytes=%u Stride=%u\n",
3055 This
, StreamNumber
, pStreamData
, OffsetInBytes
, Stride
);
3057 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3058 user_assert(Stride
<= This
->caps
.MaxStreamStride
, D3DERR_INVALIDCALL
);
3060 if (likely(!This
->is_recording
)) {
3061 if (state
->stream
[i
] == NineVertexBuffer9(pStreamData
) &&
3062 state
->vtxbuf
[i
].stride
== Stride
&&
3063 state
->vtxbuf
[i
].buffer_offset
== OffsetInBytes
)
3066 nine_bind(&state
->stream
[i
], pStreamData
);
3068 state
->changed
.vtxbuf
|= 1 << StreamNumber
;
3071 state
->vtxbuf
[i
].stride
= Stride
;
3072 state
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
3074 state
->vtxbuf
[i
].buffer
= pStreamData
? pVBuf9
->base
.resource
: NULL
;
3080 NineDevice9_GetStreamSource( struct NineDevice9
*This
,
3082 IDirect3DVertexBuffer9
**ppStreamData
,
3083 UINT
*pOffsetInBytes
,
3086 const struct nine_state
*state
= &This
->state
;
3087 const unsigned i
= StreamNumber
;
3089 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3090 user_assert(ppStreamData
, D3DERR_INVALIDCALL
);
3092 nine_reference_set(ppStreamData
, state
->stream
[i
]);
3093 *pStride
= state
->vtxbuf
[i
].stride
;
3094 *pOffsetInBytes
= state
->vtxbuf
[i
].buffer_offset
;
3100 NineDevice9_SetStreamSourceFreq( struct NineDevice9
*This
,
3104 struct nine_state
*state
= This
->update
;
3105 /* const UINT freq = Setting & 0x7FFFFF; */
3107 DBG("This=%p StreamNumber=%u FrequencyParameter=0x%x\n", This
,
3108 StreamNumber
, Setting
);
3110 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3111 user_assert(StreamNumber
!= 0 || !(Setting
& D3DSTREAMSOURCE_INSTANCEDATA
),
3112 D3DERR_INVALIDCALL
);
3113 user_assert(!((Setting
& D3DSTREAMSOURCE_INSTANCEDATA
) &&
3114 (Setting
& D3DSTREAMSOURCE_INDEXEDDATA
)), D3DERR_INVALIDCALL
);
3115 user_assert(Setting
, D3DERR_INVALIDCALL
);
3117 state
->stream_freq
[StreamNumber
] = Setting
;
3119 if (Setting
& D3DSTREAMSOURCE_INSTANCEDATA
)
3120 state
->stream_instancedata_mask
|= 1 << StreamNumber
;
3122 state
->stream_instancedata_mask
&= ~(1 << StreamNumber
);
3124 state
->changed
.stream_freq
|= 1 << StreamNumber
;
3129 NineDevice9_GetStreamSourceFreq( struct NineDevice9
*This
,
3133 user_assert(StreamNumber
< This
->caps
.MaxStreams
, D3DERR_INVALIDCALL
);
3134 *pSetting
= This
->state
.stream_freq
[StreamNumber
];
3139 NineDevice9_SetIndices( struct NineDevice9
*This
,
3140 IDirect3DIndexBuffer9
*pIndexData
)
3142 struct nine_state
*state
= This
->update
;
3144 DBG("This=%p pIndexData=%p\n", This
, pIndexData
);
3146 if (likely(!This
->is_recording
))
3147 if (state
->idxbuf
== NineIndexBuffer9(pIndexData
))
3149 nine_bind(&state
->idxbuf
, pIndexData
);
3151 state
->changed
.group
|= NINE_STATE_IDXBUF
;
3156 /* XXX: wine/d3d9 doesn't have pBaseVertexIndex, and it doesn't make sense
3157 * here because it's an argument passed to the Draw calls.
3160 NineDevice9_GetIndices( struct NineDevice9
*This
,
3161 IDirect3DIndexBuffer9
**ppIndexData
/*,
3162 UINT *pBaseVertexIndex */ )
3164 user_assert(ppIndexData
, D3DERR_INVALIDCALL
);
3165 nine_reference_set(ppIndexData
, This
->state
.idxbuf
);
3170 NineDevice9_CreatePixelShader( struct NineDevice9
*This
,
3171 const DWORD
*pFunction
,
3172 IDirect3DPixelShader9
**ppShader
)
3174 struct NinePixelShader9
*ps
;
3177 DBG("This=%p pFunction=%p ppShader=%p\n", This
, pFunction
, ppShader
);
3179 hr
= NinePixelShader9_new(This
, &ps
, pFunction
, NULL
);
3182 *ppShader
= (IDirect3DPixelShader9
*)ps
;
3187 NineDevice9_SetPixelShader( struct NineDevice9
*This
,
3188 IDirect3DPixelShader9
*pShader
)
3190 struct nine_state
*state
= This
->update
;
3192 DBG("This=%p pShader=%p\n", This
, pShader
);
3194 nine_bind(&state
->ps
, pShader
);
3196 state
->changed
.group
|= NINE_STATE_PS
;
3202 NineDevice9_GetPixelShader( struct NineDevice9
*This
,
3203 IDirect3DPixelShader9
**ppShader
)
3205 user_assert(ppShader
, D3DERR_INVALIDCALL
);
3206 nine_reference_set(ppShader
, This
->state
.ps
);
3211 NineDevice9_SetPixelShaderConstantF( struct NineDevice9
*This
,
3213 const float *pConstantData
,
3214 UINT Vector4fCount
)
3216 struct nine_state
*state
= This
->update
;
3218 DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
3219 This
, StartRegister
, pConstantData
, Vector4fCount
);
3221 user_assert(StartRegister
< NINE_MAX_CONST_F
, D3DERR_INVALIDCALL
);
3222 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F
, D3DERR_INVALIDCALL
);
3226 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3228 memcpy(&state
->ps_const_f
[StartRegister
* 4],
3230 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3232 nine_ranges_insert(&state
->changed
.ps_const_f
,
3233 StartRegister
, StartRegister
+ Vector4fCount
,
3236 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3242 NineDevice9_GetPixelShaderConstantF( struct NineDevice9
*This
,
3244 float *pConstantData
,
3245 UINT Vector4fCount
)
3247 const struct nine_state
*state
= &This
->state
;
3249 user_assert(StartRegister
< NINE_MAX_CONST_F
, D3DERR_INVALIDCALL
);
3250 user_assert(StartRegister
+ Vector4fCount
<= NINE_MAX_CONST_F
, D3DERR_INVALIDCALL
);
3251 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3253 memcpy(pConstantData
,
3254 &state
->ps_const_f
[StartRegister
* 4],
3255 Vector4fCount
* 4 * sizeof(state
->ps_const_f
[0]));
3261 NineDevice9_SetPixelShaderConstantI( struct NineDevice9
*This
,
3263 const int *pConstantData
,
3264 UINT Vector4iCount
)
3266 struct nine_state
*state
= This
->update
;
3269 DBG("This=%p StartRegister=%u pConstantData=%p Vector4iCount=%u\n",
3270 This
, StartRegister
, pConstantData
, Vector4iCount
);
3272 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3273 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3274 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3276 if (This
->driver_caps
.ps_integer
) {
3277 memcpy(&state
->ps_const_i
[StartRegister
][0],
3279 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3281 for (i
= 0; i
< Vector4iCount
; i
++) {
3282 state
->ps_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
3283 state
->ps_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
3284 state
->ps_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
3285 state
->ps_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
3288 state
->changed
.ps_const_i
|= ((1 << Vector4iCount
) - 1) << StartRegister
;
3289 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3295 NineDevice9_GetPixelShaderConstantI( struct NineDevice9
*This
,
3298 UINT Vector4iCount
)
3300 const struct nine_state
*state
= &This
->state
;
3303 user_assert(StartRegister
< NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3304 user_assert(StartRegister
+ Vector4iCount
<= NINE_MAX_CONST_I
, D3DERR_INVALIDCALL
);
3305 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3307 if (This
->driver_caps
.ps_integer
) {
3308 memcpy(pConstantData
,
3309 &state
->ps_const_i
[StartRegister
][0],
3310 Vector4iCount
* sizeof(state
->ps_const_i
[0]));
3312 for (i
= 0; i
< Vector4iCount
; i
++) {
3313 pConstantData
[4*i
] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][0]);
3314 pConstantData
[4*i
+1] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][1]);
3315 pConstantData
[4*i
+2] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][2]);
3316 pConstantData
[4*i
+3] = (int32_t) uif(state
->ps_const_i
[StartRegister
+i
][3]);
3324 NineDevice9_SetPixelShaderConstantB( struct NineDevice9
*This
,
3326 const BOOL
*pConstantData
,
3329 struct nine_state
*state
= This
->update
;
3331 uint32_t bool_true
= This
->driver_caps
.ps_integer
? 0xFFFFFFFF : fui(1.0f
);
3333 DBG("This=%p StartRegister=%u pConstantData=%p BoolCount=%u\n",
3334 This
, StartRegister
, pConstantData
, BoolCount
);
3336 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3337 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3338 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3340 for (i
= 0; i
< BoolCount
; i
++)
3341 state
->ps_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
3343 state
->changed
.ps_const_b
|= ((1 << BoolCount
) - 1) << StartRegister
;
3344 state
->changed
.group
|= NINE_STATE_PS_CONST
;
3350 NineDevice9_GetPixelShaderConstantB( struct NineDevice9
*This
,
3352 BOOL
*pConstantData
,
3355 const struct nine_state
*state
= &This
->state
;
3358 user_assert(StartRegister
< NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3359 user_assert(StartRegister
+ BoolCount
<= NINE_MAX_CONST_B
, D3DERR_INVALIDCALL
);
3360 user_assert(pConstantData
, D3DERR_INVALIDCALL
);
3362 for (i
= 0; i
< BoolCount
; i
++)
3363 pConstantData
[i
] = state
->ps_const_b
[StartRegister
+ i
] ? TRUE
: FALSE
;
3369 NineDevice9_DrawRectPatch( struct NineDevice9
*This
,
3371 const float *pNumSegs
,
3372 const D3DRECTPATCH_INFO
*pRectPatchInfo
)
3374 STUB(D3DERR_INVALIDCALL
);
3378 NineDevice9_DrawTriPatch( struct NineDevice9
*This
,
3380 const float *pNumSegs
,
3381 const D3DTRIPATCH_INFO
*pTriPatchInfo
)
3383 STUB(D3DERR_INVALIDCALL
);
3387 NineDevice9_DeletePatch( struct NineDevice9
*This
,
3390 STUB(D3DERR_INVALIDCALL
);
3394 NineDevice9_CreateQuery( struct NineDevice9
*This
,
3396 IDirect3DQuery9
**ppQuery
)
3398 struct NineQuery9
*query
;
3401 DBG("This=%p Type=%d ppQuery=%p\n", This
, Type
, ppQuery
);
3403 hr
= nine_is_query_supported(This
->screen
, Type
);
3404 if (!ppQuery
|| hr
!= D3D_OK
)
3407 hr
= NineQuery9_new(This
, &query
, Type
);
3410 *ppQuery
= (IDirect3DQuery9
*)query
;
3414 IDirect3DDevice9Vtbl NineDevice9_vtable
= {
3415 (void *)NineUnknown_QueryInterface
,
3416 (void *)NineUnknown_AddRef
,
3417 (void *)NineUnknown_Release
,
3418 (void *)NineDevice9_TestCooperativeLevel
,
3419 (void *)NineDevice9_GetAvailableTextureMem
,
3420 (void *)NineDevice9_EvictManagedResources
,
3421 (void *)NineDevice9_GetDirect3D
,
3422 (void *)NineDevice9_GetDeviceCaps
,
3423 (void *)NineDevice9_GetDisplayMode
,
3424 (void *)NineDevice9_GetCreationParameters
,
3425 (void *)NineDevice9_SetCursorProperties
,
3426 (void *)NineDevice9_SetCursorPosition
,
3427 (void *)NineDevice9_ShowCursor
,
3428 (void *)NineDevice9_CreateAdditionalSwapChain
,
3429 (void *)NineDevice9_GetSwapChain
,
3430 (void *)NineDevice9_GetNumberOfSwapChains
,
3431 (void *)NineDevice9_Reset
,
3432 (void *)NineDevice9_Present
,
3433 (void *)NineDevice9_GetBackBuffer
,
3434 (void *)NineDevice9_GetRasterStatus
,
3435 (void *)NineDevice9_SetDialogBoxMode
,
3436 (void *)NineDevice9_SetGammaRamp
,
3437 (void *)NineDevice9_GetGammaRamp
,
3438 (void *)NineDevice9_CreateTexture
,
3439 (void *)NineDevice9_CreateVolumeTexture
,
3440 (void *)NineDevice9_CreateCubeTexture
,
3441 (void *)NineDevice9_CreateVertexBuffer
,
3442 (void *)NineDevice9_CreateIndexBuffer
,
3443 (void *)NineDevice9_CreateRenderTarget
,
3444 (void *)NineDevice9_CreateDepthStencilSurface
,
3445 (void *)NineDevice9_UpdateSurface
,
3446 (void *)NineDevice9_UpdateTexture
,
3447 (void *)NineDevice9_GetRenderTargetData
,
3448 (void *)NineDevice9_GetFrontBufferData
,
3449 (void *)NineDevice9_StretchRect
,
3450 (void *)NineDevice9_ColorFill
,
3451 (void *)NineDevice9_CreateOffscreenPlainSurface
,
3452 (void *)NineDevice9_SetRenderTarget
,
3453 (void *)NineDevice9_GetRenderTarget
,
3454 (void *)NineDevice9_SetDepthStencilSurface
,
3455 (void *)NineDevice9_GetDepthStencilSurface
,
3456 (void *)NineDevice9_BeginScene
,
3457 (void *)NineDevice9_EndScene
,
3458 (void *)NineDevice9_Clear
,
3459 (void *)NineDevice9_SetTransform
,
3460 (void *)NineDevice9_GetTransform
,
3461 (void *)NineDevice9_MultiplyTransform
,
3462 (void *)NineDevice9_SetViewport
,
3463 (void *)NineDevice9_GetViewport
,
3464 (void *)NineDevice9_SetMaterial
,
3465 (void *)NineDevice9_GetMaterial
,
3466 (void *)NineDevice9_SetLight
,
3467 (void *)NineDevice9_GetLight
,
3468 (void *)NineDevice9_LightEnable
,
3469 (void *)NineDevice9_GetLightEnable
,
3470 (void *)NineDevice9_SetClipPlane
,
3471 (void *)NineDevice9_GetClipPlane
,
3472 (void *)NineDevice9_SetRenderState
,
3473 (void *)NineDevice9_GetRenderState
,
3474 (void *)NineDevice9_CreateStateBlock
,
3475 (void *)NineDevice9_BeginStateBlock
,
3476 (void *)NineDevice9_EndStateBlock
,
3477 (void *)NineDevice9_SetClipStatus
,
3478 (void *)NineDevice9_GetClipStatus
,
3479 (void *)NineDevice9_GetTexture
,
3480 (void *)NineDevice9_SetTexture
,
3481 (void *)NineDevice9_GetTextureStageState
,
3482 (void *)NineDevice9_SetTextureStageState
,
3483 (void *)NineDevice9_GetSamplerState
,
3484 (void *)NineDevice9_SetSamplerState
,
3485 (void *)NineDevice9_ValidateDevice
,
3486 (void *)NineDevice9_SetPaletteEntries
,
3487 (void *)NineDevice9_GetPaletteEntries
,
3488 (void *)NineDevice9_SetCurrentTexturePalette
,
3489 (void *)NineDevice9_GetCurrentTexturePalette
,
3490 (void *)NineDevice9_SetScissorRect
,
3491 (void *)NineDevice9_GetScissorRect
,
3492 (void *)NineDevice9_SetSoftwareVertexProcessing
,
3493 (void *)NineDevice9_GetSoftwareVertexProcessing
,
3494 (void *)NineDevice9_SetNPatchMode
,
3495 (void *)NineDevice9_GetNPatchMode
,
3496 (void *)NineDevice9_DrawPrimitive
,
3497 (void *)NineDevice9_DrawIndexedPrimitive
,
3498 (void *)NineDevice9_DrawPrimitiveUP
,
3499 (void *)NineDevice9_DrawIndexedPrimitiveUP
,
3500 (void *)NineDevice9_ProcessVertices
,
3501 (void *)NineDevice9_CreateVertexDeclaration
,
3502 (void *)NineDevice9_SetVertexDeclaration
,
3503 (void *)NineDevice9_GetVertexDeclaration
,
3504 (void *)NineDevice9_SetFVF
,
3505 (void *)NineDevice9_GetFVF
,
3506 (void *)NineDevice9_CreateVertexShader
,
3507 (void *)NineDevice9_SetVertexShader
,
3508 (void *)NineDevice9_GetVertexShader
,
3509 (void *)NineDevice9_SetVertexShaderConstantF
,
3510 (void *)NineDevice9_GetVertexShaderConstantF
,
3511 (void *)NineDevice9_SetVertexShaderConstantI
,
3512 (void *)NineDevice9_GetVertexShaderConstantI
,
3513 (void *)NineDevice9_SetVertexShaderConstantB
,
3514 (void *)NineDevice9_GetVertexShaderConstantB
,
3515 (void *)NineDevice9_SetStreamSource
,
3516 (void *)NineDevice9_GetStreamSource
,
3517 (void *)NineDevice9_SetStreamSourceFreq
,
3518 (void *)NineDevice9_GetStreamSourceFreq
,
3519 (void *)NineDevice9_SetIndices
,
3520 (void *)NineDevice9_GetIndices
,
3521 (void *)NineDevice9_CreatePixelShader
,
3522 (void *)NineDevice9_SetPixelShader
,
3523 (void *)NineDevice9_GetPixelShader
,
3524 (void *)NineDevice9_SetPixelShaderConstantF
,
3525 (void *)NineDevice9_GetPixelShaderConstantF
,
3526 (void *)NineDevice9_SetPixelShaderConstantI
,
3527 (void *)NineDevice9_GetPixelShaderConstantI
,
3528 (void *)NineDevice9_SetPixelShaderConstantB
,
3529 (void *)NineDevice9_GetPixelShaderConstantB
,
3530 (void *)NineDevice9_DrawRectPatch
,
3531 (void *)NineDevice9_DrawTriPatch
,
3532 (void *)NineDevice9_DeletePatch
,
3533 (void *)NineDevice9_CreateQuery
3536 static const GUID
*NineDevice9_IIDs
[] = {
3537 &IID_IDirect3DDevice9
,
3543 NineDevice9_new( struct pipe_screen
*pScreen
,
3544 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
3546 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
3548 ID3DPresentGroup
*pPresentationGroup
,
3549 struct d3dadapter9_context
*pCTX
,
3551 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
3552 struct NineDevice9
**ppOut
)
3555 lock
= !!(pCreationParameters
->BehaviorFlags
& D3DCREATE_MULTITHREADED
);
3557 NINE_NEW(Device9
, ppOut
, lock
, /* args */
3558 pScreen
, pCreationParameters
, pCaps
,
3559 pPresentationParameters
, pD3D9
, pPresentationGroup
, pCTX
,
3560 ex
, pFullscreenDisplayMode
);