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

Why are all storage buffers treated like runtime arrays ? #304

Open
rcmz opened this issue Feb 10, 2025 · 3 comments
Open

Why are all storage buffers treated like runtime arrays ? #304

rcmz opened this issue Feb 10, 2025 · 3 comments

Comments

@rcmz
Copy link

rcmz commented Feb 10, 2025

I'm trying to get the size of descriptor blocks.
For uniform buffers it seems to work, but for storage buffers block.size is zero.
This is caused by this bit of code in spirv_reflect.c :

bool is_parent_rta = (p_descriptor->descriptor_type == SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_BUFFER);
    result = ParseDescriptorBlockVariableSizes(p_parser, p_module, true, false, is_parent_rta, &p_descriptor->block);
    if (result != SPV_REFLECT_RESULT_SUCCESS) {
      return result;
    }

    if (is_parent_rta) {
      p_descriptor->block.size = 0;
      p_descriptor->block.padded_size = 0;
    }
  }

Why are all storage buffers treated runtime arrays ?
(I presume that's what is_parent_rta mean)

PS:
My wider goal is to make an automated system to create C structs that exactly represent shader block variables (with correct alignment and size).
I assume that is a common goal here, so if you have pointers to similar projects I'm interested.

@spencer-lunarg
Copy link
Contributor

@rcmz from what I can see this is working locally, can you provide some SPIR-V (or source GLSL/HLSL/Slang) where you are seeing this being a problem

@spencer-lunarg
Copy link
Contributor

@rcmz sorry, I think I see now

https://godbolt.org/z/TPeGEoqGq

The Storage Buffer variable itself doesn't have a size... yes, this seems wrong, will take a deeper look

@spencer-lunarg
Copy link
Contributor

final update - I realize the issue is HLSL/Slang don't have a concept of a "bound" storage buffer, all Storage Buffers in HLSL/Slang are always runtime arrays, so this is just a simple case of no one noticing (or no one creating an issue) that we forgot to get a proper size for things like GLSL

Have tests already, just busy with Vulkanize event this week, will hopefully have fix early next week

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

2 participants