From cac3d4d16691d77e8e01f158be07d182e56e9755 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sun, 5 Nov 2017 17:40:36 +0100 Subject: Cycles: fix inefficient attribute map storage, saves 615MB in victor scene. --- intern/cycles/kernel/geom/geom_attribute.h | 11 +++++++++-- intern/cycles/kernel/geom/geom_motion_curve.h | 2 +- intern/cycles/kernel/geom/geom_motion_triangle.h | 2 +- intern/cycles/kernel/kernel_types.h | 3 +-- 4 files changed, 12 insertions(+), 6 deletions(-) (limited to 'intern/cycles/kernel') diff --git a/intern/cycles/kernel/geom/geom_attribute.h b/intern/cycles/kernel/geom/geom_attribute.h index cc62192ef21..18f5c813cc8 100644 --- a/intern/cycles/kernel/geom/geom_attribute.h +++ b/intern/cycles/kernel/geom/geom_attribute.h @@ -51,14 +51,21 @@ ccl_device_inline AttributeDescriptor attribute_not_found() /* Find attribute based on ID */ +ccl_device_inline uint object_attribute_map_offset(KernelGlobals *kg, int object) +{ + int offset = object*OBJECT_SIZE + 11; + float4 f = kernel_tex_fetch(__objects, offset); + return __float_as_uint(f.y); +} + ccl_device_inline AttributeDescriptor find_attribute(KernelGlobals *kg, const ShaderData *sd, uint id) { - if(sd->object == PRIM_NONE) { + if(sd->object == OBJECT_NONE) { return attribute_not_found(); } /* for SVM, find attribute by unique id */ - uint attr_offset = sd->object*kernel_data.bvh.attributes_map_stride; + uint attr_offset = object_attribute_map_offset(kg, sd->object); attr_offset += attribute_primitive_type(kg, sd); uint4 attr_map = kernel_tex_fetch(__attributes_map, attr_offset); diff --git a/intern/cycles/kernel/geom/geom_motion_curve.h b/intern/cycles/kernel/geom/geom_motion_curve.h index 119bdb2f15c..fad29e431ec 100644 --- a/intern/cycles/kernel/geom/geom_motion_curve.h +++ b/intern/cycles/kernel/geom/geom_motion_curve.h @@ -33,7 +33,7 @@ ccl_device_inline int find_attribute_curve_motion(KernelGlobals *kg, int object, * zero iterations and rendering is really slow with motion curves. For until other * areas are speed up it's probably not so crucial to optimize this out. */ - uint attr_offset = object*kernel_data.bvh.attributes_map_stride + ATTR_PRIM_CURVE; + uint attr_offset = object_attribute_map_offset(kg, object) + ATTR_PRIM_CURVE; uint4 attr_map = kernel_tex_fetch(__attributes_map, attr_offset); while(attr_map.x != id) { diff --git a/intern/cycles/kernel/geom/geom_motion_triangle.h b/intern/cycles/kernel/geom/geom_motion_triangle.h index 4e84aa97776..cd28b75c22c 100644 --- a/intern/cycles/kernel/geom/geom_motion_triangle.h +++ b/intern/cycles/kernel/geom/geom_motion_triangle.h @@ -32,7 +32,7 @@ CCL_NAMESPACE_BEGIN ccl_device_inline int find_attribute_motion(KernelGlobals *kg, int object, uint id, AttributeElement *elem) { /* todo: find a better (faster) solution for this, maybe store offset per object */ - uint attr_offset = object*kernel_data.bvh.attributes_map_stride; + uint attr_offset = object_attribute_map_offset(kg, object); uint4 attr_map = kernel_tex_fetch(__attributes_map, attr_offset); while(attr_map.x != id) { diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h index 49ec6d97f28..d1733d8a6e7 100644 --- a/intern/cycles/kernel/kernel_types.h +++ b/intern/cycles/kernel/kernel_types.h @@ -1295,13 +1295,12 @@ static_assert_align(KernelIntegrator, 16); typedef struct KernelBVH { /* root node */ int root; - int attributes_map_stride; int have_motion; int have_curves; int have_instancing; int use_qbvh; int use_bvh_steps; - int pad1; + int pad1, pad2; } KernelBVH; static_assert_align(KernelBVH, 16); -- cgit v1.2.3