17ec681f3Smrg/**************************************************************************
27ec681f3Smrg *
37ec681f3Smrg * Copyright 2012-2021 VMware, Inc.
47ec681f3Smrg * All Rights Reserved.
57ec681f3Smrg *
67ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
77ec681f3Smrg * copy of this software and associated documentation files (the
87ec681f3Smrg * "Software"), to deal in the Software without restriction, including
97ec681f3Smrg * without limitation the rights to use, copy, modify, merge, publish,
107ec681f3Smrg * distribute, sub license, and/or sell copies of the Software, and to
117ec681f3Smrg * permit persons to whom the Software is furnished to do so, subject to
127ec681f3Smrg * the following conditions:
137ec681f3Smrg *
147ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
157ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
167ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
177ec681f3Smrg * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
187ec681f3Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
197ec681f3Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
207ec681f3Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE.
217ec681f3Smrg *
227ec681f3Smrg * The above copyright notice and this permission notice (including the
237ec681f3Smrg * next paragraph) shall be included in all copies or substantial portions
247ec681f3Smrg * of the Software.
257ec681f3Smrg *
267ec681f3Smrg **************************************************************************/
277ec681f3Smrg
287ec681f3Smrg/*
297ec681f3Smrg * Device.cpp --
307ec681f3Smrg *    Functions that provide the 3D device functionality.
317ec681f3Smrg */
327ec681f3Smrg
337ec681f3Smrg
347ec681f3Smrg#include "Draw.h"
357ec681f3Smrg#include "Dxgi.h"
367ec681f3Smrg#include "InputAssembly.h"
377ec681f3Smrg#include "OutputMerger.h"
387ec681f3Smrg#include "Query.h"
397ec681f3Smrg#include "Rasterizer.h"
407ec681f3Smrg#include "Resource.h"
417ec681f3Smrg#include "Shader.h"
427ec681f3Smrg#include "State.h"
437ec681f3Smrg#include "Format.h"
447ec681f3Smrg
457ec681f3Smrg#include "Debug.h"
467ec681f3Smrg
477ec681f3Smrg#include "util/u_sampler.h"
487ec681f3Smrg
497ec681f3Smrg
507ec681f3Smrgstatic void APIENTRY DestroyDevice(D3D10DDI_HDEVICE hDevice);
517ec681f3Smrgstatic void APIENTRY RelocateDeviceFuncs(D3D10DDI_HDEVICE hDevice,
527ec681f3Smrg                                __in struct D3D10DDI_DEVICEFUNCS *pDeviceFunctions);
537ec681f3Smrgstatic void APIENTRY RelocateDeviceFuncs1(D3D10DDI_HDEVICE hDevice,
547ec681f3Smrg                                __in struct D3D10_1DDI_DEVICEFUNCS *pDeviceFunctions);
557ec681f3Smrgstatic void APIENTRY Flush(D3D10DDI_HDEVICE hDevice);
567ec681f3Smrgstatic void APIENTRY CheckFormatSupport(D3D10DDI_HDEVICE hDevice, DXGI_FORMAT Format,
577ec681f3Smrg                               __out UINT *pFormatCaps);
587ec681f3Smrgstatic void APIENTRY CheckMultisampleQualityLevels(D3D10DDI_HDEVICE hDevice,
597ec681f3Smrg                                          DXGI_FORMAT Format,
607ec681f3Smrg                                          UINT SampleCount,
617ec681f3Smrg                                          __out UINT *pNumQualityLevels);
627ec681f3Smrgstatic void APIENTRY SetTextFilterSize(D3D10DDI_HDEVICE hDevice, UINT Width, UINT Height);
637ec681f3Smrg
647ec681f3Smrg
657ec681f3Smrg/*
667ec681f3Smrg * ----------------------------------------------------------------------
677ec681f3Smrg *
687ec681f3Smrg * CalcPrivateDeviceSize --
697ec681f3Smrg *
707ec681f3Smrg *    The CalcPrivateDeviceSize function determines the size of a memory
717ec681f3Smrg *    region that the user-mode display driver requires from the Microsoft
727ec681f3Smrg *    Direct3D runtime to store frequently-accessed data.
737ec681f3Smrg *
747ec681f3Smrg * ----------------------------------------------------------------------
757ec681f3Smrg */
767ec681f3Smrg
777ec681f3SmrgSIZE_T APIENTRY
787ec681f3SmrgCalcPrivateDeviceSize(D3D10DDI_HADAPTER hAdapter,                          // IN
797ec681f3Smrg                      __in const D3D10DDIARG_CALCPRIVATEDEVICESIZE *pData) // IN
807ec681f3Smrg{
817ec681f3Smrg   return sizeof(Device);
827ec681f3Smrg}
837ec681f3Smrg
847ec681f3Smrg/*
857ec681f3Smrg * ----------------------------------------------------------------------
867ec681f3Smrg *
877ec681f3Smrg * CreateDevice --
887ec681f3Smrg *
897ec681f3Smrg *    The CreateDevice function creates a graphics context that is
907ec681f3Smrg *    referenced in subsequent calls.
917ec681f3Smrg *
927ec681f3Smrg * ----------------------------------------------------------------------
937ec681f3Smrg */
947ec681f3Smrg
957ec681f3SmrgHRESULT APIENTRY
967ec681f3SmrgCreateDevice(D3D10DDI_HADAPTER hAdapter,                 // IN
977ec681f3Smrg             __in D3D10DDIARG_CREATEDEVICE *pCreateData) // IN
987ec681f3Smrg{
997ec681f3Smrg   LOG_ENTRYPOINT();
1007ec681f3Smrg
1017ec681f3Smrg   if (0) {
1027ec681f3Smrg      DebugPrintf("hAdapter = %p\n", hAdapter);
1037ec681f3Smrg      DebugPrintf("pKTCallbacks = %p\n", pCreateData->pKTCallbacks);
1047ec681f3Smrg      DebugPrintf("p10_1DeviceFuncs = %p\n", pCreateData->p10_1DeviceFuncs);
1057ec681f3Smrg      DebugPrintf("hDrvDevice = %p\n", pCreateData->hDrvDevice);
1067ec681f3Smrg      DebugPrintf("DXGIBaseDDI = %p\n", pCreateData->DXGIBaseDDI);
1077ec681f3Smrg      DebugPrintf("hRTCoreLayer = %p\n", pCreateData->hRTCoreLayer);
1087ec681f3Smrg      DebugPrintf("pUMCallbacks = %p\n", pCreateData->pUMCallbacks);
1097ec681f3Smrg   }
1107ec681f3Smrg
1117ec681f3Smrg   switch (pCreateData->Interface) {
1127ec681f3Smrg   case D3D10_0_DDI_INTERFACE_VERSION:
1137ec681f3Smrg   case D3D10_0_x_DDI_INTERFACE_VERSION:
1147ec681f3Smrg   case D3D10_0_7_DDI_INTERFACE_VERSION:
1157ec681f3Smrg#if SUPPORT_D3D10_1
1167ec681f3Smrg   case D3D10_1_DDI_INTERFACE_VERSION:
1177ec681f3Smrg   case D3D10_1_x_DDI_INTERFACE_VERSION:
1187ec681f3Smrg   case D3D10_1_7_DDI_INTERFACE_VERSION:
1197ec681f3Smrg#endif
1207ec681f3Smrg      break;
1217ec681f3Smrg   default:
1227ec681f3Smrg      DebugPrintf("%s: unsupported interface version 0x%08x\n",
1237ec681f3Smrg                  __FUNCTION__, pCreateData->Interface);
1247ec681f3Smrg      return E_FAIL;
1257ec681f3Smrg   }
1267ec681f3Smrg
1277ec681f3Smrg   Adapter *pAdapter = CastAdapter(hAdapter);
1287ec681f3Smrg
1297ec681f3Smrg   Device *pDevice = CastDevice(pCreateData->hDrvDevice);
1307ec681f3Smrg   memset(pDevice, 0, sizeof *pDevice);
1317ec681f3Smrg
1327ec681f3Smrg   struct pipe_screen *screen = pAdapter->screen;
1337ec681f3Smrg   struct pipe_context *pipe = screen->context_create(screen, NULL, 0);
1347ec681f3Smrg   pDevice->pipe = pipe;
1357ec681f3Smrg
1367ec681f3Smrg   pDevice->empty_vs = CreateEmptyShader(pDevice, PIPE_SHADER_VERTEX);
1377ec681f3Smrg   pDevice->empty_fs = CreateEmptyShader(pDevice, PIPE_SHADER_FRAGMENT);
1387ec681f3Smrg
1397ec681f3Smrg   pipe->bind_vs_state(pipe, pDevice->empty_vs);
1407ec681f3Smrg   pipe->bind_fs_state(pipe, pDevice->empty_fs);
1417ec681f3Smrg
1427ec681f3Smrg   pDevice->max_dual_source_render_targets =
1437ec681f3Smrg         screen->get_param(screen, PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS);
1447ec681f3Smrg
1457ec681f3Smrg   pDevice->hRTCoreLayer = pCreateData->hRTCoreLayer;
1467ec681f3Smrg   pDevice->hDevice = (HANDLE)pCreateData->hRTDevice.handle;
1477ec681f3Smrg   pDevice->KTCallbacks = *pCreateData->pKTCallbacks;
1487ec681f3Smrg   pDevice->UMCallbacks = *pCreateData->pUMCallbacks;
1497ec681f3Smrg   pDevice->pDXGIBaseCallbacks = pCreateData->DXGIBaseDDI.pDXGIBaseCallbacks;
1507ec681f3Smrg
1517ec681f3Smrg   pDevice->draw_so_target = NULL;
1527ec681f3Smrg
1537ec681f3Smrg   if (0) {
1547ec681f3Smrg      DebugPrintf("pDevice = %p\n", pDevice);
1557ec681f3Smrg   }
1567ec681f3Smrg
1577ec681f3Smrg   st_debug_parse();
1587ec681f3Smrg
1597ec681f3Smrg   /*
1607ec681f3Smrg    * Fill in the D3D10 DDI functions
1617ec681f3Smrg    */
1627ec681f3Smrg   D3D10DDI_DEVICEFUNCS *pDeviceFuncs = pCreateData->pDeviceFuncs;
1637ec681f3Smrg   pDeviceFuncs->pfnDefaultConstantBufferUpdateSubresourceUP = ResourceUpdateSubResourceUP;
1647ec681f3Smrg   pDeviceFuncs->pfnVsSetConstantBuffers = VsSetConstantBuffers;
1657ec681f3Smrg   pDeviceFuncs->pfnPsSetShaderResources = PsSetShaderResources;
1667ec681f3Smrg   pDeviceFuncs->pfnPsSetShader = PsSetShader;
1677ec681f3Smrg   pDeviceFuncs->pfnPsSetSamplers = PsSetSamplers;
1687ec681f3Smrg   pDeviceFuncs->pfnVsSetShader = VsSetShader;
1697ec681f3Smrg   pDeviceFuncs->pfnDrawIndexed = DrawIndexed;
1707ec681f3Smrg   pDeviceFuncs->pfnDraw = Draw;
1717ec681f3Smrg   pDeviceFuncs->pfnDynamicIABufferMapNoOverwrite = ResourceMap;
1727ec681f3Smrg   pDeviceFuncs->pfnDynamicIABufferUnmap = ResourceUnmap;
1737ec681f3Smrg   pDeviceFuncs->pfnDynamicConstantBufferMapDiscard = ResourceMap;
1747ec681f3Smrg   pDeviceFuncs->pfnDynamicIABufferMapDiscard = ResourceMap;
1757ec681f3Smrg   pDeviceFuncs->pfnDynamicConstantBufferUnmap = ResourceUnmap;
1767ec681f3Smrg   pDeviceFuncs->pfnPsSetConstantBuffers = PsSetConstantBuffers;
1777ec681f3Smrg   pDeviceFuncs->pfnIaSetInputLayout = IaSetInputLayout;
1787ec681f3Smrg   pDeviceFuncs->pfnIaSetVertexBuffers = IaSetVertexBuffers;
1797ec681f3Smrg   pDeviceFuncs->pfnIaSetIndexBuffer = IaSetIndexBuffer;
1807ec681f3Smrg   pDeviceFuncs->pfnDrawIndexedInstanced = DrawIndexedInstanced;
1817ec681f3Smrg   pDeviceFuncs->pfnDrawInstanced = DrawInstanced;
1827ec681f3Smrg   pDeviceFuncs->pfnDynamicResourceMapDiscard = ResourceMap;
1837ec681f3Smrg   pDeviceFuncs->pfnDynamicResourceUnmap = ResourceUnmap;
1847ec681f3Smrg   pDeviceFuncs->pfnGsSetConstantBuffers = GsSetConstantBuffers;
1857ec681f3Smrg   pDeviceFuncs->pfnGsSetShader = GsSetShader;
1867ec681f3Smrg   pDeviceFuncs->pfnIaSetTopology = IaSetTopology;
1877ec681f3Smrg   pDeviceFuncs->pfnStagingResourceMap = ResourceMap;
1887ec681f3Smrg   pDeviceFuncs->pfnStagingResourceUnmap = ResourceUnmap;
1897ec681f3Smrg   pDeviceFuncs->pfnVsSetShaderResources = VsSetShaderResources;
1907ec681f3Smrg   pDeviceFuncs->pfnVsSetSamplers = VsSetSamplers;
1917ec681f3Smrg   pDeviceFuncs->pfnGsSetShaderResources = GsSetShaderResources;
1927ec681f3Smrg   pDeviceFuncs->pfnGsSetSamplers = GsSetSamplers;
1937ec681f3Smrg   pDeviceFuncs->pfnSetRenderTargets = SetRenderTargets;
1947ec681f3Smrg   pDeviceFuncs->pfnShaderResourceViewReadAfterWriteHazard = ShaderResourceViewReadAfterWriteHazard;
1957ec681f3Smrg   pDeviceFuncs->pfnResourceReadAfterWriteHazard = ResourceReadAfterWriteHazard;
1967ec681f3Smrg   pDeviceFuncs->pfnSetBlendState = SetBlendState;
1977ec681f3Smrg   pDeviceFuncs->pfnSetDepthStencilState = SetDepthStencilState;
1987ec681f3Smrg   pDeviceFuncs->pfnSetRasterizerState = SetRasterizerState;
1997ec681f3Smrg   pDeviceFuncs->pfnQueryEnd = QueryEnd;
2007ec681f3Smrg   pDeviceFuncs->pfnQueryBegin = QueryBegin;
2017ec681f3Smrg   pDeviceFuncs->pfnResourceCopyRegion = ResourceCopyRegion;
2027ec681f3Smrg   pDeviceFuncs->pfnResourceUpdateSubresourceUP = ResourceUpdateSubResourceUP;
2037ec681f3Smrg   pDeviceFuncs->pfnSoSetTargets = SoSetTargets;
2047ec681f3Smrg   pDeviceFuncs->pfnDrawAuto = DrawAuto;
2057ec681f3Smrg   pDeviceFuncs->pfnSetViewports = SetViewports;
2067ec681f3Smrg   pDeviceFuncs->pfnSetScissorRects = SetScissorRects;
2077ec681f3Smrg   pDeviceFuncs->pfnClearRenderTargetView = ClearRenderTargetView;
2087ec681f3Smrg   pDeviceFuncs->pfnClearDepthStencilView = ClearDepthStencilView;
2097ec681f3Smrg   pDeviceFuncs->pfnSetPredication = SetPredication;
2107ec681f3Smrg   pDeviceFuncs->pfnQueryGetData = QueryGetData;
2117ec681f3Smrg   pDeviceFuncs->pfnFlush = Flush;
2127ec681f3Smrg   pDeviceFuncs->pfnGenMips = GenMips;
2137ec681f3Smrg   pDeviceFuncs->pfnResourceCopy = ResourceCopy;
2147ec681f3Smrg   pDeviceFuncs->pfnResourceResolveSubresource = ResourceResolveSubResource;
2157ec681f3Smrg   pDeviceFuncs->pfnResourceMap = ResourceMap;
2167ec681f3Smrg   pDeviceFuncs->pfnResourceUnmap = ResourceUnmap;
2177ec681f3Smrg   pDeviceFuncs->pfnResourceIsStagingBusy = ResourceIsStagingBusy;
2187ec681f3Smrg   pDeviceFuncs->pfnRelocateDeviceFuncs = RelocateDeviceFuncs;
2197ec681f3Smrg   pDeviceFuncs->pfnCalcPrivateResourceSize = CalcPrivateResourceSize;
2207ec681f3Smrg   pDeviceFuncs->pfnCalcPrivateOpenedResourceSize = CalcPrivateOpenedResourceSize;
2217ec681f3Smrg   pDeviceFuncs->pfnCreateResource = CreateResource;
2227ec681f3Smrg   pDeviceFuncs->pfnOpenResource = OpenResource;
2237ec681f3Smrg   pDeviceFuncs->pfnDestroyResource = DestroyResource;
2247ec681f3Smrg   pDeviceFuncs->pfnCalcPrivateShaderResourceViewSize = CalcPrivateShaderResourceViewSize;
2257ec681f3Smrg   pDeviceFuncs->pfnCreateShaderResourceView = CreateShaderResourceView;
2267ec681f3Smrg   pDeviceFuncs->pfnDestroyShaderResourceView = DestroyShaderResourceView;
2277ec681f3Smrg   pDeviceFuncs->pfnCalcPrivateRenderTargetViewSize = CalcPrivateRenderTargetViewSize;
2287ec681f3Smrg   pDeviceFuncs->pfnCreateRenderTargetView = CreateRenderTargetView;
2297ec681f3Smrg   pDeviceFuncs->pfnDestroyRenderTargetView = DestroyRenderTargetView;
2307ec681f3Smrg   pDeviceFuncs->pfnCalcPrivateDepthStencilViewSize = CalcPrivateDepthStencilViewSize;
2317ec681f3Smrg   pDeviceFuncs->pfnCreateDepthStencilView = CreateDepthStencilView;
2327ec681f3Smrg   pDeviceFuncs->pfnDestroyDepthStencilView = DestroyDepthStencilView;
2337ec681f3Smrg   pDeviceFuncs->pfnCalcPrivateElementLayoutSize = CalcPrivateElementLayoutSize;
2347ec681f3Smrg   pDeviceFuncs->pfnCreateElementLayout = CreateElementLayout;
2357ec681f3Smrg   pDeviceFuncs->pfnDestroyElementLayout = DestroyElementLayout;
2367ec681f3Smrg   pDeviceFuncs->pfnCalcPrivateBlendStateSize = CalcPrivateBlendStateSize;
2377ec681f3Smrg   pDeviceFuncs->pfnCreateBlendState = CreateBlendState;
2387ec681f3Smrg   pDeviceFuncs->pfnDestroyBlendState = DestroyBlendState;
2397ec681f3Smrg   pDeviceFuncs->pfnCalcPrivateDepthStencilStateSize = CalcPrivateDepthStencilStateSize;
2407ec681f3Smrg   pDeviceFuncs->pfnCreateDepthStencilState = CreateDepthStencilState;
2417ec681f3Smrg   pDeviceFuncs->pfnDestroyDepthStencilState = DestroyDepthStencilState;
2427ec681f3Smrg   pDeviceFuncs->pfnCalcPrivateRasterizerStateSize = CalcPrivateRasterizerStateSize;
2437ec681f3Smrg   pDeviceFuncs->pfnCreateRasterizerState = CreateRasterizerState;
2447ec681f3Smrg   pDeviceFuncs->pfnDestroyRasterizerState = DestroyRasterizerState;
2457ec681f3Smrg   pDeviceFuncs->pfnCalcPrivateShaderSize = CalcPrivateShaderSize;
2467ec681f3Smrg   pDeviceFuncs->pfnCreateVertexShader = CreateVertexShader;
2477ec681f3Smrg   pDeviceFuncs->pfnCreateGeometryShader = CreateGeometryShader;
2487ec681f3Smrg   pDeviceFuncs->pfnCreatePixelShader = CreatePixelShader;
2497ec681f3Smrg   pDeviceFuncs->pfnCalcPrivateGeometryShaderWithStreamOutput = CalcPrivateGeometryShaderWithStreamOutput;
2507ec681f3Smrg   pDeviceFuncs->pfnCreateGeometryShaderWithStreamOutput = CreateGeometryShaderWithStreamOutput;
2517ec681f3Smrg   pDeviceFuncs->pfnDestroyShader = DestroyShader;
2527ec681f3Smrg   pDeviceFuncs->pfnCalcPrivateSamplerSize = CalcPrivateSamplerSize;
2537ec681f3Smrg   pDeviceFuncs->pfnCreateSampler = CreateSampler;
2547ec681f3Smrg   pDeviceFuncs->pfnDestroySampler = DestroySampler;
2557ec681f3Smrg   pDeviceFuncs->pfnCalcPrivateQuerySize = CalcPrivateQuerySize;
2567ec681f3Smrg   pDeviceFuncs->pfnCreateQuery = CreateQuery;
2577ec681f3Smrg   pDeviceFuncs->pfnDestroyQuery = DestroyQuery;
2587ec681f3Smrg   pDeviceFuncs->pfnCheckFormatSupport = CheckFormatSupport;
2597ec681f3Smrg   pDeviceFuncs->pfnCheckMultisampleQualityLevels = CheckMultisampleQualityLevels;
2607ec681f3Smrg   pDeviceFuncs->pfnCheckCounterInfo = CheckCounterInfo;
2617ec681f3Smrg   pDeviceFuncs->pfnCheckCounter = CheckCounter;
2627ec681f3Smrg   pDeviceFuncs->pfnDestroyDevice = DestroyDevice;
2637ec681f3Smrg   pDeviceFuncs->pfnSetTextFilterSize = SetTextFilterSize;
2647ec681f3Smrg   if (pCreateData->Interface == D3D10_1_DDI_INTERFACE_VERSION ||
2657ec681f3Smrg       pCreateData->Interface == D3D10_1_x_DDI_INTERFACE_VERSION ||
2667ec681f3Smrg       pCreateData->Interface == D3D10_1_7_DDI_INTERFACE_VERSION) {
2677ec681f3Smrg      D3D10_1DDI_DEVICEFUNCS *p10_1DeviceFuncs = pCreateData->p10_1DeviceFuncs;
2687ec681f3Smrg      p10_1DeviceFuncs->pfnRelocateDeviceFuncs = RelocateDeviceFuncs1;
2697ec681f3Smrg      p10_1DeviceFuncs->pfnCalcPrivateShaderResourceViewSize = CalcPrivateShaderResourceViewSize1;
2707ec681f3Smrg      p10_1DeviceFuncs->pfnCreateShaderResourceView = CreateShaderResourceView1;
2717ec681f3Smrg      p10_1DeviceFuncs->pfnCalcPrivateBlendStateSize = CalcPrivateBlendStateSize1;
2727ec681f3Smrg      p10_1DeviceFuncs->pfnCreateBlendState = CreateBlendState1;
2737ec681f3Smrg      p10_1DeviceFuncs->pfnResourceConvert = ResourceCopy;
2747ec681f3Smrg      p10_1DeviceFuncs->pfnResourceConvertRegion = ResourceCopyRegion;
2757ec681f3Smrg   }
2767ec681f3Smrg
2777ec681f3Smrg   /*
2787ec681f3Smrg    * Fill in DXGI DDI functions
2797ec681f3Smrg    */
2807ec681f3Smrg   pCreateData->DXGIBaseDDI.pDXGIDDIBaseFunctions->pfnPresent =
2817ec681f3Smrg      _Present;
2827ec681f3Smrg   pCreateData->DXGIBaseDDI.pDXGIDDIBaseFunctions->pfnGetGammaCaps =
2837ec681f3Smrg      _GetGammaCaps;
2847ec681f3Smrg   pCreateData->DXGIBaseDDI.pDXGIDDIBaseFunctions->pfnSetDisplayMode =
2857ec681f3Smrg      _SetDisplayMode;
2867ec681f3Smrg   pCreateData->DXGIBaseDDI.pDXGIDDIBaseFunctions->pfnSetResourcePriority =
2877ec681f3Smrg      _SetResourcePriority;
2887ec681f3Smrg   pCreateData->DXGIBaseDDI.pDXGIDDIBaseFunctions->pfnQueryResourceResidency =
2897ec681f3Smrg      _QueryResourceResidency;
2907ec681f3Smrg   pCreateData->DXGIBaseDDI.pDXGIDDIBaseFunctions->pfnRotateResourceIdentities =
2917ec681f3Smrg      _RotateResourceIdentities;
2927ec681f3Smrg   pCreateData->DXGIBaseDDI.pDXGIDDIBaseFunctions->pfnBlt =
2937ec681f3Smrg      _Blt;
2947ec681f3Smrg
2957ec681f3Smrg   if (0) {
2967ec681f3Smrg      return S_OK;
2977ec681f3Smrg   } else {
2987ec681f3Smrg      // Tell DXGI to not use the shared resource presentation path when
2997ec681f3Smrg      // communicating with DWM:
3007ec681f3Smrg      // http://msdn.microsoft.com/en-us/library/windows/hardware/ff569887(v=vs.85).aspx
3017ec681f3Smrg      return DXGI_STATUS_NO_REDIRECTION;
3027ec681f3Smrg   }
3037ec681f3Smrg}
3047ec681f3Smrg
3057ec681f3Smrg
3067ec681f3Smrg/*
3077ec681f3Smrg * ----------------------------------------------------------------------
3087ec681f3Smrg *
3097ec681f3Smrg * DestroyDevice --
3107ec681f3Smrg *
3117ec681f3Smrg *    The DestroyDevice function destroys a graphics context.
3127ec681f3Smrg *
3137ec681f3Smrg * ----------------------------------------------------------------------
3147ec681f3Smrg */
3157ec681f3Smrg
3167ec681f3Smrgvoid APIENTRY
3177ec681f3SmrgDestroyDevice(D3D10DDI_HDEVICE hDevice)   // IN
3187ec681f3Smrg{
3197ec681f3Smrg   unsigned i;
3207ec681f3Smrg
3217ec681f3Smrg   LOG_ENTRYPOINT();
3227ec681f3Smrg
3237ec681f3Smrg   Device *pDevice = CastDevice(hDevice);
3247ec681f3Smrg   struct pipe_context *pipe = pDevice->pipe;
3257ec681f3Smrg
3267ec681f3Smrg   pipe->flush(pipe, NULL, 0);
3277ec681f3Smrg
3287ec681f3Smrg   for (i = 0; i < PIPE_MAX_SO_BUFFERS; ++i) {
3297ec681f3Smrg      pipe_so_target_reference(&pDevice->so_targets[i], NULL);
3307ec681f3Smrg   }
3317ec681f3Smrg   if (pDevice->draw_so_target) {
3327ec681f3Smrg      pipe_so_target_reference(&pDevice->draw_so_target, NULL);
3337ec681f3Smrg   }
3347ec681f3Smrg
3357ec681f3Smrg   pipe->bind_fs_state(pipe, NULL);
3367ec681f3Smrg   pipe->bind_vs_state(pipe, NULL);
3377ec681f3Smrg
3387ec681f3Smrg   DeleteEmptyShader(pDevice, PIPE_SHADER_FRAGMENT, pDevice->empty_fs);
3397ec681f3Smrg   DeleteEmptyShader(pDevice, PIPE_SHADER_VERTEX, pDevice->empty_vs);
3407ec681f3Smrg
3417ec681f3Smrg   pipe_surface_reference(&pDevice->fb.zsbuf, NULL);
3427ec681f3Smrg   for (i = 0; i < PIPE_MAX_COLOR_BUFS; ++i) {
3437ec681f3Smrg      pipe_surface_reference(&pDevice->fb.cbufs[i], NULL);
3447ec681f3Smrg   }
3457ec681f3Smrg
3467ec681f3Smrg   for (i = 0; i < PIPE_MAX_ATTRIBS; ++i) {
3477ec681f3Smrg      if (!pDevice->vertex_buffers[i].is_user_buffer) {
3487ec681f3Smrg         pipe_resource_reference(&pDevice->vertex_buffers[i].buffer.resource, NULL);
3497ec681f3Smrg      }
3507ec681f3Smrg   }
3517ec681f3Smrg
3527ec681f3Smrg   pipe_resource_reference(&pDevice->index_buffer, NULL);
3537ec681f3Smrg
3547ec681f3Smrg   static struct pipe_sampler_view * sampler_views[PIPE_MAX_SHADER_SAMPLER_VIEWS];
3557ec681f3Smrg   memset(sampler_views, 0, sizeof sampler_views);
3567ec681f3Smrg   pipe->set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, 0,
3577ec681f3Smrg                           PIPE_MAX_SHADER_SAMPLER_VIEWS, 0, sampler_views);
3587ec681f3Smrg   pipe->set_sampler_views(pipe, PIPE_SHADER_VERTEX, 0,
3597ec681f3Smrg                           PIPE_MAX_SHADER_SAMPLER_VIEWS, 0, sampler_views);
3607ec681f3Smrg   pipe->set_sampler_views(pipe, PIPE_SHADER_GEOMETRY, 0,
3617ec681f3Smrg                           PIPE_MAX_SHADER_SAMPLER_VIEWS, 0, sampler_views);
3627ec681f3Smrg
3637ec681f3Smrg   pipe->destroy(pipe);
3647ec681f3Smrg}
3657ec681f3Smrg
3667ec681f3Smrg
3677ec681f3Smrg/*
3687ec681f3Smrg * ----------------------------------------------------------------------
3697ec681f3Smrg *
3707ec681f3Smrg * RelocateDeviceFuncs --
3717ec681f3Smrg *
3727ec681f3Smrg *    The RelocateDeviceFuncs function notifies the user-mode
3737ec681f3Smrg *    display driver about the new location of the driver function table.
3747ec681f3Smrg *
3757ec681f3Smrg * ----------------------------------------------------------------------
3767ec681f3Smrg */
3777ec681f3Smrg
3787ec681f3Smrgvoid APIENTRY
3797ec681f3SmrgRelocateDeviceFuncs(D3D10DDI_HDEVICE hDevice,                           // IN
3807ec681f3Smrg                    __in struct D3D10DDI_DEVICEFUNCS *pDeviceFunctions) // IN
3817ec681f3Smrg{
3827ec681f3Smrg   LOG_ENTRYPOINT();
3837ec681f3Smrg
3847ec681f3Smrg   /*
3857ec681f3Smrg    * Nothing to do as we don't store a pointer to this entity.
3867ec681f3Smrg    */
3877ec681f3Smrg}
3887ec681f3Smrg
3897ec681f3Smrg
3907ec681f3Smrg/*
3917ec681f3Smrg * ----------------------------------------------------------------------
3927ec681f3Smrg *
3937ec681f3Smrg * RelocateDeviceFuncs1 --
3947ec681f3Smrg *
3957ec681f3Smrg *    The RelocateDeviceFuncs function notifies the user-mode
3967ec681f3Smrg *    display driver about the new location of the driver function table.
3977ec681f3Smrg *
3987ec681f3Smrg * ----------------------------------------------------------------------
3997ec681f3Smrg */
4007ec681f3Smrg
4017ec681f3Smrgvoid APIENTRY
4027ec681f3SmrgRelocateDeviceFuncs1(D3D10DDI_HDEVICE hDevice,                           // IN
4037ec681f3Smrg                    __in struct D3D10_1DDI_DEVICEFUNCS *pDeviceFunctions) // IN
4047ec681f3Smrg{
4057ec681f3Smrg   LOG_ENTRYPOINT();
4067ec681f3Smrg
4077ec681f3Smrg   /*
4087ec681f3Smrg    * Nothing to do as we don't store a pointer to this entity.
4097ec681f3Smrg    */
4107ec681f3Smrg}
4117ec681f3Smrg
4127ec681f3Smrg
4137ec681f3Smrg/*
4147ec681f3Smrg * ----------------------------------------------------------------------
4157ec681f3Smrg *
4167ec681f3Smrg * Flush --
4177ec681f3Smrg *
4187ec681f3Smrg *    The Flush function submits outstanding hardware commands that
4197ec681f3Smrg *    are in the hardware command buffer to the display miniport driver.
4207ec681f3Smrg *
4217ec681f3Smrg * ----------------------------------------------------------------------
4227ec681f3Smrg */
4237ec681f3Smrg
4247ec681f3Smrgvoid APIENTRY
4257ec681f3SmrgFlush(D3D10DDI_HDEVICE hDevice)  // IN
4267ec681f3Smrg{
4277ec681f3Smrg   LOG_ENTRYPOINT();
4287ec681f3Smrg
4297ec681f3Smrg   struct pipe_context *pipe = CastPipeContext(hDevice);
4307ec681f3Smrg
4317ec681f3Smrg   pipe->flush(pipe, NULL, 0);
4327ec681f3Smrg}
4337ec681f3Smrg
4347ec681f3Smrg
4357ec681f3Smrg/*
4367ec681f3Smrg * ----------------------------------------------------------------------
4377ec681f3Smrg *
4387ec681f3Smrg * CheckFormatSupport --
4397ec681f3Smrg *
4407ec681f3Smrg *    The CheckFormatSupport function retrieves the capabilites that
4417ec681f3Smrg *    the device has with the specified format.
4427ec681f3Smrg *
4437ec681f3Smrg * ----------------------------------------------------------------------
4447ec681f3Smrg */
4457ec681f3Smrg
4467ec681f3Smrgvoid APIENTRY
4477ec681f3SmrgCheckFormatSupport(D3D10DDI_HDEVICE hDevice, // IN
4487ec681f3Smrg                   DXGI_FORMAT Format,       // IN
4497ec681f3Smrg                   __out UINT *pFormatCaps)  // OUT
4507ec681f3Smrg{
4517ec681f3Smrg   //LOG_ENTRYPOINT();
4527ec681f3Smrg
4537ec681f3Smrg   struct pipe_context *pipe = CastPipeContext(hDevice);
4547ec681f3Smrg   struct pipe_screen *screen = pipe->screen;
4557ec681f3Smrg
4567ec681f3Smrg   *pFormatCaps = 0;
4577ec681f3Smrg
4587ec681f3Smrg   enum pipe_format format = FormatTranslate(Format, FALSE);
4597ec681f3Smrg   if (format == PIPE_FORMAT_NONE) {
4607ec681f3Smrg      *pFormatCaps = D3D10_DDI_FORMAT_SUPPORT_NOT_SUPPORTED;
4617ec681f3Smrg      return;
4627ec681f3Smrg   }
4637ec681f3Smrg
4647ec681f3Smrg   if (Format == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM) {
4657ec681f3Smrg      /*
4667ec681f3Smrg       * We only need to support creation.
4677ec681f3Smrg       * http://msdn.microsoft.com/en-us/library/windows/hardware/ff552818.aspx
4687ec681f3Smrg       */
4697ec681f3Smrg      return;
4707ec681f3Smrg   }
4717ec681f3Smrg
4727ec681f3Smrg   if (screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 0, 0,
4737ec681f3Smrg                                   PIPE_BIND_RENDER_TARGET)) {
4747ec681f3Smrg      *pFormatCaps |= D3D10_DDI_FORMAT_SUPPORT_RENDERTARGET;
4757ec681f3Smrg      *pFormatCaps |= D3D10_DDI_FORMAT_SUPPORT_BLENDABLE;
4767ec681f3Smrg
4777ec681f3Smrg#if SUPPORT_MSAA
4787ec681f3Smrg      if (screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 4, 4,
4797ec681f3Smrg                                      PIPE_BIND_RENDER_TARGET)) {
4807ec681f3Smrg         *pFormatCaps |= D3D10_DDI_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET;
4817ec681f3Smrg      }
4827ec681f3Smrg#endif
4837ec681f3Smrg   }
4847ec681f3Smrg
4857ec681f3Smrg   if (screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 0, 0,
4867ec681f3Smrg                                   PIPE_BIND_SAMPLER_VIEW)) {
4877ec681f3Smrg      *pFormatCaps |= D3D10_DDI_FORMAT_SUPPORT_SHADER_SAMPLE;
4887ec681f3Smrg
4897ec681f3Smrg#if SUPPORT_MSAA
4907ec681f3Smrg      if (screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 4, 4,
4917ec681f3Smrg                                      PIPE_BIND_RENDER_TARGET)) {
4927ec681f3Smrg         *pFormatCaps |= D3D10_DDI_FORMAT_SUPPORT_MULTISAMPLE_LOAD;
4937ec681f3Smrg      }
4947ec681f3Smrg#endif
4957ec681f3Smrg   }
4967ec681f3Smrg}
4977ec681f3Smrg
4987ec681f3Smrg
4997ec681f3Smrg/*
5007ec681f3Smrg * ----------------------------------------------------------------------
5017ec681f3Smrg *
5027ec681f3Smrg * CheckMultisampleQualityLevels --
5037ec681f3Smrg *
5047ec681f3Smrg *    The CheckMultisampleQualityLevels function retrieves the number
5057ec681f3Smrg *    of quality levels that the device supports for the specified
5067ec681f3Smrg *    number of samples.
5077ec681f3Smrg *
5087ec681f3Smrg * ----------------------------------------------------------------------
5097ec681f3Smrg */
5107ec681f3Smrg
5117ec681f3Smrgvoid APIENTRY
5127ec681f3SmrgCheckMultisampleQualityLevels(D3D10DDI_HDEVICE hDevice,        // IN
5137ec681f3Smrg                              DXGI_FORMAT Format,              // IN
5147ec681f3Smrg                              UINT SampleCount,                // IN
5157ec681f3Smrg                              __out UINT *pNumQualityLevels)   // OUT
5167ec681f3Smrg{
5177ec681f3Smrg   //LOG_ENTRYPOINT();
5187ec681f3Smrg
5197ec681f3Smrg   /* XXX: Disable MSAA */
5207ec681f3Smrg   *pNumQualityLevels = 0;
5217ec681f3Smrg}
5227ec681f3Smrg
5237ec681f3Smrg
5247ec681f3Smrg/*
5257ec681f3Smrg * ----------------------------------------------------------------------
5267ec681f3Smrg *
5277ec681f3Smrg * SetTextFilterSize --
5287ec681f3Smrg *
5297ec681f3Smrg *    The SetTextFilterSize function sets the width and height
5307ec681f3Smrg *    of the monochrome convolution filter.
5317ec681f3Smrg *
5327ec681f3Smrg * ----------------------------------------------------------------------
5337ec681f3Smrg */
5347ec681f3Smrg
5357ec681f3Smrgvoid APIENTRY
5367ec681f3SmrgSetTextFilterSize(D3D10DDI_HDEVICE hDevice,  // IN
5377ec681f3Smrg                  UINT Width,                // IN
5387ec681f3Smrg                  UINT Height)               // IN
5397ec681f3Smrg{
5407ec681f3Smrg   LOG_ENTRYPOINT();
5417ec681f3Smrg
5427ec681f3Smrg   LOG_UNSUPPORTED(Width != 1 || Height != 1);
5437ec681f3Smrg}
544