Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h
| Show First 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | #define SET_CUBIC_SPLINE_WEIGHTS(u, t) \ | ||||
| } | } | ||||
| static ccl_always_inline float4 read(ushort4 r) | static ccl_always_inline float4 read(ushort4 r) | ||||
| { | { | ||||
| float f = 1.0f / 65535.0f; | float f = 1.0f / 65535.0f; | ||||
| return make_float4(r.x * f, r.y * f, r.z * f, r.w * f); | return make_float4(r.x * f, r.y * f, r.z * f, r.w * f); | ||||
| } | } | ||||
| static ccl_always_inline float4 read(const T *data, int x, int y, int width, int height) | static ccl_always_inline float4 read(const T data, bool srgb) | ||||
| { | |||||
| float4 value = read(data); | |||||
| return srgb ? color_srgb_to_linear_v4(value) : value; | |||||
| } | |||||
| static ccl_always_inline float4 | |||||
| read(const T *data, int x, int y, int width, int height, bool srgb) | |||||
| { | { | ||||
| if (x < 0 || y < 0 || x >= width || y >= height) { | if (x < 0 || y < 0 || x >= width || y >= height) { | ||||
| return make_float4(0.0f, 0.0f, 0.0f, 0.0f); | return make_float4(0.0f, 0.0f, 0.0f, 0.0f); | ||||
| } | } | ||||
| return read(data[y * width + x]); | float4 value = read(data[y * width + x]); | ||||
| return srgb ? color_srgb_to_linear_v4(value) : value; | |||||
| } | } | ||||
| static ccl_always_inline int wrap_periodic(int x, int width) | static ccl_always_inline int wrap_periodic(int x, int width) | ||||
| { | { | ||||
| x %= width; | x %= width; | ||||
| if (x < 0) | if (x < 0) | ||||
| x += width; | x += width; | ||||
| return x; | return x; | ||||
| Show All 34 Lines | switch (info.extension) { | ||||
| case EXTENSION_EXTEND: | case EXTENSION_EXTEND: | ||||
| ix = wrap_clamp(ix, width); | ix = wrap_clamp(ix, width); | ||||
| iy = wrap_clamp(iy, height); | iy = wrap_clamp(iy, height); | ||||
| break; | break; | ||||
| default: | default: | ||||
| kernel_assert(0); | kernel_assert(0); | ||||
| return make_float4(0.0f, 0.0f, 0.0f, 0.0f); | return make_float4(0.0f, 0.0f, 0.0f, 0.0f); | ||||
| } | } | ||||
| return read(data[ix + iy * width]); | return read(data[ix + iy * width], info.compress_as_srgb); | ||||
| } | } | ||||
| static ccl_always_inline float4 interp_linear(const TextureInfo &info, float x, float y) | static ccl_always_inline float4 interp_linear(const TextureInfo &info, float x, float y) | ||||
| { | { | ||||
| const T *data = (const T *)info.data; | const T *data = (const T *)info.data; | ||||
| const int width = info.width; | const int width = info.width; | ||||
| const int height = info.height; | const int height = info.height; | ||||
| int ix, iy, nix, niy; | int ix, iy, nix, niy; | ||||
| Show All 15 Lines | switch (info.extension) { | ||||
| niy = wrap_clamp(iy + 1, height); | niy = wrap_clamp(iy + 1, height); | ||||
| ix = wrap_clamp(ix, width); | ix = wrap_clamp(ix, width); | ||||
| iy = wrap_clamp(iy, height); | iy = wrap_clamp(iy, height); | ||||
| break; | break; | ||||
| default: | default: | ||||
| kernel_assert(0); | kernel_assert(0); | ||||
| return make_float4(0.0f, 0.0f, 0.0f, 0.0f); | return make_float4(0.0f, 0.0f, 0.0f, 0.0f); | ||||
| } | } | ||||
| return (1.0f - ty) * (1.0f - tx) * read(data, ix, iy, width, height) + | const bool srgb = info.compress_as_srgb; | ||||
| (1.0f - ty) * tx * read(data, nix, iy, width, height) + | return (1.0f - ty) * (1.0f - tx) * read(data, ix, iy, width, height, srgb) + | ||||
| ty * (1.0f - tx) * read(data, ix, niy, width, height) + | (1.0f - ty) * tx * read(data, nix, iy, width, height, srgb) + | ||||
| ty * tx * read(data, nix, niy, width, height); | ty * (1.0f - tx) * read(data, ix, niy, width, height, srgb) + | ||||
| ty * tx * read(data, nix, niy, width, height, srgb); | |||||
| } | } | ||||
| static ccl_always_inline float4 interp_cubic(const TextureInfo &info, float x, float y) | static ccl_always_inline float4 interp_cubic(const TextureInfo &info, float x, float y) | ||||
| { | { | ||||
| const T *data = (const T *)info.data; | const T *data = (const T *)info.data; | ||||
| const int width = info.width; | const int width = info.width; | ||||
| const int height = info.height; | const int height = info.height; | ||||
| int ix, iy, nix, niy; | int ix, iy, nix, niy; | ||||
| Show All 31 Lines | switch (info.extension) { | ||||
| break; | break; | ||||
| default: | default: | ||||
| kernel_assert(0); | kernel_assert(0); | ||||
| return make_float4(0.0f, 0.0f, 0.0f, 0.0f); | return make_float4(0.0f, 0.0f, 0.0f, 0.0f); | ||||
| } | } | ||||
| const int xc[4] = {pix, ix, nix, nnix}; | const int xc[4] = {pix, ix, nix, nnix}; | ||||
| const int yc[4] = {piy, iy, niy, nniy}; | const int yc[4] = {piy, iy, niy, nniy}; | ||||
| float u[4], v[4]; | float u[4], v[4]; | ||||
| const bool srgb = info.compress_as_srgb; | |||||
| /* Some helper macro to keep code reasonable size, | /* Some helper macro to keep code reasonable size, | ||||
| * let compiler to inline all the matrix multiplications. | * let compiler to inline all the matrix multiplications. | ||||
| */ | */ | ||||
| #define DATA(x, y) (read(data, xc[x], yc[y], width, height)) | #define DATA(x, y) (read(data, xc[x], yc[y], width, height, srgb)) | ||||
| #define TERM(col) \ | #define TERM(col) \ | ||||
| (v[col] * \ | (v[col] * \ | ||||
| (u[0] * DATA(0, col) + u[1] * DATA(1, col) + u[2] * DATA(2, col) + u[3] * DATA(3, col))) | (u[0] * DATA(0, col) + u[1] * DATA(1, col) + u[2] * DATA(2, col) + u[3] * DATA(3, col))) | ||||
| SET_CUBIC_SPLINE_WEIGHTS(u, tx); | SET_CUBIC_SPLINE_WEIGHTS(u, tx); | ||||
| SET_CUBIC_SPLINE_WEIGHTS(v, ty); | SET_CUBIC_SPLINE_WEIGHTS(v, ty); | ||||
| /* Actual interpolation. */ | /* Actual interpolation. */ | ||||
| ▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | switch (info.extension) { | ||||
| iz = wrap_clamp(iz, depth); | iz = wrap_clamp(iz, depth); | ||||
| break; | break; | ||||
| default: | default: | ||||
| kernel_assert(0); | kernel_assert(0); | ||||
| return make_float4(0.0f, 0.0f, 0.0f, 0.0f); | return make_float4(0.0f, 0.0f, 0.0f, 0.0f); | ||||
| } | } | ||||
| const T *data = (const T *)info.data; | const T *data = (const T *)info.data; | ||||
| return read(data[ix + iy * width + iz * width * height]); | return read(data[ix + iy * width + iz * width * height], info.compress_as_srgb); | ||||
| } | } | ||||
| static ccl_always_inline float4 interp_3d_linear(const TextureInfo &info, | static ccl_always_inline float4 interp_3d_linear(const TextureInfo &info, | ||||
| float x, | float x, | ||||
| float y, | float y, | ||||
| float z) | float z) | ||||
| { | { | ||||
| int width = info.width; | int width = info.width; | ||||
| Show All 31 Lines | switch (info.extension) { | ||||
| iz = wrap_clamp(iz, depth); | iz = wrap_clamp(iz, depth); | ||||
| break; | break; | ||||
| default: | default: | ||||
| kernel_assert(0); | kernel_assert(0); | ||||
| return make_float4(0.0f, 0.0f, 0.0f, 0.0f); | return make_float4(0.0f, 0.0f, 0.0f, 0.0f); | ||||
| } | } | ||||
| const T *data = (const T *)info.data; | const T *data = (const T *)info.data; | ||||
| const bool srgb = info.compress_as_srgb; | |||||
| float4 r; | float4 r; | ||||
| r = (1.0f - tz) * (1.0f - ty) * (1.0f - tx) * | r = (1.0f - tz) * (1.0f - ty) * (1.0f - tx) * | ||||
| read(data[ix + iy * width + iz * width * height]); | read(data[ix + iy * width + iz * width * height], srgb); | ||||
| r += (1.0f - tz) * (1.0f - ty) * tx * read(data[nix + iy * width + iz * width * height]); | r += (1.0f - tz) * (1.0f - ty) * tx * read(data[nix + iy * width + iz * width * height], srgb); | ||||
| r += (1.0f - tz) * ty * (1.0f - tx) * read(data[ix + niy * width + iz * width * height]); | r += (1.0f - tz) * ty * (1.0f - tx) * read(data[ix + niy * width + iz * width * height], srgb); | ||||
| r += (1.0f - tz) * ty * tx * read(data[nix + niy * width + iz * width * height]); | r += (1.0f - tz) * ty * tx * read(data[nix + niy * width + iz * width * height], srgb); | ||||
| r += tz * (1.0f - ty) * (1.0f - tx) * read(data[ix + iy * width + niz * width * height]); | r += tz * (1.0f - ty) * (1.0f - tx) * read(data[ix + iy * width + niz * width * height], srgb); | ||||
| r += tz * (1.0f - ty) * tx * read(data[nix + iy * width + niz * width * height]); | r += tz * (1.0f - ty) * tx * read(data[nix + iy * width + niz * width * height], srgb); | ||||
| r += tz * ty * (1.0f - tx) * read(data[ix + niy * width + niz * width * height]); | r += tz * ty * (1.0f - tx) * read(data[ix + niy * width + niz * width * height], srgb); | ||||
| r += tz * ty * tx * read(data[nix + niy * width + niz * width * height]); | r += tz * ty * tx * read(data[nix + niy * width + niz * width * height], srgb); | ||||
| return r; | return r; | ||||
| } | } | ||||
| /* TODO(sergey): For some unspeakable reason both GCC-6 and Clang-3.9 are | /* TODO(sergey): For some unspeakable reason both GCC-6 and Clang-3.9 are | ||||
| * causing stack overflow issue in this function unless it is inlined. | * causing stack overflow issue in this function unless it is inlined. | ||||
| * | * | ||||
| * Only happens for AVX2 kernel and global __KERNEL_SSE__ vectorization | * Only happens for AVX2 kernel and global __KERNEL_SSE__ vectorization | ||||
| ▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | switch (info.extension) { | ||||
| return make_float4(0.0f, 0.0f, 0.0f, 0.0f); | return make_float4(0.0f, 0.0f, 0.0f, 0.0f); | ||||
| } | } | ||||
| const int xc[4] = {pix, ix, nix, nnix}; | const int xc[4] = {pix, ix, nix, nnix}; | ||||
| const int yc[4] = {width * piy, width * iy, width * niy, width * nniy}; | const int yc[4] = {width * piy, width * iy, width * niy, width * nniy}; | ||||
| const int zc[4] = { | const int zc[4] = { | ||||
| width * height * piz, width * height * iz, width * height * niz, width * height * nniz}; | width * height * piz, width * height * iz, width * height * niz, width * height * nniz}; | ||||
| float u[4], v[4], w[4]; | float u[4], v[4], w[4]; | ||||
| const bool srgb = info.compress_as_srgb; | |||||
| /* Some helper macro to keep code reasonable size, | /* Some helper macro to keep code reasonable size, | ||||
| * let compiler to inline all the matrix multiplications. | * let compiler to inline all the matrix multiplications. | ||||
| */ | */ | ||||
| #define DATA(x, y, z) (read(data[xc[x] + yc[y] + zc[z]])) | #define DATA(x, y, z) (read(data[xc[x] + yc[y] + zc[z]], srgb)) | ||||
| #define COL_TERM(col, row) \ | #define COL_TERM(col, row) \ | ||||
| (v[col] * (u[0] * DATA(0, col, row) + u[1] * DATA(1, col, row) + u[2] * DATA(2, col, row) + \ | (v[col] * (u[0] * DATA(0, col, row) + u[1] * DATA(1, col, row) + u[2] * DATA(2, col, row) + \ | ||||
| u[3] * DATA(3, col, row))) | u[3] * DATA(3, col, row))) | ||||
| #define ROW_TERM(row) \ | #define ROW_TERM(row) \ | ||||
| (w[row] * (COL_TERM(0, row) + COL_TERM(1, row) + COL_TERM(2, row) + COL_TERM(3, row))) | (w[row] * (COL_TERM(0, row) + COL_TERM(1, row) + COL_TERM(2, row) + COL_TERM(3, row))) | ||||
| SET_CUBIC_SPLINE_WEIGHTS(u, tx); | SET_CUBIC_SPLINE_WEIGHTS(u, tx); | ||||
| SET_CUBIC_SPLINE_WEIGHTS(v, ty); | SET_CUBIC_SPLINE_WEIGHTS(v, ty); | ||||
| ▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines | |||||