diff options
Diffstat (limited to 'src/gallium/drivers')
-rw-r--r-- | src/gallium/drivers/radeon/radeon_vcn_enc.c | 122 | ||||
-rw-r--r-- | src/gallium/drivers/radeon/radeon_vcn_enc.h | 20 | ||||
-rw-r--r-- | src/gallium/drivers/radeon/radeon_vcn_enc_1_2.c | 122 |
3 files changed, 142 insertions, 122 deletions
diff --git a/src/gallium/drivers/radeon/radeon_vcn_enc.c b/src/gallium/drivers/radeon/radeon_vcn_enc.c index 868f9473126..5eb5f406882 100644 --- a/src/gallium/drivers/radeon/radeon_vcn_enc.c +++ b/src/gallium/drivers/radeon/radeon_vcn_enc.c @@ -38,6 +38,8 @@ #include "radeon_video.h" #include "radeon_vcn_enc.h" +static const unsigned index_to_shifts[4] = {24, 16, 8, 0}; + static void radeon_vcn_enc_get_param(struct radeon_encoder *enc, struct pipe_picture_desc *picture) { if (u_reduce_video_profile(picture->profile) == PIPE_VIDEO_FORMAT_MPEG4_AVC) { @@ -359,3 +361,123 @@ void radeon_enc_add_buffer(struct radeon_encoder *enc, struct pb_buffer *buf, RADEON_ENC_CS(addr >> 32); RADEON_ENC_CS(addr); } + +void radeon_enc_set_emulation_prevention(struct radeon_encoder *enc, bool set) +{ + if (set != enc->emulation_prevention) { + enc->emulation_prevention = set; + enc->num_zeros = 0; + } +} + +void radeon_enc_output_one_byte(struct radeon_encoder *enc, unsigned char byte) +{ + if (enc->byte_index == 0) + enc->cs->current.buf[enc->cs->current.cdw] = 0; + enc->cs->current.buf[enc->cs->current.cdw] |= ((unsigned int)(byte) << index_to_shifts[enc->byte_index]); + enc->byte_index++; + + if (enc->byte_index >= 4) { + enc->byte_index = 0; + enc->cs->current.cdw++; + } +} + +void radeon_enc_emulation_prevention(struct radeon_encoder *enc, unsigned char byte) +{ + if(enc->emulation_prevention) { + if((enc->num_zeros >= 2) && ((byte == 0x00) || (byte == 0x01) || (byte == 0x03))) { + radeon_enc_output_one_byte(enc, 0x03); + enc->bits_output += 8; + enc->num_zeros = 0; + } + enc->num_zeros = (byte == 0 ? (enc->num_zeros + 1) : 0); + } +} + +void radeon_enc_code_fixed_bits(struct radeon_encoder *enc, unsigned int value, unsigned int num_bits) +{ + unsigned int bits_to_pack = 0; + + while(num_bits > 0) { + unsigned int value_to_pack = value & (0xffffffff >> (32 - num_bits)); + bits_to_pack = num_bits > (32 - enc->bits_in_shifter) ? (32 - enc->bits_in_shifter) : num_bits; + + if (bits_to_pack < num_bits) + value_to_pack = value_to_pack >> (num_bits - bits_to_pack); + + enc->shifter |= value_to_pack << (32 - enc->bits_in_shifter - bits_to_pack); + num_bits -= bits_to_pack; + enc->bits_in_shifter += bits_to_pack; + + while(enc->bits_in_shifter >= 8) { + unsigned char output_byte = (unsigned char)(enc->shifter >> 24); + enc->shifter <<= 8; + radeon_enc_emulation_prevention(enc, output_byte); + radeon_enc_output_one_byte(enc, output_byte); + enc->bits_in_shifter -= 8; + enc->bits_output += 8; + } + } +} + +void radeon_enc_reset(struct radeon_encoder *enc) +{ + enc->emulation_prevention = false; + enc->shifter = 0; + enc->bits_in_shifter = 0; + enc->bits_output = 0; + enc->num_zeros = 0; + enc->byte_index = 0; +} + +void radeon_enc_byte_align(struct radeon_encoder *enc) +{ + unsigned int num_padding_zeros = (32 - enc->bits_in_shifter) % 8; + + if (num_padding_zeros > 0) + radeon_enc_code_fixed_bits(enc, 0, num_padding_zeros); +} + +void radeon_enc_flush_headers(struct radeon_encoder *enc) +{ + if (enc->bits_in_shifter != 0) { + unsigned char output_byte = (unsigned char)(enc->shifter >> 24); + radeon_enc_emulation_prevention(enc, output_byte); + radeon_enc_output_one_byte(enc, output_byte); + enc->bits_output += enc->bits_in_shifter; + enc->shifter = 0; + enc->bits_in_shifter = 0; + enc->num_zeros = 0; + } + + if (enc->byte_index > 0) { + enc->cs->current.cdw++; + enc->byte_index = 0; + } +} + +void radeon_enc_code_ue(struct radeon_encoder *enc, unsigned int value) +{ + int x = -1; + unsigned int ue_code = value + 1; + value += 1; + + while (value) { + value = (value >> 1); + x += 1; + } + + unsigned int ue_length = (x << 1) + 1; + radeon_enc_code_fixed_bits(enc, ue_code, ue_length); +} + +void radeon_enc_code_se(struct radeon_encoder *enc, int value) +{ + unsigned int v = 0; + + if (value != 0) + v = (value < 0 ? ((unsigned int)(0 - value) << 1) : (((unsigned int)(value) << 1) - 1)); + + radeon_enc_code_ue(enc, v); +} diff --git a/src/gallium/drivers/radeon/radeon_vcn_enc.h b/src/gallium/drivers/radeon/radeon_vcn_enc.h index 5fa516167d9..15f12c66155 100644 --- a/src/gallium/drivers/radeon/radeon_vcn_enc.h +++ b/src/gallium/drivers/radeon/radeon_vcn_enc.h @@ -500,6 +500,26 @@ void radeon_enc_add_buffer(struct radeon_encoder *enc, struct pb_buffer *buf, enum radeon_bo_usage usage, enum radeon_bo_domain domain, signed offset); +void radeon_enc_set_emulation_prevention(struct radeon_encoder *enc, bool set); + +void radeon_enc_output_one_byte(struct radeon_encoder *enc, unsigned char byte); + +void radeon_enc_emulation_prevention(struct radeon_encoder *enc, + unsigned char byte); + +void radeon_enc_code_fixed_bits(struct radeon_encoder *enc, unsigned int value, + unsigned int num_bits); + +void radeon_enc_reset(struct radeon_encoder *enc); + +void radeon_enc_byte_align(struct radeon_encoder *enc); + +void radeon_enc_flush_headers(struct radeon_encoder *enc); + +void radeon_enc_code_ue(struct radeon_encoder *enc, unsigned int value); + +void radeon_enc_code_se(struct radeon_encoder *enc, int value); + void radeon_enc_1_2_init(struct radeon_encoder *enc); #endif // _RADEON_VCN_ENC_H diff --git a/src/gallium/drivers/radeon/radeon_vcn_enc_1_2.c b/src/gallium/drivers/radeon/radeon_vcn_enc_1_2.c index 75082092ca3..6efb10d96fc 100644 --- a/src/gallium/drivers/radeon/radeon_vcn_enc_1_2.c +++ b/src/gallium/drivers/radeon/radeon_vcn_enc_1_2.c @@ -35,128 +35,6 @@ #include "radeon_video.h" #include "radeon_vcn_enc.h" -static const unsigned index_to_shifts[4] = {24, 16, 8, 0}; - -static void radeon_enc_set_emulation_prevention(struct radeon_encoder *enc, bool set) -{ - if (set != enc->emulation_prevention) { - enc->emulation_prevention = set; - enc->num_zeros = 0; - } -} - -static void radeon_enc_output_one_byte(struct radeon_encoder *enc, unsigned char byte) -{ - if (enc->byte_index == 0) - enc->cs->current.buf[enc->cs->current.cdw] = 0; - enc->cs->current.buf[enc->cs->current.cdw] |= ((unsigned int)(byte) << index_to_shifts[enc->byte_index]); - enc->byte_index++; - - if (enc->byte_index >= 4) { - enc->byte_index = 0; - enc->cs->current.cdw++; - } -} - -static void radeon_enc_emulation_prevention(struct radeon_encoder *enc, unsigned char byte) -{ - if(enc->emulation_prevention) { - if((enc->num_zeros >= 2) && ((byte == 0x00) || (byte == 0x01) || (byte == 0x03))) { - radeon_enc_output_one_byte(enc, 0x03); - enc->bits_output += 8; - enc->num_zeros = 0; - } - enc->num_zeros = (byte == 0 ? (enc->num_zeros + 1) : 0); - } -} - -static void radeon_enc_code_fixed_bits(struct radeon_encoder *enc, unsigned int value, unsigned int num_bits) -{ - unsigned int bits_to_pack = 0; - - while(num_bits > 0) { - unsigned int value_to_pack = value & (0xffffffff >> (32 - num_bits)); - bits_to_pack = num_bits > (32 - enc->bits_in_shifter) ? (32 - enc->bits_in_shifter) : num_bits; - - if (bits_to_pack < num_bits) - value_to_pack = value_to_pack >> (num_bits - bits_to_pack); - - enc->shifter |= value_to_pack << (32 - enc->bits_in_shifter - bits_to_pack); - num_bits -= bits_to_pack; - enc->bits_in_shifter += bits_to_pack; - - while(enc->bits_in_shifter >= 8) { - unsigned char output_byte = (unsigned char)(enc->shifter >> 24); - enc->shifter <<= 8; - radeon_enc_emulation_prevention(enc, output_byte); - radeon_enc_output_one_byte(enc, output_byte); - enc->bits_in_shifter -= 8; - enc->bits_output += 8; - } - } -} - -static void radeon_enc_reset(struct radeon_encoder *enc) -{ - enc->emulation_prevention = false; - enc->shifter = 0; - enc->bits_in_shifter = 0; - enc->bits_output = 0; - enc->num_zeros = 0; - enc->byte_index = 0; -} - -static void radeon_enc_byte_align(struct radeon_encoder *enc) -{ - unsigned int num_padding_zeros = (32 - enc->bits_in_shifter) % 8; - - if (num_padding_zeros > 0) - radeon_enc_code_fixed_bits(enc, 0, num_padding_zeros); -} - -static void radeon_enc_flush_headers(struct radeon_encoder *enc) -{ - if (enc->bits_in_shifter != 0) { - unsigned char output_byte = (unsigned char)(enc->shifter >> 24); - radeon_enc_emulation_prevention(enc, output_byte); - radeon_enc_output_one_byte(enc, output_byte); - enc->bits_output += enc->bits_in_shifter; - enc->shifter = 0; - enc->bits_in_shifter = 0; - enc->num_zeros = 0; - } - - if (enc->byte_index > 0) { - enc->cs->current.cdw++; - enc->byte_index = 0; - } -} - -static void radeon_enc_code_ue(struct radeon_encoder *enc, unsigned int value) -{ - int x = -1; - unsigned int ue_code = value + 1; - value += 1; - - while (value) { - value = (value >> 1); - x += 1; - } - - unsigned int ue_length = (x << 1) + 1; - radeon_enc_code_fixed_bits(enc, ue_code, ue_length); -} - -static void radeon_enc_code_se(struct radeon_encoder *enc, int value) -{ - unsigned int v = 0; - - if (value != 0) - v = (value < 0 ? ((unsigned int)(0 - value) << 1) : (((unsigned int)(value) << 1) - 1)); - - radeon_enc_code_ue(enc, v); -} - static void radeon_enc_session_info(struct radeon_encoder *enc) { unsigned int interface_version = ((RENCODE_FW_INTERFACE_MAJOR_VERSION << RENCODE_IF_MAJOR_VERSION_SHIFT) | |