9 #define VK_CHECK_RESULT(f) \ 12 if (res != VK_SUCCESS) \ 14 F_LOG_ERROR("VkResult is {} in {} at line {}", res, __FILE__, __LINE__); \ 15 assert(res == VK_SUCCESS); \ 21 namespace GraphicsHelpers
33 void CreateBuffer(VkDevice t_Device, VkPhysicalDevice t_PhysicalDevice, VkDeviceSize t_Size, VkBufferUsageFlags t_Usage, VkMemoryPropertyFlags t_Properties, VkBuffer& t_Buffer, VkDeviceMemory& t_BuffMemory);
44 VkImageTiling t_Tiling,
45 VkImageUsageFlags t_Useage,
46 VkMemoryPropertyFlags t_Props,
48 VkDeviceMemory& t_Memory,
49 VkSampleCountFlagBits t_NumSamples = VK_SAMPLE_COUNT_1_BIT
62 VkImageTiling t_Tiling,
63 VkImageUsageFlags t_Useage,
64 VkMemoryPropertyFlags t_Props,
65 VkImageCreateFlags t_flags,
67 VkDeviceMemory& t_Memory,
68 VkSampleCountFlagBits t_NumSamples = VK_SAMPLE_COUNT_1_BIT
74 VkSamplerMipmapMode t_mipmapMode,
75 VkSamplerAddressMode t_addressModeU,
76 VkSamplerAddressMode t_addressModeV,
77 VkSamplerAddressMode t_addressModeM,
78 VkBorderColor t_borderColor,
83 VkCommandBuffer t_cmdbuffer,
85 VkImageAspectFlags t_aspectMask,
86 VkImageLayout t_oldImageLayout,
87 VkImageLayout t_newImageLayout,
88 VkPipelineStageFlags t_srcStageMask,
89 VkPipelineStageFlags t_dstStageMask
93 VkCommandBuffer t_cmdbuffer,
95 VkImageLayout t_oldImageLayout,
96 VkImageLayout t_newImageLayout,
97 VkImageSubresourceRange t_subresourceRange,
98 VkPipelineStageFlags t_srcStageMask,
99 VkPipelineStageFlags t_dstStageMask
103 VkCommandPool* t_commandPool,
104 VkCommandPoolCreateFlags t_flags
108 VkCommandBuffer* t_commandBuffer,
109 UINT32 t_commandBufferCount,
110 VkCommandPool& t_commandPool
120 VkImageView
CreateVkImageView(VkImage t_Image, VkFormat t_Format, VkImageAspectFlags t_AspectFalgs,
UINT32 t_MipLevels = 1);
122 VkFormat
FindSupportedFormat(
const std::vector<VkFormat>& t_Candidates, VkImageTiling t_Tiling, VkFormatFeatureFlags t_Features);
127 VkImageLayout t_oldLayout,
128 VkImageLayout t_NewLayout,
142 namespace Initializers
151 const std::vector<VkDescriptorPoolSize>& t_poolSizes,
158 VkDescriptorType t_type,
159 VkShaderStageFlags t_stageFlags,
161 UINT32 t_descriptorCount = 1
165 const std::vector<VkDescriptorSetLayoutBinding>& t_bindings
170 VkRenderPassBeginInfo renderPassBeginInfo{};
171 renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
172 return renderPassBeginInfo;
177 VkDescriptorSet t_DstSet,
180 VkDeviceSize t_Offset = 0);
184 VkDescriptorSet t_DstSet,
187 VkDeviceSize t_Offset = 0);
194 VkDescriptorPool t_descriptorPool,
195 const VkDescriptorSetLayout* t_pSetLayouts,
196 UINT32 t_descriptorSetCount
201 VkImageView t_imageView,
202 VkImageLayout t_imageLayout
206 VkDescriptorSet t_dstSet,
207 VkDescriptorType t_type,
209 VkDescriptorImageInfo* imageInfo,
210 UINT32 descriptorCount = 1
214 VkShaderStageFlags t_stageFlags,
220 const VkDescriptorSetLayout* t_pSetLayouts,
221 UINT32 t_setLayoutCount = 1
225 VkPrimitiveTopology t_topology,
226 VkPipelineInputAssemblyStateCreateFlags t_flags,
227 VkBool32 t_primitiveRestartEnable
231 VkPolygonMode t_polygonMode,
232 VkCullModeFlags t_cullMode,
233 VkFrontFace t_frontFace,
234 VkPipelineRasterizationStateCreateFlags t_flags = 0
239 const VkPipelineColorBlendAttachmentState* t_pAttachments
243 VkColorComponentFlags t_colorWriteMask,
244 VkBool32 t_blendEnable
248 VkBool32 depthTestEnable,
249 VkBool32 depthWriteEnable,
250 VkCompareOp depthCompareOp)
252 VkPipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo{};
253 pipelineDepthStencilStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
254 pipelineDepthStencilStateCreateInfo.depthTestEnable = depthTestEnable;
255 pipelineDepthStencilStateCreateInfo.depthWriteEnable = depthWriteEnable;
256 pipelineDepthStencilStateCreateInfo.depthCompareOp = depthCompareOp;
257 pipelineDepthStencilStateCreateInfo.front = pipelineDepthStencilStateCreateInfo.back;
258 pipelineDepthStencilStateCreateInfo.back.compareOp = VK_COMPARE_OP_ALWAYS;
259 return pipelineDepthStencilStateCreateInfo;
263 const VkDynamicState* pDynamicStates,
264 uint32_t dynamicStateCount,
265 VkPipelineDynamicStateCreateFlags flags = 0)
267 VkPipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo{};
268 pipelineDynamicStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
269 pipelineDynamicStateCreateInfo.pDynamicStates = pDynamicStates;
270 pipelineDynamicStateCreateInfo.dynamicStateCount = dynamicStateCount;
271 pipelineDynamicStateCreateInfo.flags = flags;
272 return pipelineDynamicStateCreateInfo;
276 VkBool32 t_depthTestEnable,
277 VkBool32 t_depthWriteEnable,
278 VkCompareOp t_depthCompareOp
284 VkPipelineViewportStateCreateFlags t_flags = 0
288 VkSampleCountFlagBits t_rasterizationSamples,
289 VkPipelineMultisampleStateCreateFlags t_flags = 0
293 const std::vector<VkDynamicState>& t_pDynamicStates,
294 VkPipelineDynamicStateCreateFlags t_flags = 0
298 VkPipelineLayout t_layout,
299 VkRenderPass t_renderPass,
300 VkPipelineCreateFlags t_flags = 0
306 VkVertexInputRate t_inputRate
324 VkDescriptorType type,
325 VkShaderStageFlags stageFlags,
327 uint32_t descriptorCount = 1
331 VkDescriptorSet dstSet,
332 VkDescriptorType type,
334 VkDescriptorBufferInfo* bufferInfo,
335 uint32_t descriptorCount = 1
VkFormat FindSupportedFormat(const std::vector< VkFormat > &t_Candidates, VkImageTiling t_Tiling, VkFormatFeatureFlags t_Features)
Definition: GraphicsHelpers.cpp:566
VkDescriptorSetLayoutBinding DescriptorSetLayoutBinding(VkDescriptorType type, VkShaderStageFlags stageFlags, uint32_t binding, uint32_t descriptorCount=1)
Definition: GraphicsHelpers.cpp:629
VkWriteDescriptorSet WriteDescriptorSetImage(Texture *t_Image, VkDescriptorSet t_DstSet, UINT32 t_Binding, UINT32 t_Set=0, VkDeviceSize t_Offset=0)
Definition: GraphicsHelpers.cpp:731
bool HasStencilComponent(VkFormat t_format)
Returns true if the given format has a stencil component.
Definition: GraphicsHelpers.cpp:613
VkRenderPassBeginInfo RenderPassBeginInfo()
Definition: GraphicsHelpers.h:168
VkPipelineDynamicStateCreateInfo PipelineDynamicStateCreateInfo(const std::vector< VkDynamicState > &t_pDynamicStates, VkPipelineDynamicStateCreateFlags t_flags=0)
Definition: GraphicsHelpers.cpp:901
void CreateCommandBuffers(VkCommandBuffer *t_commandBuffer, UINT32 t_commandBufferCount, VkCommandPool &t_commandPool)
Definition: GraphicsHelpers.cpp:408
VkPushConstantRange PushConstantRange(VkShaderStageFlags t_stageFlags, UINT32 t_size, UINT32 t_offset)
Definition: GraphicsHelpers.cpp:793
void SetImageLayout(VkCommandBuffer t_cmdbuffer, VkImage t_image, VkImageAspectFlags t_aspectMask, VkImageLayout t_oldImageLayout, VkImageLayout t_newImageLayout, VkPipelineStageFlags t_srcStageMask, VkPipelineStageFlags t_dstStageMask)
Definition: GraphicsHelpers.cpp:245
VkDescriptorSetLayoutCreateInfo DescriptorSetLayoutCreateInfo(const std::vector< VkDescriptorSetLayoutBinding > &t_bindings)
Definition: GraphicsHelpers.cpp:708
VkShaderModule CreateShaderModule(std::shared_ptr< File > t_ShaderCode)
Definition: GraphicsHelpers.cpp:592
void CreateVkSampler(VkFilter t_magFilter, VkFilter t_minFilter, VkSamplerMipmapMode t_mipmapMode, VkSamplerAddressMode t_addressModeU, VkSamplerAddressMode t_addressModeV, VkSamplerAddressMode t_addressModeM, VkBorderColor t_borderColor, VkSampler &t_sampler)
Definition: GraphicsHelpers.cpp:214
void CreateBuffer(VkDevice t_Device, VkPhysicalDevice t_PhysicalDevice, VkDeviceSize t_Size, VkBufferUsageFlags t_Usage, VkMemoryPropertyFlags t_Properties, VkBuffer &t_Buffer, VkDeviceMemory &t_BuffMemory)
Definition: GraphicsHelpers.cpp:30
VkDescriptorImageInfo DescriptorImageInfo(VkSampler t_sampler, VkImageView t_imageView, VkImageLayout t_imageLayout)
Definition: GraphicsHelpers.cpp:772
void CreateCommandPool(VkCommandPool *t_commandPool, VkCommandPoolCreateFlags t_flags)
Definition: GraphicsHelpers.cpp:392
An image represents a 2D file that has data about each pixel in the image.
Definition: Texture.h:11
VkVertexInputBindingDescription VertexInputBindingDescription(UINT32 t_binding, UINT32 t_stride, VkVertexInputRate t_inputRate)
Definition: GraphicsHelpers.cpp:928
VkDescriptorSetLayoutBinding DescriptorSetLayoutBindings(VkDescriptorType t_type, VkShaderStageFlags t_stageFlags, UINT32 t_binding, UINT32 t_descriptorCount=1)
Definition: GraphicsHelpers.cpp:695
VkWriteDescriptorSet WriteDescriptorSet(VkDescriptorSet dstSet, VkDescriptorType type, uint32_t binding, VkDescriptorBufferInfo *bufferInfo, uint32_t descriptorCount=1)
Definition: GraphicsHelpers.cpp:639
VkPipelineViewportStateCreateInfo PipelineViewportStateCreateInfo(UINT32 t_viewportCount, UINT32 t_scissorCount, VkPipelineViewportStateCreateFlags t_flags=0)
Definition: GraphicsHelpers.cpp:877
VkPipelineInputAssemblyStateCreateInfo PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology t_topology, VkPipelineInputAssemblyStateCreateFlags t_flags, VkBool32 t_primitiveRestartEnable)
Definition: GraphicsHelpers.cpp:813
VkPipelineDepthStencilStateCreateInfo DepthStencilState(VkBool32 t_depthTestEnable, VkBool32 t_depthWriteEnable, VkCompareOp t_depthCompareOp)
Definition: GraphicsHelpers.cpp:862
VkMappedMemoryRange MappedMemoryRange()
Definition: GraphicsHelpers.cpp:622
VkSamplerCreateInfo SamplerCreateInfo()
Definition: GraphicsHelpers.cpp:747
VkPipelineVertexInputStateCreateInfo PiplineVertexInptStateCreateInfo()
Definition: GraphicsHelpers.cpp:661
VkPipelineColorBlendAttachmentState PipelineColorBlendAttachmentState(VkColorComponentFlags t_colorWriteMask, VkBool32 t_blendEnable)
Definition: GraphicsHelpers.cpp:854
VkWriteDescriptorSet WriteDescriptorSetUniform(Buffer *t_Buffer, VkDescriptorSet t_DstSet, UINT32 t_Binding, UINT32 t_Set=0, VkDeviceSize t_Offset=0)
Definition: GraphicsHelpers.cpp:717
void CreatePipelineCache(VkPipelineCache &t_PipelineCache)
Definition: GraphicsHelpers.cpp:427
VkGraphicsPipelineCreateInfo PipelineCreateInfo(VkPipelineLayout t_layout, VkRenderPass t_renderPass, VkPipelineCreateFlags t_flags=0)
Definition: GraphicsHelpers.cpp:913
void TransitionImageLayout(VkImage t_Image, VkFormat t_Format, VkImageLayout t_oldLayout, VkImageLayout t_NewLayout, UINT32 t_MipLevels=1)
Definition: GraphicsHelpers.cpp:441
VkViewport Viewport(float t_width, float t_height, float t_minDepth, float t_maxDepth)
Definition: GraphicsHelpers.cpp:954
VkPipelineLayoutCreateInfo PiplineLayoutCreateInfo(const VkDescriptorSetLayout *t_pSetLayouts, UINT32 t_setLayoutCount=1)
Definition: GraphicsHelpers.cpp:802
VkSemaphore CreateSemaphore(VkDevice t_Dev)
Definition: GraphicsHelpers.cpp:203
VkPipelineColorBlendStateCreateInfo PipelineColorBlendStateCreateInfo(UINT32 t_attachmentCount, const VkPipelineColorBlendAttachmentState *t_pAttachments)
Definition: GraphicsHelpers.cpp:843
VkPipelineRasterizationStateCreateInfo PipelineRasterizationStateCreateInfo(VkPolygonMode t_polygonMode, VkCullModeFlags t_cullMode, VkFrontFace t_frontFace, VkPipelineRasterizationStateCreateFlags t_flags=0)
Definition: GraphicsHelpers.cpp:826
VkDescriptorPoolSize DescriptorPoolSize(VkDescriptorType t_type, UINT32 t_descriptorCount)
Definition: GraphicsHelpers.cpp:668
VkVertexInputAttributeDescription VertexInputAttributeDescription(UINT32 t_binding, UINT32 t_location, VkFormat t_format, UINT32 t_offset)
Definition: GraphicsHelpers.cpp:940
UINT32 FindMemoryType(VkPhysicalDevice t_PhysicalDevice, UINT32 t_Filter, VkMemoryPropertyFlags t_Props)
Find a suitable memory type for use on the current device.
Definition: GraphicsHelpers.cpp:11
void CreateVkImage(VkDevice t_Dev, UINT32 t_Width, UINT32 t_Height, VkFormat t_Format, VkImageTiling t_Tiling, VkImageUsageFlags t_Useage, VkMemoryPropertyFlags t_Props, VkImage &t_Image, VkDeviceMemory &t_Memory, VkSampleCountFlagBits t_NumSamples=VK_SAMPLE_COUNT_1_BIT)
Definition: GraphicsHelpers.cpp:110
A Buffer represents a Vulkan buffer with a size, buffer pointer, and buffer memory.
Definition: Buffer.h:11
VkMemoryAllocateInfo MemoryAllocateInfo()
Definition: GraphicsHelpers.cpp:688
VkRect2D Rect2D(int32_t width, int32_t height, int32_t offsetX, int32_t offsetY)
Definition: GraphicsHelpers.cpp:651
uint32_t UINT32
Definition: FlingTypes.h:13
VkImageView CreateVkImageView(VkImage t_Image, VkFormat t_Format, VkImageAspectFlags t_AspectFalgs, UINT32 t_MipLevels=1)
Create a an image view for Vulkan with the given format.
Definition: GraphicsHelpers.cpp:531
VkPipelineMultisampleStateCreateInfo PipelineMultiSampleStateCreateInfo(VkSampleCountFlagBits t_rasterizationSamples, VkPipelineMultisampleStateCreateFlags t_flags=0)
Definition: GraphicsHelpers.cpp:890
VkPipelineDepthStencilStateCreateInfo PipelineDepthStencilStateCreateInfo(VkBool32 depthTestEnable, VkBool32 depthWriteEnable, VkCompareOp depthCompareOp)
Definition: GraphicsHelpers.h:247
VkDescriptorSetAllocateInfo DescriptorSetAllocateInfo(VkDescriptorPool t_descriptorPool, const VkDescriptorSetLayout *t_pSetLayouts, UINT32 t_descriptorSetCount)
Definition: GraphicsHelpers.cpp:762
VkDescriptorPoolCreateInfo DescriptorPoolCreateInfo(const std::vector< VkDescriptorPoolSize > &t_poolSizes, UINT32 t_maxSets)
Definition: GraphicsHelpers.cpp:676
void EndSingleTimeCommands(VkCommandBuffer t_CommandBuffer)
Definition: GraphicsHelpers.cpp:89
VkImageViewCreateInfo ImageViewCreateInfo()
Definition: GraphicsHelpers.cpp:755
VkCommandBuffer BeginSingleTimeCommands()
Definition: GraphicsHelpers.cpp:65