diff options
Diffstat (limited to '')
| -rw-r--r-- | src/common/bit_util.h | 7 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_texture_cache.cpp | 6 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_texture_cache.cpp | 7 |
3 files changed, 11 insertions, 9 deletions
diff --git a/src/common/bit_util.h b/src/common/bit_util.h index 64520ca4e..eef8c1c5a 100644 --- a/src/common/bit_util.h +++ b/src/common/bit_util.h | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <bit> | 7 | #include <bit> |
| 8 | #include <climits> | 8 | #include <climits> |
| 9 | #include <cstddef> | 9 | #include <cstddef> |
| 10 | #include <type_traits> | ||
| 10 | 11 | ||
| 11 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| 12 | 13 | ||
| @@ -44,4 +45,10 @@ template <typename T> | |||
| 44 | return static_cast<u32>(log2_f + static_cast<u64>((value ^ (1ULL << log2_f)) != 0ULL)); | 45 | return static_cast<u32>(log2_f + static_cast<u64>((value ^ (1ULL << log2_f)) != 0ULL)); |
| 45 | } | 46 | } |
| 46 | 47 | ||
| 48 | template <typename T> | ||
| 49 | requires std::is_integral_v<T> | ||
| 50 | [[nodiscard]] T NextPow2(T value) { | ||
| 51 | return static_cast<T>(1ULL << ((8U * sizeof(T)) - std::countl_zero(value - 1U))); | ||
| 52 | } | ||
| 53 | |||
| 47 | } // namespace Common | 54 | } // namespace Common |
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp index e70bbec81..ecb215a7d 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.cpp +++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | 9 | ||
| 10 | #include <glad/glad.h> | 10 | #include <glad/glad.h> |
| 11 | 11 | ||
| 12 | #include "common/bit_util.h" | ||
| 12 | #include "common/literals.h" | 13 | #include "common/literals.h" |
| 13 | #include "common/settings.h" | 14 | #include "common/settings.h" |
| 14 | #include "video_core/renderer_opengl/gl_device.h" | 15 | #include "video_core/renderer_opengl/gl_device.h" |
| @@ -397,9 +398,6 @@ OGLTexture MakeImage(const VideoCommon::ImageInfo& info, GLenum gl_internal_form | |||
| 397 | return GL_R32UI; | 398 | return GL_R32UI; |
| 398 | } | 399 | } |
| 399 | 400 | ||
| 400 | [[nodiscard]] u32 NextPow2(u32 value) { | ||
| 401 | return 1U << (32U - std::countl_zero(value - 1U)); | ||
| 402 | } | ||
| 403 | } // Anonymous namespace | 401 | } // Anonymous namespace |
| 404 | 402 | ||
| 405 | ImageBufferMap::~ImageBufferMap() { | 403 | ImageBufferMap::~ImageBufferMap() { |
| @@ -1308,7 +1306,7 @@ void FormatConversionPass::ConvertImage(Image& dst_image, Image& src_image, | |||
| 1308 | const u32 copy_size = region.width * region.height * region.depth * img_bpp; | 1306 | const u32 copy_size = region.width * region.height * region.depth * img_bpp; |
| 1309 | if (pbo_size < copy_size) { | 1307 | if (pbo_size < copy_size) { |
| 1310 | intermediate_pbo.Create(); | 1308 | intermediate_pbo.Create(); |
| 1311 | pbo_size = NextPow2(copy_size); | 1309 | pbo_size = Common::NextPow2(copy_size); |
| 1312 | glNamedBufferData(intermediate_pbo.handle, pbo_size, nullptr, GL_STREAM_COPY); | 1310 | glNamedBufferData(intermediate_pbo.handle, pbo_size, nullptr, GL_STREAM_COPY); |
| 1313 | } | 1311 | } |
| 1314 | // Copy from source to PBO | 1312 | // Copy from source to PBO |
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp index 02215cfc2..f194110e5 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include <vector> | 8 | #include <vector> |
| 9 | 9 | ||
| 10 | #include "common/bit_cast.h" | 10 | #include "common/bit_cast.h" |
| 11 | #include "common/bit_util.h" | ||
| 11 | #include "common/settings.h" | 12 | #include "common/settings.h" |
| 12 | 13 | ||
| 13 | #include "video_core/engines/fermi_2d.h" | 14 | #include "video_core/engines/fermi_2d.h" |
| @@ -775,16 +776,12 @@ bool TextureCacheRuntime::ShouldReinterpret(Image& dst, Image& src) { | |||
| 775 | return false; | 776 | return false; |
| 776 | } | 777 | } |
| 777 | 778 | ||
| 778 | [[nodiscard]] size_t NextPow2(size_t value) { | ||
| 779 | return static_cast<size_t>(1ULL << ((8U * sizeof(size_t)) - std::countl_zero(value - 1U))); | ||
| 780 | } | ||
| 781 | |||
| 782 | VkBuffer TextureCacheRuntime::GetTemporaryBuffer(size_t needed_size) { | 779 | VkBuffer TextureCacheRuntime::GetTemporaryBuffer(size_t needed_size) { |
| 783 | const auto level = (8 * sizeof(size_t)) - std::countl_zero(needed_size - 1ULL); | 780 | const auto level = (8 * sizeof(size_t)) - std::countl_zero(needed_size - 1ULL); |
| 784 | if (buffer_commits[level]) { | 781 | if (buffer_commits[level]) { |
| 785 | return *buffers[level]; | 782 | return *buffers[level]; |
| 786 | } | 783 | } |
| 787 | const auto new_size = NextPow2(needed_size); | 784 | const auto new_size = Common::NextPow2(needed_size); |
| 788 | VkBufferUsageFlags flags = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | | 785 | VkBufferUsageFlags flags = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | |
| 789 | VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | | 786 | VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | |
| 790 | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT; | 787 | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT; |