- 新增32个方法文档(D3D12Buffer 13个,D3D12Texture 12个,D3D12SwapChain 6个) - 修复11处跨模块引用错误(rhi-device.md, rhi-texture.md等路径错误) - 清理d3d12-overview.md移除不存在的类引用 - 修复D3D12Device/D3D12CommandList/D3D12CommandQueue方法列表 - D3D12模块现无broken links
123 lines
4.7 KiB
Markdown
123 lines
4.7 KiB
Markdown
# D3D12Device
|
|
|
|
**命名空间**: `XCEngine::RHI`
|
|
|
|
**类型**: `class`
|
|
|
|
**头文件**: `XCEngine/RHI/D3D12/D3D12Device.h`
|
|
|
|
**描述**: DirectX 12 图形设备封装类,负责创建和管理所有 DirectX 12 图形对象
|
|
|
|
## 概述
|
|
|
|
D3D12Device 是 DirectX 12 的核心设备类,封装了 ID3D12Device 接口。它负责枚举显示适配器、创建命令队列、缓冲区、纹理、描述符堆、管道状态对象等所有图形资源。D3D12Device 继承自 RHIDevice 接口,提供跨后端的统一设备管理抽象。
|
|
|
|
该类支持可选的调试层和 GPU 验证功能,便于开发阶段的问题诊断。
|
|
|
|
## 适配器信息结构体
|
|
|
|
### AdapterInfo
|
|
|
|
存储适配器详细信息的结构体。
|
|
|
|
| 成员 | 类型 | 描述 |
|
|
|------|------|------|
|
|
| `description` | `std::wstring` | 适配器描述名称 |
|
|
| `dedicatedVideoMemory` | `uint64_t` | 专用视频内存大小(字节) |
|
|
| `dedicatedSystemMemory` | `uint64_t` | 专用系统内存大小(字节) |
|
|
| `sharedSystemMemory` | `uint64_t` | 共享系统内存大小(字节) |
|
|
| `vendorId` | `uint32_t` | 硬件供应商 ID |
|
|
| `deviceId` | `uint32_t` | 设备 ID |
|
|
| `isSoftware` | `bool` | 是否为软件适配器 |
|
|
|
|
## 公共方法
|
|
|
|
| 方法 | 描述 |
|
|
|------|------|
|
|
| `D3D12Device()` | 默认构造函数 |
|
|
| `~D3D12Device()` | 虚析构函数 |
|
|
| [Initialize](d3d12-device-initialize.md) | 初始化设备 |
|
|
| [Shutdown](d3d12-device-shutdown.md) | 关闭设备并释放资源 |
|
|
| [GetDevice](d3d12-device-get-device.md) | 获取底层 ID3D12Device 指针 |
|
|
| [GetFactory](d3d12-device-get-factory.md) | 获取底层 IDXGIFactory4 指针 |
|
|
| [GetAdapterInfo](d3d12-device-get-adapter-info.md) | 获取当前适配器信息 |
|
|
| [EnumerateAdapters](d3d12-device-enumerate-adapters.md) | 枚举所有可用适配器 |
|
|
| [GetDescriptorHandleIncrementSize](d3d12-device-get-descriptor-handle-increment-size.md) | 获取描述符增量大小 |
|
|
| [CheckFeatureSupport](d3d12-device-check-feature-support.md) | 检查功能特性支持 |
|
|
| [SetDeviceRemoved](d3d12-device-set-device-removed.md) | 标记设备已移除 |
|
|
| [IsDeviceRemoved](d3d12-device-is-device-removed.md) | 检查设备是否已移除 |
|
|
| [CreateBuffer](d3d12-device-create-buffer.md) | 创建缓冲区资源 |
|
|
| [CreateTexture](d3d12-device-create-texture.md) | 创建纹理资源 |
|
|
| [CreateSwapChain](d3d12-device-create-swap-chain.md) | 创建交换链 |
|
|
| [CreateCommandList](d3d12-device-create-command-list.md) | 创建命令列表 |
|
|
| [CreateCommandQueue](d3d12-device-create-command-queue.md) | 创建命令队列 |
|
|
| [CompileShader](d3d12-device-compile-shader.md) | 编译着色器 |
|
|
| [CreatePipelineState](d3d12-device-create-pipeline-state.md) | 创建管道状态对象 |
|
|
| [CreateFence](d3d12-device-create-fence.md) | 创建围栏 |
|
|
| [CreateSampler](d3d12-device-create-sampler.md) | 创建采样器 |
|
|
| [GetCapabilities](d3d12-device-get-capabilities.md) | 获取设备能力 |
|
|
| [GetDeviceInfo](d3d12-device-get-device-info.md) | 获取设备信息 |
|
|
| [GetNativeDevice](d3d12-device-get-native-device.md) | 获取原生设备指针 |
|
|
| [GetNativeHandle](d3d12-device-get-native-handle.md) | 获取原生句柄 |
|
|
|
|
## 使用示例
|
|
|
|
```cpp
|
|
#include <XCEngine/RHI/D3D12/D3D12Device.h>
|
|
|
|
using namespace XCEngine::RHI;
|
|
|
|
// 创建设备实例
|
|
D3D12Device device;
|
|
|
|
// 配置设备参数
|
|
RHIDeviceDesc desc;
|
|
desc.enableDebugLayer = true; // 启用调试层
|
|
desc.enableGPUValidation = true; // 启用 GPU 验证
|
|
desc.adapterIndex = 0; // 使用第一个适配器
|
|
desc.windowHandle = hwnd; // 窗口句柄
|
|
desc.width = 1280;
|
|
desc.height = 720;
|
|
desc.appName = L"XCEngine App";
|
|
|
|
// 初始化设备
|
|
if (!device.Initialize(desc)) {
|
|
// 处理初始化失败
|
|
return false;
|
|
}
|
|
|
|
// 获取设备信息
|
|
const RHIDeviceInfo& info = device.GetDeviceInfo();
|
|
printf("GPU: %ls\n", info.description.c_str());
|
|
|
|
// 获取设备能力
|
|
const RHICapabilities& caps = device.GetCapabilities();
|
|
printf("MaxTextureSize: %u\n", caps.maxTextureSize);
|
|
|
|
// 创建命令队列
|
|
CommandQueueDesc queueDesc;
|
|
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
|
|
queueDesc.priority = 0;
|
|
queueDesc.nodeMask = 0;
|
|
queueDesc.flags = 0;
|
|
D3D12CommandQueue* commandQueue = device.CreateCommandQueueImpl(queueDesc);
|
|
|
|
// 创建缓冲区
|
|
BufferDesc bufferDesc;
|
|
bufferDesc.size = 1024 * 1024; // 1MB
|
|
bufferDesc.stride = 0;
|
|
bufferDesc.bufferType = static_cast<uint32_t>(BufferType::Vertex);
|
|
bufferDesc.flags = 0;
|
|
RHIBuffer* buffer = device.CreateBuffer(bufferDesc);
|
|
|
|
// 设备关闭
|
|
device.Shutdown();
|
|
```
|
|
|
|
## 相关文档
|
|
|
|
- [D3D12 模块概览](d3d12.md) - D3D12 模块总览
|
|
- [RHIDevice](../rhi/device/device.md) - RHI 设备基类
|
|
- [D3D12CommandQueue](d3d12-command-queue.md) - 命令队列
|
|
- [D3D12Buffer](d3d12-buffer.md) - 缓冲区资源
|