summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Halase <jordan@halase.me>2019-10-27 23:08:04 -0500
committerJordan Halase <jordan@halase.me>2019-10-27 23:08:04 -0500
commit0854a0f3a0aa9d5c51b8d46686ce02723f14a666 (patch)
treec3f84170cca4c1abe7e98f0e6be90d0f3dfeaf85
First Commit
-rw-r--r--main.c162
-rw-r--r--vkpugltest.sln31
-rw-r--r--vkpugltest.vcxproj136
-rw-r--r--vkpugltest.vcxproj.filters22
-rw-r--r--vkpugltest.vcxproj.user4
5 files changed, 355 insertions, 0 deletions
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..cf59f16
--- /dev/null
+++ b/main.c
@@ -0,0 +1,162 @@
+/*
+Copyright (c) 2019, Jordan Halase <jordan@halase.me>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
+REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
+INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+*/
+
+// TODO: Create debug report callback
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <vulkan/vulkan.h>
+
+#if defined(_WIN32)
+#include <windows.h>
+#include <vulkan/vulkan_win32.h>
+#else
+#include <X11/Xlib.h>
+#include <vulkan/vulkan_xlib.h>
+#endif
+
+struct RenderVulkan {
+ /** Put `device` first in struct to reduce pointer arithmetic on most Vulkan functions */
+ VkDevice device;
+ VkInstance instance;
+};
+
+struct RenderVulkan *vk;
+
+#if defined(_WIN32)
+void getRequiredInstanceExtensions(unsigned *nRequired, const char **extensions)
+{
+ static const char *const required[] = {
+ VK_KHR_SURFACE_EXTENSION_NAME,
+ VK_KHR_WIN32_SURFACE_EXTENSION_NAME
+ };
+ static const unsigned num = sizeof(required) / sizeof(required[0]);
+ if (extensions) {
+ for (int i = 0; i < num; ++i) {
+ extensions[i] = required[i];
+ }
+ } else {
+ *nRequired = num;
+ }
+}
+#else
+void getRequiredInstanceExtensions(unsigned *nRequired, const char **const extensions)
+{
+ static const char *const required[] = {
+ VK_KHR_SURFACE_EXTENSION_NAME,
+ VK_KHR_XLIB_SURFACE_EXTENSION_NAME
+ };
+ static const unsigned num = sizeof(required) / sizeof(required[0]);
+ if (extensions) {
+ for (int i = 0; i < num; ++i) {
+ extensions[i] = required[i];
+ }
+ } else {
+ *nRequired = num;
+ }
+}
+#endif
+
+void createInstance(struct RenderVulkan *vk,
+ const uint32_t nLayers, const char *const *layers,
+ const uint32_t nAdditional, const char *const *additionalExtensions)
+{
+ VkApplicationInfo appInfo = { 0 };
+ appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
+ appInfo.pApplicationName = "Pugl Vulkan Test";
+ appInfo.applicationVersion = VK_MAKE_VERSION(0, 1, 0);
+ appInfo.pEngineName = "Pugl Vulkan Test Engine";
+ appInfo.engineVersion = VK_MAKE_VERSION(0, 1, 0);
+ appInfo.apiVersion = VK_MAKE_VERSION(1, 0, 0); // MoltenVK for macOS only supports Vulkan 1.0
+
+ unsigned i, j, nRequired;
+ getRequiredInstanceExtensions(&nRequired, NULL);
+
+ const uint32_t nExtensions = nRequired + nAdditional;
+ const char **const extensions = malloc(sizeof(const char*) * nExtensions);
+
+ getRequiredInstanceExtensions(NULL, extensions);
+ for (i = nRequired, j = 0; i < nExtensions; ++i, ++j) {
+ extensions[i] = additionalExtensions[j];
+ }
+
+ for (i = 0; i < nExtensions; ++i) {
+ printf("Using instance extension:\t%s\n", extensions[i]);
+ }
+
+ for (i = 0; i < nLayers; ++i) {
+ printf("Using instance layer:\t%s\n", layers[i]);
+ }
+
+ VkInstanceCreateInfo createInfo = { 0 };
+ createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
+ createInfo.pApplicationInfo = &appInfo;
+ createInfo.enabledLayerCount = nLayers;
+ createInfo.ppEnabledLayerNames = layers;
+ createInfo.enabledExtensionCount = nExtensions;
+ createInfo.ppEnabledExtensionNames = extensions;
+
+ VkResult result;
+ if ((result = vkCreateInstance(&createInfo, NULL, &vk->instance))) {
+ exit(result);
+ }
+ free(extensions);
+}
+
+/** Must not be called until all derivative objects are destroyed first */
+void destroyInstance(struct RenderVulkan *vk)
+{
+ vkDestroyInstance(vk->instance, NULL);
+ vk->instance = NULL;
+}
+
+int main()
+{
+ static const char *const instanceLayers[] = {
+ "VK_LAYER_LUNARG_standard_validation"
+ };
+ const uint32_t nInstanceLayers = sizeof(instanceLayers) / sizeof(instanceLayers[0]);
+ static const char *const instanceExtensions[] = {
+ VK_EXT_DEBUG_REPORT_EXTENSION_NAME
+ };
+ const uint32_t nInstanceExtensions = sizeof(instanceExtensions) / sizeof(instanceExtensions[0]);
+
+ vk = malloc(sizeof(*vk));
+ createInstance(vk, nInstanceLayers, instanceLayers, nInstanceExtensions, instanceExtensions);
+ printf("Created Vulkan Instance Successfully\n");
+ destroyInstance(vk);
+ free(vk);
+ vk = NULL;
+ return 0;
+}
+
+//#if defined(_WIN32)
+#if 0
+int WINAPI WinMain(
+ HINSTANCE hInstance,
+ HINSTANCE hPrevInstance,
+ LPSTR lpCmdLine,
+ int nCmdShow
+ )
+{
+ (void)hInstance;
+ (void)hPrevInstance;
+ (void)lpCmdLine;
+ (void)nCmdShow;
+ return main();
+}
+#endif
diff --git a/vkpugltest.sln b/vkpugltest.sln
new file mode 100644
index 0000000..279f928
--- /dev/null
+++ b/vkpugltest.sln
@@ -0,0 +1,31 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29418.71
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vkpugltest", "vkpugltest.vcxproj", "{D40E96A6-A1AF-4C08-BC54-BA73A37B04C8}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {D40E96A6-A1AF-4C08-BC54-BA73A37B04C8}.Debug|x64.ActiveCfg = Debug|x64
+ {D40E96A6-A1AF-4C08-BC54-BA73A37B04C8}.Debug|x64.Build.0 = Debug|x64
+ {D40E96A6-A1AF-4C08-BC54-BA73A37B04C8}.Debug|x86.ActiveCfg = Debug|Win32
+ {D40E96A6-A1AF-4C08-BC54-BA73A37B04C8}.Debug|x86.Build.0 = Debug|Win32
+ {D40E96A6-A1AF-4C08-BC54-BA73A37B04C8}.Release|x64.ActiveCfg = Release|x64
+ {D40E96A6-A1AF-4C08-BC54-BA73A37B04C8}.Release|x64.Build.0 = Release|x64
+ {D40E96A6-A1AF-4C08-BC54-BA73A37B04C8}.Release|x86.ActiveCfg = Release|Win32
+ {D40E96A6-A1AF-4C08-BC54-BA73A37B04C8}.Release|x86.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {6ADF8EEA-80BB-46B0-8E9E-F646BB64DEE1}
+ EndGlobalSection
+EndGlobal
diff --git a/vkpugltest.vcxproj b/vkpugltest.vcxproj
new file mode 100644
index 0000000..cee3a0b
--- /dev/null
+++ b/vkpugltest.vcxproj
@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <VCProjectVersion>16.0</VCProjectVersion>
+ <ProjectGuid>{D40E96A6-A1AF-4C08-BC54-BA73A37B04C8}</ProjectGuid>
+ <RootNamespace>vkpugltest</RootNamespace>
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v142</PlatformToolset>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v142</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v142</PlatformToolset>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v142</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="Shared">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <IncludePath>C:\VulkanSDK\1.1.121.2\Include;$(IncludePath)</IncludePath>
+ <LibraryPath>$(LibraryPath)</LibraryPath>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>true</SDLCheck>
+ <ConformanceMode>true</ConformanceMode>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>true</SDLCheck>
+ <ConformanceMode>true</ConformanceMode>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <AdditionalLibraryDirectories>C:\VulkanSDK\1.1.121.2\Lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalDependencies>vulkan-1.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>true</SDLCheck>
+ <ConformanceMode>true</ConformanceMode>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>true</SDLCheck>
+ <ConformanceMode>true</ConformanceMode>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="main.c" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project> \ No newline at end of file
diff --git a/vkpugltest.vcxproj.filters b/vkpugltest.vcxproj.filters
new file mode 100644
index 0000000..dac3b05
--- /dev/null
+++ b/vkpugltest.vcxproj.filters
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="Source Files">
+ <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+ <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+ </Filter>
+ <Filter Include="Header Files">
+ <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+ <Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
+ </Filter>
+ <Filter Include="Resource Files">
+ <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+ <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="main.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/vkpugltest.vcxproj.user b/vkpugltest.vcxproj.user
new file mode 100644
index 0000000..0f14913
--- /dev/null
+++ b/vkpugltest.vcxproj.user
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup />
+</Project> \ No newline at end of file