Skip to content

Commit

Permalink
Fix depth and stencil image_copy tests for compat
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Nov 27, 2023
1 parent 097ffd4 commit 22e258f
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions src/webgpu/api/operation/command_buffer/image_copy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -1154,10 +1158,11 @@ class ImageCopyTest extends TextureTestMixin(GPUTest) {
fragment: {
module: this.device.createShaderModule({
code: `
@group(0) @binding(0) var inputTexture: texture_2d<f32>;
@group(0) @binding(0) var inputTexture: ${textureType}<f32>;
@group(0) @binding(1) var<uniform> baseArrayLayer: u32;
@fragment fn main(@builtin(position) fragcoord : vec4<f32>) ->
@builtin(frag_depth) f32 {
var depthValue : vec4<f32> = textureLoad(inputTexture, vec2<i32>(fragcoord.xy), 0);
var depthValue : vec4<f32> = textureLoad(inputTexture, vec2<i32>(fragcoord.xy)${layerCode}, 0);
return depthValue.x;
}`,
}),
Expand Down Expand Up @@ -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);
Expand All @@ -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],
Expand Down

0 comments on commit 22e258f

Please sign in to comment.