From 55988df821de8c6bbe22ace451efa1337cdc1680 Mon Sep 17 00:00:00 2001
From: Mike <mango@live.cn>
Date: Tue, 23 Apr 2024 18:08:50 +0800
Subject: [PATCH] add error messages for CUDA/CPU backends with mega-wave
 integrator (#28)

---
 src/integrators/megawave.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/integrators/megawave.cpp b/src/integrators/megawave.cpp
index e07de707..4e7fb8cb 100644
--- a/src/integrators/megawave.cpp
+++ b/src/integrators/megawave.cpp
@@ -266,6 +266,13 @@ class MegakernelWaveFrontInstance final : public ProgressiveIntegrator::Instance
 };
 
 luisa::unique_ptr<Integrator::Instance> MegakernelWaveFront::build(Pipeline &pipeline, CommandBuffer &command_buffer) const noexcept {
+    if (auto backend = luisa::string{pipeline.device().backend_name()}; backend == "cuda" || backend == "cpu") {
+        for (auto &c : backend) { c = static_cast<char>(std::toupper(c)); }
+        LUISA_ERROR_WITH_LOCATION("The {} backend does not support the 'meagwave' integrator: "
+                                  "thread-block synchronization is not supported inside "
+                                  "ray-tracing kernels on this backend. "
+                                  "You can use 'megapath' or 'wavepath' instead.", backend);
+    }
     return luisa::make_unique<MegakernelWaveFrontInstance>(pipeline, command_buffer, this);
 }