1ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt/*
2ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt * Copyright 2009 Joakim Sindholt <opensource@zhasha.com>
33673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson *                Corbin Simpson <MostAwesomeDude@gmail.com>
4ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt *
5ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt * Permission is hereby granted, free of charge, to any person obtaining a
6ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt * copy of this software and associated documentation files (the "Software"),
7ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt * to deal in the Software without restriction, including without limitation
8ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt * on the rights to use, copy, modify, merge, publish, distribute, sub
9ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt * license, and/or sell copies of the Software, and to permit persons to whom
10ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt * the Software is furnished to do so, subject to the following conditions:
11ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt *
12ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt * The above copyright notice and this permission notice (including the next
13ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt * paragraph) shall be included in all copies or substantial portions of the
14ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt * Software.
15ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt *
16ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt * USE OR OTHER DEALINGS IN THE SOFTWARE. */
23ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt
24ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt#ifndef R300_STATE_INLINES_H
25ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt#define R300_STATE_INLINES_H
26ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt
276a448a525baf81173f92ee8c3074b98baa54397bCorbin Simpson#include "draw/draw_vertex.h"
28ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt#include "pipe/p_format.h"
2972befaaae5fd9555e1f6ccbd6a74c0d640fc2929Michal Krol#include "util/u_format.h"
30ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt#include "r300_reg.h"
314b8d3480764daf45cbbc03d76cd8b7c81937f532Marek Olšák#include <stdio.h>
324b8d3480764daf45cbbc03d76cd8b7c81937f532Marek Olšák
332b7d39da1f5445e1b0beb3b8b1ef9004e684c600Corbin Simpson/* Some maths. These should probably find their way to u_math, if needed. */
342b7d39da1f5445e1b0beb3b8b1ef9004e684c600Corbin Simpson
352b7d39da1f5445e1b0beb3b8b1ef9004e684c600Corbin Simpsonstatic INLINE int pack_float_16_6x(float f) {
362b7d39da1f5445e1b0beb3b8b1ef9004e684c600Corbin Simpson    return ((int)(f * 6.0) & 0xffff);
372b7d39da1f5445e1b0beb3b8b1ef9004e684c600Corbin Simpson}
382b7d39da1f5445e1b0beb3b8b1ef9004e684c600Corbin Simpson
393673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson/* Blend state. */
403673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson
41bdb811772fe1b11e32172b211d9935d37093c753Marek Olšákstatic INLINE uint32_t r300_translate_blend_function(int blend_func,
42bdb811772fe1b11e32172b211d9935d37093c753Marek Olšák                                                     boolean clamp)
433673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson{
443673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    switch (blend_func) {
45bdb811772fe1b11e32172b211d9935d37093c753Marek Olšák    case PIPE_BLEND_ADD:
46bdb811772fe1b11e32172b211d9935d37093c753Marek Olšák        return clamp ? R300_COMB_FCN_ADD_CLAMP : R300_COMB_FCN_ADD_NOCLAMP;
47bdb811772fe1b11e32172b211d9935d37093c753Marek Olšák    case PIPE_BLEND_SUBTRACT:
48bdb811772fe1b11e32172b211d9935d37093c753Marek Olšák        return clamp ? R300_COMB_FCN_SUB_CLAMP : R300_COMB_FCN_SUB_NOCLAMP;
49bdb811772fe1b11e32172b211d9935d37093c753Marek Olšák    case PIPE_BLEND_REVERSE_SUBTRACT:
50bdb811772fe1b11e32172b211d9935d37093c753Marek Olšák        return clamp ? R300_COMB_FCN_RSUB_CLAMP : R300_COMB_FCN_RSUB_NOCLAMP;
51bdb811772fe1b11e32172b211d9935d37093c753Marek Olšák    case PIPE_BLEND_MIN:
52bdb811772fe1b11e32172b211d9935d37093c753Marek Olšák        return R300_COMB_FCN_MIN;
53bdb811772fe1b11e32172b211d9935d37093c753Marek Olšák    case PIPE_BLEND_MAX:
54bdb811772fe1b11e32172b211d9935d37093c753Marek Olšák        return R300_COMB_FCN_MAX;
55bdb811772fe1b11e32172b211d9935d37093c753Marek Olšák    default:
56bdb811772fe1b11e32172b211d9935d37093c753Marek Olšák        fprintf(stderr, "r300: Unknown blend function %d\n", blend_func);
57bdb811772fe1b11e32172b211d9935d37093c753Marek Olšák        assert(0);
58bdb811772fe1b11e32172b211d9935d37093c753Marek Olšák        break;
593673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    }
603673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    return 0;
613673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson}
623673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson
633673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson/* XXX we can also offer the D3D versions of some of these... */
643673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpsonstatic INLINE uint32_t r300_translate_blend_factor(int blend_fact)
653673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson{
663673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    switch (blend_fact) {
673673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_BLENDFACTOR_ONE:
683673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_BLEND_GL_ONE;
693673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_BLENDFACTOR_SRC_COLOR:
703673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_BLEND_GL_SRC_COLOR;
713673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_BLENDFACTOR_SRC_ALPHA:
723673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_BLEND_GL_SRC_ALPHA;
733673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_BLENDFACTOR_DST_ALPHA:
743673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_BLEND_GL_DST_ALPHA;
753673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_BLENDFACTOR_DST_COLOR:
763673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_BLEND_GL_DST_COLOR;
773673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
783673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_BLEND_GL_SRC_ALPHA_SATURATE;
793673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_BLENDFACTOR_CONST_COLOR:
803673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_BLEND_GL_CONST_COLOR;
813673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_BLENDFACTOR_CONST_ALPHA:
823673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_BLEND_GL_CONST_ALPHA;
833673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_BLENDFACTOR_ZERO:
843673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_BLEND_GL_ZERO;
853673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_BLENDFACTOR_INV_SRC_COLOR:
863673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_BLEND_GL_ONE_MINUS_SRC_COLOR;
873673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
883673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_BLEND_GL_ONE_MINUS_SRC_ALPHA;
893673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_BLENDFACTOR_INV_DST_ALPHA:
903673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_BLEND_GL_ONE_MINUS_DST_ALPHA;
913673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_BLENDFACTOR_INV_DST_COLOR:
923673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_BLEND_GL_ONE_MINUS_DST_COLOR;
933673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_BLENDFACTOR_INV_CONST_COLOR:
943673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_BLEND_GL_ONE_MINUS_CONST_COLOR;
953673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
963673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_BLEND_GL_ONE_MINUS_CONST_ALPHA;
97bfbec0818f0e7ab9358809a1af732a1366245507Corbin Simpson
98bfbec0818f0e7ab9358809a1af732a1366245507Corbin Simpson        case PIPE_BLENDFACTOR_SRC1_COLOR:
99bfbec0818f0e7ab9358809a1af732a1366245507Corbin Simpson        case PIPE_BLENDFACTOR_SRC1_ALPHA:
1003673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_BLENDFACTOR_INV_SRC1_COLOR:
101bfbec0818f0e7ab9358809a1af732a1366245507Corbin Simpson        case PIPE_BLENDFACTOR_INV_SRC1_ALPHA:
1024b8d3480764daf45cbbc03d76cd8b7c81937f532Marek Olšák            fprintf(stderr, "r300: Implementation error: "
103bfbec0818f0e7ab9358809a1af732a1366245507Corbin Simpson                "Bad blend factor %d not supported!\n", blend_fact);
104bfbec0818f0e7ab9358809a1af732a1366245507Corbin Simpson            assert(0);
105bfbec0818f0e7ab9358809a1af732a1366245507Corbin Simpson            break;
106bfbec0818f0e7ab9358809a1af732a1366245507Corbin Simpson
1073673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        default:
1084b8d3480764daf45cbbc03d76cd8b7c81937f532Marek Olšák            fprintf(stderr, "r300: Unknown blend factor %d\n", blend_fact);
1090a8cd4862c4f04308ab818077bab94417ffbf50bCorbin Simpson            assert(0);
1103673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            break;
1113673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    }
1123673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    return 0;
1133673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson}
1143673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson
1153673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson/* DSA state. */
1163673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson
1173673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpsonstatic INLINE uint32_t r300_translate_depth_stencil_function(int zs_func)
1183673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson{
1193673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    switch (zs_func) {
1203673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_FUNC_NEVER:
1213673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_ZS_NEVER;
1223673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_FUNC_LESS:
1233673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_ZS_LESS;
1243673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_FUNC_EQUAL:
1253673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_ZS_EQUAL;
1263673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_FUNC_LEQUAL:
1273673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_ZS_LEQUAL;
1283673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_FUNC_GREATER:
1293673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_ZS_GREATER;
1303673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_FUNC_NOTEQUAL:
1313673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_ZS_NOTEQUAL;
1323673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_FUNC_GEQUAL:
1333673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_ZS_GEQUAL;
1343673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_FUNC_ALWAYS:
1353673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_ZS_ALWAYS;
1363673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        default:
1374b8d3480764daf45cbbc03d76cd8b7c81937f532Marek Olšák            fprintf(stderr, "r300: Unknown depth/stencil function %d\n",
1383673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson                zs_func);
1390a8cd4862c4f04308ab818077bab94417ffbf50bCorbin Simpson            assert(0);
1403673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            break;
1413673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    }
1423673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    return 0;
1433673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson}
1443673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson
1453673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpsonstatic INLINE uint32_t r300_translate_stencil_op(int s_op)
1463673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson{
1473673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    switch (s_op) {
1483673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_STENCIL_OP_KEEP:
1493673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_ZS_KEEP;
1503673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_STENCIL_OP_ZERO:
1513673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_ZS_ZERO;
1523673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_STENCIL_OP_REPLACE:
1533673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_ZS_REPLACE;
1543673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_STENCIL_OP_INCR:
1553673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_ZS_INCR;
1563673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_STENCIL_OP_DECR:
1573673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_ZS_DECR;
1583673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_STENCIL_OP_INCR_WRAP:
1593673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_ZS_INCR_WRAP;
1603673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_STENCIL_OP_DECR_WRAP:
1613673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_ZS_DECR_WRAP;
1623673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_STENCIL_OP_INVERT:
1633673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_ZS_INVERT;
1643673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        default:
1654b8d3480764daf45cbbc03d76cd8b7c81937f532Marek Olšák            fprintf(stderr, "r300: Unknown stencil op %d", s_op);
1660a8cd4862c4f04308ab818077bab94417ffbf50bCorbin Simpson            assert(0);
1673673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            break;
1683673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    }
1693673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    return 0;
1703673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson}
1713673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson
1723673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpsonstatic INLINE uint32_t r300_translate_alpha_function(int alpha_func)
1733673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson{
1743673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    switch (alpha_func) {
1753673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_FUNC_NEVER:
1763673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_FG_ALPHA_FUNC_NEVER;
1773673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_FUNC_LESS:
1783673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_FG_ALPHA_FUNC_LESS;
1793673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_FUNC_EQUAL:
1803673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_FG_ALPHA_FUNC_EQUAL;
1813673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_FUNC_LEQUAL:
1823673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_FG_ALPHA_FUNC_LE;
1833673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_FUNC_GREATER:
1843673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_FG_ALPHA_FUNC_GREATER;
1853673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_FUNC_NOTEQUAL:
1863673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_FG_ALPHA_FUNC_NOTEQUAL;
1873673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_FUNC_GEQUAL:
1883673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_FG_ALPHA_FUNC_GE;
1893673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_FUNC_ALWAYS:
1903673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_FG_ALPHA_FUNC_ALWAYS;
1913673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        default:
1924b8d3480764daf45cbbc03d76cd8b7c81937f532Marek Olšák            fprintf(stderr, "r300: Unknown alpha function %d", alpha_func);
1930a8cd4862c4f04308ab818077bab94417ffbf50bCorbin Simpson            assert(0);
1943673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            break;
1953673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    }
1963673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    return 0;
1973673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson}
1983673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson
199a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpsonstatic INLINE uint32_t
200a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpsonr300_translate_polygon_mode_front(unsigned mode) {
201a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson    switch (mode)
202a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson    {
203a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson        case PIPE_POLYGON_MODE_FILL:
204a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson            return R300_GA_POLY_MODE_FRONT_PTYPE_TRI;
205a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson        case PIPE_POLYGON_MODE_LINE:
206a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson            return R300_GA_POLY_MODE_FRONT_PTYPE_LINE;
207a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson        case PIPE_POLYGON_MODE_POINT:
208a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson            return R300_GA_POLY_MODE_FRONT_PTYPE_POINT;
209a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson
210a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson        default:
2114b8d3480764daf45cbbc03d76cd8b7c81937f532Marek Olšák            fprintf(stderr, "r300: Bad polygon mode %i in %s\n", mode,
212a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson                __FUNCTION__);
213a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson            return R300_GA_POLY_MODE_FRONT_PTYPE_TRI;
214a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson    }
215a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson}
216a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson
217a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpsonstatic INLINE uint32_t
218a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpsonr300_translate_polygon_mode_back(unsigned mode) {
219a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson    switch (mode)
220a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson    {
221a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson        case PIPE_POLYGON_MODE_FILL:
222a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson            return R300_GA_POLY_MODE_BACK_PTYPE_TRI;
223a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson        case PIPE_POLYGON_MODE_LINE:
224a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson            return R300_GA_POLY_MODE_BACK_PTYPE_LINE;
225a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson        case PIPE_POLYGON_MODE_POINT:
226a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson            return R300_GA_POLY_MODE_BACK_PTYPE_POINT;
227a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson
228a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson        default:
2294b8d3480764daf45cbbc03d76cd8b7c81937f532Marek Olšák            fprintf(stderr, "r300: Bad polygon mode %i in %s\n", mode,
230a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson                __FUNCTION__);
231a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson            return R300_GA_POLY_MODE_BACK_PTYPE_TRI;
232a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson    }
233a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson}
234a12fc1a9c4d544b015b40ff0266b8c8726d16f75Corbin Simpson
2353673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson/* Texture sampler state. */
2363673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson
2373673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpsonstatic INLINE uint32_t r300_translate_wrap(int wrap)
2383673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson{
2393673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    switch (wrap) {
2403673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_TEX_WRAP_REPEAT:
2413673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_TX_REPEAT;
2423673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_TEX_WRAP_CLAMP:
2433673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_TX_CLAMP;
2443673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
2453673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_TX_CLAMP_TO_EDGE;
2463673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
2473673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_TX_CLAMP_TO_BORDER;
2483673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_TEX_WRAP_MIRROR_REPEAT:
2493673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_TX_REPEAT | R300_TX_MIRRORED;
2503673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_TEX_WRAP_MIRROR_CLAMP:
2513673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_TX_CLAMP | R300_TX_MIRRORED;
2523673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
2533673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return R300_TX_CLAMP_TO_EDGE | R300_TX_MIRRORED;
2543673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
255a28ee4aa02429a1ece1172ec7765bc1621f13851Marek Olšák            return R300_TX_CLAMP_TO_BORDER | R300_TX_MIRRORED;
2563673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        default:
2574b8d3480764daf45cbbc03d76cd8b7c81937f532Marek Olšák            fprintf(stderr, "r300: Unknown texture wrap %d", wrap);
2580a8cd4862c4f04308ab818077bab94417ffbf50bCorbin Simpson            assert(0);
2593673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson            return 0;
2603673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    }
2613673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson}
2623673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson
26360f5608bd7027a5c26a84f1d63250353ec4ea43cBrian Paulstatic INLINE uint32_t r300_translate_tex_filters(int min, int mag, int mip,
264466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák                                                  boolean is_anisotropic)
2653673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson{
2663673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    uint32_t retval = 0;
267466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák
268466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák    switch (min) {
269466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák    case PIPE_TEX_FILTER_NEAREST:
270466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák        retval |= R300_TX_MIN_FILTER_NEAREST;
271466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák        break;
272466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák    case PIPE_TEX_FILTER_LINEAR:
273466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák        retval |= is_anisotropic ? R300_TX_MIN_FILTER_ANISO :
274466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák                                   R300_TX_MIN_FILTER_LINEAR;
275466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák        break;
276466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák    default:
277466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák        fprintf(stderr, "r300: Unknown texture filter %d\n", min);
278466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák        assert(0);
2793673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    }
280466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák
281466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák    switch (mag) {
282466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák    case PIPE_TEX_FILTER_NEAREST:
283466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák        retval |= R300_TX_MAG_FILTER_NEAREST;
284466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák        break;
285466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák    case PIPE_TEX_FILTER_LINEAR:
286466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák        retval |= is_anisotropic ? R300_TX_MAG_FILTER_ANISO :
287466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák                                   R300_TX_MAG_FILTER_LINEAR;
288466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák        break;
289466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák    default:
290466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák        fprintf(stderr, "r300: Unknown texture filter %d\n", mag);
291466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák        assert(0);
292466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák    }
293466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák
2943673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    switch (mip) {
295466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák    case PIPE_TEX_MIPFILTER_NONE:
296466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák        retval |= R300_TX_MIN_FILTER_MIP_NONE;
297466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák        break;
298466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák    case PIPE_TEX_MIPFILTER_NEAREST:
299466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák        retval |= R300_TX_MIN_FILTER_MIP_NEAREST;
300466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák        break;
301466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák    case PIPE_TEX_MIPFILTER_LINEAR:
302466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák        retval |= R300_TX_MIN_FILTER_MIP_LINEAR;
303466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák        break;
304466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák    default:
305466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák        fprintf(stderr, "r300: Unknown texture filter %d\n", mip);
306466ce95ddff734d5090bcb1c5ada7a4f23e13226Marek Olšák        assert(0);
3073673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    }
3083673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson
3093673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    return retval;
3103673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson}
3113673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson
312ebe12d50064370e4ddec21a1e087b24295940319Roland Scheideggerstatic INLINE uint32_t r300_anisotropy(unsigned max_aniso)
3133673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson{
314ebe12d50064370e4ddec21a1e087b24295940319Roland Scheidegger    if (max_aniso >= 16) {
3153673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        return R300_TX_MAX_ANISO_16_TO_1;
316ebe12d50064370e4ddec21a1e087b24295940319Roland Scheidegger    } else if (max_aniso >= 8) {
3173673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        return R300_TX_MAX_ANISO_8_TO_1;
318ebe12d50064370e4ddec21a1e087b24295940319Roland Scheidegger    } else if (max_aniso >= 4) {
3193673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        return R300_TX_MAX_ANISO_4_TO_1;
320ebe12d50064370e4ddec21a1e087b24295940319Roland Scheidegger    } else if (max_aniso >= 2) {
3213673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        return R300_TX_MAX_ANISO_2_TO_1;
3223673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    } else {
3233673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson        return R300_TX_MAX_ANISO_1_TO_1;
3243673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson    }
3253673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson}
3263673fc35d68edf55d0b1dc0fb4c3628f228eb9d6Corbin Simpson
3273996e493693d5aa048fed1c2fd6db4027cb47df4Marek Olšákstatic INLINE uint32_t r500_anisotropy(unsigned max_aniso)
3283996e493693d5aa048fed1c2fd6db4027cb47df4Marek Olšák{
3293996e493693d5aa048fed1c2fd6db4027cb47df4Marek Olšák    if (!max_aniso) {
3303996e493693d5aa048fed1c2fd6db4027cb47df4Marek Olšák        return 0;
3313996e493693d5aa048fed1c2fd6db4027cb47df4Marek Olšák    }
3323996e493693d5aa048fed1c2fd6db4027cb47df4Marek Olšák    max_aniso -= 1;
3333996e493693d5aa048fed1c2fd6db4027cb47df4Marek Olšák
3343996e493693d5aa048fed1c2fd6db4027cb47df4Marek Olšák    // Map the range [0, 15] to [0, 63].
3353996e493693d5aa048fed1c2fd6db4027cb47df4Marek Olšák    return R500_TX_MAX_ANISO(MIN2((unsigned)(max_aniso*4.2001), 63)) |
336d2686cdb2354b7cfe0e4eac3c5afab40cb947e0fMarek Olšák           R500_TX_ANISO_HIGH_QUALITY;
3373996e493693d5aa048fed1c2fd6db4027cb47df4Marek Olšák}
3383996e493693d5aa048fed1c2fd6db4027cb47df4Marek Olšák
339ff9e1c01989fc80f07cdc69e3e373bdfe1a384efCorbin Simpson/* Translate pipe_formats into PSC vertex types. */
340ff9e1c01989fc80f07cdc69e3e373bdfe1a384efCorbin Simpsonstatic INLINE uint16_t
341ff9e1c01989fc80f07cdc69e3e373bdfe1a384efCorbin Simpsonr300_translate_vertex_data_type(enum pipe_format format) {
342cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson    uint32_t result = 0;
3436fd8b9b550713302566bb4c28e49c219870ccfecMichal Krol    const struct util_format_description *desc;
34494e9ab975cb4187a63eeb4cd03694ebd3cb27bd8Marek Olšák    unsigned i;
345cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson
3466fd8b9b550713302566bb4c28e49c219870ccfecMichal Krol    desc = util_format_description(format);
3476fd8b9b550713302566bb4c28e49c219870ccfecMichal Krol
348f9f4f3df422334aee31f9041c374c72d0f97ba39José Fonseca    if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) {
349ebe2b546633a3593c54190bb1f2d372d70de14cdMarek Olšák        return R300_INVALID_FORMAT;
350cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson    }
351cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson
35294e9ab975cb4187a63eeb4cd03694ebd3cb27bd8Marek Olšák    /* Find the first non-VOID channel. */
35394e9ab975cb4187a63eeb4cd03694ebd3cb27bd8Marek Olšák    for (i = 0; i < 4; i++) {
35494e9ab975cb4187a63eeb4cd03694ebd3cb27bd8Marek Olšák        if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) {
35594e9ab975cb4187a63eeb4cd03694ebd3cb27bd8Marek Olšák            break;
35694e9ab975cb4187a63eeb4cd03694ebd3cb27bd8Marek Olšák        }
35794e9ab975cb4187a63eeb4cd03694ebd3cb27bd8Marek Olšák    }
35894e9ab975cb4187a63eeb4cd03694ebd3cb27bd8Marek Olšák
35994e9ab975cb4187a63eeb4cd03694ebd3cb27bd8Marek Olšák    switch (desc->channel[i].type) {
360cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson        /* Half-floats, floats, doubles */
3616fd8b9b550713302566bb4c28e49c219870ccfecMichal Krol        case UTIL_FORMAT_TYPE_FLOAT:
36294e9ab975cb4187a63eeb4cd03694ebd3cb27bd8Marek Olšák            switch (desc->channel[i].size) {
363558c15995f486d72b959ad19c914a38adbcbe5f7Marek Olšák                case 16:
364ebe2b546633a3593c54190bb1f2d372d70de14cdMarek Olšák                    /* Supported only on RV350 and later. */
36539e116e3a0dce1a13dbb4395585cd3873e5ed073Marek Olšák                    if (desc->nr_channels > 2) {
366558c15995f486d72b959ad19c914a38adbcbe5f7Marek Olšák                        result = R300_DATA_TYPE_FLT16_4;
367558c15995f486d72b959ad19c914a38adbcbe5f7Marek Olšák                    } else {
368558c15995f486d72b959ad19c914a38adbcbe5f7Marek Olšák                        result = R300_DATA_TYPE_FLT16_2;
369558c15995f486d72b959ad19c914a38adbcbe5f7Marek Olšák                    }
370558c15995f486d72b959ad19c914a38adbcbe5f7Marek Olšák                    break;
3716fd8b9b550713302566bb4c28e49c219870ccfecMichal Krol                case 32:
37239e116e3a0dce1a13dbb4395585cd3873e5ed073Marek Olšák                    result = R300_DATA_TYPE_FLOAT_1 + (desc->nr_channels - 1);
373cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson                    break;
374cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson                default:
375ebe2b546633a3593c54190bb1f2d372d70de14cdMarek Olšák                    return R300_INVALID_FORMAT;
376cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson            }
377cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson            break;
3786fd8b9b550713302566bb4c28e49c219870ccfecMichal Krol        /* Unsigned ints */
3796fd8b9b550713302566bb4c28e49c219870ccfecMichal Krol        case UTIL_FORMAT_TYPE_UNSIGNED:
3806fd8b9b550713302566bb4c28e49c219870ccfecMichal Krol        /* Signed ints */
3816fd8b9b550713302566bb4c28e49c219870ccfecMichal Krol        case UTIL_FORMAT_TYPE_SIGNED:
38294e9ab975cb4187a63eeb4cd03694ebd3cb27bd8Marek Olšák            switch (desc->channel[i].size) {
3836fd8b9b550713302566bb4c28e49c219870ccfecMichal Krol                case 8:
384cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson                    result = R300_DATA_TYPE_BYTE;
385cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson                    break;
3866fd8b9b550713302566bb4c28e49c219870ccfecMichal Krol                case 16:
38739e116e3a0dce1a13dbb4395585cd3873e5ed073Marek Olšák                    if (desc->nr_channels > 2) {
388cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson                        result = R300_DATA_TYPE_SHORT_4;
389cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson                    } else {
390cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson                        result = R300_DATA_TYPE_SHORT_2;
391cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson                    }
392cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson                    break;
393cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson                default:
394ebe2b546633a3593c54190bb1f2d372d70de14cdMarek Olšák                    return R300_INVALID_FORMAT;
395cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson            }
396ff9e1c01989fc80f07cdc69e3e373bdfe1a384efCorbin Simpson            break;
397ff9e1c01989fc80f07cdc69e3e373bdfe1a384efCorbin Simpson        default:
398ebe2b546633a3593c54190bb1f2d372d70de14cdMarek Olšák            return R300_INVALID_FORMAT;
399ff9e1c01989fc80f07cdc69e3e373bdfe1a384efCorbin Simpson    }
400cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson
40194e9ab975cb4187a63eeb4cd03694ebd3cb27bd8Marek Olšák    if (desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED) {
402cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson        result |= R300_SIGNED;
4036fd8b9b550713302566bb4c28e49c219870ccfecMichal Krol    }
40494e9ab975cb4187a63eeb4cd03694ebd3cb27bd8Marek Olšák    if (desc->channel[i].normalized) {
405cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson        result |= R300_NORMALIZE;
406cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson    }
407cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson
408cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson    return result;
409ff9e1c01989fc80f07cdc69e3e373bdfe1a384efCorbin Simpson}
410ff9e1c01989fc80f07cdc69e3e373bdfe1a384efCorbin Simpson
411ff9e1c01989fc80f07cdc69e3e373bdfe1a384efCorbin Simpsonstatic INLINE uint16_t
412ff9e1c01989fc80f07cdc69e3e373bdfe1a384efCorbin Simpsonr300_translate_vertex_data_swizzle(enum pipe_format format) {
41372befaaae5fd9555e1f6ccbd6a74c0d640fc2929Michal Krol    const struct util_format_description *desc = util_format_description(format);
41452e591383bdce49cb46a1162aff9632c57e06504Marek Olšák    unsigned i, swizzle = 0;
41572befaaae5fd9555e1f6ccbd6a74c0d640fc2929Michal Krol
41672befaaae5fd9555e1f6ccbd6a74c0d640fc2929Michal Krol    assert(format);
417cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson
418f9f4f3df422334aee31f9041c374c72d0f97ba39José Fonseca    if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) {
4194b8d3480764daf45cbbc03d76cd8b7c81937f532Marek Olšák        fprintf(stderr, "r300: Bad format %s in %s:%d\n",
420ac6a26b429d70395cf6def04d2d9c8cf1bd2c964Marek Olšák            util_format_short_name(format), __FUNCTION__, __LINE__);
421cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson        return 0;
422dcd7f1c0551812cf39ca6a3af9f1610ad84fb24eCorbin Simpson    }
423cab749a1d0046f59ca10f96d2e6343404e5f2616Corbin Simpson
42483b76657b3dbf5e00d73bc03cc102317c4af6ecaMarek Olšák    for (i = 0; i < desc->nr_channels; i++) {
42552e591383bdce49cb46a1162aff9632c57e06504Marek Olšák        swizzle |=
42652e591383bdce49cb46a1162aff9632c57e06504Marek Olšák            MIN2(desc->swizzle[i], R300_SWIZZLE_SELECT_FP_ONE) << (3*i);
42752e591383bdce49cb46a1162aff9632c57e06504Marek Olšák    }
42883b76657b3dbf5e00d73bc03cc102317c4af6ecaMarek Olšák    /* Set (0,0,0,1) in unused components. */
42983b76657b3dbf5e00d73bc03cc102317c4af6ecaMarek Olšák    for (; i < 3; i++) {
43083b76657b3dbf5e00d73bc03cc102317c4af6ecaMarek Olšák        swizzle |= R300_SWIZZLE_SELECT_FP_ZERO << (3*i);
43183b76657b3dbf5e00d73bc03cc102317c4af6ecaMarek Olšák    }
43283b76657b3dbf5e00d73bc03cc102317c4af6ecaMarek Olšák    for (; i < 4; i++) {
43383b76657b3dbf5e00d73bc03cc102317c4af6ecaMarek Olšák        swizzle |= R300_SWIZZLE_SELECT_FP_ONE << (3*i);
43483b76657b3dbf5e00d73bc03cc102317c4af6ecaMarek Olšák    }
43552e591383bdce49cb46a1162aff9632c57e06504Marek Olšák
43652e591383bdce49cb46a1162aff9632c57e06504Marek Olšák    return swizzle | (0xf << R300_WRITE_ENA_SHIFT);
437dcd7f1c0551812cf39ca6a3af9f1610ad84fb24eCorbin Simpson}
438dcd7f1c0551812cf39ca6a3af9f1610ad84fb24eCorbin Simpson
439ddc6ee316cd7ca07853efc615cd2681f3a1232d4Joakim Sindholt#endif /* R300_STATE_INLINES_H */
440