tangled
alpha
login
or
join now
altagos.dev
/
rayray
0
fork
atom
this repo has no description
0
fork
atom
overview
issues
pulls
pipelines
Changed Progress
altagos.dev
2 years ago
bb01e58f
863158da
+33
-26
1 changed file
expand all
collapse all
unified
split
src
rayray.zig
+33
-26
src/rayray.zig
···
31
31
thread_pool: *std.Thread.Pool,
32
32
33
33
camera: Camera,
34
34
-
world: BVH,
34
34
+
world: hittable.HittableList,
35
35
36
36
pub fn init(allocator: std.mem.Allocator, world: hittable.HittableList, camera_opts: Camera.Options) !Self {
37
37
var thread_pool = try allocator.create(std.Thread.Pool);
···
41
41
.allocator = allocator,
42
42
.thread_pool = thread_pool,
43
43
.camera = try Camera.init(allocator, camera_opts),
44
44
-
.world = try BVH.init(allocator, world, build_options.max_depth),
44
44
+
.world = world,
45
45
};
46
46
}
47
47
···
85
85
num_threads,
86
86
});
87
87
88
88
+
var root_node = std.Progress.start(.{
89
89
+
.root_name = "Ray Tracer",
90
90
+
.estimated_total_items = 3,
91
91
+
});
92
92
+
93
93
+
var bvh_node = root_node.start("Createing BVH", 0);
94
94
+
95
95
+
var world_bvh = try BVH.init(self.allocator, self.world, build_options.max_depth);
96
96
+
97
97
+
bvh_node.end();
98
98
+
root_node.setCompletedItems(0);
99
99
+
100
100
+
var task_node = root_node.start("Creating render tasks", 0);
101
101
+
88
102
const tasks = try self.allocator.alloc(TaskTracker, num_chunks);
89
103
defer self.allocator.free(tasks);
90
104
···
97
111
98
112
const ctx = tracer.Context{
99
113
.cam = &self.camera,
100
100
-
.world = &self.world,
114
114
+
.world = &world_bvh,
101
115
.height = c_height,
102
116
.width = c_width,
103
117
};
104
118
105
119
try self.thread_pool.spawn(
106
120
renderThread,
107
107
-
.{ ctx, t, id },
121
121
+
.{ ctx, t },
108
122
);
109
123
}
110
124
111
111
-
// const stderr = std.io.getStdErr();
125
125
+
task_node.end();
126
126
+
root_node.setCompletedItems(1);
112
127
113
113
-
// var progress = std.Progress{
114
114
-
// .terminal = stderr,
115
115
-
// .supports_ansi_escape_codes = true,
116
116
-
// };
117
117
-
// var node = progress.start("Rendered Chunks", num_chunks);
118
118
-
// node.setCompletedItems(0);
119
119
-
// node.context.refresh();
128
128
+
var render_node = root_node.start("Rendering", num_chunks);
120
129
121
130
var thread_to_idx = std.ArrayList(std.Thread.Id).init(self.allocator);
122
131
defer thread_to_idx.deinit();
123
132
124
124
-
var root_node = std.Progress.start(.{
125
125
-
.root_name = "Ray Tracer",
126
126
-
.estimated_total_items = num_chunks,
127
127
-
});
128
133
var nodes = std.ArrayList(std.Progress.Node).init(self.allocator);
129
134
defer nodes.deinit();
130
135
131
131
-
for (0..num_threads) |_| {
132
132
-
try nodes.append(root_node.start("Chunks Rendered", num_chunks / num_threads));
133
133
-
}
134
134
-
135
136
var completed_chunks: u64 = 0;
136
137
var i: usize = 0;
137
138
while (true) {
···
147
148
for (thread_to_idx.items, 0..) |value, idx| {
148
149
if (value == t.thread_id) break :blk idx;
149
150
}
151
151
+
150
152
try thread_to_idx.append(t.thread_id);
151
151
-
const idx = i;
153
153
+
154
154
+
const node_msg = try std.fmt.allocPrint(self.allocator, "Render Thread #{}", .{i});
155
155
+
defer self.allocator.free(node_msg);
156
156
+
try nodes.append(render_node.start(node_msg, num_chunks / num_threads));
157
157
+
root_node.setCompletedItems(1);
158
158
+
152
159
i += 1;
153
153
-
break :blk idx;
160
160
+
break :blk i;
154
161
};
155
162
nodes.items[idx].completeOne();
156
163
157
164
completed_chunks += 1;
158
158
-
root_node.setCompletedItems(completed_chunks);
165
165
+
render_node.setCompletedItems(completed_chunks);
159
166
// if (completed_chunks % self.thread_pool.threads.len == 0) try self.camera.image.writeToFilePath("./out/out.png", .{ .png = .{} });
160
167
} else if (!task_done) {
161
168
done = false;
···
165
172
if (done or !self.thread_pool.is_running) break;
166
173
}
167
174
168
168
-
// node.end();
175
175
+
render_node.end();
176
176
+
root_node.setCompletedItems(3);
169
177
170
178
return self.camera.image;
171
179
}
172
180
};
173
181
174
174
-
pub fn renderThread(ctx: tracer.Context, task: *TaskTracker, id: usize) void {
182
182
+
pub fn renderThread(ctx: tracer.Context, task: *TaskTracker) void {
175
183
defer task.done.store(true, .release);
176
184
task.thread_id = std.Thread.getCurrentId();
177
177
-
_ = id;
178
185
tracer.trace(ctx);
179
186
}