forge
Explore
Log in

Don't you dare go Hollow

ec-hw: Vulkan decode follows mid-stream size and DPB changes

Browse files at this commit

fc0a0f7ba9dc39e0d98e6785839cfe10fe464828Ahmet Kaan GümüşParent: 42021c7
Flush the previous picture when an SPS arrives, so it is finished against
its own SPS. Rebuild the H.264/H.265 session when the coded size or DPB
size changes (H.265 also on bit depth), flushing pending output first.
AV1 sizes the session from the sequence header maximum.
crates/ec-hw/src/vkdec264.rsmodified+13 -9
@@ -91,6 +91,7 @@ impl VkH264Decoder {
9191 let header = NalHeader::parse(first)?;
9292 match header.unit_type {
9393 NalUnitType::Sps => {
94+ self.finish_picture()?;
9495 let mut rbsp = std::mem::take(&mut self.rbsp);
9596 unescape_rbsp(payload, &mut rbsp);
9697 let sps = Sps::parse(&rbsp);
@@ -233,11 +234,14 @@ impl VkH264Decoder {
233234 }
234235 let slots = (self.dpb.capacity() as u32 + 1).min(MAX_SLOTS);
235236 let (w, h) = (sps.coded_width, sps.coded_height);
236- let (max_width, max_height, slots) = match &self.session {
237- Some(s) if w <= s.max_width && h <= s.max_height && slots <= s.slots => return Ok(()),
238- Some(s) => (w.max(s.max_width), h.max(s.max_height), slots.max(s.slots)),
239- None => (w, h, slots),
240- };
237+ if let Some(s) = &self.session
238+ && s.max_width == w
239+ && s.max_height == h
240+ && slots <= s.slots
241+ {
242+ return Ok(());
243+ }
244+ self.bump(true);
241245 self.current = None;
242246 self.dpb.clear();
243247 self.pics.clear();
@@ -245,8 +249,8 @@ impl VkH264Decoder {
245249 let h264 = H264DecodeSession::new(
246250 &self.gpu,
247251 &H264DecodeConfig {
248- max_width,
249- max_height,
252+ max_width: w,
253+ max_height: h,
250254 max_dpb_slots: slots,
251255 profile_idc: sps.profile_idc,
252256 },
@@ -255,8 +259,8 @@ impl VkH264Decoder {
255259 self.session = Some(Session {
256260 h264: Rc::new(RefCell::new(h264)),
257261 ring,
258- max_width,
259- max_height,
262+ max_width: w,
263+ max_height: h,
260264 slots,
261265 });
262266 self.params_dirty = true;
crates/ec-hw/src/vkdec265.rsmodified+14 -18
@@ -95,6 +95,7 @@ impl VkH265Decoder {
9595 }
9696 }
9797 NalUnitType::Sps => {
98+ self.finish_picture()?;
9899 let sps = Sps::parse(&nal.rbsp())?;
99100 self.dpb.max_reorder = sps.max_num_reorder_pics as usize;
100101 self.dpb.max_dec_pic_buffering = sps.max_dec_pic_buffering_minus1 as usize + 1;
@@ -234,20 +235,15 @@ impl VkH265Decoder {
234235 sps.pic_width_in_luma_samples,
235236 sps.pic_height_in_luma_samples,
236237 );
237- let (max_width, max_height, slots) = match &self.session {
238- Some(s)
239- if s.bit_depth == bit_depth
240- && w <= s.max_width
241- && h <= s.max_height
242- && slots <= s.slots =>
243- {
244- return Ok(());
245- }
246- Some(s) if s.bit_depth == bit_depth => {
247- (w.max(s.max_width), h.max(s.max_height), slots.max(s.slots))
248- }
249- _ => (w, h, slots),
250- };
238+ if let Some(s) = &self.session
239+ && s.bit_depth == bit_depth
240+ && s.max_width == w
241+ && s.max_height == h
242+ && slots <= s.slots
243+ {
244+ return Ok(());
245+ }
246+ self.bump(true);
251247 self.current = None;
252248 self.dpb.pictures.clear();
253249 self.outputs.clear();
@@ -255,8 +251,8 @@ impl VkH265Decoder {
255251 let h265 = H265DecodeSession::new(
256252 &self.gpu,
257253 &H265DecodeConfig {
258- max_width,
259- max_height,
254+ max_width: w,
255+ max_height: h,
260256 max_dpb_slots: slots,
261257 bit_depth,
262258 },
@@ -266,8 +262,8 @@ impl VkH265Decoder {
266262 h265: Rc::new(RefCell::new(h265)),
267263 ring,
268264 bit_depth,
269- max_width,
270- max_height,
265+ max_width: w,
266+ max_height: h,
271267 slots,
272268 });
273269 self.params_dirty = true;
crates/ec-hw/src/vkdec_av1.rsmodified+4 -8
@@ -219,15 +219,11 @@ impl VkAv1Decoder {
219219
220220 fn ensure_session(&mut self, seq: &SequenceHeader, width: u32, height: u32) -> Result<()> {
221221 let bit_depth = seq.color_config.bit_depth;
222+ let width = seq.max_frame_width.max(width);
223+ let height = seq.max_frame_height.max(height);
222224 let mut session = match self.session.take() {
223- Some(s) if s.bit_depth == bit_depth && width <= s.width && height <= s.height => s,
224- old => {
225- let (width, height) = match &old {
226- Some(s) if s.bit_depth == bit_depth => {
227- (width.max(s.width), height.max(s.height))
228- }
229- _ => (width, height),
230- };
225+ Some(s) if s.bit_depth == bit_depth && s.width == width && s.height == height => s,
226+ _ => {
231227 self.refs = RefSlots::new();
232228 let av1 = Av1DecodeSession::new(
233229 &self.gpu,