Skip to content

Commit b050ce5

Browse files
committed
Trim trigger with asset file; fix some waits
1 parent 17ca4d4 commit b050ce5

File tree

1 file changed

+47
-26
lines changed

1 file changed

+47
-26
lines changed

scripts/gfxr_capture_replay_test.sh

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ BUILD_DIR=./build
7373
GFXR_DUMP_RESOURCES="${BUILD_DIR}/gfxr_dump_resources/gfxr_dump_resources"
7474
JSON_BASENAME=dump.json
7575
DUMP_DIR="${REMOTE_TEMP_DIR}/dump"
76-
# Needs to be high enough to skip over loading screens but not too high to trip the wait_for_logcat_line timeout.
77-
CAPTURE_FRAME=720
78-
GFXR_BASENAME="${PACKAGE}_frame_${CAPTURE_FRAME}.gfxr"
76+
GFXR_BASENAME="${PACKAGE}_trim_trigger.gfxr"
7977
GFXA_BASENAME="${PACKAGE}_asset_file.gfxa"
8078
GFXR_REPLAY_APK=./install/gfxr-replay.apk
8179
RESULTS_DIR="${PACKAGE}-$(date +%Y%m%d_%H%M%S)"
@@ -88,7 +86,10 @@ VALIDATION_LAYER_LIB=libVkLayer_khronos_validation.so
8886
REMOTE_TEMP_FILEPATH="/data/local/tmp/${VALIDATION_LAYER_LIB}"
8987
ARCH=$(adb shell getprop ro.product.cpu.abi)
9088
LOCAL_VALIDATION_LAYER_FILEPATH="${VALIDATION_LAYER_DIR}/${ARCH}/${VALIDATION_LAYER_LIB}"
91-
FRAME_DELIMITER_PROP=openxr.enable_frame_delimiter
89+
# The old prop requires root access
90+
OLD_FRAME_DELIMITER_PROP=openxr.enable_frame_delimiter
91+
# The new prop works with shell user (does not require root access)
92+
NEW_FRAME_DELIMITER_PROP=debug.openxr.enable_frame_delimiter
9293

9394
#
9495
# Clear anything previously set (in case the script exited prematurely)
@@ -101,12 +102,15 @@ unset_vulkan_debug_settings
101102
# Ask OpenXR runtime to emit frame debug marker
102103
#
103104

104-
# Only try if it's not set (to avoid having to root all the time)
105-
ENABLE_FRAME_DELIMITER="$(adb shell getprop ${FRAME_DELIMITER_PROP})"
105+
adb shell setprop "${NEW_FRAME_DELIMITER_PROP}" true
106+
107+
# Since root/unroot disconnects the device and disrupts any host monitoring scripts (logcat, scrcpy), minimize the number of times it's called.
108+
# It's only required to set the old prop. We can check if it's already set to avoid root/unroot.
109+
ENABLE_FRAME_DELIMITER="$(adb shell getprop ${OLD_FRAME_DELIMITER_PROP})"
106110
if [ -z "${ENABLE_FRAME_DELIMITER}" ]
107111
then
108112
adb root
109-
adb shell setprop ${FRAME_DELIMITER_PROP} true
113+
adb shell setprop ${OLD_FRAME_DELIMITER_PROP} true
110114
adb unroot
111115
fi
112116

@@ -202,17 +206,14 @@ adb shell settings put global gpu_debug_layer_app "${CAPTURE_DEBUG_LAYER_APPS}"
202206
# See //third_party/gfxreconstruct/USAGE_android.md for more options.
203207
adb shell mkdir -p "${REMOTE_TEMP_DIR}"
204208
adb shell setprop debug.gfxrecon.capture_file "${REMOTE_TEMP_DIR}/${PACKAGE}.gfxr"
205-
# NOTE: quit_after_capture_frames doesn't work with capture_android_trigger or capture_frames :(
206-
# Prefer capture_frames over trigger since it's more friendly to scripting. It knows better when the app is ready and producing frames compared to trigger capture (where we have to guess).
207-
# adb shell setprop debug.gfxrecon.capture_trigger_frames 1
208-
# adb shell setprop debug.gfxrecon.capture_android_trigger false
209-
adb shell setprop debug.gfxrecon.capture_frames "${CAPTURE_FRAME}"
210-
adb shell setprop debug.gfxrecon.capture_use_asset_file false # XXX asset file is known to have problems
211-
# Remove timestamp from capture filename so it's more predictable
209+
# Use trigger trim with asset file since it's what Dive prefers
210+
adb shell setprop debug.gfxrecon.capture_trigger_frames 1
211+
adb shell setprop debug.gfxrecon.capture_android_trigger false
212+
adb shell setprop debug.gfxrecon.capture_use_asset_file true
213+
# Remove timestamp from capture filename so it's more predictable.
214+
# Since we copy into a timestamped results folder, we don't end up overwriting pulled results.
212215
adb shell setprop debug.gfxrecon.capture_file_timestamp false
213-
# Try to write all packets, even when we crash
214-
adb shell setprop debug.gfxrecon.capture_file_flush true
215-
# More logging
216+
# Since we focused on "does this work?" the extra logging helps
216217
adb shell setprop debug.gfxrecon.log_level debug
217218
# Capture layer in PACKAGE needs permissions to read capture/asset file from storage.
218219
adb shell appops set "${PACKAGE}" MANAGE_EXTERNAL_STORAGE allow
@@ -221,14 +222,15 @@ adb shell appops set "${PACKAGE}" MANAGE_EXTERNAL_STORAGE allow
221222
# 4. Capture
222223
#
223224

224-
# Clear logcat so that we can use it to determine when capture is done
225+
# Clear logcat so that we can use it to determine when capture is done based on logging.
225226
adb logcat -c
226227

227228
if [ ${CAPTURE_DEBUG} -eq 1 ]
228229
then
229230
adb shell am set-debug-app -w "${PACKAGE}"
230231
fi
231232

233+
# Start app, wait for it to start
232234
adb shell am start -S -W -n "${PACKAGE}/${ACTIVITY}"
233235

234236
# Given how long it takes to attach the debugger, etc, it is unlikely that you'll want the script to proceed.
@@ -237,8 +239,22 @@ then
237239
exit 0
238240
fi
239241

242+
# Likely redundant, but wait for the capture layer to log that it's been loaded
243+
if ! wait_for_logcat_line gfxrecon "Initializing GFXReconstruct capture layer"
244+
then
245+
adb bugreport
246+
fi
247+
248+
# Trigger a capture after the app has enough time to load.
249+
# Use this over the capture_frame setting since Dive doesn't use capture_frame.
250+
# Unfortunately "the app is loaded" is not something we can determine so we need to sleep... This is where capture_frame could really help.
251+
# 20s is too short for some large Unity apps.
252+
sleep 30
253+
adb shell setprop debug.gfxrecon.capture_android_trigger true
254+
240255
# Wait for capture to finish. Luckily, the app logs when it's done so use that as the signal to proceed.
241256
# This only works since we clear the logcat at the start of the test.
257+
# We prefer this over quit_after_capture_frames since that setting seems broken.
242258
if ! wait_for_logcat_line gfxrecon "Finished recording graphics API capture"
243259
then
244260
adb bugreport
@@ -247,23 +263,23 @@ adb shell am force-stop "${PACKAGE}"
247263

248264
# Pull the GFXR/GFXA for gfxr_dump_resources
249265
adb pull "${REMOTE_TEMP_DIR}/${GFXR_BASENAME}" "${RESULTS_DIR}"
250-
# TODO asset file was disabled for testing; re-enable
251-
# adb pull "${REMOTE_TEMP_DIR}/${GFXA_BASENAME}" "${RESULTS_DIR}"
266+
adb pull "${REMOTE_TEMP_DIR}/${GFXA_BASENAME}" "${RESULTS_DIR}"
252267

253268
#
254269
# 5. Post-capture clean-up
255270
#
256271

257272
# NOTE: Don't clean up GFXA/GFXR since we can use it for replay. Saves having to push again.
258273

259-
# Next launch should not use GFXR
274+
# Next launch of PACKAGE/ACTIVITY should not use GFXR
260275
unset_gfxr_props
261276
unset_vulkan_debug_settings
262277

263278
#
264279
# 6. Replay with dump-resources
265280
#
266281

282+
# --last-draw-only saves time by only dumping the final draw call. This should represent what the user sees.
267283
"${GFXR_DUMP_RESOURCES}" --last_draw_only "${RESULTS_DIR}/${GFXR_BASENAME}" "${JSON}"
268284
adb shell mkdir -p "${DUMP_DIR}"
269285
adb push "${JSON}" "${REMOTE_TEMP_DIR}"
@@ -290,7 +306,7 @@ python "${GFXRECON}" replay \
290306

291307
# `gfxrecon.py replay` does not wait for the app to start so. However, if it starts logging then we can assume that it has started.
292308
# This only works since we clear the logcat at the start of the test.
293-
if ! wait_for_logcat_line gfxrecon "Initializing GFXReconstruct capture layer"
309+
if ! wait_for_logcat_line gfxrecon "Loading state for captured frame"
294310
then
295311
adb bugreport
296312
fi
@@ -316,18 +332,23 @@ adb shell rm -rf "${REMOTE_TEMP_DIR}/${GFXR_BASENAME}"
316332
adb shell rm -rf "${REMOTE_TEMP_DIR}/${GFXA_BASENAME}"
317333
adb shell rm -rf "${REMOTE_TEMP_DIR}/${JSON_BASENAME}"
318334

319-
# Next launch should not use GFXR
320-
335+
# Next launch should not use GFXR. Likely redudant but doesn't hurt.
336+
unset_gfxr_props
337+
unset_vulkan_debug_settings
321338

322339
#
323340
# 8. Collect results
324341
#
325342

326-
# Show logcat for diagnostic purposes. Include DEBUG in case there was a crash.
343+
# Show logcat to the user for diagnostic purposes. Include DEBUG in case there was a crash.
327344
adb logcat -d -s gfxrecon,DEBUG
328345

329346
# Convert BMP captures into JPG for convenience.
330347
find "${RESULTS_DIR}" -name "*.bmp" | xargs -P0 -I {} convert {} {}.jpg
331348

349+
# Compress files to make them easier to share.
332350
tar czf "${RESULTS_DIR}.tgz" "${RESULTS_DIR}"
333-
echo "Results written to: ${RESULTS_DIR}"
351+
352+
set +x
353+
echo "------------------------------------------"
354+
echo "Results written to: ${RESULTS_DIR}.tgz"

0 commit comments

Comments
 (0)