diff --git a/src/Magnum/Vk/Memory.cpp b/src/Magnum/Vk/Memory.cpp index 4356a283d..d4126789f 100644 --- a/src/Magnum/Vk/Memory.cpp +++ b/src/Magnum/Vk/Memory.cpp @@ -105,6 +105,7 @@ Containers::Array Memory::map(const UnsignedLong offset, } Containers::Array Memory::map() { + CORRADE_ASSERT(_size, "Vk::Memory::map(): the memory has unknown size, you have to specify it explicitly", {}); return map(0, _size); } @@ -119,6 +120,7 @@ Containers::Array Memory::mapRead(const UnsignedLo } Containers::Array Memory::mapRead() { + CORRADE_ASSERT(_size, "Vk::Memory::mapRead(): the memory has unknown size, you have to specify it explicitly", {}); return mapRead(0, _size); } diff --git a/src/Magnum/Vk/Memory.h b/src/Magnum/Vk/Memory.h index 334a19bcc..483cc2da5 100644 --- a/src/Magnum/Vk/Memory.h +++ b/src/Magnum/Vk/Memory.h @@ -329,9 +329,14 @@ class MAGNUM_VK_EXPORT Memory { * @param size Memory size * @param flags Handle flags * - * The @p handle is expected to be originating from @p device. Unlike - * a memory allocated using a constructor, the Vulkan memory is by - * default not freed on destruction, use @p flags for different + * The @p handle is expected to be originating from @p device. The + * @p size parameter will be used to properly size the output array + * coming from @ref map(). If a concrete @p size is unknown, use a + * zero --- you will then be able to only use the @ref map(UnsignedLong, UnsignedLong) + * overload. + * + * Unlike a memory allocated using a constructor, the Vulkan memory is + * by default not freed on destruction, use @p flags for different * behavior. * @see @ref release() */ diff --git a/src/Magnum/Vk/Test/MemoryTest.cpp b/src/Magnum/Vk/Test/MemoryTest.cpp index 04a93f62f..c85c42841 100644 --- a/src/Magnum/Vk/Test/MemoryTest.cpp +++ b/src/Magnum/Vk/Test/MemoryTest.cpp @@ -24,9 +24,11 @@ */ #include +#include #include #include +#include "Magnum/Vk/Device.h" #include "Magnum/Vk/Memory.h" namespace Magnum { namespace Vk { namespace Test { namespace { @@ -47,6 +49,8 @@ struct MemoryTest: TestSuite::Tester { void constructNoCreate(); void constructCopy(); + void mapWrappedUnknownSize(); + void debugMemoryFlag(); void debugMemoryFlags(); }; @@ -65,6 +69,8 @@ MemoryTest::MemoryTest() { &MemoryTest::constructNoCreate, &MemoryTest::constructCopy, + &MemoryTest::mapWrappedUnknownSize, + &MemoryTest::debugMemoryFlag, &MemoryTest::debugMemoryFlags}); } @@ -160,6 +166,23 @@ void MemoryTest::constructCopy() { CORRADE_VERIFY(!std::is_copy_assignable{}); } +void MemoryTest::mapWrappedUnknownSize() { + #ifdef CORRADE_NO_ASSERT + CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); + #endif + + Device device{NoCreate}; + Memory memory = Memory::wrap(device, {}, 0); + + std::ostringstream out; + Error redirectError{&out}; + memory.map(); + memory.mapRead(); + CORRADE_COMPARE(out.str(), + "Vk::Memory::map(): the memory has unknown size, you have to specify it explicitly\n" + "Vk::Memory::mapRead(): the memory has unknown size, you have to specify it explicitly\n"); +} + void MemoryTest::debugMemoryFlag() { std::ostringstream out; Debug{&out} << MemoryFlag::HostCached << MemoryFlag(0xdeadcafe);