From 72bb5dac71430b5b548b5cd8f6f9c7581508455c Mon Sep 17 00:00:00 2001 From: Forrest Mark X Date: Mon, 10 Aug 2026 08:57:44 -0500 Subject: [PATCH] More rebase fixes Removed SSE2 path for unswizzle as its already included with x64 Move the vector above the span in AsyncCpuUnswizzleChunk for better memory order --- src/video_core/CMakeLists.txt | 3 - .../renderer_vulkan/vk_texture_cache.cpp | 2 - .../texture_cache/texture_cache_base.h | 2 +- src/video_core/textures/decoders.cpp | 9 +- src/video_core/textures/decoders_sse2.cpp | 131 ------------------ src/video_core/textures/decoders_sse2.h | 16 --- 6 files changed, 3 insertions(+), 160 deletions(-) delete mode 100644 src/video_core/textures/decoders_sse2.cpp delete mode 100644 src/video_core/textures/decoders_sse2.h diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index d555179969..fd9bcc9348 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt @@ -397,13 +397,10 @@ if (ARCHITECTURE_x86_64) target_sources(video_core PRIVATE textures/decoders_avx2.cpp textures/decoders_avx2.h - textures/decoders_sse2.cpp - textures/decoders_sse2.h ) if (MSVC AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set_source_files_properties(textures/decoders_avx2.cpp PROPERTIES COMPILE_OPTIONS "/arch:AVX2") else() - set_source_files_properties(textures/decoders_sse2.cpp PROPERTIES COMPILE_OPTIONS "-msse2") set_source_files_properties(textures/decoders_avx2.cpp PROPERTIES COMPILE_OPTIONS "-mavx2") endif() endif() diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp index 7306def4af..9c47862044 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp @@ -2329,10 +2329,8 @@ VkImageView Image::StorageImageView(s32 level) noexcept { MaxwellToVK::SurfaceFormat(runtime->device, FormatType::Optimal, true, info.format); if (WillUseAcceleratedAstcDecode(runtime->device, info)) { format_info.format = VK_FORMAT_A8B8G8R8_UNORM_PACK32; - format_info.format = VK_FORMAT_A8B8G8R8_UNORM_PACK32; } else if (const auto block_view_format = BlockTexelViewFormat(info.format)) { format_info.format = *block_view_format; - format_info.format = VK_FORMAT_A8B8G8R8_UNORM_PACK32; } view = MakeStorageView(runtime->device.GetLogical(), level, *(this->*current_image), format_info.format); diff --git a/src/video_core/texture_cache/texture_cache_base.h b/src/video_core/texture_cache/texture_cache_base.h index 1d00811dd1..24eb618af0 100644 --- a/src/video_core/texture_cache/texture_cache_base.h +++ b/src/video_core/texture_cache/texture_cache_base.h @@ -73,8 +73,8 @@ struct AsyncDecodeContext { }; struct AsyncCpuUnswizzleChunk { - std::span swizzled_batch; std::vector linear_batch; + std::span swizzled_batch; u32 z_src = 0; u32 z_image = 0; u32 z_count = 0; diff --git a/src/video_core/textures/decoders.cpp b/src/video_core/textures/decoders.cpp index efb2e79cef..693bcf0fc1 100644 --- a/src/video_core/textures/decoders.cpp +++ b/src/video_core/textures/decoders.cpp @@ -18,7 +18,6 @@ #include "video_core/textures/decoders.h" #if defined(ARCHITECTURE_x86_64) #include "video_core/textures/decoders_avx2.h" -#include "video_core/textures/decoders_sse2.h" #endif namespace Tegra::Texture { @@ -232,13 +231,9 @@ void Swizzle(std::span output, std::span input, u32 bytes_per_pixe if (Common::g_cpu_caps.avx2) { UnswizzleGobPermuteAVX2(output, input, bytes_per_pixel, width, height, depth, block_height, block_depth, stride_alignment); - } else { - // SSE2 comes with x64 by default but incase I'm wrong this is here - // Could maybe check for SSE3, SSSE3, SSE4.1 and SSE4.2 but I think they don't really add anything for this scenario - UnswizzleGobPermuteSSE2(output, input, bytes_per_pixel, width, height, depth, - block_height, block_depth, stride_alignment); + return; } - return; + break; default: break; } diff --git a/src/video_core/textures/decoders_sse2.cpp b/src/video_core/textures/decoders_sse2.cpp deleted file mode 100644 index 071c0df039..0000000000 --- a/src/video_core/textures/decoders_sse2.cpp +++ /dev/null @@ -1,131 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project -// SPDX-License-Identifier: GPL-3.0-or-later - -#include -#include - -#include // SSE2 - -#include "common/assert.h" -#include "common/div_ceil.h" -#include "video_core/textures/decoders.h" -#include "video_core/textures/decoders_sse2.h" - -namespace Tegra::Texture { -namespace { - -template -constexpr u32 Pdep(u32 value) { - u32 result = 0; - u32 m = mask; - for (u32 bit = 1; m; bit += bit) { - if (value & bit) { - result |= m & (~m + 1); - } - m &= m - 1; - } - return result; -} - -template -void IncrPdep(u32& value) { - static constexpr u32 swizzled_incr = Pdep(incr_amount); - value = ((value | ~mask) + swizzled_incr) & mask; -} - -template -__attribute__((target("sse2"))) void UnswizzleGobPermuteSSE2Impl(std::span output, - std::span input, - u32 width, u32 height, u32 depth, - u32 block_height, - u32 block_depth, u32 stride) { - static_assert(16 % BYTES_PER_PIXEL == 0, "BYTES_PER_PIXEL must evenly divide 16"); - - static constexpr u32 RUN_BYTES = 16; - static constexpr u32 PIXELS_PER_RUN = RUN_BYTES / BYTES_PER_PIXEL; - - const u32 pitch = width * BYTES_PER_PIXEL; - const u32 gobs_in_x = Common::DivCeilLog2(stride, GOB_SIZE_X_SHIFT); - const u32 block_size = gobs_in_x << (GOB_SIZE_SHIFT + block_height + block_depth); - const u32 slice_size = - Common::DivCeilLog2(height, block_height + GOB_SIZE_Y_SHIFT) * block_size; - const u32 block_height_mask = (1U << block_height) - 1; - const u32 block_depth_mask = (1U << block_depth) - 1; - const u32 x_shift = GOB_SIZE_SHIFT + block_height + block_depth; - - for (u32 slice = 0; slice < depth; ++slice) { - const u32 offset_z = (slice >> block_depth) * slice_size + - ((slice & block_depth_mask) << (GOB_SIZE_SHIFT + block_height)); - - for (u32 line = 0; line < height; ++line) { - const u32 swizzled_y = Pdep(line); - const u32 block_y = line >> GOB_SIZE_Y_SHIFT; - const u32 offset_y = (block_y >> block_height) * block_size + - ((block_y & block_height_mask) << GOB_SIZE_SHIFT); - - u32 swizzled_x = 0; - u32 column = 0; - - for (; column + PIXELS_PER_RUN <= width; - column += PIXELS_PER_RUN, IncrPdep(swizzled_x)) { - - const u32 x = column * BYTES_PER_PIXEL; - const u32 offset_x = (x >> GOB_SIZE_X_SHIFT) << x_shift; - const u32 base_swizzled_offset = offset_z + offset_y + offset_x; - const u32 swizzled_offset = base_swizzled_offset + (swizzled_x | swizzled_y); - const u32 unswizzled_offset = - slice * pitch * height + line * pitch + column * BYTES_PER_PIXEL; - - u8* const dst = &output[unswizzled_offset]; - const u8* const src = &input[swizzled_offset]; - - const __m128i val = _mm_loadu_si128(reinterpret_cast(src)); - _mm_storeu_si128(reinterpret_cast<__m128i*>(dst), val); - } - - for (; column < width; - ++column, IncrPdep(swizzled_x)) { - - const u32 x = column * BYTES_PER_PIXEL; - const u32 offset_x = (x >> GOB_SIZE_X_SHIFT) << x_shift; - const u32 base_swizzled_offset = offset_z + offset_y + offset_x; - const u32 swizzled_offset = base_swizzled_offset + (swizzled_x | swizzled_y); - const u32 unswizzled_offset = - slice * pitch * height + line * pitch + column * BYTES_PER_PIXEL; - - u8* const dst = &output[unswizzled_offset]; - const u8* const src = &input[swizzled_offset]; - - std::memcpy(dst, src, BYTES_PER_PIXEL); - } - } - } -} - -} // Anonymous namespace - -void UnswizzleGobPermuteSSE2(std::span output, std::span input, u32 bytes_per_pixel, - u32 width, u32 height, u32 depth, u32 block_height, u32 block_depth, - u32 stride) { - switch (bytes_per_pixel) { - case 1: - return UnswizzleGobPermuteSSE2Impl<1>(output, input, width, height, depth, block_height, - block_depth, stride); - case 2: - return UnswizzleGobPermuteSSE2Impl<2>(output, input, width, height, depth, block_height, - block_depth, stride); - case 4: - return UnswizzleGobPermuteSSE2Impl<4>(output, input, width, height, depth, block_height, - block_depth, stride); - case 8: - return UnswizzleGobPermuteSSE2Impl<8>(output, input, width, height, depth, block_height, - block_depth, stride); - case 16: - return UnswizzleGobPermuteSSE2Impl<16>(output, input, width, height, depth, block_height, - block_depth, stride); - default: - UNREACHABLE(); - } -} - -} // namespace Tegra::Texture \ No newline at end of file diff --git a/src/video_core/textures/decoders_sse2.h b/src/video_core/textures/decoders_sse2.h deleted file mode 100644 index b52242bb64..0000000000 --- a/src/video_core/textures/decoders_sse2.h +++ /dev/null @@ -1,16 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project -// SPDX-License-Identifier: GPL-3.0-or-later - -#pragma once - -#include - -#include "common/common_types.h" - -namespace Tegra::Texture { - -void UnswizzleGobPermuteSSE2(std::span output, std::span input, u32 bytes_per_pixel, - u32 width, u32 height, u32 depth, u32 block_height, u32 block_depth, - u32 stride); - -} // namespace Tegra::Texture