Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,7 @@
"webgpu:shader,execution,expression,call,builtin,textureSampleLevel:depth_2d_coords:*": { "subcaseMS": 545.401 },
"webgpu:shader,execution,expression,call,builtin,textureSampleLevel:depth_3d_coords:*": { "subcaseMS": 183.000 },
"webgpu:shader,execution,expression,call,builtin,textureSampleLevel:depth_array_2d_coords:*": { "subcaseMS": 547.500 },
"webgpu:shader,execution,expression,call,builtin,textureSampleLevel:sampled_1d_coords:*": { "subcaseMS": 430.253 },
"webgpu:shader,execution,expression,call,builtin,textureSampleLevel:sampled_2d_coords:*": { "subcaseMS": 35.601 },
"webgpu:shader,execution,expression,call,builtin,textureSampleLevel:sampled_3d_coords:*": { "subcaseMS": 118.901 },
"webgpu:shader,execution,expression,call,builtin,textureSampleLevel:sampled_array_2d_coords:*": { "subcaseMS": 822.400 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
createTextureWithRandomDataAndGetTexels,
doTextureCalls,
generateSamplePointsCube,
generateTextureBuiltinInputs1D,
generateTextureBuiltinInputs2D,
generateTextureBuiltinInputs3D,
getDepthOrArrayLayersForViewDimension,
Expand All @@ -33,12 +34,110 @@ import {
SamplePointMethods,
skipIfTextureFormatNotSupportedOrNeedsFilteringAndIsUnfilterable,
TextureCall,
vec1,
vec2,
vec3,
} from './texture_utils.js';

export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);

g.test('sampled_1d_coords')
.specURL('https://www.w3.org/TR/WGSL/#texturesamplelevel')
.desc(
`
fn textureSampleLevel(t: texture_1d<f32>, s: sampler, coords: f32, level: f32) -> vec4<f32>

Parameters:
* t The sampled or depth texture to sample.
* s The sampler type.
* coords The texture coordinates used for sampling.
* level
* The mip level, with level 0 containing a full size version of the texture.
* For the functions where level is a f32, fractional values may interpolate between
two levels if the format is filterable according to the Texture Format Capabilities.
* When not specified, mip level 0 is sampled.
`
)
.params(u =>
u
.combine('stage', kShortShaderStages)
.combine('format', kAllTextureFormats)
.filter(t => isPotentiallyFilterableAndFillable(t.format))
.combine('filt', ['nearest', 'linear'] as const)
.filter(t => t.filt === 'nearest' || isTextureFormatPossiblyFilterableAsTextureF32(t.format))
.combine('modeU', kShortAddressModes)
.combine('modeV', kShortAddressModes)
.beginSubcases()
.combine('samplePoints', kSamplePointMethods)
)
.fn(async t => {
const { format, stage, samplePoints, modeU, modeV, filt: minFilter } = t.params;
t.skipIfTextureFormatAndDimensionNotCompatible(format, '1d');
skipIfTextureFormatNotSupportedOrNeedsFilteringAndIsUnfilterable(t, minFilter, format);

// We want at least 4 blocks or something wide enough for 3 mip levels.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems inaccurate since we're only testing a single level here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe leave it? If 1d textures ever support mip levels nothing needs to change here. We'd just change chooseTextureSize. It's not technically inaccurate. We're choosing a size that could support at least 3 mip levels. We're not actually making 3 mip levels.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave it then.

const [width, height] = chooseTextureSize({
minSize: 8,
minBlocks: 4,
format,
viewDimension: '1d',
});

const descriptor: GPUTextureDescriptor = {
format,
dimension: '1d',
size: { width, height },
usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.TEXTURE_BINDING,
};
const viewDescriptor = {};
const { texels, texture } = await createTextureWithRandomDataAndGetTexels(t, descriptor);
const softwareTexture = { texels, descriptor, viewDescriptor };
const sampler: GPUSamplerDescriptor = {
addressModeU: kShortAddressModeToAddressMode[modeU],
addressModeV: kShortAddressModeToAddressMode[modeV],
minFilter,
magFilter: minFilter,
mipmapFilter: minFilter,
};

const calls: TextureCall<vec1>[] = generateTextureBuiltinInputs1D(50, {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this code needs the mipLevel code to match the 2d code. Both in the call to genearteTextureBuiltinInputs1D and in the return code. That's what makes it test out of bounds mip levels. It doesn't exist in textureSample test because texture sample test chooses mip levels by derivatives.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks for catching this!

method: samplePoints,
sampler,
softwareTexture,
mipLevel: { num: texture.mipLevelCount, type: 'f32' },
hashInputs: [stage, format, samplePoints, modeU, modeV, minFilter],
}).map(({ coords, mipLevel }) => {
return {
builtin: 'textureSampleLevel',
coordType: 'f',
coords,
mipLevel,
levelType: 'f',
};
});
const textureType = appendComponentTypeForFormatToTextureType('texture_1d', format);
const results = await doTextureCalls(
t,
texture,
viewDescriptor,
textureType,
sampler,
calls,
stage
);
const res = await checkCallResults(
t,
{ texels, descriptor, viewDescriptor },
textureType,
sampler,
calls,
results,
stage,
texture
);
t.expectOK(res);
});

g.test('sampled_2d_coords')
.specURL('https://www.w3.org/TR/WGSL/#texturesamplelevel')
.desc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type TextureSampleLevelArguments = {
};

const kValidTextureSampleLevelParameterTypes: { [n: string]: TextureSampleLevelArguments } = {
'texture_1d<f32>': { coordsArgType: Type.f32, levelIsF32: true },
'texture_2d<f32>': { coordsArgType: Type.vec2f, levelIsF32: true, offsetArgType: Type.vec2i },
'texture_2d_array<f32>': {
coordsArgType: Type.vec2f,
Expand Down