Silk.NET icon indicating copy to clipboard operation
Silk.NET copied to clipboard

ImGui DirectX11 Implementation

Open marcb152 opened this issue 11 months ago • 5 comments

Summary of the PR

This PR introduces initial support for ImGui with DirectX11 in Silk.NET. It includes:

Related issues, Discord discussions, or proposals

Current progress

  • [x] Working prototype in my own project see
  • [x] Create directory & project under /src/Lab/Experiments/ImGui_DX11/
  • [x] Create ImGui_Impl_DX11.cs (C++ port) and the associated ImGuiDX11Controller.cs
    • Not sure if I should keep those 2 files separated though? I am sticking to the original C++ file as DX11 code is a bit verbose and the controller would reach +1k lines very fast.
  • [x] Create another directory and a sample minimal project to demonstrate
  • [ ] Solve TODOs and clean up the code

Further Comments

The changes should not introduce any breaking API or behavioral changes: they will extend the functionality of Silk.NET.

Tested on

  • Silk.NET v2.22.0
  • ImGui.NET v1.91.6.1

Remarks

This is actually my first PR to such a large open-source repo. Any help, constructive criticism, remarks, suggestions, improvements and feedback are greatly appreciated!

marcb152 avatar Jan 09 '25 21:01 marcb152

@dotnet-policy-service agree

marcb152 avatar Jan 09 '25 22:01 marcb152

I have pushed my prototype code all in one. My apologize for the long files!

As a recap:

  • ImGuiDX11Controller.cs is mostly a copy paste from the existing OpenGL controller implementation, I replaced OpenGL calls by calls to ImGui_Impl_DX11.cs equivalent functions. Also assigned DirectX hwnd handle to ImGui (taken from imgui_impl_win32.cpp). Not a lot of changes there.
  • ImGui_Impl_DX11.cs is the full port of the original C++ and header (linked in the README.txt)
  • ImGuiFontConfig.cs imported from the OpenGL impl, no changes at all.
  • I created the .csproj file linking the necessary dependencies inside Silk.NET repo ⚠️never compiled yet!⚠️

marcb152 avatar Jan 09 '25 22:01 marcb152

No worries. Is this ready for review? (it's still marked as draft :P)

Perksey avatar Jan 12 '25 20:01 Perksey

Not yet, I've set aside my compilation issues and improved the code to support .NET 6.0 features (instead of the .NET 9.0 I created my prototype on). So, the code needs at least C# 12 to compile, I'll push that ASAP (probably beginning of next week) then it'll be ready for review!

I've also made a minimal sample that works which I'll push soon afterwards.

marcb152 avatar Jan 17 '25 13:01 marcb152

Hey, I think this PR is now ready for review (I provided a sample as well).

There are still work to do (tell me if you need comments/self-explanatory code anywhere, this won't bother me). Most TODOs are out of my knowledge, there's one to check out as it can cause issues later: https://github.com/dotnet/Silk.NET/pull/2409/files#diff-8c4147963edd0bf7166adef79bb3a37e316e17b1d610f2591590f81e6acd4ab9R593 It's the part where we revert back the state of the whole pipeline, I still don't understand how the bindings work with pointers to retrieve/restore arrays of viewports.

And sorry for the long wait also.

marcb152 avatar Feb 21 '25 21:02 marcb152