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 indirect drawing support #1335

Merged
merged 5 commits into from
Nov 4, 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
27 changes: 17 additions & 10 deletions src-testing/changes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3874,7 +3874,7 @@ index 006bc295..eb39fca8 100644
}

diff --git a/src-testing/src/renderers/common/Geometries.ts b/src-testing/src/renderers/common/Geometries.ts
index 9072f238..a8e29552 100644
index 14c52f6f..2a170106 100644
--- a/src-testing/src/renderers/common/Geometries.ts
+++ b/src-testing/src/renderers/common/Geometries.ts
@@ -1,9 +1,15 @@
Expand Down Expand Up @@ -3961,16 +3961,18 @@ index 9072f238..a8e29552 100644
const geometry = renderObject.geometry;
const geometryData = this.get(geometry);

@@ -109,7 +125,7 @@ class Geometries extends DataMap {
@@ -109,9 +125,8 @@ class Geometries extends DataMap {
geometry.addEventListener('dispose', onDispose);
}

- updateAttributes(renderObject) {
+ updateAttributes(renderObject: RenderObject) {
// attributes
-
const attributes = renderObject.getAttributes();

for (const attribute of attributes) {
@@ -127,10 +143,10 @@ class Geometries extends DataMap {
@@ -139,10 +154,10 @@ class Geometries extends DataMap {
}
}

Expand All @@ -3983,7 +3985,7 @@ index 9072f238..a8e29552 100644
if (this.attributeCall.get(attribute) !== callId) {
this.attributes.update(attribute, type);

@@ -141,17 +157,17 @@ class Geometries extends DataMap {
@@ -153,21 +168,21 @@ class Geometries extends DataMap {
this.attributes.update(attribute, type);

this.attributeCall.set(attribute, callId);
Expand All @@ -3999,6 +4001,11 @@ index 9072f238..a8e29552 100644
}
}

- getIndirect(renderObject) {
+ getIndirect(renderObject: RenderObject) {
return renderObject.geometry.indirect;
}

- getIndex(renderObject) {
+ getIndex(renderObject: RenderObject) {
const { geometry, material } = renderObject;
Expand Down Expand Up @@ -4751,7 +4758,7 @@ index 3fc3134e..c002ed0c 100644
}

diff --git a/src-testing/src/renderers/common/RenderObject.ts b/src-testing/src/renderers/common/RenderObject.ts
index 55fb4318..ea297bfd 100644
index e46d3871..a978762a 100644
--- a/src-testing/src/renderers/common/RenderObject.ts
+++ b/src-testing/src/renderers/common/RenderObject.ts
@@ -1,9 +1,27 @@
Expand Down Expand Up @@ -4874,7 +4881,7 @@ index 55fb4318..ea297bfd 100644

return true;
}
@@ -118,7 +188,7 @@ export default class RenderObject {
@@ -122,7 +192,7 @@ export default class RenderObject {
}

getChainArray() {
Expand All @@ -4883,7 +4890,7 @@ index 55fb4318..ea297bfd 100644
}

getAttributes() {
@@ -127,8 +197,8 @@ export default class RenderObject {
@@ -131,8 +201,8 @@ export default class RenderObject {
const nodeAttributes = this.getNodeBuilderState().nodeAttributes;
const geometry = this.geometry;

Expand All @@ -4894,7 +4901,7 @@ index 55fb4318..ea297bfd 100644

for (const nodeAttribute of nodeAttributes) {
const attribute =
@@ -341,6 +411,6 @@ export default class RenderObject {
@@ -345,6 +415,6 @@ export default class RenderObject {
dispose() {
this.material.removeEventListener('dispose', this.onMaterialDispose);

Expand Down Expand Up @@ -7724,10 +7731,10 @@ index b1e72064..40f26bf1 100644
const nodeData = this.getDataFromNode(node, shaderStage, this.globalCache);

diff --git a/src-testing/src/renderers/webgpu/WebGPUBackend.ts b/src-testing/src/renderers/webgpu/WebGPUBackend.ts
index 263ccfa4..840b556c 100644
index f14d7df5..4fe783d9 100644
--- a/src-testing/src/renderers/webgpu/WebGPUBackend.ts
+++ b/src-testing/src/renderers/webgpu/WebGPUBackend.ts
@@ -947,7 +947,7 @@ class WebGPUBackend extends Backend {
@@ -963,7 +963,7 @@ class WebGPUBackend extends Backend {
this.textureUtils.destroyTexture(texture);
}

Expand Down
1 change: 1 addition & 0 deletions types/three/src/Three.WebGPU.Nodes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export { default as PMREMGenerator } from "./renderers/common/extras/PMREMGenera
export { default as PostProcessing } from "./renderers/common/PostProcessing.js";
import * as PostProcessingUtils from "./renderers/common/PostProcessingUtils.js";
export { PostProcessingUtils };
export { default as IndirectStorageBufferAttribute } from "./renderers/common/IndirectStorageBufferAttribute.js";
export { default as QuadMesh } from "./renderers/common/QuadMesh.js";
export type { default as Renderer } from "./renderers/common/Renderer.js";
export { default as StorageBufferAttribute } from "./renderers/common/StorageBufferAttribute.js";
Expand Down
1 change: 1 addition & 0 deletions types/three/src/Three.WebGPU.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export { default as PMREMGenerator } from "./renderers/common/extras/PMREMGenera
export { default as PostProcessing } from "./renderers/common/PostProcessing.js";
import * as PostProcessingUtils from "./renderers/common/PostProcessingUtils.js";
export { PostProcessingUtils };
export { default as IndirectStorageBufferAttribute } from "./renderers/common/IndirectStorageBufferAttribute.js";
export { default as QuadMesh } from "./renderers/common/QuadMesh.js";
export type { default as Renderer } from "./renderers/common/Renderer.js";
export { default as StorageBufferAttribute } from "./renderers/common/StorageBufferAttribute.js";
Expand Down
7 changes: 7 additions & 0 deletions types/three/src/core/BufferGeometry.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Quaternion } from "../math/Quaternion.js";
import { Sphere } from "../math/Sphere.js";
import { Vector2 } from "../math/Vector2.js";
import { Vector3, Vector3Tuple } from "../math/Vector3.js";
import IndirectStorageBufferAttribute from "../renderers/common/IndirectStorageBufferAttribute.js";
import { BufferAttribute, BufferAttributeJSON } from "./BufferAttribute.js";
import { EventDispatcher } from "./EventDispatcher.js";
import { GLBufferAttribute } from "./GLBufferAttribute.js";
Expand Down Expand Up @@ -155,6 +156,8 @@ export class BufferGeometry<
*/
index: BufferAttribute | null;

indirect: IndirectStorageBufferAttribute | null;

/**
* This hashmap has as id the name of the attribute to be set and as value the {@link THREE.BufferAttribute | buffer} to set it to. Rather than accessing this property directly,
* use {@link setAttribute | .setAttribute} and {@link getAttribute | .getAttribute} to access attributes of this geometry.
Expand Down Expand Up @@ -233,6 +236,10 @@ export class BufferGeometry<
*/
setIndex(index: BufferAttribute | number[] | null): this;

setIndirect(indirect: IndirectStorageBufferAttribute | null): this;

getIndirect(): IndirectStorageBufferAttribute | null;

/**
* Sets an {@link attributes | attribute} to this geometry with the specified name.
* @remarks
Expand Down
1 change: 1 addition & 0 deletions types/three/src/renderers/common/Geometries.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ declare class Geometries extends DataMap<{
initGeometry(renderObject: RenderObject): void;
updateAttributes(renderObject: RenderObject): void;
updateAttribute(attribute: BufferAttribute | InterleavedBufferAttribute, type: AttributeType): void;
getIndirect(renderObject: RenderObject): import("./IndirectStorageBufferAttribute.js").default | null;
getIndex(renderObject: RenderObject): BufferAttribute | null;
}
export default Geometries;
1 change: 1 addition & 0 deletions types/three/src/renderers/common/RenderObject.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default class RenderObject {
getMonitor(): NodeMaterialObserver;
getBindings(): BindGroup[];
getIndex(): BufferAttribute | null;
getIndirect(): import("./IndirectStorageBufferAttribute.js").default | null;
getChainArray(): readonly [
Object3D<import("../../core/Object3D.js").Object3DEventMap>,
Material,
Expand Down
Loading