2017-12-01 17:52:05 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "dxvk_include.h"
|
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
2018-01-23 16:43:55 +01:00
|
|
|
class DxvkDataSlice;
|
|
|
|
|
2017-12-01 17:52:05 +01:00
|
|
|
/**
|
|
|
|
* \brief Data buffer
|
|
|
|
*
|
2018-01-23 16:43:55 +01:00
|
|
|
* Provides a fixed-size buffer with a linear memory
|
|
|
|
* allocator for arbitrary data. Can be used to copy
|
|
|
|
* data to or from resources. Note that allocations
|
|
|
|
* will be aligned to a cache line boundary.
|
2017-12-01 17:52:05 +01:00
|
|
|
*/
|
|
|
|
class DxvkDataBuffer : public RcObject {
|
2018-01-23 16:43:55 +01:00
|
|
|
friend class DxvkDataSlice;
|
2017-12-01 17:52:05 +01:00
|
|
|
public:
|
|
|
|
|
|
|
|
DxvkDataBuffer();
|
2018-01-23 16:43:55 +01:00
|
|
|
DxvkDataBuffer(size_t size);
|
2017-12-01 17:52:05 +01:00
|
|
|
~DxvkDataBuffer();
|
|
|
|
|
2018-01-23 16:43:55 +01:00
|
|
|
/**
|
|
|
|
* \brief Allocates a slice
|
|
|
|
*
|
|
|
|
* If the desired slice length is larger than the
|
|
|
|
* number of bytes left in the buffer, this will
|
|
|
|
* fail and the returned slice points to \c nullptr.
|
|
|
|
* \param [in] n Number of bytes to allocate
|
|
|
|
* \returns The slice, or an empty slice on failure
|
|
|
|
*/
|
|
|
|
DxvkDataSlice alloc(size_t n);
|
2017-12-01 17:52:05 +01:00
|
|
|
|
2018-01-23 16:43:55 +01:00
|
|
|
private:
|
|
|
|
|
2018-05-13 21:34:38 +02:00
|
|
|
char* m_data = nullptr;
|
|
|
|
size_t m_size = 0;
|
|
|
|
size_t m_offset = 0;
|
2018-01-23 16:43:55 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Data buffer slice
|
|
|
|
*
|
|
|
|
* A slice of a \ref DxvkDataBuffer which stores
|
|
|
|
* a strong reference to the backing buffer object.
|
|
|
|
*/
|
|
|
|
class DxvkDataSlice {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
DxvkDataSlice() { }
|
|
|
|
DxvkDataSlice(
|
|
|
|
const Rc<DxvkDataBuffer>& buffer,
|
|
|
|
size_t offset,
|
|
|
|
size_t length)
|
|
|
|
: m_buffer(buffer),
|
|
|
|
m_offset(offset),
|
|
|
|
m_length(length) { }
|
2017-12-01 17:52:05 +01:00
|
|
|
|
2018-01-23 16:43:55 +01:00
|
|
|
void* ptr() const {
|
|
|
|
return m_buffer != nullptr
|
2018-05-13 21:34:38 +02:00
|
|
|
? m_buffer->m_data + m_offset
|
2018-01-23 16:43:55 +01:00
|
|
|
: nullptr;
|
2017-12-01 17:52:05 +01:00
|
|
|
}
|
|
|
|
|
2018-01-23 16:43:55 +01:00
|
|
|
size_t offset() const { return m_offset; }
|
|
|
|
size_t length() const { return m_length; }
|
|
|
|
|
2017-12-01 17:52:05 +01:00
|
|
|
private:
|
|
|
|
|
2018-01-23 16:43:55 +01:00
|
|
|
Rc<DxvkDataBuffer> m_buffer;
|
|
|
|
size_t m_offset = 0;
|
|
|
|
size_t m_length = 0;
|
2017-12-01 17:52:05 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-01-23 16:43:55 +01:00
|
|
|
|
2017-12-01 17:52:05 +01:00
|
|
|
}
|