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
;
42 struct NineSwapChain9
;
43 struct NineStateBlock9
;
45 #include "util/list.h"
49 struct NineUnknown base
;
53 struct pipe_screen
*screen
;
54 struct pipe_context
*pipe
;
55 struct cso_context
*cso
;
57 /* creation parameters */
59 D3DDEVICE_CREATION_PARAMETERS params
;
63 ID3DPresentGroup
*present
;
64 struct NineSwapChain9
**swapchains
;
67 struct NineStateBlock9
*record
;
68 struct nine_state
*update
; /* state to update (&state / &record->state) */
69 struct nine_state state
; /* device state */
71 struct list_head update_buffers
;
72 struct list_head update_textures
;
73 struct list_head managed_buffers
;
74 struct list_head managed_textures
;
79 boolean prefer_user_constbuf
;
81 struct pipe_resource
*constbuf_vs
;
82 struct pipe_resource
*constbuf_ps
;
83 uint16_t vs_const_size
;
84 uint16_t ps_const_size
;
85 uint16_t max_vs_const_f
;
86 uint16_t max_ps_const_f
;
88 struct pipe_resource
*dummy_texture
;
89 struct pipe_sampler_view
*dummy_sampler_view
;
90 struct pipe_sampler_state dummy_sampler_state
;
92 struct gen_mipmap_state
*gen_mipmap
;
95 struct util_hash_table
*ht_vs
;
96 struct util_hash_table
*ht_ps
;
97 struct NineVertexShader9
*vs
;
98 struct NinePixelShader9
*ps
;
104 struct util_hash_table
*ht_fvf
;
108 struct pipe_resource
*image
;
111 POINT hotspot
; /* -1, -1 if no cursor image set */
121 boolean window_space_position_support
;
124 boolean offset_units_unscaled
;
128 boolean buggy_barycentrics
;
131 struct u_upload_mgr
*vertex_uploader
;
132 struct u_upload_mgr
*index_uploader
;
133 struct u_upload_mgr
*constbuf_uploader
;
134 unsigned constbuf_alignment
;
136 struct nine_range_pool range_pool
;
138 struct hud_context
*hud
; /* NULL if hud is disabled */
140 /* dummy vbo (containing 0 0 0 0) to bind if vertex shader input
141 * is not bound to anything by the vertex declaration */
142 struct pipe_resource
*dummy_vbo
;
143 BOOL device_needs_reset
;
144 int minor_version_num
;
145 long long available_texture_mem
;
146 long long available_texture_limit
;
148 /* software vertex processing */
151 static inline struct NineDevice9
*
152 NineDevice9( void *data
)
154 return (struct NineDevice9
*)data
;
158 NineDevice9_new( struct pipe_screen
*pScreen
,
159 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
161 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
163 ID3DPresentGroup
*pPresentationGroup
,
164 struct d3dadapter9_context
*pCTX
,
166 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
167 struct NineDevice9
**ppOut
,
168 int minorVersionNum
);
171 NineDevice9_ctor( struct NineDevice9
*This
,
172 struct NineUnknownParams
*pParams
,
173 struct pipe_screen
*pScreen
,
174 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
176 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
178 ID3DPresentGroup
*pPresentationGroup
,
179 struct d3dadapter9_context
*pCTX
,
181 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
182 int minorVersionNum
);
185 NineDevice9_dtor( struct NineDevice9
*This
);
187 /*** Nine private ***/
189 NineDevice9_SetDefaultState( struct NineDevice9
*This
, boolean is_reset
);
192 NineDevice9_GetScreen( struct NineDevice9
*This
);
194 struct pipe_context
*
195 NineDevice9_GetPipe( struct NineDevice9
*This
);
198 NineDevice9_GetCSO( struct NineDevice9
*This
);
201 NineDevice9_GetCaps( struct NineDevice9
*This
);
203 /*** Direct3D public ***/
206 NineDevice9_TestCooperativeLevel( struct NineDevice9
*This
);
209 NineDevice9_GetAvailableTextureMem( struct NineDevice9
*This
);
212 NineDevice9_EvictManagedResources( struct NineDevice9
*This
);
215 NineDevice9_GetDirect3D( struct NineDevice9
*This
,
216 IDirect3D9
**ppD3D9
);
219 NineDevice9_GetDeviceCaps( struct NineDevice9
*This
,
223 NineDevice9_GetDisplayMode( struct NineDevice9
*This
,
225 D3DDISPLAYMODE
*pMode
);
228 NineDevice9_GetCreationParameters( struct NineDevice9
*This
,
229 D3DDEVICE_CREATION_PARAMETERS
*pParameters
);
232 NineDevice9_SetCursorProperties( struct NineDevice9
*This
,
235 IDirect3DSurface9
*pCursorBitmap
);
238 NineDevice9_SetCursorPosition( struct NineDevice9
*This
,
244 NineDevice9_ShowCursor( struct NineDevice9
*This
,
248 NineDevice9_CreateAdditionalSwapChain( struct NineDevice9
*This
,
249 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
250 IDirect3DSwapChain9
**pSwapChain
);
253 NineDevice9_GetSwapChain( struct NineDevice9
*This
,
255 IDirect3DSwapChain9
**pSwapChain
);
258 NineDevice9_GetNumberOfSwapChains( struct NineDevice9
*This
);
261 NineDevice9_Reset( struct NineDevice9
*This
,
262 D3DPRESENT_PARAMETERS
*pPresentationParameters
);
265 NineDevice9_Present( struct NineDevice9
*This
,
266 const RECT
*pSourceRect
,
267 const RECT
*pDestRect
,
268 HWND hDestWindowOverride
,
269 const RGNDATA
*pDirtyRegion
);
272 NineDevice9_GetBackBuffer( struct NineDevice9
*This
,
275 D3DBACKBUFFER_TYPE Type
,
276 IDirect3DSurface9
**ppBackBuffer
);
279 NineDevice9_GetRasterStatus( struct NineDevice9
*This
,
281 D3DRASTER_STATUS
*pRasterStatus
);
284 NineDevice9_SetDialogBoxMode( struct NineDevice9
*This
,
285 BOOL bEnableDialogs
);
288 NineDevice9_SetGammaRamp( struct NineDevice9
*This
,
291 const D3DGAMMARAMP
*pRamp
);
294 NineDevice9_GetGammaRamp( struct NineDevice9
*This
,
296 D3DGAMMARAMP
*pRamp
);
299 NineDevice9_CreateTexture( struct NineDevice9
*This
,
306 IDirect3DTexture9
**ppTexture
,
307 HANDLE
*pSharedHandle
);
310 NineDevice9_CreateVolumeTexture( struct NineDevice9
*This
,
318 IDirect3DVolumeTexture9
**ppVolumeTexture
,
319 HANDLE
*pSharedHandle
);
322 NineDevice9_CreateCubeTexture( struct NineDevice9
*This
,
328 IDirect3DCubeTexture9
**ppCubeTexture
,
329 HANDLE
*pSharedHandle
);
332 NineDevice9_CreateVertexBuffer( struct NineDevice9
*This
,
337 IDirect3DVertexBuffer9
**ppVertexBuffer
,
338 HANDLE
*pSharedHandle
);
341 NineDevice9_CreateIndexBuffer( struct NineDevice9
*This
,
346 IDirect3DIndexBuffer9
**ppIndexBuffer
,
347 HANDLE
*pSharedHandle
);
350 NineDevice9_CreateRenderTarget( struct NineDevice9
*This
,
354 D3DMULTISAMPLE_TYPE MultiSample
,
355 DWORD MultisampleQuality
,
357 IDirect3DSurface9
**ppSurface
,
358 HANDLE
*pSharedHandle
);
361 NineDevice9_CreateDepthStencilSurface( struct NineDevice9
*This
,
365 D3DMULTISAMPLE_TYPE MultiSample
,
366 DWORD MultisampleQuality
,
368 IDirect3DSurface9
**ppSurface
,
369 HANDLE
*pSharedHandle
);
372 NineDevice9_UpdateSurface( struct NineDevice9
*This
,
373 IDirect3DSurface9
*pSourceSurface
,
374 const RECT
*pSourceRect
,
375 IDirect3DSurface9
*pDestinationSurface
,
376 const POINT
*pDestPoint
);
379 NineDevice9_UpdateTexture( struct NineDevice9
*This
,
380 IDirect3DBaseTexture9
*pSourceTexture
,
381 IDirect3DBaseTexture9
*pDestinationTexture
);
384 NineDevice9_GetRenderTargetData( struct NineDevice9
*This
,
385 IDirect3DSurface9
*pRenderTarget
,
386 IDirect3DSurface9
*pDestSurface
);
389 NineDevice9_GetFrontBufferData( struct NineDevice9
*This
,
391 IDirect3DSurface9
*pDestSurface
);
394 NineDevice9_StretchRect( struct NineDevice9
*This
,
395 IDirect3DSurface9
*pSourceSurface
,
396 const RECT
*pSourceRect
,
397 IDirect3DSurface9
*pDestSurface
,
398 const RECT
*pDestRect
,
399 D3DTEXTUREFILTERTYPE Filter
);
402 NineDevice9_ColorFill( struct NineDevice9
*This
,
403 IDirect3DSurface9
*pSurface
,
408 NineDevice9_CreateOffscreenPlainSurface( struct NineDevice9
*This
,
413 IDirect3DSurface9
**ppSurface
,
414 HANDLE
*pSharedHandle
);
417 NineDevice9_SetRenderTarget( struct NineDevice9
*This
,
418 DWORD RenderTargetIndex
,
419 IDirect3DSurface9
*pRenderTarget
);
422 NineDevice9_GetRenderTarget( struct NineDevice9
*This
,
423 DWORD RenderTargetIndex
,
424 IDirect3DSurface9
**ppRenderTarget
);
427 NineDevice9_SetDepthStencilSurface( struct NineDevice9
*This
,
428 IDirect3DSurface9
*pNewZStencil
);
431 NineDevice9_GetDepthStencilSurface( struct NineDevice9
*This
,
432 IDirect3DSurface9
**ppZStencilSurface
);
435 NineDevice9_BeginScene( struct NineDevice9
*This
);
438 NineDevice9_EndScene( struct NineDevice9
*This
);
441 NineDevice9_Clear( struct NineDevice9
*This
,
443 const D3DRECT
*pRects
,
450 NineDevice9_SetTransform( struct NineDevice9
*This
,
451 D3DTRANSFORMSTATETYPE State
,
452 const D3DMATRIX
*pMatrix
);
455 NineDevice9_GetTransform( struct NineDevice9
*This
,
456 D3DTRANSFORMSTATETYPE State
,
457 D3DMATRIX
*pMatrix
);
460 NineDevice9_MultiplyTransform( struct NineDevice9
*This
,
461 D3DTRANSFORMSTATETYPE State
,
462 const D3DMATRIX
*pMatrix
);
465 NineDevice9_SetViewport( struct NineDevice9
*This
,
466 const D3DVIEWPORT9
*pViewport
);
469 NineDevice9_GetViewport( struct NineDevice9
*This
,
470 D3DVIEWPORT9
*pViewport
);
473 NineDevice9_SetMaterial( struct NineDevice9
*This
,
474 const D3DMATERIAL9
*pMaterial
);
477 NineDevice9_GetMaterial( struct NineDevice9
*This
,
478 D3DMATERIAL9
*pMaterial
);
481 NineDevice9_SetLight( struct NineDevice9
*This
,
483 const D3DLIGHT9
*pLight
);
486 NineDevice9_GetLight( struct NineDevice9
*This
,
491 NineDevice9_LightEnable( struct NineDevice9
*This
,
496 NineDevice9_GetLightEnable( struct NineDevice9
*This
,
501 NineDevice9_SetClipPlane( struct NineDevice9
*This
,
503 const float *pPlane
);
506 NineDevice9_GetClipPlane( struct NineDevice9
*This
,
511 NineDevice9_SetRenderState( struct NineDevice9
*This
,
512 D3DRENDERSTATETYPE State
,
516 NineDevice9_GetRenderState( struct NineDevice9
*This
,
517 D3DRENDERSTATETYPE State
,
521 NineDevice9_CreateStateBlock( struct NineDevice9
*This
,
522 D3DSTATEBLOCKTYPE Type
,
523 IDirect3DStateBlock9
**ppSB
);
526 NineDevice9_BeginStateBlock( struct NineDevice9
*This
);
529 NineDevice9_EndStateBlock( struct NineDevice9
*This
,
530 IDirect3DStateBlock9
**ppSB
);
533 NineDevice9_SetClipStatus( struct NineDevice9
*This
,
534 const D3DCLIPSTATUS9
*pClipStatus
);
537 NineDevice9_GetClipStatus( struct NineDevice9
*This
,
538 D3DCLIPSTATUS9
*pClipStatus
);
541 NineDevice9_GetTexture( struct NineDevice9
*This
,
543 IDirect3DBaseTexture9
**ppTexture
);
546 NineDevice9_SetTexture( struct NineDevice9
*This
,
548 IDirect3DBaseTexture9
*pTexture
);
551 NineDevice9_GetTextureStageState( struct NineDevice9
*This
,
553 D3DTEXTURESTAGESTATETYPE Type
,
557 NineDevice9_SetTextureStageState( struct NineDevice9
*This
,
559 D3DTEXTURESTAGESTATETYPE Type
,
563 NineDevice9_GetSamplerState( struct NineDevice9
*This
,
565 D3DSAMPLERSTATETYPE Type
,
569 NineDevice9_SetSamplerState( struct NineDevice9
*This
,
571 D3DSAMPLERSTATETYPE Type
,
575 NineDevice9_ValidateDevice( struct NineDevice9
*This
,
579 NineDevice9_SetPaletteEntries( struct NineDevice9
*This
,
581 const PALETTEENTRY
*pEntries
);
584 NineDevice9_GetPaletteEntries( struct NineDevice9
*This
,
586 PALETTEENTRY
*pEntries
);
589 NineDevice9_SetCurrentTexturePalette( struct NineDevice9
*This
,
590 UINT PaletteNumber
);
593 NineDevice9_GetCurrentTexturePalette( struct NineDevice9
*This
,
594 UINT
*PaletteNumber
);
597 NineDevice9_SetScissorRect( struct NineDevice9
*This
,
601 NineDevice9_GetScissorRect( struct NineDevice9
*This
,
605 NineDevice9_SetSoftwareVertexProcessing( struct NineDevice9
*This
,
609 NineDevice9_GetSoftwareVertexProcessing( struct NineDevice9
*This
);
612 NineDevice9_SetNPatchMode( struct NineDevice9
*This
,
616 NineDevice9_GetNPatchMode( struct NineDevice9
*This
);
619 NineDevice9_DrawPrimitive( struct NineDevice9
*This
,
620 D3DPRIMITIVETYPE PrimitiveType
,
622 UINT PrimitiveCount
);
625 NineDevice9_DrawIndexedPrimitive( struct NineDevice9
*This
,
626 D3DPRIMITIVETYPE PrimitiveType
,
634 NineDevice9_DrawPrimitiveUP( struct NineDevice9
*This
,
635 D3DPRIMITIVETYPE PrimitiveType
,
637 const void *pVertexStreamZeroData
,
638 UINT VertexStreamZeroStride
);
641 NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9
*This
,
642 D3DPRIMITIVETYPE PrimitiveType
,
646 const void *pIndexData
,
647 D3DFORMAT IndexDataFormat
,
648 const void *pVertexStreamZeroData
,
649 UINT VertexStreamZeroStride
);
652 NineDevice9_ProcessVertices( struct NineDevice9
*This
,
656 IDirect3DVertexBuffer9
*pDestBuffer
,
657 IDirect3DVertexDeclaration9
*pVertexDecl
,
661 NineDevice9_CreateVertexDeclaration( struct NineDevice9
*This
,
662 const D3DVERTEXELEMENT9
*pVertexElements
,
663 IDirect3DVertexDeclaration9
**ppDecl
);
666 NineDevice9_SetVertexDeclaration( struct NineDevice9
*This
,
667 IDirect3DVertexDeclaration9
*pDecl
);
670 NineDevice9_GetVertexDeclaration( struct NineDevice9
*This
,
671 IDirect3DVertexDeclaration9
**ppDecl
);
674 NineDevice9_SetFVF( struct NineDevice9
*This
,
678 NineDevice9_GetFVF( struct NineDevice9
*This
,
682 NineDevice9_CreateVertexShader( struct NineDevice9
*This
,
683 const DWORD
*pFunction
,
684 IDirect3DVertexShader9
**ppShader
);
687 NineDevice9_SetVertexShader( struct NineDevice9
*This
,
688 IDirect3DVertexShader9
*pShader
);
691 NineDevice9_GetVertexShader( struct NineDevice9
*This
,
692 IDirect3DVertexShader9
**ppShader
);
695 NineDevice9_SetVertexShaderConstantF( struct NineDevice9
*This
,
697 const float *pConstantData
,
698 UINT Vector4fCount
);
701 NineDevice9_GetVertexShaderConstantF( struct NineDevice9
*This
,
703 float *pConstantData
,
704 UINT Vector4fCount
);
707 NineDevice9_SetVertexShaderConstantI( struct NineDevice9
*This
,
709 const int *pConstantData
,
710 UINT Vector4iCount
);
713 NineDevice9_GetVertexShaderConstantI( struct NineDevice9
*This
,
716 UINT Vector4iCount
);
719 NineDevice9_SetVertexShaderConstantB( struct NineDevice9
*This
,
721 const BOOL
*pConstantData
,
725 NineDevice9_GetVertexShaderConstantB( struct NineDevice9
*This
,
731 NineDevice9_SetStreamSource( struct NineDevice9
*This
,
733 IDirect3DVertexBuffer9
*pStreamData
,
738 NineDevice9_GetStreamSource( struct NineDevice9
*This
,
740 IDirect3DVertexBuffer9
**ppStreamData
,
741 UINT
*pOffsetInBytes
,
745 NineDevice9_SetStreamSourceFreq( struct NineDevice9
*This
,
750 NineDevice9_GetStreamSourceFreq( struct NineDevice9
*This
,
755 NineDevice9_SetIndices( struct NineDevice9
*This
,
756 IDirect3DIndexBuffer9
*pIndexData
);
759 NineDevice9_GetIndices( struct NineDevice9
*This
,
760 IDirect3DIndexBuffer9
**ppIndexData
/*,
761 UINT *pBaseVertexIndex */ );
764 NineDevice9_CreatePixelShader( struct NineDevice9
*This
,
765 const DWORD
*pFunction
,
766 IDirect3DPixelShader9
**ppShader
);
769 NineDevice9_SetPixelShader( struct NineDevice9
*This
,
770 IDirect3DPixelShader9
*pShader
);
773 NineDevice9_GetPixelShader( struct NineDevice9
*This
,
774 IDirect3DPixelShader9
**ppShader
);
777 NineDevice9_SetPixelShaderConstantF( struct NineDevice9
*This
,
779 const float *pConstantData
,
780 UINT Vector4fCount
);
783 NineDevice9_GetPixelShaderConstantF( struct NineDevice9
*This
,
785 float *pConstantData
,
786 UINT Vector4fCount
);
789 NineDevice9_SetPixelShaderConstantI( struct NineDevice9
*This
,
791 const int *pConstantData
,
792 UINT Vector4iCount
);
795 NineDevice9_GetPixelShaderConstantI( struct NineDevice9
*This
,
798 UINT Vector4iCount
);
801 NineDevice9_SetPixelShaderConstantB( struct NineDevice9
*This
,
803 const BOOL
*pConstantData
,
807 NineDevice9_GetPixelShaderConstantB( struct NineDevice9
*This
,
813 NineDevice9_DrawRectPatch( struct NineDevice9
*This
,
815 const float *pNumSegs
,
816 const D3DRECTPATCH_INFO
*pRectPatchInfo
);
819 NineDevice9_DrawTriPatch( struct NineDevice9
*This
,
821 const float *pNumSegs
,
822 const D3DTRIPATCH_INFO
*pTriPatchInfo
);
825 NineDevice9_DeletePatch( struct NineDevice9
*This
,
829 NineDevice9_CreateQuery( struct NineDevice9
*This
,
831 IDirect3DQuery9
**ppQuery
);
833 #endif /* _NINE_DEVICE9_H_ */