CMSC23700 Common Code Library
Support code for CS23700 programming projects
Loading...
Searching...
No Matches
cs237::Application Class Referenceabstract

the base class for applications More...

#include <cs237-application.hpp>

Collaboration diagram for cs237::Application:

Classes

struct  Queues
 information about queue families More...
 
struct  SamplerInfo
 
struct  SwapChainDetails
 

Public Member Functions

 Application (std::vector< std::string > const &args, std::string const &name="CS237 App")
 constructor for application base class
 
virtual ~Application ()
 
virtual void run ()=0
 main function for running the application
 
std::string name () const
 return the application name
 
bool debug () const
 is the program in debug mode?
 
bool verbose () const
 is the program in verbose mode?
 
std::vector< vk::ExtensionProperties > supportedDeviceExtensions ()
 Get the list of supported Vulkan device extensions for the selected physical device.
 
vk::Sampler createSampler (SamplerInfo const &info)
 Create a texture sampler as specified.
 
vk::Sampler createDepthSampler (SamplerInfo const &info)
 Create a depth-texture sampler as specified.
 
vk::Device device () const
 get the logical device
 
const vk::PhysicalDeviceProperties * props () const
 get the physical-device properties pointer
 
const vk::PhysicalDeviceLimits * limits () const
 access function for the physical device limits
 
const vk::PhysicalDeviceFeatures * features () const
 access function for the physical device features
 
vk::FormatProperties formatProps (vk::Format fmt) const
 access function for the properties of an image format
 
vk::PipelineLayout createPipelineLayout (std::vector< vk::DescriptorSetLayout > descSets, std::vector< vk::PushConstantRange > pcrs)
 Create a pipeline layout.
 
vk::PipelineLayout createPipelineLayout (vk::DescriptorSetLayout descSet)
 Create a pipeline layout for a single descriptor set.
 
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::RenderPass renderPass, uint32_t subPass, vk::ArrayProxy< vk::DynamicState > const &dynamic)
 Allocate a graphics pipeline.
 
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::RenderPass renderPass, uint32_t subPass, vk::ArrayProxy< vk::DynamicState > const &dynamic)
 Allocate a graphics pipeline using common defaults.
 
vk::CommandBuffer newCommandBuf ()
 create and initialize a command buffer
 
void beginCommands (vk::CommandBuffer cmdBuf, bool oneTime=false)
 begin recording commands in the given command buffer
 
void endCommands (vk::CommandBuffer cmdBuf)
 end the recording of commands in the give command buffer
 
void submitCommands (vk::CommandBuffer cmdBuf)
 end the commands and submit the buffer to the graphics queue.
 
void freeCommandBuf (vk::CommandBuffer &cmdBuf)
 free the command buffer
 

Static Public Member Functions

static std::vector< vk::ExtensionProperties > supportedExtensions ()
 Get the list of supported Vulkan instance extensions.
 
static std::vector< vk::LayerProperties > supportedLayers ()
 Get the list of supported layers.
 

Protected Member Functions

void _createInstance ()
 A helper function to create and initialize the Vulkan instance used by the application.
 
void _getPhysicalDeviceProperties () const
 function that gets the physical-device properties and caches the pointer in the _propsCache field.
 
void _getPhysicalDeviceFeatures () const
 function that gets the physical-device features and caches the pointer in the _featuresCache field.
 
void _selectDevice (vk::PhysicalDeviceFeatures *reqFeatures=nullptr)
 A helper function to select the GPU to use.
 
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 properties.
 
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 candidate formats.
 
void _initCommandPool ()
 allocate the command pool for the application
 
vk::Format _depthStencilBufferFormat (bool depth, bool stencil)
 A helper function to identify the best depth/stencil-buffer attachment format for the device.
 
bool _getQIndices (vk::PhysicalDevice dev)
 A helper function to identify the queue-family indices for the physical device that we are using.
 
void _createLogicalDevice ()
 A helper function to create the logical device during initialization.
 
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.
 
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.
 
vk::DeviceMemory _allocImageMemory (vk::Image img, vk::MemoryPropertyFlags props)
 A helper function for allocating and binding device memory for an image.
 
vk::ImageView _createImageView (vk::Image image, vk::Format format, vk::ImageAspectFlags aspectFlags)
 A helper function for creating a Vulkan image view object for an image.
 
void _transitionImageLayout (vk::Image image, vk::Format format, vk::ImageLayout oldLayout, vk::ImageLayout newLayout)
 A helper function for changing the layout of an image.
 
vk::Buffer _createBuffer (size_t size, vk::BufferUsageFlags usage)
 create a vk::Buffer object
 
vk::DeviceMemory _allocBufferMemory (vk::Buffer buf, vk::MemoryPropertyFlags props)
 A helper function for allocating and binding device memory for a buffer.
 
void _copyBuffer (vk::Buffer dstBuf, vk::Buffer srcBuf, size_t offset, size_t size)
 copy data from one buffer to another using the GPU
 
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
 
void _initDebug ()
 
void _cleanupDebug ()
 

Protected Attributes

std::string _name
 the application name
 
vk::DebugUtilsMessageSeverityFlagsEXT _messages
 set to the message severity level
 
bool _debug
 set when validation layers should be enabled
 
vk::Instance _instance
 the Vulkan instance used by the application
 
vk::PhysicalDevice _gpu
 the graphics card (aka device) that we are using
 
vk::PhysicalDeviceProperties * _propsCache
 
vk::PhysicalDeviceFeatures * _featuresCache
 a cache of the physical device properties
 
vk::Device _device
 the logical device that we are using to render
 
Queues< uint32_t > _qIdxs
 the queue family indices
 
Queues< vk::Queue > _queues
 the device queues that we are using
 
vk::CommandPool _cmdPool
 pool for allocating command buffers
 
VkDebugUtilsMessengerEXT _debugMessenger
 

Friends

class Window
 
class Buffer
 
class MemoryObj
 
class __detail::TextureBase
 
class Texture1D
 
class Texture2D
 
class DepthBuffer
 

Detailed Description

the base class for applications

Constructor & Destructor Documentation

◆ Application()

cs237::Application::Application ( std::vector< std::string > const &  args,
std::string const &  name = "CS237 App" 
)

constructor for application base class

Parameters
argsvector of the command-line arguments
nameoptional name of the application

◆ ~Application()

virtual cs237::Application::~Application ( )
virtual

Member Function Documentation

◆ _allocBufferMemory()

vk::DeviceMemory cs237::Application::_allocBufferMemory ( vk::Buffer  buf,
vk::MemoryPropertyFlags  props 
)
protected

A helper function for allocating and binding device memory for a buffer.

Parameters
bufthe buffer to allocate memory for
propsrequred memory properties
Returns
the device memory that has been bound to the buffer

◆ _allocImageMemory()

vk::DeviceMemory cs237::Application::_allocImageMemory ( vk::Image  img,
vk::MemoryPropertyFlags  props 
)
protected

A helper function for allocating and binding device memory for an image.

Parameters
imgthe image to allocate memory for
propsrequred memory properties
Returns
the device memory that has been bound to the image

◆ _cleanupDebug()

void cs237::Application::_cleanupDebug ( )
protected

◆ _copyBuffer()

void cs237::Application::_copyBuffer ( vk::Buffer  dstBuf,
vk::Buffer  srcBuf,
size_t  offset,
size_t  size 
)
protected

copy data from one buffer to another using the GPU

Parameters
dstBufthe destination buffer
srcBufthe source buffer
offsetthe offset in the destination buffer to copy to
sizethe size (in bytes) of data to copy

◆ _copyBufferToImage()

void cs237::Application::_copyBufferToImage ( vk::Image  dstImg,
vk::Buffer  srcBuf,
size_t  size,
uint32_t  wid,
uint32_t  ht = 1,
uint32_t  depth = 1 
)
protected

copy data from a buffer to an image

Parameters
dstImgthe destination image
srcBufthe source buffer
sizethe size (in bytes) of data to copy
widthe image width
htthe image height (default 1)
depththe image depth (default 1)

◆ _createBuffer()

vk::Buffer cs237::Application::_createBuffer ( size_t  size,
vk::BufferUsageFlags  usage 
)
protected

create a vk::Buffer object

Parameters
sizethe size of the buffer in bytes
usagethe usage of the buffer
Returns
the allocated buffer

◆ _createImage() [1/2]

vk::Image cs237::Application::_createImage ( uint32_t  wid,
uint32_t  ht,
vk::Format  format,
vk::ImageTiling  tiling,
vk::ImageUsageFlags  usage,
uint32_t  mipLvls = 1 
)
inlineprotected

A helper function for creating a Vulkan image that can be used for textures or depth buffers.

Parameters
widthe image width
htthe image height
formatthe pixel format for the image
tilingthe tiling method for the pixels (device optimal vs linear)
usageflags specifying the usage of the image
mipLvlsnumber of mipmap levels for the image
Returns
the created image

◆ _createImage() [2/2]

vk::Image cs237::Application::_createImage ( uint32_t  wid,
uint32_t  ht,
vk::Format  format,
vk::ImageTiling  tiling,
vk::ImageUsageFlags  usage,
vk::ImageLayout  layout,
uint32_t  mipLvls = 1 
)
protected

A helper function for creating a Vulkan image that can be used for textures or depth buffers.

Parameters
widthe image width
htthe image height
formatthe pixel format for the image
tilingthe tiling method for the pixels (device optimal vs linear)
usageflags specifying the usage of the image
layoutthe image layout
mipLvlsnumber of mipmap levels for the image (default = 1)
Returns
the created image

◆ _createImageView()

vk::ImageView cs237::Application::_createImageView ( vk::Image  image,
vk::Format  format,
vk::ImageAspectFlags  aspectFlags 
)
protected

A helper function for creating a Vulkan image view object for an image.

◆ _createInstance()

void cs237::Application::_createInstance ( )
protected

A helper function to create and initialize the Vulkan instance used by the application.

◆ _createLogicalDevice()

void cs237::Application::_createLogicalDevice ( )
protected

A helper function to create the logical device during initialization.

This function initializes the _device, _qIdxs, and _queues instance variables.

◆ _depthStencilBufferFormat()

vk::Format cs237::Application::_depthStencilBufferFormat ( bool  depth,
bool  stencil 
)
protected

A helper function to identify the best depth/stencil-buffer attachment format for the device.

Parameters
depthset to true if requesting depth-buffer support
stencilset to true if requesting stencil-buffer support
Returns
the format that has the requested buffer support and the best precision. Returns VK_FORMAT_UNDEFINED is depth and stencil are both false or if there s no depth-buffer support

◆ _findBestFormat()

vk::Format cs237::Application::_findBestFormat ( std::vector< vk::Format >  candidates,
vk::ImageTiling  tiling,
vk::FormatFeatureFlags  features 
)
protected

A helper function to identify the best image format supported by the device from an ordered list of candidate formats.

Parameters
candidateslist of candidates in order of preference
tilinghow pixels are to be tiled in the image (linear vs optimal)
featuresrequired features for the format
Returns
the first format in the list of candidates that has the required features for the specified tiling. VK_FORMAT_UNDEFINED is returned if there is no valid candidate

◆ _findMemory()

int32_t cs237::Application::_findMemory ( uint32_t  reqTypeBits,
vk::MemoryPropertyFlags  reqProps 
) const
protected

A helper function to identify the index of a device memory type that has the required type and properties.

Parameters
reqTypeBitsbit mask that specifies the possible memory types
reqPropsmemory property bit mask
Returns
the index of the lowest set bit in reqTypeBits that has the required properties. If no such memory exists, then -1 is returned.

◆ _getPhysicalDeviceFeatures()

void cs237::Application::_getPhysicalDeviceFeatures ( ) const
protected

function that gets the physical-device features and caches the pointer in the _featuresCache field.

◆ _getPhysicalDeviceProperties()

void cs237::Application::_getPhysicalDeviceProperties ( ) const
protected

function that gets the physical-device properties and caches the pointer in the _propsCache field.

◆ _getQIndices()

bool cs237::Application::_getQIndices ( vk::PhysicalDevice  dev)
protected

A helper function to identify the queue-family indices for the physical device that we are using.

Returns
true if the device supports all of the required queue types and false otherwise.

If this function returns true, then the _qIdxs instance variable will be initialized to the queue family indices that were detected.

◆ _initCommandPool()

void cs237::Application::_initCommandPool ( )
protected

allocate the command pool for the application

◆ _initDebug()

void cs237::Application::_initDebug ( )
protected

◆ _selectDevice()

void cs237::Application::_selectDevice ( vk::PhysicalDeviceFeatures *  reqFeatures = nullptr)
protected

A helper function to select the GPU to use.

Parameters
reqFeaturespoints to a structure specifying the required features of the selected device.

◆ _transitionImageLayout()

void cs237::Application::_transitionImageLayout ( vk::Image  image,
vk::Format  format,
vk::ImageLayout  oldLayout,
vk::ImageLayout  newLayout 
)
protected

A helper function for changing the layout of an image.

◆ beginCommands()

void cs237::Application::beginCommands ( vk::CommandBuffer  cmdBuf,
bool  oneTime = false 
)
inline

begin recording commands in the given command buffer

Parameters
cmdBufthe command buffer to use for recording commands
oneTimetrue if this command buffer is only going to be used once

◆ createDepthSampler()

vk::Sampler cs237::Application::createDepthSampler ( SamplerInfo const &  info)

Create a depth-texture sampler as specified.

Parameters
infoa simplified sampler specification
Returns
the created depth-texture sampler

◆ createPipeline() [1/2]

vk::Pipeline cs237::Application::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::RenderPass  renderPass,
uint32_t  subPass,
vk::ArrayProxy< vk::DynamicState > const &  dynamic 
)

Allocate a graphics pipeline.

Parameters
shadersshaders for the pipeline
vertexInfovertex info
primprimitive topology
primRestarttrue if primitive restart should be enabled
viewportsvector of viewports; ignored if the viewport state is dynamic
scissorsvector of scissor rectangles; ignored if the scissor state is dynamic
depthClamptrue if depth clamping is enabled
polyModepolygon mode
cullModeprimitive culling mode
frontthe winding order that defines the front face of a triangle
layoutthe pipeline layout
renderPassa render pass that is compatible with the render pass to be used
subPassthe index of the subpass in the render pass where the pipeline will be used
dynamicvector that specifies which parts of the pipeline can be dynamically set during the
Returns
the created pipeline

This function creates a pipeline with the following properties:

  • rasterization discard is disabled
  • depth bias is disabled
  • no multisampling
  • depth-test is enabled
  • depth-write is enabled
  • LESS is the depth-compare operation
  • bounds-test is disabled
  • stencil-test is disabled
  • color blending is disabled
  • blending logic-op is disabled

◆ createPipeline() [2/2]

vk::Pipeline cs237::Application::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::RenderPass  renderPass,
uint32_t  subPass,
vk::ArrayProxy< vk::DynamicState > const &  dynamic 
)
inline

Allocate a graphics pipeline using common defaults.

Parameters
shadersshaders for the pipeline
vertexInfovertex info
primprimitive topology
viewportsvector of viewports; ignored if the viewport state is dynamic
scissorsvector of scissor rectangles; ignored if the scissor state is dynamic
polyModepolygon mode
cullModeprimitive culling mode
frontthe winding order that defines the front face of a triangle
layoutthe pipeline layout
renderPassa render pass that is compatible with the render pass to be used
subPassthe index of the subpass in the render pass where the pipeline will be used
dynamicvector that specifies which parts of the pipeline can be dynamically set during the
Returns
the created pipeline

This function creates a pipeline with the following properties:

  • primitive restart is disabled
  • depth clamping is disabled
  • rasterization discard is disabled
  • depth bias is disabled
  • no multisampling
  • depth-test is enabled
  • depth-write is enabled
  • LESS is the depth-compare operation
  • bounds-test is disabled
  • stencil-test is disabled
  • color blending is disabled
  • blending logic-op is disabled

◆ createPipelineLayout() [1/2]

vk::PipelineLayout cs237::Application::createPipelineLayout ( std::vector< vk::DescriptorSetLayout >  descSets,
std::vector< vk::PushConstantRange >  pcrs 
)
inline

Create a pipeline layout.

Parameters
descSetsthe descriptor sets for the pipeline
pcrsthe push-constant ranged for the pipeline
Returns
the created pipeline layout object

Note that the Vulkan specification recommends using multiple descriptor sets when you have uniforms that are updated at different frequencies (e.g., per-scene vs. per-object). It also recommends putting the least frequently changing descriptor sets at the beginning.

◆ createPipelineLayout() [2/2]

vk::PipelineLayout cs237::Application::createPipelineLayout ( vk::DescriptorSetLayout  descSet)
inline

Create a pipeline layout for a single descriptor set.

Parameters
descSetthe single descriptor sets for the pipeline
Returns
the created pipeline layout object

◆ createSampler()

vk::Sampler cs237::Application::createSampler ( SamplerInfo const &  info)

Create a texture sampler as specified.

Parameters
infoa simplified sampler specification
Returns
the created sampler

◆ debug()

bool cs237::Application::debug ( ) const
inline

is the program in debug mode?

◆ device()

vk::Device cs237::Application::device ( ) const
inline

get the logical device

◆ endCommands()

void cs237::Application::endCommands ( vk::CommandBuffer  cmdBuf)
inline

end the recording of commands in the give command buffer

Parameters
cmdBufthe command buffer that we are recording in

◆ features()

const vk::PhysicalDeviceFeatures * cs237::Application::features ( ) const
inline

access function for the physical device features

◆ formatProps()

vk::FormatProperties cs237::Application::formatProps ( vk::Format  fmt) const
inline

access function for the properties of an image format

◆ freeCommandBuf()

void cs237::Application::freeCommandBuf ( vk::CommandBuffer &  cmdBuf)
inline

free the command buffer

Parameters
cmdBufthe command buffer to free

◆ limits()

const vk::PhysicalDeviceLimits * cs237::Application::limits ( ) const
inline

access function for the physical device limits

◆ name()

std::string cs237::Application::name ( ) const
inline

return the application name

◆ newCommandBuf()

vk::CommandBuffer cs237::Application::newCommandBuf ( )
inline

create and initialize a command buffer

Returns
the fresh command buffer

◆ props()

const vk::PhysicalDeviceProperties * cs237::Application::props ( ) const
inline

get the physical-device properties pointer

◆ run()

virtual void cs237::Application::run ( )
pure virtual

main function for running the application

◆ submitCommands()

void cs237::Application::submitCommands ( vk::CommandBuffer  cmdBuf)
inline

end the commands and submit the buffer to the graphics queue.

Parameters
cmdBufthe command buffer to submit

◆ supportedDeviceExtensions()

std::vector< vk::ExtensionProperties > cs237::Application::supportedDeviceExtensions ( )
inline

Get the list of supported Vulkan device extensions for the selected physical device.

Returns
The vector of vk::ExtensionProperties for the supported extensions

◆ supportedExtensions()

static std::vector< vk::ExtensionProperties > cs237::Application::supportedExtensions ( )
inlinestatic

Get the list of supported Vulkan instance extensions.

Returns
The vector of vk::ExtensionProperties for the supported extensions

◆ supportedLayers()

static std::vector< vk::LayerProperties > cs237::Application::supportedLayers ( )
inlinestatic

Get the list of supported layers.

Returns
The vector of vk::LayerProperties for the supported layers

◆ verbose()

bool cs237::Application::verbose ( ) const
inline

is the program in verbose mode?

Friends And Related Symbol Documentation

◆ __detail::TextureBase

friend class __detail::TextureBase
friend

◆ Buffer

friend class Buffer
friend

◆ DepthBuffer

friend class DepthBuffer
friend

◆ MemoryObj

friend class MemoryObj
friend

◆ Texture1D

friend class Texture1D
friend

◆ Texture2D

friend class Texture2D
friend

◆ Window

friend class Window
friend

Member Data Documentation

◆ _cmdPool

vk::CommandPool cs237::Application::_cmdPool
protected

pool for allocating command buffers

◆ _debug

bool cs237::Application::_debug
protected

set when validation layers should be enabled

◆ _debugMessenger

VkDebugUtilsMessengerEXT cs237::Application::_debugMessenger
protected

◆ _device

vk::Device cs237::Application::_device
protected

the logical device that we are using to render

◆ _featuresCache

vk::PhysicalDeviceFeatures* cs237::Application::_featuresCache
mutableprotected

a cache of the physical device properties

◆ _gpu

vk::PhysicalDevice cs237::Application::_gpu
protected

the graphics card (aka device) that we are using

◆ _instance

vk::Instance cs237::Application::_instance
protected

the Vulkan instance used by the application

◆ _messages

vk::DebugUtilsMessageSeverityFlagsEXT cs237::Application::_messages
protected

set to the message severity level

◆ _name

std::string cs237::Application::_name
protected

the application name

◆ _propsCache

vk::PhysicalDeviceProperties* cs237::Application::_propsCache
mutableprotected

◆ _qIdxs

Queues<uint32_t> cs237::Application::_qIdxs
protected

the queue family indices

◆ _queues

Queues<vk::Queue> cs237::Application::_queues
protected

the device queues that we are using


The documentation for this class was generated from the following file: