[Bf-blender-cvs] [a859837cdea] master: Cleanup: Move OptiX denoiser code from device into denoiser class
Patrick Mours
noreply at git.blender.org
Tue Nov 15 15:51:12 CET 2022
Commit: a859837cdea0c34268c870da25b038e3826aecc2
Author: Patrick Mours
Date: Tue Nov 15 13:05:23 2022 +0100
Branches: master
https://developer.blender.org/rBa859837cdea0c34268c870da25b038e3826aecc2
Cleanup: Move OptiX denoiser code from device into denoiser class
Cycles already treats denoising fairly separate in its code, with a
dedicated `Denoiser` base class used to describe denoising
behavior. That class has been fully implemented for OIDN
(`denoiser_oidn.cpp`), but for OptiX was mostly empty
(`denoiser_optix.cpp`) and denoising was instead implemented in
the OptiX device. That meant denoising code was split over various
files and directories, making it a bit awkward to work with. This
patch moves the OptiX denoising implementation into the existing
`OptiXDenoiser` class, so that everything is in one place. There are
no functional changes, code has been mostly moved as-is. To
retain support for potential other denoiser implementations based
on a GPU device in the future, the `DeviceDenoiser` base class was
kept and slightly extended (and its file renamed to
`denoiser_gpu.cpp` to follow similar naming rules as
`path_trace_work_*.cpp`).
Differential Revision: https://developer.blender.org/D16502
===================================================================
M intern/cycles/CMakeLists.txt
M intern/cycles/device/CMakeLists.txt
M intern/cycles/device/denoise.h
M intern/cycles/device/device.h
M intern/cycles/device/optix/device_impl.cpp
M intern/cycles/device/optix/device_impl.h
M intern/cycles/integrator/CMakeLists.txt
M intern/cycles/integrator/denoiser.cpp
D intern/cycles/integrator/denoiser_device.h
R077 intern/cycles/integrator/denoiser_device.cpp intern/cycles/integrator/denoiser_gpu.cpp
A intern/cycles/integrator/denoiser_gpu.h
M intern/cycles/integrator/denoiser_optix.cpp
M intern/cycles/integrator/denoiser_optix.h
===================================================================
diff --git a/intern/cycles/CMakeLists.txt b/intern/cycles/CMakeLists.txt
index 329aa3990f6..c6590a07ee4 100644
--- a/intern/cycles/CMakeLists.txt
+++ b/intern/cycles/CMakeLists.txt
@@ -253,6 +253,33 @@ if(WITH_CYCLES_OSL)
)
endif()
+if(WITH_CYCLES_DEVICE_CUDA OR WITH_CYCLES_DEVICE_OPTIX)
+ add_definitions(-DWITH_CUDA)
+
+ if(WITH_CUDA_DYNLOAD)
+ include_directories(
+ ../../extern/cuew/include
+ )
+ add_definitions(-DWITH_CUDA_DYNLOAD)
+ else()
+ include_directories(
+ SYSTEM
+ ${CUDA_TOOLKIT_INCLUDE}
+ )
+ endif()
+endif()
+
+if(WITH_CYCLES_DEVICE_HIP)
+ add_definitions(-DWITH_HIP)
+
+ if(WITH_HIP_DYNLOAD)
+ include_directories(
+ ../../extern/hipew/include
+ )
+ add_definitions(-DWITH_HIP_DYNLOAD)
+ endif()
+endif()
+
if(WITH_CYCLES_DEVICE_OPTIX)
find_package(OptiX 7.3.0)
@@ -261,12 +288,16 @@ if(WITH_CYCLES_DEVICE_OPTIX)
include_directories(
SYSTEM
${OPTIX_INCLUDE_DIR}
- )
+ )
else()
set_and_warn_library_found("OptiX" OPTIX_FOUND WITH_CYCLES_DEVICE_OPTIX)
endif()
endif()
+if(WITH_CYCLES_DEVICE_METAL)
+ add_definitions(-DWITH_METAL)
+endif()
+
if (WITH_CYCLES_DEVICE_ONEAPI)
add_definitions(-DWITH_ONEAPI)
endif()
diff --git a/intern/cycles/device/CMakeLists.txt b/intern/cycles/device/CMakeLists.txt
index bfca3ab6aea..6808d8c04d7 100644
--- a/intern/cycles/device/CMakeLists.txt
+++ b/intern/cycles/device/CMakeLists.txt
@@ -8,28 +8,13 @@ set(INC
set(INC_SYS )
if(WITH_CYCLES_DEVICE_OPTIX OR WITH_CYCLES_DEVICE_CUDA)
- if(WITH_CUDA_DYNLOAD)
- list(APPEND INC
- ../../../extern/cuew/include
- )
- add_definitions(-DWITH_CUDA_DYNLOAD)
- else()
- list(APPEND INC_SYS
- ${CUDA_TOOLKIT_INCLUDE}
- )
+ if(NOT WITH_CUDA_DYNLOAD)
add_definitions(-DCYCLES_CUDA_NVCC_EXECUTABLE="${CUDA_NVCC_EXECUTABLE}")
endif()
add_definitions(-DCYCLES_RUNTIME_OPTIX_ROOT_DIR="${CYCLES_RUNTIME_OPTIX_ROOT_DIR}")
endif()
-if(WITH_CYCLES_DEVICE_HIP AND WITH_HIP_DYNLOAD)
- list(APPEND INC
- ../../../extern/hipew/include
- )
- add_definitions(-DWITH_HIP_DYNLOAD)
-endif()
-
set(SRC_BASE
device.cpp
denoise.cpp
@@ -168,24 +153,15 @@ if(WITH_CYCLES_DEVICE_HIP AND WITH_HIP_DYNLOAD)
)
endif()
-if(WITH_CYCLES_DEVICE_CUDA)
- add_definitions(-DWITH_CUDA)
-endif()
-if(WITH_CYCLES_DEVICE_HIP)
- add_definitions(-DWITH_HIP)
-endif()
-if(WITH_CYCLES_DEVICE_OPTIX)
- add_definitions(-DWITH_OPTIX)
-endif()
if(WITH_CYCLES_DEVICE_METAL)
list(APPEND LIB
${METAL_LIBRARY}
)
- add_definitions(-DWITH_METAL)
list(APPEND SRC
${SRC_METAL}
)
endif()
+
if (WITH_CYCLES_DEVICE_ONEAPI)
if(WITH_CYCLES_ONEAPI_BINARIES)
set(cycles_kernel_oneapi_lib_suffix "_aot")
@@ -203,7 +179,6 @@ if (WITH_CYCLES_DEVICE_ONEAPI)
else()
list(APPEND LIB ${SYCL_LIBRARY})
endif()
- add_definitions(-DWITH_ONEAPI)
list(APPEND SRC
${SRC_ONEAPI}
)
diff --git a/intern/cycles/device/denoise.h b/intern/cycles/device/denoise.h
index 095ee3b89ae..48d6d5c11ed 100644
--- a/intern/cycles/device/denoise.h
+++ b/intern/cycles/device/denoise.h
@@ -78,24 +78,4 @@ class DenoiseParams : public Node {
}
};
-/* All the parameters needed to perform buffer denoising on a device.
- * Is not really a task in its canonical terms (as in, is not an asynchronous running task). Is
- * more like a wrapper for all the arguments and parameters needed to perform denoising. Is a
- * single place where they are all listed, so that it's not required to modify all device methods
- * when these parameters do change. */
-class DeviceDenoiseTask {
- public:
- DenoiseParams params;
-
- int num_samples;
-
- RenderBuffers *render_buffers;
- BufferParams buffer_params;
-
- /* Allow to do in-place modification of the input passes (scaling them down i.e.). This will
- * lower the memory footprint of the denoiser but will make input passes "invalid" (from path
- * tracer) point of view. */
- bool allow_inplace_modification;
-};
-
CCL_NAMESPACE_END
diff --git a/intern/cycles/device/device.h b/intern/cycles/device/device.h
index 06a2f5c7b01..11d693cb25b 100644
--- a/intern/cycles/device/device.h
+++ b/intern/cycles/device/device.h
@@ -233,21 +233,6 @@ class Device {
return nullptr;
}
- /* Buffer denoising. */
-
- /* Returns true if task is fully handled. */
- virtual bool denoise_buffer(const DeviceDenoiseTask & /*task*/)
- {
- LOG(ERROR) << "Request buffer denoising from a device which does not support it.";
- return false;
- }
-
- virtual DeviceQueue *get_denoise_queue()
- {
- LOG(ERROR) << "Request denoising queue from a device which does not support it.";
- return nullptr;
- }
-
/* Sub-devices */
/* Run given callback for every individual device which will be handling rendering.
diff --git a/intern/cycles/device/optix/device_impl.cpp b/intern/cycles/device/optix/device_impl.cpp
index 02f34bf3bd0..f4d1969f3f3 100644
--- a/intern/cycles/device/optix/device_impl.cpp
+++ b/intern/cycles/device/optix/device_impl.cpp
@@ -1,16 +1,15 @@
/* SPDX-License-Identifier: Apache-2.0
- * Copyright 2019, NVIDIA Corporation.
- * Copyright 2019-2022 Blender Foundation. */
+ * Copyright 2019, NVIDIA Corporation
+ * Copyright 2019-2022 Blender Foundation */
#ifdef WITH_OPTIX
# include "device/optix/device_impl.h"
+# include "device/optix/queue.h"
# include "bvh/bvh.h"
# include "bvh/optix.h"
-# include "integrator/pass_accessor_gpu.h"
-
# include "scene/hair.h"
# include "scene/mesh.h"
# include "scene/object.h"
@@ -29,197 +28,8 @@
# define __KERNEL_OPTIX__
# include "kernel/device/optix/globals.h"
-# include <optix_denoiser_tiling.h>
-
CCL_NAMESPACE_BEGIN
-// A minimal copy of functionality `optix_denoiser_tiling.h` which allows to fix integer overflow
-// issues without bumping SDK or driver requirement.
-//
-// The original code is Copyright NVIDIA Corporation, BSD-3-Clause.
-namespace {
-
-# if OPTIX_ABI_VERSION >= 60
-using ::optixUtilDenoiserInvokeTiled;
-# else
-static OptixResult optixUtilDenoiserSplitImage(const OptixImage2D &input,
- const OptixImage2D &output,
- unsigned int overlapWindowSizeInPixels,
- unsigned int tileWidth,
- unsigned int tileHeight,
- std::vector<OptixUtilDenoiserImageTile> &tiles)
-{
- if (tileWidth == 0 || tileHeight == 0)
- return OPTIX_ERROR_INVALID_VALUE;
-
- unsigned int inPixelStride = optixUtilGetPixelStride(input);
- unsigned int outPixelStride = optixUtilGetPixelStride(output);
-
- int inp_w = std::min(tileWidth + 2 * overlapWindowSizeInPixels, input.width);
- int inp_h = std::min(tileHeight + 2 * overlapWindowSizeInPixels, input.height);
- int inp_y = 0, copied_y = 0;
-
- do {
- int inputOffsetY = inp_y == 0 ? 0 :
- std::max((int)overlapWindowSizeInPixels,
- inp_h - ((int)input.height - inp_y));
- int copy_y = inp_y == 0 ? std::min(input.height, tileHeight + overlapWindowSizeInPixels) :
- std::min(tileHeight, input.height - copied_y);
-
- int inp_x = 0, copied_x = 0;
- do {
- int inputOffsetX = inp_x == 0 ? 0 :
- std::max((int)overlapWindowSizeInPixels,
- inp_w - ((int)input.width - inp_x));
- int copy_x = inp_x == 0 ? std::min(input.width, tileWidth + overlapWindowSizeInPixels) :
- std::min(tileWidth, input.width - copied_x);
-
- OptixUtilDenoiserImageTile tile;
- tile.input.data = input.data + (size_t)(inp_y - inputOffsetY) * input.rowStrideInBytes +
- +(size_t)(inp_x - inputOffsetX) * inPixelStride;
- tile.input.width = inp_w;
- tile.input.height = inp_h;
- tile.input.rowStrideInBytes = input.rowStrideInBytes;
- tile.input.pixelStrideInBytes = input.pixelStrideInBytes;
- tile.input.format = input.format;
-
- tile.output.data = output.data + (size_t)inp_y * output.rowStrideInBytes +
- (size_t)inp_x * outPixelStride;
- tile.output.width = copy_x;
- tile.output.height = copy_y;
- tile.output.rowStrideInBytes = output.rowStrideInBytes;
- tile.output.pixelStrideInBytes = output.pixelStrideInBytes;
- tile.output.format = output.format;
-
- tile.inputOffsetX = inputOffsetX;
- tile.inputOffsetY = inputOffsetY;
- tiles.push_back(tile);
-
- inp_x += inp_x == 0 ? tileWidth + overlapWindowSizeInPixels : tileWidth;
- copied_x += copy_x;
- } while (inp_x < static_cast<int>(input.width));
-
- inp_y += inp_y == 0 ? tileHeight + overlapWindowSizeInPixels : tileHeight;
- copied_y += copy_y;
- } while (inp_y < static_cast<int>(input.height));
-
- return OPTIX_SUCCESS;
-}
-
-static OptixResult optixUtilDenoiserInvokeTiled(OptixDenoiser denoiser,
- CUstream stream,
- const OptixDenoiserParams *params,
- CUdeviceptr denoiserState,
- size_t denoiserStateSizeInBytes,
- const OptixDenoiserGuideLayer *guideLayer,
- const OptixDenoiserLayer *layers,
- unsigned int numLayers,
- CUdeviceptr scratch,
- size_t scratchSizeInBytes,
- unsigned int overlapWindowSizeInPixels,
- unsigned int tileWidth,
- unsigned int tileHeight)
-{
- if (!guideLayer || !layers)
- return OPTIX_ERROR_INVALID_VALUE;
-
- std::vector<std::vector<OptixUtilDenoiserImageTile>> tiles(numLayers);
- std::vector<std::vector
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list