From 8da2a0aee512a41cf78618be71172991a3850477 Mon Sep 17 00:00:00 2001 From: KoykL Date: Mon, 18 Sep 2023 22:04:24 -0400 Subject: [PATCH 1/4] make scaled_principal_point_offset an opaque instance variable to prevent new drjit kernel from being generated on every iteration when film parameters are changed; fix #908 --- src/sensors/perspective.cpp | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/sensors/perspective.cpp b/src/sensors/perspective.cpp index 641bd0af7..dd4f46b74 100644 --- a/src/sensors/perspective.cpp +++ b/src/sensors/perspective.cpp @@ -190,9 +190,9 @@ class PerspectiveCamera final : public ProjectiveCamera { m_image_rect.expand(Point2f(pmax.x(), pmax.y()) / pmax.z()); m_normalization = 1.f / m_image_rect.volume(); m_needs_sample_3 = false; - + m_scaled_principal_point_offset = m_film->size() * m_principal_point_offset / m_film->crop_size(); dr::make_opaque(m_camera_to_sample, m_sample_to_camera, m_dx, m_dy, m_x_fov, - m_image_rect, m_normalization, m_principal_point_offset); + m_image_rect, m_normalization, m_principal_point_offset, m_scaled_principal_point_offset); } std::pair sample_ray(Float time, Float wavelength_sample, @@ -209,13 +209,10 @@ class PerspectiveCamera final : public ProjectiveCamera { ray.time = time; ray.wavelengths = wavelengths; - Vector2f scaled_principal_point_offset = - m_film->size() * m_principal_point_offset / m_film->crop_size(); - // Compute the sample position on the near plane (local camera space). Point3f near_p = m_sample_to_camera * - Point3f(position_sample.x() + scaled_principal_point_offset.x(), - position_sample.y() + scaled_principal_point_offset.y(), + Point3f(position_sample.x() + m_scaled_principal_point_offset.x(), + position_sample.y() + m_scaled_principal_point_offset.y(), 0.f); // Convert into a normalized ray direction; adjust the ray interval accordingly. @@ -246,13 +243,10 @@ class PerspectiveCamera final : public ProjectiveCamera { ray.time = time; ray.wavelengths = wavelengths; - Vector2f scaled_principal_point_offset = - m_film->size() * m_principal_point_offset / m_film->crop_size(); - // Compute the sample position on the near plane (local camera space). Point3f near_p = m_sample_to_camera * - Point3f(position_sample.x() + scaled_principal_point_offset.x(), - position_sample.y() + scaled_principal_point_offset.y(), + Point3f(position_sample.x() + m_scaled_principal_point_offset.x(), + position_sample.y() + m_scaled_principal_point_offset.y(), 0.f); // Convert into a normalized ray direction; adjust the ray interval accordingly. @@ -290,12 +284,9 @@ class PerspectiveCamera final : public ProjectiveCamera { if (dr::none_or(active)) return { ds, dr::zeros() }; - Vector2f scaled_principal_point_offset = - m_film->size() * m_principal_point_offset / m_film->crop_size(); - Point3f screen_sample = m_camera_to_sample * ref_p; - ds.uv = Point2f(screen_sample.x() - scaled_principal_point_offset.x(), - screen_sample.y() - scaled_principal_point_offset.y()); + ds.uv = Point2f(screen_sample.x() - m_scaled_principal_point_offset.x(), + screen_sample.y() - m_scaled_principal_point_offset.y()); active &= (ds.uv.x() >= 0) && (ds.uv.x() <= 1) && (ds.uv.y() >= 0) && (ds.uv.y() <= 1); if (dr::none_or(active)) @@ -409,6 +400,7 @@ class PerspectiveCamera final : public ProjectiveCamera { Float m_x_fov; Vector3f m_dx, m_dy; Vector2f m_principal_point_offset; + Vector2f m_scaled_principal_point_offset; }; MI_IMPLEMENT_CLASS_VARIANT(PerspectiveCamera, ProjectiveCamera) From d21673464f9fe380f0ee2cef4d14121d878fd3f0 Mon Sep 17 00:00:00 2001 From: KoykL Date: Tue, 19 Sep 2023 12:56:16 -0400 Subject: [PATCH 2/4] fixup --- src/render/integrator.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/render/integrator.cpp b/src/render/integrator.cpp index 418594f06..3d7d6f088 100644 --- a/src/render/integrator.cpp +++ b/src/render/integrator.cpp @@ -423,7 +423,8 @@ SamplingIntegrator::render_sample(const Scene *scene, Vector2f sample_pos = pos + sampler->next_2d(active), adjusted_pos = dr::fmadd(sample_pos, scale, offset); - + dr::make_opaque(sample_pos, adjusted_pos); + Point2f aperture_sample(.5f); if (sensor->needs_aperture_sample()) aperture_sample = sampler->next_2d(active); From fef13f2141607fd7bda02160c2a100864003061e Mon Sep 17 00:00:00 2001 From: KoykL Date: Tue, 19 Sep 2023 17:33:43 -0400 Subject: [PATCH 3/4] fixup --- ext/drjit | 2 +- src/render/integrator.cpp | 13 ++++++------- src/sensors/perspective.cpp | 26 +++++++++++++++++--------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/ext/drjit b/ext/drjit index c918fc3ca..fb2f01efb 160000 --- a/ext/drjit +++ b/ext/drjit @@ -1 +1 @@ -Subproject commit c918fc3caeaba780610deeea8c683ca5ee203b60 +Subproject commit fb2f01efb12b582a78fc5f50151b8cbe3a7da870 diff --git a/src/render/integrator.cpp b/src/render/integrator.cpp index 3d7d6f088..4c76686fe 100644 --- a/src/render/integrator.cpp +++ b/src/render/integrator.cpp @@ -290,13 +290,13 @@ SamplingIntegrator::render(Scene *scene, // Compute the position on the image plane Vector2u pos; - pos.y() = idx / film_size[0]; - pos.x() = dr::fnmadd(film_size[0], pos.y(), idx); + pos.y() = idx / dr::opaque(film_size[0]); + pos.x() = dr::fnmadd(dr::opaque(film_size[0]), pos.y(), idx); if (film->sample_border()) - pos -= film->rfilter()->border_size(); + pos -= dr::opaque(film->rfilter()->border_size()); - pos += film->crop_offset(); + pos += dr::opaque(film->crop_offset()); // Scale factor that will be applied to ray differentials ScalarFloat diff_scale_factor = dr::rsqrt((ScalarFloat) spp); @@ -422,9 +422,8 @@ SamplingIntegrator::render_sample(const Scene *scene, offset = -ScalarVector2f(film->crop_offset()) * scale; Vector2f sample_pos = pos + sampler->next_2d(active), - adjusted_pos = dr::fmadd(sample_pos, scale, offset); - dr::make_opaque(sample_pos, adjusted_pos); - + adjusted_pos = dr::fmadd(sample_pos, dr::opaque(scale), dr::opaque(offset)); + Point2f aperture_sample(.5f); if (sensor->needs_aperture_sample()) aperture_sample = sampler->next_2d(active); diff --git a/src/sensors/perspective.cpp b/src/sensors/perspective.cpp index dd4f46b74..7311c42ba 100644 --- a/src/sensors/perspective.cpp +++ b/src/sensors/perspective.cpp @@ -190,9 +190,9 @@ class PerspectiveCamera final : public ProjectiveCamera { m_image_rect.expand(Point2f(pmax.x(), pmax.y()) / pmax.z()); m_normalization = 1.f / m_image_rect.volume(); m_needs_sample_3 = false; - m_scaled_principal_point_offset = m_film->size() * m_principal_point_offset / m_film->crop_size(); + dr::make_opaque(m_camera_to_sample, m_sample_to_camera, m_dx, m_dy, m_x_fov, - m_image_rect, m_normalization, m_principal_point_offset, m_scaled_principal_point_offset); + m_image_rect, m_normalization, m_principal_point_offset); } std::pair sample_ray(Float time, Float wavelength_sample, @@ -209,10 +209,13 @@ class PerspectiveCamera final : public ProjectiveCamera { ray.time = time; ray.wavelengths = wavelengths; + Vector2f scaled_principal_point_offset = + dr::opaque(m_film->size()) * m_principal_point_offset / dr::opaque(m_film->crop_size()); + // Compute the sample position on the near plane (local camera space). Point3f near_p = m_sample_to_camera * - Point3f(position_sample.x() + m_scaled_principal_point_offset.x(), - position_sample.y() + m_scaled_principal_point_offset.y(), + Point3f(position_sample.x() + scaled_principal_point_offset.x(), + position_sample.y() + scaled_principal_point_offset.y(), 0.f); // Convert into a normalized ray direction; adjust the ray interval accordingly. @@ -243,10 +246,13 @@ class PerspectiveCamera final : public ProjectiveCamera { ray.time = time; ray.wavelengths = wavelengths; + Vector2f scaled_principal_point_offset = + dr::opaque(m_film->size()) * m_principal_point_offset / dr::opaque(m_film->crop_size()); + // Compute the sample position on the near plane (local camera space). Point3f near_p = m_sample_to_camera * - Point3f(position_sample.x() + m_scaled_principal_point_offset.x(), - position_sample.y() + m_scaled_principal_point_offset.y(), + Point3f(position_sample.x() + scaled_principal_point_offset.x(), + position_sample.y() + scaled_principal_point_offset.y(), 0.f); // Convert into a normalized ray direction; adjust the ray interval accordingly. @@ -284,9 +290,12 @@ class PerspectiveCamera final : public ProjectiveCamera { if (dr::none_or(active)) return { ds, dr::zeros() }; + Vector2f scaled_principal_point_offset = + dr::opaque(m_film->size()) * m_principal_point_offset / dr::opaque(m_film->crop_size()); + Point3f screen_sample = m_camera_to_sample * ref_p; - ds.uv = Point2f(screen_sample.x() - m_scaled_principal_point_offset.x(), - screen_sample.y() - m_scaled_principal_point_offset.y()); + ds.uv = Point2f(screen_sample.x() - scaled_principal_point_offset.x(), + screen_sample.y() - scaled_principal_point_offset.y()); active &= (ds.uv.x() >= 0) && (ds.uv.x() <= 1) && (ds.uv.y() >= 0) && (ds.uv.y() <= 1); if (dr::none_or(active)) @@ -400,7 +409,6 @@ class PerspectiveCamera final : public ProjectiveCamera { Float m_x_fov; Vector3f m_dx, m_dy; Vector2f m_principal_point_offset; - Vector2f m_scaled_principal_point_offset; }; MI_IMPLEMENT_CLASS_VARIANT(PerspectiveCamera, ProjectiveCamera) From 518b3cd3dbbec9242e43f1d1408790cc95907490 Mon Sep 17 00:00:00 2001 From: KoykL Date: Tue, 19 Sep 2023 17:37:54 -0400 Subject: [PATCH 4/4] revert accidental drjit bump --- ext/drjit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/drjit b/ext/drjit index fb2f01efb..a4f9d3029 160000 --- a/ext/drjit +++ b/ext/drjit @@ -1 +1 @@ -Subproject commit fb2f01efb12b582a78fc5f50151b8cbe3a7da870 +Subproject commit a4f9d302997d50ee9c09f9f67815bccf21ce1513