mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-05 01:24:14 +01:00
[d3d11] Lock buffers in place when used with CUDA interop
This commit is contained in:
parent
11f8dc0818
commit
c26c21edb4
@ -82,6 +82,10 @@ namespace dxvk {
|
|||||||
info.access |= VK_ACCESS_HOST_WRITE_BIT;
|
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) {
|
if (p11on12Info) {
|
||||||
m_11on12 = *p11on12Info;
|
m_11on12 = *p11on12Info;
|
||||||
|
|
||||||
@ -92,9 +96,6 @@ namespace dxvk {
|
|||||||
if (m_desc.CPUAccessFlags)
|
if (m_desc.CPUAccessFlags)
|
||||||
m_11on12.Resource->Map(0, nullptr, &importInfo.mapPtr);
|
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_buffer = m_parent->GetDXVKDevice()->importBuffer(info, importInfo, GetMemoryFlags());
|
||||||
m_mapPtr = m_buffer->mapPtr(0);
|
m_mapPtr = m_buffer->mapPtr(0);
|
||||||
|
|
||||||
@ -103,12 +104,6 @@ namespace dxvk {
|
|||||||
VkMemoryPropertyFlags memoryFlags = GetMemoryFlags();
|
VkMemoryPropertyFlags memoryFlags = GetMemoryFlags();
|
||||||
m_mapMode = DetermineMapMode(memoryFlags);
|
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,
|
// Create the buffer and set the entire buffer slice as mapped,
|
||||||
// so that we only have to update it when invalidating the buffer
|
// so that we only have to update it when invalidating the buffer
|
||||||
m_buffer = m_parent->GetDXVKDevice()->createBuffer(info, memoryFlags);
|
m_buffer = m_parent->GetDXVKDevice()->createBuffer(info, memoryFlags);
|
||||||
|
@ -2621,16 +2621,20 @@ namespace dxvk {
|
|||||||
*gpuVAStart = imageViewAddressProperties.deviceAddress;
|
*gpuVAStart = imageViewAddressProperties.deviceAddress;
|
||||||
*gpuVASize = imageViewAddressProperties.size;
|
*gpuVASize = imageViewAddressProperties.size;
|
||||||
} else if (resourceDesc.Dim == D3D11_RESOURCE_DIMENSION_BUFFER) {
|
} else if (resourceDesc.Dim == D3D11_RESOURCE_DIMENSION_BUFFER) {
|
||||||
D3D11Buffer *buffer = GetCommonBuffer(pResource);
|
Rc<DxvkBuffer> dxvkBuffer = GetCommonBuffer(pResource)->GetBuffer();
|
||||||
const DxvkBufferSliceHandle bufSliceHandle = buffer->GetBuffer()->getSliceHandle();
|
|
||||||
VkBuffer vkBuffer = bufSliceHandle.handle;
|
|
||||||
|
|
||||||
VkBufferDeviceAddressInfo bdaInfo = { VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO };
|
if (dxvkBuffer->canRelocate()) {
|
||||||
bdaInfo.buffer = vkBuffer;
|
auto chunk = m_device->AllocCsChunk(DxvkCsChunkFlag::SingleUse);
|
||||||
|
|
||||||
VkDeviceAddress bufAddr = dxvkDevice->vkd()->vkGetBufferDeviceAddress(vkDevice, &bdaInfo);
|
chunk->push([cBuffer = dxvkBuffer] (DxvkContext* ctx) {
|
||||||
*gpuVAStart = uint64_t(bufAddr) + bufSliceHandle.offset;
|
ctx->ensureBufferAddress(cBuffer);
|
||||||
*gpuVASize = bufSliceHandle.length;
|
});
|
||||||
|
|
||||||
|
m_device->GetContext()->EmitCsChunkExternal(std::move(chunk), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
*gpuVAStart = dxvkBuffer->gpuAddress();
|
||||||
|
*gpuVASize = dxvkBuffer->info().size;
|
||||||
} else {
|
} else {
|
||||||
Logger::warn(str::format("GetResourceHandleGPUVirtualAddressAndSize(): Unsupported resource type: ", resourceDesc.Dim));
|
Logger::warn(str::format("GetResourceHandleGPUVirtualAddressAndSize(): Unsupported resource type: ", resourceDesc.Dim));
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user