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为例。
答案 0 :(得分:1)
要执行此类任务,您需要编写或使用自定义软件光栅化器,这意味着您需要实现整个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版本)完全兼容且稳定。