-
-
Notifications
You must be signed in to change notification settings - Fork 435
Feature/vulkan struct chaining/2 unmanaged chains #683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
thargy
wants to merge
49
commits into
dotnet:main
from
thargy:feature/vulkan-struct-chaining/2-unmanaged-chains
Closed
Feature/vulkan struct chaining/2 unmanaged chains #683
thargy
wants to merge
49
commits into
dotnet:main
from
thargy:feature/vulkan-struct-chaining/2-unmanaged-chains
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Created class library with 3 chainable structs * Added `IChainable` interface hierarchy * Added chaining methods `Chain`, `CreateNext`, `SetNext` and `End` * Added tests
* Added tests to check that invalid structs don't compile * Minimal additional code required per struct - just add an interface for each allowed `PNext` struct; and, - add a short static method `Chain` (technically optional), and a short instance method `SetNext`.
Retargeted project to ensure that it only targets the same includes, etc. as `Silk.Next.Core` and `Silk.Net.Vulkan`
* Added `IStructureType` for any struct that has a `StructureType SType` field. This is usually added automatically by one of the other interfaces; and allows the structure type to be automatically corrected and retrieved using the `StructureType IStructuredType.StructureType()` method. * Added `IChainStart` to indicate a type that can form the start of a chain. * `IChainable<...>` was replaced with `IExtendsChain<T>` which matches the Vulkan specification more readily. * The chaining methods now all accept, and return, a reference to an `IChainStart`, making it easier to scan a chain for existing items, and making use of the auto-generated `IExtendsChain<T>` to validate types at compile time. * `SetNext`, by default, will now replace existing chain entries if they match the supplied `SType`. This behaviour can be overriden with the optional `alwaysAdd` parameter. * `CreateNext` is now called `AddNext` to indicate it always adds to the end of a Chain.cs * `TryAddNext` added to only create a new structure if it is not already there. * `IndexOf` added to return the index of a structure in a chain. * Updated Readme.md.
Updated `Changes Required` section.
* ManagedChain holds structures in unmanaged memory, preventing their movement, and it can be safely held on the heap itself. * It allows for easy modification and manipulation of the chain.
`ManagedChain` now supports 2-16 chain items.
Can now easily append an item to an existing `ManagedChain` to efficiently create a new `ManagedChain`.
`ManagedChain` now has a constructor that will load an unmanaged chain allowing it to be safely stored on the heap.
Also improved loading to detect when the unmanaged chain is too long.
Also added the new blank proposals.
Proposal - Vulkan Struct Chaining - #1 StructureType correction.md
* Restored targets for PrototypeStructChaining.csproj to match `Silk.Net.Vulkan` targets. * Upped the generated `ManageChain<T...` to 16.
* IChainable now exposes `Chain* PNext` property. * Added `ManagedChain<TChain>` as smallest chain (just the head) * All `IntPtr`s are replaced with `nint`s. * Pointer offsets are calculated once per chain type and stored in statics, meaning that a chain contains a single `nint` field internally, making it incredibly lightweight. Getting the sizes once may also improve the performance, and has simplified the code. * Various fixes to ensure tail always has `PNext` set to `null` (0). * Added `Truncate` instance methods.
Also cleaned up some tests.
* Added the `Extensions`, `Extenders`, `ClrTypes` and `StructureTypes` dictionaries to `Chain`. * Added the `ClrType`, `StructureType`, `IsChainStart`, `IsChainable`, `CanExtend` and `CanBeExtendedBy` extension methods to `ChainExtensions`. * Finished Proposal dotnet#4 on Chaining Metadata extension.
* `Chain` was replaced by `BaseInStructure`, which is supplied by the Vulkan Specification already. * `ChainExtensions` was renamed to `Chain`.
Full implementation of [proposal 1](https://github.com/dotnet/Silk.NET/blob/866f2dcdcc7817995e9fb633213e7630d510ee35/documentation/proposals/Proposal%20-%20Vulkan%20Struct%20Chaining%20-%20%231%20StructureType%20correction.md). * Adds `$VKSTRUCTUREDTYPE` intrinsic to indicate that a struct implements `IStructuredType`, and includes the default `StructureType` * Adds `IStructuredType` interface to relevant structs, implementing them explicitly.
Full implementation of [Proposal 2] (https://github.com/dotnet/Silk.NET/blob/866f2dcdcc7817995e9fb633213e7630d510ee35/documentation/proposals/Proposal%20-%20Vulkan%20Struct%20Chaining%20-%20%232%20Unmanaged%20Chaining.md) * Added `IReadOnlyList<string> Extends` property to `StructureDefinition`, to store the `structextends` values. * Added `string Alias` property to `StructureDefinition`, to store the value of the `alias` attribute. * Added `Clone()` methods to `Struct` and `Attribute`, to make alias creation faster and easier. * `VulkanReader` creates aliases by cloning existing structs, making it slightly faster to build. This speed improvement is then used to handle the complex chaining logic which requires alias expansion, creating a net even performance. * Added `$VKCHAINABLE` intrinsic to indicate a structure is `IChainable` (a lower bar than a chain start or chain extension). * Added `$VKALIASOF` intrinsic to indicate a structure is an alias of another structure. * Added `$VKALIASES` intrinsic to indicate which structures are aliases of the current structure. * Added `$VKEXTENDSCHAIN` intrinsic to indicate which structures the current structure extends. * Added `$VKCHAINSTART` intrinsic to indicate which structures the current structure can be extended by. * `StructWriter` uses the intrinsics to annotate the structs. * Added `Chain` extensions from proposal. * Added `IChainable`, `IChainStart` and `IExtendsChain` interfaces from proposal. * `ProjectWriter` has `GetFilename` added, which will disambiguate filenames whenever case-sensitivity is an issue (hasn't actually occurred yet though). TODOs * Update `PrototypeStructChaining` projects to remove manually generated code and instead link directly to `Silk.NET.Vulkan` project. * Run tests to confirm functionality. * Update proposals with any changes (e.g. `IChainable.PNext`) * Consider what to do with teh 208 structures (out of 739) that implement `IChainable` directly (i.e. are not part of a specified chain). * Check in the changes to generated structs in a standalone commit.
This was referenced Nov 9, 2021
Commiting just the auto-generated files to not muddy other commits.
* Removed the manually generated code that is replaced by the auto-generated code now that it is implemented * Removed the solution. * Corrected namespace to `Silk.NET.Vulkan`. * Fixed issue clash of `System.Buffer` and `Silk.NET.Vulkan.Buffer`.
As ~30% of Vulkan Structures are purely `IChainable`, that is they are not included in one of the Vulkan Specification `structextends` chains, but do implement `SType` and `PNext` correctly, I have added `Any` versions of each of the unmanaged chain extension methods. These methods accept `IChainable` directly for the `chain` and `next` parameters, making them work with any `IChainable` structure. Indeed the stricter non-`Any` methods, call the looser `Any` methods directly and serve merely as more rigorous compile time checks. Improved the inline documentation of the extensions methods.
Added details about PRs and the new `Any` extension methods.
…ruct-chaining/1-istructuredtype
…feature/vulkan-struct-chaining/2-unmanaged-chains
* Removed instance methods and converted into static extension methods. * Added `Any` equivalents with looser constraints. * Various fixes to make prototype match more closely with current draft implementations, and `Silk.NET.Vulkan`. * Added tests. * Added efficient equality overloads. * Added ToString(). * Expose the `HeadPtr` and `Size` in the base class.
This is a proposed implementation that only checks the start of the payload. We may change this to check the full payload Also updated the proposals to match the new `Any` functionality.
…ruct-chaining/1-istructuredtype
…feature/vulkan-struct-chaining/2-unmanaged-chains # Conflicts: # src/Lab/Experiments/PrototypeStructChaining/PrototypeStructChaining.Test/TestChainsAny.cs # src/Lab/Experiments/PrototypeStructChaining/PrototypeStructChaining.Test/TestManagedChains.cs # src/Lab/Experiments/PrototypeStructChaining/PrototypeStructChaining/BaseInStructure.cs # src/Lab/Experiments/PrototypeStructChaining/PrototypeStructChaining/ChainExtensions.cs # src/Lab/Experiments/PrototypeStructChaining/PrototypeStructChaining/DeviceCreateInfo.cs # src/Lab/Experiments/PrototypeStructChaining/PrototypeStructChaining/IStructuredType.cs # src/Lab/Experiments/PrototypeStructChaining/PrototypeStructChaining/ManagedChain.gen.cs # src/Lab/Experiments/PrototypeStructChaining/PrototypeStructChaining/ManagedChain.gen.tt # src/Lab/Experiments/PrototypeStructChaining/PrototypeStructChaining/PhysicalDeviceAccelerationStructureFeaturesKhr.cs # src/Lab/Experiments/PrototypeStructChaining/PrototypeStructChaining/PhysicalDeviceDescriptorIndexingFeatures.cs # src/Lab/Experiments/PrototypeStructChaining/PrototypeStructChaining/PhysicalDeviceFeatures.cs # src/Lab/Experiments/PrototypeStructChaining/PrototypeStructChaining/PhysicalDeviceFeatures2.cs # src/Lab/Experiments/PrototypeStructChaining/PrototypeStructChaining/StructureType.cs
Fixed broken pointer arithmetic. Also changed to hash entire structure for better separation.
…ruct-chaining/1-istructuredtype
…feature/vulkan-struct-chaining/2-unmanaged-chains
Closing this PR, as included in #693. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary of the PR
Full implementation of Proposal 2
IReadOnlyList<string> Extends
property toStructureDefinition
, to store thestructextends
values.string Alias
property toStructureDefinition
, to store the value of thealias
attribute.Clone()
methods toStruct
andAttribute
, to make alias creation faster and easier.VulkanReader
creates aliases by cloning existing structs, making it slightly faster to build. This speed improvement is then used to handle the complex chaining logic which requires alias expansion, creating a net even performance.$VKCHAINABLE
intrinsic to indicate a structure isIChainable
(a lower bar than a chain start or chain extension).$VKALIASOF
intrinsic to indicate a structure is an alias of another structure.$VKALIASES
intrinsic to indicate which structures are aliases of the current structure.$VKEXTENDSCHAIN
intrinsic to indicate which structures the current structure extends.$VKCHAINSTART
intrinsic to indicate which structures the current structure can be extended by.StructWriter
uses the intrinsics to annotate the structs.Chain
extensions from the proposal.IChainable
,IChainStart
andIExtendsChain
interfaces from proposal.ProjectWriter
hasGetFilename
added, which will disambiguate filenames whenever case-sensitivity is an issue (hasn't actually occurred yet though).Related issues, Discord discussions, or proposals
Further Comments
This is currently functionally complete.
Lead Reviewer: @Perksey