|
| 1 | +export const description = ` |
| 2 | +Validation tests for the 'texture-component-swizzle' feature. |
| 3 | +
|
| 4 | +Test that: |
| 5 | +* when the feature is off, swizzling is not allowed, even the identity swizzle. |
| 6 | +* swizzling is not allowed on textures with usage STORAGE_BINDING nor RENDER_ATTACHMENT |
| 7 | + except the identity swizzle. |
| 8 | +`; |
| 9 | + |
| 10 | +import { makeTestGroup } from '../../../../../common/framework/test_group.js'; |
| 11 | +import { GPUConst } from '../../../../constants.js'; |
| 12 | +import { UniqueFeaturesOrLimitsGPUTest } from '../../../../gpu_test.js'; |
| 13 | + |
| 14 | +import { |
| 15 | + isIdentitySwizzle, |
| 16 | + kSwizzleTests, |
| 17 | + swizzleSpecToGPUTextureComponentSwizzle, |
| 18 | +} from './texture_component_swizzle_utils.js'; |
| 19 | + |
| 20 | +export const g = makeTestGroup(UniqueFeaturesOrLimitsGPUTest); |
| 21 | + |
| 22 | +g.test('no_swizzle') |
| 23 | + .desc( |
| 24 | + ` |
| 25 | + Test that if texture-component-swizzle is not enabled, having a swizzle property generates a validation error. |
| 26 | + ` |
| 27 | + ) |
| 28 | + .fn(t => { |
| 29 | + const texture = t.createTextureTracked({ |
| 30 | + format: 'rgba8unorm', |
| 31 | + size: [1], |
| 32 | + usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.TEXTURE_BINDING, |
| 33 | + }); |
| 34 | + t.expectValidationError(() => { |
| 35 | + texture.createView({ swizzle: {} }); |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | +g.test('no_render_nor_storage') |
| 40 | + .desc( |
| 41 | + ` |
| 42 | + Test that setting the swizzle on the texture with RENDER_ATTACHMENT or STORAGE_BINDING usage works |
| 43 | + if the swizzle is the identity but generates a validation error otherwise. |
| 44 | + ` |
| 45 | + ) |
| 46 | + .params(u => |
| 47 | + u |
| 48 | + .combine('usage', [ |
| 49 | + GPUConst.TextureUsage.COPY_SRC, |
| 50 | + GPUConst.TextureUsage.COPY_DST, |
| 51 | + GPUConst.TextureUsage.TEXTURE_BINDING, |
| 52 | + GPUConst.TextureUsage.RENDER_ATTACHMENT, |
| 53 | + GPUConst.TextureUsage.STORAGE_BINDING, |
| 54 | + ] as const) |
| 55 | + .beginSubcases() |
| 56 | + .combine('swizzleSpec', kSwizzleTests) |
| 57 | + ) |
| 58 | + .beforeAllSubcases(t => { |
| 59 | + // MAINTENANCE_TODO: Remove this cast once texture-component-swizzle is added to @webgpu/types |
| 60 | + t.selectDeviceOrSkipTestCase('texture-component-swizzle' as GPUFeatureName); |
| 61 | + }) |
| 62 | + .fn(t => { |
| 63 | + const { swizzleSpec, usage } = t.params; |
| 64 | + const swizzle = swizzleSpecToGPUTextureComponentSwizzle(swizzleSpec); |
| 65 | + const texture = t.createTextureTracked({ |
| 66 | + format: 'rgba8unorm', |
| 67 | + size: [1], |
| 68 | + usage, |
| 69 | + }); |
| 70 | + const badUsage = |
| 71 | + (usage & |
| 72 | + (GPUConst.TextureUsage.RENDER_ATTACHMENT | GPUConst.TextureUsage.STORAGE_BINDING)) !== |
| 73 | + 0; |
| 74 | + const shouldError = badUsage && !isIdentitySwizzle(swizzle); |
| 75 | + t.expectValidationError(() => { |
| 76 | + texture.createView({ swizzle }); |
| 77 | + }, shouldError); |
| 78 | + }); |
0 commit comments