Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
2af56c5
Unreal Engine 5.6 Switch 2 shader records (SF_GLSL_SWITCH2)
uncraftablexd Nov 5, 2026
eb40054
shader: Ampere instructions and fixes from Orbitals, PRAGMATA and Don…
uncraftablexd Nov 5, 2026
8ff8fc3
shader: compute threads that exit before a barrier keep taking part i…
uncraftablexd Nov 5, 2026
455b6ea
dmsh_build: scalar storage-buffer loads keep their index
uncraftablexd Nov 5, 2026
ca227f5
shader: NVN2 compute c0 with two push blocks; push-constant storage b…
uncraftablexd Nov 5, 2026
8b4707b
Shader build: a simdgroup-scope fence after each threadgroup store
uncraftablexd Nov 5, 2026
5362d0f
host: GPU watchdog; the shaders of a stuck or failed submission are n…
uncraftablexd Nov 5, 2026
319ebe3
host: clamp GPU-written indirect dispatch counts
uncraftablexd Nov 5, 2026
61745aa
hid: the controller applet disconnects controllers past its maximum
uncraftablexd Nov 5, 2026
070f700
NVN2: fence and acquire syncs cover only their own queue's work
uncraftablexd Nov 5, 2026
888c4f2
NVN: 32-bit integer buffer and linear textures get the format-view us…
uncraftablexd Nov 5, 2026
ee62cc2
host: report a SyncWait that times out
uncraftablexd Nov 5, 2026
6120968
GameChat: nn::chat::Initialize answers success
uncraftablexd Nov 5, 2026
add19a4
nvn: Metal host work for Orbitals and Donkey Kong Bananza (feedback s…
uncraftablexd Nov 5, 2026
0c833c7
mac: display link rescue after the window is visible; fullscreen on a…
uncraftablexd Nov 5, 2026
1bfde97
host: NVN2 builder getters, ListFrameHistory, H.264 parameter sets, h…
uncraftablexd Nov 5, 2026
5baf078
host: a copy into a block encoder's integer texture in a CPU_NO_ACCES…
uncraftablexd Nov 5, 2026
b6f59ac
Pipelines with integer bits in float colour outputs are built whole, …
uncraftablexd Nov 5, 2026
4ac6b10
Translator binaries and chain 74287e9f3a31
uncraftablexd Nov 6, 2026
c432a5a
Orbitals (040004F027560000, Switch 2 v327680): game profile, note, ga…
uncraftablexd Nov 5, 2026
c762655
Reference entries for the Orbitals bring-up
uncraftablexd Nov 5, 2026
6c43f01
t_thermal checks the cap with its own 60 fps target, not the profile's
uncraftablexd Nov 4, 2026
16c42ab
shader: LDC .IS / .ISL with Ra = RZ, FMNMX.NAN, and PRAGMATA's LDC.64…
uncraftablexd Nov 5, 2026
0b636dd
Deferred writes: a register written again starts its shadow from the …
uncraftablexd Nov 5, 2026
1138f81
Mesh stage: find the kernel's stage memory after the loop guard's cou…
uncraftablexd Nov 5, 2026
00ba624
Mesh stage storage buffers: the hull stage's c0 table (0x210) for a m…
uncraftablexd Nov 5, 2026
bcd9f67
shader_split: RE Engine KPKA 4.2 packages and Switch 2 SDF shader def…
uncraftablexd Nov 5, 2026
297a8f0
shader: Ampere SURED.MAX.U64 / MIN.U64 as Metal 64-bit texture atomics
uncraftablexd Nov 5, 2026
db821a7
Emit integer add, subtract and multiply on uint so overflow wraps
uncraftablexd Nov 5, 2026
dd9cfbf
Build matchers accept the wrapping spelling of integer add and multiply
uncraftablexd Nov 5, 2026
9d7e39c
Keep a loop exit's subgroup block in the iteration that left the loop
uncraftablexd Nov 5, 2026
62d2889
Mesh stage memory: room for per-primitive system values, primitive bl…
uncraftablexd Nov 5, 2026
206d25b
Mesh stage: hand the per-primitive id to Metal as the primitive's [[p…
uncraftablexd Nov 5, 2026
eca874d
shader_split: read the NVN2 shaders in RE Engine's OCIO colour manage…
uncraftablexd Nov 5, 2026
7ff20b2
Ampere I2F: the immediate form has no byte select
uncraftablexd Nov 5, 2026
3c5c595
dmsh_build: one-lane subgroups for domain shaders too
uncraftablexd Nov 5, 2026
d1faa2a
Ampere ISBERD: .O reads of the stage output area in task and mesh sha…
uncraftablexd Nov 5, 2026
512993a
Ampere SUATOM.CAS (0x595, bindless 0x396)
uncraftablexd Nov 5, 2026
1b7b50a
Barycentric coordinates: attributes 0x3a8 (no perspective) and 0x3b4
uncraftablexd Nov 5, 2026
a526344
Ampere IPA.OFFSET: interpolation at an offset from the pixel centre
uncraftablexd Nov 5, 2026
8a08103
Tests for the PRAGMATA translator fixes
uncraftablexd Nov 5, 2026
e9ba2af
NVN2 sample position table: signed offsets from the pixel centre
uncraftablexd Nov 5, 2026
62e66d5
DrawMeshTasksIndirect: draw it, converting the GPU-written record bef…
uncraftablexd Nov 5, 2026
1a84fe8
Integer entry point for pixel shaders that write integer bits through…
uncraftablexd Nov 5, 2026
a9ddbd8
NVN2 push constants: the block word picks the block (compute block 1,…
uncraftablexd Nov 5, 2026
9414f12
Loop guard: a loop with a barrier counts its own iterations
uncraftablexd Nov 5, 2026
80a5c33
MEMBAR becomes a device-scope fence, not a threadgroup barrier
uncraftablexd Nov 5, 2026
c5ac943
Float slots on integer textures get a float view of the same bytes (D…
uncraftablexd Nov 5, 2026
a384ea5
Send loads through the memory pool table when a phi source of their a…
uncraftablexd Nov 5, 2026
72d9ac1
Bind buffers in sparse pools through their physical pages
uncraftablexd Nov 5, 2026
8f3dc1a
Sparse pools: bind buffers in several physical pieces through their m…
uncraftablexd Nov 5, 2026
2774e4c
docs: regenerate the symptom index
uncraftablexd Nov 5, 2026
7273f25
shader: one handle read 2D and 2D array declares the array; the 2D re…
uncraftablexd Nov 5, 2026
b31cece
Reference entries for the PRAGMATA bring-up
uncraftablexd Nov 5, 2026
de855e3
PRAGMATA (0400C76024710000): game note
uncraftablexd Nov 5, 2026
7540af7
Translator binaries and chain 7bdd33b7caf2
uncraftablexd Nov 6, 2026
8651e68
Host memory safety: no page or pool-table change under live GPU work …
uncraftablexd Nov 5, 2026
b93d4d5
Swizzled textures are deswizzled on the CPU by default; DM_NVN_DESWZ_…
uncraftablexd Nov 5, 2026
d227b45
DM_NVN_BREADCRUMB: name the dispatch in flight at the first command-b…
uncraftablexd Nov 5, 2026
dbb3531
DrawMeshTasksIndirect: read each proven record type from workgroup 0,…
uncraftablexd Nov 5, 2026
9f9dcdb
PRAGMATA (0400C76024710000): status after the tower ring; open issues
uncraftablexd Nov 5, 2026
39f0553
Residency: a removed allocation lives until its removal is committed
uncraftablexd Nov 5, 2026
32b60a9
Pool entries: drain the autorelease pool where they are made
uncraftablexd Nov 5, 2026
8a1c3a6
Sparse pools: keep 8 physical-run lookups per thread
uncraftablexd Nov 6, 2026
7ec2c66
Profile key fb_pool_dread: texture-pool shaders as depth readers, per…
uncraftablexd Nov 6, 2026
3f0b70f
nvn: read CPU-rewritten read-only storage from one copy per frame
uncraftablexd Nov 6, 2026
87da298
0x80d: Kirby's guard band cull and PRAGMATA's CSMTEST both translate
uncraftablexd Nov 6, 2026
267cec1
Ampere ALU: SETP pairs on their accumulator, IMAD's B, directed round…
uncraftablexd Nov 6, 2026
7340444
Ampere ALU: IADD3's carry predicates, PLOP3's second result, POPC / F…
uncraftablexd Nov 6, 2026
00f144b
Fix Ocarina of Time foliage jitter by preserving live shader inputs
uncraftablexd Nov 6, 2026
8eb9bac
Translator: PIXLD.COVMASK reads the pixel's coverage mask
uncraftablexd Nov 6, 2026
7eb4181
Diagnostic loop guard: loops that run out name themselves
uncraftablexd Nov 6, 2026
8ff901a
Diagnostic loop guard: pool-table miss reports, GMEM_POISON, the frag…
uncraftablexd Nov 6, 2026
0c6feb4
dmsh_dsl: the data_sized_loop analysis in the build's tools
uncraftablexd Nov 6, 2026
a5f4bbb
Automatic loop guard: data-sized loops report through the debug buffe…
uncraftablexd Nov 6, 2026
3c5d636
Host: the loop guard's buffer for library shaders with automatic sites
uncraftablexd Nov 6, 2026
ae52c66
dmsh_dsl / dmsh_loopdiag: no new lint findings
uncraftablexd Nov 6, 2026
3341821
Translator binaries and chain 29cc394f89fe
uncraftablexd Nov 6, 2026
af568a4
DM_MSL_OVERRIDE: load a side-built shader library from a plain folder
uncraftablexd Nov 6, 2026
59e4680
Mesh shaders that also write their vertices as records no longer over…
uncraftablexd Nov 6, 2026
4221b93
test_dmsh_hmma: the LDSM row address in either multiply spelling
uncraftablexd Nov 6, 2026
996be04
Translator binaries and chain bab9601ce9cf
uncraftablexd Nov 6, 2026
e31d682
MUFU.SIN and MUFU.COS of a large number of turns keep their fraction …
lunks Nov 4, 2026
1fd3301
Translator binaries and chain 916e8d674d87
uncraftablexd Nov 6, 2026
2c479a2
Large pools: a pool-table segment takes the buffer of a lookup chunk …
seedds Nov 7, 2026
b06ea7b
Large pools: one buffer over the whole pool once its chunks and segme…
seedds Nov 7, 2026
fbeacf8
Large pools: a grown pool keeps its whole-pool buffer as a wide entry…
seedds Nov 7, 2026
9e103a6
docs: large pools held twice in the residency set (memory.md), PRAGMA…
seedds Nov 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
host: NVN2 builder getters, ListFrameHistory, H.264 parameter sets, h…
…id entries, DM_CTL players 2-8

- NVN window builder getters, queue builder memory-size getters, window texture counts,
  float blend clamp and provoking vertex (PRAGMATA, Orbitals);
- vi::ListFrameHistory reports the latest presented frame;
- H.264 parameter sets from Initialize (t_codec_video passes them); DM_CODEC_DUMP;
- hid InitializeGesture(int, int); DM_CTL "p<n>:" and "both:" drive players 2-8.

Originally c56689a7 (NVN part), 24dc4535, 3eab35cf, b36fc2cb and the hid part of 5aa0fb38.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Loading branch information
uncraftablexd and claude committed Nov 6, 2026
commit 1bfde9700b5ae1e3d64bb6ed024f653edcb40c12
17 changes: 14 additions & 3 deletions dm/gfx/hle_vi.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,20 @@ uint64_t dm_nvn_frame_count(void);
HLE_FORCE("_ZN2nn2vi20GetLatestFrameNumberEPmPKNS0_5LayerE", "the layer's latest frame number: the frames presented so far", Result, h_vi_FrameNo, uint64_t *out, const void *layer) {
(void)layer; *out = dm_nvn_frame_count(); return RES_OK;
}
HLE_FORCE("_ZN2nn2vi16ListFrameHistoryEPNS0_9FrameInfoEiPKNS0_5LayerE", "the layer's frame history: none kept, 0 entries", int, h_vi_FrameHist, void *out, int n, const void *layer) {
(void)out; (void)layer; static int once; if (!once++) LOG("vi::ListFrameHistory (%d entries asked): the host keeps no frame history, 0 returned", n);
return 0;
// The layer's frame history (Switch 2 SDKs). Unreal Engine 5.6's Switch 2 RHI paces its game thread by it: its vsync thread (Orbitals, main+0x15403c0) waits for each vsync, asks
// ListFrameHistory(NULL, 0) for the count, then for that many 0x28-byte FrameInfo entries, takes the first whose u64 at +0 is 2 and, when its u64 frame number at +8 is newer than the last
// one seen, queues a flip record with the two tick counts at +0x18 and +0x20 (converted to seconds) for its frame sync. With no history the game thread's FrameSync waited for ever after the
// third frame: nothing was presented after 1 s, every thread idle (launches r03-r07). The host has no compositor: one entry, the latest presented frame, both times the current tick.
// What kind 2 and the field at +0x10 mean is read off that one consumer, not off vi2 (firmware 0400000000000063): [open]
uint64_t guest_ticks(void);
HLE_FORCE("_ZN2nn2vi16ListFrameHistoryEPNS0_9FrameInfoEiPKNS0_5LayerE", "the layer's frame history: the latest presented frame", int, h_vi_FrameHist, void *out, int n, const void *layer) {
(void)layer; uint64_t f = dm_nvn_frame_count();
static int once; if (!once++) LOG("vi::ListFrameHistory: one entry, the latest presented frame (kind 2, frame number, present ticks)");
if (!f) return 0;
if (!out || n <= 0) return 1;
uint64_t *e = out, t = guest_ticks(); memset(e, 0, 0x28);
e[0] = 2; e[1] = f; e[3] = t; e[4] = t;
return 1;
}
// Rhythm Heaven Groove (SDK 21) asks for the built-in panel's identity at start (main+0xa9a4); the SDK's version calls through the vi service object the host never made (SIGSEGV at +0x20).
// The game reads a u32 kind and, when it is 2 or more, 0x14 more bytes that it hands on; any other answer makes it hand on zeros. The host has no panel: an all-zero identifier, kind 0
Expand Down
16 changes: 16 additions & 0 deletions dm/gfx/nvn/hle_nvn.c
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,12 @@ NVN(nvnQueueBuilderGetQueueMemorySize, size_t, const NVNqueueBuilder *b) {
return (o->cmd_sz + o->comp_sz + o->ctl_sz + 4095) & ~(size_t)4095;
}
NVN(nvnQueueBuilderSetQueueMemory, void, NVNqueueBuilder *b, void *m, size_t n) { QB(b)->mem = m; QB(b)->mem_sz = n; }
// The builder's sizes read back (NVNboolean nvnQueueBuilderGet*MemorySize(const NVNqueueBuilder *, int *size)): PRAGMATA (SDK 20, RE Engine) asks for each after setting them and
// aborts in its own check (nn::diag at main+0x7169400) when they come back unanswered. The host keeps no ray-tracing queue memory: its size reads 0
NVN_NOPROTO(nvnQueueBuilderGetCommandMemorySize, NVNboolean, const NVNqueueBuilder *b, int *n) { if (n) *n = (int)QB(b)->cmd_sz; return 1; }
NVN_NOPROTO(nvnQueueBuilderGetComputeMemorySize, NVNboolean, const NVNqueueBuilder *b, int *n) { if (n) *n = (int)QB(b)->comp_sz; return 1; }
NVN_NOPROTO(nvnQueueBuilderGetControlMemorySize, NVNboolean, const NVNqueueBuilder *b, int *n) { if (n) *n = (int)QB(b)->ctl_sz; return 1; }
NVN_NOPROTO(nvnQueueBuilderGetRayTracingMemorySize, NVNboolean, const NVNqueueBuilder *b, int *n) { (void)b; if (n) *n = 0; return 1; }
NVN(nvnQueueInitialize, NVNboolean, NVNqueue *q, const NVNqueueBuilder *b) {
NVNdevice *d = ((const queue_builder_t *)b)->dev;
// NVN emits SET_WINDOW_ORIGIN / FLIP_Y into the queue's initial GPU state.
Expand Down Expand Up @@ -1410,6 +1416,11 @@ NVN(nvnWindowBuilderSetTextures, void, NVNwindowBuilder *b, int n, NVNtexture *c
}
NVN(nvnWindowBuilderSetPresentInterval, void, NVNwindowBuilder *b, int v) { WB(b)->interval = v; }
NVN(nvnWindowBuilderGetPresentInterval, int, const NVNwindowBuilder *b) { return WB(b)->interval; } // Yoshi and the Mysterious Book (Unreal Engine 5.4) reads it back
NVN(nvnWindowBuilderGetNativeWindow, NVNnativeWindow, const NVNwindowBuilder *b) { return ((const win_builder_t *)b)->native; }
NVN_NOPROTO(nvnWindowBuilderGetDevice, NVNdevice *, const NVNwindowBuilder *b) { return ((const win_builder_t *)b)->dev; }
NVN_NOPROTO(nvnWindowBuilderGetNumTextures, int, const NVNwindowBuilder *b) { return ((const win_builder_t *)b)->ntex; }
NVN_NOPROTO(nvnWindowBuilderGetTexture, NVNtexture *, const NVNwindowBuilder *b, int i) { const win_builder_t *w = (const win_builder_t *)b; return i >= 0 && i < w->ntex ? w->tex[i] : NULL; }
NVN_NOPROTO(nvnWindowBuilderGetNumActiveTextures, int, const NVNwindowBuilder *b) { return ((const win_builder_t *)b)->ntex; } // the host rotates through all of them (SetNumActiveTextures)
NVN(nvnWindowInitialize, NVNboolean, NVNwindow *w, const NVNwindowBuilder *b) {
const win_builder_t *s = (const win_builder_t *)b; win_t *o = (win_t *)w;
memset(o, 0, sizeof *o); o->magic = MAGIC('W', 'I', 'N', 'D'); o->native = s->native; o->ntex = s->ntex; o->interval = s->interval;
Expand Down Expand Up @@ -2524,6 +2535,8 @@ NVN(nvnDeviceSetIntermediateShaderCache, void, NVNdevice *d, int n) { (void)d; (
// Window: number of active swapchain textures (the host rotates through the count given at creation; logged once)
NVN_NOPROTO(nvnWindowBuilderSetNumActiveTextures, void, NVNwindowBuilder *b, int n) { (void)b; ONCE_LOG("WindowBuilderSetNumActiveTextures %d (the host rotates through the SetTextures count)", n); }
NVN_NOPROTO(nvnWindowSetNumActiveTextures, void, NVNwindow *w, int n) { (void)w; ONCE_LOG("WindowSetNumActiveTextures %d (the host rotates through the SetTextures count)", n); }
NVN_NOPROTO(nvnWindowGetNumActiveTextures, int, const NVNwindow *w) { return ((const win_t *)w)->ntex; } // PRAGMATA; the host rotates through all of them
NVN_NOPROTO(nvnWindowGetNumTextures, int, const NVNwindow *w) { return ((const win_t *)w)->ntex; }

// Command buffer memory usage: record bytes written in this recording (accumulated across segments; the host does not use control memory, always 0); the memory callback switch is ignored.
// It used to be cur - begin: once a recording overflowed into a host segment, cur is in host memory (an address below the guest begin) and it returned 0. SMBW asks for this value after recording each material setup handle,
Expand Down Expand Up @@ -2904,6 +2917,9 @@ NVN(nvnCommandBufferSetViewportSwizzles, void, NVNcommandBuffer *c, int first, i
for (int i = 0; i < n; i++) for (int k = 0; k < 4; k++) r->sw[i][k] = (uint8_t)((s[4 * i + k] ^ 2 * k) & 7);
}
NVN(nvnCommandBufferSetAlphaRef, void, NVNcommandBuffer *c, float r) { REC(c, OP_ALPHA_REF, p_alpha_ref)->ref = r; }
// Float render targets' blend clamping (SDK 20; PRAGMATA sets it at start): Metal blends float targets unclamped, so it is taken as the unclamped default for now
NVN_NOPROTO(nvnCommandBufferSetFloatBlendClamp, void, NVNcommandBuffer *c, int on) { (void)c; static int logged; if (on && !logged++) LOG("[nvn] nvnCommandBufferSetFloatBlendClamp(%d): float blending stays unclamped on Metal", on); }
NVN_NOPROTO(nvnCommandBufferSetProvokingVertexMode, void, NVNcommandBuffer *c, int mode) { (void)c; static int logged; if (mode && !logged++) LOG("[nvn] nvnCommandBufferSetProvokingVertexMode(%d): Metal keeps the first vertex as the provoking one", mode); } // PRAGMATA
NVN(nvnCommandBufferSetLineWidth, void, NVNcommandBuffer *c, float w) { (void)c; if (w != 1.0f) ONCE_LOG("SetLineWidth %.2f: Metal has only 1-pixel lines", w); }
NVN(nvnCommandBufferSetPointSize, void, NVNcommandBuffer *c, float s) { (void)c; (void)s; ONCE_LOG("SetPointSize: the point size comes from the shader"); }
NVN(nvnCommandBufferSetPrimitiveRestart, void, NVNcommandBuffer *c, uint32_t en, int idx) { *REC(c, OP_PRIM_RESTART, p_prim_restart) = (p_prim_restart){(en & 0xff) != 0, (uint32_t)idx}; }
Expand Down
11 changes: 9 additions & 2 deletions dm/host/hle_codec_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ static Result cv_dec_submit(uint64_t *out, void *t, const void *data, uint64_t s
pthread_mutex_lock(&d->mu);
if (d->nheld >= CV_HOLD) { static int n; if (n++ < 4) LOG("[RED] nn::codec %s: a packet refused with %d pictures waiting for a released buffer", k_cv_name[d->codec], d->nheld); if (d->event) hle_clear_system_event(d->event); pthread_mutex_unlock(&d->mu); return CV_BUSY; }
int got = 0;
{ static int dn = -1; if (dn < 0) dn = getenv("DM_CODEC_DUMP") ? 8 : 0; // DM_CODEC_DUMP: the first bytes of the first packets
if (dn > 0 && size) { dn--; char hx[3 * 48 + 1]; int k = 0; for (uint64_t i = 0; i < size && i < 48; i++) k += snprintf(hx + k, sizeof hx - k, "%02x ", ((const uint8_t *)data)[i]);
LOG("[codec] %s packet: %llu bytes, ts %lld, eos %d: %s", k_cv_name[d->codec], (unsigned long long)size, (long long)ts, (int)eos, hx); } }
if (d->codec == CV_H264 && d->avc) { // VideoToolbox reorders: pictures leave in presentation order, all of them at the end of the stream
if (size && mavc_decode(d->avc, data, (int)size, ts / 1000) < 0) { static int n; if (n++ < 4) LOG("[RED] nn::codec H.264: VideoToolbox could not decode a packet"); }
uint8_t *nv12 = malloc((size_t)d->w * d->h * 3 / 2); int64_t pts = 0;
Expand Down Expand Up @@ -400,8 +403,12 @@ static Result cv_dec_encrypted(void) { static int once; if (!once++) LOG("[RED]
// Each decoder type's entry points, by their names in the SDK (the work buffer, the two Initialize overloads without the H.264 parameter sets, …)
#define CV_FAMILY(tag, codec, s_work, s_init, s_init2, s_fin, s_reg, s_unreg, s_start, s_stop, s_flush, s_ev, s_sub, s_enc, s_acq, s_rel, s_props) \
HLE_FORCE(s_work, "the host decoder needs no work memory", Result, h_cv_##tag##work, uint64_t *size, uint64_t *align, uint64_t bs, uint16_t w, uint16_t h) { (void)bs; (void)w; (void)h; *size = 0x1000; *align = 0x1000; return 0; } \
HLE_FORCE(s_init, "decoded on the host", Result, h_cv_##tag##init, void *t, void *work, uint64_t wsize, uint64_t bs, uint16_t w, uint16_t h, uint32_t refs, uint32_t in, uint32_t out) { (void)work; (void)wsize; (void)bs; (void)refs; return cv_dec_init(t, codec, w, h, in, out, NULL, 0); } \
HLE_FORCE(s_init2, "decoded on the host", Result, h_cv_##tag##init2, void *t, uint64_t bs, uint16_t w, uint16_t h, uint32_t refs, uint32_t in, uint32_t out) { (void)bs; (void)refs; return cv_dec_init(t, codec, w, h, in, out, NULL, 0); } \
/* H.264's forms end in the parameter sets (const void *, size_t); the other codecs' do not, and their trailing arguments are not read. Past the registers the */ \
/* guest passes 8-byte slots, so the output format there is read as one */ \
HLE_FORCE(s_init, "decoded on the host", Result, h_cv_##tag##init, void *t, void *work, uint64_t wsize, uint64_t bs, uint16_t w, uint16_t h, uint32_t refs, uint32_t in, uint64_t out, const void *csd, uint64_t csd_n) { \
(void)work; (void)wsize; (void)bs; (void)refs; return cv_dec_init(t, codec, w, h, in, (uint32_t)out, codec == CV_H264 ? csd : NULL, codec == CV_H264 ? csd_n : 0); } \
HLE_FORCE(s_init2, "decoded on the host", Result, h_cv_##tag##init2, void *t, uint64_t bs, uint16_t w, uint16_t h, uint32_t refs, uint32_t in, uint32_t out, const void *csd, uint64_t csd_n) { \
(void)bs; (void)refs; return cv_dec_init(t, codec, w, h, in, out, codec == CV_H264 ? csd : NULL, codec == CV_H264 ? csd_n : 0); } \
HLE_FORCE(s_fin, "frees the host decoder", Result, h_cv_##tag##fin, void *t) { return cv_dec_fin(t); } \
HLE_FORCE(s_reg, "a buffer of the host decoder, acquirable at once", Result, h_cv_##tag##reg, void *t, uint32_t i, void *pool, uint32_t pidx) { return cv_dec_reg(t, i, pool, pidx); } \
HLE_FORCE(s_unreg, "the buffer leaves the host decoder", Result, h_cv_##tag##unreg, void *t, uint32_t i) { return cv_dec_unreg(t, i); } \
Expand Down
35 changes: 32 additions & 3 deletions dm/host/hle_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ void hid_keys_init(void) {
// saves a host texture's level 0 raw, every slice (a cube's six faces, a 3D texture's depth slices) (nvn_mtl.m dm_gfx_texraw), "drag <x0> <y0> <x1> <y1> [seconds=0.3]" moves one finger in a straight line between the two normalized picture
// points over that time and lifts it (the touch screen's pans and swipes, hle_touch.c gesture_sample), "dump" logs what each guest thread waits on and the graphics wait points
// (crash_dump_now, as the iOS app's DM_LOG_PORT dump; scripts/regress.py asks for it before stopping a hung game), "program <n>" makes oe::ExecuteProgram(n) with no parameters (a multi-program application's way between its programs, headless), "webshot <path>" saves the offline page shown as a PNG, "#…" is ignored.
// "p<n>:<keys>" (p2 … p8) presses on player n's controller instead, connecting it on its first press (local multiplayer without a second controller: Orbitals, two players).
// "both:<keys>" presses on players 1 and 2 together for the hold (Orbitals' "hold B to skip" wants both players: lines run one after another, so two lines never overlap).
// Look at a screen, decide, press, look again: menus whose timing moves from run to run (loading) need no blind timed script
static void *ctl_main(void *arg) {
const char *path = arg; long off = 0; char line[1100];
Expand Down Expand Up @@ -257,8 +259,25 @@ static void *ctl_main(void *arg) {
for (int i = 0; i <= n; i++) { dm_touch t = {0, x0 + (x1 - x0) * (float)i / (float)n, y0 + (y1 - y0) * (float)i / (float)n}; dm_touch_script(&t, 1); usleep((useconds_t)(s * 1e6f / (float)n)); }
dm_touch_script(NULL, 0); continue;
}
key_step st = {0, 0.15, 0}; char *h = strchr(line, '~'); if (h) { *h = 0; st.hold = atof(h + 1); }
parse_keys(line, &st);
int pn = 0, both = 0; char *keys = line; // "p<n>:<keys>": player n's controller (connected from its first press on), for scripted runs of local multiplayer
if (line[0] == 'p' && line[1] >= '2' && line[1] <= '8' && line[2] == ':') { pn = line[1] - '1'; keys = line + 3; }
else if (!strncmp(line, "both:", 5)) { both = 1; keys = line + 5; } // players 1 and 2 at the same time (a press held on one pad blocks this thread, so two lines never overlap)
key_step st = {0, 0.15, 0}; char *h = strchr(keys, '~'); if (h) { *h = 0; st.hold = atof(h + 1); }
parse_keys(keys, &st);
if (both) {
void dm_ctl_connect_player(int p); dm_ctl_connect_player(1);
LOG("DM_CTL: players 1+2 press %#llx (hold %.2f s)", (unsigned long long)st.btn, st.hold);
script_set(st.btn, st.lx, st.ly, st.rx, st.ry); dm_pad_set_player(1, st.btn, st.lx, st.ly, st.rx, st.ry);
usleep((useconds_t)(st.hold * 1e6));
script_set(0, 0, 0, 0, 0); dm_pad_set_player(1, 0, 0, 0, 0, 0);
continue;
}
if (pn) {
void dm_ctl_connect_player(int p); dm_ctl_connect_player(pn);
LOG("DM_CTL: player %d press %#llx (hold %.2f s)", pn + 1, (unsigned long long)st.btn, st.hold);
dm_pad_set_player(pn, st.btn, st.lx, st.ly, st.rx, st.ry); usleep((useconds_t)(st.hold * 1e6)); dm_pad_set_player(pn, 0, 0, 0, 0, 0);
continue;
}
LOG("DM_CTL: press %#llx (hold %.2f s)", (unsigned long long)st.btn, st.hold);
if (st.tap) { dm_touch t = {0, st.tx, st.ty}; dm_touch_script(&t, 1); }
script_set(st.btn, st.lx, st.ly, st.rx, st.ry); usleep((useconds_t)(st.hold * 1e6)); script_set(0, 0, 0, 0, 0);
Expand Down Expand Up @@ -315,8 +334,10 @@ static void note_merged(void) { // logs the players whose npad the game does n
else LOG("hid: player %d's controller is not used: the game supports no npad %d", p + 1, p);
}
}
static _Atomic uint32_t g_ctl_players, g_front_players = 1; // players DM_CTL connected ("p2:…"), on top of the front end's controllers
void dm_pad_players(uint32_t mask) {
mask = (mask | 1u) & ((1u << DM_PLAYERS) - 1);
atomic_store(&g_front_players, mask);
mask = (mask | 1u | atomic_load(&g_ctl_players)) & ((1u << DM_PLAYERS) - 1);
uint32_t old = atomic_exchange(&g_players, mask);
for (int p = 1; p < DM_PLAYERS; p++) if ((old ^ mask) >> p & 1) {
if (!(mask >> p & 1)) dm_pad_set_player(p, 0, 0, 0, 0, 0); // a controller that went away leaves nothing pressed
Expand All @@ -325,6 +346,12 @@ void dm_pad_players(uint32_t mask) {
note_merged();
}

void dm_ctl_connect_player(int p) {
if (p <= 0 || p >= DM_PLAYERS || atomic_fetch_or(&g_ctl_players, 1u << p) >> p & 1) return;
LOG("DM_CTL: player %d's controller connected (a full key controller on No%d)", p + 1, p + 1);
dm_pad_players(atomic_load(&g_front_players));
}

// DM_REC=<file>: player 1's physical input (keyboard / touch, its controller and the controllers merged into it, as fill reads them) written as DM_KEYS steps, so a run plays again
// with DM_KEYS=@<file> from the same save and build: a bug report's path without the game's data, or a regress route recorded instead of written. DM_KEYS and DM_CTL have
// paths of their own (script_set, dm_touch_script) and are never recorded. Each step is one state of player 1, from the presented frame it began to the frame it ended:
Expand Down Expand Up @@ -869,6 +896,8 @@ TOUCH(1) TOUCH(2) TOUCH(3) TOUCH(4) TOUCH(5) TOUCH(6) TOUCH(7) TOUCH(8) TOUCH(9)
// Gestures: recognized from the same touch points (hle_touch.c gesture_fill), so only in handheld mode too
int gesture_fill(void *out, int n, uint64_t now_ns);
HLE_FORCE("_ZN2nn3hid17InitializeGestureEv", "connect to the hid gesture recognizer; the host recognizes gestures from the touch points", void, h_hid_InitGesture, void) {}
// The two-argument version of newer SDKs (PRAGMATA, SDK 20), as InitializeTouchScreen(int, int): unhooked, the sdk connects to the hid service, which the host does not serve (sm 0xe15 abort)
HLE_FORCE("_ZN2nn3hid17InitializeGestureEii", "connect to the hid gesture recognizer (two-argument version); the host recognizes gestures from the touch points", void, h_hid_InitGesture2, int a, int b) { (void)a; (void)b; }
HLE_FORCE("_ZN2nn3hid16GetGestureStatesEPNS0_12GestureStateEi", "gesture states, newest first (handheld mode: recognized from the touch points; console mode: none)", int, h_hid_Gestures, void *out, int n) {
keys_sync();
return dm_opmode() == 0 ? gesture_fill(out, n, now_ns()) : 0;
Expand Down
Loading