Skip to content

Commit 5c7a132

Browse files
committed
addressing more comments.
1 parent b78f8b2 commit 5c7a132

File tree

1 file changed

+1
-76
lines changed

1 file changed

+1
-76
lines changed

en/Building_a_Simple_Engine/Mobile_Development/03_performance_optimizations.adoc

Lines changed: 1 addition & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -64,70 +64,6 @@ vk::Format find_supported_format(vk::PhysicalDevice physical_device,
6464
6565
throw std::runtime_error("Failed to find supported format");
6666
}
67-
68-
vk::Format find_best_compressed_format(vk::PhysicalDevice physical_device) {
69-
// Choose based on reported feature support; benefits apply on mobile and desktop.
70-
vk::PhysicalDeviceFeatures features = physical_device.getFeatures();
71-
72-
// Candidate lists
73-
std::vector<vk::Format> astc_formats = {
74-
vk::Format::eAstc8x8SrgbBlock,
75-
vk::Format::eAstc6x6SrgbBlock,
76-
vk::Format::eAstc4x4SrgbBlock
77-
};
78-
std::vector<vk::Format> bc_formats = {
79-
vk::Format::eBc7SrgbBlock,
80-
vk::Format::eBc3SrgbBlock,
81-
vk::Format::eBc1SrgbBlock
82-
};
83-
std::vector<vk::Format> etc2_formats = {
84-
vk::Format::eEtc2R8G8B8A8SrgbBlock,
85-
vk::Format::eEtc2R8G8B8SrgbBlock
86-
};
87-
88-
// Build a simple preference order:
89-
// - If only BC is supported, try BC first (typical on desktop-only stacks).
90-
// - If ASTC is supported, try ASTC (common on mobile; also available on some desktop drivers).
91-
// - Then try the remaining supported families.
92-
std::vector<std::vector<vk::Format>> preference;
93-
94-
if (features.textureCompressionBC && !features.textureCompressionASTC_LDR) {
95-
preference.push_back(bc_formats);
96-
}
97-
if (features.textureCompressionASTC_LDR) {
98-
preference.push_back(astc_formats);
99-
}
100-
if (features.textureCompressionBC && features.textureCompressionASTC_LDR) {
101-
// Both supported; add BC as alternative if not already first
102-
if (preference.empty() || preference[0] != bc_formats) {
103-
preference.push_back(bc_formats);
104-
}
105-
}
106-
if (features.textureCompressionETC2) {
107-
preference.push_back(etc2_formats);
108-
}
109-
110-
// As a fallback, try all families regardless of feature bits (some drivers may expose formats via properties).
111-
if (preference.empty()) {
112-
preference = { astc_formats, etc2_formats, bc_formats };
113-
}
114-
115-
for (const auto& family : preference) {
116-
try {
117-
return find_supported_format(
118-
physical_device,
119-
family,
120-
vk::ImageTiling::eOptimal,
121-
vk::FormatFeatureFlagBits::eSampledImage
122-
);
123-
} catch (const std::runtime_error&) {
124-
// Try next family
125-
}
126-
}
127-
128-
// Fall back to uncompressed
129-
return vk::Format::eR8G8B8A8Srgb;
130-
}
13167
----
13268

13369
=== Memory Optimizations
@@ -284,21 +220,10 @@ vk::Format get_optimal_texture_format(vk::PhysicalDevice physical_device) {
284220
vk::PhysicalDeviceFeatures features = physical_device.getFeatures();
285221
286222
// Check for ASTC support (widely supported on modern mobile GPUs)
223+
// Most games are written with knowledge of what the assets were compressed with so it's standard practice to only ensure the required format is supported.
287224
if (features.textureCompressionASTC_LDR) {
288225
return vk::Format::eAstc8x8SrgbBlock;
289226
}
290-
291-
// Check for vendor-specific optimizations
292-
// Huawei devices (Mali GPUs)
293-
if (props.vendorID == 0x19E5) {
294-
// Check for ETC2 support as fallback
295-
if (supports_texture_format(physical_device, vk::Format::eEtc2R8G8B8A8SrgbBlock)) {
296-
return vk::Format::eEtc2R8G8B8A8SrgbBlock;
297-
}
298-
}
299-
300-
// Otherwise, fall back to the general format selection
301-
return find_best_compressed_format(physical_device);
302227
}
303228
----
304229

0 commit comments

Comments
 (0)