Skip to content

Commit 3722912

Browse files
committed
Web Inspector: Canvas: support recording WebGPU devices
https://bugs.webkit.org/show_bug.cgi?id=201651 Reviewed by Mike Wyrzykowski. * Source/WebCore/Modules/WebGPU/GPUDevice.idl: * Source/WebCore/Modules/WebGPU/GPUDevice.h: (WebCore::GPUDevice::hasActiveInspectorCanvasCallTracer const): Added. (WebCore::GPUDevice::setHasActiveInspectorCanvasCallTracer): Added. * Source/WebCore/Modules/WebGPU/GPUDevice.cpp: (WebCore::GPUDevice::GPUDevice): (WebCore::GPUDevice::createSampler): (WebCore::GPUDevice::importExternalTexture): (WebCore::GPUDevice::createBindGroupLayout): (WebCore::GPUDevice::createAutoPipelineLayout): (WebCore::GPUDevice::createPipelineLayout): (WebCore::GPUDevice::createBindGroup): (WebCore::GPUDevice::createShaderModule): (WebCore::GPUDevice::createCommandEncoder): (WebCore::GPUDevice::createRenderBundleEncoder): (WebCore::GPUDevice::createQuerySet): * Source/WebCore/Modules/WebGPU/GPUQueue.idl: * Source/WebCore/Modules/WebGPU/GPUQueue.h: (WebCore::GPUQueue::create): * Source/WebCore/Modules/WebGPU/GPUQueue.cpp: (WebCore::GPUQueue::GPUQueue): (WebCore::GPUQueue::hasActiveInspectorCanvasCallTracer const): Added. (WebCore::GPUQueue::device const): Added. (WebCore::GPUQueue::submit): * Source/WebCore/Modules/WebGPU/GPUBuffer.idl: * Source/WebCore/Modules/WebGPU/GPUBuffer.h: * Source/WebCore/Modules/WebGPU/GPUBuffer.cpp: (WebCore::GPUBuffer::hasActiveInspectorCanvasCallTracer const): Added. (WebCore::GPUBuffer::device const): Added. * Source/WebCore/Modules/WebGPU/GPUTexture.idl: * Source/WebCore/Modules/WebGPU/GPUTexture.h: (WebCore::GPUTexture::create): * Source/WebCore/Modules/WebGPU/GPUTexture.cpp: (WebCore::GPUTexture::GPUTexture): (WebCore::GPUTexture::hasActiveInspectorCanvasCallTracer const): Added. (WebCore::GPUTexture::device const): Added. (WebCore::GPUTexture::createView): * Source/WebCore/Modules/WebGPU/GPUTextureView.idl: * Source/WebCore/Modules/WebGPU/GPUTextureView.h: (WebCore::GPUTextureView::create): * Source/WebCore/Modules/WebGPU/GPUTextureView.cpp: (WebCore::GPUTextureView::GPUTextureView): Added. (WebCore::GPUTextureView::hasActiveInspectorCanvasCallTracer const): Added. (WebCore::GPUTextureView::device const): Added. * Source/WebCore/Modules/WebGPU/GPUExternalTexture.idl: * Source/WebCore/Modules/WebGPU/GPUExternalTexture.h: (WebCore::GPUExternalTexture::create): * Source/WebCore/Modules/WebGPU/GPUExternalTexture.cpp: (WebCore::GPUExternalTexture::GPUExternalTexture): Added. (WebCore::GPUExternalTexture::hasActiveInspectorCanvasCallTracer const): Added. (WebCore::GPUExternalTexture::device const): Added. * Source/WebCore/Modules/WebGPU/GPUSampler.idl: * Source/WebCore/Modules/WebGPU/GPUSampler.h: (WebCore::GPUSampler::create): * Source/WebCore/Modules/WebGPU/GPUSampler.cpp: (WebCore::GPUSampler::GPUSampler): Added. (WebCore::GPUSampler::hasActiveInspectorCanvasCallTracer const): Added. (WebCore::GPUSampler::device const): Added. * Source/WebCore/Modules/WebGPU/GPUBindGroupLayout.idl: * Source/WebCore/Modules/WebGPU/GPUBindGroupLayout.h: (WebCore::GPUBindGroupLayout::create): * Source/WebCore/Modules/WebGPU/GPUBindGroupLayout.cpp: (WebCore::GPUBindGroupLayout::GPUBindGroupLayout): Added. (WebCore::GPUBindGroupLayout::hasActiveInspectorCanvasCallTracer const): Added. (WebCore::GPUBindGroupLayout::device const): Added. * Source/WebCore/Modules/WebGPU/GPUBindGroup.idl: * Source/WebCore/Modules/WebGPU/GPUBindGroup.h: (WebCore::GPUBindGroup::create): * Source/WebCore/Modules/WebGPU/GPUBindGroup.cpp: (WebCore::GPUBindGroup::hasActiveInspectorCanvasCallTracer const): Added. (WebCore::GPUBindGroup::device const): Added. (WebCore::GPUBindGroup::GPUBindGroup): * Source/WebCore/Modules/WebGPU/GPUPipelineLayout.idl: * Source/WebCore/Modules/WebGPU/GPUPipelineLayout.h: (WebCore::GPUPipelineLayout::create): * Source/WebCore/Modules/WebGPU/GPUPipelineLayout.cpp: (WebCore::GPUPipelineLayout::GPUPipelineLayout): Added. (WebCore::GPUPipelineLayout::hasActiveInspectorCanvasCallTracer const): Added. (WebCore::GPUPipelineLayout::device const): Added. * Source/WebCore/Modules/WebGPU/GPUShaderModule.idl: * Source/WebCore/Modules/WebGPU/GPUShaderModule.h: (WebCore::GPUShaderModule::create): * Source/WebCore/Modules/WebGPU/GPUShaderModule.cpp: (WebCore::GPUShaderModule::GPUShaderModule): Added. (WebCore::GPUShaderModule::hasActiveInspectorCanvasCallTracer const): Added. (WebCore::GPUShaderModule::device const): Added. * Source/WebCore/Modules/WebGPU/GPUComputePipeline.idl: * Source/WebCore/Modules/WebGPU/GPUComputePipeline.h: * Source/WebCore/Modules/WebGPU/GPUComputePipeline.cpp: (WebCore::GPUComputePipeline::hasActiveInspectorCanvasCallTracer const): Added. (WebCore::GPUComputePipeline::getBindGroupLayout): * Source/WebCore/Modules/WebGPU/GPURenderPipeline.idl: * Source/WebCore/Modules/WebGPU/GPURenderPipeline.h: * Source/WebCore/Modules/WebGPU/GPURenderPipeline.cpp: (WebCore::GPURenderPipeline::hasActiveInspectorCanvasCallTracer const): Added. (WebCore::GPURenderPipeline::getBindGroupLayout): * Source/WebCore/Modules/WebGPU/GPUCommandEncoder.idl: * Source/WebCore/Modules/WebGPU/GPUCommandEncoder.h: (WebCore::GPUCommandEncoder::create): * Source/WebCore/Modules/WebGPU/GPUCommandEncoder.cpp: (WebCore::GPUCommandEncoder::GPUCommandEncoder): (WebCore::GPUCommandEncoder::hasActiveInspectorCanvasCallTracer const): Added. (WebCore::GPUCommandEncoder::device const): Added. (WebCore::GPUCommandEncoder::beginRenderPass): (WebCore::GPUCommandEncoder::beginComputePass): (WebCore::GPUCommandEncoder::finish): * Source/WebCore/Modules/WebGPU/GPUComputePassEncoder.idl: * Source/WebCore/Modules/WebGPU/GPUComputePassEncoder.h: (WebCore::GPUComputePassEncoder::create): * Source/WebCore/Modules/WebGPU/GPUComputePassEncoder.cpp: (WebCore::GPUComputePassEncoder::GPUComputePassEncoder): (WebCore::GPUComputePassEncoder::hasActiveInspectorCanvasCallTracer const): Added. (WebCore::GPUComputePassEncoder::device const): Added. (WebCore::GPUComputePassEncoder::end): * Source/WebCore/Modules/WebGPU/GPURenderPassEncoder.idl: * Source/WebCore/Modules/WebGPU/GPURenderPassEncoder.h: (WebCore::GPURenderPassEncoder::create): * Source/WebCore/Modules/WebGPU/GPURenderPassEncoder.cpp: (WebCore::GPURenderPassEncoder::GPURenderPassEncoder): (WebCore::GPURenderPassEncoder::hasActiveInspectorCanvasCallTracer const): Added. (WebCore::GPURenderPassEncoder::device const): Added. (WebCore::GPURenderPassEncoder::end): * Source/WebCore/Modules/WebGPU/GPURenderBundleEncoder.idl: * Source/WebCore/Modules/WebGPU/GPURenderBundleEncoder.h: (WebCore::GPURenderBundleEncoder::create): * Source/WebCore/Modules/WebGPU/GPURenderBundleEncoder.cpp: (WebCore::GPURenderBundleEncoder::GPURenderBundleEncoder): Added. (WebCore::GPURenderBundleEncoder::hasActiveInspectorCanvasCallTracer const): Added. (WebCore::GPURenderBundleEncoder::device const): Added. (WebCore::GPURenderBundleEncoder::finish): * Source/WebCore/Modules/WebGPU/GPURenderBundle.idl: * Source/WebCore/Modules/WebGPU/GPURenderBundle.h: (WebCore::GPURenderBundle::create): * Source/WebCore/Modules/WebGPU/GPURenderBundle.cpp: (WebCore::GPURenderBundle::GPURenderBundle): Added. (WebCore::GPURenderBundle::hasActiveInspectorCanvasCallTracer const): Added. (WebCore::GPURenderBundle::device const): Added. * Source/WebCore/Modules/WebGPU/GPUCommandBuffer.idl: * Source/WebCore/Modules/WebGPU/GPUCommandBuffer.h: * Source/WebCore/Modules/WebGPU/GPUCommandBuffer.cpp: (WebCore::GPUCommandBuffer::hasActiveInspectorCanvasCallTracer const): Added. (WebCore::GPUCommandBuffer::device const): Added. * Source/WebCore/Modules/WebGPU/GPUQuerySet.idl: * Source/WebCore/Modules/WebGPU/GPUQuerySet.h: (WebCore::GPUQuerySet::create): * Source/WebCore/Modules/WebGPU/GPUQuerySet.cpp: (WebCore::GPUQuerySet::GPUQuerySet): (WebCore::GPUQuerySet::hasActiveInspectorCanvasCallTracer const): Added. (WebCore::GPUQuerySet::device const): Added. * Source/WebCore/Modules/WebGPU/GPUPresentationContext.h: * Source/WebCore/inspector/RecordingSwizzleType.h: * Source/WebCore/inspector/InspectorCanvasCallTracer.h: (WebCore::InspectorCanvasCallTracer::processArgument): (WebCore::InspectorCanvasCallTracer::recordAction): (WebCore::InspectorCanvasCallTracer::receiverSwizzleType): Added. (WebCore::InspectorCanvasCallTracer::receiverSwizzleTypeImpl): Added. * Source/WebCore/inspector/InspectorCanvasCallTracer.cpp: (WebCore::enabledCanvasAgent): (WebCore::InspectorCanvasCallTracer::enabledInspectorCanvas): (WebCore::InspectorCanvasCallTracer::recordAction): Add `CallTrace` to every WebGPU IDL (including those without any methods today so future API additions automatically get support). Each object now has a link to the owner `GPUDevice` so the `CallTracer` can check whether recording is active. * Source/JavaScriptCore/inspector/protocol/Recording.json: * Source/JavaScriptCore/inspector/scripts/codegen/generator.py: * Source/WebCore/inspector/InspectorCanvas.h: * Source/WebCore/inspector/InspectorCanvas.cpp: (WebCore::InspectorCanvas::hasActiveInspectorCanvasCallTracer): Added. (WebCore::InspectorCanvas::setHasActiveInspectorCanvasCallTracer): Added. (WebCore::InspectorCanvas::resetRecordingData): (WebCore::shouldSnapshotWebGPUAction): Added. (WebCore::InspectorCanvas::recordAction): (WebCore::buildActionReceiver): Added. (WebCore::InspectorCanvas::releaseObjectForRecording): (WebCore::InspectorCanvas::getContentAsDataURL): Added WebGPU support for device-backed canvases. (WebCore::InspectorCanvas::appendActionSnapshotIfNeeded): (WebCore::InspectorCanvas::identifierForRecordingObject): Added. (WebCore::InspectorCanvas::buildInitialState): Store explicit receivers as `[identifier, swizzleType]` before the optional snapshot field. * Source/WebCore/inspector/agents/InspectorCanvasAgent.h: * Source/WebCore/inspector/agents/InspectorCanvasAgent.cpp: (WebCore::InspectorCanvasAgent::startRecording): (WebCore::InspectorCanvasAgent::stopRecording): (WebCore::InspectorCanvasAgent::didFinishRecordingCanvasFrame): (WebCore::InspectorCanvasAgent::didCreateWebGPUDevice): (WebCore::InspectorCanvasAgent::recordAction): (WebCore::InspectorCanvasAgent::scheduleRecordingCanvasFrame): Added. (WebCore::InspectorCanvasAgent::consoleStartRecordingCanvas): (WebCore::InspectorCanvasAgent::consoleStopRecordingCanvas): (WebCore::InspectorCanvasAgent::reset): (WebCore::InspectorCanvasAgent::unbindCanvas): Support explicit and automatic `GPUDevice` recordings. * Source/WebCore/page/FrameConsoleClient.cpp: (WebCore::FrameConsoleClient::record): (WebCore::FrameConsoleClient::recordEnd): * Source/WebCore/workers/WorkerConsoleClient.cpp: (WebCore::WorkerConsoleClient::record): (WebCore::WorkerConsoleClient::recordEnd): * Source/WebCore/inspector/InspectorInstrumentation.h: (WebCore::InspectorInstrumentation::consoleStartRecordingCanvas): (WebCore::InspectorInstrumentation::consoleStopRecordingCanvas): * Source/WebCore/inspector/InspectorInstrumentation.cpp: (WebCore::InspectorInstrumentation::consoleStartRecordingCanvasImpl): (WebCore::InspectorInstrumentation::consoleStopRecordingCanvasImpl): Support `console.record()` and `console.recordEnd()` for `GPUDevice`. * Source/WebInspectorUI/UserInterface/Models/Canvas.js: (WI.Canvas.prototype.get supportsRecording): Deleted. (WI.Canvas.prototype.recordingProgress): * Source/WebInspectorUI/UserInterface/Views/CanvasContentView.js: (WI.CanvasContentView.prototype.initialLayout): * Source/WebInspectorUI/UserInterface/Views/CanvasSidebarPanel.js: (WI.CanvasSidebarPanel.prototype._canvasChanged): (WI.CanvasSidebarPanel.prototype._updateRecordNavigationItem): Pass the backend recording version when parsing a live recording. * Source/WebInspectorUI/UserInterface/Models/Recording.js: (WI.Recording.fromPayload): (WI.Recording.displayNameForRecordingType): (WI.Recording.displayNameForReceiver): Added. (WI.Recording.prototype.get isCanvas): (WI.Recording.prototype.get isCanvasWebGPU): Added. (WI.Recording.prototype.createContext): (WI.Recording.prototype.toJSON): (WI.Recording.prototype.toHTML): (WI.Recording.prototype._process): * Source/WebInspectorUI/UserInterface/Models/RecordingAction.js: (WI.RecordingAction): (WI.RecordingAction.fromPayload): (WI.RecordingAction.isFunctionForType): (WI.RecordingAction.bitfieldNamesForParameter): (WI.RecordingAction.constantNameForParameter): (WI.RecordingAction._prototypeForType): (WI.RecordingAction.prototype.get receiver): Added. (WI.RecordingAction.prototype.get contextReplacer): Deleted. (WI.RecordingAction.prototype.process): (WI.RecordingAction.prototype.swizzle): (WI.RecordingAction.prototype.get isCanvasReceiver): Added. (WI.RecordingAction.prototype.apply): (WI.RecordingAction.prototype.toJSON): * Source/WebInspectorUI/UserInterface/Models/RecordingFrame.js: (WI.RecordingFrame.fromPayload): (WI.RecordingFrame.prototype.toJSON): Parse snapshot-based WebGPU recordings without attempting to replay WebGPU commands. Display receiver identifier and type pairs as lower-camel-cased names. Drive-by: Include offscreen WebGL(2) recordings when resolving constants, bitfields, and snapshot-based processing. * Source/WebInspectorUI/UserInterface/Views/RecordingActionTreeElement.js: (WI.RecordingActionTreeElement._generateDOM): (WI.RecordingActionTreeElement._classNameForAction): (WI.RecordingActionTreeElement.prototype.populateContextMenu): * Source/WebInspectorUI/UserInterface/Views/RecordingActionTreeElement.css: (body:not(.window-inactive, .window-docked-inactive) .tree-outline:focus-within .item.recording-action.selected:not(.invalid, .initial-state, .name-unknown) > .icon): Renamed from `body:not(.window-inactive, .window-docked-inactive) .tree-outline:focus-within .item.recording-action.selected:not(.invalid, .initial-state, .has-context-replacer, .name-unknown) > .icon`. (.item.recording-action:not(.invalid, .initial-state, .name-unknown) > .icon): Renamed from `.item.recording-action:not(.invalid, .initial-state, .has-context-replacer, .name-unknown) > .icon`. Display only explicit receivers and copy actions against the correct `GPUDevice`, `CanvasRenderingContext`, or `<canvas>`. * Source/WebInspectorUI/UserInterface/Views/RecordingContentView.js: (WI.RecordingContentView): (WI.RecordingContentView.prototype._generateContentFromSnapshot): (WI.RecordingContentView.prototype._updateImageGrid): Show WebGPU content from snapshots and clear stale preview content when a recording has no initial snapshot. * Source/WebInspectorUI/UserInterface/Views/TreeOutline.js: (WI.TreeOutline.prototype.registerScrollVirtualizer): Drive-by: disable native scroll anchoring when virtualized so recycled recording rows do not cause scrolling to continue on its own. * Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js: * LayoutTests/inspector/canvas/recording.html: * LayoutTests/inspector/canvas/recording-expected.txt: * LayoutTests/inspector/canvas/recording-webgpu.html: Added. * LayoutTests/inspector/canvas/recording-webgpu-expected.txt: Added. * LayoutTests/platform/glib/TestExpectations: * LayoutTests/platform/win/TestExpectations: Canonical link: https://commits.webkit.org/318407@main
1 parent 0a2f1dc commit 3722912

91 files changed

Lines changed: 1557 additions & 431 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎LayoutTests/inspector/canvas/recording-expected.txt‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ PASS: The first frame should have 1 action.
88
PASS: The action should have 1 parameter.
99
PASS: The parameter should be null.
1010

11+
-- Running test case: Canvas.ActionReceiver
12+
PASS: Width and height getters and setters should be recorded.
13+
PASS: Width and height actions should identify the canvas receiver.
14+
PASS: Width and height actions should be recognized as canvas receiver actions.
15+
PASS: The serialized receiver should identify the canvas.
16+
PASS: Legacy width and height actions should not have a receiver.
17+
PASS: Legacy width and height actions should still be recognized as canvas receiver actions.
18+
1119
-- Running test case: Canvas.MultipleRecording
1220
Starting a recording of canvas 1...
1321
PASS: Recording started of canvas 1
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Test that CanvasManager is able to record actions made to WebGPU devices.
2+
3+
4+
== Running test suite: Canvas.recordingWebGPU
5+
-- Running test case: Canvas.recordingWebGPU.singleFrame
6+
PASS: The recording should have the WebGPU type.
7+
PASS: The recording should have initial canvas content.
8+
PASS: Device actions should use the implicit device receiver.
9+
PASS: Setting a label should be recorded as an attribute setter.
10+
PASS: Getting a label should be recorded as an attribute getter.
11+
PASS: The recording should create a concise name for a WebGPU receiver.
12+
PASS: The recording should identify each explicit receiver type.
13+
PASS: Command encoder actions should have the same receiver.
14+
PASS: Different command encoders should have different receivers.
15+
PASS: Render pass actions should have the same receiver.
16+
PASS: Queue actions should have the same receiver.
17+
PASS: Submitting work should capture a snapshot.
18+
PASS: An action without a snapshot should not include a snapshot placeholder.
19+
PASS: The serialized receiver should contain an identifier and swizzle type.
20+
PASS: The serialized receiver should precede the snapshot.
21+
PASS: The serialized snapshot should follow the receiver.
22+
23+
-- Running test case: Canvas.recordingWebGPU.Console
24+
PASS: The recording should have the name "TEST".
25+
PASS: The recording should have one frame.
26+
PASS: The first frame should have one action.
27+
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<!-- webkit-test-runner [ WebGPUEnabled=true ] -->
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
6+
<script src="resources/recording-utilities.js"></script>
7+
<script>
8+
let device = null;
9+
let context = null;
10+
11+
async function render(clearValue) {
12+
let commandEncoder = device.createCommandEncoder();
13+
let renderPassEncoder = commandEncoder.beginRenderPass({
14+
colorAttachments: [{
15+
view: context.getCurrentTexture().createView(),
16+
clearValue,
17+
loadOp: "clear",
18+
storeOp: "store",
19+
}],
20+
});
21+
renderPassEncoder.setViewport(0, 0, 4, 4, 0, 1);
22+
renderPassEncoder.end();
23+
device.queue.submit([commandEncoder.finish()]);
24+
await device.queue.onSubmittedWorkDone();
25+
return commandEncoder;
26+
}
27+
28+
function cancelActions() {
29+
// This function is expected by "resources/recording-utilities.js".
30+
}
31+
32+
async function performActions() {
33+
device.label = "device";
34+
device.label;
35+
let bindGroup = device.createBindGroup({layout: device.createBindGroupLayout({entries: []}), entries: []});
36+
bindGroup.label = "bindGroup";
37+
await Promise.all([
38+
render({r: 0, g: 1, b: 0, a: 1}),
39+
render({r: 0, g: 0, b: 1, a: 1}),
40+
]);
41+
setTimeout(() => TestPage.dispatchEventToFrontend("LastFrame"), 0);
42+
}
43+
44+
function performConsoleActions() {
45+
console.record(device, {name: "TEST"});
46+
47+
device.label = "recorded";
48+
49+
console.recordEnd(device);
50+
51+
device.label;
52+
}
53+
54+
async function load() {
55+
let adapter = await navigator.gpu.requestAdapter();
56+
device = await adapter.requestDevice();
57+
58+
context = document.querySelector("canvas").getContext("webgpu");
59+
context.configure({
60+
device,
61+
format: navigator.gpu.getPreferredCanvasFormat(),
62+
});
63+
await render({r: 1, g: 0, b: 0, a: 1});
64+
65+
runTest();
66+
}
67+
68+
function test() {
69+
let suite = InspectorTest.createAsyncSuite("Canvas.recordingWebGPU");
70+
71+
suite.addTestCase({
72+
name: "Canvas.recordingWebGPU.singleFrame",
73+
description: "Check that WebGPU device actions record stable receivers and snapshots.",
74+
test(resolve, reject) {
75+
async function checkRecording(recording) {
76+
let actions = recording.frames.flatMap((frame) => frame.actions);
77+
78+
InspectorTest.expectEqual(recording.type, WI.Recording.Type.CanvasWebGPU, "The recording should have the WebGPU type.");
79+
InspectorTest.expectGreaterThan(recording.initialState.content.length, "data:image/png;base64,".length, "The recording should have initial canvas content.");
80+
81+
let deviceLabelActions = actions.filter((action) => action.name === "label" && !action.receiver);
82+
InspectorTest.expectEqual(deviceLabelActions.length, 2, "Device actions should use the implicit device receiver.");
83+
InspectorTest.expectFalse(deviceLabelActions[0].isGetter, "Setting a label should be recorded as an attribute setter.");
84+
InspectorTest.expectTrue(deviceLabelActions[1].isGetter, "Getting a label should be recorded as an attribute getter.");
85+
86+
let bindGroupLabelAction = actions.find((action) => action.name === "label" && action.receiver === "bindGroup1");
87+
InspectorTest.expectTrue(bindGroupLabelAction, "The recording should create a concise name for a WebGPU receiver.");
88+
89+
let receiverTypes = Array.from(new Set(actions.filter((action) => action.receiver).map((action) => action.receiver.replace(/\d+$/, "")))).sort();
90+
InspectorTest.expectEqual(receiverTypes.join(", "), "bindGroup, commandEncoder, queue, renderPassEncoder, texture", "The recording should identify each explicit receiver type.");
91+
92+
let beginRenderPassActions = actions.filter((action) => action.name === "beginRenderPass");
93+
let finishActions = actions.filter((action) => action.name === "finish");
94+
InspectorTest.expectEqual(beginRenderPassActions[0].receiver, finishActions[0].receiver, "Command encoder actions should have the same receiver.");
95+
InspectorTest.expectNotEqual(beginRenderPassActions[0].receiver, beginRenderPassActions[1].receiver, "Different command encoders should have different receivers.");
96+
97+
let setViewportAction = actions.find((action) => action.name === "setViewport");
98+
let endAction = actions.find((action) => action.name === "end");
99+
InspectorTest.expectEqual(setViewportAction.receiver, endAction.receiver, "Render pass actions should have the same receiver.");
100+
101+
let submitAction = actions.find((action) => action.name === "submit");
102+
let workDoneAction = actions.find((action) => action.name === "onSubmittedWorkDone");
103+
InspectorTest.expectEqual(submitAction.receiver, workDoneAction.receiver, "Queue actions should have the same receiver.");
104+
InspectorTest.expectGreaterThan(submitAction.snapshot.length, "data:image/png;base64,".length, "Submitting work should capture a snapshot.");
105+
106+
let serializedRecording = recording.toJSON();
107+
let serializedAction = beginRenderPassActions[0].toJSON(serializedRecording.version);
108+
InspectorTest.expectEqual(serializedAction.length, 5, "An action without a snapshot should not include a snapshot placeholder.");
109+
InspectorTest.expectTrue(Array.isArray(serializedAction[4]) && serializedAction[4].length === 2 && typeof serializedAction[4][0] === "number" && serializedAction[4][1] === WI.Recording.Swizzle.GPUCommandEncoder, "The serialized receiver should contain an identifier and swizzle type.");
110+
111+
let serializedSnapshotAction = submitAction.toJSON(serializedRecording.version);
112+
InspectorTest.expectEqual(serializedSnapshotAction[4][1], WI.Recording.Swizzle.GPUQueue, "The serialized receiver should precede the snapshot.");
113+
InspectorTest.expectTrue(serializedRecording.data[serializedSnapshotAction[5]].startsWith("data:image/png;base64,"), "The serialized snapshot should follow the receiver.");
114+
}
115+
116+
startRecording(WI.Canvas.ContextType.WebGPU, resolve, reject, {frameCount: 1, callback: checkRecording});
117+
},
118+
timeout: -1,
119+
});
120+
121+
suite.addTestCase({
122+
name: "Canvas.recordingWebGPU.Console",
123+
description: "Check that a recording can be triggered by console.record().",
124+
test(resolve, reject) {
125+
consoleRecord(WI.Canvas.ContextType.WebGPU, resolve, reject);
126+
},
127+
});
128+
129+
suite.runTestCasesAndFinish();
130+
}
131+
</script>
132+
</head>
133+
<body onload="window.testRunner?.waitUntilDone(); load()">
134+
<canvas width="4" height="4"></canvas>
135+
<p>Test that CanvasManager is able to record actions made to WebGPU devices.</p>
136+
</body>
137+
</html>

‎LayoutTests/inspector/canvas/recording.html‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111
contextB.globalAlpha = NaN;
1212
}
1313

14+
function performActionsWithCanvasReceiver() {
15+
for (let context of [contextA, contextB]) {
16+
context.canvas.width;
17+
context.canvas.width = 2;
18+
context.canvas.height;
19+
context.canvas.height = 2;
20+
}
21+
}
22+
1423
function performActionsMultiple() {
1524
contextA.fill();
1625
contextB.fill();
@@ -54,6 +63,48 @@
5463
},
5564
});
5665

66+
suite.addTestCase({
67+
name: "Canvas.ActionReceiver",
68+
description: "Check that canvas actions identify their receiver.",
69+
test(resolve, reject) {
70+
let canvas = Array.from(WI.canvasManager.canvasCollection)[0];
71+
InspectorTest.assert(canvas, "There should be at least one canvas context.");
72+
73+
canvas.awaitEvent(WI.Canvas.Event.RecordingStopped)
74+
.then(async (event) => {
75+
let recording = event.data.recording;
76+
await Promise.all(recording.actions.map((action) => action.swizzle(recording)));
77+
78+
let actions = recording.frames[0].actions;
79+
InspectorTest.expectEqual(actions.length, 4, "Width and height getters and setters should be recorded.");
80+
InspectorTest.expectTrue(actions.every((action) => action.receiver === "canvas"), "Width and height actions should identify the canvas receiver.");
81+
InspectorTest.expectTrue(actions.every((action) => action.isCanvasReceiver), "Width and height actions should be recognized as canvas receiver actions.");
82+
83+
let payload = recording.toJSON();
84+
InspectorTest.expectTrue(payload.frames[0].actions.every((action) => Array.isArray(action[4]) && action[4][0] === 0 && action[4][1] === WI.Recording.Swizzle.Canvas), "The serialized receiver should identify the canvas.");
85+
86+
let legacyPayload = JSON.parse(JSON.stringify(payload));
87+
legacyPayload.version = 2;
88+
legacyPayload.frames = recording.frames.map((frame) => frame.toJSON(legacyPayload.version));
89+
90+
let legacyRecording = WI.Recording.fromPayload(legacyPayload);
91+
await Promise.all(legacyRecording.actions.map((action) => action.swizzle(legacyRecording)));
92+
93+
let legacyActions = legacyRecording.frames[0].actions;
94+
InspectorTest.expectTrue(legacyActions.every((action) => !action.receiver), "Legacy width and height actions should not have a receiver.");
95+
InspectorTest.expectTrue(legacyActions.every((action) => action.isCanvasReceiver), "Legacy width and height actions should still be recognized as canvas receiver actions.");
96+
})
97+
.then(resolve, reject);
98+
99+
canvas.awaitEvent(WI.Canvas.Event.RecordingStarted)
100+
.then(() => InspectorTest.evaluateInPage(`performActionsWithCanvasReceiver()`))
101+
.then(() => canvas.stopRecording())
102+
.catch(reject);
103+
104+
canvas.startRecording();
105+
},
106+
});
107+
57108
suite.addTestCase({
58109
name: "Canvas.MultipleRecording",
59110
description: "Check that multiple recordings are able to be started/stopped at the same time.",

‎LayoutTests/platform/glib/TestExpectations‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4211,6 +4211,7 @@ webkit.org/b/236298 fast/text/combining-character-sequence-vertical.html [ Image
42114211
fast/webgpu [ Skip ]
42124212
http/tests/webgpu/webgpu/api/operation/memory_sync/buffer/multiple_buffers.html [ Skip ]
42134213
inspector/canvas/create-context-webgpu.html [ Skip ]
4214+
inspector/canvas/recording-webgpu.html [ Skip ]
42144215
inspector/canvas/requestClientNodes-webgpu.html [ Skip ]
42154216
inspector/canvas/requestContent-webgpu.html [ Skip ]
42164217
inspector/canvas/requestShaderSource-webgpu.html [ Skip ]

‎LayoutTests/platform/win/TestExpectations‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ fast/webcodecs/audio-data-copy-to-crash.html [ Skip ]
113113
http/tests/webgpu [ Skip ]
114114
fast/webgpu [ Skip ]
115115
inspector/canvas/create-context-webgpu.html [ Skip ]
116+
inspector/canvas/recording-webgpu.html [ Skip ]
116117
inspector/canvas/requestClientNodes-webgpu.html [ Skip ]
117118
inspector/canvas/requestContent-webgpu.html [ Skip ]
118119
inspector/canvas/requestShaderSource-webgpu.html [ Skip ]

‎Source/JavaScriptCore/inspector/protocol/Recording.json‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "General types used for recordings of actions performed in the inspected page.",
44
"debuggableTypes": ["web-page"],
55
"targetTypes": ["page", "worker"],
6-
"version": 2,
6+
"version": 3,
77
"types": [
88
{
99
"id": "Type",
@@ -12,7 +12,8 @@
1212
"canvas-2d", "offscreen-canvas-2d",
1313
"canvas-bitmaprenderer", "offscreen-canvas-bitmaprenderer",
1414
"canvas-webgl", "offscreen-canvas-webgl",
15-
"canvas-webgl2", "offscreen-canvas-webgl2"
15+
"canvas-webgl2", "offscreen-canvas-webgl2",
16+
"canvas-webgpu"
1617
],
1718
"description": "The type of the recording."
1819
},
@@ -37,7 +38,7 @@
3738
"type": "object",
3839
"description": "Container object for a single frame of the recording.",
3940
"properties": [
40-
{ "name": "actions", "type": "array", "items": { "type": "any" }, "description": "Information about an action made to the recorded object. Follows the structure [name, parameters, swizzleTypes, stackTrace, snapshot], where name is a string, parameters is an array, swizzleTypes is an array, stackTrace is a Console.StackTrace, and snapshot is a data URL image of the current contents after this action."},
41+
{ "name": "actions", "type": "array", "items": { "type": "any" }, "description": "Information about an action made to the recorded object. Follows the structure [name, parameters, swizzleTypes, stackTrace, receiver, snapshot], where name is a string, parameters is an array, swizzleTypes is an array, stackTrace is a Console.StackTrace, receiver follows the structure [identifier, swizzleType] for the object that received the action, and snapshot is a data URL image of the current contents after this action."},
4142
{ "name": "duration", "type": "number", "optional": true, "description": "Total execution time of all actions recorded in this frame in milliseconds. " },
4243
{ "name": "incomplete", "type": "boolean", "optional": true, "description": "Flag indicating if the recording was stopped before this frame ended." }
4344
]

‎Source/JavaScriptCore/inspector/scripts/codegen/generator.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def ucfirst(str):
5656
'offscreen-canvas-webgl': 'OffscreenCanvasWebGL',
5757
'canvas-webgl2': 'CanvasWebGL2',
5858
'offscreen-canvas-webgl2': 'OffscreenCanvasWebGL2',
59+
'canvas-webgpu': 'CanvasWebGPU',
5960

6061
# Canvas.ContextType
6162
'bitmaprenderer': 'BitmapRenderer',

‎Source/WebCore/Modules/WebGPU/GPUBindGroup.cpp‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,22 @@
2727
#include "GPUBindGroup.h"
2828

2929
#include "GPUBindGroupLayout.h"
30+
#include "GPUDevice.h"
3031
#include "GPUExternalTexture.h"
3132

3233
namespace WebCore {
3334

35+
bool GPUBindGroup::hasActiveInspectorCanvasCallTracer() const
36+
{
37+
RefPtr device = m_device;
38+
return device && device->hasActiveInspectorCanvasCallTracer();
39+
}
40+
41+
GPUDevice* GPUBindGroup::device() const
42+
{
43+
return m_device;
44+
}
45+
3446
String GPUBindGroup::label() const
3547
{
3648
return m_backing->label();
@@ -46,9 +58,10 @@ bool GPUBindGroup::updateExternalTextures(GPUExternalTexture& externalTexture)
4658
return m_backing->updateExternalTextures(externalTexture.backing());
4759
}
4860

49-
GPUBindGroup::GPUBindGroup(Ref<WebGPU::BindGroup>&& backing, Ref<GPUBindGroupLayout>&& layout)
61+
GPUBindGroup::GPUBindGroup(Ref<WebGPU::BindGroup>&& backing, Ref<GPUBindGroupLayout>&& layout, GPUDevice& device)
5062
: m_backing(WTF::move(backing))
5163
, m_autogeneratedPipelineIdentifier(layout->autogeneratedPipelineIdentifier())
64+
, m_device(device)
5265
{
5366
}
5467

‎Source/WebCore/Modules/WebGPU/GPUBindGroup.h‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,24 @@
2525

2626
#pragma once
2727

28+
#include "EventTarget.h"
2829
#include "WebGPUBindGroup.h"
2930
#include <wtf/Ref.h>
30-
#include <wtf/RefCounted.h>
31+
#include <wtf/RefCountedAndCanMakeWeakPtr.h>
32+
#include <wtf/WeakPtr.h>
3133
#include <wtf/text/WTFString.h>
3234

3335
namespace WebCore {
3436

3537
class GPUBindGroupLayout;
38+
class GPUDevice;
3639
class GPUExternalTexture;
3740

38-
class GPUBindGroup : public RefCounted<GPUBindGroup> {
41+
class GPUBindGroup : public RefCountedAndCanMakeWeakPtr<GPUBindGroup> {
3942
public:
40-
static Ref<GPUBindGroup> create(Ref<WebGPU::BindGroup>&& backing, Ref<GPUBindGroupLayout>&& layout)
43+
static Ref<GPUBindGroup> create(Ref<WebGPU::BindGroup>&& backing, Ref<GPUBindGroupLayout>&& layout, GPUDevice& device)
4144
{
42-
return adoptRef(*new GPUBindGroup(WTF::move(backing), WTF::move(layout)));
45+
return adoptRef(*new GPUBindGroup(WTF::move(backing), WTF::move(layout), device));
4346
}
4447

4548
String NODELETE label() const;
@@ -50,11 +53,16 @@ class GPUBindGroup : public RefCounted<GPUBindGroup> {
5053
bool updateExternalTextures(GPUExternalTexture&);
5154
uint64_t autogeneratedPipelineIdentifier() const { return m_autogeneratedPipelineIdentifier; }
5255

56+
GPUDevice* device() const;
57+
58+
bool hasActiveInspectorCanvasCallTracer() const;
59+
5360
private:
54-
GPUBindGroup(Ref<WebGPU::BindGroup>&&, Ref<GPUBindGroupLayout>&&);
61+
GPUBindGroup(Ref<WebGPU::BindGroup>&&, Ref<GPUBindGroupLayout>&&, GPUDevice&);
5562

5663
const Ref<WebGPU::BindGroup> m_backing;
5764
const uint64_t m_autogeneratedPipelineIdentifier;
65+
WeakPtr<GPUDevice, WeakPtrImplWithEventTargetData> m_device;
5866
};
5967

6068
}

0 commit comments

Comments
 (0)