Skip to content

Commit

Permalink
WIP - 3d RT mipmaps in WebGPU (BabylonJS#14941)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiiBond authored Apr 2, 2024
1 parent d9f7676 commit cb2f20f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ WebGPUEngine.prototype.unBindMultiColorAttachmentFramebuffer = function (

for (let i = 0; i < count; i++) {
const texture = rtWrapper.textures![i];
if (texture.generateMipMaps && !disableGenerateMipMaps && !texture.isCube) {
if (texture.generateMipMaps && !disableGenerateMipMaps && !texture.isCube && !texture.is3D) {
this._generateMipmaps(texture);
}
}
Expand Down
9 changes: 5 additions & 4 deletions packages/dev/core/src/Engines/WebGPU/webgpuTextureManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ export class WebGPUTextureManager {
this.updateTexture(imageBitmap, gpuTexture, imageBitmap.width, imageBitmap.height, layerCount, format, 0, 0, invertY, premultiplyAlpha, 0, 0);

if (hasMipmaps && generateMipmaps) {
this.generateMipmaps(gpuTexture, format, mipLevelCount, 0, commandEncoder);
this.generateMipmaps(gpuTexture, format, mipLevelCount, 0, is3D, commandEncoder);
}
}

Expand Down Expand Up @@ -868,7 +868,7 @@ export class WebGPUTextureManager {
commandEncoder!.pushDebugGroup?.(`create cube mipmaps - ${mipLevelCount} levels`);

for (let f = 0; f < 6; ++f) {
this.generateMipmaps(gpuTexture, format, mipLevelCount, f, commandEncoder);
this.generateMipmaps(gpuTexture, format, mipLevelCount, f, false, commandEncoder);
}

commandEncoder!.popDebugGroup?.();
Expand All @@ -884,6 +884,7 @@ export class WebGPUTextureManager {
format: GPUTextureFormat,
mipLevelCount: number,
faceIndex = 0,
is3D = false,
commandEncoder?: GPUCommandEncoder
): void {
const useOwnCommandEncoder = commandEncoder === undefined;
Expand Down Expand Up @@ -918,7 +919,7 @@ export class WebGPUTextureManager {
{
view: gpuTexture.createView({
format,
dimension: WebGPUConstants.TextureViewDimension.E2d,
dimension: is3D ? WebGPUConstants.TextureViewDimension.E3d : WebGPUConstants.TextureViewDimension.E2d,
baseMipLevel: i,
mipLevelCount: 1,
arrayLayerCount: 1,
Expand Down Expand Up @@ -948,7 +949,7 @@ export class WebGPUTextureManager {
binding: 1,
resource: gpuTexture.createView({
format,
dimension: WebGPUConstants.TextureViewDimension.E2d,
dimension: is3D ? WebGPUConstants.TextureViewDimension.E3d : WebGPUConstants.TextureViewDimension.E2d,
baseMipLevel: i - 1,
mipLevelCount: 1,
arrayLayerCount: 1,
Expand Down
2 changes: 1 addition & 1 deletion packages/dev/core/src/Engines/webgpuEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2626,7 +2626,7 @@ export class WebGPUEngine extends Engine {
if (texture.isCube) {
this._textureHelper.generateCubeMipmaps(gpuHardwareTexture, format, mipmapCount, commandEncoder);
} else {
this._textureHelper.generateMipmaps(gpuHardwareTexture, format, mipmapCount, 0, commandEncoder);
this._textureHelper.generateMipmaps(gpuHardwareTexture, format, mipmapCount, 0, texture.is3D, commandEncoder);
}
}

Expand Down

0 comments on commit cb2f20f

Please sign in to comment.