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

[dxvk] Add functions to lock in and query GPU buffer addresses

This commit is contained in:
Philip Rebohle 2024-09-29 15:21:19 +02:00 committed by Philip Rebohle
parent 9f0bd8e17f
commit 11f8dc0818
4 changed files with 43 additions and 3 deletions

View File

@ -48,9 +48,8 @@ namespace dxvk {
bool DxvkBuffer::canRelocate() const { bool DxvkBuffer::canRelocate() const {
return !m_storage->flags().test(DxvkAllocationFlag::Imported) return !m_bufferInfo.mapPtr && !m_stableAddress
&& !m_bufferInfo.mapPtr && !m_storage->flags().test(DxvkAllocationFlag::Imported)
&& !(m_info.usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT)
&& !(m_info.flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT); && !(m_info.flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT);
} }

View File

@ -210,6 +210,16 @@ namespace dxvk {
: nullptr; : nullptr;
} }
/**
* \brief GPU address
*
* May be 0 if the device address usage flag is not
* enabled for this buffer.
*/
VkDeviceAddress gpuAddress() const {
return m_bufferInfo.gpuAddress;
}
/** /**
* \brief Queries shader stages that can access this buffer * \brief Queries shader stages that can access this buffer
* *
@ -350,6 +360,16 @@ namespace dxvk {
*/ */
bool canRelocate() const; bool canRelocate() const;
/**
* \brief Enables stable GPU address
*
* Subsequent calls to \c canRelocate will be \c false, preventing
* the buffer from being relocated or invalidated by the backend.
*/
void enableStableAddress() {
m_stableAddress = true;
}
/** /**
* \brief Creates or retrieves a buffer view * \brief Creates or retrieves a buffer view
* *
@ -377,6 +397,8 @@ namespace dxvk {
uint32_t m_xfbStride = 0u; uint32_t m_xfbStride = 0u;
uint32_t m_version = 0u; uint32_t m_version = 0u;
bool m_stableAddress = false;
DxvkResourceBufferInfo m_bufferInfo = { }; DxvkResourceBufferInfo m_bufferInfo = { };
Rc<DxvkResourceAllocation> m_storage; Rc<DxvkResourceAllocation> m_storage;

View File

@ -1894,6 +1894,13 @@ namespace dxvk {
} }
void DxvkContext::ensureBufferAddress(
const Rc<DxvkBuffer>& buffer) {
// Really nothing else to do here but set the flag
buffer->enableStableAddress();
}
void DxvkContext::invalidateImage( void DxvkContext::invalidateImage(
const Rc<DxvkImage>& image, const Rc<DxvkImage>& image,
Rc<DxvkResourceAllocation>&& slice) { Rc<DxvkResourceAllocation>&& slice) {

View File

@ -962,6 +962,18 @@ namespace dxvk {
const Rc<DxvkBuffer>& buffer, const Rc<DxvkBuffer>& buffer,
Rc<DxvkResourceAllocation>&& slice); Rc<DxvkResourceAllocation>&& slice);
/**
* \brief Ensures that buffer will not be relocated
*
* This guarantees that the buffer's GPU address remains the same
* throughout its lifetime. Only prevents implicit invalidation or
* relocation by the backend, client APIs must take care to respect
* this too.
* \param [in] buffer Buffer to lock in place
*/
void ensureBufferAddress(
const Rc<DxvkBuffer>& buffer);
/** /**
* \brief Invalidates image content * \brief Invalidates image content
* *