mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-18 12:08:38 +00:00
Merge task/bindinc: a draw rebuilds only the bindings, shaders and pipeline state whose inputs changed since the draw before, about 3% less render-thread time on the CPU (#381)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
f1a771e493
7 files changed
+773
-63
No files matched your search
@@ -31,6 +31,7 @@ Code copied or adapted from another project is listed here with its source, the
|
||||
| libopus (MSYS2 `mingw-w64-ucrt-x86_64-opus`), dynamic link, `libopus-0.dll` copied next to `totk.exe` | https://opus-codec.org, Copyright (c) 2001-2023 Xiph.Org, Skype Limited, Octasic, Jean-Marc Valin, Timothy B. Terriberry, CSIRO, Gregory Maxwell, Mark Borgerding, Erik de Castro Lopo, Mozilla, Amazon | BSD-3-Clause | `runtime/ov_media.c` (nn::codec hardware Opus decoder) |
|
||||
| Dear ImGui 1.91.9 (core and Vulkan back end, unmodified), as vendored by LAS Recomp | https://github.com/ocornut/imgui, via https://github.com/peiikai/LASRecomp @ `da35b83a9611d046a9a681aae668d7085954d37f` (`third_party/imgui/`), Copyright (c) 2014-2025 Omar Cornut | MIT | `runtime/third_party/imgui/` (compiled into `totk.exe` for the in-game menu, `runtime/ui/`) |
|
||||
| SavageWindRecomp settings menu: two-pane option rows (row look, left / right stepping, hold speed-up, description pane), the menu style and tab bar | https://github.com/Revivedx/SavageWindRecomp @ `575ad88e02f9a89a9a885d90039d48af33c982f4` (`runtime/ui/option_rows.mm`, `runtime/ui/menu.mm`), Copyright (c) 2026 Revivedx and the Savage Wind Recomp contributors, Copyright (c) 2026 Peiikai | MIT | `runtime/ui/option_rows.cpp`, `runtime/ui/option_rows.h`, `runtime/ui/menu.cpp` |
|
||||
| SavageWindRecomp descriptor sets allocated in growing batches per layout | https://github.com/Revivedx/SavageWindRecomp @ `740b18025fe11ba03c117dbb56668db304b5043e` (`runtime/nvn/vulkan/exec.c` vk_alloc_set), Copyright (c) 2026 Revivedx and the Savage Wind Recomp contributors, Copyright (c) 2026 Peiikai | MIT | `runtime/vk_exec_draw.c` (alloc_set_batched) |
|
||||
| SavageWindRecomp performance overlay: the frame ring and its one-second summary, the NVML calls, the sampling loop, the full panel's layout | https://github.com/Revivedx/SavageWindRecomp @ `575ad88e02f9a89a9a885d90039d48af33c982f4` (`runtime/perfmon.c`, `runtime/perfmon.h`, `perf_overlay_draw` in `runtime/ui/menu.mm`), Copyright (c) 2026 Revivedx and the Savage Wind Recomp contributors, Copyright (c) 2026 Peiikai | MIT | `runtime/perfmon.c`, `runtime/perfmon.h`, `runtime/ui/menu.cpp` |
|
||||
| Roboto Medium font (Dear ImGui's `misc/fonts/Roboto-Medium.ttf`, unmodified) | https://fonts.google.com/specimen/Roboto, via https://github.com/peiikai/LASRecomp @ `da35b83a9611d046a9a681aae668d7085954d37f` (`third_party/imgui/misc/fonts/`), Copyright 2011 Google Inc. | Apache-2.0 | `runtime/ui/fonts/Roboto-Medium.ttf` (licence text in `runtime/ui/fonts/LICENSE-Roboto.txt`), embedded by `runtime/ui/menu.cpp` |
|
||||
| Vulkan Memory Allocator 3.4.0 (MSYS2 `mingw-w64-ucrt-x86_64-vulkan-memory-allocator`), header-only, compiled into `totk.exe` | https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator, Copyright (c) 2017-2026 Advanced Micro Devices, Inc. | MIT | `runtime/vk_vma.cpp` (the allocator behind `runtime/vk_memory.c`) |
|
||||
|
||||
@@ -122,6 +122,7 @@ Many rows below are developer tools that only act together with another setting
|
||||
|
||||
| Setting | What it does | Effect of changing it | Safety |
|
||||
| --- | --- | --- | --- |
|
||||
| `bind_inc` (default `1`) | `1` (or `on`) prepares a draw from what changed since the draw before (the bind ops mark the slots whose bytes they changed) instead of from the whole bound state; `check` prepares every draw as before, takes every decision of `on` beside it, logs each kind of difference once and counts them in a `bind_inc:` line every 300 frames; `0` or `off`: as before. `check` also counts what changed between draws in that line. | Less work per draw on the render thread; a change the marks missed would leave a stale descriptor, a wrong picture or a lost device, which `check` would show first. | Caution |
|
||||
| `block_views_3d` (default `0`) | `1` gives 3D block-compressed images block views too. | On some AMD cards a GPU write past the end of the image's memory loses the Vulkan device, and the game stops. | Risky |
|
||||
| `deswizzle` (default `auto`) | Where block-linear textures are deswizzled: `auto` or `gpu` uses a compute pass where the texture's storage is an imported pool and the CPU elsewhere, `cpu` always uses the CPU, `check` uses the GPU and also deswizzles every upload on the CPU and compares the two. | `cpu` brings back the long frames on entering new areas (the replay thread deswizzles every texture); `check` waits for the GPU at every upload and is for testing only. The log names the mode in use. | Caution |
|
||||
| `dyn_delta` (default `1`) | Records only the pipeline dynamic states (cull mode, depth and stencil tests, vertex input, blend enables, equations and write masks, ...) whose values changed since the last draw in the command buffer, also across pipeline changes; `0` records the full set at every change of pipeline state, as before; `ab` alternates with the `ab` blocks. | Fewer commands per pipeline change on the render and recorder threads; a driver that loses dynamic state across pipeline binds would draw with stale state. `TOTK_TRACE=perf` prints the calls and commands per submission. | Caution |
|
||||
|
||||
+3
-3
@@ -37,7 +37,7 @@ static const char *const known[] = {
|
||||
"BIND_LSTICK_RIGHT", "BIND_LSTICK_UP", "BIND_MINUS",
|
||||
"BIND_PLUS", "BIND_R", "BIND_RCLICK", "BIND_RIGHT", "BIND_RSTICK_DOWN", "BIND_RSTICK_LEFT", "BIND_RSTICK_RIGHT", "BIND_RSTICK_UP",
|
||||
"BIND_SHAKE",
|
||||
"BIND_SKIP", "BIND_STATS", "BIND_UP", "BIND_X", "BIND_Y",
|
||||
"BIND_INC", "BIND_SKIP", "BIND_STATS", "BIND_UP", "BIND_X", "BIND_Y",
|
||||
"BIND_ZL", "BIND_ZR", "BLOCK_VIEWS_3D", "CLIMB_FIX", "CLOTH_REALTIME", "COLOR_BRIGHTNESS", "COLOR_CONTRAST", "COLOR_GAMMA",
|
||||
"COLOR_PRESET", "COLOR_SATURATION", "CONTACT_DEBUG", "CONTACT_SHADOWS", "CORE_DIAG", "CRIT", "CRIT_OUT",
|
||||
"DESC_TEMPLATE", "DESWIZZLE", "DEVICE_PROFILE", "DIALOGUE_CLICK", "DISCORD_APP_ID", "DISCORD_IMAGE", "DISCORD_RPC", "DLAA", "DLAA_JITTER", "DLAA_MV", "DLAA_MASKDEBUG", "DLAA_MVDEBUG", "DLAA_OBJMV", "DLAA_SURVEY", "DLAA_TIMES", "DLSS", "DLSS_CHAR_MASK", "DLSS_PRESET", "DLSS_REACTIVE", "DUMP", "DUMP_BUF", "DUMP_DIR",
|
||||
@@ -106,7 +106,7 @@ static const struct { const char *key, *section; } sections[] = {
|
||||
{"LIB_PREBUILD", "performance"}, {"LIB_PREBUILD_THREADS", "performance"}, {"PIPE_PREBUILD", "performance"},
|
||||
{"PREWARM_XLATE", "performance"}, {"GPL", "performance"}, {"ASTC", "performance"}, {"MEMORY", "performance"},
|
||||
{"TEX_ALIAS", "performance"}, {"TEX_VRAM_PRESSURE", "performance"}, {"TEX_RELEASED_MIB", "performance"}, {"TEX_BLOCK_MIB", "performance"}, {"VMA_BLOCK_MIB", "performance"}, {"ASTC_BC", "performance"}, {"LOD_GUARD", "performance"}, {"FIX_C0", "performance"}, {"FIX_ZERO", "performance"},
|
||||
{"BIND_SKIP", "performance"}, {"SHADER_MEMO", "performance"}, {"PIPE_MEMO", "performance"}, {"MEMX", "performance"}, {"TEX_MEMO", "performance"}, {"VB_USED", "performance"}, {"DESC_TEMPLATE", "performance"},
|
||||
{"BIND_SKIP", "performance"}, {"SHADER_MEMO", "performance"}, {"PIPE_MEMO", "performance"}, {"MEMX", "performance"}, {"BIND_INC", "performance"}, {"TEX_MEMO", "performance"}, {"VB_USED", "performance"}, {"DESC_TEMPLATE", "performance"},
|
||||
{"SYNC_AHEAD", "performance"}, {"SHADOW_DEFER", "performance"}, {"PUSH_SKIP", "performance"}, {"SPLIT_DRAWS", "performance"}, {"SPLIT_US", "performance"}, {"VK_VALIDATION", "performance"},
|
||||
{"VK_DYN_VERTEX", "performance"}, {"VK_DYN_A2C", "performance"}, {"VK_SUBGROUP_PIN", "performance"},
|
||||
{"OPTREF_GUARD", "performance"}, {"ABILITY_GUARD", "performance"}, {"REPORT_GUARD", "performance"},
|
||||
@@ -209,7 +209,7 @@ static const CfgMeta metas[] = {
|
||||
{"OPTREF_GUARD", "1", "0|1", RESTART}, {"ABILITY_GUARD", "1", "0|1", RESTART}, {"REPORT_GUARD", "1", "0|1", RESTART},
|
||||
// render fixes
|
||||
{"LOD_GUARD", "1", "0|1", RESTART}, {"FIX_C0", "1", "0|1", RESTART}, {"FIX_ZERO", "1", "0|1", RESTART},
|
||||
{"BIND_SKIP", "1", "0|1", RESTART}, {"SHADER_MEMO", "1", "0|1", RESTART}, {"PIPE_MEMO", "1", "0|1", RESTART}, {"MEMX", "1", "0|1|check", RESTART}, {"TEX_MEMO", "1", "0|1", RESTART},
|
||||
{"BIND_SKIP", "1", "0|1", RESTART}, {"SHADER_MEMO", "1", "0|1", RESTART}, {"PIPE_MEMO", "1", "0|1", RESTART}, {"MEMX", "1", "0|1|check", RESTART}, {"BIND_INC", "1", "0|1|check", RESTART}, {"TEX_MEMO", "1", "0|1", RESTART},
|
||||
{"VB_USED", "1", "0|1", RESTART},
|
||||
{"DESC_TEMPLATE", "1", "0|1", RESTART},
|
||||
{"PUSH_SKIP", "1", "0|1", RESTART}, {"SPLIT_DRAWS", "64", "0..1000", RESTART},
|
||||
|
||||
+19
-2
@@ -136,6 +136,7 @@ static void state_reset(VkExec *ex) {
|
||||
vk_pipe_state_defaults(&ex->pipe);
|
||||
ex->barrier_at = -1;
|
||||
ex->oq_open = -1;
|
||||
vk_exec_dirty_all(ex);
|
||||
}
|
||||
|
||||
// ---- render targets
|
||||
@@ -410,6 +411,8 @@ void vk_exec_noatt_dims(const VkExec *ex, uint32_t *w, uint32_t *h) {
|
||||
static void resolve_rt_as(VkExec *ex, int peek) {
|
||||
if (ex->rt_resolved) return;
|
||||
ex->rt_resolved = 1;
|
||||
int32_t fmt0[8], ds0[2] = {ex->pipe.depth_fmt, ex->pipe.samples};
|
||||
memcpy(fmt0, ex->pipe.color_fmt, sizeof fmt0);
|
||||
const p_set_rt *r = &ex->rt;
|
||||
int n = r->n < 0 ? 0 : r->n > 8 ? 8 : r->n;
|
||||
uint32_t w = UINT32_MAX, h = UINT32_MAX, layers = UINT32_MAX, samples = 0, scale = 1;
|
||||
@@ -451,6 +454,8 @@ static void resolve_rt_as(VkExec *ex, int peek) {
|
||||
ex->pass_ncolor = (uint32_t)n;
|
||||
ex->pass_samples = samples ? samples : 1;
|
||||
ex->pipe.samples = (uint8_t)ex->pass_samples;
|
||||
if (memcmp(fmt0, ex->pipe.color_fmt, sizeof fmt0) || ds0[0] != ex->pipe.depth_fmt || ds0[1] != ex->pipe.samples)
|
||||
ex->pipe_gen++; // the pipeline's target formats changed
|
||||
}
|
||||
|
||||
static void resolve_rt(VkExec *ex) { resolve_rt_as(ex, 0); }
|
||||
@@ -649,6 +654,7 @@ static void barrier_to(VkExec *ex, const VkImage *want, const VkImageAspectFlags
|
||||
for (int i = 0; i < nwant; i++)
|
||||
if (!has_image(ex->fbl_img, ex->nfbl, want[i]))
|
||||
ib[n++] = layout_barrier(want[i], wasp[i], VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_ATTACHMENT_FEEDBACK_LOOP_OPTIMAL_EXT);
|
||||
if (n || nwant != ex->nfbl) ex->fbl_serial++; // the images in the feedback layout changed
|
||||
for (int i = 0; i < nwant; i++) ex->fbl_img[i] = want[i], ex->fbl_aspect[i] = wasp[i];
|
||||
ex->nfbl = nwant;
|
||||
if (ex->barrier_at == ex->recorded && !n) return;
|
||||
@@ -967,8 +973,16 @@ static int state_op(VkExec *ex, uint32_t op, const void *a) {
|
||||
memcpy(ex->blend_color, ((const p_blend_color *)a)->rgba, sizeof ex->blend_color);
|
||||
ex->dirty |= VK_EXEC_DIRTY_BLEND_CONST;
|
||||
break;
|
||||
case OP_DEPTH_CLAMP: ex->pipe.depth_clamp = ((const p_flag *)a)->value != 0; break;
|
||||
case OP_RASTER_DISCARD: ex->pipe.raster_discard = ((const p_flag *)a)->value != 0; break;
|
||||
case OP_DEPTH_CLAMP: {
|
||||
uint8_t v = ((const p_flag *)a)->value != 0;
|
||||
if (ex->pipe.depth_clamp != v) ex->pipe.depth_clamp = v, ex->pipe_gen++;
|
||||
break;
|
||||
}
|
||||
case OP_RASTER_DISCARD: {
|
||||
uint8_t v = ((const p_flag *)a)->value != 0;
|
||||
if (ex->pipe.raster_discard != v) ex->pipe.raster_discard = v, ex->pipe_gen++;
|
||||
break;
|
||||
}
|
||||
case OP_PRIM_RESTART: ex->prim_restart = *(const p_prim_restart *)a; break;
|
||||
case OP_COPY_STRIDE: ex->copy_stride = ((const p_copy_stride *)a)->stride; break;
|
||||
case OP_SET_TEX_POOL: ex->tex_pool = ((const p_set_pool *)a)->pool, ex->tex_serial++; break;
|
||||
@@ -1170,6 +1184,7 @@ static void *grow_n(void *p, uint32_t *cap, size_t elem) {
|
||||
|
||||
static void copy_state(VkExec *dst, const VkExec *src) {
|
||||
memcpy((char *)dst + VK_EXEC_STATE_BEGIN, (const char *)src + VK_EXEC_STATE_BEGIN, VK_EXEC_STATE_END - VK_EXEC_STATE_BEGIN);
|
||||
vk_exec_dirty_all(dst); // the bound state was replaced: no draw memo may take it for what it held
|
||||
}
|
||||
|
||||
static int draw_op(uint32_t op) { return op == OP_DRAW || op == OP_DRAW_IDX || op == OP_DRAW_IDX_IND; }
|
||||
@@ -1336,6 +1351,7 @@ static void chunk_record(Rec *r, int k) {
|
||||
const Chunk *next = k + 1 < __atomic_load_n(&SC.nch, __ATOMIC_ACQUIRE) ? &SC.ch[k + 1] : NULL;
|
||||
ex->cb = rec_cb(r, RP.fence);
|
||||
ex->fence = RP.fence, ex->recorded = 0, ex->in_pass = 0, ex->nviews = 0, ex->barrier_at = -1, ex->nfbl = 0;
|
||||
ex->fbl_serial++;
|
||||
ex->part_start = 0;
|
||||
x_cur = ex;
|
||||
chunk_k = k;
|
||||
@@ -1701,6 +1717,7 @@ int vk_exec_record(VkCommandBuffer cb, const uint64_t *handles, int n, uint64_t
|
||||
ex->nviews = 0;
|
||||
ex->barrier_at = -1;
|
||||
ex->nfbl = 0; // the previous command buffer ended with a full barrier: every image is in GENERAL
|
||||
ex->fbl_serial++;
|
||||
ex->fr.submits++;
|
||||
ex->split_draws = ex->part_start = 0;
|
||||
ex->part_t0 = kern_now_ns();
|
||||
|
||||
+26
-1
@@ -1,3 +1,14 @@
|
||||
// What the bind ops changed in a context's bound slots since its last prepared draw (VkExec.dirt, TOTK_BIND_INC in
|
||||
// vk_exec_draw.c): a bit per slot, per NVN stage, set only when the bytes an op writes differ from those it replaces.
|
||||
typedef struct {
|
||||
uint32_t prog; // the program pointer or its stage mask
|
||||
uint32_t ubo[6]; // uniform slots 0..17 (OP_BIND_UBO index)
|
||||
uint32_t ssbo[6]; // storage slots 0..15
|
||||
uint64_t tex[6][2]; // texture handles 0..127
|
||||
uint32_t img[6]; // image handles 0..31
|
||||
uint32_t vbuf; // vertex buffer ranges 0..15
|
||||
} VkExecDirty;
|
||||
|
||||
// The op-stream replay of the Vulkan back end. vk_exec.c walks the command
|
||||
// handles of a submission, keeps render targets, passes, clears and fixed-function state; draws, binds and dispatches
|
||||
// (vk_exec_draw.c) and copies, counters, events and conditional rendering (vk_exec_xfer.c) plug in through the two
|
||||
@@ -110,7 +121,7 @@ typedef struct VkExec {
|
||||
const dpool_t *tex_pool, *samp_pool; // OP_SET_TEX_POOL, OP_SET_SAMP_POOL
|
||||
// Pipeline inputs. vk_exec.c writes depth_clamp (OP_DEPTH_CLAMP), raster_discard (OP_RASTER_DISCARD) and, at pass
|
||||
// begin, color_fmt, depth_fmt and samples; vk_exec_draw.c owns every other field (shaders, prim, y_flip, state
|
||||
// objects, vertex input).
|
||||
// objects, vertex input). Every write that changes it bumps pipe_gen.
|
||||
VkPipeState pipe;
|
||||
|
||||
// ---- vk_exec_draw.c slots (draws, binds, dispatch): left empty by vk_exec.c
|
||||
@@ -148,6 +159,14 @@ typedef struct VkExec {
|
||||
const void *fb_fs; // feedback_scan's memo: fragment shader, texture bind serial, pass serial
|
||||
uint32_t fb_serial, fb_pass, fb_sampled;
|
||||
uint32_t tex_serial, pass_serial; // bumped by every texture or image bind and pass begin
|
||||
// TOTK_BIND_INC (vk_exec_draw.c): the slots the bind ops changed since this context's last prepared draw, cleared
|
||||
// by that draw; vk_exec_draw_new_cb and copy_state set every bit. pipe_gen: bumped by every write that changes
|
||||
// pipe (the state object and vertex input binds, OP_DEPTH_CLAMP, OP_RASTER_DISCARD, the target formats of
|
||||
// resolve_rt, copy_state); an equal value says pipe holds what it held then. fbl_serial: bumped whenever the images
|
||||
// in the feedback layout (fbl_img, nfbl) may have changed. Outside the copied state: each context counts its own.
|
||||
VkExecDirty dirt;
|
||||
uint64_t pipe_gen;
|
||||
uint32_t fbl_serial;
|
||||
|
||||
// ---- vk_exec_xfer.c: the occlusion query of the open pass and the queries closed since the last report or reset
|
||||
int oq_open; // slot of the active query, -1 none
|
||||
@@ -195,6 +214,12 @@ void vk_exec_inline_end(int reopen);
|
||||
// vk_exec_draw.c: forget what the command buffer being recorded has bound (pipeline, sets, dynamic state, vertex
|
||||
// buffers): the replay continues in a new one (vk_sync_split).
|
||||
void vk_exec_draw_new_cb(VkExec *ex);
|
||||
// Everything a context's next draw reads may differ from its last prepared draw's (VkExec.dirt, pipe_gen, fbl_serial):
|
||||
// its bound state was replaced or its command buffer state lost.
|
||||
static inline void vk_exec_dirty_all(VkExec *ex) {
|
||||
__builtin_memset(&ex->dirt, 0xff, sizeof ex->dirt);
|
||||
ex->pipe_gen++, ex->fbl_serial++;
|
||||
}
|
||||
// vk_exec_draw.c: the fragment stage of the draw being recorded samples img through one of its bound combined
|
||||
// textures (OP_BIND_TEX, the handles tex_info swaps; vk_dlaa.c vk_dlaa_skip_draw). Takes the texture lock.
|
||||
int vk_exec_draw_samples(VkExec *ex, const GfxShader *fs, const VkTexImage *img);
|
||||
|
||||
+718
-56
File diff suppressed because it is too large.
Load diff
+5
-1
@@ -125,7 +125,9 @@
|
||||
# fix_zero = 1
|
||||
# Optimisations, 0 turns each off: skip bindings that did not change, remember shader lookups, reuse the previous
|
||||
# draw's pipeline when its state repeats, remember texture descriptors between draws, update descriptors in bulk,
|
||||
# skip push constants that did not change, bind only the vertex buffers a draw reads.
|
||||
# skip push constants that did not change, bind only the vertex buffers a draw reads, compare and copy each draw's
|
||||
# state inline, and rebuild only the parts of a draw's bindings, shaders and pipeline whose inputs changed since the
|
||||
# draw before (check: build everything and log any difference from what would have been kept).
|
||||
# bind_skip = 1
|
||||
# shader_memo = 1
|
||||
# pipe_memo = 1
|
||||
@@ -133,6 +135,8 @@
|
||||
# desc_template = 1
|
||||
# push_skip = 1
|
||||
# vb_used = 1
|
||||
# memx = 1
|
||||
# bind_inc = 1
|
||||
# Submit GPU work in parts every N draws between passes so the GPU starts earlier (0 to 1000; 0 = off), each part at
|
||||
# least split_us microseconds long (0 to 20000).
|
||||
# split_draws = 64
|
||||
|
||||
Reference in new issue
Block a user