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
1 change: 1 addition & 0 deletions core/libs/prx/libSceAgcDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ set(agcDriverSources
${CMAKE_CURRENT_SOURCE_DIR}/Graphics/src/PipelineJournal.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Graphics/src/RuntimeSwitches.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Graphics/src/Resources.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Graphics/src/CommandCheckpoints.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Graphics/src/DeferredDestruction.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Graphics/src/MemoryAccounting.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Graphics/src/PlaceholderImages.cpp
Expand Down
26 changes: 18 additions & 8 deletions core/libs/prx/libSceAgcDriver/Execution/include/DeviceFault.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,17 @@ inline std::vector<std::string> DeviceFaultReport(VkDevice device, PFN_vkGetDevi
for (const auto& point : points) {
const FaultToken token = static_cast<FaultToken>(reinterpret_cast<std::uintptr_t>(point.pCheckpointMarker));
const auto found = ring.Find(token);
if (!found.has_value()) {
std::snprintf(checkpoint, sizeof(checkpoint), "[device-fault] checkpoint: unknown token %u queue 0x%llx", static_cast<unsigned>(token), static_cast<unsigned long long>(reinterpret_cast<std::uintptr_t>(queue)));
const auto kind = CheckpointKindOf(point.pCheckpointMarker);
const std::string lead = kind == CheckpointKind::none ? std::string() : std::string(CheckpointKindName(kind)) + " after ";
if (kind != CheckpointKind::none && token == 0) {
std::snprintf(checkpoint, sizeof(checkpoint), "[device-fault] checkpoint: %s, no guest token before it on its command buffer, queue 0x%llx", CheckpointKindName(kind), static_cast<unsigned long long>(reinterpret_cast<std::uintptr_t>(queue)));
} else if (!found.has_value()) {
if (kind != CheckpointKind::none) std::snprintf(checkpoint, sizeof(checkpoint), "[device-fault] checkpoint: %s after token %u, no longer in the ring, queue 0x%llx", CheckpointKindName(kind), static_cast<unsigned>(token), static_cast<unsigned long long>(reinterpret_cast<std::uintptr_t>(queue)));
else std::snprintf(checkpoint, sizeof(checkpoint), "[device-fault] checkpoint: unknown token %u queue 0x%llx", static_cast<unsigned>(token), static_cast<unsigned long long>(reinterpret_cast<std::uintptr_t>(queue)));
} else {
const std::size_t descLength = strnlen(found->desc, sizeof(found->desc));
if (descLength == 0) std::snprintf(checkpoint, sizeof(checkpoint), "[device-fault] checkpoint: token %u batch %llu queue 0x%llx program 0x%llx variant %llu", static_cast<unsigned>(token), static_cast<unsigned long long>(found->submitSerial), static_cast<unsigned long long>(reinterpret_cast<std::uintptr_t>(queue)), static_cast<unsigned long long>(found->programAddress), static_cast<unsigned long long>(found->variantId));
else std::snprintf(checkpoint, sizeof(checkpoint), "[device-fault] checkpoint: token %u batch %llu queue 0x%llx program 0x%llx variant %llu %.*s", static_cast<unsigned>(token), static_cast<unsigned long long>(found->submitSerial), static_cast<unsigned long long>(reinterpret_cast<std::uintptr_t>(queue)), static_cast<unsigned long long>(found->programAddress), static_cast<unsigned long long>(found->variantId), static_cast<int>(descLength), found->desc);
if (descLength == 0) std::snprintf(checkpoint, sizeof(checkpoint), "[device-fault] checkpoint: %stoken %u batch %llu queue 0x%llx program 0x%llx variant %llu", lead.c_str(), static_cast<unsigned>(token), static_cast<unsigned long long>(found->submitSerial), static_cast<unsigned long long>(reinterpret_cast<std::uintptr_t>(queue)), static_cast<unsigned long long>(found->programAddress), static_cast<unsigned long long>(found->variantId));
else std::snprintf(checkpoint, sizeof(checkpoint), "[device-fault] checkpoint: %stoken %u batch %llu queue 0x%llx program 0x%llx variant %llu %.*s", lead.c_str(), static_cast<unsigned>(token), static_cast<unsigned long long>(found->submitSerial), static_cast<unsigned long long>(reinterpret_cast<std::uintptr_t>(queue)), static_cast<unsigned long long>(found->programAddress), static_cast<unsigned long long>(found->variantId), static_cast<int>(descLength), found->desc);
}
DeviceFaultAppendStage(checkpoint, sizeof(checkpoint), point.stage);
lines.emplace_back(checkpoint);
Expand Down Expand Up @@ -563,13 +568,18 @@ inline std::vector<std::string> DeviceFaultReport(VkDevice device, PFN_vkGetDevi
for (const auto& point : points) {
const FaultToken token = static_cast<FaultToken>(reinterpret_cast<std::uintptr_t>(point.pCheckpointMarker));
const auto found = ring.Find(token);
if (!found.has_value()) {
std::snprintf(checkpoint, sizeof(checkpoint), "[device-fault] checkpoint: unknown token %u queue 0x%llx", static_cast<unsigned>(token), static_cast<unsigned long long>(reinterpret_cast<std::uintptr_t>(queue)));
const auto kind = CheckpointKindOf(point.pCheckpointMarker);
const std::string lead = kind == CheckpointKind::none ? std::string() : std::string(CheckpointKindName(kind)) + " after ";
if (kind != CheckpointKind::none && token == 0) {
std::snprintf(checkpoint, sizeof(checkpoint), "[device-fault] checkpoint: %s, no guest token before it on its command buffer, queue 0x%llx", CheckpointKindName(kind), static_cast<unsigned long long>(reinterpret_cast<std::uintptr_t>(queue)));
} else if (!found.has_value()) {
if (kind != CheckpointKind::none) std::snprintf(checkpoint, sizeof(checkpoint), "[device-fault] checkpoint: %s after token %u, no longer in the ring, queue 0x%llx", CheckpointKindName(kind), static_cast<unsigned>(token), static_cast<unsigned long long>(reinterpret_cast<std::uintptr_t>(queue)));
else std::snprintf(checkpoint, sizeof(checkpoint), "[device-fault] checkpoint: unknown token %u queue 0x%llx", static_cast<unsigned>(token), static_cast<unsigned long long>(reinterpret_cast<std::uintptr_t>(queue)));
} else {
const char* stage = DeviceFaultStageName(found->stage);
const std::size_t descLength = strnlen(found->desc, sizeof(found->desc));
if (descLength == 0) std::snprintf(checkpoint, sizeof(checkpoint), "[device-fault] checkpoint: token %u batch %llu queue 0x%llx program 0x%llx variant %llu stage %s", static_cast<unsigned>(token), static_cast<unsigned long long>(found->submitSerial), static_cast<unsigned long long>(reinterpret_cast<std::uintptr_t>(queue)), static_cast<unsigned long long>(found->programAddress), static_cast<unsigned long long>(found->variantId), stage);
else std::snprintf(checkpoint, sizeof(checkpoint), "[device-fault] checkpoint: token %u batch %llu queue 0x%llx program 0x%llx variant %llu stage %s %.*s", static_cast<unsigned>(token), static_cast<unsigned long long>(found->submitSerial), static_cast<unsigned long long>(reinterpret_cast<std::uintptr_t>(queue)), static_cast<unsigned long long>(found->programAddress), static_cast<unsigned long long>(found->variantId), stage, static_cast<int>(descLength), found->desc);
if (descLength == 0) std::snprintf(checkpoint, sizeof(checkpoint), "[device-fault] checkpoint: %stoken %u batch %llu queue 0x%llx program 0x%llx variant %llu stage %s", lead.c_str(), static_cast<unsigned>(token), static_cast<unsigned long long>(found->submitSerial), static_cast<unsigned long long>(reinterpret_cast<std::uintptr_t>(queue)), static_cast<unsigned long long>(found->programAddress), static_cast<unsigned long long>(found->variantId), stage);
else std::snprintf(checkpoint, sizeof(checkpoint), "[device-fault] checkpoint: %stoken %u batch %llu queue 0x%llx program 0x%llx variant %llu stage %s %.*s", lead.c_str(), static_cast<unsigned>(token), static_cast<unsigned long long>(found->submitSerial), static_cast<unsigned long long>(reinterpret_cast<std::uintptr_t>(queue)), static_cast<unsigned long long>(found->programAddress), static_cast<unsigned long long>(found->variantId), stage, static_cast<int>(descLength), found->desc);
if (found->argBuffer != 0) {
DeviceFaultAppendStage(checkpoint, sizeof(checkpoint), point.stage);
lines.emplace_back(checkpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,46 @@ using FaultToken = std::uint32_t;

enum class FaultStage : std::uint32_t { unknown = 0, graphics = 1, compute = 2, mesh = 3, task = 4, copy = 5 };

enum class CheckpointKind : std::uint8_t { none = 0, draw, dispatch, copy, blit, clear, fill, update, barrier, renderPassBegin, renderPassEnd, query, execute, commandBufferBegin, commandBufferEnd, event, wait, count };

static_assert(sizeof(std::uintptr_t) == 8, "command checkpoint markers need 64-bit pointers");

inline constexpr unsigned CheckpointKindShift = 40;
inline constexpr unsigned CheckpointTagShift = 48;
inline constexpr std::uintptr_t CheckpointTag = 0xA65C;

inline std::uintptr_t CheckpointMarker(FaultToken token, CheckpointKind kind) noexcept {
return static_cast<std::uintptr_t>(token) | (static_cast<std::uintptr_t>(kind) << CheckpointKindShift) | (CheckpointTag << CheckpointTagShift);
}

inline CheckpointKind CheckpointKindOf(const void* marker) noexcept {
if ((reinterpret_cast<std::uintptr_t>(marker) >> CheckpointTagShift) != CheckpointTag) return CheckpointKind::none;
const auto kind = (reinterpret_cast<std::uintptr_t>(marker) >> CheckpointKindShift) & 0xffu;
return kind < static_cast<std::uintptr_t>(CheckpointKind::count) ? static_cast<CheckpointKind>(kind) : CheckpointKind::none;
}

inline const char* CheckpointKindName(CheckpointKind kind) noexcept {
switch (kind) {
case CheckpointKind::draw: return "draw";
case CheckpointKind::dispatch: return "dispatch";
case CheckpointKind::copy: return "copy";
case CheckpointKind::blit: return "blit";
case CheckpointKind::clear: return "clear";
case CheckpointKind::fill: return "fill";
case CheckpointKind::update: return "update";
case CheckpointKind::barrier: return "barrier";
case CheckpointKind::renderPassBegin: return "render pass begin";
case CheckpointKind::renderPassEnd: return "render pass end";
case CheckpointKind::query: return "query";
case CheckpointKind::execute: return "execute commands";
case CheckpointKind::commandBufferBegin: return "command buffer begin";
case CheckpointKind::commandBufferEnd: return "command buffer end";
case CheckpointKind::event: return "event";
case CheckpointKind::wait: return "wait events";
default: return "none";
}
}

struct FaultTokenEntry {
alignas(std::atomic_ref<FaultToken>::required_alignment) mutable FaultToken token = 0;
std::uint64_t submitSerial = 0;
Expand Down
7 changes: 6 additions & 1 deletion core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "SpirvBackend/SpirvOptimizer.hpp"
#endif
#include "prx/libSceAgcDriver/Graphics/include/PipelineJournal.hpp"
#include "prx/libSceAgcDriver/Graphics/include/CommandCheckpoints.hpp"
#include "prx/libSceAgcDriver/Graphics/include/PipelineLibrary.hpp"
#include "prx/libSceAgcDriver/Graphics/include/DeferredDestruction.hpp"
#include "prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp"
Expand Down Expand Up @@ -2652,6 +2653,7 @@ VulkanDevice::VulkanDevice(const PresentationWindow* window, bool compileOnly) :
check(state->InstanceFunction<PFN_vkCreateDevice>("vkCreateDevice")(selected, &deviceInfo, nullptr, &state->device), "vkCreateDevice");
state->shaderProfile = std::move(shaderProfile);
if (compileOnly) return;
if (checkpoints) state->deviceProc = Graphics::CheckpointCommandKinds(state->device, state->deviceProc);
if (state->deferDestruction) state->contextDeviceProc = Graphics::DeferDestructionToIdle(state->device, state->deviceProc);
if (calibratedTimestamps != nullptr) {
const bool khr = std::strcmp(calibratedTimestamps, VK_KHR_CALIBRATED_TIMESTAMPS_EXTENSION_NAME) == 0;
Expand Down Expand Up @@ -6484,7 +6486,10 @@ void VulkanDevice::recordDispatch(RecordedDispatch& record) {
}
}
}
if (state->checkpointMarker != nullptr) state->checkpointMarker(commands, reinterpret_cast<const void*>(static_cast<std::uintptr_t>(faultToken)));
if (state->checkpointMarker != nullptr) {
state->checkpointMarker(commands, reinterpret_cast<const void*>(static_cast<std::uintptr_t>(faultToken)));
if (faultToken != 0) Graphics::NoteRecordedCheckpoint(commands, faultToken);
}
if (faultToken != 0 && state->bufferMarker != nullptr) state->bufferMarker(commands, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, state->markerBuffer, 0, faultToken);
if (split) {
if (splitSlice->listed >= 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef CORE_LIBS_PRX_LIBSCEAGCDRIVER_GRAPHICS_INCLUDE_COMMANDCHECKPOINTS_HPP
#define CORE_LIBS_PRX_LIBSCEAGCDRIVER_GRAPHICS_INCLUDE_COMMANDCHECKPOINTS_HPP

#include "prx/libSceAgcDriver/Execution/include/SubmissionSnapshots.hpp"
#include "prx/libSceAgcDriver/Graphics/include/Context.hpp"

namespace AgcDriver::Graphics {

PFN_vkGetDeviceProcAddr CheckpointCommandKinds(VkDevice device, PFN_vkGetDeviceProcAddr resolver);
void NoteRecordedCheckpoint(VkCommandBuffer commands, AgcDriver::FaultToken token) noexcept;

}

#endif
Loading
Loading