WebGPUBufferUtils.js 665 B

123456789101112131415161718192021222324252627282930313233
  1. import { GPUChunkSize } from './constants.js';
  2. function getFloatLength( floatLength ) {
  3. // ensure chunk size alignment (STD140 layout)
  4. return floatLength + ( ( GPUChunkSize - ( floatLength % GPUChunkSize ) ) % GPUChunkSize );
  5. }
  6. function getVectorLength( count, vectorLength = 4 ) {
  7. const strideLength = getStrideLength( vectorLength );
  8. const floatLength = strideLength * count;
  9. return getFloatLength( floatLength );
  10. }
  11. function getStrideLength( vectorLength ) {
  12. const strideLength = 4;
  13. return vectorLength + ( ( strideLength - ( vectorLength % strideLength ) ) % strideLength );
  14. }
  15. export {
  16. getFloatLength,
  17. getVectorLength,
  18. getStrideLength
  19. };