Skip to content

Commit

Permalink
test textureNumLevels/Layers/Samples with stages (#4036)
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman authored Nov 12, 2024
1 parent b9f32fd commit 8d0aa85
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Returns the number of layers (elements) of an array texture.
import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
import { kTextureFormatInfo } from '../../../../../format_info.js';
import { TexelFormats } from '../../../../types.js';
import { kShaderStages } from '../../../../validation/decl/util.js';

import { kSampleTypeInfo, WGSLTextureQueryTest } from './texture_utils.js';

Expand Down Expand Up @@ -54,6 +55,7 @@ Parameters
.combine('view_type', ['full', 'partial'] as const)
.beginSubcases()
.combine('sampled_type', ['f32', 'i32', 'u32'] as const)
.combine('stage', kShaderStages)
)
.beforeAllSubcases(t => {
t.skipIf(
Expand All @@ -66,7 +68,7 @@ Parameters
);
})
.fn(t => {
const { texture_type, sampled_type, view_type } = t.params;
const { stage, texture_type, sampled_type, view_type } = t.params;
const { format } = kSampleTypeInfo[sampled_type];

const texture = t.createTextureTracked({
Expand All @@ -77,9 +79,8 @@ Parameters

const code = `
@group(0) @binding(0) var t: ${texture_type}<${sampled_type}>;
@group(0) @binding(1) var<storage, read_write> result: u32;
@compute @workgroup_size(1) fn cs() {
result = textureNumLayers(t);
fn getValue() -> u32 {
return textureNumLayers(t);
}
`;

Expand All @@ -93,7 +94,7 @@ Parameters
arrayLayerCount,
});

t.executeAndExpectResult(code, view, expected);
t.executeAndExpectResult(stage, code, view, expected);
});

g.test('arrayed')
Expand All @@ -111,6 +112,8 @@ Parameters
u
.combine('texture_type', ['texture_depth_2d_array', 'texture_depth_cube_array'] as const)
.combine('view_type', ['full', 'partial'] as const)
.beginSubcases()
.combine('stage', kShaderStages)
)
.beforeAllSubcases(t => {
t.skipIf(
Expand All @@ -123,7 +126,7 @@ Parameters
);
})
.fn(t => {
const { texture_type, view_type } = t.params;
const { stage, texture_type, view_type } = t.params;

const texture = t.createTextureTracked({
format: 'depth32float',
Expand All @@ -134,8 +137,8 @@ Parameters
const code = `
@group(0) @binding(0) var t: ${texture_type};
@group(0) @binding(1) var<storage, read_write> result: u32;
@compute @workgroup_size(1) fn cs() {
result = textureNumLayers(t);
fn getValue() -> u32 {
return textureNumLayers(t);
}
`;

Expand All @@ -149,7 +152,7 @@ Parameters
arrayLayerCount,
});

t.executeAndExpectResult(code, view, expected);
t.executeAndExpectResult(stage, code, view, expected);
});

g.test('storage')
Expand Down Expand Up @@ -185,10 +188,13 @@ Parameters
.combineWithParams(TexelFormats)
.combine('view_type', ['full', 'partial'] as const)
.beginSubcases()
.combine('stage', kShaderStages)
.combine('access_mode', ['read', 'write', 'read_write'] as const)
.filter(
t => t.access_mode !== 'read_write' || kTextureFormatInfo[t.format].color?.readWriteStorage
)
// Vertex stage can not use writable storage textures.
.unless(t => t.stage === 'vertex' && t.access_mode !== 'read')
)
.beforeAllSubcases(t => {
t.skipIf(
Expand All @@ -198,7 +204,7 @@ Parameters
t.skipIfTextureFormatNotUsableAsStorageTexture(t.params.format);
})
.fn(t => {
const { format, access_mode, view_type } = t.params;
const { stage, format, access_mode, view_type } = t.params;

const texture = t.createTextureTracked({
format,
Expand All @@ -209,8 +215,8 @@ Parameters
const code = `
@group(0) @binding(0) var t: texture_storage_2d_array<${format}, ${access_mode}>;
@group(0) @binding(1) var<storage, read_write> result: u32;
@compute @workgroup_size(1) fn cs() {
result = textureNumLayers(t);
fn getValue() -> u32 {
return textureNumLayers(t);
}
`;

Expand All @@ -223,5 +229,5 @@ Parameters
arrayLayerCount,
});

t.executeAndExpectResult(code, view, expected);
t.executeAndExpectResult(stage, code, view, expected);
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Returns the number of mip levels of a texture.

import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
import { getTextureDimensionFromView } from '../../../../../util/texture/base.js';
import { kShaderStages } from '../../../../validation/decl/util.js';

import { kSampleTypeInfo, WGSLTextureQueryTest } from './texture_utils.js';

Expand Down Expand Up @@ -66,6 +67,7 @@ Parameters
'texture_cube_array',
] as const)
.beginSubcases()
.combine('stage', kShaderStages)
.combine('sampled_type', ['f32', 'i32', 'u32'] as const)
.combine('view_type', ['full', 'partial'] as const)
// 1d textures can't have mipLevelCount > 0
Expand All @@ -75,7 +77,7 @@ Parameters
t.skipIfTextureViewDimensionNotSupported(kTextureTypeToViewDimension[t.params.texture_type]);
})
.fn(t => {
const { texture_type, sampled_type, view_type } = t.params;
const { stage, texture_type, sampled_type, view_type } = t.params;
const { format } = kSampleTypeInfo[sampled_type];

const viewDimension = kTextureTypeToViewDimension[texture_type];
Expand All @@ -101,8 +103,8 @@ Parameters
const code = `
@group(0) @binding(0) var t: ${texture_type}<${sampled_type}>;
@group(0) @binding(1) var<storage, read_write> result: u32;
@compute @workgroup_size(1) fn cs() {
result = textureNumLevels(t);
fn getValue() -> u32 {
return textureNumLevels(t);
}
`;

Expand All @@ -116,7 +118,7 @@ Parameters
mipLevelCount,
});

t.executeAndExpectResult(code, view, expected);
t.executeAndExpectResult(stage, code, view, expected);
});

g.test('depth')
Expand All @@ -141,12 +143,14 @@ Parameters
'texture_depth_cube_array',
] as const)
.combine('view_type', ['full', 'partial'] as const)
.beginSubcases()
.combine('stage', kShaderStages)
)
.beforeAllSubcases(t => {
t.skipIfTextureViewDimensionNotSupported(kTextureTypeToViewDimension[t.params.texture_type]);
})
.fn(t => {
const { texture_type, view_type } = t.params;
const { stage, texture_type, view_type } = t.params;

const viewDimension = kTextureTypeToViewDimension[texture_type];
const dimension = getTextureDimensionFromView(viewDimension);
Expand All @@ -171,8 +175,8 @@ Parameters
const code = `
@group(0) @binding(0) var t: ${texture_type};
@group(0) @binding(1) var<storage, read_write> result: u32;
@compute @workgroup_size(1) fn cs() {
result = textureNumLevels(t);
fn getValue() -> u32 {
return textureNumLevels(t);
}
`;

Expand All @@ -186,5 +190,5 @@ Parameters
mipLevelCount,
});

t.executeAndExpectResult(code, view, expected);
t.executeAndExpectResult(stage, code, view, expected);
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Returns the number samples per texel in a multisampled texture.
`;

import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
import { kShaderStages } from '../../../../validation/decl/util.js';

import { kSampleTypeInfo, WGSLTextureQueryTest } from './texture_utils.js';

Expand All @@ -22,9 +23,14 @@ Parameters
* t The multisampled texture.
`
)
.params(u => u.beginSubcases().combine('sampled_type', ['f32', 'i32', 'u32'] as const))
.params(u =>
u
.beginSubcases()
.combine('stage', kShaderStages)
.combine('sampled_type', ['f32', 'i32', 'u32'] as const)
)
.fn(t => {
const { sampled_type } = t.params;
const { stage, sampled_type } = t.params;
const { format } = kSampleTypeInfo[sampled_type];

const sampleCount = 4;
Expand All @@ -38,15 +44,15 @@ Parameters
const code = `
@group(0) @binding(0) var t: texture_multisampled_2d<${sampled_type}>;
@group(0) @binding(1) var<storage, read_write> result: u32;
@compute @workgroup_size(1) fn cs() {
result = textureNumSamples(t);
fn getValue() -> u32 {
return textureNumSamples(t);
}
`;

const expected = [sampleCount];
const view = texture.createView({});

t.executeAndExpectResult(code, view, expected);
t.executeAndExpectResult(stage, code, view, expected);
});

g.test('depth')
Expand All @@ -59,7 +65,9 @@ Parameters
* t The multisampled texture.
`
)
.params(u => u.beginSubcases().combine('stage', kShaderStages))
.fn(t => {
const { stage } = t.params;
const sampleCount = 4;
const texture = t.createTextureTracked({
format: 'depth32float',
Expand All @@ -71,13 +79,13 @@ Parameters
const code = `
@group(0) @binding(0) var t: texture_depth_multisampled_2d;
@group(0) @binding(1) var<storage, read_write> result: u32;
@compute @workgroup_size(1) fn cs() {
result = textureNumSamples(t);
fn getValue() -> u32 {
return textureNumSamples(t);
}
`;

const expected = [sampleCount];
const view = texture.createView({});

t.executeAndExpectResult(code, view, expected);
t.executeAndExpectResult(stage, code, view, expected);
});
Loading

0 comments on commit 8d0aa85

Please sign in to comment.