Skip to content

Commit 423730b

Browse files
committed
Add PreferUnsigned option for TransformEnums.CoerceBackingTypes and use it for the Vulkan bindings
1 parent cc43a21 commit 423730b

353 files changed

Lines changed: 401 additions & 351 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.silktouch/82fde6eb3b68e085.stout

0 Bytes
Binary file not shown.

generator.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@
342342
"MemberValue": "0x7FFFFFFF"
343343
}
344344
],
345-
"CoerceBackingTypes": "PreferSigned",
345+
"CoerceBackingTypes": "PreferUnsigned",
346346
"RewriteMemberValues": true
347347
},
348348
"AddVTables": {

sources/SilkTouch/SilkTouch/Mods/TransformEnums.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ public enum EnumBackingTypePreference
3232
/// match the backing types of enums generated on Windows.
3333
/// </remarks>
3434
PreferSigned,
35+
36+
/// <summary>
37+
/// Replace unsigned backing types with signed backing types.
38+
/// </summary>
39+
/// <remarks>
40+
/// This can be used to ensure that the backing types of enums generated on Windows
41+
/// match the backing types of enums generated on Unix.
42+
/// </remarks>
43+
PreferUnsigned,
3544
}
3645

3746
/// <summary>
@@ -317,6 +326,47 @@ private class Rewriter(Configuration config, List<EnumMemberFilter> removeMember
317326

318327
break;
319328
}
329+
330+
case EnumBackingTypePreference.PreferUnsigned:
331+
{
332+
var baseList = originalNode.BaseList;
333+
if (baseList == null)
334+
{
335+
break;
336+
}
337+
338+
var baseTypes = baseList.Types
339+
.Select<BaseTypeSyntax, BaseTypeSyntax?>(t =>
340+
{
341+
var type = semanticModel.GetTypeInfo(t.Type).Type;
342+
343+
if (SymbolEqualityComparer.Default.Equals(type, compilation.GetSpecialType(SpecialType.System_Int32)))
344+
{
345+
return SimpleBaseType(PredefinedType(Token(SyntaxKind.UIntKeyword)));
346+
}
347+
348+
if (SymbolEqualityComparer.Default.Equals(type, compilation.GetSpecialType(SpecialType.System_Int64)))
349+
{
350+
return SimpleBaseType(PredefinedType(Token(SyntaxKind.ULongKeyword)));
351+
}
352+
353+
return t;
354+
})
355+
.Where(x => x is not null)
356+
.Cast<BaseTypeSyntax>()
357+
.ToList();
358+
359+
if (baseTypes.Count == 0)
360+
{
361+
node = node.WithBaseList(BaseList([SimpleBaseType(PredefinedType(Token(SyntaxKind.UIntKeyword)))]));
362+
}
363+
else
364+
{
365+
node = node.WithBaseList(BaseList([..baseTypes]));
366+
}
367+
368+
break;
369+
}
320370
}
321371

322372
node = node.WithMembers([..members]);

sources/Vulkan/Vulkan/Enums/AccessFlags2.gen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Silk.NET.Vulkan;
1010

1111
[Transformed]
1212
[Flags]
13-
public enum AccessFlags2 : long
13+
public enum AccessFlags2 : ulong
1414
{
1515
None = 0x0,
1616
IndirectCommandReadBit = 0x1,

sources/Vulkan/Vulkan/Enums/AccessFlags3KHR.gen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Silk.NET.Vulkan;
1010

1111
[Transformed]
1212
[Flags]
13-
public enum AccessFlags3KHR : long
13+
public enum AccessFlags3KHR : ulong
1414
{
1515
Access3NoneKHR = 0x0,
1616
}

sources/Vulkan/Vulkan/Enums/BufferUsageFlags2.gen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Silk.NET.Vulkan;
1010

1111
[Transformed]
1212
[Flags]
13-
public enum BufferUsageFlags2 : long
13+
public enum BufferUsageFlags2 : ulong
1414
{
1515
None = 0x0,
1616
TransferSrcBit = 0x1,

sources/Vulkan/Vulkan/Enums/DataGraphPipelineDispatchFlagsARM.gen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Silk.NET.Vulkan;
1010

1111
[Transformed]
1212
[Flags]
13-
public enum DataGraphPipelineDispatchFlagsARM : long
13+
public enum DataGraphPipelineDispatchFlagsARM : ulong
1414
{
1515
None = 0x0,
1616
}

sources/Vulkan/Vulkan/Enums/DataGraphPipelineSessionCreateFlagsARM.gen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Silk.NET.Vulkan;
1010

1111
[Transformed]
1212
[Flags]
13-
public enum DataGraphPipelineSessionCreateFlagsARM : long
13+
public enum DataGraphPipelineSessionCreateFlagsARM : ulong
1414
{
1515
None = 0x0,
1616
ProtectedBitARM = 0x1,

sources/Vulkan/Vulkan/Enums/ExportMetalObjectTypeFlagsEXT.gen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Silk.NET.Vulkan;
1010

1111
[Transformed]
1212
[Flags]
13-
public enum ExportMetalObjectTypeFlagsEXT
13+
public enum ExportMetalObjectTypeFlagsEXT : uint
1414
{
1515
None = 0x0,
1616
}

sources/Vulkan/Vulkan/Enums/FormatFeatureFlags2.gen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Silk.NET.Vulkan;
1010

1111
[Transformed]
1212
[Flags]
13-
public enum FormatFeatureFlags2 : long
13+
public enum FormatFeatureFlags2 : ulong
1414
{
1515
None = 0x0,
1616
SampledImageBit = 0x1,

0 commit comments

Comments
 (0)