mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-21 21:05:56 +00:00
Decode ASTC a block per lane group through shared memory, in scratch chunks of at most 32 MiB of texels, and time the dispatches with TOTK_ASTC_TIME
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9a859dfb2c
commit
291267e65d
7 files changed
+2105
-1675
No files matched your search
+1705
-1550
File diff suppressed because it is too large.
Load diff
+16
-6
@@ -194,7 +194,8 @@ static int test_case(VkCtx *c, uint32_t bw, uint32_t bh, int srgb) {
|
||||
return bad;
|
||||
}
|
||||
|
||||
// One 2048 x 2048 texture of valid blocks: CPU decode time against the GPU batch's wall time.
|
||||
// One 2048 x 2048 texture of valid blocks: the CPU worker-pool decode against the GPU time of the dispatches alone
|
||||
// (vk_astc.c timestamps, TOTK_ASTC_TIME) and the wall time of the upload batch.
|
||||
static void timing(VkCtx *c, uint32_t bw, uint32_t bh) {
|
||||
uint32_t w = 2048, h = 2048;
|
||||
size_t n = (size_t)((w + bw - 1) / bw) * ((h + bh - 1) / bh);
|
||||
@@ -206,11 +207,18 @@ static void timing(VkCtx *c, uint32_t bw, uint32_t bh) {
|
||||
for (size_t k = 4096; k < n; k++) memcpy(blk + 16 * k, blk + 16 * (k % 4096), 16);
|
||||
double a = now_ms();
|
||||
astc_decode_ldr_mt(blk, w, h, bw, bh, false, out);
|
||||
double cpu = now_ms() - a, gpu = 0, gpu2 = 0;
|
||||
gpu_decode(c, blk, n, 1, w, h, 1, 1, bw, bh, 0, NULL, NULL, &gpu); // first run includes the table upload
|
||||
gpu_decode(c, blk, n, 1, w, h, 1, 1, bw, bh, 0, NULL, NULL, &gpu2);
|
||||
printf("probe-astc: 2048x2048 %ux%u: CPU (worker pool) %.1f ms, GPU batch %.1f ms (again %.1f ms; includes the "
|
||||
"staging copy and two readbacks of 16 MiB)\n", bw, bh, cpu, gpu, gpu2);
|
||||
double cpu = now_ms() - a, wall = 0;
|
||||
vk_astc_time_enable(1);
|
||||
uint64_t t0, c0, t1, c1;
|
||||
double u0, u1;
|
||||
vk_astc_time_get(bw, bh, &t0, &c0, &u0);
|
||||
for (int i = 0; i < 4; i++) gpu_decode(c, blk, n, 1, w, h, 1, 1, bw, bh, 0, NULL, NULL, i ? &wall : NULL);
|
||||
vk_astc_time_get(bw, bh, &t1, &c1, &u1);
|
||||
vk_astc_time_enable(0);
|
||||
double mtex = (double)(t1 - t0) / 1e6;
|
||||
printf("probe-astc: 2048x2048 %ux%u: CPU (worker pool) %.1f ms; GPU dispatches %.0f us per M texel (%llu decodes "
|
||||
"timed, %.2f M texels), batch wall %.1f ms\n", bw, bh, cpu, mtex > 0 ? (u1 - u0) / mtex : 0.0,
|
||||
(unsigned long long)(c1 - c0), mtex, wall);
|
||||
free(blk), free(out);
|
||||
}
|
||||
|
||||
@@ -230,7 +238,9 @@ int probe_astc(void) {
|
||||
if (!g_bucket[b]) { printf("probe-astc: FAIL no valid %s block was generated\n", bucket_name[b]); bad = 1; }
|
||||
if (!bad) {
|
||||
timing(c, 4, 4);
|
||||
timing(c, 6, 6);
|
||||
timing(c, 8, 8);
|
||||
timing(c, 12, 12);
|
||||
}
|
||||
vk_mem_shutdown();
|
||||
vk_shutdown();
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ static int n_entries;
|
||||
// Every name the runtime reads (and the patch sets in generated/), without the prefix. A file key outside this list is
|
||||
// logged as unknown. A new variable goes here too, or its ini key logs a harmless "unknown key" line.
|
||||
static const char *const known[] = {
|
||||
"APP_POOL", "ASSUME_FOCUS", "ASTC", "AUDIO", "AUDIO_OFF", "AUDIO_PREFILL_MS", "BACKGROUND_WINDOW", "BIND_A", "BIND_B", "BIND_DOWN", "BIND_L", "BIND_LCLICK", "BIND_LEFT",
|
||||
"APP_POOL", "ASSUME_FOCUS", "ASTC", "ASTC_TIME", "AUDIO", "AUDIO_OFF", "AUDIO_PREFILL_MS", "BACKGROUND_WINDOW", "BIND_A", "BIND_B", "BIND_DOWN", "BIND_L", "BIND_LCLICK", "BIND_LEFT",
|
||||
"BIND_MINUS", "BIND_PLUS", "BIND_R", "BIND_RCLICK", "BIND_RIGHT", "BIND_STATS", "BIND_UP", "BIND_X", "BIND_Y", "BIND_ZL",
|
||||
"BIND_ZR",
|
||||
"CLOTH_REALTIME", "DUMP", "DUMP_BUF", "DUMP_DIR", "DUMP_LOG", "EXEFS", "FEEDBACK", "FIX_C0", "FIX_ZERO", "FLIGHT",
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
// texel = (e0 * (64 - w) + e1 * w + 32) >> 6, top 8 bits. Error blocks are magenta; HDR endpoint modes give magenta
|
||||
// endpoints for their partition.
|
||||
//
|
||||
// Every invocation decodes the block header of its texel's block again and reads only the integer-sequence values it
|
||||
// needs (four weights per plane, the endpoints of its partition), so there is no shared memory and no barrier.
|
||||
// A workgroup of 64 lanes takes up to four blocks of one block row (main below): every lane decodes its block's header,
|
||||
// the block's lanes share the integer-sequence decode of its weights and colour values through shared memory, and
|
||||
// each lane then interpolates its own texels.
|
||||
// Compiled to runtime/astc_decode_spv.h by tools/build_shaders.py; vk_astc.c records the dispatch.
|
||||
#version 450
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
||||
layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
|
||||
|
||||
layout(std430, set = 0, binding = 0) readonly buffer Blocks { uvec4 blk[]; };
|
||||
layout(std430, set = 0, binding = 1) writeonly buffer Texels { uint px[]; };
|
||||
@@ -232,14 +233,26 @@ bool unpack_endpoints(int cem, int v[8], out ivec4 e0, out ivec4 e1) {
|
||||
|
||||
const uint MAGENTA = 0xFFFF00FFu;
|
||||
|
||||
uint decode_texel(uvec4 b, int bw, int bh, int x, int y, bool srgb) {
|
||||
// What every texel of a block needs from its header (tex_astc.c astc_decode_block up to the weight infill).
|
||||
struct Hdr {
|
||||
uint konst; // the colour of a void-extent or error block
|
||||
bool solid; // konst is the whole block
|
||||
int wx, wy, dual, quant, wtotal, pcount, cem0, cem1, cem2, cem3, n0, n1, n2, ccount, cq, ccs;
|
||||
};
|
||||
|
||||
Hdr header(uvec4 b, int bw, int bh) {
|
||||
Hdr H;
|
||||
H.solid = true; H.konst = MAGENTA;
|
||||
H.wx = 0; H.wy = 0; H.dual = 0; H.quant = 0; H.wtotal = 0; H.pcount = 1;
|
||||
H.cem0 = 0; H.cem1 = 0; H.cem2 = 0; H.cem3 = 0; H.n0 = 0; H.n1 = 0; H.n2 = 0; H.ccount = 0; H.cq = 20; H.ccs = -1;
|
||||
uint mode = b.x & 0x7FFu;
|
||||
if ((mode & 0x1FFu) == 0x1FCu) { // void extent
|
||||
if ((mode & 0x200u) != 0u || ((b.x >> 10) & 3u) != 3u) return MAGENTA;
|
||||
if ((mode & 0x200u) != 0u || ((b.x >> 10) & 3u) != 3u) return H;
|
||||
uint s0 = rbits(b, 12, 13), s1 = rbits(b, 25, 13), t0 = rbits(b, 38, 13), t1 = rbits(b, 51, 13);
|
||||
bool all_ones = s0 == 0x1FFFu && s1 == 0x1FFFu && t0 == 0x1FFFu && t1 == 0x1FFFu;
|
||||
if ((s0 >= s1 || t0 >= t1) && !all_ones) return MAGENTA;
|
||||
return (b.z >> 8 & 0xFFu) | (b.z >> 24) << 8 | (b.w >> 8 & 0xFFu) << 16 | (b.w >> 24) << 24;
|
||||
if ((s0 >= s1 || t0 >= t1) && !all_ones) return H;
|
||||
H.konst = (b.z >> 8 & 0xFFu) | (b.z >> 24) << 8 | (b.w >> 8 & 0xFFu) << 16 | (b.w >> 24) << 24;
|
||||
return H;
|
||||
}
|
||||
|
||||
// block mode (tex_astc.c block_mode_2d)
|
||||
@@ -260,7 +273,7 @@ uint decode_texel(uvec4 b, int bw, int bh, int x, int y, bool srgb) {
|
||||
}
|
||||
} else {
|
||||
r |= ((m >> 2) & 3u) << 1;
|
||||
if (((m >> 2) & 3u) == 0u) return MAGENTA;
|
||||
if (((m >> 2) & 3u) == 0u) return H;
|
||||
uint bb = (m >> 9) & 3u;
|
||||
uint sel = (m >> 7) & 3u;
|
||||
if (sel == 0u) { wx = 12; wy = int(a) + 2; }
|
||||
@@ -269,16 +282,16 @@ uint decode_texel(uvec4 b, int bw, int bh, int x, int y, bool srgb) {
|
||||
else {
|
||||
if (a == 0u) { wx = 6; wy = 10; }
|
||||
else if (a == 1u) { wx = 10; wy = 6; }
|
||||
else return MAGENTA;
|
||||
else return H;
|
||||
}
|
||||
}
|
||||
int dual = int(d);
|
||||
int wcount = wx * wy;
|
||||
int wtotal = (wx * wy) << dual;
|
||||
int quant = int(r) - 2 + 6 * int(h);
|
||||
int wbits = ise_bitcount(wcount << dual, quant);
|
||||
if ((wcount << dual) > 64 || wbits < 24 || wbits > 96 || wx > bw || wy > bh) return MAGENTA;
|
||||
int wbits = ise_bitcount(wtotal, quant);
|
||||
if (wtotal > 64 || wbits < 24 || wbits > 96 || wx > bw || wy > bh) return H;
|
||||
int pcount = int((b.x >> 11) & 3u) + 1;
|
||||
if (dual != 0 && pcount == 4) return MAGENTA;
|
||||
if (dual != 0 && pcount == 4) return H;
|
||||
|
||||
// colour endpoint modes
|
||||
int cem0, cem1 = 0, cem2 = 0, cem3 = 0;
|
||||
@@ -296,84 +309,121 @@ uint decode_texel(uvec4 b, int bw, int bh, int x, int y, bool srgb) {
|
||||
high = 0;
|
||||
} else {
|
||||
base--;
|
||||
uint c0 = (((enc >> 2) & 1u) + base) << 2 | ((enc >> uint(2 + pcount)) & 3u);
|
||||
uint c1 = (((enc >> 3) & 1u) + base) << 2 | ((enc >> uint(4 + pcount)) & 3u);
|
||||
uint c2 = (((enc >> 4) & 1u) + base) << 2 | ((enc >> uint(6 + pcount)) & 3u);
|
||||
uint c3 = (((enc >> 5) & 1u) + base) << 2 | ((enc >> uint(8 + pcount)) & 3u);
|
||||
cem0 = int(c0); cem1 = int(c1); cem2 = int(c2); cem3 = int(c3);
|
||||
cem0 = int((((enc >> 2) & 1u) + base) << 2 | ((enc >> uint(2 + pcount)) & 3u));
|
||||
cem1 = int((((enc >> 3) & 1u) + base) << 2 | ((enc >> uint(4 + pcount)) & 3u));
|
||||
cem2 = int((((enc >> 4) & 1u) + base) << 2 | ((enc >> uint(6 + pcount)) & 3u));
|
||||
cem3 = int((((enc >> 5) & 1u) + base) << 2 | ((enc >> uint(8 + pcount)) & 3u));
|
||||
}
|
||||
}
|
||||
int n0 = ((cem0 >> 2) + 1) * 2, n1 = pcount > 1 ? ((cem1 >> 2) + 1) * 2 : 0;
|
||||
int n2 = pcount > 2 ? ((cem2 >> 2) + 1) * 2 : 0, n3 = pcount > 3 ? ((cem3 >> 2) + 1) * 2 : 0;
|
||||
int ccount = n0 + n1 + n2 + n3;
|
||||
if (ccount > 18) return MAGENTA;
|
||||
if (ccount > 18) return H;
|
||||
int cbits = max((pcount == 1 ? 111 : 99) - wbits - high - (dual != 0 ? 2 : 0), 0);
|
||||
int cq = -1;
|
||||
for (int q = 20; q >= 0; q--) {
|
||||
if (ise_bitcount(ccount, q) <= cbits) { cq = q; break; }
|
||||
}
|
||||
if (cq < 4) return MAGENTA; // QUANT_6
|
||||
if (cq < 4) return H; // QUANT_6
|
||||
|
||||
// this texel's partition and its endpoints
|
||||
int texels = bw * bh;
|
||||
bool small = texels < 32;
|
||||
int p = pcount > 1 ? part_of(int((b.x >> 13) & 0x3FFu), pcount, small ? x << 1 : x, small ? y << 1 : y) : 0;
|
||||
int cem = p == 0 ? cem0 : p == 1 ? cem1 : p == 2 ? cem2 : cem3;
|
||||
int k = p == 0 ? 0 : p == 1 ? n0 : p == 2 ? n0 + n1 : n0 + n1 + n2;
|
||||
int n = ((cem >> 2) + 1) * 2;
|
||||
int cstart = pcount == 1 ? 17 : 29;
|
||||
uint crow = cq == 20 ? 0u : tab[12 + cq - 4];
|
||||
int v[8];
|
||||
for (int j = 0; j < 8; j++) {
|
||||
v[j] = 0;
|
||||
if (j < n) {
|
||||
uint raw = ise_at(b, cstart, ccount, cq, k + j);
|
||||
v[j] = cq == 20 ? int(raw) : int(tab_byte(crow + raw));
|
||||
}
|
||||
}
|
||||
ivec4 e0, e1;
|
||||
if (!unpack_endpoints(cem, v, e0, e1)) { e0 = ivec4(0xFF, 0, 0xFF, 0xFF); e1 = e0; }
|
||||
if (srgb) { e0 = e0 << 8 | 0x80; e1 = e1 << 8 | 0x80; }
|
||||
else { e0 *= 257; e1 *= 257; }
|
||||
|
||||
// weights: bilinear infill from the grid, read backwards from the top of the block
|
||||
uvec4 rev = uvec4(bitfieldReverse(b.w), bitfieldReverse(b.z), bitfieldReverse(b.y), bitfieldReverse(b.x));
|
||||
int vx = int((uint((1024 + bw / 2) / (bw - 1)) * uint(x) * uint(wx - 1) + 32u) >> 6);
|
||||
int vy = int((uint((1024 + bh / 2) / (bh - 1)) * uint(y) * uint(wy - 1) + 32u) >> 6);
|
||||
int fs = vx & 0xF, ft = vy & 0xF;
|
||||
int i0 = (vy >> 4) * wx + (vx >> 4);
|
||||
int w11 = (fs * ft + 8) >> 4, w10 = fs - w11, w01 = ft - w11, w00 = 16 - fs - ft + w11;
|
||||
uint wrow = tab[quant];
|
||||
int wtotal = wcount << dual;
|
||||
int w[2];
|
||||
for (int pl = 0; pl < 2; pl++) {
|
||||
w[pl] = 0;
|
||||
if (pl > dual) continue;
|
||||
int acc = 0;
|
||||
for (int c = 0; c < 4; c++) {
|
||||
int idx = i0 + (c == 0 ? 0 : c == 1 ? 1 : c == 2 ? wx : wx + 1);
|
||||
int f = c == 0 ? w00 : c == 1 ? w10 : c == 2 ? w01 : w11;
|
||||
if (f == 0 || idx >= wcount) continue;
|
||||
uint raw = ise_at(rev, 0, wtotal, quant, dual != 0 ? 2 * idx + pl : idx);
|
||||
acc += int(tab_byte(wrow + raw)) * f;
|
||||
}
|
||||
w[pl] = (acc + 8) >> 4;
|
||||
}
|
||||
int ccs = dual != 0 ? int(rbits(b, below - 2, 2)) : -1;
|
||||
|
||||
uint o = 0u;
|
||||
for (int c = 0; c < 4; c++) {
|
||||
int wc = c == ccs ? w[1] : w[0];
|
||||
o |= uint((e0[c] * (64 - wc) + e1[c] * wc + 32) >> 14) << uint(8 * c);
|
||||
}
|
||||
return o;
|
||||
H.solid = false;
|
||||
H.wx = wx; H.wy = wy; H.dual = dual; H.quant = quant; H.wtotal = wtotal; H.pcount = pcount;
|
||||
H.cem0 = cem0; H.cem1 = cem1; H.cem2 = cem2; H.cem3 = cem3; H.n0 = n0; H.n1 = n1; H.n2 = n2;
|
||||
H.ccount = ccount; H.cq = cq;
|
||||
H.ccs = dual != 0 ? int(rbits(b, below - 2, 2)) : -1;
|
||||
return H;
|
||||
}
|
||||
|
||||
// A workgroup decodes BPW blocks of one block row when a block has 64 texels or fewer (64 / texels of them), else one
|
||||
// block: S lanes per block (its texels, at most 64). The lanes of a block decode its weights and colour values into
|
||||
// shared memory, the first pcount lanes then unpack the endpoints, and each lane writes its texels.
|
||||
const int MAXB = 4; // 4x4: 4 blocks of 16 lanes
|
||||
shared uint s_w[MAXB][64]; // unquantized weights 0..64 (dual plane: interleaved as in the bit stream)
|
||||
shared int s_cv[MAXB][18]; // unquantized colour values
|
||||
shared uvec2 s_e0[MAXB][4], s_e1[MAXB][4]; // 16-bit endpoints, two channels per uint
|
||||
|
||||
uvec2 pack16(ivec4 e) { return uvec2(uint(e.x) | uint(e.y) << 16, uint(e.z) | uint(e.w) << 16); }
|
||||
int ch16(uvec2 p, int c) { return int(((c < 2 ? p.x : p.y) >> (16 * (c & 1))) & 0xFFFFu); }
|
||||
|
||||
void main() {
|
||||
uvec3 g = gl_GlobalInvocationID;
|
||||
if (g.x >= pc.width || g.y >= pc.height) return;
|
||||
uint bxi = g.x / pc.bw, byi = g.y / pc.bh;
|
||||
uvec4 b = blk[pc.in_base + g.z * pc.bslice + byi * pc.bx + bxi];
|
||||
uint t = decode_texel(b, int(pc.bw), int(pc.bh), int(g.x - bxi * pc.bw), int(g.y - byi * pc.bh), pc.srgb != 0u);
|
||||
px[pc.out_base + (g.z * pc.height + g.y) * pc.width + g.x] = t;
|
||||
int bw = int(pc.bw), bh = int(pc.bh), G = bw * bh;
|
||||
int bpw = G <= 64 ? 64 / G : 1, S = G <= 64 ? G : 64;
|
||||
int l = int(gl_LocalInvocationID.x), lb = l / S, lane = l - lb * S;
|
||||
bool live = lb < bpw;
|
||||
int bxi = int(gl_WorkGroupID.x) * bpw + lb, byi = int(gl_WorkGroupID.y);
|
||||
live = live && bxi < int(pc.bx);
|
||||
lb = min(lb, MAXB - 1);
|
||||
uvec4 b = live ? blk[pc.in_base + gl_WorkGroupID.z * pc.bslice + uint(byi) * pc.bx + uint(bxi)] : uvec4(0u);
|
||||
Hdr H = header(b, bw, bh);
|
||||
bool work = live && !H.solid;
|
||||
|
||||
if (work) {
|
||||
uvec4 rev = uvec4(bitfieldReverse(b.w), bitfieldReverse(b.z), bitfieldReverse(b.y), bitfieldReverse(b.x));
|
||||
uint wrow = tab[H.quant];
|
||||
for (int j = lane; j < H.wtotal; j += S) s_w[lb][j] = tab_byte(wrow + ise_at(rev, 0, H.wtotal, H.quant, j));
|
||||
uint crow = H.cq == 20 ? 0u : tab[12 + H.cq - 4];
|
||||
int cstart = H.pcount == 1 ? 17 : 29;
|
||||
for (int j = lane; j < H.ccount; j += S) {
|
||||
uint raw = ise_at(b, cstart, H.ccount, H.cq, j);
|
||||
s_cv[lb][j] = H.cq == 20 ? int(raw) : int(tab_byte(crow + raw));
|
||||
}
|
||||
}
|
||||
barrier();
|
||||
if (work && lane < H.pcount) {
|
||||
int p = lane;
|
||||
int cem = p == 0 ? H.cem0 : p == 1 ? H.cem1 : p == 2 ? H.cem2 : H.cem3;
|
||||
int k = p == 0 ? 0 : p == 1 ? H.n0 : p == 2 ? H.n0 + H.n1 : H.n0 + H.n1 + H.n2;
|
||||
int n = ((cem >> 2) + 1) * 2;
|
||||
int v[8];
|
||||
for (int j = 0; j < 8; j++) {
|
||||
v[j] = 0;
|
||||
if (j < n) v[j] = s_cv[lb][k + j];
|
||||
}
|
||||
ivec4 e0, e1;
|
||||
if (!unpack_endpoints(cem, v, e0, e1)) { e0 = ivec4(0xFF, 0, 0xFF, 0xFF); e1 = e0; }
|
||||
if (pc.srgb != 0u) { e0 = e0 << 8 | 0x80; e1 = e1 << 8 | 0x80; }
|
||||
else { e0 *= 257; e1 *= 257; }
|
||||
s_e0[lb][p] = pack16(e0);
|
||||
s_e1[lb][p] = pack16(e1);
|
||||
}
|
||||
barrier();
|
||||
if (!live) return;
|
||||
|
||||
bool small = G < 32;
|
||||
int seed = int((b.x >> 13) & 0x3FFu);
|
||||
int sx = int((1024 + bw / 2) / (bw - 1)), sy = int((1024 + bh / 2) / (bh - 1));
|
||||
for (int t = lane; t < G; t += S) {
|
||||
int x = t % bw, y = t / bw;
|
||||
uint gx = uint(bxi * bw + x), gy = uint(byi * bh + y);
|
||||
if (gx >= pc.width || gy >= pc.height) continue;
|
||||
uint o = H.konst;
|
||||
if (!H.solid) {
|
||||
int p = H.pcount > 1 ? part_of(seed, H.pcount, small ? x << 1 : x, small ? y << 1 : y) : 0;
|
||||
int vx = (sx * x * (H.wx - 1) + 32) >> 6, vy = (sy * y * (H.wy - 1) + 32) >> 6;
|
||||
int fs = vx & 0xF, ft = vy & 0xF;
|
||||
int i0 = (vy >> 4) * H.wx + (vx >> 4);
|
||||
int w11 = (fs * ft + 8) >> 4, w10 = fs - w11, w01 = ft - w11, w00 = 16 - fs - ft + w11;
|
||||
int wcount = H.wx * H.wy;
|
||||
int w[2];
|
||||
for (int pl = 0; pl < 2; pl++) {
|
||||
w[pl] = 0;
|
||||
if (pl > H.dual) continue;
|
||||
int acc = 0;
|
||||
for (int c = 0; c < 4; c++) {
|
||||
int idx = i0 + (c == 0 ? 0 : c == 1 ? 1 : c == 2 ? H.wx : H.wx + 1);
|
||||
int f = c == 0 ? w00 : c == 1 ? w10 : c == 2 ? w01 : w11;
|
||||
if (f == 0 || idx >= wcount) continue;
|
||||
acc += int(s_w[lb][H.dual != 0 ? 2 * idx + pl : idx]) * f;
|
||||
}
|
||||
w[pl] = (acc + 8) >> 4;
|
||||
}
|
||||
uvec2 q0 = s_e0[lb][p], q1 = s_e1[lb][p];
|
||||
o = 0u;
|
||||
for (int c = 0; c < 4; c++) {
|
||||
int wc = c == H.ccs ? w[1] : w[0];
|
||||
o |= uint((ch16(q0, c) * (64 - wc) + ch16(q1, c) * wc + 32) >> 14) << uint(8 * c);
|
||||
}
|
||||
}
|
||||
px[pc.out_base + (gl_WorkGroupID.z * pc.height + gy) * pc.width + gx] = o;
|
||||
}
|
||||
}
|
||||
@@ -212,6 +212,10 @@ typedef struct { VkDeviceSize src; uint32_t w, h, slices, level, layer; VkOffset
|
||||
int vk_astc_record(VkCommandBuffer cb, VkBuffer src, VkDeviceSize src_size, const VkAstcRegion *rg, int n, uint32_t bw,
|
||||
uint32_t bh, int srgb, VkImage img, VkImageAspectFlags aspect, VkBuffer readback);
|
||||
void vk_astc_stats(uint64_t *dispatches, uint64_t *texels); // since start
|
||||
// TOTK_ASTC_TIME=1: GPU timestamps around each vk_astc_record's dispatches (logged per footprint and the largest one)
|
||||
void vk_astc_time_enable(int on);
|
||||
int vk_astc_time_get(uint32_t bw, uint32_t bh, uint64_t *texels, uint64_t *calls, double *us); // totals so far
|
||||
void vk_astc_time_summary(void); // logs the totals
|
||||
void vk_astc_release(void); // vk_device.c, before the device goes: frees the decoder's objects
|
||||
void vk_mem_note_submit(uint64_t timeline_value); // T6: after each submit that signals ctx->timeline with this value
|
||||
void vk_mem_collect(void); // frees what has completed
|
||||
|
||||
+249
-38
@@ -6,9 +6,10 @@
|
||||
// device cannot. cpu: astc_decode_ldr_mt on the uploading thread, as before. check: gpu, and every upload is also
|
||||
// decoded on the CPU and compared (waits for the GPU; for testing only).
|
||||
//
|
||||
// The decode is recorded into the upload batch (vk_memory.c): the raw blocks go from staging to a device-local scratch
|
||||
// buffer, the dispatch writes RGBA8 texels behind them, and a buffer-to-image copy puts them into the image. The
|
||||
// scratch buffer is freed once the batch completes (vk_defer_buffer).
|
||||
// The decode is recorded into the upload batch (vk_memory.c) in chunks of at most 32 MiB of texels: a chunk's raw
|
||||
// blocks go from staging to a device-local scratch buffer, its dispatches write RGBA8 texels behind them, and a
|
||||
// buffer-to-image copy puts them into the image; the next chunk reuses the scratch after a barrier. The scratch
|
||||
// buffer is freed once the batch completes (vk_defer_buffer).
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -105,6 +106,137 @@ static struct {
|
||||
} G = {.mode = -1};
|
||||
static uint64_t n_dispatch, n_texels;
|
||||
|
||||
// TOTK_ASTC_TIME=1 (or vk_astc_time_enable): timestamps around the dispatches of each scratch chunk (the decode
|
||||
// alone) and around a whole vk_astc_record call (one texture upload or WriteTexels: copies and barriers included),
|
||||
// read back by later calls. Per footprint: texels and dispatch time; a new largest call is logged with both times.
|
||||
// Needs hostQueryReset (a slot is reset on the host after its read).
|
||||
#define TQ 256
|
||||
static SRWLOCK t_lock = SRWLOCK_INIT;
|
||||
static int t_on = -1; // -1: knob not read yet
|
||||
static VkQueryPool t_pool;
|
||||
static VkDevice t_dev;
|
||||
static double t_ns_per_tick;
|
||||
static uint64_t t_mask;
|
||||
static struct { uint64_t texels; uint32_t id; uint8_t fp, busy, whole; } t_slot[TQ]; // whole: the call, else a chunk
|
||||
static int t_next;
|
||||
static struct { uint64_t texels, chunks; double us; } t_fp[13 * 13]; // [bw * 13 + bh]: dispatch time of the chunks
|
||||
#define TA 64 // calls in flight, by id % TA
|
||||
typedef struct { uint32_t id, w, h, regions, chunks, done; int complete; uint64_t texels; double us, total; uint8_t fp; } TCall;
|
||||
static TCall t_call[TA];
|
||||
static uint32_t t_id;
|
||||
static uint64_t t_max_texels;
|
||||
static double t_max_us, t_max_total;
|
||||
static uint8_t t_max_fp;
|
||||
|
||||
static void time_init(VkCtx *c) { // t_lock held
|
||||
if (t_on < 0) {
|
||||
const char *e = cfg_get("TOTK_ASTC_TIME");
|
||||
t_on = e && *e && *e != '0';
|
||||
}
|
||||
if (t_on <= 0 || (t_pool && t_dev == c->device)) return;
|
||||
t_pool = VK_NULL_HANDLE;
|
||||
memset(t_slot, 0, sizeof t_slot);
|
||||
VkPhysicalDeviceVulkan12Features f12 = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES};
|
||||
VkPhysicalDeviceFeatures2 f2 = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, .pNext = &f12};
|
||||
vkGetPhysicalDeviceFeatures2(c->phys, &f2);
|
||||
uint32_t nq = 0;
|
||||
vkGetPhysicalDeviceQueueFamilyProperties(c->phys, &nq, NULL);
|
||||
VkQueueFamilyProperties *qp = calloc(nq ? nq : 1, sizeof *qp);
|
||||
vkGetPhysicalDeviceQueueFamilyProperties(c->phys, &nq, qp);
|
||||
uint32_t bits = c->gfx_family < nq ? qp[c->gfx_family].timestampValidBits : 0;
|
||||
free(qp);
|
||||
VkQueryPoolCreateInfo qi = {.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO, .queryType = VK_QUERY_TYPE_TIMESTAMP,
|
||||
.queryCount = 2 * TQ};
|
||||
if (!f12.hostQueryReset || !bits || vkCreateQueryPool(c->device, &qi, NULL, &t_pool) != VK_SUCCESS) {
|
||||
rt_log("vk: TOTK_ASTC_TIME: no hostQueryReset or no timestamps on the queue; ASTC decodes not timed");
|
||||
t_pool = VK_NULL_HANDLE;
|
||||
t_on = 0;
|
||||
return;
|
||||
}
|
||||
vkResetQueryPool(c->device, t_pool, 0, 2 * TQ);
|
||||
t_dev = c->device;
|
||||
t_ns_per_tick = c->props.limits.timestampPeriod;
|
||||
t_mask = bits >= 64 ? ~0ull : (1ull << bits) - 1;
|
||||
}
|
||||
|
||||
// Takes in the slots whose timestamps are available; t_lock held.
|
||||
static void time_poll_locked(VkCtx *c) {
|
||||
if (!t_pool || t_dev != c->device) return;
|
||||
for (int i = 0; i < TQ; i++) {
|
||||
if (!t_slot[i].busy) continue;
|
||||
uint64_t r[4];
|
||||
if (vkGetQueryPoolResults(c->device, t_pool, 2 * (uint32_t)i, 2, sizeof r, r, 16,
|
||||
VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT) != VK_SUCCESS ||
|
||||
!r[1] || !r[3])
|
||||
continue;
|
||||
double us = (double)((r[2] - r[0]) & t_mask) * t_ns_per_tick / 1e3;
|
||||
int fp = t_slot[i].fp;
|
||||
if (!t_slot[i].whole) t_fp[fp].texels += t_slot[i].texels, t_fp[fp].chunks++, t_fp[fp].us += us;
|
||||
TCall *k = &t_call[t_slot[i].id % TA];
|
||||
if (k->id == t_slot[i].id) {
|
||||
if (t_slot[i].whole) k->total = us;
|
||||
else k->us += us, k->texels += t_slot[i].texels;
|
||||
if (++k->done == k->chunks + 1 && k->complete && k->texels > t_max_texels) {
|
||||
t_max_texels = k->texels, t_max_us = k->us, t_max_total = k->total, t_max_fp = k->fp;
|
||||
rt_log("vk: ASTC time: largest decode so far %.2f M texels (%dx%d; %u regions, the first %ux%u; %u scratch "
|
||||
"chunks): dispatches %.0f us of GPU time (%.0f us per M texel), %.0f us with the copies",
|
||||
(double)k->texels / 1e6, k->fp / 13, k->fp % 13, k->regions, k->w, k->h, k->chunks, k->us,
|
||||
k->us * 1e6 / (double)k->texels, k->total);
|
||||
}
|
||||
}
|
||||
t_slot[i].busy = 0;
|
||||
vkResetQueryPool(c->device, t_pool, 2 * (uint32_t)i, 2);
|
||||
}
|
||||
}
|
||||
|
||||
// A free slot for a call's id (t_lock held); -1 when the ring is full.
|
||||
static int time_slot(uint32_t id, uint8_t fp, uint64_t texels, int whole) {
|
||||
for (int i = 0; i < TQ; i++, t_next = (t_next + 1) % TQ)
|
||||
if (!t_slot[t_next].busy) {
|
||||
int k = t_next;
|
||||
t_slot[k].busy = 1, t_slot[k].id = id, t_slot[k].fp = fp, t_slot[k].texels = texels;
|
||||
t_slot[k].whole = (uint8_t)whole;
|
||||
t_next = (k + 1) % TQ;
|
||||
return k;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void vk_astc_time_enable(int on) {
|
||||
AcquireSRWLockExclusive(&t_lock);
|
||||
t_on = on;
|
||||
ReleaseSRWLockExclusive(&t_lock);
|
||||
}
|
||||
|
||||
int vk_astc_time_get(uint32_t bw, uint32_t bh, uint64_t *texels, uint64_t *calls, double *us) {
|
||||
VkCtx *c = vk_ctx();
|
||||
if (!c || bw > 12 || bh > 12) return 0;
|
||||
AcquireSRWLockExclusive(&t_lock);
|
||||
time_poll_locked(c);
|
||||
int fp = (int)(bw * 13 + bh);
|
||||
*texels = t_fp[fp].texels, *calls = t_fp[fp].chunks, *us = t_fp[fp].us;
|
||||
ReleaseSRWLockExclusive(&t_lock);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void vk_astc_time_summary(void) {
|
||||
VkCtx *c = vk_ctx();
|
||||
if (!c) return;
|
||||
AcquireSRWLockExclusive(&t_lock);
|
||||
if (t_on > 0) {
|
||||
time_poll_locked(c);
|
||||
for (int fp = 0; fp < 13 * 13; fp++)
|
||||
if (t_fp[fp].chunks)
|
||||
rt_log("vk: ASTC time: %dx%d: %llu dispatch batches, %.2f M texels, %.0f us GPU (%.0f us per M texel)",
|
||||
fp / 13, fp % 13, (unsigned long long)t_fp[fp].chunks, (double)t_fp[fp].texels / 1e6, t_fp[fp].us,
|
||||
t_fp[fp].us * 1e6 / (double)t_fp[fp].texels);
|
||||
if (t_max_texels)
|
||||
rt_log("vk: ASTC time: largest decode %.2f M texels (%dx%d): dispatches %.0f us GPU, %.0f us with the copies",
|
||||
(double)t_max_texels / 1e6, t_max_fp / 13, t_max_fp % 13, t_max_us, t_max_total);
|
||||
}
|
||||
ReleaseSRWLockExclusive(&t_lock);
|
||||
}
|
||||
|
||||
static void fill_tables(uint8_t *p) {
|
||||
uint32_t off[28];
|
||||
for (int i = 0; i < 12; i++) off[i] = TAB_WUNQ + wunq_off[i];
|
||||
@@ -228,20 +360,38 @@ static void mem_barrier(VkCommandBuffer cb, VkPipelineStageFlags2 src, VkAccessF
|
||||
vkCmdPipelineBarrier2(cb, &di);
|
||||
}
|
||||
|
||||
// Scratch per vk_astc_record: texels of at most this many bytes at a time (or one region, when larger), so a large
|
||||
// texture array (169 M texels, 677 MB as RGBA8, on monsters2) does not need its whole RGBA8 copy as scratch.
|
||||
#define CHUNK_OUT (32ull << 20)
|
||||
|
||||
static VkDeviceSize region_out(const VkAstcRegion *r) { return (VkDeviceSize)r->w * r->h * r->slices * 4; }
|
||||
static VkDeviceSize region_in(const VkAstcRegion *r, uint32_t bw, uint32_t bh) {
|
||||
return (VkDeviceSize)((r->w + bw - 1) / bw) * ((r->h + bh - 1) / bh) * r->slices * 16;
|
||||
}
|
||||
|
||||
int vk_astc_record(VkCommandBuffer cb, VkBuffer src, VkDeviceSize src_size, const VkAstcRegion *rg, int n, uint32_t bw,
|
||||
uint32_t bh, int srgb, VkImage img, VkImageAspectFlags aspect, VkBuffer readback) {
|
||||
static volatile long n_fail;
|
||||
(void)src_size;
|
||||
VkCtx *c = vk_ctx();
|
||||
if (!c || !vk_astc_gpu() || bw < 4 || bh < 4 || bw > 12 || bh > 12) return 0;
|
||||
AcquireSRWLockShared(&g_lock);
|
||||
VkPipeline pipe = G.dev == c->device ? G.pipe : VK_NULL_HANDLE;
|
||||
ReleaseSRWLockShared(&g_lock);
|
||||
if (!pipe) return 0;
|
||||
// scratch: the blocks (a copy of src), then the texels of every region
|
||||
VkDeviceSize in_size = (src_size + 15) & ~15ull, out_size = 0;
|
||||
for (int i = 0; i < n; i++) out_size += (VkDeviceSize)rg[i].w * rg[i].h * rg[i].slices * 4;
|
||||
if (!out_size) return 1;
|
||||
VkBufferCreateInfo bi = {.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, .size = in_size + out_size,
|
||||
// chunks of consecutive regions; scratch = the largest chunk's blocks, then its texels
|
||||
VkDeviceSize out_total = 0, cap_in = 0, cap_out = 0, ci = 0, co = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
VkDeviceSize o = region_out(&rg[i]), b = region_in(&rg[i], bw, bh);
|
||||
if (co && co + o > CHUNK_OUT) ci = co = 0;
|
||||
ci += b, co += o, out_total += o;
|
||||
if (ci > cap_in) cap_in = ci;
|
||||
if (co > cap_out) cap_out = co;
|
||||
}
|
||||
if (!out_total) return 1;
|
||||
VkDeviceSize al = c->props.limits.minStorageBufferOffsetAlignment; // the texels bind at cap_in
|
||||
if (al > 1) cap_in = (cap_in + al - 1) / al * al;
|
||||
VkBufferCreateInfo bi = {.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, .size = cap_in + cap_out,
|
||||
.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
|
||||
VK_BUFFER_USAGE_TRANSFER_DST_BIT};
|
||||
VmaAllocationCreateInfo aci = {.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE};
|
||||
@@ -250,7 +400,7 @@ int vk_astc_record(VkCommandBuffer cb, VkBuffer src, VkDeviceSize src_size, cons
|
||||
if (vmaCreateBuffer(c->vma, &bi, &aci, &sb, &sa, NULL) != VK_SUCCESS) {
|
||||
if (InterlockedIncrement(&n_fail) <= 16)
|
||||
rt_log("vk: ASTC scratch buffer of %llu bytes failed: texture left undecoded",
|
||||
(unsigned long long)(in_size + out_size));
|
||||
(unsigned long long)(cap_in + cap_out));
|
||||
return 0;
|
||||
}
|
||||
AcquireSRWLockExclusive(&g_lock);
|
||||
@@ -265,51 +415,112 @@ int vk_astc_record(VkCommandBuffer cb, VkBuffer src, VkDeviceSize src_size, cons
|
||||
VkBufferCopy cp = {0, 0, TAB_SIZE};
|
||||
vkCmdCopyBuffer(cb, tb, tab, 1, &cp);
|
||||
}
|
||||
VkBufferCopy cp = {0, 0, src_size};
|
||||
vkCmdCopyBuffer(cb, src, sb, 1, &cp);
|
||||
mem_barrier(cb, VK_PIPELINE_STAGE_2_COPY_BIT, VK_ACCESS_2_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
|
||||
VK_ACCESS_2_SHADER_STORAGE_READ_BIT);
|
||||
vkCmdBindPipeline(cb, VK_PIPELINE_BIND_POINT_COMPUTE, pipe);
|
||||
VkDescriptorBufferInfo dbi[3] = {{sb, 0, in_size}, {sb, in_size, out_size}, {tab, 0, TAB_SIZE}};
|
||||
int timed = 0, whole = -1;
|
||||
uint32_t id = 0;
|
||||
uint8_t fp = (uint8_t)(bw * 13 + bh);
|
||||
AcquireSRWLockExclusive(&t_lock);
|
||||
time_init(c);
|
||||
if (t_on > 0 && t_pool) {
|
||||
time_poll_locked(c);
|
||||
timed = 1;
|
||||
id = ++t_id;
|
||||
t_call[id % TA] = (TCall){.id = id, .w = rg[0].w, .h = rg[0].h, .regions = (uint32_t)n, .fp = fp, .complete = 1};
|
||||
whole = time_slot(id, fp, out_total / 4, 1);
|
||||
if (whole < 0) t_call[id % TA].complete = 0;
|
||||
}
|
||||
VkQueryPool tpool = t_pool;
|
||||
ReleaseSRWLockExclusive(&t_lock);
|
||||
if (whole >= 0) vkCmdWriteTimestamp2(cb, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, tpool, 2 * (uint32_t)whole);
|
||||
VkDescriptorBufferInfo dbi[3] = {{sb, 0, cap_in}, {sb, cap_in, cap_out}, {tab, 0, TAB_SIZE}};
|
||||
VkWriteDescriptorSet w[3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
w[i] = (VkWriteDescriptorSet){.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .dstBinding = (uint32_t)i,
|
||||
.descriptorCount = 1, .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.pBufferInfo = &dbi[i]};
|
||||
G.push(cb, VK_PIPELINE_BIND_POINT_COMPUTE, G.layout, 0, 3, w);
|
||||
VkBufferImageCopy *copies = calloc((size_t)n, sizeof *copies);
|
||||
if (!copies) rt_fatal("vk: out of memory (ASTC regions)");
|
||||
VkDeviceSize out = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
const VkAstcRegion *r = &rg[i];
|
||||
uint32_t bx = (r->w + bw - 1) / bw, by = (r->h + bh - 1) / bh;
|
||||
Push pc = {.in_base = (uint32_t)(r->src / 16), .out_base = (uint32_t)(out / 4), .width = r->w, .height = r->h,
|
||||
.bw = bw, .bh = bh, .bx = bx, .bslice = bx * by, .srgb = (uint32_t)(srgb != 0)};
|
||||
vkCmdPushConstants(cb, G.layout, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof pc, &pc);
|
||||
vkCmdDispatch(cb, (r->w + 7) / 8, (r->h + 7) / 8, r->slices);
|
||||
copies[i] = (VkBufferImageCopy){.bufferOffset = in_size + out, .bufferRowLength = r->w, .bufferImageHeight = r->h,
|
||||
.imageSubresource = {aspect, r->level, r->layer, 1}, .imageOffset = r->offset,
|
||||
.imageExtent = {r->w, r->h, r->slices}};
|
||||
out += (VkDeviceSize)r->w * r->h * r->slices * 4;
|
||||
n_texels += (uint64_t)r->w * r->h * r->slices;
|
||||
VkBufferCopy *bcp = calloc((size_t)n, sizeof *bcp);
|
||||
if (!copies || !bcp) rt_fatal("vk: out of memory (ASTC regions)");
|
||||
VkDeviceSize rb_off = 0;
|
||||
int chunks = 0;
|
||||
for (int i0 = 0; i0 < n; chunks++) {
|
||||
int i1 = i0;
|
||||
VkDeviceSize in = 0, out = 0;
|
||||
for (; i1 < n && (i1 == i0 || out + region_out(&rg[i1]) <= CHUNK_OUT); i1++) {
|
||||
bcp[i1 - i0] = (VkBufferCopy){rg[i1].src, in, region_in(&rg[i1], bw, bh)};
|
||||
in += region_in(&rg[i1], bw, bh), out += region_out(&rg[i1]);
|
||||
}
|
||||
if (chunks) // the previous chunk's dispatches and image copy are done with the scratch
|
||||
mem_barrier(cb, VK_PIPELINE_STAGE_2_COPY_BIT | VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
|
||||
VK_ACCESS_2_TRANSFER_READ_BIT | VK_ACCESS_2_SHADER_STORAGE_READ_BIT,
|
||||
VK_PIPELINE_STAGE_2_COPY_BIT | VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
|
||||
VK_ACCESS_2_TRANSFER_WRITE_BIT | VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT);
|
||||
vkCmdCopyBuffer(cb, src, sb, (uint32_t)(i1 - i0), bcp);
|
||||
mem_barrier(cb, VK_PIPELINE_STAGE_2_COPY_BIT, VK_ACCESS_2_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
|
||||
VK_ACCESS_2_SHADER_STORAGE_READ_BIT);
|
||||
int slot = -1; // the timestamps bracket this chunk's dispatches: the first waits for the blocks copy
|
||||
if (timed) {
|
||||
AcquireSRWLockExclusive(&t_lock);
|
||||
slot = time_slot(id, fp, out / 4, 0);
|
||||
if (slot < 0) t_call[id % TA].complete = 0;
|
||||
ReleaseSRWLockExclusive(&t_lock);
|
||||
}
|
||||
if (slot >= 0) vkCmdWriteTimestamp2(cb, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, tpool, 2 * (uint32_t)slot);
|
||||
vkCmdBindPipeline(cb, VK_PIPELINE_BIND_POINT_COMPUTE, pipe);
|
||||
G.push(cb, VK_PIPELINE_BIND_POINT_COMPUTE, G.layout, 0, 3, w);
|
||||
VkDeviceSize ib = 0, ob = 0;
|
||||
for (int i = i0; i < i1; i++) {
|
||||
const VkAstcRegion *r = &rg[i];
|
||||
uint32_t bx = (r->w + bw - 1) / bw, by = (r->h + bh - 1) / bh;
|
||||
Push pc = {.in_base = (uint32_t)(ib / 16), .out_base = (uint32_t)(ob / 4), .width = r->w, .height = r->h,
|
||||
.bw = bw, .bh = bh, .bx = bx, .bslice = bx * by, .srgb = (uint32_t)(srgb != 0)};
|
||||
vkCmdPushConstants(cb, G.layout, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof pc, &pc);
|
||||
uint32_t bpw = bw * bh <= 64 ? 64 / (bw * bh) : 1; // blocks per workgroup, as astc_decode.comp main
|
||||
vkCmdDispatch(cb, (bx + bpw - 1) / bpw, by, r->slices);
|
||||
copies[i - i0] = (VkBufferImageCopy){.bufferOffset = cap_in + ob, .bufferRowLength = r->w,
|
||||
.bufferImageHeight = r->h, .imageSubresource = {aspect, r->level, r->layer, 1},
|
||||
.imageOffset = r->offset, .imageExtent = {r->w, r->h, r->slices}};
|
||||
ib += region_in(r, bw, bh), ob += region_out(r);
|
||||
n_texels += (uint64_t)r->w * r->h * r->slices;
|
||||
}
|
||||
if (slot >= 0)
|
||||
vkCmdWriteTimestamp2(cb, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, tpool, 2 * (uint32_t)slot + 1);
|
||||
mem_barrier(cb, VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT, VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_2_COPY_BIT, VK_ACCESS_2_TRANSFER_READ_BIT);
|
||||
vkCmdCopyBufferToImage(cb, sb, img, VK_IMAGE_LAYOUT_GENERAL, (uint32_t)(i1 - i0), copies);
|
||||
if (readback) {
|
||||
VkBufferCopy rc = {cap_in, rb_off, out};
|
||||
vkCmdCopyBuffer(cb, sb, readback, 1, &rc);
|
||||
rb_off += out;
|
||||
}
|
||||
i0 = i1;
|
||||
}
|
||||
n_dispatch += (uint64_t)n;
|
||||
mem_barrier(cb, VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT, VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_2_COPY_BIT, VK_ACCESS_2_TRANSFER_READ_BIT);
|
||||
vkCmdCopyBufferToImage(cb, sb, img, VK_IMAGE_LAYOUT_GENERAL, (uint32_t)n, copies);
|
||||
if (readback) {
|
||||
VkBufferCopy rc = {in_size, 0, out_size};
|
||||
vkCmdCopyBuffer(cb, sb, readback, 1, &rc);
|
||||
if (readback)
|
||||
mem_barrier(cb, VK_PIPELINE_STAGE_2_COPY_BIT, VK_ACCESS_2_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_2_HOST_BIT,
|
||||
VK_ACCESS_2_HOST_READ_BIT);
|
||||
if (whole >= 0) vkCmdWriteTimestamp2(cb, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, tpool, 2 * (uint32_t)whole + 1);
|
||||
if (timed) {
|
||||
AcquireSRWLockExclusive(&t_lock);
|
||||
t_call[id % TA].chunks = (uint32_t)chunks;
|
||||
ReleaseSRWLockExclusive(&t_lock);
|
||||
}
|
||||
free(copies);
|
||||
if ((n_dispatch + (uint64_t)n) / 1024 != n_dispatch / 1024 || !n_dispatch) {
|
||||
rt_log("vk: ASTC: %llu regions, %.1f M texels decoded on the GPU so far",
|
||||
(unsigned long long)(n_dispatch + (uint64_t)n), (double)n_texels / 1e6);
|
||||
vk_astc_time_summary();
|
||||
}
|
||||
n_dispatch += (uint64_t)n;
|
||||
free(copies), free(bcp);
|
||||
vk_defer_buffer(sb, sa);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void vk_astc_release(void) {
|
||||
VkCtx *c = vk_ctx();
|
||||
vk_astc_time_summary();
|
||||
AcquireSRWLockExclusive(&t_lock);
|
||||
if (c && t_pool && t_dev == c->device) vkDestroyQueryPool(c->device, t_pool, NULL);
|
||||
t_pool = VK_NULL_HANDLE, t_dev = VK_NULL_HANDLE;
|
||||
ReleaseSRWLockExclusive(&t_lock);
|
||||
AcquireSRWLockExclusive(&g_lock);
|
||||
if (c && G.dev == c->device) {
|
||||
if (G.pipe) vkDestroyPipeline(c->device, G.pipe, NULL);
|
||||
|
||||
@@ -501,7 +501,7 @@ static void astc_check(const Tex *e, const uint8_t *raw, const VkAstcRegion *ar,
|
||||
"cpu %08x gpu %08x", (unsigned long long)e->pub.addr, e->t.d.format, bw, bh,
|
||||
(unsigned long long)diff, first_k, (unsigned long long)first, want, got);
|
||||
}
|
||||
if (!(n_tex & 255) || diff)
|
||||
if (n_tex == 1 || !(n_tex & 63) || diff)
|
||||
rt_log("vk: ASTC check: %llu textures, %llu texels compared, %llu textures differ", (unsigned long long)n_tex,
|
||||
(unsigned long long)n_texels, (unsigned long long)n_diff_tex);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user