From c0d63e826da7aeadaaa064aaa5b3ecef911d9e18 Mon Sep 17 00:00:00 2001 From: Evan Mezeske Date: Wed, 11 Mar 2026 10:39:35 -0700 Subject: [PATCH] Metal: fix crash from exceeding max texture dimensions for Bloom buffer (#9784) I recently added a new fuzz test for my Filament-based app, which creates a window and then rapidly issues changes such as toggling View features, changing the window size, and other operations that the users of my app can do. It quickly found a crash when Bloom is enabled and the window dimensions get resized to weird aspect ratios on a large monitor. Eventually I narrowed it down to the Bloom buffer's width exceeding the Metal max texture dimension (on my machine, 16K). Applying this patch fixes the crash. --- filament/src/PostProcessManager.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/filament/src/PostProcessManager.cpp b/filament/src/PostProcessManager.cpp index b792906626..1165c71928 100644 --- a/filament/src/PostProcessManager.cpp +++ b/filament/src/PostProcessManager.cpp @@ -2248,6 +2248,18 @@ PostProcessManager::BloomPassOutput PostProcessManager::bloom(FrameGraph& fg, float bloomHeight = float(inoutBloomOptions.resolution); float bloomWidth = bloomHeight * aspect; + // With extreme aspect ratios the major axis can exceed the GPU's maximum + // texture dimension. Scale both axes down proportionally so that the larger + // one stays within the hardware limit. + const float maxDimension = float( + FTexture::getMaxTextureSize(mEngine, SamplerType::SAMPLER_2D)); + const float bloomMajor = std::max(bloomWidth, bloomHeight); + if (bloomMajor > maxDimension) { + const float clampScale = maxDimension / bloomMajor; + bloomWidth *= clampScale; + bloomHeight *= clampScale; + } + // we might need to adjust the max # of levels const uint32_t major = uint32_t(std::max(bloomWidth, bloomHeight)); const uint8_t maxLevels = FTexture::maxLevelCount(major);