From 8cbcafd2d733ec422f91b94ea9b0c806e85c1e8e Mon Sep 17 00:00:00 2001 From: Catalin Moldovan Date: Mon, 17 Jun 2024 18:05:20 +0300 Subject: [PATCH] Rename slices to layers to better match WebGPU naming but also gl.framebufferTextureLayer --- .../graphics/texture-array.example.mjs | 4 +- src/framework/handlers/texture.js | 6 +-- src/framework/xr/xr-view.js | 2 +- src/platform/graphics/texture-utils.js | 12 ++--- src/platform/graphics/texture.js | 44 +++++++++---------- src/platform/graphics/webgl/webgl-texture.js | 16 +++---- .../graphics/webgpu/webgpu-mipmap-renderer.js | 2 +- .../graphics/webgpu/webgpu-texture.js | 6 +-- 8 files changed, 46 insertions(+), 46 deletions(-) diff --git a/examples/src/examples/graphics/texture-array.example.mjs b/examples/src/examples/graphics/texture-array.example.mjs index 9dbe33bd561..677bf0d6a73 100644 --- a/examples/src/examples/graphics/texture-array.example.mjs +++ b/examples/src/examples/graphics/texture-array.example.mjs @@ -135,7 +135,7 @@ assetListLoader.load(() => { dimension: pc.TEXTUREDIMENSION_2D_ARRAY, width: 1024, height: 1024, - slices: 4, // array texture with 4 textures + layers: 4, // array texture with 4 textures magFilter: pc.FILTER_NEAREST, minFilter: pc.FILTER_NEAREST_MIPMAP_NEAREST, mipmaps: true, @@ -158,7 +158,7 @@ assetListLoader.load(() => { const mipmaps = generateMipmaps(textureArrayOptions.width, textureArrayOptions.height); const levels = mipmaps.map((data) => { const textures = []; - for (let i = 0; i < textureArrayOptions.slices; i++) { + for (let i = 0; i < textureArrayOptions.layers; i++) { textures.push(data); } return textures; diff --git a/src/framework/handlers/texture.js b/src/framework/handlers/texture.js index 40f50869844..a6a686f3410 100644 --- a/src/framework/handlers/texture.js +++ b/src/framework/handlers/texture.js @@ -100,8 +100,8 @@ const _completePartialMipmapChain = function (texture) { const height = Math.max(1, texture._height >> (level - 1)); if (texture.cubemap || texture.array) { const mips = []; - for (let slice = 0; slice < texture.slices; ++slice) { - mips.push(downsample(width, height, texture._levels[level - 1][slice])); + for (let layer = 0; layer < texture.layers; ++layer) { + mips.push(downsample(width, height, texture._levels[level - 1][layer])); } texture._levels.push(mips); } else { @@ -109,7 +109,7 @@ const _completePartialMipmapChain = function (texture) { } } - texture._levelsUpdated = (texture.cubemap || texture.array) ? [Array(texture.slices).fill(true)] : [true]; + texture._levelsUpdated = (texture.cubemap || texture.array) ? [Array(texture.layers).fill(true)] : [true]; }; /** diff --git a/src/framework/xr/xr-view.js b/src/framework/xr/xr-view.js index f258290b49e..ec91895e5fc 100644 --- a/src/framework/xr/xr-view.js +++ b/src/framework/xr/xr-view.js @@ -171,7 +171,7 @@ class XrView extends EventHandler { this._textureDepth = new Texture(device, { format: this._manager.views.depthPixelFormat, array: viewsCount > 1, - slices: viewsCount, + layers: viewsCount, mipmaps: false, addressU: ADDRESS_CLAMP_TO_EDGE, addressV: ADDRESS_CLAMP_TO_EDGE, diff --git a/src/platform/graphics/texture-utils.js b/src/platform/graphics/texture-utils.js index 367cad798c6..2fa11d76eaf 100644 --- a/src/platform/graphics/texture-utils.js +++ b/src/platform/graphics/texture-utils.js @@ -26,7 +26,7 @@ class TextureUtils { * * @param {number} width - Texture's width. * @param {number} height - Texture's height. - * @param {number} [depth] - Texture's depth slices. Defaults to 1. + * @param {number} [depth] - Texture's depth layers. Defaults to 1. * @returns {number} The number of mip levels required for the texture. */ static calcMipLevelsCount(width, height, depth = 1) { @@ -38,7 +38,7 @@ class TextureUtils { * * @param {number} width - Texture's width. * @param {number} height - Texture's height. - * @param {number} depth - Texture's depth slices. + * @param {number} depth - Texture's depth layers. * @param {number} format - Texture's pixel format PIXELFORMAT_***. * @returns {number} The number of bytes of GPU memory required for the texture. * @ignore @@ -71,16 +71,16 @@ class TextureUtils { * * @param {number} width - Texture's width. * @param {number} height - Texture's height. - * @param {number} slices - Texture's slices. + * @param {number} layers - Texture's layers. * @param {number} format - Texture's pixel format PIXELFORMAT_***. * @param {boolean} isVolume - True if the texture is a volume texture, false otherwise. * @param {boolean} mipmaps - True if the texture includes mipmaps, false otherwise. * @returns {number} The number of bytes of GPU memory required for the texture. * @ignore */ - static calcGpuSize(width, height, slices, format, isVolume, mipmaps) { + static calcGpuSize(width, height, layers, format, isVolume, mipmaps) { let result = 0; - let depth = isVolume ? slices : 1; + let depth = isVolume ? layers : 1; while (1) { result += TextureUtils.calcLevelGpuSize(width, height, depth, format); @@ -94,7 +94,7 @@ class TextureUtils { depth = Math.max(depth >> 1, 1); } - return result * (isVolume ? 1 : slices); + return result * (isVolume ? 1 : layers); } } diff --git a/src/platform/graphics/texture.js b/src/platform/graphics/texture.js index fa9eedea506..e6321536967 100644 --- a/src/platform/graphics/texture.js +++ b/src/platform/graphics/texture.js @@ -102,7 +102,7 @@ class Texture { * @param {string} [options.name] - The name of the texture. Defaults to null. * @param {number} [options.width] - The width of the texture in pixels. Defaults to 4. * @param {number} [options.height] - The height of the texture in pixels. Defaults to 4. - * @param {number} [options.slices] - The number of depth slices in a 3D texture, the number of textures + * @param {number} [options.layers] - The number of depth layers in a 3D texture, the number of textures * in a texture array or the number of faces for a cubemap. * @param {string} [options.dimension] - The texture dimension type. Can be: * - {@link TEXTUREDIMENSION_2D} @@ -229,7 +229,7 @@ class Texture { Debug.assert(this.device, "Texture constructor requires a graphicsDevice to be valid"); Debug.assert(!options.width || Number.isInteger(options.width), "Texture width must be an integer number, got", options); Debug.assert(!options.height || Number.isInteger(options.height), "Texture height must be an integer number, got", options); - Debug.assert(!options.slices || Number.isInteger(options.slices), "Texture slices must be an integer number, got", options); + Debug.assert(!options.layers || Number.isInteger(options.layers), "Texture layers must be an integer number, got", options); this.name = options.name ?? ''; @@ -241,9 +241,9 @@ class Texture { this._width = Math.floor(options.width ?? 4); this._height = Math.floor(options.height ?? 4); - this._slices = Math.floor(options.slices ?? (this._dimension === TEXTUREDIMENSION_CUBE ? 6 : 1)); + this._layers = Math.floor(options.layers ?? (this._dimension === TEXTUREDIMENSION_CUBE ? 6 : 1)); - Debug.assert((this._dimension === TEXTUREDIMENSION_CUBE ? this._slices === 6 : true), "Texture cube map must have 6 slices"); + Debug.assert((this._dimension === TEXTUREDIMENSION_CUBE ? this._layers === 6 : true), "Texture cube map must have 6 layers"); this._format = options.format ?? PIXELFORMAT_RGBA8; this._compressed = isCompressedPixelFormat(this._format); @@ -292,7 +292,7 @@ class Texture { if (this._levels) { this.upload(options.immediate ?? false); } else { - this._levels = (this.cubemap || this.array) ? [Array(this._slices).fill(null)] : [null]; + this._levels = (this.cubemap || this.array) ? [Array(this._layers).fill(null)] : [null]; } // track the texture @@ -340,10 +340,10 @@ class Texture { * * @param {number} width - The new width of the texture. * @param {number} height - The new height of the texture. - * @param {number} [slices] - The new number of slices for the texture. Defaults to 1. + * @param {number} [layers] - The new number of layers for the texture. Defaults to 1. * @ignore */ - resize(width, height, slices = 1) { + resize(width, height, layers = 1) { // destroy texture impl const device = this.device; @@ -352,7 +352,7 @@ class Texture { this._width = Math.floor(width); this._height = Math.floor(height); - this._slices = Math.floor(slices); + this._layers = Math.floor(layers); // re-create the implementation this.impl = device.createTextureImpl(this); @@ -689,12 +689,12 @@ class Texture { } /** - * The number of depth slices in a 3D texture. + * The number of depth layers in a 3D texture. * * @type {number} */ get depth() { - return this._dimension === TEXTUREDIMENSION_3D ? this._slices : 1; + return this._dimension === TEXTUREDIMENSION_3D ? this._layers : 1; } /** @@ -702,8 +702,8 @@ class Texture { * * @type {number} */ - get slices() { - return this._slices; + get layers() { + return this._layers; } /** @@ -750,7 +750,7 @@ class Texture { get gpuSize() { const mips = this.pot && this._mipmaps && !(this._compressed && this._levels.length === 1); - return TextureUtils.calcGpuSize(this._width, this._height, this._slices, this._format, this.volume, mips); + return TextureUtils.calcGpuSize(this._width, this._height, this._layers, this._format, this.volume, mips); } /** @@ -830,7 +830,7 @@ class Texture { // Force a full resubmission of the texture to the GPU (used on a context restore event) dirtyAll() { - this._levelsUpdated = (this.cubemap || this.array) ? [Array(this._slices).fill(true)] : [true]; + this._levelsUpdated = (this.cubemap || this.array) ? [Array(this._layers).fill(true)] : [true]; this._needsUpload = true; this._needsMipmapsUpload = this._mipmaps; @@ -847,8 +847,8 @@ class Texture { * to 0. * @param {number} [options.face] - If the texture is a cubemap, this is the index of the face * to lock. - * @param {number} [options.slice] - If the texture is a texture array, this is the index of the - * slice to lock. + * @param {number} [options.layer] - If the texture is a texture array, this is the index of the + * layer to lock. * @param {number} [options.mode] - The lock mode. Can be: * - {@link TEXTURELOCK_READ} * - {@link TEXTURELOCK_WRITE} @@ -860,7 +860,7 @@ class Texture { // Initialize options to some sensible defaults options.level ??= 0; options.face ??= 0; - options.slice ??= 0; + options.layer ??= 0; options.mode ??= TEXTURELOCK_WRITE; Debug.assert( @@ -889,7 +889,7 @@ class Texture { this._lockedMode = options.mode; - const levels = this.cubemap ? this._levels[options.face] : this.array ? this._levels[options.slice] : this._levels; + const levels = this.cubemap ? this._levels[options.face] : this.array ? this._levels[options.layer] : this._levels; if (levels[options.level] === null) { // allocate storage for this mip level const width = Math.max(1, this._width >> options.level); @@ -901,7 +901,7 @@ class Texture { if (this._lockedMode === TEXTURELOCK_WRITE) { if (this.cubemap || this.array) { - this._levelsUpdated[0][options.face ?? options.slice] = true; + this._levelsUpdated[0][options.face ?? options.layer] = true; } else { this._levelsUpdated[0] = true; } @@ -930,7 +930,7 @@ class Texture { width = source[0].width || 0; height = source[0].height || 0; - for (let i = 0; i < this._slices; i++) { + for (let i = 0; i < this._layers; i++) { const face = source[i]; // cubemap becomes invalid if any condition is not satisfied if (!face || // face is missing @@ -948,7 +948,7 @@ class Texture { if (!invalid) { // mark levels as updated - for (let i = 0; i < this._slices; i++) { + for (let i = 0; i < this._layers; i++) { if (this._levels[0][i] !== source[i]) this._levelsUpdated[0][i] = true; } @@ -977,7 +977,7 @@ class Texture { // remove levels if (this.cubemap || this.array) { - for (let i = 0; i < this._slices; i++) { + for (let i = 0; i < this._layers; i++) { this._levels[0][i] = null; this._levelsUpdated[0][i] = true; } diff --git a/src/platform/graphics/webgl/webgl-texture.js b/src/platform/graphics/webgl/webgl-texture.js index f66d400976a..d3ef7b0665e 100644 --- a/src/platform/graphics/webgl/webgl-texture.js +++ b/src/platform/graphics/webgl/webgl-texture.js @@ -414,7 +414,7 @@ class WebglTexture { this._glInternalFormat, texture._width, texture._height, - texture._slices); + texture._layers); } // Upload all existing mip levels. Initialize 0 mip anyway. @@ -444,7 +444,7 @@ class WebglTexture { if (device._isBrowserInterface(mipObject[0])) { // Upload the image, canvas or video - for (face = 0; face < texture.slices; face++) { + for (face = 0; face < texture.layers; face++) { let src = mipObject[face]; if (!texture._levelsUpdated[0][face] || !src) continue; @@ -486,7 +486,7 @@ class WebglTexture { } else { // Upload the byte array resMult = 1 / Math.pow(2, mipLevel); - for (face = 0; face < texture.slices; face++) { + for (face = 0; face < texture.layers; face++) { const texData = mipObject[face]; if (!texture._levelsUpdated[0][face]) continue; @@ -552,7 +552,7 @@ class WebglTexture { this._glInternalFormat, Math.max(texture._width * resMult, 1), Math.max(texture._height * resMult, 1), - Math.max(texture._slices * resMult, 1), + Math.max(texture._layers * resMult, 1), 0, mipObject); } else { @@ -563,7 +563,7 @@ class WebglTexture { this._glInternalFormat, Math.max(texture._width * resMult, 1), Math.max(texture._height * resMult, 1), - Math.max(texture._slices * resMult, 1), + Math.max(texture._layers * resMult, 1), 0, this._glFormat, this._glPixelType, @@ -571,7 +571,7 @@ class WebglTexture { } } else if (texture.array && typeof mipObject === "object") { if (texture._compressed) { - for (let index = 0; index < texture._slices; index++) { + for (let index = 0; index < texture._layers; index++) { if (!texture._levelsUpdated[0][index] || !mipObject[index]) continue; gl.compressedTexSubImage3D( @@ -588,7 +588,7 @@ class WebglTexture { ); } } else { - for (let index = 0; index < texture.slices; index++) { + for (let index = 0; index < texture.layers; index++) { if (!texture._levelsUpdated[0][index] || !mipObject[index]) continue; gl.texSubImage3D( @@ -719,7 +719,7 @@ class WebglTexture { if (texture._needsUpload) { if (texture.cubemap || texture.array) { - for (let i = 0; i < texture.slices; i++) + for (let i = 0; i < texture.layers; i++) texture._levelsUpdated[0][i] = false; } else { texture._levelsUpdated[0] = false; diff --git a/src/platform/graphics/webgpu/webgpu-mipmap-renderer.js b/src/platform/graphics/webgpu/webgpu-mipmap-renderer.js index 3f132277d2e..8beb3f8a54c 100644 --- a/src/platform/graphics/webgpu/webgpu-mipmap-renderer.js +++ b/src/platform/graphics/webgpu/webgpu-mipmap-renderer.js @@ -106,7 +106,7 @@ class WebgpuMipmapRenderer { DebugHelper.setLabel(pipeline, 'RenderPipeline-MipmapRenderer'); const texture = webgpuTexture.texture; - const numFaces = texture.slices; + const numFaces = texture.layers; const srcViews = []; for (let face = 0; face < numFaces; face++) { diff --git a/src/platform/graphics/webgpu/webgpu-texture.js b/src/platform/graphics/webgpu/webgpu-texture.js index 0f527456f7f..ea38a6fde93 100644 --- a/src/platform/graphics/webgpu/webgpu-texture.js +++ b/src/platform/graphics/webgpu/webgpu-texture.js @@ -98,7 +98,7 @@ class WebgpuTexture { size: { width: texture.width, height: texture.height, - depthOrArrayLayers: texture.slices + depthOrArrayLayers: texture.layers }, format: this.format, mipLevelCount: mipLevelCount, @@ -336,9 +336,9 @@ class WebgpuTexture { } else if (texture.array) { // texture array - if (texture.slices === mipObject.length) { + if (texture.layers === mipObject.length) { - for (let index = 0; index < texture.slices; index++) { + for (let index = 0; index < texture.layers; index++) { const arraySource = mipObject[index]; if (this.isExternalImage(arraySource)) {