diff --git a/RHI_Design_Issues.md b/RHI_Design_Issues.md index e01d9865..8623dc85 100644 --- a/RHI_Design_Issues.md +++ b/RHI_Design_Issues.md @@ -373,9 +373,30 @@ virtual void ResourceBarrier(uint32_t count, const ResourceBarrier* barriers) = ## 4. 其他需要修改的问题 -### 4.1 SetGlobal* 是空操作 +### 4.1 SetGlobal* 是空操作 ✅ 已完成 -详见第一版文档,此处不再赘述。 +**问题**:SetGlobal* 方法(SetGlobalInt/SetGlobalFloat/SetGlobalVec3/SetGlobalVec4/SetGlobalMat4/SetGlobalTexture)在 D3D12 和 OpenGL 中只是缓存值,从不提交到 GPU。 + +**实现状态**:2026-03-25 已完成 - 移除所有 SetGlobal* 方法 + +**移除的方法**(共6个): +| 方法 | 问题 | +|------|------| +| `SetGlobalInt` | 只缓存到 unordered_map,从未提交到 GPU | +| `SetGlobalFloat` | 只缓存到 unordered_map,从未提交到 GPU | +| `SetGlobalVec3` | 只缓存到 unordered_map,从未提交到 GPU | +| `SetGlobalVec4` | 只缓存到 unordered_map,从未提交到 GPU | +| `SetGlobalMat4` | 只缓存到 unordered_map,从未提交到 GPU | +| `SetGlobalTexture` | 只缓存到 unordered_map,从未提交到 GPU | + +**移除的缓存成员变量**: +- D3D12CommandList: `m_globalIntCache`, `m_globalFloatCache`, `m_globalVec3Cache`, `m_globalVec4Cache`, `m_globalMat4Cache`, `m_globalTextureCache` +- OpenGLCommandList: 同上 + +**说明**: +- `SetGlobal*` 从未被代码库中任何地方调用(死代码) +- `SetUniform*` 方法已正常工作,使用 shader reflection + 实际 GPU 绑定 +- 移除后无功能损失 ### 4.2 PrimitiveType 和 PrimitiveTopology 冲突 @@ -540,7 +561,7 @@ class RHITexture : public RHIResource { ... }; | 3 | 动态状态太多 | 🔴 高 | 高 | ✅ 已完成 | | 4 | ResourceView 类型不明确 | 🟡 中 | 中 | ✅ 基本完成 | | 5 | TransitionBarrier 针对 View 而非 Resource | 🟡 中 | 中 | ✅ 已完成 | -| 6 | SetGlobal* 空操作 | 🟡 中 | 低 | ❌ 未完成 | +| 6 | SetGlobal* 空操作 | 🟡 中 | 低 | ✅ 已完成 | | 7 | OpenGL 特有方法暴露 | 🟡 中 | 高 | ❌ 未完成 | | 8 | 缺少 Compute Pipeline 抽象 | 🟡 中 | 中 | ❌ 未完成 | diff --git a/engine/include/XCEngine/RHI/D3D12/D3D12CommandList.h b/engine/include/XCEngine/RHI/D3D12/D3D12CommandList.h index e7192218..69ac5d83 100644 --- a/engine/include/XCEngine/RHI/D3D12/D3D12CommandList.h +++ b/engine/include/XCEngine/RHI/D3D12/D3D12CommandList.h @@ -43,13 +43,6 @@ public: void SetUniformVec4(const char* name, float x, float y, float z, float w) override; void SetUniformMat4(const char* name, const float* value) override; - void SetGlobalInt(const char* name, int value) override; - void SetGlobalFloat(const char* name, float value) override; - void SetGlobalVec3(const char* name, float x, float y, float z) override; - void SetGlobalVec4(const char* name, float x, float y, float z, float w) override; - void SetGlobalMat4(const char* name, const float* value) override; - void SetGlobalTexture(const char* name, RHIResourceView* texture) override; - void TransitionBarrier(RHIResourceView* resource, ResourceStates stateBefore, ResourceStates stateAfter) override; void TransitionBarrier(ID3D12Resource* resource, ResourceStates stateBefore, ResourceStates stateAfter); void TransitionBarrierInternal(ID3D12Resource* resource, ResourceStates stateBefore, ResourceStates stateAfter, uint32_t subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES); @@ -164,12 +157,6 @@ private: D3D12Shader* m_currentShader; class D3D12PipelineLayout* m_currentPipelineLayout; - std::unordered_map m_globalIntCache; - std::unordered_map m_globalFloatCache; - std::unordered_map> m_globalVec3Cache; - std::unordered_map> m_globalVec4Cache; - std::unordered_map> m_globalMat4Cache; - std::unordered_map m_globalTextureCache; }; } // namespace RHI diff --git a/engine/include/XCEngine/RHI/OpenGL/OpenGLCommandList.h b/engine/include/XCEngine/RHI/OpenGL/OpenGLCommandList.h index 148c695d..fcadb600 100644 --- a/engine/include/XCEngine/RHI/OpenGL/OpenGLCommandList.h +++ b/engine/include/XCEngine/RHI/OpenGL/OpenGLCommandList.h @@ -60,13 +60,6 @@ public: void SetUniformVec4(const char* name, float x, float y, float z, float w) override; void SetUniformMat4(const char* name, const float* value) override; - void SetGlobalInt(const char* name, int value) override; - void SetGlobalFloat(const char* name, float value) override; - void SetGlobalVec3(const char* name, float x, float y, float z) override; - void SetGlobalVec4(const char* name, float x, float y, float z, float w) override; - void SetGlobalMat4(const char* name, const float* value) override; - void SetGlobalTexture(const char* name, RHIResourceView* texture) override; - void SetPipelineState(RHIPipelineState* pipelineState) override; void SetGraphicsDescriptorSets( uint32_t firstSet, @@ -203,12 +196,6 @@ private: unsigned int m_currentVAO; unsigned int m_currentProgram; OpenGLShader* m_currentShader; - std::unordered_map m_globalIntCache; - std::unordered_map m_globalFloatCache; - std::unordered_map> m_globalVec3Cache; - std::unordered_map> m_globalVec4Cache; - std::unordered_map> m_globalMat4Cache; - std::unordered_map m_globalTextureCache; }; } // namespace RHI diff --git a/engine/include/XCEngine/RHI/RHICommandList.h b/engine/include/XCEngine/RHI/RHICommandList.h index 9b162801..c887f341 100644 --- a/engine/include/XCEngine/RHI/RHICommandList.h +++ b/engine/include/XCEngine/RHI/RHICommandList.h @@ -70,13 +70,6 @@ public: virtual void SetUniformVec4(const char* name, float x, float y, float z, float w) = 0; virtual void SetUniformMat4(const char* name, const float* value) = 0; - virtual void SetGlobalInt(const char* name, int value) = 0; - virtual void SetGlobalFloat(const char* name, float value) = 0; - virtual void SetGlobalVec3(const char* name, float x, float y, float z) = 0; - virtual void SetGlobalVec4(const char* name, float x, float y, float z, float w) = 0; - virtual void SetGlobalMat4(const char* name, const float* value) = 0; - virtual void SetGlobalTexture(const char* name, RHIResourceView* texture) = 0; - virtual void SetPipelineState(RHIPipelineState* pso) = 0; virtual void SetGraphicsDescriptorSets( uint32_t firstSet, diff --git a/engine/src/RHI/D3D12/D3D12CommandList.cpp b/engine/src/RHI/D3D12/D3D12CommandList.cpp index 966bee5e..e30e4428 100644 --- a/engine/src/RHI/D3D12/D3D12CommandList.cpp +++ b/engine/src/RHI/D3D12/D3D12CommandList.cpp @@ -63,12 +63,6 @@ void D3D12CommandList::Shutdown() { m_resourceStateMap.clear(); m_trackedResources.clear(); m_currentShader = nullptr; - m_globalIntCache.clear(); - m_globalFloatCache.clear(); - m_globalVec3Cache.clear(); - m_globalVec4Cache.clear(); - m_globalMat4Cache.clear(); - m_globalTextureCache.clear(); } void D3D12CommandList::Reset() { @@ -163,30 +157,6 @@ void D3D12CommandList::SetUniformMat4(const char* name, const float* value) { } } -void D3D12CommandList::SetGlobalInt(const char* name, int value) { - m_globalIntCache[name] = value; -} - -void D3D12CommandList::SetGlobalFloat(const char* name, float value) { - m_globalFloatCache[name] = value; -} - -void D3D12CommandList::SetGlobalVec3(const char* name, float x, float y, float z) { - m_globalVec3Cache[name] = { x, y, z }; -} - -void D3D12CommandList::SetGlobalVec4(const char* name, float x, float y, float z, float w) { - m_globalVec4Cache[name] = { x, y, z, w }; -} - -void D3D12CommandList::SetGlobalMat4(const char* name, const float* value) { - m_globalMat4Cache[name] = std::vector(value, value + 16); -} - -void D3D12CommandList::SetGlobalTexture(const char* name, RHIResourceView* texture) { - m_globalTextureCache[name] = texture; -} - void D3D12CommandList::TransitionBarrier(RHIResourceView* resource, ResourceStates stateBefore, ResourceStates stateAfter) { if (!resource || !resource->IsValid()) return; D3D12ResourceView* d3d12View = static_cast(resource); diff --git a/engine/src/RHI/OpenGL/OpenGLCommandList.cpp b/engine/src/RHI/OpenGL/OpenGLCommandList.cpp index 22ba87d3..22488bca 100644 --- a/engine/src/RHI/OpenGL/OpenGLCommandList.cpp +++ b/engine/src/RHI/OpenGL/OpenGLCommandList.cpp @@ -429,12 +429,6 @@ void OpenGLCommandList::PopDebugGroup() { void OpenGLCommandList::Shutdown() { m_currentShader = nullptr; - m_globalIntCache.clear(); - m_globalFloatCache.clear(); - m_globalVec3Cache.clear(); - m_globalVec4Cache.clear(); - m_globalMat4Cache.clear(); - m_globalTextureCache.clear(); } void OpenGLCommandList::Reset() { @@ -480,30 +474,6 @@ void OpenGLCommandList::SetUniformMat4(const char* name, const float* value) { } } -void OpenGLCommandList::SetGlobalInt(const char* name, int value) { - m_globalIntCache[name] = value; -} - -void OpenGLCommandList::SetGlobalFloat(const char* name, float value) { - m_globalFloatCache[name] = value; -} - -void OpenGLCommandList::SetGlobalVec3(const char* name, float x, float y, float z) { - m_globalVec3Cache[name] = {x, y, z}; -} - -void OpenGLCommandList::SetGlobalVec4(const char* name, float x, float y, float z, float w) { - m_globalVec4Cache[name] = {x, y, z, w}; -} - -void OpenGLCommandList::SetGlobalMat4(const char* name, const float* value) { - m_globalMat4Cache[name] = std::vector(value, value + 16); -} - -void OpenGLCommandList::SetGlobalTexture(const char* name, RHIResourceView* texture) { - m_globalTextureCache[name] = texture; -} - void OpenGLCommandList::TransitionBarrier(RHIResourceView* resource, ResourceStates stateBefore, ResourceStates stateAfter) { (void)resource; (void)stateBefore;