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:
2026-03-25 00:52:36 +08:00
parent a2fc8eca02
commit da48b808cd
6 changed files with 24 additions and 96 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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,

View File

@@ -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);

View File

@@ -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;