1111#include " nbl/builtin/hlsl/colorspace/encodeCIEXYZ.hlsl"
1212#include " nbl/builtin/hlsl/sampling/quantized_sequence.hlsl"
1313#include " nbl/asset/utils/ISPIRVEntryPointTrimmer.h"
14+ #include " nbl/system/ModuleLookupUtils.h"
1415#include " app_resources/hlsl/render_common.hlsl"
1516#include " app_resources/hlsl/render_rwmc_common.hlsl"
1617#include " app_resources/hlsl/resolve_common.hlsl"
2526#include < optional>
2627#include < thread>
2728
29+ #include " nlohmann/json.hpp"
30+
2831using namespace nbl ;
2932using namespace core ;
3033using namespace hlsl ;
@@ -61,6 +64,7 @@ class HLSLComputePathtracer final : public SimpleWindowedApplication, public Bui
6164 constexpr static inline uint32_t2 WindowDimensions = { 1280 , 720 };
6265 constexpr static inline uint32_t MaxFramesInFlight = 5 ;
6366 static constexpr std::string_view BuildConfigName = PATH_TRACER_BUILD_CONFIG_NAME;
67+ static constexpr std::string_view RuntimeConfigFilename = " path_tracer.runtime.json" ;
6468 static inline std::string DefaultImagePathsFile = " envmap/envmap_0.exr" ;
6569 static inline std::string OwenSamplerFilePath = " owen_sampler_buffer.bin" ;
6670
@@ -1196,7 +1200,7 @@ class HLSLComputePathtracer final : public SimpleWindowedApplication, public Bui
11961200 ImGui::TextDisabled (" All pipelines ready" );
11971201 ImGui::Dummy (ImVec2 (0 .f , 2 .f ));
11981202
1199- if (ImGui::CollapsingHeader (" Camera" , ImGuiTreeNodeFlags_DefaultOpen ))
1203+ if (ImGui::CollapsingHeader (" Camera" ))
12001204 {
12011205 if (beginSectionTable (" ##camera_controls_table" ))
12021206 {
@@ -1918,26 +1922,66 @@ class HLSLComputePathtracer final : public SimpleWindowedApplication, public Bui
19181922 return localOutputCWD / " pipeline/cache" ;
19191923 }
19201924
1921- path getPipelineCacheRootDir () const
1925+ path getRuntimeConfigPath () const
19221926 {
1923- return tryGetPipelineCacheDirOverride (). value_or ( getDefaultPipelineCacheDir ()) ;
1927+ return system::executableDirectory () / RuntimeConfigFilename ;
19241928 }
19251929
1926- static constexpr std::string_view PipelineCacheSchemaVersion = " v4" ;
1927- static constexpr std::string_view TrimmedShaderCacheSchemaVersion = " v5" ;
1930+ std::optional<path> tryGetPipelineCacheDirFromRuntimeConfig () const
1931+ {
1932+ const auto configPath = getRuntimeConfigPath ();
1933+ if (!m_system->exists (configPath, IFile::ECF_READ))
1934+ return std::nullopt ;
1935+
1936+ std::ifstream input (configPath);
1937+ if (!input.is_open ())
1938+ return std::nullopt ;
19281939
1929- path getPipelineCacheBlobPath () const
1940+ nlohmann::json json;
1941+ try
1942+ {
1943+ input >> json;
1944+ }
1945+ catch (const std::exception& e)
1946+ {
1947+ m_logger->log (" Failed to parse PATH_TRACER runtime config %s: %s" , ILogger::ELL_WARNING, configPath.string ().c_str (), e.what ());
1948+ return std::nullopt ;
1949+ }
1950+
1951+ const auto cacheRootIt = json.find (" cache_root" );
1952+ if (cacheRootIt == json.end () || !cacheRootIt->is_string ())
1953+ return std::nullopt ;
1954+
1955+ const auto cacheRoot = cacheRootIt->get <std::string>();
1956+ if (cacheRoot.empty ())
1957+ return std::nullopt ;
1958+
1959+ const path relativeRoot (cacheRoot);
1960+ if (relativeRoot.is_absolute ())
1961+ {
1962+ m_logger->log (" Ignoring absolute cache_root in %s" , ILogger::ELL_WARNING, configPath.string ().c_str ());
1963+ return std::nullopt ;
1964+ }
1965+
1966+ return (configPath.parent_path () / relativeRoot).lexically_normal ();
1967+ }
1968+
1969+ path getPipelineCacheRootDir () const
19301970 {
1931- const auto key = m_device->getPipelineCacheKey ();
1932- return getPipelineCacheRootDir () / PipelineCacheSchemaVersion / " pipeline" / BuildConfigName / (std::string (key.deviceAndDriverUUID ) + " .bin" );
1971+ if (const auto overrideDir = tryGetPipelineCacheDirOverride (); overrideDir.has_value ())
1972+ return overrideDir.value ();
1973+ if (const auto runtimeConfigDir = tryGetPipelineCacheDirFromRuntimeConfig (); runtimeConfigDir.has_value ())
1974+ return runtimeConfigDir.value ();
1975+ return getDefaultPipelineCacheDir ();
19331976 }
19341977
1935- path getTrimmedShaderCacheDir () const
1978+ path getPipelineCacheBlobPath () const
19361979 {
1937- return getPipelineCacheRootDir () / TrimmedShaderCacheSchemaVersion / " trimmed" / BuildConfigName;
1980+ const auto key = m_device->getPipelineCacheKey ();
1981+ return getPipelineCacheRootDir () / " blob" / BuildConfigName / (std::string (key.deviceAndDriverUUID ) + " .bin" );
19381982 }
19391983
1940- path getValidatedSpirvCacheDir () const
1984+ path getSpirvCacheDir () const
19411985 {
19421986 return getPipelineCacheRootDir () / " spirv" / BuildConfigName;
19431987 }
@@ -1947,15 +1991,15 @@ class HLSLComputePathtracer final : public SimpleWindowedApplication, public Bui
19471991 core::blake3_hasher hasher;
19481992 hasher << std::string_view (shader ? shader->getFilepathHint () : std::string_view{});
19491993 hasher << std::string_view (entryPoint);
1950- return getTrimmedShaderCacheDir () / (hashToHex (static_cast <core::blake3_hash_t >(hasher)) + " .spv" );
1994+ return getSpirvCacheDir () / (hashToHex (static_cast <core::blake3_hash_t >(hasher)) + " .spv" );
19511995 }
19521996
19531997 path getValidatedSpirvMarkerPath (const ICPUBuffer* spirvBuffer) const
19541998 {
19551999 auto contentHash = spirvBuffer->getContentHash ();
19562000 if (contentHash == ICPUBuffer::INVALID_HASH)
19572001 contentHash = spirvBuffer->computeContentHash ();
1958- return getValidatedSpirvCacheDir () / (hashToHex (contentHash) + " .hash" );
2002+ return getSpirvCacheDir () / (hashToHex (contentHash) + " .hash" );
19592003 }
19602004
19612005 size_t getBackgroundPipelineBuildBudget () const
@@ -1993,8 +2037,8 @@ class HLSLComputePathtracer final : public SimpleWindowedApplication, public Bui
19932037 void initializePipelineCache ()
19942038 {
19952039 m_pipelineCache.blobPath = getPipelineCacheBlobPath ();
1996- m_pipelineCache.trimmedShaders .rootDir = getTrimmedShaderCacheDir ();
1997- m_pipelineCache.trimmedShaders .validationDir = getValidatedSpirvCacheDir ();
2040+ m_pipelineCache.trimmedShaders .rootDir = getSpirvCacheDir ();
2041+ m_pipelineCache.trimmedShaders .validationDir = getSpirvCacheDir ();
19982042 if (!m_pipelineCache.trimmedShaders .trimmer )
19992043 m_pipelineCache.trimmedShaders .trimmer = core::make_smart_refctd_ptr<asset::ISPIRVEntryPointTrimmer>();
20002044 const auto pipelineCacheRootDir = getPipelineCacheRootDir ();
0 commit comments