Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Makefile
- # Makefile for cheako-vulkan
- # Include libvulkan.so
- LDLIBS = -lvulkan
- # Include debug symbols and warn on all
- CFLAGS = -g -Wall
- # Our single executable
- OBJS = vulkan_test
- all: $(OBJS)
- clean:
- rm -f $(OBJS)
- # valgrind discovers bugs, google it.
- test: clean all
- valgrind ./vulkan_test
- .PHONY: all clean test
- */
- #include <stdlib.h>
- #include <vulkan/vulkan.h>
- #include <assert.h>
- VkInstance instance = 0;
- VkPhysicalDevice gpu = 0;
- uint32_t graphics_family_index = -1;
- VkDevice device = 0;
- int
- main (int argc, char *argv[])
- {
- VkResult err;
- VkApplicationInfo application_info;
- static const VkApplicationInfo EmptyVkApplicationInfo;
- application_info = EmptyVkApplicationInfo;
- application_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
- application_info.apiVersion = VK_MAKE_VERSION(1, 0, 39);
- application_info.applicationVersion = VK_MAKE_VERSION(0, 0, 1);
- application_info.pApplicationName = "Cheako Vulkan Test 2";
- VkInstanceCreateInfo instance_create_info;
- static const VkInstanceCreateInfo EmptyVkInstanceCreateInfo;
- instance_create_info = EmptyVkInstanceCreateInfo;
- instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
- instance_create_info.pApplicationInfo = &application_info;
- err = vkCreateInstance (&instance_create_info, NULL, &instance);
- assert((err == VK_SUCCESS) && "vkCreateInstance: failed.");
- {
- uint32_t gpu_count = 1;
- /* TODO: This just selects first GPU. */
- vkEnumeratePhysicalDevices (instance, &gpu_count, &gpu);
- }
- {
- /* TODO: This only supports up to 10 families. */
- uint32_t family_count = 10;
- VkQueueFamilyProperties family_property_list[10];
- vkGetPhysicalDeviceQueueFamilyProperties (gpu, &family_count,
- family_property_list);
- for (uint32_t i = 0; i < family_count; ++i)
- {
- if (family_property_list[i].queueFlags & VK_QUEUE_GRAPHICS_BIT)
- graphics_family_index = i;
- }
- assert(
- (graphics_family_index != -1)
- && "Vulkan ERROR: Usable queue family not found.");
- }
- static const float queue_priorities[1] =
- { 1.0f };
- VkDeviceQueueCreateInfo device_queue_create_info;
- static const VkDeviceQueueCreateInfo EmptyVkDeviceQueueCreateInfo;
- device_queue_create_info = EmptyVkDeviceQueueCreateInfo;
- device_queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
- device_queue_create_info.queueFamilyIndex = graphics_family_index;
- device_queue_create_info.queueCount = 1;
- device_queue_create_info.pQueuePriorities = queue_priorities;
- VkDeviceCreateInfo device_create_info;
- static const VkDeviceCreateInfo EmptyVkDeviceCreateInfo;
- device_create_info = EmptyVkDeviceCreateInfo;
- device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
- device_create_info.queueCreateInfoCount = 1;
- device_create_info.pQueueCreateInfos = &device_queue_create_info;
- vkCreateDevice (gpu, &device_create_info, NULL, &device);
- /* Clean up */
- vkDestroyDevice (device, NULL);
- device = 0;
- vkDestroyInstance (instance, NULL);
- instance = 0;
- exit (0);
- }
- /* Results
- cheako@debian:~/src/github/cheako-vulkan$ make test
- rm -f vulkan_test
- cc -g -Wall vulkan_test.c -lvulkan -o vulkan_test
- valgrind ./vulkan_test
- ==1540== Memcheck, a memory error detector
- ==1540== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
- ==1540== Using Valgrind-3.12.0.SVN and LibVEX; rerun with -h for copyright info
- ==1540== Command: ./vulkan_test
- ==1540==
- ==1540== Invalid read of size 4
- ==1540== at 0x48789E3: vkEnumeratePhysicalDevices (in /usr/lib/i386-linux-gnu/libvulkan.so.1.0.39)
- ==1540== by 0x108935: main (vulkan_test.c:59)
- ==1540== Address 0x0 is not stack'd, malloc'd or (recently) free'd
- ==1540==
- ==1540==
- ==1540== Process terminating with default action of signal 11 (SIGSEGV)
- ==1540== Access not within mapped region at address 0x0
- ==1540== at 0x48789E3: vkEnumeratePhysicalDevices (in /usr/lib/i386-linux-gnu/libvulkan.so.1.0.39)
- ==1540== by 0x108935: main (vulkan_test.c:59)
- ==1540== If you believe this happened as a result of a stack
- ==1540== overflow in your program's main thread (unlikely but
- ==1540== possible), you can try to increase the size of the
- ==1540== main thread stack using the --main-stacksize= flag.
- ==1540== The main thread stack size used in this run was 8388608.
- ==1540==
- ==1540== HEAP SUMMARY:
- ==1540== in use at exit: 1,424,850 bytes in 5,199 blocks
- ==1540== total heap usage: 5,422 allocs, 223 frees, 1,683,368 bytes allocated
- ==1540==
- ==1540== LEAK SUMMARY:
- ==1540== definitely lost: 0 bytes in 0 blocks
- ==1540== indirectly lost: 0 bytes in 0 blocks
- ==1540== possibly lost: 995,018 bytes in 3,971 blocks
- ==1540== still reachable: 429,832 bytes in 1,228 blocks
- ==1540== suppressed: 0 bytes in 0 blocks
- ==1540== Rerun with --leak-check=full to see details of leaked memory
- ==1540==
- ==1540== For counts of detected and suppressed errors, rerun with: -v
- ==1540== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
- Makefile:19: recipe for target 'test' failed
- make: *** [test] Segmentation fault
- cheako@debian:~/src/github/cheako-vulkan$
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement