Code refactor: make texture code more consistent between devices.
[blender-staging.git] / intern / cycles / kernel / kernels / cuda / kernel_cuda_image.h
1 /*
2  * Copyright 2017 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #if __CUDA_ARCH__ >= 300
18
19 /* Kepler */
20
21 ccl_device float4 kernel_tex_image_interp(void *kg, int id, float x, float y)
22 {
23         const TextureInfo& info = kernel_tex_fetch(__texture_info, id);
24         CUtexObject tex = (CUtexObject)info.data;
25
26         /* float4, byte4 and half4 */
27         const int texture_type = kernel_tex_type(id);
28         if(texture_type == IMAGE_DATA_TYPE_FLOAT4 ||
29            texture_type == IMAGE_DATA_TYPE_BYTE4 ||
30            texture_type == IMAGE_DATA_TYPE_HALF4)
31         {
32                 return tex2D<float4>(tex, x, y);
33         }
34         /* float, byte and half */
35         else {
36                 float f = tex2D<float>(tex, x, y);
37                 return make_float4(f, f, f, 1.0f);
38         }
39 }
40
41 ccl_device float4 kernel_tex_image_interp_3d(void *kg, int id, float x, float y, float z)
42 {
43         const TextureInfo& info = kernel_tex_fetch(__texture_info, id);
44         CUtexObject tex = (CUtexObject)info.data;
45
46         const int texture_type = kernel_tex_type(id);
47         if(texture_type == IMAGE_DATA_TYPE_FLOAT4 ||
48            texture_type == IMAGE_DATA_TYPE_BYTE4 ||
49            texture_type == IMAGE_DATA_TYPE_HALF4)
50         {
51                 return tex3D<float4>(tex, x, y, z);
52         }
53         else {
54                 float f = tex3D<float>(tex, x, y, z);
55                 return make_float4(f, f, f, 1.0f);
56         }
57 }
58
59 #else
60
61 /* Fermi */
62
63 ccl_device float4 kernel_tex_image_interp(void *kg, int id, float x, float y)
64 {
65         float4 r;
66         switch(id) {
67                 case 0: r = tex2D(__tex_image_float4_000, x, y); break;
68                 case 8: r = tex2D(__tex_image_float4_008, x, y); break;
69                 case 16: r = tex2D(__tex_image_float4_016, x, y); break;
70                 case 24: r = tex2D(__tex_image_float4_024, x, y); break;
71                 case 32: r = tex2D(__tex_image_float4_032, x, y); break;
72                 case 1: r = tex2D(__tex_image_byte4_001, x, y); break;
73                 case 9: r = tex2D(__tex_image_byte4_009, x, y); break;
74                 case 17: r = tex2D(__tex_image_byte4_017, x, y); break;
75                 case 25: r = tex2D(__tex_image_byte4_025, x, y); break;
76                 case 33: r = tex2D(__tex_image_byte4_033, x, y); break;
77                 case 41: r = tex2D(__tex_image_byte4_041, x, y); break;
78                 case 49: r = tex2D(__tex_image_byte4_049, x, y); break;
79                 case 57: r = tex2D(__tex_image_byte4_057, x, y); break;
80                 case 65: r = tex2D(__tex_image_byte4_065, x, y); break;
81                 case 73: r = tex2D(__tex_image_byte4_073, x, y); break;
82                 case 81: r = tex2D(__tex_image_byte4_081, x, y); break;
83                 case 89: r = tex2D(__tex_image_byte4_089, x, y); break;
84                 case 97: r = tex2D(__tex_image_byte4_097, x, y); break;
85                 case 105: r = tex2D(__tex_image_byte4_105, x, y); break;
86                 case 113: r = tex2D(__tex_image_byte4_113, x, y); break;
87                 case 121: r = tex2D(__tex_image_byte4_121, x, y); break;
88                 case 129: r = tex2D(__tex_image_byte4_129, x, y); break;
89                 case 137: r = tex2D(__tex_image_byte4_137, x, y); break;
90                 case 145: r = tex2D(__tex_image_byte4_145, x, y); break;
91                 case 153: r = tex2D(__tex_image_byte4_153, x, y); break;
92                 case 161: r = tex2D(__tex_image_byte4_161, x, y); break;
93                 case 169: r = tex2D(__tex_image_byte4_169, x, y); break;
94                 case 177: r = tex2D(__tex_image_byte4_177, x, y); break;
95                 case 185: r = tex2D(__tex_image_byte4_185, x, y); break;
96                 case 193: r = tex2D(__tex_image_byte4_193, x, y); break;
97                 case 201: r = tex2D(__tex_image_byte4_201, x, y); break;
98                 case 209: r = tex2D(__tex_image_byte4_209, x, y); break;
99                 case 217: r = tex2D(__tex_image_byte4_217, x, y); break;
100                 case 225: r = tex2D(__tex_image_byte4_225, x, y); break;
101                 case 233: r = tex2D(__tex_image_byte4_233, x, y); break;
102                 case 241: r = tex2D(__tex_image_byte4_241, x, y); break;
103                 case 249: r = tex2D(__tex_image_byte4_249, x, y); break;
104                 case 257: r = tex2D(__tex_image_byte4_257, x, y); break;
105                 case 265: r = tex2D(__tex_image_byte4_265, x, y); break;
106                 case 273: r = tex2D(__tex_image_byte4_273, x, y); break;
107                 case 281: r = tex2D(__tex_image_byte4_281, x, y); break;
108                 case 289: r = tex2D(__tex_image_byte4_289, x, y); break;
109                 case 297: r = tex2D(__tex_image_byte4_297, x, y); break;
110                 case 305: r = tex2D(__tex_image_byte4_305, x, y); break;
111                 case 313: r = tex2D(__tex_image_byte4_313, x, y); break;
112                 case 321: r = tex2D(__tex_image_byte4_321, x, y); break;
113                 case 329: r = tex2D(__tex_image_byte4_329, x, y); break;
114                 case 337: r = tex2D(__tex_image_byte4_337, x, y); break;
115                 case 345: r = tex2D(__tex_image_byte4_345, x, y); break;
116                 case 353: r = tex2D(__tex_image_byte4_353, x, y); break;
117                 case 361: r = tex2D(__tex_image_byte4_361, x, y); break;
118                 case 369: r = tex2D(__tex_image_byte4_369, x, y); break;
119                 case 377: r = tex2D(__tex_image_byte4_377, x, y); break;
120                 case 385: r = tex2D(__tex_image_byte4_385, x, y); break;
121                 case 393: r = tex2D(__tex_image_byte4_393, x, y); break;
122                 case 401: r = tex2D(__tex_image_byte4_401, x, y); break;
123                 case 409: r = tex2D(__tex_image_byte4_409, x, y); break;
124                 case 417: r = tex2D(__tex_image_byte4_417, x, y); break;
125                 case 425: r = tex2D(__tex_image_byte4_425, x, y); break;
126                 case 433: r = tex2D(__tex_image_byte4_433, x, y); break;
127                 case 441: r = tex2D(__tex_image_byte4_441, x, y); break;
128                 case 449: r = tex2D(__tex_image_byte4_449, x, y); break;
129                 case 457: r = tex2D(__tex_image_byte4_457, x, y); break;
130                 case 465: r = tex2D(__tex_image_byte4_465, x, y); break;
131                 case 473: r = tex2D(__tex_image_byte4_473, x, y); break;
132                 case 481: r = tex2D(__tex_image_byte4_481, x, y); break;
133                 case 489: r = tex2D(__tex_image_byte4_489, x, y); break;
134                 case 497: r = tex2D(__tex_image_byte4_497, x, y); break;
135                 case 505: r = tex2D(__tex_image_byte4_505, x, y); break;
136                 case 513: r = tex2D(__tex_image_byte4_513, x, y); break;
137                 case 521: r = tex2D(__tex_image_byte4_521, x, y); break;
138                 case 529: r = tex2D(__tex_image_byte4_529, x, y); break;
139                 case 537: r = tex2D(__tex_image_byte4_537, x, y); break;
140                 case 545: r = tex2D(__tex_image_byte4_545, x, y); break;
141                 case 553: r = tex2D(__tex_image_byte4_553, x, y); break;
142                 case 561: r = tex2D(__tex_image_byte4_561, x, y); break;
143                 case 569: r = tex2D(__tex_image_byte4_569, x, y); break;
144                 case 577: r = tex2D(__tex_image_byte4_577, x, y); break;
145                 case 585: r = tex2D(__tex_image_byte4_585, x, y); break;
146                 case 593: r = tex2D(__tex_image_byte4_593, x, y); break;
147                 case 601: r = tex2D(__tex_image_byte4_601, x, y); break;
148                 case 609: r = tex2D(__tex_image_byte4_609, x, y); break;
149                 case 617: r = tex2D(__tex_image_byte4_617, x, y); break;
150                 case 625: r = tex2D(__tex_image_byte4_625, x, y); break;
151                 case 633: r = tex2D(__tex_image_byte4_633, x, y); break;
152                 case 641: r = tex2D(__tex_image_byte4_641, x, y); break;
153                 case 649: r = tex2D(__tex_image_byte4_649, x, y); break;
154                 case 657: r = tex2D(__tex_image_byte4_657, x, y); break;
155                 case 665: r = tex2D(__tex_image_byte4_665, x, y); break;
156                 default: r = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
157         }
158         return r;
159 }
160
161 ccl_device float4 kernel_tex_image_interp_3d(void *kg, int id, float x, float y, float z)
162 {
163         float4 r;
164         switch(id) {
165                 case 0: r = tex3D(__tex_image_float4_3d_000, x, y, z); break;
166                 case 8: r = tex3D(__tex_image_float4_3d_008, x, y, z); break;
167                 case 16: r = tex3D(__tex_image_float4_3d_016, x, y, z); break;
168                 case 24: r = tex3D(__tex_image_float4_3d_024, x, y, z); break;
169                 case 32: r = tex3D(__tex_image_float4_3d_032, x, y, z); break;
170         }
171         return r;
172 }
173
174 #endif
175