Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Toenne <lukas.toenne@googlemail.com>2012-09-07 15:06:45 +0400
committerLukas Toenne <lukas.toenne@googlemail.com>2012-09-07 15:06:45 +0400
commita9105a7deaccbd98c4e994d8f0f041bef4179bfa (patch)
treefc7fcebc23cdd2f580b32c7c629198497c6531ef
parent8b6046cdad1325a82e0d161fdca0118e62f36b2d (diff)
Fix for Cycles (CUDA) compilation (again ...). Moved the AttributeStandard enum typedef and the attribute_standard_name mapping function to util_attribute/util_types headers, so they can properly be used by kernel and render files alike. This should avoid any std C includes which are not available in CUDA. Thanks to Sergey for help!
-rw-r--r--intern/cycles/kernel/CMakeLists.txt1
-rw-r--r--intern/cycles/kernel/kernel_attribute.h68
-rw-r--r--intern/cycles/kernel/kernel_triangle.h42
-rw-r--r--intern/cycles/kernel/kernel_types.h42
-rw-r--r--intern/cycles/render/attribute.h1
-rw-r--r--intern/cycles/render/mesh.cpp2
-rw-r--r--intern/cycles/render/scene.h1
-rw-r--r--intern/cycles/util/CMakeLists.txt2
-rw-r--r--intern/cycles/util/util_attribute.cpp47
-rw-r--r--intern/cycles/util/util_attribute.h31
-rw-r--r--intern/cycles/util/util_types.h16
11 files changed, 172 insertions, 81 deletions
diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt
index c26954e23b6..b43aca24496 100644
--- a/intern/cycles/kernel/CMakeLists.txt
+++ b/intern/cycles/kernel/CMakeLists.txt
@@ -16,6 +16,7 @@ set(SRC
set(SRC_HEADERS
kernel.h
kernel_accumulate.h
+ kernel_attribute.h
kernel_bvh.h
kernel_camera.h
kernel_compat_cpu.h
diff --git a/intern/cycles/kernel/kernel_attribute.h b/intern/cycles/kernel/kernel_attribute.h
new file mode 100644
index 00000000000..115de2fdbdb
--- /dev/null
+++ b/intern/cycles/kernel/kernel_attribute.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2011, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __KERNEL_ATTRIBUTE_CL__
+#define __KERNEL_ATTRIBUTE_CL__
+
+#include "util_types.h"
+
+#ifdef __OSL__
+#include <string>
+#include "util_attribute.h"
+#endif
+
+CCL_NAMESPACE_BEGIN
+
+/* note: declared in kernel.h, have to add it here because kernel.h is not available */
+bool kernel_osl_use(KernelGlobals *kg);
+
+__device_inline int find_attribute(KernelGlobals *kg, ShaderData *sd, uint id)
+{
+
+#ifdef __OSL__
+ if (kernel_osl_use(kg)) {
+ /* for OSL, a hash map is used to lookup the attribute by name. */
+ OSLGlobals::AttributeMap &attr_map = kg->osl.attribute_map[sd->object];
+ ustring stdname(std::string("std::") + std::string(attribute_standard_name((AttributeStandard)id)));
+ OSLGlobals::AttributeMap::const_iterator it = attr_map.find(stdname);
+ if (it != attr_map.end()) {
+ const OSLGlobals::Attribute &osl_attr = it->second;
+ /* return result */
+ return (osl_attr.elem == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : osl_attr.offset;
+ }
+ else
+ return (int)ATTR_STD_NOT_FOUND;
+ }
+ else
+#endif
+ {
+ /* for SVM, find attribute by unique id */
+ uint attr_offset = sd->object*kernel_data.bvh.attributes_map_stride;
+ uint4 attr_map = kernel_tex_fetch(__attributes_map, attr_offset);
+
+ while(attr_map.x != id)
+ attr_map = kernel_tex_fetch(__attributes_map, ++attr_offset);
+
+ /* return result */
+ return (attr_map.y == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : attr_map.z;
+ }
+}
+
+CCL_NAMESPACE_END
+
+#endif /* __KERNEL_ATTRIBUTE_CL__ */
diff --git a/intern/cycles/kernel/kernel_triangle.h b/intern/cycles/kernel/kernel_triangle.h
index 901034cfac6..f57c59a45eb 100644
--- a/intern/cycles/kernel/kernel_triangle.h
+++ b/intern/cycles/kernel/kernel_triangle.h
@@ -16,6 +16,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#include "kernel_attribute.h"
#include "kernel_projection.h"
CCL_NAMESPACE_BEGIN
@@ -183,48 +184,13 @@ __device float3 triangle_attribute_float3(KernelGlobals *kg, const ShaderData *s
/* motion */
-/* note: declared in kernel.h, have to add it here because kernel.h is not available */
-bool kernel_osl_use(KernelGlobals *kg);
-
-__device int triangle_find_attribute(KernelGlobals *kg, ShaderData *sd, uint id)
-{
-
-#ifdef __OSL__
- if (kernel_osl_use(kg)) {
- /* for OSL, a hash map is used to lookup the attribute by name. */
- OSLGlobals::AttributeMap &attr_map = kg->osl.attribute_map[sd->object];
- ustring stdname = ustring(std::string("std::") + attribute_standard_name((AttributeStandard)id).c_str());
- OSLGlobals::AttributeMap::const_iterator it = attr_map.find(stdname);
- if (it != attr_map.end()) {
- const OSLGlobals::Attribute &osl_attr = it->second;
- /* return result */
- return (osl_attr.elem == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : osl_attr.offset;
- }
- else
- return (int)ATTR_STD_NOT_FOUND;
- }
- else
-#endif
- {
- /* for SVM, find attribute by unique id */
- uint attr_offset = sd->object*kernel_data.bvh.attributes_map_stride;
- uint4 attr_map = kernel_tex_fetch(__attributes_map, attr_offset);
-
- while(attr_map.x != id)
- attr_map = kernel_tex_fetch(__attributes_map, ++attr_offset);
-
- /* return result */
- return (attr_map.y == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : attr_map.z;
- }
-}
-
__device float4 triangle_motion_vector(KernelGlobals *kg, ShaderData *sd)
{
float3 motion_pre = sd->P, motion_post = sd->P;
/* deformation motion */
- int offset_pre = triangle_find_attribute(kg, sd, ATTR_STD_MOTION_PRE);
- int offset_post = triangle_find_attribute(kg, sd, ATTR_STD_MOTION_POST);
+ int offset_pre = find_attribute(kg, sd, ATTR_STD_MOTION_PRE);
+ int offset_post = find_attribute(kg, sd, ATTR_STD_MOTION_POST);
if(offset_pre != ATTR_STD_NOT_FOUND)
motion_pre = triangle_attribute_float3(kg, sd, ATTR_ELEMENT_VERTEX, offset_pre, NULL, NULL);
@@ -283,7 +249,7 @@ __device float4 triangle_motion_vector(KernelGlobals *kg, ShaderData *sd)
__device float3 triangle_uv(KernelGlobals *kg, ShaderData *sd)
{
- int offset_uv = triangle_find_attribute(kg, sd, ATTR_STD_UV);
+ int offset_uv = find_attribute(kg, sd, ATTR_STD_UV);
if(offset_uv == ATTR_STD_NOT_FOUND)
return make_float3(0.0f, 0.0f, 0.0f);
diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h
index 06babe78493..ce21ab994f0 100644
--- a/intern/cycles/kernel/kernel_types.h
+++ b/intern/cycles/kernel/kernel_types.h
@@ -19,8 +19,6 @@
#ifndef __KERNEL_TYPES_H__
#define __KERNEL_TYPES_H__
-#include <string>
-
#include "kernel_math.h"
#include "svm/svm_types.h"
@@ -354,46 +352,6 @@ typedef enum AttributeElement {
ATTR_ELEMENT_NONE
} AttributeElement;
-typedef enum AttributeStandard {
- ATTR_STD_NONE = 0,
- ATTR_STD_VERTEX_NORMAL,
- ATTR_STD_FACE_NORMAL,
- ATTR_STD_UV,
- ATTR_STD_GENERATED,
- ATTR_STD_POSITION_UNDEFORMED,
- ATTR_STD_POSITION_UNDISPLACED,
- ATTR_STD_MOTION_PRE,
- ATTR_STD_MOTION_POST,
- ATTR_STD_PARTICLE,
- ATTR_STD_NUM,
-
- ATTR_STD_NOT_FOUND = ~0
-} AttributeStandard;
-
-__device std::string attribute_standard_name(AttributeStandard std)
-{
- if(std == ATTR_STD_VERTEX_NORMAL)
- return std::string("N");
- else if(std == ATTR_STD_FACE_NORMAL)
- return std::string("Ng");
- else if(std == ATTR_STD_UV)
- return std::string("uv");
- else if(std == ATTR_STD_GENERATED)
- return std::string("generated");
- else if(std == ATTR_STD_POSITION_UNDEFORMED)
- return std::string("undeformed");
- else if(std == ATTR_STD_POSITION_UNDISPLACED)
- return std::string("undisplaced");
- else if(std == ATTR_STD_MOTION_PRE)
- return std::string("motion_pre");
- else if(std == ATTR_STD_MOTION_POST)
- return std::string("motion_post");
- else if(std == ATTR_STD_PARTICLE)
- return std::string("particle");
-
- return std::string();
-}
-
/* Closure data */
#define MAX_CLOSURE 8
diff --git a/intern/cycles/render/attribute.h b/intern/cycles/render/attribute.h
index e95bf42f6ae..d05952edfd7 100644
--- a/intern/cycles/render/attribute.h
+++ b/intern/cycles/render/attribute.h
@@ -21,6 +21,7 @@
#include "kernel_types.h"
+#include "util_attribute.h"
#include "util_list.h"
#include "util_param.h"
#include "util_types.h"
diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp
index 1d9683f25cc..7037e36f313 100644
--- a/intern/cycles/render/mesh.cpp
+++ b/intern/cycles/render/mesh.cpp
@@ -366,7 +366,7 @@ void MeshManager::update_osl_attributes(Device *device, Scene *scene, vector<Att
if(req.std != ATTR_STD_NONE) {
/* if standard attribute, add lookup by std:: name convention */
- ustring stdname = ustring(string("std::") + attribute_standard_name(req.std).c_str());
+ ustring stdname(std::string("std::") + std::string(attribute_standard_name(req.std)));
og->attribute_map[i][stdname] = osl_attr;
}
else if(req.name != ustring()) {
diff --git a/intern/cycles/render/scene.h b/intern/cycles/render/scene.h
index f6c1ef44146..09087fb2970 100644
--- a/intern/cycles/render/scene.h
+++ b/intern/cycles/render/scene.h
@@ -25,6 +25,7 @@
#include "kernel_types.h"
+#include "util_attribute.h"
#include "util_param.h"
#include "util_string.h"
#include "util_thread.h"
diff --git a/intern/cycles/util/CMakeLists.txt b/intern/cycles/util/CMakeLists.txt
index 87bd84b4e0f..ae8403a14a8 100644
--- a/intern/cycles/util/CMakeLists.txt
+++ b/intern/cycles/util/CMakeLists.txt
@@ -6,6 +6,7 @@ set(INC
)
set(SRC
+ util_attribute.cpp
util_cache.cpp
util_cuda.cpp
util_dynlib.cpp
@@ -29,6 +30,7 @@ endif()
set(SRC_HEADERS
util_algorithm.h
util_args.h
+ util_attribute.h
util_boundbox.h
util_cache.h
util_cuda.h
diff --git a/intern/cycles/util/util_attribute.cpp b/intern/cycles/util/util_attribute.cpp
new file mode 100644
index 00000000000..3a1c2b6f332
--- /dev/null
+++ b/intern/cycles/util/util_attribute.cpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2011, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "util_attribute.h"
+
+CCL_NAMESPACE_BEGIN
+
+const char *attribute_standard_name(AttributeStandard std)
+{
+ if(std == ATTR_STD_VERTEX_NORMAL)
+ return "N";
+ else if(std == ATTR_STD_FACE_NORMAL)
+ return "Ng";
+ else if(std == ATTR_STD_UV)
+ return "uv";
+ else if(std == ATTR_STD_GENERATED)
+ return "generated";
+ else if(std == ATTR_STD_POSITION_UNDEFORMED)
+ return "undeformed";
+ else if(std == ATTR_STD_POSITION_UNDISPLACED)
+ return "undisplaced";
+ else if(std == ATTR_STD_MOTION_PRE)
+ return "motion_pre";
+ else if(std == ATTR_STD_MOTION_POST)
+ return "motion_post";
+ else if(std == ATTR_STD_PARTICLE)
+ return "particle";
+
+ return "";
+}
+
+CCL_NAMESPACE_END
diff --git a/intern/cycles/util/util_attribute.h b/intern/cycles/util/util_attribute.h
new file mode 100644
index 00000000000..334864c7f44
--- /dev/null
+++ b/intern/cycles/util/util_attribute.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2011, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __UTIL_ATTRIBUTE_H__
+#define __UTIL_ATTRIBUTE_H__
+
+#include "util_types.h"
+
+CCL_NAMESPACE_BEGIN
+
+const char *attribute_standard_name(AttributeStandard std);
+
+CCL_NAMESPACE_END
+
+#endif /* __UTIL_ATTRIBUTE_H__ */
+
diff --git a/intern/cycles/util/util_types.h b/intern/cycles/util/util_types.h
index 0451d877c45..5c6b9d5bb78 100644
--- a/intern/cycles/util/util_types.h
+++ b/intern/cycles/util/util_types.h
@@ -444,6 +444,22 @@ __device_inline int4 make_int4(const float3& f)
#endif
+typedef enum AttributeStandard {
+ ATTR_STD_NONE = 0,
+ ATTR_STD_VERTEX_NORMAL,
+ ATTR_STD_FACE_NORMAL,
+ ATTR_STD_UV,
+ ATTR_STD_GENERATED,
+ ATTR_STD_POSITION_UNDEFORMED,
+ ATTR_STD_POSITION_UNDISPLACED,
+ ATTR_STD_MOTION_PRE,
+ ATTR_STD_MOTION_POST,
+ ATTR_STD_PARTICLE,
+ ATTR_STD_NUM,
+
+ ATTR_STD_NOT_FOUND = ~0
+} AttributeStandard;
+
CCL_NAMESPACE_END
#endif /* __UTIL_TYPES_H__ */