checkFeatures method
Throws UnsupportedCapabilityException when this buffer needs a
feature features lacks: a storage usage (compute or
renderStageStorage, either one), an indirect usage (indirectDraw or
indirectDispatch, either one) or general buffers at all (buffers),
in that order.
Where either of two features takes a usage, the refusal names the one
the buffer was shaped for: the copy usages of
BufferUsage.standardStorage are a compute pass's buffer, a bare
storage usage a render stage's. For a backend's createBuffer, so
that a usage a minor adds with its feature is refused by a backend
written before it rather than ignored. backend names the backend as
a person would.
Implementation
void checkFeatures(DeviceFeatures features, {required String backend}) {
// The usages first: a storage or indirect buffer is refused by what it
// was made for, which says more than `buffers` would.
if (usage.contains(BufferUsage.storage) &&
!features.has(DeviceFeature.compute) &&
!features.has(DeviceFeature.renderStageStorage)) {
features.require(
usage.contains(BufferUsage.standardStorage)
? DeviceFeature.compute
: DeviceFeature.renderStageStorage,
backend: backend,
reason: 'a storage buffer needs compute or render-stage storage',
);
}
if (usage.contains(BufferUsage.indirect) &&
!features.has(DeviceFeature.indirectDraw) &&
!features.has(DeviceFeature.indirectDispatch)) {
features.require(
DeviceFeature.indirectDraw,
backend: backend,
reason: 'an indirect buffer needs indirect draws or dispatches',
);
}
features.require(DeviceFeature.buffers, backend: backend);
}