Skip to content

Commit

Permalink
Merge pull request #83 from EthicalML/update_dependencies
Browse files Browse the repository at this point in the history
Fix compatibility for Vulkan HPP 1.2.155 and above
  • Loading branch information
axsaucedo authored Nov 1, 2020
2 parents 7c8c0ee + 109d035 commit 9babbc5
Show file tree
Hide file tree
Showing 20 changed files with 199 additions and 119 deletions.
4 changes: 3 additions & 1 deletion .ccls
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
-DDEBUG=1
-DKOMPUTE_INCLUDE_FOR_SYNTAX

-I/c/Users/axsau/Programming/lib/vcpkg/installed/x64-linux/include/
-I./external/Vulkan-Headers/include/
-I./external/googletest/googletest/include/
-I./external/spdlog/include/
-I./src/include/
-I./single_include/
-I./vk_ndk_wrapper_include/
Expand Down
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[submodule "external/googletest"]
path = external/googletest
url = https://github.com/google/googletest
branch = release-1.10.0
[submodule "external/Vulkan-Headers"]
path = external/Vulkan-Headers
url = https://github.com/KhronosGroup/Vulkan-Headers
branch = v1.2.158
[submodule "external/spdlog"]
path = external/spdlog
url = https://github.com/gabime/spdlog
branch = v1.8.1
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ option(KOMPUTE_OPT_BUILD_TESTS "Enable if you want to build tests" 0)
option(KOMPUTE_OPT_BUILD_DOCS "Enable if you want to build documentation" 0)
option(KOMPUTE_OPT_BUILD_SHADERS "Enable if you want to re-build all shader files" 0)
option(KOMPUTE_OPT_BUILD_SINGLE_HEADER "Enable if you want to build the single header file" 0)
option(KOMPUTE_OPT_INSTALL "Enable if you want to enable installation" 1)
option(KOMPUTE_OPT_INSTALL "Enable if you want to enable installation" 0)
# Build options
option(KOMPUTE_OPT_ENABLE_SPDLOG "Extra compile flags for Kompute, see docs for full list" 0)
option(KOMPUTE_OPT_REPO_SUBMODULE_BUILD, "Use the submodule repos instead of external package manager" 0)
option(KOMPUTE_OPT_ANDOID_BUILD "Enable android compilation flags required" 0)
# TODO: Add on docs
option(KOMPUTE_OPT_DISABLE_VK_DEBUG_LAYERS "Explicitly disable debug layers even on debug" 0)

# Build flags
set(KOMPUTE_EXTRA_CXX_FLAGS "" CACHE STRING "Extra compile flags for Kompute, see docs for full list")

if(KOMPUTE_OPT_ENABLE_SPDLOG)
Expand Down
20 changes: 9 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,18 @@ MK_KOMPUTE_EXTRA_CXX_FLAGS ?= ""
mk_cmake:
cmake \
-Bbuild \
$(MK_CMAKE_EXTRA_FLAGS) \
-DCMAKE_TOOLCHAIN_FILE=$(VCPKG_UNIX_PATH) \
-DCMAKE_BUILD_TYPE=$(MK_BUILD_TYPE) \
-DCMAKE_INSTALL_PREFIX=$(MK_INSTALL_PATH) \
-DCMAKE_TOOLCHAIN_FILE=$(VCPKG_UNIX_PATH) \
-DKOMPUTE_EXTRA_CXX_FLAGS=$(MK_KOMPUTE_EXTRA_CXX_FLAGS) \
-DKOMPUTE_OPT_INSTALL=1 \
-DKOMPUTE_OPT_REPO_SUBMODULE_BUILD=0 \
-DKOMPUTE_OPT_BUILD_TESTS=1 \
-DKOMPUTE_OPT_BUILD_DOCS=1 \
-DKOMPUTE_OPT_BUILD_SHADERS=1 \
-DKOMPUTE_OPT_BUILD_SINGLE_HEADER=1 \
-DKOMPUTE_OPT_ENABLE_SPDLOG=1 \
$(MK_CMAKE_EXTRA_FLAGS) \
-G "Unix Makefiles"

mk_build_all:
Expand All @@ -84,16 +86,18 @@ mk_run_tests: mk_build_tests
VS_BUILD_TYPE ?= "Debug"
# Run with multiprocessin / parallel build by default
VS_CMAKE_EXTRA_FLAGS ?= ""
VS_KOMPUTE_EXTRA_CXX_FLAGS ?= "/MP" # Adding multiprocessing by default
VS_KOMPUTE_EXTRA_CXX_FLAGS ?= "/MP" # Adding multiprocessing by default. You should add "/MT" for submodule builds for compatibility with gtest
VS_INSTALL_PATH ?= "build/src/CMakeFiles/Export/" # Set to "" if prefer default

vs_cmake:
$(CMAKE_BIN) \
-Bbuild \
-DCMAKE_TOOLCHAIN_FILE=$(VCPKG_WIN_PATH) \
$(VS_CMAKE_EXTRA_FLAGS) \
-DCMAKE_TOOLCHAIN_FILE=$(VCPKG_WIN_PATH) \
-DKOMPUTE_EXTRA_CXX_FLAGS=$(VS_KOMPUTE_EXTRA_CXX_FLAGS) \
-DCMAKE_INSTALL_PREFIX=$(VS_INSTALL_PATH) \
-DKOMPUTE_OPT_INSTALL=1 \
-DKOMPUTE_OPT_REPO_SUBMODULE_BUILD=0 \
-DKOMPUTE_OPT_BUILD_TESTS=1 \
-DKOMPUTE_OPT_BUILD_DOCS=1 \
-DKOMPUTE_OPT_BUILD_SHADERS=1 \
Expand Down Expand Up @@ -125,7 +129,7 @@ vs_run_tests: vs_build_tests
####### Create release ######

update_builder_image:
docker build -f Dockerfile.linux . \
docker build -f builders/Dockerfile.linux . \
-t axsauze/kompute-builder:0.1
docker push axsauze/kompute-builder:0.1

Expand All @@ -152,12 +156,6 @@ build_shaders:
--header-path test/compiled_shaders_include/kompute_test/shaders/ \
-v

docker_vulkan_build:
docker build . -t axsauze/vulkan-sum:0.1

push_vulkan_docker:
docker push axsauze/vulkan-sum:0.1

build_single_header:
quom \
--include_directory \
Expand Down
63 changes: 4 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,70 +285,15 @@ We are currently developing Vulkan Kompute not to hide the Vulkan SDK interface

The build system provided uses `cmake`, which allows for cross platform builds.

### Build parameters (cmake)
The top level `Makefile` provides a set of optimized configurations for development as well as the docker image build, but you can start a build with the following command:

The recommended approach to build the project is as out-of-source build in the `build` folder. This project comes with a `Makefile` that provides a set of commands that help with developer workflows. You can see some of the commands if you want to add some of the more advanced commands.

For a base build you just have to run:
```
cmake -Bbuild
```

This by default configures without any of the extra build tasks (such as building shaders) and compiles without the optional dependencies. The table below provides more detail.

| Flag | Description |
|-------------------------------------------------------|--------------------------------------------------------------------------|
| -DCMAKE_INSTALL_PREFIX="build/src/CMakefiles/Export/" | Enables local installation (which won't require admin privileges) |
| -DCMAKE_TOOLCHAIN_FILE="..." | This is the path for your package manager if you use it such as vcpkg |
| -DKOMPUTE_OPT_BUILD_TESTS=1 | Enable if you wish to build and run the tests (must have deps installed. |
| -DKOMPUTE_OPT_BUILD_DOCS=1 | Enable if you wish to build the docs (must have docs deps installed) |
| -DKOMPUTE_OPT_BUILD_SINGLE_HEADER=1 | Option to build the single header file using "quom" utility |
| -DKOMPUTE_EXTRA_CXX_FLAGS="..." | Allows you to pass extra config flags to compiler |
| -DKOMPUTE_OPT_INSTALL=0 | Disables the install step in the cmake file (useful for android build) |
| -DKOMPUTE_OPT_ANDROID_BUILD=1 | Enables android build which includes and excludes relevant libraries |

#### Compile Flags


| Flag | Description |
|--------------------------------------|-----------------------------------------------------------------------------------------|
| KOMPUTE_CREATE_PIPELINE_RESULT_VALUE | Ensure the return value of createPipeline is processed as ResultValue instead of Result |
| -DKOMPUTE_VK_API_VERSION="..." | Sets the default api version to use for vulkan kompute api |
| -DKOMPUTE_VK_API_MAJOR_VERSION=1 | Major version to use for the Vulkan API |
| -DKOMPUTE_VK_API_MINOR_VERSION=1 | Minor version to use for the Vulkan API |
| -DKOMPUTE_ENABLE_SPDLOG=1 | Enables the build with SPDLOG and FMT dependencies (must be installed) |
| -DKOMPUTE_LOG_VERRIDE=1 | Does not define the SPDLOG_<LEVEL> macros if these are to be overridden |
| -DSPDLOG_ACTIVE_LEVEL | The level for the log level on compile level (whether spdlog is enabled) |
| -DVVK_USE_PLATFORM_ANDROID_KHR | Flag to enable android imports in kompute (enabled with -DKOMPUTE_OPT_ANDROID_BUILD) |
| -DRELEASE=1 | Enable release build (enabled by cmake release build) |
| -DDEBUG=1 | Enable debug build including debug flags (enabled by cmake debug build) |
| -DKOMPUTE_DISABLE_VK_DEBUG_LAYERS | Disable the debug Vulkan layers, mainly used for android builds |

### Dependencies

Given Kompute is expected to be used across a broad range of architectures and hardware, it will be important to make sure we are able to minimise dependencies.

#### Required dependencies

The only required dependency in the build is Vulkan. More specifically, the header files vulkan.h and vulkan.hpp, which are both part of the Vulkan SDK. If you haven't installed the Vulkan SDK yet, you can [download it here](https://vulkan.lunarg.com/).

#### Optional dependencies

SPDLOG is the preferred logging library, however by default Vulkan Kompute runs without SPDLOG by overriding the macros. It also provides an easy way to override the macros if you prefer to bring your own logging framework. The macro override is the following:

```c++
#ifndef KOMPUTE_LOG_OVERRIDE // Use this if you want to define custom macro overrides
#if KOMPUTE_SPDLOG_ENABLED // Use this if you want to enable SPDLOG
#include <spdlog/spdlog.h>
#endif //KOMPUTE_SPDLOG_ENABLED
// ... Otherwise it adds macros that use std::cout (and only print first element)
#endif // KOMPUTE_LOG_OVERRIDE
cmake -Bbuild
```

You can choose to build with or without SPDLOG by using the cmake flag `KOMPUTE_OPT_ENABLE_SPDLOG`.

Finally, remember that you will still need to set both the compile time log level with `SPDLOG_ACTIVE_LEVEL`, and the runtime log level with `spdlog::set_level(spdlog::level::debug);`.
You also are able to add Kompute in your repo with `add_subdirectory` - the [Android example CMakeLists.txt file](https://github.com/EthicalML/vulkan-kompute/blob/7c8c0eeba2cdc098349fcd999102bb2cca1bf711/examples/android/android-simple/app/src/main/cpp/CMakeLists.txt#L3) shows how this would be done.

For a more advanced overview of the build configuration check out the [Build System Deep Dive](https://kompute.cc/overview/build-system.html) documentation.

## Kompute Development

Expand Down
10 changes: 6 additions & 4 deletions builders/Dockerfile.linux
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
FROM amd64/ubuntu:20.04

ARG VULKAN_SDK_VERSION=1.2.154.0

# First install vulkan
RUN apt-get update
RUN apt-get install -y curl unzip tar wget
RUN wget -O VulkanSDK.tar.gz https://sdk.lunarg.com/sdk/download/1.2.141.2/linux/vulkansdk-linux-x86_64-1.2.141.2.tar.gz?u=true && \
RUN wget -O VulkanSDK.tar.gz https://sdk.lunarg.com/sdk/download/${VULKAN_SDK_VERSION}/linux/vulkansdk-linux-x86_64-${VULKAN_SDK_VERSION}.tar.gz?u=true && \
mkdir VulkanSDK && \
cd VulkanSDK && \
tar xvf /VulkanSDK.tar.gz

RUN cd VulkanSDK/1.2.141.2
ENV VULKAN_SDK="/VulkanSDK/1.2.141.2/x86_64"
RUN cd VulkanSDK/${VULKAN_SDK_VERSION}
ENV VULKAN_SDK="/VulkanSDK/${VULKAN_SDK_VERSION}/x86_64"
ENV PATH="${VULKAN_SDK}/bin:${PATH}"
ENV LD_LIBRARY_PATH="${VULKAN_SDK}/lib"
ENV VK_LAYER_PATH="${VULKAN_SDK}/etc/explicit_layer.d"
Expand Down Expand Up @@ -53,7 +55,7 @@ ENV VCPKG_PATH=/core/vcpkg
ENV VCPKG_ROOT=/core/vcpkg

# INstall dependencies for kompute
RUN vcpkg install catch2 fmt spdlog vulkan
RUN /core/vcpkg/vcpkg install fmt spdlog vulkan-headers gtest

RUN mkdir /workspace
WORKDIR /workspace
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Index
Advanced Examples <overview/advanced-examples>
Asynchronous & Parallel Operations <overview/async-parallel>
Memory Management Principles <overview/memory-management>
Build System Deep Dive <overview/build-system>
Converting GLSL/HLSL Shaders to C++ Headers <overview/shaders-to-headers>
Mobile App Integration (Android) <overview/mobile-android>
Game Engine Integration (Godot Engine) <overview/game-engine-godot>
Expand Down
96 changes: 96 additions & 0 deletions docs/overview/build-system.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@

Build System Deep Dive
======================

The recommended approach to build the project is as out-of-source build in the ``build`` folder. This project comes with a ``Makefile`` that provides a set of commands that help with developer workflows. You can see some of the commands if you want to add some of the more advanced commands.

For a base build you just have to run:

.. code-block::
cmake -Bbuild
This by default configures without any of the extra build tasks (such as building shaders) and compiles without the optional dependencies. The table below provides more detail.

.. list-table::
:header-rows: 1

* - Flag
- Description
* - -DCMAKE_INSTALL_PREFIX="build/src/CMakefiles/Export/"
- Enables local installation (which won't require admin privileges)
* - -DCMAKE_TOOLCHAIN_FILE="..."
- This is the path for your package manager if you use it such as vcpkg
* - -DKOMPUTE_OPT_BUILD_TESTS=1
- Enable if you wish to build and run the tests (must have deps installed.
* - -DKOMPUTE_OPT_BUILD_DOCS=1
- Enable if you wish to build the docs (must have docs deps installed)
* - -DKOMPUTE_OPT_BUILD_SINGLE_HEADER=1
- Option to build the single header file using "quom" utility
* - -DKOMPUTE_EXTRA_CXX_FLAGS="..."
- Allows you to pass extra config flags to compiler
* - -DKOMPUTE_OPT_INSTALL=0
- Disables the install step in the cmake file (useful for android build)
* - -DKOMPUTE_OPT_ANDROID_BUILD=1
- Enables android build which includes and excludes relevant libraries


Compile Flags
~~~~~~~~~~~~~

.. list-table::
:header-rows: 1

* - Flag
- Description
* - KOMPUTE_CREATE_PIPELINE_RESULT_VALUE
- Ensure the return value of createPipeline is processed as ResultValue instead of Result
* - -DKOMPUTE_VK_API_VERSION="..."
- Sets the default api version to use for vulkan kompute api
* - -DKOMPUTE_VK_API_MAJOR_VERSION=1
- Major version to use for the Vulkan API
* - -DKOMPUTE_VK_API_MINOR_VERSION=1
- Minor version to use for the Vulkan API
* - -DKOMPUTE_ENABLE_SPDLOG=1
- Enables the build with SPDLOG and FMT dependencies (must be installed)
* - -DKOMPUTE_LOG_VERRIDE=1
- Does not define the SPDLOG_\ :raw-html-m2r:`<LEVEL>` macros if these are to be overridden
* - -DSPDLOG_ACTIVE_LEVEL
- The level for the log level on compile level (whether spdlog is enabled)
* - -DVVK_USE_PLATFORM_ANDROID_KHR
- Flag to enable android imports in kompute (enabled with -DKOMPUTE_OPT_ANDROID_BUILD)
* - -DRELEASE=1
- Enable release build (enabled by cmake release build)
* - -DDEBUG=1
- Enable debug build including debug flags (enabled by cmake debug build)
* - -DKOMPUTE_DISABLE_VK_DEBUG_LAYERS
- Disable the debug Vulkan layers, mainly used for android builds


Dependencies
^^^^^^^^^^^^

Given Kompute is expected to be used across a broad range of architectures and hardware, it will be important to make sure we are able to minimise dependencies.

Required dependencies
~~~~~~~~~~~~~~~~~~~~~

The only required dependency in the build is Vulkan. More specifically, the header files vulkan.h and vulkan.hpp, which are both part of the Vulkan SDK. If you haven't installed the Vulkan SDK yet, you can `download it here <https://vulkan.lunarg.com/>`_.

Optional dependencies
~~~~~~~~~~~~~~~~~~~~~

SPDLOG is the preferred logging library, however by default Vulkan Kompute runs without SPDLOG by overriding the macros. It also provides an easy way to override the macros if you prefer to bring your own logging framework. The macro override is the following:

.. code-block:: c++

#ifndef KOMPUTE_LOG_OVERRIDE // Use this if you want to define custom macro overrides
#if KOMPUTE_SPDLOG_ENABLED // Use this if you want to enable SPDLOG
#include <spdlog/spdlog.h>
#endif //KOMPUTE_SPDLOG_ENABLED
// ... Otherwise it adds macros that use std::cout (and only print first element)
#endif // KOMPUTE_LOG_OVERRIDE

You can choose to build with or without SPDLOG by using the cmake flag ``KOMPUTE_OPT_ENABLE_SPDLOG``.

Finally, remember that you will still need to set both the compile time log level with ``SPDLOG_ACTIVE_LEVEL``\ , and the runtime log level with ``spdlog::set_level(spdlog::level::debug);``.
1 change: 1 addition & 0 deletions external/Vulkan-Headers
Submodule Vulkan-Headers added at 320af0
1 change: 1 addition & 0 deletions external/googletest
Submodule googletest added at 703bd9
1 change: 1 addition & 0 deletions external/spdlog
Submodule spdlog added at 01b350
12 changes: 6 additions & 6 deletions src/Algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Algorithm::~Algorithm()
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy "
"pipeline but it is null");
}
this->mDevice->destroy(*this->mPipeline);
this->mDevice->destroy(*this->mPipeline, (vk::Optional<const vk::AllocationCallbacks>)nullptr);
}

if (this->mFreePipelineCache) {
Expand All @@ -43,7 +43,7 @@ Algorithm::~Algorithm()
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy "
"pipeline cache but it is null");
}
this->mDevice->destroy(*this->mPipelineCache);
this->mDevice->destroy(*this->mPipelineCache, (vk::Optional<const vk::AllocationCallbacks>)nullptr);
}

if (this->mFreePipelineLayout) {
Expand All @@ -52,7 +52,7 @@ Algorithm::~Algorithm()
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy "
"pipeline layout but it is null");
}
this->mDevice->destroy(*this->mPipelineLayout);
this->mDevice->destroy(*this->mPipelineLayout, (vk::Optional<const vk::AllocationCallbacks>)nullptr);
}

if (this->mFreeShaderModule) {
Expand All @@ -61,7 +61,7 @@ Algorithm::~Algorithm()
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy shader "
"module but it is null");
}
this->mDevice->destroy(*this->mShaderModule);
this->mDevice->destroy(*this->mShaderModule, (vk::Optional<const vk::AllocationCallbacks>)nullptr);
}

if (this->mFreeDescriptorSet) {
Expand All @@ -80,7 +80,7 @@ Algorithm::~Algorithm()
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy "
"descriptor set layout but it is null");
}
this->mDevice->destroy(*this->mDescriptorSetLayout);
this->mDevice->destroy(*this->mDescriptorSetLayout, (vk::Optional<const vk::AllocationCallbacks>)nullptr);
}

if (this->mFreeDescriptorPool) {
Expand All @@ -89,7 +89,7 @@ Algorithm::~Algorithm()
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy "
"descriptor pool but it is null");
}
this->mDevice->destroy(*this->mDescriptorPool);
this->mDevice->destroy(*this->mDescriptorPool, (vk::Optional<const vk::AllocationCallbacks>)nullptr);
}
}

Expand Down
Loading

0 comments on commit 9babbc5

Please sign in to comment.