2017-10-10 23:32:13 +02:00
|
|
|
#pragma once
|
|
|
|
|
2017-12-09 02:44:59 +01:00
|
|
|
#include "dxvk_format.h"
|
2017-10-15 14:36:41 +02:00
|
|
|
#include "dxvk_memory.h"
|
2017-10-10 23:32:13 +02:00
|
|
|
#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
|
2017-10-15 14:36:41 +02:00
|
|
|
VkDeviceSize size;
|
|
|
|
|
|
|
|
/// Buffer usage flags
|
|
|
|
VkBufferUsageFlags usage;
|
2017-10-10 23:32:13 +02:00
|
|
|
|
2017-10-15 17:56:06 +02:00
|
|
|
/// Pipeline stages that can access
|
|
|
|
/// the contents of the buffer.
|
|
|
|
VkPipelineStageFlags stages;
|
|
|
|
|
|
|
|
/// Allowed access patterns
|
|
|
|
VkAccessFlags access;
|
2017-10-10 23:32:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-11-21 19:50:57 +01:00
|
|
|
/**
|
|
|
|
* \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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
/**
|
2017-12-10 15:57:51 +01:00
|
|
|
* \brief Buffer resource
|
2017-10-10 23:32:13 +02:00
|
|
|
*
|
2017-12-10 15:57:51 +01:00
|
|
|
* A simple buffer resource that stores linear,
|
|
|
|
* unformatted data. Can be accessed by the host
|
|
|
|
* if allocated on an appropriate memory type.
|
2017-10-10 23:32:13 +02:00
|
|
|
*/
|
|
|
|
class DxvkBuffer : public DxvkResource {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-10-15 14:36:41 +02:00
|
|
|
DxvkBuffer(
|
|
|
|
const Rc<vk::DeviceFn>& vkd,
|
|
|
|
const DxvkBufferCreateInfo& createInfo,
|
|
|
|
DxvkMemoryAllocator& memAlloc,
|
|
|
|
VkMemoryPropertyFlags memFlags);
|
|
|
|
~DxvkBuffer();
|
2017-10-10 23:32:13 +02:00
|
|
|
|
2017-10-15 14:36:41 +02:00
|
|
|
/**
|
|
|
|
* \brief Buffer handle
|
|
|
|
* \returns Buffer handle
|
|
|
|
*/
|
|
|
|
VkBuffer handle() const {
|
|
|
|
return m_buffer;
|
|
|
|
}
|
2017-10-10 23:32:13 +02:00
|
|
|
|
2017-10-15 14:36:41 +02:00
|
|
|
/**
|
|
|
|
* \brief Buffer properties
|
|
|
|
* \returns Buffer properties
|
|
|
|
*/
|
|
|
|
const DxvkBufferCreateInfo& info() const {
|
|
|
|
return m_info;
|
|
|
|
}
|
2017-10-10 23:32:13 +02:00
|
|
|
|
2017-10-15 14:36:41 +02:00
|
|
|
/**
|
|
|
|
* \brief Map pointer
|
|
|
|
*
|
|
|
|
* If the buffer has been created on a host-visible
|
|
|
|
* memory type, the buffer memory is mapped and can
|
|
|
|
* be accessed by the host.
|
2017-12-10 15:57:51 +01:00
|
|
|
* \param [in] offset Byte offset into mapped region
|
2017-10-15 14:36:41 +02:00
|
|
|
* \returns Pointer to mapped memory region
|
|
|
|
*/
|
2017-12-10 15:57:51 +01:00
|
|
|
void* mapPtr(VkDeviceSize offset) const {
|
|
|
|
return m_memory.mapPtr(offset);
|
2017-10-15 14:36:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-10-10 23:32:13 +02:00
|
|
|
|
2017-10-15 14:36:41 +02:00
|
|
|
Rc<vk::DeviceFn> m_vkd;
|
|
|
|
DxvkBufferCreateInfo m_info;
|
|
|
|
DxvkMemory m_memory;
|
|
|
|
VkBuffer m_buffer = VK_NULL_HANDLE;
|
2017-10-10 23:32:13 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-10-15 17:56:06 +02:00
|
|
|
|
2017-11-21 19:50:57 +01:00
|
|
|
/**
|
|
|
|
* \brief Buffer view
|
|
|
|
*
|
|
|
|
* Allows the application to interpret buffer
|
|
|
|
* contents like formatted pixel data. These
|
|
|
|
* buffer views are used as texel buffers.
|
|
|
|
*/
|
|
|
|
class DxvkBufferView : public DxvkResource {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
DxvkBufferView(
|
|
|
|
const Rc<vk::DeviceFn>& vkd,
|
|
|
|
const Rc<DxvkBuffer>& buffer,
|
|
|
|
const DxvkBufferViewCreateInfo& info);
|
|
|
|
|
|
|
|
~DxvkBufferView();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Buffer view handle
|
|
|
|
* \returns Buffer view handle
|
|
|
|
*/
|
|
|
|
VkBufferView handle() const {
|
|
|
|
return m_view;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Buffer view properties
|
|
|
|
* \returns Buffer view properties
|
|
|
|
*/
|
|
|
|
const DxvkBufferViewCreateInfo& info() const {
|
|
|
|
return m_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Underlying buffer object
|
|
|
|
* \returns Underlying buffer object
|
|
|
|
*/
|
|
|
|
Rc<DxvkBuffer> buffer() const {
|
|
|
|
return m_buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
Rc<vk::DeviceFn> m_vkd;
|
|
|
|
Rc<DxvkBuffer> m_buffer;
|
|
|
|
|
|
|
|
DxvkBufferViewCreateInfo m_info;
|
|
|
|
VkBufferView m_view;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-10-15 17:56:06 +02:00
|
|
|
/**
|
2017-12-14 15:24:43 +01:00
|
|
|
* \brief Buffer slice
|
2017-10-15 17:56:06 +02:00
|
|
|
*
|
2017-12-14 15:24:43 +01:00
|
|
|
* Stores the buffer and a sub-range of the buffer.
|
|
|
|
* Slices are considered equal if the buffer and
|
|
|
|
* the buffer range are the same.
|
2017-10-15 17:56:06 +02:00
|
|
|
*/
|
2017-12-14 15:24:43 +01:00
|
|
|
class DxvkBufferSlice {
|
2017-10-15 17:56:06 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-12-14 15:24:43 +01:00
|
|
|
DxvkBufferSlice() { }
|
|
|
|
DxvkBufferSlice(
|
2017-10-15 17:56:06 +02:00
|
|
|
const Rc<DxvkBuffer>& buffer,
|
|
|
|
VkDeviceSize rangeOffset,
|
|
|
|
VkDeviceSize rangeLength)
|
|
|
|
: m_buffer(buffer),
|
|
|
|
m_offset(rangeOffset),
|
|
|
|
m_length(rangeLength) { }
|
|
|
|
|
2017-12-14 19:07:08 +01:00
|
|
|
Rc<DxvkBuffer> buffer() const {
|
2017-10-15 17:56:06 +02:00
|
|
|
return m_buffer;
|
|
|
|
}
|
|
|
|
|
2017-12-14 19:09:49 +01:00
|
|
|
VkBuffer handle() const {
|
2017-11-20 15:35:29 +01:00
|
|
|
return m_buffer != nullptr
|
|
|
|
? m_buffer->handle()
|
|
|
|
: VK_NULL_HANDLE;
|
2017-11-20 13:21:27 +01:00
|
|
|
}
|
|
|
|
|
2017-12-14 19:09:49 +01:00
|
|
|
size_t offset() const {
|
2017-11-20 13:21:27 +01:00
|
|
|
return m_offset;
|
|
|
|
}
|
|
|
|
|
2017-12-14 19:09:49 +01:00
|
|
|
size_t length() const {
|
2017-11-20 13:21:27 +01:00
|
|
|
return m_length;
|
|
|
|
}
|
|
|
|
|
2017-12-15 19:11:10 +01:00
|
|
|
void* mapPtr(VkDeviceSize offset) const {
|
|
|
|
return m_buffer->mapPtr(m_offset + offset);
|
|
|
|
}
|
|
|
|
|
2017-10-15 17:56:06 +02:00
|
|
|
VkDescriptorBufferInfo descriptorInfo() const {
|
|
|
|
VkDescriptorBufferInfo info;
|
|
|
|
info.buffer = m_buffer->handle();
|
|
|
|
info.offset = m_offset;
|
|
|
|
info.range = m_length;
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2017-12-14 15:24:43 +01:00
|
|
|
bool operator == (const DxvkBufferSlice& other) const {
|
2017-10-15 17:56:06 +02:00
|
|
|
return this->m_buffer == other.m_buffer
|
|
|
|
&& this->m_offset == other.m_offset
|
|
|
|
&& this->m_length == other.m_length;
|
|
|
|
}
|
|
|
|
|
2017-12-14 15:24:43 +01:00
|
|
|
bool operator != (const DxvkBufferSlice& other) const {
|
2017-10-15 17:56:06 +02:00
|
|
|
return this->m_buffer != other.m_buffer
|
|
|
|
|| this->m_offset != other.m_offset
|
|
|
|
|| this->m_length != other.m_length;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
Rc<DxvkBuffer> m_buffer = nullptr;
|
|
|
|
VkDeviceSize m_offset = 0;
|
|
|
|
VkDeviceSize m_length = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
}
|