diff options
| author | MoonEyes <ducoinbenjamin@yahoo.fr> | 2026-11-29 00:50:27 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-29 00:50:27 +0100 |
| commit | 3dee9a5c2e702d5e9bf41db00cbb86da194d6e00 (patch) | |
| tree | 5f5db5ff38b969be18eeea5fd69bdf1e8e1133a0 /tools/batch_glb.py | |
| parent | ff9948f65299ccf9379eb6334794b3928321b2ed (diff) | |
| parent | 417b78bb6272afdcf3ca3a78e52edb827e201566 (diff) | |
Merge pull request #1752 from kirigayakazima/codex/batch-glb-per-texture-decode
batch_glb: allow independent texture decodes to overlap
Diffstat (limited to 'tools/batch_glb.py')
| -rw-r--r-- | tools/batch_glb.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/tools/batch_glb.py b/tools/batch_glb.py index e061c9653..2b085dbe3 100644 --- a/tools/batch_glb.py +++ b/tools/batch_glb.py | |||
| @@ -123,19 +123,30 @@ def _load_png_bytes(tex_path: str, max_size: int = 0) -> tuple[bytes | None, str | |||
| 123 | return None, "not a .png or .dds" | 123 | return None, "not a .png or .dds" |
| 124 | 124 | ||
| 125 | 125 | ||
| 126 | class _TextureEntry: | ||
| 127 | def __init__(self) -> None: | ||
| 128 | self.lock = threading.Lock() | ||
| 129 | self.result: tuple[bytes | None, str] | None = None | ||
| 130 | |||
| 131 | |||
| 126 | class TextureCache: | 132 | class TextureCache: |
| 127 | """Thread-safe (bytes, reason) per texture path, so the batch decodes a broken DDS once even when two | 133 | """Thread-safe (bytes, reason) per texture path, so the batch decodes a broken DDS once even when two |
| 128 | worker threads reach the same file at the same time (the pool runs one model per thread).""" | 134 | worker threads reach the same file at the same time (the pool runs one model per thread).""" |
| 129 | 135 | ||
| 130 | def __init__(self) -> None: | 136 | def __init__(self) -> None: |
| 131 | self._lock = threading.Lock() | 137 | self._lock = threading.Lock() |
| 132 | self._entries: dict[str, tuple[bytes | None, str]] = {} | 138 | self._entries: dict[tuple[str, int], _TextureEntry] = {} |
| 133 | 139 | ||
| 134 | def get_or_load(self, path: str, max_size: int = 0) -> tuple[bytes | None, str]: | 140 | def get_or_load(self, path: str, max_size: int = 0) -> tuple[bytes | None, str]: |
| 141 | key = (path, max_size) | ||
| 135 | with self._lock: | 142 | with self._lock: |
| 136 | if path not in self._entries: | 143 | entry = self._entries.get(key) |
| 137 | self._entries[path] = _load_png_bytes(path, max_size=max_size) | 144 | if entry is None: |
| 138 | return self._entries[path] | 145 | entry = self._entries[key] = _TextureEntry() |
| 146 | with entry.lock: | ||
| 147 | if entry.result is None: | ||
| 148 | entry.result = _load_png_bytes(path, max_size=max_size) | ||
| 149 | return entry.result | ||
| 139 | 150 | ||
| 140 | 151 | ||
| 141 | def convert_single( | 152 | def convert_single( |