diff --git a/intern/cycles/device/cuda/device_impl.cpp b/intern/cycles/device/cuda/device_impl.cpp index efe4b659132..7b388c465c9 100644 --- a/intern/cycles/device/cuda/device_impl.cpp +++ b/intern/cycles/device/cuda/device_impl.cpp @@ -733,6 +733,15 @@ void CUDADevice::tex_alloc(device_texture &mem) } /* Image Texture Storage */ + /* Cycles expects to read all texture data as normalized float values in + * kernel/device/gpu/image.h. But storing all data as floats would be very inefficient due to the + * huge size of float textures. So in the code below, we define different texture types including + * integer types, with the aim of using CUDA's default promotion behavior of integer data to + * floating point data in the range [0, 1], as noted in the CUDA documentation on + * cuTexObjectCreate API Call. + * Note that 32-bit integers are not supported by this promotion behavior and cannot be used + * with Cycles's current implementation in kernel/device/gpu/image.h. + */ CUarray_format_enum format; switch (mem.data_type) { case TYPE_UCHAR: @@ -741,12 +750,6 @@ void CUDADevice::tex_alloc(device_texture &mem) case TYPE_UINT16: format = CU_AD_FORMAT_UNSIGNED_INT16; break; - case TYPE_UINT: - format = CU_AD_FORMAT_UNSIGNED_INT32; - break; - case TYPE_INT: - format = CU_AD_FORMAT_SIGNED_INT32; - break; case TYPE_FLOAT: format = CU_AD_FORMAT_FLOAT; break; @@ -900,6 +903,8 @@ void CUDADevice::tex_alloc(device_texture &mem) texDesc.addressMode[1] = address_mode; texDesc.addressMode[2] = address_mode; texDesc.filterMode = filter_mode; + /* CUDA's flag CU_TRSF_READ_AS_INTEGER is intentionally not used and it is + * significant, see above an explanation about how Blender treat textures. */ texDesc.flags = CU_TRSF_NORMALIZED_COORDINATES; thread_scoped_lock lock(device_mem_map_mutex);