|
| 1 | +import { describe, expect, vi } from 'vitest'; |
| 2 | +import { it } from './utils/extendedIt.ts'; |
| 3 | +import tgpu, { d } from '../src/index.ts'; |
| 4 | +import { warnIfOverflow } from '../src/core/pipeline/limitsOverflow.ts'; |
| 5 | + |
| 6 | +describe('warnIfOverflow', () => { |
| 7 | + const limits = { |
| 8 | + maxUniformBuffersPerShaderStage: 2, |
| 9 | + maxStorageBuffersPerShaderStage: 1, |
| 10 | + // missing props may be added as necessary |
| 11 | + } as GPUSupportedLimits; |
| 12 | + |
| 13 | + it('does not warn when no limits are exceeded', () => { |
| 14 | + using consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation( |
| 15 | + () => {}, |
| 16 | + ); |
| 17 | + |
| 18 | + const layout = tgpu.bindGroupLayout({ |
| 19 | + uniform1: { uniform: d.f32 }, |
| 20 | + uniform2: { uniform: d.f32 }, |
| 21 | + storage1: { storage: d.f32 }, |
| 22 | + }); |
| 23 | + |
| 24 | + warnIfOverflow([layout], limits); |
| 25 | + |
| 26 | + expect(consoleWarnSpy).toHaveBeenCalledTimes(0); |
| 27 | + }); |
| 28 | + |
| 29 | + it('warns for uniforms', () => { |
| 30 | + using consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation( |
| 31 | + () => {}, |
| 32 | + ); |
| 33 | + |
| 34 | + const layout = tgpu.bindGroupLayout({ |
| 35 | + uniform1: { uniform: d.f32 }, |
| 36 | + uniform2: { uniform: d.f32 }, |
| 37 | + uniform3: { uniform: d.f32 }, |
| 38 | + }); |
| 39 | + |
| 40 | + warnIfOverflow([layout], limits); |
| 41 | + |
| 42 | + expect(consoleWarnSpy).toHaveBeenCalledWith( |
| 43 | + `Total number of uniform buffers (3) exceeds maxUniformBuffersPerShaderStage (2). Consider: |
| 44 | +1. Grouping some of the uniforms into one using 'd.struct', |
| 45 | +2. Increasing the limit when requesting a device or creating a root.`, |
| 46 | + ); |
| 47 | + }); |
| 48 | + |
| 49 | + it('warns for storages', () => { |
| 50 | + using consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation( |
| 51 | + () => {}, |
| 52 | + ); |
| 53 | + |
| 54 | + const layout = tgpu.bindGroupLayout({ |
| 55 | + storage1: { storage: d.f32 }, |
| 56 | + storage2: { storage: d.f32 }, |
| 57 | + }); |
| 58 | + |
| 59 | + warnIfOverflow([layout], limits); |
| 60 | + |
| 61 | + expect(consoleWarnSpy).toHaveBeenCalledWith( |
| 62 | + `Total number of storage buffers (2) exceeds maxStorageBuffersPerShaderStage (1).`, |
| 63 | + ); |
| 64 | + }); |
| 65 | + |
| 66 | + it('warns when resources are split among layouts', () => { |
| 67 | + using consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation( |
| 68 | + () => {}, |
| 69 | + ); |
| 70 | + |
| 71 | + const layout1 = tgpu.bindGroupLayout({ |
| 72 | + uniform1: { uniform: d.f32 }, |
| 73 | + }); |
| 74 | + |
| 75 | + const layout2 = tgpu.bindGroupLayout({ |
| 76 | + uniform2: { uniform: d.f32 }, |
| 77 | + }); |
| 78 | + |
| 79 | + const layout3 = tgpu.bindGroupLayout({ |
| 80 | + uniform3: { uniform: d.f32 }, |
| 81 | + }); |
| 82 | + |
| 83 | + warnIfOverflow([layout1, layout2, layout3], limits); |
| 84 | + |
| 85 | + expect(consoleWarnSpy).toHaveBeenCalledWith( |
| 86 | + `Total number of uniform buffers (3) exceeds maxUniformBuffersPerShaderStage (2). Consider: |
| 87 | +1. Grouping some of the uniforms into one using 'd.struct', |
| 88 | +2. Increasing the limit when requesting a device or creating a root.`, |
| 89 | + ); |
| 90 | + }); |
| 91 | +}); |
0 commit comments