MCPcopy Create free account
hub / github.com/KhronosGroup/OpenCL-CTS / create_random_image_data

Function create_random_image_data

test_common/harness/imageHelpers.cpp:3539–3774  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3537}
3538
3539char *create_random_image_data(ExplicitType dataType,
3540 image_descriptor *imageInfo,
3541 BufferOwningPtr<char> &P, MTdata d,
3542 bool image2DFromBuffer)
3543{
3544 size_t allocSize, numPixels;
3545 if (/*gTestMipmaps*/ imageInfo->num_mip_levels > 1)
3546 {
3547 allocSize = (size_t)(compute_mipmapped_image_size(*imageInfo) * 4
3548 * get_explicit_type_size(dataType))
3549 / get_pixel_size(imageInfo->format);
3550 numPixels = allocSize / (get_explicit_type_size(dataType) * 4);
3551 }
3552 else
3553 {
3554 numPixels = (image2DFromBuffer ? imageInfo->rowPitch : imageInfo->width)
3555 * imageInfo->height * (imageInfo->depth ? imageInfo->depth : 1)
3556 * (imageInfo->arraySize ? imageInfo->arraySize : 1);
3557 allocSize = numPixels * 4 * get_explicit_type_size(dataType);
3558 }
3559
3560#if 0 // DEBUG
3561 {
3562 fprintf(stderr,"--- create_random_image_data:\n");
3563 fprintf(stderr,"allocSize = %zu\n",allocSize);
3564 fprintf(stderr,"numPixels = %zu\n",numPixels);
3565 fprintf(stderr,"width = %zu\n",imageInfo->width);
3566 fprintf(stderr,"height = %zu\n",imageInfo->height);
3567 fprintf(stderr,"depth = %zu\n",imageInfo->depth);
3568 fprintf(stderr,"rowPitch = %zu\n",imageInfo->rowPitch);
3569 fprintf(stderr,"slicePitch = %zu\n",imageInfo->slicePitch);
3570 fprintf(stderr,"arraySize = %zu\n",imageInfo->arraySize);
3571 fprintf(stderr,"explicit_type_size = %zu\n",get_explicit_type_size(dataType));
3572 }
3573#endif
3574
3575#if defined(__APPLE__)
3576 char *data = NULL;
3577 if (gDeviceType == CL_DEVICE_TYPE_CPU)
3578 {
3579 size_t mapSize =
3580 ((allocSize + 4095L) & -4096L) + 8192; // alloc two extra pages.
3581
3582 void *map = mmap(0, mapSize, PROT_READ | PROT_WRITE,
3583 MAP_ANON | MAP_PRIVATE, 0, 0);
3584 if (map == MAP_FAILED)
3585 {
3586 perror("create_random_image_data: mmap");
3587 log_error("%s:%d: mmap failed, mapSize = %zu\n", __FILE__, __LINE__,
3588 mapSize);
3589 }
3590 intptr_t data_end = (intptr_t)map + mapSize - 4096;
3591 data = (char *)(data_end - (intptr_t)allocSize);
3592
3593 mprotect(map, 4096, PROT_NONE);
3594 mprotect((void *)((char *)map + mapSize - 4096), 4096, PROT_NONE);
3595 P.reset(data, map, mapSize);
3596 }

Callers 5

test_write_imageFunction · 0.85
test_write_image_3DFunction · 0.85
test_write_image_1DFunction · 0.85

Calls 12

get_explicit_type_sizeFunction · 0.85
get_pixel_sizeFunction · 0.85
align_mallocFunction · 0.85
get_pixel_alignmentFunction · 0.85
get_random_floatFunction · 0.85
genrand_int32Function · 0.85
is_format_signedFunction · 0.85
get_format_min_intFunction · 0.85
get_format_max_intFunction · 0.85
random_in_rangeFunction · 0.85
resetMethod · 0.45

Tested by 5

test_write_imageFunction · 0.68
test_write_image_3DFunction · 0.68
test_write_image_1DFunction · 0.68