refactor(editor): Complete architecture refactoring
- SceneManager: remove singleton, use dependency injection via EditorContext - SelectionManager: already interface-based via ISelectionManager - Panel: now receives IEditorContext for accessing managers - HierarchyPanel: migrated to use IEditorContext instead of singletons - Add ISceneManager interface and SceneManagerImpl - EditorContextImpl: holds all editor subsystems Architecture now follows dependency injection pattern: Application -> EditorContext -> SceneManager/SelectionManager EditorLayer -> Panels (receive context via SetContext) All Manager singletons removed: EditorSceneManager::Get(), SelectionManager::Get()
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
#include "fixtures/RHITestFixture.h"
|
||||
#include "XCEngine/RHI/RHICommandList.h"
|
||||
#include "XCEngine/RHI/RHITexture.h"
|
||||
#include "XCEngine/RHI/RHIBuffer.h"
|
||||
#include "XCEngine/RHI/RHIShader.h"
|
||||
#include "XCEngine/RHI/RHIPipelineState.h"
|
||||
#include "XCEngine/RHI/RHIRenderPass.h"
|
||||
#include "XCEngine/RHI/RHIFramebuffer.h"
|
||||
|
||||
using namespace XCEngine::RHI;
|
||||
|
||||
@@ -87,6 +92,26 @@ TEST_P(RHITestFixture, CommandList_SetScissorRect) {
|
||||
delete cmdList;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, CommandList_SetScissorRects_Multiple) {
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
Rect rects[2] = {
|
||||
{ 0, 0, 400, 300 },
|
||||
{ 400, 300, 800, 600 }
|
||||
};
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->SetScissorRects(2, rects);
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, CommandList_Draw) {
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
@@ -119,34 +144,6 @@ TEST_P(RHITestFixture, CommandList_DrawIndexed) {
|
||||
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(static_cast<RHIResourceView*>(nullptr), color);
|
||||
cmdList->Close();
|
||||
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, CommandList_SetStencilRef) {
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
@@ -162,136 +159,297 @@ TEST_P(RHITestFixture, CommandList_SetStencilRef) {
|
||||
delete cmdList;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, CommandList_TransitionBarrier) {
|
||||
TEST_P(RHITestFixture, CommandList_SetBlendFactor) {
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
float blendFactor[4] = { 0.5f, 0.5f, 0.5f, 1.0f };
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->SetBlendFactor(blendFactor);
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_P(RHITestFixture, CommandList_ClearRenderTarget_WithRealView) {
|
||||
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);
|
||||
|
||||
RHIResourceView* rtv = GetDevice()->CreateRenderTargetView(texture, {});
|
||||
ASSERT_NE(rtv, nullptr);
|
||||
|
||||
float color[4] = { 1.0f, 0.0f, 0.0f, 1.0f };
|
||||
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->ClearRenderTarget(rtv, color);
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
delete rtv;
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, CommandList_ClearDepthStencil_WithRealView) {
|
||||
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);
|
||||
RHITexture* texture = GetDevice()->CreateTexture(texDesc);
|
||||
ASSERT_NE(texture, nullptr);
|
||||
|
||||
RHIResourceView* dsv = GetDevice()->CreateDepthStencilView(texture, {});
|
||||
ASSERT_NE(dsv, nullptr);
|
||||
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->ClearDepthStencil(dsv, 1.0f, 0);
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
delete dsv;
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, CommandList_TransitionBarrier_WithRealResource) {
|
||||
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);
|
||||
|
||||
RHIResourceView* srv = GetDevice()->CreateShaderResourceView(texture, {});
|
||||
ASSERT_NE(srv, nullptr);
|
||||
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->TransitionBarrier(srv, ResourceStates::Common, ResourceStates::PixelShaderResource);
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
delete srv;
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, CommandList_SetRenderTargets_WithRealViews) {
|
||||
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);
|
||||
|
||||
RHIResourceView* rtv = GetDevice()->CreateRenderTargetView(texture, {});
|
||||
ASSERT_NE(rtv, nullptr);
|
||||
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->SetRenderTargets(1, &rtv, nullptr);
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
delete rtv;
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, CommandList_CopyResource_WithRealResources) {
|
||||
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* srcTexture = GetDevice()->CreateTexture(texDesc);
|
||||
ASSERT_NE(srcTexture, nullptr);
|
||||
|
||||
RHITexture* dstTexture = GetDevice()->CreateTexture(texDesc);
|
||||
ASSERT_NE(dstTexture, nullptr);
|
||||
|
||||
RHIResourceView* srcView = GetDevice()->CreateShaderResourceView(srcTexture, {});
|
||||
RHIResourceView* dstView = GetDevice()->CreateShaderResourceView(dstTexture, {});
|
||||
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->CopyResource(dstView, srcView);
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
delete srcView;
|
||||
delete dstView;
|
||||
srcTexture->Shutdown();
|
||||
delete srcTexture;
|
||||
dstTexture->Shutdown();
|
||||
delete dstTexture;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, CommandList_BeginEndRenderPass_Basic) {
|
||||
AttachmentDesc colorDesc = {};
|
||||
colorDesc.format = Format::R8G8B8A8_UNorm;
|
||||
colorDesc.loadOp = LoadAction::Clear;
|
||||
colorDesc.storeOp = StoreAction::Store;
|
||||
|
||||
RHIRenderPass* renderPass = GetDevice()->CreateRenderPass(1, &colorDesc, nullptr);
|
||||
ASSERT_NE(renderPass, 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);
|
||||
|
||||
RHIResourceView* rtv = GetDevice()->CreateRenderTargetView(texture, {});
|
||||
ASSERT_NE(rtv, nullptr);
|
||||
|
||||
RHIFramebuffer* fb = GetDevice()->CreateFramebuffer(renderPass, 256, 256, 1, &rtv, nullptr);
|
||||
ASSERT_NE(fb, nullptr);
|
||||
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
Rect renderArea = { 0, 0, 256, 256 };
|
||||
ClearValue clearValue = { { 0.0f, 0.0f, 0.0f, 1.0f }, 1.0f, 0 };
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->TransitionBarrier(static_cast<RHIResourceView*>(nullptr), ResourceStates::Common, ResourceStates::RenderTarget);
|
||||
cmdList->BeginRenderPass(renderPass, fb, renderArea, 1, &clearValue);
|
||||
cmdList->EndRenderPass();
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
fb->Shutdown();
|
||||
delete fb;
|
||||
delete rtv;
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
renderPass->Shutdown();
|
||||
delete renderPass;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, CommandList_TransitionBarrier_WithResourceView) {
|
||||
TEST_P(RHITestFixture, CommandList_BeginEndRenderPass_WithClear) {
|
||||
AttachmentDesc colorDesc = {};
|
||||
colorDesc.format = Format::R8G8B8A8_UNorm;
|
||||
colorDesc.loadOp = LoadAction::Clear;
|
||||
colorDesc.storeOp = StoreAction::Store;
|
||||
|
||||
RHIRenderPass* renderPass = GetDevice()->CreateRenderPass(1, &colorDesc, nullptr);
|
||||
ASSERT_NE(renderPass, 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);
|
||||
|
||||
RHIResourceView* rtv = GetDevice()->CreateRenderTargetView(texture, {});
|
||||
ASSERT_NE(rtv, nullptr);
|
||||
|
||||
RHIFramebuffer* fb = GetDevice()->CreateFramebuffer(renderPass, 256, 256, 1, &rtv, nullptr);
|
||||
ASSERT_NE(fb, nullptr);
|
||||
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
Rect renderArea = { 0, 0, 256, 256 };
|
||||
ClearValue clearValue = { { 1.0f, 0.0f, 0.0f, 1.0f }, 1.0f, 0 };
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->TransitionBarrier(static_cast<RHIResourceView*>(nullptr), ResourceStates::Common, ResourceStates::RenderTarget);
|
||||
cmdList->BeginRenderPass(renderPass, fb, renderArea, 1, &clearValue);
|
||||
cmdList->EndRenderPass();
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
fb->Shutdown();
|
||||
delete fb;
|
||||
delete rtv;
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
renderPass->Shutdown();
|
||||
delete renderPass;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, CommandList_SetRenderTargets_WithResourceView) {
|
||||
TEST_P(RHITestFixture, CommandList_SetShader) {
|
||||
ShaderCompileDesc shaderDesc = {};
|
||||
if (GetBackendType() == RHIType::D3D12) {
|
||||
shaderDesc.fileName = L"tests/RHI/D3D12/integration/quad/Res/Shader/quad.hlsl";
|
||||
shaderDesc.entryPoint = L"MainVS";
|
||||
shaderDesc.profile = L"vs_5_0";
|
||||
} else {
|
||||
shaderDesc.sourceLanguage = ShaderLanguage::GLSL;
|
||||
static const char* vs = "#version 430\nin vec4 aPosition;\nvoid main() { gl_Position = aPosition; }";
|
||||
shaderDesc.source.assign(vs, vs + strlen(vs));
|
||||
}
|
||||
|
||||
RHIShader* shader = GetDevice()->CompileShader(shaderDesc);
|
||||
if (shader == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
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->SetShader(shader);
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
shader->Shutdown();
|
||||
delete shader;
|
||||
}
|
||||
|
||||
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();
|
||||
RHIResourceView* buffer = nullptr;
|
||||
cmdList->SetVertexBuffers(0, 1, &buffer, nullptr, nullptr);
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user