X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Ffreedreno%2Fvulkan%2Ftu_android.c;h=1ebc9e726e87113ec8926b327351923444495892;hb=23d30f4099fac0e1fcbd7adf315a186f553e48d2;hp=fbc1bf84b848d93c9aa6147c0b609e60f6c91a3b;hpb=26380b3a9f8fd513dc4da86798f3c15191914fc2;p=mesa.git diff --git a/src/freedreno/vulkan/tu_android.c b/src/freedreno/vulkan/tu_android.c index fbc1bf84b84..1ebc9e726e8 100644 --- a/src/freedreno/vulkan/tu_android.c +++ b/src/freedreno/vulkan/tu_android.c @@ -17,23 +17,24 @@ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. */ +#include "tu_private.h" + #include #include #include #include + #include #include -#include "tu_private.h" - static int tu_hal_open(const struct hw_module_t *mod, - const char *id, - struct hw_device_t **dev); + const char *id, + struct hw_device_t **dev); static int tu_hal_close(struct hw_device_t *dev); @@ -70,8 +71,8 @@ unmask32(uint32_t *inout_mask, uint32_t test_mask) static int tu_hal_open(const struct hw_module_t *mod, - const char *id, - struct hw_device_t **dev) + const char *id, + struct hw_device_t **dev) { assert(mod == &HAL_MODULE_INFO_SYM.common); assert(strcmp(id, HWVULKAN_DEVICE_0) == 0); @@ -107,10 +108,10 @@ tu_hal_close(struct hw_device_t *dev) VkResult tu_image_from_gralloc(VkDevice device_h, - const VkImageCreateInfo *base_info, - const VkNativeBufferANDROID *gralloc_info, - const VkAllocationCallbacks *alloc, - VkImage *out_image_h) + const VkImageCreateInfo *base_info, + const VkNativeBufferANDROID *gralloc_info, + const VkAllocationCallbacks *alloc, + VkImage *out_image_h) { TU_FROM_HANDLE(tu_device, device, device_h); @@ -120,18 +121,16 @@ tu_image_from_gralloc(VkDevice device_h, VkResult result; result = tu_image_create( - device_h, - &(struct tu_image_create_info){ - .vk_info = base_info, .scanout = true, .no_metadata_planes = true }, - alloc, - &image_h); + device_h, + &(struct tu_image_create_info) { + .vk_info = base_info, .scanout = true, .no_metadata_planes = true }, + alloc, &image_h); if (result != VK_SUCCESS) return result; if (gralloc_info->handle->numFds != 1) { - return vk_errorf(device->instance, - VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR, + return vk_errorf(device->instance, VK_ERROR_INVALID_EXTERNAL_HANDLE, "VkNativeBufferANDROID::handle::numFds is %d, " "expected 1", gralloc_info->handle->numFds); @@ -147,28 +146,27 @@ tu_image_from_gralloc(VkDevice device_h, VkDeviceMemory memory_h; - const VkMemoryDedicatedAllocateInfoKHR ded_alloc = { - .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR, + const VkMemoryDedicatedAllocateInfo ded_alloc = { + .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO, .pNext = NULL, .buffer = VK_NULL_HANDLE, .image = image_h }; - const VkImportMemoryFdInfoKHR import_info = { - .sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR, + const VkImportMemoryFdInfo import_info = { + .sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO, .pNext = &ded_alloc, - .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR, + .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT, .fd = dup(dma_buf), }; /* Find the first VRAM memory type, or GART for PRIME images. */ int memory_type_index = -1; for (int i = 0; - i < device->physical_device->memory_properties.memoryTypeCount; - ++i) { + i < device->physical_device->memory_properties.memoryTypeCount; ++i) { bool is_local = - !!(device->physical_device->memory_properties.memoryTypes[i] - .propertyFlags & - VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + !!(device->physical_device->memory_properties.memoryTypes[i] + .propertyFlags & + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); if (is_local) { memory_type_index = i; break; @@ -180,15 +178,14 @@ tu_image_from_gralloc(VkDevice device_h, memory_type_index = 0; result = - tu_AllocateMemory(device_h, - &(VkMemoryAllocateInfo){ - .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, - .pNext = &import_info, - .allocationSize = image->size, - .memoryTypeIndex = memory_type_index, + tu_AllocateMemory(device_h, + &(VkMemoryAllocateInfo) { + .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, + .pNext = &import_info, + .allocationSize = image->size, + .memoryTypeIndex = memory_type_index, }, - alloc, - &memory_h); + alloc, &memory_h); if (result != VK_SUCCESS) goto fail_create_image; @@ -209,9 +206,9 @@ fail_size: VkResult tu_GetSwapchainGrallocUsageANDROID(VkDevice device_h, - VkFormat format, - VkImageUsageFlags imageUsage, - int *grallocUsage) + VkFormat format, + VkImageUsageFlags imageUsage, + int *grallocUsage) { TU_FROM_HANDLE(tu_device, device, device_h); struct tu_physical_device *phys_dev = device->physical_device; @@ -234,56 +231,53 @@ tu_GetSwapchainGrallocUsageANDROID(VkDevice device_h, * dEQP-VK.wsi.android.swapchain.*.image_usage to fail. */ - const VkPhysicalDeviceImageFormatInfo2KHR image_format_info = { - .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2_KHR, + const VkPhysicalDeviceImageFormatInfo2 image_format_info = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, .format = format, .type = VK_IMAGE_TYPE_2D, .tiling = VK_IMAGE_TILING_OPTIMAL, .usage = imageUsage, }; - VkImageFormatProperties2KHR image_format_props = { - .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2_KHR, + VkImageFormatProperties2 image_format_props = { + .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2, }; /* Check that requested format and usage are supported. */ result = tu_GetPhysicalDeviceImageFormatProperties2( - phys_dev_h, &image_format_info, &image_format_props); + phys_dev_h, &image_format_info, &image_format_props); if (result != VK_SUCCESS) { - return vk_errorf(device->instance, - result, + return vk_errorf(device->instance, result, "tu_GetPhysicalDeviceImageFormatProperties2 failed " "inside %s", __func__); } - if (unmask32(&imageUsage, - VK_IMAGE_USAGE_TRANSFER_DST_BIT | - VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)) + if (unmask32(&imageUsage, VK_IMAGE_USAGE_TRANSFER_DST_BIT | + VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)) *grallocUsage |= GRALLOC_USAGE_HW_RENDER; - if (unmask32(&imageUsage, - VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | - VK_IMAGE_USAGE_STORAGE_BIT | - VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) + if (unmask32(&imageUsage, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | + VK_IMAGE_USAGE_SAMPLED_BIT | + VK_IMAGE_USAGE_STORAGE_BIT | + VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) *grallocUsage |= GRALLOC_USAGE_HW_TEXTURE; /* All VkImageUsageFlags not explicitly checked here are unsupported for * gralloc swapchains. */ if (imageUsage != 0) { - return vk_errorf(device->instance, - VK_ERROR_FORMAT_NOT_SUPPORTED, + return vk_errorf(device->instance, VK_ERROR_FORMAT_NOT_SUPPORTED, "unsupported VkImageUsageFlags(0x%x) for gralloc " "swapchain", imageUsage); } /* - * FINISHME: Advertise all display-supported formats. Mostly - * DRM_FORMAT_ARGB2101010 and DRM_FORMAT_ABGR2101010, but need to check - * what we need for 30-bit colors. - */ + * FINISHME: Advertise all display-supported formats. Mostly + * DRM_FORMAT_ARGB2101010 and DRM_FORMAT_ABGR2101010, but need to check + * what we need for 30-bit colors. + */ if (format == VK_FORMAT_B8G8R8A8_UNORM || format == VK_FORMAT_B5G6R5_UNORM_PACK16) { *grallocUsage |= GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_HW_COMPOSER | @@ -298,36 +292,34 @@ tu_GetSwapchainGrallocUsageANDROID(VkDevice device_h, VkResult tu_AcquireImageANDROID(VkDevice device, - VkImage image_h, - int nativeFenceFd, - VkSemaphore semaphore, - VkFence fence) + VkImage image_h, + int nativeFenceFd, + VkSemaphore semaphore, + VkFence fence) { VkResult semaphore_result = VK_SUCCESS, fence_result = VK_SUCCESS; if (semaphore != VK_NULL_HANDLE) { int semaphore_fd = - nativeFenceFd >= 0 ? dup(nativeFenceFd) : nativeFenceFd; + nativeFenceFd >= 0 ? dup(nativeFenceFd) : nativeFenceFd; semaphore_result = tu_ImportSemaphoreFdKHR( - device, - &(VkImportSemaphoreFdInfoKHR){ - .sType = VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR, - .flags = VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR, - .fd = semaphore_fd, - .semaphore = semaphore, - }); + device, &(VkImportSemaphoreFdInfoKHR) { + .sType = VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR, + .flags = VK_SEMAPHORE_IMPORT_TEMPORARY_BIT, + .fd = semaphore_fd, + .semaphore = semaphore, + }); } if (fence != VK_NULL_HANDLE) { int fence_fd = nativeFenceFd >= 0 ? dup(nativeFenceFd) : nativeFenceFd; fence_result = tu_ImportFenceFdKHR( - device, - &(VkImportFenceFdInfoKHR){ - .sType = VK_STRUCTURE_TYPE_IMPORT_FENCE_FD_INFO_KHR, - .flags = VK_FENCE_IMPORT_TEMPORARY_BIT_KHR, - .fd = fence_fd, - .fence = fence, - }); + device, &(VkImportFenceFdInfoKHR) { + .sType = VK_STRUCTURE_TYPE_IMPORT_FENCE_FD_INFO_KHR, + .flags = VK_FENCE_IMPORT_TEMPORARY_BIT, + .fd = fence_fd, + .fence = fence, + }); } close(nativeFenceFd); @@ -339,10 +331,10 @@ tu_AcquireImageANDROID(VkDevice device, VkResult tu_QueueSignalReleaseImageANDROID(VkQueue _queue, - uint32_t waitSemaphoreCount, - const VkSemaphore *pWaitSemaphores, - VkImage image, - int *pNativeFenceFd) + uint32_t waitSemaphoreCount, + const VkSemaphore *pWaitSemaphores, + VkImage image, + int *pNativeFenceFd) { TU_FROM_HANDLE(tu_queue, queue, _queue); VkResult result = VK_SUCCESS; @@ -358,13 +350,13 @@ tu_QueueSignalReleaseImageANDROID(VkQueue _queue, for (uint32_t i = 0; i < waitSemaphoreCount; ++i) { int tmp_fd; result = tu_GetSemaphoreFdKHR( - tu_device_to_handle(queue->device), - &(VkSemaphoreGetFdInfoKHR){ - .sType = VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR, - .handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR, - .semaphore = pWaitSemaphores[i], - }, - &tmp_fd); + tu_device_to_handle(queue->device), + &(VkSemaphoreGetFdInfoKHR) { + .sType = VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR, + .handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT, + .semaphore = pWaitSemaphores[i], + }, + &tmp_fd); if (result != VK_SUCCESS) { if (fd >= 0) close(fd);