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: Improved Shaders Names For Debug #1470

Merged
merged 5 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
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
366 changes: 224 additions & 142 deletions src-testing/changes.patch

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions types/three/src/nodes/gpgpu/ComputeNode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ export default class ComputeNode extends Node {
count: number;
workgroupSize: number[];
dispatchCount: number;
name: string;

onInitFunction: ((args: { renderer: Renderer }) => void) | null;

constructor(computeNode: Node, count: number, workgroupSize?: number[]);

label(name: string): void;

updateDispatchCount(): void;

onInit(callback: ((args: { renderer: Renderer }) => void) | null): void;
}

Expand Down
2 changes: 1 addition & 1 deletion types/three/src/renderers/common/Animation.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ declare class Animation {
/**
* Constructs a new animation loop management component.
*
* @param {Nodes} nodes - Renderer component for managing nodes relatd logic.
* @param {Nodes} nodes - Renderer component for managing nodes related logic.
* @param {Info} info - Renderer component for managing metrics and monitoring data.
*/
constructor(nodes: Nodes, info: Info);
Expand Down
2 changes: 1 addition & 1 deletion types/three/src/renderers/common/Background.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ declare class Background extends DataMap<{
* Constructs a new background management component.
*
* @param {Renderer} renderer - The renderer.
* @param {Nodes} nodes - Renderer component for managing nodes relatd logic.
* @param {Nodes} nodes - Renderer component for managing nodes related logic.
*/
constructor(renderer: Renderer, nodes: Nodes);
/**
Expand Down
27 changes: 27 additions & 0 deletions types/three/src/renderers/common/Info.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Object3D } from "../../core/Object3D.js";
/**
* This renderer module provides a series of statistical information
* about the GPU memory and the rendering process. Useful for debugging
* and monitoring.
*/
declare class Info {
autoReset: boolean;
frame: number;
Expand All @@ -25,10 +30,32 @@ declare class Info {
geometries: number;
textures: number;
};
/**
* Constructs a new info component.
*/
constructor();
/**
* This method should be executed per draw call and updates the corresponding metrics.
*
* @param {Object3D} object - The 3D object that is going to be rendered.
* @param {Number} count - The vertex or index count.
* @param {Number} instanceCount - The instance count.
*/
update(object: Object3D, count: number, instanceCount: number): void;
/**
* Used by async render methods to updated timestamp metrics.
*
* @param {('render'|'compute')} type - The type of render call.
* @param {Number} time - The duration of the compute/render call in milliseconds.
*/
updateTimestamp(type: "render" | "compute", time: number): void;
/**
* Resets frame related metrics.
*/
reset(): void;
/**
* Performs a complete reset of the object.
*/
dispose(): void;
}
export default Info;
103 changes: 103 additions & 0 deletions types/three/src/renderers/common/Pipelines.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ interface ComputeNodeData {
interface RenderObjectData {
pipeline: RenderPipeline;
}
/**
* This renderer module manages the pipelines of the renderer.
*
* @private
*/
declare class Pipelines extends DataMap<{
computeNode: {
key: ComputeNode;
Expand All @@ -35,34 +40,132 @@ declare class Pipelines extends DataMap<{
fragment: Map<string, ProgrammableStage>;
compute: Map<string, ProgrammableStage>;
};
/**
* Constructs a new pipeline management component.
*
* @param {Backend} backend - The renderer's backend.
* @param {Nodes} nodes - Renderer component for managing nodes related logic.
*/
constructor(backend: Backend, nodes: Nodes);
/**
* Returns a compute pipeline for the given compute node.
*
* @param {Node} computeNode - The compute node.
* @param {Array<BindGroup>} bindings - The bindings.
* @return {ComputePipeline} The compute pipeline.
*/
getForCompute(computeNode: ComputeNode, bindings: Binding[]): ComputePipeline;
/**
* Returns a render pipeline for the given render object.
*
* @param {RenderObject} renderObject - The render object.
* @param {Array<Promise>?} [promises=null] - An array of compilation promises which is only relevant in context of `Renderer.compileAsync()`.
* @return {RenderPipeline} The render pipeline.
*/
getForRender(renderObject: RenderObject, promises?: Promise<void>[] | null): RenderPipeline;
/**
* Deletes the pipeline for the given render object.
*
* @param {RenderObject} object - The render object.
* @return {Object?} The deleted dictionary.
*/
delete(object: ComputeNode | RenderObject): never;
/**
* Frees internal resources.
*/
dispose(): void;
/**
* Updates the pipeline for the given render object.
*
* @param {RenderObject} renderObject - The render object.
*/
updateForRender(renderObject: RenderObject): void;
/**
* Returns a compute pipeline for the given parameters.
*
* @private
* @param {Node} computeNode - The compute node.
* @param {ProgrammableStage} stageCompute - The programmable stage representing the compute shader.
* @param {String} cacheKey - The cache key.
* @param {Array<BindGroup>} bindings - The bindings.
* @return {ComputePipeline} The compute pipeline.
*/
_getComputePipeline(
computeNode: ComputeNode,
stageCompute: ProgrammableStage,
cacheKey: string,
bindings: Binding[],
): ComputePipeline;
/**
* Returns a render pipeline for the given parameters.
*
* @private
* @param {RenderObject} renderObject - The render object.
* @param {ProgrammableStage} stageVertex - The programmable stage representing the vertex shader.
* @param {ProgrammableStage} stageFragment - The programmable stage representing the fragment shader.
* @param {String} cacheKey - The cache key.
* @param {Array} promises - An array of compilation promises which is only relevant in context of `Renderer.compileAsync()`.
* @return {ComputePipeline} The compute pipeline.
*/
_getRenderPipeline(
renderObject: RenderObject,
stageVertex: ProgrammableStage,
stageFragment: ProgrammableStage,
cacheKey: string,
promises: Promise<void>[] | null,
): RenderPipeline;
/**
* Computes a cache key representing a compute pipeline.
*
* @private
* @param {Node} computeNode - The compute node.
* @param {ProgrammableStage} stageCompute - The programmable stage representing the compute shader.
* @return {String} The cache key.
*/
_getComputeCacheKey(computeNode: ComputeNode, stageCompute: ProgrammableStage): string;
/**
* Computes a cache key representing a render pipeline.
*
* @private
* @param {RenderObject} renderObject - The render object.
* @param {ProgrammableStage} stageVertex - The programmable stage representing the vertex shader.
* @param {ProgrammableStage} stageFragment - The programmable stage representing the fragment shader.
* @return {String} The cache key.
*/
_getRenderCacheKey(
renderObject: RenderObject,
stageVertex: ProgrammableStage,
stageFragment: ProgrammableStage,
): string;
/**
* Releases the given pipeline.
*
* @private
* @param {Pipeline} pipeline - The pipeline to release.
*/
_releasePipeline(pipeline: Pipeline): void;
/**
* Releases the shader program.
*
* @private
* @param {Object} program - The shdaer program to release.
*/
_releaseProgram(program: ProgrammableStage): void;
/**
* Returns `true` if the compute pipeline for the given compute node requires an update.
*
* @private
* @param {Node} computeNode - The compute node.
* @return {Boolean} Whether the compute pipeline for the given compute node requires an update or not.
*/
_needsComputeUpdate(computeNode: ComputeNode): boolean;
/**
* Returns `true` if the render pipeline for the given render object requires an update.
*
* @private
* @param {RenderObject} renderObject - The render object.
* @return {Boolean} Whether the render object for the given render object requires an update or not.
*/
_needsRenderUpdate(renderObject: RenderObject): true | void;
}
export default Pipelines;
3 changes: 3 additions & 0 deletions types/three/src/renderers/common/ProgrammableStage.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ declare class ProgrammableStage {
id: number;
code: string;
stage: "compute" | "vertex" | "fragment";
name: string;
attributes: NodeAttribute[] | null;
usedTimes: number;
/**
* Constructs a new programmable stage.
*
* @param {String} code - The shader code.
* @param {('vertex'|'fragment'|'compute')} stage - The type of stage.
* @param {String} name - The name of the shader.
* @param {Array<Object>?} [transforms=null] - The transforms (only relevant for compute stages with WebGL 2 which uses Transform Feedback).
* @param {Array<Object>?} [attributes=null] - The attributes (only relevant for compute stages with WebGL 2 which uses Transform Feedback).
*/
constructor(
code: string,
stage: "compute" | "vertex" | "fragment",
name: string,
transforms?: null,
attributes?: NodeAttribute[] | null,
);
Expand Down
22 changes: 22 additions & 0 deletions types/three/src/renderers/common/RenderContext.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import { Vector4 } from "../../math/Vector4.js";
import { DepthTexture } from "../../textures/DepthTexture.js";
import { Texture } from "../../textures/Texture.js";
import ClippingContext from "./ClippingContext.js";
/**
* Any render or compute command is executed in a specific context that defines
* the state of the renderer and its backend. Typical examples for such context
* data are the current clear values or data from the active framebuffer. This
* module is used to represent these contexts as objects.
*
* @private
*/
declare class RenderContext {
id: number;
color: boolean;
Expand Down Expand Up @@ -36,8 +44,22 @@ declare class RenderContext {
renderTarget?: RenderTarget | undefined;
activeMipmapLevel?: number | undefined;
occlusionQueryCount?: number | undefined;
/**
* Constructs a new render context.
*/
constructor();
/**
* Returns the cache key of this render context.
*
* @return {Number} The cache key.
*/
getCacheKey(): number;
}
/**
* Computes a cache key for the given render context.
*
* @param {RenderContext} renderContext - The render context.
* @return {Number} The cache key.
*/
export declare function getCacheKey(renderContext: RenderContext): number;
export default RenderContext;
25 changes: 25 additions & 0 deletions types/three/src/renderers/common/RenderContexts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { Object3D } from "../../core/Object3D.js";
import { RenderTarget } from "../../core/RenderTarget.js";
import ChainMap from "./ChainMap.js";
import RenderContext from "./RenderContext.js";
/**
* This module manages the render contexts of the renderer.
*
* @private
*/
declare class RenderContexts {
chainMaps: {
[attachmentState: string]:
Expand All @@ -15,8 +20,25 @@ declare class RenderContexts {
>
| undefined;
};
/**
* Constructs a new render context management component.
*/
constructor();
/**
* Returns a render context for the given scene, camera and render target.
*
* @param {Scene?} [scene=null] - The scene. The parameter can become `null` e.g. when the renderer clears a render target.
* @param {Camera?} [camera=null] - The camera that is used to render the scene. The parameter can become `null` e.g. when the renderer clears a render target.
* @param {RenderTarget?} [renderTarget=null] - The active render target.
* @return {RenderContext} The render context.
*/
get(scene?: Object3D | null, camera?: Camera | null, renderTarget?: RenderTarget | null): RenderContext;
/**
* Returns a chain map for the given attachment state.
*
* @param {String} attachmentState - The attachment state.
* @return {ChainMap} The chain map.
*/
getChainMap(
attachmentState: string,
): ChainMap<
Expand All @@ -26,6 +48,9 @@ declare class RenderContexts {
}],
RenderContext
>;
/**
* Frees internal resources.
*/
dispose(): void;
}
export default RenderContexts;
Loading
Loading