Skip to content

Commit

Permalink
[Fix] Fix additional shaders getting processed on WebGPU (#5952)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
  • Loading branch information
mvaligursky and Martin Valigursky authored Jan 18, 2024
1 parent f667fbf commit c566c15
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/platform/graphics/shader-processor-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class ShaderProcessorOptions {

// WebGPU shaders are processed per vertex format
if (device.isWebGPU) {
key += this.vertexFormat?.renderingHashString;
key += this.vertexFormat?.shaderProcessingHashString;
}

return key;
Expand Down
21 changes: 9 additions & 12 deletions src/platform/graphics/vertex-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,32 +255,29 @@ class VertexFormat {
* @private
*/
_evaluateHash() {
let stringElementBatch;
const stringElementsBatch = [];
let stringElementRender;
const stringElementsRender = [];
const len = this._elements.length;
for (let i = 0; i < len; i++) {
const element = this._elements[i];
const { name, dataType, numComponents, normalize, offset, stride, size, asInt } = this._elements[i];

// create string description of each element that is relevant for batching
stringElementBatch = element.name;
stringElementBatch += element.dataType;
stringElementBatch += element.numComponents;
stringElementBatch += element.normalize;
const stringElementBatch = name + dataType + numComponents + normalize + asInt;
stringElementsBatch.push(stringElementBatch);

// create string description of each element that is relevant for rendering
stringElementRender = stringElementBatch;
stringElementRender += element.offset;
stringElementRender += element.stride;
stringElementRender += element.size;
const stringElementRender = stringElementBatch + offset + stride + size;
stringElementsRender.push(stringElementRender);
}

// sort batching ones alphabetically to make the hash order independent
stringElementsBatch.sort();
this.batchingHash = hashCode(stringElementsBatch.join());
const batchingString = stringElementsBatch.join();
this.batchingHash = hashCode(batchingString);

// shader processing hash - all elements that are used by the ShaderProcessor processing attributes
// at the moment this matches the batching hash
this.shaderProcessingHashString = batchingString;

// rendering hash
this.renderingHashString = stringElementsRender.join('_');
Expand Down

0 comments on commit c566c15

Please sign in to comment.