333 lines
12 KiB
C++
333 lines
12 KiB
C++
#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, Framebuffer_Create_Basic) {
|
|
AttachmentDesc colorAttachment = {};
|
|
colorAttachment.format = static_cast<Format>(Format::R8G8B8A8_UNorm);
|
|
colorAttachment.loadOp = LoadAction::Clear;
|
|
colorAttachment.storeOp = StoreAction::Store;
|
|
|
|
RHIRenderPass* renderPass = GetDevice()->CreateRenderPass(1, &colorAttachment, nullptr);
|
|
ASSERT_NE(renderPass, nullptr);
|
|
|
|
TextureDesc texDesc = {};
|
|
texDesc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
|
texDesc.width = 256;
|
|
texDesc.height = 256;
|
|
texDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
texDesc.sampleCount = 1;
|
|
|
|
RHITexture* texture = GetDevice()->CreateTexture(texDesc);
|
|
if (texture != nullptr) {
|
|
ResourceViewDesc rtvDesc = {};
|
|
rtvDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
RHIResourceView* rtv = GetDevice()->CreateRenderTargetView(texture, rtvDesc);
|
|
if (rtv != nullptr) {
|
|
RHIFramebuffer* fb = GetDevice()->CreateFramebuffer(
|
|
renderPass, 256, 256, 1, &rtv, nullptr);
|
|
if (fb != nullptr) {
|
|
EXPECT_EQ(fb->GetWidth(), 256u);
|
|
EXPECT_EQ(fb->GetHeight(), 256u);
|
|
fb->Shutdown();
|
|
delete fb;
|
|
}
|
|
rtv->Shutdown();
|
|
delete rtv;
|
|
}
|
|
texture->Shutdown();
|
|
delete texture;
|
|
}
|
|
renderPass->Shutdown();
|
|
delete renderPass;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, Framebuffer_GetWidthHeight) {
|
|
AttachmentDesc colorAttachment = {};
|
|
colorAttachment.format = static_cast<Format>(Format::R8G8B8A8_UNorm);
|
|
|
|
RHIRenderPass* renderPass = GetDevice()->CreateRenderPass(1, &colorAttachment, nullptr);
|
|
ASSERT_NE(renderPass, nullptr);
|
|
|
|
TextureDesc texDesc = {};
|
|
texDesc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
|
texDesc.width = 512;
|
|
texDesc.height = 512;
|
|
texDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
|
|
RHITexture* texture = GetDevice()->CreateTexture(texDesc);
|
|
if (texture != nullptr) {
|
|
ResourceViewDesc rtvDesc = {};
|
|
rtvDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
RHIResourceView* rtv = GetDevice()->CreateRenderTargetView(texture, rtvDesc);
|
|
if (rtv != nullptr) {
|
|
RHIFramebuffer* fb = GetDevice()->CreateFramebuffer(
|
|
renderPass, 512, 512, 1, &rtv, nullptr);
|
|
if (fb != nullptr) {
|
|
EXPECT_EQ(fb->GetWidth(), 512u);
|
|
EXPECT_EQ(fb->GetHeight(), 512u);
|
|
fb->Shutdown();
|
|
delete fb;
|
|
}
|
|
rtv->Shutdown();
|
|
delete rtv;
|
|
}
|
|
texture->Shutdown();
|
|
delete texture;
|
|
}
|
|
renderPass->Shutdown();
|
|
delete renderPass;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, Framebuffer_IsValid) {
|
|
AttachmentDesc colorAttachment = {};
|
|
colorAttachment.format = static_cast<Format>(Format::R8G8B8A8_UNorm);
|
|
|
|
RHIRenderPass* renderPass = GetDevice()->CreateRenderPass(1, &colorAttachment, nullptr);
|
|
ASSERT_NE(renderPass, nullptr);
|
|
|
|
TextureDesc texDesc = {};
|
|
texDesc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
|
texDesc.width = 256;
|
|
texDesc.height = 256;
|
|
texDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
|
|
RHITexture* texture = GetDevice()->CreateTexture(texDesc);
|
|
if (texture != nullptr) {
|
|
ResourceViewDesc rtvDesc = {};
|
|
rtvDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
RHIResourceView* rtv = GetDevice()->CreateRenderTargetView(texture, rtvDesc);
|
|
if (rtv != nullptr) {
|
|
RHIFramebuffer* fb = GetDevice()->CreateFramebuffer(
|
|
renderPass, 256, 256, 1, &rtv, nullptr);
|
|
if (fb != nullptr) {
|
|
EXPECT_TRUE(fb->IsValid());
|
|
fb->Shutdown();
|
|
delete fb;
|
|
}
|
|
rtv->Shutdown();
|
|
delete rtv;
|
|
}
|
|
texture->Shutdown();
|
|
delete texture;
|
|
}
|
|
renderPass->Shutdown();
|
|
delete renderPass;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, Framebuffer_Shutdown) {
|
|
AttachmentDesc colorAttachment = {};
|
|
colorAttachment.format = static_cast<Format>(Format::R8G8B8A8_UNorm);
|
|
|
|
RHIRenderPass* renderPass = GetDevice()->CreateRenderPass(1, &colorAttachment, nullptr);
|
|
ASSERT_NE(renderPass, nullptr);
|
|
|
|
TextureDesc texDesc = {};
|
|
texDesc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
|
texDesc.width = 256;
|
|
texDesc.height = 256;
|
|
texDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
|
|
RHITexture* texture = GetDevice()->CreateTexture(texDesc);
|
|
if (texture != nullptr) {
|
|
ResourceViewDesc rtvDesc = {};
|
|
rtvDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
RHIResourceView* rtv = GetDevice()->CreateRenderTargetView(texture, rtvDesc);
|
|
if (rtv != nullptr) {
|
|
RHIFramebuffer* fb = GetDevice()->CreateFramebuffer(
|
|
renderPass, 256, 256, 1, &rtv, nullptr);
|
|
if (fb != nullptr) {
|
|
fb->Shutdown();
|
|
delete fb;
|
|
}
|
|
rtv->Shutdown();
|
|
delete rtv;
|
|
}
|
|
texture->Shutdown();
|
|
delete texture;
|
|
}
|
|
renderPass->Shutdown();
|
|
delete renderPass;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, Framebuffer_WithDepthStencil) {
|
|
AttachmentDesc colorAttachment = {};
|
|
colorAttachment.format = static_cast<Format>(Format::R8G8B8A8_UNorm);
|
|
|
|
AttachmentDesc depthAttachment = {};
|
|
depthAttachment.format = Format::D24_UNorm_S8_UInt;
|
|
|
|
RHIRenderPass* renderPass = GetDevice()->CreateRenderPass(1, &colorAttachment, &depthAttachment);
|
|
ASSERT_NE(renderPass, nullptr);
|
|
|
|
TextureDesc colorDesc = {};
|
|
colorDesc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
|
colorDesc.width = 256;
|
|
colorDesc.height = 256;
|
|
colorDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
|
|
TextureDesc depthDesc = {};
|
|
depthDesc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
|
depthDesc.width = 256;
|
|
depthDesc.height = 256;
|
|
depthDesc.format = static_cast<uint32_t>(Format::D24_UNorm_S8_UInt);
|
|
|
|
RHITexture* colorTexture = GetDevice()->CreateTexture(colorDesc);
|
|
RHITexture* depthTexture = GetDevice()->CreateTexture(depthDesc);
|
|
|
|
if (colorTexture != nullptr && depthTexture != nullptr) {
|
|
ResourceViewDesc rtvDesc = {};
|
|
rtvDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
RHIResourceView* rtv = GetDevice()->CreateRenderTargetView(colorTexture, rtvDesc);
|
|
|
|
ResourceViewDesc dsvDesc = {};
|
|
dsvDesc.format = static_cast<uint32_t>(Format::D24_UNorm_S8_UInt);
|
|
RHIResourceView* dsv = GetDevice()->CreateDepthStencilView(depthTexture, dsvDesc);
|
|
|
|
if (rtv != nullptr && dsv != nullptr) {
|
|
RHIFramebuffer* fb = GetDevice()->CreateFramebuffer(
|
|
renderPass, 256, 256, 1, &rtv, dsv);
|
|
if (fb != nullptr) {
|
|
EXPECT_TRUE(fb->IsValid());
|
|
fb->Shutdown();
|
|
delete fb;
|
|
}
|
|
}
|
|
if (dsv != nullptr) {
|
|
dsv->Shutdown();
|
|
delete dsv;
|
|
}
|
|
if (rtv != nullptr) {
|
|
rtv->Shutdown();
|
|
delete rtv;
|
|
}
|
|
}
|
|
|
|
if (depthTexture != nullptr) {
|
|
depthTexture->Shutdown();
|
|
delete depthTexture;
|
|
}
|
|
if (colorTexture != nullptr) {
|
|
colorTexture->Shutdown();
|
|
delete colorTexture;
|
|
}
|
|
renderPass->Shutdown();
|
|
delete renderPass;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, Framebuffer_MultipleColorAttachments) {
|
|
AttachmentDesc colorAttachments[2] = {};
|
|
colorAttachments[0].format = Format::R8G8B8A8_UNorm;
|
|
colorAttachments[1].format = Format::R8G8B8A8_UNorm;
|
|
|
|
RHIRenderPass* renderPass = GetDevice()->CreateRenderPass(2, colorAttachments, nullptr);
|
|
ASSERT_NE(renderPass, nullptr);
|
|
|
|
TextureDesc texDesc = {};
|
|
texDesc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
|
texDesc.width = 256;
|
|
texDesc.height = 256;
|
|
texDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
|
|
RHITexture* texture0 = GetDevice()->CreateTexture(texDesc);
|
|
RHITexture* texture1 = GetDevice()->CreateTexture(texDesc);
|
|
|
|
if (texture0 != nullptr && texture1 != nullptr) {
|
|
ResourceViewDesc rtvDesc = {};
|
|
rtvDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
RHIResourceView* rtv0 = GetDevice()->CreateRenderTargetView(texture0, rtvDesc);
|
|
RHIResourceView* rtv1 = GetDevice()->CreateRenderTargetView(texture1, rtvDesc);
|
|
|
|
if (rtv0 != nullptr && rtv1 != nullptr) {
|
|
RHIResourceView* views[2] = { rtv0, rtv1 };
|
|
RHIFramebuffer* fb = GetDevice()->CreateFramebuffer(
|
|
renderPass, 256, 256, 2, views, nullptr);
|
|
if (fb != nullptr) {
|
|
EXPECT_EQ(fb->GetWidth(), 256u);
|
|
EXPECT_EQ(fb->GetHeight(), 256u);
|
|
fb->Shutdown();
|
|
delete fb;
|
|
}
|
|
}
|
|
if (rtv1 != nullptr) {
|
|
rtv1->Shutdown();
|
|
delete rtv1;
|
|
}
|
|
if (rtv0 != nullptr) {
|
|
rtv0->Shutdown();
|
|
delete rtv0;
|
|
}
|
|
}
|
|
|
|
if (texture1 != nullptr) {
|
|
texture1->Shutdown();
|
|
delete texture1;
|
|
}
|
|
if (texture0 != nullptr) {
|
|
texture0->Shutdown();
|
|
delete texture0;
|
|
}
|
|
renderPass->Shutdown();
|
|
delete renderPass;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, Framebuffer_InvalidDimensions) {
|
|
AttachmentDesc colorAttachment = {};
|
|
colorAttachment.format = static_cast<Format>(Format::R8G8B8A8_UNorm);
|
|
|
|
RHIRenderPass* renderPass = GetDevice()->CreateRenderPass(1, &colorAttachment, nullptr);
|
|
ASSERT_NE(renderPass, nullptr);
|
|
|
|
TextureDesc texDesc = {};
|
|
texDesc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
|
texDesc.width = 256;
|
|
texDesc.height = 256;
|
|
texDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
|
|
RHITexture* texture = GetDevice()->CreateTexture(texDesc);
|
|
if (texture != nullptr) {
|
|
ResourceViewDesc rtvDesc = {};
|
|
rtvDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
RHIResourceView* rtv = GetDevice()->CreateRenderTargetView(texture, rtvDesc);
|
|
if (rtv != nullptr) {
|
|
RHIFramebuffer* fb = GetDevice()->CreateFramebuffer(
|
|
renderPass, 0, 0, 1, &rtv, nullptr);
|
|
if (fb != nullptr) {
|
|
EXPECT_EQ(fb->GetWidth(), 0u);
|
|
EXPECT_EQ(fb->GetHeight(), 0u);
|
|
fb->Shutdown();
|
|
delete fb;
|
|
}
|
|
rtv->Shutdown();
|
|
delete rtv;
|
|
}
|
|
texture->Shutdown();
|
|
delete texture;
|
|
}
|
|
renderPass->Shutdown();
|
|
delete renderPass;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, Framebuffer_NullColorAttachments) {
|
|
AttachmentDesc colorAttachment = {};
|
|
colorAttachment.format = static_cast<Format>(Format::R8G8B8A8_UNorm);
|
|
|
|
RHIRenderPass* renderPass = GetDevice()->CreateRenderPass(1, &colorAttachment, nullptr);
|
|
ASSERT_NE(renderPass, nullptr);
|
|
|
|
RHIResourceView* nullView = nullptr;
|
|
RHIFramebuffer* fb = GetDevice()->CreateFramebuffer(
|
|
renderPass, 256, 256, 1, &nullView, nullptr);
|
|
if (fb != nullptr) {
|
|
EXPECT_EQ(fb->GetWidth(), 256u);
|
|
fb->Shutdown();
|
|
delete fb;
|
|
}
|
|
renderPass->Shutdown();
|
|
delete renderPass;
|
|
}
|