Skip to content

Commit

Permalink
Fix recorder errors
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan-duncan committed Jan 19, 2024
1 parent 2532246 commit a8ebb70
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions webgpu_recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,18 +452,17 @@ class WebGPURecorder {
}
} else if (method == "copyExternalImageToTexture") {
origMethod.call(object, ...arguments);

// copyExternalImageToTexture uses ImageBitmap (or canvas or offscreenCanvas) as
// its source, which we can't record. ConvertcopyExternalImageToTexture to
// writeTexture, and record the bytes from the ImageBitmap. To do that, we need
// to draw the ImageBitmap into a canvas, and record the bytes from that.
// A very heavy process, but not sure what else to do.
let bytes = self._getBytesFromImageSource(arguments[0].source);
let bytesPerPixel = 4;
let bytesPerRow = arguments[0].source.width * bytesPerPixel;

let cacheIndex = self._getDataCache(bytes, bytes.byteOffset, bytes.byteLength, texture);
const bytes = self._getBytesFromImageSource(arguments[0].source);
const bytesPerPixel = 4;
const bytesPerRow = arguments[0].source.width * bytesPerPixel;
const texture = arguments[1]["texture"];
const cacheIndex = self._getDataCache(bytes, bytes.byteOffset, bytes.byteLength, texture);
self._recordLine(`${self._getObjectVariable(object)}.writeTexture(${self._stringifyObject(method, arguments[1])}, D[${cacheIndex}], {bytesPerRow:${bytesPerRow}}, ${self._stringifyObject(method, arguments[2])});`, object);

return;
Expand Down Expand Up @@ -822,11 +821,12 @@ class WebGPURecorder {
}

if (method == "requestAdapter") {
const adapter = this._getObjectVariable(result);
this._recordLine(`const _limits = {};
const exclude = new Set(["minSubgroupSize", "maxSubgroupSize"]);
for (const x in xAdapter4.limits) {
for (const x in ${adapter}.limits) {
if (!exclude.has(x)) {
_limits[x] = xAdapter4.limits[x];
_limits[x] = ${adapter}.limits[x];
}
}`, obj);
}
Expand Down Expand Up @@ -952,3 +952,31 @@ class WebGPURecorder {
"astc-12x12-unorm": { "blockWidth": 12, "blockHeight": 12, "bytesPerBlock": 16 },
"astc-12x12-unorm-srgb": { "blockWidth": 12, "blockHeight": 12, "bytesPerBlock": 16 },
};


// -------------
// Auto start recording on script load if filename is provided:
// webgpu_recorder.js?filename=foo
function getParameterByName(name, url) {
name = name.replace(/[\[\]]/g, '\\$&');
const regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)');
const results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}

function main() {
const filename = getParameterByName("filename", document.currentScript.src);
const frames = getParameterByName("frames", document.currentScript.src);
const removeUnusedResources = getParameterByName("removeUnusedResources", document.currentScript.src);
if (filename) {
new WebGPURecorder({
"frames": frames || 1,
"export": filename,
"removeUnusedResources": !!removeUnusedResources
});
}
}

main();

0 comments on commit a8ebb70

Please sign in to comment.