Compare commits
82 Commits
__refs_pul
...
__refs_pul
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3107788e6 | ||
|
|
dd2e96b362 | ||
|
|
a86a88109a | ||
|
|
8d009a7aae | ||
|
|
20521da259 | ||
|
|
dc5eedef71 | ||
|
|
074b38b7a9 | ||
|
|
222f4b45eb | ||
|
|
fd922ddb01 | ||
|
|
7831e86c34 | ||
|
|
a2eccbf075 | ||
|
|
15d177a6ac | ||
|
|
7f6a8a33d4 | ||
|
|
081530686c | ||
|
|
d1713ad451 | ||
|
|
c6bec9aa10 | ||
|
|
2c34d8aabb | ||
|
|
219fdcb9d9 | ||
|
|
a21b88ef8f | ||
|
|
7cf091bb20 | ||
|
|
7398466c33 | ||
|
|
125caf5d6e | ||
|
|
98c6a95079 | ||
|
|
6414d9e2e5 | ||
|
|
b77430df70 | ||
|
|
141d929929 | ||
|
|
9fe8072c67 | ||
|
|
60c602e4e7 | ||
|
|
e00b529a89 | ||
|
|
ef9b31783d | ||
|
|
60315060b1 | ||
|
|
cf9e13c255 | ||
|
|
14f3cebcd4 | ||
|
|
a24e8bf9cf | ||
|
|
77b4916b33 | ||
|
|
4f16ce9294 | ||
|
|
67df3f7742 | ||
|
|
04a1161354 | ||
|
|
2f2ab9b5bc | ||
|
|
b8a62adcf1 | ||
|
|
d1d7ce74d2 | ||
|
|
67658dd6e8 | ||
|
|
9760795bfb | ||
|
|
c9c75f9587 | ||
|
|
2299950de1 | ||
|
|
ba0086e32d | ||
|
|
b25b94400e | ||
|
|
cc1d7048b5 | ||
|
|
524eb15513 | ||
|
|
d5706346d7 | ||
|
|
ac4dbd3b25 | ||
|
|
cab2619aeb | ||
|
|
0378babd15 | ||
|
|
c274fd588d | ||
|
|
cd2efed922 | ||
|
|
e0b9ee9b94 | ||
|
|
574440d59f | ||
|
|
a4ae11d63e | ||
|
|
91f6333e23 | ||
|
|
e0650a2034 | ||
|
|
cfc2f30dc4 | ||
|
|
be5dc68ca3 | ||
|
|
a31c6b2c4e | ||
|
|
f32a49d3d8 | ||
|
|
b9ddb517b1 | ||
|
|
96f2b16356 | ||
|
|
65aff6930b | ||
|
|
c9a1129c95 | ||
|
|
555866f8dc | ||
|
|
538f5880ff | ||
|
|
75395605d6 | ||
|
|
9f2719d1a4 | ||
|
|
3f104464de | ||
|
|
69fa2e6525 | ||
|
|
782b7a0ca4 | ||
|
|
ffc2ce89a0 | ||
|
|
976d9ef43c | ||
|
|
5b5e60ffec | ||
|
|
4e9f975935 | ||
|
|
c4f3400bea | ||
|
|
3952c73aee | ||
|
|
3895f7e456 |
@@ -95,11 +95,11 @@ add_custom_command(OUTPUT scm_rev.cpp
|
||||
)
|
||||
|
||||
add_library(common STATIC
|
||||
algorithm.h
|
||||
alignment.h
|
||||
assert.h
|
||||
detached_tasks.cpp
|
||||
detached_tasks.h
|
||||
binary_find.h
|
||||
bit_field.h
|
||||
bit_util.h
|
||||
cityhash.cpp
|
||||
|
||||
@@ -5,6 +5,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
// Algorithms that operate on iterators, much like the <algorithm> header.
|
||||
//
|
||||
// Note: If the algorithm is not general-purpose and/or doesn't operate on iterators,
|
||||
// it should probably not be placed within this header.
|
||||
|
||||
namespace Common {
|
||||
|
||||
@@ -116,7 +116,7 @@ public:
|
||||
num_interpreted_instructions = 0;
|
||||
}
|
||||
u64 GetTicksRemaining() override {
|
||||
return std::max(parent.system.CoreTiming().GetDowncount(), 0);
|
||||
return std::max(parent.system.CoreTiming().GetDowncount(), s64{0});
|
||||
}
|
||||
u64 GetCNTPCT() override {
|
||||
return Timing::CpuCyclesToClockCycles(parent.system.CoreTiming().GetTicks());
|
||||
|
||||
@@ -156,7 +156,7 @@ void ARM_Unicorn::Run() {
|
||||
if (GDBStub::IsServerEnabled()) {
|
||||
ExecuteInstructions(std::max(4000000, 0));
|
||||
} else {
|
||||
ExecuteInstructions(std::max(system.CoreTiming().GetDowncount(), 0));
|
||||
ExecuteInstructions(std::max(system.CoreTiming().GetDowncount(), s64{0}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -112,8 +112,8 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs,
|
||||
}
|
||||
struct System::Impl {
|
||||
explicit Impl(System& system)
|
||||
: kernel{system}, fs_controller{system}, cpu_core_manager{system},
|
||||
applet_manager{system}, reporter{system} {}
|
||||
: kernel{system}, fs_controller{system}, cpu_core_manager{system}, reporter{system},
|
||||
applet_manager{system} {}
|
||||
|
||||
Cpu& CurrentCpuCore() {
|
||||
return cpu_core_manager.GetCurrentCore();
|
||||
@@ -240,22 +240,27 @@ struct System::Impl {
|
||||
}
|
||||
|
||||
void Shutdown() {
|
||||
// Log last frame performance stats
|
||||
const auto perf_results = GetAndResetPerfStats();
|
||||
telemetry_session->AddField(Telemetry::FieldType::Performance, "Shutdown_EmulationSpeed",
|
||||
perf_results.emulation_speed * 100.0);
|
||||
telemetry_session->AddField(Telemetry::FieldType::Performance, "Shutdown_Framerate",
|
||||
perf_results.game_fps);
|
||||
telemetry_session->AddField(Telemetry::FieldType::Performance, "Shutdown_Frametime",
|
||||
perf_results.frametime * 1000.0);
|
||||
telemetry_session->AddField(Telemetry::FieldType::Performance, "Mean_Frametime_MS",
|
||||
perf_stats->GetMeanFrametime());
|
||||
// Log last frame performance stats if game was loded
|
||||
if (perf_stats) {
|
||||
const auto perf_results = GetAndResetPerfStats();
|
||||
telemetry_session->AddField(Telemetry::FieldType::Performance,
|
||||
"Shutdown_EmulationSpeed",
|
||||
perf_results.emulation_speed * 100.0);
|
||||
telemetry_session->AddField(Telemetry::FieldType::Performance, "Shutdown_Framerate",
|
||||
perf_results.game_fps);
|
||||
telemetry_session->AddField(Telemetry::FieldType::Performance, "Shutdown_Frametime",
|
||||
perf_results.frametime * 1000.0);
|
||||
telemetry_session->AddField(Telemetry::FieldType::Performance, "Mean_Frametime_MS",
|
||||
perf_stats->GetMeanFrametime());
|
||||
}
|
||||
|
||||
lm_manager.Flush();
|
||||
|
||||
is_powered_on = false;
|
||||
exit_lock = false;
|
||||
|
||||
gpu_core->WaitIdle();
|
||||
|
||||
// Shutdown emulation session
|
||||
renderer.reset();
|
||||
GDBStub::Shutdown();
|
||||
|
||||
@@ -85,24 +85,16 @@ void Cpu::RunLoop(bool tight_loop) {
|
||||
// instead advance to the next event and try to yield to the next thread
|
||||
if (Kernel::GetCurrentThread() == nullptr) {
|
||||
LOG_TRACE(Core, "Core-{} idling", core_index);
|
||||
|
||||
if (IsMainCore()) {
|
||||
// TODO(Subv): Only let CoreTiming idle if all 4 cores are idling.
|
||||
core_timing.Idle();
|
||||
core_timing.Advance();
|
||||
}
|
||||
|
||||
core_timing.Idle();
|
||||
core_timing.Advance();
|
||||
PrepareReschedule();
|
||||
} else {
|
||||
if (IsMainCore()) {
|
||||
core_timing.Advance();
|
||||
}
|
||||
|
||||
if (tight_loop) {
|
||||
arm_interface->Run();
|
||||
} else {
|
||||
arm_interface->Step();
|
||||
}
|
||||
core_timing.Advance();
|
||||
}
|
||||
|
||||
Reschedule();
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
namespace Core::Timing {
|
||||
|
||||
constexpr int MAX_SLICE_LENGTH = 20000;
|
||||
constexpr int MAX_SLICE_LENGTH = 10000;
|
||||
|
||||
struct CoreTiming::Event {
|
||||
s64 time;
|
||||
@@ -38,10 +38,12 @@ CoreTiming::CoreTiming() = default;
|
||||
CoreTiming::~CoreTiming() = default;
|
||||
|
||||
void CoreTiming::Initialize() {
|
||||
downcount = MAX_SLICE_LENGTH;
|
||||
downcounts.fill(MAX_SLICE_LENGTH);
|
||||
time_slice.fill(MAX_SLICE_LENGTH);
|
||||
slice_length = MAX_SLICE_LENGTH;
|
||||
global_timer = 0;
|
||||
idled_cycles = 0;
|
||||
current_context = 0;
|
||||
|
||||
// The time between CoreTiming being initialized and the first call to Advance() is considered
|
||||
// the slice boundary between slice -1 and slice 0. Dispatcher loops must call Advance() before
|
||||
@@ -110,7 +112,7 @@ void CoreTiming::UnscheduleEvent(const EventType* event_type, u64 userdata) {
|
||||
u64 CoreTiming::GetTicks() const {
|
||||
u64 ticks = static_cast<u64>(global_timer);
|
||||
if (!is_global_timer_sane) {
|
||||
ticks += slice_length - downcount;
|
||||
ticks += accumulated_ticks;
|
||||
}
|
||||
return ticks;
|
||||
}
|
||||
@@ -120,7 +122,8 @@ u64 CoreTiming::GetIdleTicks() const {
|
||||
}
|
||||
|
||||
void CoreTiming::AddTicks(u64 ticks) {
|
||||
downcount -= static_cast<int>(ticks);
|
||||
accumulated_ticks += ticks;
|
||||
downcounts[current_context] -= static_cast<s64>(ticks);
|
||||
}
|
||||
|
||||
void CoreTiming::ClearPendingEvents() {
|
||||
@@ -141,22 +144,35 @@ void CoreTiming::RemoveEvent(const EventType* event_type) {
|
||||
|
||||
void CoreTiming::ForceExceptionCheck(s64 cycles) {
|
||||
cycles = std::max<s64>(0, cycles);
|
||||
if (downcount <= cycles) {
|
||||
if (downcounts[current_context] <= cycles) {
|
||||
return;
|
||||
}
|
||||
|
||||
// downcount is always (much) smaller than MAX_INT so we can safely cast cycles to an int
|
||||
// here. Account for cycles already executed by adjusting the g.slice_length
|
||||
slice_length -= downcount - static_cast<int>(cycles);
|
||||
downcount = static_cast<int>(cycles);
|
||||
downcounts[current_context] = static_cast<int>(cycles);
|
||||
}
|
||||
|
||||
std::optional<u64> CoreTiming::NextAvailableCore(const s64 needed_ticks) const {
|
||||
const u64 original_context = current_context;
|
||||
u64 next_context = (original_context + 1) % num_cpu_cores;
|
||||
while (next_context != original_context) {
|
||||
if (time_slice[next_context] >= needed_ticks) {
|
||||
return {next_context};
|
||||
} else if (time_slice[next_context] >= 0) {
|
||||
return std::nullopt;
|
||||
}
|
||||
next_context = (next_context + 1) % num_cpu_cores;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void CoreTiming::Advance() {
|
||||
std::unique_lock<std::mutex> guard(inner_mutex);
|
||||
|
||||
const int cycles_executed = slice_length - downcount;
|
||||
const u64 cycles_executed = accumulated_ticks;
|
||||
time_slice[current_context] = std::max<s64>(0, time_slice[current_context] - accumulated_ticks);
|
||||
global_timer += cycles_executed;
|
||||
slice_length = MAX_SLICE_LENGTH;
|
||||
|
||||
is_global_timer_sane = true;
|
||||
|
||||
@@ -173,24 +189,46 @@ void CoreTiming::Advance() {
|
||||
|
||||
// Still events left (scheduled in the future)
|
||||
if (!event_queue.empty()) {
|
||||
slice_length = static_cast<int>(
|
||||
std::min<s64>(event_queue.front().time - global_timer, MAX_SLICE_LENGTH));
|
||||
const s64 needed_ticks =
|
||||
std::min<s64>(event_queue.front().time - global_timer, MAX_SLICE_LENGTH);
|
||||
const auto next_core = NextAvailableCore(needed_ticks);
|
||||
if (next_core) {
|
||||
downcounts[*next_core] = needed_ticks;
|
||||
}
|
||||
}
|
||||
|
||||
downcount = slice_length;
|
||||
accumulated_ticks = 0;
|
||||
|
||||
downcounts[current_context] = time_slice[current_context];
|
||||
}
|
||||
|
||||
void CoreTiming::ResetRun() {
|
||||
downcounts.fill(MAX_SLICE_LENGTH);
|
||||
time_slice.fill(MAX_SLICE_LENGTH);
|
||||
current_context = 0;
|
||||
// Still events left (scheduled in the future)
|
||||
if (!event_queue.empty()) {
|
||||
const s64 needed_ticks =
|
||||
std::min<s64>(event_queue.front().time - global_timer, MAX_SLICE_LENGTH);
|
||||
downcounts[current_context] = needed_ticks;
|
||||
}
|
||||
|
||||
is_global_timer_sane = false;
|
||||
accumulated_ticks = 0;
|
||||
}
|
||||
|
||||
void CoreTiming::Idle() {
|
||||
idled_cycles += downcount;
|
||||
downcount = 0;
|
||||
accumulated_ticks += downcounts[current_context];
|
||||
idled_cycles += downcounts[current_context];
|
||||
downcounts[current_context] = 0;
|
||||
}
|
||||
|
||||
std::chrono::microseconds CoreTiming::GetGlobalTimeUs() const {
|
||||
return std::chrono::microseconds{GetTicks() * 1000000 / BASE_CLOCK_RATE};
|
||||
}
|
||||
|
||||
int CoreTiming::GetDowncount() const {
|
||||
return downcount;
|
||||
s64 CoreTiming::GetDowncount() const {
|
||||
return downcounts[current_context];
|
||||
}
|
||||
|
||||
} // namespace Core::Timing
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
@@ -104,7 +105,19 @@ public:
|
||||
|
||||
std::chrono::microseconds GetGlobalTimeUs() const;
|
||||
|
||||
int GetDowncount() const;
|
||||
void ResetRun();
|
||||
|
||||
s64 GetDowncount() const;
|
||||
|
||||
void SwitchContext(u64 new_context) {
|
||||
current_context = new_context;
|
||||
}
|
||||
|
||||
bool CanCurrentContextRun() const {
|
||||
return time_slice[current_context] > 0;
|
||||
}
|
||||
|
||||
std::optional<u64> NextAvailableCore(const s64 needed_ticks) const;
|
||||
|
||||
private:
|
||||
struct Event;
|
||||
@@ -112,10 +125,16 @@ private:
|
||||
/// Clear all pending events. This should ONLY be done on exit.
|
||||
void ClearPendingEvents();
|
||||
|
||||
static constexpr u64 num_cpu_cores = 4;
|
||||
|
||||
s64 global_timer = 0;
|
||||
s64 idled_cycles = 0;
|
||||
int slice_length = 0;
|
||||
int downcount = 0;
|
||||
s64 slice_length = 0;
|
||||
u64 accumulated_ticks = 0;
|
||||
std::array<s64, num_cpu_cores> downcounts{};
|
||||
// Slice of time assigned to each core per run.
|
||||
std::array<s64, num_cpu_cores> time_slice{};
|
||||
u64 current_context = 0;
|
||||
|
||||
// Are we in a function that has been called from Advance()
|
||||
// If events are scheduled from a function that gets called from Advance(),
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "core/arm/exclusive_monitor.h"
|
||||
#include "core/core.h"
|
||||
#include "core/core_cpu.h"
|
||||
#include "core/core_timing.h"
|
||||
#include "core/cpu_core_manager.h"
|
||||
#include "core/gdbstub/gdbstub.h"
|
||||
#include "core/settings.h"
|
||||
@@ -122,13 +123,19 @@ void CpuCoreManager::RunLoop(bool tight_loop) {
|
||||
}
|
||||
}
|
||||
|
||||
for (active_core = 0; active_core < NUM_CPU_CORES; ++active_core) {
|
||||
cores[active_core]->RunLoop(tight_loop);
|
||||
if (Settings::values.use_multi_core) {
|
||||
// Cores 1-3 are run on other threads in this mode
|
||||
break;
|
||||
auto& core_timing = system.CoreTiming();
|
||||
core_timing.ResetRun();
|
||||
bool keep_running{};
|
||||
do {
|
||||
keep_running = false;
|
||||
for (active_core = 0; active_core < NUM_CPU_CORES; ++active_core) {
|
||||
core_timing.SwitchContext(active_core);
|
||||
if (core_timing.CanCurrentContextRun()) {
|
||||
cores[active_core]->RunLoop(tight_loop);
|
||||
}
|
||||
keep_running |= core_timing.CanCurrentContextRun();
|
||||
}
|
||||
}
|
||||
} while (keep_running);
|
||||
|
||||
if (GDBStub::IsServerEnabled()) {
|
||||
GDBStub::SetCpuStepFlag(false);
|
||||
|
||||
@@ -31,7 +31,7 @@ constexpr std::array partition_names{
|
||||
|
||||
XCI::XCI(VirtualFile file_)
|
||||
: file(std::move(file_)), program_nca_status{Loader::ResultStatus::ErrorXCIMissingProgramNCA},
|
||||
partitions(partition_names.size()) {
|
||||
partitions(partition_names.size()), partitions_raw(partition_names.size()) {
|
||||
if (file->ReadObject(&header) != sizeof(GamecardHeader)) {
|
||||
status = Loader::ResultStatus::ErrorBadXCIHeader;
|
||||
return;
|
||||
@@ -42,8 +42,10 @@ XCI::XCI(VirtualFile file_)
|
||||
return;
|
||||
}
|
||||
|
||||
PartitionFilesystem main_hfs(
|
||||
std::make_shared<OffsetVfsFile>(file, header.hfs_size, header.hfs_offset));
|
||||
PartitionFilesystem main_hfs(std::make_shared<OffsetVfsFile>(
|
||||
file, file->GetSize() - header.hfs_offset, header.hfs_offset));
|
||||
|
||||
update_normal_partition_end = main_hfs.GetFileOffsets()["secure"];
|
||||
|
||||
if (main_hfs.GetStatus() != Loader::ResultStatus::Success) {
|
||||
status = main_hfs.GetStatus();
|
||||
@@ -55,9 +57,7 @@ XCI::XCI(VirtualFile file_)
|
||||
const auto partition_idx = static_cast<std::size_t>(partition);
|
||||
auto raw = main_hfs.GetFile(partition_names[partition_idx]);
|
||||
|
||||
if (raw != nullptr) {
|
||||
partitions[partition_idx] = std::make_shared<PartitionFilesystem>(std::move(raw));
|
||||
}
|
||||
partitions_raw[static_cast<std::size_t>(partition)] = std::move(raw);
|
||||
}
|
||||
|
||||
secure_partition = std::make_shared<NSP>(
|
||||
@@ -71,13 +71,7 @@ XCI::XCI(VirtualFile file_)
|
||||
program_nca_status = Loader::ResultStatus::ErrorXCIMissingProgramNCA;
|
||||
}
|
||||
|
||||
auto result = AddNCAFromPartition(XCIPartition::Update);
|
||||
if (result != Loader::ResultStatus::Success) {
|
||||
status = result;
|
||||
return;
|
||||
}
|
||||
|
||||
result = AddNCAFromPartition(XCIPartition::Normal);
|
||||
auto result = AddNCAFromPartition(XCIPartition::Normal);
|
||||
if (result != Loader::ResultStatus::Success) {
|
||||
status = result;
|
||||
return;
|
||||
@@ -104,34 +98,114 @@ Loader::ResultStatus XCI::GetProgramNCAStatus() const {
|
||||
return program_nca_status;
|
||||
}
|
||||
|
||||
VirtualDir XCI::GetPartition(XCIPartition partition) const {
|
||||
VirtualDir XCI::GetPartition(XCIPartition partition) {
|
||||
const auto id = static_cast<std::size_t>(partition);
|
||||
if (partitions[id] == nullptr && partitions_raw[id] != nullptr) {
|
||||
partitions[id] = std::make_shared<PartitionFilesystem>(partitions_raw[id]);
|
||||
}
|
||||
|
||||
return partitions[static_cast<std::size_t>(partition)];
|
||||
}
|
||||
|
||||
std::vector<VirtualDir> XCI::GetPartitions() {
|
||||
std::vector<VirtualDir> out;
|
||||
for (const auto& id :
|
||||
{XCIPartition::Update, XCIPartition::Normal, XCIPartition::Secure, XCIPartition::Logo}) {
|
||||
const auto part = GetPartition(id);
|
||||
if (part != nullptr) {
|
||||
out.push_back(part);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::shared_ptr<NSP> XCI::GetSecurePartitionNSP() const {
|
||||
return secure_partition;
|
||||
}
|
||||
|
||||
VirtualDir XCI::GetSecurePartition() const {
|
||||
VirtualDir XCI::GetSecurePartition() {
|
||||
return GetPartition(XCIPartition::Secure);
|
||||
}
|
||||
|
||||
VirtualDir XCI::GetNormalPartition() const {
|
||||
VirtualDir XCI::GetNormalPartition() {
|
||||
return GetPartition(XCIPartition::Normal);
|
||||
}
|
||||
|
||||
VirtualDir XCI::GetUpdatePartition() const {
|
||||
VirtualDir XCI::GetUpdatePartition() {
|
||||
return GetPartition(XCIPartition::Update);
|
||||
}
|
||||
|
||||
VirtualDir XCI::GetLogoPartition() const {
|
||||
VirtualDir XCI::GetLogoPartition() {
|
||||
return GetPartition(XCIPartition::Logo);
|
||||
}
|
||||
|
||||
VirtualFile XCI::GetPartitionRaw(XCIPartition partition) const {
|
||||
return partitions_raw[static_cast<std::size_t>(partition)];
|
||||
}
|
||||
|
||||
VirtualFile XCI::GetSecurePartitionRaw() const {
|
||||
return GetPartitionRaw(XCIPartition::Secure);
|
||||
}
|
||||
|
||||
VirtualFile XCI::GetStoragePartition0() const {
|
||||
return std::make_shared<OffsetVfsFile>(file, update_normal_partition_end, 0, "partition0");
|
||||
}
|
||||
|
||||
VirtualFile XCI::GetStoragePartition1() const {
|
||||
return std::make_shared<OffsetVfsFile>(file, file->GetSize() - update_normal_partition_end,
|
||||
update_normal_partition_end, "partition1");
|
||||
}
|
||||
|
||||
VirtualFile XCI::GetNormalPartitionRaw() const {
|
||||
return GetPartitionRaw(XCIPartition::Normal);
|
||||
}
|
||||
|
||||
VirtualFile XCI::GetUpdatePartitionRaw() const {
|
||||
return GetPartitionRaw(XCIPartition::Update);
|
||||
}
|
||||
|
||||
VirtualFile XCI::GetLogoPartitionRaw() const {
|
||||
return GetPartitionRaw(XCIPartition::Logo);
|
||||
}
|
||||
|
||||
u64 XCI::GetProgramTitleID() const {
|
||||
return secure_partition->GetProgramTitleID();
|
||||
}
|
||||
|
||||
u32 XCI::GetSystemUpdateVersion() {
|
||||
const auto update = GetPartition(XCIPartition::Update);
|
||||
if (update == nullptr)
|
||||
return 0;
|
||||
|
||||
for (const auto& file : update->GetFiles()) {
|
||||
NCA nca{file, nullptr, 0, keys};
|
||||
|
||||
if (nca.GetStatus() != Loader::ResultStatus::Success)
|
||||
continue;
|
||||
|
||||
if (nca.GetType() == NCAContentType::Meta && nca.GetTitleId() == 0x0100000000000816) {
|
||||
const auto dir = nca.GetSubdirectories()[0];
|
||||
const auto cnmt = dir->GetFile("SystemUpdate_0100000000000816.cnmt");
|
||||
if (cnmt == nullptr)
|
||||
continue;
|
||||
|
||||
CNMT cnmt_data{cnmt};
|
||||
|
||||
const auto metas = cnmt_data.GetMetaRecords();
|
||||
if (metas.empty())
|
||||
continue;
|
||||
|
||||
return metas[0].title_version;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u64 XCI::GetSystemUpdateTitleID() const {
|
||||
return 0x0100000000000816;
|
||||
}
|
||||
|
||||
bool XCI::HasProgramNCA() const {
|
||||
return program != nullptr;
|
||||
}
|
||||
@@ -201,7 +275,7 @@ std::array<u8, 0x200> XCI::GetCertificate() const {
|
||||
|
||||
Loader::ResultStatus XCI::AddNCAFromPartition(XCIPartition part) {
|
||||
const auto partition_index = static_cast<std::size_t>(part);
|
||||
const auto& partition = partitions[partition_index];
|
||||
const auto partition = GetPartition(part);
|
||||
|
||||
if (partition == nullptr) {
|
||||
return Loader::ResultStatus::ErrorXCIMissingPartition;
|
||||
@@ -232,7 +306,7 @@ Loader::ResultStatus XCI::AddNCAFromPartition(XCIPartition part) {
|
||||
return Loader::ResultStatus::Success;
|
||||
}
|
||||
|
||||
u8 XCI::GetFormatVersion() const {
|
||||
u8 XCI::GetFormatVersion() {
|
||||
return GetLogoPartition() == nullptr ? 0x1 : 0x2;
|
||||
}
|
||||
} // namespace FileSys
|
||||
|
||||
@@ -81,14 +81,24 @@ public:
|
||||
Loader::ResultStatus GetStatus() const;
|
||||
Loader::ResultStatus GetProgramNCAStatus() const;
|
||||
|
||||
u8 GetFormatVersion() const;
|
||||
u8 GetFormatVersion();
|
||||
|
||||
VirtualDir GetPartition(XCIPartition partition);
|
||||
std::vector<VirtualDir> GetPartitions();
|
||||
|
||||
VirtualDir GetPartition(XCIPartition partition) const;
|
||||
std::shared_ptr<NSP> GetSecurePartitionNSP() const;
|
||||
VirtualDir GetSecurePartition() const;
|
||||
VirtualDir GetNormalPartition() const;
|
||||
VirtualDir GetUpdatePartition() const;
|
||||
VirtualDir GetLogoPartition() const;
|
||||
VirtualDir GetSecurePartition();
|
||||
VirtualDir GetNormalPartition();
|
||||
VirtualDir GetUpdatePartition();
|
||||
VirtualDir GetLogoPartition();
|
||||
|
||||
VirtualFile GetPartitionRaw(XCIPartition partition) const;
|
||||
VirtualFile GetSecurePartitionRaw() const;
|
||||
VirtualFile GetStoragePartition0() const;
|
||||
VirtualFile GetStoragePartition1() const;
|
||||
VirtualFile GetNormalPartitionRaw() const;
|
||||
VirtualFile GetUpdatePartitionRaw() const;
|
||||
VirtualFile GetLogoPartitionRaw() const;
|
||||
|
||||
u64 GetProgramTitleID() const;
|
||||
u32 GetSystemUpdateVersion();
|
||||
@@ -123,6 +133,7 @@ private:
|
||||
Loader::ResultStatus program_nca_status;
|
||||
|
||||
std::vector<VirtualDir> partitions;
|
||||
std::vector<VirtualFile> partitions_raw;
|
||||
std::shared_ptr<NSP> secure_partition;
|
||||
std::shared_ptr<NCA> program;
|
||||
std::vector<std::shared_ptr<NCA>> ncas;
|
||||
|
||||
@@ -65,6 +65,9 @@ PartitionFilesystem::PartitionFilesystem(std::shared_ptr<VfsFile> file) {
|
||||
std::string name(
|
||||
reinterpret_cast<const char*>(&file_data[strtab_offset + entry.strtab_offset]));
|
||||
|
||||
offsets.insert_or_assign(name, content_offset + entry.offset);
|
||||
sizes.insert_or_assign(name, entry.size);
|
||||
|
||||
pfs_files.emplace_back(std::make_shared<OffsetVfsFile>(
|
||||
file, entry.size, content_offset + entry.offset, std::move(name)));
|
||||
}
|
||||
@@ -78,6 +81,14 @@ Loader::ResultStatus PartitionFilesystem::GetStatus() const {
|
||||
return status;
|
||||
}
|
||||
|
||||
std::map<std::string, u64> PartitionFilesystem::GetFileOffsets() const {
|
||||
return offsets;
|
||||
}
|
||||
|
||||
std::map<std::string, u64> PartitionFilesystem::GetFileSizes() const {
|
||||
return sizes;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<VfsFile>> PartitionFilesystem::GetFiles() const {
|
||||
return pfs_files;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,9 @@ public:
|
||||
|
||||
Loader::ResultStatus GetStatus() const;
|
||||
|
||||
std::map<std::string, u64> GetFileOffsets() const;
|
||||
std::map<std::string, u64> GetFileSizes() const;
|
||||
|
||||
std::vector<std::shared_ptr<VfsFile>> GetFiles() const override;
|
||||
std::vector<std::shared_ptr<VfsDirectory>> GetSubdirectories() const override;
|
||||
std::string GetName() const override;
|
||||
@@ -80,6 +83,9 @@ private:
|
||||
bool is_hfs = false;
|
||||
std::size_t content_offset = 0;
|
||||
|
||||
std::map<std::string, u64> offsets;
|
||||
std::map<std::string, u64> sizes;
|
||||
|
||||
std::vector<VirtualFile> pfs_files;
|
||||
};
|
||||
|
||||
|
||||
@@ -1140,8 +1140,9 @@ void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) {
|
||||
LOG_DEBUG(Service_AM, "called, kind={:08X}", static_cast<u8>(kind));
|
||||
|
||||
if (kind == LaunchParameterKind::ApplicationSpecific && !launch_popped_application_specific) {
|
||||
const auto backend = BCAT::CreateBackendFromSettings(
|
||||
[this](u64 tid) { return system.GetFileSystemController().GetBCATDirectory(tid); });
|
||||
const auto backend = BCAT::CreateBackendFromSettings(system, [this](u64 tid) {
|
||||
return system.GetFileSystemController().GetBCATDirectory(tid);
|
||||
});
|
||||
const auto build_id_full = system.GetCurrentProcessBuildID();
|
||||
u64 build_id{};
|
||||
std::memcpy(&build_id, build_id_full.data(), sizeof(u64));
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <utility>
|
||||
|
||||
#include "common/logging/log.h"
|
||||
#include "core/core_timing.h"
|
||||
#include "core/hle/service/apm/controller.h"
|
||||
@@ -9,8 +13,7 @@
|
||||
|
||||
namespace Service::APM {
|
||||
|
||||
constexpr PerformanceConfiguration DEFAULT_PERFORMANCE_CONFIGURATION =
|
||||
PerformanceConfiguration::Config7;
|
||||
constexpr auto DEFAULT_PERFORMANCE_CONFIGURATION = PerformanceConfiguration::Config7;
|
||||
|
||||
Controller::Controller(Core::Timing::CoreTiming& core_timing)
|
||||
: core_timing{core_timing}, configs{
|
||||
@@ -22,18 +25,35 @@ Controller::~Controller() = default;
|
||||
|
||||
void Controller::SetPerformanceConfiguration(PerformanceMode mode,
|
||||
PerformanceConfiguration config) {
|
||||
static const std::map<PerformanceConfiguration, u32> PCONFIG_TO_SPEED_MAP{
|
||||
{PerformanceConfiguration::Config1, 1020}, {PerformanceConfiguration::Config2, 1020},
|
||||
{PerformanceConfiguration::Config3, 1224}, {PerformanceConfiguration::Config4, 1020},
|
||||
{PerformanceConfiguration::Config5, 1020}, {PerformanceConfiguration::Config6, 1224},
|
||||
{PerformanceConfiguration::Config7, 1020}, {PerformanceConfiguration::Config8, 1020},
|
||||
{PerformanceConfiguration::Config9, 1020}, {PerformanceConfiguration::Config10, 1020},
|
||||
{PerformanceConfiguration::Config11, 1020}, {PerformanceConfiguration::Config12, 1020},
|
||||
{PerformanceConfiguration::Config13, 1785}, {PerformanceConfiguration::Config14, 1785},
|
||||
{PerformanceConfiguration::Config15, 1020}, {PerformanceConfiguration::Config16, 1020},
|
||||
};
|
||||
static constexpr std::array<std::pair<PerformanceConfiguration, u32>, 16> config_to_speed{{
|
||||
{PerformanceConfiguration::Config1, 1020},
|
||||
{PerformanceConfiguration::Config2, 1020},
|
||||
{PerformanceConfiguration::Config3, 1224},
|
||||
{PerformanceConfiguration::Config4, 1020},
|
||||
{PerformanceConfiguration::Config5, 1020},
|
||||
{PerformanceConfiguration::Config6, 1224},
|
||||
{PerformanceConfiguration::Config7, 1020},
|
||||
{PerformanceConfiguration::Config8, 1020},
|
||||
{PerformanceConfiguration::Config9, 1020},
|
||||
{PerformanceConfiguration::Config10, 1020},
|
||||
{PerformanceConfiguration::Config11, 1020},
|
||||
{PerformanceConfiguration::Config12, 1020},
|
||||
{PerformanceConfiguration::Config13, 1785},
|
||||
{PerformanceConfiguration::Config14, 1785},
|
||||
{PerformanceConfiguration::Config15, 1020},
|
||||
{PerformanceConfiguration::Config16, 1020},
|
||||
}};
|
||||
|
||||
SetClockSpeed(PCONFIG_TO_SPEED_MAP.find(config)->second);
|
||||
const auto iter = std::find_if(config_to_speed.cbegin(), config_to_speed.cend(),
|
||||
[config](const auto& entry) { return entry.first == config; });
|
||||
|
||||
if (iter == config_to_speed.cend()) {
|
||||
LOG_ERROR(Service_APM, "Invalid performance configuration value provided: {}",
|
||||
static_cast<u32>(config));
|
||||
return;
|
||||
}
|
||||
|
||||
SetClockSpeed(iter->second);
|
||||
configs.insert_or_assign(mode, config);
|
||||
}
|
||||
|
||||
@@ -48,7 +68,7 @@ void Controller::SetFromCpuBoostMode(CpuBoostMode mode) {
|
||||
BOOST_MODE_TO_CONFIG_MAP.at(static_cast<u32>(mode)));
|
||||
}
|
||||
|
||||
PerformanceMode Controller::GetCurrentPerformanceMode() {
|
||||
PerformanceMode Controller::GetCurrentPerformanceMode() const {
|
||||
return Settings::values.use_docked_mode ? PerformanceMode::Docked : PerformanceMode::Handheld;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
void SetPerformanceConfiguration(PerformanceMode mode, PerformanceConfiguration config);
|
||||
void SetFromCpuBoostMode(CpuBoostMode mode);
|
||||
|
||||
PerformanceMode GetCurrentPerformanceMode();
|
||||
PerformanceMode GetCurrentPerformanceMode() const;
|
||||
PerformanceConfiguration GetCurrentPerformanceConfiguration(PerformanceMode mode);
|
||||
|
||||
private:
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
|
||||
namespace Service::BCAT {
|
||||
|
||||
ProgressServiceBackend::ProgressServiceBackend(std::string_view event_name) {
|
||||
auto& kernel{Core::System::GetInstance().Kernel()};
|
||||
ProgressServiceBackend::ProgressServiceBackend(Kernel::KernelCore& kernel,
|
||||
std::string_view event_name) {
|
||||
event = Kernel::WritableEvent::CreateEventPair(
|
||||
kernel, Kernel::ResetType::Automatic,
|
||||
std::string("ProgressServiceBackend:UpdateEvent:").append(event_name));
|
||||
|
||||
@@ -15,6 +15,14 @@
|
||||
#include "core/hle/kernel/writable_event.h"
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace Core {
|
||||
class System;
|
||||
}
|
||||
|
||||
namespace Kernel {
|
||||
class KernelCore;
|
||||
}
|
||||
|
||||
namespace Service::BCAT {
|
||||
|
||||
struct DeliveryCacheProgressImpl;
|
||||
@@ -88,7 +96,7 @@ public:
|
||||
void FinishDownload(ResultCode result);
|
||||
|
||||
private:
|
||||
explicit ProgressServiceBackend(std::string_view event_name);
|
||||
explicit ProgressServiceBackend(Kernel::KernelCore& kernel, std::string_view event_name);
|
||||
|
||||
Kernel::SharedPtr<Kernel::ReadableEvent> GetEvent() const;
|
||||
DeliveryCacheProgressImpl& GetImpl();
|
||||
@@ -145,6 +153,6 @@ public:
|
||||
std::optional<std::vector<u8>> GetLaunchParameter(TitleIDVersion title) override;
|
||||
};
|
||||
|
||||
std::unique_ptr<Backend> CreateBackendFromSettings(DirectoryGetter getter);
|
||||
std::unique_ptr<Backend> CreateBackendFromSettings(Core::System& system, DirectoryGetter getter);
|
||||
|
||||
} // namespace Service::BCAT
|
||||
|
||||
@@ -104,14 +104,15 @@ std::string GetZIPFilePath(u64 title_id) {
|
||||
|
||||
// If the error is something the user should know about (build ID mismatch, bad client version),
|
||||
// display an error.
|
||||
void HandleDownloadDisplayResult(DownloadResult res) {
|
||||
void HandleDownloadDisplayResult(const AM::Applets::AppletManager& applet_manager,
|
||||
DownloadResult res) {
|
||||
if (res == DownloadResult::Success || res == DownloadResult::NoResponse ||
|
||||
res == DownloadResult::GeneralWebError || res == DownloadResult::GeneralFSError ||
|
||||
res == DownloadResult::NoMatchTitleId || res == DownloadResult::InvalidContentType) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& frontend{Core::System::GetInstance().GetAppletManager().GetAppletFrontendSet()};
|
||||
const auto& frontend{applet_manager.GetAppletFrontendSet()};
|
||||
frontend.error->ShowCustomErrorText(
|
||||
ResultCode(-1), "There was an error while attempting to use Boxcat.",
|
||||
DOWNLOAD_RESULT_LOG_MESSAGES[static_cast<std::size_t>(res)], [] {});
|
||||
@@ -264,12 +265,13 @@ private:
|
||||
u64 build_id;
|
||||
};
|
||||
|
||||
Boxcat::Boxcat(DirectoryGetter getter) : Backend(std::move(getter)) {}
|
||||
Boxcat::Boxcat(AM::Applets::AppletManager& applet_manager_, DirectoryGetter getter)
|
||||
: Backend(std::move(getter)), applet_manager{applet_manager_} {}
|
||||
|
||||
Boxcat::~Boxcat() = default;
|
||||
|
||||
void SynchronizeInternal(DirectoryGetter dir_getter, TitleIDVersion title,
|
||||
ProgressServiceBackend& progress,
|
||||
void SynchronizeInternal(AM::Applets::AppletManager& applet_manager, DirectoryGetter dir_getter,
|
||||
TitleIDVersion title, ProgressServiceBackend& progress,
|
||||
std::optional<std::string> dir_name = {}) {
|
||||
progress.SetNeedHLELock(true);
|
||||
|
||||
@@ -295,7 +297,7 @@ void SynchronizeInternal(DirectoryGetter dir_getter, TitleIDVersion title,
|
||||
FileUtil::Delete(zip_path);
|
||||
}
|
||||
|
||||
HandleDownloadDisplayResult(res);
|
||||
HandleDownloadDisplayResult(applet_manager, res);
|
||||
progress.FinishDownload(ERROR_GENERAL_BCAT_FAILURE);
|
||||
return;
|
||||
}
|
||||
@@ -364,17 +366,24 @@ void SynchronizeInternal(DirectoryGetter dir_getter, TitleIDVersion title,
|
||||
|
||||
bool Boxcat::Synchronize(TitleIDVersion title, ProgressServiceBackend& progress) {
|
||||
is_syncing.exchange(true);
|
||||
std::thread([this, title, &progress] { SynchronizeInternal(dir_getter, title, progress); })
|
||||
|
||||
std::thread([this, title, &progress] {
|
||||
SynchronizeInternal(applet_manager, dir_getter, title, progress);
|
||||
})
|
||||
.detach();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Boxcat::SynchronizeDirectory(TitleIDVersion title, std::string name,
|
||||
ProgressServiceBackend& progress) {
|
||||
is_syncing.exchange(true);
|
||||
std::thread(
|
||||
[this, title, name, &progress] { SynchronizeInternal(dir_getter, title, progress, name); })
|
||||
|
||||
std::thread([this, title, name, &progress] {
|
||||
SynchronizeInternal(applet_manager, dir_getter, title, progress, name);
|
||||
})
|
||||
.detach();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -420,7 +429,7 @@ std::optional<std::vector<u8>> Boxcat::GetLaunchParameter(TitleIDVersion title)
|
||||
FileUtil::Delete(path);
|
||||
}
|
||||
|
||||
HandleDownloadDisplayResult(res);
|
||||
HandleDownloadDisplayResult(applet_manager, res);
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
#include <optional>
|
||||
#include "core/hle/service/bcat/backend/backend.h"
|
||||
|
||||
namespace Service::AM::Applets {
|
||||
class AppletManager;
|
||||
}
|
||||
|
||||
namespace Service::BCAT {
|
||||
|
||||
struct EventStatus {
|
||||
@@ -20,12 +24,13 @@ struct EventStatus {
|
||||
/// Boxcat is yuzu's custom backend implementation of Nintendo's BCAT service. It is free to use and
|
||||
/// doesn't require a switch or nintendo account. The content is controlled by the yuzu team.
|
||||
class Boxcat final : public Backend {
|
||||
friend void SynchronizeInternal(DirectoryGetter dir_getter, TitleIDVersion title,
|
||||
friend void SynchronizeInternal(AM::Applets::AppletManager& applet_manager,
|
||||
DirectoryGetter dir_getter, TitleIDVersion title,
|
||||
ProgressServiceBackend& progress,
|
||||
std::optional<std::string> dir_name);
|
||||
|
||||
public:
|
||||
explicit Boxcat(DirectoryGetter getter);
|
||||
explicit Boxcat(AM::Applets::AppletManager& applet_manager_, DirectoryGetter getter);
|
||||
~Boxcat() override;
|
||||
|
||||
bool Synchronize(TitleIDVersion title, ProgressServiceBackend& progress) override;
|
||||
@@ -53,6 +58,7 @@ private:
|
||||
|
||||
class Client;
|
||||
std::unique_ptr<Client> client;
|
||||
AM::Applets::AppletManager& applet_manager;
|
||||
};
|
||||
|
||||
} // namespace Service::BCAT
|
||||
|
||||
@@ -125,7 +125,11 @@ private:
|
||||
class IBcatService final : public ServiceFramework<IBcatService> {
|
||||
public:
|
||||
explicit IBcatService(Core::System& system_, Backend& backend_)
|
||||
: ServiceFramework("IBcatService"), system{system_}, backend{backend_} {
|
||||
: ServiceFramework("IBcatService"), system{system_}, backend{backend_},
|
||||
progress{{
|
||||
ProgressServiceBackend{system_.Kernel(), "Normal"},
|
||||
ProgressServiceBackend{system_.Kernel(), "Directory"},
|
||||
}} {
|
||||
// clang-format off
|
||||
static const FunctionInfo functions[] = {
|
||||
{10100, &IBcatService::RequestSyncDeliveryCache, "RequestSyncDeliveryCache"},
|
||||
@@ -249,10 +253,7 @@ private:
|
||||
Core::System& system;
|
||||
Backend& backend;
|
||||
|
||||
std::array<ProgressServiceBackend, static_cast<std::size_t>(SyncType::Count)> progress{
|
||||
ProgressServiceBackend{"Normal"},
|
||||
ProgressServiceBackend{"Directory"},
|
||||
};
|
||||
std::array<ProgressServiceBackend, static_cast<std::size_t>(SyncType::Count)> progress;
|
||||
};
|
||||
|
||||
void Module::Interface::CreateBcatService(Kernel::HLERequestContext& ctx) {
|
||||
@@ -557,12 +558,12 @@ void Module::Interface::CreateDeliveryCacheStorageServiceWithApplicationId(
|
||||
rb.PushIpcInterface<IDeliveryCacheStorageService>(fsc.GetBCATDirectory(title_id));
|
||||
}
|
||||
|
||||
std::unique_ptr<Backend> CreateBackendFromSettings(DirectoryGetter getter) {
|
||||
const auto backend = Settings::values.bcat_backend;
|
||||
|
||||
std::unique_ptr<Backend> CreateBackendFromSettings([[maybe_unused]] Core::System& system,
|
||||
DirectoryGetter getter) {
|
||||
#ifdef YUZU_ENABLE_BOXCAT
|
||||
if (backend == "boxcat")
|
||||
return std::make_unique<Boxcat>(std::move(getter));
|
||||
if (Settings::values.bcat_backend == "boxcat") {
|
||||
return std::make_unique<Boxcat>(system.GetAppletManager(), std::move(getter));
|
||||
}
|
||||
#endif
|
||||
|
||||
return std::make_unique<NullBackend>(std::move(getter));
|
||||
@@ -571,7 +572,8 @@ std::unique_ptr<Backend> CreateBackendFromSettings(DirectoryGetter getter) {
|
||||
Module::Interface::Interface(Core::System& system_, std::shared_ptr<Module> module_,
|
||||
FileSystem::FileSystemController& fsc_, const char* name)
|
||||
: ServiceFramework(name), fsc{fsc_}, module{std::move(module_)},
|
||||
backend{CreateBackendFromSettings([&fsc_](u64 tid) { return fsc_.GetBCATDirectory(tid); })},
|
||||
backend{CreateBackendFromSettings(system_,
|
||||
[&fsc_](u64 tid) { return fsc_.GetBCATDirectory(tid); })},
|
||||
system{system_} {}
|
||||
|
||||
Module::Interface::~Interface() = default;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "common/assert.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "core/core.h"
|
||||
#include "core/core_timing.h"
|
||||
#include "core/hle/service/nvdrv/devices/nvdisp_disp0.h"
|
||||
#include "core/hle/service/nvdrv/devices/nvmap.h"
|
||||
#include "core/perf_stats.h"
|
||||
@@ -38,7 +39,10 @@ void nvdisp_disp0::flip(u32 buffer_handle, u32 offset, u32 format, u32 width, u3
|
||||
transform, crop_rect};
|
||||
|
||||
system.GetPerfStats().EndGameFrame();
|
||||
system.GetPerfStats().EndSystemFrame();
|
||||
system.GPU().SwapBuffers(&framebuffer);
|
||||
system.FrameLimiter().DoFrameLimiting(system.CoreTiming().GetGlobalTimeUs());
|
||||
system.GetPerfStats().BeginSystemFrame();
|
||||
}
|
||||
|
||||
} // namespace Service::Nvidia::Devices
|
||||
|
||||
@@ -63,16 +63,26 @@ u32 nvhost_ctrl::IocCtrlEventWait(const std::vector<u8>& input, std::vector<u8>&
|
||||
return NvResult::BadParameter;
|
||||
}
|
||||
|
||||
u32 event_id = params.value & 0x00FF;
|
||||
|
||||
if (event_id >= MaxNvEvents) {
|
||||
std::memcpy(output.data(), ¶ms, sizeof(params));
|
||||
return NvResult::BadParameter;
|
||||
}
|
||||
|
||||
auto event = events_interface.events[event_id];
|
||||
auto& gpu = system.GPU();
|
||||
// This is mostly to take into account unimplemented features. As synced
|
||||
// gpu is always synced.
|
||||
if (!gpu.IsAsync()) {
|
||||
event.writable->Signal();
|
||||
return NvResult::Success;
|
||||
}
|
||||
auto lock = gpu.LockSync();
|
||||
const u32 current_syncpoint_value = gpu.GetSyncpointValue(params.syncpt_id);
|
||||
const s32 diff = current_syncpoint_value - params.threshold;
|
||||
if (diff >= 0) {
|
||||
event.writable->Signal();
|
||||
params.value = current_syncpoint_value;
|
||||
std::memcpy(output.data(), ¶ms, sizeof(params));
|
||||
return NvResult::Success;
|
||||
@@ -88,27 +98,6 @@ u32 nvhost_ctrl::IocCtrlEventWait(const std::vector<u8>& input, std::vector<u8>&
|
||||
return NvResult::Timeout;
|
||||
}
|
||||
|
||||
u32 event_id;
|
||||
if (is_async) {
|
||||
event_id = params.value & 0x00FF;
|
||||
if (event_id >= MaxNvEvents) {
|
||||
std::memcpy(output.data(), ¶ms, sizeof(params));
|
||||
return NvResult::BadParameter;
|
||||
}
|
||||
} else {
|
||||
if (ctrl.fresh_call) {
|
||||
const auto result = events_interface.GetFreeEvent();
|
||||
if (result) {
|
||||
event_id = *result;
|
||||
} else {
|
||||
LOG_CRITICAL(Service_NVDRV, "No Free Events available!");
|
||||
event_id = params.value & 0x00FF;
|
||||
}
|
||||
} else {
|
||||
event_id = ctrl.event_id;
|
||||
}
|
||||
}
|
||||
|
||||
EventState status = events_interface.status[event_id];
|
||||
if (event_id < MaxNvEvents || status == EventState::Free || status == EventState::Registered) {
|
||||
events_interface.SetEventStatus(event_id, EventState::Waiting);
|
||||
@@ -120,7 +109,7 @@ u32 nvhost_ctrl::IocCtrlEventWait(const std::vector<u8>& input, std::vector<u8>&
|
||||
params.value = ((params.syncpt_id & 0xfff) << 16) | 0x10000000;
|
||||
}
|
||||
params.value |= event_id;
|
||||
events_interface.events[event_id].writable->Clear();
|
||||
event.writable->Clear();
|
||||
gpu.RegisterSyncptInterrupt(params.syncpt_id, target_value);
|
||||
if (!is_async && ctrl.fresh_call) {
|
||||
ctrl.must_delay = true;
|
||||
|
||||
@@ -134,7 +134,9 @@ void NVDRV::QueryEvent(Kernel::HLERequestContext& ctx) {
|
||||
IPC::ResponseBuilder rb{ctx, 3, 1};
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
if (event_id < MaxNvEvents) {
|
||||
rb.PushCopyObjects(nvdrv->GetEvent(event_id));
|
||||
auto event = nvdrv->GetEvent(event_id);
|
||||
event->Clear();
|
||||
rb.PushCopyObjects(event);
|
||||
rb.Push<u32>(NvResult::Success);
|
||||
} else {
|
||||
rb.Push<u32>(0);
|
||||
|
||||
@@ -40,8 +40,8 @@ Module::Module(Core::System& system) {
|
||||
auto& kernel = system.Kernel();
|
||||
for (u32 i = 0; i < MaxNvEvents; i++) {
|
||||
std::string event_label = fmt::format("NVDRV::NvEvent_{}", i);
|
||||
events_interface.events[i] = Kernel::WritableEvent::CreateEventPair(
|
||||
kernel, Kernel::ResetType::Automatic, event_label);
|
||||
events_interface.events[i] =
|
||||
Kernel::WritableEvent::CreateEventPair(kernel, Kernel::ResetType::Manual, event_label);
|
||||
events_interface.status[i] = EventState::Free;
|
||||
events_interface.registered[i] = false;
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
|
||||
namespace Service::NVFlinger {
|
||||
|
||||
BufferQueue::BufferQueue(u32 id, u64 layer_id) : id(id), layer_id(layer_id) {
|
||||
auto& kernel = Core::System::GetInstance().Kernel();
|
||||
BufferQueue::BufferQueue(Kernel::KernelCore& kernel, u32 id, u64 layer_id)
|
||||
: id(id), layer_id(layer_id) {
|
||||
buffer_wait_event = Kernel::WritableEvent::CreateEventPair(kernel, Kernel::ResetType::Manual,
|
||||
"BufferQueue NativeHandle");
|
||||
}
|
||||
|
||||
@@ -15,6 +15,10 @@
|
||||
#include "core/hle/kernel/writable_event.h"
|
||||
#include "core/hle/service/nvdrv/nvdata.h"
|
||||
|
||||
namespace Kernel {
|
||||
class KernelCore;
|
||||
}
|
||||
|
||||
namespace Service::NVFlinger {
|
||||
|
||||
struct IGBPBuffer {
|
||||
@@ -44,7 +48,7 @@ public:
|
||||
NativeWindowFormat = 2,
|
||||
};
|
||||
|
||||
BufferQueue(u32 id, u64 layer_id);
|
||||
explicit BufferQueue(Kernel::KernelCore& kernel, u32 id, u64 layer_id);
|
||||
~BufferQueue();
|
||||
|
||||
enum class BufferTransformFlags : u32 {
|
||||
|
||||
@@ -83,7 +83,7 @@ std::optional<u64> NVFlinger::CreateLayer(u64 display_id) {
|
||||
|
||||
const u64 layer_id = next_layer_id++;
|
||||
const u32 buffer_queue_id = next_buffer_queue_id++;
|
||||
buffer_queues.emplace_back(buffer_queue_id, layer_id);
|
||||
buffer_queues.emplace_back(system.Kernel(), buffer_queue_id, layer_id);
|
||||
display->CreateLayer(layer_id, buffer_queues.back());
|
||||
return layer_id;
|
||||
}
|
||||
@@ -187,14 +187,18 @@ void NVFlinger::Compose() {
|
||||
MicroProfileFlip();
|
||||
|
||||
if (!buffer) {
|
||||
// There was no queued buffer to draw, render previous frame
|
||||
system.GetPerfStats().EndGameFrame();
|
||||
system.GPU().SwapBuffers({});
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto& igbp_buffer = buffer->get().igbp_buffer;
|
||||
|
||||
const auto& gpu = system.GPU();
|
||||
const auto& multi_fence = buffer->get().multi_fence;
|
||||
for (u32 fence_id = 0; fence_id < multi_fence.num_fences; fence_id++) {
|
||||
const auto& fence = multi_fence.fences[fence_id];
|
||||
gpu.WaitFence(fence.id, fence.value);
|
||||
}
|
||||
|
||||
// Now send the buffer to the GPU for drawing.
|
||||
// TODO(Subv): Support more than just disp0. The display device selection is probably based
|
||||
// on which display we're drawing (Default, Internal, External, etc)
|
||||
|
||||
@@ -22,7 +22,7 @@ constexpr u32 KEYPAD_BITMASK = 0x3FFFFFF;
|
||||
|
||||
StandardVmCallbacks::StandardVmCallbacks(const Core::System& system,
|
||||
const CheatProcessMetadata& metadata)
|
||||
: system(system), metadata(metadata) {}
|
||||
: metadata(metadata), system(system) {}
|
||||
|
||||
StandardVmCallbacks::~StandardVmCallbacks() = default;
|
||||
|
||||
@@ -176,9 +176,8 @@ std::vector<CheatEntry> TextCheatParser::Parse(const Core::System& system,
|
||||
|
||||
CheatEngine::CheatEngine(Core::System& system, std::vector<CheatEntry> cheats,
|
||||
const std::array<u8, 0x20>& build_id)
|
||||
: system{system}, core_timing{system.CoreTiming()}, vm{std::make_unique<StandardVmCallbacks>(
|
||||
system, metadata)},
|
||||
cheats(std::move(cheats)) {
|
||||
: vm{std::make_unique<StandardVmCallbacks>(system, metadata)},
|
||||
cheats(std::move(cheats)), core_timing{system.CoreTiming()}, system{system} {
|
||||
metadata.main_nso_build_id = build_id;
|
||||
}
|
||||
|
||||
|
||||
@@ -1133,8 +1133,8 @@ void DmntCheatVm::Execute(const CheatProcessMetadata& metadata) {
|
||||
case SaveRestoreRegisterOpType::ClearRegs:
|
||||
case SaveRestoreRegisterOpType::Restore:
|
||||
default:
|
||||
src = registers.data();
|
||||
dst = saved_values.data();
|
||||
src = saved_values.data();
|
||||
dst = registers.data();
|
||||
break;
|
||||
}
|
||||
for (std::size_t i = 0; i < NumRegisters; i++) {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <array>
|
||||
#include <bitset>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include "common/file_util.h"
|
||||
#include "core/core.h"
|
||||
@@ -13,7 +14,7 @@
|
||||
|
||||
// Numbers are chosen randomly to make sure the correct one is given.
|
||||
static constexpr std::array<u64, 5> CB_IDS{{42, 144, 93, 1026, UINT64_C(0xFFFF7FFFF7FFFF)}};
|
||||
static constexpr int MAX_SLICE_LENGTH = 20000; // Copied from CoreTiming internals
|
||||
static constexpr int MAX_SLICE_LENGTH = 10000; // Copied from CoreTiming internals
|
||||
|
||||
static std::bitset<CB_IDS.size()> callbacks_ran_flags;
|
||||
static u64 expected_callback = 0;
|
||||
@@ -28,6 +29,12 @@ void CallbackTemplate(u64 userdata, s64 cycles_late) {
|
||||
REQUIRE(lateness == cycles_late);
|
||||
}
|
||||
|
||||
static u64 callbacks_done = 0;
|
||||
|
||||
void EmptyCallback(u64 userdata, s64 cycles_late) {
|
||||
++callbacks_done;
|
||||
}
|
||||
|
||||
struct ScopeInit final {
|
||||
ScopeInit() {
|
||||
core_timing.Initialize();
|
||||
@@ -39,18 +46,19 @@ struct ScopeInit final {
|
||||
Core::Timing::CoreTiming core_timing;
|
||||
};
|
||||
|
||||
static void AdvanceAndCheck(Core::Timing::CoreTiming& core_timing, u32 idx, int downcount,
|
||||
static void AdvanceAndCheck(Core::Timing::CoreTiming& core_timing, u32 idx, u32 context = 0,
|
||||
int expected_lateness = 0, int cpu_downcount = 0) {
|
||||
callbacks_ran_flags = 0;
|
||||
expected_callback = CB_IDS[idx];
|
||||
lateness = expected_lateness;
|
||||
|
||||
// Pretend we executed X cycles of instructions.
|
||||
core_timing.SwitchContext(context);
|
||||
core_timing.AddTicks(core_timing.GetDowncount() - cpu_downcount);
|
||||
core_timing.Advance();
|
||||
core_timing.SwitchContext((context + 1) % 4);
|
||||
|
||||
REQUIRE(decltype(callbacks_ran_flags)().set(idx) == callbacks_ran_flags);
|
||||
REQUIRE(downcount == core_timing.GetDowncount());
|
||||
}
|
||||
|
||||
TEST_CASE("CoreTiming[BasicOrder]", "[core]") {
|
||||
@@ -64,9 +72,10 @@ TEST_CASE("CoreTiming[BasicOrder]", "[core]") {
|
||||
Core::Timing::EventType* cb_e = core_timing.RegisterEvent("callbackE", CallbackTemplate<4>);
|
||||
|
||||
// Enter slice 0
|
||||
core_timing.Advance();
|
||||
core_timing.ResetRun();
|
||||
|
||||
// D -> B -> C -> A -> E
|
||||
core_timing.SwitchContext(0);
|
||||
core_timing.ScheduleEvent(1000, cb_a, CB_IDS[0]);
|
||||
REQUIRE(1000 == core_timing.GetDowncount());
|
||||
core_timing.ScheduleEvent(500, cb_b, CB_IDS[1]);
|
||||
@@ -78,98 +87,46 @@ TEST_CASE("CoreTiming[BasicOrder]", "[core]") {
|
||||
core_timing.ScheduleEvent(1200, cb_e, CB_IDS[4]);
|
||||
REQUIRE(100 == core_timing.GetDowncount());
|
||||
|
||||
AdvanceAndCheck(core_timing, 3, 400);
|
||||
AdvanceAndCheck(core_timing, 1, 300);
|
||||
AdvanceAndCheck(core_timing, 2, 200);
|
||||
AdvanceAndCheck(core_timing, 0, 200);
|
||||
AdvanceAndCheck(core_timing, 4, MAX_SLICE_LENGTH);
|
||||
AdvanceAndCheck(core_timing, 3, 0);
|
||||
AdvanceAndCheck(core_timing, 1, 1);
|
||||
AdvanceAndCheck(core_timing, 2, 2);
|
||||
AdvanceAndCheck(core_timing, 0, 3);
|
||||
AdvanceAndCheck(core_timing, 4, 0);
|
||||
}
|
||||
|
||||
TEST_CASE("CoreTiming[Threadsave]", "[core]") {
|
||||
ScopeInit guard;
|
||||
auto& core_timing = guard.core_timing;
|
||||
|
||||
Core::Timing::EventType* cb_a = core_timing.RegisterEvent("callbackA", CallbackTemplate<0>);
|
||||
Core::Timing::EventType* cb_b = core_timing.RegisterEvent("callbackB", CallbackTemplate<1>);
|
||||
Core::Timing::EventType* cb_c = core_timing.RegisterEvent("callbackC", CallbackTemplate<2>);
|
||||
Core::Timing::EventType* cb_d = core_timing.RegisterEvent("callbackD", CallbackTemplate<3>);
|
||||
Core::Timing::EventType* cb_e = core_timing.RegisterEvent("callbackE", CallbackTemplate<4>);
|
||||
|
||||
// Enter slice 0
|
||||
core_timing.Advance();
|
||||
|
||||
// D -> B -> C -> A -> E
|
||||
core_timing.ScheduleEvent(1000, cb_a, CB_IDS[0]);
|
||||
// Manually force since ScheduleEvent doesn't call it
|
||||
core_timing.ForceExceptionCheck(1000);
|
||||
REQUIRE(1000 == core_timing.GetDowncount());
|
||||
core_timing.ScheduleEvent(500, cb_b, CB_IDS[1]);
|
||||
// Manually force since ScheduleEvent doesn't call it
|
||||
core_timing.ForceExceptionCheck(500);
|
||||
REQUIRE(500 == core_timing.GetDowncount());
|
||||
core_timing.ScheduleEvent(800, cb_c, CB_IDS[2]);
|
||||
// Manually force since ScheduleEvent doesn't call it
|
||||
core_timing.ForceExceptionCheck(800);
|
||||
REQUIRE(500 == core_timing.GetDowncount());
|
||||
core_timing.ScheduleEvent(100, cb_d, CB_IDS[3]);
|
||||
// Manually force since ScheduleEvent doesn't call it
|
||||
core_timing.ForceExceptionCheck(100);
|
||||
REQUIRE(100 == core_timing.GetDowncount());
|
||||
core_timing.ScheduleEvent(1200, cb_e, CB_IDS[4]);
|
||||
// Manually force since ScheduleEvent doesn't call it
|
||||
core_timing.ForceExceptionCheck(1200);
|
||||
REQUIRE(100 == core_timing.GetDowncount());
|
||||
|
||||
AdvanceAndCheck(core_timing, 3, 400);
|
||||
AdvanceAndCheck(core_timing, 1, 300);
|
||||
AdvanceAndCheck(core_timing, 2, 200);
|
||||
AdvanceAndCheck(core_timing, 0, 200);
|
||||
AdvanceAndCheck(core_timing, 4, MAX_SLICE_LENGTH);
|
||||
}
|
||||
|
||||
namespace SharedSlotTest {
|
||||
static unsigned int counter = 0;
|
||||
|
||||
template <unsigned int ID>
|
||||
void FifoCallback(u64 userdata, s64 cycles_late) {
|
||||
static_assert(ID < CB_IDS.size(), "ID out of range");
|
||||
callbacks_ran_flags.set(ID);
|
||||
REQUIRE(CB_IDS[ID] == userdata);
|
||||
REQUIRE(ID == counter);
|
||||
REQUIRE(lateness == cycles_late);
|
||||
++counter;
|
||||
}
|
||||
} // namespace SharedSlotTest
|
||||
|
||||
TEST_CASE("CoreTiming[SharedSlot]", "[core]") {
|
||||
using namespace SharedSlotTest;
|
||||
TEST_CASE("CoreTiming[FairSharing]", "[core]") {
|
||||
|
||||
ScopeInit guard;
|
||||
auto& core_timing = guard.core_timing;
|
||||
|
||||
Core::Timing::EventType* cb_a = core_timing.RegisterEvent("callbackA", FifoCallback<0>);
|
||||
Core::Timing::EventType* cb_b = core_timing.RegisterEvent("callbackB", FifoCallback<1>);
|
||||
Core::Timing::EventType* cb_c = core_timing.RegisterEvent("callbackC", FifoCallback<2>);
|
||||
Core::Timing::EventType* cb_d = core_timing.RegisterEvent("callbackD", FifoCallback<3>);
|
||||
Core::Timing::EventType* cb_e = core_timing.RegisterEvent("callbackE", FifoCallback<4>);
|
||||
Core::Timing::EventType* empty_callback =
|
||||
core_timing.RegisterEvent("empty_callback", EmptyCallback);
|
||||
|
||||
core_timing.ScheduleEvent(1000, cb_a, CB_IDS[0]);
|
||||
core_timing.ScheduleEvent(1000, cb_b, CB_IDS[1]);
|
||||
core_timing.ScheduleEvent(1000, cb_c, CB_IDS[2]);
|
||||
core_timing.ScheduleEvent(1000, cb_d, CB_IDS[3]);
|
||||
core_timing.ScheduleEvent(1000, cb_e, CB_IDS[4]);
|
||||
callbacks_done = 0;
|
||||
u64 MAX_CALLBACKS = 10;
|
||||
for (std::size_t i = 0; i < 10; i++) {
|
||||
core_timing.ScheduleEvent(i * 3333U, empty_callback, 0);
|
||||
}
|
||||
|
||||
// Enter slice 0
|
||||
core_timing.Advance();
|
||||
REQUIRE(1000 == core_timing.GetDowncount());
|
||||
const s64 advances = MAX_SLICE_LENGTH / 10;
|
||||
core_timing.ResetRun();
|
||||
u64 current_time = core_timing.GetTicks();
|
||||
bool keep_running{};
|
||||
do {
|
||||
keep_running = false;
|
||||
for (u32 active_core = 0; active_core < 4; ++active_core) {
|
||||
core_timing.SwitchContext(active_core);
|
||||
if (core_timing.CanCurrentContextRun()) {
|
||||
core_timing.AddTicks(std::min<s64>(advances, core_timing.GetDowncount()));
|
||||
core_timing.Advance();
|
||||
}
|
||||
keep_running |= core_timing.CanCurrentContextRun();
|
||||
}
|
||||
} while (keep_running);
|
||||
u64 current_time_2 = core_timing.GetTicks();
|
||||
|
||||
callbacks_ran_flags = 0;
|
||||
counter = 0;
|
||||
lateness = 0;
|
||||
core_timing.AddTicks(core_timing.GetDowncount());
|
||||
core_timing.Advance();
|
||||
REQUIRE(MAX_SLICE_LENGTH == core_timing.GetDowncount());
|
||||
REQUIRE(0x1FULL == callbacks_ran_flags.to_ullong());
|
||||
REQUIRE(MAX_CALLBACKS == callbacks_done);
|
||||
REQUIRE(current_time_2 == current_time + MAX_SLICE_LENGTH * 4);
|
||||
}
|
||||
|
||||
TEST_CASE("Core::Timing[PredictableLateness]", "[core]") {
|
||||
@@ -180,13 +137,13 @@ TEST_CASE("Core::Timing[PredictableLateness]", "[core]") {
|
||||
Core::Timing::EventType* cb_b = core_timing.RegisterEvent("callbackB", CallbackTemplate<1>);
|
||||
|
||||
// Enter slice 0
|
||||
core_timing.Advance();
|
||||
core_timing.ResetRun();
|
||||
|
||||
core_timing.ScheduleEvent(100, cb_a, CB_IDS[0]);
|
||||
core_timing.ScheduleEvent(200, cb_b, CB_IDS[1]);
|
||||
|
||||
AdvanceAndCheck(core_timing, 0, 90, 10, -10); // (100 - 10)
|
||||
AdvanceAndCheck(core_timing, 1, MAX_SLICE_LENGTH, 50, -50);
|
||||
AdvanceAndCheck(core_timing, 0, 0, 10, -10); // (100 - 10)
|
||||
AdvanceAndCheck(core_timing, 1, 1, 50, -50);
|
||||
}
|
||||
|
||||
namespace ChainSchedulingTest {
|
||||
@@ -220,7 +177,7 @@ TEST_CASE("CoreTiming[ChainScheduling]", "[core]") {
|
||||
});
|
||||
|
||||
// Enter slice 0
|
||||
core_timing.Advance();
|
||||
core_timing.ResetRun();
|
||||
|
||||
core_timing.ScheduleEvent(800, cb_a, CB_IDS[0]);
|
||||
core_timing.ScheduleEvent(1000, cb_b, CB_IDS[1]);
|
||||
@@ -229,19 +186,19 @@ TEST_CASE("CoreTiming[ChainScheduling]", "[core]") {
|
||||
REQUIRE(800 == core_timing.GetDowncount());
|
||||
|
||||
reschedules = 3;
|
||||
AdvanceAndCheck(core_timing, 0, 200); // cb_a
|
||||
AdvanceAndCheck(core_timing, 1, 1000); // cb_b, cb_rs
|
||||
AdvanceAndCheck(core_timing, 0, 0); // cb_a
|
||||
AdvanceAndCheck(core_timing, 1, 1); // cb_b, cb_rs
|
||||
REQUIRE(2 == reschedules);
|
||||
|
||||
core_timing.AddTicks(core_timing.GetDowncount());
|
||||
core_timing.Advance(); // cb_rs
|
||||
core_timing.SwitchContext(3);
|
||||
REQUIRE(1 == reschedules);
|
||||
REQUIRE(200 == core_timing.GetDowncount());
|
||||
|
||||
AdvanceAndCheck(core_timing, 2, 800); // cb_c
|
||||
AdvanceAndCheck(core_timing, 2, 3); // cb_c
|
||||
|
||||
core_timing.AddTicks(core_timing.GetDowncount());
|
||||
core_timing.Advance(); // cb_rs
|
||||
REQUIRE(0 == reschedules);
|
||||
REQUIRE(MAX_SLICE_LENGTH == core_timing.GetDowncount());
|
||||
}
|
||||
|
||||
@@ -101,7 +101,8 @@ void Maxwell3D::InitializeRegisterDefaults() {
|
||||
#define DIRTY_REGS_POS(field_name) (offsetof(Maxwell3D::DirtyRegs, field_name))
|
||||
|
||||
void Maxwell3D::InitDirtySettings() {
|
||||
const auto set_block = [this](const u32 start, const u32 range, const u8 position) {
|
||||
const auto set_block = [this](const std::size_t start, const std::size_t range,
|
||||
const u8 position) {
|
||||
const auto start_itr = dirty_pointers.begin() + start;
|
||||
const auto end_itr = start_itr + range;
|
||||
std::fill(start_itr, end_itr, position);
|
||||
@@ -478,7 +479,7 @@ void Maxwell3D::CallMethodFromMME(const GPU::MethodCall& method_call) {
|
||||
}
|
||||
|
||||
void Maxwell3D::FlushMMEInlineDraw() {
|
||||
LOG_DEBUG(HW_GPU, "called, topology={}, count={}", static_cast<u32>(regs.draw.topology.Value()),
|
||||
LOG_TRACE(HW_GPU, "called, topology={}, count={}", static_cast<u32>(regs.draw.topology.Value()),
|
||||
regs.vertex_buffer.count);
|
||||
ASSERT_MSG(!(regs.index_array.count && regs.vertex_buffer.count), "Both indexed and direct?");
|
||||
ASSERT(mme_draw.instance_count == mme_draw.gl_end_count);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/microprofile.h"
|
||||
#include "core/core.h"
|
||||
#include "core/core_timing.h"
|
||||
#include "core/memory.h"
|
||||
@@ -17,6 +18,8 @@
|
||||
|
||||
namespace Tegra {
|
||||
|
||||
MICROPROFILE_DEFINE(GPU_wait, "GPU", "Wait for the GPU", MP_RGB(128, 128, 192));
|
||||
|
||||
GPU::GPU(Core::System& system, VideoCore::RendererBase& renderer, bool is_async)
|
||||
: system{system}, renderer{renderer}, is_async{is_async} {
|
||||
auto& rasterizer{renderer.Rasterizer()};
|
||||
@@ -63,6 +66,16 @@ const DmaPusher& GPU::DmaPusher() const {
|
||||
return *dma_pusher;
|
||||
}
|
||||
|
||||
void GPU::WaitFence(u32 syncpoint_id, u32 value) const {
|
||||
// Synced GPU, is always in sync
|
||||
if (!is_async) {
|
||||
return;
|
||||
}
|
||||
MICROPROFILE_SCOPE(GPU_wait);
|
||||
while (syncpoints[syncpoint_id].load(std::memory_order_relaxed) < value) {
|
||||
}
|
||||
}
|
||||
|
||||
void GPU::IncrementSyncPoint(const u32 syncpoint_id) {
|
||||
syncpoints[syncpoint_id]++;
|
||||
std::lock_guard lock{sync_mutex};
|
||||
@@ -326,7 +339,7 @@ void GPU::ProcessSemaphoreTriggerMethod() {
|
||||
block.sequence = regs.semaphore_sequence;
|
||||
// TODO(Kmather73): Generate a real GPU timestamp and write it here instead of
|
||||
// CoreTiming
|
||||
block.timestamp = Core::System::GetInstance().CoreTiming().GetTicks();
|
||||
block.timestamp = system.CoreTiming().GetTicks();
|
||||
memory_manager->WriteBlock(regs.semaphore_address.SemaphoreAddress(), &block,
|
||||
sizeof(block));
|
||||
} else {
|
||||
|
||||
@@ -177,6 +177,12 @@ public:
|
||||
/// Returns a reference to the GPU DMA pusher.
|
||||
Tegra::DmaPusher& DmaPusher();
|
||||
|
||||
// Waits for the GPU to finish working
|
||||
virtual void WaitIdle() const = 0;
|
||||
|
||||
/// Allows the CPU/NvFlinger to wait on the GPU before presenting a frame.
|
||||
void WaitFence(u32 syncpoint_id, u32 value) const;
|
||||
|
||||
void IncrementSyncPoint(u32 syncpoint_id);
|
||||
|
||||
u32 GetSyncpointValue(u32 syncpoint_id) const;
|
||||
|
||||
@@ -44,4 +44,8 @@ void GPUAsynch::TriggerCpuInterrupt(const u32 syncpoint_id, const u32 value) con
|
||||
interrupt_manager.GPUInterruptSyncpt(syncpoint_id, value);
|
||||
}
|
||||
|
||||
void GPUAsynch::WaitIdle() const {
|
||||
gpu_thread.WaitIdle();
|
||||
}
|
||||
|
||||
} // namespace VideoCommon
|
||||
|
||||
@@ -25,6 +25,7 @@ public:
|
||||
void FlushRegion(CacheAddr addr, u64 size) override;
|
||||
void InvalidateRegion(CacheAddr addr, u64 size) override;
|
||||
void FlushAndInvalidateRegion(CacheAddr addr, u64 size) override;
|
||||
void WaitIdle() const override;
|
||||
|
||||
protected:
|
||||
void TriggerCpuInterrupt(u32 syncpoint_id, u32 value) const override;
|
||||
|
||||
@@ -24,6 +24,7 @@ public:
|
||||
void FlushRegion(CacheAddr addr, u64 size) override;
|
||||
void InvalidateRegion(CacheAddr addr, u64 size) override;
|
||||
void FlushAndInvalidateRegion(CacheAddr addr, u64 size) override;
|
||||
void WaitIdle() const override {}
|
||||
|
||||
protected:
|
||||
void TriggerCpuInterrupt([[maybe_unused]] u32 syncpoint_id,
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
#include "common/assert.h"
|
||||
#include "common/microprofile.h"
|
||||
#include "core/core.h"
|
||||
#include "core/core_timing.h"
|
||||
#include "core/core_timing_util.h"
|
||||
#include "core/frontend/scope_acquire_window_context.h"
|
||||
#include "video_core/dma_pusher.h"
|
||||
#include "video_core/gpu.h"
|
||||
@@ -68,14 +66,10 @@ ThreadManager::~ThreadManager() {
|
||||
|
||||
void ThreadManager::StartThread(VideoCore::RendererBase& renderer, Tegra::DmaPusher& dma_pusher) {
|
||||
thread = std::thread{RunThread, std::ref(renderer), std::ref(dma_pusher), std::ref(state)};
|
||||
synchronization_event = system.CoreTiming().RegisterEvent(
|
||||
"GPUThreadSynch", [this](u64 fence, s64) { state.WaitForSynchronization(fence); });
|
||||
}
|
||||
|
||||
void ThreadManager::SubmitList(Tegra::CommandList&& entries) {
|
||||
const u64 fence{PushCommand(SubmitListCommand(std::move(entries)))};
|
||||
const s64 synchronization_ticks{Core::Timing::usToCycles(std::chrono::microseconds{9000})};
|
||||
system.CoreTiming().ScheduleEvent(synchronization_ticks, synchronization_event, fence);
|
||||
PushCommand(SubmitListCommand(std::move(entries)));
|
||||
}
|
||||
|
||||
void ThreadManager::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) {
|
||||
@@ -96,16 +90,15 @@ void ThreadManager::FlushAndInvalidateRegion(CacheAddr addr, u64 size) {
|
||||
InvalidateRegion(addr, size);
|
||||
}
|
||||
|
||||
void ThreadManager::WaitIdle() const {
|
||||
while (state.last_fence > state.signaled_fence.load(std::memory_order_relaxed)) {
|
||||
}
|
||||
}
|
||||
|
||||
u64 ThreadManager::PushCommand(CommandData&& command_data) {
|
||||
const u64 fence{++state.last_fence};
|
||||
state.queue.Push(CommandDataContainer(std::move(command_data), fence));
|
||||
return fence;
|
||||
}
|
||||
|
||||
MICROPROFILE_DEFINE(GPU_wait, "GPU", "Wait for the GPU", MP_RGB(128, 128, 192));
|
||||
void SynchState::WaitForSynchronization(u64 fence) {
|
||||
while (signaled_fence.load() < fence)
|
||||
;
|
||||
}
|
||||
|
||||
} // namespace VideoCommon::GPUThread
|
||||
|
||||
@@ -21,9 +21,6 @@ class DmaPusher;
|
||||
|
||||
namespace Core {
|
||||
class System;
|
||||
namespace Timing {
|
||||
struct EventType;
|
||||
} // namespace Timing
|
||||
} // namespace Core
|
||||
|
||||
namespace VideoCommon::GPUThread {
|
||||
@@ -89,8 +86,6 @@ struct CommandDataContainer {
|
||||
struct SynchState final {
|
||||
std::atomic_bool is_running{true};
|
||||
|
||||
void WaitForSynchronization(u64 fence);
|
||||
|
||||
using CommandQueue = Common::SPSCQueue<CommandDataContainer>;
|
||||
CommandQueue queue;
|
||||
u64 last_fence{};
|
||||
@@ -121,6 +116,9 @@ public:
|
||||
/// Notify rasterizer that any caches of the specified region should be flushed and invalidated
|
||||
void FlushAndInvalidateRegion(CacheAddr addr, u64 size);
|
||||
|
||||
// Wait until the gpu thread is idle.
|
||||
void WaitIdle() const;
|
||||
|
||||
private:
|
||||
/// Pushes a command to be executed by the GPU thread
|
||||
u64 PushCommand(CommandData&& command_data);
|
||||
@@ -128,7 +126,6 @@ private:
|
||||
private:
|
||||
SynchState state;
|
||||
Core::System& system;
|
||||
Core::Timing::EventType* synchronization_event{};
|
||||
std::thread thread;
|
||||
std::thread::id thread_id;
|
||||
};
|
||||
|
||||
@@ -11,6 +11,77 @@
|
||||
MICROPROFILE_DEFINE(MacroInterp, "GPU", "Execute macro interpreter", MP_RGB(128, 128, 192));
|
||||
|
||||
namespace Tegra {
|
||||
namespace {
|
||||
enum class Operation : u32 {
|
||||
ALU = 0,
|
||||
AddImmediate = 1,
|
||||
ExtractInsert = 2,
|
||||
ExtractShiftLeftImmediate = 3,
|
||||
ExtractShiftLeftRegister = 4,
|
||||
Read = 5,
|
||||
Unused = 6, // This operation doesn't seem to be a valid encoding.
|
||||
Branch = 7,
|
||||
};
|
||||
} // Anonymous namespace
|
||||
|
||||
enum class MacroInterpreter::ALUOperation : u32 {
|
||||
Add = 0,
|
||||
AddWithCarry = 1,
|
||||
Subtract = 2,
|
||||
SubtractWithBorrow = 3,
|
||||
// Operations 4-7 don't seem to be valid encodings.
|
||||
Xor = 8,
|
||||
Or = 9,
|
||||
And = 10,
|
||||
AndNot = 11,
|
||||
Nand = 12
|
||||
};
|
||||
|
||||
enum class MacroInterpreter::ResultOperation : u32 {
|
||||
IgnoreAndFetch = 0,
|
||||
Move = 1,
|
||||
MoveAndSetMethod = 2,
|
||||
FetchAndSend = 3,
|
||||
MoveAndSend = 4,
|
||||
FetchAndSetMethod = 5,
|
||||
MoveAndSetMethodFetchAndSend = 6,
|
||||
MoveAndSetMethodSend = 7
|
||||
};
|
||||
|
||||
enum class MacroInterpreter::BranchCondition : u32 {
|
||||
Zero = 0,
|
||||
NotZero = 1,
|
||||
};
|
||||
|
||||
union MacroInterpreter::Opcode {
|
||||
u32 raw;
|
||||
BitField<0, 3, Operation> operation;
|
||||
BitField<4, 3, ResultOperation> result_operation;
|
||||
BitField<4, 1, BranchCondition> branch_condition;
|
||||
// If set on a branch, then the branch doesn't have a delay slot.
|
||||
BitField<5, 1, u32> branch_annul;
|
||||
BitField<7, 1, u32> is_exit;
|
||||
BitField<8, 3, u32> dst;
|
||||
BitField<11, 3, u32> src_a;
|
||||
BitField<14, 3, u32> src_b;
|
||||
// The signed immediate overlaps the second source operand and the alu operation.
|
||||
BitField<14, 18, s32> immediate;
|
||||
|
||||
BitField<17, 5, ALUOperation> alu_operation;
|
||||
|
||||
// Bitfield instructions data
|
||||
BitField<17, 5, u32> bf_src_bit;
|
||||
BitField<22, 5, u32> bf_size;
|
||||
BitField<27, 5, u32> bf_dst_bit;
|
||||
|
||||
u32 GetBitfieldMask() const {
|
||||
return (1 << bf_size) - 1;
|
||||
}
|
||||
|
||||
s32 GetBranchTarget() const {
|
||||
return static_cast<s32>(immediate * sizeof(u32));
|
||||
}
|
||||
};
|
||||
|
||||
MacroInterpreter::MacroInterpreter(Engines::Maxwell3D& maxwell3d) : maxwell3d(maxwell3d) {}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#include <array>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "common/bit_field.h"
|
||||
#include "common/common_types.h"
|
||||
@@ -28,75 +27,11 @@ public:
|
||||
void Execute(u32 offset, std::size_t num_parameters, const u32* parameters);
|
||||
|
||||
private:
|
||||
enum class Operation : u32 {
|
||||
ALU = 0,
|
||||
AddImmediate = 1,
|
||||
ExtractInsert = 2,
|
||||
ExtractShiftLeftImmediate = 3,
|
||||
ExtractShiftLeftRegister = 4,
|
||||
Read = 5,
|
||||
Unused = 6, // This operation doesn't seem to be a valid encoding.
|
||||
Branch = 7,
|
||||
};
|
||||
enum class ALUOperation : u32;
|
||||
enum class BranchCondition : u32;
|
||||
enum class ResultOperation : u32;
|
||||
|
||||
enum class ALUOperation : u32 {
|
||||
Add = 0,
|
||||
AddWithCarry = 1,
|
||||
Subtract = 2,
|
||||
SubtractWithBorrow = 3,
|
||||
// Operations 4-7 don't seem to be valid encodings.
|
||||
Xor = 8,
|
||||
Or = 9,
|
||||
And = 10,
|
||||
AndNot = 11,
|
||||
Nand = 12
|
||||
};
|
||||
|
||||
enum class ResultOperation : u32 {
|
||||
IgnoreAndFetch = 0,
|
||||
Move = 1,
|
||||
MoveAndSetMethod = 2,
|
||||
FetchAndSend = 3,
|
||||
MoveAndSend = 4,
|
||||
FetchAndSetMethod = 5,
|
||||
MoveAndSetMethodFetchAndSend = 6,
|
||||
MoveAndSetMethodSend = 7
|
||||
};
|
||||
|
||||
enum class BranchCondition : u32 {
|
||||
Zero = 0,
|
||||
NotZero = 1,
|
||||
};
|
||||
|
||||
union Opcode {
|
||||
u32 raw;
|
||||
BitField<0, 3, Operation> operation;
|
||||
BitField<4, 3, ResultOperation> result_operation;
|
||||
BitField<4, 1, BranchCondition> branch_condition;
|
||||
BitField<5, 1, u32>
|
||||
branch_annul; // If set on a branch, then the branch doesn't have a delay slot.
|
||||
BitField<7, 1, u32> is_exit;
|
||||
BitField<8, 3, u32> dst;
|
||||
BitField<11, 3, u32> src_a;
|
||||
BitField<14, 3, u32> src_b;
|
||||
// The signed immediate overlaps the second source operand and the alu operation.
|
||||
BitField<14, 18, s32> immediate;
|
||||
|
||||
BitField<17, 5, ALUOperation> alu_operation;
|
||||
|
||||
// Bitfield instructions data
|
||||
BitField<17, 5, u32> bf_src_bit;
|
||||
BitField<22, 5, u32> bf_size;
|
||||
BitField<27, 5, u32> bf_dst_bit;
|
||||
|
||||
u32 GetBitfieldMask() const {
|
||||
return (1 << bf_size) - 1;
|
||||
}
|
||||
|
||||
s32 GetBranchTarget() const {
|
||||
return static_cast<s32>(immediate * sizeof(u32));
|
||||
}
|
||||
};
|
||||
union Opcode;
|
||||
|
||||
union MethodAddress {
|
||||
u32 raw;
|
||||
@@ -149,9 +84,10 @@ private:
|
||||
|
||||
Engines::Maxwell3D& maxwell3d;
|
||||
|
||||
u32 pc; ///< Current program counter
|
||||
std::optional<u32>
|
||||
delayed_pc; ///< Program counter to execute at after the delay slot is executed.
|
||||
/// Current program counter
|
||||
u32 pc;
|
||||
/// Program counter to execute at after the delay slot is executed.
|
||||
std::optional<u32> delayed_pc;
|
||||
|
||||
static constexpr std::size_t NumMacroRegisters = 8;
|
||||
|
||||
|
||||
@@ -93,6 +93,7 @@ static constexpr ConversionArray morton_to_linear_fns = {
|
||||
MortonCopy<true, PixelFormat::DXT23_SRGB>,
|
||||
MortonCopy<true, PixelFormat::DXT45_SRGB>,
|
||||
MortonCopy<true, PixelFormat::BC7U_SRGB>,
|
||||
MortonCopy<true, PixelFormat::R4G4B4A4U>,
|
||||
MortonCopy<true, PixelFormat::ASTC_2D_4X4_SRGB>,
|
||||
MortonCopy<true, PixelFormat::ASTC_2D_8X8_SRGB>,
|
||||
MortonCopy<true, PixelFormat::ASTC_2D_8X5_SRGB>,
|
||||
@@ -101,6 +102,16 @@ static constexpr ConversionArray morton_to_linear_fns = {
|
||||
MortonCopy<true, PixelFormat::ASTC_2D_5X5_SRGB>,
|
||||
MortonCopy<true, PixelFormat::ASTC_2D_10X8>,
|
||||
MortonCopy<true, PixelFormat::ASTC_2D_10X8_SRGB>,
|
||||
MortonCopy<true, PixelFormat::ASTC_2D_6X6>,
|
||||
MortonCopy<true, PixelFormat::ASTC_2D_6X6_SRGB>,
|
||||
MortonCopy<true, PixelFormat::ASTC_2D_10X10>,
|
||||
MortonCopy<true, PixelFormat::ASTC_2D_10X10_SRGB>,
|
||||
MortonCopy<true, PixelFormat::ASTC_2D_12X12>,
|
||||
MortonCopy<true, PixelFormat::ASTC_2D_12X12_SRGB>,
|
||||
MortonCopy<true, PixelFormat::ASTC_2D_8X6>,
|
||||
MortonCopy<true, PixelFormat::ASTC_2D_8X6_SRGB>,
|
||||
MortonCopy<true, PixelFormat::ASTC_2D_6X5>,
|
||||
MortonCopy<true, PixelFormat::ASTC_2D_6X5_SRGB>,
|
||||
MortonCopy<true, PixelFormat::Z32F>,
|
||||
MortonCopy<true, PixelFormat::Z16>,
|
||||
MortonCopy<true, PixelFormat::Z24S8>,
|
||||
@@ -162,6 +173,17 @@ static constexpr ConversionArray linear_to_morton_fns = {
|
||||
MortonCopy<false, PixelFormat::DXT23_SRGB>,
|
||||
MortonCopy<false, PixelFormat::DXT45_SRGB>,
|
||||
MortonCopy<false, PixelFormat::BC7U_SRGB>,
|
||||
MortonCopy<false, PixelFormat::R4G4B4A4U>,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
|
||||
@@ -348,6 +348,7 @@ static constexpr auto RangeFromInterval(Map& map, const Interval& interval) {
|
||||
}
|
||||
|
||||
void RasterizerOpenGL::UpdatePagesCachedCount(VAddr addr, u64 size, int delta) {
|
||||
std::lock_guard lock{pages_mutex};
|
||||
const u64 page_start{addr >> Memory::PAGE_BITS};
|
||||
const u64 page_end{(addr + size + Memory::PAGE_SIZE - 1) >> Memory::PAGE_BITS};
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <cstddef>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
@@ -230,6 +231,8 @@ private:
|
||||
|
||||
using CachedPageMap = boost::icl::interval_map<u64, int>;
|
||||
CachedPageMap cached_pages;
|
||||
|
||||
std::mutex pages_mutex;
|
||||
};
|
||||
|
||||
} // namespace OpenGL
|
||||
|
||||
@@ -1148,7 +1148,7 @@ private:
|
||||
for (const auto& variant : extras) {
|
||||
if (const auto argument = std::get_if<TextureArgument>(&variant)) {
|
||||
expr += GenerateTextureArgument(*argument);
|
||||
} else if (std::get_if<TextureAoffi>(&variant)) {
|
||||
} else if (std::holds_alternative<TextureAoffi>(variant)) {
|
||||
expr += GenerateTextureAoffi(meta->aoffi);
|
||||
} else {
|
||||
UNREACHABLE();
|
||||
@@ -1158,8 +1158,8 @@ private:
|
||||
return expr + ')';
|
||||
}
|
||||
|
||||
std::string GenerateTextureArgument(TextureArgument argument) {
|
||||
const auto [type, operand] = argument;
|
||||
std::string GenerateTextureArgument(const TextureArgument& argument) {
|
||||
const auto& [type, operand] = argument;
|
||||
if (operand == nullptr) {
|
||||
return {};
|
||||
}
|
||||
@@ -1235,7 +1235,7 @@ private:
|
||||
|
||||
std::string BuildImageValues(Operation operation) {
|
||||
constexpr std::array constructors{"uint", "uvec2", "uvec3", "uvec4"};
|
||||
const auto meta{std::get<MetaImage>(operation.GetMeta())};
|
||||
const auto& meta{std::get<MetaImage>(operation.GetMeta())};
|
||||
|
||||
const std::size_t values_count{meta.values.size()};
|
||||
std::string expr = fmt::format("{}(", constructors.at(values_count - 1));
|
||||
@@ -1780,14 +1780,14 @@ private:
|
||||
return {"0", Type::Int};
|
||||
}
|
||||
|
||||
const auto meta{std::get<MetaImage>(operation.GetMeta())};
|
||||
const auto& meta{std::get<MetaImage>(operation.GetMeta())};
|
||||
return {fmt::format("imageLoad({}, {}){}", GetImage(meta.image),
|
||||
BuildIntegerCoordinates(operation), GetSwizzle(meta.element)),
|
||||
Type::Uint};
|
||||
}
|
||||
|
||||
Expression ImageStore(Operation operation) {
|
||||
const auto meta{std::get<MetaImage>(operation.GetMeta())};
|
||||
const auto& meta{std::get<MetaImage>(operation.GetMeta())};
|
||||
code.AddLine("imageStore({}, {}, {});", GetImage(meta.image),
|
||||
BuildIntegerCoordinates(operation), BuildImageValues(operation));
|
||||
return {};
|
||||
@@ -1795,7 +1795,7 @@ private:
|
||||
|
||||
template <const std::string_view& opname>
|
||||
Expression AtomicImage(Operation operation) {
|
||||
const auto meta{std::get<MetaImage>(operation.GetMeta())};
|
||||
const auto& meta{std::get<MetaImage>(operation.GetMeta())};
|
||||
ASSERT(meta.values.size() == 1);
|
||||
|
||||
return {fmt::format("imageAtomic{}({}, {}, {})", opname, GetImage(meta.image),
|
||||
@@ -2246,7 +2246,7 @@ private:
|
||||
code.AddLine("#ifdef SAMPLER_{}_IS_BUFFER", sampler.GetIndex());
|
||||
}
|
||||
|
||||
std::string GetDeclarationWithSuffix(u32 index, const std::string& name) const {
|
||||
std::string GetDeclarationWithSuffix(u32 index, std::string_view name) const {
|
||||
return fmt::format("{}_{}_{}", name, index, suffix);
|
||||
}
|
||||
|
||||
@@ -2271,17 +2271,15 @@ private:
|
||||
ShaderWriter code;
|
||||
};
|
||||
|
||||
static constexpr std::string_view flow_var = "flow_var_";
|
||||
|
||||
std::string GetFlowVariable(u32 i) {
|
||||
return fmt::format("{}{}", flow_var, i);
|
||||
return fmt::format("flow_var_{}", i);
|
||||
}
|
||||
|
||||
class ExprDecompiler {
|
||||
public:
|
||||
explicit ExprDecompiler(GLSLDecompiler& decomp) : decomp{decomp} {}
|
||||
|
||||
void operator()(VideoCommon::Shader::ExprAnd& expr) {
|
||||
void operator()(const ExprAnd& expr) {
|
||||
inner += "( ";
|
||||
std::visit(*this, *expr.operand1);
|
||||
inner += " && ";
|
||||
@@ -2289,7 +2287,7 @@ public:
|
||||
inner += ')';
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ExprOr& expr) {
|
||||
void operator()(const ExprOr& expr) {
|
||||
inner += "( ";
|
||||
std::visit(*this, *expr.operand1);
|
||||
inner += " || ";
|
||||
@@ -2297,17 +2295,17 @@ public:
|
||||
inner += ')';
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ExprNot& expr) {
|
||||
void operator()(const ExprNot& expr) {
|
||||
inner += '!';
|
||||
std::visit(*this, *expr.operand1);
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ExprPredicate& expr) {
|
||||
void operator()(const ExprPredicate& expr) {
|
||||
const auto pred = static_cast<Tegra::Shader::Pred>(expr.predicate);
|
||||
inner += decomp.GetPredicate(pred);
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ExprCondCode& expr) {
|
||||
void operator()(const ExprCondCode& expr) {
|
||||
const Node cc = decomp.ir.GetConditionCode(expr.cc);
|
||||
std::string target;
|
||||
|
||||
@@ -2329,15 +2327,15 @@ public:
|
||||
inner += target;
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ExprVar& expr) {
|
||||
void operator()(const ExprVar& expr) {
|
||||
inner += GetFlowVariable(expr.var_index);
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ExprBoolean& expr) {
|
||||
void operator()(const ExprBoolean& expr) {
|
||||
inner += expr.value ? "true" : "false";
|
||||
}
|
||||
|
||||
std::string& GetResult() {
|
||||
const std::string& GetResult() const {
|
||||
return inner;
|
||||
}
|
||||
|
||||
@@ -2350,7 +2348,7 @@ class ASTDecompiler {
|
||||
public:
|
||||
explicit ASTDecompiler(GLSLDecompiler& decomp) : decomp{decomp} {}
|
||||
|
||||
void operator()(VideoCommon::Shader::ASTProgram& ast) {
|
||||
void operator()(const ASTProgram& ast) {
|
||||
ASTNode current = ast.nodes.GetFirst();
|
||||
while (current) {
|
||||
Visit(current);
|
||||
@@ -2358,7 +2356,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ASTIfThen& ast) {
|
||||
void operator()(const ASTIfThen& ast) {
|
||||
ExprDecompiler expr_parser{decomp};
|
||||
std::visit(expr_parser, *ast.condition);
|
||||
decomp.code.AddLine("if ({}) {{", expr_parser.GetResult());
|
||||
@@ -2372,7 +2370,7 @@ public:
|
||||
decomp.code.AddLine("}}");
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ASTIfElse& ast) {
|
||||
void operator()(const ASTIfElse& ast) {
|
||||
decomp.code.AddLine("else {{");
|
||||
decomp.code.scope++;
|
||||
ASTNode current = ast.nodes.GetFirst();
|
||||
@@ -2384,29 +2382,29 @@ public:
|
||||
decomp.code.AddLine("}}");
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ASTBlockEncoded& ast) {
|
||||
void operator()([[maybe_unused]] const ASTBlockEncoded& ast) {
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ASTBlockDecoded& ast) {
|
||||
void operator()(const ASTBlockDecoded& ast) {
|
||||
decomp.VisitBlock(ast.nodes);
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ASTVarSet& ast) {
|
||||
void operator()(const ASTVarSet& ast) {
|
||||
ExprDecompiler expr_parser{decomp};
|
||||
std::visit(expr_parser, *ast.condition);
|
||||
decomp.code.AddLine("{} = {};", GetFlowVariable(ast.index), expr_parser.GetResult());
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ASTLabel& ast) {
|
||||
void operator()(const ASTLabel& ast) {
|
||||
decomp.code.AddLine("// Label_{}:", ast.index);
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ASTGoto& ast) {
|
||||
void operator()([[maybe_unused]] const ASTGoto& ast) {
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ASTDoWhile& ast) {
|
||||
void operator()(const ASTDoWhile& ast) {
|
||||
ExprDecompiler expr_parser{decomp};
|
||||
std::visit(expr_parser, *ast.condition);
|
||||
decomp.code.AddLine("do {{");
|
||||
@@ -2420,7 +2418,7 @@ public:
|
||||
decomp.code.AddLine("}} while({});", expr_parser.GetResult());
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ASTReturn& ast) {
|
||||
void operator()(const ASTReturn& ast) {
|
||||
const bool is_true = VideoCommon::Shader::ExprIsTrue(ast.condition);
|
||||
if (!is_true) {
|
||||
ExprDecompiler expr_parser{decomp};
|
||||
@@ -2440,7 +2438,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ASTBreak& ast) {
|
||||
void operator()(const ASTBreak& ast) {
|
||||
const bool is_true = VideoCommon::Shader::ExprIsTrue(ast.condition);
|
||||
if (!is_true) {
|
||||
ExprDecompiler expr_parser{decomp};
|
||||
@@ -2455,7 +2453,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void Visit(VideoCommon::Shader::ASTNode& node) {
|
||||
void Visit(const ASTNode& node) {
|
||||
std::visit(*this, *node->GetInnerData());
|
||||
}
|
||||
|
||||
@@ -2468,9 +2466,9 @@ void GLSLDecompiler::DecompileAST() {
|
||||
for (u32 i = 0; i < num_flow_variables; i++) {
|
||||
code.AddLine("bool {} = false;", GetFlowVariable(i));
|
||||
}
|
||||
|
||||
ASTDecompiler decompiler{*this};
|
||||
VideoCommon::Shader::ASTNode program = ir.GetASTProgram();
|
||||
decompiler.Visit(program);
|
||||
decompiler.Visit(ir.GetASTProgram());
|
||||
}
|
||||
|
||||
} // Anonymous namespace
|
||||
|
||||
@@ -111,7 +111,8 @@ constexpr std::array<FormatTuple, VideoCore::Surface::MaxPixelFormat> tex_format
|
||||
{GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, ComponentType::UNorm,
|
||||
true}, // DXT45_SRGB
|
||||
{GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, ComponentType::UNorm,
|
||||
true}, // BC7U_SRGB
|
||||
true}, // BC7U_SRGB
|
||||
{GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4_REV, ComponentType::UNorm, false}, // R4G4B4A4U
|
||||
{GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_4X4_SRGB
|
||||
{GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_8X8_SRGB
|
||||
{GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_8X5_SRGB
|
||||
@@ -120,6 +121,16 @@ constexpr std::array<FormatTuple, VideoCore::Surface::MaxPixelFormat> tex_format
|
||||
{GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_5X5_SRGB
|
||||
{GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_10X8
|
||||
{GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_10X8_SRGB
|
||||
{GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_6X6
|
||||
{GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_6X6_SRGB
|
||||
{GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_10X10
|
||||
{GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_10X10_SRGB
|
||||
{GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_12X12
|
||||
{GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_12X12_SRGB
|
||||
{GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_8X6
|
||||
{GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_8X6_SRGB
|
||||
{GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_6X5
|
||||
{GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_6X5_SRGB
|
||||
|
||||
// Depth formats
|
||||
{GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT, ComponentType::Float, false}, // Z32F
|
||||
|
||||
@@ -102,8 +102,6 @@ RendererOpenGL::RendererOpenGL(Core::Frontend::EmuWindow& emu_window, Core::Syst
|
||||
RendererOpenGL::~RendererOpenGL() = default;
|
||||
|
||||
void RendererOpenGL::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) {
|
||||
system.GetPerfStats().EndSystemFrame();
|
||||
|
||||
// Maintain the rasterizer's state as a priority
|
||||
OpenGLState prev_state = OpenGLState::GetCurState();
|
||||
state.AllDirty();
|
||||
@@ -135,9 +133,6 @@ void RendererOpenGL::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) {
|
||||
|
||||
render_window.PollEvents();
|
||||
|
||||
system.FrameLimiter().DoFrameLimiting(system.CoreTiming().GetGlobalTimeUs());
|
||||
system.GetPerfStats().BeginSystemFrame();
|
||||
|
||||
// Restore the rasterizer state
|
||||
prev_state.AllDirty();
|
||||
prev_state.Apply();
|
||||
|
||||
@@ -1648,32 +1648,32 @@ class ExprDecompiler {
|
||||
public:
|
||||
explicit ExprDecompiler(SPIRVDecompiler& decomp) : decomp{decomp} {}
|
||||
|
||||
Id operator()(VideoCommon::Shader::ExprAnd& expr) {
|
||||
Id operator()(const ExprAnd& expr) {
|
||||
const Id type_def = decomp.GetTypeDefinition(Type::Bool);
|
||||
const Id op1 = Visit(expr.operand1);
|
||||
const Id op2 = Visit(expr.operand2);
|
||||
return decomp.Emit(decomp.OpLogicalAnd(type_def, op1, op2));
|
||||
}
|
||||
|
||||
Id operator()(VideoCommon::Shader::ExprOr& expr) {
|
||||
Id operator()(const ExprOr& expr) {
|
||||
const Id type_def = decomp.GetTypeDefinition(Type::Bool);
|
||||
const Id op1 = Visit(expr.operand1);
|
||||
const Id op2 = Visit(expr.operand2);
|
||||
return decomp.Emit(decomp.OpLogicalOr(type_def, op1, op2));
|
||||
}
|
||||
|
||||
Id operator()(VideoCommon::Shader::ExprNot& expr) {
|
||||
Id operator()(const ExprNot& expr) {
|
||||
const Id type_def = decomp.GetTypeDefinition(Type::Bool);
|
||||
const Id op1 = Visit(expr.operand1);
|
||||
return decomp.Emit(decomp.OpLogicalNot(type_def, op1));
|
||||
}
|
||||
|
||||
Id operator()(VideoCommon::Shader::ExprPredicate& expr) {
|
||||
Id operator()(const ExprPredicate& expr) {
|
||||
const auto pred = static_cast<Tegra::Shader::Pred>(expr.predicate);
|
||||
return decomp.Emit(decomp.OpLoad(decomp.t_bool, decomp.predicates.at(pred)));
|
||||
}
|
||||
|
||||
Id operator()(VideoCommon::Shader::ExprCondCode& expr) {
|
||||
Id operator()(const ExprCondCode& expr) {
|
||||
const Node cc = decomp.ir.GetConditionCode(expr.cc);
|
||||
Id target;
|
||||
|
||||
@@ -1693,15 +1693,15 @@ public:
|
||||
return decomp.Emit(decomp.OpLoad(decomp.t_bool, target));
|
||||
}
|
||||
|
||||
Id operator()(VideoCommon::Shader::ExprVar& expr) {
|
||||
Id operator()(const ExprVar& expr) {
|
||||
return decomp.Emit(decomp.OpLoad(decomp.t_bool, decomp.flow_variables.at(expr.var_index)));
|
||||
}
|
||||
|
||||
Id operator()(VideoCommon::Shader::ExprBoolean& expr) {
|
||||
Id operator()(const ExprBoolean& expr) {
|
||||
return expr.value ? decomp.v_true : decomp.v_false;
|
||||
}
|
||||
|
||||
Id Visit(VideoCommon::Shader::Expr& node) {
|
||||
Id Visit(const Expr& node) {
|
||||
return std::visit(*this, *node);
|
||||
}
|
||||
|
||||
@@ -1713,7 +1713,7 @@ class ASTDecompiler {
|
||||
public:
|
||||
explicit ASTDecompiler(SPIRVDecompiler& decomp) : decomp{decomp} {}
|
||||
|
||||
void operator()(VideoCommon::Shader::ASTProgram& ast) {
|
||||
void operator()(const ASTProgram& ast) {
|
||||
ASTNode current = ast.nodes.GetFirst();
|
||||
while (current) {
|
||||
Visit(current);
|
||||
@@ -1721,7 +1721,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ASTIfThen& ast) {
|
||||
void operator()(const ASTIfThen& ast) {
|
||||
ExprDecompiler expr_parser{decomp};
|
||||
const Id condition = expr_parser.Visit(ast.condition);
|
||||
const Id then_label = decomp.OpLabel();
|
||||
@@ -1738,33 +1738,33 @@ public:
|
||||
decomp.Emit(endif_label);
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ASTIfElse& ast) {
|
||||
void operator()([[maybe_unused]] const ASTIfElse& ast) {
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ASTBlockEncoded& ast) {
|
||||
void operator()([[maybe_unused]] const ASTBlockEncoded& ast) {
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ASTBlockDecoded& ast) {
|
||||
void operator()(const ASTBlockDecoded& ast) {
|
||||
decomp.VisitBasicBlock(ast.nodes);
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ASTVarSet& ast) {
|
||||
void operator()(const ASTVarSet& ast) {
|
||||
ExprDecompiler expr_parser{decomp};
|
||||
const Id condition = expr_parser.Visit(ast.condition);
|
||||
decomp.Emit(decomp.OpStore(decomp.flow_variables.at(ast.index), condition));
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ASTLabel& ast) {
|
||||
void operator()([[maybe_unused]] const ASTLabel& ast) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ASTGoto& ast) {
|
||||
void operator()([[maybe_unused]] const ASTGoto& ast) {
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ASTDoWhile& ast) {
|
||||
void operator()(const ASTDoWhile& ast) {
|
||||
const Id loop_label = decomp.OpLabel();
|
||||
const Id endloop_label = decomp.OpLabel();
|
||||
const Id loop_start_block = decomp.OpLabel();
|
||||
@@ -1787,7 +1787,7 @@ public:
|
||||
decomp.Emit(endloop_label);
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ASTReturn& ast) {
|
||||
void operator()(const ASTReturn& ast) {
|
||||
if (!VideoCommon::Shader::ExprIsTrue(ast.condition)) {
|
||||
ExprDecompiler expr_parser{decomp};
|
||||
const Id condition = expr_parser.Visit(ast.condition);
|
||||
@@ -1817,7 +1817,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void operator()(VideoCommon::Shader::ASTBreak& ast) {
|
||||
void operator()(const ASTBreak& ast) {
|
||||
if (!VideoCommon::Shader::ExprIsTrue(ast.condition)) {
|
||||
ExprDecompiler expr_parser{decomp};
|
||||
const Id condition = expr_parser.Visit(ast.condition);
|
||||
@@ -1837,7 +1837,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void Visit(VideoCommon::Shader::ASTNode& node) {
|
||||
void Visit(const ASTNode& node) {
|
||||
std::visit(*this, *node->GetInnerData());
|
||||
}
|
||||
|
||||
@@ -1853,9 +1853,11 @@ void SPIRVDecompiler::DecompileAST() {
|
||||
Name(id, fmt::format("flow_var_{}", i));
|
||||
flow_variables.emplace(i, AddGlobalVariable(id));
|
||||
}
|
||||
|
||||
const ASTNode program = ir.GetASTProgram();
|
||||
ASTDecompiler decompiler{*this};
|
||||
VideoCommon::Shader::ASTNode program = ir.GetASTProgram();
|
||||
decompiler.Visit(program);
|
||||
|
||||
const Id next_block = OpLabel();
|
||||
Emit(OpBranch(next_block));
|
||||
Emit(next_block);
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/common_types.h"
|
||||
@@ -229,7 +232,8 @@ public:
|
||||
return inner;
|
||||
}
|
||||
|
||||
std::string inner{};
|
||||
private:
|
||||
std::string inner;
|
||||
};
|
||||
|
||||
class ASTPrinter {
|
||||
@@ -249,7 +253,7 @@ public:
|
||||
void operator()(const ASTIfThen& ast) {
|
||||
ExprPrinter expr_parser{};
|
||||
std::visit(expr_parser, *ast.condition);
|
||||
inner += Ident() + "if (" + expr_parser.GetResult() + ") {\n";
|
||||
inner += fmt::format("{}if ({}) {{\n", Indent(), expr_parser.GetResult());
|
||||
scope++;
|
||||
ASTNode current = ast.nodes.GetFirst();
|
||||
while (current) {
|
||||
@@ -257,11 +261,13 @@ public:
|
||||
current = current->GetNext();
|
||||
}
|
||||
scope--;
|
||||
inner += Ident() + "}\n";
|
||||
inner += fmt::format("{}}}\n", Indent());
|
||||
}
|
||||
|
||||
void operator()(const ASTIfElse& ast) {
|
||||
inner += Ident() + "else {\n";
|
||||
inner += Indent();
|
||||
inner += "else {\n";
|
||||
|
||||
scope++;
|
||||
ASTNode current = ast.nodes.GetFirst();
|
||||
while (current) {
|
||||
@@ -269,40 +275,41 @@ public:
|
||||
current = current->GetNext();
|
||||
}
|
||||
scope--;
|
||||
inner += Ident() + "}\n";
|
||||
|
||||
inner += Indent();
|
||||
inner += "}\n";
|
||||
}
|
||||
|
||||
void operator()(const ASTBlockEncoded& ast) {
|
||||
inner += Ident() + "Block(" + std::to_string(ast.start) + ", " + std::to_string(ast.end) +
|
||||
");\n";
|
||||
inner += fmt::format("{}Block({}, {});\n", Indent(), ast.start, ast.end);
|
||||
}
|
||||
|
||||
void operator()(const ASTBlockDecoded& ast) {
|
||||
inner += Ident() + "Block;\n";
|
||||
void operator()([[maybe_unused]] const ASTBlockDecoded& ast) {
|
||||
inner += Indent();
|
||||
inner += "Block;\n";
|
||||
}
|
||||
|
||||
void operator()(const ASTVarSet& ast) {
|
||||
ExprPrinter expr_parser{};
|
||||
std::visit(expr_parser, *ast.condition);
|
||||
inner +=
|
||||
Ident() + "V" + std::to_string(ast.index) + " := " + expr_parser.GetResult() + ";\n";
|
||||
inner += fmt::format("{}V{} := {};\n", Indent(), ast.index, expr_parser.GetResult());
|
||||
}
|
||||
|
||||
void operator()(const ASTLabel& ast) {
|
||||
inner += "Label_" + std::to_string(ast.index) + ":\n";
|
||||
inner += fmt::format("Label_{}:\n", ast.index);
|
||||
}
|
||||
|
||||
void operator()(const ASTGoto& ast) {
|
||||
ExprPrinter expr_parser{};
|
||||
std::visit(expr_parser, *ast.condition);
|
||||
inner += Ident() + "(" + expr_parser.GetResult() + ") -> goto Label_" +
|
||||
std::to_string(ast.label) + ";\n";
|
||||
inner +=
|
||||
fmt::format("{}({}) -> goto Label_{};\n", Indent(), expr_parser.GetResult(), ast.label);
|
||||
}
|
||||
|
||||
void operator()(const ASTDoWhile& ast) {
|
||||
ExprPrinter expr_parser{};
|
||||
std::visit(expr_parser, *ast.condition);
|
||||
inner += Ident() + "do {\n";
|
||||
inner += fmt::format("{}do {{\n", Indent());
|
||||
scope++;
|
||||
ASTNode current = ast.nodes.GetFirst();
|
||||
while (current) {
|
||||
@@ -310,32 +317,23 @@ public:
|
||||
current = current->GetNext();
|
||||
}
|
||||
scope--;
|
||||
inner += Ident() + "} while (" + expr_parser.GetResult() + ");\n";
|
||||
inner += fmt::format("{}}} while ({});\n", Indent(), expr_parser.GetResult());
|
||||
}
|
||||
|
||||
void operator()(const ASTReturn& ast) {
|
||||
ExprPrinter expr_parser{};
|
||||
std::visit(expr_parser, *ast.condition);
|
||||
inner += Ident() + "(" + expr_parser.GetResult() + ") -> " +
|
||||
(ast.kills ? "discard" : "exit") + ";\n";
|
||||
inner += fmt::format("{}({}) -> {};\n", Indent(), expr_parser.GetResult(),
|
||||
ast.kills ? "discard" : "exit");
|
||||
}
|
||||
|
||||
void operator()(const ASTBreak& ast) {
|
||||
ExprPrinter expr_parser{};
|
||||
std::visit(expr_parser, *ast.condition);
|
||||
inner += Ident() + "(" + expr_parser.GetResult() + ") -> break;\n";
|
||||
inner += fmt::format("{}({}) -> break;\n", Indent(), expr_parser.GetResult());
|
||||
}
|
||||
|
||||
std::string& Ident() {
|
||||
if (memo_scope == scope) {
|
||||
return tabs_memo;
|
||||
}
|
||||
tabs_memo = tabs.substr(0, scope * 2);
|
||||
memo_scope = scope;
|
||||
return tabs_memo;
|
||||
}
|
||||
|
||||
void Visit(ASTNode& node) {
|
||||
void Visit(const ASTNode& node) {
|
||||
std::visit(*this, *node->GetInnerData());
|
||||
}
|
||||
|
||||
@@ -344,16 +342,29 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
std::string_view Indent() {
|
||||
if (space_segment_scope == scope) {
|
||||
return space_segment;
|
||||
}
|
||||
|
||||
// Ensure that we don't exceed our view.
|
||||
ASSERT(scope * 2 < spaces.size());
|
||||
|
||||
space_segment = spaces.substr(0, scope * 2);
|
||||
space_segment_scope = scope;
|
||||
return space_segment;
|
||||
}
|
||||
|
||||
std::string inner{};
|
||||
std::string_view space_segment;
|
||||
|
||||
u32 scope{};
|
||||
u32 space_segment_scope{};
|
||||
|
||||
std::string tabs_memo{};
|
||||
u32 memo_scope{};
|
||||
|
||||
static constexpr std::string_view tabs{" "};
|
||||
static constexpr std::string_view spaces{" "};
|
||||
};
|
||||
|
||||
std::string ASTManager::Print() {
|
||||
std::string ASTManager::Print() const {
|
||||
ASTPrinter printer{};
|
||||
printer.Visit(main_node);
|
||||
return printer.GetResult();
|
||||
@@ -549,13 +560,13 @@ bool ASTManager::DirectlyRelated(const ASTNode& first, const ASTNode& second) co
|
||||
return min->GetParent() == max->GetParent();
|
||||
}
|
||||
|
||||
void ASTManager::ShowCurrentState(std::string_view state) {
|
||||
void ASTManager::ShowCurrentState(std::string_view state) const {
|
||||
LOG_CRITICAL(HW_GPU, "\nState {}:\n\n{}\n", state, Print());
|
||||
SanityCheck();
|
||||
}
|
||||
|
||||
void ASTManager::SanityCheck() {
|
||||
for (auto& label : labels) {
|
||||
void ASTManager::SanityCheck() const {
|
||||
for (const auto& label : labels) {
|
||||
if (!label->GetParent()) {
|
||||
LOG_CRITICAL(HW_GPU, "Sanity Check Failed");
|
||||
}
|
||||
|
||||
@@ -328,13 +328,13 @@ public:
|
||||
|
||||
void InsertReturn(Expr condition, bool kills);
|
||||
|
||||
std::string Print();
|
||||
std::string Print() const;
|
||||
|
||||
void Decompile();
|
||||
|
||||
void ShowCurrentState(std::string_view state);
|
||||
void ShowCurrentState(std::string_view state) const;
|
||||
|
||||
void SanityCheck();
|
||||
void SanityCheck() const;
|
||||
|
||||
void Clear();
|
||||
|
||||
|
||||
@@ -473,8 +473,8 @@ void DecompileShader(CFGRebuildState& state) {
|
||||
state.manager->Decompile();
|
||||
}
|
||||
|
||||
std::unique_ptr<ShaderCharacteristics> ScanFlow(const ProgramCode& program_code, u32 program_size,
|
||||
u32 start_address,
|
||||
std::unique_ptr<ShaderCharacteristics> ScanFlow(const ProgramCode& program_code,
|
||||
std::size_t program_size, u32 start_address,
|
||||
const CompilerSettings& settings) {
|
||||
auto result_out = std::make_unique<ShaderCharacteristics>();
|
||||
if (settings.depth == CompileDepth::BruteForce) {
|
||||
|
||||
@@ -76,8 +76,8 @@ struct ShaderCharacteristics {
|
||||
CompilerSettings settings{};
|
||||
};
|
||||
|
||||
std::unique_ptr<ShaderCharacteristics> ScanFlow(const ProgramCode& program_code, u32 program_size,
|
||||
u32 start_address,
|
||||
std::unique_ptr<ShaderCharacteristics> ScanFlow(const ProgramCode& program_code,
|
||||
std::size_t program_size, u32 start_address,
|
||||
const CompilerSettings& settings);
|
||||
|
||||
} // namespace VideoCommon::Shader
|
||||
|
||||
@@ -410,7 +410,7 @@ public:
|
||||
explicit OperationNode(OperationCode code) : OperationNode(code, Meta{}) {}
|
||||
|
||||
explicit OperationNode(OperationCode code, Meta meta)
|
||||
: OperationNode(code, meta, std::vector<Node>{}) {}
|
||||
: OperationNode(code, std::move(meta), std::vector<Node>{}) {}
|
||||
|
||||
explicit OperationNode(OperationCode code, std::vector<Node> operands)
|
||||
: OperationNode(code, Meta{}, std::move(operands)) {}
|
||||
|
||||
@@ -212,6 +212,14 @@ PixelFormat PixelFormatFromTextureFormat(Tegra::Texture::TextureFormat format,
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Tegra::Texture::TextureFormat::A4B4G4R4:
|
||||
switch (component_type) {
|
||||
case Tegra::Texture::ComponentType::UNORM:
|
||||
return PixelFormat::R4G4B4A4U;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Tegra::Texture::TextureFormat::R8:
|
||||
switch (component_type) {
|
||||
case Tegra::Texture::ComponentType::UNORM:
|
||||
@@ -252,6 +260,7 @@ PixelFormat PixelFormatFromTextureFormat(Tegra::Texture::TextureFormat format,
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Tegra::Texture::TextureFormat::R32_G32_B32_A32:
|
||||
switch (component_type) {
|
||||
case Tegra::Texture::ComponentType::FLOAT:
|
||||
@@ -350,6 +359,16 @@ PixelFormat PixelFormatFromTextureFormat(Tegra::Texture::TextureFormat format,
|
||||
return is_srgb ? PixelFormat::ASTC_2D_8X5_SRGB : PixelFormat::ASTC_2D_8X5;
|
||||
case Tegra::Texture::TextureFormat::ASTC_2D_10X8:
|
||||
return is_srgb ? PixelFormat::ASTC_2D_10X8_SRGB : PixelFormat::ASTC_2D_10X8;
|
||||
case Tegra::Texture::TextureFormat::ASTC_2D_6X6:
|
||||
return is_srgb ? PixelFormat::ASTC_2D_6X6_SRGB : PixelFormat::ASTC_2D_6X6;
|
||||
case Tegra::Texture::TextureFormat::ASTC_2D_10X10:
|
||||
return is_srgb ? PixelFormat::ASTC_2D_10X10_SRGB : PixelFormat::ASTC_2D_10X10;
|
||||
case Tegra::Texture::TextureFormat::ASTC_2D_12X12:
|
||||
return is_srgb ? PixelFormat::ASTC_2D_12X12_SRGB : PixelFormat::ASTC_2D_12X12;
|
||||
case Tegra::Texture::TextureFormat::ASTC_2D_8X6:
|
||||
return is_srgb ? PixelFormat::ASTC_2D_8X6_SRGB : PixelFormat::ASTC_2D_8X6;
|
||||
case Tegra::Texture::TextureFormat::ASTC_2D_6X5:
|
||||
return is_srgb ? PixelFormat::ASTC_2D_6X5_SRGB : PixelFormat::ASTC_2D_6X5;
|
||||
case Tegra::Texture::TextureFormat::R16_G16:
|
||||
switch (component_type) {
|
||||
case Tegra::Texture::ComponentType::FLOAT:
|
||||
@@ -510,6 +529,16 @@ bool IsPixelFormatASTC(PixelFormat format) {
|
||||
case PixelFormat::ASTC_2D_8X5_SRGB:
|
||||
case PixelFormat::ASTC_2D_10X8:
|
||||
case PixelFormat::ASTC_2D_10X8_SRGB:
|
||||
case PixelFormat::ASTC_2D_6X6:
|
||||
case PixelFormat::ASTC_2D_6X6_SRGB:
|
||||
case PixelFormat::ASTC_2D_10X10:
|
||||
case PixelFormat::ASTC_2D_10X10_SRGB:
|
||||
case PixelFormat::ASTC_2D_12X12:
|
||||
case PixelFormat::ASTC_2D_12X12_SRGB:
|
||||
case PixelFormat::ASTC_2D_8X6:
|
||||
case PixelFormat::ASTC_2D_8X6_SRGB:
|
||||
case PixelFormat::ASTC_2D_6X5:
|
||||
case PixelFormat::ASTC_2D_6X5_SRGB:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
@@ -530,6 +559,11 @@ bool IsPixelFormatSRGB(PixelFormat format) {
|
||||
case PixelFormat::ASTC_2D_5X4_SRGB:
|
||||
case PixelFormat::ASTC_2D_5X5_SRGB:
|
||||
case PixelFormat::ASTC_2D_10X8_SRGB:
|
||||
case PixelFormat::ASTC_2D_6X6_SRGB:
|
||||
case PixelFormat::ASTC_2D_10X10_SRGB:
|
||||
case PixelFormat::ASTC_2D_12X12_SRGB:
|
||||
case PixelFormat::ASTC_2D_8X6_SRGB:
|
||||
case PixelFormat::ASTC_2D_6X5_SRGB:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
||||
@@ -67,27 +67,38 @@ enum class PixelFormat {
|
||||
DXT23_SRGB = 49,
|
||||
DXT45_SRGB = 50,
|
||||
BC7U_SRGB = 51,
|
||||
ASTC_2D_4X4_SRGB = 52,
|
||||
ASTC_2D_8X8_SRGB = 53,
|
||||
ASTC_2D_8X5_SRGB = 54,
|
||||
ASTC_2D_5X4_SRGB = 55,
|
||||
ASTC_2D_5X5 = 56,
|
||||
ASTC_2D_5X5_SRGB = 57,
|
||||
ASTC_2D_10X8 = 58,
|
||||
ASTC_2D_10X8_SRGB = 59,
|
||||
R4G4B4A4U = 52,
|
||||
ASTC_2D_4X4_SRGB = 53,
|
||||
ASTC_2D_8X8_SRGB = 54,
|
||||
ASTC_2D_8X5_SRGB = 55,
|
||||
ASTC_2D_5X4_SRGB = 56,
|
||||
ASTC_2D_5X5 = 57,
|
||||
ASTC_2D_5X5_SRGB = 58,
|
||||
ASTC_2D_10X8 = 59,
|
||||
ASTC_2D_10X8_SRGB = 60,
|
||||
ASTC_2D_6X6 = 61,
|
||||
ASTC_2D_6X6_SRGB = 62,
|
||||
ASTC_2D_10X10 = 63,
|
||||
ASTC_2D_10X10_SRGB = 64,
|
||||
ASTC_2D_12X12 = 65,
|
||||
ASTC_2D_12X12_SRGB = 66,
|
||||
ASTC_2D_8X6 = 67,
|
||||
ASTC_2D_8X6_SRGB = 68,
|
||||
ASTC_2D_6X5 = 69,
|
||||
ASTC_2D_6X5_SRGB = 70,
|
||||
|
||||
MaxColorFormat,
|
||||
|
||||
// Depth formats
|
||||
Z32F = 60,
|
||||
Z16 = 61,
|
||||
Z32F = 71,
|
||||
Z16 = 72,
|
||||
|
||||
MaxDepthFormat,
|
||||
|
||||
// DepthStencil formats
|
||||
Z24S8 = 62,
|
||||
S8Z24 = 63,
|
||||
Z32FS8 = 64,
|
||||
Z24S8 = 73,
|
||||
S8Z24 = 74,
|
||||
Z32FS8 = 75,
|
||||
|
||||
MaxDepthStencilFormat,
|
||||
|
||||
@@ -177,6 +188,7 @@ constexpr std::array<u32, MaxPixelFormat> compression_factor_shift_table = {{
|
||||
2, // DXT23_SRGB
|
||||
2, // DXT45_SRGB
|
||||
2, // BC7U_SRGB
|
||||
0, // R4G4B4A4U
|
||||
2, // ASTC_2D_4X4_SRGB
|
||||
2, // ASTC_2D_8X8_SRGB
|
||||
2, // ASTC_2D_8X5_SRGB
|
||||
@@ -185,6 +197,16 @@ constexpr std::array<u32, MaxPixelFormat> compression_factor_shift_table = {{
|
||||
2, // ASTC_2D_5X5_SRGB
|
||||
2, // ASTC_2D_10X8
|
||||
2, // ASTC_2D_10X8_SRGB
|
||||
2, // ASTC_2D_6X6
|
||||
2, // ASTC_2D_6X6_SRGB
|
||||
2, // ASTC_2D_10X10
|
||||
2, // ASTC_2D_10X10_SRGB
|
||||
2, // ASTC_2D_12X12
|
||||
2, // ASTC_2D_12X12_SRGB
|
||||
2, // ASTC_2D_8X6
|
||||
2, // ASTC_2D_8X6_SRGB
|
||||
2, // ASTC_2D_6X5
|
||||
2, // ASTC_2D_6X5_SRGB
|
||||
0, // Z32F
|
||||
0, // Z16
|
||||
0, // Z24S8
|
||||
@@ -261,6 +283,7 @@ constexpr std::array<u32, MaxPixelFormat> block_width_table = {{
|
||||
4, // DXT23_SRGB
|
||||
4, // DXT45_SRGB
|
||||
4, // BC7U_SRGB
|
||||
1, // R4G4B4A4U
|
||||
4, // ASTC_2D_4X4_SRGB
|
||||
8, // ASTC_2D_8X8_SRGB
|
||||
8, // ASTC_2D_8X5_SRGB
|
||||
@@ -269,6 +292,16 @@ constexpr std::array<u32, MaxPixelFormat> block_width_table = {{
|
||||
5, // ASTC_2D_5X5_SRGB
|
||||
10, // ASTC_2D_10X8
|
||||
10, // ASTC_2D_10X8_SRGB
|
||||
6, // ASTC_2D_6X6
|
||||
6, // ASTC_2D_6X6_SRGB
|
||||
10, // ASTC_2D_10X10
|
||||
10, // ASTC_2D_10X10_SRGB
|
||||
12, // ASTC_2D_12X12
|
||||
12, // ASTC_2D_12X12_SRGB
|
||||
8, // ASTC_2D_8X6
|
||||
8, // ASTC_2D_8X6_SRGB
|
||||
6, // ASTC_2D_6X5
|
||||
6, // ASTC_2D_6X5_SRGB
|
||||
1, // Z32F
|
||||
1, // Z16
|
||||
1, // Z24S8
|
||||
@@ -285,71 +318,82 @@ static constexpr u32 GetDefaultBlockWidth(PixelFormat format) {
|
||||
}
|
||||
|
||||
constexpr std::array<u32, MaxPixelFormat> block_height_table = {{
|
||||
1, // ABGR8U
|
||||
1, // ABGR8S
|
||||
1, // ABGR8UI
|
||||
1, // B5G6R5U
|
||||
1, // A2B10G10R10U
|
||||
1, // A1B5G5R5U
|
||||
1, // R8U
|
||||
1, // R8UI
|
||||
1, // RGBA16F
|
||||
1, // RGBA16U
|
||||
1, // RGBA16UI
|
||||
1, // R11FG11FB10F
|
||||
1, // RGBA32UI
|
||||
4, // DXT1
|
||||
4, // DXT23
|
||||
4, // DXT45
|
||||
4, // DXN1
|
||||
4, // DXN2UNORM
|
||||
4, // DXN2SNORM
|
||||
4, // BC7U
|
||||
4, // BC6H_UF16
|
||||
4, // BC6H_SF16
|
||||
4, // ASTC_2D_4X4
|
||||
1, // BGRA8
|
||||
1, // RGBA32F
|
||||
1, // RG32F
|
||||
1, // R32F
|
||||
1, // R16F
|
||||
1, // R16U
|
||||
1, // R16S
|
||||
1, // R16UI
|
||||
1, // R16I
|
||||
1, // RG16
|
||||
1, // RG16F
|
||||
1, // RG16UI
|
||||
1, // RG16I
|
||||
1, // RG16S
|
||||
1, // RGB32F
|
||||
1, // RGBA8_SRGB
|
||||
1, // RG8U
|
||||
1, // RG8S
|
||||
1, // RG32UI
|
||||
1, // RGBX16F
|
||||
1, // R32UI
|
||||
8, // ASTC_2D_8X8
|
||||
5, // ASTC_2D_8X5
|
||||
4, // ASTC_2D_5X4
|
||||
1, // BGRA8_SRGB
|
||||
4, // DXT1_SRGB
|
||||
4, // DXT23_SRGB
|
||||
4, // DXT45_SRGB
|
||||
4, // BC7U_SRGB
|
||||
4, // ASTC_2D_4X4_SRGB
|
||||
8, // ASTC_2D_8X8_SRGB
|
||||
5, // ASTC_2D_8X5_SRGB
|
||||
4, // ASTC_2D_5X4_SRGB
|
||||
5, // ASTC_2D_5X5
|
||||
5, // ASTC_2D_5X5_SRGB
|
||||
8, // ASTC_2D_10X8
|
||||
8, // ASTC_2D_10X8_SRGB
|
||||
1, // Z32F
|
||||
1, // Z16
|
||||
1, // Z24S8
|
||||
1, // S8Z24
|
||||
1, // Z32FS8
|
||||
1, // ABGR8U
|
||||
1, // ABGR8S
|
||||
1, // ABGR8UI
|
||||
1, // B5G6R5U
|
||||
1, // A2B10G10R10U
|
||||
1, // A1B5G5R5U
|
||||
1, // R8U
|
||||
1, // R8UI
|
||||
1, // RGBA16F
|
||||
1, // RGBA16U
|
||||
1, // RGBA16UI
|
||||
1, // R11FG11FB10F
|
||||
1, // RGBA32UI
|
||||
4, // DXT1
|
||||
4, // DXT23
|
||||
4, // DXT45
|
||||
4, // DXN1
|
||||
4, // DXN2UNORM
|
||||
4, // DXN2SNORM
|
||||
4, // BC7U
|
||||
4, // BC6H_UF16
|
||||
4, // BC6H_SF16
|
||||
4, // ASTC_2D_4X4
|
||||
1, // BGRA8
|
||||
1, // RGBA32F
|
||||
1, // RG32F
|
||||
1, // R32F
|
||||
1, // R16F
|
||||
1, // R16U
|
||||
1, // R16S
|
||||
1, // R16UI
|
||||
1, // R16I
|
||||
1, // RG16
|
||||
1, // RG16F
|
||||
1, // RG16UI
|
||||
1, // RG16I
|
||||
1, // RG16S
|
||||
1, // RGB32F
|
||||
1, // RGBA8_SRGB
|
||||
1, // RG8U
|
||||
1, // RG8S
|
||||
1, // RG32UI
|
||||
1, // RGBX16F
|
||||
1, // R32UI
|
||||
8, // ASTC_2D_8X8
|
||||
5, // ASTC_2D_8X5
|
||||
4, // ASTC_2D_5X4
|
||||
1, // BGRA8_SRGB
|
||||
4, // DXT1_SRGB
|
||||
4, // DXT23_SRGB
|
||||
4, // DXT45_SRGB
|
||||
4, // BC7U_SRGB
|
||||
1, // R4G4B4A4U
|
||||
4, // ASTC_2D_4X4_SRGB
|
||||
8, // ASTC_2D_8X8_SRGB
|
||||
5, // ASTC_2D_8X5_SRGB
|
||||
4, // ASTC_2D_5X4_SRGB
|
||||
5, // ASTC_2D_5X5
|
||||
5, // ASTC_2D_5X5_SRGB
|
||||
8, // ASTC_2D_10X8
|
||||
8, // ASTC_2D_10X8_SRGB
|
||||
6, // ASTC_2D_6X6
|
||||
6, // ASTC_2D_6X6_SRGB
|
||||
10, // ASTC_2D_10X10
|
||||
10, // ASTC_2D_10X10_SRGB
|
||||
12, // ASTC_2D_12X12
|
||||
12, // ASTC_2D_12X12_SRGB
|
||||
6, // ASTC_2D_8X6
|
||||
6, // ASTC_2D_8X6_SRGB
|
||||
5, // ASTC_2D_6X5
|
||||
5, // ASTC_2D_6X5_SRGB
|
||||
1, // Z32F
|
||||
1, // Z16
|
||||
1, // Z24S8
|
||||
1, // S8Z24
|
||||
1, // Z32FS8
|
||||
}};
|
||||
|
||||
static constexpr u32 GetDefaultBlockHeight(PixelFormat format) {
|
||||
@@ -413,6 +457,7 @@ constexpr std::array<u32, MaxPixelFormat> bpp_table = {{
|
||||
128, // DXT23_SRGB
|
||||
128, // DXT45_SRGB
|
||||
128, // BC7U
|
||||
16, // R4G4B4A4U
|
||||
128, // ASTC_2D_4X4_SRGB
|
||||
128, // ASTC_2D_8X8_SRGB
|
||||
128, // ASTC_2D_8X5_SRGB
|
||||
@@ -421,6 +466,16 @@ constexpr std::array<u32, MaxPixelFormat> bpp_table = {{
|
||||
128, // ASTC_2D_5X5_SRGB
|
||||
128, // ASTC_2D_10X8
|
||||
128, // ASTC_2D_10X8_SRGB
|
||||
128, // ASTC_2D_6X6
|
||||
128, // ASTC_2D_6X6_SRGB
|
||||
128, // ASTC_2D_10X10
|
||||
128, // ASTC_2D_10X10_SRGB
|
||||
128, // ASTC_2D_12X12
|
||||
128, // ASTC_2D_12X12_SRGB
|
||||
128, // ASTC_2D_8X6
|
||||
128, // ASTC_2D_8X6_SRGB
|
||||
128, // ASTC_2D_6X5
|
||||
128, // ASTC_2D_6X5_SRGB
|
||||
32, // Z32F
|
||||
16, // Z16
|
||||
32, // Z24S8
|
||||
@@ -504,6 +559,7 @@ constexpr std::array<SurfaceCompression, MaxPixelFormat> compression_type_table
|
||||
SurfaceCompression::Compressed, // DXT23_SRGB
|
||||
SurfaceCompression::Compressed, // DXT45_SRGB
|
||||
SurfaceCompression::Compressed, // BC7U_SRGB
|
||||
SurfaceCompression::None, // R4G4B4A4U
|
||||
SurfaceCompression::Converted, // ASTC_2D_4X4_SRGB
|
||||
SurfaceCompression::Converted, // ASTC_2D_8X8_SRGB
|
||||
SurfaceCompression::Converted, // ASTC_2D_8X5_SRGB
|
||||
@@ -512,6 +568,16 @@ constexpr std::array<SurfaceCompression, MaxPixelFormat> compression_type_table
|
||||
SurfaceCompression::Converted, // ASTC_2D_5X5_SRGB
|
||||
SurfaceCompression::Converted, // ASTC_2D_10X8
|
||||
SurfaceCompression::Converted, // ASTC_2D_10X8_SRGB
|
||||
SurfaceCompression::Converted, // ASTC_2D_6X6
|
||||
SurfaceCompression::Converted, // ASTC_2D_6X6_SRGB
|
||||
SurfaceCompression::Converted, // ASTC_2D_10X10
|
||||
SurfaceCompression::Converted, // ASTC_2D_10X10_SRGB
|
||||
SurfaceCompression::Converted, // ASTC_2D_12X12
|
||||
SurfaceCompression::Converted, // ASTC_2D_12X12_SRGB
|
||||
SurfaceCompression::Converted, // ASTC_2D_8X6
|
||||
SurfaceCompression::Converted, // ASTC_2D_8X6_SRGB
|
||||
SurfaceCompression::Converted, // ASTC_2D_6X5
|
||||
SurfaceCompression::Converted, // ASTC_2D_6X5_SRGB
|
||||
SurfaceCompression::None, // Z32F
|
||||
SurfaceCompression::None, // Z16
|
||||
SurfaceCompression::None, // Z24S8
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "common/algorithm.h"
|
||||
#include "common/assert.h"
|
||||
#include "common/common_types.h"
|
||||
#include "common/microprofile.h"
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <optional>
|
||||
#include <tuple>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/binary_find.h"
|
||||
#include "common/common_types.h"
|
||||
#include "video_core/gpu.h"
|
||||
#include "video_core/morton.h"
|
||||
|
||||
@@ -62,10 +62,10 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* `Guard` guarantees that rendertargets don't unregister themselves if the
|
||||
/**
|
||||
* Guarantees that rendertargets don't unregister themselves if the
|
||||
* collide. Protection is currently only done on 3D slices.
|
||||
***/
|
||||
*/
|
||||
void GuardRenderTargets(bool new_guard) {
|
||||
guard_render_targets = new_guard;
|
||||
}
|
||||
@@ -287,7 +287,7 @@ protected:
|
||||
const Tegra::Engines::Fermi2D::Config& copy_config) = 0;
|
||||
|
||||
// Depending on the backend, a buffer copy can be slow as it means deoptimizing the texture
|
||||
// and reading it from a sepparate buffer.
|
||||
// and reading it from a separate buffer.
|
||||
virtual void BufferCopy(TSurface& src_surface, TSurface& dst_surface) = 0;
|
||||
|
||||
void ManageRenderTargetUnregister(TSurface& surface) {
|
||||
@@ -386,12 +386,13 @@ private:
|
||||
};
|
||||
|
||||
/**
|
||||
* `PickStrategy` takes care of selecting a proper strategy to deal with a texture recycle.
|
||||
* @param overlaps, the overlapping surfaces registered in the cache.
|
||||
* @param params, the paremeters on the new surface.
|
||||
* @param gpu_addr, the starting address of the new surface.
|
||||
* @param untopological, tells the recycler that the texture has no way to match the overlaps
|
||||
* due to topological reasons.
|
||||
* Takes care of selecting a proper strategy to deal with a texture recycle.
|
||||
*
|
||||
* @param overlaps The overlapping surfaces registered in the cache.
|
||||
* @param params The parameters on the new surface.
|
||||
* @param gpu_addr The starting address of the new surface.
|
||||
* @param untopological Indicates to the recycler that the texture has no way
|
||||
* to match the overlaps due to topological reasons.
|
||||
**/
|
||||
RecycleStrategy PickStrategy(std::vector<TSurface>& overlaps, const SurfaceParams& params,
|
||||
const GPUVAddr gpu_addr, const MatchTopologyResult untopological) {
|
||||
@@ -402,7 +403,7 @@ private:
|
||||
if (params.block_depth > 1 || params.target == SurfaceTarget::Texture3D) {
|
||||
return RecycleStrategy::Flush;
|
||||
}
|
||||
for (auto s : overlaps) {
|
||||
for (const auto& s : overlaps) {
|
||||
const auto& s_params = s->GetSurfaceParams();
|
||||
if (s_params.block_depth > 1 || s_params.target == SurfaceTarget::Texture3D) {
|
||||
return RecycleStrategy::Flush;
|
||||
@@ -419,16 +420,19 @@ private:
|
||||
}
|
||||
|
||||
/**
|
||||
* `RecycleSurface` es a method we use to decide what to do with textures we can't resolve in
|
||||
*the cache It has 2 implemented strategies: Ignore and Flush. Ignore just unregisters all the
|
||||
*overlaps and loads the new texture. Flush, flushes all the overlaps into memory and loads the
|
||||
*new surface from that data.
|
||||
* @param overlaps, the overlapping surfaces registered in the cache.
|
||||
* @param params, the paremeters on the new surface.
|
||||
* @param gpu_addr, the starting address of the new surface.
|
||||
* @param preserve_contents, tells if the new surface should be loaded from meory or left blank
|
||||
* @param untopological, tells the recycler that the texture has no way to match the overlaps
|
||||
* due to topological reasons.
|
||||
* Used to decide what to do with textures we can't resolve in the cache It has 2 implemented
|
||||
* strategies: Ignore and Flush.
|
||||
*
|
||||
* - Ignore: Just unregisters all the overlaps and loads the new texture.
|
||||
* - Flush: Flushes all the overlaps into memory and loads the new surface from that data.
|
||||
*
|
||||
* @param overlaps The overlapping surfaces registered in the cache.
|
||||
* @param params The parameters for the new surface.
|
||||
* @param gpu_addr The starting address of the new surface.
|
||||
* @param preserve_contents Indicates that the new surface should be loaded from memory or left
|
||||
* blank.
|
||||
* @param untopological Indicates to the recycler that the texture has no way to match the
|
||||
* overlaps due to topological reasons.
|
||||
**/
|
||||
std::pair<TSurface, TView> RecycleSurface(std::vector<TSurface>& overlaps,
|
||||
const SurfaceParams& params, const GPUVAddr gpu_addr,
|
||||
@@ -465,10 +469,12 @@ private:
|
||||
}
|
||||
|
||||
/**
|
||||
* `RebuildSurface` this method takes a single surface and recreates into another that
|
||||
* may differ in format, target or width alingment.
|
||||
* @param current_surface, the registered surface in the cache which we want to convert.
|
||||
* @param params, the new surface params which we'll use to recreate the surface.
|
||||
* Takes a single surface and recreates into another that may differ in
|
||||
* format, target or width alignment.
|
||||
*
|
||||
* @param current_surface The registered surface in the cache which we want to convert.
|
||||
* @param params The new surface params which we'll use to recreate the surface.
|
||||
* @param is_render Whether or not the surface is a render target.
|
||||
**/
|
||||
std::pair<TSurface, TView> RebuildSurface(TSurface current_surface, const SurfaceParams& params,
|
||||
bool is_render) {
|
||||
@@ -502,12 +508,14 @@ private:
|
||||
}
|
||||
|
||||
/**
|
||||
* `ManageStructuralMatch` this method takes a single surface and checks with the new surface's
|
||||
* params if it's an exact match, we return the main view of the registered surface. If it's
|
||||
* formats don't match, we rebuild the surface. We call this last method a `Mirage`. If formats
|
||||
* Takes a single surface and checks with the new surface's params if it's an exact
|
||||
* match, we return the main view of the registered surface. If its formats don't
|
||||
* match, we rebuild the surface. We call this last method a `Mirage`. If formats
|
||||
* match but the targets don't, we create an overview View of the registered surface.
|
||||
* @param current_surface, the registered surface in the cache which we want to convert.
|
||||
* @param params, the new surface params which we want to check.
|
||||
*
|
||||
* @param current_surface The registered surface in the cache which we want to convert.
|
||||
* @param params The new surface params which we want to check.
|
||||
* @param is_render Whether or not the surface is a render target.
|
||||
**/
|
||||
std::pair<TSurface, TView> ManageStructuralMatch(TSurface current_surface,
|
||||
const SurfaceParams& params, bool is_render) {
|
||||
@@ -529,13 +537,14 @@ private:
|
||||
}
|
||||
|
||||
/**
|
||||
* `TryReconstructSurface` unlike `RebuildSurface` where we know the registered surface
|
||||
* matches the candidate in some way, we got no guarantess here. We try to see if the overlaps
|
||||
* are sublayers/mipmaps of the new surface, if they all match we end up recreating a surface
|
||||
* for them, else we return nothing.
|
||||
* @param overlaps, the overlapping surfaces registered in the cache.
|
||||
* @param params, the paremeters on the new surface.
|
||||
* @param gpu_addr, the starting address of the new surface.
|
||||
* Unlike RebuildSurface where we know whether or not registered surfaces match the candidate
|
||||
* in some way, we have no guarantees here. We try to see if the overlaps are sublayers/mipmaps
|
||||
* of the new surface, if they all match we end up recreating a surface for them,
|
||||
* else we return nothing.
|
||||
*
|
||||
* @param overlaps The overlapping surfaces registered in the cache.
|
||||
* @param params The parameters on the new surface.
|
||||
* @param gpu_addr The starting address of the new surface.
|
||||
**/
|
||||
std::optional<std::pair<TSurface, TView>> TryReconstructSurface(std::vector<TSurface>& overlaps,
|
||||
const SurfaceParams& params,
|
||||
@@ -575,7 +584,7 @@ private:
|
||||
} else if (Settings::values.use_accurate_gpu_emulation && passed_tests != overlaps.size()) {
|
||||
return {};
|
||||
}
|
||||
for (auto surface : overlaps) {
|
||||
for (const auto& surface : overlaps) {
|
||||
Unregister(surface);
|
||||
}
|
||||
new_surface->MarkAsModified(modified, Tick());
|
||||
@@ -584,19 +593,27 @@ private:
|
||||
}
|
||||
|
||||
/**
|
||||
* `GetSurface` gets the starting address and parameters of a candidate surface and tries
|
||||
* to find a matching surface within the cache. This is done in 3 big steps. The first is to
|
||||
* check the 1st Level Cache in order to find an exact match, if we fail, we move to step 2.
|
||||
* Step 2 is checking if there are any overlaps at all, if none, we just load the texture from
|
||||
* memory else we move to step 3. Step 3 consists on figuring the relationship between the
|
||||
* candidate texture and the overlaps. We divide the scenarios depending if there's 1 or many
|
||||
* overlaps. If there's many, we just try to reconstruct a new surface out of them based on the
|
||||
* candidate's parameters, if we fail, we recycle. When there's only 1 overlap then we have to
|
||||
* check if the candidate is a view (layer/mipmap) of the overlap or if the registered surface
|
||||
* is a mipmap/layer of the candidate. In this last case we reconstruct a new surface.
|
||||
* @param gpu_addr, the starting address of the candidate surface.
|
||||
* @param params, the paremeters on the candidate surface.
|
||||
* @param preserve_contents, tells if the new surface should be loaded from meory or left blank.
|
||||
* Gets the starting address and parameters of a candidate surface and tries
|
||||
* to find a matching surface within the cache. This is done in 3 big steps:
|
||||
*
|
||||
* 1. Check the 1st Level Cache in order to find an exact match, if we fail, we move to step 2.
|
||||
*
|
||||
* 2. Check if there are any overlaps at all, if there are none, we just load the texture from
|
||||
* memory else we move to step 3.
|
||||
*
|
||||
* 3. Consists of figuring out the relationship between the candidate texture and the
|
||||
* overlaps. We divide the scenarios depending if there's 1 or many overlaps. If
|
||||
* there's many, we just try to reconstruct a new surface out of them based on the
|
||||
* candidate's parameters, if we fail, we recycle. When there's only 1 overlap then we
|
||||
* have to check if the candidate is a view (layer/mipmap) of the overlap or if the
|
||||
* registered surface is a mipmap/layer of the candidate. In this last case we reconstruct
|
||||
* a new surface.
|
||||
*
|
||||
* @param gpu_addr The starting address of the candidate surface.
|
||||
* @param params The parameters on the candidate surface.
|
||||
* @param preserve_contents Indicates that the new surface should be loaded from memory or
|
||||
* left blank.
|
||||
* @param is_render Whether or not the surface is a render target.
|
||||
**/
|
||||
std::pair<TSurface, TView> GetSurface(const GPUVAddr gpu_addr, const SurfaceParams& params,
|
||||
bool preserve_contents, bool is_render) {
|
||||
@@ -651,7 +668,7 @@ private:
|
||||
// Step 3
|
||||
// Now we need to figure the relationship between the texture and its overlaps
|
||||
// we do a topological test to ensure we can find some relationship. If it fails
|
||||
// inmediatly recycle the texture
|
||||
// immediately recycle the texture
|
||||
for (const auto& surface : overlaps) {
|
||||
const auto topological_result = surface->MatchesTopology(params);
|
||||
if (topological_result != MatchTopologyResult::FullMatch) {
|
||||
@@ -720,12 +737,13 @@ private:
|
||||
}
|
||||
|
||||
/**
|
||||
* `DeduceSurface` gets the starting address and parameters of a candidate surface and tries
|
||||
* to find a matching surface within the cache that's similar to it. If there are many textures
|
||||
* Gets the starting address and parameters of a candidate surface and tries to find a
|
||||
* matching surface within the cache that's similar to it. If there are many textures
|
||||
* or the texture found if entirely incompatible, it will fail. If no texture is found, the
|
||||
* blit will be unsuccessful.
|
||||
* @param gpu_addr, the starting address of the candidate surface.
|
||||
* @param params, the paremeters on the candidate surface.
|
||||
*
|
||||
* @param gpu_addr The starting address of the candidate surface.
|
||||
* @param params The parameters on the candidate surface.
|
||||
**/
|
||||
Deduction DeduceSurface(const GPUVAddr gpu_addr, const SurfaceParams& params) {
|
||||
const auto host_ptr{system.GPU().MemoryManager().GetPointer(gpu_addr)};
|
||||
@@ -777,11 +795,14 @@ private:
|
||||
}
|
||||
|
||||
/**
|
||||
* `DeduceBestBlit` gets the a source and destination starting address and parameters,
|
||||
* Gets the a source and destination starting address and parameters,
|
||||
* and tries to deduce if they are supposed to be depth textures. If so, their
|
||||
* parameters are modified and fixed into so.
|
||||
* @param gpu_addr, the starting address of the candidate surface.
|
||||
* @param params, the parameters on the candidate surface.
|
||||
*
|
||||
* @param src_params The parameters of the candidate surface.
|
||||
* @param dst_params The parameters of the destination surface.
|
||||
* @param src_gpu_addr The starting address of the candidate surface.
|
||||
* @param dst_gpu_addr The starting address of the destination surface.
|
||||
**/
|
||||
void DeduceBestBlit(SurfaceParams& src_params, SurfaceParams& dst_params,
|
||||
const GPUVAddr src_gpu_addr, const GPUVAddr dst_gpu_addr) {
|
||||
|
||||
@@ -245,10 +245,24 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
||||
|
||||
button->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(button, &QPushButton::clicked, [=] {
|
||||
HandleClick(
|
||||
button_map[button_id],
|
||||
[=](const Common::ParamPackage& params) { buttons_param[button_id] = params; },
|
||||
InputCommon::Polling::DeviceType::Button);
|
||||
HandleClick(button_map[button_id],
|
||||
[=](Common::ParamPackage params) {
|
||||
// Workaround for ZL & ZR for analog triggers like on XBOX controllors.
|
||||
// Analog triggers (from controllers like the XBOX controller) would not
|
||||
// work due to a different range of their signals (from 0 to 255 on
|
||||
// analog triggers instead of -32768 to 32768 on analog joysticks). The
|
||||
// SDL driver misinterprets analog triggers as analog joysticks.
|
||||
// TODO: reinterpret the signal range for analog triggers to map the
|
||||
// values correctly. This is required for the correct emulation of the
|
||||
// analog triggers of the GameCube controller.
|
||||
if (button_id == Settings::NativeButton::ZL ||
|
||||
button_id == Settings::NativeButton::ZR) {
|
||||
params.Set("direction", "+");
|
||||
params.Set("threshold", "0.5");
|
||||
}
|
||||
buttons_param[button_id] = std::move(params);
|
||||
},
|
||||
InputCommon::Polling::DeviceType::Button);
|
||||
});
|
||||
connect(button, &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) {
|
||||
QMenu context_menu;
|
||||
|
||||
Reference in New Issue
Block a user