17ec681f3Smrg/*
27ec681f3Smrg * Copyright (C) 2008 VMware, Inc.
37ec681f3Smrg * Copyright (C) 2014 Broadcom
47ec681f3Smrg * Copyright (C) 2018-2019 Alyssa Rosenzweig
57ec681f3Smrg * Copyright (C) 2019-2020 Collabora, Ltd.
67ec681f3Smrg *
77ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
87ec681f3Smrg * copy of this software and associated documentation files (the "Software"),
97ec681f3Smrg * to deal in the Software without restriction, including without limitation
107ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
117ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the
127ec681f3Smrg * Software is furnished to do so, subject to the following conditions:
137ec681f3Smrg *
147ec681f3Smrg * The above copyright notice and this permission notice (including the next
157ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the
167ec681f3Smrg * Software.
177ec681f3Smrg *
187ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
197ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
207ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
217ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
227ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
237ec681f3Smrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
247ec681f3Smrg * SOFTWARE.
257ec681f3Smrg *
267ec681f3Smrg */
277ec681f3Smrg
287ec681f3Smrg#ifndef __PAN_FORMAT_H
297ec681f3Smrg#define __PAN_FORMAT_H
307ec681f3Smrg
317ec681f3Smrg#include "genxml/gen_macros.h"
327ec681f3Smrg
337ec681f3Smrg#include "util/format/u_format.h"
347ec681f3Smrg
357ec681f3Smrg/* Formats */
367ec681f3Smrg
377ec681f3Smrgtypedef uint32_t mali_pixel_format;
387ec681f3Smrg
397ec681f3Smrgstruct panfrost_format {
407ec681f3Smrg        mali_pixel_format hw;
417ec681f3Smrg        unsigned bind;
427ec681f3Smrg};
437ec681f3Smrg
447ec681f3Smrgstruct pan_blendable_format {
457ec681f3Smrg        /* enum mali_color_buffer_internal_format */ uint16_t internal;
467ec681f3Smrg        /* enum mali_mfbd_color_format */ uint16_t writeback;
477ec681f3Smrg
487ec681f3Smrg        /* Indexed by the dithered? flag. So _PU first, then _AU */
497ec681f3Smrg        mali_pixel_format bifrost[2];
507ec681f3Smrg};
517ec681f3Smrg
527ec681f3Smrgextern const struct pan_blendable_format panfrost_blendable_formats_v6[PIPE_FORMAT_COUNT];
537ec681f3Smrgextern const struct pan_blendable_format panfrost_blendable_formats_v7[PIPE_FORMAT_COUNT];
547ec681f3Smrgextern const struct panfrost_format panfrost_pipe_format_v6[PIPE_FORMAT_COUNT];
557ec681f3Smrgextern const struct panfrost_format panfrost_pipe_format_v7[PIPE_FORMAT_COUNT];
567ec681f3Smrg
577ec681f3Smrg/* Helpers to construct swizzles */
587ec681f3Smrg
597ec681f3Smrg#define PAN_V6_SWIZZLE(R, G, B, A) ( \
607ec681f3Smrg        ((MALI_CHANNEL_ ## R) << 0) | \
617ec681f3Smrg        ((MALI_CHANNEL_ ## G) << 3) | \
627ec681f3Smrg        ((MALI_CHANNEL_ ## B) << 6) | \
637ec681f3Smrg        ((MALI_CHANNEL_ ## A) << 9))
647ec681f3Smrg
657ec681f3Smrgstatic inline unsigned
667ec681f3Smrgpanfrost_get_default_swizzle(unsigned components)
677ec681f3Smrg{
687ec681f3Smrg        switch (components) {
697ec681f3Smrg        case 1:
707ec681f3Smrg                return PAN_V6_SWIZZLE(R, 0, 0, 1);
717ec681f3Smrg        case 2:
727ec681f3Smrg                return PAN_V6_SWIZZLE(R, G, 0, 1);
737ec681f3Smrg        case 3:
747ec681f3Smrg                return PAN_V6_SWIZZLE(R, G, B, 1);
757ec681f3Smrg        case 4:
767ec681f3Smrg                return PAN_V6_SWIZZLE(R, G, B, A);
777ec681f3Smrg        default:
787ec681f3Smrg                unreachable("Invalid number of components");
797ec681f3Smrg        }
807ec681f3Smrg}
817ec681f3Smrg
827ec681f3Smrg#endif
83