1 /*
2 * Copyright (c) 2018-2019 Lima Project
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, sub license,
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
12 * next paragraph) shall be included in all copies or substantial portions
13 * of the 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 NON-INFRINGEMENT. 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
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
25 #ifndef H_LIMA_TEXTURE
26 #define H_LIMA_TEXTURE
27
28 #define lima_min_tex_desc_size 64
29
30 #define LIMA_SAMPLER_DIM_1D 0
31 #define LIMA_SAMPLER_DIM_2D 1
32 #define LIMA_SAMPLER_DIM_3D 2
33
34 #define LIMA_TEX_WRAP_REPEAT 0
35 #define LIMA_TEX_WRAP_CLAMP_TO_EDGE 1
36 #define LIMA_TEX_WRAP_CLAMP 2
37 #define LIMA_TEX_WRAP_CLAMP_TO_BORDER 3
38 #define LIMA_TEX_WRAP_MIRROR_REPEAT 4
39 #define LIMA_TEX_WRAP_MIRROR_CLAMP_TO_EDGE 5
40 #define LIMA_TEX_WRAP_MIRROR_CLAMP 6
41 #define LIMA_TEX_WRAP_MIRROR_CLAMP_TO_BORDER 7
42
43 typedef struct __attribute__((__packed__)) {
44 /* Word 0 */
45 uint32_t format : 6;
46 uint32_t flag1: 1;
47 uint32_t swap_r_b: 1;
48 uint32_t unknown_0_1: 8;
49 uint32_t stride: 15;
50 uint32_t unknown_0_2: 1;
51
52 /* Word 1-3 */
53 uint32_t unknown_1_1: 7;
54 uint32_t unnorm_coords: 1;
55 uint32_t unknown_1_2: 1;
56 uint32_t cube_map: 1;
57 uint32_t sampler_dim: 2;
58 uint32_t min_lod: 8; /* Fixed point, 4.4, unsigned */
59 uint32_t max_lod: 8; /* Fixed point, 4.4, unsigned */
60 uint32_t lod_bias: 9; /* Fixed point, signed, 1.4.4 */
61 uint32_t unknown_2_1: 3;
62 uint32_t has_stride: 1;
63 uint32_t min_mipfilter_2: 2; /* 0x3 for linear, 0x0 for nearest */
64 uint32_t min_img_filter_nearest: 1;
65 uint32_t mag_img_filter_nearest: 1;
66 uint32_t wrap_s: 3;
67 uint32_t wrap_t: 3;
68 uint32_t wrap_r: 3;
69 uint32_t width: 13;
70 uint32_t height: 13;
71 uint32_t depth: 13;
72
73 uint32_t border_red: 16;
74 uint32_t border_green: 16;
75 uint32_t border_blue: 16;
76 uint32_t border_alpha: 16;
77
78 /* Word 5 (last 3 bits) */
79 uint32_t unknown_5_1: 3;
80
81 /* Word 6-15 */
82 /* layout is in va[0] bit 13-14 */
83 /* VAs start in va[0] at bit 30, each VA is 26 bits (only MSBs are stored), stored
84 * linearly in memory */
85 union {
86 uint32_t va[0];
87 struct __attribute__((__packed__)) {
88 uint32_t unknown_6_1: 13;
89 uint32_t layout: 2;
90 uint32_t unknown_6_2: 9;
91 uint32_t unknown_6_3: 6;
92 #define VA_BIT_OFFSET 30
93 #define VA_BIT_SIZE 26
94 uint32_t va_0: VA_BIT_SIZE;
95 uint32_t va_0_1: 8;
96 uint32_t va_1_x[0];
97 } va_s;
98 };
99 } lima_tex_desc;
100
101 void lima_texture_desc_set_res(struct lima_context *ctx, lima_tex_desc *desc,
102 struct pipe_resource *prsc,
103 unsigned first_level, unsigned last_level,
104 unsigned first_layer, unsigned mrt_idx);
105 void lima_update_textures(struct lima_context *ctx);
106
107
lima_float_to_fixed8(float f)108 static inline int16_t lima_float_to_fixed8(float f)
109 {
110 return (int)(f * 16.0);
111 }
112
lima_fixed8_to_float(int16_t i)113 static inline float lima_fixed8_to_float(int16_t i)
114 {
115 float sign = 1.0;
116
117 if (i > 0xff) {
118 i = 0x200 - i;
119 sign = -1;
120 }
121
122 return sign * (float)(i / 16.0);
123 }
124
125 #endif
126