@@ -428,38 +428,68 @@ size_t GetElementNBytes(const cl_image_format *format)
428
428
return result;
429
429
}
430
430
431
- cl_int get2DImageDimensions (const VkImageCreateInfo *VulkanImageCreateInfo,
432
- cl_image_format *img_fmt, size_t totalImageSize ,
433
- size_t &width, size_t &height )
431
+ cl_int getImageDimensions (const VkImageCreateInfo *VulkanImageCreateInfo,
432
+ cl_image_format *img_fmt, cl_image_desc *img_desc ,
433
+ VkExtent3D max_ext, const VkSubresourceLayout *layout )
434
434
{
435
- cl_int result = CL_SUCCESS;
436
- if (totalImageSize == 0 )
435
+ test_assert_error (
436
+ VulkanImageCreateInfo != nullptr ,
437
+ " getImageDimensions: invalid VulkanImageCreateInfo pointer!" );
438
+ test_assert_error (img_fmt != nullptr ,
439
+ " getImageDimensions: invalid img_fmt pointer!" );
440
+ test_assert_error (img_desc != nullptr ,
441
+ " getImageDimensions: invalid img_desc pointer!" );
442
+
443
+ img_desc->image_depth = VulkanImageCreateInfo->extent .depth ;
444
+ img_desc->image_width = VulkanImageCreateInfo->extent .width ;
445
+ img_desc->image_height = VulkanImageCreateInfo->extent .height ;
446
+
447
+ if (layout != nullptr )
437
448
{
438
- result = CL_INVALID_VALUE;
449
+ size_t element_size = GetElementNBytes (img_fmt);
450
+ size_t row_pitch = element_size * VulkanImageCreateInfo->extent .width ;
451
+ row_pitch = row_pitch < layout->rowPitch ? layout->rowPitch : row_pitch;
452
+ img_desc->image_row_pitch = row_pitch;
453
+
454
+ size_t slice_pitch = row_pitch * VulkanImageCreateInfo->extent .height ;
455
+ slice_pitch =
456
+ slice_pitch < layout->depthPitch ? layout->depthPitch : slice_pitch;
457
+ img_desc->image_slice_pitch = slice_pitch;
439
458
}
440
- size_t element_size = GetElementNBytes (img_fmt);
441
- size_t row_pitch = element_size * VulkanImageCreateInfo->extent .width ;
442
- row_pitch = row_pitch % 64 == 0 ? row_pitch : ((row_pitch / 64 ) + 1 ) * 64 ;
443
459
444
- width = row_pitch / element_size;
445
- height = totalImageSize / row_pitch;
460
+ switch (img_desc->image_type )
461
+ {
462
+ case CL_MEM_OBJECT_IMAGE3D:
463
+ test_assert_error (img_desc->image_depth >= 1
464
+ && img_desc->image_depth <= max_ext.depth ,
465
+ " getImageDimensions: invalid image depth!" );
466
+ case CL_MEM_OBJECT_IMAGE2D:
467
+ test_assert_error (img_desc->image_height >= 1
468
+ && img_desc->image_height <= max_ext.height ,
469
+ " getImageDimensions: invalid image height!" );
470
+ case CL_MEM_OBJECT_IMAGE1D:
471
+ test_assert_error (img_desc->image_width >= 1
472
+ && img_desc->image_width <= max_ext.width ,
473
+ " getImageDimensions: invalid image width!" );
474
+ }
446
475
447
- return result ;
476
+ return CL_SUCCESS ;
448
477
}
449
478
450
479
cl_int
451
- getCLImageInfoFromVkImageInfo (const VkImageCreateInfo *VulkanImageCreateInfo,
452
- size_t totalImageSize, cl_image_format *img_fmt,
453
- cl_image_desc *img_desc)
480
+ getCLImageInfoFromVkImageInfo (const cl_device_id device,
481
+ const VkImageCreateInfo *VulkanImageCreateInfo,
482
+ cl_image_format *img_fmt, cl_image_desc *img_desc,
483
+ const VkSubresourceLayout *layout)
454
484
{
455
- cl_int result = CL_SUCCESS;
485
+ cl_int error = CL_SUCCESS;
456
486
457
487
cl_image_format clImgFormat = { 0 };
458
- result =
488
+ error =
459
489
getCLFormatFromVkFormat (VulkanImageCreateInfo->format , &clImgFormat);
460
- if (CL_SUCCESS != result )
490
+ if (CL_SUCCESS != error )
461
491
{
462
- return result ;
492
+ return error ;
463
493
}
464
494
memcpy (img_fmt, &clImgFormat, sizeof (cl_image_format));
465
495
@@ -469,25 +499,57 @@ getCLImageInfoFromVkImageInfo(const VkImageCreateInfo *VulkanImageCreateInfo,
469
499
return CL_INVALID_VALUE;
470
500
}
471
501
472
- result =
473
- get2DImageDimensions (VulkanImageCreateInfo, img_fmt, totalImageSize,
474
- img_desc->image_width , img_desc->image_height );
475
- if (CL_SUCCESS != result)
502
+ VkExtent3D max_ext = { 0 , 0 , 0 };
503
+
504
+ size_t width = 0 , height = 0 , depth = 0 ;
505
+ if (img_desc->image_type == CL_MEM_OBJECT_IMAGE3D)
506
+ {
507
+ error = clGetDeviceInfo (device, CL_DEVICE_IMAGE3D_MAX_WIDTH,
508
+ sizeof (width), &width, NULL );
509
+ test_error (error, " Unable to get CL_DEVICE_IMAGE3D_MAX_WIDTH" );
510
+ error = clGetDeviceInfo (device, CL_DEVICE_IMAGE3D_MAX_HEIGHT,
511
+ sizeof (height), &height, NULL );
512
+ test_error (error, " Unable to get CL_DEVICE_IMAGE3D_MAX_HEIGHT" );
513
+ error = clGetDeviceInfo (device, CL_DEVICE_IMAGE3D_MAX_DEPTH,
514
+ sizeof (depth), &depth, NULL );
515
+ test_error (error, " Unable to get CL_DEVICE_IMAGE3D_MAX_DEPTH" );
516
+ }
517
+ else
518
+ {
519
+ error = clGetDeviceInfo (device, CL_DEVICE_IMAGE2D_MAX_WIDTH,
520
+ sizeof (width), &width, NULL );
521
+ test_error (error, " Unable to get CL_DEVICE_IMAGE2D_MAX_WIDTH" );
522
+ error = clGetDeviceInfo (device, CL_DEVICE_IMAGE2D_MAX_HEIGHT,
523
+ sizeof (height), &height, NULL );
524
+ test_error (error, " Unable to get CL_DEVICE_IMAGE2D_MAX_HEIGHT" );
525
+ }
526
+
527
+ max_ext.depth = depth;
528
+ max_ext.height = height;
529
+ max_ext.width = width;
530
+
531
+ // If image_row_pitch is zero and the image is created from an external
532
+ // memory handle, then the image row pitch is implementation-defined
533
+ img_desc->image_row_pitch = 0 ;
534
+ // If image_slice_pitch is zero and the image is created from an external
535
+ // memory handle, then the image slice pitch is implementation-defined
536
+ img_desc->image_slice_pitch = 0 ;
537
+
538
+ error = getImageDimensions (VulkanImageCreateInfo, img_fmt, img_desc,
539
+ max_ext, layout);
540
+ if (CL_SUCCESS != error)
476
541
{
477
- throw std::runtime_error (" get2DImageDimensions failed!!!" );
542
+ throw std::runtime_error (" getImageDimensions failed!!!" );
478
543
}
479
544
480
545
img_desc->image_depth =
481
546
static_cast <size_t >(VulkanImageCreateInfo->extent .depth );
482
547
img_desc->image_array_size = 0 ;
483
- img_desc->image_row_pitch = 0 ; // Row pitch set to zero as host_ptr is NULL
484
- img_desc->image_slice_pitch =
485
- img_desc->image_row_pitch * img_desc->image_height ;
486
548
img_desc->num_mip_levels = 0 ;
487
549
img_desc->num_samples = 0 ;
488
550
img_desc->buffer = NULL ;
489
551
490
- return result ;
552
+ return error ;
491
553
}
492
554
493
555
cl_int check_external_memory_handle_type (
@@ -806,7 +868,7 @@ clExternalMemoryImage::clExternalMemoryImage(
806
868
image2D.getVkImageCreateInfo ();
807
869
808
870
errcode_ret = getCLImageInfoFromVkImageInfo (
809
- &VulkanImageCreateInfo, image2D. getSize () , &img_format, &image_desc);
871
+ deviceId, &VulkanImageCreateInfo , &img_format, &image_desc);
810
872
if (CL_SUCCESS != errcode_ret)
811
873
{
812
874
throw std::runtime_error (" getCLImageInfoFromVkImageInfo failed\n " );
@@ -1212,6 +1274,8 @@ cl_external_memory_handle_type_khr vkToOpenCLExternalMemoryHandleType(
1212
1274
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT:
1213
1275
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT_KMT:
1214
1276
return CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR;
1277
+ case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT_NAME:
1278
+ return CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_NAME_KHR;
1215
1279
}
1216
1280
return 0 ;
1217
1281
}
0 commit comments