From 1d6312d1e4935adbc7195e982815ee781a3fbc3f Mon Sep 17 00:00:00 2001 From: niels win10 Date: Mon, 17 Jun 2019 13:36:53 +0200 Subject: [PATCH 1/8] Almost added headless support --- src/d3d12/d3d12_renderer.cpp | 11 +-- .../d3d12_cubemap_convolution.hpp | 3 +- .../d3d12_deferred_composition.cpp | 1 - src/render_tasks/d3d12_deferred_main.hpp | 3 +- .../d3d12_equirect_to_cubemap.hpp | 3 +- src/render_tasks/d3d12_imgui_render_task.hpp | 3 +- src/render_tasks/d3d12_path_tracer.hpp | 1 - src/render_tasks/d3d12_raytracing_task.hpp | 1 - src/render_tasks/d3d12_rt_reflection_task.hpp | 1 - src/render_tasks/d3d12_rt_shadow_task.hpp | 1 - src/render_tasks/d3d12_rtao_task.hpp | 1 - .../d3d12_shadow_denoiser_task.hpp | 1 - src/window.cpp | 86 ++++++++++++++++--- src/window.hpp | 20 ++++- 14 files changed, 95 insertions(+), 41 deletions(-) diff --git a/src/d3d12/d3d12_renderer.cpp b/src/d3d12/d3d12_renderer.cpp index 8693a6dd..1a890fdf 100644 --- a/src/d3d12/d3d12_renderer.cpp +++ b/src/d3d12/d3d12_renderer.cpp @@ -93,7 +93,7 @@ namespace wr SetName(m_compute_queue, L"Default D3D12 Compute Command Queue"); SetName(m_copy_queue, L"Default D3D12 Copy Command Queue"); - if (window.has_value()) + if (window.has_value() && window.value()->HasPhysicalWindow()) { m_render_window = d3d12::CreateRenderWindow(m_device, window.value()->GetWindowHandle(), m_direct_queue, d3d12::settings::num_back_buffers); } @@ -137,7 +137,7 @@ namespace wr m_raytracing_offset_sb_pool = CreateStructuredBufferPool(rt_offset_align_size); // Begin Recording - auto frame_idx = m_render_window.has_value() ? m_render_window.value()->m_frame_idx : 0; + auto frame_idx = GetFrameIdx(); d3d12::Begin(m_direct_cmd_list, frame_idx); // Stage fullscreen quad @@ -970,13 +970,6 @@ namespace wr { d3d12::Begin(m_direct_cmd_list, frame_idx); - if (clear_frame_buffer) - { - CD3DX12_CPU_DESCRIPTOR_HANDLE rtv_descriptor(m_render_window.value()->m_rtv_descriptor_heap->GetCPUDescriptorHandleForHeapStart()); - - rtv_descriptor.Offset(frame_idx, m_render_window.value()->m_rtv_descriptor_increment_size); - } - for (int i = 0; i < m_structured_buffer_pools.size(); ++i) { m_structured_buffer_pools[i]->UpdateBuffers(m_direct_cmd_list, frame_idx); diff --git a/src/render_tasks/d3d12_cubemap_convolution.hpp b/src/render_tasks/d3d12_cubemap_convolution.hpp index b6601266..71d10964 100644 --- a/src/render_tasks/d3d12_cubemap_convolution.hpp +++ b/src/render_tasks/d3d12_cubemap_convolution.hpp @@ -123,11 +123,10 @@ namespace wr if (radiance->m_is_staged) { - if (n_render_system.m_render_window.has_value()) { auto cmd_list = fg.GetCommandList(handle); const auto viewport = d3d12::CreateViewport(static_cast(irradiance->m_width), static_cast(irradiance->m_height)); - const auto frame_idx = n_render_system.GetRenderWindow()->m_frame_idx; + const auto frame_idx = n_render_system.GetFrameIdx(); d3d12::BindViewport(cmd_list, viewport); d3d12::BindPipeline(cmd_list, data.in_pipeline); diff --git a/src/render_tasks/d3d12_deferred_composition.cpp b/src/render_tasks/d3d12_deferred_composition.cpp index 9455572a..25236815 100644 --- a/src/render_tasks/d3d12_deferred_composition.cpp +++ b/src/render_tasks/d3d12_deferred_composition.cpp @@ -224,7 +224,6 @@ namespace wr } } - if (n_render_system.m_render_window.has_value()) { const auto viewport = n_render_system.m_viewport; const auto frame_idx = n_render_system.GetFrameIdx(); diff --git a/src/render_tasks/d3d12_deferred_main.hpp b/src/render_tasks/d3d12_deferred_main.hpp index 9e5a0ff8..c07af928 100644 --- a/src/render_tasks/d3d12_deferred_main.hpp +++ b/src/render_tasks/d3d12_deferred_main.hpp @@ -43,10 +43,9 @@ namespace wr auto& data = fg.GetData(handle); auto cmd_list = fg.GetCommandList(handle); - if (n_render_system.m_render_window.has_value()) { const auto viewport = n_render_system.m_viewport; - const auto frame_idx = n_render_system.GetRenderWindow()->m_frame_idx; + const auto frame_idx = n_render_system.GetFrameIdx(); d3d12::BindViewport(cmd_list, viewport); d3d12::BindPipeline(cmd_list, data.in_pipeline); diff --git a/src/render_tasks/d3d12_equirect_to_cubemap.hpp b/src/render_tasks/d3d12_equirect_to_cubemap.hpp index 27be0a89..988bcf23 100644 --- a/src/render_tasks/d3d12_equirect_to_cubemap.hpp +++ b/src/render_tasks/d3d12_equirect_to_cubemap.hpp @@ -194,11 +194,10 @@ namespace wr d3d12::TextureResource* equirect_text = static_cast(data.in_equirect.m_pool->GetTextureResource(data.in_equirect)); d3d12::TextureResource* cubemap_text = static_cast(data.out_cubemap.m_pool->GetTextureResource(data.out_cubemap)); - if (n_render_system.m_render_window.has_value()) { auto cmd_list = fg.GetCommandList(handle); const auto viewport = d3d12::CreateViewport(static_cast(cubemap_text->m_width), static_cast(cubemap_text->m_height)); - const auto frame_idx = n_render_system.GetRenderWindow()->m_frame_idx; + const auto frame_idx = n_render_system.GetFrameIdx(); d3d12::BindViewport(cmd_list, viewport); d3d12::BindPipeline(cmd_list, data.in_pipeline); diff --git a/src/render_tasks/d3d12_imgui_render_task.hpp b/src/render_tasks/d3d12_imgui_render_task.hpp index 3ca01e2a..74f93bad 100644 --- a/src/render_tasks/d3d12_imgui_render_task.hpp +++ b/src/render_tasks/d3d12_imgui_render_task.hpp @@ -26,7 +26,7 @@ namespace wr { auto& n_render_system = static_cast(rs); - if (!n_render_system.m_window.has_value()) + if (!n_render_system.m_window.has_value() || !n_render_system.m_window.value()->HasPhysicalWindow()) { LOGC("Tried using imgui without a window!"); } @@ -76,7 +76,6 @@ namespace wr auto cmd_list = fg.GetCommandList(handle); // Temp rendering - if (n_render_system.m_render_window.has_value()) { auto frame_idx = n_render_system.GetFrameIdx(); diff --git a/src/render_tasks/d3d12_path_tracer.hpp b/src/render_tasks/d3d12_path_tracer.hpp index db2a78ba..3da8d9c4 100644 --- a/src/render_tasks/d3d12_path_tracer.hpp +++ b/src/render_tasks/d3d12_path_tracer.hpp @@ -229,7 +229,6 @@ namespace wr // Wait for AS to be built d3d12::UAVBarrierAS(cmd_list, as_build_data.out_tlas, frame_idx); - if (n_render_system.m_render_window.has_value()) { d3d12::BindRaytracingPipeline(cmd_list, data.out_state_object, d3d12::GetRaytracingType(device) == RaytracingType::FALLBACK); diff --git a/src/render_tasks/d3d12_raytracing_task.hpp b/src/render_tasks/d3d12_raytracing_task.hpp index 6bab32d3..77eef6d4 100644 --- a/src/render_tasks/d3d12_raytracing_task.hpp +++ b/src/render_tasks/d3d12_raytracing_task.hpp @@ -169,7 +169,6 @@ namespace wr d3d12::UAVBarrierAS(cmd_list, as_build_data.out_tlas, frame_idx); } - if (n_render_system.m_render_window.has_value()) { d3d12::BindRaytracingPipeline(cmd_list, data.out_state_object, d3d12::GetRaytracingType(device) == RaytracingType::FALLBACK); diff --git a/src/render_tasks/d3d12_rt_reflection_task.hpp b/src/render_tasks/d3d12_rt_reflection_task.hpp index caa7f401..31d7fa88 100644 --- a/src/render_tasks/d3d12_rt_reflection_task.hpp +++ b/src/render_tasks/d3d12_rt_reflection_task.hpp @@ -97,7 +97,6 @@ namespace wr d3d12::UAVBarrierAS(cmd_list, as_build_data.out_tlas, frame_idx); } - if (n_render_system.m_render_window.has_value()) { d3d12::BindRaytracingPipeline(cmd_list, data.base_data.out_state_object, d3d12::GetRaytracingType(device) == RaytracingType::FALLBACK); diff --git a/src/render_tasks/d3d12_rt_shadow_task.hpp b/src/render_tasks/d3d12_rt_shadow_task.hpp index 3e27b4d4..e30ddf78 100644 --- a/src/render_tasks/d3d12_rt_shadow_task.hpp +++ b/src/render_tasks/d3d12_rt_shadow_task.hpp @@ -112,7 +112,6 @@ namespace wr d3d12::UAVBarrierAS(cmd_list, as_build_data.out_tlas, frame_idx); } - if (n_render_system.m_render_window.has_value()) { d3d12::BindRaytracingPipeline(cmd_list, data.base_data.out_state_object, d3d12::GetRaytracingType(device) == RaytracingType::FALLBACK); diff --git a/src/render_tasks/d3d12_rtao_task.hpp b/src/render_tasks/d3d12_rtao_task.hpp index bfab2927..d3455997 100644 --- a/src/render_tasks/d3d12_rtao_task.hpp +++ b/src/render_tasks/d3d12_rtao_task.hpp @@ -170,7 +170,6 @@ namespace wr fg.WaitForPredecessorTask(); float scalar = 1.0f; - if (n_render_system.m_render_window.has_value()) { d3d12::BindRaytracingPipeline(cmd_list, data.in_state_object, false); diff --git a/src/render_tasks/d3d12_shadow_denoiser_task.hpp b/src/render_tasks/d3d12_shadow_denoiser_task.hpp index 414c6372..e4239c36 100644 --- a/src/render_tasks/d3d12_shadow_denoiser_task.hpp +++ b/src/render_tasks/d3d12_shadow_denoiser_task.hpp @@ -556,7 +556,6 @@ namespace wr data.m_constant_buffer_pool->Update(data.m_denoiser_settings_buffer[i], sizeof(temp::ShadowDenoiserSettings_CBData), 0, n_render_system.GetFrameIdx(), (uint8_t*)& data.m_denoiser_settings); } - if (n_render_system.m_render_window.has_value()) { const auto viewport = n_render_system.m_viewport; const auto frame_idx = n_render_system.GetFrameIdx(); diff --git a/src/window.cpp b/src/window.cpp index 6448ae3a..31fce8fd 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -11,7 +11,7 @@ namespace wr { - Window::Window(HINSTANCE instance, int show_cmd, std::string const & name, std::uint32_t width, std::uint32_t height) + Window::Window(HINSTANCE instance, std::string const &name, std::uint32_t width, std::uint32_t height, bool show) : m_title(name), m_instance(instance) { WNDCLASSEX wc; @@ -70,26 +70,41 @@ namespace wr SetWindowLongPtr(m_handle, GWLP_USERDATA, (LONG_PTR)this); - ShowWindow(m_handle, show_cmd); + ShowWindow(m_handle, show ? SW_SHOWNORMAL : SW_HIDE); UpdateWindow(m_handle); - - m_running = true; } - - Window::Window(HINSTANCE instance, std::string const& name, std::uint32_t width, std::uint32_t height, bool show) - : Window(instance, show ? SW_SHOWNORMAL : SW_HIDE, name, width, height) - { + + Window::Window( std::string const &name, std::uint32_t width, std::uint32_t height) + : m_title(name), m_window_width(width), m_window_height(height) { } Window::~Window() { Stop(); - UnregisterClassA(m_title.c_str(), m_instance); + + if (m_instance) + { + UnregisterClassA(m_title.c_str(), m_instance); + } } void Window::PollEvents() { + //Handle virtual window + + if(!m_handle) + { + if (m_render_func) + { + m_render_func(); + } + + return; + } + + //Handle physical window + MSG msg; if (PeekMessage(&msg, m_handle, 0, 0, PM_REMOVE)) { @@ -103,12 +118,22 @@ namespace wr void Window::Show() { - ShowWindow(m_handle, SW_SHOW); + if(m_handle) + { + ShowWindow(m_handle, SW_SHOW); + } + else + { + LOGW("Window::show called on virtual window"); + } } void Window::Stop() { - DestroyWindow(m_handle); + if (m_handle) + { + DestroyWindow(m_handle); + } } void Window::SetRenderLoop(std::function render_func) @@ -123,27 +148,43 @@ namespace wr PollEvents(); } - UnregisterClassA(m_title.c_str(), m_instance); + if(m_instance) + { + UnregisterClassA(m_title.c_str(), m_instance); + } } void Window::SetKeyCallback(KeyCallback callback) { m_key_callback = std::move(callback); + + if(!m_handle) + { + LOGW("Window::SetKeyCallback called on virtual window"); + } } void Window::SetMouseCallback(MouseCallback callback) { m_mouse_callback = std::move(callback); + + if (!m_handle) { + LOGW("Window::SetMouseCallback called on virtual window"); + } } void Window::SetMouseWheelCallback(MouseWheelCallback callback) { m_mouse_wheel_callback = std::move(callback); + + if (!m_handle) { + LOGW("Window::SetMouseWheelCallback called on virtual window"); + } } void Window::SetResizeCallback(ResizeCallback callback) { - m_resize_callback = std::move(callback); + m_resize_callback = std::move(callback); //TODO: Call once? } bool Window::IsRunning() const @@ -153,6 +194,11 @@ namespace wr std::int32_t Window::GetWidth() const { + if (!m_handle) + { + return m_window_width; + } + RECT r; GetClientRect(m_handle, &r); return static_cast(r.right - r.left); @@ -160,6 +206,10 @@ namespace wr std::int32_t Window::GetHeight() const { + if (!m_handle) { + return m_window_height; + } + RECT r; GetClientRect(m_handle, &r); return static_cast(r.bottom - r.top); @@ -175,8 +225,18 @@ namespace wr return m_handle; } + bool Window::HasPhysicalWindow() const + { + return m_handle; + } + bool Window::IsFullscreen() const { + if(!m_handle) + { + return true; + } + RECT a, b; GetWindowRect(m_handle, &a); GetWindowRect(GetDesktopWindow(), &b); diff --git a/src/window.hpp b/src/window.hpp index 2886a365..8bb0bf01 100644 --- a/src/window.hpp +++ b/src/window.hpp @@ -13,7 +13,9 @@ namespace wr using ResizeCallback = std::function; using MouseWheelCallback = std::function; public: + /*! + Creates a physical window * @param instance A handle to the current instance of the application. * @param name Window title. * @param width Initial window width. @@ -21,7 +23,15 @@ namespace wr * @param show Controls whether the window will be shown. Default is true. */ Window(HINSTANCE instance, std::string const& name, std::uint32_t width, std::uint32_t height, bool show = true); - Window(HINSTANCE instance, int show_cmd, std::string const& name, std::uint32_t width, std::uint32_t height); + + /*! + Creates a non-physical window + * @param name Window title. + * @param width Initial window width. + * @param height Initial window height. + */ + Window(std::string const &name, std::uint32_t width, std::uint32_t height); + ~Window(); Window(const Window&) = delete; @@ -62,6 +72,8 @@ namespace wr HWND GetWindowHandle() const; /*! Checks whether the window is fullscreen */ bool IsFullscreen() const; + /*! Checks whether the window is OS backed or not */ + bool HasPhysicalWindow() const; private: /*! WindowProc that calls `WindowProc_Impl` */ @@ -78,9 +90,9 @@ namespace wr std::string m_title; - bool m_running; - HWND m_handle; - HINSTANCE m_instance; + bool m_running = true; + HWND m_handle = nullptr; + HINSTANCE m_instance = nullptr; std::int32_t m_window_width = 0; std::int32_t m_window_height = 0; From 4537852ed0492e4715ba9549b9d4e11350f01afc Mon Sep 17 00:00:00 2001 From: niels win10 Date: Mon, 17 Jun 2019 14:36:59 +0200 Subject: [PATCH 2/8] Added proper delta time --- src/window.cpp | 22 +++++++++++++++++++--- src/window.hpp | 8 ++++++-- tests/common/scene.hpp | 2 +- tests/demo/demo.cpp | 5 +++-- tests/demo/scene_emibl.cpp | 4 ++-- tests/demo/scene_emibl.hpp | 2 +- tests/demo/scene_sponza.cpp | 6 +++--- tests/demo/scene_sponza.hpp | 2 +- tests/demo/scene_viknell.cpp | 6 +++--- tests/demo/scene_viknell.hpp | 2 +- tests/graphics_benchmark/spheres_scene.cpp | 2 +- tests/graphics_benchmark/spheres_scene.hpp | 2 +- 12 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/window.cpp b/src/window.cpp index 31fce8fd..57207795 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -97,7 +97,15 @@ namespace wr { if (m_render_func) { - m_render_func(); + float dt = std::chrono::duration(std::chrono::high_resolution_clock::now() - m_prev_time).count(); + + if (!m_has_time_point) { + dt = 0; + m_has_time_point = true; + } + + m_prev_time = std::chrono::high_resolution_clock::now(); + m_render_func(dt); } return; @@ -136,7 +144,7 @@ namespace wr } } - void Window::SetRenderLoop(std::function render_func) + void Window::SetRenderLoop(std::function render_func) { m_render_func = std::move(render_func); } @@ -265,7 +273,15 @@ namespace wr case WM_PAINT: if (m_render_func) { - m_render_func(); + float dt = std::chrono::duration(std::chrono::high_resolution_clock::now() - m_prev_time).count(); + + if (!m_has_time_point) { + dt = 0; + m_has_time_point = true; + } + + m_prev_time = std::chrono::high_resolution_clock::now(); + m_render_func(dt); } return 0; case WM_DESTROY: diff --git a/src/window.hpp b/src/window.hpp index 8bb0bf01..52fe841e 100644 --- a/src/window.hpp +++ b/src/window.hpp @@ -2,6 +2,7 @@ #include #include +#include namespace wr { @@ -47,7 +48,7 @@ namespace wr void Stop(); /*! Give the window a function to call on repaint */ - void SetRenderLoop(std::function render_func); + void SetRenderLoop(std::function render_func); /*! Start a loop that runs until the window is closed. */ void StartRenderLoop(); @@ -86,7 +87,7 @@ namespace wr ResizeCallback m_resize_callback; MouseWheelCallback m_mouse_wheel_callback; - std::function m_render_func; + std::function m_render_func; std::string m_title; @@ -96,6 +97,9 @@ namespace wr std::int32_t m_window_width = 0; std::int32_t m_window_height = 0; + + decltype(std::chrono::high_resolution_clock::now()) m_prev_time; + bool m_has_time_point = false; }; } /* wr */ diff --git a/tests/common/scene.hpp b/tests/common/scene.hpp index 1e21d6f0..31153c67 100644 --- a/tests/common/scene.hpp +++ b/tests/common/scene.hpp @@ -15,7 +15,7 @@ class Scene virtual ~Scene(); virtual void Init(wr::D3D12RenderSystem* rs, unsigned int width, unsigned int height, void* extra = nullptr); - virtual void Update() = 0; + virtual void Update(float dt) = 0; std::shared_ptr GetSceneGraph(); template std::shared_ptr GetCamera(); diff --git a/tests/demo/demo.cpp b/tests/demo/demo.cpp index 23e9ae61..75110b5a 100644 --- a/tests/demo/demo.cpp +++ b/tests/demo/demo.cpp @@ -114,6 +114,7 @@ int WispEntry() wr::ModelLoader* assimp_model_loader = new wr::AssimpModelLoader(); wr::ModelLoader* gltf_model_loader = new wr::TinyGLTFModelLoader(); + CoInitialize(nullptr); render_system->Init(window.get()); phys_engine.CreatePhysicsWorld(); @@ -135,7 +136,7 @@ int WispEntry() auto file_watcher = new util::FileWatcher("resources/shaders", std::chrono::milliseconds(100)); file_watcher->StartAsync(&ShaderDirChangeDetected); - window->SetRenderLoop([&]() { + window->SetRenderLoop([&](float dt) { if (new_scene && new_scene != current_scene) { //delete current_scene; @@ -145,7 +146,7 @@ int WispEntry() fg_manager::Get()->SetShouldExecute(true); } - current_scene->Update(); + current_scene->Update(dt); #ifdef ENABLE_PHYSICS phys_engine.UpdateSim(ImGui::GetIO().DeltaTime, *scene_graph.get()); diff --git a/tests/demo/scene_emibl.cpp b/tests/demo/scene_emibl.cpp index fcbf6b66..b52369e6 100644 --- a/tests/demo/scene_emibl.cpp +++ b/tests/demo/scene_emibl.cpp @@ -282,7 +282,7 @@ void EmiblScene::BuildScene(unsigned int width, unsigned int height, void* extra dir_light->SetDirectional({ 360_deg - 136_deg, 0, 0 }, { 4, 4, 4 }); } -void EmiblScene::Update() +void EmiblScene::Update(float dt) { - m_camera->Update(ImGui::GetIO().DeltaTime); + m_camera->Update(dt); } \ No newline at end of file diff --git a/tests/demo/scene_emibl.hpp b/tests/demo/scene_emibl.hpp index 79349144..ae9c0177 100644 --- a/tests/demo/scene_emibl.hpp +++ b/tests/demo/scene_emibl.hpp @@ -13,7 +13,7 @@ class EmiblScene : public Scene public: EmiblScene(); - void Update() final; + void Update(float dt) final; protected: void LoadResources() final; diff --git a/tests/demo/scene_sponza.cpp b/tests/demo/scene_sponza.cpp index 98311521..98dcdf82 100644 --- a/tests/demo/scene_sponza.cpp +++ b/tests/demo/scene_sponza.cpp @@ -40,8 +40,8 @@ void SponzaScene::BuildScene(unsigned int width, unsigned int height, void* extr LoadLightsFromJSON(); } -void SponzaScene::Update() +void SponzaScene::Update(float dt) { - m_camera->Update(ImGui::GetIO().DeltaTime); - m_camera_spline_node->UpdateSplineNode(ImGui::GetIO().DeltaTime, m_camera); + m_camera->Update(dt); + m_camera_spline_node->UpdateSplineNode(dt, m_camera); } \ No newline at end of file diff --git a/tests/demo/scene_sponza.hpp b/tests/demo/scene_sponza.hpp index 7a15d390..4fe54c05 100644 --- a/tests/demo/scene_sponza.hpp +++ b/tests/demo/scene_sponza.hpp @@ -15,7 +15,7 @@ class SponzaScene : public Scene public: SponzaScene(); - void Update() final; + void Update(float dt) final; protected: void LoadResources() final; diff --git a/tests/demo/scene_viknell.cpp b/tests/demo/scene_viknell.cpp index c89f32c0..40d07f11 100644 --- a/tests/demo/scene_viknell.cpp +++ b/tests/demo/scene_viknell.cpp @@ -113,8 +113,8 @@ void ViknellScene::BuildScene(unsigned int width, unsigned int height, void* ext LoadLightsFromJSON(); } -void ViknellScene::Update() +void ViknellScene::Update(float dt) { - m_camera->Update(ImGui::GetIO().DeltaTime); - m_camera_spline_node->UpdateSplineNode(ImGui::GetIO().DeltaTime, m_camera); + m_camera->Update(dt); + m_camera_spline_node->UpdateSplineNode(dt, m_camera); } \ No newline at end of file diff --git a/tests/demo/scene_viknell.hpp b/tests/demo/scene_viknell.hpp index 8a33fc7f..09cadcf4 100644 --- a/tests/demo/scene_viknell.hpp +++ b/tests/demo/scene_viknell.hpp @@ -15,7 +15,7 @@ class ViknellScene : public Scene public: ViknellScene(); - void Update() final; + void Update(float dt) final; protected: void LoadResources() final; diff --git a/tests/graphics_benchmark/spheres_scene.cpp b/tests/graphics_benchmark/spheres_scene.cpp index 1c41ade0..a9a1fd7b 100644 --- a/tests/graphics_benchmark/spheres_scene.cpp +++ b/tests/graphics_benchmark/spheres_scene.cpp @@ -61,7 +61,7 @@ void SpheresScene::BuildScene(unsigned int width, unsigned int height) dir_light->SetDirectional({ 136._deg, 0, 0 }, { 4, 4, 4 }); } -void SpheresScene::Update() +void SpheresScene::Update(float dt) { } diff --git a/tests/graphics_benchmark/spheres_scene.hpp b/tests/graphics_benchmark/spheres_scene.hpp index c4f12a98..03e4adca 100644 --- a/tests/graphics_benchmark/spheres_scene.hpp +++ b/tests/graphics_benchmark/spheres_scene.hpp @@ -7,7 +7,7 @@ class SpheresScene : public Scene public: SpheresScene(); - void Update() final; + void Update(float dt) final; protected: void LoadResources() final; From fb7bc208334b33d9a58b0ee52064eab618403e4c Mon Sep 17 00:00:00 2001 From: niels win10 Date: Mon, 17 Jun 2019 14:59:16 +0200 Subject: [PATCH 3/8] Added error checking to CoInit --- tests/demo/demo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/demo/demo.cpp b/tests/demo/demo.cpp index 75110b5a..4b055840 100644 --- a/tests/demo/demo.cpp +++ b/tests/demo/demo.cpp @@ -114,7 +114,7 @@ int WispEntry() wr::ModelLoader* assimp_model_loader = new wr::AssimpModelLoader(); wr::ModelLoader* gltf_model_loader = new wr::TinyGLTFModelLoader(); - CoInitialize(nullptr); + TRY_M(CoInitialize(nullptr), "Couldn't CoInitialize"); render_system->Init(window.get()); phys_engine.CreatePhysicsWorld(); From 886e1608500f5ab133bdadbd9c80448a61436596 Mon Sep 17 00:00:00 2001 From: niels win10 Date: Mon, 17 Jun 2019 15:22:58 +0200 Subject: [PATCH 4/8] Added frame counter for headless; functions almost the same as frame idx. Added resize to use valid aspect ratio --- src/d3d12/d3d12_renderer.cpp | 5 +++-- src/d3d12/d3d12_renderer.hpp | 1 + src/window.cpp | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/d3d12/d3d12_renderer.cpp b/src/d3d12/d3d12_renderer.cpp index 1a890fdf..b6c1e7a1 100644 --- a/src/d3d12/d3d12_renderer.cpp +++ b/src/d3d12/d3d12_renderer.cpp @@ -282,6 +282,8 @@ namespace wr // Optional CPU-visible copy of the render target pixel data const auto cpu_output_texture = frame_graph.GetOutputTexture(); + ++frame_counter; + // Optional CPU-visible copy of the render target pixel and/or depth data return frame_graph.GetOutputTexture(); } @@ -1251,8 +1253,7 @@ namespace wr } else { - LOGW("Called `D3D12RenderSystem::GetFrameIdx` without a window!"); - return 0; + return frame_counter % 3; } } diff --git a/src/d3d12/d3d12_renderer.hpp b/src/d3d12/d3d12_renderer.hpp index eb9de7d1..03e6fd39 100644 --- a/src/d3d12/d3d12_renderer.hpp +++ b/src/d3d12/d3d12_renderer.hpp @@ -270,6 +270,7 @@ namespace wr MaterialHandle m_last_material = { nullptr, 0 }; bool m_skybox_changed = false; + std::uint32_t frame_counter = 0; }; diff --git a/src/window.cpp b/src/window.cpp index 57207795..d3b1f0d8 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -101,6 +101,7 @@ namespace wr if (!m_has_time_point) { dt = 0; + m_resize_callback(m_window_width, m_window_height); m_has_time_point = true; } From 9b98d1e7d17665053417ecbd031596b0c3a7abbe Mon Sep 17 00:00:00 2001 From: niels win10 Date: Mon, 17 Jun 2019 15:26:08 +0200 Subject: [PATCH 5/8] Resize callback validation --- src/window.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/window.cpp b/src/window.cpp index d3b1f0d8..72254491 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -101,8 +101,11 @@ namespace wr if (!m_has_time_point) { dt = 0; - m_resize_callback(m_window_width, m_window_height); m_has_time_point = true; + + if (m_resize_callback) { + m_resize_callback(m_window_width, m_window_height); + } } m_prev_time = std::chrono::high_resolution_clock::now(); From 28b4b02b55703718366da40b3b183b2e07c0e7ba Mon Sep 17 00:00:00 2001 From: niels win10 Date: Mon, 17 Jun 2019 15:27:15 +0200 Subject: [PATCH 6/8] Removed TODO --- src/window.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/window.cpp b/src/window.cpp index 72254491..cf8212af 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -196,7 +196,7 @@ namespace wr void Window::SetResizeCallback(ResizeCallback callback) { - m_resize_callback = std::move(callback); //TODO: Call once? + m_resize_callback = std::move(callback); } bool Window::IsRunning() const From c7841f7d5eb1631a903d0cf347ebb8570ad27418 Mon Sep 17 00:00:00 2001 From: niels win10 Date: Tue, 18 Jun 2019 16:56:36 +0200 Subject: [PATCH 7/8] Changed num back buffers to match --- src/d3d12/d3d12_renderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d3d12/d3d12_renderer.cpp b/src/d3d12/d3d12_renderer.cpp index b6c1e7a1..bcd1ce80 100644 --- a/src/d3d12/d3d12_renderer.cpp +++ b/src/d3d12/d3d12_renderer.cpp @@ -1253,7 +1253,7 @@ namespace wr } else { - return frame_counter % 3; + return frame_counter % d3d12::settings::num_back_buffers; } } From aa82354d8bbb9d1c342c6b2d56c90869d6df55e6 Mon Sep 17 00:00:00 2001 From: BNiels Date: Thu, 20 Jun 2019 10:47:07 +0200 Subject: [PATCH 8/8] Now supporting variable number of backbuffers (1 or 3). --- src/render_tasks/d3d12_path_tracer.hpp | 13 ++++++------- src/render_tasks/d3d12_raytracing_task.hpp | 14 ++++++-------- src/render_tasks/d3d12_rt_hybrid_helpers.hpp | 6 +++--- src/render_tasks/d3d12_rtao_task.hpp | 11 +++++------ 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/render_tasks/d3d12_path_tracer.hpp b/src/render_tasks/d3d12_path_tracer.hpp index 3da8d9c4..bce4e662 100644 --- a/src/render_tasks/d3d12_path_tracer.hpp +++ b/src/render_tasks/d3d12_path_tracer.hpp @@ -22,9 +22,9 @@ namespace wr d3d12::AccelerationStructure out_tlas = {}; // Shader tables - std::array out_raygen_shader_table = { nullptr, nullptr, nullptr }; - std::array out_miss_shader_table = { nullptr, nullptr, nullptr }; - std::array out_hitgroup_shader_table = { nullptr, nullptr, nullptr }; + std::array out_raygen_shader_table = { }; + std::array out_miss_shader_table = { }; + std::array out_hitgroup_shader_table = { }; // Pipeline objects d3d12::StateObject* out_state_object = nullptr; @@ -178,10 +178,9 @@ namespace wr auto& rt_registry = RTPipelineRegistry::Get(); data.out_state_object = static_cast(rt_registry.Find(state_objects::path_tracer_state_object)); - // Create Shader Tables - CreateShaderTables(device, data, 0); - CreateShaderTables(device, data, 1); - CreateShaderTables(device, data, 2); + // Create Shader Tables + for (int i = 0; i < d3d12::settings::num_back_buffers; ++i) + CreateShaderTables(device, data, i); } } diff --git a/src/render_tasks/d3d12_raytracing_task.hpp b/src/render_tasks/d3d12_raytracing_task.hpp index 77eef6d4..b5d535a5 100644 --- a/src/render_tasks/d3d12_raytracing_task.hpp +++ b/src/render_tasks/d3d12_raytracing_task.hpp @@ -23,9 +23,9 @@ namespace wr { d3d12::AccelerationStructure out_tlas; - std::array out_raygen_shader_table = { nullptr, nullptr, nullptr }; - std::array out_miss_shader_table = { nullptr, nullptr, nullptr }; - std::array out_hitgroup_shader_table = { nullptr, nullptr, nullptr }; + std::array out_raygen_shader_table = { }; + std::array out_miss_shader_table = { }; + std::array out_hitgroup_shader_table = { }; d3d12::StateObject* out_state_object = nullptr; d3d12::RootSignature* out_root_signature = nullptr; D3D12ConstantBufferHandle* out_cb_camera_handle = nullptr; @@ -136,15 +136,13 @@ namespace wr data.tlas_requires_init = true; - CreateShaderTables(device, data, 0); - CreateShaderTables(device, data, 1); - CreateShaderTables(device, data, 2); + for(int i = 0; i < d3d12::settings::num_back_buffers; ++i) + CreateShaderTables(device, data, i); } - for (auto frame_idx = 0; frame_idx < 1; frame_idx++) { d3d12::DescHeapCPUHandle desc_handle = data.out_uav_from_rtv.GetDescriptorHandle(); - d3d12::CreateUAVFromSpecificRTV(n_render_target, desc_handle, frame_idx, n_render_target->m_create_info.m_rtv_formats[frame_idx]); + d3d12::CreateUAVFromSpecificRTV(n_render_target, desc_handle, 0, n_render_target->m_create_info.m_rtv_formats[0]); } } diff --git a/src/render_tasks/d3d12_rt_hybrid_helpers.hpp b/src/render_tasks/d3d12_rt_hybrid_helpers.hpp index 8c5fd939..5b85e4e4 100644 --- a/src/render_tasks/d3d12_rt_hybrid_helpers.hpp +++ b/src/render_tasks/d3d12_rt_hybrid_helpers.hpp @@ -25,9 +25,9 @@ namespace wr d3d12::AccelerationStructure out_tlas = {}; // Shader tables - std::array out_raygen_shader_table = { nullptr, nullptr, nullptr }; - std::array out_miss_shader_table = { nullptr, nullptr, nullptr }; - std::array out_hitgroup_shader_table = { nullptr, nullptr, nullptr }; + std::array out_raygen_shader_table = { }; + std::array out_miss_shader_table = { }; + std::array out_hitgroup_shader_table = { }; // Pipeline objects diff --git a/src/render_tasks/d3d12_rtao_task.hpp b/src/render_tasks/d3d12_rtao_task.hpp index d3455997..1d6af6b5 100644 --- a/src/render_tasks/d3d12_rtao_task.hpp +++ b/src/render_tasks/d3d12_rtao_task.hpp @@ -35,9 +35,9 @@ namespace wr d3d12::AccelerationStructure out_tlas = {}; // Shader tables - std::array in_raygen_shader_table = { nullptr, nullptr, nullptr }; - std::array in_miss_shader_table = { nullptr, nullptr, nullptr }; - std::array in_hitgroup_shader_table = { nullptr, nullptr, nullptr }; + std::array in_raygen_shader_table = { }; + std::array in_miss_shader_table = { }; + std::array in_hitgroup_shader_table = { }; // Pipeline objects d3d12::StateObject* in_state_object; @@ -149,9 +149,8 @@ namespace wr data.in_root_signature = static_cast(rs_registry.Find(root_signatures::rt_ao_global)); // Create Shader Tables - CreateShaderTables(device, data, 0); - CreateShaderTables(device, data, 1); - CreateShaderTables(device, data, 2); + for (int i = 0; i < d3d12::settings::num_back_buffers; ++i) + CreateShaderTables(device, data, i); } }