1.2 KiB
1.2 KiB
D3D12Device::Initialize
初始化 DirectX 12 设备。
bool Initialize(const RHIDeviceDesc& desc) override;
根据提供的设备描述配置创建设备对象、DXGI 工厂和 Direct3D 12 设备。此方法会枚举指定的适配器,获取其信息,并初始化调试层(如果启用)。
参数:
desc- 设备描述结构体,包含启用调试层、GPU 验证、适配器索引、窗口句柄、分辨率等配置
返回: bool - 初始化成功返回 true,否则返回 false
线程安全: ❌ 非线程安全,应在单线程中调用
注意:
- 如果
desc.enableDebugLayer为 true,将启用 DirectX 12 调试层 - 如果
desc.enableGPUValidation为 true,将启用 GPU 验证 - 适配器索引无效时会自动回退到默认适配器
示例:
RHIDeviceDesc desc;
desc.enableDebugLayer = true;
desc.enableGPUValidation = true;
desc.adapterIndex = 0;
desc.windowHandle = hwnd;
desc.width = 1920;
desc.height = 1080;
desc.appName = L"MyApp";
D3D12Device device;
if (!device.Initialize(desc)) {
MessageBox(L"Failed to initialize D3D12 device");
return false;
}