Sharing a modified uniform between draw calls #4017
ollelogdahl
started this conversation in
General
Replies: 1 comment
-
The way I currently do this is have an instance buffer which I fill using a Sketch of putting this into your code: let mut instance_data: Vec<Vec3> = Vec::with_capacity(chunk_meshes.len());
todo!("also make sure self.instance_buffer is big enough");
{
let mut render_pass = encoder.begin_render_pass(...);
render_pass.set_vertex_buffer(1, self.instance_buffer.slice(..));
for (instance_index, chunk) in (0..).zip(chunk_meshes) {
// This data will be written to the buffer later, but before submit
instance_data.push(chunk.chunk_position.map(|i| i as f32 * 32.0).to_homogeneous().truncate());
render_pass.set_vertex_buffer(0, chunk.vertex_buffer.slice(..));
render_pass.draw(0..chunk.vertex_count, instance_index..(instance_index + 1));
}
}
queue.write_buffer(&self.instance_buffer, bytemuck::cast_slice(instance_data.as_slice()));
self.queue.submit([encoder.finish()]); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to share a uniform buffer between multiple draw calls in a render pass, but I'm having some issues getting it working.
I have a shared uniform for the model-view-projection matrix, that performs a
write_buffer
into the shared buffer, which I'm awareonly updates after the next
submit()
. I did this believing I can share the uniform between multiple render passes, and also to improveperformance.
I understand that one solution would be to split the model, view, and projection matrices into different buffers and only update
the model-matrix; performing the calculation in-shader.
Bellow, I have the code that doesn't work right now. I assume I have modeled this a little weird. What would a good/conventional
way to share/update the buffer immediately?
Thank you :)
Beta Was this translation helpful? Give feedback.
All reactions