Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions CSGOptiX/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$<TARGET_OBJECTS:${OPTIX_PTX_TARGET}>" "${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 )
Expand Down
48 changes: 32 additions & 16 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <fstream>
#include <iostream>
#include <ranges>
#include <sstream>
#include <stdexcept>
#include <string>
#include <string_view>
Expand Down Expand Up @@ -64,6 +65,22 @@ bool FileExists(const std::string& path)
return std::filesystem::exists(path, ec) && !ec;
}

std::vector<std::string> SplitSearchPaths(std::string_view paths)
{
std::vector<std::string> 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;
}
Comment on lines +68 to +82
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is true for Windows-style drive-letter paths, but Simphony currently does not support Windows and the existing config search path convention is already Unix-style colon separation. I’m going to keep the current parser scoped to supported platforms for now.


std::string ValidEventModes()
{
std::string names;
Expand Down Expand Up @@ -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<std::string> 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 << "=<path-to-ptx>\n"
<< " - " << default_path;
<< " - " << GPHOX_PTX_PATH_ENV << "=<path-to-ptx>\n";
for (const auto& candidate : candidates)
errmsg << " - " << candidate << "\n";
throw std::runtime_error(errmsg.str());
}

Expand All @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/config_path.h.in
Original file line number Diff line number Diff line change
@@ -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 "@CMAKE_INSTALL_FULL_LIBDIR@:@GPHOX_BUILD_PTX_DIR@"
Comment on lines 3 to +4
Loading