Verified Commit 60755124 authored by Tobias Frisch's avatar Tobias Frisch
Browse files

Merge branch 'develop' into 43-multi-threading

parents 8ea8f76b eab9f823
Pipeline #26187 passed with stages
in 3 minutes and 45 seconds
<<<<<<< HEAD
=======
>>>>>>> develop
# IDE specific files # IDE specific files
.project .project
.cproject .cproject
...@@ -19,3 +15,6 @@ cmake-build-release/ ...@@ -19,3 +15,6 @@ cmake-build-release/
*.exe *.exe
*.ilk *.ilk
*.pdb *.pdb
# GUI configuration files
imgui.ini
...@@ -14,7 +14,7 @@ build_ubuntu_gcc: ...@@ -14,7 +14,7 @@ build_ubuntu_gcc:
- $RUN =~ /\bubuntu.*/i || $RUN =~ /\ball.*/i - $RUN =~ /\bubuntu.*/i || $RUN =~ /\ball.*/i
stage: build stage: build
tags: tags:
- ubuntu-gcc - ubuntu-gcc-cached
variables: variables:
GIT_SUBMODULE_STRATEGY: recursive GIT_SUBMODULE_STRATEGY: recursive
timeout: 10m timeout: 10m
...@@ -37,11 +37,11 @@ build_win10_msvc: ...@@ -37,11 +37,11 @@ build_win10_msvc:
- $RUN =~ /\bwin.*/i || $RUN =~ /\ball.*/i - $RUN =~ /\bwin.*/i || $RUN =~ /\ball.*/i
stage: build stage: build
tags: tags:
- win10-msvc - win10-msvc-cached
variables: variables:
GIT_SUBMODULE_STRATEGY: recursive GIT_SUBMODULE_STRATEGY: recursive
timeout: 10m timeout: 10m
retry: 1 retry: 0
script: script:
- cd 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\' - cd 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\'
- .\Launch-VsDevShell.ps1 - .\Launch-VsDevShell.ps1
......
...@@ -15,4 +15,10 @@ ...@@ -15,4 +15,10 @@
url = https://github.com/nothings/stb.git url = https://github.com/nothings/stb.git
[submodule "modules/camera/lib/glm"] [submodule "modules/camera/lib/glm"]
path = modules/camera/lib/glm path = modules/camera/lib/glm
url = https://github.com/g-truc/glm.git url = https://github.com/g-truc/glm.git
\ No newline at end of file [submodule "modules/shader_compiler/lib/glslang"]
path = modules/shader_compiler/lib/glslang
url = https://github.com/KhronosGroup/glslang.git
[submodule "modules/gui/lib/imgui"]
path = modules/gui/lib/imgui
url = https://github.com/ocornut/imgui.git
...@@ -41,24 +41,24 @@ if (vkcv_build_debug) ...@@ -41,24 +41,24 @@ if (vkcv_build_debug)
endif() endif()
endif() endif()
# configure everything to use the required dependencies
include(${vkcv_config}/Libraries.cmake)
# set the compile definitions aka preprocessor variables
add_compile_definitions(${vkcv_definitions})
# add modules as targets # add modules as targets
add_subdirectory(modules) add_subdirectory(modules)
# add source files for compilation # add source files for compilation
include(${vkcv_config}/Sources.cmake) include(${vkcv_config}/Sources.cmake)
# configure everything to use the required dependencies
include(${vkcv_config}/Libraries.cmake)
message("-- Libraries: [ ${vkcv_libraries} ]") message("-- Libraries: [ ${vkcv_libraries} ]")
message("-- Flags: [ ${vkcv_flags} ]") message("-- Flags: [ ${vkcv_flags} ]")
# set the compiler flags for the framework # set the compiler flags for the framework
set(CMAKE_CXX_FLAGS ${vkcv_flags}) set(CMAKE_CXX_FLAGS ${vkcv_flags})
# set the compile definitions aka preprocessor variables
add_compile_definitions(${vkcv_definitions})
# create VkCV framework as static library using all source files # create VkCV framework as static library using all source files
add_library(vkcv STATIC ${vkcv_sources}) add_library(vkcv STATIC ${vkcv_sources})
......
...@@ -865,7 +865,8 @@ WARN_LOGFILE = ...@@ -865,7 +865,8 @@ WARN_LOGFILE =
# Note: If this tag is empty the current directory is searched. # Note: If this tag is empty the current directory is searched.
INPUT = src \ INPUT = src \
include include \
modules
# This tag can be used to specify the character encoding of the source files # This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
...@@ -953,7 +954,7 @@ RECURSIVE = YES ...@@ -953,7 +954,7 @@ RECURSIVE = YES
# Note that relative paths are relative to the directory from which doxygen is # Note that relative paths are relative to the directory from which doxygen is
# run. # run.
EXCLUDE = EXCLUDE = lib
# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
# directories that are symbolic links (a Unix file system feature) are excluded # directories that are symbolic links (a Unix file system feature) are excluded
...@@ -969,7 +970,7 @@ EXCLUDE_SYMLINKS = NO ...@@ -969,7 +970,7 @@ EXCLUDE_SYMLINKS = NO
# Note that the wildcards are matched against the file with absolute path, so to # Note that the wildcards are matched against the file with absolute path, so to
# exclude all test directories for example use the pattern */test/* # exclude all test directories for example use the pattern */test/*
EXCLUDE_PATTERNS = EXCLUDE_PATTERNS = */lib/*
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
# (namespaces, classes, functions, etc.) that should be excluded from the # (namespaces, classes, functions, etc.) that should be excluded from the
......
...@@ -10,6 +10,8 @@ if(NOT WIN32) ...@@ -10,6 +10,8 @@ if(NOT WIN32)
list(APPEND vkcv_flags -fopenmp) list(APPEND vkcv_flags -fopenmp)
endif() endif()
list(APPEND vkcv_definitions _USE_MATH_DEFINES)
# some formatted printing # some formatted printing
set(vkcv_config_msg " - Library: ") set(vkcv_config_msg " - Library: ")
......
...@@ -32,8 +32,8 @@ set(vkcv_sources ...@@ -32,8 +32,8 @@ set(vkcv_sources
${vkcv_include}/vkcv/Logger.hpp ${vkcv_include}/vkcv/Logger.hpp
${vkcv_include}/vkcv/SwapChain.hpp ${vkcv_include}/vkcv/Swapchain.hpp
${vkcv_source}/vkcv/SwapChain.cpp ${vkcv_source}/vkcv/Swapchain.cpp
${vkcv_include}/vkcv/ShaderStage.hpp ${vkcv_include}/vkcv/ShaderStage.hpp
...@@ -41,7 +41,6 @@ set(vkcv_sources ...@@ -41,7 +41,6 @@ set(vkcv_sources
${vkcv_source}/vkcv/ShaderProgram.cpp ${vkcv_source}/vkcv/ShaderProgram.cpp
${vkcv_include}/vkcv/PipelineConfig.hpp ${vkcv_include}/vkcv/PipelineConfig.hpp
${vkcv_source}/vkcv/PipelineConfig.cpp
${vkcv_source}/vkcv/PipelineManager.hpp ${vkcv_source}/vkcv/PipelineManager.hpp
${vkcv_source}/vkcv/PipelineManager.cpp ${vkcv_source}/vkcv/PipelineManager.cpp
...@@ -81,4 +80,7 @@ set(vkcv_sources ...@@ -81,4 +80,7 @@ set(vkcv_sources
${vkcv_source}/vkcv/CommandStreamManager.cpp ${vkcv_source}/vkcv/CommandStreamManager.cpp
${vkcv_include}/vkcv/CommandRecordingFunctionTypes.hpp ${vkcv_include}/vkcv/CommandRecordingFunctionTypes.hpp
${vkcv_include}/vkcv/ImageConfig.hpp
${vkcv_source}/vkcv/ImageConfig.cpp
) )
...@@ -132,6 +132,9 @@ namespace vkcv ...@@ -132,6 +132,9 @@ namespace vkcv
*/ */
void unmapBuffer(const BufferHandle& handle); void unmapBuffer(const BufferHandle& handle);
void recordBufferMemoryBarrier(
const BufferHandle& handle,
vk::CommandBuffer cmdBuffer);
}; };
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <vulkan/vulkan.hpp> #include <vulkan/vulkan.hpp>
#include "vkcv/Context.hpp" #include "vkcv/Context.hpp"
#include "vkcv/SwapChain.hpp" #include "vkcv/Swapchain.hpp"
#include "vkcv/Window.hpp" #include "vkcv/Window.hpp"
#include "vkcv/PassConfig.hpp" #include "vkcv/PassConfig.hpp"
#include "vkcv/Handles.hpp" #include "vkcv/Handles.hpp"
...@@ -52,7 +52,7 @@ namespace vkcv ...@@ -52,7 +52,7 @@ namespace vkcv
* *
* @param context encapsulates various Vulkan objects * @param context encapsulates various Vulkan objects
*/ */
Core(Context &&context, Window &window, const SwapChain& swapChain, std::vector<vk::ImageView> imageViews, Core(Context &&context, Window &window, const Swapchain& swapChain, std::vector<vk::ImageView> imageViews,
const CommandResources& commandResources, const SyncResources& syncResources) noexcept; const CommandResources& commandResources, const SyncResources& syncResources) noexcept;
// explicit destruction of default constructor // explicit destruction of default constructor
Core() = delete; Core() = delete;
...@@ -61,11 +61,8 @@ namespace vkcv ...@@ -61,11 +61,8 @@ namespace vkcv
Context m_Context; Context m_Context;
SwapChain m_swapchain; Swapchain m_swapchain;
std::vector<vk::ImageView> m_swapchainImageViews; Window& m_window;
std::vector<vk::Image> m_swapchainImages;
std::vector<vk::ImageLayout> m_swapchainImageLayouts;
const Window& m_window;
std::unique_ptr<PassManager> m_PassManager; std::unique_ptr<PassManager> m_PassManager;
std::unique_ptr<PipelineManager> m_PipelineManager; std::unique_ptr<PipelineManager> m_PipelineManager;
...@@ -79,11 +76,7 @@ namespace vkcv ...@@ -79,11 +76,7 @@ namespace vkcv
SyncResources m_SyncResources; SyncResources m_SyncResources;
uint32_t m_currentSwapchainImageIndex; uint32_t m_currentSwapchainImageIndex;
std::function<void(int, int)> e_resizeHandle; event_handle<int,int> e_resizeHandle;
static std::vector<vk::ImageView> createImageViews( Context &context, SwapChain& swapChain);
void recordSwapchainImageLayoutTransition(vk::CommandBuffer cmdBuffer, vk::ImageLayout newLayout);
public: public:
/** /**
...@@ -123,6 +116,9 @@ namespace vkcv ...@@ -123,6 +116,9 @@ namespace vkcv
[[nodiscard]] [[nodiscard]]
const Context &getContext() const; const Context &getContext() const;
[[nodiscard]]
const Swapchain& getSwapchain() const;
/** /**
* Creates a #Core with given @p applicationName and @p applicationVersion for your application. * Creates a #Core with given @p applicationName and @p applicationVersion for your application.
...@@ -216,7 +212,20 @@ namespace vkcv ...@@ -216,7 +212,20 @@ namespace vkcv
* @return Image-Object * @return Image-Object
*/ */
[[nodiscard]] [[nodiscard]]
Image createImage(vk::Format format, uint32_t width, uint32_t height, uint32_t depth = 1); Image createImage(
vk::Format format,
uint32_t width,
uint32_t height,
uint32_t depth = 1,
bool createMipChain = false,
bool supportStorage = false,
bool supportColorAttachment = false,
Multisampling multisampling = Multisampling::None);
[[nodiscard]]
const uint32_t getImageWidth(ImageHandle imageHandle);
[[nodiscard]]
const uint32_t getImageHeight(ImageHandle imageHandle);
/** TODO: /** TODO:
* @param setDescriptions * @param setDescriptions
...@@ -253,8 +262,6 @@ namespace vkcv ...@@ -253,8 +262,6 @@ namespace vkcv
*/ */
void endFrame(); void endFrame();
vk::Format getSwapchainImageFormat();
/** /**
* Submit a command buffer to any queue of selected type. The recording can be customized by a * Submit a command buffer to any queue of selected type. The recording can be customized by a
* custom record-command-function. If the command submission has finished, an optional finish-function * custom record-command-function. If the command submission has finished, an optional finish-function
...@@ -264,7 +271,7 @@ namespace vkcv ...@@ -264,7 +271,7 @@ namespace vkcv
* @param record Record-command-function * @param record Record-command-function
* @param finish Finish-command-function or nullptr * @param finish Finish-command-function or nullptr
*/ */
void recordAndSubmitCommands( void recordAndSubmitCommandsImmediate(
const SubmitInfo &submitInfo, const SubmitInfo &submitInfo,
const RecordCommandFunction &record, const RecordCommandFunction &record,
const FinishCommandFunction &finish); const FinishCommandFunction &finish);
...@@ -279,5 +286,12 @@ namespace vkcv ...@@ -279,5 +286,12 @@ namespace vkcv
void submitCommandStream(const CommandStreamHandle handle); void submitCommandStream(const CommandStreamHandle handle);
void prepareSwapchainImageForPresent(const CommandStreamHandle handle); void prepareSwapchainImageForPresent(const CommandStreamHandle handle);
void prepareImageForSampling(const CommandStreamHandle cmdStream, const ImageHandle image); void prepareImageForSampling(const CommandStreamHandle cmdStream, const ImageHandle image);
void prepareImageForStorage(const CommandStreamHandle cmdStream, const ImageHandle image);
void recordImageMemoryBarrier(const CommandStreamHandle cmdStream, const ImageHandle image);
void recordBufferMemoryBarrier(const CommandStreamHandle cmdStream, const BufferHandle buffer);
void resolveMSAAImage(CommandStreamHandle cmdStream, ImageHandle src, ImageHandle dst);
vk::ImageView getSwapchainImageView() const;
}; };
} }
...@@ -4,15 +4,20 @@ ...@@ -4,15 +4,20 @@
namespace vkcv { namespace vkcv {
struct SampledImageDescriptorWrite { struct SampledImageDescriptorWrite {
inline SampledImageDescriptorWrite(uint32_t binding, ImageHandle image) : binding(binding), image(image) {}; inline SampledImageDescriptorWrite(uint32_t binding, ImageHandle image, uint32_t mipLevel = 0, bool useGeneralLayout = false)
: binding(binding), image(image), mipLevel(mipLevel), useGeneralLayout(useGeneralLayout) {};
uint32_t binding; uint32_t binding;
ImageHandle image; ImageHandle image;
uint32_t mipLevel;
bool useGeneralLayout;
}; };
struct StorageImageDescriptorWrite { struct StorageImageDescriptorWrite {
inline StorageImageDescriptorWrite(uint32_t binding, ImageHandle image) : binding(binding), image(image) {}; inline StorageImageDescriptorWrite(uint32_t binding, ImageHandle image, uint32_t mipLevel = 0)
: binding(binding), image(image), mipLevel(mipLevel) {};
uint32_t binding; uint32_t binding;
ImageHandle image; ImageHandle image;
uint32_t mipLevel;
}; };
struct UniformBufferDescriptorWrite { struct UniformBufferDescriptorWrite {
...@@ -36,8 +41,8 @@ namespace vkcv { ...@@ -36,8 +41,8 @@ namespace vkcv {
struct DescriptorWrites { struct DescriptorWrites {
std::vector<SampledImageDescriptorWrite> sampledImageWrites; std::vector<SampledImageDescriptorWrite> sampledImageWrites;
std::vector<StorageImageDescriptorWrite> storageImageWrites; std::vector<StorageImageDescriptorWrite> storageImageWrites;
std::vector<UniformBufferDescriptorWrite> uniformBufferWrites; std::vector<UniformBufferDescriptorWrite> uniformBufferWrites;
std::vector<StorageBufferDescriptorWrite> storageBufferWrites; std::vector<StorageBufferDescriptorWrite> storageBufferWrites;
std::vector<SamplerDescriptorWrite> samplerWrites; std::vector<SamplerDescriptorWrite> samplerWrites;
}; };
} }
\ No newline at end of file
...@@ -37,11 +37,12 @@ namespace vkcv { ...@@ -37,11 +37,12 @@ namespace vkcv {
}; };
struct DrawcallInfo { struct DrawcallInfo {
inline DrawcallInfo(const Mesh& mesh, const std::vector<DescriptorSetUsage>& descriptorSets) inline DrawcallInfo(const Mesh& mesh, const std::vector<DescriptorSetUsage>& descriptorSets, const uint32_t instanceCount = 1)
: mesh(mesh), descriptorSets(descriptorSets) {} : mesh(mesh), descriptorSets(descriptorSets), instanceCount(instanceCount){}
Mesh mesh; Mesh mesh;
std::vector<DescriptorSetUsage> descriptorSets; std::vector<DescriptorSetUsage> descriptorSets;
uint32_t instanceCount;
}; };
void recordDrawcall( void recordDrawcall(
......
...@@ -4,10 +4,18 @@ ...@@ -4,10 +4,18 @@
#include <mutex> #include <mutex>
namespace vkcv { namespace vkcv {
template<typename... T>
struct event_handle {
uint32_t id;
};
template<typename... T> template<typename... T>
struct event_function { struct event_function {
typedef std::function<void(T...)> type; typedef std::function<void(T...)> type;
event_handle<T...> handle;
type callback;
}; };
/** /**
...@@ -17,8 +25,9 @@ namespace vkcv { ...@@ -17,8 +25,9 @@ namespace vkcv {
template<typename... T> template<typename... T>
struct event { struct event {
private: private:
std::vector<typename event_function<T...>::type> m_handles; std::vector< event_function<T...> > m_functions;
std::mutex m_mutex; uint32_t m_id_counter;
std::mutex m_mutex;
public: public:
...@@ -28,31 +37,37 @@ namespace vkcv { ...@@ -28,31 +37,37 @@ namespace vkcv {
*/ */
void operator()(T... arguments) { void operator()(T... arguments) {
lock(); lock();
for (auto &handle : this->m_handles) { for (auto &function : this->m_functions) {
handle(arguments...); function.callback(arguments...);
} }
unlock(); unlock();
} }
/** /**
* adds a function handle to the event to be called * adds a function handle to the event to be called
* @param handle of the function * @param callback of the function
* @return handle of the function
*/ */
typename event_function<T...>::type add(typename event_function<T...>::type handle) { event_handle<T...> add(typename event_function<T...>::type callback) {
this->m_handles.push_back(handle); event_function<T...> function;
return handle; function.handle = { m_id_counter++ };
function.callback = callback;
this->m_functions.push_back(function);
return function.handle;
} }
/** /**
* removes a function handle of the event * removes a function handle of the event
* @param handle of the function * @param handle of the function
*/ */
void remove(typename event_function<T...>::type handle) { void remove(event_handle<T...> handle) {
this->m_handles.erase( this->m_functions.erase(
remove(this->m_handles.begin(), this->m_handles.end(), handle), std::remove_if(this->m_functions.begin(), this->m_functions.end(), [&handle](auto function){
this->m_handles.end() return (handle.id == function.handle.id);
}),
this->m_functions.end()
); );
} }
...@@ -60,17 +75,21 @@ namespace vkcv { ...@@ -60,17 +75,21 @@ namespace vkcv {
* locks the event so its function handles won't be called * locks the event so its function handles won't be called
*/ */
void lock() { void lock() {
m_mutex.lock(); m_mutex.lock();
} }
/** /**
* unlocks the event so its function handles can be called after locking * unlocks the event so its function handles can be called after locking
*/ */
void unlock() { void unlock() {
m_mutex.unlock(); m_mutex.unlock();
} }
event() = default; explicit event(bool locked = false) {
if (locked) {
lock();
}
}
event(const event &other) = delete; event(const event &other) = delete;
......
...@@ -7,11 +7,11 @@ ...@@ -7,11 +7,11 @@
#include "vulkan/vulkan.hpp" #include "vulkan/vulkan.hpp"
#include "Handles.hpp" #include "Handles.hpp"
#include "vkcv/ImageConfig.hpp"
namespace vkcv { namespace vkcv {
// forward declares class ImageManager;
class ImageManager;
bool isDepthFormat(const vk::Format format); bool isDepthFormat(const vk::Format format);
...@@ -29,24 +29,37 @@ namespace vkcv { ...@@ -29,24 +29,37 @@ namespace vkcv {
[[nodiscard]] [[nodiscard]]
uint32_t getDepth() const; uint32_t getDepth() const;
[[nodiscard]]
vk::ImageLayout getLayout() const;
[[nodiscard]] [[nodiscard]]
vkcv::ImageHandle getHandle() const; vkcv::ImageHandle getHandle() const;
[[nodiscard]]
uint32_t getMipCount() const;
void switchLayout(vk::ImageLayout newLayout); void switchLayout(vk::ImageLayout newLayout);
void fill(void* data, size_t size = SIZE_MAX); void