Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/scene/geometry.cpp
| Show First 20 Lines • Show All 545 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static void update_attribute_element_size(Geometry *geom, | static void update_attribute_element_size(Geometry *geom, | ||||
| Attribute *mattr, | Attribute *mattr, | ||||
| AttributePrimitive prim, | AttributePrimitive prim, | ||||
| size_t *attr_float_size, | size_t *attr_float_size, | ||||
| size_t *attr_float2_size, | size_t *attr_float2_size, | ||||
| size_t *attr_float3_size, | size_t *attr_float3_size, | ||||
| size_t *attr_float4_size, | |||||
| size_t *attr_uchar4_size) | size_t *attr_uchar4_size) | ||||
| { | { | ||||
| if (mattr) { | if (mattr) { | ||||
| size_t size = mattr->element_size(geom, prim); | size_t size = mattr->element_size(geom, prim); | ||||
| if (mattr->element == ATTR_ELEMENT_VOXEL) { | if (mattr->element == ATTR_ELEMENT_VOXEL) { | ||||
| /* pass */ | /* pass */ | ||||
| } | } | ||||
| else if (mattr->element == ATTR_ELEMENT_CORNER_BYTE) { | else if (mattr->element == ATTR_ELEMENT_CORNER_BYTE) { | ||||
| *attr_uchar4_size += size; | *attr_uchar4_size += size; | ||||
| } | } | ||||
| else if (mattr->type == TypeDesc::TypeFloat) { | else if (mattr->type == TypeDesc::TypeFloat) { | ||||
| *attr_float_size += size; | *attr_float_size += size; | ||||
| } | } | ||||
| else if (mattr->type == TypeFloat2) { | else if (mattr->type == TypeFloat2) { | ||||
| *attr_float2_size += size; | *attr_float2_size += size; | ||||
| } | } | ||||
| else if (mattr->type == TypeDesc::TypeMatrix) { | else if (mattr->type == TypeDesc::TypeMatrix) { | ||||
| *attr_float3_size += size * 4; | *attr_float4_size += size * 4; | ||||
| } | |||||
| else if (mattr->type == TypeFloat4 || mattr->type == TypeRGBA) { | |||||
| *attr_float4_size += size; | |||||
| } | } | ||||
| else { | else { | ||||
| *attr_float3_size += size; | *attr_float3_size += size; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void GeometryManager::update_attribute_element_offset(Geometry *geom, | void GeometryManager::update_attribute_element_offset(Geometry *geom, | ||||
| device_vector<float> &attr_float, | device_vector<float> &attr_float, | ||||
| size_t &attr_float_offset, | size_t &attr_float_offset, | ||||
| device_vector<float2> &attr_float2, | device_vector<float2> &attr_float2, | ||||
| size_t &attr_float2_offset, | size_t &attr_float2_offset, | ||||
| device_vector<float4> &attr_float3, | device_vector<packed_float3> &attr_float3, | ||||
| size_t &attr_float3_offset, | size_t &attr_float3_offset, | ||||
| device_vector<float4> &attr_float4, | |||||
| size_t &attr_float4_offset, | |||||
| device_vector<uchar4> &attr_uchar4, | device_vector<uchar4> &attr_uchar4, | ||||
| size_t &attr_uchar4_offset, | size_t &attr_uchar4_offset, | ||||
| Attribute *mattr, | Attribute *mattr, | ||||
| AttributePrimitive prim, | AttributePrimitive prim, | ||||
| TypeDesc &type, | TypeDesc &type, | ||||
| AttributeDescriptor &desc) | AttributeDescriptor &desc) | ||||
| { | { | ||||
| if (mattr) { | if (mattr) { | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | else if (mattr->type == TypeFloat2) { | ||||
| for (size_t k = 0; k < size; k++) { | for (size_t k = 0; k < size; k++) { | ||||
| attr_float2[offset + k] = data[k]; | attr_float2[offset + k] = data[k]; | ||||
| } | } | ||||
| } | } | ||||
| attr_float2_offset += size; | attr_float2_offset += size; | ||||
| } | } | ||||
| else if (mattr->type == TypeDesc::TypeMatrix) { | else if (mattr->type == TypeDesc::TypeMatrix) { | ||||
| Transform *tfm = mattr->data_transform(); | Transform *tfm = mattr->data_transform(); | ||||
| offset = attr_float3_offset; | offset = attr_float4_offset; | ||||
| assert(attr_float3.size() >= offset + size * 3); | assert(attr_float4.size() >= offset + size * 3); | ||||
| if (mattr->modified) { | if (mattr->modified) { | ||||
| for (size_t k = 0; k < size * 3; k++) { | for (size_t k = 0; k < size * 3; k++) { | ||||
| attr_float3[offset + k] = (&tfm->x)[k]; | attr_float4[offset + k] = (&tfm->x)[k]; | ||||
| } | } | ||||
| } | } | ||||
| attr_float3_offset += size * 3; | attr_float4_offset += size * 3; | ||||
| } | } | ||||
| else { | else if (mattr->type == TypeFloat4 || mattr->type == TypeRGBA) { | ||||
| float4 *data = mattr->data_float4(); | float4 *data = mattr->data_float4(); | ||||
| offset = attr_float4_offset; | |||||
| assert(attr_float4.size() >= offset + size); | |||||
| if (mattr->modified) { | |||||
| for (size_t k = 0; k < size; k++) { | |||||
| attr_float4[offset + k] = data[k]; | |||||
| } | |||||
| } | |||||
| attr_float4_offset += size; | |||||
| } | |||||
| else { | |||||
| float3 *data = mattr->data_float3(); | |||||
| offset = attr_float3_offset; | offset = attr_float3_offset; | ||||
| assert(attr_float3.size() >= offset + size); | assert(attr_float3.size() >= offset + size); | ||||
| if (mattr->modified) { | if (mattr->modified) { | ||||
| for (size_t k = 0; k < size; k++) { | for (size_t k = 0; k < size; k++) { | ||||
| attr_float3[offset + k] = data[k]; | attr_float3[offset + k] = data[k]; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | void GeometryManager::device_update_attributes(Device *device, | ||||
| * maps next */ | * maps next */ | ||||
| /* Pre-allocate attributes to avoid arrays re-allocation which would | /* Pre-allocate attributes to avoid arrays re-allocation which would | ||||
| * take 2x of overall attribute memory usage. | * take 2x of overall attribute memory usage. | ||||
| */ | */ | ||||
| size_t attr_float_size = 0; | size_t attr_float_size = 0; | ||||
| size_t attr_float2_size = 0; | size_t attr_float2_size = 0; | ||||
| size_t attr_float3_size = 0; | size_t attr_float3_size = 0; | ||||
| size_t attr_float4_size = 0; | |||||
| size_t attr_uchar4_size = 0; | size_t attr_uchar4_size = 0; | ||||
| for (size_t i = 0; i < scene->geometry.size(); i++) { | for (size_t i = 0; i < scene->geometry.size(); i++) { | ||||
| Geometry *geom = scene->geometry[i]; | Geometry *geom = scene->geometry[i]; | ||||
| AttributeRequestSet &attributes = geom_attributes[i]; | AttributeRequestSet &attributes = geom_attributes[i]; | ||||
| foreach (AttributeRequest &req, attributes.requests) { | foreach (AttributeRequest &req, attributes.requests) { | ||||
| Attribute *attr = geom->attributes.find(req); | Attribute *attr = geom->attributes.find(req); | ||||
| update_attribute_element_size(geom, | update_attribute_element_size(geom, | ||||
| attr, | attr, | ||||
| ATTR_PRIM_GEOMETRY, | ATTR_PRIM_GEOMETRY, | ||||
| &attr_float_size, | &attr_float_size, | ||||
| &attr_float2_size, | &attr_float2_size, | ||||
| &attr_float3_size, | &attr_float3_size, | ||||
| &attr_float4_size, | |||||
| &attr_uchar4_size); | &attr_uchar4_size); | ||||
| if (geom->is_mesh()) { | if (geom->is_mesh()) { | ||||
| Mesh *mesh = static_cast<Mesh *>(geom); | Mesh *mesh = static_cast<Mesh *>(geom); | ||||
| Attribute *subd_attr = mesh->subd_attributes.find(req); | Attribute *subd_attr = mesh->subd_attributes.find(req); | ||||
| update_attribute_element_size(mesh, | update_attribute_element_size(mesh, | ||||
| subd_attr, | subd_attr, | ||||
| ATTR_PRIM_SUBD, | ATTR_PRIM_SUBD, | ||||
| &attr_float_size, | &attr_float_size, | ||||
| &attr_float2_size, | &attr_float2_size, | ||||
| &attr_float3_size, | &attr_float3_size, | ||||
| &attr_float4_size, | |||||
| &attr_uchar4_size); | &attr_uchar4_size); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| for (size_t i = 0; i < scene->objects.size(); i++) { | for (size_t i = 0; i < scene->objects.size(); i++) { | ||||
| Object *object = scene->objects[i]; | Object *object = scene->objects[i]; | ||||
| foreach (Attribute &attr, object_attribute_values[i].attributes) { | foreach (Attribute &attr, object_attribute_values[i].attributes) { | ||||
| update_attribute_element_size(object->geometry, | update_attribute_element_size(object->geometry, | ||||
| &attr, | &attr, | ||||
| ATTR_PRIM_GEOMETRY, | ATTR_PRIM_GEOMETRY, | ||||
| &attr_float_size, | &attr_float_size, | ||||
| &attr_float2_size, | &attr_float2_size, | ||||
| &attr_float3_size, | &attr_float3_size, | ||||
| &attr_float4_size, | |||||
| &attr_uchar4_size); | &attr_uchar4_size); | ||||
| } | } | ||||
| } | } | ||||
| dscene->attributes_float.alloc(attr_float_size); | dscene->attributes_float.alloc(attr_float_size); | ||||
| dscene->attributes_float2.alloc(attr_float2_size); | dscene->attributes_float2.alloc(attr_float2_size); | ||||
| dscene->attributes_float3.alloc(attr_float3_size); | dscene->attributes_float3.alloc(attr_float3_size); | ||||
| dscene->attributes_float4.alloc(attr_float4_size); | |||||
| dscene->attributes_uchar4.alloc(attr_uchar4_size); | dscene->attributes_uchar4.alloc(attr_uchar4_size); | ||||
| /* The order of those flags needs to match that of AttrKernelDataType. */ | /* The order of those flags needs to match that of AttrKernelDataType. */ | ||||
| const bool attributes_need_realloc[4] = { | const bool attributes_need_realloc[AttrKernelDataType::NUM] = { | ||||
| dscene->attributes_float.need_realloc(), | dscene->attributes_float.need_realloc(), | ||||
| dscene->attributes_float2.need_realloc(), | dscene->attributes_float2.need_realloc(), | ||||
| dscene->attributes_float3.need_realloc(), | dscene->attributes_float3.need_realloc(), | ||||
| dscene->attributes_float4.need_realloc(), | |||||
| dscene->attributes_uchar4.need_realloc(), | dscene->attributes_uchar4.need_realloc(), | ||||
| }; | }; | ||||
| size_t attr_float_offset = 0; | size_t attr_float_offset = 0; | ||||
| size_t attr_float2_offset = 0; | size_t attr_float2_offset = 0; | ||||
| size_t attr_float3_offset = 0; | size_t attr_float3_offset = 0; | ||||
| size_t attr_float4_offset = 0; | |||||
| size_t attr_uchar4_offset = 0; | size_t attr_uchar4_offset = 0; | ||||
| /* Fill in attributes. */ | /* Fill in attributes. */ | ||||
| for (size_t i = 0; i < scene->geometry.size(); i++) { | for (size_t i = 0; i < scene->geometry.size(); i++) { | ||||
| Geometry *geom = scene->geometry[i]; | Geometry *geom = scene->geometry[i]; | ||||
| AttributeRequestSet &attributes = geom_attributes[i]; | AttributeRequestSet &attributes = geom_attributes[i]; | ||||
| /* todo: we now store std and name attributes from requests even if | /* todo: we now store std and name attributes from requests even if | ||||
| * they actually refer to the same mesh attributes, optimize */ | * they actually refer to the same mesh attributes, optimize */ | ||||
| foreach (AttributeRequest &req, attributes.requests) { | foreach (AttributeRequest &req, attributes.requests) { | ||||
| Attribute *attr = geom->attributes.find(req); | Attribute *attr = geom->attributes.find(req); | ||||
| if (attr) { | if (attr) { | ||||
| /* force a copy if we need to reallocate all the data */ | /* force a copy if we need to reallocate all the data */ | ||||
| attr->modified |= attributes_need_realloc[Attribute::kernel_type(*attr)]; | attr->modified |= attributes_need_realloc[Attribute::kernel_type(*attr)]; | ||||
| } | } | ||||
| update_attribute_element_offset(geom, | update_attribute_element_offset(geom, | ||||
| dscene->attributes_float, | dscene->attributes_float, | ||||
| attr_float_offset, | attr_float_offset, | ||||
| dscene->attributes_float2, | dscene->attributes_float2, | ||||
| attr_float2_offset, | attr_float2_offset, | ||||
| dscene->attributes_float3, | dscene->attributes_float3, | ||||
| attr_float3_offset, | attr_float3_offset, | ||||
| dscene->attributes_float4, | |||||
| attr_float4_offset, | |||||
| dscene->attributes_uchar4, | dscene->attributes_uchar4, | ||||
| attr_uchar4_offset, | attr_uchar4_offset, | ||||
| attr, | attr, | ||||
| ATTR_PRIM_GEOMETRY, | ATTR_PRIM_GEOMETRY, | ||||
| req.type, | req.type, | ||||
| req.desc); | req.desc); | ||||
| if (geom->is_mesh()) { | if (geom->is_mesh()) { | ||||
| Mesh *mesh = static_cast<Mesh *>(geom); | Mesh *mesh = static_cast<Mesh *>(geom); | ||||
| Attribute *subd_attr = mesh->subd_attributes.find(req); | Attribute *subd_attr = mesh->subd_attributes.find(req); | ||||
| if (subd_attr) { | if (subd_attr) { | ||||
| /* force a copy if we need to reallocate all the data */ | /* force a copy if we need to reallocate all the data */ | ||||
| subd_attr->modified |= attributes_need_realloc[Attribute::kernel_type(*subd_attr)]; | subd_attr->modified |= attributes_need_realloc[Attribute::kernel_type(*subd_attr)]; | ||||
| } | } | ||||
| update_attribute_element_offset(mesh, | update_attribute_element_offset(mesh, | ||||
| dscene->attributes_float, | dscene->attributes_float, | ||||
| attr_float_offset, | attr_float_offset, | ||||
| dscene->attributes_float2, | dscene->attributes_float2, | ||||
| attr_float2_offset, | attr_float2_offset, | ||||
| dscene->attributes_float3, | dscene->attributes_float3, | ||||
| attr_float3_offset, | attr_float3_offset, | ||||
| dscene->attributes_float4, | |||||
| attr_float4_offset, | |||||
| dscene->attributes_uchar4, | dscene->attributes_uchar4, | ||||
| attr_uchar4_offset, | attr_uchar4_offset, | ||||
| subd_attr, | subd_attr, | ||||
| ATTR_PRIM_SUBD, | ATTR_PRIM_SUBD, | ||||
| req.subd_type, | req.subd_type, | ||||
| req.subd_desc); | req.subd_desc); | ||||
| } | } | ||||
| Show All 16 Lines | foreach (AttributeRequest &req, attributes.requests) { | ||||
| update_attribute_element_offset(object->geometry, | update_attribute_element_offset(object->geometry, | ||||
| dscene->attributes_float, | dscene->attributes_float, | ||||
| attr_float_offset, | attr_float_offset, | ||||
| dscene->attributes_float2, | dscene->attributes_float2, | ||||
| attr_float2_offset, | attr_float2_offset, | ||||
| dscene->attributes_float3, | dscene->attributes_float3, | ||||
| attr_float3_offset, | attr_float3_offset, | ||||
| dscene->attributes_float4, | |||||
| attr_float4_offset, | |||||
| dscene->attributes_uchar4, | dscene->attributes_uchar4, | ||||
| attr_uchar4_offset, | attr_uchar4_offset, | ||||
| attr, | attr, | ||||
| ATTR_PRIM_GEOMETRY, | ATTR_PRIM_GEOMETRY, | ||||
| req.type, | req.type, | ||||
| req.desc); | req.desc); | ||||
| /* object attributes don't care about subdivision */ | /* object attributes don't care about subdivision */ | ||||
| Show All 15 Lines | if (progress.get_cancel()) | ||||
| return; | return; | ||||
| /* copy to device */ | /* copy to device */ | ||||
| progress.set_status("Updating Mesh", "Copying Attributes to device"); | progress.set_status("Updating Mesh", "Copying Attributes to device"); | ||||
| dscene->attributes_float.copy_to_device_if_modified(); | dscene->attributes_float.copy_to_device_if_modified(); | ||||
| dscene->attributes_float2.copy_to_device_if_modified(); | dscene->attributes_float2.copy_to_device_if_modified(); | ||||
| dscene->attributes_float3.copy_to_device_if_modified(); | dscene->attributes_float3.copy_to_device_if_modified(); | ||||
| dscene->attributes_float4.copy_to_device_if_modified(); | |||||
| dscene->attributes_uchar4.copy_to_device_if_modified(); | dscene->attributes_uchar4.copy_to_device_if_modified(); | ||||
| if (progress.get_cancel()) | if (progress.get_cancel()) | ||||
| return; | return; | ||||
| /* After mesh attributes and patch tables have been copied to device memory, | /* After mesh attributes and patch tables have been copied to device memory, | ||||
| * we need to update offsets in the objects. */ | * we need to update offsets in the objects. */ | ||||
| scene->object_manager->device_update_mesh_offsets(device, dscene, scene); | scene->object_manager->device_update_mesh_offsets(device, dscene, scene); | ||||
| ▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | foreach (Geometry *geom, scene->geometry) { | ||||
| } | } | ||||
| } | } | ||||
| /* Fill in all the arrays. */ | /* Fill in all the arrays. */ | ||||
| if (tri_size != 0) { | if (tri_size != 0) { | ||||
| /* normals */ | /* normals */ | ||||
| progress.set_status("Updating Mesh", "Computing normals"); | progress.set_status("Updating Mesh", "Computing normals"); | ||||
| float4 *tri_verts = dscene->tri_verts.alloc(tri_size * 3); | packed_float3 *tri_verts = dscene->tri_verts.alloc(tri_size * 3); | ||||
| uint *tri_shader = dscene->tri_shader.alloc(tri_size); | uint *tri_shader = dscene->tri_shader.alloc(tri_size); | ||||
| float4 *vnormal = dscene->tri_vnormal.alloc(vert_size); | packed_float3 *vnormal = dscene->tri_vnormal.alloc(vert_size); | ||||
| uint4 *tri_vindex = dscene->tri_vindex.alloc(tri_size); | uint4 *tri_vindex = dscene->tri_vindex.alloc(tri_size); | ||||
| uint *tri_patch = dscene->tri_patch.alloc(tri_size); | uint *tri_patch = dscene->tri_patch.alloc(tri_size); | ||||
| float2 *tri_patch_uv = dscene->tri_patch_uv.alloc(vert_size); | float2 *tri_patch_uv = dscene->tri_patch_uv.alloc(vert_size); | ||||
| const bool copy_all_data = dscene->tri_shader.need_realloc() || | const bool copy_all_data = dscene->tri_shader.need_realloc() || | ||||
| dscene->tri_vindex.need_realloc() || | dscene->tri_vindex.need_realloc() || | ||||
| dscene->tri_vnormal.need_realloc() || | dscene->tri_vnormal.need_realloc() || | ||||
| dscene->tri_patch.need_realloc() || | dscene->tri_patch.need_realloc() || | ||||
| ▲ Show 20 Lines • Show All 194 Lines • ▼ Show 20 Lines | |||||
| * can decide which device data to free or update. */ | * can decide which device data to free or update. */ | ||||
| enum { | enum { | ||||
| DEVICE_CURVE_DATA_MODIFIED = (1 << 0), | DEVICE_CURVE_DATA_MODIFIED = (1 << 0), | ||||
| DEVICE_MESH_DATA_MODIFIED = (1 << 1), | DEVICE_MESH_DATA_MODIFIED = (1 << 1), | ||||
| ATTR_FLOAT_MODIFIED = (1 << 2), | ATTR_FLOAT_MODIFIED = (1 << 2), | ||||
| ATTR_FLOAT2_MODIFIED = (1 << 3), | ATTR_FLOAT2_MODIFIED = (1 << 3), | ||||
| ATTR_FLOAT3_MODIFIED = (1 << 4), | ATTR_FLOAT3_MODIFIED = (1 << 4), | ||||
| ATTR_UCHAR4_MODIFIED = (1 << 5), | ATTR_FLOAT4_MODIFIED = (1 << 5), | ||||
| ATTR_UCHAR4_MODIFIED = (1 << 6), | |||||
| CURVE_DATA_NEED_REALLOC = (1 << 6), | CURVE_DATA_NEED_REALLOC = (1 << 7), | ||||
| MESH_DATA_NEED_REALLOC = (1 << 7), | MESH_DATA_NEED_REALLOC = (1 << 8), | ||||
| ATTR_FLOAT_NEEDS_REALLOC = (1 << 8), | ATTR_FLOAT_NEEDS_REALLOC = (1 << 9), | ||||
| ATTR_FLOAT2_NEEDS_REALLOC = (1 << 9), | ATTR_FLOAT2_NEEDS_REALLOC = (1 << 10), | ||||
| ATTR_FLOAT3_NEEDS_REALLOC = (1 << 10), | ATTR_FLOAT3_NEEDS_REALLOC = (1 << 11), | ||||
| ATTR_UCHAR4_NEEDS_REALLOC = (1 << 11), | ATTR_FLOAT4_NEEDS_REALLOC = (1 << 12), | ||||
| ATTR_UCHAR4_NEEDS_REALLOC = (1 << 13), | |||||
| ATTRS_NEED_REALLOC = (ATTR_FLOAT_NEEDS_REALLOC | ATTR_FLOAT2_NEEDS_REALLOC | | ATTRS_NEED_REALLOC = (ATTR_FLOAT_NEEDS_REALLOC | ATTR_FLOAT2_NEEDS_REALLOC | | ||||
| ATTR_FLOAT3_NEEDS_REALLOC | ATTR_UCHAR4_NEEDS_REALLOC), | ATTR_FLOAT3_NEEDS_REALLOC | ATTR_FLOAT4_NEEDS_REALLOC | | ||||
| ATTR_UCHAR4_NEEDS_REALLOC), | |||||
| DEVICE_MESH_DATA_NEEDS_REALLOC = (MESH_DATA_NEED_REALLOC | ATTRS_NEED_REALLOC), | DEVICE_MESH_DATA_NEEDS_REALLOC = (MESH_DATA_NEED_REALLOC | ATTRS_NEED_REALLOC), | ||||
| DEVICE_CURVE_DATA_NEEDS_REALLOC = (CURVE_DATA_NEED_REALLOC | ATTRS_NEED_REALLOC), | DEVICE_CURVE_DATA_NEEDS_REALLOC = (CURVE_DATA_NEED_REALLOC | ATTRS_NEED_REALLOC), | ||||
| }; | }; | ||||
| static void update_device_flags_attribute(uint32_t &device_update_flags, | static void update_device_flags_attribute(uint32_t &device_update_flags, | ||||
| const AttributeSet &attributes) | const AttributeSet &attributes) | ||||
| { | { | ||||
| foreach (const Attribute &attr, attributes.attributes) { | foreach (const Attribute &attr, attributes.attributes) { | ||||
| Show All 11 Lines | switch (kernel_type) { | ||||
| case AttrKernelDataType::FLOAT2: { | case AttrKernelDataType::FLOAT2: { | ||||
| device_update_flags |= ATTR_FLOAT2_MODIFIED; | device_update_flags |= ATTR_FLOAT2_MODIFIED; | ||||
| break; | break; | ||||
| } | } | ||||
| case AttrKernelDataType::FLOAT3: { | case AttrKernelDataType::FLOAT3: { | ||||
| device_update_flags |= ATTR_FLOAT3_MODIFIED; | device_update_flags |= ATTR_FLOAT3_MODIFIED; | ||||
| break; | break; | ||||
| } | } | ||||
| case AttrKernelDataType::FLOAT4: { | |||||
| device_update_flags |= ATTR_FLOAT4_MODIFIED; | |||||
| break; | |||||
| } | |||||
| case AttrKernelDataType::UCHAR4: { | case AttrKernelDataType::UCHAR4: { | ||||
| device_update_flags |= ATTR_UCHAR4_MODIFIED; | device_update_flags |= ATTR_UCHAR4_MODIFIED; | ||||
| break; | break; | ||||
| } | } | ||||
| case AttrKernelDataType::NUM: { | |||||
| break; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void update_attribute_realloc_flags(uint32_t &device_update_flags, | static void update_attribute_realloc_flags(uint32_t &device_update_flags, | ||||
| const AttributeSet &attributes) | const AttributeSet &attributes) | ||||
| { | { | ||||
| if (attributes.modified(AttrKernelDataType::FLOAT)) { | if (attributes.modified(AttrKernelDataType::FLOAT)) { | ||||
| device_update_flags |= ATTR_FLOAT_NEEDS_REALLOC; | device_update_flags |= ATTR_FLOAT_NEEDS_REALLOC; | ||||
| } | } | ||||
| if (attributes.modified(AttrKernelDataType::FLOAT2)) { | if (attributes.modified(AttrKernelDataType::FLOAT2)) { | ||||
| device_update_flags |= ATTR_FLOAT2_NEEDS_REALLOC; | device_update_flags |= ATTR_FLOAT2_NEEDS_REALLOC; | ||||
| } | } | ||||
| if (attributes.modified(AttrKernelDataType::FLOAT3)) { | if (attributes.modified(AttrKernelDataType::FLOAT3)) { | ||||
| device_update_flags |= ATTR_FLOAT3_NEEDS_REALLOC; | device_update_flags |= ATTR_FLOAT3_NEEDS_REALLOC; | ||||
| } | } | ||||
| if (attributes.modified(AttrKernelDataType::FLOAT4)) { | |||||
| device_update_flags |= ATTR_FLOAT4_NEEDS_REALLOC; | |||||
| } | |||||
| if (attributes.modified(AttrKernelDataType::UCHAR4)) { | if (attributes.modified(AttrKernelDataType::UCHAR4)) { | ||||
| device_update_flags |= ATTR_UCHAR4_NEEDS_REALLOC; | device_update_flags |= ATTR_UCHAR4_NEEDS_REALLOC; | ||||
| } | } | ||||
| } | } | ||||
| void GeometryManager::device_update_preprocess(Device *device, Scene *scene, Progress &progress) | void GeometryManager::device_update_preprocess(Device *device, Scene *scene, Progress &progress) | ||||
| { | { | ||||
| if (!need_update() && !need_flags_update) { | if (!need_update() && !need_flags_update) { | ||||
| ▲ Show 20 Lines • Show All 185 Lines • ▼ Show 20 Lines | void GeometryManager::device_update_preprocess(Device *device, Scene *scene, Progress &progress) | ||||
| if (device_update_flags & ATTR_FLOAT3_NEEDS_REALLOC) { | if (device_update_flags & ATTR_FLOAT3_NEEDS_REALLOC) { | ||||
| dscene->attributes_map.tag_realloc(); | dscene->attributes_map.tag_realloc(); | ||||
| dscene->attributes_float3.tag_realloc(); | dscene->attributes_float3.tag_realloc(); | ||||
| } | } | ||||
| else if (device_update_flags & ATTR_FLOAT3_MODIFIED) { | else if (device_update_flags & ATTR_FLOAT3_MODIFIED) { | ||||
| dscene->attributes_float3.tag_modified(); | dscene->attributes_float3.tag_modified(); | ||||
| } | } | ||||
| if (device_update_flags & ATTR_FLOAT4_NEEDS_REALLOC) { | |||||
| dscene->attributes_map.tag_realloc(); | |||||
| dscene->attributes_float4.tag_realloc(); | |||||
| } | |||||
| else if (device_update_flags & ATTR_FLOAT4_MODIFIED) { | |||||
| dscene->attributes_float4.tag_modified(); | |||||
| } | |||||
| if (device_update_flags & ATTR_UCHAR4_NEEDS_REALLOC) { | if (device_update_flags & ATTR_UCHAR4_NEEDS_REALLOC) { | ||||
| dscene->attributes_map.tag_realloc(); | dscene->attributes_map.tag_realloc(); | ||||
| dscene->attributes_uchar4.tag_realloc(); | dscene->attributes_uchar4.tag_realloc(); | ||||
| } | } | ||||
| else if (device_update_flags & ATTR_UCHAR4_MODIFIED) { | else if (device_update_flags & ATTR_UCHAR4_MODIFIED) { | ||||
| dscene->attributes_uchar4.tag_modified(); | dscene->attributes_uchar4.tag_modified(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 445 Lines • ▼ Show 20 Lines | void GeometryManager::device_update(Device *device, | ||||
| dscene->curves.clear_modified(); | dscene->curves.clear_modified(); | ||||
| dscene->curve_keys.clear_modified(); | dscene->curve_keys.clear_modified(); | ||||
| dscene->curve_segments.clear_modified(); | dscene->curve_segments.clear_modified(); | ||||
| dscene->patches.clear_modified(); | dscene->patches.clear_modified(); | ||||
| dscene->attributes_map.clear_modified(); | dscene->attributes_map.clear_modified(); | ||||
| dscene->attributes_float.clear_modified(); | dscene->attributes_float.clear_modified(); | ||||
| dscene->attributes_float2.clear_modified(); | dscene->attributes_float2.clear_modified(); | ||||
| dscene->attributes_float3.clear_modified(); | dscene->attributes_float3.clear_modified(); | ||||
| dscene->attributes_float4.clear_modified(); | |||||
| dscene->attributes_uchar4.clear_modified(); | dscene->attributes_uchar4.clear_modified(); | ||||
| } | } | ||||
| void GeometryManager::device_free(Device *device, DeviceScene *dscene, bool force_free) | void GeometryManager::device_free(Device *device, DeviceScene *dscene, bool force_free) | ||||
| { | { | ||||
| dscene->bvh_nodes.free_if_need_realloc(force_free); | dscene->bvh_nodes.free_if_need_realloc(force_free); | ||||
| dscene->bvh_leaf_nodes.free_if_need_realloc(force_free); | dscene->bvh_leaf_nodes.free_if_need_realloc(force_free); | ||||
| dscene->object_node.free_if_need_realloc(force_free); | dscene->object_node.free_if_need_realloc(force_free); | ||||
| Show All 11 Lines | void GeometryManager::device_free(Device *device, DeviceScene *dscene, bool force_free) | ||||
| dscene->curves.free_if_need_realloc(force_free); | dscene->curves.free_if_need_realloc(force_free); | ||||
| dscene->curve_keys.free_if_need_realloc(force_free); | dscene->curve_keys.free_if_need_realloc(force_free); | ||||
| dscene->curve_segments.free_if_need_realloc(force_free); | dscene->curve_segments.free_if_need_realloc(force_free); | ||||
| dscene->patches.free_if_need_realloc(force_free); | dscene->patches.free_if_need_realloc(force_free); | ||||
| dscene->attributes_map.free_if_need_realloc(force_free); | dscene->attributes_map.free_if_need_realloc(force_free); | ||||
| dscene->attributes_float.free_if_need_realloc(force_free); | dscene->attributes_float.free_if_need_realloc(force_free); | ||||
| dscene->attributes_float2.free_if_need_realloc(force_free); | dscene->attributes_float2.free_if_need_realloc(force_free); | ||||
| dscene->attributes_float3.free_if_need_realloc(force_free); | dscene->attributes_float3.free_if_need_realloc(force_free); | ||||
| dscene->attributes_float4.free_if_need_realloc(force_free); | |||||
| dscene->attributes_uchar4.free_if_need_realloc(force_free); | dscene->attributes_uchar4.free_if_need_realloc(force_free); | ||||
| /* Signal for shaders like displacement not to do ray tracing. */ | /* Signal for shaders like displacement not to do ray tracing. */ | ||||
| dscene->data.bvh.bvh_layout = BVH_LAYOUT_NONE; | dscene->data.bvh.bvh_layout = BVH_LAYOUT_NONE; | ||||
| #ifdef WITH_OSL | #ifdef WITH_OSL | ||||
| OSLGlobals *og = (OSLGlobals *)device->get_cpu_osl_memory(); | OSLGlobals *og = (OSLGlobals *)device->get_cpu_osl_memory(); | ||||
| Show All 34 Lines | |||||