From 5a6d8878ae82cdde26dc29413117aa0c5dc6bf97 Mon Sep 17 00:00:00 2001 From: psucien Date: Fri, 19 Jul 2024 22:10:53 +0200 Subject: [PATCH] review comments --- CMakeLists.txt | 1 - src/common/math.h | 10 ---------- .../backend/spirv/spirv_emit_context.cpp | 4 ++-- src/video_core/texture_cache/image_info.cpp | 16 ++++++++++------ src/video_core/texture_cache/tile_manager.cpp | 5 ++--- 5 files changed, 14 insertions(+), 22 deletions(-) delete mode 100644 src/common/math.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7def8ccc3..4fc910427 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -254,7 +254,6 @@ set(COMMON src/common/logging/backend.cpp src/common/error.h src/common/scope_exit.h src/common/func_traits.h - src/common/math.h src/common/native_clock.cpp src/common/native_clock.h src/common/path_util.cpp diff --git a/src/common/math.h b/src/common/math.h deleted file mode 100644 index 207c06cfa..000000000 --- a/src/common/math.h +++ /dev/null @@ -1,10 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include "common/types.h" - -static inline u32 IntLog2(u32 i) { - return 31u - __builtin_clz(i | 1u); -} diff --git a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp index c12ae4b29..16c10f53c 100644 --- a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp @@ -7,7 +7,7 @@ #include #include -static constexpr auto M_PI = 3.14159265358979323846f; +#include namespace Shader::Backend::SPIRV { namespace { @@ -103,7 +103,7 @@ void EmitContext::DefineArithmeticTypes() { u32_zero_value = ConstU32(0U); f32_zero_value = ConstF32(0.0f); - pi_x2 = ConstF32(2.0f * float(M_PI)); + pi_x2 = ConstF32(2.0f * float{std::numbers::pi}); input_f32 = Name(TypePointer(spv::StorageClass::Input, F32[1]), "input_f32"); input_u32 = Name(TypePointer(spv::StorageClass::Input, U32[1]), "input_u32"); diff --git a/src/video_core/texture_cache/image_info.cpp b/src/video_core/texture_cache/image_info.cpp index ccac9131e..41ad09381 100644 --- a/src/video_core/texture_cache/image_info.cpp +++ b/src/video_core/texture_cache/image_info.cpp @@ -3,7 +3,6 @@ #include "common/assert.h" #include "common/config.h" -#include "common/math.h" #include "video_core/renderer_vulkan/liverpool_to_vk.h" #include "video_core/texture_cache/image_info.h" @@ -46,6 +45,7 @@ static vk::ImageType ConvertImageType(AmdGpu::ImageType type) noexcept { } // clang-format off +// The table of macro tiles parameters for given tiling index (row) and bpp (column) static constexpr std::array macro_tile_extents{ std::pair{256u, 128u}, std::pair{256u, 128u}, std::pair{256u, 128u}, std::pair{256u, 128u}, // 00 std::pair{256u, 128u}, std::pair{128u, 128u}, std::pair{128u, 128u}, std::pair{128u, 128u}, // 01 @@ -77,9 +77,14 @@ static constexpr std::array macro_tile_extents{ }; // clang-format on +static constexpr std::pair micro_tile_extent{8u, 8u}; +static constexpr auto hw_pipe_interleave = 256u; + static constexpr std::pair GetMacroTileExtents(u32 tiling_idx, u32 bpp, u32 num_samples) { ASSERT(num_samples == 1); - return macro_tile_extents[tiling_idx * 4 + IntLog2(bpp) - 3]; + const auto row = tiling_idx * 4; + const auto column = std::bit_width(bpp) - 4; // bpps are 8, 16, 32, 64 + return macro_tile_extents[row + column]; } static constexpr size_t ImageSizeLinearAligned(u32 pitch, u32 height, u32 bpp, u32 num_samples) { @@ -87,7 +92,7 @@ static constexpr size_t ImageSizeLinearAligned(u32 pitch, u32 height, u32 bpp, u auto pitch_aligned = (pitch + pitch_align - 1) & ~(pitch_align - 1); const auto height_aligned = height; size_t log_sz = 1; - const auto slice_align = std::max(64u, 256u / (bpp + 7) / 8); + const auto slice_align = std::max(64u, hw_pipe_interleave / (bpp + 7) / 8); while (log_sz % slice_align) { log_sz = pitch_aligned * height_aligned * num_samples; pitch_aligned += pitch_align; @@ -96,8 +101,7 @@ static constexpr size_t ImageSizeLinearAligned(u32 pitch, u32 height, u32 bpp, u } static constexpr size_t ImageSizeMicroTiled(u32 pitch, u32 height, u32 bpp, u32 num_samples) { - const auto pitch_align = 8u; - const auto height_align = 8u; + const auto& [pitch_align, height_align] = micro_tile_extent; auto pitch_aligned = (pitch + pitch_align - 1) & ~(pitch_align - 1); const auto height_aligned = (height + height_align - 1) & ~(height_align - 1); size_t log_sz = 1; @@ -193,7 +197,7 @@ ImageInfo::ImageInfo(const AmdGpu::Image& image) noexcept { pixel_format = LiverpoolToVK::SurfaceFormat(image.GetDataFmt(), image.GetNumberFmt()); type = ConvertImageType(image.GetType()); is_cube = image.GetType() == AmdGpu::ImageType::Cube; - const auto is_volume = image.GetType() == AmdGpu::ImageType::Color3D; + is_volume = image.GetType() == AmdGpu::ImageType::Color3D; size.width = image.width + 1; size.height = image.height + 1; size.depth = is_volume ? image.depth + 1 : 1; diff --git a/src/video_core/texture_cache/tile_manager.cpp b/src/video_core/texture_cache/tile_manager.cpp index 574f51b1d..e097ba3ed 100644 --- a/src/video_core/texture_cache/tile_manager.cpp +++ b/src/video_core/texture_cache/tile_manager.cpp @@ -1,7 +1,6 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "common/math.h" #include "video_core/renderer_vulkan/vk_instance.h" #include "video_core/renderer_vulkan/vk_scheduler.h" #include "video_core/renderer_vulkan/vk_shader_util.h" @@ -78,8 +77,8 @@ public: static u32 getBankIdx(u32 x, u32 y, u32 bank_width, u32 bank_height, u32 num_banks, u32 num_pipes) { - const u32 x_shift_offset = IntLog2(bank_width * num_pipes); - const u32 y_shift_offset = IntLog2(bank_height); + const u32 x_shift_offset = std::bit_width(bank_width * num_pipes) - 1; + const u32 y_shift_offset = std::bit_width(bank_height) - 1; const u32 xs = x >> x_shift_offset; const u32 ys = y >> y_shift_offset; u32 bank = 0;