HRESULT D3D11CreateDeviceAndSwapChain(
_In_ IDXGIAdapter *pAdapter,
_In_ D3D_DRIVER_TYPE DriverType,
_In_ HMODULE Software, //<-- This parameter
_In_ UINT Flags,
_In_ const D3D_FEATURE_LEVEL *pFeatureLevels,
_In_ UINT FeatureLevels,
_In_ UINT SDKVersion,
_In_ const DXGI_SWAP_CHAIN_DESC *pSwapChainDesc,
_Out_ IDXGISwapChain **ppSwapChain,
_Out_ ID3D11Device **ppDevice,
_Out_ D3D_FEATURE_LEVEL *pFeatureLevel,
_Out_ ID3D11DeviceContext **ppImmediateContext
);
有人知道如何使用此参数的示例,例如WARP。
最佳答案
要执行此任务,将需要您编写或使用自定义软件光栅化程序,这意味着您将需要实现整个D3D驱动程序实现并模拟物理设备。然后D3D将所有API调用转发到此模块以执行。该代码看起来与以下代码非常相似:
static const D3D_FEATURE_LEVEL levels[] = {
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_9_2,
D3D_FEATURE_LEVEL_9_1
};
uint32_t flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#ifdef _DEBUG
flags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
Microsoft::WRL::ComPtr<ID3D11Device> device = nullptr;
Microsoft::WRL::ComPtr<ID3D11DeviceContext> deviceContext = nullptr;
Microsoft::WRL::ComPtr<IDXGISwapChain> swapChain = nullptr;
D3D_FEATURE_LEVEL selectedFeatureLevel;
DXGI_SWAP_CHAIN_DESC swap_chain_props { };
swap_chain_props.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swap_chain_props.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
swap_chain_props.SampleDesc.Count = 1;
swap_chain_props.BufferCount = 2;
HMODULE custom_raterizer = ::LoadLibrary(L"X:\\FolderName\\CustomRasterizer.dll");
HRESULT hr = D3D11CreateDeviceAndSwapChain(nullptr,
D3D_DRIVER_TYPE_SOFTWARE,
custom_raterizer,
flags,
levels,
ARRAYSIZE(levels),
D3D11_SDK_VERSION,
&swap_chain_props,
swapChain.GetAddressOf(),
device.GetAddressOf(),
&selectedFeatureLevel,
deviceContext.GetAddressOf());
但是,这将是一项巨大的任务。 WARP对于软件光栅化程序性能非常好,允许您将D3D_DRIVER_TYPE_WARP传递给驱动程序类型,并将nullptr传递给模块句柄。在here部分中窥视Removing the Need for Custom Software Rasterizers。
另一方面,您希望WARP驱动程序是开源的。我想使用上面的代码来玩它!
希望这可以帮助。
编辑:
我确实偶然发现了this link,它似乎具有开源3D软件光栅化器。请记住,它必须与目标功能级别(D3D版本)完全兼容且稳定。