Debian Codegraph @

media_softlet/agnostic/common/codec/hal/codechal_debug.cpp

raw
1 /*
2 * Copyright (c) 2011-2023, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file codechal_debug.cpp
24 //! \brief Defines the debug interface shared by codec only.
25 //! \details The debug interface dumps output from Media based on in input config file.
26 //!
27 #include "codechal_debug.h"
28 #if USE_CODECHAL_DEBUG_TOOL
29 #include "codechal_debug_config_manager.h"
30 #include "media_debug_fast_dump.h"
31 #include <iomanip>
32
33 #define QUERY_STATUS_BUFFER_INITIAL_VALUE 0xf
34 #define STORE_DATA_DWORD_DATA 0x01010102
35
36 // AVC Decode
37 std::ostream &operator<<(std::ostream &oss, const CODEC_AVC_PIC_PARAMS &cr)
38 {
39 const CODEC_AVC_PIC_PARAMS *picParams = &cr;
40
41 oss << "CurrPic FrameIdx: " << +picParams->CurrPic.FrameIdx << std::endl;
42 oss << "CurrPic PicFlags: " << +picParams->CurrPic.PicFlags << std::endl;
43
44 // Dump RefFrameList[15]
45 for (uint8_t i = 0; i < 15; ++i)
46 {
47 oss << "RefFrameList[" << +i << "] FrameIdx:" << +picParams->RefFrameList[i].FrameIdx << std::endl;
48 oss << "RefFrameList[" << +i << "] PicFlags:" << +picParams->RefFrameList[i].PicFlags << std::endl;
49 }
50
51 oss << "pic_width_in_mbs_minus1: " << +picParams->pic_width_in_mbs_minus1 << std::endl;
52 oss << "pic_height_in_mbs_minus1: " << +picParams->pic_height_in_mbs_minus1 << std::endl;
53 oss << "bit_depth_luma_minus8: " << +picParams->bit_depth_luma_minus8 << std::endl;
54 oss << "bit_depth_chroma_minus8: " << +picParams->bit_depth_chroma_minus8 << std::endl;
55 oss << "num_ref_frames: " << +picParams->num_ref_frames << std::endl;
56 oss << "CurrFieldOrderCnt: " << +picParams->CurrFieldOrderCnt[0] << std::endl;
57 oss << "CurrFieldOrderCnt: " << +picParams->CurrFieldOrderCnt[1] << std::endl;
58
59 // Dump FieldOrderCntList (16x2)
60 for (uint8_t i = 0; i < 2; ++i)
61 {
62 oss << "FieldOrderCntList[" << +i << "]:";
63 for (uint8_t j = 0; j < 16; j++)
64 oss << +picParams->FieldOrderCntList[j][i] << " ";
65 oss << std::endl;
66 }
67
68 // Dump seq_fields
69 oss << "seq_fields value: " << +picParams->seq_fields.value << std::endl;
70 oss << "chroma_format_idc: " << +picParams->seq_fields.chroma_format_idc << std::endl;
71 oss << "residual_colour_transform_flag: " << +picParams->seq_fields.residual_colour_transform_flag << std::endl;
72 oss << "frame_mbs_only_flag: " << +picParams->seq_fields.frame_mbs_only_flag << std::endl;
73 oss << "mb_adaptive_frame_field_flag: " << +picParams->seq_fields.mb_adaptive_frame_field_flag << std::endl;
74 oss << "direct_8x8_inference_flag: " << +picParams->seq_fields.direct_8x8_inference_flag << std::endl;
75 oss << "log2_max_frame_num_minus4: " << +picParams->seq_fields.log2_max_frame_num_minus4 << std::endl;
76 oss << "pic_order_cnt_type: " << +picParams->seq_fields.pic_order_cnt_type << std::endl;
77 oss << "log2_max_pic_order_cnt_lsb_minus4: " << +picParams->seq_fields.log2_max_pic_order_cnt_lsb_minus4 << std::endl;
78 oss << "delta_pic_order_always_zero_flag: " << +picParams->seq_fields.delta_pic_order_always_zero_flag << std::endl;
79 oss << "num_slice_groups_minus1:" << +picParams->num_slice_groups_minus1 << std::endl;
80 oss << "slice_group_map_type:" << +picParams->slice_group_map_type << std::endl;
81 oss << "slice_group_change_rate_minus1:" << +picParams->slice_group_change_rate_minus1 << std::endl;
82 oss << "pic_init_qp_minus26:" << +picParams->pic_init_qp_minus26 << std::endl;
83 oss << "chroma_qp_index_offset:" << +picParams->chroma_qp_index_offset << std::endl;
84 oss << "second_chroma_qp_index_offset:" << +picParams->second_chroma_qp_index_offset << std::endl;
85
86 // Dump pic_fields
87 oss << "pic_fields value: " << +picParams->pic_fields.value << std::endl;
88 oss << "entropy_coding_mode_flag: " << +picParams->pic_fields.entropy_coding_mode_flag << std::endl;
89 oss << "weighted_pred_flag: " << +picParams->pic_fields.weighted_pred_flag << std::endl;
90 oss << "weighted_bipred_idc: " << +picParams->pic_fields.weighted_bipred_idc << std::endl;
91 oss << "transform_8x8_mode_flag: " << +picParams->pic_fields.transform_8x8_mode_flag << std::endl;
92 oss << "field_pic_flag: " << +picParams->pic_fields.field_pic_flag << std::endl;
93 oss << "constrained_intra_pred_flag: " << +picParams->pic_fields.constrained_intra_pred_flag << std::endl;
94 oss << "pic_order_present_flag: " << +picParams->pic_fields.pic_order_present_flag << std::endl;
95 oss << "deblocking_filter_control_present_flag: " << +picParams->pic_fields.deblocking_filter_control_present_flag << std::endl;
96 oss << "redundant_pic_cnt_present_flag: " << +picParams->pic_fields.redundant_pic_cnt_present_flag << std::endl;
97 oss << "reference_pic_flag: " << +picParams->pic_fields.reference_pic_flag << std::endl;
98 oss << "IntraPicFlag: " << +picParams->pic_fields.IntraPicFlag << std::endl;
99
100 // Dump Short format specific
101 oss << "num_ref_idx_l0_active_minus1: " << +picParams->num_ref_idx_l0_active_minus1 << std::endl;
102 oss << "num_ref_idx_l1_active_minus1: " << +picParams->num_ref_idx_l1_active_minus1 << std::endl;
103 oss << "NonExistingFrameFlags: " << +picParams->NonExistingFrameFlags << std::endl;
104 oss << "UsedForReferenceFlags: " << +picParams->UsedForReferenceFlags << std::endl;
105 oss << "frame_num: " << +picParams->frame_num << std::endl;
106 oss << "StatusReportFeedbackNumber: " << +picParams->StatusReportFeedbackNumber << std::endl;
107
108 // Dump FrameNumList[16]
109 oss << "scaling_list_present_flag_buffer:";
110 for (uint8_t i = 0; i < 16; i++)
111 oss << picParams->FrameNumList[i];
112 oss << std::endl;
113
114 return oss;
115 }
116
117 std::ostream &operator<<(std::ostream &oss, const CODEC_AVC_SF_SLICE_PARAMS &cr)
118 {
119 const CODEC_AVC_SF_SLICE_PARAMS *sliceControl = &cr;
120
121 oss << "slice_data_size: " << +sliceControl->slice_data_size << std::endl;
122 oss << "slice_data_offset: " << +sliceControl->slice_data_offset << std::endl;
123 oss << std::endl;
124
125 return oss;
126 }
127
128 std::ostream &operator<<(std::ostream &oss, const CODEC_AVC_SLICE_PARAMS &cr)
129 {
130 const CODEC_AVC_SLICE_PARAMS *sliceControl = &cr;
131
132 oss << "slice_data_size: " << +sliceControl->slice_data_size << std::endl;
133 oss << "slice_data_offset: " << +sliceControl->slice_data_offset << std::endl;
134
135 // Dump Long format Params
136 oss << std::endl;
137 oss << "// Long Format Specific" << std::endl;
138 oss << "slice_data_bit_offset: " << +sliceControl->slice_data_bit_offset << std::endl;
139 oss << "first_mb_in_slice: " << +sliceControl->first_mb_in_slice << std::endl;
140 oss << "NumMbsForSlice: " << +sliceControl->NumMbsForSlice << std::endl;
141 oss << "slice_type: " << +sliceControl->slice_type << std::endl;
142 oss << "direct_spatial_mv_pred_flag: " << +sliceControl->direct_spatial_mv_pred_flag << std::endl;
143 oss << "num_ref_idx_l0_active_minus1: " << +sliceControl->num_ref_idx_l0_active_minus1 << std::endl;
144 oss << "num_ref_idx_l1_active_minus1: " << +sliceControl->num_ref_idx_l1_active_minus1 << std::endl;
145 oss << "cabac_init_idc: " << +sliceControl->cabac_init_idc << std::endl;
146 oss << "slice_qp_delta: " << +sliceControl->slice_qp_delta << std::endl;
147 oss << "disable_deblocking_filter_idc: " << +sliceControl->disable_deblocking_filter_idc << std::endl;
148 oss << "slice_alpha_c0_offset_div2: " << +sliceControl->slice_alpha_c0_offset_div2 << std::endl;
149 oss << "slice_beta_offset_div2: " << +sliceControl->slice_beta_offset_div2 << std::endl;
150
151 // Dump RefPicList[2][32]
152 for (uint8_t i = 0; i < 32; ++i)
153 {
154 oss << "RefPicList[0][" << +i << "] FrameIdx: " << +sliceControl->RefPicList[0][i].FrameIdx << std::endl;
155 oss << "RefPicList[0][" << +i << "] PicFlags: " << +sliceControl->RefPicList[0][i].PicFlags << std::endl;
156 oss << "RefPicList[1][" << +i << "] FrameIdx: " << +sliceControl->RefPicList[1][i].FrameIdx << std::endl;
157 oss << "RefPicList[1][" << +i << "] PicFlags: " << +sliceControl->RefPicList[1][i].PicFlags << std::endl;
158 }
159
160 oss << "luma_log2_weight_denom: " << +sliceControl->luma_log2_weight_denom << std::endl;
161 oss << "chroma_log2_weight_denom: " << +sliceControl->chroma_log2_weight_denom << std::endl;
162 oss << "slice_id: " << +sliceControl->slice_id << std::endl;
163
164 // Dump Weights[2][32][3][2]
165 for (uint8_t i = 0; i < 32; ++i)
166 {
167 oss << "Weights[0][" << +i << "][0][0]: " << +sliceControl->Weights[0][i][0][0] << std::endl;
168 oss << "Weights[0][" << +i << "][0][1]: " << +sliceControl->Weights[0][i][0][1] << std::endl;
169 oss << "Weights[0][" << +i << "][1][0]: " << +sliceControl->Weights[0][i][1][0] << std::endl;
170 oss << "Weights[0][" << +i << "][1][1]: " << +sliceControl->Weights[0][i][1][1] << std::endl;
171 oss << "Weights[1][" << +i << "][0][0]: " << +sliceControl->Weights[1][i][0][0] << std::endl;
172 oss << "Weights[1][" << +i << "][0][1]: " << +sliceControl->Weights[1][i][0][1] << std::endl;
173 oss << "Weights[1][" << +i << "][1][0]: " << +sliceControl->Weights[1][i][1][0] << std::endl;
174 oss << "Weights[1][" << +i << "][1][1]: " << +sliceControl->Weights[1][i][1][1] << std::endl;
175 oss << "Weights[0][" << +i << "][2][0]: " << +sliceControl->Weights[0][i][2][0] << std::endl;
176 oss << "Weights[0][" << +i << "][2][1]: " << +sliceControl->Weights[0][i][2][1] << std::endl;
177 oss << "Weights[1][" << +i << "][2][0]: " << +sliceControl->Weights[1][i][2][0] << std::endl;
178 oss << "Weights[1][" << +i << "][2][1]: " << +sliceControl->Weights[1][i][2][1] << std::endl;
179 }
180
181 oss << std::endl;
182
183 return oss;
184 }
185
186 std::ostream &operator<<(std::ostream &oss, const CODEC_AVC_IQ_MATRIX_PARAMS &cr)
187 {
188 const CODEC_AVC_IQ_MATRIX_PARAMS *iqParams = &cr;
189
190 uint32_t idx, idx2;
191 // 4x4 block
192 for (idx2 = 0; idx2 < 6; idx2++)
193 {
194 oss << "Qmatrix_H264_ScalingLists4x4[" << +idx2 << "]:" << std::endl;
195 for (idx = 0; idx < 12; idx += 4)
196 {
197 oss << "ScalingList4x4[" << +idx / 4 << "]:";
198 oss << +iqParams->ScalingList4x4[idx2][idx] << " ";
199 oss << +iqParams->ScalingList4x4[idx2][idx + 1] << " ";
200 oss << +iqParams->ScalingList4x4[idx2][idx + 2] << " ";
201 oss << +iqParams->ScalingList4x4[idx2][idx + 3] << " ";
202 oss << std::endl;
203 }
204 oss << std::endl;
205 }
206 // 8x8 block
207 for (idx2 = 0; idx2 < 2; idx2++)
208 {
209 oss << "Qmatrix_H264_ScalingLists8x8[" << +idx2 << "]:" << std::endl;
210 for (idx = 0; idx < 56; idx += 8)
211 {
212 oss << "ScalingList8x8[" << +idx / 8 << "]:";
213 oss << +iqParams->ScalingList8x8[idx2][idx] << " ";
214 oss << +iqParams->ScalingList8x8[idx2][idx + 1] << " ";
215 oss << +iqParams->ScalingList8x8[idx2][idx + 2] << " ";
216 oss << +iqParams->ScalingList8x8[idx2][idx + 3] << " ";
217 oss << +iqParams->ScalingList8x8[idx2][idx + 4] << " ";
218 oss << +iqParams->ScalingList8x8[idx2][idx + 5] << " ";
219 oss << +iqParams->ScalingList8x8[idx2][idx + 6] << " ";
220 oss << +iqParams->ScalingList8x8[idx2][idx + 7] << " ";
221 oss << std::endl;
222 }
223 oss << std::endl;
224 }
225
226 return oss;
227 }
228
229 void DumpDecodeAvcPicParams(PCODEC_AVC_PIC_PARAMS picParams, std::string fileName)
230 {
231 std::ostringstream oss;
232 oss.setf(std::ios::showbase | std::ios::uppercase);
233
234 oss << *picParams << std::endl;
235
236 std::ofstream ofs(fileName, std::ios::out);
237 ofs << oss.str();
238 ofs.close();
239 }
240
241 void DumpDecodeAvcSliceParams(PCODEC_AVC_SLICE_PARAMS sliceParams, uint32_t numSlices, std::string fileName, bool shortFormatInUse)
242 {
243 std::ostringstream oss;
244 oss.setf(std::ios::showbase | std::ios::uppercase);
245
246 if (numSlices > 1)
247 {
248 oss << "Total Num: " << numSlices << std::endl;
249 oss << std::endl;
250 }
251
252 for (uint16_t i = 0; i < numSlices; i++)
253 {
254 if (numSlices > 1)
255 {
256 oss << "---------Index = " << i << "---------" << std::endl;
257 }
258
259 if (shortFormatInUse)
260 {
261 oss << reinterpret_cast<CODEC_AVC_SF_SLICE_PARAMS &>(sliceParams[i]) << std::endl;
262 }
263 else
264 {
265 oss << sliceParams[i] << std::endl;
266 }
267 }
268
269 std::ofstream ofs(fileName, std::ios::out);
270 ofs << oss.str();
271 ofs.close();
272 }
273
274 void DumpDecodeAvcIQParams(PCODEC_AVC_IQ_MATRIX_PARAMS iqParams, std::string fileName)
275 {
276 std::ostringstream oss;
277 oss.setf(std::ios::showbase | std::ios::uppercase);
278
279 oss << *iqParams << std::endl;
280
281 std::ofstream ofs(fileName, std::ios::out);
282 ofs << oss.str();
283 ofs.close();
284 }
285
286 // HEVC Decode
287 std::ostream &operator<<(std::ostream &oss, const CODEC_HEVC_PIC_PARAMS &cr)
288 {
289 const CODEC_HEVC_PIC_PARAMS *picParams = &cr;
290
291 oss << "PicWidthInMinCbsY: " << +picParams->PicWidthInMinCbsY << std::endl;
292 oss << "PicHeightInMinCbsY: " << +picParams->PicHeightInMinCbsY << std::endl;
293
294 // FormatAndSequenceInfoFlags
295 oss << "chroma_format_idc: " << +picParams->chroma_format_idc << std::endl;
296 oss << "separate_colour_plane_flag: " << +picParams->separate_colour_plane_flag << std::endl;
297 oss << "bit_depth_luma_minus8: " << +picParams->bit_depth_luma_minus8 << std::endl;
298 oss << "bit_depth_chroma_minus8: " << +picParams->bit_depth_chroma_minus8 << std::endl;
299 oss << "log2_max_pic_order_cnt_lsb_minus4: " << +picParams->log2_max_pic_order_cnt_lsb_minus4 << std::endl;
300 oss << "NoPicReorderingFlag: " << +picParams->NoPicReorderingFlag << std::endl;
301 oss << "ReservedBits1: " << +picParams->ReservedBits1 << std::endl;
302 oss << "wFormatAndSequenceInfoFlags: " << +picParams->wFormatAndSequenceInfoFlags << std::endl;
303 oss << "CurrPic FrameIdx: " << +picParams->CurrPic.FrameIdx << std::endl;
304 oss << "CurrPic PicFlags: " << +picParams->CurrPic.PicFlags << std::endl;
305 oss << "sps_max_dec_pic_buffering_minus1: " << +picParams->sps_max_dec_pic_buffering_minus1 << std::endl;
306 oss << "log2_min_luma_coding_block_size_minus3: " << +picParams->log2_min_luma_coding_block_size_minus3 << std::endl;
307 oss << "log2_diff_max_min_luma_coding_block_size: " << +picParams->log2_diff_max_min_luma_coding_block_size << std::endl;
308 oss << "log2_min_transform_block_size_minus2: " << +picParams->log2_min_transform_block_size_minus2 << std::endl;
309 oss << "log2_diff_max_min_transform_block_size: " << +picParams->log2_diff_max_min_transform_block_size << std::endl;
310 oss << "max_transform_hierarchy_depth_intra: " << +picParams->max_transform_hierarchy_depth_intra << std::endl;
311 oss << "max_transform_hierarchy_depth_inter: " << +picParams->max_transform_hierarchy_depth_inter << std::endl;
312 oss << "num_short_term_ref_pic_sets: " << +picParams->num_short_term_ref_pic_sets << std::endl;
313 oss << "num_long_term_ref_pic_sps: " << +picParams->num_long_term_ref_pic_sps << std::endl;
314 oss << "num_ref_idx_l0_default_active_minus1: " << +picParams->num_ref_idx_l0_default_active_minus1 << std::endl;
315 oss << "num_ref_idx_l1_default_active_minus1: " << +picParams->num_ref_idx_l1_default_active_minus1 << std::endl;
316 oss << "init_qp_minus26: " << +picParams->init_qp_minus26 << std::endl;
317 oss << "ucNumDeltaPocsOfRefRpsIdx: " << +picParams->ucNumDeltaPocsOfRefRpsIdx << std::endl;
318 oss << "wNumBitsForShortTermRPSInSlice: " << +picParams->wNumBitsForShortTermRPSInSlice << std::endl;
319 oss << "ReservedBits2: " << +picParams->ReservedBits2 << std::endl;
320
321 // CodingParamToolFlags
322 oss << "scaling_list_enabled_flag: " << +picParams->scaling_list_enabled_flag << std::endl;
323 oss << "amp_enabled_flag: " << +picParams->amp_enabled_flag << std::endl;
324 oss << "sample_adaptive_offset_enabled_flag: " << +picParams->sample_adaptive_offset_enabled_flag << std::endl;
325 oss << "pcm_enabled_flag: " << +picParams->pcm_enabled_flag << std::endl;
326 oss << "pcm_sample_bit_depth_luma_minus1: " << +picParams->pcm_sample_bit_depth_luma_minus1 << std::endl;
327 oss << "pcm_sample_bit_depth_chroma_minus1: " << +picParams->pcm_sample_bit_depth_chroma_minus1 << std::endl;
328 oss << "log2_min_pcm_luma_coding_block_size_minus3: " << +picParams->log2_min_pcm_luma_coding_block_size_minus3 << std::endl;
329 oss << "log2_diff_max_min_pcm_luma_coding_block_size: " << +picParams->log2_diff_max_min_pcm_luma_coding_block_size << std::endl;
330 oss << "pcm_loop_filter_disabled_flag: " << +picParams->pcm_loop_filter_disabled_flag << std::endl;
331 oss << "long_term_ref_pics_present_flag: " << +picParams->long_term_ref_pics_present_flag << std::endl;
332 oss << "sps_temporal_mvp_enabled_flag: " << +picParams->sps_temporal_mvp_enabled_flag << std::endl;
333 oss << "strong_intra_smoothing_enabled_flag: " << +picParams->strong_intra_smoothing_enabled_flag << std::endl;
334 oss << "dependent_slice_segments_enabled_flag: " << +picParams->dependent_slice_segments_enabled_flag << std::endl;
335 oss << "output_flag_present_flag: " << +picParams->output_flag_present_flag << std::endl;
336 oss << "num_extra_slice_header_bits: " << +picParams->num_extra_slice_header_bits << std::endl;
337 oss << "sign_data_hiding_enabled_flag: " << +picParams->sign_data_hiding_enabled_flag << std::endl;
338 oss << "cabac_init_present_flag: " << +picParams->cabac_init_present_flag << std::endl;
339 oss << "ReservedBits3: " << +picParams->ReservedBits3 << std::endl;
340 oss << "dwCodingParamToolFlags: " << +picParams->dwCodingParamToolFlags << std::endl;
341
342 // CodingSettingPicturePropertyFlags
343 oss << "constrained_intra_pred_flag: " << +picParams->constrained_intra_pred_flag << std::endl;
344 oss << "transform_skip_enabled_flag: " << +picParams->transform_skip_enabled_flag << std::endl;
345 oss << "cu_qp_delta_enabled_flag: " << +picParams ->cu_qp_delta_enabled_flag << std::endl;
346 oss << "diff_cu_qp_delta_depth: " << +picParams->diff_cu_qp_delta_depth << std::endl;
347 oss << "pps_slice_chroma_qp_offsets_present_flag: " << +picParams->pps_slice_chroma_qp_offsets_present_flag << std::endl;
348 oss << "weighted_pred_flag: " << +picParams->weighted_pred_flag << std::endl;
349 oss << "weighted_bipred_flag: " << +picParams->weighted_bipred_flag << std::endl;
350 oss << "transquant_bypass_enabled_flag: " << +picParams->transquant_bypass_enabled_flag << std::endl;
351 oss << "tiles_enabled_flag: " << +picParams->tiles_enabled_flag << std::endl;
352 oss << "entropy_coding_sync_enabled_flag: " << +picParams->entropy_coding_sync_enabled_flag << std::endl;
353 oss << "uniform_spacing_flag: " << +picParams->uniform_spacing_flag << std::endl;
354 oss << "loop_filter_across_tiles_enabled_flag: " << +picParams->loop_filter_across_tiles_enabled_flag << std::endl;
355 oss << "pps_loop_filter_across_slices_enabled_flag: " << +picParams->pps_loop_filter_across_slices_enabled_flag << std::endl;
356 oss << "deblocking_filter_override_enabled_flag: " << +picParams->deblocking_filter_override_enabled_flag << std::endl;
357 oss << "pps_deblocking_filter_disabled_flag: " << +picParams->pps_deblocking_filter_disabled_flag << std::endl;
358 oss << "lists_modification_present_flag: " << +picParams->lists_modification_present_flag << std::endl;
359 oss << "slice_segment_header_extension_present_flag: " << +picParams->slice_segment_header_extension_present_flag << std::endl;
360 oss << "IrapPicFlag: " << +picParams->IrapPicFlag << std::endl;
361 oss << "IdrPicFlag: " << +picParams->IdrPicFlag << std::endl;
362 oss << "IntraPicFlag: " << +picParams->IntraPicFlag << std::endl;
363 oss << "ReservedBits4: " << +picParams->ReservedBits4 << std::endl;
364 oss << "dwCodingSettingPicturePropertyFlags: " << +picParams->dwCodingSettingPicturePropertyFlags << std::endl;
365 oss << "pps_cb_qp_offset: " << +picParams->pps_cb_qp_offset << std::endl;
366 oss << "pps_cr_qp_offset: " << +picParams->pps_cr_qp_offset << std::endl;
367 oss << "num_tile_columns_minus1: " << +picParams->num_tile_columns_minus1 << std::endl;
368 oss << "num_tile_rows_minus1: " << +picParams->num_tile_rows_minus1 << std::endl;
369
370 // column width
371 oss << "column_width_minus1[19]:";
372 for (uint8_t i = 0; i < 19; i++)
373 oss << picParams->column_width_minus1[i] << " ";
374 oss << std::endl;
375
376 // row height
377 oss << "row_height_minus1[21]:";
378 for (uint8_t i = 0; i < 21; i++)
379 oss << picParams->row_height_minus1[i] << " ";
380 oss << std::endl;
381
382 oss << "pps_beta_offset_div2: " << +picParams->pps_beta_offset_div2 << std::endl;
383 oss << "pps_tc_offset_div2: " << +picParams->pps_tc_offset_div2 << std::endl;
384 oss << "log2_parallel_merge_level_minus2: " << +picParams->log2_parallel_merge_level_minus2 << std::endl;
385 oss << "CurrPicOrderCntVal: " << +picParams->CurrPicOrderCntVal << std::endl;
386
387 oss.setf(std::ios::dec, std::ios::basefield);
388
389 // RefFrameList[15]
390 for (uint8_t i = 0; i < 15; ++i)
391 {
392 oss << "RefFrameList[" << +i << "].FrameIdx:" << +picParams->RefFrameList[i].FrameIdx << std::endl;
393 oss << "RefFrameList[" << +i << "].PicFlags:" << +picParams->RefFrameList[i].PicFlags << std::endl;
394 }
395
396 // POC List
397 oss << "PicOrderCntValList[15]:";
398 for (uint8_t i = 0; i < 15; i++)
399 oss << picParams->PicOrderCntValList[i] << " ";
400 oss << std::endl;
401
402 // Ref RefPicSetStCurrBefore List
403 oss << "RefPicSetStCurrBefore[8]:";
404 for (uint8_t i = 0; i < 8; i++)
405 oss << +picParams->RefPicSetStCurrBefore[i] << " ";
406 oss << std::endl;
407
408 // Ref RefPicSetStCurrAfter List
409 oss << "RefPicSetStCurrAfter[16]:";
410 for (uint8_t i = 0; i < 8; i++)
411 oss << +picParams->RefPicSetStCurrAfter[i] << " ";
412 oss << std::endl;
413
414 // Ref PicSetStCurr List
415 oss << "RefPicSetLtCurr[16]:";
416 for (uint8_t i = 0; i < 8; i++)
417 oss << +picParams->RefPicSetLtCurr[i] << " ";
418 oss << std::endl;
419
420 // Ref RefPicSetStCurrBefore List with POC
421 oss << "POC of RefPicSetStCurrBefore[8]: ";
422 for (uint8_t i = 0; i < 8; i++)
423 oss << +picParams->PicOrderCntValList[picParams->RefPicSetStCurrBefore[i] % 15] << " ";
424 oss << std::endl;
425
426 // Ref RefPicSetStCurrAfter List with POC
427 oss << "POC of RefPicSetStCurrAfter[16]:";
428 for (uint8_t i = 0; i < 8; i++)
429 oss << +picParams->PicOrderCntValList[picParams->RefPicSetStCurrAfter[i] % 15] << " ";
430 oss << std::endl;
431
432 // Ref PicSetStCurr List with POC
433 oss << "POC of RefPicSetLtCurr[16]: ";
434 for (uint8_t i = 0; i < 8; i++)
435 oss << +picParams->PicOrderCntValList[picParams->RefPicSetLtCurr[i] % 15] << " ";
436 oss << std::endl;
437
438 oss << "RefFieldPicFlag: " << +picParams->RefFieldPicFlag << std::endl;
439 oss << "RefBottomFieldFlag: " << +picParams->RefBottomFieldFlag << std::endl;
440 oss << "StatusReportFeedbackNumber: " << +picParams->StatusReportFeedbackNumber << std::endl;
441
442 return oss;
443 }
444
445 std::ostream &operator<<(std::ostream &oss, const CODEC_HEVC_EXT_PIC_PARAMS &cr)
446 {
447 const CODEC_HEVC_EXT_PIC_PARAMS *extPicParams = &cr;
448
449 // PicRangeExtensionFlags
450 oss << "transform_skip_rotation_enabled_flag: " << +extPicParams->PicRangeExtensionFlags.fields.transform_skip_rotation_enabled_flag << std::endl;
451 oss << "transform_skip_context_enabled_flag: " << +extPicParams->PicRangeExtensionFlags.fields.transform_skip_context_enabled_flag << std::endl;
452 oss << "implicit_rdpcm_enabled_flag: " << +extPicParams->PicRangeExtensionFlags.fields.implicit_rdpcm_enabled_flag << std::endl;
453 oss << "explicit_rdpcm_enabled_flag: " << +extPicParams->PicRangeExtensionFlags.fields.explicit_rdpcm_enabled_flag << std::endl;
454 oss << "extended_precision_processing_flag: " << +extPicParams->PicRangeExtensionFlags.fields.extended_precision_processing_flag << std::endl;
455 oss << "intra_smoothing_disabled_flag: " << +extPicParams->PicRangeExtensionFlags.fields.intra_smoothing_disabled_flag << std::endl;
456 oss << "high_precision_offsets_enabled_flag: " << +extPicParams->PicRangeExtensionFlags.fields.high_precision_offsets_enabled_flag << std::endl;
457 oss << "persistent_rice_adaptation_enabled_flag: " << +extPicParams->PicRangeExtensionFlags.fields.persistent_rice_adaptation_enabled_flag << std::endl;
458 oss << "cabac_bypass_alignment_enabled_flag: " << +extPicParams->PicRangeExtensionFlags.fields.cabac_bypass_alignment_enabled_flag << std::endl;
459 oss << "cross_component_prediction_enabled_flag: " << +extPicParams->PicRangeExtensionFlags.fields.cross_component_prediction_enabled_flag << std::endl;
460 oss << "chroma_qp_offset_list_enabled_flag: " << +extPicParams->PicRangeExtensionFlags.fields.chroma_qp_offset_list_enabled_flag << std::endl;
461 oss << "BitDepthLuma16: " << +extPicParams->PicRangeExtensionFlags.fields.BitDepthLuma16 << std::endl;
462 oss << "BitDepthChroma16: " << +extPicParams->PicRangeExtensionFlags.fields.BitDepthChroma16 << std::endl;
463 oss << "diff_cu_chroma_qp_offset_depth: " << +extPicParams->diff_cu_chroma_qp_offset_depth << std::endl;
464 oss << "chroma_qp_offset_list_len_minus1: " << +extPicParams->chroma_qp_offset_list_len_minus1 << std::endl;
465 oss << "log2_sao_offset_scale_luma: " << +extPicParams->log2_sao_offset_scale_luma << std::endl;
466 oss << "log2_sao_offset_scale_chroma: " << +extPicParams->log2_sao_offset_scale_chroma << std::endl;
467 oss << "log2_max_transform_skip_block_size_minus2: " << +extPicParams->log2_max_transform_skip_block_size_minus2 << std::endl;
468
469 // cb_qp_offset_list[6]
470 oss << "cb_qp_offset_list[6]: ";
471 for (uint8_t i = 0; i < 6; i++)
472 oss << +extPicParams->cb_qp_offset_list[i] << " ";
473 oss << std::endl;
474
475 // cr_qp_offset_list[6]
476 oss << "cr_qp_offset_list[6]: ";
477 for (uint8_t i = 0; i < 6; i++)
478 oss << +extPicParams->cr_qp_offset_list[i] << " ";
479 oss << std::endl;
480
481 return oss;
482 }
483
484 std::ostream &operator<<(std::ostream &oss, const CODEC_HEVC_SCC_PIC_PARAMS &cr)
485 {
486 const CODEC_HEVC_SCC_PIC_PARAMS *sccPicParams = &cr;
487
488 oss << "pps_curr_pic_ref_enabled_flag: " << +sccPicParams->PicSCCExtensionFlags.fields.pps_curr_pic_ref_enabled_flag << std::endl;
489 oss << "palette_mode_enabled_flag: " << +sccPicParams->PicSCCExtensionFlags.fields.palette_mode_enabled_flag << std::endl;
490 oss << "motion_vector_resolution_control_idc: " << +sccPicParams->PicSCCExtensionFlags.fields.motion_vector_resolution_control_idc << std::endl;
491 oss << "intra_boundary_filtering_disabled_flag: " << +sccPicParams->PicSCCExtensionFlags.fields.intra_boundary_filtering_disabled_flag << std::endl;
492 oss << "residual_adaptive_colour_transform_enabled_flag: " << +sccPicParams->PicSCCExtensionFlags.fields.residual_adaptive_colour_transform_enabled_flag << std::endl;
493 oss << "pps_slice_act_qp_offsets_present_flag: " << +sccPicParams->PicSCCExtensionFlags.fields.pps_slice_act_qp_offsets_present_flag << std::endl;
494 oss << "palette_max_size: " << +sccPicParams->palette_max_size << std::endl;
495 oss << "delta_palette_max_predictor_size: " << +sccPicParams->delta_palette_max_predictor_size << std::endl;
496 oss << "PredictorPaletteSize: " << +sccPicParams->PredictorPaletteSize << std::endl;
497
498 for (uint8_t i = 0; i < 128; i++)
499 {
500 oss << "PredictorPaletteEntries[0][" << +i << "]: " << +sccPicParams->PredictorPaletteEntries[0][i] << std::endl;
501 oss << "PredictorPaletteEntries[1][" << +i << "]: " << +sccPicParams->PredictorPaletteEntries[1][i] << std::endl;
502 oss << "PredictorPaletteEntries[2][" << +i << "]: " << +sccPicParams->PredictorPaletteEntries[2][i] << std::endl;
503 }
504
505 oss << "pps_act_y_qp_offset_plus5: " << +sccPicParams->pps_act_y_qp_offset_plus5 << std::endl;
506 oss << "pps_act_cb_qp_offset_plus5: " << +sccPicParams->pps_act_y_qp_offset_plus5 << std::endl;
507 oss << "pps_act_cr_qp_offset_plus3: " << +sccPicParams->pps_act_y_qp_offset_plus5 << std::endl;
508
509 return oss;
510 }
511
512 std::ostream &operator<<(std::ostream &oss, const CODEC_HEVC_SF_SLICE_PARAMS &cr)
513 {
514 const CODEC_HEVC_SF_SLICE_PARAMS *sliceControl = &cr;
515
516 oss << "slice_data_size: " << +sliceControl->slice_data_size << std::endl;
517 oss << "slice_data_offset: " << +sliceControl->slice_data_offset << std::endl;
518 oss << "slice_chopping: " << +sliceControl->slice_chopping << std::endl;
519 oss << std::endl;
520
521 return oss;
522 }
523
524 std::ostream &operator<<(std::ostream &oss, const CODEC_HEVC_SLICE_PARAMS &cr)
525 {
526 const CODEC_HEVC_SLICE_PARAMS *hevcSliceControl = &cr;
527
528 oss << "slice_data_size: " << +hevcSliceControl->slice_data_size << std::endl;
529 oss << "slice_data_offset: " << +hevcSliceControl->slice_data_offset << std::endl;
530 oss << "slice_chopping: " << +hevcSliceControl->slice_chopping << std::endl;
531
532 // Dump Long format Params
533 oss << std::endl;
534 oss << "ByteOffsetToSliceData: " << +hevcSliceControl->ByteOffsetToSliceData << std::endl;
535 oss << "slice_segment_address: " << +hevcSliceControl->slice_segment_address << std::endl;
536
537 // RefPicList[2][15]
538 for (uint8_t i = 0; i < 15; ++i)
539 {
540 oss << "RefPicList[0][" << +i << "]";
541 oss << ".FrameIdx: " << +hevcSliceControl->RefPicList[0][i].FrameIdx << std::endl;
542 oss << "RefPicList[0][" << +i << "]";
543 oss << ".PicFlags: " << +hevcSliceControl->RefPicList[0][i].PicFlags << std::endl;
544 }
545 for (uint8_t i = 0; i < 15; ++i)
546 {
547 oss << "RefPicList[1][" << +i << "]";
548 oss << ".FrameIdx: " << +hevcSliceControl->RefPicList[1][i].FrameIdx << std::endl;
549 oss << "RefPicList[1][" << +i << "]";
550 oss << ".PicFlags: " << +hevcSliceControl->RefPicList[1][i].PicFlags << std::endl;
551 }
552
553 oss << "last_slice_of_pic: " << +hevcSliceControl->LongSliceFlags.fields.LastSliceOfPic << std::endl;
554 oss << "dependent_slice_segment_flag: " << +hevcSliceControl->LongSliceFlags.fields.dependent_slice_segment_flag << std::endl;
555 oss << "slice_type: " << +hevcSliceControl->LongSliceFlags.fields.slice_type << std::endl;
556 oss << "color_plane_id: " << +hevcSliceControl->LongSliceFlags.fields.color_plane_id << std::endl;
557 oss << "slice_sao_luma_flag: " << +hevcSliceControl->LongSliceFlags.fields.slice_sao_luma_flag << std::endl;
558 oss << "slice_sao_chroma_flag: " << +hevcSliceControl->LongSliceFlags.fields.slice_sao_chroma_flag << std::endl;
559 oss << "mvd_l1_zero_flag: " << +hevcSliceControl->LongSliceFlags.fields.mvd_l1_zero_flag << std::endl;
560 oss << "cabac_init_flag: " << +hevcSliceControl->LongSliceFlags.fields.cabac_init_flag << std::endl;
561 oss << "slice_temporal_mvp_enabled_flag: " << +hevcSliceControl->LongSliceFlags.fields.slice_temporal_mvp_enabled_flag << std::endl;
562 oss << "slice_deblocking_filter_disabled_flag: " << +hevcSliceControl->LongSliceFlags.fields.slice_deblocking_filter_disabled_flag << std::endl;
563 oss << "collocated_from_l0_flag: " << +hevcSliceControl->LongSliceFlags.fields.collocated_from_l0_flag << std::endl;
564 oss << "slice_loop_filter_across_slices_enabled_flag: " << +hevcSliceControl->LongSliceFlags.fields.slice_loop_filter_across_slices_enabled_flag << std::endl;
565 oss << "reserved: " << +hevcSliceControl->LongSliceFlags.fields.reserved << std::endl;
566 oss << "collocated_ref_idx: " << +hevcSliceControl->collocated_ref_idx << std::endl;
567 oss << "num_ref_idx_l0_active_minus1: " << +hevcSliceControl->num_ref_idx_l0_active_minus1 << std::endl;
568 oss << "num_ref_idx_l1_active_minus1: " << +hevcSliceControl->num_ref_idx_l1_active_minus1 << std::endl;
569 oss << "slice_qp_delta: " << +hevcSliceControl->slice_qp_delta << std::endl;
570 oss << "slice_cb_qp_offset: " << +hevcSliceControl->slice_cb_qp_offset << std::endl;
571 oss << "slice_cr_qp_offset: " << +hevcSliceControl->slice_cr_qp_offset << std::endl;
572 oss << "slice_beta_offset_div2: " << +hevcSliceControl->slice_beta_offset_div2 << std::endl;
573 oss << "slice_tc_offset_div2: " << +hevcSliceControl->slice_tc_offset_div2 << std::endl;
574 oss << "luma_log2_weight_denom: " << +hevcSliceControl->luma_log2_weight_denom << std::endl;
575 oss << "delta_chroma_log2_weight_denom: " << +hevcSliceControl->delta_chroma_log2_weight_denom << std::endl;
576
577 // luma_offset[2][15]
578 for (uint8_t i = 0; i < 15; i++)
579 {
580 oss << "luma_offset_l0[" << +i << "]: " << +hevcSliceControl->luma_offset_l0[i] << std::endl;
581 oss << "luma_offset_l1[" << +i << "]: " << +hevcSliceControl->luma_offset_l1[i] << std::endl;
582 }
583 // delta_luma_weight[2][15]
584 for (uint8_t i = 0; i < 15; i++)
585 {
586 oss << "delta_luma_weight_l0[" << +i << "]: " << +hevcSliceControl->delta_luma_weight_l0[i] << std::endl;
587 oss << "delta_luma_weight_l1[" << +i << "]: " << +hevcSliceControl->delta_luma_weight_l1[i] << std::endl;
588 }
589 // chroma_offset[2][15][2]
590 for (uint8_t i = 0; i < 15; i++)
591 {
592 oss << "ChromaOffsetL0[" << +i << "][0]: " << +hevcSliceControl->ChromaOffsetL0[i][0] << std::endl;
593 oss << "ChromaOffsetL0[" << +i << "][1]: " << +hevcSliceControl->ChromaOffsetL0[i][1] << std::endl;
594 oss << "ChromaOffsetL1[" << +i << "][0]: " << +hevcSliceControl->ChromaOffsetL1[i][0] << std::endl;
595 oss << "ChromaOffsetL1[" << +i << "][1]: " << +hevcSliceControl->ChromaOffsetL1[i][1] << std::endl;
596 }
597 // delta_chroma_weight[2][15][2]
598 for (uint8_t i = 0; i < 15; i++)
599 {
600 oss << "delta_chroma_weight_l0[" << +i << "][0]: " << +hevcSliceControl->delta_chroma_weight_l0[i][0] << std::endl;
601 oss << "delta_chroma_weight_l0[" << +i << "][1]: " << +hevcSliceControl->delta_chroma_weight_l0[i][1] << std::endl;
602 oss << "delta_chroma_weight_l1[" << +i << "][0]: " << +hevcSliceControl->delta_chroma_weight_l1[i][0] << std::endl;
603 oss << "delta_chroma_weight_l1[" << +i << "][1]: " << +hevcSliceControl->delta_chroma_weight_l1[i][1] << std::endl;
604 }
605
606 oss << "five_minus_max_num_merge_cand: " << +hevcSliceControl->five_minus_max_num_merge_cand << std::endl;
607 oss << "num_entry_point_offsets: " << +hevcSliceControl->num_entry_point_offsets << std::endl;
608 oss << "EntryOffsetToSubsetArray: " << +hevcSliceControl->EntryOffsetToSubsetArray << std::endl;
609
610 oss << std::endl;
611
612 return oss;
613 }
614
615 std::ostream &operator<<(std::ostream &oss, const CODEC_HEVC_EXT_SLICE_PARAMS &cr)
616 {
617 const CODEC_HEVC_EXT_SLICE_PARAMS *hevcExtSliceControl = &cr;
618
619 // luma_offset[2][15]
620 for (uint8_t i = 0; i < 15; i++)
621 {
622 oss << "luma_offset_l0[" << +i << "]: " << +hevcExtSliceControl->luma_offset_l0[i] << std::endl;
623 oss << "luma_offset_l1[" << +i << "]: " << +hevcExtSliceControl->luma_offset_l1[i] << std::endl;
624 }
625
626 // chroma_offset[2][15][2]
627 for (uint8_t i = 0; i < 15; i++)
628 {
629 oss << "ChromaOffsetL0[" << +i << "][0]: " << +hevcExtSliceControl->ChromaOffsetL0[i][0] << std::endl;
630 oss << "ChromaOffsetL0[" << +i << "][1]: " << +hevcExtSliceControl->ChromaOffsetL0[i][1] << std::endl;
631 oss << "ChromaOffsetL1[" << +i << "][0]: " << +hevcExtSliceControl->ChromaOffsetL1[i][0] << std::endl;
632 oss << "ChromaOffsetL1[" << +i << "][1]: " << +hevcExtSliceControl->ChromaOffsetL1[i][1] << std::endl;
633 }
634
635 oss << "cu_chroma_qp_offset_enabled_flag: " << +hevcExtSliceControl->cu_chroma_qp_offset_enabled_flag << std::endl;
636
637 // scc slice parameters
638 oss << "slice_act_y_qp_offset: " << +hevcExtSliceControl->slice_act_y_qp_offset << std::endl;
639 oss << "slice_act_cb_qp_offset: " << +hevcExtSliceControl->slice_act_cb_qp_offset << std::endl;
640 oss << "slice_act_cr_qp_offset: " << +hevcExtSliceControl->slice_act_cr_qp_offset << std::endl;
641 oss << "use_integer_mv_flag: " << +hevcExtSliceControl->use_integer_mv_flag << std::endl;
642
643 oss << std::endl;
644
645 return oss;
646 }
647
648 std::ostream &operator<<(std::ostream &oss, const CODECHAL_HEVC_IQ_MATRIX_PARAMS &cr)
649 {
650 const CODECHAL_HEVC_IQ_MATRIX_PARAMS *iqParams = &cr;
651
652 uint32_t idx;
653 uint32_t idx2;
654
655 // 4x4 block
656 for (idx2 = 0; idx2 < 6; idx2++)
657 {
658 oss << "Qmatrix_HEVC_ucScalingLists0[" << +idx2 << "]:" << std::endl;
659
660 oss << "ucScalingLists0[" << +idx2 << "]:";
661 for (uint8_t i = 0; i < 16; i++)
662 oss << +iqParams->ucScalingLists0[idx2][i] << " ";
663 oss << std::endl;
664 }
665
666 // 8x8 block
667 for (idx2 = 0; idx2 < 6; idx2++)
668 {
669 oss << "ucScalingLists1[" << +idx2 << "]:" << std::endl;
670
671 for (idx = 0; idx < 64; idx += 8)
672 {
673 oss << "ucScalingLists1[" << +idx / 8 << "]:" << std::endl;
674 for (uint8_t i = 0; i < 8; i++)
675 oss << +iqParams->ucScalingLists1[idx2][idx + i] << " ";
676 oss << std::endl;
677 }
678 }
679
680 // 16x16 block
681 for (idx2 = 0; idx2 < 6; idx2++)
682 {
683 oss << "ucScalingLists2[" << +idx2 << "]:" << std::endl;
684
685 for (idx = 0; idx < 64; idx += 8)
686 {
687 oss << "ucScalingLists2[" << +idx / 8 << "]:" << std::endl;
688 for (uint8_t i = 0; i < 8; i++)
689 oss << +iqParams->ucScalingLists2[idx2][idx + i] << " ";
690 oss << std::endl;
691 }
692 }
693
694 // 32x32 block
695 for (idx2 = 0; idx2 < 2; idx2++)
696 {
697 oss << "ucScalingLists3[" << +idx2 << "]:" << std::endl;
698
699 for (idx = 0; idx < 64; idx += 8)
700 {
701 oss << "ucScalingLists3[" << +idx / 8 << "]:" << std::endl;
702 for (uint8_t i = 0; i < 8; i++)
703 oss << +iqParams->ucScalingLists3[idx2][idx + i] << " ";
704 oss << std::endl;
705 }
706 }
707
708 // DC16x16 block
709 oss << "ucScalingListDCCoefSizeID2: ";
710 for (uint8_t i = 0; i < 6; i++)
711 oss << +iqParams->ucScalingListDCCoefSizeID2[i] << " ";
712
713 oss << std::endl;
714
715 // DC32x32 block
716 oss << "ucScalingListDCCoefSizeID3: ";
717 oss << +iqParams->ucScalingListDCCoefSizeID3[0] << " " << +iqParams->ucScalingListDCCoefSizeID3[1] << std::endl;
718
719 return oss;
720 }
721
722 std::ostream &operator<<(std::ostream &oss, const CODEC_HEVC_SUBSET_PARAMS &cr)
723 {
724 const CODEC_HEVC_SUBSET_PARAMS *subsetsParams = &cr;
725
726 for (uint16_t i = 0; i < 440; i++)
727 {
728 oss << "entry_point_offset_minus1[" << +i << "]: " << +subsetsParams->entry_point_offset_minus1[i] << std::endl;
729 }
730
731 return oss;
732 }
733
734 void DumpDecodeHevcPicParams(PCODEC_HEVC_PIC_PARAMS picParams, std::string fileName)
735 {
736 std::ostringstream oss;
737 oss.setf(std::ios::showbase | std::ios::uppercase);
738
739 oss << *picParams << std::endl;
740
741 std::ofstream ofs(fileName, std::ios::out);
742 ofs << oss.str();
743 ofs.close();
744 }
745
746 void DumpDecodeHevcExtPicParams(PCODEC_HEVC_EXT_PIC_PARAMS extPicParams, std::string fileName)
747 {
748 std::ostringstream oss;
749 oss.setf(std::ios::showbase | std::ios::uppercase);
750
751 oss << *extPicParams << std::endl;
752
753 std::ofstream ofs(fileName, std::ios::out);
754 ofs << oss.str();
755 ofs.close();
756 }
757
758 void DumpDecodeHevcSccPicParams(PCODEC_HEVC_SCC_PIC_PARAMS sccPicParams, std::string fileName)
759 {
760 std::ostringstream oss;
761 oss.setf(std::ios::showbase | std::ios::uppercase);
762
763 oss << *sccPicParams << std::endl;
764
765 std::ofstream ofs(fileName, std::ios::out);
766 ofs << oss.str();
767 ofs.close();
768 }
769
770 void DumpDecodeHevcSliceParams(PCODEC_HEVC_SLICE_PARAMS sliceParams, uint32_t numSlices, std::string fileName, bool shortFormatInUse)
771 {
772 std::ostringstream oss;
773 oss.setf(std::ios::showbase | std::ios::uppercase);
774
775 if (numSlices > 1)
776 {
777 oss << "Total Num: " << numSlices << std::endl;
778 oss << std::endl;
779 }
780
781 for (uint16_t i = 0; i < numSlices; i++)
782 {
783 if (numSlices > 1)
784 {
785 oss << "---------Index = " << i << "---------" << std::endl;
786 }
787
788 if (shortFormatInUse)
789 {
790 oss << reinterpret_cast<CODEC_HEVC_SF_SLICE_PARAMS &>(sliceParams[i]) << std::endl;
791 }
792 else
793 {
794 oss << sliceParams[i] << std::endl;
795 }
796 }
797
798 std::ofstream ofs(fileName, std::ios::out);
799 ofs << oss.str();
800 ofs.close();
801 }
802
803 void DumpDecodeHevcExtSliceParams(PCODEC_HEVC_EXT_SLICE_PARAMS extSliceParams, uint32_t numSlices, std::string fileName)
804 {
805 std::ostringstream oss;
806 oss.setf(std::ios::showbase | std::ios::uppercase);
807
808 if (numSlices > 1)
809 {
810 oss << "Total Num: " << numSlices << std::endl;
811 oss << std::endl;
812 }
813
814 for (uint16_t i = 0; i < numSlices; i++)
815 {
816 if (numSlices > 1)
817 {
818 oss << "---------Index = " << i << "---------" << std::endl;
819 }
820
821 oss << extSliceParams[i] << std::endl;
822 }
823
824 std::ofstream ofs(fileName, std::ios::out);
825 ofs << oss.str();
826 ofs.close();
827 }
828
829 void DumpDecodeHevcIQParams(PCODECHAL_HEVC_IQ_MATRIX_PARAMS iqParams, std::string fileName)
830 {
831 std::ostringstream oss;
832 oss.setf(std::ios::showbase | std::ios::uppercase);
833
834 oss << *iqParams << std::endl;
835
836 std::ofstream ofs(fileName, std::ios::out);
837 ofs << oss.str();
838 ofs.close();
839 }
840
841 void DumpDecodeHevcSubsetParams(PCODEC_HEVC_SUBSET_PARAMS subsetsParams, std::string fileName)
842 {
843 std::ostringstream oss;
844 oss.setf(std::ios::showbase | std::ios::uppercase);
845
846 oss << *subsetsParams << std::endl;
847
848 std::ofstream ofs(fileName, std::ios::out);
849 ofs << oss.str();
850 ofs.close();
851 }
852
853 // VP9 Decode
854 std::ostream &operator<<(std::ostream &oss, const CODEC_VP9_PIC_PARAMS &cr)
855 {
856 const CODEC_VP9_PIC_PARAMS *picParams = &cr;
857
858 oss << "CurrPic FrameIdx: " << +picParams->CurrPic.FrameIdx << std::endl;
859 oss << "CurrPic PicFlags: " << +picParams->CurrPic.PicFlags << std::endl;
860
861 for (uint8_t i = 0; i < 8; ++i)
862 {
863 oss << "RefFrameList[" << +i << "] FrameIdx:" << +picParams->RefFrameList[i].FrameIdx << std::endl;
864 oss << "RefFrameList[" << +i << "] PicFlags:" << +picParams->RefFrameList[i].PicFlags << std::endl;
865 }
866 oss << "FrameWidthMinus1: " << +picParams->FrameWidthMinus1 << std::endl;
867 oss << "FrameHeightMinus1: " << +picParams->FrameHeightMinus1 << std::endl;
868 oss << "PicFlags value: " << +picParams->PicFlags.value << std::endl;
869 oss << "frame_type: " << +picParams->PicFlags.fields.frame_type << std::endl;
870 oss << "show_frame: " << +picParams->PicFlags.fields.show_frame << std::endl;
871 oss << "error_resilient_mode: " << +picParams->PicFlags.fields.error_resilient_mode << std::endl;
872 oss << "intra_only: " << +picParams->PicFlags.fields.intra_only << std::endl;
873 oss << "LastRefIdx: " << +picParams->PicFlags.fields.LastRefIdx << std::endl;
874 oss << "LastRefSignBias: " << +picParams->PicFlags.fields.LastRefSignBias << std::endl;
875 oss << "GoldenRefIdx: " << +picParams->PicFlags.fields.GoldenRefIdx << std::endl;
876 oss << "GoldenRefSignBias: " << +picParams->PicFlags.fields.GoldenRefSignBias << std::endl;
877 oss << "AltRefIdx: " << +picParams->PicFlags.fields.AltRefIdx << std::endl;
878 oss << "AltRefSignBias: " << +picParams->PicFlags.fields.AltRefSignBias << std::endl;
879 oss << "allow_high_precision_mv: " << +picParams->PicFlags.fields.allow_high_precision_mv << std::endl;
880 oss << "mcomp_filter_type: " << +picParams->PicFlags.fields.mcomp_filter_type << std::endl;
881 oss << "frame_parallel_decoding_mode: " << +picParams->PicFlags.fields.frame_parallel_decoding_mode << std::endl;
882 oss << "segmentation_enabled: " << +picParams->PicFlags.fields.segmentation_enabled << std::endl;
883 oss << "segmentation_temporal_update: " << +picParams->PicFlags.fields.segmentation_temporal_update << std::endl;
884 oss << "segmentation_update_map: " << +picParams->PicFlags.fields.segmentation_update_map << std::endl;
885 oss << "reset_frame_context: " << +picParams->PicFlags.fields.reset_frame_context << std::endl;
886 oss << "refresh_frame_context: " << +picParams->PicFlags.fields.refresh_frame_context << std::endl;
887 oss << "frame_context_idx: " << +picParams->PicFlags.fields.frame_context_idx << std::endl;
888 oss << "LosslessFlag: " << +picParams->PicFlags.fields.LosslessFlag << std::endl;
889 oss << "ReservedField: " << +picParams->PicFlags.fields.ReservedField << std::endl;
890 oss << "filter_level: " << +picParams->filter_level << std::endl;
891 oss << "sharpness_level: " << +picParams->sharpness_level << std::endl;
892 oss << "log2_tile_rows: " << +picParams->log2_tile_rows << std::endl;
893 oss << "log2_tile_columns: " << +picParams->log2_tile_columns << std::endl;
894 oss << "UncompressedHeaderLengthInBytes: " << +picParams->UncompressedHeaderLengthInBytes << std::endl;
895 oss << "FirstPartitionSize: " << +picParams->FirstPartitionSize << std::endl;
896 oss << "profile: " << +picParams->profile << std::endl;
897 oss << "BitDepthMinus8: " << +picParams->BitDepthMinus8 << std::endl;
898 oss << "subsampling_x: " << +picParams->subsampling_x << std::endl;
899 oss << "subsampling_y: " << +picParams->subsampling_y << std::endl;
900
901 for (uint8_t i = 0; i < 7; ++i)
902 {
903 oss << "SegTreeProbs[" << +i << "]: " << +picParams->SegTreeProbs[i] << std::endl;
904 }
905 for (uint8_t i = 0; i < 3; ++i)
906 {
907 oss << "SegPredProbs[" << +i << "]: " << +picParams->SegPredProbs[i] << std::endl;
908 }
909 oss << "BSBytesInBuffer: " << +picParams->BSBytesInBuffer << std::endl;
910 oss << "StatusReportFeedbackNumber: " << +picParams->StatusReportFeedbackNumber << std::endl;
911
912 return oss;
913 }
914
915 std::ostream &operator<<(std::ostream &oss, const CODEC_VP9_SLICE_PARAMS &cr)
916 {
917 const CODEC_VP9_SLICE_PARAMS *slcParams = &cr;
918
919 oss << "BSNALunitDataLocation: " << +slcParams->BSNALunitDataLocation << std::endl;
920 oss << "SliceBytesInBuffer: " << +slcParams->SliceBytesInBuffer << std::endl;
921 oss << "wBadSliceChopping: " << +slcParams->wBadSliceChopping << std::endl;
922 oss << std::endl;
923
924 return oss;
925 }
926
927 std::ostream &operator<<(std::ostream &oss, const CODEC_VP9_SEGMENT_PARAMS &cr)
928 {
929 const CODEC_VP9_SEGMENT_PARAMS *segmentParams = &cr;
930
931 for (uint8_t i = 0; i < 8; ++i)
932 {
933 oss << "SegData[" << +i << "] SegmentFlags value: " << +segmentParams->SegData[i].SegmentFlags.value << std::endl;
934 oss << "SegData[" << +i << "] SegmentReferenceEnabled: " << +segmentParams->SegData[i].SegmentFlags.fields.SegmentReferenceEnabled << std::endl;
935 oss << "SegData[" << +i << "] SegmentReference: " << +segmentParams->SegData[i].SegmentFlags.fields.SegmentReference << std::endl;
936 oss << "SegData[" << +i << "] SegmentReferenceSkipped: " << +segmentParams->SegData[i].SegmentFlags.fields.SegmentReferenceSkipped << std::endl;
937 oss << "SegData[" << +i << "] ReservedField3: " << +segmentParams->SegData[i].SegmentFlags.fields.ReservedField3 << std::endl;
938
939 for (uint8_t j = 0; j < 4; ++j)
940 {
941 oss << "SegData[" << +i << "] FilterLevel[" << +j << "]:";
942 oss << +segmentParams->SegData[i].FilterLevel[j][0] << " ";
943 oss << +segmentParams->SegData[i].FilterLevel[j][1] << std::endl;
944 }
945
946 oss << "SegData[" << +i << "] LumaACQuantScale: " << +segmentParams->SegData[i].LumaACQuantScale << std::endl;
947 oss << "SegData[" << +i << "] LumaDCQuantScale: " << +segmentParams->SegData[i].LumaDCQuantScale << std::endl;
948 oss << "SegData[" << +i << "] ChromaACQuantScale: " << +segmentParams->SegData[i].ChromaACQuantScale << std::endl;
949 oss << "SegData[" << +i << "] ChromaDCQuantScale: " << +segmentParams->SegData[i].ChromaDCQuantScale << std::endl;
950 }
951
952 return oss;
953 }
954
955 void DumpDecodeVp9PicParams(PCODEC_VP9_PIC_PARAMS picParams, std::string fileName)
956 {
957 std::ostringstream oss;
958 oss.setf(std::ios::showbase | std::ios::uppercase);
959
960 oss << *picParams << std::endl;
961
962 std::ofstream ofs(fileName, std::ios::out);
963 ofs << oss.str();
964 ofs.close();
965 }
966
967 void DumpDecodeVp9SliceParams(PCODEC_VP9_SLICE_PARAMS slcParams, std::string fileName)
968 {
969 std::ostringstream oss;
970 oss.setf(std::ios::showbase | std::ios::uppercase);
971
972 oss << *slcParams << std::endl;
973
974 std::ofstream ofs(fileName, std::ios::out);
975 ofs << oss.str();
976 ofs.close();
977 }
978
979 void DumpDecodeVp9SegmentParams(PCODEC_VP9_SEGMENT_PARAMS segmentParams, std::string fileName)
980 {
981 std::ostringstream oss;
982 oss.setf(std::ios::showbase | std::ios::uppercase);
983
984 oss << *segmentParams << std::endl;
985
986 std::ofstream ofs(fileName, std::ios::out);
987 ofs << oss.str();
988 ofs.close();
989 }
990
991 // AV1 Decode
992 std::ostream &operator<<(std::ostream &oss, const CodecAv1PicParams &cr)
993 {
994 const CodecAv1PicParams *picParams = &cr;
995
996 oss << "CurrPic FrameIdx: " << +picParams->m_currPic.FrameIdx << std::endl;
997 oss << "CurrDisplayPic FrameIdx: " << +picParams->m_currDisplayPic.FrameIdx << std::endl;
998 oss << "Profile: " << +picParams->m_profile << std::endl;
999 oss << "AnchorFrameInsertion: " << +picParams->m_anchorFrameInsertion << std::endl;
1000 oss << "order_hint_bits_minus_1: " << +picParams->m_orderHintBitsMinus1 << std::endl;
1001 oss << "BitDepthIdx: " << +picParams->m_bitDepthIdx << std::endl;
1002
1003 //Sequence Info Flags
1004 oss << "dwSeqInfoFlags: " << +picParams->m_seqInfoFlags.m_value << std::endl;
1005 oss << "still_picture: " << +picParams->m_seqInfoFlags.m_fields.m_stillPicture << std::endl;
1006 oss << "use_128x128_superblock: " << +picParams->m_seqInfoFlags.m_fields.m_use128x128Superblock << std::endl;
1007 oss << "enable_filter_intra: " << +picParams->m_seqInfoFlags.m_fields.m_enableFilterIntra << std::endl;
1008 oss << "enable_intra_edge_filter: " << +picParams->m_seqInfoFlags.m_fields.m_enableIntraEdgeFilter << std::endl;
1009 oss << "enable_interintra_compound: " << +picParams->m_seqInfoFlags.m_fields.m_enableInterintraCompound << std::endl;
1010 oss << "enable_masked_compound: " << +picParams->m_seqInfoFlags.m_fields.m_enableMaskedCompound << std::endl;
1011 oss << "enable_dual_filter: " << +picParams->m_seqInfoFlags.m_fields.m_enableDualFilter << std::endl;
1012 oss << "enable_order_hint: " << +picParams->m_seqInfoFlags.m_fields.m_enableOrderHint << std::endl;
1013 oss << "enable_jnt_comp: " << +picParams->m_seqInfoFlags.m_fields.m_enableJntComp << std::endl;
1014 oss << "enable_cdef: " << +picParams->m_seqInfoFlags.m_fields.m_enableCdef << std::endl;
1015 oss << "mono_chrome: " << +picParams->m_seqInfoFlags.m_fields.m_monoChrome << std::endl;
1016 oss << "color_range: " << +picParams->m_seqInfoFlags.m_fields.m_colorRange << std::endl;
1017 oss << "subsampling_x: " << +picParams->m_seqInfoFlags.m_fields.m_subsamplingX << std::endl;
1018 oss << "subsampling_y: " << +picParams->m_seqInfoFlags.m_fields.m_subsamplingY << std::endl;
1019 oss << "chroma_sample_position: " << +picParams->m_seqInfoFlags.m_fields.m_chromaSamplePosition << std::endl;
1020 oss << "film_grain_params_present: " << +picParams->m_seqInfoFlags.m_fields.m_filmGrainParamsPresent << std::endl;
1021
1022 //frame info
1023 oss << "dwPicInfoFlags: " << +picParams->m_picInfoFlags.m_value << std::endl;
1024 oss << "frame_type: " << +picParams->m_picInfoFlags.m_fields.m_frameType << std::endl;
1025 oss << "show_frame: " << +picParams->m_picInfoFlags.m_fields.m_showFrame << std::endl;
1026 oss << "showable_frame: " << +picParams->m_picInfoFlags.m_fields.m_showableFrame << std::endl;
1027 oss << "error_resilient_mode: " << +picParams->m_picInfoFlags.m_fields.m_errorResilientMode << std::endl;
1028 oss << "disable_cdf_update: " << +picParams->m_picInfoFlags.m_fields.m_disableCdfUpdate << std::endl;
1029 oss << "allow_screen_content_tools: " << +picParams->m_picInfoFlags.m_fields.m_allowScreenContentTools << std::endl;
1030 oss << "force_integer_mv: " << +picParams->m_picInfoFlags.m_fields.m_forceIntegerMv << std::endl;
1031 oss << "allow_intrabc: " << +picParams->m_picInfoFlags.m_fields.m_allowIntrabc << std::endl;
1032 oss << "use_superres: " << +picParams->m_picInfoFlags.m_fields.m_useSuperres << std::endl;
1033 oss << "allow_high_precision_mv: " << +picParams->m_picInfoFlags.m_fields.m_allowHighPrecisionMv << std::endl;
1034 oss << "is_motion_mode_switchable: " << +picParams->m_picInfoFlags.m_fields.m_isMotionModeSwitchable << std::endl;
1035 oss << "use_ref_frame_mvs: " << +picParams->m_picInfoFlags.m_fields.m_useRefFrameMvs << std::endl;
1036 oss << "disable_frame_end_update_cdf: " << +picParams->m_picInfoFlags.m_fields.m_disableFrameEndUpdateCdf << std::endl;
1037 oss << "uniform_tile_spacing_flag: " << +picParams->m_picInfoFlags.m_fields.m_uniformTileSpacingFlag << std::endl;
1038 oss << "allow_warped_motion: " << +picParams->m_picInfoFlags.m_fields.m_allowWarpedMotion << std::endl;
1039 oss << "large_scale_tile: " << +picParams->m_picInfoFlags.m_fields.m_largeScaleTile << std::endl;
1040
1041 oss << "frame_width_minus1: " << +picParams->m_frameWidthMinus1 << std::endl;
1042 oss << "frame_height_minus1: " << +picParams->m_frameHeightMinus1 << std::endl;
1043
1044 for (auto i = 0; i < 8; ++i)
1045 {
1046 oss << "ref_frame_map[" << +i << "] FrameIdx:" << +picParams->m_refFrameMap[i].FrameIdx << std::endl;
1047 oss << "ref_frame_map[" << +i << "] PicFlags:" << +picParams->m_refFrameMap[i].PicFlags << std::endl;
1048 }
1049
1050 for (auto i = 0; i < 7; i++)
1051 {
1052 oss << "ref_frame_idx[" << +i << "]: " << +picParams->m_refFrameIdx[i] << std::endl;
1053 }
1054
1055 oss << "primary_ref_frame: " << +picParams->m_primaryRefFrame << std::endl;
1056 oss << "output_frame_width_in_tiles_minus_1: " << +picParams->m_outputFrameWidthInTilesMinus1 << std::endl;
1057 oss << "output_frame_height_in_tiles_minus_1: " << +picParams->m_outputFrameHeightInTilesMinus1 << std::endl;
1058
1059 for (auto i = 0; i < 2; i++)
1060 {
1061 oss << "filter_level[" << +i << "]: " << +picParams->m_filterLevel[i] << std::endl;
1062 }
1063 oss << "filter_level_u: " << +picParams->m_filterLevelU << std::endl;
1064 oss << "filter_level_v: " << +picParams->m_filterLevelV << std::endl;
1065
1066 //Loop Filter Info Flags
1067 oss << "cLoopFilterInfoFlags value: " << +picParams->m_loopFilterInfoFlags.m_value << std::endl;
1068 oss << "sharpness_level: " << +picParams->m_loopFilterInfoFlags.m_fields.m_sharpnessLevel << std::endl;
1069 oss << "mode_ref_delta_enabled: " << +picParams->m_loopFilterInfoFlags.m_fields.m_modeRefDeltaEnabled << std::endl;
1070 oss << "mode_ref_delta_update: " << +picParams->m_loopFilterInfoFlags.m_fields.m_modeRefDeltaUpdate << std::endl;
1071
1072 oss << "order_hint: " << +picParams->m_orderHint << std::endl;
1073 oss << "superres_scale_denominator: " << +picParams->m_superresScaleDenominator << std::endl;
1074 oss << "interp_filter: " << +picParams->m_interpFilter << std::endl;
1075
1076 for (auto i = 0; i < 8; i++)
1077 {
1078 oss << "ref_deltas[" << +i << "]: " << +picParams->m_refDeltas[i] << std::endl;
1079 }
1080
1081 for (auto i = 0; i < 2; i++)
1082 {
1083 oss << "mode_deltas[" << +i << "]: " << +picParams->m_modeDeltas[i] << std::endl;
1084 }
1085
1086 oss << "base_qindex: " << +picParams->m_baseQindex << std::endl;
1087 oss << "y_dc_delta_q: " << +picParams->m_yDcDeltaQ << std::endl;
1088 oss << "u_dc_delta_q: " << +picParams->m_uDcDeltaQ << std::endl;
1089 oss << "u_ac_delta_q: " << +picParams->m_uAcDeltaQ << std::endl;
1090 oss << "v_dc_delta_q: " << +picParams->m_vDcDeltaQ << std::endl;
1091 oss << "v_ac_delta_q: " << +picParams->m_vAcDeltaQ << std::endl;
1092
1093 // quantization_matrix
1094 oss << "wQMatrixFlags value: " << +picParams->m_qMatrixFlags.m_value << std::endl;
1095 oss << "using_qmatrix: " << +picParams->m_qMatrixFlags.m_fields.m_usingQmatrix << std::endl;
1096 oss << "qm_y: " << +picParams->m_qMatrixFlags.m_fields.m_qmY << std::endl;
1097 oss << "qm_u: " << +picParams->m_qMatrixFlags.m_fields.m_qmU << std::endl;
1098 oss << "qm_v: " << +picParams->m_qMatrixFlags.m_fields.m_qmV << std::endl;
1099
1100 // Mode control flags
1101 oss << "dwModeControlFlags value: " << +picParams->m_modeControlFlags.m_value << std::endl;
1102 oss << "delta_q_present_flag: " << +picParams->m_modeControlFlags.m_fields.m_deltaQPresentFlag << std::endl;
1103 oss << "log2_delta_q_res: " << +picParams->m_modeControlFlags.m_fields.m_log2DeltaQRes << std::endl;
1104 oss << "delta_lf_present_flag: " << +picParams->m_modeControlFlags.m_fields.m_deltaLfPresentFlag << std::endl;
1105 oss << "log2_delta_lf_res: " << +picParams->m_modeControlFlags.m_fields.m_log2DeltaLfRes << std::endl;
1106 oss << "delta_lf_multi: " << +picParams->m_modeControlFlags.m_fields.m_deltaLfMulti << std::endl;
1107 oss << "tx_mode: " << +picParams->m_modeControlFlags.m_fields.m_txMode << std::endl;
1108 oss << "reference_mode: " << +picParams->m_modeControlFlags.m_fields.m_referenceMode << std::endl;
1109 oss << "reduced_tx_set_used: " << +picParams->m_modeControlFlags.m_fields.m_reducedTxSetUsed << std::endl;
1110 oss << "skip_mode_present: " << +picParams->m_modeControlFlags.m_fields.m_skipModePresent << std::endl;
1111
1112 // Segmentation
1113 oss << "enabled: " << +picParams->m_av1SegData.m_enabled << std::endl;
1114 oss << "update_map: " << +picParams->m_av1SegData.m_updateMap << std::endl;
1115 oss << "temporal_update: " << +picParams->m_av1SegData.m_temporalUpdate << std::endl;
1116 oss << "update_data: " << +picParams->m_av1SegData.m_updateData << std::endl;
1117
1118 for (auto i = 0; i < 8; i++)
1119 {
1120 for (auto j = 0; j < 8; j++)
1121 {
1122 oss << "feature_data[" << +i << "][" << +j << "]: " << +picParams->m_av1SegData.m_featureData[i][j] << std::endl;
1123 }
1124 }
1125 for (auto i = 0; i < 8; i++)
1126 {
1127 oss << "feature_mask[" << +i << "]: " << +picParams->m_av1SegData.m_featureMask[i] << std::endl;
1128 }
1129
1130 oss << "tile_cols: " << +picParams->m_tileCols << std::endl;
1131 for (auto i = 0; i < 63; i++)
1132 {
1133 oss << "width_in_sbs_minus_1[" << +i << "]: " << +picParams->m_widthInSbsMinus1[i] << std::endl;
1134 }
1135 oss << "tile_rows: " << +picParams->m_tileRows << std::endl;
1136 for (auto i = 0; i < 63; i++)
1137 {
1138 oss << "height_in_sbs_minus_1[" << +i << "]: " << +picParams->m_heightInSbsMinus1[i] << std::endl;
1139 }
1140
1141 oss << "tile_count_minus_1: " << +picParams->m_tileCountMinus1 << std::endl;
1142 oss << "context_update_tile_id: " << +picParams->m_contextUpdateTileId << std::endl;
1143
1144 oss << "cdef_damping_minus_3: " << +picParams->m_cdefDampingMinus3 << std::endl;
1145 oss << "cdef_bits: " << +picParams->m_cdefBits << std::endl;
1146 for (auto i = 0; i < 8; i++)
1147 {
1148 oss << "cdef_y_strengths[" << +i << "]: " << +picParams->m_cdefYStrengths[i] << std::endl;
1149 }
1150 for (auto i = 0; i < 8; i++)
1151 {
1152 oss << "cdef_uv_strengths[" << +i << "]: " << +picParams->m_cdefUvStrengths[i] << std::endl;
1153 }
1154
1155 // Loop Restoration Flags
1156 oss << "LoopRestorationFlags value: " << +picParams->m_loopRestorationFlags.m_value << std::endl;
1157 oss << "yframe_restoration_type: " << +picParams->m_loopRestorationFlags.m_fields.m_yframeRestorationType << std::endl;
1158 oss << "cbframe_restoration_type: " << +picParams->m_loopRestorationFlags.m_fields.m_cbframeRestorationType << std::endl;
1159 oss << "crframe_restoration_type: " << +picParams->m_loopRestorationFlags.m_fields.m_crframeRestorationType << std::endl;
1160 oss << "lr_unit_shift: " << +picParams->m_loopRestorationFlags.m_fields.m_lrUnitShift << std::endl;
1161 oss << "lr_uv_shift: " << +picParams->m_loopRestorationFlags.m_fields.m_lrUvShift << std::endl;
1162
1163 for (auto i = 0; i < 7; i++)
1164 {
1165 oss << "wm[" << +i << "].wmtype: " << +picParams->m_wm[i].m_wmtype << std::endl;
1166 for (auto j = 0; j < 8; j++)
1167 {
1168 oss << "wm[" << +i << "].wmmat[" << +j << "]: " << +picParams->m_wm[i].m_wmmat[j] << std::endl;
1169 }
1170 }
1171
1172 //Film Grain params
1173 oss << "apply_grain: " << +picParams->m_filmGrainParams.m_filmGrainInfoFlags.m_fields.m_applyGrain << std::endl;
1174 oss << "chroma_scaling_from_luma: " << +picParams->m_filmGrainParams.m_filmGrainInfoFlags.m_fields.m_chromaScalingFromLuma << std::endl;
1175 oss << "grain_scaling_minus_8: " << +picParams->m_filmGrainParams.m_filmGrainInfoFlags.m_fields.m_grainScalingMinus8 << std::endl;
1176 oss << "ar_coeff_lag: " << +picParams->m_filmGrainParams.m_filmGrainInfoFlags.m_fields.m_arCoeffLag << std::endl;
1177 oss << "ar_coeff_shift_minus_6: " << +picParams->m_filmGrainParams.m_filmGrainInfoFlags.m_fields.m_arCoeffShiftMinus6 << std::endl;
1178 oss << "grain_scale_shift: " << +picParams->m_filmGrainParams.m_filmGrainInfoFlags.m_fields.m_grainScaleShift << std::endl;
1179 oss << "overlap_flag: " << +picParams->m_filmGrainParams.m_filmGrainInfoFlags.m_fields.m_overlapFlag << std::endl;
1180 oss << "clip_to_restricted_range: " << +picParams->m_filmGrainParams.m_filmGrainInfoFlags.m_fields.m_clipToRestrictedRange << std::endl;
1181
1182 oss << "random_seed: " << +picParams->m_filmGrainParams.m_randomSeed << std::endl;
1183 oss << "num_y_points: " << +picParams->m_filmGrainParams.m_numYPoints << std::endl;
1184 for (auto i = 0; i < 14; i++)
1185 {
1186 oss << "point_y_value[" << +i << "]: " << +picParams->m_filmGrainParams.m_pointYValue[i] << std::endl;
1187 }
1188 for (auto i = 0; i < 14; i++)
1189 {
1190 oss << "point_y_scaling[" << +i << "]: " << +picParams->m_filmGrainParams.m_pointYScaling[i] << std::endl;
1191 }
1192
1193 oss << "num_cb_points: " << +picParams->m_filmGrainParams.m_numCbPoints << std::endl;
1194 for (auto i = 0; i < 10; i++)
1195 {
1196 oss << "point_cb_value[" << +i << "]: " << +picParams->m_filmGrainParams.m_pointCbValue[i] << std::endl;
1197 }
1198 for (auto i = 0; i < 10; i++)
1199 {
1200 oss << "point_cb_scaling[" << +i << "]: " << +picParams->m_filmGrainParams.m_pointCbScaling[i] << std::endl;
1201 }
1202
1203 oss << "num_cr_points: " << +picParams->m_filmGrainParams.m_numCrPoints << std::endl;
1204 for (auto i = 0; i < 10; i++)
1205 {
1206 oss << "point_cr_value[" << +i << "]: " << +picParams->m_filmGrainParams.m_pointCrValue[i] << std::endl;
1207 }
1208 for (auto i = 0; i < 10; i++)
1209 {
1210 oss << "point_cr_scaling[" << +i << "]: " << +picParams->m_filmGrainParams.m_pointCrScaling[i] << std::endl;
1211 }
1212
1213 for (auto i = 0; i < 24; i++)
1214 {
1215 oss << "ar_coeffs_y[" << +i << "]: " << +picParams->m_filmGrainParams.m_arCoeffsY[i] << std::endl;
1216 }
1217 for (auto i = 0; i < 25; i++)
1218 {
1219 oss << "ar_coeffs_cb[" << +i << "]: " << +picParams->m_filmGrainParams.m_arCoeffsCb[i] << std::endl;
1220 }
1221 for (auto i = 0; i < 25; i++)
1222 {
1223 oss << "ar_coeffs_cr[" << +i << "]: " << +picParams->m_filmGrainParams.m_arCoeffsCr[i] << std::endl;
1224 }
1225
1226 oss << "cb_mult: " << +picParams->m_filmGrainParams.m_cbMult << std::endl;
1227 oss << "cb_luma_mult: " << +picParams->m_filmGrainParams.m_cbLumaMult << std::endl;
1228 oss << "cb_offset: " << +picParams->m_filmGrainParams.m_cbOffset << std::endl;
1229 oss << "cr_mult: " << +picParams->m_filmGrainParams.m_crMult << std::endl;
1230 oss << "cr_luma_mult: " << +picParams->m_filmGrainParams.m_crLumaMult << std::endl;
1231 oss << "cr_offset: " << +picParams->m_filmGrainParams.m_crOffset << std::endl;
1232 oss << "StatusReportFeedbackNumber: " << +picParams->m_statusReportFeedbackNumber << std::endl;
1233
1234 //Driver internal
1235 oss << "losslessMode: " << +picParams->m_losslessMode << std::endl;
1236 oss << "superResUpscaledWidthMinus1: " << +picParams->m_superResUpscaledWidthMinus1 << std::endl;
1237 oss << "superResUpscaledHeightMinus1: " << +picParams->m_superResUpscaledHeightMinus1 << std::endl;
1238 for (auto i = 0; i < 8; i++)
1239 {
1240 oss << "activeRefBitMaskMfmv[" << +i << "]: " << +picParams->m_activeRefBitMaskMfmv[i] << std::endl;
1241 }
1242
1243 return oss;
1244 }
1245
1246 std::ostream &operator<<(std::ostream &oss, const CodecAv1TileParams &cr)
1247 {
1248 const CodecAv1TileParams *tileParams = &cr;
1249
1250 oss << "BSTileDataLocation" << +tileParams->m_bsTileDataLocation << std::endl;
1251 oss << "BSTileBytesInBuffer" << +tileParams->m_bsTileBytesInBuffer << std::endl;
1252 oss << "wBadBSBufferChopping" << +tileParams->m_badBSBufferChopping << std::endl;
1253 oss << "tile_row" << +tileParams->m_tileRow << std::endl;
1254 oss << "tile_column" << +tileParams->m_tileColumn << std::endl;
1255 oss << "anchor_frame_idx" << +tileParams->m_anchorFrameIdx.FrameIdx << std::endl;
1256 oss << "BSTilePayloadSizeInBytes" << +tileParams->m_bsTilePayloadSizeInBytes << std::endl;
1257
1258 oss << "--------- Intel Profile Specific ---------" << std::endl;
1259 oss << "tile_index" << +tileParams->m_tileIndex << std::endl;
1260 oss << "StartTileIdx" << +tileParams->m_startTileIdx << std::endl;
1261 oss << "EndTileIdx" << +tileParams->m_endTileIdx << std::endl;
1262
1263 return oss;
1264 }
1265
1266 void DumpDecodeAv1PicParams(CodecAv1PicParams *picParams, std::string fileName)
1267 {
1268 std::ostringstream oss;
1269 oss.setf(std::ios::showbase | std::ios::uppercase);
1270
1271 oss << *picParams << std::endl;
1272
1273 std::ofstream ofs(fileName, std::ios::out);
1274 ofs << oss.str();
1275 ofs.close();
1276 }
1277
1278 void DumpDecodeAv1TileParams(CodecAv1TileParams *tileParams, uint32_t tileNum, std::string fileName)
1279 {
1280 std::ostringstream oss;
1281 oss.setf(std::ios::showbase | std::ios::uppercase);
1282
1283 if (tileNum > 1)
1284 {
1285 oss << "Total Num: " << tileNum << std::endl;
1286 oss << std::endl;
1287 }
1288
1289 for (uint16_t i = 0; i < tileNum; i++)
1290 {
1291 if (tileNum > 1)
1292 {
1293 oss << "---------Index = " << i << "---------" << std::endl;
1294 }
1295
1296 oss << tileParams[i] << std::endl;
1297 }
1298
1299 std::ofstream ofs(fileName, std::ios::out);
1300 ofs << oss.str();
1301 ofs.close();
1302 }
1303
1304 // JPEG Decode
1305 std::ostream &operator<<(std::ostream &oss, const CodecDecodeJpegPicParams &cr)
1306 {
1307 const CodecDecodeJpegPicParams *picParams = &cr;
1308
1309 oss << "destPic.FrameIdx: " << +picParams->m_destPic.FrameIdx << std::endl;
1310 oss << "destPic.PicFlags: " << +picParams->m_destPic.PicFlags << std::endl;
1311 oss << "frameWidth: " << +picParams->m_frameWidth << std::endl;
1312 oss << "frameHeight: " << +picParams->m_frameHeight << std::endl;
1313 oss << "numCompInFrame: " << +picParams->m_numCompInFrame << std::endl;
1314
1315 // componentIdentifier[jpegNumComponent]
1316 for (uint32_t i = 0; i < jpegNumComponent; ++i)
1317 {
1318 oss << "componentIdentifier[" << +i << "]: " << +picParams->m_componentIdentifier[i] << std::endl;
1319 }
1320
1321 // quantTableSelector[jpegNumComponent]
1322 for (uint32_t i = 0; i < jpegNumComponent; ++i)
1323 {
1324 oss << "quantTableSelector[" << +i << "]: " << +picParams->m_quantTableSelector[i] << std::endl;
1325 }
1326
1327 oss << "chromaType: " << +picParams->m_chromaType << std::endl;
1328 oss << "rotation: " << +picParams->m_rotation << std::endl;
1329 oss << "totalScans: " << +picParams->m_totalScans << std::endl;
1330 oss << "interleavedData: " << +picParams->m_interleavedData << std::endl;
1331 oss << "reserved: " << +picParams->m_reserved << std::endl;
1332 oss << "statusReportFeedbackNumber: " << +picParams->m_statusReportFeedbackNumber << std::endl;
1333
1334 return oss;
1335 }
1336
1337 std::ostream &operator<<(std::ostream &oss, const CodecDecodeJpegScanParameter &cr)
1338 {
1339 const CodecDecodeJpegScanParameter *scanParams = &cr;
1340
1341 oss << "NumScans: " << +scanParams->NumScans << std::endl;
1342
1343 // ScanHeader[jpegNumComponent]
1344 for (uint32_t i = 0; i < jpegNumComponent; ++i)
1345 {
1346 oss << "ScanHeader[" << +i << "].NumComponents: " << +scanParams->ScanHeader[i].NumComponents << std::endl;
1347
1348 // ComponentSelector[jpegNumComponent]
1349 for (uint32_t j = 0; j < jpegNumComponent; ++j)
1350 {
1351 oss << "ScanHeader[" << +i << "].ComponentSelector[" << +j << "]: " << +scanParams->ScanHeader[i].ComponentSelector[j] << std::endl;
1352 }
1353
1354 // DcHuffTblSelector[jpegNumComponent]
1355 for (uint32_t j = 0; j < jpegNumComponent; ++j)
1356 {
1357 oss << "ScanHeader[" << +i << "].DcHuffTblSelector[" << +j << "]: " << +scanParams->ScanHeader[i].DcHuffTblSelector[j] << std::endl;
1358 }
1359
1360 // AcHuffTblSelector[jpegNumComponent]
1361 for (uint32_t j = 0; j < jpegNumComponent; ++j)
1362 {
1363 oss << "ScanHeader[" << +i << "].AcHuffTblSelector[" << +j << "]: " << +scanParams->ScanHeader[i].AcHuffTblSelector[j] << std::endl;
1364 }
1365
1366 oss << "ScanHeader[" << +i << "].RestartInterval: " << +scanParams->ScanHeader[i].RestartInterval << std::endl;
1367 oss << "ScanHeader[" << +i << "].MCUCount: " << +scanParams->ScanHeader[i].MCUCount << std::endl;
1368 oss << "ScanHeader[" << +i << "].ScanHoriPosition: " << +scanParams->ScanHeader[i].ScanHoriPosition << std::endl;
1369 oss << "ScanHeader[" << +i << "].ScanVertPosition: " << +scanParams->ScanHeader[i].ScanVertPosition << std::endl;
1370 oss << "ScanHeader[" << +i << "].DataOffset: " << +scanParams->ScanHeader[i].DataOffset << std::endl;
1371 oss << "ScanHeader[" << +i << "].DataLength: " << +scanParams->ScanHeader[i].DataLength << std::endl;
1372 }
1373
1374 return oss;
1375 }
1376
1377 std::ostream &operator<<(std::ostream &oss, const CODECHAL_DECODE_JPEG_HUFFMAN_TABLE &cr)
1378 {
1379 const CODECHAL_DECODE_JPEG_HUFFMAN_TABLE *huffmanTable = &cr;
1380
1381 // HuffTable[JPEG_MAX_NUM_HUFF_TABLE_INDEX]
1382 for (uint32_t i = 0; i < JPEG_MAX_NUM_HUFF_TABLE_INDEX; ++i)
1383 {
1384 // DC_BITS[JPEG_NUM_HUFF_TABLE_DC_BITS]
1385 oss << "HuffTable[" << +i << "].DC_BITS[0-" << (JPEG_NUM_HUFF_TABLE_DC_BITS - 1) << "]: " << std::endl;
1386
1387 for (uint32_t j = 0; j < JPEG_NUM_HUFF_TABLE_DC_BITS; ++j)
1388 {
1389 oss << +huffmanTable->HuffTable[i].DC_BITS[j] << " ";
1390 if (j % 6 == 5 || j == JPEG_NUM_HUFF_TABLE_DC_BITS - 1)
1391 {
1392 oss << std::endl;
1393 }
1394 }
1395 // DC_HUFFVAL[JPEG_NUM_HUFF_TABLE_DC_HUFFVAL]
1396 oss << "HuffTable[" << +i << "].DC_HUFFVAL[0-" << (JPEG_NUM_HUFF_TABLE_DC_HUFFVAL - 1) << "]: " << std::endl;
1397 for (uint32_t j = 0; j < JPEG_NUM_HUFF_TABLE_DC_HUFFVAL; ++j)
1398 {
1399 oss << +huffmanTable->HuffTable[i].DC_HUFFVAL[j] << ' ';
1400 if (j % 6 == 5 || j == JPEG_NUM_HUFF_TABLE_DC_HUFFVAL - 1)
1401 {
1402 oss << std::endl;
1403 }
1404 }
1405 // AC_BITS[JPEG_NUM_HUFF_TABLE_AC_BITS]
1406 oss << "HuffTable[" << +i << "].AC_BITS[0-" << (JPEG_NUM_HUFF_TABLE_AC_BITS - 1) << "]: " << std::endl;
1407
1408 for (uint32_t j = 0; j < JPEG_NUM_HUFF_TABLE_AC_BITS; ++j)
1409 {
1410 oss << +huffmanTable->HuffTable[i].AC_BITS[j] << ' ';
1411 if (j % 8 == 7 || j == JPEG_NUM_HUFF_TABLE_AC_BITS - 1)
1412 {
1413 oss << std::endl;
1414 }
1415 }
1416
1417 // AC_HUFFVAL[JPEG_NUM_HUFF_TABLE_AC_HUFFVAL]
1418 oss << "HuffTable[" << +i << "].AC_HUFFVAL[0-" << (JPEG_NUM_HUFF_TABLE_AC_HUFFVAL - 1) << "]: " << std::endl;
1419
1420 for (uint32_t j = 0; j < JPEG_NUM_HUFF_TABLE_AC_HUFFVAL; ++j)
1421 {
1422 oss << +huffmanTable->HuffTable[i].AC_HUFFVAL[j] << ' ';
1423 if (j % 9 == 8 || j == JPEG_NUM_HUFF_TABLE_AC_HUFFVAL - 1)
1424 {
1425 oss << std::endl;
1426 }
1427 }
1428 }
1429
1430 return oss;
1431 }
1432
1433 std::ostream &operator<<(std::ostream &oss, const CodecJpegQuantMatrix &cr)
1434 {
1435 const CodecJpegQuantMatrix *iqParams = &cr;
1436
1437 for (uint32_t j = 0; j < jpegNumComponent; j++)
1438 {
1439 oss << "Qmatrix " << +j << ": " << std::endl;
1440
1441 for (int8_t i = 0; i < 56; i += 8)
1442 {
1443 oss << "Qmatrix[" << +i / 8 << "]:";
1444 for (uint8_t k = 0; k < 8; k++)
1445 oss << +iqParams->m_quantMatrix[j][i + k] << " ";
1446 oss << std::endl;
1447 }
1448 }
1449
1450 return oss;
1451 }
1452
1453 void DumpDecodeJpegPicParams(CodecDecodeJpegPicParams *picParams, std::string fileName)
1454 {
1455 std::ostringstream oss;
1456 oss.setf(std::ios::showbase | std::ios::uppercase);
1457
1458 oss << *picParams << std::endl;
1459
1460 std::ofstream ofs(fileName, std::ios::out);
1461 ofs << oss.str();
1462 ofs.close();
1463 }
1464
1465 void DumpDecodeJpegScanParams(CodecDecodeJpegScanParameter *scanParams, std::string fileName)
1466 {
1467 std::ostringstream oss;
1468 oss.setf(std::ios::showbase | std::ios::uppercase);
1469
1470 oss << *scanParams << std::endl;
1471
1472 std::ofstream ofs(fileName, std::ios::out);
1473 ofs << oss.str();
1474 ofs.close();
1475 }
1476
1477 void DumpDecodeJpegHuffmanParams(PCODECHAL_DECODE_JPEG_HUFFMAN_TABLE huffmanTable, std::string fileName)
1478 {
1479 std::ostringstream oss;
1480 oss.setf(std::ios::showbase | std::ios::uppercase);
1481
1482 oss << *huffmanTable << std::endl;
1483
1484 std::ofstream ofs(fileName, std::ios::out);
1485 ofs << oss.str();
1486 ofs.close();
1487 }
1488
1489 void DumpDecodeJpegIqParams(CodecJpegQuantMatrix *iqParams, std::string fileName)
1490 {
1491 std::ostringstream oss;
1492 oss.setf(std::ios::showbase | std::ios::uppercase);
1493
1494 oss << *iqParams << std::endl;
1495
1496 std::ofstream ofs(fileName, std::ios::out);
1497 ofs << oss.str();
1498 ofs.close();
1499 }
1500
1501 // MPEG2 Decode
1502 std::ostream &operator<<(std::ostream &oss, const CodecDecodeMpeg2PicParams &cr)
1503 {
1504 const CodecDecodeMpeg2PicParams *picParams = &cr;
1505
1506 oss << "m_currPic FrameIdx: " << +picParams->m_currPic.FrameIdx << std::endl;
1507 oss << "m_currPic PicFlags: " << +picParams->m_currPic.PicFlags << std::endl;
1508 oss << "m_forwardRefIdx: " << +picParams->m_forwardRefIdx << std::endl;
1509 oss << "m_backwardRefIdx: " << +picParams->m_backwardRefIdx << std::endl;
1510 oss << "m_topFieldFirst: " << +picParams->m_topFieldFirst << std::endl;
1511 oss << "m_secondField: " << +picParams->m_secondField << std::endl;
1512 oss << "m_statusReportFeedbackNumber: " << +picParams->m_statusReportFeedbackNumber << std::endl;
1513 // union w0
1514 oss << "w0 m_value: " << +picParams->W0.m_value << std::endl;
1515 oss << "m_scanOrder: " << +picParams->W0.m_scanOrder << std::endl;
1516 oss << "m_intraVlcFormat: " << +picParams->W0.m_intraVlcFormat << std::endl;
1517 oss << "m_quantizerScaleType: " << +picParams->W0.m_quantizerScaleType << std::endl;
1518 oss << "m_concealmentMVFlag: " << +picParams->W0.m_concealmentMVFlag << std::endl;
1519 oss << "m_frameDctPrediction: " << +picParams->W0.m_frameDctPrediction << std::endl;
1520 oss << "m_topFieldFirst: " << +picParams->W0.m_topFieldFirst << std::endl;
1521 oss << "m_intraDCPrecision: " << +picParams->W0.m_intraDCPrecision << std::endl;
1522 // union w1
1523 oss << "w1 m_value: " << +picParams->W1.m_value << std::endl;
1524 oss << "m_fcode11: " << +picParams->W1.m_fcode11 << std::endl;
1525 oss << "m_fcode10: " << +picParams->W1.m_fcode10 << std::endl;
1526 oss << "m_fcode01: " << +picParams->W1.m_fcode01 << std::endl;
1527 oss << "m_fcode00: " << +picParams->W1.m_fcode00 << std::endl;
1528 oss << "m_horizontalSize: " << +picParams->m_horizontalSize << std::endl;
1529 oss << "m_verticalSize: " << +picParams->m_verticalSize << std::endl;
1530 oss << "m_pictureCodingType: " << +picParams->m_pictureCodingType << std::endl;
1531
1532 return oss;
1533 }
1534
1535 std::ostream &operator<<(std::ostream &oss, const CodecDecodeMpeg2SliceParams &cr)
1536 {
1537 const CodecDecodeMpeg2SliceParams *sliceControl = &cr;
1538
1539 oss << "m_sliceDataSize: " << +sliceControl->m_sliceDataSize << std::endl;
1540 oss << "m_sliceDataOffset: " << +sliceControl->m_sliceDataOffset << std::endl;
1541 oss << "m_macroblockOffset: " << +sliceControl->m_macroblockOffset << std::endl;
1542 oss << "m_sliceHorizontalPosition: " << +sliceControl->m_sliceHorizontalPosition << std::endl;
1543 oss << "m_sliceVerticalPosition: " << +sliceControl->m_sliceVerticalPosition << std::endl;
1544 oss << "m_quantiserScaleCode: " << +sliceControl->m_quantiserScaleCode << std::endl;
1545 oss << "m_numMbsForSlice: " << +sliceControl->m_numMbsForSlice << std::endl;
1546 oss << "m_numMbsForSliceOverflow: " << +sliceControl->m_numMbsForSliceOverflow << std::endl;
1547 oss << "m_reservedBits: " << +sliceControl->m_reservedBits << std::endl;
1548 oss << "m_startCodeBitOffset: " << +sliceControl->m_startCodeBitOffset << std::endl;
1549 oss << std::endl;
1550
1551 return oss;
1552 }
1553
1554 std::ostream &operator<<(std::ostream &oss, const CodecDecodeMpeg2MbParams &cr)
1555 {
1556 const CodecDecodeMpeg2MbParams *mbParams = &cr;
1557
1558 oss << "m_mbAddr: " << +mbParams->m_mbAddr << std::endl;
1559 oss << "MBType.m_intraMb: " << +mbParams->MBType.m_intraMb << std::endl;
1560 oss << "MBType.m_motionFwd: " << +mbParams->MBType.m_motionFwd << std::endl;
1561 oss << "MBType.m_motionBwd: " << +mbParams->MBType.m_motionBwd << std::endl;
1562 oss << "MBType.m_motion4mv: " << +mbParams->MBType.m_motion4mv << std::endl;
1563 oss << "MBType.m_h261Lpfilter: " << +mbParams->MBType.m_h261Lpfilter << std::endl;
1564 oss << "MBType.m_fieldResidual: " << +mbParams->MBType.m_fieldResidual << std::endl;
1565 oss << "MBType.m_mbScanMethod: " << +mbParams->MBType.m_mbScanMethod << std::endl;
1566 oss << "MBType.m_motionType: " << +mbParams->MBType.m_motionType << std::endl;
1567 oss << "MBType.m_hostResidualDiff: " << +mbParams->MBType.m_hostResidualDiff << std::endl;
1568 oss << "MBType.m_mvertFieldSel: " << +mbParams->MBType.m_mvertFieldSel << std::endl;
1569 oss << "m_mbSkipFollowing: " << +mbParams->m_mbSkipFollowing << std::endl;
1570 oss << "m_mbDataLoc: " << +mbParams->m_mbDataLoc << std::endl;
1571 oss << "m_codedBlockPattern: " << +mbParams->m_codedBlockPattern << std::endl;
1572
1573 // NumCoeff[CODEC_NUM_BLOCK_PER_MB]
1574 for (uint16_t i = 0; i < CODEC_NUM_BLOCK_PER_MB; ++i)
1575 {
1576 oss << "m_numCoeff[" << +i << "]: " << +mbParams->m_numCoeff[i] << std::endl;
1577 }
1578
1579 // motion_vectors[8],printing them in 4 value chunks per line
1580 for (uint8_t i = 0; i < 2; ++i)
1581 {
1582 oss << "m_motionVectors[" << +i * 4 << "-" << (+i * 4) + 3 << "]: ";
1583 for (uint8_t j = 0; j < 4; j++)
1584 oss << +mbParams->m_motionVectors[i * 4 + j] << " ";
1585 oss << std::endl;
1586 }
1587
1588 oss << std::endl;
1589
1590 return oss;
1591 }
1592
1593 std::ostream &operator<<(std::ostream &oss, const CodecMpeg2IqMatrix &cr)
1594 {
1595 const CodecMpeg2IqMatrix *iqParams = &cr;
1596
1597 if (iqParams->m_loadIntraQuantiserMatrix)
1598 {
1599 oss << "intra_QmatrixData:" << std::endl;
1600
1601 for (uint8_t i = 0; i < 56; i += 8)
1602 {
1603 oss << "Qmatrix[" << +i / 8 << "]: ";
1604 for (uint8_t j = 0; j < 8; j++)
1605 oss << +iqParams->m_intraQuantiserMatrix[i + j] << " ";
1606 oss << std::endl;
1607 }
1608 }
1609
1610 if (iqParams->m_loadNonIntraQuantiserMatrix)
1611 {
1612 oss << "non_intra_QmatrixData:" << std::endl;
1613
1614 for (uint8_t i = 0; i < 56; i += 8)
1615 {
1616 oss << "Qmatrix[" << +i / 8 << "]: ";
1617 for (uint8_t j = 0; j < 8; j++)
1618 oss << +iqParams->m_nonIntraQuantiserMatrix[i + j] << " ";
1619 oss << std::endl;
1620 }
1621 }
1622
1623 if (iqParams->m_loadChromaIntraQuantiserMatrix)
1624 {
1625 oss << "chroma_intra_QmatrixData:" << std::endl;
1626
1627 for (uint8_t i = 0; i < 56; i += 8)
1628 {
1629 oss << "Qmatrix[" << +i / 8 << "]: ";
1630 for (uint8_t j = 0; j < 8; j++)
1631 oss << +iqParams->m_chromaIntraQuantiserMatrix[i + j] << " ";
1632 oss << std::endl;
1633 }
1634 }
1635
1636 if (iqParams->m_loadChromaNonIntraQuantiserMatrix)
1637 {
1638 oss << "chroma_non_intra_QmatrixData:" << std::endl;
1639
1640 for (uint8_t i = 0; i < 56; i += 8)
1641 {
1642 oss << "Qmatrix[" << +i / 8 << "]: ";
1643 for (uint8_t j = 0; j < 8; j++)
1644 oss << +iqParams->m_chromaNonIntraQuantiserMatrix[i + j] << " ";
1645 oss << std::endl;
1646 }
1647 }
1648
1649 return oss;
1650 }
1651
1652 void DumpDecodeMpeg2PicParams(CodecDecodeMpeg2PicParams *picParams, std::string fileName)
1653 {
1654 std::ostringstream oss;
1655 oss.setf(std::ios::showbase | std::ios::uppercase);
1656
1657 oss << *picParams << std::endl;
1658
1659 std::ofstream ofs(fileName, std::ios::out);
1660 ofs << oss.str();
1661 ofs.close();
1662 }
1663
1664 void DumpDecodeMpeg2SliceParams(CodecDecodeMpeg2SliceParams *sliceParams, uint32_t numSlices, std::string fileName)
1665 {
1666 std::ostringstream oss;
1667 oss.setf(std::ios::showbase | std::ios::uppercase);
1668
1669 if (numSlices > 1)
1670 {
1671 oss << "Total Num: " << numSlices << std::endl;
1672 oss << std::endl;
1673 }
1674
1675 for (uint32_t i = 0; i < numSlices; i++)
1676 {
1677 if (numSlices > 1)
1678 {
1679 oss << "---------Index = " << i << "---------" << std::endl;
1680 }
1681
1682 oss << sliceParams[i] << std::endl;
1683 }
1684
1685 std::ofstream ofs(fileName, std::ios::out);
1686 ofs << oss.str();
1687 ofs.close();
1688 }
1689
1690 void DumpDecodeMpeg2MbParams(CodecDecodeMpeg2MbParams *mbParams, uint32_t numMbs, std::string fileName)
1691 {
1692 std::ostringstream oss;
1693 oss.setf(std::ios::showbase | std::ios::uppercase);
1694
1695 if (numMbs > 1)
1696 {
1697 oss << "Total Num: " << numMbs << std::endl;
1698 oss << std::endl;
1699 }
1700
1701 for (uint32_t i = 0; i < numMbs; i++)
1702 {
1703 if (numMbs > 1)
1704 {
1705 oss << "---------Index = " << i << "---------" << std::endl;
1706 }
1707
1708 oss << mbParams[i] << std::endl;
1709 }
1710
1711 std::ofstream ofs(fileName, std::ios::out);
1712 ofs << oss.str();
1713 ofs.close();
1714 }
1715
1716 void DumpDecodeMpeg2IqParams(CodecMpeg2IqMatrix *iqParams, std::string fileName)
1717 {
1718 std::ostringstream oss;
1719 oss.setf(std::ios::showbase | std::ios::uppercase);
1720
1721 oss << *iqParams << std::endl;
1722
1723 std::ofstream ofs(fileName, std::ios::out);
1724 ofs << oss.str();
1725 ofs.close();
1726 }
1727
1728 // VP8 Decode
1729 std::ostream &operator<<(std::ostream &oss, const CODEC_VP8_PIC_PARAMS &cr)
1730 {
1731 const CODEC_VP8_PIC_PARAMS *picParams = &cr;
1732
1733 oss << "CurrPic FrameIdx: " << +picParams->CurrPic.FrameIdx << std::endl;
1734 oss << "CurrPic PicFlags: " << +picParams->CurrPic.PicFlags << std::endl;
1735 oss << "wFrameWidthInMbsMinus1: " << +picParams->wFrameWidthInMbsMinus1 << std::endl;
1736 oss << "wFrameHeightInMbsMinus1: " << +picParams->wFrameHeightInMbsMinus1 << std::endl;
1737 oss << "ucCurrPicIndex: " << +picParams->ucCurrPicIndex << std::endl;
1738 oss << "ucLastRefPicIndex: " << +picParams->ucLastRefPicIndex << std::endl;
1739 oss << "ucGoldenRefPicIndex: " << +picParams->ucGoldenRefPicIndex << std::endl;
1740 oss << "ucAltRefPicIndex: " << +picParams->ucAltRefPicIndex << std::endl;
1741 oss << "ucDeblockedPicIndex: " << +picParams->ucDeblockedPicIndex << std::endl;
1742 oss << "ucReserved8Bits: " << +picParams->ucReserved8Bits << std::endl;
1743 oss << "wPicFlags: " << +picParams->wPicFlags << std::endl;
1744 oss << "key_frame: " << +picParams->key_frame << std::endl;
1745 oss << "version: " << +picParams->version << std::endl;
1746 oss << "segmentation_enabled: " << +picParams->segmentation_enabled << std::endl;
1747 oss << "update_mb_segmentation_map: " << +picParams->update_mb_segmentation_map << std::endl;
1748 oss << "update_segment_feature_data: " << +picParams->update_segment_feature_data << std::endl;
1749 oss << "filter_type: " << +picParams->filter_type << std::endl;
1750 oss << "sign_bias_golden: " << +picParams->sign_bias_golden << std::endl;
1751 oss << "sign_bias_alternate: " << +picParams->sign_bias_alternate << std::endl;
1752 oss << "mb_no_coeff_skip: " << +picParams->mb_no_coeff_skip << std::endl;
1753 oss << "mode_ref_lf_delta_update: " << +picParams->mode_ref_lf_delta_update << std::endl;
1754 oss << "CodedCoeffTokenPartition: " << +picParams->CodedCoeffTokenPartition << std::endl;
1755 oss << "LoopFilterDisable: " << +picParams->LoopFilterDisable << std::endl;
1756 oss << "loop_filter_adj_enable: " << +picParams->loop_filter_adj_enable << std::endl;
1757
1758 for (uint8_t i = 0; i < 4; ++i)
1759 {
1760 oss << "ucLoopFilterLevel[" << +i << "]: " << +picParams->ucLoopFilterLevel[i] << std::endl;
1761 }
1762
1763 for (uint8_t i = 0; i < 4; ++i)
1764 {
1765 oss << "cRefLfDelta[" << +i << "]: " << +picParams->cRefLfDelta[i] << std::endl;
1766 }
1767
1768 for (uint8_t i = 0; i < 4; ++i)
1769 {
1770 oss << "cModeLfDelta[" << +i << "]: " << +picParams->cModeLfDelta[i] << std::endl;
1771 }
1772 oss << "ucSharpnessLevel: " << +picParams->ucSharpnessLevel << std::endl;
1773
1774 for (uint8_t i = 0; i < 3; ++i)
1775 {
1776 oss << "cMbSegmentTreeProbs[" << +i << "]: " << +picParams->cMbSegmentTreeProbs[i] << std::endl;
1777 }
1778 oss << "ucProbSkipFalse: " << +picParams->ucProbSkipFalse << std::endl;
1779 oss << "ucProbIntra: " << +picParams->ucProbIntra << std::endl;
1780 oss << "ucProbLast: " << +picParams->ucProbLast << std::endl;
1781 oss << "ucProbGolden: " << +picParams->ucProbGolden << std::endl;
1782
1783 for (uint8_t i = 0; i < 4; ++i)
1784 {
1785 oss << "ucYModeProbs[" << +i << "]: " << +picParams->ucYModeProbs[i] << std::endl;
1786 }
1787
1788 for (uint8_t i = 0; i < 3; ++i)
1789 {
1790 oss << "ucUvModeProbs[" << +i << "]: " << +picParams->ucUvModeProbs[i] << std::endl;
1791 }
1792 oss << "ucReserved8Bits1: " << +picParams->ucReserved8Bits1 << std::endl;
1793 oss << "ucP0EntropyCount: " << +picParams->ucP0EntropyCount << std::endl;
1794 oss << "ucP0EntropyValue: " << +picParams->ucP0EntropyValue << std::endl;
1795 oss << "uiP0EntropyRange: " << +picParams->uiP0EntropyRange << std::endl;
1796 oss << "uiFirstMbByteOffset: " << +picParams->uiFirstMbByteOffset << std::endl;
1797
1798 for (uint8_t i = 0; i < 2; ++i)
1799 {
1800 for (uint8_t j = 0; j < CODEC_VP8_MVP_COUNT; ++j)
1801 {
1802 oss << "ucMvUpdateProb[" << +i << "][" << +j << "]: " << +picParams->ucMvUpdateProb[i][j] << std::endl;
1803 }
1804 }
1805 for (uint8_t i = 0; i < CODEC_VP8_MAX_PARTITION_NUMBER; ++i)
1806 {
1807 oss << "uiPartitionSize[" << +i << "]: " << +picParams->uiPartitionSize[i] << std::endl;
1808 }
1809 oss << "uiStatusReportFeedbackNumber: " << +picParams->uiStatusReportFeedbackNumber << std::endl;
1810
1811 return oss;
1812 }
1813
1814 std::ostream &operator<<(std::ostream &oss, const CODEC_VP8_SLICE_PARAMS &cr)
1815 {
1816 const CODEC_VP8_SLICE_PARAMS *sliceParams = &cr;
1817
1818 oss << "BSNALunitDataLocation: " << +sliceParams->BSNALunitDataLocation << std::endl;
1819 oss << "SliceBytesInBuffer: " << +sliceParams->SliceBytesInBuffer << std::endl;
1820 oss << std::endl;
1821
1822 return oss;
1823 }
1824
1825 std::ostream &operator<<(std::ostream &oss, const CODEC_VP8_IQ_MATRIX_PARAMS &cr)
1826 {
1827 const CODEC_VP8_IQ_MATRIX_PARAMS *iqParams = &cr;
1828
1829 for (uint8_t i = 0; i < 4; ++i)
1830 {
1831 for (uint8_t j = 0; j < 6; ++j)
1832 {
1833 oss << "quantization_values[" << +i << "][" << +j << "]: " << +iqParams->quantization_values[i][j] << std::endl;
1834 }
1835 }
1836
1837 return oss;
1838 }
1839
1840 void DumpDecodeVp8PicParams(PCODEC_VP8_PIC_PARAMS picParams, std::string fileName)
1841 {
1842 std::ostringstream oss;
1843 oss.setf(std::ios::showbase | std::ios::uppercase);
1844
1845 oss << *picParams << std::endl;
1846
1847 std::ofstream ofs(fileName, std::ios::out);
1848 ofs << oss.str();
1849 ofs.close();
1850 }
1851
1852 void DumpDecodeVp8SliceParams(PCODEC_VP8_SLICE_PARAMS sliceParams, std::string fileName)
1853 {
1854 std::ostringstream oss;
1855 oss.setf(std::ios::showbase | std::ios::uppercase);
1856
1857 oss << *sliceParams << std::endl;
1858
1859 std::ofstream ofs(fileName, std::ios::out);
1860 ofs << oss.str();
1861 ofs.close();
1862 }
1863
1864 void DumpDecodeVp8IqParams(PCODEC_VP8_IQ_MATRIX_PARAMS iqParams, std::string fileName)
1865 {
1866 std::ostringstream oss;
1867 oss.setf(std::ios::showbase | std::ios::uppercase);
1868
1869 oss << *iqParams << std::endl;
1870
1871 std::ofstream ofs(fileName, std::ios::out);
1872 ofs << oss.str();
1873 ofs.close();
1874 }
1875
1876 CodechalDebugInterface::CodechalDebugInterface()
1877 {
1878 MOS_ZeroMemory(m_fileName, sizeof(m_fileName));
1879 MOS_ZeroMemory(m_path, sizeof(m_path));
1880
1881 m_dumpYUVSurfaceLegacy = [this](
1882 PMOS_SURFACE surface,
1883 const char *attrName,
1884 const char *surfName,
1885 CODECHAL_MEDIA_STATE_TYPE mediaState,
1886 uint32_t width_in,
1887 uint32_t height_in) {
1888 bool hasAuxSurf = false;
1889 bool isPlanar = true;
1890 bool hasRefSurf = false;
1891 uint8_t *surfBaseAddr = nullptr;
1892 uint8_t *lockedAddr = nullptr;
1893 if (!DumpIsEnabled(attrName, mediaState))
1894 {
1895 return MOS_STATUS_SUCCESS;
1896 }
1897
1898 const char *funcName = (m_codecFunction == CODECHAL_FUNCTION_DECODE) ? "_DEC" : (m_codecFunction == CODECHAL_FUNCTION_CENC_DECODE ? "_DEC" : "_ENC");
1899 std::string bufName = std::string(surfName) + "_w[" + std::to_string(surface->dwWidth) + "]_h[" + std::to_string(surface->dwHeight) + "]_p[" + std::to_string(surface->dwPitch) + "]";
1900
1901 const char *filePath = CreateFileName(funcName, bufName.c_str(), hasAuxSurf ? ".Y" : ".yuv");
1902
1903 MOS_LOCK_PARAMS lockFlags;
1904 GMM_RESOURCE_FLAG gmmFlags;
1905
1906 MOS_ZeroMemory(&gmmFlags, sizeof(gmmFlags));
1907 CODECHAL_DEBUG_CHK_NULL(surface);
1908 gmmFlags = surface->OsResource.pGmmResInfo->GetResFlags();
1909 hasAuxSurf = (gmmFlags.Gpu.MMC || gmmFlags.Info.MediaCompressed) && gmmFlags.Gpu.UnifiedAuxSurface;
1910
1911 if (!m_configMgr->AttrIsEnabled(CodechalDbgAttr::attrDecodeAuxSurface))
1912 {
1913 hasAuxSurf = false;
1914 }
1915
1916 isPlanar = !!(m_osInterface->pfnGetGmmClientContext(m_osInterface)->IsPlanar(surface->OsResource.pGmmResInfo->GetResourceFormat()));
1917
1918 MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS));
1919 lockFlags.ReadOnly = 1;
1920 lockFlags.TiledAsTiled = 1; // Bypass GMM CPU blit due to some issues in GMM CpuBlt function
1921 if (hasAuxSurf)
1922 {
1923 // Dump MMC surface as raw layout
1924 lockFlags.NoDecompress = 1;
1925 }
1926
1927 // when not setting dump compressed surface cfg, use ve copy for dump
1928 if (!m_configMgr->AttrIsEnabled(CodechalDbgAttr::attrDecodeCompSurface))
1929 {
1930 DumpUncompressedYUVSurface(surface);
1931 lockedAddr = (uint8_t *)m_osInterface->pfnLockResource(m_osInterface, &m_temp2DSurfForCopy.OsResource, &lockFlags);
1932 CODECHAL_DEBUG_CHK_NULL(lockedAddr);
1933 surface = &m_temp2DSurfForCopy;
1934 }
1935 else
1936 {
1937 // when setting dump compressed surface cfg, try directly lock surface
1938 lockedAddr = (uint8_t *)m_osInterface->pfnLockResource(m_osInterface, &surface->OsResource, &lockFlags);
1939 // if failed to lock, try to submit copy task and reallocate temp surface for dump
1940 if (lockedAddr == nullptr)
1941 {
1942 uint32_t sizeToBeCopied = 0;
1943 MOS_GFXRES_TYPE ResType;
1944
1945 #if !defined(LINUX)
1946 ResType = surface->OsResource.ResType;
1947
1948 CODECHAL_DEBUG_CHK_STATUS(ReAllocateSurface(
1949 &m_temp2DSurfForCopy,
1950 surface,
1951 "Temp2DSurfForSurfDumper",
1952 ResType));
1953 #endif
1954
1955 uint32_t arraySize = surface->OsResource.pGmmResInfo->GetArraySize();
1956
1957 if (arraySize == 0)
1958 {
1959 return MOS_STATUS_UNKNOWN;
1960 }
1961
1962 uint32_t sizeSrcSurface = (uint32_t)(surface->OsResource.pGmmResInfo->GetSizeMainSurface()) / arraySize;
1963 // Ensure allocated buffer size contains the source surface size
1964 if (m_temp2DSurfForCopy.OsResource.pGmmResInfo->GetSizeMainSurface() >= sizeSrcSurface)
1965 {
1966 sizeToBeCopied = sizeSrcSurface;
1967 }
1968
1969 if (sizeToBeCopied == 0)
1970 {
1971 CODECHAL_DEBUG_ASSERTMESSAGE("Cannot allocate correct size, failed to copy nonlockable resource");
1972 return MOS_STATUS_INVALID_PARAMETER;
1973 }
1974
1975 CODECHAL_DEBUG_VERBOSEMESSAGE("Temp2DSurfaceForCopy width %d, height %d, pitch %d, TileType %d, bIsCompressed %d, CompressionMode %d",
1976 m_temp2DSurfForCopy.dwWidth,
1977 m_temp2DSurfForCopy.dwHeight,
1978 m_temp2DSurfForCopy.dwPitch,
1979 m_temp2DSurfForCopy.TileType,
1980 m_temp2DSurfForCopy.bIsCompressed,
1981 m_temp2DSurfForCopy.CompressionMode);
1982
1983 uint32_t bpp = surface->OsResource.pGmmResInfo->GetBitsPerPixel();
1984
1985 CODECHAL_DEBUG_CHK_STATUS(m_osInterface->pfnMediaCopyResource2D(m_osInterface, &surface->OsResource, &m_temp2DSurfForCopy.OsResource, surface->dwPitch, sizeSrcSurface / (surface->dwPitch), bpp, false));
1986
1987 lockedAddr = (uint8_t *)m_osInterface->pfnLockResource(m_osInterface, &m_temp2DSurfForCopy.OsResource, &lockFlags);
1988 CODECHAL_DEBUG_CHK_NULL(lockedAddr);
1989 surface = &m_temp2DSurfForCopy;
1990 }
1991 }
1992 gmmFlags = surface->OsResource.pGmmResInfo->GetResFlags();
1993 surfBaseAddr = lockedAddr;
1994
1995 // Use MOS swizzle for non-vecopy dump
1996 if (m_configMgr->AttrIsEnabled(CodechalDbgAttr::attrDecodeCompSurface))
1997 {
1998 uint32_t sizeMain = (uint32_t)(surface->OsResource.pGmmResInfo->GetSizeMainSurface());
1999 surfBaseAddr = (uint8_t *)MOS_AllocMemory(sizeMain);
2000 CODECHAL_DEBUG_CHK_NULL(surfBaseAddr);
2001 Mos_SwizzleData(lockedAddr, surfBaseAddr, surface->TileType, MOS_TILE_LINEAR, sizeMain / surface->dwPitch, surface->dwPitch, !MEDIA_IS_SKU(m_osInterface->pfnGetSkuTable(m_osInterface), FtrTileY) || gmmFlags.Info.Tile4);
2002 }
2003
2004 uint8_t *data = surfBaseAddr;
2005 data += surface->dwOffset + surface->YPlaneOffset.iYOffset * surface->dwPitch;
2006
2007 uint32_t width = width_in ? width_in : surface->dwWidth;
2008 uint32_t height = height_in ? height_in : surface->dwHeight;
2009 uint32_t lumaheight = 0;
2010
2011 switch (surface->Format)
2012 {
2013 case Format_YUY2:
2014 case Format_P010:
2015 case Format_P016:
2016 width = width << 1;
2017 break;
2018 case Format_Y216:
2019 case Format_Y210: //422 10bit -- Y0[15:0]:U[15:0]:Y1[15:0]:V[15:0] = 32bits per pixel = 4Bytes per pixel
2020 case Format_Y410: //444 10bit -- A[31:30]:V[29:20]:Y[19:10]:U[9:0] = 32bits per pixel = 4Bytes per pixel
2021 case Format_R10G10B10A2:
2022 case Format_AYUV: //444 8bit -- A[31:24]:Y[23:16]:U[15:8]:V[7:0] = 32bits per pixel = 4Bytes per pixel
2023 case Format_A8R8G8B8:
2024 width = width << 2;
2025 break;
2026 case Format_Y416:
2027 width = width << 3;
2028 break;
2029 case Format_R8G8B8:
2030 width = width * 3;
2031 break;
2032 default:
2033 break;
2034 }
2035
2036 uint32_t pitch = surface->dwPitch;
2037 if (surface->Format == Format_UYVY)
2038 pitch = width;
2039
2040 if (CodecHal_PictureIsBottomField(m_currPic))
2041 {
2042 data += pitch;
2043 }
2044
2045 if (CodecHal_PictureIsField(m_currPic))
2046 {
2047 pitch *= 2;
2048 height /= 2;
2049 }
2050
2051 lumaheight = hasAuxSurf ? GFX_ALIGN(height, 32) : height;
2052
2053 std::ofstream ofs(filePath, std::ios_base::out | std::ios_base::binary);
2054 if (ofs.fail())
2055 {
2056 return MOS_STATUS_UNKNOWN;
2057 }
2058
2059 // write luma data to file
2060 for (uint32_t h = 0; h < lumaheight; h++)
2061 {
2062 ofs.write((char *)data, hasAuxSurf ? pitch : width);
2063 data += pitch;
2064 }
2065
2066 switch (surface->Format)
2067 {
2068 case Format_NV12:
2069 case Format_P010:
2070 case Format_P016:
2071 height = height >> 1;
2072 break;
2073 case Format_Y416: //444 16bit
2074 case Format_AYUV: //444 8bit
2075 case Format_AUYV:
2076 case Format_Y410: //444 10bit
2077 case Format_R10G10B10A2:
2078 height = height << 1;
2079 break;
2080 case Format_YUY2:
2081 case Format_YUYV:
2082 case Format_YVYU:
2083 case Format_UYVY:
2084 case Format_VYUY:
2085 case Format_Y216: //422 16bit
2086 case Format_Y210: //422 10bit
2087 case Format_P208: //422 8bit
2088 case Format_RGBP:
2089 case Format_BGRP:
2090 break;
2091 case Format_422V:
2092 case Format_IMC3:
2093 height = height / 2;
2094 break;
2095 default:
2096 height = 0;
2097 break;
2098 }
2099
2100 uint8_t *vPlaneData = surfBaseAddr;
2101 if (isPlanar)
2102 {
2103 if (hasAuxSurf)
2104 {
2105 data = surfBaseAddr + surface->UPlaneOffset.iSurfaceOffset;
2106 }
2107 else
2108 {
2109 // LibVA uses iSurfaceOffset instead of iLockSurfaceOffset.To use this dump in Linux,
2110 // changing the variable to iSurfaceOffset may be necessary for the chroma dump to work properly.
2111 #if defined(LINUX)
2112 data = surfBaseAddr + surface->UPlaneOffset.iSurfaceOffset;
2113 if (surface->Format == Format_422V || surface->Format == Format_IMC3)
2114 {
2115 vPlaneData = surfBaseAddr + surface->VPlaneOffset.iSurfaceOffset;
2116 }
2117 #else
2118 data = surfBaseAddr + surface->UPlaneOffset.iLockSurfaceOffset;
2119 if (surface->Format == Format_422V ||
2120 surface->Format == Format_IMC3 ||
2121 surface->Format == Format_RGBP ||
2122 surface->Format == Format_BGRP)
2123 {
2124 vPlaneData = surfBaseAddr + surface->VPlaneOffset.iLockSurfaceOffset;
2125 }
2126 #endif
2127 }
2128
2129 //No seperate chroma for linear surfaces
2130 // Seperate Y/UV if MMC is enabled
2131 if (hasAuxSurf)
2132 {
2133 const char *uvfilePath = CreateFileName(funcName, bufName.c_str(), ".UV");
2134 std::ofstream ofs1(uvfilePath, std::ios_base::out | std::ios_base::binary);
2135 if (ofs1.fail())
2136 {
2137 return MOS_STATUS_UNKNOWN;
2138 }
2139 // write chroma data to file
2140 for (uint32_t h = 0; h < GFX_ALIGN(height, 32); h++)
2141 {
2142 ofs1.write((char *)data, pitch);
2143 data += pitch;
2144 }
2145 ofs1.close();
2146 }
2147 else
2148 {
2149 // write chroma data to file
2150 for (uint32_t h = 0; h < height; h++)
2151 {
2152 ofs.write((char *)data, hasAuxSurf ? pitch : width);
2153 data += pitch;
2154 }
2155
2156 // write v planar data to file
2157 if (surface->Format == Format_422V ||
2158 surface->Format == Format_IMC3 ||
2159 surface->Format == Format_RGBP ||
2160 surface->Format == Format_BGRP)
2161 {
2162 for (uint32_t h = 0; h < height; h++)
2163 {
2164 ofs.write((char *)vPlaneData, hasAuxSurf ? pitch : width);
2165 vPlaneData += pitch;
2166 }
2167 }
2168 }
2169 ofs.close();
2170 }
2171
2172 if (hasAuxSurf)
2173 {
2174 uint32_t resourceIndex = m_osInterface->pfnGetResourceIndex(&surface->OsResource);
2175 uint8_t *yAuxData = (uint8_t *)lockedAddr + surface->OsResource.pGmmResInfo->GetPlanarAuxOffset(resourceIndex, GMM_AUX_Y_CCS);
2176 uint32_t yAuxSize = isPlanar ? ((uint32_t)(surface->OsResource.pGmmResInfo->GetPlanarAuxOffset(resourceIndex, GMM_AUX_UV_CCS) -
2177 surface->OsResource.pGmmResInfo->GetPlanarAuxOffset(resourceIndex, GMM_AUX_Y_CCS)))
2178 : (uint32_t)surface->OsResource.pGmmResInfo->GetAuxQPitch();
2179
2180 // Y Aux data
2181 const char *yAuxfilePath = CreateFileName(funcName, bufName.c_str(), ".Yaux");
2182 std::ofstream ofs2(yAuxfilePath, std::ios_base::out | std::ios_base::binary);
2183 if (ofs2.fail())
2184 {
2185 return MOS_STATUS_UNKNOWN;
2186 }
2187 ofs2.write((char *)yAuxData, yAuxSize);
2188 ofs2.close();
2189
2190 if (isPlanar)
2191 {
2192 uint8_t *uvAuxData = (uint8_t *)lockedAddr + surface->OsResource.pGmmResInfo->GetPlanarAuxOffset(resourceIndex, GMM_AUX_UV_CCS);
2193 uint32_t uvAuxSize = (uint32_t)surface->OsResource.pGmmResInfo->GetAuxQPitch() - yAuxSize;
2194
2195 // UV Aux data
2196 const char *uvAuxfilePath = CreateFileName(funcName, bufName.c_str(), ".UVaux");
2197 std::ofstream ofs3(uvAuxfilePath, std::ios_base::out | std::ios_base::binary);
2198 if (ofs3.fail())
2199 {
2200 return MOS_STATUS_UNKNOWN;
2201 }
2202 ofs3.write((char *)uvAuxData, uvAuxSize);
2203
2204 ofs3.close();
2205 }
2206 }
2207
2208 if (surfBaseAddr && m_configMgr->AttrIsEnabled(CodechalDbgAttr::attrDecodeCompSurface))
2209 {
2210 MOS_FreeMemory(surfBaseAddr);
2211 }
2212 if (lockedAddr)
2213 {
2214 m_osInterface->pfnUnlockResource(m_osInterface, &surface->OsResource);
2215 }
2216
2217 return MOS_STATUS_SUCCESS;
2218 };
2219
2220 m_dumpYUVSurface = [this](
2221 PMOS_SURFACE surface,
2222 const char *attrName,
2223 const char *surfName,
2224 CODECHAL_MEDIA_STATE_TYPE mediaState,
2225 uint32_t width_in,
2226 uint32_t height_in) {
2227 if (!DumpIsEnabled(attrName, mediaState))
2228 {
2229 return MOS_STATUS_SUCCESS;
2230 }
2231
2232 const char *funcName = (m_codecFunction == CODECHAL_FUNCTION_DECODE) ? "_DEC" : (m_codecFunction == CODECHAL_FUNCTION_CENC_DECODE ? "_DEC" : "_ENC");
2233 std::string bufName = std::string(surfName) + "_w[" + std::to_string(surface->dwWidth) + "]_h[" + std::to_string(surface->dwHeight) + "]_p[" + std::to_string(surface->dwPitch) + "]";
2234
2235 const char *filePath = CreateFileName(funcName, bufName.c_str(), ".yuv");
2236
2237 MediaDebugFastDump::Dump(surface->OsResource, filePath);
2238
2239 if (!MediaDebugFastDump::IsGood())
2240 {
2241 return m_dumpYUVSurfaceLegacy(
2242 surface,
2243 attrName,
2244 surfName,
2245 mediaState,
2246 width_in,
2247 height_in);
2248 }
2249
2250 return MOS_STATUS_SUCCESS;
2251 };
2252
2253 m_dumpBufferLegacy = [this](
2254 PMOS_RESOURCE resource,
2255 const char *attrName,
2256 const char *bufferName,
2257 uint32_t size,
2258 uint32_t offset,
2259 CODECHAL_MEDIA_STATE_TYPE mediaState) {
2260 MEDIA_DEBUG_FUNCTION_ENTER;
2261
2262 MEDIA_DEBUG_CHK_NULL(resource);
2263 MEDIA_DEBUG_CHK_NULL(bufferName);
2264
2265 if (size == 0)
2266 {
2267 return MOS_STATUS_SUCCESS;
2268 }
2269
2270 if (attrName)
2271 {
2272 bool attrEnabled = false;
2273
2274 if (mediaState == CODECHAL_NUM_MEDIA_STATES)
2275 {
2276 attrEnabled = m_configMgr->AttrIsEnabled(attrName);
2277 }
2278 else
2279 {
2280 attrEnabled = static_cast<CodecDebugConfigMgr *>(m_configMgr)->AttrIsEnabled(mediaState, attrName);
2281 }
2282
2283 if (!attrEnabled)
2284 {
2285 return MOS_STATUS_SUCCESS;
2286 }
2287 }
2288
2289 const char *fileName;
2290 bool binaryDump = false;
2291 if ((!strcmp(attrName, MediaDbgAttr::attrDecodeBitstream)) ||
2292 (!strcmp(attrName, MediaDbgAttr::attrStreamIn)) ||
2293 (!strcmp(attrName, MediaDbgAttr::attrStreamOut)) ||
2294 (!strcmp(attrName, MediaDbgAttr::attrMvData)) ||
2295 (!strcmp(attrName, MediaDbgAttr::attrSegId)) ||
2296 (!strcmp(attrName, MediaDbgAttr::attrCoefProb)) ||
2297 (!strcmp(attrName, MediaDbgAttr::attrGranularCRCDump)) ||
2298 m_configMgr->AttrIsEnabled(MediaDbgAttr::attrDumpBufferInBinary))
2299 {
2300 binaryDump = true;
2301 }
2302 const char *extType = binaryDump ? MediaDbgExtType::dat : MediaDbgExtType::txt;
2303
2304 if (mediaState == CODECHAL_NUM_MEDIA_STATES)
2305 {
2306 fileName = CreateFileName(bufferName, attrName, extType);
2307 }
2308 else
2309 {
2310 std::string kernelName = static_cast<CodecDebugConfigMgr *>(m_configMgr)->GetMediaStateStr(mediaState);
2311 fileName = CreateFileName(kernelName.c_str(), bufferName, extType);
2312 }
2313
2314 MOS_STATUS status = MOS_STATUS_SUCCESS;
2315
2316 if ((resource->pGmmResInfo != nullptr) &&
2317 (resource->pGmmResInfo->GetResFlags().Info.NotLockable))
2318 {
2319 uint8_t *data = nullptr;
2320 PMOS_RESOURCE pReadbackBuffer = (PMOS_RESOURCE)MOS_AllocAndZeroMemory(sizeof(MOS_RESOURCE));
2321 CODECHAL_DEBUG_CHK_NULL(pReadbackBuffer);
2322 status = AllocateLinearResource(MOS_GFXRES_BUFFER, (uint32_t)resource->pGmmResInfo->GetBaseWidth(), (uint32_t)resource->pGmmResInfo->GetBaseHeight(), Format_Any, pReadbackBuffer);
2323 if (MOS_FAILED(status))
2324 {
2325 MOS_FreeMemAndSetNull(pReadbackBuffer);
2326 }
2327 CODECHAL_DEBUG_CHK_STATUS(status);
2328
2329 status = VDBypassCopyResource(resource, pReadbackBuffer);
2330 if (MOS_FAILED(status))
2331 {
2332 m_osInterface->pfnFreeResource(m_osInterface, pReadbackBuffer);
2333 MOS_FreeMemAndSetNull(pReadbackBuffer);
2334 }
2335 CODECHAL_DEBUG_CHK_STATUS(status);
2336
2337 MOS_LOCK_PARAMS lockFlags;
2338 MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS));
2339 lockFlags.ReadOnly = 1;
2340 data = (uint8_t *)m_osInterface->pfnLockResource(m_osInterface, pReadbackBuffer, &lockFlags);
2341 if(data == nullptr)
2342 {
2343 m_osInterface->pfnFreeResource(m_osInterface, pReadbackBuffer);
2344 MOS_FreeMemAndSetNull(pReadbackBuffer);
2345 }
2346 CODECHAL_DEBUG_CHK_NULL(data);
2347
2348 data += offset;
2349
2350 if (binaryDump)
2351 {
2352 status = DumpBufferInBinary(data, size);
2353 }
2354 else
2355 {
2356 status = DumpBufferInHexDwords(data, size);
2357 }
2358
2359 m_osInterface->pfnUnlockResource(m_osInterface, pReadbackBuffer);
2360 m_osInterface->pfnFreeResource(m_osInterface, pReadbackBuffer);
2361 MOS_FreeMemAndSetNull(pReadbackBuffer);
2362 CODECHAL_DEBUG_CHK_STATUS(status);
2363 }
2364 else
2365 {
2366 MOS_LOCK_PARAMS lockFlags;
2367 MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS));
2368 lockFlags.ReadOnly = 1;
2369 uint8_t *data = (uint8_t *)m_osInterface->pfnLockResource(m_osInterface, resource, &lockFlags);
2370 MEDIA_DEBUG_CHK_NULL(data);
2371 data += offset;
2372
2373 if (binaryDump)
2374 {
2375 status = DumpBufferInBinary(data, size);
2376 }
2377 else
2378 {
2379 status = DumpBufferInHexDwords(data, size);
2380 }
2381
2382 if (data)
2383 {
2384 m_osInterface->pfnUnlockResource(m_osInterface, resource);
2385 }
2386 }
2387
2388 return status;
2389 };
2390
2391 m_dumpBuffer = [this](
2392 PMOS_RESOURCE resource,
2393 const char *attrName,
2394 const char *bufferName,
2395 uint32_t size,
2396 uint32_t offset,
2397 CODECHAL_MEDIA_STATE_TYPE mediaState) {
2398 MEDIA_DEBUG_FUNCTION_ENTER;
2399
2400 MEDIA_DEBUG_CHK_NULL(resource);
2401 MEDIA_DEBUG_CHK_NULL(bufferName);
2402
2403 if (size == 0)
2404 {
2405 return MOS_STATUS_SUCCESS;
2406 }
2407
2408 bool attrEnabled = false;
2409 if (mediaState == CODECHAL_NUM_MEDIA_STATES)
2410 {
2411 attrEnabled = m_configMgr->AttrIsEnabled(attrName);
2412 }
2413 else
2414 {
2415 attrEnabled = static_cast<CodecDebugConfigMgr *>(m_configMgr)->AttrIsEnabled(mediaState, attrName);
2416 }
2417 if (!attrEnabled)
2418 {
2419 return MOS_STATUS_SUCCESS;
2420 }
2421
2422 const char *fileName;
2423 bool binaryDump = false;
2424 if ((!strcmp(attrName, MediaDbgAttr::attrDecodeBitstream)) ||
2425 (!strcmp(attrName, MediaDbgAttr::attrStreamIn)) ||
2426 (!strcmp(attrName, MediaDbgAttr::attrStreamOut)) ||
2427 (!strcmp(attrName, MediaDbgAttr::attrMvData)) ||
2428 (!strcmp(attrName, MediaDbgAttr::attrSegId)) ||
2429 (!strcmp(attrName, MediaDbgAttr::attrCoefProb)) ||
2430 (!strcmp(attrName, MediaDbgAttr::attrGranularCRCDump)) ||
2431 m_configMgr->AttrIsEnabled(MediaDbgAttr::attrDumpBufferInBinary))
2432 {
2433 binaryDump = true;
2434 }
2435 const char *extType = binaryDump ? MediaDbgExtType::dat : MediaDbgExtType::txt;
2436
2437 if (mediaState == CODECHAL_NUM_MEDIA_STATES)
2438 {
2439 fileName = CreateFileName(bufferName, attrName, extType);
2440 }
2441 else
2442 {
2443 std::string kernelName = static_cast<CodecDebugConfigMgr *>(m_configMgr)->GetMediaStateStr(mediaState);
2444 fileName = CreateFileName(kernelName.c_str(), bufferName, extType);
2445 }
2446
2447 MediaDebugFastDump::Dump(*resource, fileName, size, offset);
2448
2449 if (!MediaDebugFastDump::IsGood())
2450 {
2451 return m_dumpBufferLegacy(
2452 resource,
2453 attrName,
2454 bufferName,
2455 size,
2456 offset,
2457 mediaState);
2458 }
2459
2460 return MOS_STATUS_SUCCESS;
2461 };
2462 }
2463
2464 CodechalDebugInterface::~CodechalDebugInterface()
2465 {
2466 if (nullptr != m_configMgr)
2467 {
2468 MOS_Delete(m_configMgr);
2469 }
2470
2471 MediaDebugFastDump::DestroyInstance();
2472 }
2473
2474 CodechalDebugInterface* CodechalDebugInterface::Create()
2475 {
2476 return MOS_New(CodechalDebugInterface);
2477 }
2478
2479 void CodechalDebugInterface::CheckGoldenReferenceExist()
2480 {
2481 std::ifstream crcGoldenRefStream(m_crcGoldenRefFileName);
2482 m_goldenReferenceExist = crcGoldenRefStream.good() ? true : false;
2483 }
2484
2485 MOS_STATUS CodechalDebugInterface::DumpRgbDataOnYUVSurface(
2486 PMOS_SURFACE surface,
2487 const char *attrName,
2488 const char *surfName,
2489 CODECHAL_MEDIA_STATE_TYPE mediaState,
2490 uint32_t width_in,
2491 uint32_t height_in)
2492 {
2493 bool hasAuxSurf = false;
2494 bool isPlanar = true;
2495 bool hasRefSurf = false;
2496 uint8_t *surfBaseAddr = nullptr;
2497 uint8_t *lockedAddr = nullptr;
2498
2499 if (!DumpIsEnabled(attrName, mediaState))
2500 {
2501 return MOS_STATUS_SUCCESS;
2502 }
2503
2504 //To write RGB data on AYUV surface for validation purpose due to similiar layout
2505 int32_t sfcOutputRgbFormatFlag = 0;
2506 int32_t bIsSfcOutputLinearFlag = 0;
2507 //tile type read from reg key
2508 {
2509 MediaUserSetting::Value outValue;
2510 ReadUserSettingForDebug(
2511 m_userSettingPtr,
2512 outValue,
2513 __MEDIA_USER_FEATURE_VALUE_DECODE_SFC_RGBFORMAT_OUTPUT_DEBUG,
2514 MediaUserSetting::Group::Sequence);
2515 sfcOutputRgbFormatFlag = outValue.Get<int32_t>();
2516 }
2517
2518 //rgb format output read from reg key
2519 {
2520 MediaUserSetting::Value outValue;
2521 ReadUserSettingForDebug(
2522 m_userSettingPtr,
2523 outValue,
2524 __MEDIA_USER_FEATURE_VALUE_DECODE_SFC_LINEAR_OUTPUT_DEBUG,
2525 MediaUserSetting::Group::Sequence);
2526 bIsSfcOutputLinearFlag = outValue.Get<int32_t>();
2527 }
2528
2529 if (!sfcOutputRgbFormatFlag)
2530 {
2531 return MOS_STATUS_SUCCESS;
2532 }
2533
2534 MOS_FORMAT outputFormat = surface->Format;
2535 const char *filePostfix = "unsupport";
2536
2537 switch (sfcOutputRgbFormatFlag)
2538 {
2539 case 1: //RGBP
2540 outputFormat = Format_RGBP;
2541 filePostfix = "rgbp";
2542 break;
2543 case 2: //BGRP
2544 outputFormat = Format_BGRP;
2545 filePostfix = "bgrp";
2546 break;
2547 case 3: //RGB24 only support Tile Linear
2548 if (bIsSfcOutputLinearFlag)
2549 {
2550 outputFormat = Format_R8G8B8;
2551 filePostfix = "rgb24";
2552 break;
2553 }
2554 default:
2555 CODECHAL_DEBUG_ASSERTMESSAGE("unsupport rgb format");
2556 return MOS_STATUS_SUCCESS;
2557 }
2558
2559 MOS_TILE_TYPE outputTileType = MOS_TILE_Y;
2560 if (bIsSfcOutputLinearFlag == 1)
2561 {
2562 outputTileType = MOS_TILE_LINEAR;
2563 }
2564
2565 MOS_LOCK_PARAMS lockFlags;
2566 GMM_RESOURCE_FLAG gmmFlags;
2567
2568 MOS_ZeroMemory(&gmmFlags, sizeof(gmmFlags));
2569 CODECHAL_DEBUG_CHK_NULL(surface);
2570 gmmFlags = surface->OsResource.pGmmResInfo->GetResFlags();
2571 hasAuxSurf = (gmmFlags.Gpu.MMC || gmmFlags.Info.MediaCompressed) && gmmFlags.Gpu.UnifiedAuxSurface;
2572
2573 if (!m_configMgr->AttrIsEnabled(CodechalDbgAttr::attrDecodeAuxSurface))
2574 {
2575 hasAuxSurf = false;
2576 }
2577
2578 if (strcmp(attrName, CodechalDbgAttr::attrDecodeReferenceSurfaces) == 0)
2579 {
2580 hasRefSurf = true;
2581 }
2582
2583 MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS));
2584 lockFlags.ReadOnly = 1;
2585 lockFlags.TiledAsTiled = 1; // Bypass GMM CPU blit due to some issues in GMM CpuBlt function
2586 if (hasAuxSurf)
2587 {
2588 // Dump MMC surface as raw layout
2589 lockFlags.NoDecompress = 1;
2590 }
2591
2592 lockedAddr = (uint8_t *)m_osInterface->pfnLockResource(m_osInterface, &surface->OsResource, &lockFlags);
2593
2594 if (lockedAddr == nullptr) // Failed to lock. Try to submit copy task and dump another surface
2595 {
2596 uint32_t sizeToBeCopied = 0;
2597 MOS_GFXRES_TYPE ResType;
2598
2599 #if LINUX
2600 // Linux does not have OsResource->ResType
2601 ResType = surface->Type;
2602 #else
2603 ResType = surface->OsResource.ResType;
2604 #endif
2605
2606 CODECHAL_DEBUG_CHK_STATUS(ReAllocateSurface(
2607 &m_temp2DSurfForCopy,
2608 surface,
2609 "Temp2DSurfForSurfDumper",
2610 ResType));
2611
2612 if (!hasRefSurf)
2613 {
2614 uint32_t arraySize = surface->OsResource.pGmmResInfo->GetArraySize();
2615
2616 if (arraySize == 0)
2617 {
2618 return MOS_STATUS_UNKNOWN;
2619 }
2620
2621 uint32_t sizeSrcSurface = (uint32_t)(surface->OsResource.pGmmResInfo->GetSizeMainSurface()) / arraySize;
2622 // Ensure allocated buffer size contains the source surface size
2623 if (m_temp2DSurfForCopy.OsResource.pGmmResInfo->GetSizeMainSurface() >= sizeSrcSurface)
2624 {
2625 sizeToBeCopied = sizeSrcSurface;
2626 }
2627
2628 if (sizeToBeCopied == 0)
2629 {
2630 // Currently, MOS's pfnAllocateResource does not support allocate a surface reference to another surface.
2631 // When the source surface is not created from Media, it is possible that we cannot allocate the same size as source.
2632 // For example, on Gen9, Render target might have GMM set CCS=1 MMC=0, but MOS cannot allocate surface with such combination.
2633 // When Gmm allocation parameter is different, the resulting surface size/padding/pitch will be differnt.
2634 // Once if MOS can support allocate a surface by reference another surface, we can do a bit to bit copy without problem.
2635 CODECHAL_DEBUG_ASSERTMESSAGE("Cannot allocate correct size, failed to copy nonlockable resource");
2636 return MOS_STATUS_NULL_POINTER;
2637 }
2638
2639 CODECHAL_DEBUG_VERBOSEMESSAGE("Temp2DSurfaceForCopy width %d, height %d, pitch %d, TileType %d, bIsCompressed %d, CompressionMode %d",
2640 m_temp2DSurfForCopy.dwWidth,
2641 m_temp2DSurfForCopy.dwHeight,
2642 m_temp2DSurfForCopy.dwPitch,
2643 m_temp2DSurfForCopy.TileType,
2644 m_temp2DSurfForCopy.bIsCompressed,
2645 m_temp2DSurfForCopy.CompressionMode);
2646
2647 uint32_t bpp = surface->OsResource.pGmmResInfo->GetBitsPerPixel();
2648
2649 CODECHAL_DEBUG_CHK_STATUS(m_osInterface->pfnMediaCopyResource2D(m_osInterface, &surface->OsResource, &m_temp2DSurfForCopy.OsResource, surface->dwPitch, sizeSrcSurface / (surface->dwPitch), bpp, false));
2650 }
2651 else
2652 {
2653 CODECHAL_DEBUG_CHK_STATUS(m_osInterface->pfnDoubleBufferCopyResource(m_osInterface, &surface->OsResource, &m_temp2DSurfForCopy.OsResource, false));
2654 }
2655
2656 lockedAddr = (uint8_t *)m_osInterface->pfnLockResource(m_osInterface, &m_temp2DSurfForCopy.OsResource, &lockFlags);
2657 CODECHAL_DEBUG_CHK_NULL(lockedAddr);
2658
2659 surface = &m_temp2DSurfForCopy;
2660 gmmFlags = surface->OsResource.pGmmResInfo->GetResFlags();
2661 }
2662
2663 if (hasAuxSurf)
2664 {
2665 uint32_t sizeMain = (uint32_t)(surface->OsResource.pGmmResInfo->GetSizeMainSurface());
2666 surfBaseAddr = (uint8_t *)MOS_AllocMemory(sizeMain);
2667 CODECHAL_DEBUG_CHK_NULL(surfBaseAddr);
2668
2669 Mos_SwizzleData(lockedAddr, surfBaseAddr, surface->TileType, MOS_TILE_LINEAR, sizeMain / surface->dwPitch, surface->dwPitch, true);
2670 }
2671 else
2672 {
2673 surfBaseAddr = lockedAddr;
2674 }
2675
2676 // Allocate RGB surface internally to get surface info
2677 MOS_SURFACE *tmpRgbSurface = MOS_New(MOS_SURFACE);
2678 CODECHAL_DEBUG_CHK_NULL(tmpRgbSurface);
2679 MOS_ALLOC_GFXRES_PARAMS allocParams;
2680 MOS_ZeroMemory(&allocParams, sizeof(MOS_ALLOC_GFXRES_PARAMS));
2681 allocParams.Type = MOS_GFXRES_2D;
2682 allocParams.TileType = outputTileType;
2683 allocParams.Format = outputFormat;
2684 allocParams.dwWidth = surface->dwWidth;
2685 allocParams.dwHeight = surface->dwHeight;
2686 allocParams.dwArraySize = 1;
2687 allocParams.pBufName = "dump rgb surface";
2688 allocParams.bIsCompressible = false;
2689 allocParams.ResUsageType = MOS_HW_RESOURCE_DEF_MAX;
2690 allocParams.m_tileModeByForce = MOS_TILE_UNSET_GMM;
2691
2692 CODECHAL_DEBUG_CHK_STATUS(m_osInterface->pfnAllocateResource(
2693 m_osInterface,
2694 &allocParams,
2695 &tmpRgbSurface->OsResource));
2696
2697 tmpRgbSurface->Format = Format_Invalid;
2698 CODECHAL_DEBUG_CHK_STATUS(m_osInterface->pfnGetResourceInfo(m_osInterface, &tmpRgbSurface->OsResource, tmpRgbSurface));
2699
2700 uint32_t rgbPitch = tmpRgbSurface->dwPitch;
2701 uint32_t alignedHeight = surface->dwHeight;
2702 uint32_t alignedWidth = surface->dwWidth;
2703
2704 if (outputFormat == Format_RGBP || outputFormat == Format_BGRP && rgbPitch)
2705 {
2706 alignedHeight = tmpRgbSurface->RenderOffset.YUV.U.BaseOffset / rgbPitch;
2707 alignedWidth = rgbPitch;
2708 }
2709
2710 // Always use MOS swizzle instead of GMM Cpu blit
2711 uint32_t sizeMain = (uint32_t)(surface->OsResource.pGmmResInfo->GetSizeMainSurface());
2712 surfBaseAddr = (uint8_t *)MOS_AllocMemory(sizeMain);
2713 CODECHAL_DEBUG_CHK_NULL(surfBaseAddr);
2714
2715 int32_t swizzleHeight = sizeMain / surface->dwPitch;
2716 int32_t swizzlePitch = surface->dwPitch;
2717 uint8_t *data = lockedAddr;
2718
2719 CODECHAL_DEBUG_VERBOSEMESSAGE("RGB Surface info: format %d, tiletype %d, pitch %d,UOffset %d, dwSize %d, sizemain %d",
2720 outputFormat,
2721 tmpRgbSurface->TileType,
2722 tmpRgbSurface->dwPitch,
2723 tmpRgbSurface->RenderOffset.YUV.U.BaseOffset,
2724 tmpRgbSurface->dwSize,
2725 sizeMain);
2726
2727 if (outputTileType == MOS_TILE_Y)
2728 {
2729 swizzlePitch = rgbPitch;
2730 Mos_SwizzleData(lockedAddr, surfBaseAddr, outputTileType, MOS_TILE_LINEAR, sizeMain / swizzlePitch, swizzlePitch, !MEDIA_IS_SKU(m_osInterface->pfnGetSkuTable(m_osInterface), FtrTileY) || gmmFlags.Info.Tile4);
2731 data = surfBaseAddr;
2732 }
2733
2734 data += surface->dwOffset + surface->YPlaneOffset.iYOffset * surface->dwPitch;
2735
2736 uint32_t width = (width_in ? width_in : surface->dwWidth) << 2;
2737 uint32_t height = height_in ? height_in : surface->dwHeight;
2738 uint32_t lumaheight = 0;
2739 uint32_t pitch = surface->dwPitch;
2740
2741 lumaheight = hasAuxSurf ? GFX_ALIGN(height, 32) : height;
2742
2743 const char *funcName = (m_codecFunction == CODECHAL_FUNCTION_DECODE) ? "_DEC" : (m_codecFunction == CODECHAL_FUNCTION_CENC_DECODE ? "_DEC" : "_ENC");
2744 std::string bufName = std::string(surfName) + "_w[" + std::to_string(alignedWidth) + "]_h[" + std::to_string(alignedHeight) + "]_p[" + std::to_string(rgbPitch) + "]";
2745
2746 const char *filePath = CreateFileName(funcName, bufName.c_str(), filePostfix);
2747
2748 std::ofstream ofs(filePath, std::ios_base::out | std::ios_base::binary);
2749 if (ofs.fail())
2750 {
2751 return MOS_STATUS_UNKNOWN;
2752 }
2753
2754 // RGB data has one zero byte in every 64 bytes, need to remove this byte
2755 if (IS_RGB24_FORMAT(outputFormat))
2756 {
2757 for (uint32_t h = 0; h < lumaheight; h++)
2758 {
2759 width = surface->dwWidth * 3;
2760 int dummyBytesPerLine = width / 63;
2761 int resPixel = width - 63 * dummyBytesPerLine;
2762 int resBytesPerLine = rgbPitch;
2763 for (int p = 0; p < dummyBytesPerLine; p++)
2764 {
2765 ofs.write((char *)data, 63);
2766 data += 64;
2767 resBytesPerLine -= 64;
2768 }
2769
2770 if (resPixel > 0)
2771 {
2772 ofs.write((char *)data, resPixel);
2773 data += resPixel;
2774 resBytesPerLine -= resPixel;
2775 }
2776
2777 if (resBytesPerLine)
2778 {
2779 data += resBytesPerLine;
2780 }
2781 }
2782 }
2783 else
2784 {
2785 for (uint32_t h = 0; h < lumaheight; h++)
2786 {
2787 ofs.write((char *)data, hasAuxSurf ? pitch : width);
2788 data += pitch;
2789 }
2790 }
2791
2792 if (surfBaseAddr)
2793 {
2794 MOS_FreeMemory(surfBaseAddr);
2795 }
2796 if (lockedAddr)
2797 {
2798 m_osInterface->pfnUnlockResource(m_osInterface, &surface->OsResource);
2799 }
2800
2801 m_osInterface->pfnFreeResource(m_osInterface, &(tmpRgbSurface->OsResource));
2802 MOS_Delete(tmpRgbSurface);
2803
2804 return MOS_STATUS_SUCCESS;
2805 }
2806
2807 MOS_STATUS CodechalDebugInterface::DumpBltOutput(
2808 PMOS_SURFACE surface,
2809 const char *attrName)
2810 {
2811 if (!DumpIsEnabled(attrName))
2812 {
2813 return MOS_STATUS_SUCCESS;
2814 }
2815 else
2816 {
2817 CODECHAL_DEBUG_NORMALMESSAGE("Don't support BltOutput dump, pls not use BltState directly!");
2818 return MOS_STATUS_SUCCESS;
2819 }
2820
2821 }
2822
2823 MOS_STATUS CodechalDebugInterface::InitializeUserSetting()
2824 {
2825 CODECHAL_DEBUG_FUNCTION_ENTER;
2826 CODECHAL_DEBUG_CHK_STATUS(MediaDebugInterface::InitializeUserSetting());
2827
2828 DeclareUserSettingKeyForDebug(
2829 m_userSettingPtr,
2830 __MEDIA_USER_FEATURE_ENABLE_HW_DEBUG_HOOKS_DEBUG,
2831 MediaUserSetting::Group::Device,
2832 int32_t(0),
2833 false);
2834
2835 DeclareUserSettingKeyForDebug(
2836 m_userSettingPtr,
2837 __MEDIA_USER_FEATURE_VALUE_CODECHAL_FRAME_NUMBER_TO_STOP_DEBUG,
2838 MediaUserSetting::Group::Device,
2839 int32_t(-1),
2840 false);
2841
2842 DeclareUserSettingKeyForDebug(
2843 m_userSettingPtr,
2844 __MEDIA_USER_FEATURE_VALUE_CODECHAL_ENABLE_SW_CRC_DEBUG,
2845 MediaUserSetting::Group::Device,
2846 uint32_t(0),
2847 false);
2848
2849 return MOS_STATUS_SUCCESS;
2850 }
2851
2852 MOS_STATUS CodechalDebugInterface::Initialize(
2853 CodechalHwInterfaceNext *hwInterface,
2854 CODECHAL_FUNCTION codecFunction,
2855 MediaCopyWrapper *mediaCopyWrapper)
2856 {
2857 CODECHAL_DEBUG_FUNCTION_ENTER;
2858
2859 CODECHAL_DEBUG_CHK_NULL(hwInterface);
2860 m_hwInterfaceNext = hwInterface;
2861 m_codecFunction = codecFunction;
2862 m_osInterface = m_hwInterfaceNext->GetOsInterface();
2863 m_cpInterface = m_hwInterfaceNext->GetCpInterface();
2864
2865 CODECHAL_DEBUG_CHK_NULL(m_osInterface);
2866 m_userSettingPtr = m_osInterface->pfnGetUserSettingInstance(m_osInterface);
2867 CODECHAL_DEBUG_CHK_STATUS(InitializeUserSetting());
2868
2869 //dump loctaion is codechaldump
2870 MediaDebugInterface::SetOutputFilePath();
2871
2872 m_configMgr = MOS_New(CodecDebugConfigMgr, this, m_codecFunction, m_outputFilePath);
2873 CODECHAL_DEBUG_CHK_NULL(m_configMgr);
2874 CODECHAL_DEBUG_CHK_STATUS(m_configMgr->ParseConfig(m_osInterface->pOsContext));
2875
2876 MediaDebugInterface::InitDumpLocation();
2877
2878 m_osInterface->pfnGetPlatform(m_osInterface, &m_platform);
2879
2880 #if (_DEBUG || _RELEASE_INTERNAL)
2881 {
2882 MediaUserSetting::Value outValue;
2883 ReadUserSettingForDebug(
2884 m_userSettingPtr,
2885 outValue,
2886 __MEDIA_USER_FEATURE_ENABLE_HW_DEBUG_HOOKS_DEBUG,
2887 MediaUserSetting::Group::Device,
2888 0,
2889 true);
2890 m_enableHwDebugHooks = outValue.Get<bool>();
2891 }
2892 CheckGoldenReferenceExist();
2893 if (m_enableHwDebugHooks && m_goldenReferenceExist)
2894 {
2895 LoadGoldenReference();
2896 }
2897
2898 {
2899 MediaUserSetting::Value outValue;
2900 ReadUserSettingForDebug(
2901 m_userSettingPtr,
2902 outValue,
2903 __MEDIA_USER_FEATURE_VALUE_CODECHAL_FRAME_NUMBER_TO_STOP_DEBUG,
2904 MediaUserSetting::Group::Device,
2905 -1,
2906 true);
2907 m_stopFrameNumber = outValue.Get<int32_t>();
2908 }
2909
2910 {
2911 MediaUserSetting::Value outValue;
2912 ReadUserSettingForDebug(
2913 m_userSettingPtr,
2914 outValue,
2915 __MEDIA_USER_FEATURE_VALUE_CODECHAL_ENABLE_SW_CRC_DEBUG,
2916 MediaUserSetting::Group::Device,
2917 0,
2918 true);
2919 m_swCRC = outValue.Get<bool>();
2920 }
2921 #endif
2922
2923 SetFastDumpConfig(mediaCopyWrapper);
2924
2925 return MOS_STATUS_SUCCESS;
2926 }
2927
2928 MOS_STATUS CodechalDebugInterface::DumpHucDmem(
2929 PMOS_RESOURCE dmemResource,
2930 uint32_t dmemSize,
2931 uint32_t hucPassNum,
2932 CodechalHucRegionDumpType dumpType)
2933 {
2934 CODECHAL_DEBUG_FUNCTION_ENTER;
2935
2936 if (!m_configMgr->AttrIsEnabled(MediaDbgAttr::attrHuCDmem) && !MosUtilities::GetTraceSetting())
2937 {
2938 return MOS_STATUS_SUCCESS;
2939 }
2940
2941 CODECHAL_DEBUG_CHK_NULL(dmemResource);
2942 if (Mos_ResourceIsNull(dmemResource))
2943 {
2944 return MOS_STATUS_NULL_POINTER;
2945 }
2946
2947 std::string funcName = "";
2948 if (m_codecFunction == CODECHAL_FUNCTION_DECODE)
2949 {
2950 funcName = "DEC_";
2951 }
2952 else if (m_codecFunction == CODECHAL_FUNCTION_CENC_DECODE)
2953 {
2954 funcName = "DEC_Cenc_";
2955 }
2956 else
2957 {
2958 funcName = "ENC_";
2959 }
2960
2961 std::string dmemName = MediaDbgBufferType::bufHucDmem;
2962 std::string passName = std::to_string(hucPassNum);
2963 switch (dumpType)
2964 {
2965 case hucRegionDumpInit:
2966 funcName = funcName + dmemName + "_InitPass" + passName;
2967 break;
2968 case hucRegionDumpUpdate:
2969 funcName = funcName + dmemName + "_UpdatePass" + passName;
2970 break;
2971 case hucRegionDumpLAUpdate:
2972 funcName = funcName + dmemName + "_LookaheadUpdatePass" + passName;
2973 break;
2974 case hucRegionDumpRegionLocked:
2975 funcName = funcName + dmemName + "_RegionLocked" + passName;
2976 break;
2977 case hucRegionDumpCmdInitializer:
2978 funcName = funcName + dmemName + "_CmdInitializerPass" + passName;
2979 break;
2980 case hucRegionDumpPakIntegrate:
2981 funcName = funcName + dmemName + "_PakIntPass" + passName;
2982 break;
2983 case hucRegionDumpHpu:
2984 funcName = funcName + dmemName + "_HpuPass" + passName;
2985 break;
2986 case hucRegionDumpHpuSuperFrame:
2987 funcName = funcName + dmemName + "_HpuPass" + passName + "_SuperFramePass";
2988 break;
2989 case hucRegionDumpBackAnnotation:
2990 funcName = funcName + dmemName + "_BackAnnotationPass" + passName;
2991 break;
2992 default:
2993 funcName = funcName + dmemName + "_Pass" + passName;
2994 break;
2995 }
2996
2997 return DumpBuffer(dmemResource, MediaDbgAttr::attrHuCDmem, funcName.c_str(), dmemSize);
2998 }
2999
3000 std::string CodechalDebugInterface::SetOutputPathKey()
3001 {
3002 return __MEDIA_USER_FEATURE_VALUE_CODECHAL_DEBUG_OUTPUT_DIRECTORY;
3003 }
3004
3005 std::string CodechalDebugInterface::InitDefaultOutput()
3006 {
3007 m_outputFilePath.append(MEDIA_DEBUG_CODECHAL_DUMP_OUTPUT_FOLDER);
3008 return SetOutputPathKey();
3009 }
3010
3011 MOS_STATUS CodechalDebugInterface::VDBypassCopyResource(PMOS_RESOURCE src, PMOS_RESOURCE dst)
3012 {
3013 CODECHAL_DEBUG_FUNCTION_ENTER;
3014
3015 CODECHAL_DEBUG_CHK_NULL(m_osInterface);
3016 CODECHAL_DEBUG_CHK_NULL(m_hwInterfaceNext)
3017 CODECHAL_DEBUG_CHK_NULL(src);
3018 CODECHAL_DEBUG_CHK_NULL(dst);
3019
3020 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
3021 MOS_GPUCTX_CREATOPTIONS_ENHANCED createOption;
3022 MOS_COMMAND_BUFFER cmdBuffer;
3023 std::shared_ptr<mhw::mi::Itf> miInterface = m_hwInterfaceNext->GetMiInterfaceNext();
3024 PMHW_MI_MMIOREGISTERS pMmioRegisters = miInterface->GetMmioRegisters();
3025 MOS_CONTEXT *pOsContext = m_osInterface->pOsContext;
3026 MHW_ADD_CP_COPY_PARAMS cpCopyParams;
3027 MHW_MI_FLUSH_DW_PARAMS FlushDwParams;
3028 MhwCpInterface *mhwCpInterface = m_hwInterfaceNext->GetCpInterface();
3029
3030 CODECHAL_DEBUG_CHK_NULL(pMmioRegisters);
3031 CODECHAL_DEBUG_CHK_NULL(pOsContext);
3032 CODECHAL_DEBUG_CHK_NULL(mhwCpInterface);
3033
3034 CODECHAL_DEBUG_CHK_STATUS(m_osInterface->pfnGetCommandBuffer(m_osInterface, &cmdBuffer, 0));
3035
3036 CODECHAL_DEBUG_CHK_STATUS(miInterface->AddProtectedProlog(&cmdBuffer));
3037
3038 MOS_ZeroMemory(&cpCopyParams, sizeof(cpCopyParams));
3039 uint32_t dwWidth = (uint32_t)src->pGmmResInfo->GetBaseWidth();
3040 uint32_t dwHeight = (uint32_t)src->pGmmResInfo->GetBaseHeight();
3041 cpCopyParams.size = dwWidth * dwHeight;
3042 cpCopyParams.presSrc = src;
3043 cpCopyParams.presDst = dst;
3044 cpCopyParams.offset = 0;
3045 cpCopyParams.bypass = true;
3046
3047 eStatus = mhwCpInterface->AddCpCopy(m_osInterface, &cmdBuffer, &cpCopyParams);
3048
3049 auto &flushDwParams = miInterface->MHW_GETPAR_F(MI_FLUSH_DW)();
3050 flushDwParams = {};
3051 CODECHAL_DEBUG_CHK_STATUS(miInterface->MHW_ADDCMD_F(MI_FLUSH_DW)(&cmdBuffer));
3052 PMOS_RESOURCE pStoreResource = (PMOS_RESOURCE)MOS_AllocAndZeroMemory(sizeof(MOS_RESOURCE));
3053 CODECHAL_DEBUG_CHK_NULL(pStoreResource);
3054 // Create store resource
3055 {
3056 //Insert MFX_WAIT command.
3057 auto &mfxWaitParams = miInterface->MHW_GETPAR_F(MFX_WAIT)();
3058 mfxWaitParams = {};
3059 mfxWaitParams.iStallVdboxPipeline = true;
3060 CODECHAL_DEBUG_CHK_STATUS(miInterface->MHW_ADDCMD_F(MFX_WAIT)(&cmdBuffer, nullptr));
3061
3062 eStatus = AllocateLinearResource(MOS_GFXRES_BUFFER, sizeof(uint32_t), 1, Format_Buffer, pStoreResource, true);
3063 if (MOS_FAILED(eStatus))
3064 {
3065 MOS_FreeMemAndSetNull(pStoreResource);
3066 }
3067 CODECHAL_DEBUG_CHK_STATUS(eStatus);
3068
3069 eStatus = FillResourceMemory(*pStoreResource, sizeof(uint32_t), QUERY_STATUS_BUFFER_INITIAL_VALUE);
3070 if (MOS_FAILED(eStatus))
3071 {
3072 CODECHAL_DEBUG_ASSERTMESSAGE("Error: Failed FillResourceMemory to pStoreResource.");
3073 m_osInterface->pfnFreeResource(m_osInterface, pStoreResource);
3074 MOS_FreeMemAndSetNull(pStoreResource);
3075 }
3076 CODECHAL_DEBUG_CHK_STATUS(eStatus);
3077
3078 auto &flushDwParams = miInterface->MHW_GETPAR_F(MI_FLUSH_DW)();
3079 flushDwParams = {};
3080 flushDwParams.postSyncOperation = MHW_FLUSH_WRITE_IMMEDIATE_DATA;
3081 flushDwParams.pOsResource = pStoreResource;
3082 flushDwParams.dwResourceOffset = 0;
3083 flushDwParams.dwDataDW1 = STORE_DATA_DWORD_DATA;
3084 eStatus = miInterface->MHW_ADDCMD_F(MI_FLUSH_DW)(&cmdBuffer);
3085 if (MOS_FAILED(eStatus))
3086 {
3087 CODECHAL_DEBUG_ASSERTMESSAGE("Error: Failed MHW_ADDCMD_F(MI_FLUSH_DW).");
3088 m_osInterface->pfnFreeResource(m_osInterface, pStoreResource);
3089 MOS_FreeMemAndSetNull(pStoreResource);
3090 }
3091 }
3092
3093 do
3094 {
3095 auto &batchBufferEndParams = miInterface->MHW_GETPAR_F(MI_BATCH_BUFFER_END)();
3096 batchBufferEndParams = {};
3097 eStatus = miInterface->MHW_ADDCMD_F(MI_BATCH_BUFFER_END)(&cmdBuffer);
3098 if (MOS_FAILED(eStatus))
3099 {
3100 CODECHAL_DEBUG_ASSERTMESSAGE("Error: Failed MHW_ADDCMD_F(MI_BATCH_BUFFER_END).");
3101 break;
3102 }
3103 m_osInterface->pfnReturnCommandBuffer(m_osInterface, &cmdBuffer, 0);
3104 eStatus = m_osInterface->pfnSubmitCommandBuffer(m_osInterface, &cmdBuffer, false);
3105 if (MOS_FAILED(eStatus))
3106 {
3107 CODECHAL_DEBUG_ASSERTMESSAGE("Error: Failed MHW_ADDCMD_F(MI_BATCH_BUFFER_END).");
3108 break;
3109 }
3110
3111 volatile uint32_t dwValueInMemory = 0;
3112 MOS_LOCK_PARAMS sMosLockParams{};
3113 sMosLockParams.ReadOnly = 1;
3114 uint8_t *pStoreResBytes = reinterpret_cast<uint8_t*>(m_osInterface->pfnLockResource(m_osInterface, pStoreResource, &sMosLockParams));
3115 if (pStoreResBytes == nullptr)
3116 {
3117 CODECHAL_DEBUG_ASSERTMESSAGE("Error: Failed locking pStoreResource.");
3118 eStatus = MOS_STATUS_UNINITIALIZED;
3119 break;
3120 }
3121
3122 dwValueInMemory = *(reinterpret_cast<uint32_t *>(pStoreResBytes));
3123 if (dwValueInMemory != STORE_DATA_DWORD_DATA)
3124 {
3125 CODECHAL_DEBUG_ASSERTMESSAGE("Error: Failed to read Store Data output.");
3126 m_osInterface->pfnUnlockResource(m_osInterface, pStoreResource);
3127 eStatus = MOS_STATUS_SUCCESS;
3128 break;
3129 }
3130 m_osInterface->pfnUnlockResource(m_osInterface, pStoreResource);
3131
3132 } while (false);
3133 m_osInterface->pfnFreeResource(m_osInterface, pStoreResource);
3134 MOS_FreeMemAndSetNull(pStoreResource);
3135
3136 return eStatus;
3137 }
3138
3139 MOS_STATUS CodechalDebugInterface::AllocateLinearResource(MOS_GFXRES_TYPE eType, uint32_t dwWidth, uint32_t dwHeight, MOS_FORMAT eFormat, PMOS_RESOURCE pResource, bool bSystemMem, bool bLockable) const
3140 {
3141 MOS_ALLOC_GFXRES_PARAMS sMosAllocParams;
3142 MOS_STATUS eStatus;
3143
3144 CODECHAL_DEBUG_FUNCTION_ENTER;
3145
3146 CODECHAL_DEBUG_CHK_NULL(m_osInterface);
3147 CODECHAL_DEBUG_CHK_NULL(m_osInterface->pfnAllocateResource);
3148
3149 do
3150 {
3151 if (eType != MOS_GFXRES_BUFFER &&
3152 eType != MOS_GFXRES_2D)
3153 {
3154 CODECHAL_DEBUG_ASSERTMESSAGE("Error: Only 'BUFFER' and '2D' types are supported in CP.");
3155 eStatus = MOS_STATUS_INVALID_PARAMETER;
3156 break;
3157 }
3158
3159 if (eType == MOS_GFXRES_BUFFER &&
3160 dwHeight != 1)
3161 {
3162 CODECHAL_DEBUG_ASSERTMESSAGE("Error: Resources of type 'BUFFER' must have height = 1.");
3163 eStatus = MOS_STATUS_INVALID_PARAMETER;
3164 break;
3165 }
3166
3167 if (pResource == nullptr)
3168 {
3169 CODECHAL_DEBUG_ASSERTMESSAGE("Error: Failed to allocate memory for MOS_RESOURCE.");
3170 eStatus = MOS_STATUS_NO_SPACE;
3171 break;
3172 }
3173 MOS_ZeroMemory(pResource, sizeof(*pResource));
3174
3175 MOS_ZeroMemory(&sMosAllocParams, sizeof(sMosAllocParams));
3176 sMosAllocParams.Type = eType;
3177 sMosAllocParams.dwWidth = dwWidth;
3178 sMosAllocParams.dwHeight = dwHeight;
3179 sMosAllocParams.TileType = MOS_TILE_LINEAR;
3180 sMosAllocParams.Format = eFormat;
3181
3182 if (MEDIA_IS_SKU(m_osInterface->pfnGetSkuTable(m_osInterface), FtrLimitedLMemBar))
3183 {
3184 if (bSystemMem)
3185 {
3186 sMosAllocParams.dwMemType = MOS_MEMPOOL_SYSTEMMEMORY;
3187 }
3188 else if (!bLockable)
3189 {
3190 sMosAllocParams.Flags.bNotLockable = 1;
3191 sMosAllocParams.dwMemType = MOS_MEMPOOL_DEVICEMEMORY;
3192 }
3193 else if (bLockable)
3194 {
3195 sMosAllocParams.Flags.bNotLockable = 0;
3196 sMosAllocParams.dwMemType = MOS_MEMPOOL_VIDEOMEMORY;
3197 }
3198 }
3199
3200 if (MEDIA_IS_SKU(m_osInterface->pfnGetSkuTable(m_osInterface), FtrSAMediaCachePolicy))
3201 {
3202 sMosAllocParams.ResUsageType = MOS_HW_RESOURCE_USAGE_CP_INTERNAL_WRITE;
3203 }
3204
3205 eStatus = m_osInterface->pfnAllocateResource(
3206 m_osInterface,
3207 &sMosAllocParams,
3208 pResource);
3209 if (MOS_FAILED(eStatus))
3210 {
3211 CODECHAL_DEBUG_ASSERTMESSAGE("Failed to allocate resource. Error = 0x%x.", eStatus);
3212 eStatus = MOS_STATUS_UNKNOWN;
3213 }
3214 } while (false);
3215
3216 return eStatus;
3217 }
3218
3219 MOS_STATUS CodechalDebugInterface::FillResourceMemory(MOS_RESOURCE &sResource, uint32_t uiSize, uint8_t ucValue)
3220 {
3221 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
3222 void *pSurface = nullptr;
3223
3224 CODECHAL_DEBUG_FUNCTION_ENTER;
3225
3226 if (uiSize == 0)
3227 {
3228 // Nothing to do.
3229 CODECHAL_DEBUG_ASSERTMESSAGE("Received uiSize = 0. This should never happen!");
3230 return MOS_STATUS_INVALID_PARAMETER;
3231 }
3232
3233 do
3234 {
3235 MOS_LOCK_PARAMS sMosLockParams{};
3236 sMosLockParams.WriteOnly = true;
3237
3238 // Lock the surface for writing.
3239 pSurface = m_osInterface->pfnLockResource(m_osInterface, &sResource, &sMosLockParams);
3240
3241 if (pSurface == nullptr)
3242 {
3243 CODECHAL_DEBUG_ASSERTMESSAGE("Error: Failed locking the resource.");
3244 eStatus = MOS_STATUS_UNKNOWN;
3245 break;
3246 }
3247
3248 // Fill the surface with the wanted value.
3249 MOS_FillMemory(pSurface, uiSize, ucValue);
3250
3251 } while (false);
3252
3253 // Unlock the resource if needed.
3254 m_osInterface->pfnUnlockResource(m_osInterface, &sResource);
3255
3256 return eStatus;
3257 }
3258
3259 MOS_STATUS CodechalDebugInterface::DumpHucRegion(
3260 PMOS_RESOURCE region,
3261 uint32_t regionOffset,
3262 uint32_t regionSize,
3263 uint32_t regionNum,
3264 const char * regionName,
3265 bool inputBuffer,
3266 uint32_t hucPassNum,
3267 CodechalHucRegionDumpType dumpType)
3268 {
3269 CODECHAL_DEBUG_FUNCTION_ENTER;
3270
3271 if (!m_configMgr->AttrIsEnabled(MediaDbgAttr::attrHucRegions) && !MosUtilities::GetTraceSetting())
3272 {
3273 return MOS_STATUS_SUCCESS;
3274 }
3275 CODECHAL_DEBUG_ASSERT(regionNum < 16);
3276 CODECHAL_DEBUG_CHK_NULL(region);
3277
3278 if (Mos_ResourceIsNull(region))
3279 {
3280 return MOS_STATUS_NULL_POINTER;
3281 }
3282
3283 std::string funcName = "";
3284 if (m_codecFunction == CODECHAL_FUNCTION_DECODE)
3285 {
3286 funcName = "DEC_";
3287 }
3288 else if (m_codecFunction == CODECHAL_FUNCTION_CENC_DECODE)
3289 {
3290 funcName = "DEC_CENC_";
3291 }
3292 else
3293 {
3294 funcName = "ENC_";
3295 }
3296
3297 std::string bufName = MediaDbgBufferType::bufHucRegion;
3298 std::string inputName = (inputBuffer) ? "Input_" : "Output_";
3299 std::string regionNumName = std::to_string(regionNum);
3300 std::string passName = std::to_string(hucPassNum);
3301 switch (dumpType)
3302 {
3303 case hucRegionDumpInit:
3304 funcName = funcName + inputName + bufName + regionNumName + regionName + "_InitPass" + passName;
3305 break;
3306 case hucRegionDumpUpdate:
3307 funcName = funcName + inputName + bufName + regionNumName + regionName + "_UpdatePass" + passName;
3308 break;
3309 case hucRegionDumpLAUpdate:
3310 funcName = funcName + inputName + bufName + regionNumName + regionName + "_LookaheadUpdatePass" + passName;
3311 break;
3312 case hucRegionDumpRegionLocked:
3313 funcName = funcName + inputName + bufName + regionNumName + regionName + "_RegionLockedPass" + passName;
3314 break;
3315 case hucRegionDumpCmdInitializer:
3316 funcName = funcName + inputName + bufName + regionNumName + regionName + "_CmdInitializerPass" + passName;
3317 break;
3318 case hucRegionDumpPakIntegrate:
3319 funcName = funcName + inputName + bufName + regionNumName + regionName + "_PakIntPass" + passName;
3320 break;
3321 case hucRegionDumpHpu:
3322 funcName = funcName + inputName + bufName + regionNumName + regionName + "_HpuPass" + passName;
3323 break;
3324 case hucRegionDumpBackAnnotation:
3325 funcName = funcName + inputName + bufName + regionNumName + regionName + "_BackAnnotationPass" + passName;
3326 break;
3327 default:
3328 funcName = funcName + inputName + bufName + regionNumName + regionName + "_Pass" + passName;
3329 break;
3330 }
3331
3332 return DumpBuffer(region, MediaDbgAttr::attrHucRegions, funcName.c_str(), regionSize, regionOffset);
3333 }
3334
3335 #define FIELD_TO_OFS(field_name) ofs << print_shift << std::setfill(' ') << std::setw(25) << std::left << std::string(#field_name) + ": " << (int64_t)report->field_name << std::endl;
3336 #define PTR_TO_OFS(ptr_name) ofs << print_shift << std::setfill(' ') << std::setw(25) << std::left << std::string(#ptr_name) + ": " << report->ptr_name << std::endl;
3337 MOS_STATUS CodechalDebugInterface::DumpEncodeStatusReport(const encode::EncodeStatusReportData *report)
3338 {
3339 CODECHAL_DEBUG_FUNCTION_ENTER;
3340
3341 CODECHAL_DEBUG_CHK_NULL(report);
3342
3343 const char *bufferName = "EncodeStatusReport_Parsed";
3344 const char *attrName = MediaDbgAttr::attrStatusReport;
3345 if (!m_configMgr->AttrIsEnabled(attrName))
3346 {
3347 return MOS_STATUS_SUCCESS;
3348 }
3349
3350 const char * filePath = CreateFileName(bufferName, attrName, MediaDbgExtType::txt);
3351 std::ofstream ofs(filePath);
3352
3353 if (ofs.fail())
3354 {
3355 return MOS_STATUS_UNKNOWN;
3356 }
3357 std::string print_shift = "";
3358 sizeof(report->codecStatus);
3359 FIELD_TO_OFS(codecStatus);
3360 FIELD_TO_OFS(statusReportNumber);
3361 FIELD_TO_OFS(currOriginalPic.FrameIdx);
3362 FIELD_TO_OFS(currOriginalPic.PicFlags);
3363 FIELD_TO_OFS(currOriginalPic.PicEntry);
3364 FIELD_TO_OFS(func);
3365 PTR_TO_OFS( currRefList);
3366 ofs << std::endl;
3367
3368 FIELD_TO_OFS(sequential);
3369 FIELD_TO_OFS(bitstreamSize);
3370 FIELD_TO_OFS(qpY);
3371 FIELD_TO_OFS(suggestedQPYDelta);
3372 FIELD_TO_OFS(numberPasses);
3373 FIELD_TO_OFS(averageQP);
3374 FIELD_TO_OFS(hwCounterValue.IV);
3375 FIELD_TO_OFS(hwCounterValue.Count);
3376 PTR_TO_OFS(hwCtr);
3377 FIELD_TO_OFS(queryStatusFlags);
3378
3379 print_shift = " ";
3380 FIELD_TO_OFS(panicMode);
3381 FIELD_TO_OFS(sliceSizeOverflow);
3382 FIELD_TO_OFS(numSlicesNonCompliant);
3383 FIELD_TO_OFS(longTermReference);
3384 FIELD_TO_OFS(frameSkipped);
3385 FIELD_TO_OFS(sceneChangeDetected);
3386 print_shift = "";
3387 ofs << std::endl;
3388
3389 FIELD_TO_OFS(mad);
3390 FIELD_TO_OFS(loopFilterLevel);
3391 FIELD_TO_OFS(longTermIndication);
3392 FIELD_TO_OFS(nextFrameWidthMinus1);
3393 FIELD_TO_OFS(nextFrameHeightMinus1);
3394 FIELD_TO_OFS(numberSlices);
3395
3396 FIELD_TO_OFS(psnrX100[0]);
3397 FIELD_TO_OFS(psnrX100[1]);
3398 FIELD_TO_OFS(psnrX100[2]);
3399
3400 FIELD_TO_OFS(numberTilesInFrame);
3401 FIELD_TO_OFS(usedVdBoxNumber);
3402 FIELD_TO_OFS(sizeOfSliceSizesBuffer);
3403 PTR_TO_OFS( sliceSizes);
3404 FIELD_TO_OFS(sizeOfTileInfoBuffer);
3405 PTR_TO_OFS( hevcTileinfo);
3406 FIELD_TO_OFS(numTileReported);
3407 ofs << std::endl;
3408
3409 FIELD_TO_OFS(streamId);
3410 PTR_TO_OFS( pLookaheadStatus);
3411 ofs.close();
3412
3413 return MOS_STATUS_SUCCESS;
3414 }
3415
3416 #undef FIELD_TO_OFS
3417 #undef PTR_TO_OFS
3418
3419 bool CodechalDebugInterface::DumpIsEnabled(
3420 const char * attr,
3421 CODECHAL_MEDIA_STATE_TYPE mediaState)
3422 {
3423 if (nullptr == m_configMgr)
3424 {
3425 return false;
3426 }
3427
3428 if (mediaState != CODECHAL_NUM_MEDIA_STATES)
3429 {
3430 return static_cast<CodecDebugConfigMgr*>(m_configMgr)->AttrIsEnabled(mediaState, attr);
3431 }
3432 else
3433 {
3434 return m_configMgr->AttrIsEnabled(attr);
3435 }
3436 }
3437
3438 MOS_STATUS CodechalDebugInterface::SetFastDumpConfig(MediaCopyWrapper *mediaCopyWrapper)
3439 {
3440 auto traceSetting = MosUtilities::GetTraceSetting();
3441 if (!mediaCopyWrapper || !(DumpIsEnabled(MediaDbgAttr::attrEnableFastDump) || traceSetting))
3442 {
3443 return MOS_STATUS_SUCCESS;
3444 }
3445
3446 MediaDebugFastDump::Config cfg{};
3447 if (traceSetting)
3448 {
3449 const auto &c = traceSetting->fastDump;
3450 cfg.allowDataLoss = c.allowDataLoss;
3451 cfg.frameIdx = c.frameIdxBasedSampling ? &m_bufferDumpFrameNum : nullptr;
3452 cfg.samplingTime = static_cast<size_t>(c.samplingTime);
3453 cfg.samplingInterval = static_cast<size_t>(c.samplingInterval);
3454 cfg.memUsagePolicy = c.memUsagePolicy;
3455 cfg.maxPrioritizedMem = c.maxPrioritizedMem;
3456 cfg.maxDeprioritizedMem = c.maxDeprioritizedMem;
3457 cfg.weightRenderCopy = c.weightRenderCopy;
3458 cfg.weightVECopy = c.weightVECopy;
3459 cfg.weightBLTCopy = c.weightBLTCopy;
3460 cfg.writeMode = c.writeMode;
3461 cfg.bufferSize = static_cast<size_t>(c.bufferSize);
3462 cfg.informOnError = c.informOnError;
3463
3464 auto suffix = cfg.writeMode == 0 ? ".bin" : cfg.writeMode == 1 ? ".txt"
3465 : "";
3466
3467 class DumpEnabled
3468 {
3469 public:
3470 bool operator()(const char *attrName)
3471 {
3472 decltype(m_filter)::const_iterator it;
3473 return (it = m_filter.find(attrName)) != m_filter.end() &&
3474 MOS_TraceKeyEnabled(it->second);
3475 }
3476
3477 private:
3478 const std::map<std::string, MEDIA_EVENT_FILTER_KEYID> m_filter = {
3479 {MediaDbgAttr::attrDecodeOutputSurface, TR_KEY_DECODE_DSTYUV},
3480 {MediaDbgAttr::attrDecodeReferenceSurfaces, TR_KEY_DECODE_REFYUV},
3481 {MediaDbgAttr::attrDecodeBitstream, TR_KEY_DECODE_BITSTREAM},
3482 {MediaDbgAttr::attrEncodeRawInputSurface, TR_KEY_ENCODE_DATA_INPUT_SURFACE},
3483 {MediaDbgAttr::attrReferenceSurfaces, TR_KEY_ENCODE_DATA_REF_SURFACE},
3484 {MediaDbgAttr::attrReconstructedSurface, TR_KEY_ENCODE_DATA_RECON_SURFACE},
3485 {MediaDbgAttr::attrBitstream, TR_KEY_ENCODE_DATA_BITSTREAM},
3486 {MediaDbgAttr::attrHuCDmem, TR_KEY_ENCODE_DATA_HUC_DMEM},
3487 {MediaDbgAttr::attrHucRegions, TR_KEY_ENCODE_DATA_HUC_REGION},
3488 };
3489 };
3490
3491 auto dumpEnabled = std::make_shared<DumpEnabled>();
3492
3493 m_dumpYUVSurface = [this, dumpEnabled, traceSetting, suffix](
3494 PMOS_SURFACE surface,
3495 const char *attrName,
3496 const char *surfName,
3497 CODECHAL_MEDIA_STATE_TYPE mediaState,
3498 uint32_t,
3499 uint32_t) {
3500 if ((*dumpEnabled)(attrName))
3501 {
3502 MediaDebugFastDump::Dump(
3503 surface->OsResource,
3504 std::string(traceSetting->fastDump.filePath) +
3505 std::to_string(m_bufferDumpFrameNum) +
3506 '-' +
3507 surfName +
3508 "w[0]_h[0]_p[0]" +
3509 suffix);
3510 }
3511 return MOS_STATUS_SUCCESS;
3512 };
3513
3514 m_dumpBuffer = [this, dumpEnabled, traceSetting, suffix](
3515 PMOS_RESOURCE resource,
3516 const char *attrName,
3517 const char *compName,
3518 uint32_t size,
3519 uint32_t offset,
3520 CODECHAL_MEDIA_STATE_TYPE mediaState) {
3521 if ((*dumpEnabled)(attrName))
3522 {
3523 std::string bufferName = "";
3524
3525 if (!strcmp(attrName, "DecodeBitstream") || !strcmp(attrName, "Bitstream"))
3526 {
3527 bufferName = "_Bitstream";
3528 }
3529
3530 MediaDebugFastDump::Dump(
3531 *resource,
3532 std::string(traceSetting->fastDump.filePath) +
3533 std::to_string(m_bufferDumpFrameNum) +
3534 '-' +
3535 compName + bufferName +
3536 suffix,
3537 size,
3538 offset,
3539 MediaDebugSerializer<uint32_t>());
3540 }
3541 return MOS_STATUS_SUCCESS;
3542 };
3543 }
3544 else
3545 {
3546 cfg.allowDataLoss = m_configMgr->AttrIsEnabled(MediaDbgAttr::attrFastDumpAllowDataLoss);
3547 cfg.informOnError = false;
3548
3549 // E.g., when FastDumpRenderCpyEn:1, FastDumpVeCpyEn:0, FastDumpBltCpyEn:0, only use render copy
3550 // when FastDumpRenderCpyEn:1, FastDumpVeCpyEn:1, FastDumpBltCpyEn:0, randomly use render and VE copy
3551 // when FastDumpRenderCpyEn:1, FastDumpVeCpyEn:1, FastDumpBltCpyEn:1, randomly use render, VE and BLT copy
3552 // when FastDumpRenderCpyEn:0, FastDumpVeCpyEn:0, FastDumpBltCpyEn:0, use FastDump default copy method, which is VE copy
3553 if (m_configMgr->AttrIsEnabled(MediaDbgAttr::attrFastDumpRenderCpyEn) || m_configMgr->AttrIsEnabled(MediaDbgAttr::attrFastDumpVeCpyEn)
3554 || m_configMgr->AttrIsEnabled(MediaDbgAttr::attrFastDumpBltCpyEn))
3555 {
3556 cfg.weightRenderCopy = m_configMgr->AttrIsEnabled(MediaDbgAttr::attrFastDumpRenderCpyEn) ? 100 : 0;
3557 cfg.weightVECopy = m_configMgr->AttrIsEnabled(MediaDbgAttr::attrFastDumpVeCpyEn) ? 100 : 0;
3558 cfg.weightBLTCopy = m_configMgr->AttrIsEnabled(MediaDbgAttr::attrFastDumpBltCpyEn) ? 100 : 0;
3559 }
3560 }
3561
3562 MediaDebugFastDump::CreateInstance(*m_osInterface, *mediaCopyWrapper, &cfg);
3563
3564 return MOS_STATUS_SUCCESS;
3565 }
3566
3567 const char *CodechalDebugInterface::CreateFileName(
3568 const char *funcName,
3569 const char *bufType,
3570 const char *extType)
3571 {
3572 if (nullptr == funcName || nullptr == extType)
3573 {
3574 return nullptr;
3575 }
3576
3577 char frameType = 'X';
3578 // Sets the frameType label
3579 if (m_frameType == I_TYPE)
3580 {
3581 frameType = 'I';
3582 }
3583 else if (m_frameType == P_TYPE)
3584 {
3585 frameType = 'P';
3586 }
3587 else if (m_frameType == B_TYPE)
3588 {
3589 frameType = 'B';
3590 }
3591 else if (m_frameType == MIXED_TYPE)
3592 {
3593 frameType = 'M';
3594 }
3595
3596 const char *fieldOrder;
3597 // Sets the Field Order label
3598 if (CodecHal_PictureIsTopField(m_currPic))
3599 {
3600 fieldOrder = MediaDbgFieldType::topField;
3601 }
3602 else if (CodecHal_PictureIsBottomField(m_currPic))
3603 {
3604 fieldOrder = MediaDbgFieldType::botField;
3605 }
3606 else
3607 {
3608 fieldOrder = MediaDbgFieldType::frame;
3609 }
3610
3611 // Sets the Postfix label
3612 if (m_configMgr->AttrIsEnabled(MediaDbgAttr::attrDumpBufferInBinary) &&
3613 strcmp(extType, MediaDbgExtType::txt) == 0)
3614 {
3615 extType = MediaDbgExtType::dat;
3616 }
3617
3618 if (bufType != nullptr &&
3619 !strncmp(bufType, MediaDbgBufferType::bufSlcParams, sizeof(MediaDbgBufferType::bufSlcParams) - 1) && !strncmp(funcName, "_DDIEnc", sizeof("_DDIEnc") - 1))
3620 {
3621 m_outputFileName = m_outputFilePath +
3622 std::to_string(m_bufferDumpFrameNum) + '-' +
3623 std::to_string(m_streamId) + '_' +
3624 std::to_string(m_sliceId + 1) +
3625 funcName + '_' + bufType + '_' + frameType + fieldOrder + extType;
3626 }
3627 else if (bufType != nullptr &&
3628 !strncmp(bufType, MediaDbgBufferType::bufEncodePar, sizeof(MediaDbgBufferType::bufEncodePar) - 1))
3629 {
3630 if (!strncmp(funcName, "EncodeSequence", sizeof("EncodeSequence") - 1))
3631 {
3632 m_outputFileName = m_outputFilePath +
3633 std::to_string(m_streamId) + '_' +
3634 funcName + extType;
3635 }
3636 else
3637 {
3638 m_outputFileName = m_outputFilePath +
3639 std::to_string(m_bufferDumpFrameNum) + '-' +
3640 std::to_string(m_streamId) + '_' +
3641 funcName + frameType + fieldOrder + extType;
3642 }
3643 }
3644 else
3645 {
3646 if (funcName[0] == '_')
3647 funcName += 1;
3648
3649 if (bufType != nullptr)
3650 {
3651 m_outputFileName = m_outputFilePath +
3652 std::to_string(m_bufferDumpFrameNum) + '-' +
3653 std::to_string(m_streamId) + '_' +
3654 funcName + '_' + bufType + '_' + frameType + fieldOrder + extType;
3655 }
3656 else
3657 {
3658 m_outputFileName = m_outputFilePath +
3659 std::to_string(m_bufferDumpFrameNum) + '-' +
3660 std::to_string(m_streamId) + '_' +
3661 funcName + '_' + frameType + fieldOrder + extType;
3662 }
3663 }
3664
3665 return m_outputFileName.c_str();
3666 }
3667
3668 MOS_STATUS CodechalDebugInterface::DumpStringStream(std::stringstream& ss, const char* bufferName, const char* attrName)
3669 {
3670 MEDIA_DEBUG_FUNCTION_ENTER;
3671
3672 MEDIA_DEBUG_CHK_NULL(bufferName);
3673 MEDIA_DEBUG_CHK_NULL(attrName);
3674
3675 if (!m_configMgr->AttrIsEnabled(attrName))
3676 {
3677 return MOS_STATUS_SUCCESS;
3678 }
3679
3680 const char* filePath = CreateFileName(bufferName, nullptr, MediaDbgExtType::txt);
3681 std::ofstream ofs(filePath);
3682 ofs << ss.str();
3683 ofs.close();
3684
3685 return MOS_STATUS_SUCCESS;
3686 }
3687
3688 MOS_STATUS CodechalDebugInterface::DumpCmdBuffer(
3689 PMOS_COMMAND_BUFFER cmdBuffer,
3690 CODECHAL_MEDIA_STATE_TYPE mediaState,
3691 const char * cmdName)
3692 {
3693 MEDIA_DEBUG_FUNCTION_ENTER;
3694
3695 bool attrEnabled = m_configMgr->AttrIsEnabled(MediaDbgAttr::attrCmdBufferMfx);
3696
3697 if (!attrEnabled && mediaState != CODECHAL_NUM_MEDIA_STATES)
3698 {
3699 attrEnabled = static_cast<CodecDebugConfigMgr*>(m_configMgr)->AttrIsEnabled(mediaState, MediaDbgAttr::attrCmdBuffer);
3700 }
3701
3702 if (!attrEnabled)
3703 {
3704 return MOS_STATUS_SUCCESS;
3705 }
3706
3707 bool binaryDumpEnabled = m_configMgr->AttrIsEnabled(MediaDbgAttr::attrDumpCmdBufInBinary);
3708
3709 std::string funcName = cmdName ? cmdName : static_cast<CodecDebugConfigMgr*>(m_configMgr)->GetMediaStateStr(mediaState);
3710 const char *fileName = CreateFileName(
3711 funcName.c_str(),
3712 MediaDbgBufferType::bufCmd,
3713 binaryDumpEnabled ? MediaDbgExtType::dat : MediaDbgExtType::txt);
3714
3715 if (m_configMgr->AttrIsEnabled(CodechalDbgAttr::attrEnableFastDump) && MediaDebugFastDump::IsGood())
3716 {
3717 MediaDebugFastDump::Dump(
3718 (uint8_t *)cmdBuffer->pCmdBase,
3719 fileName,
3720 (uint32_t)cmdBuffer->iOffset,
3721 0,
3722 MediaDebugSerializer<uint32_t>());
3723 }
3724 else
3725 {
3726 if (binaryDumpEnabled)
3727 {
3728 DumpBufferInBinary((uint8_t *)cmdBuffer->pCmdBase, (uint32_t)cmdBuffer->iOffset);
3729 }
3730 else
3731 {
3732 DumpBufferInHexDwords((uint8_t *)cmdBuffer->pCmdBase, (uint32_t)cmdBuffer->iOffset);
3733 }
3734 }
3735
3736 return MOS_STATUS_SUCCESS;
3737 }
3738
3739 MOS_STATUS CodechalDebugInterface::Dump2ndLvlBatch(
3740 PMHW_BATCH_BUFFER batchBuffer,
3741 CODECHAL_MEDIA_STATE_TYPE mediaState,
3742 const char * batchName)
3743 {
3744 MEDIA_DEBUG_FUNCTION_ENTER;
3745
3746 MEDIA_DEBUG_CHK_NULL(batchBuffer);
3747
3748 bool attrEnabled = m_configMgr->AttrIsEnabled(MediaDbgAttr::attr2ndLvlBatchMfx);
3749
3750 if (!attrEnabled && mediaState != CODECHAL_NUM_MEDIA_STATES)
3751 {
3752 attrEnabled = static_cast<CodecDebugConfigMgr*>(m_configMgr)->AttrIsEnabled(mediaState, MediaDbgAttr::attr2ndLvlBatch);
3753 }
3754
3755 if (!attrEnabled)
3756 {
3757 return MOS_STATUS_SUCCESS;
3758 }
3759
3760 std::string funcName = batchName ? batchName : static_cast<CodecDebugConfigMgr*>(m_configMgr)->GetMediaStateStr(mediaState);
3761 const char *fileName = CreateFileName(
3762 funcName.c_str(),
3763 MediaDbgBufferType::buf2ndLvl,
3764 MediaDbgExtType::txt);
3765
3766 MOS_STATUS status = MOS_STATUS_SUCCESS;
3767 if ((batchBuffer->OsResource.pGmmResInfo != nullptr) &&
3768 (batchBuffer->OsResource.pGmmResInfo->GetResFlags().Info.NotLockable))
3769 {
3770 uint8_t *data = nullptr;
3771 PMOS_RESOURCE pReadbackBuffer = (PMOS_RESOURCE)MOS_AllocAndZeroMemory(sizeof(MOS_RESOURCE));
3772 CODECHAL_DEBUG_CHK_NULL(pReadbackBuffer);
3773 status = AllocateLinearResource(MOS_GFXRES_BUFFER, (uint32_t)batchBuffer->OsResource.pGmmResInfo->GetBaseWidth(), (uint32_t)batchBuffer->OsResource.pGmmResInfo->GetBaseHeight(), Format_Any, pReadbackBuffer);
3774 if (MOS_FAILED(status))
3775 {
3776 MOS_FreeMemAndSetNull(pReadbackBuffer);
3777 }
3778 CODECHAL_DEBUG_CHK_STATUS(status);
3779 status = VDBypassCopyResource(&batchBuffer->OsResource, pReadbackBuffer);
3780 if (MOS_FAILED(status))
3781 {
3782 m_osInterface->pfnFreeResource(m_osInterface, pReadbackBuffer);
3783 MOS_FreeMemAndSetNull(pReadbackBuffer);
3784 }
3785 CODECHAL_DEBUG_CHK_STATUS(status);
3786
3787 MOS_LOCK_PARAMS lockFlags;
3788 MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS));
3789 lockFlags.ReadOnly = 1;
3790 data = (uint8_t *)m_osInterface->pfnLockResource(m_osInterface, pReadbackBuffer, &lockFlags);
3791 if (data == nullptr)
3792 {
3793 m_osInterface->pfnFreeResource(m_osInterface, pReadbackBuffer);
3794 MOS_FreeMemAndSetNull(pReadbackBuffer);
3795 }
3796 CODECHAL_DEBUG_CHK_NULL(data);
3797
3798 if (DumpIsEnabled(MediaDbgAttr::attrEnableFastDump) && MediaDebugFastDump::IsGood())
3799 {
3800 MediaDebugFastDump::Dump(
3801 data + batchBuffer->dwOffset,
3802 fileName,
3803 (uint32_t)batchBuffer->iLastCurrent,
3804 0,
3805 MediaDebugSerializer<uint32_t>());
3806 }
3807 else
3808 {
3809 DumpBufferInHexDwords(data + batchBuffer->dwOffset,
3810 (uint32_t)batchBuffer->iLastCurrent);
3811 }
3812
3813 m_osInterface->pfnUnlockResource(m_osInterface, pReadbackBuffer);
3814 m_osInterface->pfnFreeResource(m_osInterface, pReadbackBuffer);
3815 MOS_FreeMemAndSetNull(pReadbackBuffer);
3816 CODECHAL_DEBUG_CHK_STATUS(status);
3817 }
3818 else
3819 {
3820 bool batchLockedForDebug = !batchBuffer->bLocked;
3821
3822 if (batchLockedForDebug)
3823 {
3824 (Mhw_LockBb(m_osInterface, batchBuffer));
3825 }
3826
3827 batchBuffer->pData += batchBuffer->dwOffset;
3828
3829 if (DumpIsEnabled(MediaDbgAttr::attrEnableFastDump) && MediaDebugFastDump::IsGood())
3830 {
3831 MediaDebugFastDump::Dump(
3832 batchBuffer->pData,
3833 fileName,
3834 (uint32_t)batchBuffer->iLastCurrent,
3835 0,
3836 MediaDebugSerializer<uint32_t>());
3837 }
3838 else
3839 {
3840 DumpBufferInHexDwords(batchBuffer->pData,
3841 (uint32_t)batchBuffer->iLastCurrent);
3842 }
3843
3844 if (batchLockedForDebug)
3845 {
3846 (Mhw_UnlockBb(m_osInterface, batchBuffer, false));
3847 }
3848 }
3849
3850 return MOS_STATUS_SUCCESS;
3851 }
3852
3853 MOS_STATUS CodechalDebugInterface::DumpCurbe(
3854 CODECHAL_MEDIA_STATE_TYPE mediaState,
3855 PMHW_KERNEL_STATE kernelState)
3856 {
3857 MEDIA_DEBUG_FUNCTION_ENTER;
3858
3859 if (mediaState >= CODECHAL_NUM_MEDIA_STATES ||
3860 !static_cast<CodecDebugConfigMgr*>(m_configMgr)->AttrIsEnabled(mediaState, MediaDbgAttr::attrCurbe))
3861 {
3862 return MOS_STATUS_SUCCESS;
3863 }
3864
3865 std::string funcName = static_cast<CodecDebugConfigMgr*>(m_configMgr)->GetMediaStateStr(mediaState);
3866 bool binaryDump = m_configMgr->AttrIsEnabled(MediaDbgAttr::attrDumpBufferInBinary);
3867
3868 const char *fileName = CreateFileName(
3869 funcName.c_str(),
3870 MediaDbgBufferType::bufCurbe,
3871 MediaDbgExtType::txt);
3872
3873 return kernelState->m_dshRegion.Dump(
3874 fileName,
3875 kernelState->dwCurbeOffset,
3876 kernelState->KernelParams.iCurbeLength,
3877 binaryDump);
3878 }
3879
3880 MOS_STATUS CodechalDebugInterface::DumpMDFCurbe(
3881 CODECHAL_MEDIA_STATE_TYPE mediaState,
3882 uint8_t * curbeBuffer,
3883 uint32_t curbeSize)
3884 {
3885 MEDIA_DEBUG_FUNCTION_ENTER;
3886
3887 uint8_t * curbeAlignedData = nullptr;
3888 uint32_t curbeAlignedSize = 0;
3889 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
3890
3891 if (mediaState >= CODECHAL_NUM_MEDIA_STATES ||
3892 !static_cast<CodecDebugConfigMgr*>(m_configMgr)->AttrIsEnabled(mediaState, MediaDbgAttr::attrCurbe))
3893 {
3894 return eStatus;
3895 }
3896
3897 std::string funcName = static_cast<CodecDebugConfigMgr*>(m_configMgr)->GetMediaStateStr(mediaState);
3898 bool binaryDump = m_configMgr->AttrIsEnabled(MediaDbgAttr::attrDumpBufferInBinary);
3899 const char *extType = binaryDump ? MediaDbgExtType::dat : MediaDbgExtType::txt;
3900
3901 const char *fileName = CreateFileName(
3902 funcName.c_str(),
3903 MediaDbgBufferType::bufCurbe,
3904 extType);
3905
3906 curbeAlignedSize = MOS_ALIGN_CEIL(curbeSize, 64);
3907 curbeAlignedData = (uint8_t *)malloc(curbeAlignedSize * sizeof(uint8_t));
3908 if (curbeAlignedData == nullptr)
3909 {
3910 eStatus = MOS_STATUS_NULL_POINTER;
3911 return eStatus;
3912 }
3913
3914 MOS_ZeroMemory(curbeAlignedData, curbeAlignedSize);
3915 MOS_SecureMemcpy(curbeAlignedData, curbeSize, curbeBuffer, curbeSize);
3916
3917 if (binaryDump)
3918 {
3919 eStatus = DumpBufferInBinary(curbeAlignedData, curbeAlignedSize);
3920 }
3921 else
3922 {
3923 eStatus = DumpBufferInHexDwords(curbeAlignedData, curbeAlignedSize);
3924 }
3925
3926 free(curbeAlignedData);
3927
3928 return eStatus;
3929 }
3930
3931 MOS_STATUS CodechalDebugInterface::DumpKernelRegion(
3932 CODECHAL_MEDIA_STATE_TYPE mediaState,
3933 MHW_STATE_HEAP_TYPE stateHeap,
3934 PMHW_KERNEL_STATE kernelState)
3935 {
3936 MEDIA_DEBUG_FUNCTION_ENTER;
3937
3938 uint8_t *sshData = nullptr;
3939 uint32_t sshSize = 0;
3940
3941 MemoryBlock *regionBlock = nullptr;
3942 bool attrEnabled = false;
3943 const char * bufferType;
3944 if (stateHeap == MHW_ISH_TYPE)
3945 {
3946 regionBlock = &kernelState->m_ishRegion;
3947 attrEnabled = static_cast<CodecDebugConfigMgr*>(m_configMgr)->AttrIsEnabled(mediaState, MediaDbgAttr::attrIsh);
3948 bufferType = MediaDbgBufferType::bufISH;
3949 }
3950 else if (stateHeap == MHW_DSH_TYPE)
3951 {
3952 regionBlock = &kernelState->m_dshRegion;
3953 attrEnabled = static_cast<CodecDebugConfigMgr*>(m_configMgr)->AttrIsEnabled(mediaState, MediaDbgAttr::attrDsh);
3954 bufferType = MediaDbgBufferType::bufDSH;
3955 }
3956 else
3957 {
3958 attrEnabled = static_cast<CodecDebugConfigMgr*>(m_configMgr)->AttrIsEnabled(mediaState, MediaDbgAttr::attrSsh);
3959 bufferType = MediaDbgBufferType::bufSSH;
3960
3961 MEDIA_DEBUG_CHK_NULL(m_osInterface);
3962 MEDIA_DEBUG_CHK_STATUS(m_osInterface->pfnGetIndirectStatePointer(
3963 m_osInterface,
3964 &sshData));
3965 sshData += kernelState->dwSshOffset;
3966 sshSize = kernelState->dwSshSize;
3967 }
3968
3969 if (!attrEnabled)
3970 {
3971 return MOS_STATUS_SUCCESS;
3972 }
3973
3974 std::string funcName = static_cast<CodecDebugConfigMgr*>(m_configMgr)->GetMediaStateStr(mediaState);
3975
3976 const char *fileName = CreateFileName(
3977 funcName.c_str(),
3978 bufferType,
3979 MediaDbgExtType::txt);
3980
3981 bool binaryDump = m_configMgr->AttrIsEnabled(MediaDbgAttr::attrDumpBufferInBinary);
3982
3983 if (regionBlock)
3984 {
3985 return regionBlock->Dump(fileName, 0, 0, binaryDump);
3986 }
3987 else
3988 {
3989 return DumpBufferInHexDwords(sshData, sshSize);
3990 }
3991 }
3992
3993 MOS_STATUS CodechalDebugInterface::DumpYUVSurfaceToBuffer(PMOS_SURFACE surface,
3994 uint8_t * buffer,
3995 uint32_t & size)
3996 {
3997 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
3998
3999 MOS_LOCK_PARAMS lockFlags;
4000 MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS));
4001 lockFlags.ReadOnly = 1;
4002 lockFlags.TiledAsTiled = 1; // Bypass GMM CPU blit due to some issues in GMM CpuBlt function
4003
4004 uint8_t *lockedAddr = (uint8_t *)m_osInterface->pfnLockResource(m_osInterface, &surface->OsResource, &lockFlags);
4005 if (lockedAddr == nullptr) // Failed to lock. Try to submit copy task and dump another surface
4006 {
4007 uint32_t sizeToBeCopied = 0;
4008 MOS_GFXRES_TYPE ResType;
4009
4010 #if LINUX
4011 // Linux does not have OsResource->ResType
4012 ResType = surface->Type;
4013 #else
4014 ResType = surface->OsResource.ResType;
4015 #endif
4016
4017 GMM_RESOURCE_FLAG gmmFlags = surface->OsResource.pGmmResInfo->GetResFlags();
4018 bool allocated = false;
4019
4020 MEDIA_DEBUG_CHK_STATUS(ReAllocateSurface(
4021 &m_temp2DSurfForCopy,
4022 surface,
4023 "Temp2DSurfForSurfDumper",
4024 ResType));
4025
4026 // Ensure allocated buffer size contains the source surface size
4027 if (m_temp2DSurfForCopy.OsResource.pGmmResInfo->GetSizeMainSurface() >= surface->OsResource.pGmmResInfo->GetSizeMainSurface())
4028 {
4029 sizeToBeCopied = (uint32_t)surface->OsResource.pGmmResInfo->GetSizeMainSurface();
4030 }
4031
4032 if (sizeToBeCopied == 0)
4033 {
4034 // Currently, MOS's pfnAllocateResource does not support allocate a surface reference to another surface.
4035 // When the source surface is not created from Media, it is possible that we cannot allocate the same size as source.
4036 // For example, on Gen9, Render target might have GMM set CCS=1 MMC=0, but MOS cannot allocate surface with such combination.
4037 // When Gmm allocation parameter is different, the resulting surface size/padding/pitch will be differnt.
4038 // Once if MOS can support allocate a surface by reference another surface, we can do a bit to bit copy without problem.
4039 MEDIA_DEBUG_ASSERTMESSAGE("Cannot allocate correct size, failed to copy nonlockable resource");
4040 return MOS_STATUS_NULL_POINTER;
4041 }
4042
4043 MEDIA_DEBUG_VERBOSEMESSAGE("Temp2DSurfaceForCopy width %d, height %d, pitch %d, TileType %d, bIsCompressed %d, CompressionMode %d",
4044 m_temp2DSurfForCopy.dwWidth,
4045 m_temp2DSurfForCopy.dwHeight,
4046 m_temp2DSurfForCopy.dwPitch,
4047 m_temp2DSurfForCopy.TileType,
4048 m_temp2DSurfForCopy.bIsCompressed,
4049 m_temp2DSurfForCopy.CompressionMode);
4050
4051 if (CopySurfaceData_Vdbox(sizeToBeCopied, &surface->OsResource, &m_temp2DSurfForCopy.OsResource) != MOS_STATUS_SUCCESS)
4052 {
4053 MEDIA_DEBUG_ASSERTMESSAGE("CopyDataSurface_Vdbox failed");
4054 m_osInterface->pfnFreeResource(m_osInterface, &m_temp2DSurfForCopy.OsResource);
4055 return MOS_STATUS_NULL_POINTER;
4056 }
4057 lockedAddr = (uint8_t *)m_osInterface->pfnLockResource(m_osInterface, &m_temp2DSurfForCopy.OsResource, &lockFlags);
4058 MEDIA_DEBUG_CHK_NULL(lockedAddr);
4059 }
4060
4061 uint32_t sizeMain = (uint32_t)(surface->OsResource.pGmmResInfo->GetSizeMainSurface());
4062 uint8_t *surfBaseAddr = (uint8_t *)MOS_AllocMemory(sizeMain);
4063 MEDIA_DEBUG_CHK_NULL(surfBaseAddr);
4064
4065 Mos_SwizzleData(lockedAddr, surfBaseAddr, surface->TileType, MOS_TILE_LINEAR, sizeMain / surface->dwPitch, surface->dwPitch, 0);
4066
4067 uint8_t *data = surfBaseAddr;
4068 data += surface->dwOffset + surface->YPlaneOffset.iYOffset * surface->dwPitch;
4069
4070 uint32_t width = surface->dwWidth;
4071 uint32_t height = surface->dwHeight;
4072
4073 switch (surface->Format)
4074 {
4075 case Format_YUY2:
4076 case Format_Y216V:
4077 case Format_P010:
4078 case Format_P016:
4079 width = width << 1;
4080 break;
4081 case Format_Y216:
4082 case Format_Y210: //422 10bit -- Y0[15:0]:U[15:0]:Y1[15:0]:V[15:0] = 32bits per pixel = 4Bytes per pixel
4083 case Format_Y410: //444 10bit -- A[31:30]:V[29:20]:Y[19:10]:U[9:0] = 32bits per pixel = 4Bytes per pixel
4084 case Format_R10G10B10A2:
4085 case Format_AYUV: //444 8bit -- A[31:24]:Y[23:16]:U[15:8]:V[7:0] = 32bits per pixel = 4Bytes per pixel
4086 case Format_A8R8G8B8:
4087 width = width << 2;
4088 break;
4089 default:
4090 break;
4091 }
4092
4093 uint32_t pitch = surface->dwPitch;
4094 if (surface->Format == Format_UYVY)
4095 pitch = width;
4096
4097 if (CodecHal_PictureIsBottomField(m_currPic))
4098 {
4099 data += pitch;
4100 }
4101
4102 if (CodecHal_PictureIsField(m_currPic))
4103 {
4104 pitch *= 2;
4105 height /= 2;
4106 }
4107
4108 // write luma data to file
4109 for (uint32_t h = 0; h < height; h++)
4110 {
4111 MOS_SecureMemcpy(buffer, width, data, width);
4112 buffer += width;
4113 size += width;
4114 data += pitch;
4115 }
4116
4117 if (surface->Format != Format_A8B8G8R8)
4118 {
4119 switch (surface->Format)
4120 {
4121 case Format_NV12:
4122 case Format_P010:
4123 case Format_P016:
4124 height >>= 1;
4125 break;
4126 case Format_Y416:
4127 case Format_AUYV:
4128 case Format_R10G10B10A2:
4129 height *= 2;
4130 break;
4131 case Format_YUY2:
4132 case Format_YUYV:
4133 case Format_YUY2V:
4134 case Format_Y216V:
4135 case Format_YVYU:
4136 case Format_UYVY:
4137 case Format_VYUY:
4138 case Format_Y216: //422 16bit
4139 case Format_Y210: //422 10bit
4140 case Format_P208: //422 8bit
4141 break;
4142 case Format_422V:
4143 case Format_IMC3:
4144 height = height / 2;
4145 break;
4146 case Format_AYUV:
4147 default:
4148 height = 0;
4149 break;
4150 }
4151
4152 uint8_t *vPlaneData = surfBaseAddr;
4153 #ifdef LINUX
4154 data = surfBaseAddr + surface->UPlaneOffset.iSurfaceOffset;
4155 if (surface->Format == Format_422V || surface->Format == Format_IMC3)
4156 {
4157 vPlaneData = surfBaseAddr + surface->VPlaneOffset.iSurfaceOffset;
4158 }
4159 #else
4160 data = surfBaseAddr + surface->UPlaneOffset.iLockSurfaceOffset;
4161 if (surface->Format == Format_422V || surface->Format == Format_IMC3)
4162 {
4163 vPlaneData = surfBaseAddr + surface->VPlaneOffset.iLockSurfaceOffset;
4164 }
4165
4166 #endif
4167
4168 // write chroma data to file
4169 for (uint32_t h = 0; h < height; h++)
4170 {
4171 MOS_SecureMemcpy(buffer, width, data, width);
4172 buffer += width;
4173 size += width;
4174 data += pitch;
4175 }
4176
4177 // write v planar data to file
4178 if (surface->Format == Format_422V || surface->Format == Format_IMC3)
4179 {
4180 for (uint32_t h = 0; h < height; h++)
4181 {
4182 MOS_SecureMemcpy(buffer, width, vPlaneData, width);
4183 buffer += width;
4184 size += width;
4185 vPlaneData += pitch;
4186 }
4187 }
4188 }
4189
4190 m_osInterface->pfnUnlockResource(m_osInterface, &surface->OsResource);
4191
4192 MOS_FreeMemory(surfBaseAddr);
4193
4194 return MOS_STATUS_SUCCESS;
4195 }
4196
4197 MOS_STATUS CodechalDebugInterface::DumpYUVSurface(
4198 PMOS_SURFACE surface,
4199 const char * attrName,
4200 const char * surfName,
4201 CODECHAL_MEDIA_STATE_TYPE mediaState,
4202 uint32_t width_in,
4203 uint32_t height_in)
4204 {
4205 return m_dumpYUVSurface(
4206 surface,
4207 attrName,
4208 surfName,
4209 mediaState,
4210 width_in,
4211 height_in);
4212 }
4213
4214 MOS_STATUS CodechalDebugInterface::DumpBuffer(
4215 PMOS_RESOURCE resource,
4216 const char * attrName,
4217 const char * bufferName,
4218 uint32_t size,
4219 uint32_t offset,
4220 CODECHAL_MEDIA_STATE_TYPE mediaState)
4221 {
4222 return m_dumpBuffer(
4223 resource,
4224 attrName,
4225 bufferName,
4226 size,
4227 offset,
4228 mediaState);
4229 }
4230
4231 MOS_STATUS CodechalDebugInterface::LoadBinaryToLockableBuffer(
4232 PMOS_RESOURCE resource,
4233 const char *attrName,
4234 const char *bufferName,
4235 uint32_t size,
4236 uint32_t offset,
4237 CODECHAL_MEDIA_STATE_TYPE mediaState)
4238 {
4239 MEDIA_DEBUG_FUNCTION_ENTER;
4240
4241 MEDIA_DEBUG_CHK_NULL(resource);
4242 MEDIA_DEBUG_CHK_NULL(bufferName);
4243
4244 const char *fileName;
4245 if (size == 0)
4246 {
4247 return MOS_STATUS_SUCCESS;
4248 }
4249 if (mediaState == CODECHAL_NUM_MEDIA_STATES)
4250 {
4251 fileName = CreateFileName(bufferName, attrName, MediaDbgExtType::dat);
4252 }
4253 else
4254 {
4255 std::string kernelName = static_cast<CodecDebugConfigMgr *>(m_configMgr)->GetMediaStateStr(mediaState);
4256 fileName = CreateFileName(kernelName.c_str(), bufferName, MediaDbgExtType::dat);
4257 }
4258
4259 MOS_STATUS status = MOS_STATUS_SUCCESS;
4260
4261 MOS_LOCK_PARAMS lockFlags;
4262 MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS));
4263 lockFlags.WriteOnly = 1;
4264 uint8_t *data = (uint8_t *)m_osInterface->pfnLockResource(m_osInterface, resource, &lockFlags);
4265 MEDIA_DEBUG_CHK_NULL(data);
4266 data += offset;
4267
4268 status = LoadBufferInBinary(data, size);
4269
4270 if (data)
4271 {
4272 m_osInterface->pfnUnlockResource(m_osInterface, resource);
4273 }
4274
4275 return status;
4276 }
4277
4278 MOS_STATUS CodechalDebugInterface::DumpSurface(
4279 PMOS_SURFACE surface,
4280 const char * attrName,
4281 const char * surfaceName,
4282 CODECHAL_MEDIA_STATE_TYPE mediaState)
4283 {
4284 MEDIA_DEBUG_FUNCTION_ENTER;
4285
4286 MEDIA_DEBUG_CHK_NULL(surface);
4287 MEDIA_DEBUG_CHK_NULL(attrName);
4288 MEDIA_DEBUG_CHK_NULL(surfaceName);
4289
4290 bool attrEnabled = false;
4291
4292 if (mediaState == CODECHAL_NUM_MEDIA_STATES)
4293 {
4294 attrEnabled = m_configMgr->AttrIsEnabled(attrName);
4295 }
4296 else
4297 {
4298 attrEnabled = static_cast<CodecDebugConfigMgr*>(m_configMgr)->AttrIsEnabled(mediaState, attrName);
4299 }
4300
4301 if (!attrEnabled)
4302 {
4303 return MOS_STATUS_SUCCESS;
4304 }
4305
4306 bool binaryDump = m_configMgr->AttrIsEnabled(MediaDbgAttr::attrDumpBufferInBinary);
4307 const char *extType = binaryDump ? MediaDbgExtType::dat : MediaDbgExtType::txt;
4308
4309 MOS_LOCK_PARAMS lockFlags;
4310 MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS));
4311 lockFlags.ReadOnly = 1;
4312 uint8_t *data = (uint8_t *)m_osInterface->pfnLockResource(m_osInterface, &surface->OsResource, &lockFlags);
4313 MEDIA_DEBUG_CHK_NULL(data);
4314
4315 std::string bufName = std::string(surfaceName) + "_w[" + std::to_string(surface->dwWidth) + "]_h[" + std::to_string(surface->dwHeight) + "]_p[" + std::to_string(surface->dwPitch) + "]";
4316 const char *fileName;
4317 if (mediaState == CODECHAL_NUM_MEDIA_STATES)
4318 {
4319 fileName = CreateFileName(bufName.c_str(), nullptr, extType);
4320 }
4321 else
4322 {
4323 std::string kernelName = static_cast<CodecDebugConfigMgr*>(m_configMgr)->GetMediaStateStr(mediaState);
4324 fileName = CreateFileName(kernelName.c_str(), bufName.c_str(), extType);
4325 }
4326
4327 MOS_STATUS status;
4328 if (binaryDump)
4329 {
4330 status = Dump2DBufferInBinary(data, surface->dwWidth, surface->dwHeight, surface->dwPitch);
4331 }
4332 else
4333 {
4334 status = DumpBufferInHexDwords(data, surface->dwHeight * surface->dwPitch);
4335 }
4336
4337 if (data)
4338 {
4339 m_osInterface->pfnUnlockResource(m_osInterface, &surface->OsResource);
4340 }
4341
4342 return status;
4343 }
4344
4345 MOS_STATUS CodechalDebugInterface::DumpData(
4346 void * data,
4347 uint32_t size,
4348 const char *attrName,
4349 const char *bufferName)
4350 {
4351 MEDIA_DEBUG_FUNCTION_ENTER;
4352
4353 MEDIA_DEBUG_CHK_NULL(data);
4354 MEDIA_DEBUG_CHK_NULL(attrName);
4355 MEDIA_DEBUG_CHK_NULL(bufferName);
4356
4357 if (!m_configMgr->AttrIsEnabled(attrName))
4358 {
4359 return MOS_STATUS_SUCCESS;
4360 }
4361
4362 bool binaryDump = m_configMgr->AttrIsEnabled(MediaDbgAttr::attrDumpBufferInBinary);
4363 const char *fileName = CreateFileName(bufferName, nullptr, binaryDump ? MediaDbgExtType::dat : MediaDbgExtType::txt);
4364
4365 if (binaryDump)
4366 {
4367 DumpBufferInBinary((uint8_t *)data, size);
4368 }
4369 else
4370 {
4371 DumpBufferInHexDwords((uint8_t *)data, size);
4372 }
4373
4374 return MOS_STATUS_SUCCESS;
4375 }
4376
4377 #define FIELD_TO_OFS(name, shift) ofs << shift #name << ": " << (int64_t)ptr->name << std::endl;
4378 #define EMPTY_TO_OFS()
4379 #define UNION_STRUCT_START_TO_OFS() ofs << "union" << std::endl \
4380 << "{" << std::endl \
4381 << " struct" << std::endl \
4382 << " {" << std::endl;
4383
4384 #define UNION_STRUCT_FIELD_TO_OFS(name) ofs << " "#name << ": " << ptr->name << std::endl;
4385 #define UNION_END_TO_OFS(name) ofs << " }" << std::endl \
4386 << " "#name << ": " << ptr->name << std::endl \
4387 << "}" << std::endl;
4388 #define OFFSET_FIELD_TO_OFS(class_name, f_name, shift) << shift " "#f_name": " << ptr->class_name.f_name << std::endl
4389 #define PLANE_OFFSET_TO_OFS(name) ofs << "MOS_PLANE_OFFSET "#name << std::endl \
4390 OFFSET_FIELD_TO_OFS(name, iSurfaceOffset,) \
4391 OFFSET_FIELD_TO_OFS(name, iXOffset,) \
4392 OFFSET_FIELD_TO_OFS(name, iYOffset,) \
4393 OFFSET_FIELD_TO_OFS(name, iLockSurfaceOffset,);
4394 #define RESOURCE_OFFSET_TO_OFS(name, shift) ofs << shift "MOS_RESOURCE_OFFSETS "#name << std::endl \
4395 OFFSET_FIELD_TO_OFS(name, BaseOffset, shift) \
4396 OFFSET_FIELD_TO_OFS(name, XOffset, shift) \
4397 OFFSET_FIELD_TO_OFS(name, YOffset, shift);
4398
4399 #define FIELD_TO_OFS_8SHIFT(name) FIELD_TO_OFS(name, " ")
4400
4401 MOS_STATUS CodechalDebugInterface::DumpSurfaceInfo(
4402 PMOS_SURFACE surface,
4403 const char* surfaceName)
4404 {
4405 MEDIA_DEBUG_FUNCTION_ENTER;
4406
4407 MEDIA_DEBUG_CHK_NULL(surface);
4408 MEDIA_DEBUG_CHK_NULL(surfaceName);
4409
4410 if (!m_configMgr->AttrIsEnabled(MediaDbgAttr::attrSurfaceInfo))
4411 {
4412 return MOS_STATUS_SUCCESS;
4413 }
4414
4415 const char* funcName = (m_mediafunction == MEDIA_FUNCTION_VP) ? "_VP" : ((m_mediafunction == MEDIA_FUNCTION_ENCODE) ? "_ENC" : "_DEC");
4416 const char* filePath = CreateFileName(funcName, surfaceName, MediaDbgExtType::txt);
4417 std::ofstream ofs(filePath);
4418 PMOS_SURFACE ptr = surface;
4419
4420 if (ofs.fail())
4421 {
4422 return MOS_STATUS_UNKNOWN;
4423 }
4424
4425 ofs << "Surface name: " << surfaceName << std::endl;
4426
4427 EMPTY_TO_OFS();
4428 ofs << "MOS_SURFACE:" << std::endl;
4429 FIELD_TO_OFS(dwArraySlice, );
4430 FIELD_TO_OFS(dwMipSlice, );
4431 FIELD_TO_OFS(S3dChannel, );
4432
4433 EMPTY_TO_OFS();
4434 FIELD_TO_OFS(Type, );
4435 FIELD_TO_OFS(bOverlay, );
4436 FIELD_TO_OFS(bFlipChain, );
4437
4438 #if !defined(LINUX)
4439 EMPTY_TO_OFS();
4440 UNION_STRUCT_START_TO_OFS();
4441 UNION_STRUCT_FIELD_TO_OFS(dwFirstArraySlice);
4442 UNION_STRUCT_FIELD_TO_OFS(dwFirstMipSlice);
4443 UNION_END_TO_OFS(dwSubResourceIndex);
4444 #endif
4445
4446 EMPTY_TO_OFS();
4447 FIELD_TO_OFS(dwWidth, );
4448 FIELD_TO_OFS(dwHeight, );
4449 FIELD_TO_OFS(dwSize, );
4450 FIELD_TO_OFS(dwDepth, );
4451 FIELD_TO_OFS(dwArraySize, );
4452 FIELD_TO_OFS(dwLockPitch, );
4453 FIELD_TO_OFS(dwPitch, );
4454 FIELD_TO_OFS(dwSlicePitch, );
4455 FIELD_TO_OFS(dwQPitch, );
4456 FIELD_TO_OFS(TileType, );
4457 FIELD_TO_OFS(TileModeGMM, );
4458 FIELD_TO_OFS(bGMMTileEnabled, );
4459 FIELD_TO_OFS(Format, );
4460 FIELD_TO_OFS(bArraySpacing, );
4461 FIELD_TO_OFS(bCompressible, );
4462
4463 EMPTY_TO_OFS();
4464 FIELD_TO_OFS(dwOffset, );
4465 PLANE_OFFSET_TO_OFS(YPlaneOffset);
4466 PLANE_OFFSET_TO_OFS(UPlaneOffset);
4467 PLANE_OFFSET_TO_OFS(VPlaneOffset);
4468
4469 EMPTY_TO_OFS();
4470 UNION_STRUCT_START_TO_OFS();
4471 RESOURCE_OFFSET_TO_OFS(RenderOffset.YUV.Y, " ");
4472 RESOURCE_OFFSET_TO_OFS(RenderOffset.YUV.U, " ");
4473 RESOURCE_OFFSET_TO_OFS(RenderOffset.YUV.V, " ");
4474 ofs << " } YUV;" << std::endl;
4475 RESOURCE_OFFSET_TO_OFS(RenderOffset.RGB, );
4476 ofs << "}" << std::endl;
4477
4478 EMPTY_TO_OFS();
4479 UNION_STRUCT_START_TO_OFS();
4480 UNION_STRUCT_FIELD_TO_OFS(LockOffset.YUV.Y);
4481 UNION_STRUCT_FIELD_TO_OFS(LockOffset.YUV.U);
4482 UNION_STRUCT_FIELD_TO_OFS(LockOffset.YUV.V);
4483 UNION_END_TO_OFS(LockOffset.RGB);
4484
4485 EMPTY_TO_OFS();
4486 FIELD_TO_OFS(bIsCompressed, );
4487 FIELD_TO_OFS(CompressionMode, );
4488 FIELD_TO_OFS(CompressionFormat, );
4489 FIELD_TO_OFS(YoffsetForUplane, );
4490 FIELD_TO_OFS(YoffsetForVplane, );
4491
4492 EMPTY_TO_OFS();
4493 EMPTY_TO_OFS();
4494 MOS_STATUS sts = DumpMosSpecificResourceInfoToOfs(&surface->OsResource, ofs);
4495 ofs.close();
4496
4497 return sts;
4498 }
4499
4500 #endif // USE_CODECHAL_DEBUG_TOOL