فهرست منبع

WebGPURenderer: `SampledTexture` extends of `Sampler` for bindings (#31494)

sunag 5 ماه پیش
والد
کامیت
84a951eb3f

+ 4 - 4
src/renderers/common/Bindings.js

@@ -244,10 +244,6 @@ class Bindings extends DataMap {
 
 				}
 
-			} else if ( binding.isSampler ) {
-
-				binding.update();
-
 			} else if ( binding.isSampledTexture ) {
 
 				const texturesTextureData = this.textures.get( binding.texture );
@@ -305,6 +301,10 @@ class Bindings extends DataMap {
 
 				}
 
+			} else if ( binding.isSampler ) {
+
+				binding.update();
+
 			}
 
 		}

+ 3 - 39
src/renderers/common/SampledTexture.js

@@ -1,4 +1,4 @@
-import Binding from './Binding.js';
+import Sampler from './Sampler.js';
 
 let _id = 0;
 
@@ -8,7 +8,7 @@ let _id = 0;
  * @private
  * @augments Binding
  */
-class SampledTexture extends Binding {
+class SampledTexture extends Sampler {
 
 	/**
 	 * Constructs a new sampled texture.
@@ -18,7 +18,7 @@ class SampledTexture extends Binding {
 	 */
 	constructor( name, texture ) {
 
-		super( name );
+		super( name, texture );
 
 		/**
 		 * This identifier.
@@ -27,20 +27,6 @@ class SampledTexture extends Binding {
 		 */
 		this.id = _id ++;
 
-		/**
-		 * The texture this binding is referring to.
-		 *
-		 * @type {?Texture}
-		 */
-		this.texture = texture;
-
-		/**
-		 * The binding's version.
-		 *
-		 * @type {number}
-		 */
-		this.version = texture ? texture.version : 0;
-
 		/**
 		 * Whether the texture is a storage texture or not.
 		 *
@@ -90,28 +76,6 @@ class SampledTexture extends Binding {
 
 	}
 
-	/**
-	 * Updates the binding.
-	 *
-	 * @return {boolean} Whether the texture has been updated and must be
-	 * uploaded to the GPU.
-	 */
-	update() {
-
-		const { texture, version } = this;
-
-		if ( version !== texture.version ) {
-
-			this.version = texture.version;
-
-			return true;
-
-		}
-
-		return false;
-
-	}
-
 }
 
 /**

+ 22 - 0
src/renderers/common/Sampler.js

@@ -43,6 +43,28 @@ class Sampler extends Binding {
 
 	}
 
+	/**
+	 * Updates the binding.
+	 *
+	 * @return {boolean} Whether the texture has been updated and must be
+	 * uploaded to the GPU.
+	 */
+	update() {
+
+		const { texture, version } = this;
+
+		if ( version !== texture.version ) {
+
+			this.version = texture.version;
+
+			return true;
+
+		}
+
+		return false;
+
+	}
+
 }
 
 export default Sampler;

+ 26 - 26
src/renderers/webgpu/utils/WebGPUBindingUtils.js

@@ -93,26 +93,6 @@ class WebGPUBindingUtils {
 
 				bindingGPU.buffer = buffer;
 
-			} else if ( binding.isSampler ) {
-
-				const sampler = {}; // GPUSamplerBindingLayout
-
-				if ( binding.texture.isDepthTexture ) {
-
-					if ( binding.texture.compareFunction !== null ) {
-
-						sampler.type = GPUSamplerBindingType.Comparison;
-
-					} else if ( backend.compatibilityMode ) {
-
-						sampler.type = GPUSamplerBindingType.NonFiltering;
-
-					}
-
-				}
-
-				bindingGPU.sampler = sampler;
-
 			} else if ( binding.isSampledTexture && binding.store ) {
 
 				const storageTexture = {}; // GPUStorageTextureBindingLayout
@@ -220,6 +200,26 @@ class WebGPUBindingUtils {
 
 				bindingGPU.texture = texture;
 
+			} else if ( binding.isSampler ) {
+
+				const sampler = {}; // GPUSamplerBindingLayout
+
+				if ( binding.texture.isDepthTexture ) {
+
+					if ( binding.texture.compareFunction !== null ) {
+
+						sampler.type = GPUSamplerBindingType.Comparison;
+
+					} else if ( backend.compatibilityMode ) {
+
+						sampler.type = GPUSamplerBindingType.NonFiltering;
+
+					}
+
+				}
+
+				bindingGPU.sampler = sampler;
+
 			} else {
 
 				console.error( `WebGPUBindingUtils: Unsupported binding "${ binding }".` );
@@ -401,12 +401,6 @@ class WebGPUBindingUtils {
 
 				entriesGPU.push( { binding: bindingPoint, resource: { buffer: bindingData.buffer } } );
 
-			} else if ( binding.isSampler ) {
-
-				const textureGPU = backend.get( binding.texture );
-
-				entriesGPU.push( { binding: bindingPoint, resource: textureGPU.sampler } );
-
 			} else if ( binding.isSampledTexture ) {
 
 				const textureData = backend.get( binding.texture );
@@ -464,6 +458,12 @@ class WebGPUBindingUtils {
 
 				entriesGPU.push( { binding: bindingPoint, resource: resourceGPU } );
 
+			} else if ( binding.isSampler ) {
+
+				const textureGPU = backend.get( binding.texture );
+
+				entriesGPU.push( { binding: bindingPoint, resource: textureGPU.sampler } );
+
 			}
 
 			bindingPoint ++;

粤ICP备19079148号