Skip to content

fix(rocDecode): check decode caps up front in video_decode_batch, stop fake passes, and fix TheRock link order and enable its tests - #561

Open
zichguan-amd wants to merge 3 commits into
amd-stagingfrom
zichguan/rocdecode-batch-skip-unsupported
Open

zichguan-amd wants to merge 3 commits into
amd-stagingfrom
zichguan/rocdecode-batch-skip-unsupported

Conversation

@zichguan-amd

@zichguan-amd zichguan-amd commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

  • [Issue] Linux gfx90a: rocdecode AV1 tests fail with GPU doesn't support codec! rocm-systems#13446: upstream video_decodeBatch still fails on gfx90a (MI210) after #13518. The batch test decodes the whole rocDecode test-video directory, which includes two AV1 files, and gfx90a has no AV1 decode. The agreed redesign: 1) check the decode capability first, and 2) decode only the supported files. This PR applies that design to the rocm-examples port.
  • Fake passes in the current port. On amd-staging, video_decode_batch exits 0 even when it decodes nothing:
    • It uses RocVideoDecoder::CodecSupported(), which returns false both for an unsupported codec and for a failed rocDecGetDecoderCaps query. A broken VA-API setup therefore looks like "every codec unsupported": Total frame decoded: 0, exit 0.
    • An empty input directory exits 0.
    • An exception in main is printed, and the example still returns 0.
    • Upstream fixed the last two in rocm-systems#8636 ("Fix fake CTest passes"), which the rocm-examples port predates.
  • CMake builds on TheRock can't initialize VA-API. On a TheRock install, the CMake-built rocDecode examples that link FFmpeg load the system libva ahead of rocDecode's vendored one. vaInitialize then fails and rocDecGetDecoderCaps returns ROCDEC_RUNTIME_ERROR (reproduced with video_decode_batch; rocdec_decode fails the same way only if forced to link FFmpeg, which it doesn't do on TheRock). The Makefile builds are unaffected. CI always installs TheRock, so it doesn't catch this: these examples' ctests are disabled on TheRock by a gate copied from rocm-systems#3768, and make test runs the Makefile builds. With the old video_decode_batch this showed up as Total frame decoded: 0, exit 0.
  • Out of sync with upstream on TheRock testing. Upstream rocDecode has since fixed the link order (rocm-systems#8869) and runs these tests on TheRock again. rocm-examples still skips them there.

Technical Details

Libraries/rocDecode/video_decode_batch/main.cpp:

  • Step 1, capability check. This runs before any decoder is created.
    • For each input file, query rocDecGetDecoderCaps directly on every GPU device the decoder threads use. This is the same per-thread device mapping as before, now in a dec_device_id(i) lambda that is shared with the thread setup.
    • Unsupported (ROCDEC_SUCCESS with is_supported == 0): the file is dropped from the batch with info: skipping <file>, its codec isn't supported on the GPU.
    • Failed query: Error: rocDecGetDecoderCaps failed for <file>: <status>, exit 1.
  • Step 2, decode. Only the supported files are demuxed and decoded, and the thread count is capped to the supported-file count.
  • Fail-fast, matching upstream #8636:
    • An empty input directory is an error.
    • An input file that can't be opened as a video is an error: Error: Failed to open <file> as a video file.
    • n_total == 0 is an error: Error: No frames were decoded!.
    • The catch block returns 1.
  • CMakeLists.txt: SKIP_RETURN_CODE 77 on the test.
  • Makefile: make test prints ==> Skipping (no codec supported on this GPU): ... on exit 77 instead of failing, matching video_decode_raw.
  • README.md: Application Flow updated, and rocDecGetDecoderCaps added to the API list.

New cmake/RocDecodeLinkOrder.cmake, the TheRock link-order fix:

  • Cause. On TheRock, librocdecode depends on the libva vendored under lib/rocm_sysdeps/lib, while FFmpeg links the system libva, so both load.
    • rocdecode::rocdecode is an INTERFACE target, so CMake puts ${FFMPEG_LIBRARIES} ahead of librocdecode on the link line. libavcodec becomes the first NEEDED entry.
    • The system libva then wins VA symbol interposition and vaInitialize fails.
    • The Makefiles link -lrocdecode before FFmpeg and work.
  • Fix. link_rocdecode_first(<target>) links ${rocdecode_LIBRARY} as a raw path (-Wl,--push-state,--no-as-needed ... -Wl,--pop-state) ahead of the other libraries, on TheRock installs only.
    • This is the same workaround the upstream rocDecode samples use since rocm-systems#8869.
    • It is called in the 8 examples that link FFmpeg: video_decode, video_decode_batch, video_decode_mem, video_decode_multi_files, video_decode_perf, video_decode_pic_files, video_decode_rgb and video_to_sequence.
    • rocdec_decode only links FFmpeg on non-TheRock installs, so it is unchanged.

TheRock test gates removed, synced with upstream rocDecode tests:

  • The if (NOT USING_THE_ROCK) blocks around the tests of video_decode, video_decode_batch, video_decode_mem, video_decode_perf and video_decode_rgb are removed, so these tests now run on TheRock too. They still skip when the test video isn't installed.
  • As upstream does, video_decode-HEVC-host (rocdecode-host backend) still doesn't run on TheRock.
  • video_decode already reports -AV1 as skipped (exit 77) on GPUs without AV1 decode.

Upstream counterpart (rocm-systems samples/videoDecodeBatch): ROCm/rocm-systems#14383 applies the same design upstream for ROCm/rocm-systems#13446.

Test Plan

On gfx1100 (RX 7900 XTX) in ghcr.io/rocm/rocm-examples-ubuntu-24.04-rocm:10.1 (TheRock install, rocDecode 1.10.0):

  • make and make test.
  • CMake build of Libraries/rocDecode: ctest with no preload, and the first NEEDED entry of each binary.
  • The same with link_rocdecode_first() disabled, for comparison.
  • An LD_PRELOAD shim on rocDecGetDecoderCaps, in three modes:
    • clear is_supported for AV1, to simulate gfx90a
    • clear it for every codec
    • return ROCDEC_RUNTIME_ERROR
  • -t 1/2/4, -m 0 -o <dir>, HIP_VISIBLE_DEVICES=0, and an empty input directory.
  • A non-video file, alone and next to a valid file.
  • The same shim cases on the amd-staging baseline, for comparison.
  • pre-commit on the changed files.

Test Result

case amd-staging this PR
all supported 4207 frames, exit 0 4207 frames, exit 0
AV1 unsupported (gfx90a) 3005 frames, exit 0 2 files skipped up front, 3005 frames, exit 0 (also with -t 1/4 and HIP_VISIBLE_DEVICES=0)
nothing supported 0 frames, exit 0 exit 77: ctest Skipped, make test skip line
caps query fails 0 frames, exit 0 Error: rocDecGetDecoderCaps failed ..., exit 1: ctest Failed, make test fails
empty input dir 0 frames, exit 0 Error: No input files found ..., exit 1
non-video file (alone, or with a valid file) abort, rc 134 Error: Failed to open ... as a video file, exit 1
  • Link order and tests on TheRock: all 8 FFmpeg examples now have librocdecode.so.1 as their first NEEDED entry.
    • 15 rocDecode ctests are now registered on TheRock (6 before) and all pass with no preload: rocdec_decode, video_decode_caps, video_decode_raw-*, video_decode-*, video_decode_batch, video_decode_mem, video_decode_perf and video_decode_rgb[-resize].
    • With the AV1 shim, video_decode-AV1 is Skipped and video_decode_batch passes.
    • Without link_rocdecode_first(), the 9 newly enabled tests fail (video_decode_perf segfaults).
    • On amd-staging, the same CMake-built video_decode_batch fails vaInitialize and reports 0 frames, exit 0.
  • With -m 0 -o, output files are written only for the decoded files.
  • No new compiler warnings in main.cpp.
  • pre-commit passes.
  • Not run on actual gfx90a, gfx1151 or multi-GPU hardware.

Added/Updated documentation?

  • Yes
  • No, does not apply to this PR.

Included Visual Studio files?

  • Yes
  • No, does not apply to this PR.

Submission Checklist

🤖 Generated with Claude Code

…p fake passes, and fix TheRock link order

Query rocDecGetDecoderCaps for every input file on every GPU device the
decoder threads use before creating any decoder. Files whose codec isn't
supported (e.g. AV1 on gfx90a) are dropped from the batch; a failed query
is an error. If no file is supported, exit with skip_exit_code (77), and
report that as a skip in ctest (SKIP_RETURN_CODE) and make test.

Also fail instead of exiting 0 when the input directory is empty, when no
frames were decoded, and when an exception is caught, matching upstream
rocm-systems#8636.

On TheRock installs, CMake placed the FFmpeg libraries ahead of
librocdecode on the link line (rocdecode::rocdecode is an INTERFACE
target), so the system libva won symbol interposition over rocDecode's
vendored one and vaInitialize failed. Add link_rocdecode_first() in
cmake/RocDecodeLinkOrder.cmake, the same workaround as upstream
rocm-systems#8869, and call it in the rocDecode examples that link FFmpeg.

Co-Authored-By: Claude <noreply@anthropic.com>
@zichguan-amd
zichguan-amd requested review from a team as code owners October 27, 2026 15:11
The tests of video_decode, video_decode_batch, video_decode_mem,
video_decode_perf and video_decode_rgb were disabled on TheRock installs
by a gate copied from rocm-systems#3768. With the link order fixed, they
pass there, and upstream rocDecode runs them on TheRock again since
rocm-systems#8869. Remove the gates. As upstream does, the rocdecode-host
backend test still doesn't run on TheRock.

Co-Authored-By: Claude <noreply@anthropic.com>
@zichguan-amd zichguan-amd changed the title fix(rocDecode): check decode caps up front in video_decode_batch, stop fake passes, and fix TheRock link order fix(rocDecode): check decode caps up front in video_decode_batch, stop fake passes, and fix TheRock link order and enable its tests Oct 27, 2026
VideoDemuxer doesn't throw when it can't open a file or find a video
stream; it leaves the bit depth at 0 and the codec ID unset. The
capability check then read the unset codec ID and reported such a file
as an unsupported codec, so a non-video file in the input directory was
skipped (exit 77, or exit 0 next to valid files). Report it as an error.

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant