playcanvas
Version:
PlayCanvas WebGL game engine
69 lines (66 loc) • 2.84 kB
JavaScript
import { Debug } from '../../../core/debug.js';
import { DebugGraphics } from '../debug-graphics.js';
/**
* @import { WebgpuGraphicsDevice } from './webgpu-graphics-device.js'
*/ // Maximum number of times a duplicate error message is logged.
var MAX_DUPLICATES = 5;
/**
* Internal WebGPU debug system. Note that the functions only execute in the debug build, and are
* stripped out in other builds.
*/ class WebgpuDebug {
/**
* Start a validation error scope.
*
* @param {WebgpuGraphicsDevice} device - The graphics device.
*/ static validate(device) {
device.wgpu.pushErrorScope('validation');
WebgpuDebug._scopes.push('validation');
WebgpuDebug._markers.push(DebugGraphics.toString());
}
/**
* Start an out-of-memory error scope.
*
* @param {WebgpuGraphicsDevice} device - The graphics device.
*/ static memory(device) {
device.wgpu.pushErrorScope('out-of-memory');
WebgpuDebug._scopes.push('out-of-memory');
WebgpuDebug._markers.push(DebugGraphics.toString());
}
/**
* Start an internal error scope.
*
* @param {WebgpuGraphicsDevice} device - The graphics device.
*/ static internal(device) {
device.wgpu.pushErrorScope('internal');
WebgpuDebug._scopes.push('internal');
WebgpuDebug._markers.push(DebugGraphics.toString());
}
/**
* End the previous error scope, and print errors if any.
*
* @param {WebgpuGraphicsDevice} device - The graphics device.
* @param {...any} args - Additional parameters that form the error message.
*/ static end(device) {
for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
args[_key - 1] = arguments[_key];
}
var header = WebgpuDebug._scopes.pop();
var marker = WebgpuDebug._markers.pop();
Debug.assert(header, 'Non matching end.');
device.wgpu.popErrorScope().then((error)=>{
if (error) {
var _WebgpuDebug__loggedMessages_get;
var count = (_WebgpuDebug__loggedMessages_get = WebgpuDebug._loggedMessages.get(error.message)) != null ? _WebgpuDebug__loggedMessages_get : 0;
if (count < MAX_DUPLICATES) {
var tooMany = count === MAX_DUPLICATES - 1 ? ' (Too many errors, ignoring this one from now)' : '';
WebgpuDebug._loggedMessages.set(error.message, count + 1);
console.error("WebGPU " + header + " error: " + error.message, tooMany, 'while rendering', marker, ...args);
}
}
});
}
}
WebgpuDebug._scopes = [];
WebgpuDebug._markers = [];
/** @type {Map<string,number>} */ WebgpuDebug._loggedMessages = new Map();
export { WebgpuDebug };