14 Commits
Author SHA1 Message Date
jhaizhou-opsandClaude Opus 5.5 f150c91446 Merge main (#284 #287) into fragment-subgroup-inline-order
Conflict at the gfx-inline default: #287 counts 6xx / 735 by name or device ID and retries old skips; this branch adds Qualcomm
drivers without fragment-stage subgroups. Both are kept: xbg_adreno_inline_default takes the device ID, and
xbg_adreno_inline_is_new also treats Qualcomm drivers without fragment subgroups (outside 750-799) as newly inlined, so their old
skip entries get the one retry. The test "650 with fragment subgroups is not inlined" now expects inlining, since #287 inlines
all 6xx.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 06:15:35 -08:00
Yuechuan YangandClaude Opus 5.5 9803dd3179 Adreno 6xx: inline subgroup helpers by default; retry skips recorded without inlining (#266)
On a Galaxy Z Fold 3 (Adreno 660) the fluid shader 098a126f92bf533a is
in gfx-pipe-skip with inlining off (it crashed the compiler on earlier
boots), and fire and smoke show white / coloured squares (#266, #265).
On an Adreno 650 it compiles once inlined (#243).

- xbg_adreno_compiler_needs_inline covers the 6xx.
- gfx-pipe-skip entries recorded with inlining on end in " i". Where
  inlining is newly on (6xx and 735 defaults, or the gfx-inline
  marker), an entry without " i" is dropped once and rebuilt inlined;
  if it still crashes it is recorded with " i" and stays skipped. The
  750-799, inlined since v2.0.2, do not retry.

Redmi (Adreno 730) with gfx-inline 1: an untagged 098a entry was
retried and the shader loaded inlined; a tagged one stayed skipped.
Policy test extended. Not tested on a 6xx.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 01:22:11 +13:00
Yuechuan YangandClaude Opus 5.5 e4a05f3057 Adreno: switch the rewrites off for the 720 only, not the whole 0x43 generation
The 735 of the same generation ran fine with the quad-derivative and
warp32 rewrites on once its helpers were inlined (#169), and turning
them off would lose their fixes there (warp32 keeps the grass, clutter
and fluid appends correct; the quad rewrite prevents black squares).
The 720 crash (#263) is the only evidence, so xbg_adreno_rewrites_fault
covers the 740-799 models plus the 720, and the device-ID rule is
dropped. The 735 keeps its inlining.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 21:05:13 +13:00
Yuechuan YangandClaude Opus 5.5 21c425f05b Adreno: recognise the 740/750 chip family by device ID (720, 735) (#263, #169)
The rewrite and inlining defaults keyed on the model number (740-799,
750-799). Device IDs show the 720 (0x43020000) and 735 (0x43030b00) are
the same chip family as the 750 (0x43051401), while the 730 (0x07...)
and 830 (0x44...) are not. The 720 ran both rewrites and lost the
device on the main menu's first frame (#263, the 740's symptom in
#141); the 735 needed the 750's inlining (#169).

- xbg_adreno_rewrites_fault takes the device ID: Qualcomm chips with
  0x43 in the top byte default the quad-derivative and warp32 rewrites
  off.
- xbg_adreno_compiler_needs_inline includes the 735.
- The start-up line names the device ID.

Policy test: 9 new cases. Redmi (Adreno 730): unchanged. Not tested on
a 720 or 735.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 20:01:36 +13:00
Yuechuan YangandClaude Opus 5.5 c8ac3c2437 Vulkan: rewrite fragment shuffles before inlining on drivers without fragment subgroups (#243)
Found by @kieusonlam on a real Adreno 650 (Retroid Pocket 5): with
gfx-inline=1 the helpers were inlined before the quad rewrite, so the
shuffles sat in the entry function under divergent control flow, none
were rewritten and the capability check aborted; with gfx-inline=0
the fluid compute shader 098a126f92bf533a crashed libllvm-qgl.so
(addr 0x48), the Adreno 750 family's compiler crash.

- front_rewrites: without fragment subgroups the quad rewrite and
  clean-up run before the inlining (both loaders); with them the order
  is unchanged.
- xbg_adreno_inline_default: inlining is on by default for the 750-799
  family and for Qualcomm drivers without fragment subgroups; the
  gfx-inline marker still wins.

Offline the Adreno 650 chain passes the check for all 6,931 shaders and
spirv-val for all 187 modules with subgroup use. Redmi (Adreno 730)
with the fake switch: inlining on, fragment shaders rewritten first,
compute shaders inlined, camp clean, same picture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 08:34:13 +13:00
jhaizhou-ops 82ca0e15ac Merge pull request #280 from jhaizhou-ops/subgroup-check-after-rewrite
Vulkan: rewrite fragment shuffles when the driver has no fragment-stage subgroups (Adreno 650 / Maleoon 910 crash, #243 #155)
2026-11-16 01:16:30 -08:00
jhaizhou-ops 92f6569556 Merge pull request #279 from jhaizhou-ops/vulkan-d24-fallback
Vulkan: store 24-bit depth as 32-bit float when the driver has no D24 formats (Xclipse crash, #250)
2026-11-16 01:16:23 -08:00
Yuechuan YangandClaude Opus 5.5 c0e1f065c9 Vulkan: rewrite fragment shuffles when the driver has no fragment-stage subgroups (#243, #155)
Old Adreno 650 drivers and the Maleoon 910 support subgroup operations
in compute shaders only (supportedStages 0x20). 182 of D2R's fragment
shaders hold one shuffle (the translator's SHFL.BFLY helper), so the
capability check aborted at the main menu. The analysis is
@kieusonlam's (#155).

- The runtime loader checks capabilities after the rewrites, not
  before, and accepts DerivativeControl.
- On such drivers the quad rewrite always runs, in a relaxed mode that
  also rewrites calls whose result has bit uses or whose value comes
  from float arithmetic/loads (as floats) or from float-to-integer
  conversions (exact integer path); divergent control flow and other
  sources stay skipped.
- xbg_spirv_strip_subgroup then removes the helper nobody calls, the
  unused subgroup built-ins and the GroupNonUniform capabilities
  (self-contained, so the HarmonyOS build has it too).
- Marker gfx-no-fragment-subgroups / DM_GFX_NO_FRAGMENT_SUBGROUPS fakes
  such a driver for testing.

Offline over the import pack: all 182 shaders end without subgroup
use and pass spirv-val; the default mode's output is byte-identical to
main's; the moved check passes all 6,931 shaders for every phone
family's rewrite chain. Redmi (Adreno 730) with the fake driver: camp
and Den of Evil run, same picture. Not tested on an Adreno 650 or
Maleoon 910.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 10:39:44 +13:00
Yuechuan YangandClaude Opus 5.5 d2a7e4c4e7 Notes: Xclipse shadows will be point-sampled; keep #250 open until shadows are checked
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 09:11:36 +13:00
Yuechuan YangandClaude Opus 5.5 1c3d2c3d83 Vulkan: store 24-bit depth as 32-bit float when the driver has no D24 formats (#250)
Samsung Xclipse drivers (AMD RDNA) offer neither D24_UNORM_S8_UINT nor
X8_D24_UNORM_PACK32, so creating the game's first Z24S8 depth target
failed with VK_ERROR_FORMAT_NOT_SUPPORTED and the engine aborted.

- choose_depth_storage (before the warm-up threads start): when either
  D24 format lacks depth-stencil attachment, sampled or transfer
  features and D32F / D32FS8 have them, NVN Z24X8 / Z24S8 are stored as
  D32_SFLOAT / D32_SFLOAT_S8_UINT. Marker gfx-depth24-float (1/0) or
  DM_GFX_DEPTH24_FLOAT forces it.
- Uploads and readbacks convert 24-bit unorm <-> float per pixel
  (xbg_depth.c; exact round trip for all 2^24 values, unit test
  tests/depth24_float_test.c).
- Warm-up records get the same render pass format remap, so seed
  records made on other phones still match (log: depth24-remapped=N).
- The first biased draws on a stand-in are logged, since a float depth
  buffer's constant bias unit depends on the depth's exponent.

Tested on the Redmi K50 Ultra (Adreno 730) with the fallback forced on:
camp runs, 392 warm records built, 267 remapped, 178 warm hits and 0
draw-time pipeline creates in both runs, same picture apart from
animated content. Not tested on an Xclipse phone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 08:50:34 +13:00
Yuechuan YangandClaude Opus 5.5 fe4a65fd8d Adreno 8xx: compute shaders return at once outside the dispatched range (#256)
On the Adreno 830 a compute dispatch with local size exactly 8x4x1 and an odd
y group count runs one extra row of work groups. The game's per-tile
light-list shader is 8x4x1, dispatched (4,5,1) over 32x20 tiles; the extra
invocations write as tile rows 20-23, which are the second-layer lists of
rows 0-3, so the top-right tiles get other tiles' lights and flicker.

When a compute module loads, the engine now puts a dispatch-range check
first in its entry function. It compares work group id x local size + local
id with number of work groups x local size: the 830's compiler removes a
comparison of the local id with the literal size, and in this shader the
extra invocations have an in-range work group id and an out-of-range local
id. On by default on Adreno 8xx, marker gfx-dispatch-guard (1 / 0).

Tested on a OnePlus 13 (Adreno 830): the light-list shader alone on
captured inputs is right in 40 of 40 runs (0 of 5 without the check), and
in game the River of Flame rectangles are gone. The risk that a later
driver removes the position comparison too is written in the code and in
docs/android-notes/2026-11-13-adreno-830-dispatch-guard.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 09:30:56 +13:00
jhaizhou-opsandClaude Opus 5.5 2428e5b3af Adreno 750: inline shader helpers at load; the pipeline guard covers graphics pipelines (#123, #153, #166)
The Adreno 750 shader compiler (libllvm-qgl.so) segfaults (addr=0x48) building any pipeline whose shader has subgroup
instructions inside a called helper function: 098a and 6a7a (compute) and 358197ac, 5c1ca4e7, e1c00b41 and others (pixel)
on four Samsung / Xiaomi phones. v2.0.1 skipped only 098a.

- Engine: on Qualcomm Adreno 750-799, a shader of that shape (187 in the pack) has its helpers inlined at load with the
  SPIRV-Tools passes merge-return, inline-entry-points-exhaustive and eliminate-dead-functions (marker gfx-inline 1 / 0).
  The import pack is unchanged; only the APK is updated. The warm-up's inlined SPIR-V is reused on the graphics thread.
- dm/third_party/spirv-tools: SPIRV-Tools v2026.3 library sources, pre-generated tables and the SPIR-V headers it includes,
  built into the Android package only, without debug info. DM_VK_INLINE_CS is removed.
- pipeguard: every pipeline-building thread (graphics, warm-up, async) marks its build in gfx-pipe-inflight.<slot>; an
  entry in flight on two boots in a row goes into gfx-pipe-skip (c:<key> for compute, g:<stage keys> for graphics); a
  graphics pipeline error is skipped instead of fatal. v2.0.1's unprefixed entries and its hard 098a skip are dropped.
- Android: graphics log lines go to the dm tag and the log file; crash lines print library+offset for symbol-less libraries.

Verified on Adreno 830 (vivo) with a v2.0.1 import pack: default unchanged, forced inlining in game with the same picture,
guard record / skip / restore / old entries. See docs/android-notes/2026-10-27-adreno-750-inline.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 18:40:19 +08:00
vickFunWorld 24616499a8 Android: Adreno 740/750 default the quad and warp32 rewrites off (#148)
The two Adreno shader rewrites were written for the Adreno 730 and run there
and on the Adreno 830. On Adreno 740 (Snapdragon 8 Gen 2) the newer driver
accepts the rewritten SPIR-V and then faults: dmesg has "gpu timeout" and
kgsl status 00EF1087, the driver drops the device, and the next submit fails
with VK_ERROR_DEVICE_LOST (#141). On Adreno 750 (8 Gen 3) the submission never
finishes; the async command pool reset waits 10 s, gets VK_TIMEOUT, and the
slot reuse aborts with "s.reset_result failed: 2" (Redmi K70 Pro report,
#123 and the other 8 Gen 3 issues).

xbg_adreno_policy.h decides by device family: Qualcomm, model 740-799. A
marker file still wins, so either rewrite can be forced back on for a test;
the JNI's DM_GFX_* values no longer override the device default. Adreno 730,
Adreno 830 and other vendors are unchanged, and existing import packs work
without a rebuild.

The pool-reset wait now logs the GPU hang and the fatal message names it,
instead of leaving a bare "2" in the crash report.

With both rewrites off, #141 ran 27,900+ frames at a 16.63 ms p50 on an
iQOO 11 with the same import pack. This build has not run on an 8 Gen 2 or
8 Gen 3 phone yet; the PR is a draft until it does.

Refs #141, #123, #137, #138, #139, #142, #143
2026-10-26 21:09:08 +08:00
b811b90172 v2.0: Android and HarmonyOS ports, Korean, iPhone Duo, Xbox controller layout, separate game packages, Mac icon and pointer
- Android (#113, @yyan160; graphics engine and shader-bundle packer from @biglawine's HarmonyOS port): an
  Android app (dm/android) with a JNI host, a touch overlay on the shared touch state machine, Vulkan
  presentation and AAudio sound; an NVN-to-Vulkan replay engine (dm/gfx/vulkan) behind the same backend
  interface as Metal; the shared host now builds for Apple and Android, and the module rewriter has an
  Android target (DM_TARGET=android; Apple output unchanged). Measured by the authors at a median 60 fps on
  a Redmi K50 Ultra.
- Android install with your own game files: the release APK (dm/android/tools/shell_apk.sh) contains no game
  content; dm/tools/d2rm_android.py makes an import pack (rewritten program, Vulkan shader bundles, touch overlay,
  data tables) that the App imports from Download/S2X/D2R Mobile/android with a progress screen. The shader export
  step (dm/gfx/tools/dmsh_vk.py) makes the 6,927 game shader bundles byte-for-byte identical to the tested set.
- Android rewriter fix (#113, @yyan160): rewrite blocks no longer stash registers below sp (Android has no red
  zone); equiv.py checks Android outputs, structck.py recognizes the Android block shapes. Apple output unchanged.
- Android touch controls drawn as on iOS (sockets, silver skill silhouettes, joystick), no map key in game state,
  no virtual pad buttons over panels; dm/android/tools/art_compare.sh compares the two drawings pixel by pixel.
- HarmonyOS (#114, @biglawine): a HarmonyOS NEXT app (dm/harmony, ArkTS shell + N-API library) on the same shared host
  and Vulkan engine as Android; shared changes are behind __OHOS__ or opt-in switches (adaptive present tier, fence waits
  woken on completion, OHAudio, HiTrace markers, a byte-identical BC fast path).
- HarmonyOS install with your own game files (@biglawine, 0.19.4 / code122): the release HAP is unsigned and contains
  no game content; players re-sign it with their own debug certificate and import a pack made with
  dm/tools/d2rm_android.py --target ohos. The registering stand-ins read the tables only when dm_derived_reload() is
  called (on __OHOS__); first import creates the target folders; outside a game a map toggle request is dropped
  before the AutoMap exists. Run by the author on a Mate 90 Pro Max: re-sign, install, import, in game, save and exit.
- Vulkan: NaN-ignoring min / max / clamp as on Maxwell (#113, @yyan160), fixing one-frame black tiles on the OnePlus 13.
- Xbox controllers (from #110, @rrroy5640): recognized automatically and given the PC / Xbox layout (bottom
  confirms, right goes back) with the game's Xbox button icons; other controllers are unchanged. The Mac-only
  keyboard prompt switch became a three-way prompt style (Switch / keyboard / Xbox) on every platform.
- Separate base and update packages (#106, @PowerBeef): setup.sh and extract_game.sh take both packages and
  read the title keys from their tickets.
- Mac App (#108, #109, @PowerBeef): the project's icon by default; the pointer hides after resting 3 s.
- run.sh install no longer goes through the test-device battery gate (#107, @PowerBeef).
- Chinese wording (#101, @zzz6519003): 「旧接口版」 and 「默认构建」 throughout.
- Dynamic 3D resolution (from #113): a run of dropped frames counts only its first 3 frames unless it lasts
  1 s, so one-off stalls no longer lower the resolution.
- In-game Korean (#118, @soulsakura): a 한국어 column for all our UI text, a fifth option in the language row (each
  checkbox now sits before its name), Korean touch wording and map name plates, Korean voice when the game files
  carry it; a Korean system language picks Korean on first install.
- iPhone Duo: in full screen the output size follows the window when the phone is unfolded or folded, up to the
  size the game started with; needs Xcode 27.1 for the inner screen to be filled. Test switches DM_TEST_FOLD and
  DM_TEST_SCREEN simulate the two screens with the iOS package on a Mac.
- README: Android and HarmonyOS sections, device table and credits in all three languages; dependency list for Android.

Every change was ported into the internal tree with its authors credited. For the shared files, the code
changes match the pull requests' after stripping comments. Host / graphics / iOS unit tests, the full
acceptance gate and the Mac smoke test passed; the rewriter's rule sets were rebuilt and passed the
equivalence regression; an iOS build of this code was played on an iPhone; the Android APK with an import pack
made from our own game files was played on a vivo X200 Ultra.

Exported from main 8055e5212.

Co-authored-by: Yuechuan Yang <22333122+yyan160@users.noreply.github.com>
Co-authored-by: biglawine <26263820+biglawine@users.noreply.github.com>
Co-authored-by: rrroy <hly5640@gmail.com>
Co-authored-by: Patrice Déry <109446870+PowerBeef@users.noreply.github.com>
Co-authored-by: Sam Snowman(赵正中) <zhengzhongzhao@gmail.com>
Co-authored-by: soulsakura <74704744+soulsakura@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 09:21:08 +08:00