Skip to content

Commit 20587db

Browse files
committed
Refine path tracer cleanup
1 parent db1e1cf commit 20587db

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

31_HLSLPathTracer/main.cpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class HLSLComputePathtracer final : public SimpleWindowedApplication, public Bui
6363

6464
constexpr static inline uint32_t2 WindowDimensions = { 1280, 720 };
6565
constexpr static inline uint32_t MaxFramesInFlight = 5;
66+
static constexpr size_t BinaryToggleCount = 2ull;
6667
static constexpr std::string_view BuildConfigName = PATH_TRACER_BUILD_CONFIG_NAME;
6768
static constexpr std::string_view RuntimeConfigFilename = "path_tracer.runtime.json";
6869
static inline std::string DefaultImagePathsFile = "envmap/envmap_0.exr";
@@ -1859,7 +1860,7 @@ class HLSLComputePathtracer final : public SimpleWindowedApplication, public Bui
18591860
return nullptr;
18601861
}
18611862

1862-
shader->setFilePathHint(std::string(ShaderKey.value, ShaderKey.value + sizeof(ShaderKey.value) - 1u));
1863+
shader->setFilePathHint(std::string(std::string_view(ShaderKey.value)));
18631864
return shader;
18641865
}
18651866

@@ -1905,12 +1906,17 @@ class HLSLComputePathtracer final : public SimpleWindowedApplication, public Bui
19051906
static std::string hashToHex(const core::blake3_hash_t& hash)
19061907
{
19071908
static constexpr char digits[] = "0123456789abcdef";
1909+
static constexpr size_t HexCharsPerByte = 2ull;
1910+
static constexpr uint32_t HighNibbleBitOffset = 4u;
1911+
static constexpr uint8_t NibbleMask = 0xfu;
1912+
const auto hashByteCount = sizeof(hash.data);
19081913
std::string retval;
1909-
retval.resize(sizeof(hash.data) * 2ull);
1910-
for (size_t i = 0ull; i < sizeof(hash.data); ++i)
1914+
retval.resize(hashByteCount * HexCharsPerByte);
1915+
for (size_t i = 0ull; i < hashByteCount; ++i)
19111916
{
1912-
retval[i * 2ull + 0ull] = digits[(hash.data[i] >> 4u) & 0xfu];
1913-
retval[i * 2ull + 1ull] = digits[hash.data[i] & 0xfu];
1917+
const auto hexOffset = i * HexCharsPerByte;
1918+
retval[hexOffset] = digits[(hash.data[i] >> HighNibbleBitOffset) & NibbleMask];
1919+
retval[hexOffset + 1ull] = digits[hash.data[i] & NibbleMask];
19141920
}
19151921
return retval;
19161922
}
@@ -2004,10 +2010,11 @@ class HLSLComputePathtracer final : public SimpleWindowedApplication, public Bui
20042010

20052011
size_t getBackgroundPipelineBuildBudget() const
20062012
{
2013+
static constexpr uint32_t ReservedForegroundThreadCount = 1u;
20072014
const auto concurrency = std::thread::hardware_concurrency();
2008-
if (concurrency > 1u)
2009-
return static_cast<size_t>(concurrency - 1u);
2010-
return 1ull;
2015+
if (concurrency > ReservedForegroundThreadCount)
2016+
return static_cast<size_t>(concurrency - ReservedForegroundThreadCount);
2017+
return ReservedForegroundThreadCount;
20112018
}
20122019

20132020
bool ensureCacheDirectoryExists(const path& dir, const char* const description)
@@ -2387,7 +2394,8 @@ class HLSLComputePathtracer final : public SimpleWindowedApplication, public Bui
23872394
if (!m_pipelineCache.warmup.started || m_pipelineCache.warmup.loggedComplete)
23882395
return;
23892396

2390-
if (m_pipelineCache.newlyReadyPipelinesSinceLastSave < 4ull)
2397+
static constexpr size_t WarmupCheckpointThreshold = 4ull;
2398+
if (m_pipelineCache.newlyReadyPipelinesSinceLastSave < WarmupCheckpointThreshold)
23912399
return;
23922400

23932401
const auto elapsedSinceLastSave = std::chrono::duration_cast<std::chrono::milliseconds>(clock_t::now() - m_pipelineCache.lastSaveAt).count();
@@ -2443,13 +2451,13 @@ class HLSLComputePathtracer final : public SimpleWindowedApplication, public Bui
24432451
using pipeline_future_array_t = std::array<pipeline_future_method_array_t, E_LIGHT_GEOMETRY::ELG_COUNT>;
24442452
struct SRenderPipelineStorage
24452453
{
2446-
shader_array_t shaders[2][2] = {};
2447-
pipeline_array_t pipelines[2][2] = {};
2448-
pipeline_future_array_t pendingPipelines[2][2] = {};
2454+
std::array<std::array<shader_array_t, BinaryToggleCount>, BinaryToggleCount> shaders = {};
2455+
std::array<std::array<pipeline_array_t, BinaryToggleCount>, BinaryToggleCount> pipelines = {};
2456+
std::array<std::array<pipeline_future_array_t, BinaryToggleCount>, BinaryToggleCount> pendingPipelines = {};
24492457

24502458
static constexpr size_t boolToIndex(const bool value)
24512459
{
2452-
return value ? 1ull : 0ull;
2460+
return static_cast<size_t>(value);
24532461
}
24542462

24552463
shader_array_t& getShaders(const bool persistentWorkGroups, const bool rwmc)
@@ -2684,12 +2692,12 @@ class HLSLComputePathtracer final : public SimpleWindowedApplication, public Bui
26842692
size_t getKnownRenderPipelineCount() const
26852693
{
26862694
size_t count = 0ull;
2687-
bool seen[ELG_COUNT][2][2][EPM_COUNT] = {};
2695+
bool seen[ELG_COUNT][BinaryToggleCount][BinaryToggleCount][EPM_COUNT] = {};
26882696
for (auto geometry = 0u; geometry < ELG_COUNT; ++geometry)
26892697
{
2690-
for (auto persistentWorkGroups = 0u; persistentWorkGroups < 2u; ++persistentWorkGroups)
2698+
for (auto persistentWorkGroups = 0u; persistentWorkGroups < BinaryToggleCount; ++persistentWorkGroups)
26912699
{
2692-
for (auto rwmc = 0u; rwmc < 2u; ++rwmc)
2700+
for (auto rwmc = 0u; rwmc < BinaryToggleCount; ++rwmc)
26932701
{
26942702
for (auto method = 0u; method < EPM_COUNT; ++method)
26952703
{

0 commit comments

Comments
 (0)