Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,105 @@ 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, clamped to 0.

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.

Will clamped to 0 be part of the spec? Do I need to do something about it in the CTS and Tint implementation?

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.

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 "clamped to zero" would fall out of the generic mip level selection rules that apply to all textures. That said, I'm struggling to find exactly where that is written down in either the WGSL or API specs.

As for Tint, I don't think you need to do anything special, as I believe the backend APIs already do The Right Thing (i.e. clamp).

Ideally CTS would test out-of-bounds mip levels to ensure this is the case, but if we're not already doing this for other textures then that would be a separate issue.

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 test tests out-of-bounds mip levels. I'm not sure the comment is needed. Whatever number of mips the texture is, the test will test out of bounds 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've updated it and used same prose as the other tests for level

`
)
.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 { texels, texture } = await createTextureWithRandomDataAndGetTexels(t, descriptor);
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!

sampler,
method: samplePoints,
descriptor,
hashInputs: [stage, format, samplePoints, modeU, modeV, minFilter],
}).map(({ coords }) => {
return {
builtin: 'textureSampleLevel',
coordType: 'f',
coords,
levelType: 'f',
mipLevel: 0,
};
});
const viewDescriptor = {};
const textureType = 'texture_1d<f32>';
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