#include "fixtures/RHITestFixture.h" #include "XCEngine/RHI/RHIRenderPass.h" #include "XCEngine/RHI/RHIFramebuffer.h" #include "XCEngine/RHI/RHITexture.h" #include "XCEngine/RHI/RHIResourceView.h" using namespace XCEngine::RHI; TEST_P(RHITestFixture, RenderPass_Create_ColorOnly) { AttachmentDesc colorAttachment = {}; colorAttachment.format = Format::R8G8B8A8_UNorm; colorAttachment.loadOp = LoadAction::Clear; colorAttachment.storeOp = StoreAction::Store; RHIRenderPass* renderPass = GetDevice()->CreateRenderPass(1, &colorAttachment, nullptr); if (renderPass != nullptr) { EXPECT_EQ(renderPass->GetColorAttachmentCount(), 1u); renderPass->Shutdown(); delete renderPass; } } TEST_P(RHITestFixture, RenderPass_Create_ColorAndDepth) { AttachmentDesc colorAttachment = {}; colorAttachment.format = Format::R8G8B8A8_UNorm; colorAttachment.loadOp = LoadAction::Clear; colorAttachment.storeOp = StoreAction::Store; AttachmentDesc depthAttachment = {}; depthAttachment.format = Format::D24_UNorm_S8_UInt; depthAttachment.loadOp = LoadAction::Clear; depthAttachment.storeOp = StoreAction::Store; RHIRenderPass* renderPass = GetDevice()->CreateRenderPass(1, &colorAttachment, &depthAttachment); if (renderPass != nullptr) { EXPECT_EQ(renderPass->GetColorAttachmentCount(), 1u); EXPECT_NE(renderPass->GetDepthStencilAttachment(), nullptr); renderPass->Shutdown(); delete renderPass; } } TEST_P(RHITestFixture, RenderPass_GetColorAttachmentCount) { AttachmentDesc colorAttachments[2] = {}; colorAttachments[0].format = Format::R8G8B8A8_UNorm; colorAttachments[1].format = Format::R8G8B8A8_UNorm; RHIRenderPass* renderPass = GetDevice()->CreateRenderPass(2, colorAttachments, nullptr); if (renderPass != nullptr) { EXPECT_EQ(renderPass->GetColorAttachmentCount(), 2u); renderPass->Shutdown(); delete renderPass; } } TEST_P(RHITestFixture, RenderPass_GetColorAttachments) { AttachmentDesc colorAttachment = {}; colorAttachment.format = Format::R8G8B8A8_UNorm; colorAttachment.loadOp = LoadAction::Clear; colorAttachment.storeOp = StoreAction::Store; RHIRenderPass* renderPass = GetDevice()->CreateRenderPass(1, &colorAttachment, nullptr); if (renderPass != nullptr) { const AttachmentDesc* attachments = renderPass->GetColorAttachments(); ASSERT_NE(attachments, nullptr); EXPECT_EQ(attachments[0].format, Format::R8G8B8A8_UNorm); renderPass->Shutdown(); delete renderPass; } } TEST_P(RHITestFixture, RenderPass_GetDepthStencilAttachment) { AttachmentDesc colorAttachment = {}; colorAttachment.format = Format::R8G8B8A8_UNorm; AttachmentDesc depthAttachment = {}; depthAttachment.format = Format::D24_UNorm_S8_UInt; RHIRenderPass* renderPass = GetDevice()->CreateRenderPass(1, &colorAttachment, &depthAttachment); if (renderPass != nullptr) { const AttachmentDesc* ds = renderPass->GetDepthStencilAttachment(); ASSERT_NE(ds, nullptr); EXPECT_EQ(ds->format, Format::D24_UNorm_S8_UInt); renderPass->Shutdown(); delete renderPass; } } TEST_P(RHITestFixture, RenderPass_Shutdown) { AttachmentDesc colorAttachment = {}; colorAttachment.format = Format::R8G8B8A8_UNorm; RHIRenderPass* renderPass = GetDevice()->CreateRenderPass(1, &colorAttachment, nullptr); if (renderPass != nullptr) { renderPass->Shutdown(); EXPECT_EQ(renderPass->GetColorAttachmentCount(), 0u); delete renderPass; } } TEST_P(RHITestFixture, RenderPass_DoubleShutdown) { AttachmentDesc colorAttachment = {}; colorAttachment.format = Format::R8G8B8A8_UNorm; RHIRenderPass* renderPass = GetDevice()->CreateRenderPass(1, &colorAttachment, nullptr); if (renderPass != nullptr) { renderPass->Shutdown(); renderPass->Shutdown(); delete renderPass; } } TEST_P(RHITestFixture, RenderPass_NullDepthStencil) { AttachmentDesc colorAttachment = {}; colorAttachment.format = Format::R8G8B8A8_UNorm; RHIRenderPass* renderPass = GetDevice()->CreateRenderPass(1, &colorAttachment, nullptr); if (renderPass != nullptr) { EXPECT_EQ(renderPass->GetDepthStencilAttachment(), nullptr); renderPass->Shutdown(); delete renderPass; } } TEST_P(RHITestFixture, RenderPass_MultipleColorAttachments) { AttachmentDesc colorAttachments[4] = {}; for (int i = 0; i < 4; ++i) { colorAttachments[i].format = Format::R8G8B8A8_UNorm; colorAttachments[i].loadOp = LoadAction::Clear; colorAttachments[i].storeOp = StoreAction::Store; } RHIRenderPass* renderPass = GetDevice()->CreateRenderPass(4, colorAttachments, nullptr); if (renderPass != nullptr) { EXPECT_EQ(renderPass->GetColorAttachmentCount(), 4u); renderPass->Shutdown(); delete renderPass; } } TEST_P(RHITestFixture, RenderPass_GetNativeHandle) { AttachmentDesc colorAttachment = {}; colorAttachment.format = static_cast(Format::R8G8B8A8_UNorm); RHIRenderPass* renderPass = GetDevice()->CreateRenderPass(1, &colorAttachment, nullptr); if (renderPass != nullptr) { void* handle = renderPass->GetNativeHandle(); EXPECT_EQ(handle, nullptr); renderPass->Shutdown(); delete renderPass; } }