nvc0_state.c revision 1f5d6fc59bd899e211c70026eb74cd2219858008
14c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller/*
24c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * Copyright 2010 Christoph Bumiller
34c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller *
44c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * Permission is hereby granted, free of charge, to any person obtaining a
54c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * copy of this software and associated documentation files (the "Software"),
64c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * to deal in the Software without restriction, including without limitation
74c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * the rights to use, copy, modify, merge, publish, distribute, sublicense,
84c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * and/or sell copies of the Software, and to permit persons to whom the
94c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * Software is furnished to do so, subject to the following conditions:
104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller *
114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * The above copyright notice and this permission notice shall be included in
124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * all copies or substantial portions of the Software.
134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller *
144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * SOFTWARE.
214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller */
224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "pipe/p_defines.h"
244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "util/u_inlines.h"
25588fa884d212eba5ffbc69fda75db37d7c77214cMarek Olšák#include "util/u_transfer.h"
264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "tgsi/tgsi_parse.h"
284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "nvc0_stateobj.h"
304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "nvc0_context.h"
314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "nvc0_3d.xml.h"
33e4c968cdbbdc020afbf869d12b536c0a0dbf9de8Christoph Bumiller#include "nv50/nv50_texture.xml.h"
344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "nouveau/nouveau_gldefs.h"
364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic INLINE uint32_t
384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_colormask(unsigned mask)
394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    uint32_t ret = 0;
414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (mask & PIPE_MASK_R)
434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        ret |= 0x0001;
444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (mask & PIPE_MASK_G)
454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        ret |= 0x0010;
464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (mask & PIPE_MASK_B)
474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        ret |= 0x0100;
484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (mask & PIPE_MASK_A)
494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        ret |= 0x1000;
504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    return ret;
524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
543903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller#define NVC0_BLEND_FACTOR_CASE(a, b) \
553903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   case PIPE_BLENDFACTOR_##a: return NV50_3D_BLEND_FACTOR_##b
563903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller
574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic INLINE uint32_t
584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_blend_fac(unsigned factor)
594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
603903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   switch (factor) {
613903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   NVC0_BLEND_FACTOR_CASE(ONE, ONE);
623903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   NVC0_BLEND_FACTOR_CASE(SRC_COLOR, SRC_COLOR);
633903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   NVC0_BLEND_FACTOR_CASE(SRC_ALPHA, SRC_ALPHA);
643903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   NVC0_BLEND_FACTOR_CASE(DST_ALPHA, DST_ALPHA);
653903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   NVC0_BLEND_FACTOR_CASE(DST_COLOR, DST_COLOR);
663903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   NVC0_BLEND_FACTOR_CASE(SRC_ALPHA_SATURATE, SRC_ALPHA_SATURATE);
673903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   NVC0_BLEND_FACTOR_CASE(CONST_COLOR, CONSTANT_COLOR);
683903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   NVC0_BLEND_FACTOR_CASE(CONST_ALPHA, CONSTANT_ALPHA);
693903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   NVC0_BLEND_FACTOR_CASE(SRC1_COLOR, SRC1_COLOR);
703903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   NVC0_BLEND_FACTOR_CASE(SRC1_ALPHA, SRC1_ALPHA);
713903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   NVC0_BLEND_FACTOR_CASE(ZERO, ZERO);
723903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   NVC0_BLEND_FACTOR_CASE(INV_SRC_COLOR, ONE_MINUS_SRC_COLOR);
733903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   NVC0_BLEND_FACTOR_CASE(INV_SRC_ALPHA, ONE_MINUS_SRC_ALPHA);
743903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   NVC0_BLEND_FACTOR_CASE(INV_DST_ALPHA, ONE_MINUS_DST_ALPHA);
753903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   NVC0_BLEND_FACTOR_CASE(INV_DST_COLOR, ONE_MINUS_DST_COLOR);
763903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   NVC0_BLEND_FACTOR_CASE(INV_CONST_COLOR, ONE_MINUS_CONSTANT_COLOR);
773903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   NVC0_BLEND_FACTOR_CASE(INV_CONST_ALPHA, ONE_MINUS_CONSTANT_ALPHA);
783903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   NVC0_BLEND_FACTOR_CASE(INV_SRC1_COLOR, ONE_MINUS_SRC1_COLOR);
793903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   NVC0_BLEND_FACTOR_CASE(INV_SRC1_ALPHA, ONE_MINUS_SRC1_ALPHA);
803903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   default:
813903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller      return NV50_3D_BLEND_FACTOR_ZERO;
823903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller   }
834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_blend_state_create(struct pipe_context *pipe,
874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                        const struct pipe_blend_state *cso)
884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_blend_stateobj *so = CALLOC_STRUCT(nvc0_blend_stateobj);
904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    int i;
914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    so->pipe = *cso;
934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
942c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller    SB_IMMED_3D(so, BLEND_INDEPENDENT, cso->independent_blend_enable);
954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (!cso->independent_blend_enable) {
974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_BEGIN_3D(so, BLEND_ENABLES, 1);
984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, cso->rt[0].blend_enable ? 0xff : 0);
994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        if (cso->rt[0].blend_enable) {
1014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_BEGIN_3D(so, BLEND_EQUATION_RGB, 5);
1024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvgl_blend_eqn(cso->rt[0].rgb_func));
1034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[0].rgb_src_factor));
1044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[0].rgb_dst_factor));
1054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvgl_blend_eqn(cso->rt[0].alpha_func));
1064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[0].alpha_src_factor));
1074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_BEGIN_3D(so, BLEND_FUNC_DST_ALPHA, 1);
1084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[0].alpha_dst_factor));
1094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        }
1104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_BEGIN_3D(so, COLOR_MASK_BROADCAST, 1);
1124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, nvc0_colormask(cso->rt[0].colormask));
1134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    } else {
1144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        uint8_t en = 0;
1154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        for (i = 0; i < 8; ++i) {
1174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            if (!cso->rt[i].blend_enable)
1184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                continue;
1194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            en |= 1 << i;
1204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_BEGIN_3D(so, IBLEND_EQUATION_RGB(i), 6);
1224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvgl_blend_eqn(cso->rt[i].rgb_func));
1234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[i].rgb_src_factor));
1244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[i].rgb_dst_factor));
1254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvgl_blend_eqn(cso->rt[i].alpha_func));
1264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[i].alpha_src_factor));
1274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[i].alpha_dst_factor));
1284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        }
1294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_BEGIN_3D(so, BLEND_ENABLES, 1);
1304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, en);
1314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_BEGIN_3D(so, COLOR_MASK(0), 8);
1334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        for (i = 0; i < 8; ++i)
1344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA(so, nvc0_colormask(cso->rt[i].colormask));
1354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    }
1364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (cso->logicop_enable) {
1384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller       SB_BEGIN_3D(so, LOGIC_OP_ENABLE, 2);
1394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller       SB_DATA    (so, 1);
1404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller       SB_DATA    (so, nvgl_logicop_func(cso->logicop_func));
1414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    } else {
1422c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller       SB_IMMED_3D(so, LOGIC_OP_ENABLE, 0);
1434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    }
1444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    assert(so->size < (sizeof(so->state) / sizeof(so->state[0])));
1464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    return so;
1474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
1484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
1504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_blend_state_bind(struct pipe_context *pipe, void *hwcso)
1514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
1524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
1534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->blend = hwcso;
1554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_BLEND;
1564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
1574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
1594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_blend_state_delete(struct pipe_context *pipe, void *hwcso)
1604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
1614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    FREE(hwcso);
1624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
1634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
1654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_rasterizer_state_create(struct pipe_context *pipe,
1664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                             const struct pipe_rasterizer_state *cso)
1674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
1684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_rasterizer_stateobj *so;
1694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    so = CALLOC_STRUCT(nvc0_rasterizer_stateobj);
1714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (!so)
1724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        return NULL;
1734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    so->pipe = *cso;
174d047168d81cfeb39a98f3ae16416872facc6237cChristoph Bumiller
175e7845e319679e3539274c37e9c16692a2dfe59feChristoph Bumiller    /* Scissor enables are handled in scissor state, we will not want to
176e7845e319679e3539274c37e9c16692a2dfe59feChristoph Bumiller     * always emit 16 commands, one for each scissor rectangle, here.
177e7845e319679e3539274c37e9c16692a2dfe59feChristoph Bumiller     */
1784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_BEGIN_3D(so, SHADE_MODEL, 1);
1804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_DATA    (so, cso->flatshade ? NVC0_3D_SHADE_MODEL_FLAT :
1814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                                     NVC0_3D_SHADE_MODEL_SMOOTH);
1822c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller    SB_IMMED_3D(so, PROVOKING_VERTEX_LAST, !cso->flatshade_first);
1832c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller    SB_IMMED_3D(so, VERTEX_TWO_SIDE_ENABLE, cso->light_twoside);
1844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_BEGIN_3D(so, LINE_WIDTH, 1);
1864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_DATA    (so, fui(cso->line_width));
1872c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller    SB_IMMED_3D(so, LINE_SMOOTH_ENABLE, cso->line_smooth);
1884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_BEGIN_3D(so, LINE_STIPPLE_ENABLE, 1);
1904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (cso->line_stipple_enable) {
1914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, 1);
1924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_BEGIN_3D(so, LINE_STIPPLE_PATTERN, 1);
1934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, (cso->line_stipple_pattern << 8) |
1944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                         cso->line_stipple_factor);
1954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    } else {
1974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, 0);
1984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    }
1994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2002c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller    SB_IMMED_3D(so, VP_POINT_SIZE_EN, cso->point_size_per_vertex);
2014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (!cso->point_size_per_vertex) {
2024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller       SB_BEGIN_3D(so, POINT_SIZE, 1);
2034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller       SB_DATA    (so, fui(cso->point_size));
2044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    }
2052c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller    SB_IMMED_3D(so, POINT_SPRITE_ENABLE, cso->point_quad_rasterization);
206370ae0bd614fcbf9c4c0424fb5c41f2cfbc17b3eChristoph Bumiller    SB_IMMED_3D(so, POINT_SMOOTH_ENABLE, cso->point_smooth);
2074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_BEGIN_3D(so, POLYGON_MODE_FRONT, 1);
2094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_DATA    (so, nvgl_polygon_mode(cso->fill_front));
2104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_BEGIN_3D(so, POLYGON_MODE_BACK, 1);
2114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_DATA    (so, nvgl_polygon_mode(cso->fill_back));
2122c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller    SB_IMMED_3D(so, POLYGON_SMOOTH_ENABLE, cso->poly_smooth);
2134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
214dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    SB_BEGIN_3D(so, CULL_FACE_ENABLE, 3);
215dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    SB_DATA    (so, cso->cull_face != PIPE_FACE_NONE);
216dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    SB_DATA    (so, cso->front_ccw ? NVC0_3D_FRONT_FACE_CCW :
217dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller                                     NVC0_3D_FRONT_FACE_CW);
218dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    switch (cso->cull_face) {
219dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    case PIPE_FACE_FRONT_AND_BACK:
220dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller       SB_DATA(so, NVC0_3D_CULL_FACE_FRONT_AND_BACK);
221dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller       break;
222dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    case PIPE_FACE_FRONT:
223dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller       SB_DATA(so, NVC0_3D_CULL_FACE_FRONT);
224dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller       break;
225dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    case PIPE_FACE_BACK:
226dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    default:
227dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller       SB_DATA(so, NVC0_3D_CULL_FACE_BACK);
228dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller       break;
2294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    }
2304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2312c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller    SB_IMMED_3D(so, POLYGON_STIPPLE_ENABLE, cso->poly_stipple_enable);
2324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_BEGIN_3D(so, POLYGON_OFFSET_POINT_ENABLE, 3);
2334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_DATA    (so, cso->offset_point);
2344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_DATA    (so, cso->offset_line);
2354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_DATA    (so, cso->offset_tri);
2364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (cso->offset_point || cso->offset_line || cso->offset_tri) {
2384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_BEGIN_3D(so, POLYGON_OFFSET_FACTOR, 1);
2394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, fui(cso->offset_scale));
2404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_BEGIN_3D(so, POLYGON_OFFSET_UNITS, 1);
2411579017b08f28d460e17de65bcc8ba17ba695c37Christoph Bumiller        SB_DATA    (so, fui(cso->offset_units * 2.0f));
2424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    }
2434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    assert(so->size < (sizeof(so->state) / sizeof(so->state[0])));
2454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    return (void *)so;
2464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
2474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
2494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_rasterizer_state_bind(struct pipe_context *pipe, void *hwcso)
2504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
2514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   struct nvc0_context *nvc0 = nvc0_context(pipe);
2524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->rast = hwcso;
2544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->dirty |= NVC0_NEW_RASTERIZER;
2554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
2564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
2584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_rasterizer_state_delete(struct pipe_context *pipe, void *hwcso)
2594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
2604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   FREE(hwcso);
2614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
2624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
2644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_zsa_state_create(struct pipe_context *pipe,
2654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                      const struct pipe_depth_stencil_alpha_state *cso)
2664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
2674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   struct nvc0_zsa_stateobj *so = CALLOC_STRUCT(nvc0_zsa_stateobj);
2684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   so->pipe = *cso;
2704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2712c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller   SB_IMMED_3D(so, DEPTH_WRITE_ENABLE, cso->depth.writemask);
2724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   SB_BEGIN_3D(so, DEPTH_TEST_ENABLE, 1);
2734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (cso->depth.enabled) {
2744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, 1);
2754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_BEGIN_3D(so, DEPTH_TEST_FUNC, 1);
2764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_comparison_op(cso->depth.func));
2774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   } else {
2784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, 0);
2794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
2804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (cso->stencil[0].enabled) {
282293a8d1b600cd5bd89b3c4c0b6c2bb245d9bd80fChristoph Bumiller      SB_BEGIN_3D(so, STENCIL_ENABLE, 5);
2834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, 1);
2844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_stencil_op(cso->stencil[0].fail_op));
2854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_stencil_op(cso->stencil[0].zfail_op));
2864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_stencil_op(cso->stencil[0].zpass_op));
2874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_comparison_op(cso->stencil[0].func));
288293a8d1b600cd5bd89b3c4c0b6c2bb245d9bd80fChristoph Bumiller      SB_BEGIN_3D(so, STENCIL_FRONT_FUNC_MASK, 2);
2894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, cso->stencil[0].valuemask);
290293a8d1b600cd5bd89b3c4c0b6c2bb245d9bd80fChristoph Bumiller      SB_DATA    (so, cso->stencil[0].writemask);
2914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   } else {
292293a8d1b600cd5bd89b3c4c0b6c2bb245d9bd80fChristoph Bumiller      SB_IMMED_3D(so, STENCIL_ENABLE, 0);
2934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
2944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (cso->stencil[1].enabled) {
296293a8d1b600cd5bd89b3c4c0b6c2bb245d9bd80fChristoph Bumiller      assert(cso->stencil[0].enabled);
2974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_BEGIN_3D(so, STENCIL_TWO_SIDE_ENABLE, 5);
2984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, 1);
2994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_stencil_op(cso->stencil[1].fail_op));
3004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_stencil_op(cso->stencil[1].zfail_op));
3014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_stencil_op(cso->stencil[1].zpass_op));
3024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_comparison_op(cso->stencil[1].func));
3034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_BEGIN_3D(so, STENCIL_BACK_MASK, 2);
3044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, cso->stencil[1].writemask);
3054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, cso->stencil[1].valuemask);
306293a8d1b600cd5bd89b3c4c0b6c2bb245d9bd80fChristoph Bumiller   } else
307293a8d1b600cd5bd89b3c4c0b6c2bb245d9bd80fChristoph Bumiller   if (cso->stencil[0].enabled) {
3082c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller      SB_IMMED_3D(so, STENCIL_TWO_SIDE_ENABLE, 0);
3094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
3104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   SB_BEGIN_3D(so, ALPHA_TEST_ENABLE, 1);
3124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (cso->alpha.enabled) {
3134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, 1);
3144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_BEGIN_3D(so, ALPHA_TEST_REF, 2);
3154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, fui(cso->alpha.ref_value));
3164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_comparison_op(cso->alpha.func));
3174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   } else {
3184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, 0);
3194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
3204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   assert(so->size < (sizeof(so->state) / sizeof(so->state[0])));
3224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   return (void *)so;
3234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
3244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
3264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_zsa_state_bind(struct pipe_context *pipe, void *hwcso)
3274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
3284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   struct nvc0_context *nvc0 = nvc0_context(pipe);
3294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->zsa = hwcso;
3314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->dirty |= NVC0_NEW_ZSA;
3324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
3334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
3354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_zsa_state_delete(struct pipe_context *pipe, void *hwcso)
3364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
3374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   FREE(hwcso);
3384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
3394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller/* ====================== SAMPLERS AND TEXTURES ================================
3414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller */
3424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#define NV50_TSC_WRAP_CASE(n) \
3444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    case PIPE_TEX_WRAP_##n: return NV50_TSC_WRAP_##n
3454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic INLINE unsigned
3474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernv50_tsc_wrap_mode(unsigned wrap)
3484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
3494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   switch (wrap) {
3504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(REPEAT);
3514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(MIRROR_REPEAT);
3524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(CLAMP_TO_EDGE);
3534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(CLAMP_TO_BORDER);
3544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(CLAMP);
3554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(MIRROR_CLAMP_TO_EDGE);
3564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(MIRROR_CLAMP_TO_BORDER);
3574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(MIRROR_CLAMP);
3584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   default:
3594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller       NOUVEAU_ERR("unknown wrap mode: %d\n", wrap);
3604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller       return NV50_TSC_WRAP_REPEAT;
3614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
3624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
3634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
3654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_sampler_state_delete(struct pipe_context *pipe, void *hwcso)
3664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
3674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   unsigned s, i;
3684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   for (s = 0; s < 5; ++s)
3704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      for (i = 0; i < nvc0_context(pipe)->num_samplers[s]; ++i)
3714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller         if (nvc0_context(pipe)->samplers[s][i] == hwcso)
3724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            nvc0_context(pipe)->samplers[s][i] = NULL;
3734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3741f5d6fc59bd899e211c70026eb74cd2219858008Christoph Bumiller   nvc0_screen_tsc_free(nvc0_context(pipe)->screen, nv50_tsc_entry(hwcso));
3754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   FREE(hwcso);
3774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
3784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic INLINE void
3804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_stage_sampler_states_bind(struct nvc0_context *nvc0, int s,
3814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                               unsigned nr, void **hwcso)
3824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
3834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   unsigned i;
3844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   for (i = 0; i < nr; ++i) {
3861f5d6fc59bd899e211c70026eb74cd2219858008Christoph Bumiller      struct nv50_tsc_entry *old = nvc0->samplers[s][i];
3874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3881f5d6fc59bd899e211c70026eb74cd2219858008Christoph Bumiller      nvc0->samplers[s][i] = nv50_tsc_entry(hwcso[i]);
3894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      if (old)
3904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller         nvc0_screen_tsc_unlock(nvc0->screen, old);
3914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
3924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   for (; i < nvc0->num_samplers[s]; ++i)
3934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      if (nvc0->samplers[s][i])
3944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller         nvc0_screen_tsc_unlock(nvc0->screen, nvc0->samplers[s][i]);
3954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->num_samplers[s] = nr;
3974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->dirty |= NVC0_NEW_SAMPLERS;
3994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
4004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
4024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_vp_sampler_states_bind(struct pipe_context *pipe, unsigned nr, void **s)
4034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
4044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_stage_sampler_states_bind(nvc0_context(pipe), 0, nr, s);
4054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
4064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
4084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_fp_sampler_states_bind(struct pipe_context *pipe, unsigned nr, void **s)
4094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
4104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_stage_sampler_states_bind(nvc0_context(pipe), 4, nr, s);
4114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
4124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
4144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_gp_sampler_states_bind(struct pipe_context *pipe, unsigned nr, void **s)
4154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
4164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_stage_sampler_states_bind(nvc0_context(pipe), 3, nr, s);
4174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
4184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller/* NOTE: only called when not referenced anywhere, won't be bound */
4204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
4214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_sampler_view_destroy(struct pipe_context *pipe,
4224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          struct pipe_sampler_view *view)
4234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
4244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   pipe_resource_reference(&view->texture, NULL);
4254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4261f5d6fc59bd899e211c70026eb74cd2219858008Christoph Bumiller   nvc0_screen_tic_free(nvc0_context(pipe)->screen, nv50_tic_entry(view));
4274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4281f5d6fc59bd899e211c70026eb74cd2219858008Christoph Bumiller   FREE(nv50_tic_entry(view));
4294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
4304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic INLINE void
4324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_stage_set_sampler_views(struct nvc0_context *nvc0, int s,
4334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                             unsigned nr,
4344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                             struct pipe_sampler_view **views)
4354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
4364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   unsigned i;
4374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   for (i = 0; i < nr; ++i) {
4391f5d6fc59bd899e211c70026eb74cd2219858008Christoph Bumiller      struct nv50_tic_entry *old = nv50_tic_entry(nvc0->textures[s][i]);
4404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      if (old)
4414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller         nvc0_screen_tic_unlock(nvc0->screen, old);
4424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      pipe_sampler_view_reference(&nvc0->textures[s][i], views[i]);
4444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
4454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   for (i = nr; i < nvc0->num_textures[s]; ++i) {
4471f5d6fc59bd899e211c70026eb74cd2219858008Christoph Bumiller      struct nv50_tic_entry *old = nv50_tic_entry(nvc0->textures[s][i]);
4484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      if (!old)
4494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller         continue;
4504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      nvc0_screen_tic_unlock(nvc0->screen, old);
4514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      pipe_sampler_view_reference(&nvc0->textures[s][i], NULL);
4534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
4544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->num_textures[s] = nr;
4564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
457e4349027f6842563555992a39add4d0b2283fbbbChristoph Bumiller   nvc0_bufctx_reset(nvc0, NVC0_BUFCTX_TEXTURES);
458e4349027f6842563555992a39add4d0b2283fbbbChristoph Bumiller
4594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->dirty |= NVC0_NEW_TEXTURES;
4604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
4614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
4634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_vp_set_sampler_views(struct pipe_context *pipe,
4644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          unsigned nr,
4654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          struct pipe_sampler_view **views)
4664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
4674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_stage_set_sampler_views(nvc0_context(pipe), 0, nr, views);
4684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
4694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
4714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_fp_set_sampler_views(struct pipe_context *pipe,
4724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          unsigned nr,
4734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          struct pipe_sampler_view **views)
4744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
4754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_stage_set_sampler_views(nvc0_context(pipe), 4, nr, views);
4764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
4774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
4794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_gp_set_sampler_views(struct pipe_context *pipe,
4804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          unsigned nr,
4814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          struct pipe_sampler_view **views)
4824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
4834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_stage_set_sampler_views(nvc0_context(pipe), 3, nr, views);
4844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
4854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller/* ============================= SHADERS =======================================
4874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller */
4884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
4904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_sp_state_create(struct pipe_context *pipe,
4914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                     const struct pipe_shader_state *cso, unsigned type)
4924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
4934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   struct nvc0_program *prog;
4944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   prog = CALLOC_STRUCT(nvc0_program);
4964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (!prog)
4974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      return NULL;
4984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   prog->type = type;
5004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   prog->pipe.tokens = tgsi_dup_tokens(cso->tokens);
5014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   return (void *)prog;
5034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
5064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_sp_state_delete(struct pipe_context *pipe, void *hwcso)
5074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   struct nvc0_program *prog = (struct nvc0_program *)hwcso;
5094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_program_destroy(nvc0_context(pipe), prog);
5114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   FREE((void *)prog->pipe.tokens);
5134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   FREE(prog);
5144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
5174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_vp_state_create(struct pipe_context *pipe,
5184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                     const struct pipe_shader_state *cso)
5194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   return nvc0_sp_state_create(pipe, cso, PIPE_SHADER_VERTEX);
5214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
5244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_vp_state_bind(struct pipe_context *pipe, void *hwcso)
5254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
5274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->vertprog = hwcso;
5294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_VERTPROG;
5304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
5334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_fp_state_create(struct pipe_context *pipe,
5344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                     const struct pipe_shader_state *cso)
5354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   return nvc0_sp_state_create(pipe, cso, PIPE_SHADER_FRAGMENT);
5374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
5404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_fp_state_bind(struct pipe_context *pipe, void *hwcso)
5414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
5434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->fragprog = hwcso;
5454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_FRAGPROG;
5464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
5494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_gp_state_create(struct pipe_context *pipe,
5504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                     const struct pipe_shader_state *cso)
5514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   return nvc0_sp_state_create(pipe, cso, PIPE_SHADER_GEOMETRY);
5534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
5564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_gp_state_bind(struct pipe_context *pipe, void *hwcso)
5574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
5594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->gmtyprog = hwcso;
5614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_GMTYPROG;
5624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
5654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
5664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                         struct pipe_resource *res)
5674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   struct nvc0_context *nvc0 = nvc0_context(pipe);
5694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   switch (shader) {
5714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_SHADER_VERTEX: shader = 0; break;
5724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      /*
5734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_SHADER_TESSELLATION_CONTROL: shader = 1; break;
5744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_SHADER_TESSELLATION_EVALUATION: shader = 2; break;
5754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      */
5764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_SHADER_GEOMETRY: shader = 3; break;
5774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_SHADER_FRAGMENT: shader = 4; break;
5784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   default:
5794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      assert(0);
5804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      break;
5814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
5824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (nvc0->constbuf[shader][index])
5844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      nvc0_bufctx_del_resident(nvc0, NVC0_BUFCTX_CONSTANT,
5854826cd0f6125b071530026143ffd8205d84b3d5eBen Skeggs			       nv04_resource(nvc0->constbuf[shader][index]));
5864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   pipe_resource_reference(&nvc0->constbuf[shader][index], res);
5884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->constbuf_dirty[shader] |= 1 << index;
5904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->dirty |= NVC0_NEW_CONSTBUF;
5924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller/* =============================================================================
5954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller */
5964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
5984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_blend_color(struct pipe_context *pipe,
5994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                     const struct pipe_blend_color *bcol)
6004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
6024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->blend_colour = *bcol;
6044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_BLEND_COLOUR;
6054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
6084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_stencil_ref(struct pipe_context *pipe,
6094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                     const struct pipe_stencil_ref *sr)
6104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
6124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->stencil_ref = *sr;
6144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_STENCIL_REF;
6154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
6184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_clip_state(struct pipe_context *pipe,
6194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                    const struct pipe_clip_state *clip)
6204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
6225138ac033ad3708e2b82f2beebc887f65a77309eChristoph Bumiller    const unsigned size = clip->nr * sizeof(clip->ucp[0]);
6235138ac033ad3708e2b82f2beebc887f65a77309eChristoph Bumiller
6245138ac033ad3708e2b82f2beebc887f65a77309eChristoph Bumiller    memcpy(&nvc0->clip.ucp[0][0], &clip->ucp[0][0], size);
6255138ac033ad3708e2b82f2beebc887f65a77309eChristoph Bumiller    nvc0->clip.nr = clip->nr;
6264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->clip.depth_clamp = clip->depth_clamp;
6285138ac033ad3708e2b82f2beebc887f65a77309eChristoph Bumiller
6294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_CLIP;
6304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
6334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_sample_mask(struct pipe_context *pipe, unsigned sample_mask)
6344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
6364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->sample_mask = sample_mask;
6384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_SAMPLE_MASK;
6394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
6434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_framebuffer_state(struct pipe_context *pipe,
6444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                           const struct pipe_framebuffer_state *fb)
6454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
6474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->framebuffer = *fb;
6494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_FRAMEBUFFER;
6504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
6534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_polygon_stipple(struct pipe_context *pipe,
6544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                         const struct pipe_poly_stipple *stipple)
6554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
6574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->stipple = *stipple;
6594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_STIPPLE;
6604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
6634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_scissor_state(struct pipe_context *pipe,
6644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                       const struct pipe_scissor_state *scissor)
6654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
6674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->scissor = *scissor;
6694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_SCISSOR;
6704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
6734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_viewport_state(struct pipe_context *pipe,
6744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                        const struct pipe_viewport_state *vpt)
6754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
6774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->viewport = *vpt;
6794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_VIEWPORT;
6804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
6834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_vertex_buffers(struct pipe_context *pipe,
6844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                        unsigned count,
6854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                        const struct pipe_vertex_buffer *vb)
6864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
6880cb6d1a4eb2dd682b499f54a82505bc3bd318bbcChristoph Bumiller    unsigned i;
6890cb6d1a4eb2dd682b499f54a82505bc3bd318bbcChristoph Bumiller
6900cb6d1a4eb2dd682b499f54a82505bc3bd318bbcChristoph Bumiller    for (i = 0; i < count; ++i)
6910cb6d1a4eb2dd682b499f54a82505bc3bd318bbcChristoph Bumiller       pipe_resource_reference(&nvc0->vtxbuf[i].buffer, vb[i].buffer);
6920cb6d1a4eb2dd682b499f54a82505bc3bd318bbcChristoph Bumiller    for (; i < nvc0->num_vtxbufs; ++i)
6930cb6d1a4eb2dd682b499f54a82505bc3bd318bbcChristoph Bumiller       pipe_resource_reference(&nvc0->vtxbuf[i].buffer, NULL);
6944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    memcpy(nvc0->vtxbuf, vb, sizeof(*vb) * count);
6964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->num_vtxbufs = count;
6974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
698e4349027f6842563555992a39add4d0b2283fbbbChristoph Bumiller    nvc0_bufctx_reset(nvc0, NVC0_BUFCTX_VERTEX);
699e4349027f6842563555992a39add4d0b2283fbbbChristoph Bumiller
7004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_ARRAYS;
7014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
7024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
7044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_index_buffer(struct pipe_context *pipe,
7054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                      const struct pipe_index_buffer *ib)
7064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
7074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
7084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (ib)
7104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        memcpy(&nvc0->idxbuf, ib, sizeof(nvc0->idxbuf));
7114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    else
7124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        nvc0->idxbuf.buffer = NULL;
7134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
7144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
7164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_vertex_state_bind(struct pipe_context *pipe, void *hwcso)
7174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
7184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
7194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->vertex = hwcso;
7214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_VERTEX;
7224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
7234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
724f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillerstatic void *
725f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillernvc0_tfb_state_create(struct pipe_context *pipe,
726f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller                      const struct pipe_stream_output_state *pso)
727f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller{
728f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   struct nvc0_transform_feedback_state *so;
729f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   int n = 0;
730f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   int i, c, b;
731f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
732f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   so = MALLOC(sizeof(*so) + pso->num_outputs * 4 * sizeof(uint8_t));
733f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   if (!so)
734f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller      return NULL;
735f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
736f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   for (b = 0; b < 4; ++b) {
737f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller      for (i = 0; i < pso->num_outputs; ++i) {
738f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller         if (pso->output_buffer[i] != b)
739f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller            continue;
740f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller         for (c = 0; c < 4; ++c) {
741f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller            if (!(pso->register_mask[i] & (1 << c)))
742f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller               continue;
743f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller            so->varying_count[b]++;
744f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller            so->varying_index[n++] = (pso->register_index[i] << 2) | c;
745f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller         }
746f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller      }
747f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller      so->stride[b] = so->varying_count[b] * 4;
748f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   }
749f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   if (pso->stride)
750f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller      so->stride[0] = pso->stride;
751f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
752f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   return so;
753f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller}
754f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
755f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillerstatic void
756f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillernvc0_tfb_state_delete(struct pipe_context *pipe, void *hwcso)
757f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller{
758f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   FREE(hwcso);
759f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller}
760f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
761f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillerstatic void
762f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillernvc0_tfb_state_bind(struct pipe_context *pipe, void *hwcso)
763f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller{
764f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   nvc0_context(pipe)->tfb = hwcso;
765f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   nvc0_context(pipe)->dirty |= NVC0_NEW_TFB;
766f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller}
767f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
768f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillerstatic void
769f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillernvc0_set_transform_feedback_buffers(struct pipe_context *pipe,
770f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller                                    struct pipe_resource **buffers,
771f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller                                    int *offsets,
772f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller                                    int num_buffers)
773f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller{
774f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   struct nvc0_context *nvc0 = nvc0_context(pipe);
775f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   int i;
776f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
777f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   assert(num_buffers >= 0 && num_buffers <= 4); /* why signed ? */
778f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
779f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   for (i = 0; i < num_buffers; ++i) {
780f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller       assert(offsets[i] >= 0);
781f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller       nvc0->tfb_offset[i] = offsets[i];
782f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller       pipe_resource_reference(&nvc0->tfbbuf[i], buffers[i]);
783f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   }
784f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   for (; i < nvc0->num_tfbbufs; ++i)
785f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller      pipe_resource_reference(&nvc0->tfbbuf[i], NULL);
786f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
787f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   nvc0->num_tfbbufs = num_buffers;
788f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
789f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   nvc0->dirty |= NVC0_NEW_TFB_BUFFERS;
790f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller}
791f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
7924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillervoid
7934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_init_state_functions(struct nvc0_context *nvc0)
7944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
7951ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   struct pipe_context *pipe = &nvc0->base.pipe;
7961ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs
7971ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->create_blend_state = nvc0_blend_state_create;
7981ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->bind_blend_state = nvc0_blend_state_bind;
7991ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->delete_blend_state = nvc0_blend_state_delete;
8001ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs
8011ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->create_rasterizer_state = nvc0_rasterizer_state_create;
8021ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->bind_rasterizer_state = nvc0_rasterizer_state_bind;
8031ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->delete_rasterizer_state = nvc0_rasterizer_state_delete;
8041ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs
8051ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->create_depth_stencil_alpha_state = nvc0_zsa_state_create;
8061ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->bind_depth_stencil_alpha_state = nvc0_zsa_state_bind;
8071ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->delete_depth_stencil_alpha_state = nvc0_zsa_state_delete;
8081ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs
8091f5d6fc59bd899e211c70026eb74cd2219858008Christoph Bumiller   pipe->create_sampler_state = nv50_sampler_state_create;
8101ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->delete_sampler_state = nvc0_sampler_state_delete;
8111ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->bind_vertex_sampler_states   = nvc0_vp_sampler_states_bind;
8121ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->bind_fragment_sampler_states = nvc0_fp_sampler_states_bind;
8131ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->bind_geometry_sampler_states = nvc0_gp_sampler_states_bind;
8141ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs
8151ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->create_sampler_view = nvc0_create_sampler_view;
8161ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->sampler_view_destroy = nvc0_sampler_view_destroy;
8171ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->set_vertex_sampler_views   = nvc0_vp_set_sampler_views;
8181ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->set_fragment_sampler_views = nvc0_fp_set_sampler_views;
8191ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->set_geometry_sampler_views = nvc0_gp_set_sampler_views;
8201ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs
8211ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->create_vs_state = nvc0_vp_state_create;
8221ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->create_fs_state = nvc0_fp_state_create;
8231ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->create_gs_state = nvc0_gp_state_create;
8241ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->bind_vs_state = nvc0_vp_state_bind;
8251ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->bind_fs_state = nvc0_fp_state_bind;
8261ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->bind_gs_state = nvc0_gp_state_bind;
8271ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->delete_vs_state = nvc0_sp_state_delete;
8281ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->delete_fs_state = nvc0_sp_state_delete;
8291ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->delete_gs_state = nvc0_sp_state_delete;
8301ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs
8311ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->set_blend_color = nvc0_set_blend_color;
8321ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->set_stencil_ref = nvc0_set_stencil_ref;
8331ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->set_clip_state = nvc0_set_clip_state;
8341ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->set_sample_mask = nvc0_set_sample_mask;
8351ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->set_constant_buffer = nvc0_set_constant_buffer;
8361ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->set_framebuffer_state = nvc0_set_framebuffer_state;
8371ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->set_polygon_stipple = nvc0_set_polygon_stipple;
8381ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->set_scissor_state = nvc0_set_scissor_state;
8391ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->set_viewport_state = nvc0_set_viewport_state;
8401ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs
8411ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->create_vertex_elements_state = nvc0_vertex_state_create;
8421ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->delete_vertex_elements_state = nvc0_vertex_state_delete;
8431ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->bind_vertex_elements_state = nvc0_vertex_state_bind;
8441ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs
8451ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->set_vertex_buffers = nvc0_set_vertex_buffers;
8461ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->set_index_buffer = nvc0_set_index_buffer;
8471ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs
8481ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->create_stream_output_state = nvc0_tfb_state_create;
8491ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->delete_stream_output_state = nvc0_tfb_state_delete;
8501ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->bind_stream_output_state = nvc0_tfb_state_bind;
8511ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->set_stream_output_buffers = nvc0_set_transform_feedback_buffers;
8521ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs
8531ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->redefine_user_buffer = u_default_redefine_user_buffer;
8544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
8554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
856