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 {
91 let header = NalHeader::parse(first)?;91 let header = NalHeader::parse(first)?;
92 match header.unit_type {92 match header.unit_type {
93 NalUnitType::Sps => {93 NalUnitType::Sps => {
94+ self.finish_picture()?;
94 let mut rbsp = std::mem::take(&mut self.rbsp);95 let mut rbsp = std::mem::take(&mut self.rbsp);
95 unescape_rbsp(payload, &mut rbsp);96 unescape_rbsp(payload, &mut rbsp);
96 let sps = Sps::parse(&rbsp);97 let sps = Sps::parse(&rbsp);
@@ -233,11 +234,14 @@ impl VkH264Decoder {
233 }234 }
234 let slots = (self.dpb.capacity() as u32 + 1).min(MAX_SLOTS);235 let slots = (self.dpb.capacity() as u32 + 1).min(MAX_SLOTS);
235 let (w, h) = (sps.coded_width, sps.coded_height);236 let (w, h) = (sps.coded_width, sps.coded_height);
236- let (max_width, max_height, slots) = match &self.session {237+ if let Some(s) = &self.session
237- Some(s) if w <= s.max_width && h <= s.max_height && slots <= s.slots => return Ok(()),238+ && s.max_width == w
238- Some(s) => (w.max(s.max_width), h.max(s.max_height), slots.max(s.slots)),239+ && s.max_height == h
239- None => (w, h, slots),240+ && slots <= s.slots
240- };241+ {
242+ return Ok(());
243+ }
244+ self.bump(true);
241 self.current = None;245 self.current = None;
242 self.dpb.clear();246 self.dpb.clear();
243 self.pics.clear();247 self.pics.clear();
@@ -245,8 +249,8 @@ impl VkH264Decoder {
245 let h264 = H264DecodeSession::new(249 let h264 = H264DecodeSession::new(
246 &self.gpu,250 &self.gpu,
247 &H264DecodeConfig {251 &H264DecodeConfig {
248- max_width,252+ max_width: w,
249- max_height,253+ max_height: h,
250 max_dpb_slots: slots,254 max_dpb_slots: slots,
251 profile_idc: sps.profile_idc,255 profile_idc: sps.profile_idc,
252 },256 },
@@ -255,8 +259,8 @@ impl VkH264Decoder {
255 self.session = Some(Session {259 self.session = Some(Session {
256 h264: Rc::new(RefCell::new(h264)),260 h264: Rc::new(RefCell::new(h264)),
257 ring,261 ring,
258- max_width,262+ max_width: w,
259- max_height,263+ max_height: h,
260 slots,264 slots,
261 });265 });
262 self.params_dirty = true;266 self.params_dirty = true;
crates/ec-hw/src/vkdec265.rsmodified+11 -15
@@ -95,6 +95,7 @@ impl VkH265Decoder {
95 }95 }
96 }96 }
97 NalUnitType::Sps => {97 NalUnitType::Sps => {
98+ self.finish_picture()?;
98 let sps = Sps::parse(&nal.rbsp())?;99 let sps = Sps::parse(&nal.rbsp())?;
99 self.dpb.max_reorder = sps.max_num_reorder_pics as usize;100 self.dpb.max_reorder = sps.max_num_reorder_pics as usize;
100 self.dpb.max_dec_pic_buffering = sps.max_dec_pic_buffering_minus1 as usize + 1;101 self.dpb.max_dec_pic_buffering = sps.max_dec_pic_buffering_minus1 as usize + 1;
@@ -234,20 +235,15 @@ impl VkH265Decoder {
234 sps.pic_width_in_luma_samples,235 sps.pic_width_in_luma_samples,
235 sps.pic_height_in_luma_samples,236 sps.pic_height_in_luma_samples,
236 );237 );
237- let (max_width, max_height, slots) = match &self.session {238+ if let Some(s) = &self.session
238- Some(s)239+ && s.bit_depth == bit_depth
239- if s.bit_depth == bit_depth240+ && s.max_width == w
240- && w <= s.max_width241+ && s.max_height == h
241- && h <= s.max_height242+ && slots <= s.slots
242- && slots <= s.slots =>
243 {243 {
244 return Ok(());244 return Ok(());
245 }245 }
246- Some(s) if s.bit_depth == bit_depth => {246+ self.bump(true);
247- (w.max(s.max_width), h.max(s.max_height), slots.max(s.slots))
248- }
249- _ => (w, h, slots),
250- };
251 self.current = None;247 self.current = None;
252 self.dpb.pictures.clear();248 self.dpb.pictures.clear();
253 self.outputs.clear();249 self.outputs.clear();
@@ -255,8 +251,8 @@ impl VkH265Decoder {
255 let h265 = H265DecodeSession::new(251 let h265 = H265DecodeSession::new(
256 &self.gpu,252 &self.gpu,
257 &H265DecodeConfig {253 &H265DecodeConfig {
258- max_width,254+ max_width: w,
259- max_height,255+ max_height: h,
260 max_dpb_slots: slots,256 max_dpb_slots: slots,
261 bit_depth,257 bit_depth,
262 },258 },
@@ -266,8 +262,8 @@ impl VkH265Decoder {
266 h265: Rc::new(RefCell::new(h265)),262 h265: Rc::new(RefCell::new(h265)),
267 ring,263 ring,
268 bit_depth,264 bit_depth,
269- max_width,265+ max_width: w,
270- max_height,266+ max_height: h,
271 slots,267 slots,
272 });268 });
273 self.params_dirty = true;269 self.params_dirty = true;
crates/ec-hw/src/vkdec_av1.rsmodified+4 -8
@@ -219,15 +219,11 @@ impl VkAv1Decoder {
219 219
220 fn ensure_session(&mut self, seq: &SequenceHeader, width: u32, height: u32) -> Result<()> {220 fn ensure_session(&mut self, seq: &SequenceHeader, width: u32, height: u32) -> Result<()> {
221 let bit_depth = seq.color_config.bit_depth;221 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);
222 let mut session = match self.session.take() {224 let mut session = match self.session.take() {
223- Some(s) if s.bit_depth == bit_depth && width <= s.width && height <= s.height => s,225+ Some(s) if s.bit_depth == bit_depth && s.width == width && s.height == height => s,
224- old => {226+ _ => {
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- };
231 self.refs = RefSlots::new();227 self.refs = RefSlots::new();
232 let av1 = Av1DecodeSession::new(228 let av1 = Av1DecodeSession::new(
233 &self.gpu,229 &self.gpu,