Skip to content
Snippets Groups Projects
Verified Commit 60755124 authored by Tobias Frisch's avatar Tobias Frisch
Browse files

Merge branch 'develop' into 43-multi-threading

parents 8ea8f76b eab9f823
No related branches found
No related tags found
1 merge request!55Draft: Resolve "Multi-Threading"
Pipeline #26187 passed
Showing
with 213 additions and 134 deletions
<<<<<<< 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 fill(void* data, size_t size = SIZE_MAX);
void generateMipChainImmediate();
void recordMipChainGeneration(const vkcv::CommandStreamHandle& cmdStream);
private: private:
ImageManager* const m_manager; // TODO: const qualifier removed, very hacky!!!
const ImageHandle m_handle; // Else you cannot recreate an image. Pls fix.
ImageManager* m_manager;
ImageHandle m_handle;
Image(ImageManager* manager, const ImageHandle& handle); Image(ImageManager* manager, const ImageHandle& handle);
static Image create(ImageManager* manager, vk::Format format, uint32_t width, uint32_t height, uint32_t depth); static Image create(
ImageManager* manager,
vk::Format format,
uint32_t width,
uint32_t height,
uint32_t depth,
uint32_t mipCount,
bool supportStorage,
bool supportColorAttachment,
Multisampling msaa);
}; };
} }
#pragma once
#include <vulkan/vulkan.hpp>
namespace vkcv {
enum class Multisampling { None, MSAA2X, MSAA4X, MSAA8X };
vk::SampleCountFlagBits msaaToVkSampleCountFlag(Multisampling msaa);
uint32_t msaaToSampleCount(Multisampling msaa);
}
#pragma once #pragma once
#include <iostream> #include <stdio.h>
namespace vkcv { namespace vkcv {
...@@ -45,12 +45,12 @@ namespace vkcv { ...@@ -45,12 +45,12 @@ namespace vkcv {
char output_message [ \ char output_message [ \
VKCV_DEBUG_MESSAGE_LEN \ VKCV_DEBUG_MESSAGE_LEN \
]; \ ]; \
std::snprintf( \ snprintf( \
output_message, \ output_message, \
VKCV_DEBUG_MESSAGE_LEN, \ VKCV_DEBUG_MESSAGE_LEN, \
__VA_ARGS__ \ __VA_ARGS__ \
); \ ); \
std::fprintf( \ fprintf( \
getLogOutput(level), \ getLogOutput(level), \
"[%s]: %s [%s, line %d: %s]\n", \ "[%s]: %s [%s, line %d: %s]\n", \
vkcv::getLogName(level), \ vkcv::getLogName(level), \
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <vector> #include <vector>
#include <vulkan/vulkan.hpp> #include <vulkan/vulkan.hpp>
#include "ImageConfig.hpp"
namespace vkcv namespace vkcv
{ {
...@@ -45,7 +46,8 @@ namespace vkcv ...@@ -45,7 +46,8 @@ namespace vkcv
struct PassConfig struct PassConfig
{ {
explicit PassConfig(std::vector<AttachmentDescription> attachments) noexcept; explicit PassConfig(std::vector<AttachmentDescription> attachments, Multisampling msaa = Multisampling::None) noexcept;
std::vector<AttachmentDescription> attachments{}; std::vector<AttachmentDescription> attachments{};
Multisampling msaa;
}; };
} }
\ No newline at end of file
...@@ -10,37 +10,35 @@ ...@@ -10,37 +10,35 @@
#include "Handles.hpp" #include "Handles.hpp"
#include "ShaderProgram.hpp" #include "ShaderProgram.hpp"
#include "VertexLayout.hpp" #include "VertexLayout.hpp"
#include "ImageConfig.hpp"
namespace vkcv { namespace vkcv {
struct PipelineConfig { enum class PrimitiveTopology{PointList, LineList, TriangleList };
/** enum class CullMode{ None, Front, Back };
* Constructor for the pipeline. Creates a pipeline using @p vertexCode, @p fragmentCode as well as the enum class DepthTest { None, Less, LessEqual, Greater, GreatherEqual, Equal };
* dimensions of the application window @p width and @p height. A handle for the Render Pass is also needed, @p passHandle.
*
* @param shaderProgram shaders of the pipeline
* @param height height of the application window
* @param width width of the application window
* @param passHandle handle for render pass
* @param vertexLayout layout of vertex buffer, comprised of its bindings and the bindings' attachments
*/
PipelineConfig(
const ShaderProgram& shaderProgram,
uint32_t width,
uint32_t height,
const PassHandle &passHandle,
const VertexLayout &vertexLayouts,
const std::vector<vk::DescriptorSetLayout> &descriptorLayouts,
bool useDynamicViewport);
ShaderProgram m_ShaderProgram; // add more as needed
uint32_t m_Height; // alternatively we could expose the blend factors directly
uint32_t m_Width; enum class BlendMode{ None, Additive };
PassHandle m_PassHandle;
VertexLayout m_VertexLayout;
std::vector<vk::DescriptorSetLayout> m_DescriptorLayouts;
bool m_UseDynamicViewport;
struct PipelineConfig {
ShaderProgram m_ShaderProgram;
uint32_t m_Width;
uint32_t m_Height;
PassHandle m_PassHandle;
VertexLayout m_VertexLayout;
std::vector<vk::DescriptorSetLayout> m_DescriptorLayouts;
bool m_UseDynamicViewport;
bool m_UseConservativeRasterization = false;
PrimitiveTopology m_PrimitiveTopology = PrimitiveTopology::TriangleList;
BlendMode m_blendMode = BlendMode::None;
bool m_EnableDepthClamping = false;
Multisampling m_multisampling = Multisampling::None;
CullMode m_culling = CullMode::None;
DepthTest m_depthTest = DepthTest::LessEqual;
bool m_depthWrite = true;
bool m_alphaToCoverage = false;
}; };
} }
\ No newline at end of file
...@@ -51,7 +51,7 @@ namespace vkcv { ...@@ -51,7 +51,7 @@ namespace vkcv {
const std::vector<VertexAttachment> &getVertexAttachments() const; const std::vector<VertexAttachment> &getVertexAttachments() const;
size_t getPushConstantSize() const; size_t getPushConstantSize() const;
const std::vector<std::vector<DescriptorBinding>> &getReflectedDescriptors() const; const std::vector<std::vector<DescriptorBinding>>& getReflectedDescriptors() const;
private: private:
/** /**
......
...@@ -7,8 +7,12 @@ ...@@ -7,8 +7,12 @@
namespace vkcv namespace vkcv
{ {
class SwapChain final {
const uint32_t MIN_SWAPCHAIN_SIZE = 2;
class Swapchain final {
private: private:
friend class Core;
struct Surface struct Surface
{ {
...@@ -21,10 +25,10 @@ namespace vkcv ...@@ -21,10 +25,10 @@ namespace vkcv
Surface m_Surface; Surface m_Surface;
vk::SwapchainKHR m_Swapchain; vk::SwapchainKHR m_Swapchain;
vk::Format m_SwapchainFormat; vk::Format m_Format;
vk::ColorSpaceKHR m_SwapchainColorSpace; vk::ColorSpaceKHR m_ColorSpace;
vk::PresentModeKHR m_SwapchainPresentMode; vk::PresentModeKHR m_PresentMode;
uint32_t m_SwapchainImageCount; uint32_t m_ImageCount;
vk::Extent2D m_Extent; vk::Extent2D m_Extent;
...@@ -39,16 +43,36 @@ namespace vkcv ...@@ -39,16 +43,36 @@ namespace vkcv
* @param format * @param format
*/ */
// TODO: // TODO:
SwapChain(const Surface &surface, Swapchain(const Surface &surface,
vk::SwapchainKHR swapchain, vk::SwapchainKHR swapchain,
vk::Format format, vk::Format format,
vk::ColorSpaceKHR colorSpace, vk::ColorSpaceKHR colorSpace,
vk::PresentModeKHR presentMode, vk::PresentModeKHR presentMode,
uint32_t imageCount, uint32_t imageCount,
vk::Extent2D extent) noexcept; vk::Extent2D extent) noexcept;
/**
* TODO
*
* @return
*/
bool shouldUpdateSwapchain() const;
/**
* TODO
*
* context
* window
*/
void updateSwapchain(const Context &context, const Window &window);
/**
*
*/
void signalSwapchainRecreation();
public: public:
SwapChain(const SwapChain& other); Swapchain(const Swapchain& other);
/** /**
* @return The swapchain linked with the #SwapChain class * @return The swapchain linked with the #SwapChain class
...@@ -69,7 +93,7 @@ namespace vkcv ...@@ -69,7 +93,7 @@ namespace vkcv
* @return gets the chosen swapchain format * @return gets the chosen swapchain format
*/ */
[[nodiscard]] [[nodiscard]]
vk::Format getSwapchainFormat() const; vk::Format getFormat() const;
/** /**
* creates a swap chain object out of the given window and the given context * creates a swap chain object out of the given window and the given context
...@@ -77,37 +101,17 @@ namespace vkcv ...@@ -77,37 +101,17 @@ namespace vkcv
* @param context of the application * @param context of the application
* @return returns an object of swapChain * @return returns an object of swapChain
*/ */
static SwapChain create(const Window &window, const Context &context); static Swapchain create(const Window &window, const Context &context);
/** /**
* Destructor of SwapChain * Destructor of SwapChain
*/ */
virtual ~SwapChain(); virtual ~Swapchain();
/** /**
* @return number of images in swapchain * @return number of images in swapchain
*/ */
uint32_t getImageCount(); uint32_t getImageCount() const;
/**
* TODO
*
* @return
*/
bool shouldUpdateSwapchain() const;
/**
* TODO
*
* context
* window
*/
void updateSwapchain(const Context &context, const Window &window);
/**
*
*/
void signalSwapchainRecreation();
/** /**
* TODO * TODO
...@@ -118,4 +122,5 @@ namespace vkcv ...@@ -118,4 +122,5 @@ namespace vkcv
const vk::Extent2D& getExtent() const; const vk::Extent2D& getExtent() const;
}; };
} }
...@@ -63,4 +63,4 @@ namespace vkcv{ ...@@ -63,4 +63,4 @@ namespace vkcv{
std::vector<VertexBinding> vertexBindings; std::vector<VertexBinding> vertexBindings;
}; };
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment