Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/kernel_compat_cpu.h
| Show First 20 Lines • Show All 310 Lines • ▼ Show 20 Lines | #undef DATA | ||||
| } | } | ||||
| } | } | ||||
| ccl_always_inline float4 interp_3d(float x, float y, float z) | ccl_always_inline float4 interp_3d(float x, float y, float z) | ||||
| { | { | ||||
| return interp_3d_ex(x, y, z, interpolation); | return interp_3d_ex(x, y, z, interpolation); | ||||
| } | } | ||||
| ccl_always_inline float4 interp_3d_ex(float x, float y, float z, | ccl_always_inline float4 interp_3d_ex_closest(float x, float y, float z) | ||||
| int interpolation = INTERPOLATION_LINEAR) | |||||
| { | { | ||||
| if(UNLIKELY(!data)) | int ix, iy, iz; | ||||
| return make_float4(0.0f, 0.0f, 0.0f, 0.0f); | |||||
| int ix, iy, iz, nix, niy, niz; | |||||
| if(interpolation == INTERPOLATION_CLOSEST) { | |||||
| frac(x*(float)width, &ix); | frac(x*(float)width, &ix); | ||||
| frac(y*(float)height, &iy); | frac(y*(float)height, &iy); | ||||
| frac(z*(float)depth, &iz); | frac(z*(float)depth, &iz); | ||||
| switch(extension) { | switch(extension) { | ||||
| case EXTENSION_REPEAT: | case EXTENSION_REPEAT: | ||||
| ix = wrap_periodic(ix, width); | ix = wrap_periodic(ix, width); | ||||
sergey: Indentation. | |||||
| iy = wrap_periodic(iy, height); | iy = wrap_periodic(iy, height); | ||||
| iz = wrap_periodic(iz, depth); | iz = wrap_periodic(iz, depth); | ||||
| break; | break; | ||||
| case EXTENSION_CLIP: | case EXTENSION_CLIP: | ||||
| if(x < 0.0f || y < 0.0f || z < 0.0f || | if(x < 0.0f || y < 0.0f || z < 0.0f || | ||||
| x > 1.0f || y > 1.0f || z > 1.0f) | x > 1.0f || y > 1.0f || z > 1.0f) | ||||
| { | { | ||||
| return make_float4(0.0f, 0.0f, 0.0f, 0.0f); | return make_float4(0.0f, 0.0f, 0.0f, 0.0f); | ||||
| } | } | ||||
| /* Fall through. */ | /* Fall through. */ | ||||
| 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); | ||||
| 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); | ||||
| } | } | ||||
| return read(data[ix + iy*width + iz*width*height]); | return read(data[ix + iy*width + iz*width*height]); | ||||
| } | } | ||||
| else if(interpolation == INTERPOLATION_LINEAR) { | |||||
| ccl_always_inline float4 interp_3d_ex_linear(float x, float y, float z) | |||||
| { | |||||
| int ix, iy, iz; | |||||
| int nix, niy, niz; | |||||
| float tx = frac(x*(float)width - 0.5f, &ix); | float tx = frac(x*(float)width - 0.5f, &ix); | ||||
| float ty = frac(y*(float)height - 0.5f, &iy); | float ty = frac(y*(float)height - 0.5f, &iy); | ||||
| float tz = frac(z*(float)depth - 0.5f, &iz); | float tz = frac(z*(float)depth - 0.5f, &iz); | ||||
| switch(extension) { | switch(extension) { | ||||
| case EXTENSION_REPEAT: | case EXTENSION_REPEAT: | ||||
| ix = wrap_periodic(ix, width); | ix = wrap_periodic(ix, width); | ||||
Done Inline ActionsWe don't use space after keyword in Cycles. Same applies to the cases below. sergey: We don't use space after keyword in Cycles.
Same applies to the cases below. | |||||
| iy = wrap_periodic(iy, height); | iy = wrap_periodic(iy, height); | ||||
Done Inline ActionsIndentation. sergey: Indentation. | |||||
| iz = wrap_periodic(iz, depth); | iz = wrap_periodic(iz, depth); | ||||
| nix = wrap_periodic(ix+1, width); | nix = wrap_periodic(ix+1, width); | ||||
| niy = wrap_periodic(iy+1, height); | niy = wrap_periodic(iy+1, height); | ||||
| niz = wrap_periodic(iz+1, depth); | niz = wrap_periodic(iz+1, depth); | ||||
| break; | break; | ||||
| case EXTENSION_CLIP: | case EXTENSION_CLIP: | ||||
| if(x < 0.0f || y < 0.0f || z < 0.0f || | if(x < 0.0f || y < 0.0f || z < 0.0f || | ||||
| x > 1.0f || y > 1.0f || z > 1.0f) | x > 1.0f || y > 1.0f || z > 1.0f) | ||||
| { | { | ||||
| return make_float4(0.0f, 0.0f, 0.0f, 0.0f); | return make_float4(0.0f, 0.0f, 0.0f, 0.0f); | ||||
| } | } | ||||
| /* Fall through. */ | /* Fall through. */ | ||||
| case EXTENSION_EXTEND: | case EXTENSION_EXTEND: | ||||
| nix = wrap_clamp(ix+1, width); | nix = wrap_clamp(ix+1, width); | ||||
| niy = wrap_clamp(iy+1, height); | niy = wrap_clamp(iy+1, height); | ||||
| niz = wrap_clamp(iz+1, depth); | niz = wrap_clamp(iz+1, depth); | ||||
| ix = wrap_clamp(ix, width); | ix = wrap_clamp(ix, width); | ||||
| iy = wrap_clamp(iy, height); | iy = wrap_clamp(iy, height); | ||||
| 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); | ||||
| } | } | ||||
| float4 r; | float4 r; | ||||
| r = (1.0f - tz)*(1.0f - ty)*(1.0f - tx)*read(data[ix + iy*width + iz*width*height]); | r = (1.0f - tz)*(1.0f - ty)*(1.0f - tx)*read(data[ix + iy*width + iz*width*height]); | ||||
| 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]); | ||||
| 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]); | ||||
| 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]); | ||||
| 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]); | ||||
| 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]); | ||||
| 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]); | ||||
| r += tz*ty*tx*read(data[nix + niy*width + niz*width*height]); | r += tz*ty*tx*read(data[nix + niy*width + niz*width*height]); | ||||
| return r; | return r; | ||||
| } | } | ||||
| else { | |||||
| ccl_never_inline float4 interp_3d_ex_tricubic(float x, float y, float z) | |||||
| { | |||||
| int ix, iy, iz; | |||||
| int nix, niy, niz; | |||||
Not Done Inline Actionsgiven the problem is very msvc specific, what are the thoughts of an ccl_msvc_never_inline ? i mean no need to punish gcc for msvc's weirdness? LazyDodo: given the problem is very msvc specific, what are the thoughts of an ccl_msvc_never_inline ? i… | |||||
Not Done Inline ActionsDon't do that. Otherwise you'll end up with nasty things like ccl_inline_for_cuda_unline_for_gcc_forceinline_for_msvc. This is a big enough function which doesn't make much sense to inline in any of compilers. sergey: Don't do that. Otherwise you'll end up with nasty things like… | |||||
| /* Tricubic b-spline interpolation. */ | /* Tricubic b-spline interpolation. */ | ||||
| const float tx = frac(x*(float)width - 0.5f, &ix); | const float tx = frac(x*(float)width - 0.5f, &ix); | ||||
| const float ty = frac(y*(float)height - 0.5f, &iy); | const float ty = frac(y*(float)height - 0.5f, &iy); | ||||
| const float tz = frac(z*(float)depth - 0.5f, &iz); | const float tz = frac(z*(float)depth - 0.5f, &iz); | ||||
| int pix, piy, piz, nnix, nniy, nniz; | int pix, piy, piz, nnix, nniy, nniz; | ||||
| switch(extension) { | switch(extension) { | ||||
| case EXTENSION_REPEAT: | case EXTENSION_REPEAT: | ||||
| ix = wrap_periodic(ix, width); | ix = wrap_periodic(ix, width); | ||||
| iy = wrap_periodic(iy, height); | iy = wrap_periodic(iy, height); | ||||
| iz = wrap_periodic(iz, depth); | iz = wrap_periodic(iz, depth); | ||||
Not Done Inline ActionsIndentation. sergey: Indentation. | |||||
| pix = wrap_periodic(ix-1, width); | pix = wrap_periodic(ix-1, width); | ||||
| piy = wrap_periodic(iy-1, height); | piy = wrap_periodic(iy-1, height); | ||||
| piz = wrap_periodic(iz-1, depth); | piz = wrap_periodic(iz-1, depth); | ||||
| nix = wrap_periodic(ix+1, width); | nix = wrap_periodic(ix+1, width); | ||||
| niy = wrap_periodic(iy+1, height); | niy = wrap_periodic(iy+1, height); | ||||
| niz = wrap_periodic(iz+1, depth); | niz = wrap_periodic(iz+1, depth); | ||||
| nnix = wrap_periodic(ix+2, width); | nnix = wrap_periodic(ix+2, width); | ||||
| nniy = wrap_periodic(iy+2, height); | nniy = wrap_periodic(iy+2, height); | ||||
| nniz = wrap_periodic(iz+2, depth); | nniz = wrap_periodic(iz+2, depth); | ||||
| break; | break; | ||||
| case EXTENSION_CLIP: | case EXTENSION_CLIP: | ||||
| if(x < 0.0f || y < 0.0f || z < 0.0f || | if(x < 0.0f || y < 0.0f || z < 0.0f || | ||||
| x > 1.0f || y > 1.0f || z > 1.0f) | x > 1.0f || y > 1.0f || z > 1.0f) | ||||
| { | { | ||||
| return make_float4(0.0f, 0.0f, 0.0f, 0.0f); | return make_float4(0.0f, 0.0f, 0.0f, 0.0f); | ||||
| } | } | ||||
Not Done Inline ActionsIndentation (x was aligned to the same column in original code). sergey: Indentation (`x` was aligned to the same column in original code). | |||||
| /* Fall through. */ | /* Fall through. */ | ||||
| case EXTENSION_EXTEND: | case EXTENSION_EXTEND: | ||||
| pix = wrap_clamp(ix-1, width); | pix = wrap_clamp(ix-1, width); | ||||
| piy = wrap_clamp(iy-1, height); | piy = wrap_clamp(iy-1, height); | ||||
| piz = wrap_clamp(iz-1, depth); | piz = wrap_clamp(iz-1, depth); | ||||
| nix = wrap_clamp(ix+1, width); | nix = wrap_clamp(ix+1, width); | ||||
| niy = wrap_clamp(iy+1, height); | niy = wrap_clamp(iy+1, height); | ||||
| niz = wrap_clamp(iz+1, depth); | niz = wrap_clamp(iz+1, depth); | ||||
| nnix = wrap_clamp(ix+2, width); | nnix = wrap_clamp(ix+2, width); | ||||
| nniy = wrap_clamp(iy+2, height); | nniy = wrap_clamp(iy+2, height); | ||||
| nniz = wrap_clamp(iz+2, depth); | nniz = wrap_clamp(iz+2, depth); | ||||
| ix = wrap_clamp(ix, width); | ix = wrap_clamp(ix, width); | ||||
| iy = wrap_clamp(iy, height); | iy = wrap_clamp(iy, height); | ||||
| 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 int xc[4] = {pix, ix, nix, nnix}; | const int xc[4] = {pix, ix, nix, nnix}; | ||||
| const int yc[4] = {width * piy, | const int yc[4] = {width * piy, | ||||
| width * iy, | width * iy, | ||||
| width * niy, | width * niy, | ||||
| width * nniy}; | width * nniy}; | ||||
| const int zc[4] = {width * height * piz, | const int zc[4] = {width * height * piz, | ||||
Not Done Inline ActionsIndentation and space around {}. It used to be const int yc[4] = {width * piy,
width * iy,
width * niy,
width * nniy};sergey: Indentation and space around {}. It used to be
const int yc[4] = {width * piy… | |||||
| width * height * iz, | width * height * iz, | ||||
| width * height * niz, | width * height * niz, | ||||
| width * height * nniz}; | width * height * nniz}; | ||||
| float u[4], v[4], w[4]; | float u[4], v[4], w[4]; | ||||
| /* 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]])) | ||||
| #define COL_TERM(col, row) \ | #define COL_TERM(col, row) \ | ||||
Not Done Inline ActionsIndentation: /* Note thew asterisk are at the same column. * (they became at the beginning of the line). */ sergey: Indentation:
/* Note thew asterisk are at the same column.
* (they became at the… | |||||
| (v[col] * (u[0] * DATA(0, col, row) + \ | (v[col] * (u[0] * DATA(0, col, row) + \ | ||||
| u[1] * DATA(1, col, row) + \ | u[1] * DATA(1, col, row) + \ | ||||
| u[2] * DATA(2, 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) + \ | (w[row] * (COL_TERM(0, row) + \ | ||||
| COL_TERM(1, row) + \ | COL_TERM(1, row) + \ | ||||
| COL_TERM(2, row) + \ | COL_TERM(2, row) + \ | ||||
| COL_TERM(3, 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); | ||||
| SET_CUBIC_SPLINE_WEIGHTS(w, tz); | SET_CUBIC_SPLINE_WEIGHTS(w, tz); | ||||
| /* Actual interpolation. */ | /* Actual interpolation. */ | ||||
| return ROW_TERM(0) + ROW_TERM(1) + ROW_TERM(2) + ROW_TERM(3); | return ROW_TERM(0) + ROW_TERM(1) + ROW_TERM(2) + ROW_TERM(3); | ||||
| #undef COL_TERM | #undef COL_TERM | ||||
| #undef ROW_TERM | #undef ROW_TERM | ||||
Done Inline ActionsSeems to be remained from some experiments. sergey: Seems to be remained from some experiments. | |||||
| #undef DATA | #undef DATA | ||||
| } | } | ||||
| ccl_always_inline float4 interp_3d_ex(float x, float y, float z, | |||||
| int interpolation = INTERPOLATION_LINEAR) | |||||
| { | |||||
| if(UNLIKELY(!data)) | |||||
| return make_float4(0.0f, 0.0f, 0.0f, 0.0f); | |||||
| switch(interpolation) { | |||||
| case INTERPOLATION_CLOSEST: | |||||
| return interp_3d_ex_closest(x, y, z); | |||||
| case INTERPOLATION_LINEAR: | |||||
| return interp_3d_ex_linear(x, y, z); | |||||
| default: | |||||
| return interp_3d_ex_tricubic(x, y, z); | |||||
| } | |||||
| } | } | ||||
| ccl_always_inline void dimensions_set(int width_, int height_, int depth_) | ccl_always_inline void dimensions_set(int width_, int height_, int depth_) | ||||
| { | { | ||||
| width = width_; | width = width_; | ||||
| height = height_; | height = height_; | ||||
| depth = depth_; | depth = depth_; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines | |||||
Indentation.