Skip to content

Commit 7b53f51

Browse files
committed
Use slightly faster cache key
1 parent cda1475 commit 7b53f51

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

src/webgpu/p5.RendererWebGPU.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ function rendererWebGPU(p5, fn) {
590590
// global so that we can reuse the last used buffer when uniform values
591591
// don't change.
592592
shader._uniformBufferGroups = [];
593+
shader.buffersDirty = new Set();
593594

594595
for (const group of shader._uniformGroups) {
595596
// Calculate the size needed for this group's uniforms
@@ -603,7 +604,7 @@ function rendererWebGPU(p5, fn) {
603604
shader._uniformBufferGroups.push({
604605
group: group.group,
605606
binding: group.binding,
606-
cacheKey: group.group + ',' + group.binding,
607+
cacheKey: group.group * 1000 + group.binding,
607608
varName: group.varName,
608609
structType: group.structType,
609610
uniforms: groupUniforms,
@@ -1461,7 +1462,7 @@ function rendererWebGPU(p5, fn) {
14611462
passEncoder.setStencilReference(1);
14621463
}
14631464
// Bind vertex buffers
1464-
for (const buffer of this._getVertexBuffers(currentShader)) {
1465+
for (const buffer of currentShader._vertexBuffers || this._getVertexBuffers(currentShader)) {
14651466
const location = currentShader.attributes[buffer.attr].location;
14661467
const gpuBuffer = buffers[buffer.dst];
14671468
passEncoder.setVertexBuffer(location, gpuBuffer, 0);
@@ -1504,8 +1505,7 @@ function rendererWebGPU(p5, fn) {
15041505
bufferInfo.data.byteLength
15051506
);
15061507

1507-
currentShader.buffersDirty = currentShader.buffersDirty || {};
1508-
currentShader.buffersDirty[bufferGroup.group + ',' + bufferGroup.binding] = false;
1508+
currentShader.buffersDirty.delete(bufferGroup.group * 1000 + bufferGroup.binding);
15091509
currentShader._cachedBindGroup[bufferGroup.group] = undefined;
15101510

15111511
// Cache this buffer and data for next frame
@@ -1514,10 +1514,10 @@ function rendererWebGPU(p5, fn) {
15141514
}
15151515
}
15161516
for (const sampler of currentShader.samplers) {
1517-
const key = sampler.group + ',' + sampler.binding;
1518-
if (currentShader.buffersDirty[key]) {
1517+
const key = sampler.group * 1000 + sampler.binding;
1518+
if (currentShader.buffersDirty.has(key)) {
15191519
currentShader._cachedBindGroup[sampler.group] = undefined;
1520-
currentShader.buffersDirty[key] = false;
1520+
currentShader.buffersDirty.delete(key);
15211521
}
15221522
}
15231523

@@ -1668,7 +1668,7 @@ function rendererWebGPU(p5, fn) {
16681668
_hasGroupDataChanged(shader, bufferGroup) {
16691669
// First time
16701670
if (!bufferGroup.currentBuffer) return true;
1671-
return shader.buffersDirty?.[bufferGroup.group + ',' + bufferGroup.binding];
1671+
return shader.buffersDirty.has(bufferGroup.group * 1000 + bufferGroup.binding);
16721672
}
16731673

16741674
_parseStruct(shaderSource, structName) {
@@ -1926,8 +1926,7 @@ function rendererWebGPU(p5, fn) {
19261926
} else {
19271927
uniform._mappedData = this._mapUniformData(uniform, uniform._cachedData);
19281928
}
1929-
shader.buffersDirty = shader.buffersDirty || {};
1930-
shader.buffersDirty[uniform.group + ',' + uniform.binding] = true;
1929+
shader.buffersDirty.add(uniform.group * 1000 + uniform.binding);
19311930
}
19321931

19331932
_updateTexture(uniform, tex) {

0 commit comments

Comments
 (0)