From 11072506008d8f2c857e0574bdc05ef040e95cde Mon Sep 17 00:00:00 2001 From: Not Zed Date: Sun, 8 May 2022 12:17:16 +0930 Subject: [PATCH] Added facility for expanding inline simple types in constructors. Added set-all facilitiy. Moved segmentallocator to end of argument list. --- Makefile | 4 +- .../classes/au/notzed/display/Window.java | 5 +- .../classes/vulkan/test/TestCube.java | 260 +++++++++-------- .../classes/vulkan/test/TestMandelbrot.java | 95 ++++--- .../classes/vulkan/test/TestSDF.java | 261 ++++++++++-------- src/notzed.vulkan/gen/generate-vulkan | 42 ++- src/notzed.vulkan/gen/struct-types.api | 169 +++++++++++- src/notzed.vulkan/gen/vulkan.pm | 3 - 8 files changed, 544 insertions(+), 295 deletions(-) diff --git a/Makefile b/Makefile index 5cee474..adae980 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ notzed.vulkan_JDEPMOD = notzed.nativez notzed.xlib notzed.xcb notzed.vulkan.test_JDEPMOD = notzed.vulkan notzed.xcb_JDEPMOD = notzed.nativez notzed.xlib_JDEPMOD = notzed.nativez -notzed.display_JDEPMOD = notzed.xlib notzed.xcb +notzed.display_JDEPMOD = notzed.xlib notzed.xcb notzed.vulkan notzed.apistatic_JMAIN = api.test.TestAPI notzed.apiobject_JMAIN = api.test.TestAPI @@ -35,7 +35,7 @@ notzed.ffmpeg_JMAIN = ffmpeg.test.TestFFMPEG notzed.clstatic_JMAIN = opencl.test.clinfo notzed.vkregistry.test_JMAIN = vulkan.test.TestMandelbrot vulkan.test.TestCube notzed.vkheader.test_JMAIN = vulkan.test.TestMandelbrot vulkan.test.TestCube -notzed.vulkan.test_JMAIN = vulkan.test.TestMandelbrot vulkan.test.TestCube +notzed.vulkan.test_JMAIN = vulkan.test.TestMandelbrot vulkan.test.TestCube vulkan.test.TestSDF $(foreach module,$(java_MODULES),$(eval $(module)_JMAINFLAGS=--enable-native-access=notzed.nativez,$(module))) diff --git a/src/notzed.display/classes/au/notzed/display/Window.java b/src/notzed.display/classes/au/notzed/display/Window.java index 74d40c0..89f4601 100644 --- a/src/notzed.display/classes/au/notzed/display/Window.java +++ b/src/notzed.display/classes/au/notzed/display/Window.java @@ -118,10 +118,11 @@ public abstract class Window { @Override public VkSurfaceKHR createVulkanSurface(VkInstance instance, ResourceScope scope) { try ( Frame frame = Frame.frame()) { - VkXlibSurfaceCreateInfoKHR surfaceinfo = VkXlibSurfaceCreateInfoKHR.create(frame, + VkXlibSurfaceCreateInfoKHR surfaceinfo = VkXlibSurfaceCreateInfoKHR.create( 0, display, - window); + window, + frame); return instance.vkCreateXlibSurfaceKHR(surfaceinfo, scope); } diff --git a/src/notzed.vulkan.test/classes/vulkan/test/TestCube.java b/src/notzed.vulkan.test/classes/vulkan/test/TestCube.java index df5d7e8..cdde4d4 100644 --- a/src/notzed.vulkan.test/classes/vulkan/test/TestCube.java +++ b/src/notzed.vulkan.test/classes/vulkan/test/TestCube.java @@ -132,14 +132,15 @@ public class TestCube { System.out.printf("Debug: %d: %s\n", severity, data.getMessage()); return 0; }, scope); - VkDebugUtilsMessengerCreateInfoEXT info = VkDebugUtilsMessengerCreateInfoEXT.create(frame, + VkDebugUtilsMessengerCreateInfoEXT info = VkDebugUtilsMessengerCreateInfoEXT.create( 0, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT, VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT, cb, - null); + null, + frame); logger = instance.vkCreateDebugUtilsMessengerEXT(info, scope); } @@ -149,11 +150,12 @@ public class TestCube { void init_instance() throws Exception { try ( Frame frame = Frame.frame()) { - VkInstanceCreateInfo info = VkInstanceCreateInfo.create(frame, + VkInstanceCreateInfo info = VkInstanceCreateInfo.create( 0, - VkApplicationInfo.create(frame, "cube", 1, "cube-engine", 2, VK_API_VERSION_1_0), + VkApplicationInfo.create("cube", 1, "cube-engine", 2, VK_API_VERSION_1_0, frame), new String[]{"VK_LAYER_KHRONOS_validation"}, - new String[]{"VK_KHR_surface", "VK_KHR_xlib_surface", "VK_EXT_debug_utils"} + new String[]{"VK_KHR_surface", "VK_KHR_xlib_surface", "VK_EXT_debug_utils"}, + frame ); instance = VkInstance.vkCreateInstance(info, scope); @@ -229,22 +231,22 @@ public class TestCube { FloatArray qpri = FloatArray.create(frame, 0.0f); VkDeviceQueueCreateInfo qinfo = VkDeviceQueueCreateInfo.create( - frame, 0, graphics_queue, - qpri); + qpri, + frame); String[] extensions = { "VK_KHR_swapchain" }; VkPhysicalDeviceFeatures features = VkPhysicalDeviceFeatures.create(frame); features.setDepthClamp(1); VkDeviceCreateInfo devinfo = VkDeviceCreateInfo.create( - frame, 0, qinfo, null, extensions, - features); + features, + frame); device = physicalDevice.vkCreateDevice(devinfo, scope); @@ -272,9 +274,10 @@ public class TestCube { if (surfCapabilities.getCurrentExtent().getWidth() == 0xFFFFFFFF) { // If the surface size is undefined, the size is set to // the size of the images requested. - swapchainExtent = VkExtent2D.create(frame, + swapchainExtent = VkExtent2D.create( clampi(width, surfCapabilities.getMinImageExtent().getWidth(), surfCapabilities.getMaxImageExtent().getWidth()), - clampi(height, surfCapabilities.getMinImageExtent().getHeight(), surfCapabilities.getMaxImageExtent().getHeight())); + clampi(height, surfCapabilities.getMinImageExtent().getHeight(), surfCapabilities.getMaxImageExtent().getHeight()), + frame); } else { // If the surface size is defined, the swap chain size must match swapchainExtent = surfCapabilities.getCurrentExtent(); @@ -292,11 +295,12 @@ public class TestCube { } } - VkSwapchainCreateInfoKHR chaininfo = VkSwapchainCreateInfoKHR.create(frame, + VkSwapchainCreateInfoKHR chaininfo = VkSwapchainCreateInfoKHR.create( 0, surface, surfCapabilities.getMinImageCount(), format, + swapchainExtent.getWidth(), swapchainExtent.getHeight(), VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, 1, //.imageArrayLayers = 1, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, @@ -308,9 +312,8 @@ public class TestCube { compositeAlpha, VK_PRESENT_MODE_FIFO_KHR, VK_TRUE, - null); - chaininfo.getImageExtent().setWidth(swapchainExtent.getWidth()); - chaininfo.getImageExtent().setHeight(swapchainExtent.getHeight()); + null, + frame); chain = device.vkCreateSwapchainKHR(chaininfo, scope); @@ -320,20 +323,14 @@ public class TestCube { chainImageCount = (int)chainImage.length(); chainImageView = VkImageView.createArray(chainImageCount, (SegmentAllocator)scope); - VkImageViewCreateInfo viewinfo = VkImageViewCreateInfo.create(frame, + VkImageViewCreateInfo viewinfo = VkImageViewCreateInfo.create( 0, null, VK_IMAGE_VIEW_TYPE_2D, - format); - VkComponentMapping components = viewinfo.getComponents(); - components.setR(VK_COMPONENT_SWIZZLE_R); - components.setG(VK_COMPONENT_SWIZZLE_G); - components.setB(VK_COMPONENT_SWIZZLE_B); - components.setA(VK_COMPONENT_SWIZZLE_A); - VkImageSubresourceRange subresourceRange = viewinfo.getSubresourceRange(); - subresourceRange.setAspectMask(VK_IMAGE_ASPECT_COLOR_BIT); - subresourceRange.setLevelCount(1); - subresourceRange.setLayerCount(1); + format, + frame); + viewinfo.getComponents().set(VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A); + viewinfo.getSubresourceRange().set(VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1); for (int i = 0; i < chainImageCount; i++) { viewinfo.setImage(chainImage.get(i)); @@ -356,16 +353,18 @@ public class TestCube { void init_command() throws Exception { try ( Frame frame = Frame.frame()) { - VkCommandPoolCreateInfo poolinfo = VkCommandPoolCreateInfo.create(frame, + VkCommandPoolCreateInfo poolinfo = VkCommandPoolCreateInfo.create( 0, - graphics_queue_index); + graphics_queue_index, + frame); cmd_pool = device.vkCreateCommandPool(poolinfo, scope); - VkCommandBufferAllocateInfo cmdinfo = VkCommandBufferAllocateInfo.create(frame, + VkCommandBufferAllocateInfo cmdinfo = VkCommandBufferAllocateInfo.create( cmd_pool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, - 1); + 1, + frame); cmd = device.vkAllocateCommandBuffers(cmdinfo, (SegmentAllocator)scope, scope); } @@ -376,9 +375,11 @@ public class TestCube { try ( Frame frame = Frame.frame()) { int format = VK_FORMAT_D16_UNORM; VkMemoryRequirements req = VkMemoryRequirements.create(frame); - VkImageCreateInfo imageinfo = VkImageCreateInfo.create(frame, 0, + VkImageCreateInfo imageinfo = VkImageCreateInfo.create( + 0, VK_IMAGE_TYPE_2D, format, + width, height, 1, 1, 1, NUM_SAMPLES, @@ -386,26 +387,27 @@ public class TestCube { VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_SHARING_MODE_EXCLUSIVE, null, - VK_IMAGE_LAYOUT_UNDEFINED); - imageinfo.getExtent().setWidth(width); - imageinfo.getExtent().setHeight(height); - imageinfo.getExtent().setDepth(1); + VK_IMAGE_LAYOUT_UNDEFINED, + frame); depthImage = device.vkCreateImage(imageinfo, scope); device.vkGetImageMemoryRequirements(depthImage, req); - VkMemoryAllocateInfo alloc = VkMemoryAllocateInfo.create(frame, + VkMemoryAllocateInfo alloc = VkMemoryAllocateInfo.create( req.getSize(), - find_memory_type(memory_properties, req.getMemoryTypeBits(), VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)); + find_memory_type(memory_properties, req.getMemoryTypeBits(), VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT), + frame); depthMemory = device.vkAllocateMemory(alloc, scope); device.vkBindImageMemory(depthImage, depthMemory, 0); - VkImageViewCreateInfo viewinfo = VkImageViewCreateInfo.create(frame, 0, + VkImageViewCreateInfo viewinfo = VkImageViewCreateInfo.create( + 0, depthImage, VK_IMAGE_VIEW_TYPE_2D, - VK_FORMAT_D16_UNORM); + VK_FORMAT_D16_UNORM, + frame); VkComponentMapping components = viewinfo.getComponents(); components.setR(VK_COMPONENT_SWIZZLE_R); @@ -430,49 +432,55 @@ public class TestCube { void init_descriptor() throws Exception { try ( Frame frame = Frame.frame()) { HandleArray layout_table = VkDescriptorSetLayout.createArray(1, frame); - VkDescriptorSetLayoutBinding layout_binding = VkDescriptorSetLayoutBinding.create(frame, + VkDescriptorSetLayoutBinding layout_binding = VkDescriptorSetLayoutBinding.create( 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, VK_SHADER_STAGE_VERTEX_BIT, - null); - VkDescriptorSetLayoutCreateInfo descriptor_layout = VkDescriptorSetLayoutCreateInfo.create(frame, + null, + frame); + VkDescriptorSetLayoutCreateInfo descriptor_layout = VkDescriptorSetLayoutCreateInfo.create( 0, - layout_binding); + layout_binding, + frame); desc_layout = device.vkCreateDescriptorSetLayout(descriptor_layout, scope); layout_table.setAtIndex(0, desc_layout); - VkPipelineLayoutCreateInfo pipeline_info = VkPipelineLayoutCreateInfo.create(frame, + VkPipelineLayoutCreateInfo pipeline_info = VkPipelineLayoutCreateInfo.create( 0, //1, layout_table, - null); + null, + frame); pipeline_layout = device.vkCreatePipelineLayout(pipeline_info, scope); - VkDescriptorPoolSize type_count = VkDescriptorPoolSize.create(frame, + VkDescriptorPoolSize type_count = VkDescriptorPoolSize.create( VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, - 1); + 1, + frame); - VkDescriptorPoolCreateInfo descriptor_pool = VkDescriptorPoolCreateInfo.create(frame, + VkDescriptorPoolCreateInfo descriptor_pool = VkDescriptorPoolCreateInfo.create( 0, 1, - type_count); + type_count, + frame); desc_pool = device.vkCreateDescriptorPool(descriptor_pool, scope); - VkDescriptorSetAllocateInfo alloc_info = VkDescriptorSetAllocateInfo.create(frame, + VkDescriptorSetAllocateInfo alloc_info = VkDescriptorSetAllocateInfo.create( desc_pool, //1, - layout_table); + layout_table, + frame); System.out.println(alloc_info); desc_set = device.vkAllocateDescriptorSets(alloc_info, (SegmentAllocator)scope); - VkDescriptorBufferInfo uniformInfo = VkDescriptorBufferInfo.create(frame, uniform.buffer, 0, uniform.size); - VkWriteDescriptorSet writes = VkWriteDescriptorSet.create(frame, + VkDescriptorBufferInfo uniformInfo = VkDescriptorBufferInfo.create(uniform.buffer, 0, uniform.size, frame); + VkWriteDescriptorSet writes = VkWriteDescriptorSet.create( desc_set.getAtIndex(0), 0, 0, @@ -480,7 +488,8 @@ public class TestCube { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, null, uniformInfo, - null); + null, + frame); device.vkUpdateDescriptorSets(1, writes, 0, null); } @@ -510,15 +519,17 @@ public class TestCube { attachments.setFinalLayoutAtIndex(1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); attachments.setFlagsAtIndex(1, 0); - VkAttachmentReference color_reference = VkAttachmentReference.create(frame, + VkAttachmentReference color_reference = VkAttachmentReference.create( 0, - VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, + frame); - VkAttachmentReference depth_reference = VkAttachmentReference.create(frame, + VkAttachmentReference depth_reference = VkAttachmentReference.create( 1, - VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, + frame); - VkSubpassDescription subpass = VkSubpassDescription.create(frame, + VkSubpassDescription subpass = VkSubpassDescription.create( 0, VK_PIPELINE_BIND_POINT_GRAPHICS, null, @@ -526,14 +537,16 @@ public class TestCube { color_reference, null, depth_reference, - null); + null, + frame); - VkRenderPassCreateInfo rp_info = VkRenderPassCreateInfo.create(frame, + VkRenderPassCreateInfo rp_info = VkRenderPassCreateInfo.create( 0, //(int)attachments.length(), attachments, subpass, - null); + null, + frame); render_pass = device.vkCreateRenderPass(rp_info, scope); } @@ -546,14 +559,15 @@ public class TestCube { attachments.setAtIndex(1, depthView); // FIXME: I don't think i want lenghts implied for types tbh - VkFramebufferCreateInfo fb_info = VkFramebufferCreateInfo.create(frame, + VkFramebufferCreateInfo fb_info = VkFramebufferCreateInfo.create( 0, render_pass, //2, attachments, width, height, - 1); + 1, + frame); framebuffers = VkFramebuffer.createArray(chainImage.length(), (SegmentAllocator)scope); for (int i = 0; i < chainImage.size(); i++) { @@ -593,20 +607,23 @@ public class TestCube { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR); - VkPipelineDynamicStateCreateInfo dynamicState = VkPipelineDynamicStateCreateInfo.create(frame, - 0, dynamicStateEnables); + VkPipelineDynamicStateCreateInfo dynamicState = VkPipelineDynamicStateCreateInfo.create( + 0, dynamicStateEnables, + frame); - VkPipelineVertexInputStateCreateInfo vi = VkPipelineVertexInputStateCreateInfo.create(frame, + VkPipelineVertexInputStateCreateInfo vi = VkPipelineVertexInputStateCreateInfo.create( 0, vi_binding, - vi_attribs); + vi_attribs, + frame); - VkPipelineInputAssemblyStateCreateInfo ia = VkPipelineInputAssemblyStateCreateInfo.create(frame, + VkPipelineInputAssemblyStateCreateInfo ia = VkPipelineInputAssemblyStateCreateInfo.create( 0, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, - 0); + 0, + frame); - VkPipelineRasterizationStateCreateInfo rs = VkPipelineRasterizationStateCreateInfo.create(frame, + VkPipelineRasterizationStateCreateInfo rs = VkPipelineRasterizationStateCreateInfo.create( 0, VK_TRUE, VK_FALSE, @@ -617,9 +634,10 @@ public class TestCube { 0.0f, 0.0f, 0.0f, - 1.0f); + 1.0f, + frame); - VkPipelineColorBlendAttachmentState att_state = VkPipelineColorBlendAttachmentState.create(frame, + VkPipelineColorBlendAttachmentState att_state = VkPipelineColorBlendAttachmentState.create( VK_FALSE, VK_BLEND_FACTOR_ZERO, VK_BLEND_FACTOR_ZERO, @@ -627,21 +645,24 @@ public class TestCube { VK_BLEND_FACTOR_ZERO, VK_BLEND_FACTOR_ZERO, VK_BLEND_OP_ADD, - 0xf); + 0xf, + frame); - VkPipelineColorBlendStateCreateInfo cb = VkPipelineColorBlendStateCreateInfo.create(frame, + VkPipelineColorBlendStateCreateInfo cb = VkPipelineColorBlendStateCreateInfo.create( 0, VK_FALSE, VK_LOGIC_OP_NO_OP, att_state, - 1.0f, 1.0f, 1.0f, 1.0f); + 1.0f, 1.0f, 1.0f, 1.0f, + frame); - VkPipelineViewportStateCreateInfo vp = VkPipelineViewportStateCreateInfo.create(frame, + VkPipelineViewportStateCreateInfo vp = VkPipelineViewportStateCreateInfo.create( 0, 1, null, - 1, null); + 1, null, + frame); - VkPipelineDepthStencilStateCreateInfo ds = VkPipelineDepthStencilStateCreateInfo.create(frame, + VkPipelineDepthStencilStateCreateInfo ds = VkPipelineDepthStencilStateCreateInfo.create( 0, VK_TRUE, VK_TRUE, @@ -649,7 +670,8 @@ public class TestCube { VK_FALSE, VK_FALSE, 0.0f, - 0.0f); + 0.0f, + frame); VkStencilOpState back = ds.getBack(); back.setFailOp(VK_STENCIL_OP_KEEP); @@ -670,31 +692,33 @@ public class TestCube { front.setDepthFailOp(VK_STENCIL_OP_KEEP); front.setWriteMask(0); - VkPipelineMultisampleStateCreateInfo ms = VkPipelineMultisampleStateCreateInfo.create(frame, + VkPipelineMultisampleStateCreateInfo ms = VkPipelineMultisampleStateCreateInfo.create( 0, NUM_SAMPLES, 0, //.sampleShadingEnable = VK_FALSE, 0.0f, null, 0, //.alphaToCoverageEnable = VK_FALSE, - 0 //.alphaToOneEnable = VK_FALSE, + 0, //.alphaToOneEnable = VK_FALSE, + frame ); - VkShaderModuleCreateInfo vsInfo = VkShaderModuleCreateInfo.create(frame, + VkShaderModuleCreateInfo vsInfo = VkShaderModuleCreateInfo.create( 0, cube_vs.length() * 4, - cube_vs); - VkShaderModuleCreateInfo fsInfo = VkShaderModuleCreateInfo.create(frame, + cube_vs, + frame); + VkShaderModuleCreateInfo fsInfo = VkShaderModuleCreateInfo.create( 0, cube_fs.length() * 4, - cube_fs); + cube_fs, + frame); shader.setAtIndex(0, device.vkCreateShaderModule(vsInfo, scope)); shader.setAtIndex(1, device.vkCreateShaderModule(fsInfo, scope)); VkPipelineShaderStageCreateInfo shaderStages = VkPipelineShaderStageCreateInfo.createArray(2, (SegmentAllocator)scope); - // FIXME: createArray should initialise this shaderStages.setStage(VK_SHADER_STAGE_VERTEX_BIT); shaderStages.setName("main", (SegmentAllocator)scope); shaderStages.setModule(shader.get(0)); @@ -703,7 +727,7 @@ public class TestCube { shaderStages.setNameAtIndex(1, "main", (SegmentAllocator)scope); shaderStages.setModuleAtIndex(1, shader.get(1)); - VkGraphicsPipelineCreateInfo pipeline = VkGraphicsPipelineCreateInfo.create(frame, + VkGraphicsPipelineCreateInfo pipeline = VkGraphicsPipelineCreateInfo.create( 0, //2, shaderStages, shaderStages, @@ -720,14 +744,15 @@ public class TestCube { render_pass, 0, null, - 0); + 0, + frame); res = device.vkCreateGraphicsPipelines(null, 1, pipeline, this.pipeline); - VkSemaphoreCreateInfo seminfo = VkSemaphoreCreateInfo.create(frame, 0); + VkSemaphoreCreateInfo seminfo = VkSemaphoreCreateInfo.create(0, frame); chainSemaphore = device.vkCreateSemaphore(seminfo, scope); - VkFenceCreateInfo fenceInfo = VkFenceCreateInfo.create(frame, 0); + VkFenceCreateInfo fenceInfo = VkFenceCreateInfo.create(0, frame); drawFence = device.vkCreateFence(fenceInfo, scope); } } @@ -735,9 +760,10 @@ public class TestCube { void execute_begin_command_buffer() throws Exception { /* DEPENDS on init_command() */ try ( Frame frame = Frame.frame()) { - VkCommandBufferBeginInfo cmd_buf_info = VkCommandBufferBeginInfo.create(frame, + VkCommandBufferBeginInfo cmd_buf_info = VkCommandBufferBeginInfo.create( 0, - null); + null, + frame); cmd.getAtIndex(0).vkBeginCommandBuffer(cmd_buf_info); } @@ -756,15 +782,16 @@ public class TestCube { /* FIXME: frame shoudl provide or take explicit scope */ try ( ResourceScope scope = ResourceScope.newConfinedScope(); Frame frame = Frame.frame()) { IntArray pipe_stage_flags = IntArray.create(frame, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT); - VkFenceCreateInfo fenceInfo = VkFenceCreateInfo.create(frame, 0); + VkFenceCreateInfo fenceInfo = VkFenceCreateInfo.create(0, frame); HandleArray fences = VkFence.createArray(1, frame); fences.setAtIndex(0, device.vkCreateFence(fenceInfo, scope)); - VkSubmitInfo submit_info = VkSubmitInfo.create(frame, + VkSubmitInfo submit_info = VkSubmitInfo.create( 1, null, pipe_stage_flags, cmd, - null); + null, + frame); graphics_queue.vkQueueSubmit(1, submit_info, drawFence); @@ -779,8 +806,9 @@ public class TestCube { void cmd_viewport() { try ( Frame frame = Frame.frame()) { VkCommandBuffer cmd = this.cmd.getAtIndex(0); - VkViewport viewport = VkViewport.create(frame, - 0, 0, width, height, 0.0f, 1.0f); + VkViewport viewport = VkViewport.create( + 0, 0, width, height, 0.0f, 1.0f, + frame); cmd.vkCmdSetViewport(0, 1, viewport); } } @@ -788,12 +816,7 @@ public class TestCube { void cmd_scissors() { try ( Frame frame = Frame.frame()) { VkCommandBuffer cmd = this.cmd.getAtIndex(0); - VkRect2D scissor = VkRect2D.create(frame); - VkExtent2D extent = scissor.getExtent(); - - extent.setWidth(width); - extent.setHeight(height); - + VkRect2D scissor = VkRect2D.create(0, 0, width, height, frame); cmd.vkCmdSetScissor(0, 1, scissor); } } @@ -821,13 +844,12 @@ public class TestCube { System.out.printf("render framebuffer[%d] = %s\n", chainIndex, framebuffers.getAtIndex(chainIndex)); - VkRenderPassBeginInfo rp_begin = VkRenderPassBeginInfo.create(frame, + VkRenderPassBeginInfo rp_begin = VkRenderPassBeginInfo.create( render_pass, framebuffers.getAtIndex(chainIndex), - clear_values); - VkExtent2D extent = rp_begin.getRenderArea().getExtent(); - extent.setWidth(width); - extent.setHeight(height); + 0, 0, width, height, + clear_values, + frame); cmd.vkCmdBeginRenderPass(rp_begin, VK_SUBPASS_CONTENTS_INLINE); @@ -848,10 +870,11 @@ public class TestCube { semaphores.setAtIndex(0, chainSemaphore); - VkSubmitInfo submit_info = VkSubmitInfo.create(frame, + VkSubmitInfo submit_info = VkSubmitInfo.create( 1, semaphores, pipe_stage_flags, this.cmd, - null); + null, + frame); HandleArray fences = VkFence.createArray(1, frame); @@ -870,12 +893,13 @@ public class TestCube { // Now present the image in the window HandleArray chains = VkSwapchainKHR.createArray(1, frame); chains.setAtIndex(0, chain); - VkPresentInfoKHR present = VkPresentInfoKHR.create(frame, + VkPresentInfoKHR present = VkPresentInfoKHR.create( null, 1, chains, chainIndices, - null); + null, + frame); present_queue.vkQueuePresentKHR(present); } @@ -891,21 +915,23 @@ public class TestCube { BufferMemory init_buffer(long dataSize, int usage, int properties, MemorySegment init) throws Exception { try ( Frame frame = Frame.frame()) { VkMemoryRequirements req = VkMemoryRequirements.create(frame); - VkBufferCreateInfo buf_info = VkBufferCreateInfo.create(frame, + VkBufferCreateInfo buf_info = VkBufferCreateInfo.create( 0, dataSize, usage, VK_SHARING_MODE_EXCLUSIVE, //0, - null); + null, + frame); VkBuffer buffer = device.vkCreateBuffer(buf_info, scope); device.vkGetBufferMemoryRequirements(buffer, req); - VkMemoryAllocateInfo alloc = VkMemoryAllocateInfo.create(frame, + VkMemoryAllocateInfo alloc = VkMemoryAllocateInfo.create( req.getSize(), - find_memory_type(memory_properties, req.getMemoryTypeBits(), properties)); + find_memory_type(memory_properties, req.getMemoryTypeBits(), properties), + frame); VkDeviceMemory memory = device.vkAllocateMemory(alloc, scope); diff --git a/src/notzed.vulkan.test/classes/vulkan/test/TestMandelbrot.java b/src/notzed.vulkan.test/classes/vulkan/test/TestMandelbrot.java index c02aa2d..703cffc 100755 --- a/src/notzed.vulkan.test/classes/vulkan/test/TestMandelbrot.java +++ b/src/notzed.vulkan.test/classes/vulkan/test/TestMandelbrot.java @@ -103,7 +103,7 @@ public class TestMandelbrot { System.out.printf("Debug: %d: %s\n", severity, data.getMessage()); return 0; }, scope); - VkDebugUtilsMessengerCreateInfoEXT info = VkDebugUtilsMessengerCreateInfoEXT.create(frame, + VkDebugUtilsMessengerCreateInfoEXT info = VkDebugUtilsMessengerCreateInfoEXT.create( 0, //VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT @@ -113,7 +113,8 @@ public class TestMandelbrot { | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT, cb, - null); + null, + frame); logger = instance.vkCreateDebugUtilsMessengerEXT(info, scope); } @@ -121,11 +122,12 @@ public class TestMandelbrot { void init_instance() throws Exception { try ( Frame frame = Frame.frame()) { - VkInstanceCreateInfo info = VkInstanceCreateInfo.create(frame, + VkInstanceCreateInfo info = VkInstanceCreateInfo.create( 0, - VkApplicationInfo.create(frame, "test", 1, "test-engine", 2, VK_API_VERSION_1_0), + VkApplicationInfo.create("test", 1, "test-engine", 2, VK_API_VERSION_1_0, frame), new String[]{"VK_LAYER_KHRONOS_validation"}, - debug ? new String[]{"VK_EXT_debug_utils"} : null + debug ? new String[]{"VK_EXT_debug_utils"} : null, + frame ); instance = VkInstance.vkCreateInstance(info, scope); @@ -174,17 +176,17 @@ public class TestMandelbrot { FloatArray qpri = FloatArray.create(frame, 0.0f); VkDeviceQueueCreateInfo qinfo = VkDeviceQueueCreateInfo.create( - frame, 0, queueid, - qpri); + qpri, + frame); VkDeviceCreateInfo devinfo = VkDeviceCreateInfo.create( - frame, 0, qinfo, null, null, - null); + null, + frame); device = physicalDevice.vkCreateDevice(devinfo, scope); @@ -208,20 +210,22 @@ public class TestMandelbrot { BufferMemory init_buffer(long dataSize, int usage, int properties) throws Exception { try ( Frame frame = Frame.frame()) { VkMemoryRequirements req = VkMemoryRequirements.create(frame); - VkBufferCreateInfo buf_info = VkBufferCreateInfo.create(frame, + VkBufferCreateInfo buf_info = VkBufferCreateInfo.create( 0, dataSize, usage, VK_SHARING_MODE_EXCLUSIVE, - null); + null, + frame); VkBuffer buffer = device.vkCreateBuffer(buf_info, scope); device.vkGetBufferMemoryRequirements(buffer, req); - VkMemoryAllocateInfo alloc = VkMemoryAllocateInfo.create(frame, + VkMemoryAllocateInfo alloc = VkMemoryAllocateInfo.create( req.getSize(), - find_memory_type(deviceMemoryProperties, req.getMemoryTypeBits(), properties)); + find_memory_type(deviceMemoryProperties, req.getMemoryTypeBits(), properties), + frame); VkDeviceMemory memory = device.vkAllocateMemory(alloc, scope); @@ -242,28 +246,32 @@ public class TestMandelbrot { void init_descriptor() throws Exception { try ( Frame frame = Frame.frame()) { /* Create descriptorset layout */ - VkDescriptorSetLayoutBinding layout_binding = VkDescriptorSetLayoutBinding.create(frame, + VkDescriptorSetLayoutBinding layout_binding = VkDescriptorSetLayoutBinding.create( 0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, - null); + null, + frame); - VkDescriptorSetLayoutCreateInfo descriptor_layout = VkDescriptorSetLayoutCreateInfo.create(frame, + VkDescriptorSetLayoutCreateInfo descriptor_layout = VkDescriptorSetLayoutCreateInfo.create( 0, - layout_binding); + layout_binding, + frame); descriptorSetLayout = device.vkCreateDescriptorSetLayout(descriptor_layout, scope); /* Create descriptor pool */ - VkDescriptorPoolSize type_count = VkDescriptorPoolSize.create(frame, + VkDescriptorPoolSize type_count = VkDescriptorPoolSize.create( VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, - 1); + 1, + frame); - VkDescriptorPoolCreateInfo descriptor_pool = VkDescriptorPoolCreateInfo.create(frame, + VkDescriptorPoolCreateInfo descriptor_pool = VkDescriptorPoolCreateInfo.create( 0, 1, - type_count); + type_count, + frame); descriptorPool = device.vkCreateDescriptorPool(descriptor_pool, scope); @@ -272,19 +280,21 @@ public class TestMandelbrot { layout_table.setAtIndex(0, descriptorSetLayout); - VkDescriptorSetAllocateInfo alloc_info = VkDescriptorSetAllocateInfo.create(frame, + VkDescriptorSetAllocateInfo alloc_info = VkDescriptorSetAllocateInfo.create( descriptorPool, - layout_table); + layout_table, + frame); descriptorSets = device.vkAllocateDescriptorSets(alloc_info, (SegmentAllocator)scope); /* Bind a buffer to the descriptor */ - VkDescriptorBufferInfo bufferInfo = VkDescriptorBufferInfo.create(frame, + VkDescriptorBufferInfo bufferInfo = VkDescriptorBufferInfo.create( dst.buffer, 0, - dstBufferSize); + dstBufferSize, + frame); - VkWriteDescriptorSet writeSet = VkWriteDescriptorSet.create(frame, + VkWriteDescriptorSet writeSet = VkWriteDescriptorSet.create( descriptorSets.getAtIndex(0), 0, 0, @@ -292,7 +302,8 @@ public class TestMandelbrot { VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, null, bufferInfo, - null); + null, + frame); System.out.println(writeSet); @@ -306,10 +317,11 @@ public class TestMandelbrot { void init_pipeline() throws Exception { try ( Frame frame = Frame.frame()) { /* Set shader code */ - VkShaderModuleCreateInfo vsInfo = VkShaderModuleCreateInfo.create(frame, + VkShaderModuleCreateInfo vsInfo = VkShaderModuleCreateInfo.create( 0, mandelbrot_cs.length() * 4, - mandelbrot_cs); + mandelbrot_cs, + frame); mandelbrotShader = device.vkCreateShaderModule(vsInfo, scope); @@ -318,19 +330,21 @@ public class TestMandelbrot { layout_table.setAtIndex(0, descriptorSetLayout); - VkPipelineLayoutCreateInfo pipelineinfo = VkPipelineLayoutCreateInfo.create(frame, + VkPipelineLayoutCreateInfo pipelineinfo = VkPipelineLayoutCreateInfo.create( 0, layout_table, - null); + null, + frame); pipelineLayout = device.vkCreatePipelineLayout(pipelineinfo, scope); /* Create pipeline */ - VkComputePipelineCreateInfo pipeline = VkComputePipelineCreateInfo.create(frame, + VkComputePipelineCreateInfo pipeline = VkComputePipelineCreateInfo.create( 0, pipelineLayout, null, - 0); + 0, + frame); VkPipelineShaderStageCreateInfo stage = pipeline.getStage(); @@ -347,24 +361,27 @@ public class TestMandelbrot { */ void init_command_buffer() throws Exception { try ( Frame frame = Frame.frame()) { - VkCommandPoolCreateInfo poolinfo = VkCommandPoolCreateInfo.create(frame, + VkCommandPoolCreateInfo poolinfo = VkCommandPoolCreateInfo.create( 0, - computeQueueIndex); + computeQueueIndex, + frame); commandPool = device.vkCreateCommandPool(poolinfo, scope); - VkCommandBufferAllocateInfo cmdinfo = VkCommandBufferAllocateInfo.create(frame, + VkCommandBufferAllocateInfo cmdinfo = VkCommandBufferAllocateInfo.create( commandPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, - 1); + 1, + frame); // should it take a scope? commandBuffers = device.vkAllocateCommandBuffers(cmdinfo, (SegmentAllocator)scope, scope); /* Fill command buffer with commands for later operation */ - VkCommandBufferBeginInfo beginInfo = VkCommandBufferBeginInfo.create(frame, + VkCommandBufferBeginInfo beginInfo = VkCommandBufferBeginInfo.create( VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, - null); + null, + frame); commandBuffers.get(0).vkBeginCommandBuffer(beginInfo); diff --git a/src/notzed.vulkan.test/classes/vulkan/test/TestSDF.java b/src/notzed.vulkan.test/classes/vulkan/test/TestSDF.java index a947ff7..651d3e6 100644 --- a/src/notzed.vulkan.test/classes/vulkan/test/TestSDF.java +++ b/src/notzed.vulkan.test/classes/vulkan/test/TestSDF.java @@ -133,14 +133,15 @@ public class TestSDF { System.out.printf("Debug: %d: %s\n", severity, data.getMessage()); return 0; }, scope); - VkDebugUtilsMessengerCreateInfoEXT info = VkDebugUtilsMessengerCreateInfoEXT.create(frame, + VkDebugUtilsMessengerCreateInfoEXT info = VkDebugUtilsMessengerCreateInfoEXT.create( 0, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT, VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT, cb, - null); + null, + frame); logger = instance.vkCreateDebugUtilsMessengerEXT(info, scope); } @@ -150,11 +151,12 @@ public class TestSDF { void init_instance() throws Exception { try ( Frame frame = Frame.frame()) { - VkInstanceCreateInfo info = VkInstanceCreateInfo.create(frame, + VkInstanceCreateInfo info = VkInstanceCreateInfo.create( 0, - VkApplicationInfo.create(frame, "cube", 1, "cube-engine", 2, VK_API_VERSION_1_0), + VkApplicationInfo.create("cube", 1, "cube-engine", 2, VK_API_VERSION_1_0, frame), new String[]{"VK_LAYER_KHRONOS_validation"}, - new String[]{"VK_KHR_surface", "VK_KHR_xlib_surface", "VK_EXT_debug_utils"} + new String[]{"VK_KHR_surface", "VK_KHR_xlib_surface", "VK_EXT_debug_utils"}, + frame ); instance = VkInstance.vkCreateInstance(info, scope); @@ -230,22 +232,22 @@ public class TestSDF { FloatArray qpri = FloatArray.create(frame, 0.0f); VkDeviceQueueCreateInfo qinfo = VkDeviceQueueCreateInfo.create( - frame, 0, graphics_queue, - qpri); + qpri, + frame); String[] extensions = { "VK_KHR_swapchain" }; VkPhysicalDeviceFeatures features = VkPhysicalDeviceFeatures.create(frame); features.setDepthClamp(1); VkDeviceCreateInfo devinfo = VkDeviceCreateInfo.create( - frame, 0, qinfo, null, extensions, - features); + features, + frame); device = physicalDevice.vkCreateDevice(devinfo, scope); @@ -273,9 +275,10 @@ public class TestSDF { if (surfCapabilities.getCurrentExtent().getWidth() == 0xFFFFFFFF) { // If the surface size is undefined, the size is set to // the size of the images requested. - swapchainExtent = VkExtent2D.create(frame, + swapchainExtent = VkExtent2D.create( clampi(width, surfCapabilities.getMinImageExtent().getWidth(), surfCapabilities.getMaxImageExtent().getWidth()), - clampi(height, surfCapabilities.getMinImageExtent().getHeight(), surfCapabilities.getMaxImageExtent().getHeight())); + clampi(height, surfCapabilities.getMinImageExtent().getHeight(), surfCapabilities.getMaxImageExtent().getHeight()), + frame); } else { // If the surface size is defined, the swap chain size must match swapchainExtent = surfCapabilities.getCurrentExtent(); @@ -293,12 +296,13 @@ public class TestSDF { } } - VkSwapchainCreateInfoKHR chaininfo = VkSwapchainCreateInfoKHR.create(frame, + VkSwapchainCreateInfoKHR chaininfo = VkSwapchainCreateInfoKHR.create( 0, surface, surfCapabilities.getMinImageCount(), format, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, + swapchainExtent.getWidth(), swapchainExtent.getHeight(), 1, //.imageArrayLayers = 1, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_SHARING_MODE_EXCLUSIVE, @@ -309,9 +313,8 @@ public class TestSDF { compositeAlpha, VK_PRESENT_MODE_FIFO_KHR, VK_TRUE, - null); - chaininfo.getImageExtent().setWidth(swapchainExtent.getWidth()); - chaininfo.getImageExtent().setHeight(swapchainExtent.getHeight()); + null, + frame); chain = device.vkCreateSwapchainKHR(chaininfo, scope); @@ -321,20 +324,14 @@ public class TestSDF { chainImageCount = (int)chainImage.length(); chainImageView = VkImageView.createArray(chainImageCount, (SegmentAllocator)scope); - VkImageViewCreateInfo viewinfo = VkImageViewCreateInfo.create(frame, + VkImageViewCreateInfo viewinfo = VkImageViewCreateInfo.create( 0, null, VK_IMAGE_VIEW_TYPE_2D, - format); - VkComponentMapping components = viewinfo.getComponents(); - components.setR(VK_COMPONENT_SWIZZLE_R); - components.setG(VK_COMPONENT_SWIZZLE_G); - components.setB(VK_COMPONENT_SWIZZLE_B); - components.setA(VK_COMPONENT_SWIZZLE_A); - VkImageSubresourceRange subresourceRange = viewinfo.getSubresourceRange(); - subresourceRange.setAspectMask(VK_IMAGE_ASPECT_COLOR_BIT); - subresourceRange.setLevelCount(1); - subresourceRange.setLayerCount(1); + format, + frame); + viewinfo.getComponents().set(VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A); + viewinfo.getSubresourceRange().set(VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1); for (int i = 0; i < chainImageCount; i++) { viewinfo.setImage(chainImage.get(i)); @@ -357,16 +354,18 @@ public class TestSDF { void init_command() throws Exception { try ( Frame frame = Frame.frame()) { - VkCommandPoolCreateInfo poolinfo = VkCommandPoolCreateInfo.create(frame, + VkCommandPoolCreateInfo poolinfo = VkCommandPoolCreateInfo.create( 0, - graphics_queue_index); + graphics_queue_index, + frame); cmd_pool = device.vkCreateCommandPool(poolinfo, scope); - VkCommandBufferAllocateInfo cmdinfo = VkCommandBufferAllocateInfo.create(frame, + VkCommandBufferAllocateInfo cmdinfo = VkCommandBufferAllocateInfo.create( cmd_pool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, - 1); + 1, + frame); cmd = device.vkAllocateCommandBuffers(cmdinfo, (SegmentAllocator)scope, scope); } @@ -377,9 +376,11 @@ public class TestSDF { try ( Frame frame = Frame.frame()) { int format = VK_FORMAT_D16_UNORM; VkMemoryRequirements req = VkMemoryRequirements.create(frame); - VkImageCreateInfo imageinfo = VkImageCreateInfo.create(frame, 0, + VkImageCreateInfo imageinfo = VkImageCreateInfo.create( + 0, VK_IMAGE_TYPE_2D, format, + width, height, 1, 1, 1, NUM_SAMPLES, @@ -387,26 +388,27 @@ public class TestSDF { VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_SHARING_MODE_EXCLUSIVE, null, - VK_IMAGE_LAYOUT_UNDEFINED); - imageinfo.getExtent().setWidth(width); - imageinfo.getExtent().setHeight(height); - imageinfo.getExtent().setDepth(1); + VK_IMAGE_LAYOUT_UNDEFINED, + frame); depthImage = device.vkCreateImage(imageinfo, scope); device.vkGetImageMemoryRequirements(depthImage, req); - VkMemoryAllocateInfo alloc = VkMemoryAllocateInfo.create(frame, + VkMemoryAllocateInfo alloc = VkMemoryAllocateInfo.create( req.getSize(), - find_memory_type(memory_properties, req.getMemoryTypeBits(), VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)); + find_memory_type(memory_properties, req.getMemoryTypeBits(), VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT), + frame); depthMemory = device.vkAllocateMemory(alloc, scope); device.vkBindImageMemory(depthImage, depthMemory, 0); - VkImageViewCreateInfo viewinfo = VkImageViewCreateInfo.create(frame, 0, + VkImageViewCreateInfo viewinfo = VkImageViewCreateInfo.create( + 0, depthImage, VK_IMAGE_VIEW_TYPE_2D, - VK_FORMAT_D16_UNORM); + VK_FORMAT_D16_UNORM, + frame); VkComponentMapping components = viewinfo.getComponents(); components.setR(VK_COMPONENT_SWIZZLE_R); @@ -431,49 +433,55 @@ public class TestSDF { void init_descriptor() throws Exception { try ( Frame frame = Frame.frame()) { HandleArray layout_table = VkDescriptorSetLayout.createArray(1, frame); - VkDescriptorSetLayoutBinding layout_binding = VkDescriptorSetLayoutBinding.create(frame, + VkDescriptorSetLayoutBinding layout_binding = VkDescriptorSetLayoutBinding.create( 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, VK_SHADER_STAGE_VERTEX_BIT, - null); - VkDescriptorSetLayoutCreateInfo descriptor_layout = VkDescriptorSetLayoutCreateInfo.create(frame, + null, + frame); + VkDescriptorSetLayoutCreateInfo descriptor_layout = VkDescriptorSetLayoutCreateInfo.create( 0, - layout_binding); + layout_binding, + frame); desc_layout = device.vkCreateDescriptorSetLayout(descriptor_layout, scope); layout_table.setAtIndex(0, desc_layout); - VkPipelineLayoutCreateInfo pipeline_info = VkPipelineLayoutCreateInfo.create(frame, + VkPipelineLayoutCreateInfo pipeline_info = VkPipelineLayoutCreateInfo.create( 0, //1, layout_table, - null); + null, + frame); pipeline_layout = device.vkCreatePipelineLayout(pipeline_info, scope); - VkDescriptorPoolSize type_count = VkDescriptorPoolSize.create(frame, + VkDescriptorPoolSize type_count = VkDescriptorPoolSize.create( VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, - 1); + 1, + frame); - VkDescriptorPoolCreateInfo descriptor_pool = VkDescriptorPoolCreateInfo.create(frame, + VkDescriptorPoolCreateInfo descriptor_pool = VkDescriptorPoolCreateInfo.create( 0, 1, - type_count); + type_count, + frame); desc_pool = device.vkCreateDescriptorPool(descriptor_pool, scope); - VkDescriptorSetAllocateInfo alloc_info = VkDescriptorSetAllocateInfo.create(frame, + VkDescriptorSetAllocateInfo alloc_info = VkDescriptorSetAllocateInfo.create( desc_pool, //1, - layout_table); + layout_table, + frame); System.out.println(alloc_info); desc_set = device.vkAllocateDescriptorSets(alloc_info, (SegmentAllocator)scope); - VkDescriptorBufferInfo uniformInfo = VkDescriptorBufferInfo.create(frame, uniform.buffer, 0, uniform.size); - VkWriteDescriptorSet writes = VkWriteDescriptorSet.create(frame, + VkDescriptorBufferInfo uniformInfo = VkDescriptorBufferInfo.create(uniform.buffer, 0, uniform.size, frame); + VkWriteDescriptorSet writes = VkWriteDescriptorSet.create( desc_set.getAtIndex(0), 0, 0, @@ -481,7 +489,8 @@ public class TestSDF { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, null, uniformInfo, - null); + null, + frame); device.vkUpdateDescriptorSets(1, writes, 0, null); } @@ -511,15 +520,17 @@ public class TestSDF { attachments.setFinalLayoutAtIndex(1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); attachments.setFlagsAtIndex(1, 0); - VkAttachmentReference color_reference = VkAttachmentReference.create(frame, + VkAttachmentReference color_reference = VkAttachmentReference.create( 0, - VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, + frame); - VkAttachmentReference depth_reference = VkAttachmentReference.create(frame, + VkAttachmentReference depth_reference = VkAttachmentReference.create( 1, - VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, + frame); - VkSubpassDescription subpass = VkSubpassDescription.create(frame, + VkSubpassDescription subpass = VkSubpassDescription.create( 0, VK_PIPELINE_BIND_POINT_GRAPHICS, null, @@ -527,14 +538,16 @@ public class TestSDF { color_reference, null, depth_reference, - null); + null, + frame); - VkRenderPassCreateInfo rp_info = VkRenderPassCreateInfo.create(frame, + VkRenderPassCreateInfo rp_info = VkRenderPassCreateInfo.create( 0, //(int)attachments.length(), attachments, subpass, - null); + null, + frame); render_pass = device.vkCreateRenderPass(rp_info, scope); } @@ -547,14 +560,15 @@ public class TestSDF { attachments.setAtIndex(1, depthView); // FIXME: I don't think i want lenghts implied for types tbh - VkFramebufferCreateInfo fb_info = VkFramebufferCreateInfo.create(frame, + VkFramebufferCreateInfo fb_info = VkFramebufferCreateInfo.create( 0, render_pass, //2, attachments, width, height, - 1); + 1, + frame); framebuffers = VkFramebuffer.createArray(chainImage.length(), (SegmentAllocator)scope); for (int i = 0; i < chainImage.size(); i++) { @@ -605,20 +619,23 @@ public class TestSDF { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR); - VkPipelineDynamicStateCreateInfo dynamicState = VkPipelineDynamicStateCreateInfo.create(frame, - 0, dynamicStateEnables); + VkPipelineDynamicStateCreateInfo dynamicState = VkPipelineDynamicStateCreateInfo.create( + 0, dynamicStateEnables, + frame); - VkPipelineVertexInputStateCreateInfo vi = VkPipelineVertexInputStateCreateInfo.create(frame, + VkPipelineVertexInputStateCreateInfo vi = VkPipelineVertexInputStateCreateInfo.create( 0, vi_binding, - vi_attribs); + vi_attribs, + frame); - VkPipelineInputAssemblyStateCreateInfo ia = VkPipelineInputAssemblyStateCreateInfo.create(frame, + VkPipelineInputAssemblyStateCreateInfo ia = VkPipelineInputAssemblyStateCreateInfo.create( 0, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, - 0); + 0, + frame); - VkPipelineRasterizationStateCreateInfo rs = VkPipelineRasterizationStateCreateInfo.create(frame, + VkPipelineRasterizationStateCreateInfo rs = VkPipelineRasterizationStateCreateInfo.create( 0, VK_TRUE, VK_FALSE, @@ -629,9 +646,10 @@ public class TestSDF { 0.0f, 0.0f, 0.0f, - 1.0f); + 1.0f, + frame); - VkPipelineColorBlendAttachmentState att_state = VkPipelineColorBlendAttachmentState.create(frame, + VkPipelineColorBlendAttachmentState att_state = VkPipelineColorBlendAttachmentState.create( VK_FALSE, VK_BLEND_FACTOR_ZERO, VK_BLEND_FACTOR_ZERO, @@ -639,21 +657,24 @@ public class TestSDF { VK_BLEND_FACTOR_ZERO, VK_BLEND_FACTOR_ZERO, VK_BLEND_OP_ADD, - 0xf); + 0xf, + frame); - VkPipelineColorBlendStateCreateInfo cb = VkPipelineColorBlendStateCreateInfo.create(frame, + VkPipelineColorBlendStateCreateInfo cb = VkPipelineColorBlendStateCreateInfo.create( 0, VK_FALSE, VK_LOGIC_OP_NO_OP, att_state, - 1.0f, 1.0f, 1.0f, 1.0f); + 1.0f, 1.0f, 1.0f, 1.0f, + frame); - VkPipelineViewportStateCreateInfo vp = VkPipelineViewportStateCreateInfo.create(frame, + VkPipelineViewportStateCreateInfo vp = VkPipelineViewportStateCreateInfo.create( 0, 1, null, - 1, null); + 1, null, + frame); - VkPipelineDepthStencilStateCreateInfo ds = VkPipelineDepthStencilStateCreateInfo.create(frame, + VkPipelineDepthStencilStateCreateInfo ds = VkPipelineDepthStencilStateCreateInfo.create( 0, VK_TRUE, VK_TRUE, @@ -661,7 +682,8 @@ public class TestSDF { VK_FALSE, VK_FALSE, 0.0f, - 0.0f); + 0.0f, + frame); VkStencilOpState back = ds.getBack(); back.setFailOp(VK_STENCIL_OP_KEEP); @@ -682,42 +704,42 @@ public class TestSDF { front.setDepthFailOp(VK_STENCIL_OP_KEEP); front.setWriteMask(0); - VkPipelineMultisampleStateCreateInfo ms = VkPipelineMultisampleStateCreateInfo.create(frame, + VkPipelineMultisampleStateCreateInfo ms = VkPipelineMultisampleStateCreateInfo.create( 0, NUM_SAMPLES, 0, //.sampleShadingEnable = VK_FALSE, 0.0f, null, 0, //.alphaToCoverageEnable = VK_FALSE, - 0 //.alphaToOneEnable = VK_FALSE, + 0, //.alphaToOneEnable = VK_FALSE, + frame ); - VkShaderModuleCreateInfo vsInfo = VkShaderModuleCreateInfo.create(frame, + VkShaderModuleCreateInfo vsInfo = VkShaderModuleCreateInfo.create( 0, sdf_vs.length() * 4, - sdf_vs); - VkShaderModuleCreateInfo fsInfo = VkShaderModuleCreateInfo.create(frame, + sdf_vs, + frame); + VkShaderModuleCreateInfo fsInfo = VkShaderModuleCreateInfo.create( 0, sdf_fs.length() * 4, - sdf_fs); + sdf_fs, + frame); shader.setAtIndex(0, device.vkCreateShaderModule(vsInfo, scope)); shader.setAtIndex(1, device.vkCreateShaderModule(fsInfo, scope)); VkPipelineShaderStageCreateInfo shaderStages = VkPipelineShaderStageCreateInfo.createArray(2, (SegmentAllocator)scope); - // FIXME: createArray should initialise this - shaderStages.setSType(VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO); shaderStages.setStage(VK_SHADER_STAGE_VERTEX_BIT); shaderStages.setName("main", (SegmentAllocator)scope); shaderStages.setModule(shader.get(0)); - shaderStages.setSTypeAtIndex(1, VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO); shaderStages.setStageAtIndex(1, VK_SHADER_STAGE_FRAGMENT_BIT); shaderStages.setNameAtIndex(1, "main", (SegmentAllocator)scope); shaderStages.setModuleAtIndex(1, shader.get(1)); - VkGraphicsPipelineCreateInfo pipeline = VkGraphicsPipelineCreateInfo.create(frame, + VkGraphicsPipelineCreateInfo pipeline = VkGraphicsPipelineCreateInfo.create( 0, //2, shaderStages, shaderStages, @@ -734,14 +756,15 @@ public class TestSDF { render_pass, 0, null, - 0); + 0, + frame); res = device.vkCreateGraphicsPipelines(null, 1, pipeline, this.pipeline); - VkSemaphoreCreateInfo seminfo = VkSemaphoreCreateInfo.create(frame, 0); + VkSemaphoreCreateInfo seminfo = VkSemaphoreCreateInfo.create(0, frame); chainSemaphore = device.vkCreateSemaphore(seminfo, scope); - VkFenceCreateInfo fenceInfo = VkFenceCreateInfo.create(frame, 0); + VkFenceCreateInfo fenceInfo = VkFenceCreateInfo.create(0, frame); drawFence = device.vkCreateFence(fenceInfo, scope); } } @@ -749,9 +772,10 @@ public class TestSDF { void execute_begin_command_buffer() throws Exception { /* DEPENDS on init_command() */ try ( Frame frame = Frame.frame()) { - VkCommandBufferBeginInfo cmd_buf_info = VkCommandBufferBeginInfo.create(frame, + VkCommandBufferBeginInfo cmd_buf_info = VkCommandBufferBeginInfo.create( 0, - null); + null, + frame); cmd.getAtIndex(0).vkBeginCommandBuffer(cmd_buf_info); } @@ -770,15 +794,16 @@ public class TestSDF { /* FIXME: frame shoudl provide or take explicit scope */ try ( ResourceScope scope = ResourceScope.newConfinedScope(); Frame frame = Frame.frame()) { IntArray pipe_stage_flags = IntArray.create(frame, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT); - VkFenceCreateInfo fenceInfo = VkFenceCreateInfo.create(frame, 0); + VkFenceCreateInfo fenceInfo = VkFenceCreateInfo.create(0, frame); HandleArray fences = VkFence.createArray(1, frame); fences.setAtIndex(0, device.vkCreateFence(fenceInfo, scope)); - VkSubmitInfo submit_info = VkSubmitInfo.create(frame, + VkSubmitInfo submit_info = VkSubmitInfo.create( 1, null, pipe_stage_flags, cmd, - null); + null, + frame); graphics_queue.vkQueueSubmit(1, submit_info, drawFence); @@ -793,8 +818,9 @@ public class TestSDF { void cmd_viewport() { try ( Frame frame = Frame.frame()) { VkCommandBuffer cmd = this.cmd.getAtIndex(0); - VkViewport viewport = VkViewport.create(frame, - 0, 0, width, height, 0.0f, 1.0f); + VkViewport viewport = VkViewport.create( + 0, 0, width, height, 0.0f, 1.0f, + frame); cmd.vkCmdSetViewport(0, 1, viewport); } } @@ -824,24 +850,19 @@ public class TestSDF { LongArray offsets = LongArray.createArray(1, frame); VkClearValue clear_values = VkClearValue.createArray(2, frame); - FloatArray col = clear_values.getColor().getFloat32(); - col.setAtIndex(0, 0.2f); - col.setAtIndex(1, 0.2f); - col.setAtIndex(2, 0.2f); - col.setAtIndex(3, 0.2f); + clear_values.getColor().setFloat32(0.2f, 0.2f, 0.2f, 0.2f); VkClearDepthStencilValue depthStencil = clear_values.getAtIndex(1).getDepthStencil(); depthStencil.setDepth(1.0f); depthStencil.setStencil(0); System.out.printf("render framebuffer[%d] = %s\n", chainIndex, framebuffers.getAtIndex(chainIndex)); - VkRenderPassBeginInfo rp_begin = VkRenderPassBeginInfo.create(frame, + VkRenderPassBeginInfo rp_begin = VkRenderPassBeginInfo.create( render_pass, framebuffers.getAtIndex(chainIndex), - clear_values); - VkExtent2D extent = rp_begin.getRenderArea().getExtent(); - extent.setWidth(width); - extent.setHeight(height); + 0, 0, width, height, + clear_values, + frame); cmd.vkCmdBeginRenderPass(rp_begin, VK_SUBPASS_CONTENTS_INLINE); @@ -862,10 +883,11 @@ public class TestSDF { semaphores.setAtIndex(0, chainSemaphore); - VkSubmitInfo submit_info = VkSubmitInfo.create(frame, + VkSubmitInfo submit_info = VkSubmitInfo.create( 1, semaphores, pipe_stage_flags, this.cmd, - null); + null, + frame); HandleArray fences = VkFence.createArray(1, frame); @@ -884,12 +906,13 @@ public class TestSDF { // Now present the image in the window HandleArray chains = VkSwapchainKHR.createArray(1, frame); chains.setAtIndex(0, chain); - VkPresentInfoKHR present = VkPresentInfoKHR.create(frame, + VkPresentInfoKHR present = VkPresentInfoKHR.create( null, 1, chains, chainIndices, - null); + null, + frame); present_queue.vkQueuePresentKHR(present); } @@ -905,21 +928,23 @@ public class TestSDF { BufferMemory init_buffer(long dataSize, int usage, int properties, MemorySegment init) throws Exception { try ( Frame frame = Frame.frame()) { VkMemoryRequirements req = VkMemoryRequirements.create(frame); - VkBufferCreateInfo buf_info = VkBufferCreateInfo.create(frame, + VkBufferCreateInfo buf_info = VkBufferCreateInfo.create( 0, dataSize, usage, VK_SHARING_MODE_EXCLUSIVE, //0, - null); + null, + frame); VkBuffer buffer = device.vkCreateBuffer(buf_info, scope); device.vkGetBufferMemoryRequirements(buffer, req); - VkMemoryAllocateInfo alloc = VkMemoryAllocateInfo.create(frame, + VkMemoryAllocateInfo alloc = VkMemoryAllocateInfo.create( req.getSize(), - find_memory_type(memory_properties, req.getMemoryTypeBits(), properties)); + find_memory_type(memory_properties, req.getMemoryTypeBits(), properties), + frame); VkDeviceMemory memory = device.vkAllocateMemory(alloc, scope); diff --git a/src/notzed.vulkan/gen/generate-vulkan b/src/notzed.vulkan/gen/generate-vulkan index 238797e..73e2107 100755 --- a/src/notzed.vulkan/gen/generate-vulkan +++ b/src/notzed.vulkan/gen/generate-vulkan @@ -38,6 +38,20 @@ my $enumInfo = { }, }; +my %primitiveMap = ( + 'char' => 'byte', + 'uint8_t' => 'byte', + 'uint16_t' => 'short', + 'int32_t' => 'int', + 'uint32_t' => 'int', + 'int' => 'int', + 'int64_t' => 'long', + 'uint64_t' => 'long', + 'size_t' => 'long', + 'float' => 'float', + 'double' => 'double', +); + # ###################################################################### # my $sys = {}; @@ -523,6 +537,8 @@ sub loadTypes { } elsif ($o =~ m/^template=(.*)/) { die "No template $o" if !defined($templates->{$1}); $c->{template} = $1; + } elsif ($o eq 'expand') { + $c->{expand} = 1; } elsif ($o eq 'ignore') { $c->{ignore} = 1; } @@ -749,6 +765,11 @@ sub analyseFields { } } + if ($s->{category} eq 'struct') { + my $mover = $structTypes->{overrides}->{$m->{baseType}}; + $type .= "-expand" if $nstar == 0 && $mover->{expand}; + } + # an array type with a length if ($nstar > 0 && $m->{len}) { if ($s->{category} =~ m/struct|union/on) { @@ -999,14 +1020,16 @@ sub formatStruct { if ($setall) { if ($s->{category} eq 'struct') { $info->{create}->{create} = { - 'setall-arg' => [ 'SegmentAllocator alloc$' ], + 'setall-arg' => [], setall => [], + setallat => [], }; } elsif ($s->{category} eq 'union') { foreach my $m (@{$s->{items}}) { $info->{create}->{"create$m->{Name}"} = { - 'setall-arg' => [ 'SegmentAllocator alloc$' ], + 'setall-arg' => [], setall => [], + setallat => [], }; } } else { @@ -1017,10 +1040,12 @@ sub formatStruct { # Collect all fields foreach my $m (@{$s->{items}}) { my $nstar = $m->{deref} =~ tr/*/*/; - my $deref = defined($override->{$m->{name}}) && defined($override->{$m->{name}}->{type}) ? $override->{$m->{name}}->{type} : $m->{deref}; + my $mover = $override->{$m->{name}}; + my $deref = defined($mover->{type}) ? $mover->{type} : $m->{deref}; my $type = $types->{$deref}; die "No type $deref ".Dumper($m, $s) if !$type; + die Dumper($mover, $type) if $mover->{accessor}; if ($type->{accessor}) { my $v = buildVars($s, $m, $type); @@ -1035,6 +1060,7 @@ sub formatStruct { my $create = $s->{category} eq 'struct' ? $info->{create}->{create} : $info->{create}->{"create$m->{Name}"}; formatAccessorIf($s, $m, $create, $type, 'setall-arg', $v); formatAccessorIf($s, $m, $create, $type, 'setall', $v); + formatAccessorIf($s, $m, $create, $type, 'setallat', $v); } } @@ -1071,17 +1097,21 @@ sub formatStruct { foreach my $k (keys %{$template->{insert}}) { my $t = $template->{insert}->{$k}; - if ($k eq 'create-all') { + die if (!defined($t)); + + if ($k eq 'create-all' || $k eq 'set-all' || $k eq 'setat-all') { if ($setall) { foreach my $kk (keys %{$info->{create}}) { my $create = $info->{create}->{$kk}; - if ($#{$create->{'setall-arg'}} > 0) { + if ($#{$create->{'setall-arg'}} >= 0) { my $v = { create => $kk, + set => $kk =~ s/create/set/r, Name => $s->{Name}, 'java-setall-arguments' => join (', ', @{$create->{'setall-arg'}}), 'java-setall' => join ("\n\t\t", @{$create->{setall}}), + 'java-setallat' => join ("\n\t\t", @{$create->{setallat}}), }; push @createAll, code::formatTemplateStream($t, $v); } @@ -1093,7 +1123,7 @@ sub formatStruct { } $v->{'create-all'} = join("\n", @createAll) if $setall; - #die Dumper($info) if $s->{name} eq 'VkMemoryOpaqueCaptureAddressAllocateInfo'; + #die Dumper($info, $v) if $s->{name} eq 'VkRect2D'; join("\n", map { '// '.$_ } split(/\n/,Dumper($s)))."\n". code::formatTemplateStream($template->{class}, $v); diff --git a/src/notzed.vulkan/gen/struct-types.api b/src/notzed.vulkan/gen/struct-types.api index 48808ce..75cc6cd 100644 --- a/src/notzed.vulkan/gen/struct-types.api +++ b/src/notzed.vulkan/gen/struct-types.api @@ -79,6 +79,7 @@ code value { #setall-arg {{ {type} {name} }} setall-arg {{ {type} {name} }} setall {{ self$.set{Name}({name}); }} + setallat {{ self$.set{Name}AtIndex(index$, {name}); }} } code value-array { @@ -185,6 +186,84 @@ code inline { }} } +# inline type that we also want to include expanded in initialiser +code inline-expand { + getorset {{ + /* inline {deref} */ + public {type} get{Name}() { + try { + return {java-get}; + } catch (Throwable t) { + throw new RuntimeException(t); + } + } + }} + getorsetat {{ + /* inline {deref} */ + public {type} get{Name}AtIndex(long i$) { + try { + return {java-getat}; + } catch (Throwable t) { + throw new RuntimeException(t); + } + } + }} + setall-arg eval {{ + my @list; + return 0 if $m->{len1}; + foreach my $a (@{$api->{data}->{$m->{baseType}}->{items}}) { + my $name = "$m->{name}\$$a->{name}"; + if ($primitiveMap{$a->{baseType}}) { + push @list, "$primitiveMap{$a->{baseType}} $name"; + } else { + my $as = $api->{data}->{$a->{baseType}}; + foreach my $aa (@{$as->{items}}) { + push @list, "$primitiveMap{$aa->{baseType}} $name\$$aa->{name}"; + } + } + } + join ', ', @list; + }} + setall eval {{ + my @list; + return 0 if $m->{len1}; + foreach my $a (@{$api->{data}->{$m->{baseType}}->{items}}) { + my $pt = $primitiveMap{$a->{baseType}}; + if ($pt) { + push @list, 'self$.segment.set(Memory.'.uc($pt).', ' + .(($m->{bitOffset} + $a->{bitOffset})/8).", $m->{name}\$$a->{name}".');'; + } else { + my $as = $api->{data}->{$a->{baseType}}; + foreach my $aa (@{$as->{items}}) { + $pt = $primitiveMap{$aa->{baseType}}; + push @list, 'self$.segment.set(Memory.'.uc($pt).', ' + .(($m->{bitOffset} + $aa->{bitOffset} + $a->{bitOffset})/8).", $m->{name}\$$a->{name}\$$aa->{name}".');'; + } + } + } + join "\n", @list; + }} + setallat eval {{ + my @list; + return 0 if $m->{len1}; + foreach my $a (@{$api->{data}->{$m->{baseType}}->{items}}) { + my $pt = $primitiveMap{$a->{baseType}}; + if ($pt) { + push @list, 'self$.segment.set(Memory.'.uc($pt).', index$ * '.($s->{bitSize} / 8).' + ' + .(($m->{bitOffset} + $a->{bitOffset})/8).", $m->{name}\$$a->{name}".');'; + } else { + my $as = $api->{data}->{$a->{baseType}}; + foreach my $aa (@{$as->{items}}) { + $pt = $primitiveMap{$aa->{baseType}}; + push @list, 'self$.segment.set(Memory.'.uc($pt).', index$ * '.($s->{bitSize} / 8).' + ' + .(($m->{bitOffset} + $aa->{bitOffset} + $a->{bitOffset})/8).", $m->{name}\$$a->{name}\$$aa->{name}".');'; + } + } + } + join "\n", @list; + }} +} + # value with a SegmentAllocator passed to set() code value-alloc value { set {{ @@ -414,7 +493,7 @@ code struct { } }} create-all {{ - public static {Name} {create}({java-setall-arguments}) { + public static {Name} {create}({java-setall-arguments}, SegmentAllocator alloc$) { {Name} self$ = create(alloc$); {java-setall} @@ -423,12 +502,19 @@ code struct { } }} set-all {{ - public void init({java-setall-arguments}) { + public void {set}({java-setall-arguments}) { {Name} self$ = this; {java-setall} } }} + setat-all {{ + public void {set}AtIndex(long index$, {java-setall-arguments}) { + {Name} self$ = this; + + {java-setallat} + } + }} array {{ static {Name} createArray(MemoryAddress addr, long length, ResourceScope scope) { return create(MemorySegment.ofAddress(addr, length * LAYOUT.byteSize(), scope)); @@ -607,6 +693,59 @@ code struct-readwrite-array insert=struct:header,struct:create-all,struct:array }} } +# read-write with a 'set' method for all members +code struct-readwrite-all insert=struct:header,struct:create-all,struct:set-all + fields=init,get,set,getorset,handle,java-setall { + class {{ + // template: struct-readwrite-all:class + package {package}; + import jdk.incubator.foreign.*; + import java.lang.invoke.*; + import au.notzed.nativez.*; + + public class {Name} implements Pointer { + {header} + + {create-all} + + {get} + {set} + {getorset} + + {handle} + } + }} +} + +code struct-readwrite-array-all insert=struct:header,struct:create-all,struct:array,struct:set-all,struct:setat-all + fields=init,init-array,get,getat,set,setat,setallat,getorset,getorsetat,handle,handleat,java-setall,java-setallat { + class {{ + // template: struct-readwrite-array-all:class + package {package}; + import jdk.incubator.foreign.*; + import java.lang.invoke.*; + import au.notzed.nativez.*; + + public class {Name} implements Pointer,Array<{Name}> { + {header} + {array} + + {create-all} + + {get} + {set} + {getorset} + + {getat} + {setat} + {getorsetat} + + {handle} + {handleat} + } + }} +} + # ###################################################################### # # Basic value-based accessor @@ -741,6 +880,8 @@ type struct[] inline-array { layout {{ MemoryLayout.sequenceLayout({len1}, {baseType}.LAYOUT) }} } +type struct-expand[] struct[] accessor=inline-expand; + type float[][] value-array2d { type {{ FloatArray }} typei {{ float }} @@ -881,6 +1022,11 @@ type struct inline { layout {{ {baseType}.LAYOUT }} } +type struct-expand inline accessor=inline-expand { + type {{ {baseType} }} + layout {{ {baseType}.LAYOUT }} +} + type struct* pointer { type {{ {baseType} }} java-get {{ {baseType}.create({native-get}, this.segment.scope()) }} @@ -917,12 +1063,19 @@ override structs { VkAllocationCallbacks ignore; - # We want 'set(all fields) for these types - #VkOffset2D template=struct-readwrite-all; - #VkOffset3D template=struct-readwrite-all-array; - #VkExtent2D template=struct-readwrite-all; - #VkExtent3D template=struct-readwrite-all; - #VkRect2D template=struct-readwrite-all; + # We want 'set(all fields) for these types and to include them expanded if inline + VkOffset2D expand template=struct-readwrite-array-all; + VkOffset3D expand template=struct-readwrite-array-all; + VkExtent2D expand template=struct-readwrite-all; + VkExtent3D expand template=struct-readwrite-all; + VkRect2D expand template=struct-readwrite-array-all; + + VkStencilOpState template=struct-readwrite-all; + VkComponentMapping template=struct-readwrite-all; + VkImageSubresourceRange template=struct-readwrite-all; + + VkClearColorValue expand template=struct-readwrite-all; + VkClearDepthStencilValue expand template=struct-readwrite-all; # Override default read/write VkDebugUtilsMessengerCallbackDataEXT template=struct-readonly; diff --git a/src/notzed.vulkan/gen/vulkan.pm b/src/notzed.vulkan/gen/vulkan.pm index 795b3b8..e405e8e 100644 --- a/src/notzed.vulkan/gen/vulkan.pm +++ b/src/notzed.vulkan/gen/vulkan.pm @@ -261,9 +261,6 @@ my $typeInfo = { # 'VkFlags64' => { bitSize => 64, bitAlign => 64 }, }; -# fuck how can i parameterise this shit? -# ?create a 'deref' thing that all these things can work from? -# this should probably do it too sub memberSize { my $vk = shift; my $api = shift; -- 2.39.2