Skip to content

Commit 2f4e48b

Browse files
KostyaAtGromainguy
andauthored
Texture: prevent SIGILL in sampler validator. (google#8468)
Co-authored-by: Romain Guy <[email protected]>
1 parent 5091b31 commit 2f4e48b

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

filament/src/details/Texture.cpp

+20-18
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,26 @@ Texture* Texture::Builder::build(Engine& engine) {
164164
(isProtectedTexturesSupported && useProtectedMemory) || !useProtectedMemory)
165165
<< "Texture is PROTECTED but protected textures are not supported";
166166

167+
const auto validateSamplerType = [&engine = downcast(engine)](SamplerType const sampler) -> bool {
168+
switch (sampler) {
169+
case SamplerType::SAMPLER_2D:
170+
case SamplerType::SAMPLER_CUBEMAP:
171+
case SamplerType::SAMPLER_EXTERNAL:
172+
return true;
173+
case SamplerType::SAMPLER_3D:
174+
case SamplerType::SAMPLER_2D_ARRAY:
175+
return engine.hasFeatureLevel(FeatureLevel::FEATURE_LEVEL_1);
176+
case SamplerType::SAMPLER_CUBEMAP_ARRAY:
177+
return engine.hasFeatureLevel(FeatureLevel::FEATURE_LEVEL_2);
178+
}
179+
return false;
180+
};
181+
182+
// Validate sampler before any further interaction with it.
183+
FILAMENT_CHECK_PRECONDITION(validateSamplerType(mImpl->mTarget))
184+
<< "SamplerType " << uint8_t(mImpl->mTarget) << " not support at feature level "
185+
<< uint8_t(engine.getActiveFeatureLevel());
186+
167187
// SAMPLER_EXTERNAL implies imported.
168188
if (mImpl->mTarget == SamplerType::SAMPLER_EXTERNAL) {
169189
mImpl->mExternal = true;
@@ -216,24 +236,6 @@ Texture* Texture::Builder::build(Engine& engine) {
216236
FILAMENT_CHECK_PRECONDITION(!swizzled) << "WebGL does not support texture swizzling.";
217237
#endif
218238

219-
auto validateSamplerType = [&engine = downcast(engine)](SamplerType const sampler) -> bool {
220-
switch (sampler) {
221-
case SamplerType::SAMPLER_2D:
222-
case SamplerType::SAMPLER_CUBEMAP:
223-
case SamplerType::SAMPLER_EXTERNAL:
224-
return true;
225-
case SamplerType::SAMPLER_3D:
226-
case SamplerType::SAMPLER_2D_ARRAY:
227-
return engine.hasFeatureLevel(FeatureLevel::FEATURE_LEVEL_1);
228-
case SamplerType::SAMPLER_CUBEMAP_ARRAY:
229-
return engine.hasFeatureLevel(FeatureLevel::FEATURE_LEVEL_2);
230-
}
231-
};
232-
233-
FILAMENT_CHECK_PRECONDITION(validateSamplerType(mImpl->mTarget))
234-
<< "SamplerType " << uint8_t(mImpl->mTarget) << " not support at feature level "
235-
<< uint8_t(engine.getActiveFeatureLevel());
236-
237239
FILAMENT_CHECK_PRECONDITION((swizzled && sampleable) || !swizzled)
238240
<< "Swizzled texture must be SAMPLEABLE";
239241

0 commit comments

Comments
 (0)