OpenVDB: openvdb_ax/codegen/VolumeComputeGenerator.h Source File

OpenVDB 10.0.1

VolumeComputeGenerator.h
Go to the documentation of this file.
1// Copyright Contributors to the OpenVDB Project
2// SPDX-License-Identifier: MPL-2.0
3
4/// @file codegen/VolumeComputeGenerator.h
5///
6/// @authors Nick Avramoussis
7///
8/// @brief The visitor framework and function definition for volume grid
9/// code generation
10///
11
12#ifndef OPENVDB_AX_VOLUME_COMPUTE_GENERATOR_HAS_BEEN_INCLUDED
13#define OPENVDB_AX_VOLUME_COMPUTE_GENERATOR_HAS_BEEN_INCLUDED
14
15#include "ComputeGenerator.h"
16#include "FunctionTypes.h"
17
18#include "../compiler/AttributeRegistry.h"
19
20#include <openvdb/version.h>
21
22namespace openvdb {
23 OPENVDB_USE_VERSION_NAMESPACE
24namespace OPENVDB_VERSION_NAME {
25
26namespace ax {
27namespace codegen {
28
29/// @brief The primary volume kernel. This function holds the generated body
30/// of AX programs.
31/// @details argument structure is as follows:
32/// 1) - A void pointer to the ax::CustomData
33/// 2) - A pointer to an array of three ints representing the
34/// current voxel coord being accessed
35/// 3) - A void pointer to the current value buffer
36/// 4) - A bool representing the current values active state
37/// 5) - The index of the current tile in the parent tile's table
38/// 6) - A void pointer to a vector of void pointers, representing
39/// an array of grid accessors
40/// 7) - A void pointer to a vector of void pointers, representing
41/// an array of grid transforms
42/// 8) - The index of currently executing volume in the list of write
43/// accessible volumes.
44 struct VolumeKernelValue
45{
46 // The signature of the generated function
47 using Signature =
48 void(const void* const,
49 const int32_t (*)[3],
50 void*, // value
51 bool, // active
52 int64_t, // index
53 void**, // r accessors
54 const void* const*,
55 int64_t);
56
57 using FunctionTraitsT = codegen::FunctionTraits<Signature>;
58 static const size_t N_ARGS = FunctionTraitsT::N_ARGS;
59
60 static const std::array<std::string, N_ARGS>& argumentKeys();
61 static const char* getDefaultName();
62};
63
64/// @brief The second volume kernel, responsible for providing the core
65/// layer of SIMD optimisations by invoking this kernel across a range of
66/// values.
67/// @details argument structure is as follows:
68/// 1) - A void pointer to the ax::CustomData
69/// 2) - A pointer to an array of three ints representing the
70/// current voxel coord being accessed
71/// 3) - A void pointer to the current value buffer
72/// 4) - A uint64_t pointer to the active word buffer
73/// 5) - The active state execution mode
74/// 6) - A void pointer to a vector of void pointers, representing
75/// an array of grid accessors
76/// 7) - A void pointer to a vector of void pointers, representing
77/// an array of grid transforms
78/// 8) - The index of currently executing volume in the list of write
79/// accessible volumes.
80 struct VolumeKernelBuffer
81{
82 // The signature of the generated function
83 using Signature =
84 void(const void* const,
85 const int32_t (*)[3],
86 void*, // value buffer
87 uint64_t*, // active buffer
88 int64_t, // buffer size
89 uint64_t, // mode (0 = off, 1 = active, 2 = both)
90 void**, // read accessors
91 const void* const*, // transforms
92 int64_t); // write index
93
94 using FunctionTraitsT = codegen::FunctionTraits<Signature>;
95 static const size_t N_ARGS = FunctionTraitsT::N_ARGS;
96
97 static const std::array<std::string, N_ARGS>& argumentKeys();
98 static const char* getDefaultName();
99};
100
101/// @brief The third volume kernel, providing an agnostic way to modify
102/// a single tile value without passing through the buffer states. Note
103/// that this kernel is mainly utility and one of the value kernels should
104/// almost always be preferred.
105/// @details argument structure is as follows:
106/// 1) - A void pointer to the ax::CustomData
107/// 2) - A pointer to an array of three ints representing the
108/// current voxel coord being accessed
109/// 3) - A void pointer to a vector of void pointers, representing
110/// an array of grid accessors
111/// 4) - A void pointer to a vector of void pointers, representing
112/// an array of grid transforms
113/// 5) - The index of currently executing volume in the list of write
114/// accessible volumes.
115/// 5) - A unique write accessor to the target volume.
116 struct VolumeKernelNode
117{
118 // The signature of the generated function
119 using Signature =
120 void(const void* const,
121 const int32_t (*)[3], // index space coord
122 void**, // read accessors
123 const void* const*, // transforms
124 int64_t, // write index
125 void*); // write accessor
126
127 using FunctionTraitsT = codegen::FunctionTraits<Signature>;
128 static const size_t N_ARGS = FunctionTraitsT::N_ARGS;
129
130 static const std::array<std::string, N_ARGS>& argumentKeys();
131 static const char* getDefaultName();
132};
133
134///////////////////////////////////////////////////////////////////////////
135///////////////////////////////////////////////////////////////////////////
136
137namespace codegen_internal {
138
139/// @brief Visitor object which will generate llvm IR for a syntax tree which has been generated
140/// from AX that targets volumes. The IR will represent a single function. It is mainly
141/// used by the Compiler class.
142 struct VolumeComputeGenerator : public ComputeGenerator
143{
144 /// @brief Constructor
145 /// @param module llvm Module for generating IR
146 /// @param options Options for the function registry behaviour
147 /// @param functionRegistry Function registry object which will be used when generating IR
148 /// for function calls
149 /// @param logger Logger for collecting logical errors and warnings
150 VolumeComputeGenerator(llvm::Module& module,
151 const FunctionOptions& options,
152 FunctionRegistry& functionRegistry,
153 Logger& logger);
154
155 ~VolumeComputeGenerator() override = default;
156
157 using ComputeGenerator::traverse;
158 using ComputeGenerator::visit;
159
160 AttributeRegistry::Ptr generate(const ast::Tree& node);
161 bool visit(const ast::Attribute*) override;
162
163private:
164 llvm::Value* accessorHandleFromToken(const std::string&);
165 void getAccessorValue(const std::string&, llvm::Value*);
166
167 void computek2(llvm::Function*, const AttributeRegistry&);
168 void computek3(llvm::Function*, const AttributeRegistry&);
169};
170
171} // namespace codegen_internal
172
173} // namespace codegen
174} // namespace ax
175} // namespace OPENVDB_VERSION_NAME
176} // namespace openvdb
177
178#endif // OPENVDB_AX_VOLUME_COMPUTE_GENERATOR_HAS_BEEN_INCLUDED
179
ComputeGenerator.h
The core visitor framework for code generation.
FunctionTypes.h
Contains frameworks for creating custom AX functions which can be registered within the FunctionRegis...
openvdb::v10_0::ax::AttributeRegistry
This class stores a list of access names, types and their dependency connections.
Definition: AttributeRegistry.h:39
openvdb::v10_0::ax::AttributeRegistry::Ptr
std::shared_ptr< AttributeRegistry > Ptr
Definition: AttributeRegistry.h:41
openvdb::v10_0::ax::Logger
Logger for collecting errors and warnings that occur during AX compilation.
Definition: Logger.h:58
openvdb::v10_0::ax::codegen::FunctionRegistry
The function registry which is used for function code generation. Each time a function is visited wit...
Definition: FunctionRegistry.h:36
openvdb
Definition: Exceptions.h:13
openvdb::v10_0::ax::FunctionOptions
Options that control how functions behave.
Definition: CompilerOptions.h:25
openvdb::v10_0::ax::ast::Attribute
Attributes represent any access to a primitive value, typically associated with the '@' symbol syntax...
Definition: AST.h:1874
openvdb::v10_0::ax::ast::Tree
A Tree is the highest concrete (non-abstract) node in the entire AX AST hierarchy....
Definition: AST.h:562
openvdb::v10_0::ax::codegen::FunctionTraits
Templated function traits which provides compile-time index access to the types of the function signa...
Definition: Types.h:279
openvdb::v10_0::ax::codegen::VolumeKernelBuffer
The second volume kernel, responsible for providing the core layer of SIMD optimisations by invoking ...
Definition: VolumeComputeGenerator.h:81
openvdb::v10_0::ax::codegen::VolumeKernelBuffer::argumentKeys
static const std::array< std::string, N_ARGS > & argumentKeys()
openvdb::v10_0::ax::codegen::VolumeKernelBuffer::Signature
void(const void *const, const int32_t(*)[3], void *, uint64_t *, int64_t, uint64_t, void **, const void *const *, int64_t) Signature
Definition: VolumeComputeGenerator.h:92
openvdb::v10_0::ax::codegen::VolumeKernelBuffer::getDefaultName
static const char * getDefaultName()
openvdb::v10_0::ax::codegen::VolumeKernelNode
The third volume kernel, providing an agnostic way to modify a single tile value without passing thro...
Definition: VolumeComputeGenerator.h:117
openvdb::v10_0::ax::codegen::VolumeKernelNode::argumentKeys
static const std::array< std::string, N_ARGS > & argumentKeys()
openvdb::v10_0::ax::codegen::VolumeKernelNode::Signature
void(const void *const, const int32_t(*)[3], void **, const void *const *, int64_t, void *) Signature
Definition: VolumeComputeGenerator.h:125
openvdb::v10_0::ax::codegen::VolumeKernelNode::getDefaultName
static const char * getDefaultName()
openvdb::v10_0::ax::codegen::VolumeKernelValue
The primary volume kernel. This function holds the generated body of AX programs.
Definition: VolumeComputeGenerator.h:45
openvdb::v10_0::ax::codegen::VolumeKernelValue::argumentKeys
static const std::array< std::string, N_ARGS > & argumentKeys()
openvdb::v10_0::ax::codegen::VolumeKernelValue::Signature
void(const void *const, const int32_t(*)[3], void *, bool, int64_t, void **, const void *const *, int64_t) Signature
Definition: VolumeComputeGenerator.h:55
openvdb::v10_0::ax::codegen::VolumeKernelValue::getDefaultName
static const char * getDefaultName()
openvdb::v10_0::ax::codegen::codegen_internal::ComputeGenerator
Visitor object which will generate llvm IR for a syntax tree. This provides the majority of the code ...
Definition: ComputeGenerator.h:87
openvdb::v10_0::ax::codegen::codegen_internal::VolumeComputeGenerator
Visitor object which will generate llvm IR for a syntax tree which has been generated from AX that ta...
Definition: VolumeComputeGenerator.h:143
openvdb::v10_0::ax::codegen::codegen_internal::VolumeComputeGenerator::generate
AttributeRegistry::Ptr generate(const ast::Tree &node)
openvdb::v10_0::ax::codegen::codegen_internal::VolumeComputeGenerator::VolumeComputeGenerator
VolumeComputeGenerator(llvm::Module &module, const FunctionOptions &options, FunctionRegistry &functionRegistry, Logger &logger)
Constructor.
openvdb::v10_0::ax::codegen::codegen_internal::VolumeComputeGenerator::~VolumeComputeGenerator
~VolumeComputeGenerator() override=default
openvdb::v10_0::ax::codegen::codegen_internal::VolumeComputeGenerator::visit
bool visit(const ast::Attribute *) override
Visitor methods for all AST nodes which implement IR generation.
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:212