这是indexloc提供的服务,不要输入任何密码
Skip to content

Support pack / unpack functions #988

@iraiter2

Description

@iraiter2

To implement vertex pulling, we need to bind vertex buffers as flat storage buffers, for example:
[[binding 0, set 0]] var<storage_buffer> vertexBuffer0 : [[block]] struct {
[[offset 0]] bufferData : [[stride 4]] array;
};

Then, reading from the buffer, we can obtain chunks of 4 bytes through the u32 bufferData. Currently, we would be able to read floats using "as<f32>(data)", and vectors by repeated reads.

The reason we need this is because attributes can refer to the same section of the buffer with different types, or have alignment problems (the alternative would be to try to generate some struct type which runs into these problems).

To be able to support vertex input formats such as "half" we need functions to unpack them, and probably include packing for consistency. These are available in GLSL std 450 under the following names:
PackSnorm4x8
PackUnorm4x8
PackSnorm2x16
PackUnorm2x16
PackHalf2x16
PackDouble2x32

UnpackSnorm4x8
UnpackUnorm4x8
UnpackSnorm2x16
UnpackUnorm2x16
UnpackHalf2x16
UnpackDouble2x32

Is there anything we need to add or would this be covered by importing GLSL.std.450? Should these be WGSL functions usable without an import?

Metadata

Metadata

Assignees

Labels

wgslWebGPU Shading Language Issues

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions