0

I am looking for a way to fetch all available uniforms in a WGPU shader, essentially, I am looking for the wgpu equivalent of this OpenGL code:

   gl.GetProgramiv(id, GL_ACTIVE_UNIFORMS, &active_uniforms);

   for (int i = 0; i < active_uniforms; i++){
      GLsizei length;
      GLsizei size;
      GLenum type;
      GLchar name[max_name_length + 1] = { 0 };

      gl.GetActiveUniform(id, i, max_name_length, &length, &size, &type, name);
      name[length] = '\0';
      
      uniforms.push(...)
    }
    // iterate over all unifroms
    uint32 buffer_size = ...
    // create uniform buffer big enough to hold all of them

Context: I am writing a toy 2D renderer. I have a 'Material' class that is supposed to hold shader + uniform data.

It will upload the data to the GPU just before a render pass. I need to create a buffer for this uniform data, and I need to know how big this buffer should be. The size of the buffer, depends on the number of uniforms defined in the shader code.

maybe irrelevant: I am writing this in Typescript for the web, not Rust/C++

1 Answer 1

1

WebGPU does not provide any "uniform" data nor any other reflection data. It's up to you to compute the offsets yourself, use a tool, or to use a library.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.