Skip to content

Worker support and non-extension usage #3

@rconde01

Description

@rconde01

First off, amazing tool! I had some things to resolve to use it:

  1. I need it to work in a worker
  2. I want it it worker programmatically instead of interactively.

I was able to get both to work but i'm not sure if/how you want to integrate it.

I changed to:

function __WebGPUReconstruct_requestAnimationFrame_callback(timestamp) {
    __WebGPUReconstruct_file.writeUint32(2);
    __WebGPUReconstruct_file.writeUint32(1);

    const globalScope =
        typeof window !== "undefined" ? window :
        typeof self !== "undefined" ? self :
        undefined;

    __webGPUReconstruct.animationFrameID = __webGPUReconstruct.requestAnimationFrame_original.call(globalScope, __WebGPUReconstruct_requestAnimationFrame_callback);
}

I have a maxFrames and numFrames. Because our requestAnimationFrame may run before our webgpu component is rendering, I count submits in __WebGPUReconstruct_GPUQueue_submit and only consider it a frame if it is non-zero for a call of requestAnimationFrame. Then when maxFrames is reached requestAnimationFrame calls finishCapture.

I removed document.addEventListener('__WebGPUReconstruct_saveCapture' add added this into finishCapture

        const blob = new Blob(__WebGPUReconstruct_file.arrays);
        postMessage({ type: 'wgpuCaptureData', data: blob });

Which is then hooked when the worker is created.

Ideally I'd like to see:

  • The build script/package containing a "manual" file which can be imported (could be useful as an npm package too)
  • Detect if it's in a worker or not and directly download or postmessage
  • Export the WebgpuReconstruct class so it can be created programmatically, and with configuration parameters (e.g. maxFrames)

If I know your thoughts I can also try to make a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions