github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/bench/call/cgo.go (about)

     1  package call
     2  
     3  import "unsafe"
     4  
     5  /*
     6  #include <stdint.h>
     7  #include <stdlib.h>
     8  
     9  // Vulkan like data structures
    10  
    11  typedef uint32_t VkFlags;
    12  typedef VkFlags  VkDeviceQueueCreateFlags;
    13  typedef uint32_t VkStructureType;
    14  
    15  typedef struct VkDeviceQueueCreateInfo {
    16      VkStructureType             sType;
    17      const void*                 pNext;
    18      VkDeviceQueueCreateFlags    flags;
    19      uint32_t                    queueFamilyIndex;
    20      uint32_t                    queueCount;
    21      const float*                pQueuePriorities;
    22  } VkDeviceQueueCreateInfo;
    23  
    24  typedef struct VkPhysicalDeviceFeatures {
    25      uint32_t bools[56];
    26  } VkPhysicalDeviceFeatures;
    27  
    28  typedef struct VkDeviceCreateInfo {
    29      VkStructureType                    sType;
    30      const void*                        pNext;
    31      VkFlags                            flags;
    32      uint32_t                           queueCreateInfoCount;
    33      const VkDeviceQueueCreateInfo*     pQueueCreateInfos;
    34      uint32_t                           enabledLayerCount;
    35      const char* const*                 ppEnabledLayerNames;
    36      uint32_t                           enabledExtensionCount;
    37      const char* const*                 ppEnabledExtensionNames;
    38      const VkPhysicalDeviceFeatures*    pEnabledFeatures;
    39  } VkDeviceCreateInfo;
    40  
    41  void nop() { }
    42  
    43  int32_t add2(int32_t x, int32_t y) { return x + y; }
    44  
    45  VkDeviceCreateInfo * createInfo() {
    46  	VkDeviceCreateInfo *info = malloc(sizeof(VkDeviceCreateInfo));
    47  	VkDeviceQueueCreateInfo *queue = malloc(sizeof(VkDeviceQueueCreateInfo));
    48  	info->pQueueCreateInfos = queue;
    49  	return info;
    50  }
    51  
    52  void create1(VkDeviceCreateInfo *x0) {}
    53  void create2(VkDeviceCreateInfo *x0, VkDeviceCreateInfo *x1) {}
    54  void create4(VkDeviceCreateInfo *x0, VkDeviceCreateInfo *x1, VkDeviceCreateInfo *x2, VkDeviceCreateInfo *x3) {}
    55  */
    56  import "C"
    57  
    58  //go:noinline
    59  func Nop() {}
    60  
    61  func CNop() { C.nop() }
    62  
    63  func NewDeviceCreateInfo() *C.VkDeviceCreateInfo {
    64  	return C.createInfo()
    65  }
    66  
    67  func Release(xs ...*C.VkDeviceCreateInfo) {
    68  	for _, x := range xs {
    69  		C.free(unsafe.Pointer(x))
    70  	}
    71  }
    72  
    73  //go:noinline
    74  func Add2(x, y int32) int32 { return x + y }
    75  
    76  func CAdd2(x, y int32) int32 { return int32(C.add2(C.int32_t(x), C.int32_t(y))) }
    77  
    78  //go:noinline
    79  func Args1(x0 *C.VkDeviceCreateInfo) {}
    80  
    81  //go:noinline
    82  func Args2(x0, x1 *C.VkDeviceCreateInfo) {}
    83  
    84  //go:noinline
    85  func Args4(x0, x1, x2, x3 *C.VkDeviceCreateInfo) {}
    86  
    87  func CArgs1(x0 *C.VkDeviceCreateInfo) {
    88  	C.create1(x0)
    89  }
    90  
    91  func CArgs2(x0, x1 *C.VkDeviceCreateInfo) {
    92  	C.create2(x0, x1)
    93  }
    94  
    95  func CArgs4(x0, x1, x2, x3 *C.VkDeviceCreateInfo) {
    96  	C.create4(x0, x1, x2, x3)
    97  }