Skip to content

Commit

Permalink
Compat: refactor depth_clip_clamp for 0 storage buffers (#4096)
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman authored Dec 18, 2024
1 parent 2fdc883 commit bdee22a
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions src/webgpu/api/operation/rendering/depth_clip_clamp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ depth ranges as well.
import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { assert } from '../../../../common/util/util.js';
import { kDepthStencilFormats, kTextureFormatInfo } from '../../../format_info.js';
import { GPUTest } from '../../../gpu_test.js';
import { GPUTest, MaxLimitsTestMixin } from '../../../gpu_test.js';
import {
checkElementsBetween,
checkElementsPassPredicate,
CheckElementsSupplementalTableRows,
} from '../../../util/check_contents.js';

export const g = makeTestGroup(GPUTest);
export const g = makeTestGroup(MaxLimitsTestMixin(GPUTest));

g.test('depth_clamp_and_clip')
.desc(
Expand Down Expand Up @@ -55,6 +55,10 @@ have unexpected values then get drawn to the color buffer, which is later checke
const info = kTextureFormatInfo[format];
assert(!!info.depth);

const hasStorageBuffers = t.isCompatibility
? t.device.limits.maxStorageBuffersInFragmentStage! > 0
: true;

/** Number of depth values to test for both vertex output and frag_depth output. */
const kNumDepthValues = 8;
/** Test every combination of vertex output and frag_depth output. */
Expand Down Expand Up @@ -111,7 +115,13 @@ have unexpected values then get drawn to the color buffer, which is later checke
@group(0) @binding(0) var <storage, read_write> output: Output;
fn checkZ(vf: VFTest) {
output.fragInputZDiff[vf.vertexIndex] = vf.pos.z - expectedFragPosZ(vf.vertexIndex);
${
hasStorageBuffers
? `
output.fragInputZDiff[vf.vertexIndex] = vf.pos.z - expectedFragPosZ(vf.vertexIndex);
`
: ''
}
}
@fragment
Expand Down Expand Up @@ -246,10 +256,12 @@ have unexpected values then get drawn to the color buffer, which is later checke
size: 4 * kNumTestPoints,
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC,
});
const testBindGroup = t.device.createBindGroup({
layout: testPipeline.getBindGroupLayout(0),
entries: [{ binding: 0, resource: { buffer: fragInputZFailedBuffer } }],
});
const testBindGroup = hasStorageBuffers
? t.device.createBindGroup({
layout: testPipeline.getBindGroupLayout(0),
entries: [{ binding: 0, resource: { buffer: fragInputZFailedBuffer } }],
})
: undefined;

const enc = t.device.createCommandEncoder();
{
Expand All @@ -266,7 +278,9 @@ have unexpected values then get drawn to the color buffer, which is later checke
},
});
pass.setPipeline(testPipeline);
pass.setBindGroup(0, testBindGroup);
if (hasStorageBuffers) {
pass.setBindGroup(0, testBindGroup);
}
pass.setViewport(0, 0, kNumTestPoints, 1, kViewportMinDepth, kViewportMaxDepth);
pass.draw(kNumTestPoints);
pass.end();
Expand Down Expand Up @@ -314,11 +328,13 @@ have unexpected values then get drawn to the color buffer, which is later checke
}
t.device.queue.submit([enc.finish()]);

t.expectGPUBufferValuesPassCheck(
fragInputZFailedBuffer,
a => checkElementsBetween(a, [() => -1e-5, () => 1e-5]),
{ type: Float32Array, typedLength: kNumTestPoints }
);
if (hasStorageBuffers) {
t.expectGPUBufferValuesPassCheck(
fragInputZFailedBuffer,
a => checkElementsBetween(a, [() => -1e-5, () => 1e-5]),
{ type: Float32Array, typedLength: kNumTestPoints }
);
}

const kCheckPassedValue = 0;
const predicatePrinter: CheckElementsSupplementalTableRows = [
Expand Down

0 comments on commit bdee22a

Please sign in to comment.