Commit 7ffcdb06 authored by Boris Brezillon's avatar Boris Brezillon Committed by Alyssa Rosenzweig
Browse files

panfrost: Add Vulkan skeleton



Based on turnip.
Signed-off-by: Boris Brezillon's avatarBoris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Alyssa Rosenzweig's avatarAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
parent 5840a9f6
Pipeline #191685 passed with stage
in 18 seconds
......@@ -262,6 +262,7 @@ endif
with_intel_vk = _vulkan_drivers.contains('intel')
with_amd_vk = _vulkan_drivers.contains('amd')
with_freedreno_vk = _vulkan_drivers.contains('freedreno')
with_panfrost_vk = _vulkan_drivers.contains('panfrost')
with_swrast_vk = _vulkan_drivers.contains('swrast')
with_any_vk = _vulkan_drivers.length() != 0
......
......@@ -166,7 +166,7 @@ option(
'vulkan-drivers',
type : 'array',
value : ['auto'],
choices : ['auto', 'amd', 'freedreno', 'intel', 'swrast'],
choices : ['auto', 'amd', 'freedreno', 'intel', 'panfrost', 'swrast'],
description : 'List of vulkan drivers to build. If this is set to auto all drivers applicable to the target OS/architecture will be built'
)
option(
......
......@@ -82,7 +82,7 @@ endif
if with_gallium_freedreno or with_freedreno_vk
subdir('freedreno')
endif
if with_gallium_panfrost or with_gallium_lima
if with_gallium_panfrost or with_gallium_lima or with_panfrost_vk
subdir('panfrost')
endif
if with_dri_i965 or with_intel_vk or with_gallium_iris
......
......@@ -67,3 +67,7 @@ bifrost_compiler = executable(
],
build_by_default : with_tools.contains('panfrost')
)
if with_panfrost_vk
subdir('vulkan')
endif
BasedOnStyle: LLVM
AlwaysBreakAfterReturnType: TopLevel
BinPackParameters: false
BraceWrapping:
AfterControlStatement: false
AfterEnum: true
AfterFunction: true
AfterStruct: true
BeforeElse: false
SplitEmptyFunction: true
BreakBeforeBraces: Custom
ColumnLimit: 78
ContinuationIndentWidth: 3
Cpp11BracedListStyle: false
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^"pan_private.h"$'
Priority: 0
- Regex: '^"(drm/|ir3/|pan_)'
Priority: 4
- Regex: '^"(c11/|compiler/|main/|nir/|spirv/|util/|vk_|wsi_)'
Priority: 3
- Regex: '^<(vulkan/)'
Priority: 2
- Regex: '.*'
Priority: 1
IndentWidth: 3
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyExcessCharacter: 100
SpaceAfterCStyleCast: true
SpaceBeforeCpp11BracedList: true
- git grep TODO src/freedreno/vulkan
# Copyright © 2017 Intel Corporation
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# 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.
pan_entrypoints = custom_target(
'pan_entrypoints.[ch]',
input : ['pan_entrypoints_gen.py', vk_api_xml],
output : ['pan_entrypoints.h', 'pan_entrypoints.c'],
command : [
prog_python, '@INPUT0@', '--xml', '@INPUT1@', '--outdir',
meson.current_build_dir()
],
depend_files : files('pan_extensions.py'),
)
pan_extensions_c = custom_target(
'pan_extensions.c',
input : ['pan_extensions.py', vk_api_xml],
output : ['pan_extensions.c', 'pan_extensions.h'],
command : [
prog_python, '@INPUT0@', '--xml', '@INPUT1@', '--out-c', '@OUTPUT0@',
'--out-h', '@OUTPUT1@'
],
)
libpan_files = files(
'pan_cmd_buffer.c',
'pan_device.c',
'pan_descriptor_set.c',
'pan_descriptor_set.h',
'pan_drm.c',
'pan_fence.c',
'pan_formats.c',
'pan_image.c',
'pan_meta_blit.c',
'pan_meta_buffer.c',
'pan_meta_clear.c',
'pan_meta_copy.c',
'pan_meta_resolve.c',
'pan_pass.c',
'pan_pipeline.c',
'pan_pipeline_cache.c',
'pan_private.h',
'pan_query.c',
'pan_shader.c',
'pan_util.c',
'pan_util.h',
'pan_wsi.c',
'vk_format.h',
)
pan_deps = []
pan_flags = []
if with_platform_wayland
pan_deps += dep_wayland_client
pan_flags += '-DVK_USE_PLATFORM_WAYLAND_KHR'
libpan_files += files('pan_wsi_wayland.c')
endif
libvulkan_panfrost = shared_library(
'vulkan_panfrost',
[libpan_files, pan_entrypoints, pan_extensions_c],
include_directories : [
inc_include,
inc_src,
inc_compiler,
inc_gallium, # XXX: pipe/p_format.h
inc_vulkan_wsi,
inc_panfrost,
],
link_with : [
libvulkan_wsi,
libpanfrost_shared,
libpanfrost_midgard,
libpanfrost_bifrost,
libpanfrost_lib,
libpanfrost_util,
],
dependencies : [
dep_dl,
dep_elf,
dep_libdrm,
dep_llvm,
dep_m,
dep_thread,
dep_valgrind,
idep_nir,
pan_deps,
idep_vulkan_util,
idep_mesautil,
],
c_args : [no_override_init_args, pan_flags],
link_args : [ld_args_bsymbolic, ld_args_gc_sections],
install : true,
)
panfrost_icd = custom_target(
'panfrost_icd',
input : 'pan_icd.py',
output : 'panfrost_icd.@0@.json'.format(host_machine.cpu()),
command : [
prog_python, '@INPUT@',
'--lib-path', join_paths(get_option('prefix'), get_option('libdir')),
'--out', '@OUTPUT@',
],
depend_files : files('pan_extensions.py'),
build_by_default : true,
install_dir : with_vulkan_icd_dir,
install : true,
)
pan_dev_icd = custom_target(
'pan_dev_icd',
input : 'pan_icd.py',
output : 'dev_icd.json',
command : [
prog_python, '@INPUT@', '--lib-path', meson.current_build_dir(),
'--out', '@OUTPUT@'
],
depend_files : files('pan_extensions.py'),
build_by_default : true,
install : false,
)
/*
* Copyright © 2017, Google Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* 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.
*/
#include "pan_private.h"
#include <hardware/gralloc.h>
#include <hardware/hardware.h>
#include <hardware/hwvulkan.h>
#include <libsync.h>
#include <vulkan/vk_android_native_buffer.h>
#include <vulkan/vk_icd.h>
static int
pan_hal_open(const struct hw_module_t *mod,
const char *id,
struct hw_device_t **dev);
static int
pan_hal_close(struct hw_device_t *dev);
static void UNUSED
static_asserts(void)
{
STATIC_ASSERT(HWVULKAN_DISPATCH_MAGIC == ICD_LOADER_MAGIC);
}
PUBLIC struct hwvulkan_module_t HAL_MODULE_INFO_SYM = {
.common =
{
.tag = HARDWARE_MODULE_TAG,
.module_api_version = HWVULKAN_MODULE_API_VERSION_0_1,
.hal_api_version = HARDWARE_MAKE_API_VERSION(1, 0),
.id = HWVULKAN_HARDWARE_MODULE_ID,
.name = "AMD Vulkan HAL",
.author = "Google",
.methods =
&(hw_module_methods_t){
.open = pan_hal_open,
},
},
};
/* If any bits in test_mask are set, then unset them and return true. */
static inline bool
unmask32(uint32_t *inout_mask, uint32_t test_mask)
{
uint32_t orig_mask = *inout_mask;
*inout_mask &= ~test_mask;
return *inout_mask != orig_mask;
}
static int
pan_hal_open(const struct hw_module_t *mod,
const char *id,
struct hw_device_t **dev)
{
assert(mod == &HAL_MODULE_INFO_SYM.common);
assert(strcmp(id, HWVULKAN_DEVICE_0) == 0);
hwvulkan_device_t *hal_dev = malloc(sizeof(*hal_dev));
if (!hal_dev)
return -1;
*hal_dev = (hwvulkan_device_t){
.common =
{
.tag = HARDWARE_DEVICE_TAG,
.version = HWVULKAN_DEVICE_API_VERSION_0_1,
.module = &HAL_MODULE_INFO_SYM.common,
.close = pan_hal_close,
},
.EnumerateInstanceExtensionProperties =
pan_EnumerateInstanceExtensionProperties,
.CreateInstance = pan_CreateInstance,
.GetInstanceProcAddr = pan_GetInstanceProcAddr,
};
*dev = &hal_dev->common;
return 0;
}
static int
pan_hal_close(struct hw_device_t *dev)
{
/* hwvulkan.h claims that hw_device_t::close() is never called. */
return -1;
}
VkResult
pan_image_from_gralloc(VkDevice device_h,
const VkImageCreateInfo *base_info,
const VkNativeBufferANDROID *gralloc_info,
const VkAllocationCallbacks *alloc,
VkImage *out_image_h)
{
TU_FROM_HANDLE(pan_device, device, device_h);
VkImage image_h = VK_NULL_HANDLE;
struct pan_image *image = NULL;
struct pan_bo *bo = NULL;
VkResult result;
result = pan_image_create(
device_h,
&(struct pan_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,
"VkNativeBufferANDROID::handle::numFds is %d, "
"expected 1",
gralloc_info->handle->numFds);
}
/* Do not close the gralloc handle's dma_buf. The lifetime of the dma_buf
* must exceed that of the gralloc handle, and we do not own the gralloc
* handle.
*/
int dma_buf = gralloc_info->handle->data[0];
image = pan_image_from_handle(image_h);
VkDeviceMemory memory_h;
const VkMemoryDedicatedAllocateInfo ded_alloc = {
.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
.pNext = NULL,
.buffer = VK_NULL_HANDLE,
.image = image_h
};
const VkImportMemoryFdInfo import_info = {
.sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO,
.pNext = &ded_alloc,
.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) {
bool is_local =
!!(device->physical_device->memory_properties.memoryTypes[i]
.propertyFlags &
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
if (is_local) {
memory_type_index = i;
break;
}
}
/* fallback */
if (memory_type_index == -1)
memory_type_index = 0;
result =
pan_AllocateMemory(device_h,
&(VkMemoryAllocateInfo) {
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
.pNext = &import_info,
.allocationSize = image->size,
.memoryTypeIndex = memory_type_index,
},
alloc, &memory_h);
if (result != VK_SUCCESS)
goto fail_create_image;
pan_BindImageMemory(device_h, image_h, memory_h, 0);
image->owned_memory = memory_h;
/* Don't clobber the out-parameter until success is certain. */
*out_image_h = image_h;
return VK_SUCCESS;
fail_create_image:
fail_size:
pan_DestroyImage(device_h, image_h, alloc);
return result;
}
VkResult
pan_GetSwapchainGrallocUsageANDROID(VkDevice device_h,
VkFormat format,
VkImageUsageFlags imageUsage,
int *grallocUsage)
{
TU_FROM_HANDLE(pan_device, device, device_h);
struct pan_physical_device *phys_dev = device->physical_device;
VkPhysicalDevice phys_dev_h = pan_physical_device_to_handle(phys_dev);
VkResult result;
*grallocUsage = 0;
/* WARNING: Android Nougat's libvulkan.so hardcodes the VkImageUsageFlags
* returned to applications via
* VkSurfaceCapabilitiesKHR::supportedUsageFlags.
* The relevant code in libvulkan/swapchain.cpp contains this fun comment:
*
* TODO(jessehall): I think these are right, but haven't thought hard
* about it. Do we need to query the driver for support of any of
* these?
*
* Any disagreement between this function and the hardcoded
* VkSurfaceCapabilitiesKHR:supportedUsageFlags causes tests
* dEQP-VK.wsi.android.swapchain.*.image_usage to fail.
*/
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,
};
VkImageFormatProperties2 image_format_props = {
.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2,
};
/* Check that requested format and usage are supported. */
result = pan_GetPhysicalDeviceImageFormatProperties2(
phys_dev_h, &image_format_info, &image_format_props);
if (result != VK_SUCCESS) {
return vk_errorf(device->instance, result,
"pan_GetPhysicalDeviceImageFormatProperties2 failed "
"inside %s",
__func__);
}
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))
*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,
"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.
*/
if (format == VK_FORMAT_B8G8R8A8_UNORM ||
format == VK_FORMAT_B5G6R5_UNORM_PACK16) {
*grallocUsage |= GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_HW_COMPOSER |
GRALLOC_USAGE_EXTERNAL_DISP;
}
if (*grallocUsage == 0)
return VK_ERROR_FORMAT_NOT_SUPPORTED;
return VK_SUCCESS;
}
VkResult
pan_AcquireImageANDROID(VkDevice device,
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;
semaphore_result = pan_ImportSemaphoreFdKHR(
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 = pan_ImportFenceFdKHR(
device, &(VkImportFenceFdInfoKHR) {
.sType = VK_STRUCTURE_TYPE_IMPORT_FENCE_FD_INFO_KHR,
.flags = VK_FENCE_IMPORT_TEMPORARY_BIT,
.fd = fence_fd,
.fence = fence,
});
}
close(nativeFenceFd);
if (semaphore_result != VK_SUCCESS)
return semaphore_result;
return fence_result;
}
VkResult
pan_QueueSignalReleaseImageANDROID(VkQueue _queue,
uint32_t waitSemaphoreCount,
const VkSemaphore *pWaitSemaphores,
VkImage image,
int *pNativeFenceFd)
{
TU_FROM_HANDLE(pan_queue, queue, _queue);
VkResult result = VK_SUCCESS;
if (waitSemaphoreCount == 0) {
if (pNativeFenceFd)
*pNativeFenceFd = -1;
return VK_SUCCESS;
}
int fd = -1;
for (uint32_t i = 0; i < waitSemaphoreCount; ++i) {
int tmp_fd;
result = pan_GetSemaphoreFdKHR(
pan_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);
return result;
}
if (fd < 0)
fd = tmp_fd;
else if (tmp_fd >= 0) {
sync_accumulate("pan", &fd, tmp_fd);
close(tmp_fd);
}
}
if (pNativeFenceFd) {
*pNativeFenceFd = fd;
} else if (fd >= 0) {
close(fd);
/* We still need to do the exports, to reset the semaphores, but
* otherwise we don't wait on them. */
}
return VK_SUCCESS;
}
/*
* Copyright © 2016 Red Hat.
* Copyright © 2016 Bas Nieuwenhuizen
*
* based in part on anv driver which is:
* Copyright © 2015 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* 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.
*/