| 1 |
/* |
| 2 |
* Copyright (C) 2019-2025 Intel Corporation |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
R"===( |
| 9 |
#pragma OPENCL EXTENSION cl_khr_3d_image_writes : enable |
| 10 |
|
| 11 |
__kernel void CopyBufferToImage3dBytes(__global uchar *src, |
| 12 |
__write_only image3d_t output, |
| 13 |
offset_t srcOffset, |
| 14 |
int4 dstOffset, |
| 15 |
coord2_t Pitch) { |
| 16 |
idx_t x = get_global_id(0); |
| 17 |
idx_t y = get_global_id(1); |
| 18 |
idx_t z = get_global_id(2); |
| 19 |
|
| 20 |
int4 dstCoord = (int4)(x, y, z, 0) + dstOffset; |
| 21 |
offset_t LOffset = srcOffset + (y * Pitch.x) + (z * Pitch.y); |
| 22 |
|
| 23 |
write_imageui(output, dstCoord, (uint4)(*(src + LOffset + x), 0, 0, 1)); |
| 24 |
} |
| 25 |
|
| 26 |
__kernel void CopyBufferToImage3d2Bytes(__global uchar *src, |
| 27 |
__write_only image3d_t output, |
| 28 |
offset_t srcOffset, |
| 29 |
int4 dstOffset, |
| 30 |
coord2_t Pitch) { |
| 31 |
idx_t x = get_global_id(0); |
| 32 |
idx_t y = get_global_id(1); |
| 33 |
idx_t z = get_global_id(2); |
| 34 |
|
| 35 |
int4 dstCoord = (int4)(x, y, z, 0) + dstOffset; |
| 36 |
offset_t LOffset = srcOffset + (y * Pitch.x) + (z * Pitch.y); |
| 37 |
|
| 38 |
uint4 c = (uint4)(0, 0, 0, 1); |
| 39 |
|
| 40 |
if(((ulong)(src + srcOffset)) & 0x00000001){ |
| 41 |
ushort upper = *((__global uchar*)(src + LOffset + x * 2 + 1)); |
| 42 |
ushort lower = *((__global uchar*)(src + LOffset + x * 2)); |
| 43 |
ushort combined = (upper << 8) | lower; |
| 44 |
c.x = (uint)combined; |
| 45 |
} |
| 46 |
else{ |
| 47 |
c.x = (uint)(*(__global ushort*)(src + LOffset + x * 2)); |
| 48 |
} |
| 49 |
write_imageui(output, dstCoord, c); |
| 50 |
} |
| 51 |
|
| 52 |
__kernel void CopyBufferToImage3d4Bytes(__global uchar *src, |
| 53 |
__write_only image3d_t output, |
| 54 |
offset_t srcOffset, |
| 55 |
int4 dstOffset, |
| 56 |
coord2_t Pitch) { |
| 57 |
idx_t x = get_global_id(0); |
| 58 |
idx_t y = get_global_id(1); |
| 59 |
idx_t z = get_global_id(2); |
| 60 |
|
| 61 |
int4 dstCoord = (int4)(x, y, z, 0) + dstOffset; |
| 62 |
offset_t LOffset = srcOffset + (y * Pitch.x) + (z * Pitch.y); |
| 63 |
|
| 64 |
uint4 c = (uint4)(0, 0, 0, 1); |
| 65 |
|
| 66 |
if(((ulong)(src + srcOffset)) & 0x00000003){ |
| 67 |
uint upper2 = *((__global uchar*)(src + LOffset + x * 4 + 3)); |
| 68 |
uint upper = *((__global uchar*)(src + LOffset + x * 4 + 2)); |
| 69 |
uint lower2 = *((__global uchar*)(src + LOffset + x * 4 + 1)); |
| 70 |
uint lower = *((__global uchar*)(src + LOffset + x * 4)); |
| 71 |
uint combined = (upper2 << 24) | (upper << 16) | (lower2 << 8) | lower; |
| 72 |
c.x = combined; |
| 73 |
} |
| 74 |
else{ |
| 75 |
c.x = (*(__global uint*)(src + LOffset + x * 4)); |
| 76 |
} |
| 77 |
write_imageui(output, dstCoord, c); |
| 78 |
} |
| 79 |
|
| 80 |
__kernel void CopyBufferToImage3d3To4Bytes(__global uchar *src, |
| 81 |
__write_only image3d_t output, |
| 82 |
offset_t srcOffset, |
| 83 |
int4 dstOffset, |
| 84 |
coord2_t Pitch) { |
| 85 |
idx_t x = get_global_id(0); |
| 86 |
idx_t y = get_global_id(1); |
| 87 |
idx_t z = get_global_id(2); |
| 88 |
|
| 89 |
int4 dstCoord = (int4)(x, y, z, 0) + dstOffset; |
| 90 |
offset_t LOffset = srcOffset + (y * Pitch.x) + (z * Pitch.y); |
| 91 |
|
| 92 |
uint4 c = (uint4)(0, 0, 0, 1); |
| 93 |
|
| 94 |
uint upper2 = 0; |
| 95 |
uint upper = *((__global uchar*)(src + LOffset + x * 3 + 2)); |
| 96 |
uint lower2 = *((__global uchar*)(src + LOffset + x * 3 + 1)); |
| 97 |
uint lower = *((__global uchar*)(src + LOffset + x * 3)); |
| 98 |
uint combined = (upper2 << 24) | (upper << 16) | (lower2 << 8) | lower; |
| 99 |
c.x = combined; |
| 100 |
|
| 101 |
write_imageui(output, dstCoord, c); |
| 102 |
} |
| 103 |
|
| 104 |
__kernel void CopyBufferToImage3d8Bytes(__global uchar *src, |
| 105 |
__write_only image3d_t output, |
| 106 |
offset_t srcOffset, |
| 107 |
int4 dstOffset, |
| 108 |
coord2_t Pitch) { |
| 109 |
idx_t x = get_global_id(0); |
| 110 |
idx_t y = get_global_id(1); |
| 111 |
idx_t z = get_global_id(2); |
| 112 |
|
| 113 |
int4 dstCoord = (int4)(x, y, z, 0) + dstOffset; |
| 114 |
offset_t LOffset = srcOffset + (y * Pitch.x) + (z * Pitch.y); |
| 115 |
|
| 116 |
uint2 c = (uint2)(0, 0);//*((__global uint2*)(src + LOffset + x * 8)); |
| 117 |
|
| 118 |
if(((ulong)(src + srcOffset)) & 0x00000007){ |
| 119 |
uint upper2 = *((__global uchar*)(src + LOffset + x * 8 + 3)); |
| 120 |
uint upper = *((__global uchar*)(src + LOffset + x * 8 + 2)); |
| 121 |
uint lower2 = *((__global uchar*)(src + LOffset + x * 8 + 1)); |
| 122 |
uint lower = *((__global uchar*)(src + LOffset + x * 8)); |
| 123 |
uint combined = (upper2 << 24) | (upper << 16) | (lower2 << 8) | lower; |
| 124 |
c.x = combined; |
| 125 |
upper2 = *((__global uchar*)(src + LOffset + x * 8 + 7)); |
| 126 |
upper = *((__global uchar*)(src + LOffset + x * 8 + 6)); |
| 127 |
lower2 = *((__global uchar*)(src + LOffset + x * 8 + 5)); |
| 128 |
lower = *((__global uchar*)(src + LOffset + x * 8 + 4)); |
| 129 |
combined = ((uint)upper2 << 24) | ((uint)upper << 16) | ((uint)lower2 << 8) | lower; |
| 130 |
c.y = combined; |
| 131 |
} |
| 132 |
else{ |
| 133 |
c = *((__global uint2*)(src + LOffset + x * 8)); |
| 134 |
} |
| 135 |
|
| 136 |
write_imageui(output, dstCoord, (uint4)(c.x, c.y, 0, 1)); |
| 137 |
} |
| 138 |
|
| 139 |
__kernel void CopyBufferToImage3d6To8Bytes(__global uchar *src, |
| 140 |
__write_only image3d_t output, |
| 141 |
offset_t srcOffset, |
| 142 |
int4 dstOffset, |
| 143 |
coord2_t Pitch) { |
| 144 |
idx_t x = get_global_id(0); |
| 145 |
idx_t y = get_global_id(1); |
| 146 |
idx_t z = get_global_id(2); |
| 147 |
|
| 148 |
int4 dstCoord = (int4)(x, y, z, 0) + dstOffset; |
| 149 |
offset_t LOffset = srcOffset + (y * Pitch.x) + (z * Pitch.y); |
| 150 |
|
| 151 |
uint2 c = (uint2)(0, 0);//*((__global uint2*)(src + LOffset + x * 8)); |
| 152 |
|
| 153 |
uint upper2 = *((__global uchar*)(src + LOffset + x * 6 + 3)); |
| 154 |
uint upper = *((__global uchar*)(src + LOffset + x * 6 + 2)); |
| 155 |
uint lower2 = *((__global uchar*)(src + LOffset + x * 6 + 1)); |
| 156 |
uint lower = *((__global uchar*)(src + LOffset + x * 6)); |
| 157 |
uint combined = (upper2 << 24) | (upper << 16) | (lower2 << 8) | lower; |
| 158 |
c.x = combined; |
| 159 |
|
| 160 |
upper2 = upper = 0; |
| 161 |
lower2 = *((__global uchar*)(src + LOffset + x * 6 + 5)); |
| 162 |
lower = *((__global uchar*)(src + LOffset + x * 6 + 4)); |
| 163 |
combined = ((uint)upper2 << 24) | ((uint)upper << 16) | ((uint)lower2 << 8) | lower; |
| 164 |
c.y = combined; |
| 165 |
|
| 166 |
write_imageui(output, dstCoord, (uint4)(c.x, c.y, 0, 1)); |
| 167 |
} |
| 168 |
|
| 169 |
__kernel void CopyBufferToImage3d16Bytes(__global uchar *src, |
| 170 |
__write_only image3d_t output, |
| 171 |
offset_t srcOffset, |
| 172 |
int4 dstOffset, |
| 173 |
coord2_t Pitch) { |
| 174 |
idx_t x = get_global_id(0); |
| 175 |
idx_t y = get_global_id(1); |
| 176 |
idx_t z = get_global_id(2); |
| 177 |
|
| 178 |
int4 dstCoord = (int4)(x, y, z, 0) + dstOffset; |
| 179 |
offset_t LOffset = srcOffset + (y * Pitch.x) + (z * Pitch.y); |
| 180 |
|
| 181 |
uint4 c = (uint4)(0, 0, 0, 0); |
| 182 |
|
| 183 |
uint upper2 = *((__global uchar*)(src + LOffset + x * 16 + 3)); |
| 184 |
uint upper = *((__global uchar*)(src + LOffset + x * 16 + 2)); |
| 185 |
uint lower2 = *((__global uchar*)(src + LOffset + x * 16 + 1)); |
| 186 |
uint lower = *((__global uchar*)(src + LOffset + x * 16)); |
| 187 |
uint combined = (upper2 << 24) | (upper << 16) | (lower2 << 8) | lower; |
| 188 |
c.x = combined; |
| 189 |
upper2 = *((__global uchar*)(src + LOffset + x * 16 + 7)); |
| 190 |
upper = *((__global uchar*)(src + LOffset + x * 16 + 6)); |
| 191 |
lower2 = *((__global uchar*)(src + LOffset + x * 16 + 5)); |
| 192 |
lower = *((__global uchar*)(src + LOffset + x * 16 + 4)); |
| 193 |
combined = (upper2 << 24) | (upper << 16) | (lower2 << 8) | lower; |
| 194 |
c.y = combined; |
| 195 |
upper2 = *((__global uchar*)(src + LOffset + x * 16 + 11)); |
| 196 |
upper = *((__global uchar*)(src + LOffset + x * 16 + 10)); |
| 197 |
lower2 = *((__global uchar*)(src + LOffset + x * 16 + 9)); |
| 198 |
lower = *((__global uchar*)(src + LOffset + x * 16 + 8)); |
| 199 |
combined = (upper2 << 24) | (upper << 16) | (lower2 << 8) | lower; |
| 200 |
c.z = combined; |
| 201 |
upper2 = *((__global uchar*)(src + LOffset + x * 16 + 15)); |
| 202 |
upper = *((__global uchar*)(src + LOffset + x * 16 + 14)); |
| 203 |
lower2 = *((__global uchar*)(src + LOffset + x * 16 + 13)); |
| 204 |
lower = *((__global uchar*)(src + LOffset + x * 16 + 12)); |
| 205 |
combined = (upper2 << 24) | (upper << 16) | (lower2 << 8) | lower; |
| 206 |
c.w = combined; |
| 207 |
|
| 208 |
write_imageui(output, dstCoord, c); |
| 209 |
} |
| 210 |
|
| 211 |
__kernel void CopyBufferToImage3d16BytesAligned(__global uint4 *src, |
| 212 |
__write_only image3d_t output, |
| 213 |
offset_t srcOffset, |
| 214 |
int4 dstOffset, |
| 215 |
coord2_t Pitch) { |
| 216 |
idx_t x = get_global_id(0); |
| 217 |
idx_t y = get_global_id(1); |
| 218 |
idx_t z = get_global_id(2); |
| 219 |
|
| 220 |
int4 dstCoord = (int4)(x, y, z, 0) + dstOffset; |
| 221 |
offset_t LOffset = srcOffset + (y * Pitch.x) + (z * Pitch.y); |
| 222 |
|
| 223 |
uint4 c = src[(LOffset >> 4) + x]; |
| 224 |
|
| 225 |
write_imageui(output, dstCoord, c); |
| 226 |
} |
| 227 |
)===" |