Updated for openjdk-19-internal
[panamaz] / test-vulkan / template / VkInstance-part.java
1
2 // cleaner?
3 ResourceScope instanceScope = ResourceScope.newSharedScope();
4
5         static final MethodHandle vkEnumeratePhysicalDevices$FH = Memory.downcall(
6                 "vkEnumeratePhysicalDevices",
7                 FunctionDescriptor.of(
8                         Memory.INT,
9                         Memory.POINTER.withName("instance"),
10                         Memory.POINTER.withName("pPhysicalDeviceCount"),
11                         Memory.POINTER.withName("pPhysicalDevices")));
12         /**
13          * VkResult vkEnumeratePhysicalDevices ( VkInstance uint32_t* VkPhysicalDevice* )
14          */
15         public Memory.HandleArray<VkPhysicalDevice> vkEnumeratePhysicalDevices()throws Exception {
16                 int res$code;
17                 try (Frame frame = Memory.createFrame()) {
18                         MemorySegment count = frame.allocateInt();
19
20                         res$code = (int)vkEnumeratePhysicalDevices$FH.invokeExact(
21                                 (Addressable)address(),
22                                 (Addressable)count.address(),
23                                 (Addressable)MemoryAddress.NULL);
24
25                         if (res$code == VkResult.VK_SUCCESS) {
26                                 Memory.HandleArray<VkPhysicalDevice> devices =
27                                         new Memory.HandleArray<>((addr)->new VkPhysicalDevice(addr, instanceDispatch),
28                                                 MemorySegment.allocateNative(count.get(Memory.INT, 0) * Memory.POINTER.byteSize(), Memory.POINTER.bitAlignment(), instanceScope));
29
30                                 res$code = (int)vkEnumeratePhysicalDevices$FH.invokeExact(
31                                         (Addressable)address(),
32                                         (Addressable)count.address(),
33                                         (Addressable)devices.address());
34
35                                 if (res$code == VkResult.VK_SUCCESS)
36                                         return devices;
37                         }
38                 } catch (Throwable t) { throw new RuntimeException(t); }
39                 throw new Exception(String.format("failcode %d", res$code));
40         }
41
42         static final MethodHandle vkEnumeratePhysicalDeviceGroups$FH = Memory.downcall(
43                 "vkEnumeratePhysicalDeviceGroups",
44                 FunctionDescriptor.of(
45                         Memory.INT,
46                         Memory.POINTER.withName("instance"),
47                         Memory.POINTER.withName("pPhysicalDeviceGroupCount"),
48                         Memory.POINTER.withName("pPhysicalDeviceGroupProperties")));
49         /**
50          * VkResult vkEnumeratePhysicalDeviceGroups ( VkInstance uint32_t* VkPhysicalDeviceGroupProperties* )
51          */
52         public VkPhysicalDeviceGroupProperties vkEnumeratePhysicalDeviceGroups() throws Exception {
53                 int res$code;
54                 try (Frame frame = Memory.createFrame()) {
55                         MemorySegment count = frame.allocateInt();
56
57                         res$code = (int)vkEnumeratePhysicalDeviceGroups$FH.invokeExact(
58                                 (Addressable)address(),
59                                 (Addressable)count.address(),
60                                 (Addressable)MemoryAddress.NULL);
61
62                         if (res$code == VkResult.VK_SUCCESS) {
63                                 VkPhysicalDeviceGroupProperties properties =
64                                         new VkPhysicalDeviceGroupProperties(
65                                                 MemorySegment.allocateNative(count.get(Memory.INT, 0) * VkPhysicalDeviceGroupProperties.LAYOUT.byteSize(), 64, instanceScope),
66                                                 instanceDispatch);
67
68                                 res$code = (int)vkEnumeratePhysicalDeviceGroups$FH.invokeExact(
69                                         (Addressable)address(),
70                                         (Addressable)count.address(),
71                                         (Addressable)properties.address());
72
73                                 if (res$code == VkResult.VK_SUCCESS)
74                                         return properties;
75                         }
76
77                 } catch (Throwable t) { throw new RuntimeException(t); }
78                 throw new Exception(String.format("failcode %d", res$code));
79         }