Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGPURenderer: clear() - use cached descriptor properties and views were possible #27551

Merged
merged 3 commits into from
Jan 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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