diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/common/bit_util.h | 49 | ||||
| -rw-r--r-- | src/common/nvidia_flags.cpp | 27 | ||||
| -rw-r--r-- | src/common/nvidia_flags.h | 10 |
4 files changed, 53 insertions, 35 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index f77575a00..bfd11e76d 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -138,6 +138,8 @@ add_library(common STATIC | |||
| 138 | microprofile.h | 138 | microprofile.h |
| 139 | microprofileui.h | 139 | microprofileui.h |
| 140 | misc.cpp | 140 | misc.cpp |
| 141 | nvidia_flags.cpp | ||
| 142 | nvidia_flags.h | ||
| 141 | page_table.cpp | 143 | page_table.cpp |
| 142 | page_table.h | 144 | page_table.h |
| 143 | param_package.cpp | 145 | param_package.cpp |
diff --git a/src/common/bit_util.h b/src/common/bit_util.h index 685e7fc9b..64520ca4e 100644 --- a/src/common/bit_util.h +++ b/src/common/bit_util.h | |||
| @@ -4,13 +4,10 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <bit> | ||
| 7 | #include <climits> | 8 | #include <climits> |
| 8 | #include <cstddef> | 9 | #include <cstddef> |
| 9 | 10 | ||
| 10 | #ifdef _MSC_VER | ||
| 11 | #include <intrin.h> | ||
| 12 | #endif | ||
| 13 | |||
| 14 | #include "common/common_types.h" | 11 | #include "common/common_types.h" |
| 15 | 12 | ||
| 16 | namespace Common { | 13 | namespace Common { |
| @@ -21,48 +18,30 @@ template <typename T> | |||
| 21 | return sizeof(T) * CHAR_BIT; | 18 | return sizeof(T) * CHAR_BIT; |
| 22 | } | 19 | } |
| 23 | 20 | ||
| 24 | #ifdef _MSC_VER | 21 | [[nodiscard]] constexpr u32 MostSignificantBit32(const u32 value) { |
| 25 | 22 | return 31U - static_cast<u32>(std::countl_zero(value)); | |
| 26 | [[nodiscard]] inline u32 MostSignificantBit32(const u32 value) { | ||
| 27 | unsigned long result; | ||
| 28 | _BitScanReverse(&result, value); | ||
| 29 | return static_cast<u32>(result); | ||
| 30 | } | ||
| 31 | |||
| 32 | [[nodiscard]] inline u32 MostSignificantBit64(const u64 value) { | ||
| 33 | unsigned long result; | ||
| 34 | _BitScanReverse64(&result, value); | ||
| 35 | return static_cast<u32>(result); | ||
| 36 | } | ||
| 37 | |||
| 38 | #else | ||
| 39 | |||
| 40 | [[nodiscard]] inline u32 MostSignificantBit32(const u32 value) { | ||
| 41 | return 31U - static_cast<u32>(__builtin_clz(value)); | ||
| 42 | } | 23 | } |
| 43 | 24 | ||
| 44 | [[nodiscard]] inline u32 MostSignificantBit64(const u64 value) { | 25 | [[nodiscard]] constexpr u32 MostSignificantBit64(const u64 value) { |
| 45 | return 63U - static_cast<u32>(__builtin_clzll(value)); | 26 | return 63U - static_cast<u32>(std::countl_zero(value)); |
| 46 | } | 27 | } |
| 47 | 28 | ||
| 48 | #endif | 29 | [[nodiscard]] constexpr u32 Log2Floor32(const u32 value) { |
| 49 | |||
| 50 | [[nodiscard]] inline u32 Log2Floor32(const u32 value) { | ||
| 51 | return MostSignificantBit32(value); | 30 | return MostSignificantBit32(value); |
| 52 | } | 31 | } |
| 53 | 32 | ||
| 54 | [[nodiscard]] inline u32 Log2Ceil32(const u32 value) { | 33 | [[nodiscard]] constexpr u32 Log2Floor64(const u64 value) { |
| 55 | const u32 log2_f = Log2Floor32(value); | 34 | return MostSignificantBit64(value); |
| 56 | return log2_f + ((value ^ (1U << log2_f)) != 0U); | ||
| 57 | } | 35 | } |
| 58 | 36 | ||
| 59 | [[nodiscard]] inline u32 Log2Floor64(const u64 value) { | 37 | [[nodiscard]] constexpr u32 Log2Ceil32(const u32 value) { |
| 60 | return MostSignificantBit64(value); | 38 | const u32 log2_f = Log2Floor32(value); |
| 39 | return log2_f + static_cast<u32>((value ^ (1U << log2_f)) != 0U); | ||
| 61 | } | 40 | } |
| 62 | 41 | ||
| 63 | [[nodiscard]] inline u32 Log2Ceil64(const u64 value) { | 42 | [[nodiscard]] constexpr u32 Log2Ceil64(const u64 value) { |
| 64 | const u64 log2_f = static_cast<u64>(Log2Floor64(value)); | 43 | const u64 log2_f = Log2Floor64(value); |
| 65 | return static_cast<u32>(log2_f + ((value ^ (1ULL << log2_f)) != 0ULL)); | 44 | return static_cast<u32>(log2_f + static_cast<u64>((value ^ (1ULL << log2_f)) != 0ULL)); |
| 66 | } | 45 | } |
| 67 | 46 | ||
| 68 | } // namespace Common | 47 | } // namespace Common |
diff --git a/src/common/nvidia_flags.cpp b/src/common/nvidia_flags.cpp new file mode 100644 index 000000000..d537517db --- /dev/null +++ b/src/common/nvidia_flags.cpp | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <filesystem> | ||
| 6 | #include <stdlib.h> | ||
| 7 | |||
| 8 | #include <fmt/format.h> | ||
| 9 | |||
| 10 | #include "common/file_util.h" | ||
| 11 | #include "common/nvidia_flags.h" | ||
| 12 | |||
| 13 | namespace Common { | ||
| 14 | |||
| 15 | void ConfigureNvidiaEnvironmentFlags() { | ||
| 16 | #ifdef _WIN32 | ||
| 17 | const std::string shader_path = Common::FS::SanitizePath( | ||
| 18 | fmt::format("{}/nvidia/", Common::FS::GetUserPath(Common::FS::UserPath::ShaderDir))); | ||
| 19 | const std::string windows_path = | ||
| 20 | Common::FS::SanitizePath(shader_path, Common::FS::DirectorySeparator::BackwardSlash); | ||
| 21 | void(Common::FS::CreateFullPath(shader_path + '/')); | ||
| 22 | void(_putenv(fmt::format("__GL_SHADER_DISK_CACHE_PATH={}", windows_path).c_str())); | ||
| 23 | void(_putenv("__GL_SHADER_DISK_CACHE_SKIP_CLEANUP=1")); | ||
| 24 | #endif | ||
| 25 | } | ||
| 26 | |||
| 27 | } // namespace Common | ||
diff --git a/src/common/nvidia_flags.h b/src/common/nvidia_flags.h new file mode 100644 index 000000000..75a0233ac --- /dev/null +++ b/src/common/nvidia_flags.h | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | namespace Common { | ||
| 6 | |||
| 7 | /// Configure platform specific flags for Nvidia's driver | ||
| 8 | void ConfigureNvidiaEnvironmentFlags(); | ||
| 9 | |||
| 10 | } // namespace Common | ||