Skip to content

Commit

Permalink
Rename slices to layers to better match WebGPU naming but also gl.fra…
Browse files Browse the repository at this point in the history
…mebufferTextureLayer
  • Loading branch information
heretique committed Jun 26, 2024
1 parent a356b4e commit b986ced
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 46 deletions.
4 changes: 2 additions & 2 deletions examples/src/examples/graphics/texture-array.example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/framework/handlers/texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ 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 {
texture._levels.push(downsample(width, height, texture._levels[level - 1]));
}
}

texture._levelsUpdated = (texture.cubemap || texture.array) ? [Array(texture.slices).fill(true)] : [true];
texture._levelsUpdated = (texture.cubemap || texture.array) ? [Array(texture.layers).fill(true)] : [true];
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/framework/xr/xr-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions src/platform/graphics/texture-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -94,7 +94,7 @@ class TextureUtils {
depth = Math.max(depth >> 1, 1);
}

return result * (isVolume ? 1 : slices);
return result * (isVolume ? 1 : layers);
}
}

Expand Down
44 changes: 22 additions & 22 deletions src/platform/graphics/texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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 ?? '';

Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -689,21 +689,21 @@ 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;
}

/**
* The number of textures in a texture array or the number of faces for a cubemap.
*
* @type {number}
*/
get slices() {
return this._slices;
get layers() {
return this._layers;
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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;
Expand All @@ -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}
Expand All @@ -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(
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
16 changes: 8 additions & 8 deletions src/platform/graphics/webgl/webgl-texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -563,15 +563,15 @@ 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,
mipObject);
}
} 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(
Expand All @@ -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(
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/graphics/webgpu/webgpu-mipmap-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
6 changes: 3 additions & 3 deletions src/platform/graphics/webgpu/webgpu-texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class WebgpuTexture {
size: {
width: texture.width,
height: texture.height,
depthOrArrayLayers: texture.slices
depthOrArrayLayers: texture.layers
},
format: this.format,
mipLevelCount: mipLevelCount,
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit b986ced

Please sign in to comment.