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: Introduce Bind Groups #1053

Merged
merged 10 commits into from
Jun 25, 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
433 changes: 273 additions & 160 deletions examples-jsm/changes.patch

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples-jsm/create-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const files = [
'renderers/common/Attributes',
'renderers/common/Backend',
'renderers/common/Background',
'renderers/common/BindGroup',
'renderers/common/Binding',
'renderers/common/Bindings',
'renderers/common/Buffer',
Expand Down
1 change: 1 addition & 0 deletions examples-jsm/declarations.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const files = [
'renderers/common/Animation',
'renderers/common/Attributes',
'renderers/common/Background',
'renderers/common/BindGroup',
'renderers/common/Binding',
'renderers/common/Bindings',
'renderers/common/Buffer',
Expand Down
20 changes: 6 additions & 14 deletions examples-testing/changes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -12634,7 +12634,7 @@ index 366a2791..74077e99 100644
+ console.log('after', renderer.info.programs!.length);
}
diff --git a/examples-testing/examples/webgl_test_wide_gamut.ts b/examples-testing/examples/webgl_test_wide_gamut.ts
index 57c38ba0..1da45af5 100644
index 620caaf1..6699085b 100644
--- a/examples-testing/examples/webgl_test_wide_gamut.ts
+++ b/examples-testing/examples/webgl_test_wide_gamut.ts
@@ -2,8 +2,8 @@ import * as THREE from 'three';
Expand Down Expand Up @@ -12682,29 +12682,21 @@ index 57c38ba0..1da45af5 100644

slider.style.left = sliderPos - slider.offsetWidth / 2 + 'px';
}
@@ -90,18 +90,18 @@ function onWindowResize() {
@@ -90,11 +90,11 @@ function onWindowResize() {

renderer.setSize(window.innerWidth, window.innerHeight);

- containTexture(window.innerWidth / window.innerHeight, sceneL.background);
- containTexture(window.innerWidth / window.innerHeight, sceneR.background);
+ containTexture(window.innerWidth / window.innerHeight, sceneL.background as THREE.Texture);
+ containTexture(window.innerWidth / window.innerHeight, sceneR.background as THREE.Texture);
- THREE.TextureUtils.contain(sceneL.background, window.innerWidth / window.innerHeight);
- THREE.TextureUtils.contain(sceneR.background, window.innerWidth / window.innerHeight);
+ THREE.TextureUtils.contain(sceneL.background as THREE.Texture, window.innerWidth / window.innerHeight);
+ THREE.TextureUtils.contain(sceneR.background as THREE.Texture, window.innerWidth / window.innerHeight);
}

-function onGamutChange({ matches }) {
+function onGamutChange({ matches }: MediaQueryListEvent) {
renderer.outputColorSpace = isP3Context && matches ? THREE.DisplayP3ColorSpace : THREE.SRGBColorSpace;

textureL.needsUpdate = true;
textureR.needsUpdate = true;
}

-function containTexture(aspect, target) {
+function containTexture(aspect: number, target: THREE.Texture) {
// Sets the matrix uv transform so the texture image is contained in a region having the specified aspect ratio,
// and does so without distortion. Akin to CSS object-fit: contain.
// Source: https://github.com/mrdoob/three.js/pull/17199
diff --git a/examples-testing/examples/webgl_texture2darray_compressed.ts b/examples-testing/examples/webgl_texture2darray_compressed.ts
index f263be70..bc8f8622 100644
--- a/examples-testing/examples/webgl_texture2darray_compressed.ts
Expand Down
2 changes: 1 addition & 1 deletion three.js
Submodule three.js updated 38 files
+214 −69 build/three.cjs
+214 −70 build/three.module.js
+1 −1 build/three.module.min.js
+15 −0 docs/api/en/extras/TextureUtils.html
+2 −1 docs/list.json
+51 −2 examples/jsm/helpers/ViewHelper.js
+8 −4 examples/jsm/loaders/GLTFLoader.js
+16 −9 examples/jsm/nodes/accessors/CameraNode.js
+2 −2 examples/jsm/nodes/accessors/InstanceNode.js
+96 −17 examples/jsm/nodes/core/NodeBuilder.js
+2 −2 examples/jsm/nodes/core/NodeFunction.js
+1 −2 examples/jsm/nodes/core/NodeUniform.js
+9 −17 examples/jsm/nodes/materialx/lib/mx_hsv.js
+472 −575 examples/jsm/nodes/materialx/lib/mx_noise.js
+2 −8 examples/jsm/nodes/materialx/lib/mx_transform_color.js
+6 −6 examples/jsm/nodes/math/OperatorNode.js
+7 −7 examples/jsm/nodes/parsers/GLSLNodeFunction.js
+1 −1 examples/jsm/renderers/common/Backend.js
+16 −0 examples/jsm/renderers/common/BindGroup.js
+38 −23 examples/jsm/renderers/common/Bindings.js
+22 −9 examples/jsm/renderers/common/nodes/NodeBuilderState.js
+6 −5 examples/jsm/renderers/common/nodes/NodeSampledTexture.js
+2 −1 examples/jsm/renderers/common/nodes/NodeSampler.js
+2 −1 examples/jsm/renderers/common/nodes/NodeStorageBuffer.js
+2 −1 examples/jsm/renderers/common/nodes/NodeUniformBuffer.js
+0 −6 examples/jsm/renderers/common/nodes/NodeUniformsGroup.js
+1 −0 examples/jsm/renderers/common/nodes/Nodes.js
+55 −41 examples/jsm/renderers/webgl/WebGLBackend.js
+29 −22 examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js
+23 −11 examples/jsm/renderers/webgpu/WebGPUBackend.js
+21 −25 examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js
+9 −9 examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js
+26 −4 examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js
+46 −4 examples/jsm/transpiler/GLSLDecoder.js
+1 −1 examples/webgl_loader_ifc.html
+4 −28 examples/webgl_test_wide_gamut.html
+71 −2 src/extras/TextureUtils.js
+3 −3 src/renderers/webgl/WebGLTextures.js
2 changes: 1 addition & 1 deletion types/three/examples/jsm/nodes/core/NodeUniform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ declare class NodeUniform<TValue> {
type: string | null;
node: UniformNode<TValue>;
needsUpdate: boolean | undefined;
constructor(name: string, type: string | null, node: UniformNode<TValue>, needsUpdate?: undefined);
constructor(name: string, type: string | null, node: UniformNode<TValue>);
get value(): TValue;
set value(val: TValue);
get id(): number;
Expand Down
9 changes: 9 additions & 0 deletions types/three/examples/jsm/renderers/common/BindGroup.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Binding from "./Binding.js";
import NodeUniformsGroup from "./nodes/NodeUniformsGroup.js";
declare class BindGroup {
name: string;
bindings: NodeUniformsGroup[] | Binding[];
id: number;
constructor(name?: string, bindings?: NodeUniformsGroup[]);
}
export default BindGroup;
25 changes: 11 additions & 14 deletions types/three/examples/jsm/renderers/common/Bindings.d.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import ComputeNode from "../../nodes/gpgpu/ComputeNode.js";
import Attributes from "./Attributes.js";
import Backend from "./Backend.js";
import Binding from "./Binding.js";
import BindGroup from "./BindGroup.js";
import DataMap from "./DataMap.js";
import Info from "./Info.js";
import Nodes from "./nodes/Nodes.js";
import Pipelines from "./Pipelines.js";
import RenderObject from "./RenderObject.js";
import Textures from "./Textures.js";
interface Data {
bindings?: Binding[] | undefined;
interface BindGroupData {
bindGroup?: BindGroup | undefined;
}
declare class Bindings extends DataMap<{
renderObject: {
key: RenderObject;
value: Data;
};
computeNode: {
key: ComputeNode;
value: Data;
bindGroup: {
key: BindGroup;
value: BindGroupData;
};
}> {
backend: Backend;
Expand All @@ -35,11 +31,12 @@ declare class Bindings extends DataMap<{
pipelines: Pipelines,
info: Info,
);
getForRender(renderObject: RenderObject): Binding[];
getForCompute(computeNode: ComputeNode): Binding[];
getForRender(renderObject: RenderObject): BindGroup[];
getForCompute(computeNode: ComputeNode): BindGroup[];
updateForCompute(computeNode: ComputeNode): void;
updateForRender(renderObject: RenderObject): void;
_init(bindings: Binding[]): void;
_update(object: ComputeNode | RenderObject, bindings: Binding[]): void;
_updateBindings(object: ComputeNode | RenderObject, bindings: BindGroup[]): void;
_init(bindGroup: BindGroup): void;
_update(object: ComputeNode | RenderObject, bindGroup: BindGroup, bindings: BindGroup[]): void;
}
export default Bindings;
6 changes: 3 additions & 3 deletions types/three/examples/jsm/renderers/common/RenderObject.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Scene,
} from "three";
import LightsNode from "../../nodes/lighting/LightsNode.js";
import Binding from "./Binding.js";
import BindGroup from "./BindGroup.js";
import ClippingContext from "./ClippingContext.js";
import Geometries from "./Geometries.js";
import NodeBuilderState from "./nodes/NodeBuilderState.js";
Expand Down Expand Up @@ -42,7 +42,7 @@ export default class RenderObject {
initialNodesCacheKey: string;
initialCacheKey: string;
_nodeBuilderState: NodeBuilderState | null;
_bindings: Binding[] | null;
_bindings: BindGroup[] | null;
onDispose: (() => void) | null;
readonly isRenderObject: true;
onMaterialDispose: () => void;
Expand All @@ -60,7 +60,7 @@ export default class RenderObject {
updateClipping(parent: ClippingContext): void;
get clippingNeedsUpdate(): boolean;
getNodeBuilderState(): NodeBuilderState;
getBindings(): Binding[];
getBindings(): BindGroup[];
getIndex(): BufferAttribute | null;
getChainArray(): readonly [Object3D<import("three").Object3DEventMap>, Material, RenderContext, LightsNode];
getAttributes(): (InterleavedBufferAttribute | BufferAttribute)[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
import Node from "../../../nodes/core/Node.js";
import NodeAttribute from "../../../nodes/core/NodeAttribute.js";
import Binding from "../Binding.js";
import BindGroup from "../BindGroup.js";
declare class NodeBuilderState {
vertexShader: string | null;
fragmentShader: string | null;
computeShader: string | null;
transforms: never[];
nodeAttributes: NodeAttribute[];
bindings: Binding[];
bindings: BindGroup[];
updateNodes: Node[];
updateBeforeNodes: Node[];
updateAfterNodes: Node[];
instanceBindGroups: boolean;
usedTimes: number;
constructor(
vertexShader: string | null,
fragmentShader: string | null,
computeShader: string | null,
nodeAttributes: NodeAttribute[],
bindings: Binding[],
bindings: BindGroup[],
updateNodes: Node[],
updateBeforeNodes: Node[],
updateAfterNodes: Node[],
instanceBindGroups?: boolean,
transforms?: never[],
);
createBindings(): Binding[];
createBindings(): BindGroup[];
}
export default NodeBuilderState;
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import TextureNode from "../../../nodes/accessors/TextureNode.js";
import UniformGroupNode from "../../../nodes/core/UniformGroupNode.js";
import { SampledTexture } from "../SampledTexture.js";

type GPUStorageTextureAccess = "read-only" | "read-write" | "write-only";

declare class NodeSampledTexture extends SampledTexture {
textureNode: TextureNode | undefined;
groupNode: UniformGroupNode;
access: "read-write" | "read-only" | "write-only";
constructor(name: string, textureNode: TextureNode | undefined, access: GPUStorageTextureAccess | null);
constructor(
name: string,
textureNode: TextureNode | undefined,
groupNode: UniformGroupNode,
access: GPUStorageTextureAccess | null,
);
get needsBindingsUpdate(): boolean;
update(): boolean;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import TextureNode from "../../../nodes/accessors/TextureNode.js";
import UniformGroupNode from "../../../nodes/core/UniformGroupNode.js";
import Sampler from "../Sampler.js";

declare class NodeSampler extends Sampler {
textureNode: TextureNode | undefined;
constructor(name: string, textureNode: TextureNode | undefined);
groupNode: UniformGroupNode;
constructor(name: string, textureNode: TextureNode | undefined, groupNode: UniformGroupNode);
update(): void;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ declare class NodeUniformsGroup extends UniformsGroup {
groupNode: UniformGroupNode;
readonly isNodeUniformsGroup: true;
constructor(name: string, groupNode: UniformGroupNode);
get shared(): boolean;
getNodes(): UniformNode<unknown>[];
}
export default NodeUniformsGroup;
Loading