Change ColumnLimit with clang-format from 120 to 160.
This commit is contained in:
@@ -20,8 +20,8 @@
|
||||
#define GLFW_INCLUDE_NONE
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
|
||||
namespace vk
|
||||
{
|
||||
@@ -40,24 +40,15 @@ namespace vk
|
||||
}
|
||||
|
||||
template <typename Func>
|
||||
void oneTimeSubmit( vk::Device const & device,
|
||||
vk::CommandPool const & commandPool,
|
||||
vk::Queue const & queue,
|
||||
Func const & func )
|
||||
void oneTimeSubmit( vk::Device const & device, vk::CommandPool const & commandPool, vk::Queue const & queue, Func const & func )
|
||||
{
|
||||
vk::CommandBuffer commandBuffer =
|
||||
device
|
||||
.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front();
|
||||
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
|
||||
oneTimeSubmit( commandBuffer, queue, func );
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void copyToDevice( vk::Device const & device,
|
||||
vk::DeviceMemory const & deviceMemory,
|
||||
T const * pData,
|
||||
size_t count,
|
||||
vk::DeviceSize stride = sizeof( T ) )
|
||||
void copyToDevice( vk::Device const & device, vk::DeviceMemory const & deviceMemory, T const * pData, size_t count, vk::DeviceSize stride = sizeof( T ) )
|
||||
{
|
||||
assert( sizeof( T ) <= stride );
|
||||
uint8_t * deviceData = static_cast<uint8_t *>( device.mapMemory( deviceMemory, 0, count * stride ) );
|
||||
@@ -88,11 +79,8 @@ namespace vk
|
||||
return v < lo ? lo : hi < v ? hi : v;
|
||||
}
|
||||
|
||||
void setImageLayout( vk::CommandBuffer const & commandBuffer,
|
||||
vk::Image image,
|
||||
vk::Format format,
|
||||
vk::ImageLayout oldImageLayout,
|
||||
vk::ImageLayout newImageLayout );
|
||||
void setImageLayout(
|
||||
vk::CommandBuffer const & commandBuffer, vk::Image image, vk::Format format, vk::ImageLayout oldImageLayout, vk::ImageLayout newImageLayout );
|
||||
|
||||
struct WindowData
|
||||
{
|
||||
@@ -114,8 +102,7 @@ namespace vk
|
||||
vk::Device const & device,
|
||||
vk::DeviceSize size,
|
||||
vk::BufferUsageFlags usage,
|
||||
vk::MemoryPropertyFlags propertyFlags = vk::MemoryPropertyFlagBits::eHostVisible |
|
||||
vk::MemoryPropertyFlagBits::eHostCoherent );
|
||||
vk::MemoryPropertyFlags propertyFlags = vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
|
||||
|
||||
void clear( vk::Device const & device )
|
||||
{
|
||||
@@ -126,8 +113,7 @@ namespace vk
|
||||
template <typename DataType>
|
||||
void upload( vk::Device const & device, DataType const & data ) const
|
||||
{
|
||||
assert( ( m_propertyFlags & vk::MemoryPropertyFlagBits::eHostCoherent ) &&
|
||||
( m_propertyFlags & vk::MemoryPropertyFlagBits::eHostVisible ) );
|
||||
assert( ( m_propertyFlags & vk::MemoryPropertyFlagBits::eHostCoherent ) && ( m_propertyFlags & vk::MemoryPropertyFlagBits::eHostVisible ) );
|
||||
assert( sizeof( DataType ) <= m_size );
|
||||
|
||||
void * dataPtr = device.mapMemory( deviceMemory, 0, sizeof( DataType ) );
|
||||
@@ -166,9 +152,11 @@ namespace vk
|
||||
vk::su::BufferData stagingBuffer( physicalDevice, device, dataSize, vk::BufferUsageFlagBits::eTransferSrc );
|
||||
copyToDevice( device, stagingBuffer.deviceMemory, data.data(), data.size(), elementSize );
|
||||
|
||||
vk::su::oneTimeSubmit( device, commandPool, queue, [&]( vk::CommandBuffer const & commandBuffer ) {
|
||||
commandBuffer.copyBuffer( stagingBuffer.buffer, buffer, vk::BufferCopy( 0, 0, dataSize ) );
|
||||
} );
|
||||
vk::su::oneTimeSubmit( device,
|
||||
commandPool,
|
||||
queue,
|
||||
[&]( vk::CommandBuffer const & commandBuffer )
|
||||
{ commandBuffer.copyBuffer( stagingBuffer.buffer, buffer, vk::BufferCopy( 0, 0, dataSize ) ); } );
|
||||
|
||||
stagingBuffer.clear( device );
|
||||
}
|
||||
@@ -210,10 +198,7 @@ namespace vk
|
||||
|
||||
struct DepthBufferData : public ImageData
|
||||
{
|
||||
DepthBufferData( vk::PhysicalDevice const & physicalDevice,
|
||||
vk::Device const & device,
|
||||
vk::Format format,
|
||||
vk::Extent2D const & extent );
|
||||
DepthBufferData( vk::PhysicalDevice const & physicalDevice, vk::Device const & device, vk::Format format, vk::Extent2D const & extent );
|
||||
};
|
||||
|
||||
struct SurfaceData
|
||||
@@ -256,8 +241,7 @@ namespace vk
|
||||
class CheckerboardImageGenerator
|
||||
{
|
||||
public:
|
||||
CheckerboardImageGenerator( std::array<uint8_t, 3> const & rgb0 = { { 0, 0, 0 } },
|
||||
std::array<uint8_t, 3> const & rgb1 = { { 255, 255, 255 } } );
|
||||
CheckerboardImageGenerator( std::array<uint8_t, 3> const & rgb0 = { { 0, 0, 0 } }, std::array<uint8_t, 3> const & rgb1 = { { 255, 255, 255 } } );
|
||||
|
||||
void operator()( void * data, vk::Extent2D & extent ) const;
|
||||
|
||||
@@ -311,50 +295,34 @@ namespace vk
|
||||
}
|
||||
|
||||
template <typename ImageGenerator>
|
||||
void setImage( vk::Device const & device,
|
||||
vk::CommandBuffer const & commandBuffer,
|
||||
ImageGenerator const & imageGenerator )
|
||||
void setImage( vk::Device const & device, vk::CommandBuffer const & commandBuffer, ImageGenerator const & imageGenerator )
|
||||
{
|
||||
void * data = needsStaging
|
||||
? device.mapMemory( stagingBufferData->deviceMemory,
|
||||
0,
|
||||
device.getBufferMemoryRequirements( stagingBufferData->buffer ).size )
|
||||
: device.mapMemory(
|
||||
imageData->deviceMemory, 0, device.getImageMemoryRequirements( imageData->image ).size );
|
||||
? device.mapMemory( stagingBufferData->deviceMemory, 0, device.getBufferMemoryRequirements( stagingBufferData->buffer ).size )
|
||||
: device.mapMemory( imageData->deviceMemory, 0, device.getImageMemoryRequirements( imageData->image ).size );
|
||||
imageGenerator( data, extent );
|
||||
device.unmapMemory( needsStaging ? stagingBufferData->deviceMemory : imageData->deviceMemory );
|
||||
|
||||
if ( needsStaging )
|
||||
{
|
||||
// Since we're going to blit to the texture image, set its layout to eTransferDstOptimal
|
||||
vk::su::setImageLayout( commandBuffer,
|
||||
imageData->image,
|
||||
imageData->format,
|
||||
vk::ImageLayout::eUndefined,
|
||||
vk::ImageLayout::eTransferDstOptimal );
|
||||
vk::su::setImageLayout( commandBuffer, imageData->image, imageData->format, vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal );
|
||||
vk::BufferImageCopy copyRegion( 0,
|
||||
extent.width,
|
||||
extent.height,
|
||||
vk::ImageSubresourceLayers( vk::ImageAspectFlagBits::eColor, 0, 0, 1 ),
|
||||
vk::Offset3D( 0, 0, 0 ),
|
||||
vk::Extent3D( extent, 1 ) );
|
||||
commandBuffer.copyBufferToImage(
|
||||
stagingBufferData->buffer, imageData->image, vk::ImageLayout::eTransferDstOptimal, copyRegion );
|
||||
commandBuffer.copyBufferToImage( stagingBufferData->buffer, imageData->image, vk::ImageLayout::eTransferDstOptimal, copyRegion );
|
||||
// Set the layout for the texture image from eTransferDstOptimal to SHADER_READ_ONLY
|
||||
vk::su::setImageLayout( commandBuffer,
|
||||
imageData->image,
|
||||
imageData->format,
|
||||
vk::ImageLayout::eTransferDstOptimal,
|
||||
vk::ImageLayout::eShaderReadOnlyOptimal );
|
||||
vk::su::setImageLayout(
|
||||
commandBuffer, imageData->image, imageData->format, vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::eShaderReadOnlyOptimal );
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we can use the linear tiled image as a texture, just do it
|
||||
vk::su::setImageLayout( commandBuffer,
|
||||
imageData->image,
|
||||
imageData->format,
|
||||
vk::ImageLayout::ePreinitialized,
|
||||
vk::ImageLayout::eShaderReadOnlyOptimal );
|
||||
vk::su::setImageLayout(
|
||||
commandBuffer, imageData->image, imageData->format, vk::ImageLayout::ePreinitialized, vk::ImageLayout::eShaderReadOnlyOptimal );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,63 +354,55 @@ namespace vk
|
||||
return static_cast<TargetType>( value );
|
||||
}
|
||||
|
||||
vk::DeviceMemory allocateDeviceMemory( vk::Device const & device,
|
||||
vk::PhysicalDeviceMemoryProperties const & memoryProperties,
|
||||
vk::MemoryRequirements const & memoryRequirements,
|
||||
vk::MemoryPropertyFlags memoryPropertyFlags );
|
||||
bool contains( std::vector<vk::ExtensionProperties> const & extensionProperties,
|
||||
std::string const & extensionName );
|
||||
vk::CommandPool createCommandPool( vk::Device const & device, uint32_t queueFamilyIndex );
|
||||
vk::DebugUtilsMessengerEXT createDebugUtilsMessengerEXT( vk::Instance const & instance );
|
||||
vk::DescriptorPool createDescriptorPool( vk::Device const & device,
|
||||
std::vector<vk::DescriptorPoolSize> const & poolSizes );
|
||||
vk::DescriptorSetLayout createDescriptorSetLayout(
|
||||
vk::Device const & device,
|
||||
std::vector<std::tuple<vk::DescriptorType, uint32_t, vk::ShaderStageFlags>> const & bindingData,
|
||||
vk::DescriptorSetLayoutCreateFlags flags = {} );
|
||||
vk::Device createDevice( vk::PhysicalDevice const & physicalDevice,
|
||||
uint32_t queueFamilyIndex,
|
||||
std::vector<std::string> const & extensions = {},
|
||||
vk::PhysicalDeviceFeatures const * physicalDeviceFeatures = nullptr,
|
||||
void const * pNext = nullptr );
|
||||
std::vector<vk::Framebuffer> createFramebuffers( vk::Device const & device,
|
||||
vk::RenderPass & renderPass,
|
||||
std::vector<vk::ImageView> const & imageViews,
|
||||
vk::ImageView const & depthImageView,
|
||||
vk::Extent2D const & extent );
|
||||
vk::Pipeline
|
||||
createGraphicsPipeline( vk::Device const & device,
|
||||
vk::PipelineCache const & pipelineCache,
|
||||
std::pair<vk::ShaderModule, vk::SpecializationInfo const *> const & vertexShaderData,
|
||||
std::pair<vk::ShaderModule, vk::SpecializationInfo const *> const & fragmentShaderData,
|
||||
uint32_t vertexStride,
|
||||
std::vector<std::pair<vk::Format, uint32_t>> const & vertexInputAttributeFormatOffset,
|
||||
vk::FrontFace frontFace,
|
||||
bool depthBuffered,
|
||||
vk::PipelineLayout const & pipelineLayout,
|
||||
vk::RenderPass const & renderPass );
|
||||
vk::Instance createInstance( std::string const & appName,
|
||||
std::string const & engineName,
|
||||
std::vector<std::string> const & layers = {},
|
||||
std::vector<std::string> const & extensions = {},
|
||||
uint32_t apiVersion = VK_API_VERSION_1_0 );
|
||||
vk::RenderPass createRenderPass( vk::Device const & device,
|
||||
vk::Format colorFormat,
|
||||
vk::Format depthFormat,
|
||||
vk::AttachmentLoadOp loadOp = vk::AttachmentLoadOp::eClear,
|
||||
vk::ImageLayout colorFinalLayout = vk::ImageLayout::ePresentSrcKHR );
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL
|
||||
debugUtilsMessengerCallback( VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
||||
VkDebugUtilsMessageTypeFlagsEXT messageTypes,
|
||||
VkDebugUtilsMessengerCallbackDataEXT const * pCallbackData,
|
||||
void * /*pUserData*/ );
|
||||
uint32_t findGraphicsQueueFamilyIndex( std::vector<vk::QueueFamilyProperties> const & queueFamilyProperties );
|
||||
std::pair<uint32_t, uint32_t> findGraphicsAndPresentQueueFamilyIndex( vk::PhysicalDevice physicalDevice,
|
||||
vk::SurfaceKHR const & surface );
|
||||
uint32_t findMemoryType( vk::PhysicalDeviceMemoryProperties const & memoryProperties,
|
||||
uint32_t typeBits,
|
||||
vk::MemoryPropertyFlags requirementsMask );
|
||||
std::vector<char const *> gatherExtensions( std::vector<std::string> const & extensions
|
||||
vk::DeviceMemory allocateDeviceMemory( vk::Device const & device,
|
||||
vk::PhysicalDeviceMemoryProperties const & memoryProperties,
|
||||
vk::MemoryRequirements const & memoryRequirements,
|
||||
vk::MemoryPropertyFlags memoryPropertyFlags );
|
||||
bool contains( std::vector<vk::ExtensionProperties> const & extensionProperties, std::string const & extensionName );
|
||||
vk::CommandPool createCommandPool( vk::Device const & device, uint32_t queueFamilyIndex );
|
||||
vk::DebugUtilsMessengerEXT createDebugUtilsMessengerEXT( vk::Instance const & instance );
|
||||
vk::DescriptorPool createDescriptorPool( vk::Device const & device, std::vector<vk::DescriptorPoolSize> const & poolSizes );
|
||||
vk::DescriptorSetLayout createDescriptorSetLayout( vk::Device const & device,
|
||||
std::vector<std::tuple<vk::DescriptorType, uint32_t, vk::ShaderStageFlags>> const & bindingData,
|
||||
vk::DescriptorSetLayoutCreateFlags flags = {} );
|
||||
vk::Device createDevice( vk::PhysicalDevice const & physicalDevice,
|
||||
uint32_t queueFamilyIndex,
|
||||
std::vector<std::string> const & extensions = {},
|
||||
vk::PhysicalDeviceFeatures const * physicalDeviceFeatures = nullptr,
|
||||
void const * pNext = nullptr );
|
||||
std::vector<vk::Framebuffer> createFramebuffers( vk::Device const & device,
|
||||
vk::RenderPass & renderPass,
|
||||
std::vector<vk::ImageView> const & imageViews,
|
||||
vk::ImageView const & depthImageView,
|
||||
vk::Extent2D const & extent );
|
||||
vk::Pipeline createGraphicsPipeline( vk::Device const & device,
|
||||
vk::PipelineCache const & pipelineCache,
|
||||
std::pair<vk::ShaderModule, vk::SpecializationInfo const *> const & vertexShaderData,
|
||||
std::pair<vk::ShaderModule, vk::SpecializationInfo const *> const & fragmentShaderData,
|
||||
uint32_t vertexStride,
|
||||
std::vector<std::pair<vk::Format, uint32_t>> const & vertexInputAttributeFormatOffset,
|
||||
vk::FrontFace frontFace,
|
||||
bool depthBuffered,
|
||||
vk::PipelineLayout const & pipelineLayout,
|
||||
vk::RenderPass const & renderPass );
|
||||
vk::Instance createInstance( std::string const & appName,
|
||||
std::string const & engineName,
|
||||
std::vector<std::string> const & layers = {},
|
||||
std::vector<std::string> const & extensions = {},
|
||||
uint32_t apiVersion = VK_API_VERSION_1_0 );
|
||||
vk::RenderPass createRenderPass( vk::Device const & device,
|
||||
vk::Format colorFormat,
|
||||
vk::Format depthFormat,
|
||||
vk::AttachmentLoadOp loadOp = vk::AttachmentLoadOp::eClear,
|
||||
vk::ImageLayout colorFinalLayout = vk::ImageLayout::ePresentSrcKHR );
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL debugUtilsMessengerCallback( VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
||||
VkDebugUtilsMessageTypeFlagsEXT messageTypes,
|
||||
VkDebugUtilsMessengerCallbackDataEXT const * pCallbackData,
|
||||
void * /*pUserData*/ );
|
||||
uint32_t findGraphicsQueueFamilyIndex( std::vector<vk::QueueFamilyProperties> const & queueFamilyProperties );
|
||||
std::pair<uint32_t, uint32_t> findGraphicsAndPresentQueueFamilyIndex( vk::PhysicalDevice physicalDevice, vk::SurfaceKHR const & surface );
|
||||
uint32_t findMemoryType( vk::PhysicalDeviceMemoryProperties const & memoryProperties, uint32_t typeBits, vk::MemoryPropertyFlags requirementsMask );
|
||||
std::vector<char const *> gatherExtensions( std::vector<std::string> const & extensions
|
||||
#if !defined( NDEBUG )
|
||||
,
|
||||
std::vector<vk::ExtensionProperties> const & extensionProperties
|
||||
@@ -468,19 +428,17 @@ namespace vk
|
||||
vk::Format pickDepthFormat( vk::PhysicalDevice const & physicalDevice );
|
||||
vk::PresentModeKHR pickPresentMode( std::vector<vk::PresentModeKHR> const & presentModes );
|
||||
vk::SurfaceFormatKHR pickSurfaceFormat( std::vector<vk::SurfaceFormatKHR> const & formats );
|
||||
void submitAndWait( vk::Device const & device, vk::Queue const & queue, vk::CommandBuffer const & commandBuffer );
|
||||
void updateDescriptorSets(
|
||||
vk::Device const & device,
|
||||
vk::DescriptorSet const & descriptorSet,
|
||||
std::vector<std::tuple<vk::DescriptorType, vk::Buffer const &, vk::BufferView const &>> const & bufferData,
|
||||
vk::su::TextureData const & textureData,
|
||||
uint32_t bindingOffset = 0 );
|
||||
void updateDescriptorSets(
|
||||
vk::Device const & device,
|
||||
vk::DescriptorSet const & descriptorSet,
|
||||
std::vector<std::tuple<vk::DescriptorType, vk::Buffer const &, vk::BufferView const &>> const & bufferData,
|
||||
std::vector<vk::su::TextureData> const & textureData,
|
||||
uint32_t bindingOffset = 0 );
|
||||
void submitAndWait( vk::Device const & device, vk::Queue const & queue, vk::CommandBuffer const & commandBuffer );
|
||||
void updateDescriptorSets( vk::Device const & device,
|
||||
vk::DescriptorSet const & descriptorSet,
|
||||
std::vector<std::tuple<vk::DescriptorType, vk::Buffer const &, vk::BufferView const &>> const & bufferData,
|
||||
vk::su::TextureData const & textureData,
|
||||
uint32_t bindingOffset = 0 );
|
||||
void updateDescriptorSets( vk::Device const & device,
|
||||
vk::DescriptorSet const & descriptorSet,
|
||||
std::vector<std::tuple<vk::DescriptorType, vk::Buffer const &, vk::BufferView const &>> const & bufferData,
|
||||
std::vector<vk::su::TextureData> const & textureData,
|
||||
uint32_t bindingOffset = 0 );
|
||||
|
||||
} // namespace su
|
||||
} // namespace vk
|
||||
|
||||
Reference in New Issue
Block a user