Skip to content

Commit

Permalink
vulkan: update hello world example
Browse files Browse the repository at this point in the history
  • Loading branch information
danbev committed Aug 7, 2024
1 parent ab6a53f commit c89c181
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 29 deletions.
4 changes: 2 additions & 2 deletions gpu/vulkan/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#CFLAGS = -std=c++17 -O2
LDFLAGS = -lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi
LDFLAGS = -lvulkan -ldl -lpthread -lX11 -lXrandr -lXi

VULKAN_SDK_PATH = /home/danielbevenius/work/ai/vulkan/1.3.275.0/x86_64
VULKAN_SDK_PATH = /home/danbev/work/ai/vulkan/1.3.283.0/x86_64
DXC = $(VULKAN_SDK_PATH)/bin/dxc

helloworld: src/helloworld.cpp
Expand Down
2 changes: 1 addition & 1 deletion gpu/vulkan/setenv.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
source /home/danielbevenius/work/ai/vulkan/1.3.275.0/setup-env.sh
source /home/danbev/work/ai/vulkan/1.3.283.0/setup-env.sh
64 changes: 38 additions & 26 deletions gpu/vulkan/src/helloworld.cpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>

#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/vec4.hpp>
#include <glm/mat4x4.hpp>

#include <vulkan/vulkan.h>
#include <iostream>
#include <vector>
#include <stdexcept>

int main() {
glfwInit();

glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
GLFWwindow* window = glfwCreateWindow(800, 600, "Vulkan Example window", nullptr, nullptr);

uint32_t extensionCount = 0;
vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);

std::cout << extensionCount << " extensions supported\n";

glm::mat4 matrix;
glm::vec4 vec;
auto test = matrix * vec;

while(!glfwWindowShouldClose(window)) {
glfwPollEvents();
// Application info
VkApplicationInfo appInfo{};
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
appInfo.pApplicationName = "Vulkan App";
appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
appInfo.pEngineName = "No Engine";
appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
appInfo.apiVersion = VK_API_VERSION_1_0;

// Instance creation info
VkInstanceCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
createInfo.pApplicationInfo = &appInfo;

// Specify extensions
std::vector<const char*> extensions = {
VK_KHR_SURFACE_EXTENSION_NAME
};
createInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
createInfo.ppEnabledExtensionNames = extensions.data();

// No validation layers for this simple example
createInfo.enabledLayerCount = 0;

// Create the Vulkan instance
VkInstance instance;
VkResult result = vkCreateInstance(&createInfo, nullptr, &instance);

if (result != VK_SUCCESS) {
throw std::runtime_error("Failed to create Vulkan instance!");
}

glfwDestroyWindow(window);
std::cout << "Vulkan instance created successfully." << std::endl;

// Use the Vulkan instance...

glfwTerminate();
// Clean up
vkDestroyInstance(instance, nullptr);

return 0;
}

0 comments on commit c89c181

Please sign in to comment.