Compile a vex library

   2467   6   4
User Avatar
Member
16 posts
Joined: 10月 2017
Offline
Hey, I've been struggling a bit on this and didn't found how to do it properly. I've made a few .vfl files with functions definitions, and I'd like to compile them and then call them in attribute wrangles (to gain some performance and avoid jit compilation each time the code is run).

The way I tested was :

test.vfl :
#ifndef TEST
#define TEST

cvex print(string message="")
{
    printf(message);
}

#endif

vcc test.vfl -> outputs a print.vex file

I define HOUDINI_VEX_PATH to include the directory where print.vex is

in Houdini, in an attr wrangle :
#include "print.vex"

print("test message");

And I have a warning : "Errors or warnings encountered during VEX compile:
/obj/geo1/pointwrangle1/attribvop1: No context function defined.. "


Cheers,
Edited by DonRomano - 2021年4月14日 09:09:29
User Avatar
スタッフ
1448 posts
Joined: 7月 2005
Offline
Normally (in surface or displacement context) you would use the `import` keyword
import print;
...
print("message", "test message");
however, I don't think import is supported in the `cvex` context, so you can't do that.

https://www.sidefx.com/docs/houdini/vex/shadercalls.html [www.sidefx.com]
User Avatar
Member
7740 posts
Joined: 9月 2011
Offline
rafal
Normally (in surface or displacement context) you would use the `import` keyword
import print;
...
print("message", "test message");
however, I don't think import is supported in the `cvex` context, so you can't do that.

https://www.sidefx.com/docs/houdini/vex/shadercalls.html [www.sidefx.com]

The example in that help page is a cvex shader, is it really not supported?
User Avatar
Member
16 posts
Joined: 10月 2017
Offline
rafal
Normally (in surface or displacement context) you would use the `import` keyword
import print;
...
print("message", "test message");
however, I don't think import is supported in the `cvex` context, so you can't do that.

https://www.sidefx.com/docs/houdini/vex/shadercalls.html [www.sidefx.com]

Thank's for the answer !

I tried with the import keyword, and it recognizes the function but that still does not work.

import print;

print("test message");

This returns an error : No matching function for print(string). Candidates are: void print(; ... )

When I don't pass any argument to the function, calling it like this :

import print;

print();

I don't get any error but the function does nothing, thought I changed it to this (to see if I could get something out of it)

#ifndef test
#define test

cvex print(string message="")
{
    printf("test message");
    addpoint(geoself(), {0,0,0});
}

 #endif


Maybe what I'm trying to do is not supported and I already have the maximum speed I can get from wrangles, and then I'll work with the hdk to do what I want to do. I have another question, because I'm not sure : are wrangles recompiled each time they are cooked (in a for loop for example, though I believe they cache the compiled code somewhere and load it each time) ?


Cheers,
Edited by DonRomano - 2021年4月20日 11:55:47
User Avatar
スタッフ
1448 posts
Joined: 7月 2005
Offline
Ah, yes it is supported. I swear there was some CVEX limitation in the past. I must have forgotten it got removed at some point. Probably when allowing to save cached code on CVEX HDAs. Anyway, @DonRomano, you can use imports to reuse CVEX code.
User Avatar
スタッフ
1448 posts
Joined: 7月 2005
Offline
DonRomano
I don't get any error but the function does nothing,
Hmm. It should work. I have this test function in foobar.vfl
cvex foobar(export vector out = {0,0,0})
{
    out.y = 0.5;
}

and this code in the Attrib Wrangle SOP (connected to an output of a Grid SOP):
import foobar;
foobar("out", v@P);

and the grid is "lifted" in the viewport to y=0.5 plane.
User Avatar
Member
16 posts
Joined: 10月 2017
Offline
rafal
DonRomano
I don't get any error but the function does nothing,
Hmm. It should work. I have this test function in foobar.vfl
cvex foobar(export vector out = {0,0,0})
{
    out.y = 0.5;
}

and this code in the Attrib Wrangle SOP (connected to an output of a Grid SOP):
import foobar;
foobar("out", v@P);

and the grid is "lifted" in the viewport to y=0.5 plane.

Thank you, got it now ! I wasn't sure about the syntax !


Cheers,
  • Quick Links