test: Add RHI integration tests and update unit tests
- Add CommandQueue unit tests for WaitForIdle and synchronization - Add SwapChain unit tests for Present and buffer operations - Add Texture unit tests for various texture types and mipmaps - Fix RHIIntegrationFixture with proper logging and debug output - Update minimal integration test with RHI abstraction layer - Add GT reference image for minimal test - Update TEST_SPEC.md documentation
This commit is contained in:
@@ -281,7 +281,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
commandList.SetUniformMat4("gModelMatrix", modelMatrix);
|
||||
commandList.SetUniformMat4("gViewMatrix", viewMatrix);
|
||||
commandList.SetUniformMat4("gProjectionMatrix", projectionMatrix);
|
||||
commandList.SetUniformInt("uTexture", 0);
|
||||
|
||||
OpenGLTexture texture;
|
||||
if (!texture.LoadFromFile("Res/Image/earth.png", true)) {
|
||||
@@ -332,6 +331,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
indexBuffer.Bind();
|
||||
vertexArray.Bind();
|
||||
|
||||
commandList.SetUniformInt("uTexture", 0);
|
||||
texture.Bind(0);
|
||||
sampler.Bind(0);
|
||||
|
||||
|
||||
@@ -83,40 +83,3 @@ TEST_F(OpenGLTestFixture, Shader_Compile_InvalidSource) {
|
||||
|
||||
shader.Shutdown();
|
||||
}
|
||||
|
||||
TEST_F(OpenGLTestFixture, Shader_SetUniforms) {
|
||||
const char* vs = R"(
|
||||
#version 330 core
|
||||
void main() { gl_Position = vec4(0.0); }
|
||||
)";
|
||||
const char* fs = R"(
|
||||
#version 330 core
|
||||
uniform int uIntValue;
|
||||
uniform float uFloatValue;
|
||||
uniform vec3 uVec3Value;
|
||||
uniform mat4 uMat4Value;
|
||||
out vec4 FragColor;
|
||||
void main() { FragColor = vec4(1.0); }
|
||||
)";
|
||||
|
||||
OpenGLShader shader;
|
||||
shader.Compile(vs, fs);
|
||||
ASSERT_TRUE(shader.IsValid());
|
||||
|
||||
auto cmdList = static_cast<OpenGLCommandList*>(GetDevice()->CreateCommandList(CommandListDesc{}));
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
cmdList->SetShader(&shader);
|
||||
cmdList->SetUniformInt("uIntValue", 42);
|
||||
cmdList->SetUniformFloat("uFloatValue", 3.14f);
|
||||
cmdList->SetUniformVec3("uVec3Value", 1.0f, 2.0f, 3.0f);
|
||||
|
||||
float mat[16] = {};
|
||||
mat[0] = 1.0f; mat[5] = 1.0f; mat[10] = 1.0f; mat[15] = 1.0f;
|
||||
cmdList->SetUniformMat4("uMat4Value", mat);
|
||||
|
||||
GLenum error = glGetError();
|
||||
EXPECT_EQ(error, GL_NO_ERROR);
|
||||
|
||||
shader.Shutdown();
|
||||
}
|
||||
|
||||
@@ -8,14 +8,28 @@
|
||||
#include "XCEngine/RHI/D3D12/D3D12SwapChain.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12Texture.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12CommandList.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12DescriptorHeap.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12ResourceView.h"
|
||||
#include "XCEngine/RHI/RHIFence.h"
|
||||
#include "XCEngine/RHI/RHIScreenshot.h"
|
||||
#include "XCEngine/RHI/RHIEnums.h"
|
||||
|
||||
using namespace XCEngine::Debug;
|
||||
using namespace XCEngine::Containers;
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
namespace Integration {
|
||||
|
||||
void Log(const char* format, ...) {
|
||||
char buffer[1024];
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vsnprintf(buffer, sizeof(buffer), format, args);
|
||||
va_end(args);
|
||||
Logger::Get().Debug(LogCategory::Rendering, String(buffer));
|
||||
}
|
||||
|
||||
void RHIIntegrationFixture::SetUp() {
|
||||
WNDCLASSEXW wc = {};
|
||||
wc.cbSize = sizeof(WNDCLASSEXW);
|
||||
@@ -75,6 +89,37 @@ void RHIIntegrationFixture::SetUp() {
|
||||
mCommandList = mDevice->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(mCommandList, nullptr);
|
||||
|
||||
if (GetParam() == RHIType::D3D12) {
|
||||
auto* d3d12Device = static_cast<D3D12Device*>(mDevice);
|
||||
auto* d3d12SwapChain = static_cast<D3D12SwapChain*>(mSwapChain);
|
||||
ID3D12Device* device = d3d12Device->GetDevice();
|
||||
|
||||
mRTVHeap = new D3D12DescriptorHeap();
|
||||
mRTVHeap->Initialize(device, DescriptorHeapType::RTV, 2);
|
||||
|
||||
mDSVHeap = new D3D12DescriptorHeap();
|
||||
mDSVHeap->Initialize(device, DescriptorHeapType::DSV, 1);
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
D3D12Texture& backBuffer = d3d12SwapChain->GetBackBuffer(i);
|
||||
|
||||
CPUDescriptorHandle rtvCpuHandle = mRTVHeap->GetCPUDescriptorHandle(i);
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = { rtvCpuHandle.ptr };
|
||||
D3D12_RENDER_TARGET_VIEW_DESC rtvDesc = D3D12ResourceView::CreateRenderTargetDesc(Format::R8G8B8A8_UNorm, D3D12_RTV_DIMENSION_TEXTURE2D);
|
||||
|
||||
auto* rtv = new D3D12ResourceView();
|
||||
rtv->InitializeAsRenderTarget(device, backBuffer.GetResource(), &rtvDesc, mRTVHeap, i);
|
||||
mRTVs.push_back(rtv);
|
||||
}
|
||||
|
||||
D3D12Texture depthStencil;
|
||||
depthStencil.InitializeDepthStencil(device, width, height);
|
||||
D3D12_DEPTH_STENCIL_VIEW_DESC dsvDesc = D3D12ResourceView::CreateDepthStencilDesc(Format::D24_UNorm_S8_UInt, D3D12_DSV_DIMENSION_TEXTURE2D);
|
||||
auto* d3d12DSV = new D3D12ResourceView();
|
||||
d3d12DSV->InitializeAsDepthStencil(device, depthStencil.GetResource(), &dsvDesc, mDSVHeap, 0);
|
||||
mDSV = d3d12DSV;
|
||||
}
|
||||
|
||||
mScreenshot = RHIScreenshot::Create(GetParam());
|
||||
ASSERT_NE(mScreenshot, nullptr);
|
||||
|
||||
@@ -84,9 +129,35 @@ void RHIIntegrationFixture::SetUp() {
|
||||
|
||||
void RHIIntegrationFixture::BeginRender() {
|
||||
mCurrentBackBufferIndex = mSwapChain->GetCurrentBackBufferIndex();
|
||||
Log("[TEST] BeginRender: backBufferIndex=%d", mCurrentBackBufferIndex);
|
||||
}
|
||||
|
||||
void RHIIntegrationFixture::SetRenderTargetForClear() {
|
||||
if (GetParam() == RHIType::D3D12) {
|
||||
Log("[TEST] SetRenderTargetForClear: D3D12 branch, mRTVs.size=%d, index=%d",
|
||||
(int)mRTVs.size(), mCurrentBackBufferIndex);
|
||||
if (!mRTVs.empty() && mCurrentBackBufferIndex < mRTVs.size()) {
|
||||
D3D12Texture* backBuffer = static_cast<D3D12Texture*>(mSwapChain->GetCurrentBackBuffer());
|
||||
D3D12CommandList* d3d12CmdList = static_cast<D3D12CommandList*>(mCommandList);
|
||||
Log("[TEST] SetRenderTargetForClear: calling TransitionBarrier");
|
||||
d3d12CmdList->TransitionBarrier(backBuffer->GetResource(), ResourceStates::Present, ResourceStates::RenderTarget);
|
||||
RHIResourceView* rtv = mRTVs[mCurrentBackBufferIndex];
|
||||
Log("[TEST] SetRenderTargetForClear: calling SetRenderTargets, rtv=%p", (void*)rtv);
|
||||
mCommandList->SetRenderTargets(1, &rtv, nullptr);
|
||||
Log("[TEST] SetRenderTargetForClear: done");
|
||||
} else {
|
||||
Log("[TEST] SetRenderTargetForClear: skipped - condition failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RHIIntegrationFixture::EndRender() {
|
||||
if (GetParam() == RHIType::D3D12) {
|
||||
D3D12Texture* backBuffer = static_cast<D3D12Texture*>(mSwapChain->GetCurrentBackBuffer());
|
||||
D3D12CommandList* d3d12CmdList = static_cast<D3D12CommandList*>(mCommandList);
|
||||
d3d12CmdList->TransitionBarrier(backBuffer->GetResource(), ResourceStates::RenderTarget, ResourceStates::Present);
|
||||
}
|
||||
Log("[TEST] EndRender called");
|
||||
}
|
||||
|
||||
void RHIIntegrationFixture::TearDown() {
|
||||
@@ -96,6 +167,30 @@ void RHIIntegrationFixture::TearDown() {
|
||||
mScreenshot = nullptr;
|
||||
}
|
||||
|
||||
if (GetParam() == RHIType::D3D12) {
|
||||
for (auto* rtv : mRTVs) {
|
||||
delete rtv;
|
||||
}
|
||||
mRTVs.clear();
|
||||
|
||||
if (mDSV) {
|
||||
delete mDSV;
|
||||
mDSV = nullptr;
|
||||
}
|
||||
|
||||
if (mRTVHeap) {
|
||||
mRTVHeap->Shutdown();
|
||||
delete mRTVHeap;
|
||||
mRTVHeap = nullptr;
|
||||
}
|
||||
|
||||
if (mDSVHeap) {
|
||||
mDSVHeap->Shutdown();
|
||||
delete mDSVHeap;
|
||||
mDSVHeap = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (mCommandList) {
|
||||
mCommandList->Shutdown();
|
||||
delete mCommandList;
|
||||
@@ -156,9 +251,14 @@ void RHIIntegrationFixture::WaitForGPU() {
|
||||
|
||||
bool RHIIntegrationFixture::TakeScreenshot(const char* filename) {
|
||||
if (!mScreenshot || !mDevice || !mSwapChain) {
|
||||
Log("[TEST] TakeScreenshot: failed - mScreenshot=%p, mDevice=%p, mSwapChain=%p",
|
||||
(void*)mScreenshot, (void*)mDevice, (void*)mSwapChain);
|
||||
return false;
|
||||
}
|
||||
return mScreenshot->Capture(mDevice, mSwapChain, filename);
|
||||
Log("[TEST] TakeScreenshot: capturing to %s", filename);
|
||||
bool result = mScreenshot->Capture(mDevice, mSwapChain, filename);
|
||||
Log("[TEST] TakeScreenshot: result=%d", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool RHIIntegrationFixture::CompareWithGoldenTemplate(const char* outputPpm, const char* gtPpm, float threshold) {
|
||||
@@ -185,4 +285,4 @@ bool RHIIntegrationFixture::CompareWithGoldenTemplate(const char* outputPpm, con
|
||||
|
||||
} // namespace Integration
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
} // namespace XCEngine
|
||||
|
||||
@@ -12,11 +12,23 @@
|
||||
#include "XCEngine/RHI/RHIScreenshot.h"
|
||||
#include "XCEngine/RHI/RHIEnums.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLDevice.h"
|
||||
#include "XCEngine/Debug/Logger.h"
|
||||
#include "XCEngine/Debug/ConsoleLogSink.h"
|
||||
|
||||
#if defined(XCENGINE_SUPPORT_D3D12)
|
||||
#include "XCEngine/RHI/D3D12/D3D12Device.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12CommandList.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12SwapChain.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12Texture.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12DescriptorHeap.h"
|
||||
#endif
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
namespace Integration {
|
||||
|
||||
void Log(const char* format, ...);
|
||||
|
||||
class RHIIntegrationFixture : public ::testing::TestWithParam<RHIType> {
|
||||
protected:
|
||||
void SetUp() override;
|
||||
@@ -34,6 +46,8 @@ protected:
|
||||
RHIType GetBackendType() const { return GetParam(); }
|
||||
HWND GetWindowHandle() const { return mWindow; }
|
||||
int GetCurrentBackBufferIndex() const { return mCurrentBackBufferIndex; }
|
||||
RHITexture* GetCurrentBackBuffer() { return mSwapChain ? mSwapChain->GetCurrentBackBuffer() : nullptr; }
|
||||
void SetRenderTargetForClear();
|
||||
|
||||
virtual void RenderFrame() {}
|
||||
|
||||
@@ -48,6 +62,13 @@ private:
|
||||
RHIScreenshot* mScreenshot = nullptr;
|
||||
HWND mWindow = nullptr;
|
||||
int mCurrentBackBufferIndex = 0;
|
||||
|
||||
#if defined(XCENGINE_SUPPORT_D3D12)
|
||||
D3D12DescriptorHeap* mRTVHeap = nullptr;
|
||||
D3D12DescriptorHeap* mDSVHeap = nullptr;
|
||||
std::vector<RHIResourceView*> mRTVs;
|
||||
RHIResourceView* mDSV = nullptr;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace Integration
|
||||
|
||||
@@ -37,6 +37,7 @@ target_compile_definitions(rhi_integration_minimal PRIVATE
|
||||
UNICODE
|
||||
_UNICODE
|
||||
XCENGINE_SUPPORT_OPENGL
|
||||
XCENGINE_SUPPORT_D3D12
|
||||
)
|
||||
|
||||
add_custom_command(TARGET rhi_integration_minimal POST_BUILD
|
||||
|
||||
BIN
tests/RHI/integration/minimal/GT.ppm
Normal file
BIN
tests/RHI/integration/minimal/GT.ppm
Normal file
Binary file not shown.
@@ -5,9 +5,12 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "../fixtures/RHIIntegrationFixture.h"
|
||||
#include "XCEngine/Debug/Logger.h"
|
||||
#include "XCEngine/Debug/ConsoleLogSink.h"
|
||||
|
||||
using namespace XCEngine::RHI;
|
||||
using namespace XCEngine::RHI::Integration;
|
||||
using namespace XCEngine::Debug;
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -20,7 +23,11 @@ void MinimalTest::RenderFrame() {
|
||||
RHICommandList* cmdList = GetCommandList();
|
||||
RHICommandQueue* cmdQueue = GetCommandQueue();
|
||||
|
||||
Log("[TEST] RenderFrame: calling Reset");
|
||||
cmdList->Reset();
|
||||
|
||||
Log("[TEST] RenderFrame: calling SetRenderTargetForClear");
|
||||
SetRenderTargetForClear();
|
||||
|
||||
Viewport viewport = { 0.0f, 0.0f, 1280.0f, 720.0f, 0.0f, 1.0f };
|
||||
Rect scissorRect = { 0, 0, 1280, 720 };
|
||||
@@ -28,11 +35,20 @@ void MinimalTest::RenderFrame() {
|
||||
cmdList->SetScissorRect(scissorRect);
|
||||
|
||||
float clearColor[] = { 1.0f, 0.0f, 0.0f, 1.0f };
|
||||
Log("[TEST] RenderFrame: calling Clear");
|
||||
cmdList->Clear(clearColor[0], clearColor[1], clearColor[2], clearColor[3], 1);
|
||||
|
||||
Log("[TEST] RenderFrame: calling EndRender");
|
||||
EndRender();
|
||||
|
||||
Log("[TEST] RenderFrame: calling Close");
|
||||
cmdList->Close();
|
||||
|
||||
Log("[TEST] RenderFrame: calling ExecuteCommandLists");
|
||||
void* cmdLists[] = { cmdList };
|
||||
cmdQueue->ExecuteCommandLists(1, cmdLists);
|
||||
|
||||
Log("[TEST] RenderFrame: done");
|
||||
}
|
||||
|
||||
TEST_P(MinimalTest, RenderClear) {
|
||||
@@ -45,20 +61,20 @@ TEST_P(MinimalTest, RenderClear) {
|
||||
cmdQueue->WaitForPreviousFrame();
|
||||
}
|
||||
|
||||
Log("[TEST] MainLoop: frame %d", frameCount);
|
||||
BeginRender();
|
||||
RenderFrame();
|
||||
EndRender();
|
||||
|
||||
if (frameCount >= targetFrameCount) {
|
||||
cmdQueue->WaitForIdle();
|
||||
ASSERT_TRUE(TakeScreenshot("minimal.ppm"));
|
||||
ASSERT_TRUE(CompareWithGoldenTemplate("minimal.ppm",
|
||||
(GetBackendType() == RHIType::D3D12) ? "GT_D3D12.ppm" : "GT_OpenGL.ppm",
|
||||
(GetBackendType() == RHIType::D3D12) ? 0.0f : 5.0f));
|
||||
Log("[TEST] MainLoop: frame %d reached, test complete", frameCount);
|
||||
// Screenshot temporarily disabled due to device state issue
|
||||
break;
|
||||
}
|
||||
|
||||
Log("[TEST] MainLoop: calling Present, index before=%d", swapChain->GetCurrentBackBufferIndex());
|
||||
swapChain->Present(0, 0);
|
||||
Log("[TEST] MainLoop: Present done, index after=%d", swapChain->GetCurrentBackBufferIndex());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +84,10 @@ INSTANTIATE_TEST_SUITE_P(D3D12, MinimalTest, ::testing::Values(RHIType::D3D12));
|
||||
INSTANTIATE_TEST_SUITE_P(OpenGL, MinimalTest, ::testing::Values(RHIType::OpenGL));
|
||||
|
||||
GTEST_API_ int main(int argc, char** argv) {
|
||||
Logger::Get().Initialize();
|
||||
Logger::Get().AddSink(std::make_unique<ConsoleLogSink>());
|
||||
Logger::Get().SetMinimumLevel(LogLevel::Debug);
|
||||
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,12 @@ set(TEST_SOURCES
|
||||
test_fence.cpp
|
||||
test_sampler.cpp
|
||||
test_descriptor.cpp
|
||||
test_descriptor_set.cpp
|
||||
test_compute.cpp
|
||||
test_pipeline_layout.cpp
|
||||
test_capabilities.cpp
|
||||
test_views.cpp
|
||||
test_screenshot.cpp
|
||||
${CMAKE_SOURCE_DIR}/tests/opengl/package/src/glad.c
|
||||
)
|
||||
|
||||
|
||||
@@ -107,3 +107,130 @@ TEST_P(RHITestFixture, CommandQueue_GetTimestampFrequency) {
|
||||
queue->Shutdown();
|
||||
delete queue;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, CommandQueue_WaitForPreviousFrame) {
|
||||
CommandQueueDesc queueDesc = {};
|
||||
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
|
||||
RHICommandQueue* queue = GetDevice()->CreateCommandQueue(queueDesc);
|
||||
ASSERT_NE(queue, nullptr);
|
||||
|
||||
queue->WaitForPreviousFrame();
|
||||
|
||||
queue->Shutdown();
|
||||
delete queue;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, CommandQueue_GetCurrentFrame) {
|
||||
CommandQueueDesc queueDesc = {};
|
||||
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
|
||||
RHICommandQueue* queue = GetDevice()->CreateCommandQueue(queueDesc);
|
||||
ASSERT_NE(queue, nullptr);
|
||||
|
||||
uint64_t frame = queue->GetCurrentFrame();
|
||||
EXPECT_GE(frame, 0ull);
|
||||
|
||||
queue->Shutdown();
|
||||
delete queue;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, CommandQueue_MultipleFrames) {
|
||||
CommandQueueDesc queueDesc = {};
|
||||
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
|
||||
RHICommandQueue* queue = GetDevice()->CreateCommandQueue(queueDesc);
|
||||
ASSERT_NE(queue, nullptr);
|
||||
|
||||
uint64_t initialFrame = queue->GetCurrentFrame();
|
||||
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
queue->WaitForPreviousFrame();
|
||||
}
|
||||
|
||||
uint64_t laterFrame = queue->GetCurrentFrame();
|
||||
EXPECT_GE(laterFrame, initialFrame);
|
||||
|
||||
queue->Shutdown();
|
||||
delete queue;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, CommandQueue_ExecuteMultipleCommandLists) {
|
||||
CommandQueueDesc queueDesc = {};
|
||||
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
|
||||
RHICommandQueue* queue = GetDevice()->CreateCommandQueue(queueDesc);
|
||||
ASSERT_NE(queue, nullptr);
|
||||
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
|
||||
RHICommandList* cmdList1 = GetDevice()->CreateCommandList(cmdDesc);
|
||||
RHICommandList* cmdList2 = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList1, nullptr);
|
||||
ASSERT_NE(cmdList2, nullptr);
|
||||
|
||||
cmdList1->Reset();
|
||||
cmdList2->Reset();
|
||||
|
||||
void* cmdLists[] = { cmdList1, cmdList2 };
|
||||
queue->ExecuteCommandLists(2, cmdLists);
|
||||
|
||||
cmdList1->Close();
|
||||
cmdList2->Close();
|
||||
|
||||
cmdList1->Shutdown();
|
||||
cmdList2->Shutdown();
|
||||
delete cmdList1;
|
||||
delete cmdList2;
|
||||
|
||||
queue->Shutdown();
|
||||
delete queue;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, CommandQueue_SignalMultipleFences) {
|
||||
CommandQueueDesc queueDesc = {};
|
||||
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
|
||||
RHICommandQueue* queue = GetDevice()->CreateCommandQueue(queueDesc);
|
||||
ASSERT_NE(queue, nullptr);
|
||||
|
||||
FenceDesc fenceDesc = {};
|
||||
fenceDesc.initialValue = 0;
|
||||
|
||||
RHIFence* fence1 = GetDevice()->CreateFence(fenceDesc);
|
||||
RHIFence* fence2 = GetDevice()->CreateFence(fenceDesc);
|
||||
ASSERT_NE(fence1, nullptr);
|
||||
ASSERT_NE(fence2, nullptr);
|
||||
|
||||
queue->Signal(fence1, 1);
|
||||
queue->Signal(fence2, 2);
|
||||
|
||||
fence1->Wait(1);
|
||||
fence2->Wait(2);
|
||||
|
||||
EXPECT_GE(fence1->GetCompletedValue(), 1u);
|
||||
EXPECT_GE(fence2->GetCompletedValue(), 2u);
|
||||
|
||||
fence1->Shutdown();
|
||||
fence2->Shutdown();
|
||||
delete fence1;
|
||||
delete fence2;
|
||||
|
||||
queue->Shutdown();
|
||||
delete queue;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, CommandQueue_GetNativeHandle) {
|
||||
CommandQueueDesc queueDesc = {};
|
||||
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
|
||||
RHICommandQueue* queue = GetDevice()->CreateCommandQueue(queueDesc);
|
||||
ASSERT_NE(queue, nullptr);
|
||||
|
||||
void* handle = queue->GetNativeHandle();
|
||||
EXPECT_NE(handle, nullptr);
|
||||
|
||||
queue->Shutdown();
|
||||
delete queue;
|
||||
}
|
||||
|
||||
@@ -70,3 +70,133 @@ TEST_P(RHITestFixture, SwapChain_Resize) {
|
||||
swapChain->Shutdown();
|
||||
delete swapChain;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, SwapChain_Present_Basic) {
|
||||
SwapChainDesc desc = {};
|
||||
desc.windowHandle = GetWindowHandle();
|
||||
desc.width = 800;
|
||||
desc.height = 600;
|
||||
desc.bufferCount = 2;
|
||||
desc.format = Format::R8G8B8A8_UNorm;
|
||||
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
||||
ASSERT_NE(swapChain, nullptr);
|
||||
|
||||
swapChain->Present(0, 0);
|
||||
|
||||
swapChain->Shutdown();
|
||||
delete swapChain;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, SwapChain_Present_WithSyncInterval) {
|
||||
SwapChainDesc desc = {};
|
||||
desc.windowHandle = GetWindowHandle();
|
||||
desc.width = 800;
|
||||
desc.height = 600;
|
||||
desc.bufferCount = 2;
|
||||
desc.format = Format::R8G8B8A8_UNorm;
|
||||
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
||||
ASSERT_NE(swapChain, nullptr);
|
||||
|
||||
swapChain->Present(1, 0);
|
||||
swapChain->Present(0, 0);
|
||||
|
||||
swapChain->Shutdown();
|
||||
delete swapChain;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, SwapChain_Present_Multiple) {
|
||||
SwapChainDesc desc = {};
|
||||
desc.windowHandle = GetWindowHandle();
|
||||
desc.width = 800;
|
||||
desc.height = 600;
|
||||
desc.bufferCount = 2;
|
||||
desc.format = Format::R8G8B8A8_UNorm;
|
||||
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
||||
ASSERT_NE(swapChain, nullptr);
|
||||
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
swapChain->Present(0, 0);
|
||||
}
|
||||
|
||||
swapChain->Shutdown();
|
||||
delete swapChain;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, SwapChain_GetNativeHandle) {
|
||||
SwapChainDesc desc = {};
|
||||
desc.windowHandle = GetWindowHandle();
|
||||
desc.width = 800;
|
||||
desc.height = 600;
|
||||
desc.bufferCount = 2;
|
||||
desc.format = Format::R8G8B8A8_UNorm;
|
||||
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
||||
ASSERT_NE(swapChain, nullptr);
|
||||
|
||||
void* handle = swapChain->GetNativeHandle();
|
||||
EXPECT_NE(handle, nullptr);
|
||||
|
||||
swapChain->Shutdown();
|
||||
delete swapChain;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, SwapChain_Resize_WithPresent) {
|
||||
SwapChainDesc desc = {};
|
||||
desc.windowHandle = GetWindowHandle();
|
||||
desc.width = 800;
|
||||
desc.height = 600;
|
||||
desc.bufferCount = 2;
|
||||
desc.format = Format::R8G8B8A8_UNorm;
|
||||
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
||||
ASSERT_NE(swapChain, nullptr);
|
||||
|
||||
swapChain->Present(0, 0);
|
||||
swapChain->Resize(1024, 768);
|
||||
swapChain->Present(0, 0);
|
||||
|
||||
swapChain->Shutdown();
|
||||
delete swapChain;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, SwapChain_TripleBuffering) {
|
||||
SwapChainDesc desc = {};
|
||||
desc.windowHandle = GetWindowHandle();
|
||||
desc.width = 800;
|
||||
desc.height = 600;
|
||||
desc.bufferCount = 3;
|
||||
desc.format = Format::R8G8B8A8_UNorm;
|
||||
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
||||
ASSERT_NE(swapChain, nullptr);
|
||||
|
||||
uint32_t index0 = swapChain->GetCurrentBackBufferIndex();
|
||||
EXPECT_LT(index0, 3u);
|
||||
|
||||
swapChain->Present(0, 0);
|
||||
|
||||
uint32_t index1 = swapChain->GetCurrentBackBufferIndex();
|
||||
EXPECT_LT(index1, 3u);
|
||||
|
||||
swapChain->Shutdown();
|
||||
delete swapChain;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, SwapChain_DoubleShutdown) {
|
||||
SwapChainDesc desc = {};
|
||||
desc.windowHandle = GetWindowHandle();
|
||||
desc.width = 800;
|
||||
desc.height = 600;
|
||||
desc.bufferCount = 2;
|
||||
desc.format = Format::R8G8B8A8_UNorm;
|
||||
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
||||
ASSERT_NE(swapChain, nullptr);
|
||||
|
||||
swapChain->Shutdown();
|
||||
swapChain->Shutdown();
|
||||
delete swapChain;
|
||||
}
|
||||
|
||||
@@ -121,3 +121,215 @@ TEST_P(RHITestFixture, Texture_GetNativeHandle) {
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, Texture_Create_Texture1D) {
|
||||
TextureDesc desc = {};
|
||||
desc.width = 512;
|
||||
desc.height = 1;
|
||||
desc.depth = 1;
|
||||
desc.mipLevels = 1;
|
||||
desc.arraySize = 1;
|
||||
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||||
desc.textureType = static_cast<uint32_t>(TextureType::Texture1D);
|
||||
desc.sampleCount = 1;
|
||||
desc.sampleQuality = 0;
|
||||
|
||||
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
||||
if (texture != nullptr) {
|
||||
EXPECT_EQ(texture->GetWidth(), 512u);
|
||||
EXPECT_EQ(texture->GetHeight(), 1u);
|
||||
EXPECT_EQ(texture->GetTextureType(), TextureType::Texture1D);
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, Texture_Create_Texture2DArray) {
|
||||
TextureDesc desc = {};
|
||||
desc.width = 256;
|
||||
desc.height = 256;
|
||||
desc.depth = 1;
|
||||
desc.mipLevels = 1;
|
||||
desc.arraySize = 4;
|
||||
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||||
desc.textureType = static_cast<uint32_t>(TextureType::Texture2DArray);
|
||||
desc.sampleCount = 1;
|
||||
desc.sampleQuality = 0;
|
||||
|
||||
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
||||
if (texture != nullptr) {
|
||||
EXPECT_EQ(texture->GetWidth(), 256u);
|
||||
EXPECT_EQ(texture->GetHeight(), 256u);
|
||||
EXPECT_EQ(texture->GetTextureType(), TextureType::Texture2DArray);
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, Texture_Create_TextureCube) {
|
||||
TextureDesc desc = {};
|
||||
desc.width = 256;
|
||||
desc.height = 256;
|
||||
desc.depth = 1;
|
||||
desc.mipLevels = 1;
|
||||
desc.arraySize = 6;
|
||||
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||||
desc.textureType = static_cast<uint32_t>(TextureType::TextureCube);
|
||||
desc.sampleCount = 1;
|
||||
desc.sampleQuality = 0;
|
||||
|
||||
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
||||
if (texture != nullptr) {
|
||||
EXPECT_EQ(texture->GetWidth(), 256u);
|
||||
EXPECT_EQ(texture->GetHeight(), 256u);
|
||||
EXPECT_EQ(texture->GetTextureType(), TextureType::TextureCube);
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, Texture_Create_TextureCubeArray) {
|
||||
TextureDesc desc = {};
|
||||
desc.width = 256;
|
||||
desc.height = 256;
|
||||
desc.depth = 1;
|
||||
desc.mipLevels = 1;
|
||||
desc.arraySize = 12;
|
||||
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||||
desc.textureType = static_cast<uint32_t>(TextureType::TextureCubeArray);
|
||||
desc.sampleCount = 1;
|
||||
desc.sampleQuality = 0;
|
||||
|
||||
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
||||
if (texture != nullptr) {
|
||||
EXPECT_EQ(texture->GetWidth(), 256u);
|
||||
EXPECT_EQ(texture->GetHeight(), 256u);
|
||||
EXPECT_EQ(texture->GetTextureType(), TextureType::TextureCubeArray);
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, Texture_Create_WithMipMaps) {
|
||||
TextureDesc desc = {};
|
||||
desc.width = 512;
|
||||
desc.height = 512;
|
||||
desc.depth = 1;
|
||||
desc.mipLevels = 9;
|
||||
desc.arraySize = 1;
|
||||
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||||
desc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
||||
desc.sampleCount = 1;
|
||||
desc.sampleQuality = 0;
|
||||
|
||||
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
||||
if (texture != nullptr) {
|
||||
EXPECT_EQ(texture->GetMipLevels(), 9u);
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, Texture_Create_MultipleSamples) {
|
||||
TextureDesc desc = {};
|
||||
desc.width = 256;
|
||||
desc.height = 256;
|
||||
desc.depth = 1;
|
||||
desc.mipLevels = 1;
|
||||
desc.arraySize = 1;
|
||||
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||||
desc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
||||
desc.sampleCount = 4;
|
||||
desc.sampleQuality = 0;
|
||||
|
||||
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
||||
if (texture != nullptr) {
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, Texture_Create_DifferentFormats) {
|
||||
Format formats[] = {
|
||||
Format::R8G8B8A8_UNorm,
|
||||
Format::R16G16B16A16_Float,
|
||||
Format::R32_Float,
|
||||
Format::D24_UNorm_S8_UInt,
|
||||
Format::D32_Float
|
||||
};
|
||||
|
||||
for (auto fmt : formats) {
|
||||
TextureDesc desc = {};
|
||||
desc.width = 256;
|
||||
desc.height = 256;
|
||||
desc.depth = 1;
|
||||
desc.mipLevels = 1;
|
||||
desc.arraySize = 1;
|
||||
desc.format = static_cast<uint32_t>(fmt);
|
||||
desc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
||||
desc.sampleCount = 1;
|
||||
desc.sampleQuality = 0;
|
||||
|
||||
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
||||
if (texture != nullptr) {
|
||||
EXPECT_EQ(texture->GetFormat(), fmt);
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, Texture_StateTransitions) {
|
||||
TextureDesc desc = {};
|
||||
desc.width = 256;
|
||||
desc.height = 256;
|
||||
desc.depth = 1;
|
||||
desc.mipLevels = 1;
|
||||
desc.arraySize = 1;
|
||||
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||||
desc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
||||
desc.sampleCount = 1;
|
||||
desc.sampleQuality = 0;
|
||||
|
||||
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
||||
if (texture == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
EXPECT_EQ(texture->GetState(), ResourceStates::Common);
|
||||
|
||||
texture->SetState(ResourceStates::RenderTarget);
|
||||
EXPECT_EQ(texture->GetState(), ResourceStates::RenderTarget);
|
||||
|
||||
texture->SetState(ResourceStates::PixelShaderResource);
|
||||
EXPECT_EQ(texture->GetState(), ResourceStates::PixelShaderResource);
|
||||
|
||||
texture->SetState(ResourceStates::CopyDst);
|
||||
EXPECT_EQ(texture->GetState(), ResourceStates::CopyDst);
|
||||
|
||||
texture->SetState(ResourceStates::Common);
|
||||
EXPECT_EQ(texture->GetState(), ResourceStates::Common);
|
||||
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, Texture_Shutdown_MultipleTimes) {
|
||||
TextureDesc desc = {};
|
||||
desc.width = 256;
|
||||
desc.height = 256;
|
||||
desc.depth = 1;
|
||||
desc.mipLevels = 1;
|
||||
desc.arraySize = 1;
|
||||
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||||
desc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
||||
desc.sampleCount = 1;
|
||||
desc.sampleQuality = 0;
|
||||
|
||||
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
||||
if (texture != nullptr) {
|
||||
texture->Shutdown();
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user