Loading...
Searching...
No Matches
VolumeComputeGenerator.h
Go to the documentation of this file.
// Copyright Contributors to the OpenVDB Project
// SPDX-License-Identifier: MPL-2.0
/// @file codegen/VolumeComputeGenerator.h
///
/// @authors Nick Avramoussis
///
/// @brief The visitor framework and function definition for volume grid
/// code generation
///
#ifndef OPENVDB_AX_VOLUME_COMPUTE_GENERATOR_HAS_BEEN_INCLUDED
#define OPENVDB_AX_VOLUME_COMPUTE_GENERATOR_HAS_BEEN_INCLUDED
#include "ComputeGenerator.h"
#include "FunctionTypes.h"
#include "../compiler/AttributeRegistry.h"
#include <openvdb/version.h>
namespace openvdb {
OPENVDB_USE_VERSION_NAMESPACE
namespace OPENVDB_VERSION_NAME {
namespace ax {
namespace codegen {
/// @brief The primary volume kernel. This function holds the generated body
/// of AX programs.
/// @details argument structure is as follows:
/// 1) - A void pointer to the ax::CustomData
/// 2) - A pointer to an array of three ints representing the
/// current voxel coord being accessed
/// 3) - A void pointer to the current value buffer
/// 4) - A bool representing the current values active state
/// 5) - The index of the current tile in the parent tile's table
/// 6) - A void pointer to a vector of void pointers, representing
/// an array of grid accessors
/// 7) - A void pointer to a vector of void pointers, representing
/// an array of grid transforms
/// 8) - The index of currently executing volume in the list of write
/// accessible volumes.
struct VolumeKernelValue
{
// The signature of the generated function
using Signature =
void(const void* const,
const int32_t (*)[3],
void*, // value
bool, // active
int64_t, // index
void**, // r accessors
const void* const*,
int64_t);
using FunctionTraitsT = codegen::FunctionTraits<Signature>;
static const size_t N_ARGS = FunctionTraitsT::N_ARGS;
static const std::array<std::string, N_ARGS>& argumentKeys();
static const char* getDefaultName();
};
/// @brief The second volume kernel, responsible for providing the core
/// layer of SIMD optimisations by invoking this kernel across a range of
/// values.
/// @details argument structure is as follows:
/// 1) - A void pointer to the ax::CustomData
/// 2) - A pointer to an array of three ints representing the
/// current voxel coord being accessed
/// 3) - A void pointer to the current value buffer
/// 4) - A uint64_t pointer to the active word buffer
/// 5) - The active state execution mode
/// 6) - A void pointer to a vector of void pointers, representing
/// an array of grid accessors
/// 7) - A void pointer to a vector of void pointers, representing
/// an array of grid transforms
/// 8) - The index of currently executing volume in the list of write
/// accessible volumes.
struct VolumeKernelBuffer
{
// The signature of the generated function
using Signature =
void(const void* const,
const int32_t (*)[3],
void*, // value buffer
uint64_t*, // active buffer
int64_t, // buffer size
uint64_t, // mode (0 = off, 1 = active, 2 = both)
void**, // read accessors
const void* const*, // transforms
int64_t); // write index
using FunctionTraitsT = codegen::FunctionTraits<Signature>;
static const size_t N_ARGS = FunctionTraitsT::N_ARGS;
static const std::array<std::string, N_ARGS>& argumentKeys();
static const char* getDefaultName();
};
/// @brief The third volume kernel, providing an agnostic way to modify
/// a single tile value without passing through the buffer states. Note
/// that this kernel is mainly utility and one of the value kernels should
/// almost always be preferred.
/// @details argument structure is as follows:
/// 1) - A void pointer to the ax::CustomData
/// 2) - A pointer to an array of three ints representing the
/// current voxel coord being accessed
/// 3) - A void pointer to a vector of void pointers, representing
/// an array of grid accessors
/// 4) - A void pointer to a vector of void pointers, representing
/// an array of grid transforms
/// 5) - The index of currently executing volume in the list of write
/// accessible volumes.
/// 5) - A unique write accessor to the target volume.
struct VolumeKernelNode
{
// The signature of the generated function
using Signature =
void(const void* const,
const int32_t (*)[3], // index space coord
void**, // read accessors
const void* const*, // transforms
int64_t, // write index
void*); // write accessor
using FunctionTraitsT = codegen::FunctionTraits<Signature>;
static const size_t N_ARGS = FunctionTraitsT::N_ARGS;
static const std::array<std::string, N_ARGS>& argumentKeys();
static const char* getDefaultName();
};
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
namespace codegen_internal {
/// @brief Visitor object which will generate llvm IR for a syntax tree which has been generated
/// from AX that targets volumes. The IR will represent a single function. It is mainly
/// used by the Compiler class.
struct VolumeComputeGenerator : public ComputeGenerator
{
/// @brief Constructor
/// @param module llvm Module for generating IR
/// @param options Options for the function registry behaviour
/// @param functionRegistry Function registry object which will be used when generating IR
/// for function calls
/// @param logger Logger for collecting logical errors and warnings
VolumeComputeGenerator(llvm::Module& module,
const FunctionOptions& options,
FunctionRegistry& functionRegistry,
Logger& logger);
~VolumeComputeGenerator() override = default;
using ComputeGenerator::traverse;
using ComputeGenerator::visit;
AttributeRegistry::Ptr generate(const ast::Tree& node);
bool visit(const ast::Attribute*) override;
private:
llvm::Value* accessorHandleFromToken(const std::string&);
void getAccessorValue(const std::string&, llvm::Value*);
void computek2(llvm::Function*, const AttributeRegistry&);
void computek3(llvm::Function*, const AttributeRegistry&);
};
} // namespace codegen_internal
} // namespace codegen
} // namespace ax
} // namespace OPENVDB_VERSION_NAME
} // namespace openvdb
#endif // OPENVDB_AX_VOLUME_COMPUTE_GENERATOR_HAS_BEEN_INCLUDED
AttributeRegistry.h
These classes contain lists of expected attributes and volumes which are populated by compiler during...
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::v10_0::ax::codegen::codegen_internal
Definition ComputeGenerator.h:67
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::FunctionTraitsT
codegen::FunctionTraits< Signature > FunctionTraitsT
Definition VolumeComputeGenerator.h:94
openvdb::v10_0::ax::codegen::VolumeKernelBuffer::argumentKeys
static const std::array< std::string, N_ARGS > & argumentKeys()
openvdb::v10_0::ax::codegen::VolumeKernelBuffer::N_ARGS
static const size_t N_ARGS
Definition VolumeComputeGenerator.h:95
openvdb::v10_0::ax::codegen::VolumeKernelBuffer::getDefaultName
static const char * getDefaultName()
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:83
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::FunctionTraitsT
codegen::FunctionTraits< Signature > FunctionTraitsT
Definition VolumeComputeGenerator.h:127
openvdb::v10_0::ax::codegen::VolumeKernelNode::argumentKeys
static const std::array< std::string, N_ARGS > & argumentKeys()
openvdb::v10_0::ax::codegen::VolumeKernelNode::N_ARGS
static const size_t N_ARGS
Definition VolumeComputeGenerator.h:128
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:119
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::FunctionTraitsT
codegen::FunctionTraits< Signature > FunctionTraitsT
Definition VolumeComputeGenerator.h:57
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:47
openvdb::v10_0::ax::codegen::VolumeKernelValue::N_ARGS
static const size_t N_ARGS
Definition VolumeComputeGenerator.h:58
openvdb::v10_0::ax::codegen::VolumeKernelValue::getDefaultName
static const char * getDefaultName()
openvdb::v10_0::ax::codegen::codegen_internal::ComputeGenerator::ComputeGenerator
ComputeGenerator(llvm::Module &module, const FunctionOptions &options, FunctionRegistry &functionRegistry, Logger &logger)
openvdb::v10_0::ax::codegen::codegen_internal::ComputeGenerator::traverse
bool traverse(const ast::Block *block)
Custom traversal of scoped blocks.
Definition ComputeGenerator.h:111
openvdb::v10_0::ax::codegen::codegen_internal::ComputeGenerator::visit
virtual bool visit(const ast::CommaOperator *)
Visitor methods for all AST nodes which implement IR generation.
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