feat: add RHI abstraction layer unit tests
- Add RHITestFixture with RHI_BACKEND env var support for backend selection - Add unit tests for: Device, Buffer, Texture, SwapChain, CommandList, CommandQueue, Shader, Fence, Sampler - Tests can run against D3D12 or OpenGL backends via RHI_BACKEND env var - Add integration folder placeholder for future integration tests
This commit is contained in:
228
tests/RHI/unit/test_command_list.cpp
Normal file
228
tests/RHI/unit/test_command_list.cpp
Normal file
@@ -0,0 +1,228 @@
|
||||
#include "fixtures/RHITestFixture.h"
|
||||
#include "XCEngine/RHI/RHICommandList.h"
|
||||
#include "XCEngine/RHI/RHITexture.h"
|
||||
|
||||
using namespace XCEngine::RHI;
|
||||
|
||||
TEST_F(RHITestFixture, CommandList_Reset_Close) {
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
}
|
||||
|
||||
TEST_F(RHITestFixture, CommandList_SetPrimitiveTopology) {
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->SetPrimitiveTopology(PrimitiveTopology::TriangleList);
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
}
|
||||
|
||||
TEST_F(RHITestFixture, CommandList_SetViewport) {
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
Viewport vp = { 0.0f, 0.0f, 800.0f, 600.0f, 0.0f, 1.0f };
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->SetViewport(vp);
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
}
|
||||
|
||||
TEST_F(RHITestFixture, CommandList_SetViewports) {
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
Viewport viewports[2] = {
|
||||
{ 0.0f, 0.0f, 400.0f, 300.0f, 0.0f, 1.0f },
|
||||
{ 400.0f, 300.0f, 400.0f, 300.0f, 0.0f, 1.0f }
|
||||
};
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->SetViewports(2, viewports);
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
}
|
||||
|
||||
TEST_F(RHITestFixture, CommandList_SetScissorRect) {
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
Rect rect = { 0, 0, 800, 600 };
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->SetScissorRect(rect);
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
}
|
||||
|
||||
TEST_F(RHITestFixture, CommandList_Draw) {
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->SetPrimitiveTopology(PrimitiveTopology::TriangleList);
|
||||
cmdList->Draw(3);
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
}
|
||||
|
||||
TEST_F(RHITestFixture, CommandList_DrawIndexed) {
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->SetPrimitiveTopology(PrimitiveTopology::TriangleList);
|
||||
cmdList->DrawIndexed(6);
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
}
|
||||
|
||||
TEST_F(RHITestFixture, CommandList_ClearRenderTarget) {
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
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);
|
||||
|
||||
RHITexture* texture = GetDevice()->CreateTexture(texDesc);
|
||||
ASSERT_NE(texture, nullptr);
|
||||
|
||||
float color[4] = { 1.0f, 0.0f, 0.0f, 1.0f };
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->ClearRenderTarget(texture->GetNativeHandle(), color);
|
||||
cmdList->Close();
|
||||
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
}
|
||||
|
||||
TEST_F(RHITestFixture, CommandList_SetDepthStencilState) {
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
DepthStencilState dsState = {};
|
||||
dsState.depthEnable = true;
|
||||
dsState.depthWriteMask = true;
|
||||
dsState.depthFunc = ComparisonFunc::Less;
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->SetDepthStencilState(dsState);
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
}
|
||||
|
||||
TEST_F(RHITestFixture, CommandList_SetBlendState) {
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
BlendState blendState = {};
|
||||
blendState.alphaToCoverageEnable = false;
|
||||
blendState.independentBlendEnable = false;
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->SetBlendState(blendState);
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
}
|
||||
|
||||
TEST_F(RHITestFixture, CommandList_SetStencilRef) {
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->SetStencilRef(0);
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
}
|
||||
|
||||
TEST_F(RHITestFixture, CommandList_TransitionBarrier) {
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
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);
|
||||
|
||||
RHITexture* texture = GetDevice()->CreateTexture(texDesc);
|
||||
ASSERT_NE(texture, nullptr);
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->TransitionBarrier(texture->GetNativeHandle(), ResourceStates::Common, ResourceStates::RenderTarget);
|
||||
cmdList->Close();
|
||||
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
}
|
||||
Reference in New Issue
Block a user