Skip to content
Merged
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
7 changes: 7 additions & 0 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4333,6 +4333,13 @@ if(TARGET Vulkan::Headers)
target_compile_definitions(replay_query_edges_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
endif()
add_test(NAME replay_query_edges COMMAND replay_query_edges_test)
# Stateful indirect draw topology coverage and per-reason indirect_stats counters (no GPU or game data).
add_executable(indirect_topology_and_stats_test test/indirect_topology_and_stats_test.cpp)
target_link_libraries(indirect_topology_and_stats_test PRIVATE Vulkan::Headers)
if(WIN32)
target_compile_definitions(indirect_topology_and_stats_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
endif()
add_test(NAME indirect_topology_and_stats COMMAND indirect_topology_and_stats_test)
# GFX10 T#/S#/V# descriptor encoding and its Vulkan mappings (src/gfx10_descriptors.h).
add_executable(gfx10_descriptors_test test/gfx10_descriptors_test.cpp)
target_link_libraries(gfx10_descriptors_test PRIVATE Vulkan::Headers)
Expand Down
4 changes: 2 additions & 2 deletions runtime/shims/d3d12_com.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1931,11 +1931,11 @@ class GraphicsCommandList final
if (!terminal_only) return skip(stats::compound);
if (!graphics_pipeline_) return skip(stats::pipeline);
if (!graphics_.layout) return skip(stats::root_layout);
if (topology_ != D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST) return skip(stats::topology);
if (!stats::topology_supported(topology_)) return skip(stats::topology);
if (indexed && (!index_.va || !index_.size ||
(index_.format != DXGI_FORMAT_R16_UINT && index_.format != DXGI_FORMAT_R32_UINT)))
return skip(stats::index_view);
if (!(viewport_.width > 0) || !(viewport_.height > 0)) return skip(stats::viewport);
if (!any_nonempty_viewport()) return skip(stats::viewport);
note_direct_heap_indexing(graphics_.layout);
record_raster_draw(indexed, 0, 0, 0, 0, 0, &args);
return;
Expand Down
97 changes: 78 additions & 19 deletions runtime/src/indirect_draw_stats.h
Original file line number Diff line number Diff line change
@@ -1,45 +1,104 @@
// Process-wide counts of calls recorded and replay attempts. A command list can replay more than once.
#pragma once
#include <atomic>
#include <cstddef>
#include <cstdint>
#include <cstdio>

namespace leonida::indirect_stats {
enum class Event { recorded, emitted, record_skip, replay_skip };
// One flag per reason, shared across resolver instantiations.
enum Reason { compound, disabled, pipeline, root_layout, viewport, mesh, topology, first_instance, entry, robust_index,
count_limit, multi_draw, count_feature, raw_count_limit, argument_usage, count_usage,
divisor, pending_pipeline, index_view, index_range, stateless, reason_count };

// D3D_PRIMITIVE_TOPOLOGY values whose Vulkan dynamic topology (or rectangle-list geometry-stage variant) needs no CPU
// vertex/index-count expansion at prepare time: POINTLIST(1), LINELIST(2), LINESTRIP(3), TRIANGLELIST(4),
// TRIANGLESTRIP(5), *_ADJ(10..13), and console RECTLIST(17). UNDEFINED(0), QUADLIST(19), and patch lists remain skipped.
inline constexpr bool topology_supported(std::uint32_t value) {
return (value >= 1 && value <= 5) || (value >= 10 && value <= 13) || value == 17;
}

inline constexpr const char* reason_name(Reason reason) {
constexpr const char* names[]{"compound signature", "opt-out", "missing pipeline", "missing root signature",
"empty viewport", "mesh indirect", "topology", "drawIndirectFirstInstance", "missing Vulkan entry point",
"robust sized index binding", "maxDrawIndirectCount", "multiDrawIndirect", "drawIndirectCount",
"counted draw requires maxDrawIndirectCount == UINT32_MAX", "argument buffer lacks indirect creation usage",
"count buffer lacks indirect creation usage", "nonunit vertex divisor", "pipeline pending",
"invalid index view", "index view outside buffer or misaligned", "legacy command has no graphics state"};
static_assert(sizeof(names) / sizeof(*names) == reason_count);
return static_cast<unsigned>(reason) < reason_count ? names[reason] : "unknown";
}

inline constexpr const char* reason_tag(Reason reason) {
constexpr const char* tags[]{"compound", "disabled", "pipeline", "root_layout", "viewport", "mesh", "topology",
"first_instance", "entry", "robust_index", "count_limit", "multi_draw", "count_feature", "raw_count_limit",
"argument_usage", "count_usage", "divisor", "pending_pipeline", "index_view", "index_range", "stateless"};
static_assert(sizeof(tags) / sizeof(*tags) == reason_count);
return static_cast<unsigned>(reason) < reason_count ? tags[reason] : "unknown";
}

struct Counts {
std::atomic<unsigned long long> values[4]{};
void report() const {
std::fprintf(stderr, "[rt] indirect graphics: recorded=%llu emitted=%llu record_skips=%llu replay_skips=%llu\n",
values[0].load(), values[1].load(), values[2].load(), values[3].load());
std::atomic<unsigned long long> by_reason[reason_count]{};
void report(std::FILE* out = stderr) const {
char line[1280];
int pos = std::snprintf(
line, sizeof(line),
"[rt] indirect graphics: recorded=%llu emitted=%llu record_skips=%llu replay_skips=%llu",
values[0].load(std::memory_order_relaxed), values[1].load(std::memory_order_relaxed),
values[2].load(std::memory_order_relaxed), values[3].load(std::memory_order_relaxed));
if (pos < 0) return;
if (static_cast<std::size_t>(pos) >= sizeof(line)) pos = static_cast<int>(sizeof(line) - 1);
bool first_reason = true;
for (unsigned i = 0; i < reason_count; ++i) {
const auto count = by_reason[i].load(std::memory_order_relaxed);
if (!count) continue;
const int rem = static_cast<int>(sizeof(line)) - pos;
if (rem <= 2) break;
const int n = std::snprintf(line + pos, static_cast<std::size_t>(rem), "%s%s=%llu",
first_reason ? " [" : ", ",
reason_tag(static_cast<Reason>(i)), count);
if (n <= 0) break;
pos += (n < rem) ? n : (rem - 1);
first_reason = false;
}
if (!first_reason && static_cast<std::size_t>(pos) + 1 < sizeof(line)) line[pos++] = ']';
std::fprintf(out, "%.*s\n", pos, line);
}
~Counts() {
for (const auto& value : values) {
if (value.load()) {
if (value.load(std::memory_order_relaxed)) {
report();
break;
}
}
}
};

inline Counts& counts() {
static Counts instance;
return instance;
}

inline unsigned long long reason_skips(Reason reason) {
return static_cast<unsigned>(reason) < reason_count
? counts().by_reason[reason].load(std::memory_order_relaxed)
: 0ull;
}

inline void note(Event event) {
static Counts counts;
const auto n = 1 + counts.values[static_cast<unsigned>(event)].fetch_add(1, std::memory_order_relaxed);
if ((n & (n - 1)) == 0) counts.report();
auto& c = counts();
const auto n = 1 + c.values[static_cast<unsigned>(event)].fetch_add(1, std::memory_order_relaxed);
if ((n & (n - 1)) == 0) c.report();
}
// One flag per reason, shared across resolver instantiations.
enum Reason { compound, disabled, pipeline, root_layout, viewport, mesh, topology, first_instance, entry, robust_index,
count_limit, multi_draw, count_feature, raw_count_limit, argument_usage, count_usage,
divisor, pending_pipeline, index_view, index_range, stateless, reason_count };

inline void skip(Event event, Reason reason) {
static constexpr const char* names[]{"compound signature", "opt-out", "missing pipeline", "missing root signature",
"empty viewport", "mesh indirect", "topology", "drawIndirectFirstInstance", "missing Vulkan entry point",
"robust sized index binding", "maxDrawIndirectCount", "multiDrawIndirect", "drawIndirectCount",
"counted draw requires maxDrawIndirectCount == UINT32_MAX", "argument buffer lacks indirect creation usage",
"count buffer lacks indirect creation usage", "nonunit vertex divisor", "pipeline pending",
"invalid index view", "index view outside buffer or misaligned", "legacy command has no graphics state"};
static_assert(sizeof(names) / sizeof(*names) == reason_count);
if (static_cast<unsigned>(reason) >= reason_count) return;
static std::atomic_flag shown[reason_count]{};
if (!shown[reason].test_and_set(std::memory_order_relaxed))
std::fprintf(stderr, "[rt] indirect graphics skipped: %s\n", names[reason]);
std::fprintf(stderr, "[rt] indirect graphics skipped: %s\n", reason_name(reason));
counts().by_reason[reason].fetch_add(1, std::memory_order_relaxed);
note(event);
}
}
12 changes: 10 additions & 2 deletions runtime/src/vulkan_replay.h
Original file line number Diff line number Diff line change
Expand Up @@ -2551,7 +2551,9 @@ ReplayResult prepare_draw(const Draw& draw, const IndirectDrawArgs* arguments, R
return ReplayResult::success;
};
if (draw.mesh) return skip(indirect_stats::mesh);
if (draw.topology != 4) return skip(indirect_stats::topology);
static_assert(indirect_stats::topology_supported(topology_rect_list) &&
!indirect_stats::topology_supported(topology_quad_list));
if (!indirect_stats::topology_supported(draw.topology)) return skip(indirect_stats::topology);
if (!vk.draw_indirect_first_instance) return skip(indirect_stats::first_instance);
if (!entry_available) return skip(indirect_stats::entry);
if (draw.indexed && !vk.bind_robust_index_view) return skip(indirect_stats::robust_index);
Expand Down Expand Up @@ -2667,7 +2669,8 @@ ReplayResult prepare_draw(const Draw& draw, const IndirectDrawArgs* arguments, R
if (pipeline->color_formats[slot] != VK_FORMAT_UNDEFINED && !p.colors[slot].id) unbound |= 1u << slot;
if (pipeline->depth_format != VK_FORMAT_UNDEFINED && !p.depth.id) unbound |= GraphicsPipeline::unbound_depth;
if (unbound || !p.pipeline) {
if (vk.compiles && pipeline->variant && pipeline->built && !pipeline->async_build) {
const bool indirect_rect_variant = arguments && (unbound & GraphicsPipeline::rectangle_stage);
if (vk.compiles && pipeline->variant && pipeline->built && !pipeline->async_build && !indirect_rect_variant) {
p.pipeline = pipeline->built(unbound);
if (!p.pipeline) p.compile = vk.compiles->add(*pipeline, unbound);
} else {
Expand All @@ -2677,6 +2680,11 @@ ReplayResult prepare_draw(const Draw& draw, const IndirectDrawArgs* arguments, R
p.skipped = true;
return ReplayResult::success;
}
if (!p.pipeline && !pipeline->async_build && indirect_rect_variant) {
indirect_stats::skip(indirect_stats::Event::replay_skip, indirect_stats::topology);
p.skipped = true;
return ReplayResult::success;
}
if (!p.pipeline) return unsupported_at(__LINE__);
}
}
Expand Down
Loading
Loading