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

[d3d9] Use DxvkBufferAllocation where appropriate

This commit is contained in:
Philip Rebohle 2024-09-22 12:23:09 +02:00 committed by Philip Rebohle
parent 8e45a60542
commit 6f6e75b4b8
5 changed files with 39 additions and 43 deletions

View File

@ -14,7 +14,7 @@ namespace dxvk {
if (m_mapMode == D3D9_COMMON_BUFFER_MAP_MODE_BUFFER)
m_stagingBuffer = CreateStagingBuffer();
m_sliceHandle = GetMapBuffer()->getSliceHandle();
m_allocation = GetMapBuffer()->getAllocation();
if (m_desc.Pool != D3DPOOL_DEFAULT)
m_dirtyRange = D3D9Range(0, m_desc.Size);

View File

@ -133,17 +133,13 @@ namespace dxvk {
return DxvkBufferSlice();
}
inline DxvkBufferSliceHandle AllocMapSlice() {
return GetMapBuffer()->allocSlice();
inline DxvkBufferAllocation DiscardMapSlice() {
m_allocation = GetMapBuffer()->allocateSlice();
return m_allocation;
}
inline DxvkBufferSliceHandle DiscardMapSlice() {
m_sliceHandle = GetMapBuffer()->allocSlice();
return m_sliceHandle;
}
inline DxvkBufferSliceHandle GetMappedSlice() const {
return m_sliceHandle;
inline DxvkBufferAllocation GetMappedSlice() const {
return m_allocation;
}
inline DWORD GetMapFlags() const { return m_mapFlags; }
@ -240,7 +236,7 @@ namespace dxvk {
Rc<DxvkBuffer> m_buffer;
Rc<DxvkBuffer> m_stagingBuffer;
DxvkBufferSliceHandle m_sliceHandle;
DxvkBufferAllocation m_allocation;
D3D9Range m_dirtyRange;

View File

@ -42,22 +42,20 @@ namespace dxvk {
void* D3D9ConstantBuffer::Alloc(VkDeviceSize size) {
if (unlikely(m_buffer == nullptr)) {
this->createBuffer();
m_slice = m_buffer->getSliceHandle();
}
if (unlikely(m_buffer == nullptr))
m_slice = this->createBuffer();
size = align(size, m_align);
if (unlikely(m_offset + size > m_size)) {
m_slice = m_buffer->allocSlice();
m_slice = m_buffer->allocateSlice();
m_offset = 0;
m_device->EmitCs([
cBuffer = m_buffer,
cSlice = m_slice
] (DxvkContext* ctx) {
ctx->invalidateBuffer(cBuffer, cSlice);
] (DxvkContext* ctx) mutable {
ctx->invalidateBuffer(cBuffer, std::move(cSlice));
});
}
@ -70,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;
}
@ -78,22 +76,22 @@ namespace dxvk {
void* D3D9ConstantBuffer::AllocSlice() {
if (unlikely(m_buffer == nullptr))
this->createBuffer();
m_slice = m_buffer->allocSlice();
m_slice = this->createBuffer();
else
m_slice = m_buffer->allocateSlice();
m_device->EmitCs([
cBuffer = m_buffer,
cSlice = m_slice
] (DxvkContext* ctx) {
ctx->invalidateBuffer(cBuffer, cSlice);
] (DxvkContext* ctx) mutable {
ctx->invalidateBuffer(cBuffer, std::move(cSlice));
});
return m_slice.mapPtr;
return m_slice.mapPtr();
}
void D3D9ConstantBuffer::createBuffer() {
DxvkBufferAllocation D3D9ConstantBuffer::createBuffer() {
auto options = m_device->GetOptions();
// Buffer usage and access flags don't make much of a difference
@ -125,6 +123,8 @@ namespace dxvk {
] (DxvkContext* ctx) mutable {
ctx->bindUniformBuffer(cStages, cBinding, std::move(cSlice));
});
return m_buffer->getAllocation();
}

View File

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

View File

@ -4386,16 +4386,16 @@ namespace dxvk {
VkDeviceSize alignedSize = align(size, CACHE_LINE_SIZE);
if (unlikely(m_upBufferOffset + alignedSize > UPBufferSize)) {
auto sliceHandle = m_upBuffer->allocSlice();
auto slice = m_upBuffer->allocateSlice();
m_upBufferOffset = 0;
m_upBufferMapPtr = sliceHandle.mapPtr;
m_upBufferMapPtr = slice.mapPtr();
EmitCs([
cBuffer = m_upBuffer,
cSlice = sliceHandle
] (DxvkContext* ctx) {
ctx->invalidateBuffer(cBuffer, cSlice);
cSlice = std::move(slice)
] (DxvkContext* ctx) mutable {
ctx->invalidateBuffer(cBuffer, std::move(cSlice));
});
}
@ -5128,19 +5128,20 @@ namespace dxvk {
Rc<DxvkBuffer> mappingBuffer = pResource->GetBuffer<D3D9_COMMON_BUFFER_TYPE_MAPPING>();
DxvkBufferSliceHandle physSlice;
uint8_t* data = nullptr;
if ((Flags & D3DLOCK_DISCARD) && (directMapping || needsReadback)) {
// Allocate a new backing slice for the buffer and set
// it as the 'new' mapped slice. This assumes that the
// only way to invalidate a buffer is by mapping it.
physSlice = pResource->DiscardMapSlice();
auto bufferSlice = pResource->DiscardMapSlice();
data = reinterpret_cast<uint8_t*>(bufferSlice.mapPtr());
EmitCs([
cBuffer = std::move(mappingBuffer),
cBufferSlice = physSlice
] (DxvkContext* ctx) {
ctx->invalidateBuffer(cBuffer, cBufferSlice);
cBufferSlice = std::move(bufferSlice)
] (DxvkContext* ctx) mutable {
ctx->invalidateBuffer(cBuffer, std::move(cBufferSlice));
});
pResource->SetNeedsReadback(false);
@ -5149,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.
physSlice = pResource->GetMappedSlice();
data = reinterpret_cast<uint8_t*>(pResource->GetMappedSlice().mapPtr());
const bool needsReadback = pResource->NeedsReadback();
const bool readOnly = Flags & D3DLOCK_READONLY;
@ -5166,7 +5167,6 @@ namespace dxvk {
}
}
uint8_t* data = reinterpret_cast<uint8_t*>(physSlice.mapPtr);
// The offset/size is not clamped to or affected by the desc size.
data += OffsetToLock;
@ -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);