diff options
5 files changed, 31 insertions, 63 deletions
diff --git a/source/blender/blenkernel/BKE_cryptomatte.h b/source/blender/blenkernel/BKE_cryptomatte.h index 2b5a6a2044b..4b62c795a5a 100644 --- a/source/blender/blenkernel/BKE_cryptomatte.h +++ b/source/blender/blenkernel/BKE_cryptomatte.h @@ -38,7 +38,6 @@ struct Object; struct RenderResult; struct CryptomatteSession *BKE_cryptomatte_init(void); -void BKE_cryptomatte_finish(struct CryptomatteSession *session); void BKE_cryptomatte_free(struct CryptomatteSession *session); uint32_t BKE_cryptomatte_hash(const char *name, int name_len); diff --git a/source/blender/blenkernel/intern/cryptomatte.cc b/source/blender/blenkernel/intern/cryptomatte.cc index db83547fe36..d2a3f6eebbe 100644 --- a/source/blender/blenkernel/intern/cryptomatte.cc +++ b/source/blender/blenkernel/intern/cryptomatte.cc @@ -35,7 +35,7 @@ #include "BLI_dynstr.h" #include "BLI_hash_mm3.h" #include "BLI_listbase.h" -#include "BLI_set.hh" +#include "BLI_map.hh" #include "BLI_string.h" #include "MEM_guardedalloc.h" @@ -47,54 +47,47 @@ #include <string> #include <string_view> -enum class CryptomatteLayerState { - EMPTY, - FILLED, - CLOSED, -}; - struct CryptomatteLayer { - CryptomatteLayerState state = CryptomatteLayerState::EMPTY; - blender::Set<std::string> names; - std::stringstream manifest; + blender::Map<std::string, std::string> hashes; #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("cryptomatte:CryptomatteLayer") #endif - - void add_hash(std::string name, uint32_t cryptomatte_hash) + std::string encode_hash(uint32_t cryptomatte_hash) { - BLI_assert(state != CryptomatteLayerState::CLOSED); - const bool first_item = names.is_empty(); - if (!names.add(name)) { - return; - } + std::stringstream encoded; + encoded << std::setfill('0') << std::setw(sizeof(uint32_t) * 2) << std::hex + << cryptomatte_hash; + return encoded.str(); + } - if (first_item) { - state = CryptomatteLayerState::FILLED; - manifest << "{"; - } - else { - manifest << ","; - } - manifest << quoted(name) << ":\""; - manifest << std::setfill('0') << std::setw(sizeof(uint32_t) * 2) << std::hex - << cryptomatte_hash; - manifest << "\""; + void add_hash(blender::StringRef name, uint32_t cryptomatte_hash) + { + hashes.add_overwrite(name, encode_hash(cryptomatte_hash)); } - void close_manifest() + void add_encoded_hash(blender::StringRef name, std::string &cryptomatte_encoded_hash) { - BLI_assert(state != CryptomatteLayerState::CLOSED); - if (state == CryptomatteLayerState::FILLED) { - manifest << "}"; - } - state = CryptomatteLayerState::CLOSED; + hashes.add_overwrite(name, cryptomatte_encoded_hash); } - std::string manifest_get_string() + std::string manifest() { - BLI_assert(state == CryptomatteLayerState::CLOSED); + std::stringstream manifest; + + bool is_first = true; + const blender::Map<std::string, std::string> &const_map = hashes; + manifest << "{"; + for (blender::Map<std::string, std::string>::Item item : const_map.items()) { + if (is_first) { + is_first = false; + } + else { + manifest << ","; + } + manifest << quoted(item.key) << ":\"" << item.value << "\""; + } + manifest << "}"; return manifest.str(); } }; @@ -107,13 +100,6 @@ struct CryptomatteSession { #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("cryptomatte:CryptomatteSession") #endif - - void finish() - { - objects.close_manifest(); - materials.close_manifest(); - assets.close_manifest(); - } }; CryptomatteSession *BKE_cryptomatte_init(void) @@ -122,12 +108,6 @@ CryptomatteSession *BKE_cryptomatte_init(void) return session; } -void BKE_cryptomatte_finish(CryptomatteSession *session) -{ - BLI_assert(session != nullptr); - session->finish(); -} - void BKE_cryptomatte_free(CryptomatteSession *session) { BLI_assert(session != nullptr); @@ -147,7 +127,7 @@ static uint32_t cryptomatte_hash(CryptomatteLayer *layer, const ID *id) uint32_t cryptohash_int = BKE_cryptomatte_hash(name, name_len); if (layer != nullptr) { - layer->add_hash(std::string(name, name_len), cryptohash_int); + layer->add_hash(blender::StringRef(name, name_len), cryptohash_int); } return cryptohash_int; @@ -336,7 +316,7 @@ void BKE_cryptomatte_store_metadata(struct CryptomatteSession *session, break; } - const std::string manifest = layer->manifest_get_string(); + const std::string manifest = layer->manifest(); const std::string name = cryptomatte_determine_name(view_layer, cryptomatte_layer_name); /* Store the meta data into the render result. */ diff --git a/source/blender/draw/engines/eevee/eevee_cryptomatte.c b/source/blender/draw/engines/eevee/eevee_cryptomatte.c index 13a3f1766a9..c95279fc078 100644 --- a/source/blender/draw/engines/eevee/eevee_cryptomatte.c +++ b/source/blender/draw/engines/eevee/eevee_cryptomatte.c @@ -321,12 +321,6 @@ void EEVEE_cryptomatte_cache_populate(EEVEE_Data *vedata, EEVEE_ViewLayerData *s } } -void EEVEE_cryptomatte_cache_finish(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata) -{ - EEVEE_PrivateData *g_data = vedata->stl->g_data; - BKE_cryptomatte_finish(g_data->cryptomatte_session); -} - /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h index 5a93853900e..4e32854dedc 100644 --- a/source/blender/draw/engines/eevee/eevee_private.h +++ b/source/blender/draw/engines/eevee/eevee_private.h @@ -1341,7 +1341,6 @@ void EEVEE_cryptomatte_output_init(EEVEE_ViewLayerData *sldata, int tot_samples); void EEVEE_cryptomatte_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata); void EEVEE_cryptomatte_cache_populate(EEVEE_Data *vedata, EEVEE_ViewLayerData *sldata, Object *ob); -void EEVEE_cryptomatte_cache_finish(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata); void EEVEE_cryptomatte_particle_hair_cache_populate(EEVEE_Data *vedata, EEVEE_ViewLayerData *sldata, Object *ob); diff --git a/source/blender/draw/engines/eevee/eevee_renderpasses.c b/source/blender/draw/engines/eevee/eevee_renderpasses.c index c759e426875..0e16037f42d 100644 --- a/source/blender/draw/engines/eevee/eevee_renderpasses.c +++ b/source/blender/draw/engines/eevee/eevee_renderpasses.c @@ -255,10 +255,6 @@ void EEVEE_renderpasses_cache_finish(EEVEE_ViewLayerData *sldata, EEVEE_Data *ve else { psl->renderpass_pass = NULL; } - - if ((g_data->render_passes & (EEVEE_RENDER_PASS_CRYPTOMATTE)) != 0) { - EEVEE_cryptomatte_cache_finish(sldata, vedata); - } } /* Post-process data to construct a specific render-pass |