HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VEX_Ops.C
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  *----------------------------------------------------------------------------
26  * This is a sample VEX operator DSO
27  */
28 
29 #if defined(LINUX)
30 
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <unistd.h>
34 #include <UT/UT_DSOVersion.h>
35 #include <UT/UT_Thread.h>
36 #include <VEX/VEX_VexOp.h>
37 
38 using namespace UT::Literal;
39 
40 namespace HDK_Sample {
41 //
42 // Callback for time() function
43 //
44 template <VEX_Precision PREC>
45 static void
46 pid_Evaluate(int, void *argv[], void *)
47 {
48  VEXint<PREC> *result = (VEXint<PREC> *)argv[0];
49  *result = getpid();
50 }
51 
52 template <VEX_Precision PREC>
53 static void
54 tid_Evaluate(int, void *argv[], void *)
55 {
56  VEXint<PREC> *result = (VEXint<PREC> *)argv[0];
57  *result = UT_Thread::getMyThreadId();
58 }
59 
60 template <VEX_Precision PREC>
61 static void
62 printStuff(int, void *argv[], void *)
63 {
64  VEXint<PREC> *result = (VEXint<PREC> *)argv[0];
65  static int callCount = 0;
66  fprintf(stderr, "Still here %d\n", callCount++);
67  result[0] = 0;
68 }
69 
70 static void *
71 initFunc()
72 {
73  fprintf(stderr, "Init\n");
74  return 0;
75 }
76 
77 static void
78 cleanupFunc(void *data)
79 {
80  fprintf(stderr, "Cleanup: Data = %p\n", data);
81 }
82 
83 }
84 
85 //
86 // Installation function
87 //
88 using namespace HDK_Sample;
89 void
90 newVEXOp(void *)
91 {
92  //
93  // Returns a random number based on the seed passed in
94  new VEX_VexOp("getpid@&I"_sh, pid_Evaluate<VEX_32>,
96  initFunc, cleanupFunc, VEX_OPTIMIZE_1);
97  new VEX_VexOp("gettid@&I"_sh, tid_Evaluate<VEX_32>,
99  0, 0, VEX_OPTIMIZE_1);
100  new VEX_VexOp("sticky@&I"_sh, printStuff<VEX_32>,
102  0, 0, VEX_OPTIMIZE_0);
103  new VEX_VexOp("rcode@&I*F*FFF"_sh, printStuff<VEX_32>,
105  0, 0, VEX_OPTIMIZE_0, true);
106  new VEX_VexOp("rcode@&I*F*FS"_sh, printStuff<VEX_32>,
108  0, 0, VEX_OPTIMIZE_0);
109 }
110 
111 #endif
Use this class to extend VEX by adding custom VEX functions.
Definition: VEX_VexOp.h:150
**But if you need a result
Definition: thread.h:613
#define VEX_OPTIMIZE_0
Definition: VEX_VexOp.h:126
#define VEX_OP_CONTEXT
Definition: VEX_VexTypes.h:86
#define VEX_OPTIMIZE_1
Definition: VEX_VexOp.h:127
auto fprintf(std::FILE *f, const S &fmt, const T &...args) -> int
Definition: printf.h:602
#define VEX_SHADING_CONTEXT
Definition: VEX_VexTypes.h:79
static ut_thread_id_t getMyThreadId()
typename VEX_PrecisionResolver< P >::int_type VEXint
Definition: VEX_PodTypes.h:68
SYS_VISIBILITY_EXPORT void newVEXOp(void *)
Definition: VEX_Example.C:143
Definition: format.h:895