From d8e14df78a5a2127d78785eec7fbc9b0cc058a5c Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Thu, 26 Mar 2026 11:44:33 +0800 Subject: [PATCH] fix(rhi): align empty pipeline layout contract --- engine/src/RHI/D3D12/D3D12Device.cpp | 2 +- engine/src/RHI/D3D12/D3D12PipelineLayout.cpp | 6 +- tests/RHI/unit/test_pipeline_layout.cpp | 70 +++++++++----------- 3 files changed, 33 insertions(+), 45 deletions(-) diff --git a/engine/src/RHI/D3D12/D3D12Device.cpp b/engine/src/RHI/D3D12/D3D12Device.cpp index 85b08e31..4d4c2fa1 100644 --- a/engine/src/RHI/D3D12/D3D12Device.cpp +++ b/engine/src/RHI/D3D12/D3D12Device.cpp @@ -155,7 +155,7 @@ void D3D12Device::Shutdown() { bool D3D12Device::CreateDXGIFactory(bool enableDebugLayer) { UINT dxgiFactoryFlags = 0; - { + if (enableDebugLayer) { ID3D12Debug* debugController = nullptr; if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugController)))) { debugController->EnableDebugLayer(); diff --git a/engine/src/RHI/D3D12/D3D12PipelineLayout.cpp b/engine/src/RHI/D3D12/D3D12PipelineLayout.cpp index ca2a344c..fc3e9b29 100644 --- a/engine/src/RHI/D3D12/D3D12PipelineLayout.cpp +++ b/engine/src/RHI/D3D12/D3D12PipelineLayout.cpp @@ -72,12 +72,8 @@ bool D3D12PipelineLayout::InitializeInternal(D3D12Device* device, const RHIPipel rootIndex++; } - if (m_rootParameters.empty()) { - return false; - } - D3D12_ROOT_SIGNATURE_DESC rootSigDesc = D3D12RootSignature::CreateDesc( - m_rootParameters.data(), + m_rootParameters.empty() ? nullptr : m_rootParameters.data(), static_cast(m_rootParameters.size()), nullptr, 0, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT); diff --git a/tests/RHI/unit/test_pipeline_layout.cpp b/tests/RHI/unit/test_pipeline_layout.cpp index 0f71fb8f..b7750f3a 100644 --- a/tests/RHI/unit/test_pipeline_layout.cpp +++ b/tests/RHI/unit/test_pipeline_layout.cpp @@ -13,11 +13,10 @@ TEST_P(RHITestFixture, PipelineLayout_Create_Basic) { desc.uavCount = 0; RHIPipelineLayout* layout = GetDevice()->CreatePipelineLayout(desc); - if (layout != nullptr) { - EXPECT_NE(layout->GetNativeHandle(), nullptr); - layout->Shutdown(); - delete layout; - } + ASSERT_NE(layout, nullptr); + EXPECT_NE(layout->GetNativeHandle(), nullptr); + layout->Shutdown(); + delete layout; } TEST_P(RHITestFixture, PipelineLayout_Create_WithTextures) { @@ -28,11 +27,10 @@ TEST_P(RHITestFixture, PipelineLayout_Create_WithTextures) { desc.uavCount = 0; RHIPipelineLayout* layout = GetDevice()->CreatePipelineLayout(desc); - if (layout != nullptr) { - EXPECT_NE(layout->GetNativeHandle(), nullptr); - layout->Shutdown(); - delete layout; - } + ASSERT_NE(layout, nullptr); + EXPECT_NE(layout->GetNativeHandle(), nullptr); + layout->Shutdown(); + delete layout; } TEST_P(RHITestFixture, PipelineLayout_Create_WithSamplers) { @@ -43,11 +41,10 @@ TEST_P(RHITestFixture, PipelineLayout_Create_WithSamplers) { desc.uavCount = 0; RHIPipelineLayout* layout = GetDevice()->CreatePipelineLayout(desc); - if (layout != nullptr) { - EXPECT_NE(layout->GetNativeHandle(), nullptr); - layout->Shutdown(); - delete layout; - } + ASSERT_NE(layout, nullptr); + EXPECT_NE(layout->GetNativeHandle(), nullptr); + layout->Shutdown(); + delete layout; } TEST_P(RHITestFixture, PipelineLayout_Create_WithUAVs) { @@ -58,11 +55,10 @@ TEST_P(RHITestFixture, PipelineLayout_Create_WithUAVs) { desc.uavCount = 3; RHIPipelineLayout* layout = GetDevice()->CreatePipelineLayout(desc); - if (layout != nullptr) { - EXPECT_NE(layout->GetNativeHandle(), nullptr); - layout->Shutdown(); - delete layout; - } + ASSERT_NE(layout, nullptr); + EXPECT_NE(layout->GetNativeHandle(), nullptr); + layout->Shutdown(); + delete layout; } TEST_P(RHITestFixture, PipelineLayout_Create_Complex) { @@ -73,11 +69,10 @@ TEST_P(RHITestFixture, PipelineLayout_Create_Complex) { desc.uavCount = 1; RHIPipelineLayout* layout = GetDevice()->CreatePipelineLayout(desc); - if (layout != nullptr) { - EXPECT_NE(layout->GetNativeHandle(), nullptr); - layout->Shutdown(); - delete layout; - } + ASSERT_NE(layout, nullptr); + EXPECT_NE(layout->GetNativeHandle(), nullptr); + layout->Shutdown(); + delete layout; } TEST_P(RHITestFixture, PipelineLayout_Create_ZeroCounts) { @@ -88,11 +83,10 @@ TEST_P(RHITestFixture, PipelineLayout_Create_ZeroCounts) { desc.uavCount = 0; RHIPipelineLayout* layout = GetDevice()->CreatePipelineLayout(desc); - if (layout != nullptr) { - EXPECT_NE(layout->GetNativeHandle(), nullptr); - layout->Shutdown(); - delete layout; - } + ASSERT_NE(layout, nullptr); + EXPECT_NE(layout->GetNativeHandle(), nullptr); + layout->Shutdown(); + delete layout; } TEST_P(RHITestFixture, PipelineLayout_Shutdown) { @@ -102,10 +96,9 @@ TEST_P(RHITestFixture, PipelineLayout_Shutdown) { desc.samplerCount = 1; RHIPipelineLayout* layout = GetDevice()->CreatePipelineLayout(desc); - if (layout != nullptr) { - layout->Shutdown(); - delete layout; - } + ASSERT_NE(layout, nullptr); + layout->Shutdown(); + delete layout; } TEST_P(RHITestFixture, PipelineLayout_DoubleShutdown) { @@ -113,11 +106,10 @@ TEST_P(RHITestFixture, PipelineLayout_DoubleShutdown) { desc.constantBufferCount = 1; RHIPipelineLayout* layout = GetDevice()->CreatePipelineLayout(desc); - if (layout != nullptr) { - layout->Shutdown(); - layout->Shutdown(); - delete layout; - } + ASSERT_NE(layout, nullptr); + layout->Shutdown(); + layout->Shutdown(); + delete layout; } TEST_P(RHITestFixture, PipelineLayout_DescriptorSetAllocation) {