Commit Graph

31 Commits

Author SHA1 Message Date
605ef56e16 Add pipeline layout support for graphics PSOs 2026-03-25 23:49:48 +08:00
2470451d96 Honor input layouts in OpenGL vertex bindings 2026-03-25 23:24:06 +08:00
1597181458 Add graphics shader support to RHI pipeline states 2026-03-25 23:19:18 +08:00
aaf9cce418 Add RHI vertex and index buffer views 2026-03-25 23:07:22 +08:00
30b5f93157 Fix RHI swap chain queue binding and restore minimal GT checks 2026-03-25 21:50:57 +08:00
8f76564ded test: Add new RHI unit tests for capabilities, views, screenshot, descriptor set and pipeline layout 2026-03-25 20:50:56 +08:00
a9b9a6ebfc 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
2026-03-25 20:50:49 +08:00
6bbd35873b test: Update RHI unit tests to use CreateShader API
Rename CompileShader to CreateShader in all RHI unit tests:
- test_command_list.cpp
- test_compute.cpp
- test_shader.cpp
2026-03-25 19:01:59 +08:00
b11f59e144 Fix RHI D3D12 RTV creation and GetFormat bug
1. Add ALLOW_RENDER_TARGET flag for color textures in CreateTexture
   - This was the root cause of 5 failing RTV-related tests
   - Without this flag, creating RTV caused device removal

2. Add FromD3D12() reverse conversion for Format enum
   - GetFormat() was incorrectly casting DXGI_FORMAT to Format
   - DXGI_FORMAT_R8G8B8A8_UNORM=28 but Format::R8G8B8A8_UNorm=3
   - Added FromD3D12() to properly convert back

3. Update RHITestFixture to pre-create CommandQueue and Fence
   - Prevents potential timing issues with GPU synchronization

4. Update RHITestFixture tests to pass correct format in ResourceViewDesc
   - Previously passed empty desc.format=0 which caused issues

All 234 RHI unit tests now pass (117 D3D12 + 117 OpenGL)
2026-03-25 18:12:50 +08:00
6612330347 Fix RHI format conversion and test viewDesc initialization
- Fix CreateTexture to use ToD3D12() for format conversion
- Fix CreateRenderTargetView to use ToD3D12() for format conversion
- Fix CreateDepthStencilView to use ToD3D12() for format conversion
- Fix CreateShaderResourceView to use ToD3D12() for format conversion
- Update test to pass correct format in ResourceViewDesc

These fixes resolve CommandList_ClearDepthStencil_WithRealView test.
Other RTV-related tests still fail with DXGI_ERROR_NOT_CURRENTLY_AVAILABLE
from CreateCommandAllocator - further investigation needed.
2026-03-25 17:43:59 +08:00
295459067f Fix RHI format conversion and add debug logging for D3D12 tests 2026-03-25 17:30:16 +08:00
16e2065c6c Unified logging: Replace LogSystem with EditorConsoleSink
- Created EditorConsoleSink (implements ILogSink interface)
- EditorConsoleSink stores logs in memory buffer (max 1000 entries)
- Added to Debug::Logger in Application::Initialize()
- ConsolePanel now reads from EditorConsoleSink via static GetInstance()
- Removed separate LogSystem singleton
- Removed editor/src/Core/LogEntry.h (no longer needed)

Now Editor and Engine share the same Debug::Logger, with ConsolePanel
displaying logs via EditorConsoleSink.
2026-03-25 16:13:02 +08:00
008fb98dee 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()
2026-03-25 15:51:27 +08:00
720dd422d5 RHI: Add Compute/Dispatch unit tests (P1-7) and fix shader type bugs
Bug fixes:
- D3D12Shader::Compile: Set m_type based on target string (cs_/vs_/ps_/gs_)
- OpenGLShader::Compile: Parse target parameter to determine shader type
- OpenGLShader::CompileCompute: Set m_type = ShaderType::Compute
- D3D12CommandList::SetPipelineState: Use correct PSO handle for Compute

New tests (test_compute.cpp, 8 tests):
- ComputeShader_Compile_ValidShader
- ComputeShader_GetType_ReturnsCompute
- ComputeShader_Shutdown_Invalidates
- PipelineState_SetComputeShader
- PipelineState_HasComputeShader_ReturnsTrue
- PipelineState_GetType_Compute
- PipelineState_EnsureValid_Compute
- CommandList_Dispatch_Basic

Test results: 232/232 passed (D3D12: 116, OpenGL: 116)
2026-03-25 13:52:11 +08:00
920d3be78b RHI: Add DescriptorPool unit tests (8 tests, P1-5) 2026-03-25 13:21:13 +08:00
2ac32e1330 RHI: Add RenderPass and Framebuffer unit tests with CMake support 2026-03-25 13:03:07 +08:00
f808f8d197 RHI: Replace IsFinalized/Finalize with IsValid/EnsureValid
Unified PSO validation semantics across D3D12 and OpenGL backends:
- IsValid() returns whether PSO is ready to use
- EnsureValid() ensures PSO is valid (compiles if needed)

Behavior by backend:
- D3D12: IsValid=false after creation, true after EnsureValid() with shaders
- OpenGL: IsValid always=true (immediate model)

Also added test_pipeline_state.cpp with 10 tests for RHIPipelineState.
2026-03-25 12:28:33 +08:00
32c04b86b7 RHI: Add embedded shader source support via ShaderCompileDesc
- Add ShaderLanguage enum (HLSL, GLSL, SPIRV)
- Extend ShaderCompileDesc with source/sourceLanguage fields
- D3D12Device::CompileShader supports both file and embedded source
- OpenGLDevice::CompileShader supports embedded GLSL source
- Refactor test_shader.cpp to use embedded source for both backends

This enables consistent shader compilation across D3D12 and OpenGL
backends while maintaining backend-specific shader language support.
2026-03-25 12:00:26 +08:00
a2fc8eca02 RHI: Remove无效的动态状态方法 - SetDepthStencilState/SetBlendState
重构原因:
- D3D12 PSO是不可变的,SetDepthStencilState/SetBlendState调用原本就是空实现(TODO)
- 这些方法在D3D12中完全无效,是死代码

移除的方法:
- SetDepthStencilState(const DepthStencilState&) - D3D12空实现,OpenGL直接调用GL函数
- SetBlendState(const BlendState&) - D3D12只设置BlendFactor其他忽略,OpenGL直接调用GL函数

保留的真正动态状态:
- SetViewport/SetViewports
- SetScissorRect/SetScissorRects
- SetStencilRef (D3D12动态状态)
- SetBlendFactor (D3D12动态状态)

注:PrimitiveTopology保留在CommandList,因为D3D12允许动态改变topology type

测试状态:150个RHI单元测试全部通过,8个集成测试全部通过
2026-03-25 00:37:18 +08:00
c6fe9547aa RHI: Add DescriptorSet abstraction for D3D12 and OpenGL backends
- Add RHIDescriptorSet base class with Update/UpdateSampler/GetNativeHandle
- Add RHIDescriptorPool with AllocateSet/FreeSet methods
- Add SetGraphicsDescriptorSets/SetComputeDescriptorSets to RHICommandList
- Implement D3D12DescriptorSet using descriptor heap allocation
- Implement OpenGLDescriptorSet using TextureUnitAllocator
- Add CreateDescriptorPool/CreateDescriptorSet factory methods to RHIDevice
- Fix unit test SetVertexBuffer -> SetVertexBuffers API
- Add SetVertexBuffer convenience method for D3D12 backward compatibility
- Update CMakeLists.txt with new source files
2026-03-25 00:26:16 +08:00
7a66913f2b refactor(RHI): 将窗口职责从RHI移到Platform层
- RHIDeviceDesc 删除 windowHandle/width/height/appName
- SwapChainDesc 添加 windowHandle 字段
- RHISwapChain 删除 PollEvents/ShouldClose/SetFullscreen 等窗口相关接口
- OpenGLDevice 删除 CreateRenderWindow,改用 InitializeWithExistingWindow
- 更新所有集成测试使用新API
- 273个单元测试 + 8个集成测试全部通过
2026-03-24 23:00:49 +08:00
0dde7234b7 refactor(RHI): remove void* from CommandList interfaces and fix OpenGL MRT bug
- Remove void* parameters from RHICommandList abstract interface
- TransitionBarrier, SetVertexBuffer, SetIndexBuffer, SetRenderTargets,
  ClearRenderTarget, ClearDepthStencil, CopyResource now use RHIResourceView*
- SetPipelineState now uses RHIPipelineState* instead of void*
- Simplified SetVertexBuffer to 3 params, SetIndexBuffer to 2 params
- Add internal D3D12 APIs for native type support (low-level escape hatch)
- Fix OpenGL SetRenderTargets to call glDrawBuffers for MRT support
- Update tests to match new interface signatures

All 289 RHI tests pass (158 unit + 64 OpenGL backend + 58 D3D12 backend + 8 integration + 1 disabled)
2026-03-24 17:20:51 +08:00
b1829bcfc5 【关键节点】OpenGLCommandList实现RHIResourceView*方法完成统一资源绑定
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集成测试全部通过
2026-03-24 05:23:42 +08:00
0a3fe842b9 Refactor RHI ResourceView abstraction layer for unified cross-platform interface
- Create unified RHIResourceView base interface with type-specific Initialize methods
- Implement D3D12ResourceView with RTV/DSV/SRV/UAV/CBV support
- Implement OpenGL ResourceView simulation layer using FBO, texture units, and UBO
- Add OpenGLTextureUnitAllocator for managing texture unit bindings
- Add OpenGLUniformBufferManager for UBO binding points
- Add OpenGLFramebuffer for FBO management
- Remove deprecated D3D12 view classes (RenderTargetView, DepthStencilView, etc.)
- Fix ExecuteCommandLists type confusion bug by adding GetNativeHandle to RHICommandList
- Fix test bug where Close() was called before ExecuteCommandLists
- Update all integration tests to use new D3D12ResourceView class
- All tests pass: 144 unit tests + 8 integration tests
2026-03-24 03:49:13 +08:00
08c01dd143 RHI: Refactor Fence module to pure timeline semantics
- Remove IsSignaled() from RHIFence interface (semantic inconsistency)
- Remove Reset() from OpenGL implementation (no D3D12 counterpart)
- OpenGL Fence now uses single GLsync + CPU counters for timeline simulation
- OpenGL Fence Initialize() now accepts uint64_t initialValue (was bool)
- Add comprehensive timeline semantics tests for all backends:
  - Signal increment/decrement scenarios
  - Multiple signals
  - Wait smaller than completed value
  - GetCompletedValue stages verification
- Update documentation to reflect actual implementation
2026-03-24 01:53:00 +08:00
0fa4f2e3a8 Fix RHI unit test failures and OpenGL backend issues
- Fix D3D12Texture::GetTextureType() to return correct type based on D3D12 resource dimension
- Fix OpenGL CommandQueue::Signal() to properly call fence->Signal()
- Fix OpenGL CommandQueue::GetTimestampFrequency() using GL_TIMESTAMP
- Fix OpenGL Device::GetNativeDevice() to return m_hglrc
- Fix OpenGL Fence::Signal() to create GL sync object and update completedValue
- Fix OpenGL Fence::Wait() to properly wait for fence
- Fix OpenGL Fence::GetNativeHandle() to create sync on first call
- Fix OpenGL SwapChain::GetCurrentBackBuffer() to return backbuffer texture
- Fix OpenGL SwapChain::Initialize() to create backbuffer texture
- Fix OpenGL SwapChain::Shutdown() to cleanup backbuffer texture
- Fix RHI unit tests: add missing sampleCount/sampleQuality/depth/arraySize fields
- Fix RHI unit tests: add complete TextureDesc fields where needed
2026-03-23 21:09:15 +08:00
bc6b47ffcf fix: RHI单元测试修复与命名规范统一
RHI抽象层测试修复:
- OpenGL Shader: 空描述符正确返回nullptr
- OpenGL Texture: 修复TextureType映射(case 2/3)
- OpenGL Buffer: 设置stride和state支持
- OpenGL Texture: 添加Format和State支持
- OpenGL SwapChain: 修复IsFullscreen硬编码false问题

命名规范统一( snake_case + _test后缀):
- D3D12_Minimal -> d3d12_minimal_test
- D3D12_Triangle -> d3d12_triangle_test
- D3D12_Quad -> d3d12_quad_test
- D3D12_Sphere -> d3d12_sphere_test
- OpenGL_Minimal -> opengl_minimal_test
- OpenGL_Triangle -> opengl_triangle_test
- OpenGL_Quad -> opengl_quad_test
- OpenGL_Sphere -> opengl_sphere_test
- CTest名称去掉_Integration后缀

测试结果: 138个测试中从21个失败减少到16个失败
2026-03-23 20:32:33 +08:00
067c82c3a9 refactor: RHI抽象层测试支持参数化
- 将RHITestFixture改为TestWithParam<RHIType>,支持D3D12和OpenGL双后端
- 重构RHIFactory.cpp的include结构,修复OpenGL设备创建
- 在CMakeLists.txt中添加XCENGINE_SUPPORT_OPENGL宏定义
- 更新engine/CMakeLists.txt和tests/RHI/unit/CMakeLists.txt
- 将所有TEST_F改为TEST_P以支持参数化测试

测试结果: 138 tests (D3D12: 58 passed / OpenGL: 48 passed)
2026-03-23 19:17:32 +08:00
6935a91a1f fix: RHI抽象层单元测试修复
- 实现 D3D12Device::CreateCommandQueue/CreateCommandList/CreateSwapChain
- 修复 Buffer::Map 对 DEFAULT heap 的问题 (Vertex/Index 使用 UPLOAD heap)
- 修复 Fence::IsSignaled() 初始值问题
- 修复 Sampler::GetNativeHandle() 返回值
- 修复 RHICapabilities 和 RHIDeviceInfo 初始化
- 修复 Shader 测试 (空 ShaderCompileDesc 预期)
- 修复 RHITestFixture 创建窗口句柄
- 重命名 opengl_engine_tests -> rhi_opengl_tests
- 添加 tests/RHI/unit/ 到构建系统

测试结果: 22 passed -> 59 passed
2026-03-23 18:53:29 +08:00
f427699ac6 refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
  instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
  test discovery (math, core, containers, memory, threading, debug,
  components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
  from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
  build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00
8d4447915d 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
2026-03-22 16:18:51 +08:00