Skip to content

Make animate_shader example work on WASM#4814

Closed
johanhelsing wants to merge 2 commits intobevyengine:mainfrom
johanhelsing:fix-animate-shader-on-wasm
Closed

Make animate_shader example work on WASM#4814
johanhelsing wants to merge 2 commits intobevyengine:mainfrom
johanhelsing:fix-animate-shader-on-wasm

Conversation

@johanhelsing
Copy link
Contributor

@johanhelsing johanhelsing commented May 20, 2022

Previously, it would draw nothing and complain with the following
console warnings:

Firefox:

WebGL warning: drawElementsInstanced: Buffer for uniform block is smaller than UNIFORM_BLOCK_DATA_SIZE

Chrome:

[.WebGL-00003B081B72A300] GL_INVALID_OPERATION: It is undefined behaviour to use a uniform buffer that is too small.

Objective

Fixes: #4813

Solution

  • I looked at some other code regarding uniforms that worked on wasm and tried to do the same thing (Derive AsStd140 and use std140_size_static).
  • Use UniformBuffer and ShaderType
  • Add annotation to align to 16 bytes, so WebGL is happy

My understanding of how uniform buffers work is a bit lacking, so please review carefully ;)


Changelog

  • The animate_shader example now works on wasm

@johanhelsing
Copy link
Contributor Author

Ok, so this needs to be rebased after the encase pr #4339 which changes how uniform buffers are handled.

Seems like ShaderType and its min_size is the thing now, but I can't really test it on wasm yet due to #4811

@johanhelsing johanhelsing marked this pull request as draft May 20, 2022 17:35
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior C-Examples An addition or correction to our examples O-Web Specific to web (WASM) builds labels May 20, 2022
Previously, it would draw nothing and complain with the following
console warnings:

Firefox:

WebGL warning: drawElementsInstanced: Buffer for uniform block is smaller than UNIFORM_BLOCK_DATA_SIZE

Chrome:

[.WebGL-00003B081B72A300] GL_INVALID_OPERATION: It is undefined behaviour to use a uniform buffer that is too small.

Issue: bevyengine#4813
Use ShaderType/UniformBuffer
@johanhelsing johanhelsing force-pushed the fix-animate-shader-on-wasm branch from 1a15f35 to 67aad46 Compare May 21, 2022 08:11
@johanhelsing johanhelsing marked this pull request as ready for review May 21, 2022 08:17
@johanhelsing
Copy link
Contributor Author

Rebased after encase migration and the fix for wasm panicking.

Ready for review now :)

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it A-Rendering Drawing game state to the screen and removed S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Oct 10, 2022
@hymm hymm self-requested a review December 26, 2022 02:07
@johanhelsing
Copy link
Contributor Author

No longer relevant, time is exposed through globals (animate_shader example running since 1170b30 #6460)

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 C-Examples An addition or correction to our examples O-Web Specific to web (WASM) builds

Projects

None yet

Development

Successfully merging this pull request may close these issues.

animate_shader example doesn't work on wasm

2 participants