From ac62a6c7085070774a430742373b562af231522e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Feb 2021 21:44:22 +0100 Subject: [PATCH] Vk: debug output for DynamicRasterizationState[s]. Will save them to a Pipeline and when there's a getter for something, it's good to have a printer for it as well. Or at least for the tests. --- src/Magnum/Vk/Pipeline.cpp | 25 +++++++++++++++++++ .../Vk/RasterizationPipelineCreateInfo.h | 12 +++++++++ src/Magnum/Vk/Test/PipelineTest.cpp | 18 ++++++++++++- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/Magnum/Vk/Pipeline.cpp b/src/Magnum/Vk/Pipeline.cpp index 05f2d80ba..ceef6f531 100644 --- a/src/Magnum/Vk/Pipeline.cpp +++ b/src/Magnum/Vk/Pipeline.cpp @@ -29,6 +29,7 @@ #include "CommandBuffer.h" #include +#include #include "Magnum/Vk/Assert.h" #include "Magnum/Vk/Device.h" @@ -451,4 +452,28 @@ Debug& operator<<(Debug& debug, const PipelineBindPoint value) { return debug << "(" << Debug::nospace << Int(value) << Debug::nospace << ")"; } +namespace { + +constexpr const char* DynamicRasterizationStateNames[]{ + #define _c(value, vkValue) #value, + #include "Magnum/Vk/Implementation/dynamicRasterizationStateMapping.hpp" + #undef _c +}; + +} + +Debug& operator<<(Debug& debug, const DynamicRasterizationState value) { + debug << "Vk::DynamicRasterizationState" << Debug::nospace; + + if(UnsignedInt(value) < Containers::arraySize(DynamicRasterizationStateNames)) { + return debug << "::" << Debug::nospace << DynamicRasterizationStateNames[UnsignedInt(value)]; + } + + return debug << "(" << Debug::nospace << reinterpret_cast(UnsignedByte(value)) << Debug::nospace << ")"; +} + +Debug& operator<<(Debug& debug, const DynamicRasterizationStates& value) { + return Containers::bigEnumSetDebugOutput(debug, value, "Vk::DynamicRasterizationStates{}"); +} + }} diff --git a/src/Magnum/Vk/RasterizationPipelineCreateInfo.h b/src/Magnum/Vk/RasterizationPipelineCreateInfo.h index b647f5255..e579212bc 100644 --- a/src/Magnum/Vk/RasterizationPipelineCreateInfo.h +++ b/src/Magnum/Vk/RasterizationPipelineCreateInfo.h @@ -273,6 +273,18 @@ typedef Containers::BigEnumSet DynamicRasterizatio CORRADE_ENUMSET_OPERATORS(DynamicRasterizationStates) +/** +@debugoperatorenum{DynamicRasterizationState} +@m_since_latest +*/ +MAGNUM_VK_EXPORT Debug& operator<<(Debug& debug, DynamicRasterizationState value); + +/** +@debugoperatorenum{DynamicRasterizationState} +@m_since_latest +*/ +MAGNUM_VK_EXPORT Debug& operator<<(Debug& debug, const DynamicRasterizationStates& value); + /** @brief Rasterization pipeline creation info @m_since_latest diff --git a/src/Magnum/Vk/Test/PipelineTest.cpp b/src/Magnum/Vk/Test/PipelineTest.cpp index a5df9d156..23785bcac 100644 --- a/src/Magnum/Vk/Test/PipelineTest.cpp +++ b/src/Magnum/Vk/Test/PipelineTest.cpp @@ -84,6 +84,8 @@ struct PipelineTest: TestSuite::Tester { void imageMemoryBarrierConstructFromVk(); void debugBindPoint(); + void debugDynamicRasterizationState(); + void debugDynamicRasterizationStates(); }; PipelineTest::PipelineTest() { @@ -124,7 +126,9 @@ PipelineTest::PipelineTest() { &PipelineTest::imageMemoryBarrierConstructNoInit, &PipelineTest::imageMemoryBarrierConstructFromVk, - &PipelineTest::debugBindPoint}); + &PipelineTest::debugBindPoint, + &PipelineTest::debugDynamicRasterizationState, + &PipelineTest::debugDynamicRasterizationStates}); } using namespace Containers::Literals; @@ -721,6 +725,18 @@ void PipelineTest::debugBindPoint() { CORRADE_COMPARE(out.str(), "Vk::PipelineBindPoint::Compute Vk::PipelineBindPoint(-10007655)\n"); } +void PipelineTest::debugDynamicRasterizationState() { + std::ostringstream out; + Debug{&out} << DynamicRasterizationState::VertexInputBindingStride << DynamicRasterizationState(0xab); + CORRADE_COMPARE(out.str(), "Vk::DynamicRasterizationState::VertexInputBindingStride Vk::DynamicRasterizationState(0xab)\n"); +} + +void PipelineTest::debugDynamicRasterizationStates() { + std::ostringstream out; + Debug{&out} << (DynamicRasterizationState::Viewport|DynamicRasterizationState::Scissor|DynamicRasterizationState(0x2a)|DynamicRasterizationState(0x3f)) << DynamicRasterizationStates{}; + CORRADE_COMPARE(out.str(), "Vk::DynamicRasterizationState::Viewport|Vk::DynamicRasterizationState::Scissor|Vk::DynamicRasterizationState(0x2a)|Vk::DynamicRasterizationState(0x3f) Vk::DynamicRasterizationStates{}\n"); +} + }}}} CORRADE_TEST_MAIN(Magnum::Vk::Test::PipelineTest)