Skip to content

Commit

Permalink
Compat: Limit max attributes (gpuweb#2953)
Browse files Browse the repository at this point in the history
In compat @Builtin(vertex_index) and @Builtin(instance_index)
each take an attribute so account for that in this test.

It's possible we should refactor this test to not
use vertex_index, instance_instance. For example we could
make each pair of data generate the correct pixel position.

For now it seemed best to get it to pass.
The test in webgpu/compat/api/validation/encoding/render_pipeline/vertex_state.spec.ts
does a simple test that you can use maxVertexAttributes but it does
not test all the combinations like this test. It only tests that
creating a pipeline passes if you use maxVertexAttributes and
fails if you use maxVertexAttributes + the builtins above
  • Loading branch information
greggman authored Sep 14, 2023
1 parent 04cd7b8 commit 3a5f789
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/webgpu/api/operation/vertex_state/correctness.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -941,13 +941,15 @@ g.test('max_buffers_and_attribs')
.params(u => u.combine('format', kVertexFormats))
.fn(t => {
const { format } = t.params;
const attributesPerBuffer = Math.ceil(kMaxVertexAttributes / kMaxVertexBuffers);
// In compat mode, @builtin(vertex_index) and @builtin(instance_index) each take an attribute
const maxVertexAttributes = t.isCompatibility ? kMaxVertexAttributes - 2 : kMaxVertexAttributes;
const attributesPerBuffer = Math.ceil(maxVertexAttributes / kMaxVertexBuffers);
let attributesEmitted = 0;

const state: VertexLayoutState<{}, {}> = [];
for (let i = 0; i < kMaxVertexBuffers; i++) {
const attributes: GPUVertexAttribute[] = [];
for (let j = 0; j < attributesPerBuffer && attributesEmitted < kMaxVertexAttributes; j++) {
for (let j = 0; j < attributesPerBuffer && attributesEmitted < maxVertexAttributes; j++) {
attributes.push({ format, offset: 0, shaderLocation: attributesEmitted });
attributesEmitted++;
}
Expand Down Expand Up @@ -1080,8 +1082,10 @@ g.test('overlapping_attributes')
.fn(t => {
const { format } = t.params;

// In compat mode, @builtin(vertex_index) and @builtin(instance_index) each take an attribute
const maxVertexAttributes = t.isCompatibility ? kMaxVertexAttributes - 2 : kMaxVertexAttributes;
const attributes: GPUVertexAttribute[] = [];
for (let i = 0; i < kMaxVertexAttributes; i++) {
for (let i = 0; i < maxVertexAttributes; i++) {
attributes.push({ format, offset: 0, shaderLocation: i });
}

Expand Down

0 comments on commit 3a5f789

Please sign in to comment.