Skip to content

Commit 9705b60

Browse files
committed
addressing more comments.
1 parent f713e9c commit 9705b60

File tree

1 file changed

+0
-65
lines changed

1 file changed

+0
-65
lines changed

en/Building_a_Simple_Engine/Mobile_Development/03_performance_optimizations.adoc

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -8,78 +8,13 @@ Mobile devices have significantly different hardware constraints compared to des
88

99
=== Texture Optimizations
1010

11-
To keep the workflow concrete and digestible, think of texture optimization in three steps:
12-
13-
1) Step 1: Ensure power‑of‑two (POT) dimensions (resize if needed)
14-
2) Step 2: Pick a hardware‑compressed format supported by the device (ASTC → ETC2 → BC → fallback)
15-
3) Step 3: Upload/update the Vulkan image and clean up staging resources
16-
1711
[NOTE]
1812
====
1913
We focus on mobile‑specific decisions here. For general Vulkan image creation, staging uploads, and descriptor setup, refer back to earlier chapters in the engine series—link:../Engine_Architecture/04_resource_management.adoc[Resource Management], link:../Engine_Architecture/05_rendering_pipeline.adoc[Rendering Pipeline]—or the Vulkan Guide (https://docs.vulkan.org/guide/latest/).
2014
====
2115

2216
Textures are often the largest consumers of memory in a graphics application. Optimizing them is crucial for mobile performance.
2317

24-
==== Power-of-Two Textures
25-
26-
One of the most important optimizations for mobile is using power-of-two (POT) texture dimensions (e.g., 256x256, 512x1024, etc.). Here's why:
27-
28-
1. *Hardware Acceleration*: Most mobile GPUs are optimized for POT textures and can process them more efficiently.
29-
30-
2. *Mipmapping*: POT textures are required for proper mipmapping, which is essential for performance and visual quality.
31-
32-
3. *Memory Alignment*: POT textures align better with memory pages, improving memory access patterns.
33-
34-
To ensure your textures are POT, you can implement a texture loading system that automatically resizes non-POT textures:
35-
36-
[source,cpp]
37-
----
38-
vk::Extent2D make_power_of_two(uint32_t width, uint32_t height) {
39-
// Find the next power of two for each dimension
40-
uint32_t pot_width = 1;
41-
while (pot_width < width) pot_width *= 2;
42-
43-
uint32_t pot_height = 1;
44-
while (pot_height < height) pot_height *= 2;
45-
46-
return vk::Extent2D(pot_width, pot_height);
47-
}
48-
49-
void load_texture(const std::string& path) {
50-
// Load the image data
51-
int width, height, channels;
52-
stbi_uc* pixels = stbi_load(path.c_str(), &width, &height, &channels, STBI_rgb_alpha);
53-
54-
if (!pixels) {
55-
throw std::runtime_error("Failed to load texture image: " + path);
56-
}
57-
58-
// Check if the dimensions are power of two
59-
bool is_pot = (width & (width - 1)) == 0 && (height & (height - 1)) == 0;
60-
61-
if (!is_pot) {
62-
// Resize to power of two
63-
vk::Extent2D pot_size = make_power_of_two(width, height);
64-
65-
stbi_uc* resized_pixels = new stbi_uc[pot_size.width * pot_size.height * 4];
66-
stbir_resize_uint8(pixels, width, height, 0,
67-
resized_pixels, pot_size.width, pot_size.height, 0, 4);
68-
69-
stbi_image_free(pixels);
70-
pixels = resized_pixels;
71-
width = pot_size.width;
72-
height = pot_size.height;
73-
}
74-
75-
// Create Vulkan image and upload pixels
76-
// ...
77-
78-
// Free the pixel data
79-
stbi_image_free(pixels);
80-
}
81-
----
82-
8318
==== Efficient Texture Formats
8419

8520
Choosing the right texture format is crucial for mobile performance:

0 commit comments

Comments
 (0)