[Bf-blender-cvs] [226eb5e3668] blender-v2.92-release: Cycles: Fix usage of double floating precision in CNanoVDB

Sergey Sharybin noreply at git.blender.org
Fri Jan 22 14:31:50 CET 2021


Commit: 226eb5e3668699e7b1d9c985a2b79ac49020befc
Author: Sergey Sharybin
Date:   Wed Jan 20 11:18:40 2021 +0100
Branches: blender-v2.92-release
https://developer.blender.org/rB226eb5e3668699e7b1d9c985a2b79ac49020befc

Cycles: Fix usage of double floating precision in CNanoVDB

Double floating point precision is an extension of OpenCL, which might
not be implemented by certain drivers, such as Intel Xe graphics.

Cycles does not use double floating point precision, and there is no
need on keeping doubles unless there is an explicit decision to use
them.

This is a simple fix from Cycles side to replace double floating point
type with a type of same size and alignment rules. Inspired by Brecht
and Patrick.

Tested on NVidia Titan V, Radeon RX Vega M, and TGL laptop.

Differential Revision: https://developer.blender.org/D10143

===================================================================

M	intern/cycles/kernel/kernels/opencl/kernel_opencl_image.h

===================================================================

diff --git a/intern/cycles/kernel/kernels/opencl/kernel_opencl_image.h b/intern/cycles/kernel/kernels/opencl/kernel_opencl_image.h
index 79e3a16ef19..d87e5f193ad 100644
--- a/intern/cycles/kernel/kernels/opencl/kernel_opencl_image.h
+++ b/intern/cycles/kernel/kernels/opencl/kernel_opencl_image.h
@@ -15,7 +15,20 @@
  */
 
 #ifdef WITH_NANOVDB
+/* Data type to replace `double` used in the NanoVDB headers. Cycles don't need doubles, and is
+ * safer and more portable to never use double datatype on GPU.
+ * Use a special structure, so that the following is true:
+ * - No unnoticed implicit cast or mathermatical operations used on scalar 64bit type
+ *   (which rules out trick like using `uint64_t` as a drop-in replacement for double).
+ * - Padding rules are matching exactly `double`
+ *   (which rules out array of `uint8_t`). */
+typedef struct ccl_vdb_double_t {
+  uint64_t i;
+} ccl_vdb_double_t;
+
+#  define double ccl_vdb_double_t
 #  include "nanovdb/CNanoVDB.h"
+#  undef double
 #endif
 
 /* For OpenCL we do manual lookup and interpolation. */



More information about the Bf-blender-cvs mailing list