2007-07-09 14:06:40 +02:00
|
|
|
/*
|
|
|
|
* Direct3D 10
|
|
|
|
*
|
|
|
|
* Copyright 2007 Andras Kovacs
|
2009-02-27 09:29:48 +01:00
|
|
|
* Copyright 2009 Henri Verbeet for CodeWeavers
|
2007-07-09 14:06:40 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-10-20 15:28:08 +02:00
|
|
|
#include "d3d10_private.h"
|
2007-07-09 14:06:40 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d10);
|
|
|
|
|
2019-10-30 15:01:32 +01:00
|
|
|
#define WINE_D3D10_TO_STR(x) case x: return #x
|
|
|
|
|
|
|
|
static const char *debug_d3d10_driver_type(D3D10_DRIVER_TYPE driver_type)
|
|
|
|
{
|
|
|
|
switch (driver_type)
|
|
|
|
{
|
|
|
|
WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_HARDWARE);
|
|
|
|
WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_REFERENCE);
|
|
|
|
WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_NULL);
|
|
|
|
WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_SOFTWARE);
|
|
|
|
WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_WARP);
|
|
|
|
default:
|
|
|
|
FIXME("Unrecognised D3D10_DRIVER_TYPE %#x.\n", driver_type);
|
|
|
|
return "unrecognised";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef WINE_D3D10_TO_STR
|
|
|
|
|
2019-02-26 20:09:02 +01:00
|
|
|
static HRESULT d3d10_create_device(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type,
|
2008-10-21 15:06:58 +02:00
|
|
|
HMODULE swrast, UINT flags, UINT sdk_version, ID3D10Device **device)
|
|
|
|
{
|
2008-11-14 13:57:06 +01:00
|
|
|
IDXGIFactory *factory;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2017-05-05 11:59:23 +02:00
|
|
|
TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, sdk_version %#x, device %p.\n",
|
2008-10-21 15:06:58 +02:00
|
|
|
adapter, debug_d3d10_driver_type(driver_type), swrast, flags, sdk_version, device);
|
|
|
|
|
2017-05-05 11:59:23 +02:00
|
|
|
if (sdk_version != D3D10_SDK_VERSION)
|
|
|
|
{
|
|
|
|
WARN("Invalid SDK version %#x.\n", sdk_version);
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2008-11-14 13:57:06 +01:00
|
|
|
if (adapter)
|
|
|
|
{
|
|
|
|
IDXGIAdapter_AddRef(adapter);
|
|
|
|
hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-08 19:48:47 +01:00
|
|
|
WARN("Failed to get dxgi factory, returning %#lx.\n", hr);
|
2008-11-14 13:57:06 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = CreateDXGIFactory(&IID_IDXGIFactory, (void **)&factory);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-08 19:48:47 +01:00
|
|
|
WARN("Failed to create dxgi factory, returning %#lx.\n", hr);
|
2008-11-14 13:57:06 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2017-05-05 11:59:23 +02:00
|
|
|
switch (driver_type)
|
2008-11-14 13:57:06 +01:00
|
|
|
{
|
2018-08-05 00:17:45 +02:00
|
|
|
case D3D10_DRIVER_TYPE_WARP:
|
|
|
|
FIXME("WARP driver not implemented, falling back to hardware.\n");
|
2008-11-14 13:57:06 +01:00
|
|
|
case D3D10_DRIVER_TYPE_HARDWARE:
|
|
|
|
{
|
|
|
|
hr = IDXGIFactory_EnumAdapters(factory, 0, &adapter);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-08 19:48:47 +01:00
|
|
|
WARN("No adapters found, returning %#lx.\n", hr);
|
2008-11-14 13:57:06 +01:00
|
|
|
IDXGIFactory_Release(factory);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case D3D10_DRIVER_TYPE_NULL:
|
2017-05-05 11:59:23 +02:00
|
|
|
FIXME("NULL device not implemented, falling back to refrast.\n");
|
2011-09-24 17:28:32 +02:00
|
|
|
/* fall through, for now */
|
2008-11-14 13:57:06 +01:00
|
|
|
case D3D10_DRIVER_TYPE_REFERENCE:
|
|
|
|
{
|
|
|
|
HMODULE refrast = LoadLibraryA("d3d10ref.dll");
|
|
|
|
if (!refrast)
|
|
|
|
{
|
2017-05-05 11:59:23 +02:00
|
|
|
WARN("Failed to load refrast, returning E_FAIL.\n");
|
2008-11-14 13:57:06 +01:00
|
|
|
IDXGIFactory_Release(factory);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
hr = IDXGIFactory_CreateSoftwareAdapter(factory, refrast, &adapter);
|
|
|
|
FreeLibrary(refrast);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-08 19:48:47 +01:00
|
|
|
WARN("Failed to create a software adapter, returning %#lx.\n", hr);
|
2008-11-14 13:57:06 +01:00
|
|
|
IDXGIFactory_Release(factory);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case D3D10_DRIVER_TYPE_SOFTWARE:
|
|
|
|
{
|
|
|
|
if (!swrast)
|
|
|
|
{
|
2017-05-05 11:59:23 +02:00
|
|
|
WARN("Software device requested, but NULL swrast passed, returning E_FAIL.\n");
|
2008-11-14 13:57:06 +01:00
|
|
|
IDXGIFactory_Release(factory);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
hr = IDXGIFactory_CreateSoftwareAdapter(factory, swrast, &adapter);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-08 19:48:47 +01:00
|
|
|
WARN("Failed to create a software adapter, returning %#lx.\n", hr);
|
2008-11-14 13:57:06 +01:00
|
|
|
IDXGIFactory_Release(factory);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-01-27 10:07:53 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled driver type %#x.\n", driver_type);
|
|
|
|
IDXGIFactory_Release(factory);
|
|
|
|
return E_FAIL;
|
2008-11-14 13:57:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-16 00:24:10 +01:00
|
|
|
hr = D3D10CoreCreateDevice(factory, adapter, flags, D3D_FEATURE_LEVEL_10_0, device);
|
2008-11-14 13:57:06 +01:00
|
|
|
IDXGIAdapter_Release(adapter);
|
|
|
|
IDXGIFactory_Release(factory);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-08 19:48:47 +01:00
|
|
|
WARN("Failed to create a device, returning %#lx.\n", hr);
|
2008-11-14 13:57:06 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2017-05-05 11:59:23 +02:00
|
|
|
TRACE("Created ID3D10Device %p.\n", *device);
|
2008-11-14 13:57:06 +01:00
|
|
|
|
|
|
|
return hr;
|
2008-10-21 15:06:58 +02:00
|
|
|
}
|
2008-10-23 16:37:09 +02:00
|
|
|
|
2019-02-26 20:09:02 +01:00
|
|
|
HRESULT WINAPI D3D10CreateDevice(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type,
|
|
|
|
HMODULE swrast, UINT flags, UINT sdk_version, ID3D10Device **device)
|
|
|
|
{
|
|
|
|
return d3d10_create_device(adapter, driver_type, swrast, flags, sdk_version, device);
|
|
|
|
}
|
|
|
|
|
2008-10-23 16:37:09 +02:00
|
|
|
HRESULT WINAPI D3D10CreateDeviceAndSwapChain(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type,
|
|
|
|
HMODULE swrast, UINT flags, UINT sdk_version, DXGI_SWAP_CHAIN_DESC *swapchain_desc,
|
|
|
|
IDXGISwapChain **swapchain, ID3D10Device **device)
|
|
|
|
{
|
2008-11-14 13:57:07 +01:00
|
|
|
IDXGIDevice *dxgi_device;
|
2008-10-23 16:37:09 +02:00
|
|
|
IDXGIFactory *factory;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2015-08-18 00:53:24 +02:00
|
|
|
TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, sdk_version %d, "
|
|
|
|
"swapchain_desc %p, swapchain %p, device %p\n",
|
2008-10-23 16:37:09 +02:00
|
|
|
adapter, debug_d3d10_driver_type(driver_type), swrast, flags, sdk_version,
|
|
|
|
swapchain_desc, swapchain, device);
|
|
|
|
|
2019-02-26 20:09:02 +01:00
|
|
|
/* Avoid forwarding to D3D10CreateDevice(), since it breaks applications
|
|
|
|
* hooking these entry-points. */
|
|
|
|
if (FAILED(hr = d3d10_create_device(adapter, driver_type, swrast, flags, sdk_version, device)))
|
2008-10-23 16:37:09 +02:00
|
|
|
{
|
2022-02-08 19:48:47 +01:00
|
|
|
WARN("Failed to create a device, returning %#lx.\n", hr);
|
2008-11-14 13:57:07 +01:00
|
|
|
*device = NULL;
|
2008-10-23 16:37:09 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Created ID3D10Device %p\n", *device);
|
|
|
|
|
2008-11-14 13:57:07 +01:00
|
|
|
hr = ID3D10Device_QueryInterface(*device, &IID_IDXGIDevice, (void **)&dxgi_device);
|
2008-10-23 16:37:09 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-08 19:48:47 +01:00
|
|
|
ERR("Failed to get a dxgi device from the d3d10 device, returning %#lx.\n", hr);
|
2008-10-23 16:37:09 +02:00
|
|
|
ID3D10Device_Release(*device);
|
|
|
|
*device = NULL;
|
2008-11-14 13:57:07 +01:00
|
|
|
return hr;
|
|
|
|
}
|
2008-10-23 16:37:09 +02:00
|
|
|
|
2008-11-14 13:57:07 +01:00
|
|
|
hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
|
|
|
|
IDXGIDevice_Release(dxgi_device);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-08 19:48:47 +01:00
|
|
|
ERR("Failed to get the device adapter, returning %#lx.\n", hr);
|
2008-11-14 13:57:07 +01:00
|
|
|
ID3D10Device_Release(*device);
|
|
|
|
*device = NULL;
|
2008-10-23 16:37:09 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2008-11-14 13:57:07 +01:00
|
|
|
hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
|
|
|
|
IDXGIAdapter_Release(adapter);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-08 19:48:47 +01:00
|
|
|
ERR("Failed to get the adapter factory, returning %#lx.\n", hr);
|
2008-11-14 13:57:07 +01:00
|
|
|
ID3D10Device_Release(*device);
|
|
|
|
*device = NULL;
|
|
|
|
return hr;
|
|
|
|
}
|
2008-10-23 16:37:09 +02:00
|
|
|
|
|
|
|
hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)*device, swapchain_desc, swapchain);
|
|
|
|
IDXGIFactory_Release(factory);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ID3D10Device_Release(*device);
|
|
|
|
*device = NULL;
|
|
|
|
|
2022-02-08 19:48:47 +01:00
|
|
|
WARN("Failed to create a swapchain, returning %#lx.\n", hr);
|
2008-10-23 16:37:09 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Created IDXGISwapChain %p\n", *swapchain);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2009-02-26 09:00:01 +01:00
|
|
|
|
2012-01-03 23:06:51 +01:00
|
|
|
HRESULT WINAPI D3D10CompileEffectFromMemory(void *data, SIZE_T data_size, const char *filename,
|
|
|
|
const D3D10_SHADER_MACRO *defines, ID3D10Include *include, UINT hlsl_flags, UINT fx_flags,
|
|
|
|
ID3D10Blob **effect, ID3D10Blob **errors)
|
|
|
|
{
|
2022-02-08 19:48:47 +01:00
|
|
|
TRACE("data %p, data_size %Iu, filename %s, defines %p, include %p, "
|
2018-04-22 22:27:20 +02:00
|
|
|
"hlsl_flags %#x, fx_flags %#x, effect %p, errors %p.\n",
|
2012-01-03 23:06:51 +01:00
|
|
|
data, data_size, wine_dbgstr_a(filename), defines, include,
|
|
|
|
hlsl_flags, fx_flags, effect, errors);
|
|
|
|
|
2018-04-22 22:27:20 +02:00
|
|
|
return D3DCompile(data, data_size, filename, defines, include,
|
|
|
|
NULL, "fx_4_0", hlsl_flags, fx_flags, effect, errors);
|
2012-01-03 23:06:51 +01:00
|
|
|
}
|
|
|
|
|
2013-09-18 10:57:12 +02:00
|
|
|
const char * WINAPI D3D10GetVertexShaderProfile(ID3D10Device *device)
|
2009-11-04 10:37:14 +01:00
|
|
|
{
|
|
|
|
FIXME("device %p stub!\n", device);
|
|
|
|
|
|
|
|
return "vs_4_0";
|
|
|
|
}
|
2009-11-04 10:37:15 +01:00
|
|
|
|
2013-09-18 10:57:12 +02:00
|
|
|
const char * WINAPI D3D10GetGeometryShaderProfile(ID3D10Device *device)
|
2009-11-04 10:37:15 +01:00
|
|
|
{
|
|
|
|
FIXME("device %p stub!\n", device);
|
|
|
|
|
|
|
|
return "gs_4_0";
|
|
|
|
}
|
2009-11-04 10:37:16 +01:00
|
|
|
|
2013-09-18 10:57:12 +02:00
|
|
|
const char * WINAPI D3D10GetPixelShaderProfile(ID3D10Device *device)
|
2009-11-04 10:37:16 +01:00
|
|
|
{
|
|
|
|
FIXME("device %p stub!\n", device);
|
|
|
|
|
|
|
|
return "ps_4_0";
|
|
|
|
}
|