Skip to content

Commit 17c6068

Browse files
committed
[GLFW] Explicitly set address of vkGetInstanceProcAddr
1 parent e7b86bd commit 17c6068

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/Application/Aardvark.Application.Slim.GL/Application.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ module private OpenGL =
419419
getCurrentContextDelegate <- null
420420

421421
{ new IWindowInterop with
422+
override _.Init(glfw) = ()
422423
override _.Boot(_, glfw) =
423424
initVersion glfw
424425
install glfw

src/Application/Aardvark.Application.Slim.Vulkan/Application.fs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,23 @@ open System.Runtime.InteropServices
1414

1515
#nowarn "9"
1616

17-
module private Vulkan =
17+
module internal Vulkan =
18+
19+
[<AutoOpen>]
20+
module GlfwExtensions =
21+
type private InitVulkanLoaderDel = delegate of pVkGetInstanceProcAddr: nativeint -> unit
22+
let private initVulkanLoaderDict = System.Collections.Concurrent.ConcurrentDictionary<Glfw, InitVulkanLoaderDel>()
23+
24+
let private getInitVulkanLoaderDel (glfw : Glfw) =
25+
initVulkanLoaderDict.GetOrAdd(glfw, fun (glfw: Glfw) ->
26+
let m = glfw.Context.GetProcAddress "glfwInitVulkanLoader"
27+
Marshal.GetDelegateForFunctionPointer(m, typeof<InitVulkanLoaderDel>) |> unbox<InitVulkanLoaderDel>
28+
)
29+
30+
type Glfw with
31+
member this.InitVulkanLoader(pVkGetInstanceProcAddr: nativeint) =
32+
getInitVulkanLoaderDel(this).Invoke(pVkGetInstanceProcAddr)
33+
1834
let getSupportedSamples (runtime : Runtime) =
1935
let limits = runtime.Device.PhysicalDevice.Limits.Framebuffer
2036

@@ -87,6 +103,13 @@ module private Vulkan =
87103

88104
let interop =
89105
{ new IWindowInterop with
106+
override _.Init(glfw) =
107+
let pVkGetInstanceProcAddr = VulkanLoader.GetProcAddress("vkGetInstanceProcAddr")
108+
if pVkGetInstanceProcAddr = 0n then
109+
failwith "[GLFW] Failed to retrieve address of Vulkan function 'vkGetInstanceProcAddr'."
110+
111+
glfw.InitVulkanLoader(pVkGetInstanceProcAddr)
112+
90113
override _.Boot(runtime, glfw) =
91114
let runtime = unbox<Runtime> runtime
92115
let instance = runtime.Device.Instance

src/Application/Aardvark.Application.Slim/GLFW.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ type IWindowSurface =
586586

587587
type IWindowInterop =
588588
inherit IDisposable
589+
abstract Init : Glfw -> unit
589590
abstract Boot : IRuntime * Glfw -> unit
590591
abstract CreateSurface : IRuntime * WindowConfig * Glfw * nativeptr<WindowHandle> -> IWindowSurface
591592
abstract WindowHints : WindowConfig * Glfw -> unit
@@ -597,6 +598,8 @@ type Instance(runtime : Aardvark.Rendering.IRuntime, interop : IWindowInterop, h
597598

598599
let glfw = Glfw.GetApi()
599600
do
601+
interop.Init(glfw)
602+
600603
if hideCocoaMenuBar then
601604
Log.line "hiding cocoa menubar"
602605
glfw.InitHint(Silk.NET.GLFW.InitHint.CocoaMenubar, false) // glfwInitHint(GLFW_COCOA_MENUBAR, GLFW_FALSE);

0 commit comments

Comments
 (0)