Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • vulkan2021/vkcv-framework
1 result
Show changes
Commits on Source (273)
Showing
with 422 additions and 62 deletions
...@@ -18,3 +18,8 @@ cmake-build-release/ ...@@ -18,3 +18,8 @@ cmake-build-release/
# GUI configuration files # GUI configuration files
imgui.ini imgui.ini
# Generated source and header files for shaders
*.hxx
*.cxx
variables: variables:
RUN: RUN:
value: "all" value: "all"
description: "The tests that should run. Possible values: ubuntu, win, all." description: "The tests that should run. Possible values: ubuntu, win-msvc, win-mingw, mac, all."
GIT_DEPTH: 1 GIT_DEPTH: 15
stages: stages:
- build - build
...@@ -17,13 +17,13 @@ build_ubuntu_gcc: ...@@ -17,13 +17,13 @@ build_ubuntu_gcc:
- ubuntu-gcc-cached - ubuntu-gcc-cached
variables: variables:
GIT_SUBMODULE_STRATEGY: recursive GIT_SUBMODULE_STRATEGY: recursive
timeout: 10m timeout: 15m
retry: 1 retry: 1
script: script:
- mkdir debug - mkdir debug
- cd debug - cd debug
- cmake -DCMAKE_BUILD_TYPE=Debug .. - cmake -DCMAKE_BUILD_TYPE=Debug ..
- cmake --build . - cmake --build . -j 4
artifacts: artifacts:
name: "Documentation - $CI_PIPELINE_ID" name: "Documentation - $CI_PIPELINE_ID"
paths: paths:
...@@ -34,13 +34,13 @@ build_ubuntu_gcc: ...@@ -34,13 +34,13 @@ build_ubuntu_gcc:
build_win10_msvc: build_win10_msvc:
only: only:
variables: variables:
- $RUN =~ /\bwin.*/i || $RUN =~ /\ball.*/i - $RUN =~ /\bwin-msvc.*/i || $RUN =~ /\ball.*/i
stage: build stage: build
tags: tags:
- win10-msvc-cached - win10-msvc-cached
variables: variables:
GIT_SUBMODULE_STRATEGY: recursive GIT_SUBMODULE_STRATEGY: recursive
timeout: 10m timeout: 15m
retry: 0 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\'
...@@ -49,7 +49,43 @@ build_win10_msvc: ...@@ -49,7 +49,43 @@ build_win10_msvc:
- mkdir debug - mkdir debug
- cd debug - cd debug
- cmake -DCMAKE_BUILD_TYPE=Debug .. - cmake -DCMAKE_BUILD_TYPE=Debug ..
- cmake --build . - cmake --build . -j 4
build_win10_mingw:
only:
variables:
- $RUN =~ /\bwin-mingw.*/i || $RUN =~ /\ball.*/i
stage: build
tags:
- win10-mingw-cached
variables:
GIT_SUBMODULE_STRATEGY: recursive
timeout: 15m
retry: 0
script:
- mkdir debug
- cd debug
- cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=C:\msys64\mingw64\bin\x86_64-w64-mingw32-gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\msys64\mingw64\bin\x86_64-w64-mingw32-g++.exe .. -G "Unix Makefiles"
- cmake --build . -j 4
build_mac_clang:
only:
variables:
- $RUN =~ /\bmac.*/i || $RUN =~ /\ball.*/i
stage: build
tags:
- catalina-clang-cached
variables:
GIT_SUBMODULE_STRATEGY: recursive
timeout: 15m
retry: 1
script:
- mkdir debug
- cd debug
- export LDFLAGS="-L/usr/local/opt/llvm/lib"
- export CPPFLAGS="-I/usr/local/opt/llvm/include"
- cmake -DCMAKE_C_COMPILER="/usr/local/opt/llvm/bin/clang" -DCMAKE_CXX_COMPILER="/usr/local/opt/llvm/bin/clang++" -DCMAKE_BUILD_TYPE=Debug ..
- cmake --build . -j 4
deploy_doc_develop: deploy_doc_develop:
only: only:
......
...@@ -22,3 +22,9 @@ ...@@ -22,3 +22,9 @@
[submodule "modules/gui/lib/imgui"] [submodule "modules/gui/lib/imgui"]
path = modules/gui/lib/imgui path = modules/gui/lib/imgui
url = https://github.com/ocornut/imgui.git url = https://github.com/ocornut/imgui.git
[submodule "lib/VulkanMemoryAllocator-Hpp"]
path = lib/VulkanMemoryAllocator-Hpp
url = https://github.com/malte-v/VulkanMemoryAllocator-Hpp.git
[submodule "modules/upscaling/lib/FidelityFX-FSR"]
path = modules/upscaling/lib/FidelityFX-FSR
url = https://github.com/GPUOpen-Effects/FidelityFX-FSR.git
...@@ -33,7 +33,8 @@ set(vkcv_flags ${CMAKE_CXX_FLAGS}) ...@@ -33,7 +33,8 @@ set(vkcv_flags ${CMAKE_CXX_FLAGS})
# enabling warnings in the debug build # enabling warnings in the debug build
if (vkcv_build_debug) if (vkcv_build_debug)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(vkcv_flags ${vkcv_flags} " -Weverything") #set(vkcv_flags ${vkcv_flags} " -Weverything")
set(vkcv_flags ${vkcv_flags} " -Wextra -Wall")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(vkcv_flags ${vkcv_flags} " -Wextra -Wall -pedantic") set(vkcv_flags ${vkcv_flags} " -Wextra -Wall -pedantic")
else() else()
......
...@@ -3,7 +3,13 @@ set(vkcv_config_lib ${vkcv_config}/lib) ...@@ -3,7 +3,13 @@ set(vkcv_config_lib ${vkcv_config}/lib)
set(vkcv_lib_path ${PROJECT_SOURCE_DIR}/${vkcv_lib}) set(vkcv_lib_path ${PROJECT_SOURCE_DIR}/${vkcv_lib})
if(NOT WIN32) if(NOT WIN32)
set(vkcv_libraries stdc++fs) if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(vkcv_libraries stdc++fs)
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
list(APPEND vkcv_flags -Xpreprocessor)
endif()
# optimization for loading times # optimization for loading times
list(APPEND vkcv_flags -pthread) list(APPEND vkcv_flags -pthread)
...@@ -19,6 +25,7 @@ set(vkcv_config_msg " - Library: ") ...@@ -19,6 +25,7 @@ set(vkcv_config_msg " - Library: ")
include(${vkcv_config_lib}/GLFW.cmake) # glfw-x11 / glfw-wayland # libglfw3-dev include(${vkcv_config_lib}/GLFW.cmake) # glfw-x11 / glfw-wayland # libglfw3-dev
include(${vkcv_config_lib}/Vulkan.cmake) # vulkan-intel / vulkan-radeon / nvidia # libvulkan-dev include(${vkcv_config_lib}/Vulkan.cmake) # vulkan-intel / vulkan-radeon / nvidia # libvulkan-dev
include(${vkcv_config_lib}/SPIRV_Cross.cmake) # SPIRV-Cross # libspirv_cross_c_shared include(${vkcv_config_lib}/SPIRV_Cross.cmake) # SPIRV-Cross # libspirv_cross_c_shared
include(${vkcv_config_lib}/VulkanMemoryAllocator.cmake) # VulkanMemoryAllocator
# cleanup of compiler flags # cleanup of compiler flags
if (vkcv_flags) if (vkcv_flags)
...@@ -33,6 +40,9 @@ endif () ...@@ -33,6 +40,9 @@ endif ()
# fix dependencies for different Linux distros (looking at you Ubuntu) # fix dependencies for different Linux distros (looking at you Ubuntu)
include(${vkcv_config_ext}/CheckLibraries.cmake) include(${vkcv_config_ext}/CheckLibraries.cmake)
# add custom function to include a file like a shader as string
include(${vkcv_config_ext}/IncludeShader.cmake)
# cleanup of compiler definitions aka preprocessor variables # cleanup of compiler definitions aka preprocessor variables
if (vkcv_definitions) if (vkcv_definitions)
list(REMOVE_DUPLICATES vkcv_definitions) list(REMOVE_DUPLICATES vkcv_definitions)
......
...@@ -6,6 +6,9 @@ set(vkcv_sources ...@@ -6,6 +6,9 @@ set(vkcv_sources
${vkcv_include}/vkcv/Core.hpp ${vkcv_include}/vkcv/Core.hpp
${vkcv_source}/vkcv/Core.cpp ${vkcv_source}/vkcv/Core.cpp
${vkcv_include}/vkcv/File.hpp
${vkcv_source}/vkcv/File.cpp
${vkcv_include}/vkcv/PassConfig.hpp ${vkcv_include}/vkcv/PassConfig.hpp
${vkcv_source}/vkcv/PassConfig.cpp ${vkcv_source}/vkcv/PassConfig.cpp
...@@ -21,6 +24,8 @@ set(vkcv_sources ...@@ -21,6 +24,8 @@ set(vkcv_sources
${vkcv_include}/vkcv/Buffer.hpp ${vkcv_include}/vkcv/Buffer.hpp
${vkcv_include}/vkcv/PushConstants.hpp
${vkcv_include}/vkcv/BufferManager.hpp ${vkcv_include}/vkcv/BufferManager.hpp
${vkcv_source}/vkcv/BufferManager.cpp ${vkcv_source}/vkcv/BufferManager.cpp
......
function(include_shader shader include_dir source_dir)
if (NOT EXISTS ${shader})
message(WARNING "Shader file does not exist: ${shader}")
else()
get_filename_component(filename ${shader} NAME)
file(SIZE ${shader} filesize)
set(include_target_file ${include_dir}/${filename}.hxx)
set(source_target_file ${source_dir}/${filename}.cxx)
if ((EXISTS ${source_target_file}) AND (EXISTS ${include_target_file}))
file(TIMESTAMP ${shader} shader_timestamp "%Y-%m-%dT%H:%M:%S")
file(TIMESTAMP ${source_target_file} source_timestamp "%Y-%m-%dT%H:%M:%S")
string(COMPARE GREATER ${shader_timestamp} ${source_timestamp} shader_update)
else()
set(shader_update true)
endif()
if (shader_update)
string(TOUPPER ${filename} varname)
string(REPLACE "." "_" varname ${varname})
set(shader_header "#pragma once\n")
string(APPEND shader_header "// This file is auto-generated via cmake, so don't touch it!\n")
string(APPEND shader_header "extern unsigned char ${varname} [${filesize}]\;\n")
string(APPEND shader_header "extern unsigned int ${varname}_LEN\;\n")
string(APPEND shader_header "const std::string ${varname}_SHADER (reinterpret_cast<const char*>(${varname}), ${varname}_LEN)\;")
file(WRITE ${include_target_file} ${shader_header})
find_program(xxd_program "xxd")
if (EXISTS ${xxd_program})
get_filename_component(shader_directory ${shader} DIRECTORY)
add_custom_command(
OUTPUT ${source_target_file}
WORKING_DIRECTORY "${shader_directory}"
COMMAND xxd -i -C "${filename}" "${source_target_file}"
COMMENT "Processing shader into source files: ${shader}"
)
else()
set(shader_source "// This file is auto-generated via cmake, so don't touch it!\n")
string(APPEND shader_source "unsigned char ${varname}[] = {")
math(EXPR max_fileoffset "${filesize} - 1" OUTPUT_FORMAT DECIMAL)
message(STATUS "Processing shader into source files: ${shader}")
foreach(fileoffset RANGE ${max_fileoffset})
file(READ ${shader} shader_source_byte OFFSET ${fileoffset} LIMIT 1 HEX)
math(EXPR offset_modulo "${fileoffset} % 12" OUTPUT_FORMAT DECIMAL)
if (${offset_modulo} EQUAL 0)
string(APPEND shader_source "\n ")
endif()
if (${fileoffset} LESS ${max_fileoffset})
string(APPEND shader_source "0x${shader_source_byte}, ")
else()
string(APPEND shader_source "0x${shader_source_byte}\n")
endif()
endforeach()
string(APPEND shader_source "}\;\n")
string(APPEND shader_source "unsigned int ${varname}_LEN = ${filesize}\;")
file(WRITE ${source_target_file} ${shader_source})
endif()
endif()
endif()
endfunction()
...@@ -10,6 +10,7 @@ else() ...@@ -10,6 +10,7 @@ else()
add_subdirectory(${vkcv_lib}/glfw) add_subdirectory(${vkcv_lib}/glfw)
list(APPEND vkcv_libraries glfw) list(APPEND vkcv_libraries glfw)
list(APPEND vkcv_includes ${vkcv_lib_path}/glfw/include)
message(${vkcv_config_msg} " GLFW - " ${glfw3_VERSION}) message(${vkcv_config_msg} " GLFW - " ${glfw3_VERSION})
else() else()
......
...@@ -25,6 +25,7 @@ else() ...@@ -25,6 +25,7 @@ else()
add_subdirectory(${vkcv_lib}/SPIRV-Cross) add_subdirectory(${vkcv_lib}/SPIRV-Cross)
list(APPEND vkcv_libraries spirv-cross-cpp) list(APPEND vkcv_libraries spirv-cross-cpp)
list(APPEND vkcv_includes ${vkcv_lib_path}/SPIV-Cross/include)
message(${vkcv_config_msg} " SPIRV Cross - " ${SPIRV_CROSS_VERSION}) message(${vkcv_config_msg} " SPIRV Cross - " ${SPIRV_CROSS_VERSION})
else() else()
......
if (EXISTS "${vkcv_lib_path}/VulkanMemoryAllocator-Hpp")
set(VMA_HPP_PATH "${vkcv_lib_path}/VulkanMemoryAllocator-Hpp" CACHE INTERNAL "")
set(VMA_RECORDING_ENABLED OFF CACHE INTERNAL "")
set(VMA_USE_STL_CONTAINERS OFF CACHE INTERNAL "")
set(VMA_STATIC_VULKAN_FUNCTIONS ON CACHE INTERNAL "")
set(VMA_DYNAMIC_VULKAN_FUNCTIONS OFF CACHE INTERNAL "")
set(VMA_DEBUG_ALWAYS_DEDICATED_MEMORY OFF CACHE INTERNAL "")
set(VMA_DEBUG_INITIALIZE_ALLOCATIONS OFF CACHE INTERNAL "")
set(VMA_DEBUG_GLOBAL_MUTEX OFF CACHE INTERNAL "")
set(VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT OFF CACHE INTERNAL "")
add_subdirectory(${vkcv_config_lib}/vma)
list(APPEND vkcv_libraries VulkanMemoryAllocator)
list(APPEND vkcv_includes ${vkcv_lib_path}/VulkanMemoryAllocator-Hpp)
message(${vkcv_config_msg} " VMA - ")
else()
message(WARNING "VulkanMemoryAllocator is required..! Update the submodules!")
endif ()
cmake_minimum_required(VERSION 3.9)
project(VulkanMemoryAllocator)
find_package(Vulkan REQUIRED)
option(VMA_HPP_PATH "Location of C++ headers" "")
message(STATUS "VMA_BUILD_SAMPLE = ${VMA_BUILD_SAMPLE}")
message(STATUS "VMA_BUILD_SAMPLE_SHADERS = ${VMA_BUILD_SAMPLE_SHADERS}")
message(STATUS "VMA_BUILD_REPLAY = ${VMA_BUILD_REPLAY}")
option(VMA_RECORDING_ENABLED "Enable VMA memory recording for debugging" OFF)
option(VMA_USE_STL_CONTAINERS "Use C++ STL containers instead of VMA's containers" OFF)
option(VMA_STATIC_VULKAN_FUNCTIONS "Link statically with Vulkan API" OFF)
option(VMA_DYNAMIC_VULKAN_FUNCTIONS "Fetch pointers to Vulkan functions internally (no static linking)" ON)
option(VMA_DEBUG_ALWAYS_DEDICATED_MEMORY "Every allocation will have its own memory block" OFF)
option(VMA_DEBUG_INITIALIZE_ALLOCATIONS "Automatically fill new allocations and destroyed allocations with some bit pattern" OFF)
option(VMA_DEBUG_GLOBAL_MUTEX "Enable single mutex protecting all entry calls to the library" OFF)
option(VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT "Never exceed VkPhysicalDeviceLimits::maxMemoryAllocationCount and return error" OFF)
message(STATUS "VMA_RECORDING_ENABLED = ${VMA_RECORDING_ENABLED}")
message(STATUS "VMA_USE_STL_CONTAINERS = ${VMA_USE_STL_CONTAINERS}")
message(STATUS "VMA_DYNAMIC_VULKAN_FUNCTIONS = ${VMA_DYNAMIC_VULKAN_FUNCTIONS}")
message(STATUS "VMA_DEBUG_ALWAYS_DEDICATED_MEMORY = ${VMA_DEBUG_ALWAYS_DEDICATED_MEMORY}")
message(STATUS "VMA_DEBUG_INITIALIZE_ALLOCATIONS = ${VMA_DEBUG_INITIALIZE_ALLOCATIONS}")
message(STATUS "VMA_DEBUG_GLOBAL_MUTEX = ${VMA_DEBUG_GLOBAL_MUTEX}")
message(STATUS "VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT = ${VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT}")
add_library(VulkanMemoryAllocator vma.cpp)
set_target_properties(
VulkanMemoryAllocator PROPERTIES
CXX_EXTENSIONS OFF
# Use C++14
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON
)
target_include_directories(VulkanMemoryAllocator PUBLIC ${VMA_HPP_PATH})
# Only link to Vulkan if static linking is used
if (NOT ${VMA_DYNAMIC_VULKAN_FUNCTIONS})
target_link_libraries(VulkanMemoryAllocator PUBLIC Vulkan::Vulkan)
endif()
target_compile_definitions(
VulkanMemoryAllocator
PUBLIC
VMA_USE_STL_CONTAINERS=$<BOOL:${VMA_USE_STL_CONTAINERS}>
VMA_DYNAMIC_VULKAN_FUNCTIONS=$<BOOL:${VMA_DYNAMIC_VULKAN_FUNCTIONS}>
VMA_DEBUG_ALWAYS_DEDICATED_MEMORY=$<BOOL:${VMA_DEBUG_ALWAYS_DEDICATED_MEMORY}>
VMA_DEBUG_INITIALIZE_ALLOCATIONS=$<BOOL:${VMA_DEBUG_INITIALIZE_ALLOCATIONS}>
VMA_DEBUG_GLOBAL_MUTEX=$<BOOL:${VMA_DEBUG_GLOBAL_MUTEX}>
VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT=$<BOOL:${VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT}>
VMA_RECORDING_ENABLED=$<BOOL:${VMA_RECORDING_ENABLED}>
)
#ifndef NDEBUG
#define _DEBUG
#endif
#ifndef _MSVC_LANG
#ifdef __MINGW32__
#include <stdint.h>
#include <stdlib.h>
class VmaMutex {
public:
VmaMutex() : m_locked(false) {}
void Lock() {
while (m_locked);
m_locked = true;
}
void Unlock() {
m_locked = false;
}
private:
bool m_locked;
};
#define VMA_MUTEX VmaMutex
template <typename T>
T* custom_overestimate_malloc(size_t size) {
return new T[size + (sizeof(T) - 1) / sizeof(T)];
}
void* custom_aligned_malloc(size_t alignment, size_t size) {
if (alignment > 4) {
return custom_overestimate_malloc<uint64_t>(size);
} else
if (alignment > 2) {
return custom_overestimate_malloc<uint32_t>(size);
} else
if (alignment > 1) {
return custom_overestimate_malloc<uint16_t>(size);
} else {
return custom_overestimate_malloc<uint8_t>(size);
}
}
void custom_free(void *ptr) {
delete[] reinterpret_cast<uint8_t*>(ptr);
}
#define VMA_SYSTEM_ALIGNED_MALLOC(size, alignment) (custom_aligned_malloc(alignment, size))
#define VMA_SYSTEM_FREE(ptr) (custom_free(ptr))
#endif
#endif
#define VMA_IMPLEMENTATION
#include "vk_mem_alloc.hpp"
...@@ -76,8 +76,8 @@ namespace vkcv { ...@@ -76,8 +76,8 @@ namespace vkcv {
{} {}
[[nodiscard]] [[nodiscard]]
static Buffer<T> create(BufferManager* manager, BufferType type, size_t count, BufferMemoryType memoryType) { static Buffer<T> create(BufferManager* manager, BufferType type, size_t count, BufferMemoryType memoryType, bool supportIndirect) {
return Buffer<T>(manager, manager->createBuffer(type, count * sizeof(T), memoryType), type, count, memoryType); return Buffer<T>(manager, manager->createBuffer(type, count * sizeof(T), memoryType, supportIndirect), type, count, memoryType);
} }
}; };
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <vector> #include <vector>
#include <vulkan/vulkan.hpp> #include <vulkan/vulkan.hpp>
#include <vk_mem_alloc.hpp>
#include "Handles.hpp" #include "Handles.hpp"
...@@ -30,9 +31,8 @@ namespace vkcv ...@@ -30,9 +31,8 @@ namespace vkcv
struct Buffer struct Buffer
{ {
vk::Buffer m_handle; vk::Buffer m_handle;
vk::DeviceMemory m_memory; vma::Allocation m_allocation;
size_t m_size = 0; size_t m_size = 0;
void* m_mapped = nullptr;
bool m_mappable = false; bool m_mappable = false;
}; };
...@@ -70,7 +70,7 @@ namespace vkcv ...@@ -70,7 +70,7 @@ namespace vkcv
* @param memoryType Type of buffers memory * @param memoryType Type of buffers memory
* @return New buffer handle * @return New buffer handle
*/ */
BufferHandle createBuffer(BufferType type, size_t size, BufferMemoryType memoryType); BufferHandle createBuffer(BufferType type, size_t size, BufferMemoryType memoryType, bool supportIndirect);
/** /**
* Returns the Vulkan buffer handle of a buffer * Returns the Vulkan buffer handle of a buffer
......
#pragma once #pragma once
#include <vulkan/vulkan.hpp> #include <vulkan/vulkan.hpp>
#include <vk_mem_alloc.hpp>
#include "QueueManager.hpp" #include "QueueManager.hpp"
#include "DrawcallRecording.hpp"
namespace vkcv namespace vkcv
{ {
...@@ -32,12 +34,15 @@ namespace vkcv ...@@ -32,12 +34,15 @@ namespace vkcv
[[nodiscard]] [[nodiscard]]
const QueueManager& getQueueManager() const; const QueueManager& getQueueManager() const;
[[nodiscard]]
const vma::Allocator& getAllocator() const;
static Context create(const char *applicationName, static Context create(const char *applicationName,
uint32_t applicationVersion, uint32_t applicationVersion,
std::vector<vk::QueueFlagBits> queueFlags, const std::vector<vk::QueueFlagBits>& queueFlags,
std::vector<const char *> instanceExtensions, const std::vector<const char *>& instanceExtensions,
std::vector<const char *> deviceExtensions); const std::vector<const char *>& deviceExtensions);
private: private:
/** /**
...@@ -47,11 +52,14 @@ namespace vkcv ...@@ -47,11 +52,14 @@ namespace vkcv
* @param physicalDevice Vulkan-PhysicalDevice * @param physicalDevice Vulkan-PhysicalDevice
* @param device Vulkan-Device * @param device Vulkan-Device
*/ */
Context(vk::Instance instance, vk::PhysicalDevice physicalDevice, vk::Device device, QueueManager&& queueManager) noexcept; Context(vk::Instance instance, vk::PhysicalDevice physicalDevice, vk::Device device,
QueueManager&& queueManager, vma::Allocator&& allocator) noexcept;
vk::Instance m_Instance; vk::Instance m_Instance;
vk::PhysicalDevice m_PhysicalDevice; vk::PhysicalDevice m_PhysicalDevice;
vk::Device m_Device; vk::Device m_Device;
QueueManager m_QueueManager; QueueManager m_QueueManager;
vma::Allocator m_Allocator;
}; };
} }
...@@ -138,9 +138,9 @@ namespace vkcv ...@@ -138,9 +138,9 @@ namespace vkcv
static Core create(Window &window, static Core create(Window &window,
const char *applicationName, const char *applicationName,
uint32_t applicationVersion, uint32_t applicationVersion,
std::vector<vk::QueueFlagBits> queueFlags = {}, const std::vector<vk::QueueFlagBits>& queueFlags = {},
std::vector<const char*> instanceExtensions = {}, const std::vector<const char*>& instanceExtensions = {},
std::vector<const char*> deviceExtensions = {}); const std::vector<const char*>& deviceExtensions = {});
/** /**
* Creates a basic vulkan graphics pipeline using @p config from the pipeline config class and returns it using the @p handle. * Creates a basic vulkan graphics pipeline using @p config from the pipeline config class and returns it using the @p handle.
...@@ -163,7 +163,7 @@ namespace vkcv ...@@ -163,7 +163,7 @@ namespace vkcv
*/ */
[[nodiscard]] [[nodiscard]]
PipelineHandle createComputePipeline( PipelineHandle createComputePipeline(
const ShaderProgram &config, const ShaderProgram &shaderProgram,
const std::vector<vk::DescriptorSetLayout> &descriptorSetLayouts); const std::vector<vk::DescriptorSetLayout> &descriptorSetLayouts);
/** /**
...@@ -185,8 +185,8 @@ namespace vkcv ...@@ -185,8 +185,8 @@ namespace vkcv
* return Buffer-Object * return Buffer-Object
*/ */
template<typename T> template<typename T>
Buffer<T> createBuffer(vkcv::BufferType type, size_t count, BufferMemoryType memoryType = BufferMemoryType::DEVICE_LOCAL) { Buffer<T> createBuffer(vkcv::BufferType type, size_t count, BufferMemoryType memoryType = BufferMemoryType::DEVICE_LOCAL, bool supportIndirect = false) {
return Buffer<T>::create(m_BufferManager.get(), type, count, memoryType); return Buffer<T>::create(m_BufferManager.get(), type, count, memoryType, supportIndirect);
} }
/** /**
...@@ -196,11 +196,13 @@ namespace vkcv ...@@ -196,11 +196,13 @@ namespace vkcv
* @param minFilter Minimizing filter * @param minFilter Minimizing filter
* @param mipmapMode Mipmapping filter * @param mipmapMode Mipmapping filter
* @param addressMode Address mode * @param addressMode Address mode
* @param mipLodBias Mip level of detail bias
* @return Sampler handle * @return Sampler handle
*/ */
[[nodiscard]] [[nodiscard]]
SamplerHandle createSampler(SamplerFilterType magFilter, SamplerFilterType minFilter, SamplerHandle createSampler(SamplerFilterType magFilter, SamplerFilterType minFilter,
SamplerMipmapMode mipmapMode, SamplerAddressMode addressMode); SamplerMipmapMode mipmapMode, SamplerAddressMode addressMode,
float mipLodBias = 0.0f);
/** /**
* Creates an #Image with a given format, width, height and depth. * Creates an #Image with a given format, width, height and depth.
...@@ -223,9 +225,13 @@ namespace vkcv ...@@ -223,9 +225,13 @@ namespace vkcv
Multisampling multisampling = Multisampling::None); Multisampling multisampling = Multisampling::None);
[[nodiscard]] [[nodiscard]]
const uint32_t getImageWidth(ImageHandle imageHandle); uint32_t getImageWidth(const ImageHandle& image);
[[nodiscard]] [[nodiscard]]
const uint32_t getImageHeight(ImageHandle imageHandle); uint32_t getImageHeight(const ImageHandle& image);
[[nodiscard]]
vk::Format getImageFormat(const ImageHandle& image);
/** TODO: /** TODO:
* @param setDescriptions * @param setDescriptions
...@@ -243,19 +249,35 @@ namespace vkcv ...@@ -243,19 +249,35 @@ namespace vkcv
bool beginFrame(uint32_t& width, uint32_t& height); bool beginFrame(uint32_t& width, uint32_t& height);
void recordDrawcallsToCmdStream( void recordDrawcallsToCmdStream(
const CommandStreamHandle cmdStreamHandle, const CommandStreamHandle cmdStreamHandle,
const PassHandle renderpassHandle, const PassHandle renderpassHandle,
const PipelineHandle pipelineHandle, const PipelineHandle pipelineHandle,
const PushConstantData &pushConstantData, const PushConstants &pushConstants,
const std::vector<DrawcallInfo> &drawcalls, const std::vector<DrawcallInfo> &drawcalls,
const std::vector<ImageHandle> &renderTargets); const std::vector<ImageHandle> &renderTargets);
void recordMeshShaderDrawcalls(
const CommandStreamHandle cmdStreamHandle,
const PassHandle renderpassHandle,
const PipelineHandle pipelineHandle,
const PushConstants& pushConstantData,
const std::vector<MeshShaderDrawcall>& drawcalls,
const std::vector<ImageHandle>& renderTargets);
void recordComputeDispatchToCmdStream( void recordComputeDispatchToCmdStream(
CommandStreamHandle cmdStream, CommandStreamHandle cmdStream,
PipelineHandle computePipeline, PipelineHandle computePipeline,
const uint32_t dispatchCount[3], const uint32_t dispatchCount[3],
const std::vector<DescriptorSetUsage> &descriptorSetUsages, const std::vector<DescriptorSetUsage> &descriptorSetUsages,
const PushConstantData& pushConstantData); const PushConstants& pushConstants);
void recordComputeIndirectDispatchToCmdStream(
const CommandStreamHandle cmdStream,
const PipelineHandle computePipeline,
const vkcv::BufferHandle buffer,
const size_t bufferArgOffset,
const std::vector<DescriptorSetUsage>& descriptorSetUsages,
const PushConstants& pushConstants);
/** /**
* @brief end recording and present image * @brief end recording and present image
...@@ -283,15 +305,21 @@ namespace vkcv ...@@ -283,15 +305,21 @@ namespace vkcv
const RecordCommandFunction &record, const RecordCommandFunction &record,
const FinishCommandFunction &finish); const FinishCommandFunction &finish);
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 prepareImageForStorage(const CommandStreamHandle& cmdStream, const ImageHandle& image);
void recordImageMemoryBarrier(const CommandStreamHandle cmdStream, const ImageHandle image); void recordImageMemoryBarrier(const CommandStreamHandle& cmdStream, const ImageHandle& image);
void recordBufferMemoryBarrier(const CommandStreamHandle cmdStream, const BufferHandle buffer); void recordBufferMemoryBarrier(const CommandStreamHandle& cmdStream, const BufferHandle& buffer);
void resolveMSAAImage(CommandStreamHandle cmdStream, ImageHandle src, ImageHandle dst); void resolveMSAAImage(const CommandStreamHandle& cmdStream, const ImageHandle& src, const ImageHandle& dst);
[[nodiscard]]
vk::ImageView getSwapchainImageView() const; vk::ImageView getSwapchainImageView() const;
void recordMemoryBarrier(const CommandStreamHandle& cmdStream);
void recordBlitImage(const CommandStreamHandle& cmdStream, const ImageHandle& src, const ImageHandle& dst,
SamplerFilterType filterType);
}; };
} }
...@@ -11,6 +11,7 @@ namespace vkcv ...@@ -11,6 +11,7 @@ namespace vkcv
{ {
vk::DescriptorSet vulkanHandle; vk::DescriptorSet vulkanHandle;
vk::DescriptorSetLayout layout; vk::DescriptorSetLayout layout;
size_t poolIndex;
}; };
/* /*
...@@ -22,7 +23,9 @@ namespace vkcv ...@@ -22,7 +23,9 @@ namespace vkcv
STORAGE_BUFFER, STORAGE_BUFFER,
SAMPLER, SAMPLER,
IMAGE_SAMPLED, IMAGE_SAMPLED,
IMAGE_STORAGE IMAGE_STORAGE,
UNIFORM_BUFFER_DYNAMIC,
STORAGE_BUFFER_DYNAMIC
}; };
/* /*
......
...@@ -20,16 +20,15 @@ namespace vkcv { ...@@ -20,16 +20,15 @@ namespace vkcv {
uint32_t mipLevel; uint32_t mipLevel;
}; };
struct UniformBufferDescriptorWrite { struct BufferDescriptorWrite {
inline UniformBufferDescriptorWrite(uint32_t binding, BufferHandle buffer) : binding(binding), buffer(buffer) {}; inline BufferDescriptorWrite(uint32_t binding, BufferHandle buffer, bool dynamic = false,
uint32_t binding; uint32_t offset = 0, uint32_t size = 0) :
BufferHandle buffer; binding(binding), buffer(buffer), dynamic(dynamic), offset(offset), size(size) {};
};
struct StorageBufferDescriptorWrite {
inline StorageBufferDescriptorWrite(uint32_t binding, BufferHandle buffer) : binding(binding), buffer(buffer) {};
uint32_t binding; uint32_t binding;
BufferHandle buffer; BufferHandle buffer;
bool dynamic;
uint32_t offset;
uint32_t size;
}; };
struct SamplerDescriptorWrite { struct SamplerDescriptorWrite {
...@@ -41,8 +40,8 @@ namespace vkcv { ...@@ -41,8 +40,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<BufferDescriptorWrite> uniformBufferWrites;
std::vector<StorageBufferDescriptorWrite> storageBufferWrites; std::vector<BufferDescriptorWrite> storageBufferWrites;
std::vector<SamplerDescriptorWrite> samplerWrites; std::vector<SamplerDescriptorWrite> samplerWrites;
}; };
} }
\ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <vulkan/vulkan.hpp> #include <vulkan/vulkan.hpp>
#include <vkcv/Handles.hpp> #include <vkcv/Handles.hpp>
#include <vkcv/DescriptorConfig.hpp> #include <vkcv/DescriptorConfig.hpp>
#include <vkcv/PushConstants.hpp>
namespace vkcv { namespace vkcv {
struct VertexBufferBinding { struct VertexBufferBinding {
...@@ -12,28 +13,41 @@ namespace vkcv { ...@@ -12,28 +13,41 @@ namespace vkcv {
vk::Buffer buffer; vk::Buffer buffer;
}; };
enum class IndexBitCount{
Bit16,
Bit32
};
struct DescriptorSetUsage { struct DescriptorSetUsage {
inline DescriptorSetUsage(uint32_t setLocation, vk::DescriptorSet vulkanHandle) noexcept inline DescriptorSetUsage(uint32_t setLocation, vk::DescriptorSet vulkanHandle,
: setLocation(setLocation), vulkanHandle(vulkanHandle) {} const std::vector<uint32_t>& dynamicOffsets = {}) noexcept
: setLocation(setLocation), vulkanHandle(vulkanHandle), dynamicOffsets(dynamicOffsets) {}
const uint32_t setLocation; const uint32_t setLocation;
const vk::DescriptorSet vulkanHandle; const vk::DescriptorSet vulkanHandle;
const std::vector<uint32_t> dynamicOffsets;
}; };
struct Mesh { struct Mesh {
inline Mesh(std::vector<VertexBufferBinding> vertexBufferBindings, vk::Buffer indexBuffer, size_t indexCount) noexcept
: vertexBufferBindings(vertexBufferBindings), indexBuffer(indexBuffer), indexCount(indexCount){} inline Mesh(){}
inline Mesh(
std::vector<VertexBufferBinding> vertexBufferBindings,
vk::Buffer indexBuffer,
size_t indexCount,
IndexBitCount indexBitCount = IndexBitCount::Bit16) noexcept
:
vertexBufferBindings(vertexBufferBindings),
indexBuffer(indexBuffer),
indexCount(indexCount),
indexBitCount(indexBitCount) {}
std::vector<VertexBufferBinding> vertexBufferBindings; std::vector<VertexBufferBinding> vertexBufferBindings;
vk::Buffer indexBuffer; vk::Buffer indexBuffer;
size_t indexCount; size_t indexCount;
}; IndexBitCount indexBitCount;
struct PushConstantData {
inline PushConstantData(void* data, size_t sizePerDrawcall) : data(data), sizePerDrawcall(sizePerDrawcall) {}
void* data;
size_t sizePerDrawcall;
}; };
struct DrawcallInfo { struct DrawcallInfo {
...@@ -49,7 +63,24 @@ namespace vkcv { ...@@ -49,7 +63,24 @@ namespace vkcv {
const DrawcallInfo &drawcall, const DrawcallInfo &drawcall,
vk::CommandBuffer cmdBuffer, vk::CommandBuffer cmdBuffer,
vk::PipelineLayout pipelineLayout, vk::PipelineLayout pipelineLayout,
const PushConstantData &pushConstantData, const PushConstants &pushConstants,
const size_t drawcallIndex); const size_t drawcallIndex);
} void InitMeshShaderDrawFunctions(vk::Device device);
\ No newline at end of file
struct MeshShaderDrawcall {
inline MeshShaderDrawcall(const std::vector<DescriptorSetUsage> descriptorSets, uint32_t taskCount)
: descriptorSets(descriptorSets), taskCount(taskCount) {}
std::vector<DescriptorSetUsage> descriptorSets;
uint32_t taskCount;
};
void recordMeshShaderDrawcall(
vk::CommandBuffer cmdBuffer,
vk::PipelineLayout pipelineLayout,
const PushConstants& pushConstantData,
const uint32_t pushConstantOffset,
const MeshShaderDrawcall& drawcall,
const uint32_t firstTask);
}
#pragma once #pragma once
#include <functional> #include <functional>
#ifndef __MINGW32__
#include <mutex> #include <mutex>
#endif
#include <vector>
namespace vkcv { namespace vkcv {
...@@ -27,7 +32,10 @@ namespace vkcv { ...@@ -27,7 +32,10 @@ namespace vkcv {
private: private:
std::vector< event_function<T...> > m_functions; std::vector< event_function<T...> > m_functions;
uint32_t m_id_counter; uint32_t m_id_counter;
#ifndef __MINGW32__
std::mutex m_mutex; std::mutex m_mutex;
#endif
public: public:
...@@ -75,14 +83,18 @@ namespace vkcv { ...@@ -75,14 +83,18 @@ 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() {
#ifndef __MINGW32__
m_mutex.lock(); m_mutex.lock();
#endif
} }
/** /**
* 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() {
#ifndef __MINGW32__
m_mutex.unlock(); m_mutex.unlock();
#endif
} }
explicit event(bool locked = false) { explicit event(bool locked = false) {
......