Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Fix additional shaders getting processed on WebGPU #5952

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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