1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-11-29 01:24:11 +01:00

[dxvk] Remove DxvkBufferAllocation

This commit is contained in:
Philip Rebohle 2024-09-23 13:29:38 +02:00 committed by Philip Rebohle
parent 14990dbb49
commit 1fd3c8040d
16 changed files with 61 additions and 118 deletions

View File

@ -119,7 +119,7 @@ namespace dxvk {
m_sparseAllocator = m_parent->GetDXVKDevice()->createSparsePageAllocator();
m_sparseAllocator->setCapacity(info.size / SparseMemoryPageSize);
m_allocation = DxvkBufferAllocation();
m_allocation = nullptr;
m_mapMode = D3D11_COMMON_BUFFER_MAP_MODE_NONE;
}

View File

@ -113,16 +113,16 @@ namespace dxvk {
: DxvkBufferSlice();
}
DxvkBufferAllocation AllocSlice() {
Rc<DxvkResourceAllocation> AllocSlice() {
return m_buffer->allocateSlice();
}
DxvkBufferAllocation DiscardSlice() {
Rc<DxvkResourceAllocation> DiscardSlice() {
m_allocation = m_buffer->allocateSlice();
return m_allocation;
}
DxvkBufferAllocation GetMappedSlice() const {
Rc<DxvkResourceAllocation> GetMappedSlice() const {
return m_allocation;
}
@ -184,7 +184,7 @@ namespace dxvk {
Rc<DxvkBuffer> m_buffer;
Rc<DxvkBuffer> m_soCounter;
Rc<DxvkSparsePageAllocator> m_sparseAllocator;
DxvkBufferAllocation m_allocation;
Rc<DxvkResourceAllocation> m_allocation;
uint64_t m_seq = 0ull;
D3D11DXGIResource m_resource;

View File

@ -279,13 +279,13 @@ namespace dxvk {
// we may write to the buffer resource directly and
// just swap in the buffer slice as needed.
auto bufferSlice = pBuffer->AllocSlice();
pMappedResource->pData = bufferSlice.mapPtr();
pMappedResource->pData = bufferSlice->mapPtr();
EmitCs([
cDstBuffer = pBuffer->GetBuffer(),
cDstSlice = std::move(bufferSlice)
] (DxvkContext* ctx) {
ctx->invalidateBuffer(cDstBuffer, DxvkBufferAllocation(cDstSlice));
ctx->invalidateBuffer(cDstBuffer, Rc<DxvkResourceAllocation>(cDstSlice));
});
} else {
// For GPU-writable resources, we need a data slice
@ -297,8 +297,8 @@ namespace dxvk {
cDstBuffer = pBuffer->GetBuffer(),
cDataSlice = dataSlice
] (DxvkContext* ctx) {
DxvkBufferAllocation slice = cDstBuffer->allocateSlice();
std::memcpy(slice.mapPtr(), cDataSlice.ptr(), cDataSlice.length());
Rc<DxvkResourceAllocation> slice = cDstBuffer->allocateSlice();
std::memcpy(slice->mapPtr(), cDataSlice.ptr(), cDataSlice.length());
ctx->invalidateBuffer(cDstBuffer, std::move(slice));
});
}

View File

@ -333,7 +333,7 @@ namespace dxvk {
// it as the 'new' mapped slice. This assumes that the
// only way to invalidate a buffer is by mapping it.
auto bufferSlice = pResource->DiscardSlice();
pMappedResource->pData = bufferSlice.mapPtr();
pMappedResource->pData = bufferSlice->mapPtr();
pMappedResource->RowPitch = bufferSize;
pMappedResource->DepthPitch = bufferSize;
@ -348,7 +348,7 @@ namespace dxvk {
} else if (likely(MapType == D3D11_MAP_WRITE_NO_OVERWRITE)) {
// Put this on a fast path without any extra checks since it's
// a somewhat desired method to partially update large buffers
pMappedResource->pData = pResource->GetMappedSlice().mapPtr();
pMappedResource->pData = pResource->GetMappedSlice()->mapPtr();
pMappedResource->RowPitch = bufferSize;
pMappedResource->DepthPitch = bufferSize;
return S_OK;
@ -379,8 +379,8 @@ namespace dxvk {
auto srcSlice = pResource->GetMappedSlice();
auto dstSlice = pResource->DiscardSlice();
auto srcPtr = srcSlice.mapPtr();
auto dstPtr = dstSlice.mapPtr();
auto srcPtr = srcSlice->mapPtr();
auto dstPtr = dstSlice->mapPtr();
EmitCs([
cBuffer = std::move(buffer),
@ -398,7 +398,7 @@ namespace dxvk {
if (!WaitForResource(buffer, sequenceNumber, MapType, MapFlags))
return DXGI_ERROR_WAS_STILL_DRAWING;
pMappedResource->pData = pResource->GetMappedSlice().mapPtr();
pMappedResource->pData = pResource->GetMappedSlice()->mapPtr();
pMappedResource->RowPitch = bufferSize;
pMappedResource->DepthPitch = bufferSize;
return S_OK;
@ -528,8 +528,8 @@ namespace dxvk {
auto srcSlice = pResource->GetMappedSlice(Subresource);
auto dstSlice = pResource->DiscardSlice(Subresource);
auto srcPtr = srcSlice.mapPtr();
mapPtr = dstSlice.mapPtr();
auto srcPtr = srcSlice->mapPtr();
mapPtr = dstSlice->mapPtr();
EmitCs([
cImageBuffer = mappedBuffer,
@ -552,7 +552,7 @@ namespace dxvk {
return DXGI_ERROR_WAS_STILL_DRAWING;
}
mapPtr = pResource->GetMappedSlice(Subresource).mapPtr();
mapPtr = pResource->GetMappedSlice(Subresource)->mapPtr();
}
}
@ -704,7 +704,7 @@ namespace dxvk {
if (likely(CopyFlags != D3D11_COPY_NO_OVERWRITE)) {
auto bufferSlice = pDstBuffer->DiscardSlice();
mapPtr = bufferSlice.mapPtr();
mapPtr = bufferSlice->mapPtr();
EmitCs([
cBuffer = pDstBuffer->GetBuffer(),
@ -713,7 +713,7 @@ namespace dxvk {
ctx->invalidateBuffer(cBuffer, std::move(cBufferSlice));
});
} else {
mapPtr = pDstBuffer->GetMappedSlice().mapPtr();
mapPtr = pDstBuffer->GetMappedSlice()->mapPtr();
}
std::memcpy(reinterpret_cast<char*>(mapPtr) + Offset, pSrcData, Length);

View File

@ -219,13 +219,13 @@ namespace dxvk {
* \param [in] Subresource Subresource to discard
* \returns Newly allocated mapped buffer slice
*/
DxvkBufferAllocation DiscardSlice(UINT Subresource) {
Rc<DxvkResourceAllocation> DiscardSlice(UINT Subresource) {
if (Subresource < m_buffers.size()) {
DxvkBufferAllocation slice = m_buffers[Subresource].buffer->allocateSlice();
Rc<DxvkResourceAllocation> slice = m_buffers[Subresource].buffer->allocateSlice();
m_buffers[Subresource].slice = slice;
return slice;
} else {
return DxvkBufferAllocation();
return nullptr;
}
}
@ -235,10 +235,10 @@ namespace dxvk {
* \param [in] Subresource Subresource index to query
* \returns Currently mapped buffer slice
*/
DxvkBufferAllocation GetMappedSlice(UINT Subresource) const {
Rc<DxvkResourceAllocation> GetMappedSlice(UINT Subresource) const {
return Subresource < m_buffers.size()
? m_buffers[Subresource].slice
: DxvkBufferAllocation();
: nullptr;
}
/**
@ -473,8 +473,8 @@ namespace dxvk {
private:
struct MappedBuffer {
Rc<DxvkBuffer> buffer;
DxvkBufferAllocation slice;
Rc<DxvkBuffer> buffer;
Rc<DxvkResourceAllocation> slice;
std::vector<D3D11_COMMON_TEXTURE_REGION> dirtyRegions;
};

View File

@ -1296,8 +1296,8 @@ namespace dxvk {
uboData.yMax = 0.9215686f;
}
DxvkBufferAllocation uboSlice = m_ubo->allocateSlice();
memcpy(uboSlice.mapPtr(), &uboData, sizeof(uboData));
Rc<DxvkResourceAllocation> uboSlice = m_ubo->allocateSlice();
memcpy(uboSlice->mapPtr(), &uboData, sizeof(uboData));
ctx->invalidateBuffer(m_ubo, std::move(uboSlice));
ctx->setViewports(1, &viewport, &scissor);

View File

@ -133,12 +133,12 @@ namespace dxvk {
return DxvkBufferSlice();
}
inline DxvkBufferAllocation DiscardMapSlice() {
inline Rc<DxvkResourceAllocation> DiscardMapSlice() {
m_allocation = GetMapBuffer()->allocateSlice();
return m_allocation;
}
inline DxvkBufferAllocation GetMappedSlice() const {
inline Rc<DxvkResourceAllocation> GetMappedSlice() const {
return m_allocation;
}
@ -236,7 +236,7 @@ namespace dxvk {
Rc<DxvkBuffer> m_buffer;
Rc<DxvkBuffer> m_stagingBuffer;
DxvkBufferAllocation m_allocation;
Rc<DxvkResourceAllocation> m_allocation;
D3D9Range m_dirtyRange;

View File

@ -68,7 +68,7 @@ namespace dxvk {
ctx->bindUniformBufferRange(cStages, cBinding, cOffset, cLength);
});
void* mapPtr = reinterpret_cast<char*>(m_slice.mapPtr()) + m_offset;
void* mapPtr = reinterpret_cast<char*>(m_slice->mapPtr()) + m_offset;
m_offset += size;
return mapPtr;
}
@ -87,11 +87,11 @@ namespace dxvk {
ctx->invalidateBuffer(cBuffer, std::move(cSlice));
});
return m_slice.mapPtr();
return m_slice->mapPtr();
}
DxvkBufferAllocation D3D9ConstantBuffer::createBuffer() {
Rc<DxvkResourceAllocation> D3D9ConstantBuffer::createBuffer() {
auto options = m_device->GetOptions();
// Buffer usage and access flags don't make much of a difference

View File

@ -74,9 +74,9 @@ namespace dxvk {
VkDeviceSize m_offset = 0ull;
Rc<DxvkBuffer> m_buffer = nullptr;
DxvkBufferAllocation m_slice = { };
Rc<DxvkResourceAllocation> m_slice = nullptr;
DxvkBufferAllocation createBuffer();
Rc<DxvkResourceAllocation> createBuffer();
VkDeviceSize getAlignment(const Rc<DxvkDevice>& device) const;

View File

@ -4389,7 +4389,7 @@ namespace dxvk {
auto slice = m_upBuffer->allocateSlice();
m_upBufferOffset = 0;
m_upBufferMapPtr = slice.mapPtr();
m_upBufferMapPtr = slice->mapPtr();
EmitCs([
cBuffer = m_upBuffer,
@ -5135,7 +5135,7 @@ namespace dxvk {
// it as the 'new' mapped slice. This assumes that the
// only way to invalidate a buffer is by mapping it.
auto bufferSlice = pResource->DiscardMapSlice();
data = reinterpret_cast<uint8_t*>(bufferSlice.mapPtr());
data = reinterpret_cast<uint8_t*>(bufferSlice->mapPtr());
EmitCs([
cBuffer = std::move(mappingBuffer),
@ -5150,7 +5150,7 @@ namespace dxvk {
// Use map pointer from previous map operation. This
// way we don't have to synchronize with the CS thread
// if the map mode is D3DLOCK_NOOVERWRITE.
data = reinterpret_cast<uint8_t*>(pResource->GetMappedSlice().mapPtr());
data = reinterpret_cast<uint8_t*>(pResource->GetMappedSlice()->mapPtr());
const bool needsReadback = pResource->NeedsReadback();
const bool readOnly = Flags & D3DLOCK_READONLY;
@ -5197,7 +5197,7 @@ namespace dxvk {
D3D9Range& range = pResource->DirtyRange();
D3D9BufferSlice slice = AllocStagingBuffer(range.max - range.min);
void* srcData = reinterpret_cast<uint8_t*>(srcSlice.mapPtr()) + range.min;
void* srcData = reinterpret_cast<uint8_t*>(srcSlice->mapPtr()) + range.min;
memcpy(slice.mapPtr, srcData, range.max - range.min);
EmitCs([
@ -5379,7 +5379,7 @@ namespace dxvk {
if (likely(copy.copyBufferLength != 0)) {
const auto* vbo = GetCommonBuffer(m_state.vertexBuffers[i].vertexBuffer);
uint8_t* data = reinterpret_cast<uint8_t*>(upSlice.mapPtr) + copy.dstOffset;
const uint8_t* src = reinterpret_cast<uint8_t*>(vbo->GetMappedSlice().mapPtr()) + copy.srcOffset;
const uint8_t* src = reinterpret_cast<uint8_t*>(vbo->GetMappedSlice()->mapPtr()) + copy.srcOffset;
if (likely(copy.copyElementStride == copy.copyElementSize)) {
std::memcpy(data, src, copy.copyBufferLength);
@ -5428,7 +5428,7 @@ namespace dxvk {
VkIndexType indexType = DecodeIndexType(ibo->Desc()->Format);
uint32_t offset = indexStride * FirstIndex;
uint8_t* data = reinterpret_cast<uint8_t*>(upSlice.mapPtr) + iboUPBufferOffset;
uint8_t* src = reinterpret_cast<uint8_t*>(ibo->GetMappedSlice().mapPtr()) + offset;
uint8_t* src = reinterpret_cast<uint8_t*>(ibo->GetMappedSlice()->mapPtr()) + offset;
std::memcpy(data, src, iboUPBufferSize);
auto iboSlice = upSlice.slice.subSlice(iboUPBufferOffset, iboUPBufferSize);

View File

@ -74,24 +74,6 @@ namespace dxvk {
};
/**
* \brief Buffer info
*
* Stores a Vulkan buffer handle and the
* memory object that is bound to the buffer.
*/
struct DxvkBufferHandle {
VkBuffer buffer = VK_NULL_HANDLE;
DxvkMemory memory;
VkDeviceSize getBaseOffset() const {
return buffer == memory.buffer()
? memory.offset()
: 0u;
}
};
/**
* \brief Buffer slice info
*
@ -121,53 +103,6 @@ namespace dxvk {
};
/**
* \brief Buffer allocation
*
* References a buffer allocation and stores
* the offset. Used when renaming a buffer.
*/
class DxvkBufferAllocation {
friend class DxvkBuffer;
public:
DxvkBufferAllocation() = default;
DxvkBufferAllocation(
Rc<DxvkResourceAllocation> allocation)
: m_allocation(std::move(allocation)) { }
/**
* \brief Retrieves CPU pointer
* \returns Pointer to the mapped buffer slice
*/
void* mapPtr() const {
return m_allocation->getBufferInfo().mapPtr;
}
/**
* \brief Checks whether the slice is valid
* \returns \c true if the slice is valid
*/
explicit operator bool () const {
return bool(m_allocation);
}
/**
* \brief Extracts resource allocation
* \returns Underlying resource allocation
*/
Rc<DxvkResourceAllocation> extract() {
return std::move(m_allocation);
}
private:
Rc<DxvkResourceAllocation> m_allocation;
};
/**
* \brief Virtual buffer resource
*
@ -313,14 +248,14 @@ namespace dxvk {
* \brief Allocates new buffer slice
* \returns The new buffer slice
*/
DxvkBufferAllocation allocateSlice() {
Rc<DxvkResourceAllocation> allocateSlice() {
VkBufferCreateInfo info = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
info.flags = m_info.flags;
info.usage = m_info.usage;
info.size = m_info.size;
info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
return DxvkBufferAllocation(m_allocator->createBufferResource(info, m_properties));
return m_allocator->createBufferResource(info, m_properties);
}
/**
@ -333,10 +268,10 @@ namespace dxvk {
* \param [in] slice The new backing resource
* \returns Previous buffer allocation
*/
Rc<DxvkResourceAllocation> assignSlice(DxvkBufferAllocation&& slice) {
Rc<DxvkResourceAllocation> assignSlice(Rc<DxvkResourceAllocation>&& slice) {
Rc<DxvkResourceAllocation> result = std::move(m_storage);
m_storage = std::move(slice.m_allocation);
m_storage = std::move(slice);
m_bufferInfo = m_storage->getBufferInfo();
return result;
}
@ -345,8 +280,8 @@ namespace dxvk {
* \brief Retrieves current backing storage
* \returns Current buffer allocation
*/
DxvkBufferAllocation getAllocation() const {
return DxvkBufferAllocation(m_storage);
Rc<DxvkResourceAllocation> getAllocation() const {
return m_storage;
}
/**

View File

@ -1828,7 +1828,7 @@ namespace dxvk {
void DxvkContext::invalidateBuffer(
const Rc<DxvkBuffer>& buffer,
DxvkBufferAllocation&& slice) {
Rc<DxvkResourceAllocation>&& slice) {
// Allocate new backing resource
Rc<DxvkResourceAllocation> prevAllocation = buffer->assignSlice(std::move(slice));
m_cmd->trackResource<DxvkAccess::None>(prevAllocation);

View File

@ -963,7 +963,7 @@ namespace dxvk {
*/
void invalidateBuffer(
const Rc<DxvkBuffer>& buffer,
DxvkBufferAllocation&& slice);
Rc<DxvkResourceAllocation>&& slice);
/**
* \brief Updates push constants

View File

@ -483,6 +483,14 @@ namespace dxvk {
return cur >= getIncrement(access);
}
/**
* \brief Queries mapped memory region
* \returns Mapped memory region
*/
void* mapPtr() const {
return m_mapPtr;
}
/**
* \brief Queries buffer info
* \returns Buffer info

View File

@ -91,10 +91,10 @@ namespace dxvk {
m_gammaSlice = m_gammaBuffer->allocateSlice();
}
std::memcpy(m_gammaSlice.mapPtr(), cpData, size);
std::memcpy(m_gammaSlice->mapPtr(), cpData, size);
} else {
m_gammaBuffer = nullptr;
m_gammaSlice = DxvkBufferAllocation();
m_gammaSlice = nullptr;
}
m_gammaCpCount = cpCount;

View File

@ -81,7 +81,7 @@ namespace dxvk {
Rc<DxvkImageView> m_gammaView;
uint32_t m_gammaCpCount = 0;
bool m_gammaDirty = false;
DxvkBufferAllocation m_gammaSlice = { };
Rc<DxvkResourceAllocation> m_gammaSlice = { };
Rc<DxvkImage> m_resolveImage;
Rc<DxvkImageView> m_resolveView;