BsVulkanUtility.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsVulkanPrerequisites.h"
  5. #include "Image/BsPixelUtil.h"
  6. #include "Renderapi/BsVertexDeclaration.h"
  7. namespace bs { namespace ct
  8. {
  9. /** @addtogroup Vulkan
  10. * @{
  11. */
  12. /** Contains various helper methods for dealing with Vulkan. */
  13. class VulkanUtility
  14. {
  15. public:
  16. /** Finds the closest pixel format that a specific Vulkan device supports. */
  17. static PixelFormat getClosestSupportedPixelFormat(VulkanDevice& device, PixelFormat format, TextureType texType,
  18. int usage, bool optimalTiling, bool hwGamma);
  19. /** Converts between Banshee and Vulkan pixel format. */
  20. static VkFormat getPixelFormat(PixelFormat format, bool sRGB = false);
  21. /** Converts between Banshee and Vulkan buffer element format. */
  22. static VkFormat getBufferFormat(GpuBufferFormat format);
  23. /** Converts between Banshee and Vulkan vertex element types. */
  24. static VkFormat getVertexType(VertexElementType type);
  25. /** Converts between Banshee and Vulkan texture addressing mode. */
  26. static VkSamplerAddressMode getAddressingMode(TextureAddressingMode mode);
  27. /** Converts between Banshee and Vulkan blend factor. */
  28. static VkBlendFactor getBlendFactor(BlendFactor factor);
  29. /** Converts between Banshee and Vulkan blend operation. */
  30. static VkBlendOp getBlendOp(BlendOperation op);
  31. /** Converts between Banshee and Vulkan comparison operation. */
  32. static VkCompareOp getCompareOp(CompareFunction op);
  33. /** Converts between Banshee and Vulkan cull mode. */
  34. static VkCullModeFlagBits getCullMode(CullingMode mode);
  35. /** Converts between Banshee and Vulkan polygon mode. */
  36. static VkPolygonMode getPolygonMode(PolygonMode mode);
  37. /** Converts between Banshee and Vulkan stencil op. */
  38. static VkStencilOp getStencilOp(StencilOperation op);
  39. /** Converts between Banshee and Vulkan index type. */
  40. static VkIndexType getIndexType(IndexType op);
  41. /** Converts between Banshee and Vulkan draw operation (i.e. primitive topology). */
  42. static VkPrimitiveTopology getDrawOp(DrawOperationType op);
  43. /** Converts between Banshee and Vulkan texture filtering modes. */
  44. static VkFilter getFilter(FilterOptions filter);
  45. /** Converts between Banshee and Vulkan texture filtering modes. */
  46. static VkSamplerMipmapMode getMipFilter(FilterOptions filter);
  47. /** Gets Vulkan flags representing the number of samples in an image. Sample count must be a power of 2. */
  48. static VkSampleCountFlagBits getSampleFlags(UINT32 numSamples);
  49. /** Gets Vulkan flags representing a certain shader stage. */
  50. static VkShaderStageFlagBits getShaderStage(GpuProgramType type);
  51. /**
  52. * Populates the provided array with Vulkan devices that correspond to provided flags. Sets null in unused slots.
  53. * Each device is placed at its own index in the output array.
  54. */
  55. static void getDevices(const VulkanRenderAPI& rapi, GpuDeviceFlags flags, VulkanDevice* (&devices)[BS_MAX_DEVICES]);
  56. /** Checks is a flag for a particular device enabled. */
  57. static bool isDeviceIdxSet(const VulkanRenderAPI& rapi, UINT32 idx, GpuDeviceFlags flags);
  58. /**
  59. * Subdivides an image subresource range by cutting it with another range. If the ranges don't overlap, or the
  60. * @p cutWith range completely overs the @p toCut range, the original @p toCut range is output.
  61. *
  62. * @param[in] toCut Range to cut.
  63. * @param[in] cutWith Range to cut with.
  64. * @param[out] output Pieces of the range that was cut.
  65. * @param[out] numAreas Number of pieces in the @p output array.
  66. */
  67. static void cutRange(const VkImageSubresourceRange& toCut, const VkImageSubresourceRange& cutWith,
  68. std::array<VkImageSubresourceRange, 5>& output, UINT32& numAreas);
  69. /** Checks if the two image subresource ranges have any overlapping subresources. */
  70. static bool rangeOverlaps(const VkImageSubresourceRange& a, const VkImageSubresourceRange& b);
  71. };
  72. /** @} */
  73. }}