OpenGL实现: - TransitionBarrier: 调用glMemoryBarrier(GL_ALL_BARRIER_BITS) - SetRenderTargets: 通过framebuffer绑定渲染目标 - SetVertexBuffer: 绑定GL_ARRAY_BUFFER并设置顶点属性 - SetIndexBuffer: 绑定GL_ELEMENT_ARRAY_BUFFER - ClearRenderTarget: 临时切换framebuffer清除颜色缓冲 - ClearDepthStencil: 临时切换framebuffer清除深度 stencil缓冲 - CopyResource: 使用glCopyImageSubData复制纹理数据 新增单元测试: - CommandList_TransitionBarrier_WithResourceView - CommandList_SetRenderTargets_WithResourceView - CommandList_SetVertexBuffer_WithResourceView - CommandList_SetIndexBuffer_WithResourceView - CommandList_ClearRenderTarget_WithResourceView - CommandList_ClearDepthStencil_WithResourceView - CommandList_CopyResource_WithResourceView 验证: 158个RHI单元测试全部通过, OpenGL集成测试全部通过
336 lines
9.7 KiB
C++
336 lines
9.7 KiB
C++
#include "fixtures/RHITestFixture.h"
|
|
#include "XCEngine/RHI/RHICommandList.h"
|
|
#include "XCEngine/RHI/RHITexture.h"
|
|
|
|
using namespace XCEngine::RHI;
|
|
|
|
TEST_P(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_P(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_P(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_P(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_P(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_P(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_P(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_P(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_P(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_P(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_P(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_P(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;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, CommandList_TransitionBarrier_WithResourceView) {
|
|
CommandListDesc cmdDesc = {};
|
|
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
|
|
|
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
|
ASSERT_NE(cmdList, nullptr);
|
|
|
|
cmdList->Reset();
|
|
cmdList->TransitionBarrier(static_cast<RHIResourceView*>(nullptr), ResourceStates::Common, ResourceStates::RenderTarget);
|
|
cmdList->Close();
|
|
|
|
cmdList->Shutdown();
|
|
delete cmdList;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, CommandList_SetRenderTargets_WithResourceView) {
|
|
CommandListDesc cmdDesc = {};
|
|
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
|
|
|
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
|
ASSERT_NE(cmdList, nullptr);
|
|
|
|
cmdList->Reset();
|
|
cmdList->SetRenderTargets(0, static_cast<RHIResourceView**>(nullptr), static_cast<RHIResourceView*>(nullptr));
|
|
cmdList->Close();
|
|
|
|
cmdList->Shutdown();
|
|
delete cmdList;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, CommandList_SetVertexBuffer_WithResourceView) {
|
|
CommandListDesc cmdDesc = {};
|
|
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
|
|
|
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
|
ASSERT_NE(cmdList, nullptr);
|
|
|
|
cmdList->Reset();
|
|
cmdList->SetVertexBuffer(0, static_cast<RHIResourceView*>(nullptr), 0, 16);
|
|
cmdList->Close();
|
|
|
|
cmdList->Shutdown();
|
|
delete cmdList;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, CommandList_SetIndexBuffer_WithResourceView) {
|
|
CommandListDesc cmdDesc = {};
|
|
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
|
|
|
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
|
ASSERT_NE(cmdList, nullptr);
|
|
|
|
cmdList->Reset();
|
|
cmdList->SetIndexBuffer(static_cast<RHIResourceView*>(nullptr), 0, Format::R32_UInt);
|
|
cmdList->Close();
|
|
|
|
cmdList->Shutdown();
|
|
delete cmdList;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, CommandList_ClearRenderTarget_WithResourceView) {
|
|
CommandListDesc cmdDesc = {};
|
|
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
|
|
|
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
|
ASSERT_NE(cmdList, nullptr);
|
|
|
|
float color[4] = { 1.0f, 0.0f, 0.0f, 1.0f };
|
|
|
|
cmdList->Reset();
|
|
cmdList->ClearRenderTarget(static_cast<RHIResourceView*>(nullptr), color);
|
|
cmdList->Close();
|
|
|
|
cmdList->Shutdown();
|
|
delete cmdList;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, CommandList_ClearDepthStencil_WithResourceView) {
|
|
CommandListDesc cmdDesc = {};
|
|
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
|
|
|
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
|
ASSERT_NE(cmdList, nullptr);
|
|
|
|
cmdList->Reset();
|
|
cmdList->ClearDepthStencil(static_cast<RHIResourceView*>(nullptr), 1.0f, 0);
|
|
cmdList->Close();
|
|
|
|
cmdList->Shutdown();
|
|
delete cmdList;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, CommandList_CopyResource_WithResourceView) {
|
|
CommandListDesc cmdDesc = {};
|
|
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
|
|
|
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
|
ASSERT_NE(cmdList, nullptr);
|
|
|
|
cmdList->Reset();
|
|
cmdList->CopyResource(static_cast<RHIResourceView*>(nullptr), static_cast<RHIResourceView*>(nullptr));
|
|
cmdList->Close();
|
|
|
|
cmdList->Shutdown();
|
|
delete cmdList;
|
|
}
|