Wgpu-rs: Dynamically uniform expression (`.length()` for arrays in SSBOs) not working

Created on 19 Feb 2020  路  7Comments  路  Source: gfx-rs/wgpu-rs

This might be related to the following issues: #36, #53. I'm aware that wgpu is not concerend with shader compilation yet, I still hope there might be somebody who can shed some light on this issue. Thank you!

In the following code snippet, the .length() call does not work:

layout(std430, set = 0, binding = 1) buffer History {
    uint history[];
};

void main() {
    ...
    uint len = history.length();
    ...
}

However, if I set uint history[1000]; it works as expected. As far as I can tell from the GLSL specification this should work. An example can be found here.

I'm runnning wgpu-rs on macOS with shaderc-rs to create SPIR-V from GLSL files. The initial buffer is created using the following code (the range is set accordingly):

let history_buffer_size = 1000 as u64 * 4;

let history_buffer = device.create_buffer(&wgpu::BufferDescriptor{
    size: history_buffer_size,
    usage: wgpu::BufferUsage::STORAGE |
           wgpu::BufferUsage::STORAGE_READ |
           wgpu::BufferUsage::COPY_DST,
    });
bug

Most helpful comment

1090000000 * 4 is very close to the maximum value for a 32 bit unsigned integer. Just as an observation. I would suspect that it returns 4294967296/4 = 1073741824.

All 7 comments

Thank you for filing! What is the exact error you are getting?

Sorry for being so vague, I didn't really know how I would best approach debugging this. It seems like the result from .length() is really large.

A crude gauging with outColor = vec4(vec3(float(history.length()) / 1090000000.0), 1); yields a very light gray. This corresponds to roughly 1'090'000'000 uints or about 4.36 GB memory. I have a Radeon Pro 580 with 8 GB VRAM. I also tested on a Radeon VII eGPU and the results are the same.

1090000000 * 4 is very close to the maximum value for a 32 bit unsigned integer. Just as an observation. I would suspect that it returns 4294967296/4 = 1073741824.

Nice find! outColor = vec4(vec3(float(history.length()) / 1073741824.0), 1.0); results in 0xFFFFFF so I think you're right. That's kind of a weird number, though.

Keep in mind that colors saturate at OxFFFFFF. So I'd test with a number twice as large to see if it yields 127,127,127.

Hmm, outColor = vec4(vec3(float(history.length()) / (2*1073741824.0)), 1.0); results in 188,188,188. Could this be the result of gamma correction?

I'd expect gamma correction to lead to either the square or square root value. However 188/255 = 0.737 and 0.737^2 = 0.543 so I don't think so. Unless there is something else going on too.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

roman-holovin picture roman-holovin  路  4Comments

RazrFalcon picture RazrFalcon  路  3Comments

JoshuaBatty picture JoshuaBatty  路  5Comments

OptimisticPeach picture OptimisticPeach  路  3Comments

MarioSieg picture MarioSieg  路  4Comments