-
Notifications
You must be signed in to change notification settings - Fork 108
Add texture_1d support to textureSampleLevel #4406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ import { | |
| createTextureWithRandomDataAndGetTexels, | ||
| doTextureCalls, | ||
| generateSamplePointsCube, | ||
| generateTextureBuiltinInputs1D, | ||
| generateTextureBuiltinInputs2D, | ||
| generateTextureBuiltinInputs3D, | ||
| getDepthOrArrayLayersForViewDimension, | ||
|
|
@@ -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. | ||
| ` | ||
| ) | ||
| .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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will
clamped to 0be part of the spec? Do I need to do something about it in the CTS and Tint implementation?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI Here's my naive thoughts regarding the spec: https://github.com/gpuweb/gpuweb/compare/main...beaufortfrancois:gpuweb:textureSampleLevel1d?expand=1
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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