Skip to content

Commit 6a6cffd

Browse files
committed
Fix depth and stencil image_copy tests for compat
1 parent 90181a7 commit 6a6cffd

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

src/webgpu/api/operation/command_buffer/image_copy.spec.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,10 @@ class ImageCopyTest extends TextureTestMixin(GPUTest) {
11321132
copySize
11331133
);
11341134

1135+
const use2DArray = this.isCompatibility && inputTexture.depthOrArrayLayers > 1;
1136+
const [textureType, layerCode] = use2DArray
1137+
? ['texture_2d_array', ', baseArrayLayer']
1138+
: ['texture_2d', ''];
11351139
const renderPipeline = this.device.createRenderPipeline({
11361140
layout: 'auto',
11371141
vertex: {
@@ -1154,10 +1158,11 @@ class ImageCopyTest extends TextureTestMixin(GPUTest) {
11541158
fragment: {
11551159
module: this.device.createShaderModule({
11561160
code: `
1157-
@group(0) @binding(0) var inputTexture: texture_2d<f32>;
1161+
@group(0) @binding(0) var inputTexture: ${textureType}<f32>;
1162+
@group(0) @binding(1) var<uniform> baseArrayLayer: u32;
11581163
@fragment fn main(@builtin(position) fragcoord : vec4<f32>) ->
11591164
@builtin(frag_depth) f32 {
1160-
var depthValue : vec4<f32> = textureLoad(inputTexture, vec2<i32>(fragcoord.xy), 0);
1165+
var depthValue : vec4<f32> = textureLoad(inputTexture, vec2<i32>(fragcoord.xy)${layerCode}, 0);
11611166
return depthValue.x;
11621167
}`,
11631168
}),
@@ -1200,19 +1205,26 @@ class ImageCopyTest extends TextureTestMixin(GPUTest) {
12001205
});
12011206
renderPass.setPipeline(renderPipeline);
12021207

1208+
const uniformBufferEntry = use2DArray
1209+
? [this.createUniformBufferAndBindGroupEntryForBaseArrayLayer(z)]
1210+
: [];
1211+
12031212
const bindGroup = this.device.createBindGroup({
12041213
layout: renderPipeline.getBindGroupLayout(0),
12051214
entries: [
12061215
{
12071216
binding: 0,
12081217
resource: inputTexture.createView({
1209-
dimension: '2d',
1210-
baseArrayLayer: z,
1211-
arrayLayerCount: 1,
1218+
dimension: use2DArray ? '2d-array' : '2d',
1219+
...(use2DArray && {
1220+
baseArrayLayer: z,
1221+
arrayLayerCount: 1,
1222+
}),
12121223
baseMipLevel: 0,
12131224
mipLevelCount: 1,
12141225
}),
12151226
},
1227+
...uniformBufferEntry,
12161228
],
12171229
});
12181230
renderPass.setBindGroup(0, bindGroup);
@@ -1223,6 +1235,23 @@ class ImageCopyTest extends TextureTestMixin(GPUTest) {
12231235
this.queue.submit([encoder.finish()]);
12241236
}
12251237

1238+
createUniformBufferAndBindGroupEntryForBaseArrayLayer(z: number) {
1239+
const buffer = this.device.createBuffer({
1240+
usage: GPUBufferUsage.UNIFORM,
1241+
size: 4,
1242+
mappedAtCreation: true,
1243+
});
1244+
this.trackForCleanup(buffer);
1245+
new Uint32Array(buffer.getMappedRange()).set([z]);
1246+
buffer.unmap();
1247+
return {
1248+
binding: 1,
1249+
resource: {
1250+
buffer,
1251+
},
1252+
};
1253+
}
1254+
12261255
DoCopyTextureToBufferWithDepthAspectTest(
12271256
format: DepthStencilFormat,
12281257
copySize: readonly [number, number, number],

0 commit comments

Comments
 (0)