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 {
858 let bitstream = vs.buffer(858 let bitstream = vs.buffer(
859 bitstream_len,859 bitstream_len,
860 vk::BufferUsageFlags::VIDEO_ENCODE_DST_KHR,860 vk::BufferUsageFlags::VIDEO_ENCODE_DST_KHR,
861- &[vk::MemoryPropertyFlags::HOST_VISIBLE | vk::MemoryPropertyFlags::HOST_COHERENT],861+ &HOST_READBACK,
862 Some(&mut list),862 Some(&mut list),
863 )?;863 )?;
864 Ok(Slot {864 Ok(Slot {
@@ -1419,12 +1419,8 @@ impl Encoder {
1419 "encoded size exceeds bitstream buffer".into(),1419 "encoded size exceeds bitstream buffer".into(),
1420 ));1420 ));
1421 }1421 }
1422- let ptr = self.slots[k]1422+ let all = self.slots[k].bitstream.bytes(self.vs.gpu.device(), offset + size)?;
1423- .bitstream1423+ Ok(all[offset..].to_vec())
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())
1428 }1424 }
1429 }1425 }
1430 1426