Skip to content

Commit

Permalink
WebGPURenderer: clear() - use cached descriptor properties and views …
Browse files Browse the repository at this point in the history
…were possible (mrdoob#27551)

* remove redundant code

* use cached descriptor properties for clear()

* remove unused import

---------

Co-authored-by: aardgoose <[email protected]>
  • Loading branch information
2 people authored and AdaRoseCannon committed Jan 15, 2024
1 parent 33bf869 commit 7769afd
Showing 1 changed file with 13 additions and 32 deletions.
45 changes: 13 additions & 32 deletions examples/jsm/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { GPUFeatureName, GPUTextureFormat, GPULoadOp, GPUStoreOp, GPUIndexFormat
import WGSLNodeBuilder from './nodes/WGSLNodeBuilder.js';
import Backend from '../common/Backend.js';

import { DepthFormat, WebGPUCoordinateSystem } from 'three';

import WebGPUUtils from './utils/WebGPUUtils.js';
import WebGPUAttributeUtils from './utils/WebGPUAttributeUtils.js';
import WebGPUBindingUtils from './utils/WebGPUBindingUtils.js';
Expand Down Expand Up @@ -138,20 +136,22 @@ class WebGPUBackend extends Backend {

}

_getDefaultRenderPassDescriptor( renderContext ) {
_getDefaultRenderPassDescriptor() {

let descriptor = this.defaultRenderPassdescriptor;

const antialias = this.parameters.antialias;

if ( descriptor === null ) {

const renderer = this.renderer;

descriptor = {
colorAttachments: [ {
view: null
} ],
depthStencilAttachment: {
view: this.textureUtils.getDepthBuffer( renderContext.depth, renderContext.stencil ).createView()
view: this.textureUtils.getDepthBuffer( renderer.depth, renderer.stencil ).createView()
}
};

Expand Down Expand Up @@ -259,12 +259,6 @@ class WebGPUBackend extends Backend {
view: depthTextureData.texture.createView(),
};

if ( renderContext.stencil && renderContext.depthTexture.format === DepthFormat ) {

renderContext.stencil = false;

}

descriptor = {
colorAttachments,
depthStencilAttachment
Expand Down Expand Up @@ -317,13 +311,13 @@ class WebGPUBackend extends Backend {

let descriptor;

if ( renderContext.textures !== null ) {
if ( renderContext.textures === null ) {

descriptor = this._getRenderPassDescriptor( renderContext );
descriptor = this._getDefaultRenderPassDescriptor();

} else {

descriptor = this._getDefaultRenderPassDescriptor( renderContext );
descriptor = this._getRenderPassDescriptor( renderContext );

}

Expand Down Expand Up @@ -578,7 +572,7 @@ class WebGPUBackend extends Backend {
const device = this.device;
const renderer = this.renderer;

const colorAttachments = [];
let colorAttachments = [];

let depthStencilAttachment;
let clearValue;
Expand All @@ -602,36 +596,23 @@ class WebGPUBackend extends Backend {
depth = depth && supportsDepth;
stencil = stencil && supportsStencil;

if ( color ) {

const antialias = this.parameters.antialias;

const colorAttachment = {};

if ( antialias === true ) {
const descriptor = this._getDefaultRenderPassDescriptor();

colorAttachment.view = this.colorBuffer.createView();
colorAttachment.resolveTarget = this.context.getCurrentTexture().createView();
if ( color ) {

} else {
colorAttachments = descriptor.colorAttachments;

colorAttachment.view = this.context.getCurrentTexture().createView();

}
const colorAttachment = colorAttachments[ 0 ];

colorAttachment.clearValue = clearValue;
colorAttachment.loadOp = GPULoadOp.Clear;
colorAttachment.storeOp = GPUStoreOp.Store;

colorAttachments.push( colorAttachment );

}

if ( depth || stencil ) {

depthStencilAttachment = {
view: this.textureUtils.getDepthBuffer( renderer.depth, renderer.stencil ).createView()
};
depthStencilAttachment = descriptor.depthStencilAttachment;

}

Expand Down

0 comments on commit 7769afd

Please sign in to comment.