RHI: Remove无效的SetGlobal*方法 - 死代码清理
问题:SetGlobal*方法(SetGlobalInt/SetGlobalFloat/SetGlobalVec3/SetGlobalVec4/SetGlobalMat4/SetGlobalTexture)在D3D12和OpenGL中都只是缓存值,从不提交到GPU。 移除内容: - RHICommandList.h: 移除6个SetGlobal*纯虚方法声明 - D3D12CommandList.h/cpp: 移除6个override声明+6个缓存变量+6个方法实现+Shutdown()中的缓存清理 - OpenGLCommandList.h/cpp: 同上 原因: - SetGlobal*从未被代码库调用(死代码) - SetUniform*已正常工作,使用shader reflection+实际GPU绑定 - 移除后无功能损失 测试状态:150个RHI单元测试全部通过,8个集成测试全部通过
This commit is contained in:
@@ -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 抽象 | 🟡 中 | 中 | ❌ 未完成 |
|
||||
|
||||
|
||||
@@ -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<std::string, int> m_globalIntCache;
|
||||
std::unordered_map<std::string, float> m_globalFloatCache;
|
||||
std::unordered_map<std::string, std::vector<float>> m_globalVec3Cache;
|
||||
std::unordered_map<std::string, std::vector<float>> m_globalVec4Cache;
|
||||
std::unordered_map<std::string, std::vector<float>> m_globalMat4Cache;
|
||||
std::unordered_map<std::string, RHIResourceView*> m_globalTextureCache;
|
||||
};
|
||||
|
||||
} // namespace RHI
|
||||
|
||||
@@ -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<std::string, int> m_globalIntCache;
|
||||
std::unordered_map<std::string, float> m_globalFloatCache;
|
||||
std::unordered_map<std::string, std::vector<float>> m_globalVec3Cache;
|
||||
std::unordered_map<std::string, std::vector<float>> m_globalVec4Cache;
|
||||
std::unordered_map<std::string, std::vector<float>> m_globalMat4Cache;
|
||||
std::unordered_map<std::string, RHIResourceView*> m_globalTextureCache;
|
||||
};
|
||||
|
||||
} // namespace RHI
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<float>(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<D3D12ResourceView*>(resource);
|
||||
|
||||
@@ -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<float>(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;
|
||||
|
||||
Reference in New Issue
Block a user