[Bf-blender-cvs] [0ce51c2d90c] xr-dev: Merge branch 'master' into xr-dev
Peter Kim
noreply at git.blender.org
Wed Nov 23 04:59:02 CET 2022
Commit: 0ce51c2d90c2a58614e1bdd214b14bc0da8332d8
Author: Peter Kim
Date: Wed Nov 23 12:29:19 2022 +0900
Branches: xr-dev
https://developer.blender.org/rB0ce51c2d90c2a58614e1bdd214b14bc0da8332d8
Merge branch 'master' into xr-dev
===================================================================
===================================================================
diff --cc source/blender/blenloader/intern/readfile.cc
index 00000000000,8bcfe27a388..de6cd23a5f4
mode 000000,100644..100644
--- a/source/blender/blenloader/intern/readfile.cc
+++ b/source/blender/blenloader/intern/readfile.cc
@@@ -1,0 -1,5213 +1,5217 @@@
+ /* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
+
+ /** \file
+ * \ingroup blenloader
+ */
+
+ #include <cctype> /* for isdigit. */
+ #include <cerrno>
+ #include <climits>
+ #include <cstdarg> /* for va_start/end. */
+ #include <cstddef> /* for offsetof. */
+ #include <cstdlib> /* for atoi. */
+ #include <ctime> /* for gmtime. */
+ #include <fcntl.h> /* for open flags (O_BINARY, O_RDONLY). */
+
+ #include "BLI_utildefines.h"
+ #ifndef WIN32
+ # include <unistd.h> /* for read close */
+ #else
+ # include "BLI_winstuff.h"
+ # include "winsock2.h"
+ # include <io.h> /* for open close read */
+ #endif
+
+ #include "CLG_log.h"
+
+ /* allow readfile to use deprecated functionality */
+ #define DNA_DEPRECATED_ALLOW
+
+ #include "DNA_anim_types.h"
+ #include "DNA_asset_types.h"
+ #include "DNA_cachefile_types.h"
+ #include "DNA_collection_types.h"
+ #include "DNA_fileglobal_types.h"
+ #include "DNA_genfile.h"
+ #include "DNA_key_types.h"
+ #include "DNA_layer_types.h"
+ #include "DNA_node_types.h"
+ #include "DNA_packedFile_types.h"
+ #include "DNA_sdna_types.h"
+ #include "DNA_sound_types.h"
+ #include "DNA_vfont_types.h"
+ #include "DNA_volume_types.h"
+ #include "DNA_workspace_types.h"
+
+ #include "MEM_guardedalloc.h"
+
+ #include "BLI_blenlib.h"
+ #include "BLI_endian_defines.h"
+ #include "BLI_endian_switch.h"
+ #include "BLI_ghash.h"
+ #include "BLI_linklist.h"
+ #include "BLI_math.h"
+ #include "BLI_memarena.h"
+ #include "BLI_mempool.h"
+ #include "BLI_threads.h"
+
+ #include "PIL_time.h"
+
+ #include "BLT_translation.h"
+
+ #include "BKE_anim_data.h"
+ #include "BKE_animsys.h"
+ #include "BKE_asset.h"
+ #include "BKE_collection.h"
+ #include "BKE_global.h" /* for G */
+ #include "BKE_idprop.h"
+ #include "BKE_idtype.h"
+ #include "BKE_layer.h"
+ #include "BKE_lib_id.h"
+ #include "BKE_lib_override.h"
+ #include "BKE_lib_query.h"
+ #include "BKE_main.h" /* for Main */
+ #include "BKE_main_idmap.h"
+ #include "BKE_material.h"
+ #include "BKE_mesh.h"
+ #include "BKE_modifier.h"
+ #include "BKE_node.h" /* for tree type defines */
+ #include "BKE_object.h"
+ #include "BKE_packedFile.h"
+ #include "BKE_report.h"
+ #include "BKE_scene.h"
+ #include "BKE_screen.h"
+ #include "BKE_undo_system.h"
+ #include "BKE_workspace.h"
+
+ #include "DRW_engine.h"
+
+ #include "DEG_depsgraph.h"
+
+ #include "BLO_blend_defs.h"
+ #include "BLO_blend_validate.h"
+ #include "BLO_read_write.h"
+ #include "BLO_readfile.h"
+ #include "BLO_undofile.h"
+
+ #include "SEQ_clipboard.h"
+ #include "SEQ_iterator.h"
+ #include "SEQ_modifier.h"
+ #include "SEQ_sequencer.h"
+ #include "SEQ_utils.h"
+
+ #include "readfile.h"
+
+ /* Make preferences read-only. */
+ #define U (*((const UserDef *)&U))
+
+ /**
+ * READ
+ * ====
+ *
+ * - Existing Library (#Main) push or free
+ * - allocate new #Main
+ * - load file
+ * - read #SDNA
+ * - for each LibBlock
+ * - read LibBlock
+ * - if a Library
+ * - make a new #Main
+ * - attach ID's to it
+ * - else
+ * - read associated 'direct data'
+ * - link direct data (internal and to LibBlock)
+ * - read #FileGlobal
+ * - read #USER data, only when indicated (file is `~/.config/blender/X.XX/config/userpref.blend`)
+ * - free file
+ * - per Library (per #Main)
+ * - read file
+ * - read #SDNA
+ * - find LibBlocks and attach #ID's to #Main
+ * - if external LibBlock
+ * - search all #Main's
+ * - or it's already read,
+ * - or not read yet
+ * - or make new #Main
+ * - per LibBlock
+ * - read recursive
+ * - read associated direct data
+ * - link direct data (internal and to LibBlock)
+ * - free file
+ * - per Library with unread LibBlocks
+ * - read file
+ * - read #SDNA
+ * - per LibBlock
+ * - read recursive
+ * - read associated direct data
+ * - link direct data (internal and to LibBlock)
+ * - free file
+ * - join all #Main's
+ * - link all LibBlocks and indirect pointers to libblocks
+ * - initialize #FileGlobal and copy pointers to #Global
+ *
+ * \note Still a weak point is the new-address function, that doesn't solve reading from
+ * multiple files at the same time.
+ * (added remark: oh, i thought that was solved? will look at that... (ton).
+ */
+
+ /**
+ * Delay reading blocks we might not use (especially applies to library linking).
+ * which keeps large arrays in memory from data-blocks we may not even use.
+ *
+ * \note This is disabled when using compression,
+ * while ZLIB supports seek it's unusably slow, see: T61880.
+ */
+ #define USE_BHEAD_READ_ON_DEMAND
+
+ /** Use #GHash for #BHead name-based lookups (speeds up linking). */
+ #define USE_GHASH_BHEAD
+
+ /** Use #GHash for restoring pointers by name. */
+ #define USE_GHASH_RESTORE_POINTER
+
+ static CLG_LogRef LOG = {"blo.readfile"};
+ static CLG_LogRef LOG_UNDO = {"blo.readfile.undo"};
+
+ /* local prototypes */
+ static void read_libraries(FileData *basefd, ListBase *mainlist);
+ static void *read_struct(FileData *fd, BHead *bh, const char *blockname);
+ static BHead *find_bhead_from_code_name(FileData *fd, const short idcode, const char *name);
+ static BHead *find_bhead_from_idname(FileData *fd, const char *idname);
+
+ struct BHeadN {
+ struct BHeadN *next, *prev;
+ #ifdef USE_BHEAD_READ_ON_DEMAND
+ /** Use to read the data from the file directly into memory as needed. */
+ off64_t file_offset;
+ /** When set, the remainder of this allocation is the data, otherwise it needs to be read. */
+ bool has_data;
+ #endif
+ bool is_memchunk_identical;
+ struct BHead bhead;
+ };
+
+ #define BHEADN_FROM_BHEAD(bh) ((BHeadN *)POINTER_OFFSET(bh, -int(offsetof(BHeadN, bhead))))
+
+ /**
+ * We could change this in the future, for now it's simplest if only data is delayed
+ * because ID names are used in lookup tables.
+ */
+ #define BHEAD_USE_READ_ON_DEMAND(bhead) ((bhead)->code == DATA)
+
+ void BLO_reportf_wrap(BlendFileReadReport *reports, eReportType type, const char *format, ...)
+ {
+ char fixed_buf[1024]; /* should be long enough */
+
+ va_list args;
+
+ va_start(args, format);
+ vsnprintf(fixed_buf, sizeof(fixed_buf), format, args);
+ va_end(args);
+
+ fixed_buf[sizeof(fixed_buf) - 1] = '\0';
+
+ BKE_report(reports->reports, type, fixed_buf);
+
+ if (G.background == 0) {
+ printf("%s: %s\n", BKE_report_type_str(type), fixed_buf);
+ }
+ }
+
+ /* for reporting linking messages */
+ static const char *library_parent_filepath(Library *lib)
+ {
+ return lib->parent ? lib->parent->filepath_abs : "<direct>";
+ }
+
+ /* -------------------------------------------------------------------- */
+ /** \name OldNewMap API
+ * \{ */
+
+ struct OldNew {
+ const void *oldp;
+ void *newp;
+ /* `nr` is "user count" for data, and ID code for libdata. */
+ int nr;
+ };
+
+ struct OldNewMap {
+ /* Array that stores the actual entries. */
+ OldNew *entries;
+ int nentries;
+ /* Hash-map that stores indices into the `entries` array. */
+ int32_t *map;
+
+ int capacity_exp;
+ };
+
+ #define ENTRIES_CAPACITY(onm) (1ll << (onm)->capacity_exp)
+ #define MAP_CAPACITY(onm) (1ll << ((onm)->capacity_exp + 1))
+ #define SLOT_MASK(onm) (MAP_CAPACITY(onm) - 1)
+ #define DEFAULT_SIZE_EXP 6
+ #define PERTURB_SHIFT 5
+
+ /* based on the probing algorithm used in Python dicts. */
+ #define ITER_SLOTS(onm, KEY, SLOT_NAME, INDEX_NAME) \
+ uint32_t hash = BLI_ghashutil_ptrhash(KEY); \
+ uint32_t mask = SLOT_MASK(onm); \
+ uint perturb = hash; \
+ int SLOT_NAME = mask & hash; \
+ int INDEX_NAME = onm->map[SLOT_NAME]; \
+ for (;; SLOT_NAME = mask & ((5 * SLOT_NAME) + 1 + perturb), \
+ perturb >>= PERTURB_SHIFT, \
+ INDEX_NAME = onm->map[SLOT_NAME])
+
+ static void oldnewmap_insert_index_in_map(OldNewMap *onm, const void *ptr, int index)
+ {
+ ITER_SLOTS (onm, ptr, slot, stored_index) {
+ if (stored_index == -1) {
+ onm->map[slot] = index;
+ break;
+ }
+ }
+ }
+
+ static void oldnewmap_insert_or_replace(OldNewMap *onm, OldNew entry)
+ {
+ ITER_SLOTS (onm, entry.oldp, slot, index) {
+ if (index == -1) {
+ onm->entries[onm->nentries] = entry;
+ onm->map[slot] = onm->nentries;
+ onm->nentries++;
+ break;
+ }
+ if (onm->entries[index].oldp == entry.oldp) {
+ onm->entries[index] = entry;
+ break;
+ }
+ }
+ }
+
+ static OldNew *oldnewmap_lookup_entry(const OldNewMap *onm, const void *addr)
+ {
+ ITER_SLOTS (onm, addr, slot, index) {
+ if (index >= 0) {
+ OldNew *entry = &onm->entries[index];
+ if (entry->oldp == addr) {
+ return entry;
+ }
+ }
+ else {
+ return nullptr;
+ }
+ }
+ }
+
+ static void oldnewmap_clear_map(OldNewMap *onm)
+ {
+ memset(onm->map, 0xFF, MAP_CAPACITY(onm) * sizeof(*onm->map));
+ }
+
+ static void oldnewmap_increase_size(OldNewMap *onm)
+ {
+ onm->capacity_exp++;
+ onm->entries = static_cast<OldNew *>(
+ MEM_reallocN(onm->entries, sizeof(*onm->entries) * ENTRIES_CAPACITY(onm)));
+ onm->map = static_cast<int32_t *>(MEM_reallocN(onm->map, sizeof(*onm->map) * MAP_CAPACITY(onm)));
+ oldnewmap_clear_map(onm);
+ for (int i = 0; i < onm->nentries; i++) {
+ oldnewmap_insert_index_in_map(onm, onm->entries[i].oldp, i);
+ }
+ }
+
+ /* Public OldNewMap API */
+
+ static void oldnewmap_init_data(OldNewMap *onm, const int capacity_exp)
+ {
+ memset(onm, 0x0, sizeof(*onm));
+
+ onm->capacity_exp = capacity_exp;
+ onm->entries = static_cast<OldNew *>(
+ MEM_malloc_arrayN(ENTRIES_CAPACITY(onm), sizeof(*onm->entries), "OldNewMap.entries"));
+ onm->map = static_cast<int32_t *>(
+ MEM_malloc_arrayN(MAP_CAPACITY(onm), sizeof(*onm->map), "OldNewMap.map"));
+ oldnewmap_clear_map(onm);
+ }
+
+ static OldNewMap *oldnewmap_new()
+ {
+ OldNew
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list