247 lines
7.5 KiB
C++
247 lines
7.5 KiB
C++
|
|
#include "fixtures/RHITestFixture.h"
|
||
|
|
#include "XCEngine/RHI/RHIResourceView.h"
|
||
|
|
#include "XCEngine/RHI/RHITexture.h"
|
||
|
|
|
||
|
|
using namespace XCEngine::RHI;
|
||
|
|
|
||
|
|
TEST_P(RHITestFixture, Device_CreateRenderTargetView) {
|
||
|
|
TextureDesc texDesc = {};
|
||
|
|
texDesc.width = 256;
|
||
|
|
texDesc.height = 256;
|
||
|
|
texDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||
|
|
texDesc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
||
|
|
texDesc.sampleCount = 1;
|
||
|
|
|
||
|
|
RHITexture* texture = GetDevice()->CreateTexture(texDesc);
|
||
|
|
if (texture == nullptr) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
ResourceViewDesc viewDesc = {};
|
||
|
|
viewDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||
|
|
viewDesc.dimension = ResourceViewDimension::Texture2D;
|
||
|
|
|
||
|
|
RHIResourceView* rtv = GetDevice()->CreateRenderTargetView(texture, viewDesc);
|
||
|
|
if (rtv != nullptr) {
|
||
|
|
EXPECT_TRUE(rtv->IsValid());
|
||
|
|
EXPECT_EQ(rtv->GetViewType(), ResourceViewType::RenderTarget);
|
||
|
|
EXPECT_EQ(rtv->GetFormat(), Format::R8G8B8A8_UNorm);
|
||
|
|
rtv->Shutdown();
|
||
|
|
delete rtv;
|
||
|
|
}
|
||
|
|
|
||
|
|
texture->Shutdown();
|
||
|
|
delete texture;
|
||
|
|
}
|
||
|
|
|
||
|
|
TEST_P(RHITestFixture, Device_CreateDepthStencilView) {
|
||
|
|
TextureDesc texDesc = {};
|
||
|
|
texDesc.width = 256;
|
||
|
|
texDesc.height = 256;
|
||
|
|
texDesc.format = static_cast<uint32_t>(Format::D24_UNorm_S8_UInt);
|
||
|
|
texDesc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
||
|
|
texDesc.sampleCount = 1;
|
||
|
|
|
||
|
|
RHITexture* texture = GetDevice()->CreateTexture(texDesc);
|
||
|
|
if (texture == nullptr) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
ResourceViewDesc viewDesc = {};
|
||
|
|
viewDesc.format = static_cast<uint32_t>(Format::D24_UNorm_S8_UInt);
|
||
|
|
viewDesc.dimension = ResourceViewDimension::Texture2D;
|
||
|
|
|
||
|
|
RHIResourceView* dsv = GetDevice()->CreateDepthStencilView(texture, viewDesc);
|
||
|
|
if (dsv != nullptr) {
|
||
|
|
EXPECT_TRUE(dsv->IsValid());
|
||
|
|
EXPECT_EQ(dsv->GetViewType(), ResourceViewType::DepthStencil);
|
||
|
|
dsv->Shutdown();
|
||
|
|
delete dsv;
|
||
|
|
}
|
||
|
|
|
||
|
|
texture->Shutdown();
|
||
|
|
delete texture;
|
||
|
|
}
|
||
|
|
|
||
|
|
TEST_P(RHITestFixture, Device_CreateShaderResourceView) {
|
||
|
|
TextureDesc texDesc = {};
|
||
|
|
texDesc.width = 256;
|
||
|
|
texDesc.height = 256;
|
||
|
|
texDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||
|
|
texDesc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
||
|
|
texDesc.sampleCount = 1;
|
||
|
|
|
||
|
|
RHITexture* texture = GetDevice()->CreateTexture(texDesc);
|
||
|
|
if (texture == nullptr) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
ResourceViewDesc viewDesc = {};
|
||
|
|
viewDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||
|
|
viewDesc.dimension = ResourceViewDimension::Texture2D;
|
||
|
|
|
||
|
|
RHIResourceView* srv = GetDevice()->CreateShaderResourceView(texture, viewDesc);
|
||
|
|
if (srv != nullptr) {
|
||
|
|
EXPECT_TRUE(srv->IsValid());
|
||
|
|
EXPECT_EQ(srv->GetViewType(), ResourceViewType::ShaderResource);
|
||
|
|
srv->Shutdown();
|
||
|
|
delete srv;
|
||
|
|
}
|
||
|
|
|
||
|
|
texture->Shutdown();
|
||
|
|
delete texture;
|
||
|
|
}
|
||
|
|
|
||
|
|
TEST_P(RHITestFixture, Device_CreateUnorderedAccessView) {
|
||
|
|
TextureDesc texDesc = {};
|
||
|
|
texDesc.width = 256;
|
||
|
|
texDesc.height = 256;
|
||
|
|
texDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||
|
|
texDesc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
||
|
|
texDesc.sampleCount = 1;
|
||
|
|
|
||
|
|
RHITexture* texture = GetDevice()->CreateTexture(texDesc);
|
||
|
|
if (texture == nullptr) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
ResourceViewDesc viewDesc = {};
|
||
|
|
viewDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||
|
|
viewDesc.dimension = ResourceViewDimension::Texture2D;
|
||
|
|
|
||
|
|
RHIResourceView* uav = GetDevice()->CreateUnorderedAccessView(texture, viewDesc);
|
||
|
|
if (uav != nullptr) {
|
||
|
|
EXPECT_TRUE(uav->IsValid());
|
||
|
|
EXPECT_EQ(uav->GetViewType(), ResourceViewType::UnorderedAccess);
|
||
|
|
uav->Shutdown();
|
||
|
|
delete uav;
|
||
|
|
}
|
||
|
|
|
||
|
|
texture->Shutdown();
|
||
|
|
delete texture;
|
||
|
|
}
|
||
|
|
|
||
|
|
TEST_P(RHITestFixture, Device_CreateRenderTargetView_Multiple) {
|
||
|
|
TextureDesc texDesc = {};
|
||
|
|
texDesc.width = 256;
|
||
|
|
texDesc.height = 256;
|
||
|
|
texDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||
|
|
texDesc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
||
|
|
texDesc.sampleCount = 1;
|
||
|
|
|
||
|
|
RHIResourceView* rtvs[4] = { nullptr };
|
||
|
|
|
||
|
|
for (int i = 0; i < 4; ++i) {
|
||
|
|
RHITexture* texture = GetDevice()->CreateTexture(texDesc);
|
||
|
|
if (texture == nullptr) {
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
|
||
|
|
ResourceViewDesc viewDesc = {};
|
||
|
|
viewDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||
|
|
viewDesc.dimension = ResourceViewDimension::Texture2D;
|
||
|
|
|
||
|
|
rtvs[i] = GetDevice()->CreateRenderTargetView(texture, viewDesc);
|
||
|
|
texture->Shutdown();
|
||
|
|
delete texture;
|
||
|
|
}
|
||
|
|
|
||
|
|
for (int i = 0; i < 4; ++i) {
|
||
|
|
if (rtvs[i] != nullptr) {
|
||
|
|
EXPECT_TRUE(rtvs[i]->IsValid());
|
||
|
|
rtvs[i]->Shutdown();
|
||
|
|
delete rtvs[i];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
TEST_P(RHITestFixture, Device_CreateShaderResourceView_ArrayTexture) {
|
||
|
|
TextureDesc texDesc = {};
|
||
|
|
texDesc.width = 256;
|
||
|
|
texDesc.height = 256;
|
||
|
|
texDesc.arraySize = 4;
|
||
|
|
texDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||
|
|
texDesc.textureType = static_cast<uint32_t>(TextureType::Texture2DArray);
|
||
|
|
texDesc.sampleCount = 1;
|
||
|
|
|
||
|
|
RHITexture* texture = GetDevice()->CreateTexture(texDesc);
|
||
|
|
if (texture == nullptr) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
ResourceViewDesc viewDesc = {};
|
||
|
|
viewDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||
|
|
viewDesc.dimension = ResourceViewDimension::Texture2DArray;
|
||
|
|
viewDesc.arraySize = 4;
|
||
|
|
|
||
|
|
RHIResourceView* srv = GetDevice()->CreateShaderResourceView(texture, viewDesc);
|
||
|
|
if (srv != nullptr) {
|
||
|
|
EXPECT_TRUE(srv->IsValid());
|
||
|
|
srv->Shutdown();
|
||
|
|
delete srv;
|
||
|
|
}
|
||
|
|
|
||
|
|
texture->Shutdown();
|
||
|
|
delete texture;
|
||
|
|
}
|
||
|
|
|
||
|
|
TEST_P(RHITestFixture, Device_CreateShaderResourceView_CubeTexture) {
|
||
|
|
TextureDesc texDesc = {};
|
||
|
|
texDesc.width = 256;
|
||
|
|
texDesc.height = 256;
|
||
|
|
texDesc.arraySize = 6;
|
||
|
|
texDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||
|
|
texDesc.textureType = static_cast<uint32_t>(TextureType::TextureCube);
|
||
|
|
texDesc.sampleCount = 1;
|
||
|
|
|
||
|
|
RHITexture* texture = GetDevice()->CreateTexture(texDesc);
|
||
|
|
if (texture == nullptr) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
ResourceViewDesc viewDesc = {};
|
||
|
|
viewDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||
|
|
viewDesc.dimension = ResourceViewDimension::TextureCube;
|
||
|
|
|
||
|
|
RHIResourceView* srv = GetDevice()->CreateShaderResourceView(texture, viewDesc);
|
||
|
|
if (srv != nullptr) {
|
||
|
|
EXPECT_TRUE(srv->IsValid());
|
||
|
|
srv->Shutdown();
|
||
|
|
delete srv;
|
||
|
|
}
|
||
|
|
|
||
|
|
texture->Shutdown();
|
||
|
|
delete texture;
|
||
|
|
}
|
||
|
|
|
||
|
|
TEST_P(RHITestFixture, Device_CreateDepthStencilView_MipLevels) {
|
||
|
|
TextureDesc texDesc = {};
|
||
|
|
texDesc.width = 256;
|
||
|
|
texDesc.height = 256;
|
||
|
|
texDesc.mipLevels = 5;
|
||
|
|
texDesc.format = static_cast<uint32_t>(Format::D24_UNorm_S8_UInt);
|
||
|
|
texDesc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
||
|
|
texDesc.sampleCount = 1;
|
||
|
|
|
||
|
|
RHITexture* texture = GetDevice()->CreateTexture(texDesc);
|
||
|
|
if (texture == nullptr) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
for (uint32_t mip = 0; mip < texDesc.mipLevels; ++mip) {
|
||
|
|
ResourceViewDesc viewDesc = {};
|
||
|
|
viewDesc.format = static_cast<uint32_t>(Format::D24_UNorm_S8_UInt);
|
||
|
|
viewDesc.dimension = ResourceViewDimension::Texture2D;
|
||
|
|
viewDesc.mipLevel = mip;
|
||
|
|
|
||
|
|
RHIResourceView* dsv = GetDevice()->CreateDepthStencilView(texture, viewDesc);
|
||
|
|
if (dsv != nullptr) {
|
||
|
|
EXPECT_TRUE(dsv->IsValid());
|
||
|
|
dsv->Shutdown();
|
||
|
|
delete dsv;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
texture->Shutdown();
|
||
|
|
delete texture;
|
||
|
|
}
|