2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 01:50:24 +00:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Constant Globals */
|
|
|
|
|
2017-03-08 10:02:54 +00:00
|
|
|
#ifndef __KERNEL_GLOBALS_H__
|
|
|
|
#define __KERNEL_GLOBALS_H__
|
|
|
|
|
Unlimited number of textures for Cycles
This patch allows for an unlimited number of textures in Cycles where the hardware allows. It replaces a number static arrays with dynamic arrays and changes the way the flat_slot indices are calculated. Eventually, I'd like to get to a point where there are only flat slots left and textures off all kinds are stored in a single array.
Note that the arrays in DeviceScene are changed from containing device_vector<T> objects to device_vector<T>* pointers. Ideally, I'd like to store objects, but dynamic resizing of a std:vector in pre-C++11 calls the copy constructor, which for a good reason is not implemented for device_vector. Once we require C++11 for Cycles builds, we can implement a move constructor for device_vector and store objects again.
The limits for CUDA Fermi hardware still apply.
Reviewers: tod_baudais, InsigMathK, dingto, #cycles
Reviewed By: dingto, #cycles
Subscribers: dingto, smellslikedonkey
Differential Revision: https://developer.blender.org/D2650
2017-04-27 07:34:51 +00:00
|
|
|
#ifdef __KERNEL_CPU__
|
2017-04-28 11:24:09 +00:00
|
|
|
# include "util/util_vector.h"
|
Unlimited number of textures for Cycles
This patch allows for an unlimited number of textures in Cycles where the hardware allows. It replaces a number static arrays with dynamic arrays and changes the way the flat_slot indices are calculated. Eventually, I'd like to get to a point where there are only flat slots left and textures off all kinds are stored in a single array.
Note that the arrays in DeviceScene are changed from containing device_vector<T> objects to device_vector<T>* pointers. Ideally, I'd like to store objects, but dynamic resizing of a std:vector in pre-C++11 calls the copy constructor, which for a good reason is not implemented for device_vector. Once we require C++11 for Cycles builds, we can implement a move constructor for device_vector and store objects again.
The limits for CUDA Fermi hardware still apply.
Reviewers: tod_baudais, InsigMathK, dingto, #cycles
Reviewed By: dingto, #cycles
Subscribers: dingto, smellslikedonkey
Differential Revision: https://developer.blender.org/D2650
2017-04-27 07:34:51 +00:00
|
|
|
#endif
|
|
|
|
|
2017-08-08 11:12:04 +00:00
|
|
|
#ifdef __KERNEL_OPENCL__
|
|
|
|
# include "util/util_atomic.h"
|
|
|
|
#endif
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/* On the CPU, we pass along the struct KernelGlobals to nearly everywhere in
|
2012-06-09 17:22:52 +00:00
|
|
|
* the kernel, to access constant data. These are all stored as "textures", but
|
|
|
|
* these are really just standard arrays. We can't use actually globals because
|
|
|
|
* multiple renders may be running inside the same process. */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-05-20 12:26:01 +00:00
|
|
|
#ifdef __KERNEL_CPU__
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2016-02-12 17:33:43 +00:00
|
|
|
# ifdef __OSL__
|
2012-12-01 19:15:05 +00:00
|
|
|
struct OSLGlobals;
|
|
|
|
struct OSLThreadData;
|
|
|
|
struct OSLShadingSystem;
|
2016-02-12 17:33:43 +00:00
|
|
|
# endif
|
2012-12-01 19:15:05 +00:00
|
|
|
|
2016-05-17 10:30:46 +00:00
|
|
|
struct Intersection;
|
|
|
|
struct VolumeStep;
|
|
|
|
|
2011-05-20 12:26:01 +00:00
|
|
|
typedef struct KernelGlobals {
|
2017-10-06 19:47:41 +00:00
|
|
|
# define KERNEL_TEX(type, name) texture<type> name;
|
2016-02-12 17:33:43 +00:00
|
|
|
# define KERNEL_IMAGE_TEX(type, ttype, name)
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 18:39:14 +00:00
|
|
|
# include "kernel/kernel_textures.h"
|
2011-05-20 12:26:01 +00:00
|
|
|
|
|
|
|
KernelData __data;
|
|
|
|
|
2016-02-12 17:33:43 +00:00
|
|
|
# ifdef __OSL__
|
2011-05-20 12:26:01 +00:00
|
|
|
/* On the CPU, we also have the OSL globals here. Most data structures are shared
|
2012-06-09 17:22:52 +00:00
|
|
|
* with SVM, the difference is in the shaders and object/mesh attributes. */
|
2012-12-01 19:15:05 +00:00
|
|
|
OSLGlobals *osl;
|
|
|
|
OSLShadingSystem *osl_ss;
|
|
|
|
OSLThreadData *osl_tdata;
|
2016-02-12 17:33:43 +00:00
|
|
|
# endif
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2016-05-17 10:30:46 +00:00
|
|
|
/* **** Run-time data **** */
|
|
|
|
|
|
|
|
/* Heap-allocated storage for transparent shadows intersections. */
|
|
|
|
Intersection *transparent_shadow_intersections;
|
|
|
|
|
|
|
|
/* Storage for decoupled volume steps. */
|
|
|
|
VolumeStep *decoupled_volume_steps[2];
|
|
|
|
int decoupled_volume_steps_index;
|
2017-02-14 11:20:48 +00:00
|
|
|
|
|
|
|
/* split kernel */
|
|
|
|
SplitData split_data;
|
|
|
|
SplitParams split_param_data;
|
|
|
|
|
|
|
|
int2 global_size;
|
|
|
|
int2 global_id;
|
2011-11-13 11:40:35 +00:00
|
|
|
} KernelGlobals;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2016-02-12 17:33:43 +00:00
|
|
|
#endif /* __KERNEL_CPU__ */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-05-20 12:26:01 +00:00
|
|
|
/* For CUDA, constant memory textures must be globals, so we can't put them
|
2012-06-09 17:22:52 +00:00
|
|
|
* into a struct. As a result we don't actually use this struct and use actual
|
|
|
|
* globals and simply pass along a NULL pointer everywhere, which we hope gets
|
|
|
|
* optimized out. */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-05-20 12:26:01 +00:00
|
|
|
#ifdef __KERNEL_CUDA__
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-05-20 12:26:01 +00:00
|
|
|
__constant__ KernelData __data;
|
2016-09-21 15:46:25 +00:00
|
|
|
typedef struct KernelGlobals {
|
|
|
|
/* NOTE: Keep the size in sync with SHADOW_STACK_MAX_HITS. */
|
|
|
|
Intersection hits_stack[64];
|
|
|
|
} KernelGlobals;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2017-10-06 19:47:41 +00:00
|
|
|
# define KERNEL_TEX(type, name) const __constant__ __device__ type *name;
|
2016-02-12 17:33:43 +00:00
|
|
|
# define KERNEL_IMAGE_TEX(type, ttype, name) ttype name;
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 18:39:14 +00:00
|
|
|
# include "kernel/kernel_textures.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2016-02-12 17:33:43 +00:00
|
|
|
#endif /* __KERNEL_CUDA__ */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-05-20 12:26:01 +00:00
|
|
|
/* OpenCL */
|
|
|
|
|
|
|
|
#ifdef __KERNEL_OPENCL__
|
|
|
|
|
2017-10-06 19:47:41 +00:00
|
|
|
# define KERNEL_TEX(type, name) \
|
2017-08-08 11:12:04 +00:00
|
|
|
typedef type name##_t;
|
|
|
|
# include "kernel/kernel_textures.h"
|
|
|
|
|
Cycles: OpenCL kernel split
This commit contains all the work related on the AMD megakernel split work
which was mainly done by Varun Sundar, George Kyriazis and Lenny Wang, plus
some help from Sergey Sharybin, Martijn Berger, Thomas Dinges and likely
someone else which we're forgetting to mention.
Currently only AMD cards are enabled for the new split kernel, but it is
possible to force split opencl kernel to be used by setting the following
environment variable: CYCLES_OPENCL_SPLIT_KERNEL_TEST=1.
Not all the features are supported yet, and that being said no motion blur,
camera blur, SSS and volumetrics for now. Also transparent shadows are
disabled on AMD device because of some compiler bug.
This kernel is also only implements regular path tracing and supporting
branched one will take a bit. Branched path tracing is exposed to the
interface still, which is a bit misleading and will be hidden there soon.
More feature will be enabled once they're ported to the split kernel and
tested.
Neither regular CPU nor CUDA has any difference, they're generating the
same exact code, which means no regressions/improvements there.
Based on the research paper:
https://research.nvidia.com/sites/default/files/publications/laine2013hpg_paper.pdf
Here's the documentation:
https://docs.google.com/document/d/1LuXW-CV-sVJkQaEGZlMJ86jZ8FmoPfecaMdR-oiWbUY/edit
Design discussion of the patch:
https://developer.blender.org/T44197
Differential Revision: https://developer.blender.org/D1200
2015-05-09 14:34:30 +00:00
|
|
|
typedef ccl_addr_space struct KernelGlobals {
|
2013-11-15 23:17:10 +00:00
|
|
|
ccl_constant KernelData *data;
|
2017-08-08 11:12:04 +00:00
|
|
|
ccl_global char *buffers[8];
|
2011-05-20 12:26:01 +00:00
|
|
|
|
2017-10-06 19:47:41 +00:00
|
|
|
# define KERNEL_TEX(type, name) \
|
|
|
|
TextureInfo name;
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 18:39:14 +00:00
|
|
|
# include "kernel/kernel_textures.h"
|
2016-01-14 14:58:22 +00:00
|
|
|
|
2016-02-12 17:33:43 +00:00
|
|
|
# ifdef __SPLIT_KERNEL__
|
2017-02-22 13:10:02 +00:00
|
|
|
SplitData split_data;
|
|
|
|
SplitParams split_param_data;
|
2016-02-12 17:33:43 +00:00
|
|
|
# endif
|
2011-04-27 11:58:34 +00:00
|
|
|
} KernelGlobals;
|
2011-05-20 12:26:01 +00:00
|
|
|
|
2017-08-08 11:12:04 +00:00
|
|
|
#define KERNEL_BUFFER_PARAMS \
|
|
|
|
ccl_global char *buffer0, \
|
|
|
|
ccl_global char *buffer1, \
|
|
|
|
ccl_global char *buffer2, \
|
|
|
|
ccl_global char *buffer3, \
|
|
|
|
ccl_global char *buffer4, \
|
|
|
|
ccl_global char *buffer5, \
|
|
|
|
ccl_global char *buffer6, \
|
|
|
|
ccl_global char *buffer7
|
|
|
|
|
|
|
|
#define KERNEL_BUFFER_ARGS buffer0, buffer1, buffer2, buffer3, buffer4, buffer5, buffer6, buffer7
|
|
|
|
|
|
|
|
ccl_device_inline void kernel_set_buffer_pointers(KernelGlobals *kg, KERNEL_BUFFER_PARAMS)
|
|
|
|
{
|
|
|
|
#ifdef __SPLIT_KERNEL__
|
|
|
|
if(ccl_local_id(0) + ccl_local_id(1) == 0)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
kg->buffers[0] = buffer0;
|
|
|
|
kg->buffers[1] = buffer1;
|
|
|
|
kg->buffers[2] = buffer2;
|
|
|
|
kg->buffers[3] = buffer3;
|
|
|
|
kg->buffers[4] = buffer4;
|
|
|
|
kg->buffers[5] = buffer5;
|
|
|
|
kg->buffers[6] = buffer6;
|
|
|
|
kg->buffers[7] = buffer7;
|
|
|
|
}
|
|
|
|
|
|
|
|
# ifdef __SPLIT_KERNEL__
|
|
|
|
ccl_barrier(CCL_LOCAL_MEM_FENCE);
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
|
|
|
|
ccl_device_inline void kernel_set_buffer_info(KernelGlobals *kg)
|
|
|
|
{
|
|
|
|
# ifdef __SPLIT_KERNEL__
|
|
|
|
if(ccl_local_id(0) + ccl_local_id(1) == 0)
|
|
|
|
# endif
|
|
|
|
{
|
2017-10-06 19:47:41 +00:00
|
|
|
ccl_global TextureInfo *info = (ccl_global TextureInfo*)kg->buffers[0];
|
2017-08-08 11:12:04 +00:00
|
|
|
|
2017-10-06 19:47:41 +00:00
|
|
|
# define KERNEL_TEX(type, name) \
|
2017-08-08 11:12:04 +00:00
|
|
|
kg->name = *(info++);
|
|
|
|
# include "kernel/kernel_textures.h"
|
|
|
|
}
|
|
|
|
|
|
|
|
# ifdef __SPLIT_KERNEL__
|
|
|
|
ccl_barrier(CCL_LOCAL_MEM_FENCE);
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
|
2016-02-12 17:33:43 +00:00
|
|
|
#endif /* __KERNEL_OPENCL__ */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-04-01 20:26:52 +00:00
|
|
|
/* Interpolated lookup table access */
|
|
|
|
|
2013-11-15 23:17:10 +00:00
|
|
|
ccl_device float lookup_table_read(KernelGlobals *kg, float x, int offset, int size)
|
2013-04-01 20:26:52 +00:00
|
|
|
{
|
2015-04-27 19:13:03 +00:00
|
|
|
x = saturate(x)*(size-1);
|
2013-04-01 20:26:52 +00:00
|
|
|
|
2013-06-07 16:06:17 +00:00
|
|
|
int index = min(float_to_int(x), size-1);
|
2013-04-01 20:26:52 +00:00
|
|
|
int nindex = min(index+1, size-1);
|
|
|
|
float t = x - index;
|
|
|
|
|
|
|
|
float data0 = kernel_tex_fetch(__lookup_table, index + offset);
|
|
|
|
if(t == 0.0f)
|
|
|
|
return data0;
|
|
|
|
|
|
|
|
float data1 = kernel_tex_fetch(__lookup_table, nindex + offset);
|
|
|
|
return (1.0f - t)*data0 + t*data1;
|
|
|
|
}
|
|
|
|
|
2013-11-15 23:17:10 +00:00
|
|
|
ccl_device float lookup_table_read_2D(KernelGlobals *kg, float x, float y, int offset, int xsize, int ysize)
|
2013-04-01 20:26:52 +00:00
|
|
|
{
|
2015-04-27 19:13:03 +00:00
|
|
|
y = saturate(y)*(ysize-1);
|
2013-04-01 20:26:52 +00:00
|
|
|
|
2013-06-07 16:06:17 +00:00
|
|
|
int index = min(float_to_int(y), ysize-1);
|
2013-04-01 20:26:52 +00:00
|
|
|
int nindex = min(index+1, ysize-1);
|
|
|
|
float t = y - index;
|
|
|
|
|
|
|
|
float data0 = lookup_table_read(kg, x, offset + xsize*index, xsize);
|
|
|
|
if(t == 0.0f)
|
|
|
|
return data0;
|
|
|
|
|
|
|
|
float data1 = lookup_table_read(kg, x, offset + xsize*nindex, xsize);
|
|
|
|
return (1.0f - t)*data0 + t*data1;
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
2017-03-08 10:02:54 +00:00
|
|
|
#endif /* __KERNEL_GLOBALS_H__ */
|