Skip to content

Commit 180bf4b

Browse files
committed
Compat: Fix texture_zero init tests for compat
1 parent 4e27db8 commit 180bf4b

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

src/webgpu/api/operation/resource_init/check_texture/by_sampling.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,20 @@ export const checkContentsBySampling: CheckContents = (
4141
? componentOrder[0].toLowerCase()
4242
: componentOrder.map(c => c.toLowerCase()).join('') + '[i]';
4343

44-
const _xd = '_' + params.dimension;
44+
const viewDimension =
45+
t.isCompatibility && params.dimension === '2d' && texture.depthOrArrayLayers > 1
46+
? '2d-array'
47+
: params.dimension;
48+
const _xd = `_${viewDimension.replace('-', '_')}`;
4549
const _multisampled = params.sampleCount > 1 ? '_multisampled' : '';
4650
const texelIndexExpression =
47-
params.dimension === '2d'
51+
viewDimension === '2d'
4852
? 'vec2<i32>(GlobalInvocationID.xy)'
49-
: params.dimension === '3d'
53+
: viewDimension === '2d-array'
54+
? 'vec2<i32>(GlobalInvocationID.xy), constants.layer'
55+
: viewDimension === '3d'
5056
? 'vec3<i32>(GlobalInvocationID.xyz)'
51-
: params.dimension === '1d'
57+
: viewDimension === '1d'
5258
? 'i32(GlobalInvocationID.x)'
5359
: unreachable();
5460
const computePipeline = t.device.createComputePipeline({
@@ -58,7 +64,8 @@ export const checkContentsBySampling: CheckContents = (
5864
module: t.device.createShaderModule({
5965
code: `
6066
struct Constants {
61-
level : i32
67+
level : i32,
68+
layer : i32,
6269
};
6370
6471
@group(0) @binding(0) var<uniform> constants : Constants;
@@ -90,10 +97,10 @@ export const checkContentsBySampling: CheckContents = (
9097
for (const layer of layers) {
9198
const ubo = t.device.createBuffer({
9299
mappedAtCreation: true,
93-
size: 4,
100+
size: 8,
94101
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
95102
});
96-
new Int32Array(ubo.getMappedRange(), 0, 1)[0] = level;
103+
new Int32Array(ubo.getMappedRange()).set([level, layer]);
97104
ubo.unmap();
98105

99106
const byteLength =
@@ -104,6 +111,14 @@ export const checkContentsBySampling: CheckContents = (
104111
});
105112
t.trackForCleanup(resultBuffer);
106113

114+
const viewDescriptor: GPUTextureViewDescriptor = {
115+
...(!t.isCompatibility && {
116+
baseArrayLayer: layer,
117+
arrayLayerCount: 1,
118+
}),
119+
dimension: viewDimension,
120+
};
121+
107122
const bindGroup = t.device.createBindGroup({
108123
layout: computePipeline.getBindGroupLayout(0),
109124
entries: [
@@ -113,11 +128,7 @@ export const checkContentsBySampling: CheckContents = (
113128
},
114129
{
115130
binding: 1,
116-
resource: texture.createView({
117-
baseArrayLayer: layer,
118-
arrayLayerCount: 1,
119-
dimension: params.dimension,
120-
}),
131+
resource: texture.createView(viewDescriptor),
121132
},
122133
{
123134
binding: 3,

0 commit comments

Comments
 (0)