D3D12: Fix texture ownership semantics and remove GetSwapChain() exposure
This commit fixes the D3D12 texture architecture issues: 1. D3D12Texture ownership semantics: - Add m_ownsResource member to track resource ownership - InitializeFromExisting() now takes ownsResource parameter (default false) - Shutdown() only releases resource if ownsResource is true - Initialize() sets m_ownsResource = true for created resources 2. D3D12SwapChain changes: - Remove GetSwapChain() method (was exposing native D3D12 API) - Change GetBackBuffer() to return reference instead of pointer - Back buffers initialized with ownsResource = false 3. minimal/main.cpp updates: - Remove gColorRTs[2] array (was duplicating back buffer wrapping) - Direct use of gSwapChain.GetBackBuffer(i) instead - All references updated to use encapsulated API 4. Documentation: - Update TEST_SPEC.md v1.3 - Remove known limitation 7.2 (minimal GetBuffer issue fixed) - Add D3D12_Texture_Architecture_Fix_Plan.md design document
This commit is contained in:
@@ -290,22 +290,6 @@ engine/
|
||||
|
||||
**状态**: 待修复
|
||||
|
||||
### 7.2 minimal GetBuffer 原生调用
|
||||
|
||||
**问题**: `minimal/main.cpp` 第 127-129 行仍使用原生 D3D12 API:
|
||||
|
||||
```cpp
|
||||
ID3D12Resource* buffer = nullptr;
|
||||
gSwapChain.GetSwapChain()->GetBuffer(i, IID_PPV_ARGS(&buffer));
|
||||
gColorRTs[i].InitializeFromExisting(buffer);
|
||||
```
|
||||
|
||||
**原因**: SwapChain back buffer 获取后需要通过 `InitializeFromExisting()` 绑定到已有的 `D3D12Texture` 对象。当前没有优雅的封装方案保留此语义。
|
||||
|
||||
**影响**: minimal 集成测试仍包含少量原生 D3D12 代码
|
||||
|
||||
**状态**: 标记为已知限制,暂不修复
|
||||
|
||||
---
|
||||
|
||||
## 8. 规范更新记录
|
||||
@@ -315,9 +299,10 @@ gColorRTs[i].InitializeFromExisting(buffer);
|
||||
| 1.0 | 2026-03-20 | 初始版本 |
|
||||
| 1.1 | 2026-03-20 | 添加 CI 集成章节,补充 Phase 5 内容 |
|
||||
| 1.2 | 2026-03-20 | 重构集成测试目录结构,每个测试独立子文件夹,stb 库移至 engine/third_party/stb/ |
|
||||
| 1.3 | 2026-03-20 | 修复 minimal GetBuffer 原生调用问题:添加 D3D12Texture 所有权语义,删除 GetSwapChain() 暴露方法,移除 gColorRTs 数组 |
|
||||
|
||||
---
|
||||
|
||||
**规范版本**: 1.2
|
||||
**规范版本**: 1.3
|
||||
**最后更新**: 2026-03-20
|
||||
**前置文档**: [tests/TEST_SPEC.md](../TEST_SPEC.md)
|
||||
|
||||
@@ -44,7 +44,6 @@ D3D12CommandAllocator gCommandAllocator;
|
||||
D3D12CommandList gCommandList;
|
||||
|
||||
// Render targets
|
||||
D3D12Texture gColorRTs[2];
|
||||
D3D12Texture gDepthStencil;
|
||||
D3D12DescriptorHeap gRTVHeap;
|
||||
D3D12DescriptorHeap gDSVHeap;
|
||||
@@ -124,13 +123,11 @@ bool InitD3D12() {
|
||||
|
||||
// Create RTVs for back buffers using encapsulated interface
|
||||
for (int i = 0; i < 2; i++) {
|
||||
ID3D12Resource* buffer = nullptr;
|
||||
gSwapChain.GetSwapChain()->GetBuffer(i, IID_PPV_ARGS(&buffer));
|
||||
gColorRTs[i].InitializeFromExisting(buffer);
|
||||
D3D12Texture& backBuffer = gSwapChain.GetBackBuffer(i);
|
||||
|
||||
CPUDescriptorHandle rtvCpuHandle = gRTVHeap.GetCPUDescriptorHandle(i);
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = { rtvCpuHandle.ptr };
|
||||
gRTVs[i].InitializeAt(device, gColorRTs[i].GetResource(), rtvHandle, nullptr);
|
||||
gRTVs[i].InitializeAt(device, backBuffer.GetResource(), rtvHandle, nullptr);
|
||||
}
|
||||
|
||||
// Create DSV
|
||||
@@ -164,7 +161,8 @@ void BeginRender() {
|
||||
gCurrentRTIndex = gSwapChain.GetCurrentBackBufferIndex();
|
||||
|
||||
// Transition render target
|
||||
gCommandList.TransitionBarrier(gColorRTs[gCurrentRTIndex].GetResource(),
|
||||
D3D12Texture& currentBackBuffer = gSwapChain.GetBackBuffer(gCurrentRTIndex);
|
||||
gCommandList.TransitionBarrier(currentBackBuffer.GetResource(),
|
||||
ResourceStates::Present, ResourceStates::RenderTarget);
|
||||
|
||||
// Set render targets using encapsulated interface
|
||||
@@ -189,7 +187,8 @@ void BeginRender() {
|
||||
|
||||
// End rendering
|
||||
void EndRender() {
|
||||
gCommandList.TransitionBarrier(gColorRTs[gCurrentRTIndex].GetResource(),
|
||||
D3D12Texture& currentBackBuffer = gSwapChain.GetBackBuffer(gCurrentRTIndex);
|
||||
gCommandList.TransitionBarrier(currentBackBuffer.GetResource(),
|
||||
ResourceStates::RenderTarget, ResourceStates::Present);
|
||||
}
|
||||
|
||||
@@ -275,7 +274,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
bool screenshotResult = D3D12Screenshot::Capture(
|
||||
gDevice,
|
||||
gCommandQueue,
|
||||
gColorRTs[gCurrentRTIndex],
|
||||
gSwapChain.GetBackBuffer(gCurrentRTIndex),
|
||||
"minimal.ppm"
|
||||
);
|
||||
if (screenshotResult) {
|
||||
|
||||
Reference in New Issue
Block a user