Comments (1)
ModelVertex
doesn't need padding because it's only used in a vertex buffer and you have to specify the VertexBufferLayout for those. This means that the vertex pipeline knows the exact offsets of the data you're trying to pass in.
Uniform layout is a special case and it does require padding. By default uniform blocks use the std140
alignment standard. You can read about alignment in the wgpu spec, and I have started a write up discussing in more detail.
From what I've read the reasoning this is performance. Rather than query the offsets for all the fields, the gpu simply expects fields to be at certain locations in memory. It takes whatever data is at that memory location and sends it to the shader. This means that if your struct is not padded correctly your shader will be pulling from the wrong parts of the struct. If ModelVertex
were used as a uniform buffer position
would overlap tex_coords
in the shader meaning that tex_coords.x
in the shader would map to tex_coords[1]
in Rust.
from learn-wgpu.
Related Issues (20)
- Panic on texture example on Linux HOT 1
- Can't run tutorial examples from chapter 2 HOT 7
- Rebuild Pong HOT 1
- MouseMotion delta is not precise HOT 3
- In `tutorial1_window` I get a compiler error that something is not a future. HOT 1
- surface_format in "The Surface" breaking change for wpgu version 0.16.0 HOT 3
- Compiler errors after finishing the new() method for State HOT 1
- Safety note for create_surface appears off HOT 2
- Viewing Old Versions HOT 2
- OPENGL_TO_WGPU_MATRIX constant for NDC conversion is incorrect HOT 2
- dark theme / use mdBook HOT 1
- a correction is needed
- What is the purpose of "window_id == state.window().id()"?
- Code for `learn-wgpu/code/beginner/tutorial3-pipeline/src/challenge.wgsl` doesn't work HOT 3
- `bytemuck` isn't listed in dependencies for "Learn Wgpu" but is used HOT 1
- The "Color Correction" paragraph is incorrect (or misleading) HOT 3
- compiler error HOT 4
- More about compute shader HOT 2
- Update to 0.17 HOT 1
- Why is the triangle color a rainbow ? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from learn-wgpu.