13#ifndef _CS237_APPLICATION_HPP_
14#define _CS237_APPLICATION_HPP_
17#error "cs237/application.hpp should not be included directly"
42 Application (std::vector<std::string>
const &args, std::string
const &
name =
"CS237 App");
47 virtual void run () = 0;
57 return (this->
_messages & vk::DebugUtilsMessageSeverityFlagBitsEXT::eVerbose)
58 == vk::DebugUtilsMessageSeverityFlagBitsEXT::eVerbose;
65 return vk::enumerateInstanceExtensionProperties(
nullptr);
73 return this->
_gpu.enumerateDeviceExtensionProperties();
80 return vk::enumerateInstanceLayerProperties();
87 const vk::PhysicalDeviceProperties *
props ()
const
96 const vk::PhysicalDeviceLimits *
limits ()
const {
return &this->
props()->limits; }
99 const vk::PhysicalDeviceFeatures *
features ()
const
130 vk::Filter magF, vk::Filter minF, vk::SamplerMipmapMode mm,
131 vk::SamplerAddressMode am, vk::BorderColor color)
139 vk::Filter magF, vk::Filter minF, vk::SamplerMipmapMode mm,
140 vk::SamplerAddressMode am1, vk::SamplerAddressMode am2,
141 vk::BorderColor color)
162 return this->
_gpu.getFormatProperties(fmt);
176 vk::ArrayProxy<vk::DescriptorSetLayout> descSets,
177 vk::ArrayProxy<vk::PushConstantRange> pcrs)
179 vk::PipelineLayoutCreateInfo layoutInfo(
184 return this->
_device.createPipelineLayout(layoutInfo);
192 vk::PipelineLayoutCreateInfo layoutInfo(
197 return this->
_device.createPipelineLayout(layoutInfo);
230 vk::PipelineVertexInputStateCreateInfo
const &vertexInfo,
231 vk::PrimitiveTopology prim,
233 vk::ArrayProxy<vk::Viewport>
const &viewports,
234 vk::ArrayProxy<vk::Rect2D>
const &scissors,
236 vk::PolygonMode polyMode,
237 vk::CullModeFlags cullMode,
239 vk::PipelineLayout layout,
240 vk::PipelineRenderingCreateInfo
const &createInfo,
241 vk::PipelineColorBlendStateCreateInfo
const &blending,
242 vk::ArrayProxy<vk::DynamicState>
const &dynamic);
275 vk::PipelineVertexInputStateCreateInfo
const &vertexInfo,
276 vk::PrimitiveTopology prim,
278 vk::ArrayProxy<vk::Viewport>
const &viewports,
279 vk::ArrayProxy<vk::Rect2D>
const &scissors,
281 vk::PolygonMode polyMode,
282 vk::CullModeFlags cullMode,
284 vk::PipelineLayout layout,
285 vk::PipelineRenderingCreateInfo
const &createInfo,
286 vk::ArrayProxy<vk::DynamicState>
const &dynamic);
319 vk::PipelineVertexInputStateCreateInfo
const &vertexInfo,
320 vk::PrimitiveTopology prim,
321 vk::ArrayProxy<vk::Viewport>
const &viewports,
322 vk::ArrayProxy<vk::Rect2D>
const &scissors,
323 vk::PolygonMode polyMode,
324 vk::CullModeFlags cullMode,
326 vk::PipelineLayout layout,
327 vk::PipelineRenderingCreateInfo
const &createInfo,
328 vk::ArrayProxy<vk::DynamicState>
const &dynamic)
359 vk::CommandBufferAllocateInfo allocInfo(
361 vk::CommandBufferLevel::ePrimary,
364 return (this->
_device.allocateCommandBuffers(allocInfo))[0];
372 vk::CommandBufferBeginInfo beginInfo(
374 ? vk::CommandBufferUsageFlagBits::eOneTimeSubmit
375 : vk::CommandBufferUsageFlags());
376 cmdBuf.begin(beginInfo);
387 vk::CommandBuffer cmdBufs[1] = { cmdBuf };
388 vk::SubmitInfo submitInfo(
391 vk::ArrayProxyNoTemporaries<const vk::CommandBuffer>(1, cmdBufs),
405 template <
typename T>
438 VmaAllocator _allocator;
464 int32_t
_findMemory (uint32_t reqTypeBits, vk::MemoryPropertyFlags reqProps)
const;
475 std::vector<vk::Format> candidates,
476 vk::ImageTiling tiling,
520 vk::ImageTiling tiling,
521 vk::ImageUsageFlags usage,
522 vk::ImageLayout layout,
523 uint32_t mipLvls = 1);
538 vk::ImageTiling tiling,
539 vk::ImageUsageFlags usage,
540 uint32_t mipLvls = 1)
543 wid, ht, format, tiling, usage,
544 vk::ImageLayout::eUndefined,
561 vk::Image img, vk::Format fmt, vk::ImageAspectFlags aspectFlags);
571 vk::ImageLayout oldLayout,
572 vk::ImageLayout newLayout);
591 void _copyBuffer (vk::Buffer dstBuf, vk::Buffer srcBuf,
size_t offset,
size_t size);
601 vk::Image dstImg, vk::Buffer srcBuf,
size_t size,
602 uint32_t wid, uint32_t ht=1, uint32_t depth=1);
Definition texture.hpp:25
friend class DepthAttachment
Definition application.hpp:35
void _createInstance()
A helper function to create and initialize the Vulkan instance used by the application.
friend class DepthBuffer
Definition application.hpp:33
std::vector< vk::ExtensionProperties > supportedDeviceExtensions()
Get the list of supported Vulkan device extensions for the selected physical device.
Definition application.hpp:71
vk::Device _device
the logical device that we are using to render
Definition application.hpp:433
vk::Format _depthStencilBufferFormat(bool depth, bool stencil)
A helper function to identify the best depth/stencil-buffer attachment format for the device.
void _createLogicalDevice()
A helper function to create the logical device during initialization.
void _getPhysicalDeviceFeatures() const
function that gets the physical-device features and caches the pointer in the _featuresCache field.
vk::PhysicalDeviceFeatures * _featuresCache
a cache of the physical device properties
Definition application.hpp:431
vk::DeviceMemory _allocBufferMemory(vk::Buffer buf, vk::MemoryPropertyFlags props)
A helper function for allocating and binding device memory for a buffer.
const vk::PhysicalDeviceLimits * limits() const
access function for the physical device limits
Definition application.hpp:96
void freeCommandBuf(vk::CommandBuffer &cmdBuf)
free the command buffer
Definition application.hpp:399
VkDebugUtilsMessengerEXT _debugMessenger
Definition application.hpp:605
void _getPhysicalDeviceProperties() const
function that gets the physical-device properties and caches the pointer in the _propsCache field.
static std::vector< vk::LayerProperties > supportedLayers()
Get the list of supported layers.
Definition application.hpp:78
Application(std::vector< std::string > const &args, std::string const &name="CS237 App")
constructor for application base class
vk::Buffer _createBuffer(size_t size, vk::BufferUsageFlags usage)
create a vk::Buffer object
void _copyBufferToImage(vk::Image dstImg, vk::Buffer srcBuf, size_t size, uint32_t wid, uint32_t ht=1, uint32_t depth=1)
copy data from a buffer to an image
std::string name() const
return the application name
Definition application.hpp:50
Queues< uint32_t > _qIdxs
the queue family indices
Definition application.hpp:434
bool verbose() const
is the program in verbose mode?
Definition application.hpp:55
friend class MemoryObj
Definition application.hpp:29
void _transitionImageLayout(vk::Image img, vk::Format fmt, vk::ImageLayout oldLayout, vk::ImageLayout newLayout)
A helper function for changing the layout of an image.
vk::Pipeline createComputePipeline(vk::PipelineLayout layout, cs237::Shaders *shaders)
Create a compute pipeline.
vk::PipelineLayout createPipelineLayout(vk::DescriptorSetLayout descSet)
Create a pipeline layout for a single descriptor set.
Definition application.hpp:190
vk::CommandBuffer newCommandBuf()
create and initialize a command buffer
Definition application.hpp:357
vk::Pipeline createPipeline(cs237::Shaders *shaders, vk::PipelineVertexInputStateCreateInfo const &vertexInfo, vk::PrimitiveTopology prim, vk::ArrayProxy< vk::Viewport > const &viewports, vk::ArrayProxy< vk::Rect2D > const &scissors, vk::PolygonMode polyMode, vk::CullModeFlags cullMode, vk::FrontFace front, vk::PipelineLayout layout, vk::PipelineRenderingCreateInfo const &createInfo, vk::ArrayProxy< vk::DynamicState > const &dynamic)
Allocate a graphics pipeline using common defaults.
Definition application.hpp:317
vk::PhysicalDeviceProperties * _propsCache
Definition application.hpp:430
void _copyBuffer(vk::Buffer dstBuf, vk::Buffer srcBuf, size_t offset, size_t size)
copy data from one buffer to another using the GPU
friend class Window
Definition application.hpp:27
friend class Buffer
Definition application.hpp:28
bool _debug
set when validation layers should be enabled
Definition application.hpp:427
const vk::PhysicalDeviceProperties * props() const
get the physical-device properties pointer
Definition application.hpp:87
void endCommands(vk::CommandBuffer cmdBuf)
end the recording of commands in the give command buffer
Definition application.hpp:381
vk::DebugUtilsMessageSeverityFlagsEXT _messages
set to the message severity level
Definition application.hpp:425
vk::PhysicalDevice _gpu
the graphics card (aka device) that we are using
Definition application.hpp:429
friend class Attachment
Definition application.hpp:34
vk::Instance _instance
the Vulkan instance used by the application
Definition application.hpp:428
vk::Sampler createDepthSampler(SamplerInfo const &info)
Create a depth-texture sampler as specified.
vk::FormatProperties formatProps(vk::Format fmt) const
access function for the properties of an image format
Definition application.hpp:160
Queues< uint32_t > getQIndices() const
get the queue indices
Definition application.hpp:413
vk::Pipeline createPipeline(cs237::Shaders *shaders, vk::PipelineVertexInputStateCreateInfo const &vertexInfo, vk::PrimitiveTopology prim, bool primRestart, vk::ArrayProxy< vk::Viewport > const &viewports, vk::ArrayProxy< vk::Rect2D > const &scissors, bool depthClamp, vk::PolygonMode polyMode, vk::CullModeFlags cullMode, vk::FrontFace front, vk::PipelineLayout layout, vk::PipelineRenderingCreateInfo const &createInfo, vk::ArrayProxy< vk::DynamicState > const &dynamic)
Allocate a graphics pipeline.
vk::Device device() const
get the logical device
Definition application.hpp:84
vk::ImageView _createImageView(vk::Image img, vk::Format fmt, vk::ImageAspectFlags aspectFlags)
A helper function for creating a Vulkan image view object for an image.
int32_t _findMemory(uint32_t reqTypeBits, vk::MemoryPropertyFlags reqProps) const
A helper function to identify the index of a device memory type that has the required type and proper...
void submitCommands(vk::CommandBuffer cmdBuf)
end the commands and submit the buffer to the graphics queue.
Definition application.hpp:385
std::string _name
the application name
Definition application.hpp:424
friend class Texture2D
Definition application.hpp:32
void beginCommands(vk::CommandBuffer cmdBuf, bool oneTime=false)
begin recording commands in the given command buffer
Definition application.hpp:370
void _selectDevice(vk::PhysicalDeviceFeatures *reqFeatures=nullptr)
A helper function to select the GPU to use.
friend class Texture1D
Definition application.hpp:31
const vk::PhysicalDeviceFeatures * features() const
access function for the physical device features
Definition application.hpp:99
Queues< vk::Queue > _queues
the device queues that we are using
Definition application.hpp:435
vk::Pipeline createPipeline(cs237::Shaders *shaders, vk::PipelineVertexInputStateCreateInfo const &vertexInfo, vk::PrimitiveTopology prim, bool primRestart, vk::ArrayProxy< vk::Viewport > const &viewports, vk::ArrayProxy< vk::Rect2D > const &scissors, bool depthClamp, vk::PolygonMode polyMode, vk::CullModeFlags cullMode, vk::FrontFace front, vk::PipelineLayout layout, vk::PipelineRenderingCreateInfo const &createInfo, vk::PipelineColorBlendStateCreateInfo const &blending, vk::ArrayProxy< vk::DynamicState > const &dynamic)
Allocate a graphics pipeline with blending support.
virtual void run()=0
main function for running the application
bool debug() const
is the program in debug mode?
Definition application.hpp:53
vk::PipelineLayout createPipelineLayout(vk::ArrayProxy< vk::DescriptorSetLayout > descSets, vk::ArrayProxy< vk::PushConstantRange > pcrs)
Create a pipeline layout.
Definition application.hpp:175
vk::CommandPool _cmdPool
pool for allocating command buffers
Definition application.hpp:436
vk::Sampler createSampler(SamplerInfo const &info)
Create a texture sampler as specified.
vk::Image _createImage(uint32_t wid, uint32_t ht, vk::Format format, vk::ImageTiling tiling, vk::ImageUsageFlags usage, uint32_t mipLvls=1)
A helper function for creating a Vulkan image that can be used for textures or depth buffers.
Definition application.hpp:534
void _initCommandPool()
allocate the command pool for the application
vk::Image _createImage(uint32_t wid, uint32_t ht, vk::Format format, vk::ImageTiling tiling, vk::ImageUsageFlags usage, vk::ImageLayout layout, uint32_t mipLvls=1)
A helper function for creating a Vulkan image that can be used for textures or depth buffers.
static std::vector< vk::ExtensionProperties > supportedExtensions()
Get the list of supported Vulkan instance extensions.
Definition application.hpp:63
vk::Format _findBestFormat(std::vector< vk::Format > candidates, vk::ImageTiling tiling, vk::FormatFeatureFlags features)
A helper function to identify the best image format supported by the device from an ordered list of c...
bool _getQIndices(vk::PhysicalDevice dev)
A helper function to identify the queue-family indices for the physical device that we are using.
vk::DeviceMemory _allocImageMemory(vk::Image img, vk::MemoryPropertyFlags props)
A helper function for allocating and binding device memory for an image.
information about queue families
Definition application.hpp:406
T compute
the queue family that supports compute
Definition application.hpp:409
T present
the queue family that supports presentation
Definition application.hpp:408
T graphics
the queue family that supports graphics
Definition application.hpp:407
Definition application.hpp:110
vk::SamplerAddressMode addressModeU
Definition application.hpp:114
SamplerInfo(vk::Filter magF, vk::Filter minF, vk::SamplerMipmapMode mm, vk::SamplerAddressMode am1, vk::SamplerAddressMode am2, vk::BorderColor color)
sampler info for 2D texture
Definition application.hpp:138
vk::SamplerMipmapMode mipmapMode
Definition application.hpp:113
vk::BorderColor borderColor
Definition application.hpp:117
vk::SamplerAddressMode addressModeW
Definition application.hpp:116
SamplerInfo(vk::Filter magF, vk::Filter minF, vk::SamplerMipmapMode mm, vk::SamplerAddressMode am, vk::BorderColor color)
sampler info for 1D texture
Definition application.hpp:129
vk::Filter magFilter
Definition application.hpp:111
SamplerInfo()
Definition application.hpp:119
vk::SamplerAddressMode addressModeV
Definition application.hpp:115
vk::Filter minFilter
Definition application.hpp:112
Definition application.hpp:418
std::vector< vk::SurfaceFormatKHR > formats
Definition application.hpp:420
vk::SurfaceCapabilitiesKHR capabilities
Definition application.hpp:419
std::vector< vk::PresentModeKHR > presentModes
Definition application.hpp:421