checkStorageBinding function
int
checkStorageBinding(
- StorageBuffer buffer,
- DeviceLimits limits, {
- int offsetInBytes = 0,
- int? sizeInBytes,
Checks a storage binding of buffer from offsetInBytes, sizeInBytes
long (to the end when null), against limits: the range lies inside
the buffer and starts at a multiple of
DeviceLimits.minStorageBufferOffsetAlignment. Answers the size bound.
Throws a RangeError naming the call that is wrong.
Implementation
int checkStorageBinding(
StorageBuffer buffer,
DeviceLimits limits, {
int offsetInBytes = 0,
int? sizeInBytes,
}) {
final size = sizeInBytes ?? buffer.lengthInBytes - offsetInBytes;
if (offsetInBytes < 0 ||
size < 0 ||
offsetInBytes + size > buffer.lengthInBytes) {
throw RangeError(
'bindStorageBuffer: $size bytes from $offsetInBytes leave a buffer of '
'${buffer.lengthInBytes}',
);
}
final alignment = limits.minStorageBufferOffsetAlignment;
if (alignment > 0 && offsetInBytes % alignment != 0) {
throw RangeError(
'bindStorageBuffer: offset $offsetInBytes is not a multiple of '
'minStorageBufferOffsetAlignment ($alignment) on this device',
);
}
return size;
}