mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-18 14:19:30 -07:00
I believe I've added support for generating the array buffer for layouts ending in runtime-sized arrays to gpu-uniforms.js.
This commit is contained in:
@@ -1,16 +1,14 @@
|
|||||||
/** PLAN
|
/**
|
||||||
*
|
*
|
||||||
* Note: This should go in its own repo
|
* Meant to conform to the WGSL spec:
|
||||||
*
|
|
||||||
* Address every TODO item
|
|
||||||
*
|
*
|
||||||
* https://gpuweb.github.io/gpuweb/wgsl/#alignment-and-size
|
* https://gpuweb.github.io/gpuweb/wgsl/#alignment-and-size
|
||||||
* https://gpuweb.github.io/gpuweb/wgsl/#structure-layout-rules
|
* https://gpuweb.github.io/gpuweb/wgsl/#structure-layout-rules
|
||||||
*
|
*
|
||||||
* Create tests (maybe mocha?)
|
* TODO:
|
||||||
*
|
* - Put in own repo
|
||||||
* Document
|
* - create mocha tests
|
||||||
* - examples of the simple constructor and from WGSL
|
* - Document. Provide examples of the simple constructor and from WGSL
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@@ -157,7 +155,7 @@ const parseStruct = (str, structLayouts) => {
|
|||||||
|
|
||||||
const minSizeInBytes = byteOffset * BYTES_PER_ELEMENT;
|
const minSizeInBytes = byteOffset * BYTES_PER_ELEMENT;
|
||||||
const align = Math.max(...fields.map((field) => field.align));
|
const align = Math.max(...fields.map((field) => field.align));
|
||||||
const size = Math.ceil(minSizeInBytes / align) * align; // TODO: support runtime-sized arrays
|
const size = Math.ceil(minSizeInBytes / align) * align;
|
||||||
return { name, fields, size, align };
|
return { name, fields, size, align };
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -211,7 +209,14 @@ const makeGenerator = (layout, structLayouts) => {
|
|||||||
minSize,
|
minSize,
|
||||||
create: () => makeDataForLayout(structLayouts, layout),
|
create: () => makeDataForLayout(structLayouts, layout),
|
||||||
write: (object, destination, warnMissingFields = false) => {
|
write: (object, destination, warnMissingFields = false) => {
|
||||||
destination ??= new ArrayBuffer(layout.size); // TODO: expand to support runtime-sized arrays, via the length of the array on the data object
|
if (destination == null) {
|
||||||
|
let size = layout.size;
|
||||||
|
const lastField = layout.fields[layout.fields.length - 1];
|
||||||
|
if (lastField.isArray && lastField.name in object) {
|
||||||
|
size += lastField.stride * object[lastField.name].length;
|
||||||
|
}
|
||||||
|
destination = new ArrayBuffer(size);
|
||||||
|
}
|
||||||
|
|
||||||
const views = {
|
const views = {
|
||||||
i32: new Int32Array(destination),
|
i32: new Int32Array(destination),
|
||||||
|
|||||||
Reference in New Issue
Block a user