From 096a92ba84dc31678af96168917d7121868af016 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 11 Jul 2021 13:21:41 +1000 Subject: [PATCH] GPU/HW: Simplify shader compile progress updates --- src/core/gpu_hw.cpp | 19 ++++++++++++++++ src/core/gpu_hw.h | 17 +++++++++++++++ src/core/gpu_hw_d3d11.cpp | 44 ++++++++++++-------------------------- src/core/gpu_hw_d3d12.cpp | 36 +++++++++++-------------------- src/core/gpu_hw_opengl.cpp | 34 ++++++++--------------------- src/core/gpu_hw_vulkan.cpp | 41 +++++++++++------------------------ 6 files changed, 84 insertions(+), 107 deletions(-) diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp index d66d2514e..cd80ab8e7 100644 --- a/src/core/gpu_hw.cpp +++ b/src/core/gpu_hw.cpp @@ -1464,3 +1464,22 @@ void GPU_HW::DrawRendererStats(bool is_idle_frame) } #endif } + +GPU_HW::ShaderCompileProgressTracker::ShaderCompileProgressTracker(std::string title, u32 total) + : m_title(std::move(title)), m_min_time(Common::Timer::ConvertSecondsToValue(1.0)), + m_update_interval(Common::Timer::ConvertSecondsToValue(0.1)), m_start_time(Common::Timer::GetValue()), + m_last_update_time(0), m_progress(0), m_total(total) +{ +} + +void GPU_HW::ShaderCompileProgressTracker::Increment() +{ + m_progress++; + + const u64 tv = Common::Timer::GetValue(); + if ((tv - m_start_time) >= m_min_time && (tv - m_last_update_time) >= m_update_interval) + { + g_host_interface->DisplayLoadingScreen(m_title.c_str(), 0, static_cast(m_total), static_cast(m_progress)); + m_last_update_time = tv; + } +} diff --git a/src/core/gpu_hw.h b/src/core/gpu_hw.h index 6faa58027..7b8199825 100644 --- a/src/core/gpu_hw.h +++ b/src/core/gpu_hw.h @@ -163,6 +163,23 @@ protected: u32 num_uniform_buffer_updates; }; + class ShaderCompileProgressTracker + { + public: + ShaderCompileProgressTracker(std::string title, u32 total); + + void Increment(); + + private: + std::string m_title; + u64 m_start_time; + u64 m_last_update_time; + u64 m_min_time; + u64 m_update_interval; + u32 m_progress; + u32 m_total; + }; + static constexpr std::tuple RGBA8ToFloat(u32 rgba) { return std::make_tuple(static_cast(rgba & UINT32_C(0xFF)) * (1.0f / 255.0f), diff --git a/src/core/gpu_hw_d3d11.cpp b/src/core/gpu_hw_d3d11.cpp index fb168c92e..0040b1677 100644 --- a/src/core/gpu_hw_d3d11.cpp +++ b/src/core/gpu_hw_d3d11.cpp @@ -508,23 +508,7 @@ bool GPU_HW_D3D11::CompileShaders() m_true_color, m_scaled_dithering, m_texture_filtering, m_using_uv_limits, m_pgxp_depth_buffer, m_supports_dual_source_blend); - Common::Timer compile_time; - const int progress_total = 1 + 1 + 2 + (4 * 9 * 2 * 2) + 7 + (2 * 3) + 1; - int progress_value = 0; -#define UPDATE_PROGRESS() \ - do \ - { \ - progress_value++; \ - if (System::IsStartupCancelled()) \ - { \ - return false; \ - } \ - if (compile_time.GetTimeSeconds() >= 1.0f) \ - { \ - compile_time.Reset(); \ - g_host_interface->DisplayLoadingScreen("Compiling Shaders", 0, progress_total, progress_value); \ - } \ - } while (0) + ShaderCompileProgressTracker progress("Compiling Shaders", 1 + 1 + 2 + (4 * 9 * 2 * 2) + 7 + (2 * 3) + 1); // input layout { @@ -552,7 +536,7 @@ bool GPU_HW_D3D11::CompileShaders() } } - UPDATE_PROGRESS(); + progress.Increment(); m_screen_quad_vertex_shader = shader_cache.GetVertexShader(m_device.Get(), shadergen.GenerateScreenQuadVertexShader()); @@ -560,7 +544,7 @@ bool GPU_HW_D3D11::CompileShaders() if (!m_screen_quad_vertex_shader || !m_uv_quad_vertex_shader) return false; - UPDATE_PROGRESS(); + progress.Increment(); for (u8 textured = 0; textured < 2; textured++) { @@ -569,7 +553,7 @@ bool GPU_HW_D3D11::CompileShaders() if (!m_batch_vertex_shaders[textured]) return false; - UPDATE_PROGRESS(); + progress.Increment(); } for (u8 render_mode = 0; render_mode < 4; render_mode++) @@ -589,7 +573,7 @@ bool GPU_HW_D3D11::CompileShaders() if (!m_batch_pixel_shaders[render_mode][texture_mode][dithering][interlacing]) return false; - UPDATE_PROGRESS(); + progress.Increment(); } } } @@ -599,46 +583,46 @@ bool GPU_HW_D3D11::CompileShaders() if (!m_copy_pixel_shader) return false; - UPDATE_PROGRESS(); + progress.Increment(); m_vram_fill_pixel_shader = shader_cache.GetPixelShader(m_device.Get(), shadergen.GenerateFillFragmentShader()); if (!m_vram_fill_pixel_shader) return false; - UPDATE_PROGRESS(); + progress.Increment(); m_vram_interlaced_fill_pixel_shader = shader_cache.GetPixelShader(m_device.Get(), shadergen.GenerateInterlacedFillFragmentShader()); if (!m_vram_interlaced_fill_pixel_shader) return false; - UPDATE_PROGRESS(); + progress.Increment(); m_vram_read_pixel_shader = shader_cache.GetPixelShader(m_device.Get(), shadergen.GenerateVRAMReadFragmentShader()); if (!m_vram_read_pixel_shader) return false; - UPDATE_PROGRESS(); + progress.Increment(); m_vram_write_pixel_shader = shader_cache.GetPixelShader(m_device.Get(), shadergen.GenerateVRAMWriteFragmentShader(false)); if (!m_vram_write_pixel_shader) return false; - UPDATE_PROGRESS(); + progress.Increment(); m_vram_copy_pixel_shader = shader_cache.GetPixelShader(m_device.Get(), shadergen.GenerateVRAMCopyFragmentShader()); if (!m_vram_copy_pixel_shader) return false; - UPDATE_PROGRESS(); + progress.Increment(); m_vram_update_depth_pixel_shader = shader_cache.GetPixelShader(m_device.Get(), shadergen.GenerateVRAMUpdateDepthFragmentShader()); if (!m_vram_update_depth_pixel_shader) return false; - UPDATE_PROGRESS(); + progress.Increment(); for (u8 depth_24bit = 0; depth_24bit < 2; depth_24bit++) { @@ -651,7 +635,7 @@ bool GPU_HW_D3D11::CompileShaders() if (!m_display_pixel_shaders[depth_24bit][interlacing]) return false; - UPDATE_PROGRESS(); + progress.Increment(); } } @@ -680,7 +664,7 @@ bool GPU_HW_D3D11::CompileShaders() return false; } - UPDATE_PROGRESS(); + progress.Increment(); #undef UPDATE_PROGRESS diff --git a/src/core/gpu_hw_d3d12.cpp b/src/core/gpu_hw_d3d12.cpp index f09a9eda9..e2962f777 100644 --- a/src/core/gpu_hw_d3d12.cpp +++ b/src/core/gpu_hw_d3d12.cpp @@ -419,19 +419,8 @@ bool GPU_HW_D3D12::CompilePipelines() m_true_color, m_scaled_dithering, m_texture_filtering, m_using_uv_limits, m_pgxp_depth_buffer, m_supports_dual_source_blend); - Common::Timer compile_time; - const int progress_total = 2 + (4 * 9 * 2 * 2) + (2 * 4 * 5 * 9 * 2 * 2) + 1 + 2 + 2 + 2 + 1 + 1 + (2 * 3); - int progress_value = 0; -#define UPDATE_PROGRESS() \ - do \ - { \ - progress_value++; \ - if (compile_time.GetTimeSeconds() >= 1.0f) \ - { \ - compile_time.Reset(); \ - g_host_interface->DisplayLoadingScreen("Compiling Shaders", 0, progress_total, progress_value); \ - } \ - } while (0) + ShaderCompileProgressTracker progress("Compiling Pipelines", 2 + (4 * 9 * 2 * 2) + (2 * 4 * 5 * 9 * 2 * 2) + 1 + 2 + + 2 + 2 + 1 + 1 + (2 * 3)); // vertex shaders - [textured] // fragment shaders - [render_mode][texture_mode][dithering][interlacing] @@ -445,7 +434,7 @@ bool GPU_HW_D3D12::CompilePipelines() if (!batch_vertex_shaders[textured]) return false; - UPDATE_PROGRESS(); + progress.Increment(); } for (u8 render_mode = 0; render_mode < 4; render_mode++) @@ -464,7 +453,7 @@ bool GPU_HW_D3D12::CompilePipelines() if (!batch_fragment_shaders[render_mode][texture_mode][dithering][interlacing]) return false; - UPDATE_PROGRESS(); + progress.Increment(); } } } @@ -542,7 +531,7 @@ bool GPU_HW_D3D12::CompilePipelines() "Batch Pipeline %u,%u,%u,%u,%u,%u", depth_test, render_mode, texture_mode, transparency_mode, dithering, interlacing); - UPDATE_PROGRESS(); + progress.Increment(); } } } @@ -555,7 +544,7 @@ bool GPU_HW_D3D12::CompilePipelines() if (!fullscreen_quad_vertex_shader) return false; - UPDATE_PROGRESS(); + progress.Increment(); // common state gpbuilder.SetRootSignature(m_single_sampler_root_signature.Get()); @@ -589,7 +578,7 @@ bool GPU_HW_D3D12::CompilePipelines() D3D12::SetObjectNameFormatted(m_vram_fill_pipelines[interlaced].Get(), "VRAM Fill Pipeline Interlacing=%u", interlaced); - UPDATE_PROGRESS(); + progress.Increment(); } } @@ -611,7 +600,7 @@ bool GPU_HW_D3D12::CompilePipelines() D3D12::SetObjectNameFormatted(m_vram_copy_pipelines[depth_test].Get(), "VRAM Copy Pipeline Depth=%u", depth_test); - UPDATE_PROGRESS(); + progress.Increment(); } } @@ -633,7 +622,7 @@ bool GPU_HW_D3D12::CompilePipelines() D3D12::SetObjectNameFormatted(m_vram_write_pipelines[depth_test].Get(), "VRAM Write Pipeline Depth=%u", depth_test); - UPDATE_PROGRESS(); + progress.Increment(); } } @@ -656,7 +645,7 @@ bool GPU_HW_D3D12::CompilePipelines() D3D12::SetObjectName(m_vram_update_depth_pipeline.Get(), "VRAM Update Depth Pipeline"); - UPDATE_PROGRESS(); + progress.Increment(); } gpbuilder.Clear(); @@ -683,7 +672,7 @@ bool GPU_HW_D3D12::CompilePipelines() D3D12::SetObjectName(m_vram_update_depth_pipeline.Get(), "VRAM Readback Pipeline"); - UPDATE_PROGRESS(); + progress.Increment(); } gpbuilder.Clear(); @@ -717,7 +706,7 @@ bool GPU_HW_D3D12::CompilePipelines() D3D12::SetObjectNameFormatted(m_display_pipelines[depth_24][interlace_mode].Get(), "Display Pipeline Depth=%u Interlace=%u", depth_24, interlace_mode); - UPDATE_PROGRESS(); + progress.Increment(); } } } @@ -1043,7 +1032,6 @@ void GPU_HW_D3D12::UpdateVRAMReadTexture() { ID3D12GraphicsCommandList* cmdlist = g_d3d12_context->GetCommandList(); - const auto scaled_rect = m_vram_dirty_rect * m_resolution_scale; if (m_vram_texture.IsMultisampled()) diff --git a/src/core/gpu_hw_opengl.cpp b/src/core/gpu_hw_opengl.cpp index 71e045cf1..94bd39582 100644 --- a/src/core/gpu_hw_opengl.cpp +++ b/src/core/gpu_hw_opengl.cpp @@ -517,23 +517,7 @@ bool GPU_HW_OpenGL::CompilePrograms() m_true_color, m_scaled_dithering, m_texture_filtering, m_using_uv_limits, m_pgxp_depth_buffer, m_supports_dual_source_blend); - Common::Timer compile_time; - const int progress_total = (4 * 9 * 2 * 2) + (2 * 3) + 1 + 1 + 1 + 1 + 1 + 1; - int progress_value = 0; -#define UPDATE_PROGRESS() \ - do \ - { \ - progress_value++; \ - if (System::IsStartupCancelled()) \ - { \ - return false; \ - } \ - if (compile_time.GetTimeSeconds() >= 1.0f) \ - { \ - compile_time.Reset(); \ - g_host_interface->DisplayLoadingScreen("Compiling Shaders", 0, progress_total, progress_value); \ - } \ - } while (0) + ShaderCompileProgressTracker progress("Compiling Programs", (4 * 9 * 2 * 2) + (2 * 3) + 1 + 1 + 1 + 1 + 1 + 1); for (u32 render_mode = 0; render_mode < 4; render_mode++) { @@ -592,7 +576,7 @@ bool GPU_HW_OpenGL::CompilePrograms() m_render_programs[render_mode][texture_mode][dithering][interlacing] = std::move(*prog); - UPDATE_PROGRESS(); + progress.Increment(); } } } @@ -621,7 +605,7 @@ bool GPU_HW_OpenGL::CompilePrograms() prog->Uniform1i("samp0", 0); } m_display_programs[depth_24bit][interlaced] = std::move(*prog); - UPDATE_PROGRESS(); + progress.Increment(); } } @@ -638,7 +622,7 @@ bool GPU_HW_OpenGL::CompilePrograms() prog->BindUniformBlock("UBOBlock", 1); m_vram_interlaced_fill_program = std::move(*prog); - UPDATE_PROGRESS(); + progress.Increment(); prog = shader_cache.GetProgram(shadergen.GenerateScreenQuadVertexShader(), {}, shadergen.GenerateVRAMReadFragmentShader(), @@ -656,7 +640,7 @@ bool GPU_HW_OpenGL::CompilePrograms() prog->Uniform1i("samp0", 0); } m_vram_read_program = std::move(*prog); - UPDATE_PROGRESS(); + progress.Increment(); prog = shader_cache.GetProgram(shadergen.GenerateScreenQuadVertexShader(), {}, shadergen.GenerateVRAMCopyFragmentShader(), @@ -674,7 +658,7 @@ bool GPU_HW_OpenGL::CompilePrograms() prog->Uniform1i("samp0", 0); } m_vram_copy_program = std::move(*prog); - UPDATE_PROGRESS(); + progress.Increment(); prog = shader_cache.GetProgram(shadergen.GenerateScreenQuadVertexShader(), {}, shadergen.GenerateVRAMUpdateDepthFragmentShader()); @@ -684,7 +668,7 @@ bool GPU_HW_OpenGL::CompilePrograms() prog->Bind(); prog->Uniform1i("samp0", 0); m_vram_update_depth_program = std::move(*prog); - UPDATE_PROGRESS(); + progress.Increment(); if (m_use_texture_buffer_for_vram_writes || m_use_ssbo_for_vram_writes) { @@ -706,7 +690,7 @@ bool GPU_HW_OpenGL::CompilePrograms() m_vram_write_program = std::move(*prog); } - UPDATE_PROGRESS(); + progress.Increment(); if (m_downsample_mode == GPUDownsampleMode::Box) { @@ -728,7 +712,7 @@ bool GPU_HW_OpenGL::CompilePrograms() m_downsample_program = std::move(*prog); } - UPDATE_PROGRESS(); + progress.Increment(); #undef UPDATE_PROGRESS return true; diff --git a/src/core/gpu_hw_vulkan.cpp b/src/core/gpu_hw_vulkan.cpp index d7c5dfad5..a13544d8c 100644 --- a/src/core/gpu_hw_vulkan.cpp +++ b/src/core/gpu_hw_vulkan.cpp @@ -839,23 +839,8 @@ bool GPU_HW_Vulkan::CompilePipelines() m_true_color, m_scaled_dithering, m_texture_filtering, m_using_uv_limits, m_pgxp_depth_buffer, m_supports_dual_source_blend); - Common::Timer compile_time; - const int progress_total = 2 + (4 * 9 * 2 * 2) + (3 * 4 * 5 * 9 * 2 * 2) + 1 + 2 + 2 + 2 + 1 + 1 + (2 * 3) + 1; - int progress_value = 0; -#define UPDATE_PROGRESS() \ - do \ - { \ - progress_value++; \ - if (System::IsStartupCancelled()) \ - { \ - return false; \ - } \ - if (compile_time.GetTimeSeconds() >= 1.0f) \ - { \ - compile_time.Reset(); \ - g_host_interface->DisplayLoadingScreen("Compiling Shaders", 0, progress_total, progress_value); \ - } \ - } while (0) + ShaderCompileProgressTracker progress("Compiling Pipelines", 2 + (4 * 9 * 2 * 2) + (3 * 4 * 5 * 9 * 2 * 2) + 1 + 2 + + 2 + 2 + 1 + 1 + (2 * 3) + 1); // vertex shaders - [textured] // fragment shaders - [render_mode][texture_mode][dithering][interlacing] @@ -874,7 +859,7 @@ bool GPU_HW_Vulkan::CompilePipelines() return false; batch_vertex_shaders[textured] = shader; - UPDATE_PROGRESS(); + progress.Increment(); } for (u8 render_mode = 0; render_mode < 4; render_mode++) @@ -894,7 +879,7 @@ bool GPU_HW_Vulkan::CompilePipelines() return false; batch_fragment_shaders[render_mode][texture_mode][dithering][interlacing] = shader; - UPDATE_PROGRESS(); + progress.Increment(); } } } @@ -986,7 +971,7 @@ bool GPU_HW_Vulkan::CompilePipelines() m_batch_pipelines[depth_test][render_mode][texture_mode][transparency_mode][dithering][interlacing] = pipeline; - UPDATE_PROGRESS(); + progress.Increment(); } } } @@ -1007,7 +992,7 @@ bool GPU_HW_Vulkan::CompilePipelines() return false; } - UPDATE_PROGRESS(); + progress.Increment(); Common::ScopeGuard fullscreen_quad_vertex_shader_guard([&fullscreen_quad_vertex_shader, &uv_quad_vertex_shader]() { vkDestroyShaderModule(g_vulkan_context->GetDevice(), fullscreen_quad_vertex_shader, nullptr); @@ -1042,7 +1027,7 @@ bool GPU_HW_Vulkan::CompilePipelines() if (m_vram_fill_pipelines[interlaced] == VK_NULL_HANDLE) return false; - UPDATE_PROGRESS(); + progress.Increment(); } } @@ -1066,7 +1051,7 @@ bool GPU_HW_Vulkan::CompilePipelines() return false; } - UPDATE_PROGRESS(); + progress.Increment(); } vkDestroyShaderModule(device, fs, nullptr); @@ -1091,7 +1076,7 @@ bool GPU_HW_Vulkan::CompilePipelines() return false; } - UPDATE_PROGRESS(); + progress.Increment(); } vkDestroyShaderModule(device, fs, nullptr); @@ -1115,7 +1100,7 @@ bool GPU_HW_Vulkan::CompilePipelines() if (m_vram_update_depth_pipeline == VK_NULL_HANDLE) return false; - UPDATE_PROGRESS(); + progress.Increment(); } gpbuilder.Clear(); @@ -1140,7 +1125,7 @@ bool GPU_HW_Vulkan::CompilePipelines() if (m_vram_readback_pipeline == VK_NULL_HANDLE) return false; - UPDATE_PROGRESS(); + progress.Increment(); } gpbuilder.Clear(); @@ -1171,7 +1156,7 @@ bool GPU_HW_Vulkan::CompilePipelines() if (m_display_pipelines[depth_24][interlace_mode] == VK_NULL_HANDLE) return false; - UPDATE_PROGRESS(); + progress.Increment(); } } } @@ -1253,7 +1238,7 @@ bool GPU_HW_Vulkan::CompilePipelines() return false; } - UPDATE_PROGRESS(); + progress.Increment(); #undef UPDATE_PROGRESS