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

WebGPURenderer: Fix missing updates to geometry attributes #29589

Merged
merged 7 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
180 changes: 180 additions & 0 deletions src/materials/nodes/manager/NodeMaterialObserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class NodeMaterialObserver {

data = {
material: this.getMaterialData( renderObject.material ),
geometry: this.getGeometryData( renderObject.geometry ),
worldMatrix: renderObject.object.matrixWorld.clone()
};

Expand Down Expand Up @@ -168,6 +169,170 @@ class NodeMaterialObserver {

}

getGeometryData( geometry ) {

const data = {
attributes: {}
};

const attributes = geometry.attributes;

for ( const name in attributes ) {

const attribute = attributes[ name ];

data.attributes[ name ] = {
version: attribute.version
};

}

if ( geometry.index !== null ) {

const index = geometry.index;

data.index = {
version: index.version
};

}

data.drawRange = {
start: geometry.drawRange.start,
count: geometry.drawRange.count
};

data.morphAttributes = {};

for ( const name in geometry.morphAttributes ) {

const morphArray = geometry.morphAttributes[ name ];
data.morphAttributes[ name ] = [];

for ( let i = 0; i < morphArray.length; i ++ ) {

const attribute = morphArray[ i ];

data.morphAttributes[ name ][ i ] = {
version: attribute.version
};

}

}

return data;

}

compareGeometryData( storedData, currentData ) {

// Compare attributes
const storedAttributes = storedData.attributes;
const currentAttributes = currentData.attributes;

const storedAttributeNames = Object.keys( storedAttributes );
const currentAttributeNames = Object.keys( currentAttributes );

if ( storedAttributeNames.length !== currentAttributeNames.length ) {

return false;

}

for ( const name of storedAttributeNames ) {

if ( currentAttributes[ name ] === undefined ) {

return false;

}

const storedAttribute = storedAttributes[ name ];
const currentAttribute = currentAttributes[ name ];

if ( storedAttribute.version !== currentAttribute.version ) {

return false;

}

}

// Compare index
if ( ( storedData.index === undefined ) !== ( currentData.index === undefined ) ) {

return false;

}

if ( storedData.index && currentData.index ) {

if ( storedData.index.version !== currentData.index.version ) {

return false;

}

}

// Compare drawRange
if ( storedData.drawRange.start !== currentData.drawRange.start ||
storedData.drawRange.count !== currentData.drawRange.count ) {

return false;

}

// Compare morphAttributes
const storedMorphAttributes = storedData.morphAttributes;
const currentMorphAttributes = currentData.morphAttributes;

const storedMorphNames = Object.keys( storedMorphAttributes );
const currentMorphNames = Object.keys( currentMorphAttributes );

if ( storedMorphNames.length !== currentMorphNames.length ) {

return false;

}

for ( const name of storedMorphNames ) {

if ( currentMorphAttributes[ name ] === undefined ) {

return false;

}

const storedMorphArray = storedMorphAttributes[ name ];
const currentMorphArray = currentMorphAttributes[ name ];

if ( storedMorphArray.length !== currentMorphArray.length ) {

return false;

}

for ( let i = 0; i < storedMorphArray.length; i ++ ) {

const storedAttribute = storedMorphArray[ i ];
const currentAttribute = currentMorphArray[ i ];

if ( storedAttribute.version !== currentAttribute.version ) {

return false;

}

}

}

return true;

}

equals( renderObject ) {

const { object, material } = renderObject;
Expand Down Expand Up @@ -224,6 +389,21 @@ class NodeMaterialObserver {

}

// geometry

const geometryData = renderObjectData.geometry;
const currentGeometryData = this.getGeometryData( renderObject.geometry );
sunag marked this conversation as resolved.
Show resolved Hide resolved

if ( ! this.compareGeometryData( geometryData, currentGeometryData ) ) {

// Update stored geometry data
renderObjectData.geometry = currentGeometryData;

return false;

}


// morph targets

if ( renderObjectData.morphTargetInfluences ) {
Expand Down
8 changes: 4 additions & 4 deletions src/renderers/webgl-fallback/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,9 @@ class WebGLBackend extends Backend {

const contextData = this.get( context );

const drawParms = renderObject.getDrawParameters();
const drawParams = renderObject.getDrawParameters();

if ( drawParms === null ) return;
if ( drawParams === null ) return;

//

Expand Down Expand Up @@ -717,8 +717,8 @@ class WebGLBackend extends Backend {

//

const { vertexCount, instanceCount } = drawParms;
let { firstVertex } = drawParms;
const { vertexCount, instanceCount } = drawParams;
let { firstVertex } = drawParams;

renderer.object = object;

Expand Down
8 changes: 4 additions & 4 deletions src/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -846,9 +846,9 @@ class WebGPUBackend extends Backend {
const currentSets = renderContextData.currentSets;
const passEncoderGPU = renderContextData.currentPass;

const drawParms = renderObject.getDrawParameters();
const drawParams = renderObject.getDrawParameters();

if ( drawParms === null ) return;
if ( drawParams === null ) return;

// pipeline

Expand Down Expand Up @@ -970,15 +970,15 @@ class WebGPUBackend extends Backend {

} else if ( hasIndex === true ) {

const { vertexCount: indexCount, instanceCount, firstVertex: firstIndex } = drawParms;
const { vertexCount: indexCount, instanceCount, firstVertex: firstIndex } = drawParams;

passEncoderGPU.drawIndexed( indexCount, instanceCount, firstIndex, 0, 0 );

info.update( object, indexCount, instanceCount );

} else {

const { vertexCount, instanceCount, firstVertex } = drawParms;
const { vertexCount, instanceCount, firstVertex } = drawParams;

passEncoderGPU.draw( vertexCount, instanceCount, firstVertex, 0 );

Expand Down