panfrost: Make pan_sample.c panfrost_device agnostic

In order to do that, we create a pan_sample.h header, and make it so
the buffer allocation is left to the caller.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Constantine Shablya <constantine.shablya@collabora.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26698>
This commit is contained in:
Boris Brezillon 2023-12-07 17:21:15 +01:00 committed by Marge Bot
parent 387882d811
commit 0651b8871b
6 changed files with 63 additions and 23 deletions

View file

@ -51,6 +51,7 @@
#include "pan_job.h"
#include "pan_pool.h"
#include "pan_resource.h"
#include "pan_samples.h"
#include "pan_shader.h"
#include "pan_texture.h"
#include "pan_util.h"
@ -1114,7 +1115,8 @@ panfrost_upload_sample_positions_sysval(struct panfrost_batch *batch,
unsigned samples = util_framebuffer_get_num_samples(&batch->key);
uniform->du[0] =
panfrost_sample_positions(dev, panfrost_sample_pattern(samples));
dev->sample_positions->ptr.gpu +
panfrost_sample_positions_offset(panfrost_sample_pattern(samples));
}
static void
@ -2502,7 +2504,8 @@ emit_fbd(struct panfrost_batch *batch, struct pan_fb_info *fb)
#if PAN_ARCH >= 6
fb->sample_positions =
panfrost_sample_positions(dev, pan_sample_pattern(fb->nr_samples));
dev->sample_positions->ptr.gpu +
panfrost_sample_positions_offset(pan_sample_pattern(fb->nr_samples));
#endif
batch->framebuffer.gpu |=

View file

@ -256,11 +256,6 @@ void panfrost_close_device(struct panfrost_device *dev);
bool panfrost_supports_compressed_format(struct panfrost_device *dev,
unsigned fmt);
void panfrost_upload_sample_positions(struct panfrost_device *dev);
mali_ptr panfrost_sample_positions(const struct panfrost_device *dev,
enum mali_sample_pattern pattern);
unsigned panfrost_query_l2_slices(const struct panfrost_device *dev);
static inline struct panfrost_bo *

View file

@ -34,6 +34,7 @@
#include "pan_bo.h"
#include "pan_device.h"
#include "pan_encoder.h"
#include "pan_samples.h"
#include "pan_texture.h"
#include "pan_util.h"
#include "wrap.h"
@ -274,7 +275,9 @@ panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev)
pthread_mutex_init(&dev->submit_lock, NULL);
/* Done once on init */
panfrost_upload_sample_positions(dev);
dev->sample_positions = panfrost_bo_create(
dev, panfrost_sample_positions_buffer_size(), 0, "Sample positions");
panfrost_upload_sample_positions(dev->sample_positions->ptr.cpu);
return;
err_free_kmod_dev:

View file

@ -21,8 +21,9 @@
* SOFTWARE.
*/
#include "pan_bo.h"
#include "pan_device.h"
#include <stdint.h>
#include "pan_samples.h"
/* Sample positions are specified partially in hardware, partially in software
* on Mali. On Midgard, sample positions are completely fixed but need to be
@ -127,21 +128,21 @@ const struct mali_sample_positions sample_position_lut[] = {
};
/* clang-format on */
mali_ptr
panfrost_sample_positions(const struct panfrost_device *dev,
enum mali_sample_pattern pattern)
unsigned panfrost_sample_positions_buffer_size(void)
{
return sizeof(sample_position_lut);
}
unsigned
panfrost_sample_positions_offset(enum mali_sample_pattern pattern)
{
assert(pattern < ARRAY_SIZE(sample_position_lut));
unsigned offset = (pattern * sizeof(sample_position_lut[0]));
return dev->sample_positions->ptr.gpu + offset;
return offset;
}
void
panfrost_upload_sample_positions(struct panfrost_device *dev)
panfrost_upload_sample_positions(void *buffer)
{
STATIC_ASSERT(sizeof(sample_position_lut) < 4096);
dev->sample_positions = panfrost_bo_create(dev, 4096, 0, "Sample positions");
memcpy(dev->sample_positions->ptr.cpu, sample_position_lut,
sizeof(sample_position_lut));
memcpy(buffer, sample_position_lut, sizeof(sample_position_lut));
}

View file

@ -0,0 +1,35 @@
/*
* Copyright (C) 2019 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 PAN_SAMPLES_H
#define PAN_SAMPLES_H
#include <genxml/gen_macros.h>
unsigned panfrost_sample_positions_buffer_size(void);
void panfrost_upload_sample_positions(void *buffer);
unsigned panfrost_sample_positions_offset(enum mali_sample_pattern pattern);
#endif

View file

@ -34,6 +34,7 @@
#include "pan_blitter.h"
#include "pan_desc.h"
#include "pan_encoder.h"
#include "pan_samples.h"
#include "util/rounding.h"
#include "util/u_pack_color.h"
@ -132,9 +133,11 @@ panvk_per_arch(cmd_close_batch)(struct panvk_cmd_buffer *cmdbuf)
GENX(pan_emit_tls)(&batch->tlsinfo, batch->tls.cpu);
if (batch->fb.desc.cpu) {
fbinfo->sample_positions =
panfrost_sample_positions(&cmdbuf->device->physical_device->pdev,
pan_sample_pattern(fbinfo->nr_samples));
struct panfrost_device *pdev = &cmdbuf->device->physical_device->pdev;
fbinfo->sample_positions = pdev->sample_positions->ptr.gpu +
panfrost_sample_positions_offset(
pan_sample_pattern(fbinfo->nr_samples));
batch->fb.desc.gpu |=
GENX(pan_emit_fbd)(&cmdbuf->state.fb.info, &batch->tlsinfo,