|
|
@@ -210,20 +210,9 @@ class WebGPUTextureUtils {
|
|
|
|
|
|
if ( bindingData.sampler !== samplerData.sampler ) {
|
|
|
|
|
|
- // check if previous sampler is unused so it can be deleted
|
|
|
+ // release the previous sampler (if any) so it can be deleted when unused
|
|
|
|
|
|
- if ( bindingData.sampler !== undefined ) {
|
|
|
-
|
|
|
- const oldSamplerData = this._samplerCache.get( bindingData.samplerKey );
|
|
|
- oldSamplerData.usedTimes --;
|
|
|
-
|
|
|
- if ( oldSamplerData.usedTimes === 0 ) {
|
|
|
-
|
|
|
- this._samplerCache.delete( bindingData.samplerKey );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ this._releaseSampler( bindingData );
|
|
|
|
|
|
// update to new sampler data
|
|
|
|
|
|
@@ -238,6 +227,44 @@ class WebGPUTextureUtils {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Frees the GPU sampler referenced by the given sampler binding.
|
|
|
+ *
|
|
|
+ * @param {Sampler} binding - The sampler binding to free.
|
|
|
+ */
|
|
|
+ destroySampler( binding ) {
|
|
|
+
|
|
|
+ this._releaseSampler( this.backend.get( binding ) );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Releases the pooled sampler referenced by the given binding data and
|
|
|
+ * removes it from the cache when no binding references it anymore.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @param {Object} bindingData - The binding data holding the sampler reference.
|
|
|
+ */
|
|
|
+ _releaseSampler( bindingData ) {
|
|
|
+
|
|
|
+ if ( bindingData.sampler !== undefined ) {
|
|
|
+
|
|
|
+ const samplerData = this._samplerCache.get( bindingData.samplerKey );
|
|
|
+ samplerData.usedTimes --;
|
|
|
+
|
|
|
+ if ( samplerData.usedTimes === 0 ) {
|
|
|
+
|
|
|
+ this._samplerCache.delete( bindingData.samplerKey );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ bindingData.sampler = undefined;
|
|
|
+ bindingData.samplerKey = undefined;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Creates a default texture for the given texture that can be used
|
|
|
* as a placeholder until the actual texture is ready for usage.
|