19f464c52Smaya/* 29f464c52Smaya * Copyright (c) 2018-2019 Lima Project 39f464c52Smaya * 49f464c52Smaya * Permission is hereby granted, free of charge, to any person obtaining a 59f464c52Smaya * copy of this software and associated documentation files (the "Software"), 69f464c52Smaya * to deal in the Software without restriction, including without limitation 79f464c52Smaya * the rights to use, copy, modify, merge, publish, distribute, sub license, 89f464c52Smaya * and/or sell copies of the Software, and to permit persons to whom the 99f464c52Smaya * Software is furnished to do so, subject to the following conditions: 109f464c52Smaya * 119f464c52Smaya * The above copyright notice and this permission notice (including the 129f464c52Smaya * next paragraph) shall be included in all copies or substantial portions 139f464c52Smaya * of the Software. 149f464c52Smaya * 159f464c52Smaya * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 169f464c52Smaya * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 179f464c52Smaya * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 189f464c52Smaya * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 199f464c52Smaya * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 209f464c52Smaya * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 219f464c52Smaya * DEALINGS IN THE SOFTWARE. 229f464c52Smaya * 239f464c52Smaya */ 249f464c52Smaya 259f464c52Smaya#ifndef H_LIMA_TEXTURE 269f464c52Smaya#define H_LIMA_TEXTURE 279f464c52Smaya 287ec681f3Smrg#define lima_min_tex_desc_size 64 299f464c52Smaya 307ec681f3Smrg#define LIMA_TEXTURE_TYPE_2D 2 317ec681f3Smrg#define LIMA_TEXTURE_TYPE_CUBE 5 327ec681f3Smrg 337ec681f3Smrgtypedef struct __attribute__((__packed__)) { 347ec681f3Smrg /* Word 0 */ 357ec681f3Smrg uint32_t format : 6; 367ec681f3Smrg uint32_t flag1: 1; 377ec681f3Smrg uint32_t swap_r_b: 1; 387ec681f3Smrg uint32_t unknown_0_1: 8; 397ec681f3Smrg uint32_t stride: 15; 407ec681f3Smrg uint32_t unknown_0_2: 1; 417ec681f3Smrg 427ec681f3Smrg /* Word 1-3 */ 437ec681f3Smrg uint32_t unknown_1_1: 7; 447ec681f3Smrg uint32_t unnorm_coords: 1; 457ec681f3Smrg uint32_t unknown_1_2: 1; 467ec681f3Smrg uint32_t texture_type: 3; 477ec681f3Smrg uint32_t min_lod: 8; /* Fixed point, 4.4, unsigned */ 487ec681f3Smrg uint32_t max_lod: 8; /* Fixed point, 4.4, unsigned */ 497ec681f3Smrg uint32_t lod_bias: 9; /* Fixed point, signed, 1.4.4 */ 507ec681f3Smrg uint32_t unknown_2_1: 3; 517ec681f3Smrg uint32_t has_stride: 1; 527ec681f3Smrg uint32_t min_mipfilter_2: 2; /* 0x3 for linear, 0x0 for nearest */ 537ec681f3Smrg uint32_t min_img_filter_nearest: 1; 547ec681f3Smrg uint32_t mag_img_filter_nearest: 1; 557ec681f3Smrg uint32_t wrap_s_clamp_to_edge: 1; 567ec681f3Smrg uint32_t wrap_s_clamp: 1; 577ec681f3Smrg uint32_t wrap_s_mirror_repeat: 1; 587ec681f3Smrg uint32_t wrap_t_clamp_to_edge: 1; 597ec681f3Smrg uint32_t wrap_t_clamp: 1; 607ec681f3Smrg uint32_t wrap_t_mirror_repeat: 1; 617ec681f3Smrg uint32_t unknown_2_2: 3; 627ec681f3Smrg uint32_t width: 13; 637ec681f3Smrg uint32_t height: 13; 647ec681f3Smrg uint32_t unknown_3_1: 1; 657ec681f3Smrg uint32_t unknown_3_2: 15; 667ec681f3Smrg 677ec681f3Smrg /* Word 4 */ 687ec681f3Smrg uint32_t unknown_4; 697ec681f3Smrg 707ec681f3Smrg /* Word 5 */ 717ec681f3Smrg uint32_t unknown_5; 727ec681f3Smrg 737ec681f3Smrg /* Word 6-15 */ 747ec681f3Smrg /* layout is in va[0] bit 13-14 */ 757ec681f3Smrg /* VAs start in va[0] at bit 30, each VA is 26 bits (only MSBs are stored), stored 767ec681f3Smrg * linearly in memory */ 777ec681f3Smrg union { 787ec681f3Smrg uint32_t va[0]; 797ec681f3Smrg struct __attribute__((__packed__)) { 807ec681f3Smrg uint32_t unknown_6_1: 13; 817ec681f3Smrg uint32_t layout: 2; 827ec681f3Smrg uint32_t unknown_6_2: 9; 837ec681f3Smrg uint32_t unknown_6_3: 6; 847ec681f3Smrg#define VA_BIT_OFFSET 30 857ec681f3Smrg#define VA_BIT_SIZE 26 867ec681f3Smrg uint32_t va_0: VA_BIT_SIZE; 877ec681f3Smrg uint32_t va_0_1: 8; 887ec681f3Smrg uint32_t va_1_x[0]; 897ec681f3Smrg } va_s; 907ec681f3Smrg }; 917ec681f3Smrg} lima_tex_desc; 927ec681f3Smrg 937ec681f3Smrgvoid lima_texture_desc_set_res(struct lima_context *ctx, lima_tex_desc *desc, 949f464c52Smaya struct pipe_resource *prsc, 957ec681f3Smrg unsigned first_level, unsigned last_level, 967ec681f3Smrg unsigned first_layer); 979f464c52Smayavoid lima_update_textures(struct lima_context *ctx); 989f464c52Smaya 997ec681f3Smrg 1007ec681f3Smrgstatic inline int16_t lima_float_to_fixed8(float f) 1017ec681f3Smrg{ 1027ec681f3Smrg return (int)(f * 16.0); 1037ec681f3Smrg} 1047ec681f3Smrg 1057ec681f3Smrgstatic inline float lima_fixed8_to_float(int16_t i) 1067ec681f3Smrg{ 1077ec681f3Smrg float sign = 1.0; 1087ec681f3Smrg 1097ec681f3Smrg if (i > 0xff) { 1107ec681f3Smrg i = 0x200 - i; 1117ec681f3Smrg sign = -1; 1127ec681f3Smrg } 1137ec681f3Smrg 1147ec681f3Smrg return sign * (float)(i / 16.0); 1157ec681f3Smrg} 1167ec681f3Smrg 1179f464c52Smaya#endif 118