1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright 2009 Joakim Sindholt <opensource@zhasha.com> 3bf215546Sopenharmony_ci * Corbin Simpson <MostAwesomeDude@gmail.com> 4bf215546Sopenharmony_ci * 5bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 6bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 7bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 8bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub 9bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom 10bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions: 11bf215546Sopenharmony_ci * 12bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 13bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 14bf215546Sopenharmony_ci * Software. 15bf215546Sopenharmony_ci * 16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 19bf215546Sopenharmony_ci * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 20bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 21bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 22bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. */ 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ci#ifndef R300_STATE_INLINES_H 25bf215546Sopenharmony_ci#define R300_STATE_INLINES_H 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#include "draw/draw_vertex.h" 28bf215546Sopenharmony_ci#include "pipe/p_format.h" 29bf215546Sopenharmony_ci#include "util/format/u_format.h" 30bf215546Sopenharmony_ci#include "r300_reg.h" 31bf215546Sopenharmony_ci#include <stdio.h> 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_ci/* Some maths. These should probably find their way to u_math, if needed. */ 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_cistatic inline int pack_float_16_6x(float f) { 36bf215546Sopenharmony_ci return ((int)(f * 6.0) & 0xffff); 37bf215546Sopenharmony_ci} 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_ci/* Blend state. */ 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_cistatic inline uint32_t r300_translate_blend_function(int blend_func, 42bf215546Sopenharmony_ci boolean clamp) 43bf215546Sopenharmony_ci{ 44bf215546Sopenharmony_ci switch (blend_func) { 45bf215546Sopenharmony_ci case PIPE_BLEND_ADD: 46bf215546Sopenharmony_ci return clamp ? R300_COMB_FCN_ADD_CLAMP : R300_COMB_FCN_ADD_NOCLAMP; 47bf215546Sopenharmony_ci case PIPE_BLEND_SUBTRACT: 48bf215546Sopenharmony_ci return clamp ? R300_COMB_FCN_SUB_CLAMP : R300_COMB_FCN_SUB_NOCLAMP; 49bf215546Sopenharmony_ci case PIPE_BLEND_REVERSE_SUBTRACT: 50bf215546Sopenharmony_ci return clamp ? R300_COMB_FCN_RSUB_CLAMP : R300_COMB_FCN_RSUB_NOCLAMP; 51bf215546Sopenharmony_ci case PIPE_BLEND_MIN: 52bf215546Sopenharmony_ci return R300_COMB_FCN_MIN; 53bf215546Sopenharmony_ci case PIPE_BLEND_MAX: 54bf215546Sopenharmony_ci return R300_COMB_FCN_MAX; 55bf215546Sopenharmony_ci default: 56bf215546Sopenharmony_ci fprintf(stderr, "r300: Unknown blend function %d\n", blend_func); 57bf215546Sopenharmony_ci assert(0); 58bf215546Sopenharmony_ci break; 59bf215546Sopenharmony_ci } 60bf215546Sopenharmony_ci return 0; 61bf215546Sopenharmony_ci} 62bf215546Sopenharmony_ci 63bf215546Sopenharmony_cistatic inline uint32_t r300_translate_blend_factor(int blend_fact) 64bf215546Sopenharmony_ci{ 65bf215546Sopenharmony_ci switch (blend_fact) { 66bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_ONE: 67bf215546Sopenharmony_ci return R300_BLEND_GL_ONE; 68bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC_COLOR: 69bf215546Sopenharmony_ci return R300_BLEND_GL_SRC_COLOR; 70bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC_ALPHA: 71bf215546Sopenharmony_ci return R300_BLEND_GL_SRC_ALPHA; 72bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_DST_ALPHA: 73bf215546Sopenharmony_ci return R300_BLEND_GL_DST_ALPHA; 74bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_DST_COLOR: 75bf215546Sopenharmony_ci return R300_BLEND_GL_DST_COLOR; 76bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: 77bf215546Sopenharmony_ci return R300_BLEND_GL_SRC_ALPHA_SATURATE; 78bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_CONST_COLOR: 79bf215546Sopenharmony_ci return R300_BLEND_GL_CONST_COLOR; 80bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_CONST_ALPHA: 81bf215546Sopenharmony_ci return R300_BLEND_GL_CONST_ALPHA; 82bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_ZERO: 83bf215546Sopenharmony_ci return R300_BLEND_GL_ZERO; 84bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_SRC_COLOR: 85bf215546Sopenharmony_ci return R300_BLEND_GL_ONE_MINUS_SRC_COLOR; 86bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_SRC_ALPHA: 87bf215546Sopenharmony_ci return R300_BLEND_GL_ONE_MINUS_SRC_ALPHA; 88bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_DST_ALPHA: 89bf215546Sopenharmony_ci return R300_BLEND_GL_ONE_MINUS_DST_ALPHA; 90bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_DST_COLOR: 91bf215546Sopenharmony_ci return R300_BLEND_GL_ONE_MINUS_DST_COLOR; 92bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_CONST_COLOR: 93bf215546Sopenharmony_ci return R300_BLEND_GL_ONE_MINUS_CONST_COLOR; 94bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_CONST_ALPHA: 95bf215546Sopenharmony_ci return R300_BLEND_GL_ONE_MINUS_CONST_ALPHA; 96bf215546Sopenharmony_ci 97bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC1_COLOR: 98bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC1_ALPHA: 99bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_SRC1_COLOR: 100bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: 101bf215546Sopenharmony_ci fprintf(stderr, "r300: Implementation error: " 102bf215546Sopenharmony_ci "Bad blend factor %d not supported!\n", blend_fact); 103bf215546Sopenharmony_ci assert(0); 104bf215546Sopenharmony_ci break; 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_ci default: 107bf215546Sopenharmony_ci fprintf(stderr, "r300: Unknown blend factor %d\n", blend_fact); 108bf215546Sopenharmony_ci assert(0); 109bf215546Sopenharmony_ci break; 110bf215546Sopenharmony_ci } 111bf215546Sopenharmony_ci return 0; 112bf215546Sopenharmony_ci} 113bf215546Sopenharmony_ci 114bf215546Sopenharmony_ci/* DSA state. */ 115bf215546Sopenharmony_ci 116bf215546Sopenharmony_cistatic inline uint32_t r300_translate_depth_stencil_function(int zs_func) 117bf215546Sopenharmony_ci{ 118bf215546Sopenharmony_ci switch (zs_func) { 119bf215546Sopenharmony_ci case PIPE_FUNC_NEVER: 120bf215546Sopenharmony_ci return R300_ZS_NEVER; 121bf215546Sopenharmony_ci case PIPE_FUNC_LESS: 122bf215546Sopenharmony_ci return R300_ZS_LESS; 123bf215546Sopenharmony_ci case PIPE_FUNC_EQUAL: 124bf215546Sopenharmony_ci return R300_ZS_EQUAL; 125bf215546Sopenharmony_ci case PIPE_FUNC_LEQUAL: 126bf215546Sopenharmony_ci return R300_ZS_LEQUAL; 127bf215546Sopenharmony_ci case PIPE_FUNC_GREATER: 128bf215546Sopenharmony_ci return R300_ZS_GREATER; 129bf215546Sopenharmony_ci case PIPE_FUNC_NOTEQUAL: 130bf215546Sopenharmony_ci return R300_ZS_NOTEQUAL; 131bf215546Sopenharmony_ci case PIPE_FUNC_GEQUAL: 132bf215546Sopenharmony_ci return R300_ZS_GEQUAL; 133bf215546Sopenharmony_ci case PIPE_FUNC_ALWAYS: 134bf215546Sopenharmony_ci return R300_ZS_ALWAYS; 135bf215546Sopenharmony_ci default: 136bf215546Sopenharmony_ci fprintf(stderr, "r300: Unknown depth/stencil function %d\n", 137bf215546Sopenharmony_ci zs_func); 138bf215546Sopenharmony_ci assert(0); 139bf215546Sopenharmony_ci break; 140bf215546Sopenharmony_ci } 141bf215546Sopenharmony_ci return 0; 142bf215546Sopenharmony_ci} 143bf215546Sopenharmony_ci 144bf215546Sopenharmony_cistatic inline uint32_t r300_translate_stencil_op(int s_op) 145bf215546Sopenharmony_ci{ 146bf215546Sopenharmony_ci switch (s_op) { 147bf215546Sopenharmony_ci case PIPE_STENCIL_OP_KEEP: 148bf215546Sopenharmony_ci return R300_ZS_KEEP; 149bf215546Sopenharmony_ci case PIPE_STENCIL_OP_ZERO: 150bf215546Sopenharmony_ci return R300_ZS_ZERO; 151bf215546Sopenharmony_ci case PIPE_STENCIL_OP_REPLACE: 152bf215546Sopenharmony_ci return R300_ZS_REPLACE; 153bf215546Sopenharmony_ci case PIPE_STENCIL_OP_INCR: 154bf215546Sopenharmony_ci return R300_ZS_INCR; 155bf215546Sopenharmony_ci case PIPE_STENCIL_OP_DECR: 156bf215546Sopenharmony_ci return R300_ZS_DECR; 157bf215546Sopenharmony_ci case PIPE_STENCIL_OP_INCR_WRAP: 158bf215546Sopenharmony_ci return R300_ZS_INCR_WRAP; 159bf215546Sopenharmony_ci case PIPE_STENCIL_OP_DECR_WRAP: 160bf215546Sopenharmony_ci return R300_ZS_DECR_WRAP; 161bf215546Sopenharmony_ci case PIPE_STENCIL_OP_INVERT: 162bf215546Sopenharmony_ci return R300_ZS_INVERT; 163bf215546Sopenharmony_ci default: 164bf215546Sopenharmony_ci fprintf(stderr, "r300: Unknown stencil op %d", s_op); 165bf215546Sopenharmony_ci assert(0); 166bf215546Sopenharmony_ci break; 167bf215546Sopenharmony_ci } 168bf215546Sopenharmony_ci return 0; 169bf215546Sopenharmony_ci} 170bf215546Sopenharmony_ci 171bf215546Sopenharmony_cistatic inline uint32_t r300_translate_alpha_function(int alpha_func) 172bf215546Sopenharmony_ci{ 173bf215546Sopenharmony_ci switch (alpha_func) { 174bf215546Sopenharmony_ci case PIPE_FUNC_NEVER: 175bf215546Sopenharmony_ci return R300_FG_ALPHA_FUNC_NEVER; 176bf215546Sopenharmony_ci case PIPE_FUNC_LESS: 177bf215546Sopenharmony_ci return R300_FG_ALPHA_FUNC_LESS; 178bf215546Sopenharmony_ci case PIPE_FUNC_EQUAL: 179bf215546Sopenharmony_ci return R300_FG_ALPHA_FUNC_EQUAL; 180bf215546Sopenharmony_ci case PIPE_FUNC_LEQUAL: 181bf215546Sopenharmony_ci return R300_FG_ALPHA_FUNC_LE; 182bf215546Sopenharmony_ci case PIPE_FUNC_GREATER: 183bf215546Sopenharmony_ci return R300_FG_ALPHA_FUNC_GREATER; 184bf215546Sopenharmony_ci case PIPE_FUNC_NOTEQUAL: 185bf215546Sopenharmony_ci return R300_FG_ALPHA_FUNC_NOTEQUAL; 186bf215546Sopenharmony_ci case PIPE_FUNC_GEQUAL: 187bf215546Sopenharmony_ci return R300_FG_ALPHA_FUNC_GE; 188bf215546Sopenharmony_ci case PIPE_FUNC_ALWAYS: 189bf215546Sopenharmony_ci return R300_FG_ALPHA_FUNC_ALWAYS; 190bf215546Sopenharmony_ci default: 191bf215546Sopenharmony_ci fprintf(stderr, "r300: Unknown alpha function %d", alpha_func); 192bf215546Sopenharmony_ci assert(0); 193bf215546Sopenharmony_ci break; 194bf215546Sopenharmony_ci } 195bf215546Sopenharmony_ci return 0; 196bf215546Sopenharmony_ci} 197bf215546Sopenharmony_ci 198bf215546Sopenharmony_cistatic inline uint32_t 199bf215546Sopenharmony_cir300_translate_polygon_mode_front(unsigned mode) { 200bf215546Sopenharmony_ci switch (mode) 201bf215546Sopenharmony_ci { 202bf215546Sopenharmony_ci case PIPE_POLYGON_MODE_FILL: 203bf215546Sopenharmony_ci return R300_GA_POLY_MODE_FRONT_PTYPE_TRI; 204bf215546Sopenharmony_ci case PIPE_POLYGON_MODE_LINE: 205bf215546Sopenharmony_ci return R300_GA_POLY_MODE_FRONT_PTYPE_LINE; 206bf215546Sopenharmony_ci case PIPE_POLYGON_MODE_POINT: 207bf215546Sopenharmony_ci return R300_GA_POLY_MODE_FRONT_PTYPE_POINT; 208bf215546Sopenharmony_ci 209bf215546Sopenharmony_ci default: 210bf215546Sopenharmony_ci fprintf(stderr, "r300: Bad polygon mode %i in %s\n", mode, 211bf215546Sopenharmony_ci __FUNCTION__); 212bf215546Sopenharmony_ci return R300_GA_POLY_MODE_FRONT_PTYPE_TRI; 213bf215546Sopenharmony_ci } 214bf215546Sopenharmony_ci} 215bf215546Sopenharmony_ci 216bf215546Sopenharmony_cistatic inline uint32_t 217bf215546Sopenharmony_cir300_translate_polygon_mode_back(unsigned mode) { 218bf215546Sopenharmony_ci switch (mode) 219bf215546Sopenharmony_ci { 220bf215546Sopenharmony_ci case PIPE_POLYGON_MODE_FILL: 221bf215546Sopenharmony_ci return R300_GA_POLY_MODE_BACK_PTYPE_TRI; 222bf215546Sopenharmony_ci case PIPE_POLYGON_MODE_LINE: 223bf215546Sopenharmony_ci return R300_GA_POLY_MODE_BACK_PTYPE_LINE; 224bf215546Sopenharmony_ci case PIPE_POLYGON_MODE_POINT: 225bf215546Sopenharmony_ci return R300_GA_POLY_MODE_BACK_PTYPE_POINT; 226bf215546Sopenharmony_ci 227bf215546Sopenharmony_ci default: 228bf215546Sopenharmony_ci fprintf(stderr, "r300: Bad polygon mode %i in %s\n", mode, 229bf215546Sopenharmony_ci __FUNCTION__); 230bf215546Sopenharmony_ci return R300_GA_POLY_MODE_BACK_PTYPE_TRI; 231bf215546Sopenharmony_ci } 232bf215546Sopenharmony_ci} 233bf215546Sopenharmony_ci 234bf215546Sopenharmony_ci/* Texture sampler state. */ 235bf215546Sopenharmony_ci 236bf215546Sopenharmony_cistatic inline uint32_t r300_translate_wrap(int wrap) 237bf215546Sopenharmony_ci{ 238bf215546Sopenharmony_ci switch (wrap) { 239bf215546Sopenharmony_ci case PIPE_TEX_WRAP_REPEAT: 240bf215546Sopenharmony_ci return R300_TX_REPEAT; 241bf215546Sopenharmony_ci case PIPE_TEX_WRAP_CLAMP: 242bf215546Sopenharmony_ci return R300_TX_CLAMP; 243bf215546Sopenharmony_ci case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 244bf215546Sopenharmony_ci return R300_TX_CLAMP_TO_EDGE; 245bf215546Sopenharmony_ci case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 246bf215546Sopenharmony_ci return R300_TX_CLAMP_TO_BORDER; 247bf215546Sopenharmony_ci case PIPE_TEX_WRAP_MIRROR_REPEAT: 248bf215546Sopenharmony_ci return R300_TX_REPEAT | R300_TX_MIRRORED; 249bf215546Sopenharmony_ci case PIPE_TEX_WRAP_MIRROR_CLAMP: 250bf215546Sopenharmony_ci return R300_TX_CLAMP | R300_TX_MIRRORED; 251bf215546Sopenharmony_ci case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: 252bf215546Sopenharmony_ci return R300_TX_CLAMP_TO_EDGE | R300_TX_MIRRORED; 253bf215546Sopenharmony_ci case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: 254bf215546Sopenharmony_ci return R300_TX_CLAMP_TO_BORDER | R300_TX_MIRRORED; 255bf215546Sopenharmony_ci default: 256bf215546Sopenharmony_ci fprintf(stderr, "r300: Unknown texture wrap %d", wrap); 257bf215546Sopenharmony_ci assert(0); 258bf215546Sopenharmony_ci return 0; 259bf215546Sopenharmony_ci } 260bf215546Sopenharmony_ci} 261bf215546Sopenharmony_ci 262bf215546Sopenharmony_cistatic inline uint32_t r300_translate_tex_filters(int min, int mag, int mip, 263bf215546Sopenharmony_ci boolean is_anisotropic) 264bf215546Sopenharmony_ci{ 265bf215546Sopenharmony_ci uint32_t retval = 0; 266bf215546Sopenharmony_ci 267bf215546Sopenharmony_ci switch (min) { 268bf215546Sopenharmony_ci case PIPE_TEX_FILTER_NEAREST: 269bf215546Sopenharmony_ci retval |= R300_TX_MIN_FILTER_NEAREST; 270bf215546Sopenharmony_ci break; 271bf215546Sopenharmony_ci case PIPE_TEX_FILTER_LINEAR: 272bf215546Sopenharmony_ci retval |= is_anisotropic ? R300_TX_MIN_FILTER_ANISO : 273bf215546Sopenharmony_ci R300_TX_MIN_FILTER_LINEAR; 274bf215546Sopenharmony_ci break; 275bf215546Sopenharmony_ci default: 276bf215546Sopenharmony_ci fprintf(stderr, "r300: Unknown texture filter %d\n", min); 277bf215546Sopenharmony_ci assert(0); 278bf215546Sopenharmony_ci } 279bf215546Sopenharmony_ci 280bf215546Sopenharmony_ci switch (mag) { 281bf215546Sopenharmony_ci case PIPE_TEX_FILTER_NEAREST: 282bf215546Sopenharmony_ci retval |= R300_TX_MAG_FILTER_NEAREST; 283bf215546Sopenharmony_ci break; 284bf215546Sopenharmony_ci case PIPE_TEX_FILTER_LINEAR: 285bf215546Sopenharmony_ci retval |= is_anisotropic ? R300_TX_MAG_FILTER_ANISO : 286bf215546Sopenharmony_ci R300_TX_MAG_FILTER_LINEAR; 287bf215546Sopenharmony_ci break; 288bf215546Sopenharmony_ci default: 289bf215546Sopenharmony_ci fprintf(stderr, "r300: Unknown texture filter %d\n", mag); 290bf215546Sopenharmony_ci assert(0); 291bf215546Sopenharmony_ci } 292bf215546Sopenharmony_ci 293bf215546Sopenharmony_ci switch (mip) { 294bf215546Sopenharmony_ci case PIPE_TEX_MIPFILTER_NONE: 295bf215546Sopenharmony_ci retval |= R300_TX_MIN_FILTER_MIP_NONE; 296bf215546Sopenharmony_ci break; 297bf215546Sopenharmony_ci case PIPE_TEX_MIPFILTER_NEAREST: 298bf215546Sopenharmony_ci retval |= R300_TX_MIN_FILTER_MIP_NEAREST; 299bf215546Sopenharmony_ci break; 300bf215546Sopenharmony_ci case PIPE_TEX_MIPFILTER_LINEAR: 301bf215546Sopenharmony_ci retval |= R300_TX_MIN_FILTER_MIP_LINEAR; 302bf215546Sopenharmony_ci break; 303bf215546Sopenharmony_ci default: 304bf215546Sopenharmony_ci fprintf(stderr, "r300: Unknown texture filter %d\n", mip); 305bf215546Sopenharmony_ci assert(0); 306bf215546Sopenharmony_ci } 307bf215546Sopenharmony_ci 308bf215546Sopenharmony_ci return retval; 309bf215546Sopenharmony_ci} 310bf215546Sopenharmony_ci 311bf215546Sopenharmony_cistatic inline uint32_t r300_anisotropy(unsigned max_aniso) 312bf215546Sopenharmony_ci{ 313bf215546Sopenharmony_ci if (max_aniso >= 16) { 314bf215546Sopenharmony_ci return R300_TX_MAX_ANISO_16_TO_1; 315bf215546Sopenharmony_ci } else if (max_aniso >= 8) { 316bf215546Sopenharmony_ci return R300_TX_MAX_ANISO_8_TO_1; 317bf215546Sopenharmony_ci } else if (max_aniso >= 4) { 318bf215546Sopenharmony_ci return R300_TX_MAX_ANISO_4_TO_1; 319bf215546Sopenharmony_ci } else if (max_aniso >= 2) { 320bf215546Sopenharmony_ci return R300_TX_MAX_ANISO_2_TO_1; 321bf215546Sopenharmony_ci } else { 322bf215546Sopenharmony_ci return R300_TX_MAX_ANISO_1_TO_1; 323bf215546Sopenharmony_ci } 324bf215546Sopenharmony_ci} 325bf215546Sopenharmony_ci 326bf215546Sopenharmony_cistatic inline uint32_t r500_anisotropy(unsigned max_aniso) 327bf215546Sopenharmony_ci{ 328bf215546Sopenharmony_ci if (!max_aniso) { 329bf215546Sopenharmony_ci return 0; 330bf215546Sopenharmony_ci } 331bf215546Sopenharmony_ci max_aniso -= 1; 332bf215546Sopenharmony_ci 333bf215546Sopenharmony_ci // Map the range [0, 15] to [0, 63]. 334bf215546Sopenharmony_ci return R500_TX_MAX_ANISO(MIN2((unsigned)(max_aniso*4.2001), 63)) | 335bf215546Sopenharmony_ci R500_TX_ANISO_HIGH_QUALITY; 336bf215546Sopenharmony_ci} 337bf215546Sopenharmony_ci 338bf215546Sopenharmony_ci/* Translate pipe_formats into PSC vertex types. */ 339bf215546Sopenharmony_cistatic inline uint16_t 340bf215546Sopenharmony_cir300_translate_vertex_data_type(enum pipe_format format) { 341bf215546Sopenharmony_ci uint32_t result = 0; 342bf215546Sopenharmony_ci const struct util_format_description *desc; 343bf215546Sopenharmony_ci unsigned i; 344bf215546Sopenharmony_ci 345bf215546Sopenharmony_ci if (!format) 346bf215546Sopenharmony_ci format = PIPE_FORMAT_R32_FLOAT; 347bf215546Sopenharmony_ci 348bf215546Sopenharmony_ci desc = util_format_description(format); 349bf215546Sopenharmony_ci 350bf215546Sopenharmony_ci if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) { 351bf215546Sopenharmony_ci return R300_INVALID_FORMAT; 352bf215546Sopenharmony_ci } 353bf215546Sopenharmony_ci 354bf215546Sopenharmony_ci /* Find the first non-VOID channel. */ 355bf215546Sopenharmony_ci for (i = 0; i < 4; i++) { 356bf215546Sopenharmony_ci if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) { 357bf215546Sopenharmony_ci break; 358bf215546Sopenharmony_ci } 359bf215546Sopenharmony_ci } 360bf215546Sopenharmony_ci 361bf215546Sopenharmony_ci switch (desc->channel[i].type) { 362bf215546Sopenharmony_ci /* Half-floats, floats, doubles */ 363bf215546Sopenharmony_ci case UTIL_FORMAT_TYPE_FLOAT: 364bf215546Sopenharmony_ci switch (desc->channel[i].size) { 365bf215546Sopenharmony_ci case 16: 366bf215546Sopenharmony_ci /* Supported only on RV350 and later. */ 367bf215546Sopenharmony_ci if (desc->nr_channels > 2) { 368bf215546Sopenharmony_ci result = R300_DATA_TYPE_FLT16_4; 369bf215546Sopenharmony_ci } else { 370bf215546Sopenharmony_ci result = R300_DATA_TYPE_FLT16_2; 371bf215546Sopenharmony_ci } 372bf215546Sopenharmony_ci break; 373bf215546Sopenharmony_ci case 32: 374bf215546Sopenharmony_ci result = R300_DATA_TYPE_FLOAT_1 + (desc->nr_channels - 1); 375bf215546Sopenharmony_ci break; 376bf215546Sopenharmony_ci default: 377bf215546Sopenharmony_ci return R300_INVALID_FORMAT; 378bf215546Sopenharmony_ci } 379bf215546Sopenharmony_ci break; 380bf215546Sopenharmony_ci /* Unsigned ints */ 381bf215546Sopenharmony_ci case UTIL_FORMAT_TYPE_UNSIGNED: 382bf215546Sopenharmony_ci /* Signed ints */ 383bf215546Sopenharmony_ci case UTIL_FORMAT_TYPE_SIGNED: 384bf215546Sopenharmony_ci switch (desc->channel[i].size) { 385bf215546Sopenharmony_ci case 8: 386bf215546Sopenharmony_ci result = R300_DATA_TYPE_BYTE; 387bf215546Sopenharmony_ci break; 388bf215546Sopenharmony_ci case 16: 389bf215546Sopenharmony_ci if (desc->nr_channels > 2) { 390bf215546Sopenharmony_ci result = R300_DATA_TYPE_SHORT_4; 391bf215546Sopenharmony_ci } else { 392bf215546Sopenharmony_ci result = R300_DATA_TYPE_SHORT_2; 393bf215546Sopenharmony_ci } 394bf215546Sopenharmony_ci break; 395bf215546Sopenharmony_ci default: 396bf215546Sopenharmony_ci return R300_INVALID_FORMAT; 397bf215546Sopenharmony_ci } 398bf215546Sopenharmony_ci break; 399bf215546Sopenharmony_ci default: 400bf215546Sopenharmony_ci return R300_INVALID_FORMAT; 401bf215546Sopenharmony_ci } 402bf215546Sopenharmony_ci 403bf215546Sopenharmony_ci if (desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED) { 404bf215546Sopenharmony_ci result |= R300_SIGNED; 405bf215546Sopenharmony_ci } 406bf215546Sopenharmony_ci if (desc->channel[i].normalized) { 407bf215546Sopenharmony_ci result |= R300_NORMALIZE; 408bf215546Sopenharmony_ci } 409bf215546Sopenharmony_ci 410bf215546Sopenharmony_ci return result; 411bf215546Sopenharmony_ci} 412bf215546Sopenharmony_ci 413bf215546Sopenharmony_cistatic inline uint16_t 414bf215546Sopenharmony_cir300_translate_vertex_data_swizzle(enum pipe_format format) { 415bf215546Sopenharmony_ci const struct util_format_description *desc; 416bf215546Sopenharmony_ci unsigned i, swizzle = 0; 417bf215546Sopenharmony_ci 418bf215546Sopenharmony_ci if (!format) 419bf215546Sopenharmony_ci return (R300_SWIZZLE_SELECT_FP_ZERO << R300_SWIZZLE_SELECT_X_SHIFT) | 420bf215546Sopenharmony_ci (R300_SWIZZLE_SELECT_FP_ZERO << R300_SWIZZLE_SELECT_Y_SHIFT) | 421bf215546Sopenharmony_ci (R300_SWIZZLE_SELECT_FP_ZERO << R300_SWIZZLE_SELECT_Z_SHIFT) | 422bf215546Sopenharmony_ci (R300_SWIZZLE_SELECT_FP_ONE << R300_SWIZZLE_SELECT_W_SHIFT); 423bf215546Sopenharmony_ci 424bf215546Sopenharmony_ci desc = util_format_description(format); 425bf215546Sopenharmony_ci 426bf215546Sopenharmony_ci if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) { 427bf215546Sopenharmony_ci fprintf(stderr, "r300: Bad format %s in %s:%d\n", 428bf215546Sopenharmony_ci util_format_short_name(format), __FUNCTION__, __LINE__); 429bf215546Sopenharmony_ci return 0; 430bf215546Sopenharmony_ci } 431bf215546Sopenharmony_ci 432bf215546Sopenharmony_ci for (i = 0; i < desc->nr_channels; i++) { 433bf215546Sopenharmony_ci swizzle |= 434bf215546Sopenharmony_ci MIN2(desc->swizzle[i], R300_SWIZZLE_SELECT_FP_ONE) << (3*i); 435bf215546Sopenharmony_ci } 436bf215546Sopenharmony_ci /* Set (0,0,0,1) in unused components. */ 437bf215546Sopenharmony_ci for (; i < 3; i++) { 438bf215546Sopenharmony_ci swizzle |= R300_SWIZZLE_SELECT_FP_ZERO << (3*i); 439bf215546Sopenharmony_ci } 440bf215546Sopenharmony_ci for (; i < 4; i++) { 441bf215546Sopenharmony_ci swizzle |= R300_SWIZZLE_SELECT_FP_ONE << (3*i); 442bf215546Sopenharmony_ci } 443bf215546Sopenharmony_ci 444bf215546Sopenharmony_ci return swizzle | (0xf << R300_WRITE_ENA_SHIFT); 445bf215546Sopenharmony_ci} 446bf215546Sopenharmony_ci 447bf215546Sopenharmony_ci#endif /* R300_STATE_INLINES_H */ 448