Skip to content

Commit

Permalink
Fix crash when Device::generateAnOutOfMemoryError is repeatedly inv…
Browse files Browse the repository at this point in the history
…oked

https://bugs.webkit.org/show_bug.cgi?id=270991
rdar://124475321

Reviewed by Mike Wyrzykowski.

`m_uncapturedErrorCallback` can only be called once, so it should always be cleared after calling it.

* LayoutTests/fast/webgpu/repeated-out-of-memory-error-expected.txt: Added.
* LayoutTests/fast/webgpu/repeated-out-of-memory-error.html: Added.
* Source/WebGPU/WebGPU/Device.mm:
(WebGPU::Device::generateAnOutOfMemoryError):
(WebGPU::Device::generateAnInternalError):

Canonical link: https://commits.webkit.org/276135@main
  • Loading branch information
charliewolfe committed Mar 15, 2024
1 parent 86e114a commit 56e388b
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This test passes if it does not crash.
83 changes: 83 additions & 0 deletions LayoutTests/fast/webgpu/repeated-out-of-memory-error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
This test passes if it does not crash.
<script>
if (window.testRunner) {
testRunner.waitUntilDone();
testRunner.dumpAsText();
}

onload = async () => {
try {
let adapter0 = await navigator.gpu.requestAdapter(
{
powerPreference: 'high-performance',
}
);
let device0 = await adapter0.requestDevice(
{
label: '\u{1fc7e}',
requiredFeatures: [
'depth-clip-control',
'shader-f16',
'bgra8unorm-storage'
],
requiredLimits: {
maxColorAttachmentBytesPerSample: 60,
maxVertexAttributes: 30,
maxVertexBufferArrayStride: 11348,
maxStorageTexturesPerShaderStage: 42,
maxBindingsPerBindGroup: 7372,
maxTextureArrayLayers: 2011
},
}
);
let bindGroupLayout0 = device0.createBindGroupLayout(
{
entries: [
{
binding: 5869,
visibility: GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT,
texture: { viewDimension: '2d', sampleType: 'float', multisampled: false },
}
],
}
);
device0.addEventListener('uncapturederror', e => { e.label = device0.label; });
device0.createTexture(
{
label: '\u04ab',
size: {
width: 7798,
height: 7120,
depthOrArrayLayers: 377,
},
format: 'stencil8',
usage: GPUTextureUsage.COPY_SRC | GPUTextureUsage.COPY_DST,
}
);
let sampler5 = device0.createSampler(
{
addressModeU: 'repeat',
addressModeV: 'mirror-repeat',
addressModeW: 'mirror-repeat',
minFilter: 'nearest',
lodMinClamp: 45.683,
lodMaxClamp: 77.763,
compare: 'always',
}
);
let bindGroup0 = device0.createBindGroup(
{
layout: bindGroupLayout0,
entries: [
{
binding: 646,
resource: sampler5,
}
],
}
);
} catch (e) { }
if (window.testRunner)
testRunner.notifyDone();
};
</script>
8 changes: 6 additions & 2 deletions Source/WebGPU/WebGPU/Device.mm
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,10 @@ static void captureFrame(id<MTLDevice> captureObject)
return;
}

if (m_uncapturedErrorCallback)
if (m_uncapturedErrorCallback) {
m_uncapturedErrorCallback(WGPUErrorType_OutOfMemory, WTFMove(message));
m_uncapturedErrorCallback = nullptr;
}
}

void Device::generateAnInternalError(String&& message)
Expand All @@ -339,8 +341,10 @@ static void captureFrame(id<MTLDevice> captureObject)
return;
}

if (m_uncapturedErrorCallback)
if (m_uncapturedErrorCallback) {
m_uncapturedErrorCallback(WGPUErrorType_Internal, WTFMove(message));
m_uncapturedErrorCallback = nullptr;
}
}

uint32_t Device::maxBuffersPlusVertexBuffersForVertexStage() const
Expand Down

0 comments on commit 56e388b

Please sign in to comment.