Browse Source

Vk: add a PixelFormat enum.

I was slowly getting cancer from having to write the unreadably awful
VK_FORMAT_R666G666B666A666_SRGB all the time. Besides that:

 - All pixel formats are documented to show what's guaranteed for them
   by the spec. Pretty useful I'd say.
 - The old hasVkFormat() and vkFormat() converters operating on a
   VkFormat are deprecated in favor of new hasPixelFormat() and
   pixelFormat() that use the PixelFormat enum. Similarly as done in the
   GL wrapper.
 - All APIs that took a VkFormat before take a PixelFormat now, together
   with having conveinience overloads for Magnum::PixelFormat and
   Magnum::CompressedPixelFormat. Again similarly as done in the GL
   wrapper, also the first step on being able to *directly* use data
   imported with the Trade library with Vulkan.
pull/494/head
Vladimír Vondruš 5 years ago
parent
commit
64c2c7a348
  1. 11
      doc/changelog.dox
  2. 24
      doc/snippets/MagnumVk.cpp
  3. 4
      doc/vulkan-support.dox
  4. 301
      src/Magnum/PixelFormat.h
  5. 1
      src/Magnum/Vk/CMakeLists.txt
  6. 94
      src/Magnum/Vk/DeviceFeatures.h
  7. 61
      src/Magnum/Vk/Enums.cpp
  8. 83
      src/Magnum/Vk/Enums.h
  9. 21
      src/Magnum/Vk/Image.cpp
  10. 16
      src/Magnum/Vk/Image.h
  11. 127
      src/Magnum/Vk/ImageCreateInfo.h
  12. 26
      src/Magnum/Vk/ImageView.cpp
  13. 54
      src/Magnum/Vk/ImageViewCreateInfo.h
  14. 154
      src/Magnum/Vk/Implementation/compressedPixelFormatMapping.hpp
  15. 104
      src/Magnum/Vk/Implementation/pixelFormatMapping.hpp
  16. 248
      src/Magnum/Vk/PixelFormat.cpp
  17. 1467
      src/Magnum/Vk/PixelFormat.h
  18. 29
      src/Magnum/Vk/RenderPass.cpp
  19. 42
      src/Magnum/Vk/RenderPassCreateInfo.h
  20. 1
      src/Magnum/Vk/Test/CMakeLists.txt
  21. 219
      src/Magnum/Vk/Test/EnumsTest.cpp
  22. 9
      src/Magnum/Vk/Test/FramebufferVkTest.cpp
  23. 116
      src/Magnum/Vk/Test/ImageTest.cpp
  24. 158
      src/Magnum/Vk/Test/ImageViewTest.cpp
  25. 19
      src/Magnum/Vk/Test/ImageViewVkTest.cpp
  26. 60
      src/Magnum/Vk/Test/ImageVkTest.cpp
  27. 274
      src/Magnum/Vk/Test/PixelFormatTest.cpp
  28. 86
      src/Magnum/Vk/Test/RenderPassTest.cpp
  29. 11
      src/Magnum/Vk/Test/RenderPassVkTest.cpp
  30. 52
      src/Magnum/Vk/Test/pixelFormatTraits.h
  31. 1
      src/Magnum/Vk/Vk.h

11
doc/changelog.dox

@ -342,6 +342,17 @@ See also:
@ref MAGNUM_BUILD_DEPRECATED is enabled, the returned type acts as a @ref MAGNUM_BUILD_DEPRECATED is enabled, the returned type acts as a
@ref Corrade::Containers::Optional but has (deprecated) implicit conversion @ref Corrade::Containers::Optional but has (deprecated) implicit conversion
to a @ref Corrade::Containers::Pointer to avoid breaking user code. to a @ref Corrade::Containers::Pointer to avoid breaking user code.
- @cpp Vk::hasVkFormat(Magnum::PixelFormat) @ce,
@cpp Vk::hasVkFormat(Magnum::CompressedPixelFormat) @ce,
@cpp Vk::vkFormat(Magnum::PixelFormat) @ce and
@cpp Vk::vkFormat(Magnum::CompressedPixelFormat) @ce returning a raw
@type_vk{Format} are deprecated in favor of
@ref Vk::hasPixelFormat(Magnum::PixelFormat),
@ref Vk::hasPixelFormat(Magnum::CompressedPixelFormat),
@ref Vk::pixelFormat(Magnum::PixelFormat) and
@ref Vk::pixelFormat(Magnum::CompressedPixelFormat) that return the new
@ref Vk::PixelFormat enum that contains only values suitable for a pixel
format
@subsection changelog-latest-compatibility Potential compatibility breakages, removed APIs @subsection changelog-latest-compatibility Potential compatibility breakages, removed APIs

24
doc/snippets/MagnumVk.cpp

@ -29,6 +29,7 @@
#include <Corrade/Utility/Directory.h> #include <Corrade/Utility/Directory.h>
#include "Magnum/Magnum.h" #include "Magnum/Magnum.h"
#include "Magnum/PixelFormat.h"
#include "Magnum/Math/Color.h" #include "Magnum/Math/Color.h"
#include "Magnum/Vk/Assert.h" #include "Magnum/Vk/Assert.h"
#include "Magnum/Vk/BufferCreateInfo.h" #include "Magnum/Vk/BufferCreateInfo.h"
@ -47,6 +48,7 @@
#include "Magnum/Vk/ImageViewCreateInfo.h" #include "Magnum/Vk/ImageViewCreateInfo.h"
#include "Magnum/Vk/LayerProperties.h" #include "Magnum/Vk/LayerProperties.h"
#include "Magnum/Vk/MemoryAllocateInfo.h" #include "Magnum/Vk/MemoryAllocateInfo.h"
#include "Magnum/Vk/PixelFormat.h"
#include "Magnum/Vk/Queue.h" #include "Magnum/Vk/Queue.h"
#include "Magnum/Vk/RenderPassCreateInfo.h" #include "Magnum/Vk/RenderPassCreateInfo.h"
#include "Magnum/Vk/Result.h" #include "Magnum/Vk/Result.h"
@ -392,10 +394,10 @@ DOXYGEN_IGNORE()
Vk::Image color{device, Vk::ImageCreateInfo2D{ /* created before */ Vk::Image color{device, Vk::ImageCreateInfo2D{ /* created before */
Vk::ImageUsage::ColorAttachment, Vk::ImageUsage::ColorAttachment,
VK_FORMAT_R8G8B8A8_UNORM, size, 1}, DOXYGEN_IGNORE(NoAllocate)}; Vk::PixelFormat::RGBA8Unorm, size, 1}, DOXYGEN_IGNORE(NoAllocate)};
Vk::Image depth{device, Vk::ImageCreateInfo2D{ Vk::Image depth{device, Vk::ImageCreateInfo2D{
Vk::ImageUsage::DepthStencilAttachment, Vk::ImageUsage::DepthStencilAttachment,
VK_FORMAT_D24_UNORM_S8_UINT, size, 1}, DOXYGEN_IGNORE(NoAllocate)}; Vk::PixelFormat::Depth24UnormStencil8UI, size, 1}, DOXYGEN_IGNORE(NoAllocate)};
Vk::ImageView colorView{device, Vk::ImageViewCreateInfo2D{color}}; Vk::ImageView colorView{device, Vk::ImageViewCreateInfo2D{color}};
Vk::ImageView depthView{device, Vk::ImageViewCreateInfo2D{depth}}; Vk::ImageView depthView{device, Vk::ImageViewCreateInfo2D{depth}};
@ -423,7 +425,7 @@ Vk::Device device{NoCreate};
DOXYGEN_IGNORE() DOXYGEN_IGNORE()
Vk::Image image{device, Vk::ImageCreateInfo2D{ Vk::Image image{device, Vk::ImageCreateInfo2D{
Vk::ImageUsage::Sampled, VK_FORMAT_R8G8B8A8_SRGB, {1024, 1024}, 1 Vk::ImageUsage::Sampled, PixelFormat::RGBA8Srgb, {1024, 1024}, 1
}, Vk::MemoryFlag::DeviceLocal }, Vk::MemoryFlag::DeviceLocal
}; };
/* [Image-creation] */ /* [Image-creation] */
@ -433,7 +435,7 @@ Vk::Image image{device, Vk::ImageCreateInfo2D{
Vk::Device device{NoCreate}; Vk::Device device{NoCreate};
/* [Image-creation-custom-allocation] */ /* [Image-creation-custom-allocation] */
Vk::Image image{device, Vk::ImageCreateInfo2D{ Vk::Image image{device, Vk::ImageCreateInfo2D{
Vk::ImageUsage::Sampled, VK_FORMAT_R8G8B8A8_SRGB, {1024, 1024}, 1 Vk::ImageUsage::Sampled, PixelFormat::RGBA8Srgb, {1024, 1024}, 1
}, NoAllocate }, NoAllocate
}; };
@ -457,7 +459,7 @@ Vk::Device device{NoCreate};
DOXYGEN_IGNORE() DOXYGEN_IGNORE()
Vk::Image image{device, Vk::ImageCreateInfo2DArray{ /* created before */ Vk::Image image{device, Vk::ImageCreateInfo2DArray{ /* created before */
DOXYGEN_IGNORE(Vk::ImageUsage::Sampled, {}, {}, 1) DOXYGEN_IGNORE(Vk::ImageUsage::Sampled, PixelFormat{}, {}, 1)
}, DOXYGEN_IGNORE(Vk::MemoryFlag::DeviceLocal) }, DOXYGEN_IGNORE(Vk::MemoryFlag::DeviceLocal)
}; };
@ -628,8 +630,8 @@ DOXYGEN_IGNORE()
Vk::RenderPass renderPass{device, Vk::RenderPassCreateInfo{} Vk::RenderPass renderPass{device, Vk::RenderPassCreateInfo{}
.setAttachments({ .setAttachments({
VK_FORMAT_R8G8B8A8_SRGB, Vk::PixelFormat::RGBA8Srgb,
VK_FORMAT_D24_UNORM_S8_UINT Vk::PixelFormat::Depth24UnormStencil8UI
}) })
.addSubpass(Vk::SubpassDescription{} .addSubpass(Vk::SubpassDescription{}
.setColorAttachments({0}) .setColorAttachments({0})
@ -644,8 +646,8 @@ Vk::Device device{DOXYGEN_IGNORE(NoCreate)};
/* [RenderPass-creation-load-store] */ /* [RenderPass-creation-load-store] */
Vk::RenderPass renderPass{device, Vk::RenderPassCreateInfo{} Vk::RenderPass renderPass{device, Vk::RenderPassCreateInfo{}
.setAttachments({ .setAttachments({
{VK_FORMAT_R8G8B8A8_SRGB, Vk::AttachmentLoadOperation::Clear, {}}, {Vk::PixelFormat::RGBA8Srgb, Vk::AttachmentLoadOperation::Clear, {}},
{VK_FORMAT_D24_UNORM_S8_UINT, Vk::AttachmentLoadOperation::Clear, {}}, {Vk::PixelFormat::Depth24UnormStencil8UI, Vk::AttachmentLoadOperation::Clear, {}},
}) })
DOXYGEN_IGNORE() DOXYGEN_IGNORE()
}; };
@ -657,11 +659,11 @@ Vk::Device device{DOXYGEN_IGNORE(NoCreate)};
/* [RenderPass-creation-layout] */ /* [RenderPass-creation-layout] */
Vk::RenderPass renderPass{device, Vk::RenderPassCreateInfo{} Vk::RenderPass renderPass{device, Vk::RenderPassCreateInfo{}
.setAttachments({ .setAttachments({
{VK_FORMAT_R8G8B8A8_SRGB, {Vk::PixelFormat::RGBA8Srgb,
Vk::AttachmentLoadOperation::Clear, {}, Vk::AttachmentLoadOperation::Clear, {},
Vk::ImageLayout::ColorAttachment, Vk::ImageLayout::ColorAttachment,
Vk::ImageLayout::ColorAttachment}, Vk::ImageLayout::ColorAttachment},
{VK_FORMAT_D24_UNORM_S8_UINT, {Vk::PixelFormat::Depth24UnormStencil8UI,
Vk::AttachmentLoadOperation::Clear, {}, Vk::AttachmentLoadOperation::Clear, {},
Vk::ImageLayout::DepthStencilAttachment, Vk::ImageLayout::DepthStencilAttachment,
Vk::ImageLayout::DepthStencilAttachment}, Vk::ImageLayout::DepthStencilAttachment},

4
doc/vulkan-support.dox

@ -117,7 +117,7 @@ Extension | Status
--------------------------------------------------- | ------ --------------------------------------------------- | ------
@vk_extension{EXT,debug_report} @m_class{m-label m-danger} **deprecated** @m_class{m-label m-info} **instance** | | @vk_extension{EXT,debug_report} @m_class{m-label m-danger} **deprecated** @m_class{m-label m-info} **instance** | |
@vk_extension{EXT,debug_marker} @m_class{m-label m-danger} **deprecated** | | @vk_extension{EXT,debug_marker} @m_class{m-label m-danger} **deprecated** | |
@vk_extension{EXT,texture_compression_astc_hdr} | @ref Vk::vkFormat() only @vk_extension{EXT,texture_compression_astc_hdr} | done
@vk_extension{EXT,debug_utils} @m_class{m-label m-info} **instance** | | @vk_extension{EXT,debug_utils} @m_class{m-label m-info} **instance** | |
@vk_extension{EXT,validation_features} @m_class{m-label m-info} **instance** | | @vk_extension{EXT,validation_features} @m_class{m-label m-info} **instance** | |
@vk_extension{EXT,vertex_attribute_divisor} | | @vk_extension{EXT,vertex_attribute_divisor} | |
@ -128,7 +128,7 @@ Extension | Status
@vk_extension{KHR,pipeline_library} | | @vk_extension{KHR,pipeline_library} | |
@vk_extension{KHR,ray_tracing_pipeline} | | @vk_extension{KHR,ray_tracing_pipeline} | |
@vk_extension{KHR,ray_query} | | @vk_extension{KHR,ray_query} | |
@vk_extension{IMG,format_pvrtc} | @ref Vk::vkFormat() only @vk_extension{IMG,format_pvrtc} | done
*/ */

301
src/Magnum/PixelFormat.h

File diff suppressed because it is too large Load Diff

1
src/Magnum/Vk/CMakeLists.txt

@ -54,6 +54,7 @@ set(MagnumVk_GracefulAssert_SRCS
Instance.cpp Instance.cpp
LayerProperties.cpp LayerProperties.cpp
Memory.cpp Memory.cpp
PixelFormat.cpp
RenderPass.cpp) RenderPass.cpp)
set(MagnumVk_HEADERS set(MagnumVk_HEADERS

94
src/Magnum/Vk/DeviceFeatures.h

@ -132,21 +132,80 @@ enum class DeviceFeature: UnsignedShort {
SamplerAnisotropy, SamplerAnisotropy,
/** /**
* Whether *all* ETC2 and EAC compressed texture formats are supported. * Whether @ref PixelFormat::CompressedEacR11Unorm,
* @todoc link to the formats once we have our own PixelFormat enum * @ref PixelFormat::CompressedEacR11Snorm,
* @ref PixelFormat::CompressedEacRG11Unorm,
* @ref PixelFormat::CompressedEacRG11Snorm,
* @ref PixelFormat::CompressedEtc2RGB8Unorm,
* @ref PixelFormat::CompressedEtc2RGB8Srgb,
* @ref PixelFormat::CompressedEtc2RGB8A1Unorm,
* @ref PixelFormat::CompressedEtc2RGB8A1Srgb,
* @ref PixelFormat::CompressedEtc2RGBA8Unorm,
* @ref PixelFormat::CompressedEtc2RGBA8Unorm ETC2 and EAC compressed
* texture formats are *all* supported.
* @see @ref DeviceFeature::TextureCompressionBc,
* @ref DeviceFeature::TextureCompressionAstcLdr,
* @ref DeviceFeature::TextureCompressionAstcHdr
*/ */
TextureCompressionEtc2, TextureCompressionEtc2,
/** /**
* Whether *all* ASTC LDR compressed texture formats are supported. * Whether @ref PixelFormat::CompressedAstc4x4RGBAUnorm,
* @todoc link to the formats once we have our own PixelFormat enum * @ref PixelFormat::CompressedAstc4x4RGBASrgb,
* @see @ref DeviceFeature::TextureCompressionAstcHdr * @ref PixelFormat::CompressedAstc5x4RGBAUnorm,
* @ref PixelFormat::CompressedAstc5x4RGBASrgb,
* @ref PixelFormat::CompressedAstc5x5RGBAUnorm,
* @ref PixelFormat::CompressedAstc5x5RGBASrgb,
* @ref PixelFormat::CompressedAstc6x5RGBAUnorm,
* @ref PixelFormat::CompressedAstc6x5RGBASrgb,
* @ref PixelFormat::CompressedAstc6x6RGBAUnorm,
* @ref PixelFormat::CompressedAstc6x6RGBASrgb,
* @ref PixelFormat::CompressedAstc8x5RGBAUnorm,
* @ref PixelFormat::CompressedAstc8x5RGBASrgb,
* @ref PixelFormat::CompressedAstc8x6RGBAUnorm,
* @ref PixelFormat::CompressedAstc8x6RGBASrgb,
* @ref PixelFormat::CompressedAstc8x8RGBAUnorm,
* @ref PixelFormat::CompressedAstc8x8RGBASrgb,
* @ref PixelFormat::CompressedAstc10x5RGBAUnorm,
* @ref PixelFormat::CompressedAstc10x5RGBASrgb,
* @ref PixelFormat::CompressedAstc10x6RGBAUnorm,
* @ref PixelFormat::CompressedAstc10x6RGBASrgb,
* @ref PixelFormat::CompressedAstc10x8RGBAUnorm,
* @ref PixelFormat::CompressedAstc10x8RGBASrgb,
* @ref PixelFormat::CompressedAstc10x10RGBAUnorm,
* @ref PixelFormat::CompressedAstc10x10RGBASrgb,
* @ref PixelFormat::CompressedAstc12x10RGBAUnorm,
* @ref PixelFormat::CompressedAstc12x10RGBASrgb,
* @ref PixelFormat::CompressedAstc12x12RGBAUnorm,
* @ref PixelFormat::CompressedAstc12x12RGBASrgb,
* ASTC LDR compressed texture formats are *all* supported.
* @see @ref DeviceFeature::TextureCompressionAstcHdr,
* @ref DeviceFeature::TextureCompressionEtc2,
* @ref DeviceFeature::TextureCompressionBc
*/ */
TextureCompressionAstcLdr, TextureCompressionAstcLdr,
/** /**
* Whether *all* BC compressed texture formats are supported. * Whether @ref PixelFormat::CompressedBc1RGBUnorm,
* @todoc link to the formats once we have our own PixelFormat enum * @ref PixelFormat::CompressedBc1RGBSrgb,
* @ref PixelFormat::CompressedBc1RGBAUnorm,
* @ref PixelFormat::CompressedBc1RGBASrgb,
* @ref PixelFormat::CompressedBc2RGBAUnorm,
* @ref PixelFormat::CompressedBc2RGBASrgb,
* @ref PixelFormat::CompressedBc3RGBAUnorm,
* @ref PixelFormat::CompressedBc3RGBASrgb,
* @ref PixelFormat::CompressedBc4RUnorm,
* @ref PixelFormat::CompressedBc4RSnorm,
* @ref PixelFormat::CompressedBc5RGUnorm,
* @ref PixelFormat::CompressedBc5RGSnorm,
* @ref PixelFormat::CompressedBc6hRGBUfloat,
* @ref PixelFormat::CompressedBc6hRGBSfloat,
* @ref PixelFormat::CompressedBc7RGBAUnorm,
* @ref PixelFormat::CompressedBc7RGBASrgb BC compressed texture formats
* are *all* supported.
* @see @ref DeviceFeature::TextureCompressionEtc2,
* @ref DeviceFeature::TextureCompressionAstcLdr,
* @ref DeviceFeature::TextureCompressionAstcHdr
*/ */
TextureCompressionBc, TextureCompressionBc,
@ -438,9 +497,24 @@ enum class DeviceFeature: UnsignedShort {
/* VkPhysicalDeviceTextureCompressionASTCHDRFeaturesEXT, #67 */ /* VkPhysicalDeviceTextureCompressionASTCHDRFeaturesEXT, #67 */
/** /**
* Whether *all* ASTC HDR compressed texture formats are supported. * Whether @ref PixelFormat::CompressedAstc4x4RGBAF,
* @todoc link to the formats once we have our own PixelFormat enum * @ref PixelFormat::CompressedAstc5x4RGBAF,
* @see @ref DeviceFeature::TextureCompressionAstcLdr * @ref PixelFormat::CompressedAstc5x5RGBAF,
* @ref PixelFormat::CompressedAstc6x5RGBAF,
* @ref PixelFormat::CompressedAstc6x6RGBAF,
* @ref PixelFormat::CompressedAstc8x5RGBAF,
* @ref PixelFormat::CompressedAstc8x6RGBAF,
* @ref PixelFormat::CompressedAstc8x8RGBAF,
* @ref PixelFormat::CompressedAstc10x5RGBAF,
* @ref PixelFormat::CompressedAstc10x6RGBAF,
* @ref PixelFormat::CompressedAstc10x8RGBAF,
* @ref PixelFormat::CompressedAstc10x10RGBAF,
* @ref PixelFormat::CompressedAstc12x10RGBAF,
* @ref PixelFormat::CompressedAstc12x12RGBAF ASTC HDR compressed
* texture formats are *all* supported.
* @see @ref DeviceFeature::TextureCompressionAstcLdr,
* @ref DeviceFeature::TextureCompressionEtc2,
* @ref DeviceFeature::TextureCompressionBc
* @requires_vk_extension Extension @vk_extension{EXT,texture_compression_astc_hdr} * @requires_vk_extension Extension @vk_extension{EXT,texture_compression_astc_hdr}
*/ */
TextureCompressionAstcHdr, TextureCompressionAstcHdr,

61
src/Magnum/Vk/Enums.cpp

@ -28,10 +28,13 @@
#include <Corrade/Containers/ArrayView.h> #include <Corrade/Containers/ArrayView.h>
#include "Magnum/Mesh.h" #include "Magnum/Mesh.h"
#include "Magnum/PixelFormat.h"
#include "Magnum/Sampler.h" #include "Magnum/Sampler.h"
#include "Magnum/VertexFormat.h" #include "Magnum/VertexFormat.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#include "Magnum/Vk/PixelFormat.h"
#endif
namespace Magnum { namespace Vk { namespace Magnum { namespace Vk {
namespace { namespace {
@ -66,24 +69,6 @@ constexpr VkFormat VertexFormatMapping[] {
#undef _s #undef _s
#undef _c #undef _c
}; };
constexpr VkFormat PixelFormatMapping[] {
/* GCC 4.8 doesn't like just a {} for default enum values */
#define _c(input, format) VK_FORMAT_ ## format,
#define _s(input) VkFormat{},
#include "Magnum/Vk/Implementation/pixelFormatMapping.hpp"
#undef _s
#undef _c
};
constexpr VkFormat CompressedPixelFormatMapping[] {
/* GCC 4.8 doesn't like just a {} for default enum values */
#define _c(input, format) VK_FORMAT_ ## format,
#define _s(input) VkFormat{},
#include "Magnum/Vk/Implementation/compressedPixelFormatMapping.hpp"
#undef _s
#undef _c
};
#endif #endif
constexpr VkFilter FilterMapping[]{ constexpr VkFilter FilterMapping[]{
@ -152,23 +137,15 @@ bool hasVkFormat(const Magnum::VertexFormat format) {
return UnsignedInt(VertexFormatMapping[UnsignedInt(format) - 1]); return UnsignedInt(VertexFormatMapping[UnsignedInt(format) - 1]);
} }
#ifdef MAGNUM_BUILD_DEPRECATED
bool hasVkFormat(const Magnum::PixelFormat format) { bool hasVkFormat(const Magnum::PixelFormat format) {
if(isPixelFormatImplementationSpecific(format)) return hasPixelFormat(format);
return true;
CORRADE_ASSERT(UnsignedInt(format) - 1 < Containers::arraySize(PixelFormatMapping),
"Vk::hasVkFormat(): invalid format" << format, {});
return UnsignedInt(PixelFormatMapping[UnsignedInt(format) - 1]);
} }
bool hasVkFormat(const Magnum::CompressedPixelFormat format) { bool hasVkFormat(const Magnum::CompressedPixelFormat format) {
if(isCompressedPixelFormatImplementationSpecific(format)) return hasPixelFormat(format);
return true;
CORRADE_ASSERT(UnsignedInt(format) - 1 < Containers::arraySize(CompressedPixelFormatMapping),
"Vk::hasVkFormat(): invalid format" << format, {});
return UnsignedInt(CompressedPixelFormatMapping[UnsignedInt(format) - 1]);
} }
#endif
VkFormat vkFormat(const Magnum::VertexFormat format) { VkFormat vkFormat(const Magnum::VertexFormat format) {
if(isVertexFormatImplementationSpecific(format)) if(isVertexFormatImplementationSpecific(format))
@ -182,29 +159,15 @@ VkFormat vkFormat(const Magnum::VertexFormat format) {
return out; return out;
} }
#ifdef MAGNUM_BUILD_DEPRECATED
VkFormat vkFormat(const Magnum::PixelFormat format) { VkFormat vkFormat(const Magnum::PixelFormat format) {
if(isPixelFormatImplementationSpecific(format)) return VkFormat(pixelFormat(format));
return pixelFormatUnwrap<VkFormat>(format);
CORRADE_ASSERT(UnsignedInt(format) - 1 < Containers::arraySize(PixelFormatMapping),
"Vk::vkFormat(): invalid format" << format, {});
const VkFormat out = PixelFormatMapping[UnsignedInt(format) - 1];
CORRADE_ASSERT(UnsignedInt(out),
"Vk::vkFormat(): unsupported format" << format, {});
return out;
} }
VkFormat vkFormat(const Magnum::CompressedPixelFormat format) { VkFormat vkFormat(const Magnum::CompressedPixelFormat format) {
if(isCompressedPixelFormatImplementationSpecific(format)) return VkFormat(pixelFormat(format));
return compressedPixelFormatUnwrap<VkFormat>(format);
CORRADE_ASSERT(UnsignedInt(format) - 1 < Containers::arraySize(CompressedPixelFormatMapping),
"Vk::vkFormat(): invalid format" << format, {});
const VkFormat out = CompressedPixelFormatMapping[UnsignedInt(format) - 1];
CORRADE_ASSERT(UnsignedInt(out),
"Vk::vkFormat(): unsupported format" << format, {});
return out;
} }
#endif
VkFilter vkFilter(const Magnum::SamplerFilter filter) { VkFilter vkFilter(const Magnum::SamplerFilter filter) {
CORRADE_ASSERT(UnsignedInt(filter) < Containers::arraySize(FilterMapping), CORRADE_ASSERT(UnsignedInt(filter) < Containers::arraySize(FilterMapping),

83
src/Magnum/Vk/Enums.h

@ -33,6 +33,10 @@
#include "Magnum/Vk/Vulkan.h" #include "Magnum/Vk/Vulkan.h"
#include "Magnum/Vk/visibility.h" #include "Magnum/Vk/visibility.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#include <Corrade/Utility/Macros.h>
#endif
namespace Magnum { namespace Vk { namespace Magnum { namespace Vk {
/** /**
@ -107,37 +111,21 @@ vectors to consecutive attribute locations based on what
*/ */
MAGNUM_VK_EXPORT bool hasVkFormat(Magnum::VertexFormat format); MAGNUM_VK_EXPORT bool hasVkFormat(Magnum::VertexFormat format);
#ifdef MAGNUM_BUILD_DEPRECATED
/** /**
@brief Check availability of a generic pixel format * @brief @copybrief hasPixelFormat(Magnum::PixelFormat)
* @m_deprecated_since_latest Use @ref hasPixelFormat(Magnum::PixelFormat)
Returns @cpp false @ce if Vulkan doesn't support such format, @cpp true @ce * instead.
otherwise. Moreover, returns @cpp true @ce also for all formats that are */
@ref isPixelFormatImplementationSpecific(). The @p format value is expected to CORRADE_DEPRECATED("use hasPixelFormat() instead") MAGNUM_VK_EXPORT bool hasVkFormat(Magnum::PixelFormat format);
be valid.
@note Support of some formats depends on presence of a particular Vulkan
extension. Such check is outside of the scope of this function and you are
expected to verify extension availability before using such format.
@see @ref vkFormat(Magnum::PixelFormat)
*/
MAGNUM_VK_EXPORT bool hasVkFormat(Magnum::PixelFormat format);
/** /**
@brief Check availability of a generic compressed pixel format * @brief @copybrief hasPixelFormat(Magnum::CompressedPixelFormat)
* @m_deprecated_since_latest Use @ref hasPixelFormat(Magnum::CompressedPixelFormat)
Returns @cpp false @ce if Vulkan doesn't support such format, @cpp true @ce * instead.
otherwise. Moreover, returns @cpp true @ce also for all formats that are */
@ref isCompressedPixelFormatImplementationSpecific(). The @p format value is CORRADE_DEPRECATED("use hasPixelFormat() instead") MAGNUM_VK_EXPORT bool hasVkFormat(Magnum::CompressedPixelFormat format);
expected to be valid. #endif
@note Support of some formats depends on presence of a particular Vulkan
extension. Such check is outside of the scope of this function and you are
expected to verify extension availability before using such format.
@see @ref vkFormat(Magnum::CompressedPixelFormat)
*/
MAGNUM_VK_EXPORT bool hasVkFormat(Magnum::CompressedPixelFormat format);
/** /**
@brief Convert a generic vertex format to Vulkan format @brief Convert a generic vertex format to Vulkan format
@ -155,36 +143,21 @@ to query availability of given format.
*/ */
MAGNUM_VK_EXPORT VkFormat vkFormat(Magnum::VertexFormat format); MAGNUM_VK_EXPORT VkFormat vkFormat(Magnum::VertexFormat format);
#ifdef MAGNUM_BUILD_DEPRECATED
/** /**
@brief Convert a generic pixel format to Vulkan format * @brief @copybrief pixelFormat(Magnum::PixelFormat)
* @m_deprecated_since_latest Use @ref pixelFormat(Magnum::PixelFormat)
In case @ref isPixelFormatImplementationSpecific() returns @cpp false @ce for * instead.
@p format, maps it to a corresponding Vulkan format. In case */
@ref isPixelFormatImplementationSpecific() returns @cpp true @ce, assumes CORRADE_DEPRECATED("use pixelFormat() instead") MAGNUM_VK_EXPORT VkFormat vkFormat(Magnum::PixelFormat format);
@p format stores a Vulkan-specific format and returns @ref pixelFormatUnwrap()
cast to @type_vk{Format}.
Not all generic pixel formats have a Vulkan equivalent and this function
expects that given format is available. Use @ref hasVkFormat(Magnum::PixelFormat)
to query availability of given format.
*/
MAGNUM_VK_EXPORT VkFormat vkFormat(Magnum::PixelFormat format);
/** /**
@brief Convert a generic pixel format to Vulkan format * @brief @copybrief pixelFormat(Magnum::CompressedPixelFormat)
* @m_deprecated_since_latest Use @ref pixelFormat(Magnum::CompressedPixelFormat)
In case @ref isCompressedPixelFormatImplementationSpecific() returns * instead.
@cpp false @ce for @p format, maps it to a corresponding Vulkan format. In case */
@ref isCompressedPixelFormatImplementationSpecific() returns @cpp true @ce, CORRADE_DEPRECATED("use pixelFormat() instead") MAGNUM_VK_EXPORT VkFormat vkFormat(Magnum::CompressedPixelFormat format);
assumes @p format stores a Vulkan-specific format and returns #endif
@ref compressedPixelFormatUnwrap() cast to @type_vk{Format}.
Not all generic pixel formats have a Vulkan equivalent and this function
expects that given format is available. Use
@ref hasVkFormat(Magnum::CompressedPixelFormat) to query availability of given
format.
*/
MAGNUM_VK_EXPORT VkFormat vkFormat(Magnum::CompressedPixelFormat format);
/** /**
@brief Convert generic sampler filter to Vulkan filter @brief Convert generic sampler filter to Vulkan filter

21
src/Magnum/Vk/Image.cpp

@ -32,15 +32,16 @@
#include "Magnum/Vk/Handle.h" #include "Magnum/Vk/Handle.h"
#include "Magnum/Vk/Integration.h" #include "Magnum/Vk/Integration.h"
#include "Magnum/Vk/MemoryAllocateInfo.h" #include "Magnum/Vk/MemoryAllocateInfo.h"
#include "Magnum/Vk/PixelFormat.h"
#include "Magnum/Vk/Implementation/DeviceState.h" #include "Magnum/Vk/Implementation/DeviceState.h"
namespace Magnum { namespace Vk { namespace Magnum { namespace Vk {
ImageCreateInfo::ImageCreateInfo(const VkImageType type, const ImageUsages usages, const VkFormat format, const Vector3i& size, const Int layers, const Int levels, const Int samples, const ImageLayout initialLayout, const Flags flags): _info{} { ImageCreateInfo::ImageCreateInfo(const VkImageType type, const ImageUsages usages, const PixelFormat format, const Vector3i& size, const Int layers, const Int levels, const Int samples, const ImageLayout initialLayout, const Flags flags): _info{} {
_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; _info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
_info.flags = VkImageCreateFlags(flags); _info.flags = VkImageCreateFlags(flags);
_info.imageType = type; _info.imageType = type;
_info.format = format; _info.format = VkFormat(format);
_info.extent = VkExtent3D(size); _info.extent = VkExtent3D(size);
_info.mipLevels = levels; _info.mipLevels = levels;
_info.arrayLayers = layers; _info.arrayLayers = layers;
@ -53,6 +54,10 @@ ImageCreateInfo::ImageCreateInfo(const VkImageType type, const ImageUsages usage
_info.initialLayout = VkImageLayout(initialLayout); _info.initialLayout = VkImageLayout(initialLayout);
} }
ImageCreateInfo::ImageCreateInfo(const VkImageType type, const ImageUsages usages, const Magnum::PixelFormat format, const Vector3i& size, const Int layers, const Int levels, const Int samples, const ImageLayout initialLayout, const Flags flags): ImageCreateInfo{type, usages, pixelFormat(format), size, layers, levels, samples, initialLayout, flags} {}
ImageCreateInfo::ImageCreateInfo(const VkImageType type, const ImageUsages usages, const Magnum::CompressedPixelFormat format, const Vector3i& size, const Int layers, const Int levels, const Int samples, const ImageLayout initialLayout, const Flags flags): ImageCreateInfo{type, usages, pixelFormat(format), size, layers, levels, samples, initialLayout, flags} {}
ImageCreateInfo::ImageCreateInfo(NoInitT) noexcept {} ImageCreateInfo::ImageCreateInfo(NoInitT) noexcept {}
ImageCreateInfo::ImageCreateInfo(const VkImageCreateInfo& info): ImageCreateInfo::ImageCreateInfo(const VkImageCreateInfo& info):
@ -60,7 +65,7 @@ ImageCreateInfo::ImageCreateInfo(const VkImageCreateInfo& info):
member instead of doing a copy */ member instead of doing a copy */
_info(info) {} _info(info) {}
Image Image::wrap(Device& device, const VkImage handle, const VkFormat format, const HandleFlags flags) { Image Image::wrap(Device& device, const VkImage handle, const PixelFormat format, const HandleFlags flags) {
Image out{NoCreate}; Image out{NoCreate};
out._device = &device; out._device = &device;
out._handle = handle; out._handle = handle;
@ -69,7 +74,15 @@ Image Image::wrap(Device& device, const VkImage handle, const VkFormat format, c
return out; return out;
} }
Image::Image(Device& device, const ImageCreateInfo& info, NoAllocateT): _device{&device}, _flags{HandleFlag::DestroyOnDestruction}, _format{info->format}, _dedicatedMemory{NoCreate} { Image Image::wrap(Device& device, const VkImage handle, const Magnum::PixelFormat format, const HandleFlags flags) {
return wrap(device, handle, pixelFormat(format), flags);
}
Image Image::wrap(Device& device, const VkImage handle, const Magnum::CompressedPixelFormat format, const HandleFlags flags) {
return wrap(device, handle, pixelFormat(format), flags);
}
Image::Image(Device& device, const ImageCreateInfo& info, NoAllocateT): _device{&device}, _flags{HandleFlag::DestroyOnDestruction}, _format{PixelFormat(info->format)}, _dedicatedMemory{NoCreate} {
MAGNUM_VK_INTERNAL_ASSERT_SUCCESS(device->CreateImage(device, info, nullptr, &_handle)); MAGNUM_VK_INTERNAL_ASSERT_SUCCESS(device->CreateImage(device, info, nullptr, &_handle));
} }

16
src/Magnum/Vk/Image.h

@ -198,16 +198,20 @@ class MAGNUM_VK_EXPORT Image {
* *
* The @p handle is expected to be originating from @p device. The * The @p handle is expected to be originating from @p device. The
* @p format parameter is used for convenience @ref ImageView creation. * @p format parameter is used for convenience @ref ImageView creation.
* If it's unknown, use @val_vk{FORMAT_UNDEFINED,Format} --- you will * If it's unknown, use a @cpp PixelFormat{} @ce --- you will then be
* then be able to only create image views by passing a concrete format * able to only create image views by passing a concrete format to
* to @ref ImageViewCreateInfo. * @ref ImageViewCreateInfo.
* *
* Unlike an image created using a constructor, the Vulkan image is by * Unlike an image created using a constructor, the Vulkan image is by
* default not deleted on destruction, use @p flags for different * default not deleted on destruction, use @p flags for different
* behavior. * behavior.
* @see @ref release() * @see @ref release()
*/ */
static Image wrap(Device& device, VkImage handle, VkFormat format, HandleFlags flags = {}); static Image wrap(Device& device, VkImage handle, PixelFormat format, HandleFlags flags = {});
/** @overload */
static Image wrap(Device& device, VkImage handle, Magnum::PixelFormat format, HandleFlags flags = {});
/** @overload */
static Image wrap(Device& device, VkImage handle, Magnum::CompressedPixelFormat format, HandleFlags flags = {});
/** /**
* @brief Construct an image without allocating * @brief Construct an image without allocating
@ -276,7 +280,7 @@ class MAGNUM_VK_EXPORT Image {
HandleFlags handleFlags() const { return _flags; } HandleFlags handleFlags() const { return _flags; }
/** @brief Image format */ /** @brief Image format */
VkFormat format() const { return _format; } PixelFormat format() const { return _format; }
/** /**
* @brief Image memory requirements * @brief Image memory requirements
@ -360,7 +364,7 @@ class MAGNUM_VK_EXPORT Image {
involved and not safe to rely on (e.g., implicit view type would be involved and not safe to rely on (e.g., implicit view type would be
2D_ARRAY if there's more than one layer and then if you'd use just 2D_ARRAY if there's more than one layer and then if you'd use just
one layer it suddenly becomes just 2D, breaking everything). */ one layer it suddenly becomes just 2D, breaking everything). */
VkFormat _format; PixelFormat _format;
Memory _dedicatedMemory; Memory _dedicatedMemory;
}; };

127
src/Magnum/Vk/ImageCreateInfo.h

@ -70,18 +70,28 @@ enum class ImageUsage: UnsignedInt {
TransferDestination = VK_IMAGE_USAGE_TRANSFER_DST_BIT, TransferDestination = VK_IMAGE_USAGE_TRANSFER_DST_BIT,
/** /**
* Sampled by a shader * Sampled by a shader.
* *
* Not all pixel formats support sampling, see @ref PixelFormat for more
* information.
* @see @ref ImageLayout::ShaderReadOnly * @see @ref ImageLayout::ShaderReadOnly
*/ */
Sampled = VK_IMAGE_USAGE_SAMPLED_BIT, Sampled = VK_IMAGE_USAGE_SAMPLED_BIT,
/** Shader storage */ /**
* Shader storage.
*
* Not all pixel formats support shader storage, with some requiring the
* @ref DeviceFeature::ShaderStorageImageExtendedFormats feature. See
* @ref PixelFormat for more information.
*/
Storage = VK_IMAGE_USAGE_STORAGE_BIT, Storage = VK_IMAGE_USAGE_STORAGE_BIT,
/** /**
* Color attachment * Color attachment
* *
* Not all pixel formats support color attachment, see @ref PixelFormat for
* more information.
* @see @ref ImageLayout::ColorAttachment * @see @ref ImageLayout::ColorAttachment
*/ */
ColorAttachment = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, ColorAttachment = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
@ -89,6 +99,10 @@ enum class ImageUsage: UnsignedInt {
/** /**
* Depth/stencil attachment * Depth/stencil attachment
* *
* Note that only one of @ref PixelFormat::Depth24Unorm /
* @ref PixelFormat::Depth32F and @ref PixelFormat::Depth24UnormStencil8UI
* / @ref PixelFormat::Depth32FStencil8UI is guaranteed to support
* depth/stencil attachment.
* @see @ref ImageLayout::DepthStencilAttachment * @see @ref ImageLayout::DepthStencilAttachment
*/ */
DepthStencilAttachment = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, DepthStencilAttachment = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
@ -131,7 +145,7 @@ class MAGNUM_VK_EXPORT ImageCreateInfo {
* @brief Image creation flag * @brief Image creation flag
* *
* Wraps @type_vk_keyword{ImageCreateFlagBits}. * Wraps @type_vk_keyword{ImageCreateFlagBits}.
* @see @ref Flags, @ref ImageCreateInfo(VkImageType, ImageUsages, VkFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags) * @see @ref Flags, @ref ImageCreateInfo(VkImageType, ImageUsages, PixelFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags)
* @m_enum_values_as_keywords * @m_enum_values_as_keywords
*/ */
enum class Flag: UnsignedInt { enum class Flag: UnsignedInt {
@ -154,7 +168,7 @@ class MAGNUM_VK_EXPORT ImageCreateInfo {
* @brief Image creation flags * @brief Image creation flags
* *
* Type-safe wrapper for @type_vk_keyword{ImageCreateFlags}. * Type-safe wrapper for @type_vk_keyword{ImageCreateFlags}.
* @see @ref ImageCreateInfo(VkImageType, ImageUsages, VkFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags) * @see @ref ImageCreateInfo(VkImageType, ImageUsages, PixelFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags)
*/ */
typedef Containers::EnumSet<Flag> Flags; typedef Containers::EnumSet<Flag> Flags;
@ -196,7 +210,12 @@ class MAGNUM_VK_EXPORT ImageCreateInfo {
* @ref ImageCreateInfoCubeMapArray convenience classes instead of * @ref ImageCreateInfoCubeMapArray convenience classes instead of
* this constructor. * this constructor.
*/ */
explicit ImageCreateInfo(VkImageType type, ImageUsages usages, VkFormat format, const Vector3i& size, Int layers, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}); explicit ImageCreateInfo(VkImageType type, ImageUsages usages, PixelFormat format, const Vector3i& size, Int layers, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {});
/** @overload */
explicit ImageCreateInfo(VkImageType type, ImageUsages usages, Magnum::PixelFormat format, const Vector3i& size, Int layers, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {});
/** @overload */
explicit ImageCreateInfo(VkImageType type, ImageUsages usages, Magnum::CompressedPixelFormat format, const Vector3i& size, Int layers, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {});
/* No overload w/o initialLayout here as the general public is expected /* No overload w/o initialLayout here as the general public is expected
to use the convenience classes anyway */ to use the convenience classes anyway */
@ -245,20 +264,28 @@ Compared to the base @ref ImageCreateInfo constructor creates an image of type
to have only one layer. to have only one layer.
Note that same as with the Note that same as with the
@ref ImageCreateInfo::ImageCreateInfo(VkImageType, ImageUsages, VkFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags) @ref ImageCreateInfo::ImageCreateInfo(VkImageType, ImageUsages, PixelFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags)
constructor, at least one @ref ImageUsage value is required. constructor, at least one @ref ImageUsage value is required.
*/ */
class ImageCreateInfo1D: public ImageCreateInfo { class ImageCreateInfo1D: public ImageCreateInfo {
public: public:
/** @brief Constructor */ /** @brief Constructor */
explicit ImageCreateInfo1D(ImageUsages usages, VkFormat format, Int size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_1D, usages, format, {size, 1, 1}, 1, levels, samples, initialLayout, flags} {} explicit ImageCreateInfo1D(ImageUsages usages, PixelFormat format, Int size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_1D, usages, format, {size, 1, 1}, 1, levels, samples, initialLayout, flags} {}
/** @overload */
explicit ImageCreateInfo1D(ImageUsages usages, Magnum::PixelFormat format, Int size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_1D, usages, format, {size, 1, 1}, 1, levels, samples, initialLayout, flags} {}
/** @overload */
explicit ImageCreateInfo1D(ImageUsages usages, Magnum::CompressedPixelFormat format, Int size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_1D, usages, format, {size, 1, 1}, 1, levels, samples, initialLayout, flags} {}
/** @overload /** @overload
* *
* Equivalent to the above with @p initialLayout set to * Equivalent to the above with @p initialLayout set to
* @ref ImageLayout::Undefined. * @ref ImageLayout::Undefined.
*/ */
explicit ImageCreateInfo1D(ImageUsages usages, VkFormat format, Int size, Int levels, Int samples, Flags flags): ImageCreateInfo1D{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {} explicit ImageCreateInfo1D(ImageUsages usages, PixelFormat format, Int size, Int levels, Int samples, Flags flags): ImageCreateInfo1D{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {}
/** @overload */
explicit ImageCreateInfo1D(ImageUsages usages, Magnum::PixelFormat format, Int size, Int levels, Int samples, Flags flags): ImageCreateInfo1D{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {}
/** @overload */
explicit ImageCreateInfo1D(ImageUsages usages, Magnum::CompressedPixelFormat format, Int size, Int levels, Int samples, Flags flags): ImageCreateInfo1D{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {}
}; };
/** /**
@ -272,20 +299,28 @@ set to @cpp 1 @ce. You can use both @ref ImageViewCreateInfo2D and
to have only one layer. to have only one layer.
Note that same as with the Note that same as with the
@ref ImageCreateInfo::ImageCreateInfo(VkImageType, ImageUsages, VkFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags) @ref ImageCreateInfo::ImageCreateInfo(VkImageType, ImageUsages, PixelFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags)
constructor, at least one @ref ImageUsage value is required. constructor, at least one @ref ImageUsage value is required.
*/ */
class ImageCreateInfo2D: public ImageCreateInfo { class ImageCreateInfo2D: public ImageCreateInfo {
public: public:
/** @brief Constructor */ /** @brief Constructor */
explicit ImageCreateInfo2D(ImageUsages usages, VkFormat format, const Vector2i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_2D, usages, format, {size, 1}, 1, levels, samples, initialLayout, flags} {} explicit ImageCreateInfo2D(ImageUsages usages, PixelFormat format, const Vector2i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_2D, usages, format, {size, 1}, 1, levels, samples, initialLayout, flags} {}
/** @overload */
explicit ImageCreateInfo2D(ImageUsages usages, Magnum::PixelFormat format, const Vector2i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_2D, usages, format, {size, 1}, 1, levels, samples, initialLayout, flags} {}
/** @overload */
explicit ImageCreateInfo2D(ImageUsages usages, Magnum::CompressedPixelFormat format, const Vector2i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_2D, usages, format, {size, 1}, 1, levels, samples, initialLayout, flags} {}
/** @overload /** @overload
* *
* Equivalent to the above with @p initialLayout set to * Equivalent to the above with @p initialLayout set to
* @ref ImageLayout::Undefined. * @ref ImageLayout::Undefined.
*/ */
explicit ImageCreateInfo2D(ImageUsages usages, VkFormat format, const Vector2i& size, Int levels, Int samples, Flags flags): ImageCreateInfo2D{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {} explicit ImageCreateInfo2D(ImageUsages usages, PixelFormat format, const Vector2i& size, Int levels, Int samples, Flags flags): ImageCreateInfo2D{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {}
/** @overload */
explicit ImageCreateInfo2D(ImageUsages usages, Magnum::PixelFormat format, const Vector2i& size, Int levels, Int samples, Flags flags): ImageCreateInfo2D{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {}
/** @overload */
explicit ImageCreateInfo2D(ImageUsages usages, Magnum::CompressedPixelFormat format, const Vector2i& size, Int levels, Int samples, Flags flags): ImageCreateInfo2D{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {}
}; };
/** /**
@ -297,20 +332,28 @@ Compared to the base @ref ImageCreateInfo constructor creates an image of type
@ref ImageViewCreateInfo3D for view creation. @ref ImageViewCreateInfo3D for view creation.
Note that same as with the Note that same as with the
@ref ImageCreateInfo::ImageCreateInfo(VkImageType, ImageUsages, VkFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags) @ref ImageCreateInfo::ImageCreateInfo(VkImageType, ImageUsages, PixelFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags)
constructor, at least one @ref ImageUsage value is required. constructor, at least one @ref ImageUsage value is required.
*/ */
class ImageCreateInfo3D: public ImageCreateInfo { class ImageCreateInfo3D: public ImageCreateInfo {
public: public:
/** @brief Constructor */ /** @brief Constructor */
explicit ImageCreateInfo3D(ImageUsages usages, VkFormat format, const Vector3i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_3D, usages, format, size, 1, levels, samples, initialLayout, flags} {} explicit ImageCreateInfo3D(ImageUsages usages, PixelFormat format, const Vector3i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_3D, usages, format, size, 1, levels, samples, initialLayout, flags} {}
/** @overload */
explicit ImageCreateInfo3D(ImageUsages usages, Magnum::PixelFormat format, const Vector3i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_3D, usages, format, size, 1, levels, samples, initialLayout, flags} {}
/** @overload */
explicit ImageCreateInfo3D(ImageUsages usages, Magnum::CompressedPixelFormat format, const Vector3i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_3D, usages, format, size, 1, levels, samples, initialLayout, flags} {}
/** @overload /** @overload
* *
* Equivalent to the above with @p initialLayout set to * Equivalent to the above with @p initialLayout set to
* @ref ImageLayout::Undefined. * @ref ImageLayout::Undefined.
*/ */
explicit ImageCreateInfo3D(ImageUsages usages, VkFormat format, const Vector3i& size, Int levels, Int samples, Flags flags): ImageCreateInfo3D{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {} explicit ImageCreateInfo3D(ImageUsages usages, PixelFormat format, const Vector3i& size, Int levels, Int samples, Flags flags): ImageCreateInfo3D{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {}
/** @overload */
explicit ImageCreateInfo3D(ImageUsages usages, Magnum::PixelFormat format, const Vector3i& size, Int levels, Int samples, Flags flags): ImageCreateInfo3D{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {}
/** @overload */
explicit ImageCreateInfo3D(ImageUsages usages, Magnum::CompressedPixelFormat format, const Vector3i& size, Int levels, Int samples, Flags flags): ImageCreateInfo3D{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {}
}; };
/** /**
@ -324,20 +367,28 @@ Compared to the base @ref ImageCreateInfo constructor creates an image of type
creation. creation.
Note that same as with the Note that same as with the
@ref ImageCreateInfo::ImageCreateInfo(VkImageType, ImageUsages, VkFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags) @ref ImageCreateInfo::ImageCreateInfo(VkImageType, ImageUsages, PixelFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags)
constructor, at least one @ref ImageUsage value is required. constructor, at least one @ref ImageUsage value is required.
*/ */
class ImageCreateInfo1DArray: public ImageCreateInfo { class ImageCreateInfo1DArray: public ImageCreateInfo {
public: public:
/** @brief Constructor */ /** @brief Constructor */
explicit ImageCreateInfo1DArray(ImageUsages usages, VkFormat format, const Vector2i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_1D, usages, format, {size.x(), 1, 1}, size.y(), levels, samples, initialLayout, flags} {} explicit ImageCreateInfo1DArray(ImageUsages usages, PixelFormat format, const Vector2i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_1D, usages, format, {size.x(), 1, 1}, size.y(), levels, samples, initialLayout, flags} {}
/** @overload */
explicit ImageCreateInfo1DArray(ImageUsages usages, Magnum::PixelFormat format, const Vector2i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_1D, usages, format, {size.x(), 1, 1}, size.y(), levels, samples, initialLayout, flags} {}
/** @overload */
explicit ImageCreateInfo1DArray(ImageUsages usages, Magnum::CompressedPixelFormat format, const Vector2i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_1D, usages, format, {size.x(), 1, 1}, size.y(), levels, samples, initialLayout, flags} {}
/** @overload /** @overload
* *
* Equivalent to the above with @p initialLayout set to * Equivalent to the above with @p initialLayout set to
* @ref ImageLayout::Undefined. * @ref ImageLayout::Undefined.
*/ */
explicit ImageCreateInfo1DArray(ImageUsages usages, VkFormat format, const Vector2i& size, Int levels, Int samples, Flags flags): ImageCreateInfo1DArray{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {} explicit ImageCreateInfo1DArray(ImageUsages usages, PixelFormat format, const Vector2i& size, Int levels, Int samples, Flags flags): ImageCreateInfo1DArray{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {}
/** @overload */
explicit ImageCreateInfo1DArray(ImageUsages usages, Magnum::PixelFormat format, const Vector2i& size, Int levels, Int samples, Flags flags): ImageCreateInfo1DArray{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {}
/** @overload */
explicit ImageCreateInfo1DArray(ImageUsages usages, Magnum::CompressedPixelFormat format, const Vector2i& size, Int levels, Int samples, Flags flags): ImageCreateInfo1DArray{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {}
}; };
/** /**
@ -353,20 +404,28 @@ well, although in that case it's better to use @ref ImageCreateInfoCubeMap that
does this automatically. does this automatically.
Note that same as with the Note that same as with the
@ref ImageCreateInfo::ImageCreateInfo(VkImageType, ImageUsages, VkFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags) @ref ImageCreateInfo::ImageCreateInfo(VkImageType, ImageUsages, PixelFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags)
constructor, at least one @ref ImageUsage value is required. constructor, at least one @ref ImageUsage value is required.
*/ */
class ImageCreateInfo2DArray: public ImageCreateInfo { class ImageCreateInfo2DArray: public ImageCreateInfo {
public: public:
/** @brief Constructor */ /** @brief Constructor */
explicit ImageCreateInfo2DArray(ImageUsages usages, VkFormat format, const Vector3i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_2D, usages, format, {size.xy(), 1}, size.z(), levels, samples, initialLayout, flags} {} explicit ImageCreateInfo2DArray(ImageUsages usages, PixelFormat format, const Vector3i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_2D, usages, format, {size.xy(), 1}, size.z(), levels, samples, initialLayout, flags} {}
/** @overload */
explicit ImageCreateInfo2DArray(ImageUsages usages, Magnum::PixelFormat format, const Vector3i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_2D, usages, format, {size.xy(), 1}, size.z(), levels, samples, initialLayout, flags} {}
/** @overload */
explicit ImageCreateInfo2DArray(ImageUsages usages, Magnum::CompressedPixelFormat format, const Vector3i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_2D, usages, format, {size.xy(), 1}, size.z(), levels, samples, initialLayout, flags} {}
/** @overload /** @overload
* *
* Equivalent to the above with @p initialLayout set to * Equivalent to the above with @p initialLayout set to
* @ref ImageLayout::Undefined. * @ref ImageLayout::Undefined.
*/ */
explicit ImageCreateInfo2DArray(ImageUsages usages, VkFormat format, const Vector3i& size, Int levels, Int samples, Flags flags): ImageCreateInfo2DArray{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {} explicit ImageCreateInfo2DArray(ImageUsages usages, PixelFormat format, const Vector3i& size, Int levels, Int samples, Flags flags): ImageCreateInfo2DArray{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {}
/** @overload */
explicit ImageCreateInfo2DArray(ImageUsages usages, Magnum::PixelFormat format, const Vector3i& size, Int levels, Int samples, Flags flags): ImageCreateInfo2DArray{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {}
/** @overload */
explicit ImageCreateInfo2DArray(ImageUsages usages, Magnum::CompressedPixelFormat format, const Vector3i& size, Int levels, Int samples, Flags flags): ImageCreateInfo2DArray{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {}
}; };
/** /**
@ -383,20 +442,28 @@ will need to have exactly six layers, and requires
@ref DeviceFeature::ImageCubeArray to be enabled. @ref DeviceFeature::ImageCubeArray to be enabled.
Note that same as with the Note that same as with the
@ref ImageCreateInfo::ImageCreateInfo(VkImageType, ImageUsages, VkFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags) @ref ImageCreateInfo::ImageCreateInfo(VkImageType, ImageUsages, PixelFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags)
constructor, at least one @ref ImageUsage value is required. constructor, at least one @ref ImageUsage value is required.
*/ */
class ImageCreateInfoCubeMap: public ImageCreateInfo { class ImageCreateInfoCubeMap: public ImageCreateInfo {
public: public:
/** @brief Constructor */ /** @brief Constructor */
explicit ImageCreateInfoCubeMap(ImageUsages usages, VkFormat format, const Vector2i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_2D, usages, format, {size, 1}, 6, levels, samples, initialLayout, flags|Flag::CubeCompatible} {} explicit ImageCreateInfoCubeMap(ImageUsages usages, PixelFormat format, const Vector2i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_2D, usages, format, {size, 1}, 6, levels, samples, initialLayout, flags|Flag::CubeCompatible} {}
/** @overload */
explicit ImageCreateInfoCubeMap(ImageUsages usages, Magnum::PixelFormat format, const Vector2i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_2D, usages, format, {size, 1}, 6, levels, samples, initialLayout, flags|Flag::CubeCompatible} {}
/** @overload */
explicit ImageCreateInfoCubeMap(ImageUsages usages, Magnum::CompressedPixelFormat format, const Vector2i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_2D, usages, format, {size, 1}, 6, levels, samples, initialLayout, flags|Flag::CubeCompatible} {}
/** @overload /** @overload
* *
* Equivalent to the above with @p initialLayout set to * Equivalent to the above with @p initialLayout set to
* @ref ImageLayout::Undefined. * @ref ImageLayout::Undefined.
*/ */
explicit ImageCreateInfoCubeMap(ImageUsages usages, VkFormat format, const Vector2i& size, Int levels, Int samples, Flags flags): ImageCreateInfoCubeMap{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {} explicit ImageCreateInfoCubeMap(ImageUsages usages, PixelFormat format, const Vector2i& size, Int levels, Int samples, Flags flags): ImageCreateInfoCubeMap{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {}
/** @overload */
explicit ImageCreateInfoCubeMap(ImageUsages usages, Magnum::PixelFormat format, const Vector2i& size, Int levels, Int samples, Flags flags): ImageCreateInfoCubeMap{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {}
/** @overload */
explicit ImageCreateInfoCubeMap(ImageUsages usages, Magnum::CompressedPixelFormat format, const Vector2i& size, Int levels, Int samples, Flags flags): ImageCreateInfoCubeMap{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {}
}; };
/** /**
@ -412,20 +479,28 @@ Compared to the base @ref ImageCreateInfo constructor creates an image of type
requires @ref DeviceFeature::ImageCubeArray to be enabled. requires @ref DeviceFeature::ImageCubeArray to be enabled.
Note that same as with the Note that same as with the
@ref ImageCreateInfo::ImageCreateInfo(VkImageType, ImageUsages, VkFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags) @ref ImageCreateInfo::ImageCreateInfo(VkImageType, ImageUsages, PixelFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags)
constructor, at least one @ref ImageUsage value is required. constructor, at least one @ref ImageUsage value is required.
*/ */
class ImageCreateInfoCubeMapArray: public ImageCreateInfo { class ImageCreateInfoCubeMapArray: public ImageCreateInfo {
public: public:
/** @brief Constructor */ /** @brief Constructor */
explicit ImageCreateInfoCubeMapArray(ImageUsages usages, VkFormat format, const Vector3i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_2D, usages, format, {size.xy(), 1}, size.z(), levels, samples, initialLayout, flags|Flag::CubeCompatible} {} explicit ImageCreateInfoCubeMapArray(ImageUsages usages, PixelFormat format, const Vector3i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_2D, usages, format, {size.xy(), 1}, size.z(), levels, samples, initialLayout, flags|Flag::CubeCompatible} {}
/** @overload */
explicit ImageCreateInfoCubeMapArray(ImageUsages usages, Magnum::PixelFormat format, const Vector3i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_2D, usages, format, {size.xy(), 1}, size.z(), levels, samples, initialLayout, flags|Flag::CubeCompatible} {}
/** @overload */
explicit ImageCreateInfoCubeMapArray(ImageUsages usages, Magnum::CompressedPixelFormat format, const Vector3i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_2D, usages, format, {size.xy(), 1}, size.z(), levels, samples, initialLayout, flags|Flag::CubeCompatible} {}
/** @overload /** @overload
* *
* Equivalent to the above with @p initialLayout set to * Equivalent to the above with @p initialLayout set to
* @ref ImageLayout::Undefined. * @ref ImageLayout::Undefined.
*/ */
explicit ImageCreateInfoCubeMapArray(ImageUsages usages, VkFormat format, const Vector3i& size, Int levels, Int samples, Flags flags): ImageCreateInfoCubeMapArray{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {} explicit ImageCreateInfoCubeMapArray(ImageUsages usages, PixelFormat format, const Vector3i& size, Int levels, Int samples, Flags flags): ImageCreateInfoCubeMapArray{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {}
/** @overload */
explicit ImageCreateInfoCubeMapArray(ImageUsages usages, Magnum::PixelFormat format, const Vector3i& size, Int levels, Int samples, Flags flags): ImageCreateInfoCubeMapArray{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {}
/** @overload */
explicit ImageCreateInfoCubeMapArray(ImageUsages usages, Magnum::CompressedPixelFormat format, const Vector3i& size, Int levels, Int samples, Flags flags): ImageCreateInfoCubeMapArray{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {}
}; };
}} }}

26
src/Magnum/Vk/ImageView.cpp

@ -29,6 +29,7 @@
#include "Magnum/Vk/Assert.h" #include "Magnum/Vk/Assert.h"
#include "Magnum/Vk/Device.h" #include "Magnum/Vk/Device.h"
#include "Magnum/Vk/Image.h" #include "Magnum/Vk/Image.h"
#include "Magnum/Vk/PixelFormat.h"
namespace Magnum { namespace Vk { namespace Magnum { namespace Vk {
@ -36,15 +37,16 @@ namespace {
/* Vulkan, it would kill you if 0 was a valid default, right?! ffs */ /* Vulkan, it would kill you if 0 was a valid default, right?! ffs */
/** @todo this might be useful elsewhere as well */ /** @todo this might be useful elsewhere as well */
VkImageAspectFlags aspectFor(const VkFormat format) { VkImageAspectFlags aspectFor(const PixelFormat format) {
if(format == VK_FORMAT_D16_UNORM_S8_UINT || if(format == PixelFormat::Depth16UnormStencil8UI ||
format == VK_FORMAT_D24_UNORM_S8_UINT || format == PixelFormat::Depth24UnormStencil8UI ||
format == VK_FORMAT_D32_SFLOAT_S8_UINT) format == PixelFormat::Depth32FStencil8UI)
return VK_IMAGE_ASPECT_DEPTH_BIT|VK_IMAGE_ASPECT_STENCIL_BIT; return VK_IMAGE_ASPECT_DEPTH_BIT|VK_IMAGE_ASPECT_STENCIL_BIT;
if(format == VK_FORMAT_D16_UNORM || if(format == PixelFormat::Depth16Unorm ||
format == VK_FORMAT_D32_SFLOAT) format == PixelFormat::Depth24Unorm ||
format == PixelFormat::Depth32F)
return VK_IMAGE_ASPECT_DEPTH_BIT; return VK_IMAGE_ASPECT_DEPTH_BIT;
if(format == VK_FORMAT_S8_UINT) if(format == PixelFormat::Stencil8UI)
return VK_IMAGE_ASPECT_STENCIL_BIT; return VK_IMAGE_ASPECT_STENCIL_BIT;
/** @todo planar formats */ /** @todo planar formats */
@ -54,12 +56,12 @@ VkImageAspectFlags aspectFor(const VkFormat format) {
} }
ImageViewCreateInfo::ImageViewCreateInfo(const VkImageViewType type, const VkImage image, const VkFormat format, const UnsignedInt layerOffset, const UnsignedInt layerCount, const UnsignedInt levelOffset, const UnsignedInt levelCount, const Flags flags): _info{} { ImageViewCreateInfo::ImageViewCreateInfo(const VkImageViewType type, const VkImage image, const PixelFormat format, const UnsignedInt layerOffset, const UnsignedInt layerCount, const UnsignedInt levelOffset, const UnsignedInt levelCount, const Flags flags): _info{} {
_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; _info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
_info.flags = VkImageViewCreateFlags(flags); _info.flags = VkImageViewCreateFlags(flags);
_info.image = image; _info.image = image;
_info.viewType = type; _info.viewType = type;
_info.format = format; _info.format = VkFormat(format);
_info.subresourceRange.aspectMask = aspectFor(format); _info.subresourceRange.aspectMask = aspectFor(format);
_info.subresourceRange.baseMipLevel = levelOffset; _info.subresourceRange.baseMipLevel = levelOffset;
_info.subresourceRange.levelCount = levelCount; _info.subresourceRange.levelCount = levelCount;
@ -67,8 +69,12 @@ ImageViewCreateInfo::ImageViewCreateInfo(const VkImageViewType type, const VkIma
_info.subresourceRange.layerCount = layerCount; _info.subresourceRange.layerCount = layerCount;
} }
ImageViewCreateInfo::ImageViewCreateInfo(const VkImageViewType type, const VkImage image, const Magnum::PixelFormat format, const UnsignedInt layerOffset, const UnsignedInt layerCount, const UnsignedInt levelOffset, const UnsignedInt levelCount, const Flags flags): ImageViewCreateInfo{type, image, pixelFormat(format), layerOffset, layerCount, levelOffset, levelCount, flags} {}
ImageViewCreateInfo::ImageViewCreateInfo(const VkImageViewType type, const VkImage image, const Magnum::CompressedPixelFormat format, const UnsignedInt layerOffset, const UnsignedInt layerCount, const UnsignedInt levelOffset, const UnsignedInt levelCount, const Flags flags): ImageViewCreateInfo{type, image, pixelFormat(format), layerOffset, layerCount, levelOffset, levelCount, flags} {}
ImageViewCreateInfo::ImageViewCreateInfo(const VkImageViewType type, Image& image, const UnsignedInt layerOffset, const UnsignedInt layerCount, const UnsignedInt levelOffset, const UnsignedInt levelCount, const Flags flags): ImageViewCreateInfo{type, image, image.format(), layerOffset, layerCount, levelOffset, levelCount, flags} { ImageViewCreateInfo::ImageViewCreateInfo(const VkImageViewType type, Image& image, const UnsignedInt layerOffset, const UnsignedInt layerCount, const UnsignedInt levelOffset, const UnsignedInt levelCount, const Flags flags): ImageViewCreateInfo{type, image, image.format(), layerOffset, layerCount, levelOffset, levelCount, flags} {
CORRADE_ASSERT(image.format(), CORRADE_ASSERT(VkFormat(image.format()),
"Vk::ImageViewCreateInfo: the image has unknown format, you have to specify it explicitly", ); "Vk::ImageViewCreateInfo: the image has unknown format, you have to specify it explicitly", );
} }

54
src/Magnum/Vk/ImageViewCreateInfo.h

@ -57,7 +57,7 @@ class MAGNUM_VK_EXPORT ImageViewCreateInfo {
* @brief Image view creation flag * @brief Image view creation flag
* *
* Wraps @type_vk_keyword{ImageViewCreateFlagBits}. * Wraps @type_vk_keyword{ImageViewCreateFlagBits}.
* @see @ref Flags, @ref ImageViewCreateInfo(VkImageViewType, VkImage, VkFormat, UnsignedInt, UnsignedInt, UnsignedInt, UnsignedInt, Flags) * @see @ref Flags, @ref ImageViewCreateInfo(VkImageViewType, VkImage, PixelFormat, UnsignedInt, UnsignedInt, UnsignedInt, UnsignedInt, Flags)
* @m_enum_values_as_keywords * @m_enum_values_as_keywords
*/ */
enum class Flag: UnsignedInt { enum class Flag: UnsignedInt {
@ -68,7 +68,7 @@ class MAGNUM_VK_EXPORT ImageViewCreateInfo {
* @brief ImageView creation flags * @brief ImageView creation flags
* *
* Type-safe wrapper for @type_vk_keyword{ImageViewCreateFlags}. * Type-safe wrapper for @type_vk_keyword{ImageViewCreateFlags}.
* @see @ref ImageViewCreateInfo(VkImageViewType, VkImage, VkFormat, UnsignedInt, UnsignedInt, UnsignedInt, UnsignedInt, Flags) * @see @ref ImageViewCreateInfo(VkImageViewType, VkImage, PixelFormat, UnsignedInt, UnsignedInt, UnsignedInt, UnsignedInt, Flags)
*/ */
typedef Containers::EnumSet<Flag> Flags; typedef Containers::EnumSet<Flag> Flags;
@ -112,12 +112,16 @@ class MAGNUM_VK_EXPORT ImageViewCreateInfo {
* @ref ImageViewCreateInfoCubeMapArray convenience classes instead of * @ref ImageViewCreateInfoCubeMapArray convenience classes instead of
* this constructor. * this constructor.
*/ */
explicit ImageViewCreateInfo(VkImageViewType type, VkImage image, VkFormat format, UnsignedInt layerOffset = 0, UnsignedInt layerCount = VK_REMAINING_ARRAY_LAYERS, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}); explicit ImageViewCreateInfo(VkImageViewType type, VkImage image, PixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt layerCount = VK_REMAINING_ARRAY_LAYERS, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {});
/** @overload */
explicit ImageViewCreateInfo(VkImageViewType type, VkImage image, Magnum::PixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt layerCount = VK_REMAINING_ARRAY_LAYERS, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {});
/** @overload */
explicit ImageViewCreateInfo(VkImageViewType type, VkImage image, Magnum::CompressedPixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt layerCount = VK_REMAINING_ARRAY_LAYERS, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {});
/** /**
* @brief Construct with format matching given image * @brief Construct with format matching given image
* *
* Compared to @ref ImageViewCreateInfo(VkImageViewType, VkImage, VkFormat, UnsignedInt, UnsignedInt, UnsignedInt, UnsignedInt, Flags) * Compared to @ref ImageViewCreateInfo(VkImageViewType, VkImage, PixelFormat, UnsignedInt, UnsignedInt, UnsignedInt, UnsignedInt, Flags)
* the @p format is taken from @ref Image::format(). * the @p format is taken from @ref Image::format().
*/ */
explicit ImageViewCreateInfo(VkImageViewType type, Image& image, UnsignedInt layerOffset = 0, UnsignedInt layerCount = VK_REMAINING_ARRAY_LAYERS, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}); explicit ImageViewCreateInfo(VkImageViewType type, Image& image, UnsignedInt layerOffset = 0, UnsignedInt layerCount = VK_REMAINING_ARRAY_LAYERS, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {});
@ -169,7 +173,11 @@ type @val_vk{IMAGE_VIEW_TYPE_1D,ImageViewType} with @p layerCount set to
class ImageViewCreateInfo1D: public ImageViewCreateInfo { class ImageViewCreateInfo1D: public ImageViewCreateInfo {
public: public:
/** @brief Constructor */ /** @brief Constructor */
explicit ImageViewCreateInfo1D(VkImage image, VkFormat format, UnsignedInt layerOffset = 0, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_1D, image, format, layerOffset, 1, levelOffset, levelCount, flags} {} explicit ImageViewCreateInfo1D(VkImage image, PixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_1D, image, format, layerOffset, 1, levelOffset, levelCount, flags} {}
/** @overload */
explicit ImageViewCreateInfo1D(VkImage image, Magnum::PixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_1D, image, format, layerOffset, 1, levelOffset, levelCount, flags} {}
/** @overload */
explicit ImageViewCreateInfo1D(VkImage image, Magnum::CompressedPixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_1D, image, format, layerOffset, 1, levelOffset, levelCount, flags} {}
/** @overload /** @overload
* *
@ -195,7 +203,11 @@ type @val_vk{IMAGE_VIEW_TYPE_2D,ImageViewType} with @p layerCount set to
class ImageViewCreateInfo2D: public ImageViewCreateInfo { class ImageViewCreateInfo2D: public ImageViewCreateInfo {
public: public:
/** @brief Constructor */ /** @brief Constructor */
explicit ImageViewCreateInfo2D(VkImage image, VkFormat format, UnsignedInt layerOffset = 0, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_2D, image, format, layerOffset, 1, levelOffset, levelCount, flags} {} explicit ImageViewCreateInfo2D(VkImage image, PixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_2D, image, format, layerOffset, 1, levelOffset, levelCount, flags} {}
/** @overload */
explicit ImageViewCreateInfo2D(VkImage image, Magnum::PixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_2D, image, format, layerOffset, 1, levelOffset, levelCount, flags} {}
/** @overload */
explicit ImageViewCreateInfo2D(VkImage image, Magnum::CompressedPixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_2D, image, format, layerOffset, 1, levelOffset, levelCount, flags} {}
/** @overload /** @overload
* *
@ -216,7 +228,11 @@ type @val_vk{IMAGE_VIEW_TYPE_3D,ImageViewType} with @p layerCount set to
class ImageViewCreateInfo3D: public ImageViewCreateInfo { class ImageViewCreateInfo3D: public ImageViewCreateInfo {
public: public:
/** @brief Constructor */ /** @brief Constructor */
explicit ImageViewCreateInfo3D(VkImage image, VkFormat format, UnsignedInt layerOffset = 0, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_3D, image, format, layerOffset, 1, levelOffset, levelCount, flags} {} explicit ImageViewCreateInfo3D(VkImage image, PixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_3D, image, format, layerOffset, 1, levelOffset, levelCount, flags} {}
/** @overload */
explicit ImageViewCreateInfo3D(VkImage image, Magnum::PixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_3D, image, format, layerOffset, 1, levelOffset, levelCount, flags} {}
/** @overload */
explicit ImageViewCreateInfo3D(VkImage image, Magnum::CompressedPixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_3D, image, format, layerOffset, 1, levelOffset, levelCount, flags} {}
/** @overload /** @overload
* *
@ -238,7 +254,11 @@ to fit the required subrange.
class ImageViewCreateInfo1DArray: public ImageViewCreateInfo { class ImageViewCreateInfo1DArray: public ImageViewCreateInfo {
public: public:
/** @brief Constructor */ /** @brief Constructor */
explicit ImageViewCreateInfo1DArray(VkImage image, VkFormat format, UnsignedInt layerOffset = 0, UnsignedInt layerCount = VK_REMAINING_ARRAY_LAYERS, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_1D_ARRAY, image, format, layerOffset, layerCount, levelOffset, levelCount, flags} {} explicit ImageViewCreateInfo1DArray(VkImage image, PixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt layerCount = VK_REMAINING_ARRAY_LAYERS, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_1D_ARRAY, image, format, layerOffset, layerCount, levelOffset, levelCount, flags} {}
/** @overload */
explicit ImageViewCreateInfo1DArray(VkImage image, Magnum::PixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt layerCount = VK_REMAINING_ARRAY_LAYERS, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_1D_ARRAY, image, format, layerOffset, layerCount, levelOffset, levelCount, flags} {}
/** @overload */
explicit ImageViewCreateInfo1DArray(VkImage image, Magnum::CompressedPixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt layerCount = VK_REMAINING_ARRAY_LAYERS, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_1D_ARRAY, image, format, layerOffset, layerCount, levelOffset, levelCount, flags} {}
/** @overload /** @overload
* *
@ -264,7 +284,11 @@ subrange.
class ImageViewCreateInfo2DArray: public ImageViewCreateInfo { class ImageViewCreateInfo2DArray: public ImageViewCreateInfo {
public: public:
/** @brief Constructor */ /** @brief Constructor */
explicit ImageViewCreateInfo2DArray(VkImage image, VkFormat format, UnsignedInt layerOffset = 0, UnsignedInt layerCount = VK_REMAINING_ARRAY_LAYERS, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_2D_ARRAY, image, format, layerOffset, layerCount, levelOffset, levelCount, flags} {} explicit ImageViewCreateInfo2DArray(VkImage image, PixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt layerCount = VK_REMAINING_ARRAY_LAYERS, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_2D_ARRAY, image, format, layerOffset, layerCount, levelOffset, levelCount, flags} {}
/** @overload */
explicit ImageViewCreateInfo2DArray(VkImage image, Magnum::PixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt layerCount = VK_REMAINING_ARRAY_LAYERS, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_2D_ARRAY, image, format, layerOffset, layerCount, levelOffset, levelCount, flags} {}
/** @overload */
explicit ImageViewCreateInfo2DArray(VkImage image, Magnum::CompressedPixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt layerCount = VK_REMAINING_ARRAY_LAYERS, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_2D_ARRAY, image, format, layerOffset, layerCount, levelOffset, levelCount, flags} {}
/** @overload /** @overload
* *
@ -287,7 +311,11 @@ set (e.g., created using @ref ImageCreateInfoCubeMap or
class ImageViewCreateInfoCubeMap: public ImageViewCreateInfo { class ImageViewCreateInfoCubeMap: public ImageViewCreateInfo {
public: public:
/** @brief Constructor */ /** @brief Constructor */
explicit ImageViewCreateInfoCubeMap(VkImage image, VkFormat format, UnsignedInt layerOffset = 0, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_CUBE, image, format, layerOffset, 6, levelOffset, levelCount, flags} {} explicit ImageViewCreateInfoCubeMap(VkImage image, PixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_CUBE, image, format, layerOffset, 6, levelOffset, levelCount, flags} {}
/** @overload */
explicit ImageViewCreateInfoCubeMap(VkImage image, Magnum::PixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_CUBE, image, format, layerOffset, 6, levelOffset, levelCount, flags} {}
/** @overload */
explicit ImageViewCreateInfoCubeMap(VkImage image, Magnum::CompressedPixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_CUBE, image, format, layerOffset, 6, levelOffset, levelCount, flags} {}
/** @overload /** @overload
* *
@ -311,7 +339,11 @@ array layers to fit the required subrange.
class ImageViewCreateInfoCubeMapArray: public ImageViewCreateInfo { class ImageViewCreateInfoCubeMapArray: public ImageViewCreateInfo {
public: public:
/** @brief Constructor */ /** @brief Constructor */
explicit ImageViewCreateInfoCubeMapArray(VkImage image, VkFormat format, UnsignedInt layerOffset = 0, UnsignedInt layerCount = VK_REMAINING_ARRAY_LAYERS, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_CUBE_ARRAY, image, format, layerOffset, layerCount, levelOffset, levelCount, flags} {} explicit ImageViewCreateInfoCubeMapArray(VkImage image, PixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt layerCount = VK_REMAINING_ARRAY_LAYERS, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_CUBE_ARRAY, image, format, layerOffset, layerCount, levelOffset, levelCount, flags} {}
/** @overload */
explicit ImageViewCreateInfoCubeMapArray(VkImage image, Magnum::PixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt layerCount = VK_REMAINING_ARRAY_LAYERS, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_CUBE_ARRAY, image, format, layerOffset, layerCount, levelOffset, levelCount, flags} {}
/** @overload */
explicit ImageViewCreateInfoCubeMapArray(VkImage image, Magnum::CompressedPixelFormat format, UnsignedInt layerOffset = 0, UnsignedInt layerCount = VK_REMAINING_ARRAY_LAYERS, UnsignedInt levelOffset = 0, UnsignedInt levelCount = VK_REMAINING_MIP_LEVELS, Flags flags = {}): ImageViewCreateInfo{VK_IMAGE_VIEW_TYPE_CUBE_ARRAY, image, format, layerOffset, layerCount, levelOffset, levelCount, flags} {}
/** @overload /** @overload
* *

154
src/Magnum/Vk/Implementation/compressedPixelFormatMapping.hpp

@ -25,74 +25,75 @@
/* See Magnum/Vk/Enums.cpp and Magnum/Vk/Test/EnumsTest.cpp */ /* See Magnum/Vk/Enums.cpp and Magnum/Vk/Test/EnumsTest.cpp */
#ifdef _c #ifdef _c
_c(Bc1RGBUnorm, BC1_RGB_UNORM_BLOCK) #define _c2(input) _c(input, input)
_c(Bc1RGBSrgb, BC1_RGB_SRGB_BLOCK) _c2(Bc1RGBUnorm)
_c(Bc1RGBAUnorm, BC1_RGBA_UNORM_BLOCK) _c2(Bc1RGBSrgb)
_c(Bc1RGBASrgb, BC1_RGBA_SRGB_BLOCK) _c2(Bc1RGBAUnorm)
_c(Bc2RGBAUnorm, BC2_UNORM_BLOCK) _c2(Bc1RGBASrgb)
_c(Bc2RGBASrgb, BC2_SRGB_BLOCK) _c2(Bc2RGBAUnorm)
_c(Bc3RGBAUnorm, BC3_UNORM_BLOCK) _c2(Bc2RGBASrgb)
_c(Bc3RGBASrgb, BC3_SRGB_BLOCK) _c2(Bc3RGBAUnorm)
_c(Bc4RUnorm, BC4_UNORM_BLOCK) _c2(Bc3RGBASrgb)
_c(Bc4RSnorm, BC4_SNORM_BLOCK) _c2(Bc4RUnorm)
_c(Bc5RGUnorm, BC5_UNORM_BLOCK) _c2(Bc4RSnorm)
_c(Bc5RGSnorm, BC5_SNORM_BLOCK) _c2(Bc5RGUnorm)
_c(Bc6hRGBUfloat, BC6H_UFLOAT_BLOCK) _c2(Bc5RGSnorm)
_c(Bc6hRGBSfloat, BC6H_SFLOAT_BLOCK) _c2(Bc6hRGBUfloat)
_c(Bc7RGBAUnorm, BC7_UNORM_BLOCK) _c2(Bc6hRGBSfloat)
_c(Bc7RGBASrgb, BC7_SRGB_BLOCK) _c2(Bc7RGBAUnorm)
_c(EacR11Unorm, EAC_R11_UNORM_BLOCK) _c2(Bc7RGBASrgb)
_c(EacR11Snorm, EAC_R11_SNORM_BLOCK) _c2(EacR11Unorm)
_c(EacRG11Unorm, EAC_R11G11_UNORM_BLOCK) _c2(EacR11Snorm)
_c(EacRG11Snorm, EAC_R11G11_SNORM_BLOCK) _c2(EacRG11Unorm)
_c(Etc2RGB8Unorm, ETC2_R8G8B8_UNORM_BLOCK) _c2(EacRG11Snorm)
_c(Etc2RGB8Srgb, ETC2_R8G8B8_SRGB_BLOCK) _c2(Etc2RGB8Unorm)
_c(Etc2RGB8A1Unorm, ETC2_R8G8B8A1_UNORM_BLOCK) _c2(Etc2RGB8Srgb)
_c(Etc2RGB8A1Srgb, ETC2_R8G8B8A1_SRGB_BLOCK) _c2(Etc2RGB8A1Unorm)
_c(Etc2RGBA8Unorm, ETC2_R8G8B8A8_UNORM_BLOCK) _c2(Etc2RGB8A1Srgb)
_c(Etc2RGBA8Srgb, ETC2_R8G8B8A8_SRGB_BLOCK) _c2(Etc2RGBA8Unorm)
_c(Astc4x4RGBAUnorm, ASTC_4x4_UNORM_BLOCK) _c2(Etc2RGBA8Srgb)
_c(Astc4x4RGBASrgb, ASTC_4x4_SRGB_BLOCK) _c2(Astc4x4RGBAUnorm)
_c(Astc4x4RGBAF, ASTC_4x4_SFLOAT_BLOCK_EXT) _c2(Astc4x4RGBASrgb)
_c(Astc5x4RGBAUnorm, ASTC_5x4_UNORM_BLOCK) _c2(Astc4x4RGBAF)
_c(Astc5x4RGBASrgb, ASTC_5x4_SRGB_BLOCK) _c2(Astc5x4RGBAUnorm)
_c(Astc5x4RGBAF, ASTC_5x4_SFLOAT_BLOCK_EXT) _c2(Astc5x4RGBASrgb)
_c(Astc5x5RGBAUnorm, ASTC_5x5_UNORM_BLOCK) _c2(Astc5x4RGBAF)
_c(Astc5x5RGBASrgb, ASTC_5x5_SRGB_BLOCK) _c2(Astc5x5RGBAUnorm)
_c(Astc5x5RGBAF, ASTC_5x5_SFLOAT_BLOCK_EXT) _c2(Astc5x5RGBASrgb)
_c(Astc6x5RGBAUnorm, ASTC_6x5_UNORM_BLOCK) _c2(Astc5x5RGBAF)
_c(Astc6x5RGBASrgb, ASTC_6x5_SRGB_BLOCK) _c2(Astc6x5RGBAUnorm)
_c(Astc6x5RGBAF, ASTC_6x5_SFLOAT_BLOCK_EXT) _c2(Astc6x5RGBASrgb)
_c(Astc6x6RGBAUnorm, ASTC_6x6_UNORM_BLOCK) _c2(Astc6x5RGBAF)
_c(Astc6x6RGBASrgb, ASTC_6x6_SRGB_BLOCK) _c2(Astc6x6RGBAUnorm)
_c(Astc6x6RGBAF, ASTC_6x6_SFLOAT_BLOCK_EXT) _c2(Astc6x6RGBASrgb)
_c(Astc8x5RGBAUnorm, ASTC_8x5_UNORM_BLOCK) _c2(Astc6x6RGBAF)
_c(Astc8x5RGBASrgb, ASTC_8x5_SRGB_BLOCK) _c2(Astc8x5RGBAUnorm)
_c(Astc8x5RGBAF, ASTC_8x5_SFLOAT_BLOCK_EXT) _c2(Astc8x5RGBASrgb)
_c(Astc8x6RGBAUnorm, ASTC_8x6_UNORM_BLOCK) _c2(Astc8x5RGBAF)
_c(Astc8x6RGBASrgb, ASTC_8x6_SRGB_BLOCK) _c2(Astc8x6RGBAUnorm)
_c(Astc8x6RGBAF, ASTC_8x6_SFLOAT_BLOCK_EXT) _c2(Astc8x6RGBASrgb)
_c(Astc8x8RGBAUnorm, ASTC_8x8_UNORM_BLOCK) _c2(Astc8x6RGBAF)
_c(Astc8x8RGBASrgb, ASTC_8x8_SRGB_BLOCK) _c2(Astc8x8RGBAUnorm)
_c(Astc8x8RGBAF, ASTC_8x8_SFLOAT_BLOCK_EXT) _c2(Astc8x8RGBASrgb)
_c(Astc10x5RGBAUnorm, ASTC_10x5_UNORM_BLOCK) _c2(Astc8x8RGBAF)
_c(Astc10x5RGBASrgb, ASTC_10x5_SRGB_BLOCK) _c2(Astc10x5RGBAUnorm)
_c(Astc10x5RGBAF, ASTC_10x5_SFLOAT_BLOCK_EXT) _c2(Astc10x5RGBASrgb)
_c(Astc10x6RGBAUnorm, ASTC_10x6_UNORM_BLOCK) _c2(Astc10x5RGBAF)
_c(Astc10x6RGBASrgb, ASTC_10x6_SRGB_BLOCK) _c2(Astc10x6RGBAUnorm)
_c(Astc10x6RGBAF, ASTC_10x6_SFLOAT_BLOCK_EXT) _c2(Astc10x6RGBASrgb)
_c(Astc10x8RGBAUnorm, ASTC_10x8_UNORM_BLOCK) _c2(Astc10x6RGBAF)
_c(Astc10x8RGBASrgb, ASTC_10x8_SRGB_BLOCK) _c2(Astc10x8RGBAUnorm)
_c(Astc10x8RGBAF, ASTC_10x8_SFLOAT_BLOCK_EXT) _c2(Astc10x8RGBASrgb)
_c(Astc10x10RGBAUnorm, ASTC_10x10_UNORM_BLOCK) _c2(Astc10x8RGBAF)
_c(Astc10x10RGBASrgb, ASTC_10x10_SRGB_BLOCK) _c2(Astc10x10RGBAUnorm)
_c(Astc10x10RGBAF, ASTC_10x10_SFLOAT_BLOCK_EXT) _c2(Astc10x10RGBASrgb)
_c(Astc12x10RGBAUnorm, ASTC_12x10_UNORM_BLOCK) _c2(Astc10x10RGBAF)
_c(Astc12x10RGBASrgb, ASTC_12x10_SRGB_BLOCK) _c2(Astc12x10RGBAUnorm)
_c(Astc12x10RGBAF, ASTC_12x10_SFLOAT_BLOCK_EXT) _c2(Astc12x10RGBASrgb)
_c(Astc12x12RGBAUnorm, ASTC_12x12_UNORM_BLOCK) _c2(Astc12x10RGBAF)
_c(Astc12x12RGBASrgb, ASTC_12x12_SRGB_BLOCK) _c2(Astc12x12RGBAUnorm)
_c(Astc12x12RGBAF, ASTC_12x12_SFLOAT_BLOCK_EXT) _c2(Astc12x12RGBASrgb)
_c2(Astc12x12RGBAF)
/* https://github.com/KhronosGroup/KTX-Specification/pull/97 */ /* https://github.com/KhronosGroup/KTX-Specification/pull/97 */
_s(Astc3x3x3RGBAUnorm) //, ASTC_3x3x3_UNORM_BLOCK) _s(Astc3x3x3RGBAUnorm) //, ASTC_3x3x3_UNORM_BLOCK)
@ -127,12 +128,13 @@ _s(Astc6x6x6RGBASrgb) //, ASTC_6x6x6_SRGB_BLOCK)
_s(Astc6x6x6RGBAF) //, ASTC_6x6x6_SFLOAT_BLOCK_EXT) _s(Astc6x6x6RGBAF) //, ASTC_6x6x6_SFLOAT_BLOCK_EXT)
/* https://github.com/KhronosGroup/Vulkan-Docs/issues/512 */ /* https://github.com/KhronosGroup/Vulkan-Docs/issues/512 */
_c(PvrtcRGB2bppUnorm, PVRTC1_2BPP_UNORM_BLOCK_IMG) _c(PvrtcRGB2bppUnorm, PvrtcRGBA2bppUnorm)
_c(PvrtcRGB2bppSrgb, PVRTC1_2BPP_SRGB_BLOCK_IMG) _c(PvrtcRGB2bppSrgb, PvrtcRGBA2bppSrgb)
_c(PvrtcRGBA2bppUnorm, PVRTC1_2BPP_UNORM_BLOCK_IMG) _c2(PvrtcRGBA2bppUnorm)
_c(PvrtcRGBA2bppSrgb, PVRTC1_2BPP_SRGB_BLOCK_IMG) _c2(PvrtcRGBA2bppSrgb)
_c(PvrtcRGB4bppUnorm, PVRTC1_4BPP_UNORM_BLOCK_IMG) _c(PvrtcRGB4bppUnorm, PvrtcRGBA4bppUnorm)
_c(PvrtcRGB4bppSrgb, PVRTC1_4BPP_SRGB_BLOCK_IMG) _c(PvrtcRGB4bppSrgb, PvrtcRGBA4bppSrgb)
_c(PvrtcRGBA4bppUnorm, PVRTC1_4BPP_UNORM_BLOCK_IMG) _c2(PvrtcRGBA4bppUnorm)
_c(PvrtcRGBA4bppSrgb, PVRTC1_4BPP_SRGB_BLOCK_IMG) _c2(PvrtcRGBA4bppSrgb)
#undef _c2
#endif #endif

104
src/Magnum/Vk/Implementation/pixelFormatMapping.hpp

@ -25,56 +25,56 @@
/* See Magnum/Vk/Enums.cpp and Magnum/Vk/Test/EnumsTest.cpp */ /* See Magnum/Vk/Enums.cpp and Magnum/Vk/Test/EnumsTest.cpp */
#ifdef _c #ifdef _c
_c(R8Unorm, R8_UNORM) _c(R8Unorm)
_c(RG8Unorm, R8G8_UNORM) _c(RG8Unorm)
_c(RGB8Unorm, R8G8B8_UNORM) _c(RGB8Unorm)
_c(RGBA8Unorm, R8G8B8A8_UNORM) _c(RGBA8Unorm)
_c(R8Snorm, R8_SNORM) _c(R8Snorm)
_c(RG8Snorm, R8G8_SNORM) _c(RG8Snorm)
_c(RGB8Snorm, R8G8B8_SNORM) _c(RGB8Snorm)
_c(RGBA8Snorm, R8G8B8A8_SNORM) _c(RGBA8Snorm)
_c(R8Srgb, R8_SRGB) _c(R8Srgb)
_c(RG8Srgb, R8G8_SRGB) _c(RG8Srgb)
_c(RGB8Srgb, R8G8B8_SRGB) _c(RGB8Srgb)
_c(RGBA8Srgb, R8G8B8A8_SRGB) _c(RGBA8Srgb)
_c(R8UI, R8_UINT) _c(R8UI)
_c(RG8UI, R8G8_UINT) _c(RG8UI)
_c(RGB8UI, R8G8B8_UINT) _c(RGB8UI)
_c(RGBA8UI, R8G8B8A8_UINT) _c(RGBA8UI)
_c(R8I, R8_SINT) _c(R8I)
_c(RG8I, R8G8_SINT) _c(RG8I)
_c(RGB8I, R8G8B8_SINT) _c(RGB8I)
_c(RGBA8I, R8G8B8A8_SINT) _c(RGBA8I)
_c(R16Unorm, R16_UNORM) _c(R16Unorm)
_c(RG16Unorm, R16G16_UNORM) _c(RG16Unorm)
_c(RGB16Unorm, R16G16B16_UNORM) _c(RGB16Unorm)
_c(RGBA16Unorm, R16G16B16A16_UNORM) _c(RGBA16Unorm)
_c(R16Snorm, R16_SNORM) _c(R16Snorm)
_c(RG16Snorm, R16G16_SNORM) _c(RG16Snorm)
_c(RGB16Snorm, R16G16B16_SNORM) _c(RGB16Snorm)
_c(RGBA16Snorm, R16G16B16A16_SNORM) _c(RGBA16Snorm)
_c(R16UI, R16_UINT) _c(R16UI)
_c(RG16UI, R16G16_UINT) _c(RG16UI)
_c(RGB16UI, R16G16B16_UINT) _c(RGB16UI)
_c(RGBA16UI, R16G16B16A16_UINT) _c(RGBA16UI)
_c(R16I, R16_SINT) _c(R16I)
_c(RG16I, R16G16_SINT) _c(RG16I)
_c(RGB16I, R16G16B16_SINT) _c(RGB16I)
_c(RGBA16I, R16G16B16A16_SINT) _c(RGBA16I)
_c(R32UI, R32_UINT) _c(R32UI)
_c(RG32UI, R32G32_UINT) _c(RG32UI)
_c(RGB32UI, R32G32B32_UINT) _c(RGB32UI)
_c(RGBA32UI, R32G32B32A32_UINT) _c(RGBA32UI)
_c(R32I, R32_SINT) _c(R32I)
_c(RG32I, R32G32_SINT) _c(RG32I)
_c(RGB32I, R32G32B32_SINT) _c(RGB32I)
_c(RGBA32I, R32G32B32A32_SINT) _c(RGBA32I)
_c(R16F, R16_SFLOAT) _c(R16F)
_c(RG16F, R16G16_SFLOAT) _c(RG16F)
_c(RGB16F, R16G16B16_SFLOAT) _c(RGB16F)
_c(RGBA16F, R16G16B16A16_SFLOAT) _c(RGBA16F)
_c(R32F, R32_SFLOAT) _c(R32F)
_c(RG32F, R32G32_SFLOAT) _c(RG32F)
_c(RGB32F, R32G32B32_SFLOAT) _c(RGB32F)
_c(RGBA32F, R32G32B32A32_SFLOAT) _c(RGBA32F)
#endif #endif

248
src/Magnum/Vk/PixelFormat.cpp

@ -0,0 +1,248 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020 Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include "PixelFormat.h"
#include <Corrade/Containers/ArrayView.h>
#include <Corrade/Utility/Debug.h>
#include "Magnum/PixelFormat.h"
namespace Magnum { namespace Vk {
namespace {
constexpr PixelFormat PixelFormatMapping[] {
/* GCC 4.8 doesn't like just a {} for default enum values */
#define _c(input) PixelFormat::input,
#define _s(input) PixelFormat{},
#include "Magnum/Vk/Implementation/pixelFormatMapping.hpp"
#undef _s
#undef _c
};
constexpr PixelFormat CompressedPixelFormatMapping[] {
/* GCC 4.8 doesn't like just a {} for default enum values */
#define _c(input, format) PixelFormat::Compressed ## format,
#define _s(input) PixelFormat{},
#include "Magnum/Vk/Implementation/compressedPixelFormatMapping.hpp"
#undef _s
#undef _c
};
}
Debug& operator<<(Debug& debug, const PixelFormat value) {
debug << "Vk::PixelFormat" << Debug::nospace;
switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case Vk::PixelFormat::value: return debug << "::" << Debug::nospace << #value;
_c(R8Unorm)
_c(RG8Unorm)
_c(RGB8Unorm)
_c(RGBA8Unorm)
_c(R8Snorm)
_c(RG8Snorm)
_c(RGB8Snorm)
_c(RGBA8Snorm)
_c(R8Srgb)
_c(RG8Srgb)
_c(RGB8Srgb)
_c(RGBA8Srgb)
_c(R8UI)
_c(RG8UI)
_c(RGB8UI)
_c(RGBA8UI)
_c(R8I)
_c(RG8I)
_c(RGB8I)
_c(RGBA8I)
_c(R16Unorm)
_c(RG16Unorm)
_c(RGB16Unorm)
_c(RGBA16Unorm)
_c(R16Snorm)
_c(RG16Snorm)
_c(RGB16Snorm)
_c(RGBA16Snorm)
_c(R16UI)
_c(RG16UI)
_c(RGB16UI)
_c(RGBA16UI)
_c(R16I)
_c(RG16I)
_c(RGB16I)
_c(RGBA16I)
_c(R32UI)
_c(RG32UI)
_c(RGB32UI)
_c(RGBA32UI)
_c(R32I)
_c(RG32I)
_c(RGB32I)
_c(RGBA32I)
_c(R16F)
_c(RG16F)
_c(RGB16F)
_c(RGBA16F)
_c(R32F)
_c(RG32F)
_c(RGB32F)
_c(RGBA32F)
_c(Depth16Unorm)
_c(Depth24Unorm)
_c(Depth32F)
_c(Stencil8UI)
_c(Depth16UnormStencil8UI)
_c(Depth24UnormStencil8UI)
_c(Depth32FStencil8UI)
_c(CompressedBc1RGBUnorm)
_c(CompressedBc1RGBSrgb)
_c(CompressedBc1RGBAUnorm)
_c(CompressedBc1RGBASrgb)
_c(CompressedBc2RGBAUnorm)
_c(CompressedBc2RGBASrgb)
_c(CompressedBc3RGBAUnorm)
_c(CompressedBc3RGBASrgb)
_c(CompressedBc4RUnorm)
_c(CompressedBc4RSnorm)
_c(CompressedBc5RGUnorm)
_c(CompressedBc5RGSnorm)
_c(CompressedBc6hRGBUfloat)
_c(CompressedBc6hRGBSfloat)
_c(CompressedBc7RGBAUnorm)
_c(CompressedBc7RGBASrgb)
_c(CompressedEacR11Unorm)
_c(CompressedEacR11Snorm)
_c(CompressedEacRG11Unorm)
_c(CompressedEacRG11Snorm)
_c(CompressedEtc2RGB8Unorm)
_c(CompressedEtc2RGB8Srgb)
_c(CompressedEtc2RGB8A1Unorm)
_c(CompressedEtc2RGB8A1Srgb)
_c(CompressedEtc2RGBA8Unorm)
_c(CompressedEtc2RGBA8Srgb)
_c(CompressedAstc4x4RGBAUnorm)
_c(CompressedAstc4x4RGBASrgb)
_c(CompressedAstc4x4RGBAF)
_c(CompressedAstc5x4RGBAUnorm)
_c(CompressedAstc5x4RGBASrgb)
_c(CompressedAstc5x4RGBAF)
_c(CompressedAstc5x5RGBAUnorm)
_c(CompressedAstc5x5RGBASrgb)
_c(CompressedAstc5x5RGBAF)
_c(CompressedAstc6x5RGBAUnorm)
_c(CompressedAstc6x5RGBASrgb)
_c(CompressedAstc6x5RGBAF)
_c(CompressedAstc6x6RGBAUnorm)
_c(CompressedAstc6x6RGBASrgb)
_c(CompressedAstc6x6RGBAF)
_c(CompressedAstc8x5RGBAUnorm)
_c(CompressedAstc8x5RGBASrgb)
_c(CompressedAstc8x5RGBAF)
_c(CompressedAstc8x6RGBAUnorm)
_c(CompressedAstc8x6RGBASrgb)
_c(CompressedAstc8x6RGBAF)
_c(CompressedAstc8x8RGBAUnorm)
_c(CompressedAstc8x8RGBASrgb)
_c(CompressedAstc8x8RGBAF)
_c(CompressedAstc10x5RGBAUnorm)
_c(CompressedAstc10x5RGBASrgb)
_c(CompressedAstc10x5RGBAF)
_c(CompressedAstc10x6RGBAUnorm)
_c(CompressedAstc10x6RGBASrgb)
_c(CompressedAstc10x6RGBAF)
_c(CompressedAstc10x8RGBAUnorm)
_c(CompressedAstc10x8RGBASrgb)
_c(CompressedAstc10x8RGBAF)
_c(CompressedAstc10x10RGBAUnorm)
_c(CompressedAstc10x10RGBASrgb)
_c(CompressedAstc10x10RGBAF)
_c(CompressedAstc12x10RGBAUnorm)
_c(CompressedAstc12x10RGBASrgb)
_c(CompressedAstc12x10RGBAF)
_c(CompressedAstc12x12RGBAUnorm)
_c(CompressedAstc12x12RGBASrgb)
_c(CompressedAstc12x12RGBAF)
_c(CompressedPvrtcRGBA2bppUnorm)
_c(CompressedPvrtcRGBA2bppSrgb)
_c(CompressedPvrtcRGBA4bppUnorm)
_c(CompressedPvrtcRGBA4bppSrgb)
_c(CompressedPvrtc2RGBA2bppUnorm)
_c(CompressedPvrtc2RGBA2bppSrgb)
_c(CompressedPvrtc2RGBA4bppUnorm)
_c(CompressedPvrtc2RGBA4bppSrgb)
#undef _c
/* LCOV_EXCL_STOP */
}
/* Vulkan docs have the values in decimal, so not converting to hex */
return debug << "(" << Debug::nospace << Int(value) << Debug::nospace << ")";
}
bool hasPixelFormat(const Magnum::PixelFormat format) {
if(isPixelFormatImplementationSpecific(format))
return true;
CORRADE_ASSERT(UnsignedInt(format) - 1 < Containers::arraySize(PixelFormatMapping),
"Vk::hasPixelFormat(): invalid format" << format, {});
return UnsignedInt(PixelFormatMapping[UnsignedInt(format) - 1]);
}
bool hasPixelFormat(const Magnum::CompressedPixelFormat format) {
if(isCompressedPixelFormatImplementationSpecific(format))
return true;
CORRADE_ASSERT(UnsignedInt(format) - 1 < Containers::arraySize(CompressedPixelFormatMapping),
"Vk::hasPixelFormat(): invalid format" << format, {});
return UnsignedInt(CompressedPixelFormatMapping[UnsignedInt(format) - 1]);
}
PixelFormat pixelFormat(const Magnum::PixelFormat format) {
if(isPixelFormatImplementationSpecific(format))
return pixelFormatUnwrap<PixelFormat>(format);
CORRADE_ASSERT(UnsignedInt(format) - 1 < Containers::arraySize(PixelFormatMapping),
"Vk::pixelFormat(): invalid format" << format, {});
const PixelFormat out = PixelFormatMapping[UnsignedInt(format) - 1];
CORRADE_ASSERT(UnsignedInt(out),
"Vk::pixelFormat(): unsupported format" << format, {});
return out;
}
PixelFormat pixelFormat(const Magnum::CompressedPixelFormat format) {
if(isCompressedPixelFormatImplementationSpecific(format))
return compressedPixelFormatUnwrap<PixelFormat>(format);
CORRADE_ASSERT(UnsignedInt(format) - 1 < Containers::arraySize(CompressedPixelFormatMapping),
"Vk::pixelFormat(): invalid format" << format, {});
const PixelFormat out = CompressedPixelFormatMapping[UnsignedInt(format) - 1];
CORRADE_ASSERT(UnsignedInt(out),
"Vk::pixelFormat(): unsupported format" << format, {});
return out;
}
}}

1467
src/Magnum/Vk/PixelFormat.h

File diff suppressed because it is too large Load Diff

29
src/Magnum/Vk/RenderPass.cpp

@ -37,14 +37,15 @@
#include "Magnum/Vk/Handle.h" #include "Magnum/Vk/Handle.h"
#include "Magnum/Vk/Image.h" #include "Magnum/Vk/Image.h"
#include "Magnum/Vk/Integration.h" #include "Magnum/Vk/Integration.h"
#include "Magnum/Vk/PixelFormat.h"
#include "Magnum/Vk/Implementation/DeviceState.h" #include "Magnum/Vk/Implementation/DeviceState.h"
namespace Magnum { namespace Vk { namespace Magnum { namespace Vk {
AttachmentDescription::AttachmentDescription(const VkFormat format, const AttachmentLoadOperation loadOperation, const AttachmentStoreOperation storeOperation, const ImageLayout initialLayout, const ImageLayout finalLayout, const Int samples, const Flags flags): _description{} { AttachmentDescription::AttachmentDescription(const PixelFormat format, const AttachmentLoadOperation loadOperation, const AttachmentStoreOperation storeOperation, const ImageLayout initialLayout, const ImageLayout finalLayout, const Int samples, const Flags flags): _description{} {
_description.sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2; _description.sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2;
_description.flags = VkAttachmentDescriptionFlags(flags); _description.flags = VkAttachmentDescriptionFlags(flags);
_description.format = format; _description.format = VkFormat(format);
_description.samples = VkSampleCountFlagBits(samples); _description.samples = VkSampleCountFlagBits(samples);
_description.loadOp = VkAttachmentLoadOp(loadOperation); _description.loadOp = VkAttachmentLoadOp(loadOperation);
_description.storeOp = VkAttachmentStoreOp(storeOperation); _description.storeOp = VkAttachmentStoreOp(storeOperation);
@ -52,12 +53,20 @@ AttachmentDescription::AttachmentDescription(const VkFormat format, const Attach
_description.finalLayout = VkImageLayout(finalLayout); _description.finalLayout = VkImageLayout(finalLayout);
} }
AttachmentDescription::AttachmentDescription(const VkFormat format, const AttachmentLoadOperation loadOperation, const AttachmentStoreOperation storeOperation, const Int samples, const Flags flags): AttachmentDescription{format, loadOperation, storeOperation, ImageLayout::General, ImageLayout::General, samples, flags} {} AttachmentDescription::AttachmentDescription(const Magnum::PixelFormat format, const AttachmentLoadOperation loadOperation, const AttachmentStoreOperation storeOperation, const ImageLayout initialLayout, const ImageLayout finalLayout, const Int samples, const Flags flags): AttachmentDescription{pixelFormat(format), loadOperation, storeOperation, initialLayout, finalLayout, samples, flags} {}
AttachmentDescription::AttachmentDescription(const VkFormat format, const std::pair<AttachmentLoadOperation, AttachmentLoadOperation> depthStencilLoadOperation, const std::pair<AttachmentStoreOperation, AttachmentStoreOperation> depthStencilStoreOperation, const ImageLayout initialLayout, const ImageLayout finalLayout, const Int samples, const Flags flags): _description{} { AttachmentDescription::AttachmentDescription(const Magnum::CompressedPixelFormat format, const AttachmentLoadOperation loadOperation, const AttachmentStoreOperation storeOperation, const ImageLayout initialLayout, const ImageLayout finalLayout, const Int samples, const Flags flags): AttachmentDescription{pixelFormat(format), loadOperation, storeOperation, initialLayout, finalLayout, samples, flags} {}
AttachmentDescription::AttachmentDescription(const PixelFormat format, const AttachmentLoadOperation loadOperation, const AttachmentStoreOperation storeOperation, const Int samples, const Flags flags): AttachmentDescription{format, loadOperation, storeOperation, ImageLayout::General, ImageLayout::General, samples, flags} {}
AttachmentDescription::AttachmentDescription(const Magnum::PixelFormat format, const AttachmentLoadOperation loadOperation, const AttachmentStoreOperation storeOperation, const Int samples, const Flags flags): AttachmentDescription{pixelFormat(format), loadOperation, storeOperation, samples, flags} {}
AttachmentDescription::AttachmentDescription(const Magnum::CompressedPixelFormat format, const AttachmentLoadOperation loadOperation, const AttachmentStoreOperation storeOperation, const Int samples, const Flags flags): AttachmentDescription{pixelFormat(format), loadOperation, storeOperation, samples, flags} {}
AttachmentDescription::AttachmentDescription(const PixelFormat format, const std::pair<AttachmentLoadOperation, AttachmentLoadOperation> depthStencilLoadOperation, const std::pair<AttachmentStoreOperation, AttachmentStoreOperation> depthStencilStoreOperation, const ImageLayout initialLayout, const ImageLayout finalLayout, const Int samples, const Flags flags): _description{} {
_description.sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2; _description.sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2;
_description.flags = VkAttachmentDescriptionFlags(flags); _description.flags = VkAttachmentDescriptionFlags(flags);
_description.format = format; _description.format = VkFormat(format);
_description.samples = VkSampleCountFlagBits(samples); _description.samples = VkSampleCountFlagBits(samples);
_description.loadOp = VkAttachmentLoadOp(depthStencilLoadOperation.first); _description.loadOp = VkAttachmentLoadOp(depthStencilLoadOperation.first);
_description.storeOp = VkAttachmentStoreOp(depthStencilStoreOperation.first); _description.storeOp = VkAttachmentStoreOp(depthStencilStoreOperation.first);
@ -67,7 +76,15 @@ AttachmentDescription::AttachmentDescription(const VkFormat format, const std::p
_description.finalLayout = VkImageLayout(finalLayout); _description.finalLayout = VkImageLayout(finalLayout);
} }
AttachmentDescription::AttachmentDescription(const VkFormat format, const std::pair<AttachmentLoadOperation, AttachmentLoadOperation> depthStencilLoadOperation, const std::pair<AttachmentStoreOperation, AttachmentStoreOperation> depthStencilStoreOperation, const Int samples, const Flags flags): AttachmentDescription{format, depthStencilLoadOperation, depthStencilStoreOperation, ImageLayout::General, ImageLayout::General, samples, flags} {} AttachmentDescription::AttachmentDescription(const Magnum::PixelFormat format, const std::pair<AttachmentLoadOperation, AttachmentLoadOperation> depthStencilLoadOperation, const std::pair<AttachmentStoreOperation, AttachmentStoreOperation> depthStencilStoreOperation, const ImageLayout initialLayout, const ImageLayout finalLayout, const Int samples, const Flags flags): AttachmentDescription{pixelFormat(format), depthStencilLoadOperation, depthStencilStoreOperation, initialLayout, finalLayout, samples, flags} {}
AttachmentDescription::AttachmentDescription(const Magnum::CompressedPixelFormat format, const std::pair<AttachmentLoadOperation, AttachmentLoadOperation> depthStencilLoadOperation, const std::pair<AttachmentStoreOperation, AttachmentStoreOperation> depthStencilStoreOperation, const ImageLayout initialLayout, const ImageLayout finalLayout, const Int samples, const Flags flags): AttachmentDescription{pixelFormat(format), depthStencilLoadOperation, depthStencilStoreOperation, initialLayout, finalLayout, samples, flags} {}
AttachmentDescription::AttachmentDescription(const PixelFormat format, const std::pair<AttachmentLoadOperation, AttachmentLoadOperation> depthStencilLoadOperation, const std::pair<AttachmentStoreOperation, AttachmentStoreOperation> depthStencilStoreOperation, const Int samples, const Flags flags): AttachmentDescription{format, depthStencilLoadOperation, depthStencilStoreOperation, ImageLayout::General, ImageLayout::General, samples, flags} {}
AttachmentDescription::AttachmentDescription(const Magnum::PixelFormat format, const std::pair<AttachmentLoadOperation, AttachmentLoadOperation> depthStencilLoadOperation, const std::pair<AttachmentStoreOperation, AttachmentStoreOperation> depthStencilStoreOperation, const Int samples, const Flags flags): AttachmentDescription{pixelFormat(format), depthStencilLoadOperation, depthStencilStoreOperation, samples, flags} {}
AttachmentDescription::AttachmentDescription(const Magnum::CompressedPixelFormat format, const std::pair<AttachmentLoadOperation, AttachmentLoadOperation> depthStencilLoadOperation, const std::pair<AttachmentStoreOperation, AttachmentStoreOperation> depthStencilStoreOperation, const Int samples, const Flags flags): AttachmentDescription{pixelFormat(format), depthStencilLoadOperation, depthStencilStoreOperation, samples, flags} {}
AttachmentDescription::AttachmentDescription(NoInitT) noexcept {} AttachmentDescription::AttachmentDescription(NoInitT) noexcept {}

42
src/Magnum/Vk/RenderPassCreateInfo.h

@ -54,7 +54,7 @@ subpass.
enum class AttachmentLoadOperation: Int { enum class AttachmentLoadOperation: Int {
/** /**
* Previous contents are preserved. This is the conservative default when * Previous contents are preserved. This is the conservative default when
* using the @ref AttachmentDescription::AttachmentDescription(VkFormat, Int, Flags) * using the @ref AttachmentDescription::AttachmentDescription(PixelFormat, Int, Flags)
* constructor. * constructor.
* *
* This value is also guaranteed to be @cpp 0 @ce, which means you're * This value is also guaranteed to be @cpp 0 @ce, which means you're
@ -105,7 +105,7 @@ treated at the end of a subpass.
enum class AttachmentStoreOperation: Int { enum class AttachmentStoreOperation: Int {
/** /**
* Generated contents are written to memory. This is the conservative * Generated contents are written to memory. This is the conservative
* default when using the @ref AttachmentDescription::AttachmentDescription(VkFormat, Int, Flags) * default when using the @ref AttachmentDescription::AttachmentDescription(PixelFormat, Int, Flags)
* constructor. * constructor.
* *
* This value is also guaranteed to be @cpp 0 @ce, which means you're * This value is also guaranteed to be @cpp 0 @ce, which means you're
@ -212,19 +212,27 @@ class MAGNUM_VK_EXPORT AttachmentDescription {
* - `initialLayout` * - `initialLayout`
* - `finalLayout` * - `finalLayout`
* *
* See also @ref AttachmentDescription(VkFormat, std::pair<AttachmentLoadOperation, AttachmentLoadOperation>, std::pair<AttachmentStoreOperation, AttachmentStoreOperation>, ImageLayout, ImageLayout, Int, Flags) * See also @ref AttachmentDescription(PixelFormat, std::pair<AttachmentLoadOperation, AttachmentLoadOperation>, std::pair<AttachmentStoreOperation, AttachmentStoreOperation>, ImageLayout, ImageLayout, Int, Flags)
* for a constructing a combined depth/stencil attachment description. * for a constructing a combined depth/stencil attachment description.
*/ */
/*implicit*/ AttachmentDescription(VkFormat format, AttachmentLoadOperation loadOperation, AttachmentStoreOperation storeOperation, ImageLayout initialLayout, ImageLayout finalLayout, Int samples = 1, Flags flags = {}); /*implicit*/ AttachmentDescription(PixelFormat format, AttachmentLoadOperation loadOperation, AttachmentStoreOperation storeOperation, ImageLayout initialLayout, ImageLayout finalLayout, Int samples = 1, Flags flags = {});
/** @overload */
/*implicit*/ AttachmentDescription(Magnum::PixelFormat format, AttachmentLoadOperation loadOperation, AttachmentStoreOperation storeOperation, ImageLayout initialLayout, ImageLayout finalLayout, Int samples = 1, Flags flags = {});
/** @overload */
/*implicit*/ AttachmentDescription(Magnum::CompressedPixelFormat format, AttachmentLoadOperation loadOperation, AttachmentStoreOperation storeOperation, ImageLayout initialLayout, ImageLayout finalLayout, Int samples = 1, Flags flags = {});
/** /**
* @brief Construct with implicit conservative layout * @brief Construct with implicit conservative layout
* *
* Equivalent to calling @ref AttachmentDescription(VkFormat, AttachmentLoadOperation, AttachmentStoreOperation, ImageLayout, ImageLayout, Int, Flags) * Equivalent to calling @ref AttachmentDescription(PixelFormat, AttachmentLoadOperation, AttachmentStoreOperation, ImageLayout, ImageLayout, Int, Flags)
* with both @p initialLayout and @p finalLayout set to * with both @p initialLayout and @p finalLayout set to
* @ref ImageLayout::General. * @ref ImageLayout::General.
*/ */
/*implicit*/ AttachmentDescription(VkFormat format, AttachmentLoadOperation loadOperation, AttachmentStoreOperation storeOperation, Int samples = 1, Flags flags = {}); /*implicit*/ AttachmentDescription(PixelFormat format, AttachmentLoadOperation loadOperation, AttachmentStoreOperation storeOperation, Int samples = 1, Flags flags = {});
/** @overload */
/*implicit*/ AttachmentDescription(Magnum::PixelFormat format, AttachmentLoadOperation loadOperation, AttachmentStoreOperation storeOperation, Int samples = 1, Flags flags = {});
/** @overload */
/*implicit*/ AttachmentDescription(Magnum::CompressedPixelFormat format, AttachmentLoadOperation loadOperation, AttachmentStoreOperation storeOperation, Int samples = 1, Flags flags = {});
/** /**
* @brief Construct for a combined depth/stencil attachment * @brief Construct for a combined depth/stencil attachment
@ -260,26 +268,38 @@ class MAGNUM_VK_EXPORT AttachmentDescription {
* @todo Implement @vk_extension{KHR,separate_depth_stencil_layouts} * @todo Implement @vk_extension{KHR,separate_depth_stencil_layouts}
* and provide a pair of layouts as well * and provide a pair of layouts as well
*/ */
/*implicit*/ AttachmentDescription(VkFormat format, std::pair<AttachmentLoadOperation, AttachmentLoadOperation> depthStencilLoadOperation, std::pair<AttachmentStoreOperation, AttachmentStoreOperation> depthStencilStoreOperation, ImageLayout initialLayout, ImageLayout finalLayout, Int samples = 1, Flags flags = {}); /*implicit*/ AttachmentDescription(PixelFormat format, std::pair<AttachmentLoadOperation, AttachmentLoadOperation> depthStencilLoadOperation, std::pair<AttachmentStoreOperation, AttachmentStoreOperation> depthStencilStoreOperation, ImageLayout initialLayout, ImageLayout finalLayout, Int samples = 1, Flags flags = {});
/** @overload */
/*implicit*/ AttachmentDescription(Magnum::PixelFormat format, std::pair<AttachmentLoadOperation, AttachmentLoadOperation> depthStencilLoadOperation, std::pair<AttachmentStoreOperation, AttachmentStoreOperation> depthStencilStoreOperation, ImageLayout initialLayout, ImageLayout finalLayout, Int samples = 1, Flags flags = {});
/** @overload */
/*implicit*/ AttachmentDescription(Magnum::CompressedPixelFormat format, std::pair<AttachmentLoadOperation, AttachmentLoadOperation> depthStencilLoadOperation, std::pair<AttachmentStoreOperation, AttachmentStoreOperation> depthStencilStoreOperation, ImageLayout initialLayout, ImageLayout finalLayout, Int samples = 1, Flags flags = {});
/** /**
* @brief Construct for a combined depth/stencil attachment with implicit conservative layout * @brief Construct for a combined depth/stencil attachment with implicit conservative layout
* *
* Equivalent to calling @ref AttachmentDescription(VkFormat, std::pair<AttachmentLoadOperation, AttachmentLoadOperation>, std::pair<AttachmentStoreOperation, AttachmentStoreOperation>, ImageLayout, ImageLayout, Int, Flags) * Equivalent to calling @ref AttachmentDescription(PixelFormat, std::pair<AttachmentLoadOperation, AttachmentLoadOperation>, std::pair<AttachmentStoreOperation, AttachmentStoreOperation>, ImageLayout, ImageLayout, Int, Flags)
* with both @p initialLayout and @p finalLayout set to * with both @p initialLayout and @p finalLayout set to
* @ref ImageLayout::General. * @ref ImageLayout::General.
*/ */
/*implicit*/ AttachmentDescription(VkFormat format, std::pair<AttachmentLoadOperation, AttachmentLoadOperation> depthStencilLoadOperation, std::pair<AttachmentStoreOperation, AttachmentStoreOperation> depthStencilStoreOperation, Int samples = 1, Flags flags = {}); /*implicit*/ AttachmentDescription(PixelFormat format, std::pair<AttachmentLoadOperation, AttachmentLoadOperation> depthStencilLoadOperation, std::pair<AttachmentStoreOperation, AttachmentStoreOperation> depthStencilStoreOperation, Int samples = 1, Flags flags = {});
/** @overload */
/*implicit*/ AttachmentDescription(Magnum::PixelFormat format, std::pair<AttachmentLoadOperation, AttachmentLoadOperation> depthStencilLoadOperation, std::pair<AttachmentStoreOperation, AttachmentStoreOperation> depthStencilStoreOperation, Int samples = 1, Flags flags = {});
/** @overload */
/*implicit*/ AttachmentDescription(Magnum::CompressedPixelFormat format, std::pair<AttachmentLoadOperation, AttachmentLoadOperation> depthStencilLoadOperation, std::pair<AttachmentStoreOperation, AttachmentStoreOperation> depthStencilStoreOperation, Int samples = 1, Flags flags = {});
/** /**
* @brief Construct with implicit conservative load/store operation and layout * @brief Construct with implicit conservative load/store operation and layout
* *
* Equivalent to calling @ref AttachmentDescription(VkFormat, std::pair<AttachmentLoadOperation, AttachmentLoadOperation>, std::pair<AttachmentStoreOperation, AttachmentStoreOperation>, ImageLayout, ImageLayout, Int, Flags) * Equivalent to calling @ref AttachmentDescription(PixelFormat, std::pair<AttachmentLoadOperation, AttachmentLoadOperation>, std::pair<AttachmentStoreOperation, AttachmentStoreOperation>, ImageLayout, ImageLayout, Int, Flags)
* with @ref AttachmentLoadOperation::Load and * with @ref AttachmentLoadOperation::Load and
* @ref AttachmentStoreOperation::Store and both @p initialLayout and * @ref AttachmentStoreOperation::Store and both @p initialLayout and
* @p finalLayout set to @ref ImageLayout::General. * @p finalLayout set to @ref ImageLayout::General.
*/ */
/*implicit*/ AttachmentDescription(VkFormat format, Int samples = 1, Flags flags = {}): AttachmentDescription{format, AttachmentLoadOperation{}, AttachmentStoreOperation{}, samples, flags} {} /*implicit*/ AttachmentDescription(PixelFormat format, Int samples = 1, Flags flags = {}): AttachmentDescription{format, AttachmentLoadOperation{}, AttachmentStoreOperation{}, samples, flags} {}
/** @overload */
/*implicit*/ AttachmentDescription(Magnum::PixelFormat format, Int samples = 1, Flags flags = {}): AttachmentDescription{format, AttachmentLoadOperation{}, AttachmentStoreOperation{}, samples, flags} {}
/** @overload */
/*implicit*/ AttachmentDescription(Magnum::CompressedPixelFormat format, Int samples = 1, Flags flags = {}): AttachmentDescription{format, AttachmentLoadOperation{}, AttachmentStoreOperation{}, samples, flags} {}
/** /**
* @brief Construct without initializing the contents * @brief Construct without initializing the contents

1
src/Magnum/Vk/Test/CMakeLists.txt

@ -42,6 +42,7 @@ corrade_add_test(VkInstanceTest InstanceTest.cpp LIBRARIES MagnumVk)
corrade_add_test(VkIntegrationTest IntegrationTest.cpp LIBRARIES MagnumVk) corrade_add_test(VkIntegrationTest IntegrationTest.cpp LIBRARIES MagnumVk)
corrade_add_test(VkLayerPropertiesTest LayerPropertiesTest.cpp LIBRARIES MagnumVk) corrade_add_test(VkLayerPropertiesTest LayerPropertiesTest.cpp LIBRARIES MagnumVk)
corrade_add_test(VkMemoryTest MemoryTest.cpp LIBRARIES MagnumVkTestLib) corrade_add_test(VkMemoryTest MemoryTest.cpp LIBRARIES MagnumVkTestLib)
corrade_add_test(VkPixelFormatTest PixelFormatTest.cpp LIBRARIES MagnumVkTestLib)
corrade_add_test(VkQueueTest QueueTest.cpp LIBRARIES MagnumVk) corrade_add_test(VkQueueTest QueueTest.cpp LIBRARIES MagnumVk)
corrade_add_test(VkResultTest ResultTest.cpp LIBRARIES MagnumVk) corrade_add_test(VkResultTest ResultTest.cpp LIBRARIES MagnumVk)
corrade_add_test(VkRenderPassTest RenderPassTest.cpp LIBRARIES MagnumVkTestLib) corrade_add_test(VkRenderPassTest RenderPassTest.cpp LIBRARIES MagnumVkTestLib)

219
src/Magnum/Vk/Test/EnumsTest.cpp

@ -52,16 +52,6 @@ struct EnumsTest: TestSuite::Tester {
void mapVkFormatVertexFormatUnsupported(); void mapVkFormatVertexFormatUnsupported();
void mapVkFormatVertexFormatInvalid(); void mapVkFormatVertexFormatInvalid();
void mapVkFormatPixelFormat();
void mapVkFormatPixelFormatImplementationSpecific();
void mapVkFormatPixelFormatUnsupported();
void mapVkFormatPixelFormatInvalid();
void mapVkFormatCompressedPixelFormat();
void mapVkFormatCompressedPixelFormatImplementationSpecific();
void mapVkFormatCompressedPixelFormatUnsupported();
void mapVkFormatCompressedPixelFormatInvalid();
void mapVkFilter(); void mapVkFilter();
void mapVkFilterInvalid(); void mapVkFilterInvalid();
@ -89,16 +79,6 @@ EnumsTest::EnumsTest() {
&EnumsTest::mapVkFormatVertexFormatUnsupported, &EnumsTest::mapVkFormatVertexFormatUnsupported,
&EnumsTest::mapVkFormatVertexFormatInvalid, &EnumsTest::mapVkFormatVertexFormatInvalid,
&EnumsTest::mapVkFormatPixelFormat,
&EnumsTest::mapVkFormatPixelFormatImplementationSpecific,
&EnumsTest::mapVkFormatPixelFormatUnsupported,
&EnumsTest::mapVkFormatPixelFormatInvalid,
&EnumsTest::mapVkFormatCompressedPixelFormat,
&EnumsTest::mapVkFormatCompressedPixelFormatImplementationSpecific,
&EnumsTest::mapVkFormatCompressedPixelFormatUnsupported,
&EnumsTest::mapVkFormatCompressedPixelFormatInvalid,
&EnumsTest::mapVkFilter, &EnumsTest::mapVkFilter,
&EnumsTest::mapVkFilterInvalid, &EnumsTest::mapVkFilterInvalid,
@ -365,205 +345,6 @@ void EnumsTest::mapVkFormatVertexFormatInvalid() {
"Vk::vkFormat(): invalid format VertexFormat(0x123)\n"); "Vk::vkFormat(): invalid format VertexFormat(0x123)\n");
} }
void EnumsTest::mapVkFormatPixelFormat() {
/* Touchstone verification */
CORRADE_VERIFY(hasVkFormat(Magnum::PixelFormat::RGBA8Unorm));
CORRADE_COMPARE(vkFormat(Magnum::PixelFormat::RGBA8Unorm), VK_FORMAT_R8G8B8A8_UNORM);
/* This goes through the first 16 bits, which should be enough. Going
through 32 bits takes 8 seconds, too much. */
UnsignedInt firstUnhandled = 0xffff;
UnsignedInt nextHandled = 1; /* 0 is an invalid format */
for(UnsignedInt i = 1; i <= 0xffff; ++i) {
const auto format = Magnum::PixelFormat(i);
/* Each case verifies:
- that the entries are ordered by number by comparing a function to
expected result (so insertion here is done in proper place)
- that there was no gap (unhandled value inside the range)
- that a particular pixel format maps to a particular vkFormat */
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(format) {
#define _c(format, expectedFormat) \
case Magnum::PixelFormat::format: \
CORRADE_COMPARE(nextHandled, i); \
CORRADE_COMPARE(firstUnhandled, 0xffff); \
CORRADE_VERIFY(hasVkFormat(Magnum::PixelFormat::format)); \
CORRADE_COMPARE(vkFormat(Magnum::PixelFormat::format), VK_FORMAT_ ## expectedFormat); \
++nextHandled; \
continue;
#define _s(format) \
case Magnum::PixelFormat::format: { \
CORRADE_COMPARE(nextHandled, i); \
CORRADE_COMPARE(firstUnhandled, 0xffff); \
CORRADE_VERIFY(!hasVkFormat(Magnum::PixelFormat::format)); \
std::ostringstream out; \
{ /* Redirected otherwise graceful assert would abort */ \
Error redirectError{&out}; \
vkFormat(Magnum::PixelFormat::format); \
} \
Debug{Debug::Flag::NoNewlineAtTheEnd} << out.str(); \
++nextHandled; \
continue; \
}
#include "Magnum/Vk/Implementation/pixelFormatMapping.hpp"
#undef _s
#undef _c
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
/* Not handled by any value, remember -- we might either be at the end
of the enum range (which is okay) or some value might be unhandled
here */
firstUnhandled = i;
}
CORRADE_COMPARE(firstUnhandled, 0xffff);
}
void EnumsTest::mapVkFormatPixelFormatImplementationSpecific() {
CORRADE_VERIFY(hasVkFormat(Magnum::pixelFormatWrap(VK_FORMAT_A8B8G8R8_SINT_PACK32)));
CORRADE_COMPARE(vkFormat(Magnum::pixelFormatWrap(VK_FORMAT_A8B8G8R8_SINT_PACK32)),
VK_FORMAT_A8B8G8R8_SINT_PACK32);
}
void EnumsTest::mapVkFormatPixelFormatUnsupported() {
#ifdef CORRADE_NO_ASSERT
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");
#endif
#if 1
CORRADE_SKIP("All pixel formats are supported.");
#else
std::ostringstream out;
Error redirectError{&out};
vkFormat(Magnum::PixelFormat::RGB16UI);
CORRADE_COMPARE(out.str(), "Vk::vkFormat(): unsupported format PixelFormat::RGB16UI\n");
#endif
}
void EnumsTest::mapVkFormatPixelFormatInvalid() {
#ifdef CORRADE_NO_ASSERT
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");
#endif
std::ostringstream out;
Error redirectError{&out};
hasVkFormat(Magnum::PixelFormat{});
hasVkFormat(Magnum::PixelFormat(0x123));
vkFormat(Magnum::PixelFormat{});
vkFormat(Magnum::PixelFormat(0x123));
CORRADE_COMPARE(out.str(),
"Vk::hasVkFormat(): invalid format PixelFormat(0x0)\n"
"Vk::hasVkFormat(): invalid format PixelFormat(0x123)\n"
"Vk::vkFormat(): invalid format PixelFormat(0x0)\n"
"Vk::vkFormat(): invalid format PixelFormat(0x123)\n");
}
void EnumsTest::mapVkFormatCompressedPixelFormat() {
/* Touchstone verification */
CORRADE_VERIFY(hasVkFormat(Magnum::CompressedPixelFormat::Bc1RGBAUnorm));
CORRADE_COMPARE(vkFormat(Magnum::CompressedPixelFormat::Bc1RGBAUnorm), VK_FORMAT_BC1_RGBA_UNORM_BLOCK);
/* This goes through the first 16 bits, which should be enough. Going
through 32 bits takes 8 seconds, too much. */
UnsignedInt firstUnhandled = 0xffff;
UnsignedInt nextHandled = 1; /* 0 is an invalid format */
for(UnsignedInt i = 1; i <= 0xffff; ++i) {
const auto format = Magnum::CompressedPixelFormat(i);
/* Each case verifies:
- that the entries are ordered by number by comparing a function to
expected result (so insertion here is done in proper place)
- that there was no gap (unhandled value inside the range)
- that a particular pixel format maps to a particular VkFormat */
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(format) {
#define _c(format, expectedFormat) \
case Magnum::CompressedPixelFormat::format: \
CORRADE_COMPARE(nextHandled, i); \
CORRADE_COMPARE(firstUnhandled, 0xffff); \
CORRADE_VERIFY(hasVkFormat(Magnum::CompressedPixelFormat::format)); \
CORRADE_COMPARE(vkFormat(Magnum::CompressedPixelFormat::format), VK_FORMAT_ ## expectedFormat); \
++nextHandled; \
continue;
#define _s(format) \
case Magnum::CompressedPixelFormat::format: { \
CORRADE_COMPARE(nextHandled, i); \
CORRADE_COMPARE(firstUnhandled, 0xffff); \
CORRADE_VERIFY(!hasVkFormat(Magnum::CompressedPixelFormat::format)); \
std::ostringstream out; \
{ /* Redirected otherwise graceful assert would abort */ \
Error redirectError{&out}; \
vkFormat(Magnum::CompressedPixelFormat::format); \
} \
Debug{Debug::Flag::NoNewlineAtTheEnd} << out.str(); \
++nextHandled; \
continue; \
}
#include "Magnum/Vk/Implementation/compressedPixelFormatMapping.hpp"
#undef _s
#undef _c
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
/* Not handled by any value, remember -- we might either be at the end
of the enum range (which is okay) or some value might be unhandled
here */
firstUnhandled = i;
}
CORRADE_COMPARE(firstUnhandled, 0xffff);
}
void EnumsTest::mapVkFormatCompressedPixelFormatImplementationSpecific() {
CORRADE_VERIFY(hasVkFormat(Magnum::compressedPixelFormatWrap(VK_FORMAT_ASTC_10x6_UNORM_BLOCK)));
CORRADE_COMPARE(vkFormat(Magnum::compressedPixelFormatWrap(VK_FORMAT_ASTC_10x6_UNORM_BLOCK)),
VK_FORMAT_ASTC_10x6_UNORM_BLOCK);
}
void EnumsTest::mapVkFormatCompressedPixelFormatUnsupported() {
#ifdef CORRADE_NO_ASSERT
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");
#endif
CORRADE_VERIFY(!hasVkFormat(Magnum::CompressedPixelFormat::Astc3x3x3RGBAUnorm));
std::ostringstream out;
Error redirectError{&out};
vkFormat(Magnum::CompressedPixelFormat::Astc3x3x3RGBAUnorm);
CORRADE_COMPARE(out.str(), "Vk::vkFormat(): unsupported format CompressedPixelFormat::Astc3x3x3RGBAUnorm\n");
}
void EnumsTest::mapVkFormatCompressedPixelFormatInvalid() {
#ifdef CORRADE_NO_ASSERT
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");
#endif
std::ostringstream out;
Error redirectError{&out};
hasVkFormat(Magnum::CompressedPixelFormat{});
hasVkFormat(Magnum::CompressedPixelFormat(0x123));
vkFormat(Magnum::CompressedPixelFormat{});
vkFormat(Magnum::CompressedPixelFormat(0x123));
CORRADE_COMPARE(out.str(),
"Vk::hasVkFormat(): invalid format CompressedPixelFormat(0x0)\n"
"Vk::hasVkFormat(): invalid format CompressedPixelFormat(0x123)\n"
"Vk::vkFormat(): invalid format CompressedPixelFormat(0x0)\n"
"Vk::vkFormat(): invalid format CompressedPixelFormat(0x123)\n");
}
void EnumsTest::mapVkFilter() { void EnumsTest::mapVkFilter() {
CORRADE_COMPARE(vkFilter(SamplerFilter::Nearest), VK_FILTER_NEAREST); CORRADE_COMPARE(vkFilter(SamplerFilter::Nearest), VK_FILTER_NEAREST);
CORRADE_COMPARE(vkFilter(SamplerFilter::Linear), VK_FILTER_LINEAR); CORRADE_COMPARE(vkFilter(SamplerFilter::Linear), VK_FILTER_LINEAR);

9
src/Magnum/Vk/Test/FramebufferVkTest.cpp

@ -28,6 +28,7 @@
#include "Magnum/Vk/FramebufferCreateInfo.h" #include "Magnum/Vk/FramebufferCreateInfo.h"
#include "Magnum/Vk/ImageCreateInfo.h" #include "Magnum/Vk/ImageCreateInfo.h"
#include "Magnum/Vk/ImageViewCreateInfo.h" #include "Magnum/Vk/ImageViewCreateInfo.h"
#include "Magnum/Vk/PixelFormat.h"
#include "Magnum/Vk/RenderPassCreateInfo.h" #include "Magnum/Vk/RenderPassCreateInfo.h"
#include "Magnum/Vk/Result.h" #include "Magnum/Vk/Result.h"
#include "Magnum/Vk/VulkanTester.h" #include "Magnum/Vk/VulkanTester.h"
@ -54,9 +55,9 @@ void FramebufferVkTest::construct() {
/* Using a depth attachment as well even though not strictly necessary to /* Using a depth attachment as well even though not strictly necessary to
catch potential unexpected bugs */ catch potential unexpected bugs */
Image color{device(), ImageCreateInfo2D{ImageUsage::ColorAttachment, Image color{device(), ImageCreateInfo2D{ImageUsage::ColorAttachment,
VK_FORMAT_R8G8B8A8_UNORM, {256, 256}, 1}, MemoryFlag::DeviceLocal}; PixelFormat::RGBA8Unorm, {256, 256}, 1}, MemoryFlag::DeviceLocal};
Image depth{device(), ImageCreateInfo2D{ImageUsage::DepthStencilAttachment, Image depth{device(), ImageCreateInfo2D{ImageUsage::DepthStencilAttachment,
VK_FORMAT_D24_UNORM_S8_UINT, {256, 256}, 1}, MemoryFlag::DeviceLocal}; PixelFormat::Depth24UnormStencil8UI, {256, 256}, 1}, MemoryFlag::DeviceLocal};
ImageView colorView{device(), ImageViewCreateInfo2D{color}}; ImageView colorView{device(), ImageViewCreateInfo2D{color}};
ImageView depthView{device(), ImageViewCreateInfo2D{depth}}; ImageView depthView{device(), ImageViewCreateInfo2D{depth}};
@ -87,7 +88,7 @@ void FramebufferVkTest::construct() {
void FramebufferVkTest::constructMove() { void FramebufferVkTest::constructMove() {
Image color{device(), ImageCreateInfo2D{ImageUsage::ColorAttachment, Image color{device(), ImageCreateInfo2D{ImageUsage::ColorAttachment,
VK_FORMAT_R8G8B8A8_UNORM, {256, 256}, 1}, MemoryFlag::DeviceLocal}; PixelFormat::RGBA8Unorm, {256, 256}, 1}, MemoryFlag::DeviceLocal};
ImageView colorView{device(), ImageViewCreateInfo2D{color}}; ImageView colorView{device(), ImageViewCreateInfo2D{color}};
RenderPass renderPass{device(), RenderPassCreateInfo{} RenderPass renderPass{device(), RenderPassCreateInfo{}
.setAttachments({color.format()}) .setAttachments({color.format()})
@ -119,7 +120,7 @@ void FramebufferVkTest::constructMove() {
void FramebufferVkTest::wrap() { void FramebufferVkTest::wrap() {
Image color{device(), ImageCreateInfo2D{ImageUsage::ColorAttachment, Image color{device(), ImageCreateInfo2D{ImageUsage::ColorAttachment,
VK_FORMAT_R8G8B8A8_UNORM, {256, 256}, 1}, MemoryFlag::DeviceLocal}; PixelFormat::RGBA8Unorm, {256, 256}, 1}, MemoryFlag::DeviceLocal};
ImageView colorView{device(), ImageViewCreateInfo2D{color}}; ImageView colorView{device(), ImageViewCreateInfo2D{color}};
RenderPass renderPass{device(), RenderPassCreateInfo{} RenderPass renderPass{device(), RenderPassCreateInfo{}
.setAttachments({color.format()}) .setAttachments({color.format()})

116
src/Magnum/Vk/Test/ImageTest.cpp

@ -28,22 +28,26 @@
#include <Corrade/TestSuite/Tester.h> #include <Corrade/TestSuite/Tester.h>
#include <Corrade/Utility/DebugStl.h> #include <Corrade/Utility/DebugStl.h>
#include "Magnum/PixelFormat.h"
#include "Magnum/Vk/ImageCreateInfo.h" #include "Magnum/Vk/ImageCreateInfo.h"
#include "Magnum/Vk/Integration.h" #include "Magnum/Vk/Integration.h"
#include "Magnum/Vk/PixelFormat.h"
#include "Magnum/Vk/Test/pixelFormatTraits.h"
namespace Magnum { namespace Vk { namespace Test { namespace { namespace Magnum { namespace Vk { namespace Test { namespace {
struct ImageTest: TestSuite::Tester { struct ImageTest: TestSuite::Tester {
explicit ImageTest(); explicit ImageTest();
void createInfoConstruct(); template<class T> void createInfoConstruct();
void createInfoConstruct1D(); template<class T> void createInfoConstruct1D();
void createInfoConstruct2D(); template<class T> void createInfoConstruct2D();
void createInfoConstruct3D(); template<class T> void createInfoConstruct3D();
void createInfoConstruct1DArray(); template<class T> void createInfoConstruct1DArray();
void createInfoConstruct2DArray(); template<class T> void createInfoConstruct2DArray();
void createInfoConstructCubeMap(); template<class T> void createInfoConstructCubeMap();
void createInfoConstructCubeMapArray(); template<class T> void createInfoConstructCubeMapArray();
void createInfoConstructNoInit(); void createInfoConstructNoInit();
void createInfoConstructFromVk(); void createInfoConstructFromVk();
@ -54,14 +58,30 @@ struct ImageTest: TestSuite::Tester {
}; };
ImageTest::ImageTest() { ImageTest::ImageTest() {
addTests({&ImageTest::createInfoConstruct, addTests({&ImageTest::createInfoConstruct<PixelFormat>,
&ImageTest::createInfoConstruct1D, &ImageTest::createInfoConstruct<Magnum::PixelFormat>,
&ImageTest::createInfoConstruct2D, &ImageTest::createInfoConstruct<Magnum::CompressedPixelFormat>,
&ImageTest::createInfoConstruct3D, &ImageTest::createInfoConstruct1D<PixelFormat>,
&ImageTest::createInfoConstruct1DArray, &ImageTest::createInfoConstruct1D<Magnum::PixelFormat>,
&ImageTest::createInfoConstruct2DArray, &ImageTest::createInfoConstruct1D<Magnum::CompressedPixelFormat>,
&ImageTest::createInfoConstructCubeMap, &ImageTest::createInfoConstruct2D<PixelFormat>,
&ImageTest::createInfoConstructCubeMapArray, &ImageTest::createInfoConstruct2D<Magnum::PixelFormat>,
&ImageTest::createInfoConstruct2D<Magnum::CompressedPixelFormat>,
&ImageTest::createInfoConstruct3D<PixelFormat>,
&ImageTest::createInfoConstruct3D<Magnum::PixelFormat>,
&ImageTest::createInfoConstruct3D<Magnum::CompressedPixelFormat>,
&ImageTest::createInfoConstruct1DArray<PixelFormat>,
&ImageTest::createInfoConstruct1DArray<Magnum::PixelFormat>,
&ImageTest::createInfoConstruct1DArray<Magnum::CompressedPixelFormat>,
&ImageTest::createInfoConstruct2DArray<PixelFormat>,
&ImageTest::createInfoConstruct2DArray<Magnum::PixelFormat>,
&ImageTest::createInfoConstruct2DArray<Magnum::CompressedPixelFormat>,
&ImageTest::createInfoConstructCubeMap<PixelFormat>,
&ImageTest::createInfoConstructCubeMap<Magnum::PixelFormat>,
&ImageTest::createInfoConstructCubeMap<Magnum::CompressedPixelFormat>,
&ImageTest::createInfoConstructCubeMapArray<PixelFormat>,
&ImageTest::createInfoConstructCubeMapArray<Magnum::PixelFormat>,
&ImageTest::createInfoConstructCubeMapArray<Magnum::CompressedPixelFormat>,
&ImageTest::createInfoConstructNoInit, &ImageTest::createInfoConstructNoInit,
&ImageTest::createInfoConstructFromVk, &ImageTest::createInfoConstructFromVk,
@ -71,11 +91,13 @@ ImageTest::ImageTest() {
&ImageTest::dedicatedMemoryNotDedicated}); &ImageTest::dedicatedMemoryNotDedicated});
} }
void ImageTest::createInfoConstruct() { template<class T> void ImageTest::createInfoConstruct() {
ImageCreateInfo info{VK_IMAGE_TYPE_2D, ImageUsage::Sampled, VK_FORMAT_R8G8B8A8_UNORM, {256, 128, 1}, 6, 8, 16, ImageLayout::Undefined, ImageCreateInfo::Flag::CubeCompatible}; setTestCaseTemplateName(PixelFormatTraits<T>::name());
ImageCreateInfo info{VK_IMAGE_TYPE_2D, ImageUsage::Sampled, PixelFormatTraits<T>::format(), {256, 128, 1}, 6, 8, 16, ImageLayout::Undefined, ImageCreateInfo::Flag::CubeCompatible};
CORRADE_COMPARE(info->flags, VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT); CORRADE_COMPARE(info->flags, VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT);
CORRADE_COMPARE(info->imageType, VK_IMAGE_TYPE_2D); CORRADE_COMPARE(info->imageType, VK_IMAGE_TYPE_2D);
CORRADE_COMPARE(info->format, VK_FORMAT_R8G8B8A8_UNORM); CORRADE_COMPARE(info->format, PixelFormatTraits<T>::expected());
CORRADE_COMPARE(Vector3i(info->extent), (Vector3i{256, 128, 1})); CORRADE_COMPARE(Vector3i(info->extent), (Vector3i{256, 128, 1}));
CORRADE_COMPARE(info->mipLevels, 8); CORRADE_COMPARE(info->mipLevels, 8);
CORRADE_COMPARE(info->arrayLayers, 6); CORRADE_COMPARE(info->arrayLayers, 6);
@ -86,11 +108,13 @@ void ImageTest::createInfoConstruct() {
CORRADE_COMPARE(info->initialLayout, VK_IMAGE_LAYOUT_UNDEFINED); CORRADE_COMPARE(info->initialLayout, VK_IMAGE_LAYOUT_UNDEFINED);
} }
void ImageTest::createInfoConstruct1D() { template<class T> void ImageTest::createInfoConstruct1D() {
ImageCreateInfo1D info{ImageUsage::Storage, VK_FORMAT_R8G8B8A8_UNORM, 256, 8, 16, ImageCreateInfo::Flag::MutableFormat}; setTestCaseTemplateName(PixelFormatTraits<T>::name());
ImageCreateInfo1D info{ImageUsage::Storage, PixelFormatTraits<T>::format(), 256, 8, 16, ImageCreateInfo::Flag::MutableFormat};
CORRADE_COMPARE(info->flags, VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT); CORRADE_COMPARE(info->flags, VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT);
CORRADE_COMPARE(info->imageType, VK_IMAGE_TYPE_1D); CORRADE_COMPARE(info->imageType, VK_IMAGE_TYPE_1D);
CORRADE_COMPARE(info->format, VK_FORMAT_R8G8B8A8_UNORM); CORRADE_COMPARE(info->format, PixelFormatTraits<T>::expected());
CORRADE_COMPARE(Vector3i(info->extent), (Vector3i{256, 1, 1})); CORRADE_COMPARE(Vector3i(info->extent), (Vector3i{256, 1, 1}));
CORRADE_COMPARE(info->mipLevels, 8); CORRADE_COMPARE(info->mipLevels, 8);
CORRADE_COMPARE(info->arrayLayers, 1); CORRADE_COMPARE(info->arrayLayers, 1);
@ -98,11 +122,13 @@ void ImageTest::createInfoConstruct1D() {
CORRADE_COMPARE(info->usage, VK_IMAGE_USAGE_STORAGE_BIT); CORRADE_COMPARE(info->usage, VK_IMAGE_USAGE_STORAGE_BIT);
} }
void ImageTest::createInfoConstruct2D() { template<class T> void ImageTest::createInfoConstruct2D() {
ImageCreateInfo2D info{ImageUsage::TransferDestination, VK_FORMAT_R8G8B8A8_UNORM, {256, 64}, 8, 16, ImageCreateInfo::Flag::MutableFormat}; setTestCaseTemplateName(PixelFormatTraits<T>::name());
ImageCreateInfo2D info{ImageUsage::TransferDestination, PixelFormatTraits<T>::format(), {256, 64}, 8, 16, ImageCreateInfo::Flag::MutableFormat};
CORRADE_COMPARE(info->flags, VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT); CORRADE_COMPARE(info->flags, VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT);
CORRADE_COMPARE(info->imageType, VK_IMAGE_TYPE_2D); CORRADE_COMPARE(info->imageType, VK_IMAGE_TYPE_2D);
CORRADE_COMPARE(info->format, VK_FORMAT_R8G8B8A8_UNORM); CORRADE_COMPARE(info->format, PixelFormatTraits<T>::expected());
CORRADE_COMPARE(Vector3i(info->extent), (Vector3i{256, 64, 1})); CORRADE_COMPARE(Vector3i(info->extent), (Vector3i{256, 64, 1}));
CORRADE_COMPARE(info->mipLevels, 8); CORRADE_COMPARE(info->mipLevels, 8);
CORRADE_COMPARE(info->arrayLayers, 1); CORRADE_COMPARE(info->arrayLayers, 1);
@ -110,11 +136,13 @@ void ImageTest::createInfoConstruct2D() {
CORRADE_COMPARE(info->usage, VK_IMAGE_USAGE_TRANSFER_DST_BIT); CORRADE_COMPARE(info->usage, VK_IMAGE_USAGE_TRANSFER_DST_BIT);
} }
void ImageTest::createInfoConstruct3D() { template<class T> void ImageTest::createInfoConstruct3D() {
ImageCreateInfo3D info{ImageUsage::InputAttachment, VK_FORMAT_R8G8B8A8_UNORM, {256, 64, 32}, 8, 16, ImageCreateInfo::Flag::MutableFormat}; setTestCaseTemplateName(PixelFormatTraits<T>::name());
ImageCreateInfo3D info{ImageUsage::InputAttachment, PixelFormatTraits<T>::format(), {256, 64, 32}, 8, 16, ImageCreateInfo::Flag::MutableFormat};
CORRADE_COMPARE(info->flags, VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT); CORRADE_COMPARE(info->flags, VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT);
CORRADE_COMPARE(info->imageType, VK_IMAGE_TYPE_3D); CORRADE_COMPARE(info->imageType, VK_IMAGE_TYPE_3D);
CORRADE_COMPARE(info->format, VK_FORMAT_R8G8B8A8_UNORM); CORRADE_COMPARE(info->format, PixelFormatTraits<T>::expected());
CORRADE_COMPARE(Vector3i(info->extent), (Vector3i{256, 64, 32})); CORRADE_COMPARE(Vector3i(info->extent), (Vector3i{256, 64, 32}));
CORRADE_COMPARE(info->mipLevels, 8); CORRADE_COMPARE(info->mipLevels, 8);
CORRADE_COMPARE(info->arrayLayers, 1); CORRADE_COMPARE(info->arrayLayers, 1);
@ -122,11 +150,13 @@ void ImageTest::createInfoConstruct3D() {
CORRADE_COMPARE(info->usage, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT); CORRADE_COMPARE(info->usage, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT);
} }
void ImageTest::createInfoConstruct1DArray() { template<class T> void ImageTest::createInfoConstruct1DArray() {
ImageCreateInfo1DArray info{ImageUsage::TransferDestination, VK_FORMAT_R8G8B8A8_UNORM, {256, 64}, 8, 16, ImageCreateInfo::Flag::MutableFormat}; setTestCaseTemplateName(PixelFormatTraits<T>::name());
ImageCreateInfo1DArray info{ImageUsage::TransferDestination, PixelFormatTraits<T>::format(), {256, 64}, 8, 16, ImageCreateInfo::Flag::MutableFormat};
CORRADE_COMPARE(info->flags, VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT); CORRADE_COMPARE(info->flags, VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT);
CORRADE_COMPARE(info->imageType, VK_IMAGE_TYPE_1D); CORRADE_COMPARE(info->imageType, VK_IMAGE_TYPE_1D);
CORRADE_COMPARE(info->format, VK_FORMAT_R8G8B8A8_UNORM); CORRADE_COMPARE(info->format, PixelFormatTraits<T>::expected());
CORRADE_COMPARE(Vector3i(info->extent), (Vector3i{256, 1, 1})); CORRADE_COMPARE(Vector3i(info->extent), (Vector3i{256, 1, 1}));
CORRADE_COMPARE(info->mipLevels, 8); CORRADE_COMPARE(info->mipLevels, 8);
CORRADE_COMPARE(info->arrayLayers, 64); CORRADE_COMPARE(info->arrayLayers, 64);
@ -134,11 +164,13 @@ void ImageTest::createInfoConstruct1DArray() {
CORRADE_COMPARE(info->usage, VK_IMAGE_USAGE_TRANSFER_DST_BIT); CORRADE_COMPARE(info->usage, VK_IMAGE_USAGE_TRANSFER_DST_BIT);
} }
void ImageTest::createInfoConstruct2DArray() { template<class T> void ImageTest::createInfoConstruct2DArray() {
ImageCreateInfo2DArray info{ImageUsage::TransferDestination, VK_FORMAT_R8G8B8A8_UNORM, {256, 64, 32}, 8, 16, ImageCreateInfo::Flag::MutableFormat}; setTestCaseTemplateName(PixelFormatTraits<T>::name());
ImageCreateInfo2DArray info{ImageUsage::TransferDestination, PixelFormatTraits<T>::format(), {256, 64, 32}, 8, 16, ImageCreateInfo::Flag::MutableFormat};
CORRADE_COMPARE(info->flags, VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT); CORRADE_COMPARE(info->flags, VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT);
CORRADE_COMPARE(info->imageType, VK_IMAGE_TYPE_2D); CORRADE_COMPARE(info->imageType, VK_IMAGE_TYPE_2D);
CORRADE_COMPARE(info->format, VK_FORMAT_R8G8B8A8_UNORM); CORRADE_COMPARE(info->format, PixelFormatTraits<T>::expected());
CORRADE_COMPARE(Vector3i(info->extent), (Vector3i{256, 64, 1})); CORRADE_COMPARE(Vector3i(info->extent), (Vector3i{256, 64, 1}));
CORRADE_COMPARE(info->mipLevels, 8); CORRADE_COMPARE(info->mipLevels, 8);
CORRADE_COMPARE(info->arrayLayers, 32); CORRADE_COMPARE(info->arrayLayers, 32);
@ -146,11 +178,13 @@ void ImageTest::createInfoConstruct2DArray() {
CORRADE_COMPARE(info->usage, VK_IMAGE_USAGE_TRANSFER_DST_BIT); CORRADE_COMPARE(info->usage, VK_IMAGE_USAGE_TRANSFER_DST_BIT);
} }
void ImageTest::createInfoConstructCubeMap() { template<class T> void ImageTest::createInfoConstructCubeMap() {
ImageCreateInfoCubeMap info{ImageUsage::TransferDestination, VK_FORMAT_R8G8B8A8_UNORM, {256, 256}, 8, 16, ImageCreateInfo::Flag::MutableFormat}; setTestCaseTemplateName(PixelFormatTraits<T>::name());
ImageCreateInfoCubeMap info{ImageUsage::TransferDestination, PixelFormatTraits<T>::format(), {256, 256}, 8, 16, ImageCreateInfo::Flag::MutableFormat};
CORRADE_COMPARE(info->flags, VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT|VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT); CORRADE_COMPARE(info->flags, VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT|VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT);
CORRADE_COMPARE(info->imageType, VK_IMAGE_TYPE_2D); CORRADE_COMPARE(info->imageType, VK_IMAGE_TYPE_2D);
CORRADE_COMPARE(info->format, VK_FORMAT_R8G8B8A8_UNORM); CORRADE_COMPARE(info->format, PixelFormatTraits<T>::expected());
CORRADE_COMPARE(Vector3i(info->extent), (Vector3i{256, 256, 1})); CORRADE_COMPARE(Vector3i(info->extent), (Vector3i{256, 256, 1}));
CORRADE_COMPARE(info->mipLevels, 8); CORRADE_COMPARE(info->mipLevels, 8);
CORRADE_COMPARE(info->arrayLayers, 6); CORRADE_COMPARE(info->arrayLayers, 6);
@ -158,11 +192,13 @@ void ImageTest::createInfoConstructCubeMap() {
CORRADE_COMPARE(info->usage, VK_IMAGE_USAGE_TRANSFER_DST_BIT); CORRADE_COMPARE(info->usage, VK_IMAGE_USAGE_TRANSFER_DST_BIT);
} }
void ImageTest::createInfoConstructCubeMapArray() { template<class T> void ImageTest::createInfoConstructCubeMapArray() {
ImageCreateInfoCubeMapArray info{ImageUsage::TransferDestination, VK_FORMAT_R8G8B8A8_UNORM, {256, 256, 36}, 8, 16, ImageCreateInfo::Flag::MutableFormat}; setTestCaseTemplateName(PixelFormatTraits<T>::name());
ImageCreateInfoCubeMapArray info{ImageUsage::TransferDestination, PixelFormatTraits<T>::format(), {256, 256, 36}, 8, 16, ImageCreateInfo::Flag::MutableFormat};
CORRADE_COMPARE(info->flags, VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT|VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT); CORRADE_COMPARE(info->flags, VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT|VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT);
CORRADE_COMPARE(info->imageType, VK_IMAGE_TYPE_2D); CORRADE_COMPARE(info->imageType, VK_IMAGE_TYPE_2D);
CORRADE_COMPARE(info->format, VK_FORMAT_R8G8B8A8_UNORM); CORRADE_COMPARE(info->format, PixelFormatTraits<T>::expected());
CORRADE_COMPARE(Vector3i(info->extent), (Vector3i{256, 256, 1})); CORRADE_COMPARE(Vector3i(info->extent), (Vector3i{256, 256, 1}));
CORRADE_COMPARE(info->mipLevels, 8); CORRADE_COMPARE(info->mipLevels, 8);
CORRADE_COMPARE(info->arrayLayers, 36); CORRADE_COMPARE(info->arrayLayers, 36);

158
src/Magnum/Vk/Test/ImageViewTest.cpp

@ -32,27 +32,30 @@
#include "Magnum/Vk/Image.h" #include "Magnum/Vk/Image.h"
#include "Magnum/Vk/ImageViewCreateInfo.h" #include "Magnum/Vk/ImageViewCreateInfo.h"
#include "Magnum/Vk/Test/pixelFormatTraits.h"
namespace Magnum { namespace Vk { namespace Test { namespace { namespace Magnum { namespace Vk { namespace Test { namespace {
struct ImageViewTest: TestSuite::Tester { struct ImageViewTest: TestSuite::Tester {
explicit ImageViewTest(); explicit ImageViewTest();
void createInfoConstruct(); template<class T> void createInfoConstruct();
void createInfoConstructFromImage(); void createInfoConstructFromImage();
void createInfoConstructFromImageFormatUknown(); void createInfoConstructFromImageFormatUknown();
void createInfoConstruct1D(); template<class T> void createInfoConstruct1D();
void createInfoConstruct1DFromImage(); void createInfoConstruct1DFromImage();
void createInfoConstruct2D(); template<class T> void createInfoConstruct2D();
void createInfoConstruct2DAspect();
void createInfoConstruct2DFromImage(); void createInfoConstruct2DFromImage();
void createInfoConstruct3D(); template<class T> void createInfoConstruct3D();
void createInfoConstruct3DFromImage(); void createInfoConstruct3DFromImage();
void createInfoConstruct1DArray(); template<class T> void createInfoConstruct1DArray();
void createInfoConstruct1DArrayFromImage(); void createInfoConstruct1DArrayFromImage();
void createInfoConstruct2DArray(); template<class T> void createInfoConstruct2DArray();
void createInfoConstruct2DArrayFromImage(); void createInfoConstruct2DArrayFromImage();
void createInfoConstructCubeMap(); template<class T> void createInfoConstructCubeMap();
void createInfoConstructCubeMapFromImage(); void createInfoConstructCubeMapFromImage();
void createInfoConstructCubeMapArray(); template<class T> void createInfoConstructCubeMapArray();
void createInfoConstructCubeMapArrayFromImage(); void createInfoConstructCubeMapArrayFromImage();
void createInfoConstructNoInit(); void createInfoConstructNoInit();
void createInfoConstructFromVk(); void createInfoConstructFromVk();
@ -63,35 +66,52 @@ struct ImageViewTest: TestSuite::Tester {
const struct { const struct {
const char* name; const char* name;
VkFormat format; PixelFormat format;
VkImageAspectFlags aspect; VkImageAspectFlags aspect;
} View2DFormatData[] { } View2DFormatData[] {
{"color", VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_ASPECT_COLOR_BIT}, {"color", PixelFormat::RGBA8Unorm, VK_IMAGE_ASPECT_COLOR_BIT},
{"depth + stencil", VK_FORMAT_D32_SFLOAT_S8_UINT, VK_IMAGE_ASPECT_DEPTH_BIT|VK_IMAGE_ASPECT_STENCIL_BIT}, {"depth + stencil", PixelFormat::Depth32FStencil8UI, VK_IMAGE_ASPECT_DEPTH_BIT|VK_IMAGE_ASPECT_STENCIL_BIT},
{"depth", VK_FORMAT_D16_UNORM, VK_IMAGE_ASPECT_DEPTH_BIT}, {"depth", PixelFormat::Depth16Unorm, VK_IMAGE_ASPECT_DEPTH_BIT},
{"stencil", VK_FORMAT_S8_UINT, VK_IMAGE_ASPECT_STENCIL_BIT} {"stencil", PixelFormat::Stencil8UI, VK_IMAGE_ASPECT_STENCIL_BIT}
}; };
ImageViewTest::ImageViewTest() { ImageViewTest::ImageViewTest() {
addTests({&ImageViewTest::createInfoConstruct, addTests({&ImageViewTest::createInfoConstruct<PixelFormat>,
&ImageViewTest::createInfoConstruct<Magnum::PixelFormat>,
&ImageViewTest::createInfoConstruct<Magnum::CompressedPixelFormat>,
&ImageViewTest::createInfoConstructFromImage, &ImageViewTest::createInfoConstructFromImage,
&ImageViewTest::createInfoConstructFromImageFormatUknown, &ImageViewTest::createInfoConstructFromImageFormatUknown,
&ImageViewTest::createInfoConstruct1D, &ImageViewTest::createInfoConstruct1D<PixelFormat>,
&ImageViewTest::createInfoConstruct1DFromImage}); &ImageViewTest::createInfoConstruct1D<Magnum::PixelFormat>,
&ImageViewTest::createInfoConstruct1D<Magnum::CompressedPixelFormat>,
addInstancedTests({&ImageViewTest::createInfoConstruct2D}, &ImageViewTest::createInfoConstruct1DFromImage,
&ImageViewTest::createInfoConstruct2D<PixelFormat>,
&ImageViewTest::createInfoConstruct2D<Magnum::PixelFormat>,
&ImageViewTest::createInfoConstruct2D<Magnum::CompressedPixelFormat>});
addInstancedTests({&ImageViewTest::createInfoConstruct2DAspect},
Containers::arraySize(View2DFormatData)); Containers::arraySize(View2DFormatData));
addTests({&ImageViewTest::createInfoConstruct2DFromImage, addTests({&ImageViewTest::createInfoConstruct2DFromImage,
&ImageViewTest::createInfoConstruct3D, &ImageViewTest::createInfoConstruct3D<PixelFormat>,
&ImageViewTest::createInfoConstruct3D<Magnum::PixelFormat>,
&ImageViewTest::createInfoConstruct3D<Magnum::CompressedPixelFormat>,
&ImageViewTest::createInfoConstruct3DFromImage, &ImageViewTest::createInfoConstruct3DFromImage,
&ImageViewTest::createInfoConstruct1DArray, &ImageViewTest::createInfoConstruct1DArray<PixelFormat>,
&ImageViewTest::createInfoConstruct1DArray<Magnum::PixelFormat>,
&ImageViewTest::createInfoConstruct1DArray<Magnum::CompressedPixelFormat>,
&ImageViewTest::createInfoConstruct1DArrayFromImage, &ImageViewTest::createInfoConstruct1DArrayFromImage,
&ImageViewTest::createInfoConstruct2DArray, &ImageViewTest::createInfoConstruct2DArray<PixelFormat>,
&ImageViewTest::createInfoConstruct2DArray<Magnum::PixelFormat>,
&ImageViewTest::createInfoConstruct2DArray<Magnum::CompressedPixelFormat>,
&ImageViewTest::createInfoConstruct2DArrayFromImage, &ImageViewTest::createInfoConstruct2DArrayFromImage,
&ImageViewTest::createInfoConstructCubeMap, &ImageViewTest::createInfoConstructCubeMap<PixelFormat>,
&ImageViewTest::createInfoConstructCubeMap<Magnum::PixelFormat>,
&ImageViewTest::createInfoConstructCubeMap<Magnum::CompressedPixelFormat>,
&ImageViewTest::createInfoConstructCubeMapFromImage, &ImageViewTest::createInfoConstructCubeMapFromImage,
&ImageViewTest::createInfoConstructCubeMapArray, &ImageViewTest::createInfoConstructCubeMapArray<PixelFormat>,
&ImageViewTest::createInfoConstructCubeMapArray<Magnum::PixelFormat>,
&ImageViewTest::createInfoConstructCubeMapArray<Magnum::CompressedPixelFormat>,
&ImageViewTest::createInfoConstructCubeMapArrayFromImage, &ImageViewTest::createInfoConstructCubeMapArrayFromImage,
&ImageViewTest::createInfoConstructNoInit, &ImageViewTest::createInfoConstructNoInit,
&ImageViewTest::createInfoConstructFromVk, &ImageViewTest::createInfoConstructFromVk,
@ -102,13 +122,13 @@ ImageViewTest::ImageViewTest() {
const VkImage imageHandle{reinterpret_cast<VkImage>(0xdeadbeef)}; const VkImage imageHandle{reinterpret_cast<VkImage>(0xdeadbeef)};
void ImageViewTest::createInfoConstruct() { template<class T> void ImageViewTest::createInfoConstruct() {
/** @todo use a real flag once it exists */ /** @todo use a real flag once it exists */
ImageViewCreateInfo info{VK_IMAGE_VIEW_TYPE_2D, imageHandle, VK_FORMAT_R8G8B8A8_SRGB, 3, 5, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)}; ImageViewCreateInfo info{VK_IMAGE_VIEW_TYPE_2D, imageHandle, PixelFormatTraits<T>::format(), 3, 5, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)};
CORRADE_COMPARE(info->flags, VK_NOT_READY); CORRADE_COMPARE(info->flags, VK_NOT_READY);
CORRADE_COMPARE(info->image, imageHandle); CORRADE_COMPARE(info->image, imageHandle);
CORRADE_COMPARE(info->viewType, VK_IMAGE_VIEW_TYPE_2D); CORRADE_COMPARE(info->viewType, VK_IMAGE_VIEW_TYPE_2D);
CORRADE_COMPARE(info->format, VK_FORMAT_R8G8B8A8_SRGB); CORRADE_COMPARE(info->format, PixelFormatTraits<T>::expected());
CORRADE_COMPARE(info->subresourceRange.aspectMask, VK_IMAGE_ASPECT_COLOR_BIT); CORRADE_COMPARE(info->subresourceRange.aspectMask, VK_IMAGE_ASPECT_COLOR_BIT);
CORRADE_COMPARE(info->subresourceRange.baseArrayLayer, 3); CORRADE_COMPARE(info->subresourceRange.baseArrayLayer, 3);
CORRADE_COMPARE(info->subresourceRange.layerCount, 5); CORRADE_COMPARE(info->subresourceRange.layerCount, 5);
@ -118,7 +138,7 @@ void ImageViewTest::createInfoConstruct() {
void ImageViewTest::createInfoConstructFromImage() { void ImageViewTest::createInfoConstructFromImage() {
Device device{NoCreate}; Device device{NoCreate};
Image image = Image::wrap(device, imageHandle, VK_FORMAT_R8G8B8A8_SRGB); Image image = Image::wrap(device, imageHandle, PixelFormat::RGBA8Srgb);
/** @todo use a real flag once it exists */ /** @todo use a real flag once it exists */
ImageViewCreateInfo info{VK_IMAGE_VIEW_TYPE_2D, image, 3, 5, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)}; ImageViewCreateInfo info{VK_IMAGE_VIEW_TYPE_2D, image, 3, 5, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)};
@ -139,7 +159,7 @@ void ImageViewTest::createInfoConstructFromImageFormatUknown() {
#endif #endif
Device device{NoCreate}; Device device{NoCreate};
Image image = Image::wrap(device, imageHandle, VK_FORMAT_UNDEFINED); Image image = Image::wrap(device, imageHandle, PixelFormat{});
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
@ -148,13 +168,15 @@ void ImageViewTest::createInfoConstructFromImageFormatUknown() {
"Vk::ImageViewCreateInfo: the image has unknown format, you have to specify it explicitly\n"); "Vk::ImageViewCreateInfo: the image has unknown format, you have to specify it explicitly\n");
} }
void ImageViewTest::createInfoConstruct1D() { template<class T> void ImageViewTest::createInfoConstruct1D() {
setTestCaseTemplateName(PixelFormatTraits<T>::name());
/** @todo use a real flag once it exists */ /** @todo use a real flag once it exists */
ImageViewCreateInfo1D info{imageHandle, VK_FORMAT_R8G8B8A8_SRGB, 3, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)}; ImageViewCreateInfo1D info{imageHandle, PixelFormatTraits<T>::format(), 3, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)};
CORRADE_COMPARE(info->flags, VK_NOT_READY); CORRADE_COMPARE(info->flags, VK_NOT_READY);
CORRADE_COMPARE(info->image, imageHandle); CORRADE_COMPARE(info->image, imageHandle);
CORRADE_COMPARE(info->viewType, VK_IMAGE_VIEW_TYPE_1D); CORRADE_COMPARE(info->viewType, VK_IMAGE_VIEW_TYPE_1D);
CORRADE_COMPARE(info->format, VK_FORMAT_R8G8B8A8_SRGB); CORRADE_COMPARE(info->format, PixelFormatTraits<T>::expected());
CORRADE_COMPARE(info->subresourceRange.aspectMask, VK_IMAGE_ASPECT_COLOR_BIT); CORRADE_COMPARE(info->subresourceRange.aspectMask, VK_IMAGE_ASPECT_COLOR_BIT);
CORRADE_COMPARE(info->subresourceRange.baseArrayLayer, 3); CORRADE_COMPARE(info->subresourceRange.baseArrayLayer, 3);
CORRADE_COMPARE(info->subresourceRange.layerCount, 1); CORRADE_COMPARE(info->subresourceRange.layerCount, 1);
@ -164,7 +186,7 @@ void ImageViewTest::createInfoConstruct1D() {
void ImageViewTest::createInfoConstruct1DFromImage() { void ImageViewTest::createInfoConstruct1DFromImage() {
Device device{NoCreate}; Device device{NoCreate};
Image image = Image::wrap(device, imageHandle, VK_FORMAT_R8G8B8A8_SRGB); Image image = Image::wrap(device, imageHandle, PixelFormat::RGBA8Srgb);
/** @todo use a real flag once it exists */ /** @todo use a real flag once it exists */
ImageViewCreateInfo1D info{image, 3, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)}; ImageViewCreateInfo1D info{image, 3, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)};
@ -179,26 +201,34 @@ void ImageViewTest::createInfoConstruct1DFromImage() {
CORRADE_COMPARE(info->subresourceRange.levelCount, 9); CORRADE_COMPARE(info->subresourceRange.levelCount, 9);
} }
void ImageViewTest::createInfoConstruct2D() { template<class T> void ImageViewTest::createInfoConstruct2D() {
auto&& data = View2DFormatData[testCaseInstanceId()]; setTestCaseTemplateName(PixelFormatTraits<T>::name());
setTestCaseDescription(data.name);
/** @todo use a real flag once it exists */ /** @todo use a real flag once it exists */
ImageViewCreateInfo2D info{imageHandle, data.format, 3, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)}; ImageViewCreateInfo2D info{imageHandle, PixelFormatTraits<T>::format(), 3, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)};
CORRADE_COMPARE(info->flags, VK_NOT_READY); CORRADE_COMPARE(info->flags, VK_NOT_READY);
CORRADE_COMPARE(info->image, imageHandle); CORRADE_COMPARE(info->image, imageHandle);
CORRADE_COMPARE(info->viewType, VK_IMAGE_VIEW_TYPE_2D); CORRADE_COMPARE(info->viewType, VK_IMAGE_VIEW_TYPE_2D);
CORRADE_COMPARE(info->format, data.format); CORRADE_COMPARE(info->format, PixelFormatTraits<T>::expected());
CORRADE_COMPARE(info->subresourceRange.aspectMask, data.aspect); CORRADE_COMPARE(info->subresourceRange.aspectMask, VK_IMAGE_ASPECT_COLOR_BIT);
CORRADE_COMPARE(info->subresourceRange.baseArrayLayer, 3); CORRADE_COMPARE(info->subresourceRange.baseArrayLayer, 3);
CORRADE_COMPARE(info->subresourceRange.layerCount, 1); CORRADE_COMPARE(info->subresourceRange.layerCount, 1);
CORRADE_COMPARE(info->subresourceRange.baseMipLevel, 7); CORRADE_COMPARE(info->subresourceRange.baseMipLevel, 7);
CORRADE_COMPARE(info->subresourceRange.levelCount, 9); CORRADE_COMPARE(info->subresourceRange.levelCount, 9);
} }
void ImageViewTest::createInfoConstruct2DAspect() {
auto&& data = View2DFormatData[testCaseInstanceId()];
setTestCaseDescription(data.name);
ImageViewCreateInfo2D info{imageHandle, data.format};
CORRADE_COMPARE(info->format, VkFormat(data.format));
CORRADE_COMPARE(info->subresourceRange.aspectMask, data.aspect);
}
void ImageViewTest::createInfoConstruct2DFromImage() { void ImageViewTest::createInfoConstruct2DFromImage() {
Device device{NoCreate}; Device device{NoCreate};
Image image = Image::wrap(device, imageHandle, VK_FORMAT_R8G8B8A8_SRGB); Image image = Image::wrap(device, imageHandle, PixelFormat::RGBA8Srgb);
/** @todo use a real flag once it exists */ /** @todo use a real flag once it exists */
ImageViewCreateInfo2D info{image, 3, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)}; ImageViewCreateInfo2D info{image, 3, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)};
@ -213,13 +243,15 @@ void ImageViewTest::createInfoConstruct2DFromImage() {
CORRADE_COMPARE(info->subresourceRange.levelCount, 9); CORRADE_COMPARE(info->subresourceRange.levelCount, 9);
} }
void ImageViewTest::createInfoConstruct3D() { template<class T> void ImageViewTest::createInfoConstruct3D() {
setTestCaseTemplateName(PixelFormatTraits<T>::name());
/** @todo use a real flag once it exists */ /** @todo use a real flag once it exists */
ImageViewCreateInfo3D info{imageHandle, VK_FORMAT_R8G8B8A8_SRGB, 3, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)}; ImageViewCreateInfo3D info{imageHandle, PixelFormatTraits<T>::format(), 3, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)};
CORRADE_COMPARE(info->flags, VK_NOT_READY); CORRADE_COMPARE(info->flags, VK_NOT_READY);
CORRADE_COMPARE(info->image, imageHandle); CORRADE_COMPARE(info->image, imageHandle);
CORRADE_COMPARE(info->viewType, VK_IMAGE_VIEW_TYPE_3D); CORRADE_COMPARE(info->viewType, VK_IMAGE_VIEW_TYPE_3D);
CORRADE_COMPARE(info->format, VK_FORMAT_R8G8B8A8_SRGB); CORRADE_COMPARE(info->format, PixelFormatTraits<T>::expected());
CORRADE_COMPARE(info->subresourceRange.aspectMask, VK_IMAGE_ASPECT_COLOR_BIT); CORRADE_COMPARE(info->subresourceRange.aspectMask, VK_IMAGE_ASPECT_COLOR_BIT);
CORRADE_COMPARE(info->subresourceRange.baseArrayLayer, 3); CORRADE_COMPARE(info->subresourceRange.baseArrayLayer, 3);
CORRADE_COMPARE(info->subresourceRange.layerCount, 1); CORRADE_COMPARE(info->subresourceRange.layerCount, 1);
@ -229,7 +261,7 @@ void ImageViewTest::createInfoConstruct3D() {
void ImageViewTest::createInfoConstruct3DFromImage() { void ImageViewTest::createInfoConstruct3DFromImage() {
Device device{NoCreate}; Device device{NoCreate};
Image image = Image::wrap(device, imageHandle, VK_FORMAT_R8G8B8A8_SRGB); Image image = Image::wrap(device, imageHandle, PixelFormat::RGBA8Srgb);
/** @todo use a real flag once it exists */ /** @todo use a real flag once it exists */
ImageViewCreateInfo3D info{image, 3, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)}; ImageViewCreateInfo3D info{image, 3, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)};
@ -244,13 +276,15 @@ void ImageViewTest::createInfoConstruct3DFromImage() {
CORRADE_COMPARE(info->subresourceRange.levelCount, 9); CORRADE_COMPARE(info->subresourceRange.levelCount, 9);
} }
void ImageViewTest::createInfoConstruct1DArray() { template<class T> void ImageViewTest::createInfoConstruct1DArray() {
setTestCaseTemplateName(PixelFormatTraits<T>::name());
/** @todo use a real flag once it exists */ /** @todo use a real flag once it exists */
ImageViewCreateInfo1DArray info{imageHandle, VK_FORMAT_R8G8B8A8_SRGB, 3, 5, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)}; ImageViewCreateInfo1DArray info{imageHandle, PixelFormatTraits<T>::format(), 3, 5, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)};
CORRADE_COMPARE(info->flags, VK_NOT_READY); CORRADE_COMPARE(info->flags, VK_NOT_READY);
CORRADE_COMPARE(info->image, imageHandle); CORRADE_COMPARE(info->image, imageHandle);
CORRADE_COMPARE(info->viewType, VK_IMAGE_VIEW_TYPE_1D_ARRAY); CORRADE_COMPARE(info->viewType, VK_IMAGE_VIEW_TYPE_1D_ARRAY);
CORRADE_COMPARE(info->format, VK_FORMAT_R8G8B8A8_SRGB); CORRADE_COMPARE(info->format, PixelFormatTraits<T>::expected());
CORRADE_COMPARE(info->subresourceRange.aspectMask, VK_IMAGE_ASPECT_COLOR_BIT); CORRADE_COMPARE(info->subresourceRange.aspectMask, VK_IMAGE_ASPECT_COLOR_BIT);
CORRADE_COMPARE(info->subresourceRange.baseArrayLayer, 3); CORRADE_COMPARE(info->subresourceRange.baseArrayLayer, 3);
CORRADE_COMPARE(info->subresourceRange.layerCount, 5); CORRADE_COMPARE(info->subresourceRange.layerCount, 5);
@ -260,7 +294,7 @@ void ImageViewTest::createInfoConstruct1DArray() {
void ImageViewTest::createInfoConstruct1DArrayFromImage() { void ImageViewTest::createInfoConstruct1DArrayFromImage() {
Device device{NoCreate}; Device device{NoCreate};
Image image = Image::wrap(device, imageHandle, VK_FORMAT_R8G8B8A8_SRGB); Image image = Image::wrap(device, imageHandle, PixelFormat::RGBA8Srgb);
/** @todo use a real flag once it exists */ /** @todo use a real flag once it exists */
ImageViewCreateInfo1DArray info{image, 3, 5, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)}; ImageViewCreateInfo1DArray info{image, 3, 5, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)};
@ -275,13 +309,15 @@ void ImageViewTest::createInfoConstruct1DArrayFromImage() {
CORRADE_COMPARE(info->subresourceRange.levelCount, 9); CORRADE_COMPARE(info->subresourceRange.levelCount, 9);
} }
void ImageViewTest::createInfoConstruct2DArray() { template<class T> void ImageViewTest::createInfoConstruct2DArray() {
setTestCaseTemplateName(PixelFormatTraits<T>::name());
/** @todo use a real flag once it exists */ /** @todo use a real flag once it exists */
ImageViewCreateInfo2DArray info{imageHandle, VK_FORMAT_R8G8B8A8_SRGB, 3, 5, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)}; ImageViewCreateInfo2DArray info{imageHandle, PixelFormatTraits<T>::format(), 3, 5, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)};
CORRADE_COMPARE(info->flags, VK_NOT_READY); CORRADE_COMPARE(info->flags, VK_NOT_READY);
CORRADE_COMPARE(info->image, imageHandle); CORRADE_COMPARE(info->image, imageHandle);
CORRADE_COMPARE(info->viewType, VK_IMAGE_VIEW_TYPE_2D_ARRAY); CORRADE_COMPARE(info->viewType, VK_IMAGE_VIEW_TYPE_2D_ARRAY);
CORRADE_COMPARE(info->format, VK_FORMAT_R8G8B8A8_SRGB); CORRADE_COMPARE(info->format, PixelFormatTraits<T>::expected());
CORRADE_COMPARE(info->subresourceRange.aspectMask, VK_IMAGE_ASPECT_COLOR_BIT); CORRADE_COMPARE(info->subresourceRange.aspectMask, VK_IMAGE_ASPECT_COLOR_BIT);
CORRADE_COMPARE(info->subresourceRange.baseArrayLayer, 3); CORRADE_COMPARE(info->subresourceRange.baseArrayLayer, 3);
CORRADE_COMPARE(info->subresourceRange.layerCount, 5); CORRADE_COMPARE(info->subresourceRange.layerCount, 5);
@ -291,7 +327,7 @@ void ImageViewTest::createInfoConstruct2DArray() {
void ImageViewTest::createInfoConstruct2DArrayFromImage() { void ImageViewTest::createInfoConstruct2DArrayFromImage() {
Device device{NoCreate}; Device device{NoCreate};
Image image = Image::wrap(device, imageHandle, VK_FORMAT_R8G8B8A8_SRGB); Image image = Image::wrap(device, imageHandle, PixelFormat::RGBA8Srgb);
/** @todo use a real flag once it exists */ /** @todo use a real flag once it exists */
ImageViewCreateInfo2DArray info{image, 3, 5, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)}; ImageViewCreateInfo2DArray info{image, 3, 5, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)};
@ -306,13 +342,15 @@ void ImageViewTest::createInfoConstruct2DArrayFromImage() {
CORRADE_COMPARE(info->subresourceRange.levelCount, 9); CORRADE_COMPARE(info->subresourceRange.levelCount, 9);
} }
void ImageViewTest::createInfoConstructCubeMap() { template<class T> void ImageViewTest::createInfoConstructCubeMap() {
setTestCaseTemplateName(PixelFormatTraits<T>::name());
/** @todo use a real flag once it exists */ /** @todo use a real flag once it exists */
ImageViewCreateInfoCubeMap info{imageHandle, VK_FORMAT_R8G8B8A8_SRGB, 3, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)}; ImageViewCreateInfoCubeMap info{imageHandle, PixelFormatTraits<T>::format(), 3, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)};
CORRADE_COMPARE(info->flags, VK_NOT_READY); CORRADE_COMPARE(info->flags, VK_NOT_READY);
CORRADE_COMPARE(info->image, imageHandle); CORRADE_COMPARE(info->image, imageHandle);
CORRADE_COMPARE(info->viewType, VK_IMAGE_VIEW_TYPE_CUBE); CORRADE_COMPARE(info->viewType, VK_IMAGE_VIEW_TYPE_CUBE);
CORRADE_COMPARE(info->format, VK_FORMAT_R8G8B8A8_SRGB); CORRADE_COMPARE(info->format, PixelFormatTraits<T>::expected());
CORRADE_COMPARE(info->subresourceRange.aspectMask, VK_IMAGE_ASPECT_COLOR_BIT); CORRADE_COMPARE(info->subresourceRange.aspectMask, VK_IMAGE_ASPECT_COLOR_BIT);
CORRADE_COMPARE(info->subresourceRange.baseArrayLayer, 3); CORRADE_COMPARE(info->subresourceRange.baseArrayLayer, 3);
CORRADE_COMPARE(info->subresourceRange.layerCount, 6); CORRADE_COMPARE(info->subresourceRange.layerCount, 6);
@ -322,7 +360,7 @@ void ImageViewTest::createInfoConstructCubeMap() {
void ImageViewTest::createInfoConstructCubeMapFromImage() { void ImageViewTest::createInfoConstructCubeMapFromImage() {
Device device{NoCreate}; Device device{NoCreate};
Image image = Image::wrap(device, imageHandle, VK_FORMAT_R8G8B8A8_SRGB); Image image = Image::wrap(device, imageHandle, PixelFormat::RGBA8Srgb);
/** @todo use a real flag once it exists */ /** @todo use a real flag once it exists */
ImageViewCreateInfoCubeMap info{image, 3, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)}; ImageViewCreateInfoCubeMap info{image, 3, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)};
@ -337,13 +375,15 @@ void ImageViewTest::createInfoConstructCubeMapFromImage() {
CORRADE_COMPARE(info->subresourceRange.levelCount, 9); CORRADE_COMPARE(info->subresourceRange.levelCount, 9);
} }
void ImageViewTest::createInfoConstructCubeMapArray() { template<class T> void ImageViewTest::createInfoConstructCubeMapArray() {
setTestCaseTemplateName(PixelFormatTraits<T>::name());
/** @todo use a real flag once it exists */ /** @todo use a real flag once it exists */
ImageViewCreateInfoCubeMapArray info{imageHandle, VK_FORMAT_R8G8B8A8_SRGB, 3, 18, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)}; ImageViewCreateInfoCubeMapArray info{imageHandle, PixelFormatTraits<T>::format(), 3, 18, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)};
CORRADE_COMPARE(info->flags, VK_NOT_READY); CORRADE_COMPARE(info->flags, VK_NOT_READY);
CORRADE_COMPARE(info->image, imageHandle); CORRADE_COMPARE(info->image, imageHandle);
CORRADE_COMPARE(info->viewType, VK_IMAGE_VIEW_TYPE_CUBE_ARRAY); CORRADE_COMPARE(info->viewType, VK_IMAGE_VIEW_TYPE_CUBE_ARRAY);
CORRADE_COMPARE(info->format, VK_FORMAT_R8G8B8A8_SRGB); CORRADE_COMPARE(info->format, PixelFormatTraits<T>::expected());
CORRADE_COMPARE(info->subresourceRange.aspectMask, VK_IMAGE_ASPECT_COLOR_BIT); CORRADE_COMPARE(info->subresourceRange.aspectMask, VK_IMAGE_ASPECT_COLOR_BIT);
CORRADE_COMPARE(info->subresourceRange.baseArrayLayer, 3); CORRADE_COMPARE(info->subresourceRange.baseArrayLayer, 3);
CORRADE_COMPARE(info->subresourceRange.layerCount, 18); CORRADE_COMPARE(info->subresourceRange.layerCount, 18);
@ -353,7 +393,7 @@ void ImageViewTest::createInfoConstructCubeMapArray() {
void ImageViewTest::createInfoConstructCubeMapArrayFromImage() { void ImageViewTest::createInfoConstructCubeMapArrayFromImage() {
Device device{NoCreate}; Device device{NoCreate};
Image image = Image::wrap(device, imageHandle, VK_FORMAT_R8G8B8A8_SRGB); Image image = Image::wrap(device, imageHandle, PixelFormat::RGBA8Srgb);
/** @todo use a real flag once it exists */ /** @todo use a real flag once it exists */
ImageViewCreateInfoCubeMapArray info{image, 3, 18, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)}; ImageViewCreateInfoCubeMapArray info{image, 3, 18, 7, 9, ImageViewCreateInfo::Flag(VK_NOT_READY)};

19
src/Magnum/Vk/Test/ImageViewVkTest.cpp

@ -29,6 +29,7 @@
#include "Magnum/Vk/Handle.h" #include "Magnum/Vk/Handle.h"
#include "Magnum/Vk/ImageCreateInfo.h" #include "Magnum/Vk/ImageCreateInfo.h"
#include "Magnum/Vk/ImageViewCreateInfo.h" #include "Magnum/Vk/ImageViewCreateInfo.h"
#include "Magnum/Vk/PixelFormat.h"
#include "Magnum/Vk/Result.h" #include "Magnum/Vk/Result.h"
#include "Magnum/Vk/VulkanTester.h" #include "Magnum/Vk/VulkanTester.h"
@ -64,7 +65,7 @@ ImageViewVkTest::ImageViewVkTest() {
void ImageViewVkTest::construct1D() { void ImageViewVkTest::construct1D() {
Image image{device(), ImageCreateInfo1D{ImageUsage::Sampled, Image image{device(), ImageCreateInfo1D{ImageUsage::Sampled,
VK_FORMAT_R8G8B8A8_UNORM, 256, 1}, MemoryFlag::DeviceLocal}; PixelFormat::RGBA8Unorm, 256, 1}, MemoryFlag::DeviceLocal};
{ {
ImageView view{device(), ImageViewCreateInfo1D{image}}; ImageView view{device(), ImageViewCreateInfo1D{image}};
@ -78,7 +79,7 @@ void ImageViewVkTest::construct1D() {
void ImageViewVkTest::construct2D() { void ImageViewVkTest::construct2D() {
Image image{device(), ImageCreateInfo2D{ImageUsage::Sampled, Image image{device(), ImageCreateInfo2D{ImageUsage::Sampled,
VK_FORMAT_R8G8B8A8_UNORM, {256, 256}, 1}, MemoryFlag::DeviceLocal}; PixelFormat::RGBA8Unorm, {256, 256}, 1}, MemoryFlag::DeviceLocal};
{ {
ImageView view{device(), ImageViewCreateInfo2D{image}}; ImageView view{device(), ImageViewCreateInfo2D{image}};
@ -92,7 +93,7 @@ void ImageViewVkTest::construct2D() {
void ImageViewVkTest::construct3D() { void ImageViewVkTest::construct3D() {
Image image{device(), ImageCreateInfo3D{ImageUsage::Sampled, Image image{device(), ImageCreateInfo3D{ImageUsage::Sampled,
VK_FORMAT_R8G8B8A8_UNORM, {256, 256, 10}, 1}, MemoryFlag::DeviceLocal}; PixelFormat::RGBA8Unorm, {256, 256, 10}, 1}, MemoryFlag::DeviceLocal};
{ {
ImageView view{device(), ImageViewCreateInfo3D{image}}; ImageView view{device(), ImageViewCreateInfo3D{image}};
@ -106,7 +107,7 @@ void ImageViewVkTest::construct3D() {
void ImageViewVkTest::construct1DArray() { void ImageViewVkTest::construct1DArray() {
Image image{device(), ImageCreateInfo1DArray{ImageUsage::Sampled, Image image{device(), ImageCreateInfo1DArray{ImageUsage::Sampled,
VK_FORMAT_R8G8B8A8_UNORM, {256, 10}, 1}, MemoryFlag::DeviceLocal}; PixelFormat::RGBA8Unorm, {256, 10}, 1}, MemoryFlag::DeviceLocal};
{ {
ImageView view{device(), ImageViewCreateInfo1DArray{image}}; ImageView view{device(), ImageViewCreateInfo1DArray{image}};
@ -120,7 +121,7 @@ void ImageViewVkTest::construct1DArray() {
void ImageViewVkTest::construct2DArray() { void ImageViewVkTest::construct2DArray() {
Image image{device(), ImageCreateInfo2DArray{ImageUsage::Sampled, Image image{device(), ImageCreateInfo2DArray{ImageUsage::Sampled,
VK_FORMAT_R8G8B8A8_UNORM, {256, 256, 10}, 1}, MemoryFlag::DeviceLocal}; PixelFormat::RGBA8Unorm, {256, 256, 10}, 1}, MemoryFlag::DeviceLocal};
{ {
ImageView view{device(), ImageViewCreateInfo2DArray{image}}; ImageView view{device(), ImageViewCreateInfo2DArray{image}};
@ -134,7 +135,7 @@ void ImageViewVkTest::construct2DArray() {
void ImageViewVkTest::constructCubeMap() { void ImageViewVkTest::constructCubeMap() {
Image image{device(), ImageCreateInfoCubeMap{ImageUsage::Sampled, Image image{device(), ImageCreateInfoCubeMap{ImageUsage::Sampled,
VK_FORMAT_R8G8B8A8_UNORM, {256, 256}, 1}, MemoryFlag::DeviceLocal}; PixelFormat::RGBA8Unorm, {256, 256}, 1}, MemoryFlag::DeviceLocal};
{ {
ImageView view{device(), ImageViewCreateInfoCubeMap{image}}; ImageView view{device(), ImageViewCreateInfoCubeMap{image}};
@ -156,7 +157,7 @@ void ImageViewVkTest::constructCubeMapArray() {
.addQueues(0, {0.0f}, {queue2}) .addQueues(0, {0.0f}, {queue2})
.setEnabledFeatures(DeviceFeature::ImageCubeArray)}; .setEnabledFeatures(DeviceFeature::ImageCubeArray)};
Image image{device2, ImageCreateInfoCubeMapArray{ImageUsage::Sampled, Image image{device2, ImageCreateInfoCubeMapArray{ImageUsage::Sampled,
VK_FORMAT_R8G8B8A8_UNORM, {256, 256, 18}, 1}, MemoryFlag::DeviceLocal}; PixelFormat::RGBA8Unorm, {256, 256, 18}, 1}, MemoryFlag::DeviceLocal};
{ {
ImageView view{device2, ImageViewCreateInfoCubeMapArray{image}}; ImageView view{device2, ImageViewCreateInfoCubeMapArray{image}};
@ -170,7 +171,7 @@ void ImageViewVkTest::constructCubeMapArray() {
void ImageViewVkTest::constructMove() { void ImageViewVkTest::constructMove() {
Image image{device(), ImageCreateInfo2D{ImageUsage::Sampled, Image image{device(), ImageCreateInfo2D{ImageUsage::Sampled,
VK_FORMAT_R8G8B8A8_UNORM, {256, 256}, 1}, MemoryFlag::DeviceLocal}; PixelFormat::RGBA8Unorm, {256, 256}, 1}, MemoryFlag::DeviceLocal};
ImageView a{device(), ImageViewCreateInfo2D{image}}; ImageView a{device(), ImageViewCreateInfo2D{image}};
VkImageView handle = a.handle(); VkImageView handle = a.handle();
@ -192,7 +193,7 @@ void ImageViewVkTest::constructMove() {
void ImageViewVkTest::wrap() { void ImageViewVkTest::wrap() {
Image image{device(), ImageCreateInfo2D{ImageUsage::Sampled, Image image{device(), ImageCreateInfo2D{ImageUsage::Sampled,
VK_FORMAT_R8G8B8A8_UNORM, {256, 256}, 1}, MemoryFlag::DeviceLocal}; PixelFormat::RGBA8Unorm, {256, 256}, 1}, MemoryFlag::DeviceLocal};
VkImageView view{}; VkImageView view{};
CORRADE_COMPARE(Result(device()->CreateImageView(device(), CORRADE_COMPARE(Result(device()->CreateImageView(device(),

60
src/Magnum/Vk/Test/ImageVkTest.cpp

@ -33,6 +33,8 @@
#include "Magnum/Vk/Result.h" #include "Magnum/Vk/Result.h"
#include "Magnum/Vk/VulkanTester.h" #include "Magnum/Vk/VulkanTester.h"
#include "Magnum/Vk/Test/pixelFormatTraits.h"
namespace Magnum { namespace Vk { namespace Test { namespace { namespace Magnum { namespace Vk { namespace Test { namespace {
struct ImageVkTest: VulkanTester { struct ImageVkTest: VulkanTester {
@ -47,7 +49,7 @@ struct ImageVkTest: VulkanTester {
void constructCubeMapArray(); void constructCubeMapArray();
void constructMove(); void constructMove();
void wrap(); template<class T> void wrap();
void memoryRequirements(); void memoryRequirements();
@ -67,7 +69,9 @@ ImageVkTest::ImageVkTest() {
&ImageVkTest::constructCubeMapArray, &ImageVkTest::constructCubeMapArray,
&ImageVkTest::constructMove, &ImageVkTest::constructMove,
&ImageVkTest::wrap, &ImageVkTest::wrap<PixelFormat>,
&ImageVkTest::wrap<Magnum::PixelFormat>,
&ImageVkTest::wrap<Magnum::CompressedPixelFormat>,
&ImageVkTest::memoryRequirements, &ImageVkTest::memoryRequirements,
@ -80,10 +84,10 @@ ImageVkTest::ImageVkTest() {
void ImageVkTest::construct1D() { void ImageVkTest::construct1D() {
{ {
Image image{device(), ImageCreateInfo1D{ImageUsage::Sampled, Image image{device(), ImageCreateInfo1D{ImageUsage::Sampled,
VK_FORMAT_R8G8B8A8_UNORM, 256, 8}, NoAllocate}; PixelFormat::RGBA8Unorm, 256, 8}, NoAllocate};
CORRADE_VERIFY(image.handle()); CORRADE_VERIFY(image.handle());
CORRADE_COMPARE(image.handleFlags(), HandleFlag::DestroyOnDestruction); CORRADE_COMPARE(image.handleFlags(), HandleFlag::DestroyOnDestruction);
CORRADE_COMPARE(image.format(), VK_FORMAT_R8G8B8A8_UNORM); CORRADE_COMPARE(image.format(), PixelFormat::RGBA8Unorm);
} }
/* Shouldn't crash or anything */ /* Shouldn't crash or anything */
@ -93,10 +97,10 @@ void ImageVkTest::construct1D() {
void ImageVkTest::construct2D() { void ImageVkTest::construct2D() {
{ {
Image image{device(), ImageCreateInfo2D{ImageUsage::Sampled, Image image{device(), ImageCreateInfo2D{ImageUsage::Sampled,
VK_FORMAT_R8G8B8A8_UNORM, {256, 256}, 8}, NoAllocate}; PixelFormat::RGBA8Unorm, {256, 256}, 8}, NoAllocate};
CORRADE_VERIFY(image.handle()); CORRADE_VERIFY(image.handle());
CORRADE_COMPARE(image.handleFlags(), HandleFlag::DestroyOnDestruction); CORRADE_COMPARE(image.handleFlags(), HandleFlag::DestroyOnDestruction);
CORRADE_COMPARE(image.format(), VK_FORMAT_R8G8B8A8_UNORM); CORRADE_COMPARE(image.format(), PixelFormat::RGBA8Unorm);
} }
/* Shouldn't crash or anything */ /* Shouldn't crash or anything */
@ -106,10 +110,10 @@ void ImageVkTest::construct2D() {
void ImageVkTest::construct3D() { void ImageVkTest::construct3D() {
{ {
Image image{device(), ImageCreateInfo3D{ImageUsage::Sampled, Image image{device(), ImageCreateInfo3D{ImageUsage::Sampled,
VK_FORMAT_R8G8B8A8_UNORM, {256, 256, 64}, 8}, NoAllocate}; PixelFormat::RGBA8Unorm, {256, 256, 64}, 8}, NoAllocate};
CORRADE_VERIFY(image.handle()); CORRADE_VERIFY(image.handle());
CORRADE_COMPARE(image.handleFlags(), HandleFlag::DestroyOnDestruction); CORRADE_COMPARE(image.handleFlags(), HandleFlag::DestroyOnDestruction);
CORRADE_COMPARE(image.format(), VK_FORMAT_R8G8B8A8_UNORM); CORRADE_COMPARE(image.format(), PixelFormat::RGBA8Unorm);
} }
/* Shouldn't crash or anything */ /* Shouldn't crash or anything */
@ -119,10 +123,10 @@ void ImageVkTest::construct3D() {
void ImageVkTest::construct1DArray() { void ImageVkTest::construct1DArray() {
{ {
Image image{device(), ImageCreateInfo1DArray{ImageUsage::Sampled, Image image{device(), ImageCreateInfo1DArray{ImageUsage::Sampled,
VK_FORMAT_R8G8B8A8_UNORM, {256, 64}, 8}, NoAllocate}; PixelFormat::RGBA8Unorm, {256, 64}, 8}, NoAllocate};
CORRADE_VERIFY(image.handle()); CORRADE_VERIFY(image.handle());
CORRADE_COMPARE(image.handleFlags(), HandleFlag::DestroyOnDestruction); CORRADE_COMPARE(image.handleFlags(), HandleFlag::DestroyOnDestruction);
CORRADE_COMPARE(image.format(), VK_FORMAT_R8G8B8A8_UNORM); CORRADE_COMPARE(image.format(), PixelFormat::RGBA8Unorm);
} }
/* Shouldn't crash or anything */ /* Shouldn't crash or anything */
@ -132,10 +136,10 @@ void ImageVkTest::construct1DArray() {
void ImageVkTest::construct2DArray() { void ImageVkTest::construct2DArray() {
{ {
Image image{device(), ImageCreateInfo2DArray{ImageUsage::Sampled, Image image{device(), ImageCreateInfo2DArray{ImageUsage::Sampled,
VK_FORMAT_R8G8B8A8_UNORM, {256, 256, 64}, 8}, NoAllocate}; PixelFormat::RGBA8Unorm, {256, 256, 64}, 8}, NoAllocate};
CORRADE_VERIFY(image.handle()); CORRADE_VERIFY(image.handle());
CORRADE_COMPARE(image.handleFlags(), HandleFlag::DestroyOnDestruction); CORRADE_COMPARE(image.handleFlags(), HandleFlag::DestroyOnDestruction);
CORRADE_COMPARE(image.format(), VK_FORMAT_R8G8B8A8_UNORM); CORRADE_COMPARE(image.format(), PixelFormat::RGBA8Unorm);
} }
/* Shouldn't crash or anything */ /* Shouldn't crash or anything */
@ -145,10 +149,10 @@ void ImageVkTest::construct2DArray() {
void ImageVkTest::constructCubeMap() { void ImageVkTest::constructCubeMap() {
{ {
Image image{device(), ImageCreateInfoCubeMap{ImageUsage::Sampled, Image image{device(), ImageCreateInfoCubeMap{ImageUsage::Sampled,
VK_FORMAT_R8G8B8A8_UNORM, {256, 256}, 8}, NoAllocate}; PixelFormat::RGBA8Unorm, {256, 256}, 8}, NoAllocate};
CORRADE_VERIFY(image.handle()); CORRADE_VERIFY(image.handle());
CORRADE_COMPARE(image.handleFlags(), HandleFlag::DestroyOnDestruction); CORRADE_COMPARE(image.handleFlags(), HandleFlag::DestroyOnDestruction);
CORRADE_COMPARE(image.format(), VK_FORMAT_R8G8B8A8_UNORM); CORRADE_COMPARE(image.format(), PixelFormat::RGBA8Unorm);
} }
/* Shouldn't crash or anything */ /* Shouldn't crash or anything */
@ -158,10 +162,10 @@ void ImageVkTest::constructCubeMap() {
void ImageVkTest::constructCubeMapArray() { void ImageVkTest::constructCubeMapArray() {
{ {
Image image{device(), ImageCreateInfoCubeMapArray{ImageUsage::Sampled, Image image{device(), ImageCreateInfoCubeMapArray{ImageUsage::Sampled,
VK_FORMAT_R8G8B8A8_UNORM, {256, 256, 36}, 8}, NoAllocate}; PixelFormat::RGBA8Unorm, {256, 256, 36}, 8}, NoAllocate};
CORRADE_VERIFY(image.handle()); CORRADE_VERIFY(image.handle());
CORRADE_COMPARE(image.handleFlags(), HandleFlag::DestroyOnDestruction); CORRADE_COMPARE(image.handleFlags(), HandleFlag::DestroyOnDestruction);
CORRADE_COMPARE(image.format(), VK_FORMAT_R8G8B8A8_UNORM); CORRADE_COMPARE(image.format(), PixelFormat::RGBA8Unorm);
} }
/* Shouldn't crash or anything */ /* Shouldn't crash or anything */
@ -171,7 +175,7 @@ void ImageVkTest::constructCubeMapArray() {
void ImageVkTest::constructMove() { void ImageVkTest::constructMove() {
/* Verify that also the dedicated memory gets moved */ /* Verify that also the dedicated memory gets moved */
Image a{device(), ImageCreateInfo2D{ImageUsage::ColorAttachment, Image a{device(), ImageCreateInfo2D{ImageUsage::ColorAttachment,
VK_FORMAT_R8G8B8A8_UNORM, {256, 256}, 1}, PixelFormat::RGBA8Unorm, {256, 256}, 1},
MemoryFlag::DeviceLocal}; MemoryFlag::DeviceLocal};
VkImage handle = a.handle(); VkImage handle = a.handle();
VkDeviceMemory memoryHandle = a.dedicatedMemory().handle(); VkDeviceMemory memoryHandle = a.dedicatedMemory().handle();
@ -181,7 +185,7 @@ void ImageVkTest::constructMove() {
CORRADE_VERIFY(!a.hasDedicatedMemory()); CORRADE_VERIFY(!a.hasDedicatedMemory());
CORRADE_COMPARE(b.handle(), handle); CORRADE_COMPARE(b.handle(), handle);
CORRADE_COMPARE(b.handleFlags(), HandleFlag::DestroyOnDestruction); CORRADE_COMPARE(b.handleFlags(), HandleFlag::DestroyOnDestruction);
CORRADE_COMPARE(b.format(), VK_FORMAT_R8G8B8A8_UNORM); CORRADE_COMPARE(b.format(), PixelFormat::RGBA8Unorm);
CORRADE_VERIFY(b.hasDedicatedMemory()); CORRADE_VERIFY(b.hasDedicatedMemory());
CORRADE_COMPARE(b.dedicatedMemory().handle(), memoryHandle); CORRADE_COMPARE(b.dedicatedMemory().handle(), memoryHandle);
@ -192,7 +196,7 @@ void ImageVkTest::constructMove() {
CORRADE_COMPARE(b.handleFlags(), HandleFlags{}); CORRADE_COMPARE(b.handleFlags(), HandleFlags{});
CORRADE_COMPARE(c.handle(), handle); CORRADE_COMPARE(c.handle(), handle);
CORRADE_COMPARE(c.handleFlags(), HandleFlag::DestroyOnDestruction); CORRADE_COMPARE(c.handleFlags(), HandleFlag::DestroyOnDestruction);
CORRADE_COMPARE(c.format(), VK_FORMAT_R8G8B8A8_UNORM); CORRADE_COMPARE(c.format(), PixelFormat::RGBA8Unorm);
CORRADE_VERIFY(c.hasDedicatedMemory()); CORRADE_VERIFY(c.hasDedicatedMemory());
CORRADE_COMPARE(c.dedicatedMemory().handle(), memoryHandle); CORRADE_COMPARE(c.dedicatedMemory().handle(), memoryHandle);
@ -200,17 +204,19 @@ void ImageVkTest::constructMove() {
CORRADE_VERIFY(std::is_nothrow_move_assignable<Image>::value); CORRADE_VERIFY(std::is_nothrow_move_assignable<Image>::value);
} }
void ImageVkTest::wrap() { template<class T> void ImageVkTest::wrap() {
setTestCaseTemplateName(PixelFormatTraits<T>::name());
VkImage image{}; VkImage image{};
CORRADE_COMPARE(Result(device()->CreateImage(device(), CORRADE_COMPARE(Result(device()->CreateImage(device(),
ImageCreateInfo2D{ImageUsage::Sampled, ImageCreateInfo2D{ImageUsage::Sampled,
VK_FORMAT_R8G8B8A8_UNORM, {256, 256}, 8}, PixelFormatTraits<T>::format(), {256, 256}, 8},
nullptr, &image)), Result::Success); nullptr, &image)), Result::Success);
CORRADE_VERIFY(image); CORRADE_VERIFY(image);
auto wrapped = Image::wrap(device(), image, VK_FORMAT_R8G8B8A8_UNORM, HandleFlag::DestroyOnDestruction); auto wrapped = Image::wrap(device(), image, PixelFormatTraits<T>::format(), HandleFlag::DestroyOnDestruction);
CORRADE_COMPARE(wrapped.handle(), image); CORRADE_COMPARE(wrapped.handle(), image);
CORRADE_COMPARE(wrapped.format(), VK_FORMAT_R8G8B8A8_UNORM); CORRADE_COMPARE(wrapped.format(), PixelFormat(PixelFormatTraits<T>::expected()));
/* Release the handle again, destroy by hand */ /* Release the handle again, destroy by hand */
CORRADE_COMPARE(wrapped.release(), image); CORRADE_COMPARE(wrapped.release(), image);
@ -220,7 +226,7 @@ void ImageVkTest::wrap() {
void ImageVkTest::memoryRequirements() { void ImageVkTest::memoryRequirements() {
/* Use linear tiling for a deterministic memory size */ /* Use linear tiling for a deterministic memory size */
ImageCreateInfo2D info{ImageUsage::Sampled, VK_FORMAT_R8G8B8A8_UNORM, {128, 64}, 1}; ImageCreateInfo2D info{ImageUsage::Sampled, PixelFormat::RGBA8Unorm, {128, 64}, 1};
info->tiling = VK_IMAGE_TILING_LINEAR; info->tiling = VK_IMAGE_TILING_LINEAR;
Image image{device(), info, NoAllocate}; Image image{device(), info, NoAllocate};
@ -238,7 +244,7 @@ void ImageVkTest::memoryRequirements() {
void ImageVkTest::bindMemory() { void ImageVkTest::bindMemory() {
Image image{device(), ImageCreateInfo2D{ImageUsage::Sampled, Image image{device(), ImageCreateInfo2D{ImageUsage::Sampled,
VK_FORMAT_R8G8B8A8_UNORM, {256, 256}, 8}, NoAllocate}; PixelFormat::RGBA8Unorm, {256, 256}, 8}, NoAllocate};
MemoryRequirements requirements = image.memoryRequirements(); MemoryRequirements requirements = image.memoryRequirements();
/* We're testing the offset, so ensure what we hardcode is correctly /* We're testing the offset, so ensure what we hardcode is correctly
@ -258,7 +264,7 @@ void ImageVkTest::bindMemory() {
void ImageVkTest::bindDedicatedMemory() { void ImageVkTest::bindDedicatedMemory() {
Image image{device(), ImageCreateInfo2D{ImageUsage::Sampled, Image image{device(), ImageCreateInfo2D{ImageUsage::Sampled,
VK_FORMAT_R8G8B8A8_UNORM, {256, 256}, 8}, NoAllocate}; PixelFormat::RGBA8Unorm, {256, 256}, 8}, NoAllocate};
MemoryRequirements requirements = image.memoryRequirements(); MemoryRequirements requirements = image.memoryRequirements();
/** @todo expand once KHR_dedicated_allocation is implemented */ /** @todo expand once KHR_dedicated_allocation is implemented */
@ -276,7 +282,7 @@ void ImageVkTest::bindDedicatedMemory() {
void ImageVkTest::directAllocation() { void ImageVkTest::directAllocation() {
Image image{device(), ImageCreateInfo2D{ImageUsage::Sampled, Image image{device(), ImageCreateInfo2D{ImageUsage::Sampled,
VK_FORMAT_R8G8B8A8_UNORM, {256, 256}, 8}, MemoryFlag::DeviceLocal}; PixelFormat::RGBA8Unorm, {256, 256}, 8}, MemoryFlag::DeviceLocal};
/* Not sure what else to test here */ /* Not sure what else to test here */
CORRADE_VERIFY(image.hasDedicatedMemory()); CORRADE_VERIFY(image.hasDedicatedMemory());

274
src/Magnum/Vk/Test/PixelFormatTest.cpp

@ -0,0 +1,274 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020 Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <sstream>
#include <Corrade/TestSuite/Tester.h>
#include <Corrade/Utility/DebugStl.h>
#include "Magnum/PixelFormat.h"
#include "Magnum/Vk/PixelFormat.h"
namespace Magnum { namespace Vk { namespace Test { namespace {
struct PixelFormatTest: TestSuite::Tester {
explicit PixelFormatTest();
void mapPixelFormat();
void mapPixelFormatImplementationSpecific();
void mapPixelFormatUnsupported();
void mapPixelFormatInvalid();
void mapCompressedPixelFormat();
void mapCompressedPixelFormatImplementationSpecific();
void mapCompressedPixelFormatUnsupported();
void mapCompressedPixelFormatInvalid();
void debug();
};
PixelFormatTest::PixelFormatTest() {
addTests({&PixelFormatTest::mapPixelFormat,
&PixelFormatTest::mapPixelFormatImplementationSpecific,
&PixelFormatTest::mapPixelFormatUnsupported,
&PixelFormatTest::mapPixelFormatInvalid,
&PixelFormatTest::mapCompressedPixelFormat,
&PixelFormatTest::mapCompressedPixelFormatImplementationSpecific,
&PixelFormatTest::mapCompressedPixelFormatUnsupported,
&PixelFormatTest::mapCompressedPixelFormatInvalid,
&PixelFormatTest::debug});
}
void PixelFormatTest::mapPixelFormat() {
/* Touchstone verification. Using Vulkan enums directly to sidestep
potential problems in enum mapping as well. */
CORRADE_VERIFY(hasPixelFormat(Magnum::PixelFormat::RGBA8Unorm));
CORRADE_COMPARE(pixelFormat(Magnum::PixelFormat::RGBA8Unorm), PixelFormat(VK_FORMAT_R8G8B8A8_UNORM));
/* This goes through the first 16 bits, which should be enough. Going
through 32 bits takes 8 seconds, too much. */
UnsignedInt firstUnhandled = 0xffff;
UnsignedInt nextHandled = 1; /* 0 is an invalid format */
for(UnsignedInt i = 1; i <= 0xffff; ++i) {
const auto format = Magnum::PixelFormat(i);
/* Each case verifies:
- that the entries are ordered by number by comparing a function to
expected result (so insertion here is done in proper place)
- that there was no gap (unhandled value inside the range)
- that a particular pixel format maps to a particular vkFormat */
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(format) {
#define _c(format) \
case Magnum::PixelFormat::format: \
CORRADE_COMPARE(nextHandled, i); \
CORRADE_COMPARE(firstUnhandled, 0xffff); \
CORRADE_VERIFY(hasPixelFormat(Magnum::PixelFormat::format)); \
CORRADE_COMPARE(pixelFormat(Magnum::PixelFormat::format), PixelFormat::format); \
++nextHandled; \
continue;
#define _s(format) \
case Magnum::PixelFormat::format: { \
CORRADE_COMPARE(nextHandled, i); \
CORRADE_COMPARE(firstUnhandled, 0xffff); \
CORRADE_VERIFY(!hasPixelFormat(Magnum::PixelFormat::format)); \
std::ostringstream out; \
{ /* Redirected otherwise graceful assert would abort */ \
Error redirectError{&out}; \
pixelFormat(Magnum::PixelFormat::format); \
} \
Debug{Debug::Flag::NoNewlineAtTheEnd} << out.str(); \
++nextHandled; \
continue; \
}
#include "Magnum/Vk/Implementation/pixelFormatMapping.hpp"
#undef _s
#undef _c
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
/* Not handled by any value, remember -- we might either be at the end
of the enum range (which is okay) or some value might be unhandled
here */
firstUnhandled = i;
}
CORRADE_COMPARE(firstUnhandled, 0xffff);
}
void PixelFormatTest::mapPixelFormatImplementationSpecific() {
CORRADE_VERIFY(hasPixelFormat(Magnum::pixelFormatWrap(VK_FORMAT_A8B8G8R8_SINT_PACK32)));
CORRADE_COMPARE(pixelFormat(Magnum::pixelFormatWrap(VK_FORMAT_A8B8G8R8_SINT_PACK32)),
PixelFormat(VK_FORMAT_A8B8G8R8_SINT_PACK32));
}
void PixelFormatTest::mapPixelFormatUnsupported() {
#ifdef CORRADE_NO_ASSERT
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");
#endif
#if 1
CORRADE_SKIP("All pixel formats are supported.");
#else
std::ostringstream out;
Error redirectError{&out};
pixelFormat(Magnum::PixelFormat::RGB16UI);
CORRADE_COMPARE(out.str(), "Vk::pixelFormat(): unsupported format PixelFormat::RGB16UI\n");
#endif
}
void PixelFormatTest::mapPixelFormatInvalid() {
#ifdef CORRADE_NO_ASSERT
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");
#endif
std::ostringstream out;
Error redirectError{&out};
hasPixelFormat(Magnum::PixelFormat{});
hasPixelFormat(Magnum::PixelFormat(0x123));
pixelFormat(Magnum::PixelFormat{});
pixelFormat(Magnum::PixelFormat(0x123));
CORRADE_COMPARE(out.str(),
"Vk::hasPixelFormat(): invalid format PixelFormat(0x0)\n"
"Vk::hasPixelFormat(): invalid format PixelFormat(0x123)\n"
"Vk::pixelFormat(): invalid format PixelFormat(0x0)\n"
"Vk::pixelFormat(): invalid format PixelFormat(0x123)\n");
}
void PixelFormatTest::mapCompressedPixelFormat() {
/* Touchstone verification. Using Vulkan enums directly to sidestep
potential problems in enum mapping as well. */
CORRADE_VERIFY(hasPixelFormat(Magnum::CompressedPixelFormat::Bc1RGBAUnorm));
CORRADE_COMPARE(pixelFormat(Magnum::CompressedPixelFormat::Bc1RGBAUnorm), PixelFormat(VK_FORMAT_BC1_RGBA_UNORM_BLOCK));
/* This goes through the first 16 bits, which should be enough. Going
through 32 bits takes 8 seconds, too much. */
UnsignedInt firstUnhandled = 0xffff;
UnsignedInt nextHandled = 1; /* 0 is an invalid format */
for(UnsignedInt i = 1; i <= 0xffff; ++i) {
const auto format = Magnum::CompressedPixelFormat(i);
/* Each case verifies:
- that the entries are ordered by number by comparing a function to
expected result (so insertion here is done in proper place)
- that there was no gap (unhandled value inside the range)
- that a particular pixel format maps to a particular VkFormat */
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(format) {
#define _c(format, expectedFormat) \
case Magnum::CompressedPixelFormat::format: \
CORRADE_COMPARE(nextHandled, i); \
CORRADE_COMPARE(firstUnhandled, 0xffff); \
CORRADE_VERIFY(hasPixelFormat(Magnum::CompressedPixelFormat::format)); \
CORRADE_COMPARE(pixelFormat(Magnum::CompressedPixelFormat::format), PixelFormat::Compressed ## expectedFormat); \
++nextHandled; \
continue;
#define _s(format) \
case Magnum::CompressedPixelFormat::format: { \
CORRADE_COMPARE(nextHandled, i); \
CORRADE_COMPARE(firstUnhandled, 0xffff); \
CORRADE_VERIFY(!hasPixelFormat(Magnum::CompressedPixelFormat::format)); \
std::ostringstream out; \
{ /* Redirected otherwise graceful assert would abort */ \
Error redirectError{&out}; \
pixelFormat(Magnum::CompressedPixelFormat::format); \
} \
Debug{Debug::Flag::NoNewlineAtTheEnd} << out.str(); \
++nextHandled; \
continue; \
}
#include "Magnum/Vk/Implementation/compressedPixelFormatMapping.hpp"
#undef _s
#undef _c
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
/* Not handled by any value, remember -- we might either be at the end
of the enum range (which is okay) or some value might be unhandled
here */
firstUnhandled = i;
}
CORRADE_COMPARE(firstUnhandled, 0xffff);
}
void PixelFormatTest::mapCompressedPixelFormatImplementationSpecific() {
CORRADE_VERIFY(hasPixelFormat(Magnum::compressedPixelFormatWrap(VK_FORMAT_ASTC_10x6_UNORM_BLOCK)));
CORRADE_COMPARE(pixelFormat(Magnum::compressedPixelFormatWrap(VK_FORMAT_ASTC_10x6_UNORM_BLOCK)),
PixelFormat(VK_FORMAT_ASTC_10x6_UNORM_BLOCK));
}
void PixelFormatTest::mapCompressedPixelFormatUnsupported() {
#ifdef CORRADE_NO_ASSERT
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");
#endif
CORRADE_VERIFY(!hasPixelFormat(Magnum::CompressedPixelFormat::Astc3x3x3RGBAUnorm));
std::ostringstream out;
Error redirectError{&out};
pixelFormat(Magnum::CompressedPixelFormat::Astc3x3x3RGBAUnorm);
CORRADE_COMPARE(out.str(), "Vk::pixelFormat(): unsupported format CompressedPixelFormat::Astc3x3x3RGBAUnorm\n");
}
void PixelFormatTest::mapCompressedPixelFormatInvalid() {
#ifdef CORRADE_NO_ASSERT
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");
#endif
std::ostringstream out;
Error redirectError{&out};
hasPixelFormat(Magnum::CompressedPixelFormat{});
hasPixelFormat(Magnum::CompressedPixelFormat(0x123));
pixelFormat(Magnum::CompressedPixelFormat{});
pixelFormat(Magnum::CompressedPixelFormat(0x123));
CORRADE_COMPARE(out.str(),
"Vk::hasPixelFormat(): invalid format CompressedPixelFormat(0x0)\n"
"Vk::hasPixelFormat(): invalid format CompressedPixelFormat(0x123)\n"
"Vk::pixelFormat(): invalid format CompressedPixelFormat(0x0)\n"
"Vk::pixelFormat(): invalid format CompressedPixelFormat(0x123)\n");
}
void PixelFormatTest::debug() {
std::ostringstream out;
Debug{&out} << PixelFormat::RGB16UI << PixelFormat(-10007655);
CORRADE_COMPARE(out.str(), "Vk::PixelFormat::RGB16UI Vk::PixelFormat(-10007655)\n");
}
}}}}
CORRADE_TEST_MAIN(Magnum::Vk::Test::PixelFormatTest)

86
src/Magnum/Vk/Test/RenderPassTest.cpp

@ -38,6 +38,8 @@
#include "Magnum/Vk/Integration.h" #include "Magnum/Vk/Integration.h"
#include "Magnum/Vk/RenderPassCreateInfo.h" #include "Magnum/Vk/RenderPassCreateInfo.h"
#include "Magnum/Vk/Test/pixelFormatTraits.h"
namespace Magnum { namespace Vk { namespace Test { namespace { namespace Magnum { namespace Vk { namespace Test { namespace {
struct RenderPassTest: TestSuite::Tester { struct RenderPassTest: TestSuite::Tester {
@ -49,11 +51,11 @@ struct RenderPassTest: TestSuite::Tester {
the contained structure are correctly propagated to the resulting the contained structure are correctly propagated to the resulting
structures. */ structures. */
void attachmentDescriptionConstruct(); template<class T> void attachmentDescriptionConstruct();
void attachmentDescriptionConstructImplicitLayout(); template<class T> void attachmentDescriptionConstructImplicitLayout();
void attachmentDescriptionConstructDepthStencil(); template<class T> void attachmentDescriptionConstructDepthStencil();
void attachmentDescriptionConstructDepthStencilImplicitLayout(); template<class T> void attachmentDescriptionConstructDepthStencilImplicitLayout();
void attachmentDescriptionConstructImplicitLoadStoreLayout(); template<class T> void attachmentDescriptionConstructImplicitLoadStoreLayout();
void attachmentDescriptionConstructNoInit(); void attachmentDescriptionConstructNoInit();
template<class From, class To> void attachmentDescriptionConstructFromVk(); template<class From, class To> void attachmentDescriptionConstructFromVk();
template<class T> void attachmentDescriptionConvertToVk(); template<class T> void attachmentDescriptionConvertToVk();
@ -117,11 +119,21 @@ struct RenderPassTest: TestSuite::Tester {
}; };
RenderPassTest::RenderPassTest() { RenderPassTest::RenderPassTest() {
addTests({&RenderPassTest::attachmentDescriptionConstruct, addTests({&RenderPassTest::attachmentDescriptionConstruct<PixelFormat>,
&RenderPassTest::attachmentDescriptionConstructImplicitLayout, &RenderPassTest::attachmentDescriptionConstruct<Magnum::PixelFormat>,
&RenderPassTest::attachmentDescriptionConstructDepthStencil, &RenderPassTest::attachmentDescriptionConstruct<Magnum::CompressedPixelFormat>,
&RenderPassTest::attachmentDescriptionConstructDepthStencilImplicitLayout, &RenderPassTest::attachmentDescriptionConstructImplicitLayout<PixelFormat>,
&RenderPassTest::attachmentDescriptionConstructImplicitLoadStoreLayout, &RenderPassTest::attachmentDescriptionConstructImplicitLayout<Magnum::PixelFormat>,
&RenderPassTest::attachmentDescriptionConstructImplicitLayout<Magnum::CompressedPixelFormat>,
&RenderPassTest::attachmentDescriptionConstructDepthStencil<PixelFormat>,
&RenderPassTest::attachmentDescriptionConstructDepthStencil<Magnum::PixelFormat>,
&RenderPassTest::attachmentDescriptionConstructDepthStencil<Magnum::CompressedPixelFormat>,
&RenderPassTest::attachmentDescriptionConstructDepthStencilImplicitLayout<PixelFormat>,
&RenderPassTest::attachmentDescriptionConstructDepthStencilImplicitLayout<Magnum::PixelFormat>,
&RenderPassTest::attachmentDescriptionConstructDepthStencilImplicitLayout<Magnum::CompressedPixelFormat>,
&RenderPassTest::attachmentDescriptionConstructImplicitLoadStoreLayout<PixelFormat>,
&RenderPassTest::attachmentDescriptionConstructImplicitLoadStoreLayout<Magnum::PixelFormat>,
&RenderPassTest::attachmentDescriptionConstructImplicitLoadStoreLayout<Magnum::CompressedPixelFormat>,
&RenderPassTest::attachmentDescriptionConstructNoInit, &RenderPassTest::attachmentDescriptionConstructNoInit,
&RenderPassTest::attachmentDescriptionConstructFromVk<VkAttachmentDescription2, VkAttachmentDescription2>, &RenderPassTest::attachmentDescriptionConstructFromVk<VkAttachmentDescription2, VkAttachmentDescription2>,
&RenderPassTest::attachmentDescriptionConstructFromVk<VkAttachmentDescription, VkAttachmentDescription2>, &RenderPassTest::attachmentDescriptionConstructFromVk<VkAttachmentDescription, VkAttachmentDescription2>,
@ -242,13 +254,15 @@ _ca(RenderPassCreateInfo)
#undef _c #undef _c
#undef _ca #undef _ca
void RenderPassTest::attachmentDescriptionConstruct() { template<class T> void RenderPassTest::attachmentDescriptionConstruct() {
AttachmentDescription description{VK_FORMAT_R8G8B8A8_SNORM, setTestCaseTemplateName(PixelFormatTraits<T>::name());
AttachmentDescription description{PixelFormatTraits<T>::format(),
AttachmentLoadOperation::Clear, AttachmentStoreOperation::DontCare, AttachmentLoadOperation::Clear, AttachmentStoreOperation::DontCare,
ImageLayout::ColorAttachment, ImageLayout::TransferDestination, ImageLayout::ColorAttachment, ImageLayout::TransferDestination,
4, AttachmentDescription::Flag::MayAlias}; 4, AttachmentDescription::Flag::MayAlias};
CORRADE_COMPARE(description->flags, VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT); CORRADE_COMPARE(description->flags, VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT);
CORRADE_COMPARE(description->format, VK_FORMAT_R8G8B8A8_SNORM); CORRADE_COMPARE(description->format, PixelFormatTraits<T>::expected());
CORRADE_COMPARE(description->samples, VK_SAMPLE_COUNT_4_BIT); CORRADE_COMPARE(description->samples, VK_SAMPLE_COUNT_4_BIT);
CORRADE_COMPARE(description->loadOp, VK_ATTACHMENT_LOAD_OP_CLEAR); CORRADE_COMPARE(description->loadOp, VK_ATTACHMENT_LOAD_OP_CLEAR);
CORRADE_COMPARE(description->stencilLoadOp, VK_ATTACHMENT_LOAD_OP_LOAD); CORRADE_COMPARE(description->stencilLoadOp, VK_ATTACHMENT_LOAD_OP_LOAD);
@ -258,12 +272,14 @@ void RenderPassTest::attachmentDescriptionConstruct() {
CORRADE_COMPARE(description->finalLayout, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); CORRADE_COMPARE(description->finalLayout, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
} }
void RenderPassTest::attachmentDescriptionConstructImplicitLayout() { template<class T> void RenderPassTest::attachmentDescriptionConstructImplicitLayout() {
AttachmentDescription description{VK_FORMAT_R8G8B8A8_SNORM, setTestCaseTemplateName(PixelFormatTraits<T>::name());
AttachmentDescription description{PixelFormatTraits<T>::format(),
AttachmentLoadOperation::Clear, AttachmentStoreOperation::DontCare, AttachmentLoadOperation::Clear, AttachmentStoreOperation::DontCare,
4, AttachmentDescription::Flag::MayAlias}; 4, AttachmentDescription::Flag::MayAlias};
CORRADE_COMPARE(description->flags, VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT); CORRADE_COMPARE(description->flags, VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT);
CORRADE_COMPARE(description->format, VK_FORMAT_R8G8B8A8_SNORM); CORRADE_COMPARE(description->format, PixelFormatTraits<T>::expected());
CORRADE_COMPARE(description->samples, VK_SAMPLE_COUNT_4_BIT); CORRADE_COMPARE(description->samples, VK_SAMPLE_COUNT_4_BIT);
CORRADE_COMPARE(description->loadOp, VK_ATTACHMENT_LOAD_OP_CLEAR); CORRADE_COMPARE(description->loadOp, VK_ATTACHMENT_LOAD_OP_CLEAR);
CORRADE_COMPARE(description->stencilLoadOp, VK_ATTACHMENT_LOAD_OP_LOAD); CORRADE_COMPARE(description->stencilLoadOp, VK_ATTACHMENT_LOAD_OP_LOAD);
@ -273,14 +289,16 @@ void RenderPassTest::attachmentDescriptionConstructImplicitLayout() {
CORRADE_COMPARE(description->finalLayout, VK_IMAGE_LAYOUT_GENERAL); CORRADE_COMPARE(description->finalLayout, VK_IMAGE_LAYOUT_GENERAL);
} }
void RenderPassTest::attachmentDescriptionConstructDepthStencil() { template<class T> void RenderPassTest::attachmentDescriptionConstructDepthStencil() {
AttachmentDescription description{VK_FORMAT_R8G8B8A8_SNORM, setTestCaseTemplateName(PixelFormatTraits<T>::name());
AttachmentDescription description{PixelFormatTraits<T>::format(),
{AttachmentLoadOperation::Clear, AttachmentLoadOperation::DontCare}, {AttachmentLoadOperation::Clear, AttachmentLoadOperation::DontCare},
{AttachmentStoreOperation::Store, AttachmentStoreOperation::DontCare}, {AttachmentStoreOperation::Store, AttachmentStoreOperation::DontCare},
ImageLayout::DepthStencilAttachment, ImageLayout::ShaderReadOnly, ImageLayout::DepthStencilAttachment, ImageLayout::ShaderReadOnly,
4, AttachmentDescription::Flag::MayAlias}; 4, AttachmentDescription::Flag::MayAlias};
CORRADE_COMPARE(description->flags, VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT); CORRADE_COMPARE(description->flags, VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT);
CORRADE_COMPARE(description->format, VK_FORMAT_R8G8B8A8_SNORM); CORRADE_COMPARE(description->format, PixelFormatTraits<T>::expected());
CORRADE_COMPARE(description->samples, VK_SAMPLE_COUNT_4_BIT); CORRADE_COMPARE(description->samples, VK_SAMPLE_COUNT_4_BIT);
CORRADE_COMPARE(description->loadOp, VK_ATTACHMENT_LOAD_OP_CLEAR); CORRADE_COMPARE(description->loadOp, VK_ATTACHMENT_LOAD_OP_CLEAR);
CORRADE_COMPARE(description->stencilLoadOp, VK_ATTACHMENT_LOAD_OP_DONT_CARE); CORRADE_COMPARE(description->stencilLoadOp, VK_ATTACHMENT_LOAD_OP_DONT_CARE);
@ -290,13 +308,15 @@ void RenderPassTest::attachmentDescriptionConstructDepthStencil() {
CORRADE_COMPARE(description->finalLayout, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); CORRADE_COMPARE(description->finalLayout, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
} }
void RenderPassTest::attachmentDescriptionConstructDepthStencilImplicitLayout() { template<class T> void RenderPassTest::attachmentDescriptionConstructDepthStencilImplicitLayout() {
AttachmentDescription description{VK_FORMAT_R8G8B8A8_SNORM, setTestCaseTemplateName(PixelFormatTraits<T>::name());
AttachmentDescription description{PixelFormatTraits<T>::format(),
{AttachmentLoadOperation::Clear, AttachmentLoadOperation::DontCare}, {AttachmentLoadOperation::Clear, AttachmentLoadOperation::DontCare},
{AttachmentStoreOperation::Store, AttachmentStoreOperation::DontCare}, {AttachmentStoreOperation::Store, AttachmentStoreOperation::DontCare},
4, AttachmentDescription::Flag::MayAlias}; 4, AttachmentDescription::Flag::MayAlias};
CORRADE_COMPARE(description->flags, VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT); CORRADE_COMPARE(description->flags, VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT);
CORRADE_COMPARE(description->format, VK_FORMAT_R8G8B8A8_SNORM); CORRADE_COMPARE(description->format, PixelFormatTraits<T>::expected());
CORRADE_COMPARE(description->samples, VK_SAMPLE_COUNT_4_BIT); CORRADE_COMPARE(description->samples, VK_SAMPLE_COUNT_4_BIT);
CORRADE_COMPARE(description->loadOp, VK_ATTACHMENT_LOAD_OP_CLEAR); CORRADE_COMPARE(description->loadOp, VK_ATTACHMENT_LOAD_OP_CLEAR);
CORRADE_COMPARE(description->stencilLoadOp, VK_ATTACHMENT_LOAD_OP_DONT_CARE); CORRADE_COMPARE(description->stencilLoadOp, VK_ATTACHMENT_LOAD_OP_DONT_CARE);
@ -306,11 +326,13 @@ void RenderPassTest::attachmentDescriptionConstructDepthStencilImplicitLayout()
CORRADE_COMPARE(description->finalLayout, VK_IMAGE_LAYOUT_GENERAL); CORRADE_COMPARE(description->finalLayout, VK_IMAGE_LAYOUT_GENERAL);
} }
void RenderPassTest::attachmentDescriptionConstructImplicitLoadStoreLayout() { template<class T> void RenderPassTest::attachmentDescriptionConstructImplicitLoadStoreLayout() {
AttachmentDescription description{VK_FORMAT_R8G8B8A8_SNORM, setTestCaseTemplateName(PixelFormatTraits<T>::name());
AttachmentDescription description{PixelFormatTraits<T>::format(),
4, AttachmentDescription::Flag::MayAlias}; 4, AttachmentDescription::Flag::MayAlias};
CORRADE_COMPARE(description->flags, VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT); CORRADE_COMPARE(description->flags, VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT);
CORRADE_COMPARE(description->format, VK_FORMAT_R8G8B8A8_SNORM); CORRADE_COMPARE(description->format, PixelFormatTraits<T>::expected());
CORRADE_COMPARE(description->samples, VK_SAMPLE_COUNT_4_BIT); CORRADE_COMPARE(description->samples, VK_SAMPLE_COUNT_4_BIT);
CORRADE_COMPARE(description->loadOp, VK_ATTACHMENT_LOAD_OP_LOAD); CORRADE_COMPARE(description->loadOp, VK_ATTACHMENT_LOAD_OP_LOAD);
CORRADE_COMPARE(description->stencilLoadOp, VK_ATTACHMENT_LOAD_OP_LOAD); CORRADE_COMPARE(description->stencilLoadOp, VK_ATTACHMENT_LOAD_OP_LOAD);
@ -362,7 +384,7 @@ template<class From, class To> void RenderPassTest::attachmentDescriptionConstru
template<class T> void RenderPassTest::attachmentDescriptionConvertToVk() { template<class T> void RenderPassTest::attachmentDescriptionConvertToVk() {
setTestCaseTemplateName(Traits<T>::name()); setTestCaseTemplateName(Traits<T>::name());
AttachmentDescription description{VK_FORMAT_R8G8B8A8_SNORM, AttachmentDescription description{PixelFormat::RGBA8Snorm,
{AttachmentLoadOperation::Clear, AttachmentLoadOperation::DontCare}, {AttachmentStoreOperation::Store, AttachmentStoreOperation::DontCare}, {AttachmentLoadOperation::Clear, AttachmentLoadOperation::DontCare}, {AttachmentStoreOperation::Store, AttachmentStoreOperation::DontCare},
ImageLayout::ShaderReadOnly, ImageLayout::TransferDestination, ImageLayout::ShaderReadOnly, ImageLayout::TransferDestination,
32, AttachmentDescription::Flag::MayAlias}; 32, AttachmentDescription::Flag::MayAlias};
@ -796,8 +818,8 @@ void RenderPassTest::createInfoConstructNoInit() {
void RenderPassTest::createInfoConstructAttachments() { void RenderPassTest::createInfoConstructAttachments() {
RenderPassCreateInfo info; RenderPassCreateInfo info;
info.setAttachments({ info.setAttachments({
{VK_FORMAT_R16G16B16A16_SFLOAT, AttachmentLoadOperation::Clear, AttachmentStoreOperation::DontCare}, {PixelFormat::RGBA16F, AttachmentLoadOperation::Clear, AttachmentStoreOperation::DontCare},
{VK_FORMAT_R8G8B8_SNORM, 4} {PixelFormat::RGB8Snorm, 4}
}); });
CORRADE_COMPARE(info->attachmentCount, 2); CORRADE_COMPARE(info->attachmentCount, 2);
CORRADE_VERIFY(info->pAttachments); CORRADE_VERIFY(info->pAttachments);
@ -931,7 +953,7 @@ void RenderPassTest::createInfoConstructCopy() {
void RenderPassTest::createInfoConstructMove() { void RenderPassTest::createInfoConstructMove() {
RenderPassCreateInfo a; RenderPassCreateInfo a;
a.setAttachments({VK_FORMAT_D32_SFLOAT, VK_FORMAT_R8G8B8_SNORM}); a.setAttachments({PixelFormat::Depth32F, PixelFormat::RGB8Snorm});
CORRADE_COMPARE(a->attachmentCount, 2); CORRADE_COMPARE(a->attachmentCount, 2);
CORRADE_COMPARE(a->pAttachments[1].format, VK_FORMAT_R8G8B8_SNORM); CORRADE_COMPARE(a->pAttachments[1].format, VK_FORMAT_R8G8B8_SNORM);
@ -958,8 +980,8 @@ template<class T> void RenderPassTest::createInfoConvertToVk() {
RenderPassCreateInfo info; RenderPassCreateInfo info;
info.setAttachments({ info.setAttachments({
AttachmentDescription{VK_FORMAT_A1R5G5B5_UNORM_PACK16}, AttachmentDescription{PixelFormat::RGB16UI},
AttachmentDescription{{}, {}, {AttachmentStoreOperation::Store, AttachmentStoreOperation::DontCare}} AttachmentDescription{PixelFormat{}, {}, {AttachmentStoreOperation::Store, AttachmentStoreOperation::DontCare}}
}) })
.addSubpass(SubpassDescription{}.setColorAttachments({1, {15, ImageLayout::ShaderReadOnly}})) .addSubpass(SubpassDescription{}.setColorAttachments({1, {15, ImageLayout::ShaderReadOnly}}))
.addSubpass(SubpassDescription{}.setDepthStencilAttachment({15, ImageLayout::ShaderReadOnly})) .addSubpass(SubpassDescription{}.setDepthStencilAttachment({15, ImageLayout::ShaderReadOnly}))
@ -970,7 +992,7 @@ template<class T> void RenderPassTest::createInfoConvertToVk() {
CORRADE_COMPARE(to.attachmentCount, 2); CORRADE_COMPARE(to.attachmentCount, 2);
CORRADE_VERIFY(to.pAttachments); CORRADE_VERIFY(to.pAttachments);
CORRADE_COMPARE(to.pAttachments[0].format, VK_FORMAT_A1R5G5B5_UNORM_PACK16); CORRADE_COMPARE(to.pAttachments[0].format, VK_FORMAT_R16G16B16_UINT);
CORRADE_COMPARE(to.pAttachments[1].stencilStoreOp, VK_ATTACHMENT_STORE_OP_DONT_CARE); CORRADE_COMPARE(to.pAttachments[1].stencilStoreOp, VK_ATTACHMENT_STORE_OP_DONT_CARE);
CORRADE_COMPARE(to.subpassCount, 3); CORRADE_COMPARE(to.subpassCount, 3);

11
src/Magnum/Vk/Test/RenderPassVkTest.cpp

@ -36,6 +36,7 @@
#include "Magnum/Vk/Handle.h" #include "Magnum/Vk/Handle.h"
#include "Magnum/Vk/ImageCreateInfo.h" #include "Magnum/Vk/ImageCreateInfo.h"
#include "Magnum/Vk/ImageViewCreateInfo.h" #include "Magnum/Vk/ImageViewCreateInfo.h"
#include "Magnum/Vk/PixelFormat.h"
#include "Magnum/Vk/RenderPassCreateInfo.h" #include "Magnum/Vk/RenderPassCreateInfo.h"
#include "Magnum/Vk/Result.h" #include "Magnum/Vk/Result.h"
#include "Magnum/Vk/VulkanTester.h" #include "Magnum/Vk/VulkanTester.h"
@ -69,7 +70,7 @@ RenderPassVkTest::RenderPassVkTest() {
void RenderPassVkTest::construct() { void RenderPassVkTest::construct() {
{ {
RenderPass renderPass{device(), RenderPassCreateInfo{} RenderPass renderPass{device(), RenderPassCreateInfo{}
.setAttachments({VK_FORMAT_R8G8B8A8_SNORM}) .setAttachments({PixelFormat::RGBA8Unorm})
.addSubpass(SubpassDescription{}.setColorAttachments({0})) .addSubpass(SubpassDescription{}.setColorAttachments({0}))
}; };
CORRADE_VERIFY(renderPass.handle()); CORRADE_VERIFY(renderPass.handle());
@ -102,7 +103,7 @@ void RenderPassVkTest::constructSubpassNoAttachments() {
void RenderPassVkTest::constructMove() { void RenderPassVkTest::constructMove() {
RenderPass a{device(), RenderPassCreateInfo{} RenderPass a{device(), RenderPassCreateInfo{}
.setAttachments({VK_FORMAT_R8G8B8A8_SNORM}) .setAttachments({PixelFormat::RGBA8Unorm})
.addSubpass(SubpassDescription{}.setColorAttachments({0})) .addSubpass(SubpassDescription{}.setColorAttachments({0}))
}; };
VkRenderPass handle = a.handle(); VkRenderPass handle = a.handle();
@ -127,7 +128,7 @@ void RenderPassVkTest::wrap() {
VkRenderPass renderPass{}; VkRenderPass renderPass{};
CORRADE_COMPARE(Result(device()->CreateRenderPass(device(), CORRADE_COMPARE(Result(device()->CreateRenderPass(device(),
RenderPassCreateInfo{} RenderPassCreateInfo{}
.setAttachments({VK_FORMAT_R8G8B8A8_SNORM}) .setAttachments({PixelFormat::RGBA8Unorm})
.addSubpass(SubpassDescription{}.setColorAttachments({0})) .addSubpass(SubpassDescription{}.setColorAttachments({0}))
.vkRenderPassCreateInfo(), .vkRenderPassCreateInfo(),
nullptr, &renderPass)), Result::Success); nullptr, &renderPass)), Result::Success);
@ -151,9 +152,9 @@ void RenderPassVkTest::cmdBeginEnd() {
/* Using a depth attachment as well even though not strictly necessary to /* Using a depth attachment as well even though not strictly necessary to
catch potential unexpected bugs */ catch potential unexpected bugs */
Image color{device(), ImageCreateInfo2D{ImageUsage::ColorAttachment, Image color{device(), ImageCreateInfo2D{ImageUsage::ColorAttachment,
VK_FORMAT_R8G8B8A8_UNORM, {256, 256}, 1}, MemoryFlag::DeviceLocal}; PixelFormat::RGBA8Unorm, {256, 256}, 1}, MemoryFlag::DeviceLocal};
Image depth{device(), ImageCreateInfo2D{ImageUsage::DepthStencilAttachment, Image depth{device(), ImageCreateInfo2D{ImageUsage::DepthStencilAttachment,
VK_FORMAT_D24_UNORM_S8_UINT, {256, 256}, 1}, MemoryFlag::DeviceLocal}; PixelFormat::Depth24UnormStencil8UI, {256, 256}, 1}, MemoryFlag::DeviceLocal};
ImageView colorView{device(), ImageViewCreateInfo2D{color}}; ImageView colorView{device(), ImageViewCreateInfo2D{color}};
ImageView depthView{device(), ImageViewCreateInfo2D{depth}}; ImageView depthView{device(), ImageViewCreateInfo2D{depth}};

52
src/Magnum/Vk/Test/pixelFormatTraits.h

@ -0,0 +1,52 @@
#ifndef Magnum_Vk_Test_pixelFormatTraits_h
#define Magnum_Vk_Test_pixelFormatTraits_h
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020 Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include "Magnum/PixelFormat.h"
#include "Magnum/Vk/PixelFormat.h"
namespace Magnum { namespace Vk { namespace Test { namespace {
template<class> struct PixelFormatTraits;
template<> struct PixelFormatTraits<PixelFormat> {
static const char* name() { return "PixelFormat"; }
static PixelFormat format() { return PixelFormat::RGBA8Srgb; }
static VkFormat expected() { return VK_FORMAT_R8G8B8A8_SRGB; }
};
template<> struct PixelFormatTraits<Magnum::PixelFormat> {
static const char* name() { return "Magnum::PixelFormat"; }
static Magnum::PixelFormat format() { return Magnum::PixelFormat::RGBA8Srgb; }
static VkFormat expected() { return VK_FORMAT_R8G8B8A8_SRGB; }
};
template<> struct PixelFormatTraits<Magnum::CompressedPixelFormat> {
static const char* name() { return "Magnum::CompressedPixelFormat"; }
static Magnum::CompressedPixelFormat format() { return Magnum::CompressedPixelFormat::Bc3RGBASrgb; }
static VkFormat expected() { return VK_FORMAT_BC3_SRGB_BLOCK; }
};
}}}}
#endif

1
src/Magnum/Vk/Vk.h

@ -76,6 +76,7 @@ enum class MemoryFlag: UnsignedInt;
typedef Containers::EnumSet<MemoryFlag> MemoryFlags; typedef Containers::EnumSet<MemoryFlag> MemoryFlags;
enum class MemoryHeapFlag: UnsignedInt; enum class MemoryHeapFlag: UnsignedInt;
typedef Containers::EnumSet<MemoryHeapFlag> MemoryHeapFlags; typedef Containers::EnumSet<MemoryHeapFlag> MemoryHeapFlags;
enum class PixelFormat: Int;
class Queue; class Queue;
enum class QueueFlag: UnsignedInt; enum class QueueFlag: UnsignedInt;
typedef Containers::EnumSet<QueueFlag> QueueFlags; typedef Containers::EnumSet<QueueFlag> QueueFlags;

Loading…
Cancel
Save