| 1 |
/* |
| 2 |
* Copyright (C) 2026 Arm Ltd. |
| 3 |
* |
| 4 |
* Derived from pan_texture.c which is: |
| 5 |
* Copyright (C) 2008 VMware, Inc. |
| 6 |
* Copyright (C) 2014 Broadcom |
| 7 |
* Copyright (C) 2018-2019 Alyssa Rosenzweig |
| 8 |
* Copyright (C) 2019-2020 Collabora, Ltd. |
| 9 |
* Copyright (C) 2024 Arm Ltd. |
| 10 |
* |
| 11 |
* SPDX-License-Identifier: MIT |
| 12 |
*/ |
| 13 |
|
| 14 |
#include "pan_buffer.h" |
| 15 |
#include "pan_desc.h" |
| 16 |
#include "pan_format.h" |
| 17 |
#include "pan_texture.h" |
| 18 |
#include "pan_util.h" |
| 19 |
|
| 20 |
#if PAN_ARCH >= 9 |
| 21 |
|
| 22 |
void |
| 23 |
GENX(pan_buffer_texture_emit)(const struct pan_buffer_view *bview, |
| 24 |
struct mali_buffer_packed *out) |
| 25 |
{ |
| 26 |
unsigned stride = util_format_get_blocksize(bview->format); |
| 27 |
struct MALI_INTERNAL_CONVERSION conv = { |
| 28 |
.memory_format = GENX(pan_format_from_pipe_format)(bview->format)->hw, |
| 29 |
.raw = false, |
| 30 |
}; |
| 31 |
|
| 32 |
uint64_t buffer_size = bview->width_el * stride; |
| 33 |
|
| 34 |
pan_pack(out, BUFFER, cfg) { |
| 35 |
cfg.type = MALI_DESCRIPTOR_TYPE_BUFFER; |
| 36 |
cfg.buffer_type = MALI_BUFFER_TYPE_STRUCTURE; |
| 37 |
|
| 38 |
#if PAN_ARCH >= 11 |
| 39 |
cfg.size = buffer_size & BITFIELD_MASK(32); |
| 40 |
cfg.size_hi = buffer_size >> 32; |
| 41 |
#else |
| 42 |
cfg.size = buffer_size; |
| 43 |
#endif |
| 44 |
|
| 45 |
cfg.address = bview->base; |
| 46 |
cfg.stride = stride; |
| 47 |
cfg.conversion = conv; |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
#elif PAN_ARCH >= 6 |
| 52 |
|
| 53 |
void |
| 54 |
GENX(pan_buffer_texture_emit)(const struct pan_buffer_view *bview, |
| 55 |
struct mali_attribute_buffer_packed *out_buf, |
| 56 |
struct mali_attribute_packed *out_attrib) |
| 57 |
{ |
| 58 |
unsigned stride = util_format_get_blocksize(bview->format); |
| 59 |
uint32_t hw_fmt = GENX(pan_format_from_pipe_format)(bview->format)->hw; |
| 60 |
|
| 61 |
/* The base address has shr(6) applied so we need to use the offset of the |
| 62 |
* attribute to get the last 6 bits. |
| 63 |
*/ |
| 64 |
uint64_t base = bview->base & ~0x3f; |
| 65 |
uint32_t offset = bview->base & 0x3f; |
| 66 |
|
| 67 |
pan_pack(out_buf, ATTRIBUTE_BUFFER, cfg) { |
| 68 |
cfg.type = MALI_ATTRIBUTE_TYPE_1D; |
| 69 |
cfg.pointer = base; |
| 70 |
cfg.stride = stride; |
| 71 |
/* The ATTRIBUTE_BUFFER.size specifies the size of the buffer starting |
| 72 |
* at ATTRIBUTE_BUFFER.pointer and and ATTRIBUTE.offset specifies an |
| 73 |
* offset into that window. If we're going to use it to offset the base |
| 74 |
* of the buffer, we need to increase the size as well. |
| 75 |
*/ |
| 76 |
cfg.size = bview->width_el * stride + offset; |
| 77 |
} |
| 78 |
|
| 79 |
pan_pack(out_attrib, ATTRIBUTE, cfg) { |
| 80 |
cfg.format = hw_fmt; |
| 81 |
cfg.offset = offset; |
| 82 |
cfg.offset_enable = offset != 0; |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
#else |
| 87 |
|
| 88 |
void |
| 89 |
GENX(pan_buffer_texture_emit)(const struct pan_buffer_view *bview, |
| 90 |
struct mali_texture_packed *out, |
| 91 |
const struct pan_ptr *payload) |
| 92 |
{ |
| 93 |
uint32_t mali_format = GENX(pan_format_from_pipe_format)(bview->format)->hw; |
| 94 |
static const unsigned char rgba_swizzle[4] = { |
| 95 |
PIPE_SWIZZLE_X, |
| 96 |
PIPE_SWIZZLE_Y, |
| 97 |
PIPE_SWIZZLE_Z, |
| 98 |
PIPE_SWIZZLE_W, |
| 99 |
}; |
| 100 |
|
| 101 |
pan_cast_and_pack(payload->cpu, SURFACE_WITH_STRIDE, cfg) { |
| 102 |
cfg.pointer = bview->base; |
| 103 |
cfg.row_stride = 0; |
| 104 |
cfg.surface_stride = 0; |
| 105 |
} |
| 106 |
|
| 107 |
pan_pack(out, TEXTURE, cfg) { |
| 108 |
cfg.dimension = MALI_TEXTURE_DIMENSION_1D; |
| 109 |
cfg.format = mali_format; |
| 110 |
cfg.width = bview->width_el; |
| 111 |
cfg.height = 1; |
| 112 |
cfg.sample_count = 1; |
| 113 |
cfg.swizzle = pan_translate_swizzle_4(rgba_swizzle); |
| 114 |
cfg.texel_ordering = MALI_TEXTURE_LAYOUT_LINEAR; |
| 115 |
cfg.levels = 1; |
| 116 |
cfg.array_size = 1; |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
#endif |