Skip to content

Commit 6ec855e

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

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-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: 10 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

@@ -1121,14 +1121,21 @@ class Renderer {
11211121
const { width, height } = this.getDrawingBufferSize( _drawingBufferSize );
11221122
const { depth, stencil } = this;
11231123

1124+
// to improve performance we only want to use HalfFloatType if necessary
1125+
// HalfFloatType is required when a) tone mapping is used or b) the backend specifically requests it
1126+
1127+
const type = ( useToneMapping || this.backend.needsHalfFloatFrameBufferTarget() ) ? HalfFloatType : UnsignedByteType;
1128+
11241129
let frameBufferTarget = this._frameBufferTarget;
11251130

1126-
if ( frameBufferTarget === null ) {
1131+
if ( frameBufferTarget === null || this._frameBufferTarget.texture.type !== type ) {
1132+
1133+
if ( frameBufferTarget !== null ) frameBufferTarget.dispose();
11271134

11281135
frameBufferTarget = new RenderTarget( width, height, {
11291136
depthBuffer: depth,
11301137
stencilBuffer: stencil,
1131-
type: HalfFloatType, // FloatType
1138+
type: type,
11321139
format: RGBAFormat,
11331140
colorSpace: LinearSRGBColorSpace,
11341141
generateMipmaps: false,

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)