Bound GPU uploads and complete Greek and performance integration

This commit is contained in:
Hakan Seven committed 2026-09-04 20:26:29 +03:00
1 parent 89624f64fc
commit 9d991d7feb
14 files changed
+678 -380

No files matched your search

+32 -35
View File
@@ -1,17 +1,4 @@
//! GPU buffers for SDF text quads (Phase 2b of the text-shader initiative).
//!
//! Unlike images (one texture per entity), all glyphs share ONE atlas texture
//! and every glyph is a quad in a single instance-less vertex buffer, so the
//! whole layout draws in one call. Group 1 is just `{ atlas texture, sampler }`;
//! per-glyph colour and draw-order live in the vertices.
//!
//! Vertex positions use the same double-single relative-to-eye encoding as
//! wires/hatches/images so text stays precise at large drawing coordinates.
// Not yet driven by the render loop — that hook-up (Pipeline fields, per-frame
// upload, a render pass, and suppressing the old stroke text) is the final
// integration step, done with the app running to verify pixels.
#![allow(dead_code)]
//! Chunked SDF text quads sharing one glyph atlas.
use iced::wgpu;
@@ -91,6 +78,11 @@ impl BlockTextInstance {
}
}
pub struct TextGpu {
pub vertex_buffer: wgpu::Buffer,
pub vertex_count: u32,
}
pub struct BlockTextGpu {
pub vertex_buffer: wgpu::Buffer,
pub instance_buffer: wgpu::Buffer,
@@ -517,9 +509,7 @@ pub fn upload_block_vertex_refs(
} else {
source.text_verts.as_slice()
};
let Some(vertex_buffer) = upload_vertices(device, queue, vertices) else {
continue;
};
let vertex_chunks = upload_vertices(device, queue, vertices);
let instances: Vec<BlockTextInstance> = group
.iter()
.filter_map(|wire| {
@@ -552,33 +542,40 @@ pub fn upload_block_vertex_refs(
chunk,
wgpu::BufferUsages::VERTEX,
);
out.push(BlockTextGpu {
vertex_buffer: vertex_buffer.clone(),
instance_buffer,
vertex_count: vertices.len() as u32,
instance_count: chunk.len() as u32,
});
for text in &vertex_chunks {
out.push(BlockTextGpu {
vertex_buffer: text.vertex_buffer.clone(),
instance_buffer: instance_buffer.clone(),
vertex_count: text.vertex_count,
instance_count: chunk.len() as u32,
});
}
}
}
out
}
/// Upload a finished vertex list; `None` if empty.
/// Upload whole glyph quads within the per-buffer budget.
pub fn upload_vertices(
device: &wgpu::Device,
queue: &wgpu::Queue,
verts: &[TextVertex],
) -> Option<wgpu::Buffer> {
if verts.is_empty() {
return None;
}
Some(super::gpu_upload::upload_buffer(
device,
queue,
"text.vbuf",
verts,
wgpu::BufferUsages::VERTEX,
))
) -> Vec<TextGpu> {
verts
.chunks(super::gpu_budget::max_elements_grouped::<TextVertex>(
device, 6,
))
.map(|chunk| TextGpu {
vertex_buffer: super::gpu_upload::upload_buffer(
device,
queue,
"text.vbuf",
chunk,
wgpu::BufferUsages::VERTEX,
),
vertex_count: chunk.len() as u32,
})
.collect()
}
// ── Tests ─────────────────────────────────────────────────────────────────