what in particular are you having

what in particular are you having trouble with? F# has ref T via byref<'T>, in T via inref<'T>, out T via outref<'T> you can declare pointers via nativeptr<'T> and for external functions in particular (DllImport) it directly supports T* and T& for pointers/byrefs
3 Replies
Unslinga
Unslinga5mo ago
I was having an issue with this in particular:
c#
private bool CheckValidationLayerSupport()
{
uint layerCount = 0;
vk!.EnumerateInstanceLayerProperties(ref layerCount, null);
var availableLayers = new LayerProperties[layerCount];
fixed (LayerProperties* availableLayersPtr = availableLayers)
{
vk!.EnumerateInstanceLayerProperties(ref layerCount, availableLayersPtr);
}

var availableLayerNames = availableLayers
.Select(layer => Marshal.PtrToStringAnsi((IntPtr)layer.LayerName))
.ToHashSet();

return validationLayers.All(availableLayerNames.Contains);
}
c#
private bool CheckValidationLayerSupport()
{
uint layerCount = 0;
vk!.EnumerateInstanceLayerProperties(ref layerCount, null);
var availableLayers = new LayerProperties[layerCount];
fixed (LayerProperties* availableLayersPtr = availableLayers)
{
vk!.EnumerateInstanceLayerProperties(ref layerCount, availableLayersPtr);
}

var availableLayerNames = availableLayers
.Select(layer => Marshal.PtrToStringAnsi((IntPtr)layer.LayerName))
.ToHashSet();

return validationLayers.All(availableLayerNames.Contains);
}
I cannot find any F# equivalent of var availableLayers = new LayerProperties[layerCount];, I only get let layers = LayerProperties layerCount which returns LayerProperties and not an array, as well as not being able to replicate
c#
fixed (LayerProperties* availableLayersPtr = availableLayers)
{
vk!.EnumerateInstanceLayerProperties(ref layerCount, availableLayersPtr);
}
c#
fixed (LayerProperties* availableLayersPtr = availableLayers)
{
vk!.EnumerateInstanceLayerProperties(ref layerCount, availableLayersPtr);
}
in any capacity
tannergooding
tannergooding5mo ago
you want let availableLayers = Array.zeroCreate layerCount pretty sure https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/arrays#create-arrays F# in general has a lot of the functionality either in patterns or via custom F# helper types https://github.com/tannergooding/fsharp-demoapp is an older demo-app I did that has some Win32 interop and does software rendering using hardware intrinsics, entirely in F#
Unslinga
Unslinga5mo ago
Oh man, I didn't even realize that was empty array! let mutable layers: LayerProperties[] = Array.zeroCreate <| int layerCount this works
https://discord.com/channels/521092042781229087/607634593201520651/1202199796719554561
Now I can put this idea to rest a little while longer
f#
do
use ptr = fixed layers
vk.EnumerateInstanceLayerProperties(&layerCount, ptr) |> ignore
f#
do
use ptr = fixed layers
vk.EnumerateInstanceLayerProperties(&layerCount, ptr) |> ignore