Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compat: Refactor draw test for 0 storage buffers #4149

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 34 additions & 19 deletions src/webgpu/api/operation/rendering/draw.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class DrawTest extends TextureTestMixin(MaxLimitsTestMixin(GPUTest)) {
baseVertex: opts.baseVertex ?? 0,
};

const haveStorageBuffersInFragmentStage =
!this.isCompatibility || this.device.limits.maxStorageBuffersInFragmentStage! > 0;
const renderTargetSize = [72, 36];

// The test will split up the render target into a grid where triangles of
Expand Down Expand Up @@ -101,7 +103,7 @@ struct Output {
@group(0) @binding(0) var<storage, read_write> output : Output;
@fragment fn frag_main() -> @location(0) vec4<f32> {
output.value = 1u;
${haveStorageBuffersInFragmentStage ? 'output.value = 1u;' : ''}
return vec4<f32>(0.0, 1.0, 0.0, 1.0);
}
`,
Expand Down Expand Up @@ -136,22 +138,26 @@ struct Output {
},
});

const resultBuffer = this.createBufferTracked({
size: Uint32Array.BYTES_PER_ELEMENT,
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC,
});

const resultBindGroup = this.device.createBindGroup({
layout: pipeline.getBindGroupLayout(0),
entries: [
{
binding: 0,
resource: {
buffer: resultBuffer,
},
},
],
});
const resultBuffer = haveStorageBuffersInFragmentStage
? this.createBufferTracked({
size: Uint32Array.BYTES_PER_ELEMENT,
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC,
})
: null;

const resultBindGroup = haveStorageBuffersInFragmentStage
? this.device.createBindGroup({
layout: pipeline.getBindGroupLayout(0),
entries: [
{
binding: 0,
resource: {
buffer: resultBuffer!,
},
},
],
})
: null;

const commandEncoder = this.device.createCommandEncoder();
const renderPass = commandEncoder.beginRenderPass({
Expand Down Expand Up @@ -279,7 +285,9 @@ struct Output {

const didDraw = defaulted.count && defaulted.instanceCount;

this.expectGPUBufferValuesEqual(resultBuffer, new Uint32Array([didDraw ? 1 : 0]));
if (resultBuffer) {
this.expectGPUBufferValuesEqual(resultBuffer, new Uint32Array([didDraw ? 1 : 0]));
}

const baseVertexCount = defaulted.baseVertex ?? 0;
const pixelComparisons: PerPixelComparison<Uint8Array>[] = [];
Expand Down Expand Up @@ -321,7 +329,7 @@ Increasing the |first| param should skip some of the beginning triangles on the
Increasing the |first_instance| param should skip of the beginning triangles on the vertical axis.
The vertex buffer contains two sets of disjoint triangles, and base_vertex is used to select the second set.
The test checks that the center of all of the expected triangles is drawn, and the others are empty.
The fragment shader also writes out to a storage buffer. If the draw is zero-sized, check that no value is written.
The fragment shader also writes out to a storage buffer if it can. If the draw is zero-sized, check that no value is written.
Params:
- first= {0, 3} - either the firstVertex or firstIndex
Expand Down Expand Up @@ -428,6 +436,13 @@ g.test('vertex_attributes,basic')
.unless(p => p.step_mode === 'mixed' && p.vertex_buffer_count <= 1)
)
.fn(t => {
// MAINTENANCE_TODO: refactor this test so it doesn't need a storage buffer OR
// consider removing it. It's possible the tests in src/webgpu/api/operation/vertex_state/correctness.spec.ts
// already test this.
t.skipIf(
t.isCompatibility && !(t.device.limits.maxStorageBuffersInFragmentStage! > 0),
`maxStorageBuffersInFragmentStage(${t.device.limits.maxStorageBuffersInFragmentStage}) is 0`
);
const vertexCount = 4;
const instanceCount = 4;

Expand Down
Loading