1 /**************************************************************************
3 * Copyright 2018 Advanced Micro Devices, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 #include "pipe/p_video_codec.h"
32 #include "util/u_video.h"
33 #include "util/u_memory.h"
35 #include "vl/vl_video_buffer.h"
36 #include "radeonsi/si_pipe.h"
37 #include "radeon_video.h"
38 #include "radeon_uvd_enc.h"
40 #define RADEON_ENC_CS(value) (enc->cs->current.buf[enc->cs->current.cdw++] = (value))
41 #define RADEON_ENC_BEGIN(cmd) { \
42 uint32_t *begin = &enc->cs->current.buf[enc->cs->current.cdw++]; \
44 #define RADEON_ENC_READ(buf, domain, off) radeon_uvd_enc_add_buffer(enc, (buf), RADEON_USAGE_READ, (domain), (off))
45 #define RADEON_ENC_WRITE(buf, domain, off) radeon_uvd_enc_add_buffer(enc, (buf), RADEON_USAGE_WRITE, (domain), (off))
46 #define RADEON_ENC_READWRITE(buf, domain, off) radeon_uvd_enc_add_buffer(enc, (buf), RADEON_USAGE_READWRITE, (domain), (off))
47 #define RADEON_ENC_END() *begin = (&enc->cs->current.buf[enc->cs->current.cdw] - begin) * 4; \
48 enc->total_task_size += *begin;}
50 static const unsigned index_to_shifts
[4] = { 24, 16, 8, 0 };
53 radeon_uvd_enc_add_buffer(struct radeon_uvd_encoder
*enc
,
54 struct pb_buffer
*buf
, enum radeon_bo_usage usage
,
55 enum radeon_bo_domain domain
, signed offset
)
57 enc
->ws
->cs_add_buffer(enc
->cs
, buf
, usage
| RADEON_USAGE_SYNCHRONIZED
,
60 addr
= enc
->ws
->buffer_get_virtual_address(buf
);
62 RADEON_ENC_CS(addr
>> 32);
67 radeon_uvd_enc_set_emulation_prevention(struct radeon_uvd_encoder
*enc
,
70 if (set
!= enc
->emulation_prevention
) {
71 enc
->emulation_prevention
= set
;
77 radeon_uvd_enc_output_one_byte(struct radeon_uvd_encoder
*enc
,
80 if (enc
->byte_index
== 0)
81 enc
->cs
->current
.buf
[enc
->cs
->current
.cdw
] = 0;
82 enc
->cs
->current
.buf
[enc
->cs
->current
.cdw
] |=
83 ((unsigned int) (byte
) << index_to_shifts
[enc
->byte_index
]);
86 if (enc
->byte_index
>= 4) {
88 enc
->cs
->current
.cdw
++;
93 radeon_uvd_enc_emulation_prevention(struct radeon_uvd_encoder
*enc
,
96 if (enc
->emulation_prevention
) {
97 if ((enc
->num_zeros
>= 2)
98 && ((byte
== 0x00) || (byte
== 0x01)
99 || (byte
== 0x02) || (byte
== 0x03))) {
100 radeon_uvd_enc_output_one_byte(enc
, 0x03);
101 enc
->bits_output
+= 8;
104 enc
->num_zeros
= (byte
== 0 ? (enc
->num_zeros
+ 1) : 0);
109 radeon_uvd_enc_code_fixed_bits(struct radeon_uvd_encoder
*enc
,
110 unsigned int value
, unsigned int num_bits
)
112 unsigned int bits_to_pack
= 0;
114 while (num_bits
> 0) {
115 unsigned int value_to_pack
= value
& (0xffffffff >> (32 - num_bits
));
118 (32 - enc
->bits_in_shifter
) ? (32 - enc
->bits_in_shifter
) : num_bits
;
120 if (bits_to_pack
< num_bits
)
121 value_to_pack
= value_to_pack
>> (num_bits
- bits_to_pack
);
124 value_to_pack
<< (32 - enc
->bits_in_shifter
- bits_to_pack
);
125 num_bits
-= bits_to_pack
;
126 enc
->bits_in_shifter
+= bits_to_pack
;
128 while (enc
->bits_in_shifter
>= 8) {
129 unsigned char output_byte
= (unsigned char) (enc
->shifter
>> 24);
131 radeon_uvd_enc_emulation_prevention(enc
, output_byte
);
132 radeon_uvd_enc_output_one_byte(enc
, output_byte
);
133 enc
->bits_in_shifter
-= 8;
134 enc
->bits_output
+= 8;
140 radeon_uvd_enc_reset(struct radeon_uvd_encoder
*enc
)
142 enc
->emulation_prevention
= false;
144 enc
->bits_in_shifter
= 0;
145 enc
->bits_output
= 0;
151 radeon_uvd_enc_byte_align(struct radeon_uvd_encoder
*enc
)
153 unsigned int num_padding_zeros
= (32 - enc
->bits_in_shifter
) % 8;
155 if (num_padding_zeros
> 0)
156 radeon_uvd_enc_code_fixed_bits(enc
, 0, num_padding_zeros
);
160 radeon_uvd_enc_flush_headers(struct radeon_uvd_encoder
*enc
)
162 if (enc
->bits_in_shifter
!= 0) {
163 unsigned char output_byte
= (unsigned char) (enc
->shifter
>> 24);
164 radeon_uvd_enc_emulation_prevention(enc
, output_byte
);
165 radeon_uvd_enc_output_one_byte(enc
, output_byte
);
166 enc
->bits_output
+= enc
->bits_in_shifter
;
168 enc
->bits_in_shifter
= 0;
172 if (enc
->byte_index
> 0) {
173 enc
->cs
->current
.cdw
++;
179 radeon_uvd_enc_code_ue(struct radeon_uvd_encoder
*enc
, unsigned int value
)
182 unsigned int ue_code
= value
+ 1;
186 value
= (value
>> 1);
190 unsigned int ue_length
= (x
<< 1) + 1;
191 radeon_uvd_enc_code_fixed_bits(enc
, ue_code
, ue_length
);
195 radeon_uvd_enc_code_se(struct radeon_uvd_encoder
*enc
, int value
)
200 v
= (value
< 0 ? ((unsigned int) (0 - value
) << 1)
201 : (((unsigned int) (value
) << 1) - 1));
203 radeon_uvd_enc_code_ue(enc
, v
);
207 radeon_uvd_enc_session_info(struct radeon_uvd_encoder
*enc
)
209 unsigned int interface_version
=
210 ((RENC_UVD_FW_INTERFACE_MAJOR_VERSION
<<
211 RENC_UVD_IF_MAJOR_VERSION_SHIFT
) |
212 (RENC_UVD_FW_INTERFACE_MINOR_VERSION
<<
213 RENC_UVD_IF_MINOR_VERSION_SHIFT
));
214 RADEON_ENC_BEGIN(RENC_UVD_IB_PARAM_SESSION_INFO
);
215 RADEON_ENC_CS(0x00000000); // reserved
216 RADEON_ENC_CS(interface_version
);
217 RADEON_ENC_READWRITE(enc
->si
->res
->buf
, enc
->si
->res
->domains
, 0x0);
222 radeon_uvd_enc_task_info(struct radeon_uvd_encoder
*enc
, bool need_feedback
)
224 enc
->enc_pic
.task_info
.task_id
++;
227 enc
->enc_pic
.task_info
.allowed_max_num_feedbacks
= 1;
229 enc
->enc_pic
.task_info
.allowed_max_num_feedbacks
= 0;
231 RADEON_ENC_BEGIN(RENC_UVD_IB_PARAM_TASK_INFO
);
232 enc
->p_task_size
= &enc
->cs
->current
.buf
[enc
->cs
->current
.cdw
++];
233 RADEON_ENC_CS(enc
->enc_pic
.task_info
.task_id
);
234 RADEON_ENC_CS(enc
->enc_pic
.task_info
.allowed_max_num_feedbacks
);
239 radeon_uvd_enc_session_init_hevc(struct radeon_uvd_encoder
*enc
)
241 enc
->enc_pic
.session_init
.aligned_picture_width
=
242 align(enc
->base
.width
, 64);
243 enc
->enc_pic
.session_init
.aligned_picture_height
=
244 align(enc
->base
.height
, 16);
245 enc
->enc_pic
.session_init
.padding_width
=
246 enc
->enc_pic
.session_init
.aligned_picture_width
- enc
->base
.width
;
247 enc
->enc_pic
.session_init
.padding_height
=
248 enc
->enc_pic
.session_init
.aligned_picture_height
- enc
->base
.height
;
249 enc
->enc_pic
.session_init
.pre_encode_mode
= RENC_UVD_PREENCODE_MODE_NONE
;
250 enc
->enc_pic
.session_init
.pre_encode_chroma_enabled
= false;
252 RADEON_ENC_BEGIN(RENC_UVD_IB_PARAM_SESSION_INIT
);
253 RADEON_ENC_CS(enc
->enc_pic
.session_init
.aligned_picture_width
);
254 RADEON_ENC_CS(enc
->enc_pic
.session_init
.aligned_picture_height
);
255 RADEON_ENC_CS(enc
->enc_pic
.session_init
.padding_width
);
256 RADEON_ENC_CS(enc
->enc_pic
.session_init
.padding_height
);
257 RADEON_ENC_CS(enc
->enc_pic
.session_init
.pre_encode_mode
);
258 RADEON_ENC_CS(enc
->enc_pic
.session_init
.pre_encode_chroma_enabled
);
263 radeon_uvd_enc_layer_control(struct radeon_uvd_encoder
*enc
)
265 enc
->enc_pic
.layer_ctrl
.max_num_temporal_layers
= 1;
266 enc
->enc_pic
.layer_ctrl
.num_temporal_layers
= 1;
268 RADEON_ENC_BEGIN(RENC_UVD_IB_PARAM_LAYER_CONTROL
);
269 RADEON_ENC_CS(enc
->enc_pic
.layer_ctrl
.max_num_temporal_layers
);
270 RADEON_ENC_CS(enc
->enc_pic
.layer_ctrl
.num_temporal_layers
);
275 radeon_uvd_enc_layer_select(struct radeon_uvd_encoder
*enc
)
277 enc
->enc_pic
.layer_sel
.temporal_layer_index
= 0;
279 RADEON_ENC_BEGIN(RENC_UVD_IB_PARAM_LAYER_SELECT
);
280 RADEON_ENC_CS(enc
->enc_pic
.layer_sel
.temporal_layer_index
);
285 radeon_uvd_enc_slice_control_hevc(struct radeon_uvd_encoder
*enc
)
287 enc
->enc_pic
.hevc_slice_ctrl
.slice_control_mode
=
288 RENC_UVD_SLICE_CONTROL_MODE_FIXED_CTBS
;
289 enc
->enc_pic
.hevc_slice_ctrl
.fixed_ctbs_per_slice
.num_ctbs_per_slice
=
290 align(enc
->base
.width
, 64) / 64 * align(enc
->base
.height
, 64) / 64;
291 enc
->enc_pic
.hevc_slice_ctrl
.
292 fixed_ctbs_per_slice
.num_ctbs_per_slice_segment
=
293 enc
->enc_pic
.hevc_slice_ctrl
.fixed_ctbs_per_slice
.num_ctbs_per_slice
;
295 RADEON_ENC_BEGIN(RENC_UVD_IB_PARAM_SLICE_CONTROL
);
296 RADEON_ENC_CS(enc
->enc_pic
.hevc_slice_ctrl
.slice_control_mode
);
297 RADEON_ENC_CS(enc
->enc_pic
.hevc_slice_ctrl
.
298 fixed_ctbs_per_slice
.num_ctbs_per_slice
);
299 RADEON_ENC_CS(enc
->enc_pic
.hevc_slice_ctrl
.
300 fixed_ctbs_per_slice
.num_ctbs_per_slice_segment
);
305 radeon_uvd_enc_spec_misc_hevc(struct radeon_uvd_encoder
*enc
,
306 struct pipe_picture_desc
*picture
)
308 struct pipe_h265_enc_picture_desc
*pic
=
309 (struct pipe_h265_enc_picture_desc
*) picture
;
310 enc
->enc_pic
.hevc_spec_misc
.log2_min_luma_coding_block_size_minus3
=
311 pic
->seq
.log2_min_luma_coding_block_size_minus3
;
312 enc
->enc_pic
.hevc_spec_misc
.amp_disabled
= !pic
->seq
.amp_enabled_flag
;
313 enc
->enc_pic
.hevc_spec_misc
.strong_intra_smoothing_enabled
=
314 pic
->seq
.strong_intra_smoothing_enabled_flag
;
315 enc
->enc_pic
.hevc_spec_misc
.constrained_intra_pred_flag
=
316 pic
->pic
.constrained_intra_pred_flag
;
317 enc
->enc_pic
.hevc_spec_misc
.cabac_init_flag
= pic
->slice
.cabac_init_flag
;
318 enc
->enc_pic
.hevc_spec_misc
.half_pel_enabled
= 1;
319 enc
->enc_pic
.hevc_spec_misc
.quarter_pel_enabled
= 1;
321 RADEON_ENC_BEGIN(RENC_UVD_IB_PARAM_SPEC_MISC
);
322 RADEON_ENC_CS(enc
->enc_pic
.
323 hevc_spec_misc
.log2_min_luma_coding_block_size_minus3
);
324 RADEON_ENC_CS(enc
->enc_pic
.hevc_spec_misc
.amp_disabled
);
325 RADEON_ENC_CS(enc
->enc_pic
.hevc_spec_misc
.strong_intra_smoothing_enabled
);
326 RADEON_ENC_CS(enc
->enc_pic
.hevc_spec_misc
.constrained_intra_pred_flag
);
327 RADEON_ENC_CS(enc
->enc_pic
.hevc_spec_misc
.cabac_init_flag
);
328 RADEON_ENC_CS(enc
->enc_pic
.hevc_spec_misc
.half_pel_enabled
);
329 RADEON_ENC_CS(enc
->enc_pic
.hevc_spec_misc
.quarter_pel_enabled
);
334 radeon_uvd_enc_rc_session_init(struct radeon_uvd_encoder
*enc
,
335 struct pipe_picture_desc
*picture
)
337 struct pipe_h265_enc_picture_desc
*pic
=
338 (struct pipe_h265_enc_picture_desc
*) picture
;
339 enc
->enc_pic
.rc_session_init
.vbv_buffer_level
= pic
->rc
.vbv_buf_lv
;
340 switch (pic
->rc
.rate_ctrl_method
) {
341 case PIPE_H265_ENC_RATE_CONTROL_METHOD_DISABLE
:
342 enc
->enc_pic
.rc_session_init
.rate_control_method
=
343 RENC_UVD_RATE_CONTROL_METHOD_NONE
;
345 case PIPE_H265_ENC_RATE_CONTROL_METHOD_CONSTANT_SKIP
:
346 case PIPE_H265_ENC_RATE_CONTROL_METHOD_CONSTANT
:
347 enc
->enc_pic
.rc_session_init
.rate_control_method
=
348 RENC_UVD_RATE_CONTROL_METHOD_CBR
;
350 case PIPE_H265_ENC_RATE_CONTROL_METHOD_VARIABLE_SKIP
:
351 case PIPE_H265_ENC_RATE_CONTROL_METHOD_VARIABLE
:
352 enc
->enc_pic
.rc_session_init
.rate_control_method
=
353 RENC_UVD_RATE_CONTROL_METHOD_PEAK_CONSTRAINED_VBR
;
356 enc
->enc_pic
.rc_session_init
.rate_control_method
=
357 RENC_UVD_RATE_CONTROL_METHOD_NONE
;
360 RADEON_ENC_BEGIN(RENC_UVD_IB_PARAM_RATE_CONTROL_SESSION_INIT
);
361 RADEON_ENC_CS(enc
->enc_pic
.rc_session_init
.rate_control_method
);
362 RADEON_ENC_CS(enc
->enc_pic
.rc_session_init
.vbv_buffer_level
);
367 radeon_uvd_enc_rc_layer_init(struct radeon_uvd_encoder
*enc
,
368 struct pipe_picture_desc
*picture
)
370 struct pipe_h265_enc_picture_desc
*pic
=
371 (struct pipe_h265_enc_picture_desc
*) picture
;
372 enc
->enc_pic
.rc_layer_init
.target_bit_rate
= pic
->rc
.target_bitrate
;
373 enc
->enc_pic
.rc_layer_init
.peak_bit_rate
= pic
->rc
.peak_bitrate
;
374 enc
->enc_pic
.rc_layer_init
.frame_rate_num
= pic
->rc
.frame_rate_num
;
375 enc
->enc_pic
.rc_layer_init
.frame_rate_den
= pic
->rc
.frame_rate_den
;
376 enc
->enc_pic
.rc_layer_init
.vbv_buffer_size
= pic
->rc
.vbv_buffer_size
;
377 enc
->enc_pic
.rc_layer_init
.avg_target_bits_per_picture
=
378 pic
->rc
.target_bits_picture
;
379 enc
->enc_pic
.rc_layer_init
.peak_bits_per_picture_integer
=
380 pic
->rc
.peak_bits_picture_integer
;
381 enc
->enc_pic
.rc_layer_init
.peak_bits_per_picture_fractional
=
382 pic
->rc
.peak_bits_picture_fraction
;
384 RADEON_ENC_BEGIN(RENC_UVD_IB_PARAM_RATE_CONTROL_LAYER_INIT
);
385 RADEON_ENC_CS(enc
->enc_pic
.rc_layer_init
.target_bit_rate
);
386 RADEON_ENC_CS(enc
->enc_pic
.rc_layer_init
.peak_bit_rate
);
387 RADEON_ENC_CS(enc
->enc_pic
.rc_layer_init
.frame_rate_num
);
388 RADEON_ENC_CS(enc
->enc_pic
.rc_layer_init
.frame_rate_den
);
389 RADEON_ENC_CS(enc
->enc_pic
.rc_layer_init
.vbv_buffer_size
);
390 RADEON_ENC_CS(enc
->enc_pic
.rc_layer_init
.avg_target_bits_per_picture
);
391 RADEON_ENC_CS(enc
->enc_pic
.rc_layer_init
.peak_bits_per_picture_integer
);
392 RADEON_ENC_CS(enc
->enc_pic
.rc_layer_init
.peak_bits_per_picture_fractional
);
397 radeon_uvd_enc_deblocking_filter_hevc(struct radeon_uvd_encoder
*enc
,
398 struct pipe_picture_desc
*picture
)
400 struct pipe_h265_enc_picture_desc
*pic
=
401 (struct pipe_h265_enc_picture_desc
*) picture
;
402 enc
->enc_pic
.hevc_deblock
.loop_filter_across_slices_enabled
=
403 pic
->slice
.slice_loop_filter_across_slices_enabled_flag
;
404 enc
->enc_pic
.hevc_deblock
.deblocking_filter_disabled
=
405 pic
->slice
.slice_deblocking_filter_disabled_flag
;
406 enc
->enc_pic
.hevc_deblock
.beta_offset_div2
=
407 pic
->slice
.slice_beta_offset_div2
;
408 enc
->enc_pic
.hevc_deblock
.tc_offset_div2
= pic
->slice
.slice_tc_offset_div2
;
409 enc
->enc_pic
.hevc_deblock
.cb_qp_offset
= pic
->slice
.slice_cb_qp_offset
;
410 enc
->enc_pic
.hevc_deblock
.cr_qp_offset
= pic
->slice
.slice_cr_qp_offset
;
412 RADEON_ENC_BEGIN(RENC_UVD_IB_PARAM_DEBLOCKING_FILTER
);
413 RADEON_ENC_CS(enc
->enc_pic
.hevc_deblock
.loop_filter_across_slices_enabled
);
414 RADEON_ENC_CS(enc
->enc_pic
.hevc_deblock
.deblocking_filter_disabled
);
415 RADEON_ENC_CS(enc
->enc_pic
.hevc_deblock
.beta_offset_div2
);
416 RADEON_ENC_CS(enc
->enc_pic
.hevc_deblock
.tc_offset_div2
);
417 RADEON_ENC_CS(enc
->enc_pic
.hevc_deblock
.cb_qp_offset
);
418 RADEON_ENC_CS(enc
->enc_pic
.hevc_deblock
.cr_qp_offset
);
423 radeon_uvd_enc_quality_params(struct radeon_uvd_encoder
*enc
)
425 enc
->enc_pic
.quality_params
.vbaq_mode
= 0;
426 enc
->enc_pic
.quality_params
.scene_change_sensitivity
= 0;
427 enc
->enc_pic
.quality_params
.scene_change_min_idr_interval
= 0;
429 RADEON_ENC_BEGIN(RENC_UVD_IB_PARAM_QUALITY_PARAMS
);
430 RADEON_ENC_CS(enc
->enc_pic
.quality_params
.vbaq_mode
);
431 RADEON_ENC_CS(enc
->enc_pic
.quality_params
.scene_change_sensitivity
);
432 RADEON_ENC_CS(enc
->enc_pic
.quality_params
.scene_change_min_idr_interval
);
437 radeon_uvd_enc_nalu_sps_hevc(struct radeon_uvd_encoder
*enc
)
439 RADEON_ENC_BEGIN(RENC_UVD_IB_PARAM_INSERT_NALU_BUFFER
);
440 RADEON_ENC_CS(RENC_UVD_NALU_TYPE_SPS
);
441 uint32_t *size_in_bytes
= &enc
->cs
->current
.buf
[enc
->cs
->current
.cdw
++];
444 radeon_uvd_enc_reset(enc
);
445 radeon_uvd_enc_set_emulation_prevention(enc
, false);
446 radeon_uvd_enc_code_fixed_bits(enc
, 0x00000001, 32);
447 radeon_uvd_enc_code_fixed_bits(enc
, 0x4201, 16);
448 radeon_uvd_enc_byte_align(enc
);
449 radeon_uvd_enc_set_emulation_prevention(enc
, true);
450 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 4);
451 radeon_uvd_enc_code_fixed_bits(enc
,
453 layer_ctrl
.max_num_temporal_layers
- 1, 3);
454 radeon_uvd_enc_code_fixed_bits(enc
, 0x1, 1);
455 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 2);
456 radeon_uvd_enc_code_fixed_bits(enc
, enc
->enc_pic
.general_tier_flag
, 1);
457 radeon_uvd_enc_code_fixed_bits(enc
, enc
->enc_pic
.general_profile_idc
, 5);
458 radeon_uvd_enc_code_fixed_bits(enc
, 0x60000000, 32);
459 radeon_uvd_enc_code_fixed_bits(enc
, 0xb0000000, 32);
460 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 16);
461 radeon_uvd_enc_code_fixed_bits(enc
, enc
->enc_pic
.general_level_idc
, 8);
463 for (i
= 0; i
< (enc
->enc_pic
.layer_ctrl
.max_num_temporal_layers
- 1); i
++)
464 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 2);
466 if ((enc
->enc_pic
.layer_ctrl
.max_num_temporal_layers
- 1) > 0) {
467 for (i
= (enc
->enc_pic
.layer_ctrl
.max_num_temporal_layers
- 1); i
< 8; i
++)
468 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 2);
471 radeon_uvd_enc_code_ue(enc
, 0x0);
472 radeon_uvd_enc_code_ue(enc
, enc
->enc_pic
.chroma_format_idc
);
473 radeon_uvd_enc_code_ue(enc
,
474 enc
->enc_pic
.session_init
.aligned_picture_width
);
475 radeon_uvd_enc_code_ue(enc
,
476 enc
->enc_pic
.session_init
.aligned_picture_height
);
478 int conformance_window_flag
=
479 (enc
->enc_pic
.crop_top
> 0) ||
480 (enc
->enc_pic
.crop_bottom
> 0) ||
481 (enc
->enc_pic
.crop_left
> 0) ||
482 (enc
->enc_pic
.crop_right
> 0) ? 0x1 : 0x0;
483 radeon_uvd_enc_code_fixed_bits(enc
, conformance_window_flag
, 1);
484 if (conformance_window_flag
== 1) {
485 radeon_uvd_enc_code_ue(enc
, enc
->enc_pic
.crop_left
);
486 radeon_uvd_enc_code_ue(enc
, enc
->enc_pic
.crop_right
);
487 radeon_uvd_enc_code_ue(enc
, enc
->enc_pic
.crop_top
);
488 radeon_uvd_enc_code_ue(enc
, enc
->enc_pic
.crop_bottom
);
491 radeon_uvd_enc_code_ue(enc
, enc
->enc_pic
.bit_depth_luma_minus8
);
492 radeon_uvd_enc_code_ue(enc
, enc
->enc_pic
.bit_depth_chroma_minus8
);
493 radeon_uvd_enc_code_ue(enc
, enc
->enc_pic
.log2_max_poc
- 4);
494 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
495 radeon_uvd_enc_code_ue(enc
, 1);
496 radeon_uvd_enc_code_ue(enc
, 0x0);
497 radeon_uvd_enc_code_ue(enc
, 0x0);
498 radeon_uvd_enc_code_ue(enc
,
499 enc
->enc_pic
.hevc_spec_misc
.
500 log2_min_luma_coding_block_size_minus3
);
501 /* Only support CTBSize 64 */
502 radeon_uvd_enc_code_ue(enc
,
504 (enc
->enc_pic
.hevc_spec_misc
.
505 log2_min_luma_coding_block_size_minus3
+ 3));
506 radeon_uvd_enc_code_ue(enc
,
507 enc
->enc_pic
.log2_min_transform_block_size_minus2
);
508 radeon_uvd_enc_code_ue(enc
,
510 log2_diff_max_min_transform_block_size
);
511 radeon_uvd_enc_code_ue(enc
,
512 enc
->enc_pic
.max_transform_hierarchy_depth_inter
);
513 radeon_uvd_enc_code_ue(enc
,
514 enc
->enc_pic
.max_transform_hierarchy_depth_intra
);
516 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
517 radeon_uvd_enc_code_fixed_bits(enc
,
518 !enc
->enc_pic
.hevc_spec_misc
.amp_disabled
,
520 radeon_uvd_enc_code_fixed_bits(enc
,
522 sample_adaptive_offset_enabled_flag
, 1);
523 radeon_uvd_enc_code_fixed_bits(enc
, enc
->enc_pic
.pcm_enabled_flag
, 1);
525 radeon_uvd_enc_code_ue(enc
, 1);
526 radeon_uvd_enc_code_ue(enc
, 1);
527 radeon_uvd_enc_code_ue(enc
, 0);
528 radeon_uvd_enc_code_ue(enc
, 0);
529 radeon_uvd_enc_code_fixed_bits(enc
, 0x1, 1);
531 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
533 radeon_uvd_enc_code_fixed_bits(enc
, 0, 1);
534 radeon_uvd_enc_code_fixed_bits(enc
,
535 enc
->enc_pic
.hevc_spec_misc
.
536 strong_intra_smoothing_enabled
, 1);
538 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
540 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
542 radeon_uvd_enc_code_fixed_bits(enc
, 0x1, 1);
544 radeon_uvd_enc_byte_align(enc
);
545 radeon_uvd_enc_flush_headers(enc
);
546 *size_in_bytes
= (enc
->bits_output
+ 7) / 8;
551 radeon_uvd_enc_nalu_pps_hevc(struct radeon_uvd_encoder
*enc
)
553 RADEON_ENC_BEGIN(RENC_UVD_IB_PARAM_INSERT_NALU_BUFFER
);
554 RADEON_ENC_CS(RENC_UVD_NALU_TYPE_PPS
);
555 uint32_t *size_in_bytes
= &enc
->cs
->current
.buf
[enc
->cs
->current
.cdw
++];
556 radeon_uvd_enc_reset(enc
);
557 radeon_uvd_enc_set_emulation_prevention(enc
, false);
558 radeon_uvd_enc_code_fixed_bits(enc
, 0x00000001, 32);
559 radeon_uvd_enc_code_fixed_bits(enc
, 0x4401, 16);
560 radeon_uvd_enc_byte_align(enc
);
561 radeon_uvd_enc_set_emulation_prevention(enc
, true);
562 radeon_uvd_enc_code_ue(enc
, 0x0);
563 radeon_uvd_enc_code_ue(enc
, 0x0);
564 radeon_uvd_enc_code_fixed_bits(enc
, 0x1, 1);
565 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1); /* output_flag_resent_flag */
566 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 3); /* num_extra_slice_header_bits */
567 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
568 radeon_uvd_enc_code_fixed_bits(enc
, 0x1, 1);
569 radeon_uvd_enc_code_ue(enc
, 0x0);
570 radeon_uvd_enc_code_ue(enc
, 0x0);
571 radeon_uvd_enc_code_se(enc
, 0x0);
572 radeon_uvd_enc_code_fixed_bits(enc
,
573 enc
->enc_pic
.hevc_spec_misc
.
574 constrained_intra_pred_flag
, 1);
575 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
576 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
577 radeon_uvd_enc_code_se(enc
, enc
->enc_pic
.hevc_deblock
.cb_qp_offset
);
578 radeon_uvd_enc_code_se(enc
, enc
->enc_pic
.hevc_deblock
.cr_qp_offset
);
579 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
580 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 2);
581 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
582 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
583 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
584 radeon_uvd_enc_code_fixed_bits(enc
,
585 enc
->enc_pic
.hevc_deblock
.
586 loop_filter_across_slices_enabled
, 1);
587 radeon_uvd_enc_code_fixed_bits(enc
, 0x1, 1);
588 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
589 radeon_uvd_enc_code_fixed_bits(enc
,
590 enc
->enc_pic
.hevc_deblock
.
591 deblocking_filter_disabled
, 1);
593 if (!enc
->enc_pic
.hevc_deblock
.deblocking_filter_disabled
) {
594 radeon_uvd_enc_code_se(enc
, enc
->enc_pic
.hevc_deblock
.beta_offset_div2
);
595 radeon_uvd_enc_code_se(enc
, enc
->enc_pic
.hevc_deblock
.tc_offset_div2
);
598 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
599 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
600 radeon_uvd_enc_code_ue(enc
, enc
->enc_pic
.log2_parallel_merge_level_minus2
);
601 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 2);
603 radeon_uvd_enc_code_fixed_bits(enc
, 0x1, 1);
605 radeon_uvd_enc_byte_align(enc
);
606 radeon_uvd_enc_flush_headers(enc
);
607 *size_in_bytes
= (enc
->bits_output
+ 7) / 8;
612 radeon_uvd_enc_nalu_vps_hevc(struct radeon_uvd_encoder
*enc
)
614 RADEON_ENC_BEGIN(RENC_UVD_IB_PARAM_INSERT_NALU_BUFFER
);
615 RADEON_ENC_CS(RENC_UVD_NALU_TYPE_VPS
);
616 uint32_t *size_in_bytes
= &enc
->cs
->current
.buf
[enc
->cs
->current
.cdw
++];
619 radeon_uvd_enc_reset(enc
);
620 radeon_uvd_enc_set_emulation_prevention(enc
, false);
621 radeon_uvd_enc_code_fixed_bits(enc
, 0x00000001, 32);
622 radeon_uvd_enc_code_fixed_bits(enc
, 0x4001, 16);
623 radeon_uvd_enc_byte_align(enc
);
624 radeon_uvd_enc_set_emulation_prevention(enc
, true);
626 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 4);
627 radeon_uvd_enc_code_fixed_bits(enc
, 0x3, 2);
628 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 6);
629 radeon_uvd_enc_code_fixed_bits(enc
,
630 enc
->enc_pic
.layer_ctrl
.
631 max_num_temporal_layers
- 1, 3);
632 radeon_uvd_enc_code_fixed_bits(enc
, 0x1, 1);
633 radeon_uvd_enc_code_fixed_bits(enc
, 0xffff, 16);
634 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 2);
635 radeon_uvd_enc_code_fixed_bits(enc
, enc
->enc_pic
.general_tier_flag
, 1);
636 radeon_uvd_enc_code_fixed_bits(enc
, enc
->enc_pic
.general_profile_idc
, 5);
637 radeon_uvd_enc_code_fixed_bits(enc
, 0x60000000, 32);
638 radeon_uvd_enc_code_fixed_bits(enc
, 0xb0000000, 32);
639 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 16);
640 radeon_uvd_enc_code_fixed_bits(enc
, enc
->enc_pic
.general_level_idc
, 8);
642 for (i
= 0; i
< (enc
->enc_pic
.layer_ctrl
.max_num_temporal_layers
- 1); i
++)
643 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 2);
645 if ((enc
->enc_pic
.layer_ctrl
.max_num_temporal_layers
- 1) > 0) {
646 for (i
= (enc
->enc_pic
.layer_ctrl
.max_num_temporal_layers
- 1); i
< 8; i
++)
647 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 2);
650 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
651 radeon_uvd_enc_code_ue(enc
, 0x1);
652 radeon_uvd_enc_code_ue(enc
, 0x0);
653 radeon_uvd_enc_code_ue(enc
, 0x0);
655 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 6);
656 radeon_uvd_enc_code_ue(enc
, 0x0);
657 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
658 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
660 radeon_uvd_enc_code_fixed_bits(enc
, 0x1, 1);
662 radeon_uvd_enc_byte_align(enc
);
663 radeon_uvd_enc_flush_headers(enc
);
664 *size_in_bytes
= (enc
->bits_output
+ 7) / 8;
669 radeon_uvd_enc_nalu_aud_hevc(struct radeon_uvd_encoder
*enc
)
671 RADEON_ENC_BEGIN(RENC_UVD_IB_PARAM_INSERT_NALU_BUFFER
);
672 RADEON_ENC_CS(RENC_UVD_NALU_TYPE_AUD
);
673 uint32_t *size_in_bytes
= &enc
->cs
->current
.buf
[enc
->cs
->current
.cdw
++];
674 radeon_uvd_enc_reset(enc
);
675 radeon_uvd_enc_set_emulation_prevention(enc
, false);
676 radeon_uvd_enc_code_fixed_bits(enc
, 0x00000001, 32);
677 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
678 radeon_uvd_enc_code_fixed_bits(enc
, 35, 6);
679 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 6);
680 radeon_uvd_enc_code_fixed_bits(enc
, 0x1, 3);
681 radeon_uvd_enc_byte_align(enc
);
682 radeon_uvd_enc_set_emulation_prevention(enc
, true);
683 switch (enc
->enc_pic
.picture_type
) {
684 case PIPE_H265_ENC_PICTURE_TYPE_I
:
685 case PIPE_H265_ENC_PICTURE_TYPE_IDR
:
686 radeon_uvd_enc_code_fixed_bits(enc
, 0x00, 3);
688 case PIPE_H265_ENC_PICTURE_TYPE_P
:
689 radeon_uvd_enc_code_fixed_bits(enc
, 0x01, 3);
691 case PIPE_H265_ENC_PICTURE_TYPE_B
:
692 radeon_uvd_enc_code_fixed_bits(enc
, 0x02, 3);
695 assert(0 && "Unsupported picture type!");
698 radeon_uvd_enc_code_fixed_bits(enc
, 0x1, 1);
700 radeon_uvd_enc_byte_align(enc
);
701 radeon_uvd_enc_flush_headers(enc
);
702 *size_in_bytes
= (enc
->bits_output
+ 7) / 8;
707 radeon_uvd_enc_slice_header_hevc(struct radeon_uvd_encoder
*enc
)
709 uint32_t instruction
[RENC_UVD_SLICE_HEADER_TEMPLATE_MAX_NUM_INSTRUCTIONS
] = { 0 };
710 uint32_t num_bits
[RENC_UVD_SLICE_HEADER_TEMPLATE_MAX_NUM_INSTRUCTIONS
] = { 0 };
711 unsigned int inst_index
= 0;
712 unsigned int bit_index
= 0;
713 unsigned int bits_copied
= 0;
714 RADEON_ENC_BEGIN(RENC_UVD_IB_PARAM_SLICE_HEADER
);
715 radeon_uvd_enc_reset(enc
);
716 radeon_uvd_enc_set_emulation_prevention(enc
, false);
718 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
719 radeon_uvd_enc_code_fixed_bits(enc
, enc
->enc_pic
.nal_unit_type
, 6);
720 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 6);
721 radeon_uvd_enc_code_fixed_bits(enc
, 0x1, 3);
723 radeon_uvd_enc_flush_headers(enc
);
725 instruction
[inst_index
] = RENC_UVD_HEADER_INSTRUCTION_COPY
;
726 num_bits
[inst_index
] = enc
->bits_output
- bits_copied
;
727 bits_copied
= enc
->bits_output
;
730 instruction
[inst_index
] = RENC_UVD_HEADER_INSTRUCTION_FIRST_SLICE
;
733 if ((enc
->enc_pic
.nal_unit_type
>= 16)
734 && (enc
->enc_pic
.nal_unit_type
<= 23))
735 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
737 radeon_uvd_enc_code_ue(enc
, 0x0);
739 radeon_uvd_enc_flush_headers(enc
);
741 instruction
[inst_index
] = RENC_UVD_HEADER_INSTRUCTION_COPY
;
742 num_bits
[inst_index
] = enc
->bits_output
- bits_copied
;
743 bits_copied
= enc
->bits_output
;
746 instruction
[inst_index
] = RENC_UVD_HEADER_INSTRUCTION_SLICE_SEGMENT
;
749 instruction
[inst_index
] = RENC_UVD_HEADER_INSTRUCTION_DEPENDENT_SLICE_END
;
752 switch (enc
->enc_pic
.picture_type
) {
753 case PIPE_H265_ENC_PICTURE_TYPE_I
:
754 case PIPE_H265_ENC_PICTURE_TYPE_IDR
:
755 radeon_uvd_enc_code_ue(enc
, 0x2);
757 case PIPE_H265_ENC_PICTURE_TYPE_P
:
758 case PIPE_H265_ENC_PICTURE_TYPE_SKIP
:
759 radeon_uvd_enc_code_ue(enc
, 0x1);
761 case PIPE_H265_ENC_PICTURE_TYPE_B
:
762 radeon_uvd_enc_code_ue(enc
, 0x0);
765 radeon_uvd_enc_code_ue(enc
, 0x1);
768 if ((enc
->enc_pic
.nal_unit_type
!= 19)
769 && (enc
->enc_pic
.nal_unit_type
!= 20)) {
770 radeon_uvd_enc_code_fixed_bits(enc
,
771 enc
->enc_pic
.frame_num
%
772 enc
->enc_pic
.max_poc
,
773 enc
->enc_pic
.log2_max_poc
);
774 if (enc
->enc_pic
.picture_type
== PIPE_H265_ENC_PICTURE_TYPE_P
)
775 radeon_uvd_enc_code_fixed_bits(enc
, 0x1, 1);
777 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
778 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
779 radeon_uvd_enc_code_ue(enc
, 0x0);
780 radeon_uvd_enc_code_ue(enc
, 0x0);
784 if (enc
->enc_pic
.sample_adaptive_offset_enabled_flag
)
785 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1); /* slice_sao_luma_flag */
787 if ((enc
->enc_pic
.picture_type
== PIPE_H265_ENC_PICTURE_TYPE_P
) ||
788 (enc
->enc_pic
.picture_type
== PIPE_H265_ENC_PICTURE_TYPE_B
)) {
789 radeon_uvd_enc_code_fixed_bits(enc
, 0x0, 1);
790 radeon_uvd_enc_code_fixed_bits(enc
,
791 enc
->enc_pic
.hevc_spec_misc
.
793 radeon_uvd_enc_code_ue(enc
, 5 - enc
->enc_pic
.max_num_merge_cand
);
796 radeon_uvd_enc_flush_headers(enc
);
798 instruction
[inst_index
] = RENC_UVD_HEADER_INSTRUCTION_COPY
;
799 num_bits
[inst_index
] = enc
->bits_output
- bits_copied
;
800 bits_copied
= enc
->bits_output
;
803 instruction
[inst_index
] = RENC_UVD_HEADER_INSTRUCTION_SLICE_QP_DELTA
;
806 if ((enc
->enc_pic
.hevc_deblock
.loop_filter_across_slices_enabled
) &&
807 (!enc
->enc_pic
.hevc_deblock
.deblocking_filter_disabled
)) {
808 radeon_uvd_enc_code_fixed_bits(enc
,
809 enc
->enc_pic
.hevc_deblock
.
810 loop_filter_across_slices_enabled
, 1);
812 radeon_uvd_enc_flush_headers(enc
);
814 instruction
[inst_index
] = RENC_UVD_HEADER_INSTRUCTION_COPY
;
815 num_bits
[inst_index
] = enc
->bits_output
- bits_copied
;
816 bits_copied
= enc
->bits_output
;
820 instruction
[inst_index
] = RENC_UVD_HEADER_INSTRUCTION_END
;
822 for (int i
= bit_index
;
823 i
< RENC_UVD_SLICE_HEADER_TEMPLATE_MAX_TEMPLATE_SIZE_IN_DWORDS
; i
++)
824 RADEON_ENC_CS(0x00000000);
826 for (int j
= 0; j
< RENC_UVD_SLICE_HEADER_TEMPLATE_MAX_NUM_INSTRUCTIONS
;
828 RADEON_ENC_CS(instruction
[j
]);
829 RADEON_ENC_CS(num_bits
[j
]);
836 radeon_uvd_enc_ctx(struct radeon_uvd_encoder
*enc
)
838 struct si_screen
*sscreen
= (struct si_screen
*) enc
->screen
;
840 enc
->enc_pic
.ctx_buf
.swizzle_mode
= 0;
841 if (sscreen
->info
.chip_class
< GFX9
) {
842 enc
->enc_pic
.ctx_buf
.rec_luma_pitch
=
843 (enc
->luma
->u
.legacy
.level
[0].nblk_x
* enc
->luma
->bpe
);
844 enc
->enc_pic
.ctx_buf
.rec_chroma_pitch
=
845 (enc
->chroma
->u
.legacy
.level
[0].nblk_x
* enc
->chroma
->bpe
);
848 enc
->enc_pic
.ctx_buf
.rec_luma_pitch
=
849 enc
->luma
->u
.gfx9
.surf_pitch
* enc
->luma
->bpe
;
850 enc
->enc_pic
.ctx_buf
.rec_chroma_pitch
=
851 enc
->chroma
->u
.gfx9
.surf_pitch
* enc
->chroma
->bpe
;
853 enc
->enc_pic
.ctx_buf
.num_reconstructed_pictures
= 2;
855 RADEON_ENC_BEGIN(RENC_UVD_IB_PARAM_ENCODE_CONTEXT_BUFFER
);
856 RADEON_ENC_READWRITE(enc
->cpb
.res
->buf
, enc
->cpb
.res
->domains
, 0);
857 RADEON_ENC_CS(0x00000000); // reserved
858 RADEON_ENC_CS(enc
->enc_pic
.ctx_buf
.swizzle_mode
);
859 RADEON_ENC_CS(enc
->enc_pic
.ctx_buf
.rec_luma_pitch
);
860 RADEON_ENC_CS(enc
->enc_pic
.ctx_buf
.rec_chroma_pitch
);
861 RADEON_ENC_CS(enc
->enc_pic
.ctx_buf
.num_reconstructed_pictures
);
862 /* reconstructed_picture_1_luma_offset */
863 RADEON_ENC_CS(0x00000000);
864 /* reconstructed_picture_1_chroma_offset */
865 RADEON_ENC_CS(enc
->enc_pic
.ctx_buf
.rec_chroma_pitch
*
866 align(enc
->base
.height
, 16));
867 /* reconstructed_picture_2_luma_offset */
868 RADEON_ENC_CS(enc
->enc_pic
.ctx_buf
.rec_luma_pitch
*
869 align(enc
->base
.height
, 16) * 3 / 2);
870 /* reconstructed_picture_2_chroma_offset */
871 RADEON_ENC_CS(enc
->enc_pic
.ctx_buf
.rec_chroma_pitch
*
872 align(enc
->base
.height
, 16) * 5 / 2);
874 for (int i
= 0; i
< 136; i
++)
875 RADEON_ENC_CS(0x00000000);
881 radeon_uvd_enc_bitstream(struct radeon_uvd_encoder
*enc
)
883 enc
->enc_pic
.bit_buf
.mode
= RENC_UVD_SWIZZLE_MODE_LINEAR
;
884 enc
->enc_pic
.bit_buf
.video_bitstream_buffer_size
= enc
->bs_size
;
885 enc
->enc_pic
.bit_buf
.video_bitstream_data_offset
= 0;
887 RADEON_ENC_BEGIN(RENC_UVD_IB_PARAM_VIDEO_BITSTREAM_BUFFER
);
888 RADEON_ENC_CS(enc
->enc_pic
.bit_buf
.mode
);
889 RADEON_ENC_WRITE(enc
->bs_handle
, RADEON_DOMAIN_GTT
, 0);
890 RADEON_ENC_CS(enc
->enc_pic
.bit_buf
.video_bitstream_buffer_size
);
891 RADEON_ENC_CS(enc
->enc_pic
.bit_buf
.video_bitstream_data_offset
);
896 radeon_uvd_enc_feedback(struct radeon_uvd_encoder
*enc
)
898 enc
->enc_pic
.fb_buf
.mode
= RENC_UVD_FEEDBACK_BUFFER_MODE_LINEAR
;
899 enc
->enc_pic
.fb_buf
.feedback_buffer_size
= 16;
900 enc
->enc_pic
.fb_buf
.feedback_data_size
= 40;
902 RADEON_ENC_BEGIN(RENC_UVD_IB_PARAM_FEEDBACK_BUFFER
);
903 RADEON_ENC_CS(enc
->enc_pic
.fb_buf
.mode
);
904 RADEON_ENC_WRITE(enc
->fb
->res
->buf
, enc
->fb
->res
->domains
, 0x0);
905 RADEON_ENC_CS(enc
->enc_pic
.fb_buf
.feedback_buffer_size
);
906 RADEON_ENC_CS(enc
->enc_pic
.fb_buf
.feedback_data_size
);
911 radeon_uvd_enc_intra_refresh(struct radeon_uvd_encoder
*enc
)
913 enc
->enc_pic
.intra_ref
.intra_refresh_mode
=
914 RENC_UVD_INTRA_REFRESH_MODE_NONE
;
915 enc
->enc_pic
.intra_ref
.offset
= 0;
916 enc
->enc_pic
.intra_ref
.region_size
= 0;
918 RADEON_ENC_BEGIN(RENC_UVD_IB_PARAM_INTRA_REFRESH
);
919 RADEON_ENC_CS(enc
->enc_pic
.intra_ref
.intra_refresh_mode
);
920 RADEON_ENC_CS(enc
->enc_pic
.intra_ref
.offset
);
921 RADEON_ENC_CS(enc
->enc_pic
.intra_ref
.region_size
);
926 radeon_uvd_enc_rc_per_pic(struct radeon_uvd_encoder
*enc
,
927 struct pipe_picture_desc
*picture
)
929 struct pipe_h265_enc_picture_desc
*pic
=
930 (struct pipe_h265_enc_picture_desc
*) picture
;
931 enc
->enc_pic
.rc_per_pic
.qp
= pic
->rc
.quant_i_frames
;
932 enc
->enc_pic
.rc_per_pic
.min_qp_app
= 0;
933 enc
->enc_pic
.rc_per_pic
.max_qp_app
= 51;
934 enc
->enc_pic
.rc_per_pic
.max_au_size
= 0;
935 enc
->enc_pic
.rc_per_pic
.enabled_filler_data
= pic
->rc
.fill_data_enable
;
936 enc
->enc_pic
.rc_per_pic
.skip_frame_enable
= false;
937 enc
->enc_pic
.rc_per_pic
.enforce_hrd
= pic
->rc
.enforce_hrd
;
939 RADEON_ENC_BEGIN(RENC_UVD_IB_PARAM_RATE_CONTROL_PER_PICTURE
);
940 RADEON_ENC_CS(enc
->enc_pic
.rc_per_pic
.qp
);
941 RADEON_ENC_CS(enc
->enc_pic
.rc_per_pic
.min_qp_app
);
942 RADEON_ENC_CS(enc
->enc_pic
.rc_per_pic
.max_qp_app
);
943 RADEON_ENC_CS(enc
->enc_pic
.rc_per_pic
.max_au_size
);
944 RADEON_ENC_CS(enc
->enc_pic
.rc_per_pic
.enabled_filler_data
);
945 RADEON_ENC_CS(enc
->enc_pic
.rc_per_pic
.skip_frame_enable
);
946 RADEON_ENC_CS(enc
->enc_pic
.rc_per_pic
.enforce_hrd
);
951 radeon_uvd_enc_encode_params_hevc(struct radeon_uvd_encoder
*enc
)
953 struct si_screen
*sscreen
= (struct si_screen
*) enc
->screen
;
954 switch (enc
->enc_pic
.picture_type
) {
955 case PIPE_H265_ENC_PICTURE_TYPE_I
:
956 case PIPE_H265_ENC_PICTURE_TYPE_IDR
:
957 enc
->enc_pic
.enc_params
.pic_type
= RENC_UVD_PICTURE_TYPE_I
;
959 case PIPE_H265_ENC_PICTURE_TYPE_P
:
960 enc
->enc_pic
.enc_params
.pic_type
= RENC_UVD_PICTURE_TYPE_P
;
962 case PIPE_H265_ENC_PICTURE_TYPE_SKIP
:
963 enc
->enc_pic
.enc_params
.pic_type
= RENC_UVD_PICTURE_TYPE_P_SKIP
;
965 case PIPE_H265_ENC_PICTURE_TYPE_B
:
966 enc
->enc_pic
.enc_params
.pic_type
= RENC_UVD_PICTURE_TYPE_B
;
969 enc
->enc_pic
.enc_params
.pic_type
= RENC_UVD_PICTURE_TYPE_I
;
972 enc
->enc_pic
.enc_params
.allowed_max_bitstream_size
= enc
->bs_size
;
973 if (sscreen
->info
.chip_class
< GFX9
) {
974 enc
->enc_pic
.enc_params
.input_pic_luma_pitch
=
975 (enc
->luma
->u
.legacy
.level
[0].nblk_x
* enc
->luma
->bpe
);
976 enc
->enc_pic
.enc_params
.input_pic_chroma_pitch
=
977 (enc
->chroma
->u
.legacy
.level
[0].nblk_x
* enc
->chroma
->bpe
);
980 enc
->enc_pic
.enc_params
.input_pic_luma_pitch
=
981 enc
->luma
->u
.gfx9
.surf_pitch
* enc
->luma
->bpe
;
982 enc
->enc_pic
.enc_params
.input_pic_chroma_pitch
=
983 enc
->chroma
->u
.gfx9
.surf_pitch
* enc
->chroma
->bpe
;
985 enc
->enc_pic
.enc_params
.input_pic_swizzle_mode
=
986 RENC_UVD_SWIZZLE_MODE_LINEAR
;
988 if (enc
->enc_pic
.enc_params
.pic_type
== RENC_UVD_PICTURE_TYPE_I
)
989 enc
->enc_pic
.enc_params
.reference_picture_index
= 0xFFFFFFFF;
991 enc
->enc_pic
.enc_params
.reference_picture_index
=
992 (enc
->enc_pic
.frame_num
- 1) % 2;
994 enc
->enc_pic
.enc_params
.reconstructed_picture_index
=
995 enc
->enc_pic
.frame_num
% 2;
997 RADEON_ENC_BEGIN(RENC_UVD_IB_PARAM_ENCODE_PARAMS
);
998 RADEON_ENC_CS(enc
->enc_pic
.enc_params
.pic_type
);
999 RADEON_ENC_CS(enc
->enc_pic
.enc_params
.allowed_max_bitstream_size
);
1001 if (sscreen
->info
.chip_class
< GFX9
) {
1002 RADEON_ENC_READ(enc
->handle
, RADEON_DOMAIN_VRAM
,
1003 enc
->luma
->u
.legacy
.level
[0].offset
);
1004 RADEON_ENC_READ(enc
->handle
, RADEON_DOMAIN_VRAM
,
1005 enc
->chroma
->u
.legacy
.level
[0].offset
);
1008 RADEON_ENC_READ(enc
->handle
, RADEON_DOMAIN_VRAM
,
1009 enc
->luma
->u
.gfx9
.surf_offset
);
1010 RADEON_ENC_READ(enc
->handle
, RADEON_DOMAIN_VRAM
,
1011 enc
->chroma
->u
.gfx9
.surf_offset
);
1013 RADEON_ENC_CS(enc
->enc_pic
.enc_params
.input_pic_luma_pitch
);
1014 RADEON_ENC_CS(enc
->enc_pic
.enc_params
.input_pic_chroma_pitch
);
1015 RADEON_ENC_CS(0x00000000); // reserved
1016 RADEON_ENC_CS(enc
->enc_pic
.enc_params
.input_pic_swizzle_mode
);
1017 RADEON_ENC_CS(enc
->enc_pic
.enc_params
.reference_picture_index
);
1018 RADEON_ENC_CS(enc
->enc_pic
.enc_params
.reconstructed_picture_index
);
1023 radeon_uvd_enc_op_init(struct radeon_uvd_encoder
*enc
)
1025 RADEON_ENC_BEGIN(RENC_UVD_IB_OP_INITIALIZE
);
1030 radeon_uvd_enc_op_close(struct radeon_uvd_encoder
*enc
)
1032 RADEON_ENC_BEGIN(RENC_UVD_IB_OP_CLOSE_SESSION
);
1037 radeon_uvd_enc_op_enc(struct radeon_uvd_encoder
*enc
)
1039 RADEON_ENC_BEGIN(RENC_UVD_IB_OP_ENCODE
);
1044 radeon_uvd_enc_op_init_rc(struct radeon_uvd_encoder
*enc
)
1046 RADEON_ENC_BEGIN(RENC_UVD_IB_OP_INIT_RC
);
1051 radeon_uvd_enc_op_init_rc_vbv(struct radeon_uvd_encoder
*enc
)
1053 RADEON_ENC_BEGIN(RENC_UVD_IB_OP_INIT_RC_VBV_BUFFER_LEVEL
);
1058 radeon_uvd_enc_op_speed(struct radeon_uvd_encoder
*enc
)
1060 RADEON_ENC_BEGIN(RENC_UVD_IB_OP_SET_SPEED_ENCODING_MODE
);
1065 begin(struct radeon_uvd_encoder
*enc
, struct pipe_picture_desc
*pic
)
1067 radeon_uvd_enc_session_info(enc
);
1068 enc
->total_task_size
= 0;
1069 radeon_uvd_enc_task_info(enc
, enc
->need_feedback
);
1070 radeon_uvd_enc_op_init(enc
);
1072 radeon_uvd_enc_session_init_hevc(enc
);
1073 radeon_uvd_enc_slice_control_hevc(enc
);
1074 radeon_uvd_enc_spec_misc_hevc(enc
, pic
);
1075 radeon_uvd_enc_deblocking_filter_hevc(enc
, pic
);
1077 radeon_uvd_enc_layer_control(enc
);
1078 radeon_uvd_enc_rc_session_init(enc
, pic
);
1079 radeon_uvd_enc_quality_params(enc
);
1080 radeon_uvd_enc_layer_select(enc
);
1081 radeon_uvd_enc_rc_layer_init(enc
, pic
);
1082 radeon_uvd_enc_layer_select(enc
);
1083 radeon_uvd_enc_rc_per_pic(enc
, pic
);
1084 radeon_uvd_enc_op_init_rc(enc
);
1085 radeon_uvd_enc_op_init_rc_vbv(enc
);
1086 *enc
->p_task_size
= (enc
->total_task_size
);
1090 encode(struct radeon_uvd_encoder
*enc
)
1092 radeon_uvd_enc_session_info(enc
);
1093 enc
->total_task_size
= 0;
1094 radeon_uvd_enc_task_info(enc
, enc
->need_feedback
);
1096 radeon_uvd_enc_nalu_aud_hevc(enc
);
1098 if (enc
->enc_pic
.is_iframe
) {
1099 radeon_uvd_enc_nalu_vps_hevc(enc
);
1100 radeon_uvd_enc_nalu_pps_hevc(enc
);
1101 radeon_uvd_enc_nalu_sps_hevc(enc
);
1103 radeon_uvd_enc_slice_header_hevc(enc
);
1104 radeon_uvd_enc_encode_params_hevc(enc
);
1106 radeon_uvd_enc_ctx(enc
);
1107 radeon_uvd_enc_bitstream(enc
);
1108 radeon_uvd_enc_feedback(enc
);
1109 radeon_uvd_enc_intra_refresh(enc
);
1111 radeon_uvd_enc_op_speed(enc
);
1112 radeon_uvd_enc_op_enc(enc
);
1113 *enc
->p_task_size
= (enc
->total_task_size
);
1117 destroy(struct radeon_uvd_encoder
*enc
)
1119 radeon_uvd_enc_session_info(enc
);
1120 enc
->total_task_size
= 0;
1121 radeon_uvd_enc_task_info(enc
, enc
->need_feedback
);
1122 radeon_uvd_enc_op_close(enc
);
1123 *enc
->p_task_size
= (enc
->total_task_size
);
1127 radeon_uvd_enc_1_1_init(struct radeon_uvd_encoder
*enc
)
1130 enc
->encode
= encode
;
1131 enc
->destroy
= destroy
;