Przeglądaj źródła

Fix view not being created correctly when using swap&die

Popov72 4 lat temu
rodzic
commit
9631ef2742

+ 3 - 0
src/Engines/WebGL/webGLHardwareTexture.ts

@@ -22,6 +22,9 @@ export class WebGLHardwareTexture implements HardwareTextureWrapper {
         this.set(existingTexture);
     }
 
+    public setUsage(textureSource: number, generateMipMaps: boolean, isCube: boolean, width: number, height: number): void {
+    }
+
     public set(hardwareTexture: WebGLTexture) {
         this._webGLTexture = hardwareTexture;
     }

+ 18 - 4
src/Engines/WebGPU/webgpuHardwareTexture.ts

@@ -1,6 +1,8 @@
 import { HardwareTextureWrapper } from '../../Materials/Textures/hardwareTextureWrapper';
+import { InternalTextureSource } from '../../Materials/Textures/internalTexture';
 import { Nullable } from '../../types';
 import * as WebGPUConstants from './webgpuConstants';
+import { WebGPUTextureHelper } from './webgpuTextureHelper';
 
 /** @hidden */
 export class WebGPUHardwareTexture implements HardwareTextureWrapper {
@@ -21,21 +23,33 @@ export class WebGPUHardwareTexture implements HardwareTextureWrapper {
         this.sampler = null;
     }
 
-    public set(hardwareTexture: GPUTexture) {
+    public set(hardwareTexture: GPUTexture): void {
         this._webgpuTexture = hardwareTexture;
     }
 
-    public createView(descriptor?: GPUTextureViewDescriptor) {
+    public setUsage(textureSource: number, generateMipMaps: boolean, isCube: boolean, width: number, height: number): void {
+        generateMipMaps = textureSource === InternalTextureSource.RenderTarget ? false : generateMipMaps;
+
+        this.createView({
+            dimension: isCube ? WebGPUConstants.TextureViewDimension.Cube : WebGPUConstants.TextureViewDimension.E2d,
+            mipLevelCount: generateMipMaps ? WebGPUTextureHelper.computeNumMipmapLevels(width, height) : 1,
+            baseArrayLayer: 0,
+            baseMipLevel: 0,
+            aspect: WebGPUConstants.TextureAspect.All
+        });
+    }
+
+    public createView(descriptor?: GPUTextureViewDescriptor): void {
         this.view = this._webgpuTexture!.createView(descriptor);
     }
 
-    public reset() {
+    public reset(): void {
         this._webgpuTexture = null;
         this.view = null;
         this.sampler = null;
     }
 
-    public release() {
+    public release(): void {
         this._webgpuTexture?.destroy();
         this.reset();
     }

+ 1 - 0
src/Materials/Textures/hardwareTextureWrapper.ts

@@ -4,6 +4,7 @@ export interface HardwareTextureWrapper {
     underlyingResource: any;
 
     set(hardwareTexture: any): void;
+    setUsage(textureSource: number, generateMipMaps: boolean, isCube: boolean, width: number, height: number): void;
     reset(): void;
     release(): void;
 }

+ 2 - 0
src/Materials/Textures/internalTexture.ts

@@ -456,6 +456,8 @@ export class InternalTexture {
     public _swapAndDie(target: InternalTexture): void {
         // TODO what about refcount on target?
 
+        this._hardwareTexture?.setUsage(target._source, this.generateMipMaps, this.isCube, this.width, this.height);
+
         target._hardwareTexture = this._hardwareTexture;
         target._isRGBD = this._isRGBD;