diff --git a/extensions/chrome/content_script.js b/extensions/chrome/content_script.js index 2e78fb7..2d20c00 100644 --- a/extensions/chrome/content_script.js +++ b/extensions/chrome/content_script.js @@ -1,2 +1,2 @@ -!function(){const e={CaptureBufferData:'webgpu_inspect_capture_buffer_data',CaptureBuffers:'webgpu_inspect_capture_buffers',DeleteObjects:'webgpu_inspect_delete_objects',ValidationError:'webgpu_inspect_validation_error',MemoryLeakWarning:'webgpu_inspect_memory_leak_warning',DeltaTime:'webgpu_inspect_delta_time',CaptureFrameResults:'webgpu_inspect_capture_frame_results',CaptureFrameCommands:'webgpu_inspect_capture_frame_commands',ObjectSetLabel:'webgpu_inspect_object_set_label',AddObject:'webgpu_inspect_add_object',ResolveAsyncObject:'webgpu_inspect_resolve_async_object',DeleteObject:'webgpu_inspect_delete_object',CaptureTextureFrames:'webgpu_inspect_capture_texture_frames',CaptureTextureData:'webgpu_inspect_capture_texture_data',CaptureBufferData:'webgpu_inspect_capture_buffer_data',Recording:'webgpu_record_recording',RecordingCommand:'webgpu_record_command',RecordingDataCount:'webgpu_record_data_count',RecordingData:'webgpu_record_data'};e.values=new Set(Object.values(e));const t='webgpu_inspect_request_texture',s='webgpu_inspect_compile_shader',r='webgpu_inspect_revert_shader',o='webgpu_inspector_capture',n='webgpu_initialize_inspector',a='webgpu_initialize_recorder',i='WEBGPU_INSPECTOR_LOADED',c='WEBGPU_RECORDER_LOADED',_='WEBGPU_INSPECTOR_CAPTURE_FRAME',p=new class u{constructor(e,t,s){this.name=e,this.tabId=t??0,this.listeners=[],s&&this.listeners.push(s),this._port=null,this.reset()}reset(){const e=this;this._port=chrome.runtime.connect({name:this.name}),this._port.onDisconnect.addListener((()=>{e.reset()})),this._port.onMessage.addListener((t=>{for(const s of e.listeners)s(t)}))}addListener(e){this.listeners.push(e)}postMessage(e){e.__webgpuInspector=!0,this.tabId&&(e.tabId=this.tabId);try{this._port.postMessage(e)}catch(e){this.reset()}}}('webgpu-inspector-page',0,(e=>{let p=e.action;if(!p)return;if(p===t||p===s||p===r)return void window.postMessage(e,'*');if(p===a)return sessionStorage.setItem(c,`${e.frames}%${e.filename}%${e.download}`),void setTimeout((()=>{window.location.reload()}),50);let u='true';if(p===o){const t=JSON.stringify(e);!d||e.frame>=0?(p=n,u=t):(sessionStorage.setItem(_,t),window.postMessage({__webgpuInspector:!0,__webgpuInspectorPanel:!0,action:o,data:t},'*'))}p===n&&(sessionStorage.setItem(i,u),setTimeout((()=>{window.location.reload()}),50))}));let d=!1;function g(e,t,s){const r=document.createElement('script');if(r.id=e,r.src=t,s)for(const e in s)r.setAttribute(e,s[e]);(document.head||document.documentElement).appendChild(r)}window.addEventListener('pageshow',(e=>{e.persisted&&p.reset()})),window.addEventListener('message',(t=>{if(t.source!==window)return;const s=t.data;if('object'!=typeof s||null===s)return;const r=s.action;if(e.values.has(r))try{p.postMessage(s)}catch(e){console.log('#### error:',e)}}));const b=sessionStorage.getItem(i);b&&(sessionStorage.removeItem(i),'true'!==b&&sessionStorage.setItem(_,b),g('__webgpu_inspector',chrome.runtime.getURL('webgpu_inspector.js')),d=!0);const m=sessionStorage.getItem(c);if(m){sessionStorage.removeItem(c);const e=m.split('%');g('__webgpu_recorder',chrome.runtime.getURL('webgpu_recorder.js'),{filename:e[1],frames:e[0],download:e[2],removeUnusedResources:1,messageRecording:1})}p.postMessage({action:'PageLoaded'})}(); +!function(){const e={CaptureBufferData:'webgpu_inspect_capture_buffer_data',CaptureBuffers:'webgpu_inspect_capture_buffers',DeleteObjects:'webgpu_inspect_delete_objects',ValidationError:'webgpu_inspect_validation_error',MemoryLeakWarning:'webgpu_inspect_memory_leak_warning',DeltaTime:'webgpu_inspect_delta_time',CaptureFrameResults:'webgpu_inspect_capture_frame_results',CaptureFrameCommands:'webgpu_inspect_capture_frame_commands',ObjectSetLabel:'webgpu_inspect_object_set_label',AddObject:'webgpu_inspect_add_object',ResolveAsyncObject:'webgpu_inspect_resolve_async_object',DeleteObject:'webgpu_inspect_delete_object',CaptureTextureFrames:'webgpu_inspect_capture_texture_frames',CaptureTextureData:'webgpu_inspect_capture_texture_data',CaptureBufferData:'webgpu_inspect_capture_buffer_data',Recording:'webgpu_record_recording',RecordingCommand:'webgpu_record_command',RecordingDataCount:'webgpu_record_data_count',RecordingData:'webgpu_record_data'};e.values=new Set(Object.values(e));const t='webgpu_inspect_request_texture',s='webgpu_inspect_compile_shader',r='webgpu_inspect_revert_shader',n='webgpu_inspector_capture',o='webgpu_initialize_inspector',a='webgpu_initialize_recorder',i='WEBGPU_INSPECTOR_LOADED',c='WEBGPU_RECORDER_LOADED',_='WEBGPU_INSPECTOR_CAPTURE_FRAME',p=new class u{constructor(e,t,s){this.name=e,this.tabId=t??0,this.listeners=[],s&&this.listeners.push(s),this._port=null,this.reset()}reset(){const e=this;this._port=chrome.runtime.connect({name:this.name}),this._port.onDisconnect.addListener((()=>{e.reset()})),this._port.onMessage.addListener((t=>{for(const s of e.listeners)s(t)}))}addListener(e){this.listeners.push(e)}postMessage(e){e.__webgpuInspector=!0,this.tabId&&(e.tabId=this.tabId);try{this._port.postMessage(e)}catch(e){this.reset()}}}('webgpu-inspector-page',0,(e=>{let p=e.action;if(!p)return;if(p===t||p===s||p===r)return void window.dispatchEvent(new CustomEvent('__WebGPUInspector',{detail:e}));if(p===a)return sessionStorage.setItem(c,`${e.frames}%${e.filename}%${e.download}`),void setTimeout((()=>{window.location.reload()}),50);let u='true';if(p===n){const t=JSON.stringify(e);if(!d||e.frame>=0)p=o,u=t;else{sessionStorage.setItem(_,t);const e={__webgpuInspector:!0,__webgpuInspectorPanel:!0,action:n,data:t};window.dispatchEvent(new CustomEvent('__WebGPUInspector',{detail:e}))}}p===o&&(sessionStorage.setItem(i,u),setTimeout((()=>{window.location.reload()}),50))}));let d=!1;function g(e,t,s){const r=document.createElement('script');if(r.id=e,r.src=t,s)for(const e in s)r.setAttribute(e,s[e]);(document.head||document.documentElement).appendChild(r)}window.addEventListener('pageshow',(e=>{e.persisted&&p.reset()})),window.addEventListener('__WebGPUInspector',(t=>{const s=t.detail;if('object'!=typeof s||null===s)return;const r=s.action;if(e.values.has(r))try{p.postMessage(s)}catch(e){console.log('#### error:',e)}}));const b=sessionStorage.getItem(i);b&&(sessionStorage.removeItem(i),'true'!==b&&sessionStorage.setItem(_,b),g('__webgpu_inspector',chrome.runtime.getURL('webgpu_inspector.js')),d=!0);const m=sessionStorage.getItem(c);if(m){sessionStorage.removeItem(c);const e=m.split('%');g('__webgpu_recorder',chrome.runtime.getURL('webgpu_recorder.js'),{filename:e[1],frames:e[0],download:e[2],removeUnusedResources:1,messageRecording:1})}p.postMessage({action:'PageLoaded'})}(); //# sourceMappingURL=content_script.js.map diff --git a/extensions/chrome/webgpu_inspector.js b/extensions/chrome/webgpu_inspector.js index 7f80367..b89bd75 100644 --- a/extensions/chrome/webgpu_inspector.js +++ b/extensions/chrome/webgpu_inspector.js @@ -1,2 +1,2 @@ -!function(e){async function t(e,t='application/octet-stream'){return await new Promise(((r,s)=>{const o=Object.assign(new FileReader,{onload:()=>r(o.result),onerror:()=>s(o.error)});o.readAsDataURL(new File([e],'',{type:t}))}))}class r{constructor(e){this._lastSlotId=0,this.slots=new Map,e&&(this.name=e)}static get enabled(){return 0==r._disableSignals}static get disabled(){return r._disableSignals>0}static disable(){return r._disableSignals++}static enable(e){return e?(r._disableSignals=0,0):r._disableSignals>0?r._disableSignals--:0}static disconnect(e,t,s){for(const o in e){const i=e[o];i.constructor===r&&i.disconnect(t,s)}}static getSignals(e,t){t=t||[];for(const s in e){const o=e[s];o.constructor===r&&t.push(o)}return t}get hasListeners(){return this.slots.size>0}emit(){if(!r.disabled)for(const e of this.slots){const t=e[1][0],s=e[1][1]||t;t&&(t.constructor===r?t.emit.apply(s,arguments):t.apply(s,arguments))}}addListener(e,t){return this.isListening(e,t)?null:(this.slots.set(this._lastSlotId++,[e,t]),this._lastSlotId-1)}isListening(e,t){for(const r of this.slots){const s=r[1];if(e&&!t){if(s[0]===e||s[1]===e)return!0}else if(!e&&t){if(s[1]===t)return!0}else if(s[0]===e&&s[1]===t)return!0}return!1}disconnect(e,t){if(null==e&&null==t)return this.slots.clear(),!0;if(e.constructor===Number){const t=e;return!!this.slots.has(t)&&(this.slots.delete(t),!0)}let r=!1;for(const s of this.slots){const o=s[0],i=s[1];e&&!t?i[0]!==e&&i[1]!==e||(this.slots.delete(o),r=!0):!e&&t?i[1]===t&&(this.slots.delete(o),r=!0):i[0]===e&&i[1]===t&&(this.slots.delete(o),r=!0)}return r}}function s(){if(!Error.captureStackTrace)return'';const e={};if(Error.captureStackTrace(e,s),!e.stack)return'';return e.stack.split('\n').map((e=>e.split('at ')[1])).slice(2).filter((e=>e&&!e.includes('webgpu_inspector.js'))).join('\n')}r._disableSignals=0;const o=new Set([GPUAdapter,GPUDevice,GPUBuffer,GPUTexture,GPUTextureView,GPUSampler,GPUBindGroupLayout,GPUBindGroup,GPUPipelineLayout,GPUShaderModule,GPUComputePipeline,GPURenderPipeline,GPUCommandBuffer,GPUCommandEncoder,GPUComputePassEncoder,GPURenderPassEncoder,GPURenderBundle,GPUQueue,GPUQuerySet,GPUCanvasContext]),i=new Set(['createBuffer','createTexture','createSampler','importExternalTexture','createBindGroupLayout','createPipelineLayout','createBindGroup','createShaderModule','createComputePipeline','createRenderPipeline','createComputePipelineAsync','createRenderPipelineAsync','createCommandEncoder','createRenderBundleEncoder','createQuerySet','createView']);class n{constructor(e){this._idGenerator=e,this.onPreCall=new r,this.onPostCall=new r,this.onPromise=new r,this.onPromiseResolve=new r,this.recordStacktraces=!1,this._skipRecord=0,this._wrapGPUTypes()}_wrapGPUTypes(){GPU.prototype.requestAdapter=this._wrapMethod('requestAdapter',GPU.prototype.requestAdapter),GPU.prototype.getPreferredFormat=this._wrapMethod('getPreferredFormat',GPU.prototype.getPreferredFormat),GPUAdapter.prototype.requestDevice=this._wrapMethod('requestDevice',GPUAdapter.prototype.requestDevice),GPUDevice.prototype.destroy=this._wrapMethod('destroy',GPUDevice.prototype.destroy),GPUDevice.prototype.createBuffer=this._wrapMethod('createBuffer',GPUDevice.prototype.createBuffer),GPUDevice.prototype.createTexture=this._wrapMethod('createTexture',GPUDevice.prototype.createTexture),GPUDevice.prototype.createSampler=this._wrapMethod('createSampler',GPUDevice.prototype.createSampler),GPUDevice.prototype.importExternalTexture=this._wrapMethod('importExternalTexture',GPUDevice.prototype.importExternalTexture),GPUDevice.prototype.createBindGroupLayout=this._wrapMethod('createBindGroupLayout',GPUDevice.prototype.createBindGroupLayout),GPUDevice.prototype.createPipelineLayout=this._wrapMethod('createPipelineLayout',GPUDevice.prototype.createPipelineLayout),GPUDevice.prototype.createBindGroup=this._wrapMethod('createBindGroup',GPUDevice.prototype.createBindGroup),GPUDevice.prototype.createShaderModule=this._wrapMethod('createShaderModule',GPUDevice.prototype.createShaderModule),GPUDevice.prototype.createComputePipeline=this._wrapMethod('createComputePipeline',GPUDevice.prototype.createComputePipeline),GPUDevice.prototype.createRenderPipeline=this._wrapMethod('createRenderPipeline',GPUDevice.prototype.createRenderPipeline),GPUDevice.prototype.createComputePipelineAsync=this._wrapMethod('createComputePipelineAsync',GPUDevice.prototype.createComputePipelineAsync),GPUDevice.prototype.createRenderPipelineAsync=this._wrapMethod('createRenderPipelineAsync',GPUDevice.prototype.createRenderPipelineAsync),GPUDevice.prototype.createCommandEncoder=this._wrapMethod('createCommandEncoder',GPUDevice.prototype.createCommandEncoder),GPUDevice.prototype.createRenderBundleEncoder=this._wrapMethod('createRenderBundleEncoder',GPUDevice.prototype.createRenderBundleEncoder),GPUDevice.prototype.createQuerySet=this._wrapMethod('createQuerySet',GPUDevice.prototype.createQuerySet),GPUBuffer.prototype.mapAsync=this._wrapMethod('mapAsync',GPUBuffer.prototype.mapAsync),GPUBuffer.prototype.getMappedRange=this._wrapMethod('getMappedRange',GPUBuffer.prototype.getMappedRange),GPUBuffer.prototype.unmap=this._wrapMethod('unmap',GPUBuffer.prototype.unmap),GPUBuffer.prototype.destroy=this._wrapMethod('destroy',GPUBuffer.prototype.destroy),GPUTexture.prototype.createView=this._wrapMethod('createView',GPUTexture.prototype.createView),GPUTexture.prototype.destroy=this._wrapMethod('destroy',GPUTexture.prototype.destroy),GPUShaderModule.prototype.getCompilationInfo=this._wrapMethod('getCompilationInfo',GPUShaderModule.prototype.getCompilationInfo),GPUComputePipeline.prototype.getBindGroupLayout=this._wrapMethod('getBindGroupLayout',GPUComputePipeline.prototype.getBindGroupLayout),GPURenderPipeline.prototype.getBindGroupLayout=this._wrapMethod('getBindGroupLayout',GPURenderPipeline.prototype.getBindGroupLayout),GPUCommandEncoder.prototype.beginRenderPass=this._wrapMethod('beginRenderPass',GPUCommandEncoder.prototype.beginRenderPass),GPUCommandEncoder.prototype.beginComputePass=this._wrapMethod('beginComputePass',GPUCommandEncoder.prototype.beginComputePass),GPUCommandEncoder.prototype.copyBufferToBuffer=this._wrapMethod('copyBufferToBuffer',GPUCommandEncoder.prototype.copyBufferToBuffer),GPUCommandEncoder.prototype.copyBufferToTexture=this._wrapMethod('copyBufferToTexture',GPUCommandEncoder.prototype.copyBufferToTexture),GPUCommandEncoder.prototype.copyTextureToBuffer=this._wrapMethod('copyTextureToBuffer',GPUCommandEncoder.prototype.copyTextureToBuffer),GPUCommandEncoder.prototype.copyTextureToTexture=this._wrapMethod('copyTextureToTexture',GPUCommandEncoder.prototype.copyTextureToTexture),GPUCommandEncoder.prototype.clearBuffer=this._wrapMethod('clearBuffer',GPUCommandEncoder.prototype.clearBuffer),GPUCommandEncoder.prototype.resolveQuerySet=this._wrapMethod('resolveQuerySet',GPUCommandEncoder.prototype.resolveQuerySet),GPUCommandEncoder.prototype.finish=this._wrapMethod('finish',GPUCommandEncoder.prototype.finish),GPUCommandEncoder.prototype.pushDebugGroup=this._wrapMethod('pushDebugGroup',GPUCommandEncoder.prototype.pushDebugGroup),GPUCommandEncoder.prototype.popDebugGroup=this._wrapMethod('popDebugGroup',GPUCommandEncoder.prototype.popDebugGroup),GPUCommandEncoder.prototype.insertDebugMarker=this._wrapMethod('insertDebugMarker',GPUCommandEncoder.prototype.insertDebugMarker),GPUComputePassEncoder.prototype.setPipeline=this._wrapMethod('setPipeline',GPUComputePassEncoder.prototype.setPipeline),GPUComputePassEncoder.prototype.dispatchWorkgroups=this._wrapMethod('dispatchWorkgroups',GPUComputePassEncoder.prototype.dispatchWorkgroups),GPUComputePassEncoder.prototype.dispatchWorkgroupsIndirect=this._wrapMethod('dispatchWorkgroupsIndirect',GPUComputePassEncoder.prototype.dispatchWorkgroupsIndirect),GPUComputePassEncoder.prototype.end=this._wrapMethod('end',GPUComputePassEncoder.prototype.end),GPUComputePassEncoder.prototype.setBindGroup=this._wrapMethod('setBindGroup',GPUComputePassEncoder.prototype.setBindGroup),GPUComputePassEncoder.prototype.setBindGroup=this._wrapMethod('setBindGroup',GPUComputePassEncoder.prototype.setBindGroup),GPUComputePassEncoder.prototype.pushDebugGroup=this._wrapMethod('pushDebugGroup',GPUComputePassEncoder.prototype.pushDebugGroup),GPUComputePassEncoder.prototype.popDebugGroup=this._wrapMethod('popDebugGroup',GPUComputePassEncoder.prototype.popDebugGroup),GPUComputePassEncoder.prototype.insertDebugMarker=this._wrapMethod('insertDebugMarker',GPUComputePassEncoder.prototype.insertDebugMarker),GPURenderPassEncoder.prototype.setViewport=this._wrapMethod('setViewport',GPURenderPassEncoder.prototype.setViewport),GPURenderPassEncoder.prototype.setScissorRect=this._wrapMethod('setScissorRect',GPURenderPassEncoder.prototype.setScissorRect),GPURenderPassEncoder.prototype.setBlendConstant=this._wrapMethod('setBlendConstant',GPURenderPassEncoder.prototype.setBlendConstant),GPURenderPassEncoder.prototype.setStencilReference=this._wrapMethod('setStencilReference',GPURenderPassEncoder.prototype.setStencilReference),GPURenderPassEncoder.prototype.beginOcclusionQuery=this._wrapMethod('beginOcclusionQuery',GPURenderPassEncoder.prototype.beginOcclusionQuery),GPURenderPassEncoder.prototype.endOcclusionQuery=this._wrapMethod('endOcclusionQuery',GPURenderPassEncoder.prototype.endOcclusionQuery),GPURenderPassEncoder.prototype.executeBundles=this._wrapMethod('executeBundles',GPURenderPassEncoder.prototype.executeBundles),GPURenderPassEncoder.prototype.end=this._wrapMethod('end',GPURenderPassEncoder.prototype.end),GPURenderPassEncoder.prototype.setPipeline=this._wrapMethod('setPipeline',GPURenderPassEncoder.prototype.setPipeline),GPURenderPassEncoder.prototype.setIndexBuffer=this._wrapMethod('setIndexBuffer',GPURenderPassEncoder.prototype.setIndexBuffer),GPURenderPassEncoder.prototype.setVertexBuffer=this._wrapMethod('setVertexBuffer',GPURenderPassEncoder.prototype.setVertexBuffer),GPURenderPassEncoder.prototype.draw=this._wrapMethod('draw',GPURenderPassEncoder.prototype.draw),GPURenderPassEncoder.prototype.drawIndexed=this._wrapMethod('drawIndexed',GPURenderPassEncoder.prototype.drawIndexed),GPURenderPassEncoder.prototype.drawIndirect=this._wrapMethod('drawIndirect',GPURenderPassEncoder.prototype.drawIndirect),GPURenderPassEncoder.prototype.drawIndexedIndirect=this._wrapMethod('drawIndexedIndirect',GPURenderPassEncoder.prototype.drawIndexedIndirect),GPURenderPassEncoder.prototype.setBindGroup=this._wrapMethod('setBindGroup',GPURenderPassEncoder.prototype.setBindGroup),GPURenderPassEncoder.prototype.pushDebugGroup=this._wrapMethod('pushDebugGroup',GPURenderPassEncoder.prototype.pushDebugGroup),GPURenderPassEncoder.prototype.popDebugGroup=this._wrapMethod('popDebugGroup',GPURenderPassEncoder.prototype.popDebugGroup),GPURenderPassEncoder.prototype.insertDebugMarker=this._wrapMethod('insertDebugMarker',GPURenderPassEncoder.prototype.insertDebugMarker),GPUQueue.prototype.submit=this._wrapMethod('submit',GPUQueue.prototype.submit),GPUQueue.prototype.writeBuffer=this._wrapMethod('writeBuffer',GPUQueue.prototype.writeBuffer),GPUQueue.prototype.writeTexture=this._wrapMethod('writeTexture',GPUQueue.prototype.writeTexture),GPUQueue.prototype.copyExternalImageToTexture=this._wrapMethod('copyExternalImageToTexture',GPUQueue.prototype.copyExternalImageToTexture),GPUQuerySet.prototype.destroy=this._wrapMethod('destroy',GPUQuerySet.prototype.destroy),GPUCanvasContext.prototype.configure=this._wrapMethod('configure',GPUCanvasContext.prototype.configure),GPUCanvasContext.prototype.unconfigure=this._wrapMethod('unconfigure',GPUCanvasContext.prototype.unconfigure),GPUCanvasContext.prototype.getCurrentTexture=this._wrapMethod('getCurrentTexture',GPUCanvasContext.prototype.getCurrentTexture)}disableRecording(){this._skipRecord++}enableRecording(){this._skipRecord--,this._skipRecord<0&&(this._skipRecord=0)}get isRecordingEnabled(){return 0===this._skipRecord}_wrapMethod(e,t){const r=this;return function(){const o=this,n=[...arguments];if(r._skipRecord>0)return t.call(o,...n);r.onPreCall.emit(o,e,n);const a=t.call(o,...n),c=i.has(e),p=r.recordStacktraces||c?s():void 0;if(a instanceof Promise){const t=r._idGenerator.getNextId(o);r.onPromise.emit(o,e,n,t,p);const s=a,i=new Promise((i=>{s.then((s=>{r.onPromiseResolve.emit(o,e,n,t,s,p),i(s)}))}));return i}return r.onPostCall.emit(o,e,n,a,p),a}}}const a={r8unorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8snorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8uint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8sint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg8unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8snorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},'rgba8unorm-srgb':{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8snorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},bgra8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},'bgra8unorm-srgb':{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r16uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16float:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg16uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba16uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r32uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg32uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba32uint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32sint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32float:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rg11b10ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},stencil8:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!1,hasStencil:!0,channels:1},depth16unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},depth24plus:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,depthOnlyFormat:'depth32float',channels:1},'depth24plus-stencil8':{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,depthOnlyFormat:'depth32float',channels:1},depth32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},'depth32float-stencil8':{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,stencilOnlyFormat:'depth32float',channels:1},rgb9e5ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},'bc1-rgba-unorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc1-rgba-unorm-srgb':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc2-rgba-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc2-rgba-unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc3-rgba-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc3-rgba-unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc4-r-unorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},'bc4-r-snorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},'bc5-rg-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},'bc5-rg-snorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},'bc6h-rgb-ufloat':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc6h-rgb-float':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc7-rgba-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc7-rgba-unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgb8unorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgb8unorm-srgb':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgb8a1unorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgb8a1unorm-srgb':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgba8unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgba8unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'eac-r11unorm':{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},'eac-r11snorm':{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},'eac-rg11unorm':{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},'eac-rg11snorm':{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},'astc-4x4-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'astc-4x4-unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'astc-5x4-unorm':{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},'astc-5x4-unorm-srgb':{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},'astc-5x5-unorm':{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},'astc-5x5-unorm-srgb':{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},'astc-6x5-unorm':{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},'astc-6x5-unorm-srgb':{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},'astc-6x6-unorm':{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},'astc-6x6-unorm-srgb':{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},'astc-8x5-unorm':{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},'astc-8x5-unorm-srgb':{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},'astc-8x6-unorm':{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},'astc-8x6-unorm-srgb':{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},'astc-8x8-unorm':{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},'astc-8x8-unorm-srgb':{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},'astc-10x5-unorm':{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},'astc-10x5-unorm-srgb':{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},'astc-10x6-unorm':{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},'astc-10x6-unorm-srgb':{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},'astc-10x8-unorm':{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},'astc-10x8-unorm-srgb':{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},'astc-10x10-unorm':{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},'astc-10x10-unorm-srgb':{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},'astc-12x10-unorm':{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},'astc-12x10-unorm-srgb':{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},'astc-12x12-unorm':{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4},'astc-12x12-unorm-srgb':{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4}};class c{constructor(e){this.device=e,this.blitShaderModule=e.createShaderModule({code:c.blitShader}),this.multisampleBlitShaderModule=e.createShaderModule({code:c.multisampleBlitShader}),this.depthToFloatShaderModule=e.createShaderModule({code:c.depthToFloatShader}),this.depthToFloatMultisampleShaderModule=e.createShaderModule({code:c.depthToFloatMultisampleShader}),this.blitPipelines={},this.blitDepthPipelines={},this.bindGroupLayouts=new Map,this.pipelineLayouts=new Map,this.depthToFloatPipeline=null,this.depthToFloatMSPipeline=null,this.pointSampler=e.createSampler({magFilter:'nearest',minFilter:'nearest'}),this.displayUniformBuffer=e.createBuffer({size:32,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),this.displayBingGroupLayout=e.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,buffer:{type:'uniform'}}]}),this.displayBindGroup=e.createBindGroup({layout:this.displayBingGroupLayout,entries:[{binding:0,resource:{buffer:this.displayUniformBuffer}}]})}copyDepthTexture(e,t,r){const s=e.width,o=e.height,i=e.depthOrArrayLayers,n=e.usage|GPUTextureUsage.RENDER_TARGET|GPUTextureUsage.COPY_SRC,a=[s,o,i];t=t||'r32float';const c=this.device.createTexture({format:t,size:a,usage:n});for(let s=0;s1}}]});this.bindGroupLayouts.set(c,e);const t=this.device.createPipelineLayout({bindGroupLayouts:[e,this.displayBingGroupLayout]});this.pipelineLayouts.set(c,t)}const p=a[t],d=p?.channels??4,u=this.bindGroupLayouts.get(c),l=this.pipelineLayouts.get(c),h=`${o}#${n}#${r}`;let _=this.blitPipelines[h];if(!_){const e=r>1?this.multisampleBlitShaderModule:this.blitShaderModule;_=this.device.createRenderPipeline({layout:l,vertex:{module:e,entryPoint:'vertexMain'},fragment:{module:e,entryPoint:'fragmentMain',targets:[{format:o}]},primitive:{topology:'triangle-list'}}),this.blitPipelines[h]=_}const m=this.device.createBindGroup({layout:u,entries:[{binding:0,resource:this.pointSampler},{binding:1,resource:e}]}),f=this.device.createCommandEncoder(),g={colorAttachments:[{view:s,loadOp:'clear',storeOp:'store'}]};i?this.device.queue.writeBuffer(this.displayUniformBuffer,0,new Float32Array([i.exposure,i.channels,d,i.minRange,i.maxRange,0,0,0])):this.device.queue.writeBuffer(this.displayUniformBuffer,0,new Float32Array([1,0,d,0,1,0,0,0]));const b=f.beginRenderPass(g);b.setPipeline(_),b.setBindGroup(0,m),b.setBindGroup(1,this.displayBindGroup),b.draw(3),b.end(),this.device.queue.submit([f.finish()])}convertDepthToFloat(e,t,r,s,o){if(t>1){if(!this.depthToFloatMSPipeline){this.device.pushErrorScope('validation'),this.depthToFloatBindGroupMSLayout=this.device.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:'depth',multisampled:!0}}]});const e=this.device.createPipelineLayout({bindGroupLayouts:[this.depthToFloatBindGroupMSLayout]}),t=this.depthToFloatMultisampleShaderModule;this.depthToFloatMSPipeline=this.device.createRenderPipeline({layout:e,vertex:{module:t,entryPoint:'vertexMain'},fragment:{module:t,entryPoint:'fragmentMain',targets:[{format:s}]},primitive:{topology:'triangle-list'}}),this.device.popErrorScope().then((e=>{e&&console.error(e.message)}))}}else if(!this.depthToFloatPipeline){this.device.pushErrorScope('validation'),this.depthToFloatBindGroupLayout=this.device.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:'depth'}}]});const e=this.device.createPipelineLayout({bindGroupLayouts:[this.depthToFloatBindGroupLayout]}),t=this.depthToFloatShaderModule;this.depthToFloatPipeline=this.device.createRenderPipeline({layout:e,vertex:{module:t,entryPoint:'vertexMain'},fragment:{module:t,entryPoint:'fragmentMain',targets:[{format:s}]},primitive:{topology:'triangle-list'}}),this.device.popErrorScope().then((e=>{e&&console.error(e.message)}))}this.device.pushErrorScope('validation');const i=this.device.createBindGroup({layout:t>1?this.depthToFloatBindGroupMSLayout:this.depthToFloatBindGroupLayout,entries:[{binding:0,resource:e}]}),n=!o;o??=this.device.createCommandEncoder();const a=o.beginRenderPass({colorAttachments:[{view:r,loadOp:'clear',storeOp:'store',clearColor:{r:0,g:0,b:0,a:0}}]});a.setPipeline(t>1?this.depthToFloatMSPipeline:this.depthToFloatPipeline),a.setBindGroup(0,i),a.draw(3),a.end(),n&&this.device.queue.submit([o.finish()]),this.device.popErrorScope().then((e=>{e&&console.error(e.message)}))}}c.blitShader='\n var posTex:array = array(\n vec4f(-1.0, 1.0, 0.0, 0.0),\n vec4f(3.0, 1.0, 2.0, 0.0),\n vec4f(-1.0, -3.0, 0.0, 2.0));\n struct VertexOutput {\n @builtin(position) position: vec4f,\n @location(0) uv: vec2f\n };\n @vertex\n fn vertexMain(@builtin(vertex_index) vertexIndex: u32) -> VertexOutput {\n var output: VertexOutput;\n output.uv = posTex[vertexIndex].zw;\n output.position = vec4f(posTex[vertexIndex].xy, 0.0, 1.0);\n return output;;\n }\n @group(0) @binding(0) var texSampler: sampler;\n @group(0) @binding(1) var texture: texture_2d;\n struct Display {\n exposure: f32,\n channels: f32,\n numChannels: f32,\n minRange: f32,\n maxRange: f32,\n _pad1: f32,\n _pad2: f32,\n _pad3: f32\n };\n @group(1) @binding(0) var display: Display; \n @fragment\n fn fragmentMain(input: VertexOutput) -> @location(0) vec4f {\n var color = textureSample(texture, texSampler, input.uv);\n\n if (display.numChannels == 1.0) {\n if (display.minRange != display.maxRange) {\n if (color.r < display.minRange) {\n color = vec4f(0.0, 0.0, 0.0, 1);\n } else if (color.r > display.maxRange) {\n color = vec4f(1.0, 0.0, 0.0, 1);\n } else {\n color = vec4f((color.r - display.minRange) / (display.maxRange - display.minRange), 0.0, 0.0, 1);\n }\n }\n color = vec4f(color.r, color.r, color.r, 1.0);\n } else if (display.numChannels == 2.0) {\n color = vec4f(color.r, color.g, 0.0, 1.0);\n }\n\n if (display.channels == 1.0) { // R\n var rgb = color.rgb * display.exposure;\n return vec4f(rgb.r, 0.0, 0.0, 1);\n } else if (display.channels == 2.0) { // G\n var rgb = color.rgb * display.exposure;\n return vec4f(0.0, rgb.g, 0.0, 1);\n } else if (display.channels == 3.0) { // B\n var rgb = color.rgb * display.exposure;\n return vec4f(0.0, 0.0, rgb.b, 1);\n } else if (display.channels == 4.0) { // A\n var a = color.a * display.exposure;\n return vec4f(a, a, a, 1);\n } else if (display.channels == 5.0) { // Luminance\n var luminance = dot(color.rgb, vec3f(0.2126, 0.7152, 0.0722));\n var rgb = vec3f(luminance) * display.exposure;\n return vec4f(rgb, 1);\n }\n\n // RGB\n var rgb = color.rgb * display.exposure;\n return vec4f(rgb, 1);\n }\n',c.multisampleBlitShader='\n var posTex:array = array(\n vec4f(-1.0, 1.0, 0.0, 0.0),\n vec4f(3.0, 1.0, 2.0, 0.0),\n vec4f(-1.0, -3.0, 0.0, 2.0));\n struct VertexOutput {\n @builtin(position) position: vec4f,\n @location(0) uv: vec2f\n };\n @vertex\n fn vertexMain(@builtin(vertex_index) vertexIndex: u32) -> VertexOutput {\n var output: VertexOutput;\n output.uv = posTex[vertexIndex].zw;\n output.position = vec4f(posTex[vertexIndex].xy, 0.0, 1.0);\n return output;;\n }\n @group(0) @binding(0) var texSampler: sampler;\n @group(0) @binding(1) var texture: texture_multisampled_2d;\n struct Display {\n exposure: f32,\n channels: f32,\n numChannels: f32,\n minRange: f32,\n maxRange: f32,\n _pad1: f32,\n _pad2: f32,\n _pad3: f32\n };\n @group(1) @binding(0) var display: Display; \n @fragment\n fn fragmentMain(input: VertexOutput) -> @location(0) vec4f {\n var coords = vec2i(input.uv * vec2f(textureDimensions(texture)));\n var color = textureLoad(texture, coords, 0);\n if (display.numChannels == 1.0) {\n if (display.minRange != display.maxRange) {\n if (color.r < display.minRange) {\n color = vec4f(0.0, 0.0, 0.0, color.a);\n } else if (color.r > display.maxRange) {\n color = vec4f(1.0, 1.0, 1.0, color.a);\n } else {\n color = vec4f((color.r - display.minRange) / (display.maxRange - display.minRange), 0.0, 0.0, color.a);\n }\n }\n color = vec4f(color.r, color.r, color.r, 1.0);\n } else if (display.numChannels == 2.0) {\n color = vec4f(color.r, color.g, 0.0, 1.0);\n }\n if (display.channels == 1.0) { // R\n var rgb = color.rgb * display.exposure;\n return vec4f(rgb.r, 0.0, 0.0, color.a);\n } else if (display.channels == 2.0) { // G\n var rgb = color.rgb * display.exposure;\n return vec4f(0.0, rgb.g, 0.0, color.a);\n } else if (display.channels == 3.0) { // B\n var rgb = color.rgb * display.exposure;\n return vec4f(0.0, 0.0, rgb.b, color.a);\n } else if (display.channels == 4.0) { // A\n var a = color.a * display.exposure;\n return vec4f(a, a, a, color.a);\n } else if (display.channels == 5.0) { // Luminance\n var luminance = dot(color.rgb, vec3f(0.2126, 0.7152, 0.0722));\n var rgb = vec3f(luminance) * display.exposure;\n return vec4f(rgb, color.a);\n }\n\n // RGB\n var rgb = color.rgb * display.exposure;\n return vec4f(rgb, color.a);\n }',c.depthToFloatShader='\n var posTex:array = array(\n vec4f(-1.0, 1.0, 0.0, 0.0),\n vec4f(3.0, 1.0, 2.0, 0.0),\n vec4f(-1.0, -3.0, 0.0, 2.0));\n struct VertexOutput {\n @builtin(position) position: vec4,\n @location(0) uv : vec2\n };\n @vertex\n fn vertexMain(@builtin(vertex_index) vertexIndex: u32) -> VertexOutput {\n var output: VertexOutput;\n output.uv = posTex[vertexIndex].zw;\n output.position = vec4f(posTex[vertexIndex].xy, 0.0, 1.0);\n return output;;\n }\n \n @binding(0) @group(0) var depth: texture_depth_2d;\n @fragment\n fn fragmentMain(input: VertexOutput) -> @location(0) vec4 {\n var depthSize = textureDimensions(depth);\n var coords = vec2(i32(f32(depthSize.x) * input.uv.x),\n i32(f32(depthSize.y) * input.uv.y));\n var d = textureLoad(depth, coords, 0);\n return vec4(d, 0.0, 0.0, 1.0);\n }',c.depthToFloatMultisampleShader='\n var posTex:array = array(\n vec4f(-1.0, 1.0, 0.0, 0.0),\n vec4f(3.0, 1.0, 2.0, 0.0),\n vec4f(-1.0, -3.0, 0.0, 2.0));\n struct VertexOutput {\n @builtin(position) position: vec4,\n @location(0) uv : vec2\n };\n @vertex\n fn vertexMain(@builtin(vertex_index) vertexIndex: u32) -> VertexOutput {\n var output: VertexOutput;\n output.uv = posTex[vertexIndex].zw;\n output.position = vec4f(posTex[vertexIndex].xy, 0.0, 1.0);\n return output;;\n }\n \n @binding(0) @group(0) var depth: texture_depth_multisampled_2d;\n @fragment\n fn fragmentMain(input: VertexOutput) -> @location(0) vec4 {\n var depthSize = textureDimensions(depth);\n var coords = vec2(i32(f32(depthSize.x) * input.uv.x),\n i32(f32(depthSize.y) * input.uv.y));\n var d = textureLoad(depth, coords, 0);\n return vec4(d, 0.0, 0.0, 1.0);\n }';const p={CaptureBufferData:'webgpu_inspect_capture_buffer_data',CaptureBuffers:'webgpu_inspect_capture_buffers',DeleteObjects:'webgpu_inspect_delete_objects',ValidationError:'webgpu_inspect_validation_error',MemoryLeakWarning:'webgpu_inspect_memory_leak_warning',DeltaTime:'webgpu_inspect_delta_time',CaptureFrameResults:'webgpu_inspect_capture_frame_results',CaptureFrameCommands:'webgpu_inspect_capture_frame_commands',ObjectSetLabel:'webgpu_inspect_object_set_label',AddObject:'webgpu_inspect_add_object',ResolveAsyncObject:'webgpu_inspect_resolve_async_object',DeleteObject:'webgpu_inspect_delete_object',CaptureTextureFrames:'webgpu_inspect_capture_texture_frames',CaptureTextureData:'webgpu_inspect_capture_texture_data',CaptureBufferData:'webgpu_inspect_capture_buffer_data',Recording:'webgpu_record_recording',RecordingCommand:'webgpu_record_command',RecordingDataCount:'webgpu_record_data_count',RecordingData:'webgpu_record_data'};p.values=new Set(Object.values(p));const d='webgpu_inspect_request_texture',u='webgpu_inspect_compile_shader',l='webgpu_inspect_revert_shader',h='webgpu_inspector_capture';class _{constructor(e){this.windowSize=e,this.buffer=[],this.sum=0}add(e){this.buffer.push(e),this.buffer.length>this.windowSize&&(this.sum-=this.buffer.shift()),this.sum+=e}get average(){return 0===this.buffer.length?0:this.sum/this.buffer.length}}function m(e,t){return e+t-1&~(t-1)}e.webgpuInspector=null,(()=>{const r=self,s=self.window,i=self.document,f=self.sessionStorage,g=self.postMessage,b='WEBGPU_INSPECTOR_CAPTURE_FRAME',y=262144;e.webgpuInspector=new class P{constructor(){if(this._captureFrameCommands=[],this._frameData=[],this._frameRenderPassCount=0,this._captureTexturedBuffers=[],this._currentFrame=null,this._frameIndex=0,this._initalized=!0,this._objectID=1,this._lastFrameTime=0,this._frameCommandCount=0,this._captureFrameRequest=!1,this._errorChecking=1,this._trackedObjects=new Map,this._trackedObjectInfo=new Map,this._bindGroupCount=0,this._captureTextureRequest=new Map,this._toDestroy=[],this._objectReplacementMap=new Map,this._captureBuffersCount=0,this._captureTempBuffers=[],this._mappedTextureBufferCount=0,this._encodingTextureChunkCount=0,this._mappedBufferCount=0,this._encodingBufferChunkCount=0,this._captureData=null,this._frameRate=new _(60),this._captureTimestamps=!1,this._timestampQuerySet=null,this._timestampBuffer=null,this._timestampIndex=0,this._maxTimestamps=2e3,!navigator.gpu)return;if(i?.body){const e=i.createElement('div');e.style='position: absolute; z-index: 1000000; margin-left: 10px; margin-top: 5px; padding-left: 5px; padding-right: 10px; background-color: rgba(0, 0, 1, 0.75); border-radius: 5px; box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.5); color: #fff; font-size: 12pt;',i.body.insertBefore(e,i.body.firstChild),this._inspectingStatus=i.createElement('div'),this._inspectingStatus.title='WebGPU Inspector Running',this._inspectingStatus.style='height: 10px; width: 10px; display: inline-block; margin-right: 5px; background-color: #ff0; border-radius: 50%; border: 1px solid #000; box-shadow: inset -4px -4px 4px -3px rgb(255,100,0), 2px 2px 3px rgba(0,0,0,0.8);',e.appendChild(this._inspectingStatus),this._inspectingStatusFrame=i.createElement('div'),this._inspectingStatusFrame.style='display: inline-block;',this._inspectingStatusFrame.textContent='Frame: 0',e.appendChild(this._inspectingStatusFrame),this._inspectingStatusText=i.createElement('div'),this._inspectingStatusText.style='display: inline-block; margin-left: 10px;',e.appendChild(this._inspectingStatusText)}this._gpuWrapper=new n(this);const e=this;this._gpuWrapper.onPromise.addListener(this._onAsyncPromise,this),this._gpuWrapper.onPromiseResolve.addListener(this._onAsyncResolve,this),this._gpuWrapper.onPreCall.addListener(this._preMethodCall,this),this._gpuWrapper.onPostCall.addListener(this._postMethodCall,this),this._garbageCollectectedObjects=[],this._garbageCollectionRegistry=new FinalizationRegistry((t=>{if(t>0){e._garbageCollectectedObjects.push(t);const r=e._trackedObjectInfo.get(t);r&&(r===GPUBindGroup&&e._bindGroupCount--,r!==GPUBuffer&&r!==GPUTexture&&r!==GPUDevice||e._memoryLeakWarning(t,r)),e._garbageCollectectedObjects.length>100&&(e._postMessage({action:p.DeleteObjects,idList:e._garbageCollectectedObjects}),e._garbageCollectectedObjects.length=0)}t>0&&(e._trackedObjects.delete(t),e._trackedObjectInfo.delete(t),e._captureTextureRequest.delete(t),e._objectReplacementMap.delete(t))}));if(setInterval((()=>{e._garbageCollectectedObjects.length>0&&(e._postMessage({action:p.DeleteObjects,idList:e._garbageCollectectedObjects}),e._garbageCollectectedObjects.length=0)}),200),i){const t=i.getElementsByTagName('canvas');for(const e of t)this._wrapCanvas(e);const r=i.createElement;i.createElement=t=>{const s=r.call(i,t);return'canvas'===t&&e._wrapCanvas(s),s}}const t=requestAnimationFrame;this._currentFrameTime=0,requestAnimationFrame=r=>t((function(t){if(!e._currentFrameTime){e._currentFrameTime=t,e._frameStart(t);const s=r(t);s instanceof Promise?Promise.all([s]).then((()=>{e._frameEnd(t),e._currentFrameTime=0})):(e._frameEnd(t),e._currentFrameTime=0)}})),r.addEventListener('message',(t=>{if(s&&t.source!==s)return;const r=t.data;if('object'==typeof r&&r.__webgpuInspector)if(r.action===p.DeltaTime)r.__webgpuInspectorWorker&&this._updateFrameRate(r.deltaTime);else if(r.action===d){const t=r.id;e._requestTexture(t)}else if(r.action===u){const t=r.id,s=r.code;e._compileShader(t,s)}else if(r.action===l){const t=r.id;e._revertShader(t)}else r.action===h&&null==s&&('String'===r.data.constructor.name&&(r.data=JSON.parse(r.data)),e._captureData=r.data)}))}captureWorker(e){this._wrapCanvas(e)}disableRecording(){this._gpuWrapper.disableRecording()}enableRecording(){this._gpuWrapper.enableRecording()}_postMessage(e){e.__webgpuInspector=!0,e.__webgpuInspectorPage=!0,e.__webgpuInspectorWorker=!s,g(e)}_updateCanvasAttachment(e){let t=null;e.resolveTarget?t=e.resolveTarget:e.view&&(t=e.view);const r=t?.__texture,s=r?.__context;if(!s)return;s.__captureTexture&&(s.__captureTexture.width==r.width&&s.__captureTexture.height==r.height&&s.__captureTexture.format==r.format||(this.disableRecording(),s.__captureTexture.destroy(),s.__captureTexture=null,this.enableRecording()));const o=s.__device;if(o){this.disableRecording();const i=o.createTexture({size:[r.width,r.height,1],format:r.format,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC});if(s.__captureTexture=i,i){i.__id=r.__id,i.__canvasTexture=r,i.__context=s;const o=i.createView();o.__texture=i,o.__canvasView=t,i.__view=o,o.__context=s,e.resolveTarget?e.resolveTarget=o:e.view=o}this.enableRecording()}}_preMethodCall(e,t,r){if('requestDevice'===t&&(0===r.length&&(r[0]={}),r[0].requiredFeatures?r[0].requiredFeatures.push('timestamp-query'):r[0].requiredFeatures=['timestamp-query']),'setPipeline'===t){let e=r[0];const t=this._objectReplacementMap.get(e.__id);t&&t.replacement&&(r[0]=t.replacement)}if('createTexture'===t&&(r[0].usage|=GPUTextureUsage.COPY_SRC|GPUTextureUsage.TEXTURE_BINDING),'createBuffer'===t&&(r[0].usage&GPUBufferUsage.MAP_READ||(r[0].usage|=GPUBufferUsage.COPY_SRC)),'createShaderModule'!==t&&'createRenderPipeline'!==t&&'createComputePipeline'!==t&&'createBindGroup'!==t||this._errorChecking>0&&(this._gpuWrapper.disableRecording(),e.pushErrorScope('validation'),this._gpuWrapper.enableRecording()),'beginRenderPass'!==t&&'beginComputePass'!==t||this._captureTimestamps&&this._captureFrameRequest&&(!this._timestampQuerySet&&e.__device&&(this._timestampQuerySet=e.__device.createQuerySet({type:'timestamp',count:this._maxTimestamps}),this._timestampBuffer=e.__device.createBuffer({size:8*this._maxTimestamps,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC})),!r[0].timestampWrites&&this._timestampIndex0){const r=e.__device.createCommandEncoder();r.resolveQuerySet(this._timestampQuerySet,0,this._timestampIndex,this._timestampBuffer,0),t=e.__device.createBuffer({size:8*this._timestampIndex,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),t.__count=this._timestampIndex,r.copyBufferToBuffer(this._timestampBuffer,0,t,0,8*this._timestampIndex),e.__device.queue.submit([r.finish()]),this._timestampIndex=0}const s=this;if(this._captureTextureRequest.size>0){const t=r[0];let o=!1;for(const e of t)o|=!!e.__rendersToCanvas;this._captureTextureRequest.forEach(((t,r)=>{(r>0||o)&&(t=t||s._trackedObjects.get(r)?.deref(),s._captureTextureBuffer(e.__device,null,t),s._captureTextureRequest.delete(r))}))}const o=[...this._captureTempBuffers];this._captureTempBuffers.length=0;const i=[...this._captureTexturedBuffers];this._captureTexturedBuffers.length=0;const n=[...this._toDestroy];this._toDestroy.length=0,e.onSubmittedWorkDone().then((async()=>{s.disableRecording(),t&&s._sendTimestampBuffer(t.__count,t),o.length&&s._sendCapturedBuffers(o),i.length&&s._sendCaptureTextureBuffers(i);for(const e of n)e.destroy();s.enableRecording()})),this.enableRecording()}let n;if('createShaderModule'!==t&&'createRenderPipeline'!==t&&'createComputePipeline'!==t&&'createBindGroup'!==t||this._errorChecking>0&&(this.disableRecording(),e.popErrorScope().then((e=>{if(e){console.error(e.message);const t=s?.__id??0;self._postMessage({action:p.ValidationError,id:t,message:e.message,stacktrace:i})}})),this.enableRecording()),'getCurrentTexture'===t?(e.__id||(this._wrapObject(e),this._trackObject(e.__id,e)),n=-e.__id,e.__canvasTexture=new WeakRef(s),s.__frameIndex=this._frameIndex):'createView'===t&&e.__id<0&&(n=e.__id-.5),e instanceof GPUDevice&&void 0===e?.__id&&(this._wrapDevice(null,e),e.__adapter||navigator.gpu.requestAdapter().then((t=>{e.__adapter=t}))),s)if(o.has(s.constructor)&&this._wrapObject(s,n),'createShaderModule'===t||'createRenderPipeline'===t)s.__descriptor=r[0],s.__device=e,this._objectReplacementMap.set(s.__id,{id:s.__id,object:new WeakRef(s),replacement:null});else if('getCurrentTexture'===t)s.__context=e,this._trackObject(s.__id,s),s.label='CanvasTexture';else if('createTexture'===t)this._trackObject(s.__id,s);else if('createView'!==t||n){if('createBuffer'===t)this._trackObject(s.__id,s);else if('createBindGroup'===t)this._trackObject(s.__id,s),s.__descriptor=r[0];else if('setBindGroup'===t){const t=r[1].__descriptor;if(t)for(const r of t.entries)if(r.resource instanceof GPUTextureView&&r.resource.__id<0){if(r.resource.__texture.__frameIndex{const i={vendor:o.vendor,architecture:o.architecture,device:o.device,description:o.description,features:s._gpuToArray(e.features),limits:s._gpuToObject(e.limits),isFallbackAdapter:e.isFallbackAdapter,wgslFeatures:s._gpuToArray(navigator.gpu.wgslLanguageFeatures)};s._sendAddObjectMessage(t,0,'Adapter',JSON.stringify(i),r)}))}_wrapDevice(e,t,r,s,o){if(e&&void 0===e.__id&&this._wrapAdapter(e,void 0,o),t&&void 0===t.__id){t.queue.__device=t;const i=this;t.addEventListener('uncapturederror',(e=>{i._postMessage({action:p.ValidationError,id:0,message:e.error.message})})),s??=[],this._wrapObject(t,r);const n=s[0]??{},a=t.__id,c=e?.__id??0;n.features=this._gpuToArray(t.features),n.limits=this._gpuToObject(t.limits),this._trackObject(a,t),this._sendAddObjectMessage(r,c,'Device',JSON.stringify(n),o),t.__adapter=e,this._device=t}}clear(){this._captureFrameCommands.length=0,this._currentFrame=null}getNextId(e){return e instanceof GPUCommandEncoder||e instanceof GPUComputePassEncoder||e instanceof GPURenderPassEncoder||e instanceof GPUCommandBuffer?0:this._objectID++}_memoryLeakWarning(e,t){if(t){const e=`${t.name} was garbage collected without being explicitly destroyed. These objects should explicitly destroyed to avoid GPU memory leaks.`;this._postMessage({action:p.ValidationError,id:0,message:e})}}_isPrimitiveType(e){return!e||e.constructor===String||e.constructor===Number||e.constructor===Boolean}_isTypedArray(e){return e&&(e instanceof ArrayBuffer||e.buffer instanceof ArrayBuffer)}_isArray(e){return e&&e.constructor===Array}_duplicateArray(e,t){const r=new Array(e.length);for(let s=0,o=e.length;s{if(t){console.error(t.message);const r=e??0;a._postMessage({action:p.ValidationError,id:r,message:t.message})}})),this._errorChecking++,this.enableRecording(),r.replacement=n;for(const e of this._objectReplacementMap.values()){const t=e.object.deref(),r=t instanceof GPURenderPipeline,i=t instanceof GPUComputePipeline;if(r||i){const i=t.__descriptor;let a=!1,c=null;if(i.vertex?.module===s&&(c||(c=this._duplicateObject(i)),a=!0,c.vertex.module=n),i.fragment?.module===s&&(c||(c=this._duplicateObject(i)),a=!0,c.fragment.module=n),i.compute?.module===s&&(c||(c=this._duplicateObject(i)),a=!0,c.compute.module=n),a){this.disableRecording(),this._errorChecking--,c.__replacement=e.id,o.pushErrorScope('validation');const t=r?o.createRenderPipeline(c):o.createComputePipeline(c),s=this;o.popErrorScope().then((t=>{if(t){console.error(t.message);const r=e.id??0;s._postMessage({action:p.ValidationError,id:r,message:t.message})}})),this._errorChecking++,this.enableRecording(),e.replacement=t}}}}_requestTexture(e){if(e<0)this._captureTextureRequest.set(e,null);else{const t=this._trackedObjects.get(e),r=t?.deref();r instanceof GPUTexture&&this._captureTextureRequest.set(e,r)}}_updateStatusMessage(){let e='';this._captureTexturedBuffers.length>0&&(e+=`Texture: ${this._captureTexturedBuffers.length} `),this._mappedTextureBufferCount>0&&(e+=`Pending Texture Reads: ${this._mappedTextureBufferCount} `),this._encodingTextureChunkCount>0&&(e+=`Pending Texture Encoding: ${this._encodingTextureChunkCount} `),this._captureBuffersCount&&(e+=`Buffers: ${this._captureBuffersCount} `),this._mappedBufferCount>0&&(e+=`Pending Buffer Reads: ${this._mappedBufferCount} `),this._encodingBufferChunkCount>0&&(e+=`Pending Buffer Encoding: ${this._encodingBufferChunkCount} `),e&&(e=`Capturing: ${e} `),this._inspectingStatusFrame&&(this._inspectingStatusText.textContent=e)}_updateFrameRate(e){this._frameRate.add(e),this._frameIndex++,this._inspectingStatusFrame&&(this._inspectingStatusFrame.textContent=`Frame: ${this._frameIndex} : ${this._frameRate.average.toFixed(2)}ms`)}_frameStart(e){let t=0;if(0==this._lastFrameTime?this._lastFrameTime=e:(t=e-this._lastFrameTime,this._postMessage({action:p.DeltaTime,deltaTime:t}),this._lastFrameTime=e,this._frameRate.add(t)),f){const e=f.getItem(b);if(e){try{this._captureData=JSON.parse(e)}catch(e){this._captureData=null}f.removeItem(b)}}if(this._captureData&&(this._captureData.frame<0||this._frameIndex>=this._captureData.frame)&&(this._captureMaxBufferSize=this._captureData.maxBufferSize||262144,this._captureFrameRequest=!0,this._gpuWrapper.recordStacktraces=!0,this._captureData=null,this._captureTimestamps)){if(this.disableRecording(),this._device){this._timestampQuerySet||(this._timestampQuerySet=this._device.createQuerySet({type:'timestamp',count:this._maxTimestamps}),this._timestampBuffer=this._device.createBuffer({size:8*this._maxTimestamps,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}));const e=this._device.createCommandEncoder();e.beginComputePass({timestampWrites:{querySet:this._timestampQuerySet,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1}}).end(),this._device.queue.submit([e.finish()]),this._timestampIndex=2}this.enableRecording()}this._frameData.length=0,this._captureFrameCommands.length=0,this._frameRenderPassCount=0,this._frameIndex++,this._frameCommandCount=0,this._inspectingStatusFrame&&(this._inspectingStatusFrame.textContent=`Frame: ${this._frameIndex} : ${this._frameRate.average.toFixed(2)}ms`)}_frameEnd(e){if(this._captureFrameCommands.length){const e=2e3,t=Math.ceil(this._captureFrameCommands.length/e);this._postMessage({action:p.CaptureFrameResults,frame:this._frameIndex,count:this._captureFrameCommands.length,batches:t});for(let t=0;t{const i=r.call(e,s,o);return i instanceof GPUCanvasContext&&(t._wrapObject(i),t._trackObject(i.__id,i)),i}}_wrapObject(e,t){if(e&&void 0===e.__id){if(e.__id=t??this.getNextId(e),this._garbageCollectionRegistry.register(e,e.__id),void 0!==e.label){const t=e.label;e._label=t;const r=this;Object.defineProperty(e,'label',{enumerable:!0,configurable:!0,get(){return this._label},set(e){if(e!==this._label){this._label=e;const t=this.__id;r._postMessage({action:p.ObjectSetLabel,id:t,label:e})}}})}e instanceof GPUDevice&&void 0===e.queue.__id&&this._wrapObject(e.queue)}}_gpuToArray(e){const t=[];if(e)for(const r of e)t.push(r);return t}_gpuToObject(e){const t={};if(e)for(const r in e)t[r]=e[r];return t}_stringifyDescriptor(e){const t=this._duplicateObject(e,!0)??{};let r=null;try{r=JSON.stringify(t)}catch(e){console.log(e.message)}return r}_sendAddObjectMessage(e,t,r,s,o,i){this._postMessage({action:p.AddObject,id:e,parent:t,type:r,descriptor:s,stacktrace:o,pending:i})}_recordCommand(e,t,r,s,o){const i=e?.__id??0;if('destroy'===t){e===this._device&&(this._device=null);const t=e.__id;e.__destroyed=!0,t>0&&(this._trackedObjects.delete(t),this._trackedObjectInfo.delete(t),this._objectReplacementMap.delete(t)),e instanceof GPUBindGroup&&this._bindGroupCount--,t>=0&&(this._captureTextureRequest.delete(t),this._postMessage({action:p.DeleteObject,id:t}))}else if('createShaderModule'===t){const e=r.__id;s[0].__replacement||this._sendAddObjectMessage(e,i,'ShaderModule',this._stringifyDescriptor(s[0]),o)}else if('createBuffer'===t){const e=r.__id;this._sendAddObjectMessage(e,i,'Buffer',this._stringifyDescriptor(s[0]),o)}else if('createTexture'===t){const t=r.__id;this._sendAddObjectMessage(t,i,'Texture',this._stringifyDescriptor(s[0]),o),r.__device=e}else if('getCurrentTexture'===t){const e=r.__id;if(r){const t={size:[r.width,r.height,r.depthOrArrayLayers],mipLevelCount:r.mipLevelCount,sampleCount:r.sampleCount,dimension:r.dimension,format:r.format,usage:r.usage},s=JSON.stringify(t);this._sendAddObjectMessage(e,i,'Texture',s,o)}}else if('createView'===t){const t=r.__id;r.__texture=e,this._sendAddObjectMessage(t,i,'TextureView',this._stringifyDescriptor(s[0]),o)}else if('createSampler'===t){const e=r.__id;this._sendAddObjectMessage(e,i,'Sampler',this._stringifyDescriptor(s[0]),o)}else if('createBindGroup'===t){this._bindGroupCount++;const e=r.__id;r.__descriptor=s[0],this._sendAddObjectMessage(e,i,'BindGroup',this._stringifyDescriptor(s[0]),o)}else if('createBindGroupLayout'===t){const e=r.__id;r.__descriptor=s[0],this._sendAddObjectMessage(e,i,'BindGroupLayout',this._stringifyDescriptor(s[0]),o)}else if('createPipelineLayout'===t){const e=r.__id;this._sendAddObjectMessage(e,i,'PipelineLayout',this._stringifyDescriptor(s[0]),o)}else if('createRenderPipeline'===t){const e=r.__id;s[0].__replacement||(this._sendAddObjectMessage(e,i,'RenderPipeline',this._stringifyDescriptor(s[0]),o),s[0].vertex?.module&&(r.__vertexModule=s[0].vertex?.module),s[0].fragment?.module&&(r.__fragmentModule=s[0].fragment?.module))}else if('createComputePipeline'===t){const e=r.__id;s[0].__replacement||(this._sendAddObjectMessage(e,i,'ComputePipeline',this._stringifyDescriptor(s[0]),o),s[0].compute?.module&&(r.__computeModule=s[0].compute?.module))}else'createCommandEncoder'===t&&(r.__device=e);this._captureFrameRequest&&this._captureCommand(e,t,s,o,r)}_captureCommand(e,t,r,s,o){const i=this._captureFrameCommands.length,n=r;1===n.length&&void 0===n[0]&&(n.length=0),('beginRenderPass'===t||'beginComputePass'===t||'createCommandEncoder'===t||'finish'===t)&&(o.__id=`_${i}`);let a=null;if('setBindGroup'===t){a=[];const t=n[0],r=n[1];if(a.push(t),a.push(r),n.length>2&&n[2]?.length){const e=n[2];if(e.length>0)if(e instanceof Uint32Array){const t=n[3],r=n[4];if(r>0){const s=new Uint32Array(e.buffer,4*t,r);a.push(s)}}else a.push(e)}const s=a.length>2?a[2]:null;let o=0;const c=r.__descriptor,p=c.layout?.__descriptor;if(c)for(const t in c.entries){const r=c.entries[t],n=p?.entries[t],a=r?.resource?.buffer,d=n?.buffer?.hasDynamicOffset??!1;if(a){let n=r.resource.offset??0;const c=m(r.resource.size??a.size-n,4);c3){const e=n[3]??0,t=n[4],s=r instanceof ArrayBuffer?r:r.buffer;s&&(t>0?r=new Uint8Array(s,e,t):e>0&&(r=new Uint8Array(s,e)))}a.push(r)}else a=n;if(a=this._processCommandArgs(a),this._captureFrameCommands.push({class:e.constructor.name,object:e.__id,result:o?.__id??0,commandId:i,method:t,args:a,stacktrace:s}),'setIndexBuffer'===t&&(e.__indexBuffer=r),'setVertexBuffer'===t){const t=r[0],s=r[1],o=r[2]??0,n=r[3]??s.size-o;e.__captureBuffers||(e.__captureBuffers=[]),e.__captureBuffers.push({commandId:i,entryIndex:t,buffer:s,offset:o,size:n}),this._captureBuffersCount++,this._updateStatusMessage()}if('setIndexBuffer'===t){const t=r[0],s=t.size;e.__captureBuffers||(e.__captureBuffers=[]),e.__captureBuffers.push({commandId:i,entryIndex:0,buffer:t,offset:0,size:s}),this._captureBuffersCount++,this._updateStatusMessage()}if('drawIndirect'===t||'drawIndexedIndirect'===t||'dispatchWorkgroupsIndirect'===t){const t=r[0],s=0,o=t.size;e.__captureBuffers||(e.__captureBuffers=[]),e.__captureBuffers.push({commandId:i,entryIndex:0,buffer:t,offset:s,size:o}),this._captureBuffersCount++,this._updateStatusMessage()}if('beginRenderPass'===t){if(r[0]?.colorAttachments?.length>0){o.__captureTextureViews=new Set;for(const e of r[0].colorAttachments){if(!e)continue;const t=e.resolveTarget??e.view;o.__captureTextureViews.add(t)}}if(o.__descriptor=r[0],r[0]?.depthStencilAttachment){o.__captureTextureViews||(o.__captureTextureViews=new Set);const e=r[0].depthStencilAttachment,t=e.resolveTarget??e.view;o.__captureTextureViews.add(t)}this._inComputePass=!1,o.__commandEncoder=e}else if('beginComputePass'===t)o.__commandEncoder=e,this._inComputePass=!0;else if('end'===t){this._inComputePass=!1;const t=e.__commandEncoder;if(e.__captureBuffers?.length>0&&(this._recordCaptureBuffers(t,e.__captureBuffers),this._updateStatusMessage()),e.__captureTextureViews?.size>0){let r=10*this._frameRenderPassCount;for(const s of e.__captureTextureViews){const e=s.__texture;e&&this._captureTextureBuffer(t?.__device,t,e,r++)}e.__captureTextureViews.clear()}e.__commandEncoder=null,e instanceof GPURenderPassEncoder&&this._frameRenderPassCount++}}_sendCaptureTextureBuffers(e){const t=[];for(const r of e)t.push(r.id);let r=0;for(const t of e){const e=t.tempBuffer.size;r+=Math.ceil(e/y)}this._postMessage({action:p.CaptureTextureFrames,chunkCount:r,count:e.length,textures:t});for(const t of e){const{id:e,tempBuffer:r,passId:s}=t;this._mappedTextureBufferCount++;const o=this;r.mapAsync(GPUMapMode.READ).then((()=>{o._mappedTextureBufferCount--,o._updateStatusMessage();const t=r.getMappedRange(),i=new Uint8Array(t);o._sendTextureData(e,s,i),r.destroy()})).catch((e=>{console.error(e)}))}this._updateStatusMessage()}_sendTextureData(e,r,s){const o=s.length,i=Math.ceil(o/y),n=this;for(let a=0;a{n._postMessage({action:p.CaptureTextureData,id:e,passId:r,offset:c,size:o,index:a,count:i,chunk:t}),n._encodingTextureChunkCount--,n._updateStatusMessage()})).catch((e=>{console.log('Error encoding texture data:',e)}))}}_getTextureUtils(e){return e?(e.__textureUtils||(e.__textureUtils=new c(e)),e.__textureUtils):null}_sendBufferData(e,r,s){const o=s.length,i=Math.ceil(o/y),n=this;for(let a=0;a{n._postMessage({action:p.CaptureBufferData,commandId:e,entryIndex:r,offset:c,size:o,index:a,count:i,chunk:t}),n._encodingBufferChunkCount--,n._updateStatusMessage()})).catch((e=>{console.error(e.message)}))}}_sendTimestampBuffer(e,t){const r=this;t.mapAsync(GPUMapMode.READ).then((()=>{const e=t.getMappedRange(),s=new Uint8Array(e);r._sendBufferData(-1e3,-1e3,s),t.destroy()})).catch((e=>{console.error(e)}))}_sendCapturedBuffers(e){if(e.length>0){let t=0;for(const r of e){const e=r.tempBuffer.size;t+=Math.ceil(e/y)}this._postMessage({action:p.CaptureBuffers,count:e.length,chunkCount:t})}e.length;for(const t of e){const e=t.tempBuffer,r=t.commandId,s=t.entryIndex,o=this;this._mappedBufferCount++,this._updateStatusMessage(),e.mapAsync(GPUMapMode.READ).then((()=>{o._mappedBufferCount--,o._updateStatusMessage();const t=e.getMappedRange(),i=new Uint8Array(t);o._sendBufferData(r,s,i),e.destroy()})).catch((e=>{console.error(e)}))}}_recordCaptureBuffers(e,t){const r=e?.__device;if(!r)return this._captureBuffersCount-=t.length,void(t.length=0);for(const s of t){const{commandId:t,entryIndex:o,buffer:i,offset:n,size:a}=s;if(i.__destroyed)continue;let c=null;this.disableRecording();try{c=r.createBuffer({size:a,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,label:`BUFFER CAPTURE TEMP [${t},${o}]`}),e.copyBufferToBuffer(i,n,c,0,a),this._captureTempBuffers.push({commandId:t,entryIndex:o,tempBuffer:c})}catch(e){console.log(e)}this.enableRecording()}this._captureBuffersCount-=t.length,t.length=0}_captureTextureBuffer(e,t,r,s){if(!e)return;const o=!t;t??=e.createCommandEncoder(),s??=-1;const i=r.__id;let n=r.format,c=n?a[n]:void 0;if(!c)return;if(c.isDepthStencil){this.disableRecording();try{r=this._getTextureUtils(e).copyDepthTexture(r,'r32float',t)}catch(e){return this.enableRecording(),void console.log(e)}this.enableRecording(),n=r.format,c=n?a[n]:void 0,r.__id=i,this._toDestroy.push(r)}else if(r.sampleCount>1){this.disableRecording();try{(r=this._getTextureUtils(e).copyMultisampledTexture(r)).__id=i,this._toDestroy.push(r)}catch(e){return this.enableRecording(),void console.log(e)}this.enableRecording()}const p=r.width,d=r.height||1,u=r.depthOrArrayLayers||1,l=p*c.bytesPerBlock+255&-256,h=l*d*u;if(!h)return;const _={width:p,height:d,depthOrArrayLayers:u};let m=null;try{this.disableRecording(),m=e.createBuffer({size:h,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});const s='all';t.copyTextureToBuffer({texture:r,aspect:s},{buffer:m,bytesPerRow:l,rowsPerImage:d},_)}catch(e){console.log(e)}o&&e.queue.submit([t.finish()]),this.enableRecording(),m&&(this._captureTexturedBuffers.push({id:i,tempBuffer:m,width:p,height:d,depthOrArrayLayers:u,format:n,passId:s}),this._updateStatusMessage())}_addCommandData(e){if(this._captureFrameRequest){const t=this._frameData.length;return this._frameData.push(e),t}return-1}_isHTMLImageElement(e){return!!s&&(e instanceof HTMLImageElement||e instanceof HTMLCanvasElement||e instanceof HTMLVideoElement)}_processCommandArgs(e){if(!e||e.constructor===Number||e.constructor===String||e.constructor===Boolean)return e;if(void 0!==e.__id)return{__id:e.__id,__class:e.constructor.name};if(e instanceof ImageBitmap||e instanceof ImageData||e instanceof OffscreenCanvas||e instanceof VideoFrame||this._isHTMLImageElement(e))return`@-1 ${e.constructor.name} ${e.width} ${e.height}`;if(e instanceof Array||void 0!==e.buffer){const t=100;if(e.length>t){return`@${this._addCommandData(e)} ${e.constructor.name} ${e.byteLength}`}const r=[];for(const t in e)r[t]=this._processCommandArgs(e[t]);return r}if(e instanceof ArrayBuffer){return`@${this._addCommandData(e)} ${e.constructor.name} ${e.byteLength}`}if(e instanceof Object){const t={};for(const r in e)t[r]=this._processCommandArgs(e[r]);return t}return e}};const x=Worker;class C{constructor(){this._worker=new x(...arguments),function(e){if(!e.__webgpuInspector){if(e.__webgpuInspector=!0,e.terminate){const t=e.terminate;e.terminate=function(){const r=t.call(e,...arguments);return e.__webgpuInspector=!1,r}}e.addEventListener('message',(e=>{e.data.__webgpuInspector&&window.postMessage(e.data,'*')})),window.addEventListener('message',(t=>{e.__webgpuInspector&&t.data.__webgpuInspector&&!t.data.__webgpuInspectorPage&&e.postMessage(t.data)}))}}(this._worker)}}for(const e in x.prototype)'constructor'!==e&&(C.prototype[e]=function(){return this._worker[e].apply(this._worker,arguments)});Worker=C})(),Object.defineProperty(e,'__esModule',{value:!0})}({}); +!function(e){async function t(e,t='application/octet-stream'){return await new Promise(((r,s)=>{const o=Object.assign(new FileReader,{onload:()=>r(o.result),onerror:()=>s(o.error)});o.readAsDataURL(new File([e],'',{type:t}))}))}class r{constructor(e){this._lastSlotId=0,this.slots=new Map,e&&(this.name=e)}static get enabled(){return 0==r._disableSignals}static get disabled(){return r._disableSignals>0}static disable(){return r._disableSignals++}static enable(e){return e?(r._disableSignals=0,0):r._disableSignals>0?r._disableSignals--:0}static disconnect(e,t,s){for(const o in e){const i=e[o];i.constructor===r&&i.disconnect(t,s)}}static getSignals(e,t){t=t||[];for(const s in e){const o=e[s];o.constructor===r&&t.push(o)}return t}get hasListeners(){return this.slots.size>0}emit(){if(!r.disabled)for(const e of this.slots){const t=e[1][0],s=e[1][1]||t;t&&(t.constructor===r?t.emit.apply(s,arguments):t.apply(s,arguments))}}addListener(e,t){return this.isListening(e,t)?null:(this.slots.set(this._lastSlotId++,[e,t]),this._lastSlotId-1)}isListening(e,t){for(const r of this.slots){const s=r[1];if(e&&!t){if(s[0]===e||s[1]===e)return!0}else if(!e&&t){if(s[1]===t)return!0}else if(s[0]===e&&s[1]===t)return!0}return!1}disconnect(e,t){if(null==e&&null==t)return this.slots.clear(),!0;if(e.constructor===Number){const t=e;return!!this.slots.has(t)&&(this.slots.delete(t),!0)}let r=!1;for(const s of this.slots){const o=s[0],i=s[1];e&&!t?i[0]!==e&&i[1]!==e||(this.slots.delete(o),r=!0):!e&&t?i[1]===t&&(this.slots.delete(o),r=!0):i[0]===e&&i[1]===t&&(this.slots.delete(o),r=!0)}return r}}function s(){if(!Error.captureStackTrace)return'';const e={};if(Error.captureStackTrace(e,s),!e.stack)return'';return e.stack.split('\n').map((e=>e.split('at ')[1])).slice(2).filter((e=>e&&!e.includes('webgpu_inspector.js'))).join('\n')}r._disableSignals=0;const o=new Set([GPUAdapter,GPUDevice,GPUBuffer,GPUTexture,GPUTextureView,GPUSampler,GPUBindGroupLayout,GPUBindGroup,GPUPipelineLayout,GPUShaderModule,GPUComputePipeline,GPURenderPipeline,GPUCommandBuffer,GPUCommandEncoder,GPUComputePassEncoder,GPURenderPassEncoder,GPURenderBundle,GPUQueue,GPUQuerySet,GPUCanvasContext]),i=new Set(['createBuffer','createTexture','createSampler','importExternalTexture','createBindGroupLayout','createPipelineLayout','createBindGroup','createShaderModule','createComputePipeline','createRenderPipeline','createComputePipelineAsync','createRenderPipelineAsync','createCommandEncoder','createRenderBundleEncoder','createQuerySet','createView']);class n{constructor(e){this._idGenerator=e,this.onPreCall=new r,this.onPostCall=new r,this.onPromise=new r,this.onPromiseResolve=new r,this.recordStacktraces=!1,this._skipRecord=0,this._wrapGPUTypes()}_wrapGPUTypes(){GPU.prototype.requestAdapter=this._wrapMethod('requestAdapter',GPU.prototype.requestAdapter),GPU.prototype.getPreferredFormat=this._wrapMethod('getPreferredFormat',GPU.prototype.getPreferredFormat),GPUAdapter.prototype.requestDevice=this._wrapMethod('requestDevice',GPUAdapter.prototype.requestDevice),GPUDevice.prototype.destroy=this._wrapMethod('destroy',GPUDevice.prototype.destroy),GPUDevice.prototype.createBuffer=this._wrapMethod('createBuffer',GPUDevice.prototype.createBuffer),GPUDevice.prototype.createTexture=this._wrapMethod('createTexture',GPUDevice.prototype.createTexture),GPUDevice.prototype.createSampler=this._wrapMethod('createSampler',GPUDevice.prototype.createSampler),GPUDevice.prototype.importExternalTexture=this._wrapMethod('importExternalTexture',GPUDevice.prototype.importExternalTexture),GPUDevice.prototype.createBindGroupLayout=this._wrapMethod('createBindGroupLayout',GPUDevice.prototype.createBindGroupLayout),GPUDevice.prototype.createPipelineLayout=this._wrapMethod('createPipelineLayout',GPUDevice.prototype.createPipelineLayout),GPUDevice.prototype.createBindGroup=this._wrapMethod('createBindGroup',GPUDevice.prototype.createBindGroup),GPUDevice.prototype.createShaderModule=this._wrapMethod('createShaderModule',GPUDevice.prototype.createShaderModule),GPUDevice.prototype.createComputePipeline=this._wrapMethod('createComputePipeline',GPUDevice.prototype.createComputePipeline),GPUDevice.prototype.createRenderPipeline=this._wrapMethod('createRenderPipeline',GPUDevice.prototype.createRenderPipeline),GPUDevice.prototype.createComputePipelineAsync=this._wrapMethod('createComputePipelineAsync',GPUDevice.prototype.createComputePipelineAsync),GPUDevice.prototype.createRenderPipelineAsync=this._wrapMethod('createRenderPipelineAsync',GPUDevice.prototype.createRenderPipelineAsync),GPUDevice.prototype.createCommandEncoder=this._wrapMethod('createCommandEncoder',GPUDevice.prototype.createCommandEncoder),GPUDevice.prototype.createRenderBundleEncoder=this._wrapMethod('createRenderBundleEncoder',GPUDevice.prototype.createRenderBundleEncoder),GPUDevice.prototype.createQuerySet=this._wrapMethod('createQuerySet',GPUDevice.prototype.createQuerySet),GPUBuffer.prototype.mapAsync=this._wrapMethod('mapAsync',GPUBuffer.prototype.mapAsync),GPUBuffer.prototype.getMappedRange=this._wrapMethod('getMappedRange',GPUBuffer.prototype.getMappedRange),GPUBuffer.prototype.unmap=this._wrapMethod('unmap',GPUBuffer.prototype.unmap),GPUBuffer.prototype.destroy=this._wrapMethod('destroy',GPUBuffer.prototype.destroy),GPUTexture.prototype.createView=this._wrapMethod('createView',GPUTexture.prototype.createView),GPUTexture.prototype.destroy=this._wrapMethod('destroy',GPUTexture.prototype.destroy),GPUShaderModule.prototype.getCompilationInfo=this._wrapMethod('getCompilationInfo',GPUShaderModule.prototype.getCompilationInfo),GPUComputePipeline.prototype.getBindGroupLayout=this._wrapMethod('getBindGroupLayout',GPUComputePipeline.prototype.getBindGroupLayout),GPURenderPipeline.prototype.getBindGroupLayout=this._wrapMethod('getBindGroupLayout',GPURenderPipeline.prototype.getBindGroupLayout),GPUCommandEncoder.prototype.beginRenderPass=this._wrapMethod('beginRenderPass',GPUCommandEncoder.prototype.beginRenderPass),GPUCommandEncoder.prototype.beginComputePass=this._wrapMethod('beginComputePass',GPUCommandEncoder.prototype.beginComputePass),GPUCommandEncoder.prototype.copyBufferToBuffer=this._wrapMethod('copyBufferToBuffer',GPUCommandEncoder.prototype.copyBufferToBuffer),GPUCommandEncoder.prototype.copyBufferToTexture=this._wrapMethod('copyBufferToTexture',GPUCommandEncoder.prototype.copyBufferToTexture),GPUCommandEncoder.prototype.copyTextureToBuffer=this._wrapMethod('copyTextureToBuffer',GPUCommandEncoder.prototype.copyTextureToBuffer),GPUCommandEncoder.prototype.copyTextureToTexture=this._wrapMethod('copyTextureToTexture',GPUCommandEncoder.prototype.copyTextureToTexture),GPUCommandEncoder.prototype.clearBuffer=this._wrapMethod('clearBuffer',GPUCommandEncoder.prototype.clearBuffer),GPUCommandEncoder.prototype.resolveQuerySet=this._wrapMethod('resolveQuerySet',GPUCommandEncoder.prototype.resolveQuerySet),GPUCommandEncoder.prototype.finish=this._wrapMethod('finish',GPUCommandEncoder.prototype.finish),GPUCommandEncoder.prototype.pushDebugGroup=this._wrapMethod('pushDebugGroup',GPUCommandEncoder.prototype.pushDebugGroup),GPUCommandEncoder.prototype.popDebugGroup=this._wrapMethod('popDebugGroup',GPUCommandEncoder.prototype.popDebugGroup),GPUCommandEncoder.prototype.insertDebugMarker=this._wrapMethod('insertDebugMarker',GPUCommandEncoder.prototype.insertDebugMarker),GPUComputePassEncoder.prototype.setPipeline=this._wrapMethod('setPipeline',GPUComputePassEncoder.prototype.setPipeline),GPUComputePassEncoder.prototype.dispatchWorkgroups=this._wrapMethod('dispatchWorkgroups',GPUComputePassEncoder.prototype.dispatchWorkgroups),GPUComputePassEncoder.prototype.dispatchWorkgroupsIndirect=this._wrapMethod('dispatchWorkgroupsIndirect',GPUComputePassEncoder.prototype.dispatchWorkgroupsIndirect),GPUComputePassEncoder.prototype.end=this._wrapMethod('end',GPUComputePassEncoder.prototype.end),GPUComputePassEncoder.prototype.setBindGroup=this._wrapMethod('setBindGroup',GPUComputePassEncoder.prototype.setBindGroup),GPUComputePassEncoder.prototype.setBindGroup=this._wrapMethod('setBindGroup',GPUComputePassEncoder.prototype.setBindGroup),GPUComputePassEncoder.prototype.pushDebugGroup=this._wrapMethod('pushDebugGroup',GPUComputePassEncoder.prototype.pushDebugGroup),GPUComputePassEncoder.prototype.popDebugGroup=this._wrapMethod('popDebugGroup',GPUComputePassEncoder.prototype.popDebugGroup),GPUComputePassEncoder.prototype.insertDebugMarker=this._wrapMethod('insertDebugMarker',GPUComputePassEncoder.prototype.insertDebugMarker),GPURenderPassEncoder.prototype.setViewport=this._wrapMethod('setViewport',GPURenderPassEncoder.prototype.setViewport),GPURenderPassEncoder.prototype.setScissorRect=this._wrapMethod('setScissorRect',GPURenderPassEncoder.prototype.setScissorRect),GPURenderPassEncoder.prototype.setBlendConstant=this._wrapMethod('setBlendConstant',GPURenderPassEncoder.prototype.setBlendConstant),GPURenderPassEncoder.prototype.setStencilReference=this._wrapMethod('setStencilReference',GPURenderPassEncoder.prototype.setStencilReference),GPURenderPassEncoder.prototype.beginOcclusionQuery=this._wrapMethod('beginOcclusionQuery',GPURenderPassEncoder.prototype.beginOcclusionQuery),GPURenderPassEncoder.prototype.endOcclusionQuery=this._wrapMethod('endOcclusionQuery',GPURenderPassEncoder.prototype.endOcclusionQuery),GPURenderPassEncoder.prototype.executeBundles=this._wrapMethod('executeBundles',GPURenderPassEncoder.prototype.executeBundles),GPURenderPassEncoder.prototype.end=this._wrapMethod('end',GPURenderPassEncoder.prototype.end),GPURenderPassEncoder.prototype.setPipeline=this._wrapMethod('setPipeline',GPURenderPassEncoder.prototype.setPipeline),GPURenderPassEncoder.prototype.setIndexBuffer=this._wrapMethod('setIndexBuffer',GPURenderPassEncoder.prototype.setIndexBuffer),GPURenderPassEncoder.prototype.setVertexBuffer=this._wrapMethod('setVertexBuffer',GPURenderPassEncoder.prototype.setVertexBuffer),GPURenderPassEncoder.prototype.draw=this._wrapMethod('draw',GPURenderPassEncoder.prototype.draw),GPURenderPassEncoder.prototype.drawIndexed=this._wrapMethod('drawIndexed',GPURenderPassEncoder.prototype.drawIndexed),GPURenderPassEncoder.prototype.drawIndirect=this._wrapMethod('drawIndirect',GPURenderPassEncoder.prototype.drawIndirect),GPURenderPassEncoder.prototype.drawIndexedIndirect=this._wrapMethod('drawIndexedIndirect',GPURenderPassEncoder.prototype.drawIndexedIndirect),GPURenderPassEncoder.prototype.setBindGroup=this._wrapMethod('setBindGroup',GPURenderPassEncoder.prototype.setBindGroup),GPURenderPassEncoder.prototype.pushDebugGroup=this._wrapMethod('pushDebugGroup',GPURenderPassEncoder.prototype.pushDebugGroup),GPURenderPassEncoder.prototype.popDebugGroup=this._wrapMethod('popDebugGroup',GPURenderPassEncoder.prototype.popDebugGroup),GPURenderPassEncoder.prototype.insertDebugMarker=this._wrapMethod('insertDebugMarker',GPURenderPassEncoder.prototype.insertDebugMarker),GPUQueue.prototype.submit=this._wrapMethod('submit',GPUQueue.prototype.submit),GPUQueue.prototype.writeBuffer=this._wrapMethod('writeBuffer',GPUQueue.prototype.writeBuffer),GPUQueue.prototype.writeTexture=this._wrapMethod('writeTexture',GPUQueue.prototype.writeTexture),GPUQueue.prototype.copyExternalImageToTexture=this._wrapMethod('copyExternalImageToTexture',GPUQueue.prototype.copyExternalImageToTexture),GPUQuerySet.prototype.destroy=this._wrapMethod('destroy',GPUQuerySet.prototype.destroy),GPUCanvasContext.prototype.configure=this._wrapMethod('configure',GPUCanvasContext.prototype.configure),GPUCanvasContext.prototype.unconfigure=this._wrapMethod('unconfigure',GPUCanvasContext.prototype.unconfigure),GPUCanvasContext.prototype.getCurrentTexture=this._wrapMethod('getCurrentTexture',GPUCanvasContext.prototype.getCurrentTexture)}disableRecording(){this._skipRecord++}enableRecording(){this._skipRecord--,this._skipRecord<0&&(this._skipRecord=0)}get isRecordingEnabled(){return 0===this._skipRecord}_wrapMethod(e,t){const r=this;return function(){const o=this,n=[...arguments];if(r._skipRecord>0)return t.call(o,...n);r.onPreCall.emit(o,e,n);const a=t.call(o,...n),c=i.has(e),p=r.recordStacktraces||c?s():void 0;if(a instanceof Promise){const t=r._idGenerator.getNextId(o);r.onPromise.emit(o,e,n,t,p);const s=a,i=new Promise((i=>{s.then((s=>{r.onPromiseResolve.emit(o,e,n,t,s,p),i(s)}))}));return i}return r.onPostCall.emit(o,e,n,a,p),a}}}const a={r8unorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8snorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8uint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8sint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg8unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8snorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},'rgba8unorm-srgb':{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8snorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},bgra8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},'bgra8unorm-srgb':{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r16uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16float:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg16uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba16uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r32uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg32uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba32uint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32sint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32float:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rg11b10ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},stencil8:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!1,hasStencil:!0,channels:1},depth16unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},depth24plus:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,depthOnlyFormat:'depth32float',channels:1},'depth24plus-stencil8':{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,depthOnlyFormat:'depth32float',channels:1},depth32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},'depth32float-stencil8':{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,stencilOnlyFormat:'depth32float',channels:1},rgb9e5ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},'bc1-rgba-unorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc1-rgba-unorm-srgb':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc2-rgba-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc2-rgba-unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc3-rgba-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc3-rgba-unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc4-r-unorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},'bc4-r-snorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},'bc5-rg-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},'bc5-rg-snorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},'bc6h-rgb-ufloat':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc6h-rgb-float':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc7-rgba-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc7-rgba-unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgb8unorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgb8unorm-srgb':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgb8a1unorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgb8a1unorm-srgb':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgba8unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgba8unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'eac-r11unorm':{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},'eac-r11snorm':{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},'eac-rg11unorm':{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},'eac-rg11snorm':{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},'astc-4x4-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'astc-4x4-unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'astc-5x4-unorm':{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},'astc-5x4-unorm-srgb':{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},'astc-5x5-unorm':{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},'astc-5x5-unorm-srgb':{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},'astc-6x5-unorm':{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},'astc-6x5-unorm-srgb':{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},'astc-6x6-unorm':{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},'astc-6x6-unorm-srgb':{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},'astc-8x5-unorm':{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},'astc-8x5-unorm-srgb':{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},'astc-8x6-unorm':{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},'astc-8x6-unorm-srgb':{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},'astc-8x8-unorm':{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},'astc-8x8-unorm-srgb':{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},'astc-10x5-unorm':{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},'astc-10x5-unorm-srgb':{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},'astc-10x6-unorm':{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},'astc-10x6-unorm-srgb':{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},'astc-10x8-unorm':{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},'astc-10x8-unorm-srgb':{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},'astc-10x10-unorm':{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},'astc-10x10-unorm-srgb':{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},'astc-12x10-unorm':{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},'astc-12x10-unorm-srgb':{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},'astc-12x12-unorm':{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4},'astc-12x12-unorm-srgb':{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4}};class c{constructor(e){this.device=e,this.blitShaderModule=e.createShaderModule({code:c.blitShader}),this.multisampleBlitShaderModule=e.createShaderModule({code:c.multisampleBlitShader}),this.depthToFloatShaderModule=e.createShaderModule({code:c.depthToFloatShader}),this.depthToFloatMultisampleShaderModule=e.createShaderModule({code:c.depthToFloatMultisampleShader}),this.blitPipelines={},this.blitDepthPipelines={},this.bindGroupLayouts=new Map,this.pipelineLayouts=new Map,this.depthToFloatPipeline=null,this.depthToFloatMSPipeline=null,this.pointSampler=e.createSampler({magFilter:'nearest',minFilter:'nearest'}),this.displayUniformBuffer=e.createBuffer({size:32,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),this.displayBingGroupLayout=e.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,buffer:{type:'uniform'}}]}),this.displayBindGroup=e.createBindGroup({layout:this.displayBingGroupLayout,entries:[{binding:0,resource:{buffer:this.displayUniformBuffer}}]})}copyDepthTexture(e,t,r){const s=e.width,o=e.height,i=e.depthOrArrayLayers,n=e.usage|GPUTextureUsage.RENDER_TARGET|GPUTextureUsage.COPY_SRC,a=[s,o,i];t=t||'r32float';const c=this.device.createTexture({format:t,size:a,usage:n});for(let s=0;s1}}]});this.bindGroupLayouts.set(c,e);const t=this.device.createPipelineLayout({bindGroupLayouts:[e,this.displayBingGroupLayout]});this.pipelineLayouts.set(c,t)}const p=a[t],d=p?.channels??4,u=this.bindGroupLayouts.get(c),l=this.pipelineLayouts.get(c),h=`${o}#${n}#${r}`;let _=this.blitPipelines[h];if(!_){const e=r>1?this.multisampleBlitShaderModule:this.blitShaderModule;_=this.device.createRenderPipeline({layout:l,vertex:{module:e,entryPoint:'vertexMain'},fragment:{module:e,entryPoint:'fragmentMain',targets:[{format:o}]},primitive:{topology:'triangle-list'}}),this.blitPipelines[h]=_}const m=this.device.createBindGroup({layout:u,entries:[{binding:0,resource:this.pointSampler},{binding:1,resource:e}]}),f=this.device.createCommandEncoder(),g={colorAttachments:[{view:s,loadOp:'clear',storeOp:'store'}]};i?this.device.queue.writeBuffer(this.displayUniformBuffer,0,new Float32Array([i.exposure,i.channels,d,i.minRange,i.maxRange,0,0,0])):this.device.queue.writeBuffer(this.displayUniformBuffer,0,new Float32Array([1,0,d,0,1,0,0,0]));const b=f.beginRenderPass(g);b.setPipeline(_),b.setBindGroup(0,m),b.setBindGroup(1,this.displayBindGroup),b.draw(3),b.end(),this.device.queue.submit([f.finish()])}convertDepthToFloat(e,t,r,s,o){if(t>1){if(!this.depthToFloatMSPipeline){this.device.pushErrorScope('validation'),this.depthToFloatBindGroupMSLayout=this.device.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:'depth',multisampled:!0}}]});const e=this.device.createPipelineLayout({bindGroupLayouts:[this.depthToFloatBindGroupMSLayout]}),t=this.depthToFloatMultisampleShaderModule;this.depthToFloatMSPipeline=this.device.createRenderPipeline({layout:e,vertex:{module:t,entryPoint:'vertexMain'},fragment:{module:t,entryPoint:'fragmentMain',targets:[{format:s}]},primitive:{topology:'triangle-list'}}),this.device.popErrorScope().then((e=>{e&&console.error(e.message)}))}}else if(!this.depthToFloatPipeline){this.device.pushErrorScope('validation'),this.depthToFloatBindGroupLayout=this.device.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:'depth'}}]});const e=this.device.createPipelineLayout({bindGroupLayouts:[this.depthToFloatBindGroupLayout]}),t=this.depthToFloatShaderModule;this.depthToFloatPipeline=this.device.createRenderPipeline({layout:e,vertex:{module:t,entryPoint:'vertexMain'},fragment:{module:t,entryPoint:'fragmentMain',targets:[{format:s}]},primitive:{topology:'triangle-list'}}),this.device.popErrorScope().then((e=>{e&&console.error(e.message)}))}this.device.pushErrorScope('validation');const i=this.device.createBindGroup({layout:t>1?this.depthToFloatBindGroupMSLayout:this.depthToFloatBindGroupLayout,entries:[{binding:0,resource:e}]}),n=!o;o??=this.device.createCommandEncoder();const a=o.beginRenderPass({colorAttachments:[{view:r,loadOp:'clear',storeOp:'store',clearColor:{r:0,g:0,b:0,a:0}}]});a.setPipeline(t>1?this.depthToFloatMSPipeline:this.depthToFloatPipeline),a.setBindGroup(0,i),a.draw(3),a.end(),n&&this.device.queue.submit([o.finish()]),this.device.popErrorScope().then((e=>{e&&console.error(e.message)}))}}c.blitShader='\n var posTex:array = array(\n vec4f(-1.0, 1.0, 0.0, 0.0),\n vec4f(3.0, 1.0, 2.0, 0.0),\n vec4f(-1.0, -3.0, 0.0, 2.0));\n struct VertexOutput {\n @builtin(position) position: vec4f,\n @location(0) uv: vec2f\n };\n @vertex\n fn vertexMain(@builtin(vertex_index) vertexIndex: u32) -> VertexOutput {\n var output: VertexOutput;\n output.uv = posTex[vertexIndex].zw;\n output.position = vec4f(posTex[vertexIndex].xy, 0.0, 1.0);\n return output;;\n }\n @group(0) @binding(0) var texSampler: sampler;\n @group(0) @binding(1) var texture: texture_2d;\n struct Display {\n exposure: f32,\n channels: f32,\n numChannels: f32,\n minRange: f32,\n maxRange: f32,\n _pad1: f32,\n _pad2: f32,\n _pad3: f32\n };\n @group(1) @binding(0) var display: Display; \n @fragment\n fn fragmentMain(input: VertexOutput) -> @location(0) vec4f {\n var color = textureSample(texture, texSampler, input.uv);\n\n if (display.numChannels == 1.0) {\n if (display.minRange != display.maxRange) {\n if (color.r < display.minRange) {\n color = vec4f(0.0, 0.0, 0.0, 1);\n } else if (color.r > display.maxRange) {\n color = vec4f(1.0, 0.0, 0.0, 1);\n } else {\n color = vec4f((color.r - display.minRange) / (display.maxRange - display.minRange), 0.0, 0.0, 1);\n }\n }\n color = vec4f(color.r, color.r, color.r, 1.0);\n } else if (display.numChannels == 2.0) {\n color = vec4f(color.r, color.g, 0.0, 1.0);\n }\n\n if (display.channels == 1.0) { // R\n var rgb = color.rgb * display.exposure;\n return vec4f(rgb.r, 0.0, 0.0, 1);\n } else if (display.channels == 2.0) { // G\n var rgb = color.rgb * display.exposure;\n return vec4f(0.0, rgb.g, 0.0, 1);\n } else if (display.channels == 3.0) { // B\n var rgb = color.rgb * display.exposure;\n return vec4f(0.0, 0.0, rgb.b, 1);\n } else if (display.channels == 4.0) { // A\n var a = color.a * display.exposure;\n return vec4f(a, a, a, 1);\n } else if (display.channels == 5.0) { // Luminance\n var luminance = dot(color.rgb, vec3f(0.2126, 0.7152, 0.0722));\n var rgb = vec3f(luminance) * display.exposure;\n return vec4f(rgb, 1);\n }\n\n // RGB\n var rgb = color.rgb * display.exposure;\n return vec4f(rgb, 1);\n }\n',c.multisampleBlitShader='\n var posTex:array = array(\n vec4f(-1.0, 1.0, 0.0, 0.0),\n vec4f(3.0, 1.0, 2.0, 0.0),\n vec4f(-1.0, -3.0, 0.0, 2.0));\n struct VertexOutput {\n @builtin(position) position: vec4f,\n @location(0) uv: vec2f\n };\n @vertex\n fn vertexMain(@builtin(vertex_index) vertexIndex: u32) -> VertexOutput {\n var output: VertexOutput;\n output.uv = posTex[vertexIndex].zw;\n output.position = vec4f(posTex[vertexIndex].xy, 0.0, 1.0);\n return output;;\n }\n @group(0) @binding(0) var texSampler: sampler;\n @group(0) @binding(1) var texture: texture_multisampled_2d;\n struct Display {\n exposure: f32,\n channels: f32,\n numChannels: f32,\n minRange: f32,\n maxRange: f32,\n _pad1: f32,\n _pad2: f32,\n _pad3: f32\n };\n @group(1) @binding(0) var display: Display; \n @fragment\n fn fragmentMain(input: VertexOutput) -> @location(0) vec4f {\n var coords = vec2i(input.uv * vec2f(textureDimensions(texture)));\n var color = textureLoad(texture, coords, 0);\n if (display.numChannels == 1.0) {\n if (display.minRange != display.maxRange) {\n if (color.r < display.minRange) {\n color = vec4f(0.0, 0.0, 0.0, color.a);\n } else if (color.r > display.maxRange) {\n color = vec4f(1.0, 1.0, 1.0, color.a);\n } else {\n color = vec4f((color.r - display.minRange) / (display.maxRange - display.minRange), 0.0, 0.0, color.a);\n }\n }\n color = vec4f(color.r, color.r, color.r, 1.0);\n } else if (display.numChannels == 2.0) {\n color = vec4f(color.r, color.g, 0.0, 1.0);\n }\n if (display.channels == 1.0) { // R\n var rgb = color.rgb * display.exposure;\n return vec4f(rgb.r, 0.0, 0.0, color.a);\n } else if (display.channels == 2.0) { // G\n var rgb = color.rgb * display.exposure;\n return vec4f(0.0, rgb.g, 0.0, color.a);\n } else if (display.channels == 3.0) { // B\n var rgb = color.rgb * display.exposure;\n return vec4f(0.0, 0.0, rgb.b, color.a);\n } else if (display.channels == 4.0) { // A\n var a = color.a * display.exposure;\n return vec4f(a, a, a, color.a);\n } else if (display.channels == 5.0) { // Luminance\n var luminance = dot(color.rgb, vec3f(0.2126, 0.7152, 0.0722));\n var rgb = vec3f(luminance) * display.exposure;\n return vec4f(rgb, color.a);\n }\n\n // RGB\n var rgb = color.rgb * display.exposure;\n return vec4f(rgb, color.a);\n }',c.depthToFloatShader='\n var posTex:array = array(\n vec4f(-1.0, 1.0, 0.0, 0.0),\n vec4f(3.0, 1.0, 2.0, 0.0),\n vec4f(-1.0, -3.0, 0.0, 2.0));\n struct VertexOutput {\n @builtin(position) position: vec4,\n @location(0) uv : vec2\n };\n @vertex\n fn vertexMain(@builtin(vertex_index) vertexIndex: u32) -> VertexOutput {\n var output: VertexOutput;\n output.uv = posTex[vertexIndex].zw;\n output.position = vec4f(posTex[vertexIndex].xy, 0.0, 1.0);\n return output;;\n }\n \n @binding(0) @group(0) var depth: texture_depth_2d;\n @fragment\n fn fragmentMain(input: VertexOutput) -> @location(0) vec4 {\n var depthSize = textureDimensions(depth);\n var coords = vec2(i32(f32(depthSize.x) * input.uv.x),\n i32(f32(depthSize.y) * input.uv.y));\n var d = textureLoad(depth, coords, 0);\n return vec4(d, 0.0, 0.0, 1.0);\n }',c.depthToFloatMultisampleShader='\n var posTex:array = array(\n vec4f(-1.0, 1.0, 0.0, 0.0),\n vec4f(3.0, 1.0, 2.0, 0.0),\n vec4f(-1.0, -3.0, 0.0, 2.0));\n struct VertexOutput {\n @builtin(position) position: vec4,\n @location(0) uv : vec2\n };\n @vertex\n fn vertexMain(@builtin(vertex_index) vertexIndex: u32) -> VertexOutput {\n var output: VertexOutput;\n output.uv = posTex[vertexIndex].zw;\n output.position = vec4f(posTex[vertexIndex].xy, 0.0, 1.0);\n return output;;\n }\n \n @binding(0) @group(0) var depth: texture_depth_multisampled_2d;\n @fragment\n fn fragmentMain(input: VertexOutput) -> @location(0) vec4 {\n var depthSize = textureDimensions(depth);\n var coords = vec2(i32(f32(depthSize.x) * input.uv.x),\n i32(f32(depthSize.y) * input.uv.y));\n var d = textureLoad(depth, coords, 0);\n return vec4(d, 0.0, 0.0, 1.0);\n }';const p={CaptureBufferData:'webgpu_inspect_capture_buffer_data',CaptureBuffers:'webgpu_inspect_capture_buffers',DeleteObjects:'webgpu_inspect_delete_objects',ValidationError:'webgpu_inspect_validation_error',MemoryLeakWarning:'webgpu_inspect_memory_leak_warning',DeltaTime:'webgpu_inspect_delta_time',CaptureFrameResults:'webgpu_inspect_capture_frame_results',CaptureFrameCommands:'webgpu_inspect_capture_frame_commands',ObjectSetLabel:'webgpu_inspect_object_set_label',AddObject:'webgpu_inspect_add_object',ResolveAsyncObject:'webgpu_inspect_resolve_async_object',DeleteObject:'webgpu_inspect_delete_object',CaptureTextureFrames:'webgpu_inspect_capture_texture_frames',CaptureTextureData:'webgpu_inspect_capture_texture_data',CaptureBufferData:'webgpu_inspect_capture_buffer_data',Recording:'webgpu_record_recording',RecordingCommand:'webgpu_record_command',RecordingDataCount:'webgpu_record_data_count',RecordingData:'webgpu_record_data'};p.values=new Set(Object.values(p));const d='webgpu_inspect_request_texture',u='webgpu_inspect_compile_shader',l='webgpu_inspect_revert_shader',h='webgpu_inspector_capture';class _{constructor(e){this.windowSize=e,this.buffer=[],this.sum=0}add(e){this.buffer.push(e),this.buffer.length>this.windowSize&&(this.sum-=this.buffer.shift()),this.sum+=e}get average(){return 0===this.buffer.length?0:this.sum/this.buffer.length}}function m(e,t){return e+t-1&~(t-1)}e.webgpuInspector=null,(()=>{const r=self,s=self.window,i=self.document,f=self.sessionStorage,g=self.postMessage,b=self.dispatchEvent,y='WEBGPU_INSPECTOR_CAPTURE_FRAME',P=262144;e.webgpuInspector=new class x{constructor(){if(this._captureFrameCommands=[],this._frameData=[],this._frameRenderPassCount=0,this._captureTexturedBuffers=[],this._currentFrame=null,this._frameIndex=0,this._initalized=!0,this._objectID=1,this._lastFrameTime=0,this._frameCommandCount=0,this._captureFrameRequest=!1,this._errorChecking=1,this._trackedObjects=new Map,this._trackedObjectInfo=new Map,this._bindGroupCount=0,this._captureTextureRequest=new Map,this._toDestroy=[],this._objectReplacementMap=new Map,this._captureBuffersCount=0,this._captureTempBuffers=[],this._mappedTextureBufferCount=0,this._encodingTextureChunkCount=0,this._mappedBufferCount=0,this._encodingBufferChunkCount=0,this._captureData=null,this._frameRate=new _(60),this._captureTimestamps=!1,this._timestampQuerySet=null,this._timestampBuffer=null,this._timestampIndex=0,this._maxTimestamps=2e3,!navigator.gpu)return;if(i?.body){const e=i.createElement('div');e.style='position: absolute; z-index: 1000000; margin-left: 10px; margin-top: 5px; padding-left: 5px; padding-right: 10px; background-color: rgba(0, 0, 1, 0.75); border-radius: 5px; box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.5); color: #fff; font-size: 12pt;',i.body.insertBefore(e,i.body.firstChild),this._inspectingStatus=i.createElement('div'),this._inspectingStatus.title='WebGPU Inspector Running',this._inspectingStatus.style='height: 10px; width: 10px; display: inline-block; margin-right: 5px; background-color: #ff0; border-radius: 50%; border: 1px solid #000; box-shadow: inset -4px -4px 4px -3px rgb(255,100,0), 2px 2px 3px rgba(0,0,0,0.8);',e.appendChild(this._inspectingStatus),this._inspectingStatusFrame=i.createElement('div'),this._inspectingStatusFrame.style='display: inline-block;',this._inspectingStatusFrame.textContent='Frame: 0',e.appendChild(this._inspectingStatusFrame),this._inspectingStatusText=i.createElement('div'),this._inspectingStatusText.style='display: inline-block; margin-left: 10px;',e.appendChild(this._inspectingStatusText)}this._gpuWrapper=new n(this);const e=this;this._gpuWrapper.onPromise.addListener(this._onAsyncPromise,this),this._gpuWrapper.onPromiseResolve.addListener(this._onAsyncResolve,this),this._gpuWrapper.onPreCall.addListener(this._preMethodCall,this),this._gpuWrapper.onPostCall.addListener(this._postMethodCall,this),this._garbageCollectectedObjects=[],this._garbageCollectionRegistry=new FinalizationRegistry((t=>{if(t>0){e._garbageCollectectedObjects.push(t);const r=e._trackedObjectInfo.get(t);r&&(r===GPUBindGroup&&e._bindGroupCount--,r!==GPUBuffer&&r!==GPUTexture&&r!==GPUDevice||e._memoryLeakWarning(t,r)),e._garbageCollectectedObjects.length>100&&(e._postMessage({action:p.DeleteObjects,idList:e._garbageCollectectedObjects}),e._garbageCollectectedObjects.length=0)}t>0&&(e._trackedObjects.delete(t),e._trackedObjectInfo.delete(t),e._captureTextureRequest.delete(t),e._objectReplacementMap.delete(t))}));if(setInterval((()=>{e._garbageCollectectedObjects.length>0&&(e._postMessage({action:p.DeleteObjects,idList:e._garbageCollectectedObjects}),e._garbageCollectectedObjects.length=0)}),200),i){const t=i.getElementsByTagName('canvas');for(const e of t)this._wrapCanvas(e);const r=i.createElement;i.createElement=t=>{const s=r.call(i,t);return'canvas'===t&&e._wrapCanvas(s),s}}const t=requestAnimationFrame;function o(t){const r=t.detail||t.data;if('object'==typeof r&&r.__webgpuInspector)if(r.action===p.DeltaTime)r.__webgpuInspectorWorker&&e._updateFrameRate(r.deltaTime);else if(r.action===d){const t=r.id;e._requestTexture(t)}else if(r.action===u){const t=r.id,s=r.code;e._compileShader(t,s)}else if(r.action===l){const t=r.id;e._revertShader(t)}else r.action===h&&null==s&&('String'===r.data.constructor.name&&(r.data=JSON.parse(r.data)),e._captureData=r.data)}this._currentFrameTime=0,requestAnimationFrame=r=>t((function(t){if(!e._currentFrameTime){e._currentFrameTime=t,e._frameStart(t);const s=r(t);s instanceof Promise?Promise.all([s]).then((()=>{e._frameEnd(t),e._currentFrameTime=0})):(e._frameEnd(t),e._currentFrameTime=0)}})),s?r.addEventListener('__WebGPUInspector',o):r.addEventListener('message',o)}captureWorker(e){this._wrapCanvas(e)}disableRecording(){this._gpuWrapper.disableRecording()}enableRecording(){this._gpuWrapper.enableRecording()}_postMessage(e){e.__webgpuInspector=!0,e.__webgpuInspectorPage=!0,e.__webgpuInspectorWorker=!s,s?b(new CustomEvent('__WebGPUInspector',{detail:e})):g(e)}_updateCanvasAttachment(e){let t=null;e.resolveTarget?t=e.resolveTarget:e.view&&(t=e.view);const r=t?.__texture,s=r?.__context;if(!s)return;s.__captureTexture&&(s.__captureTexture.width==r.width&&s.__captureTexture.height==r.height&&s.__captureTexture.format==r.format||(this.disableRecording(),s.__captureTexture.destroy(),s.__captureTexture=null,this.enableRecording()));const o=s.__device;if(o){this.disableRecording();const i=o.createTexture({size:[r.width,r.height,1],format:r.format,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC});if(s.__captureTexture=i,i){i.__id=r.__id,i.__canvasTexture=r,i.__context=s;const o=i.createView();o.__texture=i,o.__canvasView=t,i.__view=o,o.__context=s,e.resolveTarget?e.resolveTarget=o:e.view=o}this.enableRecording()}}_preMethodCall(e,t,r){if('requestDevice'===t&&(0===r.length&&(r[0]={}),r[0].requiredFeatures?r[0].requiredFeatures.push('timestamp-query'):r[0].requiredFeatures=['timestamp-query']),'setPipeline'===t){let e=r[0];const t=this._objectReplacementMap.get(e.__id);t&&t.replacement&&(r[0]=t.replacement)}if('createTexture'===t&&(r[0].usage|=GPUTextureUsage.COPY_SRC|GPUTextureUsage.TEXTURE_BINDING),'createBuffer'===t&&(r[0].usage&GPUBufferUsage.MAP_READ||(r[0].usage|=GPUBufferUsage.COPY_SRC)),'createShaderModule'!==t&&'createRenderPipeline'!==t&&'createComputePipeline'!==t&&'createBindGroup'!==t||this._errorChecking>0&&(this._gpuWrapper.disableRecording(),e.pushErrorScope('validation'),this._gpuWrapper.enableRecording()),'beginRenderPass'!==t&&'beginComputePass'!==t||this._captureTimestamps&&this._captureFrameRequest&&(!this._timestampQuerySet&&e.__device&&(this._timestampQuerySet=e.__device.createQuerySet({type:'timestamp',count:this._maxTimestamps}),this._timestampBuffer=e.__device.createBuffer({size:8*this._maxTimestamps,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC})),!r[0].timestampWrites&&this._timestampIndex0){const r=e.__device.createCommandEncoder();r.resolveQuerySet(this._timestampQuerySet,0,this._timestampIndex,this._timestampBuffer,0),t=e.__device.createBuffer({size:8*this._timestampIndex,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),t.__count=this._timestampIndex,r.copyBufferToBuffer(this._timestampBuffer,0,t,0,8*this._timestampIndex),e.__device.queue.submit([r.finish()]),this._timestampIndex=0}const s=this;if(this._captureTextureRequest.size>0){const t=r[0];let o=!1;for(const e of t)o|=!!e.__rendersToCanvas;this._captureTextureRequest.forEach(((t,r)=>{(r>0||o)&&(t=t||s._trackedObjects.get(r)?.deref(),s._captureTextureBuffer(e.__device,null,t),s._captureTextureRequest.delete(r))}))}const o=[...this._captureTempBuffers];this._captureTempBuffers.length=0;const i=[...this._captureTexturedBuffers];this._captureTexturedBuffers.length=0;const n=[...this._toDestroy];this._toDestroy.length=0,e.onSubmittedWorkDone().then((async()=>{s.disableRecording(),t&&s._sendTimestampBuffer(t.__count,t),o.length&&s._sendCapturedBuffers(o),i.length&&s._sendCaptureTextureBuffers(i);for(const e of n)e.destroy();s.enableRecording()})),this.enableRecording()}let n;if('createShaderModule'!==t&&'createRenderPipeline'!==t&&'createComputePipeline'!==t&&'createBindGroup'!==t||this._errorChecking>0&&(this.disableRecording(),e.popErrorScope().then((e=>{if(e){console.error(e.message);const t=s?.__id??0;self._postMessage({action:p.ValidationError,id:t,message:e.message,stacktrace:i})}})),this.enableRecording()),'getCurrentTexture'===t?(e.__id||(this._wrapObject(e),this._trackObject(e.__id,e)),n=-e.__id,e.__canvasTexture=new WeakRef(s),s.__frameIndex=this._frameIndex):'createView'===t&&e.__id<0&&(n=e.__id-.5),e instanceof GPUDevice&&void 0===e?.__id&&(this._wrapDevice(null,e),e.__adapter||navigator.gpu.requestAdapter().then((t=>{e.__adapter=t}))),s)if(o.has(s.constructor)&&this._wrapObject(s,n),'createShaderModule'===t||'createRenderPipeline'===t)s.__descriptor=r[0],s.__device=e,this._objectReplacementMap.set(s.__id,{id:s.__id,object:new WeakRef(s),replacement:null});else if('getCurrentTexture'===t)s.__context=e,this._trackObject(s.__id,s),s.label='CanvasTexture';else if('createTexture'===t)this._trackObject(s.__id,s);else if('createView'!==t||n){if('createBuffer'===t)this._trackObject(s.__id,s);else if('createBindGroup'===t)this._trackObject(s.__id,s),s.__descriptor=r[0];else if('setBindGroup'===t){const t=r[1].__descriptor;if(t)for(const r of t.entries)if(r.resource instanceof GPUTextureView&&r.resource.__id<0){if(r.resource.__texture.__frameIndex{const i={vendor:o.vendor,architecture:o.architecture,device:o.device,description:o.description,features:s._gpuToArray(e.features),limits:s._gpuToObject(e.limits),isFallbackAdapter:e.isFallbackAdapter,wgslFeatures:s._gpuToArray(navigator.gpu.wgslLanguageFeatures)};s._sendAddObjectMessage(t,0,'Adapter',JSON.stringify(i),r)}))}_wrapDevice(e,t,r,s,o){if(e&&void 0===e.__id&&this._wrapAdapter(e,void 0,o),t&&void 0===t.__id){t.queue.__device=t;const i=this;t.addEventListener('uncapturederror',(e=>{i._postMessage({action:p.ValidationError,id:0,message:e.error.message})})),s??=[],this._wrapObject(t,r);const n=s[0]??{},a=t.__id,c=e?.__id??0;n.features=this._gpuToArray(t.features),n.limits=this._gpuToObject(t.limits),this._trackObject(a,t),this._sendAddObjectMessage(r,c,'Device',JSON.stringify(n),o),t.__adapter=e,this._device=t}}clear(){this._captureFrameCommands.length=0,this._currentFrame=null}getNextId(e){return e instanceof GPUCommandEncoder||e instanceof GPUComputePassEncoder||e instanceof GPURenderPassEncoder||e instanceof GPUCommandBuffer?0:this._objectID++}_memoryLeakWarning(e,t){if(t){const e=`${t.name} was garbage collected without being explicitly destroyed. These objects should explicitly destroyed to avoid GPU memory leaks.`;this._postMessage({action:p.ValidationError,id:0,message:e})}}_isPrimitiveType(e){return!e||e.constructor===String||e.constructor===Number||e.constructor===Boolean}_isTypedArray(e){return e&&(e instanceof ArrayBuffer||e.buffer instanceof ArrayBuffer)}_isArray(e){return e&&e.constructor===Array}_duplicateArray(e,t){const r=new Array(e.length);for(let s=0,o=e.length;s{if(t){console.error(t.message);const r=e??0;a._postMessage({action:p.ValidationError,id:r,message:t.message})}})),this._errorChecking++,this.enableRecording(),r.replacement=n;for(const e of this._objectReplacementMap.values()){const t=e.object.deref(),r=t instanceof GPURenderPipeline,i=t instanceof GPUComputePipeline;if(r||i){const i=t.__descriptor;let a=!1,c=null;if(i.vertex?.module===s&&(c||(c=this._duplicateObject(i)),a=!0,c.vertex.module=n),i.fragment?.module===s&&(c||(c=this._duplicateObject(i)),a=!0,c.fragment.module=n),i.compute?.module===s&&(c||(c=this._duplicateObject(i)),a=!0,c.compute.module=n),a){this.disableRecording(),this._errorChecking--,c.__replacement=e.id,o.pushErrorScope('validation');const t=r?o.createRenderPipeline(c):o.createComputePipeline(c),s=this;o.popErrorScope().then((t=>{if(t){console.error(t.message);const r=e.id??0;s._postMessage({action:p.ValidationError,id:r,message:t.message})}})),this._errorChecking++,this.enableRecording(),e.replacement=t}}}}_requestTexture(e){if(e<0)this._captureTextureRequest.set(e,null);else{const t=this._trackedObjects.get(e),r=t?.deref();r instanceof GPUTexture&&this._captureTextureRequest.set(e,r)}}_updateStatusMessage(){let e='';this._captureTexturedBuffers.length>0&&(e+=`Texture: ${this._captureTexturedBuffers.length} `),this._mappedTextureBufferCount>0&&(e+=`Pending Texture Reads: ${this._mappedTextureBufferCount} `),this._encodingTextureChunkCount>0&&(e+=`Pending Texture Encoding: ${this._encodingTextureChunkCount} `),this._captureBuffersCount&&(e+=`Buffers: ${this._captureBuffersCount} `),this._mappedBufferCount>0&&(e+=`Pending Buffer Reads: ${this._mappedBufferCount} `),this._encodingBufferChunkCount>0&&(e+=`Pending Buffer Encoding: ${this._encodingBufferChunkCount} `),e&&(e=`Capturing: ${e} `),this._inspectingStatusFrame&&(this._inspectingStatusText.textContent=e)}_updateFrameRate(e){this._frameRate.add(e),this._frameIndex++,this._inspectingStatusFrame&&(this._inspectingStatusFrame.textContent=`Frame: ${this._frameIndex} : ${this._frameRate.average.toFixed(2)}ms`)}_frameStart(e){let t=0;if(0==this._lastFrameTime?this._lastFrameTime=e:(t=e-this._lastFrameTime,this._postMessage({action:p.DeltaTime,deltaTime:t}),this._lastFrameTime=e,this._frameRate.add(t)),f){const e=f.getItem(y);if(e){try{this._captureData=JSON.parse(e)}catch(e){this._captureData=null}f.removeItem(y)}}if(this._captureData&&(this._captureData.frame<0||this._frameIndex>=this._captureData.frame)&&(this._captureMaxBufferSize=this._captureData.maxBufferSize||262144,this._captureFrameRequest=!0,this._gpuWrapper.recordStacktraces=!0,this._captureData=null,this._captureTimestamps)){if(this.disableRecording(),this._device){this._timestampQuerySet||(this._timestampQuerySet=this._device.createQuerySet({type:'timestamp',count:this._maxTimestamps}),this._timestampBuffer=this._device.createBuffer({size:8*this._maxTimestamps,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}));const e=this._device.createCommandEncoder();e.beginComputePass({timestampWrites:{querySet:this._timestampQuerySet,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1}}).end(),this._device.queue.submit([e.finish()]),this._timestampIndex=2}this.enableRecording()}this._frameData.length=0,this._captureFrameCommands.length=0,this._frameRenderPassCount=0,this._frameIndex++,this._frameCommandCount=0,this._inspectingStatusFrame&&(this._inspectingStatusFrame.textContent=`Frame: ${this._frameIndex} : ${this._frameRate.average.toFixed(2)}ms`)}_frameEnd(e){if(this._captureFrameCommands.length){const e=2e3,t=Math.ceil(this._captureFrameCommands.length/e);this._postMessage({action:p.CaptureFrameResults,frame:this._frameIndex,count:this._captureFrameCommands.length,batches:t});for(let t=0;t{const i=r.call(e,s,o);return i instanceof GPUCanvasContext&&(t._wrapObject(i),t._trackObject(i.__id,i)),i}}_wrapObject(e,t){if(e&&void 0===e.__id){if(e.__id=t??this.getNextId(e),this._garbageCollectionRegistry.register(e,e.__id),void 0!==e.label){const t=e.label;e._label=t;const r=this;Object.defineProperty(e,'label',{enumerable:!0,configurable:!0,get(){return this._label},set(e){if(e!==this._label){this._label=e;const t=this.__id;r._postMessage({action:p.ObjectSetLabel,id:t,label:e})}}})}e instanceof GPUDevice&&void 0===e.queue.__id&&this._wrapObject(e.queue)}}_gpuToArray(e){const t=[];if(e)for(const r of e)t.push(r);return t}_gpuToObject(e){const t={};if(e)for(const r in e)t[r]=e[r];return t}_stringifyDescriptor(e){const t=this._duplicateObject(e,!0)??{};let r=null;try{r=JSON.stringify(t)}catch(e){console.log(e.message)}return r}_sendAddObjectMessage(e,t,r,s,o,i){this._postMessage({action:p.AddObject,id:e,parent:t,type:r,descriptor:s,stacktrace:o,pending:i})}_recordCommand(e,t,r,s,o){const i=e?.__id??0;if('destroy'===t){e===this._device&&(this._device=null);const t=e.__id;e.__destroyed=!0,t>0&&(this._trackedObjects.delete(t),this._trackedObjectInfo.delete(t),this._objectReplacementMap.delete(t)),e instanceof GPUBindGroup&&this._bindGroupCount--,t>=0&&(this._captureTextureRequest.delete(t),this._postMessage({action:p.DeleteObject,id:t}))}else if('createShaderModule'===t){const e=r.__id;s[0].__replacement||this._sendAddObjectMessage(e,i,'ShaderModule',this._stringifyDescriptor(s[0]),o)}else if('createBuffer'===t){const e=r.__id;this._sendAddObjectMessage(e,i,'Buffer',this._stringifyDescriptor(s[0]),o)}else if('createTexture'===t){const t=r.__id;this._sendAddObjectMessage(t,i,'Texture',this._stringifyDescriptor(s[0]),o),r.__device=e}else if('getCurrentTexture'===t){const e=r.__id;if(r){const t={size:[r.width,r.height,r.depthOrArrayLayers],mipLevelCount:r.mipLevelCount,sampleCount:r.sampleCount,dimension:r.dimension,format:r.format,usage:r.usage},s=JSON.stringify(t);this._sendAddObjectMessage(e,i,'Texture',s,o)}}else if('createView'===t){const t=r.__id;r.__texture=e,this._sendAddObjectMessage(t,i,'TextureView',this._stringifyDescriptor(s[0]),o)}else if('createSampler'===t){const e=r.__id;this._sendAddObjectMessage(e,i,'Sampler',this._stringifyDescriptor(s[0]),o)}else if('createBindGroup'===t){this._bindGroupCount++;const e=r.__id;r.__descriptor=s[0],this._sendAddObjectMessage(e,i,'BindGroup',this._stringifyDescriptor(s[0]),o)}else if('createBindGroupLayout'===t){const e=r.__id;r.__descriptor=s[0],this._sendAddObjectMessage(e,i,'BindGroupLayout',this._stringifyDescriptor(s[0]),o)}else if('createPipelineLayout'===t){const e=r.__id;this._sendAddObjectMessage(e,i,'PipelineLayout',this._stringifyDescriptor(s[0]),o)}else if('createRenderPipeline'===t){const e=r.__id;s[0].__replacement||(this._sendAddObjectMessage(e,i,'RenderPipeline',this._stringifyDescriptor(s[0]),o),s[0].vertex?.module&&(r.__vertexModule=s[0].vertex?.module),s[0].fragment?.module&&(r.__fragmentModule=s[0].fragment?.module))}else if('createComputePipeline'===t){const e=r.__id;s[0].__replacement||(this._sendAddObjectMessage(e,i,'ComputePipeline',this._stringifyDescriptor(s[0]),o),s[0].compute?.module&&(r.__computeModule=s[0].compute?.module))}else'createCommandEncoder'===t&&(r.__device=e);this._captureFrameRequest&&this._captureCommand(e,t,s,o,r)}_captureCommand(e,t,r,s,o){const i=this._captureFrameCommands.length,n=r;1===n.length&&void 0===n[0]&&(n.length=0),('beginRenderPass'===t||'beginComputePass'===t||'createCommandEncoder'===t||'finish'===t)&&(o.__id=`_${i}`);let a=null;if('setBindGroup'===t){a=[];const t=n[0],r=n[1];if(a.push(t),a.push(r),n.length>2&&n[2]?.length){const e=n[2];if(e.length>0)if(e instanceof Uint32Array){const t=n[3],r=n[4];if(r>0){const s=new Uint32Array(e.buffer,4*t,r);a.push(s)}}else a.push(e)}const s=a.length>2?a[2]:null;let o=0;const c=r.__descriptor,p=c.layout?.__descriptor;if(c)for(const t in c.entries){const r=c.entries[t],n=p?.entries[t],a=r?.resource?.buffer,d=n?.buffer?.hasDynamicOffset??!1;if(a){let n=r.resource.offset??0;const c=m(r.resource.size??a.size-n,4);c3){const e=n[3]??0,t=n[4],s=r instanceof ArrayBuffer?r:r.buffer;s&&(t>0?r=new Uint8Array(s,e,t):e>0&&(r=new Uint8Array(s,e)))}a.push(r)}else a=n;if(a=this._processCommandArgs(a),this._captureFrameCommands.push({class:e.constructor.name,object:e.__id,result:o?.__id??0,commandId:i,method:t,args:a,stacktrace:s}),'setIndexBuffer'===t&&(e.__indexBuffer=r),'setVertexBuffer'===t){const t=r[0],s=r[1],o=r[2]??0,n=r[3]??s.size-o;e.__captureBuffers||(e.__captureBuffers=[]),e.__captureBuffers.push({commandId:i,entryIndex:t,buffer:s,offset:o,size:n}),this._captureBuffersCount++,this._updateStatusMessage()}if('setIndexBuffer'===t){const t=r[0],s=t.size;e.__captureBuffers||(e.__captureBuffers=[]),e.__captureBuffers.push({commandId:i,entryIndex:0,buffer:t,offset:0,size:s}),this._captureBuffersCount++,this._updateStatusMessage()}if('drawIndirect'===t||'drawIndexedIndirect'===t||'dispatchWorkgroupsIndirect'===t){const t=r[0],s=0,o=t.size;e.__captureBuffers||(e.__captureBuffers=[]),e.__captureBuffers.push({commandId:i,entryIndex:0,buffer:t,offset:s,size:o}),this._captureBuffersCount++,this._updateStatusMessage()}if('beginRenderPass'===t){if(r[0]?.colorAttachments?.length>0){o.__captureTextureViews=new Set;for(const e of r[0].colorAttachments){if(!e)continue;const t=e.resolveTarget??e.view;o.__captureTextureViews.add(t)}}if(o.__descriptor=r[0],r[0]?.depthStencilAttachment){o.__captureTextureViews||(o.__captureTextureViews=new Set);const e=r[0].depthStencilAttachment,t=e.resolveTarget??e.view;o.__captureTextureViews.add(t)}this._inComputePass=!1,o.__commandEncoder=e}else if('beginComputePass'===t)o.__commandEncoder=e,this._inComputePass=!0;else if('end'===t){this._inComputePass=!1;const t=e.__commandEncoder;if(e.__captureBuffers?.length>0&&(this._recordCaptureBuffers(t,e.__captureBuffers),this._updateStatusMessage()),e.__captureTextureViews?.size>0){let r=10*this._frameRenderPassCount;for(const s of e.__captureTextureViews){const e=s.__texture;e&&this._captureTextureBuffer(t?.__device,t,e,r++)}e.__captureTextureViews.clear()}e.__commandEncoder=null,e instanceof GPURenderPassEncoder&&this._frameRenderPassCount++}}_sendCaptureTextureBuffers(e){const t=[];for(const r of e)t.push(r.id);let r=0;for(const t of e){const e=t.tempBuffer.size;r+=Math.ceil(e/P)}this._postMessage({action:p.CaptureTextureFrames,chunkCount:r,count:e.length,textures:t});for(const t of e){const{id:e,tempBuffer:r,passId:s}=t;this._mappedTextureBufferCount++;const o=this;r.mapAsync(GPUMapMode.READ).then((()=>{o._mappedTextureBufferCount--,o._updateStatusMessage();const t=r.getMappedRange(),i=new Uint8Array(t);o._sendTextureData(e,s,i),r.destroy()})).catch((e=>{console.error(e)}))}this._updateStatusMessage()}_sendTextureData(e,r,s){const o=s.length,i=Math.ceil(o/P),n=this;for(let a=0;a{n._postMessage({action:p.CaptureTextureData,id:e,passId:r,offset:c,size:o,index:a,count:i,chunk:t}),n._encodingTextureChunkCount--,n._updateStatusMessage()})).catch((e=>{console.log('Error encoding texture data:',e)}))}}_getTextureUtils(e){return e?(e.__textureUtils||(e.__textureUtils=new c(e)),e.__textureUtils):null}_sendBufferData(e,r,s){const o=s.length,i=Math.ceil(o/P),n=this;for(let a=0;a{n._postMessage({action:p.CaptureBufferData,commandId:e,entryIndex:r,offset:c,size:o,index:a,count:i,chunk:t}),n._encodingBufferChunkCount--,n._updateStatusMessage()})).catch((e=>{console.error(e.message)}))}}_sendTimestampBuffer(e,t){const r=this;t.mapAsync(GPUMapMode.READ).then((()=>{const e=t.getMappedRange(),s=new Uint8Array(e);r._sendBufferData(-1e3,-1e3,s),t.destroy()})).catch((e=>{console.error(e)}))}_sendCapturedBuffers(e){if(e.length>0){let t=0;for(const r of e){const e=r.tempBuffer.size;t+=Math.ceil(e/P)}this._postMessage({action:p.CaptureBuffers,count:e.length,chunkCount:t})}e.length;for(const t of e){const e=t.tempBuffer,r=t.commandId,s=t.entryIndex,o=this;this._mappedBufferCount++,this._updateStatusMessage(),e.mapAsync(GPUMapMode.READ).then((()=>{o._mappedBufferCount--,o._updateStatusMessage();const t=e.getMappedRange(),i=new Uint8Array(t);o._sendBufferData(r,s,i),e.destroy()})).catch((e=>{console.error(e)}))}}_recordCaptureBuffers(e,t){const r=e?.__device;if(!r)return this._captureBuffersCount-=t.length,void(t.length=0);for(const s of t){const{commandId:t,entryIndex:o,buffer:i,offset:n,size:a}=s;if(i.__destroyed)continue;let c=null;this.disableRecording();try{c=r.createBuffer({size:a,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,label:`BUFFER CAPTURE TEMP [${t},${o}]`}),e.copyBufferToBuffer(i,n,c,0,a),this._captureTempBuffers.push({commandId:t,entryIndex:o,tempBuffer:c})}catch(e){console.log(e)}this.enableRecording()}this._captureBuffersCount-=t.length,t.length=0}_captureTextureBuffer(e,t,r,s){if(!e)return;const o=!t;t??=e.createCommandEncoder(),s??=-1;const i=r.__id;let n=r.format,c=n?a[n]:void 0;if(!c)return;if(c.isDepthStencil){this.disableRecording();try{r=this._getTextureUtils(e).copyDepthTexture(r,'r32float',t)}catch(e){return this.enableRecording(),void console.log(e)}this.enableRecording(),n=r.format,c=n?a[n]:void 0,r.__id=i,this._toDestroy.push(r)}else if(r.sampleCount>1){this.disableRecording();try{(r=this._getTextureUtils(e).copyMultisampledTexture(r)).__id=i,this._toDestroy.push(r)}catch(e){return this.enableRecording(),void console.log(e)}this.enableRecording()}const p=r.width,d=r.height||1,u=r.depthOrArrayLayers||1,l=p*c.bytesPerBlock+255&-256,h=l*d*u;if(!h)return;const _={width:p,height:d,depthOrArrayLayers:u};let m=null;try{this.disableRecording(),m=e.createBuffer({size:h,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});const s='all';t.copyTextureToBuffer({texture:r,aspect:s},{buffer:m,bytesPerRow:l,rowsPerImage:d},_)}catch(e){console.log(e)}o&&e.queue.submit([t.finish()]),this.enableRecording(),m&&(this._captureTexturedBuffers.push({id:i,tempBuffer:m,width:p,height:d,depthOrArrayLayers:u,format:n,passId:s}),this._updateStatusMessage())}_addCommandData(e){if(this._captureFrameRequest){const t=this._frameData.length;return this._frameData.push(e),t}return-1}_isHTMLImageElement(e){return!!s&&(e instanceof HTMLImageElement||e instanceof HTMLCanvasElement||e instanceof HTMLVideoElement)}_processCommandArgs(e){if(!e||e.constructor===Number||e.constructor===String||e.constructor===Boolean)return e;if(void 0!==e.__id)return{__id:e.__id,__class:e.constructor.name};if(e instanceof ImageBitmap||e instanceof ImageData||e instanceof OffscreenCanvas||e instanceof VideoFrame||this._isHTMLImageElement(e))return`@-1 ${e.constructor.name} ${e.width} ${e.height}`;if(e instanceof Array||void 0!==e.buffer){const t=100;if(e.length>t){return`@${this._addCommandData(e)} ${e.constructor.name} ${e.byteLength}`}const r=[];for(const t in e)r[t]=this._processCommandArgs(e[t]);return r}if(e instanceof ArrayBuffer){return`@${this._addCommandData(e)} ${e.constructor.name} ${e.byteLength}`}if(e instanceof Object){const t={};for(const r in e)t[r]=this._processCommandArgs(e[r]);return t}return e}};const C=Worker;class k{constructor(){this._worker=new C(...arguments),function(e){if(!e.__webgpuInspector){if(e.__webgpuInspector=!0,e.terminate){const t=e.terminate;e.terminate=function(){const r=t.call(e,...arguments);return e.__webgpuInspector=!1,r}}e.addEventListener('message',(e=>{e.data.__webgpuInspector&&window.dispatchEvent(new CustomEvent('__WebGPUInspector',{detail:e.data}))})),window.addEventListener('__WebGPUInspector',(t=>{e.__webgpuInspector&&t.detail.__webgpuInspector&&!t.detail.__webgpuInspectorPage&&e.postMessage(t.detail)}))}}(this._worker)}}for(const e in C.prototype)'constructor'!==e&&(k.prototype[e]=function(){return this._worker[e].apply(this._worker,arguments)});Worker=k})(),Object.defineProperty(e,'__esModule',{value:!0})}({}); //# sourceMappingURL=webgpu_inspector.js.map diff --git a/extensions/chrome/webgpu_inspector_worker.js b/extensions/chrome/webgpu_inspector_worker.js index 4aff651..e9f7d2f 100644 --- a/extensions/chrome/webgpu_inspector_worker.js +++ b/extensions/chrome/webgpu_inspector_worker.js @@ -1,2 +1,2 @@ -var exports;(exports={}).webgpuInspectorWorker=e=>{if(!e.__webgpuInspector){if(e.__webgpuInspector=!0,e.terminate){const t=e.terminate;e.terminate=function(){const s=t.call(e,...arguments);return e.__webgpuInspector=!1,s}}e.addEventListener('message',(e=>{e.data.__webgpuInspector&&window.postMessage(e.data,'*')})),window.addEventListener('message',(t=>{e.__webgpuInspector&&t.data.__webgpuInspector&&!t.data.__webgpuInspectorPage&&e.postMessage(t.data)}))}},Object.defineProperty(exports,'__esModule',{value:!0}); +var exports;(exports={}).webgpuInspectorWorker=e=>{if(!e.__webgpuInspector){if(e.__webgpuInspector=!0,e.terminate){const t=e.terminate;e.terminate=function(){const n=t.call(e,...arguments);return e.__webgpuInspector=!1,n}}e.addEventListener('message',(e=>{e.data.__webgpuInspector&&window.dispatchEvent(new CustomEvent('__WebGPUInspector',{detail:e.data}))})),window.addEventListener('__WebGPUInspector',(t=>{e.__webgpuInspector&&t.detail.__webgpuInspector&&!t.detail.__webgpuInspectorPage&&e.postMessage(t.detail)}))}},Object.defineProperty(exports,'__esModule',{value:!0}); //# sourceMappingURL=webgpu_inspector_worker.js.map diff --git a/extensions/firefox/content_script.js b/extensions/firefox/content_script.js index 2e78fb7..2d20c00 100644 --- a/extensions/firefox/content_script.js +++ b/extensions/firefox/content_script.js @@ -1,2 +1,2 @@ -!function(){const e={CaptureBufferData:'webgpu_inspect_capture_buffer_data',CaptureBuffers:'webgpu_inspect_capture_buffers',DeleteObjects:'webgpu_inspect_delete_objects',ValidationError:'webgpu_inspect_validation_error',MemoryLeakWarning:'webgpu_inspect_memory_leak_warning',DeltaTime:'webgpu_inspect_delta_time',CaptureFrameResults:'webgpu_inspect_capture_frame_results',CaptureFrameCommands:'webgpu_inspect_capture_frame_commands',ObjectSetLabel:'webgpu_inspect_object_set_label',AddObject:'webgpu_inspect_add_object',ResolveAsyncObject:'webgpu_inspect_resolve_async_object',DeleteObject:'webgpu_inspect_delete_object',CaptureTextureFrames:'webgpu_inspect_capture_texture_frames',CaptureTextureData:'webgpu_inspect_capture_texture_data',CaptureBufferData:'webgpu_inspect_capture_buffer_data',Recording:'webgpu_record_recording',RecordingCommand:'webgpu_record_command',RecordingDataCount:'webgpu_record_data_count',RecordingData:'webgpu_record_data'};e.values=new Set(Object.values(e));const t='webgpu_inspect_request_texture',s='webgpu_inspect_compile_shader',r='webgpu_inspect_revert_shader',o='webgpu_inspector_capture',n='webgpu_initialize_inspector',a='webgpu_initialize_recorder',i='WEBGPU_INSPECTOR_LOADED',c='WEBGPU_RECORDER_LOADED',_='WEBGPU_INSPECTOR_CAPTURE_FRAME',p=new class u{constructor(e,t,s){this.name=e,this.tabId=t??0,this.listeners=[],s&&this.listeners.push(s),this._port=null,this.reset()}reset(){const e=this;this._port=chrome.runtime.connect({name:this.name}),this._port.onDisconnect.addListener((()=>{e.reset()})),this._port.onMessage.addListener((t=>{for(const s of e.listeners)s(t)}))}addListener(e){this.listeners.push(e)}postMessage(e){e.__webgpuInspector=!0,this.tabId&&(e.tabId=this.tabId);try{this._port.postMessage(e)}catch(e){this.reset()}}}('webgpu-inspector-page',0,(e=>{let p=e.action;if(!p)return;if(p===t||p===s||p===r)return void window.postMessage(e,'*');if(p===a)return sessionStorage.setItem(c,`${e.frames}%${e.filename}%${e.download}`),void setTimeout((()=>{window.location.reload()}),50);let u='true';if(p===o){const t=JSON.stringify(e);!d||e.frame>=0?(p=n,u=t):(sessionStorage.setItem(_,t),window.postMessage({__webgpuInspector:!0,__webgpuInspectorPanel:!0,action:o,data:t},'*'))}p===n&&(sessionStorage.setItem(i,u),setTimeout((()=>{window.location.reload()}),50))}));let d=!1;function g(e,t,s){const r=document.createElement('script');if(r.id=e,r.src=t,s)for(const e in s)r.setAttribute(e,s[e]);(document.head||document.documentElement).appendChild(r)}window.addEventListener('pageshow',(e=>{e.persisted&&p.reset()})),window.addEventListener('message',(t=>{if(t.source!==window)return;const s=t.data;if('object'!=typeof s||null===s)return;const r=s.action;if(e.values.has(r))try{p.postMessage(s)}catch(e){console.log('#### error:',e)}}));const b=sessionStorage.getItem(i);b&&(sessionStorage.removeItem(i),'true'!==b&&sessionStorage.setItem(_,b),g('__webgpu_inspector',chrome.runtime.getURL('webgpu_inspector.js')),d=!0);const m=sessionStorage.getItem(c);if(m){sessionStorage.removeItem(c);const e=m.split('%');g('__webgpu_recorder',chrome.runtime.getURL('webgpu_recorder.js'),{filename:e[1],frames:e[0],download:e[2],removeUnusedResources:1,messageRecording:1})}p.postMessage({action:'PageLoaded'})}(); +!function(){const e={CaptureBufferData:'webgpu_inspect_capture_buffer_data',CaptureBuffers:'webgpu_inspect_capture_buffers',DeleteObjects:'webgpu_inspect_delete_objects',ValidationError:'webgpu_inspect_validation_error',MemoryLeakWarning:'webgpu_inspect_memory_leak_warning',DeltaTime:'webgpu_inspect_delta_time',CaptureFrameResults:'webgpu_inspect_capture_frame_results',CaptureFrameCommands:'webgpu_inspect_capture_frame_commands',ObjectSetLabel:'webgpu_inspect_object_set_label',AddObject:'webgpu_inspect_add_object',ResolveAsyncObject:'webgpu_inspect_resolve_async_object',DeleteObject:'webgpu_inspect_delete_object',CaptureTextureFrames:'webgpu_inspect_capture_texture_frames',CaptureTextureData:'webgpu_inspect_capture_texture_data',CaptureBufferData:'webgpu_inspect_capture_buffer_data',Recording:'webgpu_record_recording',RecordingCommand:'webgpu_record_command',RecordingDataCount:'webgpu_record_data_count',RecordingData:'webgpu_record_data'};e.values=new Set(Object.values(e));const t='webgpu_inspect_request_texture',s='webgpu_inspect_compile_shader',r='webgpu_inspect_revert_shader',n='webgpu_inspector_capture',o='webgpu_initialize_inspector',a='webgpu_initialize_recorder',i='WEBGPU_INSPECTOR_LOADED',c='WEBGPU_RECORDER_LOADED',_='WEBGPU_INSPECTOR_CAPTURE_FRAME',p=new class u{constructor(e,t,s){this.name=e,this.tabId=t??0,this.listeners=[],s&&this.listeners.push(s),this._port=null,this.reset()}reset(){const e=this;this._port=chrome.runtime.connect({name:this.name}),this._port.onDisconnect.addListener((()=>{e.reset()})),this._port.onMessage.addListener((t=>{for(const s of e.listeners)s(t)}))}addListener(e){this.listeners.push(e)}postMessage(e){e.__webgpuInspector=!0,this.tabId&&(e.tabId=this.tabId);try{this._port.postMessage(e)}catch(e){this.reset()}}}('webgpu-inspector-page',0,(e=>{let p=e.action;if(!p)return;if(p===t||p===s||p===r)return void window.dispatchEvent(new CustomEvent('__WebGPUInspector',{detail:e}));if(p===a)return sessionStorage.setItem(c,`${e.frames}%${e.filename}%${e.download}`),void setTimeout((()=>{window.location.reload()}),50);let u='true';if(p===n){const t=JSON.stringify(e);if(!d||e.frame>=0)p=o,u=t;else{sessionStorage.setItem(_,t);const e={__webgpuInspector:!0,__webgpuInspectorPanel:!0,action:n,data:t};window.dispatchEvent(new CustomEvent('__WebGPUInspector',{detail:e}))}}p===o&&(sessionStorage.setItem(i,u),setTimeout((()=>{window.location.reload()}),50))}));let d=!1;function g(e,t,s){const r=document.createElement('script');if(r.id=e,r.src=t,s)for(const e in s)r.setAttribute(e,s[e]);(document.head||document.documentElement).appendChild(r)}window.addEventListener('pageshow',(e=>{e.persisted&&p.reset()})),window.addEventListener('__WebGPUInspector',(t=>{const s=t.detail;if('object'!=typeof s||null===s)return;const r=s.action;if(e.values.has(r))try{p.postMessage(s)}catch(e){console.log('#### error:',e)}}));const b=sessionStorage.getItem(i);b&&(sessionStorage.removeItem(i),'true'!==b&&sessionStorage.setItem(_,b),g('__webgpu_inspector',chrome.runtime.getURL('webgpu_inspector.js')),d=!0);const m=sessionStorage.getItem(c);if(m){sessionStorage.removeItem(c);const e=m.split('%');g('__webgpu_recorder',chrome.runtime.getURL('webgpu_recorder.js'),{filename:e[1],frames:e[0],download:e[2],removeUnusedResources:1,messageRecording:1})}p.postMessage({action:'PageLoaded'})}(); //# sourceMappingURL=content_script.js.map diff --git a/extensions/firefox/webgpu_inspector.js b/extensions/firefox/webgpu_inspector.js index 7f80367..b89bd75 100644 --- a/extensions/firefox/webgpu_inspector.js +++ b/extensions/firefox/webgpu_inspector.js @@ -1,2 +1,2 @@ -!function(e){async function t(e,t='application/octet-stream'){return await new Promise(((r,s)=>{const o=Object.assign(new FileReader,{onload:()=>r(o.result),onerror:()=>s(o.error)});o.readAsDataURL(new File([e],'',{type:t}))}))}class r{constructor(e){this._lastSlotId=0,this.slots=new Map,e&&(this.name=e)}static get enabled(){return 0==r._disableSignals}static get disabled(){return r._disableSignals>0}static disable(){return r._disableSignals++}static enable(e){return e?(r._disableSignals=0,0):r._disableSignals>0?r._disableSignals--:0}static disconnect(e,t,s){for(const o in e){const i=e[o];i.constructor===r&&i.disconnect(t,s)}}static getSignals(e,t){t=t||[];for(const s in e){const o=e[s];o.constructor===r&&t.push(o)}return t}get hasListeners(){return this.slots.size>0}emit(){if(!r.disabled)for(const e of this.slots){const t=e[1][0],s=e[1][1]||t;t&&(t.constructor===r?t.emit.apply(s,arguments):t.apply(s,arguments))}}addListener(e,t){return this.isListening(e,t)?null:(this.slots.set(this._lastSlotId++,[e,t]),this._lastSlotId-1)}isListening(e,t){for(const r of this.slots){const s=r[1];if(e&&!t){if(s[0]===e||s[1]===e)return!0}else if(!e&&t){if(s[1]===t)return!0}else if(s[0]===e&&s[1]===t)return!0}return!1}disconnect(e,t){if(null==e&&null==t)return this.slots.clear(),!0;if(e.constructor===Number){const t=e;return!!this.slots.has(t)&&(this.slots.delete(t),!0)}let r=!1;for(const s of this.slots){const o=s[0],i=s[1];e&&!t?i[0]!==e&&i[1]!==e||(this.slots.delete(o),r=!0):!e&&t?i[1]===t&&(this.slots.delete(o),r=!0):i[0]===e&&i[1]===t&&(this.slots.delete(o),r=!0)}return r}}function s(){if(!Error.captureStackTrace)return'';const e={};if(Error.captureStackTrace(e,s),!e.stack)return'';return e.stack.split('\n').map((e=>e.split('at ')[1])).slice(2).filter((e=>e&&!e.includes('webgpu_inspector.js'))).join('\n')}r._disableSignals=0;const o=new Set([GPUAdapter,GPUDevice,GPUBuffer,GPUTexture,GPUTextureView,GPUSampler,GPUBindGroupLayout,GPUBindGroup,GPUPipelineLayout,GPUShaderModule,GPUComputePipeline,GPURenderPipeline,GPUCommandBuffer,GPUCommandEncoder,GPUComputePassEncoder,GPURenderPassEncoder,GPURenderBundle,GPUQueue,GPUQuerySet,GPUCanvasContext]),i=new Set(['createBuffer','createTexture','createSampler','importExternalTexture','createBindGroupLayout','createPipelineLayout','createBindGroup','createShaderModule','createComputePipeline','createRenderPipeline','createComputePipelineAsync','createRenderPipelineAsync','createCommandEncoder','createRenderBundleEncoder','createQuerySet','createView']);class n{constructor(e){this._idGenerator=e,this.onPreCall=new r,this.onPostCall=new r,this.onPromise=new r,this.onPromiseResolve=new r,this.recordStacktraces=!1,this._skipRecord=0,this._wrapGPUTypes()}_wrapGPUTypes(){GPU.prototype.requestAdapter=this._wrapMethod('requestAdapter',GPU.prototype.requestAdapter),GPU.prototype.getPreferredFormat=this._wrapMethod('getPreferredFormat',GPU.prototype.getPreferredFormat),GPUAdapter.prototype.requestDevice=this._wrapMethod('requestDevice',GPUAdapter.prototype.requestDevice),GPUDevice.prototype.destroy=this._wrapMethod('destroy',GPUDevice.prototype.destroy),GPUDevice.prototype.createBuffer=this._wrapMethod('createBuffer',GPUDevice.prototype.createBuffer),GPUDevice.prototype.createTexture=this._wrapMethod('createTexture',GPUDevice.prototype.createTexture),GPUDevice.prototype.createSampler=this._wrapMethod('createSampler',GPUDevice.prototype.createSampler),GPUDevice.prototype.importExternalTexture=this._wrapMethod('importExternalTexture',GPUDevice.prototype.importExternalTexture),GPUDevice.prototype.createBindGroupLayout=this._wrapMethod('createBindGroupLayout',GPUDevice.prototype.createBindGroupLayout),GPUDevice.prototype.createPipelineLayout=this._wrapMethod('createPipelineLayout',GPUDevice.prototype.createPipelineLayout),GPUDevice.prototype.createBindGroup=this._wrapMethod('createBindGroup',GPUDevice.prototype.createBindGroup),GPUDevice.prototype.createShaderModule=this._wrapMethod('createShaderModule',GPUDevice.prototype.createShaderModule),GPUDevice.prototype.createComputePipeline=this._wrapMethod('createComputePipeline',GPUDevice.prototype.createComputePipeline),GPUDevice.prototype.createRenderPipeline=this._wrapMethod('createRenderPipeline',GPUDevice.prototype.createRenderPipeline),GPUDevice.prototype.createComputePipelineAsync=this._wrapMethod('createComputePipelineAsync',GPUDevice.prototype.createComputePipelineAsync),GPUDevice.prototype.createRenderPipelineAsync=this._wrapMethod('createRenderPipelineAsync',GPUDevice.prototype.createRenderPipelineAsync),GPUDevice.prototype.createCommandEncoder=this._wrapMethod('createCommandEncoder',GPUDevice.prototype.createCommandEncoder),GPUDevice.prototype.createRenderBundleEncoder=this._wrapMethod('createRenderBundleEncoder',GPUDevice.prototype.createRenderBundleEncoder),GPUDevice.prototype.createQuerySet=this._wrapMethod('createQuerySet',GPUDevice.prototype.createQuerySet),GPUBuffer.prototype.mapAsync=this._wrapMethod('mapAsync',GPUBuffer.prototype.mapAsync),GPUBuffer.prototype.getMappedRange=this._wrapMethod('getMappedRange',GPUBuffer.prototype.getMappedRange),GPUBuffer.prototype.unmap=this._wrapMethod('unmap',GPUBuffer.prototype.unmap),GPUBuffer.prototype.destroy=this._wrapMethod('destroy',GPUBuffer.prototype.destroy),GPUTexture.prototype.createView=this._wrapMethod('createView',GPUTexture.prototype.createView),GPUTexture.prototype.destroy=this._wrapMethod('destroy',GPUTexture.prototype.destroy),GPUShaderModule.prototype.getCompilationInfo=this._wrapMethod('getCompilationInfo',GPUShaderModule.prototype.getCompilationInfo),GPUComputePipeline.prototype.getBindGroupLayout=this._wrapMethod('getBindGroupLayout',GPUComputePipeline.prototype.getBindGroupLayout),GPURenderPipeline.prototype.getBindGroupLayout=this._wrapMethod('getBindGroupLayout',GPURenderPipeline.prototype.getBindGroupLayout),GPUCommandEncoder.prototype.beginRenderPass=this._wrapMethod('beginRenderPass',GPUCommandEncoder.prototype.beginRenderPass),GPUCommandEncoder.prototype.beginComputePass=this._wrapMethod('beginComputePass',GPUCommandEncoder.prototype.beginComputePass),GPUCommandEncoder.prototype.copyBufferToBuffer=this._wrapMethod('copyBufferToBuffer',GPUCommandEncoder.prototype.copyBufferToBuffer),GPUCommandEncoder.prototype.copyBufferToTexture=this._wrapMethod('copyBufferToTexture',GPUCommandEncoder.prototype.copyBufferToTexture),GPUCommandEncoder.prototype.copyTextureToBuffer=this._wrapMethod('copyTextureToBuffer',GPUCommandEncoder.prototype.copyTextureToBuffer),GPUCommandEncoder.prototype.copyTextureToTexture=this._wrapMethod('copyTextureToTexture',GPUCommandEncoder.prototype.copyTextureToTexture),GPUCommandEncoder.prototype.clearBuffer=this._wrapMethod('clearBuffer',GPUCommandEncoder.prototype.clearBuffer),GPUCommandEncoder.prototype.resolveQuerySet=this._wrapMethod('resolveQuerySet',GPUCommandEncoder.prototype.resolveQuerySet),GPUCommandEncoder.prototype.finish=this._wrapMethod('finish',GPUCommandEncoder.prototype.finish),GPUCommandEncoder.prototype.pushDebugGroup=this._wrapMethod('pushDebugGroup',GPUCommandEncoder.prototype.pushDebugGroup),GPUCommandEncoder.prototype.popDebugGroup=this._wrapMethod('popDebugGroup',GPUCommandEncoder.prototype.popDebugGroup),GPUCommandEncoder.prototype.insertDebugMarker=this._wrapMethod('insertDebugMarker',GPUCommandEncoder.prototype.insertDebugMarker),GPUComputePassEncoder.prototype.setPipeline=this._wrapMethod('setPipeline',GPUComputePassEncoder.prototype.setPipeline),GPUComputePassEncoder.prototype.dispatchWorkgroups=this._wrapMethod('dispatchWorkgroups',GPUComputePassEncoder.prototype.dispatchWorkgroups),GPUComputePassEncoder.prototype.dispatchWorkgroupsIndirect=this._wrapMethod('dispatchWorkgroupsIndirect',GPUComputePassEncoder.prototype.dispatchWorkgroupsIndirect),GPUComputePassEncoder.prototype.end=this._wrapMethod('end',GPUComputePassEncoder.prototype.end),GPUComputePassEncoder.prototype.setBindGroup=this._wrapMethod('setBindGroup',GPUComputePassEncoder.prototype.setBindGroup),GPUComputePassEncoder.prototype.setBindGroup=this._wrapMethod('setBindGroup',GPUComputePassEncoder.prototype.setBindGroup),GPUComputePassEncoder.prototype.pushDebugGroup=this._wrapMethod('pushDebugGroup',GPUComputePassEncoder.prototype.pushDebugGroup),GPUComputePassEncoder.prototype.popDebugGroup=this._wrapMethod('popDebugGroup',GPUComputePassEncoder.prototype.popDebugGroup),GPUComputePassEncoder.prototype.insertDebugMarker=this._wrapMethod('insertDebugMarker',GPUComputePassEncoder.prototype.insertDebugMarker),GPURenderPassEncoder.prototype.setViewport=this._wrapMethod('setViewport',GPURenderPassEncoder.prototype.setViewport),GPURenderPassEncoder.prototype.setScissorRect=this._wrapMethod('setScissorRect',GPURenderPassEncoder.prototype.setScissorRect),GPURenderPassEncoder.prototype.setBlendConstant=this._wrapMethod('setBlendConstant',GPURenderPassEncoder.prototype.setBlendConstant),GPURenderPassEncoder.prototype.setStencilReference=this._wrapMethod('setStencilReference',GPURenderPassEncoder.prototype.setStencilReference),GPURenderPassEncoder.prototype.beginOcclusionQuery=this._wrapMethod('beginOcclusionQuery',GPURenderPassEncoder.prototype.beginOcclusionQuery),GPURenderPassEncoder.prototype.endOcclusionQuery=this._wrapMethod('endOcclusionQuery',GPURenderPassEncoder.prototype.endOcclusionQuery),GPURenderPassEncoder.prototype.executeBundles=this._wrapMethod('executeBundles',GPURenderPassEncoder.prototype.executeBundles),GPURenderPassEncoder.prototype.end=this._wrapMethod('end',GPURenderPassEncoder.prototype.end),GPURenderPassEncoder.prototype.setPipeline=this._wrapMethod('setPipeline',GPURenderPassEncoder.prototype.setPipeline),GPURenderPassEncoder.prototype.setIndexBuffer=this._wrapMethod('setIndexBuffer',GPURenderPassEncoder.prototype.setIndexBuffer),GPURenderPassEncoder.prototype.setVertexBuffer=this._wrapMethod('setVertexBuffer',GPURenderPassEncoder.prototype.setVertexBuffer),GPURenderPassEncoder.prototype.draw=this._wrapMethod('draw',GPURenderPassEncoder.prototype.draw),GPURenderPassEncoder.prototype.drawIndexed=this._wrapMethod('drawIndexed',GPURenderPassEncoder.prototype.drawIndexed),GPURenderPassEncoder.prototype.drawIndirect=this._wrapMethod('drawIndirect',GPURenderPassEncoder.prototype.drawIndirect),GPURenderPassEncoder.prototype.drawIndexedIndirect=this._wrapMethod('drawIndexedIndirect',GPURenderPassEncoder.prototype.drawIndexedIndirect),GPURenderPassEncoder.prototype.setBindGroup=this._wrapMethod('setBindGroup',GPURenderPassEncoder.prototype.setBindGroup),GPURenderPassEncoder.prototype.pushDebugGroup=this._wrapMethod('pushDebugGroup',GPURenderPassEncoder.prototype.pushDebugGroup),GPURenderPassEncoder.prototype.popDebugGroup=this._wrapMethod('popDebugGroup',GPURenderPassEncoder.prototype.popDebugGroup),GPURenderPassEncoder.prototype.insertDebugMarker=this._wrapMethod('insertDebugMarker',GPURenderPassEncoder.prototype.insertDebugMarker),GPUQueue.prototype.submit=this._wrapMethod('submit',GPUQueue.prototype.submit),GPUQueue.prototype.writeBuffer=this._wrapMethod('writeBuffer',GPUQueue.prototype.writeBuffer),GPUQueue.prototype.writeTexture=this._wrapMethod('writeTexture',GPUQueue.prototype.writeTexture),GPUQueue.prototype.copyExternalImageToTexture=this._wrapMethod('copyExternalImageToTexture',GPUQueue.prototype.copyExternalImageToTexture),GPUQuerySet.prototype.destroy=this._wrapMethod('destroy',GPUQuerySet.prototype.destroy),GPUCanvasContext.prototype.configure=this._wrapMethod('configure',GPUCanvasContext.prototype.configure),GPUCanvasContext.prototype.unconfigure=this._wrapMethod('unconfigure',GPUCanvasContext.prototype.unconfigure),GPUCanvasContext.prototype.getCurrentTexture=this._wrapMethod('getCurrentTexture',GPUCanvasContext.prototype.getCurrentTexture)}disableRecording(){this._skipRecord++}enableRecording(){this._skipRecord--,this._skipRecord<0&&(this._skipRecord=0)}get isRecordingEnabled(){return 0===this._skipRecord}_wrapMethod(e,t){const r=this;return function(){const o=this,n=[...arguments];if(r._skipRecord>0)return t.call(o,...n);r.onPreCall.emit(o,e,n);const a=t.call(o,...n),c=i.has(e),p=r.recordStacktraces||c?s():void 0;if(a instanceof Promise){const t=r._idGenerator.getNextId(o);r.onPromise.emit(o,e,n,t,p);const s=a,i=new Promise((i=>{s.then((s=>{r.onPromiseResolve.emit(o,e,n,t,s,p),i(s)}))}));return i}return r.onPostCall.emit(o,e,n,a,p),a}}}const a={r8unorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8snorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8uint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8sint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg8unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8snorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},'rgba8unorm-srgb':{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8snorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},bgra8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},'bgra8unorm-srgb':{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r16uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16float:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg16uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba16uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r32uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg32uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba32uint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32sint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32float:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rg11b10ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},stencil8:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!1,hasStencil:!0,channels:1},depth16unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},depth24plus:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,depthOnlyFormat:'depth32float',channels:1},'depth24plus-stencil8':{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,depthOnlyFormat:'depth32float',channels:1},depth32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},'depth32float-stencil8':{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,stencilOnlyFormat:'depth32float',channels:1},rgb9e5ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},'bc1-rgba-unorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc1-rgba-unorm-srgb':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc2-rgba-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc2-rgba-unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc3-rgba-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc3-rgba-unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc4-r-unorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},'bc4-r-snorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},'bc5-rg-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},'bc5-rg-snorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},'bc6h-rgb-ufloat':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc6h-rgb-float':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc7-rgba-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc7-rgba-unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgb8unorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgb8unorm-srgb':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgb8a1unorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgb8a1unorm-srgb':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgba8unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgba8unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'eac-r11unorm':{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},'eac-r11snorm':{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},'eac-rg11unorm':{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},'eac-rg11snorm':{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},'astc-4x4-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'astc-4x4-unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'astc-5x4-unorm':{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},'astc-5x4-unorm-srgb':{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},'astc-5x5-unorm':{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},'astc-5x5-unorm-srgb':{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},'astc-6x5-unorm':{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},'astc-6x5-unorm-srgb':{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},'astc-6x6-unorm':{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},'astc-6x6-unorm-srgb':{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},'astc-8x5-unorm':{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},'astc-8x5-unorm-srgb':{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},'astc-8x6-unorm':{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},'astc-8x6-unorm-srgb':{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},'astc-8x8-unorm':{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},'astc-8x8-unorm-srgb':{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},'astc-10x5-unorm':{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},'astc-10x5-unorm-srgb':{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},'astc-10x6-unorm':{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},'astc-10x6-unorm-srgb':{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},'astc-10x8-unorm':{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},'astc-10x8-unorm-srgb':{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},'astc-10x10-unorm':{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},'astc-10x10-unorm-srgb':{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},'astc-12x10-unorm':{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},'astc-12x10-unorm-srgb':{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},'astc-12x12-unorm':{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4},'astc-12x12-unorm-srgb':{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4}};class c{constructor(e){this.device=e,this.blitShaderModule=e.createShaderModule({code:c.blitShader}),this.multisampleBlitShaderModule=e.createShaderModule({code:c.multisampleBlitShader}),this.depthToFloatShaderModule=e.createShaderModule({code:c.depthToFloatShader}),this.depthToFloatMultisampleShaderModule=e.createShaderModule({code:c.depthToFloatMultisampleShader}),this.blitPipelines={},this.blitDepthPipelines={},this.bindGroupLayouts=new Map,this.pipelineLayouts=new Map,this.depthToFloatPipeline=null,this.depthToFloatMSPipeline=null,this.pointSampler=e.createSampler({magFilter:'nearest',minFilter:'nearest'}),this.displayUniformBuffer=e.createBuffer({size:32,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),this.displayBingGroupLayout=e.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,buffer:{type:'uniform'}}]}),this.displayBindGroup=e.createBindGroup({layout:this.displayBingGroupLayout,entries:[{binding:0,resource:{buffer:this.displayUniformBuffer}}]})}copyDepthTexture(e,t,r){const s=e.width,o=e.height,i=e.depthOrArrayLayers,n=e.usage|GPUTextureUsage.RENDER_TARGET|GPUTextureUsage.COPY_SRC,a=[s,o,i];t=t||'r32float';const c=this.device.createTexture({format:t,size:a,usage:n});for(let s=0;s1}}]});this.bindGroupLayouts.set(c,e);const t=this.device.createPipelineLayout({bindGroupLayouts:[e,this.displayBingGroupLayout]});this.pipelineLayouts.set(c,t)}const p=a[t],d=p?.channels??4,u=this.bindGroupLayouts.get(c),l=this.pipelineLayouts.get(c),h=`${o}#${n}#${r}`;let _=this.blitPipelines[h];if(!_){const e=r>1?this.multisampleBlitShaderModule:this.blitShaderModule;_=this.device.createRenderPipeline({layout:l,vertex:{module:e,entryPoint:'vertexMain'},fragment:{module:e,entryPoint:'fragmentMain',targets:[{format:o}]},primitive:{topology:'triangle-list'}}),this.blitPipelines[h]=_}const m=this.device.createBindGroup({layout:u,entries:[{binding:0,resource:this.pointSampler},{binding:1,resource:e}]}),f=this.device.createCommandEncoder(),g={colorAttachments:[{view:s,loadOp:'clear',storeOp:'store'}]};i?this.device.queue.writeBuffer(this.displayUniformBuffer,0,new Float32Array([i.exposure,i.channels,d,i.minRange,i.maxRange,0,0,0])):this.device.queue.writeBuffer(this.displayUniformBuffer,0,new Float32Array([1,0,d,0,1,0,0,0]));const b=f.beginRenderPass(g);b.setPipeline(_),b.setBindGroup(0,m),b.setBindGroup(1,this.displayBindGroup),b.draw(3),b.end(),this.device.queue.submit([f.finish()])}convertDepthToFloat(e,t,r,s,o){if(t>1){if(!this.depthToFloatMSPipeline){this.device.pushErrorScope('validation'),this.depthToFloatBindGroupMSLayout=this.device.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:'depth',multisampled:!0}}]});const e=this.device.createPipelineLayout({bindGroupLayouts:[this.depthToFloatBindGroupMSLayout]}),t=this.depthToFloatMultisampleShaderModule;this.depthToFloatMSPipeline=this.device.createRenderPipeline({layout:e,vertex:{module:t,entryPoint:'vertexMain'},fragment:{module:t,entryPoint:'fragmentMain',targets:[{format:s}]},primitive:{topology:'triangle-list'}}),this.device.popErrorScope().then((e=>{e&&console.error(e.message)}))}}else if(!this.depthToFloatPipeline){this.device.pushErrorScope('validation'),this.depthToFloatBindGroupLayout=this.device.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:'depth'}}]});const e=this.device.createPipelineLayout({bindGroupLayouts:[this.depthToFloatBindGroupLayout]}),t=this.depthToFloatShaderModule;this.depthToFloatPipeline=this.device.createRenderPipeline({layout:e,vertex:{module:t,entryPoint:'vertexMain'},fragment:{module:t,entryPoint:'fragmentMain',targets:[{format:s}]},primitive:{topology:'triangle-list'}}),this.device.popErrorScope().then((e=>{e&&console.error(e.message)}))}this.device.pushErrorScope('validation');const i=this.device.createBindGroup({layout:t>1?this.depthToFloatBindGroupMSLayout:this.depthToFloatBindGroupLayout,entries:[{binding:0,resource:e}]}),n=!o;o??=this.device.createCommandEncoder();const a=o.beginRenderPass({colorAttachments:[{view:r,loadOp:'clear',storeOp:'store',clearColor:{r:0,g:0,b:0,a:0}}]});a.setPipeline(t>1?this.depthToFloatMSPipeline:this.depthToFloatPipeline),a.setBindGroup(0,i),a.draw(3),a.end(),n&&this.device.queue.submit([o.finish()]),this.device.popErrorScope().then((e=>{e&&console.error(e.message)}))}}c.blitShader='\n var posTex:array = array(\n vec4f(-1.0, 1.0, 0.0, 0.0),\n vec4f(3.0, 1.0, 2.0, 0.0),\n vec4f(-1.0, -3.0, 0.0, 2.0));\n struct VertexOutput {\n @builtin(position) position: vec4f,\n @location(0) uv: vec2f\n };\n @vertex\n fn vertexMain(@builtin(vertex_index) vertexIndex: u32) -> VertexOutput {\n var output: VertexOutput;\n output.uv = posTex[vertexIndex].zw;\n output.position = vec4f(posTex[vertexIndex].xy, 0.0, 1.0);\n return output;;\n }\n @group(0) @binding(0) var texSampler: sampler;\n @group(0) @binding(1) var texture: texture_2d;\n struct Display {\n exposure: f32,\n channels: f32,\n numChannels: f32,\n minRange: f32,\n maxRange: f32,\n _pad1: f32,\n _pad2: f32,\n _pad3: f32\n };\n @group(1) @binding(0) var display: Display; \n @fragment\n fn fragmentMain(input: VertexOutput) -> @location(0) vec4f {\n var color = textureSample(texture, texSampler, input.uv);\n\n if (display.numChannels == 1.0) {\n if (display.minRange != display.maxRange) {\n if (color.r < display.minRange) {\n color = vec4f(0.0, 0.0, 0.0, 1);\n } else if (color.r > display.maxRange) {\n color = vec4f(1.0, 0.0, 0.0, 1);\n } else {\n color = vec4f((color.r - display.minRange) / (display.maxRange - display.minRange), 0.0, 0.0, 1);\n }\n }\n color = vec4f(color.r, color.r, color.r, 1.0);\n } else if (display.numChannels == 2.0) {\n color = vec4f(color.r, color.g, 0.0, 1.0);\n }\n\n if (display.channels == 1.0) { // R\n var rgb = color.rgb * display.exposure;\n return vec4f(rgb.r, 0.0, 0.0, 1);\n } else if (display.channels == 2.0) { // G\n var rgb = color.rgb * display.exposure;\n return vec4f(0.0, rgb.g, 0.0, 1);\n } else if (display.channels == 3.0) { // B\n var rgb = color.rgb * display.exposure;\n return vec4f(0.0, 0.0, rgb.b, 1);\n } else if (display.channels == 4.0) { // A\n var a = color.a * display.exposure;\n return vec4f(a, a, a, 1);\n } else if (display.channels == 5.0) { // Luminance\n var luminance = dot(color.rgb, vec3f(0.2126, 0.7152, 0.0722));\n var rgb = vec3f(luminance) * display.exposure;\n return vec4f(rgb, 1);\n }\n\n // RGB\n var rgb = color.rgb * display.exposure;\n return vec4f(rgb, 1);\n }\n',c.multisampleBlitShader='\n var posTex:array = array(\n vec4f(-1.0, 1.0, 0.0, 0.0),\n vec4f(3.0, 1.0, 2.0, 0.0),\n vec4f(-1.0, -3.0, 0.0, 2.0));\n struct VertexOutput {\n @builtin(position) position: vec4f,\n @location(0) uv: vec2f\n };\n @vertex\n fn vertexMain(@builtin(vertex_index) vertexIndex: u32) -> VertexOutput {\n var output: VertexOutput;\n output.uv = posTex[vertexIndex].zw;\n output.position = vec4f(posTex[vertexIndex].xy, 0.0, 1.0);\n return output;;\n }\n @group(0) @binding(0) var texSampler: sampler;\n @group(0) @binding(1) var texture: texture_multisampled_2d;\n struct Display {\n exposure: f32,\n channels: f32,\n numChannels: f32,\n minRange: f32,\n maxRange: f32,\n _pad1: f32,\n _pad2: f32,\n _pad3: f32\n };\n @group(1) @binding(0) var display: Display; \n @fragment\n fn fragmentMain(input: VertexOutput) -> @location(0) vec4f {\n var coords = vec2i(input.uv * vec2f(textureDimensions(texture)));\n var color = textureLoad(texture, coords, 0);\n if (display.numChannels == 1.0) {\n if (display.minRange != display.maxRange) {\n if (color.r < display.minRange) {\n color = vec4f(0.0, 0.0, 0.0, color.a);\n } else if (color.r > display.maxRange) {\n color = vec4f(1.0, 1.0, 1.0, color.a);\n } else {\n color = vec4f((color.r - display.minRange) / (display.maxRange - display.minRange), 0.0, 0.0, color.a);\n }\n }\n color = vec4f(color.r, color.r, color.r, 1.0);\n } else if (display.numChannels == 2.0) {\n color = vec4f(color.r, color.g, 0.0, 1.0);\n }\n if (display.channels == 1.0) { // R\n var rgb = color.rgb * display.exposure;\n return vec4f(rgb.r, 0.0, 0.0, color.a);\n } else if (display.channels == 2.0) { // G\n var rgb = color.rgb * display.exposure;\n return vec4f(0.0, rgb.g, 0.0, color.a);\n } else if (display.channels == 3.0) { // B\n var rgb = color.rgb * display.exposure;\n return vec4f(0.0, 0.0, rgb.b, color.a);\n } else if (display.channels == 4.0) { // A\n var a = color.a * display.exposure;\n return vec4f(a, a, a, color.a);\n } else if (display.channels == 5.0) { // Luminance\n var luminance = dot(color.rgb, vec3f(0.2126, 0.7152, 0.0722));\n var rgb = vec3f(luminance) * display.exposure;\n return vec4f(rgb, color.a);\n }\n\n // RGB\n var rgb = color.rgb * display.exposure;\n return vec4f(rgb, color.a);\n }',c.depthToFloatShader='\n var posTex:array = array(\n vec4f(-1.0, 1.0, 0.0, 0.0),\n vec4f(3.0, 1.0, 2.0, 0.0),\n vec4f(-1.0, -3.0, 0.0, 2.0));\n struct VertexOutput {\n @builtin(position) position: vec4,\n @location(0) uv : vec2\n };\n @vertex\n fn vertexMain(@builtin(vertex_index) vertexIndex: u32) -> VertexOutput {\n var output: VertexOutput;\n output.uv = posTex[vertexIndex].zw;\n output.position = vec4f(posTex[vertexIndex].xy, 0.0, 1.0);\n return output;;\n }\n \n @binding(0) @group(0) var depth: texture_depth_2d;\n @fragment\n fn fragmentMain(input: VertexOutput) -> @location(0) vec4 {\n var depthSize = textureDimensions(depth);\n var coords = vec2(i32(f32(depthSize.x) * input.uv.x),\n i32(f32(depthSize.y) * input.uv.y));\n var d = textureLoad(depth, coords, 0);\n return vec4(d, 0.0, 0.0, 1.0);\n }',c.depthToFloatMultisampleShader='\n var posTex:array = array(\n vec4f(-1.0, 1.0, 0.0, 0.0),\n vec4f(3.0, 1.0, 2.0, 0.0),\n vec4f(-1.0, -3.0, 0.0, 2.0));\n struct VertexOutput {\n @builtin(position) position: vec4,\n @location(0) uv : vec2\n };\n @vertex\n fn vertexMain(@builtin(vertex_index) vertexIndex: u32) -> VertexOutput {\n var output: VertexOutput;\n output.uv = posTex[vertexIndex].zw;\n output.position = vec4f(posTex[vertexIndex].xy, 0.0, 1.0);\n return output;;\n }\n \n @binding(0) @group(0) var depth: texture_depth_multisampled_2d;\n @fragment\n fn fragmentMain(input: VertexOutput) -> @location(0) vec4 {\n var depthSize = textureDimensions(depth);\n var coords = vec2(i32(f32(depthSize.x) * input.uv.x),\n i32(f32(depthSize.y) * input.uv.y));\n var d = textureLoad(depth, coords, 0);\n return vec4(d, 0.0, 0.0, 1.0);\n }';const p={CaptureBufferData:'webgpu_inspect_capture_buffer_data',CaptureBuffers:'webgpu_inspect_capture_buffers',DeleteObjects:'webgpu_inspect_delete_objects',ValidationError:'webgpu_inspect_validation_error',MemoryLeakWarning:'webgpu_inspect_memory_leak_warning',DeltaTime:'webgpu_inspect_delta_time',CaptureFrameResults:'webgpu_inspect_capture_frame_results',CaptureFrameCommands:'webgpu_inspect_capture_frame_commands',ObjectSetLabel:'webgpu_inspect_object_set_label',AddObject:'webgpu_inspect_add_object',ResolveAsyncObject:'webgpu_inspect_resolve_async_object',DeleteObject:'webgpu_inspect_delete_object',CaptureTextureFrames:'webgpu_inspect_capture_texture_frames',CaptureTextureData:'webgpu_inspect_capture_texture_data',CaptureBufferData:'webgpu_inspect_capture_buffer_data',Recording:'webgpu_record_recording',RecordingCommand:'webgpu_record_command',RecordingDataCount:'webgpu_record_data_count',RecordingData:'webgpu_record_data'};p.values=new Set(Object.values(p));const d='webgpu_inspect_request_texture',u='webgpu_inspect_compile_shader',l='webgpu_inspect_revert_shader',h='webgpu_inspector_capture';class _{constructor(e){this.windowSize=e,this.buffer=[],this.sum=0}add(e){this.buffer.push(e),this.buffer.length>this.windowSize&&(this.sum-=this.buffer.shift()),this.sum+=e}get average(){return 0===this.buffer.length?0:this.sum/this.buffer.length}}function m(e,t){return e+t-1&~(t-1)}e.webgpuInspector=null,(()=>{const r=self,s=self.window,i=self.document,f=self.sessionStorage,g=self.postMessage,b='WEBGPU_INSPECTOR_CAPTURE_FRAME',y=262144;e.webgpuInspector=new class P{constructor(){if(this._captureFrameCommands=[],this._frameData=[],this._frameRenderPassCount=0,this._captureTexturedBuffers=[],this._currentFrame=null,this._frameIndex=0,this._initalized=!0,this._objectID=1,this._lastFrameTime=0,this._frameCommandCount=0,this._captureFrameRequest=!1,this._errorChecking=1,this._trackedObjects=new Map,this._trackedObjectInfo=new Map,this._bindGroupCount=0,this._captureTextureRequest=new Map,this._toDestroy=[],this._objectReplacementMap=new Map,this._captureBuffersCount=0,this._captureTempBuffers=[],this._mappedTextureBufferCount=0,this._encodingTextureChunkCount=0,this._mappedBufferCount=0,this._encodingBufferChunkCount=0,this._captureData=null,this._frameRate=new _(60),this._captureTimestamps=!1,this._timestampQuerySet=null,this._timestampBuffer=null,this._timestampIndex=0,this._maxTimestamps=2e3,!navigator.gpu)return;if(i?.body){const e=i.createElement('div');e.style='position: absolute; z-index: 1000000; margin-left: 10px; margin-top: 5px; padding-left: 5px; padding-right: 10px; background-color: rgba(0, 0, 1, 0.75); border-radius: 5px; box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.5); color: #fff; font-size: 12pt;',i.body.insertBefore(e,i.body.firstChild),this._inspectingStatus=i.createElement('div'),this._inspectingStatus.title='WebGPU Inspector Running',this._inspectingStatus.style='height: 10px; width: 10px; display: inline-block; margin-right: 5px; background-color: #ff0; border-radius: 50%; border: 1px solid #000; box-shadow: inset -4px -4px 4px -3px rgb(255,100,0), 2px 2px 3px rgba(0,0,0,0.8);',e.appendChild(this._inspectingStatus),this._inspectingStatusFrame=i.createElement('div'),this._inspectingStatusFrame.style='display: inline-block;',this._inspectingStatusFrame.textContent='Frame: 0',e.appendChild(this._inspectingStatusFrame),this._inspectingStatusText=i.createElement('div'),this._inspectingStatusText.style='display: inline-block; margin-left: 10px;',e.appendChild(this._inspectingStatusText)}this._gpuWrapper=new n(this);const e=this;this._gpuWrapper.onPromise.addListener(this._onAsyncPromise,this),this._gpuWrapper.onPromiseResolve.addListener(this._onAsyncResolve,this),this._gpuWrapper.onPreCall.addListener(this._preMethodCall,this),this._gpuWrapper.onPostCall.addListener(this._postMethodCall,this),this._garbageCollectectedObjects=[],this._garbageCollectionRegistry=new FinalizationRegistry((t=>{if(t>0){e._garbageCollectectedObjects.push(t);const r=e._trackedObjectInfo.get(t);r&&(r===GPUBindGroup&&e._bindGroupCount--,r!==GPUBuffer&&r!==GPUTexture&&r!==GPUDevice||e._memoryLeakWarning(t,r)),e._garbageCollectectedObjects.length>100&&(e._postMessage({action:p.DeleteObjects,idList:e._garbageCollectectedObjects}),e._garbageCollectectedObjects.length=0)}t>0&&(e._trackedObjects.delete(t),e._trackedObjectInfo.delete(t),e._captureTextureRequest.delete(t),e._objectReplacementMap.delete(t))}));if(setInterval((()=>{e._garbageCollectectedObjects.length>0&&(e._postMessage({action:p.DeleteObjects,idList:e._garbageCollectectedObjects}),e._garbageCollectectedObjects.length=0)}),200),i){const t=i.getElementsByTagName('canvas');for(const e of t)this._wrapCanvas(e);const r=i.createElement;i.createElement=t=>{const s=r.call(i,t);return'canvas'===t&&e._wrapCanvas(s),s}}const t=requestAnimationFrame;this._currentFrameTime=0,requestAnimationFrame=r=>t((function(t){if(!e._currentFrameTime){e._currentFrameTime=t,e._frameStart(t);const s=r(t);s instanceof Promise?Promise.all([s]).then((()=>{e._frameEnd(t),e._currentFrameTime=0})):(e._frameEnd(t),e._currentFrameTime=0)}})),r.addEventListener('message',(t=>{if(s&&t.source!==s)return;const r=t.data;if('object'==typeof r&&r.__webgpuInspector)if(r.action===p.DeltaTime)r.__webgpuInspectorWorker&&this._updateFrameRate(r.deltaTime);else if(r.action===d){const t=r.id;e._requestTexture(t)}else if(r.action===u){const t=r.id,s=r.code;e._compileShader(t,s)}else if(r.action===l){const t=r.id;e._revertShader(t)}else r.action===h&&null==s&&('String'===r.data.constructor.name&&(r.data=JSON.parse(r.data)),e._captureData=r.data)}))}captureWorker(e){this._wrapCanvas(e)}disableRecording(){this._gpuWrapper.disableRecording()}enableRecording(){this._gpuWrapper.enableRecording()}_postMessage(e){e.__webgpuInspector=!0,e.__webgpuInspectorPage=!0,e.__webgpuInspectorWorker=!s,g(e)}_updateCanvasAttachment(e){let t=null;e.resolveTarget?t=e.resolveTarget:e.view&&(t=e.view);const r=t?.__texture,s=r?.__context;if(!s)return;s.__captureTexture&&(s.__captureTexture.width==r.width&&s.__captureTexture.height==r.height&&s.__captureTexture.format==r.format||(this.disableRecording(),s.__captureTexture.destroy(),s.__captureTexture=null,this.enableRecording()));const o=s.__device;if(o){this.disableRecording();const i=o.createTexture({size:[r.width,r.height,1],format:r.format,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC});if(s.__captureTexture=i,i){i.__id=r.__id,i.__canvasTexture=r,i.__context=s;const o=i.createView();o.__texture=i,o.__canvasView=t,i.__view=o,o.__context=s,e.resolveTarget?e.resolveTarget=o:e.view=o}this.enableRecording()}}_preMethodCall(e,t,r){if('requestDevice'===t&&(0===r.length&&(r[0]={}),r[0].requiredFeatures?r[0].requiredFeatures.push('timestamp-query'):r[0].requiredFeatures=['timestamp-query']),'setPipeline'===t){let e=r[0];const t=this._objectReplacementMap.get(e.__id);t&&t.replacement&&(r[0]=t.replacement)}if('createTexture'===t&&(r[0].usage|=GPUTextureUsage.COPY_SRC|GPUTextureUsage.TEXTURE_BINDING),'createBuffer'===t&&(r[0].usage&GPUBufferUsage.MAP_READ||(r[0].usage|=GPUBufferUsage.COPY_SRC)),'createShaderModule'!==t&&'createRenderPipeline'!==t&&'createComputePipeline'!==t&&'createBindGroup'!==t||this._errorChecking>0&&(this._gpuWrapper.disableRecording(),e.pushErrorScope('validation'),this._gpuWrapper.enableRecording()),'beginRenderPass'!==t&&'beginComputePass'!==t||this._captureTimestamps&&this._captureFrameRequest&&(!this._timestampQuerySet&&e.__device&&(this._timestampQuerySet=e.__device.createQuerySet({type:'timestamp',count:this._maxTimestamps}),this._timestampBuffer=e.__device.createBuffer({size:8*this._maxTimestamps,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC})),!r[0].timestampWrites&&this._timestampIndex0){const r=e.__device.createCommandEncoder();r.resolveQuerySet(this._timestampQuerySet,0,this._timestampIndex,this._timestampBuffer,0),t=e.__device.createBuffer({size:8*this._timestampIndex,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),t.__count=this._timestampIndex,r.copyBufferToBuffer(this._timestampBuffer,0,t,0,8*this._timestampIndex),e.__device.queue.submit([r.finish()]),this._timestampIndex=0}const s=this;if(this._captureTextureRequest.size>0){const t=r[0];let o=!1;for(const e of t)o|=!!e.__rendersToCanvas;this._captureTextureRequest.forEach(((t,r)=>{(r>0||o)&&(t=t||s._trackedObjects.get(r)?.deref(),s._captureTextureBuffer(e.__device,null,t),s._captureTextureRequest.delete(r))}))}const o=[...this._captureTempBuffers];this._captureTempBuffers.length=0;const i=[...this._captureTexturedBuffers];this._captureTexturedBuffers.length=0;const n=[...this._toDestroy];this._toDestroy.length=0,e.onSubmittedWorkDone().then((async()=>{s.disableRecording(),t&&s._sendTimestampBuffer(t.__count,t),o.length&&s._sendCapturedBuffers(o),i.length&&s._sendCaptureTextureBuffers(i);for(const e of n)e.destroy();s.enableRecording()})),this.enableRecording()}let n;if('createShaderModule'!==t&&'createRenderPipeline'!==t&&'createComputePipeline'!==t&&'createBindGroup'!==t||this._errorChecking>0&&(this.disableRecording(),e.popErrorScope().then((e=>{if(e){console.error(e.message);const t=s?.__id??0;self._postMessage({action:p.ValidationError,id:t,message:e.message,stacktrace:i})}})),this.enableRecording()),'getCurrentTexture'===t?(e.__id||(this._wrapObject(e),this._trackObject(e.__id,e)),n=-e.__id,e.__canvasTexture=new WeakRef(s),s.__frameIndex=this._frameIndex):'createView'===t&&e.__id<0&&(n=e.__id-.5),e instanceof GPUDevice&&void 0===e?.__id&&(this._wrapDevice(null,e),e.__adapter||navigator.gpu.requestAdapter().then((t=>{e.__adapter=t}))),s)if(o.has(s.constructor)&&this._wrapObject(s,n),'createShaderModule'===t||'createRenderPipeline'===t)s.__descriptor=r[0],s.__device=e,this._objectReplacementMap.set(s.__id,{id:s.__id,object:new WeakRef(s),replacement:null});else if('getCurrentTexture'===t)s.__context=e,this._trackObject(s.__id,s),s.label='CanvasTexture';else if('createTexture'===t)this._trackObject(s.__id,s);else if('createView'!==t||n){if('createBuffer'===t)this._trackObject(s.__id,s);else if('createBindGroup'===t)this._trackObject(s.__id,s),s.__descriptor=r[0];else if('setBindGroup'===t){const t=r[1].__descriptor;if(t)for(const r of t.entries)if(r.resource instanceof GPUTextureView&&r.resource.__id<0){if(r.resource.__texture.__frameIndex{const i={vendor:o.vendor,architecture:o.architecture,device:o.device,description:o.description,features:s._gpuToArray(e.features),limits:s._gpuToObject(e.limits),isFallbackAdapter:e.isFallbackAdapter,wgslFeatures:s._gpuToArray(navigator.gpu.wgslLanguageFeatures)};s._sendAddObjectMessage(t,0,'Adapter',JSON.stringify(i),r)}))}_wrapDevice(e,t,r,s,o){if(e&&void 0===e.__id&&this._wrapAdapter(e,void 0,o),t&&void 0===t.__id){t.queue.__device=t;const i=this;t.addEventListener('uncapturederror',(e=>{i._postMessage({action:p.ValidationError,id:0,message:e.error.message})})),s??=[],this._wrapObject(t,r);const n=s[0]??{},a=t.__id,c=e?.__id??0;n.features=this._gpuToArray(t.features),n.limits=this._gpuToObject(t.limits),this._trackObject(a,t),this._sendAddObjectMessage(r,c,'Device',JSON.stringify(n),o),t.__adapter=e,this._device=t}}clear(){this._captureFrameCommands.length=0,this._currentFrame=null}getNextId(e){return e instanceof GPUCommandEncoder||e instanceof GPUComputePassEncoder||e instanceof GPURenderPassEncoder||e instanceof GPUCommandBuffer?0:this._objectID++}_memoryLeakWarning(e,t){if(t){const e=`${t.name} was garbage collected without being explicitly destroyed. These objects should explicitly destroyed to avoid GPU memory leaks.`;this._postMessage({action:p.ValidationError,id:0,message:e})}}_isPrimitiveType(e){return!e||e.constructor===String||e.constructor===Number||e.constructor===Boolean}_isTypedArray(e){return e&&(e instanceof ArrayBuffer||e.buffer instanceof ArrayBuffer)}_isArray(e){return e&&e.constructor===Array}_duplicateArray(e,t){const r=new Array(e.length);for(let s=0,o=e.length;s{if(t){console.error(t.message);const r=e??0;a._postMessage({action:p.ValidationError,id:r,message:t.message})}})),this._errorChecking++,this.enableRecording(),r.replacement=n;for(const e of this._objectReplacementMap.values()){const t=e.object.deref(),r=t instanceof GPURenderPipeline,i=t instanceof GPUComputePipeline;if(r||i){const i=t.__descriptor;let a=!1,c=null;if(i.vertex?.module===s&&(c||(c=this._duplicateObject(i)),a=!0,c.vertex.module=n),i.fragment?.module===s&&(c||(c=this._duplicateObject(i)),a=!0,c.fragment.module=n),i.compute?.module===s&&(c||(c=this._duplicateObject(i)),a=!0,c.compute.module=n),a){this.disableRecording(),this._errorChecking--,c.__replacement=e.id,o.pushErrorScope('validation');const t=r?o.createRenderPipeline(c):o.createComputePipeline(c),s=this;o.popErrorScope().then((t=>{if(t){console.error(t.message);const r=e.id??0;s._postMessage({action:p.ValidationError,id:r,message:t.message})}})),this._errorChecking++,this.enableRecording(),e.replacement=t}}}}_requestTexture(e){if(e<0)this._captureTextureRequest.set(e,null);else{const t=this._trackedObjects.get(e),r=t?.deref();r instanceof GPUTexture&&this._captureTextureRequest.set(e,r)}}_updateStatusMessage(){let e='';this._captureTexturedBuffers.length>0&&(e+=`Texture: ${this._captureTexturedBuffers.length} `),this._mappedTextureBufferCount>0&&(e+=`Pending Texture Reads: ${this._mappedTextureBufferCount} `),this._encodingTextureChunkCount>0&&(e+=`Pending Texture Encoding: ${this._encodingTextureChunkCount} `),this._captureBuffersCount&&(e+=`Buffers: ${this._captureBuffersCount} `),this._mappedBufferCount>0&&(e+=`Pending Buffer Reads: ${this._mappedBufferCount} `),this._encodingBufferChunkCount>0&&(e+=`Pending Buffer Encoding: ${this._encodingBufferChunkCount} `),e&&(e=`Capturing: ${e} `),this._inspectingStatusFrame&&(this._inspectingStatusText.textContent=e)}_updateFrameRate(e){this._frameRate.add(e),this._frameIndex++,this._inspectingStatusFrame&&(this._inspectingStatusFrame.textContent=`Frame: ${this._frameIndex} : ${this._frameRate.average.toFixed(2)}ms`)}_frameStart(e){let t=0;if(0==this._lastFrameTime?this._lastFrameTime=e:(t=e-this._lastFrameTime,this._postMessage({action:p.DeltaTime,deltaTime:t}),this._lastFrameTime=e,this._frameRate.add(t)),f){const e=f.getItem(b);if(e){try{this._captureData=JSON.parse(e)}catch(e){this._captureData=null}f.removeItem(b)}}if(this._captureData&&(this._captureData.frame<0||this._frameIndex>=this._captureData.frame)&&(this._captureMaxBufferSize=this._captureData.maxBufferSize||262144,this._captureFrameRequest=!0,this._gpuWrapper.recordStacktraces=!0,this._captureData=null,this._captureTimestamps)){if(this.disableRecording(),this._device){this._timestampQuerySet||(this._timestampQuerySet=this._device.createQuerySet({type:'timestamp',count:this._maxTimestamps}),this._timestampBuffer=this._device.createBuffer({size:8*this._maxTimestamps,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}));const e=this._device.createCommandEncoder();e.beginComputePass({timestampWrites:{querySet:this._timestampQuerySet,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1}}).end(),this._device.queue.submit([e.finish()]),this._timestampIndex=2}this.enableRecording()}this._frameData.length=0,this._captureFrameCommands.length=0,this._frameRenderPassCount=0,this._frameIndex++,this._frameCommandCount=0,this._inspectingStatusFrame&&(this._inspectingStatusFrame.textContent=`Frame: ${this._frameIndex} : ${this._frameRate.average.toFixed(2)}ms`)}_frameEnd(e){if(this._captureFrameCommands.length){const e=2e3,t=Math.ceil(this._captureFrameCommands.length/e);this._postMessage({action:p.CaptureFrameResults,frame:this._frameIndex,count:this._captureFrameCommands.length,batches:t});for(let t=0;t{const i=r.call(e,s,o);return i instanceof GPUCanvasContext&&(t._wrapObject(i),t._trackObject(i.__id,i)),i}}_wrapObject(e,t){if(e&&void 0===e.__id){if(e.__id=t??this.getNextId(e),this._garbageCollectionRegistry.register(e,e.__id),void 0!==e.label){const t=e.label;e._label=t;const r=this;Object.defineProperty(e,'label',{enumerable:!0,configurable:!0,get(){return this._label},set(e){if(e!==this._label){this._label=e;const t=this.__id;r._postMessage({action:p.ObjectSetLabel,id:t,label:e})}}})}e instanceof GPUDevice&&void 0===e.queue.__id&&this._wrapObject(e.queue)}}_gpuToArray(e){const t=[];if(e)for(const r of e)t.push(r);return t}_gpuToObject(e){const t={};if(e)for(const r in e)t[r]=e[r];return t}_stringifyDescriptor(e){const t=this._duplicateObject(e,!0)??{};let r=null;try{r=JSON.stringify(t)}catch(e){console.log(e.message)}return r}_sendAddObjectMessage(e,t,r,s,o,i){this._postMessage({action:p.AddObject,id:e,parent:t,type:r,descriptor:s,stacktrace:o,pending:i})}_recordCommand(e,t,r,s,o){const i=e?.__id??0;if('destroy'===t){e===this._device&&(this._device=null);const t=e.__id;e.__destroyed=!0,t>0&&(this._trackedObjects.delete(t),this._trackedObjectInfo.delete(t),this._objectReplacementMap.delete(t)),e instanceof GPUBindGroup&&this._bindGroupCount--,t>=0&&(this._captureTextureRequest.delete(t),this._postMessage({action:p.DeleteObject,id:t}))}else if('createShaderModule'===t){const e=r.__id;s[0].__replacement||this._sendAddObjectMessage(e,i,'ShaderModule',this._stringifyDescriptor(s[0]),o)}else if('createBuffer'===t){const e=r.__id;this._sendAddObjectMessage(e,i,'Buffer',this._stringifyDescriptor(s[0]),o)}else if('createTexture'===t){const t=r.__id;this._sendAddObjectMessage(t,i,'Texture',this._stringifyDescriptor(s[0]),o),r.__device=e}else if('getCurrentTexture'===t){const e=r.__id;if(r){const t={size:[r.width,r.height,r.depthOrArrayLayers],mipLevelCount:r.mipLevelCount,sampleCount:r.sampleCount,dimension:r.dimension,format:r.format,usage:r.usage},s=JSON.stringify(t);this._sendAddObjectMessage(e,i,'Texture',s,o)}}else if('createView'===t){const t=r.__id;r.__texture=e,this._sendAddObjectMessage(t,i,'TextureView',this._stringifyDescriptor(s[0]),o)}else if('createSampler'===t){const e=r.__id;this._sendAddObjectMessage(e,i,'Sampler',this._stringifyDescriptor(s[0]),o)}else if('createBindGroup'===t){this._bindGroupCount++;const e=r.__id;r.__descriptor=s[0],this._sendAddObjectMessage(e,i,'BindGroup',this._stringifyDescriptor(s[0]),o)}else if('createBindGroupLayout'===t){const e=r.__id;r.__descriptor=s[0],this._sendAddObjectMessage(e,i,'BindGroupLayout',this._stringifyDescriptor(s[0]),o)}else if('createPipelineLayout'===t){const e=r.__id;this._sendAddObjectMessage(e,i,'PipelineLayout',this._stringifyDescriptor(s[0]),o)}else if('createRenderPipeline'===t){const e=r.__id;s[0].__replacement||(this._sendAddObjectMessage(e,i,'RenderPipeline',this._stringifyDescriptor(s[0]),o),s[0].vertex?.module&&(r.__vertexModule=s[0].vertex?.module),s[0].fragment?.module&&(r.__fragmentModule=s[0].fragment?.module))}else if('createComputePipeline'===t){const e=r.__id;s[0].__replacement||(this._sendAddObjectMessage(e,i,'ComputePipeline',this._stringifyDescriptor(s[0]),o),s[0].compute?.module&&(r.__computeModule=s[0].compute?.module))}else'createCommandEncoder'===t&&(r.__device=e);this._captureFrameRequest&&this._captureCommand(e,t,s,o,r)}_captureCommand(e,t,r,s,o){const i=this._captureFrameCommands.length,n=r;1===n.length&&void 0===n[0]&&(n.length=0),('beginRenderPass'===t||'beginComputePass'===t||'createCommandEncoder'===t||'finish'===t)&&(o.__id=`_${i}`);let a=null;if('setBindGroup'===t){a=[];const t=n[0],r=n[1];if(a.push(t),a.push(r),n.length>2&&n[2]?.length){const e=n[2];if(e.length>0)if(e instanceof Uint32Array){const t=n[3],r=n[4];if(r>0){const s=new Uint32Array(e.buffer,4*t,r);a.push(s)}}else a.push(e)}const s=a.length>2?a[2]:null;let o=0;const c=r.__descriptor,p=c.layout?.__descriptor;if(c)for(const t in c.entries){const r=c.entries[t],n=p?.entries[t],a=r?.resource?.buffer,d=n?.buffer?.hasDynamicOffset??!1;if(a){let n=r.resource.offset??0;const c=m(r.resource.size??a.size-n,4);c3){const e=n[3]??0,t=n[4],s=r instanceof ArrayBuffer?r:r.buffer;s&&(t>0?r=new Uint8Array(s,e,t):e>0&&(r=new Uint8Array(s,e)))}a.push(r)}else a=n;if(a=this._processCommandArgs(a),this._captureFrameCommands.push({class:e.constructor.name,object:e.__id,result:o?.__id??0,commandId:i,method:t,args:a,stacktrace:s}),'setIndexBuffer'===t&&(e.__indexBuffer=r),'setVertexBuffer'===t){const t=r[0],s=r[1],o=r[2]??0,n=r[3]??s.size-o;e.__captureBuffers||(e.__captureBuffers=[]),e.__captureBuffers.push({commandId:i,entryIndex:t,buffer:s,offset:o,size:n}),this._captureBuffersCount++,this._updateStatusMessage()}if('setIndexBuffer'===t){const t=r[0],s=t.size;e.__captureBuffers||(e.__captureBuffers=[]),e.__captureBuffers.push({commandId:i,entryIndex:0,buffer:t,offset:0,size:s}),this._captureBuffersCount++,this._updateStatusMessage()}if('drawIndirect'===t||'drawIndexedIndirect'===t||'dispatchWorkgroupsIndirect'===t){const t=r[0],s=0,o=t.size;e.__captureBuffers||(e.__captureBuffers=[]),e.__captureBuffers.push({commandId:i,entryIndex:0,buffer:t,offset:s,size:o}),this._captureBuffersCount++,this._updateStatusMessage()}if('beginRenderPass'===t){if(r[0]?.colorAttachments?.length>0){o.__captureTextureViews=new Set;for(const e of r[0].colorAttachments){if(!e)continue;const t=e.resolveTarget??e.view;o.__captureTextureViews.add(t)}}if(o.__descriptor=r[0],r[0]?.depthStencilAttachment){o.__captureTextureViews||(o.__captureTextureViews=new Set);const e=r[0].depthStencilAttachment,t=e.resolveTarget??e.view;o.__captureTextureViews.add(t)}this._inComputePass=!1,o.__commandEncoder=e}else if('beginComputePass'===t)o.__commandEncoder=e,this._inComputePass=!0;else if('end'===t){this._inComputePass=!1;const t=e.__commandEncoder;if(e.__captureBuffers?.length>0&&(this._recordCaptureBuffers(t,e.__captureBuffers),this._updateStatusMessage()),e.__captureTextureViews?.size>0){let r=10*this._frameRenderPassCount;for(const s of e.__captureTextureViews){const e=s.__texture;e&&this._captureTextureBuffer(t?.__device,t,e,r++)}e.__captureTextureViews.clear()}e.__commandEncoder=null,e instanceof GPURenderPassEncoder&&this._frameRenderPassCount++}}_sendCaptureTextureBuffers(e){const t=[];for(const r of e)t.push(r.id);let r=0;for(const t of e){const e=t.tempBuffer.size;r+=Math.ceil(e/y)}this._postMessage({action:p.CaptureTextureFrames,chunkCount:r,count:e.length,textures:t});for(const t of e){const{id:e,tempBuffer:r,passId:s}=t;this._mappedTextureBufferCount++;const o=this;r.mapAsync(GPUMapMode.READ).then((()=>{o._mappedTextureBufferCount--,o._updateStatusMessage();const t=r.getMappedRange(),i=new Uint8Array(t);o._sendTextureData(e,s,i),r.destroy()})).catch((e=>{console.error(e)}))}this._updateStatusMessage()}_sendTextureData(e,r,s){const o=s.length,i=Math.ceil(o/y),n=this;for(let a=0;a{n._postMessage({action:p.CaptureTextureData,id:e,passId:r,offset:c,size:o,index:a,count:i,chunk:t}),n._encodingTextureChunkCount--,n._updateStatusMessage()})).catch((e=>{console.log('Error encoding texture data:',e)}))}}_getTextureUtils(e){return e?(e.__textureUtils||(e.__textureUtils=new c(e)),e.__textureUtils):null}_sendBufferData(e,r,s){const o=s.length,i=Math.ceil(o/y),n=this;for(let a=0;a{n._postMessage({action:p.CaptureBufferData,commandId:e,entryIndex:r,offset:c,size:o,index:a,count:i,chunk:t}),n._encodingBufferChunkCount--,n._updateStatusMessage()})).catch((e=>{console.error(e.message)}))}}_sendTimestampBuffer(e,t){const r=this;t.mapAsync(GPUMapMode.READ).then((()=>{const e=t.getMappedRange(),s=new Uint8Array(e);r._sendBufferData(-1e3,-1e3,s),t.destroy()})).catch((e=>{console.error(e)}))}_sendCapturedBuffers(e){if(e.length>0){let t=0;for(const r of e){const e=r.tempBuffer.size;t+=Math.ceil(e/y)}this._postMessage({action:p.CaptureBuffers,count:e.length,chunkCount:t})}e.length;for(const t of e){const e=t.tempBuffer,r=t.commandId,s=t.entryIndex,o=this;this._mappedBufferCount++,this._updateStatusMessage(),e.mapAsync(GPUMapMode.READ).then((()=>{o._mappedBufferCount--,o._updateStatusMessage();const t=e.getMappedRange(),i=new Uint8Array(t);o._sendBufferData(r,s,i),e.destroy()})).catch((e=>{console.error(e)}))}}_recordCaptureBuffers(e,t){const r=e?.__device;if(!r)return this._captureBuffersCount-=t.length,void(t.length=0);for(const s of t){const{commandId:t,entryIndex:o,buffer:i,offset:n,size:a}=s;if(i.__destroyed)continue;let c=null;this.disableRecording();try{c=r.createBuffer({size:a,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,label:`BUFFER CAPTURE TEMP [${t},${o}]`}),e.copyBufferToBuffer(i,n,c,0,a),this._captureTempBuffers.push({commandId:t,entryIndex:o,tempBuffer:c})}catch(e){console.log(e)}this.enableRecording()}this._captureBuffersCount-=t.length,t.length=0}_captureTextureBuffer(e,t,r,s){if(!e)return;const o=!t;t??=e.createCommandEncoder(),s??=-1;const i=r.__id;let n=r.format,c=n?a[n]:void 0;if(!c)return;if(c.isDepthStencil){this.disableRecording();try{r=this._getTextureUtils(e).copyDepthTexture(r,'r32float',t)}catch(e){return this.enableRecording(),void console.log(e)}this.enableRecording(),n=r.format,c=n?a[n]:void 0,r.__id=i,this._toDestroy.push(r)}else if(r.sampleCount>1){this.disableRecording();try{(r=this._getTextureUtils(e).copyMultisampledTexture(r)).__id=i,this._toDestroy.push(r)}catch(e){return this.enableRecording(),void console.log(e)}this.enableRecording()}const p=r.width,d=r.height||1,u=r.depthOrArrayLayers||1,l=p*c.bytesPerBlock+255&-256,h=l*d*u;if(!h)return;const _={width:p,height:d,depthOrArrayLayers:u};let m=null;try{this.disableRecording(),m=e.createBuffer({size:h,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});const s='all';t.copyTextureToBuffer({texture:r,aspect:s},{buffer:m,bytesPerRow:l,rowsPerImage:d},_)}catch(e){console.log(e)}o&&e.queue.submit([t.finish()]),this.enableRecording(),m&&(this._captureTexturedBuffers.push({id:i,tempBuffer:m,width:p,height:d,depthOrArrayLayers:u,format:n,passId:s}),this._updateStatusMessage())}_addCommandData(e){if(this._captureFrameRequest){const t=this._frameData.length;return this._frameData.push(e),t}return-1}_isHTMLImageElement(e){return!!s&&(e instanceof HTMLImageElement||e instanceof HTMLCanvasElement||e instanceof HTMLVideoElement)}_processCommandArgs(e){if(!e||e.constructor===Number||e.constructor===String||e.constructor===Boolean)return e;if(void 0!==e.__id)return{__id:e.__id,__class:e.constructor.name};if(e instanceof ImageBitmap||e instanceof ImageData||e instanceof OffscreenCanvas||e instanceof VideoFrame||this._isHTMLImageElement(e))return`@-1 ${e.constructor.name} ${e.width} ${e.height}`;if(e instanceof Array||void 0!==e.buffer){const t=100;if(e.length>t){return`@${this._addCommandData(e)} ${e.constructor.name} ${e.byteLength}`}const r=[];for(const t in e)r[t]=this._processCommandArgs(e[t]);return r}if(e instanceof ArrayBuffer){return`@${this._addCommandData(e)} ${e.constructor.name} ${e.byteLength}`}if(e instanceof Object){const t={};for(const r in e)t[r]=this._processCommandArgs(e[r]);return t}return e}};const x=Worker;class C{constructor(){this._worker=new x(...arguments),function(e){if(!e.__webgpuInspector){if(e.__webgpuInspector=!0,e.terminate){const t=e.terminate;e.terminate=function(){const r=t.call(e,...arguments);return e.__webgpuInspector=!1,r}}e.addEventListener('message',(e=>{e.data.__webgpuInspector&&window.postMessage(e.data,'*')})),window.addEventListener('message',(t=>{e.__webgpuInspector&&t.data.__webgpuInspector&&!t.data.__webgpuInspectorPage&&e.postMessage(t.data)}))}}(this._worker)}}for(const e in x.prototype)'constructor'!==e&&(C.prototype[e]=function(){return this._worker[e].apply(this._worker,arguments)});Worker=C})(),Object.defineProperty(e,'__esModule',{value:!0})}({}); +!function(e){async function t(e,t='application/octet-stream'){return await new Promise(((r,s)=>{const o=Object.assign(new FileReader,{onload:()=>r(o.result),onerror:()=>s(o.error)});o.readAsDataURL(new File([e],'',{type:t}))}))}class r{constructor(e){this._lastSlotId=0,this.slots=new Map,e&&(this.name=e)}static get enabled(){return 0==r._disableSignals}static get disabled(){return r._disableSignals>0}static disable(){return r._disableSignals++}static enable(e){return e?(r._disableSignals=0,0):r._disableSignals>0?r._disableSignals--:0}static disconnect(e,t,s){for(const o in e){const i=e[o];i.constructor===r&&i.disconnect(t,s)}}static getSignals(e,t){t=t||[];for(const s in e){const o=e[s];o.constructor===r&&t.push(o)}return t}get hasListeners(){return this.slots.size>0}emit(){if(!r.disabled)for(const e of this.slots){const t=e[1][0],s=e[1][1]||t;t&&(t.constructor===r?t.emit.apply(s,arguments):t.apply(s,arguments))}}addListener(e,t){return this.isListening(e,t)?null:(this.slots.set(this._lastSlotId++,[e,t]),this._lastSlotId-1)}isListening(e,t){for(const r of this.slots){const s=r[1];if(e&&!t){if(s[0]===e||s[1]===e)return!0}else if(!e&&t){if(s[1]===t)return!0}else if(s[0]===e&&s[1]===t)return!0}return!1}disconnect(e,t){if(null==e&&null==t)return this.slots.clear(),!0;if(e.constructor===Number){const t=e;return!!this.slots.has(t)&&(this.slots.delete(t),!0)}let r=!1;for(const s of this.slots){const o=s[0],i=s[1];e&&!t?i[0]!==e&&i[1]!==e||(this.slots.delete(o),r=!0):!e&&t?i[1]===t&&(this.slots.delete(o),r=!0):i[0]===e&&i[1]===t&&(this.slots.delete(o),r=!0)}return r}}function s(){if(!Error.captureStackTrace)return'';const e={};if(Error.captureStackTrace(e,s),!e.stack)return'';return e.stack.split('\n').map((e=>e.split('at ')[1])).slice(2).filter((e=>e&&!e.includes('webgpu_inspector.js'))).join('\n')}r._disableSignals=0;const o=new Set([GPUAdapter,GPUDevice,GPUBuffer,GPUTexture,GPUTextureView,GPUSampler,GPUBindGroupLayout,GPUBindGroup,GPUPipelineLayout,GPUShaderModule,GPUComputePipeline,GPURenderPipeline,GPUCommandBuffer,GPUCommandEncoder,GPUComputePassEncoder,GPURenderPassEncoder,GPURenderBundle,GPUQueue,GPUQuerySet,GPUCanvasContext]),i=new Set(['createBuffer','createTexture','createSampler','importExternalTexture','createBindGroupLayout','createPipelineLayout','createBindGroup','createShaderModule','createComputePipeline','createRenderPipeline','createComputePipelineAsync','createRenderPipelineAsync','createCommandEncoder','createRenderBundleEncoder','createQuerySet','createView']);class n{constructor(e){this._idGenerator=e,this.onPreCall=new r,this.onPostCall=new r,this.onPromise=new r,this.onPromiseResolve=new r,this.recordStacktraces=!1,this._skipRecord=0,this._wrapGPUTypes()}_wrapGPUTypes(){GPU.prototype.requestAdapter=this._wrapMethod('requestAdapter',GPU.prototype.requestAdapter),GPU.prototype.getPreferredFormat=this._wrapMethod('getPreferredFormat',GPU.prototype.getPreferredFormat),GPUAdapter.prototype.requestDevice=this._wrapMethod('requestDevice',GPUAdapter.prototype.requestDevice),GPUDevice.prototype.destroy=this._wrapMethod('destroy',GPUDevice.prototype.destroy),GPUDevice.prototype.createBuffer=this._wrapMethod('createBuffer',GPUDevice.prototype.createBuffer),GPUDevice.prototype.createTexture=this._wrapMethod('createTexture',GPUDevice.prototype.createTexture),GPUDevice.prototype.createSampler=this._wrapMethod('createSampler',GPUDevice.prototype.createSampler),GPUDevice.prototype.importExternalTexture=this._wrapMethod('importExternalTexture',GPUDevice.prototype.importExternalTexture),GPUDevice.prototype.createBindGroupLayout=this._wrapMethod('createBindGroupLayout',GPUDevice.prototype.createBindGroupLayout),GPUDevice.prototype.createPipelineLayout=this._wrapMethod('createPipelineLayout',GPUDevice.prototype.createPipelineLayout),GPUDevice.prototype.createBindGroup=this._wrapMethod('createBindGroup',GPUDevice.prototype.createBindGroup),GPUDevice.prototype.createShaderModule=this._wrapMethod('createShaderModule',GPUDevice.prototype.createShaderModule),GPUDevice.prototype.createComputePipeline=this._wrapMethod('createComputePipeline',GPUDevice.prototype.createComputePipeline),GPUDevice.prototype.createRenderPipeline=this._wrapMethod('createRenderPipeline',GPUDevice.prototype.createRenderPipeline),GPUDevice.prototype.createComputePipelineAsync=this._wrapMethod('createComputePipelineAsync',GPUDevice.prototype.createComputePipelineAsync),GPUDevice.prototype.createRenderPipelineAsync=this._wrapMethod('createRenderPipelineAsync',GPUDevice.prototype.createRenderPipelineAsync),GPUDevice.prototype.createCommandEncoder=this._wrapMethod('createCommandEncoder',GPUDevice.prototype.createCommandEncoder),GPUDevice.prototype.createRenderBundleEncoder=this._wrapMethod('createRenderBundleEncoder',GPUDevice.prototype.createRenderBundleEncoder),GPUDevice.prototype.createQuerySet=this._wrapMethod('createQuerySet',GPUDevice.prototype.createQuerySet),GPUBuffer.prototype.mapAsync=this._wrapMethod('mapAsync',GPUBuffer.prototype.mapAsync),GPUBuffer.prototype.getMappedRange=this._wrapMethod('getMappedRange',GPUBuffer.prototype.getMappedRange),GPUBuffer.prototype.unmap=this._wrapMethod('unmap',GPUBuffer.prototype.unmap),GPUBuffer.prototype.destroy=this._wrapMethod('destroy',GPUBuffer.prototype.destroy),GPUTexture.prototype.createView=this._wrapMethod('createView',GPUTexture.prototype.createView),GPUTexture.prototype.destroy=this._wrapMethod('destroy',GPUTexture.prototype.destroy),GPUShaderModule.prototype.getCompilationInfo=this._wrapMethod('getCompilationInfo',GPUShaderModule.prototype.getCompilationInfo),GPUComputePipeline.prototype.getBindGroupLayout=this._wrapMethod('getBindGroupLayout',GPUComputePipeline.prototype.getBindGroupLayout),GPURenderPipeline.prototype.getBindGroupLayout=this._wrapMethod('getBindGroupLayout',GPURenderPipeline.prototype.getBindGroupLayout),GPUCommandEncoder.prototype.beginRenderPass=this._wrapMethod('beginRenderPass',GPUCommandEncoder.prototype.beginRenderPass),GPUCommandEncoder.prototype.beginComputePass=this._wrapMethod('beginComputePass',GPUCommandEncoder.prototype.beginComputePass),GPUCommandEncoder.prototype.copyBufferToBuffer=this._wrapMethod('copyBufferToBuffer',GPUCommandEncoder.prototype.copyBufferToBuffer),GPUCommandEncoder.prototype.copyBufferToTexture=this._wrapMethod('copyBufferToTexture',GPUCommandEncoder.prototype.copyBufferToTexture),GPUCommandEncoder.prototype.copyTextureToBuffer=this._wrapMethod('copyTextureToBuffer',GPUCommandEncoder.prototype.copyTextureToBuffer),GPUCommandEncoder.prototype.copyTextureToTexture=this._wrapMethod('copyTextureToTexture',GPUCommandEncoder.prototype.copyTextureToTexture),GPUCommandEncoder.prototype.clearBuffer=this._wrapMethod('clearBuffer',GPUCommandEncoder.prototype.clearBuffer),GPUCommandEncoder.prototype.resolveQuerySet=this._wrapMethod('resolveQuerySet',GPUCommandEncoder.prototype.resolveQuerySet),GPUCommandEncoder.prototype.finish=this._wrapMethod('finish',GPUCommandEncoder.prototype.finish),GPUCommandEncoder.prototype.pushDebugGroup=this._wrapMethod('pushDebugGroup',GPUCommandEncoder.prototype.pushDebugGroup),GPUCommandEncoder.prototype.popDebugGroup=this._wrapMethod('popDebugGroup',GPUCommandEncoder.prototype.popDebugGroup),GPUCommandEncoder.prototype.insertDebugMarker=this._wrapMethod('insertDebugMarker',GPUCommandEncoder.prototype.insertDebugMarker),GPUComputePassEncoder.prototype.setPipeline=this._wrapMethod('setPipeline',GPUComputePassEncoder.prototype.setPipeline),GPUComputePassEncoder.prototype.dispatchWorkgroups=this._wrapMethod('dispatchWorkgroups',GPUComputePassEncoder.prototype.dispatchWorkgroups),GPUComputePassEncoder.prototype.dispatchWorkgroupsIndirect=this._wrapMethod('dispatchWorkgroupsIndirect',GPUComputePassEncoder.prototype.dispatchWorkgroupsIndirect),GPUComputePassEncoder.prototype.end=this._wrapMethod('end',GPUComputePassEncoder.prototype.end),GPUComputePassEncoder.prototype.setBindGroup=this._wrapMethod('setBindGroup',GPUComputePassEncoder.prototype.setBindGroup),GPUComputePassEncoder.prototype.setBindGroup=this._wrapMethod('setBindGroup',GPUComputePassEncoder.prototype.setBindGroup),GPUComputePassEncoder.prototype.pushDebugGroup=this._wrapMethod('pushDebugGroup',GPUComputePassEncoder.prototype.pushDebugGroup),GPUComputePassEncoder.prototype.popDebugGroup=this._wrapMethod('popDebugGroup',GPUComputePassEncoder.prototype.popDebugGroup),GPUComputePassEncoder.prototype.insertDebugMarker=this._wrapMethod('insertDebugMarker',GPUComputePassEncoder.prototype.insertDebugMarker),GPURenderPassEncoder.prototype.setViewport=this._wrapMethod('setViewport',GPURenderPassEncoder.prototype.setViewport),GPURenderPassEncoder.prototype.setScissorRect=this._wrapMethod('setScissorRect',GPURenderPassEncoder.prototype.setScissorRect),GPURenderPassEncoder.prototype.setBlendConstant=this._wrapMethod('setBlendConstant',GPURenderPassEncoder.prototype.setBlendConstant),GPURenderPassEncoder.prototype.setStencilReference=this._wrapMethod('setStencilReference',GPURenderPassEncoder.prototype.setStencilReference),GPURenderPassEncoder.prototype.beginOcclusionQuery=this._wrapMethod('beginOcclusionQuery',GPURenderPassEncoder.prototype.beginOcclusionQuery),GPURenderPassEncoder.prototype.endOcclusionQuery=this._wrapMethod('endOcclusionQuery',GPURenderPassEncoder.prototype.endOcclusionQuery),GPURenderPassEncoder.prototype.executeBundles=this._wrapMethod('executeBundles',GPURenderPassEncoder.prototype.executeBundles),GPURenderPassEncoder.prototype.end=this._wrapMethod('end',GPURenderPassEncoder.prototype.end),GPURenderPassEncoder.prototype.setPipeline=this._wrapMethod('setPipeline',GPURenderPassEncoder.prototype.setPipeline),GPURenderPassEncoder.prototype.setIndexBuffer=this._wrapMethod('setIndexBuffer',GPURenderPassEncoder.prototype.setIndexBuffer),GPURenderPassEncoder.prototype.setVertexBuffer=this._wrapMethod('setVertexBuffer',GPURenderPassEncoder.prototype.setVertexBuffer),GPURenderPassEncoder.prototype.draw=this._wrapMethod('draw',GPURenderPassEncoder.prototype.draw),GPURenderPassEncoder.prototype.drawIndexed=this._wrapMethod('drawIndexed',GPURenderPassEncoder.prototype.drawIndexed),GPURenderPassEncoder.prototype.drawIndirect=this._wrapMethod('drawIndirect',GPURenderPassEncoder.prototype.drawIndirect),GPURenderPassEncoder.prototype.drawIndexedIndirect=this._wrapMethod('drawIndexedIndirect',GPURenderPassEncoder.prototype.drawIndexedIndirect),GPURenderPassEncoder.prototype.setBindGroup=this._wrapMethod('setBindGroup',GPURenderPassEncoder.prototype.setBindGroup),GPURenderPassEncoder.prototype.pushDebugGroup=this._wrapMethod('pushDebugGroup',GPURenderPassEncoder.prototype.pushDebugGroup),GPURenderPassEncoder.prototype.popDebugGroup=this._wrapMethod('popDebugGroup',GPURenderPassEncoder.prototype.popDebugGroup),GPURenderPassEncoder.prototype.insertDebugMarker=this._wrapMethod('insertDebugMarker',GPURenderPassEncoder.prototype.insertDebugMarker),GPUQueue.prototype.submit=this._wrapMethod('submit',GPUQueue.prototype.submit),GPUQueue.prototype.writeBuffer=this._wrapMethod('writeBuffer',GPUQueue.prototype.writeBuffer),GPUQueue.prototype.writeTexture=this._wrapMethod('writeTexture',GPUQueue.prototype.writeTexture),GPUQueue.prototype.copyExternalImageToTexture=this._wrapMethod('copyExternalImageToTexture',GPUQueue.prototype.copyExternalImageToTexture),GPUQuerySet.prototype.destroy=this._wrapMethod('destroy',GPUQuerySet.prototype.destroy),GPUCanvasContext.prototype.configure=this._wrapMethod('configure',GPUCanvasContext.prototype.configure),GPUCanvasContext.prototype.unconfigure=this._wrapMethod('unconfigure',GPUCanvasContext.prototype.unconfigure),GPUCanvasContext.prototype.getCurrentTexture=this._wrapMethod('getCurrentTexture',GPUCanvasContext.prototype.getCurrentTexture)}disableRecording(){this._skipRecord++}enableRecording(){this._skipRecord--,this._skipRecord<0&&(this._skipRecord=0)}get isRecordingEnabled(){return 0===this._skipRecord}_wrapMethod(e,t){const r=this;return function(){const o=this,n=[...arguments];if(r._skipRecord>0)return t.call(o,...n);r.onPreCall.emit(o,e,n);const a=t.call(o,...n),c=i.has(e),p=r.recordStacktraces||c?s():void 0;if(a instanceof Promise){const t=r._idGenerator.getNextId(o);r.onPromise.emit(o,e,n,t,p);const s=a,i=new Promise((i=>{s.then((s=>{r.onPromiseResolve.emit(o,e,n,t,s,p),i(s)}))}));return i}return r.onPostCall.emit(o,e,n,a,p),a}}}const a={r8unorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8snorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8uint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8sint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg8unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8snorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},'rgba8unorm-srgb':{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8snorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},bgra8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},'bgra8unorm-srgb':{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r16uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16float:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg16uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba16uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r32uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg32uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba32uint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32sint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32float:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rg11b10ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},stencil8:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!1,hasStencil:!0,channels:1},depth16unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},depth24plus:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,depthOnlyFormat:'depth32float',channels:1},'depth24plus-stencil8':{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,depthOnlyFormat:'depth32float',channels:1},depth32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},'depth32float-stencil8':{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,stencilOnlyFormat:'depth32float',channels:1},rgb9e5ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},'bc1-rgba-unorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc1-rgba-unorm-srgb':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc2-rgba-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc2-rgba-unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc3-rgba-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc3-rgba-unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc4-r-unorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},'bc4-r-snorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},'bc5-rg-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},'bc5-rg-snorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},'bc6h-rgb-ufloat':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc6h-rgb-float':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc7-rgba-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'bc7-rgba-unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgb8unorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgb8unorm-srgb':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgb8a1unorm':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgb8a1unorm-srgb':{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgba8unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'etc2-rgba8unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'eac-r11unorm':{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},'eac-r11snorm':{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},'eac-rg11unorm':{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},'eac-rg11snorm':{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},'astc-4x4-unorm':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'astc-4x4-unorm-srgb':{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},'astc-5x4-unorm':{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},'astc-5x4-unorm-srgb':{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},'astc-5x5-unorm':{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},'astc-5x5-unorm-srgb':{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},'astc-6x5-unorm':{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},'astc-6x5-unorm-srgb':{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},'astc-6x6-unorm':{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},'astc-6x6-unorm-srgb':{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},'astc-8x5-unorm':{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},'astc-8x5-unorm-srgb':{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},'astc-8x6-unorm':{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},'astc-8x6-unorm-srgb':{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},'astc-8x8-unorm':{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},'astc-8x8-unorm-srgb':{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},'astc-10x5-unorm':{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},'astc-10x5-unorm-srgb':{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},'astc-10x6-unorm':{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},'astc-10x6-unorm-srgb':{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},'astc-10x8-unorm':{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},'astc-10x8-unorm-srgb':{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},'astc-10x10-unorm':{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},'astc-10x10-unorm-srgb':{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},'astc-12x10-unorm':{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},'astc-12x10-unorm-srgb':{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},'astc-12x12-unorm':{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4},'astc-12x12-unorm-srgb':{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4}};class c{constructor(e){this.device=e,this.blitShaderModule=e.createShaderModule({code:c.blitShader}),this.multisampleBlitShaderModule=e.createShaderModule({code:c.multisampleBlitShader}),this.depthToFloatShaderModule=e.createShaderModule({code:c.depthToFloatShader}),this.depthToFloatMultisampleShaderModule=e.createShaderModule({code:c.depthToFloatMultisampleShader}),this.blitPipelines={},this.blitDepthPipelines={},this.bindGroupLayouts=new Map,this.pipelineLayouts=new Map,this.depthToFloatPipeline=null,this.depthToFloatMSPipeline=null,this.pointSampler=e.createSampler({magFilter:'nearest',minFilter:'nearest'}),this.displayUniformBuffer=e.createBuffer({size:32,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),this.displayBingGroupLayout=e.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,buffer:{type:'uniform'}}]}),this.displayBindGroup=e.createBindGroup({layout:this.displayBingGroupLayout,entries:[{binding:0,resource:{buffer:this.displayUniformBuffer}}]})}copyDepthTexture(e,t,r){const s=e.width,o=e.height,i=e.depthOrArrayLayers,n=e.usage|GPUTextureUsage.RENDER_TARGET|GPUTextureUsage.COPY_SRC,a=[s,o,i];t=t||'r32float';const c=this.device.createTexture({format:t,size:a,usage:n});for(let s=0;s1}}]});this.bindGroupLayouts.set(c,e);const t=this.device.createPipelineLayout({bindGroupLayouts:[e,this.displayBingGroupLayout]});this.pipelineLayouts.set(c,t)}const p=a[t],d=p?.channels??4,u=this.bindGroupLayouts.get(c),l=this.pipelineLayouts.get(c),h=`${o}#${n}#${r}`;let _=this.blitPipelines[h];if(!_){const e=r>1?this.multisampleBlitShaderModule:this.blitShaderModule;_=this.device.createRenderPipeline({layout:l,vertex:{module:e,entryPoint:'vertexMain'},fragment:{module:e,entryPoint:'fragmentMain',targets:[{format:o}]},primitive:{topology:'triangle-list'}}),this.blitPipelines[h]=_}const m=this.device.createBindGroup({layout:u,entries:[{binding:0,resource:this.pointSampler},{binding:1,resource:e}]}),f=this.device.createCommandEncoder(),g={colorAttachments:[{view:s,loadOp:'clear',storeOp:'store'}]};i?this.device.queue.writeBuffer(this.displayUniformBuffer,0,new Float32Array([i.exposure,i.channels,d,i.minRange,i.maxRange,0,0,0])):this.device.queue.writeBuffer(this.displayUniformBuffer,0,new Float32Array([1,0,d,0,1,0,0,0]));const b=f.beginRenderPass(g);b.setPipeline(_),b.setBindGroup(0,m),b.setBindGroup(1,this.displayBindGroup),b.draw(3),b.end(),this.device.queue.submit([f.finish()])}convertDepthToFloat(e,t,r,s,o){if(t>1){if(!this.depthToFloatMSPipeline){this.device.pushErrorScope('validation'),this.depthToFloatBindGroupMSLayout=this.device.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:'depth',multisampled:!0}}]});const e=this.device.createPipelineLayout({bindGroupLayouts:[this.depthToFloatBindGroupMSLayout]}),t=this.depthToFloatMultisampleShaderModule;this.depthToFloatMSPipeline=this.device.createRenderPipeline({layout:e,vertex:{module:t,entryPoint:'vertexMain'},fragment:{module:t,entryPoint:'fragmentMain',targets:[{format:s}]},primitive:{topology:'triangle-list'}}),this.device.popErrorScope().then((e=>{e&&console.error(e.message)}))}}else if(!this.depthToFloatPipeline){this.device.pushErrorScope('validation'),this.depthToFloatBindGroupLayout=this.device.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:'depth'}}]});const e=this.device.createPipelineLayout({bindGroupLayouts:[this.depthToFloatBindGroupLayout]}),t=this.depthToFloatShaderModule;this.depthToFloatPipeline=this.device.createRenderPipeline({layout:e,vertex:{module:t,entryPoint:'vertexMain'},fragment:{module:t,entryPoint:'fragmentMain',targets:[{format:s}]},primitive:{topology:'triangle-list'}}),this.device.popErrorScope().then((e=>{e&&console.error(e.message)}))}this.device.pushErrorScope('validation');const i=this.device.createBindGroup({layout:t>1?this.depthToFloatBindGroupMSLayout:this.depthToFloatBindGroupLayout,entries:[{binding:0,resource:e}]}),n=!o;o??=this.device.createCommandEncoder();const a=o.beginRenderPass({colorAttachments:[{view:r,loadOp:'clear',storeOp:'store',clearColor:{r:0,g:0,b:0,a:0}}]});a.setPipeline(t>1?this.depthToFloatMSPipeline:this.depthToFloatPipeline),a.setBindGroup(0,i),a.draw(3),a.end(),n&&this.device.queue.submit([o.finish()]),this.device.popErrorScope().then((e=>{e&&console.error(e.message)}))}}c.blitShader='\n var posTex:array = array(\n vec4f(-1.0, 1.0, 0.0, 0.0),\n vec4f(3.0, 1.0, 2.0, 0.0),\n vec4f(-1.0, -3.0, 0.0, 2.0));\n struct VertexOutput {\n @builtin(position) position: vec4f,\n @location(0) uv: vec2f\n };\n @vertex\n fn vertexMain(@builtin(vertex_index) vertexIndex: u32) -> VertexOutput {\n var output: VertexOutput;\n output.uv = posTex[vertexIndex].zw;\n output.position = vec4f(posTex[vertexIndex].xy, 0.0, 1.0);\n return output;;\n }\n @group(0) @binding(0) var texSampler: sampler;\n @group(0) @binding(1) var texture: texture_2d;\n struct Display {\n exposure: f32,\n channels: f32,\n numChannels: f32,\n minRange: f32,\n maxRange: f32,\n _pad1: f32,\n _pad2: f32,\n _pad3: f32\n };\n @group(1) @binding(0) var display: Display; \n @fragment\n fn fragmentMain(input: VertexOutput) -> @location(0) vec4f {\n var color = textureSample(texture, texSampler, input.uv);\n\n if (display.numChannels == 1.0) {\n if (display.minRange != display.maxRange) {\n if (color.r < display.minRange) {\n color = vec4f(0.0, 0.0, 0.0, 1);\n } else if (color.r > display.maxRange) {\n color = vec4f(1.0, 0.0, 0.0, 1);\n } else {\n color = vec4f((color.r - display.minRange) / (display.maxRange - display.minRange), 0.0, 0.0, 1);\n }\n }\n color = vec4f(color.r, color.r, color.r, 1.0);\n } else if (display.numChannels == 2.0) {\n color = vec4f(color.r, color.g, 0.0, 1.0);\n }\n\n if (display.channels == 1.0) { // R\n var rgb = color.rgb * display.exposure;\n return vec4f(rgb.r, 0.0, 0.0, 1);\n } else if (display.channels == 2.0) { // G\n var rgb = color.rgb * display.exposure;\n return vec4f(0.0, rgb.g, 0.0, 1);\n } else if (display.channels == 3.0) { // B\n var rgb = color.rgb * display.exposure;\n return vec4f(0.0, 0.0, rgb.b, 1);\n } else if (display.channels == 4.0) { // A\n var a = color.a * display.exposure;\n return vec4f(a, a, a, 1);\n } else if (display.channels == 5.0) { // Luminance\n var luminance = dot(color.rgb, vec3f(0.2126, 0.7152, 0.0722));\n var rgb = vec3f(luminance) * display.exposure;\n return vec4f(rgb, 1);\n }\n\n // RGB\n var rgb = color.rgb * display.exposure;\n return vec4f(rgb, 1);\n }\n',c.multisampleBlitShader='\n var posTex:array = array(\n vec4f(-1.0, 1.0, 0.0, 0.0),\n vec4f(3.0, 1.0, 2.0, 0.0),\n vec4f(-1.0, -3.0, 0.0, 2.0));\n struct VertexOutput {\n @builtin(position) position: vec4f,\n @location(0) uv: vec2f\n };\n @vertex\n fn vertexMain(@builtin(vertex_index) vertexIndex: u32) -> VertexOutput {\n var output: VertexOutput;\n output.uv = posTex[vertexIndex].zw;\n output.position = vec4f(posTex[vertexIndex].xy, 0.0, 1.0);\n return output;;\n }\n @group(0) @binding(0) var texSampler: sampler;\n @group(0) @binding(1) var texture: texture_multisampled_2d;\n struct Display {\n exposure: f32,\n channels: f32,\n numChannels: f32,\n minRange: f32,\n maxRange: f32,\n _pad1: f32,\n _pad2: f32,\n _pad3: f32\n };\n @group(1) @binding(0) var display: Display; \n @fragment\n fn fragmentMain(input: VertexOutput) -> @location(0) vec4f {\n var coords = vec2i(input.uv * vec2f(textureDimensions(texture)));\n var color = textureLoad(texture, coords, 0);\n if (display.numChannels == 1.0) {\n if (display.minRange != display.maxRange) {\n if (color.r < display.minRange) {\n color = vec4f(0.0, 0.0, 0.0, color.a);\n } else if (color.r > display.maxRange) {\n color = vec4f(1.0, 1.0, 1.0, color.a);\n } else {\n color = vec4f((color.r - display.minRange) / (display.maxRange - display.minRange), 0.0, 0.0, color.a);\n }\n }\n color = vec4f(color.r, color.r, color.r, 1.0);\n } else if (display.numChannels == 2.0) {\n color = vec4f(color.r, color.g, 0.0, 1.0);\n }\n if (display.channels == 1.0) { // R\n var rgb = color.rgb * display.exposure;\n return vec4f(rgb.r, 0.0, 0.0, color.a);\n } else if (display.channels == 2.0) { // G\n var rgb = color.rgb * display.exposure;\n return vec4f(0.0, rgb.g, 0.0, color.a);\n } else if (display.channels == 3.0) { // B\n var rgb = color.rgb * display.exposure;\n return vec4f(0.0, 0.0, rgb.b, color.a);\n } else if (display.channels == 4.0) { // A\n var a = color.a * display.exposure;\n return vec4f(a, a, a, color.a);\n } else if (display.channels == 5.0) { // Luminance\n var luminance = dot(color.rgb, vec3f(0.2126, 0.7152, 0.0722));\n var rgb = vec3f(luminance) * display.exposure;\n return vec4f(rgb, color.a);\n }\n\n // RGB\n var rgb = color.rgb * display.exposure;\n return vec4f(rgb, color.a);\n }',c.depthToFloatShader='\n var posTex:array = array(\n vec4f(-1.0, 1.0, 0.0, 0.0),\n vec4f(3.0, 1.0, 2.0, 0.0),\n vec4f(-1.0, -3.0, 0.0, 2.0));\n struct VertexOutput {\n @builtin(position) position: vec4,\n @location(0) uv : vec2\n };\n @vertex\n fn vertexMain(@builtin(vertex_index) vertexIndex: u32) -> VertexOutput {\n var output: VertexOutput;\n output.uv = posTex[vertexIndex].zw;\n output.position = vec4f(posTex[vertexIndex].xy, 0.0, 1.0);\n return output;;\n }\n \n @binding(0) @group(0) var depth: texture_depth_2d;\n @fragment\n fn fragmentMain(input: VertexOutput) -> @location(0) vec4 {\n var depthSize = textureDimensions(depth);\n var coords = vec2(i32(f32(depthSize.x) * input.uv.x),\n i32(f32(depthSize.y) * input.uv.y));\n var d = textureLoad(depth, coords, 0);\n return vec4(d, 0.0, 0.0, 1.0);\n }',c.depthToFloatMultisampleShader='\n var posTex:array = array(\n vec4f(-1.0, 1.0, 0.0, 0.0),\n vec4f(3.0, 1.0, 2.0, 0.0),\n vec4f(-1.0, -3.0, 0.0, 2.0));\n struct VertexOutput {\n @builtin(position) position: vec4,\n @location(0) uv : vec2\n };\n @vertex\n fn vertexMain(@builtin(vertex_index) vertexIndex: u32) -> VertexOutput {\n var output: VertexOutput;\n output.uv = posTex[vertexIndex].zw;\n output.position = vec4f(posTex[vertexIndex].xy, 0.0, 1.0);\n return output;;\n }\n \n @binding(0) @group(0) var depth: texture_depth_multisampled_2d;\n @fragment\n fn fragmentMain(input: VertexOutput) -> @location(0) vec4 {\n var depthSize = textureDimensions(depth);\n var coords = vec2(i32(f32(depthSize.x) * input.uv.x),\n i32(f32(depthSize.y) * input.uv.y));\n var d = textureLoad(depth, coords, 0);\n return vec4(d, 0.0, 0.0, 1.0);\n }';const p={CaptureBufferData:'webgpu_inspect_capture_buffer_data',CaptureBuffers:'webgpu_inspect_capture_buffers',DeleteObjects:'webgpu_inspect_delete_objects',ValidationError:'webgpu_inspect_validation_error',MemoryLeakWarning:'webgpu_inspect_memory_leak_warning',DeltaTime:'webgpu_inspect_delta_time',CaptureFrameResults:'webgpu_inspect_capture_frame_results',CaptureFrameCommands:'webgpu_inspect_capture_frame_commands',ObjectSetLabel:'webgpu_inspect_object_set_label',AddObject:'webgpu_inspect_add_object',ResolveAsyncObject:'webgpu_inspect_resolve_async_object',DeleteObject:'webgpu_inspect_delete_object',CaptureTextureFrames:'webgpu_inspect_capture_texture_frames',CaptureTextureData:'webgpu_inspect_capture_texture_data',CaptureBufferData:'webgpu_inspect_capture_buffer_data',Recording:'webgpu_record_recording',RecordingCommand:'webgpu_record_command',RecordingDataCount:'webgpu_record_data_count',RecordingData:'webgpu_record_data'};p.values=new Set(Object.values(p));const d='webgpu_inspect_request_texture',u='webgpu_inspect_compile_shader',l='webgpu_inspect_revert_shader',h='webgpu_inspector_capture';class _{constructor(e){this.windowSize=e,this.buffer=[],this.sum=0}add(e){this.buffer.push(e),this.buffer.length>this.windowSize&&(this.sum-=this.buffer.shift()),this.sum+=e}get average(){return 0===this.buffer.length?0:this.sum/this.buffer.length}}function m(e,t){return e+t-1&~(t-1)}e.webgpuInspector=null,(()=>{const r=self,s=self.window,i=self.document,f=self.sessionStorage,g=self.postMessage,b=self.dispatchEvent,y='WEBGPU_INSPECTOR_CAPTURE_FRAME',P=262144;e.webgpuInspector=new class x{constructor(){if(this._captureFrameCommands=[],this._frameData=[],this._frameRenderPassCount=0,this._captureTexturedBuffers=[],this._currentFrame=null,this._frameIndex=0,this._initalized=!0,this._objectID=1,this._lastFrameTime=0,this._frameCommandCount=0,this._captureFrameRequest=!1,this._errorChecking=1,this._trackedObjects=new Map,this._trackedObjectInfo=new Map,this._bindGroupCount=0,this._captureTextureRequest=new Map,this._toDestroy=[],this._objectReplacementMap=new Map,this._captureBuffersCount=0,this._captureTempBuffers=[],this._mappedTextureBufferCount=0,this._encodingTextureChunkCount=0,this._mappedBufferCount=0,this._encodingBufferChunkCount=0,this._captureData=null,this._frameRate=new _(60),this._captureTimestamps=!1,this._timestampQuerySet=null,this._timestampBuffer=null,this._timestampIndex=0,this._maxTimestamps=2e3,!navigator.gpu)return;if(i?.body){const e=i.createElement('div');e.style='position: absolute; z-index: 1000000; margin-left: 10px; margin-top: 5px; padding-left: 5px; padding-right: 10px; background-color: rgba(0, 0, 1, 0.75); border-radius: 5px; box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.5); color: #fff; font-size: 12pt;',i.body.insertBefore(e,i.body.firstChild),this._inspectingStatus=i.createElement('div'),this._inspectingStatus.title='WebGPU Inspector Running',this._inspectingStatus.style='height: 10px; width: 10px; display: inline-block; margin-right: 5px; background-color: #ff0; border-radius: 50%; border: 1px solid #000; box-shadow: inset -4px -4px 4px -3px rgb(255,100,0), 2px 2px 3px rgba(0,0,0,0.8);',e.appendChild(this._inspectingStatus),this._inspectingStatusFrame=i.createElement('div'),this._inspectingStatusFrame.style='display: inline-block;',this._inspectingStatusFrame.textContent='Frame: 0',e.appendChild(this._inspectingStatusFrame),this._inspectingStatusText=i.createElement('div'),this._inspectingStatusText.style='display: inline-block; margin-left: 10px;',e.appendChild(this._inspectingStatusText)}this._gpuWrapper=new n(this);const e=this;this._gpuWrapper.onPromise.addListener(this._onAsyncPromise,this),this._gpuWrapper.onPromiseResolve.addListener(this._onAsyncResolve,this),this._gpuWrapper.onPreCall.addListener(this._preMethodCall,this),this._gpuWrapper.onPostCall.addListener(this._postMethodCall,this),this._garbageCollectectedObjects=[],this._garbageCollectionRegistry=new FinalizationRegistry((t=>{if(t>0){e._garbageCollectectedObjects.push(t);const r=e._trackedObjectInfo.get(t);r&&(r===GPUBindGroup&&e._bindGroupCount--,r!==GPUBuffer&&r!==GPUTexture&&r!==GPUDevice||e._memoryLeakWarning(t,r)),e._garbageCollectectedObjects.length>100&&(e._postMessage({action:p.DeleteObjects,idList:e._garbageCollectectedObjects}),e._garbageCollectectedObjects.length=0)}t>0&&(e._trackedObjects.delete(t),e._trackedObjectInfo.delete(t),e._captureTextureRequest.delete(t),e._objectReplacementMap.delete(t))}));if(setInterval((()=>{e._garbageCollectectedObjects.length>0&&(e._postMessage({action:p.DeleteObjects,idList:e._garbageCollectectedObjects}),e._garbageCollectectedObjects.length=0)}),200),i){const t=i.getElementsByTagName('canvas');for(const e of t)this._wrapCanvas(e);const r=i.createElement;i.createElement=t=>{const s=r.call(i,t);return'canvas'===t&&e._wrapCanvas(s),s}}const t=requestAnimationFrame;function o(t){const r=t.detail||t.data;if('object'==typeof r&&r.__webgpuInspector)if(r.action===p.DeltaTime)r.__webgpuInspectorWorker&&e._updateFrameRate(r.deltaTime);else if(r.action===d){const t=r.id;e._requestTexture(t)}else if(r.action===u){const t=r.id,s=r.code;e._compileShader(t,s)}else if(r.action===l){const t=r.id;e._revertShader(t)}else r.action===h&&null==s&&('String'===r.data.constructor.name&&(r.data=JSON.parse(r.data)),e._captureData=r.data)}this._currentFrameTime=0,requestAnimationFrame=r=>t((function(t){if(!e._currentFrameTime){e._currentFrameTime=t,e._frameStart(t);const s=r(t);s instanceof Promise?Promise.all([s]).then((()=>{e._frameEnd(t),e._currentFrameTime=0})):(e._frameEnd(t),e._currentFrameTime=0)}})),s?r.addEventListener('__WebGPUInspector',o):r.addEventListener('message',o)}captureWorker(e){this._wrapCanvas(e)}disableRecording(){this._gpuWrapper.disableRecording()}enableRecording(){this._gpuWrapper.enableRecording()}_postMessage(e){e.__webgpuInspector=!0,e.__webgpuInspectorPage=!0,e.__webgpuInspectorWorker=!s,s?b(new CustomEvent('__WebGPUInspector',{detail:e})):g(e)}_updateCanvasAttachment(e){let t=null;e.resolveTarget?t=e.resolveTarget:e.view&&(t=e.view);const r=t?.__texture,s=r?.__context;if(!s)return;s.__captureTexture&&(s.__captureTexture.width==r.width&&s.__captureTexture.height==r.height&&s.__captureTexture.format==r.format||(this.disableRecording(),s.__captureTexture.destroy(),s.__captureTexture=null,this.enableRecording()));const o=s.__device;if(o){this.disableRecording();const i=o.createTexture({size:[r.width,r.height,1],format:r.format,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC});if(s.__captureTexture=i,i){i.__id=r.__id,i.__canvasTexture=r,i.__context=s;const o=i.createView();o.__texture=i,o.__canvasView=t,i.__view=o,o.__context=s,e.resolveTarget?e.resolveTarget=o:e.view=o}this.enableRecording()}}_preMethodCall(e,t,r){if('requestDevice'===t&&(0===r.length&&(r[0]={}),r[0].requiredFeatures?r[0].requiredFeatures.push('timestamp-query'):r[0].requiredFeatures=['timestamp-query']),'setPipeline'===t){let e=r[0];const t=this._objectReplacementMap.get(e.__id);t&&t.replacement&&(r[0]=t.replacement)}if('createTexture'===t&&(r[0].usage|=GPUTextureUsage.COPY_SRC|GPUTextureUsage.TEXTURE_BINDING),'createBuffer'===t&&(r[0].usage&GPUBufferUsage.MAP_READ||(r[0].usage|=GPUBufferUsage.COPY_SRC)),'createShaderModule'!==t&&'createRenderPipeline'!==t&&'createComputePipeline'!==t&&'createBindGroup'!==t||this._errorChecking>0&&(this._gpuWrapper.disableRecording(),e.pushErrorScope('validation'),this._gpuWrapper.enableRecording()),'beginRenderPass'!==t&&'beginComputePass'!==t||this._captureTimestamps&&this._captureFrameRequest&&(!this._timestampQuerySet&&e.__device&&(this._timestampQuerySet=e.__device.createQuerySet({type:'timestamp',count:this._maxTimestamps}),this._timestampBuffer=e.__device.createBuffer({size:8*this._maxTimestamps,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC})),!r[0].timestampWrites&&this._timestampIndex0){const r=e.__device.createCommandEncoder();r.resolveQuerySet(this._timestampQuerySet,0,this._timestampIndex,this._timestampBuffer,0),t=e.__device.createBuffer({size:8*this._timestampIndex,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),t.__count=this._timestampIndex,r.copyBufferToBuffer(this._timestampBuffer,0,t,0,8*this._timestampIndex),e.__device.queue.submit([r.finish()]),this._timestampIndex=0}const s=this;if(this._captureTextureRequest.size>0){const t=r[0];let o=!1;for(const e of t)o|=!!e.__rendersToCanvas;this._captureTextureRequest.forEach(((t,r)=>{(r>0||o)&&(t=t||s._trackedObjects.get(r)?.deref(),s._captureTextureBuffer(e.__device,null,t),s._captureTextureRequest.delete(r))}))}const o=[...this._captureTempBuffers];this._captureTempBuffers.length=0;const i=[...this._captureTexturedBuffers];this._captureTexturedBuffers.length=0;const n=[...this._toDestroy];this._toDestroy.length=0,e.onSubmittedWorkDone().then((async()=>{s.disableRecording(),t&&s._sendTimestampBuffer(t.__count,t),o.length&&s._sendCapturedBuffers(o),i.length&&s._sendCaptureTextureBuffers(i);for(const e of n)e.destroy();s.enableRecording()})),this.enableRecording()}let n;if('createShaderModule'!==t&&'createRenderPipeline'!==t&&'createComputePipeline'!==t&&'createBindGroup'!==t||this._errorChecking>0&&(this.disableRecording(),e.popErrorScope().then((e=>{if(e){console.error(e.message);const t=s?.__id??0;self._postMessage({action:p.ValidationError,id:t,message:e.message,stacktrace:i})}})),this.enableRecording()),'getCurrentTexture'===t?(e.__id||(this._wrapObject(e),this._trackObject(e.__id,e)),n=-e.__id,e.__canvasTexture=new WeakRef(s),s.__frameIndex=this._frameIndex):'createView'===t&&e.__id<0&&(n=e.__id-.5),e instanceof GPUDevice&&void 0===e?.__id&&(this._wrapDevice(null,e),e.__adapter||navigator.gpu.requestAdapter().then((t=>{e.__adapter=t}))),s)if(o.has(s.constructor)&&this._wrapObject(s,n),'createShaderModule'===t||'createRenderPipeline'===t)s.__descriptor=r[0],s.__device=e,this._objectReplacementMap.set(s.__id,{id:s.__id,object:new WeakRef(s),replacement:null});else if('getCurrentTexture'===t)s.__context=e,this._trackObject(s.__id,s),s.label='CanvasTexture';else if('createTexture'===t)this._trackObject(s.__id,s);else if('createView'!==t||n){if('createBuffer'===t)this._trackObject(s.__id,s);else if('createBindGroup'===t)this._trackObject(s.__id,s),s.__descriptor=r[0];else if('setBindGroup'===t){const t=r[1].__descriptor;if(t)for(const r of t.entries)if(r.resource instanceof GPUTextureView&&r.resource.__id<0){if(r.resource.__texture.__frameIndex{const i={vendor:o.vendor,architecture:o.architecture,device:o.device,description:o.description,features:s._gpuToArray(e.features),limits:s._gpuToObject(e.limits),isFallbackAdapter:e.isFallbackAdapter,wgslFeatures:s._gpuToArray(navigator.gpu.wgslLanguageFeatures)};s._sendAddObjectMessage(t,0,'Adapter',JSON.stringify(i),r)}))}_wrapDevice(e,t,r,s,o){if(e&&void 0===e.__id&&this._wrapAdapter(e,void 0,o),t&&void 0===t.__id){t.queue.__device=t;const i=this;t.addEventListener('uncapturederror',(e=>{i._postMessage({action:p.ValidationError,id:0,message:e.error.message})})),s??=[],this._wrapObject(t,r);const n=s[0]??{},a=t.__id,c=e?.__id??0;n.features=this._gpuToArray(t.features),n.limits=this._gpuToObject(t.limits),this._trackObject(a,t),this._sendAddObjectMessage(r,c,'Device',JSON.stringify(n),o),t.__adapter=e,this._device=t}}clear(){this._captureFrameCommands.length=0,this._currentFrame=null}getNextId(e){return e instanceof GPUCommandEncoder||e instanceof GPUComputePassEncoder||e instanceof GPURenderPassEncoder||e instanceof GPUCommandBuffer?0:this._objectID++}_memoryLeakWarning(e,t){if(t){const e=`${t.name} was garbage collected without being explicitly destroyed. These objects should explicitly destroyed to avoid GPU memory leaks.`;this._postMessage({action:p.ValidationError,id:0,message:e})}}_isPrimitiveType(e){return!e||e.constructor===String||e.constructor===Number||e.constructor===Boolean}_isTypedArray(e){return e&&(e instanceof ArrayBuffer||e.buffer instanceof ArrayBuffer)}_isArray(e){return e&&e.constructor===Array}_duplicateArray(e,t){const r=new Array(e.length);for(let s=0,o=e.length;s{if(t){console.error(t.message);const r=e??0;a._postMessage({action:p.ValidationError,id:r,message:t.message})}})),this._errorChecking++,this.enableRecording(),r.replacement=n;for(const e of this._objectReplacementMap.values()){const t=e.object.deref(),r=t instanceof GPURenderPipeline,i=t instanceof GPUComputePipeline;if(r||i){const i=t.__descriptor;let a=!1,c=null;if(i.vertex?.module===s&&(c||(c=this._duplicateObject(i)),a=!0,c.vertex.module=n),i.fragment?.module===s&&(c||(c=this._duplicateObject(i)),a=!0,c.fragment.module=n),i.compute?.module===s&&(c||(c=this._duplicateObject(i)),a=!0,c.compute.module=n),a){this.disableRecording(),this._errorChecking--,c.__replacement=e.id,o.pushErrorScope('validation');const t=r?o.createRenderPipeline(c):o.createComputePipeline(c),s=this;o.popErrorScope().then((t=>{if(t){console.error(t.message);const r=e.id??0;s._postMessage({action:p.ValidationError,id:r,message:t.message})}})),this._errorChecking++,this.enableRecording(),e.replacement=t}}}}_requestTexture(e){if(e<0)this._captureTextureRequest.set(e,null);else{const t=this._trackedObjects.get(e),r=t?.deref();r instanceof GPUTexture&&this._captureTextureRequest.set(e,r)}}_updateStatusMessage(){let e='';this._captureTexturedBuffers.length>0&&(e+=`Texture: ${this._captureTexturedBuffers.length} `),this._mappedTextureBufferCount>0&&(e+=`Pending Texture Reads: ${this._mappedTextureBufferCount} `),this._encodingTextureChunkCount>0&&(e+=`Pending Texture Encoding: ${this._encodingTextureChunkCount} `),this._captureBuffersCount&&(e+=`Buffers: ${this._captureBuffersCount} `),this._mappedBufferCount>0&&(e+=`Pending Buffer Reads: ${this._mappedBufferCount} `),this._encodingBufferChunkCount>0&&(e+=`Pending Buffer Encoding: ${this._encodingBufferChunkCount} `),e&&(e=`Capturing: ${e} `),this._inspectingStatusFrame&&(this._inspectingStatusText.textContent=e)}_updateFrameRate(e){this._frameRate.add(e),this._frameIndex++,this._inspectingStatusFrame&&(this._inspectingStatusFrame.textContent=`Frame: ${this._frameIndex} : ${this._frameRate.average.toFixed(2)}ms`)}_frameStart(e){let t=0;if(0==this._lastFrameTime?this._lastFrameTime=e:(t=e-this._lastFrameTime,this._postMessage({action:p.DeltaTime,deltaTime:t}),this._lastFrameTime=e,this._frameRate.add(t)),f){const e=f.getItem(y);if(e){try{this._captureData=JSON.parse(e)}catch(e){this._captureData=null}f.removeItem(y)}}if(this._captureData&&(this._captureData.frame<0||this._frameIndex>=this._captureData.frame)&&(this._captureMaxBufferSize=this._captureData.maxBufferSize||262144,this._captureFrameRequest=!0,this._gpuWrapper.recordStacktraces=!0,this._captureData=null,this._captureTimestamps)){if(this.disableRecording(),this._device){this._timestampQuerySet||(this._timestampQuerySet=this._device.createQuerySet({type:'timestamp',count:this._maxTimestamps}),this._timestampBuffer=this._device.createBuffer({size:8*this._maxTimestamps,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}));const e=this._device.createCommandEncoder();e.beginComputePass({timestampWrites:{querySet:this._timestampQuerySet,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1}}).end(),this._device.queue.submit([e.finish()]),this._timestampIndex=2}this.enableRecording()}this._frameData.length=0,this._captureFrameCommands.length=0,this._frameRenderPassCount=0,this._frameIndex++,this._frameCommandCount=0,this._inspectingStatusFrame&&(this._inspectingStatusFrame.textContent=`Frame: ${this._frameIndex} : ${this._frameRate.average.toFixed(2)}ms`)}_frameEnd(e){if(this._captureFrameCommands.length){const e=2e3,t=Math.ceil(this._captureFrameCommands.length/e);this._postMessage({action:p.CaptureFrameResults,frame:this._frameIndex,count:this._captureFrameCommands.length,batches:t});for(let t=0;t{const i=r.call(e,s,o);return i instanceof GPUCanvasContext&&(t._wrapObject(i),t._trackObject(i.__id,i)),i}}_wrapObject(e,t){if(e&&void 0===e.__id){if(e.__id=t??this.getNextId(e),this._garbageCollectionRegistry.register(e,e.__id),void 0!==e.label){const t=e.label;e._label=t;const r=this;Object.defineProperty(e,'label',{enumerable:!0,configurable:!0,get(){return this._label},set(e){if(e!==this._label){this._label=e;const t=this.__id;r._postMessage({action:p.ObjectSetLabel,id:t,label:e})}}})}e instanceof GPUDevice&&void 0===e.queue.__id&&this._wrapObject(e.queue)}}_gpuToArray(e){const t=[];if(e)for(const r of e)t.push(r);return t}_gpuToObject(e){const t={};if(e)for(const r in e)t[r]=e[r];return t}_stringifyDescriptor(e){const t=this._duplicateObject(e,!0)??{};let r=null;try{r=JSON.stringify(t)}catch(e){console.log(e.message)}return r}_sendAddObjectMessage(e,t,r,s,o,i){this._postMessage({action:p.AddObject,id:e,parent:t,type:r,descriptor:s,stacktrace:o,pending:i})}_recordCommand(e,t,r,s,o){const i=e?.__id??0;if('destroy'===t){e===this._device&&(this._device=null);const t=e.__id;e.__destroyed=!0,t>0&&(this._trackedObjects.delete(t),this._trackedObjectInfo.delete(t),this._objectReplacementMap.delete(t)),e instanceof GPUBindGroup&&this._bindGroupCount--,t>=0&&(this._captureTextureRequest.delete(t),this._postMessage({action:p.DeleteObject,id:t}))}else if('createShaderModule'===t){const e=r.__id;s[0].__replacement||this._sendAddObjectMessage(e,i,'ShaderModule',this._stringifyDescriptor(s[0]),o)}else if('createBuffer'===t){const e=r.__id;this._sendAddObjectMessage(e,i,'Buffer',this._stringifyDescriptor(s[0]),o)}else if('createTexture'===t){const t=r.__id;this._sendAddObjectMessage(t,i,'Texture',this._stringifyDescriptor(s[0]),o),r.__device=e}else if('getCurrentTexture'===t){const e=r.__id;if(r){const t={size:[r.width,r.height,r.depthOrArrayLayers],mipLevelCount:r.mipLevelCount,sampleCount:r.sampleCount,dimension:r.dimension,format:r.format,usage:r.usage},s=JSON.stringify(t);this._sendAddObjectMessage(e,i,'Texture',s,o)}}else if('createView'===t){const t=r.__id;r.__texture=e,this._sendAddObjectMessage(t,i,'TextureView',this._stringifyDescriptor(s[0]),o)}else if('createSampler'===t){const e=r.__id;this._sendAddObjectMessage(e,i,'Sampler',this._stringifyDescriptor(s[0]),o)}else if('createBindGroup'===t){this._bindGroupCount++;const e=r.__id;r.__descriptor=s[0],this._sendAddObjectMessage(e,i,'BindGroup',this._stringifyDescriptor(s[0]),o)}else if('createBindGroupLayout'===t){const e=r.__id;r.__descriptor=s[0],this._sendAddObjectMessage(e,i,'BindGroupLayout',this._stringifyDescriptor(s[0]),o)}else if('createPipelineLayout'===t){const e=r.__id;this._sendAddObjectMessage(e,i,'PipelineLayout',this._stringifyDescriptor(s[0]),o)}else if('createRenderPipeline'===t){const e=r.__id;s[0].__replacement||(this._sendAddObjectMessage(e,i,'RenderPipeline',this._stringifyDescriptor(s[0]),o),s[0].vertex?.module&&(r.__vertexModule=s[0].vertex?.module),s[0].fragment?.module&&(r.__fragmentModule=s[0].fragment?.module))}else if('createComputePipeline'===t){const e=r.__id;s[0].__replacement||(this._sendAddObjectMessage(e,i,'ComputePipeline',this._stringifyDescriptor(s[0]),o),s[0].compute?.module&&(r.__computeModule=s[0].compute?.module))}else'createCommandEncoder'===t&&(r.__device=e);this._captureFrameRequest&&this._captureCommand(e,t,s,o,r)}_captureCommand(e,t,r,s,o){const i=this._captureFrameCommands.length,n=r;1===n.length&&void 0===n[0]&&(n.length=0),('beginRenderPass'===t||'beginComputePass'===t||'createCommandEncoder'===t||'finish'===t)&&(o.__id=`_${i}`);let a=null;if('setBindGroup'===t){a=[];const t=n[0],r=n[1];if(a.push(t),a.push(r),n.length>2&&n[2]?.length){const e=n[2];if(e.length>0)if(e instanceof Uint32Array){const t=n[3],r=n[4];if(r>0){const s=new Uint32Array(e.buffer,4*t,r);a.push(s)}}else a.push(e)}const s=a.length>2?a[2]:null;let o=0;const c=r.__descriptor,p=c.layout?.__descriptor;if(c)for(const t in c.entries){const r=c.entries[t],n=p?.entries[t],a=r?.resource?.buffer,d=n?.buffer?.hasDynamicOffset??!1;if(a){let n=r.resource.offset??0;const c=m(r.resource.size??a.size-n,4);c3){const e=n[3]??0,t=n[4],s=r instanceof ArrayBuffer?r:r.buffer;s&&(t>0?r=new Uint8Array(s,e,t):e>0&&(r=new Uint8Array(s,e)))}a.push(r)}else a=n;if(a=this._processCommandArgs(a),this._captureFrameCommands.push({class:e.constructor.name,object:e.__id,result:o?.__id??0,commandId:i,method:t,args:a,stacktrace:s}),'setIndexBuffer'===t&&(e.__indexBuffer=r),'setVertexBuffer'===t){const t=r[0],s=r[1],o=r[2]??0,n=r[3]??s.size-o;e.__captureBuffers||(e.__captureBuffers=[]),e.__captureBuffers.push({commandId:i,entryIndex:t,buffer:s,offset:o,size:n}),this._captureBuffersCount++,this._updateStatusMessage()}if('setIndexBuffer'===t){const t=r[0],s=t.size;e.__captureBuffers||(e.__captureBuffers=[]),e.__captureBuffers.push({commandId:i,entryIndex:0,buffer:t,offset:0,size:s}),this._captureBuffersCount++,this._updateStatusMessage()}if('drawIndirect'===t||'drawIndexedIndirect'===t||'dispatchWorkgroupsIndirect'===t){const t=r[0],s=0,o=t.size;e.__captureBuffers||(e.__captureBuffers=[]),e.__captureBuffers.push({commandId:i,entryIndex:0,buffer:t,offset:s,size:o}),this._captureBuffersCount++,this._updateStatusMessage()}if('beginRenderPass'===t){if(r[0]?.colorAttachments?.length>0){o.__captureTextureViews=new Set;for(const e of r[0].colorAttachments){if(!e)continue;const t=e.resolveTarget??e.view;o.__captureTextureViews.add(t)}}if(o.__descriptor=r[0],r[0]?.depthStencilAttachment){o.__captureTextureViews||(o.__captureTextureViews=new Set);const e=r[0].depthStencilAttachment,t=e.resolveTarget??e.view;o.__captureTextureViews.add(t)}this._inComputePass=!1,o.__commandEncoder=e}else if('beginComputePass'===t)o.__commandEncoder=e,this._inComputePass=!0;else if('end'===t){this._inComputePass=!1;const t=e.__commandEncoder;if(e.__captureBuffers?.length>0&&(this._recordCaptureBuffers(t,e.__captureBuffers),this._updateStatusMessage()),e.__captureTextureViews?.size>0){let r=10*this._frameRenderPassCount;for(const s of e.__captureTextureViews){const e=s.__texture;e&&this._captureTextureBuffer(t?.__device,t,e,r++)}e.__captureTextureViews.clear()}e.__commandEncoder=null,e instanceof GPURenderPassEncoder&&this._frameRenderPassCount++}}_sendCaptureTextureBuffers(e){const t=[];for(const r of e)t.push(r.id);let r=0;for(const t of e){const e=t.tempBuffer.size;r+=Math.ceil(e/P)}this._postMessage({action:p.CaptureTextureFrames,chunkCount:r,count:e.length,textures:t});for(const t of e){const{id:e,tempBuffer:r,passId:s}=t;this._mappedTextureBufferCount++;const o=this;r.mapAsync(GPUMapMode.READ).then((()=>{o._mappedTextureBufferCount--,o._updateStatusMessage();const t=r.getMappedRange(),i=new Uint8Array(t);o._sendTextureData(e,s,i),r.destroy()})).catch((e=>{console.error(e)}))}this._updateStatusMessage()}_sendTextureData(e,r,s){const o=s.length,i=Math.ceil(o/P),n=this;for(let a=0;a{n._postMessage({action:p.CaptureTextureData,id:e,passId:r,offset:c,size:o,index:a,count:i,chunk:t}),n._encodingTextureChunkCount--,n._updateStatusMessage()})).catch((e=>{console.log('Error encoding texture data:',e)}))}}_getTextureUtils(e){return e?(e.__textureUtils||(e.__textureUtils=new c(e)),e.__textureUtils):null}_sendBufferData(e,r,s){const o=s.length,i=Math.ceil(o/P),n=this;for(let a=0;a{n._postMessage({action:p.CaptureBufferData,commandId:e,entryIndex:r,offset:c,size:o,index:a,count:i,chunk:t}),n._encodingBufferChunkCount--,n._updateStatusMessage()})).catch((e=>{console.error(e.message)}))}}_sendTimestampBuffer(e,t){const r=this;t.mapAsync(GPUMapMode.READ).then((()=>{const e=t.getMappedRange(),s=new Uint8Array(e);r._sendBufferData(-1e3,-1e3,s),t.destroy()})).catch((e=>{console.error(e)}))}_sendCapturedBuffers(e){if(e.length>0){let t=0;for(const r of e){const e=r.tempBuffer.size;t+=Math.ceil(e/P)}this._postMessage({action:p.CaptureBuffers,count:e.length,chunkCount:t})}e.length;for(const t of e){const e=t.tempBuffer,r=t.commandId,s=t.entryIndex,o=this;this._mappedBufferCount++,this._updateStatusMessage(),e.mapAsync(GPUMapMode.READ).then((()=>{o._mappedBufferCount--,o._updateStatusMessage();const t=e.getMappedRange(),i=new Uint8Array(t);o._sendBufferData(r,s,i),e.destroy()})).catch((e=>{console.error(e)}))}}_recordCaptureBuffers(e,t){const r=e?.__device;if(!r)return this._captureBuffersCount-=t.length,void(t.length=0);for(const s of t){const{commandId:t,entryIndex:o,buffer:i,offset:n,size:a}=s;if(i.__destroyed)continue;let c=null;this.disableRecording();try{c=r.createBuffer({size:a,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,label:`BUFFER CAPTURE TEMP [${t},${o}]`}),e.copyBufferToBuffer(i,n,c,0,a),this._captureTempBuffers.push({commandId:t,entryIndex:o,tempBuffer:c})}catch(e){console.log(e)}this.enableRecording()}this._captureBuffersCount-=t.length,t.length=0}_captureTextureBuffer(e,t,r,s){if(!e)return;const o=!t;t??=e.createCommandEncoder(),s??=-1;const i=r.__id;let n=r.format,c=n?a[n]:void 0;if(!c)return;if(c.isDepthStencil){this.disableRecording();try{r=this._getTextureUtils(e).copyDepthTexture(r,'r32float',t)}catch(e){return this.enableRecording(),void console.log(e)}this.enableRecording(),n=r.format,c=n?a[n]:void 0,r.__id=i,this._toDestroy.push(r)}else if(r.sampleCount>1){this.disableRecording();try{(r=this._getTextureUtils(e).copyMultisampledTexture(r)).__id=i,this._toDestroy.push(r)}catch(e){return this.enableRecording(),void console.log(e)}this.enableRecording()}const p=r.width,d=r.height||1,u=r.depthOrArrayLayers||1,l=p*c.bytesPerBlock+255&-256,h=l*d*u;if(!h)return;const _={width:p,height:d,depthOrArrayLayers:u};let m=null;try{this.disableRecording(),m=e.createBuffer({size:h,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});const s='all';t.copyTextureToBuffer({texture:r,aspect:s},{buffer:m,bytesPerRow:l,rowsPerImage:d},_)}catch(e){console.log(e)}o&&e.queue.submit([t.finish()]),this.enableRecording(),m&&(this._captureTexturedBuffers.push({id:i,tempBuffer:m,width:p,height:d,depthOrArrayLayers:u,format:n,passId:s}),this._updateStatusMessage())}_addCommandData(e){if(this._captureFrameRequest){const t=this._frameData.length;return this._frameData.push(e),t}return-1}_isHTMLImageElement(e){return!!s&&(e instanceof HTMLImageElement||e instanceof HTMLCanvasElement||e instanceof HTMLVideoElement)}_processCommandArgs(e){if(!e||e.constructor===Number||e.constructor===String||e.constructor===Boolean)return e;if(void 0!==e.__id)return{__id:e.__id,__class:e.constructor.name};if(e instanceof ImageBitmap||e instanceof ImageData||e instanceof OffscreenCanvas||e instanceof VideoFrame||this._isHTMLImageElement(e))return`@-1 ${e.constructor.name} ${e.width} ${e.height}`;if(e instanceof Array||void 0!==e.buffer){const t=100;if(e.length>t){return`@${this._addCommandData(e)} ${e.constructor.name} ${e.byteLength}`}const r=[];for(const t in e)r[t]=this._processCommandArgs(e[t]);return r}if(e instanceof ArrayBuffer){return`@${this._addCommandData(e)} ${e.constructor.name} ${e.byteLength}`}if(e instanceof Object){const t={};for(const r in e)t[r]=this._processCommandArgs(e[r]);return t}return e}};const C=Worker;class k{constructor(){this._worker=new C(...arguments),function(e){if(!e.__webgpuInspector){if(e.__webgpuInspector=!0,e.terminate){const t=e.terminate;e.terminate=function(){const r=t.call(e,...arguments);return e.__webgpuInspector=!1,r}}e.addEventListener('message',(e=>{e.data.__webgpuInspector&&window.dispatchEvent(new CustomEvent('__WebGPUInspector',{detail:e.data}))})),window.addEventListener('__WebGPUInspector',(t=>{e.__webgpuInspector&&t.detail.__webgpuInspector&&!t.detail.__webgpuInspectorPage&&e.postMessage(t.detail)}))}}(this._worker)}}for(const e in C.prototype)'constructor'!==e&&(k.prototype[e]=function(){return this._worker[e].apply(this._worker,arguments)});Worker=k})(),Object.defineProperty(e,'__esModule',{value:!0})}({}); //# sourceMappingURL=webgpu_inspector.js.map diff --git a/extensions/firefox/webgpu_inspector_worker.js b/extensions/firefox/webgpu_inspector_worker.js index 4aff651..e9f7d2f 100644 --- a/extensions/firefox/webgpu_inspector_worker.js +++ b/extensions/firefox/webgpu_inspector_worker.js @@ -1,2 +1,2 @@ -var exports;(exports={}).webgpuInspectorWorker=e=>{if(!e.__webgpuInspector){if(e.__webgpuInspector=!0,e.terminate){const t=e.terminate;e.terminate=function(){const s=t.call(e,...arguments);return e.__webgpuInspector=!1,s}}e.addEventListener('message',(e=>{e.data.__webgpuInspector&&window.postMessage(e.data,'*')})),window.addEventListener('message',(t=>{e.__webgpuInspector&&t.data.__webgpuInspector&&!t.data.__webgpuInspectorPage&&e.postMessage(t.data)}))}},Object.defineProperty(exports,'__esModule',{value:!0}); +var exports;(exports={}).webgpuInspectorWorker=e=>{if(!e.__webgpuInspector){if(e.__webgpuInspector=!0,e.terminate){const t=e.terminate;e.terminate=function(){const n=t.call(e,...arguments);return e.__webgpuInspector=!1,n}}e.addEventListener('message',(e=>{e.data.__webgpuInspector&&window.dispatchEvent(new CustomEvent('__WebGPUInspector',{detail:e.data}))})),window.addEventListener('__WebGPUInspector',(t=>{e.__webgpuInspector&&t.detail.__webgpuInspector&&!t.detail.__webgpuInspectorPage&&e.postMessage(t.detail)}))}},Object.defineProperty(exports,'__esModule',{value:!0}); //# sourceMappingURL=webgpu_inspector_worker.js.map diff --git a/src/extension/content_script.js b/src/extension/content_script.js index cb1abaf..83fd689 100644 --- a/src/extension/content_script.js +++ b/src/extension/content_script.js @@ -12,7 +12,7 @@ const port = new MessagePort("webgpu-inspector-page", 0, (message) => { } if (action === PanelActions.RequestTexture || action === PanelActions.CompileShader || action === PanelActions.RevertShader) { - window.postMessage(message, "*"); + window.dispatchEvent(new CustomEvent("__WebGPUInspector", { detail: message })) return; } @@ -36,8 +36,9 @@ const port = new MessagePort("webgpu-inspector-page", 0, (message) => { inspectMessage = messageString; } else { sessionStorage.setItem(webgpuInspectorCaptureFrameKey, messageString); - window.postMessage({ __webgpuInspector: true, __webgpuInspectorPanel: true, action: PanelActions.Capture, - data: messageString }, "*"); + const message = { __webgpuInspector: true, __webgpuInspectorPanel: true, action: PanelActions.Capture, + data: messageString }; + window.dispatchEvent(new CustomEvent("__WebGPUInspector", { detail: message })) } } @@ -59,11 +60,8 @@ window.addEventListener('pageshow', (event) => { }); // Listen for messages from the page -window.addEventListener('message', (event) => { - if (event.source !== window) { - return; - } - const message = event.data; +window.addEventListener("__WebGPUInspector", (event) => { + const message = event.detail; if (typeof message !== 'object' || message === null) { return; } @@ -119,7 +117,6 @@ if (recordMessage) { removeUnusedResources: 1, messageRecording: 1 }); - } port.postMessage({action: "PageLoaded"}); diff --git a/src/webgpu_inspector.js b/src/webgpu_inspector.js index ed27809..b77427b 100644 --- a/src/webgpu_inspector.js +++ b/src/webgpu_inspector.js @@ -15,6 +15,7 @@ export let webgpuInspector = null; const _document = self.document; const _sessionStorage = self.sessionStorage; const _postMessage = self.postMessage; + const _dispatchEvent = self.dispatchEvent; const webgpuInspectorCaptureFrameKey = "WEBGPU_INSPECTOR_CAPTURE_FRAME"; @@ -181,18 +182,16 @@ export let webgpuInspector = null; }; // Listen for messages from the content-script. - _self.addEventListener("message", (event) => { - if (_window && event.source !== _window) { - return; - } - const message = event.data; + + function eventCallback(event) { + const message = event.detail || event.data; if (typeof message !== "object" || !message.__webgpuInspector) { return; } if (message.action === Actions.DeltaTime) { if (message.__webgpuInspectorWorker) { - this._updateFrameRate(message.deltaTime); + self._updateFrameRate(message.deltaTime); } } else if (message.action === PanelActions.RequestTexture) { const textureId = message.id; @@ -212,7 +211,13 @@ export let webgpuInspector = null; self._captureData = message.data; } } - }); + } + + if (!_window) { + _self.addEventListener("message", eventCallback); + } else { + _self.addEventListener("__WebGPUInspector", eventCallback); + } } captureWorker(canvas) { @@ -231,7 +236,11 @@ export let webgpuInspector = null; message.__webgpuInspector = true; message.__webgpuInspectorPage = true; message.__webgpuInspectorWorker = !_window; - _postMessage(message); + if (!_window) { + _postMessage(message); + } else { + _dispatchEvent(new CustomEvent("__WebGPUInspector", { detail: message })); + } } _updateCanvasAttachment(attachment) { diff --git a/src/webgpu_inspector_worker.js b/src/webgpu_inspector_worker.js index f85ab56..dae92d4 100644 --- a/src/webgpu_inspector_worker.js +++ b/src/webgpu_inspector_worker.js @@ -18,16 +18,16 @@ export function webgpuInspectorWorker(worker) { worker.addEventListener("message", (event) => { if (event.data.__webgpuInspector) { - window.postMessage(event.data, "*"); + window.dispatchEvent(new CustomEvent("__WebGPUInspector", { detail: event.data })); } }); - window.addEventListener("message", (event) => { + window.addEventListener("__WebGPUInspector", (event) => { // Forward messages from the page to the worker, if the worker hasn't been terminated, // the message is from the inspector, and the message is not from the worker. - if (worker.__webgpuInspector && event.data.__webgpuInspector && - !event.data.__webgpuInspectorPage) { - worker.postMessage(event.data); + if (worker.__webgpuInspector && event.detail.__webgpuInspector && + !event.detail.__webgpuInspectorPage) { + worker.postMessage(event.detail); } }); } diff --git a/test/webgpu_worker.js b/test/webgpu_worker.js index 11574f7..e9d8462 100644 --- a/test/webgpu_worker.js +++ b/test/webgpu_worker.js @@ -1,4 +1,5 @@ import { webgpuInspector } from 'https://cdn.jsdelivr.net/gh/brendan-duncan/webgpu_inspector@0.4/src/webgpu_inspector.js'; +//import { webgpuInspector } from '../src/webgpu_inspector.js'; self.addEventListener('message', (ev) => { switch (ev.data.type) { diff --git a/test/worker.html b/test/worker.html index 601b250..0991153 100644 --- a/test/worker.html +++ b/test/worker.html @@ -3,10 +3,12 @@