Skip to content
Closed
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
20 changes: 20 additions & 0 deletions docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,8 @@ and any validation error fails them.
- the 22 written-or-refused cases behind the table in section 3.2, compared with the host's PC runtime when
there is one.
- `xbox_present_test`: `PresentX` and the frame events (section 4.5, "what is implemented"), checked on swapchain pixels.
- `present_probe_test`: `LEONIDA_PRESENT_PROBE` and `LEONIDA_CAPTURE_SOURCE` (section 4.5), unset and set (`--on`): the
same clear, draws and `PresentX` calls show the same frames, with no probe line or source file when unset.
there is one. A host that reports no non-normalized samplers is compared only on the 3 cases without the
flag. The other 19 are then checked against their recorded answers only.
- `d3d12_subgroup_test`: subgroup size control through D3D12 PSOs, on the PSOs of the device proxy.
Expand Down Expand Up @@ -3577,6 +3579,24 @@ will forward to. The queue-side calls ignore which queue they came on (one `VkQu
layer actually presented: the window is not readable in every setup (under Wine it is not even mapped), and the
mean is enough to tell a real frame from a black one. `d3d12_present_test` turns it on and checks the files against
the colour it clears to.
- *Source capture* (`LEONIDA_CAPTURE_SOURCE=1`, with `LEONIDA_CAPTURE`): for the same frames, also copies mip 0
of the texture the title presented (plane 0 of a composition) to host memory on the presenter's queue, waits for
it, and writes `<dir>/source_NNNNN.ppm` (8-bit RGB, clamped) plus one line of `<dir>/source_index.txt` with the
path (`blit` or `compose`), the format, the extent, the tracked layout, the mean RGB and how many texels are not
zero. The frame capture says what was shown and this says what was handed over, so a black frame can be told from
a failed blit or composition. A texture that no tracked operation ever wrote is not read (its line says `never
written`), nor is a multisampled or block-compressed one. Off unless the variable is set (anything but empty or
`0`).
- *Present probe* (`LEONIDA_PRESENT_PROBE=1`, `runtime/src/present_probe.h`): `[rt] present-probe:` lines on stderr
for a frame that is presented but shows nothing. `ClearRenderTargetView` logs the target and the colour; a draw
logs its pipeline, render target, viewport and scissor, and whether it was recorded or dropped for want of a
viewport; `PresentX` logs the plane count, tokens, resources and flags of a call and, when a check refuses it,
which check and the `HRESULT`; the presenter logs the path of each submitted present (`blit`, `compose` or
`blank`), the source's id, format, extent, mips, layers and samples, whether the id still resolves, and the
running count per path; a present queued behind held work is counted too. Each kind of line is written for the
first few events and then for every 600th (draws: every 1200th), and the lines hold ids, sizes, formats, counts
and result codes, never the contents of a buffer or texture. Unset (or empty, or `0`), nothing is written and no
counter is kept. `present_probe_test` runs the same clear, draws and presents with both variables unset and set.
- *`SuspendX`/`ResumeX`*: suspend drops the interval, the origin event and the frames in flight, wakes blocked waits
with `ERROR_INVALID_STATE` and refuses presents (a `PresentX` waiting for a swapchain image polls the suspended
state every 50 ms and gives up, so `SuspendX` never waits on it); resume allows presents again, but waits fail until
Expand Down
11 changes: 11 additions & 0 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3473,6 +3473,17 @@ if(TARGET Vulkan::Headers)
add_test(NAME d3d12_stub_pipelines COMMAND d3d12_stub_pipelines_test)
set_tests_properties(d3d12_stub_pipelines PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 30)
set_tests_properties(d3d12_draw d3d12_title_index_window d3d12_title_vertex_window PROPERTIES SKIP_RETURN_CODE 77)
# LEONIDA_PRESENT_PROBE and LEONIDA_CAPTURE_SOURCE (src/present_probe.h): the same clear, draws and PresentX
# calls with both unset (no probe line, no source capture) and with both set (--on: every line and the files).
add_executable(present_probe_test test/present_probe_test.cpp ${LEONIDA_TEST_VS_FULLSCREEN} ${LEONIDA_TEST_PS})
target_link_libraries(present_probe_test PRIVATE gta6rt_d3d12_com user32)
target_compile_definitions(present_probe_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX
LEONIDA_TEST_VS_FULLSCREEN_SPV="${LEONIDA_TEST_VS_FULLSCREEN}"
LEONIDA_TEST_PS_SPV="${LEONIDA_TEST_PS}")
target_compile_options(present_probe_test PRIVATE /W4 /permissive- /utf-8)
add_test(NAME present_probe_off COMMAND present_probe_test)
add_test(NAME present_probe_on COMMAND present_probe_test --on)
set_tests_properties(present_probe_off present_probe_on PROPERTIES SKIP_RETURN_CODE 77)
# Graphics & compute PSO descriptor validation parity against live Windows D3D12 (WARP and HW).
add_executable(d3d12_pso_validation_test test/d3d12_pso_validation_test.cpp ${LEONIDA_TEST_VS}
${LEONIDA_TEST_PS} ${LEONIDA_TEST_PS_UINT} ${LEONIDA_TEST_VS_FULLSCREEN} ${LEONIDA_TEST_CS})
Expand Down
11 changes: 8 additions & 3 deletions runtime/shims/d3d12_com.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "../src/title_va_alias.h"
#include "../src/fsdraw_probe.h" // LOCAL DIAGNOSTIC
#include "../src/local_diagnostics.h"
#include "../src/present_probe.h"

#include <algorithm>
#include <array>
Expand Down Expand Up @@ -823,7 +824,7 @@ class GraphicsCommandList final
if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE) return check(false);
if (!view.ptr || !color) return check(false);
// LOCAL DIAGNOSTIC: what the title clears, and with which colour
if (leonida::local_diagnostics()) {
if (leonida::present_probe::enabled()) {
static std::atomic<std::uint64_t> clears{0};
const std::uint64_t n = ++clears;
if (n <= 6 || n % 600 == 0) {
Expand Down Expand Up @@ -1824,10 +1825,12 @@ class GraphicsCommandList final
// No viewport (never set, or unbound with RSSetViewports(0)) or every bound viewport empty: D3D12 rasterizes
// nothing, and Vulkan forbids a 0x0 viewport, so the draw is not recorded.
// LOCAL DIAGNOSTIC: the state each draw is recorded with
if (leonida::local_diagnostics()) {
std::uint64_t n = 0;
if (leonida::present_probe::enabled()) {
static std::atomic<std::uint64_t> draws{0}, skipped{0};
const bool skip = !any_nonempty_viewport();
const std::uint64_t n = ++draws, k = skip ? ++skipped : skipped.load();
n = ++draws;
const std::uint64_t k = skip ? ++skipped : skipped.load();
if (n <= 8 || n % 1200 == 0)
std::fprintf(stderr, "[rt] present-probe: draw #%llu (%s; %llu skipped so far) pso %p rts %u rt0 0x%llx "
"mip %u viewport %.0fx%.0f at %.0f,%.0f scissor %d,%d-%d,%d count %u x%u\n",
Expand All @@ -1836,6 +1839,8 @@ class GraphicsCommandList final
render_target_count_, static_cast<unsigned long long>(render_targets_[0].resource),
render_targets_[0].mip, viewport_.width, viewport_.height, viewport_.x, viewport_.y,
scissor_.left, scissor_.top, scissor_.right, scissor_.bottom, count, instances);
}
if (leonida::local_diagnostics()) {
// LOCAL DIAGNOSTIC (fsdraw): the first draw of each pipeline, and one frame's draws every ~300 frames,
// with the pipeline's description, the root data and what the bound descriptor tables hold.
static std::mutex seen_mutex;
Expand Down
5 changes: 3 additions & 2 deletions runtime/shims/xbox_present.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <atomic>
#include "xbox_present.h"
#include "../src/present_probe.h"

#include "d3d12_trace.h"
#include "d3d12_xs_device.h"
Expand Down Expand Up @@ -154,15 +155,15 @@ HRESULT XboxPresentation::PresentX(UINT plane_count, const XboxPresentPlaneParam
// LOCAL DIAGNOSTIC (LEONIDA_LOCAL_DIAGNOSTICS=1): which check refuses PresentX, with its HRESULT.
static HRESULT present_diag(int line, HRESULT hr) {
static std::atomic<int> logged{0};
if (FAILED(hr) && leonida::local_diagnostics() && logged.fetch_add(1) < 40)
if (FAILED(hr) && leonida::present_probe::enabled() && logged.fetch_add(1) < 40)
std::fprintf(stderr, "[rt] PresentX diag: refused at line %d hr 0x%08lx\n", line, static_cast<unsigned long>(hr));
return hr;
}

HRESULT XboxPresentation::present_x(UINT plane_count, const XboxPresentPlaneParameters* planes,
const XboxPresentParameters* params) {
std::lock_guard serialise(present_mutex_);
if (leonida::local_diagnostics()) {
if (leonida::present_probe::enabled()) {
static std::atomic<int> dumped{0};
if (dumped.fetch_add(1) < 6) {
std::fprintf(stderr, "[rt] PresentX diag: planes %u params %p suspended %d registered %d\n", plane_count,
Expand Down
31 changes: 31 additions & 0 deletions runtime/src/present_probe.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

// LEONIDA_PRESENT_PROBE (any non-empty value other than "0"): opt-in diagnostics for a frame that is presented but
// shows nothing. With it, stderr gets `[rt] present-probe:` lines that say what the title cleared and with which
// colour, which draws were recorded and which were dropped for want of a viewport, what each PresentX carried and
// which check refused it, and which path each present took through the presenter (blit, compose or blank) with the
// description of its source texture. The lines carry ids, sizes, formats, counters and result codes, never the
// contents of a buffer or texture. Unset, none of it runs: no line is written and no counter is kept.
//
// Each kind of line is written for the first few events and then for every n-th, so a long run stays readable.

#include "local_diagnostics.h"

#include <cstdint>
#include <cstdlib>

namespace leonida::present_probe {

// Read once per process, at the first call.
inline bool enabled() {
static const bool on = [] {
const char* value = std::getenv("LEONIDA_PRESENT_PROBE");
return value && *value && *value != '0';
}();
return on || local_diagnostics();
}

// True for the first `first` events and for every `every`-th one after them.
inline bool sampled(std::uint64_t n, std::uint64_t first, std::uint64_t every) { return n <= first || n % every == 0; }

} // namespace leonida::present_probe
13 changes: 8 additions & 5 deletions runtime/src/vulkan_present.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "vulkan_present_compose.h"
#include "fsdraw_probe.h" // LOCAL DIAGNOSTIC
#include "local_diagnostics.h"
#include "present_probe.h"
#include "present_dump.h"

// Use the original EXT spellings. They are aliases of the promoted KHR types and are available in older headers.
Expand Down Expand Up @@ -407,9 +408,11 @@ class VulkanPresenter {
if (source_rect) pending.rect = *source_rect;
if (planes) pending.planes = *planes;
deferred_.push_back(pending);
if (const std::uint64_t n = ++probe_deferred_; local_diagnostics() && (n <= 8 || n % 600 == 0))
std::fprintf(stderr, "[rt] present-probe: present #%llu queued behind held work (%zu queued)\n",
static_cast<unsigned long long>(n), deferred_.size());
if (present_probe::enabled()) {
if (const std::uint64_t n = ++probe_deferred_; present_probe::sampled(n, 8, 600))
std::fprintf(stderr, "[rt] present-probe: present #%llu queued behind held work (%zu queued)\n",
static_cast<unsigned long long>(n), deferred_.size());
}
last_tore_ = false;
context_.holds().after_held(this, [this] { run_deferred(); });
return VK_SUCCESS;
Expand Down Expand Up @@ -472,7 +475,7 @@ class VulkanPresenter {
VkResult submit_now(const ResourceBinding* binding, ResourceId source, bool vsync, const PresentRect* source_rect,
bool srgb, bool tear = false, const PresentPlanes* planes = nullptr) {
last_tore_ = false;
probe_path(binding, source, planes); // LOCAL DIAGNOSTIC
if (present_probe::enabled() || probe_source_) probe_path(binding, source, planes);
if (!ok_) return VK_ERROR_INITIALIZATION_FAILED;
if (surface_lost_) { // the window's display went away under a presented swapchain
// Try to make a new surface for the same window (the hwnd is retained by the factory's callback).
Expand Down Expand Up @@ -769,7 +772,7 @@ class VulkanPresenter {
}
}
if (id && !resolved) ++probe_unresolved_;
if (local_diagnostics() && (n <= 6 || n % 600 == 0))
if (present_probe::enabled() && present_probe::sampled(n, 6, 600))
std::fprintf(stderr,
"[rt] present-probe: submit #%llu path %s source 0x%llx resolved %d image %p format %d %ux%u "
"mips %u layers %u samples %u sampled %d (blit %llu compose %llu blank %llu unresolved %llu)\n",
Expand Down
Loading
Loading