2016-02-26 13:39:01 +11:00
|
|
|
/*
|
2018-08-04 15:24:36 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2016-02-26 13:39:01 +11:00
|
|
|
*
|
|
|
|
* Copyright:
|
2017-09-13 23:26:15 +10:00
|
|
|
* 2016-2017 Danny Robson <danny@nerdcruft.net>
|
2016-02-26 13:39:01 +11:00
|
|
|
*/
|
|
|
|
|
2016-02-24 11:11:41 +11:00
|
|
|
#include "./device_memory.hpp"
|
|
|
|
|
|
|
|
#include "./device.hpp"
|
|
|
|
|
2017-05-26 16:30:48 +10:00
|
|
|
using cruft::vk::device_memory;
|
2016-02-24 11:11:41 +11:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2017-09-14 01:39:38 +10:00
|
|
|
cruft::vk::map_t::~map_t ()
|
2016-02-24 11:11:41 +11:00
|
|
|
{
|
2017-09-14 01:39:38 +10:00
|
|
|
CHECK_ZERO (cbegin ());
|
|
|
|
CHECK_ZERO (cend ());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-16 15:12:54 +11:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
cruft::vk::map_t&
|
|
|
|
cruft::vk::map_t::operator= (std::nullptr_t ptr)
|
|
|
|
{
|
2018-08-05 14:51:18 +10:00
|
|
|
cruft::view<std::byte*>::operator= (ptr);
|
2018-01-16 15:12:54 +11:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-14 01:39:38 +10:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cruft::vk::map_t::destroy (device &_device, device_memory &_memory)
|
|
|
|
{
|
|
|
|
CHECK_NEZ (cbegin ());
|
|
|
|
CHECK_NEZ (cend ());
|
2016-02-24 11:11:41 +11:00
|
|
|
|
2017-09-14 01:39:38 +10:00
|
|
|
vkUnmapMemory (_device.native (), _memory.native ());
|
|
|
|
|
2018-01-10 17:30:04 +11:00
|
|
|
*this = nullptr;
|
2017-09-14 01:39:38 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
cruft::vk::map_t
|
|
|
|
cruft::vk::map (device &_device, device_memory &_memory, int len)
|
|
|
|
{
|
|
|
|
void *ptr = nullptr;
|
|
|
|
auto err = vkMapMemory (_device.native (), _memory.native (), 0, len, 0, &ptr);
|
2016-02-24 11:11:41 +11:00
|
|
|
error::try_code (err);
|
|
|
|
|
2017-09-14 01:39:38 +10:00
|
|
|
return {
|
|
|
|
reinterpret_cast<std::byte*> (ptr),
|
|
|
|
reinterpret_cast<std::byte*> (ptr) + len
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
cruft::vk::owned_map_t::owned_map_t (owned_ptr<device_memory> &_memory,
|
|
|
|
std::byte *first,
|
|
|
|
std::byte *last):
|
|
|
|
map_t (first, last),
|
|
|
|
m_memory (_memory)
|
|
|
|
{ ; }
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
cruft::vk::owned_map_t::~owned_map_t ()
|
|
|
|
{
|
|
|
|
destroy ();
|
2016-02-24 11:11:41 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void
|
2017-09-14 01:39:38 +10:00
|
|
|
cruft::vk::owned_map_t::destroy ()
|
2016-02-24 11:11:41 +11:00
|
|
|
{
|
2017-09-14 01:39:38 +10:00
|
|
|
if (cbegin ())
|
|
|
|
map_t::destroy (m_memory.owner (), *m_memory);
|
2016-02-24 11:11:41 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-14 01:39:38 +10:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
cruft::vk::owned_map_t
|
|
|
|
cruft::vk::map (owned_ptr<device_memory> &_memory, int len)
|
|
|
|
{
|
|
|
|
void *ptr = nullptr;
|
|
|
|
auto err = vkMapMemory (_memory.owner ().native (), _memory->native (), 0, len, 0, &ptr);
|
|
|
|
error::try_code (err);
|
|
|
|
|
|
|
|
return owned_map_t {
|
|
|
|
_memory,
|
|
|
|
reinterpret_cast<std::byte*> (ptr),
|
|
|
|
reinterpret_cast<std::byte*> (ptr) + len
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-24 11:11:41 +11:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
VkDeviceSize
|
|
|
|
device_memory::commitment (const device &dev) const
|
|
|
|
{
|
|
|
|
VkDeviceSize size;
|
2017-09-08 17:11:35 +10:00
|
|
|
vkGetDeviceMemoryCommitment (dev.native (), native (), &size);
|
2016-02-24 11:11:41 +11:00
|
|
|
return size;
|
|
|
|
}
|