Merge branch 'worktree-agent-a3c3417b136770f87'
Browse files at this commit4 changed files +45 -12
- crates/ec-hw/src/dec/av1.rs +11 -0
- crates/ec-hw/src/output.rs +7 -3
- crates/ec-hw/src/vkdec_av1.rs +7 -6
- shims/vk-video-ffi/src/av1_decode.rs +20 -3
crates/ec-hw/src/dec/av1.rsmodified+11 -0
| @@ -235,6 +235,17 @@ impl Av1Decoder { | |||
| 235 | 235 | ||
| 236 | fn ensure_session(&mut self, seq: &SequenceHeader, header: &FrameHeader) -> Result<()> { | 236 | fn ensure_session(&mut self, seq: &SequenceHeader, header: &FrameHeader) -> Result<()> { |
| 237 | let bit_depth = seq.color_config.bit_depth; | 237 | let bit_depth = seq.color_config.bit_depth; |
| 238 | + let color = &seq.color_config; | ||
| 239 | + if color.mono_chrome | ||
| 240 | + || bit_depth == 12 | ||
| 241 | + || color.subsampling_x != 1 | ||
| 242 | + || color.subsampling_y != 1 | ||
| 243 | + { | ||
| 244 | + return Err(Error::unsupported( | ||
| 245 | + "AV1 hardware decode", | ||
| 246 | + "only 4:2:0 8- and 10-bit", | ||
| 247 | + )); | ||
| 248 | + } | ||
| 238 | let profile = match (seq.seq_profile, bit_depth) { | 249 | let profile = match (seq.seq_profile, bit_depth) { |
| 239 | (0, _) => Profile::AV1Profile0, | 250 | (0, _) => Profile::AV1Profile0, |
| 240 | (2, _) => Profile::AV1Profile2, | 251 | (2, _) => Profile::AV1Profile2, |
crates/ec-hw/src/output.rsmodified+7 -3
| @@ -282,7 +282,11 @@ impl VkPicture { | |||
| 282 | } | 282 | } |
| 283 | 283 | ||
| 284 | fn read(&self) -> Result<(Vec<u8>, Vec<u8>)> { | 284 | fn read(&self) -> Result<(Vec<u8>, Vec<u8>)> { |
| 285 | - self.surfaces.nv12(self.slot.index, self.width, self.height) | 285 | + self.surfaces.nv12( |
| 286 | + self.slot.index, | ||
| 287 | + self.width.next_multiple_of(2), | ||
| 288 | + self.height.next_multiple_of(2), | ||
| 289 | + ) | ||
| 286 | } | 290 | } |
| 287 | 291 | ||
| 288 | fn i420(&self) -> Result<I420> { | 292 | fn i420(&self) -> Result<I420> { |
| @@ -291,7 +295,7 @@ impl VkPicture { | |||
| 291 | self.bit_depth, | 295 | self.bit_depth, |
| 292 | &y, | 296 | &y, |
| 293 | &uv, | 297 | &uv, |
| 294 | - self.width as usize, | 298 | + self.width.next_multiple_of(2) as usize, |
| 295 | (0, 0), | 299 | (0, 0), |
| 296 | (self.width, self.height), | 300 | (self.width, self.height), |
| 297 | )?; | 301 | )?; |
| @@ -307,7 +311,7 @@ impl VkPicture { | |||
| 307 | self.bit_depth, | 311 | self.bit_depth, |
| 308 | &y, | 312 | &y, |
| 309 | &uv, | 313 | &uv, |
| 310 | - self.width as usize, | 314 | + self.width.next_multiple_of(2) as usize, |
| 311 | (0, 0), | 315 | (0, 0), |
| 312 | (self.width, self.height), | 316 | (self.width, self.height), |
| 313 | )?; | 317 | )?; |
crates/ec-hw/src/vkdec_av1.rsmodified+7 -6
| @@ -135,7 +135,7 @@ impl VkAv1Decoder { | |||
| 135 | .sequence_header() | 135 | .sequence_header() |
| 136 | .cloned() | 136 | .cloned() |
| 137 | .ok_or_else(|| Error::config("AV1 frame before any sequence header"))?; | 137 | .ok_or_else(|| Error::config("AV1 frame before any sequence header"))?; |
| 138 | - check_supported(&seq, header)?; | 138 | + check_supported(&seq)?; |
| 139 | let (width, height) = (header.upscaled_width, header.frame_height); | 139 | let (width, height) = (header.upscaled_width, header.frame_height); |
| 140 | self.ensure_session(&seq, width, height)?; | 140 | self.ensure_session(&seq, width, height)?; |
| 141 | 141 | ||
| @@ -182,7 +182,10 @@ impl VkAv1Decoder { | |||
| 182 | .ring | 182 | .ring |
| 183 | .borrow_mut() | 183 | .borrow_mut() |
| 184 | .take(|| Ok(session.av1.borrow_mut().add_ring_slot()?))?; | 184 | .take(|| Ok(session.av1.borrow_mut().add_ring_slot()?))?; |
| 185 | - session.av1.borrow_mut().store_output(slot.index(), (0, 0, width, height))?; | 185 | + session.av1.borrow_mut().store_output( |
| 186 | + slot.index(), | ||
| 187 | + (0, 0, width.next_multiple_of(2), height.next_multiple_of(2)), | ||
| 188 | + )?; | ||
| 186 | let codes = Tags::from_codes(u64::from(seq.color_config.matrix_coefficients), 0, 0); | 189 | let codes = Tags::from_codes(u64::from(seq.color_config.matrix_coefficients), 0, 0); |
| 187 | let matrix = ColorDescription::resolve(Tags::default(), codes, height).matrix; | 190 | let matrix = ColorDescription::resolve(Tags::default(), codes, height).matrix; |
| 188 | let decoded = VkPicture::new( | 191 | let decoded = VkPicture::new( |
| @@ -201,6 +204,7 @@ impl VkAv1Decoder { | |||
| 201 | sign_bias: sign_bias(&header.ref_frame_sign_bias), | 204 | sign_bias: sign_bias(&header.ref_frame_sign_bias), |
| 202 | disable_frame_end_update_cdf: header.disable_frame_end_update_cdf, | 205 | disable_frame_end_update_cdf: header.disable_frame_end_update_cdf, |
| 203 | segmentation_enabled: header.segmentation.enabled, | 206 | segmentation_enabled: header.segmentation.enabled, |
| 207 | + extent: (width, height), | ||
| 204 | }; | 208 | }; |
| 205 | if header.show_frame { | 209 | if header.show_frame { |
| 206 | let shown = decoded.with_grain(&header.film_grain, &seq); | 210 | let shown = decoded.with_grain(&header.film_grain, &seq); |
| @@ -263,7 +267,7 @@ impl VkAv1Decoder { | |||
| 263 | } | 267 | } |
| 264 | } | 268 | } |
| 265 | 269 | ||
| 266 | -fn check_supported(seq: &SequenceHeader, header: &FrameHeader) -> Result<()> { | 270 | +fn check_supported(seq: &SequenceHeader) -> Result<()> { |
| 267 | let c = &seq.color_config; | 271 | let c = &seq.color_config; |
| 268 | if seq.seq_profile != 0 | 272 | if seq.seq_profile != 0 |
| 269 | || !matches!(c.bit_depth, 8 | 10) | 273 | || !matches!(c.bit_depth, 8 | 10) |
| @@ -276,9 +280,6 @@ fn check_supported(seq: &SequenceHeader, header: &FrameHeader) -> Result<()> { | |||
| 276 | "only Main 8- and 10-bit 4:2:0", | 280 | "only Main 8- and 10-bit 4:2:0", |
| 277 | )); | 281 | )); |
| 278 | } | 282 | } |
| 279 | - if header.upscaled_width % 2 != 0 || header.frame_height % 2 != 0 { | ||
| 280 | - return Err(Error::unsupported("Vulkan AV1 decode", "odd frame size")); | ||
| 281 | - } | ||
| 282 | Ok(()) | 283 | Ok(()) |
| 283 | } | 284 | } |
| 284 | 285 | ||
shims/vk-video-ffi/src/av1_decode.rsmodified+20 -3
| @@ -438,6 +438,8 @@ pub struct Av1RefSlot { | |||
| 438 | pub disable_frame_end_update_cdf: bool, | 438 | pub disable_frame_end_update_cdf: bool, |
| 439 | /// segmentation_enabled of the picture in the slot. | 439 | /// segmentation_enabled of the picture in the slot. |
| 440 | pub segmentation_enabled: bool, | 440 | pub segmentation_enabled: bool, |
| 441 | + /// Upscaled width and frame height of the picture in the slot. | ||
| 442 | + pub extent: (u32, u32), | ||
| 441 | } | 443 | } |
| 442 | 444 | ||
| 443 | /// One frame to decode, with the tile data as one buffer. | 445 | /// One frame to decode, with the tile data as one buffer. |
| @@ -728,7 +730,18 @@ impl Av1DecodeSession { | |||
| 728 | .dec | 730 | .dec |
| 729 | .dpb | 731 | .dpb |
| 730 | .iter() | 732 | .iter() |
| 731 | - .map(|i| picture_resource(i.view, extent)) | 733 | + .enumerate() |
| 734 | + .map(|(slot, i)| { | ||
| 735 | + let size = pic | ||
| 736 | + .refs | ||
| 737 | + .iter() | ||
| 738 | + .find(|r| r.slot as usize == slot) | ||
| 739 | + .map_or(extent, |r| vk::Extent2D { | ||
| 740 | + width: r.extent.0, | ||
| 741 | + height: r.extent.1, | ||
| 742 | + }); | ||
| 743 | + picture_resource(i.view, size) | ||
| 744 | + }) | ||
| 732 | .collect(); | 745 | .collect(); |
| 733 | 746 | ||
| 734 | let setup_std = ref_info( | 747 | let setup_std = ref_info( |
| @@ -1063,14 +1076,18 @@ fn std_loop_filter(l: &Av1LoopFilter) -> vk::video::StdVideoAV1LoopFilter { | |||
| 1063 | } | 1076 | } |
| 1064 | } | 1077 | } |
| 1065 | 1078 | ||
| 1079 | +fn raw_sec_strength(s: [u8; 8]) -> [u8; 8] { | ||
| 1080 | + s.map(|v| if v == 4 { 3 } else { v }) | ||
| 1081 | +} | ||
| 1082 | + | ||
| 1066 | fn std_cdef(c: &Av1Cdef) -> vk::video::StdVideoAV1CDEF { | 1083 | fn std_cdef(c: &Av1Cdef) -> vk::video::StdVideoAV1CDEF { |
| 1067 | vk::video::StdVideoAV1CDEF { | 1084 | vk::video::StdVideoAV1CDEF { |
| 1068 | cdef_damping_minus_3: c.damping_minus_3, | 1085 | cdef_damping_minus_3: c.damping_minus_3, |
| 1069 | cdef_bits: c.bits, | 1086 | cdef_bits: c.bits, |
| 1070 | cdef_y_pri_strength: c.y_pri, | 1087 | cdef_y_pri_strength: c.y_pri, |
| 1071 | - cdef_y_sec_strength: c.y_sec, | 1088 | + cdef_y_sec_strength: raw_sec_strength(c.y_sec), |
| 1072 | cdef_uv_pri_strength: c.uv_pri, | 1089 | cdef_uv_pri_strength: c.uv_pri, |
| 1073 | - cdef_uv_sec_strength: c.uv_sec, | 1090 | + cdef_uv_sec_strength: raw_sec_strength(c.uv_sec), |
| 1074 | } | 1091 | } |
| 1075 | } | 1092 | } |
| 1076 | 1093 | ||