From 170fd918cae24b91d03bf0bf89be2b5c928bd206 Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Thu, 28 May 2026 18:32:01 -0400 Subject: [PATCH 1/3] build(cmake): make generated PTX available via build ptx dir - Add a stable build-tree PTX output directory at `${PROJECT_BINARY_DIR}/ptx` - Copy generated OptiX PTX files into that directory via a `gphox_ptx` target --- CMakeLists.txt | 1 + CSGOptiX/CMakeLists.txt | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 571dce106..aa0ef6670 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,7 @@ endif() # used by src/config.h.in set(GPHOX_INSTALL_FULL_DATADIR "${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}") +set(GPHOX_BUILD_PTX_DIR "${PROJECT_BINARY_DIR}/ptx") add_subdirectory(sysrap) add_subdirectory(sysrap/tests) diff --git a/CSGOptiX/CMakeLists.txt b/CSGOptiX/CMakeLists.txt index 6a90da7dd..b307b9f41 100644 --- a/CSGOptiX/CMakeLists.txt +++ b/CSGOptiX/CMakeLists.txt @@ -37,9 +37,20 @@ target_compile_definitions(${OPTIX_PTX_TARGET} PUBLIC WITH_PRD WITH_SIMULATE WIT PLOG_LOCAL RNG_PHILOX DEBUG_TAG DEBUG_PIDX DEBUG_PIDXYZ OPTICKS_OKCONF OPTICKS_QUDARAP NVCC) target_link_libraries(${OPTIX_PTX_TARGET} PUBLIC OptiX::OptiX) +get_filename_component(ptx_stem "${OPTIX_PTX_SRC}" NAME_WE) +set(ptx_output "${GPHOX_BUILD_PTX_DIR}/${ptx_stem}.ptx") +add_custom_target(gphox_ptx + COMMAND ${CMAKE_COMMAND} -E make_directory "${GPHOX_BUILD_PTX_DIR}" + COMMAND ${CMAKE_COMMAND} -E copy_if_different "$" "${ptx_output}" + BYPRODUCTS "${ptx_output}" + VERBATIM +) +add_dependencies(gphox_ptx ${OPTIX_PTX_TARGET}) + message(STATUS "Configured PTX build for ${OPTIX_PTX_SRC}") add_library( ${name} SHARED ${SOURCES} ${HEADERS} ) +add_dependencies(${name} gphox_ptx) target_compile_definitions( ${name} PRIVATE WITH_PRD ) # using Pointer trick means can reduce attrib and payload to 2 target_compile_definitions( ${name} PUBLIC WITH_SIMULATE ) From fef177cff35fd853e9698d0aebbcb63df9cdbc3f Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Fri, 5 Jun 2026 17:27:43 -0400 Subject: [PATCH 2/3] build(config): add PTX search path and share search-path parsing --- src/config.cpp | 48 +++++++++++++++++++++++++++++--------------- src/config_path.h.in | 2 +- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index 8644bbcaa..3d1a66261 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -64,6 +65,22 @@ bool FileExists(const std::string& path) return std::filesystem::exists(path, ec) && !ec; } +std::vector SplitSearchPaths(std::string_view paths) +{ + std::vector search_paths; + + size_t last = 0; + size_t next = 0; + while ((next = paths.find(':', last)) != std::string_view::npos) + { + search_paths.push_back(std::string{paths.substr(last, next - last)}); + last = next + 1; + } + + search_paths.push_back(std::string{paths.substr(last)}); + return search_paths; +} + std::string ValidEventModes() { std::string names; @@ -178,15 +195,24 @@ std::string Config::PtxPath(const std::string& ptx_name) if (env_path && FileExists(env_path)) return env_path; - std::string default_path = std::string(GPHOX_PTX_DIR) + "/" + ptx_name; - if (FileExists(default_path)) - return default_path; + std::vector candidates; + for (const auto& dir : SplitSearchPaths(GPHOX_PTX_SEARCH_PATHS)) + { + if (dir.empty()) + continue; + + std::string candidate = (std::filesystem::path{dir} / ptx_name).string(); + candidates.push_back(candidate); + if (FileExists(candidate)) + return candidate; + } std::stringstream errmsg; errmsg << "Could not resolve PTX file \"" << ptx_name << "\".\n" << "Expected one of:\n" - << " - " << GPHOX_PTX_PATH_ENV << "=\n" - << " - " << default_path; + << " - " << GPHOX_PTX_PATH_ENV << "=\n"; + for (const auto& candidate : candidates) + errmsg << " - " << candidate << "\n"; throw std::runtime_error(errmsg.str()); } @@ -198,17 +224,7 @@ std::string Config::Locate(std::string filename) const if (user_dir.empty()) { - std::string paths(GPHOX_CONFIG_SEARCH_PATHS); - - size_t last = 0; - size_t next = 0; - while ((next = paths.find(':', last)) != std::string::npos) - { - search_paths.push_back(paths.substr(last, next - last)); - last = next + 1; - } - - search_paths.push_back(paths.substr(last)); + search_paths = SplitSearchPaths(GPHOX_CONFIG_SEARCH_PATHS); } else { diff --git a/src/config_path.h.in b/src/config_path.h.in index 19bda3687..3d5f1f0b7 100644 --- a/src/config_path.h.in +++ b/src/config_path.h.in @@ -1,4 +1,4 @@ #pragma once #define GPHOX_CONFIG_SEARCH_PATHS ".:config:@GPHOX_INSTALL_FULL_DATADIR@/config" -#define GPHOX_PTX_DIR "@CMAKE_INSTALL_FULL_LIBDIR@" +#define GPHOX_PTX_SEARCH_PATHS "@GPHOX_BUILD_PTX_DIR@:@CMAKE_INSTALL_FULL_LIBDIR@" From 325ac64ce0611b361212be3da36cf473aeb84751 Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Fri, 5 Jun 2026 18:05:46 -0400 Subject: [PATCH 3/3] fix: prioritize install libdir before the build-tree PTX dir --- src/config_path.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config_path.h.in b/src/config_path.h.in index 3d5f1f0b7..f602e7ceb 100644 --- a/src/config_path.h.in +++ b/src/config_path.h.in @@ -1,4 +1,4 @@ #pragma once #define GPHOX_CONFIG_SEARCH_PATHS ".:config:@GPHOX_INSTALL_FULL_DATADIR@/config" -#define GPHOX_PTX_SEARCH_PATHS "@GPHOX_BUILD_PTX_DIR@:@CMAKE_INSTALL_FULL_LIBDIR@" +#define GPHOX_PTX_SEARCH_PATHS "@CMAKE_INSTALL_FULL_LIBDIR@:@GPHOX_BUILD_PTX_DIR@"