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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Settings are kept across versions. Unless noted, the defaults stay `Multiplier=2
and start a new empty [Unreleased] above it: the Release workflow refuses a tag whose version
has no "## [x.y.z]" section here. -->

### Added
- **Copy-pass GPU timing:** with `[Debug] VerboseLog=1`, the log shows every 600 frames how much GPU time the mod's own copies take (depth, motion vectors, HUD-less). With logging off it costs nothing. They measure about 44 µs per frame, around 0.5% of a 6x frame on an RTX 5090.

### Changed
- **Barrier after each copy:** the game's next rendering work no longer waits for the mod's copies to finish, only DLSS-G does. The gain is a few microseconds per frame.

## [0.8.5] - 2026-10-18

### Changed
Expand Down
23 changes: 23 additions & 0 deletions docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,29 @@ That's +4% at 2x and +24% at 6x, about 2.1 ms per frame at 6x.
- **Log:** over about 3 minutes at 2x–6x, 4 fence waits (all in the first frames) and 0 timeouts.
- **User test:** image quality and latency were unchanged.

### Copy-pass GPU timing and narrower barriers (after v0.8.5, 2026-10-18)

**Timing:** with `[Debug] VerboseLog=1`, each `CopyPass` creates a timestamp query pool.
- **Timestamps:** a `BOTTOM_OF_PIPE` timestamp pair goes around each copy, kept in a 4-frame ring.
- **Read-back:** the pair from 4 copies ago is read with `vkGetQueryPoolResults` (no WAIT; a result that isn't ready is skipped) just before its queries are reset and reused.
- **Log line:** every 600 frames, `copy passes GPU time: depth … mvec … hudless …; total … us per frame (frame … ms)`.
- **When off:** no query pool is created.

**Barrier:** the barrier after each copy used to have `ALL_COMMANDS` as its destination stage. It now waits only for `COMPUTE_SHADER | TRANSFER`, the stages where DLSS-G reads the copies. On its own queues those reads are ordered by Streamline's semaphores anyway. The game's next graphics work no longer waits for our dispatch.

**Measured (RTX 5090, 1080p DLSS Quality, 6x, parallel mode, about 90 s, 15 full 600-frame windows):**

| Pass | Average per frame |
|---|---|
| Depth (1280×720 → R32F) | ~12.8 µs (12.1–15.9) |
| Motion vectors (1280×720 → RG16F) | ~10.6 µs (9.2–14.8) |
| HUD-less (1920×1080 → RGBA8) | ~20.7 µs (19.1–22.5) |
| **Total** | **~44 µs (41.5–48.7)**, about 0.5% of the 8.4–9.9 ms frame |

- **Max values of 200–2,100 µs:** these are measurement artifacts, not cost. `BOTTOM_OF_PIPE` timestamps also count time the GPU spends on other work in between, such as DLSS-G on its own queues in parallel mode. The spikes hit all three passes at random while the averages stay flat.
- **Conclusion:** removing the copies entirely would give back at most ~0.5%. The rest of frame generation's overhead is DLSS-G's own GPU work. The barrier change is too small to show in fps.

## Key risks
- **Manual hooking:** SL Vulkan manual hooking is documented as "advanced integration only". Running an injected `sl.interposer` next to the game's own NGX instance is untested, so Phase 3 is the go/no-go gate.
- **Camera matrices:** the approximation may not be good enough, and step B is a reverse-engineering effort of unknown size.
- **Latency at high multipliers:** the community already reports this for 4x–6x. Reflex has to be correctly wired through SL.
Expand Down
79 changes: 75 additions & 4 deletions src/render/copy_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ bool Load(T& out, VkDevice device, const char* name) {
} // namespace

bool CopyPass::Init(const char* name, VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device,
VkFormat dstFormat, const uint32_t* spirv, size_t spirvBytes, uint32_t slots, WaitFn wait) {
VkFormat dstFormat, const uint32_t* spirv, size_t spirvBytes, uint32_t slots, WaitFn wait,
bool timing) {
name_ = name;
device_ = device;
format_ = dstFormat;
Expand Down Expand Up @@ -91,7 +92,31 @@ bool CopyPass::Init(const char* name, VkInstance instance, VkPhysicalDevice phys
return false;
}
ready_ = true;
EFG_LOG("CopyPass %s ready (-> format %d, %u slots%s)", name_, format_, slots_, wait_ ? ", fence-guarded" : "");

if (timing) {
auto getProps = reinterpret_cast<PFN_vkGetPhysicalDeviceProperties>(
RealInstanceProc(instance, "vkGetPhysicalDeviceProperties"));
PFN_vkCreateQueryPool createQueryPool = nullptr;
VkPhysicalDeviceProperties props{};
if (getProps) getProps(physicalDevice, &props);
if (getProps && props.limits.timestampComputeAndGraphics && props.limits.timestampPeriod > 0 &&
Load(createQueryPool, device, "vkCreateQueryPool") && Load(vkDestroyQueryPool_, device, "vkDestroyQueryPool") &&
Load(vkCmdResetQueryPool_, device, "vkCmdResetQueryPool") &&
Load(vkCmdWriteTimestamp_, device, "vkCmdWriteTimestamp") &&
Load(vkGetQueryPoolResults_, device, "vkGetQueryPoolResults")) {
VkQueryPoolCreateInfo qi{VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO};
qi.queryType = VK_QUERY_TYPE_TIMESTAMP;
qi.queryCount = 2 * kTimingFrames;
if (createQueryPool(device, &qi, nullptr, &queryPool_) == VK_SUCCESS) {
timestampPeriodNs_ = props.limits.timestampPeriod;
} else {
queryPool_ = VK_NULL_HANDLE;
}
}
if (!queryPool_) EFG_LOG("CopyPass %s: GPU timestamps unavailable", name_);
}
EFG_LOG("CopyPass %s ready (-> format %d, %u slots%s%s)", name_, format_, slots_, wait_ ? ", fence-guarded" : "",
queryPool_ ? ", GPU-timed" : "");
return true;
}

Expand Down Expand Up @@ -161,6 +186,8 @@ void CopyPass::Shutdown() {
if (pipeline_) vkDestroyPipeline_(device_, pipeline_, nullptr);
if (pipelineLayout_) vkDestroyPipelineLayout_(device_, pipelineLayout_, nullptr);
if (setLayout_) vkDestroyDescriptorSetLayout_(device_, setLayout_, nullptr);
if (queryPool_) vkDestroyQueryPool_(device_, queryPool_, nullptr);
queryPool_ = VK_NULL_HANDLE;
pipeline_ = VK_NULL_HANDLE;
pipelineLayout_ = VK_NULL_HANDLE;
setLayout_ = VK_NULL_HANDLE;
Expand All @@ -184,6 +211,15 @@ sl_bridge::ImageRef CopyPass::Copy(VkCommandBuffer cmd, VkImageView srcView, uin
if (wait_ && t.fenceValue) wait_(t.fenceValue);
t.fenceValue = 0;

// VerboseLog timing: a timestamp pair per copy, in a ring of kTimingFrames. The pair from
// kTimingFrames copies ago is read back (without waiting) before its queries are reused.
const uint32_t q = timingFrame_ % kTimingFrames;
if (queryPool_) {
ReadTiming(q);
vkCmdResetQueryPool_(cmd, queryPool_, 2 * q, 2);
vkCmdWriteTimestamp_(cmd, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, queryPool_, 2 * q);
}

VkImageMemoryBarrier toWrite{VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER};
toWrite.srcAccessMask = 0; // earlier DLSS-G reads: Streamline's queue blocking, or the fence wait above
toWrite.dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
Expand Down Expand Up @@ -218,17 +254,52 @@ sl_bridge::ImageRef CopyPass::Copy(VkCommandBuffer cmd, VkImageView srcView, uin
vkCmdPushConstants_(cmd, pipelineLayout_, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(size), size);
vkCmdDispatch_(cmd, (width + 7) / 8, (height + 7) / 8, 1);

// Only DLSS-G reads the copy, with compute shaders or transfers (on its own queues it is ordered by
// Streamline's semaphores). Waiting for just those stages lets the game's following graphics work
// start without waiting for this dispatch.
VkImageMemoryBarrier toRead = toWrite;
toRead.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
toRead.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_TRANSFER_READ_BIT;
toRead.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
toRead.newLayout = VK_IMAGE_LAYOUT_GENERAL;
vkCmdPipelineBarrier_(cmd, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
0, nullptr, 1, &toRead);
vkCmdPipelineBarrier_(cmd, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0,
nullptr, 1, &toRead);
if (queryPool_) {
vkCmdWriteTimestamp_(cmd, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, queryPool_, 2 * q + 1);
queryWritten_[q] = true;
++timingFrame_;
}

return {t.image, t.view, format_, width, height};
}

void CopyPass::ReadTiming(uint32_t q) {
if (!queryWritten_[q]) return; // never used: its queries were never reset
queryWritten_[q] = false;
uint64_t ts[2] = {};
// No WAIT flag: a pair that is somehow still in flight is skipped rather than stalling the game.
if (vkGetQueryPoolResults_(device_, queryPool_, 2 * q, 2, sizeof(ts), ts, sizeof(uint64_t),
VK_QUERY_RESULT_64_BIT) != VK_SUCCESS)
return;
const uint64_t delta = (ts[1] - ts[0]) & timestampMask_;
const double us = double(delta) * timestampPeriodNs_ / 1000.0;
if (us < 0 || us > 100000.0) return; // wrapped or bogus
timingSumUs_ += us;
if (us > timingMaxUs_) timingMaxUs_ = us;
++timingCount_;
}

bool CopyPass::TakeTiming(double& avgUs, double& maxUs, uint32_t& count) {
if (!queryPool_ || !timingCount_) return false;
avgUs = timingSumUs_ / timingCount_;
maxUs = timingMaxUs_;
count = timingCount_;
timingSumUs_ = timingMaxUs_ = 0;
timingCount_ = 0;
return true;
}

void CopyPass::MarkPresented(uint64_t fenceValue) {
if (written_ < 0) return;
targets_[written_].fenceValue = fenceValue;
Expand Down
20 changes: 19 additions & 1 deletion src/render/copy_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ class CopyPass {

// `slots`: 2 is enough while Streamline blocks the presenting queue; parallel mode uses 3 plus
// `wait`, which is called before a slot that DLSS-G may still be reading is rewritten.
// `timing` ([Debug] VerboseLog): GPU timestamps around each copy, read back a few frames later.
bool Init(const char* name, VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device,
VkFormat dstFormat, const uint32_t* spirv, size_t spirvBytes, uint32_t slots = 2,
WaitFn wait = nullptr);
WaitFn wait = nullptr, bool timing = false);
void Shutdown();
bool Ready() const { return ready_; }

Expand All @@ -34,6 +35,8 @@ class CopyPass {
// After a present: DLSS-G's completion-fence value for that frame's inputs. It's recorded on the slot
// written since the previous call (if any), and waited for before that slot is written again.
void MarkPresented(uint64_t fenceValue);
// GPU time of the copies measured since the last call (timing only). Returns false if none.
bool TakeTiming(double& avgUs, double& maxUs, uint32_t& count);

private:
struct Target {
Expand All @@ -45,6 +48,9 @@ class CopyPass {
};
bool EnsureTargets(uint32_t width, uint32_t height);
void DestroyTargets();
void ReadTiming(uint32_t frame); // collects a finished timestamp pair, if available

static constexpr uint32_t kTimingFrames = 4; // timestamp pairs in flight

const char* name_ = "";
VkDevice device_ = VK_NULL_HANDLE;
Expand All @@ -61,6 +67,14 @@ class CopyPass {
int written_ = -1; // slot written since the last MarkPresented (-1 = none)
bool ready_ = false;

VkQueryPool queryPool_ = VK_NULL_HANDLE;
double timestampPeriodNs_ = 0;
uint64_t timestampMask_ = ~0ull;
bool queryWritten_[kTimingFrames] = {};
uint32_t timingFrame_ = 0;
double timingSumUs_ = 0, timingMaxUs_ = 0;
uint32_t timingCount_ = 0;

PFN_vkCreateImage vkCreateImage_ = nullptr;
PFN_vkDestroyImage vkDestroyImage_ = nullptr;
PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements_ = nullptr;
Expand All @@ -77,6 +91,10 @@ class CopyPass {
PFN_vkCmdPushDescriptorSetKHR vkCmdPushDescriptorSetKHR_ = nullptr;
PFN_vkCmdPushConstants vkCmdPushConstants_ = nullptr;
PFN_vkCmdDispatch vkCmdDispatch_ = nullptr;
PFN_vkDestroyQueryPool vkDestroyQueryPool_ = nullptr;
PFN_vkCmdResetQueryPool vkCmdResetQueryPool_ = nullptr;
PFN_vkCmdWriteTimestamp vkCmdWriteTimestamp_ = nullptr;
PFN_vkGetQueryPoolResults vkGetQueryPoolResults_ = nullptr;
};

} // namespace efg::render
26 changes: 23 additions & 3 deletions src/sl/sl_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,15 +502,16 @@ void EnsureCopyPasses() {
const bool ring = wantParallel && fenceFns;
const uint32_t slots = ring ? 3 : 2;
const render::CopyPass::WaitFn wait = ring ? &WaitForInputs : nullptr;
const bool timing = LoadConfig().verboseLog; // GPU timestamps around each copy
if (!g_mvCopy.Init("mvec", g_instance, g_physicalDevice, device, VK_FORMAT_R16G16_SFLOAT, kMvConvertSpv,
sizeof(kMvConvertSpv), slots, wait))
sizeof(kMvConvertSpv), slots, wait, timing))
EFG_LOG("motion-vector copy pass unavailable - tagging the game's SNORM motion vectors directly");
if (!g_hudlessCopy.Init("hudless", g_instance, g_physicalDevice, device, VK_FORMAT_R8G8B8A8_UNORM, kCopyRgba8Spv,
sizeof(kCopyRgba8Spv), slots, wait))
sizeof(kCopyRgba8Spv), slots, wait, timing))
EFG_LOG("HUD-less copy pass unavailable - frame generation will run without HUD-less colour");
if (ring)
g_depthCopy.Init("depth", g_instance, g_physicalDevice, device, VK_FORMAT_R32_SFLOAT, kCopyR32Spv,
sizeof(kCopyR32Spv), slots, wait);
sizeof(kCopyR32Spv), slots, wait, timing);
// Every tagged input must be our own copy, or the game would overwrite it while DLSS-G reads it.
g_parallel = ring && g_mvCopy.Ready() && g_depthCopy.Ready() && g_hudlessCopy.Ready();
if (wantParallel)
Expand Down Expand Up @@ -1124,6 +1125,25 @@ void AfterPresent(unsigned long long presentCount) {
g_camMaxStep = 0;
}
if (presentCount == 2 || presentCount % 6000 == 0) LogReflexState("periodic");
if (LoadConfig().verboseLog) {
// GPU time of our own copy passes (VerboseLog only), to compare with the frame time.
struct {
const char* name;
render::CopyPass& pass;
} passes[] = {{"depth", g_depthCopy}, {"mvec", g_mvCopy}, {"hudless", g_hudlessCopy}};
char line[256];
int len = snprintf(line, sizeof(line), "copy passes GPU time:");
double total = 0;
for (auto& p : passes) {
double avg = 0, mx = 0;
uint32_t n = 0;
if (!p.pass.TakeTiming(avg, mx, n)) continue;
total += avg;
len += snprintf(line + len, sizeof(line) - len, " %s %.1f us (max %.1f, %u)", p.name, avg, mx, n);
if (len >= (int)sizeof(line)) break;
}
if (total > 0) EFG_LOG("%s; total %.1f us per frame (frame %.2f ms)", line, total, 1000.0 / std::max(g_baseFps, 1.0));
}
if (g_parallel) {
EFG_LOG("parallel: %u fence waits, %u timeouts in the last 600 frames", g_fenceWaits, g_fenceWaitTimeouts);
g_fenceWaits = g_fenceWaitTimeouts = 0;
Expand Down
3 changes: 2 additions & 1 deletion tools/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ EnshroudedFG.ini (next to enshrouded.exe)
[Overlay] Readout 0 | 1 corner readout (multiplier, rendered fps, output fps)
[Overlay] ReadoutX/Y readout position in pixels, set by dragging; -1 = top-right corner
[Camera] Source game | approx
[Debug] VerboseLog / FrameTrace diagnostics only (FrameTrace: F11 writes EnshroudedFG\frame_trace.txt)
[Debug] VerboseLog / FrameTrace diagnostics only (FrameTrace: F11 writes EnshroudedFG\frame_trace.txt;
VerboseLog also logs the GPU time of the mod's copy passes every 600 frames)

Notes
-----
Expand Down
Loading