forge
Explore
Log in

Don't you dare go Hollow

vk-video-ffi: read encoded bitstream from cached host memory

Browse files at this commit

e22e714c5877dfcb05ef91748250c29a40ad3ff8Ahmet Kaan GümüşParent: d81f9eb
The encode bitstream buffer was HOST_COHERENT only, so the per-frame
copy-out ran at uncached speed: AV1 (~187 KB/frame) spent ~0.68 ms per
frame in the readback, which serialized on the CPU. Prefer HOST_CACHED
with an invalidate on read, matching the decode readback.
shims/vk-video-ffi/src/session.rsmodified+3 -7
@@ -858,7 +858,7 @@ impl Slot {
858858 let bitstream = vs.buffer(
859859 bitstream_len,
860860 vk::BufferUsageFlags::VIDEO_ENCODE_DST_KHR,
861- &[vk::MemoryPropertyFlags::HOST_VISIBLE | vk::MemoryPropertyFlags::HOST_COHERENT],
861+ &HOST_READBACK,
862862 Some(&mut list),
863863 )?;
864864 Ok(Slot {
@@ -1419,12 +1419,8 @@ impl Encoder {
14191419 "encoded size exceeds bitstream buffer".into(),
14201420 ));
14211421 }
1422- let ptr = self.slots[k]
1423- .bitstream
1424- .ptr
1425- .ok_or_else(|| Error::Invalid("bitstream buffer not mapped".into()))?;
1426- let bytes = unsafe { std::slice::from_raw_parts(ptr.add(offset), size) };
1427- Ok(bytes.to_vec())
1422+ let all = self.slots[k].bitstream.bytes(self.vs.gpu.device(), offset + size)?;
1423+ Ok(all[offset..].to_vec())
14281424 }
14291425 }
14301426