Path: blob/21.2-virgl/src/gallium/frontends/d3d10umd/Adapter.cpp
4565 views
/**************************************************************************1*2* Copyright 2012-2021 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL16* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,17* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR18* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE19* USE OR OTHER DEALINGS IN THE SOFTWARE.20*21* The above copyright notice and this permission notice (including the22* next paragraph) shall be included in all copies or substantial portions23* of the Software.24*25**************************************************************************/2627/*28* Adpater.cpp --29* Driver entry point.30*/313233#include "DriverIncludes.h"34#include "Device.h"35#include "State.h"3637#include "Debug.h"3839#include "util/u_memory.h"404142EXTERN_C struct pipe_screen *43d3d10_create_screen(void);444546static HRESULT APIENTRY CloseAdapter(D3D10DDI_HADAPTER hAdapter);4748static unsigned long numAdapters = 0;49#if 050static unsigned long memdbg_no = 0;51#endif5253/*54* ----------------------------------------------------------------------55*56* OpenAdapterCommon --57*58* Common code for OpenAdapter10 and OpenAdapter10_259*60* ----------------------------------------------------------------------61*/626364static HRESULT65OpenAdapterCommon(__inout D3D10DDIARG_OPENADAPTER *pOpenData) // IN66{67#if 068if (numAdapters == 0) {69memdbg_no = debug_memory_begin();70}71#endif72++numAdapters;7374Adapter *pAdaptor = (Adapter *)calloc(sizeof *pAdaptor, 1);75if (!pAdaptor) {76--numAdapters;77return E_OUTOFMEMORY;78}7980pAdaptor->screen = d3d10_create_screen();81if (!pAdaptor->screen) {82free(pAdaptor);83--numAdapters;84return E_OUTOFMEMORY;85}8687pOpenData->hAdapter.pDrvPrivate = pAdaptor;8889pOpenData->pAdapterFuncs->pfnCalcPrivateDeviceSize = CalcPrivateDeviceSize;90pOpenData->pAdapterFuncs->pfnCreateDevice = CreateDevice;91pOpenData->pAdapterFuncs->pfnCloseAdapter = CloseAdapter;9293return S_OK;94}959697/*98* ----------------------------------------------------------------------99*100* OpenAdapter10 --101*102* The OpenAdapter10 function creates a graphics adapter object103* that is referenced in subsequent calls.104*105* ----------------------------------------------------------------------106*/107108109EXTERN_C HRESULT APIENTRY110OpenAdapter10(__inout D3D10DDIARG_OPENADAPTER *pOpenData) // IN111{112LOG_ENTRYPOINT();113114/*115* This is checked here and not on the common code because MSDN docs116* state that it should be ignored on OpenAdapter10_2.117*/118switch (pOpenData->Interface) {119case D3D10_0_DDI_INTERFACE_VERSION:120case D3D10_0_x_DDI_INTERFACE_VERSION:121case D3D10_0_7_DDI_INTERFACE_VERSION:122#if SUPPORT_D3D10_1123case D3D10_1_DDI_INTERFACE_VERSION:124case D3D10_1_x_DDI_INTERFACE_VERSION:125case D3D10_1_7_DDI_INTERFACE_VERSION:126#endif127#if SUPPORT_D3D11128case D3D11_0_DDI_INTERFACE_VERSION:129case D3D11_0_7_DDI_INTERFACE_VERSION:130#endif131break;132default:133if (0) {134DebugPrintf("%s: unsupported interface version 0x%08x\n",135__FUNCTION__, pOpenData->Interface);136}137return E_FAIL;138}139140return OpenAdapterCommon(pOpenData);141}142143144static const UINT64145SupportedDDIInterfaceVersions[] = {146D3D10_0_DDI_SUPPORTED,147D3D10_0_x_DDI_SUPPORTED,148D3D10_0_7_DDI_SUPPORTED,149#if SUPPORT_D3D10_1150D3D10_1_DDI_SUPPORTED,151D3D10_1_x_DDI_SUPPORTED,152D3D10_1_7_DDI_SUPPORTED,153#endif154#if SUPPORT_D3D11155D3D11_0_DDI_SUPPORTED,156D3D11_0_7_DDI_SUPPORTED,157#endif158};159160161/*162* ----------------------------------------------------------------------163*164* GetSupportedVersions --165*166* Return a list of interface versions supported by the graphics167* adapter.168*169* ----------------------------------------------------------------------170*/171172static HRESULT APIENTRY173GetSupportedVersions(D3D10DDI_HADAPTER hAdapter,174UINT32 *puEntries,175UINT64 *pSupportedDDIInterfaceVersions)176{177LOG_ENTRYPOINT();178179if (pSupportedDDIInterfaceVersions &&180*puEntries < ARRAYSIZE(SupportedDDIInterfaceVersions)) {181return E_OUTOFMEMORY;182}183184*puEntries = ARRAYSIZE(SupportedDDIInterfaceVersions);185186if (pSupportedDDIInterfaceVersions) {187memcpy(pSupportedDDIInterfaceVersions,188SupportedDDIInterfaceVersions,189sizeof SupportedDDIInterfaceVersions);190}191192return S_OK;193}194195196/*197* ----------------------------------------------------------------------198*199* GetCaps --200*201* Return the capabilities of the graphics adapter.202*203* ----------------------------------------------------------------------204*/205206static HRESULT APIENTRY207GetCaps(D3D10DDI_HADAPTER hAdapter,208const D3D10_2DDIARG_GETCAPS *pData)209{210LOG_ENTRYPOINT();211memset(pData->pData, 0, pData->DataSize);212return S_OK;213}214215216/*217* ----------------------------------------------------------------------218*219* OpenAdapter10 --220*221* The OpenAdapter10 function creates a graphics adapter object222* that is referenced in subsequent calls.223*224* ----------------------------------------------------------------------225*/226227228EXTERN_C HRESULT APIENTRY229OpenAdapter10_2(__inout D3D10DDIARG_OPENADAPTER *pOpenData) // IN230{231LOG_ENTRYPOINT();232233HRESULT hr = OpenAdapterCommon(pOpenData);234235if (SUCCEEDED(hr)) {236pOpenData->pAdapterFuncs_2->pfnGetSupportedVersions = GetSupportedVersions;237pOpenData->pAdapterFuncs_2->pfnGetCaps = GetCaps;238}239240return hr;241}242243244/*245* ----------------------------------------------------------------------246*247* CloseAdapter --248*249* The CloseAdapter function releases resources for a250* graphics adapter object.251*252* ----------------------------------------------------------------------253*/254255HRESULT APIENTRY256CloseAdapter(D3D10DDI_HADAPTER hAdapter) // IN257{258LOG_ENTRYPOINT();259260Adapter *pAdapter = CastAdapter(hAdapter);261struct pipe_screen *screen = pAdapter->screen;262screen->destroy(screen);263free(pAdapter);264265--numAdapters;266#if 0267if (numAdapters == 0) {268debug_memory_end(memdbg_no);269}270#endif271272return S_OK;273}274275276