Skip to content

Platform: add D3D12 to modulemap #35221

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

Merged
merged 1 commit into from
Jan 5, 2021
Merged

Platform: add D3D12 to modulemap #35221

merged 1 commit into from
Jan 5, 2021

Conversation

compnerd
Copy link
Member

Add the DirectX 12 header to the modulemap for the Windows SDK.

Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.

Resolves SR-NNNN.

@compnerd
Copy link
Member Author

CC: @egorzhdan

@compnerd
Copy link
Member Author

@swift-ci please test

@compnerd
Copy link
Member Author

@swift-ci please test

@STREGAsGate
Copy link

Can we unlock these too? To make sure they are all compatible with the same version of Swift.

XInput XINPUT1_4.DLL
XAudio2 XAUDIO2_9.DLL

@compnerd
Copy link
Member Author

Sure, that seems reasonable; got a pointer to the docs for the covered API?

@STREGAsGate
Copy link

STREGAsGate commented Dec 29, 2020

Yup

D3d12 library info here
Xinput library info here.
XAudio2 library info here.
DXCore library info here

@stevapple
Copy link
Contributor

stevapple commented Dec 29, 2020

Discussion: Should we place this module at WinSDK.DirectX.Direct3D.V12, for a clearer classification and versioning?

@stevapple
Copy link
Contributor

stevapple commented Dec 29, 2020

Consideration: There’re many APIs in Windows which has many patches (for example, Direct2D), which can be “subversion”ed in the module map. Therefore, I propose to use such structure for Windows SDK:

module DirectX {
  module Direct3D {
    explicit module V12 {
      header "d3d12.h"
      export *

      link "d3d12.lib"
    }

    explicit module V11 {
      // ...
    }
  }

  module Direct2D {
    module V1 {
      header "d2d1.h"
      export *

      link "d2d1.lib"
    }

    explicit module V1_1 {
      header "d2d1_1.h"
      use V1

      export *
    }

    explicit module V1_2 {
      header "d2d1_2.h"
      use V1

      export *
    }
    // ...
  }
  // ...
}

Copy link
Contributor

@egorzhdan egorzhdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works well for me (SourceKit produces a valid generated Swift interface for this submodule), however, I would agree with @stevapple's suggestion on naming: MSDN lists this header under "Direct3D 12 Graphics", could this submodule be located under WinSDK.Direct3D or WinSDK.DirectX?

@compnerd
Copy link
Member Author

Yes, if we are adding the remainder of the DirectX APIs, it makes sense to organize them as @stevapple was pointing out. Although, I plan on only doing the minimum for the requested set. The organization of the modules has been somewhat ... difficult, at least in the past, so I tend to do the most minimal evolution of the module.

@stevapple
Copy link
Contributor

stevapple commented Dec 29, 2020

I think the bigger problem is about versioning the same API set (as for the case of Direct2D and many others). Direct3D 12 is newer so it doesn’t have such variety yet. Direct3D 11, for example, has extra headers ranging from d3d11_1.h to d3d11_4.h, which requires higher target versions. It’s really a question how we can prove both compatibility and functionality.

@compnerd
Copy link
Member Author

@stevapple you cannot - the user is responsible for handling the version compatibility checking. That is one of the problems with not having control over the platform. The best you can do is augment the information with APINotes.

@compnerd
Copy link
Member Author

compnerd commented Dec 29, 2020

To be a bit more clear, we already have the ability to have conditional versioning on Windows:

if #available(Windows 10.0.18362) {
  ...
} else {
  ...
}

I haven't made much use of the deployment target handling as of yet, but I don't see why that would not afford us the necessary support for the version checking. We can continue to bump the minimum supported SDK, but as long as the runtime can be backdeployed to 17763, I think that we are okay. The annotations would need to be per-API, but we could add availability information as an APINotes supplement to validate on deployment targets.

The reason for the 17763 support to continue is that it is a LTSC release with support until 1/9/2029, and was the first version that I had targeted (due to missing APIs for UWP support in the earlier releases needed to support Dispatch and backtracing). This allows us to continue to deploy to various targets - the current implementation was carefully considered in order to be able to support Windows desktop (laptops/tablets/desktops), XBox, HoloLens, and Windows Phone.

@compnerd
Copy link
Member Author

@STREGAsGate - I've added the DXCore bindings, but note that they are not usable. It requires the C++ interop to be functional, which is currently not fully working on Windows. There are problems with the modules (which is also why I prefer keeping the changes to the modules minimal) which prevent the C++ interop tests from even running on Windows with an updated environment. Once the module is well formed enough to allow the C++ interop to be used with a modern SDK, you should be able to use it with -enable-cxx-interop flag.

@compnerd
Copy link
Member Author

@swift-ci please test

@compnerd
Copy link
Member Author

@swift-ci please test Windows platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - d2b8462effe54c2c92a463a096cfd1a6509e7038

@STREGAsGate
Copy link

STREGAsGate commented Dec 29, 2020

Okay, we don't actually need DXCore. The functionality I would need is also found in DXGI so we could add that instead.

We do also need to add D3d12SDKLayers though, which is where all the debug and validation tools appear to be.

@stevapple
Copy link
Contributor

stevapple commented Dec 30, 2020

The best you can do is augment the information with APINotes.

I mean we may introduce such headers with explicit module and an API note. Then everything depends on the user itself. @compnerd

This is the best solution I’ve come up with. I don’t like the idea of bumping minimum target version either. Oppositely, we should lower the bound to use a Swift application.

@compnerd
Copy link
Member Author

I don't think that we need the explicit module, simply adding the APINotes for the interfaces should be sufficient. I think that we can assume, at least for the time being, anything at 17763 to always be available and annotate the newer interfaces? If so, if you want to create such an APINotes, I think that would be fine to add in.

@compnerd
Copy link
Member Author

@swift-ci please test Linux platform

@STREGAsGate
Copy link

Okay, we don't actually need DXCore. The functionality I would need is also found in DXGI so we could add that instead.

We do also need to add D3d12SDKLayers though, which is where all the debug and validation tools appear to be.

Sry I edited my comment instead of posting again.
We can ditch DXCore and use DXGI which is older and shouldn't need build flags or API notes.
Also will need SDKLayers to be added. And I think that's it I think 🤞

@compnerd
Copy link
Member Author

Sorry for the silly request, while I could try to fish out the docs, I want to make sure that I get the correct header. Would you mind sharing a pointer to MSDN for the API surface so I can cross-check and validate the module setup?

@STREGAsGate
Copy link

No prob. I think these are what you want.
DXGI and D3d12/D3d12SDKLayers

@compnerd
Copy link
Member Author

compnerd commented Jan 1, 2021

It seems that we should be okay with additional link directives to pick up the import libraries. The dxd312.h includes d3d12sdklayers.h and d3d12sdklayers.h will include dxgi.h. The problem with the explicit include is that dxgi.h is a shared header, and the module map is in the um path, which makes it slight more challenging to get it explicitly handled.

Add the module definitions for:
- Direct3D v12
- XAudio 2.9
- XInput 1.4

Additionally, add the following, unusable modules:
- DXCore

DXCore requires C++ Support (C++11 or newer to be precise) and is not
yet available until C++ interop can be made to work fully.
@compnerd
Copy link
Member Author

compnerd commented Jan 1, 2021

@swift-ci please test

@compnerd
Copy link
Member Author

compnerd commented Jan 4, 2021

@swift-ci please smoke test macOS platform

@compnerd
Copy link
Member Author

compnerd commented Jan 4, 2021

@swift-ci please test Windows platform

@compnerd compnerd merged commit f2adeda into swiftlang:main Jan 5, 2021
@compnerd compnerd deleted the d12 branch January 5, 2021 03:00
@drodriguez
Copy link
Contributor

Does this need any change in the VS2017 CI machines? Seems that at least xaudio2.h is not being parsed correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants