gpuweb / gpuweb

Where the GPU for the Web work happens!

Home Page:http://webgpu.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compat: Disallow vertex stride of 0

Kangz opened this issue · comments

I think this is another thing that needs to be added to the list. WebGPU supports a stride of 0 for attributes. OpenGL ES does not. Stride of 0 in GL = advance the size of the attribute. Stride of 0 in WebGPU = a stride of 0 as in don't advance the attribute. Just keep reading the same value.

I guess in Compat a stride if 0 in an attribute would generate a validation error? Otherwise you could read value in the buffer, turn off the attribute (gl.disableVertexAttribPointer), and set the attribute's constant value (gl.vertexAttrib4f(...valueReadFromBuffer))

Originally posted by @greggman in #4266 (comment)

There's a comment further down, there's a CTS test for that and it's already passing

https://github.com/gpuweb/cts/blob/6e75f19212e3deaebd5bd8542fe10a6fdedc0cdf/src/webgpu/api/operation/vertex_state/correctness.spec.ts#L728

It's passing because in OpenGL this can be emulated by setting the divisor for the attribute to a high number

glVertexAttribDivisor(attribLocation, 0xffffffff)

Which is what Dawn is currently doing. So I guess no spec changes are needed for this. Just passing on the existing solution.

Instancing works fine and is tested in the test linked above. glVertexAttribDivisor sets how many instances you have to draw before the attribute advances and setting it to 0xffffffff means you'll never advance since that's also the maximum instance count.

@kdashg

I'm going to close this issue since it's solved/done. Re-open if needed.

GPU Web CG 2024-03-13 Atlantic-time
* GT: already a solution. Set divisor of attribute to a giant number, and it works.
* KG: instance and non-instance values?
* CW: think we have tests for both. Remember writing tests for them.
* GT: I can double-check.
* Consensus. If it works, good - don't need to disallow.