profile
viewpoint

issue openedgpuweb/gpuweb

Uniform buffer block size issue on Metal

On Metal, it is required that the size of the constant buffer must be no less than the size of the constant buffer structure defined in shader, and the overall size of the structure declared in the constant buffer is aligned to the largest base alignment of its members.

For example, considering the following constant buffer declaration,

struct Block {
    float4 color;
    float depth;
};

fragment FragOut main(constant Block& uBuffer [[buffer(0)]]) {
    ...
}

As the largest alignment of the attribute (float4) is 16 bytes, the actual size of uBuffer is 32 bytes, so when we bind a buffer with 20 bytes in bind group, the Metal validation layer will report the following validation error:

Fragment Function(main0): argument uBuffer[0] from buffer(0) with offset(0) and length(20) has space for 20 bytes, but argument has a length(32)

For constant buffer declaration below, as the largest alignment of the attribute of uBuffer is 16 bytes, the size of the constant buffer bound to [[buffer(0)]] must be at least 48 bytes.

struct Block {
    float2 a;
    float3 b;
    float4 c;
};

fragment FragOut main(constant Block& uBuffer [[buffer(0)]]) {
    ...
}

There is a similar issue on gfx-rs: https://github.com/gfx-rs/wgpu/issues/185

In conclusion, in WebGPU we should validate the size of the uniform buffer bound in bind group must be no less than the size of the uniform block declared in shader, and the computation of the uniform block size must be compatible with the algorithm in Metal.

created time in 2 days

PR opened KhronosGroup/Vulkan-Docs

Compatible pathlib for py2 and py3 in script/generator.py

pathlib name is not compatible in python2 and python3, it's named pathlib2 in python2.

Fixes #1011

+4 -1

0 comment

1 changed file

pr created time in 25 days

create barnchhaoxli/Vulkan-Docs

branch : pathlib-py2

created branch time in 25 days

fork haoxli/Vulkan-Docs

The Vulkan API Specification and related tools

fork in 25 days

issue openedKhronosGroup/Vulkan-Docs

Incompatible moudle pathlib for py2 and py3 in script/generator.py

https://github.com/KhronosGroup/Vulkan-Docs/blob/master/scripts/generator.py

from pathlib import Path

The script throws import error 'No module named pathlib' in environment with python2, becuase pathlib is named pathlib2 in python2.

created time in 25 days

create barnchhaoxli/Vulkan-Headers

branch : pathlib

created branch time in a month

fork haoxli/Vulkan-Headers

Vulkan Header files and API registry

fork in a month

more