mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-18 12:08:38 +00:00
Merge the per-draw shader memo and push skip, the page-indexed pool resolve cache, region-only ReadTexels and WriteTexels, GOB-wide swizzle, the Intel legacy driver vertex-input fallback and all-thread profile chains
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
0140dc1672
10 files changed
+375
-97
No files matched your search
+4
-4
@@ -32,12 +32,12 @@ static const char *const known[] = {
|
||||
"GPU", "GPU_INDEX", "GPU_NAME", "HIGHFPS_FIX", "INPUT", "INPUT_RECORD", "INPUT_SCRIPT", "LANG", "LIB_PREBUILD",
|
||||
"LIB_PREBUILD_KEEP", "LIB_PREBUILD_THREADS", "LOCALE", "LOD_GUARD", "MEMORY", "MINIMAL_LAYOUT", "MIRROR_GAP", "MOTION", "MOUSE_SENS", "MOVIE_HOST",
|
||||
"MOVIE_PACE", "OPERATION_MODE", "PERF_SLOW_MS", "PIPELINE_CACHE", "PIPE_PREBUILD", "PIPE_SYNC", "PREWARM_XLATE",
|
||||
"PROBE_MOVIE", "PROBE_MOVIE_SHOT", "PROFILE", "PROFILE_DIR", "PROFILE_FRAMES", "PROFILE_RENDER", "PUSH_STAGE", "RDOC",
|
||||
"RDOC_DIR", "RDOC_DLL", "REALTIME", "REEXEC", "ROMFS", "ROMFS_INDEX", "ROMFS_MMAP", "ROMFS_MODS", "ROMFS_PATCHES",
|
||||
"PROBE_MOVIE", "PROBE_MOVIE_SHOT", "PROFILE", "PROFILE_CHAINS", "PROFILE_DIR", "PROFILE_FRAMES", "PROFILE_RENDER", "PUSH_SKIP", "PUSH_STAGE", "RDOC",
|
||||
"RDOC_DIR", "RDOC_DLL", "REALTIME", "REEXEC", "RESOLVE_CHECK", "ROMFS", "ROMFS_INDEX", "ROMFS_MMAP", "ROMFS_MODS", "ROMFS_PATCHES",
|
||||
"ROMFS_PROOF_DIR", "ROMFS_VERIFY", "RUMBLE", "RUMBLE_CURVE", "RUMBLE_STRENGTH", "RUMBLE_TRIGGERS",
|
||||
"SHADER_CACHE", "SHARED_FONTS", "SHOTS", "SHOTS_DIR", "SHOTS_FULL",
|
||||
"SHADER_CACHE", "SHADER_MEMO", "SHARED_FONTS", "SHOTS", "SHOTS_DIR", "SHOTS_FULL",
|
||||
"SPEED_PROBE", "SPLIT_DRAWS", "SWKBD_ANSWER", "SWKBD_TEST", "TEST_PREPARE_SHADERS", "TEX_ALIAS", "TIMER_1MS",
|
||||
"TRACE", "VK_NO_FLOAT64", "VK_PRESENT", "VK_SSBO_ALIGN", "VK_SUBGROUP", "VK_SUBGROUP_PIN", "VK_VALIDATION",
|
||||
"TRACE", "VK_NO_FLOAT64", "VK_DYN_VERTEX", "VK_PRESENT", "VK_SSBO_ALIGN", "VK_SUBGROUP", "VK_SUBGROUP_PIN", "VK_VALIDATION",
|
||||
"VS_OUTS", "XLATE", "XLATE_ID", "XLATE_PROCS",
|
||||
};
|
||||
|
||||
|
||||
+10
-5
@@ -2,9 +2,11 @@
|
||||
// A host thread wakes every 1 ms and, for every other thread, suspends it, reads Rip and resumes it. The sampler never
|
||||
// allocates or takes a lock between SuspendThread and ResumeThread and never runs guest code. The profile is text:
|
||||
// totk-prof 1 / base <hex> / period_us / samples N / thread <tid> <samples> <in-exe samples> / module <base> <size> <path> /
|
||||
// rip <hex> <count> (the top PROF_TOP Rips) / stack <count> <rip> <caller> ... (TOTK_PROFILE_RENDER only, the top
|
||||
// PROF_STACKS call chains)
|
||||
// With TOTK_PROFILE_RENDER the sampler also copies up to STK_COPY bytes of the suspended thread's stack and, after
|
||||
// rip <hex> <count> (the top PROF_TOP Rips) / stack <count> <rip> <caller> ... (TOTK_PROFILE_RENDER or
|
||||
// TOTK_PROFILE_CHAINS only, the top PROF_STACKS call chains)
|
||||
// With TOTK_PROFILE_RENDER (the render thread) or TOTK_PROFILE_CHAINS=1 (every thread, chains of all threads summed: for
|
||||
// short frame ranges, as each sample copies a stack) the sampler also copies up to STK_COPY bytes of the suspended
|
||||
// thread's stack and, after
|
||||
// ResumeThread, unwinds the copy with the .pdata tables (RtlVirtualUnwind), so it takes no lock while the thread is
|
||||
// suspended. The unwind stops at the first frame outside the copy; deeper callers are cut.
|
||||
#include <windows.h>
|
||||
@@ -45,6 +47,7 @@ static volatile LONG stop, written;
|
||||
static uintptr_t exe_lo, exe_hi;
|
||||
static volatile DWORD render_tid; // the thread that presents (perf_present)
|
||||
static int only_render; // TOTK_PROFILE_RENDER=1: sample the render thread only
|
||||
static int chains; // call chains are kept: TOTK_PROFILE_RENDER or TOTK_PROFILE_CHAINS
|
||||
static volatile uint64_t cur_frame; // last presented frame
|
||||
static uint64_t frame_lo, frame_hi; // TOTK_PROFILE_FRAMES=<lo>-<hi>: sample only while presents lo..hi-1 are pending
|
||||
|
||||
@@ -151,12 +154,12 @@ static DWORD WINAPI sampler_main(void *arg) {
|
||||
for (int i = 0; i < n_threads; i++) {
|
||||
ThreadSlot *t = &threads[i];
|
||||
if (only_render && t->tid != render_tid) continue;
|
||||
ctx.ContextFlags = only_render ? CONTEXT_CONTROL | CONTEXT_INTEGER : CONTEXT_CONTROL;
|
||||
ctx.ContextFlags = chains ? CONTEXT_CONTROL | CONTEXT_INTEGER : CONTEXT_CONTROL;
|
||||
if (SuspendThread(t->h) == (DWORD)-1) continue;
|
||||
BOOL ok = GetThreadContext(t->h, &ctx);
|
||||
size_t n = 0;
|
||||
MEMORY_BASIC_INFORMATION mb;
|
||||
if (ok && only_render && VirtualQuery((void *)ctx.Rsp, &mb, sizeof mb) && mb.State == MEM_COMMIT) {
|
||||
if (ok && chains && VirtualQuery((void *)ctx.Rsp, &mb, sizeof mb) && mb.State == MEM_COMMIT) {
|
||||
n = (uintptr_t)mb.BaseAddress + mb.RegionSize - ctx.Rsp; // the committed stack above Rsp
|
||||
if (n > STK_COPY) n = STK_COPY;
|
||||
memcpy(stk_buf, (void *)ctx.Rsp, n);
|
||||
@@ -242,6 +245,8 @@ void prof_start(void) {
|
||||
return;
|
||||
}
|
||||
only_render = cfg_get("TOTK_PROFILE_RENDER") != NULL;
|
||||
const char *ch = cfg_get("TOTK_PROFILE_CHAINS");
|
||||
chains = only_render || (ch && *ch && strcmp(ch, "0"));
|
||||
const char *fr = cfg_get("TOTK_PROFILE_FRAMES");
|
||||
if (fr && sscanf(fr, "%llu-%llu", (unsigned long long *)&frame_lo, (unsigned long long *)&frame_hi) != 2) frame_hi = 0;
|
||||
MODULEINFO mi;
|
||||
|
||||
@@ -17,6 +17,11 @@ int nvn_deswizzle(const nvn_texdesc *d, unsigned level, unsigned layer, const vo
|
||||
size_t dst_pitch);
|
||||
int nvn_swizzle(const nvn_texdesc *d, unsigned level, unsigned layer, const void *src_linear, size_t src_pitch,
|
||||
void *dst_storage);
|
||||
// One box of a level and layer, [x, x + wb) bytes by [y, y + h) block rows of slice z (3D textures), between the storage
|
||||
// and caller rows of pitch bytes, touching nothing else of the level: ReadTexels / WriteTexels of a region cost the
|
||||
// region, not the level. Same textures as nvn_deswizzle; -1 for others and for a box outside the level.
|
||||
int nvn_texels_box(const nvn_texdesc *d, unsigned level, unsigned layer, uint32_t x, uint32_t y, uint32_t z, uint32_t wb,
|
||||
uint32_t h, void *storage, void *rows, size_t pitch, int to_linear);
|
||||
// Byte offset of (x byte, y block row, z slice) inside one level of block height 2^th and block depth 2^td GOBs.
|
||||
uint64_t nvn_bl_offset(uint32_t x, uint32_t y, uint32_t z, uint32_t row_bytes, uint32_t rows, unsigned th, unsigned td);
|
||||
// Geometry of a level as the two functions above use it; -1 for textures they reject.
|
||||
|
||||
+46
-4
@@ -46,15 +46,25 @@ int nvn_deswizzle_geom(const nvn_texdesc *d, unsigned level, unsigned layer,
|
||||
return 0;
|
||||
}
|
||||
|
||||
// nvn_bl_offset per row instead of per 16 bytes: within a row, GOB column k starts k blocks further, and the four
|
||||
// 16-byte segments of a GOB row (x % 64 = 0, 16, 32, 48) sit at 0, 32, 256 and 288 of it.
|
||||
void tex_bl_copy(uint8_t *bl, uint8_t *lin, size_t pitch, uint32_t row_bytes, uint32_t rows, uint32_t slices,
|
||||
unsigned th, unsigned td, int to_linear) {
|
||||
static const uint32_t seg[4] = {0, 32, 256, 288};
|
||||
uint64_t block = 512ull << th << td;
|
||||
for (uint32_t z = 0; z < slices; z++)
|
||||
for (uint32_t y = 0; y < rows; y++) {
|
||||
uint8_t *row = lin + ((size_t)z * rows + y) * pitch;
|
||||
for (uint32_t x = 0; x < row_bytes; x += 16) { // 16-byte segments: contiguous within a GOB, and 16 divides every block width
|
||||
uint8_t *row = lin + ((size_t)z * rows + y) * pitch, *g = bl + nvn_bl_offset(0, y, z, row_bytes, rows, th, td);
|
||||
uint32_t x = 0;
|
||||
if (to_linear)
|
||||
for (; x + 64 <= row_bytes; x += 64, g += block)
|
||||
for (int s = 0; s < 4; s++) memcpy(row + x + 16 * s, g + seg[s], 16);
|
||||
else
|
||||
for (; x + 64 <= row_bytes; x += 64, g += block)
|
||||
for (int s = 0; s < 4; s++) memcpy(g + seg[s], row + x + 16 * s, 16);
|
||||
for (int s = 0; x < row_bytes; s++, x += 16) { // a partial GOB at the row's end
|
||||
uint32_t n = row_bytes - x < 16 ? row_bytes - x : 16;
|
||||
uint8_t *p = bl + nvn_bl_offset(x, y, z, row_bytes, rows, th, td);
|
||||
if (to_linear) memcpy(row + x, p, n); else memcpy(p, row + x, n);
|
||||
if (to_linear) memcpy(row + x, g + seg[s], n); else memcpy(g + seg[s], row + x, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,6 +90,38 @@ static int move(const nvn_texdesc *d, unsigned level, unsigned layer, uint8_t *b
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nvn_texels_box(const nvn_texdesc *d, unsigned level, unsigned layer, uint32_t x, uint32_t y, uint32_t z, uint32_t wb,
|
||||
uint32_t h, void *storage, void *rows, size_t pitch, int to_linear) {
|
||||
uint8_t *st = storage, *ln = rows;
|
||||
if (nvn_tex_is_linear(d)) {
|
||||
if (level || layer || z || d->samples > 1 || (d->target != 0 && d->target != 1 && d->target != 7)) return -1;
|
||||
int bw, bh, bpb = nvn_fmt_bpb(d->format, &bw, &bh);
|
||||
if (!bpb) return -1;
|
||||
size_t row = (size_t)((d->width + bw - 1) / bw) * bpb;
|
||||
uint32_t nrows = d->target == 0 ? 1 : (d->height + bh - 1) / bh, stride = nvn_tex_linear_stride(d);
|
||||
if (stride < row || x + (size_t)wb > row || y + (uint64_t)h > nrows) return -1;
|
||||
for (uint32_t r = 0; r < h; r++) {
|
||||
uint8_t *p = st + (size_t)(y + r) * stride + x, *q = ln + r * pitch;
|
||||
if (to_linear) memcpy(q, p, wb); else memcpy(p, q, wb);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
uint32_t row_bytes, nrows, slices, bpb; uint64_t base; unsigned th, td;
|
||||
if (nvn_deswizzle_geom(d, level, layer, &row_bytes, &nrows, &slices, &base, &th, &td, &bpb)) return -1;
|
||||
if (x + (uint64_t)wb > row_bytes || y + (uint64_t)h > nrows || z >= slices) return -1;
|
||||
for (uint32_t r = 0; r < h; r++) {
|
||||
uint8_t *q = ln + r * pitch;
|
||||
for (uint32_t i = 0; i < wb;) {
|
||||
uint32_t xb = x + i, n = 16 - xb % 16; // contiguous up to the end of its 16-byte segment
|
||||
if (n > wb - i) n = wb - i;
|
||||
uint8_t *p = st + base + nvn_bl_offset(xb, y + r, z, row_bytes, nrows, th, td);
|
||||
if (to_linear) memcpy(q + i, p, n); else memcpy(p, q + i, n);
|
||||
i += n;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nvn_deswizzle(const nvn_texdesc *d, unsigned level, unsigned layer, const void *src, void *dst, size_t dst_pitch) {
|
||||
return move(d, level, layer, (uint8_t *)src, (uint8_t *)dst, dst_pitch, 1);
|
||||
}
|
||||
|
||||
+60
-1
@@ -118,6 +118,65 @@ static int test_deswizzle(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// nvn_texels_box against the whole-level path on random boxes: a box read equals the box cut from the deswizzled level,
|
||||
// and a box write leaves the storage as deswizzle, overwrite the box, swizzle does (nothing outside the box changes).
|
||||
static int check_box(const nvn_texdesc *d, unsigned lv, unsigned layer) {
|
||||
uint32_t rb, rows, sl, bpb; uint64_t base; unsigned th, td;
|
||||
if (nvn_deswizzle_geom(d, lv, layer, &rb, &rows, &sl, &base, &th, &td, &bpb)) { printf("probe-vkmem: FAIL box geometry\n"); return 1; }
|
||||
nvn_texlayout L;
|
||||
nvn_tex_layout(d, &L);
|
||||
uint8_t *store = malloc(L.size), *want = malloc(L.size), *lin = malloc((size_t)rb * rows * sl);
|
||||
for (uint64_t i = 0; i < L.size; i++) store[i] = rnd8();
|
||||
uint32_t cols = rb / bpb;
|
||||
for (int k = 0; k < 8; k++) {
|
||||
uint32_t bx = rnd8() % cols, bn = 1 + rnd8() % (cols - bx), y = rnd8() % rows, h = 1 + rnd8() % (rows - y);
|
||||
uint32_t z = sl > 1 ? rnd8() % sl : 0, x = bx * bpb, wb = bn * bpb;
|
||||
size_t pitch = wb + 8;
|
||||
uint8_t *box = malloc(pitch * h), *ref = malloc(pitch * h);
|
||||
// read
|
||||
if (nvn_deswizzle(d, lv, layer, store, lin, rb)) { printf("probe-vkmem: FAIL box deswizzle\n"); return 1; }
|
||||
memset(box, 0xAB, pitch * h), memset(ref, 0xAB, pitch * h);
|
||||
for (uint32_t r = 0; r < h; r++) memcpy(ref + r * pitch, lin + ((size_t)z * rows + y + r) * rb + x, wb);
|
||||
if (nvn_texels_box(d, lv, layer, x, y, z, wb, h, store, box, pitch, 1) || memcmp(box, ref, pitch * h)) {
|
||||
printf("probe-vkmem: FAIL box read format %#x level %u layer %u box %u,%u,%u %ux%u\n", d->format, lv, layer, x, y, z, wb, h);
|
||||
return 1;
|
||||
}
|
||||
// write
|
||||
for (size_t i = 0; i < pitch * h; i++) box[i] = rnd8();
|
||||
memcpy(want, store, L.size);
|
||||
for (uint32_t r = 0; r < h; r++) memcpy(lin + ((size_t)z * rows + y + r) * rb + x, box + r * pitch, wb);
|
||||
if (nvn_swizzle(d, lv, layer, lin, rb, want)) { printf("probe-vkmem: FAIL box swizzle\n"); return 1; }
|
||||
if (nvn_texels_box(d, lv, layer, x, y, z, wb, h, store, box, pitch, 0) || memcmp(store, want, L.size)) {
|
||||
printf("probe-vkmem: FAIL box write format %#x level %u layer %u box %u,%u,%u %ux%u\n", d->format, lv, layer, x, y, z, wb, h);
|
||||
return 1;
|
||||
}
|
||||
g_cases++;
|
||||
free(box), free(ref);
|
||||
}
|
||||
free(store), free(want), free(lin);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_box(void) {
|
||||
// one format per block size: 1, 8 and 16 bytes per texel, 8 and 16 bytes per 4x4 block
|
||||
int fmt[5] = {0}, n = 0;
|
||||
static const int want_bpb[5] = {1, 8, 16, 8, 16}, want_bw[5] = {1, 1, 1, 4, 4};
|
||||
for (int f = 1; f < 0x200 && n < 5; f++) {
|
||||
int bw, bh, bpb = nvn_fmt_bpb(f, &bw, &bh);
|
||||
for (int i = 0; i < 5; i++)
|
||||
if (!fmt[i] && bpb == want_bpb[i] && bw == want_bw[i] && bh == bw) fmt[i] = f, n++;
|
||||
}
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (!fmt[i]) continue;
|
||||
nvn_texdesc d2 = {.target = 1, .format = fmt[i], .width = 300, .height = 170, .depth = 1, .levels = 3};
|
||||
nvn_texdesc da = {.target = 4, .format = fmt[i], .width = 96, .height = 80, .depth = 3, .levels = 2};
|
||||
nvn_texdesc d3 = {.target = 2, .format = fmt[i], .width = 72, .height = 40, .depth = 5, .levels = 2};
|
||||
for (unsigned lv = 0; lv < 2; lv++)
|
||||
if (check_box(&d2, lv, 0) || check_box(&da, lv, 2) || check_box(&d3, lv, 0)) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ---- ASTC ----
|
||||
static void void_block(uint8_t b[16], uint16_t r, uint16_t g, uint16_t bl, uint16_t a, int hdr) {
|
||||
uint64_t lo = 0xFFFFFFFFFFFFFDFCull; // 0x1FC mode, LDR, reserved bits 11, extent all ones
|
||||
@@ -522,7 +581,7 @@ static int test_gpu(void) {
|
||||
}
|
||||
|
||||
int probe_vkmem(void) {
|
||||
if (test_deswizzle() || test_astc() || test_formats()) return 1;
|
||||
if (test_deswizzle() || test_box() || test_astc() || test_formats()) return 1;
|
||||
printf("probe-vkmem: cpu part passed (%u deswizzle cases, %u astc blocks, formats: %u mapped, %u supported by the GPU, "
|
||||
"%u unsupported by the GPU, %u unmapped, %u with a fallback)\n",
|
||||
g_cases, g_astc_blocks, n_mapped, n_supported, n_unsupported, n_unmapped, n_fallback);
|
||||
|
||||
+189
-44
@@ -16,6 +16,7 @@
|
||||
// sampler descriptor lookups and the dispatch flow follow LAS Recomp runtime/nvn/vulkan/exec.c:1851-1908, 2300-2516
|
||||
// @ da35b83a (MIT, Copyright (c) 2026 Peiikai). The support buffer layout is Ryujinx's SupportBuffer.cs (MIT).
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -116,12 +117,18 @@ static struct {
|
||||
VkDescriptorSet ds_bound[2]; // allocated set bound per set number (0: none or pushed since)
|
||||
VkDescriptorSet ds_last[2]; // last allocated and written set per set number, contents in DS
|
||||
VkDescriptorSetLayout ds_last_layout[2];
|
||||
int ds_pushed[2]; // set number holds the push of DS.psig under ds_layout
|
||||
} B;
|
||||
|
||||
// Contents of B.ds_last: the writes' bindings, types, counts and descriptor infos. A draw whose allocated set would
|
||||
// hold the same reuses the set instead of allocating and writing one (Task 2.2's per-draw cost).
|
||||
// hold the same reuses the set instead of allocating and writing one (Task 2.2's per-draw cost). psig: the same for
|
||||
// the last push per set number; a push equal to it under the same layout is not recorded again (the descriptors stay
|
||||
// bound across pipeline binds of that layout).
|
||||
#define DS_SIG_BYTES (MAX_DESC * 24 + MAX_BINDINGS * 12)
|
||||
static struct { uint32_t n[2]; uint8_t sig[2][DS_SIG_BYTES], tmp[DS_SIG_BYTES]; } DS;
|
||||
static struct { uint32_t n[2], pn[2]; uint8_t sig[2][DS_SIG_BYTES], psig[2][DS_SIG_BYTES], tmp[DS_SIG_BYTES]; } DS;
|
||||
|
||||
// TOTK_BIND_STATS counters (bind_stats).
|
||||
static struct { int on; uint64_t draws, bind[2], desc[2], push, push_skip, set_new, set_reuse, ac_miss, same_prog, same_all; } BS = {-1};
|
||||
|
||||
static uint32_t c0_dim[3], c0_binst; // the dispatch size and base instance of the draw or dispatch being bound
|
||||
|
||||
@@ -497,9 +504,10 @@ static int find_stage(const prog_t *p, int nvn_stage, const uint8_t **ctl, const
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Texture and image types of a stage's first 32 slots, kept while its handles and every slot's resolution
|
||||
// (vk_texture_slots_gen) stay the same: consecutive draws mostly bind the same slots, and each lookup is a hash probe.
|
||||
// Texture and image types of a stage's first 32 slots, kept while every slot's resolution (vk_texture_slots_gen)
|
||||
// stays the same: only slots whose handle changed are looked up again, each lookup being a hash probe.
|
||||
static struct { int valid; uint32_t gen; uint64_t tex[32], img[32]; uint8_t tt[32], it[32]; } AC[6];
|
||||
static int shader_memo_on(void);
|
||||
|
||||
static void answers_for(VkExec *ex, int st, const uint8_t *ctl, GfxShaderAnswers *a) {
|
||||
memset(a, 0, sizeof *a);
|
||||
@@ -514,21 +522,39 @@ static void answers_for(VkExec *ex, int st, const uint8_t *ctl, GfxShaderAnswers
|
||||
typeof(AC[0]) *c = &AC[st];
|
||||
vk_texture_lock();
|
||||
uint32_t gen = vk_texture_slots_gen(); // before the lookups: one that creates an entry bumps it
|
||||
if (!c->valid || c->gen != gen || memcmp(c->tex, ex->tex[st], sizeof c->tex) || memcmp(c->img, ex->img[st], sizeof c->img)) {
|
||||
int all = !c->valid || c->gen != gen;
|
||||
if (all || memcmp(c->tex, ex->tex[st], sizeof c->tex) || memcmp(c->img, ex->img[st], sizeof c->img)) {
|
||||
for (int slot = 0; slot < 32; slot++) {
|
||||
view_t v;
|
||||
int hv;
|
||||
uint64_t h = ex->tex[st][slot];
|
||||
const VkTexImage *img = h ? vk_texture_by_id_locked((int)(h & 0xfffff), &v, &hv) : NULL;
|
||||
c->tt[slot] = img ? (uint8_t)gfx_type_of(img, &v, hv) : 0;
|
||||
if (all || h != c->tex[slot]) {
|
||||
const VkTexImage *img = h ? vk_texture_by_id_locked((int)(h & 0xfffff), &v, &hv) : NULL;
|
||||
c->tt[slot] = img ? (uint8_t)gfx_type_of(img, &v, hv) : 0;
|
||||
}
|
||||
h = ex->img[st][slot];
|
||||
img = h ? vk_texture_by_id_locked((int)(h & 0xfffff), &v, &hv) : NULL;
|
||||
c->it[slot] = img ? (uint8_t)gfx_type_of(img, &v, hv) : 0;
|
||||
if (all || h != c->img[slot]) {
|
||||
const VkTexImage *img = h ? vk_texture_by_id_locked((int)(h & 0xfffff), &v, &hv) : NULL;
|
||||
c->it[slot] = img ? (uint8_t)gfx_type_of(img, &v, hv) : 0;
|
||||
}
|
||||
}
|
||||
memcpy(c->tex, ex->tex[st], sizeof c->tex);
|
||||
memcpy(c->img, ex->img[st], sizeof c->img);
|
||||
c->gen = gen, c->valid = 1;
|
||||
BS.ac_miss++;
|
||||
}
|
||||
if (shader_memo_on() == 2) // check mode: every slot looked up again
|
||||
for (int slot = 0; slot < 32; slot++) {
|
||||
view_t v;
|
||||
int hv;
|
||||
uint64_t h = ex->tex[st][slot], hi = ex->img[st][slot];
|
||||
const VkTexImage *img = h ? vk_texture_by_id_locked((int)(h & 0xfffff), &v, &hv) : NULL;
|
||||
int tt = img ? gfx_type_of(img, &v, hv) : 0;
|
||||
img = hi ? vk_texture_by_id_locked((int)(hi & 0xfffff), &v, &hv) : NULL;
|
||||
int it = img ? gfx_type_of(img, &v, hv) : 0;
|
||||
if (tt != c->tt[slot] || it != c->it[slot])
|
||||
rt_fatal("vk_exec: kept texture types of stage %d slot %d differ from a lookup", st, slot);
|
||||
}
|
||||
vk_texture_unlock();
|
||||
memcpy(a->tex_type, c->tt, sizeof c->tt);
|
||||
memcpy(a->img_type, c->it, sizeof c->it);
|
||||
@@ -898,30 +924,101 @@ static void support_fill(uint8_t *b, float w, float h, float point_size) {
|
||||
for (int i = 0; i < 73; i++) memcpy(b + 192 + 16 * i, &one, 4); // render scale 1: the host renders at guest size
|
||||
}
|
||||
|
||||
// TOTK_BIND_STATS=1: bindings and descriptors per draw of each stage, logged every 20000 draws (Task 2.2's choice of
|
||||
// the pushed stage).
|
||||
static struct { int on; uint64_t draws, bind[2], desc[2]; } BS = {-1};
|
||||
|
||||
static void bind_stats(const VkPipeInfo *info) {
|
||||
// TOTK_BIND_STATS=1: bindings and descriptors per draw of each stage (Task 2.2's choice of the pushed stage), and how
|
||||
// often a draw repeats the previous one, logged every 20000 draws: pushes recorded and skipped, allocated sets written
|
||||
// and reused, stage texture-type recomputations (answers_for), draws with the previous draw's program, bound state
|
||||
// and textures (shaders and pipeline would be the same) and those that also have its buffers and viewport (all
|
||||
// descriptors would be the same). BS is declared beside DS.
|
||||
static int bind_stats_on(void) {
|
||||
if (BS.on < 0) {
|
||||
const char *e = cfg_get("TOTK_BIND_STATS");
|
||||
BS.on = e && *e && strcmp(e, "0");
|
||||
}
|
||||
if (!BS.on || info->bind_point != VK_PIPELINE_BIND_POINT_GRAPHICS) return;
|
||||
return BS.on;
|
||||
}
|
||||
|
||||
static void bind_stats(const VkPipeInfo *info) {
|
||||
if (!bind_stats_on() || info->bind_point != VK_PIPELINE_BIND_POINT_GRAPHICS) return;
|
||||
for (uint32_t i = 0; i < info->n_bindings; i++) {
|
||||
const VkPipeBinding *b = &info->bindings[i];
|
||||
int fs = info->n_sets > 1 ? b->set : !(b->stages & VK_SHADER_STAGE_VERTEX_BIT);
|
||||
BS.bind[fs]++, BS.desc[fs] += b->count ? b->count : 1;
|
||||
}
|
||||
if (++BS.draws % 20000 == 0)
|
||||
if (++BS.draws % 20000 == 0) {
|
||||
double d = (double)BS.draws;
|
||||
rt_log("vk_exec: per draw over %llu draws: vertex %.2f bindings %.2f descriptors, fragment %.2f bindings %.2f descriptors",
|
||||
(unsigned long long)BS.draws, (double)BS.bind[0] / BS.draws, (double)BS.desc[0] / BS.draws,
|
||||
(double)BS.bind[1] / BS.draws, (double)BS.desc[1] / BS.draws);
|
||||
(unsigned long long)BS.draws, BS.bind[0] / d, BS.desc[0] / d, BS.bind[1] / d, BS.desc[1] / d);
|
||||
rt_log("vk_exec: per draw: pushes %.3f skipped %.3f, sets written %.3f reused %.3f, texture types %.3f; "
|
||||
"same program and state as the draw before %.3f, also same buffers %.3f",
|
||||
BS.push / d, BS.push_skip / d, BS.set_new / d, BS.set_reuse / d, BS.ac_miss / d, BS.same_prog / d,
|
||||
BS.same_all / d);
|
||||
}
|
||||
}
|
||||
|
||||
// The bound state a draw reads, compared with the previous draw's (TOTK_BIND_STATS only).
|
||||
static void repeat_stats(const VkExec *ex, const VkPipeInfo *info) {
|
||||
static struct {
|
||||
const prog_t *prog;
|
||||
VkPipeState pipe;
|
||||
uint64_t tex[2][128], img[2][32];
|
||||
const VkPipeInfo *info;
|
||||
p_bind_buf ubo[2][18], ssbo[2][16];
|
||||
float vp[6], point_size;
|
||||
} last, cur;
|
||||
if (!bind_stats_on()) return;
|
||||
memset(&cur, 0, sizeof cur);
|
||||
cur.prog = ex->prog, cur.pipe = ex->pipe, cur.info = info;
|
||||
const int st[2] = {NVN_STAGE_VS, NVN_STAGE_FS};
|
||||
for (int k = 0; k < 2; k++) {
|
||||
memcpy(cur.tex[k], ex->tex[st[k]], sizeof cur.tex[k]), memcpy(cur.img[k], ex->img[st[k]], sizeof cur.img[k]);
|
||||
memcpy(cur.ubo[k], ex->ubo[st[k]], sizeof cur.ubo[k]), memcpy(cur.ssbo[k], ex->ssbo[st[k]], sizeof cur.ssbo[k]);
|
||||
}
|
||||
memcpy(cur.vp, ex->vp[0], sizeof cur.vp), cur.point_size = ex->point_size;
|
||||
size_t prog_part = offsetof(typeof(cur), info);
|
||||
if (!memcmp(&cur, &last, prog_part)) {
|
||||
BS.same_prog++;
|
||||
if (!memcmp((const char *)&cur + prog_part, (const char *)&last + prog_part, sizeof cur - prog_part)) BS.same_all++;
|
||||
}
|
||||
last = cur;
|
||||
}
|
||||
|
||||
// The signature of a set's writes into out (DS layout): bindings, types, counts and descriptor infos. Returns its size.
|
||||
static uint32_t ds_sig(const VkWriteDescriptorSet *w, uint32_t nw, uint8_t *out) {
|
||||
uint32_t n = 0;
|
||||
for (uint32_t k = 0; k < nw; k++) {
|
||||
const VkWriteDescriptorSet *x = &w[k];
|
||||
uint32_t hdr[3] = {x->dstBinding, (uint32_t)x->descriptorType, x->descriptorCount};
|
||||
memcpy(out + n, hdr, sizeof hdr), n += sizeof hdr;
|
||||
if (x->pImageInfo) { // field by field: the struct's tail padding is not written
|
||||
for (uint32_t d = 0; d < x->descriptorCount; d++) {
|
||||
const VkDescriptorImageInfo *ii1 = &x->pImageInfo[d];
|
||||
memcpy(out + n, &ii1->sampler, 8), memcpy(out + n + 8, &ii1->imageView, 8);
|
||||
memcpy(out + n + 16, &ii1->imageLayout, 4), n += 20;
|
||||
}
|
||||
} else if (x->pBufferInfo) {
|
||||
memcpy(out + n, x->pBufferInfo, sizeof *x->pBufferInfo * x->descriptorCount);
|
||||
n += (uint32_t)(sizeof *x->pBufferInfo * x->descriptorCount);
|
||||
} else {
|
||||
memcpy(out + n, x->pTexelBufferView, sizeof *x->pTexelBufferView * x->descriptorCount);
|
||||
n += (uint32_t)(sizeof *x->pTexelBufferView * x->descriptorCount);
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
static int push_skip_on(void) { // TOTK_PUSH_SKIP=0: every graphics draw pushes its set again
|
||||
static int on = -1;
|
||||
if (on < 0) {
|
||||
const char *e = cfg_get("TOTK_PUSH_SKIP");
|
||||
on = !(e && !strcmp(e, "0"));
|
||||
}
|
||||
return on;
|
||||
}
|
||||
|
||||
// Writes the pipeline's sets from the bound state: set 0, and set 1 with independent layouts. Each is pushed into the
|
||||
// command buffer, or allocated, written and bound; a graphics set whose contents equal the last one allocated for that
|
||||
// set number in this command buffer is reused, and bound again only when another layout or a push came between.
|
||||
// set number in this command buffer is reused, and bound again only when another layout or a push came between. A
|
||||
// graphics push equal to the last one at its set number, with no other layout or bind between, is not recorded.
|
||||
static void bind_resources(VkExec *ex, const VkPipeInfo *info) {
|
||||
static VkWriteDescriptorSet w[MAX_BINDINGS];
|
||||
static VkDescriptorBufferInfo bi[MAX_DESC];
|
||||
@@ -995,6 +1092,7 @@ static void bind_resources(VkExec *ex, const VkPipeInfo *info) {
|
||||
if (gfx && info->layout != B.ds_layout) { // another layout: sets bound before may be disturbed
|
||||
B.ds_layout = info->layout;
|
||||
B.ds_bound[0] = B.ds_bound[1] = VK_NULL_HANDLE;
|
||||
B.ds_pushed[0] = B.ds_pushed[1] = 0;
|
||||
set1_first = n_sets == 2 && vk_ctx()->validation;
|
||||
}
|
||||
uint32_t lo[2] = {0, 0}, hi[2] = {0, 0};
|
||||
@@ -1009,13 +1107,22 @@ static void bind_resources(VkExec *ex, const VkPipeInfo *info) {
|
||||
if (set1_first) { // bound only to drop the layer's push set (comment above)
|
||||
VkDescriptorSet set = alloc_set(ex, info->set_layout1);
|
||||
vkCmdBindDescriptorSets(ex->cb, info->bind_point, info->layout, 1, 1, &set, 0, NULL);
|
||||
B.ds_bound[1] = set;
|
||||
B.ds_bound[1] = set, B.ds_pushed[1] = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (s ? info->push1 : info->push) {
|
||||
uint32_t n = gfx && push_skip_on() ? ds_sig(w + i0, i1 - i0, DS.tmp) : 0;
|
||||
if (n && B.ds_pushed[s] && DS.pn[s] == n && !memcmp(DS.psig[s], DS.tmp, n)) {
|
||||
BS.push_skip++;
|
||||
continue;
|
||||
}
|
||||
vk_pipeline_push_fn()(ex->cb, info->bind_point, info->layout, s, i1 - i0, w + i0);
|
||||
if (gfx) B.ds_bound[s] = VK_NULL_HANDLE;
|
||||
BS.push++;
|
||||
if (gfx) {
|
||||
B.ds_bound[s] = VK_NULL_HANDLE, B.ds_pushed[s] = n != 0;
|
||||
if (n) DS.pn[s] = n, memcpy(DS.psig[s], DS.tmp, n);
|
||||
}
|
||||
} else if (!gfx || s > 1) {
|
||||
VkDescriptorSet set = alloc_set(ex, s ? info->set_layout1 : info->set_layout);
|
||||
for (uint32_t k = i0; k < i1; k++) w[k].dstSet = set;
|
||||
@@ -1023,25 +1130,7 @@ static void bind_resources(VkExec *ex, const VkPipeInfo *info) {
|
||||
vkCmdBindDescriptorSets(ex->cb, info->bind_point, info->layout, s, 1, &set, 0, NULL);
|
||||
} else {
|
||||
VkDescriptorSetLayout sl = s ? info->set_layout1 : info->set_layout;
|
||||
uint32_t n = 0;
|
||||
for (uint32_t k = i0; k < i1; k++) {
|
||||
const VkWriteDescriptorSet *x = &w[k];
|
||||
uint32_t hdr[3] = {x->dstBinding, (uint32_t)x->descriptorType, x->descriptorCount};
|
||||
memcpy(DS.tmp + n, hdr, sizeof hdr), n += sizeof hdr;
|
||||
if (x->pImageInfo) { // field by field: the struct's tail padding is not written
|
||||
for (uint32_t d = 0; d < x->descriptorCount; d++) {
|
||||
const VkDescriptorImageInfo *ii1 = &x->pImageInfo[d];
|
||||
memcpy(DS.tmp + n, &ii1->sampler, 8), memcpy(DS.tmp + n + 8, &ii1->imageView, 8);
|
||||
memcpy(DS.tmp + n + 16, &ii1->imageLayout, 4), n += 20;
|
||||
}
|
||||
} else if (x->pBufferInfo) {
|
||||
memcpy(DS.tmp + n, x->pBufferInfo, sizeof *x->pBufferInfo * x->descriptorCount);
|
||||
n += (uint32_t)(sizeof *x->pBufferInfo * x->descriptorCount);
|
||||
} else {
|
||||
memcpy(DS.tmp + n, x->pTexelBufferView, sizeof *x->pTexelBufferView * x->descriptorCount);
|
||||
n += (uint32_t)(sizeof *x->pTexelBufferView * x->descriptorCount);
|
||||
}
|
||||
}
|
||||
uint32_t n = ds_sig(w + i0, i1 - i0, DS.tmp);
|
||||
VkDescriptorSet set = B.ds_last[s];
|
||||
if (!set || B.ds_last_layout[s] != sl || DS.n[s] != n || memcmp(DS.sig[s], DS.tmp, n)) {
|
||||
set = alloc_set(ex, sl);
|
||||
@@ -1049,10 +1138,13 @@ static void bind_resources(VkExec *ex, const VkPipeInfo *info) {
|
||||
if (i1 > i0) vkUpdateDescriptorSets(vk_ctx()->device, i1 - i0, w + i0, 0, NULL);
|
||||
B.ds_last[s] = set, B.ds_last_layout[s] = sl, DS.n[s] = n;
|
||||
memcpy(DS.sig[s], DS.tmp, n);
|
||||
BS.set_new++;
|
||||
} else {
|
||||
BS.set_reuse++;
|
||||
}
|
||||
if (B.ds_bound[s] != set) {
|
||||
vkCmdBindDescriptorSets(ex->cb, info->bind_point, info->layout, s, 1, &set, 0, NULL);
|
||||
B.ds_bound[s] = set;
|
||||
B.ds_bound[s] = set, B.ds_pushed[s] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1136,6 +1228,43 @@ static void bind_vertex_buffers(VkExec *ex) {
|
||||
B.vb_valid = 1;
|
||||
}
|
||||
|
||||
// The previous draw's shaders, kept while its program, bound pipeline state, the vertex and fragment stages' first 32
|
||||
// texture and image handles and every slot's resolution (vk_texture_slots_gen, read unlocked: a registration racing
|
||||
// with it is ordered after this draw, as answers_for's own check would order it) stay the same: answers_for reads
|
||||
// nothing else, so shader_for would return the same shaders. About 65% of field draws repeat them
|
||||
// (TOTK_BIND_STATS). TOTK_SHADER_MEMO=0 turns it off; =check looks the shaders up on every hit too, and every slot's
|
||||
// texture type in answers_for, and stops on a difference.
|
||||
typedef struct {
|
||||
const prog_t *prog;
|
||||
uint64_t serial;
|
||||
uint32_t gen;
|
||||
uint64_t tex[2][32], img[2][32];
|
||||
VkPipeState pipe;
|
||||
} MemoKey;
|
||||
static struct { int on, valid, has_fs; MemoKey k; const GfxShader *vs, *fs; } SM = {-1};
|
||||
|
||||
static void memo_key(const VkExec *ex, uint32_t gen, MemoKey *k) {
|
||||
k->prog = ex->prog, k->serial = ex->prog->serial, k->gen = gen;
|
||||
memcpy(k->tex[0], ex->tex[NVN_STAGE_VS], sizeof k->tex[0]), memcpy(k->tex[1], ex->tex[NVN_STAGE_FS], sizeof k->tex[1]);
|
||||
memcpy(k->img[0], ex->img[NVN_STAGE_VS], sizeof k->img[0]), memcpy(k->img[1], ex->img[NVN_STAGE_FS], sizeof k->img[1]);
|
||||
memcpy(&k->pipe, &ex->pipe, sizeof k->pipe);
|
||||
}
|
||||
|
||||
static int memo_match(const VkExec *ex, uint32_t gen, const MemoKey *k) {
|
||||
return k->prog == ex->prog && k->serial == ex->prog->serial && k->gen == gen &&
|
||||
!memcmp(k->tex[0], ex->tex[NVN_STAGE_VS], sizeof k->tex[0]) && !memcmp(k->tex[1], ex->tex[NVN_STAGE_FS], sizeof k->tex[1]) &&
|
||||
!memcmp(k->img[0], ex->img[NVN_STAGE_VS], sizeof k->img[0]) && !memcmp(k->img[1], ex->img[NVN_STAGE_FS], sizeof k->img[1]) &&
|
||||
!memcmp(&k->pipe, &ex->pipe, sizeof k->pipe);
|
||||
}
|
||||
|
||||
static int shader_memo_on(void) {
|
||||
if (SM.on < 0) {
|
||||
const char *e = cfg_get("TOTK_SHADER_MEMO");
|
||||
SM.on = e && !strcmp(e, "check") ? 2 : !(e && !strcmp(e, "0"));
|
||||
}
|
||||
return SM.on;
|
||||
}
|
||||
|
||||
// Pass, shaders, pipeline, fixed state and resources for a draw. 0: the draw is skipped.
|
||||
static int prepare_draw(VkExec *ex, int prim, int32_t count, int restart) {
|
||||
if (ex->render_disabled) return 0;
|
||||
@@ -1146,9 +1275,24 @@ static int prepare_draw(VkExec *ex, int prim, int32_t count, int restart) {
|
||||
VkRect2D sc = vk_exec_scissor(ex);
|
||||
if (!sc.extent.width || !sc.extent.height) return 0;
|
||||
if (!ex->prog) return warn_once(W_PROGRAM, "a draw without a bound program is skipped"), 0;
|
||||
int has_vs, has_fs, vs_wait, fs_wait;
|
||||
const GfxShader *vs = shader_for(ex, NVN_STAGE_VS, &has_vs, &vs_wait, 0);
|
||||
const GfxShader *fs = shader_for(ex, NVN_STAGE_FS, &has_fs, &fs_wait, 0);
|
||||
int has_vs, has_fs, vs_wait = 0, fs_wait = 0, memo = shader_memo_on();
|
||||
const GfxShader *vs, *fs;
|
||||
uint32_t gen = memo ? vk_texture_slots_gen() : 0; // before shader_for, whose lookups may bump it
|
||||
if (memo && SM.valid && memo_match(ex, gen, &SM.k)) {
|
||||
vs = SM.vs, fs = SM.fs, has_vs = 1, has_fs = SM.has_fs;
|
||||
if (memo == 2) {
|
||||
int hv, hf, wv, wf;
|
||||
const GfxShader *v2 = shader_for(ex, NVN_STAGE_VS, &hv, &wv, 0), *f2 = shader_for(ex, NVN_STAGE_FS, &hf, &wf, 0);
|
||||
if (v2 != vs || f2 != fs || hf != has_fs || wv || wf)
|
||||
rt_fatal("vk_exec: shader memo of program %llu differs from the lookup", (unsigned long long)ex->prog->serial);
|
||||
}
|
||||
} else {
|
||||
SM.valid = 0;
|
||||
vs = shader_for(ex, NVN_STAGE_VS, &has_vs, &vs_wait, 0);
|
||||
fs = shader_for(ex, NVN_STAGE_FS, &has_fs, &fs_wait, 0);
|
||||
if (memo && vs && !vs_wait && !fs_wait && (!has_fs || fs))
|
||||
memo_key(ex, gen, &SM.k), SM.vs = vs, SM.fs = fs, SM.has_fs = has_fs, SM.valid = 1;
|
||||
}
|
||||
if (!has_vs) return warn_once(W_NO_VS, "a draw with a program that has no vertex stage is skipped"), 0;
|
||||
// A draw into a target the previous frame did not render (or into none) waits for a pending shader or pipeline:
|
||||
// one-shot draws (volumes and LUTs generated once, later only sampled) would leave their target empty for the
|
||||
@@ -1204,6 +1348,7 @@ static int prepare_draw(VkExec *ex, int prim, int32_t count, int restart) {
|
||||
B.st = s, B.st_valid = 1;
|
||||
}
|
||||
record_fixed(ex);
|
||||
repeat_stats(ex, info);
|
||||
bind_resources(ex, info);
|
||||
if (fbl & ex->fb_dirty) feedback_barrier(ex);
|
||||
feedback_written(ex, &s);
|
||||
|
||||
+41
-16
@@ -350,7 +350,10 @@ int vk_pool_map_virtual(pool_t *v, int n, const void *requests) {
|
||||
}
|
||||
|
||||
// Per-thread copies of resolved import and physical pools that overlap no other index entry (so pidx_find picks them for
|
||||
// any range inside), valid while pool_gen is unchanged: the replay resolves a few pools thousands of times per frame.
|
||||
// any range inside), valid while pool_gen is unchanged: the replay resolves a few dozen pools thousands of times per
|
||||
// frame (16 vertex streams and every buffer binding of each draw). Direct-mapped by the 4 KiB page of the address, so
|
||||
// a hit is one compare however many pools a frame touches. TOTK_RESOLVE_CHECK=1 compares every hit with the locked
|
||||
// lookup and stops on a difference.
|
||||
static int rec_class(const PoolRec *r) {
|
||||
if (r->kind != POOL_IMPORT) return VK_MCLS_DEVICE;
|
||||
return r->flags & NVN_MEMORY_POOL_FLAGS_CPU_NO_ACCESS ? VK_MCLS_HOST_NOACC
|
||||
@@ -358,25 +361,47 @@ static int rec_class(const PoolRec *r) {
|
||||
}
|
||||
|
||||
typedef struct { uint64_t gen, lo, hi, base, end; VkBuffer buf; VmaAllocation alloc; int cls; void *pool; } ResolveHit;
|
||||
static _Thread_local ResolveHit rhit[4];
|
||||
static _Thread_local unsigned rhit_next;
|
||||
#define RHIT_SLOTS 512
|
||||
static _Thread_local ResolveHit rhit[RHIT_SLOTS];
|
||||
|
||||
static ResolveHit *rhit_slot(uint64_t addr) { return &rhit[(addr >> 12 ^ addr >> 21) & (RHIT_SLOTS - 1)]; }
|
||||
|
||||
static int resolve_check_on(void) {
|
||||
static int on = -1;
|
||||
if (on < 0) {
|
||||
const char *e = cfg_get("TOTK_RESOLVE_CHECK");
|
||||
on = e && *e && strcmp(e, "0");
|
||||
}
|
||||
return on;
|
||||
}
|
||||
|
||||
static int resolve_locked(uint64_t addr, uint64_t size, VkMemSpan *out);
|
||||
|
||||
int vk_mem_resolve(uint64_t addr, uint64_t size, VkMemSpan *out) {
|
||||
memset(out, 0, sizeof *out);
|
||||
uint64_t g = __atomic_load_n(&pool_gen, __ATOMIC_ACQUIRE), end = addr + size;
|
||||
if (end >= addr)
|
||||
for (int i = 0; i < 4; i++) {
|
||||
const ResolveHit *h = &rhit[i];
|
||||
if (h->gen != g || addr < h->lo || end > h->hi) continue;
|
||||
out->buffer = h->buf;
|
||||
out->offset = addr - h->base;
|
||||
out->avail = h->end - addr;
|
||||
out->alloc = h->alloc;
|
||||
out->cls = h->cls;
|
||||
out->pool = h->pool;
|
||||
if (h->alloc) out->alloc_offset = out->offset;
|
||||
return 1;
|
||||
const ResolveHit *h = rhit_slot(addr);
|
||||
if (end >= addr && h->gen == g && addr >= h->lo && end <= h->hi) {
|
||||
out->buffer = h->buf;
|
||||
out->offset = addr - h->base;
|
||||
out->avail = h->end - addr;
|
||||
out->alloc = h->alloc;
|
||||
out->cls = h->cls;
|
||||
out->pool = h->pool;
|
||||
if (h->alloc) out->alloc_offset = out->offset;
|
||||
if (resolve_check_on()) {
|
||||
VkMemSpan s;
|
||||
if (!resolve_locked(addr, size, &s) || memcmp(&s, out, sizeof s))
|
||||
rt_fatal("vk: resolve cache of 0x%llx differs from the pool index", (unsigned long long)addr);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return resolve_locked(addr, size, out);
|
||||
}
|
||||
|
||||
// The pool index lookup under the lock; a non-overlapped import or physical pool goes into the address's cache slot.
|
||||
static int resolve_locked(uint64_t addr, uint64_t size, VkMemSpan *out) {
|
||||
memset(out, 0, sizeof *out);
|
||||
AcquireSRWLockShared(&pool_lock);
|
||||
const pidx_ent *e = pidx_find(&pool_index, (uintptr_t)addr, size);
|
||||
PoolRec *r = e ? e->buf : NULL;
|
||||
@@ -384,7 +409,7 @@ int vk_mem_resolve(uint64_t addr, uint64_t size, VkMemSpan *out) {
|
||||
if (r && (r->kind == POOL_IMPORT ? r->buf != VK_NULL_HANDLE : r->kind == POOL_PHYS)) {
|
||||
int i = (int)(e - pool_index.e);
|
||||
if ((i == 0 || pool_index.maxhi[i - 1] <= e->lo) && (i + 1 == pool_index.n || pool_index.e[i + 1].lo >= e->hi)) {
|
||||
ResolveHit *h = &rhit[rhit_next++ & 3];
|
||||
ResolveHit *h = rhit_slot(addr);
|
||||
h->gen = __atomic_load_n(&pool_gen, __ATOMIC_RELAXED); // stable: changed only under the exclusive lock
|
||||
h->lo = e->lo, h->hi = e->hi, h->buf = r->buf, h->cls = rec_class(r);
|
||||
if (r->kind == POOL_IMPORT) h->base = r->import_lo, h->end = r->import_hi, h->alloc = NULL, h->pool = r;
|
||||
|
||||
@@ -242,7 +242,15 @@ static int ensure_init(void) {
|
||||
P.f_dual_src = f2.features.dualSrcBlend;
|
||||
#define PROC(field, name) (P.field = (void *)vkGetDeviceProcAddr(c->device, name))
|
||||
PROC(push, "vkCmdPushDescriptorSetKHR");
|
||||
P.dyn_vi = c->has_vertex_input_dynamic_state && PROC(set_vi, "vkCmdSetVertexInputEXT");
|
||||
// TOTK_VK_DYN_VERTEX=0/1 forces dynamic vertex input off or on. Default off on Intel's frozen Windows driver for its
|
||||
// older integrated GPUs (UHD 630, Ice Lake: Vulkan 1.3.215 and older), which draws nothing with it (LAS Recomp
|
||||
// 61fe44ff, its issues #8 and #357).
|
||||
const char *dv = cfg_get("TOTK_VK_DYN_VERTEX");
|
||||
int intel_legacy = c->props.vendorID == 0x8086 && c->props.apiVersion <= VK_MAKE_API_VERSION(0, 1, 3, 215);
|
||||
int dv_on = dv && *dv ? strcmp(dv, "0") != 0 : !intel_legacy;
|
||||
P.dyn_vi = dv_on && c->has_vertex_input_dynamic_state && PROC(set_vi, "vkCmdSetVertexInputEXT");
|
||||
if (!dv_on && c->has_vertex_input_dynamic_state)
|
||||
rt_log("vk_pipeline: dynamic vertex input off (%s)", dv && *dv ? "TOTK_VK_DYN_VERTEX=0" : "Intel's older Windows driver draws nothing with it");
|
||||
if (c->has_eds3) {
|
||||
P.dyn_clamp = e3.extendedDynamicState3DepthClampEnable && P.f_depth_clamp && PROC(set_clamp, "vkCmdSetDepthClampEnableEXT");
|
||||
P.dyn_poly = e3.extendedDynamicState3PolygonMode && PROC(set_poly, "vkCmdSetPolygonModeEXT");
|
||||
|
||||
+9
-20
@@ -932,29 +932,18 @@ static int region_of(const tex_t *t, const view_t *v, const NVNcopyRegion *r, ui
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Pool bytes <-> caller rows through a linear copy of the level (MNG nvn_mtl.m:10121-10132, 10158-10170).
|
||||
// Pool bytes <-> caller rows of the region alone (nvn_texels_box). MNG nvn_mtl.m:10121-10132, 10158-10170 go through a
|
||||
// linear copy of the whole level; for a small region of a large texture that cost tens of milliseconds while the guest
|
||||
// thread held its virtual core and the caller the texture lock (monsters2 replay, frames 765-790).
|
||||
static int storage_texels(const tex_t *t, const Region *g, const NVNcopyRegion *r, uint8_t *mem, int write) {
|
||||
const nvn_texdesc *d = &t->d;
|
||||
uint32_t lw = mip(d->width, g->level), lh = d->target == 0 || d->target == 3 ? 1 : mip(d->height, g->level);
|
||||
uint32_t lz = g->is3d ? mip(d->depth, g->level) : 1;
|
||||
size_t lp = (size_t)((lw + g->bw - 1) / g->bw) * (size_t)g->bpb, lr = (lh + g->bh - 1) / (uint32_t)g->bh;
|
||||
if (g->x0 + g->wb > lp || g->y0 + g->hb > lr || (g->is3d && (uint32_t)(r->zoffset + g->nz) > lz)) return 0;
|
||||
uint8_t *lin = malloc(lp * lr * lz);
|
||||
if (!lin) rt_fatal("vk: out of memory for texels");
|
||||
int ok = 1;
|
||||
for (int z = 0; z < g->nz && ok; z++) {
|
||||
for (int z = 0; z < g->nz; z++) {
|
||||
unsigned layer = g->is3d ? 0 : g->layer0 + (unsigned)r->zoffset + (unsigned)z;
|
||||
if ((!g->is3d || z == 0) && nvn_deswizzle(d, g->level, layer, t->mem, lin, lp)) { ok = 0; break; }
|
||||
uint8_t *slice = lin + (g->is3d ? (size_t)(r->zoffset + z) * lp * lr : 0);
|
||||
for (size_t y = 0; y < g->hb; y++) {
|
||||
uint8_t *p = slice + (g->y0 + y) * lp + g->x0, *q = mem + (size_t)z * g->img + y * g->row;
|
||||
if (write) memcpy(p, q, g->wb);
|
||||
else memcpy(q, p, g->wb);
|
||||
}
|
||||
if (write && (!g->is3d || z == g->nz - 1) && nvn_swizzle(d, g->level, layer, lin, lp, t->mem)) ok = 0;
|
||||
uint32_t slice = g->is3d ? (uint32_t)(r->zoffset + z) : 0;
|
||||
if (nvn_texels_box(&t->d, g->level, layer, (uint32_t)g->x0, (uint32_t)g->y0, slice, (uint32_t)g->wb,
|
||||
(uint32_t)g->hb, t->mem, mem + (size_t)z * g->img, g->row, !write))
|
||||
return 0;
|
||||
}
|
||||
free(lin);
|
||||
return ok;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int read_aspect(const Tex *e, VkImageAspectFlags *a) {
|
||||
|
||||
@@ -6,7 +6,7 @@ The map is the lld one from the link (build/<version>/totk.map); its addresses a
|
||||
runtime image base, so ASLR does not matter. Symbols in the map are labels without sizes: a Rip belongs to the nearest
|
||||
symbol at or below it.
|
||||
|
||||
A profile taken with TOTK_PROFILE_RENDER=1 also has call chains: the report then adds the inclusive time per
|
||||
A profile taken with TOTK_PROFILE_RENDER=1 or TOTK_PROFILE_CHAINS=1 also has call chains: the report then adds the inclusive time per
|
||||
function (a function counted once per chain), and for each module outside the exe the exe functions that call into it
|
||||
and the longest common chains down to it.
|
||||
"""
|
||||
@@ -56,7 +56,7 @@ def load_profile(path):
|
||||
def report_chains(prof, name_of, in_exe, top):
|
||||
stacks = prof['stacks']
|
||||
total = sum(n for n, _ in stacks) or 1
|
||||
print(f'\ncall chains: {total} samples in {len(stacks)} chains (render thread)')
|
||||
print(f'\ncall chains: {total} samples in {len(stacks)} chains (render thread, or every thread with TOTK_PROFILE_CHAINS)')
|
||||
incl = collections.Counter()
|
||||
for n, chain in stacks:
|
||||
for f in set(name_of(r) for r in chain):
|
||||
|
||||
Reference in new issue
Block a user