From a4cfd14f0af092685f1bc8f628536bf35e11deb2 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 5 Jun 2025 20:37:25 +0200 Subject: [PATCH] Fix #137966: oneAPI crash when max texture size is exceeded Until the texture cache addresses this properly, show a useful error rather than crashing. Pull Request: https://projects.blender.org/blender/blender/pulls/139892 --- intern/cycles/device/oneapi/device_impl.cpp | 42 ++++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/intern/cycles/device/oneapi/device_impl.cpp b/intern/cycles/device/oneapi/device_impl.cpp index 270dfa91025..dfa46924975 100644 --- a/intern/cycles/device/oneapi/device_impl.cpp +++ b/intern/cycles/device/oneapi/device_impl.cpp @@ -764,6 +764,41 @@ void OneapiDevice::tex_alloc(device_texture &mem) sycl::ext::oneapi::experimental::image_descriptor desc{}; if (mem.data_height > 0) { + const sycl::device &device = reinterpret_cast(queue)->get_device(); + if (mem.data_depth > 1) { + const size_t max_width = device.get_info(); + const size_t max_height = device.get_info(); + const size_t max_depth = device.get_info(); + + if (mem.data_width > max_width || mem.data_height > max_height || + mem.data_depth > max_depth) + { + set_error(string_printf( + "Maximum GPU 3D texture size exceeded (max %zux%zux%zu, found %zux%zux%zu)", + max_width, + max_height, + max_depth, + mem.data_width, + mem.data_height, + mem.data_depth)); + return; + } + } + else { + const size_t max_width = device.get_info(); + const size_t max_height = device.get_info(); + + if (mem.data_width > max_width || mem.data_height > max_height) { + set_error( + string_printf("Maximum GPU 2D texture size exceeded (max %zux%zu, found %zux%zu)", + max_width, + max_height, + mem.data_width, + mem.data_height)); + return; + } + } + /* 2D/3D texture -- Tile optimized */ size_t depth = mem.data_depth == 1 ? 0 : mem.data_depth; desc = sycl::ext::oneapi::experimental::image_descriptor( @@ -775,6 +810,10 @@ void OneapiDevice::tex_alloc(device_texture &mem) sycl::ext::oneapi::experimental::image_mem_handle memHandle = sycl::ext::oneapi::experimental::alloc_image_mem(desc, *queue); + if (!memHandle.raw_handle) { + set_error("GPU texture allocation failed: Raw handle is null"); + return; + } /* Copy data from host to the texture properly based on the texture description */ queue->ext_oneapi_copy(mem.host_pointer, memHandle, desc); @@ -848,8 +887,7 @@ void OneapiDevice::tex_alloc(device_texture &mem) } } catch (sycl::exception const &e) { - set_error("oneAPI texture allocation error: got runtime exception \"" + string(e.what()) + - "\""); + set_error("GPU texture allocation failed: runtime exception \"" + string(e.what()) + "\""); } }