nvc0_state.c revision e7845e319679e3539274c37e9c16692a2dfe59fe
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"
334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "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
544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic INLINE uint32_t
554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_blend_fac(unsigned factor)
564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    static const uint16_t bf[] = {
584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ZERO, /* 0x00 */
594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ONE,
604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_SRC_COLOR,
614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_SRC_ALPHA,
624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_DST_ALPHA,
634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_DST_COLOR,
644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_SRC_ALPHA_SATURATE,
654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_CONSTANT_COLOR,
664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_CONSTANT_ALPHA,
674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_SRC1_COLOR,
684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_SRC1_ALPHA,
694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ZERO, /* 0x0b */
704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ZERO, /* 0x0c */
714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ZERO, /* 0x0d */
724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ZERO, /* 0x0e */
734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ZERO, /* 0x0f */
744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ZERO, /* 0x10 */
754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ZERO, /* 0x11 */
764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ONE_MINUS_SRC_COLOR,
774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ONE_MINUS_DST_ALPHA,
794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ONE_MINUS_DST_COLOR,
804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR,
814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA,
824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR,
834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA
844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    };
854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    assert(factor < (sizeof(bf) / sizeof(bf[0])));
874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    return bf[factor];
884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_blend_state_create(struct pipe_context *pipe,
924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                        const struct pipe_blend_state *cso)
934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_blend_stateobj *so = CALLOC_STRUCT(nvc0_blend_stateobj);
954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    int i;
964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    so->pipe = *cso;
984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
992c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller    SB_IMMED_3D(so, BLEND_INDEPENDENT, cso->independent_blend_enable);
1004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (!cso->independent_blend_enable) {
1024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_BEGIN_3D(so, BLEND_ENABLES, 1);
1034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, cso->rt[0].blend_enable ? 0xff : 0);
1044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        if (cso->rt[0].blend_enable) {
1064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_BEGIN_3D(so, BLEND_EQUATION_RGB, 5);
1074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvgl_blend_eqn(cso->rt[0].rgb_func));
1084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[0].rgb_src_factor));
1094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[0].rgb_dst_factor));
1104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvgl_blend_eqn(cso->rt[0].alpha_func));
1114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[0].alpha_src_factor));
1124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_BEGIN_3D(so, BLEND_FUNC_DST_ALPHA, 1);
1134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[0].alpha_dst_factor));
1144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        }
1154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_BEGIN_3D(so, COLOR_MASK_BROADCAST, 1);
1174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, nvc0_colormask(cso->rt[0].colormask));
1184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    } else {
1194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        uint8_t en = 0;
1204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        for (i = 0; i < 8; ++i) {
1224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            if (!cso->rt[i].blend_enable)
1234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                continue;
1244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            en |= 1 << i;
1254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_BEGIN_3D(so, IBLEND_EQUATION_RGB(i), 6);
1274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvgl_blend_eqn(cso->rt[i].rgb_func));
1284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[i].rgb_src_factor));
1294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[i].rgb_dst_factor));
1304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvgl_blend_eqn(cso->rt[i].alpha_func));
1314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[i].alpha_src_factor));
1324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[i].alpha_dst_factor));
1334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        }
1344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_BEGIN_3D(so, BLEND_ENABLES, 1);
1354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, en);
1364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_BEGIN_3D(so, COLOR_MASK(0), 8);
1384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        for (i = 0; i < 8; ++i)
1394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA(so, nvc0_colormask(cso->rt[i].colormask));
1404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    }
1414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (cso->logicop_enable) {
1434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller       SB_BEGIN_3D(so, LOGIC_OP_ENABLE, 2);
1444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller       SB_DATA    (so, 1);
1454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller       SB_DATA    (so, nvgl_logicop_func(cso->logicop_func));
1464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    } else {
1472c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller       SB_IMMED_3D(so, LOGIC_OP_ENABLE, 0);
1484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    }
1494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    assert(so->size < (sizeof(so->state) / sizeof(so->state[0])));
1514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    return so;
1524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
1534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
1554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_blend_state_bind(struct pipe_context *pipe, void *hwcso)
1564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
1574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
1584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->blend = hwcso;
1604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_BLEND;
1614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
1624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
1644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_blend_state_delete(struct pipe_context *pipe, void *hwcso)
1654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
1664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    FREE(hwcso);
1674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
1684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
1704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_rasterizer_state_create(struct pipe_context *pipe,
1714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                             const struct pipe_rasterizer_state *cso)
1724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
1734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_rasterizer_stateobj *so;
1744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    so = CALLOC_STRUCT(nvc0_rasterizer_stateobj);
1764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (!so)
1774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        return NULL;
1784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    so->pipe = *cso;
179d047168d81cfeb39a98f3ae16416872facc6237cChristoph Bumiller
180e7845e319679e3539274c37e9c16692a2dfe59feChristoph Bumiller    /* Scissor enables are handled in scissor state, we will not want to
181e7845e319679e3539274c37e9c16692a2dfe59feChristoph Bumiller     * always emit 16 commands, one for each scissor rectangle, here.
182e7845e319679e3539274c37e9c16692a2dfe59feChristoph Bumiller     */
1834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_BEGIN_3D(so, SHADE_MODEL, 1);
1854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_DATA    (so, cso->flatshade ? NVC0_3D_SHADE_MODEL_FLAT :
1864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                                     NVC0_3D_SHADE_MODEL_SMOOTH);
1872c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller    SB_IMMED_3D(so, PROVOKING_VERTEX_LAST, !cso->flatshade_first);
1882c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller    SB_IMMED_3D(so, VERTEX_TWO_SIDE_ENABLE, cso->light_twoside);
1894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_BEGIN_3D(so, LINE_WIDTH, 1);
1914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_DATA    (so, fui(cso->line_width));
1922c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller    SB_IMMED_3D(so, LINE_SMOOTH_ENABLE, cso->line_smooth);
1934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_BEGIN_3D(so, LINE_STIPPLE_ENABLE, 1);
1954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (cso->line_stipple_enable) {
1964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, 1);
1974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_BEGIN_3D(so, LINE_STIPPLE_PATTERN, 1);
1984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, (cso->line_stipple_pattern << 8) |
1994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                         cso->line_stipple_factor);
2004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    } else {
2024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, 0);
2034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    }
2044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2052c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller    SB_IMMED_3D(so, VP_POINT_SIZE_EN, cso->point_size_per_vertex);
2064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (!cso->point_size_per_vertex) {
2074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller       SB_BEGIN_3D(so, POINT_SIZE, 1);
2084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller       SB_DATA    (so, fui(cso->point_size));
2094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    }
2102c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller    SB_IMMED_3D(so, POINT_SPRITE_ENABLE, cso->point_quad_rasterization);
211370ae0bd614fcbf9c4c0424fb5c41f2cfbc17b3eChristoph Bumiller    SB_IMMED_3D(so, POINT_SMOOTH_ENABLE, cso->point_smooth);
2124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_BEGIN_3D(so, POLYGON_MODE_FRONT, 1);
2144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_DATA    (so, nvgl_polygon_mode(cso->fill_front));
2154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_BEGIN_3D(so, POLYGON_MODE_BACK, 1);
2164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_DATA    (so, nvgl_polygon_mode(cso->fill_back));
2172c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller    SB_IMMED_3D(so, POLYGON_SMOOTH_ENABLE, cso->poly_smooth);
2184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
219dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    SB_BEGIN_3D(so, CULL_FACE_ENABLE, 3);
220dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    SB_DATA    (so, cso->cull_face != PIPE_FACE_NONE);
221dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    SB_DATA    (so, cso->front_ccw ? NVC0_3D_FRONT_FACE_CCW :
222dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller                                     NVC0_3D_FRONT_FACE_CW);
223dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    switch (cso->cull_face) {
224dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    case PIPE_FACE_FRONT_AND_BACK:
225dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller       SB_DATA(so, NVC0_3D_CULL_FACE_FRONT_AND_BACK);
226dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller       break;
227dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    case PIPE_FACE_FRONT:
228dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller       SB_DATA(so, NVC0_3D_CULL_FACE_FRONT);
229dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller       break;
230dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    case PIPE_FACE_BACK:
231dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    default:
232dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller       SB_DATA(so, NVC0_3D_CULL_FACE_BACK);
233dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller       break;
2344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    }
2354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2362c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller    SB_IMMED_3D(so, POLYGON_STIPPLE_ENABLE, cso->poly_stipple_enable);
2374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_BEGIN_3D(so, POLYGON_OFFSET_POINT_ENABLE, 3);
2384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_DATA    (so, cso->offset_point);
2394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_DATA    (so, cso->offset_line);
2404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_DATA    (so, cso->offset_tri);
2414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (cso->offset_point || cso->offset_line || cso->offset_tri) {
2434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_BEGIN_3D(so, POLYGON_OFFSET_FACTOR, 1);
2444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, fui(cso->offset_scale));
2454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_BEGIN_3D(so, POLYGON_OFFSET_UNITS, 1);
2464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, fui(cso->offset_units)); /* XXX: multiply by 2 ? */
2474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    }
2484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    assert(so->size < (sizeof(so->state) / sizeof(so->state[0])));
2504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    return (void *)so;
2514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
2524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
2544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_rasterizer_state_bind(struct pipe_context *pipe, void *hwcso)
2554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
2564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   struct nvc0_context *nvc0 = nvc0_context(pipe);
2574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->rast = hwcso;
2594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->dirty |= NVC0_NEW_RASTERIZER;
2604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
2614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
2634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_rasterizer_state_delete(struct pipe_context *pipe, void *hwcso)
2644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
2654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   FREE(hwcso);
2664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
2674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
2694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_zsa_state_create(struct pipe_context *pipe,
2704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                      const struct pipe_depth_stencil_alpha_state *cso)
2714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
2724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   struct nvc0_zsa_stateobj *so = CALLOC_STRUCT(nvc0_zsa_stateobj);
2734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   so->pipe = *cso;
2754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2762c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller   SB_IMMED_3D(so, DEPTH_WRITE_ENABLE, cso->depth.writemask);
2774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   SB_BEGIN_3D(so, DEPTH_TEST_ENABLE, 1);
2784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (cso->depth.enabled) {
2794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, 1);
2804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_BEGIN_3D(so, DEPTH_TEST_FUNC, 1);
2814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_comparison_op(cso->depth.func));
2824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   } else {
2834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, 0);
2844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
2854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (cso->stencil[0].enabled) {
287293a8d1b600cd5bd89b3c4c0b6c2bb245d9bd80fChristoph Bumiller      SB_BEGIN_3D(so, STENCIL_ENABLE, 5);
2884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, 1);
2894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_stencil_op(cso->stencil[0].fail_op));
2904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_stencil_op(cso->stencil[0].zfail_op));
2914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_stencil_op(cso->stencil[0].zpass_op));
2924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_comparison_op(cso->stencil[0].func));
293293a8d1b600cd5bd89b3c4c0b6c2bb245d9bd80fChristoph Bumiller      SB_BEGIN_3D(so, STENCIL_FRONT_FUNC_MASK, 2);
2944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, cso->stencil[0].valuemask);
295293a8d1b600cd5bd89b3c4c0b6c2bb245d9bd80fChristoph Bumiller      SB_DATA    (so, cso->stencil[0].writemask);
2964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   } else {
297293a8d1b600cd5bd89b3c4c0b6c2bb245d9bd80fChristoph Bumiller      SB_IMMED_3D(so, STENCIL_ENABLE, 0);
2984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
2994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (cso->stencil[1].enabled) {
301293a8d1b600cd5bd89b3c4c0b6c2bb245d9bd80fChristoph Bumiller      assert(cso->stencil[0].enabled);
3024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_BEGIN_3D(so, STENCIL_TWO_SIDE_ENABLE, 5);
3034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, 1);
3044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_stencil_op(cso->stencil[1].fail_op));
3054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_stencil_op(cso->stencil[1].zfail_op));
3064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_stencil_op(cso->stencil[1].zpass_op));
3074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_comparison_op(cso->stencil[1].func));
3084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_BEGIN_3D(so, STENCIL_BACK_MASK, 2);
3094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, cso->stencil[1].writemask);
3104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, cso->stencil[1].valuemask);
311293a8d1b600cd5bd89b3c4c0b6c2bb245d9bd80fChristoph Bumiller   } else
312293a8d1b600cd5bd89b3c4c0b6c2bb245d9bd80fChristoph Bumiller   if (cso->stencil[0].enabled) {
3132c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller      SB_IMMED_3D(so, STENCIL_TWO_SIDE_ENABLE, 0);
3144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
3154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   SB_BEGIN_3D(so, ALPHA_TEST_ENABLE, 1);
3174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (cso->alpha.enabled) {
3184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, 1);
3194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_BEGIN_3D(so, ALPHA_TEST_REF, 2);
3204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, fui(cso->alpha.ref_value));
3214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_comparison_op(cso->alpha.func));
3224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   } else {
3234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, 0);
3244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
3254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   assert(so->size < (sizeof(so->state) / sizeof(so->state[0])));
3274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   return (void *)so;
3284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
3294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
3314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_zsa_state_bind(struct pipe_context *pipe, void *hwcso)
3324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
3334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   struct nvc0_context *nvc0 = nvc0_context(pipe);
3344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->zsa = hwcso;
3364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->dirty |= NVC0_NEW_ZSA;
3374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
3384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
3404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_zsa_state_delete(struct pipe_context *pipe, void *hwcso)
3414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
3424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   FREE(hwcso);
3434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
3444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller/* ====================== SAMPLERS AND TEXTURES ================================
3464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller */
3474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#define NV50_TSC_WRAP_CASE(n) \
3494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    case PIPE_TEX_WRAP_##n: return NV50_TSC_WRAP_##n
3504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic INLINE unsigned
3524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernv50_tsc_wrap_mode(unsigned wrap)
3534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
3544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   switch (wrap) {
3554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(REPEAT);
3564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(MIRROR_REPEAT);
3574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(CLAMP_TO_EDGE);
3584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(CLAMP_TO_BORDER);
3594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(CLAMP);
3604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(MIRROR_CLAMP_TO_EDGE);
3614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(MIRROR_CLAMP_TO_BORDER);
3624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(MIRROR_CLAMP);
3634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   default:
3644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller       NOUVEAU_ERR("unknown wrap mode: %d\n", wrap);
3654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller       return NV50_TSC_WRAP_REPEAT;
3664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
3674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
3684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
3704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_sampler_state_create(struct pipe_context *pipe,
3714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          const struct pipe_sampler_state *cso)
3724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
3734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   struct nvc0_tsc_entry *so = CALLOC_STRUCT(nvc0_tsc_entry);
3744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   float f[2];
3754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   so->id = -1;
3774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   so->tsc[0] = (0x00026000 |
3794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                 (nv50_tsc_wrap_mode(cso->wrap_s) << 0) |
3804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                 (nv50_tsc_wrap_mode(cso->wrap_t) << 3) |
3814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                 (nv50_tsc_wrap_mode(cso->wrap_r) << 6));
3824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   switch (cso->mag_img_filter) {
3844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_TEX_FILTER_LINEAR:
3854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[1] |= NV50_TSC_1_MAGF_LINEAR;
3864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      break;
3874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_TEX_FILTER_NEAREST:
3884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   default:
3894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[1] |= NV50_TSC_1_MAGF_NEAREST;
3904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      break;
3914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
3924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   switch (cso->min_img_filter) {
3944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_TEX_FILTER_LINEAR:
3954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[1] |= NV50_TSC_1_MINF_LINEAR;
3964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      break;
3974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_TEX_FILTER_NEAREST:
3984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   default:
3994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[1] |= NV50_TSC_1_MINF_NEAREST;
4004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      break;
4014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
4024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   switch (cso->min_mip_filter) {
4044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_TEX_MIPFILTER_LINEAR:
4054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[1] |= NV50_TSC_1_MIPF_LINEAR;
4064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      break;
4074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_TEX_MIPFILTER_NEAREST:
4084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[1] |= NV50_TSC_1_MIPF_NEAREST;
4094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      break;
4104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_TEX_MIPFILTER_NONE:
4114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   default:
4124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[1] |= NV50_TSC_1_MIPF_NONE;
4134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      break;
4144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
4154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (cso->max_anisotropy >= 16)
4174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[0] |= (7 << 20);
4184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   else
4194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (cso->max_anisotropy >= 12)
4204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[0] |= (6 << 20);
4214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   else {
4224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[0] |= (cso->max_anisotropy >> 1) << 20;
4234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      if (cso->max_anisotropy >= 4)
4254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller         so->tsc[1] |= NV50_TSC_1_UNKN_ANISO_35;
4264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      else
4274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      if (cso->max_anisotropy >= 2)
4284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller         so->tsc[1] |= NV50_TSC_1_UNKN_ANISO_15;
4294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
4304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (cso->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) {
4324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      /* NOTE: must be deactivated for non-shadow textures */
4334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[0] |= (1 << 9);
4344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[0] |= (nvgl_comparison_op(cso->compare_func) & 0x7) << 10;
4354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
4364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   f[0] = CLAMP(cso->lod_bias, -16.0f, 15.0f);
4384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   so->tsc[1] |= ((int)(f[0] * 256.0f) & 0x1fff) << 12;
4394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   f[0] = CLAMP(cso->min_lod, 0.0f, 15.0f);
4414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   f[1] = CLAMP(cso->max_lod, 0.0f, 15.0f);
4424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   so->tsc[2] |=
4434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      (((int)(f[1] * 256.0f) & 0xfff) << 12) | ((int)(f[0] * 256.0f) & 0xfff);
4444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   so->tsc[4] = fui(cso->border_color[0]);
4464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   so->tsc[5] = fui(cso->border_color[1]);
4474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   so->tsc[6] = fui(cso->border_color[2]);
4484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   so->tsc[7] = fui(cso->border_color[3]);
4494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   return (void *)so;
4514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
4524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
4544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_sampler_state_delete(struct pipe_context *pipe, void *hwcso)
4554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
4564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   unsigned s, i;
4574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   for (s = 0; s < 5; ++s)
4594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      for (i = 0; i < nvc0_context(pipe)->num_samplers[s]; ++i)
4604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller         if (nvc0_context(pipe)->samplers[s][i] == hwcso)
4614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            nvc0_context(pipe)->samplers[s][i] = NULL;
4624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_screen_tsc_free(nvc0_context(pipe)->screen, nvc0_tsc_entry(hwcso));
4644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   FREE(hwcso);
4664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
4674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic INLINE void
4694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_stage_sampler_states_bind(struct nvc0_context *nvc0, int s,
4704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                               unsigned nr, void **hwcso)
4714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
4724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   unsigned i;
4734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   for (i = 0; i < nr; ++i) {
4754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      struct nvc0_tsc_entry *old = nvc0->samplers[s][i];
4764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      nvc0->samplers[s][i] = nvc0_tsc_entry(hwcso[i]);
4784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      if (old)
4794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller         nvc0_screen_tsc_unlock(nvc0->screen, old);
4804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
4814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   for (; i < nvc0->num_samplers[s]; ++i)
4824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      if (nvc0->samplers[s][i])
4834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller         nvc0_screen_tsc_unlock(nvc0->screen, nvc0->samplers[s][i]);
4844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->num_samplers[s] = nr;
4864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->dirty |= NVC0_NEW_SAMPLERS;
4884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
4894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
4914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_vp_sampler_states_bind(struct pipe_context *pipe, unsigned nr, void **s)
4924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
4934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_stage_sampler_states_bind(nvc0_context(pipe), 0, nr, s);
4944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
4954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
4974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_fp_sampler_states_bind(struct pipe_context *pipe, unsigned nr, void **s)
4984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
4994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_stage_sampler_states_bind(nvc0_context(pipe), 4, nr, s);
5004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
5034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_gp_sampler_states_bind(struct pipe_context *pipe, unsigned nr, void **s)
5044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_stage_sampler_states_bind(nvc0_context(pipe), 3, nr, s);
5064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller/* NOTE: only called when not referenced anywhere, won't be bound */
5094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
5104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_sampler_view_destroy(struct pipe_context *pipe,
5114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          struct pipe_sampler_view *view)
5124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   pipe_resource_reference(&view->texture, NULL);
5144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_screen_tic_free(nvc0_context(pipe)->screen, nvc0_tic_entry(view));
5164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   FREE(nvc0_tic_entry(view));
5184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic INLINE void
5214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_stage_set_sampler_views(struct nvc0_context *nvc0, int s,
5224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                             unsigned nr,
5234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                             struct pipe_sampler_view **views)
5244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   unsigned i;
5264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   for (i = 0; i < nr; ++i) {
5284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      struct nvc0_tic_entry *old = nvc0_tic_entry(nvc0->textures[s][i]);
5294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      if (old)
5304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller         nvc0_screen_tic_unlock(nvc0->screen, old);
5314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      pipe_sampler_view_reference(&nvc0->textures[s][i], views[i]);
5334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
5344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   for (i = nr; i < nvc0->num_textures[s]; ++i) {
5364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      struct nvc0_tic_entry *old = nvc0_tic_entry(nvc0->textures[s][i]);
5374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      if (!old)
5384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller         continue;
5394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      nvc0_screen_tic_unlock(nvc0->screen, old);
5404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      pipe_sampler_view_reference(&nvc0->textures[s][i], NULL);
5424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
5434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->num_textures[s] = nr;
5454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
546e4349027f6842563555992a39add4d0b2283fbbbChristoph Bumiller   nvc0_bufctx_reset(nvc0, NVC0_BUFCTX_TEXTURES);
547e4349027f6842563555992a39add4d0b2283fbbbChristoph Bumiller
5484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->dirty |= NVC0_NEW_TEXTURES;
5494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
5524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_vp_set_sampler_views(struct pipe_context *pipe,
5534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          unsigned nr,
5544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          struct pipe_sampler_view **views)
5554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_stage_set_sampler_views(nvc0_context(pipe), 0, nr, views);
5574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
5604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_fp_set_sampler_views(struct pipe_context *pipe,
5614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          unsigned nr,
5624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          struct pipe_sampler_view **views)
5634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_stage_set_sampler_views(nvc0_context(pipe), 4, nr, views);
5654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
5684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_gp_set_sampler_views(struct pipe_context *pipe,
5694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          unsigned nr,
5704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          struct pipe_sampler_view **views)
5714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_stage_set_sampler_views(nvc0_context(pipe), 3, nr, views);
5734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller/* ============================= SHADERS =======================================
5764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller */
5774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
5794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_sp_state_create(struct pipe_context *pipe,
5804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                     const struct pipe_shader_state *cso, unsigned type)
5814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   struct nvc0_program *prog;
5834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   prog = CALLOC_STRUCT(nvc0_program);
5854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (!prog)
5864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      return NULL;
5874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   prog->type = type;
5894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   prog->pipe.tokens = tgsi_dup_tokens(cso->tokens);
5904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   return (void *)prog;
5924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
5954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_sp_state_delete(struct pipe_context *pipe, void *hwcso)
5964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   struct nvc0_program *prog = (struct nvc0_program *)hwcso;
5984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_program_destroy(nvc0_context(pipe), prog);
6004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   FREE((void *)prog->pipe.tokens);
6024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   FREE(prog);
6034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
6064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_vp_state_create(struct pipe_context *pipe,
6074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                     const struct pipe_shader_state *cso)
6084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   return nvc0_sp_state_create(pipe, cso, PIPE_SHADER_VERTEX);
6104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
6134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_vp_state_bind(struct pipe_context *pipe, void *hwcso)
6144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
6164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->vertprog = hwcso;
6184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_VERTPROG;
6194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
6224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_fp_state_create(struct pipe_context *pipe,
6234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                     const struct pipe_shader_state *cso)
6244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   return nvc0_sp_state_create(pipe, cso, PIPE_SHADER_FRAGMENT);
6264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
6294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_fp_state_bind(struct pipe_context *pipe, void *hwcso)
6304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
6324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->fragprog = hwcso;
6344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_FRAGPROG;
6354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
6384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_gp_state_create(struct pipe_context *pipe,
6394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                     const struct pipe_shader_state *cso)
6404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   return nvc0_sp_state_create(pipe, cso, PIPE_SHADER_GEOMETRY);
6424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
6454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_gp_state_bind(struct pipe_context *pipe, void *hwcso)
6464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
6484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->gmtyprog = hwcso;
6504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_GMTYPROG;
6514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
6544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
6554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                         struct pipe_resource *res)
6564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   struct nvc0_context *nvc0 = nvc0_context(pipe);
6584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   switch (shader) {
6604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_SHADER_VERTEX: shader = 0; break;
6614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      /*
6624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_SHADER_TESSELLATION_CONTROL: shader = 1; break;
6634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_SHADER_TESSELLATION_EVALUATION: shader = 2; break;
6644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      */
6654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_SHADER_GEOMETRY: shader = 3; break;
6664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_SHADER_FRAGMENT: shader = 4; break;
6674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   default:
6684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      assert(0);
6694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      break;
6704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
6714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (nvc0->constbuf[shader][index])
6734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      nvc0_bufctx_del_resident(nvc0, NVC0_BUFCTX_CONSTANT,
6744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller			       nvc0_resource(
6754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller				       nvc0->constbuf[shader][index]));
6764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   pipe_resource_reference(&nvc0->constbuf[shader][index], res);
6784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->constbuf_dirty[shader] |= 1 << index;
6804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->dirty |= NVC0_NEW_CONSTBUF;
6824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller/* =============================================================================
6854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller */
6864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
6884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_blend_color(struct pipe_context *pipe,
6894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                     const struct pipe_blend_color *bcol)
6904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
6924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->blend_colour = *bcol;
6944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_BLEND_COLOUR;
6954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
6984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_stencil_ref(struct pipe_context *pipe,
6994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                     const struct pipe_stencil_ref *sr)
7004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
7014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
7024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->stencil_ref = *sr;
7044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_STENCIL_REF;
7054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
7064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
7084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_clip_state(struct pipe_context *pipe,
7094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                    const struct pipe_clip_state *clip)
7104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
7114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
7125138ac033ad3708e2b82f2beebc887f65a77309eChristoph Bumiller    const unsigned size = clip->nr * sizeof(clip->ucp[0]);
7135138ac033ad3708e2b82f2beebc887f65a77309eChristoph Bumiller
7145138ac033ad3708e2b82f2beebc887f65a77309eChristoph Bumiller    memcpy(&nvc0->clip.ucp[0][0], &clip->ucp[0][0], size);
7155138ac033ad3708e2b82f2beebc887f65a77309eChristoph Bumiller    nvc0->clip.nr = clip->nr;
7164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->clip.depth_clamp = clip->depth_clamp;
7185138ac033ad3708e2b82f2beebc887f65a77309eChristoph Bumiller
7194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_CLIP;
7204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
7214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
7234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_sample_mask(struct pipe_context *pipe, unsigned sample_mask)
7244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
7254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
7264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->sample_mask = sample_mask;
7284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_SAMPLE_MASK;
7294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
7304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
7334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_framebuffer_state(struct pipe_context *pipe,
7344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                           const struct pipe_framebuffer_state *fb)
7354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
7364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
7374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->framebuffer = *fb;
7394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_FRAMEBUFFER;
7404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
7414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
7434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_polygon_stipple(struct pipe_context *pipe,
7444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                         const struct pipe_poly_stipple *stipple)
7454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
7464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
7474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->stipple = *stipple;
7494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_STIPPLE;
7504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
7514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
7534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_scissor_state(struct pipe_context *pipe,
7544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                       const struct pipe_scissor_state *scissor)
7554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
7564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
7574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->scissor = *scissor;
7594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_SCISSOR;
7604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
7614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
7634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_viewport_state(struct pipe_context *pipe,
7644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                        const struct pipe_viewport_state *vpt)
7654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
7664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
7674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->viewport = *vpt;
7694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_VIEWPORT;
7704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
7714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
7734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_vertex_buffers(struct pipe_context *pipe,
7744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                        unsigned count,
7754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                        const struct pipe_vertex_buffer *vb)
7764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
7774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
7780cb6d1a4eb2dd682b499f54a82505bc3bd318bbcChristoph Bumiller    unsigned i;
7790cb6d1a4eb2dd682b499f54a82505bc3bd318bbcChristoph Bumiller
7800cb6d1a4eb2dd682b499f54a82505bc3bd318bbcChristoph Bumiller    for (i = 0; i < count; ++i)
7810cb6d1a4eb2dd682b499f54a82505bc3bd318bbcChristoph Bumiller       pipe_resource_reference(&nvc0->vtxbuf[i].buffer, vb[i].buffer);
7820cb6d1a4eb2dd682b499f54a82505bc3bd318bbcChristoph Bumiller    for (; i < nvc0->num_vtxbufs; ++i)
7830cb6d1a4eb2dd682b499f54a82505bc3bd318bbcChristoph Bumiller       pipe_resource_reference(&nvc0->vtxbuf[i].buffer, NULL);
7844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    memcpy(nvc0->vtxbuf, vb, sizeof(*vb) * count);
7864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->num_vtxbufs = count;
7874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
788e4349027f6842563555992a39add4d0b2283fbbbChristoph Bumiller    nvc0_bufctx_reset(nvc0, NVC0_BUFCTX_VERTEX);
789e4349027f6842563555992a39add4d0b2283fbbbChristoph Bumiller
7904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_ARRAYS;
7914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
7924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
7944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_index_buffer(struct pipe_context *pipe,
7954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                      const struct pipe_index_buffer *ib)
7964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
7974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
7984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (ib)
8004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        memcpy(&nvc0->idxbuf, ib, sizeof(nvc0->idxbuf));
8014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    else
8024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        nvc0->idxbuf.buffer = NULL;
8034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
8044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
8054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
8064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_vertex_state_bind(struct pipe_context *pipe, void *hwcso)
8074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
8084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
8094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
8104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->vertex = hwcso;
8114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_VERTEX;
8124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
8134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
814f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillerstatic void *
815f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillernvc0_tfb_state_create(struct pipe_context *pipe,
816f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller                      const struct pipe_stream_output_state *pso)
817f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller{
818f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   struct nvc0_transform_feedback_state *so;
819f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   int n = 0;
820f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   int i, c, b;
821f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
822f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   so = MALLOC(sizeof(*so) + pso->num_outputs * 4 * sizeof(uint8_t));
823f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   if (!so)
824f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller      return NULL;
825f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
826f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   for (b = 0; b < 4; ++b) {
827f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller      for (i = 0; i < pso->num_outputs; ++i) {
828f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller         if (pso->output_buffer[i] != b)
829f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller            continue;
830f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller         for (c = 0; c < 4; ++c) {
831f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller            if (!(pso->register_mask[i] & (1 << c)))
832f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller               continue;
833f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller            so->varying_count[b]++;
834f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller            so->varying_index[n++] = (pso->register_index[i] << 2) | c;
835f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller         }
836f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller      }
837f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller      so->stride[b] = so->varying_count[b] * 4;
838f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   }
839f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   if (pso->stride)
840f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller      so->stride[0] = pso->stride;
841f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
842f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   return so;
843f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller}
844f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
845f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillerstatic void
846f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillernvc0_tfb_state_delete(struct pipe_context *pipe, void *hwcso)
847f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller{
848f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   FREE(hwcso);
849f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller}
850f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
851f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillerstatic void
852f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillernvc0_tfb_state_bind(struct pipe_context *pipe, void *hwcso)
853f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller{
854f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   nvc0_context(pipe)->tfb = hwcso;
855f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   nvc0_context(pipe)->dirty |= NVC0_NEW_TFB;
856f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller}
857f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
858f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillerstatic void
859f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillernvc0_set_transform_feedback_buffers(struct pipe_context *pipe,
860f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller                                    struct pipe_resource **buffers,
861f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller                                    int *offsets,
862f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller                                    int num_buffers)
863f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller{
864f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   struct nvc0_context *nvc0 = nvc0_context(pipe);
865f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   int i;
866f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
867f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   assert(num_buffers >= 0 && num_buffers <= 4); /* why signed ? */
868f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
869f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   for (i = 0; i < num_buffers; ++i) {
870f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller       assert(offsets[i] >= 0);
871f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller       nvc0->tfb_offset[i] = offsets[i];
872f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller       pipe_resource_reference(&nvc0->tfbbuf[i], buffers[i]);
873f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   }
874f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   for (; i < nvc0->num_tfbbufs; ++i)
875f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller      pipe_resource_reference(&nvc0->tfbbuf[i], NULL);
876f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
877f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   nvc0->num_tfbbufs = num_buffers;
878f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
879f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller   nvc0->dirty |= NVC0_NEW_TFB_BUFFERS;
880f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller}
881f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
8824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillervoid
8834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_init_state_functions(struct nvc0_context *nvc0)
8844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
8854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.create_blend_state = nvc0_blend_state_create;
8864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.bind_blend_state = nvc0_blend_state_bind;
8874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.delete_blend_state = nvc0_blend_state_delete;
8884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
8894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.create_rasterizer_state = nvc0_rasterizer_state_create;
8904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.bind_rasterizer_state = nvc0_rasterizer_state_bind;
8914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.delete_rasterizer_state = nvc0_rasterizer_state_delete;
8924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
8934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.create_depth_stencil_alpha_state = nvc0_zsa_state_create;
8944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.bind_depth_stencil_alpha_state = nvc0_zsa_state_bind;
8954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.delete_depth_stencil_alpha_state = nvc0_zsa_state_delete;
8964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
8974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.create_sampler_state = nvc0_sampler_state_create;
8984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.delete_sampler_state = nvc0_sampler_state_delete;
8994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.bind_vertex_sampler_states   = nvc0_vp_sampler_states_bind;
9004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.bind_fragment_sampler_states = nvc0_fp_sampler_states_bind;
9014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.bind_geometry_sampler_states = nvc0_gp_sampler_states_bind;
9024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
9034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.create_sampler_view = nvc0_create_sampler_view;
9044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.sampler_view_destroy = nvc0_sampler_view_destroy;
9054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_vertex_sampler_views   = nvc0_vp_set_sampler_views;
9064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_fragment_sampler_views = nvc0_fp_set_sampler_views;
9074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_geometry_sampler_views = nvc0_gp_set_sampler_views;
9084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
9094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.create_vs_state = nvc0_vp_state_create;
9104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.create_fs_state = nvc0_fp_state_create;
9114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.create_gs_state = nvc0_gp_state_create;
9124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.bind_vs_state = nvc0_vp_state_bind;
9134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.bind_fs_state = nvc0_fp_state_bind;
9144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.bind_gs_state = nvc0_gp_state_bind;
9154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.delete_vs_state = nvc0_sp_state_delete;
9164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.delete_fs_state = nvc0_sp_state_delete;
9174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.delete_gs_state = nvc0_sp_state_delete;
9184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
9194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_blend_color = nvc0_set_blend_color;
9204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_stencil_ref = nvc0_set_stencil_ref;
9214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_clip_state = nvc0_set_clip_state;
9224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_sample_mask = nvc0_set_sample_mask;
9234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_constant_buffer = nvc0_set_constant_buffer;
9244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_framebuffer_state = nvc0_set_framebuffer_state;
9254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_polygon_stipple = nvc0_set_polygon_stipple;
9264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_scissor_state = nvc0_set_scissor_state;
9274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_viewport_state = nvc0_set_viewport_state;
9284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
9294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.create_vertex_elements_state = nvc0_vertex_state_create;
9304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.delete_vertex_elements_state = nvc0_vertex_state_delete;
9314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.bind_vertex_elements_state = nvc0_vertex_state_bind;
9324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
9334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_vertex_buffers = nvc0_set_vertex_buffers;
9344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_index_buffer = nvc0_set_index_buffer;
935f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller
936f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller    nvc0->pipe.create_stream_output_state = nvc0_tfb_state_create;
937f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller    nvc0->pipe.delete_stream_output_state = nvc0_tfb_state_delete;
938f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller    nvc0->pipe.bind_stream_output_state = nvc0_tfb_state_bind;
939f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller    nvc0->pipe.set_stream_output_buffers = nvc0_set_transform_feedback_buffers;
940588fa884d212eba5ffbc69fda75db37d7c77214cMarek Olšák
941588fa884d212eba5ffbc69fda75db37d7c77214cMarek Olšák    nvc0->pipe.redefine_user_buffer = u_default_redefine_user_buffer;
9424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
9434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
944