| 3537 | } |
| 3538 | |
| 3539 | char *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 | } |