harmony-skills-game-performance 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # harmony-skills-game-performance
2
2
 
3
- > HarmonyOS 游戏性能评估技能,在通过 HDC 连接的鸿蒙 PC 上评估主流游戏的运行性能,输出十项指标与综合报告。
3
+ > HarmonyOS 游戏性能评估与 HMDeck 游戏调优技能。
4
4
 
5
5
  ## 概述
6
6
 
7
- 本包提供鸿蒙 PC 游戏基准测试工具集。Agent 负责设备识别、HMDeck/Steam 界面操作、存档准备与恢复、固定场景执行、指标采集和综合报告生成。用户只需指定游戏或全测(「测只狼」「测生化3」「测 NBA」「三款全测」)。
7
+ 本包提供鸿蒙 PC 游戏基准测试工具和 HMDeck 接入、诊断与调优流程。基准评估 Agent 负责设备识别、HMDeck/Steam 界面操作、存档准备与恢复、固定场景执行、指标采集和综合报告生成。用户只需指定游戏或全测(「测只狼」「测生化3」「测 NBA」「三款全测」)。
8
8
 
9
9
  默认留取截图、SmartPerf 和轻量运行日志,不抓系统 trace;启动和等待加载的时间排除在性能窗口外;保留用户预设的画质、分辨率、插帧和超分。
10
10
 
@@ -13,6 +13,14 @@
13
13
  | 技能 ID | 名称 | 职责 |
14
14
  |---------|------|------|
15
15
  | `game-performance-evaluation` | 鸿蒙 PC 游戏性能评估 | 从 HMDeck 启动 Steam、在 Steam 库内启动游戏(只狼/RE3/NBA 2K22)、准备和恢复账号存档、执行固定场景、输出每款游戏的十项指标和综合报告(HTML/MD/JSON/CSV) |
16
+ | `hmdeck-game-onboarding` | 游戏接入诊断 | 核验启动链、PE 架构和实际运行时,产出接入记录与最小复现 |
17
+ | `hmdeck-performance-diagnosis` | 性能证据与归因 | 用可比帧时和有效采样定位游戏、转译、图形及呈现阶段的性能瓶颈 |
18
+ | `hmdeck-cpu-sync-tuning` | CPU 与同步调优 | 核验线程绑核、QoS、Wine 同步策略的生效范围及恢复结果 |
19
+ | `hmdeck-graphics-compat` | 图形兼容诊断 | 定位 D3D 初始化、资源格式、着色器与驱动兼容问题并形成最小复现 |
20
+ | `hmdeck-texture-memory-tuning` | 纹理与内存调优 | 区分纹理解码、上传和实际内存驻留,验证压缩与缓存预算的代价 |
21
+ | `hmdeck-frame-pacing-tuning` | 帧节奏与超分调优 | 比较锁帧、超分及插帧对真实渲染、输出节奏、画质和延迟的影响 |
22
+ | `hmdeck-media-compat` | 媒体兼容诊断 | 追踪媒体图、解码插件与画面和音频输出,定位开场视频兼容故障 |
23
+ | `hmdeck-input-window-compat` | 输入与窗口适配 | 定位手柄、鼠标、焦点及窗口生命周期问题,验证前后台和设备切换 |
16
24
 
17
25
  ## 安装
18
26
 
@@ -20,11 +28,11 @@
20
28
  npm install harmony-skills-game-performance
21
29
  ```
22
30
 
23
- 安装后将 `game-performance-evaluation` 目录复制到 Agent 的 skill 发现路径(如项目 `.agents/skills/` 或 `~/.agents/skills/`),确认入口位于 `<skill 目录>/game-performance-evaluation/SKILL.md`。
31
+ 安装后,从 `node_modules/harmony-skills-game-performance/` 将所需技能目录复制到 Agent 的 skill 发现路径(如项目 `.agents/skills/`),使 `<skill ID>/SKILL.md` 可被发现。
24
32
 
25
33
  ## 使用说明
26
34
 
27
- ### 前置条件
35
+ ### 基准评估前置条件
28
36
 
29
37
  - 控制机:Python >= 3.10,依赖见 `game-performance-evaluation/requirements.txt`(PIL、cv2、numpy、filelock 等),HDC 来自已安装的 HarmonyOS SDK
30
38
  - 目标设备:鸿蒙 PC,已授权 HDC,安装兼容 HMDeck、Linux ARM64 Steam 及获许可的游戏,允许使用 uinput、snapshot_display、SP_daemon
@@ -43,8 +51,16 @@ npm install harmony-skills-game-performance
43
51
  - 逐游戏指标.csv、分场景指标.csv
44
52
  - 每款游戏的 run 目录保留结果、采样与截图;缺传感器、日志或完整样本时按指标显示 N/A
45
53
 
54
+ ## HMDeck 游戏调优
55
+
56
+ 启动失败时先用 `hmdeck-game-onboarding` 定位失败阶段。运行卡顿时用 `hmdeck-performance-diagnosis` 建立基线,再选择对应的调优或兼容 Skill。源码和日志可用于离线分析。真机验证需要可访问的授权设备、合法安装的游戏及当前构建支持的调试入口。两个可选分析脚本使用 Python 3 标准库。
57
+
58
+ 每项调优在目标游戏内比较前后效果,核验实际生效值与恢复结果。逐游戏设置按实际 AppID、入口或会话核验作用域。共享运行时改动按受影响的组件和场景选择代表游戏回归。
59
+
46
60
  ## 目录结构
47
61
 
62
+ 每个 `hmdeck-*` 目录含独立 `SKILL.md` 和 Agent 元数据,部分包含脚本或输入格式参考。基准评估目录如下。
63
+
48
64
  ```
49
65
  game-performance-evaluation/
50
66
  ├── SKILL.md # 技能入口与执行流程
@@ -0,0 +1,18 @@
1
+ ---
2
+ name: hmdeck-cpu-sync-tuning
3
+ description: "在 HMDeck 游戏主线程、渲染提交线程或 Wine 服务存在 CPU 调度和同步等待瓶颈时使用。核验绑核、QoS、同步策略的作用域、收益和恢复。"
4
+ ---
5
+
6
+ # CPU 与同步调优
7
+
8
+ ## 看清线程与作用域
9
+
10
+ 1. 从相同场景的 CPU 时间、帧时和等待证据选出具体线程。分别识别游戏主线程、图形提交线程、工作线程和共享 Wine 服务。按设备实际核心拓扑选择候选参数。
11
+ 2. 核验当前构建是否支持线程亲和性、QoS、fsync 及对象服务内化,记录配置入口的作用域和生效时机。共享启动器、共享服务或应用级控制项要按其实际范围记录。
12
+ 3. 每次仅调整一个可验证的线程角色或同步策略。涉及服务端创建共享状态的同步机制时,核对客户端、服务端、prefix/会话兼容及重启条件。用对应的等待语义和真实场景检查功能。
13
+
14
+ ## 验证与恢复
15
+
16
+ 比较同场景的帧时、CPU 时间和等待。采纳有效的线程读回时匹配目标线程及会话代次,并与内核实际状态核对。例如在设备允许时核对 `/proc/<tid>/status` 的 CPU affinity。修改前记录原值。支持版本序号的控制接口使用新序号恢复原值,随后独立确认线程已恢复;有共享服务时再核对服务进程实际状态。
17
+
18
+ 交付策略、目标线程、前后帧时、参数读回和恢复记录。需要更改共享同步机制时,按受影响的等待路径选择代表游戏回归。
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "CPU 与同步调优"
3
+ short_description: "核验线程绑核、QoS、Wine 同步策略的生效范围及恢复结果"
4
+ default_prompt: "用 $hmdeck-cpu-sync-tuning 分析这款 HMDeck 游戏,并记录实际证据、验证结果和待确认项。"
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: hmdeck-frame-pacing-tuning
3
+ description: "在 HMDeck 游戏需要评估锁帧、超分、插帧或 WSI 呈现节奏时使用。区分源帧和输出帧,比较画质、延迟、帧序与实际生效值。"
4
+ ---
5
+
6
+ # 帧节奏与超分调优
7
+
8
+ ## 验证实际能力
9
+
10
+ 记录源分辨率、输出分辨率、刷新率、游戏帧率上限和启动路径。确认实际使用的超分或插帧引擎、支持模式、应用范围及是否需重启。按读回或加载证据区分 XEngine、FSR 和其他实现。应用级设置与可按 AppID 或会话下发的值分别记录。
11
+
12
+ ## 试验顺序
13
+
14
+ 1. 固定画质和玩法,关闭超分与插帧,分别测量游戏源帧和最终输出帧。
15
+ 2. 单独试验锁帧、超分和插帧,然后根据需求比较组合。记录真实/生成帧比例、重复或丢弃、帧间隔 P50/P95/P99、画质及输入延迟。
16
+ 3. 用真实镜头运动、HUD 和窗口 resize 验证帧序、过时历史帧、前后台及休眠恢复。出现呈现卡顿时核对 surface 代次、同步和缓冲区生命周期。
17
+
18
+ ## 验证与产物
19
+
20
+ 核验目标游戏参数是否实际生效,恢复原锁帧、分辨率、超分和插帧设置后再次读回。交付同场景对照、源帧与输出帧指标、画质和延迟证据、适用范围及恢复步骤。
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "帧节奏与超分调优"
3
+ short_description: "比较锁帧、超分及插帧对真实渲染、输出节奏、画质和延迟的影响"
4
+ default_prompt: "用 $hmdeck-frame-pacing-tuning 分析这款 HMDeck 游戏,并记录实际证据、验证结果和待确认项。"
@@ -0,0 +1,17 @@
1
+ ---
2
+ name: hmdeck-game-onboarding
3
+ description: "在 HMDeck 接入 Windows 游戏或排查游戏启动失败时使用。核验实际启动链、PE 架构、已加载运行时和首个失败阶段。"
4
+ ---
5
+
6
+ # 游戏接入诊断
7
+
8
+ ## 定位启动阶段
9
+
10
+ - 记录游戏版本、真实入口 EXE、游戏平台、目标系统和驱动、HMDeck/HAP 版本及运行时组件。若可读本地源码和 EXE,从本 Skill 目录运行 `python3 scripts/collect_context.py --repo "<本地源码路径>" --exe "<游戏入口路径>"`,Steam 游戏可加 `--steam-app-id`。静态 PE 类型用于识别入口,ARM64EC/ARM64X 及辅助进程还需从实际模块加载记录确认。
11
+ - 分清直接启动 EXE 和经 Steam 等客户端启动的路径。跟踪 AppID(如有)、入口 EXE、会话代次和目标 PID。启动器、安装辅助进程与游戏本体分别记录。
12
+ - 按顺序检查文件访问、工作目录、PE 位宽和转译器、DLL 导入与加载、prefix 迁移、窗口创建及首帧。以第一个有证据的失败阶段缩小复现范围。
13
+ - 核验实际组件和工作目录,尤其是 Windows API 兼容、跨架构转译和 D3D 后端的边界。缺少 DLL 导出或不匹配的 ABI 时,记录受影响组件及版本。
14
+
15
+ ## 验证与产物
16
+
17
+ 按进程创建、首帧、主菜单、实际玩法、退出与存档逐项记录结果。测试启动参数时仅修改目标游戏入口,比较同一构建默认和候选设置,检查目标进程读回及原值恢复。交付接入记录、首个失败证据及可复现步骤。
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "游戏接入诊断"
3
+ short_description: "核验启动链、PE 架构和实际运行时,产出接入记录与最小复现"
4
+ default_prompt: "用 $hmdeck-game-onboarding 分析这款 HMDeck 游戏,并记录实际证据、验证结果和待确认项。"
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env python3
2
+ """Collect explicit local repository/PE identity without launching a game."""
3
+ import argparse
4
+ import hashlib
5
+ import json
6
+ from pathlib import Path
7
+ import struct
8
+ import subprocess
9
+
10
+
11
+ def sha256(path):
12
+ digest = hashlib.sha256()
13
+ with path.open('rb') as stream:
14
+ for chunk in iter(lambda: stream.read(1024 * 1024), b''):
15
+ digest.update(chunk)
16
+ return digest.hexdigest()
17
+
18
+
19
+ def pe_identity(path):
20
+ with path.open('rb') as stream:
21
+ header = stream.read(64)
22
+ if len(header) < 64 or header[:2] != b'MZ':
23
+ raise ValueError('Not a DOS/PE executable')
24
+ offset = struct.unpack_from('<I', header, 0x3c)[0]
25
+ if offset < 64 or offset > path.stat().st_size - 24:
26
+ raise ValueError('Invalid PE header offset')
27
+ stream.seek(offset)
28
+ coff = stream.read(24)
29
+ if len(coff) != 24 or coff[:4] != b'PE\0\0':
30
+ raise ValueError('Missing PE signature')
31
+ machine = struct.unpack_from('<H', coff, 4)[0]
32
+ architectures = {0x14c: 'x86', 0x8664: 'x86_64', 0xaa64: 'arm64',
33
+ 0xa641: 'arm64ec', 0xa64e: 'arm64x'}
34
+ return {'path': str(path.resolve()), 'bytes': path.stat().st_size,
35
+ 'sha256': sha256(path), 'machine': hex(machine),
36
+ 'architecture': architectures.get(machine, 'unknown')}
37
+
38
+
39
+ def git(repo, *args):
40
+ return subprocess.check_output(['git', '-C', str(repo), *args], text=True,
41
+ stderr=subprocess.PIPE).strip()
42
+
43
+
44
+ def main():
45
+ parser = argparse.ArgumentParser(description=__doc__)
46
+ parser.add_argument('--repo', type=Path, required=True)
47
+ parser.add_argument('--exe', type=Path)
48
+ parser.add_argument('--steam-app-id')
49
+ parser.add_argument('--output', type=Path)
50
+ args = parser.parse_args()
51
+ if args.steam_app_id and not args.steam_app_id.isdecimal():
52
+ parser.error('--steam-app-id must be a decimal Steam AppID')
53
+ try:
54
+ top = Path(git(args.repo, 'rev-parse', '--show-toplevel'))
55
+ data = {'schema_version': 1, 'repository': str(top),
56
+ 'commit': git(top, 'rev-parse', 'HEAD'),
57
+ 'branch': git(top, 'branch', '--show-current'),
58
+ 'shallow': git(top, 'rev-parse', '--is-shallow-repository') == 'true',
59
+ 'dirty': bool(git(top, 'status', '--porcelain', '--untracked-files=no')),
60
+ 'steam_app_id': args.steam_app_id,
61
+ 'executable': pe_identity(args.exe) if args.exe else None,
62
+ 'limits': ['Static identity only; no installed-runtime, device, launch or game qualification.']}
63
+ except (OSError, ValueError, subprocess.CalledProcessError) as exc:
64
+ parser.exit(2, f'Context collection failed: {exc}\n')
65
+ rendered = json.dumps(data, ensure_ascii=False, indent=2) + '\n'
66
+ if args.output:
67
+ args.output.parent.mkdir(parents=True, exist_ok=True)
68
+ args.output.write_text(rendered, encoding='utf-8')
69
+ else:
70
+ print(rendered, end='')
71
+
72
+
73
+ if __name__ == '__main__':
74
+ main()
@@ -0,0 +1,16 @@
1
+ ---
2
+ name: hmdeck-graphics-compat
3
+ description: "在 HMDeck 游戏 D3D11/12 初始化失败、黑屏、贴图或光照异常及 GPU 卡死时使用。定位 DXVK/VKD3D、Vulkan 能力、着色器、资源与驱动条件。"
4
+ ---
5
+
6
+ # 图形兼容诊断
7
+
8
+ ## 从真实后端开始
9
+
10
+ 1. 记录实际加载的 D3D/DXGI DLL、版本、位宽、图形后端、设备与驱动。读取实际 Vulkan 特性和格式支持。D3D12 初始化异常先核对配套 DXGI、导出符号和 prefix 迁移。
11
+ 2. 从第一个失败的 API 或错误画面制作最小探针。格式问题覆盖资源创建、RTV/SRV/UAV 视图、初始数据、更新/复制和读回。SNORM 等格式回退同时核对游戏可见格式、实际存储和各视图的读写语义。
12
+ 3. 着色器异常缩小到具体阶段与输入,记录驱动条件。GPU 卡死时检查提交、fence、队列归属与资源生命周期。将 GPU 步进、回读等诊断采集与正常帧时测量分开。
13
+
14
+ ## 验证与产物
15
+
16
+ 同一游戏验证原问题、候选和恢复行为,记录实际生效参数、真实玩法画面与最小复现结果。游戏规则写清 AppID/入口及版本条件;驱动规避验证设备和驱动匹配。共享组件变更按受影响的 API 和后端补代表场景回归。交付最小复现、匹配条件、组件修复建议或已支持的游戏参数。
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "图形兼容诊断"
3
+ short_description: "定位 D3D 初始化、资源格式、着色器与驱动兼容问题并形成最小复现"
4
+ default_prompt: "用 $hmdeck-graphics-compat 分析这款 HMDeck 游戏,并记录实际证据、验证结果和待确认项。"
@@ -0,0 +1,17 @@
1
+ ---
2
+ name: hmdeck-input-window-compat
3
+ description: "在 HMDeck 游戏手柄或鼠标异常、输入焦点丢失、全屏切换失败或前后台恢复异常时使用。定位宿主输入到游戏窗口的路由与生命周期。"
4
+ ---
5
+
6
+ # 输入与窗口适配
7
+
8
+ ## 追踪输入与窗口
9
+
10
+ - 固定目标会话、游戏 EXE、窗口 owner PID、窗口/表面代次和输入配置。按物理设备事件、宿主桥、Wine bus/RawInput/DirectInput/XInput、游戏响应逐段确认。
11
+ - 区分绝对/相对鼠标、锁定/隐藏、焦点和坐标变换。切出、窗口销毁或设备移除时核对按键/按钮释放。
12
+ - 区分启动器窗口、游戏窗口和辅助窗口。确认可见性、前台与输入路由的关系,覆盖全屏切换、窗口重建和重新获得焦点。
13
+ - 按实际游戏平台标识、游戏版本及入口核验输入配置规则。同名 EXE 或共享启动器场景下用目标游戏进程或窗口身份补充匹配。
14
+
15
+ ## 验证与产物
16
+
17
+ 在目标游戏检查手柄热插拔、游戏内按键和摇杆、相对鼠标/拖动、前后台、全屏和退出。记录目标窗口实际收到的事件,保留物理设备和模拟探针各自的结果。恢复原输入配置并复查焦点和卡键风险。交付路由证据、失效环节、候选配置或共享桥修复和恢复记录。
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "输入与窗口适配"
3
+ short_description: "定位手柄、鼠标、焦点及窗口生命周期问题,验证前后台和设备切换"
4
+ default_prompt: "用 $hmdeck-input-window-compat 分析这款 HMDeck 游戏,并记录实际证据、验证结果和待确认项。"
@@ -0,0 +1,16 @@
1
+ ---
2
+ name: hmdeck-media-compat
3
+ description: "在 HMDeck 游戏开场视频黑屏、Media Foundation/DirectShow 初始化失败、缺解码器或视频无声时使用。核验实际媒体链和包内运行时依赖。"
4
+ ---
5
+
6
+ # 媒体兼容诊断
7
+
8
+ ## 核验实际媒体链
9
+
10
+ 1. 建立黑屏或无声的时间线,确认游戏是否打开媒体,并记录实际使用的 Media Foundation、DirectShow 或 GStreamer 链路。尚未创建媒体图时先调查启动、渲染或呈现阶段。
11
+ 2. 核对媒体容器及编码、目标进程位宽、媒体 DLL、Unix 模块初始化、插件发现和动态加载依赖。WoW64 场景分别核验 32 位和 64 位入口的依赖闭包。
12
+ 3. 用受控短片段确认非黑视频帧、音频缓冲、PTS 推进和正常结束。组件缺失时从实际包或运行时清单定位;逐游戏兼容开关则核对目标启动器和实际进程是否消费。
13
+
14
+ ## 验证与产物
15
+
16
+ 在目标游戏验证开场、跳过/重播、正常进入玩法及前后台恢复。记录探针和游戏实测结果。恢复本次试验的媒体选项,再核对目标入口原值。交付失败阶段、最小复现、候选开关或组件依赖修复、版本及作用范围。
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "媒体兼容诊断"
3
+ short_description: "追踪媒体图、解码插件与画面和音频输出,定位开场视频兼容故障"
4
+ default_prompt: "用 $hmdeck-media-compat 分析这款 HMDeck 游戏,并记录实际证据、验证结果和待确认项。"
@@ -0,0 +1,22 @@
1
+ ---
2
+ name: hmdeck-performance-diagnosis
3
+ description: "在 HMDeck 游戏掉帧、卡顿、CPU/GPU 开销异常或优化收益待确认时使用。建立同场景基线,核验采样质量并定位卡顿所在阶段。"
4
+ ---
5
+
6
+ # 性能证据与归因
7
+
8
+ ## 建立可比基线
9
+
10
+ 固定游戏存档或路线、设备与驱动、运行时、分辨率、画质、锁帧和超分/插帧状态。记录前后台、缓存冷热和温度。先关闭高开销采样、逐提交日志及像素读回,测量稳定玩法窗口。
11
+
12
+ ## 分层定位
13
+
14
+ 1. 分别确定游戏出图、提交、GPU 完成和宿主呈现的指标来源。启用插帧时单列生成帧和输出帧。多个窗口读到同一全局计数器时,只统计一次。
15
+ 2. 从长帧窗口定位时间缺口,区分游戏线程、Wine 或转译代码、D3D 提交、GPU 执行、WSI 和窗口呈现。记录窗口、会话、PID 和实际加载模块,避免把旧日志或辅助进程计入。
16
+ 3. 使用设备支持的采样入口。使用 `hiperf` 时先短采确认符号、用户栈和采样覆盖。Guest/JIT 栈不可展开时,归因粒度停在可确认的进程、线程或动态库。采样占比和线程 CPU 利用率分别记录。
17
+
18
+ ## 验证与产物
19
+
20
+ 在同一游戏场景逐项试验。波动大时使用 A/B/A(基线、候选、恢复基线)或重复交错测量。对比画面正确性、帧时长尾和掉帧,记录诊断开销。可将单一指标来源的相邻帧间隔按[帧时输入格式](references/run-format.md)交给 `scripts/compare_runs.py`。
21
+
22
+ 交付前后测量、瓶颈归因、证据缺口和下一项实验。实际调参后核对生效值并恢复本次修改。固定游戏的标准化基准评估可使用本包的 `game-performance-evaluation`。
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "性能证据与归因"
3
+ short_description: "用可比帧时和有效采样定位游戏、转译、图形及呈现阶段的性能瓶颈"
4
+ default_prompt: "用 $hmdeck-performance-diagnosis 分析这款 HMDeck 游戏,并记录实际证据、验证结果和待确认项。"
@@ -0,0 +1,40 @@
1
+ # 帧时比较输入
2
+
3
+ ```json
4
+ {
5
+ "schema_version": 1,
6
+ "runs": [
7
+ {
8
+ "id": "A1",
9
+ "condition": "baseline",
10
+ "game_key": "steam:1001",
11
+ "scene": "same-save-same-camera",
12
+ "device": "measured-device-class",
13
+ "driver": "exact-driver-version",
14
+ "resolution": [1920, 1080],
15
+ "cache_state": "warm",
16
+ "profiled": false,
17
+ "metric_source": "render",
18
+ "runtime_receipt_sha256": "0000000000000000000000000000000000000000000000000000000000000000",
19
+ "hap_sha256": "0000000000000000000000000000000000000000000000000000000000000000",
20
+ "frame_times_ms": [16.4, 16.8, 17.0]
21
+ }
22
+ ]
23
+ }
24
+ ```
25
+
26
+ 以上只有结构示例,哈希和数值均为合成数据,不是 HMDeck 实测。实际输入至少包含 baseline 和 candidate 两组,推荐 A1/B1/A2 或多轮交错,候选两侧均有基线。
27
+
28
+ `frame_times_ms` 必须是同一观测源产生的、正值、有限、非重叠的真实相邻帧间隔。不能把成功调用耗时、GPU 段耗时、FPS 倒数或多个窗口的累计计数当成相邻帧间隔。跨采样丢失/重置的间隔应在预处理中分段,不悄悄删除慢帧。
29
+
30
+ `metric_source`:render 为实际游戏出图,present 为所核验提交/呈现时间,output 为含插帧的输出时间。三者不能混合。若超分改变工作负载,输入和输出尺寸都在原始实验记录中明确,不能仅复用本表的 resolution 掩盖差异。
31
+
32
+ 脚本以 nearest-rank 算 P50/P95/P99,FPS 使用 `1000 / 平均相邻帧间隔`,每组最终取各轮统计的中位数,避免长轮次按帧数压过短轮次。`max_ms` 的组中位数仍不是所有轮次中的最坏最大值,最坏值见每轮明细。
33
+
34
+ 基线漂移门限缺省 5%,只是可调整的实验质量提示。少于 300 个间隔会标记短样本。字段不一致、没有 A/B/A 包围或控制组漂移过大时输出 `comparable=false`。
35
+
36
+ ```sh
37
+ python3 scripts/compare_runs.py /absolute/path/runs.json --output /absolute/path/comparison.json
38
+ ```
39
+
40
+ 结果只反映输入数据。未做视觉正确性、延迟、热状态、实际运行时或 A/B 游戏隔离验证,不会生成“可发布”结论。格式错误退出 2;合法数据即使不可比也正常生成报告,由 comparable 字段明确表示。
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env python3
2
+ """Summarize explicitly comparable frame-interval runs; never qualify a game."""
3
+ import argparse
4
+ import json
5
+ import math
6
+ from pathlib import Path
7
+ import statistics
8
+
9
+ CONSTANTS = ('game_key', 'scene', 'device', 'driver', 'resolution', 'cache_state',
10
+ 'profiled', 'metric_source')
11
+
12
+
13
+ def percentile(values, q):
14
+ values = sorted(values)
15
+ return values[max(0, math.ceil(len(values) * q) - 1)]
16
+
17
+
18
+ def compare(data, max_drift=5.0):
19
+ if not isinstance(data, dict) or data.get('schema_version') != 1:
20
+ raise ValueError('schema_version=1 required')
21
+ runs = data.get('runs')
22
+ if not isinstance(runs, list) or len(runs) < 2 or not all(isinstance(r, dict) for r in runs):
23
+ raise ValueError('At least two run objects required')
24
+ records, warnings, reasons, ids = [], [], [], set()
25
+ for run in runs:
26
+ if not isinstance(run.get('id'), str) or not run['id'] or run['id'] in ids:
27
+ raise ValueError('Unique, non-empty run IDs required')
28
+ ids.add(run['id'])
29
+ if run.get('condition') not in ('baseline', 'candidate'):
30
+ raise ValueError('condition must be baseline or candidate')
31
+ for key in CONSTANTS:
32
+ if key not in run or run[key] is None or run[key] == '':
33
+ raise ValueError('Missing contract field: ' + key)
34
+ if not isinstance(run['profiled'], bool):
35
+ raise ValueError('profiled must be boolean')
36
+ if run['metric_source'] not in ('render', 'present', 'output'):
37
+ raise ValueError('metric_source must be render, present or output')
38
+ if not isinstance(run['resolution'], list) or len(run['resolution']) != 2 or any(
39
+ not isinstance(n, int) or isinstance(n, bool) or n <= 0 for n in run['resolution']):
40
+ raise ValueError('resolution must be [positive width, positive height]')
41
+ for key in ('runtime_receipt_sha256', 'hap_sha256'):
42
+ text = run.get(key)
43
+ if not isinstance(text, str) or len(text) != 64 or any(c not in '0123456789abcdef' for c in text):
44
+ raise ValueError(key + ' must be a SHA256')
45
+ values = run.get('frame_times_ms')
46
+ if not isinstance(values, list) or len(values) < 2 or any(
47
+ isinstance(v, bool) or not isinstance(v, (int, float)) or not math.isfinite(v) or v <= 0 for v in values):
48
+ raise ValueError('Each run needs at least two finite positive frame intervals')
49
+ if len(values) < 300:
50
+ warnings.append(run['id'] + ': fewer than 300 intervals; short observational sample')
51
+ mean = statistics.mean(values)
52
+ records.append({'id': run['id'], 'condition': run['condition'], 'samples': len(values),
53
+ 'mean_fps': 1000 / mean, 'p50_ms': percentile(values, .50),
54
+ 'p95_ms': percentile(values, .95), 'p99_ms': percentile(values, .99),
55
+ 'max_ms': max(values)})
56
+ if {r['condition'] for r in runs} != {'baseline', 'candidate'}:
57
+ raise ValueError('Both baseline and candidate conditions required')
58
+ for key in CONSTANTS:
59
+ if any(run[key] != runs[0][key] for run in runs[1:]):
60
+ reasons.append('Different contract field: ' + key)
61
+ base = [r for r in records if r['condition'] == 'baseline']
62
+ cand = [r for r in records if r['condition'] == 'candidate']
63
+ first_candidate = next(i for i,r in enumerate(runs) if r['condition'] == 'candidate')
64
+ last_candidate = max(i for i,r in enumerate(runs) if r['condition'] == 'candidate')
65
+ bracketed = any(r['condition'] == 'baseline' for r in runs[:first_candidate]) and any(
66
+ r['condition'] == 'baseline' for r in runs[last_candidate+1:])
67
+ if not bracketed:
68
+ reasons.append('Candidate runs are not bracketed by baseline runs (A/B/A)')
69
+ baseline_fps = statistics.median(r['mean_fps'] for r in base)
70
+ drift = 100 * (max(r['mean_fps'] for r in base) - min(r['mean_fps'] for r in base)) / baseline_fps
71
+ if drift > max_drift:
72
+ reasons.append('Baseline FPS spread exceeds the chosen drift threshold')
73
+ if runs[0]['profiled']:
74
+ warnings.append('Profiled measurements cannot establish unprofiled production performance')
75
+ summaries = {c: {key: statistics.median(r[key] for r in group)
76
+ for key in ('mean_fps','p50_ms','p95_ms','p99_ms','max_ms')}
77
+ for c,group in [('baseline',base),('candidate',cand)]}
78
+ changes = {key: 100*(summaries['candidate'][key]-summaries['baseline'][key])/summaries['baseline'][key]
79
+ for key in summaries['baseline']}
80
+ return {'comparable': not reasons, 'inconclusive_reasons': reasons, 'warnings': warnings,
81
+ 'baseline_fps_spread_pct': drift, 'max_baseline_drift_pct': max_drift,
82
+ 'metric_source': runs[0]['metric_source'], 'run_summaries': records,
83
+ 'condition_medians': summaries, 'candidate_change_pct': changes,
84
+ 'qualification': 'Statistics only; visual correctness, input latency, game isolation and actual frame provenance are not verified.'}
85
+
86
+
87
+ def main():
88
+ parser = argparse.ArgumentParser(description=__doc__)
89
+ parser.add_argument('input', type=Path)
90
+ parser.add_argument('--output', type=Path)
91
+ parser.add_argument('--max-baseline-drift-pct', type=float, default=5.0)
92
+ args = parser.parse_args()
93
+ if not math.isfinite(args.max_baseline_drift_pct) or args.max_baseline_drift_pct < 0:
94
+ parser.error('Drift threshold must be finite and nonnegative')
95
+ try:
96
+ result = compare(json.loads(args.input.read_text(encoding='utf-8')), args.max_baseline_drift_pct)
97
+ except (OSError, ValueError, TypeError) as exc:
98
+ parser.exit(2, f'Invalid measurement: {exc}\n')
99
+ text = json.dumps(result, ensure_ascii=False, indent=2, allow_nan=False)+'\n'
100
+ if args.output:
101
+ args.output.parent.mkdir(parents=True, exist_ok=True)
102
+ args.output.write_text(text, encoding='utf-8')
103
+ else:
104
+ print(text, end='')
105
+
106
+
107
+ if __name__ == '__main__':
108
+ main()
@@ -0,0 +1,17 @@
1
+ ---
2
+ name: hmdeck-texture-memory-tuning
3
+ description: "在 HMDeck 游戏纹理不支持、上传卡顿、显存增长或转译缓存压力过高时使用。分析纹理格式、转码开销、实际驻留与可恢复的预算策略。"
4
+ ---
5
+
6
+ # 纹理与内存调优
7
+
8
+ ## 量化内存和上传
9
+
10
+ - 记录设备压缩格式支持及最大纹理尺寸、原始格式、mip 层级与数组层数。分别报告估算字节数、CPU/GPU 实测内存和设备退出原因。资源占用告警需结合场景、多轮切换和内存回落判断。
11
+ - BC 不可用时核对 RGBA 解码或已支持的 ASTC 转码。检查格式视图、sRGB/UNORM、初始数据和 UpdateSubresource 等更新语义。记录实际走到的路径、解码时间、上传尖峰、驻留变化及画质。
12
+ - 对转译缓存先确认转译器和构建支持的预算接口。分别记录缓存命中、内存和二次进入场景的长尾。预算按实际游戏会话生效时才作为逐游戏策略交付。
13
+ - 如游戏资源实验已获授权,在独立目录使用用户提供的资源副本和匹配版本,保留启动文件、资源引用、校验与存档。先验完整性,再测试实际画面。
14
+
15
+ ## 验证与产物
16
+
17
+ 比较同场景的首次加载、连续玩法、切场景和前后台切换,核验内存峰值、稳态、回落和缺图/色差。保存原图形或预算设置,结束后恢复并验证实际值。输出已测内存曲线、适用条件、参数和画质/帧时权衡。
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "纹理与内存调优"
3
+ short_description: "区分纹理解码、上传和实际内存驻留,验证压缩与缓存预算的代价"
4
+ default_prompt: "用 $hmdeck-texture-memory-tuning 分析这款 HMDeck 游戏,并记录实际证据、验证结果和待确认项。"
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "harmony-skills-game-performance",
3
- "version": "1.0.0",
4
- "description": "HarmonyOS 游戏性能评估技能,在通过 HDC 连接的鸿蒙 PC 上评估只狼/生化危机3重制版/NBA 2K22 的运行性能,输出十项指标与综合报告",
3
+ "version": "1.1.0",
4
+ "description": "HarmonyOS 游戏性能技能,覆盖鸿蒙 PC 固定场景基准评估、HMDeck 游戏接入、兼容诊断与性能调优",
5
5
  "keywords": [
6
6
  "harmony-suit-skills",
7
7
  "game-skill",
8
8
  "game-performance-evaluation",
9
9
  "fps",
10
- "benchmark"
10
+ "benchmark",
11
+ "game-tuning",
12
+ "hmdeck"
11
13
  ],
12
14
  "license": "MIT",
13
15
  "repository": {
@@ -21,6 +23,14 @@
21
23
  "url": ""
22
24
  },
23
25
  "files": [
24
- "game-performance-evaluation"
26
+ "game-performance-evaluation",
27
+ "hmdeck-game-onboarding",
28
+ "hmdeck-performance-diagnosis",
29
+ "hmdeck-cpu-sync-tuning",
30
+ "hmdeck-graphics-compat",
31
+ "hmdeck-texture-memory-tuning",
32
+ "hmdeck-frame-pacing-tuning",
33
+ "hmdeck-media-compat",
34
+ "hmdeck-input-window-compat"
25
35
  ]
26
36
  }