1.3.72
 
Loading...
Searching...
No Matches
BackendFactory.cpp
Go to the documentation of this file.
1
16#include "RayTracingBackend.h"
17
18// Conditionally include backend headers based on compile-time definitions
19#ifdef HELIOS_HAVE_OPTIX8
20#include "OptiX8Backend.h"
21#endif
22
23#ifdef HELIOS_HAVE_OPTIX
24#include "OptiX6Backend.h"
25#endif
26
27#ifdef HELIOS_HAVE_VULKAN
29#endif
30
31namespace helios {
32
33 std::unique_ptr<RayTracingBackend> RayTracingBackend::create(const std::string &backend_type) {
34
35 // Auto-detect: probe compiled-in backends in priority order at runtime.
36 // Note: probe() verifies driver/hardware availability but not full initialization
37 // capability (e.g., missing device code files, insufficient VRAM). If initialize()
38 // fails after a successful probe, the error propagates directly — no fallthrough
39 // to the next backend.
40 if (backend_type == "auto") {
41#ifdef HELIOS_HAVE_OPTIX8
43 return std::make_unique<OptiX8Backend>();
44 }
45#endif
46#ifdef HELIOS_HAVE_OPTIX
48 return std::make_unique<OptiX6Backend>();
49 }
50#endif
51#ifdef HELIOS_HAVE_VULKAN
53 return std::make_unique<VulkanComputeBackend>();
54 }
55#endif
56 std::string compiled_backends;
57#ifdef HELIOS_HAVE_OPTIX8
58 compiled_backends += "OptiX 8.1 (NVIDIA drivers >= 560)";
59#endif
60#ifdef HELIOS_HAVE_OPTIX
61 if (!compiled_backends.empty()) compiled_backends += ", ";
62 compiled_backends += "OptiX 6.5 (NVIDIA drivers < 590)";
63#endif
64#ifdef HELIOS_HAVE_VULKAN
65 if (!compiled_backends.empty()) compiled_backends += ", ";
66 compiled_backends += "Vulkan Compute (AMD/Intel/Apple Silicon)";
67#endif
68 if (compiled_backends.empty()) {
69 compiled_backends = "(none)";
70 }
71
73 "ERROR (RayTracingBackend::create): No compatible GPU backend found.\n\n"
74 "The radiation plugin requires a GPU with one of the following:\n"
75 " - NVIDIA GPU with CUDA drivers (for OptiX backend)\n"
76 " - AMD, Intel, or Apple Silicon GPU with Vulkan support\n\n"
77 "Backends compiled into this build: " + compiled_backends + "\n"
78 "All failed hardware probing. Ensure GPU drivers are installed and up to date.\n\n"
79 "To diagnose:\n"
80 " - NVIDIA: run 'nvidia-smi' to verify driver is loaded\n"
81 " - Vulkan: run 'vulkaninfo --summary' to verify Vulkan support"
82 );
83 }
84
85#ifdef HELIOS_HAVE_OPTIX8
86 // OptiX 8.1 backend (explicit request)
87 if (backend_type == "optix8" || backend_type == "OptiX8") {
88 return std::make_unique<OptiX8Backend>();
89 }
90#endif
91
92#ifdef HELIOS_HAVE_OPTIX8
93 // "optix" / "optix6" auto-selects: prefer OptiX 8 on modern drivers
94 if (backend_type == "optix" || backend_type == "OptiX" || backend_type == "optix6" || backend_type == "OptiX6") {
95 return std::make_unique<OptiX8Backend>();
96 }
97#elif defined(HELIOS_HAVE_OPTIX)
98 // OptiX 6.5 backend (legacy drivers < 560)
99 if (backend_type == "optix6" || backend_type == "OptiX6" || backend_type == "optix" || backend_type == "OptiX") {
100 return std::make_unique<OptiX6Backend>();
101 }
102#endif
103
104#ifdef HELIOS_HAVE_VULKAN
105 // Vulkan compute backend (software BVH traversal)
106 if (backend_type == "vulkan_compute" || backend_type == "vulkan" || backend_type == "Vulkan") {
107 return std::make_unique<VulkanComputeBackend>();
108 }
109#endif
110
111 // Unknown backend type - provide helpful error message listing available backends
112 std::string available_backends;
113#ifdef HELIOS_HAVE_OPTIX8
114 available_backends += "'optix8' (OptiX 8.1), 'optix6' (auto-selects OptiX 8.1)";
115#elif defined(HELIOS_HAVE_OPTIX)
116 available_backends += "'optix6' (OptiX 6.5)";
117#endif
118#ifdef HELIOS_HAVE_VULKAN
119 if (!available_backends.empty()) {
120 available_backends += ", ";
121 }
122 available_backends += "'vulkan_compute' (Vulkan compute shaders)";
123#endif
124
125 helios_runtime_error("ERROR (RayTracingBackend::create): Unknown ray tracing backend type '" + backend_type +
126 "'. "
127 "Supported backends: " +
128 available_backends);
129
130 // Unreachable, but silence compiler warning
131 return nullptr;
132 }
133
134 bool probeAnyGPUBackend() noexcept {
135#ifdef HELIOS_HAVE_OPTIX8
136 if (OptiX8Backend::probe()) return true;
137#endif
138#ifdef HELIOS_HAVE_OPTIX
139 if (OptiX6Backend::probe()) return true;
140#endif
141#ifdef HELIOS_HAVE_VULKAN
142 if (VulkanComputeBackend::probe()) return true;
143#endif
144 return false;
145 }
146
147} // namespace helios