PXL
task_count.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: Apache-2.0
2 // Copyright 2026 XCENA Inc.
3 
4 #pragma once
5 
6 #include <cstdint>
7 #include <utility>
8 
9 namespace pxl
10 {
11 namespace detail
12 {
13 
22 template <typename Builder>
23 class [[nodiscard]] TaskCountConfigured : public Builder
24 {
25 public:
26  explicit TaskCountConfigured(Builder&& builder)
27  : Builder(std::move(builder))
28  {
29  }
30 
32  TaskCountConfigured& operator=(TaskCountConfigured&&) noexcept = default;
34  TaskCountConfigured& operator=(const TaskCountConfigured&) = delete;
35 
36 // Keep every setting's lvalue/rvalue behavior identical. No storage or exported
37 // symbols are added to the underlying builders.
38 #define PXL_CONFIGURED_SETTING(method) \
39  template <typename... Args> \
40  TaskCountConfigured& method(Args&&... args)& \
41  { \
42  Builder::method(std::forward<Args>(args)...); \
43  return *this; \
44  } \
45  template <typename... Args> \
46  TaskCountConfigured&& method(Args&&... args)&& \
47  { \
48  Builder::method(std::forward<Args>(args)...); \
49  return std::move(*this); \
50  }
51 
53  PXL_CONFIGURED_SETTING(reserve)
54  PXL_CONFIGURED_SETTING(batchSize)
55  PXL_CONFIGURED_SETTING(clusterBitmap)
56  PXL_CONFIGURED_SETTING(locality)
57  PXL_CONFIGURED_SETTING(onComplete)
58  PXL_CONFIGURED_SETTING(onMessage)
59  PXL_CONFIGURED_SETTING(onError)
61  PXL_CONFIGURED_SETTING(enableProfile)
62 
63 #undef PXL_CONFIGURED_SETTING
64 
65  template <auto Func, typename... Args, typename B = Builder>
66  auto stage(Args&&... args) & -> decltype(std::declval<B&>().template stage<Func>(std::forward<Args>(args)...))
67  {
68  return Builder::template stage<Func>(std::forward<Args>(args)...);
69  }
70 
71  template <auto Func, typename... Args, typename B = Builder>
72  auto stage(Args&&... args) && -> decltype(std::declval<B&&>().template stage<Func>(std::forward<Args>(args)...))
73  {
74  return std::move(static_cast<Builder&>(*this)).template stage<Func>(std::forward<Args>(args)...);
75  }
76 
77  template <typename B = Builder>
78  auto stage() & -> decltype(std::declval<B&>().stage())
79  {
80  return Builder::stage();
81  }
82 
83  // A group returned from a temporary chain must own that chain. Borrowing
84  // it would leave a stored group pointing at a destroyed parent.
85  template <typename B = Builder>
86  auto stage() && -> decltype(std::declval<B&&>().takeStageGroup())
87  {
88  return std::move(static_cast<Builder&>(*this)).takeStageGroup();
89  }
90 };
91 
101 template <typename Builder>
102 class [[nodiscard]] TaskCountRequired
103 {
104 public:
105  explicit TaskCountRequired(Builder&& builder)
106  : builder_(std::move(builder))
107  {
108  }
109 
110  TaskCountRequired(TaskCountRequired&&) noexcept = default;
111  TaskCountRequired& operator=(TaskCountRequired&&) noexcept = default;
113  TaskCountRequired& operator=(const TaskCountRequired&) = delete;
114 
115  TaskCountConfigured<Builder> tasks(uint32_t taskCount)
116  {
117  builder_.tasks(taskCount);
118  return TaskCountConfigured<Builder>(std::move(builder_));
119  }
120 
121  template <typename... Args>
122  TaskCountRequired& reserve(Args&&... args)
123  {
124  builder_.reserve(std::forward<Args>(args)...);
125  return *this;
126  }
127 
128  template <typename... Args>
129  TaskCountRequired& batchSize(Args&&... args)
130  {
131  builder_.batchSize(std::forward<Args>(args)...);
132  return *this;
133  }
134 
135  template <typename... Args>
137  {
138  builder_.clusterBitmap(std::forward<Args>(args)...);
139  return *this;
140  }
141 
142  template <typename... Args>
143  TaskCountRequired& locality(Args&&... args)
144  {
145  builder_.locality(std::forward<Args>(args)...);
146  return *this;
147  }
148 
149  template <typename... Args>
150  TaskCountRequired& onComplete(Args&&... args)
151  {
152  builder_.onComplete(std::forward<Args>(args)...);
153  return *this;
154  }
155 
156  template <typename... Args>
157  TaskCountRequired& onMessage(Args&&... args)
158  {
159  builder_.onMessage(std::forward<Args>(args)...);
160  return *this;
161  }
162 
163  template <typename... Args>
164  TaskCountRequired& onError(Args&&... args)
165  {
166  builder_.onError(std::forward<Args>(args)...);
167  return *this;
168  }
169 
170  template <typename... Args>
171  TaskCountRequired& stream(Args&&... args)
172  {
173  builder_.stream(std::forward<Args>(args)...);
174  return *this;
175  }
176 
177  template <typename... Args>
179  {
180  builder_.enableProfile(std::forward<Args>(args)...);
181  return *this;
182  }
183 
184 private:
185  Builder builder_;
186 };
187 
188 } // namespace detail
189 } // namespace pxl
Runnable builder that preserves the value category of settings.
Definition: task_count.hpp:24
auto stage() &&-> decltype(std::declval< B && >().takeStageGroup())
Definition: task_count.hpp:86
auto stage() &-> decltype(std::declval< B & >().stage())
Definition: task_count.hpp:78
TaskCountConfigured(TaskCountConfigured &&) noexcept=default
auto stage(Args &&... args) &&-> decltype(std::declval< B && >().template stage< Func >(std::forward< Args >(args)...))
Definition: task_count.hpp:72
auto stage(Args &&... args) &-> decltype(std::declval< B & >().template stage< Func >(std::forward< Args >(args)...))
Definition: task_count.hpp:66
TaskCountConfigured(Builder &&builder)
Definition: task_count.hpp:26
Holds a launch request that still needs its task count.
Definition: task_count.hpp:103
TaskCountRequired & reserve(Args &&... args)
Definition: task_count.hpp:122
TaskCountRequired & onComplete(Args &&... args)
Definition: task_count.hpp:150
TaskCountRequired & stream(Args &&... args)
Definition: task_count.hpp:171
TaskCountRequired(Builder &&builder)
Definition: task_count.hpp:105
TaskCountRequired & locality(Args &&... args)
Definition: task_count.hpp:143
TaskCountRequired & batchSize(Args &&... args)
Definition: task_count.hpp:129
TaskCountRequired & onMessage(Args &&... args)
Definition: task_count.hpp:157
TaskCountRequired(TaskCountRequired &&) noexcept=default
TaskCountRequired & enableProfile(Args &&... args)
Definition: task_count.hpp:178
TaskCountRequired & onError(Args &&... args)
Definition: task_count.hpp:164
TaskCountRequired & clusterBitmap(Args &&... args)
Definition: task_count.hpp:136
Definition: config.hpp:11
#define PXL_CONFIGURED_SETTING(method)
Definition: task_count.hpp:38