From 8dc8922af257e454f4460bbc5993df5647968146 Mon Sep 17 00:00:00 2001 From: Jonathan Marek Date: Tue, 29 Sep 2020 12:04:17 -0400 Subject: [PATCH] turnip: implement legacy API functions separately Move legacy API functions to a separate file, and implement them by calling the new API functions, like tu_CreateRenderPass was already doing. Signed-off-by: Jonathan Marek Part-of: --- src/freedreno/vulkan/meson.build | 1 + src/freedreno/vulkan/tu_cmd_buffer.c | 37 +--- src/freedreno/vulkan/tu_device.c | 167 +++------------- src/freedreno/vulkan/tu_formats.c | 52 ----- src/freedreno/vulkan/tu_legacy.c | 375 +++++++++++++++++++++++++++++++++++ src/freedreno/vulkan/tu_pass.c | 145 -------------- 6 files changed, 414 insertions(+), 363 deletions(-) create mode 100644 src/freedreno/vulkan/tu_legacy.c diff --git a/src/freedreno/vulkan/meson.build b/src/freedreno/vulkan/meson.build index f50375c..2dbcfd8 100644 --- a/src/freedreno/vulkan/meson.build +++ b/src/freedreno/vulkan/meson.build @@ -49,6 +49,7 @@ libtu_files = files( 'tu_descriptor_set.h', 'tu_formats.c', 'tu_image.c', + 'tu_legacy.c', 'tu_nir_lower_multiview.c', 'tu_pass.c', 'tu_pipeline.c', diff --git a/src/freedreno/vulkan/tu_cmd_buffer.c b/src/freedreno/vulkan/tu_cmd_buffer.c index 3d31231..9142c8c 100644 --- a/src/freedreno/vulkan/tu_cmd_buffer.c +++ b/src/freedreno/vulkan/tu_cmd_buffer.c @@ -2881,9 +2881,9 @@ tu_subpass_barrier(struct tu_cmd_buffer *cmd_buffer, } void -tu_CmdBeginRenderPass(VkCommandBuffer commandBuffer, - const VkRenderPassBeginInfo *pRenderPassBegin, - VkSubpassContents contents) +tu_CmdBeginRenderPass2(VkCommandBuffer commandBuffer, + const VkRenderPassBeginInfo *pRenderPassBegin, + const VkSubpassBeginInfo *pSubpassBeginInfo) { TU_FROM_HANDLE(tu_cmd_buffer, cmd, commandBuffer); TU_FROM_HANDLE(tu_render_pass, pass, pRenderPassBegin->renderPass); @@ -2918,16 +2918,9 @@ tu_CmdBeginRenderPass(VkCommandBuffer commandBuffer, } void -tu_CmdBeginRenderPass2(VkCommandBuffer commandBuffer, - const VkRenderPassBeginInfo *pRenderPassBeginInfo, - const VkSubpassBeginInfoKHR *pSubpassBeginInfo) -{ - tu_CmdBeginRenderPass(commandBuffer, pRenderPassBeginInfo, - pSubpassBeginInfo->contents); -} - -void -tu_CmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) +tu_CmdNextSubpass2(VkCommandBuffer commandBuffer, + const VkSubpassBeginInfo *pSubpassBeginInfo, + const VkSubpassEndInfo *pSubpassEndInfo) { TU_FROM_HANDLE(tu_cmd_buffer, cmd, commandBuffer); const struct tu_render_pass *pass = cmd->state.pass; @@ -2980,14 +2973,6 @@ tu_CmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) tu_set_input_attachments(cmd, cmd->state.subpass); } -void -tu_CmdNextSubpass2(VkCommandBuffer commandBuffer, - const VkSubpassBeginInfoKHR *pSubpassBeginInfo, - const VkSubpassEndInfoKHR *pSubpassEndInfo) -{ - tu_CmdNextSubpass(commandBuffer, pSubpassBeginInfo->contents); -} - static void tu6_emit_user_consts(struct tu_cs *cs, const struct tu_pipeline *pipeline, struct tu_descriptor_state *descriptors_state, @@ -3839,7 +3824,8 @@ tu_CmdDispatchIndirect(VkCommandBuffer commandBuffer, } void -tu_CmdEndRenderPass(VkCommandBuffer commandBuffer) +tu_CmdEndRenderPass2(VkCommandBuffer commandBuffer, + const VkSubpassEndInfoKHR *pSubpassEndInfo) { TU_FROM_HANDLE(tu_cmd_buffer, cmd_buffer, commandBuffer); @@ -3869,13 +3855,6 @@ tu_CmdEndRenderPass(VkCommandBuffer commandBuffer) cmd_buffer->state.has_subpass_predication = false; } -void -tu_CmdEndRenderPass2(VkCommandBuffer commandBuffer, - const VkSubpassEndInfoKHR *pSubpassEndInfo) -{ - tu_CmdEndRenderPass(commandBuffer); -} - struct tu_barrier_info { uint32_t eventCount; diff --git a/src/freedreno/vulkan/tu_device.c b/src/freedreno/vulkan/tu_device.c index 8b4f157..c06fdec 100644 --- a/src/freedreno/vulkan/tu_device.c +++ b/src/freedreno/vulkan/tu_device.c @@ -367,12 +367,10 @@ tu_EnumeratePhysicalDeviceGroups( } void -tu_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, - VkPhysicalDeviceFeatures *pFeatures) +tu_GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice, + VkPhysicalDeviceFeatures2 *pFeatures) { - memset(pFeatures, 0, sizeof(*pFeatures)); - - *pFeatures = (VkPhysicalDeviceFeatures) { + pFeatures->features = (VkPhysicalDeviceFeatures) { .robustBufferAccess = true, .fullDrawIndexUint32 = true, .imageCubeArray = true, @@ -419,12 +417,7 @@ tu_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, .variableMultisampleRate = false, .inheritedQueries = false, }; -} -void -tu_GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice, - VkPhysicalDeviceFeatures2 *pFeatures) -{ vk_foreach_struct(ext, pFeatures->pNext) { switch (ext->sType) { @@ -629,12 +622,11 @@ tu_GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice, break; } } - return tu_GetPhysicalDeviceFeatures(physicalDevice, &pFeatures->features); } void -tu_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, - VkPhysicalDeviceProperties *pProperties) +tu_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice, + VkPhysicalDeviceProperties2 *pProperties) { TU_FROM_HANDLE(tu_physical_device, pdevice, physicalDevice); VkSampleCountFlags sample_counts = @@ -757,7 +749,7 @@ tu_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, .nonCoherentAtomSize = 64, }; - *pProperties = (VkPhysicalDeviceProperties) { + pProperties->properties = (VkPhysicalDeviceProperties) { .apiVersion = tu_physical_device_api_version(pdevice), .driverVersion = vk_get_driver_version(), .vendorID = 0, /* TODO */ @@ -767,16 +759,8 @@ tu_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, .sparseProperties = { 0 }, }; - strcpy(pProperties->deviceName, pdevice->name); - memcpy(pProperties->pipelineCacheUUID, pdevice->cache_uuid, VK_UUID_SIZE); -} - -void -tu_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice, - VkPhysicalDeviceProperties2 *pProperties) -{ - TU_FROM_HANDLE(tu_physical_device, pdevice, physicalDevice); - tu_GetPhysicalDeviceProperties(physicalDevice, &pProperties->properties); + strcpy(pProperties->properties.deviceName, pdevice->name); + memcpy(pProperties->properties.pipelineCacheUUID, pdevice->cache_uuid, VK_UUID_SIZE); vk_foreach_struct(ext, pProperties->pNext) { @@ -893,17 +877,6 @@ static const VkQueueFamilyProperties tu_queue_family_properties = { }; void -tu_GetPhysicalDeviceQueueFamilyProperties( - VkPhysicalDevice physicalDevice, - uint32_t *pQueueFamilyPropertyCount, - VkQueueFamilyProperties *pQueueFamilyProperties) -{ - VK_OUTARRAY_MAKE(out, pQueueFamilyProperties, pQueueFamilyPropertyCount); - - vk_outarray_append(&out, p) { *p = tu_queue_family_properties; } -} - -void tu_GetPhysicalDeviceQueueFamilyProperties2( VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, @@ -938,29 +911,21 @@ tu_get_system_heap_size() } void -tu_GetPhysicalDeviceMemoryProperties( - VkPhysicalDevice physicalDevice, - VkPhysicalDeviceMemoryProperties *pMemoryProperties) +tu_GetPhysicalDeviceMemoryProperties2(VkPhysicalDevice pdev, + VkPhysicalDeviceMemoryProperties2 *props2) { - pMemoryProperties->memoryHeapCount = 1; - pMemoryProperties->memoryHeaps[0].size = tu_get_system_heap_size(); - pMemoryProperties->memoryHeaps[0].flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT; + VkPhysicalDeviceMemoryProperties *props = &props2->memoryProperties; + + props->memoryHeapCount = 1; + props->memoryHeaps[0].size = tu_get_system_heap_size(); + props->memoryHeaps[0].flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT; - pMemoryProperties->memoryTypeCount = 1; - pMemoryProperties->memoryTypes[0].propertyFlags = + props->memoryTypeCount = 1; + props->memoryTypes[0].propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; - pMemoryProperties->memoryTypes[0].heapIndex = 0; -} - -void -tu_GetPhysicalDeviceMemoryProperties2( - VkPhysicalDevice physicalDevice, - VkPhysicalDeviceMemoryProperties2 *pMemoryProperties) -{ - return tu_GetPhysicalDeviceMemoryProperties( - physicalDevice, &pMemoryProperties->memoryProperties); + props->memoryTypes[0].heapIndex = 0; } static VkResult @@ -1316,20 +1281,6 @@ tu_GetDeviceQueue2(VkDevice _device, *pQueue = tu_queue_to_handle(queue); } -void -tu_GetDeviceQueue(VkDevice _device, - uint32_t queueFamilyIndex, - uint32_t queueIndex, - VkQueue *pQueue) -{ - const VkDeviceQueueInfo2 info = - (VkDeviceQueueInfo2) { .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2, - .queueFamilyIndex = queueFamilyIndex, - .queueIndex = queueIndex }; - - tu_GetDeviceQueue2(_device, &info, pQueue); -} - VkResult tu_QueueWaitIdle(VkQueue _queue) { @@ -1573,38 +1524,18 @@ tu_InvalidateMappedMemoryRanges(VkDevice _device, } void -tu_GetBufferMemoryRequirements(VkDevice _device, - VkBuffer _buffer, - VkMemoryRequirements *pMemoryRequirements) -{ - TU_FROM_HANDLE(tu_buffer, buffer, _buffer); - - pMemoryRequirements->memoryTypeBits = 1; - pMemoryRequirements->alignment = 64; - pMemoryRequirements->size = - align64(buffer->size, pMemoryRequirements->alignment); -} - -void tu_GetBufferMemoryRequirements2( VkDevice device, const VkBufferMemoryRequirementsInfo2 *pInfo, VkMemoryRequirements2 *pMemoryRequirements) { - tu_GetBufferMemoryRequirements(device, pInfo->buffer, - &pMemoryRequirements->memoryRequirements); -} - -void -tu_GetImageMemoryRequirements(VkDevice _device, - VkImage _image, - VkMemoryRequirements *pMemoryRequirements) -{ - TU_FROM_HANDLE(tu_image, image, _image); + TU_FROM_HANDLE(tu_buffer, buffer, pInfo->buffer); - pMemoryRequirements->memoryTypeBits = 1; - pMemoryRequirements->size = image->total_size; - pMemoryRequirements->alignment = image->layout[0].base_align; + pMemoryRequirements->memoryRequirements = (VkMemoryRequirements) { + .memoryTypeBits = 1, + .alignment = 64, + .size = align64(buffer->size, 64), + }; } void @@ -1612,18 +1543,13 @@ tu_GetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo, VkMemoryRequirements2 *pMemoryRequirements) { - tu_GetImageMemoryRequirements(device, pInfo->image, - &pMemoryRequirements->memoryRequirements); -} + TU_FROM_HANDLE(tu_image, image, pInfo->image); -void -tu_GetImageSparseMemoryRequirements( - VkDevice device, - VkImage image, - uint32_t *pSparseMemoryRequirementCount, - VkSparseImageMemoryRequirements *pSparseMemoryRequirements) -{ - tu_stub(); + pMemoryRequirements->memoryRequirements = (VkMemoryRequirements) { + .memoryTypeBits = 1, + .alignment = image->layout[0].base_align, + .size = image->total_size + }; } void @@ -1664,22 +1590,6 @@ tu_BindBufferMemory2(VkDevice device, } VkResult -tu_BindBufferMemory(VkDevice device, - VkBuffer buffer, - VkDeviceMemory memory, - VkDeviceSize memoryOffset) -{ - const VkBindBufferMemoryInfo info = { - .sType = VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO, - .buffer = buffer, - .memory = memory, - .memoryOffset = memoryOffset - }; - - return tu_BindBufferMemory2(device, 1, &info); -} - -VkResult tu_BindImageMemory2(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfo *pBindInfos) @@ -1701,22 +1611,6 @@ tu_BindImageMemory2(VkDevice device, } VkResult -tu_BindImageMemory(VkDevice device, - VkImage image, - VkDeviceMemory memory, - VkDeviceSize memoryOffset) -{ - const VkBindImageMemoryInfo info = { - .sType = VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO, - .image = image, - .memory = memory, - .memoryOffset = memoryOffset - }; - - return tu_BindImageMemory2(device, 1, &info); -} - -VkResult tu_QueueBindSparse(VkQueue _queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo, @@ -1725,7 +1619,6 @@ tu_QueueBindSparse(VkQueue _queue, return VK_SUCCESS; } - VkResult tu_CreateEvent(VkDevice _device, const VkEventCreateInfo *pCreateInfo, diff --git a/src/freedreno/vulkan/tu_formats.c b/src/freedreno/vulkan/tu_formats.c index a820179..1b3597f 100644 --- a/src/freedreno/vulkan/tu_formats.c +++ b/src/freedreno/vulkan/tu_formats.c @@ -464,17 +464,6 @@ end: } void -tu_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, - VkFormat format, - VkFormatProperties *pFormatProperties) -{ - TU_FROM_HANDLE(tu_physical_device, physical_device, physicalDevice); - - tu_physical_device_get_format_properties(physical_device, format, - pFormatProperties); -} - -void tu_GetPhysicalDeviceFormatProperties2( VkPhysicalDevice physicalDevice, VkFormat format, @@ -647,32 +636,6 @@ unsupported: return VK_ERROR_FORMAT_NOT_SUPPORTED; } -VkResult -tu_GetPhysicalDeviceImageFormatProperties( - VkPhysicalDevice physicalDevice, - VkFormat format, - VkImageType type, - VkImageTiling tiling, - VkImageUsageFlags usage, - VkImageCreateFlags createFlags, - VkImageFormatProperties *pImageFormatProperties) -{ - TU_FROM_HANDLE(tu_physical_device, physical_device, physicalDevice); - - const VkPhysicalDeviceImageFormatInfo2 info = { - .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, - .pNext = NULL, - .format = format, - .type = type, - .tiling = tiling, - .usage = usage, - .flags = createFlags, - }; - - return tu_get_image_format_properties(physical_device, &info, - pImageFormatProperties, NULL); -} - static VkResult tu_get_external_image_format_properties( const struct tu_physical_device *physical_device, @@ -832,21 +795,6 @@ fail: } void -tu_GetPhysicalDeviceSparseImageFormatProperties( - VkPhysicalDevice physicalDevice, - VkFormat format, - VkImageType type, - uint32_t samples, - VkImageUsageFlags usage, - VkImageTiling tiling, - uint32_t *pNumProperties, - VkSparseImageFormatProperties *pProperties) -{ - /* Sparse images are not yet supported. */ - *pNumProperties = 0; -} - -void tu_GetPhysicalDeviceSparseImageFormatProperties2( VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSparseImageFormatInfo2 *pFormatInfo, diff --git a/src/freedreno/vulkan/tu_legacy.c b/src/freedreno/vulkan/tu_legacy.c new file mode 100644 index 0000000..046dc05 --- /dev/null +++ b/src/freedreno/vulkan/tu_legacy.c @@ -0,0 +1,375 @@ +/* + * Copyright 2020 Valve Corporation + * SPDX-License-Identifier: MIT + * + * Authors: + * Jonathan Marek + */ + +#include +#include /* android tu_entrypoints.h depends on this */ +#include + +#include "tu_entrypoints.h" +#include "vk_util.h" + +void +tu_GetPhysicalDeviceFeatures(VkPhysicalDevice pdev, VkPhysicalDeviceFeatures *features) +{ + VkPhysicalDeviceFeatures2 features2; + features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; + features2.pNext = NULL; + tu_GetPhysicalDeviceFeatures2(pdev, &features2); + *features = features2.features; +} + +void +tu_GetPhysicalDeviceProperties(VkPhysicalDevice pdev, VkPhysicalDeviceProperties *props) +{ + VkPhysicalDeviceProperties2 props2; + props2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; + props2.pNext = NULL; + tu_GetPhysicalDeviceProperties2(pdev, &props2); + *props = props2.properties; +} + +void +tu_GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice pdev, + uint32_t *count, + VkQueueFamilyProperties *props) +{ + if (!props) + return tu_GetPhysicalDeviceQueueFamilyProperties2(pdev, count, NULL); + + VkQueueFamilyProperties2 props2[*count]; + for (uint32_t i = 0; i < *count; i++) { + props2[i].sType = VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2; + props2[i].pNext = NULL; + } + tu_GetPhysicalDeviceQueueFamilyProperties2(pdev, count, props2); + for (uint32_t i = 0; i < *count; i++) + props[i] = props2[i].queueFamilyProperties; +} + +void +tu_GetPhysicalDeviceMemoryProperties(VkPhysicalDevice pdev, VkPhysicalDeviceMemoryProperties *props) +{ + VkPhysicalDeviceMemoryProperties2 props2; + props2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2; + props2.pNext = NULL; + tu_GetPhysicalDeviceMemoryProperties2(pdev, &props2); + *props = props2.memoryProperties; +} + +void +tu_GetPhysicalDeviceFormatProperties(VkPhysicalDevice pdev, VkFormat format, VkFormatProperties *props) +{ + VkFormatProperties2 props2 = { .sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2 }; + tu_GetPhysicalDeviceFormatProperties2(pdev, format, &props2); + *props = props2.formatProperties; +} + +VkResult +tu_GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice pdev, + VkFormat format, + VkImageType type, + VkImageTiling tiling, + VkImageUsageFlags usage, + VkImageCreateFlags flags, + VkImageFormatProperties *props) +{ + VkImageFormatProperties2 props2 = { .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2 }; + VkResult result = tu_GetPhysicalDeviceImageFormatProperties2(pdev, &(VkPhysicalDeviceImageFormatInfo2) { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, + .format = format, + .type = type, + .tiling = tiling, + .usage = usage, + .flags = flags + }, &props2); + *props = props2.imageFormatProperties; + return result; +} + +void +tu_GetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice pdev, + VkFormat format, + VkImageType type, + VkSampleCountFlagBits samples, + VkImageUsageFlags usage, + VkImageTiling tiling, + uint32_t *count, + VkSparseImageFormatProperties *props) +{ + const VkPhysicalDeviceSparseImageFormatInfo2 info = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, + .format = format, + .type = type, + .samples = samples, + .usage = usage, + .tiling = tiling, + }; + + if (!props) + return tu_GetPhysicalDeviceSparseImageFormatProperties2(pdev, &info, count, NULL); + + VkSparseImageFormatProperties2 props2[*count]; + for (uint32_t i = 0; i < *count; i++) { + props2[i].sType = VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2; + props2[i].pNext = NULL; + } + tu_GetPhysicalDeviceSparseImageFormatProperties2(pdev, &info, count, props2); + for (uint32_t i = 0; i < *count; i++) + props[i] = props2[i].properties; +} + +void +tu_GetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue *pQueue) +{ + tu_GetDeviceQueue2(device, &(VkDeviceQueueInfo2) { + .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2, + .queueFamilyIndex = queueFamilyIndex, + .queueIndex = queueIndex + }, pQueue); +} + +void +tu_GetBufferMemoryRequirements(VkDevice device, VkBuffer buffer, VkMemoryRequirements *reqs) +{ + VkMemoryRequirements2 reqs2 = { .sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2 }; + tu_GetBufferMemoryRequirements2(device, &(VkBufferMemoryRequirementsInfo2) { + .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2, + .buffer = buffer + }, &reqs2); + *reqs = reqs2.memoryRequirements; +} + +void +tu_GetImageMemoryRequirements(VkDevice device, VkImage image, VkMemoryRequirements *reqs) +{ + VkMemoryRequirements2 reqs2 = { .sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2 }; + tu_GetImageMemoryRequirements2(device, &(VkImageMemoryRequirementsInfo2) { + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2, + .image = image + }, &reqs2); + *reqs = reqs2.memoryRequirements; +} + +void +tu_GetImageSparseMemoryRequirements(VkDevice device, + VkImage image, + uint32_t *count, + VkSparseImageMemoryRequirements *reqs) +{ + const VkImageSparseMemoryRequirementsInfo2 info = { + .sType = VK_STRUCTURE_TYPE_IMAGE_SPARSE_MEMORY_REQUIREMENTS_INFO_2, + .image = image + }; + + if (!reqs) + return tu_GetImageSparseMemoryRequirements2(device, &info, count, NULL); + + VkSparseImageMemoryRequirements2 reqs2[*count]; + for (uint32_t i = 0; i < *count; i++) { + reqs2[i].sType = VK_STRUCTURE_TYPE_SPARSE_IMAGE_MEMORY_REQUIREMENTS_2; + reqs2[i].pNext = NULL; + } + tu_GetImageSparseMemoryRequirements2(device, &info, count, reqs2); + for (uint32_t i = 0; i < *count; i++) + reqs[i] = reqs2[i].memoryRequirements; +} + +VkResult +tu_BindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, VkDeviceSize offset) +{ + return tu_BindBufferMemory2(device, 1, &(VkBindBufferMemoryInfo) { + .sType = VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO, + .buffer = buffer, + .memory = memory, + .memoryOffset = offset + }); +} + +VkResult +tu_BindImageMemory(VkDevice device, VkImage image, VkDeviceMemory memory, VkDeviceSize offset) +{ + return tu_BindImageMemory2(device, 1, &(VkBindImageMemoryInfo) { + .sType = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO, + .image = image, + .memory = memory, + .memoryOffset = offset + }); +} + +static void +translate_references(VkAttachmentReference2 **reference_ptr, + const VkAttachmentReference *reference, + uint32_t count) +{ + VkAttachmentReference2 *reference2 = *reference_ptr; + *reference_ptr += count; + for (uint32_t i = 0; i < count; i++) { + reference2[i] = (VkAttachmentReference2) { + .sType = VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2, + .pNext = NULL, + .attachment = reference[i].attachment, + .layout = reference[i].layout, + .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, + }; + } +} + +VkResult +tu_CreateRenderPass(VkDevice device, + const VkRenderPassCreateInfo *pCreateInfo, + const VkAllocationCallbacks *pAllocator, + VkRenderPass *pRenderPass) +{ + /* note: these counts shouldn't be excessively high, so allocating it all + * on the stack should be OK.. + * also note preserve attachments aren't translated, currently unused + */ + VkAttachmentDescription2 attachments[pCreateInfo->attachmentCount]; + VkSubpassDescription2 subpasses[pCreateInfo->subpassCount]; + VkSubpassDependency2 dependencies[pCreateInfo->dependencyCount]; + uint32_t reference_count = 0; + for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) { + reference_count += pCreateInfo->pSubpasses[i].inputAttachmentCount; + reference_count += pCreateInfo->pSubpasses[i].colorAttachmentCount; + if (pCreateInfo->pSubpasses[i].pResolveAttachments) + reference_count += pCreateInfo->pSubpasses[i].colorAttachmentCount; + if (pCreateInfo->pSubpasses[i].pDepthStencilAttachment) + reference_count += 1; + } + VkAttachmentReference2 reference[reference_count]; + VkAttachmentReference2 *reference_ptr = reference; + + VkRenderPassMultiviewCreateInfo *multiview_info = NULL; + vk_foreach_struct(ext, pCreateInfo->pNext) { + if (ext->sType == VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO) { + multiview_info = (VkRenderPassMultiviewCreateInfo*) ext; + break; + } + } + + for (uint32_t i = 0; i < pCreateInfo->attachmentCount; i++) { + attachments[i] = (VkAttachmentDescription2) { + .sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2, + .pNext = NULL, + .flags = pCreateInfo->pAttachments[i].flags, + .format = pCreateInfo->pAttachments[i].format, + .samples = pCreateInfo->pAttachments[i].samples, + .loadOp = pCreateInfo->pAttachments[i].loadOp, + .storeOp = pCreateInfo->pAttachments[i].storeOp, + .stencilLoadOp = pCreateInfo->pAttachments[i].stencilLoadOp, + .stencilStoreOp = pCreateInfo->pAttachments[i].stencilStoreOp, + .initialLayout = pCreateInfo->pAttachments[i].initialLayout, + .finalLayout = pCreateInfo->pAttachments[i].finalLayout, + }; + } + + for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) { + subpasses[i] = (VkSubpassDescription2) { + .sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2, + .pNext = NULL, + .flags = pCreateInfo->pSubpasses[i].flags, + .pipelineBindPoint = pCreateInfo->pSubpasses[i].pipelineBindPoint, + .viewMask = 0, + .inputAttachmentCount = pCreateInfo->pSubpasses[i].inputAttachmentCount, + .colorAttachmentCount = pCreateInfo->pSubpasses[i].colorAttachmentCount, + }; + + if (multiview_info && multiview_info->subpassCount) + subpasses[i].viewMask = multiview_info->pViewMasks[i]; + + subpasses[i].pInputAttachments = reference_ptr; + translate_references(&reference_ptr, + pCreateInfo->pSubpasses[i].pInputAttachments, + subpasses[i].inputAttachmentCount); + subpasses[i].pColorAttachments = reference_ptr; + translate_references(&reference_ptr, + pCreateInfo->pSubpasses[i].pColorAttachments, + subpasses[i].colorAttachmentCount); + subpasses[i].pResolveAttachments = NULL; + if (pCreateInfo->pSubpasses[i].pResolveAttachments) { + subpasses[i].pResolveAttachments = reference_ptr; + translate_references(&reference_ptr, + pCreateInfo->pSubpasses[i].pResolveAttachments, + subpasses[i].colorAttachmentCount); + } + subpasses[i].pDepthStencilAttachment = NULL; + if (pCreateInfo->pSubpasses[i].pDepthStencilAttachment) { + subpasses[i].pDepthStencilAttachment = reference_ptr; + translate_references(&reference_ptr, + pCreateInfo->pSubpasses[i].pDepthStencilAttachment, + 1); + } + } + + assert(reference_ptr == reference + reference_count); + + for (uint32_t i = 0; i < pCreateInfo->dependencyCount; i++) { + dependencies[i] = (VkSubpassDependency2) { + .sType = VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2, + .pNext = NULL, + .srcSubpass = pCreateInfo->pDependencies[i].srcSubpass, + .dstSubpass = pCreateInfo->pDependencies[i].dstSubpass, + .srcStageMask = pCreateInfo->pDependencies[i].srcStageMask, + .dstStageMask = pCreateInfo->pDependencies[i].dstStageMask, + .srcAccessMask = pCreateInfo->pDependencies[i].srcAccessMask, + .dstAccessMask = pCreateInfo->pDependencies[i].dstAccessMask, + .dependencyFlags = pCreateInfo->pDependencies[i].dependencyFlags, + .viewOffset = 0, + }; + + if (multiview_info && multiview_info->dependencyCount) + dependencies[i].viewOffset = multiview_info->pViewOffsets[i]; + } + + VkRenderPassCreateInfo2 create_info = { + .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2, + .pNext = pCreateInfo->pNext, + .flags = pCreateInfo->flags, + .attachmentCount = pCreateInfo->attachmentCount, + .pAttachments = attachments, + .subpassCount = pCreateInfo->subpassCount, + .pSubpasses = subpasses, + .dependencyCount = pCreateInfo->dependencyCount, + .pDependencies = dependencies, + }; + + if (multiview_info) { + create_info.correlatedViewMaskCount = multiview_info->correlationMaskCount; + create_info.pCorrelatedViewMasks = multiview_info->pCorrelationMasks; + } + + return tu_CreateRenderPass2(device, &create_info, pAllocator, pRenderPass); +} + +void +tu_CmdBeginRenderPass(VkCommandBuffer cmd, const VkRenderPassBeginInfo *info, VkSubpassContents contents) +{ + return tu_CmdBeginRenderPass2(cmd, info, &(VkSubpassBeginInfo) { + .sType = VK_STRUCTURE_TYPE_SUBPASS_BEGIN_INFO, + .contents = contents + }); +} + +void +tu_CmdNextSubpass(VkCommandBuffer cmd, VkSubpassContents contents) +{ + return tu_CmdNextSubpass2(cmd, &(VkSubpassBeginInfo) { + .sType = VK_STRUCTURE_TYPE_SUBPASS_BEGIN_INFO, + .contents = contents + }, &(VkSubpassEndInfoKHR) { + .sType = VK_STRUCTURE_TYPE_SUBPASS_END_INFO, + }); +} + +void +tu_CmdEndRenderPass(VkCommandBuffer cmd) +{ + return tu_CmdEndRenderPass2(cmd, &(VkSubpassEndInfoKHR) { + .sType = VK_STRUCTURE_TYPE_SUBPASS_END_INFO, + }); +} diff --git a/src/freedreno/vulkan/tu_pass.c b/src/freedreno/vulkan/tu_pass.c index fd91045..c31c830 100644 --- a/src/freedreno/vulkan/tu_pass.c +++ b/src/freedreno/vulkan/tu_pass.c @@ -475,151 +475,6 @@ attachment_set_ops(struct tu_render_pass_attachment *att, } } -static void -translate_references(VkAttachmentReference2 **reference_ptr, - const VkAttachmentReference *reference, - uint32_t count) -{ - VkAttachmentReference2 *reference2 = *reference_ptr; - *reference_ptr += count; - for (uint32_t i = 0; i < count; i++) { - reference2[i] = (VkAttachmentReference2) { - .sType = VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2, - .pNext = NULL, - .attachment = reference[i].attachment, - .layout = reference[i].layout, - .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, - }; - } -} - -VkResult -tu_CreateRenderPass(VkDevice device, - const VkRenderPassCreateInfo *pCreateInfo, - const VkAllocationCallbacks *pAllocator, - VkRenderPass *pRenderPass) -{ - /* note: these counts shouldn't be excessively high, so allocating it all - * on the stack should be OK.. - * also note preserve attachments aren't translated, currently unused - */ - VkAttachmentDescription2 attachments[pCreateInfo->attachmentCount]; - VkSubpassDescription2 subpasses[pCreateInfo->subpassCount]; - VkSubpassDependency2 dependencies[pCreateInfo->dependencyCount]; - uint32_t reference_count = 0; - for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) { - reference_count += pCreateInfo->pSubpasses[i].inputAttachmentCount; - reference_count += pCreateInfo->pSubpasses[i].colorAttachmentCount; - if (pCreateInfo->pSubpasses[i].pResolveAttachments) - reference_count += pCreateInfo->pSubpasses[i].colorAttachmentCount; - if (pCreateInfo->pSubpasses[i].pDepthStencilAttachment) - reference_count += 1; - } - VkAttachmentReference2 reference[reference_count]; - VkAttachmentReference2 *reference_ptr = reference; - - VkRenderPassMultiviewCreateInfo *multiview_info = NULL; - vk_foreach_struct(ext, pCreateInfo->pNext) { - if (ext->sType == VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO) { - multiview_info = (VkRenderPassMultiviewCreateInfo*) ext; - break; - } - } - - for (uint32_t i = 0; i < pCreateInfo->attachmentCount; i++) { - attachments[i] = (VkAttachmentDescription2) { - .sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2, - .pNext = NULL, - .flags = pCreateInfo->pAttachments[i].flags, - .format = pCreateInfo->pAttachments[i].format, - .samples = pCreateInfo->pAttachments[i].samples, - .loadOp = pCreateInfo->pAttachments[i].loadOp, - .storeOp = pCreateInfo->pAttachments[i].storeOp, - .stencilLoadOp = pCreateInfo->pAttachments[i].stencilLoadOp, - .stencilStoreOp = pCreateInfo->pAttachments[i].stencilStoreOp, - .initialLayout = pCreateInfo->pAttachments[i].initialLayout, - .finalLayout = pCreateInfo->pAttachments[i].finalLayout, - }; - } - - for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) { - subpasses[i] = (VkSubpassDescription2) { - .sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2, - .pNext = NULL, - .flags = pCreateInfo->pSubpasses[i].flags, - .pipelineBindPoint = pCreateInfo->pSubpasses[i].pipelineBindPoint, - .viewMask = 0, - .inputAttachmentCount = pCreateInfo->pSubpasses[i].inputAttachmentCount, - .colorAttachmentCount = pCreateInfo->pSubpasses[i].colorAttachmentCount, - }; - - if (multiview_info && multiview_info->subpassCount) - subpasses[i].viewMask = multiview_info->pViewMasks[i]; - - subpasses[i].pInputAttachments = reference_ptr; - translate_references(&reference_ptr, - pCreateInfo->pSubpasses[i].pInputAttachments, - subpasses[i].inputAttachmentCount); - subpasses[i].pColorAttachments = reference_ptr; - translate_references(&reference_ptr, - pCreateInfo->pSubpasses[i].pColorAttachments, - subpasses[i].colorAttachmentCount); - subpasses[i].pResolveAttachments = NULL; - if (pCreateInfo->pSubpasses[i].pResolveAttachments) { - subpasses[i].pResolveAttachments = reference_ptr; - translate_references(&reference_ptr, - pCreateInfo->pSubpasses[i].pResolveAttachments, - subpasses[i].colorAttachmentCount); - } - subpasses[i].pDepthStencilAttachment = NULL; - if (pCreateInfo->pSubpasses[i].pDepthStencilAttachment) { - subpasses[i].pDepthStencilAttachment = reference_ptr; - translate_references(&reference_ptr, - pCreateInfo->pSubpasses[i].pDepthStencilAttachment, - 1); - } - } - - assert(reference_ptr == reference + reference_count); - - for (uint32_t i = 0; i < pCreateInfo->dependencyCount; i++) { - dependencies[i] = (VkSubpassDependency2) { - .sType = VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2, - .pNext = NULL, - .srcSubpass = pCreateInfo->pDependencies[i].srcSubpass, - .dstSubpass = pCreateInfo->pDependencies[i].dstSubpass, - .srcStageMask = pCreateInfo->pDependencies[i].srcStageMask, - .dstStageMask = pCreateInfo->pDependencies[i].dstStageMask, - .srcAccessMask = pCreateInfo->pDependencies[i].srcAccessMask, - .dstAccessMask = pCreateInfo->pDependencies[i].dstAccessMask, - .dependencyFlags = pCreateInfo->pDependencies[i].dependencyFlags, - .viewOffset = 0, - }; - - if (multiview_info && multiview_info->dependencyCount) - dependencies[i].viewOffset = multiview_info->pViewOffsets[i]; - } - - VkRenderPassCreateInfo2 create_info = { - .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2, - .pNext = pCreateInfo->pNext, - .flags = pCreateInfo->flags, - .attachmentCount = pCreateInfo->attachmentCount, - .pAttachments = attachments, - .subpassCount = pCreateInfo->subpassCount, - .pSubpasses = subpasses, - .dependencyCount = pCreateInfo->dependencyCount, - .pDependencies = dependencies, - }; - - if (multiview_info) { - create_info.correlatedViewMaskCount = multiview_info->correlationMaskCount; - create_info.pCorrelatedViewMasks = multiview_info->pCorrelationMasks; - } - - return tu_CreateRenderPass2(device, &create_info, pAllocator, pRenderPass); -} - VkResult tu_CreateRenderPass2(VkDevice _device, const VkRenderPassCreateInfo2KHR *pCreateInfo, -- 2.7.4