Skip to content

Commit 2b6771e

Browse files
committed
WebGPURenderer: Only use HalfFloatType for the framebuffer target if necessary.
1 parent 0d34438 commit 2b6771e

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

src/renderers/common/Backend.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,17 @@ class Backend {
588588

589589
}
590590

591+
/**
592+
* Returns `true` if the backend requires a framebuffer target with type `HalfFloat`.
593+
*
594+
* @return {Boolean} Whether the backend requires a framebuffer target with type `HalfFloat` or not.
595+
*/
596+
needsHalfFloatFrameBufferTarget() {
597+
598+
return false;
599+
600+
}
601+
591602
/**
592603
* Sets a dictionary for the given object into the
593604
* internal data structure.

src/renderers/common/Renderer.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { Matrix4 } from '../../math/Matrix4.js';
2626
import { Vector2 } from '../../math/Vector2.js';
2727
import { Vector4 } from '../../math/Vector4.js';
2828
import { RenderTarget } from '../../core/RenderTarget.js';
29-
import { DoubleSide, BackSide, FrontSide, SRGBColorSpace, NoToneMapping, LinearFilter, LinearSRGBColorSpace, HalfFloatType, RGBAFormat, PCFShadowMap } from '../../constants.js';
29+
import { DoubleSide, BackSide, FrontSide, SRGBColorSpace, NoToneMapping, LinearFilter, LinearSRGBColorSpace, HalfFloatType, RGBAFormat, PCFShadowMap, UnsignedByteType } from '../../constants.js';
3030

3131
/** @module Renderer **/
3232

@@ -453,6 +453,15 @@ class Renderer {
453453
*/
454454
this._frameBufferTarget = null;
455455

456+
/**
457+
* Used to identify the framebuffer target.
458+
*
459+
* @private
460+
* @type {Number?}
461+
* @default null
462+
*/
463+
this._frameBufferTargetKey = null;
464+
456465
const alphaClear = this.alpha === true ? 0 : 1;
457466

458467
/**
@@ -1123,12 +1132,19 @@ class Renderer {
11231132

11241133
let frameBufferTarget = this._frameBufferTarget;
11251134

1126-
if ( frameBufferTarget === null ) {
1135+
if ( frameBufferTarget === null || this._frameBufferTargetKey !== currentToneMapping ) {
1136+
1137+
if ( frameBufferTarget !== null ) frameBufferTarget.dispose();
1138+
1139+
// to improve performance we only want to use HalfFloatType if necessary
1140+
// HalfFloatType is required when a) tone mapping is configured or b) the backend specifically requests it
1141+
1142+
const type = ( currentToneMapping !== NoToneMapping || this.backend.needsHalfFloatFrameBufferTarget() ) ? HalfFloatType : UnsignedByteType;
11271143

11281144
frameBufferTarget = new RenderTarget( width, height, {
11291145
depthBuffer: depth,
11301146
stencilBuffer: stencil,
1131-
type: HalfFloatType, // FloatType
1147+
type: type,
11321148
format: RGBAFormat,
11331149
colorSpace: LinearSRGBColorSpace,
11341150
generateMipmaps: false,
@@ -1140,6 +1156,7 @@ class Renderer {
11401156
frameBufferTarget.isPostProcessingRenderTarget = true;
11411157

11421158
this._frameBufferTarget = frameBufferTarget;
1159+
this._frameBufferTargetKey = currentToneMapping;
11431160

11441161
}
11451162

src/renderers/webgpu/WebGPUBackend.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import WebGPUBindingUtils from './utils/WebGPUBindingUtils.js';
1313
import WebGPUPipelineUtils from './utils/WebGPUPipelineUtils.js';
1414
import WebGPUTextureUtils from './utils/WebGPUTextureUtils.js';
1515

16-
import { WebGPUCoordinateSystem } from '../../constants.js';
16+
import { HalfFloatType, WebGPUCoordinateSystem } from '../../constants.js';
1717
import WebGPUTimestampQueryPool from './utils/WebGPUTimestampQueryPool.js';
1818

1919
/**
@@ -279,6 +279,17 @@ class WebGPUBackend extends Backend {
279279

280280
}
281281

282+
/**
283+
* Returns `true` if the backend requires a framebuffer target with type `HalfFloat`.
284+
*
285+
* @return {Boolean} Whether the backend requires a framebuffer target with type `HalfFloat` or not.
286+
*/
287+
needsHalfFloatFrameBufferTarget() {
288+
289+
return ( this.parameters.outputType === HalfFloatType );
290+
291+
}
292+
282293
/**
283294
* Returns the default render pass descriptor.
284295
*

0 commit comments

Comments
 (0)