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

fix(shadertools): Correct order of uniforms in picking module #1906

Merged
merged 1 commit into from
Jan 3, 2024

Conversation

felixpalmer
Copy link
Collaborator

Background

The order of uniforms in the uniformTypes must match that used in the shader. This was not the case in the picking module, which led to the incorrect layout being generated

Screenshot 2024-01-03 at 14 27 51

with the positions of useFloatColors and isHighlightActive being swapped

Screenshot 2024-01-03 at 15 11 31

Change List

  • Correct order of uniforms in picking module

@felixpalmer felixpalmer requested a review from donmccurdy January 3, 2024 14:18
Copy link
Collaborator

@donmccurdy donmccurdy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of uniforms in the uniformTypes must match that used in the shader.

That sounds painful to discover! Do you know whether this is an intended constraint of ShaderInputs, or an unexpected one?

I wonder if we should include a (temporary?) lint before shader compilation to detect and warn about mismatched order. If it's an unintended or new constraint, there may be more cases like this.

@felixpalmer felixpalmer merged commit f31ef64 into master Jan 3, 2024
2 checks passed
@felixpalmer felixpalmer deleted the felix/picking-uniform-store-layout branch January 3, 2024 15:00
@felixpalmer
Copy link
Collaborator Author

Do you know whether this is an intended constraint of ShaderInputs, or an unexpected one?

Not sure, @ibgreen?

I wonder if we should include a (temporary?) lint before shader compilation to detect and warn about mismatched order. If it's an unintended or new constraint, there may be more cases like this.

That would be nice, but not really sure how to go about it, and my current feeling is that we have a lot on our plate to land the picking UBO plate as is. If you want to take a stab though, that would be helpful :)

@donmccurdy
Copy link
Collaborator

Ah yeah! Just floating the idea, no expectation or ask on that. 😁 I may take a shot at it if I run into similar issues.

@ibgreen
Copy link
Collaborator

ibgreen commented Jan 9, 2024

Do you know whether this is an intended constraint of ShaderInputs, or an unexpected one?

It is fundamental, unrelated to ShaderInputs. The memory layout is defined by the order of the declarations in the uniform block in the shader code, and that binary layout must be precisely replicated on the CPU in the block that is passed in.

luma.gl does extract some (currently unused) information about uniform blocks using the WebGL introspection API so it should be fairly easy to write some code that checks that the layouts are identical.

Another option is to autogenerate the uniform block declarations in the shaders from the shader module uniform declarations which would guaranteed that types are always matching.

But that would be a pretty big "philosophy" change: luma.gl has been focused on enabling users to write their own shaders (as opposed to shaders being something that is magically generated by the engine).

I'd prefer to have multiple reasons for making such a big change, rather than just trying to prevent one type of error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants