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

[d3d11] Lock buffers in place when used with CUDA interop

This commit is contained in:
Philip Rebohle 2024-09-29 15:23:27 +02:00 committed by Philip Rebohle
parent 11f8dc0818
commit c26c21edb4
2 changed files with 16 additions and 17 deletions

View File

@ -82,6 +82,10 @@ namespace dxvk {
info.access |= VK_ACCESS_HOST_WRITE_BIT;
}
// Always enable BDA usage if available so that CUDA interop can work
if (m_parent->GetDXVKDevice()->features().vk12.bufferDeviceAddress)
info.usage |= VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT;
if (p11on12Info) {
m_11on12 = *p11on12Info;
@ -92,9 +96,6 @@ namespace dxvk {
if (m_desc.CPUAccessFlags)
m_11on12.Resource->Map(0, nullptr, &importInfo.mapPtr);
// D3D12 will always have BDA enabled
info.usage |= VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT;
m_buffer = m_parent->GetDXVKDevice()->importBuffer(info, importInfo, GetMemoryFlags());
m_mapPtr = m_buffer->mapPtr(0);
@ -103,12 +104,6 @@ namespace dxvk {
VkMemoryPropertyFlags memoryFlags = GetMemoryFlags();
m_mapMode = DetermineMapMode(memoryFlags);
// Prevent buffer renaming for buffers that are not mappable, so
// that interop interfaces can safely query the GPU address.
if (m_mapMode == D3D11_COMMON_BUFFER_MAP_MODE_NONE
&& m_parent->GetDXVKDevice()->features().vk12.bufferDeviceAddress)
info.usage |= VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT;
// Create the buffer and set the entire buffer slice as mapped,
// so that we only have to update it when invalidating the buffer
m_buffer = m_parent->GetDXVKDevice()->createBuffer(info, memoryFlags);

View File

@ -2621,16 +2621,20 @@ namespace dxvk {
*gpuVAStart = imageViewAddressProperties.deviceAddress;
*gpuVASize = imageViewAddressProperties.size;
} else if (resourceDesc.Dim == D3D11_RESOURCE_DIMENSION_BUFFER) {
D3D11Buffer *buffer = GetCommonBuffer(pResource);
const DxvkBufferSliceHandle bufSliceHandle = buffer->GetBuffer()->getSliceHandle();
VkBuffer vkBuffer = bufSliceHandle.handle;
Rc<DxvkBuffer> dxvkBuffer = GetCommonBuffer(pResource)->GetBuffer();
VkBufferDeviceAddressInfo bdaInfo = { VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO };
bdaInfo.buffer = vkBuffer;
if (dxvkBuffer->canRelocate()) {
auto chunk = m_device->AllocCsChunk(DxvkCsChunkFlag::SingleUse);
VkDeviceAddress bufAddr = dxvkDevice->vkd()->vkGetBufferDeviceAddress(vkDevice, &bdaInfo);
*gpuVAStart = uint64_t(bufAddr) + bufSliceHandle.offset;
*gpuVASize = bufSliceHandle.length;
chunk->push([cBuffer = dxvkBuffer] (DxvkContext* ctx) {
ctx->ensureBufferAddress(cBuffer);
});
m_device->GetContext()->EmitCsChunkExternal(std::move(chunk), true);
}
*gpuVAStart = dxvkBuffer->gpuAddress();
*gpuVASize = dxvkBuffer->info().size;
} else {
Logger::warn(str::format("GetResourceHandleGPUVirtualAddressAndSize(): Unsupported resource type: ", resourceDesc.Dim));
return false;