Skip to content

Commit

Permalink
Update animometer to account for arbitrarily sized minUniformBufferOf…
Browse files Browse the repository at this point in the history
…fsetAlignment
  • Loading branch information
cmhhelgeson committed Dec 7, 2023
1 parent 08d811d commit b7503c7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/sample/animometer/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,16 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => {
function configure() {
const numTriangles = settings.numTriangles;
const uniformBytes = 5 * Float32Array.BYTES_PER_ELEMENT;
const alignedUniformBytes = Math.ceil(uniformBytes / 256) * 256;
const minBufferAllignment = device.limits.minUniformBufferOffsetAlignment;
let alignedUniformBytes = 0;
const blocks = Math.ceil(uniformBytes / minBufferAllignment);
if (uniformBytes < minBufferAllignment) {
alignedUniformBytes = blocks * minBufferAllignment;
} else {
// Number of minBufferAllignment Blocks occupied by our data
alignedUniformBytes = blocks * blocks * minBufferAllignment;
}

const alignedUniformFloats =
alignedUniformBytes / Float32Array.BYTES_PER_ELEMENT;
const uniformBuffer = device.createBuffer({
Expand Down

0 comments on commit b7503c7

Please sign in to comment.