refactor: Clean up RHI interface and implement descriptor set pooling

- Remove unnecessary inline keywords from RHICommandList
- Add TextureType enum for proper texture type classification
- Update DescriptorSet API to support binding with pipeline layout
- Simplify D3D12CommandList implementation
- Implement descriptor set binding with pipeline layout for both D3D12 and OpenGL
This commit is contained in:
2026-03-25 20:50:40 +08:00
parent 6bbd35873b
commit 04a80d10e7
12 changed files with 132 additions and 116 deletions

View File

@@ -101,68 +101,6 @@ void D3D12CommandList::SetPipelineLayout(D3D12PipelineLayout* layout) {
}
}
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::TransitionBarrier(RHIResourceView* resource, ResourceStates stateBefore, ResourceStates stateAfter) {
if (!resource || !resource->IsValid()) return;
D3D12ResourceView* d3d12View = static_cast<D3D12ResourceView*>(resource);
@@ -584,7 +522,20 @@ void D3D12CommandList::ClearRenderTargetView(D3D12_CPU_DESCRIPTOR_HANDLE renderT
}
void D3D12CommandList::Clear(float r, float g, float b, float a, uint32_t buffers) {
(void)r; (void)g; (void)b; (void)a; (void)buffers;
float color[4] = { r, g, b, a };
if (buffers & 1) {
for (const auto& rtvHandle : m_boundRenderTargets) {
m_commandList->ClearRenderTargetView(rtvHandle, color, 0, nullptr);
}
}
if (buffers & 2 || buffers & 4) {
if (m_depthStencilBound) {
uint32_t clearFlags = 0;
if (buffers & 2) clearFlags |= D3D12_CLEAR_FLAG_DEPTH;
if (buffers & 4) clearFlags |= D3D12_CLEAR_FLAG_STENCIL;
m_commandList->ClearDepthStencilView(m_boundDepthStencil, static_cast<D3D12_CLEAR_FLAGS>(clearFlags), 1.0f, 0, 0, nullptr);
}
}
}
void D3D12CommandList::ClearRenderTarget(RHIResourceView* renderTarget, const float color[4]) {