Reputation: 1421
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
);
Someone knows an example on how use this parameter, with WARP by example.
Upvotes: 0
Views: 354
Reputation: 2505
To perform such a task would require you to write or use a custom software rasterizer, meaning you would need to implement the entire D3D driver implementation and emulate the physical device. Then D3D will forward all API calls to this module for execution. The code would look very similar to the following:
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());
However, this would be a very large undertaking. WARP performs extremely well for a software rasterizer, allowing you to pass D3D_DRIVER_TYPE_WARP for the driver type, and nullptr for the module handle. Take a peek here in the section Removing the Need for Custom Software Rasterizers.
On the other hand, to your point, I wish the WARP driver was open source. I would love to play around with it using the above code!
Hope this helps.
EDIT:
I did stumble across this link which appear to have a open source 3D software rasterizer. Keep in mind, it would have to be completely compatible and stable with your target feature level (D3D version).
Upvotes: 1