11# Generator Mods
22
3- Silk's SilkTouch bindings generator is designed to be a linear pipeline where a set of mods sequentially transform C#
4- source code represented by Roslyn syntax nodes. This approach used by Silk 3 is in contrast to the approach in Silk 2,
5- where a monolithic generator output code represented by bespoke data structures. Silk 3 focuses on breaking down each
6- transformation step into its own mod to aid in maintainability and understanding of the codebase.
3+ Silk.NET 's SilkTouch bindings generator is designed to be a linear pipeline where a set of mods sequentially transform
4+ C# source code represented by Roslyn syntax nodes. This approach used by Silk.NET 3.X is in contrast to the approach in
5+ Silk.NET 2.X, where a monolithic generator output code represented by bespoke data structures. Silk.NET 3.X focuses on
6+ breaking down each transformation step into its own mod to aid in maintainability and understanding of the codebase.
77
88This document is intended to act as both documentation on how to use the mods as well notes on how the mods were
99implemented. For users of the generator, first read the [ Using the Generator] ( using-the-generator.md ) documentation,
@@ -27,8 +27,8 @@ ideally, no communication is done at all so that mods are kept completely standa
2727
2828### Mod Configuration
2929
30- Mods are configured as part of bindings generation jobs in a separate C# project. Silk's own configuration project is
31- the
30+ Mods are configured as part of bindings generation jobs in a separate C# project. Silk.NET 's own configuration project
31+ is the
3232[ ` Silk.NET.SilkTouch.Jobs ` ] ( https://github.com/dotnet/Silk.NET/blob/develop/3.0/sources/SilkTouch/Jobs/Program.cs )
3333project. This project can be used as reference for your own SilkTouch configuration projects. More information about
3434using the SilkTouch generator can be found in the [ Using the Generator] ( using-the-generator.md ) documentation.
@@ -53,12 +53,12 @@ Standardized sections:
5353 represents.
5454
5555- ** Usage recommendations** - Provides information such as situations the mod is useful for, how to configure it, and
56- where to place it in the mod order. This information can include examples of how Silk's own bindings use it or whether
57- the mod is mainly designed for Silk internal use.
56+ where to place it in the mod order. This information can include examples of how Silk.NET 's own bindings use it or
57+ whether the mod is mainly designed for Silk.NET internal use.
5858
5959General recommendations:
6060
61- For the most part, mods should be configured to run in an order similar to the mod orders used by Silk's existing
61+ For the most part, mods should be configured to run in an order similar to the mod orders used by Silk.NET 's existing
6262bindings. The same goes for the configuration, but more care needs to be done regarding whether the configuration is
6363specific to that set of bindings.
6464
@@ -130,10 +130,10 @@ This mod merges multiple sets of source code into one set of source code.
130130Usage recommendations:
131131
132132The main use case for this mod is for when an API has different APIs available depending on the platform. For example,
133- OpenXR has platform-specific integrations. Silk handles this by generating the raw OpenXR bindings on Windows, Linux ,
134- and Mac, then combining the three sets of raw bindings into one before doing further transformations.
133+ OpenXR has platform-specific integrations. Silk.NET handles this by generating the raw OpenXR bindings on Windows,
134+ Linux, and Mac, then combining the three sets of raw bindings into one before doing further transformations.
135135
136- Silk also uses this mod to merge the different OpenGL profiles into one.
136+ Silk.NET also uses this mod to merge the different OpenGL profiles into one.
137137
138138### ChangeNamespace
139139
@@ -169,26 +169,26 @@ differences in the API for which bindings are being generated will also affect t
169169
170170Platform-specific differences:
171171
172- For the most part, these behaviors are expected, but potentially unwanted behaviors considering the goal of Silk is to
173- provide cross-platform bindings.
172+ For the most part, these behaviors are expected, but potentially unwanted behaviors considering the goal of Silk.NET is
173+ to provide cross-platform bindings.
174174
175175- ` uint64_t ` in C becomes ` ulong ` on Windows, ` nuint ` on Linux. This is filed as an issue in the ClangSharp repo:
176- https://github.com/dotnet/ClangSharp/issues/574 . Silk handles this by remapping the ` stdint.h ` types in
176+ https://github.com/dotnet/ClangSharp/issues/574 . Silk.NET handles this by remapping the ` stdint.h ` types in
177177 [ remap-stdint.rsp] ( https://github.com/dotnet/Silk.NET/blob/develop/3.0/eng/silktouch/remap-stdint.rsp ) . APIs, such as
178178 OpenGL, that define their own integer types may require additional configuration.
179179
180- - Enums use ` uint ` as their backing type on Linux instead of ` int ` like on Windows. Silk handles this by using
180+ - Enums use ` uint ` as their backing type on Linux instead of ` int ` like on Windows. Silk.NET handles this by using
181181 ` TransformEnums ` to "coerce" the backing types to their Windows equivalents when possible.
182182
183- - C ` long ` is output as C# ` long ` on Windows and C# ` nint ` on Linux. Silk handles this by generating bindings on Windows
184- where possible.
183+ - C ` long ` is output as C# ` long ` on Windows and C# ` nint ` on Linux. Silk.NET handles this by generating bindings on
184+ Windows where possible.
185185
186186Note: There may be other differences not yet documented here. In the case new differences are discovered, please
187187update this section. API-specific differences should not be documented here and should be documented in the
188188[ API-Specific Notes] ( api-specific-notes.md ) document.
189189
190- To further avoid platform-specific differences, Silk prefers to generate its bindings on Windows. However, for sake of
191- development and iteration , the generator is typically set up so that platform-specific differences are minimalized.
190+ To further avoid platform-specific differences, Silk.NET prefers to generate its bindings on Windows. However, for
191+ consistency , the configuration Silk.NET itself uses is set up so platform-specific differences are minimalized.
192192
193193Usage recommendations:
194194
@@ -371,11 +371,11 @@ notably relating to how existing name affixes are treated in the
371371
372372Name affix categories:
373373
374- - ` SharedPrefix ` - This is a prefix that represents the shared prefix that is identified for a group of names. Silk's
375- bindings typically remove this prefix because these prefixes are typically used to prevent naming collisions in C
376- libraries. C# has its own namespacing functionality, thus making this prefix irrelevant. This prefix can be kept or
377- prettified if preferred over removing the prefix. The prefix can also be configured as a discriminator, which removes
378- the prefix by default, but allows the prefix to be used in case of name conflicts.
374+ - ` SharedPrefix ` - This is a prefix that represents the shared prefix that is identified for a group of names.
375+ Silk.NET's bindings typically remove this prefix because these prefixes are typically used to prevent naming
376+ collisions in C libraries. C# has its own namespacing functionality, thus making this prefix irrelevant. This prefix
377+ can be kept or prettified if preferred over removing the prefix. The prefix can also be configured as a discriminator,
378+ which removes the prefix by default, but preserves the prefix in the case of name conflicts.
379379
380380Example name affix configurations for ` PrettifyNames ` :
381381
@@ -467,8 +467,8 @@ This is a monolithic mod that handles behavior specific to Khronos-style APIs su
467467
468468Because this mod is intended more for internal use rather than public use, the documentation here will focus on
469469decisions made during the development of the mod and other internal details rather than the exact usage of the mod.
470- For information relating to how the mod should be used, please use Silk's own configuration, source code, and
471- ` MixKhronosDataTests ` as a reference .
470+ For information relating to how the mod should be used, please refer to Silk.NET 's own configuration, source code, and
471+ ` MixKhronosDataTests ` .
472472
473473(TODO: Document major decisions relating to ` MixKhronosData ` . This is difficult because of the mod's long development
474474history, and while this section is already massive, it still does not cover everything the mod does. This should be done
@@ -504,14 +504,14 @@ Khronos-style XML specifications:
504504- OpenXR: https://raw.githubusercontent.com/KhronosGroup/OpenXR-SDK/main/specification/registry/xr.xml
505505- Vulkan: https://raw.githubusercontent.com/KhronosGroup/Vulkan-Docs/main/xml/vk.xml
506506
507- Be aware that these link to the latest version. Silk's repo may be using an older version of these XML files.
507+ Be aware that these link to the latest version. Silk.NET 's repository may be using an older version of these XML files.
508508
509509Name affix categories:
510510
511511- ` KhronosFunctionDataType ` - ` IdentifyFunctionDataTypes ` must be set to true in the ` MixKhronosData ` configuration for
512512 this affix category to be identified. This is a suffix relevant to OpenGL-like APIs where functions like ` glColor3 `
513513 have variants such as ` glColor3i ` , ` glColor3f ` , and ` glColor3b ` . These suffixes indicate the data type that the
514- function expects. In this case, integer, float, and byte, respectively. Silk's bindings configure these as
514+ function expects. In this case, integer, float, and byte, respectively. Silk.NET 's bindings configure these as
515515 discriminators so that they can be removed when removing them does not lead to method overload conflicts.
516516
517517- ` KhronosHandleType ` - This is a suffix used on handle structs resulting from the typedefs used by Khronos in their
@@ -527,14 +527,14 @@ Name affix categories:
527527 enum member is usually defined as a standalone, global constant without any other context whether the enum member is
528528 part of an extension. In C#, this is not a problem because the enum type itself conveys that information. For example,
529529 in Vulkan, ` VkPresentModeKHR ` in Vulkan is a ` KHR ` suffixed enum type that contains ` VK_PRESENT_MODE_IMMEDIATE_KHR ` as
530- a member. In C#, this ` KHR ` suffix on the member is redundant. As such, Silk's bindings are configured to remove this
531- suffix.
530+ a member. In C#, this ` KHR ` suffix on the member is redundant. As such, Silk.NET 's bindings are configured to remove
531+ this suffix.
532532
533533- ` KhronosNamespaceEnum ` - This is a prefix added to the "namespace" enum of OpenGL-like APIs such as ` GLEnum ` ,
534534 ` ALEnum ` , and ` ALCEnum ` . In this case, the value of the prefix would be ` GL ` , ` AL ` , and ` ALC ` , respectively. This is
535- so that the casing of the prefix is preserved by ` PrettifyNames ` . As such, Silk's bindings leaves the affix category
536- unconfigured in the ` PrettifyNames ` configuration so that ` PrettifyNames ` uses the default behavior of preserving the
537- affix.
535+ so that the casing of the prefix is preserved by ` PrettifyNames ` . As such, Silk.NET 's bindings leaves the affix
536+ category unconfigured in the ` PrettifyNames ` configuration so that ` PrettifyNames ` uses the default behavior of
537+ preserving the affix.
538538
539539- ` KhronosNonExclusiveVendor ` - ` IdentifyEnumTypeNonExclusiveVendors ` must be set to true in the ` MixKhronosData `
540540 configuration for this affix category to be identified. This is a suffix used on enum types instead of ` KhronosVendor `
@@ -546,7 +546,7 @@ Name affix categories:
546546 This affix category is only intended to be used for OpenGL-like APIs where enum member promotion was not
547547 fully defined, leading to inconsistent vendor suffixing where a non-promoted enum type contains a promoted enum
548548 member. Modern APIs like Vulkan do not have this issue. In modern APIs, there can be "mismatches", but those are cases
549- where promoted enum types contain non-promoted enum members, which is allowed. As such, Silk's bindings enables
549+ where promoted enum types contain non-promoted enum members, which is allowed. As such, Silk.NET 's bindings enables
550550 ` IdentifyEnumTypeNonExclusiveVendors ` and configures ` KhronosNonExclusiveVendor ` affixes to be removed only for
551551 OpenGL-like APIs.
552552
@@ -564,13 +564,13 @@ Name affix categories:
564564 identification of other suffixes. For example, OpenAL has names such as ` alAuxiliaryEffectSlotfDirect ` where the
565565 ` Direct ` suffix is after the ` KhronosFunctionDataType ` suffix, thus blocking the ` KhronosFunctionDataType ` suffix
566566 from being identified. In this case, adding ` Direct ` as a non-vendor suffix fixes the issue. Because this is a
567- "helper" affix, Silk's bindings leave this affix category unconfigured in the ` PrettifyNames ` configuration.
567+ "helper" affix, Silk.NET 's bindings leave this affix category unconfigured in the ` PrettifyNames ` configuration.
568568
569569- ` KhronosVendor ` - This is a suffix added to any identifier that is identified to contain a Khronos vendor suffix such
570570 as ` KHR ` , ` EXT ` , or ` NV ` . The list of vendor suffixes used during identification is retrieved from the provided XML
571- specification. Silk's bindings are configured to move ` KhronosVendor ` suffixes to the end of the name. This is to
572- match Khronos's own naming convention. This primarily affects cases where Silk's generator added additional suffixes
573- to the end of the name, such as with ` HandleType ` suffixes like in ` DebugUtilsMessengerHandleEXT ` in Vulkan.
571+ specification. Silk.NET 's bindings are configured to move ` KhronosVendor ` suffixes to the end of the name. This is to
572+ match Khronos's own naming convention. This primarily affects cases where Silk.NET 's generator adds additional
573+ suffixes to the end of the name, such as with ` HandleType ` suffixes like in ` DebugUtilsMessengerHandleEXT ` in Vulkan.
574574
575575Usage recommendations:
576576
@@ -580,10 +580,10 @@ the XML specification file, `MixKhronosData` has not been tested for use without
580580One key consideration when using ` MixKhronosData ` is identifying the conventions used by the API for which bindings are
581581being generated for. Older Khronos APIs are more similar to OpenGL while newer Khronos APIs are more similar to Vulkan.
582582These conventions determine which settings should be used in the ` MixKhronosData ` configuration. For exact configuration
583- details, please refer to the configurations used by Silk for the existing Khronos-style bindings as well as the source
584- code.
583+ details, please refer to the configurations used by Silk.NET for the existing Khronos-style bindings as well as the
584+ source code.
585585
586- Note: Although ` MixKhronosData ` has not been used by Silk for generating bindings for APIs that do not have XML
586+ Note: Although ` MixKhronosData ` has not been used by Silk.NET for generating bindings for APIs that do not have XML
587587specifications, we will likely experiment with using this mod for bindings that do not have XML specifications such as
588588SPIRV-Reflect in the near future. Whether we end up using this mod for these types of bindings depends on how much
589589benefit ` MixKhronosData ` provides for those bindings.
@@ -627,7 +627,7 @@ Usage recommendations:
627627This mod is intended to be used as a way to clean up intermediate metadata attributes and other attributes usually
628628useful during bindings generation or debugging, but not particularly useful to the end user of the generated bindings.
629629
630- These are attributes removed in Silk's own bindings:
630+ These are attributes removed in Silk.NET 's own bindings:
631631
632632- ` NameAffix ` - Metadata attribute used to store name affix information. Introduced by various mods.
633633
@@ -674,7 +674,8 @@ This mod focuses on the transformation of methods, such as by changing parameter
674674
675675(TODO: To be expanded)
676676
677- Notably, the transformations include transforming methods to use the Silk DSL types (` Ptr ` , ` Ref ` , ` MaybeBool ` , etc).
677+ Notably, the transformations include transforming methods to use the Silk.NET DSL types (` Ptr ` , ` Ref ` , ` MaybeBool ` ,
678+ etc).
678679
679680Name affix categories:
680681
0 commit comments