diff --git a/.gitmodules b/.gitmodules index b97b6d690..59774a5fc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,9 +7,6 @@ [submodule "Extern/googletest"] path = Extern/googletest url = https://github.com/google/googletest -[submodule "Extern/VMA"] - path = Extern/VMA - url = https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator [submodule "Extern/imgui"] path = Extern/imgui url = https://github.com/ocornut/imgui diff --git a/CMakeLists.txt b/CMakeLists.txt index c928ac03a..f56973a10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,9 @@ option(RAYX_ENABLE_OPENMP "This option enables the search for OPENMP. Project wi option(RAYX_REQUIRE_OPENMP "If option 'RAYX_ENABLE_OPENMP' is ON, this option will add the requirement that openmp must be found." OFF) option(RAYX_ENABLE_H5 "This option enables the search for HDF5. Project will be compiled without HDF5 if not found." ON) option(RAYX_REQUIRE_H5 "If option 'RAYX_ENABLE_H5' is ON, this option will add the requirement that HDF5 must be found." OFF) +option(RAYX_BUILD_RAYX_CLI "This option builds the RAYX command line interface." ON) +option(RAYX_BUILD_RAYX_UI "This option builds the RAYX graphical user interface." ON) +option(RAYX_BUILD_RAYX_TESTS "This option builds the RAYX test suite." ON) option(RAYX_STATIC_LIB "This option builds 'rayx-core' as a static library." OFF) # ------------------ diff --git a/Extern/CMakeLists.txt b/Extern/CMakeLists.txt index 2671fe84b..70b028c9e 100644 --- a/Extern/CMakeLists.txt +++ b/Extern/CMakeLists.txt @@ -1,27 +1,6 @@ cmake_minimum_required(VERSION 3.24 FATAL_ERROR) include(CheckLanguage) -set(gtest_force_shared_crt ON CACHE BOOL "Always use msvcrt.dll" FORCE) - -add_subdirectory(googletest) - -# support version in CMakeLists.txt of portable-file-dialogs was removed from cmake. thus we include the header only library by hand -add_library(portable_file_dialogs INTERFACE) -target_include_directories(portable_file_dialogs INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/portable-file-dialogs) - -# --- CLI11 --- -set(CLI11_SANITIZERS OFF) -set(CLI11_BUILD_DOCS OFF) -set(CLI11_BUILD_TESTS OFF) -set(CLI11_BUILD_EXAMPLES OFF) -set(CLI11_BUILD_EXAMPLES_JSON OFF) -set(CLI11_SINGLE_FILE_TESTS OFF) -set(CLI11_INSTALL OFF) -set(CLI11_FORCE_LIBCXX OFF) -set(CLI11_CUDA_TESTS OFF) -set(CLI11_CLANG_TIDY OFF) -add_subdirectory(CLI11) - # --- alpaka --- # alpaka openmp backend @@ -97,5 +76,32 @@ if(RAYX_ENABLE_H5) endif() endif() +if (RAYX_BUILD_TESTS) + set(gtest_force_shared_crt ON CACHE BOOL "Always use msvcrt.dll" FORCE) + + add_subdirectory(googletest) +endif() + +# --- CLI11 --- +if (RAYX_BUILD_RAYX_CLI) + set(CLI11_SANITIZERS OFF) + set(CLI11_BUILD_DOCS OFF) + set(CLI11_BUILD_TESTS OFF) + set(CLI11_BUILD_EXAMPLES OFF) + set(CLI11_BUILD_EXAMPLES_JSON OFF) + set(CLI11_SINGLE_FILE_TESTS OFF) + set(CLI11_INSTALL OFF) + set(CLI11_FORCE_LIBCXX OFF) + set(CLI11_CUDA_TESTS OFF) + set(CLI11_CLANG_TIDY OFF) + add_subdirectory(CLI11) +endif() + # --- SDL --- -add_subdirectory(SDL EXCLUDE_FROM_ALL) +if(RAYX_BUILD_RAYX_UI) + # support version in CMakeLists.txt of portable-file-dialogs was removed from cmake. thus we include the header only library by hand + add_library(portable_file_dialogs INTERFACE) + target_include_directories(portable_file_dialogs INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/portable-file-dialogs) + + add_subdirectory(SDL EXCLUDE_FROM_ALL) +endif() diff --git a/Extern/VMA b/Extern/VMA deleted file mode 160000 index 009ecd192..000000000 --- a/Extern/VMA +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 009ecd192c1289c7529bff248a16cfe896254816 diff --git a/Intern/CMakeLists.txt b/Intern/CMakeLists.txt index 3dc68ae75..ad6b44196 100644 --- a/Intern/CMakeLists.txt +++ b/Intern/CMakeLists.txt @@ -12,13 +12,15 @@ endif() # ---- Subdirectories ---- add_subdirectory(rayx-core) -if(NOT RAYX_CMD STREQUAL "NO") +if(RAYX_BUILD_RAYX_CLI) add_subdirectory(rayx) endif() -# Don't build rayx-ui without Vulkan -if(NOT VULKAN STREQUAL "NO") - add_subdirectory(rayx-ui) +if(RAYX_BUILD_RAYX_UI) + # Don't build rayx-ui without Vulkan + if(NOT VULKAN STREQUAL "NO") + add_subdirectory(rayx-ui) + endif() endif() # ------------------------ diff --git a/Intern/rayx-core/CMakeLists.txt b/Intern/rayx-core/CMakeLists.txt index efcb0eda4..c70129de3 100644 --- a/Intern/rayx-core/CMakeLists.txt +++ b/Intern/rayx-core/CMakeLists.txt @@ -46,7 +46,9 @@ endif() # ----------------------- # ---- Add tests ---- - add_subdirectory(tests) +if(RAYX_BUILD_RAYX_TESTS) + add_subdirectory(tests) +endif() # ------------------- @@ -192,7 +194,6 @@ target_include_directories(${PROJECT_NAME} SYSTEM INTERFACE ${PROJECT_SOURCE_DIR target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${PROJECT_SOURCE_DIR}/../../Extern/glm/glm/ ${PROJECT_SOURCE_DIR}/../../Extern/rapidxml-1.13/ - ${PROJECT_SOURCE_DIR}/../../Extern/VMA/include/ ${PROJECT_SOURCE_DIR}/../../Extern/alpaka/include/ ) target_link_libraries(${PROJECT_NAME} PUBLIC alpaka::alpaka) diff --git a/Intern/rayx-core/src/Core.h b/Intern/rayx-core/src/Core.h index cc73555e1..57b0a9e6d 100644 --- a/Intern/rayx-core/src/Core.h +++ b/Intern/rayx-core/src/Core.h @@ -1,16 +1,5 @@ #pragma once -// Memory leak detection (RAYX_NEW instead of new allows leaks to be detected) -#ifdef RAYX_DEBUG_MODE -#ifdef RAYX_PLATFORM_MSVC -#define _CRTDBG_MAP_ALLOC -#include -#endif -#define RAYX_NEW new (_NORMAL_BLOCK, __FILE__, __LINE__) -#else -#define RAYX_NEW new -#endif - /** * Defining the RAYX_API macro, which helps with * building the library (context based import/export of code). @@ -41,13 +30,6 @@ #endif #endif -// make string comparison available for msvc compiler -// not #if defined(_WIN32) || defined(_WIN64) because we have strncasecmp in mingw -#ifdef _MSC_VER -#define strncasecmp _strnicmp -#define strcasecmp _stricmp -#endif - #ifdef RAYX_BUILD_DLL #include #define RAYX_FN_ACC ALPAKA_FN_ACC diff --git a/Intern/rayx-core/src/Shader/LightSources/EnergyDistributions/EnergyDistribution.h b/Intern/rayx-core/src/Shader/LightSources/EnergyDistributions/EnergyDistribution.h index 5629f7503..acfad8783 100644 --- a/Intern/rayx-core/src/Shader/LightSources/EnergyDistributions/EnergyDistribution.h +++ b/Intern/rayx-core/src/Shader/LightSources/EnergyDistributions/EnergyDistribution.h @@ -16,13 +16,14 @@ struct EnergyDistributionList { }; struct EnergyDistributionDataBase { - using HardEdge = rayx::HardEdge; - using SoftEdge = rayx::SoftEdge; - using SeparateEnergies = rayx::SeparateEnergies; + using HardEdge = rayx::HardEdge; + using SoftEdge = rayx::SoftEdge; + using SeparateEnergies = rayx::SeparateEnergies; using EnergyDistributionList = rayx::EnergyDistributionList; }; -using EnergyDistributionDataVariant = Variant; +using EnergyDistributionDataVariant = Variant; RAYX_FN_ACC double selectEnergy(const HardEdge& __restrict hardEdge, Rand& __restrict rand); RAYX_FN_ACC double selectEnergy(const SoftEdge& __restrict softEdge, Rand& __restrict rand); diff --git a/Intern/rayx-core/src/Tracer/DeviceConfig.cpp b/Intern/rayx-core/src/Tracer/DeviceConfig.cpp index fc561c04c..4470a8028 100644 --- a/Intern/rayx-core/src/Tracer/DeviceConfig.cpp +++ b/Intern/rayx-core/src/Tracer/DeviceConfig.cpp @@ -20,7 +20,11 @@ DeviceType platformToDeviceType(); template <> DeviceType platformToDeviceType() { - return DeviceType::Cpu; +#if defined(RAYX_OPENMP_ENABLED) + return DeviceType::CpuParallel; +#else + return DeviceType::CpuSerial; +#endif } #if defined(RAYX_CUDA_ENABLED) @@ -30,13 +34,6 @@ DeviceType platformToDeviceType() { } #endif -#if defined(RAYX_HIP_ENABLED) -template <> -DeviceType platformToDeviceType() { - return DeviceType::GpuHip; -} -#endif - template std::vector getAvailableDevicesProps() { std::vector devices; @@ -80,31 +77,26 @@ std::vector getAvailableDevices(DeviceType deviceType = DeviceType::All) }; #if defined(RAYX_OPENMP_ENABLED) - using TagCpu = alpaka::TagCpuOmp2Blocks; + if (deviceType & DeviceType::CpuParallel) append(alpaka::TagCpuOmp2Blocks{}); #else - using TagCpu = alpaka::TagCpuSerial; + if (deviceType & DeviceType::CpuSerial) append(alpaka::TagCpuSerial{}); #endif - if (deviceType & DeviceType::Cpu) append(TagCpu{}); #if defined(RAYX_CUDA_ENABLED) if (deviceType & DeviceType::GpuCuda) append(alpaka::TagGpuCudaRt{}); #endif -#if defined(RAYX_HIP_ENABLED) - if (deviceType & DeviceType::GpuHip) append(alpaka::TagGpuHipRt{}); -#endif - return devices; } std::string deviceTypeToString(DeviceType deviceType) { std::vector names; - if (deviceType & DeviceType::Cpu) names.push_back("Cpu"); + if (deviceType & DeviceType::CpuSerial) names.push_back("CpuSerial"); + if (deviceType & DeviceType::CpuParallel) names.push_back("CpuParallel"); if (deviceType & DeviceType::GpuCuda) names.push_back("GpuCuda"); - if (deviceType & DeviceType::GpuHip) names.push_back("GpuHip"); - if (names.empty()) names.push_back("Unsupported"); + if (names.empty()) names.push_back("None"); std::stringstream ss; @@ -130,6 +122,10 @@ void DeviceConfig::dumpDevices() const { const auto& device = devices[i]; RAYX_LOG << "Device - index: " << i << ", type: " << deviceTypeToString(device.type) << ", name: " << device.name; } + +#if !defined(RAYX_CUDA_ENABLED) + if (!(m_fetchedDeviceType & DeviceType::Cpu)) RAYX_WARN << "GPU support is not enabled in this build."; +#endif } size_t DeviceConfig::enabledDevicesCount() const { @@ -192,4 +188,20 @@ DeviceConfig& DeviceConfig::enableBestDevice(DeviceType deviceType) { return *this; } +DeviceConfig::DeviceType DeviceConfig::availableDeviceTypes() { + DeviceType deviceType = DeviceType::None; + +#if defined(RAYX_OPENMP_ENABLED) + deviceType = static_cast(deviceType | DeviceType::CpuParallel); +#else + deviceType = static_cast(deviceType | DeviceType::CpuSerial); +#endif + +#if defined(RAYX_CUDA_ENABLED) + deviceType = static_cast(deviceType | DeviceType::GpuCuda); +#endif + + return deviceType; +} + } // namespace rayx diff --git a/Intern/rayx-core/src/Tracer/DeviceConfig.h b/Intern/rayx-core/src/Tracer/DeviceConfig.h index 319b14309..327cb9db5 100644 --- a/Intern/rayx-core/src/Tracer/DeviceConfig.h +++ b/Intern/rayx-core/src/Tracer/DeviceConfig.h @@ -9,11 +9,12 @@ namespace rayx { struct RAYX_API DeviceConfig { enum RAYX_API DeviceType { - Unsupported = 0, - Cpu = 1 << 0, - GpuCuda = 1 << 1, - GpuHip = 1 << 2, - Gpu = GpuCuda | GpuHip, + None = 0, + CpuSerial = 1 << 0, + CpuParallel = 1 << 1, + Cpu = CpuSerial | CpuParallel, + GpuCuda = 1 << 2, + Gpu = GpuCuda, All = Cpu | Gpu, }; @@ -46,6 +47,8 @@ struct RAYX_API DeviceConfig { DeviceConfig& enableBestDevice(DeviceType deviceType = DeviceType::All); + static DeviceType availableDeviceTypes(); + std::vector devices; private: diff --git a/Intern/rayx-core/src/Tracer/Tracer.cpp b/Intern/rayx-core/src/Tracer/Tracer.cpp index 8f90d2df5..61baf7f19 100644 --- a/Intern/rayx-core/src/Tracer/Tracer.cpp +++ b/Intern/rayx-core/src/Tracer/Tracer.cpp @@ -17,13 +17,6 @@ inline std::shared_ptr createDeviceTracer(DeviceType deviceT #else RAYX_EXIT << "Failed to create Tracer with Cuda device. Cuda was disabled during build."; return nullptr; -#endif - case DeviceType::GpuHip: -#if defined(RAYX_HIP_ENABLED) - eturn std::make_shared>(deviceIndex); -#else - RAYX_EXIT << "Failed to create Tracer with Hip device. Hip was disabled during build."; - return nullptr; #endif default: // case DeviceType::Cpu #if defined(RAYX_OPENMP_ENABLED) diff --git a/Scripts/shell.nix b/Scripts/shell.nix index 170c62dd5..3a33eccc0 100644 --- a/Scripts/shell.nix +++ b/Scripts/shell.nix @@ -21,6 +21,10 @@ pkgs.mkShell { gdb cmake ninja + llvmPackages.openmp + # cudaPackages.cuda_cudart + # cudaPackages.cuda_nvcc + # cudaPackages.cuda_cccl # rayx-core dependencies hdf5 @@ -30,6 +34,7 @@ pkgs.mkShell { vulkan-headers vulkan-loader vulkan-validation-layers + vulkan-extension-layer vulkan-tools vulkan-tools-lunarg vulkan-utility-libraries @@ -52,7 +57,7 @@ pkgs.mkShell { ]; shellHook = '' - export CMAKE_PREFIX_PATH=${pkgs.boost}:${pkgs.hdf5}:${pkgs.cmake}:${pkgs.pkg-config}; + export CMAKE_PREFIX_PATH=${pkgs.hdf5}:${pkgs.cmake}:${pkgs.pkg-config}:${pkgs.vulkan-headers}:${pkgs.vulkan-loader}:${pkgs.vulkan-validation-layers}:${pkgs.vulkan-extension-layer}:${pkgs.vulkan-tools}:${pkgs.vulkan-tools-lunarg}:${pkgs.vulkan-utility-libraries}; export VK_LAYER_PATH="${pkgs.vulkan-validation-layers}/share/vulkan/explicit_layer.d"; ''; } diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..f525e56d8 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1763049705, + "narHash": "sha256-A5LS0AJZ1yDPTa2fHxufZN++n8MCmtgrJDtxFxrH4S8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3acb677ea67d4c6218f33de0db0955f116b7588c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-25.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..c9a9ba739 --- /dev/null +++ b/flake.nix @@ -0,0 +1,131 @@ +{ + description = "RAYX simulation tool with CUDA, OpenMP, valgrind, and Ninja build"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; + }; + + outputs = { self, nixpkgs }: + let + version = "1.1.0"; + supportedSystems = [ "x86_64-linux" ]; # TODO: add support for "x86_64-darwin" "aarch64-linux" "aarch64-darwin" + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; config.allowUnfree = true; }); + in { + packages = forAllSystems (system: + let + pkgs = nixpkgsFor.${system}; + pkgsUnfree = nixpkgsFor.${system}; + + src = pkgs.fetchgit { + url = "https://github.com/hz-b/rayx"; + rev = "5694a0117e7d8e58a1b19f35202891270dc5ee91"; # git commit hash for desired version + sha256 = "sha256-clfHvQK9JI/TWDmpXiTtBie4q++F9+F37uzTvLqvMlc="; # fill after build failure + fetchSubmodules = true; + }; + + commonNativeBuildInputs = with pkgs; [ + cmake + gcc + llvmPackages.openmp + ninja + ]; + + commonBuildInputs = with pkgs; [ + hdf5 + ]; + + commonCmakeConfigureFlags = '' + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_SKIP_BUILD_RPATH=ON \ + -DRAYX_REQUIRE_CUDA=ON \ + -DRAYX_ENABLE_OPENMP=ON \ + -DRAYX_REQUIRE_OPENMP=ON \ + -DRAYX_ENABLE_H5=ON \ + -DRAYX_REQUIRE_H5=ON \ + -DRAYX_WERROR=OFF \ + -DRAYX_BUILD_TESTS=OFF \ + -DRAYX_BUILD_RAYX_CLI=ON \ + -DRAYX_BUILD_RAYX_UI=OFF + ''; + in + { + rayx = pkgs.stdenv.mkDerivation { + pname = "rayx"; + inherit version; + inherit src; + + nativeBuildInputs = with pkgs; [ + ] ++ commonNativeBuildInputs; + + buildInputs = with pkgs; [ + ] ++ commonBuildInputs; + + configurePhase = '' + mkdir build + cd build + cmake -G Ninja .. \ + -DRAYX_ENABLE_CUDA=OFF \ + ${commonCmakeConfigureFlags} + ''; + + buildPhase = '' + ninja -v rayx + ''; + + installPhase = '' + mkdir -p $out/bin + cp -r bin/release/Data $out/bin + cp -r bin/release/rayx $out/bin/ + + mkdir -p $out/lib + cp -r lib/release/* $out/lib + ''; + + meta.description = "TODO"; # TODO: write description + }; + + rayx-cuda = pkgs.stdenv.mkDerivation { + pname = "rayx-cuda"; + inherit version; + inherit src; + + nativeBuildInputs = with pkgs; [ + cudaPackages.cuda_nvcc + cudaPackages.cuda_cccl + ] ++ commonNativeBuildInputs; + + buildInputs = with pkgs; [ + cudaPackages.cuda_cudart + ] ++ commonBuildInputs; + + configurePhase = '' + mkdir build + cd build + cmake -G Ninja .. \ + -DRAYX_ENABLE_CUDA=ON \ + ${commonCmakeConfigureFlags} + ''; + + buildPhase = '' + ninja -v rayx + ''; + + installPhase = '' + mkdir -p $out/bin + cp -r bin/release/Data $out/bin + cp -r bin/release/rayx $out/bin + mv $out/bin/rayx $out/bin/rayx-cuda + + mkdir -p $out/lib + cp -r lib/release/* $out/lib + ''; + + meta.description = "TODO"; # TODO: write description + }; + + default = self.packages.${system}.rayx; + } + ); + }; +}