Explorar el Código

Avoid copying uniform buffers in WebGPU

Popov72 hace 4 años
padre
commit
c2755e218b

+ 3 - 0
src/Engines/engineFeatures.ts

@@ -13,4 +13,7 @@ export interface EngineFeatures {
 
     /** Indicates that the engine support shadow samplers */
     supportShadowSamplers: boolean;
+
+    /** Indicates to check the matrix bytes per bytes to know if it has changed or not. If false, only the updateFlag of the matrix is checked */
+    uniformBufferHardCheckMatrix: boolean;
 }

+ 1 - 0
src/Engines/thinEngine.ts

@@ -180,6 +180,7 @@ export class ThinEngine {
         framebuffersHaveYTopToBottom: false,
         supportDepthStencilTexture: false,
         supportShadowSamplers: false,
+        uniformBufferHardCheckMatrix: false,
     };
 
     /**

+ 1 - 0
src/Engines/webgpuEngine.ts

@@ -233,6 +233,7 @@ export class WebGPUEngine extends Engine {
         ThinEngine.Features.framebuffersHaveYTopToBottom = true;
         ThinEngine.Features.supportDepthStencilTexture = true;
         ThinEngine.Features.supportShadowSamplers = true;
+        ThinEngine.Features.uniformBufferHardCheckMatrix = true;
 
         options.deviceDescriptor = options.deviceDescriptor || { };
         options.swapChainFormat = options.swapChainFormat || WebGPUConstants.TextureFormat.BGRA8Unorm;

+ 2 - 1
src/Materials/uniformBuffer.ts

@@ -7,6 +7,7 @@ import { BaseTexture } from "../Materials/Textures/baseTexture";
 import { DataBuffer } from '../Meshes/dataBuffer';
 import { Color3 } from '../Maths/math.color';
 import { IMatrixLike } from '../Maths/math.like';
+import { ThinEngine } from '../Engines/thinEngine';
 
 import "../Engines/Extensions/engine.uniformBuffer";
 
@@ -507,7 +508,7 @@ export class UniformBuffer {
             var changed = false;
 
             for (var i = 0; i < size; i++) {
-                if (size === 16 || this._bufferData[location + i] !== data[i]) {
+                if ((size === 16 && !ThinEngine.Features.uniformBufferHardCheckMatrix) || this._bufferData[location + i] !== data[i]) {
                     changed = true;
                     this._bufferData[location + i] = data[i];
                 }