Compare commits
193 Commits
__refs_pul
...
__refs_pul
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
67fa51ea2f | ||
|
|
0dce6d7008 | ||
|
|
3ed0115e36 | ||
|
|
d65f079cc1 | ||
|
|
fee8bdd90c | ||
|
|
fde2017a3f | ||
|
|
ebf5768340 | ||
|
|
a4ac3bed6c | ||
|
|
da3da6be90 | ||
|
|
2a472ff54d | ||
|
|
c4ed0b16b1 | ||
|
|
c7f2fb2151 | ||
|
|
232b0d9d2a | ||
|
|
74e08b4800 | ||
|
|
a1bdc597e9 | ||
|
|
c5ea6db02d | ||
|
|
c7c4e6dcba | ||
|
|
c5c0da41b4 | ||
|
|
f835349364 | ||
|
|
12ba80a86c | ||
|
|
1fd979f50a | ||
|
|
b2ca8089ce | ||
|
|
e70a3c5a5d | ||
|
|
d1b1c42c07 | ||
|
|
dd35b4b18a | ||
|
|
4877e6c2f6 | ||
|
|
8e8326595f | ||
|
|
8ce02d85e9 | ||
|
|
b38d67d940 | ||
|
|
cea627b0fc | ||
|
|
5abf71fe65 | ||
|
|
eef0c93643 | ||
|
|
125d7122ac | ||
|
|
ad1220e1b3 | ||
|
|
92b85fad70 | ||
|
|
cb8b371570 | ||
|
|
38517241ec | ||
|
|
15cc34b93e | ||
|
|
99fc32428a | ||
|
|
d63b1d21f1 | ||
|
|
ac68c8a605 | ||
|
|
c2695aa2eb | ||
|
|
16b83fac9b | ||
|
|
a769d8c913 | ||
|
|
a0e2bd85a5 | ||
|
|
29ac15d1b8 | ||
|
|
0057a47e41 | ||
|
|
5a53d75313 | ||
|
|
8dd9cb98ce | ||
|
|
c95c4442e9 | ||
|
|
37f2ec6fc2 | ||
|
|
624239ed6b | ||
|
|
5678ec0dd0 | ||
|
|
3f4fb4b037 | ||
|
|
bfb28c5b3f | ||
|
|
f2d5b100c2 | ||
|
|
6923ecee3a | ||
|
|
36090521ce | ||
|
|
cc71832b19 | ||
|
|
bf89a99839 | ||
|
|
79243b6fa0 | ||
|
|
b0f7713fce | ||
|
|
8c9abe1d41 | ||
|
|
ca58929eb0 | ||
|
|
523e4be02c | ||
|
|
fde3b1b6f2 | ||
|
|
477eee3993 | ||
|
|
93a4097e9d | ||
|
|
e3bddf8137 | ||
|
|
c4ce7e456a | ||
|
|
e33452f7e8 | ||
|
|
5aaee2ff8d | ||
|
|
2ae88feea7 | ||
|
|
16db8b9d9f | ||
|
|
948002635f | ||
|
|
ea99819f37 | ||
|
|
eac3cf301c | ||
|
|
fc5b489b0f | ||
|
|
19b05c3f55 | ||
|
|
2788144f46 | ||
|
|
96463d0a55 | ||
|
|
dd70ddad7e | ||
|
|
c0fb321935 | ||
|
|
34f3d58470 | ||
|
|
b5fb246a99 | ||
|
|
c6fda4c758 | ||
|
|
609cb04f3f | ||
|
|
eb88fedc5d | ||
|
|
f5b132676f | ||
|
|
0fcdf37917 | ||
|
|
350f6e0aa4 | ||
|
|
9d8f19d7bf | ||
|
|
38cd4e9c61 | ||
|
|
f9a26d468c | ||
|
|
1277556c69 | ||
|
|
dfdf4a46fe | ||
|
|
69dd37d874 | ||
|
|
f13a66b963 | ||
|
|
2b9eee4d1e | ||
|
|
b1d238bbb8 | ||
|
|
f24ab6d9e6 | ||
|
|
46ef072cf9 | ||
|
|
6bcdf37d4f | ||
|
|
bc16f7f3cc | ||
|
|
ba8ff096fd | ||
|
|
7784ce1854 | ||
|
|
e8cb6f5c9b | ||
|
|
9e9a4bb3a7 | ||
|
|
d7c68fbb12 | ||
|
|
3fe77be392 | ||
|
|
028d90eb79 | ||
|
|
296e57fa0e | ||
|
|
b20ed93884 | ||
|
|
185b35bfcd | ||
|
|
943771e703 | ||
|
|
ce4b77bd7d | ||
|
|
6ee8b15abe | ||
|
|
23d45715dc | ||
|
|
ffd60ee476 | ||
|
|
8a88110060 | ||
|
|
6cf719a4ab | ||
|
|
51ddb130c5 | ||
|
|
9b17486be6 | ||
|
|
0a1d4fbc5c | ||
|
|
f7edbcd7a3 | ||
|
|
b0eb580931 | ||
|
|
85da529f15 | ||
|
|
7fb406c3fc | ||
|
|
3ef4b3d4b4 | ||
|
|
73b937b190 | ||
|
|
656758fd81 | ||
|
|
29d4f8c2dd | ||
|
|
9baf5de90c | ||
|
|
d6cb22b0df | ||
|
|
1b92ae136f | ||
|
|
731701a2d2 | ||
|
|
706fc5d2d6 | ||
|
|
27da7bc9da | ||
|
|
9b1c49a9cf | ||
|
|
e0f66c1fbf | ||
|
|
8335b2f115 | ||
|
|
367feaefa0 | ||
|
|
71cc482bbd | ||
|
|
ff358d97e8 | ||
|
|
2e95ba2e9c | ||
|
|
6eba539f4a | ||
|
|
63dff47e22 | ||
|
|
504cff2b7a | ||
|
|
804aebf7c7 | ||
|
|
2003771789 | ||
|
|
f246fd778d | ||
|
|
1db7839f11 | ||
|
|
224be09d66 | ||
|
|
e341d868ee | ||
|
|
da7226442f | ||
|
|
727136a9c9 | ||
|
|
0d9b3e425e | ||
|
|
ce56b8e1fa | ||
|
|
cef35e7c9c | ||
|
|
928e78dced | ||
|
|
3fd78f4d24 | ||
|
|
a0ce6de913 | ||
|
|
94329038b6 | ||
|
|
24a759de4a | ||
|
|
b39cd70cd4 | ||
|
|
89c3d6a2a3 | ||
|
|
0769aa594e | ||
|
|
c8e3f98c27 | ||
|
|
c5284efd4f | ||
|
|
60f476cd8f | ||
|
|
10f494eefe | ||
|
|
448290bee4 | ||
|
|
2592e41301 | ||
|
|
0b6f8ba51e | ||
|
|
d0b2950434 | ||
|
|
42431d2aa6 | ||
|
|
b8e70faa2d | ||
|
|
662218e997 | ||
|
|
c3013c7c9c | ||
|
|
acff922762 | ||
|
|
dfea525cbe | ||
|
|
82fa0bcea7 | ||
|
|
4fa4d80c68 | ||
|
|
6aa8ee6943 | ||
|
|
b76ddb7647 | ||
|
|
2a3b335b15 | ||
|
|
4e1471ef21 | ||
|
|
e9978fd4f5 | ||
|
|
75169c7570 | ||
|
|
03d7faf583 | ||
|
|
6f691e71bf | ||
|
|
5f8d253ce0 | ||
|
|
ed8b2a0254 |
2
externals/boost
vendored
2
externals/boost
vendored
Submodule externals/boost updated: d80e506e17...0b920df1c9
2
externals/dynarmic
vendored
2
externals/dynarmic
vendored
Submodule externals/dynarmic updated: 0118ee04f9...a42f301c28
2
externals/fmt
vendored
2
externals/fmt
vendored
Submodule externals/fmt updated: c2ce7e4f07...62010520ed
@@ -46,7 +46,7 @@ void Filter::Process(std::vector<s16>& signal) {
|
||||
out[0][ch] = b0 * in[0][ch] + b1 * in[1][ch] + b2 * in[2][ch] - a1 * out[1][ch] -
|
||||
a2 * out[2][ch];
|
||||
|
||||
signal[i * 2 + ch] = std::clamp(out[0][ch], -32768.0, 32767.0);
|
||||
signal[i * 2 + ch] = static_cast<s16>(std::clamp(out[0][ch], -32768.0, 32767.0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,8 +178,7 @@ public:
|
||||
return ExtractValue(storage);
|
||||
}
|
||||
|
||||
// TODO: we may want to change this to explicit operator bool() if it's bug-free in VS2015
|
||||
constexpr FORCE_INLINE bool ToBool() const {
|
||||
constexpr explicit operator bool() const {
|
||||
return Value() != 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "common/hex_util.h"
|
||||
|
||||
namespace Common {
|
||||
|
||||
u8 ToHexNibble(char c1) {
|
||||
if (c1 >= 65 && c1 <= 70)
|
||||
return c1 - 55;
|
||||
@@ -25,3 +27,5 @@ std::array<u8, 32> operator""_array32(const char* str, size_t len) {
|
||||
throw std::logic_error("Not of correct size.");
|
||||
return HexStringToArray<32>(str);
|
||||
}
|
||||
|
||||
} // namespace Common
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <fmt/format.h>
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Common {
|
||||
|
||||
u8 ToHexNibble(char c1);
|
||||
|
||||
template <size_t Size, bool le = false>
|
||||
@@ -35,3 +37,5 @@ std::string HexArrayToString(std::array<u8, Size> array, bool upper = true) {
|
||||
|
||||
std::array<u8, 0x10> operator"" _array16(const char* str, size_t len);
|
||||
std::array<u8, 0x20> operator"" _array32(const char* str, size_t len);
|
||||
|
||||
} // namespace Common
|
||||
|
||||
@@ -42,7 +42,7 @@ void PrintColoredMessage(const Entry& entry) {
|
||||
return;
|
||||
}
|
||||
|
||||
CONSOLE_SCREEN_BUFFER_INFO original_info = {0};
|
||||
CONSOLE_SCREEN_BUFFER_INFO original_info = {};
|
||||
GetConsoleScreenBufferInfo(console_handle, &original_info);
|
||||
|
||||
WORD color = 0;
|
||||
|
||||
@@ -3,8 +3,15 @@
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include "common/assert.h"
|
||||
#include "common/scm_rev.h"
|
||||
#include "common/telemetry.h"
|
||||
|
||||
#ifdef ARCHITECTURE_x86_64
|
||||
#include "common/x64/cpu_detect.h"
|
||||
#endif
|
||||
|
||||
namespace Telemetry {
|
||||
|
||||
void FieldCollection::Accept(VisitorInterface& visitor) const {
|
||||
@@ -37,4 +44,62 @@ template class Field<std::string>;
|
||||
template class Field<const char*>;
|
||||
template class Field<std::chrono::microseconds>;
|
||||
|
||||
#ifdef ARCHITECTURE_x86_64
|
||||
static const char* CpuVendorToStr(Common::CPUVendor vendor) {
|
||||
switch (vendor) {
|
||||
case Common::CPUVendor::INTEL:
|
||||
return "Intel";
|
||||
case Common::CPUVendor::AMD:
|
||||
return "Amd";
|
||||
case Common::CPUVendor::OTHER:
|
||||
return "Other";
|
||||
}
|
||||
UNREACHABLE();
|
||||
}
|
||||
#endif
|
||||
|
||||
void AppendBuildInfo(FieldCollection& fc) {
|
||||
const bool is_git_dirty{std::strstr(Common::g_scm_desc, "dirty") != nullptr};
|
||||
fc.AddField(FieldType::App, "Git_IsDirty", is_git_dirty);
|
||||
fc.AddField(FieldType::App, "Git_Branch", Common::g_scm_branch);
|
||||
fc.AddField(FieldType::App, "Git_Revision", Common::g_scm_rev);
|
||||
fc.AddField(FieldType::App, "BuildDate", Common::g_build_date);
|
||||
fc.AddField(FieldType::App, "BuildName", Common::g_build_name);
|
||||
}
|
||||
|
||||
void AppendCPUInfo(FieldCollection& fc) {
|
||||
#ifdef ARCHITECTURE_x86_64
|
||||
fc.AddField(FieldType::UserSystem, "CPU_Model", Common::GetCPUCaps().cpu_string);
|
||||
fc.AddField(FieldType::UserSystem, "CPU_BrandString", Common::GetCPUCaps().brand_string);
|
||||
fc.AddField(FieldType::UserSystem, "CPU_Vendor", CpuVendorToStr(Common::GetCPUCaps().vendor));
|
||||
fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_AES", Common::GetCPUCaps().aes);
|
||||
fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_AVX", Common::GetCPUCaps().avx);
|
||||
fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_AVX2", Common::GetCPUCaps().avx2);
|
||||
fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_BMI1", Common::GetCPUCaps().bmi1);
|
||||
fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_BMI2", Common::GetCPUCaps().bmi2);
|
||||
fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_FMA", Common::GetCPUCaps().fma);
|
||||
fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_FMA4", Common::GetCPUCaps().fma4);
|
||||
fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_SSE", Common::GetCPUCaps().sse);
|
||||
fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_SSE2", Common::GetCPUCaps().sse2);
|
||||
fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_SSE3", Common::GetCPUCaps().sse3);
|
||||
fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_SSSE3", Common::GetCPUCaps().ssse3);
|
||||
fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_SSE41", Common::GetCPUCaps().sse4_1);
|
||||
fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_SSE42", Common::GetCPUCaps().sse4_2);
|
||||
#else
|
||||
fc.AddField(FieldType::UserSystem, "CPU_Model", "Other");
|
||||
#endif
|
||||
}
|
||||
|
||||
void AppendOSInfo(FieldCollection& fc) {
|
||||
#ifdef __APPLE__
|
||||
fc.AddField(FieldType::UserSystem, "OsPlatform", "Apple");
|
||||
#elif defined(_WIN32)
|
||||
fc.AddField(FieldType::UserSystem, "OsPlatform", "Windows");
|
||||
#elif defined(__linux__) || defined(linux) || defined(__linux)
|
||||
fc.AddField(FieldType::UserSystem, "OsPlatform", "Linux");
|
||||
#else
|
||||
fc.AddField(FieldType::UserSystem, "OsPlatform", "Unknown");
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace Telemetry
|
||||
|
||||
@@ -180,4 +180,16 @@ struct NullVisitor : public VisitorInterface {
|
||||
void Complete() override {}
|
||||
};
|
||||
|
||||
/// Appends build-specific information to the given FieldCollection,
|
||||
/// such as branch name, revision hash, etc.
|
||||
void AppendBuildInfo(FieldCollection& fc);
|
||||
|
||||
/// Appends CPU-specific information to the given FieldCollection,
|
||||
/// such as instruction set extensions, etc.
|
||||
void AppendCPUInfo(FieldCollection& fc);
|
||||
|
||||
/// Appends OS-specific information to the given FieldCollection,
|
||||
/// such as platform name, etc.
|
||||
void AppendOSInfo(FieldCollection& fc);
|
||||
|
||||
} // namespace Telemetry
|
||||
|
||||
@@ -122,6 +122,8 @@ add_library(core STATIC
|
||||
hle/service/acc/acc_u0.h
|
||||
hle/service/acc/acc_u1.cpp
|
||||
hle/service/acc/acc_u1.h
|
||||
hle/service/acc/profile_manager.cpp
|
||||
hle/service/acc/profile_manager.h
|
||||
hle/service/am/am.cpp
|
||||
hle/service/am/am.h
|
||||
hle/service/am/applet_ae.cpp
|
||||
|
||||
@@ -134,6 +134,9 @@ std::unique_ptr<Dynarmic::A64::Jit> ARM_Dynarmic::MakeJit() const {
|
||||
config.dczid_el0 = 4;
|
||||
config.ctr_el0 = 0x8444c004;
|
||||
|
||||
// Unpredictable instructions
|
||||
config.define_unpredictable_behaviour = true;
|
||||
|
||||
return std::make_unique<Dynarmic::A64::Jit>(config);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,12 @@ namespace Core {
|
||||
|
||||
class System {
|
||||
public:
|
||||
System(const System&) = delete;
|
||||
System& operator=(const System&) = delete;
|
||||
|
||||
System(System&&) = delete;
|
||||
System& operator=(System&&) = delete;
|
||||
|
||||
~System();
|
||||
|
||||
/**
|
||||
@@ -181,6 +187,13 @@ public:
|
||||
return current_process;
|
||||
}
|
||||
|
||||
/// Gets the name of the current game
|
||||
Loader::ResultStatus GetGameName(std::string& out) const {
|
||||
if (app_loader == nullptr)
|
||||
return Loader::ResultStatus::ErrorNotInitialized;
|
||||
return app_loader->ReadTitle(out);
|
||||
}
|
||||
|
||||
PerfStats perf_stats;
|
||||
FrameLimiter frame_limiter;
|
||||
|
||||
|
||||
@@ -52,20 +52,20 @@ void KeyManager::LoadFromFile(const std::string& filename, bool is_title_keys) {
|
||||
out[1].erase(std::remove(out[1].begin(), out[1].end(), ' '), out[1].end());
|
||||
|
||||
if (is_title_keys) {
|
||||
auto rights_id_raw = HexStringToArray<16>(out[0]);
|
||||
auto rights_id_raw = Common::HexStringToArray<16>(out[0]);
|
||||
u128 rights_id{};
|
||||
std::memcpy(rights_id.data(), rights_id_raw.data(), rights_id_raw.size());
|
||||
Key128 key = HexStringToArray<16>(out[1]);
|
||||
Key128 key = Common::HexStringToArray<16>(out[1]);
|
||||
SetKey(S128KeyType::Titlekey, key, rights_id[1], rights_id[0]);
|
||||
} else {
|
||||
std::transform(out[0].begin(), out[0].end(), out[0].begin(), ::tolower);
|
||||
if (s128_file_id.find(out[0]) != s128_file_id.end()) {
|
||||
const auto index = s128_file_id.at(out[0]);
|
||||
Key128 key = HexStringToArray<16>(out[1]);
|
||||
Key128 key = Common::HexStringToArray<16>(out[1]);
|
||||
SetKey(index.type, key, index.field1, index.field2);
|
||||
} else if (s256_file_id.find(out[0]) != s256_file_id.end()) {
|
||||
const auto index = s256_file_id.at(out[0]);
|
||||
Key256 key = HexStringToArray<32>(out[1]);
|
||||
Key256 key = Common::HexStringToArray<32>(out[1]);
|
||||
SetKey(index.type, key, index.field1, index.field2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ enum class NCAContentType : u8 {
|
||||
Control = 2,
|
||||
Manual = 3,
|
||||
Data = 4,
|
||||
Data_Unknown5 = 5, ///< Seems to be used on some system archives
|
||||
};
|
||||
|
||||
enum class NCASectionCryptoType : u8 {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "common/common_funcs.h"
|
||||
#include "common/common_types.h"
|
||||
#include "common/swap.h"
|
||||
#include "core/file_sys/vfs.h"
|
||||
|
||||
@@ -37,11 +37,12 @@ static bool FollowsNcaIdFormat(std::string_view name) {
|
||||
static std::string GetRelativePathFromNcaID(const std::array<u8, 16>& nca_id, bool second_hex_upper,
|
||||
bool within_two_digit) {
|
||||
if (!within_two_digit)
|
||||
return fmt::format("/{}.nca", HexArrayToString(nca_id, second_hex_upper));
|
||||
return fmt::format("/{}.nca", Common::HexArrayToString(nca_id, second_hex_upper));
|
||||
|
||||
Core::Crypto::SHA256Hash hash{};
|
||||
mbedtls_sha256(nca_id.data(), nca_id.size(), hash.data(), 0);
|
||||
return fmt::format("/000000{:02X}/{}.nca", hash[0], HexArrayToString(nca_id, second_hex_upper));
|
||||
return fmt::format("/000000{:02X}/{}.nca", hash[0],
|
||||
Common::HexArrayToString(nca_id, second_hex_upper));
|
||||
}
|
||||
|
||||
static std::string GetCNMTName(TitleType type, u64 title_id) {
|
||||
@@ -76,12 +77,13 @@ static ContentRecordType GetCRTypeFromNCAType(NCAContentType type) {
|
||||
case NCAContentType::Control:
|
||||
return ContentRecordType::Control;
|
||||
case NCAContentType::Data:
|
||||
case NCAContentType::Data_Unknown5:
|
||||
return ContentRecordType::Data;
|
||||
case NCAContentType::Manual:
|
||||
// TODO(DarkLordZach): Peek at NCA contents to differentiate Manual and Legal.
|
||||
return ContentRecordType::Manual;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
UNREACHABLE_MSG("Invalid NCAContentType={:02X}", static_cast<u8>(type));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +172,7 @@ std::vector<NcaID> RegisteredCache::AccumulateFiles() const {
|
||||
std::vector<NcaID> ids;
|
||||
for (const auto& d2_dir : dir->GetSubdirectories()) {
|
||||
if (FollowsNcaIdFormat(d2_dir->GetName())) {
|
||||
ids.push_back(HexStringToArray<0x10, true>(d2_dir->GetName().substr(0, 0x20)));
|
||||
ids.push_back(Common::HexStringToArray<0x10, true>(d2_dir->GetName().substr(0, 0x20)));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -181,20 +183,21 @@ std::vector<NcaID> RegisteredCache::AccumulateFiles() const {
|
||||
if (!FollowsNcaIdFormat(nca_dir->GetName()))
|
||||
continue;
|
||||
|
||||
ids.push_back(HexStringToArray<0x10, true>(nca_dir->GetName().substr(0, 0x20)));
|
||||
ids.push_back(Common::HexStringToArray<0x10, true>(nca_dir->GetName().substr(0, 0x20)));
|
||||
}
|
||||
|
||||
for (const auto& nca_file : d2_dir->GetFiles()) {
|
||||
if (!FollowsNcaIdFormat(nca_file->GetName()))
|
||||
continue;
|
||||
|
||||
ids.push_back(HexStringToArray<0x10, true>(nca_file->GetName().substr(0, 0x20)));
|
||||
ids.push_back(
|
||||
Common::HexStringToArray<0x10, true>(nca_file->GetName().substr(0, 0x20)));
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& d2_file : dir->GetFiles()) {
|
||||
if (FollowsNcaIdFormat(d2_file->GetName()))
|
||||
ids.push_back(HexStringToArray<0x10, true>(d2_file->GetName().substr(0, 0x20)));
|
||||
ids.push_back(Common::HexStringToArray<0x10, true>(d2_file->GetName().substr(0, 0x20)));
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
@@ -339,7 +342,7 @@ std::vector<RegisteredCacheEntry> RegisteredCache::ListEntriesFilter(
|
||||
}
|
||||
|
||||
static std::shared_ptr<NCA> GetNCAFromXCIForID(std::shared_ptr<XCI> xci, const NcaID& id) {
|
||||
const auto filename = fmt::format("{}.nca", HexArrayToString(id, false));
|
||||
const auto filename = fmt::format("{}.nca", Common::HexArrayToString(id, false));
|
||||
const auto iter =
|
||||
std::find_if(xci->GetNCAs().begin(), xci->GetNCAs().end(),
|
||||
[&filename](std::shared_ptr<NCA> nca) { return nca->GetName() == filename; });
|
||||
@@ -361,7 +364,7 @@ InstallResult RegisteredCache::InstallEntry(std::shared_ptr<XCI> xci, bool overw
|
||||
|
||||
// Install Metadata File
|
||||
const auto meta_id_raw = (*meta_iter)->GetName().substr(0, 32);
|
||||
const auto meta_id = HexStringToArray<16>(meta_id_raw);
|
||||
const auto meta_id = Common::HexStringToArray<16>(meta_id_raw);
|
||||
|
||||
const auto res = RawInstallNCA(*meta_iter, copy, overwrite_if_exists, meta_id);
|
||||
if (res != InstallResult::Success)
|
||||
|
||||
@@ -6,20 +6,57 @@
|
||||
#include <memory>
|
||||
#include "common/common_types.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "core/file_sys/nca_metadata.h"
|
||||
#include "core/file_sys/registered_cache.h"
|
||||
#include "core/file_sys/romfs_factory.h"
|
||||
#include "core/hle/kernel/process.h"
|
||||
#include "core/hle/service/filesystem/filesystem.h"
|
||||
#include "core/loader/loader.h"
|
||||
|
||||
namespace FileSys {
|
||||
|
||||
RomFSFactory::RomFSFactory(Loader::AppLoader& app_loader) {
|
||||
// Load the RomFS from the app
|
||||
if (Loader::ResultStatus::Success != app_loader.ReadRomFS(file)) {
|
||||
if (app_loader.ReadRomFS(file) != Loader::ResultStatus::Success) {
|
||||
LOG_ERROR(Service_FS, "Unable to read RomFS!");
|
||||
}
|
||||
}
|
||||
|
||||
ResultVal<VirtualFile> RomFSFactory::Open(u64 title_id) {
|
||||
// TODO(DarkLordZach): Use title id.
|
||||
ResultVal<VirtualFile> RomFSFactory::OpenCurrentProcess() {
|
||||
return MakeResult<VirtualFile>(file);
|
||||
}
|
||||
|
||||
ResultVal<VirtualFile> RomFSFactory::Open(u64 title_id, StorageId storage, ContentRecordType type) {
|
||||
switch (storage) {
|
||||
case StorageId::NandSystem: {
|
||||
const auto res = Service::FileSystem::GetSystemNANDContents()->GetEntry(title_id, type);
|
||||
if (res == nullptr) {
|
||||
// TODO(DarkLordZach): Find the right error code to use here
|
||||
return ResultCode(-1);
|
||||
}
|
||||
const auto romfs = res->GetRomFS();
|
||||
if (romfs == nullptr) {
|
||||
// TODO(DarkLordZach): Find the right error code to use here
|
||||
return ResultCode(-1);
|
||||
}
|
||||
return MakeResult<VirtualFile>(romfs);
|
||||
}
|
||||
case StorageId::NandUser: {
|
||||
const auto res = Service::FileSystem::GetUserNANDContents()->GetEntry(title_id, type);
|
||||
if (res == nullptr) {
|
||||
// TODO(DarkLordZach): Find the right error code to use here
|
||||
return ResultCode(-1);
|
||||
}
|
||||
const auto romfs = res->GetRomFS();
|
||||
if (romfs == nullptr) {
|
||||
// TODO(DarkLordZach): Find the right error code to use here
|
||||
return ResultCode(-1);
|
||||
}
|
||||
return MakeResult<VirtualFile>(romfs);
|
||||
}
|
||||
default:
|
||||
UNIMPLEMENTED_MSG("Unimplemented storage_id={:02X}", static_cast<u8>(storage));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace FileSys
|
||||
|
||||
@@ -6,17 +6,33 @@
|
||||
|
||||
#include <memory>
|
||||
#include "common/common_types.h"
|
||||
#include "core/file_sys/vfs.h"
|
||||
#include "core/hle/result.h"
|
||||
#include "core/loader/loader.h"
|
||||
|
||||
namespace Loader {
|
||||
class AppLoader;
|
||||
} // namespace Loader
|
||||
|
||||
namespace FileSys {
|
||||
|
||||
enum class ContentRecordType : u8;
|
||||
|
||||
enum class StorageId : u8 {
|
||||
None = 0,
|
||||
Host = 1,
|
||||
GameCard = 2,
|
||||
NandSystem = 3,
|
||||
NandUser = 4,
|
||||
SdCard = 5,
|
||||
};
|
||||
|
||||
/// File system interface to the RomFS archive
|
||||
class RomFSFactory {
|
||||
public:
|
||||
explicit RomFSFactory(Loader::AppLoader& app_loader);
|
||||
|
||||
ResultVal<VirtualFile> Open(u64 title_id);
|
||||
ResultVal<VirtualFile> OpenCurrentProcess();
|
||||
ResultVal<VirtualFile> Open(u64 title_id, StorageId storage, ContentRecordType type);
|
||||
|
||||
private:
|
||||
VirtualFile file;
|
||||
|
||||
@@ -73,7 +73,7 @@ ResultVal<VirtualDir> SaveDataFactory::Open(SaveDataSpaceId space, SaveDataDescr
|
||||
}
|
||||
|
||||
std::string SaveDataFactory::GetFullPath(SaveDataSpaceId space, SaveDataType type, u64 title_id,
|
||||
u128 user_id, u64 save_id) const {
|
||||
u128 user_id, u64 save_id) {
|
||||
// According to switchbrew, if a save is of type SaveData and the title id field is 0, it should
|
||||
// be interpreted as the title id of the current process.
|
||||
if (type == SaveDataType::SaveData && title_id == 0)
|
||||
|
||||
@@ -49,11 +49,11 @@ public:
|
||||
|
||||
ResultVal<VirtualDir> Open(SaveDataSpaceId space, SaveDataDescriptor meta);
|
||||
|
||||
static std::string GetFullPath(SaveDataSpaceId space, SaveDataType type, u64 title_id,
|
||||
u128 user_id, u64 save_id);
|
||||
|
||||
private:
|
||||
VirtualDir dir;
|
||||
|
||||
std::string GetFullPath(SaveDataSpaceId space, SaveDataType type, u64 title_id, u128 user_id,
|
||||
u64 save_id) const;
|
||||
};
|
||||
|
||||
} // namespace FileSys
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <memory>
|
||||
#include "core/core.h"
|
||||
#include "core/file_sys/sdmc_factory.h"
|
||||
|
||||
namespace FileSys {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/file_sys/vfs.h"
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace FileSys {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "common/common_paths.h"
|
||||
#include "common/file_util.h"
|
||||
#include "common/logging/backend.h"
|
||||
#include "core/file_sys/mode.h"
|
||||
#include "core/file_sys/vfs.h"
|
||||
|
||||
namespace FileSys {
|
||||
|
||||
@@ -9,9 +9,8 @@
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include "boost/optional.hpp"
|
||||
#include <boost/optional.hpp>
|
||||
#include "common/common_types.h"
|
||||
#include "core/file_sys/mode.h"
|
||||
|
||||
namespace FileSys {
|
||||
|
||||
@@ -19,6 +18,8 @@ class VfsDirectory;
|
||||
class VfsFile;
|
||||
class VfsFilesystem;
|
||||
|
||||
enum class Mode : u32;
|
||||
|
||||
// Convenience typedefs to use Vfs* interfaces
|
||||
using VirtualFilesystem = std::shared_ptr<VfsFilesystem>;
|
||||
using VirtualDir = std::shared_ptr<VfsDirectory>;
|
||||
|
||||
@@ -3,17 +3,19 @@
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <array>
|
||||
#include "common/common_types.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/swap.h"
|
||||
#include "core/core_timing.h"
|
||||
#include "core/hle/ipc_helpers.h"
|
||||
#include "core/hle/service/acc/acc.h"
|
||||
#include "core/hle/service/acc/acc_aa.h"
|
||||
#include "core/hle/service/acc/acc_su.h"
|
||||
#include "core/hle/service/acc/acc_u0.h"
|
||||
#include "core/hle/service/acc/acc_u1.h"
|
||||
#include "core/settings.h"
|
||||
#include "core/hle/service/acc/profile_manager.h"
|
||||
|
||||
namespace Service::Account {
|
||||
|
||||
// TODO: RE this structure
|
||||
struct UserData {
|
||||
INSERT_PADDING_WORDS(1);
|
||||
@@ -25,19 +27,10 @@ struct UserData {
|
||||
};
|
||||
static_assert(sizeof(UserData) == 0x80, "UserData structure has incorrect size");
|
||||
|
||||
struct ProfileBase {
|
||||
u128 user_id;
|
||||
u64 timestamp;
|
||||
std::array<u8, 0x20> username;
|
||||
};
|
||||
static_assert(sizeof(ProfileBase) == 0x38, "ProfileBase structure has incorrect size");
|
||||
|
||||
// TODO(ogniK): Generate a real user id based on username, md5(username) maybe?
|
||||
static constexpr u128 DEFAULT_USER_ID{1ull, 0ull};
|
||||
|
||||
class IProfile final : public ServiceFramework<IProfile> {
|
||||
public:
|
||||
explicit IProfile(u128 user_id) : ServiceFramework("IProfile"), user_id(user_id) {
|
||||
explicit IProfile(UUID user_id, ProfileManager& profile_manager)
|
||||
: ServiceFramework("IProfile"), profile_manager(profile_manager), user_id(user_id) {
|
||||
static const FunctionInfo functions[] = {
|
||||
{0, &IProfile::Get, "Get"},
|
||||
{1, &IProfile::GetBase, "GetBase"},
|
||||
@@ -49,46 +42,42 @@ public:
|
||||
|
||||
private:
|
||||
void Get(Kernel::HLERequestContext& ctx) {
|
||||
LOG_WARNING(Service_ACC, "(STUBBED) called");
|
||||
LOG_INFO(Service_ACC, "called user_id={}", user_id.Format());
|
||||
ProfileBase profile_base{};
|
||||
profile_base.user_id = user_id;
|
||||
if (Settings::values.username.size() > profile_base.username.size()) {
|
||||
std::copy_n(Settings::values.username.begin(), profile_base.username.size(),
|
||||
profile_base.username.begin());
|
||||
std::array<u8, MAX_DATA> data{};
|
||||
if (profile_manager.GetProfileBaseAndData(user_id, profile_base, data)) {
|
||||
ctx.WriteBuffer(data);
|
||||
IPC::ResponseBuilder rb{ctx, 16};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
rb.PushRaw(profile_base);
|
||||
} else {
|
||||
std::copy(Settings::values.username.begin(), Settings::values.username.end(),
|
||||
profile_base.username.begin());
|
||||
LOG_ERROR(Service_ACC, "Failed to get profile base and data for user={}",
|
||||
user_id.Format());
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultCode(-1)); // TODO(ogniK): Get actual error code
|
||||
}
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 16};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
rb.PushRaw(profile_base);
|
||||
}
|
||||
|
||||
void GetBase(Kernel::HLERequestContext& ctx) {
|
||||
LOG_WARNING(Service_ACC, "(STUBBED) called");
|
||||
|
||||
// TODO(Subv): Retrieve this information from somewhere.
|
||||
LOG_INFO(Service_ACC, "called user_id={}", user_id.Format());
|
||||
ProfileBase profile_base{};
|
||||
profile_base.user_id = user_id;
|
||||
if (Settings::values.username.size() > profile_base.username.size()) {
|
||||
std::copy_n(Settings::values.username.begin(), profile_base.username.size(),
|
||||
profile_base.username.begin());
|
||||
if (profile_manager.GetProfileBase(user_id, profile_base)) {
|
||||
IPC::ResponseBuilder rb{ctx, 16};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
rb.PushRaw(profile_base);
|
||||
} else {
|
||||
std::copy(Settings::values.username.begin(), Settings::values.username.end(),
|
||||
profile_base.username.begin());
|
||||
LOG_ERROR(Service_ACC, "Failed to get profile base for user={}", user_id.Format());
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultCode(-1)); // TODO(ogniK): Get actual error code
|
||||
}
|
||||
IPC::ResponseBuilder rb{ctx, 16};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
rb.PushRaw(profile_base);
|
||||
}
|
||||
|
||||
void LoadImage(Kernel::HLERequestContext& ctx) {
|
||||
LOG_WARNING(Service_ACC, "(STUBBED) called");
|
||||
// smallest jpeg https://github.com/mathiasbynens/small/blob/master/jpeg.jpg
|
||||
// TODO(mailwl): load actual profile image from disk, width 256px, max size 0x20000
|
||||
const u32 jpeg_size = 107;
|
||||
static const std::array<u8, jpeg_size> jpeg{
|
||||
constexpr u32 jpeg_size = 107;
|
||||
static constexpr std::array<u8, jpeg_size> jpeg{
|
||||
0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03,
|
||||
0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04,
|
||||
0x08, 0x06, 0x06, 0x05, 0x06, 0x09, 0x08, 0x0a, 0x0a, 0x09, 0x08, 0x09, 0x09, 0x0a,
|
||||
@@ -98,13 +87,14 @@ private:
|
||||
0xff, 0xcc, 0x00, 0x06, 0x00, 0x10, 0x10, 0x05, 0xff, 0xda, 0x00, 0x08, 0x01, 0x01,
|
||||
0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9,
|
||||
};
|
||||
ctx.WriteBuffer(jpeg.data(), jpeg_size);
|
||||
ctx.WriteBuffer(jpeg);
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
rb.Push<u32>(jpeg_size);
|
||||
}
|
||||
|
||||
u128 user_id; ///< The user id this profile refers to.
|
||||
const ProfileManager& profile_manager;
|
||||
UUID user_id; ///< The user id this profile refers to.
|
||||
};
|
||||
|
||||
class IManagerForApplication final : public ServiceFramework<IManagerForApplication> {
|
||||
@@ -141,44 +131,57 @@ private:
|
||||
};
|
||||
|
||||
void Module::Interface::GetUserCount(Kernel::HLERequestContext& ctx) {
|
||||
LOG_WARNING(Service_ACC, "(STUBBED) called");
|
||||
LOG_INFO(Service_ACC, "called");
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
rb.Push<u32>(1);
|
||||
rb.Push<u32>(static_cast<u32>(profile_manager->GetUserCount()));
|
||||
}
|
||||
|
||||
void Module::Interface::GetUserExistence(Kernel::HLERequestContext& ctx) {
|
||||
LOG_WARNING(Service_ACC, "(STUBBED) called");
|
||||
IPC::RequestParser rp{ctx};
|
||||
UUID user_id = rp.PopRaw<UUID>();
|
||||
LOG_INFO(Service_ACC, "called user_id={}", user_id.Format());
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
rb.Push(true); // TODO: Check when this is supposed to return true and when not
|
||||
rb.Push(profile_manager->UserExists(user_id));
|
||||
}
|
||||
|
||||
void Module::Interface::ListAllUsers(Kernel::HLERequestContext& ctx) {
|
||||
LOG_WARNING(Service_ACC, "(STUBBED) called");
|
||||
// TODO(Subv): There is only one user for now.
|
||||
const std::vector<u128> user_ids = {DEFAULT_USER_ID};
|
||||
ctx.WriteBuffer(user_ids);
|
||||
LOG_INFO(Service_ACC, "called");
|
||||
ctx.WriteBuffer(profile_manager->GetAllUsers());
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
void Module::Interface::ListOpenUsers(Kernel::HLERequestContext& ctx) {
|
||||
LOG_WARNING(Service_ACC, "(STUBBED) called");
|
||||
// TODO(Subv): There is only one user for now.
|
||||
const std::vector<u128> user_ids = {DEFAULT_USER_ID};
|
||||
ctx.WriteBuffer(user_ids);
|
||||
LOG_INFO(Service_ACC, "called");
|
||||
ctx.WriteBuffer(profile_manager->GetOpenUsers());
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
void Module::Interface::GetLastOpenedUser(Kernel::HLERequestContext& ctx) {
|
||||
LOG_INFO(Service_ACC, "called");
|
||||
IPC::ResponseBuilder rb{ctx, 6};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
rb.PushRaw<UUID>(profile_manager->GetLastOpenedUser());
|
||||
}
|
||||
|
||||
void Module::Interface::GetProfile(Kernel::HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
u128 user_id = rp.PopRaw<u128>();
|
||||
UUID user_id = rp.PopRaw<UUID>();
|
||||
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
rb.PushIpcInterface<IProfile>(user_id);
|
||||
LOG_DEBUG(Service_ACC, "called user_id=0x{:016X}{:016X}", user_id[1], user_id[0]);
|
||||
rb.PushIpcInterface<IProfile>(user_id, *profile_manager);
|
||||
LOG_DEBUG(Service_ACC, "called user_id={}", user_id.Format());
|
||||
}
|
||||
|
||||
void Module::Interface::IsUserRegistrationRequestPermitted(Kernel::HLERequestContext& ctx) {
|
||||
LOG_WARNING(Service_ACC, "(STUBBED) called");
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
rb.Push(profile_manager->CanSystemRegisterUser());
|
||||
}
|
||||
|
||||
void Module::Interface::InitializeApplicationInfo(Kernel::HLERequestContext& ctx) {
|
||||
@@ -194,22 +197,20 @@ void Module::Interface::GetBaasAccountManagerForApplication(Kernel::HLERequestCo
|
||||
LOG_DEBUG(Service_ACC, "called");
|
||||
}
|
||||
|
||||
void Module::Interface::GetLastOpenedUser(Kernel::HLERequestContext& ctx) {
|
||||
LOG_WARNING(Service_ACC, "(STUBBED) called");
|
||||
IPC::ResponseBuilder rb{ctx, 6};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
rb.PushRaw(DEFAULT_USER_ID);
|
||||
}
|
||||
Module::Interface::Interface(std::shared_ptr<Module> module,
|
||||
std::shared_ptr<ProfileManager> profile_manager, const char* name)
|
||||
: ServiceFramework(name), module(std::move(module)),
|
||||
profile_manager(std::move(profile_manager)) {}
|
||||
|
||||
Module::Interface::Interface(std::shared_ptr<Module> module, const char* name)
|
||||
: ServiceFramework(name), module(std::move(module)) {}
|
||||
Module::Interface::~Interface() = default;
|
||||
|
||||
void InstallInterfaces(SM::ServiceManager& service_manager) {
|
||||
auto module = std::make_shared<Module>();
|
||||
std::make_shared<ACC_AA>(module)->InstallAsService(service_manager);
|
||||
std::make_shared<ACC_SU>(module)->InstallAsService(service_manager);
|
||||
std::make_shared<ACC_U0>(module)->InstallAsService(service_manager);
|
||||
std::make_shared<ACC_U1>(module)->InstallAsService(service_manager);
|
||||
auto profile_manager = std::make_shared<ProfileManager>();
|
||||
std::make_shared<ACC_AA>(module, profile_manager)->InstallAsService(service_manager);
|
||||
std::make_shared<ACC_SU>(module, profile_manager)->InstallAsService(service_manager);
|
||||
std::make_shared<ACC_U0>(module, profile_manager)->InstallAsService(service_manager);
|
||||
std::make_shared<ACC_U1>(module, profile_manager)->InstallAsService(service_manager);
|
||||
}
|
||||
|
||||
} // namespace Service::Account
|
||||
|
||||
@@ -8,11 +8,15 @@
|
||||
|
||||
namespace Service::Account {
|
||||
|
||||
class ProfileManager;
|
||||
|
||||
class Module final {
|
||||
public:
|
||||
class Interface : public ServiceFramework<Interface> {
|
||||
public:
|
||||
explicit Interface(std::shared_ptr<Module> module, const char* name);
|
||||
explicit Interface(std::shared_ptr<Module> module,
|
||||
std::shared_ptr<ProfileManager> profile_manager, const char* name);
|
||||
~Interface() override;
|
||||
|
||||
void GetUserCount(Kernel::HLERequestContext& ctx);
|
||||
void GetUserExistence(Kernel::HLERequestContext& ctx);
|
||||
@@ -22,9 +26,11 @@ public:
|
||||
void GetProfile(Kernel::HLERequestContext& ctx);
|
||||
void InitializeApplicationInfo(Kernel::HLERequestContext& ctx);
|
||||
void GetBaasAccountManagerForApplication(Kernel::HLERequestContext& ctx);
|
||||
void IsUserRegistrationRequestPermitted(Kernel::HLERequestContext& ctx);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<Module> module;
|
||||
std::shared_ptr<ProfileManager> profile_manager;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
|
||||
namespace Service::Account {
|
||||
|
||||
ACC_AA::ACC_AA(std::shared_ptr<Module> module) : Module::Interface(std::move(module), "acc:aa") {
|
||||
ACC_AA::ACC_AA(std::shared_ptr<Module> module, std::shared_ptr<ProfileManager> profile_manager)
|
||||
: Module::Interface(std::move(module), std::move(profile_manager), "acc:aa") {
|
||||
static const FunctionInfo functions[] = {
|
||||
{0, nullptr, "EnsureCacheAsync"},
|
||||
{1, nullptr, "LoadCache"},
|
||||
|
||||
@@ -10,7 +10,8 @@ namespace Service::Account {
|
||||
|
||||
class ACC_AA final : public Module::Interface {
|
||||
public:
|
||||
explicit ACC_AA(std::shared_ptr<Module> module);
|
||||
explicit ACC_AA(std::shared_ptr<Module> module,
|
||||
std::shared_ptr<ProfileManager> profile_manager);
|
||||
};
|
||||
|
||||
} // namespace Service::Account
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
|
||||
namespace Service::Account {
|
||||
|
||||
ACC_SU::ACC_SU(std::shared_ptr<Module> module) : Module::Interface(std::move(module), "acc:su") {
|
||||
ACC_SU::ACC_SU(std::shared_ptr<Module> module, std::shared_ptr<ProfileManager> profile_manager)
|
||||
: Module::Interface(std::move(module), std::move(profile_manager), "acc:su") {
|
||||
static const FunctionInfo functions[] = {
|
||||
{0, &ACC_SU::GetUserCount, "GetUserCount"},
|
||||
{1, &ACC_SU::GetUserExistence, "GetUserExistence"},
|
||||
@@ -15,7 +16,7 @@ ACC_SU::ACC_SU(std::shared_ptr<Module> module) : Module::Interface(std::move(mod
|
||||
{4, &ACC_SU::GetLastOpenedUser, "GetLastOpenedUser"},
|
||||
{5, &ACC_SU::GetProfile, "GetProfile"},
|
||||
{6, nullptr, "GetProfileDigest"},
|
||||
{50, nullptr, "IsUserRegistrationRequestPermitted"},
|
||||
{50, &ACC_SU::IsUserRegistrationRequestPermitted, "IsUserRegistrationRequestPermitted"},
|
||||
{51, nullptr, "TrySelectUserWithoutInteraction"},
|
||||
{60, nullptr, "ListOpenContextStoredUsers"},
|
||||
{100, nullptr, "GetUserRegistrationNotifier"},
|
||||
|
||||
@@ -11,7 +11,8 @@ namespace Account {
|
||||
|
||||
class ACC_SU final : public Module::Interface {
|
||||
public:
|
||||
explicit ACC_SU(std::shared_ptr<Module> module);
|
||||
explicit ACC_SU(std::shared_ptr<Module> module,
|
||||
std::shared_ptr<ProfileManager> profile_manager);
|
||||
};
|
||||
|
||||
} // namespace Account
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
|
||||
namespace Service::Account {
|
||||
|
||||
ACC_U0::ACC_U0(std::shared_ptr<Module> module) : Module::Interface(std::move(module), "acc:u0") {
|
||||
ACC_U0::ACC_U0(std::shared_ptr<Module> module, std::shared_ptr<ProfileManager> profile_manager)
|
||||
: Module::Interface(std::move(module), std::move(profile_manager), "acc:u0") {
|
||||
static const FunctionInfo functions[] = {
|
||||
{0, &ACC_U0::GetUserCount, "GetUserCount"},
|
||||
{1, &ACC_U0::GetUserExistence, "GetUserExistence"},
|
||||
@@ -15,7 +16,7 @@ ACC_U0::ACC_U0(std::shared_ptr<Module> module) : Module::Interface(std::move(mod
|
||||
{4, &ACC_U0::GetLastOpenedUser, "GetLastOpenedUser"},
|
||||
{5, &ACC_U0::GetProfile, "GetProfile"},
|
||||
{6, nullptr, "GetProfileDigest"},
|
||||
{50, nullptr, "IsUserRegistrationRequestPermitted"},
|
||||
{50, &ACC_U0::IsUserRegistrationRequestPermitted, "IsUserRegistrationRequestPermitted"},
|
||||
{51, nullptr, "TrySelectUserWithoutInteraction"},
|
||||
{60, nullptr, "ListOpenContextStoredUsers"},
|
||||
{100, &ACC_U0::InitializeApplicationInfo, "InitializeApplicationInfo"},
|
||||
|
||||
@@ -10,7 +10,8 @@ namespace Service::Account {
|
||||
|
||||
class ACC_U0 final : public Module::Interface {
|
||||
public:
|
||||
explicit ACC_U0(std::shared_ptr<Module> module);
|
||||
explicit ACC_U0(std::shared_ptr<Module> module,
|
||||
std::shared_ptr<ProfileManager> profile_manager);
|
||||
};
|
||||
|
||||
} // namespace Service::Account
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
|
||||
namespace Service::Account {
|
||||
|
||||
ACC_U1::ACC_U1(std::shared_ptr<Module> module) : Module::Interface(std::move(module), "acc:u1") {
|
||||
ACC_U1::ACC_U1(std::shared_ptr<Module> module, std::shared_ptr<ProfileManager> profile_manager)
|
||||
: Module::Interface(std::move(module), std::move(profile_manager), "acc:u1") {
|
||||
static const FunctionInfo functions[] = {
|
||||
{0, &ACC_U1::GetUserCount, "GetUserCount"},
|
||||
{1, &ACC_U1::GetUserExistence, "GetUserExistence"},
|
||||
@@ -15,7 +16,7 @@ ACC_U1::ACC_U1(std::shared_ptr<Module> module) : Module::Interface(std::move(mod
|
||||
{4, &ACC_U1::GetLastOpenedUser, "GetLastOpenedUser"},
|
||||
{5, &ACC_U1::GetProfile, "GetProfile"},
|
||||
{6, nullptr, "GetProfileDigest"},
|
||||
{50, nullptr, "IsUserRegistrationRequestPermitted"},
|
||||
{50, &ACC_U1::IsUserRegistrationRequestPermitted, "IsUserRegistrationRequestPermitted"},
|
||||
{51, nullptr, "TrySelectUserWithoutInteraction"},
|
||||
{60, nullptr, "ListOpenContextStoredUsers"},
|
||||
{100, nullptr, "GetUserRegistrationNotifier"},
|
||||
|
||||
@@ -10,7 +10,8 @@ namespace Service::Account {
|
||||
|
||||
class ACC_U1 final : public Module::Interface {
|
||||
public:
|
||||
explicit ACC_U1(std::shared_ptr<Module> module);
|
||||
explicit ACC_U1(std::shared_ptr<Module> module,
|
||||
std::shared_ptr<ProfileManager> profile_manager);
|
||||
};
|
||||
|
||||
} // namespace Service::Account
|
||||
|
||||
236
src/core/hle/service/acc/profile_manager.cpp
Normal file
236
src/core/hle/service/acc/profile_manager.cpp
Normal file
@@ -0,0 +1,236 @@
|
||||
// Copyright 2018 yuzu emulator team
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <random>
|
||||
#include <boost/optional.hpp>
|
||||
#include "core/hle/service/acc/profile_manager.h"
|
||||
#include "core/settings.h"
|
||||
|
||||
namespace Service::Account {
|
||||
// TODO(ogniK): Get actual error codes
|
||||
constexpr ResultCode ERROR_TOO_MANY_USERS(ErrorModule::Account, -1);
|
||||
constexpr ResultCode ERROR_USER_ALREADY_EXISTS(ErrorModule::Account, -2);
|
||||
constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20);
|
||||
|
||||
const UUID& UUID::Generate() {
|
||||
std::random_device device;
|
||||
std::mt19937 gen(device());
|
||||
std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max());
|
||||
uuid[0] = distribution(gen);
|
||||
uuid[1] = distribution(gen);
|
||||
return *this;
|
||||
}
|
||||
|
||||
ProfileManager::ProfileManager() {
|
||||
// TODO(ogniK): Create the default user we have for now until loading/saving users is added
|
||||
auto user_uuid = UUID{1, 0};
|
||||
CreateNewUser(user_uuid, Settings::values.username);
|
||||
OpenUser(user_uuid);
|
||||
}
|
||||
|
||||
/// After a users creation it needs to be "registered" to the system. AddToProfiles handles the
|
||||
/// internal management of the users profiles
|
||||
boost::optional<size_t> ProfileManager::AddToProfiles(const ProfileInfo& user) {
|
||||
if (user_count >= MAX_USERS) {
|
||||
return boost::none;
|
||||
}
|
||||
profiles[user_count] = user;
|
||||
return user_count++;
|
||||
}
|
||||
|
||||
/// Deletes a specific profile based on it's profile index
|
||||
bool ProfileManager::RemoveProfileAtIndex(size_t index) {
|
||||
if (index >= MAX_USERS || index >= user_count) {
|
||||
return false;
|
||||
}
|
||||
if (index < user_count - 1) {
|
||||
std::rotate(profiles.begin() + index, profiles.begin() + index + 1, profiles.end());
|
||||
}
|
||||
profiles.back() = {};
|
||||
user_count--;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Helper function to register a user to the system
|
||||
ResultCode ProfileManager::AddUser(const ProfileInfo& user) {
|
||||
if (AddToProfiles(user) == boost::none) {
|
||||
return ERROR_TOO_MANY_USERS;
|
||||
}
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
/// Create a new user on the system. If the uuid of the user already exists, the user is not
|
||||
/// created.
|
||||
ResultCode ProfileManager::CreateNewUser(UUID uuid, const ProfileUsername& username) {
|
||||
if (user_count == MAX_USERS) {
|
||||
return ERROR_TOO_MANY_USERS;
|
||||
}
|
||||
if (!uuid) {
|
||||
return ERROR_ARGUMENT_IS_NULL;
|
||||
}
|
||||
if (username[0] == 0x0) {
|
||||
return ERROR_ARGUMENT_IS_NULL;
|
||||
}
|
||||
if (std::any_of(profiles.begin(), profiles.end(),
|
||||
[&uuid](const ProfileInfo& profile) { return uuid == profile.user_uuid; })) {
|
||||
return ERROR_USER_ALREADY_EXISTS;
|
||||
}
|
||||
ProfileInfo profile;
|
||||
profile.user_uuid = uuid;
|
||||
profile.username = username;
|
||||
profile.data = {};
|
||||
profile.creation_time = 0x0;
|
||||
profile.is_open = false;
|
||||
return AddUser(profile);
|
||||
}
|
||||
|
||||
/// Creates a new user on the system. This function allows a much simpler method of registration
|
||||
/// specifically by allowing an std::string for the username. This is required specifically since
|
||||
/// we're loading a string straight from the config
|
||||
ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username) {
|
||||
ProfileUsername username_output;
|
||||
if (username.size() > username_output.size()) {
|
||||
std::copy_n(username.begin(), username_output.size(), username_output.begin());
|
||||
} else {
|
||||
std::copy(username.begin(), username.end(), username_output.begin());
|
||||
}
|
||||
return CreateNewUser(uuid, username_output);
|
||||
}
|
||||
|
||||
/// Returns a users profile index based on their user id.
|
||||
boost::optional<size_t> ProfileManager::GetUserIndex(const UUID& uuid) const {
|
||||
if (!uuid) {
|
||||
return boost::none;
|
||||
}
|
||||
auto iter = std::find_if(profiles.begin(), profiles.end(),
|
||||
[&uuid](const ProfileInfo& p) { return p.user_uuid == uuid; });
|
||||
if (iter == profiles.end()) {
|
||||
return boost::none;
|
||||
}
|
||||
return static_cast<size_t>(std::distance(profiles.begin(), iter));
|
||||
}
|
||||
|
||||
/// Returns a users profile index based on their profile
|
||||
boost::optional<size_t> ProfileManager::GetUserIndex(const ProfileInfo& user) const {
|
||||
return GetUserIndex(user.user_uuid);
|
||||
}
|
||||
|
||||
/// Returns the data structure used by the switch when GetProfileBase is called on acc:*
|
||||
bool ProfileManager::GetProfileBase(boost::optional<size_t> index, ProfileBase& profile) const {
|
||||
if (index == boost::none || index >= MAX_USERS) {
|
||||
return false;
|
||||
}
|
||||
const auto& prof_info = profiles[index.get()];
|
||||
profile.user_uuid = prof_info.user_uuid;
|
||||
profile.username = prof_info.username;
|
||||
profile.timestamp = prof_info.creation_time;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Returns the data structure used by the switch when GetProfileBase is called on acc:*
|
||||
bool ProfileManager::GetProfileBase(UUID uuid, ProfileBase& profile) const {
|
||||
auto idx = GetUserIndex(uuid);
|
||||
return GetProfileBase(idx, profile);
|
||||
}
|
||||
|
||||
/// Returns the data structure used by the switch when GetProfileBase is called on acc:*
|
||||
bool ProfileManager::GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const {
|
||||
return GetProfileBase(user.user_uuid, profile);
|
||||
}
|
||||
|
||||
/// Returns the current user count on the system. We keep a variable which tracks the count so we
|
||||
/// don't have to loop the internal profile array every call.
|
||||
size_t ProfileManager::GetUserCount() const {
|
||||
return user_count;
|
||||
}
|
||||
|
||||
/// Lists the current "opened" users on the system. Users are typically not open until they sign
|
||||
/// into something or pick a profile. As of right now users should all be open until qlaunch is
|
||||
/// booting
|
||||
size_t ProfileManager::GetOpenUserCount() const {
|
||||
return std::count_if(profiles.begin(), profiles.end(),
|
||||
[](const ProfileInfo& p) { return p.is_open; });
|
||||
}
|
||||
|
||||
/// Checks if a user id exists in our profile manager
|
||||
bool ProfileManager::UserExists(UUID uuid) const {
|
||||
return (GetUserIndex(uuid) != boost::none);
|
||||
}
|
||||
|
||||
/// Opens a specific user
|
||||
void ProfileManager::OpenUser(UUID uuid) {
|
||||
auto idx = GetUserIndex(uuid);
|
||||
if (idx == boost::none) {
|
||||
return;
|
||||
}
|
||||
profiles[idx.get()].is_open = true;
|
||||
last_opened_user = uuid;
|
||||
}
|
||||
|
||||
/// Closes a specific user
|
||||
void ProfileManager::CloseUser(UUID uuid) {
|
||||
auto idx = GetUserIndex(uuid);
|
||||
if (idx == boost::none) {
|
||||
return;
|
||||
}
|
||||
profiles[idx.get()].is_open = false;
|
||||
}
|
||||
|
||||
/// Gets all valid user ids on the system
|
||||
UserIDArray ProfileManager::GetAllUsers() const {
|
||||
UserIDArray output;
|
||||
std::transform(profiles.begin(), profiles.end(), output.begin(),
|
||||
[](const ProfileInfo& p) { return p.user_uuid; });
|
||||
return output;
|
||||
}
|
||||
|
||||
/// Get all the open users on the system and zero out the rest of the data. This is specifically
|
||||
/// needed for GetOpenUsers and we need to ensure the rest of the output buffer is zero'd out
|
||||
UserIDArray ProfileManager::GetOpenUsers() const {
|
||||
UserIDArray output;
|
||||
std::transform(profiles.begin(), profiles.end(), output.begin(), [](const ProfileInfo& p) {
|
||||
if (p.is_open)
|
||||
return p.user_uuid;
|
||||
return UUID{};
|
||||
});
|
||||
std::stable_partition(output.begin(), output.end(), [](const UUID& uuid) { return uuid; });
|
||||
return output;
|
||||
}
|
||||
|
||||
/// Returns the last user which was opened
|
||||
UUID ProfileManager::GetLastOpenedUser() const {
|
||||
return last_opened_user;
|
||||
}
|
||||
|
||||
/// Return the users profile base and the unknown arbitary data.
|
||||
bool ProfileManager::GetProfileBaseAndData(boost::optional<size_t> index, ProfileBase& profile,
|
||||
ProfileData& data) const {
|
||||
if (GetProfileBase(index, profile)) {
|
||||
data = profiles[index.get()].data;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Return the users profile base and the unknown arbitary data.
|
||||
bool ProfileManager::GetProfileBaseAndData(UUID uuid, ProfileBase& profile,
|
||||
ProfileData& data) const {
|
||||
auto idx = GetUserIndex(uuid);
|
||||
return GetProfileBaseAndData(idx, profile, data);
|
||||
}
|
||||
|
||||
/// Return the users profile base and the unknown arbitary data.
|
||||
bool ProfileManager::GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile,
|
||||
ProfileData& data) const {
|
||||
return GetProfileBaseAndData(user.user_uuid, profile, data);
|
||||
}
|
||||
|
||||
/// Returns if the system is allowing user registrations or not
|
||||
bool ProfileManager::CanSystemRegisterUser() const {
|
||||
return false; // TODO(ogniK): Games shouldn't have
|
||||
// access to user registration, when we
|
||||
// emulate qlaunch. Update this to dynamically change.
|
||||
}
|
||||
|
||||
}; // namespace Service::Account
|
||||
117
src/core/hle/service/acc/profile_manager.h
Normal file
117
src/core/hle/service/acc/profile_manager.h
Normal file
@@ -0,0 +1,117 @@
|
||||
// Copyright 2018 yuzu emulator team
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "boost/optional.hpp"
|
||||
#include "common/common_types.h"
|
||||
#include "common/swap.h"
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace Service::Account {
|
||||
constexpr size_t MAX_USERS = 8;
|
||||
constexpr size_t MAX_DATA = 128;
|
||||
constexpr u128 INVALID_UUID{{0, 0}};
|
||||
|
||||
struct UUID {
|
||||
// UUIDs which are 0 are considered invalid!
|
||||
u128 uuid = INVALID_UUID;
|
||||
UUID() = default;
|
||||
explicit UUID(const u128& id) : uuid{id} {}
|
||||
explicit UUID(const u64 lo, const u64 hi) : uuid{{lo, hi}} {}
|
||||
|
||||
explicit operator bool() const {
|
||||
return uuid != INVALID_UUID;
|
||||
}
|
||||
|
||||
bool operator==(const UUID& rhs) const {
|
||||
return uuid == rhs.uuid;
|
||||
}
|
||||
|
||||
bool operator!=(const UUID& rhs) const {
|
||||
return !operator==(rhs);
|
||||
}
|
||||
|
||||
// TODO(ogniK): Properly generate uuids based on RFC-4122
|
||||
const UUID& Generate();
|
||||
|
||||
// Set the UUID to {0,0} to be considered an invalid user
|
||||
void Invalidate() {
|
||||
uuid = INVALID_UUID;
|
||||
}
|
||||
std::string Format() const {
|
||||
return fmt::format("0x{:016X}{:016X}", uuid[1], uuid[0]);
|
||||
}
|
||||
};
|
||||
static_assert(sizeof(UUID) == 16, "UUID is an invalid size!");
|
||||
|
||||
using ProfileUsername = std::array<u8, 0x20>;
|
||||
using ProfileData = std::array<u8, MAX_DATA>;
|
||||
using UserIDArray = std::array<UUID, MAX_USERS>;
|
||||
|
||||
/// This holds general information about a users profile. This is where we store all the information
|
||||
/// based on a specific user
|
||||
struct ProfileInfo {
|
||||
UUID user_uuid;
|
||||
ProfileUsername username;
|
||||
u64 creation_time;
|
||||
ProfileData data; // TODO(ognik): Work out what this is
|
||||
bool is_open;
|
||||
};
|
||||
|
||||
struct ProfileBase {
|
||||
UUID user_uuid;
|
||||
u64_le timestamp;
|
||||
ProfileUsername username;
|
||||
|
||||
// Zero out all the fields to make the profile slot considered "Empty"
|
||||
void Invalidate() {
|
||||
user_uuid.Invalidate();
|
||||
timestamp = 0;
|
||||
username.fill(0);
|
||||
}
|
||||
};
|
||||
static_assert(sizeof(ProfileBase) == 0x38, "ProfileBase is an invalid size");
|
||||
|
||||
/// The profile manager is used for handling multiple user profiles at once. It keeps track of open
|
||||
/// users, all the accounts registered on the "system" as well as fetching individual "ProfileInfo"
|
||||
/// objects
|
||||
class ProfileManager {
|
||||
public:
|
||||
ProfileManager(); // TODO(ogniK): Load from system save
|
||||
ResultCode AddUser(const ProfileInfo& user);
|
||||
ResultCode CreateNewUser(UUID uuid, const ProfileUsername& username);
|
||||
ResultCode CreateNewUser(UUID uuid, const std::string& username);
|
||||
boost::optional<size_t> GetUserIndex(const UUID& uuid) const;
|
||||
boost::optional<size_t> GetUserIndex(const ProfileInfo& user) const;
|
||||
bool GetProfileBase(boost::optional<size_t> index, ProfileBase& profile) const;
|
||||
bool GetProfileBase(UUID uuid, ProfileBase& profile) const;
|
||||
bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const;
|
||||
bool GetProfileBaseAndData(boost::optional<size_t> index, ProfileBase& profile,
|
||||
ProfileData& data) const;
|
||||
bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, ProfileData& data) const;
|
||||
bool GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile,
|
||||
ProfileData& data) const;
|
||||
size_t GetUserCount() const;
|
||||
size_t GetOpenUserCount() const;
|
||||
bool UserExists(UUID uuid) const;
|
||||
void OpenUser(UUID uuid);
|
||||
void CloseUser(UUID uuid);
|
||||
UserIDArray GetOpenUsers() const;
|
||||
UserIDArray GetAllUsers() const;
|
||||
UUID GetLastOpenedUser() const;
|
||||
|
||||
bool CanSystemRegisterUser() const;
|
||||
|
||||
private:
|
||||
std::array<ProfileInfo, MAX_USERS> profiles{};
|
||||
size_t user_count = 0;
|
||||
boost::optional<size_t> AddToProfiles(const ProfileInfo& profile);
|
||||
bool RemoveProfileAtIndex(size_t index);
|
||||
UUID last_opened_user{INVALID_UUID};
|
||||
};
|
||||
|
||||
}; // namespace Service::Account
|
||||
@@ -2,6 +2,7 @@
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <array>
|
||||
#include <cinttypes>
|
||||
#include <stack>
|
||||
#include "core/core.h"
|
||||
@@ -145,8 +146,8 @@ ISelfController::ISelfController(std::shared_ptr<NVFlinger::NVFlinger> nvflinger
|
||||
{51, nullptr, "ApproveToDisplay"},
|
||||
{60, nullptr, "OverrideAutoSleepTimeAndDimmingTime"},
|
||||
{61, nullptr, "SetMediaPlaybackState"},
|
||||
{62, nullptr, "SetIdleTimeDetectionExtension"},
|
||||
{63, nullptr, "GetIdleTimeDetectionExtension"},
|
||||
{62, &ISelfController::SetIdleTimeDetectionExtension, "SetIdleTimeDetectionExtension"},
|
||||
{63, &ISelfController::GetIdleTimeDetectionExtension, "GetIdleTimeDetectionExtension"},
|
||||
{64, nullptr, "SetInputDetectionSourceSet"},
|
||||
{65, nullptr, "ReportUserIsActive"},
|
||||
{66, nullptr, "GetCurrentIlluminance"},
|
||||
@@ -281,6 +282,23 @@ void ISelfController::SetHandlesRequestToDisplay(Kernel::HLERequestContext& ctx)
|
||||
LOG_WARNING(Service_AM, "(STUBBED) called");
|
||||
}
|
||||
|
||||
void ISelfController::SetIdleTimeDetectionExtension(Kernel::HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
idle_time_detection_extension = rp.Pop<u32>();
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
|
||||
LOG_WARNING(Service_AM, "(STUBBED) called");
|
||||
}
|
||||
|
||||
void ISelfController::GetIdleTimeDetectionExtension(Kernel::HLERequestContext& ctx) {
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
rb.Push<u32>(idle_time_detection_extension);
|
||||
|
||||
LOG_WARNING(Service_AM, "(STUBBED) called");
|
||||
}
|
||||
|
||||
ICommonStateGetter::ICommonStateGetter() : ServiceFramework("ICommonStateGetter") {
|
||||
static const FunctionInfo functions[] = {
|
||||
{0, &ICommonStateGetter::GetEventHandle, "GetEventHandle"},
|
||||
@@ -306,7 +324,8 @@ ICommonStateGetter::ICommonStateGetter() : ServiceFramework("ICommonStateGetter"
|
||||
{52, nullptr, "SwitchLcdBacklight"},
|
||||
{55, nullptr, "IsInControllerFirmwareUpdateSection"},
|
||||
{60, nullptr, "GetDefaultDisplayResolution"},
|
||||
{61, nullptr, "GetDefaultDisplayResolutionChangeEvent"},
|
||||
{61, &ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent,
|
||||
"GetDefaultDisplayResolutionChangeEvent"},
|
||||
{62, nullptr, "GetHdcpAuthenticationState"},
|
||||
{63, nullptr, "GetHdcpAuthenticationStateChangeEvent"},
|
||||
};
|
||||
@@ -341,6 +360,16 @@ void ICommonStateGetter::GetCurrentFocusState(Kernel::HLERequestContext& ctx) {
|
||||
LOG_WARNING(Service_AM, "(STUBBED) called");
|
||||
}
|
||||
|
||||
void ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent(Kernel::HLERequestContext& ctx) {
|
||||
event->Signal();
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2, 1};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
rb.PushCopyObjects(event);
|
||||
|
||||
LOG_WARNING(Service_AM, "(STUBBED) called");
|
||||
}
|
||||
|
||||
void ICommonStateGetter::GetOperationMode(Kernel::HLERequestContext& ctx) {
|
||||
const bool use_docked_mode{Settings::values.use_docked_mode};
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
@@ -597,16 +626,16 @@ IApplicationFunctions::IApplicationFunctions() : ServiceFramework("IApplicationF
|
||||
}
|
||||
|
||||
void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) {
|
||||
constexpr u8 data[0x88] = {
|
||||
constexpr std::array<u8, 0x88> data{{
|
||||
0xca, 0x97, 0x94, 0xc7, // Magic
|
||||
1, 0, 0, 0, // IsAccountSelected (bool)
|
||||
1, 0, 0, 0, // User Id (word 0)
|
||||
0, 0, 0, 0, // User Id (word 1)
|
||||
0, 0, 0, 0, // User Id (word 2)
|
||||
0, 0, 0, 0 // User Id (word 3)
|
||||
};
|
||||
}};
|
||||
|
||||
std::vector<u8> buffer(data, data + sizeof(data));
|
||||
std::vector<u8> buffer(data.begin(), data.end());
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
||||
|
||||
|
||||
@@ -87,9 +87,12 @@ private:
|
||||
void CreateManagedDisplayLayer(Kernel::HLERequestContext& ctx);
|
||||
void SetScreenShotPermission(Kernel::HLERequestContext& ctx);
|
||||
void SetHandlesRequestToDisplay(Kernel::HLERequestContext& ctx);
|
||||
void SetIdleTimeDetectionExtension(Kernel::HLERequestContext& ctx);
|
||||
void GetIdleTimeDetectionExtension(Kernel::HLERequestContext& ctx);
|
||||
|
||||
std::shared_ptr<NVFlinger::NVFlinger> nvflinger;
|
||||
Kernel::SharedPtr<Kernel::Event> launchable_event;
|
||||
u32 idle_time_detection_extension = 0;
|
||||
};
|
||||
|
||||
class ICommonStateGetter final : public ServiceFramework<ICommonStateGetter> {
|
||||
@@ -110,6 +113,7 @@ private:
|
||||
void GetEventHandle(Kernel::HLERequestContext& ctx);
|
||||
void ReceiveMessage(Kernel::HLERequestContext& ctx);
|
||||
void GetCurrentFocusState(Kernel::HLERequestContext& ctx);
|
||||
void GetDefaultDisplayResolutionChangeEvent(Kernel::HLERequestContext& ctx);
|
||||
void GetOperationMode(Kernel::HLERequestContext& ctx);
|
||||
void GetPerformanceMode(Kernel::HLERequestContext& ctx);
|
||||
|
||||
|
||||
@@ -7,12 +7,14 @@
|
||||
#include "common/assert.h"
|
||||
#include "common/file_util.h"
|
||||
#include "core/core.h"
|
||||
#include "core/file_sys/bis_factory.h"
|
||||
#include "core/file_sys/errors.h"
|
||||
#include "core/file_sys/mode.h"
|
||||
#include "core/file_sys/romfs_factory.h"
|
||||
#include "core/file_sys/savedata_factory.h"
|
||||
#include "core/file_sys/sdmc_factory.h"
|
||||
#include "core/file_sys/vfs.h"
|
||||
#include "core/file_sys/vfs_offset.h"
|
||||
#include "core/file_sys/vfs_real.h"
|
||||
#include "core/hle/service/filesystem/filesystem.h"
|
||||
#include "core/hle/service/filesystem/fsp_ldr.h"
|
||||
#include "core/hle/service/filesystem/fsp_pr.h"
|
||||
@@ -256,15 +258,28 @@ ResultCode RegisterBIS(std::unique_ptr<FileSys::BISFactory>&& factory) {
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ResultVal<FileSys::VirtualFile> OpenRomFS(u64 title_id) {
|
||||
LOG_TRACE(Service_FS, "Opening RomFS for title_id={:016X}", title_id);
|
||||
ResultVal<FileSys::VirtualFile> OpenRomFSCurrentProcess() {
|
||||
LOG_TRACE(Service_FS, "Opening RomFS for current process");
|
||||
|
||||
if (romfs_factory == nullptr) {
|
||||
// TODO(bunnei): Find a better error code for this
|
||||
return ResultCode(-1);
|
||||
}
|
||||
|
||||
return romfs_factory->Open(title_id);
|
||||
return romfs_factory->OpenCurrentProcess();
|
||||
}
|
||||
|
||||
ResultVal<FileSys::VirtualFile> OpenRomFS(u64 title_id, FileSys::StorageId storage_id,
|
||||
FileSys::ContentRecordType type) {
|
||||
LOG_TRACE(Service_FS, "Opening RomFS for title_id={:016X}, storage_id={:02X}, type={:02X}",
|
||||
title_id, static_cast<u8>(storage_id), static_cast<u8>(type));
|
||||
|
||||
if (romfs_factory == nullptr) {
|
||||
// TODO(bunnei): Find a better error code for this
|
||||
return ResultCode(-1);
|
||||
}
|
||||
|
||||
return romfs_factory->Open(title_id, storage_id, type);
|
||||
}
|
||||
|
||||
ResultVal<FileSys::VirtualDir> OpenSaveData(FileSys::SaveDataSpaceId space,
|
||||
|
||||
@@ -6,14 +6,24 @@
|
||||
|
||||
#include <memory>
|
||||
#include "common/common_types.h"
|
||||
#include "core/file_sys/bis_factory.h"
|
||||
#include "core/file_sys/directory.h"
|
||||
#include "core/file_sys/mode.h"
|
||||
#include "core/file_sys/romfs_factory.h"
|
||||
#include "core/file_sys/savedata_factory.h"
|
||||
#include "core/file_sys/sdmc_factory.h"
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace FileSys {
|
||||
class BISFactory;
|
||||
class RegisteredCache;
|
||||
class RomFSFactory;
|
||||
class SaveDataFactory;
|
||||
class SDMCFactory;
|
||||
|
||||
enum class ContentRecordType : u8;
|
||||
enum class Mode : u32;
|
||||
enum class SaveDataSpaceId : u8;
|
||||
enum class StorageId : u8;
|
||||
|
||||
struct SaveDataDescriptor;
|
||||
} // namespace FileSys
|
||||
|
||||
namespace Service {
|
||||
|
||||
namespace SM {
|
||||
@@ -27,7 +37,9 @@ ResultCode RegisterSaveData(std::unique_ptr<FileSys::SaveDataFactory>&& factory)
|
||||
ResultCode RegisterSDMC(std::unique_ptr<FileSys::SDMCFactory>&& factory);
|
||||
ResultCode RegisterBIS(std::unique_ptr<FileSys::BISFactory>&& factory);
|
||||
|
||||
ResultVal<FileSys::VirtualFile> OpenRomFS(u64 title_id);
|
||||
ResultVal<FileSys::VirtualFile> OpenRomFSCurrentProcess();
|
||||
ResultVal<FileSys::VirtualFile> OpenRomFS(u64 title_id, FileSys::StorageId storage_id,
|
||||
FileSys::ContentRecordType type);
|
||||
ResultVal<FileSys::VirtualDir> OpenSaveData(FileSys::SaveDataSpaceId space,
|
||||
FileSys::SaveDataDescriptor save_struct);
|
||||
ResultVal<FileSys::VirtualDir> OpenSDMC();
|
||||
|
||||
@@ -13,9 +13,12 @@
|
||||
#include "common/common_types.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/string_util.h"
|
||||
#include "core/core.h"
|
||||
#include "core/file_sys/directory.h"
|
||||
#include "core/file_sys/errors.h"
|
||||
#include "core/file_sys/mode.h"
|
||||
#include "core/file_sys/nca_metadata.h"
|
||||
#include "core/file_sys/savedata_factory.h"
|
||||
#include "core/file_sys/vfs.h"
|
||||
#include "core/hle/ipc_helpers.h"
|
||||
#include "core/hle/kernel/process.h"
|
||||
#include "core/hle/service/filesystem/filesystem.h"
|
||||
@@ -23,15 +26,6 @@
|
||||
|
||||
namespace Service::FileSystem {
|
||||
|
||||
enum class StorageId : u8 {
|
||||
None = 0,
|
||||
Host = 1,
|
||||
GameCard = 2,
|
||||
NandSystem = 3,
|
||||
NandUser = 4,
|
||||
SdCard = 5,
|
||||
};
|
||||
|
||||
class IStorage final : public ServiceFramework<IStorage> {
|
||||
public:
|
||||
explicit IStorage(FileSys::VirtualFile backend_)
|
||||
@@ -467,7 +461,7 @@ FSP_SRV::FSP_SRV() : ServiceFramework("fsp-srv") {
|
||||
{110, nullptr, "OpenContentStorageFileSystem"},
|
||||
{200, &FSP_SRV::OpenDataStorageByCurrentProcess, "OpenDataStorageByCurrentProcess"},
|
||||
{201, nullptr, "OpenDataStorageByProgramId"},
|
||||
{202, nullptr, "OpenDataStorageByDataId"},
|
||||
{202, &FSP_SRV::OpenDataStorageByDataId, "OpenDataStorageByDataId"},
|
||||
{203, &FSP_SRV::OpenRomStorage, "OpenRomStorage"},
|
||||
{400, nullptr, "OpenDeviceOperator"},
|
||||
{500, nullptr, "OpenSdCardDetectionEventNotifier"},
|
||||
@@ -580,7 +574,7 @@ void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) {
|
||||
void FSP_SRV::OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx) {
|
||||
LOG_DEBUG(Service_FS, "called");
|
||||
|
||||
auto romfs = OpenRomFS(Core::System::GetInstance().CurrentProcess()->program_id);
|
||||
auto romfs = OpenRomFSCurrentProcess();
|
||||
if (romfs.Failed()) {
|
||||
// TODO (bunnei): Find the right error code to use here
|
||||
LOG_CRITICAL(Service_FS, "no file system interface available!");
|
||||
@@ -596,10 +590,37 @@ void FSP_SRV::OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx) {
|
||||
rb.PushIpcInterface<IStorage>(std::move(storage));
|
||||
}
|
||||
|
||||
void FSP_SRV::OpenDataStorageByDataId(Kernel::HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto storage_id = rp.PopRaw<FileSys::StorageId>();
|
||||
const auto unknown = rp.PopRaw<u32>();
|
||||
const auto title_id = rp.PopRaw<u64>();
|
||||
|
||||
LOG_DEBUG(Service_FS, "called with storage_id={:02X}, unknown={:08X}, title_id={:016X}",
|
||||
static_cast<u8>(storage_id), unknown, title_id);
|
||||
|
||||
auto data = OpenRomFS(title_id, storage_id, FileSys::ContentRecordType::Data);
|
||||
if (data.Failed()) {
|
||||
// TODO(DarkLordZach): Find the right error code to use here
|
||||
LOG_ERROR(Service_FS,
|
||||
"could not open data storage with title_id={:016X}, storage_id={:02X}", title_id,
|
||||
static_cast<u8>(storage_id));
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultCode(-1));
|
||||
return;
|
||||
}
|
||||
|
||||
IStorage storage(std::move(data.Unwrap()));
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
rb.PushIpcInterface<IStorage>(std::move(storage));
|
||||
}
|
||||
|
||||
void FSP_SRV::OpenRomStorage(Kernel::HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
|
||||
auto storage_id = rp.PopRaw<StorageId>();
|
||||
auto storage_id = rp.PopRaw<FileSys::StorageId>();
|
||||
auto title_id = rp.PopRaw<u64>();
|
||||
|
||||
LOG_DEBUG(Service_FS, "called with storage_id={:02X}, title_id={:016X}",
|
||||
|
||||
@@ -25,6 +25,7 @@ private:
|
||||
void MountSaveData(Kernel::HLERequestContext& ctx);
|
||||
void GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx);
|
||||
void OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx);
|
||||
void OpenDataStorageByDataId(Kernel::HLERequestContext& ctx);
|
||||
void OpenRomStorage(Kernel::HLERequestContext& ctx);
|
||||
|
||||
FileSys::VirtualFile romfs;
|
||||
|
||||
@@ -5,31 +5,98 @@
|
||||
#include "common/common_paths.h"
|
||||
#include "common/file_util.h"
|
||||
#include "core/core.h"
|
||||
#include "core/file_sys/bis_factory.h"
|
||||
#include "core/file_sys/romfs.h"
|
||||
#include "core/hle/ipc_helpers.h"
|
||||
#include "core/hle/service/filesystem/filesystem.h"
|
||||
#include "core/hle/service/ns/pl_u.h"
|
||||
|
||||
namespace Service::NS {
|
||||
|
||||
enum class FontArchives : u64 {
|
||||
Extension = 0x0100000000000810,
|
||||
Standard = 0x0100000000000811,
|
||||
Korean = 0x0100000000000812,
|
||||
ChineseTraditional = 0x0100000000000813,
|
||||
ChineseSimple = 0x0100000000000814,
|
||||
};
|
||||
|
||||
struct FontRegion {
|
||||
u32 offset;
|
||||
u32 size;
|
||||
};
|
||||
|
||||
static constexpr std::array<std::pair<FontArchives, const char*>, 7> SHARED_FONTS{
|
||||
std::make_pair(FontArchives::Standard, "nintendo_udsg-r_std_003.bfttf"),
|
||||
std::make_pair(FontArchives::ChineseSimple, "nintendo_udsg-r_org_zh-cn_003.bfttf"),
|
||||
std::make_pair(FontArchives::ChineseSimple, "nintendo_udsg-r_ext_zh-cn_003.bfttf"),
|
||||
std::make_pair(FontArchives::ChineseTraditional, "nintendo_udjxh-db_zh-tw_003.bfttf"),
|
||||
std::make_pair(FontArchives::Korean, "nintendo_udsg-r_ko_003.bfttf"),
|
||||
std::make_pair(FontArchives::Extension, "nintendo_ext_003.bfttf"),
|
||||
std::make_pair(FontArchives::Extension, "nintendo_ext2_003.bfttf")};
|
||||
|
||||
// The below data is specific to shared font data dumped from Switch on f/w 2.2
|
||||
// Virtual address and offsets/sizes likely will vary by dump
|
||||
static constexpr VAddr SHARED_FONT_MEM_VADDR{0x00000009d3016000ULL};
|
||||
static constexpr u32 EXPECTED_RESULT{
|
||||
0x7f9a0218}; // What we expect the decrypted bfttf first 4 bytes to be
|
||||
static constexpr u32 EXPECTED_MAGIC{
|
||||
0x36f81a1e}; // What we expect the encrypted bfttf first 4 bytes to be
|
||||
static constexpr u64 SHARED_FONT_MEM_SIZE{0x1100000};
|
||||
static constexpr std::array<FontRegion, 6> SHARED_FONT_REGIONS{
|
||||
FontRegion{0x00000008, 0x001fe764}, FontRegion{0x001fe774, 0x00773e58},
|
||||
FontRegion{0x009725d4, 0x0001aca8}, FontRegion{0x0098d284, 0x00369cec},
|
||||
FontRegion{0x00cf6f78, 0x0039b858}, FontRegion{0x010927d8, 0x00019e80},
|
||||
};
|
||||
static constexpr FontRegion EMPTY_REGION{0, 0};
|
||||
std::vector<FontRegion>
|
||||
SHARED_FONT_REGIONS{}; // Automatically populated based on shared_fonts dump or system archives
|
||||
|
||||
const FontRegion& GetSharedFontRegion(size_t index) {
|
||||
if (index >= SHARED_FONT_REGIONS.size() || SHARED_FONT_REGIONS.empty()) {
|
||||
// No font fallback
|
||||
return EMPTY_REGION;
|
||||
}
|
||||
return SHARED_FONT_REGIONS.at(index);
|
||||
}
|
||||
|
||||
enum class LoadState : u32 {
|
||||
Loading = 0,
|
||||
Done = 1,
|
||||
};
|
||||
|
||||
void DecryptSharedFont(const std::vector<u32>& input, std::vector<u8>& output, size_t& offset) {
|
||||
ASSERT_MSG(offset + (input.size() * sizeof(u32)) < SHARED_FONT_MEM_SIZE,
|
||||
"Shared fonts exceeds 17mb!");
|
||||
ASSERT_MSG(input[0] == EXPECTED_MAGIC, "Failed to derive key, unexpected magic number");
|
||||
|
||||
const u32 KEY = input[0] ^ EXPECTED_RESULT; // Derive key using an inverse xor
|
||||
std::vector<u32> transformed_font(input.size());
|
||||
// TODO(ogniK): Figure out a better way to do this
|
||||
std::transform(input.begin(), input.end(), transformed_font.begin(),
|
||||
[&KEY](u32 font_data) { return Common::swap32(font_data ^ KEY); });
|
||||
transformed_font[1] = Common::swap32(transformed_font[1]) ^ KEY; // "re-encrypt" the size
|
||||
std::memcpy(output.data() + offset, transformed_font.data(),
|
||||
transformed_font.size() * sizeof(u32));
|
||||
offset += transformed_font.size() * sizeof(u32);
|
||||
}
|
||||
|
||||
static u32 GetU32Swapped(const u8* data) {
|
||||
u32 value;
|
||||
std::memcpy(&value, data, sizeof(value));
|
||||
return Common::swap32(value); // Helper function to make BuildSharedFontsRawRegions a bit nicer
|
||||
}
|
||||
|
||||
void BuildSharedFontsRawRegions(const std::vector<u8>& input) {
|
||||
unsigned cur_offset = 0; // As we can derive the xor key we can just populate the offsets based
|
||||
// on the shared memory dump
|
||||
for (size_t i = 0; i < SHARED_FONTS.size(); i++) {
|
||||
// Out of shared fonts/Invalid font
|
||||
if (GetU32Swapped(input.data() + cur_offset) != EXPECTED_RESULT)
|
||||
break;
|
||||
const u32 KEY = GetU32Swapped(input.data() + cur_offset) ^
|
||||
EXPECTED_MAGIC; // Derive key withing inverse xor
|
||||
const u32 SIZE = GetU32Swapped(input.data() + cur_offset + 4) ^ KEY;
|
||||
SHARED_FONT_REGIONS.push_back(FontRegion{cur_offset + 8, SIZE});
|
||||
cur_offset += SIZE + 8;
|
||||
}
|
||||
}
|
||||
|
||||
PL_U::PL_U() : ServiceFramework("pl:u") {
|
||||
static const FunctionInfo functions[] = {
|
||||
{0, &PL_U::RequestLoad, "RequestLoad"},
|
||||
@@ -40,26 +107,78 @@ PL_U::PL_U() : ServiceFramework("pl:u") {
|
||||
{5, &PL_U::GetSharedFontInOrderOfPriority, "GetSharedFontInOrderOfPriority"},
|
||||
};
|
||||
RegisterHandlers(functions);
|
||||
|
||||
// Attempt to load shared font data from disk
|
||||
const std::string filepath{FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir) + SHARED_FONT};
|
||||
FileUtil::CreateFullPath(filepath); // Create path if not already created
|
||||
FileUtil::IOFile file(filepath, "rb");
|
||||
|
||||
shared_font = std::make_shared<std::vector<u8>>(SHARED_FONT_MEM_SIZE);
|
||||
if (file.IsOpen()) {
|
||||
// Read shared font data
|
||||
ASSERT(file.GetSize() == SHARED_FONT_MEM_SIZE);
|
||||
file.ReadBytes(shared_font->data(), shared_font->size());
|
||||
const auto nand = FileSystem::GetSystemNANDContents();
|
||||
// Rebuild shared fonts from data ncas
|
||||
if (nand->HasEntry(static_cast<u64>(FontArchives::Standard),
|
||||
FileSys::ContentRecordType::Data)) {
|
||||
size_t offset = 0;
|
||||
shared_font = std::make_shared<std::vector<u8>>(SHARED_FONT_MEM_SIZE);
|
||||
for (auto font : SHARED_FONTS) {
|
||||
const auto nca =
|
||||
nand->GetEntry(static_cast<u64>(font.first), FileSys::ContentRecordType::Data);
|
||||
if (!nca) {
|
||||
LOG_ERROR(Service_NS, "Failed to find {:016X}! Skipping",
|
||||
static_cast<u64>(font.first));
|
||||
continue;
|
||||
}
|
||||
const auto romfs = nca->GetRomFS();
|
||||
if (!romfs) {
|
||||
LOG_ERROR(Service_NS, "{:016X} has no RomFS! Skipping",
|
||||
static_cast<u64>(font.first));
|
||||
continue;
|
||||
}
|
||||
const auto extracted_romfs = FileSys::ExtractRomFS(romfs);
|
||||
if (!extracted_romfs) {
|
||||
LOG_ERROR(Service_NS, "Failed to extract RomFS for {:016X}! Skipping",
|
||||
static_cast<u64>(font.first));
|
||||
continue;
|
||||
}
|
||||
const auto font_fp = extracted_romfs->GetFile(font.second);
|
||||
if (!font_fp) {
|
||||
LOG_ERROR(Service_NS, "{:016X} has no file \"{}\"! Skipping",
|
||||
static_cast<u64>(font.first), font.second);
|
||||
continue;
|
||||
}
|
||||
std::vector<u32> font_data_u32(font_fp->GetSize() / sizeof(u32));
|
||||
font_fp->ReadBytes<u32>(font_data_u32.data(), font_fp->GetSize());
|
||||
// We need to be BigEndian as u32s for the xor encryption
|
||||
std::transform(font_data_u32.begin(), font_data_u32.end(), font_data_u32.begin(),
|
||||
Common::swap32);
|
||||
FontRegion region{
|
||||
static_cast<u32>(offset + 8),
|
||||
static_cast<u32>((font_data_u32.size() * sizeof(u32)) -
|
||||
8)}; // Font offset and size do not account for the header
|
||||
DecryptSharedFont(font_data_u32, *shared_font, offset);
|
||||
SHARED_FONT_REGIONS.push_back(region);
|
||||
}
|
||||
} else {
|
||||
LOG_WARNING(Service_NS, "Unable to load shared font: {}", filepath);
|
||||
const std::string filepath{FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir) +
|
||||
SHARED_FONT};
|
||||
// Create path if not already created
|
||||
if (!FileUtil::CreateFullPath(filepath)) {
|
||||
LOG_ERROR(Service_NS, "Failed to create sharedfonts path \"{}\"!", filepath);
|
||||
return;
|
||||
}
|
||||
FileUtil::IOFile file(filepath, "rb");
|
||||
|
||||
shared_font = std::make_shared<std::vector<u8>>(
|
||||
SHARED_FONT_MEM_SIZE); // Shared memory needs to always be allocated and a fixed size
|
||||
if (file.IsOpen()) {
|
||||
// Read shared font data
|
||||
ASSERT(file.GetSize() == SHARED_FONT_MEM_SIZE);
|
||||
file.ReadBytes(shared_font->data(), shared_font->size());
|
||||
BuildSharedFontsRawRegions(*shared_font);
|
||||
} else {
|
||||
LOG_WARNING(Service_NS, "Unable to load shared font: {}", filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PL_U::RequestLoad(Kernel::HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const u32 shared_font_type{rp.Pop<u32>()};
|
||||
|
||||
// Games don't call this so all fonts should be loaded
|
||||
LOG_DEBUG(Service_NS, "called, shared_font_type={}", shared_font_type);
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
@@ -82,7 +201,7 @@ void PL_U::GetSize(Kernel::HLERequestContext& ctx) {
|
||||
LOG_DEBUG(Service_NS, "called, font_id={}", font_id);
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
rb.Push<u32>(SHARED_FONT_REGIONS[font_id].size);
|
||||
rb.Push<u32>(GetSharedFontRegion(font_id).size);
|
||||
}
|
||||
|
||||
void PL_U::GetSharedMemoryAddressOffset(Kernel::HLERequestContext& ctx) {
|
||||
@@ -92,14 +211,10 @@ void PL_U::GetSharedMemoryAddressOffset(Kernel::HLERequestContext& ctx) {
|
||||
LOG_DEBUG(Service_NS, "called, font_id={}", font_id);
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
rb.Push<u32>(SHARED_FONT_REGIONS[font_id].offset);
|
||||
rb.Push<u32>(GetSharedFontRegion(font_id).offset);
|
||||
}
|
||||
|
||||
void PL_U::GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx) {
|
||||
// TODO(bunnei): This is a less-than-ideal solution to load a RAM dump of the Switch shared
|
||||
// font data. This (likely) relies on exact address, size, and offsets from the original
|
||||
// dump. In the future, we need to replace this with a more robust solution.
|
||||
|
||||
// Map backing memory for the font data
|
||||
Core::CurrentProcess()->vm_manager.MapMemoryBlock(
|
||||
SHARED_FONT_MEM_VADDR, shared_font, 0, SHARED_FONT_MEM_SIZE, Kernel::MemoryState::Shared);
|
||||
@@ -128,8 +243,9 @@ void PL_U::GetSharedFontInOrderOfPriority(Kernel::HLERequestContext& ctx) {
|
||||
// TODO(ogniK): Have actual priority order
|
||||
for (size_t i = 0; i < SHARED_FONT_REGIONS.size(); i++) {
|
||||
font_codes.push_back(static_cast<u32>(i));
|
||||
font_offsets.push_back(SHARED_FONT_REGIONS[i].offset);
|
||||
font_sizes.push_back(SHARED_FONT_REGIONS[i].size);
|
||||
auto region = GetSharedFontRegion(i);
|
||||
font_offsets.push_back(region.offset);
|
||||
font_sizes.push_back(region.size);
|
||||
}
|
||||
|
||||
ctx.WriteBuffer(font_codes, 0);
|
||||
|
||||
@@ -14,7 +14,8 @@ public:
|
||||
IParentalControlService() : ServiceFramework("IParentalControlService") {
|
||||
static const FunctionInfo functions[] = {
|
||||
{1, &IParentalControlService::Initialize, "Initialize"},
|
||||
{1001, nullptr, "CheckFreeCommunicationPermission"},
|
||||
{1001, &IParentalControlService::CheckFreeCommunicationPermission,
|
||||
"CheckFreeCommunicationPermission"},
|
||||
{1002, nullptr, "ConfirmLaunchApplicationPermission"},
|
||||
{1003, nullptr, "ConfirmResumeApplicationPermission"},
|
||||
{1004, nullptr, "ConfirmSnsPostPermission"},
|
||||
@@ -116,6 +117,12 @@ private:
|
||||
IPC::ResponseBuilder rb{ctx, 2, 0, 0};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
void CheckFreeCommunicationPermission(Kernel::HLERequestContext& ctx) {
|
||||
LOG_WARNING(Service_PCTL, "(STUBBED) called");
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
}
|
||||
};
|
||||
|
||||
void Module::Interface::CreateService(Kernel::HLERequestContext& ctx) {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "common/logging/log.h"
|
||||
#include "core/file_sys/content_archive.h"
|
||||
#include "core/file_sys/control_metadata.h"
|
||||
#include "core/file_sys/romfs_factory.h"
|
||||
#include "core/gdbstub/gdbstub.h"
|
||||
#include "core/hle/kernel/process.h"
|
||||
#include "core/hle/kernel/resource_limit.h"
|
||||
|
||||
@@ -3,28 +3,23 @@
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "common/file_util.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/string_util.h"
|
||||
#include "common/swap.h"
|
||||
#include "core/core.h"
|
||||
#include "core/file_sys/content_archive.h"
|
||||
#include "core/file_sys/program_metadata.h"
|
||||
#include "core/gdbstub/gdbstub.h"
|
||||
#include "core/file_sys/romfs_factory.h"
|
||||
#include "core/hle/kernel/process.h"
|
||||
#include "core/hle/kernel/resource_limit.h"
|
||||
#include "core/hle/service/filesystem/filesystem.h"
|
||||
#include "core/loader/deconstructed_rom_directory.h"
|
||||
#include "core/loader/nca.h"
|
||||
#include "core/loader/nso.h"
|
||||
#include "core/memory.h"
|
||||
|
||||
namespace Loader {
|
||||
|
||||
AppLoader_NCA::AppLoader_NCA(FileSys::VirtualFile file_)
|
||||
: AppLoader(std::move(file_)), nca(std::make_unique<FileSys::NCA>(file)) {}
|
||||
|
||||
AppLoader_NCA::~AppLoader_NCA() = default;
|
||||
|
||||
FileType AppLoader_NCA::IdentifyType(const FileSys::VirtualFile& file) {
|
||||
FileSys::NCA nca(file);
|
||||
|
||||
@@ -83,6 +78,4 @@ ResultStatus AppLoader_NCA::ReadProgramId(u64& out_program_id) {
|
||||
return ResultStatus::Success;
|
||||
}
|
||||
|
||||
AppLoader_NCA::~AppLoader_NCA() = default;
|
||||
|
||||
} // namespace Loader
|
||||
|
||||
@@ -4,20 +4,24 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "common/common_types.h"
|
||||
#include "core/file_sys/content_archive.h"
|
||||
#include "core/file_sys/program_metadata.h"
|
||||
#include "core/file_sys/vfs.h"
|
||||
#include "core/hle/kernel/object.h"
|
||||
#include "core/loader/loader.h"
|
||||
#include "deconstructed_rom_directory.h"
|
||||
|
||||
namespace FileSys {
|
||||
class NCA;
|
||||
}
|
||||
|
||||
namespace Loader {
|
||||
|
||||
class AppLoader_DeconstructedRomDirectory;
|
||||
|
||||
/// Loads an NCA file
|
||||
class AppLoader_NCA final : public AppLoader {
|
||||
public:
|
||||
explicit AppLoader_NCA(FileSys::VirtualFile file);
|
||||
~AppLoader_NCA() override;
|
||||
|
||||
/**
|
||||
* Returns the type of the file
|
||||
@@ -35,12 +39,7 @@ public:
|
||||
ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override;
|
||||
ResultStatus ReadProgramId(u64& out_program_id) override;
|
||||
|
||||
~AppLoader_NCA();
|
||||
|
||||
private:
|
||||
FileSys::ProgramMetadata metadata;
|
||||
|
||||
FileSys::NCAHeader header;
|
||||
std::unique_ptr<FileSys::NCA> nca;
|
||||
std::unique_ptr<AppLoader_DeconstructedRomDirectory> directory_loader;
|
||||
};
|
||||
|
||||
@@ -4,22 +4,14 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "common/file_util.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/string_util.h"
|
||||
#include "common/swap.h"
|
||||
#include "core/core.h"
|
||||
#include "common/common_types.h"
|
||||
#include "core/file_sys/card_image.h"
|
||||
#include "core/file_sys/content_archive.h"
|
||||
#include "core/file_sys/control_metadata.h"
|
||||
#include "core/file_sys/program_metadata.h"
|
||||
#include "core/file_sys/romfs.h"
|
||||
#include "core/gdbstub/gdbstub.h"
|
||||
#include "core/hle/kernel/process.h"
|
||||
#include "core/hle/kernel/resource_limit.h"
|
||||
#include "core/hle/service/filesystem/filesystem.h"
|
||||
#include "core/loader/nso.h"
|
||||
#include "core/loader/nca.h"
|
||||
#include "core/loader/xci.h"
|
||||
#include "core/memory.h"
|
||||
|
||||
namespace Loader {
|
||||
|
||||
|
||||
@@ -6,12 +6,18 @@
|
||||
|
||||
#include <memory>
|
||||
#include "common/common_types.h"
|
||||
#include "core/file_sys/card_image.h"
|
||||
#include "core/file_sys/vfs.h"
|
||||
#include "core/loader/loader.h"
|
||||
#include "core/loader/nca.h"
|
||||
|
||||
namespace FileSys {
|
||||
class NACP;
|
||||
class XCI;
|
||||
} // namespace FileSys
|
||||
|
||||
namespace Loader {
|
||||
|
||||
class AppLoader_NCA;
|
||||
|
||||
/// Loads an XCI file
|
||||
class AppLoader_XCI final : public AppLoader {
|
||||
public:
|
||||
@@ -37,8 +43,6 @@ public:
|
||||
ResultStatus ReadTitle(std::string& title) override;
|
||||
|
||||
private:
|
||||
FileSys::ProgramMetadata metadata;
|
||||
|
||||
std::unique_ptr<FileSys::XCI> xci;
|
||||
std::unique_ptr<AppLoader_NCA> nca_loader;
|
||||
|
||||
|
||||
@@ -76,22 +76,31 @@ double PerfStats::GetLastFrameTimeScale() {
|
||||
void FrameLimiter::DoFrameLimiting(microseconds current_system_time_us) {
|
||||
// Max lag caused by slow frames. Can be adjusted to compensate for too many slow frames. Higher
|
||||
// values increase the time needed to recover and limit framerate again after spikes.
|
||||
constexpr microseconds MAX_LAG_TIME_US = 25us;
|
||||
constexpr microseconds MAX_LAG_TIME_US = 25000us;
|
||||
|
||||
if (!Settings::values.toggle_framelimit) {
|
||||
if (!Settings::values.use_frame_limit) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto now = Clock::now();
|
||||
|
||||
frame_limiting_delta_err += current_system_time_us - previous_system_time_us;
|
||||
const double sleep_scale = Settings::values.frame_limit / 100.0;
|
||||
|
||||
// Max lag caused by slow frames. Shouldn't be more than the length of a frame at the current
|
||||
// speed percent or it will clamp too much and prevent this from properly limiting to that
|
||||
// percent. High values means it'll take longer after a slow frame to recover and start
|
||||
// limiting
|
||||
const microseconds max_lag_time_us = duration_cast<microseconds>(
|
||||
std::chrono::duration<double, std::chrono::microseconds::period>(25ms / sleep_scale));
|
||||
frame_limiting_delta_err += duration_cast<microseconds>(
|
||||
std::chrono::duration<double, std::chrono::microseconds::period>(
|
||||
(current_system_time_us - previous_system_time_us) / sleep_scale));
|
||||
frame_limiting_delta_err -= duration_cast<microseconds>(now - previous_walltime);
|
||||
frame_limiting_delta_err =
|
||||
std::clamp(frame_limiting_delta_err, -MAX_LAG_TIME_US, MAX_LAG_TIME_US);
|
||||
std::clamp(frame_limiting_delta_err, -max_lag_time_us, max_lag_time_us);
|
||||
|
||||
if (frame_limiting_delta_err > microseconds::zero()) {
|
||||
std::this_thread::sleep_for(frame_limiting_delta_err);
|
||||
|
||||
auto now_after_sleep = Clock::now();
|
||||
frame_limiting_delta_err -= duration_cast<microseconds>(now_after_sleep - now);
|
||||
now = now_after_sleep;
|
||||
|
||||
@@ -130,7 +130,8 @@ struct Values {
|
||||
|
||||
// Renderer
|
||||
float resolution_factor;
|
||||
bool toggle_framelimit;
|
||||
bool use_frame_limit;
|
||||
u16 frame_limit;
|
||||
bool use_accurate_framebuffers;
|
||||
|
||||
float bg_red;
|
||||
|
||||
@@ -2,34 +2,16 @@
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/common_types.h"
|
||||
#include "common/file_util.h"
|
||||
#include "common/scm_rev.h"
|
||||
#ifdef ARCHITECTURE_x86_64
|
||||
#include "common/x64/cpu_detect.h"
|
||||
#endif
|
||||
|
||||
#include "core/core.h"
|
||||
#include "core/settings.h"
|
||||
#include "core/telemetry_session.h"
|
||||
|
||||
namespace Core {
|
||||
|
||||
#ifdef ARCHITECTURE_x86_64
|
||||
static const char* CpuVendorToStr(Common::CPUVendor vendor) {
|
||||
switch (vendor) {
|
||||
case Common::CPUVendor::INTEL:
|
||||
return "Intel";
|
||||
case Common::CPUVendor::AMD:
|
||||
return "Amd";
|
||||
case Common::CPUVendor::OTHER:
|
||||
return "Other";
|
||||
}
|
||||
UNREACHABLE();
|
||||
}
|
||||
#endif
|
||||
|
||||
static u64 GenerateTelemetryId() {
|
||||
u64 telemetry_id{};
|
||||
return telemetry_id;
|
||||
@@ -37,8 +19,8 @@ static u64 GenerateTelemetryId() {
|
||||
|
||||
u64 GetTelemetryId() {
|
||||
u64 telemetry_id{};
|
||||
static const std::string& filename{FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) +
|
||||
"telemetry_id"};
|
||||
const std::string filename{FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) +
|
||||
"telemetry_id"};
|
||||
|
||||
if (FileUtil::Exists(filename)) {
|
||||
FileUtil::IOFile file(filename, "rb");
|
||||
@@ -62,8 +44,8 @@ u64 GetTelemetryId() {
|
||||
|
||||
u64 RegenerateTelemetryId() {
|
||||
const u64 new_telemetry_id{GenerateTelemetryId()};
|
||||
static const std::string& filename{FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) +
|
||||
"telemetry_id"};
|
||||
const std::string filename{FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) +
|
||||
"telemetry_id"};
|
||||
|
||||
FileUtil::IOFile file(filename, "wb");
|
||||
if (!file.IsOpen()) {
|
||||
@@ -112,48 +94,11 @@ TelemetrySession::TelemetrySession() {
|
||||
}
|
||||
|
||||
// Log application information
|
||||
const bool is_git_dirty{std::strstr(Common::g_scm_desc, "dirty") != nullptr};
|
||||
AddField(Telemetry::FieldType::App, "Git_IsDirty", is_git_dirty);
|
||||
AddField(Telemetry::FieldType::App, "Git_Branch", Common::g_scm_branch);
|
||||
AddField(Telemetry::FieldType::App, "Git_Revision", Common::g_scm_rev);
|
||||
AddField(Telemetry::FieldType::App, "BuildDate", Common::g_build_date);
|
||||
AddField(Telemetry::FieldType::App, "BuildName", Common::g_build_name);
|
||||
Telemetry::AppendBuildInfo(field_collection);
|
||||
|
||||
// Log user system information
|
||||
#ifdef ARCHITECTURE_x86_64
|
||||
AddField(Telemetry::FieldType::UserSystem, "CPU_Model", Common::GetCPUCaps().cpu_string);
|
||||
AddField(Telemetry::FieldType::UserSystem, "CPU_BrandString",
|
||||
Common::GetCPUCaps().brand_string);
|
||||
AddField(Telemetry::FieldType::UserSystem, "CPU_Vendor",
|
||||
CpuVendorToStr(Common::GetCPUCaps().vendor));
|
||||
AddField(Telemetry::FieldType::UserSystem, "CPU_Extension_x64_AES", Common::GetCPUCaps().aes);
|
||||
AddField(Telemetry::FieldType::UserSystem, "CPU_Extension_x64_AVX", Common::GetCPUCaps().avx);
|
||||
AddField(Telemetry::FieldType::UserSystem, "CPU_Extension_x64_AVX2", Common::GetCPUCaps().avx2);
|
||||
AddField(Telemetry::FieldType::UserSystem, "CPU_Extension_x64_BMI1", Common::GetCPUCaps().bmi1);
|
||||
AddField(Telemetry::FieldType::UserSystem, "CPU_Extension_x64_BMI2", Common::GetCPUCaps().bmi2);
|
||||
AddField(Telemetry::FieldType::UserSystem, "CPU_Extension_x64_FMA", Common::GetCPUCaps().fma);
|
||||
AddField(Telemetry::FieldType::UserSystem, "CPU_Extension_x64_FMA4", Common::GetCPUCaps().fma4);
|
||||
AddField(Telemetry::FieldType::UserSystem, "CPU_Extension_x64_SSE", Common::GetCPUCaps().sse);
|
||||
AddField(Telemetry::FieldType::UserSystem, "CPU_Extension_x64_SSE2", Common::GetCPUCaps().sse2);
|
||||
AddField(Telemetry::FieldType::UserSystem, "CPU_Extension_x64_SSE3", Common::GetCPUCaps().sse3);
|
||||
AddField(Telemetry::FieldType::UserSystem, "CPU_Extension_x64_SSSE3",
|
||||
Common::GetCPUCaps().ssse3);
|
||||
AddField(Telemetry::FieldType::UserSystem, "CPU_Extension_x64_SSE41",
|
||||
Common::GetCPUCaps().sse4_1);
|
||||
AddField(Telemetry::FieldType::UserSystem, "CPU_Extension_x64_SSE42",
|
||||
Common::GetCPUCaps().sse4_2);
|
||||
#else
|
||||
AddField(Telemetry::FieldType::UserSystem, "CPU_Model", "Other");
|
||||
#endif
|
||||
#ifdef __APPLE__
|
||||
AddField(Telemetry::FieldType::UserSystem, "OsPlatform", "Apple");
|
||||
#elif defined(_WIN32)
|
||||
AddField(Telemetry::FieldType::UserSystem, "OsPlatform", "Windows");
|
||||
#elif defined(__linux__) || defined(linux) || defined(__linux)
|
||||
AddField(Telemetry::FieldType::UserSystem, "OsPlatform", "Linux");
|
||||
#else
|
||||
AddField(Telemetry::FieldType::UserSystem, "OsPlatform", "Unknown");
|
||||
#endif
|
||||
// Log user system information
|
||||
Telemetry::AppendCPUInfo(field_collection);
|
||||
Telemetry::AppendOSInfo(field_collection);
|
||||
|
||||
// Log user configuration information
|
||||
AddField(Telemetry::FieldType::UserConfig, "Core_UseCpuJit", Settings::values.use_cpu_jit);
|
||||
@@ -161,8 +106,9 @@ TelemetrySession::TelemetrySession() {
|
||||
Settings::values.use_multi_core);
|
||||
AddField(Telemetry::FieldType::UserConfig, "Renderer_ResolutionFactor",
|
||||
Settings::values.resolution_factor);
|
||||
AddField(Telemetry::FieldType::UserConfig, "Renderer_ToggleFramelimit",
|
||||
Settings::values.toggle_framelimit);
|
||||
AddField(Telemetry::FieldType::UserConfig, "Renderer_UseFrameLimit",
|
||||
Settings::values.use_frame_limit);
|
||||
AddField(Telemetry::FieldType::UserConfig, "Renderer_FrameLimit", Settings::values.frame_limit);
|
||||
AddField(Telemetry::FieldType::UserConfig, "Renderer_UseAccurateFramebuffers",
|
||||
Settings::values.use_accurate_framebuffers);
|
||||
AddField(Telemetry::FieldType::UserConfig, "System_UseDockedMode",
|
||||
|
||||
@@ -222,6 +222,18 @@ void Maxwell3D::DrawArrays() {
|
||||
debug_context->OnEvent(Tegra::DebugContext::Event::FinishedPrimitiveBatch, nullptr);
|
||||
}
|
||||
|
||||
// Both instance configuration registers can not be set at the same time.
|
||||
ASSERT_MSG(!regs.draw.instance_next || !regs.draw.instance_cont,
|
||||
"Illegal combination of instancing parameters");
|
||||
|
||||
if (regs.draw.instance_next) {
|
||||
// Increment the current instance *before* drawing.
|
||||
state.current_instance += 1;
|
||||
} else if (!regs.draw.instance_cont) {
|
||||
// Reset the current instance to 0.
|
||||
state.current_instance = 0;
|
||||
}
|
||||
|
||||
const bool is_indexed{regs.index_array.count && !regs.vertex_buffer.count};
|
||||
rasterizer.AccelerateDrawBatch(is_indexed);
|
||||
|
||||
|
||||
@@ -311,6 +311,36 @@ public:
|
||||
AlwaysOld = 8,
|
||||
};
|
||||
|
||||
enum class LogicOperation : u32 {
|
||||
Clear = 0x1500,
|
||||
And = 0x1501,
|
||||
AndReverse = 0x1502,
|
||||
Copy = 0x1503,
|
||||
AndInverted = 0x1504,
|
||||
NoOp = 0x1505,
|
||||
Xor = 0x1506,
|
||||
Or = 0x1507,
|
||||
Nor = 0x1508,
|
||||
Equiv = 0x1509,
|
||||
Invert = 0x150A,
|
||||
OrReverse = 0x150B,
|
||||
CopyInverted = 0x150C,
|
||||
OrInverted = 0x150D,
|
||||
Nand = 0x150E,
|
||||
Set = 0x150F,
|
||||
};
|
||||
|
||||
enum class StencilOp : u32 {
|
||||
Keep = 1,
|
||||
Zero = 2,
|
||||
Replace = 3,
|
||||
Incr = 4,
|
||||
Decr = 5,
|
||||
Invert = 6,
|
||||
IncrWrap = 7,
|
||||
DecrWrap = 8,
|
||||
};
|
||||
|
||||
struct Cull {
|
||||
enum class FrontFace : u32 {
|
||||
ClockWise = 0x0900,
|
||||
@@ -489,8 +519,16 @@ public:
|
||||
|
||||
float clear_color[4];
|
||||
float clear_depth;
|
||||
INSERT_PADDING_WORDS(0x3);
|
||||
s32 clear_stencil;
|
||||
|
||||
INSERT_PADDING_WORDS(0x93);
|
||||
INSERT_PADDING_WORDS(0x6C);
|
||||
|
||||
s32 stencil_back_func_ref;
|
||||
u32 stencil_back_mask;
|
||||
u32 stencil_back_func_mask;
|
||||
|
||||
INSERT_PADDING_WORDS(0x20);
|
||||
|
||||
struct {
|
||||
u32 address_high;
|
||||
@@ -554,16 +592,14 @@ public:
|
||||
u32 enable[NumRenderTargets];
|
||||
} blend;
|
||||
|
||||
struct {
|
||||
u32 enable;
|
||||
u32 front_op_fail;
|
||||
u32 front_op_zfail;
|
||||
u32 front_op_zpass;
|
||||
u32 front_func_func;
|
||||
u32 front_func_ref;
|
||||
u32 front_func_mask;
|
||||
u32 front_mask;
|
||||
} stencil;
|
||||
u32 stencil_enable;
|
||||
StencilOp stencil_front_op_fail;
|
||||
StencilOp stencil_front_op_zfail;
|
||||
StencilOp stencil_front_op_zpass;
|
||||
ComparisonOp stencil_front_func_func;
|
||||
s32 stencil_front_func_ref;
|
||||
u32 stencil_front_func_mask;
|
||||
u32 stencil_front_mask;
|
||||
|
||||
INSERT_PADDING_WORDS(0x3);
|
||||
|
||||
@@ -607,13 +643,11 @@ public:
|
||||
|
||||
INSERT_PADDING_WORDS(0x5);
|
||||
|
||||
struct {
|
||||
u32 enable;
|
||||
u32 back_op_fail;
|
||||
u32 back_op_zfail;
|
||||
u32 back_op_zpass;
|
||||
u32 back_func_func;
|
||||
} stencil_two_side;
|
||||
u32 stencil_two_side_enable;
|
||||
StencilOp stencil_back_op_fail;
|
||||
StencilOp stencil_back_op_zfail;
|
||||
StencilOp stencil_back_op_zpass;
|
||||
ComparisonOp stencil_back_func_func;
|
||||
|
||||
INSERT_PADDING_WORDS(0x17);
|
||||
|
||||
@@ -638,6 +672,8 @@ public:
|
||||
union {
|
||||
u32 vertex_begin_gl;
|
||||
BitField<0, 16, PrimitiveTopology> topology;
|
||||
BitField<26, 1, u32> instance_next;
|
||||
BitField<27, 1, u32> instance_cont;
|
||||
};
|
||||
} draw;
|
||||
|
||||
@@ -677,11 +713,30 @@ public:
|
||||
|
||||
INSERT_PADDING_WORDS(0x7);
|
||||
|
||||
INSERT_PADDING_WORDS(0x46);
|
||||
INSERT_PADDING_WORDS(0x20);
|
||||
|
||||
struct {
|
||||
u32 is_instanced[NumVertexArrays];
|
||||
|
||||
/// Returns whether the vertex array specified by index is supposed to be
|
||||
/// accessed per instance or not.
|
||||
bool IsInstancingEnabled(u32 index) const {
|
||||
return is_instanced[index];
|
||||
}
|
||||
} instanced_arrays;
|
||||
|
||||
INSERT_PADDING_WORDS(0x6);
|
||||
|
||||
Cull cull;
|
||||
|
||||
INSERT_PADDING_WORDS(0x2B);
|
||||
INSERT_PADDING_WORDS(0x28);
|
||||
|
||||
struct {
|
||||
u32 enable;
|
||||
LogicOperation operation;
|
||||
} logic_op;
|
||||
|
||||
INSERT_PADDING_WORDS(0x1);
|
||||
|
||||
union {
|
||||
u32 raw;
|
||||
@@ -830,6 +885,7 @@ public:
|
||||
};
|
||||
|
||||
std::array<ShaderStageInfo, Regs::MaxShaderStage> shader_stages;
|
||||
u32 current_instance = 0; ///< Current instance to be used to simulate instanced rendering.
|
||||
};
|
||||
|
||||
State state{};
|
||||
@@ -903,6 +959,10 @@ ASSERT_REG_POSITION(viewport, 0x300);
|
||||
ASSERT_REG_POSITION(vertex_buffer, 0x35D);
|
||||
ASSERT_REG_POSITION(clear_color[0], 0x360);
|
||||
ASSERT_REG_POSITION(clear_depth, 0x364);
|
||||
ASSERT_REG_POSITION(clear_stencil, 0x368);
|
||||
ASSERT_REG_POSITION(stencil_back_func_ref, 0x3D5);
|
||||
ASSERT_REG_POSITION(stencil_back_mask, 0x3D6);
|
||||
ASSERT_REG_POSITION(stencil_back_func_mask, 0x3D7);
|
||||
ASSERT_REG_POSITION(zeta, 0x3F8);
|
||||
ASSERT_REG_POSITION(vertex_attrib_format[0], 0x458);
|
||||
ASSERT_REG_POSITION(rt_control, 0x487);
|
||||
@@ -914,18 +974,31 @@ ASSERT_REG_POSITION(depth_write_enabled, 0x4BA);
|
||||
ASSERT_REG_POSITION(d3d_cull_mode, 0x4C2);
|
||||
ASSERT_REG_POSITION(depth_test_func, 0x4C3);
|
||||
ASSERT_REG_POSITION(blend, 0x4CF);
|
||||
ASSERT_REG_POSITION(stencil, 0x4E0);
|
||||
ASSERT_REG_POSITION(stencil_enable, 0x4E0);
|
||||
ASSERT_REG_POSITION(stencil_front_op_fail, 0x4E1);
|
||||
ASSERT_REG_POSITION(stencil_front_op_zfail, 0x4E2);
|
||||
ASSERT_REG_POSITION(stencil_front_op_zpass, 0x4E3);
|
||||
ASSERT_REG_POSITION(stencil_front_func_func, 0x4E4);
|
||||
ASSERT_REG_POSITION(stencil_front_func_ref, 0x4E5);
|
||||
ASSERT_REG_POSITION(stencil_front_func_mask, 0x4E6);
|
||||
ASSERT_REG_POSITION(stencil_front_mask, 0x4E7);
|
||||
ASSERT_REG_POSITION(screen_y_control, 0x4EB);
|
||||
ASSERT_REG_POSITION(vb_element_base, 0x50D);
|
||||
ASSERT_REG_POSITION(zeta_enable, 0x54E);
|
||||
ASSERT_REG_POSITION(tsc, 0x557);
|
||||
ASSERT_REG_POSITION(tic, 0x55D);
|
||||
ASSERT_REG_POSITION(stencil_two_side, 0x565);
|
||||
ASSERT_REG_POSITION(stencil_two_side_enable, 0x565);
|
||||
ASSERT_REG_POSITION(stencil_back_op_fail, 0x566);
|
||||
ASSERT_REG_POSITION(stencil_back_op_zfail, 0x567);
|
||||
ASSERT_REG_POSITION(stencil_back_op_zpass, 0x568);
|
||||
ASSERT_REG_POSITION(stencil_back_func_func, 0x569);
|
||||
ASSERT_REG_POSITION(point_coord_replace, 0x581);
|
||||
ASSERT_REG_POSITION(code_address, 0x582);
|
||||
ASSERT_REG_POSITION(draw, 0x585);
|
||||
ASSERT_REG_POSITION(index_array, 0x5F2);
|
||||
ASSERT_REG_POSITION(instanced_arrays, 0x620);
|
||||
ASSERT_REG_POSITION(cull, 0x646);
|
||||
ASSERT_REG_POSITION(logic_op, 0x671);
|
||||
ASSERT_REG_POSITION(clear_buffers, 0x674);
|
||||
ASSERT_REG_POSITION(query, 0x6C0);
|
||||
ASSERT_REG_POSITION(vertex_array[0], 0x700);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/bit_field.h"
|
||||
#include "common/common_types.h"
|
||||
|
||||
@@ -79,6 +80,9 @@ union Attribute {
|
||||
// shader, and a tuple of (TessCoord.x, TessCoord.y, TessCoord.z, ~) when inside a Tess Eval
|
||||
// shader.
|
||||
TessCoordInstanceIDVertexID = 47,
|
||||
// This attribute contains a tuple of (Unk, Unk, Unk, gl_FrontFacing) when inside a fragment
|
||||
// shader. It is unknown what the other values contain.
|
||||
FrontFacing = 63,
|
||||
};
|
||||
|
||||
union {
|
||||
@@ -141,6 +145,7 @@ enum class PredCondition : u64 {
|
||||
NotEqual = 5,
|
||||
GreaterEqual = 6,
|
||||
LessThanWithNan = 9,
|
||||
GreaterThanWithNan = 12,
|
||||
NotEqualWithNan = 13,
|
||||
// TODO(Subv): Other condition types
|
||||
};
|
||||
@@ -213,6 +218,18 @@ enum class FlowCondition : u64 {
|
||||
Fcsm_Tr = 0x1C, // TODO(bunnei): What is this used for?
|
||||
};
|
||||
|
||||
enum class PredicateResultMode : u64 {
|
||||
None = 0x0,
|
||||
NotZero = 0x3,
|
||||
};
|
||||
|
||||
enum class TextureType : u64 {
|
||||
Texture1D = 0,
|
||||
Texture2D = 1,
|
||||
Texture3D = 2,
|
||||
TextureCube = 3,
|
||||
};
|
||||
|
||||
union Instruction {
|
||||
Instruction& operator=(const Instruction& instr) {
|
||||
value = instr.value;
|
||||
@@ -253,7 +270,7 @@ union Instruction {
|
||||
BitField<39, 1, u64> invert_a;
|
||||
BitField<40, 1, u64> invert_b;
|
||||
BitField<41, 2, LogicOperation> operation;
|
||||
BitField<44, 2, u64> unk44;
|
||||
BitField<44, 2, PredicateResultMode> pred_result_mode;
|
||||
BitField<48, 3, Pred> pred48;
|
||||
} lop;
|
||||
|
||||
@@ -263,6 +280,19 @@ union Instruction {
|
||||
BitField<56, 1, u64> invert_b;
|
||||
} lop32i;
|
||||
|
||||
union {
|
||||
BitField<28, 8, u64> imm_lut28;
|
||||
BitField<48, 8, u64> imm_lut48;
|
||||
|
||||
u32 GetImmLut28() const {
|
||||
return static_cast<u32>(imm_lut28);
|
||||
}
|
||||
|
||||
u32 GetImmLut48() const {
|
||||
return static_cast<u32>(imm_lut48);
|
||||
}
|
||||
} lop3;
|
||||
|
||||
u32 GetImm20_19() const {
|
||||
u32 imm{static_cast<u32>(imm20_19)};
|
||||
imm <<= 12;
|
||||
@@ -282,6 +312,10 @@ union Instruction {
|
||||
}
|
||||
} alu;
|
||||
|
||||
union {
|
||||
BitField<48, 1, u64> negate_b;
|
||||
} fmul;
|
||||
|
||||
union {
|
||||
BitField<48, 1, u64> is_signed;
|
||||
} shift;
|
||||
@@ -420,6 +454,8 @@ union Instruction {
|
||||
} conversion;
|
||||
|
||||
union {
|
||||
BitField<28, 1, u64> array;
|
||||
BitField<29, 2, TextureType> texture_type;
|
||||
BitField<31, 4, u64> component_mask;
|
||||
|
||||
bool IsComponentEnabled(size_t component) const {
|
||||
@@ -428,28 +464,91 @@ union Instruction {
|
||||
} tex;
|
||||
|
||||
union {
|
||||
BitField<50, 3, u64> component_mask_selector;
|
||||
BitField<28, 1, u64> array;
|
||||
BitField<29, 2, TextureType> texture_type;
|
||||
BitField<56, 2, u64> component;
|
||||
} tld4;
|
||||
|
||||
union {
|
||||
BitField<52, 2, u64> component;
|
||||
} tld4s;
|
||||
|
||||
union {
|
||||
BitField<0, 8, Register> gpr0;
|
||||
BitField<28, 8, Register> gpr28;
|
||||
BitField<50, 3, u64> component_mask_selector;
|
||||
BitField<53, 4, u64> texture_info;
|
||||
|
||||
TextureType GetTextureType() const {
|
||||
// The TEXS instruction has a weird encoding for the texture type.
|
||||
if (texture_info == 0)
|
||||
return TextureType::Texture1D;
|
||||
if (texture_info >= 1 && texture_info <= 9)
|
||||
return TextureType::Texture2D;
|
||||
if (texture_info >= 10 && texture_info <= 11)
|
||||
return TextureType::Texture3D;
|
||||
if (texture_info >= 12 && texture_info <= 13)
|
||||
return TextureType::TextureCube;
|
||||
|
||||
LOG_CRITICAL(HW_GPU, "Unhandled texture_info: {}",
|
||||
static_cast<u32>(texture_info.Value()));
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
bool IsArrayTexture() const {
|
||||
// TEXS only supports Texture2D arrays.
|
||||
return texture_info >= 7 && texture_info <= 9;
|
||||
}
|
||||
|
||||
bool HasTwoDestinations() const {
|
||||
return gpr28.Value() != Register::ZeroIndex;
|
||||
}
|
||||
|
||||
bool IsComponentEnabled(size_t component) const {
|
||||
static constexpr std::array<std::array<u32, 8>, 4> mask_lut{
|
||||
{{},
|
||||
{0x1, 0x2, 0x4, 0x8, 0x3},
|
||||
{0x1, 0x2, 0x4, 0x8, 0x3, 0x9, 0xa, 0xc},
|
||||
{0x7, 0xb, 0xd, 0xe, 0xf}}};
|
||||
static constexpr std::array<std::array<u32, 8>, 4> mask_lut{{
|
||||
{},
|
||||
{0x1, 0x2, 0x4, 0x8, 0x3, 0x9, 0xa, 0xc},
|
||||
{0x1, 0x2, 0x4, 0x8, 0x3, 0x9, 0xa, 0xc},
|
||||
{0x7, 0xb, 0xd, 0xe, 0xf},
|
||||
}};
|
||||
|
||||
size_t index{gpr0.Value() != Register::ZeroIndex ? 1U : 0U};
|
||||
index |= gpr28.Value() != Register::ZeroIndex ? 2 : 0;
|
||||
|
||||
return ((1ull << component) & mask_lut[index][component_mask_selector]) != 0;
|
||||
u32 mask = mask_lut[index][component_mask_selector];
|
||||
// A mask of 0 means this instruction uses an unimplemented mask.
|
||||
ASSERT(mask != 0);
|
||||
return ((1ull << component) & mask) != 0;
|
||||
}
|
||||
} texs;
|
||||
|
||||
union {
|
||||
BitField<53, 4, u64> texture_info;
|
||||
|
||||
TextureType GetTextureType() const {
|
||||
// The TLDS instruction has a weird encoding for the texture type.
|
||||
if (texture_info >= 0 && texture_info <= 1) {
|
||||
return TextureType::Texture1D;
|
||||
}
|
||||
if (texture_info == 2 || texture_info == 8 || texture_info == 12 ||
|
||||
(texture_info >= 4 && texture_info <= 6)) {
|
||||
return TextureType::Texture2D;
|
||||
}
|
||||
if (texture_info == 7) {
|
||||
return TextureType::Texture3D;
|
||||
}
|
||||
|
||||
LOG_CRITICAL(HW_GPU, "Unhandled texture_info: {}",
|
||||
static_cast<u32>(texture_info.Value()));
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
bool IsArrayTexture() const {
|
||||
// TEXS only supports Texture2D arrays.
|
||||
return texture_info == 8;
|
||||
}
|
||||
} tlds;
|
||||
|
||||
union {
|
||||
BitField<20, 24, u64> target;
|
||||
BitField<5, 1, u64> constant_buffer;
|
||||
@@ -512,10 +611,14 @@ public:
|
||||
LD_A,
|
||||
LD_C,
|
||||
ST_A,
|
||||
LDG, // Load from global memory
|
||||
STG, // Store in global memory
|
||||
TEX,
|
||||
TEXQ, // Texture Query
|
||||
TEXS, // Texture Fetch with scalar/non-vec4 source/destinations
|
||||
TLDS, // Texture Load with scalar/non-vec4 source/destinations
|
||||
TEXQ, // Texture Query
|
||||
TEXS, // Texture Fetch with scalar/non-vec4 source/destinations
|
||||
TLDS, // Texture Load with scalar/non-vec4 source/destinations
|
||||
TLD4, // Texture Load 4
|
||||
TLD4S, // Texture Load 4 with scalar / non - vec4 source / destinations
|
||||
EXIT,
|
||||
IPA,
|
||||
FFMA_IMM, // Fused Multiply and Add
|
||||
@@ -560,6 +663,9 @@ public:
|
||||
LOP_R,
|
||||
LOP_IMM,
|
||||
LOP32I,
|
||||
LOP3_C,
|
||||
LOP3_R,
|
||||
LOP3_IMM,
|
||||
MOV_C,
|
||||
MOV_R,
|
||||
MOV_IMM,
|
||||
@@ -723,10 +829,14 @@ private:
|
||||
INST("1110111111011---", Id::LD_A, Type::Memory, "LD_A"),
|
||||
INST("1110111110010---", Id::LD_C, Type::Memory, "LD_C"),
|
||||
INST("1110111111110---", Id::ST_A, Type::Memory, "ST_A"),
|
||||
INST("1110111011010---", Id::LDG, Type::Memory, "LDG"),
|
||||
INST("1110111011011---", Id::STG, Type::Memory, "STG"),
|
||||
INST("110000----111---", Id::TEX, Type::Memory, "TEX"),
|
||||
INST("1101111101001---", Id::TEXQ, Type::Memory, "TEXQ"),
|
||||
INST("1101100---------", Id::TEXS, Type::Memory, "TEXS"),
|
||||
INST("1101101---------", Id::TLDS, Type::Memory, "TLDS"),
|
||||
INST("110010----111---", Id::TLD4, Type::Memory, "TLD4"),
|
||||
INST("1101111100------", Id::TLD4S, Type::Memory, "TLD4S"),
|
||||
INST("111000110000----", Id::EXIT, Type::Trivial, "EXIT"),
|
||||
INST("11100000--------", Id::IPA, Type::Trivial, "IPA"),
|
||||
INST("0011001-1-------", Id::FFMA_IMM, Type::Ffma, "FFMA_IMM"),
|
||||
@@ -778,6 +888,9 @@ private:
|
||||
INST("0101110001000---", Id::LOP_R, Type::ArithmeticInteger, "LOP_R"),
|
||||
INST("0011100001000---", Id::LOP_IMM, Type::ArithmeticInteger, "LOP_IMM"),
|
||||
INST("000001----------", Id::LOP32I, Type::ArithmeticIntegerImmediate, "LOP32I"),
|
||||
INST("0000001---------", Id::LOP3_C, Type::ArithmeticInteger, "LOP3_C"),
|
||||
INST("0101101111100---", Id::LOP3_R, Type::ArithmeticInteger, "LOP3_R"),
|
||||
INST("0011110---------", Id::LOP3_IMM, Type::ArithmeticInteger, "LOP3_IMM"),
|
||||
INST("0100110001001---", Id::SHL_C, Type::Shift, "SHL_C"),
|
||||
INST("0101110001001---", Id::SHL_R, Type::Shift, "SHL_R"),
|
||||
INST("0011100-01001---", Id::SHL_IMM, Type::Shift, "SHL_IMM"),
|
||||
|
||||
@@ -55,6 +55,7 @@ u32 RenderTargetBytesPerPixel(RenderTargetFormat format) {
|
||||
case RenderTargetFormat::RGBA8_UNORM:
|
||||
case RenderTargetFormat::RGBA8_SNORM:
|
||||
case RenderTargetFormat::RGBA8_SRGB:
|
||||
case RenderTargetFormat::RGBA8_UINT:
|
||||
case RenderTargetFormat::RGB10_A2_UNORM:
|
||||
case RenderTargetFormat::BGRA8_UNORM:
|
||||
case RenderTargetFormat::RG16_UNORM:
|
||||
|
||||
@@ -30,6 +30,7 @@ enum class RenderTargetFormat : u32 {
|
||||
RGBA8_UNORM = 0xD5,
|
||||
RGBA8_SRGB = 0xD6,
|
||||
RGBA8_SNORM = 0xD7,
|
||||
RGBA8_UINT = 0xD9,
|
||||
RG16_UNORM = 0xDA,
|
||||
RG16_SNORM = 0xDB,
|
||||
RG16_SINT = 0xDC,
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
#include "video_core/gpu.h"
|
||||
#include "video_core/memory_manager.h"
|
||||
|
||||
struct ScreenInfo;
|
||||
|
||||
namespace VideoCore {
|
||||
|
||||
class RasterizerInterface {
|
||||
@@ -55,7 +53,7 @@ public:
|
||||
|
||||
/// Attempt to use a faster method to display the framebuffer to screen
|
||||
virtual bool AccelerateDisplay(const Tegra::FramebufferConfig& config, VAddr framebuffer_addr,
|
||||
u32 pixel_stride, ScreenInfo& screen_info) {
|
||||
u32 pixel_stride) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <memory>
|
||||
#include "core/frontend/emu_window.h"
|
||||
#include "core/settings.h"
|
||||
#include "video_core/renderer_base.h"
|
||||
@@ -17,16 +16,9 @@ RendererBase::RendererBase(Core::Frontend::EmuWindow& window) : render_window{wi
|
||||
RendererBase::~RendererBase() = default;
|
||||
|
||||
void RendererBase::RefreshBaseSettings() {
|
||||
RefreshRasterizerSetting();
|
||||
UpdateCurrentFramebufferLayout();
|
||||
|
||||
renderer_settings.use_framelimiter = Settings::values.toggle_framelimit;
|
||||
}
|
||||
|
||||
void RendererBase::RefreshRasterizerSetting() {
|
||||
if (rasterizer == nullptr) {
|
||||
rasterizer = std::make_unique<RasterizerOpenGL>(render_window);
|
||||
}
|
||||
renderer_settings.use_framelimiter = Settings::values.use_frame_limit;
|
||||
}
|
||||
|
||||
void RendererBase::UpdateCurrentFramebufferLayout() {
|
||||
|
||||
@@ -58,9 +58,6 @@ public:
|
||||
void RefreshBaseSettings();
|
||||
|
||||
protected:
|
||||
/// Refreshes settings specific to the rasterizer.
|
||||
void RefreshRasterizerSetting();
|
||||
|
||||
Core::Frontend::EmuWindow& render_window; ///< Reference to the render window handle.
|
||||
std::unique_ptr<RasterizerInterface> rasterizer;
|
||||
f32 m_current_fps = 0.0f; ///< Current framerate, should be set by the renderer
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "common/logging/log.h"
|
||||
#include "common/math_util.h"
|
||||
#include "common/microprofile.h"
|
||||
#include "common/scope_exit.h"
|
||||
#include "core/core.h"
|
||||
#include "core/frontend/emu_window.h"
|
||||
#include "core/hle/kernel/process.h"
|
||||
@@ -25,6 +26,8 @@
|
||||
#include "video_core/renderer_opengl/renderer_opengl.h"
|
||||
#include "video_core/video_core.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
using Maxwell = Tegra::Engines::Maxwell3D::Regs;
|
||||
using PixelFormat = SurfaceParams::PixelFormat;
|
||||
using SurfaceType = SurfaceParams::SurfaceType;
|
||||
@@ -36,8 +39,8 @@ MICROPROFILE_DEFINE(OpenGL_Drawing, "OpenGL", "Drawing", MP_RGB(128, 128, 192));
|
||||
MICROPROFILE_DEFINE(OpenGL_Blits, "OpenGL", "Blits", MP_RGB(100, 100, 255));
|
||||
MICROPROFILE_DEFINE(OpenGL_CacheManagement, "OpenGL", "Cache Mgmt", MP_RGB(100, 255, 100));
|
||||
|
||||
RasterizerOpenGL::RasterizerOpenGL(Core::Frontend::EmuWindow& window)
|
||||
: emu_window{window}, stream_buffer(GL_ARRAY_BUFFER, STREAM_BUFFER_SIZE) {
|
||||
RasterizerOpenGL::RasterizerOpenGL(Core::Frontend::EmuWindow& window, ScreenInfo& info)
|
||||
: emu_window{window}, screen_info{info}, stream_buffer(GL_ARRAY_BUFFER, STREAM_BUFFER_SIZE) {
|
||||
// Create sampler objects
|
||||
for (size_t i = 0; i < texture_samplers.size(); ++i) {
|
||||
texture_samplers[i].Create();
|
||||
@@ -98,7 +101,8 @@ RasterizerOpenGL::~RasterizerOpenGL() {}
|
||||
std::pair<u8*, GLintptr> RasterizerOpenGL::SetupVertexArrays(u8* array_ptr,
|
||||
GLintptr buffer_offset) {
|
||||
MICROPROFILE_SCOPE(OpenGL_VAO);
|
||||
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
|
||||
const auto& gpu = Core::System::GetInstance().GPU().Maxwell3D();
|
||||
const auto& regs = gpu.regs;
|
||||
|
||||
state.draw.vertex_array = hw_vao.handle;
|
||||
state.draw.vertex_buffer = stream_buffer.GetHandle();
|
||||
@@ -110,9 +114,13 @@ std::pair<u8*, GLintptr> RasterizerOpenGL::SetupVertexArrays(u8* array_ptr,
|
||||
if (!vertex_array.IsEnabled())
|
||||
continue;
|
||||
|
||||
const Tegra::GPUVAddr start = vertex_array.StartAddress();
|
||||
Tegra::GPUVAddr start = vertex_array.StartAddress();
|
||||
const Tegra::GPUVAddr end = regs.vertex_array_limit[index].LimitAddress();
|
||||
|
||||
if (regs.instanced_arrays.IsInstancingEnabled(index) && vertex_array.divisor != 0) {
|
||||
start += vertex_array.stride * (gpu.state.current_instance / vertex_array.divisor);
|
||||
}
|
||||
|
||||
ASSERT(end > start);
|
||||
u64 size = end - start + 1;
|
||||
|
||||
@@ -124,7 +132,15 @@ std::pair<u8*, GLintptr> RasterizerOpenGL::SetupVertexArrays(u8* array_ptr,
|
||||
glBindVertexBuffer(index, stream_buffer.GetHandle(), vertex_buffer_offset,
|
||||
vertex_array.stride);
|
||||
|
||||
ASSERT_MSG(vertex_array.divisor == 0, "Vertex buffer divisor unimplemented");
|
||||
if (regs.instanced_arrays.IsInstancingEnabled(index) && vertex_array.divisor != 0) {
|
||||
// Tell OpenGL that this is an instanced vertex buffer to prevent accessing different
|
||||
// indexes on each vertex. We do the instance indexing manually by incrementing the
|
||||
// start address of the vertex buffer.
|
||||
glVertexBindingDivisor(index, 1);
|
||||
} else {
|
||||
// Disable the vertex buffer instancing.
|
||||
glVertexBindingDivisor(index, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Use the vertex array as-is, assumes that the data is formatted correctly for OpenGL.
|
||||
@@ -166,7 +182,7 @@ static GLShader::ProgramCode GetShaderProgramCode(Maxwell::ShaderProgram program
|
||||
auto& gpu = Core::System::GetInstance().GPU().Maxwell3D();
|
||||
|
||||
// Fetch program code from memory
|
||||
GLShader::ProgramCode program_code;
|
||||
GLShader::ProgramCode program_code(GLShader::MAX_PROGRAM_CODE_LENGTH);
|
||||
auto& shader_config = gpu.regs.shader_config[static_cast<size_t>(program)];
|
||||
const u64 gpu_address{gpu.regs.code_address.CodeAddress() + shader_config.offset};
|
||||
const boost::optional<VAddr> cpu_address{gpu.memory_manager.GpuToCpuAddress(gpu_address)};
|
||||
@@ -291,7 +307,8 @@ bool RasterizerOpenGL::AccelerateDrawBatch(bool is_indexed) {
|
||||
}
|
||||
|
||||
std::pair<Surface, Surface> RasterizerOpenGL::ConfigureFramebuffers(bool using_color_fb,
|
||||
bool using_depth_fb) {
|
||||
bool using_depth_fb,
|
||||
bool preserve_contents) {
|
||||
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
|
||||
|
||||
if (regs.rt[0].format == Tegra::RenderTargetFormat::NONE) {
|
||||
@@ -299,22 +316,20 @@ std::pair<Surface, Surface> RasterizerOpenGL::ConfigureFramebuffers(bool using_c
|
||||
using_color_fb = false;
|
||||
}
|
||||
|
||||
// TODO(bunnei): Implement this
|
||||
const bool has_stencil = false;
|
||||
|
||||
const bool has_stencil = regs.stencil_enable;
|
||||
const bool write_color_fb =
|
||||
state.color_mask.red_enabled == GL_TRUE || state.color_mask.green_enabled == GL_TRUE ||
|
||||
state.color_mask.blue_enabled == GL_TRUE || state.color_mask.alpha_enabled == GL_TRUE;
|
||||
|
||||
const bool write_depth_fb =
|
||||
(state.depth.test_enabled && state.depth.write_mask == GL_TRUE) ||
|
||||
(has_stencil && state.stencil.test_enabled && state.stencil.write_mask != 0);
|
||||
(has_stencil && (state.stencil.front.write_mask || state.stencil.back.write_mask));
|
||||
|
||||
Surface color_surface;
|
||||
Surface depth_surface;
|
||||
MathUtil::Rectangle<u32> surfaces_rect;
|
||||
std::tie(color_surface, depth_surface, surfaces_rect) =
|
||||
res_cache.GetFramebufferSurfaces(using_color_fb, using_depth_fb);
|
||||
res_cache.GetFramebufferSurfaces(using_color_fb, using_depth_fb, preserve_contents);
|
||||
|
||||
const MathUtil::Rectangle<s32> viewport_rect{regs.viewport_transform[0].GetRect()};
|
||||
const MathUtil::Rectangle<u32> draw_rect{
|
||||
@@ -348,41 +363,70 @@ std::pair<Surface, Surface> RasterizerOpenGL::ConfigureFramebuffers(bool using_c
|
||||
}
|
||||
|
||||
void RasterizerOpenGL::Clear() {
|
||||
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
|
||||
const auto prev_state{state};
|
||||
SCOPE_EXIT({ prev_state.Apply(); });
|
||||
|
||||
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
|
||||
bool use_color_fb = false;
|
||||
bool use_depth_fb = false;
|
||||
|
||||
GLbitfield clear_mask = 0;
|
||||
if (regs.clear_buffers.R && regs.clear_buffers.G && regs.clear_buffers.B &&
|
||||
OpenGLState clear_state;
|
||||
clear_state.draw.draw_framebuffer = state.draw.draw_framebuffer;
|
||||
clear_state.color_mask.red_enabled = regs.clear_buffers.R ? GL_TRUE : GL_FALSE;
|
||||
clear_state.color_mask.green_enabled = regs.clear_buffers.G ? GL_TRUE : GL_FALSE;
|
||||
clear_state.color_mask.blue_enabled = regs.clear_buffers.B ? GL_TRUE : GL_FALSE;
|
||||
clear_state.color_mask.alpha_enabled = regs.clear_buffers.A ? GL_TRUE : GL_FALSE;
|
||||
|
||||
GLbitfield clear_mask{};
|
||||
if (regs.clear_buffers.R || regs.clear_buffers.G || regs.clear_buffers.B ||
|
||||
regs.clear_buffers.A) {
|
||||
clear_mask |= GL_COLOR_BUFFER_BIT;
|
||||
use_color_fb = true;
|
||||
if (regs.clear_buffers.RT == 0) {
|
||||
// We only support clearing the first color attachment for now
|
||||
clear_mask |= GL_COLOR_BUFFER_BIT;
|
||||
use_color_fb = true;
|
||||
} else {
|
||||
// TODO(subv): Add support for the other color attachments
|
||||
LOG_CRITICAL(HW_GPU, "Clear unimplemented for RT {}", regs.clear_buffers.RT);
|
||||
}
|
||||
}
|
||||
if (regs.clear_buffers.Z) {
|
||||
ASSERT_MSG(regs.zeta_enable != 0, "Tried to clear Z but buffer is not enabled!");
|
||||
use_depth_fb = true;
|
||||
clear_mask |= GL_DEPTH_BUFFER_BIT;
|
||||
use_depth_fb = regs.zeta_enable != 0;
|
||||
|
||||
// Always enable the depth write when clearing the depth buffer. The depth write mask is
|
||||
// ignored when clearing the buffer in the Switch, but OpenGL obeys it so we set it to true.
|
||||
state.depth.test_enabled = true;
|
||||
state.depth.write_mask = GL_TRUE;
|
||||
state.depth.test_func = GL_ALWAYS;
|
||||
state.Apply();
|
||||
clear_state.depth.test_enabled = true;
|
||||
clear_state.depth.test_func = GL_ALWAYS;
|
||||
}
|
||||
if (regs.clear_buffers.S) {
|
||||
ASSERT_MSG(regs.zeta_enable != 0, "Tried to clear stencil but buffer is not enabled!");
|
||||
use_depth_fb = true;
|
||||
clear_mask |= GL_STENCIL_BUFFER_BIT;
|
||||
clear_state.stencil.test_enabled = true;
|
||||
}
|
||||
|
||||
if (clear_mask == 0)
|
||||
if (!use_color_fb && !use_depth_fb) {
|
||||
// No color surface nor depth/stencil surface are enabled
|
||||
return;
|
||||
}
|
||||
|
||||
if (clear_mask == 0) {
|
||||
// No clear mask is enabled
|
||||
return;
|
||||
}
|
||||
|
||||
ScopeAcquireGLContext acquire_context{emu_window};
|
||||
|
||||
auto [dirty_color_surface, dirty_depth_surface] =
|
||||
ConfigureFramebuffers(use_color_fb, use_depth_fb);
|
||||
ConfigureFramebuffers(use_color_fb, use_depth_fb, false);
|
||||
|
||||
clear_state.Apply();
|
||||
|
||||
// TODO(Subv): Support clearing only partial colors.
|
||||
glClearColor(regs.clear_color[0], regs.clear_color[1], regs.clear_color[2],
|
||||
regs.clear_color[3]);
|
||||
glClearDepth(regs.clear_depth);
|
||||
glClearStencil(regs.clear_stencil);
|
||||
|
||||
glClear(clear_mask);
|
||||
|
||||
@@ -432,10 +476,12 @@ void RasterizerOpenGL::DrawArrays() {
|
||||
ScopeAcquireGLContext acquire_context{emu_window};
|
||||
|
||||
auto [dirty_color_surface, dirty_depth_surface] =
|
||||
ConfigureFramebuffers(true, regs.zeta.Address() != 0 && regs.zeta_enable != 0);
|
||||
ConfigureFramebuffers(true, regs.zeta.Address() != 0 && regs.zeta_enable != 0, true);
|
||||
|
||||
SyncDepthTestState();
|
||||
SyncStencilTestState();
|
||||
SyncBlendState();
|
||||
SyncLogicOpState();
|
||||
SyncCullMode();
|
||||
|
||||
// TODO(bunnei): Sync framebuffer_scale uniform here
|
||||
@@ -561,8 +607,7 @@ bool RasterizerOpenGL::AccelerateFill(const void* config) {
|
||||
}
|
||||
|
||||
bool RasterizerOpenGL::AccelerateDisplay(const Tegra::FramebufferConfig& config,
|
||||
VAddr framebuffer_addr, u32 pixel_stride,
|
||||
ScreenInfo& screen_info) {
|
||||
VAddr framebuffer_addr, u32 pixel_stride) {
|
||||
if (!framebuffer_addr) {
|
||||
return {};
|
||||
}
|
||||
@@ -825,6 +870,34 @@ void RasterizerOpenGL::SyncDepthTestState() {
|
||||
state.depth.test_func = MaxwellToGL::ComparisonOp(regs.depth_test_func);
|
||||
}
|
||||
|
||||
void RasterizerOpenGL::SyncStencilTestState() {
|
||||
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
|
||||
state.stencil.test_enabled = regs.stencil_enable != 0;
|
||||
|
||||
if (!regs.stencil_enable) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(bunnei): Verify behavior when this is not set
|
||||
ASSERT(regs.stencil_two_side_enable);
|
||||
|
||||
state.stencil.front.test_func = MaxwellToGL::ComparisonOp(regs.stencil_front_func_func);
|
||||
state.stencil.front.test_ref = regs.stencil_front_func_ref;
|
||||
state.stencil.front.test_mask = regs.stencil_front_func_mask;
|
||||
state.stencil.front.action_stencil_fail = MaxwellToGL::StencilOp(regs.stencil_front_op_fail);
|
||||
state.stencil.front.action_depth_fail = MaxwellToGL::StencilOp(regs.stencil_front_op_zfail);
|
||||
state.stencil.front.action_depth_pass = MaxwellToGL::StencilOp(regs.stencil_front_op_zpass);
|
||||
state.stencil.front.write_mask = regs.stencil_front_mask;
|
||||
|
||||
state.stencil.back.test_func = MaxwellToGL::ComparisonOp(regs.stencil_back_func_func);
|
||||
state.stencil.back.test_ref = regs.stencil_back_func_ref;
|
||||
state.stencil.back.test_mask = regs.stencil_back_func_mask;
|
||||
state.stencil.back.action_stencil_fail = MaxwellToGL::StencilOp(regs.stencil_back_op_fail);
|
||||
state.stencil.back.action_depth_fail = MaxwellToGL::StencilOp(regs.stencil_back_op_zfail);
|
||||
state.stencil.back.action_depth_pass = MaxwellToGL::StencilOp(regs.stencil_back_op_zpass);
|
||||
state.stencil.back.write_mask = regs.stencil_back_mask;
|
||||
}
|
||||
|
||||
void RasterizerOpenGL::SyncBlendState() {
|
||||
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
|
||||
|
||||
@@ -834,6 +907,9 @@ void RasterizerOpenGL::SyncBlendState() {
|
||||
if (!state.blend.enabled)
|
||||
return;
|
||||
|
||||
ASSERT_MSG(regs.logic_op.enable == 0,
|
||||
"Blending and logic op can't be enabled at the same time.");
|
||||
|
||||
ASSERT_MSG(regs.independent_blend_enable == 1, "Only independent blending is implemented");
|
||||
ASSERT_MSG(!regs.independent_blend[0].separate_alpha, "Unimplemented");
|
||||
state.blend.rgb_equation = MaxwellToGL::BlendEquation(regs.independent_blend[0].equation_rgb);
|
||||
@@ -843,3 +919,19 @@ void RasterizerOpenGL::SyncBlendState() {
|
||||
state.blend.src_a_func = MaxwellToGL::BlendFunc(regs.independent_blend[0].factor_source_a);
|
||||
state.blend.dst_a_func = MaxwellToGL::BlendFunc(regs.independent_blend[0].factor_dest_a);
|
||||
}
|
||||
|
||||
void RasterizerOpenGL::SyncLogicOpState() {
|
||||
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
|
||||
|
||||
// TODO(Subv): Support more than just render target 0.
|
||||
state.logic_op.enabled = regs.logic_op.enable != 0;
|
||||
|
||||
if (!state.logic_op.enabled)
|
||||
return;
|
||||
|
||||
ASSERT_MSG(regs.blend.enable == 0, "Blending and logic op can't be enabled at the same time.");
|
||||
|
||||
state.logic_op.operation = MaxwellToGL::LogicOp(regs.logic_op.operation);
|
||||
}
|
||||
|
||||
} // namespace OpenGL
|
||||
|
||||
@@ -22,15 +22,17 @@
|
||||
#include "video_core/renderer_opengl/gl_state.h"
|
||||
#include "video_core/renderer_opengl/gl_stream_buffer.h"
|
||||
|
||||
struct ScreenInfo;
|
||||
|
||||
namespace Core::Frontend {
|
||||
class EmuWindow;
|
||||
}
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
struct ScreenInfo;
|
||||
|
||||
class RasterizerOpenGL : public VideoCore::RasterizerInterface {
|
||||
public:
|
||||
explicit RasterizerOpenGL(Core::Frontend::EmuWindow& renderer);
|
||||
explicit RasterizerOpenGL(Core::Frontend::EmuWindow& renderer, ScreenInfo& info);
|
||||
~RasterizerOpenGL() override;
|
||||
|
||||
void DrawArrays() override;
|
||||
@@ -43,8 +45,8 @@ public:
|
||||
bool AccelerateDisplayTransfer(const void* config) override;
|
||||
bool AccelerateTextureCopy(const void* config) override;
|
||||
bool AccelerateFill(const void* config) override;
|
||||
bool AccelerateDisplay(const Tegra::FramebufferConfig& framebuffer, VAddr framebuffer_addr,
|
||||
u32 pixel_stride, ScreenInfo& screen_info) override;
|
||||
bool AccelerateDisplay(const Tegra::FramebufferConfig& config, VAddr framebuffer_addr,
|
||||
u32 pixel_stride) override;
|
||||
bool AccelerateDrawBatch(bool is_indexed) override;
|
||||
|
||||
/// OpenGL shader generated for a given Maxwell register state
|
||||
@@ -87,7 +89,8 @@ private:
|
||||
|
||||
/// Configures the color and depth framebuffer states and returns the dirty <Color, Depth>
|
||||
/// surfaces if writing was enabled.
|
||||
std::pair<Surface, Surface> ConfigureFramebuffers(bool using_color_fb, bool using_depth_fb);
|
||||
std::pair<Surface, Surface> ConfigureFramebuffers(bool using_color_fb, bool using_depth_fb,
|
||||
bool preserve_contents);
|
||||
|
||||
/// Binds the framebuffer color and depth surface
|
||||
void BindFramebufferSurfaces(const Surface& color_surface, const Surface& depth_surface,
|
||||
@@ -138,9 +141,15 @@ private:
|
||||
/// Syncs the depth test state to match the guest state
|
||||
void SyncDepthTestState();
|
||||
|
||||
/// Syncs the stencil test state to match the guest state
|
||||
void SyncStencilTestState();
|
||||
|
||||
/// Syncs the blend state to match the guest state
|
||||
void SyncBlendState();
|
||||
|
||||
/// Syncs the LogicOp state to match the guest state
|
||||
void SyncLogicOpState();
|
||||
|
||||
bool has_ARB_direct_state_access = false;
|
||||
bool has_ARB_separate_shader_objects = false;
|
||||
bool has_ARB_vertex_attrib_binding = false;
|
||||
@@ -151,6 +160,8 @@ private:
|
||||
|
||||
Core::Frontend::EmuWindow& emu_window;
|
||||
|
||||
ScreenInfo& screen_info;
|
||||
|
||||
std::unique_ptr<GLShader::ProgramManager> shader_program_manager;
|
||||
OGLVertexArray sw_vao;
|
||||
OGLVertexArray hw_vao;
|
||||
@@ -178,3 +189,5 @@ private:
|
||||
enum class AccelDraw { Disabled, Arrays, Indexed };
|
||||
AccelDraw accelerate_draw = AccelDraw::Disabled;
|
||||
};
|
||||
|
||||
} // namespace OpenGL
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include "video_core/textures/decoders.h"
|
||||
#include "video_core/utils.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
using SurfaceType = SurfaceParams::SurfaceType;
|
||||
using PixelFormat = SurfaceParams::PixelFormat;
|
||||
using ComponentType = SurfaceParams::ComponentType;
|
||||
@@ -94,6 +96,7 @@ struct FormatTuple {
|
||||
static constexpr std::array<FormatTuple, SurfaceParams::MaxPixelFormat> tex_format_tuples = {{
|
||||
{GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, ComponentType::UNorm, false}, // ABGR8U
|
||||
{GL_RGBA8, GL_RGBA, GL_BYTE, ComponentType::SNorm, false}, // ABGR8S
|
||||
{GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, ComponentType::UInt, false}, // ABGR8UI
|
||||
{GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV, ComponentType::UNorm, false}, // B5G6R5U
|
||||
{GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, ComponentType::UNorm,
|
||||
false}, // A2B10G10R10U
|
||||
@@ -142,14 +145,16 @@ static constexpr std::array<FormatTuple, SurfaceParams::MaxPixelFormat> tex_form
|
||||
{GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT, ComponentType::UInt, false}, // RG32UI
|
||||
{GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT, ComponentType::UInt, false}, // R32UI
|
||||
|
||||
// Depth formats
|
||||
{GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT, ComponentType::Float, false}, // Z32F
|
||||
{GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, ComponentType::UNorm,
|
||||
false}, // Z16
|
||||
|
||||
// DepthStencil formats
|
||||
{GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, ComponentType::UNorm,
|
||||
false}, // Z24S8
|
||||
{GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, ComponentType::UNorm,
|
||||
false}, // S8Z24
|
||||
{GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT, ComponentType::Float, false}, // Z32F
|
||||
{GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, ComponentType::UNorm,
|
||||
false}, // Z16
|
||||
false}, // S8Z24
|
||||
{GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV,
|
||||
ComponentType::Float, false}, // Z32FS8
|
||||
}};
|
||||
@@ -243,6 +248,7 @@ static constexpr std::array<void (*)(u32, u32, u32, std::vector<u8>&, Tegra::GPU
|
||||
// clang-format off
|
||||
MortonCopy<true, PixelFormat::ABGR8U>,
|
||||
MortonCopy<true, PixelFormat::ABGR8S>,
|
||||
MortonCopy<true, PixelFormat::ABGR8UI>,
|
||||
MortonCopy<true, PixelFormat::B5G6R5U>,
|
||||
MortonCopy<true, PixelFormat::A2B10G10R10U>,
|
||||
MortonCopy<true, PixelFormat::A1B5G5R5U>,
|
||||
@@ -283,10 +289,10 @@ static constexpr std::array<void (*)(u32, u32, u32, std::vector<u8>&, Tegra::GPU
|
||||
MortonCopy<true, PixelFormat::RG8S>,
|
||||
MortonCopy<true, PixelFormat::RG32UI>,
|
||||
MortonCopy<true, PixelFormat::R32UI>,
|
||||
MortonCopy<true, PixelFormat::Z24S8>,
|
||||
MortonCopy<true, PixelFormat::S8Z24>,
|
||||
MortonCopy<true, PixelFormat::Z32F>,
|
||||
MortonCopy<true, PixelFormat::Z16>,
|
||||
MortonCopy<true, PixelFormat::Z24S8>,
|
||||
MortonCopy<true, PixelFormat::S8Z24>,
|
||||
MortonCopy<true, PixelFormat::Z32FS8>,
|
||||
// clang-format on
|
||||
};
|
||||
@@ -297,6 +303,7 @@ static constexpr std::array<void (*)(u32, u32, u32, std::vector<u8>&, Tegra::GPU
|
||||
// clang-format off
|
||||
MortonCopy<false, PixelFormat::ABGR8U>,
|
||||
MortonCopy<false, PixelFormat::ABGR8S>,
|
||||
MortonCopy<false, PixelFormat::ABGR8UI>,
|
||||
MortonCopy<false, PixelFormat::B5G6R5U>,
|
||||
MortonCopy<false, PixelFormat::A2B10G10R10U>,
|
||||
MortonCopy<false, PixelFormat::A1B5G5R5U>,
|
||||
@@ -339,10 +346,10 @@ static constexpr std::array<void (*)(u32, u32, u32, std::vector<u8>&, Tegra::GPU
|
||||
MortonCopy<false, PixelFormat::RG8S>,
|
||||
MortonCopy<false, PixelFormat::RG32UI>,
|
||||
MortonCopy<false, PixelFormat::R32UI>,
|
||||
MortonCopy<false, PixelFormat::Z24S8>,
|
||||
MortonCopy<false, PixelFormat::S8Z24>,
|
||||
MortonCopy<false, PixelFormat::Z32F>,
|
||||
MortonCopy<false, PixelFormat::Z16>,
|
||||
MortonCopy<false, PixelFormat::Z24S8>,
|
||||
MortonCopy<false, PixelFormat::S8Z24>,
|
||||
MortonCopy<false, PixelFormat::Z32FS8>,
|
||||
// clang-format on
|
||||
};
|
||||
@@ -681,7 +688,8 @@ Surface RasterizerCacheOpenGL::GetTextureSurface(const Tegra::Texture::FullTextu
|
||||
}
|
||||
|
||||
SurfaceSurfaceRect_Tuple RasterizerCacheOpenGL::GetFramebufferSurfaces(bool using_color_fb,
|
||||
bool using_depth_fb) {
|
||||
bool using_depth_fb,
|
||||
bool preserve_contents) {
|
||||
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
|
||||
|
||||
// TODO(bunnei): This is hard corded to use just the first render buffer
|
||||
@@ -703,7 +711,7 @@ SurfaceSurfaceRect_Tuple RasterizerCacheOpenGL::GetFramebufferSurfaces(bool usin
|
||||
MathUtil::Rectangle<u32> color_rect{};
|
||||
Surface color_surface;
|
||||
if (using_color_fb) {
|
||||
color_surface = GetSurface(color_params);
|
||||
color_surface = GetSurface(color_params, preserve_contents);
|
||||
if (color_surface) {
|
||||
color_rect = color_surface->GetSurfaceParams().GetRect();
|
||||
}
|
||||
@@ -712,7 +720,7 @@ SurfaceSurfaceRect_Tuple RasterizerCacheOpenGL::GetFramebufferSurfaces(bool usin
|
||||
MathUtil::Rectangle<u32> depth_rect{};
|
||||
Surface depth_surface;
|
||||
if (using_depth_fb) {
|
||||
depth_surface = GetSurface(depth_params);
|
||||
depth_surface = GetSurface(depth_params, preserve_contents);
|
||||
if (depth_surface) {
|
||||
depth_rect = depth_surface->GetSurfaceParams().GetRect();
|
||||
}
|
||||
@@ -747,7 +755,7 @@ void RasterizerCacheOpenGL::FlushSurface(const Surface& surface) {
|
||||
surface->FlushGLBuffer();
|
||||
}
|
||||
|
||||
Surface RasterizerCacheOpenGL::GetSurface(const SurfaceParams& params) {
|
||||
Surface RasterizerCacheOpenGL::GetSurface(const SurfaceParams& params, bool preserve_contents) {
|
||||
if (params.addr == 0 || params.height * params.width == 0) {
|
||||
return {};
|
||||
}
|
||||
@@ -769,16 +777,33 @@ Surface RasterizerCacheOpenGL::GetSurface(const SurfaceParams& params) {
|
||||
} else if (surface->GetSurfaceParams().IsCompatibleSurface(params)) {
|
||||
// Use the cached surface as-is
|
||||
return surface;
|
||||
} else if (preserve_contents) {
|
||||
// If surface parameters changed and we care about keeping the previous data, recreate
|
||||
// the surface from the old one
|
||||
UnregisterSurface(surface);
|
||||
Surface new_surface{RecreateSurface(surface, params)};
|
||||
RegisterSurface(new_surface);
|
||||
return new_surface;
|
||||
} else {
|
||||
// If surface parameters changed, recreate the surface from the old one
|
||||
return RecreateSurface(surface, params);
|
||||
// Delete the old surface before creating a new one to prevent collisions.
|
||||
UnregisterSurface(surface);
|
||||
}
|
||||
}
|
||||
|
||||
// Try to get a previously reserved surface
|
||||
surface = TryGetReservedSurface(params);
|
||||
|
||||
// No surface found - create a new one
|
||||
surface = std::make_shared<CachedSurface>(params);
|
||||
RegisterSurface(surface);
|
||||
LoadSurface(surface);
|
||||
if (!surface) {
|
||||
surface = std::make_shared<CachedSurface>(params);
|
||||
ReserveSurface(surface);
|
||||
RegisterSurface(surface);
|
||||
}
|
||||
|
||||
// Only load surface from memory if we care about the contents
|
||||
if (preserve_contents) {
|
||||
LoadSurface(surface);
|
||||
}
|
||||
|
||||
return surface;
|
||||
}
|
||||
@@ -787,19 +812,76 @@ Surface RasterizerCacheOpenGL::RecreateSurface(const Surface& surface,
|
||||
const SurfaceParams& new_params) {
|
||||
// Verify surface is compatible for blitting
|
||||
const auto& params{surface->GetSurfaceParams()};
|
||||
ASSERT(params.type == new_params.type);
|
||||
ASSERT(params.pixel_format == new_params.pixel_format);
|
||||
ASSERT(params.component_type == new_params.component_type);
|
||||
|
||||
// Create a new surface with the new parameters, and blit the previous surface to it
|
||||
Surface new_surface{std::make_shared<CachedSurface>(new_params)};
|
||||
BlitTextures(surface->Texture().handle, params.GetRect(), new_surface->Texture().handle,
|
||||
new_surface->GetSurfaceParams().GetRect(), params.type, read_framebuffer.handle,
|
||||
draw_framebuffer.handle);
|
||||
|
||||
// Update cache accordingly
|
||||
UnregisterSurface(surface);
|
||||
RegisterSurface(new_surface);
|
||||
// If format is unchanged, we can do a faster blit without reinterpreting pixel data
|
||||
if (params.pixel_format == new_params.pixel_format) {
|
||||
BlitTextures(surface->Texture().handle, params.GetRect(), new_surface->Texture().handle,
|
||||
new_surface->GetSurfaceParams().GetRect(), params.type,
|
||||
read_framebuffer.handle, draw_framebuffer.handle);
|
||||
return new_surface;
|
||||
}
|
||||
|
||||
auto source_format = GetFormatTuple(params.pixel_format, params.component_type);
|
||||
auto dest_format = GetFormatTuple(new_params.pixel_format, new_params.component_type);
|
||||
|
||||
size_t buffer_size = std::max(params.SizeInBytes(), new_params.SizeInBytes());
|
||||
|
||||
// Use a Pixel Buffer Object to download the previous texture and then upload it to the new one
|
||||
// using the new format.
|
||||
OGLBuffer pbo;
|
||||
pbo.Create();
|
||||
|
||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo.handle);
|
||||
glBufferData(GL_PIXEL_PACK_BUFFER, buffer_size, nullptr, GL_STREAM_DRAW_ARB);
|
||||
if (source_format.compressed) {
|
||||
glGetCompressedTextureImage(surface->Texture().handle, 0,
|
||||
static_cast<GLsizei>(params.SizeInBytes()), nullptr);
|
||||
} else {
|
||||
glGetTextureImage(surface->Texture().handle, 0, source_format.format, source_format.type,
|
||||
static_cast<GLsizei>(params.SizeInBytes()), nullptr);
|
||||
}
|
||||
// If the new texture is bigger than the previous one, we need to fill in the rest with data
|
||||
// from the CPU.
|
||||
if (params.SizeInBytes() < new_params.SizeInBytes()) {
|
||||
// Upload the rest of the memory.
|
||||
if (new_params.is_tiled) {
|
||||
// TODO(Subv): We might have to de-tile the subtexture and re-tile it with the rest of
|
||||
// the data in this case. Games like Super Mario Odyssey seem to hit this case when
|
||||
// drawing, it re-uses the memory of a previous texture as a bigger framebuffer but it
|
||||
// doesn't clear it beforehand, the texture is already full of zeros.
|
||||
LOG_CRITICAL(HW_GPU, "Trying to upload extra texture data from the CPU during "
|
||||
"reinterpretation but the texture is tiled.");
|
||||
}
|
||||
size_t remaining_size = new_params.SizeInBytes() - params.SizeInBytes();
|
||||
auto address = Core::System::GetInstance().GPU().memory_manager->GpuToCpuAddress(
|
||||
new_params.addr + params.SizeInBytes());
|
||||
std::vector<u8> data(remaining_size);
|
||||
Memory::ReadBlock(*address, data.data(), data.size());
|
||||
glBufferSubData(GL_PIXEL_PACK_BUFFER, params.SizeInBytes(), remaining_size, data.data());
|
||||
}
|
||||
|
||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||
|
||||
const auto& dest_rect{new_params.GetRect()};
|
||||
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.handle);
|
||||
if (dest_format.compressed) {
|
||||
glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
|
||||
static_cast<GLsizei>(dest_rect.GetWidth()),
|
||||
static_cast<GLsizei>(dest_rect.GetHeight()), dest_format.format,
|
||||
static_cast<GLsizei>(new_params.SizeInBytes()), nullptr);
|
||||
} else {
|
||||
glTextureSubImage2D(new_surface->Texture().handle, 0, 0, 0,
|
||||
static_cast<GLsizei>(dest_rect.GetWidth()),
|
||||
static_cast<GLsizei>(dest_rect.GetHeight()), dest_format.format,
|
||||
dest_format.type, nullptr);
|
||||
}
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
|
||||
pbo.Release();
|
||||
|
||||
return new_surface;
|
||||
}
|
||||
@@ -875,6 +957,21 @@ void RasterizerCacheOpenGL::UnregisterSurface(const Surface& surface) {
|
||||
surface_cache.erase(search);
|
||||
}
|
||||
|
||||
void RasterizerCacheOpenGL::ReserveSurface(const Surface& surface) {
|
||||
const auto& surface_reserve_key{SurfaceReserveKey::Create(surface->GetSurfaceParams())};
|
||||
surface_reserve[surface_reserve_key] = surface;
|
||||
}
|
||||
|
||||
Surface RasterizerCacheOpenGL::TryGetReservedSurface(const SurfaceParams& params) {
|
||||
const auto& surface_reserve_key{SurfaceReserveKey::Create(params)};
|
||||
auto search{surface_reserve.find(surface_reserve_key)};
|
||||
if (search != surface_reserve.end()) {
|
||||
RegisterSurface(search->second);
|
||||
return search->second;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
template <typename Map, typename Interval>
|
||||
constexpr auto RangeFromInterval(Map& map, const Interval& interval) {
|
||||
return boost::make_iterator_range(map.equal_range(interval));
|
||||
@@ -913,3 +1010,5 @@ void RasterizerCacheOpenGL::UpdatePagesCachedCount(Tegra::GPUVAddr addr, u64 siz
|
||||
if (delta < 0)
|
||||
cached_pages.add({pages_interval, delta});
|
||||
}
|
||||
|
||||
} // namespace OpenGL
|
||||
|
||||
@@ -11,11 +11,14 @@
|
||||
#include <boost/icl/interval_map.hpp>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "common/hash.h"
|
||||
#include "common/math_util.h"
|
||||
#include "video_core/engines/maxwell_3d.h"
|
||||
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
||||
#include "video_core/textures/texture.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
class CachedSurface;
|
||||
using Surface = std::shared_ptr<CachedSurface>;
|
||||
using SurfaceSurfaceRect_Tuple = std::tuple<Surface, Surface, MathUtil::Rectangle<u32>>;
|
||||
@@ -25,55 +28,60 @@ struct SurfaceParams {
|
||||
enum class PixelFormat {
|
||||
ABGR8U = 0,
|
||||
ABGR8S = 1,
|
||||
B5G6R5U = 2,
|
||||
A2B10G10R10U = 3,
|
||||
A1B5G5R5U = 4,
|
||||
R8U = 5,
|
||||
R8UI = 6,
|
||||
RGBA16F = 7,
|
||||
RGBA16U = 8,
|
||||
RGBA16UI = 9,
|
||||
R11FG11FB10F = 10,
|
||||
RGBA32UI = 11,
|
||||
DXT1 = 12,
|
||||
DXT23 = 13,
|
||||
DXT45 = 14,
|
||||
DXN1 = 15, // This is also known as BC4
|
||||
DXN2UNORM = 16,
|
||||
DXN2SNORM = 17,
|
||||
BC7U = 18,
|
||||
ASTC_2D_4X4 = 19,
|
||||
G8R8U = 20,
|
||||
G8R8S = 21,
|
||||
BGRA8 = 22,
|
||||
RGBA32F = 23,
|
||||
RG32F = 24,
|
||||
R32F = 25,
|
||||
R16F = 26,
|
||||
R16U = 27,
|
||||
R16S = 28,
|
||||
R16UI = 29,
|
||||
R16I = 30,
|
||||
RG16 = 31,
|
||||
RG16F = 32,
|
||||
RG16UI = 33,
|
||||
RG16I = 34,
|
||||
RG16S = 35,
|
||||
RGB32F = 36,
|
||||
SRGBA8 = 37,
|
||||
RG8U = 38,
|
||||
RG8S = 39,
|
||||
RG32UI = 40,
|
||||
R32UI = 41,
|
||||
ABGR8UI = 2,
|
||||
B5G6R5U = 3,
|
||||
A2B10G10R10U = 4,
|
||||
A1B5G5R5U = 5,
|
||||
R8U = 6,
|
||||
R8UI = 7,
|
||||
RGBA16F = 8,
|
||||
RGBA16U = 9,
|
||||
RGBA16UI = 10,
|
||||
R11FG11FB10F = 11,
|
||||
RGBA32UI = 12,
|
||||
DXT1 = 13,
|
||||
DXT23 = 14,
|
||||
DXT45 = 15,
|
||||
DXN1 = 16, // This is also known as BC4
|
||||
DXN2UNORM = 17,
|
||||
DXN2SNORM = 18,
|
||||
BC7U = 19,
|
||||
ASTC_2D_4X4 = 20,
|
||||
G8R8U = 21,
|
||||
G8R8S = 22,
|
||||
BGRA8 = 23,
|
||||
RGBA32F = 24,
|
||||
RG32F = 25,
|
||||
R32F = 26,
|
||||
R16F = 27,
|
||||
R16U = 28,
|
||||
R16S = 29,
|
||||
R16UI = 30,
|
||||
R16I = 31,
|
||||
RG16 = 32,
|
||||
RG16F = 33,
|
||||
RG16UI = 34,
|
||||
RG16I = 35,
|
||||
RG16S = 36,
|
||||
RGB32F = 37,
|
||||
SRGBA8 = 38,
|
||||
RG8U = 39,
|
||||
RG8S = 40,
|
||||
RG32UI = 41,
|
||||
R32UI = 42,
|
||||
|
||||
MaxColorFormat,
|
||||
|
||||
// Depth formats
|
||||
Z32F = 43,
|
||||
Z16 = 44,
|
||||
|
||||
MaxDepthFormat,
|
||||
|
||||
// DepthStencil formats
|
||||
Z24S8 = 42,
|
||||
S8Z24 = 43,
|
||||
Z32F = 44,
|
||||
Z16 = 45,
|
||||
Z32FS8 = 46,
|
||||
Z24S8 = 45,
|
||||
S8Z24 = 46,
|
||||
Z32FS8 = 47,
|
||||
|
||||
MaxDepthStencilFormat,
|
||||
|
||||
@@ -113,6 +121,7 @@ struct SurfaceParams {
|
||||
constexpr std::array<u32, MaxPixelFormat> compression_factor_table = {{
|
||||
1, // ABGR8U
|
||||
1, // ABGR8S
|
||||
1, // ABGR8UI
|
||||
1, // B5G6R5U
|
||||
1, // A2B10G10R10U
|
||||
1, // A1B5G5R5U
|
||||
@@ -153,10 +162,10 @@ struct SurfaceParams {
|
||||
1, // RG8S
|
||||
1, // RG32UI
|
||||
1, // R32UI
|
||||
1, // Z24S8
|
||||
1, // S8Z24
|
||||
1, // Z32F
|
||||
1, // Z16
|
||||
1, // Z24S8
|
||||
1, // S8Z24
|
||||
1, // Z32FS8
|
||||
}};
|
||||
|
||||
@@ -171,6 +180,7 @@ struct SurfaceParams {
|
||||
constexpr std::array<u32, MaxPixelFormat> bpp_table = {{
|
||||
32, // ABGR8U
|
||||
32, // ABGR8S
|
||||
32, // ABGR8UI
|
||||
16, // B5G6R5U
|
||||
32, // A2B10G10R10U
|
||||
16, // A1B5G5R5U
|
||||
@@ -211,10 +221,10 @@ struct SurfaceParams {
|
||||
16, // RG8S
|
||||
64, // RG32UI
|
||||
32, // R32UI
|
||||
32, // Z24S8
|
||||
32, // S8Z24
|
||||
32, // Z32F
|
||||
16, // Z16
|
||||
32, // Z24S8
|
||||
32, // S8Z24
|
||||
64, // Z32FS8
|
||||
}};
|
||||
|
||||
@@ -253,6 +263,8 @@ struct SurfaceParams {
|
||||
return PixelFormat::ABGR8U;
|
||||
case Tegra::RenderTargetFormat::RGBA8_SNORM:
|
||||
return PixelFormat::ABGR8S;
|
||||
case Tegra::RenderTargetFormat::RGBA8_UINT:
|
||||
return PixelFormat::ABGR8UI;
|
||||
case Tegra::RenderTargetFormat::BGRA8_UNORM:
|
||||
return PixelFormat::BGRA8;
|
||||
case Tegra::RenderTargetFormat::RGB10_A2_UNORM:
|
||||
@@ -323,6 +335,8 @@ struct SurfaceParams {
|
||||
return PixelFormat::ABGR8U;
|
||||
case Tegra::Texture::ComponentType::SNORM:
|
||||
return PixelFormat::ABGR8S;
|
||||
case Tegra::Texture::ComponentType::UINT:
|
||||
return PixelFormat::ABGR8UI;
|
||||
}
|
||||
LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}",
|
||||
static_cast<u32>(component_type));
|
||||
@@ -547,6 +561,7 @@ struct SurfaceParams {
|
||||
case Tegra::RenderTargetFormat::R16_UINT:
|
||||
case Tegra::RenderTargetFormat::RG32_UINT:
|
||||
case Tegra::RenderTargetFormat::R32_UINT:
|
||||
case Tegra::RenderTargetFormat::RGBA8_UINT:
|
||||
return ComponentType::UInt;
|
||||
case Tegra::RenderTargetFormat::RG16_SINT:
|
||||
case Tegra::RenderTargetFormat::R16_SINT:
|
||||
@@ -587,6 +602,10 @@ struct SurfaceParams {
|
||||
return SurfaceType::ColorTexture;
|
||||
}
|
||||
|
||||
if (static_cast<size_t>(pixel_format) < static_cast<size_t>(PixelFormat::MaxDepthFormat)) {
|
||||
return SurfaceType::Depth;
|
||||
}
|
||||
|
||||
if (static_cast<size_t>(pixel_format) <
|
||||
static_cast<size_t>(PixelFormat::MaxDepthStencilFormat)) {
|
||||
return SurfaceType::DepthStencil;
|
||||
@@ -664,6 +683,27 @@ struct SurfaceParams {
|
||||
u32 cache_height;
|
||||
};
|
||||
|
||||
}; // namespace OpenGL
|
||||
|
||||
/// Hashable variation of SurfaceParams, used for a key in the surface cache
|
||||
struct SurfaceReserveKey : Common::HashableStruct<OpenGL::SurfaceParams> {
|
||||
static SurfaceReserveKey Create(const OpenGL::SurfaceParams& params) {
|
||||
SurfaceReserveKey res;
|
||||
res.state = params;
|
||||
return res;
|
||||
}
|
||||
};
|
||||
namespace std {
|
||||
template <>
|
||||
struct hash<SurfaceReserveKey> {
|
||||
size_t operator()(const SurfaceReserveKey& k) const {
|
||||
return k.Hash();
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
class CachedSurface final {
|
||||
public:
|
||||
CachedSurface(const SurfaceParams& params);
|
||||
@@ -706,7 +746,8 @@ public:
|
||||
Surface GetTextureSurface(const Tegra::Texture::FullTextureInfo& config);
|
||||
|
||||
/// Get the color and depth surfaces based on the framebuffer configuration
|
||||
SurfaceSurfaceRect_Tuple GetFramebufferSurfaces(bool using_color_fb, bool using_depth_fb);
|
||||
SurfaceSurfaceRect_Tuple GetFramebufferSurfaces(bool using_color_fb, bool using_depth_fb,
|
||||
bool preserve_contents);
|
||||
|
||||
/// Flushes the surface to Switch memory
|
||||
void FlushSurface(const Surface& surface);
|
||||
@@ -722,7 +763,7 @@ public:
|
||||
|
||||
private:
|
||||
void LoadSurface(const Surface& surface);
|
||||
Surface GetSurface(const SurfaceParams& params);
|
||||
Surface GetSurface(const SurfaceParams& params, bool preserve_contents = true);
|
||||
|
||||
/// Recreates a surface with new parameters
|
||||
Surface RecreateSurface(const Surface& surface, const SurfaceParams& new_params);
|
||||
@@ -733,12 +774,25 @@ private:
|
||||
/// Remove surface from the cache
|
||||
void UnregisterSurface(const Surface& surface);
|
||||
|
||||
/// Reserves a unique surface that can be reused later
|
||||
void ReserveSurface(const Surface& surface);
|
||||
|
||||
/// Tries to get a reserved surface for the specified parameters
|
||||
Surface TryGetReservedSurface(const SurfaceParams& params);
|
||||
|
||||
/// Increase/decrease the number of surface in pages touching the specified region
|
||||
void UpdatePagesCachedCount(Tegra::GPUVAddr addr, u64 size, int delta);
|
||||
|
||||
std::unordered_map<Tegra::GPUVAddr, Surface> surface_cache;
|
||||
PageMap cached_pages;
|
||||
|
||||
/// The surface reserve is a "backup" cache, this is where we put unique surfaces that have
|
||||
/// previously been used. This is to prevent surfaces from being constantly created and
|
||||
/// destroyed when used with different surface parameters.
|
||||
std::unordered_map<SurfaceReserveKey, Surface> surface_reserve;
|
||||
|
||||
OGLFramebuffer read_framebuffer;
|
||||
OGLFramebuffer draw_framebuffer;
|
||||
};
|
||||
|
||||
} // namespace OpenGL
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "video_core/renderer_opengl/gl_shader_util.h"
|
||||
#include "video_core/renderer_opengl/gl_state.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
class OGLTexture : private NonCopyable {
|
||||
public:
|
||||
OGLTexture() = default;
|
||||
@@ -331,3 +333,5 @@ public:
|
||||
|
||||
GLuint handle = 0;
|
||||
};
|
||||
|
||||
} // namespace OpenGL
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "video_core/renderer_opengl/gl_rasterizer.h"
|
||||
#include "video_core/renderer_opengl/gl_shader_decompiler.h"
|
||||
|
||||
namespace GLShader::Decompiler {
|
||||
namespace OpenGL::GLShader::Decompiler {
|
||||
|
||||
using Tegra::Shader::Attribute;
|
||||
using Tegra::Shader::Instruction;
|
||||
@@ -26,6 +26,7 @@ using Tegra::Shader::Sampler;
|
||||
using Tegra::Shader::SubOp;
|
||||
|
||||
constexpr u32 PROGRAM_END = MAX_PROGRAM_CODE_LENGTH;
|
||||
constexpr u32 PROGRAM_HEADER_SIZE = 0x50;
|
||||
|
||||
class DecompileFail : public std::runtime_error {
|
||||
public:
|
||||
@@ -541,7 +542,11 @@ private:
|
||||
// vertex shader, and what's the value of the fourth element when inside a Tess Eval
|
||||
// shader.
|
||||
ASSERT(stage == Maxwell3D::Regs::ShaderStage::Vertex);
|
||||
return "vec4(0, 0, uintBitsToFloat(gl_InstanceID), uintBitsToFloat(gl_VertexID))";
|
||||
return "vec4(0, 0, uintBitsToFloat(instance_id.x), uintBitsToFloat(gl_VertexID))";
|
||||
case Attribute::Index::FrontFacing:
|
||||
// TODO(Subv): Find out what the values are for the other elements.
|
||||
ASSERT(stage == Maxwell3D::Regs::ShaderStage::Fragment);
|
||||
return "vec4(0, 0, 0, uintBitsToFloat(gl_FrontFacing ? 1 : 0))";
|
||||
default:
|
||||
const u32 index{static_cast<u32>(attribute) -
|
||||
static_cast<u32>(Attribute::Index::Attribute_0)};
|
||||
@@ -616,6 +621,23 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
// Shader program header for a Fragment Shader.
|
||||
struct FragmentHeader {
|
||||
INSERT_PADDING_WORDS(5);
|
||||
INSERT_PADDING_WORDS(13);
|
||||
u32 enabled_color_outputs;
|
||||
union {
|
||||
BitField<0, 1, u32> writes_samplemask;
|
||||
BitField<1, 1, u32> writes_depth;
|
||||
};
|
||||
|
||||
bool IsColorComponentOutputEnabled(u32 render_target, u32 component) const {
|
||||
u32 bit = render_target * 4 + component;
|
||||
return enabled_color_outputs & (1 << bit);
|
||||
}
|
||||
};
|
||||
static_assert(sizeof(FragmentHeader) == PROGRAM_HEADER_SIZE, "FragmentHeader size is wrong");
|
||||
|
||||
/// Gets the Subroutine object corresponding to the specified address.
|
||||
const Subroutine& GetSubroutine(u32 begin, u32 end) const {
|
||||
auto iter = subroutines.find(Subroutine{begin, end, suffix});
|
||||
@@ -703,10 +725,11 @@ private:
|
||||
const std::string& op_a, const std::string& op_b) const {
|
||||
using Tegra::Shader::PredCondition;
|
||||
static const std::unordered_map<PredCondition, const char*> PredicateComparisonStrings = {
|
||||
{PredCondition::LessThan, "<"}, {PredCondition::Equal, "=="},
|
||||
{PredCondition::LessEqual, "<="}, {PredCondition::GreaterThan, ">"},
|
||||
{PredCondition::NotEqual, "!="}, {PredCondition::GreaterEqual, ">="},
|
||||
{PredCondition::LessThanWithNan, "<"}, {PredCondition::NotEqualWithNan, "!="},
|
||||
{PredCondition::LessThan, "<"}, {PredCondition::Equal, "=="},
|
||||
{PredCondition::LessEqual, "<="}, {PredCondition::GreaterThan, ">"},
|
||||
{PredCondition::NotEqual, "!="}, {PredCondition::GreaterEqual, ">="},
|
||||
{PredCondition::LessThanWithNan, "<"}, {PredCondition::NotEqualWithNan, "!="},
|
||||
{PredCondition::GreaterThanWithNan, ">"},
|
||||
};
|
||||
|
||||
const auto& comparison{PredicateComparisonStrings.find(condition)};
|
||||
@@ -715,7 +738,8 @@ private:
|
||||
|
||||
std::string predicate{'(' + op_a + ") " + comparison->second + " (" + op_b + ')'};
|
||||
if (condition == PredCondition::LessThanWithNan ||
|
||||
condition == PredCondition::NotEqualWithNan) {
|
||||
condition == PredCondition::NotEqualWithNan ||
|
||||
condition == PredCondition::GreaterThanWithNan) {
|
||||
predicate += " || isnan(" + op_a + ") || isnan(" + op_b + ')';
|
||||
}
|
||||
|
||||
@@ -741,6 +765,30 @@ private:
|
||||
return op->second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the input string GLSL operand into one that applies the abs() function and negates
|
||||
* the output if necessary. When both abs and neg are true, the negation will be applied after
|
||||
* taking the absolute value.
|
||||
* @param operand The input operand to take the abs() of, negate, or both.
|
||||
* @param abs Whether to apply the abs() function to the input operand.
|
||||
* @param neg Whether to negate the input operand.
|
||||
* @returns String corresponding to the operand after being transformed by the abs() and
|
||||
* negation operations.
|
||||
*/
|
||||
static std::string GetOperandAbsNeg(const std::string& operand, bool abs, bool neg) {
|
||||
std::string result = operand;
|
||||
|
||||
if (abs) {
|
||||
result = "abs(" + result + ')';
|
||||
}
|
||||
|
||||
if (neg) {
|
||||
result = "-(" + result + ')';
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns whether the instruction at the specified offset is a 'sched' instruction.
|
||||
* Sched instructions always appear before a sequence of 3 instructions.
|
||||
@@ -754,28 +802,78 @@ private:
|
||||
}
|
||||
|
||||
void WriteLogicOperation(Register dest, LogicOperation logic_op, const std::string& op_a,
|
||||
const std::string& op_b) {
|
||||
const std::string& op_b,
|
||||
Tegra::Shader::PredicateResultMode predicate_mode,
|
||||
Tegra::Shader::Pred predicate) {
|
||||
std::string result{};
|
||||
switch (logic_op) {
|
||||
case LogicOperation::And: {
|
||||
regs.SetRegisterToInteger(dest, true, 0, '(' + op_a + " & " + op_b + ')', 1, 1);
|
||||
result = '(' + op_a + " & " + op_b + ')';
|
||||
break;
|
||||
}
|
||||
case LogicOperation::Or: {
|
||||
regs.SetRegisterToInteger(dest, true, 0, '(' + op_a + " | " + op_b + ')', 1, 1);
|
||||
result = '(' + op_a + " | " + op_b + ')';
|
||||
break;
|
||||
}
|
||||
case LogicOperation::Xor: {
|
||||
regs.SetRegisterToInteger(dest, true, 0, '(' + op_a + " ^ " + op_b + ')', 1, 1);
|
||||
result = '(' + op_a + " ^ " + op_b + ')';
|
||||
break;
|
||||
}
|
||||
case LogicOperation::PassB: {
|
||||
regs.SetRegisterToInteger(dest, true, 0, op_b, 1, 1);
|
||||
result = op_b;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_CRITICAL(HW_GPU, "Unimplemented logic operation: {}", static_cast<u32>(logic_op));
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
if (dest != Tegra::Shader::Register::ZeroIndex) {
|
||||
regs.SetRegisterToInteger(dest, true, 0, result, 1, 1);
|
||||
}
|
||||
|
||||
using Tegra::Shader::PredicateResultMode;
|
||||
// Write the predicate value depending on the predicate mode.
|
||||
switch (predicate_mode) {
|
||||
case PredicateResultMode::None:
|
||||
// Do nothing.
|
||||
return;
|
||||
case PredicateResultMode::NotZero:
|
||||
// Set the predicate to true if the result is not zero.
|
||||
SetPredicate(static_cast<u64>(predicate), '(' + result + ") != 0");
|
||||
break;
|
||||
default:
|
||||
LOG_CRITICAL(HW_GPU, "Unimplemented predicate result mode: {}",
|
||||
static_cast<u32>(predicate_mode));
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
void WriteLop3Instruction(Register dest, const std::string& op_a, const std::string& op_b,
|
||||
const std::string& op_c, const std::string& imm_lut) {
|
||||
if (dest == Tegra::Shader::Register::ZeroIndex) {
|
||||
return;
|
||||
}
|
||||
|
||||
static constexpr std::array<const char*, 32> shift_amounts = {
|
||||
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
|
||||
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21",
|
||||
"22", "23", "24", "25", "26", "27", "28", "29", "30", "31"};
|
||||
|
||||
std::string result;
|
||||
result += '(';
|
||||
|
||||
for (size_t i = 0; i < shift_amounts.size(); ++i) {
|
||||
if (i)
|
||||
result += '|';
|
||||
result += "(((" + imm_lut + " >> (((" + op_c + " >> " + shift_amounts[i] +
|
||||
") & 1) | ((" + op_b + " >> " + shift_amounts[i] + ") & 1) << 1 | ((" + op_a +
|
||||
" >> " + shift_amounts[i] + ") & 1) << 2)) & 1) << " + shift_amounts[i] + ")";
|
||||
}
|
||||
|
||||
result += ')';
|
||||
|
||||
regs.SetRegisterToInteger(dest, true, 0, result, 1, 1);
|
||||
}
|
||||
|
||||
void WriteTexsInstruction(const Instruction& instr, const std::string& coord,
|
||||
@@ -786,33 +884,90 @@ private:
|
||||
++shader.scope;
|
||||
shader.AddLine(coord);
|
||||
|
||||
// TEXS has two destination registers. RG goes into gpr0+0 and gpr0+1, and BA
|
||||
// goes into gpr28+0 and gpr28+1
|
||||
size_t texs_offset{};
|
||||
// TEXS has two destination registers and a swizzle. The first two elements in the swizzle
|
||||
// go into gpr0+0 and gpr0+1, and the rest goes into gpr28+0 and gpr28+1
|
||||
|
||||
size_t src_elem{};
|
||||
for (const auto& dest : {instr.gpr0.Value(), instr.gpr28.Value()}) {
|
||||
size_t dest_elem{};
|
||||
for (unsigned elem = 0; elem < 2; ++elem) {
|
||||
if (!instr.texs.IsComponentEnabled(src_elem++)) {
|
||||
// Skip disabled components
|
||||
continue;
|
||||
}
|
||||
regs.SetRegisterToFloat(dest, elem + texs_offset, texture, 1, 4, false,
|
||||
dest_elem++);
|
||||
size_t written_components = 0;
|
||||
for (u32 component = 0; component < 4; ++component) {
|
||||
if (!instr.texs.IsComponentEnabled(component)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!instr.texs.HasTwoDestinations()) {
|
||||
// Skip the second destination
|
||||
break;
|
||||
if (written_components < 2) {
|
||||
// Write the first two swizzle components to gpr0 and gpr0+1
|
||||
regs.SetRegisterToFloat(instr.gpr0, component, texture, 1, 4, false,
|
||||
written_components % 2);
|
||||
} else {
|
||||
ASSERT(instr.texs.HasTwoDestinations());
|
||||
// Write the rest of the swizzle components to gpr28 and gpr28+1
|
||||
regs.SetRegisterToFloat(instr.gpr28, component, texture, 1, 4, false,
|
||||
written_components % 2);
|
||||
}
|
||||
|
||||
texs_offset += 2;
|
||||
++written_components;
|
||||
}
|
||||
|
||||
--shader.scope;
|
||||
shader.AddLine('}');
|
||||
}
|
||||
|
||||
/*
|
||||
* Emits code to push the input target address to the SSY address stack, incrementing the stack
|
||||
* top.
|
||||
*/
|
||||
void EmitPushToSSYStack(u32 target) {
|
||||
shader.AddLine('{');
|
||||
++shader.scope;
|
||||
shader.AddLine("ssy_stack[ssy_stack_top] = " + std::to_string(target) + "u;");
|
||||
shader.AddLine("ssy_stack_top++;");
|
||||
--shader.scope;
|
||||
shader.AddLine('}');
|
||||
}
|
||||
|
||||
/*
|
||||
* Emits code to pop an address from the SSY address stack, setting the jump address to the
|
||||
* popped address and decrementing the stack top.
|
||||
*/
|
||||
void EmitPopFromSSYStack() {
|
||||
shader.AddLine('{');
|
||||
++shader.scope;
|
||||
shader.AddLine("ssy_stack_top--;");
|
||||
shader.AddLine("jmp_to = ssy_stack[ssy_stack_top];");
|
||||
shader.AddLine("break;");
|
||||
--shader.scope;
|
||||
shader.AddLine('}');
|
||||
}
|
||||
|
||||
/// Writes the output values from a fragment shader to the corresponding GLSL output variables.
|
||||
void EmitFragmentOutputsWrite() {
|
||||
ASSERT(stage == Maxwell3D::Regs::ShaderStage::Fragment);
|
||||
FragmentHeader header;
|
||||
std::memcpy(&header, program_code.data(), PROGRAM_HEADER_SIZE);
|
||||
|
||||
ASSERT_MSG(header.writes_samplemask == 0, "Samplemask write is unimplemented");
|
||||
|
||||
// Write the color outputs using the data in the shader registers, disabled
|
||||
// rendertargets/components are skipped in the register assignment.
|
||||
u32 current_reg = 0;
|
||||
for (u32 render_target = 0; render_target < Maxwell3D::Regs::NumRenderTargets;
|
||||
++render_target) {
|
||||
// TODO(Subv): Figure out how dual-source blending is configured in the Switch.
|
||||
for (u32 component = 0; component < 4; ++component) {
|
||||
if (header.IsColorComponentOutputEnabled(render_target, component)) {
|
||||
shader.AddLine(fmt::format("color[{}][{}] = {};", render_target, component,
|
||||
regs.GetRegisterAsFloat(current_reg)));
|
||||
++current_reg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (header.writes_depth) {
|
||||
// The depth output is always 2 registers after the last color output, and current_reg
|
||||
// already contains one past the last color register.
|
||||
shader.AddLine("gl_FragDepth = " + regs.GetRegisterAsFloat(current_reg + 1) + ';');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles a single instruction from Tegra to GLSL.
|
||||
* @param offset the offset of the Tegra shader instruction.
|
||||
@@ -857,13 +1012,6 @@ private:
|
||||
switch (opcode->GetType()) {
|
||||
case OpCode::Type::Arithmetic: {
|
||||
std::string op_a = regs.GetRegisterAsFloat(instr.gpr8);
|
||||
if (instr.alu.abs_a) {
|
||||
op_a = "abs(" + op_a + ')';
|
||||
}
|
||||
|
||||
if (instr.alu.negate_a) {
|
||||
op_a = "-(" + op_a + ')';
|
||||
}
|
||||
|
||||
std::string op_b;
|
||||
|
||||
@@ -878,17 +1026,10 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
if (instr.alu.abs_b) {
|
||||
op_b = "abs(" + op_b + ')';
|
||||
}
|
||||
|
||||
if (instr.alu.negate_b) {
|
||||
op_b = "-(" + op_b + ')';
|
||||
}
|
||||
|
||||
switch (opcode->GetId()) {
|
||||
case OpCode::Id::MOV_C:
|
||||
case OpCode::Id::MOV_R: {
|
||||
// MOV does not have neither 'abs' nor 'neg' bits.
|
||||
regs.SetRegisterToFloat(instr.gpr0, 0, op_b, 1, 1);
|
||||
break;
|
||||
}
|
||||
@@ -896,6 +1037,8 @@ private:
|
||||
case OpCode::Id::FMUL_C:
|
||||
case OpCode::Id::FMUL_R:
|
||||
case OpCode::Id::FMUL_IMM: {
|
||||
// FMUL does not have 'abs' bits and only the second operand has a 'neg' bit.
|
||||
op_b = GetOperandAbsNeg(op_b, false, instr.fmul.negate_b);
|
||||
regs.SetRegisterToFloat(instr.gpr0, 0, op_a + " * " + op_b, 1, 1,
|
||||
instr.alu.saturate_d);
|
||||
break;
|
||||
@@ -903,11 +1046,14 @@ private:
|
||||
case OpCode::Id::FADD_C:
|
||||
case OpCode::Id::FADD_R:
|
||||
case OpCode::Id::FADD_IMM: {
|
||||
op_a = GetOperandAbsNeg(op_a, instr.alu.abs_a, instr.alu.negate_a);
|
||||
op_b = GetOperandAbsNeg(op_b, instr.alu.abs_b, instr.alu.negate_b);
|
||||
regs.SetRegisterToFloat(instr.gpr0, 0, op_a + " + " + op_b, 1, 1,
|
||||
instr.alu.saturate_d);
|
||||
break;
|
||||
}
|
||||
case OpCode::Id::MUFU: {
|
||||
op_a = GetOperandAbsNeg(op_a, instr.alu.abs_a, instr.alu.negate_a);
|
||||
switch (instr.sub_op) {
|
||||
case SubOp::Cos:
|
||||
regs.SetRegisterToFloat(instr.gpr0, 0, "cos(" + op_a + ')', 1, 1,
|
||||
@@ -947,6 +1093,9 @@ private:
|
||||
case OpCode::Id::FMNMX_C:
|
||||
case OpCode::Id::FMNMX_R:
|
||||
case OpCode::Id::FMNMX_IMM: {
|
||||
op_a = GetOperandAbsNeg(op_a, instr.alu.abs_a, instr.alu.negate_a);
|
||||
op_b = GetOperandAbsNeg(op_b, instr.alu.abs_b, instr.alu.negate_b);
|
||||
|
||||
std::string condition =
|
||||
GetPredicateCondition(instr.alu.fmnmx.pred, instr.alu.fmnmx.negate_pred != 0);
|
||||
std::string parameters = op_a + ',' + op_b;
|
||||
@@ -960,7 +1109,7 @@ private:
|
||||
case OpCode::Id::RRO_R:
|
||||
case OpCode::Id::RRO_IMM: {
|
||||
// Currently RRO is only implemented as a register move.
|
||||
// Usage of `abs_b` and `negate_b` here should also be correct.
|
||||
op_b = GetOperandAbsNeg(op_b, instr.alu.abs_b, instr.alu.negate_b);
|
||||
regs.SetRegisterToFloat(instr.gpr0, 0, op_b, 1, 1);
|
||||
LOG_WARNING(HW_GPU, "RRO instruction is incomplete");
|
||||
break;
|
||||
@@ -1097,7 +1246,9 @@ private:
|
||||
if (instr.alu.lop32i.invert_b)
|
||||
op_b = "~(" + op_b + ')';
|
||||
|
||||
WriteLogicOperation(instr.gpr0, instr.alu.lop32i.operation, op_a, op_b);
|
||||
WriteLogicOperation(instr.gpr0, instr.alu.lop32i.operation, op_a, op_b,
|
||||
Tegra::Shader::PredicateResultMode::None,
|
||||
Tegra::Shader::Pred::UnusedIndex);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@@ -1163,16 +1314,28 @@ private:
|
||||
case OpCode::Id::LOP_C:
|
||||
case OpCode::Id::LOP_R:
|
||||
case OpCode::Id::LOP_IMM: {
|
||||
ASSERT_MSG(!instr.alu.lop.unk44, "Unimplemented");
|
||||
ASSERT_MSG(instr.alu.lop.pred48 == Pred::UnusedIndex, "Unimplemented");
|
||||
|
||||
if (instr.alu.lop.invert_a)
|
||||
op_a = "~(" + op_a + ')';
|
||||
|
||||
if (instr.alu.lop.invert_b)
|
||||
op_b = "~(" + op_b + ')';
|
||||
|
||||
WriteLogicOperation(instr.gpr0, instr.alu.lop.operation, op_a, op_b);
|
||||
WriteLogicOperation(instr.gpr0, instr.alu.lop.operation, op_a, op_b,
|
||||
instr.alu.lop.pred_result_mode, instr.alu.lop.pred48);
|
||||
break;
|
||||
}
|
||||
case OpCode::Id::LOP3_C:
|
||||
case OpCode::Id::LOP3_R:
|
||||
case OpCode::Id::LOP3_IMM: {
|
||||
std::string op_c = regs.GetRegisterAsInteger(instr.gpr39);
|
||||
std::string lut;
|
||||
if (opcode->GetId() == OpCode::Id::LOP3_R) {
|
||||
lut = '(' + std::to_string(instr.alu.lop3.GetImmLut28()) + ')';
|
||||
} else {
|
||||
lut = '(' + std::to_string(instr.alu.lop3.GetImmLut48()) + ')';
|
||||
}
|
||||
|
||||
WriteLop3Instruction(instr.gpr0, op_a, op_b, op_c, lut);
|
||||
break;
|
||||
}
|
||||
case OpCode::Id::IMNMX_C:
|
||||
@@ -1237,8 +1400,6 @@ private:
|
||||
break;
|
||||
}
|
||||
case OpCode::Type::Conversion: {
|
||||
ASSERT_MSG(!instr.conversion.negate_a, "Unimplemented");
|
||||
|
||||
switch (opcode->GetId()) {
|
||||
case OpCode::Id::I2I_R: {
|
||||
ASSERT_MSG(!instr.conversion.selector, "Unimplemented");
|
||||
@@ -1478,6 +1639,57 @@ private:
|
||||
WriteTexsInstruction(instr, coord, texture);
|
||||
break;
|
||||
}
|
||||
case OpCode::Id::TLD4: {
|
||||
ASSERT(instr.tld4.texture_type == Tegra::Shader::TextureType::Texture2D);
|
||||
ASSERT(instr.tld4.array == 0);
|
||||
std::string coord{};
|
||||
|
||||
switch (instr.tld4.texture_type) {
|
||||
case Tegra::Shader::TextureType::Texture2D: {
|
||||
std::string x = regs.GetRegisterAsFloat(instr.gpr8);
|
||||
std::string y = regs.GetRegisterAsFloat(instr.gpr8.Value() + 1);
|
||||
coord = "vec2 coords = vec2(" + x + ", " + y + ");";
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_CRITICAL(HW_GPU, "Unhandled texture type {}",
|
||||
static_cast<u32>(instr.tld4.texture_type.Value()));
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
const std::string sampler = GetSampler(instr.sampler);
|
||||
// Add an extra scope and declare the texture coords inside to prevent
|
||||
// overwriting them in case they are used as outputs of the texs instruction.
|
||||
shader.AddLine("{");
|
||||
++shader.scope;
|
||||
shader.AddLine(coord);
|
||||
const std::string texture = "textureGather(" + sampler + ", coords, " +
|
||||
std::to_string(instr.tld4.component) + ')';
|
||||
|
||||
size_t dest_elem{};
|
||||
for (size_t elem = 0; elem < 4; ++elem) {
|
||||
if (!instr.tex.IsComponentEnabled(elem)) {
|
||||
// Skip disabled components
|
||||
continue;
|
||||
}
|
||||
regs.SetRegisterToFloat(instr.gpr0, elem, texture, 1, 4, false, dest_elem);
|
||||
++dest_elem;
|
||||
}
|
||||
--shader.scope;
|
||||
shader.AddLine("}");
|
||||
break;
|
||||
}
|
||||
case OpCode::Id::TLD4S: {
|
||||
const std::string op_a = regs.GetRegisterAsFloat(instr.gpr8);
|
||||
const std::string op_b = regs.GetRegisterAsFloat(instr.gpr20);
|
||||
// TODO(Subv): Figure out how the sampler type is encoded in the TLD4S instruction.
|
||||
const std::string sampler = GetSampler(instr.sampler);
|
||||
const std::string coord = "vec2 coords = vec2(" + op_a + ", " + op_b + ");";
|
||||
const std::string texture = "textureGather(" + sampler + ", coords, " +
|
||||
std::to_string(instr.tld4s.component) + ')';
|
||||
WriteTexsInstruction(instr, coord, texture);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
LOG_CRITICAL(HW_GPU, "Unhandled memory instruction: {}", opcode->GetName());
|
||||
UNREACHABLE();
|
||||
@@ -1777,12 +1989,8 @@ private:
|
||||
default: {
|
||||
switch (opcode->GetId()) {
|
||||
case OpCode::Id::EXIT: {
|
||||
// Final color output is currently hardcoded to GPR0-3 for fragment shaders
|
||||
if (stage == Maxwell3D::Regs::ShaderStage::Fragment) {
|
||||
shader.AddLine("color.r = " + regs.GetRegisterAsFloat(0) + ';');
|
||||
shader.AddLine("color.g = " + regs.GetRegisterAsFloat(1) + ';');
|
||||
shader.AddLine("color.b = " + regs.GetRegisterAsFloat(2) + ';');
|
||||
shader.AddLine("color.a = " + regs.GetRegisterAsFloat(3) + ';');
|
||||
EmitFragmentOutputsWrite();
|
||||
}
|
||||
|
||||
switch (instr.flow.cond) {
|
||||
@@ -1841,13 +2049,13 @@ private:
|
||||
ASSERT_MSG(instr.bra.constant_buffer == 0, "Constant buffer SSY is not supported");
|
||||
|
||||
u32 target = offset + instr.bra.GetBranchTarget();
|
||||
shader.AddLine("ssy_target = " + std::to_string(target) + "u;");
|
||||
EmitPushToSSYStack(target);
|
||||
break;
|
||||
}
|
||||
case OpCode::Id::SYNC: {
|
||||
// The SYNC opcode jumps to the address previously set by the SSY opcode
|
||||
ASSERT(instr.flow.cond == Tegra::Shader::FlowCondition::Always);
|
||||
shader.AddLine("{ jmp_to = ssy_target; break; }");
|
||||
EmitPopFromSSYStack();
|
||||
break;
|
||||
}
|
||||
case OpCode::Id::DEPBAR: {
|
||||
@@ -1918,7 +2126,13 @@ private:
|
||||
} else {
|
||||
labels.insert(subroutine.begin);
|
||||
shader.AddLine("uint jmp_to = " + std::to_string(subroutine.begin) + "u;");
|
||||
shader.AddLine("uint ssy_target = 0u;");
|
||||
|
||||
// TODO(Subv): Figure out the actual depth of the SSY stack, for now it seems
|
||||
// unlikely that shaders will use 20 nested SSYs.
|
||||
constexpr u32 SSY_STACK_SIZE = 20;
|
||||
shader.AddLine("uint ssy_stack[" + std::to_string(SSY_STACK_SIZE) + "];");
|
||||
shader.AddLine("uint ssy_stack_top = 0u;");
|
||||
|
||||
shader.AddLine("while (true) {");
|
||||
++shader.scope;
|
||||
|
||||
@@ -2003,4 +2217,4 @@ boost::optional<ProgramResult> DecompileProgram(const ProgramCode& program_code,
|
||||
return boost::none;
|
||||
}
|
||||
|
||||
} // namespace GLShader::Decompiler
|
||||
} // namespace OpenGL::GLShader::Decompiler
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "video_core/engines/maxwell_3d.h"
|
||||
#include "video_core/renderer_opengl/gl_shader_gen.h"
|
||||
|
||||
namespace GLShader::Decompiler {
|
||||
namespace OpenGL::GLShader::Decompiler {
|
||||
|
||||
using Tegra::Engines::Maxwell3D;
|
||||
|
||||
@@ -22,4 +22,4 @@ boost::optional<ProgramResult> DecompileProgram(const ProgramCode& program_code,
|
||||
Maxwell3D::Regs::ShaderStage stage,
|
||||
const std::string& suffix);
|
||||
|
||||
} // namespace GLShader::Decompiler
|
||||
} // namespace OpenGL::GLShader::Decompiler
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "video_core/renderer_opengl/gl_shader_decompiler.h"
|
||||
#include "video_core/renderer_opengl/gl_shader_gen.h"
|
||||
|
||||
namespace GLShader {
|
||||
namespace OpenGL::GLShader {
|
||||
|
||||
using Tegra::Engines::Maxwell3D;
|
||||
|
||||
@@ -38,6 +38,7 @@ out vec4 position;
|
||||
|
||||
layout (std140) uniform vs_config {
|
||||
vec4 viewport_flip;
|
||||
uvec4 instance_id;
|
||||
};
|
||||
|
||||
void main() {
|
||||
@@ -86,10 +87,11 @@ ProgramResult GenerateFragmentShader(const ShaderSetup& setup, const MaxwellFSCo
|
||||
.get_value_or({});
|
||||
out += R"(
|
||||
in vec4 position;
|
||||
out vec4 color;
|
||||
layout(location = 0) out vec4 color[8];
|
||||
|
||||
layout (std140) uniform fs_config {
|
||||
vec4 viewport_flip;
|
||||
uvec4 instance_id;
|
||||
};
|
||||
|
||||
void main() {
|
||||
@@ -101,4 +103,4 @@ void main() {
|
||||
return {out, program.second};
|
||||
}
|
||||
|
||||
} // namespace GLShader
|
||||
} // namespace OpenGL::GLShader
|
||||
|
||||
@@ -9,14 +9,14 @@
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include "common/common_types.h"
|
||||
#include "common/hash.h"
|
||||
|
||||
namespace GLShader {
|
||||
namespace OpenGL::GLShader {
|
||||
|
||||
constexpr size_t MAX_PROGRAM_CODE_LENGTH{0x1000};
|
||||
|
||||
using ProgramCode = std::array<u64, MAX_PROGRAM_CODE_LENGTH>;
|
||||
using ProgramCode = std::vector<u64>;
|
||||
|
||||
class ConstBufferEntry {
|
||||
using Maxwell = Tegra::Engines::Maxwell3D::Regs;
|
||||
@@ -115,8 +115,8 @@ struct ShaderEntries {
|
||||
using ProgramResult = std::pair<std::string, ShaderEntries>;
|
||||
|
||||
struct ShaderSetup {
|
||||
ShaderSetup(const ProgramCode& program_code) {
|
||||
program.code = program_code;
|
||||
explicit ShaderSetup(ProgramCode program_code) {
|
||||
program.code = std::move(program_code);
|
||||
}
|
||||
|
||||
struct {
|
||||
@@ -135,8 +135,8 @@ struct ShaderSetup {
|
||||
}
|
||||
|
||||
/// Used in scenarios where we have a dual vertex shaders
|
||||
void SetProgramB(const ProgramCode& program_b) {
|
||||
program.code_b = program_b;
|
||||
void SetProgramB(ProgramCode program_b) {
|
||||
program.code_b = std::move(program_b);
|
||||
has_program_b = true;
|
||||
}
|
||||
|
||||
@@ -146,13 +146,18 @@ struct ShaderSetup {
|
||||
|
||||
private:
|
||||
u64 GetNewHash() const {
|
||||
size_t hash = 0;
|
||||
|
||||
const u64 hash_a = Common::ComputeHash64(program.code.data(), program.code.size());
|
||||
boost::hash_combine(hash, hash_a);
|
||||
|
||||
if (has_program_b) {
|
||||
// Compute hash over dual shader programs
|
||||
return Common::ComputeHash64(&program, sizeof(program));
|
||||
} else {
|
||||
// Compute hash over a single shader program
|
||||
return Common::ComputeHash64(&program.code, program.code.size());
|
||||
const u64 hash_b = Common::ComputeHash64(program.code_b.data(), program.code_b.size());
|
||||
boost::hash_combine(hash, hash_b);
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
u64 program_code_hash{};
|
||||
@@ -191,20 +196,20 @@ ProgramResult GenerateVertexShader(const ShaderSetup& setup, const MaxwellVSConf
|
||||
*/
|
||||
ProgramResult GenerateFragmentShader(const ShaderSetup& setup, const MaxwellFSConfig& config);
|
||||
|
||||
} // namespace GLShader
|
||||
} // namespace OpenGL::GLShader
|
||||
|
||||
namespace std {
|
||||
|
||||
template <>
|
||||
struct hash<GLShader::MaxwellVSConfig> {
|
||||
size_t operator()(const GLShader::MaxwellVSConfig& k) const {
|
||||
struct hash<OpenGL::GLShader::MaxwellVSConfig> {
|
||||
size_t operator()(const OpenGL::GLShader::MaxwellVSConfig& k) const {
|
||||
return k.Hash();
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<GLShader::MaxwellFSConfig> {
|
||||
size_t operator()(const GLShader::MaxwellFSConfig& k) const {
|
||||
struct hash<OpenGL::GLShader::MaxwellFSConfig> {
|
||||
size_t operator()(const OpenGL::GLShader::MaxwellFSConfig& k) const {
|
||||
return k.Hash();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "video_core/engines/maxwell_3d.h"
|
||||
#include "video_core/renderer_opengl/gl_shader_manager.h"
|
||||
|
||||
namespace GLShader {
|
||||
namespace OpenGL::GLShader {
|
||||
|
||||
namespace Impl {
|
||||
static void SetShaderUniformBlockBinding(GLuint shader, const char* name,
|
||||
@@ -37,11 +37,16 @@ void SetShaderUniformBlockBindings(GLuint shader) {
|
||||
} // namespace Impl
|
||||
|
||||
void MaxwellUniformData::SetFromRegs(const Maxwell3D::State::ShaderStageInfo& shader_stage) {
|
||||
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
|
||||
const auto& gpu = Core::System::GetInstance().GPU().Maxwell3D();
|
||||
const auto& regs = gpu.regs;
|
||||
const auto& state = gpu.state;
|
||||
|
||||
// TODO(bunnei): Support more than one viewport
|
||||
viewport_flip[0] = regs.viewport_transform[0].scale_x < 0.0 ? -1.0f : 1.0f;
|
||||
viewport_flip[1] = regs.viewport_transform[0].scale_y < 0.0 ? -1.0f : 1.0f;
|
||||
|
||||
// We only assign the instance to the first component of the vector, the rest is just padding.
|
||||
instance_id[0] = state.current_instance;
|
||||
}
|
||||
|
||||
} // namespace GLShader
|
||||
} // namespace OpenGL::GLShader
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "video_core/renderer_opengl/gl_shader_gen.h"
|
||||
#include "video_core/renderer_opengl/maxwell_to_gl.h"
|
||||
|
||||
namespace GLShader {
|
||||
namespace OpenGL::GLShader {
|
||||
|
||||
/// Number of OpenGL texture samplers that can be used in the fragment shader
|
||||
static constexpr size_t NumTextureSamplers = 32;
|
||||
@@ -24,14 +24,15 @@ void SetShaderUniformBlockBindings(GLuint shader);
|
||||
} // namespace Impl
|
||||
|
||||
/// Uniform structure for the Uniform Buffer Object, all vectors must be 16-byte aligned
|
||||
// NOTE: Always keep a vec4 at the end. The GL spec is not clear wether the alignment at
|
||||
// NOTE: Always keep a vec4 at the end. The GL spec is not clear whether the alignment at
|
||||
// the end of a uniform block is included in UNIFORM_BLOCK_DATA_SIZE or not.
|
||||
// Not following that rule will cause problems on some AMD drivers.
|
||||
struct MaxwellUniformData {
|
||||
void SetFromRegs(const Maxwell3D::State::ShaderStageInfo& shader_stage);
|
||||
alignas(16) GLvec4 viewport_flip;
|
||||
alignas(16) GLuvec4 instance_id;
|
||||
};
|
||||
static_assert(sizeof(MaxwellUniformData) == 16, "MaxwellUniformData structure size is incorrect");
|
||||
static_assert(sizeof(MaxwellUniformData) == 32, "MaxwellUniformData structure size is incorrect");
|
||||
static_assert(sizeof(MaxwellUniformData) < 16384,
|
||||
"MaxwellUniformData structure must be less than 16kb as per the OpenGL spec");
|
||||
|
||||
@@ -170,4 +171,4 @@ private:
|
||||
OGLPipeline pipeline;
|
||||
};
|
||||
|
||||
} // namespace GLShader
|
||||
} // namespace OpenGL::GLShader
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "common/logging/log.h"
|
||||
#include "video_core/renderer_opengl/gl_shader_util.h"
|
||||
|
||||
namespace GLShader {
|
||||
namespace OpenGL::GLShader {
|
||||
|
||||
GLuint LoadShader(const char* source, GLenum type) {
|
||||
const char* debug_type;
|
||||
@@ -47,4 +47,4 @@ GLuint LoadShader(const char* source, GLenum type) {
|
||||
return shader_id;
|
||||
}
|
||||
|
||||
} // namespace GLShader
|
||||
} // namespace OpenGL::GLShader
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "common/assert.h"
|
||||
#include "common/logging/log.h"
|
||||
|
||||
namespace GLShader {
|
||||
namespace OpenGL::GLShader {
|
||||
|
||||
/**
|
||||
* Utility function to log the source code of a list of shaders.
|
||||
@@ -89,4 +89,4 @@ GLuint LoadProgram(bool separable_program, T... shaders) {
|
||||
return program_id;
|
||||
}
|
||||
|
||||
} // namespace GLShader
|
||||
} // namespace OpenGL::GLShader
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include "common/logging/log.h"
|
||||
#include "video_core/renderer_opengl/gl_state.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
OpenGLState OpenGLState::cur_state;
|
||||
|
||||
OpenGLState::OpenGLState() {
|
||||
@@ -25,13 +27,17 @@ OpenGLState::OpenGLState() {
|
||||
color_mask.alpha_enabled = GL_TRUE;
|
||||
|
||||
stencil.test_enabled = false;
|
||||
stencil.test_func = GL_ALWAYS;
|
||||
stencil.test_ref = 0;
|
||||
stencil.test_mask = 0xFF;
|
||||
stencil.write_mask = 0xFF;
|
||||
stencil.action_depth_fail = GL_KEEP;
|
||||
stencil.action_depth_pass = GL_KEEP;
|
||||
stencil.action_stencil_fail = GL_KEEP;
|
||||
auto reset_stencil = [](auto& config) {
|
||||
config.test_func = GL_ALWAYS;
|
||||
config.test_ref = 0;
|
||||
config.test_mask = 0xFFFFFFFF;
|
||||
config.write_mask = 0xFFFFFFFF;
|
||||
config.action_depth_fail = GL_KEEP;
|
||||
config.action_depth_pass = GL_KEEP;
|
||||
config.action_stencil_fail = GL_KEEP;
|
||||
};
|
||||
reset_stencil(stencil.front);
|
||||
reset_stencil(stencil.back);
|
||||
|
||||
blend.enabled = true;
|
||||
blend.rgb_equation = GL_FUNC_ADD;
|
||||
@@ -45,7 +51,8 @@ OpenGLState::OpenGLState() {
|
||||
blend.color.blue = 0.0f;
|
||||
blend.color.alpha = 0.0f;
|
||||
|
||||
logic_op = GL_COPY;
|
||||
logic_op.enabled = false;
|
||||
logic_op.operation = GL_COPY;
|
||||
|
||||
for (auto& texture_unit : texture_units) {
|
||||
texture_unit.Reset();
|
||||
@@ -126,33 +133,31 @@ void OpenGLState::Apply() const {
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
if (stencil.test_func != cur_state.stencil.test_func ||
|
||||
stencil.test_ref != cur_state.stencil.test_ref ||
|
||||
stencil.test_mask != cur_state.stencil.test_mask) {
|
||||
glStencilFunc(stencil.test_func, stencil.test_ref, stencil.test_mask);
|
||||
}
|
||||
|
||||
if (stencil.action_depth_fail != cur_state.stencil.action_depth_fail ||
|
||||
stencil.action_depth_pass != cur_state.stencil.action_depth_pass ||
|
||||
stencil.action_stencil_fail != cur_state.stencil.action_stencil_fail) {
|
||||
glStencilOp(stencil.action_stencil_fail, stencil.action_depth_fail,
|
||||
stencil.action_depth_pass);
|
||||
}
|
||||
|
||||
// Stencil mask
|
||||
if (stencil.write_mask != cur_state.stencil.write_mask) {
|
||||
glStencilMask(stencil.write_mask);
|
||||
}
|
||||
auto config_stencil = [](GLenum face, const auto& config, const auto& prev_config) {
|
||||
if (config.test_func != prev_config.test_func || config.test_ref != prev_config.test_ref ||
|
||||
config.test_mask != prev_config.test_mask) {
|
||||
glStencilFuncSeparate(face, config.test_func, config.test_ref, config.test_mask);
|
||||
}
|
||||
if (config.action_depth_fail != prev_config.action_depth_fail ||
|
||||
config.action_depth_pass != prev_config.action_depth_pass ||
|
||||
config.action_stencil_fail != prev_config.action_stencil_fail) {
|
||||
glStencilOpSeparate(face, config.action_stencil_fail, config.action_depth_fail,
|
||||
config.action_depth_pass);
|
||||
}
|
||||
if (config.write_mask != prev_config.write_mask) {
|
||||
glStencilMaskSeparate(face, config.write_mask);
|
||||
}
|
||||
};
|
||||
config_stencil(GL_FRONT, stencil.front, cur_state.stencil.front);
|
||||
config_stencil(GL_BACK, stencil.back, cur_state.stencil.back);
|
||||
|
||||
// Blending
|
||||
if (blend.enabled != cur_state.blend.enabled) {
|
||||
if (blend.enabled) {
|
||||
ASSERT(!logic_op.enabled);
|
||||
glEnable(GL_BLEND);
|
||||
glDisable(GL_COLOR_LOGIC_OP);
|
||||
} else {
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_COLOR_LOGIC_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,8 +181,18 @@ void OpenGLState::Apply() const {
|
||||
glBlendEquationSeparate(blend.rgb_equation, blend.a_equation);
|
||||
}
|
||||
|
||||
if (logic_op != cur_state.logic_op) {
|
||||
glLogicOp(logic_op);
|
||||
// Logic Operation
|
||||
if (logic_op.enabled != cur_state.logic_op.enabled) {
|
||||
if (logic_op.enabled) {
|
||||
ASSERT(!blend.enabled);
|
||||
glEnable(GL_COLOR_LOGIC_OP);
|
||||
} else {
|
||||
glDisable(GL_COLOR_LOGIC_OP);
|
||||
}
|
||||
}
|
||||
|
||||
if (logic_op.operation != cur_state.logic_op.operation) {
|
||||
glLogicOp(logic_op.operation);
|
||||
}
|
||||
|
||||
// Textures
|
||||
@@ -328,3 +343,5 @@ OpenGLState& OpenGLState::ResetFramebuffer(GLuint handle) {
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
} // namespace OpenGL
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
#include "video_core/engines/maxwell_3d.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
using Regs = Tegra::Engines::Maxwell3D::Regs;
|
||||
|
||||
namespace TextureUnits {
|
||||
@@ -56,14 +58,16 @@ public:
|
||||
} color_mask; // GL_COLOR_WRITEMASK
|
||||
|
||||
struct {
|
||||
bool test_enabled; // GL_STENCIL_TEST
|
||||
GLenum test_func; // GL_STENCIL_FUNC
|
||||
GLint test_ref; // GL_STENCIL_REF
|
||||
GLuint test_mask; // GL_STENCIL_VALUE_MASK
|
||||
GLuint write_mask; // GL_STENCIL_WRITEMASK
|
||||
GLenum action_stencil_fail; // GL_STENCIL_FAIL
|
||||
GLenum action_depth_fail; // GL_STENCIL_PASS_DEPTH_FAIL
|
||||
GLenum action_depth_pass; // GL_STENCIL_PASS_DEPTH_PASS
|
||||
bool test_enabled; // GL_STENCIL_TEST
|
||||
struct {
|
||||
GLenum test_func; // GL_STENCIL_FUNC
|
||||
GLint test_ref; // GL_STENCIL_REF
|
||||
GLuint test_mask; // GL_STENCIL_VALUE_MASK
|
||||
GLuint write_mask; // GL_STENCIL_WRITEMASK
|
||||
GLenum action_stencil_fail; // GL_STENCIL_FAIL
|
||||
GLenum action_depth_fail; // GL_STENCIL_PASS_DEPTH_FAIL
|
||||
GLenum action_depth_pass; // GL_STENCIL_PASS_DEPTH_PASS
|
||||
} front, back;
|
||||
} stencil;
|
||||
|
||||
struct {
|
||||
@@ -83,7 +87,10 @@ public:
|
||||
} color; // GL_BLEND_COLOR
|
||||
} blend;
|
||||
|
||||
GLenum logic_op; // GL_LOGIC_OP_MODE
|
||||
struct {
|
||||
bool enabled; // GL_LOGIC_OP_MODE
|
||||
GLenum operation;
|
||||
} logic_op;
|
||||
|
||||
// 3 texture units - one for each that is used in PICA fragment shader emulation
|
||||
struct TextureUnit {
|
||||
@@ -160,3 +167,5 @@ public:
|
||||
private:
|
||||
static OpenGLState cur_state;
|
||||
};
|
||||
|
||||
} // namespace OpenGL
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "video_core/renderer_opengl/gl_state.h"
|
||||
#include "video_core/renderer_opengl/gl_stream_buffer.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
OGLStreamBuffer::OGLStreamBuffer(GLenum target, GLsizeiptr size, bool prefer_coherent)
|
||||
: gl_target(target), buffer_size(size) {
|
||||
gl_buffer.Create();
|
||||
@@ -97,3 +99,5 @@ void OGLStreamBuffer::Unmap(GLsizeiptr size) {
|
||||
|
||||
buffer_pos += size;
|
||||
}
|
||||
|
||||
} // namespace OpenGL
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tuple>
|
||||
#include <glad/glad.h>
|
||||
#include "common/common_types.h"
|
||||
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
class OGLStreamBuffer : private NonCopyable {
|
||||
public:
|
||||
explicit OGLStreamBuffer(GLenum target, GLsizeiptr size, bool prefer_coherent = false);
|
||||
@@ -40,3 +44,5 @@ private:
|
||||
GLsizeiptr mapped_size = 0;
|
||||
u8* mapped_ptr = nullptr;
|
||||
};
|
||||
|
||||
} // namespace OpenGL
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "common/logging/log.h"
|
||||
#include "video_core/engines/maxwell_3d.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
using GLvec2 = std::array<GLfloat, 2>;
|
||||
using GLvec3 = std::array<GLfloat, 3>;
|
||||
using GLvec4 = std::array<GLfloat, 4>;
|
||||
@@ -107,6 +109,8 @@ inline GLenum PrimitiveTopology(Maxwell::PrimitiveTopology topology) {
|
||||
switch (topology) {
|
||||
case Maxwell::PrimitiveTopology::Points:
|
||||
return GL_POINTS;
|
||||
case Maxwell::PrimitiveTopology::Lines:
|
||||
return GL_LINES;
|
||||
case Maxwell::PrimitiveTopology::LineStrip:
|
||||
return GL_LINE_STRIP;
|
||||
case Maxwell::PrimitiveTopology::Triangles:
|
||||
@@ -147,6 +151,8 @@ inline GLenum WrapMode(Tegra::Texture::WrapMode wrap_mode) {
|
||||
// GL_CLAMP_TO_BORDER to get the border color of the texture, and then sample the edge to
|
||||
// manually mix them. However the shader part of this is not yet implemented.
|
||||
return GL_CLAMP_TO_BORDER;
|
||||
case Tegra::Texture::WrapMode::MirrorOnceClampToEdge:
|
||||
return GL_MIRROR_CLAMP_TO_EDGE;
|
||||
}
|
||||
LOG_CRITICAL(Render_OpenGL, "Unimplemented texture wrap mode={}", static_cast<u32>(wrap_mode));
|
||||
UNREACHABLE();
|
||||
@@ -289,6 +295,30 @@ inline GLenum ComparisonOp(Maxwell::ComparisonOp comparison) {
|
||||
return {};
|
||||
}
|
||||
|
||||
inline GLenum StencilOp(Maxwell::StencilOp stencil) {
|
||||
switch (stencil) {
|
||||
case Maxwell::StencilOp::Keep:
|
||||
return GL_KEEP;
|
||||
case Maxwell::StencilOp::Zero:
|
||||
return GL_ZERO;
|
||||
case Maxwell::StencilOp::Replace:
|
||||
return GL_REPLACE;
|
||||
case Maxwell::StencilOp::Incr:
|
||||
return GL_INCR;
|
||||
case Maxwell::StencilOp::Decr:
|
||||
return GL_DECR;
|
||||
case Maxwell::StencilOp::Invert:
|
||||
return GL_INVERT;
|
||||
case Maxwell::StencilOp::IncrWrap:
|
||||
return GL_INCR_WRAP;
|
||||
case Maxwell::StencilOp::DecrWrap:
|
||||
return GL_DECR_WRAP;
|
||||
}
|
||||
LOG_CRITICAL(Render_OpenGL, "Unimplemented stencil op={}", static_cast<u32>(stencil));
|
||||
UNREACHABLE();
|
||||
return {};
|
||||
}
|
||||
|
||||
inline GLenum FrontFace(Maxwell::Cull::FrontFace front_face) {
|
||||
switch (front_face) {
|
||||
case Maxwell::Cull::FrontFace::ClockWise:
|
||||
@@ -315,4 +345,45 @@ inline GLenum CullFace(Maxwell::Cull::CullFace cull_face) {
|
||||
return {};
|
||||
}
|
||||
|
||||
inline GLenum LogicOp(Maxwell::LogicOperation operation) {
|
||||
switch (operation) {
|
||||
case Maxwell::LogicOperation::Clear:
|
||||
return GL_CLEAR;
|
||||
case Maxwell::LogicOperation::And:
|
||||
return GL_AND;
|
||||
case Maxwell::LogicOperation::AndReverse:
|
||||
return GL_AND_REVERSE;
|
||||
case Maxwell::LogicOperation::Copy:
|
||||
return GL_COPY;
|
||||
case Maxwell::LogicOperation::AndInverted:
|
||||
return GL_AND_INVERTED;
|
||||
case Maxwell::LogicOperation::NoOp:
|
||||
return GL_NOOP;
|
||||
case Maxwell::LogicOperation::Xor:
|
||||
return GL_XOR;
|
||||
case Maxwell::LogicOperation::Or:
|
||||
return GL_OR;
|
||||
case Maxwell::LogicOperation::Nor:
|
||||
return GL_NOR;
|
||||
case Maxwell::LogicOperation::Equiv:
|
||||
return GL_EQUIV;
|
||||
case Maxwell::LogicOperation::Invert:
|
||||
return GL_INVERT;
|
||||
case Maxwell::LogicOperation::OrReverse:
|
||||
return GL_OR_REVERSE;
|
||||
case Maxwell::LogicOperation::CopyInverted:
|
||||
return GL_COPY_INVERTED;
|
||||
case Maxwell::LogicOperation::OrInverted:
|
||||
return GL_OR_INVERTED;
|
||||
case Maxwell::LogicOperation::Nand:
|
||||
return GL_NAND;
|
||||
case Maxwell::LogicOperation::Set:
|
||||
return GL_SET;
|
||||
}
|
||||
LOG_CRITICAL(Render_OpenGL, "Unimplemented logic operation={}", static_cast<u32>(operation));
|
||||
UNREACHABLE();
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace MaxwellToGL
|
||||
} // namespace OpenGL
|
||||
|
||||
@@ -16,9 +16,12 @@
|
||||
#include "core/memory.h"
|
||||
#include "core/settings.h"
|
||||
#include "core/tracer/recorder.h"
|
||||
#include "video_core/renderer_opengl/gl_rasterizer.h"
|
||||
#include "video_core/renderer_opengl/renderer_opengl.h"
|
||||
#include "video_core/utils.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
static const char vertex_shader[] = R"(
|
||||
#version 150 core
|
||||
|
||||
@@ -130,7 +133,7 @@ void RendererOpenGL::SwapBuffers(boost::optional<const Tegra::FramebufferConfig&
|
||||
}
|
||||
|
||||
// Load the framebuffer from memory, draw it to the screen, and swap buffers
|
||||
LoadFBToScreenInfo(*framebuffer, screen_info);
|
||||
LoadFBToScreenInfo(*framebuffer);
|
||||
DrawScreen();
|
||||
render_window.SwapBuffers();
|
||||
}
|
||||
@@ -142,14 +145,12 @@ void RendererOpenGL::SwapBuffers(boost::optional<const Tegra::FramebufferConfig&
|
||||
|
||||
// Restore the rasterizer state
|
||||
prev_state.Apply();
|
||||
RefreshRasterizerSetting();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads framebuffer from emulated memory into the active OpenGL texture.
|
||||
*/
|
||||
void RendererOpenGL::LoadFBToScreenInfo(const Tegra::FramebufferConfig& framebuffer,
|
||||
ScreenInfo& screen_info) {
|
||||
void RendererOpenGL::LoadFBToScreenInfo(const Tegra::FramebufferConfig& framebuffer) {
|
||||
const u32 bytes_per_pixel{Tegra::FramebufferConfig::BytesPerPixel(framebuffer.pixel_format)};
|
||||
const u64 size_in_bytes{framebuffer.stride * framebuffer.height * bytes_per_pixel};
|
||||
const VAddr framebuffer_addr{framebuffer.address + framebuffer.offset};
|
||||
@@ -162,8 +163,7 @@ void RendererOpenGL::LoadFBToScreenInfo(const Tegra::FramebufferConfig& framebuf
|
||||
// only allows rows to have a memory alignement of 4.
|
||||
ASSERT(framebuffer.stride % 4 == 0);
|
||||
|
||||
if (!rasterizer->AccelerateDisplay(framebuffer, framebuffer_addr, framebuffer.stride,
|
||||
screen_info)) {
|
||||
if (!rasterizer->AccelerateDisplay(framebuffer, framebuffer_addr, framebuffer.stride)) {
|
||||
// Reset the screen info's display texture to its own permanent texture
|
||||
screen_info.display_texture = screen_info.texture.resource.handle;
|
||||
|
||||
@@ -276,6 +276,14 @@ void RendererOpenGL::InitOpenGLObjects() {
|
||||
LoadColorToActiveGLTexture(0, 0, 0, 0, screen_info.texture);
|
||||
}
|
||||
|
||||
void RendererOpenGL::CreateRasterizer() {
|
||||
if (rasterizer) {
|
||||
return;
|
||||
}
|
||||
|
||||
rasterizer = std::make_unique<RasterizerOpenGL>(render_window, screen_info);
|
||||
}
|
||||
|
||||
void RendererOpenGL::ConfigureFramebufferTexture(TextureInfo& texture,
|
||||
const Tegra::FramebufferConfig& framebuffer) {
|
||||
|
||||
@@ -425,14 +433,14 @@ static void APIENTRY DebugHandler(GLenum source, GLenum type, GLuint id, GLenum
|
||||
|
||||
switch (severity) {
|
||||
case GL_DEBUG_SEVERITY_HIGH:
|
||||
LOG_ERROR(Render_OpenGL, format, str_source, str_type, id, message);
|
||||
LOG_CRITICAL(Render_OpenGL, format, str_source, str_type, id, message);
|
||||
break;
|
||||
case GL_DEBUG_SEVERITY_MEDIUM:
|
||||
LOG_WARNING(Render_OpenGL, format, str_source, str_type, id, message);
|
||||
break;
|
||||
case GL_DEBUG_SEVERITY_NOTIFICATION:
|
||||
case GL_DEBUG_SEVERITY_LOW:
|
||||
LOG_TRACE(Render_OpenGL, format, str_source, str_type, id, message);
|
||||
LOG_DEBUG(Render_OpenGL, format, str_source, str_type, id, message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -463,11 +471,12 @@ bool RendererOpenGL::Init() {
|
||||
}
|
||||
|
||||
InitOpenGLObjects();
|
||||
|
||||
RefreshRasterizerSetting();
|
||||
CreateRasterizer();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Shutdown the renderer
|
||||
void RendererOpenGL::ShutDown() {}
|
||||
|
||||
} // namespace OpenGL
|
||||
|
||||
@@ -16,6 +16,8 @@ namespace Core::Frontend {
|
||||
class EmuWindow;
|
||||
}
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
/// Structure used for storing information about the textures for the Switch screen
|
||||
struct TextureInfo {
|
||||
OGLTexture resource;
|
||||
@@ -59,6 +61,8 @@ public:
|
||||
|
||||
private:
|
||||
void InitOpenGLObjects();
|
||||
void CreateRasterizer();
|
||||
|
||||
void ConfigureFramebufferTexture(TextureInfo& texture,
|
||||
const Tegra::FramebufferConfig& framebuffer);
|
||||
void DrawScreen();
|
||||
@@ -66,7 +70,7 @@ private:
|
||||
void UpdateFramerate();
|
||||
|
||||
// Loads framebuffer from emulated memory into the display information structure
|
||||
void LoadFBToScreenInfo(const Tegra::FramebufferConfig& framebuffer, ScreenInfo& screen_info);
|
||||
void LoadFBToScreenInfo(const Tegra::FramebufferConfig& framebuffer);
|
||||
// Fills active OpenGL texture with the given RGBA color.
|
||||
void LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, u8 color_a,
|
||||
const TextureInfo& texture);
|
||||
@@ -96,3 +100,5 @@ private:
|
||||
Tegra::FramebufferConfig::TransformFlags framebuffer_transform_flags;
|
||||
MathUtil::Rectangle<int> framebuffer_crop_rect;
|
||||
};
|
||||
|
||||
} // namespace OpenGL
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
namespace VideoCore {
|
||||
|
||||
std::unique_ptr<RendererBase> CreateRenderer(Core::Frontend::EmuWindow& emu_window) {
|
||||
return std::make_unique<RendererOpenGL>(emu_window);
|
||||
return std::make_unique<OpenGL::RendererOpenGL>(emu_window);
|
||||
}
|
||||
|
||||
} // namespace VideoCore
|
||||
|
||||
@@ -83,7 +83,8 @@ void Config::ReadValues() {
|
||||
|
||||
qt_config->beginGroup("Renderer");
|
||||
Settings::values.resolution_factor = qt_config->value("resolution_factor", 1.0).toFloat();
|
||||
Settings::values.toggle_framelimit = qt_config->value("toggle_framelimit", true).toBool();
|
||||
Settings::values.use_frame_limit = qt_config->value("use_frame_limit", true).toBool();
|
||||
Settings::values.frame_limit = qt_config->value("frame_limit", 100).toInt();
|
||||
Settings::values.use_accurate_framebuffers =
|
||||
qt_config->value("use_accurate_framebuffers", false).toBool();
|
||||
|
||||
@@ -124,7 +125,7 @@ void Config::ReadValues() {
|
||||
|
||||
qt_config->beginGroup("UIGameList");
|
||||
UISettings::values.show_unknown = qt_config->value("show_unknown", true).toBool();
|
||||
UISettings::values.icon_size = qt_config->value("icon_size", 48).toUInt();
|
||||
UISettings::values.icon_size = qt_config->value("icon_size", 64).toUInt();
|
||||
UISettings::values.row_1_text_id = qt_config->value("row_1_text_id", 0).toUInt();
|
||||
UISettings::values.row_2_text_id = qt_config->value("row_2_text_id", 3).toUInt();
|
||||
qt_config->endGroup();
|
||||
@@ -203,7 +204,8 @@ void Config::SaveValues() {
|
||||
|
||||
qt_config->beginGroup("Renderer");
|
||||
qt_config->setValue("resolution_factor", (double)Settings::values.resolution_factor);
|
||||
qt_config->setValue("toggle_framelimit", Settings::values.toggle_framelimit);
|
||||
qt_config->setValue("use_frame_limit", Settings::values.use_frame_limit);
|
||||
qt_config->setValue("frame_limit", Settings::values.frame_limit);
|
||||
qt_config->setValue("use_accurate_framebuffers", Settings::values.use_accurate_framebuffers);
|
||||
|
||||
// Cast to double because Qt's written float values are not human-readable
|
||||
|
||||
@@ -12,6 +12,10 @@ ConfigureGraphics::ConfigureGraphics(QWidget* parent)
|
||||
|
||||
ui->setupUi(this);
|
||||
this->setConfiguration();
|
||||
|
||||
ui->frame_limit->setEnabled(Settings::values.use_frame_limit);
|
||||
connect(ui->toggle_frame_limit, &QCheckBox::stateChanged, ui->frame_limit,
|
||||
&QSpinBox::setEnabled);
|
||||
}
|
||||
|
||||
ConfigureGraphics::~ConfigureGraphics() = default;
|
||||
@@ -58,13 +62,15 @@ Resolution FromResolutionFactor(float factor) {
|
||||
void ConfigureGraphics::setConfiguration() {
|
||||
ui->resolution_factor_combobox->setCurrentIndex(
|
||||
static_cast<int>(FromResolutionFactor(Settings::values.resolution_factor)));
|
||||
ui->toggle_framelimit->setChecked(Settings::values.toggle_framelimit);
|
||||
ui->toggle_frame_limit->setChecked(Settings::values.use_frame_limit);
|
||||
ui->frame_limit->setValue(Settings::values.frame_limit);
|
||||
ui->use_accurate_framebuffers->setChecked(Settings::values.use_accurate_framebuffers);
|
||||
}
|
||||
|
||||
void ConfigureGraphics::applyConfiguration() {
|
||||
Settings::values.resolution_factor =
|
||||
ToResolutionFactor(static_cast<Resolution>(ui->resolution_factor_combobox->currentIndex()));
|
||||
Settings::values.toggle_framelimit = ui->toggle_framelimit->isChecked();
|
||||
Settings::values.use_frame_limit = ui->toggle_frame_limit->isChecked();
|
||||
Settings::values.frame_limit = ui->frame_limit->value();
|
||||
Settings::values.use_accurate_framebuffers = ui->use_accurate_framebuffers->isChecked();
|
||||
}
|
||||
|
||||
@@ -23,11 +23,31 @@
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="toggle_framelimit">
|
||||
<property name="text">
|
||||
<string>Limit framerate</string>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="toggle_frame_limit">
|
||||
<property name="text">
|
||||
<string>Limit Speed Percent</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="frame_limit">
|
||||
<property name="suffix">
|
||||
<string>%</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>9999</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>100</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="use_accurate_framebuffers">
|
||||
|
||||
@@ -29,24 +29,6 @@
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_6">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="buttonMiscPlusVerticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="labelPlus">
|
||||
<property name="text">
|
||||
<string>Plus:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonPlus">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<layout class="QVBoxLayout" name="buttonMiscMinusVerticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="labelMinus">
|
||||
@@ -64,6 +46,24 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<layout class="QVBoxLayout" name="buttonMiscPlusVerticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="labelPlus">
|
||||
<property name="text">
|
||||
<string>Plus:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonPlus">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<layout class="QVBoxLayout" name="buttonMiscHomeVerticalLayout">
|
||||
<item>
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "common/string_util.h"
|
||||
#include "core/file_sys/content_archive.h"
|
||||
#include "core/file_sys/control_metadata.h"
|
||||
#include "core/file_sys/registered_cache.h"
|
||||
#include "core/file_sys/romfs.h"
|
||||
#include "core/file_sys/vfs_real.h"
|
||||
#include "core/loader/loader.h"
|
||||
@@ -326,7 +327,7 @@ void GameList::PopupContextMenu(const QPoint& menu_location) {
|
||||
QAction* open_save_location = context_menu.addAction(tr("Open Save Data Location"));
|
||||
open_save_location->setEnabled(program_id != 0);
|
||||
connect(open_save_location, &QAction::triggered,
|
||||
[&]() { emit OpenSaveFolderRequested(program_id); });
|
||||
[&]() { emit OpenFolderRequested(program_id, GameListOpenTarget::SaveData); });
|
||||
context_menu.exec(tree_view->viewport()->mapToGlobal(menu_location));
|
||||
}
|
||||
|
||||
@@ -438,7 +439,7 @@ void GameListWorker::AddInstalledTitlesToGameList() {
|
||||
|
||||
std::vector<u8> icon;
|
||||
std::string name;
|
||||
u64 program_id;
|
||||
u64 program_id = 0;
|
||||
loader->ReadProgramId(program_id);
|
||||
|
||||
const auto& control =
|
||||
@@ -509,7 +510,7 @@ void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsign
|
||||
std::vector<u8> icon;
|
||||
const auto res1 = loader->ReadIcon(icon);
|
||||
|
||||
u64 program_id;
|
||||
u64 program_id = 0;
|
||||
const auto res2 = loader->ReadProgramId(program_id);
|
||||
|
||||
std::string name = " ";
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
|
||||
class GameListWorker;
|
||||
|
||||
enum class GameListOpenTarget { SaveData };
|
||||
|
||||
class GameList : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
@@ -76,7 +78,7 @@ public:
|
||||
signals:
|
||||
void GameChosen(QString game_path);
|
||||
void ShouldCancelWorker();
|
||||
void OpenSaveFolderRequested(u64 program_id);
|
||||
void OpenFolderRequested(u64 program_id, GameListOpenTarget target);
|
||||
|
||||
private slots:
|
||||
void onTextChanged(const QString& newText);
|
||||
@@ -99,3 +101,5 @@ private:
|
||||
GameListWorker* current_worker = nullptr;
|
||||
QFileSystemWatcher* watcher = nullptr;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(GameListOpenTarget);
|
||||
|
||||
@@ -6,12 +6,15 @@
|
||||
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <QImage>
|
||||
#include <QRunnable>
|
||||
#include <QStandardItem>
|
||||
#include <QString>
|
||||
#include "common/string_util.h"
|
||||
#include "core/file_sys/content_archive.h"
|
||||
#include "ui_settings.h"
|
||||
#include "yuzu/util/util.h"
|
||||
|
||||
|
||||
@@ -27,7 +27,10 @@
|
||||
#include "common/string_util.h"
|
||||
#include "core/core.h"
|
||||
#include "core/crypto/key_manager.h"
|
||||
#include "core/file_sys/bis_factory.h"
|
||||
#include "core/file_sys/card_image.h"
|
||||
#include "core/file_sys/registered_cache.h"
|
||||
#include "core/file_sys/savedata_factory.h"
|
||||
#include "core/file_sys/vfs_real.h"
|
||||
#include "core/gdbstub/gdbstub.h"
|
||||
#include "core/loader/loader.h"
|
||||
@@ -213,6 +216,14 @@ void GMainWindow::InitializeRecentFileMenuActions() {
|
||||
|
||||
ui.menu_recent_files->addAction(actions_recent_files[i]);
|
||||
}
|
||||
ui.menu_recent_files->addSeparator();
|
||||
QAction* action_clear_recent_files = new QAction(this);
|
||||
action_clear_recent_files->setText(tr("Clear Recent Files"));
|
||||
connect(action_clear_recent_files, &QAction::triggered, this, [this] {
|
||||
UISettings::values.recent_files.clear();
|
||||
UpdateRecentFiles();
|
||||
});
|
||||
ui.menu_recent_files->addAction(action_clear_recent_files);
|
||||
|
||||
UpdateRecentFiles();
|
||||
}
|
||||
@@ -221,11 +232,16 @@ void GMainWindow::InitializeHotkeys() {
|
||||
hotkey_registry.RegisterHotkey("Main Window", "Load File", QKeySequence::Open);
|
||||
hotkey_registry.RegisterHotkey("Main Window", "Start Emulation");
|
||||
hotkey_registry.RegisterHotkey("Main Window", "Continue/Pause", QKeySequence(Qt::Key_F4));
|
||||
hotkey_registry.RegisterHotkey("Main Window", "Restart", QKeySequence(Qt::Key_F5));
|
||||
hotkey_registry.RegisterHotkey("Main Window", "Fullscreen", QKeySequence::FullScreen);
|
||||
hotkey_registry.RegisterHotkey("Main Window", "Exit Fullscreen", QKeySequence(Qt::Key_Escape),
|
||||
Qt::ApplicationShortcut);
|
||||
hotkey_registry.RegisterHotkey("Main Window", "Toggle Speed Limit", QKeySequence("CTRL+Z"),
|
||||
Qt::ApplicationShortcut);
|
||||
hotkey_registry.RegisterHotkey("Main Window", "Increase Speed Limit", QKeySequence("+"),
|
||||
Qt::ApplicationShortcut);
|
||||
hotkey_registry.RegisterHotkey("Main Window", "Decrease Speed Limit", QKeySequence("-"),
|
||||
Qt::ApplicationShortcut);
|
||||
hotkey_registry.LoadHotkeys();
|
||||
|
||||
connect(hotkey_registry.GetHotkey("Main Window", "Load File", this), &QShortcut::activated,
|
||||
@@ -242,6 +258,12 @@ void GMainWindow::InitializeHotkeys() {
|
||||
}
|
||||
}
|
||||
});
|
||||
connect(hotkey_registry.GetHotkey("Main Window", "Restart", this), &QShortcut::activated, this,
|
||||
[this] {
|
||||
if (!Core::System::GetInstance().IsPoweredOn())
|
||||
return;
|
||||
BootGame(QString(game_path));
|
||||
});
|
||||
connect(hotkey_registry.GetHotkey("Main Window", "Fullscreen", render_window),
|
||||
&QShortcut::activated, ui.action_Fullscreen, &QAction::trigger);
|
||||
connect(hotkey_registry.GetHotkey("Main Window", "Fullscreen", render_window),
|
||||
@@ -255,9 +277,24 @@ void GMainWindow::InitializeHotkeys() {
|
||||
});
|
||||
connect(hotkey_registry.GetHotkey("Main Window", "Toggle Speed Limit", this),
|
||||
&QShortcut::activated, this, [&] {
|
||||
Settings::values.toggle_framelimit = !Settings::values.toggle_framelimit;
|
||||
Settings::values.use_frame_limit = !Settings::values.use_frame_limit;
|
||||
UpdateStatusBar();
|
||||
});
|
||||
constexpr u16 SPEED_LIMIT_STEP = 5;
|
||||
connect(hotkey_registry.GetHotkey("Main Window", "Increase Speed Limit", this),
|
||||
&QShortcut::activated, this, [&] {
|
||||
if (Settings::values.frame_limit < 9999 - SPEED_LIMIT_STEP) {
|
||||
Settings::values.frame_limit += SPEED_LIMIT_STEP;
|
||||
UpdateStatusBar();
|
||||
}
|
||||
});
|
||||
connect(hotkey_registry.GetHotkey("Main Window", "Decrease Speed Limit", this),
|
||||
&QShortcut::activated, this, [&] {
|
||||
if (Settings::values.frame_limit > SPEED_LIMIT_STEP) {
|
||||
Settings::values.frame_limit -= SPEED_LIMIT_STEP;
|
||||
UpdateStatusBar();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void GMainWindow::SetDefaultUIGeometry() {
|
||||
@@ -301,8 +338,7 @@ void GMainWindow::RestoreUIState() {
|
||||
|
||||
void GMainWindow::ConnectWidgetEvents() {
|
||||
connect(game_list, &GameList::GameChosen, this, &GMainWindow::OnGameListLoadFile);
|
||||
connect(game_list, &GameList::OpenSaveFolderRequested, this,
|
||||
&GMainWindow::OnGameListOpenSaveFolder);
|
||||
connect(game_list, &GameList::OpenFolderRequested, this, &GMainWindow::OnGameListOpenFolder);
|
||||
|
||||
connect(this, &GMainWindow::EmulationStarting, render_window,
|
||||
&GRenderWindow::OnEmulationStarting);
|
||||
@@ -326,6 +362,7 @@ void GMainWindow::ConnectMenuEvents() {
|
||||
connect(ui.action_Start, &QAction::triggered, this, &GMainWindow::OnStartGame);
|
||||
connect(ui.action_Pause, &QAction::triggered, this, &GMainWindow::OnPauseGame);
|
||||
connect(ui.action_Stop, &QAction::triggered, this, &GMainWindow::OnStopGame);
|
||||
connect(ui.action_Restart, &QAction::triggered, this, [this] { BootGame(QString(game_path)); });
|
||||
connect(ui.action_Configure, &QAction::triggered, this, &GMainWindow::OnConfigure);
|
||||
|
||||
// View
|
||||
@@ -377,6 +414,8 @@ bool GMainWindow::SupportsRequiredGLExtensions() {
|
||||
unsupported_ext.append("ARB_vertex_attrib_binding");
|
||||
if (!GLAD_GL_ARB_vertex_type_10f_11f_11f_rev)
|
||||
unsupported_ext.append("ARB_vertex_type_10f_11f_11f_rev");
|
||||
if (!GLAD_GL_ARB_texture_mirror_clamp_to_edge)
|
||||
unsupported_ext.append("ARB_texture_mirror_clamp_to_edge");
|
||||
|
||||
// Extensions required to support some texture formats.
|
||||
if (!GLAD_GL_EXT_texture_compression_s3tc)
|
||||
@@ -473,6 +512,8 @@ bool GMainWindow::LoadROM(const QString& filename) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
game_path = filename;
|
||||
|
||||
Core::Telemetry().AddField(Telemetry::FieldType::App, "Frontend", "Qt");
|
||||
return true;
|
||||
}
|
||||
@@ -504,6 +545,15 @@ void GMainWindow::BootGame(const QString& filename) {
|
||||
}
|
||||
status_bar_update_timer.start(2000);
|
||||
|
||||
std::string title_name;
|
||||
const auto res = Core::System::GetInstance().GetGameName(title_name);
|
||||
if (res != Loader::ResultStatus::Success)
|
||||
title_name = FileUtil::GetFilename(filename.toStdString());
|
||||
|
||||
setWindowTitle(QString("yuzu %1| %4 | %2-%3")
|
||||
.arg(Common::g_build_name, Common::g_scm_branch, Common::g_scm_desc,
|
||||
QString::fromStdString(title_name)));
|
||||
|
||||
render_window->show();
|
||||
render_window->setFocus();
|
||||
|
||||
@@ -531,9 +581,12 @@ void GMainWindow::ShutdownGame() {
|
||||
ui.action_Start->setText(tr("Start"));
|
||||
ui.action_Pause->setEnabled(false);
|
||||
ui.action_Stop->setEnabled(false);
|
||||
ui.action_Restart->setEnabled(false);
|
||||
render_window->hide();
|
||||
game_list->show();
|
||||
game_list->setFilterFocus();
|
||||
setWindowTitle(QString("yuzu %1| %2-%3")
|
||||
.arg(Common::g_build_name, Common::g_scm_branch, Common::g_scm_desc));
|
||||
|
||||
// Disable status bar updates
|
||||
status_bar_update_timer.stop();
|
||||
@@ -543,6 +596,8 @@ void GMainWindow::ShutdownGame() {
|
||||
emu_frametime_label->setVisible(false);
|
||||
|
||||
emulation_running = false;
|
||||
|
||||
game_path.clear();
|
||||
}
|
||||
|
||||
void GMainWindow::StoreRecentFile(const QString& filename) {
|
||||
@@ -580,8 +635,37 @@ void GMainWindow::OnGameListLoadFile(QString game_path) {
|
||||
BootGame(game_path);
|
||||
}
|
||||
|
||||
void GMainWindow::OnGameListOpenSaveFolder(u64 program_id) {
|
||||
UNIMPLEMENTED();
|
||||
void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target) {
|
||||
std::string path;
|
||||
std::string open_target;
|
||||
switch (target) {
|
||||
case GameListOpenTarget::SaveData: {
|
||||
open_target = "Save Data";
|
||||
const std::string nand_dir = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
||||
ASSERT(program_id != 0);
|
||||
// TODO(tech4me): Update this to work with arbitrary user profile
|
||||
// Refer to core/hle/service/acc/profile_manager.cpp ProfileManager constructor
|
||||
constexpr u128 user_id = {1, 0};
|
||||
path = nand_dir + FileSys::SaveDataFactory::GetFullPath(FileSys::SaveDataSpaceId::NandUser,
|
||||
FileSys::SaveDataType::SaveData,
|
||||
program_id, user_id, 0);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
UNIMPLEMENTED();
|
||||
}
|
||||
|
||||
const QString qpath = QString::fromStdString(path);
|
||||
|
||||
const QDir dir(qpath);
|
||||
if (!dir.exists()) {
|
||||
QMessageBox::warning(this,
|
||||
tr("Error Opening %1 Folder").arg(QString::fromStdString(open_target)),
|
||||
tr("Folder does not exist!"));
|
||||
return;
|
||||
}
|
||||
LOG_INFO(Frontend, "Opening {} path for program_id={:016x}", open_target, program_id);
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(qpath));
|
||||
}
|
||||
|
||||
void GMainWindow::OnMenuLoadFile() {
|
||||
@@ -807,6 +891,7 @@ void GMainWindow::OnPauseGame() {
|
||||
ui.action_Start->setEnabled(true);
|
||||
ui.action_Pause->setEnabled(false);
|
||||
ui.action_Stop->setEnabled(true);
|
||||
ui.action_Restart->setEnabled(true);
|
||||
}
|
||||
|
||||
void GMainWindow::OnStopGame() {
|
||||
@@ -908,7 +993,13 @@ void GMainWindow::UpdateStatusBar() {
|
||||
|
||||
auto results = Core::System::GetInstance().GetAndResetPerfStats();
|
||||
|
||||
emu_speed_label->setText(tr("Speed: %1%").arg(results.emulation_speed * 100.0, 0, 'f', 0));
|
||||
if (Settings::values.use_frame_limit) {
|
||||
emu_speed_label->setText(tr("Speed: %1% / %2%")
|
||||
.arg(results.emulation_speed * 100.0, 0, 'f', 0)
|
||||
.arg(Settings::values.frame_limit));
|
||||
} else {
|
||||
emu_speed_label->setText(tr("Speed: %1%").arg(results.emulation_speed * 100.0, 0, 'f', 0));
|
||||
}
|
||||
game_fps_label->setText(tr("Game: %1 FPS").arg(results.game_fps, 0, 'f', 0));
|
||||
emu_frametime_label->setText(tr("Frame: %1 ms").arg(results.frametime * 1000.0, 0, 'f', 2));
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ class GRenderWindow;
|
||||
class MicroProfileDialog;
|
||||
class ProfilerWidget;
|
||||
class WaitTreeWidget;
|
||||
enum class GameListOpenTarget;
|
||||
|
||||
namespace Tegra {
|
||||
class DebugContext;
|
||||
@@ -122,7 +123,7 @@ private slots:
|
||||
void OnStopGame();
|
||||
/// Called whenever a user selects a game in the game list widget.
|
||||
void OnGameListLoadFile(QString game_path);
|
||||
void OnGameListOpenSaveFolder(u64 program_id);
|
||||
void OnGameListOpenFolder(u64 program_id, GameListOpenTarget target);
|
||||
void OnMenuLoadFile();
|
||||
void OnMenuLoadFolder();
|
||||
void OnMenuInstallToNAND();
|
||||
@@ -161,6 +162,8 @@ private:
|
||||
// Whether emulation is currently running in yuzu.
|
||||
bool emulation_running = false;
|
||||
std::unique_ptr<EmuThread> emu_thread;
|
||||
// The path to the game currently running
|
||||
QString game_path;
|
||||
|
||||
// FS
|
||||
FileSys::VirtualFilesystem vfs;
|
||||
|
||||
@@ -211,6 +211,14 @@
|
||||
<string>Fullscreen</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_Restart">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Restart</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
</ui>
|
||||
|
||||
@@ -96,8 +96,9 @@ void Config::ReadValues() {
|
||||
// Renderer
|
||||
Settings::values.resolution_factor =
|
||||
(float)sdl2_config->GetReal("Renderer", "resolution_factor", 1.0);
|
||||
Settings::values.toggle_framelimit =
|
||||
sdl2_config->GetBoolean("Renderer", "toggle_framelimit", true);
|
||||
Settings::values.use_frame_limit = sdl2_config->GetBoolean("Renderer", "use_frame_limit", true);
|
||||
Settings::values.frame_limit =
|
||||
static_cast<u16>(sdl2_config->GetInteger("Renderer", "frame_limit", 100));
|
||||
Settings::values.use_accurate_framebuffers =
|
||||
sdl2_config->GetBoolean("Renderer", "use_accurate_framebuffers", false);
|
||||
|
||||
|
||||
@@ -102,6 +102,14 @@ resolution_factor =
|
||||
# 0 (default): Off, 1: On
|
||||
use_vsync =
|
||||
|
||||
# Turns on the frame limiter, which will limit frames output to the target game speed
|
||||
# 0: Off, 1: On (default)
|
||||
use_frame_limit =
|
||||
|
||||
# Limits the speed of the game to run no faster than this value as a percentage of target speed
|
||||
# 1 - 9999: Speed limit as a percentage of target game speed. 100 (default)
|
||||
frame_limit =
|
||||
|
||||
# Whether to use accurate framebuffers
|
||||
# 0 (default): Off (fast), 1 : On (slow)
|
||||
use_accurate_framebuffers =
|
||||
@@ -132,10 +140,6 @@ custom_bottom_top =
|
||||
custom_bottom_right =
|
||||
custom_bottom_bottom =
|
||||
|
||||
# Whether to toggle frame limiter on or off.
|
||||
# 0: Off, 1 (default): On
|
||||
toggle_framelimit =
|
||||
|
||||
# Swaps the prominent screen with the other screen.
|
||||
# For example, if Single Screen is chosen, setting this to 1 will display the bottom screen instead of the top screen.
|
||||
# 0 (default): Top Screen is prominent, 1: Bottom Screen is prominent
|
||||
|
||||
@@ -89,6 +89,8 @@ bool EmuWindow_SDL2::SupportsRequiredGLExtensions() {
|
||||
unsupported_ext.push_back("ARB_vertex_attrib_binding");
|
||||
if (!GLAD_GL_ARB_vertex_type_10f_11f_11f_rev)
|
||||
unsupported_ext.push_back("ARB_vertex_type_10f_11f_11f_rev");
|
||||
if (!GLAD_GL_ARB_texture_mirror_clamp_to_edge)
|
||||
unsupported_ext.push_back("ARB_texture_mirror_clamp_to_edge");
|
||||
|
||||
// Extensions required to support some texture formats.
|
||||
if (!GLAD_GL_EXT_texture_compression_s3tc)
|
||||
|
||||
Reference in New Issue
Block a user