Silk.Net.Vulkan API proposals #647
-
First, congratulate on the great work that you are doing! I have recently ported my Vulkan rendering engine to your library and it is working very well. But I have a few recommendations for the API: Flag enum value names are too long and contain the name of the enum. The "General" text is what is important for the user. But this is very hard to see because of the long prefix and suffix. The current name is also breaking code style rule CA1712 To prevent creating a breaking change by renaming the existing enum values, the generator could preserve the existing names and make them as obsolete. This would allow compiling the existing code with the new version of Silk.Net.Vulkan and allow developers to easily adapt to the new names. The structs in Silk.Net.Vulkan assembly provide an additional constructor with optional parameters. This allows the user to generate the struct by providing only some of the parameters. But the problem with this implementation is that all the parameters are nullable. For value types this requires boxing. For example the constructor for Extent3D is defined as:
When Extent3D is created by "new Extent3D(10, 10, 10)" the 3 int values are converted into 3 new objects that are passed to the constructor. Instead of using nullable types the same optional parameter functionality can be achieved by using default keyword. For example:
For number the default can be also replaced by 0. But the default keyword would be used for other more complex types like "void*", "Buffer", etc. (using "default(void*)", "default(Buffer)", etc.) What is more, improved constructors can be used to set the default value for the sType field. Many Vulkan structs that are used to create vulkan objects define the sType filed. The value of the sType field must match the type of the struct. In .Net it is not possible to fix the value of this field. But with using a special constructor it would be possible to set this field to the required value. For example:
For comparison, the current constructor has the following signature:
As written in the code comment above, the struct constructor could set the SType value and also set PNext to null. Most of the Vulkan objects are represented in .Net as structs with a ulong handle. This means we cannot check if the object is null (for example " buffer == null") but we need to check if the handle is zero ("buffer.Handle == 0"). Also, it is not possible to set the object to null, but we need to set handle to 0 ("buffer.Handle = 0;") or create a new object ("buffer = new Buffer();"). It would be nicer that the objects would provide an IsNull getter and a static Null getter. The implementation for Buffer object would look like:
This would allow some nicer code patterns, for example, when disposing an object that uses a buffer:
Provide a ToString override or add DebuggerDisplay attribute to Vulkan structs that define only a Vulkan handle. The ToString / DebuggerDisplay should display the object type and the value of the handle written as a hex value. When handle values are written as decimal numbers, they are just very bug values that do not provide any data to the user and cannot be compared with other handle values. But if handle values are written as hex values, then it is seen that the value has some structure and also the values can be much easier compared. What is more, the Vulkan validation errors always display the handle values as hex values and this way it would be possible to check which object (struct) in your application this refers to. Add None enum value (with value 0) to Flags enums. In C and C++ it is common to set enum field to 0. Therefore the enum values in vulkan.h do not provide names for zero values. Mostly out of curiosity, I am wondering what is the purpose of NativeName attributes that are set to all structs and all fields in the structs, for example:
Because there are many fields and structs in the Vulkan assemblies defining all those attributes actually takes a significant amount of bytes in the assembly. If this is used just for annotations, then it would be probably better to generate an XML documentation file instead. For example, the XML documentation file can be generated from:
Or you could even use "", for example:
This would reduce the size of assemblies and also show the native name in the IntelliSense. What do you think about those proposals? If you find them useful and if you can help me to get started with changing the code generator I can also try to provide a PR for those items. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
|
Beta Was this translation helpful? Give feedback.
-
Extra info given I'm the author of the bindings generator:
|
Beta Was this translation helpful? Give feedback.
IsNull
is ideal, I hoped that the language would eventually have some feature for us here (I'd really like to have a way to supportis null
, but it doesn't. I'm not opposed to having anIsZero
orIsNull
property, though I'm not too big of a fan either.vkSetDebugUtilsObjectNameEXT
0