From de5f61f8c738a68433eaa39f85843fcaea57c070 Mon Sep 17 00:00:00 2001 From: Martin Felke Date: Sun, 4 Jun 2023 22:40:13 +0200 Subject: [PATCH] fixed calculation, ui look and behavior, and compile errors --- src/common/settings.cpp | 4 +-- src/common/settings.h | 4 ++- .../renderer_opengl/gl_buffer_cache.cpp | 2 +- src/video_core/renderer_opengl/gl_device.cpp | 15 +++++--- src/video_core/renderer_opengl/gl_device.h | 2 ++ .../renderer_opengl/gl_texture_cache.cpp | 2 +- .../vulkan_common/vulkan_device.cpp | 3 +- src/yuzu/configuration/config.cpp | 4 +++ .../configure_graphics_advanced.cpp | 24 +++++++++---- .../configure_graphics_advanced.ui | 36 ++++++++++--------- 10 files changed, 62 insertions(+), 34 deletions(-) diff --git a/src/common/settings.cpp b/src/common/settings.cpp index c97784f17d..6575769fe0 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -238,8 +238,8 @@ void RestoreGlobalState(bool is_powered_on) { values.bg_green.SetGlobal(true); values.bg_blue.SetGlobal(true); values.enable_compute_pipelines.SetGlobal(true); - values.use_vram_percentage(true); - values.vram_percentage(25); + values.use_vram_percentage.SetGlobal(true); + values.vram_percentage.SetGlobal(true); // System values.language_index.SetGlobal(true); diff --git a/src/common/settings.h b/src/common/settings.h index 41a21871c4..c6a31b530e 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -487,7 +487,7 @@ struct Values { SwitchableSetting bg_green{0, "bg_green"}; SwitchableSetting bg_blue{0, "bg_blue"}; - SwitchableSetting use_vram_percentage{true, "use_vram_percentage"}; + SwitchableSetting use_vram_percentage{true, "use_vram_percentage"}; SwitchableSetting vram_percentage{25, 10, 90, "vram_percentage"}; // System @@ -615,4 +615,6 @@ void UpdateRescalingInfo(); // Restore the global state of all applicable settings in the Values struct void RestoreGlobalState(bool is_powered_on); +u64 RAM_Percent_to_Byte(u8 percent); + } // namespace Settings diff --git a/src/video_core/renderer_opengl/gl_buffer_cache.cpp b/src/video_core/renderer_opengl/gl_buffer_cache.cpp index fa3c1aaa47..aee69c9bfc 100644 --- a/src/video_core/renderer_opengl/gl_buffer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_buffer_cache.cpp @@ -142,7 +142,7 @@ BufferCacheRuntime::BufferCacheRuntime(const Device& device_) u64 BufferCacheRuntime::GetDeviceMemoryUsage() const { if (device.CanReportMemoryUsage()) { - return device_access_memory - device.GetCurrentDedicatedVideoMemory(); + return device.GetTotalDedicatedVideoMemory() - device.GetCurrentDedicatedVideoMemory(); } return 2_GiB; } diff --git a/src/video_core/renderer_opengl/gl_device.cpp b/src/video_core/renderer_opengl/gl_device.cpp index 2c8c4a3f53..b0f106bdfd 100644 --- a/src/video_core/renderer_opengl/gl_device.cpp +++ b/src/video_core/renderer_opengl/gl_device.cpp @@ -289,10 +289,16 @@ u64 Device::GetTotalDedicatedVideoMemory() const { // this should report the correct size of the VRAM, on integrated devices it shows the size of // the UMA Framebuffer glGetIntegerv(GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &tot_avail_mem_kb); - // LOG_INFO(Render_OpenGL, "total VRAM: {} GB", tot_avail_mem_kb / f64{1_MiB}); - f64 percent = Settings::values.vram_percentage.GetValue(); - u64 vram = Settings::RAM_Percent_to_Byte(percent); - return static_cast(tot_avail_mem_kb) * 1_KiB + vram; + + if (Settings::values.use_vram_percentage.GetValue()) { + u8 percent = Settings::values.vram_percentage.GetValue(); + return Settings::RAM_Percent_to_Byte(percent); + } + else { + // this is according to both former settings in the gl_buffer_cache + // and gl_texture_cache, regarding device_access_memory + return static_cast(tot_avail_mem_kb) * 1_KiB + 512_MiB; + } } @@ -300,7 +306,6 @@ u64 Device::GetCurrentDedicatedVideoMemory() const { GLint cur_avail_mem_kb = 0; // this should report the currently available video memory glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &cur_avail_mem_kb); - // LOG_INFO(Render_OpenGL, "current VRAM: {} GB", cur_avail_mem_kb / f64{1_MiB}); return static_cast(cur_avail_mem_kb) * 1_KiB; } diff --git a/src/video_core/renderer_opengl/gl_device.h b/src/video_core/renderer_opengl/gl_device.h index cc0b95f1a5..71e00f3933 100644 --- a/src/video_core/renderer_opengl/gl_device.h +++ b/src/video_core/renderer_opengl/gl_device.h @@ -22,6 +22,8 @@ public: [[nodiscard]] std::string GetVendorName() const; + u64 GetTotalDedicatedVideoMemory() const; + u64 GetCurrentDedicatedVideoMemory() const; u32 GetMaxUniformBuffers(Shader::Stage stage) const noexcept { diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp index 33cfe020ef..43f9713f97 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.cpp +++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp @@ -568,7 +568,7 @@ ImageBufferMap TextureCacheRuntime::DownloadStagingBuffer(size_t size) { u64 TextureCacheRuntime::GetDeviceMemoryUsage() const { if (device.CanReportMemoryUsage()) { - return device_access_memory - device.GetCurrentDedicatedVideoMemory(); + return device.GetTotalDedicatedVideoMemory() - device.GetCurrentDedicatedVideoMemory(); } return 2_GiB; } diff --git a/src/video_core/vulkan_common/vulkan_device.cpp b/src/video_core/vulkan_common/vulkan_device.cpp index 7dd850d747..26a470982a 100644 --- a/src/video_core/vulkan_common/vulkan_device.cpp +++ b/src/video_core/vulkan_common/vulkan_device.cpp @@ -1041,8 +1041,9 @@ void Device::CollectPhysicalMemoryInfo() { } const u8 percent = Settings::values.vram_percentage.GetValue(); const s64 available_memory = static_cast(device_access_memory - device_initial_usage); + const s64 limit = Settings::values.use_vram_percentage.GetValue() ? Settings::RAM_Percent_to_Byte(percent) : 4_GiB; device_access_memory = static_cast(std::max( - std::min(available_memory - 8_GiB, 4_GiB), std::min(local_memory, Settings::RAM_Percent_to_Byte(percent))); + std::min(available_memory - 8_GiB, 4_GiB), std::min(local_memory, limit))); } void Device::CollectToolingInfo() { diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 6288fef626..072deaf4c1 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -757,6 +757,8 @@ void Config::ReadRendererValues() { ReadGlobalSetting(Settings::values.bg_red); ReadGlobalSetting(Settings::values.bg_green); ReadGlobalSetting(Settings::values.bg_blue); + ReadGlobalSetting(Settings::values.use_vram_percentage); + ReadGlobalSetting(Settings::values.vram_percentage); if (global) { Settings::values.vsync_mode.SetValue(static_cast( @@ -1412,6 +1414,8 @@ void Config::SaveRendererValues() { WriteGlobalSetting(Settings::values.bg_red); WriteGlobalSetting(Settings::values.bg_green); WriteGlobalSetting(Settings::values.bg_blue); + WriteGlobalSetting(Settings::values.use_vram_percentage); + WriteGlobalSetting(Settings::values.vram_percentage); if (global) { WriteSetting(QString::fromStdString(Settings::values.vsync_mode.GetLabel()), diff --git a/src/yuzu/configuration/configure_graphics_advanced.cpp b/src/yuzu/configuration/configure_graphics_advanced.cpp index 46e378514a..39472dbc82 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.cpp +++ b/src/yuzu/configuration/configure_graphics_advanced.cpp @@ -31,6 +31,7 @@ void ConfigureGraphicsAdvanced::SetConfiguration() { ui->use_asynchronous_shaders->setEnabled(runtime_lock); ui->anisotropic_filtering_combobox->setEnabled(runtime_lock); ui->enable_compute_pipelines_checkbox->setEnabled(runtime_lock); + ui->use_vram_percentage->setEnabled(runtime_lock); ui->async_present->setChecked(Settings::values.async_presentation.GetValue()); ui->renderer_force_max_clock->setChecked(Settings::values.renderer_force_max_clock.GetValue()); @@ -43,7 +44,15 @@ void ConfigureGraphicsAdvanced::SetConfiguration() { ui->enable_compute_pipelines_checkbox->setChecked( Settings::values.enable_compute_pipelines.GetValue()); ui->use_vram_percentage->setChecked(Settings::values.use_vram_percentage.GetValue()); - ui->vram_percentage->setVisible(Settings::values.use_vram_percentage.GetValue()); + + if (Settings::IsConfiguringGlobal()) { + ui->vram_percentage->setEnabled(Settings::values.use_vram_percentage.GetValue() && runtime_lock); + } else { + ui->vram_percentage->setEnabled(Settings::values.use_vram_percentage.GetValue() && + use_vram_percentage != ConfigurationShared::CheckState::Global && runtime_lock); + } + + ui->vram_percentage->setValue(Settings::values.vram_percentage.GetValue()); if (Settings::IsConfiguringGlobal()) { @@ -65,6 +74,7 @@ void ConfigureGraphicsAdvanced::SetConfiguration() { !Settings::values.max_anisotropy.UsingGlobal()); ConfigurationShared::SetHighlight(ui->label_astc_recompression, !Settings::values.astc_recompression.UsingGlobal()); + ConfigurationShared::SetHighlight(ui->vram_percentage, !Settings::values.vram_percentage.UsingGlobal()); } } @@ -97,9 +107,7 @@ void ConfigureGraphicsAdvanced::ApplyConfiguration() { ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_vram_percentage, ui->use_vram_percentage, use_vram_percentage); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.vram_percentage, - ui->vram_percentage, - vram_percentage); + Settings::values.vram_percentage.SetValue(ui->vram_percentage->value()); } void ConfigureGraphicsAdvanced::changeEvent(QEvent* event) { @@ -170,9 +178,11 @@ void ConfigureGraphicsAdvanced::SetupPerGameUI() { ConfigurationShared::SetColoredTristate(ui->use_vram_percentage, Settings::values.use_vram_percentage, use_vram_percentage); - ConfigurationShared::SetColoredTristate(ui->vram_percentage, - Settings::values.vram_percentage, - vram_percentage); + + connect(ui->use_vram_percentage, &QCheckBox::clicked, ui->vram_percentage, [this]() { + ui->vram_percentage->setEnabled(ui->use_vram_percentage->isChecked() && + (use_vram_percentage != ConfigurationShared::CheckState::Global)); + }); } void ConfigureGraphicsAdvanced::ExposeComputeOption() { diff --git a/src/yuzu/configuration/configure_graphics_advanced.ui b/src/yuzu/configuration/configure_graphics_advanced.ui index 904f284a5e..7b0d09532a 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.ui +++ b/src/yuzu/configuration/configure_graphics_advanced.ui @@ -247,14 +247,19 @@ Compute pipelines are always enabled on all other drivers. - - - - Assign the given percentage of the total shared RAM as VRAM - - - Assign RAM percentage as VRAM (Integrated devices only) - + + + + + + + + + Assign the given % of the total shared RAM as VRAM + + + Assign % of RAM as VRAM (Integrated devices only) + @@ -265,7 +270,7 @@ Compute pipelines are always enabled on all other drivers. 10 - + 90 @@ -274,13 +279,12 @@ Compute pipelines are always enabled on all other drivers. - - - - - - - + + + + + +