1 # -*- Mode:text; tab-width:4; electric-indent-mode: nil; indent-line-function:insert-tab; -*-
3 # types for structs and unions
5 # ###################################################################### #
7 #accessor=code template
16 public {type} get{Name}() {
22 public void set{Name}({type} {name}) {
27 # FIXME: only handles single element arrays
28 init {{ {name}$VH.set(this.segment, VkConstants.{values}); }}
30 # for complex constructors?
31 setall-arg {{ {type} {name} /* value */ }}
32 setall {{ self$.set{Name}({name}); }}
37 /* value-array {deref} */
38 public {type} get{Name}() {
41 } catch (Throwable t) {
42 throw new RuntimeException(t);
45 public {typei} get{Name}Element(int i$) {
48 public void set{Name}Element(int i$, {typei} {name}) {
56 /* value-array2d {deref} */
57 public {type} get{Name}() {
60 } catch (Throwable t) {
61 throw new RuntimeException(t);
64 public {typei} get{Name}Element(int i$, int j$) {
67 public void set{Name}Element(int i$, int j$, {typei} {name}) {
76 public {type} get{Name}() {
79 } catch (Throwable t) {
80 throw new RuntimeException(t);
86 # value with a SegmentAllocator passed to set()
90 public {type} get{Name}() {
96 public void set{Name}({type} {name}, SegmentAllocator alloc$) {
100 setall-arg {{ {type} {name} }}
101 setall {{ self$.set{Name}({name}, alloc$); }}
104 # implied accessors are ignored in constructors
108 public {type} get{Name}() {
114 public void set{Name}({type} {name}) {
119 # supposed to be handled in set of the target, but ...?
120 setall {{ self$.set{Name}(({type})Memory.length({lengthfor})); }}
123 # ###################################################################### #
127 // template: dispatch:class
129 import jdk.incubator.foreign.*;
130 import java.lang.invoke.*;
131 import au.notzed.nativez.*;
136 {Name}(VkInstance instance$, ResourceScope scope$) {
141 field-init {{ final NativeSymbol {name}$NS; }}
142 init {{ {name}$NS = instance$.vkGetInstanceProcAddr("{name}", scope$); }}
146 # non-dispatchable handle
149 // template: handle:class
151 import jdk.incubator.foreign.*;
152 import java.lang.invoke.*;
153 import au.notzed.nativez.*;
155 public class {name} implements Pointer {
156 final NativeSymbol self;
158 private {name}(MemoryAddress address, ResourceScope scope) {
159 this.self = NativeSymbol.ofAddress("{name}", address, scope);
163 public static {name} create(MemoryAddress address, ResourceScope scope) {
164 return new {name}(address, scope);
167 public static HandleArray<{name}> createArray(long length, SegmentAllocator alloc) {
168 return HandleArray.createArray(1, alloc, {name}::create);
171 public MemoryAddress address() {
172 return self.address();
175 public ResourceScope scope() {
183 code handle-instance {
185 // template: handle-instance:class
187 import jdk.incubator.foreign.*;
188 import java.lang.invoke.*;
189 import au.notzed.nativez.*;
191 public class {name} implements Pointer {
192 final NativeSymbol self;
193 final DispatchInstance dispatch;
195 private {name}(MemoryAddress address, ResourceScope scope) {
196 this.self = NativeSymbol.ofAddress("{name}", address, scope);
197 this.dispatch = new DispatchInstance(this, scope);
201 public static {name} create(MemoryAddress address, ResourceScope scope) {
202 return new {name}(address, scope);
205 public MemoryAddress address() {
206 return self.address();
209 public ResourceScope scope() {
218 # dispatchable handle
219 code handle-dispatch {
221 // template: handle-dispatch:class
223 import jdk.incubator.foreign.*;
224 import java.lang.invoke.*;
225 import au.notzed.nativez.*;
227 public class {name} implements Pointer {
228 final NativeSymbol self;
229 final DispatchInstance dispatch;
231 private {name}(MemoryAddress address, DispatchInstance dispatch, ResourceScope scope) {
232 this.self = NativeSymbol.ofAddress("{name}", address, scope);
233 this.dispatch = dispatch;
237 public static {name} create(MemoryAddress address, DispatchInstance dispatch, ResourceScope scope) {
238 return new {name}(address, dispatch, scope);
241 // TODO: evaluate how scope fits here
242 public static HandleArray<{name}> createArray(long length, SegmentAllocator alloc, DispatchInstance dispatch, ResourceScope scope) {
243 return HandleArray.createArray(1, alloc, (a, s) -> create(a, dispatch, s), scope);
246 public static HandleArray<{name}> createArray(long length, SegmentAllocator alloc, VkInstance instance, ResourceScope scope) {
247 return HandleArray.createArray(1, alloc, (a, s) -> create(a, instance.dispatch, s), scope);
250 public MemoryAddress address() {
251 return self.address();
254 public ResourceScope scope() {
263 # ###################################################################### #
265 # shared struct components
268 public MemorySegment segment;
270 public static final GroupLayout LAYOUT = {layout};
272 private {Name}(MemorySegment segment) {
273 this.segment = segment;
277 public static {Name} create(MemorySegment segment) {
278 return new {Name}(segment);
281 public static {Name} create(MemoryAddress address, ResourceScope scope) {
282 return new {Name}(MemorySegment.ofAddress(address, LAYOUT.byteSize(), scope));
285 public static {Name} create(SegmentAllocator alloc) {
286 return new {Name}(alloc.allocate(LAYOUT));
291 public MemoryAddress address() {
292 return segment.address();
297 public ResourceScope scope() {
298 return segment.scope();
302 public String toString() {
303 return Memory.toString(segment, LAYOUT);
307 public static {Name} {create}({java-setall-arguments}) {
308 {Name} self$ = create(alloc$.allocate(LAYOUT));
316 public void init({java-setall-arguments}) {
323 static {Name} createArray(MemoryAddress addr, long length, ResourceScope scope) {
324 return new {Name}(MemorySegment.ofAddress(addr, length * LAYOUT.byteSize(), scope));
327 public static {Name} createArray(long length, SegmentAllocator alloc) {
328 return new {Name}(alloc.allocateArray(LAYOUT, length));
331 public final static MethodHandle LAYOUT$SH = MemoryLayout.sequenceLayout(LAYOUT).sliceHandle(MemoryLayout.PathElement.sequenceElement());
335 public long length() {
336 return segment.byteSize() / LAYOUT.byteSize();
341 public {Name} getAtIndex(long index$) {
343 return create((MemorySegment)LAYOUT$SH.invokeExact(this.segment, index$));
344 } catch (Throwable t) {
345 throw new RuntimeException(t);
351 # default - writeonly struct
352 code struct-writeonly insert=struct:header,struct:create-all {
354 // template: struct-writeonly:class
356 import jdk.incubator.foreign.*;
357 import java.lang.invoke.*;
358 import au.notzed.nativez.*;
360 public class {Name} implements Pointer {
373 code struct-writeonly-array insert=struct:header,struct:create-all,struct:array {
375 // template: struct-writeonly-array:class
377 import jdk.incubator.foreign.*;
378 import java.lang.invoke.*;
379 import au.notzed.nativez.*;
381 public class {Name} implements Pointer, Array<{Name}> {
395 code struct-readonly insert=struct:header {
397 // template: struct-readonly:class
399 import jdk.incubator.foreign.*;
400 import java.lang.invoke.*;
401 import au.notzed.nativez.*;
403 public class {Name} implements Pointer {
414 code struct-readonly-array insert=struct:header,struct:array {
416 // template: struct-readonly-array:class
418 import jdk.incubator.foreign.*;
419 import java.lang.invoke.*;
420 import au.notzed.nativez.*;
422 public class {Name} implements Pointer, Array<{Name}> {
434 code struct-readwrite insert=struct:header,struct:create-all {
436 // template: struct-readwrite:class
438 import jdk.incubator.foreign.*;
439 import java.lang.invoke.*;
440 import au.notzed.nativez.*;
442 public class {Name} implements Pointer {
456 code struct-readwrite-array insert=struct:header,struct:create-all,struct:array {
458 // template: struct-readwrite-array:class
460 import jdk.incubator.foreign.*;
461 import java.lang.invoke.*;
462 import au.notzed.nativez.*;
464 public class {Name} implements Pointer,Array<{Name}> {
479 # ###################################################################### #
481 # how to arrays? in code?
484 type value accessor=value {
485 java-get {{ ({type}){name}$VH.get(this.segment) }}
486 java-set {{ {name}$VH.set(this.segment, {name}) }}
487 handle {{ final static VarHandle {name}$VH = LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("{name}")); }}
490 type value-array accessor=value-array {
491 native-get {{ (MemorySegment){name}$SH.invokeExact(this.segment) }}
492 java-get {{ {type}.create({native-get}) }}
493 java-geti {{ ({typei}){name}$EH.get(i$) }}
494 java-seti {{ {name}$EH.set(i$, {name}) }}
496 final static MethodHandle {name}$SH = LAYOUT.sliceHandle(MemoryLayout.PathElement.groupElement("{name}"));
497 final static VarHandle {name}$EH = LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("{name}"), MemoryLayout.PathElement.sequenceElement());
501 type value-array2d accessor=value-array2d {
502 native-get {{ (MemorySegment){name}$SH.invokeExact(this.segment) }}
503 java-get {{ {type}.create({native-get}) }}
504 java-geti {{ ({typei}){name}$EH.get(i$, j$) }}
505 java-seti {{ {name}$EH.set(i$, j$, {name}) }}
507 final static MethodHandle {name}$SH = LAYOUT.sliceHandle(MemoryLayout.PathElement.groupElement("{name}"));
508 final static VarHandle {name}$EH = LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("{name}"), MemoryLayout.PathElement.sequenceElement(), MemoryLayout.PathElement.sequenceElement());
512 type inline accessor=inline {
513 native-get {{ (MemorySegment){name}$SH.invokeExact(this.segment) }}
514 java-get {{ {type}.create({native-get}) }}
515 handle {{ final static MethodHandle {name}$SH = LAYOUT.sliceHandle(MemoryLayout.PathElement.groupElement("{name}")); }}
518 type inline-array accessor=inline {
519 # type {{ MemorySegment }}
520 native-get {{ (MemorySegment){name}$SH.invokeExact(this.segment) }}
521 # java-get {{ {native-get} }}
522 java-get {{ {type}.create({native-get}) }}
524 final static MethodHandle {name}$SH = LAYOUT.sliceHandle(MemoryLayout.PathElement.groupElement("{name}"));
528 type uint8_t,char value {
530 layout {{ Memory.BYTE }}
533 type uint16_t value {
535 layout {{ Memory.SHORT }}
538 type uint32_t,int,int32_t value {
540 layout {{ Memory.INT }}
543 type uint64_t,int64_t,size_t value {
545 layout {{ Memory.LONG }}
550 layout {{ Memory.FLOAT }}
555 layout {{ Memory.DOUBLE }}
558 # ###################################################################### #
559 # implied length types
560 type uint64_t-implied,size_t-implied uint64_t accessor=value-implied {
564 type uint32_t-implied uint32_t accessor=value-implied {
567 # ###################################################################### #
569 type uint8_t[],char[] value-array {
571 layout {{ MemoryLayout.sequenceLayout({len1}, Memory.BYTE) }}
575 type uint32_t[],int32_t[] value-array {
577 layout {{ MemoryLayout.sequenceLayout({len1}, Memory.INT) }}
581 type uint64_t[] value-array {
583 layout {{ MemoryLayout.sequenceLayout({len1}, Memory.LONG) }}
587 type float[] value-array {
588 type {{ FloatArray }}
589 layout {{ MemoryLayout.sequenceLayout({len1}, Memory.FLOAT) }}
593 type struct[] inline-array {
594 type {{ {baseType} }}
595 layout {{ MemoryLayout.sequenceLayout({len1}, {baseType}.LAYOUT) }}
598 type float[][] value-array2d {
599 type {{ FloatArray }}
601 layout {{ MemoryLayout.sequenceLayout({len1}, MemoryLayout.sequenceLayout({len2}, Memory.FLOAT)) }}
604 # select=len? or what?
607 layout {{ Memory.POINTER }}
608 type {{ MemoryAddress }}
610 native-get {{ (MemoryAddress){name}$VH.get(this.segment) }}
612 java-get {{ {native-get} }}
613 java-set {{ {name}$VH.set(this.segment, Memory.address({name})) }}
618 type value-pointer pointer {
619 java-get {{ {type}.create((MemoryAddress){name}$VH.get(this.segment), segment.scope()) }}
622 type uint8_t* value-pointer {
626 type uint32_t*,int32_t*,int* value-pointer {
630 type uint64_t* value-pointer {
634 type float* value-pointer {
638 type size_t* value-pointer {
642 type pointer-length pointer {
643 java-get {{ {type}.createArray({native-get}, {length}, this.segment.scope()) }}
646 type void*-length pointer-length {
648 java-get {{ MemorySegment.ofAddress({native-get}, {length}, this.segment.scope()) }}
651 type uint8_t*-length pointer-length {
655 type uint32_t*-length,int32_t*-length pointer-length {
659 type uint64_t*-length pointer-length {
663 type float*-length pointer-length {
667 # special handling for strings, will fail if it isn't
668 type char* pointer accessor=value-alloc {
671 java-get {{ ({native-get}).getUtf8String(0) }}
672 java-set {{ {name}$VH.set(this.segment, alloc$.allocateUtf8String({name}).address()) }}
674 # this just verifies it's a string type
676 if ($v->{len} =~ m/null-terminated/) {
685 type char**-length pointer-length accessor=value-alloc {
688 java-set {{ {name}$VH.set(this.segment, Memory.copyStringArray({name}, alloc$).address()); {set-length} }}
689 java-get {{ Memory.copyStringArray((MemoryAddress){name}$VH.get(this.segment), {length}) }}
692 # if ($v->{len} =~ m/(.*),null-terminated/) {
693 # 'set'.ucfirst($1).'({name}.length)';
695 # die Dumper($v, $s);
701 type uint32_t** pointer {
702 type {{ HandleArray<IntArray> }}
705 type funcpointer pointer {
706 type {{ FunctionPointer<{baseType}> }}
707 typei {{ {baseType} }}
708 java-get {{ {baseType}.downcall({native-get}, this.segment.scope()) }}
711 type void** pointer {
714 type void**-length pointer-length {
718 type handle pointer {
719 type {{ {baseType} }}
720 java-get {{ {type}.create({native-get}, this.segment.scope()) }}
725 type {{ HandleArray<{typei}> }}
726 layout {{ MemoryLayout.sequenceLayout({len1}, Memory.POINTER) }}
727 #java-get {{ HandleArray.create({get}, {typei}::create) }}
729 typei {{ {baseType} }}
732 type handle* pointer {
733 type {{ HandleArray<{typei}> }}
734 typei {{ {baseType} }}
735 java-get {{ HandleArray.create({native-get}, {typei}::create) }}
738 type handle*-length pointer-length {
739 type {{ HandleArray<{baseType}> }}
740 typei {{ {baseType} }}
741 java-get {{ HandleArray.createArray({native-get}, {length}, {typei}::create, this.segment.scope()) }}
742 java-set {{ {name}$VH.set(this.segment, Memory.address({name})); {set-length} }}
746 type {{ {baseType} }}
747 layout {{ {baseType}.LAYOUT }}
751 type struct* pointer {
752 type {{ {baseType} }}
753 java-get {{ {baseType}.create({native-get}, this.segment.scope()) }}
756 type struct*-length pointer-length {
757 type {{ {baseType} }}
758 typei {{ {baseType} }}
761 type struct** pointer {
765 type XID,Window,VisualID uint64_t;
767 type Display* handle {
772 type xcb_window_t uint32_t;
773 type xcb_visualid_t uint32_t;
774 type xcb_connection_t* handle {
779 VkInstance template=handle-instance;
780 VkPhysicalDevice template=handle-dispatch;
781 VkDevice template=handle-dispatch;
782 VkCommandBuffer template=handle-dispatch;
783 VkQueue template=handle-dispatch;
785 VkAllocationCallbacks ignore;
787 #VkQueueFamilyProperties template=struct-readwrite;
789 # Override default read/write
790 VkDebugUtilsMessengerCallbackDataEXT template=struct-readonly;
791 VkDebugUtilsLabelEXT template=struct-readonly-array;
792 VkDebugUtilsObjectNameInfoEXT template=struct-readonly-array;
794 # override default array-length behaviours, some of these are independent of the array pointer
795 VkAccelerationStructureBuildGeometryInfoKHR geometryCount=type:uint32_t;
796 VkDescriptorSetLayoutBinding pImmutableSamplers=type:handle* descriptorCount=type:uint32_t;
797 VkPipelineViewportStateCreateInfo scissorCount=type:uint32_t viewportCount=type:uint32_t;
799 # can't really work out what this is it's a void ** but it stays it's a pointer to uint8_t * in the spec
800 VkCuLaunchInfoNVX pParams=type:pointer pExtras=type:pointer;