Skip to content

Commit cd644ab

Browse files
fixed some nasty bugs in path prefix comparison, and fixed the way we look for includes in HLSL
1 parent 49023e7 commit cd644ab

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

include/nbl/system/CFileArchive.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class NBL_API2 CFileArchive : public IFileArchive
7474
static inline constexpr size_t ALIGNOF_INNER_ARCHIVE_FILE = std::max(alignof(CInnerArchiveFile<CPlainHeapAllocator>), alignof(CInnerArchiveFile<VirtualMemoryAllocator>));
7575

7676
protected:
77-
CFileArchive(path&& _defaultAbsolutePath, system::logger_opt_smart_ptr&& logger, std::shared_ptr<core::vector<SFileList::SEntry>> _items) :
77+
inline CFileArchive(path&& _defaultAbsolutePath, system::logger_opt_smart_ptr&& logger, std::shared_ptr<core::vector<SFileList::SEntry>> _items) :
7878
IFileArchive(std::move(_defaultAbsolutePath),std::move(logger))
7979
{
8080
setItemList(_items);
@@ -86,7 +86,7 @@ class NBL_API2 CFileArchive : public IFileArchive
8686
m_fileFlags[i].clear();
8787
memset(m_filesBuffer,0,fileCount*SIZEOF_INNER_ARCHIVE_FILE);
8888
}
89-
~CFileArchive()
89+
inline ~CFileArchive()
9090
{
9191
_NBL_ALIGNED_FREE(m_filesBuffer);
9292
_NBL_ALIGNED_FREE(m_fileFlags);

src/nbl/asset/utils/CHLSLCompiler.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,31 +77,29 @@ static tcpp::TInputStreamUniquePtr getInputStreamInclude(
7777
std::vector<std::pair<uint32_t, std::string>>& includeStack
7878
)
7979
{
80-
std::filesystem::path relDir;
80+
std::filesystem::path requestingSourceDir;
8181
#ifdef NBL_EMBED_BUILTIN_RESOURCES
8282
const bool reqFromBuiltin = nbl::builtin::hasPathPrefix(requestingSource) || spirv::builtin::hasPathPrefix(requestingSource);
8383
const bool reqBuiltin = nbl::builtin::hasPathPrefix(requestedSource) || spirv::builtin::hasPathPrefix(requestedSource);
84+
//While #includ'ing a builtin, one must specify its full path (starting with "nbl/builtin" or "/nbl/builtin").
85+
// This rule applies also while a builtin is #includ`ing another builtin.
86+
//While including a filesystem file it must be either absolute path (or relative to any search dir added to asset::iIncludeHandler; <>-type),
87+
// or path relative to executable's working directory (""-type).
8488
if (!reqFromBuiltin && !reqBuiltin)
85-
{
86-
//While #includ'ing a builtin, one must specify its full path (starting with "nbl/builtin" or "/nbl/builtin").
87-
// This rule applies also while a builtin is #includ`ing another builtin.
88-
//While including a filesystem file it must be either absolute path (or relative to any search dir added to asset::iIncludeHandler; <>-type),
89-
// or path relative to executable's working directory (""-type).
90-
relDir = std::filesystem::path(requestingSource).parent_path();
91-
}
9289
#else
9390
const bool reqBuiltin = false;
9491
#endif // NBL_EMBED_BUILTIN_RESOURCES
95-
std::filesystem::path name = isRelative ? (relDir / requestedSource) : (requestedSource);
92+
requestingSourceDir = system::path(requestingSource).parent_path();
9693

94+
system::path name = isRelative ? (requestingSourceDir / requestedSource) : (requestedSource);
9795
if (std::filesystem::exists(name) && !reqBuiltin)
9896
name = std::filesystem::absolute(name);
9997

10098
std::optional<std::string> result;
10199
if (isRelative)
102-
result = inclFinder->getIncludeRelative(relDir, requestedSource);
100+
result = inclFinder->getIncludeRelative(requestingSourceDir, requestedSource);
103101
else //shaderc_include_type_standard
104-
result = inclFinder->getIncludeStandard(relDir, requestedSource);
102+
result = inclFinder->getIncludeStandard(requestingSourceDir, requestedSource);
105103

106104
if (!result)
107105
{

src/nbl/builtin/template/CArchive.h.in

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,27 @@
77

88
namespace @_NAMESPACE_@
99
{
10-
constexpr std::string_view pathPrefix = "@_BUNDLE_ARCHIVE_ABSOLUTE_PATH_@";
11-
constexpr bool hasPathPrefix(std::string_view str) { return str.find(pathPrefix) == 0ull; }
10+
constexpr std::string_view pathPrefix = "@_BUNDLE_ARCHIVE_ABSOLUTE_PATH_@";
1211

13-
class @NBL_BR_API@ CArchive final : public nbl::system::CFileArchive
14-
{
15-
public:
16-
CArchive(nbl::system::logger_opt_smart_ptr&& logger);
12+
inline bool hasPathPrefix(nbl::system::path _path)
13+
{
14+
_path.make_preferred();
15+
const auto prefix = nbl::system::path(pathPrefix).make_preferred();
16+
return _path.string().find(prefix.string())==0ull;
17+
}
18+
19+
class @NBL_BR_API@ CArchive final : public nbl::system::CFileArchive
20+
{
21+
public:
22+
CArchive(nbl::system::logger_opt_smart_ptr&& logger);
1723

18-
protected:
19-
file_buffer_t getFileBuffer(const nbl::system::IFileArchive::SFileList::found_t& found) override
20-
{
21-
auto resource = get_resource_runtime(found->pathRelativeToArchive.string());
22-
return {const_cast<uint8_t*>(resource.first),resource.second,nullptr};
23-
}
24-
};
24+
protected:
25+
file_buffer_t getFileBuffer(const nbl::system::IFileArchive::SFileList::found_t& found) override
26+
{
27+
auto resource = get_resource_runtime(found->pathRelativeToArchive.string());
28+
return {const_cast<uint8_t*>(resource.first),resource.second,nullptr};
29+
}
30+
};
2531
}
2632

2733
#endif // _@_GUARD_SUFFIX_@_C_ARCHIVE_H_

0 commit comments

Comments
 (0)