diff --git a/src/d3d11/d3d11_buffer.cpp b/src/d3d11/d3d11_buffer.cpp index adddcb34..8f3ed95c 100644 --- a/src/d3d11/d3d11_buffer.cpp +++ b/src/d3d11/d3d11_buffer.cpp @@ -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); diff --git a/src/d3d11/d3d11_device.cpp b/src/d3d11/d3d11_device.cpp index 40e89b01..0902a473 100644 --- a/src/d3d11/d3d11_device.cpp +++ b/src/d3d11/d3d11_device.cpp @@ -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 = 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;