From 10bf9699ac5fdc17d037f8733c14134e4521f14f Mon Sep 17 00:00:00 2001 From: Martin Valigursky Date: Thu, 18 Jan 2024 12:20:01 +0000 Subject: [PATCH] [Fix] Fix additional shaders getting processed on WebGPU --- .../graphics/shader-processor-options.js | 2 +- src/platform/graphics/vertex-format.js | 21 ++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/platform/graphics/shader-processor-options.js b/src/platform/graphics/shader-processor-options.js index 6af88c71bcd..97e86a5917b 100644 --- a/src/platform/graphics/shader-processor-options.js +++ b/src/platform/graphics/shader-processor-options.js @@ -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; diff --git a/src/platform/graphics/vertex-format.js b/src/platform/graphics/vertex-format.js index 0905bb97c94..6343ec6804b 100644 --- a/src/platform/graphics/vertex-format.js +++ b/src/platform/graphics/vertex-format.js @@ -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('_');