mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-21 12:55:57 +00:00
Merge #898: record only the dynamic states that changed since the last pipeline state
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
2eb5adebd6
5 files changed
+147
-4
No files matched your search
+1
-1
@@ -41,7 +41,7 @@ static const char *const known[] = {
|
||||
"BIND_ZL", "BIND_ZR", "BLOCK_VIEWS_3D", "CLOTH_REALTIME", "COLOR_BRIGHTNESS", "COLOR_CONTRAST", "COLOR_GAMMA",
|
||||
"COLOR_PRESET", "COLOR_SATURATION", "CONTACT_DEBUG", "CONTACT_SHADOWS", "CORE_DIAG", "CRIT", "CRIT_OUT",
|
||||
"DESC_TEMPLATE", "DEVICE_PROFILE", "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",
|
||||
"DUMP_LOG", "EXEFS", "FEEDBACK", "FIX_C0", "FIX_ZERO", "FLIGHT", "FLIGHT_AT", "FLIGHT_DIR", "FLIGHT_FRAMES",
|
||||
"DUMP_LOG", "DYN_DELTA", "EXEFS", "FEEDBACK", "FIX_C0", "FIX_ZERO", "FLIGHT", "FLIGHT_AT", "FLIGHT_DIR", "FLIGHT_FRAMES",
|
||||
"FLIGHT_SPIKE_MS", "FLIGHT_THUMBS", "FLUSH_SPAN", "FOV", "FOV_PATCH", "FPS60", "FPS_LIMIT", "FRAME_QUEUE",
|
||||
"FREEZE_IDLE", "FREE_CORES",
|
||||
"FULLSCREEN", "FXAA", "GPL", "GPL_DRAW_BUILD", "GPU", "GPU_INDEX", "GPU_NAME", "HDR", "HDR_GAME_NITS", "HDR_HUE",
|
||||
|
||||
@@ -561,6 +561,12 @@ VkPipeline vk_pipeline_compute(const GfxShader *cs, const VkPipeInfo **info);
|
||||
// vk_pipeline_vertex_input_dynamic(), else from VkPipeState.vstream). Returns the vertex bindings (bit per binding) the
|
||||
// state's vertex input reads, whether set here or made into the pipeline.
|
||||
uint32_t vk_pipeline_set_dynamic(VkCommandBuffer cb, const VkPipeState *s);
|
||||
// The replay's variant (one thread, TOTK_DYN_DELTA): valid 1 says every graphics pipeline bound in cb since the last call
|
||||
// was one of vk_pipeline_graphics*'s, which all declare the same dynamic states, and nothing else set them, so cb still
|
||||
// holds what that call recorded (Vulkan keeps dynamic state across such binds for the life of the command buffer);
|
||||
// then only the commands whose values differ are recorded. valid 0 (a new command buffer, or one whose state another
|
||||
// recorder changed) records everything. *cmds: the commands recorded (valid 0: 1). Returns as vk_pipeline_set_dynamic.
|
||||
uint32_t vk_pipeline_set_dynamic_delta(VkCommandBuffer cb, const VkPipeState *s, int valid, uint32_t *cmds);
|
||||
int vk_pipeline_vertex_input_dynamic(void); // 1: vertex input is VK_EXT_vertex_input_dynamic_state
|
||||
// Translator answers from the bound state: attr_type from the vertex attribute formats (vs), frag_out_type from the
|
||||
// colour target formats (fs). Other fields are left as they are; either pointer may be NULL.
|
||||
|
||||
+27
-3
@@ -99,6 +99,8 @@ static struct {
|
||||
VkPipeline pipe[2]; // bound per bind point: 0 graphics, 1 compute
|
||||
VkPipeState st; // the state vk_pipeline_set_dynamic last recorded
|
||||
int st_valid;
|
||||
int dyn_valid; // vk_pipeline_set_dynamic_delta's record of this command buffer's dynamic state
|
||||
// holds (TOTK_DYN_DELTA); pipeline binds keep it, the memset clears it
|
||||
uint32_t vmask; // the vertex bindings st's vertex input reads (valid with st_valid)
|
||||
uint32_t vres; // the streams whose vb entry was resolved from vin (others: the zero buffer)
|
||||
VkBuffer vb[17]; // vertex buffers last bound
|
||||
@@ -139,6 +141,10 @@ static struct {
|
||||
uint64_t draws, bind[2], desc[2], push, push_skip, set_new, set_reuse, ac_miss, same_prog, same_all, bind_skip;
|
||||
} BS = {-1};
|
||||
|
||||
// TOTK_DYN_DELTA (prepare_draw): the mode and, for the perf line, the set_dynamic calls, the commands they recorded
|
||||
// (a full call counts 1) and the calls that recorded none.
|
||||
static struct { int mode; uint64_t calls, cmds, empty; } DD = {-1};
|
||||
|
||||
// The inputs of the last graphics bind_resources (bind_sig) and what its build counted for the traffic census, which a
|
||||
// skipped build counts again. RS_BYTES bounds the bound-slot bytes a pipeline reads (RsList): per binding at most one
|
||||
// c0 storage table, otherwise one bound range or handle per descriptor.
|
||||
@@ -2290,8 +2296,20 @@ static int prepare_draw(VkExec *ex, int prim, int32_t count, int restart) {
|
||||
if (!p || !info) return warn_once(W_PIPELINE, "a graphics pipeline could not be created: draws with it are skipped"), 0;
|
||||
bind_pipeline(ex, VK_PIPELINE_BIND_POINT_GRAPHICS, p);
|
||||
if (!B.st_valid || memcmp(&B.st, &s, sizeof s)) {
|
||||
B.vmask = vk_pipeline_set_dynamic(ex->cb, &s);
|
||||
ex->recorded++;
|
||||
// TOTK_DYN_DELTA: only the dynamic states whose values changed since the last call in this command buffer. A
|
||||
// pipeline bind clears st_valid but not dyn_valid: every pipeline here declares the same dynamic states, which
|
||||
// the bind leaves as they were (the viewport, scissor and stencil values of record_fixed rely on that too).
|
||||
if (DD.mode < 0) DD.mode = rt_knob("DYN_DELTA", "1");
|
||||
uint32_t cmds = 1;
|
||||
if (RT_KNOB_ON(DD.mode)) {
|
||||
B.vmask = vk_pipeline_set_dynamic_delta(ex->cb, &s, B.dyn_valid, &cmds);
|
||||
B.dyn_valid = 1;
|
||||
} else {
|
||||
B.vmask = vk_pipeline_set_dynamic(ex->cb, &s);
|
||||
B.dyn_valid = 0; // the delta's record is stale from here on
|
||||
}
|
||||
DD.calls++, DD.cmds += cmds, DD.empty += !cmds;
|
||||
ex->recorded += cmds != 0;
|
||||
B.st = s, B.st_valid = 1;
|
||||
if (ex->mark && vk_exec_frame.draws == ex->mark_draws0) ex->mark->first[0] = vs, ex->mark->first[1] = fs;
|
||||
}
|
||||
@@ -3391,7 +3409,13 @@ void vk_exec_ub_flush(VkExec *ex) {
|
||||
|
||||
// TOTK_TRACE=perf, every 600 submissions: per submission, the updates and how many stayed in their pass.
|
||||
void vk_exec_ub_perf(void) {
|
||||
static unsigned subs;
|
||||
static unsigned subs, dsubs;
|
||||
if (DD.mode >= 0 && ++dsubs % 600 == 0 && DD.calls) {
|
||||
rt_log("perf: dynamic state per submission: %.1f calls, %.1f commands (a full set counts 1), %.1f calls with "
|
||||
"nothing changed%s", DD.calls / 600.0, DD.cmds / 600.0, DD.empty / 600.0,
|
||||
DD.mode == 2 ? " (TOTK_DYN_DELTA=ab)" : DD.mode ? "" : " (TOTK_DYN_DELTA=0)");
|
||||
DD.calls = DD.cmds = DD.empty = 0;
|
||||
}
|
||||
if (OV.mode <= 0 || ++subs % 600) return;
|
||||
const double k = 1 / 600.0;
|
||||
rt_log("perf: uniform updates per submission %.1f: %.1f overlaid (%.1f of them between passes; copied in %.2f "
|
||||
|
||||
@@ -3168,6 +3168,118 @@ uint32_t vk_pipeline_set_dynamic(VkCommandBuffer cb, const VkPipeState *s) {
|
||||
return streams;
|
||||
}
|
||||
|
||||
// The values vk_pipeline_set_dynamic records for a state, as the commands take them.
|
||||
typedef struct {
|
||||
VkCullModeFlags cull;
|
||||
VkFrontFace front;
|
||||
VkPrimitiveTopology topo;
|
||||
VkBool32 dt, dw, st, bias, discard, restart, clamp, a2c;
|
||||
VkCompareOp df, scmp[2];
|
||||
VkStencilOp sop[2][3]; // fail, pass, depth fail; front, back
|
||||
VkPolygonMode poly;
|
||||
int n; // colour attachments en, eq and wm hold
|
||||
VkBool32 en[8];
|
||||
VkColorBlendEquationEXT eq[8];
|
||||
VkColorComponentFlags wm[8];
|
||||
} DynVals;
|
||||
|
||||
static void dyn_vals(const VkPipeState *s, DynVals *o) {
|
||||
const poly_st *pl = &s->poly;
|
||||
const ds_st *d = &s->ds;
|
||||
memset(o, 0, sizeof *o);
|
||||
o->cull = (VkCullModeFlags)(pl->cull & 3);
|
||||
o->front = pl->front == NVN_FRONT_FACE_CW ? VK_FRONT_FACE_CLOCKWISE : VK_FRONT_FACE_COUNTER_CLOCKWISE;
|
||||
o->topo = vk_pipeline_topology(s->prim);
|
||||
o->dt = d->dt, o->dw = d->dw, o->st = d->st;
|
||||
o->df = compare_op(d->df);
|
||||
o->sop[0][0] = stencil_op(d->fail_f), o->sop[0][1] = stencil_op(d->zpass_f), o->sop[0][2] = stencil_op(d->zfail_f);
|
||||
o->sop[1][0] = stencil_op(d->fail_b), o->sop[1][1] = stencil_op(d->zpass_b), o->sop[1][2] = stencil_op(d->zfail_b);
|
||||
o->scmp[0] = compare_op(d->sf_f), o->scmp[1] = compare_op(d->sf_b);
|
||||
unsigned mode = pl->mode <= NVN_POLYGON_MODE_FILL ? pl->mode : NVN_POLYGON_MODE_FILL;
|
||||
o->bias = (pl->offset_en >> mode & 1) != 0;
|
||||
o->discard = s->raster_discard != 0, o->restart = s->prim_restart != 0;
|
||||
o->clamp = s->depth_clamp != 0, o->a2c = s->ms.a2c != 0;
|
||||
o->poly = polygon_mode(pl->mode);
|
||||
o->n = target_count(s);
|
||||
for (int i = 0; i < o->n; i++) {
|
||||
const blend_st *b = &s->blend[i];
|
||||
o->en[i] = (s->color.blend_en >> i & 1) && blendable(target_format(s->color_fmt[i], NULL, NULL));
|
||||
o->eq[i] = (VkColorBlendEquationEXT){blend_factor(b->src_rgb), blend_factor(b->dst_rgb), blend_op(b->eq_rgb),
|
||||
blend_factor(b->src_a), blend_factor(b->dst_a), blend_op(b->eq_a)};
|
||||
o->wm[i] = target_wmask(s, i);
|
||||
}
|
||||
}
|
||||
|
||||
// What the replay's command buffer holds, as vk_pipeline_set_dynamic_delta last recorded it (the replay thread only):
|
||||
// the values, the inputs of the vertex input and the vertex bindings it reads. Invariant while the caller passes
|
||||
// valid 1: cb holds DC.v for every dynamic state of P.dyn, colour attachments [0, DC.v.n) included.
|
||||
static struct {
|
||||
DynVals v;
|
||||
const GfxShader *vs;
|
||||
uint32_t vattr[16];
|
||||
vs_st vstream[16];
|
||||
uint32_t streams;
|
||||
} DC;
|
||||
|
||||
uint32_t vk_pipeline_set_dynamic_delta(VkCommandBuffer cb, const VkPipeState *s, int valid, uint32_t *cmds) {
|
||||
*cmds = 0;
|
||||
if (!ensure_init()) return VK_PIPE_ALL_BINDINGS;
|
||||
if (!valid) { // a new command buffer, or one whose dynamic state someone else set: everything, as before
|
||||
uint32_t streams = vk_pipeline_set_dynamic(cb, s);
|
||||
dyn_vals(s, &DC.v);
|
||||
DC.vs = s->vs, DC.streams = streams;
|
||||
memcpy(DC.vattr, s->vattr, sizeof DC.vattr), memcpy(DC.vstream, s->vstream, sizeof DC.vstream);
|
||||
*cmds = 1;
|
||||
return streams;
|
||||
}
|
||||
DynVals v;
|
||||
dyn_vals(s, &v);
|
||||
const DynVals *o = &DC.v;
|
||||
uint32_t k = 0;
|
||||
if (v.cull != o->cull) vkCmdSetCullMode(cb, v.cull), k++;
|
||||
if (v.front != o->front) vkCmdSetFrontFace(cb, v.front), k++;
|
||||
if (v.topo != o->topo) vkCmdSetPrimitiveTopology(cb, v.topo), k++;
|
||||
if (v.dt != o->dt) vkCmdSetDepthTestEnable(cb, v.dt), k++;
|
||||
if (v.dw != o->dw) vkCmdSetDepthWriteEnable(cb, v.dw), k++;
|
||||
if (v.df != o->df) vkCmdSetDepthCompareOp(cb, v.df), k++;
|
||||
if (v.st != o->st) vkCmdSetStencilTestEnable(cb, v.st), k++;
|
||||
for (int f = 0; f < 2; f++)
|
||||
if (memcmp(v.sop[f], o->sop[f], sizeof v.sop[f]) || v.scmp[f] != o->scmp[f])
|
||||
vkCmdSetStencilOp(cb, f ? VK_STENCIL_FACE_BACK_BIT : VK_STENCIL_FACE_FRONT_BIT, v.sop[f][0], v.sop[f][1],
|
||||
v.sop[f][2], v.scmp[f]),
|
||||
k++;
|
||||
if (v.bias != o->bias) vkCmdSetDepthBiasEnable(cb, v.bias), k++;
|
||||
if (v.discard != o->discard) vkCmdSetRasterizerDiscardEnable(cb, v.discard), k++;
|
||||
if (v.restart != o->restart) vkCmdSetPrimitiveRestartEnable(cb, v.restart), k++;
|
||||
// The vertex input is made from the vertex shader's inputs and the attribute and stream states alone
|
||||
// (vertex_input): a draw that keeps all three keeps it, and the bindings it reads.
|
||||
if (s->vs != DC.vs || memcmp(s->vattr, DC.vattr, sizeof DC.vattr) || memcmp(s->vstream, DC.vstream, sizeof DC.vstream)) {
|
||||
uint32_t streams = VK_PIPE_ALL_BINDINGS;
|
||||
if (s->vs) {
|
||||
VtxInput vi;
|
||||
vertex_input(s, &vi);
|
||||
if (P.dyn_vi) rec_vertex_input(P.set_vi, cb, vi.n_bind, vi.b, vi.n_attr, vi.a), k++;
|
||||
streams = 0;
|
||||
for (uint32_t i = 0; i < vi.n_bind; i++) streams |= 1u << vi.b[i].binding;
|
||||
}
|
||||
DC.vs = s->vs, DC.streams = streams;
|
||||
memcpy(DC.vattr, s->vattr, sizeof DC.vattr), memcpy(DC.vstream, s->vstream, sizeof DC.vstream);
|
||||
}
|
||||
if (P.dyn_clamp && v.clamp != o->clamp) rec_bool(P.set_clamp, cb, v.clamp), k++;
|
||||
if (P.dyn_poly && v.poly != o->poly) rec_polygon_mode(P.set_poly, cb, v.poly), k++;
|
||||
if (P.dyn_a2c && v.a2c != o->a2c) rec_bool((PFN_vkCmdSetDepthClampEnableEXT)P.set_a2c, cb, v.a2c), k++;
|
||||
// Attachments past o->n may hold nothing yet in this command buffer: a state with more targets sets all of them.
|
||||
// One with fewer leaves the ones past its count as they were, which no draw of it reads.
|
||||
uint32_t n = (uint32_t)v.n;
|
||||
int all = v.n > o->n;
|
||||
if (n && P.dyn_blend_en && (all || memcmp(v.en, o->en, n * sizeof *v.en))) rec_blend_enable(P.set_blend_en, cb, 0, n, v.en), k++;
|
||||
if (n && P.dyn_blend_eq && (all || memcmp(v.eq, o->eq, n * sizeof *v.eq))) rec_blend_equation(P.set_blend_eq, cb, 0, n, v.eq), k++;
|
||||
if (n && P.dyn_wmask && (all || memcmp(v.wm, o->wm, n * sizeof *v.wm))) rec_write_mask(P.set_wmask, cb, 0, n, v.wm), k++;
|
||||
DC.v = v; // the invariant now covers [0, v.n) only
|
||||
*cmds = k;
|
||||
return DC.streams;
|
||||
}
|
||||
|
||||
// ---- statistics, persistence, teardown
|
||||
|
||||
void vk_pipeline_stats(VkPipeStats *s) {
|
||||
|
||||
Reference in new issue
Block a user