panfrost: Prepare blend helpers to per-gen XML

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12935>
This commit is contained in:
Boris Brezillon 2021-08-06 11:46:20 +02:00
parent f68c9a575b
commit e145a5fdd4
7 changed files with 104 additions and 75 deletions

View file

@ -38,6 +38,7 @@
#include "pan_pool.h"
#include "pan_bo.h"
#include "pan_blend.h"
#include "pan_context.h"
#include "pan_job.h"
#include "pan_shader.h"
@ -918,7 +919,7 @@ panfrost_upload_rt_conversion_sysval(struct panfrost_batch *batch,
if (rt < batch->key.nr_cbufs && batch->key.cbufs[rt]) {
enum pipe_format format = batch->key.cbufs[rt]->format;
uniform->u[0] =
pan_blend_get_bifrost_desc(dev, format, rt, size, false) >> 32;
GENX(pan_blend_get_internal_desc)(dev, format, rt, size, false) >> 32;
} else {
pan_pack(&uniform->u[0], BIFROST_INTERNAL_CONVERSION, cfg)
cfg.memory_format = dev->formats[PIPE_FORMAT_NONE].hw;
@ -3666,6 +3667,7 @@ GENX(panfrost_cmdstream_screen_init)(struct panfrost_screen *screen)
screen->vtbl.preload = preload;
screen->vtbl.context_init = context_init;
screen->vtbl.init_batch = init_batch;
screen->vtbl.get_blend_shader = GENX(pan_blend_get_shader_locked);
screen->vtbl.init_polygon_list = init_polygon_list;
GENX(pan_blitter_init)(dev, &screen->blitter.bin_pool.base,

View file

@ -200,8 +200,11 @@ panfrost_get_blend(struct panfrost_batch *batch, unsigned rti, struct panfrost_b
pthread_mutex_lock(&dev->blend_shaders.lock);
struct pan_blend_shader_variant *shader =
pan_blend_get_shader_locked(dev, &pan_blend,
col0_type, col1_type, rti);
pan_screen(ctx->base.screen)->vtbl.get_blend_shader(dev,
&pan_blend,
col0_type,
col1_type,
rti);
/* Size check and upload */
unsigned offset = *shader_offset;

View file

@ -46,6 +46,7 @@ struct panfrost_context;
struct panfrost_resource;
struct panfrost_shader_state;
struct pan_fb_info;
struct pan_blend_state;
/* Virtual table of per-generation (GenXML) functions */
@ -77,6 +78,13 @@ struct panfrost_vtable {
/* Device-dependent initialization of a panfrost_batch */
void (*init_batch)(struct panfrost_batch *batch);
/* Get blend shader */
struct pan_blend_shader_variant *
(*get_blend_shader)(const struct panfrost_device *,
const struct pan_blend_state *,
nir_alu_type, nir_alu_type,
unsigned rt);
/* Initialize the polygon list */
void (*init_polygon_list)(struct panfrost_batch *);
};

View file

@ -54,6 +54,7 @@ foreach ver : ['4', '5', '6', '7']
libpanfrost_per_arch += static_library(
'pan-arch-v' + ver,
[
'pan_blend.c',
'pan_blitter.c',
'pan_indirect_dispatch.c',
'pan_indirect_draw.c',

View file

@ -32,7 +32,7 @@
#include "compiler/nir/nir_conversion_builder.h"
#include "compiler/nir/nir_lower_blend.h"
#include <gen_macros.h>
#ifndef PAN_ARCH
/* Fixed function blending */
@ -376,6 +376,33 @@ pan_pack_blend(const struct pan_blend_equation equation)
return out;
}
static uint32_t pan_blend_shader_key_hash(const void *key)
{
return _mesa_hash_data(key, sizeof(struct pan_blend_shader_key));
}
static bool pan_blend_shader_key_equal(const void *a, const void *b)
{
return !memcmp(a, b, sizeof(struct pan_blend_shader_key));
}
void
pan_blend_shaders_init(struct panfrost_device *dev)
{
dev->blend_shaders.shaders =
_mesa_hash_table_create(NULL, pan_blend_shader_key_hash,
pan_blend_shader_key_equal);
pthread_mutex_init(&dev->blend_shaders.lock, NULL);
}
void
pan_blend_shaders_cleanup(struct panfrost_device *dev)
{
_mesa_hash_table_destroy(dev->blend_shaders.shaders, NULL);
}
#else /* ifndef PAN_ARCH */
static const char *
logicop_str(enum pipe_logicop logicop)
{
@ -481,11 +508,11 @@ pan_inline_blend_constants(nir_builder *b, nir_instr *instr, void *data)
}
nir_shader *
pan_blend_create_shader(const struct panfrost_device *dev,
const struct pan_blend_state *state,
nir_alu_type src0_type,
nir_alu_type src1_type,
unsigned rt)
GENX(pan_blend_create_shader)(const struct panfrost_device *dev,
const struct pan_blend_state *state,
nir_alu_type src0_type,
nir_alu_type src1_type,
unsigned rt)
{
const struct pan_blend_rt_state *rt_state = &state->rts[rt];
char equation_str[128] = { 0 };
@ -587,10 +614,11 @@ pan_blend_create_shader(const struct panfrost_device *dev,
return b.shader;
}
#if PAN_ARCH >= 6
uint64_t
pan_blend_get_bifrost_desc(const struct panfrost_device *dev,
enum pipe_format fmt, unsigned rt,
unsigned force_size, bool dithered)
GENX(pan_blend_get_internal_desc)(const struct panfrost_device *dev,
enum pipe_format fmt, unsigned rt,
unsigned force_size, bool dithered)
{
const struct util_format_description *desc = util_format_description(fmt);
uint64_t res;
@ -642,13 +670,14 @@ pan_blend_get_bifrost_desc(const struct panfrost_device *dev,
return res;
}
#endif
struct pan_blend_shader_variant *
pan_blend_get_shader_locked(const struct panfrost_device *dev,
const struct pan_blend_state *state,
nir_alu_type src0_type,
nir_alu_type src1_type,
unsigned rt)
GENX(pan_blend_get_shader_locked)(const struct panfrost_device *dev,
const struct pan_blend_state *state,
nir_alu_type src0_type,
nir_alu_type src1_type,
unsigned rt)
{
struct pan_blend_shader_key key = {
.format = state->rts[rt].format,
@ -695,7 +724,8 @@ pan_blend_get_shader_locked(const struct panfrost_device *dev,
util_dynarray_clear(&variant->binary);
}
nir_shader *nir = pan_blend_create_shader(dev, state, src0_type, src1_type, rt);
nir_shader *nir =
GENX(pan_blend_create_shader)(dev, state, src0_type, src1_type, rt);
/* Compile the NIR shader */
struct panfrost_compile_inputs inputs = {
@ -706,45 +736,23 @@ pan_blend_get_shader_locked(const struct panfrost_device *dev,
.rt_formats = { key.format },
};
if (pan_is_bifrost(dev)) {
inputs.blend.bifrost_blend_desc =
pan_blend_get_bifrost_desc(dev, key.format, key.rt, 0, false);
}
#if PAN_ARCH >= 6
inputs.blend.bifrost_blend_desc =
GENX(pan_blend_get_internal_desc)(dev, key.format, key.rt, 0, false);
#endif
struct pan_shader_info info;
pan_shader_compile(dev, nir, &inputs, &variant->binary, &info);
variant->work_reg_count = info.work_reg_count;
if (!pan_is_bifrost(dev))
variant->first_tag = info.midgard.first_tag;
#if PAN_ARCH <= 5
variant->first_tag = info.midgard.first_tag;
#endif
ralloc_free(nir);
return variant;
}
static uint32_t pan_blend_shader_key_hash(const void *key)
{
return _mesa_hash_data(key, sizeof(struct pan_blend_shader_key));
}
static bool pan_blend_shader_key_equal(const void *a, const void *b)
{
return !memcmp(a, b, sizeof(struct pan_blend_shader_key));
}
void
pan_blend_shaders_init(struct panfrost_device *dev)
{
dev->blend_shaders.shaders =
_mesa_hash_table_create(NULL, pan_blend_shader_key_hash,
pan_blend_shader_key_equal);
pthread_mutex_init(&dev->blend_shaders.lock, NULL);
}
void
pan_blend_shaders_cleanup(struct panfrost_device *dev)
{
_mesa_hash_table_destroy(dev->blend_shaders.shaders, NULL);
}
#endif /* ifndef PAN_ARCH */

View file

@ -25,6 +25,8 @@
#ifndef __PAN_BLEND_H__
#define __PAN_BLEND_H__
#include "gen_macros.h"
#include "util/u_dynarray.h"
#include "util/format/u_format.h"
#include "compiler/shader_enums.h"
@ -147,32 +149,37 @@ pan_blend_to_fixed_function_equation(const struct pan_blend_equation eq,
uint32_t
pan_pack_blend(const struct pan_blend_equation equation);
nir_shader *
pan_blend_create_shader(const struct panfrost_device *dev,
const struct pan_blend_state *state,
nir_alu_type src0_type,
nir_alu_type src1_type,
unsigned rt);
uint64_t
pan_blend_get_bifrost_desc(const struct panfrost_device *dev,
enum pipe_format fmt, unsigned rt,
unsigned force_size, bool dithered);
/* Take blend_shaders.lock before calling this function and release it when
* you're done with the shader variant object.
*/
struct pan_blend_shader_variant *
pan_blend_get_shader_locked(const struct panfrost_device *dev,
const struct pan_blend_state *state,
nir_alu_type src0_type,
nir_alu_type src1_type,
unsigned rt);
void
pan_blend_shaders_init(struct panfrost_device *dev);
void
pan_blend_shaders_cleanup(struct panfrost_device *dev);
#ifdef PAN_ARCH
nir_shader *
GENX(pan_blend_create_shader)(const struct panfrost_device *dev,
const struct pan_blend_state *state,
nir_alu_type src0_type,
nir_alu_type src1_type,
unsigned rt);
#if PAN_ARCH >= 6
uint64_t
GENX(pan_blend_get_internal_desc)(const struct panfrost_device *dev,
enum pipe_format fmt, unsigned rt,
unsigned force_size, bool dithered);
#endif
/* Take blend_shaders.lock before calling this function and release it when
* you're done with the shader variant object.
*/
struct pan_blend_shader_variant *
GENX(pan_blend_get_shader_locked)(const struct panfrost_device *dev,
const struct pan_blend_state *state,
nir_alu_type src0_type,
nir_alu_type src1_type,
unsigned rt);
#endif
#endif

View file

@ -377,10 +377,10 @@ pan_blitter_get_blend_shaders(struct panfrost_device *dev,
pthread_mutex_lock(&dev->blend_shaders.lock);
struct pan_blend_shader_variant *b =
pan_blend_get_shader_locked(dev, &blend_state,
blit_shader->blend_types[i],
nir_type_float32, /* unused */
i);
GENX(pan_blend_get_shader_locked)(dev, &blend_state,
blit_shader->blend_types[i],
nir_type_float32, /* unused */
i);
ASSERTED unsigned full_threads =
(dev->arch >= 7) ? 32 : ((dev->arch == 6) ? 64 : 4);