Repository navigation
EmotionalSense-P3 v0.2.1
Android at a steady 60 fps with clean audio on a modest phone (Snapdragon 636, Adreno 512): direct Vulkan present,
preemption of long guest computations, the GE, file reads and video decoding off the guest CPU, an asynchronous GE,
native decryption of the game data and a faster allocator; touch controls that no longer blink, an analog slider,
the app icon, and preparing that survives the launcher being rebuilt. The PC gets the same lighter CPU path.
Run PREPARE again after updating: the generated C changes.
Added
-
Vulkan direct present: the overlay that reads the frame (the speed pill and badge on the song list, the pause pill) now reads only the
few rectangles it needs from the GPU and uploads only those, instead of reading, copying and comparing the whole frame every presentation
(2 MB at 2x, ~100 MB/s on an Adreno 512). The picture is identical. -
Performance log:
pub_wait_ms/s(the guest thread waiting for the GPU to finish the previous frame) andgpu_ms/frame(GPU time per
stage, average and maximum, from timestamp queries) for finding where a frame's GPU time goes. -
Performance log (
EMOTIONALSENSE_PERF=1,--verbose, or "Registro de desempenho" in the Android launcher): one line a second
with the frame rate, CPU handovers between guest threads, audio underruns and queue depth, plus the firmware calls and threads
that cause the most handovers; on Android it goes to logcat and tologs/perf.log, and the launcher can share it with
renderer.log(system share sheet, no new permission). -
Vulkan direct present (default on Android): up to three frames in flight. The guest thread no longer waits for the GPU after every batch
(it waited ~45-110 ms per second on a PC), only when it reuses the slot three submits back; the PC default (copy) is unchanged.
EMOTIONALSENSE_VK_INFLIGHT=0restores the wait. -
Android: guest threads get a better priority and a 1 ns timer slack, a Performance Hint (ADPF) session reports each frame's
work against the 16.68 ms target (API 33+), and the logs say what the system accepted. -
Experimental, off by default:
EMOTIONALSENSE_MIN_DELAY_US,EMOTIONALSENSE_HOST_TICK_US(fewer thread wakeups) and
EMOTIONALSENSE_PIN(core affinity); the Android launcher has one switch for the first two. -
Direct present (Vulkan): the window can be a Vulkan window and the frame stays on the GPU (copy into a "front" image,
blit into the swapchain with the aspect kept, host overlay as a texture), instead of GPU -> host memory -> SDL texture -> GPU.
On a phone that read-back was the cost (reading memory the GPU wrote runs at about 100 MB/s on an Adreno 512: 64 % of the guest
thread at 1x, and the same again for the scaled frame at 2x). Default on Android; on a PC the default is unchanged (copy):
EMOTIONALSENSE_VK_PRESENT=direct|copy. With it the 1x framebuffer is no longer uploaded from and written back to guest
memory (as at 2x and up); a failure at any step falls back to the copy path and says why inrenderer.log. The presenter
sleeps on a condition (a frame, a resize, the window closing) with no timed polling; the performance log shows the present
mode, frames shown per second and the presenter's time per frame. -
Crash reports name the game module on Android too (the module table was full of system libraries before it) and add the
caller's address (native lr) on aarch64. -
Android: the launcher keeps the screen on while it prepares the game (extraction and compilation).
-
Android: the app has its icon (adaptive, from the same drawing as the desktop one,
scripts/android_icons.py). -
The GE runs display lists (and the renderer presents) and file reads run without holding the guest CPU, as the PSP's GE and disc run beside its CPU: the sound threads keep running while a heavy screen is drawn or a song is loaded, which removes the breaks in the menu music on phones (
EMOTIONALSENSE_HOST_WORK=0restores the old behaviour). -
Asynchronous GE: a GE thread runs the display lists beside the game, as the PSP's GE does (the game builds the next commands while the previous ones are drawn, on another core); DrawSync, ListSync and the present wait for it.
EMOTIONALSENSE_GE_ASYNC=0restores the synchronous GE. -
Video (H.264) decodes and converts without holding the guest CPU, with FFmpeg slice threads; big textures are decoded on helper threads (
EMOTIONALSENSE_TEX_THREADS), with the same result texel for texel. -
The game's data decryption (Rijndael,
0x81294) runs as native code on the game's own tables and keys: it was a fifth of the CPU of a song's loading on a phone. Checked block by block against the recompiled one (EMOTIONALSENSE_AES_CHECK=1, 131072 blocks, none differ). -
Faster user-memory and VPL allocator (no linear scans; low placement is a first fit over the free gaps; the game holds thousands of small blocks): less CPU in menus and loading, where it starved the sound threads on phones. Placement is unchanged.
-
Android: preparing recompiles the game to C again when the recompiler changed (a launcher update); it used to keep the C of the first preparation as long as it existed, so changes to the generated code (the preemption of the sound threads) never reached the phone.
-
Android: preparing and installing the game module run in a foreground service with a progress notification: they survive the launcher being rotated, rebuilt, sent to the background or the screen going off, and the launcher shows the running job, its log and its progress when it comes back.
-
Android: the two analog touch buttons (A◄, A►) are now one slider for the PSP stick, left/right only: drag the knob, the
stick follows the finger past a small dead zone and returns to the centre on release. -
Android: the touch controls no longer blink or vanish during play. They are drawn by the CPU on their own half-size surface
above the game, only when what they show changes; on an Adreno 512 every GPU-drawn buffer of the app's interface came
out one with the controls and one empty. Lifecycle events still ask for a redraw and are logged (overlay: ...in logcat).
Changed
-
Preemption at loop back-edges. The PSP's kernel is preemptive by priority; here the CPU changed hands only inside firmware calls, so a
guest thread that computed for 150 to 300 ms (loading a song) kept the sound threads waiting and the audio ring ran dry (clicks and
cuts in the transitions, worst on a phone). The generated code now tests one flag at every backward branch; a waiting thread of strictly
better priority raises it once the running thread has held the CPU for 3 ms, and the running thread yields and takes the CPU back when
that thread is done. Not applied with interrupts masked, inside callbacks and interrupt handlers, to the host's own loop, or with the
virtual clock (the deterministic runs are unchanged).EMOTIONALSENSE_PREEMPT=0turns it off,EMOTIONALSENSE_PREEMPT_USsets the
limit; the performance log haspreempt/sandhold_max_ms. The generated C changes (the kit's recompiler emits the flag test),
so PREPARE has to run again after the update. -
Vulkan renderer: above 1x the bilinear filter uses the GPU's sampler instead of four manual texel reads (at 1x it is unchanged, byte for
byte). The picture differs only by rounding; the GPU time per frame drops on a mobile GPU. -
The window's presenter sleeps until a frame exists instead of polling every millisecond (about 7 % fewer kernel context
switches on a PC; the game's own polling is unchanged), and the scheduler no longer makes wake-up calls nobody is waiting for.
A one-waiter baton (EMOTIONALSENSE_BATON=targeted) exists as an experiment and is off: it changes thread order. -
Less CPU on the gameplay screen (found on a phone: one core at 100 % and the game at 26-30 fps on a Snapdragon 636).
Measured on a PC with the Vulkan renderer, a song with the background video playing: CPU time per frame 3.1 ms -> 1.2 ms,
start-up CPU 4.0 s -> 1.25 s; the picture and the saves are unchanged.- The renderer hashed the whole texture on every draw that used it (25 GB of memory read in 1,700 frames, mostly the 512x512
video texture). The hash is now remembered per texture and recomputed only when the guest writes its memory: the memory
layer counts the writes of the pages that a cached texture covers (psp_mem_stamp,psp_mem_note_write). The value is the
same as before, so the texture-pack and dump keys do not change.EMOTIONALSENSE_TEX_HASH_CACHE=0turns it off,
EMOTIONALSENSE_TEX_HASH_CHECK=1hashes again on each hit and logs the stale ones (none in any route). - The video's YUV to RGB conversion (
sceMpegAvcCsc) does the edges once per row, shares the chroma of two pixels and uses
tables for the products; a picture asked for again is copied instead of converted again. Same pixels (unit test
avc_cscagainst the old formula). - The system memory allocator walks the blocks in address order once instead of rescanning the table for every block in the
way (thousands of small blocks cost about 150 us per allocation); same addresses as before. - The depth buffer is read back into guest memory only when a draw of the batch wrote it.
- The renderer hashed the whole texture on every draw that used it (25 GB of memory read in 1,700 frames, mostly the 512x512
-
Framebuffer copies and staging memory (Vulkan), from a phone profile where
memcpywas a third of the guest thread:- The staging buffers the CPU reads back (colour and depth) now prefer cached host memory even when it is not coherent
(invalidate before the read, flush after the write, ranges rounded to 256 bytes); on mobile GPUs the coherent fallback is
uncached memory, where CPU reads are very slow. Buffers the CPU only writes are unchanged. The memory types and the one
chosen for each buffer are listed inrenderer.log;EMOTIONALSENSE_STAGING_CACHED=0restores the old choice. - The upload of the guest framebuffer and depth buffer into the renderer is skipped when the renderer already holds that
region and the guest has not written it since (two colour staging slots, one per double-buffer target; 8888 only). On a PC
that is 783 KB per frame down to nothing after the first two frames; the checkEMOTIONALSENSE_UPLOAD_CHECK=1compares every
skipped upload with guest memory (no difference in any route).EMOTIONALSENSE_UPLOAD_SKIP=0turns it off. - The window's presenter copies the newest frame once instead of twice when the host overlay is on.
- The performance log has the renderer's flushes, bytes uploaded and written back per second and the bytes copied for the window.
- The staging buffers the CPU reads back (colour and depth) now prefer cached host memory even when it is not coherent