diff --git a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocdecode/defines.hpp b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocdecode/defines.hpp index cde821df96..affe75ec33 100644 --- a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocdecode/defines.hpp +++ b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocdecode/defines.hpp @@ -180,6 +180,12 @@ return std::vector{ \ GET_ADDR_MEMBER_FIELDS(get_api_data_args(trace_data.args), __VA_ARGS__)}; \ } \ + static auto as_arg_list(callback_data_type trace_data, int32_t max_deref) \ + { \ + return utils::stringize( \ + max_deref, \ + GET_NAMED_MEMBER_FIELDS(get_api_data_args(trace_data.args), __VA_ARGS__)); \ + } \ }; \ } \ } diff --git a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocdecode/details/CMakeLists.txt b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocdecode/details/CMakeLists.txt new file mode 100644 index 0000000000..a58de33532 --- /dev/null +++ b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocdecode/details/CMakeLists.txt @@ -0,0 +1,9 @@ +# +# +# +set(ROCPROFILER_LIB_ROCDECODE_DETAILS_SOURCES) +set(ROCPROFILER_LIB_ROCDECODE_DETAILS_HEADERS format.hpp) + +target_sources( + rocprofiler-sdk-object-library PRIVATE ${ROCPROFILER_LIB_ROCDECODE_DETAILS_SOURCES} + ${ROCPROFILER_LIB_ROCDECODE_DETAILS_HEADERS}) diff --git a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocdecode/details/format.hpp b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocdecode/details/format.hpp new file mode 100644 index 0000000000..0055222e07 --- /dev/null +++ b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocdecode/details/format.hpp @@ -0,0 +1,315 @@ +// MIT License +// +// Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#pragma once + +#include + +#include "fmt/core.h" + +#define ROCP_SDK_ROCDECODE_FORMATTER(TYPE, ...) \ + template <> \ + struct formatter : rocprofiler::rocdecode::details::base_formatter \ + { \ + template \ + auto format(const TYPE& v, Ctx& ctx) const \ + { \ + return fmt::format_to(ctx.out(), __VA_ARGS__); \ + } \ + }; + +#define ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(PREFIX, SUFFIX) \ + case PREFIX##_##SUFFIX: return fmt::format_to(ctx.out(), #SUFFIX) + +namespace rocprofiler +{ +namespace rocdecode +{ +namespace details +{ +struct base_formatter +{ + template + constexpr auto parse(ParseContext& ctx) + { + return ctx.begin(); + } +}; +} // namespace details +} // namespace rocdecode +} // namespace rocprofiler + +namespace fmt +{ +template <> +struct formatter : rocprofiler::rocdecode::details::base_formatter +{ + template + auto format(rocDecStatus v, Ctx& ctx) const + { + switch(v) + { + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(ROCDEC, DEVICE_INVALID); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(ROCDEC, CONTEXT_INVALID); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(ROCDEC, RUNTIME_ERROR); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(ROCDEC, OUTOF_MEMORY); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(ROCDEC, INVALID_PARAMETER); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(ROCDEC, NOT_IMPLEMENTED); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(ROCDEC, NOT_INITIALIZED); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(ROCDEC, NOT_SUPPORTED); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(ROCDEC, SUCCESS); + } + return fmt::format_to(ctx.out(), "Unknown"); + } +}; + +template <> +struct formatter : rocprofiler::rocdecode::details::base_formatter +{ + template + auto format(rocDecDecodeStatus v, Ctx& ctx) const + { + switch(v) + { + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecodeStatus, Invalid); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecodeStatus, InProgress); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecodeStatus, Success); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecodeStatus, Error); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecodeStatus, Error_Concealed); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecodeStatus, Displaying); + } + return fmt::format_to(ctx.out(), "Unknown"); + } +}; + +template <> +struct formatter : rocprofiler::rocdecode::details::base_formatter +{ + template + auto format(rocDecVideoCodec v, Ctx& ctx) const + { + switch(v) + { + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, MPEG1); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, MPEG2); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, MPEG4); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, AVC); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, HEVC); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, AV1); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, VP8); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, VP9); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, JPEG); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, NumCodecs); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, YUV420); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, YV12); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, NV12); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, YUYV); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, UYVY); + } + return fmt::format_to(ctx.out(), "Unknown"); + } +}; + +template <> +struct formatter : rocprofiler::rocdecode::details::base_formatter +{ + template + auto format(rocDecVideoChromaFormat v, Ctx& ctx) const + { + switch(v) + { + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoChromaFormat, Monochrome); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoChromaFormat, 420); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoChromaFormat, 422); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoChromaFormat, 444); + } + return fmt::format_to(ctx.out(), "Unknown"); + } +}; + +template <> +struct formatter : rocprofiler::rocdecode::details::base_formatter +{ + template + auto format(rocDecVideoSurfaceFormat v, Ctx& ctx) const + { + switch(v) + { + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoSurfaceFormat, NV12); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoSurfaceFormat, P016); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoSurfaceFormat, YUV444); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoSurfaceFormat, YUV444_16Bit); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoSurfaceFormat, YUV420); + ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoSurfaceFormat, YUV420_16Bit); + } + return fmt::format_to(ctx.out(), "Unknown"); + } +}; + +ROCP_SDK_ROCDECODE_FORMATTER( + _RocdecParserParams, + "{}codec_type={},max_num_decode_surfaces={}, clock_rate={}, error_threshold={}, " + "max_display_delay={}, annex_b={}, reserved={}, user_data={}, ext_video_info={}{}", + '{', + v.codec_type, + v.max_num_decode_surfaces, + v.clock_rate, + v.error_threshold, + v.max_display_delay, + v.annex_b, + v.reserved, + v.user_data, + static_cast(v.ext_video_info), + '}') + +ROCP_SDK_ROCDECODE_FORMATTER(RocdecTimeStamp, "{}RocdecTimeStamp={}{}", '{', v, '}') + +ROCP_SDK_ROCDECODE_FORMATTER(_RocdecSourceDataPacket, + "{}flags={}, payload_size={}, payload={}, pts={}{}", + '{', + v.flags, + v.payload_size, + static_cast(v.payload), + v.pts, + '}') + +ROCP_SDK_ROCDECODE_FORMATTER( + _RocDecoderCreateInfo, + "{}device_id={}, width={}, height={}, num_decode_surfaces={}, codec_type={}, chroma_format={}, " + "bit_depth_minus_8={}, intra_decode_only={}, max_width={}, max_height={}, " + "display_rect={}left={}, right={}, top={}, bottom={}{}, target_width={}, target_height={}, " + "num_output_surfaces={}, target_rect={}left={}, right={}, top={}, bottom={}{}{}", + '{', + v.device_id, + v.width, + v.height, + v.num_decode_surfaces, + v.codec_type, + v.chroma_format, + v.bit_depth_minus_8, + v.intra_decode_only, + v.max_width, + v.max_height, + '{', + v.display_rect.left, + v.display_rect.right, + v.display_rect.top, + v.display_rect.bottom, + '}', + v.target_width, + v.target_height, + v.num_output_surfaces, + '{', + v.target_rect.left, + v.target_rect.right, + v.target_rect.top, + v.target_rect.bottom, + '}', + '}') + +ROCP_SDK_ROCDECODE_FORMATTER(_RocdecReconfigureDecoderInfo, + "{}width={}, height={}, target_width={}, target_height={}, " + "num_decode_surfaces={}, display_rect={}left={}, right={}, top={}, " + "bottom={}{}, target_rect={}left={}, right={}, top={}, bottom={}{}{}", + '{', + v.width, + v.height, + v.target_width, + v.target_height, + v.num_decode_surfaces, + '{', + v.display_rect.left, + v.display_rect.right, + v.display_rect.top, + v.display_rect.bottom, + '}', + '{', + v.target_rect.left, + v.target_rect.right, + v.target_rect.top, + v.target_rect.bottom, + '}', + '}') + +ROCP_SDK_ROCDECODE_FORMATTER(_RocdecDecodeStatus, + "{}decode_status={}, p_reserved={}{}", + '{', + v.decode_status, + v.p_reserved, + '}') + +ROCP_SDK_ROCDECODE_FORMATTER( + _RocdecPicParams, + "{}pic_width={}, pic_height={}, curr_pic_idx={}, field_pic_flag={}, bottom_field_flag={}, " + "second_field={}, bitstream_data_len={}, bitstream_data={}, num_slices={}, ref_pic_flag={}, " + "intra_pic_flag={}{}", + '{', + v.pic_width, + v.pic_height, + v.curr_pic_idx, + v.field_pic_flag, + v.bottom_field_flag, + v.second_field, + v.bitstream_data_len, + static_cast(v.bitstream_data), + v.num_slices, + v.ref_pic_flag, + v.intra_pic_flag, + '}') + +ROCP_SDK_ROCDECODE_FORMATTER( + _RocdecDecodeCaps, + "{}device_id={}, codec_type={}, chroma_format={}, bit_depth_minus_8={}, is_supported={}, " + "num_decoders={}, output_format_mask={}, max_width={}, max_height={}, min_width={}, " + "min_height={}{}", + '{', + v.device_id, + v.codec_type, + v.chroma_format, + v.bit_depth_minus_8, + v.is_supported, + v.num_decoders, + v.output_format_mask, + v.max_width, + v.max_height, + v.min_width, + v.min_height, + '}') + +ROCP_SDK_ROCDECODE_FORMATTER( + _RocdecProcParams, + "{}progressive_frame={}, top_field_first={}, raw_input_dptr={}, raw_input_pitch={}, " + "raw_input_format={}, raw_output_dptr={}, raw_output_pitch={}, raw_output_format={}{}", + '{', + v.progressive_frame, + v.top_field_first, + v.raw_input_dptr, + v.raw_input_pitch, + v.raw_input_format, + v.raw_output_dptr, + v.raw_output_pitch, + v.raw_output_format, + '}') +} // namespace fmt + +#undef ROCP_SDK_ROCDECODE_FORMATTER +#undef ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT diff --git a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocdecode/rocdecode.cpp b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocdecode/rocdecode.cpp index 6dc74b4886..288815ee00 100644 --- a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocdecode/rocdecode.cpp +++ b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocdecode/rocdecode.cpp @@ -556,7 +556,9 @@ using rocdecode_op_args_cb_t = rocprofiler_callback_tracing_operation_args_cb_t; template const char* name_by_id(uint32_t); \ template uint32_t id_by_name(const char*); \ template std::vector get_ids(); \ - template std::vector get_names(); + template std::vector get_names(); \ + template void iterate_args( \ + uint32_t, const rocdecode_api_data_t&, rocdecode_op_args_cb_t, int32_t, void*); INSTANTIATE_ROCDECODE_TABLE_FUNC(rocdecode_api_func_table_t, ROCPROFILER_ROCDECODE_TABLE_ID_CORE) } // namespace rocdecode diff --git a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocdecode/rocdecode.def.cpp b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocdecode/rocdecode.def.cpp index 5c0a4b0e30..8f58dfde4b 100644 --- a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocdecode/rocdecode.def.cpp +++ b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocdecode/rocdecode.def.cpp @@ -22,6 +22,7 @@ #include "lib/rocprofiler-sdk/rocdecode/defines.hpp" #include "lib/rocprofiler-sdk/rocdecode/rocdecode.hpp" +#include "lib/rocprofiler-sdk/rocdecode/utils.hpp" #include #include diff --git a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocdecode/utils.hpp b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocdecode/utils.hpp new file mode 100644 index 0000000000..996419c015 --- /dev/null +++ b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocdecode/utils.hpp @@ -0,0 +1,68 @@ +// MIT License +// +// Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#pragma once + +#include "lib/common/stringize_arg.hpp" +#include "lib/rocprofiler-sdk/rocdecode/details/format.hpp" + +#include "fmt/core.h" +#include "fmt/ranges.h" + +#include +#include + +namespace rocprofiler +{ +namespace rocdecode +{ +namespace utils +{ +template +auto +stringize_impl(const Tp& _v) +{ + using value_type = std::decay_t; + + if constexpr(fmt::is_formattable::value && !std::is_pointer::value) + { + return fmt::format("{}", _v); + } + else + { + auto _ss = std::stringstream{}; + _ss << _v; + return _ss.str(); + } +} + +template +auto +stringize(int32_t max_deref, Args... args) +{ + using array_type = common::stringified_argument_array_t; + return array_type{common::stringize_arg( + max_deref, args, [](const auto& _v) { return stringize_impl(_v); })...}; +} +} // namespace utils +} // namespace rocdecode +} // namespace rocprofiler