Skip to content

Commit eed71da

Browse files
committed
reduce gpu memory
1 parent 4415d9e commit eed71da

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

docs/src/pages/changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ language: 'en'
1313
- Kitty image protocol.
1414
- Breaking: `Decorations` as `Transparent` is default on MacOS (instead of `Enabled`).
1515

16+
## 0.2.35
17+
18+
- GPU memory usage drop >50%.
19+
- Sync input render logic.
20+
1621
## 0.2.34
1722

1823
- Fix issue for finding fonts introduced with the v0.2.33 new font loader.

sugarloaf/src/components/layer/atlas.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ impl Atlas {
2727
context: &crate::context::Context,
2828
) -> Self {
2929
let max_size = context.max_texture_dimension_2d();
30-
let size = std::cmp::min(4096, max_size);
30+
let size = std::cmp::min(2048, max_size);
3131

32-
tracing::info!("Creating layer atlas with size: {}x{}", size, size);
32+
tracing::info!("Creating layer atlas with size: {}x{} (reduced from 4096 for memory efficiency)", size, size);
3333

3434
let layers = match backend {
3535
wgpu::Backend::Gl => vec![Layer::Empty, Layer::Empty],
@@ -42,8 +42,7 @@ impl Atlas {
4242
depth_or_array_layers: layers.len() as u32,
4343
};
4444

45-
let texture_format = context.get_optimal_texture_format(4);
46-
45+
let texture_format = wgpu::TextureFormat::Rgba8Unorm;
4746
let texture = device.create_texture(&wgpu::TextureDescriptor {
4847
label: Some("image texture atlas"),
4948
size: extent,
@@ -107,7 +106,7 @@ impl Atlas {
107106
&mut self,
108107
device: &wgpu::Device,
109108
backend: wgpu::Backend,
110-
context: &crate::context::Context,
109+
_context: &crate::context::Context,
111110
) {
112111
self.layers = match backend {
113112
wgpu::Backend::Gl => vec![Layer::Empty, Layer::Empty],
@@ -120,8 +119,7 @@ impl Atlas {
120119
depth_or_array_layers: self.layers.len() as u32,
121120
};
122121

123-
let texture_format = context.get_optimal_texture_format(4);
124-
122+
let texture_format = wgpu::TextureFormat::Rgba8Unorm;
125123
self.texture = device.create_texture(&wgpu::TextureDescriptor {
126124
label: Some("image texture atlas"),
127125
size: extent,
@@ -150,7 +148,7 @@ impl Atlas {
150148
width: u32,
151149
height: u32,
152150
data: &[u8],
153-
context: &crate::context::Context,
151+
_context: &crate::context::Context,
154152
) -> Option<Entry> {
155153
let entry = {
156154
let current_size = self.layers.len();
@@ -164,9 +162,7 @@ impl Atlas {
164162

165163
tracing::info!("Allocated atlas entry: {:?}", entry);
166164

167-
let converted_data = context.convert_rgba8_to_optimal_format(data);
168165
let bytes_per_pixel = self.get_bytes_per_pixel();
169-
170166
let align = wgpu::COPY_BYTES_PER_ROW_ALIGNMENT;
171167
let row_bytes = bytes_per_pixel * width;
172168
let padding = (align - row_bytes % align) % align;
@@ -180,7 +176,7 @@ impl Atlas {
180176
let src_row_bytes = (bytes_per_pixel * width) as usize;
181177

182178
padded_data[offset..offset + src_row_bytes].copy_from_slice(
183-
&converted_data[row * src_row_bytes..(row + 1) * src_row_bytes],
179+
&data[row * src_row_bytes..(row + 1) * src_row_bytes],
184180
)
185181
}
186182

sugarloaf/src/components/rich_text/image_cache/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl ImageCache {
7575
pub fn new(context: &Context) -> Self {
7676
let device = &context.device;
7777
let max_size = context.max_texture_dimension_2d();
78-
let max_texture_size = std::cmp::min(4096, max_size) as u16;
78+
let max_texture_size = std::cmp::min(2048, max_size) as u16;
7979

8080
tracing::info!(
8181
"Creating rich_text image cache with size: {}x{}",

0 commit comments

Comments
 (0)