Skip to content

Commit

Permalink
Compat: Fix texture_zero init tests for compat
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Nov 11, 2023
1 parent 4e27db8 commit 180bf4b
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/webgpu/api/operation/resource_init/check_texture/by_sampling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,20 @@ export const checkContentsBySampling: CheckContents = (
? componentOrder[0].toLowerCase()
: componentOrder.map(c => c.toLowerCase()).join('') + '[i]';

const _xd = '_' + params.dimension;
const viewDimension =
t.isCompatibility && params.dimension === '2d' && texture.depthOrArrayLayers > 1
? '2d-array'
: params.dimension;
const _xd = `_${viewDimension.replace('-', '_')}`;
const _multisampled = params.sampleCount > 1 ? '_multisampled' : '';
const texelIndexExpression =
params.dimension === '2d'
viewDimension === '2d'
? 'vec2<i32>(GlobalInvocationID.xy)'
: params.dimension === '3d'
: viewDimension === '2d-array'
? 'vec2<i32>(GlobalInvocationID.xy), constants.layer'
: viewDimension === '3d'
? 'vec3<i32>(GlobalInvocationID.xyz)'
: params.dimension === '1d'
: viewDimension === '1d'
? 'i32(GlobalInvocationID.x)'
: unreachable();
const computePipeline = t.device.createComputePipeline({
Expand All @@ -58,7 +64,8 @@ export const checkContentsBySampling: CheckContents = (
module: t.device.createShaderModule({
code: `
struct Constants {
level : i32
level : i32,
layer : i32,
};
@group(0) @binding(0) var<uniform> constants : Constants;
Expand Down Expand Up @@ -90,10 +97,10 @@ export const checkContentsBySampling: CheckContents = (
for (const layer of layers) {
const ubo = t.device.createBuffer({
mappedAtCreation: true,
size: 4,
size: 8,
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
});
new Int32Array(ubo.getMappedRange(), 0, 1)[0] = level;
new Int32Array(ubo.getMappedRange()).set([level, layer]);
ubo.unmap();

const byteLength =
Expand All @@ -104,6 +111,14 @@ export const checkContentsBySampling: CheckContents = (
});
t.trackForCleanup(resultBuffer);

const viewDescriptor: GPUTextureViewDescriptor = {
...(!t.isCompatibility && {
baseArrayLayer: layer,
arrayLayerCount: 1,
}),
dimension: viewDimension,
};

const bindGroup = t.device.createBindGroup({
layout: computePipeline.getBindGroupLayout(0),
entries: [
Expand All @@ -113,11 +128,7 @@ export const checkContentsBySampling: CheckContents = (
},
{
binding: 1,
resource: texture.createView({
baseArrayLayer: layer,
arrayLayerCount: 1,
dimension: params.dimension,
}),
resource: texture.createView(viewDescriptor),
},
{
binding: 3,
Expand Down

0 comments on commit 180bf4b

Please sign in to comment.