@@ -117,15 +117,23 @@ void DefaultBinaryIO::_write(const luisa::string &file_path, luisa::span<std::by
117
117
_unlock (idx, true );
118
118
}
119
119
120
- DefaultBinaryIO::DefaultBinaryIO (Context &&ctx, void *ext ) noexcept
120
+ DefaultBinaryIO::DefaultBinaryIO (Context &&ctx, bool headless ) noexcept
121
121
: _ctx(std::move(ctx)),
122
- _cache_dir{_ctx.create_runtime_subdir (" .cache" sv)},
123
- _data_dir{_ctx.create_runtime_subdir (" .data" sv)},
124
- _data_lmdb{_data_dir, std::max<size_t >(126ull , std::thread::hardware_concurrency () * 2 )},
125
- _cache_lmdb{_cache_dir, std::max<size_t >(126ull , std::thread::hardware_concurrency () * 2 )} {
122
+ _headless (headless) {
123
+ if (!headless) {
124
+ _cache_dir = _ctx.create_runtime_subdir (" .cache" sv);
125
+ _data_dir = _ctx.create_runtime_subdir (" .data" sv);
126
+ _data_lmdb.create (_data_dir, std::max<size_t >(126ull , std::thread::hardware_concurrency () * 2 ));
127
+ _cache_lmdb.create (_cache_dir, std::max<size_t >(126ull , std::thread::hardware_concurrency () * 2 ));
128
+ }
126
129
}
127
130
128
- DefaultBinaryIO::~DefaultBinaryIO () noexcept = default ;
131
+ DefaultBinaryIO::~DefaultBinaryIO () noexcept {
132
+ if (!_headless) {
133
+ _data_lmdb.destroy ();
134
+ _cache_lmdb.destroy ();
135
+ }
136
+ }
129
137
130
138
luisa::unique_ptr<BinaryStream> DefaultBinaryIO::read_shader_bytecode (luisa::string_view name) const noexcept {
131
139
std::filesystem::path local_path{name};
@@ -137,13 +145,13 @@ luisa::unique_ptr<BinaryStream> DefaultBinaryIO::read_shader_bytecode(luisa::str
137
145
}
138
146
139
147
luisa::unique_ptr<BinaryStream> DefaultBinaryIO::read_shader_cache (luisa::string_view name) const noexcept {
140
- auto r = _cache_lmdb. read (name);
148
+ auto r = _cache_lmdb-> read (name);
141
149
if (r.empty ()) return {};
142
150
return luisa::make_unique<LMDBBinaryStream>(r.data (), r.size ());
143
151
}
144
152
145
153
luisa::unique_ptr<BinaryStream> DefaultBinaryIO::read_internal_shader (luisa::string_view name) const noexcept {
146
- auto r = _data_lmdb. read (name);
154
+ auto r = _data_lmdb-> read (name);
147
155
if (r.empty ()) return {};
148
156
return luisa::make_unique<LMDBBinaryStream>(r.data (), r.size ());
149
157
}
@@ -177,17 +185,17 @@ luisa::filesystem::path DefaultBinaryIO::write_shader_source(luisa::string_view
177
185
}
178
186
179
187
luisa::filesystem::path DefaultBinaryIO::write_shader_cache (luisa::string_view name, luisa::span<std::byte const > data) const noexcept {
180
- _cache_lmdb. write (name, data);
188
+ _cache_lmdb-> write (name, data);
181
189
return _cache_dir / name;
182
190
}
183
191
184
192
luisa::filesystem::path DefaultBinaryIO::write_internal_shader (luisa::string_view name, luisa::span<std::byte const > data) const noexcept {
185
- _data_lmdb. write (name, data);
193
+ _data_lmdb-> write (name, data);
186
194
return _data_dir / name;
187
195
}
188
196
189
197
void DefaultBinaryIO::clear_shader_cache () const noexcept {
190
- std::destroy_at ( std::addressof ( _cache_lmdb) );
198
+ _cache_lmdb. destroy ( );
191
199
std::error_code ec;
192
200
for (auto &&dir : std::filesystem::directory_iterator (_cache_dir)) {
193
201
std::filesystem::remove_all (dir, ec);
@@ -197,7 +205,7 @@ void DefaultBinaryIO::clear_shader_cache() const noexcept {
197
205
to_string (dir), ec.message ());
198
206
}
199
207
}
200
- std::construct_at (& _cache_lmdb, _cache_dir);
208
+ _cache_lmdb. create ( _cache_dir);
201
209
}
202
210
203
211
}// namespace luisa::compute
0 commit comments