this repo has no description

changed render context

+7 -8
+2 -2
src/rayray.zig
··· 60 const finished_threads = try self.allocator.alloc(bool, num_threads); 61 62 for (0..num_threads) |row| { 63 - const ctx = renderer.Context{ .cam = &self.camera, .world = &self.world, .done = &threads[row].done }; 64 - const t = try std.Thread.spawn(.{}, renderer.renderThread, .{ ctx, row, row_height }); 65 threads[row].thread = t; 66 } 67
··· 60 const finished_threads = try self.allocator.alloc(bool, num_threads); 61 62 for (0..num_threads) |row| { 63 + const ctx = renderer.Context{ .cam = &self.camera, .world = &self.world }; 64 + const t = try std.Thread.spawn(.{}, renderer.renderThread, .{ ctx, &threads[row].done, row, row_height }); 65 threads[row].thread = t; 66 } 67
+5 -6
src/renderer.zig
··· 17 pub const Context = struct { 18 cam: *Camera, 19 world: *hittable.HittableList, 20 - done: *std.atomic.Value(bool), 21 }; 22 23 pub fn rayColor(r: *Ray, world: *hittable.HittableList) zm.Vec { ··· 30 return zm.f32x4s(1.0 - a) * zm.f32x4s(1.0) + zm.f32x4s(a) * zm.f32x4(0.5, 0.7, 1.0, 1.0); 31 } 32 33 - pub fn render(ctx: Context, height: IntervalUsize, width: IntervalUsize) void { 34 var height_iter = height.iter(); 35 height_iter.upper_boundry = .inclusive; 36 ··· 51 ctx.cam.setPixel(i, j, col) catch break; 52 } 53 } 54 - 55 - ctx.done.store(true, .Release); 56 } 57 58 - pub fn renderThread(ctx: Context, row: usize, row_height: usize) void { 59 spall.init_thread(); 60 defer spall.deinit_thread(); 61 ··· 67 const s = spall.trace(@src(), "Render Thread {}", .{row}); 68 defer s.end(); 69 70 - render(ctx, height, width); 71 } 72 73 fn vecToRgba(v: zm.Vec) color.Rgba32 {
··· 17 pub const Context = struct { 18 cam: *Camera, 19 world: *hittable.HittableList, 20 }; 21 22 pub fn rayColor(r: *Ray, world: *hittable.HittableList) zm.Vec { ··· 29 return zm.f32x4s(1.0 - a) * zm.f32x4s(1.0) + zm.f32x4s(a) * zm.f32x4(0.5, 0.7, 1.0, 1.0); 30 } 31 32 + pub fn run(ctx: Context, height: IntervalUsize, width: IntervalUsize) void { 33 var height_iter = height.iter(); 34 height_iter.upper_boundry = .inclusive; 35 ··· 50 ctx.cam.setPixel(i, j, col) catch break; 51 } 52 } 53 } 54 55 + pub fn renderThread(ctx: Context, done: *std.atomic.Value(bool), row: usize, row_height: usize) void { 56 spall.init_thread(); 57 defer spall.deinit_thread(); 58 ··· 64 const s = spall.trace(@src(), "Render Thread {}", .{row}); 65 defer s.end(); 66 67 + run(ctx, height, width); 68 + 69 + done.store(true, .Release); 70 } 71 72 fn vecToRgba(v: zm.Vec) color.Rgba32 {