Hey everyone,
I am using SharpGenTools.Sdk version 2.4.2-beta
I wanted to give SharpGenTools another shot to create a C# wrapper for the SLANG shader SDK. I have slightly modified slang.h to work around a few minor issues (see here) . But right now I am stuck on a larger obstacle.
slang defines a dozen free functions like:
SLANG_EXTERN_C SLANG_API void slang_shutdown();
Which I think translates to this on my machine:
extern "C" __declspec(dllimport) void slang_shutdown();
To accommodate such functions I have created a class to put them in:
<extension>
<create class="CapriKit.Slang.FreeFunctions" visibility="public static" />
</extension>
But whenever I map such a free function like this:
<map function="slang_shutdown" group="CapriKit.Slang.FreeFunctions" />
I get a big NullReferenceException (see below). Does anybody know the cause of this exception, if its a bug and if/how I can work around it?
The "SharpGenTask" task failed unexpectedly.
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.SyntaxToken.Identifier(GreenNode leading, String text, GreenNode trailing)
at Microsoft.CodeAnalysis.CSharp.SyntaxFactory.Identifier(String text)
at SharpGen.Generator.FunctionImportCodeGenerator.<GenerateCode>d__4.MoveNext()
at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at SharpGen.Generator.SyntaxListBase`2.AddRange(IEnumerable`1 collection)
at SharpGen.Generator.SyntaxListBase`2.TryAddPlatform[T,TSyntax,TGenerator](T source, TGenerator generator)
at SharpGen.Generator.MemberSyntaxList.Add[T](T source, IMemberCodeGenerator`1 generator)
at SharpGen.Generator.FunctionCodeGenerator.GenerateCode(CsFunction csElement)
at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at SharpGen.Generator.SyntaxListBase`2.AddRange(IEnumerable`1 collection)
at SharpGen.Generator.SyntaxListBase`2.TryAddGeneric[T,TSyntax,TGenerator](IEnumerable`1 source, TGenerator generator)
at SharpGen.Generator.SyntaxListBase`2.TryAdd[T,TSyntax,TGenerator](IEnumerable`1 source, TGenerator generator)
at SharpGen.Generator.MemberSyntaxList.AddRange[T](IEnumerable`1 source, IMemberCodeGenerator`1 generator)
at SharpGen.Generator.GroupCodeGenerator.GenerateCode(CsGroup csElement)
at System.Linq.Enumerable.<>c__DisplayClass7_0`3.<CombineSelectors>b__0(TSource x)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at SharpGen.Generator.SyntaxListBase`2.AddRange(IEnumerable`1 collection)
at SharpGen.Generator.SyntaxListBase`2.TryAddGeneric[T,TSyntax,TGenerator](IEnumerable`1 source, TGenerator generator)
at SharpGen.Generator.SyntaxListBase`2.TryAdd[T,TSyntax,TGenerator](IEnumerable`1 source, TGenerator generator)
at SharpGen.Generator.MemberSyntaxList.AddRange[T](IEnumerable`1 source, IMemberCodeGenerator`1 generator)
at SharpGen.Generator.RoslynGenerator.<>c__DisplayClass3_0.<Run>g__NamespaceSelector|1(CsNamespace ns)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at Microsoft.CodeAnalysis.SyntaxList`1.CreateNode(IEnumerable`1 nodes)
at SharpGen.Generator.RoslynGenerator.Run(CsAssembly csAssembly, Ioc ioc)
at SharpGenTools.Sdk.SharpGenTask.ExecuteImpl() in D:\a\SharpGenTools\SharpGenTools\SharpGenTools.Sdk\SharpGenTask.cs:line 468
at SharpGenTools.Sdk.SharpGenTask.Execute() in D:\a\SharpGenTools\SharpGenTools\SharpGenTools.Sdk\SharpGenTask.cs:line 133
at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
My full mapping.xml file:
<?xml version="1.0" encoding="utf-8"?>
<config id="caprikit-slang" xmlns="urn:SharpGen.Config">
<namespace>CapriKit.Slang</namespace>
<include-dir override="true">$(THIS_CONFIG_PATH)/native</include-dir>
<include-prolog>
#define SLANG_DISABLE_EXCEPTIONS
</include-prolog>
<include file="slang.h" namespace="CapriKit.Slang" attach="true"/>
<bindings>
<bind from="SlangReflectionType" to="IntPtr" />
<bind from="ICompileRequest" to="IntPtr" />
<bind from="IGlobalSession" to="IntPtr" />
</bindings>
<extension>
<create class="CapriKit.Slang.FreeFunctions" visibility="public static" />
</extension>
<mapping>
<map function="slang_shutdown" class="CapriKit.Slang.FreeFunctions" />
<remove function="slang_getEmbeddedCoreModule" group="CapriKit.Slang.FreeFunctions" />
<remove function="slang_createBlob" group="CapriKit.Slang.FreeFunctions" />
<remove function="slang_loadModuleInfoFromIRBlob" group="CapriKit.Slang.FreeFunctions" />
<remove function="slang_disassembleByteCode" group="CapriKit.Slang.FreeFunctions" />
<remove function="slang_createGlobalSessionWithoutCoreModule" group="CapriKit.Slang.FreeFunctions" />
<remove function="slang_createGlobalSession2" group="CapriKit.Slang.FreeFunctions" />
<remove function="slang_createGlobalSession" group="CapriKit.Slang.FreeFunctions" />
<remove function="slang_createByteCodeRunner" group="CapriKit.Slang.FreeFunctions" />
<remove function="slang_createByteCodeRunner" group="CapriKit.Slang.FreeFunctions" />
<remove function="slang_loadModuleFromSource" group="CapriKit.Slang.FreeFunctions" />
<remove function="slang_loadModuleFromIRBlob" group="CapriKit.Slang.FreeFunctions" />
<remove function="slang_getLastInternalErrorMessage" group="CapriKit.Slang.FreeFunctions" />
<remove function="spGetBuildTagString" />
<!-- TODO: there is something special about the members of these two structs that I need to double check
right now I just remove all fields to pretend there is no problem -->
<map struct="VMExecOperand" name="VMExecOperand" />
<remove field="VMExecOperand::.+" />
<map struct="SpecializationArg" name="SpecializationArg" />
<remove field="SpecializationArg::.+" />
</mapping>
</config>
Note: slang requires C++17 so I have set
<PropertyGroup>
<CppStandard>c++17</CppStandard>
</PropertyGroup>
In my csproj file.
Hey everyone,
I am using SharpGenTools.Sdk version 2.4.2-beta
I wanted to give SharpGenTools another shot to create a C# wrapper for the SLANG shader SDK. I have slightly modified
slang.hto work around a few minor issues (see here) . But right now I am stuck on a larger obstacle.slang defines a dozen free functions like:
Which I think translates to this on my machine:
To accommodate such functions I have created a class to put them in:
But whenever I map such a free function like this:
I get a big NullReferenceException (see below). Does anybody know the cause of this exception, if its a bug and if/how I can work around it?
My full mapping.xml file:
Note: slang requires C++17 so I have set
In my csproj file.