mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-20 19:54:19 +01:00
[dxvk] Remove DxvkPhysicalBuffer and friends
This commit is contained in:
parent
8b5db80fbd
commit
9faf841f32
@ -3,11 +3,54 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "dxvk_buffer_res.h"
|
||||
#include "dxvk_descriptor.h"
|
||||
#include "dxvk_format.h"
|
||||
#include "dxvk_hash.h"
|
||||
#include "dxvk_memory.h"
|
||||
#include "dxvk_resource.h"
|
||||
|
||||
namespace dxvk {
|
||||
|
||||
/**
|
||||
* \brief Buffer create info
|
||||
*
|
||||
* The properties of a buffer that are
|
||||
* passed to \ref DxvkDevice::createBuffer
|
||||
*/
|
||||
struct DxvkBufferCreateInfo {
|
||||
/// Size of the buffer, in bytes
|
||||
VkDeviceSize size;
|
||||
|
||||
/// Buffer usage flags
|
||||
VkBufferUsageFlags usage;
|
||||
|
||||
/// Pipeline stages that can access
|
||||
/// the contents of the buffer.
|
||||
VkPipelineStageFlags stages;
|
||||
|
||||
/// Allowed access patterns
|
||||
VkAccessFlags access;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \brief Buffer view create info
|
||||
*
|
||||
* The properties of a buffer view that
|
||||
* are to \ref DxvkDevice::createBufferView
|
||||
*/
|
||||
struct DxvkBufferViewCreateInfo {
|
||||
/// Buffer data format, like image data
|
||||
VkFormat format;
|
||||
|
||||
/// Offset of the buffer region to include in the view
|
||||
VkDeviceSize rangeOffset;
|
||||
|
||||
/// Size of the buffer region to include in the view
|
||||
VkDeviceSize rangeLength;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \brief Buffer info
|
||||
*
|
||||
|
@ -1,100 +0,0 @@
|
||||
#include "dxvk_buffer_res.h"
|
||||
|
||||
namespace dxvk {
|
||||
|
||||
DxvkPhysicalBuffer::DxvkPhysicalBuffer(
|
||||
const Rc<vk::DeviceFn>& vkd,
|
||||
const DxvkBufferCreateInfo& createInfo,
|
||||
DxvkMemoryAllocator& memAlloc,
|
||||
VkMemoryPropertyFlags memFlags)
|
||||
: m_vkd(vkd) {
|
||||
|
||||
VkBufferCreateInfo info;
|
||||
info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
||||
info.pNext = nullptr;
|
||||
info.flags = 0;
|
||||
info.size = createInfo.size;
|
||||
info.usage = createInfo.usage;
|
||||
info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
info.queueFamilyIndexCount = 0;
|
||||
info.pQueueFamilyIndices = nullptr;
|
||||
|
||||
if (m_vkd->vkCreateBuffer(m_vkd->device(),
|
||||
&info, nullptr, &m_handle) != VK_SUCCESS) {
|
||||
throw DxvkError(str::format(
|
||||
"DxvkPhysicalBuffer: Failed to create buffer:"
|
||||
"\n size: ", info.size,
|
||||
"\n usage: ", info.usage));
|
||||
}
|
||||
|
||||
VkMemoryDedicatedRequirementsKHR dedicatedRequirements;
|
||||
dedicatedRequirements.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR;
|
||||
dedicatedRequirements.pNext = VK_NULL_HANDLE;
|
||||
dedicatedRequirements.prefersDedicatedAllocation = VK_FALSE;
|
||||
dedicatedRequirements.requiresDedicatedAllocation = VK_FALSE;
|
||||
|
||||
VkMemoryRequirements2KHR memReq;
|
||||
memReq.sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR;
|
||||
memReq.pNext = &dedicatedRequirements;
|
||||
|
||||
VkBufferMemoryRequirementsInfo2KHR memReqInfo;
|
||||
memReqInfo.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2_KHR;
|
||||
memReqInfo.buffer = m_handle;
|
||||
memReqInfo.pNext = VK_NULL_HANDLE;
|
||||
|
||||
VkMemoryDedicatedAllocateInfoKHR dedMemoryAllocInfo;
|
||||
dedMemoryAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR;
|
||||
dedMemoryAllocInfo.pNext = VK_NULL_HANDLE;
|
||||
dedMemoryAllocInfo.buffer = m_handle;
|
||||
dedMemoryAllocInfo.image = VK_NULL_HANDLE;
|
||||
|
||||
m_vkd->vkGetBufferMemoryRequirements2KHR(
|
||||
m_vkd->device(), &memReqInfo, &memReq);
|
||||
|
||||
bool useDedicated = dedicatedRequirements.prefersDedicatedAllocation;
|
||||
m_memory = memAlloc.alloc(&memReq.memoryRequirements,
|
||||
useDedicated ? &dedMemoryAllocInfo : nullptr, memFlags);
|
||||
|
||||
if (m_vkd->vkBindBufferMemory(m_vkd->device(), m_handle,
|
||||
m_memory.memory(), m_memory.offset()) != VK_SUCCESS)
|
||||
throw DxvkError("DxvkPhysicalBuffer: Failed to bind device memory");
|
||||
}
|
||||
|
||||
|
||||
DxvkPhysicalBuffer::~DxvkPhysicalBuffer() {
|
||||
if (m_handle != VK_NULL_HANDLE)
|
||||
m_vkd->vkDestroyBuffer(m_vkd->device(), m_handle, nullptr);
|
||||
}
|
||||
|
||||
|
||||
DxvkPhysicalBufferView::DxvkPhysicalBufferView(
|
||||
const Rc<vk::DeviceFn>& vkd,
|
||||
const DxvkPhysicalBufferSlice& slice,
|
||||
const DxvkBufferViewCreateInfo& info)
|
||||
: m_vkd(vkd), m_slice(slice.subSlice(info.rangeOffset, info.rangeLength)) {
|
||||
VkBufferViewCreateInfo viewInfo;
|
||||
viewInfo.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
|
||||
viewInfo.pNext = nullptr;
|
||||
viewInfo.flags = 0;
|
||||
viewInfo.buffer = m_slice.handle();
|
||||
viewInfo.format = info.format;
|
||||
viewInfo.offset = m_slice.offset();
|
||||
viewInfo.range = m_slice.length();
|
||||
|
||||
if (m_vkd->vkCreateBufferView(m_vkd->device(),
|
||||
&viewInfo, nullptr, &m_view) != VK_SUCCESS) {
|
||||
throw DxvkError(str::format(
|
||||
"DxvkPhysicalBufferView: Failed to create buffer view:",
|
||||
"\n Offset: ", viewInfo.offset,
|
||||
"\n Range: ", viewInfo.range,
|
||||
"\n Format: ", viewInfo.format));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DxvkPhysicalBufferView::~DxvkPhysicalBufferView() {
|
||||
m_vkd->vkDestroyBufferView(
|
||||
m_vkd->device(), m_view, nullptr);
|
||||
}
|
||||
|
||||
}
|
@ -1,275 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "dxvk_descriptor.h"
|
||||
#include "dxvk_format.h"
|
||||
#include "dxvk_memory.h"
|
||||
#include "dxvk_resource.h"
|
||||
|
||||
namespace dxvk {
|
||||
|
||||
/**
|
||||
* \brief Buffer create info
|
||||
*
|
||||
* The properties of a buffer that are
|
||||
* passed to \ref DxvkDevice::createBuffer
|
||||
*/
|
||||
struct DxvkBufferCreateInfo {
|
||||
/// Size of the buffer, in bytes
|
||||
VkDeviceSize size;
|
||||
|
||||
/// Buffer usage flags
|
||||
VkBufferUsageFlags usage;
|
||||
|
||||
/// Pipeline stages that can access
|
||||
/// the contents of the buffer.
|
||||
VkPipelineStageFlags stages;
|
||||
|
||||
/// Allowed access patterns
|
||||
VkAccessFlags access;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \brief Buffer view create info
|
||||
*
|
||||
* The properties of a buffer view that
|
||||
* are to \ref DxvkDevice::createBufferView
|
||||
*/
|
||||
struct DxvkBufferViewCreateInfo {
|
||||
/// Buffer data format, like image data
|
||||
VkFormat format;
|
||||
|
||||
/// Offset of the buffer region to include in the view
|
||||
VkDeviceSize rangeOffset;
|
||||
|
||||
/// Size of the buffer region to include in the view
|
||||
VkDeviceSize rangeLength;
|
||||
};
|
||||
|
||||
|
||||
class DxvkPhysicalBuffer;
|
||||
class DxvkPhysicalBufferSlice;
|
||||
|
||||
|
||||
/**
|
||||
* \brief Physical buffer
|
||||
*
|
||||
* A physical buffer is used as a backing resource for
|
||||
* a virtual buffer. See \ref DxvkBuffer as for why
|
||||
* this separation is necessary.
|
||||
*/
|
||||
class DxvkPhysicalBuffer : public DxvkResource {
|
||||
|
||||
public:
|
||||
|
||||
DxvkPhysicalBuffer(
|
||||
const Rc<vk::DeviceFn>& vkd,
|
||||
const DxvkBufferCreateInfo& createInfo,
|
||||
DxvkMemoryAllocator& memAlloc,
|
||||
VkMemoryPropertyFlags memFlags);
|
||||
|
||||
~DxvkPhysicalBuffer();
|
||||
|
||||
/**
|
||||
* \brief Vulkan buffer handle
|
||||
* \returns Vulkan buffer handle
|
||||
*/
|
||||
VkBuffer handle() const {
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Map pointer
|
||||
*
|
||||
* Retrieves a pointer into the mapped memory region
|
||||
* of the buffer, relative to the start of the buffer.
|
||||
* \param [in] offset Offset into the buffer
|
||||
* \returns Pointer into the mapped memory region
|
||||
*/
|
||||
void* mapPtr(VkDeviceSize offset) const {
|
||||
return m_memory.mapPtr(offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Retrieves a physical buffer slice
|
||||
*
|
||||
* \param [in] offset Slice offset
|
||||
* \param [in] length Slice length
|
||||
* \returns The physical slice
|
||||
*/
|
||||
DxvkPhysicalBufferSlice slice(
|
||||
VkDeviceSize offset,
|
||||
VkDeviceSize length);
|
||||
|
||||
private:
|
||||
|
||||
Rc<vk::DeviceFn> m_vkd;
|
||||
DxvkMemory m_memory;
|
||||
VkBuffer m_handle;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \brief Physical buffer slice
|
||||
*
|
||||
* A slice into a physical buffer, which stores
|
||||
* the buffer and the offset into the buffer.
|
||||
*/
|
||||
class DxvkPhysicalBufferSlice {
|
||||
|
||||
public:
|
||||
|
||||
DxvkPhysicalBufferSlice() { }
|
||||
DxvkPhysicalBufferSlice(
|
||||
const Rc<DxvkPhysicalBuffer>& buffer,
|
||||
VkDeviceSize offset,
|
||||
VkDeviceSize length)
|
||||
: m_buffer(buffer),
|
||||
m_offset(offset),
|
||||
m_length(length) { }
|
||||
|
||||
/**
|
||||
* \brief Buffer handle
|
||||
* \returns Buffer handle
|
||||
*/
|
||||
VkBuffer handle() const {
|
||||
return m_buffer != nullptr
|
||||
? m_buffer->handle()
|
||||
: VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Slice offset
|
||||
*
|
||||
* Offset of the slice into
|
||||
* the underlying buffer.
|
||||
* \returns Slice offset
|
||||
*/
|
||||
VkDeviceSize offset() const {
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Slice length
|
||||
*
|
||||
* Number of bytes in the slice.
|
||||
* \returns Slice length, in bytes
|
||||
*/
|
||||
VkDeviceSize length() const {
|
||||
return m_length;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sub slice into the physical buffer
|
||||
*
|
||||
* \param [in] offset Offset, relative to this slice
|
||||
* \param [in] length Number of bytes of the sub slice
|
||||
* \returns The sub slice
|
||||
*/
|
||||
DxvkPhysicalBufferSlice subSlice(VkDeviceSize offset, VkDeviceSize length) const {
|
||||
return DxvkPhysicalBufferSlice(m_buffer, m_offset + offset, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Map pointer
|
||||
*
|
||||
* Retrieves a pointer into the mapped memory
|
||||
* region of the underlying buffer, relative
|
||||
* to the slice's offset.
|
||||
* \param [in] offset Offset into the slice
|
||||
* \returns Pointer to the mapped memory region
|
||||
*/
|
||||
void* mapPtr(VkDeviceSize offset) const {
|
||||
return m_buffer->mapPtr(m_offset + offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief The buffer resource
|
||||
* \returns Buffer resource
|
||||
*/
|
||||
Rc<DxvkResource> resource() const {
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Checks whether this slice overlaps with another
|
||||
*
|
||||
* \param [in] other The buffer slice to check
|
||||
* \returns \c true if the two slices overlap
|
||||
*/
|
||||
bool overlaps(const DxvkPhysicalBufferSlice& other) const {
|
||||
return this->m_buffer == other.m_buffer
|
||||
&& this->m_offset + this->m_length > other.m_offset
|
||||
&& this->m_offset < other.m_offset + other.m_length;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Rc<DxvkPhysicalBuffer> m_buffer = nullptr;
|
||||
VkDeviceSize m_offset = 0;
|
||||
VkDeviceSize m_length = 0;
|
||||
|
||||
};
|
||||
|
||||
inline DxvkPhysicalBufferSlice DxvkPhysicalBuffer::slice(
|
||||
VkDeviceSize offset,
|
||||
VkDeviceSize length) {
|
||||
return DxvkPhysicalBufferSlice(this, offset, length);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Physical buffer view
|
||||
*
|
||||
* Manages a texel buffer view for a physical
|
||||
* buffer slice, which is used as the backing
|
||||
* resource of a \c DxvkBufferView.
|
||||
*/
|
||||
class DxvkPhysicalBufferView : public DxvkResource {
|
||||
|
||||
public:
|
||||
|
||||
DxvkPhysicalBufferView(
|
||||
const Rc<vk::DeviceFn>& vkd,
|
||||
const DxvkPhysicalBufferSlice& slice,
|
||||
const DxvkBufferViewCreateInfo& info);
|
||||
|
||||
~DxvkPhysicalBufferView();
|
||||
|
||||
/**
|
||||
* \brief Vulkan buffer view handle
|
||||
* \returns Vulkan buffer view handle
|
||||
*/
|
||||
VkBufferView handle() const {
|
||||
return m_view;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Physical buffer slice
|
||||
*
|
||||
* The slice backing this buffer view.
|
||||
* \returns Physical buffer slice
|
||||
*/
|
||||
DxvkPhysicalBufferSlice slice() const {
|
||||
return m_slice;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Physical buffer resource
|
||||
* \returns Resource pointer
|
||||
*/
|
||||
Rc<DxvkResource> bufferResource() const {
|
||||
return m_slice.resource();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Rc<vk::DeviceFn> m_vkd;
|
||||
DxvkPhysicalBufferSlice m_slice;
|
||||
|
||||
VkBufferView m_view = VK_NULL_HANDLE;
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -43,7 +43,6 @@ dxvk_src = files([
|
||||
'dxvk_adapter.cpp',
|
||||
'dxvk_barrier.cpp',
|
||||
'dxvk_buffer.cpp',
|
||||
'dxvk_buffer_res.cpp',
|
||||
'dxvk_cmdlist.cpp',
|
||||
'dxvk_compute.cpp',
|
||||
'dxvk_context.cpp',
|
||||
|
Loading…
x
Reference in New Issue
Block a user