Skip to content

Commit 48aa7a7

Browse files
committed
Track builtin bootstrap mounts
1 parent 58b9ff1 commit 48aa7a7

5 files changed

Lines changed: 55 additions & 50 deletions

File tree

.github/workflows/build-nabla.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,6 @@ jobs:
174174
--target install `
175175
--config ${{ matrix.config }}
176176
177-
- name: Container – Install and verify NSC runtime bundle
178-
run: |
179-
docker exec orphan `
180-
${{ env.entry }} ${{ env.cmd }} -Command ctest `
181-
--test-dir ${{ env.binary }}\tools\nsc `
182-
-C ${{ matrix.config }} `
183-
--output-on-failure `
184-
-R "^(NBL_NSC_INSTALL_RUNTIMES_TEST|NBL_NSC_INSTALL_EXECUTABLES_TEST|NBL_NSC_SELF_TEST_UNMOUNT_BUILTINS)$"
185-
186177
- name: API / Examples / Check Run (Create)
187178
id: check-run-create
188179
uses: actions/github-script@v6

include/nbl/system/ISystem.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class NBL_API2 ISystem : public core::IReferenceCounted
143143

144144
void unmountBuiltins();
145145
bool areBuiltinsMounted() const;
146+
size_t getMountedBuiltinArchiveCount() const;
146147
inline size_t getMountedArchiveCount() const { return m_cachedArchiveFiles.getSize(); }
147148

148149
//
@@ -206,8 +207,16 @@ class NBL_API2 ISystem : public core::IReferenceCounted
206207
//! The key is file extension
207208
core::CMultiObjectCache<std::string,core::smart_refctd_ptr<IArchiveLoader>,std::vector> perFileExt;
208209
} m_loaders;
210+
struct SBuiltinMount
211+
{
212+
core::smart_refctd_ptr<IFileArchive> archive;
213+
system::path pathAlias;
214+
};
215+
void mountBuiltin(core::smart_refctd_ptr<IFileArchive>&& archive, const system::path& pathAlias = "");
216+
bool isBuiltinMounted(const SBuiltinMount& mount) const;
209217
//
210218
core::CMultiObjectCache<system::path,core::smart_refctd_ptr<IFileArchive>> m_cachedArchiveFiles;
219+
core::vector<SBuiltinMount> m_builtinMounts;
211220

212221
private:
213222
struct SRequestParams_NOOP

src/nbl/system/ISystem.cpp

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,27 @@
1212
#include "nbl/system/CArchiveLoaderTar.h"
1313
#include "nbl/system/CMountDirectoryArchive.h"
1414

15-
#include <array>
16-
1715
using namespace nbl;
1816
using namespace nbl::system;
1917

20-
namespace
21-
{
22-
constexpr std::array<const char*, 4> builtinMountPoints = { "nbl/builtin", "nbl/video", "spirv", "boost" };
23-
}
24-
2518
ISystem::ISystem(core::smart_refctd_ptr<ISystem::ICaller>&& caller) : m_dispatcher(std::move(caller))
2619
{
2720
addArchiveLoader(core::make_smart_refctd_ptr<CArchiveLoaderZip>(nullptr));
2821
addArchiveLoader(core::make_smart_refctd_ptr<CArchiveLoaderTar>(nullptr));
2922

23+
// Builtins still live in the main archive cache for normal path resolution.
24+
// This separate bootstrap tracking is only for exact unmounting and regression tests.
3025
#ifdef NBL_EMBED_BUILTIN_RESOURCES
31-
mount(core::make_smart_refctd_ptr<nbl::builtin::CArchive>(nullptr));
32-
mount(core::make_smart_refctd_ptr<spirv::builtin::CArchive>(nullptr));
33-
mount(core::make_smart_refctd_ptr<boost::builtin::CArchive>(nullptr));
34-
mount(core::make_smart_refctd_ptr<nbl::devicegen::builtin::CArchive>(nullptr));
26+
mountBuiltin(core::make_smart_refctd_ptr<nbl::builtin::CArchive>(nullptr));
27+
mountBuiltin(core::make_smart_refctd_ptr<spirv::builtin::CArchive>(nullptr));
28+
mountBuiltin(core::make_smart_refctd_ptr<boost::builtin::CArchive>(nullptr));
29+
mountBuiltin(core::make_smart_refctd_ptr<nbl::devicegen::builtin::CArchive>(nullptr));
3530
#else
3631
// TODO: absolute default entry paths? we should do something with it
37-
mount(core::make_smart_refctd_ptr<nbl::system::CMountDirectoryArchive>(NBL_BUILTIN_RESOURCES_DIRECTORY_PATH, nullptr, this), "nbl/builtin");
38-
mount(core::make_smart_refctd_ptr<nbl::system::CMountDirectoryArchive>(SPIRV_BUILTIN_RESOURCES_DIRECTORY_PATH, nullptr, this), "spirv");
39-
mount(core::make_smart_refctd_ptr<nbl::system::CMountDirectoryArchive>(BOOST_BUILTIN_RESOURCES_DIRECTORY_PATH, nullptr, this), "boost");
40-
mount(core::make_smart_refctd_ptr<nbl::system::CMountDirectoryArchive>(DEVICEGEN_BUILTIN_RESOURCES_DIRECTORY_PATH, nullptr, this), "nbl/video");
32+
mountBuiltin(core::make_smart_refctd_ptr<nbl::system::CMountDirectoryArchive>(NBL_BUILTIN_RESOURCES_DIRECTORY_PATH, nullptr, this), "nbl/builtin");
33+
mountBuiltin(core::make_smart_refctd_ptr<nbl::system::CMountDirectoryArchive>(SPIRV_BUILTIN_RESOURCES_DIRECTORY_PATH, nullptr, this), "spirv");
34+
mountBuiltin(core::make_smart_refctd_ptr<nbl::system::CMountDirectoryArchive>(BOOST_BUILTIN_RESOURCES_DIRECTORY_PATH, nullptr, this), "boost");
35+
mountBuiltin(core::make_smart_refctd_ptr<nbl::system::CMountDirectoryArchive>(DEVICEGEN_BUILTIN_RESOURCES_DIRECTORY_PATH, nullptr, this), "nbl/video");
4136
#endif
4237
}
4338

@@ -328,32 +323,41 @@ bool ISystem::ICaller::flushMapping(IFile* file, size_t offset, size_t size)
328323
}
329324

330325
void ISystem::unmountBuiltins() {
326+
for (auto& mount : m_builtinMounts)
327+
unmount(mount.archive.get(), mount.pathAlias);
328+
m_builtinMounts.clear();
329+
}
331330

332-
auto removeByKey = [&, this](const char* s) {
333-
auto range = m_cachedArchiveFiles.findRange(s);
334-
335-
std::vector<core::smart_refctd_ptr<IFileArchive>> items_to_remove = {}; //is it always just 1 item?
336-
for (auto it = range.begin(); it != range.end(); ++it)
337-
{
338-
items_to_remove.push_back(it->second);
339-
}
340-
for (size_t i = 0; i < items_to_remove.size(); i++)
341-
{
342-
m_cachedArchiveFiles.removeObject(items_to_remove[i], s);
343-
}
344-
};
331+
bool ISystem::areBuiltinsMounted() const
332+
{
333+
return !m_builtinMounts.empty() && getMountedBuiltinArchiveCount() == m_builtinMounts.size();
334+
}
345335

346-
for (const auto* mountPoint : builtinMountPoints)
347-
removeByKey(mountPoint);
336+
size_t ISystem::getMountedBuiltinArchiveCount() const
337+
{
338+
size_t retval = 0ull;
339+
for (const auto& mount : m_builtinMounts)
340+
retval += size_t(isBuiltinMounted(mount));
341+
return retval;
348342
}
349343

350-
bool ISystem::areBuiltinsMounted() const
344+
void ISystem::mountBuiltin(core::smart_refctd_ptr<IFileArchive>&& archive, const system::path& pathAlias)
351345
{
352-
for (const auto* mountPoint : builtinMountPoints)
353-
if (!isDirectory(path(mountPoint)))
354-
return false;
346+
auto tracked = archive;
347+
mount(std::move(archive), pathAlias);
348+
m_builtinMounts.push_back({ std::move(tracked), pathAlias });
349+
}
355350

356-
return true;
351+
bool ISystem::isBuiltinMounted(const SBuiltinMount& mount) const
352+
{
353+
const auto lookupKey = mount.pathAlias.empty() ? mount.archive->getDefaultAbsolutePath() : mount.pathAlias;
354+
const auto range = m_cachedArchiveFiles.findRange(lookupKey);
355+
for (auto it = range.begin(); it != range.end(); ++it)
356+
{
357+
if (it->second.get() == mount.archive.get())
358+
return true;
359+
}
360+
return false;
357361
}
358362

359363
#ifdef _NBL_PLATFORM_WINDOWS_

tools/nsc/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ execute_process(COMMAND "@DOCKER_EXE@"
510510
511511
message(STATUS "Executing CTests")
512512
execute_process(COMMAND "@CTEST_EXE@"
513-
-C "$<CONFIG>" --stop-on-failure
513+
-C "$<CONFIG>" --stop-on-failure --output-on-failure
514514
WORKING_DIRECTORY "@CMAKE_CURRENT_BINARY_DIR@"
515515
COMMAND_ERROR_IS_FATAL ANY
516516
)

tools/nsc/main.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,18 +209,19 @@ class ShaderCompiler final : public IApplicationFramework
209209

210210
if (program.get<bool>("--self-test-unmount-builtins"))
211211
{
212-
const auto mountedArchiveCount = m_system->getMountedArchiveCount();
213-
if (!mountedArchiveCount)
212+
const auto mountedBuiltinArchiveCount = m_system->getMountedBuiltinArchiveCount();
213+
if (!mountedBuiltinArchiveCount)
214214
{
215-
std::cerr << "Builtins were not mounted at startup.\n";
215+
std::cerr << "Builtins were not mounted at startup. builtin_mount_count=0 total_mount_count=" << m_system->getMountedArchiveCount() << "\n";
216216
return false;
217217
}
218218

219219
m_system->unmountBuiltins();
220220

221-
if (const auto remainingArchiveCount = m_system->getMountedArchiveCount(); remainingArchiveCount != 0ull)
221+
if (const auto remainingBuiltinArchiveCount = m_system->getMountedBuiltinArchiveCount(); remainingBuiltinArchiveCount != 0ull)
222222
{
223-
std::cerr << "Builtins unmount self-test failed. Remaining mounted archives: " << remainingArchiveCount << "\n";
223+
std::cerr << "Builtins unmount self-test failed. remaining_builtin_mount_count=" << remainingBuiltinArchiveCount
224+
<< " total_mount_count=" << m_system->getMountedArchiveCount() << "\n";
224225
return false;
225226
}
226227

0 commit comments

Comments
 (0)