123 lines
3.1 KiB
C++
123 lines
3.1 KiB
C++
/*
|
|
* 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:
|
|
* 2016-2017 Danny Robson <danny@nerdcruft.net>
|
|
*/
|
|
|
|
#include "./device_memory.hpp"
|
|
|
|
#include "./device.hpp"
|
|
|
|
using cruft::vk::device_memory;
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
cruft::vk::map_t::~map_t ()
|
|
{
|
|
CHECK_ZERO (cbegin ());
|
|
CHECK_ZERO (cend ());
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
cruft::vk::map_t&
|
|
cruft::vk::map_t::operator= (std::nullptr_t ptr)
|
|
{
|
|
util::view<std::byte*>::operator= (ptr);
|
|
return *this;
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
void
|
|
cruft::vk::map_t::destroy (device &_device, device_memory &_memory)
|
|
{
|
|
CHECK_NEZ (cbegin ());
|
|
CHECK_NEZ (cend ());
|
|
|
|
vkUnmapMemory (_device.native (), _memory.native ());
|
|
|
|
*this = 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);
|
|
error::try_code (err);
|
|
|
|
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 ();
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
void
|
|
cruft::vk::owned_map_t::destroy ()
|
|
{
|
|
if (cbegin ())
|
|
map_t::destroy (m_memory.owner (), *m_memory);
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
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
|
|
};
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
VkDeviceSize
|
|
device_memory::commitment (const device &dev) const
|
|
{
|
|
VkDeviceSize size;
|
|
vkGetDeviceMemoryCommitment (dev.native (), native (), &size);
|
|
return size;
|
|
}
|