summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/CMakeLists.txt2
-rw-r--r--src/common/common_sizes.h44
-rw-r--r--src/common/literals.h31
-rw-r--r--src/common/logging/backend.cpp11
-rw-r--r--src/core/arm/dynarmic/arm_dynarmic_32.cpp7
-rw-r--r--src/core/arm/dynarmic/arm_dynarmic_64.cpp6
-rw-r--r--src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp37
-rw-r--r--src/core/hle/kernel/k_address_space_info.cpp35
-rw-r--r--src/core/hle/kernel/k_memory_layout.board.nintendo_nx.cpp5
-rw-r--r--src/core/hle/kernel/k_memory_layout.h27
-rw-r--r--src/core/hle/kernel/k_page_table.cpp5
-rw-r--r--src/core/hle/kernel/k_trace.h6
-rw-r--r--src/core/hle/kernel/kernel.cpp17
-rw-r--r--src/tests/common/host_memory.cpp4
-rw-r--r--src/video_core/buffer_cache/buffer_cache.h11
-rw-r--r--src/video_core/host_shaders/astc_decoder.comp46
-rw-r--r--src/video_core/renderer_opengl/gl_stream_buffer.h5
-rw-r--r--src/video_core/renderer_opengl/util_shaders.cpp31
-rw-r--r--src/video_core/renderer_vulkan/vk_compute_pass.cpp107
-rw-r--r--src/video_core/renderer_vulkan/vk_staging_buffer_pool.cpp8
-rw-r--r--src/video_core/renderer_vulkan/vk_stream_buffer.cpp5
-rw-r--r--src/video_core/texture_cache/texture_cache.h12
-rw-r--r--src/video_core/textures/astc.cpp10
-rw-r--r--src/video_core/textures/astc.h11
-rw-r--r--src/video_core/vulkan_common/vulkan_device.cpp4
-rw-r--r--src/video_core/vulkan_common/vulkan_device.h33
26 files changed, 220 insertions, 300 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 7534eb8f1..a6fa9a85d 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -110,7 +110,6 @@ add_library(common STATIC
110 cityhash.cpp 110 cityhash.cpp
111 cityhash.h 111 cityhash.h
112 common_funcs.h 112 common_funcs.h
113 common_sizes.h
114 common_types.h 113 common_types.h
115 concepts.h 114 concepts.h
116 div_ceil.h 115 div_ceil.h
@@ -134,6 +133,7 @@ add_library(common STATIC
134 host_memory.cpp 133 host_memory.cpp
135 host_memory.h 134 host_memory.h
136 intrusive_red_black_tree.h 135 intrusive_red_black_tree.h
136 literals.h
137 logging/backend.cpp 137 logging/backend.cpp
138 logging/backend.h 138 logging/backend.h
139 logging/filter.cpp 139 logging/filter.cpp
diff --git a/src/common/common_sizes.h b/src/common/common_sizes.h
deleted file mode 100644
index d07b7ee5a..000000000
--- a/src/common/common_sizes.h
+++ /dev/null
@@ -1,44 +0,0 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <limits>
8
9#include "common/common_types.h"
10
11namespace Common {
12
13enum : u64 {
14 Size_1_KB = 0x400ULL,
15 Size_64_KB = 64ULL * Size_1_KB,
16 Size_128_KB = 128ULL * Size_1_KB,
17 Size_1_MB = 0x100000ULL,
18 Size_2_MB = 2ULL * Size_1_MB,
19 Size_4_MB = 4ULL * Size_1_MB,
20 Size_5_MB = 5ULL * Size_1_MB,
21 Size_14_MB = 14ULL * Size_1_MB,
22 Size_32_MB = 32ULL * Size_1_MB,
23 Size_33_MB = 33ULL * Size_1_MB,
24 Size_128_MB = 128ULL * Size_1_MB,
25 Size_448_MB = 448ULL * Size_1_MB,
26 Size_507_MB = 507ULL * Size_1_MB,
27 Size_512_MB = 512ULL * Size_1_MB,
28 Size_562_MB = 562ULL * Size_1_MB,
29 Size_1554_MB = 1554ULL * Size_1_MB,
30 Size_2048_MB = 2048ULL * Size_1_MB,
31 Size_2193_MB = 2193ULL * Size_1_MB,
32 Size_3285_MB = 3285ULL * Size_1_MB,
33 Size_4916_MB = 4916ULL * Size_1_MB,
34 Size_1_GB = 0x40000000ULL,
35 Size_2_GB = 2ULL * Size_1_GB,
36 Size_4_GB = 4ULL * Size_1_GB,
37 Size_6_GB = 6ULL * Size_1_GB,
38 Size_8_GB = 8ULL * Size_1_GB,
39 Size_64_GB = 64ULL * Size_1_GB,
40 Size_512_GB = 512ULL * Size_1_GB,
41 Size_Invalid = std::numeric_limits<u64>::max(),
42};
43
44} // namespace Common
diff --git a/src/common/literals.h b/src/common/literals.h
new file mode 100644
index 000000000..d55fed40b
--- /dev/null
+++ b/src/common/literals.h
@@ -0,0 +1,31 @@
1// Copyright 2021 yuzu emulator team
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/common_types.h"
8
9namespace Common::Literals {
10
11constexpr u64 operator""_KiB(unsigned long long int x) {
12 return 1024ULL * x;
13}
14
15constexpr u64 operator""_MiB(unsigned long long int x) {
16 return 1024_KiB * x;
17}
18
19constexpr u64 operator""_GiB(unsigned long long int x) {
20 return 1024_MiB * x;
21}
22
23constexpr u64 operator""_TiB(unsigned long long int x) {
24 return 1024_GiB * x;
25}
26
27constexpr u64 operator""_PiB(unsigned long long int x) {
28 return 1024_TiB * x;
29}
30
31} // namespace Common::Literals
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index 47ce06478..b6fa4affb 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -19,6 +19,8 @@
19#include "common/assert.h" 19#include "common/assert.h"
20#include "common/fs/file.h" 20#include "common/fs/file.h"
21#include "common/fs/fs.h" 21#include "common/fs/fs.h"
22#include "common/literals.h"
23
22#include "common/logging/backend.h" 24#include "common/logging/backend.h"
23#include "common/logging/log.h" 25#include "common/logging/log.h"
24#include "common/logging/text_formatter.h" 26#include "common/logging/text_formatter.h"
@@ -98,8 +100,8 @@ private:
98 write_logs(entry); 100 write_logs(entry);
99 } 101 }
100 102
101 // Drain the logging queue. Only writes out up to MAX_LOGS_TO_WRITE to prevent a case 103 // Drain the logging queue. Only writes out up to MAX_LOGS_TO_WRITE to prevent a
102 // where a system is repeatedly spamming logs even on close. 104 // case where a system is repeatedly spamming logs even on close.
103 const int MAX_LOGS_TO_WRITE = filter.IsDebug() ? INT_MAX : 100; 105 const int MAX_LOGS_TO_WRITE = filter.IsDebug() ? INT_MAX : 100;
104 int logs_written = 0; 106 int logs_written = 0;
105 while (logs_written++ < MAX_LOGS_TO_WRITE && message_queue.Pop(entry)) { 107 while (logs_written++ < MAX_LOGS_TO_WRITE && message_queue.Pop(entry)) {
@@ -169,10 +171,11 @@ FileBackend::FileBackend(const std::filesystem::path& filename) {
169FileBackend::~FileBackend() = default; 171FileBackend::~FileBackend() = default;
170 172
171void FileBackend::Write(const Entry& entry) { 173void FileBackend::Write(const Entry& entry) {
174 using namespace Common::Literals;
172 // prevent logs from going over the maximum size (in case its spamming and the user doesn't 175 // prevent logs from going over the maximum size (in case its spamming and the user doesn't
173 // know) 176 // know)
174 constexpr std::size_t MAX_BYTES_WRITTEN = 100 * 1024 * 1024; 177 constexpr std::size_t MAX_BYTES_WRITTEN = 100_MiB;
175 constexpr std::size_t MAX_BYTES_WRITTEN_EXTENDED = 1024 * 1024 * 1024; 178 constexpr std::size_t MAX_BYTES_WRITTEN_EXTENDED = 1_GiB;
176 179
177 if (!file->IsOpen()) { 180 if (!file->IsOpen()) {
178 return; 181 return;
diff --git a/src/core/arm/dynarmic/arm_dynarmic_32.cpp b/src/core/arm/dynarmic/arm_dynarmic_32.cpp
index f871f7bf4..77a44f862 100644
--- a/src/core/arm/dynarmic/arm_dynarmic_32.cpp
+++ b/src/core/arm/dynarmic/arm_dynarmic_32.cpp
@@ -8,6 +8,7 @@
8#include <dynarmic/interface/A32/config.h> 8#include <dynarmic/interface/A32/config.h>
9#include <dynarmic/interface/A32/context.h> 9#include <dynarmic/interface/A32/context.h>
10#include "common/assert.h" 10#include "common/assert.h"
11#include "common/literals.h"
11#include "common/logging/log.h" 12#include "common/logging/log.h"
12#include "common/page_table.h" 13#include "common/page_table.h"
13#include "common/settings.h" 14#include "common/settings.h"
@@ -22,6 +23,8 @@
22 23
23namespace Core { 24namespace Core {
24 25
26using namespace Common::Literals;
27
25class DynarmicCallbacks32 : public Dynarmic::A32::UserCallbacks { 28class DynarmicCallbacks32 : public Dynarmic::A32::UserCallbacks {
26public: 29public:
27 explicit DynarmicCallbacks32(ARM_Dynarmic_32& parent_) 30 explicit DynarmicCallbacks32(ARM_Dynarmic_32& parent_)
@@ -143,8 +146,8 @@ std::shared_ptr<Dynarmic::A32::Jit> ARM_Dynarmic_32::MakeJit(Common::PageTable*
143 config.wall_clock_cntpct = uses_wall_clock; 146 config.wall_clock_cntpct = uses_wall_clock;
144 147
145 // Code cache size 148 // Code cache size
146 config.code_cache_size = 512 * 1024 * 1024; 149 config.code_cache_size = 512_MiB;
147 config.far_code_offset = 400 * 1024 * 1024; 150 config.far_code_offset = 400_MiB;
148 151
149 // Safe optimizations 152 // Safe optimizations
150 if (Settings::values.cpu_accuracy.GetValue() == Settings::CPUAccuracy::DebugMode) { 153 if (Settings::values.cpu_accuracy.GetValue() == Settings::CPUAccuracy::DebugMode) {
diff --git a/src/core/arm/dynarmic/arm_dynarmic_64.cpp b/src/core/arm/dynarmic/arm_dynarmic_64.cpp
index ba524cd05..75332e348 100644
--- a/src/core/arm/dynarmic/arm_dynarmic_64.cpp
+++ b/src/core/arm/dynarmic/arm_dynarmic_64.cpp
@@ -7,6 +7,7 @@
7#include <dynarmic/interface/A64/a64.h> 7#include <dynarmic/interface/A64/a64.h>
8#include <dynarmic/interface/A64/config.h> 8#include <dynarmic/interface/A64/config.h>
9#include "common/assert.h" 9#include "common/assert.h"
10#include "common/literals.h"
10#include "common/logging/log.h" 11#include "common/logging/log.h"
11#include "common/page_table.h" 12#include "common/page_table.h"
12#include "common/settings.h" 13#include "common/settings.h"
@@ -24,6 +25,7 @@
24namespace Core { 25namespace Core {
25 26
26using Vector = Dynarmic::A64::Vector; 27using Vector = Dynarmic::A64::Vector;
28using namespace Common::Literals;
27 29
28class DynarmicCallbacks64 : public Dynarmic::A64::UserCallbacks { 30class DynarmicCallbacks64 : public Dynarmic::A64::UserCallbacks {
29public: 31public:
@@ -184,8 +186,8 @@ std::shared_ptr<Dynarmic::A64::Jit> ARM_Dynarmic_64::MakeJit(Common::PageTable*
184 config.wall_clock_cntpct = uses_wall_clock; 186 config.wall_clock_cntpct = uses_wall_clock;
185 187
186 // Code cache size 188 // Code cache size
187 config.code_cache_size = 512 * 1024 * 1024; 189 config.code_cache_size = 512_MiB;
188 config.far_code_offset = 400 * 1024 * 1024; 190 config.far_code_offset = 400_MiB;
189 191
190 // Safe optimizations 192 // Safe optimizations
191 if (Settings::values.cpu_accuracy.GetValue() == Settings::CPUAccuracy::DebugMode) { 193 if (Settings::values.cpu_accuracy.GetValue() == Settings::CPUAccuracy::DebugMode) {
diff --git a/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp b/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp
index 86472b5ce..6f335c251 100644
--- a/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp
+++ b/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp
@@ -4,7 +4,8 @@
4 4
5#include <random> 5#include <random>
6 6
7#include "common/common_sizes.h" 7#include "common/literals.h"
8
8#include "core/hle/kernel/board/nintendo/nx/k_system_control.h" 9#include "core/hle/kernel/board/nintendo/nx/k_system_control.h"
9#include "core/hle/kernel/board/nintendo/nx/secure_monitor.h" 10#include "core/hle/kernel/board/nintendo/nx/secure_monitor.h"
10#include "core/hle/kernel/k_trace.h" 11#include "core/hle/kernel/k_trace.h"
@@ -25,6 +26,8 @@ constexpr const std::size_t RequiredNonSecureSystemMemorySize =
25 26
26namespace { 27namespace {
27 28
29using namespace Common::Literals;
30
28u32 GetMemoryModeForInit() { 31u32 GetMemoryModeForInit() {
29 return 0x01; 32 return 0x01;
30} 33}
@@ -57,11 +60,11 @@ size_t KSystemControl::Init::GetIntendedMemorySize() {
57 switch (GetMemorySizeForInit()) { 60 switch (GetMemorySizeForInit()) {
58 case Smc::MemorySize_4GB: 61 case Smc::MemorySize_4GB:
59 default: // All invalid modes should go to 4GB. 62 default: // All invalid modes should go to 4GB.
60 return Common::Size_4_GB; 63 return 4_GiB;
61 case Smc::MemorySize_6GB: 64 case Smc::MemorySize_6GB:
62 return Common::Size_6_GB; 65 return 6_GiB;
63 case Smc::MemorySize_8GB: 66 case Smc::MemorySize_8GB:
64 return Common::Size_8_GB; 67 return 8_GiB;
65 } 68 }
66} 69}
67 70
@@ -79,17 +82,17 @@ std::size_t KSystemControl::Init::GetApplicationPoolSize() {
79 switch (GetMemoryArrangeForInit()) { 82 switch (GetMemoryArrangeForInit()) {
80 case Smc::MemoryArrangement_4GB: 83 case Smc::MemoryArrangement_4GB:
81 default: 84 default:
82 return Common::Size_3285_MB; 85 return 3285_MiB;
83 case Smc::MemoryArrangement_4GBForAppletDev: 86 case Smc::MemoryArrangement_4GBForAppletDev:
84 return Common::Size_2048_MB; 87 return 2048_MiB;
85 case Smc::MemoryArrangement_4GBForSystemDev: 88 case Smc::MemoryArrangement_4GBForSystemDev:
86 return Common::Size_3285_MB; 89 return 3285_MiB;
87 case Smc::MemoryArrangement_6GB: 90 case Smc::MemoryArrangement_6GB:
88 return Common::Size_4916_MB; 91 return 4916_MiB;
89 case Smc::MemoryArrangement_6GBForAppletDev: 92 case Smc::MemoryArrangement_6GBForAppletDev:
90 return Common::Size_3285_MB; 93 return 3285_MiB;
91 case Smc::MemoryArrangement_8GB: 94 case Smc::MemoryArrangement_8GB:
92 return Common::Size_4916_MB; 95 return 4916_MiB;
93 } 96 }
94 }(); 97 }();
95 98
@@ -103,22 +106,22 @@ size_t KSystemControl::Init::GetAppletPoolSize() {
103 switch (GetMemoryArrangeForInit()) { 106 switch (GetMemoryArrangeForInit()) {
104 case Smc::MemoryArrangement_4GB: 107 case Smc::MemoryArrangement_4GB:
105 default: 108 default:
106 return Common::Size_507_MB; 109 return 507_MiB;
107 case Smc::MemoryArrangement_4GBForAppletDev: 110 case Smc::MemoryArrangement_4GBForAppletDev:
108 return Common::Size_1554_MB; 111 return 1554_MiB;
109 case Smc::MemoryArrangement_4GBForSystemDev: 112 case Smc::MemoryArrangement_4GBForSystemDev:
110 return Common::Size_448_MB; 113 return 448_MiB;
111 case Smc::MemoryArrangement_6GB: 114 case Smc::MemoryArrangement_6GB:
112 return Common::Size_562_MB; 115 return 562_MiB;
113 case Smc::MemoryArrangement_6GBForAppletDev: 116 case Smc::MemoryArrangement_6GBForAppletDev:
114 return Common::Size_2193_MB; 117 return 2193_MiB;
115 case Smc::MemoryArrangement_8GB: 118 case Smc::MemoryArrangement_8GB:
116 return Common::Size_2193_MB; 119 return 2193_MiB;
117 } 120 }
118 }(); 121 }();
119 122
120 // Return (possibly) adjusted size. 123 // Return (possibly) adjusted size.
121 constexpr size_t ExtraSystemMemoryForAtmosphere = Common::Size_33_MB; 124 constexpr size_t ExtraSystemMemoryForAtmosphere = 33_MiB;
122 return base_pool_size - ExtraSystemMemoryForAtmosphere - KTraceBufferSize; 125 return base_pool_size - ExtraSystemMemoryForAtmosphere - KTraceBufferSize;
123} 126}
124 127
diff --git a/src/core/hle/kernel/k_address_space_info.cpp b/src/core/hle/kernel/k_address_space_info.cpp
index c7549f7a2..ca29edc88 100644
--- a/src/core/hle/kernel/k_address_space_info.cpp
+++ b/src/core/hle/kernel/k_address_space_info.cpp
@@ -5,34 +5,37 @@
5#include <array> 5#include <array>
6 6
7#include "common/assert.h" 7#include "common/assert.h"
8#include "common/common_sizes.h" 8#include "common/literals.h"
9#include "core/hle/kernel/k_address_space_info.h" 9#include "core/hle/kernel/k_address_space_info.h"
10 10
11namespace Kernel { 11namespace Kernel {
12 12
13namespace { 13namespace {
14 14
15using namespace Common::Literals;
16
17constexpr u64 Size_Invalid = UINT64_MAX;
18
15// clang-format off 19// clang-format off
16constexpr std::array<KAddressSpaceInfo, 13> AddressSpaceInfos{{ 20constexpr std::array<KAddressSpaceInfo, 13> AddressSpaceInfos{{
17 { .bit_width = 32, .address = Common::Size_2_MB , .size = Common::Size_1_GB - Common::Size_2_MB , .type = KAddressSpaceInfo::Type::MapSmall, }, 21 { .bit_width = 32, .address = 2_MiB , .size = 1_GiB - 2_MiB , .type = KAddressSpaceInfo::Type::MapSmall, },
18 { .bit_width = 32, .address = Common::Size_1_GB , .size = Common::Size_4_GB - Common::Size_1_GB , .type = KAddressSpaceInfo::Type::MapLarge, }, 22 { .bit_width = 32, .address = 1_GiB , .size = 4_GiB - 1_GiB , .type = KAddressSpaceInfo::Type::MapLarge, },
19 { .bit_width = 32, .address = Common::Size_Invalid, .size = Common::Size_1_GB , .type = KAddressSpaceInfo::Type::Alias, }, 23 { .bit_width = 32, .address = Size_Invalid, .size = 1_GiB , .type = KAddressSpaceInfo::Type::Alias, },
20 { .bit_width = 32, .address = Common::Size_Invalid, .size = Common::Size_1_GB , .type = KAddressSpaceInfo::Type::Heap, }, 24 { .bit_width = 32, .address = Size_Invalid, .size = 1_GiB , .type = KAddressSpaceInfo::Type::Heap, },
21 { .bit_width = 36, .address = Common::Size_128_MB , .size = Common::Size_2_GB - Common::Size_128_MB, .type = KAddressSpaceInfo::Type::MapSmall, }, 25 { .bit_width = 36, .address = 128_MiB , .size = 2_GiB - 128_MiB, .type = KAddressSpaceInfo::Type::MapSmall, },
22 { .bit_width = 36, .address = Common::Size_2_GB , .size = Common::Size_64_GB - Common::Size_2_GB , .type = KAddressSpaceInfo::Type::MapLarge, }, 26 { .bit_width = 36, .address = 2_GiB , .size = 64_GiB - 2_GiB , .type = KAddressSpaceInfo::Type::MapLarge, },
23 { .bit_width = 36, .address = Common::Size_Invalid, .size = Common::Size_6_GB , .type = KAddressSpaceInfo::Type::Heap, }, 27 { .bit_width = 36, .address = Size_Invalid, .size = 6_GiB , .type = KAddressSpaceInfo::Type::Heap, },
24 { .bit_width = 36, .address = Common::Size_Invalid, .size = Common::Size_6_GB , .type = KAddressSpaceInfo::Type::Alias, }, 28 { .bit_width = 36, .address = Size_Invalid, .size = 6_GiB , .type = KAddressSpaceInfo::Type::Alias, },
25 { .bit_width = 39, .address = Common::Size_128_MB , .size = Common::Size_512_GB - Common::Size_128_MB, .type = KAddressSpaceInfo::Type::Map39Bit, }, 29 { .bit_width = 39, .address = 128_MiB , .size = 512_GiB - 128_MiB, .type = KAddressSpaceInfo::Type::Map39Bit, },
26 { .bit_width = 39, .address = Common::Size_Invalid, .size = Common::Size_64_GB , .type = KAddressSpaceInfo::Type::MapSmall }, 30 { .bit_width = 39, .address = Size_Invalid, .size = 64_GiB , .type = KAddressSpaceInfo::Type::MapSmall },
27 { .bit_width = 39, .address = Common::Size_Invalid, .size = Common::Size_6_GB , .type = KAddressSpaceInfo::Type::Heap, }, 31 { .bit_width = 39, .address = Size_Invalid, .size = 6_GiB , .type = KAddressSpaceInfo::Type::Heap, },
28 { .bit_width = 39, .address = Common::Size_Invalid, .size = Common::Size_64_GB , .type = KAddressSpaceInfo::Type::Alias, }, 32 { .bit_width = 39, .address = Size_Invalid, .size = 64_GiB , .type = KAddressSpaceInfo::Type::Alias, },
29 { .bit_width = 39, .address = Common::Size_Invalid, .size = Common::Size_2_GB , .type = KAddressSpaceInfo::Type::Stack, }, 33 { .bit_width = 39, .address = Size_Invalid, .size = 2_GiB , .type = KAddressSpaceInfo::Type::Stack, },
30}}; 34}};
31// clang-format on 35// clang-format on
32 36
33constexpr bool IsAllowedIndexForAddress(std::size_t index) { 37constexpr bool IsAllowedIndexForAddress(std::size_t index) {
34 return index < AddressSpaceInfos.size() && 38 return index < AddressSpaceInfos.size() && AddressSpaceInfos[index].address != Size_Invalid;
35 AddressSpaceInfos[index].address != Common::Size_Invalid;
36} 39}
37 40
38using IndexArray = 41using IndexArray =
diff --git a/src/core/hle/kernel/k_memory_layout.board.nintendo_nx.cpp b/src/core/hle/kernel/k_memory_layout.board.nintendo_nx.cpp
index a78551291..af652af58 100644
--- a/src/core/hle/kernel/k_memory_layout.board.nintendo_nx.cpp
+++ b/src/core/hle/kernel/k_memory_layout.board.nintendo_nx.cpp
@@ -3,6 +3,7 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include "common/alignment.h" 5#include "common/alignment.h"
6#include "common/literals.h"
6#include "core/hle/kernel/k_memory_layout.h" 7#include "core/hle/kernel/k_memory_layout.h"
7#include "core/hle/kernel/k_memory_manager.h" 8#include "core/hle/kernel/k_memory_manager.h"
8#include "core/hle/kernel/k_system_control.h" 9#include "core/hle/kernel/k_system_control.h"
@@ -12,8 +13,10 @@ namespace Kernel {
12 13
13namespace { 14namespace {
14 15
16using namespace Common::Literals;
17
15constexpr size_t CarveoutAlignment = 0x20000; 18constexpr size_t CarveoutAlignment = 0x20000;
16constexpr size_t CarveoutSizeMax = (512ULL * 1024 * 1024) - CarveoutAlignment; 19constexpr size_t CarveoutSizeMax = (512_MiB) - CarveoutAlignment;
17 20
18bool SetupPowerManagementControllerMemoryRegion(KMemoryLayout& memory_layout) { 21bool SetupPowerManagementControllerMemoryRegion(KMemoryLayout& memory_layout) {
19 // Above firmware 2.0.0, the PMC is not mappable. 22 // Above firmware 2.0.0, the PMC is not mappable.
diff --git a/src/core/hle/kernel/k_memory_layout.h b/src/core/hle/kernel/k_memory_layout.h
index 288642d9a..57ff538cc 100644
--- a/src/core/hle/kernel/k_memory_layout.h
+++ b/src/core/hle/kernel/k_memory_layout.h
@@ -7,8 +7,7 @@
7#include <utility> 7#include <utility>
8 8
9#include "common/alignment.h" 9#include "common/alignment.h"
10#include "common/common_sizes.h" 10#include "common/literals.h"
11#include "common/common_types.h"
12#include "core/device_memory.h" 11#include "core/device_memory.h"
13#include "core/hle/kernel/k_memory_region.h" 12#include "core/hle/kernel/k_memory_region.h"
14#include "core/hle/kernel/k_memory_region_type.h" 13#include "core/hle/kernel/k_memory_region_type.h"
@@ -16,20 +15,22 @@
16 15
17namespace Kernel { 16namespace Kernel {
18 17
19constexpr std::size_t L1BlockSize = Common::Size_1_GB; 18using namespace Common::Literals;
20constexpr std::size_t L2BlockSize = Common::Size_2_MB; 19
20constexpr std::size_t L1BlockSize = 1_GiB;
21constexpr std::size_t L2BlockSize = 2_MiB;
21 22
22constexpr std::size_t GetMaximumOverheadSize(std::size_t size) { 23constexpr std::size_t GetMaximumOverheadSize(std::size_t size) {
23 return (Common::DivideUp(size, L1BlockSize) + Common::DivideUp(size, L2BlockSize)) * PageSize; 24 return (Common::DivideUp(size, L1BlockSize) + Common::DivideUp(size, L2BlockSize)) * PageSize;
24} 25}
25 26
26constexpr std::size_t MainMemorySize = Common::Size_4_GB; 27constexpr std::size_t MainMemorySize = 4_GiB;
27constexpr std::size_t MainMemorySizeMax = Common::Size_8_GB; 28constexpr std::size_t MainMemorySizeMax = 8_GiB;
28 29
29constexpr std::size_t ReservedEarlyDramSize = 0x60000; 30constexpr std::size_t ReservedEarlyDramSize = 384_KiB;
30constexpr std::size_t DramPhysicalAddress = 0x80000000; 31constexpr std::size_t DramPhysicalAddress = 0x80000000;
31 32
32constexpr std::size_t KernelAslrAlignment = Common::Size_2_MB; 33constexpr std::size_t KernelAslrAlignment = 2_MiB;
33constexpr std::size_t KernelVirtualAddressSpaceWidth = 1ULL << 39; 34constexpr std::size_t KernelVirtualAddressSpaceWidth = 1ULL << 39;
34constexpr std::size_t KernelPhysicalAddressSpaceWidth = 1ULL << 48; 35constexpr std::size_t KernelPhysicalAddressSpaceWidth = 1ULL << 48;
35 36
@@ -40,7 +41,7 @@ constexpr std::size_t KernelVirtualAddressSpaceLast = KernelVirtualAddressSpaceE
40constexpr std::size_t KernelVirtualAddressSpaceSize = 41constexpr std::size_t KernelVirtualAddressSpaceSize =
41 KernelVirtualAddressSpaceEnd - KernelVirtualAddressSpaceBase; 42 KernelVirtualAddressSpaceEnd - KernelVirtualAddressSpaceBase;
42constexpr std::size_t KernelVirtualAddressCodeBase = KernelVirtualAddressSpaceBase; 43constexpr std::size_t KernelVirtualAddressCodeBase = KernelVirtualAddressSpaceBase;
43constexpr std::size_t KernelVirtualAddressCodeSize = 0x62000; 44constexpr std::size_t KernelVirtualAddressCodeSize = 392_KiB;
44constexpr std::size_t KernelVirtualAddressCodeEnd = 45constexpr std::size_t KernelVirtualAddressCodeEnd =
45 KernelVirtualAddressCodeBase + KernelVirtualAddressCodeSize; 46 KernelVirtualAddressCodeBase + KernelVirtualAddressCodeSize;
46 47
@@ -53,14 +54,14 @@ constexpr std::size_t KernelPhysicalAddressSpaceSize =
53constexpr std::size_t KernelPhysicalAddressCodeBase = DramPhysicalAddress + ReservedEarlyDramSize; 54constexpr std::size_t KernelPhysicalAddressCodeBase = DramPhysicalAddress + ReservedEarlyDramSize;
54 55
55constexpr std::size_t KernelPageTableHeapSize = GetMaximumOverheadSize(MainMemorySizeMax); 56constexpr std::size_t KernelPageTableHeapSize = GetMaximumOverheadSize(MainMemorySizeMax);
56constexpr std::size_t KernelInitialPageHeapSize = Common::Size_128_KB; 57constexpr std::size_t KernelInitialPageHeapSize = 128_KiB;
57 58
58constexpr std::size_t KernelSlabHeapDataSize = Common::Size_5_MB; 59constexpr std::size_t KernelSlabHeapDataSize = 5_MiB;
59constexpr std::size_t KernelSlabHeapGapsSize = Common::Size_2_MB - Common::Size_64_KB; 60constexpr std::size_t KernelSlabHeapGapsSize = 2_MiB - 64_KiB;
60constexpr std::size_t KernelSlabHeapSize = KernelSlabHeapDataSize + KernelSlabHeapGapsSize; 61constexpr std::size_t KernelSlabHeapSize = KernelSlabHeapDataSize + KernelSlabHeapGapsSize;
61 62
62// NOTE: This is calculated from KThread slab counts, assuming KThread size <= 0x860. 63// NOTE: This is calculated from KThread slab counts, assuming KThread size <= 0x860.
63constexpr std::size_t KernelSlabHeapAdditionalSize = 0x68000ULL; 64constexpr std::size_t KernelSlabHeapAdditionalSize = 416_KiB;
64 65
65constexpr std::size_t KernelResourceSize = 66constexpr std::size_t KernelResourceSize =
66 KernelPageTableHeapSize + KernelInitialPageHeapSize + KernelSlabHeapSize; 67 KernelPageTableHeapSize + KernelInitialPageHeapSize + KernelSlabHeapSize;
diff --git a/src/core/hle/kernel/k_page_table.cpp b/src/core/hle/kernel/k_page_table.cpp
index 66d260635..701268545 100644
--- a/src/core/hle/kernel/k_page_table.cpp
+++ b/src/core/hle/kernel/k_page_table.cpp
@@ -4,6 +4,7 @@
4 4
5#include "common/alignment.h" 5#include "common/alignment.h"
6#include "common/assert.h" 6#include "common/assert.h"
7#include "common/literals.h"
7#include "common/scope_exit.h" 8#include "common/scope_exit.h"
8#include "core/core.h" 9#include "core/core.h"
9#include "core/hle/kernel/k_address_space_info.h" 10#include "core/hle/kernel/k_address_space_info.h"
@@ -23,6 +24,8 @@ namespace Kernel {
23 24
24namespace { 25namespace {
25 26
27using namespace Common::Literals;
28
26constexpr std::size_t GetAddressSpaceWidthFromType(FileSys::ProgramAddressSpaceType as_type) { 29constexpr std::size_t GetAddressSpaceWidthFromType(FileSys::ProgramAddressSpaceType as_type) {
27 switch (as_type) { 30 switch (as_type) {
28 case FileSys::ProgramAddressSpaceType::Is32Bit: 31 case FileSys::ProgramAddressSpaceType::Is32Bit:
@@ -89,7 +92,7 @@ ResultCode KPageTable::InitializeForProcess(FileSys::ProgramAddressSpaceType as_
89 } 92 }
90 93
91 // Set code regions and determine remaining 94 // Set code regions and determine remaining
92 constexpr std::size_t RegionAlignment{2 * 1024 * 1024}; 95 constexpr std::size_t RegionAlignment{2_MiB};
93 VAddr process_code_start{}; 96 VAddr process_code_start{};
94 VAddr process_code_end{}; 97 VAddr process_code_end{};
95 std::size_t stack_region_size{}; 98 std::size_t stack_region_size{};
diff --git a/src/core/hle/kernel/k_trace.h b/src/core/hle/kernel/k_trace.h
index 91ebf9ab2..79391bccb 100644
--- a/src/core/hle/kernel/k_trace.h
+++ b/src/core/hle/kernel/k_trace.h
@@ -4,9 +4,13 @@
4 4
5#pragma once 5#pragma once
6 6
7#include "common/common_funcs.h"
8
7namespace Kernel { 9namespace Kernel {
8 10
11using namespace Common::Literals;
12
9constexpr bool IsKTraceEnabled = false; 13constexpr bool IsKTraceEnabled = false;
10constexpr std::size_t KTraceBufferSize = IsKTraceEnabled ? 16 * 1024 * 1024 : 0; 14constexpr std::size_t KTraceBufferSize = IsKTraceEnabled ? 16_MiB : 0;
11 15
12} // namespace Kernel 16} // namespace Kernel
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 2ceeaeb5f..64bd0c494 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -12,7 +12,6 @@
12#include <utility> 12#include <utility>
13 13
14#include "common/assert.h" 14#include "common/assert.h"
15#include "common/common_sizes.h"
16#include "common/logging/log.h" 15#include "common/logging/log.h"
17#include "common/microprofile.h" 16#include "common/microprofile.h"
18#include "common/thread.h" 17#include "common/thread.h"
@@ -180,7 +179,7 @@ struct KernelCore::Impl {
180 system_resource_limit->Reserve(LimitableResource::PhysicalMemory, kernel_size); 179 system_resource_limit->Reserve(LimitableResource::PhysicalMemory, kernel_size);
181 180
182 // Reserve secure applet memory, introduced in firmware 5.0.0 181 // Reserve secure applet memory, introduced in firmware 5.0.0
183 constexpr u64 secure_applet_memory_size{Common::Size_4_MB}; 182 constexpr u64 secure_applet_memory_size{4_MiB};
184 ASSERT(system_resource_limit->Reserve(LimitableResource::PhysicalMemory, 183 ASSERT(system_resource_limit->Reserve(LimitableResource::PhysicalMemory,
185 secure_applet_memory_size)); 184 secure_applet_memory_size));
186 185
@@ -320,8 +319,8 @@ struct KernelCore::Impl {
320 const VAddr code_end_virt_addr = KernelVirtualAddressCodeEnd; 319 const VAddr code_end_virt_addr = KernelVirtualAddressCodeEnd;
321 320
322 // Setup the containing kernel region. 321 // Setup the containing kernel region.
323 constexpr size_t KernelRegionSize = Common::Size_1_GB; 322 constexpr size_t KernelRegionSize = 1_GiB;
324 constexpr size_t KernelRegionAlign = Common::Size_1_GB; 323 constexpr size_t KernelRegionAlign = 1_GiB;
325 constexpr VAddr kernel_region_start = 324 constexpr VAddr kernel_region_start =
326 Common::AlignDown(code_start_virt_addr, KernelRegionAlign); 325 Common::AlignDown(code_start_virt_addr, KernelRegionAlign);
327 size_t kernel_region_size = KernelRegionSize; 326 size_t kernel_region_size = KernelRegionSize;
@@ -368,7 +367,7 @@ struct KernelCore::Impl {
368 367
369 // Decide on the actual size for the misc region. 368 // Decide on the actual size for the misc region.
370 constexpr size_t MiscRegionAlign = KernelAslrAlignment; 369 constexpr size_t MiscRegionAlign = KernelAslrAlignment;
371 constexpr size_t MiscRegionMinimumSize = Common::Size_32_MB; 370 constexpr size_t MiscRegionMinimumSize = 32_MiB;
372 const size_t misc_region_size = Common::AlignUp( 371 const size_t misc_region_size = Common::AlignUp(
373 std::max(misc_region_needed_size, MiscRegionMinimumSize), MiscRegionAlign); 372 std::max(misc_region_needed_size, MiscRegionMinimumSize), MiscRegionAlign);
374 ASSERT(misc_region_size > 0); 373 ASSERT(misc_region_size > 0);
@@ -381,7 +380,7 @@ struct KernelCore::Impl {
381 misc_region_start, misc_region_size, KMemoryRegionType_KernelMisc)); 380 misc_region_start, misc_region_size, KMemoryRegionType_KernelMisc));
382 381
383 // Setup the stack region. 382 // Setup the stack region.
384 constexpr size_t StackRegionSize = Common::Size_14_MB; 383 constexpr size_t StackRegionSize = 14_MiB;
385 constexpr size_t StackRegionAlign = KernelAslrAlignment; 384 constexpr size_t StackRegionAlign = KernelAslrAlignment;
386 const VAddr stack_region_start = 385 const VAddr stack_region_start =
387 memory_layout.GetVirtualMemoryRegionTree().GetRandomAlignedRegion( 386 memory_layout.GetVirtualMemoryRegionTree().GetRandomAlignedRegion(
@@ -414,7 +413,7 @@ struct KernelCore::Impl {
414 slab_region_start, slab_region_size, KMemoryRegionType_KernelSlab)); 413 slab_region_start, slab_region_size, KMemoryRegionType_KernelSlab));
415 414
416 // Setup the temp region. 415 // Setup the temp region.
417 constexpr size_t TempRegionSize = Common::Size_128_MB; 416 constexpr size_t TempRegionSize = 128_MiB;
418 constexpr size_t TempRegionAlign = KernelAslrAlignment; 417 constexpr size_t TempRegionAlign = KernelAslrAlignment;
419 const VAddr temp_region_start = 418 const VAddr temp_region_start =
420 memory_layout.GetVirtualMemoryRegionTree().GetRandomAlignedRegion( 419 memory_layout.GetVirtualMemoryRegionTree().GetRandomAlignedRegion(
@@ -470,7 +469,7 @@ struct KernelCore::Impl {
470 // Determine size available for kernel page table heaps, requiring > 8 MB. 469 // Determine size available for kernel page table heaps, requiring > 8 MB.
471 const PAddr resource_end_phys_addr = slab_start_phys_addr + resource_region_size; 470 const PAddr resource_end_phys_addr = slab_start_phys_addr + resource_region_size;
472 const size_t page_table_heap_size = resource_end_phys_addr - slab_end_phys_addr; 471 const size_t page_table_heap_size = resource_end_phys_addr - slab_end_phys_addr;
473 ASSERT(page_table_heap_size / Common::Size_4_MB > 2); 472 ASSERT(page_table_heap_size / 4_MiB > 2);
474 473
475 // Insert a physical region for the kernel page table heap region 474 // Insert a physical region for the kernel page table heap region
476 ASSERT(memory_layout.GetPhysicalMemoryRegionTree().Insert( 475 ASSERT(memory_layout.GetPhysicalMemoryRegionTree().Insert(
@@ -495,7 +494,7 @@ struct KernelCore::Impl {
495 ASSERT(linear_extents.GetEndAddress() != 0); 494 ASSERT(linear_extents.GetEndAddress() != 0);
496 495
497 // Setup the linear mapping region. 496 // Setup the linear mapping region.
498 constexpr size_t LinearRegionAlign = Common::Size_1_GB; 497 constexpr size_t LinearRegionAlign = 1_GiB;
499 const PAddr aligned_linear_phys_start = 498 const PAddr aligned_linear_phys_start =
500 Common::AlignDown(linear_extents.GetAddress(), LinearRegionAlign); 499 Common::AlignDown(linear_extents.GetAddress(), LinearRegionAlign);
501 const size_t linear_region_size = 500 const size_t linear_region_size =
diff --git a/src/tests/common/host_memory.cpp b/src/tests/common/host_memory.cpp
index e241f8be5..2dc7b5d5e 100644
--- a/src/tests/common/host_memory.cpp
+++ b/src/tests/common/host_memory.cpp
@@ -5,11 +5,13 @@
5#include <catch2/catch.hpp> 5#include <catch2/catch.hpp>
6 6
7#include "common/host_memory.h" 7#include "common/host_memory.h"
8#include "common/literals.h"
8 9
9using Common::HostMemory; 10using Common::HostMemory;
11using namespace Common::Literals;
10 12
11static constexpr size_t VIRTUAL_SIZE = 1ULL << 39; 13static constexpr size_t VIRTUAL_SIZE = 1ULL << 39;
12static constexpr size_t BACKING_SIZE = 4ULL * 1024 * 1024 * 1024; 14static constexpr size_t BACKING_SIZE = 4_GiB;
13 15
14TEST_CASE("HostMemory: Initialize and deinitialize", "[common]") { 16TEST_CASE("HostMemory: Initialize and deinitialize", "[common]") {
15 { HostMemory mem(BACKING_SIZE, VIRTUAL_SIZE); } 17 { HostMemory mem(BACKING_SIZE, VIRTUAL_SIZE); }
diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h
index 6d04d00da..9d726a6fb 100644
--- a/src/video_core/buffer_cache/buffer_cache.h
+++ b/src/video_core/buffer_cache/buffer_cache.h
@@ -16,9 +16,9 @@
16 16
17#include <boost/container/small_vector.hpp> 17#include <boost/container/small_vector.hpp>
18 18
19#include "common/common_sizes.h"
20#include "common/common_types.h" 19#include "common/common_types.h"
21#include "common/div_ceil.h" 20#include "common/div_ceil.h"
21#include "common/literals.h"
22#include "common/microprofile.h" 22#include "common/microprofile.h"
23#include "common/scope_exit.h" 23#include "common/scope_exit.h"
24#include "common/settings.h" 24#include "common/settings.h"
@@ -48,8 +48,11 @@ constexpr u32 NUM_COMPUTE_UNIFORM_BUFFERS = 8;
48constexpr u32 NUM_STORAGE_BUFFERS = 16; 48constexpr u32 NUM_STORAGE_BUFFERS = 16;
49constexpr u32 NUM_STAGES = 5; 49constexpr u32 NUM_STAGES = 5;
50 50
51using namespace Common::Literals;
52
51template <typename P> 53template <typename P>
52class BufferCache { 54class BufferCache {
55
53 // Page size for caching purposes. 56 // Page size for caching purposes.
54 // This is unrelated to the CPU page size and it can be changed as it seems optimal. 57 // This is unrelated to the CPU page size and it can be changed as it seems optimal.
55 static constexpr u32 PAGE_BITS = 16; 58 static constexpr u32 PAGE_BITS = 16;
@@ -66,8 +69,8 @@ class BufferCache {
66 69
67 static constexpr BufferId NULL_BUFFER_ID{0}; 70 static constexpr BufferId NULL_BUFFER_ID{0};
68 71
69 static constexpr u64 EXPECTED_MEMORY = Common::Size_512_MB; 72 static constexpr u64 EXPECTED_MEMORY = 512_MiB;
70 static constexpr u64 CRITICAL_MEMORY = Common::Size_1_GB; 73 static constexpr u64 CRITICAL_MEMORY = 1_GiB;
71 74
72 using Maxwell = Tegra::Engines::Maxwell3D::Regs; 75 using Maxwell = Tegra::Engines::Maxwell3D::Regs;
73 76
@@ -96,7 +99,7 @@ class BufferCache {
96 }; 99 };
97 100
98public: 101public:
99 static constexpr u32 DEFAULT_SKIP_CACHE_SIZE = 4096; 102 static constexpr u32 DEFAULT_SKIP_CACHE_SIZE = 4_KiB;
100 103
101 explicit BufferCache(VideoCore::RasterizerInterface& rasterizer_, 104 explicit BufferCache(VideoCore::RasterizerInterface& rasterizer_,
102 Tegra::Engines::Maxwell3D& maxwell3d_, 105 Tegra::Engines::Maxwell3D& maxwell3d_,
diff --git a/src/video_core/host_shaders/astc_decoder.comp b/src/video_core/host_shaders/astc_decoder.comp
index eaba1b103..c37f15bfd 100644
--- a/src/video_core/host_shaders/astc_decoder.comp
+++ b/src/video_core/host_shaders/astc_decoder.comp
@@ -11,12 +11,8 @@
11#define UNIFORM(n) 11#define UNIFORM(n)
12#define BINDING_INPUT_BUFFER 0 12#define BINDING_INPUT_BUFFER 0
13#define BINDING_ENC_BUFFER 1 13#define BINDING_ENC_BUFFER 1
14#define BINDING_6_TO_8_BUFFER 2 14#define BINDING_SWIZZLE_BUFFER 2
15#define BINDING_7_TO_8_BUFFER 3 15#define BINDING_OUTPUT_IMAGE 3
16#define BINDING_8_TO_8_BUFFER 4
17#define BINDING_BYTE_TO_16_BUFFER 5
18#define BINDING_SWIZZLE_BUFFER 6
19#define BINDING_OUTPUT_IMAGE 7
20 16
21#else // ^^^ Vulkan ^^^ // vvv OpenGL vvv 17#else // ^^^ Vulkan ^^^ // vvv OpenGL vvv
22 18
@@ -26,10 +22,6 @@
26#define BINDING_SWIZZLE_BUFFER 0 22#define BINDING_SWIZZLE_BUFFER 0
27#define BINDING_INPUT_BUFFER 1 23#define BINDING_INPUT_BUFFER 1
28#define BINDING_ENC_BUFFER 2 24#define BINDING_ENC_BUFFER 2
29#define BINDING_6_TO_8_BUFFER 3
30#define BINDING_7_TO_8_BUFFER 4
31#define BINDING_8_TO_8_BUFFER 5
32#define BINDING_BYTE_TO_16_BUFFER 6
33#define BINDING_OUTPUT_IMAGE 0 25#define BINDING_OUTPUT_IMAGE 0
34 26
35#endif 27#endif
@@ -76,19 +68,6 @@ layout(binding = BINDING_INPUT_BUFFER, std430) readonly buffer InputBufferU32 {
76layout(binding = BINDING_ENC_BUFFER, std430) readonly buffer EncodingsValues { 68layout(binding = BINDING_ENC_BUFFER, std430) readonly buffer EncodingsValues {
77 EncodingData encoding_values[]; 69 EncodingData encoding_values[];
78}; 70};
79// ASTC Precompiled tables
80layout(binding = BINDING_6_TO_8_BUFFER, std430) readonly buffer REPLICATE_6_BIT_TO_8 {
81 uint REPLICATE_6_BIT_TO_8_TABLE[];
82};
83layout(binding = BINDING_7_TO_8_BUFFER, std430) readonly buffer REPLICATE_7_BIT_TO_8 {
84 uint REPLICATE_7_BIT_TO_8_TABLE[];
85};
86layout(binding = BINDING_8_TO_8_BUFFER, std430) readonly buffer REPLICATE_8_BIT_TO_8 {
87 uint REPLICATE_8_BIT_TO_8_TABLE[];
88};
89layout(binding = BINDING_BYTE_TO_16_BUFFER, std430) readonly buffer REPLICATE_BYTE_TO_16 {
90 uint REPLICATE_BYTE_TO_16_TABLE[];
91};
92 71
93layout(binding = BINDING_OUTPUT_IMAGE, rgba8) uniform writeonly image2DArray dest_image; 72layout(binding = BINDING_OUTPUT_IMAGE, rgba8) uniform writeonly image2DArray dest_image;
94 73
@@ -139,6 +118,19 @@ const uint REPLICATE_4_BIT_TO_6_TABLE[16] =
139const uint REPLICATE_5_BIT_TO_6_TABLE[32] = 118const uint REPLICATE_5_BIT_TO_6_TABLE[32] =
140 uint[](0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 33, 35, 37, 39, 41, 43, 45, 119 uint[](0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 33, 35, 37, 39, 41, 43, 45,
141 47, 49, 51, 53, 55, 57, 59, 61, 63); 120 47, 49, 51, 53, 55, 57, 59, 61, 63);
121const uint REPLICATE_6_BIT_TO_8_TABLE[64] =
122 uint[](0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 65, 69, 73, 77, 81, 85, 89,
123 93, 97, 101, 105, 109, 113, 117, 121, 125, 130, 134, 138, 142, 146, 150, 154, 158, 162,
124 166, 170, 174, 178, 182, 186, 190, 195, 199, 203, 207, 211, 215, 219, 223, 227, 231, 235,
125 239, 243, 247, 251, 255);
126const uint REPLICATE_7_BIT_TO_8_TABLE[128] =
127 uint[](0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44,
128 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88,
129 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126,
130 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 157, 159, 161, 163,
131 165, 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 189, 191, 193, 195, 197, 199,
132 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 221, 223, 225, 227, 229, 231, 233, 235,
133 237, 239, 241, 243, 245, 247, 249, 251, 253, 255);
142 134
143// Input ASTC texture globals 135// Input ASTC texture globals
144uint current_index = 0; 136uint current_index = 0;
@@ -207,8 +199,7 @@ uint Replicate(uint val, uint num_bits, uint to_bit) {
207} 199}
208 200
209uvec4 ReplicateByteTo16(uvec4 value) { 201uvec4 ReplicateByteTo16(uvec4 value) {
210 return uvec4(REPLICATE_BYTE_TO_16_TABLE[value.x], REPLICATE_BYTE_TO_16_TABLE[value.y], 202 return value * 0x101;
211 REPLICATE_BYTE_TO_16_TABLE[value.z], REPLICATE_BYTE_TO_16_TABLE[value.w]);
212} 203}
213 204
214uint ReplicateBitTo7(uint value) { 205uint ReplicateBitTo7(uint value) {
@@ -236,7 +227,7 @@ uint FastReplicateTo8(uint value, uint num_bits) {
236 case 7: 227 case 7:
237 return REPLICATE_7_BIT_TO_8_TABLE[value]; 228 return REPLICATE_7_BIT_TO_8_TABLE[value];
238 case 8: 229 case 8:
239 return REPLICATE_8_BIT_TO_8_TABLE[value]; 230 return value;
240 } 231 }
241 return Replicate(value, num_bits, 8); 232 return Replicate(value, num_bits, 8);
242} 233}
@@ -1327,6 +1318,9 @@ void main() {
1327 offset += swizzle; 1318 offset += swizzle;
1328 1319
1329 const ivec3 coord = ivec3(gl_GlobalInvocationID * uvec3(block_dims, 1)); 1320 const ivec3 coord = ivec3(gl_GlobalInvocationID * uvec3(block_dims, 1));
1321 if (any(greaterThanEqual(coord, imageSize(dest_image)))) {
1322 return;
1323 }
1330 uint block_index = 1324 uint block_index =
1331 pos.z * gl_WorkGroupSize.x * gl_WorkGroupSize.y + pos.y * gl_WorkGroupSize.x + pos.x; 1325 pos.z * gl_WorkGroupSize.x * gl_WorkGroupSize.y + pos.y * gl_WorkGroupSize.x + pos.x;
1332 1326
diff --git a/src/video_core/renderer_opengl/gl_stream_buffer.h b/src/video_core/renderer_opengl/gl_stream_buffer.h
index 6dbb6bfba..2e67922a6 100644
--- a/src/video_core/renderer_opengl/gl_stream_buffer.h
+++ b/src/video_core/renderer_opengl/gl_stream_buffer.h
@@ -12,12 +12,15 @@
12#include <glad/glad.h> 12#include <glad/glad.h>
13 13
14#include "common/common_types.h" 14#include "common/common_types.h"
15#include "common/literals.h"
15#include "video_core/renderer_opengl/gl_resource_manager.h" 16#include "video_core/renderer_opengl/gl_resource_manager.h"
16 17
17namespace OpenGL { 18namespace OpenGL {
18 19
20using namespace Common::Literals;
21
19class StreamBuffer { 22class StreamBuffer {
20 static constexpr size_t STREAM_BUFFER_SIZE = 64 * 1024 * 1024; 23 static constexpr size_t STREAM_BUFFER_SIZE = 64_MiB;
21 static constexpr size_t NUM_SYNCS = 16; 24 static constexpr size_t NUM_SYNCS = 16;
22 static constexpr size_t REGION_SIZE = STREAM_BUFFER_SIZE / NUM_SYNCS; 25 static constexpr size_t REGION_SIZE = STREAM_BUFFER_SIZE / NUM_SYNCS;
23 static constexpr size_t MAX_ALIGNMENT = 256; 26 static constexpr size_t MAX_ALIGNMENT = 256;
diff --git a/src/video_core/renderer_opengl/util_shaders.cpp b/src/video_core/renderer_opengl/util_shaders.cpp
index 47fddcb6e..abaf1ee6a 100644
--- a/src/video_core/renderer_opengl/util_shaders.cpp
+++ b/src/video_core/renderer_opengl/util_shaders.cpp
@@ -69,7 +69,8 @@ UtilShaders::UtilShaders(ProgramManager& program_manager_)
69 swizzle_table_buffer.Create(); 69 swizzle_table_buffer.Create();
70 astc_buffer.Create(); 70 astc_buffer.Create();
71 glNamedBufferStorage(swizzle_table_buffer.handle, sizeof(swizzle_table), &swizzle_table, 0); 71 glNamedBufferStorage(swizzle_table_buffer.handle, sizeof(swizzle_table), &swizzle_table, 0);
72 glNamedBufferStorage(astc_buffer.handle, sizeof(ASTC_BUFFER_DATA), &ASTC_BUFFER_DATA, 0); 72 glNamedBufferStorage(astc_buffer.handle, sizeof(ASTC_ENCODINGS_VALUES), &ASTC_ENCODINGS_VALUES,
73 0);
73} 74}
74 75
75UtilShaders::~UtilShaders() = default; 76UtilShaders::~UtilShaders() = default;
@@ -79,12 +80,6 @@ void UtilShaders::ASTCDecode(Image& image, const ImageBufferMap& map,
79 static constexpr GLuint BINDING_SWIZZLE_BUFFER = 0; 80 static constexpr GLuint BINDING_SWIZZLE_BUFFER = 0;
80 static constexpr GLuint BINDING_INPUT_BUFFER = 1; 81 static constexpr GLuint BINDING_INPUT_BUFFER = 1;
81 static constexpr GLuint BINDING_ENC_BUFFER = 2; 82 static constexpr GLuint BINDING_ENC_BUFFER = 2;
82
83 static constexpr GLuint BINDING_6_TO_8_BUFFER = 3;
84 static constexpr GLuint BINDING_7_TO_8_BUFFER = 4;
85 static constexpr GLuint BINDING_8_TO_8_BUFFER = 5;
86 static constexpr GLuint BINDING_BYTE_TO_16_BUFFER = 6;
87
88 static constexpr GLuint BINDING_OUTPUT_IMAGE = 0; 83 static constexpr GLuint BINDING_OUTPUT_IMAGE = 0;
89 84
90 const Extent2D tile_size{ 85 const Extent2D tile_size{
@@ -93,21 +88,7 @@ void UtilShaders::ASTCDecode(Image& image, const ImageBufferMap& map,
93 }; 88 };
94 program_manager.BindHostCompute(astc_decoder_program.handle); 89 program_manager.BindHostCompute(astc_decoder_program.handle);
95 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BINDING_SWIZZLE_BUFFER, swizzle_table_buffer.handle); 90 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BINDING_SWIZZLE_BUFFER, swizzle_table_buffer.handle);
96 glBindBufferRange(GL_SHADER_STORAGE_BUFFER, BINDING_ENC_BUFFER, astc_buffer.handle, 91 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BINDING_ENC_BUFFER, astc_buffer.handle);
97 offsetof(AstcBufferData, encoding_values),
98 sizeof(AstcBufferData::encoding_values));
99 glBindBufferRange(GL_SHADER_STORAGE_BUFFER, BINDING_6_TO_8_BUFFER, astc_buffer.handle,
100 offsetof(AstcBufferData, replicate_6_to_8),
101 sizeof(AstcBufferData::replicate_6_to_8));
102 glBindBufferRange(GL_SHADER_STORAGE_BUFFER, BINDING_7_TO_8_BUFFER, astc_buffer.handle,
103 offsetof(AstcBufferData, replicate_7_to_8),
104 sizeof(AstcBufferData::replicate_7_to_8));
105 glBindBufferRange(GL_SHADER_STORAGE_BUFFER, BINDING_8_TO_8_BUFFER, astc_buffer.handle,
106 offsetof(AstcBufferData, replicate_8_to_8),
107 sizeof(AstcBufferData::replicate_8_to_8));
108 glBindBufferRange(GL_SHADER_STORAGE_BUFFER, BINDING_BYTE_TO_16_BUFFER, astc_buffer.handle,
109 offsetof(AstcBufferData, replicate_byte_to_16),
110 sizeof(AstcBufferData::replicate_byte_to_16));
111 92
112 glFlushMappedNamedBufferRange(map.buffer, map.offset, image.guest_size_bytes); 93 glFlushMappedNamedBufferRange(map.buffer, map.offset, image.guest_size_bytes);
113 glUniform2ui(1, tile_size.width, tile_size.height); 94 glUniform2ui(1, tile_size.width, tile_size.height);
@@ -137,6 +118,12 @@ void UtilShaders::ASTCDecode(Image& image, const ImageBufferMap& map,
137 118
138 glDispatchCompute(num_dispatches_x, num_dispatches_y, image.info.resources.layers); 119 glDispatchCompute(num_dispatches_x, num_dispatches_y, image.info.resources.layers);
139 } 120 }
121 // Precautionary barrier to ensure the compute shader is done decoding prior to texture access.
122 // GL_TEXTURE_FETCH_BARRIER_BIT and GL_SHADER_IMAGE_ACCESS_BARRIER_BIT are used in a separate
123 // glMemoryBarrier call by the texture cache runtime
124 glMemoryBarrier(GL_UNIFORM_BARRIER_BIT | GL_COMMAND_BARRIER_BIT | GL_PIXEL_BUFFER_BARRIER_BIT |
125 GL_TEXTURE_UPDATE_BARRIER_BIT | GL_BUFFER_UPDATE_BARRIER_BIT |
126 GL_SHADER_STORAGE_BARRIER_BIT | GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT);
140 program_manager.RestoreGuestCompute(); 127 program_manager.RestoreGuestCompute();
141} 128}
142 129
diff --git a/src/video_core/renderer_vulkan/vk_compute_pass.cpp b/src/video_core/renderer_vulkan/vk_compute_pass.cpp
index e11406e58..205cd3b05 100644
--- a/src/video_core/renderer_vulkan/vk_compute_pass.cpp
+++ b/src/video_core/renderer_vulkan/vk_compute_pass.cpp
@@ -30,19 +30,16 @@
30namespace Vulkan { 30namespace Vulkan {
31 31
32using Tegra::Texture::SWIZZLE_TABLE; 32using Tegra::Texture::SWIZZLE_TABLE;
33using Tegra::Texture::ASTC::EncodingsValues; 33using Tegra::Texture::ASTC::ASTC_ENCODINGS_VALUES;
34using namespace Tegra::Texture::ASTC; 34using namespace Tegra::Texture::ASTC;
35 35
36namespace { 36namespace {
37 37
38constexpr u32 ASTC_BINDING_INPUT_BUFFER = 0; 38constexpr u32 ASTC_BINDING_INPUT_BUFFER = 0;
39constexpr u32 ASTC_BINDING_ENC_BUFFER = 1; 39constexpr u32 ASTC_BINDING_ENC_BUFFER = 1;
40constexpr u32 ASTC_BINDING_6_TO_8_BUFFER = 2; 40constexpr u32 ASTC_BINDING_SWIZZLE_BUFFER = 2;
41constexpr u32 ASTC_BINDING_7_TO_8_BUFFER = 3; 41constexpr u32 ASTC_BINDING_OUTPUT_IMAGE = 3;
42constexpr u32 ASTC_BINDING_8_TO_8_BUFFER = 4; 42constexpr size_t ASTC_NUM_BINDINGS = 4;
43constexpr u32 ASTC_BINDING_BYTE_TO_16_BUFFER = 5;
44constexpr u32 ASTC_BINDING_SWIZZLE_BUFFER = 6;
45constexpr u32 ASTC_BINDING_OUTPUT_IMAGE = 7;
46 43
47VkPushConstantRange BuildComputePushConstantRange(std::size_t size) { 44VkPushConstantRange BuildComputePushConstantRange(std::size_t size) {
48 return { 45 return {
@@ -71,7 +68,7 @@ std::array<VkDescriptorSetLayoutBinding, 2> BuildInputOutputDescriptorSetBinding
71 }}; 68 }};
72} 69}
73 70
74std::array<VkDescriptorSetLayoutBinding, 8> BuildASTCDescriptorSetBindings() { 71std::array<VkDescriptorSetLayoutBinding, ASTC_NUM_BINDINGS> BuildASTCDescriptorSetBindings() {
75 return {{ 72 return {{
76 { 73 {
77 .binding = ASTC_BINDING_INPUT_BUFFER, 74 .binding = ASTC_BINDING_INPUT_BUFFER,
@@ -88,34 +85,6 @@ std::array<VkDescriptorSetLayoutBinding, 8> BuildASTCDescriptorSetBindings() {
88 .pImmutableSamplers = nullptr, 85 .pImmutableSamplers = nullptr,
89 }, 86 },
90 { 87 {
91 .binding = ASTC_BINDING_6_TO_8_BUFFER,
92 .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
93 .descriptorCount = 1,
94 .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
95 .pImmutableSamplers = nullptr,
96 },
97 {
98 .binding = ASTC_BINDING_7_TO_8_BUFFER,
99 .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
100 .descriptorCount = 1,
101 .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
102 .pImmutableSamplers = nullptr,
103 },
104 {
105 .binding = ASTC_BINDING_8_TO_8_BUFFER,
106 .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
107 .descriptorCount = 1,
108 .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
109 .pImmutableSamplers = nullptr,
110 },
111 {
112 .binding = ASTC_BINDING_BYTE_TO_16_BUFFER,
113 .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
114 .descriptorCount = 1,
115 .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
116 .pImmutableSamplers = nullptr,
117 },
118 {
119 .binding = ASTC_BINDING_SWIZZLE_BUFFER, 88 .binding = ASTC_BINDING_SWIZZLE_BUFFER,
120 .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 89 .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
121 .descriptorCount = 1, 90 .descriptorCount = 1,
@@ -143,7 +112,8 @@ VkDescriptorUpdateTemplateEntryKHR BuildInputOutputDescriptorUpdateTemplate() {
143 }; 112 };
144} 113}
145 114
146std::array<VkDescriptorUpdateTemplateEntryKHR, 8> BuildASTCPassDescriptorUpdateTemplateEntry() { 115std::array<VkDescriptorUpdateTemplateEntryKHR, ASTC_NUM_BINDINGS>
116BuildASTCPassDescriptorUpdateTemplateEntry() {
147 return {{ 117 return {{
148 { 118 {
149 .dstBinding = ASTC_BINDING_INPUT_BUFFER, 119 .dstBinding = ASTC_BINDING_INPUT_BUFFER,
@@ -162,38 +132,6 @@ std::array<VkDescriptorUpdateTemplateEntryKHR, 8> BuildASTCPassDescriptorUpdateT
162 .stride = sizeof(DescriptorUpdateEntry), 132 .stride = sizeof(DescriptorUpdateEntry),
163 }, 133 },
164 { 134 {
165 .dstBinding = ASTC_BINDING_6_TO_8_BUFFER,
166 .dstArrayElement = 0,
167 .descriptorCount = 1,
168 .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
169 .offset = ASTC_BINDING_6_TO_8_BUFFER * sizeof(DescriptorUpdateEntry),
170 .stride = sizeof(DescriptorUpdateEntry),
171 },
172 {
173 .dstBinding = ASTC_BINDING_7_TO_8_BUFFER,
174 .dstArrayElement = 0,
175 .descriptorCount = 1,
176 .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
177 .offset = ASTC_BINDING_7_TO_8_BUFFER * sizeof(DescriptorUpdateEntry),
178 .stride = sizeof(DescriptorUpdateEntry),
179 },
180 {
181 .dstBinding = ASTC_BINDING_8_TO_8_BUFFER,
182 .dstArrayElement = 0,
183 .descriptorCount = 1,
184 .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
185 .offset = ASTC_BINDING_8_TO_8_BUFFER * sizeof(DescriptorUpdateEntry),
186 .stride = sizeof(DescriptorUpdateEntry),
187 },
188 {
189 .dstBinding = ASTC_BINDING_BYTE_TO_16_BUFFER,
190 .dstArrayElement = 0,
191 .descriptorCount = 1,
192 .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
193 .offset = ASTC_BINDING_BYTE_TO_16_BUFFER * sizeof(DescriptorUpdateEntry),
194 .stride = sizeof(DescriptorUpdateEntry),
195 },
196 {
197 .dstBinding = ASTC_BINDING_SWIZZLE_BUFFER, 135 .dstBinding = ASTC_BINDING_SWIZZLE_BUFFER,
198 .dstArrayElement = 0, 136 .dstArrayElement = 0,
199 .descriptorCount = 1, 137 .descriptorCount = 1,
@@ -222,15 +160,6 @@ struct AstcPushConstants {
222 u32 block_height_mask; 160 u32 block_height_mask;
223}; 161};
224 162
225struct AstcBufferData {
226 decltype(SWIZZLE_TABLE) swizzle_table_buffer = SWIZZLE_TABLE;
227 decltype(EncodingsValues) encoding_values = EncodingsValues;
228 decltype(REPLICATE_6_BIT_TO_8_TABLE) replicate_6_to_8 = REPLICATE_6_BIT_TO_8_TABLE;
229 decltype(REPLICATE_7_BIT_TO_8_TABLE) replicate_7_to_8 = REPLICATE_7_BIT_TO_8_TABLE;
230 decltype(REPLICATE_8_BIT_TO_8_TABLE) replicate_8_to_8 = REPLICATE_8_BIT_TO_8_TABLE;
231 decltype(REPLICATE_BYTE_TO_16_TABLE) replicate_byte_to_16 = REPLICATE_BYTE_TO_16_TABLE;
232} constexpr ASTC_BUFFER_DATA;
233
234} // Anonymous namespace 163} // Anonymous namespace
235 164
236VKComputePass::VKComputePass(const Device& device, VKDescriptorPool& descriptor_pool, 165VKComputePass::VKComputePass(const Device& device, VKDescriptorPool& descriptor_pool,
@@ -423,7 +352,7 @@ ASTCDecoderPass::ASTCDecoderPass(const Device& device_, VKScheduler& scheduler_,
423ASTCDecoderPass::~ASTCDecoderPass() = default; 352ASTCDecoderPass::~ASTCDecoderPass() = default;
424 353
425void ASTCDecoderPass::MakeDataBuffer() { 354void ASTCDecoderPass::MakeDataBuffer() {
426 constexpr size_t TOTAL_BUFFER_SIZE = sizeof(ASTC_BUFFER_DATA) + sizeof(SWIZZLE_TABLE); 355 constexpr size_t TOTAL_BUFFER_SIZE = sizeof(ASTC_ENCODINGS_VALUES) + sizeof(SWIZZLE_TABLE);
427 data_buffer = device.GetLogical().CreateBuffer(VkBufferCreateInfo{ 356 data_buffer = device.GetLogical().CreateBuffer(VkBufferCreateInfo{
428 .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, 357 .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
429 .pNext = nullptr, 358 .pNext = nullptr,
@@ -437,9 +366,10 @@ void ASTCDecoderPass::MakeDataBuffer() {
437 data_buffer_commit = memory_allocator.Commit(data_buffer, MemoryUsage::Upload); 366 data_buffer_commit = memory_allocator.Commit(data_buffer, MemoryUsage::Upload);
438 367
439 const auto staging_ref = staging_buffer_pool.Request(TOTAL_BUFFER_SIZE, MemoryUsage::Upload); 368 const auto staging_ref = staging_buffer_pool.Request(TOTAL_BUFFER_SIZE, MemoryUsage::Upload);
440 std::memcpy(staging_ref.mapped_span.data(), &ASTC_BUFFER_DATA, sizeof(ASTC_BUFFER_DATA)); 369 std::memcpy(staging_ref.mapped_span.data(), &ASTC_ENCODINGS_VALUES,
370 sizeof(ASTC_ENCODINGS_VALUES));
441 // Tack on the swizzle table at the end of the buffer 371 // Tack on the swizzle table at the end of the buffer
442 std::memcpy(staging_ref.mapped_span.data() + sizeof(ASTC_BUFFER_DATA), &SWIZZLE_TABLE, 372 std::memcpy(staging_ref.mapped_span.data() + sizeof(ASTC_ENCODINGS_VALUES), &SWIZZLE_TABLE,
443 sizeof(SWIZZLE_TABLE)); 373 sizeof(SWIZZLE_TABLE));
444 374
445 scheduler.Record([src = staging_ref.buffer, offset = staging_ref.offset, dst = *data_buffer, 375 scheduler.Record([src = staging_ref.buffer, offset = staging_ref.offset, dst = *data_buffer,
@@ -509,18 +439,8 @@ void ASTCDecoderPass::Assemble(Image& image, const StagingBufferRef& map,
509 update_descriptor_queue.Acquire(); 439 update_descriptor_queue.Acquire();
510 update_descriptor_queue.AddBuffer(map.buffer, input_offset, 440 update_descriptor_queue.AddBuffer(map.buffer, input_offset,
511 image.guest_size_bytes - swizzle.buffer_offset); 441 image.guest_size_bytes - swizzle.buffer_offset);
512 update_descriptor_queue.AddBuffer(*data_buffer, offsetof(AstcBufferData, encoding_values), 442 update_descriptor_queue.AddBuffer(*data_buffer, 0, sizeof(ASTC_ENCODINGS_VALUES));
513 sizeof(AstcBufferData::encoding_values)); 443 update_descriptor_queue.AddBuffer(*data_buffer, sizeof(ASTC_ENCODINGS_VALUES),
514 update_descriptor_queue.AddBuffer(*data_buffer, offsetof(AstcBufferData, replicate_6_to_8),
515 sizeof(AstcBufferData::replicate_6_to_8));
516 update_descriptor_queue.AddBuffer(*data_buffer, offsetof(AstcBufferData, replicate_7_to_8),
517 sizeof(AstcBufferData::replicate_7_to_8));
518 update_descriptor_queue.AddBuffer(*data_buffer, offsetof(AstcBufferData, replicate_8_to_8),
519 sizeof(AstcBufferData::replicate_8_to_8));
520 update_descriptor_queue.AddBuffer(*data_buffer,
521 offsetof(AstcBufferData, replicate_byte_to_16),
522 sizeof(AstcBufferData::replicate_byte_to_16));
523 update_descriptor_queue.AddBuffer(*data_buffer, sizeof(AstcBufferData),
524 sizeof(SWIZZLE_TABLE)); 444 sizeof(SWIZZLE_TABLE));
525 update_descriptor_queue.AddImage(image.StorageImageView(swizzle.level)); 445 update_descriptor_queue.AddImage(image.StorageImageView(swizzle.level));
526 446
@@ -569,6 +489,7 @@ void ASTCDecoderPass::Assemble(Image& image, const StagingBufferRef& map,
569 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 489 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
570 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, image_barrier); 490 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, image_barrier);
571 }); 491 });
492 scheduler.Finish();
572} 493}
573 494
574} // namespace Vulkan 495} // namespace Vulkan
diff --git a/src/video_core/renderer_vulkan/vk_staging_buffer_pool.cpp b/src/video_core/renderer_vulkan/vk_staging_buffer_pool.cpp
index 7a1232497..0412b5234 100644
--- a/src/video_core/renderer_vulkan/vk_staging_buffer_pool.cpp
+++ b/src/video_core/renderer_vulkan/vk_staging_buffer_pool.cpp
@@ -12,6 +12,7 @@
12#include "common/assert.h" 12#include "common/assert.h"
13#include "common/bit_util.h" 13#include "common/bit_util.h"
14#include "common/common_types.h" 14#include "common/common_types.h"
15#include "common/literals.h"
15#include "video_core/renderer_vulkan/vk_scheduler.h" 16#include "video_core/renderer_vulkan/vk_scheduler.h"
16#include "video_core/renderer_vulkan/vk_staging_buffer_pool.h" 17#include "video_core/renderer_vulkan/vk_staging_buffer_pool.h"
17#include "video_core/vulkan_common/vulkan_device.h" 18#include "video_core/vulkan_common/vulkan_device.h"
@@ -19,12 +20,15 @@
19 20
20namespace Vulkan { 21namespace Vulkan {
21namespace { 22namespace {
23
24using namespace Common::Literals;
25
22// Maximum potential alignment of a Vulkan buffer 26// Maximum potential alignment of a Vulkan buffer
23constexpr VkDeviceSize MAX_ALIGNMENT = 256; 27constexpr VkDeviceSize MAX_ALIGNMENT = 256;
24// Maximum size to put elements in the stream buffer 28// Maximum size to put elements in the stream buffer
25constexpr VkDeviceSize MAX_STREAM_BUFFER_REQUEST_SIZE = 8 * 1024 * 1024; 29constexpr VkDeviceSize MAX_STREAM_BUFFER_REQUEST_SIZE = 8_MiB;
26// Stream buffer size in bytes 30// Stream buffer size in bytes
27constexpr VkDeviceSize STREAM_BUFFER_SIZE = 128 * 1024 * 1024; 31constexpr VkDeviceSize STREAM_BUFFER_SIZE = 128_MiB;
28constexpr VkDeviceSize REGION_SIZE = STREAM_BUFFER_SIZE / StagingBufferPool::NUM_SYNCS; 32constexpr VkDeviceSize REGION_SIZE = STREAM_BUFFER_SIZE / StagingBufferPool::NUM_SYNCS;
29 33
30constexpr VkMemoryPropertyFlags HOST_FLAGS = 34constexpr VkMemoryPropertyFlags HOST_FLAGS =
diff --git a/src/video_core/renderer_vulkan/vk_stream_buffer.cpp b/src/video_core/renderer_vulkan/vk_stream_buffer.cpp
index a09fe084e..7b4875d0e 100644
--- a/src/video_core/renderer_vulkan/vk_stream_buffer.cpp
+++ b/src/video_core/renderer_vulkan/vk_stream_buffer.cpp
@@ -10,6 +10,7 @@
10 10
11#include "common/alignment.h" 11#include "common/alignment.h"
12#include "common/assert.h" 12#include "common/assert.h"
13#include "common/literals.h"
13#include "video_core/renderer_vulkan/vk_scheduler.h" 14#include "video_core/renderer_vulkan/vk_scheduler.h"
14#include "video_core/renderer_vulkan/vk_stream_buffer.h" 15#include "video_core/renderer_vulkan/vk_stream_buffer.h"
15#include "video_core/vulkan_common/vulkan_device.h" 16#include "video_core/vulkan_common/vulkan_device.h"
@@ -19,6 +20,8 @@ namespace Vulkan {
19 20
20namespace { 21namespace {
21 22
23using namespace Common::Literals;
24
22constexpr VkBufferUsageFlags BUFFER_USAGE = 25constexpr VkBufferUsageFlags BUFFER_USAGE =
23 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT | 26 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT |
24 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; 27 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
@@ -26,7 +29,7 @@ constexpr VkBufferUsageFlags BUFFER_USAGE =
26constexpr u64 WATCHES_INITIAL_RESERVE = 0x4000; 29constexpr u64 WATCHES_INITIAL_RESERVE = 0x4000;
27constexpr u64 WATCHES_RESERVE_CHUNK = 0x1000; 30constexpr u64 WATCHES_RESERVE_CHUNK = 0x1000;
28 31
29constexpr u64 PREFERRED_STREAM_BUFFER_SIZE = 256 * 1024 * 1024; 32constexpr u64 PREFERRED_STREAM_BUFFER_SIZE = 256_MiB;
30 33
31/// Find a memory type with the passed requirements 34/// Find a memory type with the passed requirements
32std::optional<u32> FindMemoryType(const VkPhysicalDeviceMemoryProperties& properties, 35std::optional<u32> FindMemoryType(const VkPhysicalDeviceMemoryProperties& properties,
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h
index e7f8478b4..84530a179 100644
--- a/src/video_core/texture_cache/texture_cache.h
+++ b/src/video_core/texture_cache/texture_cache.h
@@ -19,9 +19,8 @@
19#include <boost/container/small_vector.hpp> 19#include <boost/container/small_vector.hpp>
20 20
21#include "common/alignment.h" 21#include "common/alignment.h"
22#include "common/common_funcs.h"
23#include "common/common_sizes.h"
24#include "common/common_types.h" 22#include "common/common_types.h"
23#include "common/literals.h"
25#include "common/logging/log.h" 24#include "common/logging/log.h"
26#include "common/settings.h" 25#include "common/settings.h"
27#include "video_core/compatible_formats.h" 26#include "video_core/compatible_formats.h"
@@ -59,6 +58,7 @@ using VideoCore::Surface::PixelFormat;
59using VideoCore::Surface::PixelFormatFromDepthFormat; 58using VideoCore::Surface::PixelFormatFromDepthFormat;
60using VideoCore::Surface::PixelFormatFromRenderTargetFormat; 59using VideoCore::Surface::PixelFormatFromRenderTargetFormat;
61using VideoCore::Surface::SurfaceType; 60using VideoCore::Surface::SurfaceType;
61using namespace Common::Literals;
62 62
63template <class P> 63template <class P>
64class TextureCache { 64class TextureCache {
@@ -79,8 +79,8 @@ class TextureCache {
79 /// Sampler ID for bugged sampler ids 79 /// Sampler ID for bugged sampler ids
80 static constexpr SamplerId NULL_SAMPLER_ID{0}; 80 static constexpr SamplerId NULL_SAMPLER_ID{0};
81 81
82 static constexpr u64 DEFAULT_EXPECTED_MEMORY = Common::Size_1_GB; 82 static constexpr u64 DEFAULT_EXPECTED_MEMORY = 1_GiB;
83 static constexpr u64 DEFAULT_CRITICAL_MEMORY = Common::Size_2_GB; 83 static constexpr u64 DEFAULT_CRITICAL_MEMORY = 2_GiB;
84 84
85 using Runtime = typename P::Runtime; 85 using Runtime = typename P::Runtime;
86 using Image = typename P::Image; 86 using Image = typename P::Image;
@@ -400,8 +400,8 @@ TextureCache<P>::TextureCache(Runtime& runtime_, VideoCore::RasterizerInterface&
400 minimum_memory = 0; 400 minimum_memory = 0;
401 } else { 401 } else {
402 // on OGL we can be more conservatives as the driver takes care. 402 // on OGL we can be more conservatives as the driver takes care.
403 expected_memory = DEFAULT_EXPECTED_MEMORY + Common::Size_512_MB; 403 expected_memory = DEFAULT_EXPECTED_MEMORY + 512_MiB;
404 critical_memory = DEFAULT_CRITICAL_MEMORY + Common::Size_1_GB; 404 critical_memory = DEFAULT_CRITICAL_MEMORY + 1_GiB;
405 minimum_memory = expected_memory; 405 minimum_memory = expected_memory;
406 } 406 }
407} 407}
diff --git a/src/video_core/textures/astc.cpp b/src/video_core/textures/astc.cpp
index 9b2177ebd..7b756ba41 100644
--- a/src/video_core/textures/astc.cpp
+++ b/src/video_core/textures/astc.cpp
@@ -269,7 +269,7 @@ static void DecodeQuintBlock(InputBitStream& bits, IntegerEncodedVector& result,
269static void DecodeIntegerSequence(IntegerEncodedVector& result, InputBitStream& bits, u32 maxRange, 269static void DecodeIntegerSequence(IntegerEncodedVector& result, InputBitStream& bits, u32 maxRange,
270 u32 nValues) { 270 u32 nValues) {
271 // Determine encoding parameters 271 // Determine encoding parameters
272 IntegerEncodedValue val = EncodingsValues[maxRange]; 272 IntegerEncodedValue val = ASTC_ENCODINGS_VALUES[maxRange];
273 273
274 // Start decoding 274 // Start decoding
275 u32 nValsDecoded = 0; 275 u32 nValsDecoded = 0;
@@ -310,7 +310,7 @@ struct TexelWeightParams {
310 nIdxs *= 2; 310 nIdxs *= 2;
311 } 311 }
312 312
313 return EncodingsValues[m_MaxWeight].GetBitLength(nIdxs); 313 return ASTC_ENCODINGS_VALUES[m_MaxWeight].GetBitLength(nIdxs);
314 } 314 }
315 315
316 u32 GetNumWeightValues() const { 316 u32 GetNumWeightValues() const {
@@ -551,6 +551,8 @@ static void FillError(std::span<u32> outBuf, u32 blockWidth, u32 blockHeight) {
551 } 551 }
552 } 552 }
553} 553}
554
555static constexpr auto REPLICATE_BYTE_TO_16_TABLE = MakeReplicateTable<u32, 8, 16>();
554static constexpr u32 ReplicateByteTo16(std::size_t value) { 556static constexpr u32 ReplicateByteTo16(std::size_t value) {
555 return REPLICATE_BYTE_TO_16_TABLE[value]; 557 return REPLICATE_BYTE_TO_16_TABLE[value];
556} 558}
@@ -753,12 +755,12 @@ static void DecodeColorValues(u32* out, std::span<u8> data, const u32* modes, co
753 // figure out the max value for each of them... 755 // figure out the max value for each of them...
754 u32 range = 256; 756 u32 range = 256;
755 while (--range > 0) { 757 while (--range > 0) {
756 IntegerEncodedValue val = EncodingsValues[range]; 758 IntegerEncodedValue val = ASTC_ENCODINGS_VALUES[range];
757 u32 bitLength = val.GetBitLength(nValues); 759 u32 bitLength = val.GetBitLength(nValues);
758 if (bitLength <= nBitsForColorData) { 760 if (bitLength <= nBitsForColorData) {
759 // Find the smallest possible range that matches the given encoding 761 // Find the smallest possible range that matches the given encoding
760 while (--range > 0) { 762 while (--range > 0) {
761 IntegerEncodedValue newval = EncodingsValues[range]; 763 IntegerEncodedValue newval = ASTC_ENCODINGS_VALUES[range];
762 if (!newval.MatchesEncoding(val)) { 764 if (!newval.MatchesEncoding(val)) {
763 break; 765 break;
764 } 766 }
diff --git a/src/video_core/textures/astc.h b/src/video_core/textures/astc.h
index c1c37dfe7..0229ae122 100644
--- a/src/video_core/textures/astc.h
+++ b/src/video_core/textures/astc.h
@@ -77,7 +77,7 @@ constexpr std::array<IntegerEncodedValue, 256> MakeEncodedValues() {
77 return encodings; 77 return encodings;
78} 78}
79 79
80constexpr std::array<IntegerEncodedValue, 256> EncodingsValues = MakeEncodedValues(); 80constexpr std::array<IntegerEncodedValue, 256> ASTC_ENCODINGS_VALUES = MakeEncodedValues();
81 81
82// Replicates low num_bits such that [(to_bit - 1):(to_bit - 1 - from_bit)] 82// Replicates low num_bits such that [(to_bit - 1):(to_bit - 1 - from_bit)]
83// is the same as [(num_bits - 1):0] and repeats all the way down. 83// is the same as [(num_bits - 1):0] and repeats all the way down.
@@ -116,19 +116,10 @@ constexpr auto MakeReplicateTable() {
116 return table; 116 return table;
117} 117}
118 118
119constexpr auto REPLICATE_BYTE_TO_16_TABLE = MakeReplicateTable<u32, 8, 16>();
120constexpr auto REPLICATE_6_BIT_TO_8_TABLE = MakeReplicateTable<u32, 6, 8>(); 119constexpr auto REPLICATE_6_BIT_TO_8_TABLE = MakeReplicateTable<u32, 6, 8>();
121constexpr auto REPLICATE_7_BIT_TO_8_TABLE = MakeReplicateTable<u32, 7, 8>(); 120constexpr auto REPLICATE_7_BIT_TO_8_TABLE = MakeReplicateTable<u32, 7, 8>();
122constexpr auto REPLICATE_8_BIT_TO_8_TABLE = MakeReplicateTable<u32, 8, 8>(); 121constexpr auto REPLICATE_8_BIT_TO_8_TABLE = MakeReplicateTable<u32, 8, 8>();
123 122
124struct AstcBufferData {
125 decltype(EncodingsValues) encoding_values = EncodingsValues;
126 decltype(REPLICATE_6_BIT_TO_8_TABLE) replicate_6_to_8 = REPLICATE_6_BIT_TO_8_TABLE;
127 decltype(REPLICATE_7_BIT_TO_8_TABLE) replicate_7_to_8 = REPLICATE_7_BIT_TO_8_TABLE;
128 decltype(REPLICATE_8_BIT_TO_8_TABLE) replicate_8_to_8 = REPLICATE_8_BIT_TO_8_TABLE;
129 decltype(REPLICATE_BYTE_TO_16_TABLE) replicate_byte_to_16 = REPLICATE_BYTE_TO_16_TABLE;
130} constexpr ASTC_BUFFER_DATA;
131
132void Decompress(std::span<const uint8_t> data, uint32_t width, uint32_t height, uint32_t depth, 123void Decompress(std::span<const uint8_t> data, uint32_t width, uint32_t height, uint32_t depth,
133 uint32_t block_width, uint32_t block_height, std::span<uint8_t> output); 124 uint32_t block_width, uint32_t block_height, std::span<uint8_t> output);
134 125
diff --git a/src/video_core/vulkan_common/vulkan_device.cpp b/src/video_core/vulkan_common/vulkan_device.cpp
index 707a8b8fb..23814afd2 100644
--- a/src/video_core/vulkan_common/vulkan_device.cpp
+++ b/src/video_core/vulkan_common/vulkan_device.cpp
@@ -821,9 +821,9 @@ void Device::CollectTelemetryParameters() {
821 821
822void Device::CollectPhysicalMemoryInfo() { 822void Device::CollectPhysicalMemoryInfo() {
823 const auto mem_properties = physical.GetMemoryProperties(); 823 const auto mem_properties = physical.GetMemoryProperties();
824 const std::size_t num_properties = mem_properties.memoryHeapCount; 824 const size_t num_properties = mem_properties.memoryHeapCount;
825 device_access_memory = 0; 825 device_access_memory = 0;
826 for (std::size_t element = 0; element < num_properties; element++) { 826 for (size_t element = 0; element < num_properties; ++element) {
827 if ((mem_properties.memoryHeaps[element].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) != 0) { 827 if ((mem_properties.memoryHeaps[element].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) != 0) {
828 device_access_memory += mem_properties.memoryHeaps[element].size; 828 device_access_memory += mem_properties.memoryHeaps[element].size;
829 } 829 }
diff --git a/src/video_core/vulkan_common/vulkan_device.h b/src/video_core/vulkan_common/vulkan_device.h
index a1aba973b..88b298196 100644
--- a/src/video_core/vulkan_common/vulkan_device.h
+++ b/src/video_core/vulkan_common/vulkan_device.h
@@ -264,21 +264,22 @@ private:
264 bool IsFormatSupported(VkFormat wanted_format, VkFormatFeatureFlags wanted_usage, 264 bool IsFormatSupported(VkFormat wanted_format, VkFormatFeatureFlags wanted_usage,
265 FormatType format_type) const; 265 FormatType format_type) const;
266 266
267 VkInstance instance; ///< Vulkan instance. 267 VkInstance instance; ///< Vulkan instance.
268 vk::DeviceDispatch dld; ///< Device function pointers. 268 vk::DeviceDispatch dld; ///< Device function pointers.
269 vk::PhysicalDevice physical; ///< Physical device. 269 vk::PhysicalDevice physical; ///< Physical device.
270 VkPhysicalDeviceProperties properties; ///< Device properties. 270 VkPhysicalDeviceProperties properties; ///< Device properties.
271 vk::Device logical; ///< Logical device. 271 vk::Device logical; ///< Logical device.
272 vk::Queue graphics_queue; ///< Main graphics queue. 272 vk::Queue graphics_queue; ///< Main graphics queue.
273 vk::Queue present_queue; ///< Main present queue. 273 vk::Queue present_queue; ///< Main present queue.
274 u32 instance_version{}; ///< Vulkan onstance version. 274 u32 instance_version{}; ///< Vulkan onstance version.
275 u32 graphics_family{}; ///< Main graphics queue family index. 275 u32 graphics_family{}; ///< Main graphics queue family index.
276 u32 present_family{}; ///< Main present queue family index. 276 u32 present_family{}; ///< Main present queue family index.
277 VkDriverIdKHR driver_id{}; ///< Driver ID. 277 VkDriverIdKHR driver_id{}; ///< Driver ID.
278 VkShaderStageFlags guest_warp_stages{}; ///< Stages where the guest warp size can be forced.ed 278 VkShaderStageFlags guest_warp_stages{}; ///< Stages where the guest warp size can be forced.
279 bool is_optimal_astc_supported{}; ///< Support for native ASTC. 279 u64 device_access_memory{}; ///< Total size of device local memory in bytes.
280 bool is_float16_supported{}; ///< Support for float16 arithmetics. 280 bool is_optimal_astc_supported{}; ///< Support for native ASTC.
281 bool is_warp_potentially_bigger{}; ///< Host warp size can be bigger than guest. 281 bool is_float16_supported{}; ///< Support for float16 arithmetics.
282 bool is_warp_potentially_bigger{}; ///< Host warp size can be bigger than guest.
282 bool is_formatless_image_load_supported{}; ///< Support for shader image read without format. 283 bool is_formatless_image_load_supported{}; ///< Support for shader image read without format.
283 bool is_shader_storage_image_multisample{}; ///< Support for image operations on MSAA images. 284 bool is_shader_storage_image_multisample{}; ///< Support for image operations on MSAA images.
284 bool is_blit_depth_stencil_supported{}; ///< Support for blitting from and to depth stencil. 285 bool is_blit_depth_stencil_supported{}; ///< Support for blitting from and to depth stencil.
@@ -309,8 +310,6 @@ private:
309 310
310 /// Nsight Aftermath GPU crash tracker 311 /// Nsight Aftermath GPU crash tracker
311 std::unique_ptr<NsightAftermathTracker> nsight_aftermath_tracker; 312 std::unique_ptr<NsightAftermathTracker> nsight_aftermath_tracker;
312
313 u64 device_access_memory;
314}; 313};
315 314
316} // namespace Vulkan 315} // namespace Vulkan