[Bf-blender-cvs] [231e545] temp-cycles-microdisplacement: Add AttributeDescriptor

Mai Lavelle noreply at git.blender.org
Sun Jul 10 05:31:19 CEST 2016


Commit: 231e5452caeb30689a8f8ee83f43e81c8d844434
Author: Mai Lavelle
Date:   Fri Jul 1 17:36:27 2016 -0400
Branches: temp-cycles-microdisplacement
https://developer.blender.org/rB231e5452caeb30689a8f8ee83f43e81c8d844434

Add AttributeDescriptor

Adds a descriptor for attributes that can easily be passed around and extended
to contain more data. Will be needed for attributes on subdivision meshes.

===================================================================

M	intern/cycles/kernel/geom/geom_attribute.h
M	intern/cycles/kernel/geom/geom_curve.h
M	intern/cycles/kernel/geom/geom_primitive.h
M	intern/cycles/kernel/geom/geom_triangle.h
M	intern/cycles/kernel/geom/geom_volume.h
M	intern/cycles/kernel/kernel_types.h
M	intern/cycles/kernel/osl/osl_globals.h
M	intern/cycles/kernel/osl/osl_services.cpp
M	intern/cycles/kernel/osl/osl_shader.cpp
M	intern/cycles/kernel/osl/osl_shader.h
M	intern/cycles/kernel/svm/svm_attribute.h
M	intern/cycles/kernel/svm/svm_tex_coord.h
M	intern/cycles/render/attribute.cpp
M	intern/cycles/render/attribute.h
M	intern/cycles/render/mesh.cpp

===================================================================

diff --git a/intern/cycles/kernel/geom/geom_attribute.h b/intern/cycles/kernel/geom/geom_attribute.h
index 4cfae40..a16f135 100644
--- a/intern/cycles/kernel/geom/geom_attribute.h
+++ b/intern/cycles/kernel/geom/geom_attribute.h
@@ -45,10 +45,12 @@ ccl_device_inline uint attribute_primitive_type(KernelGlobals *kg, const ShaderD
 
 /* Find attribute based on ID */
 
-ccl_device_inline int find_attribute(KernelGlobals *kg, const ShaderData *sd, uint id, AttributeElement *elem)
+ccl_device_inline int find_attribute(KernelGlobals *kg, const ShaderData *sd, uint id, AttributeDescriptor *desc)
 {
-	if(ccl_fetch(sd, object) == PRIM_NONE)
+	if(ccl_fetch(sd, object) == PRIM_NONE) {
+		desc->offset = ATTR_STD_NOT_FOUND;
 		return (int)ATTR_STD_NOT_FOUND;
+	}
 
 	/* for SVM, find attribute by unique id */
 	uint attr_offset = ccl_fetch(sd, object)*kernel_data.bvh.attributes_map_stride;
@@ -57,31 +59,37 @@ ccl_device_inline int find_attribute(KernelGlobals *kg, const ShaderData *sd, ui
 	
 	while(attr_map.x != id) {
 		if(UNLIKELY(attr_map.x == ATTR_STD_NONE)) {
+			desc->offset = ATTR_STD_NOT_FOUND;
 			return ATTR_STD_NOT_FOUND;
 		}
 		attr_offset += ATTR_PRIM_TYPES;
 		attr_map = kernel_tex_fetch(__attributes_map, attr_offset);
 	}
 
-	*elem = (AttributeElement)attr_map.y;
+	desc->element = (AttributeElement)attr_map.y;
 	
-	if(ccl_fetch(sd, prim) == PRIM_NONE && (AttributeElement)attr_map.y != ATTR_ELEMENT_MESH)
+	if(ccl_fetch(sd, prim) == PRIM_NONE && (AttributeElement)attr_map.y != ATTR_ELEMENT_MESH) {
+		desc->offset = ATTR_STD_NOT_FOUND;
 		return ATTR_STD_NOT_FOUND;
+	}
 
 	/* return result */
-	return (attr_map.y == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : (int)attr_map.z;
+	desc->offset = (attr_map.y == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : (int)attr_map.z;
+	desc->type = (NodeAttributeType)attr_map.w;
+
+	return desc->offset;
 }
 
 /* Transform matrix attribute on meshes */
 
-ccl_device Transform primitive_attribute_matrix(KernelGlobals *kg, const ShaderData *sd, int offset)
+ccl_device Transform primitive_attribute_matrix(KernelGlobals *kg, const ShaderData *sd, const AttributeDescriptor *desc)
 {
 	Transform tfm;
 
-	tfm.x = kernel_tex_fetch(__attributes_float3, offset + 0);
-	tfm.y = kernel_tex_fetch(__attributes_float3, offset + 1);
-	tfm.z = kernel_tex_fetch(__attributes_float3, offset + 2);
-	tfm.w = kernel_tex_fetch(__attributes_float3, offset + 3);
+	tfm.x = kernel_tex_fetch(__attributes_float3, desc->offset + 0);
+	tfm.y = kernel_tex_fetch(__attributes_float3, desc->offset + 1);
+	tfm.z = kernel_tex_fetch(__attributes_float3, desc->offset + 2);
+	tfm.w = kernel_tex_fetch(__attributes_float3, desc->offset + 3);
 
 	return tfm;
 }
diff --git a/intern/cycles/kernel/geom/geom_curve.h b/intern/cycles/kernel/geom/geom_curve.h
index 8894843..7759f4c 100644
--- a/intern/cycles/kernel/geom/geom_curve.h
+++ b/intern/cycles/kernel/geom/geom_curve.h
@@ -24,23 +24,23 @@ CCL_NAMESPACE_BEGIN
 
 /* Reading attributes on various curve elements */
 
-ccl_device float curve_attribute_float(KernelGlobals *kg, const ShaderData *sd, AttributeElement elem, int offset, float *dx, float *dy)
+ccl_device float curve_attribute_float(KernelGlobals *kg, const ShaderData *sd, const AttributeDescriptor *desc, float *dx, float *dy)
 {
-	if(elem == ATTR_ELEMENT_CURVE) {
+	if(desc->element == ATTR_ELEMENT_CURVE) {
 #ifdef __RAY_DIFFERENTIALS__
 		if(dx) *dx = 0.0f;
 		if(dy) *dy = 0.0f;
 #endif
 
-		return kernel_tex_fetch(__attributes_float, offset + ccl_fetch(sd, prim));
+		return kernel_tex_fetch(__attributes_float, desc->offset + ccl_fetch(sd, prim));
 	}
-	else if(elem == ATTR_ELEMENT_CURVE_KEY || elem == ATTR_ELEMENT_CURVE_KEY_MOTION) {
+	else if(desc->element == ATTR_ELEMENT_CURVE_KEY || desc->element == ATTR_ELEMENT_CURVE_KEY_MOTION) {
 		float4 curvedata = kernel_tex_fetch(__curves, ccl_fetch(sd, prim));
 		int k0 = __float_as_int(curvedata.x) + PRIMITIVE_UNPACK_SEGMENT(ccl_fetch(sd, type));
 		int k1 = k0 + 1;
 
-		float f0 = kernel_tex_fetch(__attributes_float, offset + k0);
-		float f1 = kernel_tex_fetch(__attributes_float, offset + k1);
+		float f0 = kernel_tex_fetch(__attributes_float, desc->offset + k0);
+		float f1 = kernel_tex_fetch(__attributes_float, desc->offset + k1);
 
 #ifdef __RAY_DIFFERENTIALS__
 		if(dx) *dx = ccl_fetch(sd, du).dx*(f1 - f0);
@@ -59,9 +59,9 @@ ccl_device float curve_attribute_float(KernelGlobals *kg, const ShaderData *sd,
 	}
 }
 
-ccl_device float3 curve_attribute_float3(KernelGlobals *kg, const ShaderData *sd, AttributeElement elem, int offset, float3 *dx, float3 *dy)
+ccl_device float3 curve_attribute_float3(KernelGlobals *kg, const ShaderData *sd, const AttributeDescriptor *desc, float3 *dx, float3 *dy)
 {
-	if(elem == ATTR_ELEMENT_CURVE) {
+	if(desc->element == ATTR_ELEMENT_CURVE) {
 		/* idea: we can't derive any useful differentials here, but for tiled
 		 * mipmap image caching it would be useful to avoid reading the highest
 		 * detail level always. maybe a derivative based on the hair density
@@ -71,15 +71,15 @@ ccl_device float3 curve_attribute_float3(KernelGlobals *kg, const ShaderData *sd
 		if(dy) *dy = make_float3(0.0f, 0.0f, 0.0f);
 #endif
 
-		return float4_to_float3(kernel_tex_fetch(__attributes_float3, offset + ccl_fetch(sd, prim)));
+		return float4_to_float3(kernel_tex_fetch(__attributes_float3, desc->offset + ccl_fetch(sd, prim)));
 	}
-	else if(elem == ATTR_ELEMENT_CURVE_KEY || elem == ATTR_ELEMENT_CURVE_KEY_MOTION) {
+	else if(desc->element == ATTR_ELEMENT_CURVE_KEY || desc->element == ATTR_ELEMENT_CURVE_KEY_MOTION) {
 		float4 curvedata = kernel_tex_fetch(__curves, ccl_fetch(sd, prim));
 		int k0 = __float_as_int(curvedata.x) + PRIMITIVE_UNPACK_SEGMENT(ccl_fetch(sd, type));
 		int k1 = k0 + 1;
 
-		float3 f0 = float4_to_float3(kernel_tex_fetch(__attributes_float3, offset + k0));
-		float3 f1 = float4_to_float3(kernel_tex_fetch(__attributes_float3, offset + k1));
+		float3 f0 = float4_to_float3(kernel_tex_fetch(__attributes_float3, desc->offset + k0));
+		float3 f1 = float4_to_float3(kernel_tex_fetch(__attributes_float3, desc->offset + k1));
 
 #ifdef __RAY_DIFFERENTIALS__
 		if(dx) *dx = ccl_fetch(sd, du).dx*(f1 - f0);
diff --git a/intern/cycles/kernel/geom/geom_primitive.h b/intern/cycles/kernel/geom/geom_primitive.h
index 44734d1..0e5359f 100644
--- a/intern/cycles/kernel/geom/geom_primitive.h
+++ b/intern/cycles/kernel/geom/geom_primitive.h
@@ -23,22 +23,22 @@ CCL_NAMESPACE_BEGIN
 
 /* Generic primitive attribute reading functions */
 
-ccl_device float primitive_attribute_float(KernelGlobals *kg, const ShaderData *sd, AttributeElement elem, int offset, float *dx, float *dy)
+ccl_device float primitive_attribute_float(KernelGlobals *kg, const ShaderData *sd, const AttributeDescriptor *desc, float *dx, float *dy)
 {
 	if(ccl_fetch(sd, type) & PRIMITIVE_ALL_TRIANGLE) {
 		if(subd_triangle_patch(kg, sd) == ~0)
-			return triangle_attribute_float(kg, sd, elem, offset, dx, dy);
+			return triangle_attribute_float(kg, sd, desc, dx, dy);
 		else
-			return subd_triangle_attribute_float(kg, sd, elem, offset, dx, dy);
+			return subd_triangle_attribute_float(kg, sd, desc, dx, dy);
 	}
 #ifdef __HAIR__
 	else if(ccl_fetch(sd, type) & PRIMITIVE_ALL_CURVE) {
-		return curve_attribute_float(kg, sd, elem, offset, dx, dy);
+		return curve_attribute_float(kg, sd, desc, dx, dy);
 	}
 #endif
 #ifdef __VOLUME__
-	else if(ccl_fetch(sd, object) != OBJECT_NONE && elem == ATTR_ELEMENT_VOXEL) {
-		return volume_attribute_float(kg, sd, elem, offset, dx, dy);
+	else if(ccl_fetch(sd, object) != OBJECT_NONE && desc->element == ATTR_ELEMENT_VOXEL) {
+		return volume_attribute_float(kg, sd, desc, dx, dy);
 	}
 #endif
 	else {
@@ -48,22 +48,22 @@ ccl_device float primitive_attribute_float(KernelGlobals *kg, const ShaderData *
 	}
 }
 
-ccl_device float3 primitive_attribute_float3(KernelGlobals *kg, const ShaderData *sd, AttributeElement elem, int offset, float3 *dx, float3 *dy)
+ccl_device float3 primitive_attribute_float3(KernelGlobals *kg, const ShaderData *sd, const AttributeDescriptor *desc, float3 *dx, float3 *dy)
 {
 	if(ccl_fetch(sd, type) & PRIMITIVE_ALL_TRIANGLE) {
 		if(subd_triangle_patch(kg, sd) == ~0)
-			return triangle_attribute_float3(kg, sd, elem, offset, dx, dy);
+			return triangle_attribute_float3(kg, sd, desc, dx, dy);
 		else
-			return subd_triangle_attribute_float3(kg, sd, elem, offset, dx, dy);
+			return subd_triangle_attribute_float3(kg, sd, desc, dx, dy);
 	}
 #ifdef __HAIR__
 	else if(ccl_fetch(sd, type) & PRIMITIVE_ALL_CURVE) {
-		return curve_attribute_float3(kg, sd, elem, offset, dx, dy);
+		return curve_attribute_float3(kg, sd, desc, dx, dy);
 	}
 #endif
 #ifdef __VOLUME__
-	else if(ccl_fetch(sd, object) != OBJECT_NONE && elem == ATTR_ELEMENT_VOXEL) {
-		return volume_attribute_float3(kg, sd, elem, offset, dx, dy);
+	else if(ccl_fetch(sd, object) != OBJECT_NONE && desc->element == ATTR_ELEMENT_VOXEL) {
+		return volume_attribute_float3(kg, sd, desc, dx, dy);
 	}
 #endif
 	else {
@@ -77,13 +77,12 @@ ccl_device float3 primitive_attribute_float3(KernelGlobals *kg, const ShaderData
 
 ccl_device float3 primitive_uv(KernelGlobals *kg, ShaderData *sd)
 {
-	AttributeElement elem_uv;
-	int offset_uv = find_attribute(kg, sd, ATTR_STD_UV, &elem_uv);
+	AttributeDescriptor desc;
 
-	if(offset_uv == ATTR_STD_NOT_FOUND)
+	if(find_attribute(kg, sd, ATTR_STD_UV, &desc) == ATTR_STD_NOT_FOUND)
 		return make_float3(0.0f, 0.0f, 0.0f);
 
-	float3 uv = primitive_attribute_float3(kg, sd, elem_uv, offset_uv, NULL, NULL);
+	float3 uv = primitive_attribute_float3(kg, sd, &desc, NULL, NULL);
 	uv.z = 1.0f;
 	return uv;
 }
@@ -93,15 +92,16 @@ ccl_device float3 primitive_uv(KernelGlobals *kg, ShaderData *sd)
 ccl_device bool primitive_ptex(KernelGlobals *kg, ShaderData *sd, float2 *uv, int *face_id)
 {
 	/* storing ptex data as attributes is not memory efficient but simple for tests */
-	AttributeElement elem_face_id, elem_uv;
-	int offset_face_id = find_attribute(kg, sd, ATTR_STD_PTEX_FACE_ID, &elem_face_id);
-	int offset_uv = find_attribute(kg, sd, ATTR_STD_PTEX_UV, &elem_uv);
+	AttributeDescriptor desc_face_id, desc_uv;
 
-	if(offset_face_id == ATTR_STD_NOT_FOUND || offset_uv == ATTR_STD_NOT_FOUND)
+	find

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list