Skip to content

Proposal/vulkan struct chaining #676

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
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ea222f8
feat: Initial working sample
thargy Nov 4, 2021
7863b1d
feat: Now supports limiting allowed structs.
thargy Nov 4, 2021
babe08f
docs: Added Readme.md
thargy Nov 4, 2021
58865bf
fix: Change __makeref to Unsafe.AsPointer
thargy Nov 4, 2021
73763e6
chore: Retargeting
thargy Nov 5, 2021
81cc29c
refactor: Various changes
thargy Nov 5, 2021
aea15c9
chore: Updated readme.md
thargy Nov 5, 2021
eca1dd2
feat: Added ManagedChain
thargy Nov 5, 2021
389c1f9
feat: Added static `ManagedChain.Create` example
thargy Nov 5, 2021
e7f047d
feat: ManagedChain uses a single memory block.
thargy Nov 5, 2021
ff031f6
feat: Added T4 template.
thargy Nov 5, 2021
dd2c1a8
feat: Added `ManagedChain.Append`
thargy Nov 5, 2021
ea96e2a
feat: Loading of unmanaged chains
thargy Nov 5, 2021
ec40730
feat: Added `IReadOnlyList` support to `ManagedChain`
thargy Nov 6, 2021
5254b9d
feat: Added deconstructor to `ManageChain<...>`
thargy Nov 6, 2021
8d3f124
feat: Added static `ManagedChain.Load`
thargy Nov 6, 2021
80dac45
chore: Readme.md updated
thargy Nov 6, 2021
fe2baf7
Imported PrototypeStructChaining into src/Lab/Experiments from extern…
thargy Nov 6, 2021
e74c977
chore: Added Lab projects to Solution
thargy Nov 6, 2021
3cae5cc
chore: Fixed issues with previous commit
thargy Nov 6, 2021
ef57171
docs: Finished initial draft #1
thargy Nov 6, 2021
089f2e5
docs: Embedded code sample directly into Proposal #1
thargy Nov 6, 2021
d5552b6
docs: Updated the Unmanaged Chaining Proposal.
thargy Nov 7, 2021
bd9f0eb
chore: Minor fixes to lab
thargy Nov 7, 2021
1c8dbda
docs: Initial work on Managed Chaining Proposal.
thargy Nov 7, 2021
af6c5a8
docs: Finished draft proposal for Managed Chains
thargy Nov 7, 2021
75f0371
feat: Numerous enhancements to ManagedChains
thargy Nov 7, 2021
d1ced73
docs: Updated Chaining proposals to match new functionality.
thargy Nov 7, 2021
e07f72f
feat: Added chain metadata extensions.
thargy Nov 7, 2021
374d85e
docs: Added suggestion for specific chain interfaces
thargy Nov 9, 2021
866f2dc
docs: Updated to use `BaseInStructure`
thargy Nov 9, 2021
8152c47
docs: Updated the first two proposals
thargy Nov 10, 2021
a83156e
feat: Added `Any` functionality to `ManagedChain`
thargy Nov 11, 2021
aebe0d2
feat: Added `GetHashCode` implementation
thargy Nov 14, 2021
930a2fc
fix: Fixed GetHashCode
thargy Nov 15, 2021
640f745
Merge branch 'dotnet:main' into proposal/vulkan-struct-chaining
thargy Nov 21, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions Silk.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Silk.NET.NUKE", "build\nuke\Silk.NET.NUKE.csproj", "{B9A8D738-FE7D-4860-A446-4A03E3DDEB74}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Microsoft", "Microsoft", "{F2CF5D32-4B41-425E-B229-8FFC48F88063}"
ProjectSection(SolutionItems) = preProject
src\Microsoft\dxva.h = src\Microsoft\dxva.h
EndProjectSection
ProjectSection(SolutionItems) = preProject
src\Microsoft\dxva.h = src\Microsoft\dxva.h
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Silk.NET.Direct3D11", "src\Microsoft\Silk.NET.Direct3D11\Silk.NET.Direct3D11.csproj", "{F3B7A9D6-5B15-45E8-925B-20B5BBD33428}"
EndProject
Expand Down Expand Up @@ -474,6 +474,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.OpenXR.Extensions.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.OpenXR.Extensions.HTCX", "src\OpenXR\Extensions\Silk.NET.OpenXR.Extensions.HTCX\Silk.NET.OpenXR.Extensions.HTCX.csproj", "{782B6A7E-9F04-429A-9DCD-D7273AA3882E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PrototypeStructChaining", "PrototypeStructChaining", "{B15922CB-815C-4038-B635-EE2D8A8F700B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrototypeStructChaining", "src\Lab\Experiments\PrototypeStructChaining\PrototypeStructChaining\PrototypeStructChaining.csproj", "{EEFF37DA-E4F2-406E-AF97-8615BB7BC34C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrototypeStructChaining.Test", "src\Lab\Experiments\PrototypeStructChaining\PrototypeStructChaining.Test\PrototypeStructChaining.Test.csproj", "{BD19250B-E143-4F4E-9E1D-18829CCB3642}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -2823,6 +2829,30 @@ Global
{782B6A7E-9F04-429A-9DCD-D7273AA3882E}.Release|x64.Build.0 = Release|Any CPU
{782B6A7E-9F04-429A-9DCD-D7273AA3882E}.Release|x86.ActiveCfg = Release|Any CPU
{782B6A7E-9F04-429A-9DCD-D7273AA3882E}.Release|x86.Build.0 = Release|Any CPU
{EEFF37DA-E4F2-406E-AF97-8615BB7BC34C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EEFF37DA-E4F2-406E-AF97-8615BB7BC34C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EEFF37DA-E4F2-406E-AF97-8615BB7BC34C}.Debug|x64.ActiveCfg = Debug|Any CPU
{EEFF37DA-E4F2-406E-AF97-8615BB7BC34C}.Debug|x64.Build.0 = Debug|Any CPU
{EEFF37DA-E4F2-406E-AF97-8615BB7BC34C}.Debug|x86.ActiveCfg = Debug|Any CPU
{EEFF37DA-E4F2-406E-AF97-8615BB7BC34C}.Debug|x86.Build.0 = Debug|Any CPU
{EEFF37DA-E4F2-406E-AF97-8615BB7BC34C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EEFF37DA-E4F2-406E-AF97-8615BB7BC34C}.Release|Any CPU.Build.0 = Release|Any CPU
{EEFF37DA-E4F2-406E-AF97-8615BB7BC34C}.Release|x64.ActiveCfg = Release|Any CPU
{EEFF37DA-E4F2-406E-AF97-8615BB7BC34C}.Release|x64.Build.0 = Release|Any CPU
{EEFF37DA-E4F2-406E-AF97-8615BB7BC34C}.Release|x86.ActiveCfg = Release|Any CPU
{EEFF37DA-E4F2-406E-AF97-8615BB7BC34C}.Release|x86.Build.0 = Release|Any CPU
{BD19250B-E143-4F4E-9E1D-18829CCB3642}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BD19250B-E143-4F4E-9E1D-18829CCB3642}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD19250B-E143-4F4E-9E1D-18829CCB3642}.Debug|x64.ActiveCfg = Debug|Any CPU
{BD19250B-E143-4F4E-9E1D-18829CCB3642}.Debug|x64.Build.0 = Debug|Any CPU
{BD19250B-E143-4F4E-9E1D-18829CCB3642}.Debug|x86.ActiveCfg = Debug|Any CPU
{BD19250B-E143-4F4E-9E1D-18829CCB3642}.Debug|x86.Build.0 = Debug|Any CPU
{BD19250B-E143-4F4E-9E1D-18829CCB3642}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BD19250B-E143-4F4E-9E1D-18829CCB3642}.Release|Any CPU.Build.0 = Release|Any CPU
{BD19250B-E143-4F4E-9E1D-18829CCB3642}.Release|x64.ActiveCfg = Release|Any CPU
{BD19250B-E143-4F4E-9E1D-18829CCB3642}.Release|x64.Build.0 = Release|Any CPU
{BD19250B-E143-4F4E-9E1D-18829CCB3642}.Release|x86.ActiveCfg = Release|Any CPU
{BD19250B-E143-4F4E-9E1D-18829CCB3642}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -3052,6 +3082,9 @@ Global
{3E30D674-9282-4297-AD1F-9B233A166308} = {0651C5EF-50AA-4598-8D9C-8F210ADD8490}
{606214B8-07FC-436F-9523-02AF32E1AB1E} = {90471225-AC23-424E-B62E-F6EC4C6ECAC0}
{782B6A7E-9F04-429A-9DCD-D7273AA3882E} = {90471225-AC23-424E-B62E-F6EC4C6ECAC0}
{B15922CB-815C-4038-B635-EE2D8A8F700B} = {39B598E9-44BA-4A61-A1BB-7C543734DBA6}
{EEFF37DA-E4F2-406E-AF97-8615BB7BC34C} = {B15922CB-815C-4038-B635-EE2D8A8F700B}
{BD19250B-E143-4F4E-9E1D-18829CCB3642} = {B15922CB-815C-4038-B635-EE2D8A8F700B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F5273D7F-3334-48DF-94E3-41AE6816CD4D}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Summary

This proposal is a minimal enhancement to [`Silk.Net.Vulkan`](../../src/Vulkan/Silk.NET.Vulkan) to mark all structures
that contain a `StructureType SType` field as implementing the interface `IStructuredType`.

This is a tiny pre-requisite for
[Proposal - Vulkan Struct Chaining - #2 Unmanaged Chaining.md](Proposal%20-%20Vulkan%20Struct%20Chaining%20-%20%232%20Unmanaged%20Chaining.md)
and is of limited value otherwise. Its primary purpose is to mark any structure that requires it's `SType` field to be
correctly set when passing to Vulkan, and to provide a mechanism for doing so.

A full implementation can be found [in Pull Request 680](https://github.com/dotnet/Silk.NET/pull/680).

# Contributors

- [Craig Dean, DevDecoder](https://github.com/thargy)

# Current Status

- [x] Proposed
- [ ] Discussed with API Review Board (ARB)
- [ ] Approved
- [x] Implemented

# Design Decisions

- The `IStructuredType` interface will usually not be implemented directly, instead `IChainable` (from
the [unmanaged chaining proposal](Proposal%20-%20Vulkan%20Struct%20Chaining%20-%20%232%20Unmanaged%20Chaining.md))
will extend this interface.
- Whenever the `IStructuredType` is added to an interface (either directly or indirectly) the
corresponding `StructureType()` method should also be explicitly
implemented ([see below](#istructuretype-implementation)).
- This proposed interface could easily be combined/merged with the `IChainable`
interface which [is proposed](Proposal%20-%20Vulkan%20Struct%20Chaining%20-%20%232%20Unmanaged%20Chaining.md) as an
extension. However, that interface marks a struct as having a second field `void* PNext`, as well as requiring
that `StructureType sType` field is in the first position, which is not required by this proposal (but is allowed).
Keeping the two concepts separate is good encapsulation and good for supporting future changes. The concept
that an `SType` must be correct is somewhat different to the concept of a chain (implied by `void* PNext`).
- To be clear, this proposal does not need to guarantee that the `SType` field is in position 0 (i.e. first),
that requirement is only necessary to implement the functionality
[proposed by the unmanaged chaining system](Proposal%20-%20Vulkan%20Struct%20Chaining%20-%20%232%20Unmanaged%20Chaining.md)
- Not all structures exposed by Vulkan have a default value for the `SType`, (e.g. `BaseOutStructure` and `BaseInStructure`),
where no default is available, the `StructureType()` method only returns the current value, rather than setting it.

# Implementation Notes

- BuildTools already contains enough information to determine whether the interface should be added to a structure, and
already knows which `StructureType` the structure should use.
- A working example of such a struct can
be [found in the labs.](../../src/Lab/Experiments/PrototypeStructChaining/PrototypeStructChaining/PhysicalDeviceFeatures2.cs)

# Proposed API

## StructureType structures

### IStructuredType

This proposal adds a single interface `IStructuredType`, the primary purpose of which is to mark any structure that
requires it's `SType` to be correctly set when passing to Vulkan. It adds a single
method `void IStructuredType.StructureType()`
which sets the `SType` correctly and returns it to the caller.

```csharp
namespace Silk.Net.Vulkan;

/// <summary>
/// Base interface for any struct that has a <see cref="StructureType"/> field called `SType`, that must be correctly
/// set when passing into the Vulkan API.
/// </summary>
public interface IStructuredType
{
/// <summary>
/// Gets the structured type's <see cref="Vulkan.StructureType"/> enum value.
/// </summary>
/// <remarks>
/// Retrieving the <see cref="Vulkan.StructureType"/> also ensures it is set to the correct value (if any).
/// </remarks>
StructureType StructureType();
}
```

### IStructureType implementation

Each struct generated that implements `IStructuredType` should also have the following code auto-generated, to
explicitly implement the interface. The method sets and returns the `SType` correctly (if any) for the current structure.

```csharp
/// <inheritdoc />
StructureType IStructuredType.StructureType()
{
return SType = StructureType.<INSERT CORRECT TYPE HERE>;
}
```
Loading