Advertisement
cheako

Vulkan array bug.

Feb 6th, 2018
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.16 KB | None | 0 0
  1. /* Makefile
  2. # Makefile for cheako-vulkan
  3.  
  4. # Include libvulkan.so
  5. LDLIBS = -lvulkan
  6.  
  7. # Include debug symbols and warn on all
  8. CFLAGS = -g -Wall
  9.  
  10. # Our single executable
  11. OBJS = vulkan_test
  12.  
  13. all: $(OBJS)
  14.  
  15. clean:
  16.     rm -f $(OBJS)
  17.  
  18. # valgrind discovers bugs, google it.
  19. test: clean all
  20.     valgrind ./vulkan_test
  21.  
  22. .PHONY: all clean test
  23.  
  24.  */
  25.  
  26. #include <stdlib.h>
  27. #include <vulkan/vulkan.h>
  28. #include <assert.h>
  29.  
  30. VkInstance instance = 0;
  31. VkPhysicalDevice gpu = 0;
  32. uint32_t graphics_family_index = -1;
  33. VkDevice device = 0;
  34.  
  35. int
  36. main (int argc, char *argv[])
  37. {
  38.   VkResult err;
  39.   VkApplicationInfo application_info;
  40.   static const VkApplicationInfo EmptyVkApplicationInfo;
  41.   application_info = EmptyVkApplicationInfo;
  42.   application_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
  43.   application_info.apiVersion = VK_MAKE_VERSION(1, 0, 39);
  44.   application_info.applicationVersion = VK_MAKE_VERSION(0, 0, 1);
  45.   application_info.pApplicationName = "Cheako Vulkan Test 2";
  46.  
  47.   VkInstanceCreateInfo instance_create_info;
  48.   static const VkInstanceCreateInfo EmptyVkInstanceCreateInfo;
  49.   instance_create_info = EmptyVkInstanceCreateInfo;
  50.   instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
  51.   instance_create_info.pApplicationInfo = &application_info;
  52.  
  53.   err = vkCreateInstance (&instance_create_info, NULL, &instance);
  54.   assert((err == VK_SUCCESS) && "vkCreateInstance: failed.");
  55.  
  56.     {
  57.       uint32_t gpu_count = 1;
  58.       /* TODO: This just selects first GPU. */
  59.       vkEnumeratePhysicalDevices (instance, &gpu_count, &gpu);
  60.     }
  61.     {
  62.       /* TODO: This only supports up to 10 families. */
  63.       uint32_t family_count = 10;
  64.       VkQueueFamilyProperties family_property_list[10];
  65.       vkGetPhysicalDeviceQueueFamilyProperties (gpu, &family_count,
  66.                         family_property_list);
  67.       for (uint32_t i = 0; i < family_count; ++i)
  68.     {
  69.       if (family_property_list[i].queueFlags & VK_QUEUE_GRAPHICS_BIT)
  70.         graphics_family_index = i;
  71.     }
  72.       assert(
  73.       (graphics_family_index != -1)
  74.           && "Vulkan ERROR: Usable queue family not found.");
  75.     }
  76.  
  77.   static const float queue_priorities[1] =
  78.     { 1.0f };
  79.   VkDeviceQueueCreateInfo device_queue_create_info;
  80.   static const VkDeviceQueueCreateInfo EmptyVkDeviceQueueCreateInfo;
  81.   device_queue_create_info = EmptyVkDeviceQueueCreateInfo;
  82.   device_queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
  83.   device_queue_create_info.queueFamilyIndex = graphics_family_index;
  84.   device_queue_create_info.queueCount = 1;
  85.   device_queue_create_info.pQueuePriorities = queue_priorities;
  86.  
  87.   VkDeviceCreateInfo device_create_info;
  88.   static const VkDeviceCreateInfo EmptyVkDeviceCreateInfo;
  89.   device_create_info = EmptyVkDeviceCreateInfo;
  90.   device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
  91.   device_create_info.queueCreateInfoCount = 1;
  92.   device_create_info.pQueueCreateInfos = &device_queue_create_info;
  93.  
  94.   vkCreateDevice (gpu, &device_create_info, NULL, &device);
  95.  
  96.   /* Clean up */
  97.   vkDestroyDevice (device, NULL);
  98.   device = 0;
  99.   vkDestroyInstance (instance, NULL);
  100.   instance = 0;
  101.   exit (0);
  102. }
  103.  
  104. /* Results
  105. cheako@debian:~/src/github/cheako-vulkan$ make test
  106. rm -f vulkan_test
  107. cc -g -Wall    vulkan_test.c  -lvulkan -o vulkan_test
  108. valgrind ./vulkan_test
  109. ==1540== Memcheck, a memory error detector
  110. ==1540== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
  111. ==1540== Using Valgrind-3.12.0.SVN and LibVEX; rerun with -h for copyright info
  112. ==1540== Command: ./vulkan_test
  113. ==1540==
  114. ==1540== Invalid read of size 4
  115. ==1540==    at 0x48789E3: vkEnumeratePhysicalDevices (in /usr/lib/i386-linux-gnu/libvulkan.so.1.0.39)
  116. ==1540==    by 0x108935: main (vulkan_test.c:59)
  117. ==1540==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
  118. ==1540==
  119. ==1540==
  120. ==1540== Process terminating with default action of signal 11 (SIGSEGV)
  121. ==1540==  Access not within mapped region at address 0x0
  122. ==1540==    at 0x48789E3: vkEnumeratePhysicalDevices (in /usr/lib/i386-linux-gnu/libvulkan.so.1.0.39)
  123. ==1540==    by 0x108935: main (vulkan_test.c:59)
  124. ==1540==  If you believe this happened as a result of a stack
  125. ==1540==  overflow in your program's main thread (unlikely but
  126. ==1540==  possible), you can try to increase the size of the
  127. ==1540==  main thread stack using the --main-stacksize= flag.
  128. ==1540==  The main thread stack size used in this run was 8388608.
  129. ==1540==
  130. ==1540== HEAP SUMMARY:
  131. ==1540==     in use at exit: 1,424,850 bytes in 5,199 blocks
  132. ==1540==   total heap usage: 5,422 allocs, 223 frees, 1,683,368 bytes allocated
  133. ==1540==
  134. ==1540== LEAK SUMMARY:
  135. ==1540==    definitely lost: 0 bytes in 0 blocks
  136. ==1540==    indirectly lost: 0 bytes in 0 blocks
  137. ==1540==      possibly lost: 995,018 bytes in 3,971 blocks
  138. ==1540==    still reachable: 429,832 bytes in 1,228 blocks
  139. ==1540==         suppressed: 0 bytes in 0 blocks
  140. ==1540== Rerun with --leak-check=full to see details of leaked memory
  141. ==1540==
  142. ==1540== For counts of detected and suppressed errors, rerun with: -v
  143. ==1540== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
  144. Makefile:19: recipe for target 'test' failed
  145. make: *** [test] Segmentation fault
  146. cheako@debian:~/src/github/cheako-vulkan$
  147.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement