Sfoglia il codice sorgente

Fix sample count invalid values

Popov72 4 anni fa
parent
commit
9febb85528
2 ha cambiato i file con 20 aggiunte e 0 eliminazioni
  1. 10 0
      src/Engines/WebGPU/webgpuTextureHelper.ts
  2. 10 0
      src/Engines/webgpuEngine.ts

+ 10 - 0
src/Engines/WebGPU/webgpuTextureHelper.ts

@@ -733,6 +733,11 @@ export class WebGPUTextureHelper {
     public createTexture(imageBitmap: ImageBitmap | { width: number, height: number, layers: number }, hasMipmaps = false, generateMipmaps = false, invertY = false, premultiplyAlpha = false, is3D = false, format: GPUTextureFormat = WebGPUConstants.TextureFormat.RGBA8Unorm,
     public createTexture(imageBitmap: ImageBitmap | { width: number, height: number, layers: number }, hasMipmaps = false, generateMipmaps = false, invertY = false, premultiplyAlpha = false, is3D = false, format: GPUTextureFormat = WebGPUConstants.TextureFormat.RGBA8Unorm,
         sampleCount = 1, commandEncoder?: GPUCommandEncoder, usage = -1): GPUTexture
         sampleCount = 1, commandEncoder?: GPUCommandEncoder, usage = -1): GPUTexture
     {
     {
+        if (sampleCount > 1) {
+            // TODO WEBGPU for the time being, Chrome only accepts values of 1 or 4
+            sampleCount = 4;
+        }
+
         const layerCount = (imageBitmap as any).layers || 1;
         const layerCount = (imageBitmap as any).layers || 1;
         let textureSize = {
         let textureSize = {
             width: imageBitmap.width,
             width: imageBitmap.width,
@@ -767,6 +772,11 @@ export class WebGPUTextureHelper {
     public createCubeTexture(imageBitmaps: ImageBitmap[] | { width: number, height: number }, hasMipmaps = false, generateMipmaps = false, invertY = false, premultiplyAlpha = false, format: GPUTextureFormat = WebGPUConstants.TextureFormat.RGBA8Unorm,
     public createCubeTexture(imageBitmaps: ImageBitmap[] | { width: number, height: number }, hasMipmaps = false, generateMipmaps = false, invertY = false, premultiplyAlpha = false, format: GPUTextureFormat = WebGPUConstants.TextureFormat.RGBA8Unorm,
         sampleCount = 1, commandEncoder?: GPUCommandEncoder, usage = -1): GPUTexture
         sampleCount = 1, commandEncoder?: GPUCommandEncoder, usage = -1): GPUTexture
     {
     {
+        if (sampleCount > 1) {
+            // TODO WEBGPU for the time being, Chrome only accepts values of 1 or 4
+            sampleCount = 4;
+        }
+
         const width = WebGPUTextureHelper.IsImageBitmapArray(imageBitmaps) ? imageBitmaps[0].width : imageBitmaps.width;
         const width = WebGPUTextureHelper.IsImageBitmapArray(imageBitmaps) ? imageBitmaps[0].width : imageBitmaps.width;
         const height = WebGPUTextureHelper.IsImageBitmapArray(imageBitmaps) ? imageBitmaps[0].height : imageBitmaps.height;
         const height = WebGPUTextureHelper.IsImageBitmapArray(imageBitmaps) ? imageBitmaps[0].height : imageBitmaps.height;
 
 

+ 10 - 0
src/Engines/webgpuEngine.ts

@@ -2632,6 +2632,11 @@ export class WebGPUEngine extends Engine {
 
 
         samples = Math.min(samples, this.getCaps().maxMSAASamples);
         samples = Math.min(samples, this.getCaps().maxMSAASamples);
 
 
+        if (samples > 1) {
+            // TODO WEBGPU for the time being, Chrome only accepts values of 1 or 4
+            samples = 4;
+        }
+
         this._textureHelper.createMSAATexture(texture, samples);
         this._textureHelper.createMSAATexture(texture, samples);
 
 
         if (texture._depthStencilTexture) {
         if (texture._depthStencilTexture) {
@@ -2657,6 +2662,11 @@ export class WebGPUEngine extends Engine {
 
 
         samples = Math.min(samples, this.getCaps().maxMSAASamples);
         samples = Math.min(samples, this.getCaps().maxMSAASamples);
 
 
+        if (samples > 1) {
+            // TODO WEBGPU for the time being, Chrome only accepts values of 1 or 4
+            samples = 4;
+        }
+
         // Note that the last texture of textures is the depth texture (if the depth texture has been generated by the MRT class) and so the MSAA texture
         // Note that the last texture of textures is the depth texture (if the depth texture has been generated by the MRT class) and so the MSAA texture
         // will be recreated for this texture too. As a consequence, there's no need to explicitly recreate the MSAA texture for textures[0]._depthStencilTexture
         // will be recreated for this texture too. As a consequence, there's no need to explicitly recreate the MSAA texture for textures[0]._depthStencilTexture
         for (let i = 0; i < textures.length; ++i) {
         for (let i = 0; i < textures.length; ++i) {