Updated for openjdk-19-internal
[panamaz] / test-vulkan / template / VkDevice-part.java
1
2 // cleaner?
3 ResourceScope deviceScope = ResourceScope.newSharedScope();
4
5         static final MethodHandle vkAllocateCommandBuffers$FH = Memory.downcall(
6                 "vkAllocateCommandBuffers",
7                 FunctionDescriptor.of(
8                         Memory.INT,
9                         Memory.POINTER.withName("device"),
10                         Memory.POINTER.withName("pAllocateInfo"),
11                         Memory.POINTER.withName("pCommandBuffers")));
12         /**
13          * VkResult vkAllocateCommandBuffers ( VkDevice const VkCommandBufferAllocateInfo* VkCommandBuffer* )
14          * Success Codes: VK_SUCCESS
15          *   Error Codes: VK_ERROR_OUT_OF_HOST_MEMORY,VK_ERROR_OUT_OF_DEVICE_MEMORY
16          */
17         public Memory.HandleArray<VkCommandBuffer> vkAllocateCommandBuffers(VkCommandBufferAllocateInfo pAllocateInfo)throws Exception {
18                 int res$code;
19                 try {
20                         Memory.HandleArray<VkCommandBuffer> pCommandBuffers =
21                                 new Memory.HandleArray<>((addr)->new VkCommandBuffer(addr, instanceDispatch, deviceDispatch),
22                                         MemorySegment.allocateNative(pAllocateInfo.getCommandBufferCount() * Memory.POINTER.byteSize(), Memory.POINTER.bitAlignment(), deviceScope));
23
24                         res$code = (int)vkAllocateCommandBuffers$FH.invokeExact(
25                                 (Addressable)address(),
26                                 (Addressable)Memory.address(pAllocateInfo),
27                                 (Addressable)Memory.address(pCommandBuffers));
28                         if (res$code == VkResult.VK_SUCCESS) return pCommandBuffers;
29                 } catch (Throwable t) { throw new RuntimeException(t); }
30                 throw new Exception(String.format("failcode %d", res$code));
31         }
32
33         static final MethodHandle vkMapMemory$FH = Memory.downcall(
34                 "vkMapMemory",
35                 FunctionDescriptor.of(
36                         Memory.INT,
37                         Memory.POINTER.withName("device"),
38                         Memory.POINTER.withName("memory"),
39                         Memory.LONG.withName("offset"),
40                         Memory.LONG.withName("size"),
41                         Memory.INT.withName("flags"),
42                         Memory.POINTER.withName("ppData")));
43         /**
44          * VkResult vkMapMemory ( VkDevice VkDeviceMemory VkDeviceSize VkDeviceSize VkMemoryMapFlags void** )
45          * Success Codes: VK_SUCCESS
46          *   Error Codes: VK_ERROR_OUT_OF_HOST_MEMORY,VK_ERROR_OUT_OF_DEVICE_MEMORY,VK_ERROR_MEMORY_MAP_FAILED
47          */
48         public MemorySegment vkMapMemory(VkDeviceMemory memory, long offset, long size, int flags, ResourceScope scope)throws Exception {
49                 int res$code;
50                 try (Frame frame = Memory.createFrame()) {
51                         MemorySegment ppData = frame.allocatePointer();
52                         res$code = (int)vkMapMemory$FH.invokeExact(
53                                 (Addressable)address(),
54                                 (Addressable)Memory.address(memory),
55                                 (long)offset,
56                                 (long)size,
57                                 (int)flags,
58                                 (Addressable)Memory.address(ppData));
59                         if (res$code == VkResult.VK_SUCCESS) return MemorySegment.ofAddress(ppData.getAtIndex(Memory.POINTER, 0), size, scope);
60                 } catch (Throwable t) { throw new RuntimeException(t); }
61                 throw new Exception(String.format("failcode %d", res$code));
62         }