From 8bf08ed66f73898426f00835def9e25054148a71 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sun, 15 Nov 2020 19:44:13 +0000 Subject: [PATCH] Fix CircularQueue and improve debug logging + exefs loading CircularQueue was looping around too early resulting in the wrong pushbuffers being used. The debug logging is useful for interpreting the GPU method call logs. Exefs loading was changed to check if an NSO exists before trying to read it, preventing exceptions that get annoying while debugging. --- .../main/cpp/skyline/common/circular_queue.h | 23 ++++++++----------- .../cpp/skyline/gpu/engines/maxwell_3d.cpp | 1 + app/src/main/cpp/skyline/gpu/gpfifo.cpp | 2 ++ app/src/main/cpp/skyline/gpu/gpfifo.h | 6 ++++- app/src/main/cpp/skyline/loader/nca.cpp | 6 ++--- .../cpp/skyline/services/hid/IHidServer.cpp | 5 +++- .../skyline/services/nvdrv/INvDrvServices.cpp | 2 +- 7 files changed, 25 insertions(+), 20 deletions(-) diff --git a/app/src/main/cpp/skyline/common/circular_queue.h b/app/src/main/cpp/skyline/common/circular_queue.h index 2ab64095..637b5db3 100644 --- a/app/src/main/cpp/skyline/common/circular_queue.h +++ b/app/src/main/cpp/skyline/common/circular_queue.h @@ -69,28 +69,24 @@ namespace skyline { inline void Push(const Type &item) { std::unique_lock lock(productionMutex); - auto next{end + 1}; - next = (next == reinterpret_cast(vector.end().base())) ? reinterpret_cast(vector.begin().base()) : next; - if (next == start) { + end = (end == reinterpret_cast(vector.end().base()) - 1) ? reinterpret_cast(vector.begin().base()) : end; + if (start == end + 1) { std::unique_lock consumeLock(consumptionMutex); - consumeCondition.wait(consumeLock, [=]() { return next != start; }); + consumeCondition.wait(consumeLock, [=]() { return start != end + 1; }); } - *next = item; - end = next; + *end = item; produceCondition.notify_one(); } inline void Append(span buffer) { std::unique_lock lock(productionMutex); for (auto &item : buffer) { - auto next{end + 1}; - next = (next == reinterpret_cast(vector.end().base())) ? reinterpret_cast(vector.begin().base()) : next; - if (next == start) { + end = (end == reinterpret_cast(vector.end().base()) - 1) ? reinterpret_cast(vector.begin().base()) : end; + if (start == end + 1) { std::unique_lock consumeLock(consumptionMutex); - consumeCondition.wait(consumeLock, [=]() { return next != start; }); + consumeCondition.wait(consumeLock, [=]() { return start != end + 1; }); } - *next = item; - end = next; + *(end++) = item; } produceCondition.notify_one(); } @@ -102,9 +98,8 @@ namespace skyline { template inline void AppendTranform(span buffer, Transformation transformation) { std::unique_lock lock(productionMutex); - auto next{end}; for (auto &item : buffer) { - end = (end == reinterpret_cast(vector.end().base())) ? reinterpret_cast(vector.begin().base()) : end; + end = (end == reinterpret_cast(vector.end().base()) - 1) ? reinterpret_cast(vector.begin().base()) : end; if (start == end + 1) { std::unique_lock consumeLock(consumptionMutex); consumeCondition.wait(consumeLock, [=]() { return start != end + 1; }); diff --git a/app/src/main/cpp/skyline/gpu/engines/maxwell_3d.cpp b/app/src/main/cpp/skyline/gpu/engines/maxwell_3d.cpp index e273056e..ec25bff5 100644 --- a/app/src/main/cpp/skyline/gpu/engines/maxwell_3d.cpp +++ b/app/src/main/cpp/skyline/gpu/engines/maxwell_3d.cpp @@ -117,6 +117,7 @@ namespace skyline::gpu::engine { shadowRegisters.mme.shadowRamControl = static_cast(params.argument); break; case MAXWELL3D_OFFSET(syncpointAction): + state.logger->Debug("Increment syncpoint: {}", static_cast(registers.syncpointAction.id)); state.gpu->syncpoints.at(registers.syncpointAction.id).Increment(); break; case MAXWELL3D_OFFSET(semaphore.info): diff --git a/app/src/main/cpp/skyline/gpu/gpfifo.cpp b/app/src/main/cpp/skyline/gpu/gpfifo.cpp index 66aff668..b72f67df 100644 --- a/app/src/main/cpp/skyline/gpu/gpfifo.cpp +++ b/app/src/main/cpp/skyline/gpu/gpfifo.cpp @@ -93,6 +93,8 @@ namespace skyline::gpu::gpfifo { pushBuffers->Process([this](PushBuffer &pushBuffer) { if (pushBuffer.segment.empty()) pushBuffer.Fetch(state.gpu->memoryManager); + + state.logger->Debug("Processing pushbuffer: 0x{:X}", pushBuffer.gpEntry.Address()); Process(pushBuffer.segment); }); } catch (const signal::SignalException &e) { diff --git a/app/src/main/cpp/skyline/gpu/gpfifo.h b/app/src/main/cpp/skyline/gpu/gpfifo.h index 058faa91..e20fd2dc 100644 --- a/app/src/main/cpp/skyline/gpu/gpfifo.h +++ b/app/src/main/cpp/skyline/gpu/gpfifo.h @@ -67,6 +67,10 @@ namespace skyline::gpu { Sync sync : 1; }; }; + + constexpr u64 Address() { + return (static_cast(getHi) << 32) | (static_cast(get) << 2); + } }; static_assert(sizeof(GpEntry) == sizeof(u64)); @@ -140,7 +144,7 @@ namespace skyline::gpu { inline void Fetch(const vmm::MemoryManager &memoryManager) { segment.resize(gpEntry.size); - memoryManager.Read(segment, (static_cast(gpEntry.getHi) << 32) | (static_cast(gpEntry.get) << 2)); + memoryManager.Read(segment, gpEntry.Address()); } }; diff --git a/app/src/main/cpp/skyline/loader/nca.cpp b/app/src/main/cpp/skyline/loader/nca.cpp index 5a4359f0..88a7dcc1 100644 --- a/app/src/main/cpp/skyline/loader/nca.cpp +++ b/app/src/main/cpp/skyline/loader/nca.cpp @@ -29,9 +29,9 @@ namespace skyline::loader { state.logger->Info("Loaded nso 'rtld' at 0x{:X} (.text @ 0x{:X})", base, entry); for (const auto &nso : {"main", "subsdk0", "subsdk1", "subsdk2", "subsdk3", "subsdk4", "subsdk5", "subsdk6", "subsdk7", "sdk"}) { - nsoFile = exeFs->OpenFile(nso); - - if (nsoFile == nullptr) + if (exeFs->FileExists(nso)) + nsoFile = exeFs->OpenFile(nso); + else continue; loadInfo = NsoLoader::LoadNso(nsoFile, process, state, offset); diff --git a/app/src/main/cpp/skyline/services/hid/IHidServer.cpp b/app/src/main/cpp/skyline/services/hid/IHidServer.cpp index 372f8ba9..91e84eed 100644 --- a/app/src/main/cpp/skyline/services/hid/IHidServer.cpp +++ b/app/src/main/cpp/skyline/services/hid/IHidServer.cpp @@ -61,7 +61,10 @@ namespace skyline::service::hid { Result IHidServer::AcquireNpadStyleSetUpdateEventHandle(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { auto id{request.Pop()}; - response.copyHandles.push_back(state.process->InsertItem(state.input->npad.at(id).updateEvent)); + auto handle{state.process->InsertItem(state.input->npad.at(id).updateEvent)}; + + state.logger->Debug("Npad {} Style Set Update Event Handle: 0x{:X}", id, handle); + response.copyHandles.push_back(handle); return {}; } diff --git a/app/src/main/cpp/skyline/services/nvdrv/INvDrvServices.cpp b/app/src/main/cpp/skyline/services/nvdrv/INvDrvServices.cpp index 97621a8c..94f02cd7 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/INvDrvServices.cpp +++ b/app/src/main/cpp/skyline/services/nvdrv/INvDrvServices.cpp @@ -76,7 +76,7 @@ namespace skyline::service::nvdrv { if (event != nullptr) { auto handle{state.process->InsertItem(event)}; - state.logger->Debug("QueryEvent: FD: {}, Event ID: {}, Handle: {}", fd, eventId, handle); + state.logger->Debug("QueryEvent: FD: {}, Event ID: {}, Handle: 0x{:X}", fd, eventId, handle); response.copyHandles.push_back(handle); response.Push(device::NvStatus::Success);