diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index 02c95c1413a..8714dcea343 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -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 |= diff --git a/src/panfrost/lib/pan_device.h b/src/panfrost/lib/pan_device.h index 104e52da4a5..f629d6979d8 100644 --- a/src/panfrost/lib/pan_device.h +++ b/src/panfrost/lib/pan_device.h @@ -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 * diff --git a/src/panfrost/lib/pan_props.c b/src/panfrost/lib/pan_props.c index 5650c338cde..656174b5630 100644 --- a/src/panfrost/lib/pan_props.c +++ b/src/panfrost/lib/pan_props.c @@ -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: diff --git a/src/panfrost/lib/pan_samples.c b/src/panfrost/lib/pan_samples.c index 5ee569c2c90..02b60caa804 100644 --- a/src/panfrost/lib/pan_samples.c +++ b/src/panfrost/lib/pan_samples.c @@ -21,8 +21,9 @@ * SOFTWARE. */ -#include "pan_bo.h" -#include "pan_device.h" +#include + +#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)); } diff --git a/src/panfrost/lib/pan_samples.h b/src/panfrost/lib/pan_samples.h new file mode 100644 index 00000000000..f50d47ddd39 --- /dev/null +++ b/src/panfrost/lib/pan_samples.h @@ -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 + +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 diff --git a/src/panfrost/vulkan/panvk_vX_cmd_buffer.c b/src/panfrost/vulkan/panvk_vX_cmd_buffer.c index cf760c64cec..20fbaa39edf 100644 --- a/src/panfrost/vulkan/panvk_vX_cmd_buffer.c +++ b/src/panfrost/vulkan/panvk_vX_cmd_buffer.c @@ -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,