2018-01-18 15:52:57 +01:00
|
|
|
#pragma once
|
|
|
|
|
2018-09-20 12:10:43 +02:00
|
|
|
#include "dxvk_descriptor.h"
|
2018-01-18 15:52:57 +01:00
|
|
|
#include "dxvk_format.h"
|
|
|
|
#include "dxvk_memory.h"
|
|
|
|
#include "dxvk_resource.h"
|
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Buffer create info
|
|
|
|
*
|
|
|
|
* The properties of a buffer that are
|
|
|
|
* passed to \ref DxvkDevice::createBuffer
|
|
|
|
*/
|
|
|
|
struct DxvkBufferCreateInfo {
|
|
|
|
/// Size of the buffer, in bytes
|
|
|
|
VkDeviceSize size;
|
|
|
|
|
|
|
|
/// Buffer usage flags
|
|
|
|
VkBufferUsageFlags usage;
|
|
|
|
|
|
|
|
/// Pipeline stages that can access
|
|
|
|
/// the contents of the buffer.
|
|
|
|
VkPipelineStageFlags stages;
|
|
|
|
|
|
|
|
/// Allowed access patterns
|
|
|
|
VkAccessFlags access;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Buffer view create info
|
|
|
|
*
|
|
|
|
* The properties of a buffer view that
|
|
|
|
* are to \ref DxvkDevice::createBufferView
|
|
|
|
*/
|
|
|
|
struct DxvkBufferViewCreateInfo {
|
|
|
|
/// Buffer data format, like image data
|
|
|
|
VkFormat format;
|
|
|
|
|
|
|
|
/// Offset of the buffer region to include in the view
|
|
|
|
VkDeviceSize rangeOffset;
|
|
|
|
|
|
|
|
/// Size of the buffer region to include in the view
|
|
|
|
VkDeviceSize rangeLength;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class DxvkPhysicalBuffer;
|
|
|
|
class DxvkPhysicalBufferSlice;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Physical buffer
|
|
|
|
*
|
|
|
|
* A physical buffer is used as a backing resource for
|
|
|
|
* a virtual buffer. See \ref DxvkBuffer as for why
|
|
|
|
* this separation is necessary.
|
|
|
|
*/
|
|
|
|
class DxvkPhysicalBuffer : public DxvkResource {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
DxvkPhysicalBuffer(
|
|
|
|
const Rc<vk::DeviceFn>& vkd,
|
|
|
|
const DxvkBufferCreateInfo& createInfo,
|
|
|
|
DxvkMemoryAllocator& memAlloc,
|
|
|
|
VkMemoryPropertyFlags memFlags);
|
|
|
|
|
|
|
|
~DxvkPhysicalBuffer();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Vulkan buffer handle
|
|
|
|
* \returns Vulkan buffer handle
|
|
|
|
*/
|
|
|
|
VkBuffer handle() const {
|
|
|
|
return m_handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Map pointer
|
|
|
|
*
|
|
|
|
* Retrieves a pointer into the mapped memory region
|
|
|
|
* of the buffer, relative to the start of the buffer.
|
|
|
|
* \param [in] offset Offset into the buffer
|
|
|
|
* \returns Pointer into the mapped memory region
|
|
|
|
*/
|
|
|
|
void* mapPtr(VkDeviceSize offset) const {
|
|
|
|
return m_memory.mapPtr(offset);
|
|
|
|
}
|
2018-09-20 12:10:43 +02:00
|
|
|
|
2018-01-18 15:52:57 +01:00
|
|
|
/**
|
|
|
|
* \brief Retrieves a physical buffer slice
|
|
|
|
*
|
2018-01-29 00:01:00 +01:00
|
|
|
* \param [in] offset Slice offset
|
|
|
|
* \param [in] length Slice length
|
2018-01-18 15:52:57 +01:00
|
|
|
* \returns The physical slice
|
|
|
|
*/
|
2018-01-29 00:01:00 +01:00
|
|
|
DxvkPhysicalBufferSlice slice(
|
|
|
|
VkDeviceSize offset,
|
|
|
|
VkDeviceSize length);
|
2018-01-18 15:52:57 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
Rc<vk::DeviceFn> m_vkd;
|
|
|
|
DxvkMemory m_memory;
|
|
|
|
VkBuffer m_handle;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Physical buffer slice
|
|
|
|
*
|
|
|
|
* A slice into a physical buffer, which stores
|
|
|
|
* the buffer and the offset into the buffer.
|
|
|
|
*/
|
|
|
|
class DxvkPhysicalBufferSlice {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
DxvkPhysicalBufferSlice() { }
|
|
|
|
DxvkPhysicalBufferSlice(
|
|
|
|
const Rc<DxvkPhysicalBuffer>& buffer,
|
|
|
|
VkDeviceSize offset,
|
|
|
|
VkDeviceSize length)
|
|
|
|
: m_buffer(buffer),
|
|
|
|
m_offset(offset),
|
|
|
|
m_length(length) { }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Buffer handle
|
|
|
|
* \returns Buffer handle
|
|
|
|
*/
|
|
|
|
VkBuffer handle() const {
|
2018-07-24 18:20:45 +02:00
|
|
|
return m_buffer != nullptr
|
|
|
|
? m_buffer->handle()
|
|
|
|
: VK_NULL_HANDLE;
|
2018-01-18 15:52:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Slice offset
|
|
|
|
*
|
|
|
|
* Offset of the slice into
|
|
|
|
* the underlying buffer.
|
|
|
|
* \returns Slice offset
|
|
|
|
*/
|
|
|
|
VkDeviceSize offset() const {
|
|
|
|
return m_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Slice length
|
|
|
|
*
|
|
|
|
* Number of bytes in the slice.
|
|
|
|
* \returns Slice length, in bytes
|
|
|
|
*/
|
|
|
|
VkDeviceSize length() const {
|
|
|
|
return m_length;
|
|
|
|
}
|
|
|
|
|
2018-01-18 17:32:34 +01:00
|
|
|
/**
|
|
|
|
* \brief Sub slice into the physical buffer
|
|
|
|
*
|
|
|
|
* \param [in] offset Offset, relative to this slice
|
|
|
|
* \param [in] length Number of bytes of the sub slice
|
|
|
|
* \returns The sub slice
|
|
|
|
*/
|
|
|
|
DxvkPhysicalBufferSlice subSlice(VkDeviceSize offset, VkDeviceSize length) const {
|
|
|
|
return DxvkPhysicalBufferSlice(m_buffer, m_offset + offset, length);
|
|
|
|
}
|
2018-09-20 12:10:43 +02:00
|
|
|
|
2018-01-18 15:52:57 +01:00
|
|
|
/**
|
|
|
|
* \brief Map pointer
|
|
|
|
*
|
|
|
|
* Retrieves a pointer into the mapped memory
|
|
|
|
* region of the underlying buffer, relative
|
|
|
|
* to the slice's offset.
|
|
|
|
* \param [in] offset Offset into the slice
|
|
|
|
* \returns Pointer to the mapped memory region
|
|
|
|
*/
|
|
|
|
void* mapPtr(VkDeviceSize offset) const {
|
|
|
|
return m_buffer->mapPtr(m_offset + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief The buffer resource
|
|
|
|
* \returns Buffer resource
|
|
|
|
*/
|
|
|
|
Rc<DxvkResource> resource() const {
|
|
|
|
return m_buffer;
|
|
|
|
}
|
|
|
|
|
2018-06-16 11:53:06 +02:00
|
|
|
/**
|
|
|
|
* \brief Checks whether this slice overlaps with another
|
|
|
|
*
|
|
|
|
* \param [in] other The buffer slice to check
|
|
|
|
* \returns \c true if the two slices overlap
|
|
|
|
*/
|
|
|
|
bool overlaps(const DxvkPhysicalBufferSlice& other) const {
|
|
|
|
return this->m_buffer == other.m_buffer
|
|
|
|
&& this->m_offset + this->m_length > other.m_offset
|
|
|
|
&& this->m_offset < other.m_offset + other.m_length;
|
|
|
|
}
|
|
|
|
|
2018-01-18 15:52:57 +01:00
|
|
|
private:
|
|
|
|
|
2018-01-18 18:53:33 +01:00
|
|
|
Rc<DxvkPhysicalBuffer> m_buffer = nullptr;
|
|
|
|
VkDeviceSize m_offset = 0;
|
|
|
|
VkDeviceSize m_length = 0;
|
2018-01-18 15:52:57 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-01-29 00:01:00 +01:00
|
|
|
inline DxvkPhysicalBufferSlice DxvkPhysicalBuffer::slice(
|
|
|
|
VkDeviceSize offset,
|
|
|
|
VkDeviceSize length) {
|
|
|
|
return DxvkPhysicalBufferSlice(this, offset, length);
|
|
|
|
}
|
|
|
|
|
2018-03-07 13:32:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Physical buffer view
|
|
|
|
*
|
|
|
|
* Manages a texel buffer view for a physical
|
|
|
|
* buffer slice, which is used as the backing
|
|
|
|
* resource of a \c DxvkBufferView.
|
|
|
|
*/
|
|
|
|
class DxvkPhysicalBufferView : public DxvkResource {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
DxvkPhysicalBufferView(
|
|
|
|
const Rc<vk::DeviceFn>& vkd,
|
|
|
|
const DxvkPhysicalBufferSlice& slice,
|
|
|
|
const DxvkBufferViewCreateInfo& info);
|
|
|
|
|
|
|
|
~DxvkPhysicalBufferView();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Vulkan buffer view handle
|
|
|
|
* \returns Vulkan buffer view handle
|
|
|
|
*/
|
|
|
|
VkBufferView handle() const {
|
|
|
|
return m_view;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Physical buffer slice
|
|
|
|
*
|
|
|
|
* The slice backing this buffer view.
|
|
|
|
* \returns Physical buffer slice
|
|
|
|
*/
|
|
|
|
DxvkPhysicalBufferSlice slice() const {
|
|
|
|
return m_slice;
|
|
|
|
}
|
2018-09-17 23:30:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Physical buffer resource
|
|
|
|
* \returns Resource pointer
|
|
|
|
*/
|
|
|
|
Rc<DxvkResource> bufferResource() const {
|
|
|
|
return m_slice.resource();
|
|
|
|
}
|
2018-03-07 13:32:17 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
Rc<vk::DeviceFn> m_vkd;
|
|
|
|
DxvkPhysicalBufferSlice m_slice;
|
|
|
|
|
|
|
|
VkBufferView m_view = VK_NULL_HANDLE;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-01-18 15:52:57 +01:00
|
|
|
}
|