Skip to content

Commit 352f8ee

Browse files
authored
[Impeller] Enable ETC2/ASTC LDR/BC texture compression features at Vulkan device creation (flutter#189303)
## Description Enable `textureCompressionETC2`, `textureCompressionASTC_LDR`, and `textureCompressionBC` core Vulkan 1.0 features at device creation in `CapabilitiesVK::GetEnabledDeviceFeatures`. These three features were read back in `SetPhysicalDevice` (~line 670) from `enabled_features`, but never requested in `GetEnabledDeviceFeatures` — so the capability query always returned `false` on every Android Vulkan device, regardless of hardware support. This was a three-line omission in flutter#187077, which wired the read-back on all three backends (Vulkan/GLES/Metal) but only enabled the features on GLES and Metal. ASTC HDR was already correctly enabled via `VK_EXT_texture_compression_astc_hdr`. The fix mirrors the existing `samplerAnisotropy` pattern in the same "Base features" block. ## Related Issue Fixes flutter#189107 ## Tests This change enables features that are already supported by the hardware — it simply requests them at device creation so the existing read-back reflects real capability. No new tests are needed; existing `capabilities_vk_unittests` cover the feature chain plumbing. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added no tests because this is a trivial feature-enable with no new logic. [Contributor Guide]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-Hygiene.md [Tree Hygiene]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-Hygiene.md [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
1 parent 82e2bc2 commit 352f8ee

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

‎engine/src/flutter/impeller/renderer/backend/vulkan/capabilities_vk.cc‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,15 @@ CapabilitiesVK::GetEnabledDeviceFeatures(
456456
// `max_anisotropy` greater than 1 may only be created when this feature
457457
// is enabled.
458458
required.samplerAnisotropy = supported.samplerAnisotropy;
459+
460+
// Enable block-compressed texture format support when available.
461+
// These core Vulkan 1.0 features must be explicitly requested at device
462+
// creation; otherwise the capability read-back in SetPhysicalDevice
463+
// (which reads from enabled_features) will always report false.
464+
// See: https://github.com/flutter/flutter/issues/189107
465+
required.textureCompressionETC2 = supported.textureCompressionETC2;
466+
required.textureCompressionASTC_LDR = supported.textureCompressionASTC_LDR;
467+
required.textureCompressionBC = supported.textureCompressionBC;
459468
}
460469
// VK_KHR_sampler_ycbcr_conversion features.
461470
if (IsExtensionInList(

‎engine/src/flutter/impeller/renderer/backend/vulkan/context_vk_unittests.cc‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,24 @@ TEST(CapabilitiesVKTest, ContextInitializesWithNoStencilFormat) {
208208
PixelFormat::kD32FloatS8UInt);
209209
}
210210

211+
// Regression test for https://github.com/flutter/flutter/issues/189107.
212+
// The core Vulkan 1.0 block-compression features (ETC2, ASTC LDR, BC) must be
213+
// explicitly requested in GetEnabledDeviceFeatures so the read-back in
214+
// SetPhysicalDevice reports real support. The mock device advertises all three
215+
// as supported, so a device that enables them correctly must report them here.
216+
TEST(CapabilitiesVKTest, ReportsBlockCompressedTextureSupport) {
217+
const std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
218+
ASSERT_NE(context, nullptr);
219+
const CapabilitiesVK* capabilities_vk =
220+
reinterpret_cast<const CapabilitiesVK*>(context->GetCapabilities().get());
221+
EXPECT_TRUE(capabilities_vk->SupportsTextureCompression(
222+
CompressedTextureFamily::kETC2));
223+
EXPECT_TRUE(capabilities_vk->SupportsTextureCompression(
224+
CompressedTextureFamily::kASTC));
225+
EXPECT_TRUE(capabilities_vk->SupportsTextureCompression(
226+
CompressedTextureFamily::kBC));
227+
}
228+
211229
// Impeller's 2D renderer relies on hardware support for a combined
212230
// depth-stencil format (widely supported). So fail initialization if a suitable
213231
// one couldn't be found. That way we have an opportunity to fallback to

‎engine/src/flutter/impeller/renderer/backend/vulkan/test/mock_vulkan.cc‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,15 @@ void vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice,
323323

324324
void vkGetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice,
325325
VkPhysicalDeviceFeatures2* pFeatures) {
326+
// Advertise the core block-compressed texture features so tests can exercise
327+
// the GetEnabledDeviceFeatures -> SetPhysicalDevice plumbing that gates
328+
// CapabilitiesVK::SupportsTextureCompression. Without this the mock reports
329+
// these core Vulkan 1.0 features as VK_FALSE and the capability is always
330+
// false regardless of the enable path.
331+
pFeatures->features.textureCompressionETC2 = VK_TRUE;
332+
pFeatures->features.textureCompressionASTC_LDR = VK_TRUE;
333+
pFeatures->features.textureCompressionBC = VK_TRUE;
334+
326335
// Advertise the features the mock supports by walking the pNext chain.
327336
auto* next = reinterpret_cast<VkBaseOutStructure*>(pFeatures->pNext);
328337
while (next != nullptr) {

0 commit comments

Comments
 (0)