Try to auto-detect some simple-type query functions.
authorNot Zed <notzed@gmail.com>
Sun, 8 May 2022 07:18:39 +0000 (16:48 +0930)
committerNot Zed <notzed@gmail.com>
Sun, 8 May 2022 07:18:39 +0000 (16:48 +0930)
src/notzed.vulkan.test/classes/vulkan/test/TestCube.java
src/notzed.vulkan.test/classes/vulkan/test/TestSDF.java
src/notzed.vulkan/gen/command-types.api
src/notzed.vulkan/gen/generate-vulkan

index 9f022e6..c7be005 100644 (file)
@@ -195,10 +195,7 @@ public class TestCube {
                                famprops = dev.vkGetPhysicalDeviceQueueFamilyProperties(frame);
 
                                for (int j = 0; j < famprops.length(); j++) {
-                                       boolean present;
-
-                                       dev.vkGetPhysicalDeviceSurfaceSupportKHR(j, surface, present$h);
-                                       present = present$h.get(0) != 0;
+                                       boolean present = dev.vkGetPhysicalDeviceSurfaceSupportKHR(j, surface);
 
                                        if (present && present_queue == -1)
                                                present_queue = j;
@@ -408,19 +405,10 @@ public class TestCube {
                                VK_IMAGE_VIEW_TYPE_2D,
                                VK_FORMAT_D16_UNORM,
                                frame);
-
-                       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_DEPTH_BIT);
-                       subresourceRange.setLevelCount(1);
-                       subresourceRange.setLayerCount(1);
+                       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);
 
                        depthView = device.vkCreateImageView(viewinfo, scope);
-
                        depthFormat = format;
                }
        }
index f72dd12..c60f54a 100644 (file)
@@ -196,10 +196,7 @@ public class TestSDF {
                                famprops = dev.vkGetPhysicalDeviceQueueFamilyProperties(frame);
 
                                for (int j = 0; j < famprops.length(); j++) {
-                                       boolean present;
-
-                                       dev.vkGetPhysicalDeviceSurfaceSupportKHR(j, surface, present$h);
-                                       present = present$h.get(0) != 0;
+                                       boolean present = dev.vkGetPhysicalDeviceSurfaceSupportKHR(j, surface);
 
                                        if (present && present_queue == -1)
                                                present_queue = j;
@@ -409,19 +406,10 @@ public class TestSDF {
                                VK_IMAGE_VIEW_TYPE_2D,
                                VK_FORMAT_D16_UNORM,
                                frame);
-
-                       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_DEPTH_BIT);
-                       subresourceRange.setLevelCount(1);
-                       subresourceRange.setLayerCount(1);
+                       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);
 
                        depthView = device.vkCreateImageView(viewinfo, scope);
-
                        depthFormat = format;
                }
        }
index 3f164f1..3adfe1f 100644 (file)
@@ -538,6 +538,41 @@ type handle*-output handle* need-frame need-scope {
        java-result-return      {{ return result$$; }}
 }
 
+type uint32_t*-output,int*-output uint32_t* need-frame {
+       java-arg        {{ }}
+       invoke-arg      {{ (Addressable){name}.address() }}
+
+       java-result                     {{ int }}
+       native-init                     {{ MemorySegment {name} = frame$.allocate(Memory.INT); }}
+       java-result-assign      {{ int result$$ = {name}.getAtIndex(Memory.INT, 0); }}
+       java-result-return      {{ return result$$; }}
+}
+
+type uint64_t*-output uint64_t* need-frame {
+       java-arg        {{ }}
+       invoke-arg      {{ (Addressable){name}.address() }}
+
+       java-result                     {{ long }}
+       native-init                     {{ MemorySegment {name} = frame$.allocate(Memory.LONG); }}
+       java-result-assign      {{ long result$$ = {name}.getAtIndex(Memory.LONG, 0); }}
+       java-result-return      {{ return result$$; }}
+}
+
+type void*-output handle*-output need-frame {
+       java-arg        {{ }}
+       invoke-arg      {{ (Addressable){name}.address() }}
+
+       java-result                     {{ MemoryAddress }}
+       native-init                     {{ MemorySegment {name} = frame$.allocate(Memory.POINTER); }}
+       java-result-assign      {{ MemoryAddress result$$ = {name}.getAtIndex(Memory.POINTER, 0); }}
+       java-result-return      {{ return result$$; }}
+}
+
+type VkBool32*-output uint32_t*-output {
+       java-result                     {{ boolean }}
+       java-result-return      {{ return result$$ != 0; }}
+}
+
 # for handle constructors of dispatchable types
 type dispatch*-output handle*-output {
        java-result-assign      {{ {baseType} result$$ = {baseType}.create({name}.get(Memory.POINTER, 0), dispatch, scope$); }}
index 5e260a8..02edd41 100755 (executable)
@@ -180,6 +180,19 @@ foreach my $s (values %{$api->{commands}}) {
                }
        }
 
+       # A whole bunch of query functions
+       if ($s->{name} =~ m/^vkGet/ && !($last->{fullType} =~ m/const/n) && !(defined($override->{$last->{name}}) && defined($override->{$last->{name}}->{type}))) {
+               if ($last->{fullType} eq 'VkBool32 *') {
+                       print "output: [$last->{fullType}] [$last->{deref}] $s->{name}\n" if $sys->{verbose};
+                       $override->{$last->{name}}->{type} = 'VkBool32*-output';
+               } elsif ($last->{deref} =~ m/^(int|uint32_t|uint64_t|void)\*$/on) {
+                       print "output: [$last->{fullType}] [$last->{deref}] $s->{name}\n" if $sys->{verbose};
+                       $override->{$last->{name}}->{type} = $last->{deref}."-output";
+               } else {
+                       print "output? [$last->{fullType}] [$last->{deref}] $s->{name}\n" if $sys->{verbose};
+               }
+       }
+
        # other per-item things
        foreach my $m (@{$s->{items}}) {
                my $so = $structTypes->{overrides}->{$m->{baseType}};
@@ -1339,7 +1352,7 @@ sub formatFunctionDescriptor {
                my $deref = defined($override->{$m->{name}}) && defined($override->{$m->{name}}->{type}) ? $override->{$m->{name}}->{type} : $m->{deref};
                my $type = $types->{$deref};
 
-               die "No type found ".Dumper($m, $s, $override) if !$type;
+               die "No type '$deref' found ".Dumper($m, $s, $override) if !$type;
 
                my $v = buildVars($s, $m, $type);