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

Add padded static size and recursive padding to crevice and use it #18

Open
wants to merge 29 commits into
base: pipelined-rendering
Choose a base branch
from

Conversation

superdump
Copy link

@superdump superdump commented Jul 1, 2021

This appears to work just fine for rounding up the sizes. We had the code already for rounding up sizes to the struct alignment in UniformVec for item sizes so I just moved that into crevice as a std140_padded_size_static and tested it - it returns what wgpu expects for wgsl for GpuLights and ViewUniform min_binding_size at least. I'll let them decide if it is fully correct, but if it isn't then we need to fix UniformVec too I expect.

cart and others added 18 commits June 4, 2021 15:50
Renamed PipelineDescriptor to RenderPipelineDescriptor
StandardMaterial flat values
* bevy_pbr2: Add support for most of the StandardMaterial textures

Normal maps are not included here as they require tangents in a vertex attribute.

* bevy_pbr2: Ensure RenderCommandQueue is ready for PbrShaders init

* texture_pipelined: Add a light to the scene so we can see stuff

* WIP bevy_pbr2: back to front sorting hack

* bevy_pbr2: Uniform control flow for texture sampling in pbr.frag

From 'fintelia' on the Bevy Render Rework Round 2 discussion:

"My understanding is that GPUs these days never use the "execute both branches
and select the result" strategy. Rather, what they do is evaluate the branch
condition on all threads of a warp, and jump over it if all of them evaluate to
false. If even a single thread needs to execute the if statement body, however,
then the remaining threads are paused until that is completed."

* bevy_pbr2: Simplify texture and sampler names

The StandardMaterial_ prefix is no longer needed

* bevy_pbr2: Match default 'AmbientColor' of current bevy_pbr for now

* bevy_pbr2: Convert from non-linear to linear sRGB for the color uniform

* bevy_pbr2: Add pbr_pipelined example

* Fix view vector in pbr frag to work in ortho

* bevy_pbr2: Use a 90 degree y fov and light range projection for lights

* bevy_pbr2: Add AmbientLight resource

* bevy_pbr2: Convert PointLight color to linear sRGB for use in fragment shader

* bevy_pbr2: pbr.frag: Rename PointLight.projection to view_projection

The uniform contains the view_projection matrix so this was incorrect.

* bevy_pbr2: PointLight is an OmniLight as it has a radius

* bevy_pbr2: Factoring out duplicated code

* bevy_pbr2: Implement RenderAsset for StandardMaterial

* Remove unnecessary texture and sampler clones

* fix comment formatting

* remove redundant Buffer:from

* Don't extract meshes when their material textures aren't ready

* make missing textures in the queue step an error

Co-authored-by: Aevyrie <aevyrie@gmail.com>
Co-authored-by: Carter Anderson <mcanders1@gmail.com>
Force main thread for prepare_windows system
bevy_pbr2: Fix light uniforms
This rounds up the size to the struct's alignment. This allows interoperability with wgsl.
@superdump
Copy link
Author

Looking at the wgsl spec: https://www.w3.org/TR/WGSL/#alignment-and-size

For wgsl: it looks like a struct's alignment is the maximum alignment of its members. And a struct's size is the offset of the last member of the struct, plus the size of the last member of the struct (which is what std140_size_static() returns, unless I am mistaken) rounded up to the alignment of the struct, which is what the Std140Type::ALIGNMENT is. So I think this should be correct for structs.

I think implicit-stride arrays work the same way as glsl arrays, except that glsl seems to say things about aligning to vec4 unconditionally in some situations:

  1. If the member is a scalar consuming N basic machine units, the base alignment is N.
  2. If the member is a two- or four-component vector with components consuming N basic machine units, the base alignment is 2N or 4N, respectively.
  3. If the member is a three-component vector with components consuming N basic machine units, the base alignment is 4N.
  4. If the member is an array of scalars or vectors, the base alignment and array stride are set to match the base alignment of a single array element, according to rules (1), (2), and (3), and rounded up to the base alignment of a vec4. The array may have padding at the end; the base offset of the member following the array is rounded up to the next multiple of the base alignment.

It's not exactly clear to me what the rounded up to the base alignment of a vec4 means. Is it talking about the size?

@superdump
Copy link
Author

I'll keep the discussion going over there, but I found an error case: LPGhatguy/crevice#29 (comment)

@superdump superdump changed the title Add padded static size to crevice and use it Add padded static size and recursive padding to crevice and use it Jul 4, 2021
@cart cart force-pushed the pipelined-rendering branch 2 times, most recently from 05bd717 to 955c79f Compare July 24, 2021 23:43
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.

6 participants