Skip to content

Commit

Permalink
WebGPURenderer: Only use HalfFloatType for the framebuffer target if …
Browse files Browse the repository at this point in the history
…necessary.
  • Loading branch information
Mugen87 committed Jan 25, 2025
1 parent 0d34438 commit 6ec855e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/renderers/common/Backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,17 @@ class Backend {

}

/**
* Returns `true` if the backend requires a framebuffer target with type `HalfFloat`.
*
* @return {Boolean} Whether the backend requires a framebuffer target with type `HalfFloat` or not.
*/
needsHalfFloatFrameBufferTarget() {

return false;

}

/**
* Sets a dictionary for the given object into the
* internal data structure.
Expand Down
13 changes: 10 additions & 3 deletions src/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Matrix4 } from '../../math/Matrix4.js';
import { Vector2 } from '../../math/Vector2.js';
import { Vector4 } from '../../math/Vector4.js';
import { RenderTarget } from '../../core/RenderTarget.js';
import { DoubleSide, BackSide, FrontSide, SRGBColorSpace, NoToneMapping, LinearFilter, LinearSRGBColorSpace, HalfFloatType, RGBAFormat, PCFShadowMap } from '../../constants.js';
import { DoubleSide, BackSide, FrontSide, SRGBColorSpace, NoToneMapping, LinearFilter, LinearSRGBColorSpace, HalfFloatType, RGBAFormat, PCFShadowMap, UnsignedByteType } from '../../constants.js';

/** @module Renderer **/

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

// to improve performance we only want to use HalfFloatType if necessary
// HalfFloatType is required when a) tone mapping is used or b) the backend specifically requests it

const type = ( useToneMapping || this.backend.needsHalfFloatFrameBufferTarget() ) ? HalfFloatType : UnsignedByteType;

let frameBufferTarget = this._frameBufferTarget;

if ( frameBufferTarget === null ) {
if ( frameBufferTarget === null || this._frameBufferTarget.texture.type !== type ) {

if ( frameBufferTarget !== null ) frameBufferTarget.dispose();

frameBufferTarget = new RenderTarget( width, height, {
depthBuffer: depth,
stencilBuffer: stencil,
type: HalfFloatType, // FloatType
type: type,
format: RGBAFormat,
colorSpace: LinearSRGBColorSpace,
generateMipmaps: false,
Expand Down
13 changes: 12 additions & 1 deletion src/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import WebGPUBindingUtils from './utils/WebGPUBindingUtils.js';
import WebGPUPipelineUtils from './utils/WebGPUPipelineUtils.js';
import WebGPUTextureUtils from './utils/WebGPUTextureUtils.js';

import { WebGPUCoordinateSystem } from '../../constants.js';
import { HalfFloatType, WebGPUCoordinateSystem } from '../../constants.js';
import WebGPUTimestampQueryPool from './utils/WebGPUTimestampQueryPool.js';

/**
Expand Down Expand Up @@ -279,6 +279,17 @@ class WebGPUBackend extends Backend {

}

/**
* Returns `true` if the backend requires a framebuffer target with type `HalfFloat`.
*
* @return {Boolean} Whether the backend requires a framebuffer target with type `HalfFloat` or not.
*/
needsHalfFloatFrameBufferTarget() {

return ( this.parameters.outputType === HalfFloatType );

}

/**
* Returns the default render pass descriptor.
*
Expand Down

0 comments on commit 6ec855e

Please sign in to comment.