tangled
alpha
login
or
join now
altagos.dev
/
rayray
0
fork
atom
this repo has no description
0
fork
atom
overview
issues
pulls
pipelines
chunk based rendering on a thread pool
altagos.dev
2 years ago
46c921e9
514a48c3
+32
-31
1 changed file
expand all
collapse all
unified
split
src
rayray.zig
+32
-31
src/rayray.zig
···
52
52
const s = spall.trace(@src(), "Render", .{});
53
53
defer s.end();
54
54
55
55
-
// const rows: usize = try std.Thread.getCpuCount() - 1;
56
56
-
// const row_height = @divTrunc(self.camera.image_height, rows);
57
57
-
// const num_threads = blk: {
58
58
-
// if (self.camera.image_height % rows == 0) {
59
59
-
// break :blk rows;
60
60
-
// }
61
61
-
// break :blk rows + 1;
62
62
-
// };
63
55
64
56
const chunk_height: usize = 25;
65
57
const chunk_width: usize = 25;
66
58
59
59
+
67
60
var rows: usize = @divTrunc(self.camera.image_height, chunk_height);
68
61
if (self.camera.image_height % rows != 0) {
69
62
rows += 1;
70
63
}
64
64
+
71
65
72
66
var cols: usize = @divTrunc(self.camera.image_width, chunk_width);
73
67
if (self.camera.image_width % cols != 0) {
74
68
cols += 1;
75
69
}
76
70
71
71
+
77
72
const num_chunks = cols * rows;
78
73
79
79
-
// log.debug("rows: {}, cols: {}, chunk_height: {}, chunk_width: {}, num_chunks: {}, num_threads: {}", .{
80
80
-
// rows,
81
81
-
// cols,
82
82
-
// chunk_height,
83
83
-
// chunk_width,
84
84
-
// num_chunks,
85
85
-
// self.thread_pool.threads.len,
86
86
-
// });
74
74
+
log.debug("rows: {}, cols: {}, chunk_height: {}, chunk_width: {}, num_chunks: {}, num_threads: {}", .{
75
75
+
rows,
76
76
+
cols,
77
77
+
chunk_height,
78
78
+
chunk_width,
79
79
+
num_chunks,
80
80
+
self.thread_pool.threads.len,
81
81
+
});
87
82
88
88
-
var tasks = try self.allocator.alloc(TaskTracker, num_chunks);
83
83
+
const tasks = try self.allocator.alloc(TaskTracker, num_chunks);
89
84
defer self.allocator.free(tasks);
90
85
91
86
for (tasks, 0..) |*t, id| {
92
92
-
var row: usize = id / cols;
93
93
-
var col: usize = id - cols * row;
94
94
-
95
95
-
row *= chunk_height;
96
96
-
col *= chunk_width;
87
87
+
const row: usize = @divTrunc(id, cols) * chunk_height;
88
88
+
const col: usize = (id - cols * @divTrunc(id, cols)) * chunk_width;
97
89
98
90
const c_height = IntervalUsize{ .min = row, .max = row + chunk_height };
99
91
const c_width = IntervalUsize{ .min = col, .max = col + chunk_width + 1 };
···
105
97
.width = c_width,
106
98
};
107
99
108
108
-
log.debug("Spawning chunk: {}, row start: {}, col start: {}", .{ id, row, col });
100
100
+
// log.debug("Spawning chunk: {}, row start: {}, col start: {}", .{ id, row, col });
109
101
110
102
try self.thread_pool.spawn(
111
103
renderThread,
···
127
119
while (true) {
128
120
var done = true;
129
121
130
130
-
for (0..num_chunks) |id| {
131
131
-
const task_done = tasks[id].done.load(.acquire);
132
122
133
133
-
if (task_done and !tasks[id].marked_as_done) {
134
134
-
// threads[id].thread.join();
135
135
-
tasks[id].marked_as_done = true;
123
123
+
for (tasks) |*t| {
124
124
+
const task_done = t.done.load(.acquire);
125
125
+
126
126
+
127
127
+
if (task_done and !t.marked_as_done) {
128
128
+
t.marked_as_done = true;
136
129
node.completeOne();
137
137
-
try self.camera.image.writeToFilePath("./out/out.png", .{ .png = .{} });
138
138
-
node.context.refresh();
130
130
+
131
131
+
} else if (!thead_done) {
132
132
+
// try self.camera.image.writeToFilePath("./out/out.png", .{ .png = .{} });
133
133
+
// node.context.refresh();
139
134
} else if (!task_done) {
140
135
done = false;
141
136
}
···
148
143
149
144
return self.camera.image;
150
145
}
151
151
-
};
146
146
+
}
152
147
153
148
pub fn renderThread(ctx: tracer.Context, task: *TaskTracker, id: usize) void {
154
149
spall.init_thread();
···
161
156
162
157
tracer.trace(ctx);
163
158
159
159
+
<<<<<<< HEAD
164
160
{
165
161
task.done.store(true, .release);
166
162
}
167
163
168
164
// log.info("Chunk {} rendered", .{id});
169
165
_ = id;
166
166
+
||||||| parent of 3cb11d6 (chunk based rendering on a thread pool)
167
167
+
done.store(true, .Release);
168
168
+
=======
169
169
+
task.done.store(true, .release);
170
170
+
>>>>>>> 3cb11d6 (chunk based rendering on a thread pool)
170
171
}