Skip to content

Commit

Permalink
Texture: prevent SIGILL in sampler validator. (#8468)
Browse files Browse the repository at this point in the history
Co-authored-by: Romain Guy <romainguy@curious-creature.com>
  • Loading branch information
KostyaAtG and romainguy authored Mar 7, 2025
1 parent 5091b31 commit 2f4e48b
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions filament/src/details/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";

Expand Down

0 comments on commit 2f4e48b

Please sign in to comment.