mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-12 22:08:59 +01:00
[d3d9] Use DxvkBufferAllocation where appropriate
This commit is contained in:
parent
8e45a60542
commit
6f6e75b4b8
@ -14,7 +14,7 @@ namespace dxvk {
|
|||||||
if (m_mapMode == D3D9_COMMON_BUFFER_MAP_MODE_BUFFER)
|
if (m_mapMode == D3D9_COMMON_BUFFER_MAP_MODE_BUFFER)
|
||||||
m_stagingBuffer = CreateStagingBuffer();
|
m_stagingBuffer = CreateStagingBuffer();
|
||||||
|
|
||||||
m_sliceHandle = GetMapBuffer()->getSliceHandle();
|
m_allocation = GetMapBuffer()->getAllocation();
|
||||||
|
|
||||||
if (m_desc.Pool != D3DPOOL_DEFAULT)
|
if (m_desc.Pool != D3DPOOL_DEFAULT)
|
||||||
m_dirtyRange = D3D9Range(0, m_desc.Size);
|
m_dirtyRange = D3D9Range(0, m_desc.Size);
|
||||||
|
@ -133,17 +133,13 @@ namespace dxvk {
|
|||||||
return DxvkBufferSlice();
|
return DxvkBufferSlice();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline DxvkBufferSliceHandle AllocMapSlice() {
|
inline DxvkBufferAllocation DiscardMapSlice() {
|
||||||
return GetMapBuffer()->allocSlice();
|
m_allocation = GetMapBuffer()->allocateSlice();
|
||||||
|
return m_allocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline DxvkBufferSliceHandle DiscardMapSlice() {
|
inline DxvkBufferAllocation GetMappedSlice() const {
|
||||||
m_sliceHandle = GetMapBuffer()->allocSlice();
|
return m_allocation;
|
||||||
return m_sliceHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline DxvkBufferSliceHandle GetMappedSlice() const {
|
|
||||||
return m_sliceHandle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline DWORD GetMapFlags() const { return m_mapFlags; }
|
inline DWORD GetMapFlags() const { return m_mapFlags; }
|
||||||
@ -240,7 +236,7 @@ namespace dxvk {
|
|||||||
Rc<DxvkBuffer> m_buffer;
|
Rc<DxvkBuffer> m_buffer;
|
||||||
Rc<DxvkBuffer> m_stagingBuffer;
|
Rc<DxvkBuffer> m_stagingBuffer;
|
||||||
|
|
||||||
DxvkBufferSliceHandle m_sliceHandle;
|
DxvkBufferAllocation m_allocation;
|
||||||
|
|
||||||
D3D9Range m_dirtyRange;
|
D3D9Range m_dirtyRange;
|
||||||
|
|
||||||
|
@ -42,22 +42,20 @@ namespace dxvk {
|
|||||||
|
|
||||||
|
|
||||||
void* D3D9ConstantBuffer::Alloc(VkDeviceSize size) {
|
void* D3D9ConstantBuffer::Alloc(VkDeviceSize size) {
|
||||||
if (unlikely(m_buffer == nullptr)) {
|
if (unlikely(m_buffer == nullptr))
|
||||||
this->createBuffer();
|
m_slice = this->createBuffer();
|
||||||
m_slice = m_buffer->getSliceHandle();
|
|
||||||
}
|
|
||||||
|
|
||||||
size = align(size, m_align);
|
size = align(size, m_align);
|
||||||
|
|
||||||
if (unlikely(m_offset + size > m_size)) {
|
if (unlikely(m_offset + size > m_size)) {
|
||||||
m_slice = m_buffer->allocSlice();
|
m_slice = m_buffer->allocateSlice();
|
||||||
m_offset = 0;
|
m_offset = 0;
|
||||||
|
|
||||||
m_device->EmitCs([
|
m_device->EmitCs([
|
||||||
cBuffer = m_buffer,
|
cBuffer = m_buffer,
|
||||||
cSlice = m_slice
|
cSlice = m_slice
|
||||||
] (DxvkContext* ctx) {
|
] (DxvkContext* ctx) mutable {
|
||||||
ctx->invalidateBuffer(cBuffer, cSlice);
|
ctx->invalidateBuffer(cBuffer, std::move(cSlice));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +68,7 @@ namespace dxvk {
|
|||||||
ctx->bindUniformBufferRange(cStages, cBinding, cOffset, cLength);
|
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;
|
m_offset += size;
|
||||||
return mapPtr;
|
return mapPtr;
|
||||||
}
|
}
|
||||||
@ -78,22 +76,22 @@ namespace dxvk {
|
|||||||
|
|
||||||
void* D3D9ConstantBuffer::AllocSlice() {
|
void* D3D9ConstantBuffer::AllocSlice() {
|
||||||
if (unlikely(m_buffer == nullptr))
|
if (unlikely(m_buffer == nullptr))
|
||||||
this->createBuffer();
|
m_slice = this->createBuffer();
|
||||||
|
else
|
||||||
m_slice = m_buffer->allocSlice();
|
m_slice = m_buffer->allocateSlice();
|
||||||
|
|
||||||
m_device->EmitCs([
|
m_device->EmitCs([
|
||||||
cBuffer = m_buffer,
|
cBuffer = m_buffer,
|
||||||
cSlice = m_slice
|
cSlice = m_slice
|
||||||
] (DxvkContext* ctx) {
|
] (DxvkContext* ctx) mutable {
|
||||||
ctx->invalidateBuffer(cBuffer, cSlice);
|
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();
|
auto options = m_device->GetOptions();
|
||||||
|
|
||||||
// Buffer usage and access flags don't make much of a difference
|
// Buffer usage and access flags don't make much of a difference
|
||||||
@ -125,6 +123,8 @@ namespace dxvk {
|
|||||||
] (DxvkContext* ctx) mutable {
|
] (DxvkContext* ctx) mutable {
|
||||||
ctx->bindUniformBuffer(cStages, cBinding, std::move(cSlice));
|
ctx->bindUniformBuffer(cStages, cBinding, std::move(cSlice));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return m_buffer->getAllocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,9 +74,9 @@ namespace dxvk {
|
|||||||
VkDeviceSize m_offset = 0ull;
|
VkDeviceSize m_offset = 0ull;
|
||||||
|
|
||||||
Rc<DxvkBuffer> m_buffer = nullptr;
|
Rc<DxvkBuffer> m_buffer = nullptr;
|
||||||
DxvkBufferSliceHandle m_slice = { };
|
DxvkBufferAllocation m_slice = { };
|
||||||
|
|
||||||
void createBuffer();
|
DxvkBufferAllocation createBuffer();
|
||||||
|
|
||||||
VkDeviceSize getAlignment(const Rc<DxvkDevice>& device) const;
|
VkDeviceSize getAlignment(const Rc<DxvkDevice>& device) const;
|
||||||
|
|
||||||
|
@ -4386,16 +4386,16 @@ namespace dxvk {
|
|||||||
VkDeviceSize alignedSize = align(size, CACHE_LINE_SIZE);
|
VkDeviceSize alignedSize = align(size, CACHE_LINE_SIZE);
|
||||||
|
|
||||||
if (unlikely(m_upBufferOffset + alignedSize > UPBufferSize)) {
|
if (unlikely(m_upBufferOffset + alignedSize > UPBufferSize)) {
|
||||||
auto sliceHandle = m_upBuffer->allocSlice();
|
auto slice = m_upBuffer->allocateSlice();
|
||||||
|
|
||||||
m_upBufferOffset = 0;
|
m_upBufferOffset = 0;
|
||||||
m_upBufferMapPtr = sliceHandle.mapPtr;
|
m_upBufferMapPtr = slice.mapPtr();
|
||||||
|
|
||||||
EmitCs([
|
EmitCs([
|
||||||
cBuffer = m_upBuffer,
|
cBuffer = m_upBuffer,
|
||||||
cSlice = sliceHandle
|
cSlice = std::move(slice)
|
||||||
] (DxvkContext* ctx) {
|
] (DxvkContext* ctx) mutable {
|
||||||
ctx->invalidateBuffer(cBuffer, cSlice);
|
ctx->invalidateBuffer(cBuffer, std::move(cSlice));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5128,19 +5128,20 @@ namespace dxvk {
|
|||||||
|
|
||||||
Rc<DxvkBuffer> mappingBuffer = pResource->GetBuffer<D3D9_COMMON_BUFFER_TYPE_MAPPING>();
|
Rc<DxvkBuffer> mappingBuffer = pResource->GetBuffer<D3D9_COMMON_BUFFER_TYPE_MAPPING>();
|
||||||
|
|
||||||
DxvkBufferSliceHandle physSlice;
|
uint8_t* data = nullptr;
|
||||||
|
|
||||||
if ((Flags & D3DLOCK_DISCARD) && (directMapping || needsReadback)) {
|
if ((Flags & D3DLOCK_DISCARD) && (directMapping || needsReadback)) {
|
||||||
// Allocate a new backing slice for the buffer and set
|
// Allocate a new backing slice for the buffer and set
|
||||||
// it as the 'new' mapped slice. This assumes that the
|
// it as the 'new' mapped slice. This assumes that the
|
||||||
// only way to invalidate a buffer is by mapping it.
|
// 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([
|
EmitCs([
|
||||||
cBuffer = std::move(mappingBuffer),
|
cBuffer = std::move(mappingBuffer),
|
||||||
cBufferSlice = physSlice
|
cBufferSlice = std::move(bufferSlice)
|
||||||
] (DxvkContext* ctx) {
|
] (DxvkContext* ctx) mutable {
|
||||||
ctx->invalidateBuffer(cBuffer, cBufferSlice);
|
ctx->invalidateBuffer(cBuffer, std::move(cBufferSlice));
|
||||||
});
|
});
|
||||||
|
|
||||||
pResource->SetNeedsReadback(false);
|
pResource->SetNeedsReadback(false);
|
||||||
@ -5149,7 +5150,7 @@ namespace dxvk {
|
|||||||
// Use map pointer from previous map operation. This
|
// Use map pointer from previous map operation. This
|
||||||
// way we don't have to synchronize with the CS thread
|
// way we don't have to synchronize with the CS thread
|
||||||
// if the map mode is D3DLOCK_NOOVERWRITE.
|
// 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 needsReadback = pResource->NeedsReadback();
|
||||||
const bool readOnly = Flags & D3DLOCK_READONLY;
|
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.
|
// The offset/size is not clamped to or affected by the desc size.
|
||||||
data += OffsetToLock;
|
data += OffsetToLock;
|
||||||
|
|
||||||
@ -5197,7 +5197,7 @@ namespace dxvk {
|
|||||||
D3D9Range& range = pResource->DirtyRange();
|
D3D9Range& range = pResource->DirtyRange();
|
||||||
|
|
||||||
D3D9BufferSlice slice = AllocStagingBuffer(range.max - range.min);
|
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);
|
memcpy(slice.mapPtr, srcData, range.max - range.min);
|
||||||
|
|
||||||
EmitCs([
|
EmitCs([
|
||||||
@ -5379,7 +5379,7 @@ namespace dxvk {
|
|||||||
if (likely(copy.copyBufferLength != 0)) {
|
if (likely(copy.copyBufferLength != 0)) {
|
||||||
const auto* vbo = GetCommonBuffer(m_state.vertexBuffers[i].vertexBuffer);
|
const auto* vbo = GetCommonBuffer(m_state.vertexBuffers[i].vertexBuffer);
|
||||||
uint8_t* data = reinterpret_cast<uint8_t*>(upSlice.mapPtr) + copy.dstOffset;
|
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)) {
|
if (likely(copy.copyElementStride == copy.copyElementSize)) {
|
||||||
std::memcpy(data, src, copy.copyBufferLength);
|
std::memcpy(data, src, copy.copyBufferLength);
|
||||||
@ -5428,7 +5428,7 @@ namespace dxvk {
|
|||||||
VkIndexType indexType = DecodeIndexType(ibo->Desc()->Format);
|
VkIndexType indexType = DecodeIndexType(ibo->Desc()->Format);
|
||||||
uint32_t offset = indexStride * FirstIndex;
|
uint32_t offset = indexStride * FirstIndex;
|
||||||
uint8_t* data = reinterpret_cast<uint8_t*>(upSlice.mapPtr) + iboUPBufferOffset;
|
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);
|
std::memcpy(data, src, iboUPBufferSize);
|
||||||
|
|
||||||
auto iboSlice = upSlice.slice.subSlice(iboUPBufferOffset, iboUPBufferSize);
|
auto iboSlice = upSlice.slice.subSlice(iboUPBufferOffset, iboUPBufferSize);
|
||||||
|
Loading…
Reference in New Issue
Block a user