refactor: extract duplicated magic numbers to Constants.h and ISPC#49
Conversation
|
I've reviewed the full diff. Here's my analysis: Bug FoundBVH.h missing
|
|
Now I have the complete picture. Here's my review: Review SummaryThe refactor is clean and consistent — all 4 magic numbers are correctly extracted across all 8 files. The prior reviewer's feedback was already addressed in commit 2 (adding Bug: Missed hardcoded
|
|
Here's my review of the PR: Verified: Both prior review issues are resolvedThe New finding: Missing BVH stack overflow guards (pre-existing)The GPU path has a guard (
With Other observations
VerdictLGTM. The refactor is correct and consistent. All 4 magic numbers are unified across 8 files with no regressions. The prior reviewers' bugs were already addressed. Merge-ready. |
BT.709 luminance (0.2126/0.7152/0.0722) → kLuminanceR/G/B ONB threshold 0.9999f → kONBThreshold MB conversion 1024*1024 → kBytesPerMB BVH stack depth 64 → kBVHMaxStackDepth Updated: Constants.h, CUDARenderer.cuh, CPUBackend.cpp, PathTracerCore.h, BVH.h, CUDARenderer.cu, OptiXDenoiser.cpp, PathTracer.ispc (ISPC keeps own static const equivalents)
… (review feedback)
70ec6a7 to
033e65e
Compare
PR Review —
|
| Constant | Value | Occurrences | Files |
|---|---|---|---|
kLuminanceR/G/B |
BT.709 | 3 paths | CPUBackend, CUDARenderer.cuh, PathTracer.ispc |
kONBThreshold |
0.9999f |
3 paths | PathTracerCore.h, CUDARenderer.cuh, PathTracer.ispc |
kBVHMaxStackDepth |
64 |
3 paths + guard | BVH.h, CUDARenderer.cuh, PathTracer.ispc |
kBytesPerMB |
1024*1024 |
2 prints | CUDARenderer.cu, OptiXDenoiser.cpp |
No leftover raw literals. All ISPC constants match C++ values exactly.
Minor Observations (non-blocking)
-
kBytesPerMBasconstexpr int— every usage casts tosize_torfloat. Aconstexpr size_twould be semantically more appropriate. Minor. -
Missing BVH stack overflow guards (pre-existing) —
BVH.h:147-153andPathTracer.ispc:235-236push children unconditionally without astackPtr + 2 <= kBVHMaxStackDepthguard (unlikeCUDARenderer.cuh:283). Harmless with 7 spheres + depth 64, but the constant extraction makes the asymmetry more visible. Worth fixing in a follow-up. -
kONBThresholdnaming — functional but slightly vague;kONBDegeneracyThresholdwould be more self-documenting. Minor.
Verdict
LGTM. Merge-ready.
…ompatibility ISPC does not treat static const int as a compile-time integer constant usable in array dimensions. Use #define kBVHMaxStackDepth 64 instead.
PR Review —
|
| Constant | Value | Occurrences | Paths |
|---|---|---|---|
kLuminanceR/G/B |
BT.709 | 3 | CPU C++, CUDA, ISPC |
kONBThreshold |
0.9999f |
3 | PathTracerCore.h, CUDA, ISPC |
kBVHMaxStackDepth |
64 |
3 + guard | BVH.h, CUDA, ISPC |
kBytesPerMB |
1024*1024 |
2 | CUDARenderer.cu, OptiXDenoiser.cpp |
ISPC correctly uses #define for kBVHMaxStackDepth (ISPC requires compile-time array dimensions, static const int won't work).
Minor Observations (non-blocking)
-
kBytesPerMBasconstexpr int— every usage casts tosize_torfloat. Aconstexpr size_twould be semantically cleaner and eliminate thesize_tcast. Minor. -
Pre-existing: missing BVH stack overflow guards —
BVH.h:147-153andPathTracer.ispc:235-236push children unconditionally without bounds checks, unlike the GPU path (CUDARenderer.cuh:283). Harmless with 7 spheres + depth 64, but the constant extraction makes the asymmetry more visible. Worth a follow-up fix.
Verdict
LGTM. Merge-ready.





Closes #44. 4 magic numbers → named constants across 8 files (+35 -12).