mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-21 22:54:16 +01:00
[dxvk] Introduce DxvkBufferAllocation
For now, this is merely a wrapper around the existing buffer slice struct in order to allow easier refactoring.
This commit is contained in:
parent
d0832f8431
commit
5c2f56c9cc
@ -100,10 +100,10 @@ namespace dxvk {
|
|||||||
* to the mapped region..
|
* to the mapped region..
|
||||||
*/
|
*/
|
||||||
struct DxvkBufferSliceHandle {
|
struct DxvkBufferSliceHandle {
|
||||||
VkBuffer handle;
|
VkBuffer handle = VK_NULL_HANDLE;
|
||||||
VkDeviceSize offset;
|
VkDeviceSize offset = 0u;
|
||||||
VkDeviceSize length;
|
VkDeviceSize length = 0u;
|
||||||
void* mapPtr;
|
void* mapPtr = nullptr;
|
||||||
|
|
||||||
bool eq(const DxvkBufferSliceHandle& other) const {
|
bool eq(const DxvkBufferSliceHandle& other) const {
|
||||||
return handle == other.handle
|
return handle == other.handle
|
||||||
@ -121,6 +121,61 @@ namespace dxvk {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Buffer allocation
|
||||||
|
*
|
||||||
|
* References a buffer allocation and stores
|
||||||
|
* the offset. Used when renaming a buffer.
|
||||||
|
*/
|
||||||
|
class DxvkBufferAllocation {
|
||||||
|
friend class DxvkBuffer;
|
||||||
|
friend class DxvkContext; /* TODO remove */
|
||||||
|
public:
|
||||||
|
|
||||||
|
DxvkBufferAllocation() = default;
|
||||||
|
|
||||||
|
explicit DxvkBufferAllocation(DxvkBufferSliceHandle slice)
|
||||||
|
: m_slice(slice) { }
|
||||||
|
|
||||||
|
DxvkBufferAllocation(const DxvkBufferAllocation&) = default;
|
||||||
|
DxvkBufferAllocation& operator = (const DxvkBufferAllocation&) = default;
|
||||||
|
|
||||||
|
DxvkBufferAllocation(DxvkBufferAllocation&& other)
|
||||||
|
: m_slice(other.m_slice) {
|
||||||
|
other.m_slice = DxvkBufferSliceHandle();
|
||||||
|
}
|
||||||
|
|
||||||
|
DxvkBufferAllocation& operator = (DxvkBufferAllocation&& other) {
|
||||||
|
m_slice = other.m_slice;
|
||||||
|
other.m_slice = DxvkBufferSliceHandle();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
~DxvkBufferAllocation() = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Retrieves CPU pointer
|
||||||
|
* \returns Pointer to the mapped buffer slice
|
||||||
|
*/
|
||||||
|
void* mapPtr() const {
|
||||||
|
return m_slice.mapPtr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Checks whether the slice is valid
|
||||||
|
* \returns \c true if the slice is valid
|
||||||
|
*/
|
||||||
|
explicit operator bool () const {
|
||||||
|
return m_slice.handle != VK_NULL_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
DxvkBufferSliceHandle m_slice = { };
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Virtual buffer resource
|
* \brief Virtual buffer resource
|
||||||
*
|
*
|
||||||
@ -247,7 +302,7 @@ namespace dxvk {
|
|||||||
DxvkBufferSliceHandle rename(const DxvkBufferSliceHandle& slice) {
|
DxvkBufferSliceHandle rename(const DxvkBufferSliceHandle& slice) {
|
||||||
return std::exchange(m_physSlice, slice);
|
return std::exchange(m_physSlice, slice);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Transform feedback vertex stride
|
* \brief Transform feedback vertex stride
|
||||||
*
|
*
|
||||||
@ -269,7 +324,7 @@ namespace dxvk {
|
|||||||
void setXfbVertexStride(uint32_t stride) {
|
void setXfbVertexStride(uint32_t stride) {
|
||||||
m_vertexStride = stride;
|
m_vertexStride = stride;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Allocates new buffer slice
|
* \brief Allocates new buffer slice
|
||||||
* \returns The new buffer slice
|
* \returns The new buffer slice
|
||||||
@ -309,7 +364,34 @@ namespace dxvk {
|
|||||||
m_freeSlices.pop_back();
|
m_freeSlices.pop_back();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Allocates a new buffer slice
|
||||||
|
* \returns New buffer slice
|
||||||
|
*/
|
||||||
|
DxvkBufferAllocation allocateSlice() {
|
||||||
|
return DxvkBufferAllocation(allocSlice());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Replaces backing storage
|
||||||
|
*
|
||||||
|
* Implicitly invalidates all views created for the buffer.
|
||||||
|
* \param [in] slice New buffer slice
|
||||||
|
* \returns Previous buffer allocation for lifetime tracking.
|
||||||
|
*/
|
||||||
|
DxvkBufferAllocation assignSlice(DxvkBufferAllocation&& slice) {
|
||||||
|
return DxvkBufferAllocation(rename(slice.m_slice));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Retrieves current backing storage
|
||||||
|
* \returns Current buffer allocation
|
||||||
|
*/
|
||||||
|
DxvkBufferAllocation getAllocation() const {
|
||||||
|
return DxvkBufferAllocation(m_physSlice);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Frees a buffer slice
|
* \brief Frees a buffer slice
|
||||||
*
|
*
|
||||||
|
@ -1828,10 +1828,10 @@ namespace dxvk {
|
|||||||
|
|
||||||
void DxvkContext::invalidateBuffer(
|
void DxvkContext::invalidateBuffer(
|
||||||
const Rc<DxvkBuffer>& buffer,
|
const Rc<DxvkBuffer>& buffer,
|
||||||
const DxvkBufferSliceHandle& slice) {
|
DxvkBufferAllocation&& slice) {
|
||||||
// Allocate new backing resource
|
// Allocate new backing resource
|
||||||
DxvkBufferSliceHandle prevSlice = buffer->rename(slice);
|
DxvkBufferAllocation prevSlice = buffer->assignSlice(std::move(slice));
|
||||||
m_cmd->freeBufferSlice(buffer, prevSlice);
|
m_cmd->freeBufferSlice(buffer, prevSlice.m_slice);
|
||||||
|
|
||||||
// We also need to update all bindings that the buffer
|
// We also need to update all bindings that the buffer
|
||||||
// may be bound to either directly or through views.
|
// may be bound to either directly or through views.
|
||||||
@ -1865,6 +1865,13 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DxvkContext::invalidateBuffer(
|
||||||
|
const Rc<DxvkBuffer>& buffer,
|
||||||
|
const DxvkBufferSliceHandle& slice) {
|
||||||
|
invalidateBuffer(buffer, DxvkBufferAllocation(slice));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void DxvkContext::resolveImage(
|
void DxvkContext::resolveImage(
|
||||||
const Rc<DxvkImage>& dstImage,
|
const Rc<DxvkImage>& dstImage,
|
||||||
const Rc<DxvkImage>& srcImage,
|
const Rc<DxvkImage>& srcImage,
|
||||||
@ -6385,10 +6392,10 @@ namespace dxvk {
|
|||||||
&& (m_flags.test(DxvkContextFlag::GpXfbActive)))
|
&& (m_flags.test(DxvkContextFlag::GpXfbActive)))
|
||||||
this->spillRenderPass(true);
|
this->spillRenderPass(true);
|
||||||
|
|
||||||
this->invalidateBuffer(buffer, buffer->allocSlice());
|
this->invalidateBuffer(buffer, buffer->allocateSlice());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DxvkGraphicsPipeline* DxvkContext::lookupGraphicsPipeline(
|
DxvkGraphicsPipeline* DxvkContext::lookupGraphicsPipeline(
|
||||||
const DxvkGraphicsPipelineShaders& shaders) {
|
const DxvkGraphicsPipelineShaders& shaders) {
|
||||||
|
@ -959,8 +959,12 @@ namespace dxvk {
|
|||||||
* \warning If the buffer is used by another context,
|
* \warning If the buffer is used by another context,
|
||||||
* invalidating it will result in undefined behaviour.
|
* invalidating it will result in undefined behaviour.
|
||||||
* \param [in] buffer The buffer to invalidate
|
* \param [in] buffer The buffer to invalidate
|
||||||
* \param [in] slice New buffer slice handle
|
* \param [in] slice New buffer slice
|
||||||
*/
|
*/
|
||||||
|
void invalidateBuffer(
|
||||||
|
const Rc<DxvkBuffer>& buffer,
|
||||||
|
DxvkBufferAllocation&& slice);
|
||||||
|
|
||||||
void invalidateBuffer(
|
void invalidateBuffer(
|
||||||
const Rc<DxvkBuffer>& buffer,
|
const Rc<DxvkBuffer>& buffer,
|
||||||
const DxvkBufferSliceHandle& slice);
|
const DxvkBufferSliceHandle& slice);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user