refactor(RHI): 完成 Shader uniform 设置迁移到 CommandList
- 删除 RHIShader 的 OpenGL 风格 SetMat4/SetVec3/SetInt 等方法 - 添加 UniformInfo 结构体和 GetUniformInfos/GetUniformInfo 接口 - D3D12Shader 和 OpenGLShader 实现 CacheUniformInfos - RHICommandList 添加 SetUniform*/SetGlobal* 统一接口 - D3D12 实现 D3D12PipelineLayout 管理 root signature 映射 - 修复 D3D12CommandList::SetPipelineStateInternal 在 Reset 后未重新应用 root signature 的问题 - 更新 OpenGL 集成测试使用新的 SetUniform* API - 所有单元测试和集成测试通过 (8/8 integration tests)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#include "XCEngine/RHI/D3D12/D3D12CommandList.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12ResourceView.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12PipelineState.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12Shader.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12PipelineLayout.h"
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
@@ -10,7 +12,9 @@ D3D12CommandList::D3D12CommandList()
|
||||
, m_currentTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST)
|
||||
, m_currentPipelineState(nullptr)
|
||||
, m_currentRootSignature(nullptr)
|
||||
, m_currentDescriptorHeap(nullptr) {
|
||||
, m_currentDescriptorHeap(nullptr)
|
||||
, m_currentShader(nullptr)
|
||||
, m_currentPipelineLayout(nullptr) {
|
||||
}
|
||||
|
||||
D3D12CommandList::~D3D12CommandList() {
|
||||
@@ -55,6 +59,13 @@ void D3D12CommandList::Shutdown() {
|
||||
m_rtvHeap.Reset();
|
||||
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() {
|
||||
@@ -64,6 +75,7 @@ void D3D12CommandList::Reset() {
|
||||
m_currentTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
|
||||
m_currentPipelineState = nullptr;
|
||||
m_currentRootSignature = nullptr;
|
||||
m_currentPipelineLayout = nullptr;
|
||||
m_currentDescriptorHeap = nullptr;
|
||||
m_resourceStateMap.clear();
|
||||
m_trackedResources.clear();
|
||||
@@ -75,6 +87,103 @@ void D3D12CommandList::Close() {
|
||||
m_commandList->Close();
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetShader(RHIShader* shader) {
|
||||
m_currentShader = static_cast<D3D12Shader*>(shader);
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetPipelineLayout(D3D12PipelineLayout* layout) {
|
||||
m_currentPipelineLayout = layout;
|
||||
if (layout) {
|
||||
SetRootSignature(layout->GetRootSignature());
|
||||
}
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetUniformInt(const char* name, int value) {
|
||||
if (m_currentShader && m_currentPipelineLayout) {
|
||||
const RHIShader::UniformInfo* info = m_currentShader->GetUniformInfo(name);
|
||||
if (info) {
|
||||
uint32_t rootIndex = m_currentPipelineLayout->GetRootParameterIndex(info->bindPoint);
|
||||
if (rootIndex != UINT32_MAX) {
|
||||
m_commandList->SetGraphicsRoot32BitConstants(rootIndex, 1, &value, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetUniformFloat(const char* name, float value) {
|
||||
if (m_currentShader && m_currentPipelineLayout) {
|
||||
const RHIShader::UniformInfo* info = m_currentShader->GetUniformInfo(name);
|
||||
if (info) {
|
||||
uint32_t rootIndex = m_currentPipelineLayout->GetRootParameterIndex(info->bindPoint);
|
||||
if (rootIndex != UINT32_MAX) {
|
||||
m_commandList->SetGraphicsRoot32BitConstants(rootIndex, 1, &value, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetUniformVec3(const char* name, float x, float y, float z) {
|
||||
if (m_currentShader && m_currentPipelineLayout) {
|
||||
const RHIShader::UniformInfo* info = m_currentShader->GetUniformInfo(name);
|
||||
if (info) {
|
||||
uint32_t rootIndex = m_currentPipelineLayout->GetRootParameterIndex(info->bindPoint);
|
||||
if (rootIndex != UINT32_MAX) {
|
||||
float values[3] = { x, y, z };
|
||||
m_commandList->SetGraphicsRoot32BitConstants(rootIndex, 3, values, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetUniformVec4(const char* name, float x, float y, float z, float w) {
|
||||
if (m_currentShader && m_currentPipelineLayout) {
|
||||
const RHIShader::UniformInfo* info = m_currentShader->GetUniformInfo(name);
|
||||
if (info) {
|
||||
uint32_t rootIndex = m_currentPipelineLayout->GetRootParameterIndex(info->bindPoint);
|
||||
if (rootIndex != UINT32_MAX) {
|
||||
float values[4] = { x, y, z, w };
|
||||
m_commandList->SetGraphicsRoot32BitConstants(rootIndex, 4, values, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetUniformMat4(const char* name, const float* value) {
|
||||
if (m_currentShader && m_currentPipelineLayout) {
|
||||
const RHIShader::UniformInfo* info = m_currentShader->GetUniformInfo(name);
|
||||
if (info) {
|
||||
uint32_t rootIndex = m_currentPipelineLayout->GetRootParameterIndex(info->bindPoint);
|
||||
if (rootIndex != UINT32_MAX) {
|
||||
m_commandList->SetGraphicsRoot32BitConstants(rootIndex, 16, value, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -139,6 +248,9 @@ void D3D12CommandList::AliasBarrierInternal(ID3D12Resource* beforeResource, ID3D
|
||||
void D3D12CommandList::SetPipelineStateInternal(ID3D12PipelineState* pso) {
|
||||
m_commandList->SetPipelineState(pso);
|
||||
m_currentPipelineState = pso;
|
||||
if (m_currentRootSignature) {
|
||||
m_commandList->SetGraphicsRootSignature(m_currentRootSignature);
|
||||
}
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetRootSignature(ID3D12RootSignature* signature) {
|
||||
|
||||
Reference in New Issue
Block a user