summaryrefslogtreecommitdiff
path: root/scene/3d/voxel_light_baker.cpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-12-20 17:36:40 +0100
committerGitHub <noreply@github.com>2017-12-20 17:36:40 +0100
commit1040766725113a3a0813740fe47eb0fe674be54e (patch)
tree6017067d4ed81a85d75aca54e88bfa9131c5b776 /scene/3d/voxel_light_baker.cpp
parent3c7f06a0e6630c81d8df8d7642877778e5814c60 (diff)
parent0db512354807318646ac9884f3702733a56b3bb1 (diff)
Merge pull request #14867 from hpvb/optimize-lightbaker-prevent-false-sharing
Prevent false sharing in lightbaker RNG state
Diffstat (limited to 'scene/3d/voxel_light_baker.cpp')
-rw-r--r--scene/3d/voxel_light_baker.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/scene/3d/voxel_light_baker.cpp b/scene/3d/voxel_light_baker.cpp
index 4c52d0bb1b..bf0f801e32 100644
--- a/scene/3d/voxel_light_baker.cpp
+++ b/scene/3d/voxel_light_baker.cpp
@@ -1711,11 +1711,14 @@ Vector3 VoxelLightBaker::_compute_ray_trace_at_pos(const Vector3 &p_pos, const V
const Light *light = bake_light.ptr();
const Cell *cells = bake_cells.ptr();
+ // Prevent false sharing when running on OpenMP
+ uint32_t local_rng_state = *rng_state;
+
for (int i = 0; i < samples; i++) {
- float random_angle1 = (((xorshift32(rng_state) % 65535) / 65535.0) * 2.0 - 1.0) * spread;
+ float random_angle1 = (((xorshift32(&local_rng_state) % 65535) / 65535.0) * 2.0 - 1.0) * spread;
Vector3 axis(0, sin(random_angle1), cos(random_angle1));
- float random_angle2 = ((xorshift32(rng_state) % 65535) / 65535.0) * Math_PI * 2.0;
+ float random_angle2 = ((xorshift32(&local_rng_state) % 65535) / 65535.0) * Math_PI * 2.0;
Basis rot(Vector3(0, 0, 1), random_angle2);
axis = rot.xform(axis);
@@ -1792,6 +1795,8 @@ Vector3 VoxelLightBaker::_compute_ray_trace_at_pos(const Vector3 &p_pos, const V
}
}
+ // Make sure we don't reset this thread's RNG state
+ *rng_state = local_rng_state;
return accum / samples;
}