1/*
2 * Copyright © 2014 Broadcom
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24#ifndef VC4_TILING_H
25#define VC4_TILING_H
26
27#include <stdbool.h>
28#include <stdint.h>
29#include "util/macros.h"
30#include "util/u_cpu_detect.h"
31
32/** Return the width in pixels of a 64-byte microtile. */
33static inline uint32_t
34vc4_utile_width(int cpp)
35{
36        switch (cpp) {
37        case 1:
38        case 2:
39                return 8;
40        case 4:
41                return 4;
42        case 8:
43                return 2;
44        default:
45                unreachable("unknown cpp");
46        }
47}
48
49/** Return the height in pixels of a 64-byte microtile. */
50static inline uint32_t
51vc4_utile_height(int cpp)
52{
53        switch (cpp) {
54        case 1:
55                return 8;
56        case 2:
57        case 4:
58        case 8:
59                return 4;
60        default:
61                unreachable("unknown cpp");
62        }
63}
64
65bool vc4_size_is_lt(uint32_t width, uint32_t height, int cpp) ATTRIBUTE_CONST;
66void vc4_load_lt_image_base(void *dst, uint32_t dst_stride,
67                            void *src, uint32_t src_stride,
68                            int cpp, const struct pipe_box *box);
69void vc4_store_lt_image_base(void *dst, uint32_t dst_stride,
70                             void *src, uint32_t src_stride,
71                             int cpp, const struct pipe_box *box);
72void vc4_load_lt_image_neon(void *dst, uint32_t dst_stride,
73                            void *src, uint32_t src_stride,
74                            int cpp, const struct pipe_box *box);
75void vc4_store_lt_image_neon(void *dst, uint32_t dst_stride,
76                             void *src, uint32_t src_stride,
77                             int cpp, const struct pipe_box *box);
78void vc4_load_tiled_image(void *dst, uint32_t dst_stride,
79                          void *src, uint32_t src_stride,
80                          uint8_t tiling_format, int cpp,
81                          const struct pipe_box *box);
82void vc4_store_tiled_image(void *dst, uint32_t dst_stride,
83                           void *src, uint32_t src_stride,
84                           uint8_t tiling_format, int cpp,
85                           const struct pipe_box *box);
86
87static inline void
88vc4_load_lt_image(void *dst, uint32_t dst_stride,
89                  void *src, uint32_t src_stride,
90                  int cpp, const struct pipe_box *box)
91{
92#ifdef USE_ARM_ASM
93        if (util_get_cpu_caps()->has_neon) {
94                vc4_load_lt_image_neon(dst, dst_stride, src, src_stride,
95                                       cpp, box);
96                return;
97        }
98#endif
99        vc4_load_lt_image_base(dst, dst_stride, src, src_stride,
100                               cpp, box);
101}
102
103static inline void
104vc4_store_lt_image(void *dst, uint32_t dst_stride,
105                   void *src, uint32_t src_stride,
106                   int cpp, const struct pipe_box *box)
107{
108#ifdef USE_ARM_ASM
109        if (util_get_cpu_caps()->has_neon) {
110                vc4_store_lt_image_neon(dst, dst_stride, src, src_stride,
111                                        cpp, box);
112                return;
113        }
114#endif
115
116        vc4_store_lt_image_base(dst, dst_stride, src, src_stride,
117                                cpp, box);
118}
119
120#endif /* VC4_TILING_H */
121