From 2f4e48b6b938da3a52cb37599627abfbb2a8dcbc Mon Sep 17 00:00:00 2001 From: Konstantin Sakhin Date: Fri, 7 Mar 2025 14:11:04 -0600 Subject: [PATCH] Texture: prevent SIGILL in sampler validator. (#8468) Co-authored-by: Romain Guy --- filament/src/details/Texture.cpp | 38 +++++++++++++++++--------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/filament/src/details/Texture.cpp b/filament/src/details/Texture.cpp index d018f3800f..3749344d35 100644 --- a/filament/src/details/Texture.cpp +++ b/filament/src/details/Texture.cpp @@ -164,6 +164,26 @@ Texture* Texture::Builder::build(Engine& engine) { (isProtectedTexturesSupported && useProtectedMemory) || !useProtectedMemory) << "Texture is PROTECTED but protected textures are not supported"; + const auto validateSamplerType = [&engine = downcast(engine)](SamplerType const sampler) -> bool { + switch (sampler) { + case SamplerType::SAMPLER_2D: + case SamplerType::SAMPLER_CUBEMAP: + case SamplerType::SAMPLER_EXTERNAL: + return true; + case SamplerType::SAMPLER_3D: + case SamplerType::SAMPLER_2D_ARRAY: + return engine.hasFeatureLevel(FeatureLevel::FEATURE_LEVEL_1); + case SamplerType::SAMPLER_CUBEMAP_ARRAY: + return engine.hasFeatureLevel(FeatureLevel::FEATURE_LEVEL_2); + } + return false; + }; + + // Validate sampler before any further interaction with it. + FILAMENT_CHECK_PRECONDITION(validateSamplerType(mImpl->mTarget)) + << "SamplerType " << uint8_t(mImpl->mTarget) << " not support at feature level " + << uint8_t(engine.getActiveFeatureLevel()); + // SAMPLER_EXTERNAL implies imported. if (mImpl->mTarget == SamplerType::SAMPLER_EXTERNAL) { mImpl->mExternal = true; @@ -216,24 +236,6 @@ Texture* Texture::Builder::build(Engine& engine) { FILAMENT_CHECK_PRECONDITION(!swizzled) << "WebGL does not support texture swizzling."; #endif - auto validateSamplerType = [&engine = downcast(engine)](SamplerType const sampler) -> bool { - switch (sampler) { - case SamplerType::SAMPLER_2D: - case SamplerType::SAMPLER_CUBEMAP: - case SamplerType::SAMPLER_EXTERNAL: - return true; - case SamplerType::SAMPLER_3D: - case SamplerType::SAMPLER_2D_ARRAY: - return engine.hasFeatureLevel(FeatureLevel::FEATURE_LEVEL_1); - case SamplerType::SAMPLER_CUBEMAP_ARRAY: - return engine.hasFeatureLevel(FeatureLevel::FEATURE_LEVEL_2); - } - }; - - FILAMENT_CHECK_PRECONDITION(validateSamplerType(mImpl->mTarget)) - << "SamplerType " << uint8_t(mImpl->mTarget) << " not support at feature level " - << uint8_t(engine.getActiveFeatureLevel()); - FILAMENT_CHECK_PRECONDITION((swizzled && sampleable) || !swizzled) << "Swizzled texture must be SAMPLEABLE";