profile font rendering with tracy

This commit is contained in:
Vicente Ferrari Smith 2026-01-27 23:58:02 +01:00
parent 12199ac7b6
commit 20ba7b51a1
3 changed files with 22 additions and 14 deletions

View File

@ -82,7 +82,7 @@ pub fn build(b: *std.Build) void {
}); });
const ztracy = b.dependency("ztracy", .{ const ztracy = b.dependency("ztracy", .{
.enable_ztracy = false, .enable_ztracy = true,
.enable_fibers = false, .enable_fibers = false,
.on_demand = false, .on_demand = false,
}); });

View File

@ -43,7 +43,7 @@ pub const Font = struct {
texture : rl.Texture2D, texture : rl.Texture2D,
kb_file_data : []u8, kb_file_data : []u8,
pub fn init(filename : []const u8, size : i32, allocator: std.mem.Allocator) !Font { pub fn init(filename : [:0]const u8, size : i32, allocator: std.mem.Allocator) !Font {
const file_data = try std.fs.cwd().readFileAlloc( const file_data = try std.fs.cwd().readFileAlloc(
allocator, allocator,
@ -189,7 +189,7 @@ pub const Font = struct {
pub fn deinit(self: *Font, allocator : std.mem.Allocator) void { pub fn deinit(self: *Font, allocator : std.mem.Allocator) void {
self.glyphs.deinit(); self.glyphs.deinit();
self.face.deinit(); self.face.deinit();
kb.kbts_FreeFont(&self.kb); kb.kbts_FreeFont(&self.kbts_font);
self.texture.unload(); self.texture.unload();
allocator.free(self.kb_file_data); allocator.free(self.kb_file_data);
} }
@ -237,7 +237,7 @@ pub const Font = struct {
const Context = kb.kbts_CreateShapeContext(null, null); const Context = kb.kbts_CreateShapeContext(null, null);
defer kb.kbts_DestroyShapeContext(Context); defer kb.kbts_DestroyShapeContext(Context);
const kb_font = kb.kbts_ShapePushFont(Context, &self.kb); const kb_font = kb.kbts_ShapePushFont(Context, &self.kbts_font);
if (kb_font == null) { if (kb_font == null) {
std.log.info("Could not open font!", .{}); std.log.info("Could not open font!", .{});
return; return;
@ -253,7 +253,7 @@ pub const Font = struct {
var cursor_y : f32 = 0; var cursor_y : f32 = 0;
var Run = kb.kbts_run{}; var Run = kb.kbts_run{};
while (kb.kbts_ShapeRun(Context, &Run) != 0) { while (my_kbts_ShapeRun(Context, &Run) != 0) {
const zone3 = ztracy.ZoneNC(@src(), "shape run", 0x00_ff_00_00); const zone3 = ztracy.ZoneNC(@src(), "shape run", 0x00_ff_00_00);
defer zone3.End(); defer zone3.End();
if ((Run.Flags & kb.KBTS_BREAK_FLAG_LINE_HARD) != 0) { if ((Run.Flags & kb.KBTS_BREAK_FLAG_LINE_HARD) != 0) {
@ -374,3 +374,9 @@ pub const Font = struct {
return .{ size, max_descent, 0}; return .{ size, max_descent, 0};
} }
}; };
fn my_kbts_ShapeRun(Context: ?*kb.kbts_shape_context, Run: [*c]kb.kbts_run) c_int {
const zone = ztracy.ZoneNC(@src(), "my_kbts_ShapeRun", 0x00_ff_00_00);
defer zone.End();
return kb.kbts_ShapeRun(Context, Run);
}

View File

@ -247,15 +247,15 @@ pub fn main() !void {
true true
); );
arabic[0].render_text( // arabic[0].render_text(
"الليل طويل وبارد في الخارج", // "الليل طويل وبارد في الخارج",
rl.Vector2{ .x = 0, .y = 100}, // rl.Vector2{ .x = 0, .y = 100},
true, // true,
.white, // .white,
.blank, // .blank,
false, // false,
true // true
); // );
// var y : f32 = 0; // var y : f32 = 0;
// var it = std.mem.splitScalar(u8, lorem, '\n'); // var it = std.mem.splitScalar(u8, lorem, '\n');
@ -483,7 +483,9 @@ pub fn main() !void {
rl.endDrawing(); rl.endDrawing();
const swap_zone = ztracy.ZoneNC(@src(), "swapScreenBuffer", 0x00_ff_00_00);
rl.swapScreenBuffer(); rl.swapScreenBuffer();
swap_zone.End();
frame += 1; frame += 1;