Skip to content

Commit

Permalink
WebGPURenderer: Add .outputType backend parameter (#1508)
Browse files Browse the repository at this point in the history
* Update three.js

* Add src

* Update patch and delete src

* Update declarations

* WebGPURenderer: Add .outputType backend parameter

* Update three.js

* Add src

* Update patch and delete src
  • Loading branch information
Methuselah96 authored Jan 21, 2025
1 parent bad775e commit 18cf1ce
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 44 deletions.
68 changes: 34 additions & 34 deletions src-testing/changes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -2540,7 +2540,7 @@ index 2e8a372c..0dd736ec 100644
* This flag can be used for type testing.
*
diff --git a/src-testing/src/nodes/core/NodeUtils.ts b/src-testing/src/nodes/core/NodeUtils.ts
index 0fc08ddc..a3a7fc7e 100644
index 2229f0c0..74580b4a 100644
--- a/src-testing/src/nodes/core/NodeUtils.ts
+++ b/src-testing/src/nodes/core/NodeUtils.ts
@@ -4,6 +4,7 @@ import { Matrix4 } from '../../math/Matrix4.js';
Expand Down Expand Up @@ -3852,7 +3852,7 @@ index 01b8ddeb..e39524b8 100644
* The bind group's name.
*
diff --git a/src-testing/src/renderers/common/Binding.ts b/src-testing/src/renderers/common/Binding.ts
index 4417e9b8..559cc30c 100644
index 9b27454f..cca19581 100644
--- a/src-testing/src/renderers/common/Binding.ts
+++ b/src-testing/src/renderers/common/Binding.ts
@@ -8,6 +8,10 @@
Expand Down Expand Up @@ -4276,7 +4276,7 @@ index b913d6b6..d4d3d9be 100644
if (map === undefined) return false;
}
diff --git a/src-testing/src/renderers/common/ClippingContext.ts b/src-testing/src/renderers/common/ClippingContext.ts
index a7c62000..a41ae955 100644
index 3f08f771..56df8224 100644
--- a/src-testing/src/renderers/common/ClippingContext.ts
+++ b/src-testing/src/renderers/common/ClippingContext.ts
@@ -1,6 +1,10 @@
Expand Down Expand Up @@ -4341,7 +4341,7 @@ index a7c62000..a41ae955 100644
*/
- updateGlobal(scene, camera) {
+ updateGlobal(scene: Scene, camera: Camera) {
this.shadowPass = scene.overrideMaterial !== null && scene.overrideMaterial.isShadowNodeMaterial;
this.shadowPass = scene.overrideMaterial !== null && scene.overrideMaterial.isShadowPassMaterial;
this.viewMatrix = camera.matrixWorldInverse;

@@ -138,12 +159,12 @@ class ClippingContext {
Expand Down Expand Up @@ -4425,7 +4425,7 @@ index a7c62000..a41ae955 100644
}

diff --git a/src-testing/src/renderers/common/Color4.ts b/src-testing/src/renderers/common/Color4.ts
index fc7845fd..414a8b9a 100644
index a1718cff..f991ed90 100644
--- a/src-testing/src/renderers/common/Color4.ts
+++ b/src-testing/src/renderers/common/Color4.ts
@@ -1,4 +1,4 @@
Expand Down Expand Up @@ -4456,7 +4456,7 @@ index fc7845fd..414a8b9a 100644

this.a = a;
}
@@ -32,7 +36,8 @@ class Color4 extends Color {
@@ -34,7 +38,8 @@ class Color4 extends Color {
* @param {Number} [a=1] - The alpha value.
* @return {Color4} A reference to this object.
*/
Expand All @@ -4466,7 +4466,7 @@ index fc7845fd..414a8b9a 100644
this.a = a;

return super.set(r, g, b);
@@ -44,8 +49,8 @@ class Color4 extends Color {
@@ -46,8 +51,8 @@ class Color4 extends Color {
* @param {Color4} color - The color to copy.
* @return {Color4} A reference to this object.
*/
Expand All @@ -4477,7 +4477,7 @@ index fc7845fd..414a8b9a 100644

return super.copy(color);
}
@@ -55,8 +60,8 @@ class Color4 extends Color {
@@ -57,8 +62,8 @@ class Color4 extends Color {
*
* @return {Color4} The cloned color.
*/
Expand Down Expand Up @@ -4905,7 +4905,7 @@ index 0336ccac..0c6fb271 100644
* The pipeline's cache key.
*
diff --git a/src-testing/src/renderers/common/Pipelines.ts b/src-testing/src/renderers/common/Pipelines.ts
index 7c326179..6e64b4a7 100644
index f7939ba6..b397b8c4 100644
--- a/src-testing/src/renderers/common/Pipelines.ts
+++ b/src-testing/src/renderers/common/Pipelines.ts
@@ -2,6 +2,22 @@ import DataMap from './DataMap.js';
Expand Down Expand Up @@ -5149,7 +5149,7 @@ index 7c326179..6e64b4a7 100644
if (pipeline === undefined) {
pipeline = new ComputePipeline(cacheKey, stageCompute);
@@ -312,12 +351,18 @@ class Pipelines extends DataMap {
* @param {Array} promises - An array of compilation promises which is only relevant in context of `Renderer.compileAsync()`.
* @param {Array<Promise>?} promises - An array of compilation promises which is only relevant in context of `Renderer.compileAsync()`.
* @return {ComputePipeline} The compute pipeline.
*/
- _getRenderPipeline(renderObject, stageVertex, stageFragment, cacheKey, promises) {
Expand Down Expand Up @@ -5329,7 +5329,7 @@ index d6c72696..3ae4005b 100644

_chainKeys[0] = bundleGroup;
diff --git a/src-testing/src/renderers/common/RenderContext.ts b/src-testing/src/renderers/common/RenderContext.ts
index 17124b62..ed67c412 100644
index 5edc6d81..e1f0cbbe 100644
--- a/src-testing/src/renderers/common/RenderContext.ts
+++ b/src-testing/src/renderers/common/RenderContext.ts
@@ -1,5 +1,9 @@
Expand Down Expand Up @@ -5386,7 +5386,7 @@ index 17124b62..ed67c412 100644
/**
* Constructs a new render context.
*/
@@ -232,12 +273,12 @@ class RenderContext {
@@ -240,12 +281,12 @@ class RenderContext {
* @param {RenderContext} renderContext - The render context.
* @return {Number} The cache key.
*/
Expand Down Expand Up @@ -5728,7 +5728,7 @@ index d12ad583..ef6e14ec 100644
}

diff --git a/src-testing/src/renderers/common/RenderObject.ts b/src-testing/src/renderers/common/RenderObject.ts
index d4cc350a..8d62b85b 100644
index 85958384..60918f7f 100644
--- a/src-testing/src/renderers/common/RenderObject.ts
+++ b/src-testing/src/renderers/common/RenderObject.ts
@@ -1,8 +1,27 @@
Expand Down Expand Up @@ -5835,7 +5835,7 @@ index d4cc350a..8d62b85b 100644
) {
this.id = _id++;

@@ -295,7 +355,7 @@ class RenderObject {
@@ -305,7 +365,7 @@ class RenderObject {
*
* @param {ClippingContext} context - The clipping context to set.
*/
Expand All @@ -5844,7 +5844,7 @@ index d4cc350a..8d62b85b 100644
this.clippingContext = context;
}

@@ -309,7 +369,7 @@ class RenderObject {
@@ -319,7 +379,7 @@ class RenderObject {
if (this.clippingContext === null || this.clippingContext.cacheKey === this.clippingContextCacheKey)
return false;

Expand All @@ -5853,7 +5853,7 @@ index d4cc350a..8d62b85b 100644

return true;
}
@@ -375,7 +435,7 @@ class RenderObject {
@@ -385,7 +445,7 @@ class RenderObject {
* @return {Array<Object>} An array with object references.
*/
getChainArray() {
Expand All @@ -5862,7 +5862,7 @@ index d4cc350a..8d62b85b 100644
}

/**
@@ -384,7 +444,7 @@ class RenderObject {
@@ -394,7 +454,7 @@ class RenderObject {
*
* @param {BufferGeometry} geometry - The geometry to set.
*/
Expand All @@ -5871,7 +5871,7 @@ index d4cc350a..8d62b85b 100644
this.geometry = geometry;
this.attributes = null;
}
@@ -401,8 +461,8 @@ class RenderObject {
@@ -411,8 +471,8 @@ class RenderObject {
const nodeAttributes = this.getNodeBuilderState().nodeAttributes;
const geometry = this.geometry;

Expand All @@ -5882,7 +5882,7 @@ index d4cc350a..8d62b85b 100644

for (const nodeAttribute of nodeAttributes) {
const attribute =
@@ -693,7 +753,7 @@ class RenderObject {
@@ -708,7 +768,7 @@ class RenderObject {
dispose() {
this.material.removeEventListener('dispose', this.onMaterialDispose);

Expand Down Expand Up @@ -6050,7 +6050,7 @@ index 78ce62cb..e978810d 100644

/**
diff --git a/src-testing/src/renderers/common/Renderer.ts b/src-testing/src/renderers/common/Renderer.ts
index a5ec1592..bfa81fd3 100644
index fd9a9811..e8230f27 100644
--- a/src-testing/src/renderers/common/Renderer.ts
+++ b/src-testing/src/renderers/common/Renderer.ts
@@ -36,7 +36,34 @@ import {
Expand Down Expand Up @@ -6293,7 +6293,7 @@ index a5ec1592..bfa81fd3 100644
scene,
@@ -803,14 +996,14 @@ class Renderer {
* @param {Scene} targetScene - If the first argument is a 3D object, this parameter must represent the scene the 3D object is going to be added.
* @return {Promise} A Promise that resolves when the compile has been finished.
* @return {Promise<Array>} A Promise that resolves when the compile has been finished.
*/
- async compileAsync(scene, camera, targetScene = null) {
+ async compileAsync(scene: Object3D, camera: Camera, targetScene: Object3D | null = null) {
Expand Down Expand Up @@ -6801,7 +6801,7 @@ index a5ec1592..bfa81fd3 100644
*/
- compute(computeNodes) {
+ compute(computeNodes: ComputeNode | ComputeNode[]) {
if (this.isDeviceLost === true) return;
if (this._isDeviceLost === true) return;

if (this._initialized === false) {
@@ -1949,7 +2158,7 @@ class Renderer {
Expand All @@ -6828,7 +6828,7 @@ index a5ec1592..bfa81fd3 100644

@@ -2022,7 +2231,7 @@ class Renderer {
* @param {Node|Array<Node>} computeNodes - The compute node(s).
* @return {Promise?} A Promise that resolve when the compute has finished.
* @return {Promise} A Promise that resolve when the compute has finished.
*/
- async computeAsync(computeNodes) {
+ async computeAsync(computeNodes: ComputeNode | ComputeNode[]) {
Expand Down Expand Up @@ -7056,7 +7056,7 @@ index a5ec1592..bfa81fd3 100644
// process renderable objects

for (let i = 0, il = renderList.length; i < il; i++) {
@@ -2359,18 +2608,18 @@ class Renderer {
@@ -2356,18 +2605,18 @@ class Renderer {

const { object, geometry, material, group, clippingContext } = renderItem;

Expand All @@ -7079,7 +7079,7 @@ index a5ec1592..bfa81fd3 100644
viewportValue.copy(vp).multiplyScalar(this._pixelRatio).floor();
viewportValue.minDepth = minDepth;
viewportValue.maxDepth = maxDepth;
@@ -2378,13 +2627,13 @@ class Renderer {
@@ -2375,13 +2624,13 @@ class Renderer {

this.backend.updateViewport(this._currentRenderContext);

Expand All @@ -7098,7 +7098,7 @@ index a5ec1592..bfa81fd3 100644
lightsNode,
clippingContext,
passId,
@@ -2392,13 +2641,13 @@ class Renderer {
@@ -2389,13 +2638,13 @@ class Renderer {
}
}
} else {
Expand All @@ -7117,7 +7117,7 @@ index a5ec1592..bfa81fd3 100644
lightsNode,
clippingContext,
passId,
@@ -2421,7 +2670,17 @@ class Renderer {
@@ -2418,7 +2667,17 @@ class Renderer {
* @param {ClippingContext} clippingContext - The clipping context.
* @param {String?} [passId=null] - An optional ID for identifying the pass.
*/
Expand All @@ -7136,7 +7136,7 @@ index a5ec1592..bfa81fd3 100644
let overridePositionNode;
let overrideColorNode;
let overrideDepthNode;
@@ -2508,14 +2767,23 @@ class Renderer {
@@ -2505,14 +2764,23 @@ class Renderer {
* @param {ClippingContext} clippingContext - The clipping context.
* @param {String?} [passId=null] - An optional ID for identifying the pass.
*/
Expand All @@ -7163,7 +7163,7 @@ index a5ec1592..bfa81fd3 100644
clippingContext,
passId,
);
@@ -2524,18 +2792,18 @@ class Renderer {
@@ -2521,18 +2789,18 @@ class Renderer {

//

Expand All @@ -7188,7 +7188,7 @@ index a5ec1592..bfa81fd3 100644

//

@@ -2549,7 +2817,7 @@ class Renderer {
@@ -2546,7 +2814,7 @@ class Renderer {

this.backend.draw(renderObject, this.info);

Expand All @@ -7197,7 +7197,7 @@ index a5ec1592..bfa81fd3 100644
}

/**
@@ -2566,14 +2834,23 @@ class Renderer {
@@ -2563,14 +2831,23 @@ class Renderer {
* @param {ClippingContext} clippingContext - The clipping context.
* @param {String?} [passId=null] - An optional ID for identifying the pass.
*/
Expand All @@ -7224,7 +7224,7 @@ index a5ec1592..bfa81fd3 100644
clippingContext,
passId,
);
@@ -2582,16 +2859,16 @@ class Renderer {
@@ -2579,16 +2856,16 @@ class Renderer {

//

Expand Down Expand Up @@ -9214,10 +9214,10 @@ index bc7914ba..ffbf5e67 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 d17e3a4b..eaeb4232 100644
index d566c074..e8126a9c 100644
--- a/src-testing/src/renderers/webgpu/WebGPUBackend.ts
+++ b/src-testing/src/renderers/webgpu/WebGPUBackend.ts
@@ -1279,7 +1279,14 @@ class WebGPUBackend extends Backend {
@@ -1284,7 +1284,14 @@ class WebGPUBackend extends Backend {
* @param {Number} faceIndex - The face index.
* @return {Promise<TypedArray>} A Promise that resolves with a typed array when the copy operation has finished.
*/
Expand Down
2 changes: 2 additions & 0 deletions types/three/src/renderers/common/Color4.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ declare class Color4 extends Color {
constructor(r: number, g: number, b: number, a?: number);
/**
* Overwrites the default to honor alpha.
* You can also passed a single THREE.Color, hex or
* string argument to this method.
*
* @param {Number|String} r - The red value.
* @param {Number} g - The green value.
Expand Down
2 changes: 1 addition & 1 deletion types/three/src/renderers/common/Pipelines.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ declare class Pipelines extends DataMap<{
* @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()`.
* @param {Array<Promise>?} promises - An array of compilation promises which is only relevant in context of `Renderer.compileAsync()`.
* @return {ComputePipeline} The compute pipeline.
*/
_getRenderPipeline(
Expand Down
6 changes: 3 additions & 3 deletions types/three/src/renderers/common/RenderObject.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ declare class RenderObject {
*
* The material cache key is part of the render object cache key.
*
* @return {String} The material cache key.
* @return {Number} The material cache key.
*/
getMaterialCacheKey(): number;
/**
Expand Down Expand Up @@ -234,13 +234,13 @@ declare class RenderObject {
/**
* Returns the dynamic cache key which represents a key that is computed per draw command.
*
* @return {String} The cache key.
* @return {Number} The cache key.
*/
getDynamicCacheKey(): number;
/**
* Returns the render object's cache key.
*
* @return {String} The cache key.
* @return {Number} The cache key.
*/
getCacheKey(): number;
/**
Expand Down
8 changes: 4 additions & 4 deletions types/three/src/renderers/common/Renderer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ declare class Renderer {
* @param {Object3D} scene - The scene or 3D object to precompile.
* @param {Camera} camera - The camera that is used to render the scene.
* @param {Scene} targetScene - If the first argument is a 3D object, this parameter must represent the scene the 3D object is going to be added.
* @return {Promise} A Promise that resolves when the compile has been finished.
* @return {Promise<Array>} A Promise that resolves when the compile has been finished.
*/
compileAsync(scene: Object3D, camera: Camera, targetScene?: Object3D | null): Promise<void>;
/**
Expand Down Expand Up @@ -677,7 +677,7 @@ declare class Renderer {
*
* @async
* @param {Node|Array<Node>} computeNodes - The compute node(s).
* @return {Promise?} A Promise that resolve when the compute has finished.
* @return {Promise} A Promise that resolve when the compute has finished.
*/
computeAsync(computeNodes: ComputeNode | ComputeNode[]): Promise<void>;
/**
Expand Down Expand Up @@ -860,7 +860,7 @@ declare class Renderer {
* @param {Scene} scene - The scene the 3D object belongs to.
* @param {Camera} camera - The camera the object should be rendered with.
* @param {LightsNode} lightsNode - The current lights node.
* @param {Object?} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`.
* @param {{start: Number, count: Number}?} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`.
* @param {ClippingContext} clippingContext - The clipping context.
* @param {String?} [passId=null] - An optional ID for identifying the pass.
*/
Expand All @@ -884,7 +884,7 @@ declare class Renderer {
* @param {Scene} scene - The scene the 3D object belongs to.
* @param {Camera} camera - The camera the object should be rendered with.
* @param {LightsNode} lightsNode - The current lights node.
* @param {Object?} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`.
* @param {{start: Number, count: Number}?} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`.
* @param {ClippingContext} clippingContext - The clipping context.
* @param {String?} [passId=null] - An optional ID for identifying the pass.
*/
Expand Down
3 changes: 2 additions & 1 deletion types/three/src/renderers/webgpu/WebGPUBackend.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="@webgpu/types" />

import { CoordinateSystem } from "../../constants.js";
import { CoordinateSystem, HalfFloatType, UnsignedByteType } from "../../constants.js";
import Backend, { BackendParameters } from "../common/Backend.js";

export interface WebGPUBackendParameters extends BackendParameters {
Expand All @@ -10,6 +10,7 @@ export interface WebGPUBackendParameters extends BackendParameters {
device?: GPUDevice | undefined;
powerPreference?: GPUPowerPreference | undefined;
context?: GPUCanvasContext | undefined;
outputType?: typeof UnsignedByteType | typeof HalfFloatType | undefined;
}

export default class WebGPUBackend extends Backend {
Expand Down

0 comments on commit 18cf1ce

Please sign in to comment.