Repository navigation
[rocDecode] Feature: Add support for user set output surface format. - #4229
jeffqjiangNew merged 11 commits into
Conversation
…e coded stream and allow user to surface format of lower bit depth. - On 10 bit and up streams, the user can set output surface to 8 bit. - Added output format parameter to decoder reconfigure API. - Added output surface format command option to rocdecdecode sample.
…coder reconfig API to avoid potentially breaking the current user workflow. Added a new output surface format to indicate that the output surface format is determined by the stream content.
There was a problem hiding this comment.
Pull request overview
This PR introduces a new rocDecode capability to let callers request a specific decoded output surface format (or defer to a “native” format derived from stream chroma format + bit depth), with VA-API backend support and a sample CLI option to exercise the feature.
Changes:
- Added
rocDecVideoSurfaceFormat_Nativeto represent auto-selected (“native”) output format. - Implemented output-format resolution/override logic in the VA-API decoder (including limited validation/adjustment).
- Updated the
rocdecdecodesample to accept-o_formatand updated some chroma helper switches to includedefault.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
projects/rocdecode/api/rocdecode/rocdecode.h |
Adds rocDecVideoSurfaceFormat_Native enum value for “auto/native” output selection. |
projects/rocdecode/src/rocdecode/vaapi/vaapi_videodecoder.h |
Adds state + helper method declarations to track/resolve output-format override vs native selection. |
projects/rocdecode/src/rocdecode/vaapi/vaapi_videodecoder.cpp |
Implements native/override output-format selection and applies it during init + reconfigure; adds special-case NV12 override for >8-bit 4:2:0 streams. |
projects/rocdecode/utils/rocvideodecode/roc_video_dec.cpp |
Passes Native output format to decoder creation (intended to let backend choose output format). |
projects/rocdecode/utils/rocvideodecode/roc_video_dec.h |
Adds default cases to chroma helper switches (likely to cover new enum). |
projects/rocdecode/utils/ffmpegvideodecode/ffmpeg_video_dec.cpp |
Adds default to chroma width-factor switch. |
projects/rocdecode/samples/rocdecDecode/rocdecdecode.cpp |
Adds -o_format and -f CLI options; tracks whether output format is user-overridden; updates chroma helper switches. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… document. Addressed several review comments.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Comments suppressed due to low confidence (1)
projects/rocdecode/src/rocdecode/vaapi/vaapi_videodecoder.cpp:583
- In CreateSurfaces(), the VASurfaceAttribPixelFormat attribute (surf_attrib.value.value.i) is only set for Monochrome and 4:2:0, but for 4:2:2 and 4:4:4 cases it remains uninitialized and is still pushed into surf_attribs. This is undefined behavior and can lead to vaCreateSurfaces using a garbage/incorrect pixel format. Initialize surf_attrib (e.g., zero-initialize) and set a valid FOURCC for every chroma_format/bit-depth path, or only push the PixelFormat attribute when its value is explicitly set.
VASurfaceAttrib surf_attrib;
surf_attrib.type = VASurfaceAttribPixelFormat;
surf_attrib.flags = VA_SURFACE_ATTRIB_SETTABLE;
surf_attrib.value.type = VAGenericValueTypeInteger;
uint32_t surface_format;
switch (decoder_create_info_.chroma_format) {
case rocDecVideoChromaFormat_Monochrome: {
surface_format = VA_RT_FORMAT_YUV400;
surf_attrib.value.value.i = VA_FOURCC_Y800;
}
break;
case rocDecVideoChromaFormat_420: {
// If the user sets the output surface format
// Special case for 8-bit output requirement even when the stream is 10-bit and above
if (output_surface_format_override_ && decoder_create_info_.output_format == rocDecVideoSurfaceFormat_NV12) {
surface_format = VA_RT_FORMAT_YUV420;
surf_attrib.value.value.i = VA_FOURCC_NV12;
} else {
if (decoder_create_info_.bit_depth_minus_8 == 2) {
surface_format = VA_RT_FORMAT_YUV420_10;
surf_attrib.value.value.i = VA_FOURCC_P010;
} else if (decoder_create_info_.bit_depth_minus_8 == 4) {
surface_format = VA_RT_FORMAT_YUV420_12;
surf_attrib.value.value.i = VA_FOURCC_P012;
} else {
surface_format = VA_RT_FORMAT_YUV420;
surf_attrib.value.value.i = VA_FOURCC_NV12;
}
}
}
break;
case rocDecVideoChromaFormat_422:
surface_format = VA_RT_FORMAT_YUV422;
break;
case rocDecVideoChromaFormat_444:
surface_format = VA_RT_FORMAT_YUV444;
break;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
projects/rocdecode/src/rocdecode/vaapi/vaapi_videodecoder.cpp:583
- In
CreateSurfaces(),surf_attrib.value.value.i(the requested FOURCC) is not set forrocDecVideoChromaFormat_422androcDecVideoChromaFormat_444, butsurf_attribis still pushed intosurf_attribs. This leaves the FOURCC uninitialized/leftover from prior cases and can cause undefined behavior or surface creation failures. Initializesurf_attrib(e.g., zero it) and setvalue.value.ifor every chroma case, or only add the pixel-format attrib when it’s explicitly set (and/or map 4:2:2/4:4:4 to the correct VA_FOURCC values).
case rocDecVideoChromaFormat_422:
surface_format = VA_RT_FORMAT_YUV422;
break;
case rocDecVideoChromaFormat_444:
surface_format = VA_RT_FORMAT_YUV444;
break;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
rrawther
left a comment
There was a problem hiding this comment.
Let's discuss this PR. We don't need to add new format.
There was a problem hiding this comment.
@jeffqjiangNew please bump the rocdecode version to 1.8 in the main CMakeLists.txt and in the changelog.
Please also provide the output of ctest -VV for the build/tests using the TheRock tarball.
…4229) ## Motivation This PR adds a new rocDecode feature: support for user specified output surface format. ## Technical Details In certain use cases, the user requests a decoded image format that is not the native format based on the stream content. For example, 8-bit output is needed on a 10-bit stream. This PR enables the output format selection as long as it is supported by the VA-API driver. - Added a special output format define to indicate if the output format is user set or native. - VA-API decoder now sets the surface format either native or by user override. - Added the output format command option to rocdecdecode sample for feature verification. ## JIRA ID <!-- If applicable, mention the JIRA ID resolved by this PR (Example: Resolves SWDEV-12345). --> <!-- Do not post any JIRA links here. --> ## Test Plan - Run CTests and decode conformance tests to catch any regressions. - Run rocdecdecode samples to verify user set output. ## Test Result All CTests and conformance tests pass. Example summary of the test results: CTests: Start 1: video_decodeRaw-HEVC 1/15 Test #1: video_decodeRaw-HEVC ............. Passed 2.05 sec Start 2: video_decodeRaw-AVC 2/15 Test #2: video_decodeRaw-AVC .............. Passed 1.89 sec Start 3: video_decodeRaw-AV1 3/15 Test #3: video_decodeRaw-AV1 .............. Passed 2.31 sec Start 4: video_decodeRaw-VP9 4/15 Test #4: video_decodeRaw-VP9 .............. Passed 2.04 sec Start 5: rocdec_Decode-HEVC 5/15 Test #5: rocdec_Decode-HEVC ............... Passed 0.92 sec Start 6: rocDecode_Negative_API_Tests 6/15 Test #6: rocDecode_Negative_API_Tests ..... Passed 0.78 sec Start 7: video_decode-HEVC 7/15 Test #7: video_decode-HEVC ................ Passed 2.74 sec Start 8: video_decode-AVC 8/15 Test #8: video_decode-AVC ................. Passed 2.64 sec Start 9: video_decode-AV1 9/15 Test #9: video_decode-AV1 ................. Passed 2.74 sec Start 10: video_decode-VP9 10/15 Test #10: video_decode-VP9 ................. Passed 2.78 sec Start 11: video_decodePerf-HEVC 11/15 Test #11: video_decodePerf-HEVC ............ Passed 2.92 sec Start 12: video_decodeBatch 12/15 Test #12: video_decodeBatch ................ Passed 4.34 sec Start 13: video_decodeRGB-HEVC 13/15 Test #13: video_decodeRGB-HEVC ............. Passed 33.51 sec Start 14: video_decodeMem-HEVC 14/15 Test #14: video_decodeMem-HEVC ............. Passed 2.09 sec Start 15: video_decodeRGB-Resize 15/15 Test #15: video_decodeRGB-Resize ........... Passed 33.94 sec 100% tests passed, 0 tests failed out of 15 AVC conformance test: Conformance test completed on the 127 streams: The number of passing streams is 127 The number of failing streams is 0 The number of streams that did not finish decoding is 0 HEVC conformance test: Conformance test completed on the 135 streams: The number of passing streams is 135 The number of failing streams is 0 The number of streams that did not finish decoding is 0 AV1 conformance test: Conformance test completed on the 162 streams: The number of passing streams is 162 The number of failing streams is 0 The number of streams that did not finish decoding is 0 VP9 conformance test: Conformance test completed on the 108 streams: The number of passing streams is 108 The number of failing streams is 0 The number of streams that did not finish decoding is 0 <!-- Briefly summarize test outcomes. --> rocdecdecode sample dumps the clean output YUV clips of the specified format (NV12 or P016). ## Submission Checklist - [ ] Look over the contributing guidelines at https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
Motivation
This PR adds a new rocDecode feature: support for user specified output surface format.
Technical Details
In certain use cases, the user requests a decoded image format that is not the native format based on the stream content. For example, 8-bit output is needed on a 10-bit stream. This PR enables the output format selection as long as it is supported by the VA-API driver.
JIRA ID
Test Plan
Test Result
All CTests and conformance tests pass. Example summary of the test results:
CTests:
Start 1: video_decodeRaw-HEVC
1/15 Test #1: video_decodeRaw-HEVC ............. Passed 2.05 sec
Start 2: video_decodeRaw-AVC
2/15 Test #2: video_decodeRaw-AVC .............. Passed 1.89 sec
Start 3: video_decodeRaw-AV1
3/15 Test #3: video_decodeRaw-AV1 .............. Passed 2.31 sec
Start 4: video_decodeRaw-VP9
4/15 Test #4: video_decodeRaw-VP9 .............. Passed 2.04 sec
Start 5: rocdec_Decode-HEVC
5/15 Test #5: rocdec_Decode-HEVC ............... Passed 0.92 sec
Start 6: rocDecode_Negative_API_Tests
6/15 Test #6: rocDecode_Negative_API_Tests ..... Passed 0.78 sec
Start 7: video_decode-HEVC
7/15 Test #7: video_decode-HEVC ................ Passed 2.74 sec
Start 8: video_decode-AVC
8/15 Test #8: video_decode-AVC ................. Passed 2.64 sec
Start 9: video_decode-AV1
9/15 Test #9: video_decode-AV1 ................. Passed 2.74 sec
Start 10: video_decode-VP9
10/15 Test #10: video_decode-VP9 ................. Passed 2.78 sec
Start 11: video_decodePerf-HEVC
11/15 Test #11: video_decodePerf-HEVC ............ Passed 2.92 sec
Start 12: video_decodeBatch
12/15 Test #12: video_decodeBatch ................ Passed 4.34 sec
Start 13: video_decodeRGB-HEVC
13/15 Test #13: video_decodeRGB-HEVC ............. Passed 33.51 sec
Start 14: video_decodeMem-HEVC
14/15 Test #14: video_decodeMem-HEVC ............. Passed 2.09 sec
Start 15: video_decodeRGB-Resize
15/15 Test #15: video_decodeRGB-Resize ........... Passed 33.94 sec
100% tests passed, 0 tests failed out of 15
AVC conformance test:
Conformance test completed on the 127 streams:
The number of passing streams is 127
The number of failing streams is 0
The number of streams that did not finish decoding is 0
HEVC conformance test:
Conformance test completed on the 135 streams:
The number of passing streams is 135
The number of failing streams is 0
The number of streams that did not finish decoding is 0
AV1 conformance test:
Conformance test completed on the 162 streams:
The number of passing streams is 162
The number of failing streams is 0
The number of streams that did not finish decoding is 0
VP9 conformance test:
Conformance test completed on the 108 streams:
The number of passing streams is 108
The number of failing streams is 0
The number of streams that did not finish decoding is 0
rocdecdecode sample dumps the clean output YUV clips of the specified format (NV12 or P016).
Submission Checklist