Commit 61d3ae6e authored by Alyssa Rosenzweig's avatar Alyssa Rosenzweig

panfrost: Initial stub for Panfrost driver

This patch adds an initial stub for the Gallium driver, containing
simple screen functions and the majority of the driver headers but no
actual functionality. It further adds the winsys glue for linking in
this stub driver via kmsro on Rockchip/Amlogic boards.
Signed-off-by: Alyssa Rosenzweig's avatarAlyssa Rosenzweig <alyssa@rosenzweig.io>
Acked-by: Jason Ekstrand's avatarJason Ekstrand <jason@jlekstrand.net>
Acked-by: Rob Clark's avatarRob Clark <robdclark@gmail.com>
Acked-by: Eric Anholt's avatarEric Anholt <eric@anholt.net>
Acked-by: default avatarEmil Velikov <emil.velikov@collabora.com>
parent 742d6cdb
......@@ -132,7 +132,7 @@ if _drivers.contains('auto')
elif ['arm', 'aarch64'].contains(host_machine.cpu_family())
_drivers = [
'kmsro', 'v3d', 'vc4', 'freedreno', 'etnaviv', 'nouveau',
'tegra', 'virgl', 'swrast',
'tegra', 'virgl', 'swrast', 'panfrost'
]
else
error('Unknown architecture @0@. Please pass -Dgallium-drivers to set driver options. Patches gladly accepted to fix this.'.format(
......@@ -154,6 +154,7 @@ with_gallium_freedreno = _drivers.contains('freedreno')
with_gallium_softpipe = _drivers.contains('swrast')
with_gallium_vc4 = _drivers.contains('vc4')
with_gallium_v3d = _drivers.contains('v3d')
with_gallium_panfrost = _drivers.contains('panfrost')
with_gallium_etnaviv = _drivers.contains('etnaviv')
with_gallium_tegra = _drivers.contains('tegra')
with_gallium_i915 = _drivers.contains('i915')
......@@ -209,8 +210,8 @@ endif
if with_dri_i915 and with_gallium_i915
error('Only one i915 provider can be built')
endif
if with_gallium_kmsro and not (with_gallium_vc4 or with_gallium_etnaviv or with_gallium_freedreno)
error('kmsro driver requires one or more renderonly drivers (vc4, etnaviv, freedreno)')
if with_gallium_kmsro and not (with_gallium_vc4 or with_gallium_etnaviv or with_gallium_freedreno or with_gallium_panfrost)
error('kmsro driver requires one or more renderonly drivers (vc4, etnaviv, freedreno, panfrost)')
endif
if with_gallium_tegra and not with_gallium_nouveau
error('tegra driver requires nouveau driver')
......
......@@ -60,7 +60,7 @@ option(
choices : [
'', 'auto', 'kmsro', 'radeonsi', 'r300', 'r600', 'nouveau', 'freedreno',
'swrast', 'v3d', 'vc4', 'etnaviv', 'tegra', 'i915', 'svga', 'virgl',
'swr',
'swr', 'panfrost'
],
description : 'List of gallium drivers to build. If this is set to auto all drivers applicable to the target OS/architecture will be built'
)
......
......@@ -121,6 +121,11 @@ static const struct drm_driver_descriptor driver_descriptors[] = {
.create_screen = pipe_vc4_create_screen,
.configuration = pipe_default_configuration_query,
},
{
.driver_name = "panfrost",
.create_screen = pipe_panfrost_create_screen,
.configuration = pipe_default_configuration_query,
},
{
.driver_name = "etnaviv",
.create_screen = pipe_etna_create_screen,
......
......@@ -333,6 +333,29 @@ pipe_v3d_create_screen(int fd, const struct pipe_screen_config *config)
#endif
#ifdef GALLIUM_PANFROST
#include "panfrost/drm/panfrost_drm_public.h"
struct pipe_screen *
pipe_panfrost_create_screen(int fd, const struct pipe_screen_config *config)
{
struct pipe_screen *screen;
screen = panfrost_drm_screen_create(fd);
return screen ? debug_screen_wrap(screen) : NULL;
}
#else
struct pipe_screen *
pipe_panfrost_create_screen(int fd, const struct pipe_screen_config *config)
{
fprintf(stderr, "panfrost: driver missing\n");
return NULL;
}
#endif
#ifdef GALLIUM_ETNAVIV
#include "etnaviv/drm/etnaviv_drm_public.h"
......
......@@ -42,6 +42,9 @@ pipe_v3d_create_screen(int fd, const struct pipe_screen_config *config);
struct pipe_screen *
pipe_vc4_create_screen(int fd, const struct pipe_screen_config *config);
struct pipe_screen *
pipe_panfrost_create_screen(int fd, const struct pipe_screen_config *config);
struct pipe_screen *
pipe_kmsro_create_screen(int fd, const struct pipe_screen_config *config);
......
[*.{c,h,cpp,hpp,cc,hh}]
indent_style = space
indent_size = 8
This diff is collapsed.
/*
* © Copyright 2017-2018 The Panfrost Community
*
* 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 __PANFROST_MISC_H__
#define __PANFROST_MISC_H__
#include <inttypes.h>
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
typedef uint64_t mali_ptr;
#define MALI_PTR_FMT "0x%" PRIx64
/* FIXME: put this somewhere more fitting */
#define MALI_MEM_MAP_TRACKING_HANDLE (3ull << 12)
#endif
# Copyright © 2017 Intel Corporation
# Copyright © 2018 Alyssa Rosenzweig
# 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.
files_panfrost = files(
'pan_public.h',
'pan_screen.c',
'pan_screen.h',
)
inc_panfrost = [
inc_common,
inc_gallium,
inc_gallium_aux,
inc_drm_uapi,
inc_include,
inc_src,
include_directories('include')
]
libpanfrost = static_library(
'panfrost',
[files_panfrost],
dependencies: [
dep_thread,
idep_nir
],
include_directories : inc_panfrost,
c_args : [c_vis_args, c_msvc_compat_args],
)
driver_panfrost = declare_dependency(
compile_args : ['-DGALLIUM_PANFROST', '-Wno-pointer-arith'],
link_with : [libpanfrost, libpanfrostwinsys],
)
/*
* © Copyright 2017-2018 Alyssa Rosenzweig
*
* 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 __PAN_ALLOCATE_H__
#define __PAN_ALLOCATE_H__
#include <unistd.h>
#include <sys/mman.h>
#include <stdbool.h>
#include "pipebuffer/pb_slab.h"
#include <panfrost-misc.h>
struct panfrost_context;
/* Texture memory */
#define HEAP_TEXTURE 0
/* Single-frame (transient) command stream memory, done at the block scale
* rather than the individual cmdstream alllocation scale. We use pb_alloc for
* pooling, but we have to implement our own logic atop the API for performance
* reasons when considering many low-latency tiny heterogenous allocations */
#define HEAP_TRANSIENT 1
/* Multi-frame descriptor memory (replaces what used to be
* cmdstream_persistent), for long-living small allocations */
#define HEAP_DESCRIPTOR 2
/* Represents a fat pointer for GPU-mapped memory, returned from the transient
* allocator and not used for much else */
struct panfrost_transfer {
uint8_t *cpu;
mali_ptr gpu;
};
struct panfrost_memory {
/* Subclassing slab object */
struct pb_slab slab;
/* Backing for the slab in memory */
uint8_t *cpu;
mali_ptr gpu;
int stack_bottom;
size_t size;
};
/* Slab entry sizes range from 2^min to 2^max. In this case, we range from 1k
* to 16MB. Numbers are kind of arbitrary but these seem to work alright in
* practice. */
#define MIN_SLAB_ENTRY_SIZE (10)
#define MAX_SLAB_ENTRY_SIZE (24)
struct panfrost_memory_entry {
/* Subclass */
struct pb_slab_entry base;
/* Have we been freed? */
bool freed;
/* Offset into the slab of the entry */
off_t offset;
};
/* Functions for replay */
mali_ptr pandev_upload(int cheating_offset, int *stack_bottom, mali_ptr base, void *base_map, const void *data, size_t sz, bool no_pad);
mali_ptr pandev_upload_sequential(mali_ptr base, void *base_map, const void *data, size_t sz);
/* Functions for the actual Galliumish driver */
mali_ptr panfrost_upload(struct panfrost_memory *mem, const void *data, size_t sz, bool no_pad);
mali_ptr panfrost_upload_sequential(struct panfrost_memory *mem, const void *data, size_t sz);
struct panfrost_transfer
panfrost_allocate_transient(struct panfrost_context *ctx, size_t sz);
mali_ptr
panfrost_upload_transient(struct panfrost_context *ctx, const void *data, size_t sz);
void *
panfrost_allocate_transfer(struct panfrost_memory *mem, size_t sz, mali_ptr *gpu);
static inline mali_ptr
panfrost_reserve(struct panfrost_memory *mem, size_t sz)
{
mem->stack_bottom += sz;
return mem->gpu + (mem->stack_bottom - sz);
}
struct panfrost_transfer
panfrost_allocate_chunk(struct panfrost_context *ctx, size_t size, unsigned heap_id);
#include <math.h>
#define inff INFINITY
#define R(...) #__VA_ARGS__
#define ALIGN(x, y) (((x) + ((y) - 1)) & ~((y) - 1))
#endif /* __PAN_ALLOCATE_H__ */
/*
* © Copyright 2018 Alyssa Rosenzweig
*
* 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 __BUILDER_H__
#define __BUILDER_H__
#define MFBD
#define _LARGEFILE64_SOURCE 1
#define CACHE_LINE_SIZE 1024 /* TODO */
#include <sys/mman.h>
#include <assert.h>
#include "pan_resource.h"
#include "pipe/p_compiler.h"
#include "pipe/p_config.h"
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_format.h"
#include "pipe/p_screen.h"
#include "pipe/p_state.h"
#include "util/u_blitter.h"
/* Forward declare to avoid extra header dep */
struct prim_convert_context;
/* TODO: Handle on newer hardware */
#ifdef MFBD
#define PANFROST_DEFAULT_FBD (MALI_MFBD)
#define PANFROST_FRAMEBUFFER struct bifrost_framebuffer
#else
#define PANFROST_DEFAULT_FBD (MALI_SFBD)
#define PANFROST_FRAMEBUFFER struct mali_single_framebuffer
#endif
#define MAX_DRAW_CALLS 4096
#define MAX_VARYINGS 4096
//#define PAN_DIRTY_CLEAR (1 << 0)
#define PAN_DIRTY_RASTERIZER (1 << 2)
#define PAN_DIRTY_FS (1 << 3)
#define PAN_DIRTY_FRAG_CORE (PAN_DIRTY_FS) /* Dirty writes are tied */
#define PAN_DIRTY_VS (1 << 4)
#define PAN_DIRTY_VERTEX (1 << 5)
#define PAN_DIRTY_VERT_BUF (1 << 6)
//#define PAN_DIRTY_VIEWPORT (1 << 7)
#define PAN_DIRTY_SAMPLERS (1 << 8)
#define PAN_DIRTY_TEXTURES (1 << 9)
struct panfrost_constant_buffer {
bool dirty;
size_t size;
void *buffer;
};
struct panfrost_query {
/* Passthrough from Gallium */
unsigned type;
unsigned index;
/* Memory for the GPU to writeback the value of the query */
struct panfrost_transfer transfer;
};
#define PANFROST_MAX_TRANSIENT_ENTRIES 64
struct panfrost_transient_pool {
/* Memory blocks in the pool */
struct panfrost_memory_entry *entries[PANFROST_MAX_TRANSIENT_ENTRIES];
/* Number of entries we own */
unsigned entry_count;
/* Current entry that we are writing to, zero-indexed, strictly less than entry_count */
unsigned entry_index;
/* Number of bytes into the current entry we are */
off_t entry_offset;
/* Entry size (all entries must be homogenous) */
size_t entry_size;
};
struct panfrost_context {
/* Gallium context */
struct pipe_context base;
struct pipe_framebuffer_state pipe_framebuffer;
/* The number of concurrent FBOs allowed depends on the number of pools
* used; pools are ringed for parallelism opportunities */
struct panfrost_transient_pool transient_pools[2];
int cmdstream_i;
struct panfrost_memory cmdstream_persistent;
struct panfrost_memory shaders;
struct panfrost_memory scratchpad;
struct panfrost_memory tiler_heap;
struct panfrost_memory varying_mem;
struct panfrost_memory misc_0;
struct panfrost_memory misc_1;
struct panfrost_memory depth_stencil_buffer;
struct {
unsigned buffers;
const union pipe_color_union *color;
double depth;
unsigned stencil;
} last_clear;
struct panfrost_query *occlusion_query;
/* Each render job has multiple framebuffer descriptors associated with
* it, used for various purposes with more or less the same format. The
* most obvious is the fragment framebuffer descriptor, which carries
* e.g. clearing information */
#ifdef SFBD
struct mali_single_framebuffer fragment_fbd;
#else
struct bifrost_framebuffer fragment_fbd;
struct bifrost_fb_extra fragment_extra;
struct bifrost_render_target fragment_rts[4];
#endif
/* Each draw has corresponding vertex and tiler payloads */
struct midgard_payload_vertex_tiler payload_vertex;
struct midgard_payload_vertex_tiler payload_tiler;
/* The fragment shader binary itself is pointed here (for the tripipe) but
* also everything else in the shader core, including blending, the
* stencil/depth tests, etc. Refer to the presentations. */
struct mali_shader_meta fragment_shader_core;
/* A frame is composed of a starting set value job, a number of vertex
* and tiler jobs, linked to the fragment job at the end. See the
* presentations for more information how this works */
unsigned draw_count;
mali_ptr set_value_job;
mali_ptr vertex_jobs[MAX_DRAW_CALLS];
mali_ptr tiler_jobs[MAX_DRAW_CALLS];
struct mali_job_descriptor_header *u_set_value_job;
struct mali_job_descriptor_header *u_vertex_jobs[MAX_DRAW_CALLS];
struct mali_job_descriptor_header *u_tiler_jobs[MAX_DRAW_CALLS];
unsigned vertex_job_count;
unsigned tiler_job_count;
/* Per-draw Dirty flags are setup like any other driver */
int dirty;
/* Per frame dirty flag - whether there was a clear. If not, we need to do a partial update, maybe */
bool frame_cleared;
unsigned vertex_count;
union mali_attr attributes[PIPE_MAX_ATTRIBS];
unsigned varying_height;
struct mali_viewport *viewport;
PANFROST_FRAMEBUFFER vt_framebuffer;
/* TODO: Multiple uniform buffers (index =/= 0), finer updates? */
struct panfrost_constant_buffer constant_buffer[PIPE_SHADER_TYPES];
/* CSOs */
struct panfrost_rasterizer *rasterizer;
struct panfrost_shader_variants *vs;
struct panfrost_shader_variants *fs;
struct panfrost_vertex_state *vertex;
struct pipe_vertex_buffer *vertex_buffers;
unsigned vertex_buffer_count;
struct panfrost_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
unsigned sampler_count[PIPE_SHADER_TYPES];
struct panfrost_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
unsigned sampler_view_count[PIPE_SHADER_TYPES];
struct primconvert_context *primconvert;
struct blitter_context *blitter;
struct panfrost_blend_state *blend;
struct pipe_viewport_state pipe_viewport;
struct pipe_scissor_state scissor;
struct pipe_blend_color blend_color;
struct pipe_depth_stencil_alpha_state *depth_stencil;
struct pipe_stencil_ref stencil_ref;
};
/* Corresponds to the CSO */
struct panfrost_rasterizer {
struct pipe_rasterizer_state base;
/* Bitmask of front face, etc */
unsigned tiler_gl_enables;
};
struct panfrost_blend_state {
struct pipe_blend_state base;
/* Whether a blend shader is in use */
bool has_blend_shader;
/* Compiled fixed function command */
struct mali_blend_equation equation;
/* Compiled blend shader */
mali_ptr blend_shader;
int blend_work_count;
};
/* Internal varyings descriptor */
struct panfrost_varyings {
/* Varyings information: stride of each chunk of memory used for
* varyings (similar structure with attributes). Count is just the
* number of vec4's. Buffer count is the number of varying chunks (<=
* count). Height is used to calculate gl_Position's position ("it's
* not a pun, Alyssa!"). Vertex-only varyings == descriptor for
* gl_Position and something else apparently occupying the same space.
* Varyings == main varyings descriptors following typical mali_attr
* conventions. */
unsigned varyings_stride[MAX_VARYINGS];
unsigned varying_count;
unsigned varying_buffer_count;
/* Map of the actual varyings buffer */
uint8_t *varyings_buffer_cpu;
mali_ptr varyings_descriptor;
mali_ptr varyings_descriptor_fragment;
};
/* Variants bundle together to form the backing CSO, bundling multiple
* shaders with varying emulated features baked in (alpha test
* parameters, etc) */
#define MAX_SHADER_VARIANTS 8
/* A shader state corresponds to the actual, current variant of the shader */
struct panfrost_shader_state {
struct pipe_shader_state *base;
/* Compiled, mapped descriptor, ready for the hardware */
bool compiled;
struct mali_shader_meta *tripipe;
mali_ptr tripipe_gpu;
/* Non-descript information */
int uniform_count;
bool can_discard;
bool writes_point_size;
/* Valid for vertex shaders only due to when this is calculated */
struct panfrost_varyings varyings;
/* Information on this particular shader variant */
struct pipe_alpha_state alpha_state;
};
/* A collection of varyings (the CSO) */
struct panfrost_shader_variants {
struct pipe_shader_state base;
struct panfrost_shader_state variants[MAX_SHADER_VARIANTS];
unsigned variant_count;
/* The current active variant */
unsigned active_variant;
};
struct panfrost_vertex_state {
unsigned num_elements;
struct pipe_vertex_element pipe[PIPE_MAX_ATTRIBS];
int nr_components[PIPE_MAX_ATTRIBS];
/* The actual attribute meta, prebaked and GPU mapped. TODO: Free memory */
struct mali_attr_meta *hw;
mali_ptr descriptor_ptr;
};