From b2f0e59cb320ee8a7da3d180de49b345cc9bae74 Mon Sep 17 00:00:00 2001 From: aardgoose Date: Sun, 14 Jul 2024 17:49:36 +0100 Subject: [PATCH] wip --- .../webgpu/utils/WebGPUTextureUtils.js | 4 +-- src/renderers/webgpu/utils/WebGPUUtils.js | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/renderers/webgpu/utils/WebGPUTextureUtils.js b/src/renderers/webgpu/utils/WebGPUTextureUtils.js index d45b0fd4decd9f..8355fd7468fe74 100644 --- a/src/renderers/webgpu/utils/WebGPUTextureUtils.js +++ b/src/renderers/webgpu/utils/WebGPUTextureUtils.js @@ -113,9 +113,9 @@ class WebGPUTextureUtils { const dimension = this._getDimension( texture ); const format = texture.internalFormat || options.format || getFormat( texture, backend.device ); - const sampleCount = options.sampleCount !== undefined ? options.sampleCount : 1; + let sampleCount = options.sampleCount !== undefined ? options.sampleCount : 1; - // sampleCount = backend.utils.getSampleCount( sampleCount ); + sampleCount = backend.utils.getSampleCount( sampleCount ); const primarySampleCount = texture.isRenderTargetTexture && ! texture.isMultisampleRenderTargetTexture ? 1 : sampleCount; diff --git a/src/renderers/webgpu/utils/WebGPUUtils.js b/src/renderers/webgpu/utils/WebGPUUtils.js index e1b176bff0eb93..0307b9d47cc2f8 100644 --- a/src/renderers/webgpu/utils/WebGPUUtils.js +++ b/src/renderers/webgpu/utils/WebGPUUtils.js @@ -64,6 +64,39 @@ class WebGPUUtils { } + getSampleCount( sampleCount ) { + + let count = 1; + + if ( sampleCount > 1 ) { + + // WebGPU only supports power-of-two sample counts and 2 is not a valid value + count = Math.pow( 2, Math.floor( Math.log2( sampleCount ) ) ); + + if ( count === 2 ) { + + count = 4; + + } + + } + + return count; + + } + + getSampleCountRenderContext( renderContext ) { + + if ( renderContext.textures !== null ) { + + return this.getSampleCount( renderContext.sampleCount ); + + } + + return this.getSampleCount( this.backend.renderer.samples ); + + } + } export default WebGPUUtils;