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
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __KERNEL_COMPAT_CPU_H__
|
|
|
|
#define __KERNEL_COMPAT_CPU_H__
|
|
|
|
|
|
|
|
#define __KERNEL_CPU__
|
|
|
|
|
2015-02-12 12:51:02 +00:00
|
|
|
/* Release kernel has too much false-positive maybe-uninitialized warnings,
|
2015-02-02 16:13:41 +00:00
|
|
|
* which makes it possible to miss actual warnings.
|
|
|
|
*/
|
2015-10-25 19:48:28 +00:00
|
|
|
#if (defined(__GNUC__) && !defined(__clang__)) && defined(NDEBUG)
|
2015-02-02 16:13:41 +00:00
|
|
|
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
2015-06-13 14:17:55 +00:00
|
|
|
# pragma GCC diagnostic ignored "-Wuninitialized"
|
2015-02-02 16:13:41 +00:00
|
|
|
#endif
|
|
|
|
|
2015-05-09 14:22:16 +00:00
|
|
|
/* Selective nodes compilation. */
|
|
|
|
#ifndef __NODES_MAX_GROUP__
|
|
|
|
# define __NODES_MAX_GROUP__ NODE_GROUP_LEVEL_MAX
|
|
|
|
#endif
|
|
|
|
#ifndef __NODES_FEATURES__
|
|
|
|
# define __NODES_FEATURES__ NODE_FEATURE_ALL
|
|
|
|
#endif
|
|
|
|
|
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 "util/util_debug.h"
|
|
|
|
#include "util/util_math.h"
|
|
|
|
#include "util/util_simd.h"
|
|
|
|
#include "util/util_half.h"
|
|
|
|
#include "util/util_types.h"
|
|
|
|
#include "util/util_texture.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
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
|
|
|
#define ccl_addr_space
|
|
|
|
|
2017-02-14 11:20:48 +00:00
|
|
|
#define ccl_local_id(d) 0
|
|
|
|
#define ccl_global_id(d) (kg->global_id[d])
|
|
|
|
|
|
|
|
#define ccl_local_size(d) 1
|
|
|
|
#define ccl_global_size(d) (kg->global_size[d])
|
|
|
|
|
|
|
|
#define ccl_group_id(d) ccl_global_id(d)
|
|
|
|
#define ccl_num_groups(d) ccl_global_size(d)
|
|
|
|
|
2014-11-07 08:35:45 +00:00
|
|
|
/* On x86_64, versions of glibc < 2.16 have an issue where expf is
|
|
|
|
* much slower than the double version. This was fixed in glibc 2.16.
|
2014-10-06 07:43:23 +00:00
|
|
|
*/
|
2014-11-07 08:35:45 +00:00
|
|
|
#if !defined(__KERNEL_GPU__) && defined(__x86_64__) && defined(__x86_64__) && \
|
|
|
|
defined(__GNU_LIBRARY__) && defined(__GLIBC__ ) && defined(__GLIBC_MINOR__) && \
|
|
|
|
(__GLIBC__ <= 2 && __GLIBC_MINOR__ < 16)
|
2014-10-07 22:02:46 +00:00
|
|
|
# define expf(x) ((float)exp((double)(x)))
|
2014-10-06 07:43:23 +00:00
|
|
|
#endif
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/* Assertions inside the kernel only work for the CPU device, so we wrap it in
|
2012-06-09 17:22:52 +00:00
|
|
|
* a macro which is empty for other devices */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
#define kernel_assert(cond) assert(cond)
|
|
|
|
|
|
|
|
/* Texture types to be compatible with CUDA textures. These are really just
|
2012-06-09 17:22:52 +00:00
|
|
|
* simple arrays and after inlining fetch hopefully revert to being a simple
|
|
|
|
* pointer lookup. */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
template<typename T> struct texture {
|
2017-10-06 19:47:41 +00:00
|
|
|
ccl_always_inline const T& fetch(int index)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
kernel_assert(index >= 0 && index < width);
|
|
|
|
return data[index];
|
|
|
|
}
|
|
|
|
|
2016-10-12 11:03:15 +00:00
|
|
|
#ifdef __KERNEL_AVX__
|
|
|
|
/* Reads 256 bytes but indexes in blocks of 128 bytes to maintain
|
|
|
|
* compatibility with existing indicies and data structures.
|
|
|
|
*/
|
|
|
|
ccl_always_inline avxf fetch_avxf(const int index)
|
|
|
|
{
|
|
|
|
kernel_assert(index >= 0 && (index+1) < width);
|
2017-03-23 11:41:33 +00:00
|
|
|
ssef *ssef_data = (ssef*)data;
|
|
|
|
ssef *ssef_node_data = &ssef_data[index];
|
|
|
|
return _mm256_loadu_ps((float *)ssef_node_data);
|
2016-10-12 11:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2014-12-25 09:11:37 +00:00
|
|
|
#ifdef __KERNEL_SSE2__
|
2014-06-13 19:13:18 +00:00
|
|
|
ccl_always_inline ssef fetch_ssef(int index)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
kernel_assert(index >= 0 && index < width);
|
2014-06-13 19:13:18 +00:00
|
|
|
return ((ssef*)data)[index];
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2014-06-13 19:13:18 +00:00
|
|
|
ccl_always_inline ssei fetch_ssei(int index)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
kernel_assert(index >= 0 && index < width);
|
2014-06-13 19:13:18 +00:00
|
|
|
return ((ssei*)data)[index];
|
2012-06-09 17:22:52 +00:00
|
|
|
}
|
2014-12-25 09:11:37 +00:00
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
T *data;
|
|
|
|
int width;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Macros to handle different memory storage on different devices */
|
|
|
|
|
|
|
|
#define kernel_tex_fetch(tex, index) (kg->tex.fetch(index))
|
2016-10-12 11:03:15 +00:00
|
|
|
#define kernel_tex_fetch_avxf(tex, index) (kg->tex.fetch_avxf(index))
|
2014-06-13 19:13:18 +00:00
|
|
|
#define kernel_tex_fetch_ssef(tex, index) (kg->tex.fetch_ssef(index))
|
|
|
|
#define kernel_tex_fetch_ssei(tex, index) (kg->tex.fetch_ssei(index))
|
2013-04-01 20:26:43 +00:00
|
|
|
#define kernel_tex_lookup(tex, t, offset, size) (kg->tex.lookup(t, offset, size))
|
2016-05-09 10:51:42 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
#define kernel_data (kg->__data)
|
|
|
|
|
2014-12-16 15:27:44 +00:00
|
|
|
#ifdef __KERNEL_SSE2__
|
|
|
|
typedef vector3<sseb> sse3b;
|
|
|
|
typedef vector3<ssef> sse3f;
|
|
|
|
typedef vector3<ssei> sse3i;
|
2015-02-10 19:20:34 +00:00
|
|
|
|
|
|
|
ccl_device_inline void print_sse3b(const char *label, sse3b& a)
|
|
|
|
{
|
|
|
|
print_sseb(label, a.x);
|
|
|
|
print_sseb(label, a.y);
|
|
|
|
print_sseb(label, a.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
ccl_device_inline void print_sse3f(const char *label, sse3f& a)
|
|
|
|
{
|
|
|
|
print_ssef(label, a.x);
|
|
|
|
print_ssef(label, a.y);
|
|
|
|
print_ssef(label, a.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
ccl_device_inline void print_sse3i(const char *label, sse3i& a)
|
|
|
|
{
|
|
|
|
print_ssei(label, a.x);
|
|
|
|
print_ssei(label, a.y);
|
|
|
|
print_ssei(label, a.z);
|
|
|
|
}
|
|
|
|
|
2014-12-16 15:27:44 +00:00
|
|
|
#endif
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif /* __KERNEL_COMPAT_CPU_H__ */
|
|
|
|
|