Skip to content

Commit

Permalink
fix compile
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxwellGengYF committed Mar 24, 2024
1 parent bbf115b commit d965f74
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
23 changes: 16 additions & 7 deletions include/luisa/core/fiber.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,26 @@ template<class F>
});
return evt;
}

namespace detail {
template<typename T>
struct NonMovableAtomic {
std::atomic<T> value;
NonMovableAtomic() noexcept = default;
NonMovableAtomic(T &&t) noexcept : value{std::move(t)} {}
NonMovableAtomic(NonMovableAtomic const &) = delete;
NonMovableAtomic(NonMovableAtomic &&rhs) noexcept
: value{rhs.value.load()} {
}
};
}// namespace detail
template<class F>
requires(std::is_invocable_v<F, uint32_t>)
[[nodiscard]] auto async_parallel(uint32_t job_count, F &&lambda) noexcept {
auto thread_count = std::min<uint32_t>(job_count, marl::Scheduler::get()->config().workerThread.count);
counter evt{thread_count};
auto counter = luisa::make_unique<std::atomic<uint32_t>>(0);
luisa::SharedFunction<void()> func{[counter = std::move(counter), job_count, evt, lambda = std::forward<F>(lambda)]() mutable noexcept {
luisa::SharedFunction<void()> func{[counter = detail::NonMovableAtomic<uint32_t>(0), job_count, evt, lambda = std::forward<F>(lambda)]() mutable noexcept {
uint32_t i = 0u;
while ((i = counter->fetch_add(1u)) < job_count) { lambda(i); }
while ((i = counter.value.fetch_add(1u)) < job_count) { lambda(i); }
evt.decrement();
}};
for (uint32_t i = 0; i < thread_count; ++i) {
Expand All @@ -115,10 +125,9 @@ template<class F>
void parallel(uint32_t job_count, F &&lambda) noexcept {
auto thread_count = std::min<uint32_t>(job_count, marl::Scheduler::get()->config().workerThread.count);
counter evt{thread_count};
auto counter = luisa::make_unique<std::atomic<uint32_t>>(0);
luisa::SharedFunction<void()> func{[counter = std::move(counter), job_count, &evt, lambda = std::forward<F>(lambda)]() mutable noexcept {
luisa::SharedFunction<void()> func{[counter = detail::NonMovableAtomic<uint32_t>(0), job_count, &evt, lambda = std::forward<F>(lambda)]() mutable noexcept {
uint32_t i = 0u;
while ((i = counter->fetch_add(1u)) < job_count) { lambda(i); }
while ((i = counter.value.fetch_add(1u)) < job_count) { lambda(i); }
evt.decrement();
}};
for (uint32_t i = 0; i < thread_count; ++i) {
Expand Down
18 changes: 11 additions & 7 deletions src/tests/test_clang_cxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ int main(int argc, char *argv[]) {
auto inc_iter = vstd::range_linker{
vstd::make_ite_range(luisa::span{&include_path, 1}),
vstd::transform_range{
[&](auto &&path) { return luisa::to_string(path); }}}.i_range();
[&](auto &&path) { return luisa::to_string(path); }}}
.i_range();
if (kUseExport) {
auto lib = luisa::clangcxx::Compiler::export_callables(
device, iter, shader_path, inc_iter);
Expand Down Expand Up @@ -107,10 +108,14 @@ int main(int argc, char *argv[]) {
auto texture = device.create_image<float>(PixelStorage::FLOAT4, width, height);
Window window{"test func", uint2(width, height)};
Swapchain swap_chain{device.create_swapchain(
window.native_handle(),
stream,
uint2(width, height),
false, false, 2)};
SwapchainOption{
.display = window.native_display(),
.window = window.native_handle(),
.size = uint2(width, height),
.wants_hdr = false,
.wants_vsync = false,
.back_buffer_count = 2})};
auto ldr_image = device.create_image<float>(swap_chain.backend_storage(), uint2(width, height));

Kernel2D hdr2ldr_kernel = [&](ImageVar<float> hdr_image, ImageFloat ldr_image, Float scale, Bool is_hdr) noexcept {
Expand Down Expand Up @@ -211,12 +216,11 @@ int main(int argc, char *argv[]) {
LUISA_INFO("Time: {} ms", time);
stbi_write_png("test_rtx.png", width, height, 4, pixels.data(), 0);
}
if(kTestName == "raster"){
if (kTestName == "raster") {
auto raster_ext = device.extension<RasterExt>();
auto types = {
Type::of<float4x4>(),
Type::of<float3>()
};
Type::of<float3>()};
auto shader = device.load_raster_shader<float, float>("test.bin");
}
}
Expand Down

0 comments on commit d965f74

Please sign in to comment.