From 6a6cffd0d11cee332af28fed410cd37ce2e107a0 Mon Sep 17 00:00:00 2001 From: Gregg Tavares Date: Mon, 27 Nov 2023 11:11:38 -0800 Subject: [PATCH] Fix depth and stencil image_copy tests for compat --- .../command_buffer/image_copy.spec.ts | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/webgpu/api/operation/command_buffer/image_copy.spec.ts b/src/webgpu/api/operation/command_buffer/image_copy.spec.ts index 4eebc3d611e4..451ef8a97687 100644 --- a/src/webgpu/api/operation/command_buffer/image_copy.spec.ts +++ b/src/webgpu/api/operation/command_buffer/image_copy.spec.ts @@ -1132,6 +1132,10 @@ class ImageCopyTest extends TextureTestMixin(GPUTest) { copySize ); + const use2DArray = this.isCompatibility && inputTexture.depthOrArrayLayers > 1; + const [textureType, layerCode] = use2DArray + ? ['texture_2d_array', ', baseArrayLayer'] + : ['texture_2d', '']; const renderPipeline = this.device.createRenderPipeline({ layout: 'auto', vertex: { @@ -1154,10 +1158,11 @@ class ImageCopyTest extends TextureTestMixin(GPUTest) { fragment: { module: this.device.createShaderModule({ code: ` - @group(0) @binding(0) var inputTexture: texture_2d; + @group(0) @binding(0) var inputTexture: ${textureType}; + @group(0) @binding(1) var baseArrayLayer: u32; @fragment fn main(@builtin(position) fragcoord : vec4) -> @builtin(frag_depth) f32 { - var depthValue : vec4 = textureLoad(inputTexture, vec2(fragcoord.xy), 0); + var depthValue : vec4 = textureLoad(inputTexture, vec2(fragcoord.xy)${layerCode}, 0); return depthValue.x; }`, }), @@ -1200,19 +1205,26 @@ class ImageCopyTest extends TextureTestMixin(GPUTest) { }); renderPass.setPipeline(renderPipeline); + const uniformBufferEntry = use2DArray + ? [this.createUniformBufferAndBindGroupEntryForBaseArrayLayer(z)] + : []; + const bindGroup = this.device.createBindGroup({ layout: renderPipeline.getBindGroupLayout(0), entries: [ { binding: 0, resource: inputTexture.createView({ - dimension: '2d', - baseArrayLayer: z, - arrayLayerCount: 1, + dimension: use2DArray ? '2d-array' : '2d', + ...(use2DArray && { + baseArrayLayer: z, + arrayLayerCount: 1, + }), baseMipLevel: 0, mipLevelCount: 1, }), }, + ...uniformBufferEntry, ], }); renderPass.setBindGroup(0, bindGroup); @@ -1223,6 +1235,23 @@ class ImageCopyTest extends TextureTestMixin(GPUTest) { this.queue.submit([encoder.finish()]); } + createUniformBufferAndBindGroupEntryForBaseArrayLayer(z: number) { + const buffer = this.device.createBuffer({ + usage: GPUBufferUsage.UNIFORM, + size: 4, + mappedAtCreation: true, + }); + this.trackForCleanup(buffer); + new Uint32Array(buffer.getMappedRange()).set([z]); + buffer.unmap(); + return { + binding: 1, + resource: { + buffer, + }, + }; + } + DoCopyTextureToBufferWithDepthAspectTest( format: DepthStencilFormat, copySize: readonly [number, number, number],