diff --git a/dm/README.md b/dm/README.md index d3dc9f6..2562e1f 100644 --- a/dm/README.md +++ b/dm/README.md @@ -75,6 +75,10 @@ The game draws with NVN (the Switch graphics interface). `main` imports only one The App compiles the sources of `host/` and `gfx/` in directly. The front-end interface `host/front.h` is implemented on the Mac by `host/front_mac.m` and on iOS by `ios/Sources/front_ios.m`. The rewritten module images are turned into embedded assembly by `ios/tools/gen_embed.py` and compiled into the executable; the iOS branch of `loader.c` does not copy code, it only maps these blocks back at their original relative positions. Touch controls and the user interface are also in `ios/`. See [ios/README.md](ios/README.md) for details. +### 6. Android shell (`android/`, Adreno devices only) + +The same `host/` and `gfx/` sources are built with the NDK into `libd2r.so`, loaded by a GameActivity; the front-end interface is implemented by `android/Sources/front_app.c`, and the touch HUD is in `android/Sources/touch_app.c`. Graphics replay switches to Vulkan: `gfx/vulkan/nvn_vk.c` consumes the same commands recorded by `hle_nvn.c`. Differences in system interfaces are filled in by `host/compat/linux/`. See [android/README.md](android/README.md) for details. + ## Directories | Location | Contents | @@ -82,8 +86,9 @@ The App compiles the sources of `host/` and `gfx/` in directly. The front-end in | `PRODUCT` | The codename of the current rewrite build output, one line | | `tools/` | The rewriter `patch_nso.py`, the build output script `product.sh`, `dmx.py` for reading the game's resource storage, `casc_overlay.py` for rewriting the resource storage at build time, and a batch of code-reading and analysis scripts | | `host/` | The host: loading, system call and system library takeover, the Mac front end, in-game features; `host/tests/` holds the unit tests | -| `gfx/` | The graphics layer: `nvn/` (interface layer and Metal replay), `tex/` (texture formats and deswizzling), `tools/` (shader translation chain), `tests/` | +| `gfx/` | The graphics layer: `nvn/` (interface layer and Metal replay), `vulkan/` (Vulkan replay for Android), `tex/` (texture formats and deswizzling), `tools/` (shader translation chain), `tests/` | | `ios/` | The iOS App: `Sources/`, the project description `project.yml`, the build-and-install script `run.sh`, `tools/` (asset generation, smoke tests, UI regression), `tests/` | +| `android/` | The Android App: `app/` (GameActivity, `res/`, packaging script), `Sources/` (front end and touch HUD), the build entry point `Makefile`, `tests/` | | `verify/` | Verification: the rewrite-equivalence regression `regress.sh`, the full acceptance run `accept.sh`, and the scripts and format descriptions its items use | | `data/` | Small data shipped with the repository: the registry of borrowed paths for the resource overlay. The startup prefetch list is not in the public repository: without it there is no prefetch, and startup skips one step of decoding ahead of time | | `i18n/` | The Chinese-English string table `ui_text.tsv`; `scan_literals.py` checks that all Chinese text the player can see goes through this table, with exceptions registered in `literal_whitelist.tsv` | @@ -128,6 +133,8 @@ Usage is `dmhost [module…] [-- game arguments…]`. ` **Unit tests**: `make -C dm/host/tests run`, `make -C dm/gfx/tests run`, `make -C dm/ios/tests test`. +**Build the Android package**: `make -C dm/android -j8` (output `dm/android/build/app/d2r.apk`); `make -C dm/android install` installs it onto the phone connected over adb. + **Build the iOS package**: `cd dm/ios && ./run.sh build`; to install on a device use `./run.sh install`. For signing configuration see the top-level README. **Full acceptance run**: `dm/verify/accept.sh [--fast|--full]` runs rewrite equivalence, save-file comparison, the screenshot gate, unit tests, the iOS build, functional cases and more together. Besides the game files it also needs reference run data and standard save files, which are not provided with the repository; the emulator driver scripts used to obtain the reference run data are not shipped either, so the full acceptance run cannot be run with this repository alone. diff --git a/dm/README.zh-CN.md b/dm/README.zh-CN.md index 746f26f..9dda7ca 100644 --- a/dm/README.zh-CN.md +++ b/dm/README.zh-CN.md @@ -75,6 +75,10 @@ English: [README.md](README.md) App 把 `host/` 与 `gfx/` 的源码直接编进去,前端接口 `host/front.h` 在 Mac 上由 `host/front_mac.m` 实现、在 iOS 上由 `ios/Sources/front_ios.m` 实现。改写后的模块映像由 `ios/tools/gen_embed.py` 生成内嵌汇编,编进可执行文件;`loader.c` 的 iOS 分支不拷贝代码,只把这几块按原来的相对位置映射回去。触摸操作与界面也在 `ios/` 里。细节见 [ios/README.zh-CN.md](ios/README.zh-CN.md)。 +### 6. Android 外壳(`android/`,仅 Adreno 机型) + +同一套 `host/` 与 `gfx/` 源码用 NDK 编成 `libd2r.so`,由 GameActivity 加载;前端接口由 `android/Sources/front_app.c` 实现,触屏 HUD 在 `android/Sources/touch_app.c`。图形回放换成 Vulkan:`gfx/vulkan/nvn_vk.c` 接 `hle_nvn.c` 录下的同一份命令。系统接口的差异由 `host/compat/linux/` 补齐。细节见 [android/README.zh-CN.md](android/README.zh-CN.md)。 + ## 目录 | 位置 | 内容 | @@ -82,8 +86,9 @@ App 把 `host/` 与 `gfx/` 的源码直接编进去,前端接口 `host/front.h | `PRODUCT` | 当前改写产物的代号,一行 | | `tools/` | 改写器 `patch_nso.py`、产物脚本 `product.sh`、读游戏资源存储的 `dmx.py`、构建期改写资源存储的 `casc_overlay.py`,以及一批读码与分析脚本 | | `host/` | 宿主:装载、系统调用与系统库接管、Mac 前端、游戏内功能;`host/tests/` 是单元测试 | -| `gfx/` | 图形层:`nvn/`(接口层与 Metal 回放)、`tex/`(贴图格式与解排布)、`tools/`(着色器翻译链)、`tests/` | +| `gfx/` | 图形层:`nvn/`(接口层与 Metal 回放)、`vulkan/`(Android 的 Vulkan 回放)、`tex/`(贴图格式与解排布)、`tools/`(着色器翻译链)、`tests/` | | `ios/` | iOS App:`Sources/`、工程描述 `project.yml`、出包与装机脚本 `run.sh`、`tools/`(资源生成、冒烟、界面回归)、`tests/` | +| `android/` | Android App:`app/`(GameActivity、`res/`、出包脚本)、`Sources/`(前端与触屏 HUD)、构建入口 `Makefile`、`tests/` | | `verify/` | 验证:改写等价回归 `regress.sh`、整套验收 `accept.sh` 及其各项用到的脚本与格式说明 | | `data/` | 随仓库的小数据:资源覆盖层的借用路径登记表。启动预取清单公开仓库不带:缺了就不预取,启动时少一步提前解码 | | `i18n/` | 中英文案表 `ui_text.tsv`;`scan_literals.py` 检查玩家看得到的中文都进了这张表,例外登记在 `literal_whitelist.tsv` | @@ -128,6 +133,8 @@ DM_ROMFS= DM_SAVE=<存档目录> DM_TEMP=<临时目录> DM_ **单元测试**:`make -C dm/host/tests run`、`make -C dm/gfx/tests run`、`make -C dm/ios/tests test`。 +**出 Android 包**:`make -C dm/android -j8`(产物 `dm/android/build/app/d2r.apk`),`make -C dm/android install` 装到 adb 连着的手机。 + **出 iOS 包**:`cd dm/ios && ./run.sh build`,装到设备用 `./run.sh install`。签名配置见顶层 README。 **整套验收**:`dm/verify/accept.sh [--fast|--full]` 把改写等价、存档对拍、画面闸门、单测、iOS 构建、功能用例等并在一起跑。它除游戏文件外还要用到参照运行数据和标准存档,这些没有随仓库提供;取参照运行数据用的模拟器驱动脚本也不随仓库提供,所以整套验收在仓库外跑不了。 diff --git a/dm/android/.gitignore b/dm/android/.gitignore new file mode 100644 index 0000000..27acaab --- /dev/null +++ b/dm/android/.gitignore @@ -0,0 +1,2 @@ +# 构建产物、缓存、日志、游戏截图 | build outputs, caches, logs, game frame captures +build/ diff --git a/dm/android/Makefile b/dm/android/Makefile new file mode 100644 index 0000000..a6ea12e --- /dev/null +++ b/dm/android/Makefile @@ -0,0 +1,27 @@ +# Android 入口(仅 Adreno 机型)。规则在 build.mk,以 dm/host 为当前目录跑(宿主共用源码);产物在 build/(不进 git) +# make = make apk:libd2r.so + d2r.apk(不用 Gradle) +# make install 装到 adb 连着的手机(会结束正在运行的游戏) +# make headless 无头宿主 build/dmhost(adb shell 直接跑) +# make tests Vulkan 后端设备测试 build/tests/t_vk_perf +# 没有游戏文件生成的表头时:DM_GENH_DIR=<表头目录>;并行:-j8 +# Android entry point (Adreno devices only). The rules are in build.mk, run with dm/host as the current directory (shared host sources); outputs in build/ (not in git) +# make = make apk: libd2r.so + d2r.apk (no Gradle) +# make install install onto the phone connected over adb (ends a running game) +# make headless headless host build/dmhost (run directly from adb shell) +# make tests Vulkan backend device test build/tests/t_vk_perf +# Without the headers generated from game files: DM_GENH_DIR=
; parallel: -j8 +HOST := $(abspath ../host) +B := $(CURDIR)/build +apk: lib + sh app/build_apk.sh +lib: + $(MAKE) -C $(HOST) -f $(CURDIR)/build.mk APP=1 $(B)/app/libd2r.so +install: apk + adb install -r $(B)/app/d2r.apk +headless: + $(MAKE) -C $(HOST) -f $(CURDIR)/build.mk $(B)/dmhost +tests: + $(MAKE) -C tests +clean: + rm -rf $(B) +.PHONY: apk lib install headless tests clean diff --git a/dm/host/android/PERFORMANCE.md b/dm/android/PERFORMANCE.md similarity index 95% rename from dm/host/android/PERFORMANCE.md rename to dm/android/PERFORMANCE.md index 3150036..e2f2f8a 100644 --- a/dm/host/android/PERFORMANCE.md +++ b/dm/android/PERFORMANCE.md @@ -37,7 +37,7 @@ Changes: `BATCH_SLOTS` raised to 8; GPU timestamp queries report `gpu_ms` per in The scene now runs at about 8.4 FPS on this device (60 frames in ~7.1 s) and is GPU-bound: GPU time alone caps it near 12 FPS. `PASSPROF` shows one 1600×900 forward+ lighting pass (pixel shader `5c1ca4e7c3e4657c`, 385 draws) takes ~44 ms of ~87 ms per frame; `spirv-opt -O` made no difference. The 60 FPS target applies to Adreno 830-class devices, which still need re-measuring with this build. -更新(Redmi,Adreno 710):批次槽位改为 8,新增 GPU 时间戳 `gpu_ms`,着色器包使用 `SB_ALIGN=64` 后存储缓冲区按 64 字节对齐直接绑定,不再拷贝。角色选择每 60 帧从 18–35 秒降到约 7.1 秒,临时缓冲区创建从 8,309 降为 0;当前为 GPU 瓶颈(约 85 ms/帧,其中一个前向+光照 pass 约 44 ms)。60 FPS 目标需在 Adreno 830 上复测。Logs: `build-android/perf/redmi1.log`, `redmi8.log`–`redmi10.log`. +更新(Redmi,Adreno 710):批次槽位改为 8,新增 GPU 时间戳 `gpu_ms`,着色器包使用 `SB_ALIGN=64` 后存储缓冲区按 64 字节对齐直接绑定,不再拷贝。角色选择每 60 帧从 18–35 秒降到约 7.1 秒,临时缓冲区创建从 8,309 降为 0;当前为 GPU 瓶颈(约 85 ms/帧,其中一个前向+光照 pass 约 44 ms)。60 FPS 目标需在 Adreno 830 上复测。Logs: `dm/android/build/perf/redmi1.log`, `redmi8.log`–`redmi10.log`. Update (WaitEvent, Redmi): `WAIT_PROFILE` showed every CPU wait came from `OP_WAIT_EVENT` (~5.1 s per 60 frames, two per frame); the host committed and CPU-waited for all prior GPU work although NVN's WaitEvent is a GPU-side wait, so CPU and GPU ran serially. Events already satisfied by queued signals now record only a barrier (`event_queued=120 event_blocked=0`). 60 frames: 7.7 s → 5.03–5.05 s (≈11.9 FPS), submits 4 → 2 per frame; elapsed now equals `gpu_ms`, so the scene is purely GPU-bound. The remaining `sync` wait (~2.6 s / 60, `sync_lag_max=5`) is the game's own one-frame-ahead throttle. Frame 841 matches the baseline. `DM_VK_EVENT_SYNC=1` restores the old path. Logs: `redmi18.log` (before), `redmi19.log` (after). @@ -64,4 +64,4 @@ Deferred commits, reusable fence slots (eight since the update above) and comple - Khronos validation could not be enabled on this retail device: the Android loader returned `VK_ERROR_LAYER_NOT_PRESENT`, and `/data/local/debug/vulkan` is not writable by shell. No validation-layer-clean claim is made. Android's loader discovery restrictions are described in [the Android Vulkan implementation documentation](https://source.android.com/docs/core/graphics/implement-vulkan). - Mac / iOS runtime, real-window WSI and AAudio were not exercised. The new QueueFlush declaration/call are guarded by `__ANDROID__`. -Reproduction commands and environment variables are in [README.md](README.md) / [README.zh-CN.md](README.zh-CN.md). Local evidence lives in ignored `dm/host/build-android/perf/`: `baseline.log`, `final.log`, `gpu-tests.log`, `cache-test.log`, and `final-0601.ppm` / `.png`. The device retains the original `dmhost`; the tested binary is `dmhost-perf-final` under `/data/local/tmp/d2r`. +Reproduction commands and environment variables are in [README.md](README.md) / [README.zh-CN.md](README.zh-CN.md). Local evidence lives in ignored `dm/android/build/perf/`: `baseline.log`, `final.log`, `gpu-tests.log`, `cache-test.log`, and `final-0601.ppm` / `.png`. The device retains the original `dmhost`; the tested binary is `dmhost-perf-final` under `/data/local/tmp/d2r`. diff --git a/dm/host/android/README.md b/dm/android/README.md similarity index 81% rename from dm/host/android/README.md rename to dm/android/README.md index c1df226..d95cc83 100644 --- a/dm/host/android/README.md +++ b/dm/android/README.md @@ -1,17 +1,27 @@ -# Android Vulkan headless backend +# Android shell (Adreno devices only) 中文: [README.zh-CN.md](README.zh-CN.md) -The backend retains the NVN recorder's `mtl_*` interface. Headless rendering is verified on OnePlus 13 / Adreno 830. A minimal GameActivity app (window, raw touch, gamepad, text input) is in `app/`; AAudio and the touch HUD remain subsequent work. +Layout (a sibling of `dm/ios/`): + +| Path | Contents | +|---|---| +| `app/` | The GameActivity app: `AndroidManifest.xml`, `java/`, `res/`, the packaging script `build_apk.sh`, `art_from_ipa.py` | +| `Sources/` | Front ends: `front_app.c` (app), `touch_app.c` (touch HUD), `front_headless.c` (adb headless host) | +| `Makefile`, `build.mk` | Build entry point and rules; the shared host sources come from `dm/host/`, outputs go to `build/` (not in git) | +| `tests/` | Vulkan backend device test `t_vk_perf` | +| `../gfx/vulkan/` | The Vulkan graphics backend `nvn_vk.c` (counterpart of the Metal backend `gfx/nvn/nvn_mtl.m`) | + +The backend (`gfx/vulkan/nvn_vk.c`) retains the NVN recorder's `mtl_*` interface. Headless rendering is verified on OnePlus 13 / Adreno 830. A minimal GameActivity app (window, raw touch, gamepad, text input) is in `app/`; AAudio and the touch HUD remain subsequent work. ## Build and test Run from the repository root with generated host headers and your own rewritten game files: ```sh -make -C dm/host -f Makefile.android -j8 -make -C dm/host/android/tests -adb push dm/host/build-android/tests/t_vk_perf /data/local/tmp/d2r/t_vk_perf +make -C dm/android headless -j8 # headless host dm/android/build/dmhost +make -C dm/android tests +adb push dm/android/build/tests/t_vk_perf /data/local/tmp/d2r/t_vk_perf adb shell /data/local/tmp/d2r/t_vk_perf ``` @@ -37,12 +47,11 @@ Following the [Vulkan cache header contract](https://docs.vulkan.org/spec/latest ## App (GameActivity) ```sh -make -C dm/host -f Makefile.android APP=1 -j8 build-android/app/libd2r.so -sh dm/host/android/app/build_apk.sh # -> dm/host/build-android/app/d2r.apk, no Gradle -adb install -r dm/host/build-android/app/d2r.apk +make -C dm/android -j8 # libd2r.so + dm/android/build/app/d2r.apk, no Gradle +make -C dm/android install # adb install -r (ends a running game) ``` -`APP=1` builds the host as `libd2r.so` with `app/front_app.c` in place of `front_headless.c`. `build_apk.sh` uses javac (Android Studio's JBR by default), d8, aapt2, zipalign and apksigner with the debug keystore. The app is debuggable so game data can be copied in with `run-as`: +`APP=1` builds the host as `libd2r.so` with `Sources/front_app.c` in place of `Sources/front_headless.c`. `build_apk.sh` uses javac (Android Studio's JBR by default), d8, aapt2, zipalign and apksigner with the debug keystore. The app is debuggable so game data can be copied in with `run-as`: ```sh adb shell run-as org.d2rmobile.app sh -c 'mkdir -p files/d2r && cp -r /data/local/tmp/d2r/dm /data/local/tmp/d2r/romfs /data/local/tmp/d2r/romfs_overlay /data/local/tmp/d2r/rt64 /data/local/tmp/d2r/save files/d2r/' @@ -66,4 +75,4 @@ The data root is `files/d2r` (`dm/main.patched.bin`, `romfs`, `rt64` required). `RENDER_PROFILE` counts actual Vulkan submissions including Present; the old counter excluded Present. `RENDER_CACHE_PROFILE` records cache reuse, pass count, pass breaks, transient buffer use and `gpu_ms` (GPU time of the interval from timestamp queries). `RENDER_INPUT_PROFILE` records uploads and shared GPU reads. `WAIT_PROFILE` splits CPU-side GPU wait time by origin (sync / event / present / slot / readtex / texrel / sampler / pooldel / finish / capture, as `ms/count`), plus `sync_lag_max` and `event_queued` / `event_blocked`. -See [PERFORMANCE.md](PERFORMANCE.md) for measurements and validation limits. Keep binaries, caches, logs and game screenshots under ignored `build-android/` or device test directories. +See [PERFORMANCE.md](PERFORMANCE.md) for measurements and validation limits. Keep binaries, caches, logs and game screenshots under ignored `dm/android/build/` or device test directories. diff --git a/dm/host/android/README.zh-CN.md b/dm/android/README.zh-CN.md similarity index 80% rename from dm/host/android/README.zh-CN.md rename to dm/android/README.zh-CN.md index 4723348..6ef896c 100644 --- a/dm/host/android/README.zh-CN.md +++ b/dm/android/README.zh-CN.md @@ -1,17 +1,27 @@ -# Android Vulkan 无头后端 +# Android 外壳(仅 Adreno 机型) English: [README.md](README.md) -`nvn_vk.c` 保留 NVN 记录器的 `mtl_*` 接口。目前在 OnePlus 13 / Adreno 830 上验证无头渲染。`app/` 是最小 GameActivity 应用(窗口、原始触摸、手柄、文字输入);AAudio 与触屏 HUD 是后续步骤。 +目录(与 `dm/ios/` 平级): + +| 位置 | 内容 | +|---|---| +| `app/` | GameActivity 应用:`AndroidManifest.xml`、`java/`、`res/`、出包脚本 `build_apk.sh`、`art_from_ipa.py` | +| `Sources/` | 前端:`front_app.c`(App)、`touch_app.c`(触屏 HUD)、`front_headless.c`(adb 无头宿主) | +| `Makefile`、`build.mk` | 构建入口与规则;宿主共用源码来自 `dm/host/`,产物在 `build/`(不入库) | +| `tests/` | Vulkan 后端设备测试 `t_vk_perf` | +| `../gfx/vulkan/` | Vulkan 图形后端 `nvn_vk.c`(与 Metal 后端 `gfx/nvn/nvn_mtl.m` 对应) | + +`gfx/vulkan/nvn_vk.c` 保留 NVN 记录器的 `mtl_*` 接口。目前在 OnePlus 13 / Adreno 830 上验证无头渲染。`app/` 是最小 GameActivity 应用(窗口、原始触摸、手柄、文字输入);AAudio 与触屏 HUD 是后续步骤。 ## 构建与回归 从仓库根目录运行,使用已生成的宿主表头与玩家自己的改写产物: ```sh -make -C dm/host -f Makefile.android -j8 -make -C dm/host/android/tests -adb push dm/host/build-android/tests/t_vk_perf /data/local/tmp/d2r/t_vk_perf +make -C dm/android headless -j8 # 无头宿主 dm/android/build/dmhost +make -C dm/android tests +adb push dm/android/build/tests/t_vk_perf /data/local/tmp/d2r/t_vk_perf adb shell /data/local/tmp/d2r/t_vk_perf ``` @@ -39,12 +49,11 @@ NDK 默认取 `ANDROID_NDK_HOME`,否则使用本机 Android SDK 中最新的 N ## App(GameActivity) ```sh -make -C dm/host -f Makefile.android APP=1 -j8 build-android/app/libd2r.so -sh dm/host/android/app/build_apk.sh # 输出 dm/host/build-android/app/d2r.apk,不用 Gradle -adb install -r dm/host/build-android/app/d2r.apk +make -C dm/android -j8 # libd2r.so + dm/android/build/app/d2r.apk,不用 Gradle +make -C dm/android install # adb install -r(会结束正在运行的游戏) ``` -`APP=1` 把宿主编成 `libd2r.so`,用 `app/front_app.c` 取代 `front_headless.c`。`build_apk.sh` 使用 javac(默认 Android Studio 自带 JBR)、d8、aapt2、zipalign 和 apksigner(debug keystore)。应用是 debuggable 的,游戏数据可以用 `run-as` 拷进去: +`APP=1` 把宿主编成 `libd2r.so`,用 `Sources/front_app.c` 取代 `Sources/front_headless.c`。`build_apk.sh` 使用 javac(默认 Android Studio 自带 JBR)、d8、aapt2、zipalign 和 apksigner(debug keystore)。应用是 debuggable 的,游戏数据可以用 `run-as` 拷进去: ```sh adb shell run-as org.d2rmobile.app sh -c 'mkdir -p files/d2r && cp -r /data/local/tmp/d2r/dm /data/local/tmp/d2r/romfs /data/local/tmp/d2r/romfs_overlay /data/local/tmp/d2r/rt64 /data/local/tmp/d2r/save files/d2r/' @@ -68,4 +77,4 @@ adb shell run-as org.d2rmobile.app cat files/d2r/run.log `RENDER_PROFILE` 计时并统计实际 Vulkan 提交(包括 Present);`RENDER_CACHE_PROFILE` 记录 pipeline 命中、pass / framebuffer 复用、pass 次数与打断次数、临时缓冲区用量,以及 `gpu_ms`(时间戳查询得到的区间 GPU 时间);`RENDER_INPUT_PROFILE` 记录上传和共享 GPU 输入;`WAIT_PROFILE` 按来源拆分 CPU 等待 GPU 的时间(sync / event / present / slot / readtex / texrel / sampler / pooldel / finish / capture,格式 `毫秒/次数`),并给出 `sync_lag_max` 与 `event_queued` / `event_blocked`。旧后端的提交统计不包含 Present,比较时需注意口径。 -2026-10-13 的实测和限制见 [PERFORMANCE.md](PERFORMANCE.md)。构建文件、缓存、日志、游戏截图均留在 `build-android/` 或设备测试目录,不入库。 +2026-10-13 的实测和限制见 [PERFORMANCE.md](PERFORMANCE.md)。构建文件、缓存、日志、游戏截图均留在 `dm/android/build/` 或设备测试目录,不入库。 diff --git a/dm/host/android/app/front_app.c b/dm/android/Sources/front_app.c similarity index 98% rename from dm/host/android/app/front_app.c rename to dm/android/Sources/front_app.c index 9efa048..d160a83 100644 --- a/dm/host/android/app/front_app.c +++ b/dm/android/Sources/front_app.c @@ -6,13 +6,13 @@ // The host starts from main() as usual (on a thread started over JNI); this file gives it the window, input, software keyboard and foreground / background switching. // Game data lives in the app's private directory files/d2r/ (dm/ modules, romfs/, romfs_overlay/, rt64/ shader pack, save/, temp/); // each KEY=VALUE line of files/d2r/env.txt is setenv'd before start (debug switches such as DM_VK_VRS=2x2). The log is written to files/d2r/run.log. -#include "../../dm.h" -#include "../../hle.h" -#include "../../front.h" -#include "../../dm_input.h" -#include "../../dm_padmap.h" -#include "../../dm_cursor.h" -#include "../vk_platform.h" +#include "../../host/dm.h" +#include "../../host/hle.h" +#include "../../host/front.h" +#include "../../host/dm_input.h" +#include "../../host/dm_padmap.h" +#include "../../host/dm_cursor.h" +#include "../../gfx/vulkan/vk_platform.h" #include #include #include diff --git a/dm/host/android/front_headless.c b/dm/android/Sources/front_headless.c similarity index 96% rename from dm/host/android/front_headless.c rename to dm/android/Sources/front_headless.c index 5ddf939..30d3507 100644 --- a/dm/host/android/front_headless.c +++ b/dm/android/Sources/front_headless.c @@ -1,7 +1,7 @@ // Android 无头前端(adb shell 直接跑 dmhost,先跑通引导链):无窗口、无输入框,客体在当前线程跑;GameActivity 前端接上后由它替换 // Android headless front end (run dmhost straight from adb shell to get the boot chain working first): no window, no input box, the guest runs on the current thread; replaced by the GameActivity front end once that is wired up -#include "../dm.h" -#include "../front.h" +#include "../../host/dm.h" +#include "../../host/front.h" // 客体在 64 MB 栈的线程里跑(与 iOS 壳的 boot_thread 一致;adb shell 主线程栈只有 8 MB) // The guest runs on a thread with a 64 MB stack (same as the iOS shell's boot_thread; the adb shell main thread has only 8 MB) static void *guest_thread(void *p) { ((void (*)(void))p)(); return NULL; } diff --git a/dm/host/android/app/touch_app.c b/dm/android/Sources/touch_app.c similarity index 99% rename from dm/host/android/app/touch_app.c rename to dm/android/Sources/touch_app.c index f6f304f..96b1f3b 100644 --- a/dm/host/android/app/touch_app.c +++ b/dm/android/Sources/touch_app.c @@ -9,20 +9,20 @@ // atomics that the UI-thread tick picks up (iOS uses dispatch_async to the main thread here). Drawing does not touch a Canvas: C emits a draw list // (float array + string table) that Java executes. // Not ported: Rift objective bar, the shelf-drag ghost image, scripted test touches, overlay capture. -#include "../../dm.h" -#include "../../front.h" -#include "../../hle.h" -#include "../../dm_input.h" -#include "../../dm_cursor.h" -#include "../../dm_hud.h" -#include "../../dm_world.h" -#include "../../dm_uiscreen.h" -#include "../../dm_actions.h" -#include "../../dm_i18n.h" -#include "../../dm_custom.h" -#include "../../../touch/dm_touch_controls.h" -#include "../../../touch/dm_touch_game_state.h" -#include "../../../touch/dm_touch_native_art.h" +#include "../../host/dm.h" +#include "../../host/front.h" +#include "../../host/hle.h" +#include "../../host/dm_input.h" +#include "../../host/dm_cursor.h" +#include "../../host/dm_hud.h" +#include "../../host/dm_world.h" +#include "../../host/dm_uiscreen.h" +#include "../../host/dm_actions.h" +#include "../../host/dm_i18n.h" +#include "../../host/dm_custom.h" +#include "../../touch/dm_touch_controls.h" +#include "../../touch/dm_touch_game_state.h" +#include "../../touch/dm_touch_native_art.h" #include #include #include diff --git a/dm/host/android/app/AndroidManifest.xml b/dm/android/app/AndroidManifest.xml similarity index 100% rename from dm/host/android/app/AndroidManifest.xml rename to dm/android/app/AndroidManifest.xml diff --git a/dm/host/android/app/art_from_ipa.py b/dm/android/app/art_from_ipa.py similarity index 100% rename from dm/host/android/app/art_from_ipa.py rename to dm/android/app/art_from_ipa.py diff --git a/dm/host/android/app/build_apk.sh b/dm/android/app/build_apk.sh similarity index 92% rename from dm/host/android/app/build_apk.sh rename to dm/android/app/build_apk.sh index 94179ec..8d4f316 100644 --- a/dm/host/android/app/build_apk.sh +++ b/dm/android/app/build_apk.sh @@ -1,12 +1,11 @@ #!/bin/sh -# Package build-android/app/libd2r.so + GameActivity into a debug-signed APK, without Gradle. -# make -f Makefile.android APP=1 build-android/app/libd2r.so && sh android/app/build_apk.sh +# Package build/app/libd2r.so + GameActivity into a debug-signed APK, without Gradle. +# make -C dm/android (= build libd2r.so, then this script) # Env: ANDROID_SDK (default ~/Library/Android/sdk), BUILD_TOOLS (35.0.0), PLATFORM (android-33), # JAVA_HOME (default: Android Studio's bundled JBR), KEYSTORE (default ~/.android/debug.keystore). set -eu here=$(cd "$(dirname "$0")" && pwd) -host=$(cd "$here/../.." && pwd) -out=$host/build-android/app +out=$(cd "$here/.." && pwd)/build/app sdk=${ANDROID_SDK:-$HOME/Library/Android/sdk} bt=$sdk/build-tools/${BUILD_TOOLS:-35.0.0} jar=$sdk/platforms/${PLATFORM:-android-33}/android.jar @@ -28,7 +27,7 @@ PATH="$jh/bin:$PATH" "$bt/d8" --release --min-api 29 --lib "$jar" --output "$w/d # 触屏 HUD 素材(从玩家自己的游戏文件生成,不进仓库):TouchArt/ = ios/tools/native_art/generate.py,hud_v4_ui/ = ios/tools/gen_hud_v4.py,mapgoal/ = ios/tools/gen_map_goal_art.py # Touch HUD assets (generated from the player's own game files, not in the repo): TouchArt/ = ios/tools/native_art/generate.py, hud_v4_ui/ = ios/tools/gen_hud_v4.py, mapgoal/ = ios/tools/gen_map_goal_art.py -ios=$host/../ios +ios=$(cd "$here/../../ios" && pwd) mkdir -p "$w/assets/TouchArt" cp "$ios"/Sources/TouchArt/*.png "$w/assets/TouchArt/" 2>/dev/null || echo "warning: no TouchArt pngs (run ios/tools/gen_assets.py)" >&2 if [ -d "$ios/Gen/assets/NativeHUD/v4/hud_v4_ui" ]; then cp -R "$ios/Gen/assets/NativeHUD/v4/hud_v4_ui" "$w/assets/" diff --git a/dm/host/android/app/java/org/d2rmobile/app/GameActivity.java b/dm/android/app/java/org/d2rmobile/app/GameActivity.java similarity index 100% rename from dm/host/android/app/java/org/d2rmobile/app/GameActivity.java rename to dm/android/app/java/org/d2rmobile/app/GameActivity.java diff --git a/dm/host/android/app/java/org/d2rmobile/app/TouchOverlay.java b/dm/android/app/java/org/d2rmobile/app/TouchOverlay.java similarity index 100% rename from dm/host/android/app/java/org/d2rmobile/app/TouchOverlay.java rename to dm/android/app/java/org/d2rmobile/app/TouchOverlay.java diff --git a/dm/host/android/app/res/mipmap-anydpi-v26/ic_launcher.xml b/dm/android/app/res/mipmap-anydpi-v26/ic_launcher.xml similarity index 100% rename from dm/host/android/app/res/mipmap-anydpi-v26/ic_launcher.xml rename to dm/android/app/res/mipmap-anydpi-v26/ic_launcher.xml diff --git a/dm/host/android/app/res/mipmap-xxhdpi/ic_launcher_fg.png b/dm/android/app/res/mipmap-xxhdpi/ic_launcher_fg.png similarity index 100% rename from dm/host/android/app/res/mipmap-xxhdpi/ic_launcher_fg.png rename to dm/android/app/res/mipmap-xxhdpi/ic_launcher_fg.png diff --git a/dm/host/android/app/res/mipmap-xxxhdpi/ic_launcher_fg.png b/dm/android/app/res/mipmap-xxxhdpi/ic_launcher_fg.png similarity index 100% rename from dm/host/android/app/res/mipmap-xxxhdpi/ic_launcher_fg.png rename to dm/android/app/res/mipmap-xxxhdpi/ic_launcher_fg.png diff --git a/dm/host/Makefile.android b/dm/android/build.mk similarity index 70% rename from dm/host/Makefile.android rename to dm/android/build.mk index c983bcb..fb6afd5 100644 --- a/dm/host/Makefile.android +++ b/dm/android/build.mk @@ -1,9 +1,12 @@ -# Android(arm64,仅 Adreno 机型)无头宿主:adb shell 直接跑,用来先把引导链跑通;图形 / 音频 / 前端后续接入 -# Android (arm64, Adreno devices only) headless host: run directly from adb shell to get the boot chain working first; graphics / audio / front end come later +# Android(arm64,仅 Adreno 机型)构建规则。由 dm/android/Makefile 以 dm/host 为当前目录调用(宿主共用源码按 host 的相对路径列),产物放 dm/android/build/ +# 缺省:无头宿主 dmhost(adb shell 直接跑);APP=1:libd2r.so 给 GameActivity 加载 +# Android (arm64, Adreno devices only) build rules. Invoked by dm/android/Makefile with dm/host as the current directory (the shared host sources are listed relative to host); outputs go to dm/android/build/ +# Default: the headless host dmhost (run directly from adb shell); APP=1: libd2r.so for GameActivity to load +ANDROID_DIR := $(abspath ../android) NDK ?= $(or $(ANDROID_NDK_HOME),$(lastword $(sort $(wildcard $(HOME)/Library/Android/sdk/ndk/*)))) API ?= 33 CC := $(wildcard $(NDK)/toolchains/llvm/prebuilt/*/bin)/aarch64-linux-android$(API)-clang -OUT ?= build-android +OUT ?= $(ANDROID_DIR)/build # 表头:没有游戏文件时可用 DM_GENH_DIR 指向现成的表头目录 | generated headers: without game files, DM_GENH_DIR can point at a directory of ready-made headers GENH_DIR ?= $(or $(DM_GENH_DIR),.) # -ffixed-x18:x18 是客体的平台寄存器,宿主代码不许碰;16K 页对齐(Android 15+ 16K 页设备);保留 __start_/__stop_ 段登记表 @@ -11,10 +14,10 @@ GENH_DIR ?= $(or $(DM_GENH_DIR),.) CFLAGS = -O1 -g -Wall -Wno-unused-function -Wno-format -ffixed-x18 -fPIE \ -include compat/linux/compat_linux.h -Icompat/linux/include -I. -I$(GENH_DIR) -I../gfx/nvn/include -I../gfx/nvn LDFLAGS = -pie -Wl,-z,max-page-size=16384 -Wl,-z,nostart-stop-gc -Wl,--export-dynamic -# APP=1:同一份源编成 libd2r.so 给 GameActivity 加载(android/app/),前端换成 front_app.c;APK 由 android/app/build_apk.sh 打 -# APP=1: build the same sources into libd2r.so for GameActivity to load (android/app/), with front_app.c as the front end; the APK is packed by android/app/build_apk.sh +# APP=1:同一份源编成 libd2r.so 给 GameActivity 加载(dm/android/app/),前端换成 Sources/front_app.c;APK 由 app/build_apk.sh 打 +# APP=1: build the same sources into libd2r.so for GameActivity to load (dm/android/app/), with Sources/front_app.c as the front end; the APK is packed by app/build_apk.sh ifeq ($(APP),1) -OUT := build-android/app +OUT := $(ANDROID_DIR)/build/app CFLAGS := $(subst -fPIE,-fPIC,$(CFLAGS)) LDFLAGS := -shared -Wl,-soname,libd2r.so -Wl,-Bsymbolic -Wl,--no-undefined -Wl,-z,max-page-size=16384 -Wl,-z,nostart-stop-gc endif @@ -23,12 +26,14 @@ LIBS = -llog -lm -ldl -lz -landroid -laaudio # Same source list as Makefile, minus the macOS-only ones (.m, touch_mac.c, front_mac.m, memstat.m) # Makefile 的 SRC 是续行写的(一行一个),读到第一条不带续行符的行为止 | Makefile's SRC uses continuation lines (one per line); read up to the first line without a continuation SRC_MAC := $(filter %.c,$(shell awk '/^SRC=/{f=1} f{l=$$0; sub(/^SRC=/,"",l); c=(l ~ /[\\\\]$$/); sub(/[\\\\]$$/,"",l); print l; if(!c) exit}' Makefile)) -SRC := $(filter-out touch_mac.c,$(SRC_MAC)) $(sort $(wildcard hle_*.c)) $(wildcard compat/linux/*.c) $(wildcard android/*.c) -ifeq ($(APP),1) -SRC := $(filter-out android/front_headless.c,$(SRC)) android/app/front_app.c android/app/touch_app.c \ +SRC := $(filter-out touch_mac.c,$(SRC_MAC)) $(sort $(wildcard hle_*.c)) $(wildcard compat/linux/*.c) +ifneq ($(APP),1) +SRC += ../android/Sources/front_headless.c +else +SRC += ../android/Sources/front_app.c ../android/Sources/touch_app.c \ ../touch/dm_touch_game_bridge.c ../touch/dm_touch_game_state.c ../touch/dm_touch_game_identity.c ../touch/dm_touch_native_art.c endif -GFX := $(sort $(wildcard ../gfx/*.c ../gfx/nvn/*.c ../gfx/tex/*.c)) +GFX := $(sort $(wildcard ../gfx/*.c ../gfx/nvn/*.c ../gfx/tex/*.c ../gfx/vulkan/*.c)) LIBDEFLATE := $(shell sed -n 's/^LIBDEFLATE=//p' Makefile) ASM := entry.S ../gfx/nvn/nvn_entry.S ../gfx/nvn/nvn_thunks.S OBJ := $(patsubst %.c,$(OUT)/obj/%.o,$(subst ../,up/,$(SRC) $(GFX) $(LIBDEFLATE))) \ @@ -39,9 +44,9 @@ $(OUT)/dmhost: $(OBJ) $(OUT)/libd2r.so: $(OBJ) $(CC) $(LDFLAGS) -Wl,--error-limit=0 -o $@ $^ $(LIBS) -# 图形回放(gfx/、android/)是逐绘制热路径,用 -O2;其余宿主代码保持 -O1,与 Mac 构建一致 -# Graphics replay (gfx/, android/) is the per-draw hot path, built at -O2; the rest of the host stays at -O1 like the Mac build -$(OUT)/obj/up/gfx/%.o $(OUT)/obj/android/%.o: CFLAGS += -O2 +# 图形回放(gfx/,含 Vulkan 后端 gfx/vulkan/)是逐绘制热路径,用 -O2;其余宿主代码保持 -O1,与 Mac 构建一致 +# Graphics replay (gfx/, including the Vulkan backend gfx/vulkan/) is the per-draw hot path, built at -O2; the rest of the host stays at -O1 like the Mac build +$(OUT)/obj/up/gfx/%.o: CFLAGS += -O2 $(OUT)/obj/up/%.o: ../%.c @mkdir -p $(dir $@) diff --git a/dm/host/android/tests/Makefile b/dm/android/tests/Makefile similarity index 70% rename from dm/host/android/tests/Makefile rename to dm/android/tests/Makefile index 0631654..18993cd 100644 --- a/dm/host/android/tests/Makefile +++ b/dm/android/tests/Makefile @@ -1,8 +1,8 @@ NDK ?= $(or $(ANDROID_NDK_HOME),$(lastword $(sort $(wildcard $(HOME)/Library/Android/sdk/ndk/*)))) CC := $(wildcard $(NDK)/toolchains/llvm/prebuilt/*/bin)/aarch64-linux-android33-clang -OUT ?= ../../build-android/tests -CFLAGS = -O1 -g -Wall -Wno-unused-function -ffunction-sections -fdata-sections -I../../../gfx/nvn -I../../../gfx/nvn/include -$(OUT)/t_vk_perf: t_vk_perf.c ../nvn_vk.c ../nvn_vk_dispatch.h +OUT ?= ../build/tests +CFLAGS = -O1 -g -Wall -Wno-unused-function -ffunction-sections -fdata-sections -I../../gfx/nvn -I../../gfx/nvn/include +$(OUT)/t_vk_perf: t_vk_perf.c ../../gfx/vulkan/nvn_vk.c ../../gfx/vulkan/nvn_vk_dispatch.h @mkdir -p $(OUT) $(CC) $(CFLAGS) -Wl,--gc-sections -Wl,-z,max-page-size=16384 $< -o $@ -landroid -ldl -lm -lz .PHONY: all diff --git a/dm/host/android/tests/t_vk_perf.c b/dm/android/tests/t_vk_perf.c similarity index 99% rename from dm/host/android/tests/t_vk_perf.c rename to dm/android/tests/t_vk_perf.c index d4271dc..dd5e0af 100644 --- a/dm/host/android/tests/t_vk_perf.c +++ b/dm/android/tests/t_vk_perf.c @@ -1,6 +1,6 @@ /* Runs real Vulkan buffer/fence regressions on an Android device. The include * exposes the backend's private cache/batch state without a production API. */ -#include "../nvn_vk.c" +#include "../../gfx/vulkan/nvn_vk.c" #include static void wait_current(void) { uint64_t ticket=mtl_sub_commit();assert(mtl_wait(ticket,UINT64_MAX)); } diff --git a/dm/host/android/nvn_vk.c b/dm/gfx/vulkan/nvn_vk.c similarity index 100% rename from dm/host/android/nvn_vk.c rename to dm/gfx/vulkan/nvn_vk.c diff --git a/dm/host/android/nvn_vk_dispatch.h b/dm/gfx/vulkan/nvn_vk_dispatch.h similarity index 100% rename from dm/host/android/nvn_vk_dispatch.h rename to dm/gfx/vulkan/nvn_vk_dispatch.h diff --git a/dm/host/android/nvn_vk_stats.c b/dm/gfx/vulkan/nvn_vk_stats.c similarity index 98% rename from dm/host/android/nvn_vk_stats.c rename to dm/gfx/vulkan/nvn_vk_stats.c index 146b6b6..3dbe5b0 100644 --- a/dm/host/android/nvn_vk_stats.c +++ b/dm/gfx/vulkan/nvn_vk_stats.c @@ -1,6 +1,6 @@ // Vulkan 后端暂不提供的 Metal 统计 / 调度接口:一律「无数据」,宿主诊断按缺数据处理 // Metal statistics / scheduling interfaces the Vulkan backend does not provide yet: all "no data", host diagnostics treat them as missing -#include "../dm.h" +#include "../../host/dm.h" #include "nvn_obj.h" #include "nvn_mtl.h" diff --git a/dm/host/android/vk_platform.h b/dm/gfx/vulkan/vk_platform.h similarity index 100% rename from dm/host/android/vk_platform.h rename to dm/gfx/vulkan/vk_platform.h diff --git a/dm/host/.gitignore b/dm/host/.gitignore index 5ddf9aa..59d8a28 100644 --- a/dm/host/.gitignore +++ b/dm/host/.gitignore @@ -5,5 +5,3 @@ dm_bright_levels.inc *.h.tmp *.inc.tmp -# Android generated binaries, logs, caches and game frame captures -build-android/