Skip to content

Commit f9baae3

Browse files
committed
fix sppm
1 parent 2ea38b3 commit f9baae3

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

src/integrators/sppm.jl

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ struct SPPMIntegrator{C<:Camera} <: Integrator
118118
n_iterations::Int64, photons_per_iteration::Int64 = -1,
119119
write_frequency::Int64 = 1,
120120
) where C<:Camera
121+
121122
photons_per_iteration = (
122123
photons_per_iteration > 0
123124
? photons_per_iteration : area(get_film(camera).crop_bounds)
@@ -129,7 +130,11 @@ struct SPPMIntegrator{C<:Camera} <: Integrator
129130
end
130131
end
131132

133+
134+
135+
132136
function (i::SPPMIntegrator)(scene::Scene)
137+
133138
pixel_bounds = get_film(i.camera).crop_bounds
134139

135140
b_sides = inclusive_sides(pixel_bounds)
@@ -149,7 +154,7 @@ function (i::SPPMIntegrator)(scene::Scene)
149154
n_tiles::Point2 = Int64.(floor.((pixel_extent .+ tile_size) ./ tile_size))
150155

151156
sampler = UniformSampler(1)
152-
mempools = [MemoryPool(round(Int, 100_000)) for _ in 1:Threads.maxthreadid()]
157+
mempools = [MemoryPool(round(Int, 100000)) for _ in 1:Threads.maxthreadid()]
153158
for iteration in 1:i.n_iterations
154159
_generate_visible_sppm_points!(
155160
mempools, i, pixels, scene,
@@ -322,13 +327,20 @@ function _populate_grid!(
322327
grid_bounds, grid_resolution
323328
end
324329

330+
function trace_photon_kernel()
331+
332+
333+
334+
end
335+
336+
325337
function _trace_photons!(
326-
mempools, i::SPPMIntegrator, scene::Scene, iteration::Int64,
327-
light_distribution::Distribution1D,
328-
grid::Vector{Maybe{SPPMPixelListNode}},
329-
grid_bounds::Bounds3, grid_resolution::Point3,
330-
n_pixels::UInt64,
331-
)
338+
mempools, i::SPPMIntegrator, scene::Scene, iteration::Int64,
339+
light_distribution::Distribution1D,
340+
grid::Vector{Maybe{SPPMPixelListNode}},
341+
grid_bounds::Bounds3, grid_resolution::Point3,
342+
n_pixels::UInt64,
343+
)
332344
# Trace photons and accumulate contributions.
333345
halton_base = UInt64(iteration - 1) * UInt64(i.photons_per_iteration)
334346
bar = get_progress_bar(
@@ -377,7 +389,11 @@ function _trace_photons!(
377389

378390
# Follow photon path through scene and record intersections.
379391
depth = 1
392+
_photon_ray = photon_ray[] # load it from mempool
380393
while depth i.max_depth
394+
free_all(pool)
395+
# put it back after free
396+
photon_ray = allocate(pool, _photon_ray)
381397
hit, primitive, interaction = intersect!(pool, scene, photon_ray)
382398
!hit && break
383399
if depth > 1
@@ -435,7 +451,7 @@ function _trace_photons!(
435451
end
436452
halton_dim += 1
437453
# β = β_new / (1f0 - q)
438-
photon_ray = allocate(pool, RayDifferentials, spawn_ray(pool, interaction, wi))
454+
_photon_ray = allocate(pool, RayDifferentials, spawn_ray(pool, interaction, wi))[]
439455
depth += 1
440456
end
441457
next!(bar)

src/materials/bsdf.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ struct BSDF{S}
5353
bxdfs::BXDFVector{S}
5454
end
5555

56+
BSDF() = BSDF{RGBSpectrum}(0f0, Normal3f(0f0), Normal3f(0f0), Vec3f(0f0), Vec3f(0f0), BXDFVector{RGBSpectrum}())
57+
5658
function BSDF(si::SurfaceInteraction, sbdfs::Vararg{UberBxDF{S}, N}) where {S<:Spectrum, N}
5759
BSDF(si, 1f0, sbdfs...)
5860
end

src/mempool.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ end
8181
end
8282
end
8383

84+
function allocate(pool, obj::T) where {T}
85+
mem = allocate(pool, T)
86+
ptr = type_pointer(mem)
87+
unsafe_store!(ptr, obj)
88+
return mem
89+
end
90+
8491
@inline function allocate(pool::MemoryPool, ::Type{T}) where {T}
8592
@assert isbitstype(T) "$T"
8693
nbytes = sizeof(T)

0 commit comments

Comments
 (0)