46 lines
1.2 KiB
Markdown
46 lines
1.2 KiB
Markdown
# D3D12Device::Initialize
|
||
|
||
初始化 DirectX 12 设备。
|
||
|
||
```cpp
|
||
bool Initialize(const RHIDeviceDesc& desc) override;
|
||
```
|
||
|
||
根据提供的设备描述配置创建设备对象、DXGI 工厂和 Direct3D 12 设备。此方法会枚举指定的适配器,获取其信息,并初始化调试层(如果启用)。
|
||
|
||
**参数:**
|
||
- `desc` - 设备描述结构体,包含启用调试层、GPU 验证、适配器索引、窗口句柄、分辨率等配置
|
||
|
||
**返回:** `bool` - 初始化成功返回 true,否则返回 false
|
||
|
||
**线程安全:** ❌ 非线程安全,应在单线程中调用
|
||
|
||
**注意:**
|
||
- 如果 `desc.enableDebugLayer` 为 true,将启用 DirectX 12 调试层
|
||
- 如果 `desc.enableGPUValidation` 为 true,将启用 GPU 验证
|
||
- 适配器索引无效时会自动回退到默认适配器
|
||
|
||
**示例:**
|
||
|
||
```cpp
|
||
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;
|
||
}
|
||
```
|
||
|
||
## 相关文档
|
||
|
||
- [D3D12Device 总览](d3d12-device.md)
|
||
- [D3D12Device::Shutdown](d3d12-device-shutdown.md)
|