2016-02-26 13:39:01 +11:00
|
|
|
/*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
* 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 ());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
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 ());
|
|
|
|
|
|
|
|
*this = {nullptr, nullptr};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
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;
|
|
|
|
}
|