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

getting In Queue::write_buffer Copy of 0..32 would end up overrunning the bounds of the Destination buffer of size 16 when trying to write to buffer #10

Open
NewUser69420 opened this issue Feb 3, 2024 · 1 comment

Comments

@NewUser69420
Copy link

this is my shader code:

@group(0) @binding(0) var<storage,read> firstArray: array<f32>;
@group(0) @binding(1) var<storage,read> secondArray: array<f32>;
@group(0) @binding(2) var<storage,read_write> resultArray: array<f32>;

@compute @workgroup_size(1, 1, 1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
    let index: u32 = global_id.x;

    resultArray[index] = firstArray[index] + secondArray[index];
}

and the code in bevy:

fn calc_gpu_things(mut compute_worker: ResMut<AppComputeWorker<SimpleComputeWorker>>) {
    if !compute_worker.ready() {
        return;
    };

    compute_worker.write_slice("firstArray", &[2.0, 3.0, 5.0, 6.0]);
    //compute_worker.write("secondArray", &[2.0, 3.0, 4.0, 5.0]);
    let result: [f32; 4] = compute_worker.read("resultArray");

    println!("got {:?}", result);
}

#[derive(TypeUuid)]
#[uuid = "2545ae14-a9bc-4f03-9ea4-4eb43d1075a7"]
struct SimpleShader;

impl ComputeShader for SimpleShader {
    fn shader() -> ShaderRef {
        "compute1.wgsl".into()
    }
}

#[derive(Resource)]
struct SimpleComputeWorker;

impl ComputeWorker for SimpleComputeWorker {
    fn build(world: &mut World) -> AppComputeWorker<Self> {
        let worker = AppComputeWorkerBuilder::new(world)
            // Add a staging buffer, it will be available from
            // both CPU and GPU land.
            .add_staging("firstArray", &[2.0, 3.0, 4.0, 5.0])
            .add_staging("secondArray", &[2.0, 3.0, 4.0, 5.0])
            .add_staging("resultArray", &[0.0, 0.0, 0.0, 0.0])
            // Create a compute pass from your compute shader
            // and define used variables
            .add_pass::<SimpleShader>([4, 1, 1], &["firstArray", "secondArray", "resultArray"])
            .build();

        worker
    }
}

and the panic i get during run time:

thread 'Compute Task Pool (4)' panicked at C:\Users\bramb\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wgpu-0.17.2\src\backend\direct.rs:3056:5:
wgpu error: Validation Error

Caused by:
    In Queue::write_buffer
    Copy of 0..32 would end up overrunning the bounds of the Destination buffer of size 16
@NewUser69420
Copy link
Author

i found the problem, i had to do: &[2.0f32, 3,0, 4.0, 5.0] to make it into an f32, not f64

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

1 participant