I am implementing the NVAPI GSync Module via Reflection in C#.
I got pretty far and beside 2 functions everything is working fine.
The two functions giving me problems are
NvAPI_GSync_GetTopology and
NvAPI_GSync_SetSyncStateSettings.
Both of them give me an Incompatible_Struct_Version error.
After reading the documentation of the structs and the documentation
of the two functions a felt 1435345634 times I do not know what to do anymore.
The structs I am using look like this:
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct NvGsyncGpu
{
public uint version;
public NvPhysicalGpuHandle hPhysicalGpu;
public Nv_Gsync_Gpu_Topology_Connector connector;
public NvPhysicalGpuHandle hProxyPhysicalGpu;
public uint isSynced;
public uint reserved;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct NvGsyncDisplay
{
public uint version;
public uint displayId;
public readonly uint isMasterable;
public uint[] reserved;
public Nv_Gsync_Display_Sync_State syncState;
}
The Enumerations used in this structs are defined like this
public enum Nv_Gsync_Gpu_Topology_Connector
{
NVAPI_GSYNC_GPU_TOPOLOGY_CONNECTOR_NONE = 0,
NVAPI_GSYNC_GPU_TOPOLOGY_CONNECTOR_PRIMARY = 1,
NVAPI_GSYNC_GPU_TOPOLOGY_CONNECTOR_SECONDARY = 2,
NVAPI_GSYNC_GPU_TOPOLOGY_CONNECTOR_TERTIARY = 3,
NVAPI_GSYNC_GPU_TOPOLOGY_CONNECTOR_QUARTERNARY = 4
};
The struct used in this structs is defined like this
[StructLayout(LayoutKind.Sequential)]
public struct NvPhysicalGpuHandle
{
public readonly IntPtr ptr;
}
I calculate the version like this:
public static readonly uint GSYNC_GPU_VER = (uint)Marshal.SizeOf(typeof(NvGsyncGpu)) | 0x10000;
public static readonly uint GSYNC_DISPLAY_VER = (uint)Marshal.SizeOf(typeof(NvGsyncDisplay)) | 0x10000;
And finally call the functions like this:
public NvStatus NvNETAPI_GSync_GetTopology(NvGsyncDeviceHandle gsyncHandle, out uint gsyncGpuCount, out NvGsyncGpu gsyncGpus, out uint gsyncDisplayCount, out NvGsyncDisplay gsyncDisplays)
{
NvStatus status;
uint gGPUCount = 0;
uint gDisplayCount = 0;
if (NvAPI_GSync_GetTopology != null)
{
status = NvAPI_GSync_GetTopology1(gsyncHandle, ref gGPUCount, null, ref gDisplayCount, null); //this one gives Status=OK
if (status == NvStatus.OK )
{
NvGsyncGpu[] gGpu = new NvGsyncGpu[gGPUCount]; //in test scenario gGPUCount always 1
gGpu[0].version = GSYNC_GPU_VER;
NvGsyncDisplay[] gDisplay = new NvGsyncDisplay[gDisplayCount]; //in test scenario gDisplayCount always 1
gDisplay[0].version = GSYNC_DISPLAY_VER;
status = NvAPI_GSync_GetTopology(gsyncHandle, ref gGPUCount, ref gGpu, ref gDisplayCount, ref gDisplay); //this one gives Incompatible Struct Version
gsyncDisplayCount = gDisplayCount;
gsyncGpuCount = gGPUCount;
gsyncGpus = null;
gsyncDisplays = null;
}
else
{
gsyncDisplayCount = gDisplayCount;
gsyncGpuCount = gGPUCount;
gsyncGpus = null;
gsyncDisplays = null;
}
}
else
{
gsyncDisplayCount = 0;
gsyncGpuCount = 0;
gsyncGpus = null;
gsyncDisplays = null;
status = NvStatus.FUNCTION_NOT_FOUND;
}
return status;
}
public NvStatus NvNETAPI_GSync_SetSyncStateSettings(uint gsyncDisplayCount, NvGsyncDisplay gsyncDisplays, uint flags)
{
NvStatus status;
if (NvAPI_GSync_SetSyncStateSettings != null)
{
status = NvAPI_GSync_SetSyncStateSettings(gsyncDisplayCount, gsyncDisplays, flags);
if (status == NvStatus.OK)
{
}
else
{
}
}
else
{
status = NvStatus.FUNCTION_NOT_FOUND;
}
return status;
}
What is wrong with this :-( i do not see where I am messing this up…please give me a hint