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

Helper for writing gpu data #167

Open
QuantumEntangledAndy opened this issue Apr 25, 2022 · 1 comment
Open

Helper for writing gpu data #167

QuantumEntangledAndy opened this issue Apr 25, 2022 · 1 comment

Comments

@QuantumEntangledAndy
Copy link
Contributor

Gpu data like uniforms and storage need special rules for alignement of data. It would be nice if we have some sort of convenince methods that would automatically align data and place data.

For example consider a matrix of 3x3. On the gpu the data is arranged as:
m11, m12, m13, PAD_BYTE, m21, m22, m23, PAD_BYTE, m31, m32, m33, PAD_BYTE
due to how the data is 16byte aligned

Similaraly for vec3 it is also 16byte aliged so that a structure of kind:

Struct Example {
  a: vec3<f32>,
  b: vec3<f32>,
}

Is actually in memory

Struct ExampleOnCpu {
  a: [f32; 3],
  pad_a: f32,
  b: [f32; 3],
  pad_b: f32,
}

Having some way to consistenty serialise this would reduce code complexity and reduce errors caused by missunderstood alignments

@voxelias
Copy link
Member

I agree we need some rules. And I like your suggestion with pad_ prefix with name of padded property.
You suggest to write down rules somewhere? Or prepare some tool to handle this? Like macro or something?

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

No branches or pull requests

2 participants