Path: blob/21.2-virgl/src/gallium/frontends/nine/device9ex.c
4561 views
/*1* Copyright 2011 Joakim Sindholt <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* on the rights to use, copy, modify, merge, publish, distribute, sub7* license, and/or sell copies of the Software, and to permit persons to whom8* the Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE. */2122#include "device9.h"23#include "device9ex.h"24#include "nine_pipe.h"25#include "swapchain9ex.h"2627#include "nine_helpers.h"2829#include "util/macros.h"3031#define DBG_CHANNEL DBG_DEVICE3233static HRESULT34NineDevice9Ex_ctor( struct NineDevice9Ex *This,35struct NineUnknownParams *pParams,36struct pipe_screen *pScreen,37D3DDEVICE_CREATION_PARAMETERS *pCreationParameters,38D3DCAPS9 *pCaps,39D3DPRESENT_PARAMETERS *pPresentationParameters,40D3DDISPLAYMODEEX *pFullscreenDisplayMode,41IDirect3D9Ex *pD3D9Ex,42ID3DPresentGroup *pPresentationGroup,43struct d3dadapter9_context *pCTX,44int minorVersionNum )45{46DBG("This=%p pParams=%p pScreen=%p pCreationParameters=%p pCaps=%p "47"pPresentationParameters=%p pFullscreenDisplayMode=%p "48"pD3D9Ex=%p pPresentationGroup=%p pCTX=%p\n",49This, pParams, pScreen, pCreationParameters, pCaps,50pPresentationParameters, pFullscreenDisplayMode,51pD3D9Ex, pPresentationGroup, pCTX);5253return NineDevice9_ctor(&This->base, pParams,54pScreen, pCreationParameters, pCaps,55pPresentationParameters,56(IDirect3D9 *)pD3D9Ex, pPresentationGroup, pCTX,57TRUE, pFullscreenDisplayMode, minorVersionNum);58}5960static void61NineDevice9Ex_dtor( struct NineDevice9Ex *This )62{63NineDevice9_dtor(&This->base);64}6566HRESULT NINE_WINAPI67NineDevice9Ex_SetConvolutionMonoKernel( UNUSED struct NineDevice9Ex *This,68UNUSED UINT width,69UNUSED UINT height,70UNUSED float *rows,71UNUSED float *columns )72{73DBG("This\n");74STUB(D3D_OK);75}7677HRESULT NINE_WINAPI78NineDevice9Ex_ComposeRects( UNUSED struct NineDevice9Ex *This,79UNUSED IDirect3DSurface9 *pSrc,80UNUSED IDirect3DSurface9 *pDst,81UNUSED IDirect3DVertexBuffer9 *pSrcRectDescs,82UNUSED UINT NumRects,83UNUSED IDirect3DVertexBuffer9 *pDstRectDescs,84UNUSED D3DCOMPOSERECTSOP Operation,85UNUSED int Xoffset,86UNUSED int Yoffset )87{88DBG("This\n");89STUB(D3D_OK);90}9192HRESULT NINE_WINAPI93NineDevice9Ex_PresentEx( struct NineDevice9Ex *This,94const RECT *pSourceRect,95const RECT *pDestRect,96HWND hDestWindowOverride,97const RGNDATA *pDirtyRegion,98DWORD dwFlags )99{100unsigned i;101HRESULT hr;102103DBG("This=%p pSourceRect=%p pDestRect=%p hDestWindowOverride=%p "104"pDirtyRegion=%p dwFlags=%d\n",105This, pSourceRect, pDestRect, hDestWindowOverride,106pDirtyRegion, dwFlags);107108for (i = 0; i < This->base.nswapchains; i++) {109hr = NineSwapChain9_Present(This->base.swapchains[i], pSourceRect, pDestRect,110hDestWindowOverride, pDirtyRegion, dwFlags);111if (FAILED(hr)) { return hr; }112}113114return D3D_OK;115}116117HRESULT NINE_WINAPI118NineDevice9Ex_GetGPUThreadPriority( struct NineDevice9Ex *This,119INT *pPriority )120{121DBG("This\n");122user_assert(pPriority != NULL, D3DERR_INVALIDCALL);123*pPriority = This->base.gpu_priority;124return D3D_OK;125}126127HRESULT NINE_WINAPI128NineDevice9Ex_SetGPUThreadPriority( struct NineDevice9Ex *This,129INT Priority )130{131DBG("This\n");132user_assert(Priority >= -7 && Priority <= 7, D3DERR_INVALIDCALL);133This->base.gpu_priority = Priority;134return D3D_OK;135}136137HRESULT NINE_WINAPI138NineDevice9Ex_WaitForVBlank( UNUSED struct NineDevice9Ex *This,139UNUSED UINT iSwapChain )140{141DBG("This\n");142STUB(D3D_OK);143}144145HRESULT NINE_WINAPI146NineDevice9Ex_CheckResourceResidency( UNUSED struct NineDevice9Ex *This,147UNUSED IDirect3DResource9 **pResourceArray,148UNUSED UINT32 NumResources )149{150DBG("This\n");151STUB(D3D_OK);152}153154HRESULT NINE_WINAPI155NineDevice9Ex_SetMaximumFrameLatency( struct NineDevice9Ex *This,156UINT MaxLatency )157{158DBG("This\n");159This->base.max_frame_latency = MaxLatency;160return D3D_OK;161}162163HRESULT NINE_WINAPI164NineDevice9Ex_GetMaximumFrameLatency( struct NineDevice9Ex *This,165UINT *pMaxLatency )166{167DBG("This\n");168user_assert(pMaxLatency != NULL, D3DERR_INVALIDCALL);169*pMaxLatency = This->base.max_frame_latency;170return D3D_OK;171}172173HRESULT NINE_WINAPI174NineDevice9Ex_CheckDeviceState( struct NineDevice9Ex *This,175HWND hDestinationWindow )176{177DBG("This=%p hDestinationWindow=%p\n",178This, hDestinationWindow);179180user_assert(!This->base.swapchains[0]->params.Windowed, D3D_OK);181182if (This->base.params.hFocusWindow == hDestinationWindow) {183if (NineSwapChain9_GetOccluded(This->base.swapchains[0]))184return S_PRESENT_OCCLUDED;185} else if(!NineSwapChain9_GetOccluded(This->base.swapchains[0])) {186return S_PRESENT_OCCLUDED;187}188/* TODO: handle the other return values */189return D3D_OK;190}191192HRESULT NINE_WINAPI193NineDevice9Ex_CreateRenderTargetEx( struct NineDevice9Ex *This,194UINT Width,195UINT Height,196D3DFORMAT Format,197D3DMULTISAMPLE_TYPE MultiSample,198DWORD MultisampleQuality,199BOOL Lockable,200IDirect3DSurface9 **ppSurface,201HANDLE *pSharedHandle,202UNUSED DWORD Usage )203{204DBG("This\n");205/* The Create*Ex functions only purpose seem to introduce the206* Usage field, to pass the new d3d9ex flags on secure/restricted207* content.208* TODO: Return error on invalid Usage.209* TODO: Store Usage in the surface descriptor, in case the210* app checks */211return NineDevice9_CreateRenderTarget(&This->base,212Width,213Height,214Format,215MultiSample,216MultisampleQuality,217Lockable,218ppSurface,219pSharedHandle);220}221222HRESULT NINE_WINAPI223NineDevice9Ex_CreateOffscreenPlainSurfaceEx( struct NineDevice9Ex *This,224UINT Width,225UINT Height,226D3DFORMAT Format,227D3DPOOL Pool,228IDirect3DSurface9 **ppSurface,229HANDLE *pSharedHandle,230UNUSED DWORD Usage )231{232DBG("This\n");233/* The Create*Ex functions only purpose seem to introduce the234* Usage field, to pass the new d3d9ex flags on secure/restricted235* content.236* TODO: Return error on invalid Usage.237* TODO: Store Usage in the surface descriptor, in case the238* app checks */239return NineDevice9_CreateOffscreenPlainSurface(&This->base,240Width,241Height,242Format,243Pool,244ppSurface,245pSharedHandle);246}247248HRESULT NINE_WINAPI249NineDevice9Ex_CreateDepthStencilSurfaceEx( struct NineDevice9Ex *This,250UINT Width,251UINT Height,252D3DFORMAT Format,253D3DMULTISAMPLE_TYPE MultiSample,254DWORD MultisampleQuality,255BOOL Discard,256IDirect3DSurface9 **ppSurface,257HANDLE *pSharedHandle,258UNUSED DWORD Usage )259{260DBG("This\n");261/* The Create*Ex functions only purpose seem to introduce the262* Usage field, to pass the new d3d9ex flags on secure/restricted263* content.264* TODO: Return error on invalid Usage.265* TODO: Store Usage in the surface descriptor, in case the266* app checks */267return NineDevice9_CreateDepthStencilSurface(&This->base,268Width,269Height,270Format,271MultiSample,272MultisampleQuality,273Discard,274ppSurface,275pSharedHandle);276}277278HRESULT NINE_WINAPI279NineDevice9Ex_ResetEx( struct NineDevice9Ex *This,280D3DPRESENT_PARAMETERS *pPresentationParameters,281D3DDISPLAYMODEEX *pFullscreenDisplayMode )282{283HRESULT hr = D3D_OK;284float MinZ, MaxZ;285unsigned i;286287DBG("This=%p pPresentationParameters=%p pFullscreenDisplayMode=%p\n", This, pPresentationParameters, pFullscreenDisplayMode);288289for (i = 0; i < This->base.nswapchains; ++i) {290D3DDISPLAYMODEEX *mode = NULL;291D3DPRESENT_PARAMETERS *params = &pPresentationParameters[i];292if (pFullscreenDisplayMode) mode = &(pFullscreenDisplayMode[i]);293hr = NineSwapChain9_Resize(This->base.swapchains[i], params, mode);294if (FAILED(hr))295break;296}297298MinZ = This->base.state.viewport.MinZ; /* These are preserved */299MaxZ = This->base.state.viewport.MaxZ;300NineDevice9_SetRenderTarget(301(struct NineDevice9 *)This, 0, (IDirect3DSurface9 *)This->base.swapchains[0]->buffers[0]);302This->base.state.viewport.MinZ = MinZ;303This->base.state.viewport.MaxZ = MaxZ;304nine_context_set_viewport(&This->base, &This->base.state.viewport);305306if (This->base.nswapchains && This->base.swapchains[0]->params.EnableAutoDepthStencil)307NineDevice9_SetDepthStencilSurface(308&This->base, (IDirect3DSurface9 *)This->base.swapchains[0]->zsbuf);309310return hr;311}312313HRESULT NINE_WINAPI314NineDevice9Ex_Reset( struct NineDevice9Ex *This,315D3DPRESENT_PARAMETERS *pPresentationParameters )316{317HRESULT hr = D3D_OK;318float MinZ, MaxZ;319unsigned i;320321DBG("This=%p pPresentationParameters=%p\n", This, pPresentationParameters);322323for (i = 0; i < This->base.nswapchains; ++i) {324D3DPRESENT_PARAMETERS *params = &pPresentationParameters[i];325hr = NineSwapChain9_Resize(This->base.swapchains[i], params, NULL);326if (FAILED(hr))327break;328}329330MinZ = This->base.state.viewport.MinZ; /* These are preserved */331MaxZ = This->base.state.viewport.MaxZ;332NineDevice9_SetRenderTarget(333(struct NineDevice9 *)This, 0, (IDirect3DSurface9 *)This->base.swapchains[0]->buffers[0]);334This->base.state.viewport.MinZ = MinZ;335This->base.state.viewport.MaxZ = MaxZ;336nine_context_set_viewport(&This->base, &This->base.state.viewport);337338if (This->base.nswapchains && This->base.swapchains[0]->params.EnableAutoDepthStencil)339NineDevice9_SetDepthStencilSurface(340&This->base, (IDirect3DSurface9 *)This->base.swapchains[0]->zsbuf);341342return hr;343}344345HRESULT NINE_WINAPI346NineDevice9Ex_GetDisplayModeEx( struct NineDevice9Ex *This,347UINT iSwapChain,348D3DDISPLAYMODEEX *pMode,349D3DDISPLAYROTATION *pRotation )350{351struct NineSwapChain9Ex *swapchain;352353DBG("This=%p iSwapChain=%u pMode=%p pRotation=%p\n",354This, iSwapChain, pMode, pRotation);355356user_assert(iSwapChain < This->base.nswapchains, D3DERR_INVALIDCALL);357358swapchain = NineSwapChain9Ex(This->base.swapchains[iSwapChain]);359return NineSwapChain9Ex_GetDisplayModeEx(swapchain, pMode, pRotation);360}361362HRESULT NINE_WINAPI363NineDevice9Ex_TestCooperativeLevel( UNUSED struct NineDevice9Ex *This )364{365DBG("This\n");366return D3D_OK;367}368369370IDirect3DDevice9ExVtbl NineDevice9Ex_vtable = {371(void *)NineUnknown_QueryInterface,372(void *)NineUnknown_AddRef,373(void *)NineUnknown_Release,374(void *)NineDevice9Ex_TestCooperativeLevel,375(void *)NineDevice9_GetAvailableTextureMem,376(void *)NineDevice9_EvictManagedResources,377(void *)NineDevice9_GetDirect3D,378(void *)NineDevice9_GetDeviceCaps,379(void *)NineDevice9_GetDisplayMode,380(void *)NineDevice9_GetCreationParameters,381(void *)NineDevice9_SetCursorProperties,382(void *)NineDevice9_SetCursorPosition,383(void *)NineDevice9_ShowCursor,384(void *)NineDevice9_CreateAdditionalSwapChain,385(void *)NineDevice9_GetSwapChain,386(void *)NineDevice9_GetNumberOfSwapChains,387(void *)NineDevice9Ex_Reset,388(void *)NineDevice9_Present,389(void *)NineDevice9_GetBackBuffer,390(void *)NineDevice9_GetRasterStatus,391(void *)NineDevice9_SetDialogBoxMode,392(void *)NineDevice9_SetGammaRamp,393(void *)NineDevice9_GetGammaRamp,394(void *)NineDevice9_CreateTexture,395(void *)NineDevice9_CreateVolumeTexture,396(void *)NineDevice9_CreateCubeTexture,397(void *)NineDevice9_CreateVertexBuffer,398(void *)NineDevice9_CreateIndexBuffer,399(void *)NineDevice9_CreateRenderTarget,400(void *)NineDevice9_CreateDepthStencilSurface,401(void *)NineDevice9_UpdateSurface,402(void *)NineDevice9_UpdateTexture,403(void *)NineDevice9_GetRenderTargetData,404(void *)NineDevice9_GetFrontBufferData,405(void *)NineDevice9_StretchRect,406(void *)NineDevice9_ColorFill,407(void *)NineDevice9_CreateOffscreenPlainSurface,408(void *)NineDevice9_SetRenderTarget,409(void *)NineDevice9_GetRenderTarget,410(void *)NineDevice9_SetDepthStencilSurface,411(void *)NineDevice9_GetDepthStencilSurface,412(void *)NineDevice9_BeginScene,413(void *)NineDevice9_EndScene,414(void *)NineDevice9_Clear,415(void *)NineDevice9_SetTransform,416(void *)NineDevice9_GetTransform,417(void *)NineDevice9_MultiplyTransform,418(void *)NineDevice9_SetViewport,419(void *)NineDevice9_GetViewport,420(void *)NineDevice9_SetMaterial,421(void *)NineDevice9_GetMaterial,422(void *)NineDevice9_SetLight,423(void *)NineDevice9_GetLight,424(void *)NineDevice9_LightEnable,425(void *)NineDevice9_GetLightEnable,426(void *)NineDevice9_SetClipPlane,427(void *)NineDevice9_GetClipPlane,428(void *)NineDevice9_SetRenderState,429(void *)NineDevice9_GetRenderState,430(void *)NineDevice9_CreateStateBlock,431(void *)NineDevice9_BeginStateBlock,432(void *)NineDevice9_EndStateBlock,433(void *)NineDevice9_SetClipStatus,434(void *)NineDevice9_GetClipStatus,435(void *)NineDevice9_GetTexture,436(void *)NineDevice9_SetTexture,437(void *)NineDevice9_GetTextureStageState,438(void *)NineDevice9_SetTextureStageState,439(void *)NineDevice9_GetSamplerState,440(void *)NineDevice9_SetSamplerState,441(void *)NineDevice9_ValidateDevice,442(void *)NineDevice9_SetPaletteEntries,443(void *)NineDevice9_GetPaletteEntries,444(void *)NineDevice9_SetCurrentTexturePalette,445(void *)NineDevice9_GetCurrentTexturePalette,446(void *)NineDevice9_SetScissorRect,447(void *)NineDevice9_GetScissorRect,448(void *)NineDevice9_SetSoftwareVertexProcessing,449(void *)NineDevice9_GetSoftwareVertexProcessing,450(void *)NineDevice9_SetNPatchMode,451(void *)NineDevice9_GetNPatchMode,452(void *)NineDevice9_DrawPrimitive,453(void *)NineDevice9_DrawIndexedPrimitive,454(void *)NineDevice9_DrawPrimitiveUP,455(void *)NineDevice9_DrawIndexedPrimitiveUP,456(void *)NineDevice9_ProcessVertices,457(void *)NineDevice9_CreateVertexDeclaration,458(void *)NineDevice9_SetVertexDeclaration,459(void *)NineDevice9_GetVertexDeclaration,460(void *)NineDevice9_SetFVF,461(void *)NineDevice9_GetFVF,462(void *)NineDevice9_CreateVertexShader,463(void *)NineDevice9_SetVertexShader,464(void *)NineDevice9_GetVertexShader,465(void *)NineDevice9_SetVertexShaderConstantF,466(void *)NineDevice9_GetVertexShaderConstantF,467(void *)NineDevice9_SetVertexShaderConstantI,468(void *)NineDevice9_GetVertexShaderConstantI,469(void *)NineDevice9_SetVertexShaderConstantB,470(void *)NineDevice9_GetVertexShaderConstantB,471(void *)NineDevice9_SetStreamSource,472(void *)NineDevice9_GetStreamSource,473(void *)NineDevice9_SetStreamSourceFreq,474(void *)NineDevice9_GetStreamSourceFreq,475(void *)NineDevice9_SetIndices,476(void *)NineDevice9_GetIndices,477(void *)NineDevice9_CreatePixelShader,478(void *)NineDevice9_SetPixelShader,479(void *)NineDevice9_GetPixelShader,480(void *)NineDevice9_SetPixelShaderConstantF,481(void *)NineDevice9_GetPixelShaderConstantF,482(void *)NineDevice9_SetPixelShaderConstantI,483(void *)NineDevice9_GetPixelShaderConstantI,484(void *)NineDevice9_SetPixelShaderConstantB,485(void *)NineDevice9_GetPixelShaderConstantB,486(void *)NineDevice9_DrawRectPatch,487(void *)NineDevice9_DrawTriPatch,488(void *)NineDevice9_DeletePatch,489(void *)NineDevice9_CreateQuery,490(void *)NineDevice9Ex_SetConvolutionMonoKernel,491(void *)NineDevice9Ex_ComposeRects,492(void *)NineDevice9Ex_PresentEx,493(void *)NineDevice9Ex_GetGPUThreadPriority,494(void *)NineDevice9Ex_SetGPUThreadPriority,495(void *)NineDevice9Ex_WaitForVBlank,496(void *)NineDevice9Ex_CheckResourceResidency,497(void *)NineDevice9Ex_SetMaximumFrameLatency,498(void *)NineDevice9Ex_GetMaximumFrameLatency,499(void *)NineDevice9Ex_CheckDeviceState,500(void *)NineDevice9Ex_CreateRenderTargetEx,501(void *)NineDevice9Ex_CreateOffscreenPlainSurfaceEx,502(void *)NineDevice9Ex_CreateDepthStencilSurfaceEx,503(void *)NineDevice9Ex_ResetEx,504(void *)NineDevice9Ex_GetDisplayModeEx505};506507static const GUID *NineDevice9Ex_IIDs[] = {508&IID_IDirect3DDevice9Ex,509&IID_IDirect3DDevice9,510&IID_IUnknown,511NULL512};513514HRESULT515NineDevice9Ex_new( struct pipe_screen *pScreen,516D3DDEVICE_CREATION_PARAMETERS *pCreationParameters,517D3DCAPS9 *pCaps,518D3DPRESENT_PARAMETERS *pPresentationParameters,519D3DDISPLAYMODEEX *pFullscreenDisplayMode,520IDirect3D9Ex *pD3D9Ex,521ID3DPresentGroup *pPresentationGroup,522struct d3dadapter9_context *pCTX,523struct NineDevice9Ex **ppOut,524int minorVersionNum )525{526BOOL lock;527lock = !!(pCreationParameters->BehaviorFlags & D3DCREATE_MULTITHREADED);528529NINE_NEW(Device9Ex, ppOut, lock,530pScreen, pCreationParameters, pCaps, pPresentationParameters,531pFullscreenDisplayMode, pD3D9Ex, pPresentationGroup, pCTX, minorVersionNum );532}533534535536