Merge branch 'master' into blender2.8

This commit is contained in:
Sergey Sharybin
2017-04-05 15:36:55 +02:00
6 changed files with 59 additions and 38 deletions

View File

@@ -67,6 +67,7 @@ void SVMShaderManager::device_update_shader(Scene *scene,
<< "Shader name: " << shader->name << "\n" << "Shader name: " << shader->name << "\n"
<< summary.full_report(); << summary.full_report();
nodes_lock_.lock();
if(shader->use_mis && shader->has_surface_emission) { if(shader->use_mis && shader->has_surface_emission) {
scene->light_manager->need_update = true; scene->light_manager->need_update = true;
} }
@@ -74,7 +75,6 @@ void SVMShaderManager::device_update_shader(Scene *scene,
/* The copy needs to be done inside the lock, if another thread resizes the array /* The copy needs to be done inside the lock, if another thread resizes the array
* while memcpy is running, it'll be copying into possibly invalid/freed ram. * while memcpy is running, it'll be copying into possibly invalid/freed ram.
*/ */
nodes_lock_.lock();
size_t global_nodes_size = global_svm_nodes->size(); size_t global_nodes_size = global_svm_nodes->size();
global_svm_nodes->resize(global_nodes_size + svm_nodes.size()); global_svm_nodes->resize(global_nodes_size + svm_nodes.size());
@@ -393,11 +393,13 @@ void SVMCompiler::add_node(const float4& f)
uint SVMCompiler::attribute(ustring name) uint SVMCompiler::attribute(ustring name)
{ {
thread_scoped_spin_lock lock(attribute_lock_);
return shader_manager->get_attribute_id(name); return shader_manager->get_attribute_id(name);
} }
uint SVMCompiler::attribute(AttributeStandard std) uint SVMCompiler::attribute(AttributeStandard std)
{ {
thread_scoped_spin_lock lock(attribute_lock_);
return shader_manager->get_attribute_id(std); return shader_manager->get_attribute_id(std);
} }

View File

@@ -218,6 +218,8 @@ protected:
int max_stack_use; int max_stack_use;
uint mix_weight_offset; uint mix_weight_offset;
bool compile_failed; bool compile_failed;
thread_spin_lock attribute_lock_;
}; };
CCL_NAMESPACE_END CCL_NAMESPACE_END

View File

@@ -106,6 +106,23 @@ protected:
#endif #endif
}; };
class thread_scoped_spin_lock {
public:
explicit thread_scoped_spin_lock(thread_spin_lock& lock)
: lock_(lock) {
lock_.lock();
}
~thread_scoped_spin_lock() {
lock_.unlock();
}
/* TODO(sergey): Implement manual control over lock/unlock. */
protected:
thread_spin_lock& lock_;
};
CCL_NAMESPACE_END CCL_NAMESPACE_END
#endif /* __UTIL_THREAD_H__ */ #endif /* __UTIL_THREAD_H__ */

View File

@@ -27,42 +27,48 @@ namespace {
std::map<std::string, std::string> MESSAGES; std::map<std::string, std::string> MESSAGES;
bool starts_with(const std::string &string, bool starts_with(const std::string &str,
const std::string &prefix) { const std::string &prefix) {
return prefix.size() <= string.size() && const size_t prefix_length = prefix.length();
string.compare(0, prefix.size(), prefix) == 0; if (prefix_length == 0) {
return true;
}
// TODO(sergey): Could be optimized if we calculate str.length()
// to maximum of prefix_length characters.
if (prefix_length > str.length()) {
return false;
} else {
return str.compare(0, prefix_length, prefix) == 0;
}
} }
std::string ltrim(const std::string &s) { std::string ltrim(const std::string &str) {
std::string result = s; std::string result = str;
result.erase(result.begin(), result.erase(0, result.find_first_not_of(" \t\r\n"));
std::find_if(result.begin(),
result.end(),
std::not1(std::ptr_fun<int, int>(std::isspace))));
return result; return result;
} }
std::string rtrim(const std::string &s) { std::string rtrim(const std::string &str) {
std::string result = s; std::string result = str;
result.erase( result.erase(result.find_last_not_of(" \t\r\n") + 1);
std::find_if(result.rbegin(),
result.rend(),
std::not1(std::ptr_fun<int, int>(std::isspace))).base(),
result.end());
return result; return result;
} }
std::string trim(const std::string &s) { std::string trim(const std::string &str) {
return ltrim(rtrim(s)); std::string result = str;
result.erase(0, result.find_first_not_of(" \t\r\n"));
result.erase(result.find_last_not_of(" \t\r\n") + 1);
return result;
} }
std::string unescape(const std::string &s) { std::string unescape(const std::string &str) {
std::string result; std::string result;
std::string::const_iterator it = s.begin(); const size_t str_length = str.length();
while (it != s.end()) { size_t i = 0;
char current_char = *it++; while (i < str_length) {
if (current_char == '\\' && it != s.end()) { char current_char = str[i++];
char next_char = *it++; if (current_char == '\\' && i < str_length - 1) {
char next_char = str[i++];
if (next_char == '\\') { if (next_char == '\\') {
current_char = '\\'; current_char = '\\';
} else if (next_char == 'n') { } else if (next_char == 'n') {
@@ -76,8 +82,9 @@ std::string unescape(const std::string &s) {
result += current_char; result += current_char;
} }
if (result[0] == '"' && result[result.size() - 1] == '"') { const size_t result_length = result.length();
result = result.substr(1, result.size() - 2); if (result[0] == '"' && result[result_length - 1] == '"') {
result = result.substr(1, result_length - 2);
} }
return result; return result;
@@ -100,6 +107,7 @@ void add(const std::string &msgctxt,
template<typename TKey, typename TValue> template<typename TKey, typename TValue>
void get_keys(std::map<TKey, TValue> map, void get_keys(std::map<TKey, TValue> map,
std::vector<TKey> *keys) { std::vector<TKey> *keys) {
keys->reserve(map.size());
for (typename std::map<TKey, TValue>::iterator it = map.begin(); for (typename std::map<TKey, TValue>::iterator it = map.begin();
it != map.end(); it != map.end();
it++) { it++) {
@@ -136,6 +144,7 @@ std::string generate(void) {
std::sort(keys.begin(), keys.end()); std::sort(keys.begin(), keys.end());
std::vector<Offset> offsets; std::vector<Offset> offsets;
offsets.reserve(keys.size());
std::string ids = "", strs = ""; std::string ids = "", strs = "";
for (std::vector<std::string>::iterator it = keys.begin(); for (std::vector<std::string>::iterator it = keys.begin();
it != keys.end(); it != keys.end();
@@ -160,6 +169,8 @@ std::string generate(void) {
int valuestart = keystart + ids.size(); int valuestart = keystart + ids.size();
std::vector<int> koffsets; std::vector<int> koffsets;
std::vector<int> voffsets; std::vector<int> voffsets;
koffsets.reserve(offsets.size() * 2);
voffsets.reserve(offsets.size() * 2);
// The string table first has the list of keys, then the list of values. // The string table first has the list of keys, then the list of values.
// Each entry has first the size of the string, then the file offset. // Each entry has first the size of the string, then the file offset.
for (std::vector<Offset>::iterator it = offsets.begin(); for (std::vector<Offset>::iterator it = offsets.begin();

View File

@@ -52,14 +52,6 @@
namespace DEG { namespace DEG {
string deg_fcurve_id_name(const FCurve *fcu)
{
char index_buf[32];
// TODO(sergey): Use int-to-string utility or so.
BLI_snprintf(index_buf, sizeof(index_buf), "[%d]", fcu->array_index);
return string(fcu->rna_path) + index_buf;
}
void deg_graph_build_finalize(Depsgraph *graph) void deg_graph_build_finalize(Depsgraph *graph)
{ {
/* Re-tag IDs for update if it was tagged before the relations /* Re-tag IDs for update if it was tagged before the relations

View File

@@ -38,9 +38,6 @@ namespace DEG {
struct Depsgraph; struct Depsgraph;
/* Get unique identifier for FCurves and Drivers */
string deg_fcurve_id_name(const FCurve *fcu);
void deg_graph_build_finalize(struct Depsgraph *graph); void deg_graph_build_finalize(struct Depsgraph *graph);
} // namespace DEG } // namespace DEG