Skip to content

Commit 89d6db7

Browse files
committed
merge
2 parents 60ef870 + 4d78f46 commit 89d6db7

File tree

12 files changed

+514
-191
lines changed

12 files changed

+514
-191
lines changed

docs/code/basic-scene.jl

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,34 +72,18 @@ end
7272

7373
begin
7474
integrator = Trace.WhittedIntegrator(cam, Trace.UniformSampler(8), 5)
75-
@time integrator(scene, film)
75+
@btime integrator(scene, film)
7676
img = reverse(film.framebuffer, dims=1)
7777
end
78+
7879
# 6.296157 seconds (17.64 k allocations: 19.796 MiB, 0.13% gc time, 45 lock conflicts)
7980
# After more GPU optimizations
8081
# 4.169616 seconds (17.37 k allocations: 19.777 MiB, 0.14% gc time, 20 lock conflicts)
8182
# After first shading running on GPU
8283
# 3.835527 seconds (17.36 k allocations: 19.779 MiB, 0.16% gc time, 41 lock conflicts)
84+
# 4.191 s (4710 allocations: 18.36 MiB)
85+
# iterative_li: 5.2s -.-
8386

84-
camera_sample = Trace.get_camera_sample(integrator.sampler, Point2f(512))
85-
ray, ω = Trace.generate_ray_differential(integrator.camera, camera_sample)
86-
87-
@btime Trace.intersect_p(bvh, ray)
88-
@btime Trace.intersect!(bvh, ray)
89-
90-
###
91-
# Int32 always
92-
# 42.000 μs (1 allocation: 624 bytes)
93-
# Tuple instead of vector for nodes_to_visit
94-
# 43.400 μs (1 allocation: 624 bytes)
95-
# AFTER GPU rework
96-
# intersect!
97-
# 40.500 μs (1 allocation: 368 bytes)
98-
# intersect_p
99-
# 11.500 μs (0 allocations: 0 bytes)
100-
101-
### LinearBVHLeaf as one type
102-
# 5.247460 seconds (17.55 k allocations: 19.783 MiB, 46 lock conflicts)
10387

10488
# begin
10589
# integrator = Trace.SPPMIntegrator(cam, 0.075f0, 5, 1)

src/accel/bvh.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ end
251251
if !ln.is_interior && ln.n_primitives > Int32(0)
252252
# Intersect ray with primitives in node.
253253
for i in Int32(0):ln.n_primitives - Int32(1)
254-
tmp_primitive = primitives[ln.offset+i]
254+
offset = ln.offset % Int32
255+
tmp_primitive = primitives[offset+i]
255256
tmp_hit, ray, tmp_interaction = intersect_p!(
256257
tmp_primitive, ray,
257258
)
@@ -293,13 +294,15 @@ end
293294

294295
to_visit_offset, current_node_i = Int32(1), Int32(1)
295296
nodes_to_visit = zeros(MVector{64,Int32})
297+
primitives = bvh.primitives
296298
@inbounds while true
297299
ln = bvh.nodes[current_node_i]
298300
if intersect_p(ln.bounds, ray, inv_dir, dir_is_neg)
299301
if !ln.is_interior && ln.n_primitives > Int32(0)
300302
for i in Int32(0):ln.n_primitives-Int32(1)
303+
offset = ln.offset % Int32
301304
intersect_p(
302-
bvh.primitives[ln.offset + i], ray,
305+
primitives[offset + i], ray,
303306
) && return true
304307
end
305308
to_visit_offset == 1 && break

src/gpu-support.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ function to_gpu(ArrayType, m::Trace.UberMaterial; preserve=[])
3333
no_tex_s = typeof(Kr)()
3434
Kd = Trace.no_texture(m.Kd) ? no_tex_s : to_gpu(ArrayType, m.Kd; preserve=preserve)
3535
end
36-
f_tex = to_gpu(ArrayType, Trace.Texture(ArrayType(zeros(Float32, 1, 1))); preserve=preserve)
36+
f_tex = to_gpu(ArrayType, Trace.Texture(zeros(Float32, 1, 1)); preserve=preserve)
3737
no_tex_f = typeof(f_tex)()
3838
return Trace.UberMaterial(
3939
Kd,
4040
Trace.no_texture(m.Ks) ? no_tex_s : to_gpu(ArrayType, m.Ks; preserve=preserve),
4141
Trace.no_texture(m.Kr) ? no_tex_s : to_gpu(ArrayType, m.Kr; preserve=preserve),
4242
Trace.no_texture(m.Kt) ? no_tex_s : to_gpu(ArrayType, m.Kt; preserve=preserve),
43+
4344
Trace.no_texture(m.σ) ? no_tex_f : to_gpu(ArrayType, m.σ; preserve=preserve),
4445
Trace.no_texture(m.roughness) ? no_tex_f : to_gpu(ArrayType, m.roughness; preserve=preserve),
4546
Trace.no_texture(m.u_roughness) ? no_tex_f : to_gpu(ArrayType, m.u_roughness; preserve=preserve),

0 commit comments

Comments
 (0)