checkDispatch function

void checkDispatch(
  1. DeviceLimits limits,
  2. int x,
  3. int y,
  4. int z,
)

Checks a dispatch of x × y × z workgroups against limits: each count at least zero and at most DeviceLimits.maxComputeWorkgroupsPerDimension.

Throws a RangeError naming the count that is wrong.

Implementation

void checkDispatch(DeviceLimits limits, int x, int y, int z) {
  final most = limits.maxComputeWorkgroupsPerDimension;
  for (final (axis, n) in <(String, int)>[('x', x), ('y', y), ('z', z)]) {
    if (n < 0 || n > most) {
      throw RangeError(
        'dispatch: $n workgroups along $axis, and this device takes 0 to '
        '$most (maxComputeWorkgroupsPerDimension)',
      );
    }
  }
}