[Bf-blender-cvs] [ad81074fab1] cycles-x: Merge branch 'master' into cycles-x

Sergey Sharybin noreply at git.blender.org
Fri May 21 12:34:23 CEST 2021


Commit: ad81074fab1e6dbb823998a94406e65b2ebb6ab2
Author: Sergey Sharybin
Date:   Fri May 21 12:34:19 2021 +0200
Branches: cycles-x
https://developer.blender.org/rBad81074fab1e6dbb823998a94406e65b2ebb6ab2

Merge branch 'master' into cycles-x

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



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

diff --cc intern/cycles/device/device.h
index c3e165255a6,ecf79bcdfa6..68393c67fb7
--- a/intern/cycles/device/device.h
+++ b/intern/cycles/device/device.h
@@@ -348,7 -426,18 +348,10 @@@ class Device 
    /* acceleration structure building */
    virtual void build_bvh(BVH *bvh, Progress &progress, bool refit);
  
+   /* OptiX specific destructor. */
+   virtual void release_optix_bvh(BVH * /*bvh*/){};
+ 
 -#ifdef WITH_NETWORK
 -  /* networking */
 -  void server_run();
 -#endif
 -
    /* multi device */
 -  virtual void map_tile(Device * /*sub_device*/, RenderTile & /*tile*/)
 -  {
 -  }
    virtual int device_number(Device * /*sub_device*/)
    {
      return 0;
diff --cc intern/cycles/device/opencl/device_impl.cpp
index 826584a3e36,715213175c9..0dd4094f9cc
--- a/intern/cycles/device/opencl/device_impl.cpp
+++ b/intern/cycles/device/opencl/device_impl.cpp
@@@ -103,11 -107,10 +103,10 @@@ void OpenCLDevice::enable_default_featu
  }
  
  string OpenCLDevice::get_build_options(const DeviceRequestedFeatures &requested_features,
-                                        const string &opencl_program_name,
-                                        bool preview_kernel)
+                                        const string &opencl_program_name)
  {
    /* first check for non-split kernel programs */
 -  if (opencl_program_name == "base" || opencl_program_name == "denoising") {
 +  if (opencl_program_name == "base") {
      return "";
    }
    else if (opencl_program_name == "bake") {
@@@ -607,11 -604,10 +598,10 @@@ void OpenCLDevice::opencl_assert_err(cl
    }
  }
  
 -OpenCLDevice::OpenCLDevice(DeviceInfo &info, Stats &stats, Profiler &profiler, bool background)
 -    : Device(info, stats, profiler, background),
 +OpenCLDevice::OpenCLDevice(const DeviceInfo &info, Stats &stats, Profiler &profiler)
 +    : Device(info, stats, profiler),
        load_kernel_num_compiling(0),
        kernel_programs(this),
-       preview_programs(this),
        memory_manager(this),
        texture_info(this, "__texture_info", MEM_GLOBAL)
  {
@@@ -769,8 -762,27 +755,8 @@@ bool OpenCLDevice::load_kernels(const D
    load_required_kernels(requested_features);
  
    vector<OpenCLProgram *> programs;
-   kernel_programs.load_kernels(programs, requested_features, false);
+   kernel_programs.load_kernels(programs, requested_features);
  
 -  if (!requested_features.use_baking && requested_features.use_denoising) {
 -    denoising_program = OpenCLProgram(
 -        this, "denoising", "filter.cl", get_build_options(requested_features, "denoising"));
 -    denoising_program.add_kernel(ustring("filter_divide_shadow"));
 -    denoising_program.add_kernel(ustring("filter_get_feature"));
 -    denoising_program.add_kernel(ustring("filter_write_feature"));
 -    denoising_program.add_kernel(ustring("filter_detect_outliers"));
 -    denoising_program.add_kernel(ustring("filter_combine_halves"));
 -    denoising_program.add_kernel(ustring("filter_construct_transform"));
 -    denoising_program.add_kernel(ustring("filter_nlm_calc_difference"));
 -    denoising_program.add_kernel(ustring("filter_nlm_blur"));
 -    denoising_program.add_kernel(ustring("filter_nlm_calc_weight"));
 -    denoising_program.add_kernel(ustring("filter_nlm_update_output"));
 -    denoising_program.add_kernel(ustring("filter_nlm_normalize"));
 -    denoising_program.add_kernel(ustring("filter_nlm_construct_gramian"));
 -    denoising_program.add_kernel(ustring("filter_finalize"));
 -    programs.push_back(&denoising_program);
 -  }
 -
    load_required_kernel_task_pool.wait_work();
  
    /* Parallel compilation of Cycles kernels, this launches multiple
diff --cc intern/cycles/device/opencl/device_impl.h
index f9426cad1e9,a65e764b0d4..3fd0209b640
--- a/intern/cycles/device/opencl/device_impl.h
+++ b/intern/cycles/device/opencl/device_impl.h
@@@ -376,9 -377,9 +374,8 @@@ class OpenCLDevice : public Device 
    OpenCLProgram bake_program;
    OpenCLProgram displace_program;
    OpenCLProgram background_program;
 -  OpenCLProgram denoising_program;
  
    OpenCLSplitPrograms kernel_programs;
-   OpenCLSplitPrograms preview_programs;
  
    typedef map<string, device_vector<uchar> *> ConstMemMap;
    typedef map<string, device_ptr> MemMap;
diff --cc intern/cycles/device/optix/device_impl.cpp
index 5e2c923c573,00000000000..1483e2715cd
mode 100644,000000..100644
--- a/intern/cycles/device/optix/device_impl.cpp
+++ b/intern/cycles/device/optix/device_impl.cpp
@@@ -1,1396 -1,0 +1,1418 @@@
 +/*
 + * Copyright 2019, NVIDIA Corporation.
 + * Copyright 2019, Blender Foundation.
 + *
 + * Licensed under the Apache License, Version 2.0 (the "License");
 + * you may not use this file except in compliance with the License.
 + * You may obtain a copy of the License at
 + *
 + * http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +
 +#ifdef WITH_OPTIX
 +
 +#  include "device/optix/device_impl.h"
 +
 +#  include "bvh/bvh.h"
 +#  include "bvh/bvh_optix.h"
 +#  include "render/buffers.h"
 +#  include "render/hair.h"
 +#  include "render/mesh.h"
 +#  include "render/object.h"
 +#  include "render/scene.h"
 +
 +#  include "util/util_debug.h"
 +#  include "util/util_logging.h"
 +#  include "util/util_md5.h"
 +#  include "util/util_path.h"
 +#  include "util/util_progress.h"
 +#  include "util/util_time.h"
 +
 +#  undef __KERNEL_CPU__
 +#  define __KERNEL_OPTIX__
 +#  include "kernel/device/optix/globals.h"
 +
 +CCL_NAMESPACE_BEGIN
 +
 +OptiXDevice::Denoiser::Denoiser(CUDADevice *device)
 +    : device(device), state(device, "__denoiser_state")
 +{
 +}
 +
 +OptiXDevice::Denoiser::~Denoiser()
 +{
 +  const CUDAContextScope scope(device);
 +  if (optix_denoiser != nullptr) {
 +    optixDenoiserDestroy(optix_denoiser);
 +  }
 +}
 +
 +OptiXDevice::OptiXDevice(const DeviceInfo &info, Stats &stats, Profiler &profiler)
 +    : CUDADevice(info, stats, profiler),
 +      sbt_data(this, "__sbt", MEM_READ_ONLY),
 +      launch_params(this, "__params"),
 +      denoiser_(this)
 +{
 +  /* Make the CUDA context current. */
 +  if (!cuContext) {
 +    /* Do not initialize if CUDA context creation failed already. */
 +    return;
 +  }
 +  const CUDAContextScope scope(this);
 +
 +  /* Create OptiX context for this device. */
 +  OptixDeviceContextOptions options = {};
 +#  ifdef WITH_CYCLES_LOGGING
 +  options.logCallbackLevel = 4; /* Fatal = 1, Error = 2, Warning = 3, Print = 4. */
 +  options.logCallbackFunction = [](unsigned int level, const char *, const char *message, void *) {
 +    switch (level) {
 +      case 1:
 +        LOG_IF(FATAL, VLOG_IS_ON(1)) << message;
 +        break;
 +      case 2:
 +        LOG_IF(ERROR, VLOG_IS_ON(1)) << message;
 +        break;
 +      case 3:
 +        LOG_IF(WARNING, VLOG_IS_ON(1)) << message;
 +        break;
 +      case 4:
 +        LOG_IF(INFO, VLOG_IS_ON(1)) << message;
 +        break;
 +    }
 +  };
 +#  endif
 +#  if OPTIX_ABI_VERSION >= 41 && defined(WITH_CYCLES_DEBUG)
 +  options.validationMode = OPTIX_DEVICE_CONTEXT_VALIDATION_MODE_ALL;
 +#  endif
 +  optix_assert(optixDeviceContextCreate(cuContext, &options, &context));
 +#  ifdef WITH_CYCLES_LOGGING
 +  optix_assert(optixDeviceContextSetLogCallback(
 +      context, options.logCallbackFunction, options.logCallbackData, options.logCallbackLevel));
 +#  endif
 +
 +  /* Fix weird compiler bug that assigns wrong size. */
 +  launch_params.data_elements = sizeof(KernelParamsOptiX);
 +
 +  /* Allocate launch parameter buffer memory on device. */
 +  launch_params.alloc_to_device(1);
 +}
 +
 +OptiXDevice::~OptiXDevice()
 +{
 +  /* Make CUDA context current. */
 +  const CUDAContextScope scope(this);
 +
++  free_bvh_memory_delayed();
++
 +  sbt_data.free();
 +  texture_info.free();
 +  launch_params.free();
 +
 +  /* Unload modules. */
 +  if (optix_module != NULL) {
 +    optixModuleDestroy(optix_module);
 +  }
 +  for (unsigned int i = 0; i < 2; ++i) {
 +    if (builtin_modules[i] != NULL) {
 +      optixModuleDestroy(builtin_modules[i]);
 +    }
 +  }
 +  for (unsigned int i = 0; i < NUM_PIPELINES; ++i) {
 +    if (pipelines[i] != NULL) {
 +      optixPipelineDestroy(pipelines[i]);
 +    }
 +  }
 +
 +  optixDeviceContextDestroy(context);
 +}
 +
 +unique_ptr<DeviceQueue> OptiXDevice::gpu_queue_create()
 +{
 +  return make_unique<OptiXDeviceQueue>(this);
 +}
 +
 +BVHLayoutMask OptiXDevice::get_bvh_layout_mask() const
 +{
 +  /* CUDA kernels are used when doing baking, so need to build a BVH those can understand too! */
 +  if (optix_module == NULL) {
 +    return CUDADevice::get_bvh_layout_mask();
 +  }
 +
 +  /* OptiX has its own internal acceleration structure format. */
 +  return BVH_LAYOUT_OPTIX;
 +}
 +
 +string OptiXDevice::compile_kernel_get_common_cflags(
 +    const DeviceRequestedFeatures &requested_features)
 +{
 +  string common_cflags = CUDADevice::compile_kernel_get_common_cflags(requested_features);
 +
 +  /* Add OptiX SDK include directory to include paths. */
 +  const char *optix_sdk_path = getenv("OPTIX_ROOT_DIR");
 +  if (optix_sdk_path) {
 +    common_cflags += string_printf(" -I\"%s/include\"", optix_sdk_path);
 +  }
 +
 +  /* Specialization for shader raytracing. */
 +  if (requested_features.use_shader_raytrace) {
 +    common_cflags += " --keep-device-functions";
 +  }
 +  else {
 +    common_cflags += " -D __NO_SHADER_RAYTRACE__";
 +  }
 +
 +  return common_cflags;
 +}
 +
 +bool OptiXDevice::load_kernels(const DeviceRequestedFeatures &requested_features)
 +{
 +  if (have_error()) {
 +    /* Abort early if context creation failed already. */
 +    return false;
 +  }
 +
 +  /* Load CUDA modules because we need some of the utility kernels. */
 +  if (!CUDADevice::load_kernels(requested_features)) {
 +    return false;
 +  }
 +
 +  /* Baking is currently performed using CUDA, so no need to load OptiX kernels.
 +   * Can also skip creating OptiX module if only doing denoising (no path tracing).
 +   */
 + 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list