Skip to content

Fix WebGL not rendering StandardMaterial#12110

Merged
alice-i-cecile merged 3 commits intobevyengine:mainfrom
janhohenheim:fix-webgl
Feb 25, 2024
Merged

Fix WebGL not rendering StandardMaterial#12110
alice-i-cecile merged 3 commits intobevyengine:mainfrom
janhohenheim:fix-webgl

Conversation

@janhohenheim
Copy link
Copy Markdown
Member

@janhohenheim janhohenheim commented Feb 25, 2024

Objective

Solution

Passing the Affine2 as a neatly packed mat3x2 breaks WebGL with drawElementsInstanced: Buffer for uniform block is smaller than UNIFORM_BLOCK_DATA_SIZE.
I fixed this by using a mat3x3 instead.
Alternative solutions that come to mind:

  • Pass in a mat3x2 on non-webgl targets and a mat3x3 otherwise. I guess I could use #ifdef SIXTEEN_BYTE_ALIGNMENT for this, but it doesn't seem quite right? This would be more efficient, but decrease code quality.
  • Do something about UNIFORM_BLOCK_DATA_SIZE. I don't know how, so I'd need some guidance here.

@superdump let me know if you'd like me to implement other variants. Otherwise, I vote for merging this as a quick fix for main and then improving the packing in subsequent PRs :)

Additional notes

Ideally we should merge this before @JMS55 rebases #10164 so that they don't have to rebase everything a second time.

Copy link
Copy Markdown
Contributor

@afonsolage afonsolage left a comment

Choose a reason for hiding this comment

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

I can confirm this solved the issue (Windows 11, build for WebGl2), altho I'm not capable of saying if this fix may have some side effects.

@alice-i-cecile alice-i-cecile added this to the 0.14 milestone Feb 25, 2024
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen labels Feb 25, 2024
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Feb 25, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Feb 25, 2024
Merged via the queue into bevyengine:main with commit ad5d790 Feb 25, 2024
msvbg pushed a commit to msvbg/bevy that referenced this pull request Feb 26, 2024
# Objective

- Fixes bevyengine#12081

## Solution

Passing the `Affine2` as a neatly packed `mat3x2` breaks WebGL with
`drawElementsInstanced: Buffer for uniform block is smaller than
UNIFORM_BLOCK_DATA_SIZE.`
I fixed this by using a `mat3x3` instead.
Alternative solutions that come to mind:
- Pass in a `mat3x2` on non-webgl targets and a `mat3x3` otherwise. I
guess I could use `#ifdef SIXTEEN_BYTE_ALIGNMENT` for this, but it
doesn't seem quite right? This would be more efficient, but decrease
code quality.
- Do something about `UNIFORM_BLOCK_DATA_SIZE`. I don't know how, so I'd
need some guidance here.

@superdump let me know if you'd like me to implement other variants.
Otherwise, I vote for merging this as a quick fix for `main` and then
improving the packing in subsequent PRs :)

## Additional notes

Ideally we should merge this before @JMS55 rebases bevyengine#10164 so that they
don't have to rebase everything a second time.
msvbg pushed a commit to msvbg/bevy that referenced this pull request Feb 26, 2024
# Objective

- Fixes bevyengine#12081

## Solution

Passing the `Affine2` as a neatly packed `mat3x2` breaks WebGL with
`drawElementsInstanced: Buffer for uniform block is smaller than
UNIFORM_BLOCK_DATA_SIZE.`
I fixed this by using a `mat3x3` instead.
Alternative solutions that come to mind:
- Pass in a `mat3x2` on non-webgl targets and a `mat3x3` otherwise. I
guess I could use `#ifdef SIXTEEN_BYTE_ALIGNMENT` for this, but it
doesn't seem quite right? This would be more efficient, but decrease
code quality.
- Do something about `UNIFORM_BLOCK_DATA_SIZE`. I don't know how, so I'd
need some guidance here.

@superdump let me know if you'd like me to implement other variants.
Otherwise, I vote for merging this as a quick fix for `main` and then
improving the packing in subsequent PRs :)

## Additional notes

Ideally we should merge this before @JMS55 rebases bevyengine#10164 so that they
don't have to rebase everything a second time.
mockersf added a commit to mockersf/bevy that referenced this pull request Feb 28, 2024
mockersf added a commit to mockersf/bevy that referenced this pull request Feb 29, 2024
mockersf added a commit to mockersf/bevy that referenced this pull request Mar 19, 2024
mockersf added a commit to mockersf/bevy that referenced this pull request Apr 9, 2024
mockersf added a commit to mockersf/bevy that referenced this pull request Apr 9, 2024
@janhohenheim janhohenheim deleted the fix-webgl branch July 5, 2024 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebGL2: can't render StandardMaterial

5 participants