Blender V5.3
BLI_execution_mode.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include <concepts>
12#include <optional>
13
15
17struct Parallel {
18 static constexpr bool is_parallel = true;
19
20 int grain_size(const int fallback) const
21 {
22 return fallback;
23 }
24};
25
27struct Serial {
28 static constexpr bool is_parallel = false;
29};
30
36 static constexpr bool is_parallel = true;
38
39 int grain_size(const int /*fallback*/) const
40 {
41 return this->grain_size_override;
42 }
43};
44
48template<typename T>
49concept Tag = requires {
50 { T::is_parallel } -> std::convertible_to<bool>;
51
52 requires(!T::is_parallel || requires(const T t, int fallback) {
53 { t.grain_size(fallback) } -> std::same_as<int>;
54 });
55};
56
60struct Mode {
62 std::optional<int> grain_size_override;
63 constexpr Mode(Parallel /*tag*/) : is_parallel(true), grain_size_override(std::nullopt) {}
64 constexpr Mode(Serial /*tag*/) : is_parallel(false), grain_size_override(std::nullopt) {}
69
70 constexpr int grain_size(const int fallback) const
71 {
72 return this->grain_size_override.value_or(fallback);
73 }
74};
75
78constexpr Serial serial = Serial();
83
84} // namespace blender::exec_mode
#define T
constexpr ParallelGrainSize grain_size(int grain_size)
constexpr Serial serial
constexpr Parallel parallel
constexpr int grain_size(const int fallback) const
std::optional< int > grain_size_override
constexpr Mode(ParallelGrainSize tag)
static constexpr bool is_parallel
int grain_size(const int fallback) const
static constexpr bool is_parallel