From 8fe147b8f9da8976ce476d7e2c7af30549a6599f Mon Sep 17 00:00:00 2001 From: Wunk Date: Mon, 6 Nov 2023 13:38:54 -0800 Subject: [PATCH] video_core: Use binary memory-literals for memory-sizes (#7127) Replaces `... * 1024 * 1024` with `_MiB`/`_GiB` literals. --- src/video_core/custom_textures/custom_tex_manager.cpp | 7 +++++-- src/video_core/renderer_opengl/gl_rasterizer.cpp | 10 ++++++---- src/video_core/renderer_vulkan/vk_rasterizer.cpp | 8 +++++--- src/video_core/renderer_vulkan/vk_texture_runtime.cpp | 6 ++++-- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/video_core/custom_textures/custom_tex_manager.cpp b/src/video_core/custom_textures/custom_tex_manager.cpp index 18d69e129..da05b6e6d 100644 --- a/src/video_core/custom_textures/custom_tex_manager.cpp +++ b/src/video_core/custom_textures/custom_tex_manager.cpp @@ -4,6 +4,7 @@ #include #include "common/file_util.h" +#include "common/literals.h" #include "common/memory_detect.h" #include "common/microprofile.h" #include "common/settings.h" @@ -26,6 +27,8 @@ MICROPROFILE_DEFINE(CustomTexManager_TickFrame, "CustomTexManager", "TickFrame", constexpr std::size_t MAX_UPLOADS_PER_TICK = 8; +using namespace Common::Literals; + bool IsPow2(u32 value) { return value != 0 && (value & (value - 1)) == 0; } @@ -206,9 +209,9 @@ void CustomTexManager::PreloadTextures(const std::atomic_bool& stop_run, u64 size_sum = 0; size_t preloaded = 0; const u64 sys_mem = Common::GetMemInfo().total_physical_memory; - const u64 recommended_min_mem = 2 * size_t(1024 * 1024 * 1024); + const u64 recommended_min_mem = 2_GiB; - // keep 2GB memory for system stability if system RAM is 4GB+ - use half of memory in other + // keep 2GiB memory for system stability if system RAM is 4GiB+ - use half of memory in other // cases const u64 max_mem = (sys_mem / 2 < recommended_min_mem) ? (sys_mem / 2) : (sys_mem - recommended_min_mem); diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index d9c3bbf66..640d8fbc5 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -4,6 +4,7 @@ #include "common/alignment.h" #include "common/assert.h" +#include "common/literals.h" #include "common/logging/log.h" #include "common/math_util.h" #include "common/microprofile.h" @@ -28,12 +29,13 @@ MICROPROFILE_DEFINE(OpenGL_Drawing, "OpenGL", "Drawing", MP_RGB(128, 128, 192)); MICROPROFILE_DEFINE(OpenGL_Display, "OpenGL", "Display", MP_RGB(128, 128, 192)); using VideoCore::SurfaceType; +using namespace Common::Literals; using namespace Pica::Shader::Generator; -constexpr std::size_t VERTEX_BUFFER_SIZE = 16 * 1024 * 1024; -constexpr std::size_t INDEX_BUFFER_SIZE = 2 * 1024 * 1024; -constexpr std::size_t UNIFORM_BUFFER_SIZE = 2 * 1024 * 1024; -constexpr std::size_t TEXTURE_BUFFER_SIZE = 2 * 1024 * 1024; +constexpr std::size_t VERTEX_BUFFER_SIZE = 16_MiB; +constexpr std::size_t INDEX_BUFFER_SIZE = 2_MiB; +constexpr std::size_t UNIFORM_BUFFER_SIZE = 2_MiB; +constexpr std::size_t TEXTURE_BUFFER_SIZE = 2_MiB; GLenum MakePrimitiveMode(Pica::PipelineRegs::TriangleTopology topology) { switch (topology) { diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index d565c9315..f6e652fca 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include "common/alignment.h" +#include "common/literals.h" #include "common/logging/log.h" #include "common/math_util.h" #include "common/microprofile.h" @@ -28,11 +29,12 @@ MICROPROFILE_DEFINE(Vulkan_Drawing, "Vulkan", "Drawing", MP_RGB(128, 128, 192)); using TriangleTopology = Pica::PipelineRegs::TriangleTopology; using VideoCore::SurfaceType; +using namespace Common::Literals; using namespace Pica::Shader::Generator; -constexpr u64 STREAM_BUFFER_SIZE = 64 * 1024 * 1024; -constexpr u64 UNIFORM_BUFFER_SIZE = 4 * 1024 * 1024; -constexpr u64 TEXTURE_BUFFER_SIZE = 2 * 1024 * 1024; +constexpr u64 STREAM_BUFFER_SIZE = 64_MiB; +constexpr u64 UNIFORM_BUFFER_SIZE = 4_MiB; +constexpr u64 TEXTURE_BUFFER_SIZE = 2_MiB; constexpr vk::BufferUsageFlags BUFFER_USAGE = vk::BufferUsageFlagBits::eVertexBuffer | vk::BufferUsageFlagBits::eIndexBuffer; diff --git a/src/video_core/renderer_vulkan/vk_texture_runtime.cpp b/src/video_core/renderer_vulkan/vk_texture_runtime.cpp index bff700969..79458a70c 100644 --- a/src/video_core/renderer_vulkan/vk_texture_runtime.cpp +++ b/src/video_core/renderer_vulkan/vk_texture_runtime.cpp @@ -4,6 +4,7 @@ #include +#include "common/literals.h" #include "common/microprofile.h" #include "common/scope_exit.h" #include "video_core/custom_textures/material.h" @@ -35,6 +36,7 @@ using VideoCore::MapType; using VideoCore::PixelFormat; using VideoCore::SurfaceType; using VideoCore::TextureType; +using namespace Common::Literals; struct RecordParams { vk::ImageAspectFlags aspect; @@ -244,8 +246,8 @@ vk::ImageSubresourceRange MakeSubresourceRange(vk::ImageAspectFlags aspect, u32 }; } -constexpr u64 UPLOAD_BUFFER_SIZE = 512 * 1024 * 1024; -constexpr u64 DOWNLOAD_BUFFER_SIZE = 16 * 1024 * 1024; +constexpr u64 UPLOAD_BUFFER_SIZE = 512_MiB; +constexpr u64 DOWNLOAD_BUFFER_SIZE = 16_MiB; } // Anonymous namespace