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-05 21:08:56 +0400
committerLukas Toenne <lukas.toenne@googlemail.com>2012-09-05 21:08:56 +0400
commit674d295df3931f3ebbfa5bca549bf000c1abe362 (patch)
tree91ef3ac7c934c19a219560d542c4de69aa06587b /intern/cycles/kernel
parentc1dc3753790038d94dd088923f0bb7f97e5ed6f9 (diff)
Fix for attribute lookup in OSL. This uses a map in the OSL globals instead of the device texture.
Diffstat (limited to 'intern/cycles/kernel')
-rw-r--r--intern/cycles/kernel/kernel_triangle.h42
-rw-r--r--intern/cycles/kernel/kernel_types.h26
2 files changed, 59 insertions, 9 deletions
diff --git a/intern/cycles/kernel/kernel_triangle.h b/intern/cycles/kernel/kernel_triangle.h
index 492800e8aab..60d6d9356ec 100644
--- a/intern/cycles/kernel/kernel_triangle.h
+++ b/intern/cycles/kernel/kernel_triangle.h
@@ -15,9 +15,11 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-
+
#include "kernel_projection.h"
+#include "util_param.h"
+
CCL_NAMESPACE_BEGIN
/* Point on triangle for Moller-Trumbore triangles */
@@ -183,17 +185,39 @@ __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)
{
- /* 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;
+#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)
diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h
index 39e088583c4..738d459df30 100644
--- a/intern/cycles/kernel/kernel_types.h
+++ b/intern/cycles/kernel/kernel_types.h
@@ -22,6 +22,8 @@
#include "kernel_math.h"
#include "svm/svm_types.h"
+#include "util_param.h"
+
#ifndef __KERNEL_GPU__
#define __KERNEL_CPU__
#endif
@@ -368,6 +370,30 @@ typedef enum AttributeStandard {
ATTR_STD_NOT_FOUND = ~0
} AttributeStandard;
+__device ustring attribute_standard_name(AttributeStandard std)
+{
+ if(std == ATTR_STD_VERTEX_NORMAL)
+ return ustring("N");
+ else if(std == ATTR_STD_FACE_NORMAL)
+ return ustring("Ng");
+ else if(std == ATTR_STD_UV)
+ return ustring("uv");
+ else if(std == ATTR_STD_GENERATED)
+ return ustring("generated");
+ else if(std == ATTR_STD_POSITION_UNDEFORMED)
+ return ustring("undeformed");
+ else if(std == ATTR_STD_POSITION_UNDISPLACED)
+ return ustring("undisplaced");
+ else if(std == ATTR_STD_MOTION_PRE)
+ return ustring("motion_pre");
+ else if(std == ATTR_STD_MOTION_POST)
+ return ustring("motion_post");
+ else if(std == ATTR_STD_PARTICLE)
+ return ustring("particle");
+
+ return ustring();
+}
+
/* Closure data */
#define MAX_CLOSURE 8