浏览代码

Add a name to uniform buffers for easier debugging

Popov72 4 年之前
父节点
当前提交
8eb4db2537

+ 3 - 0
src/Engines/IPipelineContext.ts

@@ -16,6 +16,9 @@ export interface IPipelineContext {
     isReady: boolean;
 
     /** @hidden */
+    _name?:  string;
+
+    /** @hidden */
     _getVertexShaderCode(): string | null;
 
     /** @hidden */

+ 5 - 5
src/Engines/WebGPU/webgpuPipelineContext.ts

@@ -95,7 +95,11 @@ export class WebGPUPipelineContext implements IPipelineContext {
         return false;
     }
 
+    /** @hidden */
+    public _name: string;
+
     constructor(shaderProcessingContext: WebGPUShaderProcessingContext, engine: WebGPUEngine) {
+        this._name = "unnamed";
         if (shaderProcessingContext) {
             this.availableAttributes = shaderProcessingContext.availableAttributes;
             this.availableUBOs = shaderProcessingContext.availableUBOs;
@@ -159,11 +163,7 @@ export class WebGPUPipelineContext implements IPipelineContext {
             return;
         }
 
-        if (this.uniformBuffer) {
-            // If the uniform buffer is already existing it means one wants to do multiple rendering with the same pipeline context
-            // we need to have a new uniform buffer for the new rendering, else all the rendering will end up using the same uniform buffer.
-            // Calling _rebuild() is enough to recreate the underlying hardware buffer without removing any other data.
-            // That means the user does not need to re-set all the uniforms of the buffer, the new buffer is in the same state than the previous one.
+        this.uniformBuffer = new UniformBuffer(this.engine, undefined, undefined, "leftOver-" + this._name);
 
         for (let leftOverUniform of this.leftOverUniforms) {
             const size = _uniformSizes[leftOverUniform.type];

+ 1 - 1
src/Lights/light.ts

@@ -345,7 +345,7 @@ export abstract class Light extends Node {
     constructor(name: string, scene: Scene) {
         super(name, scene);
         this.getScene().addLight(this);
-        this._uniformBuffer = new UniformBuffer(this.getScene().getEngine());
+        this._uniformBuffer = new UniformBuffer(this.getScene().getEngine(), undefined,  undefined, name);
         this._buildUniformLayout();
 
         this.includedOnlyMeshes = new Array<AbstractMesh>();

+ 1 - 0
src/Materials/effect.ts

@@ -665,6 +665,7 @@ export class Effect implements IDisposable {
             let engine = this._engine;
 
             this._pipelineContext = engine.createPipelineContext(this._processingContext);
+            this._pipelineContext._name = this._key;
 
             let rebuildRebind = this._rebuildProgram.bind(this);
             if (this._vertexSourceCodeOverride && this._fragmentSourceCodeOverride) {

+ 1 - 1
src/Materials/material.ts

@@ -671,7 +671,7 @@ export class Material implements IAnimatable {
             this.sideOrientation = Material.CounterClockWiseSideOrientation;
         }
 
-        this._uniformBuffer = new UniformBuffer(this._scene.getEngine());
+        this._uniformBuffer = new UniformBuffer(this._scene.getEngine(), undefined, undefined, name);
         this._useUBO = this.getScene().getEngine().supportsUniformBuffers;
 
         if (!doNotAdd) {

+ 3 - 1
src/Materials/uniformBuffer.ts

@@ -41,6 +41,7 @@ export class UniformBuffer {
     private _needSync: boolean;
     private _noUBO: boolean;
     private _currentEffect: Effect;
+    private _name: string;
     private _currentFrameId: number;
 
     /** @hidden */
@@ -161,10 +162,11 @@ export class UniformBuffer {
      * @param data Define the data contained in the buffer
      * @param dynamic Define if the buffer is updatable
      */
-    constructor(engine: Engine, data?: number[], dynamic?: boolean) {
+    constructor(engine: Engine, data?: number[], dynamic?: boolean, name?: string) {
         this._engine = engine;
         this._noUBO = !engine.supportsUniformBuffers;
         this._dynamic = dynamic;
+        this._name = name ?? "no-name";
 
         this._data = data || [];
 

+ 1 - 1
src/Meshes/abstractMesh.ts

@@ -717,7 +717,7 @@ export class AbstractMesh extends TransformNode implements IDisposable, ICullabl
         this._resyncLightSources();
 
         // Mesh Uniform Buffer.
-        this._uniformBuffer = new UniformBuffer(this.getScene().getEngine());
+        this._uniformBuffer = new UniformBuffer(this.getScene().getEngine(), undefined, undefined, name);
         this._buildUniformLayout();
     }