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. */
23 #ifndef _NINE_DEVICE9_H_
24 #define _NINE_DEVICE9_H_
26 #include "d3dadapter/d3dadapter9.h"
31 #include "nine_helpers.h"
32 #include "nine_state.h"
34 struct gen_mipmap_state
;
35 struct util_hash_table
;
43 struct NineSwapChain9
;
44 struct NineStateBlock9
;
46 #include "util/list.h"
50 struct NineUnknown base
;
55 struct pipe_screen
*screen
;
56 /* For first time upload. No Sync with rendering thread */
57 struct pipe_context
*pipe_secondary
;
58 struct pipe_screen
*screen_sw
;
59 struct pipe_context
*pipe_sw
;
60 struct cso_context
*cso_sw
;
63 struct csmt_context
*csmt_ctx
;
66 /* creation parameters */
68 D3DDEVICE_CREATION_PARAMETERS params
;
72 ID3DPresentGroup
*present
;
73 struct NineSwapChain9
**swapchains
;
76 struct NineStateBlock9
*record
;
77 struct nine_state
*update
; /* state to update (&state / &record->state) */
78 struct nine_state state
; /* device state */
79 struct nine_context context
;
80 struct nine_state_sw_internal state_sw_internal
;
82 struct list_head update_buffers
;
83 struct list_head update_textures
;
84 struct list_head managed_buffers
;
85 struct list_head managed_textures
;
90 uint16_t vs_const_size
;
91 uint16_t ps_const_size
;
92 uint16_t max_vs_const_f
;
93 uint16_t max_ps_const_f
;
95 struct pipe_resource
*dummy_texture
;
96 struct pipe_sampler_view
*dummy_sampler_view
;
97 struct pipe_sampler_state dummy_sampler_state
;
99 struct gen_mipmap_state
*gen_mipmap
;
102 struct util_hash_table
*ht_vs
;
103 struct util_hash_table
*ht_ps
;
104 struct NineVertexShader9
*vs
;
105 struct NinePixelShader9
*ps
;
111 struct util_hash_table
*ht_fvf
;
115 struct pipe_resource
*image
;
118 POINT hotspot
; /* -1, -1 if no cursor image set */
122 void *hw_upload_temp
;
129 boolean user_sw_vbufs
;
130 boolean user_sw_cbufs
;
131 boolean window_space_position_support
;
134 boolean offset_units_unscaled
;
138 boolean buggy_barycentrics
;
141 struct u_upload_mgr
*vertex_uploader
;
142 struct u_upload_mgr
*index_uploader
;
143 struct u_upload_mgr
*constbuf_uploader
;
144 struct u_upload_mgr
*vertex_sw_uploader
;
145 struct u_upload_mgr
*constbuf_sw_uploader
;
146 unsigned constbuf_alignment
;
148 struct nine_range_pool range_pool
;
150 struct hud_context
*hud
; /* NULL if hud is disabled */
152 /* dummy vbo (containing 0 0 0 0) to bind if vertex shader input
153 * is not bound to anything by the vertex declaration */
154 struct pipe_resource
*dummy_vbo
;
155 BOOL device_needs_reset
;
156 int minor_version_num
;
157 long long available_texture_mem
;
158 long long available_texture_limit
;
160 /* software vertex processing */
163 static inline struct NineDevice9
*
164 NineDevice9( void *data
)
166 return (struct NineDevice9
*)data
;
170 NineDevice9_new( struct pipe_screen
*pScreen
,
171 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
173 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
175 ID3DPresentGroup
*pPresentationGroup
,
176 struct d3dadapter9_context
*pCTX
,
178 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
179 struct NineDevice9
**ppOut
,
180 int minorVersionNum
);
183 NineDevice9_ctor( struct NineDevice9
*This
,
184 struct NineUnknownParams
*pParams
,
185 struct pipe_screen
*pScreen
,
186 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
188 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
190 ID3DPresentGroup
*pPresentationGroup
,
191 struct d3dadapter9_context
*pCTX
,
193 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
194 int minorVersionNum
);
197 NineDevice9_dtor( struct NineDevice9
*This
);
199 /*** Nine private ***/
201 NineDevice9_SetDefaultState( struct NineDevice9
*This
, boolean is_reset
);
204 NineDevice9_GetScreen( struct NineDevice9
*This
);
206 struct pipe_context
*
207 NineDevice9_GetPipe( struct NineDevice9
*This
);
210 NineDevice9_GetCaps( struct NineDevice9
*This
);
212 /*** Direct3D public ***/
215 NineDevice9_TestCooperativeLevel( struct NineDevice9
*This
);
218 NineDevice9_GetAvailableTextureMem( struct NineDevice9
*This
);
221 NineDevice9_EvictManagedResources( struct NineDevice9
*This
);
224 NineDevice9_GetDirect3D( struct NineDevice9
*This
,
225 IDirect3D9
**ppD3D9
);
228 NineDevice9_GetDeviceCaps( struct NineDevice9
*This
,
232 NineDevice9_GetDisplayMode( struct NineDevice9
*This
,
234 D3DDISPLAYMODE
*pMode
);
237 NineDevice9_GetCreationParameters( struct NineDevice9
*This
,
238 D3DDEVICE_CREATION_PARAMETERS
*pParameters
);
241 NineDevice9_SetCursorProperties( struct NineDevice9
*This
,
244 IDirect3DSurface9
*pCursorBitmap
);
247 NineDevice9_SetCursorPosition( struct NineDevice9
*This
,
253 NineDevice9_ShowCursor( struct NineDevice9
*This
,
257 NineDevice9_CreateAdditionalSwapChain( struct NineDevice9
*This
,
258 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
259 IDirect3DSwapChain9
**pSwapChain
);
262 NineDevice9_GetSwapChain( struct NineDevice9
*This
,
264 IDirect3DSwapChain9
**pSwapChain
);
267 NineDevice9_GetNumberOfSwapChains( struct NineDevice9
*This
);
270 NineDevice9_Reset( struct NineDevice9
*This
,
271 D3DPRESENT_PARAMETERS
*pPresentationParameters
);
274 NineDevice9_Present( struct NineDevice9
*This
,
275 const RECT
*pSourceRect
,
276 const RECT
*pDestRect
,
277 HWND hDestWindowOverride
,
278 const RGNDATA
*pDirtyRegion
);
281 NineDevice9_GetBackBuffer( struct NineDevice9
*This
,
284 D3DBACKBUFFER_TYPE Type
,
285 IDirect3DSurface9
**ppBackBuffer
);
288 NineDevice9_GetRasterStatus( struct NineDevice9
*This
,
290 D3DRASTER_STATUS
*pRasterStatus
);
293 NineDevice9_SetDialogBoxMode( struct NineDevice9
*This
,
294 BOOL bEnableDialogs
);
297 NineDevice9_SetGammaRamp( struct NineDevice9
*This
,
300 const D3DGAMMARAMP
*pRamp
);
303 NineDevice9_GetGammaRamp( struct NineDevice9
*This
,
305 D3DGAMMARAMP
*pRamp
);
308 NineDevice9_CreateTexture( struct NineDevice9
*This
,
315 IDirect3DTexture9
**ppTexture
,
316 HANDLE
*pSharedHandle
);
319 NineDevice9_CreateVolumeTexture( struct NineDevice9
*This
,
327 IDirect3DVolumeTexture9
**ppVolumeTexture
,
328 HANDLE
*pSharedHandle
);
331 NineDevice9_CreateCubeTexture( struct NineDevice9
*This
,
337 IDirect3DCubeTexture9
**ppCubeTexture
,
338 HANDLE
*pSharedHandle
);
341 NineDevice9_CreateVertexBuffer( struct NineDevice9
*This
,
346 IDirect3DVertexBuffer9
**ppVertexBuffer
,
347 HANDLE
*pSharedHandle
);
350 NineDevice9_CreateIndexBuffer( struct NineDevice9
*This
,
355 IDirect3DIndexBuffer9
**ppIndexBuffer
,
356 HANDLE
*pSharedHandle
);
359 NineDevice9_CreateRenderTarget( struct NineDevice9
*This
,
363 D3DMULTISAMPLE_TYPE MultiSample
,
364 DWORD MultisampleQuality
,
366 IDirect3DSurface9
**ppSurface
,
367 HANDLE
*pSharedHandle
);
370 NineDevice9_CreateDepthStencilSurface( struct NineDevice9
*This
,
374 D3DMULTISAMPLE_TYPE MultiSample
,
375 DWORD MultisampleQuality
,
377 IDirect3DSurface9
**ppSurface
,
378 HANDLE
*pSharedHandle
);
381 NineDevice9_UpdateSurface( struct NineDevice9
*This
,
382 IDirect3DSurface9
*pSourceSurface
,
383 const RECT
*pSourceRect
,
384 IDirect3DSurface9
*pDestinationSurface
,
385 const POINT
*pDestPoint
);
388 NineDevice9_UpdateTexture( struct NineDevice9
*This
,
389 IDirect3DBaseTexture9
*pSourceTexture
,
390 IDirect3DBaseTexture9
*pDestinationTexture
);
393 NineDevice9_GetRenderTargetData( struct NineDevice9
*This
,
394 IDirect3DSurface9
*pRenderTarget
,
395 IDirect3DSurface9
*pDestSurface
);
398 NineDevice9_GetFrontBufferData( struct NineDevice9
*This
,
400 IDirect3DSurface9
*pDestSurface
);
403 NineDevice9_StretchRect( struct NineDevice9
*This
,
404 IDirect3DSurface9
*pSourceSurface
,
405 const RECT
*pSourceRect
,
406 IDirect3DSurface9
*pDestSurface
,
407 const RECT
*pDestRect
,
408 D3DTEXTUREFILTERTYPE Filter
);
411 NineDevice9_ColorFill( struct NineDevice9
*This
,
412 IDirect3DSurface9
*pSurface
,
417 NineDevice9_CreateOffscreenPlainSurface( struct NineDevice9
*This
,
422 IDirect3DSurface9
**ppSurface
,
423 HANDLE
*pSharedHandle
);
426 NineDevice9_SetRenderTarget( struct NineDevice9
*This
,
427 DWORD RenderTargetIndex
,
428 IDirect3DSurface9
*pRenderTarget
);
431 NineDevice9_GetRenderTarget( struct NineDevice9
*This
,
432 DWORD RenderTargetIndex
,
433 IDirect3DSurface9
**ppRenderTarget
);
436 NineDevice9_SetDepthStencilSurface( struct NineDevice9
*This
,
437 IDirect3DSurface9
*pNewZStencil
);
440 NineDevice9_GetDepthStencilSurface( struct NineDevice9
*This
,
441 IDirect3DSurface9
**ppZStencilSurface
);
444 NineDevice9_BeginScene( struct NineDevice9
*This
);
447 NineDevice9_EndScene( struct NineDevice9
*This
);
450 NineDevice9_Clear( struct NineDevice9
*This
,
452 const D3DRECT
*pRects
,
459 NineDevice9_SetTransform( struct NineDevice9
*This
,
460 D3DTRANSFORMSTATETYPE State
,
461 const D3DMATRIX
*pMatrix
);
464 NineDevice9_GetTransform( struct NineDevice9
*This
,
465 D3DTRANSFORMSTATETYPE State
,
466 D3DMATRIX
*pMatrix
);
469 NineDevice9_MultiplyTransform( struct NineDevice9
*This
,
470 D3DTRANSFORMSTATETYPE State
,
471 const D3DMATRIX
*pMatrix
);
474 NineDevice9_SetViewport( struct NineDevice9
*This
,
475 const D3DVIEWPORT9
*pViewport
);
478 NineDevice9_GetViewport( struct NineDevice9
*This
,
479 D3DVIEWPORT9
*pViewport
);
482 NineDevice9_SetMaterial( struct NineDevice9
*This
,
483 const D3DMATERIAL9
*pMaterial
);
486 NineDevice9_GetMaterial( struct NineDevice9
*This
,
487 D3DMATERIAL9
*pMaterial
);
490 NineDevice9_SetLight( struct NineDevice9
*This
,
492 const D3DLIGHT9
*pLight
);
495 NineDevice9_GetLight( struct NineDevice9
*This
,
500 NineDevice9_LightEnable( struct NineDevice9
*This
,
505 NineDevice9_GetLightEnable( struct NineDevice9
*This
,
510 NineDevice9_SetClipPlane( struct NineDevice9
*This
,
512 const float *pPlane
);
515 NineDevice9_GetClipPlane( struct NineDevice9
*This
,
520 NineDevice9_SetRenderState( struct NineDevice9
*This
,
521 D3DRENDERSTATETYPE State
,
525 NineDevice9_GetRenderState( struct NineDevice9
*This
,
526 D3DRENDERSTATETYPE State
,
530 NineDevice9_CreateStateBlock( struct NineDevice9
*This
,
531 D3DSTATEBLOCKTYPE Type
,
532 IDirect3DStateBlock9
**ppSB
);
535 NineDevice9_BeginStateBlock( struct NineDevice9
*This
);
538 NineDevice9_EndStateBlock( struct NineDevice9
*This
,
539 IDirect3DStateBlock9
**ppSB
);
542 NineDevice9_SetClipStatus( struct NineDevice9
*This
,
543 const D3DCLIPSTATUS9
*pClipStatus
);
546 NineDevice9_GetClipStatus( struct NineDevice9
*This
,
547 D3DCLIPSTATUS9
*pClipStatus
);
550 NineDevice9_GetTexture( struct NineDevice9
*This
,
552 IDirect3DBaseTexture9
**ppTexture
);
555 NineDevice9_SetTexture( struct NineDevice9
*This
,
557 IDirect3DBaseTexture9
*pTexture
);
560 NineDevice9_GetTextureStageState( struct NineDevice9
*This
,
562 D3DTEXTURESTAGESTATETYPE Type
,
566 NineDevice9_SetTextureStageState( struct NineDevice9
*This
,
568 D3DTEXTURESTAGESTATETYPE Type
,
572 NineDevice9_GetSamplerState( struct NineDevice9
*This
,
574 D3DSAMPLERSTATETYPE Type
,
578 NineDevice9_SetSamplerState( struct NineDevice9
*This
,
580 D3DSAMPLERSTATETYPE Type
,
584 NineDevice9_ValidateDevice( struct NineDevice9
*This
,
588 NineDevice9_SetPaletteEntries( struct NineDevice9
*This
,
590 const PALETTEENTRY
*pEntries
);
593 NineDevice9_GetPaletteEntries( struct NineDevice9
*This
,
595 PALETTEENTRY
*pEntries
);
598 NineDevice9_SetCurrentTexturePalette( struct NineDevice9
*This
,
599 UINT PaletteNumber
);
602 NineDevice9_GetCurrentTexturePalette( struct NineDevice9
*This
,
603 UINT
*PaletteNumber
);
606 NineDevice9_SetScissorRect( struct NineDevice9
*This
,
610 NineDevice9_GetScissorRect( struct NineDevice9
*This
,
614 NineDevice9_SetSoftwareVertexProcessing( struct NineDevice9
*This
,
618 NineDevice9_GetSoftwareVertexProcessing( struct NineDevice9
*This
);
621 NineDevice9_SetNPatchMode( struct NineDevice9
*This
,
625 NineDevice9_GetNPatchMode( struct NineDevice9
*This
);
628 NineDevice9_DrawPrimitive( struct NineDevice9
*This
,
629 D3DPRIMITIVETYPE PrimitiveType
,
631 UINT PrimitiveCount
);
634 NineDevice9_DrawIndexedPrimitive( struct NineDevice9
*This
,
635 D3DPRIMITIVETYPE PrimitiveType
,
643 NineDevice9_DrawPrimitiveUP( struct NineDevice9
*This
,
644 D3DPRIMITIVETYPE PrimitiveType
,
646 const void *pVertexStreamZeroData
,
647 UINT VertexStreamZeroStride
);
650 NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9
*This
,
651 D3DPRIMITIVETYPE PrimitiveType
,
655 const void *pIndexData
,
656 D3DFORMAT IndexDataFormat
,
657 const void *pVertexStreamZeroData
,
658 UINT VertexStreamZeroStride
);
661 NineDevice9_ProcessVertices( struct NineDevice9
*This
,
665 IDirect3DVertexBuffer9
*pDestBuffer
,
666 IDirect3DVertexDeclaration9
*pVertexDecl
,
670 NineDevice9_CreateVertexDeclaration( struct NineDevice9
*This
,
671 const D3DVERTEXELEMENT9
*pVertexElements
,
672 IDirect3DVertexDeclaration9
**ppDecl
);
675 NineDevice9_SetVertexDeclaration( struct NineDevice9
*This
,
676 IDirect3DVertexDeclaration9
*pDecl
);
679 NineDevice9_GetVertexDeclaration( struct NineDevice9
*This
,
680 IDirect3DVertexDeclaration9
**ppDecl
);
683 NineDevice9_SetFVF( struct NineDevice9
*This
,
687 NineDevice9_GetFVF( struct NineDevice9
*This
,
691 NineDevice9_CreateVertexShader( struct NineDevice9
*This
,
692 const DWORD
*pFunction
,
693 IDirect3DVertexShader9
**ppShader
);
696 NineDevice9_SetVertexShader( struct NineDevice9
*This
,
697 IDirect3DVertexShader9
*pShader
);
700 NineDevice9_GetVertexShader( struct NineDevice9
*This
,
701 IDirect3DVertexShader9
**ppShader
);
704 NineDevice9_SetVertexShaderConstantF( struct NineDevice9
*This
,
706 const float *pConstantData
,
707 UINT Vector4fCount
);
710 NineDevice9_GetVertexShaderConstantF( struct NineDevice9
*This
,
712 float *pConstantData
,
713 UINT Vector4fCount
);
716 NineDevice9_SetVertexShaderConstantI( struct NineDevice9
*This
,
718 const int *pConstantData
,
719 UINT Vector4iCount
);
722 NineDevice9_GetVertexShaderConstantI( struct NineDevice9
*This
,
725 UINT Vector4iCount
);
728 NineDevice9_SetVertexShaderConstantB( struct NineDevice9
*This
,
730 const BOOL
*pConstantData
,
734 NineDevice9_GetVertexShaderConstantB( struct NineDevice9
*This
,
740 NineDevice9_SetStreamSource( struct NineDevice9
*This
,
742 IDirect3DVertexBuffer9
*pStreamData
,
747 NineDevice9_GetStreamSource( struct NineDevice9
*This
,
749 IDirect3DVertexBuffer9
**ppStreamData
,
750 UINT
*pOffsetInBytes
,
754 NineDevice9_SetStreamSourceFreq( struct NineDevice9
*This
,
759 NineDevice9_GetStreamSourceFreq( struct NineDevice9
*This
,
764 NineDevice9_SetIndices( struct NineDevice9
*This
,
765 IDirect3DIndexBuffer9
*pIndexData
);
768 NineDevice9_GetIndices( struct NineDevice9
*This
,
769 IDirect3DIndexBuffer9
**ppIndexData
/*,
770 UINT *pBaseVertexIndex */ );
773 NineDevice9_CreatePixelShader( struct NineDevice9
*This
,
774 const DWORD
*pFunction
,
775 IDirect3DPixelShader9
**ppShader
);
778 NineDevice9_SetPixelShader( struct NineDevice9
*This
,
779 IDirect3DPixelShader9
*pShader
);
782 NineDevice9_GetPixelShader( struct NineDevice9
*This
,
783 IDirect3DPixelShader9
**ppShader
);
786 NineDevice9_SetPixelShaderConstantF( struct NineDevice9
*This
,
788 const float *pConstantData
,
789 UINT Vector4fCount
);
792 NineDevice9_GetPixelShaderConstantF( struct NineDevice9
*This
,
794 float *pConstantData
,
795 UINT Vector4fCount
);
798 NineDevice9_SetPixelShaderConstantI( struct NineDevice9
*This
,
800 const int *pConstantData
,
801 UINT Vector4iCount
);
804 NineDevice9_GetPixelShaderConstantI( struct NineDevice9
*This
,
807 UINT Vector4iCount
);
810 NineDevice9_SetPixelShaderConstantB( struct NineDevice9
*This
,
812 const BOOL
*pConstantData
,
816 NineDevice9_GetPixelShaderConstantB( struct NineDevice9
*This
,
822 NineDevice9_DrawRectPatch( struct NineDevice9
*This
,
824 const float *pNumSegs
,
825 const D3DRECTPATCH_INFO
*pRectPatchInfo
);
828 NineDevice9_DrawTriPatch( struct NineDevice9
*This
,
830 const float *pNumSegs
,
831 const D3DTRIPATCH_INFO
*pTriPatchInfo
);
834 NineDevice9_DeletePatch( struct NineDevice9
*This
,
838 NineDevice9_CreateQuery( struct NineDevice9
*This
,
840 IDirect3DQuery9
**ppQuery
);
842 #endif /* _NINE_DEVICE9_H_ */