Aliasing storage buffers in WGSL #3994
-
|
In JavaScript (and C/C++) it's easy to view raw data as different things. const ab = new ArrayBuffer(1000);
const asFloat32 = new Float32Array(ab);
const asUint32 = new Uint32Array(ab);
const asInt16 = new Int16Array(ab);
const asUint8 = new Uint8Array(ab);struct MyStruct {
float speed;
uint32_t count;
};
...
void* p = malloc(1000);
float* asFloat = reinterpret_cast<float*>(p);
uint32_t* asUint32 = reinterpret_cast<uint32_t*>(p);
int16_t* asInt16 = reinterpret_cast<int16_t*>(p);
uint8_t* asUint8 = reinterpret_cast<uint8_t*>(p);
MyStruct* asStruct = reinterpret_cast<MyStruct*>(p);Can I do the same with a storage buffer in WGSL? Read only storage buffers would be fine. Ideally without having to waste a binding for each different type. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
@dneto0 , brandon suggested asking you. |
Beta Was this translation helpful? Give feedback.
-
|
This is not currently possible in WGSL. You would have manually write the conversions from some base type (e.g. There is certainly desire for more fully featured pointers, but that won't make the initial release. |
Beta Was this translation helpful? Give feedback.
This is not currently possible in WGSL. You would have manually write the conversions from some base type (e.g.
array<u32>) to the various types you need. Example:There is certainly desire for more fully featured pointers, but that won't make the initial release.