D3D12 Core: - Add ID3D12Fence1 and fence_value to d3d12_command - Add fence_event for CPU waiting - Implement wait() in command_frame for frame sync - Implement flush() to wait all frames complete - Add fence_value tracking per frame - Signal fence at end_frame with incremented value TestRenderer: - Call graphics::render() in run() Documentation: - Add changelog for Fence sync implementation - Update D3D12 Wiki with Fence sync section
113 lines
2.2 KiB
C++
113 lines
2.2 KiB
C++
/**
|
|
* @file TestRenderer.cpp
|
|
* @brief 渲染功能综合测试实现。
|
|
*/
|
|
|
|
#include "TestRenderer.h"
|
|
#include "Graphics/Renderer.h"
|
|
#include "Platform/Platform.h"
|
|
#include "Platform/PlatformTypes.h"
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
|
|
|
|
#ifdef TEST_RENDERER
|
|
using namespace XEngine;
|
|
|
|
graphics::render_surface _surfaces[4];
|
|
|
|
LRESULT win_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
|
{
|
|
bool toggle_fullscreen{ false };
|
|
switch (msg)
|
|
{
|
|
case WM_DESTROY:
|
|
{
|
|
bool all_closed{ true };
|
|
for (u32 i{ 0 }; i < _countof(_surfaces); ++i)
|
|
{
|
|
if(!_surfaces[i].window.is_closed())
|
|
{
|
|
all_closed = false;
|
|
}
|
|
}
|
|
if (all_closed)
|
|
{
|
|
PostQuitMessage(0);
|
|
return 0;
|
|
}
|
|
break;
|
|
}
|
|
case WM_SYSCHAR:
|
|
{
|
|
|
|
if(wparam == VK_RETURN && (HIWORD(lparam) & KF_ALTDOWN))
|
|
{
|
|
platform::window win{ platform::window_id{(id::id_type)GetWindowLongPtr(hwnd, GWLP_USERDATA)} };
|
|
win.set_fullscreen(!win.is_fullscreen());
|
|
return 0;
|
|
}
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
return DefWindowProc(hwnd, msg, wparam, lparam);
|
|
}
|
|
|
|
void
|
|
create_render_surface(graphics::render_surface& surface, const platform::window_init_info info)
|
|
{
|
|
surface.window = platform::create_window(&info);
|
|
}
|
|
|
|
void
|
|
_destroy_render_surface(graphics::render_surface& surface)
|
|
{
|
|
platform::remove_window(surface.window.get_id());
|
|
}
|
|
|
|
bool
|
|
engine_test::initialize()
|
|
{
|
|
bool result{ graphics::initialize(graphics::graphics_platform::direct3d12) };
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
platform::window_init_info info[]
|
|
{
|
|
{&win_proc, nullptr, L"Test Window 1", 200, 100,400,400},
|
|
{&win_proc, nullptr, L"Test Window 2", 700, 100,400,400},
|
|
{&win_proc, nullptr, L"Test Window 2", 700, 100,400,400},
|
|
{&win_proc, nullptr, L"Test Window 3", 1200,100,400,400},
|
|
};
|
|
static_assert(_countof(info) == _countof(_surfaces));
|
|
for (u32 i{ 0 }; i < _countof(_surfaces); ++i)
|
|
{
|
|
create_render_surface(_surfaces[i], info[i]);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
void
|
|
engine_test::run()
|
|
{
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
graphics::render();
|
|
}
|
|
|
|
bool
|
|
engine_test::shutdown()
|
|
{
|
|
for (u32 i{ 0 }; i < _countof(_surfaces); ++i)
|
|
{
|
|
_destroy_render_surface(_surfaces[i]);
|
|
}
|
|
|
|
graphics::shutdown();
|
|
|
|
return true;
|
|
}
|
|
#endif // TEST_RENDERER
|