SharpVk-Samples icon indicating copy to clipboard operation
SharpVk-Samples copied to clipboard

Switch samples to use GLFW

Open FacticiusVir opened this issue 8 years ago • 31 comments

Current sample projects use WinForms as the Surface host, which makes them dependent on Windows; GLFW is a cross-platform window library with explicit support for Vulkan Surfaces.

FacticiusVir avatar Nov 20 '16 04:11 FacticiusVir

@sunkin351 Could you try the Test Harness project in the GLFW branch to see if it runs on Linux? I've tested on Win32 and it works okay for me. It'll need a 32-bit compile of libglfw.so which I don't have; you can change the project to an x64 build config and it should still work, or update the dllmap tag in App.config if you need to point to a different file.

FacticiusVir avatar Nov 20 '16 04:11 FacticiusVir

I'm not sure what genius decided to name the vulkan library different on windows and linux, windows adds a "-1" to the end of the name before the file extension... which is irritating. Is there anything you can do about that at runtime?

Edit: Also, since C# gives the feature of using [DllImport("vulkan")], I would advise using that instead of the complete library name and let the runtime choose. I wonder if it will account for the "-1" in the windows name...

sunkin351 avatar Dec 05 '16 17:12 sunkin351

Mono supports DLL mapping - you can see an example here for my GLFW bindings: https://github.com/FacticiusVir/SharpVk/blob/Glfw/SharpVk/Test%20Harness/App.config I'll add one to the repo, but in the meantime you can fix it directly in the build output by adding a SharpVk.dll.config file in the same format as the link, drop the startup element and update the dllmap line to be: <dllmap os="linux" dll="vulkan-1.dll" target="vulkan.so"/> (I'm assuming the Linux library is called vulkan.so)

FacticiusVir avatar Dec 05 '16 17:12 FacticiusVir

libvulkan.so, but yea. I am changing a little code in the sample to match linux needs. (Xcb surface so far) Is it possible to compile once and have it run on multiple platform? (using dllmap and such?)

sunkin351 avatar Dec 05 '16 17:12 sunkin351

Btw, you wouldn't happen to know why vulkan is telling me I have two Graphics cards when I only have one, would you? (Nvidia GeForce GTX 750 Ti)

sunkin351 avatar Dec 05 '16 18:12 sunkin351

Is it the same name for both? If not, it might be picking up the on-chip GPU on some Intel CPUs.

FacticiusVir avatar Dec 05 '16 19:12 FacticiusVir

Its the same name, type, and ID. Plus my mb doesnt support onboard video.

sunkin351 avatar Dec 05 '16 20:12 sunkin351

Also, your sample has the same problem with CreateRenderPass().

sunkin351 avatar Dec 05 '16 21:12 sunkin351

Odd, not sure about the multiple physical devices; also, I'm reworking the marshalling/interop layer to fix the CreateRenderPass issue now, but it looks like a lot of the unmanaged memory code simply isn't Mono-compatible so it'll take me a little while. For the XCB Surface change in the sample, is that just to include the correct extension name? If so, I can easily update the sample to detect the current platform's surface extension and load that, so it'll work cross-platform.

FacticiusVir avatar Dec 06 '16 01:12 FacticiusVir

Its really funny, because that is the only function I have come across that creates a SigSegV. Everything else that isn't dependent on a render pass pretty much works from what I can tell. (Except for maybe all those warnings on device creation from the validation layers.)

sunkin351 avatar Dec 06 '16 15:12 sunkin351

I would hate to be a pest, but can you give me a timeframe to expect this done?

sunkin351 avatar Dec 09 '16 15:12 sunkin351

No worries, I've got some fixes in place that I'm testing, should have something to you this weekend.

FacticiusVir avatar Dec 09 '16 23:12 FacticiusVir

Its the weekend. :)

sunkin351 avatar Dec 11 '16 16:12 sunkin351

Its the very end of the weekend, what do you have?

sunkin351 avatar Dec 12 '16 01:12 sunkin351

Right, was having a nightmare reworking for PCL, so I've separated and tested the Mono fix on it's own, along with the NVX extension patches that appeared last week; I was able to replicate your original issue on Windows with Mono, and the latest commit to the GLFW branch seems to resolve it.

Note to self: if you're moving house of a weekend, remember to push your local git commits before the Internet is disconnected.

FacticiusVir avatar Dec 12 '16 15:12 FacticiusVir

What branch is this on btw?

sunkin351 avatar Dec 12 '16 21:12 sunkin351

Glfw (https://github.com/FacticiusVir/SharpVk/tree/Glfw)

FacticiusVir avatar Dec 12 '16 22:12 FacticiusVir

I am able to get past the part where it would previously crash at CreateRenderPass(). I will let you know if I encounter any more problems. Thank you for your hard work. Could this get merged into master where my projects can benefit?

sunkin351 avatar Dec 14 '16 02:12 sunkin351

Also, would you like to incorporate some glfw interop code in your library? It would definitely help.

sunkin351 avatar Dec 14 '16 02:12 sunkin351

WOW... The sample you made has a serious issue at least on Linux, I gave it free reign over my gpu and it lagged my entire system to hell, I almost couldn't move my mouse to close the window. I seemed to have solved this problem by using device.WaitIdle() just after the present call: presentQueue.Present() in Program.DrawFrame(). Otherwise, it runs well and no issues.

sunkin351 avatar Dec 14 '16 04:12 sunkin351

Interesting; possibly a different blocking behaviour on AcquireNextImage for Windows drivers, either way I'll add some additional synchronisation and get a merge up to master later, then flesh out the "proper" version.

FacticiusVir avatar Dec 14 '16 11:12 FacticiusVir

Could you please add something to the official repo to give me the status/return code of Device.WaitForFences()? It would be very helpful for future synchronization.

Edit: I also cant seem to figure out dllmap, could you provide an example? ~~Edit2: There is also a definite crash for me when trying to allocate command buffers. Will send you a debug report shortly.~~ Scratch that, completely my fault. :)

sunkin351 avatar Dec 18 '16 22:12 sunkin351

Which dllmap isn't working for you? There should be one included in the SharpVk.Glfw library already.

FacticiusVir avatar Dec 19 '16 11:12 FacticiusVir

I cant figure out how to create one for the SharpVk binding itself.

sunkin351 avatar Dec 20 '16 03:12 sunkin351

App.config in the SharpVk project:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <dllmap os="linux" dll="vulkan-1.dll" target="libvulkan.so"/>
</configuration>

FacticiusVir avatar Dec 21 '16 12:12 FacticiusVir

The dllmap configuration is now included in the master branch SharpVk project.

FacticiusVir avatar Dec 22 '16 01:12 FacticiusVir

Does the config have to be with the compiled assembly?

sunkin351 avatar Dec 23 '16 15:12 sunkin351

It should be compiled to SharpVk.dll.config, and that file should be in the folder with SharpVk.dll (along with SharpVk.Glfw.dll.config & Test Harness.exe.config)

FacticiusVir avatar Dec 23 '16 15:12 FacticiusVir

Note that a "compiled" config file will have the same contents as the un-compiled, it just renames the file.

FacticiusVir avatar Dec 23 '16 15:12 FacticiusVir

Monodevelop did not for me and I had to move & rename it manually...

sunkin351 avatar Dec 23 '16 21:12 sunkin351

That's bizarre, having done some googling it seems Mono doesn't process app.configs for you at all; I'll see if there's a way to make the project builds cross-compatible.

FacticiusVir avatar Dec 23 '16 21:12 FacticiusVir