Skip to content

Commit

Permalink
PresentationContextIOSurface::configure should check for invalid heig…
Browse files Browse the repository at this point in the history
…ht before creating MTLTexture

https://bugs.webkit.org/show_bug.cgi?id=270608
rdar://124143113

Reviewed by Mike Wyrzykowski.

* LayoutTests/fast/webgpu/invalid-surface-height-expected.txt: Added.
* LayoutTests/fast/webgpu/invalid-surface-height.html: Added.
* Source/WebGPU/WebGPU/PresentationContextIOSurface.mm:
(WebGPU::PresentationContextIOSurface::configure):

Canonical link: https://commits.webkit.org/275772@main
  • Loading branch information
achristensen07 committed Mar 7, 2024
1 parent e644c80 commit 055511d
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This test passes if it does not crash.
89 changes: 89 additions & 0 deletions LayoutTests/fast/webgpu/invalid-surface-height.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<script>
if (window.testRunner) { testRunner.waitUntilDone(); testRunner.dumpAsText() }

onload = async () => {
try {
let adapter0 = await navigator.gpu.requestAdapter(
{
}
);
let device0 = await adapter0.requestDevice(
{
label: '\u5b22',
requiredFeatures: [
'depth-clip-control',
'depth32float-stencil8',
'texture-compression-etc2',
'texture-compression-astc',
'shader-f16',
'rg11b10ufloat-renderable',
'bgra8unorm-storage'
],
requiredLimits: {
maxColorAttachmentBytesPerSample: 48,
maxVertexAttributes: 17,
maxVertexBufferArrayStride: 18611,
maxStorageTexturesPerShaderStage: 41,
maxBindingsPerBindGroup: 7922,
maxTextureArrayLayers: 402,
maxTextureDimension1D: 12869,
maxTextureDimension2D: 8698,
maxVertexBuffers: 10,
minStorageBufferOffsetAlignment: 64,
minUniformBufferOffsetAlignment: 32,
},
}
);

let adapter1 = await navigator.gpu.requestAdapter(
{
}
);
let offscreenCanvas3 = new OffscreenCanvas(605, 2935663512);

let gpuCanvasContext1 = offscreenCanvas3.getContext('webgpu');
gpuCanvasContext1.configure(
{
device: device0,
format: 'rgba8unorm',
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.STORAGE_BINDING | GPUTextureUsage.COPY_DST,
viewFormats: [
'astc-5x5-unorm',
'rg8sint',
'r16sint',
'bgra8unorm-srgb',
'etc2-rgb8a1unorm-srgb',
'rgba32float',
'astc-4x4-unorm',
'astc-8x6-unorm',
'astc-12x12-unorm'
],
colorSpace: 'srgb',
alphaMode: 'premultiplied',
}
);
let device1 = await adapter1.requestDevice(
{
label: '\u0d54',
requiredLimits: {
maxColorAttachmentBytesPerSample: 61,
maxVertexAttributes: 18,
maxVertexBufferArrayStride: 51506,
maxStorageTexturesPerShaderStage: 26,
maxBindingsPerBindGroup: 9286,
maxTextureArrayLayers: 1815,
maxTextureDimension1D: 9422,
maxTextureDimension2D: 15639,
maxVertexBuffers: 12,
minStorageBufferOffsetAlignment: 32,
minUniformBufferOffsetAlignment: 64,
},
}
);
} catch (e) {

}
if (window.testRunner) { testRunner.notifyDone() }
};
</script>
This test passes if it does not crash.
4 changes: 4 additions & 0 deletions Source/WebGPU/WebGPU/PresentationContextIOSurface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@
MTLTextureDescriptor *textureDescriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:Texture::pixelFormat(effectiveFormat) width:width height:height mipmapped:NO];
textureDescriptor.usage = Texture::usage(descriptor.usage, effectiveFormat);
bool needsLuminanceClampFunction = false;
for (IOSurface *iosurface in m_ioSurfaces) {
if (iosurface.height != static_cast<NSInteger>(height) || iosurface.width != static_cast<NSInteger>(width))
return device.generateAValidationError("Invalid surface size"_s);
}
for (IOSurface *iosurface in m_ioSurfaces) {
RefPtr<Texture> parentLuminanceClampTexture;
if (textureDescriptor.pixelFormat == MTLPixelFormatRGBA16Float) {
Expand Down

0 comments on commit 055511d

Please sign in to comment.