gpt4 book ai didi

c - D3D11CreateDeviceAndSwapChain 软件参数

转载 作者:行者123 更新时间:2023-11-30 15:28:40 26 4
gpt4 key购买 nike

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。快来看看hereRemoving the Need for Custom Software Rasterizers部分.

另一方面,就你的观点而言,我希望 WARP 驱动程序是开源的。我很想使用上面的代码来尝试它!

希望这有帮助。

编辑:

我确实偶然发现了this link其中似乎有一个开源 3D 软件光栅器。请记住,它必须与您的目标功能级别(D3D 版本)完全兼容且稳定。

关于c - D3D11CreateDeviceAndSwapChain 软件参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26499159/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com