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.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user