Skip to content

Commit

Permalink
WGSL execution tests for textureSampleBaseClampToEdge (#3896)
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman authored Aug 8, 2024
1 parent 550b446 commit cdd0502
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,7 @@
"webgpu:shader,execution,expression,call,builtin,textureSample:sampled_3d_coords:*": { "subcaseMS": 36.002 },
"webgpu:shader,execution,expression,call,builtin,textureSample:sampled_array_2d_coords:*": { "subcaseMS": 92.500 },
"webgpu:shader,execution,expression,call,builtin,textureSample:sampled_array_3d_coords:*": { "subcaseMS": 20.200 },
"webgpu:shader,execution,expression,call,builtin,textureSampleBaseClampToEdge:2d_coords:*": { "subcaseMS": 55.401 },
"webgpu:shader,execution,expression,call,builtin,textureSampleBias:arrayed_2d_coords:*": { "subcaseMS": 585.100 },
"webgpu:shader,execution,expression,call,builtin,textureSampleBias:arrayed_3d_coords:*": { "subcaseMS": 121.600 },
"webgpu:shader,execution,expression,call,builtin,textureSampleBias:sampled_2d_coords:*": { "subcaseMS": 48.601 },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
export const description = `
Execution tests for textureSampleBaseClampToEdge
`;

import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../../gpu_test.js';
import { TexelView } from '../../../../../util/texture/texel_view.js';

import {
checkCallResults,
createTextureWithRandomDataAndGetTexels,
createVideoFrameWithRandomDataAndGetTexels,
doTextureCalls,
generateTextureBuiltinInputs2D,
kSamplePointMethods,
TextureCall,
vec2,
WGSLTextureSampleTest,
} from './texture_utils.js';

export const g = makeTestGroup(WGSLTextureSampleTest);

async function createTextureAndDataForTest(
t: GPUTest,
descriptor: GPUTextureDescriptor,
isExternal: boolean
): Promise<{
texels: TexelView[];
texture: GPUTexture | GPUExternalTexture;
videoFrame?: VideoFrame;
}> {
if (isExternal) {
const { texels, videoFrame } = createVideoFrameWithRandomDataAndGetTexels(descriptor.size);
const texture = t.device.importExternalTexture({ source: videoFrame });
return { texels, texture, videoFrame };
} else {
return await createTextureWithRandomDataAndGetTexels(t, descriptor);
}
}

g.test('2d_coords')
.specURL('https://www.w3.org/TR/WGSL/#texturesamplebaseclamptoedge')
.desc(
`
fn textureSampleBaseClampToEdge(t: texture_2d<f32>, s: sampler, coords: vec2<f32>) -> vec4<f32>
fn textureSampleBaseClampToEdge(t: texture_external, s: sampler, coords: vec2<f32>) -> vec4<f32>
Parameters:
* t The texture to sample.
* s The sampler type.
* coords The texture coordinates used for sampling.
`
)
.params(u =>
u
.combine('textureType', ['texture_2d<f32>', 'texture_external'] as const)
.beginSubcases()
.combine('samplePoints', kSamplePointMethods)
.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)
)
.fn(async t => {
const { textureType, samplePoints, addressModeU, addressModeV, minFilter } = t.params;

const descriptor: GPUTextureDescriptor = {
format: 'rgba8unorm',
size: [8, 8],
usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.TEXTURE_BINDING,
mipLevelCount: 3,
};

const isExternal = textureType === 'texture_external';
const { texture, texels, videoFrame } = await createTextureAndDataForTest(
t,
descriptor,
isExternal
);
try {
const sampler: GPUSamplerDescriptor = {
addressModeU,
addressModeV,
minFilter,
magFilter: minFilter,
mipmapFilter: minFilter,
};

const calls: TextureCall<vec2>[] = generateTextureBuiltinInputs2D(50, {
method: samplePoints,
sampler,
descriptor,
hashInputs: [samplePoints, addressModeU, addressModeV, minFilter],
}).map(({ coords }) => {
return {
builtin: 'textureSampleBaseClampToEdge',
coordType: 'f',
coords,
};
});
const viewDescriptor = {};
const results = await doTextureCalls(t, texture, viewDescriptor, textureType, sampler, calls);
const res = await checkCallResults(
t,
{ texels, descriptor, viewDescriptor },
textureType,
sampler,
calls,
results
);
t.expectOK(res);
} finally {
videoFrame?.close();
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ export interface TextureCallArgs<T extends Dimensionality> {
}

export interface TextureCall<T extends Dimensionality> extends TextureCallArgs<T> {
builtin: 'textureSample' | 'textureLoad' | 'textureSampleLevel';
builtin: 'textureLoad' | 'textureSample' | 'textureSampleBaseClampToEdge' | 'textureSampleLevel';
coordType: 'f' | 'i' | 'u';
levelType?: 'i' | 'u' | 'f';
arrayIndexType?: 'i' | 'u';
Expand Down Expand Up @@ -652,11 +652,14 @@ export function softwareTextureReadMipLevel<T extends Dimensionality>(
texture.descriptor.size,
mipLevel
);
const addressMode = [
sampler?.addressModeU ?? 'clamp-to-edge',
sampler?.addressModeV ?? 'clamp-to-edge',
sampler?.addressModeW ?? 'clamp-to-edge',
];
const addressMode: GPUAddressMode[] =
call.builtin === 'textureSampleBaseClampToEdge'
? ['clamp-to-edge', 'clamp-to-edge', 'clamp-to-edge']
: [
sampler?.addressModeU ?? 'clamp-to-edge',
sampler?.addressModeV ?? 'clamp-to-edge',
sampler?.addressModeW ?? 'clamp-to-edge',
];

const isCube =
texture.viewDescriptor.dimension === 'cube' ||
Expand All @@ -682,6 +685,7 @@ export function softwareTextureReadMipLevel<T extends Dimensionality>(

switch (call.builtin) {
case 'textureSample':
case 'textureSampleBaseClampToEdge':
case 'textureSampleLevel': {
let coords = toArray(call.coords!);

Expand Down Expand Up @@ -830,6 +834,8 @@ export function softwareTextureReadMipLevel<T extends Dimensionality>(
: load(call.coords!);
return convertPerTexelComponentToResultFormat(out, format);
}
default:
unreachable();
}
}

Expand Down

0 comments on commit cdd0502

Please sign in to comment.