Skip to content

Commit e22a231

Browse files
committed
remove atomics and switch to StructArrays for SPPM
1 parent f9baae3 commit e22a231

File tree

8 files changed

+136
-121
lines changed

8 files changed

+136
-121
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ authors = ["Anton Smirnov <[email protected]>"]
44
version = "0.1.0"
55

66
[deps]
7+
Atomix = "a9b6321e-bd34-4604-b9c9-b65b8de01458"
78
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
89
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
910
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
@@ -16,6 +17,7 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1617
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
1718

1819
[compat]
20+
Atomix = "0.1.0"
1921
FileIO = "1.16"
2022
GeometryBasics = "0.4"
2123
ImageCore = "0.10"

src/Trace.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ using LinearAlgebra
99
using StaticArrays
1010
using ProgressMeter
1111
using StructArrays
12+
using Atomix
1213

1314
abstract type AbstractRay end
1415
abstract type Spectrum end

src/film.jl

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ struct Film{Pixels<:AbstractMatrix{Pixel}}
2424
"""
2525
filter_table::Matrix{Float32}
2626
scale::Float32
27+
framebuffer::Matrix{RGB{Float32}}
28+
2729
"""
2830
- resolution: full resolution of the image in pixels.
2931
- crop_bounds: subset of the image to render in [0, 1] range.
@@ -44,16 +46,20 @@ struct Film{Pixels<:AbstractMatrix{Pixel}}
4446
)
4547
crop_resolution = Int32.(inclusive_sides(crop_bounds))
4648
# Allocate film image storage.
47-
pixels = StructArray(fill(Pixel(), crop_resolution[end], crop_resolution[end]))
49+
pixels = StructArray{Pixel}(undef, crop_resolution[end], crop_resolution[end])
50+
pixels.xyz .= (Point3f(0),)
51+
pixels.filter_weight_sum .= 0f0
52+
pixels.splat_xyz .= (Point3f(0),)
4853
# Precompute filter weight table.
4954
r = filter.radius ./ filter_table_width
5055
for y in 0:filter_table_width-1, x in 0:filter_table_width-1
5156
p = Point2f((x + 0.5f0) * r[1], (y + 0.5f0) * r[2])
5257
filter_table[y+1, x+1] = filter(p)
5358
end
59+
framebuffer = Matrix{RGB{Float32}}(undef, size(pixels)...)
5460
new{typeof(pixels)}(
5561
resolution, crop_bounds, diagonal * 0.001f0, filter, filename,
56-
pixels, filter_table_width, filter_table, scale,
62+
pixels, filter_table_width, filter_table, scale, framebuffer
5763
)
5864
end
5965
end
@@ -98,11 +104,13 @@ struct FilmTile{Pixels<:AbstractMatrix{<:FilmTilePixel}}
98104
pixels::Pixels
99105

100106
function FilmTile(
101-
bounds::Bounds2, filter_radius::Point2f,
102-
filter_table::Matrix{Float32}, filter_table_width::Int32,
103-
)
107+
bounds::Bounds2, filter_radius::Point2f,
108+
filter_table::Matrix{Float32}, filter_table_width::Int32,
109+
)
104110
tile_res = (Int32.(inclusive_sides(bounds)))
105-
pixels = StructArray(fill(FilmTilePixel(), (tile_res[2], tile_res[1])))
111+
pixels = StructArray{FilmTilePixel{RGBSpectrum}}(undef, tile_res[2], tile_res[1])
112+
pixels.contrib_sum .= (RGBSpectrum(),)
113+
pixels.filter_weight_sum .= 0.0f0
106114
new{typeof(pixels)}(
107115
bounds, filter_radius, 1f0 ./ filter_radius,
108116
filter_table, filter_table_width,
@@ -129,14 +137,15 @@ Add sample contribution to the film tile.
129137
And is relative to the film, not the film tile.
130138
"""
131139
function add_sample!(
132-
t::FilmTile, point::Point2f, spectrum::S,
133-
sample_weight::Float32 = 1f0,
134-
) where S<:Spectrum
140+
t::FilmTile, point::Point2f, spectrum::S,
141+
sample_weight::Float32 = 1f0,
142+
) where S<:Spectrum
143+
135144
# Compute sample's raster bounds.
136145
discrete_point = point .- 0.5f0
137146
p0 = ceil.(Int32, discrete_point .- t.filter_radius)
138147
p1 = floor.(Int32, discrete_point .+ t.filter_radius) .+ 1
139-
p0 = Int32.(max.(p0, max.(t.bounds.p_min, Point2(Int32(1)))))
148+
p0 = Int32.(max.(p0, max.(t.bounds.p_min, Point2{Int32}(1))))
140149
p1 = Int32.(min.(p1, t.bounds.p_max))
141150
# Precompute x & y filter offsets.
142151
offsets_x = Vector{Int32}(undef, p1[1] - p0[1] + 1)

src/integrators/sampler.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function li(
7575
wo = core.wo
7676
# Compute scattering functions for surface interaction.
7777
bsdf = compute_scattering!(pool, primitive, si, ray)
78-
if bsdf isa Nothing
78+
if bsdf.bxdfs.last == 0
7979
return li(
8080
pool, spawn_ray(pool, si, ray.d),
8181
scene, i.sampler, depth,

0 commit comments

Comments
 (0)