#AsBindGroup macro error

4 messages · Page 1 of 1 (latest)

north plover
#
#[derive(Asset, Clone, Reflect, AsBindGroup)]
pub struct OutlineMaterial {
    #[uniform(0)]
    pub color: Vec4,

    #[storage(1)]
    pub(crate) map_texture: Vec<u32>,

    #[texture(2)]
    #[sampler(3)]
    pub texture: Handle<Image>,
}

This is my code, and its error is:

mismatched types
expected reference `&bevy::prelude::Handle<ShaderStorageBuffer>`
   found reference `&std::vec::Vec<u32>`

I think there should be a problem with this

#[storage(1)]
pub(crate) map_texture: Vec<u32>,

But how should I fix it? This code was found in other open source projects, but that project relies on bevy0.12, so it may have been modified by bevy in the future. What should I do?

untold isle
#

Check out https://docs.rs/bevy/latest/bevy/render/render_resource/trait.AsBindGroup.html It looks like the storage type needs to be a Handle<Storage> See also https://docs.rs/bevy/latest/bevy/render/storage/struct.ShaderStorageBuffer.html You'll have to register the asset, etc, but hopefully that fixes the problem. Here's a good example: https://bevyengine.org/examples/shaders/storage-buffer/

north plover
# untold isle Check out https://docs.rs/bevy/latest/bevy/render/render_resource/trait.AsBindGr...

thanks, Another question is, how should I modify the value of one of the items in the F32 list that I put into ShaderWarehousBuffer after it is created? I looked at its definition and only found ways to set values for 'from' and 'set_data'. However, this is to set the overall data, not just any specific item, because my idea is that if I have data that needs to be modified, it's best to only modify the parts that need to be modified.

untold isle
# north plover thanks, Another question is, how should I modify the value of one of the items i...

I’m no expert here, but I’m not aware of a way to do this either. In general, buffers are sent and received from the gpu in bulk since that’s the most efficient. I’m not even sure if the drivers support modifying a single value in a buffer.

That’s not to say it’s impossible, I just don’t know of a way to do it. Plus, reading and writing buffers from the gpu are generally optimized for throughput instead of latency I think, so even if this was possible, IDK how much of a performance difference it would make compared to updating the whole buffer.

One way you might be able to fake this is to have a uniforms that store a index and updated value, and just update the buffer with those values at the start of the shader, but again, if you’re updating more than one value per frame, it’s probably not worth it.

Sorry that’s not a perfect answer. Maybe someone else has more information or knows something I don’t.