vkd3d: Use VK_KHR_bind_memory2

Mesa RADV translates these legacy entrypoints to the 2 variants. Using
them directly will cost a bit less CPU cycles.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
This commit is contained in:
Samuel Pitoiset 2022-01-10 10:18:41 +01:00 committed by Hans-Kristian Arntzen
parent b42a7193fc
commit 870dda927d
4 changed files with 48 additions and 11 deletions

View File

@ -471,6 +471,7 @@ static HRESULT vkd3d_memory_allocation_init(struct vkd3d_memory_allocation *allo
VkMemoryRequirements memory_requirements;
VkMemoryAllocateFlagsInfo flags_info;
VkMemoryPropertyFlags type_flags;
VkBindBufferMemoryInfo bind_info;
void *host_ptr = info->host_ptr;
uint32_t type_mask;
VkResult vr;
@ -599,8 +600,13 @@ static HRESULT vkd3d_memory_allocation_init(struct vkd3d_memory_allocation *allo
/* Bind memory to global or dedicated buffer as needed */
if (allocation->resource.vk_buffer)
{
if ((vr = VK_CALL(vkBindBufferMemory(device->vk_device,
allocation->resource.vk_buffer, allocation->device_allocation.vk_memory, 0))) < 0)
bind_info.sType = VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO;
bind_info.pNext = NULL;
bind_info.buffer = allocation->resource.vk_buffer;
bind_info.memory = allocation->device_allocation.vk_memory;
bind_info.memoryOffset = 0;
if ((vr = VK_CALL(vkBindBufferMemory2KHR(device->vk_device, 1, &bind_info))) < 0)
{
ERR("Failed to bind buffer memory, vr %d.\n", vr);
vkd3d_memory_allocation_free(allocation, device, allocator);
@ -1454,6 +1460,7 @@ HRESULT vkd3d_allocate_buffer_memory(struct d3d12_device *device, VkBuffer vk_bu
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
VkMemoryRequirements memory_requirements;
VkMemoryAllocateFlagsInfo flags_info;
VkBindBufferMemoryInfo bind_info;
VkResult vr;
HRESULT hr;
@ -1470,7 +1477,13 @@ HRESULT vkd3d_allocate_buffer_memory(struct d3d12_device *device, VkBuffer vk_bu
type_flags, memory_requirements.memoryTypeBits, &flags_info, allocation)))
return hr;
if (FAILED(vr = VK_CALL(vkBindBufferMemory(device->vk_device, vk_buffer, allocation->vk_memory, 0))))
bind_info.sType = VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO;
bind_info.pNext = NULL;
bind_info.buffer = vk_buffer;
bind_info.memory = allocation->vk_memory;
bind_info.memoryOffset = 0;
if (FAILED(vr = VK_CALL(vkBindBufferMemory2KHR(device->vk_device, 1, &bind_info))))
return hresult_from_vk_result(vr);
return hr;
@ -1482,6 +1495,7 @@ HRESULT vkd3d_allocate_image_memory(struct d3d12_device *device, VkImage vk_imag
{
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
VkMemoryRequirements memory_requirements;
VkBindImageMemoryInfo bind_info;
VkResult vr;
HRESULT hr;
@ -1491,7 +1505,13 @@ HRESULT vkd3d_allocate_image_memory(struct d3d12_device *device, VkImage vk_imag
type_flags, memory_requirements.memoryTypeBits, NULL, allocation)))
return hr;
if (FAILED(vr = VK_CALL(vkBindImageMemory(device->vk_device, vk_image, allocation->vk_memory, 0))))
bind_info.sType = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO;
bind_info.pNext = NULL;
bind_info.image = vk_image;
bind_info.memory = allocation->vk_memory;
bind_info.memoryOffset = 0;
if (FAILED(vr = VK_CALL(vkBindImageMemory2KHR(device->vk_device, 1, &bind_info))))
return hresult_from_vk_result(vr);
return hr;

View File

@ -2650,6 +2650,7 @@ HRESULT d3d12_resource_create_committed(struct d3d12_device *device, const D3D12
VkMemoryDedicatedAllocateInfo dedicated_info;
VkImageMemoryRequirementsInfo2 image_info;
VkMemoryRequirements2 memory_requirements;
VkBindImageMemoryInfo bind_info;
bool use_dedicated_allocation;
VkResult vr;
@ -2705,8 +2706,13 @@ HRESULT d3d12_resource_create_committed(struct d3d12_device *device, const D3D12
if (FAILED(hr = vkd3d_allocate_memory(device, &device->memory_allocator, &allocate_info, &object->mem)))
goto fail;
if ((vr = VK_CALL(vkBindImageMemory(device->vk_device, object->res.vk_image,
object->mem.device_allocation.vk_memory, object->mem.offset))))
bind_info.sType = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO;
bind_info.pNext = NULL;
bind_info.image = object->res.vk_image;
bind_info.memory = object->mem.device_allocation.vk_memory;
bind_info.memoryOffset = object->mem.offset;
if ((vr = VK_CALL(vkBindImageMemory2KHR(device->vk_device, 1, &bind_info))))
{
ERR("Failed to bind image memory, vr %d.\n", vr);
hr = hresult_from_vk_result(vr);
@ -2779,6 +2785,7 @@ HRESULT d3d12_resource_create_placed(struct d3d12_device *device, const D3D12_RE
{
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
VkMemoryRequirements memory_requirements;
VkBindImageMemoryInfo bind_info;
struct d3d12_resource *object;
VkResult vr;
HRESULT hr;
@ -2838,8 +2845,13 @@ HRESULT d3d12_resource_create_placed(struct d3d12_device *device, const D3D12_RE
if (d3d12_resource_is_texture(object))
{
if ((vr = VK_CALL(vkBindImageMemory(device->vk_device, object->res.vk_image,
object->mem.device_allocation.vk_memory, object->mem.offset))) < 0)
bind_info.sType = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO;
bind_info.pNext = NULL;
bind_info.image = object->res.vk_image;
bind_info.memory = object->mem.device_allocation.vk_memory;
bind_info.memoryOffset = object->mem.offset;
if ((vr = VK_CALL(vkBindImageMemory2KHR(device->vk_device, 1, &bind_info))) < 0)
{
ERR("Failed to bind image memory, vr %d.\n", vr);
hr = hresult_from_vk_result(vr);

View File

@ -61,8 +61,6 @@ VK_DEVICE_PFN(vkAllocateCommandBuffers)
VK_DEVICE_PFN(vkAllocateDescriptorSets)
VK_DEVICE_PFN(vkAllocateMemory)
VK_DEVICE_PFN(vkBeginCommandBuffer)
VK_DEVICE_PFN(vkBindBufferMemory)
VK_DEVICE_PFN(vkBindImageMemory)
VK_DEVICE_PFN(vkCmdBeginQuery)
VK_DEVICE_PFN(vkCmdBeginRenderPass)
VK_DEVICE_PFN(vkCmdBindDescriptorSets)

View File

@ -823,6 +823,7 @@ static VkDeviceMemory allocate_vulkan_image_memory(ID3D12Device *device,
VkMemoryPropertyFlags required_flags, VkImage vk_image)
{
VkMemoryRequirements memory_requirements;
VkBindImageMemoryInfo bind_info;
VkDeviceMemory vk_memory;
VkDevice vk_device;
VkResult vr;
@ -832,7 +833,13 @@ static VkDeviceMemory allocate_vulkan_image_memory(ID3D12Device *device,
vkGetImageMemoryRequirements(vk_device, vk_image, &memory_requirements);
vk_memory = allocate_vulkan_device_memory(device, required_flags, &memory_requirements);
vr = vkBindImageMemory(vk_device, vk_image, vk_memory, 0);
bind_info.sType = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO;
bind_info.pNext = NULL;
bind_info.image = vk_image;
bind_info.memory = vk_memory;
bind_info.memoryOffset = 0;
vr = vkBindImageMemory2KHR(vk_device, 1, &bind_info);
ok(vr == VK_SUCCESS, "Got unexpected VkResult %d.\n", vr);
return vk_memory;