Skip to content

Conversation

@zeozeozeo
Copy link
Contributor

Previously SetStorageBuffer would always assume the renderpass's bind group even if we have a compute pass active.

Repro:

#include <raygpu.h>
#include <cstdio>

void setup() {
    const char* shaderCode = R"(
@group(0) @binding(0) var<storage, read_write> b0: array<u32>;
@group(0) @binding(1) var<storage, read_write> b1: array<u32>;
@group(0) @binding(2) var<storage, read_write> b2: array<u32>;
@group(0) @binding(3) var<storage, read_write> b3: array<u32>;
@group(0) @binding(4) var<storage, read_write> b4: array<u32>;

@compute @workgroup_size(1)
fn main() {
    b4[0] = 123u;
}
    )";

    ResourceTypeDescriptor resources[] = {
        { storage_buffer, 0, 0, access_type_readwrite, we_dont_know, RGShaderStage_Compute },
        { storage_buffer, 0, 1, access_type_readwrite, we_dont_know, RGShaderStage_Compute },
        { storage_buffer, 0, 2, access_type_readwrite, we_dont_know, RGShaderStage_Compute },
        { storage_buffer, 0, 3, access_type_readwrite, we_dont_know, RGShaderStage_Compute },
        { storage_buffer, 0, 4, access_type_readwrite, we_dont_know, RGShaderStage_Compute },
    };

    DescribedComputePipeline* pipeline = LoadComputePipelineEx(shaderCode, resources, 5);

    DescribedBuffer* buffers[5];
    uint32_t data = 0;
    
    for(int i = 0; i < 5; i++) {
        buffers[i] = GenBufferEx(&data, sizeof(uint32_t), RGBufferUsage_Storage | RGBufferUsage_CopyDst);
    }

    BeginComputepass();
    BindComputePipeline(pipeline);

    for(int i = 0; i < 5; i++) {
        printf("SetStorageBuffer(%d, ...)\n", i); 
        SetStorageBuffer(i, buffers[i]);
    }

    DispatchCompute(1, 1, 1);
    EndComputepass();
}

void render() {
    BeginDrawing();
    ClearBackground(RAYWHITE);
    EndDrawing();
}

int main(void) {
    SetConfigFlags(FLAG_VSYNC_HINT);
    ProgramInfo program = {
        .windowWidth = 800,
        .windowHeight = 600,
        .setupFunction = setup,
        .renderFunction = render,
    };
    InitProgram(program);
    return 0;
}

The above would print:

entry count: 5
ERROR: >> Validation error: Binding entry buffer not set.
 - While validating entries[0] against { binding: 0, visibility: ShaderStage::Compute, buffer: {type: BufferBindingType::Storage, minBindingSize: 0, hasDynamicOffset: 0} }.
 - While validating [BindGroupDescriptor] against [BindGroupLayout (unlabeled)]
 - While calling [Device].CreateBindGroup([BindGroupDescriptor]).

SetStorageBuffer(0, ...)
SetStorageBuffer(1, ...)
SetStorageBuffer(2, ...)
SetStorageBuffer(3, ...)
SetStorageBuffer(4, ...)
WARNING: Trying to set entry 4 on a BindGroup with only 4 entries

This fixes that.

@manuel5975p manuel5975p merged commit 80e2e42 into manuel5975p:master Dec 10, 2025
9 checks passed
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

Successfully merging this pull request may close these issues.

2 participants