Skip to content

WebGPURenderer: Add Storage3DTexture and StorageArrayTexture #31175

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

Open
wants to merge 24 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a167227
Add support for texture_storage_2d_array
May 26, 2025
a62fcf8
additional extensions
May 29, 2025
da2caad
additional extensions
May 29, 2025
540c1d1
update
May 29, 2025
6f7c308
update
May 30, 2025
21f8d30
update
May 30, 2025
1d18ef1
update
May 30, 2025
f471b4d
update
May 30, 2025
44ab9fa
changed isTextureArray to isArrayTexture and the conditions
May 31, 2025
a295334
changed isTextureArray to isArrayTexture and the conditions
May 31, 2025
efe63ff
changed isTextureArray to isArrayTexture and the conditions
May 31, 2025
f32ec26
changed isTextureArray to isArrayTexture and the conditions
May 31, 2025
6478e35
with new classes for storageArrayTexture and storage3DTexture
Jun 23, 2025
bb35de5
with new classes for storageArrayTexture and storage3DTexture
Jun 23, 2025
8395fb2
with new classes for storageArrayTexture and storage3DTexture
Jun 23, 2025
5ad8c2e
with new classes for storageArrayTexture and storage3DTexture
Jun 23, 2025
912b3c3
with new classes for storageArrayTexture and storage3DTexture
Jun 23, 2025
c26fab3
with new classes for storageArrayTexture and storage3DTexture
Jun 23, 2025
dafe742
with new classes for storageArrayTexture and storage3DTexture
Jun 23, 2025
e5643c4
[200~
Jun 23, 2025
a1e9f0b
isSampledTexture3D replaced by is3DTexture, since it does not matter …
Jun 23, 2025
6db99f1
isSampledTexture3D replaced by is3DTexture, since it does not matter …
Jun 23, 2025
2d97903
isSampledTexture3D replaced by is3DTexture, since it does not matter …
Jun 23, 2025
177c903
isSampledTexture3D replaced by is3DTexture, since it does not matter …
Jun 23, 2025
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 src/Three.TSL.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ export const storage = TSL.storage;
export const storageBarrier = TSL.storageBarrier;
export const storageObject = TSL.storageObject;
export const storageTexture = TSL.storageTexture;
export const storage3DTexture = TSL.storage3DTexture;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These TSL functions were declared in some point?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, a valid point. For WebGPU, only the export from src/Three.WebGPU.js is necessary.
I can remove the export from src/Three.TSL.js or, what seems more appealing to me, add it for Three.TSL.js, because it should be available there too. But I have to look where.

export const storageArrayTexture = TSL.storageArrayTexture;
export const string = TSL.string;
export const struct = TSL.struct;
export const sub = TSL.sub;
Expand Down
2 changes: 2 additions & 0 deletions src/Three.WebGPU.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export { default as PostProcessing } from './renderers/common/PostProcessing.js'
import * as RendererUtils from './renderers/common/RendererUtils.js';
export { RendererUtils };
export { default as StorageTexture } from './renderers/common/StorageTexture.js';
export { default as Storage3DTexture } from './renderers/common/Storage3DTexture.js';
export { default as StorageArrayTexture } from './renderers/common/StorageArrayTexture.js';
export { default as StorageBufferAttribute } from './renderers/common/StorageBufferAttribute.js';
export { default as StorageInstancedBufferAttribute } from './renderers/common/StorageInstancedBufferAttribute.js';
export { default as IndirectStorageBufferAttribute } from './renderers/common/IndirectStorageBufferAttribute.js';
Expand Down
79 changes: 79 additions & 0 deletions src/renderers/common/Storage3DTexture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { Texture } from '../../textures/Texture.js';
import { LinearFilter, ClampToEdgeWrapping } from '../../constants.js';

/**
* This special type of texture is intended for compute shaders.
* It can be used to compute the data of a texture with a compute shader.
*
* Note: This type of texture can only be used with `WebGPURenderer`
* and a WebGPU backend.
*
* @augments Texture
*/
class Storage3DTexture extends Texture {

/**
* Constructs a new storage texture.
*
* @param {number} [width=1] - The storage texture's width.
* @param {number} [height=1] - The storage texture's height.
* @param {number} [depth=1] - The storage texture's depth.
*/
constructor( width = 1, height = 1, depth = 1 ) {

super();

//inherited from texture. Must be false for 3DTexture
this.isArrayTexture = false;

/**
* The image object which just represents the texture's dimension.
*
* @type {{width: number, height: number, depth: number}}
*/
this.image = { width, height, depth };

/**
* The default `magFilter` for storage textures is `THREE.LinearFilter`.
*
* @type {number}
*/
this.magFilter = LinearFilter;

/**
* The default `minFilter` for storage textures is `THREE.LinearFilter`.
*
* @type {number}
*/
this.minFilter = LinearFilter;

/**
* This defines how the texture is wrapped in the depth direction and corresponds to
* *W* in UVW mapping.
*
* @type {number}
*/
this.wrapR = ClampToEdgeWrapping;

/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isStorageTexture = true;

/**
* Indicates whether this texture is a 3D texture.
*
* @type {boolean}
*
*/
this.is3DTexture = true;

}

}

export default Storage3DTexture;
63 changes: 63 additions & 0 deletions src/renderers/common/StorageArrayTexture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Texture } from '../../textures/Texture.js';
import { LinearFilter } from '../../constants.js';

/**
* This special type of texture is intended for compute shaders.
* It can be used to compute the data of a texture with a compute shader.
*
* Note: This type of texture can only be used with `WebGPURenderer`
* and a WebGPU backend.
*
* @augments Texture
*/
class StorageArrayTexture extends Texture {

/**
* Constructs a new storage texture.
*
* @param {number} [width=1] - The storage texture's width.
* @param {number} [height=1] - The storage texture's height.
* @param {number} [depth=1] - The storage texture's depth.
*/
constructor( width = 1, height = 1, depth = 1 ) {

super();

//inherited from texture
this.isArrayTexture = true;

/**
* The image object which just represents the texture's dimension.
*
* @type {{width: number, height: number, depth: number}}
*/
this.image = { width, height, depth };

/**
* The default `magFilter` for storage textures is `THREE.LinearFilter`.
*
* @type {number}
*/
this.magFilter = LinearFilter;

/**
* The default `minFilter` for storage textures is `THREE.LinearFilter`.
*
* @type {number}
*/
this.minFilter = LinearFilter;

/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isStorageTexture = true;

}

}

export default StorageArrayTexture;
2 changes: 1 addition & 1 deletion src/renderers/common/nodes/NodeSampledTexture.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class NodeSampledTexture3D extends NodeSampledTexture {
* @readonly
* @default true
*/
this.isSampledTexture3D = true;
this.is3DTexture = true;

}

Expand Down
25 changes: 15 additions & 10 deletions src/renderers/webgpu/nodes/WGSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1701,24 +1701,29 @@ ${ flowData.code }

}

} else if ( texture.isArrayTexture === true || texture.isDataArrayTexture === true || texture.isCompressedArrayTexture === true ) {
} else if ( uniform.node.isStorageTextureNode === true ) {

textureType = 'texture_2d_array<f32>';
const format = getFormat( texture );
const access = this.getStorageAccess( uniform.node, shaderStage );

} else if ( texture.isVideoTexture === true ) {
const is3D = uniform.node.value.is3DTexture;
const isArrayTexture = uniform.node.value.isArrayTexture;

textureType = 'texture_external';
const dimension = is3D ? '3d' : `2d${ isArrayTexture ? '_array' : '' }`;

} else if ( texture.isData3DTexture === true ) {
textureType = `texture_storage_${ dimension }<${ format }, ${ access }>`;

textureType = 'texture_3d<f32>';
} else if ( texture.isArrayTexture === true || texture.isDataArrayTexture === true || texture.isCompressedArrayTexture === true ) {

} else if ( uniform.node.isStorageTextureNode === true ) {
textureType = 'texture_2d_array<f32>';

const format = getFormat( texture );
const access = this.getStorageAccess( uniform.node, shaderStage );
} else if ( texture.is3DTexture === true || texture.isData3DTexture === true ) {

textureType = `texture_storage_2d<${ format }, ${ access }>`;
textureType = 'texture_3d<f32>';

} else if ( texture.isVideoTexture === true ) {

textureType = 'texture_external';

} else {

Expand Down
14 changes: 12 additions & 2 deletions src/renderers/webgpu/utils/WebGPUBindingUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ class WebGPUBindingUtils {

}

if ( binding.texture.isArrayTexture ) {

storageTexture.viewDimension = GPUTextureViewDimension.TwoDArray;

} else if ( binding.texture.is3DTexture ) {

storageTexture.viewDimension = GPUTextureViewDimension.ThreeD;

}

bindingGPU.storageTexture = storageTexture;

} else if ( binding.isSampledTexture ) {
Expand Down Expand Up @@ -206,7 +216,7 @@ class WebGPUBindingUtils {

texture.viewDimension = GPUTextureViewDimension.TwoDArray;

} else if ( binding.isSampledTexture3D ) {
} else if ( binding.texture.is3DTexture ) {

texture.viewDimension = GPUTextureViewDimension.ThreeD;

Expand Down Expand Up @@ -428,7 +438,7 @@ class WebGPUBindingUtils {

dimensionViewGPU = GPUTextureViewDimension.Cube;

} else if ( binding.isSampledTexture3D ) {
} else if ( binding.texture.is3DTexture ) {

dimensionViewGPU = GPUTextureViewDimension.ThreeD;

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/webgpu/utils/WebGPUTextureUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ class WebGPUTextureUtils {

let dimension;

if ( texture.isData3DTexture ) {
if ( texture.is3DTexture || texture.isData3DTexture ) {

dimension = GPUTextureDimension.ThreeD;

Expand Down