Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 2 additions & 0 deletions packages/dev/core/src/Decorators/nodeDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const enum PropertyTypeForEdition {
Vector3,
/** property is a list of values */
List,
/** property is a Color3 */
Color3,
/** property is a Color4 */
Color4,
/** property (int) should be edited as a combo box with a list of sampling modes */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,26 @@ export class NodeRenderGraphBaseObjectRendererBlock extends NodeRenderGraphBlock
this._createFrameGraphObjectWithState(this.doNotChangeAspectRatio, value);
}

/** If true, MSAA color textures will be resolved at the end of the render pass (default: true) */
@editableInPropertyPage("Resolve MSAA colors", PropertyTypeForEdition.Boolean, "PROPERTIES")
public get resolveMSAAColors() {
return this._frameGraphTask.resolveMSAAColors;
}

public set resolveMSAAColors(value: boolean) {
this._frameGraphTask.resolveMSAAColors = value;
}

/** If true, MSAA depth texture will be resolved at the end of the render pass (default: false) */
@editableInPropertyPage("Resolve MSAA depth", PropertyTypeForEdition.Boolean, "PROPERTIES")
public get resolveMSAADepth() {
return this._frameGraphTask.resolveMSAADepth;
}

public set resolveMSAADepth(value: boolean) {
this._frameGraphTask.resolveMSAADepth = value;
}

/**
* Gets the current class name
* @returns the class name
Expand Down Expand Up @@ -358,6 +378,8 @@ export class NodeRenderGraphBaseObjectRendererBlock extends NodeRenderGraphBlock
codes.push(`${this._codeVariableName}.enableOutlineRendering = ${this.enableOutlineRendering};`);
codes.push(`${this._codeVariableName}.disableShadows = ${this.disableShadows};`);
codes.push(`${this._codeVariableName}.renderInLinearSpace = ${this.renderInLinearSpace};`);
codes.push(`${this._codeVariableName}.resolveMSAAColors = ${this.resolveMSAAColors};`);
codes.push(`${this._codeVariableName}.resolveMSAADepth = ${this.resolveMSAADepth};`);
return super._dumpPropertiesCode() + codes.join("\n");
}

Expand All @@ -373,6 +395,8 @@ export class NodeRenderGraphBaseObjectRendererBlock extends NodeRenderGraphBlock
serializationObject.enableOutlineRendering = this.enableOutlineRendering;
serializationObject.disableShadows = this.disableShadows;
serializationObject.renderInLinearSpace = this.renderInLinearSpace;
serializationObject.resolveMSAAColors = this.resolveMSAAColors;
serializationObject.resolveMSAADepth = this.resolveMSAADepth;
return serializationObject;
}

Expand All @@ -388,5 +412,7 @@ export class NodeRenderGraphBaseObjectRendererBlock extends NodeRenderGraphBlock
this.enableOutlineRendering = serializationObject.enableOutlineRendering ?? true;
this.disableShadows = serializationObject.disableShadows;
this.renderInLinearSpace = !!serializationObject.renderInLinearSpace;
this.resolveMSAAColors = serializationObject.resolveMSAAColors ?? true;
this.resolveMSAADepth = serializationObject.resolveMSAADepth ?? false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,26 @@ export class NodeRenderGraphGeometryRendererBlock extends NodeRenderGraphBlock {
this._frameGraphTask.dontRenderWhenMaterialDepthWriteIsDisabled = value;
}

/** If true, MSAA color textures will be resolved at the end of the render pass (default: true) */
@editableInPropertyPage("Resolve MSAA colors", PropertyTypeForEdition.Boolean, "PROPERTIES")
public get resolveMSAAColors() {
return this._frameGraphTask.resolveMSAAColors;
}

public set resolveMSAAColors(value: boolean) {
this._frameGraphTask.resolveMSAAColors = value;
}

/** If true, MSAA depth texture will be resolved at the end of the render pass (default: false) */
@editableInPropertyPage("Resolve MSAA depth", PropertyTypeForEdition.Boolean, "PROPERTIES")
public get resolveMSAADepth() {
return this._frameGraphTask.resolveMSAADepth;
}

public set resolveMSAADepth(value: boolean) {
this._frameGraphTask.resolveMSAADepth = value;
}

// View depth
@editableInPropertyPage("View depth format", PropertyTypeForEdition.TextureFormat, "GEOMETRY BUFFERS")
public viewDepthFormat = Constants.TEXTUREFORMAT_RED;
Expand Down Expand Up @@ -509,6 +529,8 @@ export class NodeRenderGraphGeometryRendererBlock extends NodeRenderGraphBlock {
codes.push(`${this._codeVariableName}.velocityType = ${this.velocityType};`);
codes.push(`${this._codeVariableName}.linearVelocityFormat = ${this.linearVelocityFormat};`);
codes.push(`${this._codeVariableName}.linearVelocityType = ${this.linearVelocityType};`);
codes.push(`${this._codeVariableName}.resolveMSAAColors = ${this.resolveMSAAColors};`);
codes.push(`${this._codeVariableName}.resolveMSAADepth = ${this.resolveMSAADepth};`);
return super._dumpPropertiesCode() + codes.join("\n");
}

Expand Down Expand Up @@ -542,6 +564,8 @@ export class NodeRenderGraphGeometryRendererBlock extends NodeRenderGraphBlock {
serializationObject.velocityType = this.velocityType;
serializationObject.linearVelocityFormat = this.linearVelocityFormat;
serializationObject.linearVelocityType = this.linearVelocityType;
serializationObject.resolveMSAAColors = this.resolveMSAAColors;
serializationObject.resolveMSAADepth = this.resolveMSAADepth;
return serializationObject;
}

Expand Down Expand Up @@ -575,6 +599,8 @@ export class NodeRenderGraphGeometryRendererBlock extends NodeRenderGraphBlock {
this.velocityType = serializationObject.velocityType;
this.linearVelocityFormat = serializationObject.linearVelocityFormat;
this.linearVelocityType = serializationObject.linearVelocityType;
this.resolveMSAAColors = serializationObject.resolveMSAAColors ?? true;
this.resolveMSAADepth = serializationObject.resolveMSAADepth ?? false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ export class NodeRenderGraphClearBlock extends NodeRenderGraphBlock {
protected override _buildBlock(state: NodeRenderGraphBuildState) {
super._buildBlock(state);

this._propagateInputValueToOutput(this.target, this.output);
this._propagateInputValueToOutput(this.depth, this.outputDepth);
this.output.value = this._frameGraphTask.outputTexture;
this.outputDepth.value = this._frameGraphTask.outputDepthTexture;

this._frameGraphTask.targetTexture = this.target.connectedPoint?.value as FrameGraphTextureHandle;
this._frameGraphTask.depthTexture = this.depth.connectedPoint?.value as FrameGraphTextureHandle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class NodeRenderGraphGenerateMipmapsBlock extends NodeRenderGraphBlock {
protected override _buildBlock(state: NodeRenderGraphBuildState) {
super._buildBlock(state);

this._propagateInputValueToOutput(this.target, this.output);
this.output.value = this._frameGraphTask.outputTexture;

this._frameGraphTask.targetTexture = this.target.connectedPoint?.value as FrameGraphTextureHandle;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@ import type { Nullable, AbstractEngine, IFrameGraphPass, FrameGraphContext, Fram
import { FrameGraphPass } from "./pass";

/**
* Cull pass used to filter objects that are not visible.
* Object list pass used to generate a list of objects.
*/
export class FrameGraphCullPass extends FrameGraphPass<FrameGraphContext> {
export class FrameGraphObjectListPass extends FrameGraphPass<FrameGraphContext> {
protected readonly _engine: AbstractEngine;
protected _objectList: FrameGraphObjectList;

/**
* Checks if a pass is a cull pass.
* Checks if a pass is an object list pass.
* @param pass The pass to check.
* @returns True if the pass is a cull pass, else false.
* @returns True if the pass is an object list pass, else false.
*/
public static IsCullPass(pass: IFrameGraphPass): pass is FrameGraphCullPass {
return (pass as FrameGraphCullPass).setObjectList !== undefined;
public static IsObjectListPass(pass: IFrameGraphPass): pass is FrameGraphObjectListPass {
return (pass as FrameGraphObjectListPass).setObjectList !== undefined;
}

/**
* Gets the object list used by the cull pass.
* Gets the object list used by the pass.
*/
public get objectList(): FrameGraphObjectList {
return this._objectList;
}

/**
* Sets the object list to use for culling.
* @param objectList The object list to use for culling.
* Sets the object list to use for the pass.
* @param objectList The object list to use for the pass.
*/
public setObjectList(objectList: FrameGraphObjectList) {
this._objectList = objectList;
Expand Down
18 changes: 16 additions & 2 deletions packages/dev/core/src/FrameGraph/Passes/renderPass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,26 @@ export class FrameGraphRenderPass extends FrameGraphPass<FrameGraphRenderContext
}

/**
* Gets the render target(s) used by the render pass.
* Gets the handle(s) of the render target(s) used by the render pass.
*/
public get renderTarget(): FrameGraphTextureHandle | FrameGraphTextureHandle[] | undefined {
return this._renderTarget;
}

/**
* Gets the render target depth used by the render pass.
* Gets the handle of the render target depth used by the render pass.
*/
public get renderTargetDepth(): FrameGraphTextureHandle | undefined {
return this._renderTargetDepth;
}

/**
* Gets the frame graph render target used by the render pass.
*/
public get frameGraphRenderTarget(): FrameGraphRenderTarget | undefined {
return this._frameGraphRenderTarget;
}

/**
* If true, the depth attachment will be read-only (may allow some optimizations in WebGPU)
*/
Expand Down Expand Up @@ -121,6 +128,13 @@ export class FrameGraphRenderPass extends FrameGraphPass<FrameGraphRenderContext
super._execute();

this._context._flushDebugMessages();

const renderTargetWrapper = this._frameGraphRenderTarget.renderTargetWrapper;
if (renderTargetWrapper && (renderTargetWrapper.resolveMSAAColors || renderTargetWrapper.resolveMSAADepth || renderTargetWrapper.resolveMSAAStencil)) {
// Unbinding the render target will trigger resolving MSAA textures.
this._context.bindRenderTarget(undefined, `frame graph render pass - ${this.name} - resolve MSAA`, true);
this._context._flushDebugMessages();
}
}

/** @internal */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class FrameGraphCullObjectsTask extends FrameGraphTask {
this.outputObjectList.meshes = this.objectList.meshes;
this.outputObjectList.particleSystems = this.objectList.particleSystems;

const pass = this._frameGraph.addCullPass(this.name);
const pass = this._frameGraph.addObjectListPass(this.name);

pass.setObjectList(this.outputObjectList);
pass.setExecuteFunc((_context) => {
Expand Down Expand Up @@ -82,7 +82,7 @@ export class FrameGraphCullObjectsTask extends FrameGraphTask {
}
});

const passDisabled = this._frameGraph.addCullPass(this.name + "_disabled", true);
const passDisabled = this._frameGraph.addObjectListPass(this.name + "_disabled", true);

passDisabled.setObjectList(this.outputObjectList);
passDisabled.setExecuteFunc((_context) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ export class FrameGraphGeometryRendererTask extends FrameGraphTask {
*/
public dontRenderWhenMaterialDepthWriteIsDisabled = true;

/**
* If true, the output geometry texture(s) will be resolved at the end of the render pass, if samples is greater than 1 (default: true)
*/
public resolveMSAAColors = true;

/**
* If true, depthTexture will be resolved at the end of the render pass, if this texture is provided and samples is greater than 1 (default: true)
*/
public resolveMSAADepth = false;

/**
* The list of texture descriptions used by the geometry renderer task.
*/
Expand Down Expand Up @@ -403,6 +413,9 @@ export class FrameGraphGeometryRendererTask extends FrameGraphTask {
this._renderer.renderList = this.objectList.meshes;
this._renderer.particleSystemList = this.objectList.particleSystems;

pass.frameGraphRenderTarget!.renderTargetWrapper!.resolveMSAAColors = this.resolveMSAAColors;
pass.frameGraphRenderTarget!.renderTargetWrapper!.resolveMSAADepth = this.resolveMSAADepth;

context.setDepthStates(this.depthTest && depthEnabled, this.depthWrite && depthEnabled);

this._clearAttachmentsLayout.forEach((layout, clearType) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ export class FrameGraphObjectRendererTask extends FrameGraphTask {
this._renderer.enableOutlineRendering = value;
}

/**
* If true, targetTexture will be resolved at the end of the render pass, if this/these texture(s) is/are MSAA (default: true)
*/
public resolveMSAAColors = true;

/**
* If true, depthTexture will be resolved at the end of the render pass, if this texture is provided and is MSAA (default: false).
*/
public resolveMSAADepth = false;

/**
* The output texture.
* This texture will point to the same texture than the targetTexture property.
Expand Down Expand Up @@ -318,6 +328,9 @@ export class FrameGraphObjectRendererTask extends FrameGraphTask {
this._renderer.renderList = this.objectList.meshes;
this._renderer.particleSystemList = this.objectList.particleSystems;

pass.frameGraphRenderTarget!.renderTargetWrapper!.resolveMSAAColors = this.resolveMSAAColors;
pass.frameGraphRenderTarget!.renderTargetWrapper!.resolveMSAADepth = this.resolveMSAADepth;

// The cast to "any" is to avoid an error in ES6 in case you don't import boundingBoxRenderer
const boundingBoxRenderer = (this as any).getBoundingBoxRenderer?.() as Nullable<BoundingBoxRenderer>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class FrameGraphClearTextureTask extends FrameGraphTask {
this.outputDepthTexture = this._frameGraph.textureManager.createDanglingHandle();
}

public record(): FrameGraphRenderPass {
public record(skipCreationOfDisabledPasses = false): FrameGraphRenderPass {
if (this.targetTexture === undefined && this.depthTexture === undefined) {
throw new Error(`FrameGraphClearTextureTask ${this.name}: targetTexture and depthTexture can't both be undefined.`);
}
Expand Down Expand Up @@ -112,11 +112,13 @@ export class FrameGraphClearTextureTask extends FrameGraphTask {
context.clearAttachments(color, attachments, !!this.clearColor, !!this.clearDepth, !!this.clearStencil, this.stencilValue);
});

const passDisabled = this._frameGraph.addRenderPass(this.name + "_disabled", true);
if (!skipCreationOfDisabledPasses) {
const passDisabled = this._frameGraph.addRenderPass(this.name + "_disabled", true);

passDisabled.setRenderTarget(targetTextures);
passDisabled.setRenderTargetDepth(this.depthTexture);
passDisabled.setExecuteFunc((_context) => {});
passDisabled.setRenderTarget(targetTextures);
passDisabled.setRenderTargetDepth(this.depthTexture);
passDisabled.setExecuteFunc((_context) => {});
}

return pass;
}
Expand Down
16 changes: 8 additions & 8 deletions packages/dev/core/src/FrameGraph/frameGraph.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Scene, AbstractEngine, FrameGraphTask, Nullable, NodeRenderGraph, IDisposable } from "core/index";
import { FrameGraphPass } from "./Passes/pass";
import { FrameGraphRenderPass } from "./Passes/renderPass";
import { FrameGraphCullPass } from "./Passes/cullPass";
import { FrameGraphObjectListPass } from "./Passes/objectListPass";
import { FrameGraphRenderContext } from "./frameGraphRenderContext";
import { FrameGraphContext } from "./frameGraphContext";
import { FrameGraphTextureManager } from "./frameGraphTextureManager";
Expand All @@ -16,7 +16,7 @@ import "core/Engines/WebGPU/Extensions/engine.multiRender";
enum FrameGraphPassType {
Normal = 0,
Render = 1,
Cull = 2,
ObjectList = 2,
}

/**
Expand Down Expand Up @@ -170,13 +170,13 @@ export class FrameGraph implements IDisposable {
}

/**
* Adds a cull pass to a task. This method can only be called during a Task.record execution.
* Adds an object list pass to a task. This method can only be called during a Task.record execution.
* @param name The name of the pass
* @param whenTaskDisabled If true, the pass will be added to the list of passes to execute when the task is disabled (default is false)
* @returns The cull pass created
* @returns The object list pass created
*/
public addCullPass(name: string, whenTaskDisabled = false): FrameGraphCullPass {
return this._addPass(name, FrameGraphPassType.Cull, whenTaskDisabled) as FrameGraphCullPass;
public addObjectListPass(name: string, whenTaskDisabled = false): FrameGraphObjectListPass {
return this._addPass(name, FrameGraphPassType.ObjectList, whenTaskDisabled) as FrameGraphObjectListPass;
}

private _addPass(name: string, passType: FrameGraphPassType, whenTaskDisabled = false): FrameGraphPass<FrameGraphContext> | FrameGraphRenderPass {
Expand All @@ -190,8 +190,8 @@ export class FrameGraph implements IDisposable {
case FrameGraphPassType.Render:
pass = new FrameGraphRenderPass(name, this._currentProcessedTask, this._renderContext, this._engine);
break;
case FrameGraphPassType.Cull:
pass = new FrameGraphCullPass(name, this._currentProcessedTask, this._passContext, this._engine);
case FrameGraphPassType.ObjectList:
pass = new FrameGraphObjectListPass(name, this._currentProcessedTask, this._passContext, this._engine);
break;
default:
pass = new FrameGraphPass(name, this._currentProcessedTask, this._passContext);
Expand Down
6 changes: 3 additions & 3 deletions packages/dev/core/src/FrameGraph/frameGraphTask.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FrameGraph, FrameGraphObjectList, IFrameGraphPass, Nullable, FrameGraphTextureHandle, InternalTexture, FrameGraphRenderContext } from "core/index";
import { FrameGraphCullPass } from "./Passes/cullPass";
import { FrameGraphObjectListPass } from "./Passes/objectListPass";
import { FrameGraphRenderPass } from "./Passes/renderPass";
import { Observable } from "core/Misc/observable";

Expand Down Expand Up @@ -145,7 +145,7 @@ export abstract class FrameGraphTask {
}
}
outputDepthTexture = pass.renderTargetDepth !== undefined ? this._frameGraph.textureManager.getTextureFromHandle(pass.renderTargetDepth) : null;
} else if (FrameGraphCullPass.IsCullPass(pass)) {
} else if (FrameGraphObjectListPass.IsObjectListPass(pass)) {
outputObjectList = pass.objectList;
}
}
Expand All @@ -170,7 +170,7 @@ export abstract class FrameGraphTask {
}
disabledOutputTextureHandle = handles;
disabledOutputDepthTexture = pass.renderTargetDepth !== undefined ? this._frameGraph.textureManager.getTextureFromHandle(pass.renderTargetDepth) : null;
} else if (FrameGraphCullPass.IsCullPass(pass)) {
} else if (FrameGraphObjectListPass.IsObjectListPass(pass)) {
disabledOutputObjectList = pass.objectList;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/dev/core/src/FrameGraph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export * from "./Node/nodeRenderGraphBuildState";
export * from "./Node/Types/nodeRenderGraphTypes";
export * from "./Node/Blocks/index";

export * from "./Passes/cullPass";
export * from "./Passes/objectListPass";
export * from "./Passes/pass";
export * from "./Passes/renderPass";

Expand Down
Loading
Loading