Skip to content

[FOR TEST ONLY] PanVK kbase (mali_kbase) from zenithblue-oss's repo - #123

Draft
lfdevs wants to merge 398 commits into
dev/adreno-mainfrom
test/panvk-kbase
Draft

lfdevs wants to merge 398 commits into
dev/adreno-mainfrom
test/panvk-kbase

Conversation

@lfdevs

@lfdevs lfdevs commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

zenithblue-oss and others added 28 commits November 18, 2026 10:46
vkCreateXlibSurfaceKHR and vkCreateXcbSurfaceKHR looked up the window
visual (query_tree + get_window_attributes) and returned
VK_ERROR_OUT_OF_HOST_MEMORY when it could not be found. That happens
whenever the X window has been destroyed or is going away (app exit,
backgrounding in the launcher's X server), not on allocation failure.
DXVK's presenter, after VK_ERROR_OUT_OF_DATE_KHR and SURFACE_LOST from
the capability query, re-creates the surface and got OOHM, logged as
"Failed to create Vulkan surface: VK_ERROR_OUT_OF_HOST_MEMORY"
(PanPlay, 11 sessions on v9-v13, Just Cause 2 twice on G68).

Surface creation has no SURFACE_LOST code, so create the surface
anyway, as opaque (has_alpha = false), and let its queries report
VK_ERROR_SURFACE_LOST_KHR: x11_surface_get_capabilities already does
when xcb_get_geometry fails. The visual is only used for the composite
alpha caps. OOHM remains for a real allocation failure (and for the
libxcb dlopen failure, as before). Also free the xcb error of a failed
get_geometry in the capability query (leaked once per query).

Assisted-by: LLM
VkPresentRegionKHR rects were stored as given. The MIT-SHM software
present (csf-v11/117) skipped any rect with a negative x or y, so a rect
that starts left of or above the image but covers part of it was never
copied and that part of the frame stayed stale. The PutImage software
path used the rects unclipped and read before the start of the image
for a negative origin.

Clip each rect to the swapchain extent in x11_queue_present (64-bit
arithmetic, so large offsets cannot wrap) and drop the empty ones. If
none is left, present the whole image, as without damage. The XFixes
update region gets the same clipped rects.

Assisted-by: LLM
The ETC2/EAC transcoder of csf-v11/197 searched the ETC2/EAC code space
per texel (16 decoded texels x every table, modifier and base); on the
G615 that put BC1-BC5 uploads at 16-43 ms per 1024x1024 chain against
1.4-4.1 ms for the RC4-lowmem decode path. It is now a palette encoder:
BC1-BC5 blocks have at most 4 colours / 8 alpha values, so every search
runs on the palette and the texels are remapped at the end.

 - EAC (BC2/BC3 alpha, BC4, BC5): the base codeword is fitted to the 8
   palette values (centre, then least squares on the chosen modifiers),
   the (table, multiplier) candidates come from a LUT indexed by the
   palette shape (EAC_TM_LUT, trained offline by tests/bc-host/gen_eac_lut
   over all BC4 endpoint pairs), the nearest modifier per value from a
   second LUT (EAC_NEAR); the error is exact (clamped, palette counts).
   PANVK_BC_LM_OPTS bits 20-21 pick 1-3 candidates (default 1).
 - ETC2 RGB (BC1-BC3): the 4 BC1 colours are kept unpacked; the flip is
   chosen from the half-block sums (both with 0x40000), ETC1 tables by a
   1D luma search over the 3 tables around the colour spread (all 8 with
   0x80000), H mode seeded from the BC1 endpoints with 3 distances around
   their spread, planar from the palette moments; every candidate error
   is exact over the palette with per-colour counts.
 - one pipeline per transcode mode: the mode and the options are
   specialization constants (2, 3) instead of push constants, so each
   pipeline only holds its own path; loops are unrolled ([[unroll]]), the
   per-block arrays are scalars (no dynamically indexed locals), loads and
   stores are uvec2/uvec4, and block addresses are 64-bit (z * slice no
   longer overflows 32 bits).

Quality against 200 (tests/bc-host/bench_etc2, PSNR of the ETC2/EAC
decode against the exact BC decode, 65536 blocks per set, default opts
0x30000), and host time per block:

  set      BC1    BC1A   BC2a   BC3a   BC4U   BC4S   (dB delta)
  random  -0.43  -0.11  -0.16  -0.09  -2.33  -2.37
  pic0    -0.15  -0.14  -1.02  -0.17  -1.10  -3.18
  pic2    -0.70  -0.70  -0.74  -0.64  +1.95  -4.14
  pic3    -0.08  -0.08  -1.87  -0.08  +2.12  -3.52
  host time: BC1 2.6-7.3x, BC2/BC3 3.4-8.8x, BC4/BC5 5.6-8.4x faster,
  5.8x overall

With 3 EAC candidates (PANVK_BC_LM_OPTS=0x230000) EAC is within
-0.45..+10.1 dB of 200 (BC4S pic3 -1.58) at 2x the EAC cost. SPIR-V ops
per block after specialization and optimization (default opts): BC1
2311, BC1A 2284, BC2 3130, BC3 3006, BC4 843, BC4S 835, BC5 1573, BC5S
1557 (BC4 1792 with 3 candidates).

The workgroup size is a specialization constant too, PANVK_BC_LM_WG=XxY
(default 8x8, x * y <= 256), part of the pipeline key, for device tuning.

PANVK_DEBUG=bc_timing: two ALL_COMMANDS timestamps (device-wide query
pool of 4096 slots, created lazily) around every BC upload / BC image
copy, read back when the command buffer is reset or freed (it can not be
pending then) and logged as
  panvk: bc_timing <format> <w>x<h> regions=N layers=N xcode|decode: X us
plus a running total every 64 operations. It serializes the queue around
each operation and is meant for measurements only.

Teardown goes through panvk_per_arch(device_bc_finish)(), which replaces
the panvk_meta_cleanup() call of destroy_device on the same line, so the
jm-v9 hunks in panvk_vX_device.c keep their line numbers.

Tested GPU: none (host tests: tests/bc-host test_etc2 0 failures,
bitstream and exact-error model checked against the Mesa ETC2/EAC
decoder for every mode; bench_etc2 table above)
Mesa base range: 5a07217
Dependencies: csf-v11/197
Validation test: tests/bc-host (make run); device: PanProbe bc_decode
 (ETC2/EAC shadow within the PSNR gate) and bc_perf with
 PANVK_DEBUG=bc_timing (upload ms per format)

Generated-by: LLM
…e store

csf-v11/197 had to keep the raw BC block plane of every lowmem image with
TRANSFER_SRC usage in the image memory, because Vulkan returns those
blocks from image -> buffer copies and BC-source image copies. DXVK sets
TRANSFER_SRC on every texture, so under DXVK the plane cost most of the
lowmem saving (BC1-BC5 images were 2x the BC size, BC6H/BC7 unchanged).

Such images (PANVK_BC_RAW=store, the default, raw blocks of at least
PANVK_BC_RAW_MIN bytes, default 64 KiB) now get no raw plane in the image
memory: vkGetImageMemoryRequirements reports the shadow only, the size
of the RC4-lowmem build (BC1/BC4 = BC size, BC3/BC5 = BC size, BC7 = the
8 bpp AFRC shadow, BC6H = the exact shadow). The raw blocks go to a
per-image panvk_bc_raw:

 - a driver BO (CPU-cached mapping) holds them while command buffers that
   touch raw blocks exist. Every raw access (buffer -> image upload,
   image -> buffer copy, both sides of vkCmdCopyImage) takes a reference
   for the command buffer at record time (panvk_bc_raw_acquire()); the
   reference goes when the command buffer is reset or freed, which it can
   only be once it is no longer pending. planes[0] points at the BO, so
   all the existing raw paths work unchanged and the GPU sees a single
   copy of the blocks whatever the submission order;
 - when no command buffer references the store, a low-priority worker
   thread writes the blocks to an unlinked per-device spill file (O_TMPFILE
   in $PANVK_BC_RAW_DIR, $TMPDIR, the Android app cache directory
   /data/user/<user>/<package>/cache, /data/local/tmp or /tmp; app
   processes can not write /data/local/tmp), drops the page
   cache copy and frees the BO. The copy only commits if no acquire came in
   meanwhile (generation count);
 - the next raw access reads them back at record time into a new BO. An
   image that never got blocks gets a zeroed BO (that is also what a
   ZERO_INITIALIZED image holds; its decode reads a zero row). A store read
   back twice stays resident (no ping-pong for images that are updated or
   copied all the time). Without a spill directory stores stay resident,
   which costs what the in-image plane did.

Uploads transcode or decode from the copy source as before, so the store
is never read on the upload path. An upload or BC -> BC image copy whose
regions cover every block of the image (they can not overlap) gets a new
BO without the read-back or the zero fill and CPU cache flush. Images that are destroyed while command
buffers still hold the store free it with the last reference. Images
without TRANSFER_SRC keep the 197 behaviour (no raw blocks at all), and
PANVK_BC_RAW=plane restores the in-image plane.

Trade-offs: raw blocks are written to flash once per upload (about the
BC size of every texture DXVK uploads, freed with the image by punching
holes in the file), and a later raw read costs a pread at record time.
Both only happen for TRANSFER_SRC images; the GPU-side cost is unchanged.

Tested GPU: none (builds; device plan in worklogs/bc-emul-perf/lowmem-v2.md)
Mesa base range: 5a07217
Dependencies: csf-v11/197, 200
Validation test: device plan in worklogs/bc-emul-perf/lowmem-v2.md
 (bc_decode raw readback and image copies bit-exact for all 16 formats,
 the vkCmdCopyImage BC matrix, bc_perf memory, spill file and RSS)

Generated-by: LLM
BC6H was the one format the lowmem path did not shrink: its exact shadow
is B10G11R11 (32 bpp, 4x the BC6H size) and the RC4-lowmem build only
dropped the raw plane (-11..-20%). The G615 samples ASTC HDR natively, so
BC6H UF16 images on the lowmem path can get an ASTC 4x4
HDR shadow (bc_lowmem = 3, PANVK_BC_BC6H=astc) (VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK, 8 bpp, U-interleaved, sampled
only), written by a new compute transcoder, bc/panvk_bc_astc.comp:

 - exact BC6H decode per texel (the decoder of panvk_bc_bc6.comp), then
 - bc/panvk_bc_astc_enc.h, an encoder in the GLSL/C subset: one partition,
   colour endpoint mode 11 (HDR RGB direct, all 8 sub-modes, both endpoint
   orders and the majcomp-3 layout tried), endpoints at QUANT_256, a 4x4
   weight grid at QUANT_12 (trit ISE, 58 bits). Endpoints come from the
   principal axis in the LNS domain the ASTC decoder interpolates in, plus
   up to two least-squares refinements; weights are picked on the decoded
   fp16 values (the exact objective).

Host checks (tests/bc-host/test_astc, 131072 blocks): every block decoded
by the ARM reference codec (astc-encoder 4.8.0) matches the encoder's own
model bit for bit. Against the exact BC6H decode, tone-mapped PSNR
(x/(1+x), 8-bit scale) / max relative error, with the B10G11R11 rounding
of the exact path for reference:

  sky + sun (0..60)        63.6 dB / 0.050   (B10G11R11 59.6 dB / 0.015)
  lightmap (0..8)          52.1 dB / 0.105   (60.6 dB)
  noisy texture (0..2)     52.5 dB / 0.076   (59.1 dB)
  emissive panel           80.2 dB / 0.005   (80.5 dB)
  random BC6H blocks       23.6 dB           (68.3 dB; noise blocks with
                                              1e-5..6e4 in one block)

BC6H SF16 keeps the exact RGBA16F shadow (ASTC HDR has no negative
values), and so do MUTABLE_FORMAT UF16 images (an SFLOAT view would sample
the ASTC shadow as signed). The default is PANVK_BC_BC6H=exact
(B10G11R11): the ASTC shadow is 4x smaller but filters at half rate
(64 bpp decode) and is lossier, so it is opt-in. Image views of the ASTC
shadow set pan_image_view.astc.hdr from the shadow format (it was computed
from the BC view format before the format swap). Memory per
2048x2048 chain with mips: 22.4 MiB shadow -> 5.6 MiB.

Sampling cost is the open question: a random-payload ASTC 4x4 texture
sampled at 0.84 ms in the bandwidth-bound bc_perf mode E, against 0.33 ms
for the B10G11R11 shadow; these blocks use only single-partition HDR
mode 11, which may be faster. Measure before relying on it.

Tested GPU: none (host bitstream test only)
Mesa base range: 5a07217
Dependencies: csf-v11/197, 200, 201
Validation test: tests/bc-host/test_astc; device plan in
 worklogs/bc-emul-perf/lowmem-v2.md (bc_decode BC6H UF within the PSNR
 gate, bc_perf memory and sampling time, PANVK_BC_BC6H=exact)

Generated-by: LLM
RC5-dev-bc2 uploads BC1-BC5 into lowmem images 1.2-2.6x slower than
RC4-lowmem on the G615 (BC1 2.9 -> 5.0 ms, BC3 3.2 -> 6.2 ms per 2048^2
mip chain), BC6H/BC7 ~1 ms slower. Three causes, three fixes:

- The ETC2/EAC transcoder is integer-ALU bound on Valhall (CVT/SFU units,
  IMUL for every squared error) with the FMA unit idle. The ETC1 / H
  error sums now run in fp32, which is exact here (at most
  16 * 3 * 255^2 < 2^24): same bitstream, Valhall static cycles per
  block BC1 79 -> 58, BC2 107 -> 85, BC3 102 -> 81 (panfrost compiler
  shader-db stats for v11).
- An upload into a raw-store image (csf-v11/201) ran a separate
  vk_meta copy of the source into the raw plane before the transcode,
  reading the source twice in two dispatches per region. The transcoder
  now stores the raw blocks itself (push constant raw/raw_row_B/
  raw_slice_B, 0 when the image keeps none); the BC6H ASTC transcoder
  and 3D images keep the separate copy.
- Android app processes have no writable $HOME/.cache, so the disk
  shader cache stayed off and every process compiled the per-mode
  transcode pipelines again (0.7-5.8 s each on the host for the
  unrolled shaders), which doubled bc_perf wall time. util/disk_cache:
  without MESA_SHADER_CACHE_DIR or XDG_CACHE_HOME, Android uses the app
  cache directory /data/user/<user>/<package>/cache before $HOME.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
csf-v11/203 took the package for the app cache directory from
/proc/self/cmdline, but PanProbe (and any app that runs Vulkan in a
helper it fork()s and execve()s) has the helper's path there,
/data/app/~~<x>/<package>-<y>/lib/arm64/libpt_runner.so. HOME is /data,
so the G615 log still said "Failed to create /data/.cache for shader
cache (Permission denied)---disabling" and every process compiled the
BC transcode pipelines again.

u_android_app_dir.h resolves the app's writable cache directory,
/data/user/<uid / 100000>/<package>/cache or /data/data/<package>/cache,
from the first package that has one: our process name, the parent's
process name, the /data/app path of our binary, or an app directory in
TMPDIR, the current directory or HOME. disk_cache uses it before $HOME,
and on Android an unwritable XDG_CACHE_HOME now falls back to it instead
of disabling the cache. The BC raw store spill uses the same resolver.
MESA_SHADER_CACHE_DIR still wins and still disables the cache when it
cannot be created.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
csf-v11/100 commits the 64 MiB gpu_prerast arena and the 96 MiB
tessellation arena when the VkDevice is created, because GPU-fault
growth on MediaTek kbase loses the first gpu_prerast draw's output.
Every VkDevice that enables GS, XFB, tessellation, non-solid fill,
viewport index or vertex stores (every DXVK device, and PanProbe) paid
160 MiB of committed, CPU-cleared memory, whether it drew through
gpu_prerast or not (perf review #11).

Create each arena at the first draw that records a pass into it,
under a device lock, still fully committed and cleared before any GPU
access (the record precedes the submit), so the fault growth problem
does not come back. Barriers keep keying on whether the device enabled
the features, not on whether an arena exists yet. A failed late
allocation sets VK_ERROR_OUT_OF_DEVICE_MEMORY on the command buffer.

PANVK_GPU_PRERAST_ARENA=eager restores the creation-time commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
The BC1-BC5 lowmem transcoder (csf-v11/197-203) loses to RC4-lowmem's
precompiled kernels on the G615 (upload_gpu_ms BC1 3.45 vs 2.89,
BC3 4.33 vs 3.22, BC4S 2.66 vs 1.17, BC5U 3.96 vs 2.50). It uses 53-59
registers (one thread per slot), and the EAC part searched 16 EAC_NEAR
loads per channel.

A BC4 block's palette depends only on its two endpoint bytes, so the
EAC (base, multiplier, table) that fits it and the EAC index of every
palette entry do too. panvk_bc_eac_lutgen.c (offline, idea and
exact-end rule adapted from GunaCharanTeja/panvk-kbase-android
csf-v11/213 and 219, MIT) fits all 65536 pairs per EAC kind (alpha, R11,
signed R11; multiplier 0 for R11; a fit keeps an exact 0 / max level
when the palette has one). The driver expands a kind's 16-bit headers
with the palette entry -> index map into a 512 KiB BO at its first use
(push constant lut). The shader does one load per block and remaps the
16 BC indices.

Valhall v11 (tools/spvstat), cycles / registers, bc3 -> this:
  BC4U 30.0/53 -> 10.3/16, BC4S 29.8/55 -> 10.3/16,
  BC5U 54.3/57 -> 14.7/19, BC5S 53.8/57 -> 14.7/19,
  BC3 81.1/59 -> 54.5/59, BC1 58.3/59 -> 50.6/59 (with the opts below).
BC4/BC5 now fit in 32 registers (2 threads).

Default PANVK_BC_LM_OPTS goes from 0x30000 to 0x20000: no ETC2 planar
mode (-0.7 dB on gradients, a sixth of the BC1 cycles), and the H mode
only on blocks whose ETC1 error is above 1024 (-0.01 dB). New bits:
0x400000 EAC by the old search, 0x800000 H on every block.
PANVK_BC_LM_OPTS=0xc30000 is the csf-v11/203 encoder, bit-identical.

Quality (tools/bc-bench, 1024^2, PSNR vs the exact BC decode, bc3 ->
this): BC1 random 20.19 -> 20.19, gradient 41.17 -> 40.46; BC3
25.80/42.30 -> 25.88/41.6; BC4U 33.26/52.19 -> 35.40/51.71; BC4S
33.21/40.28 -> 35.42/40.82; BC5U 33.26/51.92 -> 35.42/51.21; BC5S
33.22/40.37 -> 35.39/42.47.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
csf-v11/201 gave every readable (TRANSFER_SRC) BC lowmem image a raw
store, and 203 made every upload write the raw blocks next to the
transcode: one more write of the source size per upload, a BO per full
upload (memset on the CPU) and a spill to flash later. DXVK sets
TRANSFER_SRC on nearly every texture but almost never reads one back.
RC4-lowmem and the GunaCharanTeja fork keep no raw blocks at all.

PANVK_BC_RAW=lazy (the new default): readable 2D BC1-BC5 images (ETC2/EAC
shadows) created before the device ever read a BC image back keep no
raw blocks (bc_raw_lazy, with bc_no_raw). Uploads write only the shadow.
A BC -> BC vkCmdCopyImage from such an image into one with the same
shadow format copies the shadow blocks (panvk_bc_scopy.comp), which is
exact for sampling. Any other read of its raw blocks (copy to a
buffer or memory, copy to a non-BC image) is skipped with one warning
and sets the device's bc_raw.needed, so BC images created after it get a
raw store again and read back exactly. BC6H/BC7 and 3D images keep
their raw stores.

PANVK_BC_RAW=store restores csf-v11/201-206 (a raw store for every
readable image), PANVK_BC_RAW=plane the raw plane in the image memory.
Apps that check raw readback bit-exactly (PanProbe bc_decode) set
PANVK_BC_RAW=store.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
BC6H SF16 lowmem images keep the exact RGBA16F shadow (~43 MiB per
2048^2 mip chain against 5.6 MiB for UF16 as ASTC HDR, csf-v11/202).
PANVK_BC_BC6H=astc_sf also sends SF16 (non-MUTABLE) images through the
ASTC HDR transcoder: the BC6H block is decoded signed and its negative
texels become 0, since ASTC HDR has no sign (as in the
GunaCharanTeja/panvk-kbase-android BC6H path). Most game BC6H SF data
(skies, light probes) is non-negative; the default stays exact.
PANVK_BC_BC6H=astc keeps its meaning (UF16 only).

The transcode mode (8 UF16, 9 SF16) is now specialization constant 2 of
panvk_bc_astc.comp as well. ASTC HDR decodes to fp16 RGBA, so it filters
at half the rate of the default B10G11R11 UF16 shadow: memory against
sampling speed, both opt-in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
A fork() child has only the forking thread. The queue workers stay in
the parent, so a job added in the child never runs and
util_queue_finish()/util_queue_destroy() in the child wait forever.

PanProbe vkd3d_heap creates the VkInstance in the parent (panvk creates
the disk cache and its disk$ worker at physical device init) and forks
one child per case. Once csf-v11/204 made the disk cache work on
Android, each child's pipeline compile queued a cache write, and its
vkDestroyInstance -> disk_cache_destroy -> util_queue_finish blocked
until the 12 s case watchdog fired (all 4 cases; passes with
MESA_SHADER_CACHE_DISABLE=true).

Register pthread_atfork handlers next to the atexit handler:
- prepare holds exit_mutex and every queue lock across fork();
- child drops the parent's queued jobs (their fences are signalled, the
  jobs stay the parent's), sets num_threads = 0, re-inits the condition
  variables without cnd_destroy (they may count the parent's waiters)
  and marks the queue respawn_after_fork;
- the child's first util_queue_add_job starts a new worker.
So the child's cache writes land and its destroy returns.

Also complete CPU detection before any worker exists (global_init) and
in the prepare handler. The first worker calls util_get_cpu_caps() ->
call_once(_util_cpu_detect_once) at nice 19 / SCHED_BATCH, reading sysfs
for every CPU. vkd3d_heap forks its first case a few ms after
vkCreateInstance, inside that window, and bionic's pthread_once (unlike
glibc's, which restarts an in-progress once in a fork child) leaves the
child's once flag "in progress" forever: the child's respawned disk$
worker blocks in util_get_cpu_caps and disk_cache_destroy waits on it.
On G615 that failed only the first case (ssbo_heap, 12 s watchdog) with
the cache really on; texel/image/mutable, forked later, passed.

Host repro: tools/u-queue-fork-test (HANG before, PASS after, and the
child's entries are readable from the parent; fork_cost: no extra
threads, only queues that get a job start one). glibc cannot show the
pthread_once part.

Assisted-by: LLM
The fragment decode of BC6H (csf-v11/150) runs one invocation per texel,
so every texel decodes its block's mode, partition and endpoints again:
each block is decoded 16 times, plus one render pass per mip level and,
for readable images, a separate raw copy pass.

PANVK_BC_BC6H_DECODE=block (the new default) makes BC6H lowmem images
bc_lowmem 4: the same exact B10G11R11 (UF16) or R16G16B16A16_SFLOAT (SF16)
shadow, U-interleaved, written by panvk_bc_bc6.comp -DPANVK_BC_BLOCK. One
invocation per 4x4 block takes both subsets' endpoints from the
per-texel decoders above (texel 0, part 0 and 1: the endpoint arithmetic
is the same code), reads each texel's index at its offset in the index
bits, and stores the 16 texels as 4 (or 8) consecutive 16-byte U-tile
writes. It runs through the transcoder plumbing (panvk_bc_xcoded()), so
uploads, image copies and ZERO_INITIALIZED images all dispatch it like
the ETC2/ASTC transcoders, and it writes the raw blocks of raw-keeping
uploads itself (no separate raw copy pass). Raw blocks are kept exactly as
for bc_lowmem 1/2.

UF16 halves become B10G11R11 with round to nearest even, saturating at
the largest finite value (65504 -> 65024, never infinity); SF16 halves
are stored unchanged. tools/bc-glsl-host/test_bc6 (the shaders run as
C++ on the host): over 320k texels of random blocks of every mode, SF16
is bit-identical to the per-texel decoder and UF16 is its correctly
rounded B10G11R11 value (max relative error 0.0154, within bc_verify's
BC_BC6U_TOL=0.0157); the per-texel decoder matches Mesa's CPU BPTC
decoder on every channel; the U-tile addresses match pan_tiling.c.

Valhall v11 (tools/spvstat), cycles per warp:
  per-texel (16 texels):    8.5-14.3 taken path, 120.9 static, 30 regs
  block, UF16 (256 texels): 34.6 (1 subset) / 48.8 (2 subsets) with the
                            mode fixed, 110.2 static, 52 regs, 0 spills
  block, SF16 (256 texels): 37.9-39.5 / 54.4-55.0, 142.1 static, 43 regs
about 4.6-5.3x fewer ALU cycles per texel, one dispatch per level instead
of one render pass, and no raw copy pass.

The shadow is U-interleaved instead of AFBC: no larger (no AFBC
headers). PANVK_BC_BC6H_DECODE=fragment keeps the csf-v11/150 fragment
decode (bc5).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
…n the decode

BC7 has to stay a fragment decode: its AFRC shadow can only be written by
a render pass. The Granite decoder (csf-v11/150) reads the block with 4
scalar loads and, in the partitioned modes, extracts every endpoint at a
subset-dependent offset, which the generic extract_bits() turns into
branches and dynamic uvec4 indexing; the weight tables are constant-
memory loads.

PANVK_BC_BC7_DECODE=fast (the new default, panvk_bc_bc7.comp
-DPANVK_BC_FAST, fragment only) decodes the same texel with:
- unsigned coordinate arithmetic and one 128-bit load of the block (BC7
  sources are 16-byte aligned);
- each channel's endpoints of all subsets read as one field of at most
  30 bits at a constant offset, then shifted to the texel's subset;
- the texel index as one shift of a 32- or 64-bit window of the index
  bits;
- arithmetic weights ((i 85 + 2) >> 2, (i 73 + 4) >> 3, (i 68 + 8) >> 4,
  exact for every index);
- the interpolation in fp32 (exact, every term is an integer below 2^24)
  inside each mode's case: it moves work from the busy CVT unit to the
  idle FMA unit, drops the division by 255, and only the colour is live
  across the mode switch (26 registers, 2 threads).
tools/bc-glsl-host/test_bc7: 200k random blocks of every mode and invalid
modes, 3.2M texels bit-identical to the Granite decoder, which matches
Mesa's CPU BPTC decoder on every texel. The AFRC shadow content is
therefore unchanged.

Valhall v11 (tools/spvstat, compute variant), cycles per warp of 16
texels with the mode fixed (Granite -> fast):
  mode 0 15.5 -> 6.2, 1 14.3 -> 5.0, 2 13.6 -> 5.0, 3 13.9 -> 4.8,
  4 9.2 -> 5.4, 5 8.5 -> 4.7, 6 6.8 -> 4.1, 7 16.8 -> 5.8;
  all modes (static): 2425 -> 1163 instrs, 75.4 -> 30.7 cycles,
  15 -> 11 ls, 30 -> 26 registers, 0 spills.

The fast fragment decoder also writes the raw blocks of an upload into an
image that keeps them (the texel at each block origin stores the block,
through the dst fields of the decode push constants), like the
transcoders do since csf-v11/203, so a BC7 upload into a readable image
no longer runs a separate raw copy pass first.

PANVK_BC_BC7_DECODE=granite keeps the csf-v11/150 decoder and the
separate raw copy (bc5).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
The BC1 -> ETC2 RGB8 / RGB8A1 encoder (shared with BC2/BC3 colour) took
58 registers and spilled 17 values on Valhall v11 at the bc4 default
opts (0x20000). BC1 RGB / RGBA now go through a cheaper palette fit,
new PANVK_BC_LM_OPTS bit 0x1000000 (OPT_BC1_PAL), default 0x1020000:

- same block structure: flip by half-block variance, differential or
  individual base per half, H mode only when the ETC1 error is above
  H_SKIP_ERR;
- every choice is made on the luma axis of the (at most 4) palette
  colours: the ETC1 modifiers and the H distance move all three
  channels, so the best modifier is the one nearest s / 3 (the palette
  fit of GunaCharanTeja's csf-v11/214, MIT). Only the chosen indices get
  the exact clamped error, instead of the nearest of the 4 clamped
  levels for every colour (48 distances per half);
- less live state: the palette packed 8:8:8 (4 registers instead of 24
  ints and floats), errors in fp32 on the FMA unit, the header and the
  bases packed before the two half fits, index planes as a mux on the BC
  index bits, H texel counts from the index bit planes (not the masks
  the ETC1 fit uses, which CSE would keep live across it), the H group
  flag in bit 24 of the packed palette;
- main() computes the final 64-bit output address before the transcode,
  so x, y, z no longer stay live across it (all modes, same address).

tools/spvstat, v11, cycles / registers / spills:
  BC1   50.78 / 59 / 14 -> 47.69 / 59 / 0
  BC1A  50.97 / 59 / 14 -> 48.50 / 59 / 0
  (bc5 tree: 50.81 / 58 / 17.) BC2 / BC3 15 spills (was 18), BC4/BC5
  unchanged or slightly lower.

tools/bc-bench, 1024^2, PSNR dB random / gradient vs 0x20000:
  BC1   20.186 / 40.446 -> 20.079 / 40.446 (-0.11 / 0.00)
  BC1A  20.913 / 40.361 -> 20.911 / 40.360 (-0.00 / -0.00)

Bit identity (host C build, 1M random + structured blocks per mode):
BC2-BC5 at 0x1020000 identical to cc9e48fc at 0x20000; every mode
identical at 0x20000 and at 0xc30000 (bc3 encoder).

PANVK_BC_LM_OPTS=0x20000 restores the bc4 encoder, 0xc30000 the bc3 one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
Each tessellation chunk ran three dependent dispatches after the TCS,
each followed by a full compute drain: panlib_tessellate(COUNT),
panlib_tess_draw() (a serial prefix sum on a single invocation, one
dependent load/store per patch, up to ~507 patches a chunk) and
panlib_tessellate(WITH_COUNTS) (tess perf review #2, #3).

panlib_tess_count_draw() does COUNT, a 64-wide workgroup scan of the
per-patch index counts and the draw/range bookkeeping of
panlib_tess_draw() in one workgroup. For a direct draw with at most
PANVK_TESS_FUSE_GEN_MAX patches (default 64), the same workgroup also
runs the WITH_COUNTS pass after a global barrier: the separate pass
would have been a single 64-wide workgroup too, so nothing is lost,
and the chunk takes one dispatch instead of three. Larger and
indirect draws keep the many-workgroup WITH_COUNTS pass.

Statistics, prims-generated, range and "more" are written exactly as
panlib_tess_draw() writes them. The kernels live in a new
libpan/tess_fast.cl (with panlib_tess_gen(), the WITH_COUNTS pass), so
draw_helper.cl and the v9 JM tess path that later series patch stay as
they are.

PANVK_TESS_FUSE=0 restores the three passes. Both knobs are read at
VkDevice creation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
Every tessellated draw ran panlib_tess_setup() as its own dispatch and
drain before the loop, then on the first iteration a CS once-block
(three CS loads, each waited on, and up to eight stores) that drops
the draw when conditional rendering says so, then panlib_tess_step()
(tess perf review #4).

panlib_tess_setup_step() does all three in one single-invocation
dispatch: on its first execution (pass_mem[1] == 0) it copies the API
draw exactly as panlib_tess_setup() does, zeroes the same fields the
CS once-block zeroed when the predicate (pass_mem[0]) is 0, sets the
once flag, then runs the step. The CS still writes the predicate and
clears the once flag at execution time before the loop, so
resubmission and simultaneous use behave as before, and a dropped draw
still runs both loops as empty handshakes and releases the arenas.

PANVK_TESS_SETUP_STEP=0 restores the separate setup dispatch and the
CS once-block. Read at VkDevice creation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
A tessellated draw owns the device's single 96 MiB tessellation arena
from its compute pre-pass until its vertex/tiler loop has drawn the
last range and released it. The next tess draw's compute side waits
on that release, so on a frame of many small tess draws the compute
and vertex/tiler queues take strict turns: compute idles while the
draw is tiled, the tiler idles while the next draw's VS, TCS and
tessellator run, and every draw pays both cross-queue hand-offs in
series (tess perf review #1).

Give the device a second tessellation arena, with its own ownership
sync and its own ready/free pair in the queue syncobjs BO (same
64-byte slots, +16 bytes, initialized like the first pair). Odd tess
draws of a command buffer use it. The compute side of draw N+1 then
runs while draw N is drawn, and the queues overlap.

Deadlock freedom is the same argument as before: every loop takes and
gives one pair, each pair's loops are recorded in the same order on
the compute and vertex/tiler queues, and each arena's ownership sync
is taken on compute and given on vertex/tiler in that same order. The
non-tessellated chunk loop keeps sharing the first pair. Nested
(GS / polygon-mode / XFB) tess draws still serialize on the gpu_prerast
arena, as before.

The second arena is allocated, fully committed, at the first draw that
picks it (as csf-v11/205 does for the first), so a device that never
records two tess draws in a command buffer pays nothing. If that
allocation fails, the device falls back to one arena for good.

PANVK_TESS_ARENAS=1 keeps the single arena. Read at VkDevice creation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
The libpoly tessellator writes clockwise triangles. For the other
winding, panlib_tessellate() made a second pass over each patch's
indices, on the same single invocation that tessellated the patch:
one load and two stores per triangle, 512 dependent round trips for a
quad at level 16 and 8192 at level 64 (tess perf review #5). With the
default upper-left domain origin, every TES that asks for ccw (most
D3D content through DXVK) paid it.

Add POLY_TESS_CCW_INLINE, a poly_tess_params::ccw bit that makes
DefineTriangle() swap the second and third index as it writes the
triangle. The order and the provoking (first) vertex are the same as
after the old pass. The tess_fast.cl kernels only run the pass for the
old value 1, and the PANVK_TESS_FUSE=0 path now generates through
panlib_tess_gen() too, so no CSF draw swaps twice. panlib_tessellate()
(COUNT on CSF, and the v9 JM path, which keeps ccw = 0/1) is unchanged.
The asahi users set 0 or 1 and are unaffected; points and isolines
never go through DefineTriangle().

PANVK_TESS_WINDING_INLINE=0 restores the second pass. Read at VkDevice
creation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
BC2 / BC3 colour still went through the full ETC2 encoder, which takes
59 registers and spills 15 values on Valhall v11 (scratch traffic on
every block). Their colour blocks are always 4-colour, i.e. the opaque
BC1 case of the palette fit of csf-v11/212, so new PANVK_BC_LM_OPTS bit
0x2000000 (OPT_BC23_PAL) sends them through etc2_encode_bc1_pal() too.
Default 0x3020000; 0x1020000 is the previous (bc6) encoder.

tools/spvstat, v11, cycles / registers / spills:
  BC2   78.28 / 59 / 15 -> 74.94 / 59 / 0
  BC3   54.78 / 59 / 15 -> 51.41 / 59 / 0
BC1 / BC1A / BC4 / BC5 are unchanged.

tools/bc-bench PSNR at 1024^2 (random / gradient), vs 0x20000 (bc4):
  BC2   25.450 / 41.444 -> 25.433 / 41.448 dB
  BC3   25.914 / 41.582 -> 25.879 / 41.585 dB

Assisted-by: LLM
A BC1-BC5 -> ETC2/EAC upload of a full mip chain was one dispatch per
level: 12 for a 2048^2 chain, of which the 9 smallest hold 1.6% of the
blocks but each pays the dispatch setup (pipeline bind, push upload,
RUN_COMPUTE and its sync). The whole-level, single-layer regions of an
upload with at most PANVK_BC_LM_BATCH blocks (default 4096, i.e. 256^2
and below; 0 = one dispatch per region as before) now go through one
dispatch of a new XC_BATCH specialization (constant 4) of
panvk_bc_etc2.comp: the push constants point at a table of up to 16
levels (first block index, source / shadow / raw addresses and
strides), invocation i transcodes block i of the levels laid end to end.
A 2048^2 chain takes 4 dispatches instead of 12.

The per-region pipeline (XC_BATCH 0) compiles to the same code as
before. The batch pipeline costs ~3.8 cycles more per block (table
lookup, division by the level width), on the small levels only.

tools/spvstat, v11, XC_BATCH=1 (cycles / registers / spills):
  BC1 51.44 / 57 / 0, BC3 55.16 / 57 / 0, BC4 13.88 / 22 / 0,
  BC5S 18.22 / 22 / 0.
Host check (tools/bc-glsl-host, shader as C++): batched and per-level
output (shadow and raw blocks) are byte-identical for BC1, BC1A and BC2
on a 100x60 chain (non-power-of-two widths).

Assisted-by: LLM
PANVK_TESS_FUSE (csf-v11 213) broke every quad-domain tess draw small
enough for the fused workgroup to tessellate (bc6c on G615: 13 of 24
tessellation cases, tess_perf L=4/16/mix). Triangles, isolines, and
draws over PANVK_TESS_FUSE_GEN_MAX patches, which tessellate in
panlib_tess_gen(), passed. In point mode the 16 outer-ring points of
an L4 quad were drawn and the 9 interior ones were not: the interior
points come from the dynamically indexed tessellator arrays, which live
on the stack.

The fused kernel's logic is that of the three passes. What differs is
the stack: panlib_tess_count_draw() inlined the tessellator once for
COUNT and once for WITH_COUNTS, and its quad variant needed 5648 B
(8 KiB per thread). No other libpan kernel needs more than 2096 B
(4 KiB per thread), and the triangle variant at 3616 B worked. On G615
the WITH_COUNTS copy in the upper half of the stack produced broken
points. The 8 KiB stack also doubled the device-wide TLS.

gen is now a variant of panlib_tess_count_draw(). The COUNT-only
variant has the stack of panlib_tessellate(COUNT) (0 B for triangles,
2208 B for quads). The driver uses the gen variant only while it needs
at most 4 KiB per thread. Triangles and isolines still take one
dispatch per chunk. Quads count, scan and draw in the fused workgroup,
then tessellate in panlib_tess_gen(), which is two dispatches instead
of the legacy three, with the parallel scan.

A single tessellator call site with a run-time mode was tried first.
It still needed 5296 B.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
…n trim

Rationale: vkResetCommandPool(RELEASE_RESOURCES) cleaned only
tls_big_bo_pool, and did it before the command buffer resets put their
BOs back on the free lists, so nothing was released; there was no
vkTrimCommandPool, so the desc/varying/TLS/CS free lists only grew
(perf review 2026-10-22 K6).
Expected gain: memory. After a loading screen or a large frame, PSS
drops by the pool's free-list slabs once the app resets with
RELEASE_RESOURCES or trims (DXVK trims command pools); no per-frame cost.

The free lists are freed after vk_common_ResetCommandPool(), and
panvk_TrimCommandPool() frees them and the cached push sets. Free-list
BOs belong to reset command buffers, which are not pending, and the
pool is externally synchronized.

Knob: PANVK_CMD_POOL_TRIM=0 restores the old behaviour.
Arch: all (common code). Not device-tested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
Rationale: panvk_pool_flush_maps() cleaned every WB-mapped pool BO in
full, including the unused tail of the current transient slab (perf
review 2026-10-22, "Flushing" in the submit notes).
Expected gain: CPU at vkEndCommandBuffer and JM re-submit. A command
buffer that uses a few KiB of a 64 KiB desc/cs slab now cleans only
those lines: up to about 60 KiB less cache maintenance per pool per
flush, more for small command buffers.

The transient BO is used only below transient_offset (rounded up to a
64-byte line). The other BOs have no used-size record and are still
cleaned whole. Pools without WB_MMAP return early, as before.

Knob: PANVK_POOL_FLUSH_FULL=1 restores the full flush.
Arch: all (common code). Not device-tested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
Rationale: every dma-buf import logged two info lines and every CSF
kbase_queue_wait_current() logged "wait completed successfully" at info
level; on Android each is a logd write (perf review 2026-10-22, "Logging"
in the submit notes).
Expected gain: CPU and logcat noise: two log writes per import (DXVK
host-visible chunks, swapchain/AHB images) and one per CSF queue wait.

The import lines go through mesa_log(MESA_LOG_DEBUG), which release
builds filter at run time, so MESA_LOG_LEVEL=debug shows them again (the
knob). The queue-wait line is mesa_logd (compiled out in release). Same
line count, so later series hunks keep their offsets.

Knob: MESA_LOG_LEVEL=debug restores the import lines. Arch: all.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
Rationale: Fallout 4 on the G615 (build 110) held 2.6 GiB of kbase memory
while DXVK accounted for 1.6 GiB; the other ~1 GiB could not be split
between tiler heaps, BC raw stores and pools without a counter
(worklogs/g615-dxvk/fo4-memory-analysis-2026-10-23.md, fix 1).

Every private BO is counted under a kind (device pools, shaders, command
buffer CS / descriptor / TLS slabs, device TLS, descriptor pools, BC raw
stores, u_trace, other pools, misc), with current bytes, peak and count.
Pool slabs are classified by the pool label (panvk_priv_bo_create_pool),
other callers pass the kind (panvk_priv_bo_create_kind); both are
line-neutral edits so later series hunks keep their offsets. The kbase
tiler heap contexts (alive, peak, bytes committed at HEAP_INIT, renewals,
synchronous TERMs, TERM backlog peak), BC raw store events (spills,
read-backs, pins, skipped lazy reads) and VkDeviceMemory are reported too,
with VmRSS / RssAnon / RssFile / VmSwap and MemAvailable.

logd is stopped on some phones, so the line goes to PANVK_MEM_LOG=<path>
(appended, "%p" = pid) when set, else to mesa_logi (MESA_LOG_FILE works).
At most one line per PANVK_MEM_LOG_MS (default 10000) from the CSF submit
path, plus a "panvk-mem-final" line at queue destroy.

Knob: PANVK_DEBUG=mem or PANVK_MEM_LOG=<path> (off by default; the
counters are a few atomics per BO create/destroy). Arch: counters in shared
code (all), report from the CSF queue (v10+).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
Rationale: with chunk recycling disarmed on kbase (csf-v11 098), a tiler
heap is renewed after about every big submit (KBASE_TILER_HEAP_RENEW_WORK),
and every new heap commits and zeroes 10 initial 1 MiB chunks. Up to
PANVK_KBASE_HEAP_SLOTS heaps, a spare and up to 16 retired heaps waiting
for TERM on the heap thread are alive at once, and a retired heap keeps
every chunk it grew until its TERM (fo4-memory-analysis section 2.2).

- PANVK_KBASE_HEAP_CHUNKS=<initial>[,<max>]: default 4 initial chunks and
  the physical-device max (400); "10,400" is the old behaviour. The heap
  grows on demand through kbase tiler OOM, so only a few more growth
  events per heap.
- PANVK_KBASE_HEAP_TERM_MAX (default 2, old 16, 0 = all synchronous): at
  most that many retired heaps wait for TERM on the heap thread; beyond
  it, TERM runs on the submitting thread, so the chunks go back sooner.
- One info line at the first heap: "kbase: tiler heaps N initial / M max
  chunks of K KiB".

Expected gain: 6 MiB per heap generation (about 30-60 MiB with 5-10 heaps
alive) and up to 14 fewer grown retired heaps pending under GPU-bound
load. The max is unchanged (lowering it sends big frames through the
incremental-render OOM path). Arch: v10+ kbase only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
…ks after a shadow-only copy

Rationale (fo4-memory-analysis sections 2.1, 4): Fallout 4 on the G615
shows a black head on an NPC after minutes of play under memory pressure,
and the BC raw stores can grow up to the whole BC texture size.

1. Black head: a BC -> BC copy from a lazy image (csf-v11 207) copies only
   the ETC2/EAC shadow, so a destination with raw blocks (a raw store or
   the in-image raw plane) keeps zero blocks that no longer match its
   shadow. A second copy from that image (DXVK relocating a texture twice
   under budget pressure) then copied and decoded those zero blocks: black
   ETC2, and EAC normals of (-1, -1) that light to black. The destination
   is now marked bc_raw_stale: raw reads of it take the lazy path (shadow
   copy when the shadows match, else skipped and counted) until a raw
   write covers the whole image. PANVK_BC_RAW_STALE=0 = old.
2. The first skipped lazy read switched every BC image created later to
   raw stores (bc_raw.needed) without making that read exact. Now the read
   is skipped and counted (PANVK_DEBUG=mem lazy_skips, logged 4 times and
   then at powers of two), and no image changes mode. PANVK_BC_RAW_FLIP=1
   = old.
3. A raw store read back from the spill file twice was pinned resident for
   good; DXVK touches streamed textures in several command lists, so most
   stores of a long session ended up pinned. PANVK_BC_RAW_PIN=<n> pins
   after n read-backs; default 0 = never (2 = old).

PANVK_BC_RAW=store still keeps raw blocks for every readable image (exact
readback). Arch: v10+ (the BC lowmem paths); the new checks in shared meta
code are false on v6/v7/v9, where bc_raw_lazy and bc_raw_stale stay unset.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
abhay-byte and others added 29 commits November 18, 2026 10:47
PANVK_GPU_STATS=<file> (PanPlay sets it only with MangoHud on): on the
kbase CSF queue each ring entry stores GPU timestamps after its
cross-subqueue waits and once its work retired (64-entry ring per
subqueue in the seqno BO). At each submit the retired entries are
reported, the busy intervals of all subqueues are merged, and at most
every 500 ms the file is rewritten as load=<busy %> and vram=<bytes the
driver allocated: device memory plus private BOs>. Unset: no cost.

Assisted-by: LLM
v14 A/B on build 116: PanProbe tessellation passes 3/3 with
PANVK_PRERAST_CHUNK_FLUSH=0. The v14 tessellation fault was fixed by the
sparse device TLS change (0148), so the per-chunk LS/other cache flush
only costs time. This reverts commit 5cb79a1963d (jm-v7-wip 0147).

Assisted-by: LLM
…I_SW_CACHED=1 opts in)

jm-v7-wip 0115 made the sw WSI (kbase without the DRI3 dma-buf path, so
every PanPlay Wine/DXVK present) read each frame back through the cached
host memory type and invalidate it first.  The invalidate is a userland
DC CIVAC over the whole frame per present, and on the X6 Pro (MT6897, v11)
that costs more than the write-combined read it replaces:
small frames lose most (D3D11 FL 11_1 640x360: 257 fps cached, 831
uncached, rc4 803), the cube gains (255 to 271 fps, 1 % low 43 to 83),
SquidRoom D3D12 is the same (58 / 58).  rc4 (before 0115) read uncached,
which is the whole rc4 vs 115c+ fps gap on PanPlay's small-frame tests.

Default the sw readback to the uncached buffer; PANVK_WSI_SW_CACHED=1
keeps the cached read + invalidate for A/B.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
…roup, chunk recycling)

On kbase every subqueue ran in its own queue group and no group asked for
BASE_CSF_TILER_OOM_EXCEPTION_FLAG. When a tiler heap reached max_chunks,
kbase terminated the vertex/tiler group ("CSF group 0 tiler heap OOM
notification", all subqueues stuck at one seqno, DEVICE_LOST). PanProbe
tess_perf on the Mali-G925 (v13) failed this way in ~75% of runs, and v14
showed it before. Raising max_chunks did not help: chunks never came back
to the heap within a heap generation (098 skips FINISH_FRAGMENT), so every
pass until the next heap renewal shared one budget.

- All subqueues now share one kbase group (CS i = subqueue i, the panthor
  layout) created with BASE_CSF_TILER_OOM_EXCEPTION_FLAG. At max_chunks
  kbase answers the OOM with a NULL chunk, and the firmware runs the
  existing TILER_OOM handler on the fragment CS (incremental rendering:
  flush the bins, FINISH_FRAGMENT the chunks back). The handler only
  reaches CSs of the group that hit the OOM, so with one group per
  subqueue it never ran. Group create tries the layouts that carry
  csi_handlers before the 1_6 one (MediaTek 1.21 kernels).
- The fragment subqueue issues FINISH_FRAGMENT at the end of each pass
  again, without the FRAGMENT_COMPLETED increment and without
  FRAGMENT_END, so vt_end/frag_end stay 0 and kbase's heap statistics
  check (098) still holds. Without it the IR handler frees nothing once
  earlier passes hold every chunk, and the tiler OOMs forever (X6 Pro,
  8 max chunks: firmware hang and GPU reset).

PANVK_KBASE_TILER_IR=0 restores the old layout and behaviour.

X6 Pro (G615, v11), PanProbe tess_perf with PANVK_KBASE_HEAP_CHUNKS=4,32:
10/10 PASS (build 119: OOM, DEVICE_LOST at gs=0 L=16). With 1,8 (below the
working set of the tiler) runs still hang in the firmware 4 of 9 times.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
…mages

0155 compiled the XC_BATCH pipeline of every ETC2 mode at image creation,
in the same job as the per-region one, and an upload waited for both.
Images that never take a batched upload (bc_xcode_batchable(): not a
one-layer 2D mip chain, e.g. bc_decode's 2-layer images) paid a second
compile: bc_decode with a cold shader cache took 9.3 s on build 120 vs
5.0 s on 118. The batch pipeline is now prewarmed only for one-layer 2D
images with mips; others compile it at first use, as before 0155.

Assisted-by: LLM
0157 only hooked the CSF draw path (v10+). The v9 JM draws (v9_cmd_draw)
kept running a pt_skip GS through the gpu_prerast GS kernel: strip_gs 353
us/draw on the TB336FU vs 7.5 on the X6 Pro. v9_cmd_draw now swaps the GS
out the same way (not with pipeline statistics queries, PANVK_GS_PT_SKIP=0
turns it off).

Assisted-by: LLM
0158 left JM at 0: the JM chains have no cheap GPU timestamps (they need
PERMON and write-value jobs in every chain). JM now reports the
CPU-observed time with at least one atom of the context in flight:
kbase_kmod counts atoms from JOB_SUBMIT to their completion event (only
once PANVK_GPU_STATS enabled it), and each submit reports the growth of
that busy time as consecutive intervals on a busy-time axis, so the
union in panvk_gpu_stats_busy() is that time. VRAM is the same as CSF.
Unset: no tracking, no cost.

Assisted-by: LLM
A direct draw without primitive restart inside a primitives-generated
query (and no GS/tess, which count in their kernels) has a CPU-known
primitive count. It is summed in the command buffer and added at the
query end by one update_pstats_draw job (a point list of that many
vertices) instead of one job per draw. The sum stays within 32 bits; a
draw that would overflow it counts on the GPU as before.

Assisted-by: LLM
…ed size

0164 reported 1.35-1.68 GiB of VRAM on JM: the reserved size of the
GROW_ON_GPF private BOs (tiler heaps, indirect varyings, GS and tess
buffers), of which only the pages the GPU touched are backed. With
PANVK_GPU_STATS set, such BOs are kept on a list, and the 500 ms report
replaces their full size with KBASE_IOCTL_MEM_QUERY COMMIT_SIZE (one
ioctl per BO), the same meaning as on v10+: device memory plus backed
private BOs. Unset: no list, no ioctl.

Assisted-by: LLM
…11/v13

On v14 G1-Ultra the single kbase queue group with the tiler OOM flag hangs the first submit (subqueue 1 timeout, DEVICE_LOST at vkCreateDevice). v10 and v12 are untested. Default PANVK_KBASE_TILER_IR to on for PAN_ARCH 11 and 13 only; =1 forces it on elsewhere.

Assisted-by: LLM
0160 made the uncached buffer the default for every arch after the X6 Pro (v11) A/B. On the MediaTek v14 SM-X946B the D3D11 cube runs 258 fps uncached and 733 cached (116: 766); v13 lost the same way from build 120 on. Default PANVK_WSI_SW_CACHED by arch: cached on v13+, uncached below; the env still forces either way.

Assisted-by: LLM
The TB336FU .so bisect puts the v9 PanPlay drop at 119 -> 120, which only adds 0160 for v9: D3D12 gears 259 -> 220 fps, D3D11 FL 11_0 214 -> 196. With v13/v14 losing the same way, keep 0160's uncached read only on v11 (the X6 Pro, where FL 11_1 runs ~800 uncached vs ~470 cached) and read cached everywhere else, as before 0160.

Assisted-by: LLM
…compiled

Patch 0153's block decoders (32 texels per invocation) cost about 2x the
cold compile time of build 116's per-texel decoders, so a cold BC level load
on v9 took 273-295 ms against 116's 138 ms.

Ship both variants. The first decode of a format uses the per-texel pipeline,
which compiles as fast as 116's, and queues the block decoder on a low
priority 2-thread queue that waits until no per-texel compile has run for
100 ms. Later decodes switch to the block pipeline once it is in the meta
cache. After a disk cache hit on the per-texel pipeline (no NIR compile
counted on this thread) the background compile starts without the quiet
window; it is never created synchronously, because it is not always in the
cache (a process killed before the background compile ended): doing so made
a warm bc_decode 1777 ms against 116's 219.

PANVK_BC_DECODE_TEXEL=0 restores 0153 (block decoder only).

TB336FU (v9), cold: bc_decode 849 ms vs 116 919 vs 122e 1830; bc_perf
45.7 s vs 116 46.8 vs 122e 46.5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
…e rate

Whether the cached readback type (with a full-frame invalidate) or the
uncached one is faster depends on the workload, not on the frame size: on
the X6 Pro (v11), with the same 640x360 swapchain, the D3D11 cube runs 382
fps cached vs 271 uncached, but D3D11 FL 11_1 505 vs 708. The per-arch
default of 0168/0169 can only win one of them.

With MIT-SHM and the deferred reply (the sw present path of 0160), each
BUFFER_BLIT swapchain now measures its mean frame interval in the starting
mode, the other mode and the starting mode again (A, B, A), each window at
least 120 frames and 500 ms after a 30 frame / 250 ms settle, starting 1 s
after the first present. It switches if B is 3 % faster than the mean of the
A windows, then holds, and measures again when the interval drifts by 25 %
(at most every 10 s). wsi_image_set_cpu_readback_cached() moves one image
to the other type right after its CPU copy, while it is idle.

The arch default stays the starting mode. PANVK_WSI_SW_CACHED=0/1 forces a
mode and disables the measurement.

X6 Pro, PanPlay, auto vs 122e cached / uncached (fps): D3D11 cube 352 and
383 vs 370 / 271; D3D11 FL 11_1 753 and 709 vs 562 / 759; D3D9 118 vs 118
/ 118. Build 116: cube 312-333, FL 11_1 404-443.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
On the X6 Pro (v11, lowmem BC: BC1-BC5 transcoded to ETC2/EAC, BC6H
decoded per block) a cold bc_decode took 5.2 s against rc4's 0.55 s.
Timing the pipeline creates showed 490-690 ms per ETC2 mode, of which
the back end (panvk_compile_shaders) was 4-45 ms: the rest is the
driver front end on the full transcoder, which carries every mode and
option behind specialization constants and big constant tables.

bc/gen_etc2_fixed.sh now builds the ETC2 transcoder once per mode at the
default PANVK_BC_LM_OPTS (0x3020000) and the BC6H block decoder once per
signedness, with the mode as a plain constant and spirv-opt -O folding the
rest away. In those builds the lookup tables are private arrays instead of
const arrays: glslang copies a const array into a function variable at
every dynamic index (EAC_NEAR, 512 words, 32 times in BC2), which made BC2
927 ms even after folding. Non-default PANVK_BC_LM_OPTS keeps the full
shader.

X6 Pro, cold (shader cache cleared), imported slot:
- bc_decode 612-648 ms (122f 5192, rc4 526-588, PASS mismatch=0)
- per mode: ETC2 8-55 ms, BC6H block 61-74 ms (was 490-690 / 236-262)
- workload_perf bc_level 39 ms per op (122f 462, rc4 49)
- bc_perf 28.6 s (122f 37.6, rc4 28.7)

PANVK_BC_XC_FIXED=0 compiles every mode from the full shaders again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
0171 picks the cached or uncached readback buffer from A/B/A frame-rate
windows and reprobes on drift. On v12 (SM-X920, D3D12 gears) the probe
ran five times in one session and flipped the mode back and forth, and
the D3D11 cube averaged 603 fps against 745-762 with the cached buffer
forced. On the X6 Pro (v11) the first probe of the cube landed in a
noisy window and kept the slower mode.

Probe once per swapchain (a resize makes a new swapchain, so it probes
again). Windows are 60 frames or 400 ms after a 1 s start delay. The
mode flips only when the other mode beats both windows of the current
one by 10%, and stays only when it loses to both by 10%. An unclear
result retries after 3 s, at most 3 times, then keeps the current mode.

PANVK_WSI_SW_CACHED=0/1 still forces a mode and turns the probe off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
0167 turned 0161 on only for v11 and v13 and left v12 untested. On v12
(SM-X926B, RTL) PanProbe workload_perf on 122g with
PANVK_KBASE_TILER_IR=1 (3 runs, against 5 default runs, alternating) is
faster in every case, with no failures and no DEVICE_LOST:
gs_layer 42 vs 77 us (ranges 41-53 vs 64-84), msaa_sshade 61 vs 71,
msaa_a2one 109 vs 118, msaa_ref 23 vs 27, pg_query 1.9 vs 2.2,
tex_rgba 23.9 vs 24.6.

v10 and v14 keep the old layout. PANVK_KBASE_TILER_IR=0 restores it on
v12, =1 forces 0161 on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
…lower

Firebase Pixel 7 (v10), 122g D3D11 cube: the probe measured cached
587/574 fps and uncached 130.6 fps for a whole window before it kept
cached. The B window now ends after 8 frames when it runs below 70 % of
the A rate: the A mode is restored and the probe is done. An unclear
probe is retried once instead of twice (Galaxy S9, v6: cached 101 vs
uncached 105-107, "unclear, again later").

PANVK_WSI_SW_CACHED=0/1 still forces a mode and turns the probe off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assisted-by: LLM
Use the current poly_heap layout for the per-batch varying allocators. Pass the same heap to the indexed helpers and tessellation budget kernel, retaining the downstream heap-half selection and resubmit reset.

Generated-by: LLM
Keep the backend handshake version when no driver override is supplied. Register dma-buf imports in handle_to_bo while the generic import path holds its lock, as required by pan_kmod_bo_put().

Generated-by: LLM
Read product IDs from physical device properties now that compiler inputs carry the model and architecture. Pass PAN_ARCH to the current varying layout APIs, including emulated preraster and passthrough variants.

Generated-by: LLM
Keep JM query copy/reset kernels independent of the cross-architecture pipeline statistics helper. Make the byte-count draw helper available to v6/v7 as well as v9 and CSF.

Generated-by: LLM
The nixpkgs OpenCL patch that configures Mesa to locate Clang libraries is
removed when adapting its Mesa recipe. Apply the equivalent Meson changes
for this Mesa baseline and pass the Clang library directory explicitly so
the NixOS build can find clangBasic and related libraries.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants