Skip to content

Commit f83ce42

Browse files
committed
Merge pull request #6 from dneg/v0.0.3
Version 0.0.3 - Novemember 13, 2018
2 parents a85a96f + 8cebcac commit f83ce42

34 files changed

+2644
-1398
lines changed

openvdb_ax/CHANGES.md

+43
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,49 @@
11
OpenVDB AX Version History
22
==========================
33

4+
Version 0.0.3 - November 13, 2018
5+
6+
New features:
7+
- Introduced new $ syntax and back-end logic for fast lookups into AX Custom
8+
Data. This syntax works identically to attribute access syntax with type
9+
specifiers expected to be present when accessing non float data. For
10+
literal path names, this can be up to x20 faster than using the lookup()
11+
functions.
12+
- New External Variable AST node, Code Generation/Visitor methods and
13+
internal intrinsic functions for processing Custom Data lookups using $
14+
syntax.
15+
- Added a --print-ast command to the vdb_ax binary to output the built AST
16+
from the provided code snippet.
17+
18+
Improvements:
19+
- Removed the uint64_t LLVM Type specialization as all back-end values are
20+
signed.
21+
- Introduced a uintptr_t LLVM Type specialization for accessing pointers
22+
to typed data.
23+
- Consolidated attribute type checking with external variable type checking
24+
in Compiler.cc into verifyTypedAccesses().
25+
- Minor re-work to the PointDefaultModifier for conversion of default
26+
attributes.
27+
28+
API Changes:
29+
- ax::print() now takes a const ast::Tree reference.
30+
31+
Houdini:
32+
- External variable $ syntax can now be used to access parameters on the AX
33+
SOP e.g. ch("parm") -> $parm
34+
- Known path lookups using supported Houdini channel functions (e.g. ch())
35+
or AX lookup functions are optimized using the new external variable
36+
syntax for speed gains of up to x20.
37+
- Added optimised access to all available floating points Global and Local
38+
Node HScript variables such as $F, $T etc.
39+
- Back-ticks are no longer supported as the code is evaluated as a raw
40+
string. This is to support optimizations for ch() and Houdini HScript $
41+
parameters. These can be embedded without the need to re-compile the
42+
string parameter, even if they are time dependent.
43+
- Verbified the AX SOP so that it can be used in compile blocks and as a
44+
verb through python.
45+
46+
447
Version 0.0.2 - October 8, 2018
548

649
Improvements:

openvdb_ax/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ SET ( TEST_SOURCE_FILES
195195
test/frontend/TestConditionalStatementNode.cc
196196
test/frontend/TestCrementNode.cc
197197
test/frontend/TestDeclareLocalNode.cc
198+
test/frontend/TestExternalVariableNode.cc
198199
test/frontend/TestFunctionCallNode.cc
199200
test/frontend/TestKeywordNode.cc
200201
test/frontend/TestLocalValueNode.cc
@@ -207,7 +208,6 @@ SET ( TEST_SOURCE_FILES
207208
test/integration/TestAssign.cc
208209
test/integration/TestBinary.cc
209210
test/integration/TestCast.cc
210-
test/integration/TestChannelExpressions.cc
211211
test/integration/TestDeclare.cc
212212
test/integration/TestEditGroups.cc
213213
test/integration/TestEmpty.cc

openvdb_ax/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ TEST_SRC_NAMES := \
318318
test/frontend/TestConditionalStatementNode.cc \
319319
test/frontend/TestCrementNode.cc \
320320
test/frontend/TestDeclareLocalNode.cc \
321+
test/frontend/TestExternalVariableNode.cc \
321322
test/frontend/TestFunctionCallNode.cc \
322323
test/frontend/TestKeywordNode.cc \
323324
test/frontend/TestLocalValueNode.cc \
@@ -331,7 +332,6 @@ TEST_SRC_NAMES := \
331332
test/integration/TestAssign.cc \
332333
test/integration/TestBinary.cc \
333334
test/integration/TestCast.cc \
334-
test/integration/TestChannelExpressions.cc \
335335
test/integration/TestDeclare.cc \
336336
test/integration/TestEditGroups.cc \
337337
test/integration/TestEmpty.cc \

openvdb_ax/ast/AST.cc

+13
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ void Attribute::accept(Visitor& visitor) const
139139
visitor.visit(*this);
140140
}
141141

142+
void ExternalVariable::accept(Visitor& visitor) const
143+
{
144+
visitor.visit(*this);
145+
}
146+
142147
void AttributeValue::accept(Visitor& visitor) const
143148
{
144149
mAttribute->accept(visitor);
@@ -356,6 +361,14 @@ Variable* Attribute::accept(Modifier& visitor)
356361
return nullptr;
357362
}
358363

364+
Variable* ExternalVariable::accept(Modifier& visitor)
365+
{
366+
if (Variable* node = visitor.visit(*this)) {
367+
return node;
368+
}
369+
return nullptr;
370+
}
371+
359372
Expression* AttributeValue::accept(Modifier& visitor)
360373
{
361374
if (Expression* node = visitor.visit(*this)) {

openvdb_ax/ast/AST.h

+23
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ struct Cast;
7676
struct Variable;
7777
struct Attribute;
7878
struct AttributeValue;
79+
struct ExternalVariable;
7980
struct DeclareLocal;
8081
struct Local;
8182
struct LocalValue;
@@ -415,6 +416,26 @@ struct Attribute : public Variable
415416
const bool mTypeInferred;
416417
};
417418

419+
struct ExternalVariable : public Variable
420+
{
421+
using Ptr = std::shared_ptr<ExternalVariable>;
422+
using UniquePtr = std::unique_ptr<ExternalVariable>;
423+
424+
ExternalVariable(const std::string& name, const std::string& type)
425+
: Variable(name)
426+
, mType(type) {}
427+
ExternalVariable(const ExternalVariable& other)
428+
: Variable(other.mName)
429+
, mType(other.mType) {}
430+
~ExternalVariable() override = default;
431+
432+
void accept(Visitor& visitor) const override final;
433+
Variable* accept(Modifier& visitor) override final;
434+
ExternalVariable* copy() const override final { return new ExternalVariable(*this); }
435+
436+
const Name mType;
437+
};
438+
418439
struct AttributeValue : public Expression
419440
{
420441
using Ptr = std::shared_ptr<AttributeValue>;
@@ -641,6 +662,7 @@ struct Visitor
641662
inline virtual void visit(const Return& node) {};
642663
inline virtual void visit(const Attribute& node) {};
643664
inline virtual void visit(const AttributeValue& node) {};
665+
inline virtual void visit(const ExternalVariable& node) {};
644666
inline virtual void visit(const DeclareLocal& node) {};
645667
inline virtual void visit(const Local& node) {};
646668
inline virtual void visit(const LocalValue& node) {};
@@ -675,6 +697,7 @@ struct Modifier
675697
inline virtual Expression* visit(Return& node) { return nullptr; };
676698
inline virtual Variable* visit(Attribute& node) { return nullptr; };
677699
inline virtual Expression* visit(AttributeValue& node) { return nullptr; };
700+
inline virtual Variable* visit(ExternalVariable& node) { return nullptr; };
678701
inline virtual Variable* visit(DeclareLocal& node) { return nullptr; };
679702
inline virtual Variable* visit(Local& node) { return nullptr; };
680703
inline virtual Expression* visit(LocalValue& node) { return nullptr; };

openvdb_ax/ast/PrintTree.cc

+8-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct PrintVisitor : public ast::Visitor
6262
void visit(const ast::FunctionCall& node) override;
6363
void visit(const ast::Attribute& node) override;
6464
void visit(const ast::AttributeValue& node) override;
65+
void visit(const ast::ExternalVariable& node) override;
6566
void visit(const ast::DeclareLocal& node) override;
6667
void visit(const ast::Local& node) override;
6768
void visit(const ast::LocalValue& node) override;
@@ -225,6 +226,12 @@ void PrintVisitor::visit(const ast::VectorPack& node)
225226
mOs << "VectorPack " << std::endl;
226227
}
227228

229+
void PrintVisitor::visit(const ast::ExternalVariable& node)
230+
{
231+
printIndent();
232+
mOs << "External Variable " << node.mName << std::endl;
233+
}
234+
228235
template <typename T>
229236
void PrintVisitor::visitValue(const ast::Value<T>& node)
230237
{
@@ -245,7 +252,7 @@ void PrintVisitor::printIndent()
245252
////////////////////////////////////////////////////////////////////////////////
246253

247254

248-
void print(ast::Tree& tree, std::ostream& os)
255+
void print(const ast::Tree& tree, std::ostream& os)
249256
{
250257
PrintVisitor visitor(os);
251258
tree.accept(visitor);

openvdb_ax/ast/PrintTree.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct Tree;
4848
/// @brief Writes a debug printout of a Tree object into a target stream
4949
/// @param tree Tree to print
5050
/// @param os Stream to write into
51-
void print(ast::Tree& tree, std::ostream& os = std::cout);
51+
void print(const ast::Tree& tree, std::ostream& os = std::cout);
5252

5353
} // namespace ast
5454
} // namespace ax

openvdb_ax/cmd/openvdb_ax/main.cc

+14-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include <openvdb_ax/ast/AST.h>
3232
#include <openvdb_ax/ast/Scanners.h>
33+
#include <openvdb_ax/ast/PrintTree.h>
3334
#include <openvdb_ax/codegen/FunctionRegistry.h>
3435
#include <openvdb_ax/compiler/Compiler.h>
3536
#include <openvdb_ax/compiler/PointExecutable.h>
@@ -57,6 +58,7 @@ struct ProgOptions
5758
std::string mInputVDBFile = "";
5859
std::string mOutputVDBFile = "";
5960
bool mVerbose = false;
61+
bool mPrintAST = false;
6062
};
6163

6264
void
@@ -70,6 +72,7 @@ usage [[noreturn]] (int exitStatus = EXIT_FAILURE)
7072
" -f file.txt execute text file containing a code snippet on the input.vdb file\n" <<
7173
" -v verbose (print timing and diagnostics)\n" <<
7274
" --list-functions list all available functions, their signatures and their documentation\n" <<
75+
" --print-ast print the abstract syntax tree generated for point and volume execution\n" <<
7376
"Warning:\n" <<
7477
" Providing the same file-path to both input.vdb and output.vdb arguments will overwrite\n" <<
7578
" the file. If no output file is provided, the input.vdb will be processed but will remain\n" <<
@@ -205,6 +208,8 @@ main(int argc, char *argv[])
205208
initializer.initializeCompiler();
206209
printFunctions(std::cout);
207210
return EXIT_SUCCESS;
211+
} else if (parser.check(i, "--print-ast", 0)) {
212+
options.mPrintAST = true;
208213
} else if (arg == "-h" || arg == "-help" || arg == "--help") {
209214
usage(EXIT_SUCCESS);
210215
} else {
@@ -259,6 +264,14 @@ main(int argc, char *argv[])
259264
initializer.initializeCompiler();
260265
openvdb::ax::Compiler::Ptr compiler = openvdb::ax::Compiler::create();
261266

267+
// parse
268+
269+
const openvdb::ax::ast::Tree::ConstPtr syntaxTree =
270+
openvdb::ax::ast::parse(options.mInputCode.c_str());
271+
if (options.mPrintAST) {
272+
openvdb::ax::ast::print(*syntaxTree);
273+
}
274+
262275
// Execute on PointDataGrids
263276

264277
bool executeOnPoints = false;
@@ -276,9 +289,6 @@ main(int argc, char *argv[])
276289
openvdb::ax::CustomData::Ptr customData = openvdb::ax::CustomData::create();
277290
PointExecutable::Ptr pointExecutable;
278291

279-
const openvdb::ax::ast::Tree::ConstPtr syntaxTree =
280-
openvdb::ax::ast::parse(options.mInputCode.c_str());
281-
282292
if (options.mVerbose) std::cout << "OpenVDB PointDataGrids Found" << std::endl;
283293
std::vector<std::string> warnings;
284294

@@ -348,7 +358,7 @@ main(int argc, char *argv[])
348358
try {
349359
if (options.mVerbose) std::cout << " Compiling for Volume VDB Grid...";
350360
volumeExecutable =
351-
compiler->compile<VolumeExecutable>(options.mInputCode, customData, &warnings);
361+
compiler->compile<VolumeExecutable>(*syntaxTree, customData, &warnings);
352362
} catch (std::exception& e) {
353363
OPENVDB_LOG_FATAL("Compilation error!");
354364
OPENVDB_LOG_FATAL("Errors:");

openvdb_ax/codegen/ComputeGenerator.cc

+18
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,24 @@ ComputeGenerator::visit(const ast::Value<ValueType>& node)
987987
mValues.push(store);
988988
}
989989

990+
void ComputeGenerator::visit(const ast::ExternalVariable& node)
991+
{
992+
const std::string globalName = getGlobalExternalAccess(node.mName, node.mType);
993+
llvm::Value* ptrToAddress = this->globals().get(globalName);
994+
995+
if (!ptrToAddress) {
996+
ptrToAddress = llvm::cast<llvm::GlobalVariable>
997+
(mModule.getOrInsertGlobal(globalName, LLVMType<uintptr_t>::get(mContext)));
998+
this->globals().insert(globalName, ptrToAddress);
999+
}
1000+
1001+
llvm::Type* type = llvmTypeFromName(node.mType, mContext);
1002+
llvm::Value* address = mBuilder.CreateLoad(ptrToAddress);
1003+
llvm::Value* value = mBuilder.CreateIntToPtr(address, type->getPointerTo(0));
1004+
1005+
mValues.push(value);
1006+
}
1007+
9901008
void ComputeGenerator::visit(const ast::Tree& node)
9911009
{
9921010
assert(mBlocks.size() == 1);

openvdb_ax/codegen/ComputeGenerator.h

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ struct ComputeGenerator : public ast::Visitor
127127
void visit(const ast::Cast& node) override;
128128
void visit(const ast::DeclareLocal& node) override;
129129
void visit(const ast::Local& node) override;
130+
void visit(const ast::ExternalVariable& node) override;
130131

131132
/// @brief VectorUnpack pushes a single llvm::Value onto the value
132133
/// stack which represents a pointer to an element of a vector

openvdb_ax/codegen/FunctionRegistry.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,13 @@ void insertStandardFunctions(FunctionRegistry& registry)
185185

186186
// indirect internals
187187

188-
registry.insert("internal_cross", CrossProd::Internal::create, false);
189-
registry.insert("internal_normalize", Normalize::Internal::create, false);
190-
registry.insert("internal_addtogroup", AddToGroup::Internal::create, false);
191-
registry.insert("internal_ingroup", InGroup::Internal::create, false);
192-
registry.insert("internal_removefromgroup", RemoveFromGroup::Internal::create, false);
193-
registry.insert("internal_lookupf", LookupFloat::Internal::create, false);
194-
registry.insert("internal_lookupvec3f", LookupVec3f::Internal::create, false);
188+
registry.insert("internal_cross", CrossProd::Internal::create, true);
189+
registry.insert("internal_normalize", Normalize::Internal::create, true);
190+
registry.insert("internal_addtogroup", AddToGroup::Internal::create, true);
191+
registry.insert("internal_ingroup", InGroup::Internal::create, true);
192+
registry.insert("internal_removefromgroup", RemoveFromGroup::Internal::create, true);
193+
registry.insert("internal_lookupf", LookupFloat::Internal::create, true);
194+
registry.insert("internal_lookupvec3f", LookupVec3f::Internal::create, true);
195195

196196
// volume functions
197197

0 commit comments

Comments
 (0)