Browse Source

Vk: clarify what's the extra Memory::wrap() parameter for, add assert.

Similar thing will be done for all upcoming wrap() calls as well.
pull/491/head
Vladimír Vondruš 5 years ago
parent
commit
299a17f95b
  1. 2
      src/Magnum/Vk/Memory.cpp
  2. 11
      src/Magnum/Vk/Memory.h
  3. 23
      src/Magnum/Vk/Test/MemoryTest.cpp

2
src/Magnum/Vk/Memory.cpp

@ -105,6 +105,7 @@ Containers::Array<char, MemoryMapDeleter> Memory::map(const UnsignedLong offset,
}
Containers::Array<char, MemoryMapDeleter> 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<const char, MemoryMapDeleter> Memory::mapRead(const UnsignedLo
}
Containers::Array<const char, MemoryMapDeleter> Memory::mapRead() {
CORRADE_ASSERT(_size, "Vk::Memory::mapRead(): the memory has unknown size, you have to specify it explicitly", {});
return mapRead(0, _size);
}

11
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()
*/

23
src/Magnum/Vk/Test/MemoryTest.cpp

@ -24,9 +24,11 @@
*/
#include <sstream>
#include <Corrade/Containers/Array.h>
#include <Corrade/TestSuite/Tester.h>
#include <Corrade/Utility/DebugStl.h>
#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<Memory>{});
}
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);

Loading…
Cancel
Save