Windows DXGI Experiment

Hugo De Vaan hdevaan76 at gmail.com
Wed Feb 26 18:18:07 UTC 2025


The signature was a bit off, I was under the impression I was working from
the C++ interface and so needed to add 'this' (the usual extra parameter
from C perspective), but I think I was already in C. Now that I'm using
jextract that's no longer a problem - the code is restructured to invoke
functions via the generated Vtbl classes, which is indeed much easier.

I've made some good progress. In addition to factory creation, I can now
enumerate the adapters and get a handle to the GetDesc1 function in
IDXGIAdapter1Vtbl. However, invoking that function somehow crashes the JVM,
so it seems some of my 2020-to-2025 FFM translations are wrong.

MemorySegment factory = IDXGIFactory1.reinterpret(
    fpointer.get(dxgi_h.C_POINTER, 0L), arena, null);

MemorySegment vtblFactory = IDXGIFactory1.lpVtbl(factory);

MemorySegment EnumAdapters1 =
    IDXGIFactory1Vtbl.EnumAdapters1(vtblFactory);

System.out.println("Handle to EnumAdapters1 created.");

MemorySegment adapterPtr = arena.allocate(dxgi_h.C_POINTER);

try {
    int adapterIndex = 0;
    int hresult = IDXGIFactory1Vtbl.EnumAdapters1.invoke(
        EnumAdapters1, factory, adapterIndex, adapterPtr);

    System.out.println(
        "Invocation result: " +
        HexFormat.of().toHexDigits(hresult));
} catch (Throwable t) {
    t.printStackTrace();
}

MemorySegment vtblAdapter = IDXGIAdapter1.lpVtbl(adapterPtr);

MemorySegment GetDescriptor1 = IDXGIAdapter1Vtbl.GetDesc1(vtblAdapter);
System.out.println("Handle to GetDescriptor1 created.");

MemorySegment adescPtr = DXGI_ADAPTER_DESC1.allocate(arena);

try {
    int hresult = IDXGIAdapter1Vtbl.GetDesc1.invoke(
        GetDescriptor1, adapterPtr, adescPtr);

    System.out.println(
        "Invocation result: " +
        HexFormat.of().toHexDigits(hresult));
} catch (Throwable t) {
    t.printStackTrace();
}

Hugo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20250226/9f4487c2/attachment-0001.htm>


More information about the panama-dev mailing list