xref: /aosp_15_r20/external/executorch/backends/vulkan/runtime/graph/containers/SymInt.h (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #pragma once
10 
11 #include <executorch/backends/vulkan/runtime/api/Context.h>
12 #include <executorch/backends/vulkan/runtime/api/containers/ParamsBuffer.h>
13 
14 namespace vkcompute {
15 
16 /*
17  * Represents a symbolic integer whose value can be variable. It is implemented
18  * as a thin wrapper around a `ParamsBuffer` object that holds the value of the
19  * integer. The `ParamsBuffer` object allows the value of the symbolic integer
20  * to be changed from the CPU and have those changes be visible to all shaders
21  * that use the symbolic integer; it also allows the value of the symbolic
22  * integer to be the result of a compute shader.
23  *
24  * Regular scalar types represented by `TypeTag::INT` cannot be used for
25  * symbolic integers because their value is assumed to be constant; therefore
26  * the `Value` instance holding the value of the scalar does not contain
27  * any reference to the GPU buffers used to pass its value into compute shaders.
28  * Therefore, updating the value of the scalar does not impact the value seen
29  * by compute shaders.
30  */
31 struct SymInt final {
32   api::ParamsBuffer gpu_buffer;
33 
34   explicit SymInt(api::Context* context_p, const int32_t val);
35 
36   void set(const int32_t val);
37 
38   int32_t get();
39 
40   void operator=(const int32_t val);
41 };
42 
43 } // namespace vkcompute
44