rt(mtl): don't allow buffers of size 0

This commit is contained in:
chyyran 2024-02-15 19:55:22 -05:00 committed by Ronny Chan
parent c0ecae844c
commit efdfd56e0e

View file

@ -24,7 +24,7 @@ impl AsRef<ProtocolObject<dyn MTLBuffer>> for MetalBuffer {
impl MetalBuffer {
pub fn new(
device: &ProtocolObject<dyn MTLDevice>,
size: usize,
mut size: usize,
label: &str,
) -> error::Result<Self> {
let storage_mode = if cfg!(all(target_arch = "aarch64", target_vendor = "apple")) {
@ -33,6 +33,11 @@ impl MetalBuffer {
MTLResourceStorageModeManaged
};
// Can't create buffer of size 0.
if size == 0 {
size = 16;
};
let buffer = device
.newBufferWithLength_options(size, storage_mode)
.ok_or(FilterChainError::BufferError)?;