Skip to content

Commit 61db6a8

Browse files
committed
on behalf of @brookea
Added shared memory session option to Houdini Engine for Unity
1 parent 243020f commit 61db6a8

File tree

10 files changed

+484
-15
lines changed

10 files changed

+484
-15
lines changed

Plugins/HoudiniEngineUnity/Editor/HEU_EditorMenu.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ public static void CreateSocketSession()
7676
}
7777
}
7878

79+
[MenuItem(HEU_Defines.HEU_PRODUCT_NAME + "/Session/Create/" + HEU_EditorStrings.RPC_SHARED_MEMORY_SESSION, false, 0)]
80+
public static void CreateSharedMemorySession()
81+
{
82+
bool bResult = HEU_SessionManager.CreateThriftSharedMemorySession(HEU_PluginSettings.Session_SharedMemoryName,
83+
HEU_PluginSettings.Session_SharedMemoryBufferType, HEU_PluginSettings.Session_SharedMemoryBufferSize,
84+
HEU_PluginSettings.Session_AutoClose, HEU_PluginSettings.Session_Timeout, true);
85+
if (!bResult)
86+
{
87+
HEU_EditorUtility.DisplayErrorDialog("Create Session", HEU_SessionManager.GetLastSessionError(), "OK");
88+
}
89+
}
90+
7991
[MenuItem(HEU_Defines.HEU_PRODUCT_NAME + "/Session/Connect/" + HEU_EditorStrings.RPC_PIPE_SESSION, false, 0)]
8092
public static void ConnectPipeSession()
8193
{
@@ -98,6 +110,19 @@ public static void ConnectSocketSession()
98110
}
99111
}
100112

113+
[MenuItem(HEU_Defines.HEU_PRODUCT_NAME + "/Session/Connect/" + HEU_EditorStrings.RPC_SHARED_MEMORY_SESSION, false, 0)]
114+
public static void ConnectSharedMemorySession()
115+
{
116+
bool bResult = HEU_SessionManager.ConnectThriftSharedMemorySession(
117+
HEU_PluginSettings.Session_SharedMemoryName, HEU_PluginSettings.Session_SharedMemoryBufferType,
118+
HEU_PluginSettings.Session_SharedMemoryBufferSize, HEU_PluginSettings.Session_AutoClose,
119+
HEU_PluginSettings.Session_Timeout);
120+
if (!bResult)
121+
{
122+
HEU_EditorUtility.DisplayErrorDialog("Connect Session", HEU_SessionManager.GetLastSessionError(), "OK");
123+
}
124+
}
125+
101126
[MenuItem(HEU_Defines.HEU_PRODUCT_NAME + "/SessionSync", false, 0)]
102127
public static void SessionSync()
103128
{
@@ -371,4 +396,4 @@ public static void QueryMeshTopology()
371396
HEU_EditorUtility.QuerySelectedMeshTopology();
372397
}
373398
}
374-
} // HoudiniEngineUnity
399+
} // HoudiniEngineUnity

Plugins/HoudiniEngineUnity/Editor/HEU_EditorStrings.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public static class HEU_EditorStrings
3939
public const string INPROCESS_SESSION = "In-Process Session";
4040
public const string RPC_PIPE_SESSION = "Pipe Session";
4141
public const string RPC_SOCKET_SESSION = "Socket Session";
42+
public const string RPC_SHARED_MEMORY_SESSION = "Shared Memory Session";
4243
public const string GET_SESSION_INFO = "Session Info";
4344
public const string CLOSE_DEFAULT_SESSION = "Close Default Session";
4445
public const string CLOSE_ALL_SESSIONS = "Close All Sessions";
@@ -58,4 +59,4 @@ public static class HEU_EditorStrings
5859
public const string HELP_FORUM = "Online Forum";
5960
public const string HELP_FORUM_URL = "http://www.sidefx.com/forum/50/";
6061
}
61-
} // HoudiniEngineUnity
62+
} // HoudiniEngineUnity

Plugins/HoudiniEngineUnity/Editor/UI/HEU_SessionSyncWindow.cs

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ private void ReInitialize()
8383

8484
_port = HEU_PluginSettings.Session_Port;
8585
_pipeName = HEU_PluginSettings.Session_PipeName;
86+
_sharedMemoryName = HEU_PluginSettings.Session_SharedMemoryName;
87+
_sharedMemoryBufferType = HEU_PluginSettings.Session_SharedMemoryBufferType;
88+
_sharedMemoryBufferSize = HEU_PluginSettings.Session_SharedMemoryBufferSize;
8689

8790
_log = new StringBuilder();
8891

@@ -214,6 +217,46 @@ private void OnGUI()
214217
_port = newPort;
215218
}
216219
}
220+
else if (_sessionMode == SessionMode.SharedMemory)
221+
{
222+
string newSharedMemoryName =
223+
EditorGUILayout.DelayedTextField("Name", _sharedMemoryName);
224+
if (_sharedMemoryName != newSharedMemoryName)
225+
{
226+
HEU_PluginSettings.Session_SharedMemoryName = newSharedMemoryName;
227+
_sharedMemoryName = newSharedMemoryName;
228+
}
229+
230+
string[] bufferTypeOptions = {"Ring Buffer", "Fixed Length Buffer"};
231+
int oldValueInt = 0;
232+
if (_sharedMemoryBufferType == HAPI_ThriftSharedMemoryBufferType.HAPI_THRIFT_SHARED_MEMORY_RING_BUFFER)
233+
oldValueInt = 0;
234+
else if (_sharedMemoryBufferType == HAPI_ThriftSharedMemoryBufferType.HAPI_THRIFT_SHARED_MEMORY_FIXED_LENGTH_BUFFER)
235+
oldValueInt = 1;
236+
int newValueInt = EditorGUILayout.Popup("Buffer Type",
237+
oldValueInt, bufferTypeOptions);
238+
239+
HAPI_ThriftSharedMemoryBufferType newSharedMemoryBufferType =
240+
HAPI_ThriftSharedMemoryBufferType.HAPI_THRIFT_SHARED_MEMORY_RING_BUFFER;
241+
if (newValueInt == 0)
242+
newSharedMemoryBufferType = HAPI_ThriftSharedMemoryBufferType.HAPI_THRIFT_SHARED_MEMORY_RING_BUFFER;
243+
else if (newValueInt == 1)
244+
newSharedMemoryBufferType = HAPI_ThriftSharedMemoryBufferType.HAPI_THRIFT_SHARED_MEMORY_FIXED_LENGTH_BUFFER;
245+
246+
if (_sharedMemoryBufferType != newSharedMemoryBufferType)
247+
{
248+
HEU_PluginSettings.Session_SharedMemoryBufferType = newSharedMemoryBufferType;
249+
_sharedMemoryBufferType = newSharedMemoryBufferType;
250+
}
251+
252+
int newSharedMemoryBufferSize =
253+
EditorGUILayout.DelayedIntField("Buffer Size", _sharedMemoryBufferSize);
254+
if (_sharedMemoryBufferSize != newSharedMemoryBufferSize)
255+
{
256+
HEU_PluginSettings.Session_SharedMemoryBufferSize = newSharedMemoryBufferSize;
257+
_sharedMemoryBufferSize = newSharedMemoryBufferSize;
258+
}
259+
}
217260

218261
EditorGUI.indentLevel--;
219262
}
@@ -345,6 +388,7 @@ private void ConnectSessionSync(HEU_SessionSyncData syncData)
345388

346389
bool result = InternalConnect(_sessionMode, _pipeName,
347390
HEU_PluginSettings.Session_Localhost, _port,
391+
_sharedMemoryName, _sharedMemoryBufferType, _sharedMemoryBufferSize,
348392
HEU_PluginSettings.Session_AutoClose,
349393
HEU_PluginSettings.Session_Timeout,
350394
true);
@@ -379,8 +423,10 @@ private void ConnectSessionSync(HEU_SessionSyncData syncData)
379423
/// </summary>
380424
private bool InternalConnect(
381425
SessionMode sessionType, string pipeName,
382-
string ip, int port, bool autoClose, float timeout,
383-
bool logError)
426+
string ip, int port, string sharedMemoryName,
427+
HAPI_ThriftSharedMemoryBufferType sharedMemoryBufferType,
428+
int sharedMemoryBufferSize,
429+
bool autoClose, float timeout, bool logError)
384430
{
385431
if (sessionType == SessionMode.Pipe)
386432
{
@@ -390,7 +436,7 @@ private bool InternalConnect(
390436
timeout,
391437
logError);
392438
}
393-
else
439+
else if (sessionType == SessionMode.Socket)
394440
{
395441
return HEU_SessionManager.ConnectSessionSyncUsingThriftSocket(
396442
ip,
@@ -399,6 +445,12 @@ private bool InternalConnect(
399445
timeout,
400446
logError);
401447
}
448+
else
449+
{
450+
return HEU_SessionManager.ConnectSessionSyncUsingThriftSharedMemory(
451+
sharedMemoryName, sharedMemoryBufferType,
452+
sharedMemoryBufferSize, autoClose, timeout, logError);
453+
}
402454
}
403455

404456
/// <summary>
@@ -436,10 +488,31 @@ private bool OpenHoudini()
436488
{
437489
args = string.Format("-hess=pipe:{0}", _pipeName);
438490
}
439-
else
491+
else if (_sessionMode == SessionMode.Socket)
440492
{
441493
args = string.Format("-hess=port:{0}", _port);
442494
}
495+
else
496+
{
497+
if (_sharedMemoryBufferType ==
498+
HAPI_ThriftSharedMemoryBufferType.HAPI_THRIFT_SHARED_MEMORY_RING_BUFFER)
499+
{
500+
args = string.Format("-hess=shared:{0}:{1}:{2}",
501+
"ring", _sharedMemoryBufferSize, _sharedMemoryName);
502+
}
503+
else if (_sharedMemoryBufferType ==
504+
HAPI_ThriftSharedMemoryBufferType.HAPI_THRIFT_SHARED_MEMORY_FIXED_LENGTH_BUFFER)
505+
{
506+
args = string.Format("-hess=shared:{0}:{1}:{2}",
507+
"fixed", _sharedMemoryBufferSize, _sharedMemoryName);
508+
}
509+
else
510+
{
511+
Log(@"Failed to start Houdini because an invalid shared
512+
memory buffer type was provided.");
513+
return false;
514+
}
515+
}
443516

444517
Log("Opening Houdini...");
445518

@@ -535,6 +608,9 @@ private void UpdateConnecting(HEU_SessionSyncData syncData)
535608
{
536609
if (InternalConnect(_sessionMode, _pipeName,
537610
HEU_PluginSettings.Session_Localhost, _port,
611+
_sharedMemoryName,
612+
_sharedMemoryBufferType,
613+
_sharedMemoryBufferSize,
538614
HEU_PluginSettings.Session_AutoClose,
539615
HEU_PluginSettings.Session_Timeout, false))
540616
{
@@ -937,6 +1013,15 @@ public void ClearLog()
9371013
// Pipe name
9381014
public string _pipeName = "";
9391015

1016+
// Shared memory name
1017+
public string _sharedMemoryName = "";
1018+
1019+
// Shared memory buffer type
1020+
public HAPI_ThriftSharedMemoryBufferType _sharedMemoryBufferType;
1021+
1022+
// Shared memory buffer size
1023+
public int _sharedMemoryBufferSize = 0;
1024+
9401025
// Seconds between connection attempts while Houdini launches
9411026
private const float CONNECTION_ATTEMPT_RATE = 5f;
9421027

@@ -968,4 +1053,4 @@ public void ClearLog()
9681053

9691054
private HEU_OutputLogUIComponent _outputLogUI = null;
9701055
}
971-
}
1056+
}

Plugins/HoudiniEngineUnity/Editor/UI/HEU_SettingsWindow.cs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,51 @@ private bool DrawSessionSettings()
793793
}
794794
}
795795
HEU_EditorUI.DrawSeparator();
796+
{
797+
string oldValue = HEU_PluginSettings.Session_SharedMemoryName;
798+
string newValue = EditorGUILayout.DelayedTextField("Shared Memory Session Name", oldValue);
799+
if (oldValue != newValue && !string.IsNullOrEmpty(newValue))
800+
{
801+
HEU_PluginSettings.Session_SharedMemoryName = newValue;
802+
bChanged = true;
803+
}
804+
}
805+
HEU_EditorUI.DrawSeparator();
806+
{
807+
int oldValue = HEU_PluginSettings.Session_SharedMemoryBufferSize;
808+
int newValue = EditorGUILayout.DelayedIntField("Shared Memory Session Buffer Size", oldValue);
809+
if (oldValue != newValue)
810+
{
811+
HEU_PluginSettings.Session_SharedMemoryBufferSize = newValue;
812+
bChanged = true;
813+
}
814+
}
815+
HEU_EditorUI.DrawSeparator();
816+
{
817+
string[] bufferTypeOptions =
818+
{"Ring Buffer", "Fixed Length Buffer"};
819+
HAPI_ThriftSharedMemoryBufferType oldValue = HEU_PluginSettings.Session_SharedMemoryBufferType;
820+
int selectedIndex = 0;
821+
if (oldValue == HAPI_ThriftSharedMemoryBufferType.HAPI_THRIFT_SHARED_MEMORY_RING_BUFFER)
822+
selectedIndex = 0;
823+
else if (oldValue == HAPI_ThriftSharedMemoryBufferType.HAPI_THRIFT_SHARED_MEMORY_FIXED_LENGTH_BUFFER)
824+
selectedIndex = 1;
825+
int newValueInt =
826+
EditorGUILayout.Popup("Shared Memory Session Buffer Type", selectedIndex, bufferTypeOptions);
827+
828+
HAPI_ThriftSharedMemoryBufferType newValue;
829+
if (newValueInt == 0)
830+
newValue = HAPI_ThriftSharedMemoryBufferType.HAPI_THRIFT_SHARED_MEMORY_RING_BUFFER;
831+
else
832+
newValue = HAPI_ThriftSharedMemoryBufferType.HAPI_THRIFT_SHARED_MEMORY_FIXED_LENGTH_BUFFER;
833+
834+
if (oldValue != newValue)
835+
{
836+
HEU_PluginSettings.Session_SharedMemoryBufferType = newValue;
837+
bChanged = true;
838+
}
839+
}
840+
HEU_EditorUI.DrawSeparator();
796841
{
797842
float oldValue = HEU_PluginSettings.Session_Timeout;
798843
float newValue = EditorGUILayout.DelayedFloatField("Session Timeout", oldValue);
@@ -975,4 +1020,4 @@ private bool DrawAdvancedSettings()
9751020
return bChanged;
9761021
}
9771022
}
978-
} // HoudiniEngineUnity
1023+
} // HoudiniEngineUnity

Plugins/HoudiniEngineUnity/Scripts/Core/HEU_Defines.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ public class HEU_Defines
7676
public const string HEU_SESSION_PIPENAME = "hapi";
7777
public const string HEU_SESSION_LOCALHOST = "localhost";
7878
public const int HEU_SESSION_PORT = 9090;
79+
public const string HEU_SESSION_SHARED_MEMORY_NAME = "hapi";
80+
public const int HEU_SESSION_SHARED_MEMORY_BUFFER_SIZE = 100;
81+
public const HAPI_ThriftSharedMemoryBufferType HEU_SESSION_SHARED_MEMORY_BUFFER_TYPE
82+
= HAPI_ThriftSharedMemoryBufferType.HAPI_THRIFT_SHARED_MEMORY_RING_BUFFER;
7983
public const float HEU_SESSION_TIMEOUT = 10000f;
8084
public const bool HEU_SESSION_AUTOCLOSE = true;
8185

@@ -421,4 +425,4 @@ public class HEU_Defines
421425
public const string HEU_KEY_CTRL = "Ctrl";
422426
#endif
423427
}
424-
} // HoudiniEngineUnity
428+
} // HoudiniEngineUnity

Plugins/HoudiniEngineUnity/Scripts/Core/HEU_PluginSettings.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,39 @@ public static int Session_Port
433433
set => HEU_PluginStorage.Instance.Set("HAPI_SessionPort", value);
434434
}
435435

436+
public static string Session_SharedMemoryName
437+
{
438+
get
439+
{
440+
string attrValue = HEU_Defines.HEU_SESSION_SHARED_MEMORY_NAME;
441+
HEU_PluginStorage.Instance.Get("HAPI_SharedMemoryName", out attrValue, attrValue);
442+
return attrValue;
443+
}
444+
set => HEU_PluginStorage.Instance.Set("HAPI_SharedMemoryName", value);
445+
}
446+
447+
public static int Session_SharedMemoryBufferSize
448+
{
449+
get
450+
{
451+
int attrValue = HEU_Defines.HEU_SESSION_SHARED_MEMORY_BUFFER_SIZE;
452+
HEU_PluginStorage.Instance.Get("HAPI_SharedMemoryBufferSize", out attrValue, attrValue);
453+
return attrValue;
454+
}
455+
set => HEU_PluginStorage.Instance.Set("HAPI_SharedMemoryBufferSize", value);
456+
}
457+
458+
public static HAPI_ThriftSharedMemoryBufferType Session_SharedMemoryBufferType
459+
{
460+
get
461+
{
462+
int attrValue = (int)HEU_Defines.HEU_SESSION_SHARED_MEMORY_BUFFER_TYPE;
463+
HEU_PluginStorage.Instance.Get("HAPI_SharedMemoryBufferType", out attrValue, attrValue);
464+
return (HAPI_ThriftSharedMemoryBufferType)attrValue;
465+
}
466+
set => HEU_PluginStorage.Instance.Set("HAPI_SharedMemoryBufferType", (int)value);
467+
}
468+
436469
public static float Session_Timeout
437470
{
438471
get
@@ -956,4 +989,4 @@ public static bool EditableNodesToolsEnabled
956989
set => HEU_PluginStorage.Instance.Set("HAPI_EditableNodesToolsEnabled", value);
957990
}
958991
}
959-
} // HoudiniEngineUnity
992+
} // HoudiniEngineUnity

Plugins/HoudiniEngineUnity/Scripts/Sessions/HEU_SessionBase.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,17 @@ public virtual bool CreateThriftPipeSession(bool bIsDefaultSession,
279279
return false;
280280
}
281281

282+
public virtual bool CreateThriftSharedMemorySession(bool bIsDefaultSession,
283+
string sharedMemoryName,
284+
HAPI_ThriftSharedMemoryBufferType sharedMemoryBufferType = HEU_Defines.HEU_SESSION_SHARED_MEMORY_BUFFER_TYPE,
285+
int sharedMemoryBufferSize = HEU_Defines.HEU_SESSION_SHARED_MEMORY_BUFFER_SIZE,
286+
bool autoClose = HEU_Defines.HEU_SESSION_AUTOCLOSE,
287+
float timeout = HEU_Defines.HEU_SESSION_TIMEOUT,
288+
bool bLogError = true)
289+
{
290+
return false;
291+
}
292+
282293
public virtual bool CreateCustomSession(bool bIsDefaultSession)
283294
{
284295
return false;
@@ -305,6 +316,19 @@ public virtual bool ConnectThriftPipeSession(bool bIsDefaultSession,
305316
return false;
306317
}
307318

319+
public virtual bool ConnectThriftSharedMemorySession(
320+
bool bIsDefaultSession,
321+
string sharedMemoryName = HEU_Defines.HEU_SESSION_SHARED_MEMORY_NAME,
322+
HAPI_ThriftSharedMemoryBufferType sharedMemoryBufferType = HEU_Defines.HEU_SESSION_SHARED_MEMORY_BUFFER_TYPE,
323+
int sharedMemoryBufferSize = HEU_Defines.HEU_SESSION_SHARED_MEMORY_BUFFER_SIZE,
324+
bool autoClose = HEU_Defines.HEU_SESSION_AUTOCLOSE,
325+
float timeout = HEU_Defines.HEU_SESSION_TIMEOUT,
326+
bool logError = true,
327+
bool autoInitialize = true)
328+
{
329+
return false;
330+
}
331+
308332
/// <summary>
309333
/// Close the existing session.
310334
/// </summary>
@@ -1754,4 +1778,4 @@ public virtual bool SetNodeDisplay(HAPI_NodeId node_id, int onOff)
17541778
return false;
17551779
}
17561780
}
1757-
} // HoudiniEngineUnity
1781+
} // HoudiniEngineUnity

0 commit comments

Comments
 (0)