mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-01-09 18:20:16 +01:00
41 lines
879 B
C++
41 lines
879 B
C++
#include "buffer_view.h"
|
|
#include "shared.h"
|
|
|
|
namespace vk
|
|
{
|
|
buffer_view::buffer_view(VkDevice dev, VkBuffer buffer, VkFormat format, VkDeviceSize offset, VkDeviceSize size)
|
|
: m_device(dev)
|
|
{
|
|
info.buffer = buffer;
|
|
info.format = format;
|
|
info.offset = offset;
|
|
info.range = size;
|
|
info.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
|
|
CHECK_RESULT(vkCreateBufferView(m_device, &info, nullptr, &value));
|
|
}
|
|
|
|
buffer_view::~buffer_view()
|
|
{
|
|
vkDestroyBufferView(m_device, value, nullptr);
|
|
}
|
|
|
|
bool buffer_view::in_range(u32 address, u32 size, u32& offset) const
|
|
{
|
|
if (address < info.offset)
|
|
return false;
|
|
|
|
const u32 _offset = address - static_cast<u32>(info.offset);
|
|
if (info.range < _offset)
|
|
return false;
|
|
|
|
const auto remaining = info.range - _offset;
|
|
if (size <= remaining)
|
|
{
|
|
offset = _offset;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|