Просмотр исходного кода

WebGPURenderer: webgl-fallback - fix uniform/texture index allocation (#29622)

* fix uniform index/texture use

* use explict test

* Update WebGLBackend.js

Minor code style clean up.

---------

Co-authored-by: aardgoose <angus.sawyer@email.com>
Co-authored-by: Michael Herzog <michael.herzog@human-interactive.org>
aardgoose 1 год назад
Родитель
Сommit
597481c879
1 измененных файлов с 31 добавлено и 17 удалено
  1. 31 17
      src/renderers/webgl-fallback/WebGLBackend.js

+ 31 - 17
src/renderers/webgl-fallback/WebGLBackend.js

@@ -63,6 +63,8 @@ class WebGLBackend extends Backend {
 		this.disjoint = this.extensions.get( 'EXT_disjoint_timer_query_webgl2' );
 		this.parallel = this.extensions.get( 'KHR_parallel_shader_compile' );
 
+		this._knownBindings = new WeakSet();
+
 		this._currentContext = null;
 
 	}
@@ -1125,33 +1127,45 @@ class WebGLBackend extends Backend {
 
 	createBindings( bindGroup, bindings ) {
 
-		this.updateBindings( bindGroup, bindings );
+		if ( this._knownBindings.has( bindings ) === false ) {
 
-	}
+			this._knownBindings.add( bindings );
 
-	updateBindings( bindGroup, bindings ) {
+			let uniformBuffers = 0;
+			let textures = 0;
 
-		if ( ! bindGroup ) return;
+			for ( const bindGroup of bindings ) {
 
-		const { gl } = this;
+				this.set( bindGroup, {
+					textures: textures,
+					uniformBuffers: uniformBuffers
+				} );
 
-		const bindingsData = this.get( bindings );
-		const bindGroupData = this.get( bindGroup );
+				for ( const binding of bindGroup.bindings ) {
 
-		if ( bindingsData.textureIndex === undefined ) bindingsData.textureIndex = 0;
+					if ( binding.isUniformBuffer ) uniformBuffers ++;
+					if ( binding.isSampledTexture ) textures ++;
 
-		if ( bindGroupData.textureIndex === undefined ) {
+				}
 
-			bindGroupData.textureIndex = bindingsData.textureIndex;
+			}
 
-		} else {
+		}
 
-			// reset textureIndex to match previous mappimgs when rebuilt
-			bindingsData.textureIndex = bindGroupData.textureIndex;
+		this.updateBindings( bindGroup, bindings );
 
-		}
+	}
+
+	updateBindings( bindGroup /*, bindings*/ ) {
+
+		if ( bindGroup === null ) return;
+
+		const { gl } = this;
+
+		const bindGroupData = this.get( bindGroup );
 
-		let i = 0;
+		let i = bindGroupData.uniformBuffers;
+		let t = bindGroupData.textures;
 
 		for ( const binding of bindGroup.bindings ) {
 
@@ -1164,7 +1178,7 @@ class WebGLBackend extends Backend {
 				gl.bufferData( gl.UNIFORM_BUFFER, data, gl.DYNAMIC_DRAW );
 
 				this.set( binding, {
-					index: bindGroup.index * 2 + i ++,
+					index: i ++,
 					bufferGPU
 				} );
 
@@ -1173,7 +1187,7 @@ class WebGLBackend extends Backend {
 				const { textureGPU, glTextureType } = this.get( binding.texture );
 
 				this.set( binding, {
-					index: bindingsData.textureIndex ++,
+					index: t ++,
 					textureGPU,
 					glTextureType
 				} );

粤ICP备19079148号