1
0
Эх сурвалжийг харах

WebGPURenderer: Use all visibility for shared BindingGroup. (#32997)

sunag 2 сар өмнө
parent
commit
f579efc98d

+ 0 - 8
src/nodes/core/NodeBuilder.js

@@ -625,14 +625,6 @@ class NodeBuilder {
 
 				bindingGroupsCache.set( cacheKey, bindGroup );
 
-			} else {
-
-				for ( let i = 0; i < bindings.length; i ++ ) {
-
-					bindGroup.bindings[ i ].visibility |= bindings[ i ].visibility;
-
-				}
-
 			}
 
 		} else {

+ 2 - 2
src/renderers/webgpu/nodes/WGSLNodeBuilder.js

@@ -1151,8 +1151,8 @@ class WGSLNodeBuilder extends NodeBuilder {
 
 				}
 
-				// Update visibility to include this shader stage (bitwise OR)
-				uniformsGroup.setVisibility( uniformsGroup.getVisibility() | gpuShaderStageLib[ shaderStage ] );
+				// TODO: Verifier caches
+				uniformsGroup.setVisibility( GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT | GPUShaderStage.COMPUTE );
 
 				// Add to bindings for this stage if not already present
 				if ( bindings.indexOf( uniformsGroup ) === - 1 ) {

+ 13 - 41
src/renderers/webgpu/utils/WebGPUBindingUtils.js

@@ -6,7 +6,6 @@ import {
 import { FloatType, IntType, UnsignedIntType, Compatibility } from '../../../constants.js';
 import { NodeAccess } from '../../../nodes/core/constants.js';
 import { isTypedArray, error } from '../../../utils.js';
-import { hashString } from '../../../nodes/core/NodeUtils.js';
 
 /**
  * Class representing a WebGPU bind group layout.
@@ -89,63 +88,36 @@ class WebGPUBindingUtils {
 
 		const bindingsData = backend.get( bindGroup );
 
-		const entries = this._createLayoutEntries( bindGroup );
-		const bindGroupLayoutHash = hashString( JSON.stringify( entries ) );
-
-		let layoutChanged = false;
-
-		// check if the bind group already has a layout and if it's still valid
+		// check if the the bind group already has a layout
 
 		if ( bindingsData.layout ) {
 
-			// if the layout hash changed (e.g. visibility was updated), invalidate the old layout
-
-			if ( bindingsData.layoutHash !== bindGroupLayoutHash ) {
-
-				bindingsData.layout.usedTimes --;
-
-				if ( bindingsData.layout.usedTimes === 0 ) {
-
-					this._bindGroupLayoutCache.delete( bindingsData.layoutHash );
-
-				}
-
-				bindingsData.layout = undefined;
-				bindingsData.layoutHash = undefined;
-
-				layoutChanged = true;
+			return bindingsData.layout.layoutGPU;
 
-			} else {
+		}
 
-				return bindingsData.layout.layoutGPU;
+		// if not, assing one
 
-			}
+		const entries = this._createLayoutEntries( bindGroup );
+		const bindGroupLayoutKey = JSON.stringify( entries );
 
-		}
+		// try to find an existing layout in the cache
 
-		// create or reuse a bind group layout from the cache
+		let bindGroupLayout = this._bindGroupLayoutCache.get( bindGroupLayoutKey );
 
-		let bindGroupLayout = this._bindGroupLayoutCache.get( bindGroupLayoutHash );
+		// if not create a new one
 
 		if ( bindGroupLayout === undefined ) {
 
 			bindGroupLayout = new BindGroupLayout( device.createBindGroupLayout( { entries } ) );
-			this._bindGroupLayoutCache.set( bindGroupLayoutHash, bindGroupLayout );
+			this._bindGroupLayoutCache.set( bindGroupLayoutKey, bindGroupLayout );
 
 		}
 
 		bindGroupLayout.usedTimes ++;
 
 		bindingsData.layout = bindGroupLayout;
-		bindingsData.layoutHash = bindGroupLayoutHash;
-
-		// if layout changed, recreate the GPU bind group with the new layout
-
-		if ( layoutChanged ) {
-
-			bindingsData.group = this.createBindGroup( bindGroup, bindGroupLayout.layoutGPU );
-
-		}
+		bindingsData.layoutKey = bindGroupLayoutKey;
 
 		return bindGroupLayout.layoutGPU;
 
@@ -644,12 +616,12 @@ class WebGPUBindingUtils {
 
 			if ( bindingsData.layout.usedTimes === 0 ) {
 
-				this._bindGroupLayoutCache.delete( bindingsData.layoutHash );
+				this._bindGroupLayoutCache.delete( bindingsData.layoutKey );
 
 			}
 
 			bindingsData.layout = undefined;
-			bindingsData.layoutHash = undefined;
+			bindingsData.layoutKey = undefined;
 
 		}
 

+ 4 - 4
src/renderers/webgpu/utils/WebGPUPipelineUtils.js

@@ -105,8 +105,8 @@ class WebGPUPipelineUtils {
 
 		for ( const bindGroup of renderObject.getBindings() ) {
 
-			// ensure layout is up to date (visibility may have changed due to shared bind groups)
-			const layoutGPU = backend.bindingUtils.createBindingsLayout( bindGroup );
+			const bindingsData = backend.get( bindGroup );
+			const { layoutGPU } = bindingsData.layout;
 
 			bindGroupLayouts.push( layoutGPU );
 
@@ -366,8 +366,8 @@ class WebGPUPipelineUtils {
 
 		for ( const bindingsGroup of bindings ) {
 
-			// ensure layout is up to date (visibility may have changed due to shared bind groups)
-			const layoutGPU = backend.bindingUtils.createBindingsLayout( bindingsGroup );
+			const bindingsData = backend.get( bindingsGroup );
+			const { layoutGPU } = bindingsData.layout;
 
 			bindGroupLayouts.push( layoutGPU );
 

粤ICP备19079148号