From 2cfe69c07d6690b220cf1e7b76d16a6d6ef4d263 Mon Sep 17 00:00:00 2001 From: Xavier Hallade Date: Mon, 14 Oct 2024 20:34:55 +0200 Subject: [PATCH] Cycles: Fix error handling of BVH transfer to device Previously, in case of a failure during BVH transfer, when running out of memory for example, we could get an error such as "BVH failed to migrate to the GPU due to Embree library error (no error)", because embree error status was actually reset before being queried. This commit fixes its propagation. Pull Request: https://projects.blender.org/blender/blender/pulls/129022 --- intern/cycles/bvh/embree.cpp | 14 ++++++++------ intern/cycles/bvh/embree.h | 4 ++-- intern/cycles/device/oneapi/device_impl.cpp | 7 ++++--- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/intern/cycles/bvh/embree.cpp b/intern/cycles/bvh/embree.cpp index cac35864216..57c378fa211 100644 --- a/intern/cycles/bvh/embree.cpp +++ b/intern/cycles/bvh/embree.cpp @@ -178,9 +178,8 @@ void BVHEmbree::build(Progress &progress, rtcCommitScene(scene); } -const char *BVHEmbree::get_last_error_message() +const char *BVHEmbree::get_error_string(RTCError error_code) { - const RTCError error_code = rtcGetDeviceError(rtc_device); switch (error_code) { case RTC_ERROR_NONE: return "no error"; @@ -203,7 +202,9 @@ const char *BVHEmbree::get_last_error_message() } # if defined(WITH_EMBREE_GPU) && RTC_VERSION >= 40302 -bool BVHEmbree::offload_scenes_to_gpu(const vector &scenes) +/* offload_scenes_to_gpu() uses rtcGetDeviceError() which also resets Embree error status, + * we propagate its value so it doesn't get lost. */ +RTCError BVHEmbree::offload_scenes_to_gpu(const vector &scenes) { /* Having BVH on GPU is more performance-critical than texture data. * In order to ensure good performance even when running out of GPU @@ -216,10 +217,11 @@ bool BVHEmbree::offload_scenes_to_gpu(const vector &scenes) rtcCommitScene(embree_scene); /* In case of any errors from Embree, we should stop * the execution and propagate the error. */ - if (rtcGetDeviceError(rtc_device) != RTC_ERROR_NONE) - return false; + RTCError error_code = rtcGetDeviceError(rtc_device); + if (error_code != RTC_ERROR_NONE) + return error_code; } - return true; + return RTC_ERROR_NONE; } # endif diff --git a/intern/cycles/bvh/embree.h b/intern/cycles/bvh/embree.h index 6f7d8cae355..6ba45cbbd55 100644 --- a/intern/cycles/bvh/embree.h +++ b/intern/cycles/bvh/embree.h @@ -38,10 +38,10 @@ class BVHEmbree : public BVH { void refit(Progress &progress); # if defined(WITH_EMBREE_GPU) && RTC_VERSION >= 40302 - bool offload_scenes_to_gpu(const vector &scenes); + RTCError offload_scenes_to_gpu(const vector &scenes); # endif - const char *get_last_error_message(); + const char *get_error_string(RTCError error_code); RTCScene scene; diff --git a/intern/cycles/device/oneapi/device_impl.cpp b/intern/cycles/device/oneapi/device_impl.cpp index b26ca8a18b5..5c5919c6b09 100644 --- a/intern/cycles/device/oneapi/device_impl.cpp +++ b/intern/cycles/device/oneapi/device_impl.cpp @@ -190,10 +190,11 @@ void OneapiDevice::build_bvh(BVH *bvh, Progress &progress, bool refit) if (bvh->params.top_level) { embree_scene = bvh_embree->scene; # if RTC_VERSION >= 40302 - if (bvh_embree->offload_scenes_to_gpu(all_embree_scenes) == false) { + RTCError error_code = bvh_embree->offload_scenes_to_gpu(all_embree_scenes); + if (error_code != RTC_ERROR_NONE) { set_error( - string_printf("BVH failed to to migrate to the GPU due to Embree library error (%s)", - bvh_embree->get_last_error_message())); + string_printf("BVH failed to migrate to the GPU due to Embree library error (%s)", + bvh_embree->get_error_string(error_code))); } all_embree_scenes.clear(); # endif