Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ struct TraceSummary {
std::uint64_t firstPresent = 0;
double gpuBusyMs = 0;
std::uint64_t ownedDrawUnbound = 0;
std::uint64_t ownedStorageUnbound = 0;
std::string trace;
std::optional<std::pair<double, double>> interval;
std::optional<TraceHost> host;
Expand Down Expand Up @@ -696,8 +697,10 @@ class TraceFormat {
std::map<std::string, Clock::duration> waitedPhases;
std::map<std::string, std::uint64_t> ownedCounts;
std::map<std::string, std::uint64_t> graphicsCounts;
bool dropped = summary.ownedDrawUnbound != 0;
std::map<std::string, std::uint64_t> storageCounts;
bool dropped = summary.ownedDrawUnbound != 0 || summary.ownedStorageUnbound != 0;
if (summary.ownedDrawUnbound != 0) ownedCounts["OwnedDraw.unbound"] = summary.ownedDrawUnbound;
if (summary.ownedStorageUnbound != 0) storageCounts["OwnedStorage.unbound"] = summary.ownedStorageUnbound;
struct DroppedThread {
std::string name;
std::uint64_t eventsLost = 0;
Expand All @@ -720,6 +723,7 @@ class TraceFormat {
if (total.stage == nullptr && std::find(WorkerBusyScopes.begin(), WorkerBusyScopes.end(), scope) != WorkerBusyScopes.end()) busy += total.length;
if (total.stage == nullptr && GraphicsTrackScope(scope)) graphicsCounts[std::string(scope)] += total.count;
else if (scope.starts_with("OwnedDraw.") && total.stage == nullptr) ownedCounts[std::string(scope)] += total.count;
else if (scope.starts_with("OwnedStorage.") && total.stage == nullptr) storageCounts[std::string(scope)] += total.count;
else if (scope != WorkerWaitScope) {
const auto name = Name(total.scope, total.stage);
phases[name] += total.length;
Expand Down Expand Up @@ -777,6 +781,15 @@ class TraceFormat {
output += ':' + std::to_string(value);
}
output += '}';
output += ",\"owned_storage_counts\":{";
firstCount = true;
for (const auto& [name, value] : storageCounts) {
if (!firstCount) output += ',';
firstCount = false;
AppendString(output, name);
output += ':' + std::to_string(value);
}
output += '}';
output += ",\"graphics_track\":{";
bool firstGraphics = true;
for (const auto& [name, value] : graphicsCounts) {
Expand Down Expand Up @@ -962,6 +975,7 @@ class PerformanceTrace {

static void CountOwnedDraw(const char* scope, std::uint64_t amount = 1);
static std::uint64_t OwnedDrawUnbound();
static std::uint64_t OwnedStorageUnbound();

static void SetOverlayTotals(bool on);
static bool OverlayTotals();
Expand All @@ -980,6 +994,7 @@ class PerformanceTrace {

static std::atomic<bool> recording;
static std::atomic<std::uint64_t> ownedDrawUnbound;
static std::atomic<std::uint64_t> ownedStorageUnbound;
inline static std::atomic<bool> buffering{false};
inline static std::atomic<std::uint64_t> presentCount{0};
static thread_local TraceThread* local;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ struct Session {
bool windowOpen = false;
std::vector<std::vector<TraceThread::Total>> windowBase;
std::uint64_t windowOwnedUnbound = 0;
std::uint64_t windowStorageUnbound = 0;
std::optional<TraceInterval> interval;
bool intervalOpen = false;
std::uint64_t intervalFirstPresent = 0;
double intervalGpuBusy = 0;
std::vector<std::vector<TraceThread::Total>> intervalBase;
std::uint64_t intervalOwnedUnbound = 0;
std::uint64_t intervalStorageUnbound = 0;
std::vector<Clock::time_point> intervalPresents;
Clock::time_point first{};
std::uint64_t present = 0;
Expand Down Expand Up @@ -269,6 +271,7 @@ void PerformanceTrace::OpenInterval(Clock::time_point now, std::uint64_t present
state.intervalFirstPresent = present;
state.intervalGpuBusy = VulkanDevice::PresentCounts().gpuBusyMs;
state.intervalOwnedUnbound = OwnedDrawUnbound();
state.intervalStorageUnbound = OwnedStorageUnbound();
state.intervalPresents.assign(1, now);
if (summaryWriter()) return;
summaryWriter() = std::make_unique<ProfileOutput>([directory = traceDirectory()](std::string_view text) {
Expand Down Expand Up @@ -298,6 +301,7 @@ void PerformanceTrace::FlushInterval(Clock::time_point now, std::uint32_t width,
}
auto summary = identity(width, height, device);
summary.ownedDrawUnbound = OwnedDrawUnbound() - state.intervalOwnedUnbound;
summary.ownedStorageUnbound = OwnedStorageUnbound() - state.intervalStorageUnbound;
summary.window = state.interval->Describe();
summary.firstPresent = state.intervalFirstPresent;
summary.gpuBusyMs = VulkanDevice::PresentCounts().gpuBusyMs - state.intervalGpuBusy;
Expand Down Expand Up @@ -351,6 +355,7 @@ void PerformanceTrace::Present(std::uint32_t width, std::uint32_t height, const
state.windowOpen = true;
state.windowBase = totalsOf(state.threads);
state.windowOwnedUnbound = OwnedDrawUnbound();
state.windowStorageUnbound = OwnedStorageUnbound();
state.firstPresent = present;
state.gpuBusyAtOpen = VulkanDevice::PresentCounts().gpuBusyMs;
TraceClockSample clock;
Expand Down Expand Up @@ -399,6 +404,7 @@ void PerformanceTrace::Present(std::uint32_t width, std::uint32_t height, const
const auto process = processId();
auto summary = identity(width, height, device);
summary.ownedDrawUnbound = OwnedDrawUnbound() - state.windowOwnedUnbound;
summary.ownedStorageUnbound = OwnedStorageUnbound() - state.windowStorageUnbound;
summary.window = state.window->Describe();
summary.firstPresent = state.firstPresent;
summary.gpuBusyMs = VulkanDevice::PresentCounts().gpuBusyMs - state.gpuBusyAtOpen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ namespace AgcDriver {

std::atomic<bool> PerformanceTrace::recording{false};
std::atomic<std::uint64_t> PerformanceTrace::ownedDrawUnbound{0};
std::atomic<std::uint64_t> PerformanceTrace::ownedStorageUnbound{0};

void PerformanceTrace::CountOwnedDraw(const char* scope, std::uint64_t amount) {
if (amount == 0 || !Recording()) return;
if (auto* thread = Thread()) thread->Count(scope, amount);
else if (std::string_view(scope).starts_with("OwnedStorage.")) ownedStorageUnbound.fetch_add(1, std::memory_order_relaxed);
else ownedDrawUnbound.fetch_add(1, std::memory_order_relaxed);
}

std::uint64_t PerformanceTrace::OwnedDrawUnbound() {
return ownedDrawUnbound.load(std::memory_order_relaxed);
}
std::uint64_t PerformanceTrace::OwnedStorageUnbound() {
return ownedStorageUnbound.load(std::memory_order_relaxed);
}

thread_local TraceThread* PerformanceTrace::local = nullptr;
thread_local const char* PerformanceTrace::localName = nullptr;
std::atomic<TraceThread* (*)()> PerformanceTrace::binder{nullptr};
Expand Down
4 changes: 2 additions & 2 deletions core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class Recorder {
std::uint64_t note = 0;
};
std::size_t OwnedDrawInputEntries() const { return ownedDrawInputs; }
OwnedDrawInputProof ArmOwnedDrawInput(std::uint64_t address, std::size_t bytes) const;
OwnedDrawInputProof ArmOwnedDrawInput(std::uint64_t address, std::size_t bytes, SnapshotUse use) const;
std::shared_ptr<Buffer> ReusableOwnedDrawInput(std::uint64_t address, std::size_t bytes, SnapshotUse use, std::uint32_t* derived, std::size_t from = 0, std::uint32_t* lowest = nullptr);
void KeepOwnedDrawInput(std::uint64_t address, std::size_t bytes, const OwnedDrawInputProof& proof, std::shared_ptr<Buffer> buffer, SnapshotUse use, std::uint32_t derived, std::size_t from = 0, std::uint32_t lowest = 0);
static constexpr std::size_t ContainingSnapshotProbes = 16;
Expand Down Expand Up @@ -1165,7 +1165,7 @@ class Recorder {
};
std::map<DrawSnapshotKey, IndexRange> indexRanges;
std::list<DrawSnapshotKey> indexRangeRecency;
bool ownedDrawInputHolds(std::uint64_t address, std::size_t bytes, const OwnedDrawInputProof& proof) const;
bool ownedDrawInputHolds(std::uint64_t address, std::size_t bytes, const OwnedDrawInputProof& proof, SnapshotUse use) const;
bool refreshDrawSnapshot(DrawSnapshot& entry, std::uint64_t address, std::size_t bytes);
std::shared_ptr<Buffer> containingDrawSnapshot(std::uint64_t address, std::size_t bytes, VkDeviceSize* offset);
mutable std::weak_ptr<const WriteRanges> publishedWriteRanges;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ enum class RuntimeSwitch : std::size_t {
NoAliasViews,
NoTargetMemo,
NoTargetMemoOverlapCache,
NoOwnedDrawSnapshots,
NoStagePoolReuse,
IndexInPlaceBehindWriter,
WideLibraryKeys,
Expand Down
2 changes: 1 addition & 1 deletion core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,7 @@ DrawInputCopy CopyDrawInput(const Context& context, Recorder* recorder, std::uin
copy.registryGeneration = GuestAllocations::GuestAllocationsGeneration_nid_postfix();
copy.generation = GuestMemory::CollectWrites(address, bytes);
if (copy.generation != 0) copy.buffer = recorder->ReusableDrawSnapshot(address, bytes, use, &copy.derived, 0, nullptr, from, &copy.lowest, !hostOnly);
else if (owned) copy.owned = recorder->ArmOwnedDrawInput(address, bytes);
else if (owned) copy.owned = recorder->ArmOwnedDrawInput(address, bytes, use);
if (copy.buffer != nullptr) {
copy.reused = true;
return copy;
Expand Down
43 changes: 22 additions & 21 deletions core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3847,7 +3847,7 @@ std::shared_ptr<Buffer> Recorder::containingDrawSnapshot(std::uint64_t address,
for (std::size_t probe = 0; probe < ContainingSnapshotProbes && entry != drawSnapshots.begin(); ++probe) {
--entry;
const auto& [start, use, held] = entry->first;
if (use != SnapshotUse::Storage || start + held < address + bytes || (address - start) % alignment != 0) continue;
if (use != SnapshotUse::Storage || !entry->second.owned.words.empty() || start + held < address + bytes || (address - start) % alignment != 0) continue;
if (entry->second.registryGeneration != registry || !GuestMemory::UnchangedSince(address, bytes, entry->second.generation)) continue;
auto& recency = drawSnapshotPools[SnapshotPool(use)].recency;
recency.splice(recency.end(), recency, entry->second.recent);
Expand Down Expand Up @@ -3922,8 +3922,11 @@ void Recorder::KeepDrawSnapshot(std::uint64_t address, std::size_t bytes, std::u
}
while (!pool.recency.empty() && (pool.bytes + bytes > budget || pool.recency.size() >= maxEntries)) {
const auto victim = drawSnapshots.find(pool.recency.front());
if (!storage) {
const bool ownedVictim = !victim->second.owned.words.empty();
const bool ownedVictim = !victim->second.owned.words.empty();
if (storage) {
OwnedDrawTraceCount(ownedVictim ? "OwnedStorage.evicted_owned" : "OwnedStorage.evicted_other");
if (ownedInsertion) OwnedDrawTraceCount(ownedVictim ? "OwnedStorage.evicted_owned_by_owned" : "OwnedStorage.evicted_other_by_owned");
} else {
OwnedDrawTraceCount(ownedVictim ? "OwnedDraw.evicted_owned" : "OwnedDraw.evicted_other");
if (ownedInsertion) OwnedDrawTraceCount(ownedVictim ? "OwnedDraw.evicted_owned_by_owned" : "OwnedDraw.evicted_other_by_owned");
}
Expand All @@ -3940,58 +3943,57 @@ void Recorder::KeepDrawSnapshot(std::uint64_t address, std::size_t bytes, std::u
pool.bytes += bytes;
}

Recorder::OwnedDrawInputProof Recorder::ArmOwnedDrawInput(std::uint64_t address, std::size_t bytes) const {
Recorder::OwnedDrawInputProof Recorder::ArmOwnedDrawInput(std::uint64_t address, std::size_t bytes, SnapshotUse use) const {
GuestMemory::AssertGpuLockHeld("arm owned draw input");
OwnedDrawTraceCount("OwnedDraw.arm_attempt");
OwnedDrawTraceCount(use == SnapshotUse::Storage ? "OwnedStorage.arm_attempt" : "OwnedDraw.arm_attempt");
if (bytes == 0 || bytes > DrawInputBudget || bytes > std::numeric_limits<std::uint64_t>::max() - address || !GuestMemory::WriteWatched() || PendingWriteOverlaps(address, bytes)) {
OwnedDrawTraceCount("OwnedDraw.arm_refused");
OwnedDrawTraceCount(use == SnapshotUse::Storage ? "OwnedStorage.arm_refused" : "OwnedDraw.arm_refused");
return {};
}
OwnedDrawInputProof proof;
proof.words.resize((address + bytes - 1) / 65536 - address / 65536 + 1);
OwnedDrawTraceCount("OwnedDraw.arm_blocks_requested", proof.words.size());
OwnedDrawTraceCount(use == SnapshotUse::Storage ? "OwnedStorage.arm_blocks_requested" : "OwnedDraw.arm_blocks_requested", proof.words.size());
if (!GuestArena::GuestArenaArmOwned_nid_no_patch(static_cast<std::uintptr_t>(address), bytes, proof.words.data(), proof.words.size(), 1)) {
OwnedDrawTraceCount("OwnedDraw.arm_refused");
OwnedDrawTraceCount(use == SnapshotUse::Storage ? "OwnedStorage.arm_refused" : "OwnedDraw.arm_refused");
return {};
}
proof.registry = GuestAllocations::GuestAllocationsGeneration_nid_postfix();
proof.forget = GuestMemory::ForgetSerial();
proof.since = GuestMemory::TrackerGeneration();
proof.note = NewestWriteNote(address, bytes);
if (proof.since == 0 || (proof.forget & 1u) != 0) {
OwnedDrawTraceCount("OwnedDraw.arm_refused");
OwnedDrawTraceCount(use == SnapshotUse::Storage ? "OwnedStorage.arm_refused" : "OwnedDraw.arm_refused");
return {};
}
OwnedDrawTraceCount("OwnedDraw.arm_success");
OwnedDrawTraceCount(use == SnapshotUse::Storage ? "OwnedStorage.arm_success" : "OwnedDraw.arm_success");
return proof;
}

bool Recorder::ownedDrawInputHolds(std::uint64_t address, std::size_t bytes, const OwnedDrawInputProof& proof) const {
bool Recorder::ownedDrawInputHolds(std::uint64_t address, std::size_t bytes, const OwnedDrawInputProof& proof, SnapshotUse use) const {
GuestMemory::AssertGpuLockHeld("check owned draw input");
OwnedDrawTraceCount("OwnedDraw.proof_check");
OwnedDrawTraceCount(use == SnapshotUse::Storage ? "OwnedStorage.proof_check" : "OwnedDraw.proof_check");
if (proof.words.empty() || proof.since == 0 || (proof.forget & 1u) != 0 || !GuestMemory::WriteWatched()) return false;
if (proof.registry != GuestAllocations::GuestAllocationsGeneration_nid_postfix() || proof.forget != GuestMemory::ForgetSerial()) return false;
if (PendingWriteOverlaps(address, bytes) || proof.note != NewestWriteNote(address, bytes) || GuestMemory::NewestStamp(address, bytes) > proof.since) return false;
OwnedDrawTraceCount("OwnedDraw.arena_check");
OwnedDrawTraceCount("OwnedDraw.check_blocks_requested", proof.words.size());
OwnedDrawTraceCount(use == SnapshotUse::Storage ? "OwnedStorage.arena_check" : "OwnedDraw.arena_check");
OwnedDrawTraceCount(use == SnapshotUse::Storage ? "OwnedStorage.check_blocks_requested" : "OwnedDraw.check_blocks_requested", proof.words.size());
return GuestArena::GuestArenaOwnedUnchanged_nid_no_patch(static_cast<std::uintptr_t>(address), bytes, proof.words.data(), proof.words.size());
}

std::shared_ptr<Buffer> Recorder::ReusableOwnedDrawInput(std::uint64_t address, std::size_t bytes, SnapshotUse use, std::uint32_t* derived, std::size_t from, std::uint32_t* lowest) {
GuestMemory::AssertGpuLockHeld("reuse owned draw input");
Require(use != SnapshotUse::Storage, "an owned draw input is a vertex or index buffer");
const auto found = drawSnapshots.find({address, use, bytes});
if (found == drawSnapshots.end() || found->second.owned.words.empty() || found->second.from > from) return {};
if (!ownedDrawInputHolds(address, bytes, found->second.owned)) {
OwnedDrawTraceCount("OwnedDraw.invalidated");
if (!ownedDrawInputHolds(address, bytes, found->second.owned, use)) {
OwnedDrawTraceCount(use == SnapshotUse::Storage ? "OwnedStorage.invalidated" : "OwnedDraw.invalidated");
eraseDrawSnapshot(found);
return {};
}
static const bool verify = std::getenv("APS5_VERIFY_OWNED_DRAW_INPUTS") != nullptr;
if (verify) {
const auto held = found->second.from;
const bool equal = GuestMemory::EqualsCommittedUnsynced(address + held, found->second.buffer->Bytes().subspan(held));
if (!ownedDrawInputHolds(address, bytes, found->second.owned)) {
if (!ownedDrawInputHolds(address, bytes, found->second.owned, use)) {
eraseDrawSnapshot(found);
return {};
}
Expand All @@ -4001,13 +4003,12 @@ std::shared_ptr<Buffer> Recorder::ReusableOwnedDrawInput(std::uint64_t address,
recency.splice(recency.end(), recency, found->second.recent);
if (derived != nullptr) *derived = found->second.derived;
if (lowest != nullptr) *lowest = found->second.lowest;
OwnedDrawTraceCount("OwnedDraw.reused");
OwnedDrawTraceCount(use == SnapshotUse::Storage ? "OwnedStorage.reused" : "OwnedDraw.reused");
return found->second.buffer;
}

void Recorder::KeepOwnedDrawInput(std::uint64_t address, std::size_t bytes, const OwnedDrawInputProof& proof, std::shared_ptr<Buffer> buffer, SnapshotUse use, std::uint32_t derived, std::size_t from, std::uint32_t lowest) {
Require(use != SnapshotUse::Storage, "an owned draw input is a vertex or index buffer");
if (buffer == nullptr || buffer->Bytes().size() != bytes || !ownedDrawInputHolds(address, bytes, proof)) return;
if (buffer == nullptr || buffer->Bytes().size() != bytes || !ownedDrawInputHolds(address, bytes, proof, use)) return;
auto kept = proof;
KeepDrawSnapshot(address, bytes, proof.since, proof.registry, std::move(buffer), use, derived, from, lowest, true);
if (const auto found = drawSnapshots.find({address, use, bytes}); found != drawSnapshots.end()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ constexpr std::array<const char*, SwitchCount> SwitchNames{
"APS5_NO_ALIAS_VIEWS",
"APS5_NO_TARGET_MEMO",
"APS5_NO_TARGET_MEMO_OVERLAP_CACHE",
"APS5_NO_OWNED_DRAW_SNAPSHOTS",
"APS5_NO_STAGE_POOL_REUSE",
"APS5_INDEX_IN_PLACE_BEHIND_WRITER",
"APS5_WIDE_LIBRARY_KEYS",
Expand Down Expand Up @@ -61,6 +62,7 @@ struct SwitchValues {
std::getenv("APS5_NO_ALIAS_VIEWS") != nullptr,
std::getenv("APS5_NO_TARGET_MEMO") != nullptr,
std::getenv("APS5_NO_TARGET_MEMO_OVERLAP_CACHE") != nullptr,
std::getenv("APS5_NO_OWNED_DRAW_SNAPSHOTS") != nullptr,
std::getenv("APS5_NO_STAGE_POOL_REUSE") != nullptr,
std::getenv("APS5_INDEX_IN_PLACE_BEHIND_WRITER") != nullptr,
std::getenv("APS5_WIDE_LIBRARY_KEYS") != nullptr,
Expand Down
Loading
Loading