Skip to content

Commit

Permalink
update compute and add support for fallback backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-Leo-Smith committed Jan 10, 2025
1 parent 2df84d1 commit 2c9c69f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[submodule "src/compute"]
path = src/compute
url = https://github.com/LuisaGroup/LuisaCompute.git
branch = stable
branch = next
[submodule "src/ext/json"]
path = src/ext/json
url = https://github.com/nlohmann/json.git
35 changes: 31 additions & 4 deletions src/base/geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ Var<Hit> Geometry::trace_closest(const Var<Ray> &ray_in) const noexcept {
return Var<Hit>{hit.inst, hit.prim, hit.bary};
}
// TODO: DirectX has bug with ray query, so we manually march the ray here
if (_pipeline.device().backend_name() == "dx") {
// TODO: Fallback backend has not implemented ray query yet, so we manually march the ray here
if (_pipeline.device().backend_name() == "dx" || _pipeline.device().backend_name() == "fallback") {
auto ray = ray_in;
auto hit = _accel->intersect(ray, {});
constexpr auto max_iterations = 100u;
Expand Down Expand Up @@ -261,10 +262,36 @@ Var<Hit> Geometry::trace_closest(const Var<Ray> &ray_in) const noexcept {
return impl(ray_in);
}

Var<bool> Geometry::trace_any(const Var<Ray> &ray) const noexcept {
Var<bool> Geometry::trace_any(const Var<Ray> &ray_in) const noexcept {
if (!_any_non_opaque) {
// happy path
return _accel->intersect_any(ray, {});
return _accel->intersect_any(ray_in, {});
}
// TODO: Fallback backend has not implemented ray query yet, so we manually march the ray here
if (_pipeline.device().backend_name() == "fallback") {
auto ray = ray_in;
auto any_hit = def(false);
constexpr auto max_iterations = 100u;
constexpr auto epsilone = 1e-5f;
$for (i [[maybe_unused]], max_iterations) {
auto hit = _accel->intersect(ray, {});
$if (hit->miss()) { $break; };
$if (!this->_alpha_skip(ray, hit)) {
any_hit = true;
$break;
};
#ifndef NDEBUG
$if (i == max_iterations - 1u) {
compute::device_log(luisa::format(
"ERROR: max iterations ({}) exceeded in trace any",
max_iterations));
};
#endif
ray = compute::make_ray(ray->origin(), ray->direction(),
hit.committed_ray_t + epsilone,
ray->t_max());
};
return any_hit;
}
Callable impl = [this](Var<Ray> ray) noexcept {
auto rq_hit =
Expand All @@ -277,7 +304,7 @@ Var<bool> Geometry::trace_any(const Var<Ray> &ray) const noexcept {
.trace();
return !rq_hit->miss();
};
return impl(ray);
return impl(ray_in);
}

luisa::shared_ptr<Interaction> Geometry::interaction(Expr<uint> inst_id, Expr<uint> prim_id,
Expand Down
4 changes: 2 additions & 2 deletions src/base/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ class Geometry {
[[nodiscard]] auto light_instances() const noexcept { return luisa::span{_instanced_lights}; }
[[nodiscard]] auto world_min() const noexcept { return _world_min; }
[[nodiscard]] auto world_max() const noexcept { return _world_max; }
[[nodiscard]] Var<Hit> trace_closest(const Var<Ray> &ray) const noexcept;
[[nodiscard]] Var<bool> trace_any(const Var<Ray> &ray) const noexcept;
[[nodiscard]] Var<Hit> trace_closest(const Var<Ray> &ray_in) const noexcept;
[[nodiscard]] Var<bool> trace_any(const Var<Ray> &ray_in) const noexcept;
[[nodiscard]] luisa::shared_ptr<Interaction> interaction(const Var<Ray> &ray, const Var<Hit> &hit) const noexcept;
[[nodiscard]] luisa::shared_ptr<Interaction> interaction(Expr<uint> inst_id, Expr<uint> prim_id,
Expr<float3> bary, Expr<float3> wo) const noexcept;
Expand Down
2 changes: 1 addition & 1 deletion src/compute
Submodule compute updated 243 files

0 comments on commit 2c9c69f

Please sign in to comment.