101e04c3fSmrg/*
201e04c3fSmrg * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
301e04c3fSmrg *
401e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a
501e04c3fSmrg * copy of this software and associated documentation files (the "Software"),
601e04c3fSmrg * to deal in the Software without restriction, including without limitation
701e04c3fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
801e04c3fSmrg * and/or sell copies of the Software, and to permit persons to whom the
901e04c3fSmrg * Software is furnished to do so, subject to the following conditions:
1001e04c3fSmrg *
1101e04c3fSmrg * The above copyright notice and this permission notice (including the next
1201e04c3fSmrg * paragraph) shall be included in all copies or substantial portions of the
1301e04c3fSmrg * Software.
1401e04c3fSmrg *
1501e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1601e04c3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1701e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1801e04c3fSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1901e04c3fSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2001e04c3fSmrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2101e04c3fSmrg * SOFTWARE.
2201e04c3fSmrg *
2301e04c3fSmrg * Authors:
2401e04c3fSmrg *    Rob Clark <robclark@freedesktop.org>
2501e04c3fSmrg */
2601e04c3fSmrg
2701e04c3fSmrg#ifndef TGSI_LOWERING_H_
2801e04c3fSmrg#define TGSI_LOWERING_H_
2901e04c3fSmrg
3001e04c3fSmrg#include "pipe/p_shader_tokens.h"
3101e04c3fSmrg#include "tgsi/tgsi_scan.h"
3201e04c3fSmrg
3301e04c3fSmrgstruct tgsi_lowering_config
3401e04c3fSmrg{
3501e04c3fSmrg   /* For fragment shaders, generate a shader that emulates two
3601e04c3fSmrg    * sided color by inserting a BGCOLOR input for each COLOR
3701e04c3fSmrg    * input, and insert a CMP instruction to select the correct
3801e04c3fSmrg    * color to use based on the TGSI_SEMANTIC_FACE input.
3901e04c3fSmrg    *
4001e04c3fSmrg    * Note that drivers which use this to emulate two sided color
4101e04c3fSmrg    * will:
4201e04c3fSmrg    *  a) need to generate (on demand) alternate shaders to use
4301e04c3fSmrg    *     depending on the rasterizer state (ie. whether two
4401e04c3fSmrg    *     sided shading enabled)
4501e04c3fSmrg    *  b) expect to see the BGCOLOR semantic name in fragment
4601e04c3fSmrg    *     shaders.  During linkage, the driver should simply
4701e04c3fSmrg    *     map VS.OUT.BGCOLOR[n] to FS.IN.BGCOLOR[n] (in the
4801e04c3fSmrg    *     same was as linking other outs/ins).
4901e04c3fSmrg    */
5001e04c3fSmrg   unsigned color_two_side:1;
5101e04c3fSmrg
5201e04c3fSmrg   /* TODO support for alpha_to_one as well?? */
5301e04c3fSmrg
5401e04c3fSmrg   /* Individual OPC lowerings, if lower_<opc> is TRUE then
5501e04c3fSmrg    * enable lowering of TGSI_OPCODE_<opc>
5601e04c3fSmrg    */
5701e04c3fSmrg   unsigned lower_DST:1;
5801e04c3fSmrg   unsigned lower_LRP:1;
5901e04c3fSmrg   unsigned lower_FRC:1;
6001e04c3fSmrg   unsigned lower_POW:1;
6101e04c3fSmrg   unsigned lower_LIT:1;
6201e04c3fSmrg   unsigned lower_EXP:1;
6301e04c3fSmrg   unsigned lower_LOG:1;
6401e04c3fSmrg   unsigned lower_DP4:1;
6501e04c3fSmrg   unsigned lower_DP3:1;
6601e04c3fSmrg   unsigned lower_DP2:1;
6701e04c3fSmrg   unsigned lower_FLR:1;
6801e04c3fSmrg   unsigned lower_CEIL:1;
6901e04c3fSmrg   unsigned lower_TRUNC:1;
7001e04c3fSmrg
7101e04c3fSmrg   /* bitmask of (1 << TGSI_TEXTURE_type): */
7201e04c3fSmrg   unsigned lower_TXP;
7301e04c3fSmrg
7401e04c3fSmrg   /* To emulate certain texture wrap modes, this can be used
7501e04c3fSmrg    * to saturate the specified tex coord to [0.0, 1.0].  The
7601e04c3fSmrg    * bits are according to sampler #, ie. if, for example:
7701e04c3fSmrg    *
7801e04c3fSmrg    *   (conf->saturate_s & (1 << n))
7901e04c3fSmrg    *
8001e04c3fSmrg    * is true, then the s coord for sampler n is saturated.
8101e04c3fSmrg    */
8201e04c3fSmrg   unsigned saturate_s, saturate_t, saturate_r;
8301e04c3fSmrg};
8401e04c3fSmrg
8501e04c3fSmrgconst struct tgsi_token *
8601e04c3fSmrgtgsi_transform_lowering(const struct tgsi_lowering_config *config,
8701e04c3fSmrg                        const struct tgsi_token *tokens,
8801e04c3fSmrg                        struct tgsi_shader_info *info);
8901e04c3fSmrg
9001e04c3fSmrg#endif /* FREEDRENO_LOWERING_H_ */
91