mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 18:58:37 +00:00
With LEONIDA_DEVICE_MARKERS=1 every draw the replay records takes a seq from the dispatch numbering and writes the VK_AMD_buffer_marker pair: started before its helper passes and rendering scope, finished after the scope ends (the legacy indirect path inside the caller's scope, which the extension allows). The marker history (now 65,536 items) keeps each draw's kind and counts, pipeline names, execute, list, command and its place among the draws to the same targets. The loss and stall reports name the last finished item, the likely hang, the rest in flight and an idle queue's next one not started, for draws and dispatches alike; a device-fault address is followed by the last draw each queue started. Tests: the CPU marker test records draws and dispatches and checks the lines; the GPU marker test writes draw markers outside and inside a dynamic-rendering scope. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
442 lines
24 KiB
C++
442 lines
24 KiB
C++
// The AMD breadcrumbs of the device-fault report (src/vulkan_device_markers.h, LEONIDA_DEVICE_MARKERS=1), on the
|
|
// CPU: seq numbering, the marker writes a recorded dispatch or draw makes, the history ring, and which dispatch or draw
|
|
// the report calls the likely hang for given marker values, with the lines that name it. The driver is faked: its
|
|
// marker writes are logged, and a "GPU" applies a prefix of them to the mapped words, as a queue that stopped at that
|
|
// point would have. No GPU, no game data.
|
|
#include "../src/vulkan_device_fault.h"
|
|
#include "../src/vulkan_gpu_profile.h"
|
|
|
|
#include <algorithm>
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
#include <string>
|
|
#include <type_traits>
|
|
#include <vector>
|
|
|
|
#define EXPECT(condition) do { \
|
|
if (!(condition)) { std::fprintf(stderr, "line %d: %s\n", __LINE__, #condition); return 1; } \
|
|
} while (0)
|
|
|
|
using namespace leonida;
|
|
|
|
namespace {
|
|
|
|
template<typename Handle>
|
|
Handle fake_handle(std::uintptr_t value) {
|
|
if constexpr (std::is_pointer_v<Handle>) return reinterpret_cast<Handle>(value);
|
|
else return Handle(value);
|
|
}
|
|
|
|
struct Write {
|
|
VkCommandBuffer command_buffer;
|
|
std::uint64_t stage;
|
|
VkDeviceSize offset;
|
|
std::uint32_t marker;
|
|
};
|
|
std::vector<Write> writes;
|
|
std::uint32_t words[2 * DeviceMarkers::max_queues];
|
|
bool mapped = false, unmapped = false, freed = false;
|
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL create_buffer(VkDevice, const VkBufferCreateInfo* info, const VkAllocationCallbacks*,
|
|
VkBuffer* buffer) {
|
|
if (info->size < sizeof(words)) return VK_ERROR_UNKNOWN;
|
|
*buffer = fake_handle<VkBuffer>(0x100);
|
|
return VK_SUCCESS;
|
|
}
|
|
VKAPI_ATTR void VKAPI_CALL requirements(VkDevice, VkBuffer, VkMemoryRequirements* out) {
|
|
*out = {sizeof(words), 4, 0x6};
|
|
}
|
|
VKAPI_ATTR VkResult VKAPI_CALL allocate(VkDevice, const VkMemoryAllocateInfo* info, const VkAllocationCallbacks*,
|
|
VkDeviceMemory* memory) {
|
|
if (info->memoryTypeIndex != 2) return VK_ERROR_UNKNOWN; // host-visible, coherent, not device-local
|
|
*memory = fake_handle<VkDeviceMemory>(0x200);
|
|
return VK_SUCCESS;
|
|
}
|
|
VKAPI_ATTR VkResult VKAPI_CALL bind(VkDevice, VkBuffer, VkDeviceMemory, VkDeviceSize) { return VK_SUCCESS; }
|
|
VKAPI_ATTR VkResult VKAPI_CALL map(VkDevice, VkDeviceMemory, VkDeviceSize, VkDeviceSize, VkMemoryMapFlags, void** out) {
|
|
std::memset(words, 0xcd, sizeof(words));
|
|
*out = words;
|
|
mapped = true;
|
|
return VK_SUCCESS;
|
|
}
|
|
VKAPI_ATTR void VKAPI_CALL unmap(VkDevice, VkDeviceMemory) { unmapped = true; }
|
|
VKAPI_ATTR void VKAPI_CALL destroy_buffer(VkDevice, VkBuffer, const VkAllocationCallbacks*) {}
|
|
VKAPI_ATTR void VKAPI_CALL free_memory(VkDevice, VkDeviceMemory, const VkAllocationCallbacks*) { freed = true; }
|
|
VKAPI_ATTR void VKAPI_CALL write_marker2(VkCommandBuffer command_buffer, VkPipelineStageFlags2 stage, VkBuffer,
|
|
VkDeviceSize offset, std::uint32_t marker) {
|
|
writes.push_back({command_buffer, stage, offset, marker});
|
|
}
|
|
VKAPI_ATTR void VKAPI_CALL write_marker(VkCommandBuffer command_buffer, VkPipelineStageFlagBits stage, VkBuffer buffer,
|
|
VkDeviceSize offset, std::uint32_t marker) {
|
|
write_marker2(command_buffer, stage, buffer, offset, marker);
|
|
}
|
|
|
|
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL get_proc(VkDevice, const char* name) {
|
|
#define LEONIDA_FAKE(entry, fn) if (!std::strcmp(name, entry)) return reinterpret_cast<PFN_vkVoidFunction>(fn)
|
|
LEONIDA_FAKE("vkCreateBuffer", create_buffer);
|
|
LEONIDA_FAKE("vkGetBufferMemoryRequirements", requirements);
|
|
LEONIDA_FAKE("vkAllocateMemory", allocate);
|
|
LEONIDA_FAKE("vkBindBufferMemory", bind);
|
|
LEONIDA_FAKE("vkMapMemory", map);
|
|
LEONIDA_FAKE("vkUnmapMemory", unmap);
|
|
LEONIDA_FAKE("vkDestroyBuffer", destroy_buffer);
|
|
LEONIDA_FAKE("vkFreeMemory", free_memory);
|
|
LEONIDA_FAKE("vkCmdWriteBufferMarkerAMD", write_marker);
|
|
LEONIDA_FAKE("vkCmdWriteBufferMarker2AMD", write_marker2);
|
|
#undef LEONIDA_FAKE
|
|
return nullptr;
|
|
}
|
|
|
|
VkPhysicalDeviceMemoryProperties memory_types() {
|
|
VkPhysicalDeviceMemoryProperties memory{};
|
|
memory.memoryTypeCount = 4;
|
|
memory.memoryTypes[0].propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
|
memory.memoryTypes[1].propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
|
|
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
|
memory.memoryTypes[2].propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
|
memory.memoryTypes[3].propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
|
|
VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
|
|
return memory;
|
|
}
|
|
|
|
// The "GPU": runs the first `count` logged marker writes, in order.
|
|
void execute(std::size_t count) {
|
|
for (std::size_t i = 0; i < count && i < writes.size(); ++i)
|
|
words[writes[i].offset / 4] = writes[i].marker;
|
|
}
|
|
|
|
struct History { // a plain list in MarkerHistory::for_each order, for judge_markers
|
|
std::vector<MarkedWork> entries;
|
|
template<typename Visit>
|
|
void for_each(Visit&& visit) const {
|
|
for (const auto& d : entries) visit(d);
|
|
}
|
|
};
|
|
|
|
int pure_logic() {
|
|
// Serial order on the 32 bits the GPU writes, across the wrap.
|
|
EXPECT(marker_after(5, 4) && !marker_after(4, 4) && !marker_after(3, 4));
|
|
EXPECT(marker_after(0x100000002ull, 0xfffffffeu)); // seq 2^32 + 2 is after marker 2^32 - 2
|
|
EXPECT(!marker_after(0xfffffffeull, 0x00000003u)); // and 2^32 - 2 is before a wrapped 3
|
|
|
|
// The history ring keeps the newest `capacity`, oldest first.
|
|
MarkerHistory ring;
|
|
EXPECT(ring.size() == 0);
|
|
for (std::uint64_t seq = 1; seq <= MarkerHistory::capacity + 5; ++seq) ring.push({seq});
|
|
EXPECT(ring.size() == MarkerHistory::capacity);
|
|
std::uint64_t expect = 6, visited = 0;
|
|
bool ordered = true;
|
|
ring.for_each([&](const MarkedWork& d) { ordered &= d.seq == expect++; ++visited; });
|
|
EXPECT(ordered && visited == MarkerHistory::capacity);
|
|
|
|
// Two queues interleaved: compute has 1 3 5 6 8, direct has 2 4 7.
|
|
const VkQueue compute = fake_handle<VkQueue>(0x10), direct = fake_handle<VkQueue>(0x20);
|
|
History history;
|
|
for (std::uint64_t seq : {1, 3, 5, 6, 8}) history.entries.push_back({seq, 1, compute, "compute"});
|
|
for (std::uint64_t seq : {2, 4, 7}) history.entries.push_back({seq, 2, direct, "direct"});
|
|
std::sort(history.entries.begin(), history.entries.end(),
|
|
[](const auto& a, const auto& b) { return a.seq < b.seq; });
|
|
|
|
// compute finished 3, started 6: 5 and 6 run, 5 is the likely hang; 8 was submitted and not started.
|
|
auto r = judge_markers(compute, {6, 3}, history);
|
|
EXPECT(!r.idle() && r.unfinished == std::vector<std::uint64_t>({5, 6}) && r.likely_hang == 5 && !r.missing);
|
|
EXPECT(r.next_queued == 0 && r.queue_kind && !std::strcmp(r.queue_kind, "compute"));
|
|
// One dispatch started and not finished.
|
|
r = judge_markers(compute, {5, 3}, history);
|
|
EXPECT(r.unfinished == std::vector<std::uint64_t>({5}) && r.likely_hang == 5);
|
|
// direct idle after 4: nothing reported as hung, 7 is the next one it had queued.
|
|
r = judge_markers(direct, {4, 4}, history);
|
|
EXPECT(r.idle() && r.unfinished.empty() && !r.likely_hang && r.next_queued == 7 && !r.missing);
|
|
// Everything done.
|
|
r = judge_markers(direct, {7, 7}, history);
|
|
EXPECT(r.idle() && !r.likely_hang && !r.next_queued);
|
|
// Started past the history's newest dispatch of the queue: nothing to name.
|
|
r = judge_markers(compute, {9, 8}, history);
|
|
EXPECT(r.missing && !r.likely_hang && r.unfinished.empty());
|
|
// A started word behind the finished one (memory a reset scrambled) is read as idle, not as a hang.
|
|
r = judge_markers(compute, {1, 5}, history);
|
|
EXPECT(r.idle() && !r.likely_hang && r.next_queued == 6);
|
|
// No marker yet: every dispatch of the queue is queued, none hung.
|
|
r = judge_markers(compute, {0, 0}, history);
|
|
EXPECT(r.idle() && r.next_queued == 1 && !r.likely_hang);
|
|
// A queue the history does not know.
|
|
r = judge_markers(fake_handle<VkQueue>(0x30), {0, 0}, history);
|
|
EXPECT(!r.queue_kind && !r.next_queued);
|
|
|
|
// Across the 32-bit wrap: seqs 2^32 - 1, 2^32, 2^32 + 1 on one queue; markers hold their low 32 bits.
|
|
History wrapped;
|
|
for (std::uint64_t seq : {0xffffffffull, 0x100000000ull, 0x100000001ull})
|
|
wrapped.entries.push_back({seq, 1, compute, "compute"});
|
|
r = judge_markers(compute, {0x00000001u, 0xffffffffu}, wrapped);
|
|
EXPECT(r.unfinished == std::vector<std::uint64_t>({0x100000000ull, 0x100000001ull}) &&
|
|
r.likely_hang == 0x100000000ull);
|
|
|
|
// Memory type: host-visible and coherent, system memory first.
|
|
const auto memory = memory_types();
|
|
EXPECT(DeviceMarkers::memory_type(memory, 0xf) == 2);
|
|
EXPECT(DeviceMarkers::memory_type(memory, 0x3) == 1); // only device-local ones allowed: the BAR one
|
|
EXPECT(DeviceMarkers::memory_type(memory, 0x1) == UINT32_MAX);
|
|
return 0;
|
|
}
|
|
|
|
// Recording through CheckpointRecorder with the markers on, then the report's verdict for a stopped "GPU".
|
|
int recorded(bool synchronization2) {
|
|
writes.clear();
|
|
mapped = unmapped = freed = false;
|
|
const auto memory = memory_types();
|
|
DeviceFaultExtensions enabled;
|
|
enabled.markers = true;
|
|
const VkQueue compute = fake_handle<VkQueue>(0x10), direct = fake_handle<VkQueue>(0x20);
|
|
const VkCommandBuffer cb = fake_handle<VkCommandBuffer>(0x30);
|
|
{
|
|
DeviceFaultDiagnostics diagnostics(get_proc, VK_NULL_HANDLE, enabled, &memory, synchronization2);
|
|
EXPECT(diagnostics.markers_on() && mapped);
|
|
diagnostics.add_queue(compute);
|
|
diagnostics.add_queue(direct);
|
|
diagnostics.add_queue(compute); // once is enough
|
|
EXPECT(words[0] == 0 && words[3] == 0); // the slots start at no dispatch
|
|
diagnostics.pipeline_names[4] = {"cs_example_a"};
|
|
diagnostics.pipeline_names[5] = {"cs_example_b"};
|
|
const std::array<std::uint32_t, 32> roots{};
|
|
|
|
// Submission 1 on the compute queue: seqs 1..3. Submission 2 on the direct queue: 4..5.
|
|
auto first = diagnostics.begin_submission(diagnostics.next_execute_call(), compute, "compute", 1);
|
|
EXPECT(first.markers && first.markers.offset == 0);
|
|
const CheckpointRecorder a{nullptr, first, diagnostics.pipeline_names, 0};
|
|
for (unsigned i = 0; i < 3; ++i) {
|
|
a.dispatch(cb, 10 + i, VK_NULL_HANDLE, i == 1 ? 5 : 4, roots, {1, 1, 1});
|
|
a.dispatched(cb);
|
|
}
|
|
a.dispatched(cb); // nothing open: no write
|
|
EXPECT(writes.size() == 6);
|
|
auto second = diagnostics.begin_submission(diagnostics.next_execute_call(), direct, "direct", 1);
|
|
EXPECT(second.markers && second.markers.offset == 8);
|
|
const CheckpointRecorder b{nullptr, second, diagnostics.pipeline_names, 0};
|
|
for (unsigned i = 0; i < 2; ++i) {
|
|
b.dispatch(cb, 20 + i, VK_NULL_HANDLE, 4, roots, {}, true, 1, 0, 0, 0, 1, 12);
|
|
b.dispatched(cb);
|
|
}
|
|
EXPECT(writes.size() == 10);
|
|
// Each dispatch: started (top of pipe, slot +0) then finished (bottom of pipe, slot +4), with its seq.
|
|
for (std::size_t i = 0; i < writes.size(); ++i) {
|
|
const Write& w = writes[i];
|
|
const std::uint32_t seq = std::uint32_t(i / 2 + 1);
|
|
const bool top = i % 2 == 0;
|
|
const VkDeviceSize slot = seq <= 3 ? 0 : 8;
|
|
const std::uint64_t top_stage = synchronization2 ? VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT
|
|
: VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
|
|
const std::uint64_t bottom_stage = synchronization2 ? VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT
|
|
: VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
|
EXPECT(w.marker == seq && w.command_buffer == cb && w.offset == slot + (top ? 0 : 4) &&
|
|
w.stage == (top ? top_stage : bottom_stage));
|
|
}
|
|
// The report's list numbers them the same way.
|
|
EXPECT(first.dispatches.size() == 3 && first.dispatches[0].seq == 1 && first.dispatches[2].seq == 3);
|
|
EXPECT(second.dispatches.size() == 2 && second.dispatches[1].seq == 5);
|
|
EXPECT(first.marked.size() == 3 && first.marked[1].shader && !std::strcmp(first.marked[1].shader, "cs_example_b"));
|
|
diagnostics.publish(std::move(first));
|
|
diagnostics.publish(std::move(second));
|
|
|
|
// Nothing has run: no queue is reported as hung.
|
|
EXPECT(diagnostics.report_markers(false).empty());
|
|
// The compute queue stopped inside seq 2 (its started write ran, its finished one did not); the direct queue
|
|
// ran seq 4 completely and stopped inside 5.
|
|
execute(3); // seq 1 started and finished, seq 2 started
|
|
words[2] = 4; words[3] = 4; // direct: seq 4 done
|
|
words[2] = 5; // seq 5 started
|
|
auto hangs = diagnostics.report_markers(true);
|
|
EXPECT(hangs == std::vector<std::uint64_t>({2, 5}));
|
|
diagnostics.report_stall("synthetic marker check", 2, 1); // the list marks seq 2 and 5 as likely hangs
|
|
// Everything finished: no hang.
|
|
execute(writes.size());
|
|
EXPECT(diagnostics.report_markers(false).empty());
|
|
const MarkerSlot compute_slot = diagnostics.marker_slot(compute), direct_slot = diagnostics.marker_slot(direct);
|
|
EXPECT(compute_slot.started == 3 && compute_slot.finished == 3);
|
|
EXPECT(direct_slot.started == 5 && direct_slot.finished == 5);
|
|
}
|
|
EXPECT(unmapped && freed);
|
|
return 0;
|
|
}
|
|
|
|
bool contains(const std::string& text, const char* part) {
|
|
if (text.find(part) != std::string::npos) return true;
|
|
std::fprintf(stderr, "missing \"%s\" in:\n%s", part, text.c_str());
|
|
return false;
|
|
}
|
|
|
|
// Draws get marker pairs too, numbered with the dispatches, and the report names the draw the "GPU" stopped in: its
|
|
// kind and counts, its pipeline as the GPU profile names it, its list and command, and its place among the draws to the
|
|
// same targets. Also the device-fault address note, the draws in flight and an idle queue's next draw.
|
|
int draws() {
|
|
writes.clear();
|
|
const auto memory = memory_types();
|
|
DeviceFaultExtensions enabled;
|
|
enabled.markers = true;
|
|
const VkQueue direct = fake_handle<VkQueue>(0x20);
|
|
const VkCommandBuffer cb = fake_handle<VkCommandBuffer>(0x30);
|
|
DeviceFaultDiagnostics diagnostics(get_proc, VK_NULL_HANDLE, enabled, &memory, true);
|
|
diagnostics.add_queue(direct);
|
|
diagnostics.pipeline_names[4] = {"library/cs_example_a"};
|
|
diagnostics.pipeline_names[7] = {"library/vs_example", nullptr, "library/ps_example"};
|
|
diagnostics.pipeline_names[8] = {"library/ms_example", nullptr, "library/ps_mesh_example"};
|
|
const std::array<std::uint32_t, 32> roots{};
|
|
const VkImageView rt0 = fake_handle<VkImageView>(0x41), rt1 = fake_handle<VkImageView>(0x42);
|
|
const VkImageView depth = fake_handle<VkImageView>(0x43), other = fake_handle<VkImageView>(0x44);
|
|
const std::array<VkImageView, 3> gbuffer{rt0, VK_NULL_HANDLE, rt1}; // slot 1 unbound
|
|
const std::array<VkImageView, 1> single{other};
|
|
const MarkedTargets pass_a = MarkedTargets::of(gbuffer, depth, {640, 480});
|
|
const MarkedTargets pass_b = MarkedTargets::of(single, VK_NULL_HANDLE, {320, 240});
|
|
EXPECT(pass_a.key && pass_a.colors == 2 && pass_a.depth && pass_a.key != pass_b.key && !pass_b.depth);
|
|
|
|
auto s = diagnostics.begin_submission(diagnostics.next_execute_call(), direct, "direct", 2);
|
|
{
|
|
const CheckpointRecorder list0{nullptr, s, diagnostics.pipeline_names, 0};
|
|
list0.dispatch(cb, 0, VK_NULL_HANDLE, 4, roots, {8, 1, 1}); // seq 1
|
|
list0.dispatched(cb);
|
|
list0.draw(cb, 3, 7, marked_draw::indexed, {36, 2, 0}, pass_a); // seq 2
|
|
list0.drawn(cb);
|
|
list0.draw(cb, 5, 7, marked_draw::indexed, {12, 1, 6}, pass_a); // seq 3
|
|
list0.drawn(cb);
|
|
list0.draw(cb, 6, 8, marked_draw::mesh, {4, 2, 1}, pass_a); // seq 4
|
|
list0.drawn(cb);
|
|
list0.draw(cb, 9, 7, 0, {3, 1, 0}, pass_b); // seq 5
|
|
list0.drawn(cb);
|
|
}
|
|
{
|
|
const CheckpointRecorder list1{nullptr, s, diagnostics.pipeline_names, 1};
|
|
list1.draw(cb, 0, 7, marked_draw::indexed | marked_draw::indirect | marked_draw::counted, {64, 20, 0},
|
|
pass_b); // seq 6
|
|
list1.drawn(cb);
|
|
list1.dispatch(cb, 1, VK_NULL_HANDLE, 4, roots, {1, 1, 1}); // seq 7
|
|
list1.dispatched(cb);
|
|
}
|
|
EXPECT(writes.size() == 14);
|
|
for (std::size_t i = 0; i < writes.size(); ++i) // started, finished, ... with seqs 1..7, all in slot 0
|
|
EXPECT(writes[i].marker == i / 2 + 1 && writes[i].offset == (i % 2 ? 4u : 0u) &&
|
|
writes[i].stage ==
|
|
std::uint64_t(i % 2 ? VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT : VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT));
|
|
// The dispatch list keeps dispatches only, with their seqs; draws are in the marker history.
|
|
EXPECT(s.dispatches.size() == 2 && s.dispatches[0].seq == 1 && s.dispatches[1].seq == 7);
|
|
EXPECT(s.marked.size() == 7 && s.marked[1].is_draw() && !s.marked[0].is_draw());
|
|
EXPECT(s.marked[2].pass_command == 3 && s.marked[2].pass_draw == 2); // the second draw to pass_a
|
|
EXPECT(s.marked[3].pass_command == 3 && s.marked[3].pass_draw == 3);
|
|
EXPECT(s.marked[4].pass_command == 9 && s.marked[4].pass_draw == 1); // other targets: a new pass
|
|
EXPECT(s.marked[5].list == 1 && s.marked[5].pass_command == 0 && s.marked[5].pass_draw == 1); // a new list
|
|
diagnostics.publish(std::move(s));
|
|
|
|
// The pipeline as the GPU profile's lines call it.
|
|
const gpu_profile::Key graphics{gpu_profile::Kind::graphics, {"library/vs_example", nullptr, "library/ps_example"}};
|
|
EXPECT(marked_pipeline_label(graphics.names, false, 7) == gpu_profile::label(graphics));
|
|
const gpu_profile::Key mesh{gpu_profile::Kind::mesh, {"library/ms_example", nullptr, "library/ps_mesh_example"}};
|
|
EXPECT(marked_pipeline_label(mesh.names, true, 8) == gpu_profile::label(mesh));
|
|
gpu_profile::Key unnamed{gpu_profile::Kind::graphics};
|
|
unnamed.id = 0x99;
|
|
EXPECT(marked_pipeline_label({}, false, 0x99) == gpu_profile::label(unnamed));
|
|
|
|
// The "GPU" ran seq 1 and 2, started 3 and stopped in it: 3 is the likely hang, 2 the last finished.
|
|
execute(5);
|
|
std::string text;
|
|
EXPECT(diagnostics.report_markers(true, &text) == std::vector<std::uint64_t>({3}));
|
|
EXPECT(contains(text, " (direct) finished seq=2 started seq=3; started, not finished: 3\n"));
|
|
EXPECT(contains(text, "[rt] device-markers: finished: seq=2 execute=1 queue="));
|
|
EXPECT(contains(text, " (direct) list=0 command=3 draw=indexed count=36 instances=2 pipeline=vs vs_example ps "
|
|
"ps_example pass=draw 1 since command 3 (2 colours + depth, 640x480)\n"));
|
|
EXPECT(contains(text, "[rt] device-markers: likely hang: seq=3 execute=1 queue="));
|
|
EXPECT(contains(text, " (direct) list=0 command=5 draw=indexed count=12 instances=1 pipeline=vs vs_example ps "
|
|
"ps_example pass=draw 2 since command 3 (2 colours + depth, 640x480)\n"));
|
|
// With a fault address: the last draw the queue started.
|
|
std::string fault = diagnostics.marker_fault_draws();
|
|
EXPECT(contains(fault, "[rt] device-fault: last started draw (device-markers): seq=3 execute=1"));
|
|
EXPECT(contains(fault, "list=0 command=5 draw=indexed count=12 instances=1 pipeline=vs vs_example ps ps_example"));
|
|
EXPECT(contains(fault, " (not finished) <- likely hang\n"));
|
|
|
|
// Stopped inside the mesh dispatch, with the vertex draw after it started too: both in flight.
|
|
execute(7); // through seq 4 started, 3 finished
|
|
words[0] = 5; // seq 5 started
|
|
text.clear();
|
|
EXPECT(diagnostics.report_markers(true, &text) == std::vector<std::uint64_t>({4}));
|
|
EXPECT(contains(text, "likely hang: seq=4 execute=1 queue="));
|
|
EXPECT(contains(text, " list=0 command=6 draw=mesh groups=4,2,1 pipeline=ms ms_example ps ps_mesh_example "
|
|
"pass=draw 3 since command 3 (2 colours + depth, 640x480)\n"));
|
|
EXPECT(contains(text, "[rt] device-markers: in flight: seq=5 execute=1 queue="));
|
|
EXPECT(contains(text, " list=0 command=9 draw=vertices count=3 instances=1 pipeline=vs vs_example ps ps_example "
|
|
"pass=draw 1 since command 9 (1 colour, 320x240)\n"));
|
|
fault = diagnostics.marker_fault_draws();
|
|
EXPECT(contains(fault, "seq=5 execute=1") && contains(fault, "(not finished)\n"));
|
|
|
|
// Idle after seq 5: the next one, an indirect draw, was not started.
|
|
execute(10);
|
|
text.clear();
|
|
EXPECT(diagnostics.report_markers(false, &text).empty());
|
|
EXPECT(contains(text, "idle: finished seq=5, nothing started after it; next submitted seq=6 not started"));
|
|
EXPECT(contains(text, "[rt] device-markers: not started: seq=6 execute=1 queue="));
|
|
EXPECT(contains(text, " list=1 command=0 draw=indexed-indirect-count max=64 stride=20 pipeline=vs vs_example ps "
|
|
"ps_example pass=draw 1 since command 0 (1 colour, 320x240)\n"));
|
|
fault = diagnostics.marker_fault_draws();
|
|
EXPECT(contains(fault, "seq=5 execute=1") && contains(fault, "(finished)\n"));
|
|
// Everything ran: the last item is the dispatch, the last started draw seq 6, finished.
|
|
execute(writes.size());
|
|
text.clear();
|
|
EXPECT(diagnostics.report_markers(false, &text).empty());
|
|
EXPECT(contains(text, "idle: finished seq=7, nothing started after it\n"));
|
|
EXPECT(contains(text, " list=1 command=1 shader=library/cs_example_a\n"));
|
|
EXPECT(contains(diagnostics.marker_fault_draws(), "seq=6 execute=1"));
|
|
|
|
// Without the markers a draw writes nothing and takes no seq.
|
|
DeviceFaultDiagnostics plain(get_proc, VK_NULL_HANDLE, DeviceFaultExtensions{});
|
|
auto off = plain.begin_submission(plain.next_execute_call(), direct, "direct", 1);
|
|
writes.clear();
|
|
const CheckpointRecorder recorder{nullptr, off, plain.pipeline_names, 0};
|
|
recorder.draw(cb, 0, 7, 0, {3, 1, 0}, pass_b);
|
|
recorder.drawn(cb);
|
|
recorder.dispatch(cb, 1, VK_NULL_HANDLE, 4, roots, {1, 1, 1});
|
|
EXPECT(writes.empty() && off.marked.empty() && off.dispatches[0].seq == 1);
|
|
EXPECT(plain.marker_fault_draws().empty());
|
|
return 0;
|
|
}
|
|
|
|
// Without LEONIDA_DEVICE_MARKERS the extension is not asked for, and with it only where the device has it.
|
|
int extension_request() {
|
|
const VkExtensionProperties with[] = {{VK_AMD_BUFFER_MARKER_EXTENSION_NAME, 1}};
|
|
VkDeviceCreateInfo device{VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO};
|
|
const auto no_features = [](VkPhysicalDevice, VkPhysicalDeviceFeatures2*) {};
|
|
DeviceFaultFeatures features;
|
|
std::vector<const char*> extensions;
|
|
DeviceFaultRequest request;
|
|
EXPECT(!features.enable(VK_NULL_HANDLE, no_features, with, extensions, device, request).markers);
|
|
EXPECT(extensions.empty());
|
|
request.markers = true;
|
|
EXPECT(!features.enable(VK_NULL_HANDLE, no_features, {}, extensions, device, request).markers);
|
|
EXPECT(extensions.empty());
|
|
EXPECT(features.enable(VK_NULL_HANDLE, no_features, with, extensions, device, request).markers);
|
|
EXPECT(extensions.size() == 1 && !std::strcmp(extensions[0], VK_AMD_BUFFER_MARKER_EXTENSION_NAME));
|
|
|
|
// Markers enabled but no memory types given: off, the rest of the report unchanged.
|
|
DeviceFaultExtensions enabled;
|
|
enabled.markers = true;
|
|
DeviceFaultDiagnostics diagnostics(get_proc, VK_NULL_HANDLE, enabled);
|
|
EXPECT(!diagnostics.markers_on());
|
|
auto submission = diagnostics.begin_submission(diagnostics.next_execute_call(), VK_NULL_HANDLE, "compute", 1);
|
|
EXPECT(!submission.markers);
|
|
writes.clear();
|
|
const CheckpointRecorder recorder{nullptr, submission, diagnostics.pipeline_names, 0};
|
|
recorder.dispatch(VK_NULL_HANDLE, 0, VK_NULL_HANDLE, 0, {}, {1, 1, 1});
|
|
recorder.dispatched(VK_NULL_HANDLE);
|
|
EXPECT(writes.empty() && submission.dispatches[0].seq == 1 && submission.marked.empty());
|
|
EXPECT(diagnostics.report_markers(true).empty());
|
|
return 0;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
int main() {
|
|
if (int failed = pure_logic()) return failed;
|
|
if (int failed = recorded(true)) return failed;
|
|
if (int failed = recorded(false)) return failed;
|
|
if (int failed = draws()) return failed;
|
|
if (int failed = extension_request()) return failed;
|
|
std::puts("vulkan_device_markers: ok");
|
|
return 0;
|
|
}
|