Skip to content

Commit

Permalink
WGSL textureSampleLevel execution tests (#3888)
Browse files Browse the repository at this point in the history
Cube and cube-arrays are not thoroughly tested at the moment.
See TODO in comments.
  • Loading branch information
greggman authored Aug 6, 2024
1 parent 9cf0129 commit c5ab6ed
Show file tree
Hide file tree
Showing 4 changed files with 1,218 additions and 385 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ note: uniformity validation is covered in src/webgpu/shader/validation/uniformit
`;

import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
import { unreachable } from '../../../../../../common/util/util.js';
import {
isCompressedTextureFormat,
kCompressedTextureFormats,
kEncodableTextureFormats,
kTextureFormatInfo,
} from '../../../../../format_info.js';
import { GPUTest, TextureTestMixin } from '../../../../../gpu_test.js';
import { TextureTestMixin } from '../../../../../gpu_test.js';

import {
vec2,
Expand All @@ -29,38 +27,17 @@ import {
kCubeSamplePointMethods,
SamplePointMethods,
chooseTextureSize,
isPotentiallyFilterableAndFillable,
skipIfTextureFormatNotSupportedNotAvailableOrNotFilterable,
getDepthOrArrayLayersForViewDimension,
getTextureTypeForTextureViewDimension,
WGSLTextureSampleTest,
} from './texture_utils.js';
import { generateCoordBoundaries, generateOffsets } from './utils.js';

const kTestableColorFormats = [...kEncodableTextureFormats, ...kCompressedTextureFormats] as const;

function getDepthOrArrayLayersForViewDimension(viewDimension: GPUTextureViewDimension) {
switch (viewDimension) {
case '2d':
return 1;
case '3d':
return 8;
case 'cube':
return 6;
default:
unreachable();
}
}

function getTextureTypeForTextureViewDimension(viewDimension: GPUTextureViewDimension) {
switch (viewDimension) {
case '2d':
return 'texture_2d<f32>';
case '3d':
return 'texture_3d<f32>';
case 'cube':
return 'texture_cube<f32>';
default:
unreachable();
}
}

export const g = makeTestGroup(TextureTestMixin(GPUTest));
export const g = makeTestGroup(TextureTestMixin(WGSLTextureSampleTest));

g.test('sampled_1d_coords')
.specURL('https://www.w3.org/TR/WGSL/#texturesample')
Expand Down Expand Up @@ -103,31 +80,17 @@ Parameters:
.params(u =>
u
.combine('format', kTestableColorFormats)
.filter(t => {
const type = kTextureFormatInfo[t.format].color?.type;
const canPotentialFilter = type === 'float' || type === 'unfilterable-float';
// We can't easily put random bytes into compressed textures if they are float formats
// since we want the range to be +/- 1000 and not +/- infinity or NaN.
const isFillable = !isCompressedTextureFormat(t.format) || !t.format.endsWith('float');
return canPotentialFilter && isFillable;
})
.filter(t => isPotentiallyFilterableAndFillable(t.format))
.combine('samplePoints', kSamplePointMethods)
.beginSubcases()
.combine('addressModeU', ['clamp-to-edge', 'repeat', 'mirror-repeat'] as const)
.combine('addressModeV', ['clamp-to-edge', 'repeat', 'mirror-repeat'] as const)
.combine('minFilter', ['nearest', 'linear'] as const)
.combine('offset', [false, true] as const)
)
.beforeAllSubcases(t => {
const { format } = t.params;
t.skipIfTextureFormatNotSupported(format);
const info = kTextureFormatInfo[format];
if (info.color?.type === 'unfilterable-float') {
t.selectDeviceOrSkipTestCase('float32-filterable');
} else {
t.selectDeviceForTextureFormatOrSkipTestCase(t.params.format);
}
})
.beforeAllSubcases(t =>
skipIfTextureFormatNotSupportedNotAvailableOrNotFilterable(t, t.params.format)
)
.fn(async t => {
const { format, samplePoints, addressModeU, addressModeV, minFilter, offset } = t.params;

Expand Down Expand Up @@ -194,14 +157,7 @@ test mip level selection based on derivatives
.params(u =>
u
.combine('format', kTestableColorFormats)
.filter(t => {
const type = kTextureFormatInfo[t.format].color?.type;
const canPotentialFilter = type === 'float' || type === 'unfilterable-float';
// We can't easily put random bytes into compressed textures if they are float formats
// since we want the range to be +/- 1000 and not +/- infinity or NaN.
const isFillable = !isCompressedTextureFormat(t.format) || !t.format.endsWith('float');
return canPotentialFilter && isFillable;
})
.filter(t => isPotentiallyFilterableAndFillable(t.format))
.combine('mipmapFilter', ['nearest', 'linear'] as const)
.beginSubcases()
// note: this is the derivative we want at sample time. It is not the value
Expand All @@ -220,16 +176,9 @@ test mip level selection based on derivatives
{ ddx: 1.5, ddy: 1.5, uvwStart: [-3.5, -4] as const }, // test mix between 1 and 2 with negative coords
])
)
.beforeAllSubcases(t => {
const { format } = t.params;
t.skipIfTextureFormatNotSupported(format);
const info = kTextureFormatInfo[format];
if (info.color?.type === 'unfilterable-float') {
t.selectDeviceOrSkipTestCase('float32-filterable');
} else {
t.selectDeviceForTextureFormatOrSkipTestCase(t.params.format);
}
})
.beforeAllSubcases(t =>
skipIfTextureFormatNotSupportedNotAvailableOrNotFilterable(t, t.params.format)
)
.fn(async t => {
const { format, mipmapFilter, ddx, ddy, uvwStart, offset } = t.params;

Expand Down Expand Up @@ -285,14 +234,7 @@ Parameters:
.params(u =>
u
.combine('format', kTestableColorFormats)
.filter(t => {
const type = kTextureFormatInfo[t.format].color?.type;
const canPotentialFilter = type === 'float' || type === 'unfilterable-float';
// We can't easily put random bytes into compressed textures if they are float formats
// since we want the range to be +/- 1000 and not +/- infinity or NaN.
const isFillable = !isCompressedTextureFormat(t.format) || !t.format.endsWith('float');
return canPotentialFilter && isFillable;
})
.filter(t => isPotentiallyFilterableAndFillable(t.format))
.combine('viewDimension', ['3d', 'cube'] as const)
.filter(t => !isCompressedTextureFormat(t.format) || t.viewDimension === 'cube')
.combine('samplePoints', kCubeSamplePointMethods)
Expand All @@ -305,16 +247,9 @@ Parameters:
.combine('offset', [false, true] as const)
.filter(t => t.viewDimension !== 'cube' || t.offset !== true)
)
.beforeAllSubcases(t => {
const { format } = t.params;
t.skipIfTextureFormatNotSupported(format);
const info = kTextureFormatInfo[format];
if (info.color?.type === 'unfilterable-float') {
t.selectDeviceOrSkipTestCase('float32-filterable');
} else {
t.selectDeviceForTextureFormatOrSkipTestCase(t.params.format);
}
})
.beforeAllSubcases(t =>
skipIfTextureFormatNotSupportedNotAvailableOrNotFilterable(t, t.params.format)
)
.fn(async t => {
const {
format,
Expand Down
Loading

0 comments on commit c5ab6ed

Please sign in to comment.