Commit 8b3c7231 authored by Boris Brezillon's avatar Boris Brezillon
Browse files

panfrost: Add Vulkan driver



Based on turnip.
Signed-off-by: Boris Brezillon's avatarBoris Brezillon <boris.brezillon@collabora.com>
parent 22a979be
Pipeline #290052 waiting for manual action with stages
......@@ -271,6 +271,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_freedreno_kgsl = get_option('freedreno-kgsl')
with_broadcom_vk = _vulkan_drivers.contains('broadcom')
......
......@@ -178,7 +178,7 @@ option(
'vulkan-drivers',
type : 'array',
value : ['auto'],
choices : ['auto', 'amd', 'broadcom', 'freedreno', 'intel', 'swrast'],
choices : ['auto', 'amd', 'broadcom', '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(
......
......@@ -83,7 +83,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_gallium_virgl
......
......@@ -65,3 +65,7 @@ bifrost_compiler = executable(
],
build_by_default : with_tools.contains('panfrost')
)
if with_panfrost_vk
subdir('vulkan')
endif
# Copyright © 2021 Collabora Ltd.
#
# Derived from the freedreno driver which is:
# 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.
panvk_entrypoints = custom_target(
'panvk_entrypoints.[ch]',
input : [vk_entrypoints_gen, vk_api_xml],
output : ['panvk_entrypoints.h', 'panvk_entrypoints.c'],
command : [
prog_python, '@INPUT0@', '--xml', '@INPUT1@', '--proto', '--weak',
'--out-h', '@OUTPUT0@', '--out-c', '@OUTPUT1@', '--prefix', 'panvk',
],
depend_files : files('panvk_extensions.py'),
)
panvk_extensions_c = custom_target(
'panvk_extensions.c',
input : ['panvk_extensions.py', vk_api_xml],
output : ['panvk_extensions.c', 'panvk_extensions.h'],
command : [
prog_python, '@INPUT0@', '--xml', '@INPUT1@', '--out-c', '@OUTPUT0@',
'--out-h', '@OUTPUT1@'
],
)
libpanvk_files = files(
'panvk_cmd_buffer.c',
'panvk_cs.c',
'panvk_device.c',
'panvk_descriptor_set.c',
'panvk_formats.c',
'panvk_image.c',
'panvk_meta_blit.c',
'panvk_meta_buffer.c',
'panvk_meta_clear.c',
'panvk_meta_copy.c',
'panvk_meta_resolve.c',
'panvk_pass.c',
'panvk_pipeline.c',
'panvk_pipeline_cache.c',
'panvk_private.h',
'panvk_query.c',
'panvk_shader.c',
'panvk_sync.c',
'panvk_util.c',
'panvk_util.h',
'panvk_varyings.c',
'panvk_wsi.c',
'panvk_wsi_display.c',
)
panvk_deps = []
panvk_flags = []
if system_has_kms_drm
panvk_flags += '-DVK_USE_PLATFORM_DISPLAY_KHR'
libpanvk_files += files('panvk_wsi_display.c')
endif
if with_platform_wayland
panvk_deps += [dep_wayland_client, dep_wl_protocols]
panvk_flags += '-DVK_USE_PLATFORM_WAYLAND_KHR'
libpanvk_files += files('panvk_wsi_wayland.c')
libpanvk_files += [wayland_drm_client_protocol_h, wayland_drm_protocol_c]
endif
libvulkan_panfrost = shared_library(
'vulkan_panfrost',
[libpanvk_files, panvk_entrypoints, panvk_extensions_c],
include_directories : [
inc_include,
inc_src,
inc_compiler,
inc_gallium, # XXX: pipe/p_format.h
inc_gallium_aux, # XXX: renderonly
inc_vulkan_wsi,
inc_panfrost,
],
link_with : [
libvulkan_wsi,
libpanfrost_shared,
libpanfrost_midgard,
libpanfrost_bifrost,
libpanfrost_decode,
libpanfrost_lib,
libpanfrost_util,
],
dependencies : [
dep_dl,
dep_elf,
dep_libdrm,
dep_llvm,
dep_m,
dep_thread,
dep_valgrind,
idep_nir,
panvk_deps,
idep_vulkan_util,
idep_mesautil,
],
c_args : [no_override_init_args, panvk_flags],
link_args : [ld_args_bsymbolic, ld_args_gc_sections],
install : true,
)
panfrost_icd = custom_target(
'panfrost_icd',
input : 'panvk_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('panvk_extensions.py'),
build_by_default : true,
install_dir : with_vulkan_icd_dir,
install : true,
)
panvk_dev_icd = custom_target(
'panvk_dev_icd',
input : 'panvk_icd.py',
output : 'dev_icd.json',
command : [
prog_python, '@INPUT@', '--lib-path', meson.current_build_dir(),
'--out', '@OUTPUT@'
],
depend_files : files('panvk_extensions.py'),
build_by_default : true,
install : false,
)
This diff is collapsed.
This diff is collapsed.
/*
* Copyright (C) 2021 Collabora Ltd.
*
* 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.
*/
#ifndef PANVK_CS_H
#define PANVK_CS_H
#include <vulkan/vulkan.h>
#include "compiler/shader_enums.h"
#include "panfrost-job.h"
struct pan_blend_state;
struct pan_shader_info;
struct panfrost_ptr;
struct pan_pool;
union panvk_sysval_data;
struct panvk_framebuffer;
struct panvk_cmd_state;
struct panvk_compute_dim;
struct panvk_device;
struct panvk_batch;
struct panvk_varyings_info;
struct panvk_attribs_info;
struct panvk_pipeline;
struct panvk_draw_info;
struct panvk_descriptor_state;
struct panvk_subpass;
struct panvk_clear_value;
void
panvk_emit_varyings(const struct panvk_device *dev,
const struct panvk_varyings_info *varyings,
gl_shader_stage stage,
void *descs);
void
panvk_emit_varying_bufs(const struct panvk_device *dev,
const struct panvk_varyings_info *varyings,
void *descs);
void
panvk_emit_attribs(const struct panvk_device *dev,
const struct panvk_attribs_info *attribs,
void *descs);
void
panvk_emit_attrib_bufs(const struct panvk_device *dev,
const struct panvk_attribs_info *attribs,
const struct panvk_draw_info *draw,
void *descs);
void
panvk_emit_ubos(const struct panvk_pipeline *pipeline,
const struct panvk_descriptor_state *state,
void *descs);
void
panvk_emit_vertex_job(const struct panvk_device *dev,
const struct panvk_pipeline *pipeline,
const struct panvk_draw_info *draw,
void *job);
void
panvk_emit_tiler_job(const struct panvk_device *dev,
const struct panvk_pipeline *pipeline,
const struct panvk_draw_info *draw,
void *job);
void
panvk_emit_fragment_job(const struct panvk_device *dev,
const struct panvk_framebuffer *fb,
mali_ptr fbdesc,
void *job);
void
panvk_emit_viewport(const VkViewport *viewport, const VkRect2D *scissor,
void *vpd);
void
panvk_emit_fs_rsd(const struct panvk_device *dev,
const struct panvk_pipeline *pipeline,
const struct panvk_cmd_state *state,
void *rsd);
void
panvk_emit_non_fs_rsd(const struct panvk_device *dev,
const struct pan_shader_info *shader_info,
mali_ptr shader_ptr,
void *rsd);
void
panvk_emit_bifrost_tiler_context(const struct panvk_device *dev,
const struct panvk_framebuffer *fb,
const struct panfrost_ptr *descs);
void
panvk_emit_fb(const struct panvk_device *dev,
const struct panvk_batch *batch,
const struct panvk_subpass *subpass,
const struct panvk_pipeline *pipeline,
const struct panvk_framebuffer *fb,
const struct panvk_clear_value *clears,
void *desc);
void
panvk_emit_tls(const struct panvk_device *dev,
const struct panvk_pipeline *pipeline,
const struct panvk_compute_dim *wg_count,
struct pan_pool *tls_pool,
void *desc);
void
panvk_sysval_upload_viewport_scale(const VkViewport *viewport,
union panvk_sysval_data *data);
void
panvk_sysval_upload_viewport_offset(const VkViewport *viewport,
union panvk_sysval_data *data);
#endif
This diff is collapsed.
This diff is collapsed.
COPYRIGHT = """\
/*
* Copyright 2021 Collabora Ltd.
*
* Derived from tu_extensions.py which is:
* 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, sub license, 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 NON-INFRINGEMENT.
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
*/
"""
import argparse
import os.path
import re
import sys
VULKAN_UTIL = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../vulkan/util'))
sys.path.append(VULKAN_UTIL)
from vk_extensions import *
from vk_extensions_gen import *
MAX_API_VERSION = '1.0.0'
# On Android, we disable all surface and swapchain extensions. Android's Vulkan
# loader implements VK_KHR_surface and VK_KHR_swapchain, and applications
# cannot access the driver's implementation. Moreoever, if the driver exposes
# the those extension strings, then tests dEQP-VK.api.info.instance.extensions
# and dEQP-VK.api.info.device fail due to the duplicated strings.
EXTENSIONS = [
Extension('VK_KHR_surface', 25, 'PANVK_HAS_SURFACE'),
Extension('VK_KHR_swapchain', 68, 'PANVK_HAS_SURFACE'),
Extension('VK_KHR_wayland_surface', 6, 'VK_USE_PLATFORM_WAYLAND_KHR'),
Extension('VK_EXT_custom_border_color', 12, True),
]
MAX_API_VERSION = VkVersion(MAX_API_VERSION)
API_VERSIONS = [ ApiVersion(MAX_API_VERSION, True) ]
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--out-c', help='Output C file.', required=True)
parser.add_argument('--out-h', help='Output H file.', required=True)
parser.add_argument('--xml',
help='Vulkan API XML file.',
required=True,
action='append',
dest='xml_files')
args = parser.parse_args()
gen_extensions('panvk', args.xml_files, API_VERSIONS, MAX_API_VERSION, EXTENSIONS, args.out_c, args.out_h)
/*
* Copyright © 2021 Collabora Ltd.
*
* Derived from tu_formats.c which is:
* Copyright © 2016 Red Hat.
* Copyright © 2016 Bas Nieuwenhuizen
*
* 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 "panvk_private.h"
#include "util/format_r11g11b10f.h"
#include "util/format_srgb.h"
#include "util/half_float.h"
#include "vulkan/util/vk_format.h"
#include "vk_format.h"
#include "vk_util.h"
#include "panfrost/lib/pan_texture.h"
static void
get_format_properties(struct panvk_physical_device *physical_device,
VkFormat format,
VkFormatProperties *out_properties)
{
struct panfrost_device *pdev = &physical_device->pdev;
VkFormatFeatureFlags tex = 0, buffer = 0;
const struct panfrost_format fmt =
pdev->formats[vk_format_to_pipe_format(format)];
if (!fmt.hw)
goto end;
buffer |= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT |
VK_FORMAT_FEATURE_TRANSFER_DST_BIT;
if (fmt.bind & PIPE_BIND_VERTEX_BUFFER)
buffer |= VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT;
if (fmt.bind & PIPE_BIND_SAMPLER_VIEW) {
tex |= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT |
VK_FORMAT_FEATURE_TRANSFER_DST_BIT |
VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT |
VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT |
VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT |
VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT |
VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT;
buffer |= VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT;
tex |= VK_FORMAT_FEATURE_BLIT_SRC_BIT;
}
if (fmt.bind & PIPE_BIND_RENDER_TARGET) {
tex |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT |
VK_FORMAT_FEATURE_BLIT_DST_BIT;
tex |= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT;
buffer |= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT;
/* Can always blend via blend shaders */
tex |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT;
}
if (fmt.bind & PIPE_BIND_DEPTH_STENCIL)
tex |= VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
end:
out_properties->linearTilingFeatures = tex;
out_properties->optimalTilingFeatures = tex;
out_properties->bufferFeatures = buffer;
}
void
panvk_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice,
VkFormat format,
VkFormatProperties *pFormatProperties)
{
VK_FROM_HANDLE(panvk_physical_device, physical_device, physicalDevice);
get_format_properties(physical_device, format, pFormatProperties);
}
void
panvk_GetPhysicalDeviceFormatProperties2(VkPhysicalDevice physicalDevice,
VkFormat format,
VkFormatProperties2 *pFormatProperties)
{
VK_FROM_HANDLE(panvk_physical_device, physical_device, physicalDevice);
get_format_properties(physical_device, format,
&pFormatProperties->formatProperties);
VkDrmFormatModifierPropertiesListEXT *list =
vk_find_struct(pFormatProperties->pNext, DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT);
if (list) {
VK_OUTARRAY_MAKE(out, list->pDrmFormatModifierProperties,
&list->drmFormatModifierCount);
vk_outarray_append(&out, mod_props) {
mod_props->drmFormatModifier = DRM_FORMAT_MOD_LINEAR;
mod_props->drmFormatModifierPlaneCount = 1;
}
/* TODO: any cases where this should be disabled? */
vk_outarray_append(&out, mod_props) {
mod_props->drmFormatModifier = DRM_FORMAT_MOD_QCOM_COMPRESSED;
mod_props->drmFormatModifierPlaneCount = 1;
}
}
}
static VkResult
get_image_format_properties(struct panvk_physical_device *physical_device,
const VkPhysicalDeviceImageFormatInfo2 *info,
VkImageFormatProperties *pImageFormatProperties,
VkFormatFeatureFlags *p_feature_flags)
{
VkFormatProperties format_props;
VkFormatFeatureFlags format_feature_flags;
VkExtent3D maxExtent;
uint32_t maxMipLevels;
uint32_t maxArraySize;
VkSampleCountFlags sampleCounts = VK_SAMPLE_COUNT_1_BIT;
enum pipe_format format = vk_format_to_pipe_format(info->format);
get_format_properties(physical_device, info->format, &format_props);
switch (info->tiling) {
case VK_IMAGE_TILING_LINEAR:
format_feature_flags = format_props.linearTilingFeatures;
break;
case VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT:
/* The only difference between optimal and linear is currently whether
* depth/stencil attachments are allowed on depth/stencil formats.
* There's no reason to allow importing depth/stencil textures, so just
* disallow it and then this annoying edge case goes away.
*
* TODO: If anyone cares, we could enable this by looking at the
* modifier and checking if it's LINEAR or not.
*/
if (util_format_is_depth_or_stencil(format))
goto unsupported;
assert(format_props.optimalTilingFeatures == format_props.linearTilingFeatures);
/* fallthrough */
case VK_IMAGE_TILING_OPTIMAL:
format_feature_flags = format_props.optimalTilingFeatures;
break;
default:
unreachable("bad VkPhysicalDeviceImageFormatInfo2");
}
if (format_feature_flags == 0)
goto unsupported;
if (info->type != VK_IMAGE_TYPE_2D &&
util_format_is_depth_or_stencil(format))
goto unsupported;
switch (info->type) {
default:
unreachable("bad vkimage type\n");
case VK_IMAGE_TYPE_1D:
maxExtent.width = 16384;
maxExtent.height = 1;
maxExtent.depth = 1;
maxMipLevels = 15; /* log2(maxWidth) + 1 */
maxArraySize = 2048;
break;
case VK_IMAGE_TYPE_2D:
maxExtent.width = 16384;
maxExtent.height = 16384;
maxExtent.depth = 1;
maxMipLevels = 15; /* log2(maxWidth) + 1 */
maxArraySize = 2048;
break;
case VK_IMAGE_TYPE_3D:
maxExtent.width = 2048;
maxExtent.height = 2048;
maxExtent.depth = 2048;
maxMipLevels = 12; /* log2(maxWidth) + 1 */
maxArraySize = 1;
break;
}
if (info->tiling == VK_IMAGE_TILING_OPTIMAL &&
info->type == VK_IMAGE_TYPE_2D &&