nvc0_state.c revision d047168d81cfeb39a98f3ae16416872facc6237c
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"
254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "tgsi/tgsi_parse.h"
274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "nvc0_stateobj.h"
294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "nvc0_context.h"
304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "nvc0_3d.xml.h"
324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "nv50_texture.xml.h"
334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "nouveau/nouveau_gldefs.h"
354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic INLINE uint32_t
374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_colormask(unsigned mask)
384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    uint32_t ret = 0;
404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (mask & PIPE_MASK_R)
424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        ret |= 0x0001;
434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (mask & PIPE_MASK_G)
444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        ret |= 0x0010;
454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (mask & PIPE_MASK_B)
464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        ret |= 0x0100;
474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (mask & PIPE_MASK_A)
484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        ret |= 0x1000;
494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    return ret;
514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic INLINE uint32_t
544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_blend_fac(unsigned factor)
554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    static const uint16_t bf[] = {
574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ZERO, /* 0x00 */
584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ONE,
594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_SRC_COLOR,
604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_SRC_ALPHA,
614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_DST_ALPHA,
624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_DST_COLOR,
634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_SRC_ALPHA_SATURATE,
644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_CONSTANT_COLOR,
654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_CONSTANT_ALPHA,
664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_SRC1_COLOR,
674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_SRC1_ALPHA,
684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ZERO, /* 0x0b */
694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ZERO, /* 0x0c */
704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ZERO, /* 0x0d */
714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ZERO, /* 0x0e */
724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ZERO, /* 0x0f */
734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ZERO, /* 0x10 */
744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ZERO, /* 0x11 */
754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ONE_MINUS_SRC_COLOR,
764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ONE_MINUS_DST_ALPHA,
784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ONE_MINUS_DST_COLOR,
794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR,
804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA,
814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR,
824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        NV50_3D_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA
834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    };
844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    assert(factor < (sizeof(bf) / sizeof(bf[0])));
864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    return bf[factor];
874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_blend_state_create(struct pipe_context *pipe,
914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                        const struct pipe_blend_state *cso)
924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_blend_stateobj *so = CALLOC_STRUCT(nvc0_blend_stateobj);
944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    int i;
954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    so->pipe = *cso;
974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_OUT_3D(so, BLEND_INDEPENDENT, cso->independent_blend_enable);
994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (!cso->independent_blend_enable) {
1014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_BEGIN_3D(so, BLEND_ENABLES, 1);
1024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, cso->rt[0].blend_enable ? 0xff : 0);
1034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        if (cso->rt[0].blend_enable) {
1054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_BEGIN_3D(so, BLEND_EQUATION_RGB, 5);
1064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvgl_blend_eqn(cso->rt[0].rgb_func));
1074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[0].rgb_src_factor));
1084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[0].rgb_dst_factor));
1094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvgl_blend_eqn(cso->rt[0].alpha_func));
1104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[0].alpha_src_factor));
1114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_BEGIN_3D(so, BLEND_FUNC_DST_ALPHA, 1);
1124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[0].alpha_dst_factor));
1134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        }
1144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_BEGIN_3D(so, COLOR_MASK_BROADCAST, 1);
1164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, nvc0_colormask(cso->rt[0].colormask));
1174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    } else {
1184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        uint8_t en = 0;
1194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        for (i = 0; i < 8; ++i) {
1214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            if (!cso->rt[i].blend_enable)
1224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                continue;
1234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            en |= 1 << i;
1244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_BEGIN_3D(so, IBLEND_EQUATION_RGB(i), 6);
1264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvgl_blend_eqn(cso->rt[i].rgb_func));
1274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[i].rgb_src_factor));
1284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[i].rgb_dst_factor));
1294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvgl_blend_eqn(cso->rt[i].alpha_func));
1304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[i].alpha_src_factor));
1314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA    (so, nvc0_blend_fac(cso->rt[i].alpha_dst_factor));
1324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        }
1334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_BEGIN_3D(so, BLEND_ENABLES, 1);
1344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, en);
1354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_BEGIN_3D(so, COLOR_MASK(0), 8);
1374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        for (i = 0; i < 8; ++i)
1384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            SB_DATA(so, nvc0_colormask(cso->rt[i].colormask));
1394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    }
1404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (cso->logicop_enable) {
1424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller       SB_BEGIN_3D(so, LOGIC_OP_ENABLE, 2);
1434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller       SB_DATA    (so, 1);
1444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller       SB_DATA    (so, nvgl_logicop_func(cso->logicop_func));
1454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    } else {
1464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller       SB_OUT_3D  (so, LOGIC_OP_ENABLE, 0);
1474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    }
1484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    assert(so->size < (sizeof(so->state) / sizeof(so->state[0])));
1504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    return so;
1514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
1524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
1544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_blend_state_bind(struct pipe_context *pipe, void *hwcso)
1554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
1564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
1574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->blend = hwcso;
1594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_BLEND;
1604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
1614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
1634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_blend_state_delete(struct pipe_context *pipe, void *hwcso)
1644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
1654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    FREE(hwcso);
1664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
1674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
1694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_rasterizer_state_create(struct pipe_context *pipe,
1704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                             const struct pipe_rasterizer_state *cso)
1714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
1724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_rasterizer_stateobj *so;
1734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    so = CALLOC_STRUCT(nvc0_rasterizer_stateobj);
1754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (!so)
1764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        return NULL;
1774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    so->pipe = *cso;
178d047168d81cfeb39a98f3ae16416872facc6237cChristoph Bumiller
179d047168d81cfeb39a98f3ae16416872facc6237cChristoph Bumiller#ifndef NVC0_SCISSORS_CLIPPING
180d047168d81cfeb39a98f3ae16416872facc6237cChristoph Bumiller    SB_OUT_3D  (so, SCISSOR_ENABLE(0), cso->scissor);
181d047168d81cfeb39a98f3ae16416872facc6237cChristoph Bumiller#endif
1824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_BEGIN_3D(so, SHADE_MODEL, 1);
1844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_DATA    (so, cso->flatshade ? NVC0_3D_SHADE_MODEL_FLAT :
1854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                                     NVC0_3D_SHADE_MODEL_SMOOTH);
1864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_OUT_3D  (so, PROVOKING_VERTEX_LAST, !cso->flatshade_first);
1874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_OUT_3D  (so, VERTEX_TWO_SIDE_ENABLE, cso->light_twoside);
1884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_BEGIN_3D(so, LINE_WIDTH, 1);
1904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_DATA    (so, fui(cso->line_width));
1914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_OUT_3D  (so, LINE_SMOOTH_ENABLE, cso->line_smooth);
1924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
1934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_BEGIN_3D(so, LINE_STIPPLE_ENABLE, 1);
1944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (cso->line_stipple_enable) {
1954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, 1);
1964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_BEGIN_3D(so, LINE_STIPPLE_PATTERN, 1);
1974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, (cso->line_stipple_pattern << 8) |
1984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                         cso->line_stipple_factor);
1994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    } else {
2014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, 0);
2024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    }
2034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_OUT_3D(so, VP_POINT_SIZE_EN, cso->point_size_per_vertex);
2054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (!cso->point_size_per_vertex) {
2064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller       SB_BEGIN_3D(so, POINT_SIZE, 1);
2074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller       SB_DATA    (so, fui(cso->point_size));
2084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    }
2094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_OUT_3D(so, POINT_SPRITE_ENABLE, cso->point_quad_rasterization);
2104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_BEGIN_3D(so, POLYGON_MODE_FRONT, 1);
2124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_DATA    (so, nvgl_polygon_mode(cso->fill_front));
2134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_BEGIN_3D(so, POLYGON_MODE_BACK, 1);
2144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_DATA    (so, nvgl_polygon_mode(cso->fill_back));
2154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_OUT_3D  (so, POLYGON_SMOOTH_ENABLE, cso->poly_smooth);
2164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
217dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    SB_BEGIN_3D(so, CULL_FACE_ENABLE, 3);
218dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    SB_DATA    (so, cso->cull_face != PIPE_FACE_NONE);
219dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    SB_DATA    (so, cso->front_ccw ? NVC0_3D_FRONT_FACE_CCW :
220dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller                                     NVC0_3D_FRONT_FACE_CW);
221dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    switch (cso->cull_face) {
222dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    case PIPE_FACE_FRONT_AND_BACK:
223dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller       SB_DATA(so, NVC0_3D_CULL_FACE_FRONT_AND_BACK);
224dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller       break;
225dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    case PIPE_FACE_FRONT:
226dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller       SB_DATA(so, NVC0_3D_CULL_FACE_FRONT);
227dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller       break;
228dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    case PIPE_FACE_BACK:
229dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller    default:
230dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller       SB_DATA(so, NVC0_3D_CULL_FACE_BACK);
231dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller       break;
2324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    }
2334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_OUT_3D  (so, POLYGON_STIPPLE_ENABLE, cso->poly_stipple_enable);
2354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_BEGIN_3D(so, POLYGON_OFFSET_POINT_ENABLE, 3);
2364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_DATA    (so, cso->offset_point);
2374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_DATA    (so, cso->offset_line);
2384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    SB_DATA    (so, cso->offset_tri);
2394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (cso->offset_point || cso->offset_line || cso->offset_tri) {
2414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_BEGIN_3D(so, POLYGON_OFFSET_FACTOR, 1);
2424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, fui(cso->offset_scale));
2434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_BEGIN_3D(so, POLYGON_OFFSET_UNITS, 1);
2444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        SB_DATA    (so, fui(cso->offset_units)); /* XXX: multiply by 2 ? */
2454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    }
2464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    assert(so->size < (sizeof(so->state) / sizeof(so->state[0])));
2484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    return (void *)so;
2494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
2504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
2524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_rasterizer_state_bind(struct pipe_context *pipe, void *hwcso)
2534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
2544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   struct nvc0_context *nvc0 = nvc0_context(pipe);
2554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->rast = hwcso;
2574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->dirty |= NVC0_NEW_RASTERIZER;
2584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
2594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
2614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_rasterizer_state_delete(struct pipe_context *pipe, void *hwcso)
2624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
2634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   FREE(hwcso);
2644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
2654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
2674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_zsa_state_create(struct pipe_context *pipe,
2684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                      const struct pipe_depth_stencil_alpha_state *cso)
2694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
2704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   struct nvc0_zsa_stateobj *so = CALLOC_STRUCT(nvc0_zsa_stateobj);
2714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   so->pipe = *cso;
2734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   SB_OUT_3D  (so, DEPTH_WRITE_ENABLE, cso->depth.writemask);
2754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   SB_BEGIN_3D(so, DEPTH_TEST_ENABLE, 1);
2764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (cso->depth.enabled) {
2774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, 1);
2784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_BEGIN_3D(so, DEPTH_TEST_FUNC, 1);
2794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_comparison_op(cso->depth.func));
2804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   } else {
2814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, 0);
2824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
2834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (cso->stencil[0].enabled) {
2854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_BEGIN_3D(so, STENCIL_FRONT_ENABLE, 5);
2864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, 1);
2874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_stencil_op(cso->stencil[0].fail_op));
2884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_stencil_op(cso->stencil[0].zfail_op));
2894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_stencil_op(cso->stencil[0].zpass_op));
2904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_comparison_op(cso->stencil[0].func));
2914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_BEGIN_3D(so, STENCIL_FRONT_MASK, 2);
2924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, cso->stencil[0].writemask);
2934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, cso->stencil[0].valuemask);
2944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   } else {
2954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_OUT_3D  (so, STENCIL_FRONT_ENABLE, 0);
2964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
2974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
2984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (cso->stencil[1].enabled) {
2994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_BEGIN_3D(so, STENCIL_TWO_SIDE_ENABLE, 5);
3004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, 1);
3014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_stencil_op(cso->stencil[1].fail_op));
3024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_stencil_op(cso->stencil[1].zfail_op));
3034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_stencil_op(cso->stencil[1].zpass_op));
3044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_comparison_op(cso->stencil[1].func));
3054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_BEGIN_3D(so, STENCIL_BACK_MASK, 2);
3064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, cso->stencil[1].writemask);
3074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, cso->stencil[1].valuemask);
3084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   } else {
3094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_OUT_3D  (so, STENCIL_TWO_SIDE_ENABLE, 0);
3104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
3114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   SB_BEGIN_3D(so, ALPHA_TEST_ENABLE, 1);
3134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (cso->alpha.enabled) {
3144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, 1);
3154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_BEGIN_3D(so, ALPHA_TEST_REF, 2);
3164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, fui(cso->alpha.ref_value));
3174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, nvgl_comparison_op(cso->alpha.func));
3184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   } else {
3194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      SB_DATA    (so, 0);
3204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
3214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   assert(so->size < (sizeof(so->state) / sizeof(so->state[0])));
3234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   return (void *)so;
3244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
3254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
3274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_zsa_state_bind(struct pipe_context *pipe, void *hwcso)
3284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
3294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   struct nvc0_context *nvc0 = nvc0_context(pipe);
3304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->zsa = hwcso;
3324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->dirty |= NVC0_NEW_ZSA;
3334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
3344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
3364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_zsa_state_delete(struct pipe_context *pipe, void *hwcso)
3374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
3384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   FREE(hwcso);
3394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
3404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller/* ====================== SAMPLERS AND TEXTURES ================================
3424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller */
3434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#define NV50_TSC_WRAP_CASE(n) \
3454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    case PIPE_TEX_WRAP_##n: return NV50_TSC_WRAP_##n
3464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic INLINE unsigned
3484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernv50_tsc_wrap_mode(unsigned wrap)
3494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
3504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   switch (wrap) {
3514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(REPEAT);
3524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(MIRROR_REPEAT);
3534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(CLAMP_TO_EDGE);
3544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(CLAMP_TO_BORDER);
3554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(CLAMP);
3564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(MIRROR_CLAMP_TO_EDGE);
3574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(MIRROR_CLAMP_TO_BORDER);
3584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   NV50_TSC_WRAP_CASE(MIRROR_CLAMP);
3594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   default:
3604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller       NOUVEAU_ERR("unknown wrap mode: %d\n", wrap);
3614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller       return NV50_TSC_WRAP_REPEAT;
3624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
3634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
3644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
3664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_sampler_state_create(struct pipe_context *pipe,
3674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          const struct pipe_sampler_state *cso)
3684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
3694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   struct nvc0_tsc_entry *so = CALLOC_STRUCT(nvc0_tsc_entry);
3704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   float f[2];
3714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   so->id = -1;
3734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   so->tsc[0] = (0x00026000 |
3754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                 (nv50_tsc_wrap_mode(cso->wrap_s) << 0) |
3764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                 (nv50_tsc_wrap_mode(cso->wrap_t) << 3) |
3774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                 (nv50_tsc_wrap_mode(cso->wrap_r) << 6));
3784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   switch (cso->mag_img_filter) {
3804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_TEX_FILTER_LINEAR:
3814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[1] |= NV50_TSC_1_MAGF_LINEAR;
3824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      break;
3834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_TEX_FILTER_NEAREST:
3844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   default:
3854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[1] |= NV50_TSC_1_MAGF_NEAREST;
3864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      break;
3874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
3884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   switch (cso->min_img_filter) {
3904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_TEX_FILTER_LINEAR:
3914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[1] |= NV50_TSC_1_MINF_LINEAR;
3924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      break;
3934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_TEX_FILTER_NEAREST:
3944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   default:
3954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[1] |= NV50_TSC_1_MINF_NEAREST;
3964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      break;
3974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
3984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
3994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   switch (cso->min_mip_filter) {
4004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_TEX_MIPFILTER_LINEAR:
4014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[1] |= NV50_TSC_1_MIPF_LINEAR;
4024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      break;
4034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_TEX_MIPFILTER_NEAREST:
4044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[1] |= NV50_TSC_1_MIPF_NEAREST;
4054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      break;
4064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_TEX_MIPFILTER_NONE:
4074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   default:
4084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[1] |= NV50_TSC_1_MIPF_NONE;
4094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      break;
4104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
4114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (cso->max_anisotropy >= 16)
4134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[0] |= (7 << 20);
4144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   else
4154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (cso->max_anisotropy >= 12)
4164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[0] |= (6 << 20);
4174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   else {
4184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[0] |= (cso->max_anisotropy >> 1) << 20;
4194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      if (cso->max_anisotropy >= 4)
4214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller         so->tsc[1] |= NV50_TSC_1_UNKN_ANISO_35;
4224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      else
4234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      if (cso->max_anisotropy >= 2)
4244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller         so->tsc[1] |= NV50_TSC_1_UNKN_ANISO_15;
4254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
4264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (cso->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) {
4284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      /* NOTE: must be deactivated for non-shadow textures */
4294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[0] |= (1 << 9);
4304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      so->tsc[0] |= (nvgl_comparison_op(cso->compare_func) & 0x7) << 10;
4314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
4324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   f[0] = CLAMP(cso->lod_bias, -16.0f, 15.0f);
4344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   so->tsc[1] |= ((int)(f[0] * 256.0f) & 0x1fff) << 12;
4354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   f[0] = CLAMP(cso->min_lod, 0.0f, 15.0f);
4374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   f[1] = CLAMP(cso->max_lod, 0.0f, 15.0f);
4384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   so->tsc[2] |=
4394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      (((int)(f[1] * 256.0f) & 0xfff) << 12) | ((int)(f[0] * 256.0f) & 0xfff);
4404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   so->tsc[4] = fui(cso->border_color[0]);
4424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   so->tsc[5] = fui(cso->border_color[1]);
4434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   so->tsc[6] = fui(cso->border_color[2]);
4444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   so->tsc[7] = fui(cso->border_color[3]);
4454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   return (void *)so;
4474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
4484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
4504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_sampler_state_delete(struct pipe_context *pipe, void *hwcso)
4514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
4524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   unsigned s, i;
4534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   for (s = 0; s < 5; ++s)
4554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      for (i = 0; i < nvc0_context(pipe)->num_samplers[s]; ++i)
4564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller         if (nvc0_context(pipe)->samplers[s][i] == hwcso)
4574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller            nvc0_context(pipe)->samplers[s][i] = NULL;
4584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_screen_tsc_free(nvc0_context(pipe)->screen, nvc0_tsc_entry(hwcso));
4604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   FREE(hwcso);
4624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
4634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic INLINE void
4654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_stage_sampler_states_bind(struct nvc0_context *nvc0, int s,
4664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                               unsigned nr, void **hwcso)
4674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
4684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   unsigned i;
4694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   for (i = 0; i < nr; ++i) {
4714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      struct nvc0_tsc_entry *old = nvc0->samplers[s][i];
4724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      nvc0->samplers[s][i] = nvc0_tsc_entry(hwcso[i]);
4744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      if (old)
4754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller         nvc0_screen_tsc_unlock(nvc0->screen, old);
4764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
4774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   for (; i < nvc0->num_samplers[s]; ++i)
4784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      if (nvc0->samplers[s][i])
4794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller         nvc0_screen_tsc_unlock(nvc0->screen, nvc0->samplers[s][i]);
4804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->num_samplers[s] = nr;
4824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->dirty |= NVC0_NEW_SAMPLERS;
4844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
4854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
4874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_vp_sampler_states_bind(struct pipe_context *pipe, unsigned nr, void **s)
4884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
4894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_stage_sampler_states_bind(nvc0_context(pipe), 0, nr, s);
4904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
4914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
4934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_fp_sampler_states_bind(struct pipe_context *pipe, unsigned nr, void **s)
4944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
4954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_stage_sampler_states_bind(nvc0_context(pipe), 4, nr, s);
4964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
4974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
4984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
4994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_gp_sampler_states_bind(struct pipe_context *pipe, unsigned nr, void **s)
5004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_stage_sampler_states_bind(nvc0_context(pipe), 3, nr, s);
5024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller/* NOTE: only called when not referenced anywhere, won't be bound */
5054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
5064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_sampler_view_destroy(struct pipe_context *pipe,
5074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          struct pipe_sampler_view *view)
5084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   pipe_resource_reference(&view->texture, NULL);
5104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_screen_tic_free(nvc0_context(pipe)->screen, nvc0_tic_entry(view));
5124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   FREE(nvc0_tic_entry(view));
5144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic INLINE void
5174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_stage_set_sampler_views(struct nvc0_context *nvc0, int s,
5184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                             unsigned nr,
5194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                             struct pipe_sampler_view **views)
5204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   unsigned i;
5224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   for (i = 0; i < nr; ++i) {
5244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      struct nvc0_tic_entry *old = nvc0_tic_entry(nvc0->textures[s][i]);
5254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      if (old)
5264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller         nvc0_screen_tic_unlock(nvc0->screen, old);
5274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      pipe_sampler_view_reference(&nvc0->textures[s][i], views[i]);
5294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
5304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   for (i = nr; i < nvc0->num_textures[s]; ++i) {
5324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      struct nvc0_tic_entry *old = nvc0_tic_entry(nvc0->textures[s][i]);
5334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      if (!old)
5344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller         continue;
5354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      nvc0_screen_tic_unlock(nvc0->screen, old);
5364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      pipe_sampler_view_reference(&nvc0->textures[s][i], NULL);
5384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
5394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->num_textures[s] = nr;
5414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->dirty |= NVC0_NEW_TEXTURES;
5434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
5464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_vp_set_sampler_views(struct pipe_context *pipe,
5474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          unsigned nr,
5484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          struct pipe_sampler_view **views)
5494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_stage_set_sampler_views(nvc0_context(pipe), 0, nr, views);
5514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
5544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_fp_set_sampler_views(struct pipe_context *pipe,
5554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          unsigned nr,
5564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          struct pipe_sampler_view **views)
5574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_stage_set_sampler_views(nvc0_context(pipe), 4, nr, views);
5594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
5624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_gp_set_sampler_views(struct pipe_context *pipe,
5634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          unsigned nr,
5644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                          struct pipe_sampler_view **views)
5654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_stage_set_sampler_views(nvc0_context(pipe), 3, nr, views);
5674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller/* ============================= SHADERS =======================================
5704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller */
5714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
5734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_sp_state_create(struct pipe_context *pipe,
5744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                     const struct pipe_shader_state *cso, unsigned type)
5754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   struct nvc0_program *prog;
5774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   prog = CALLOC_STRUCT(nvc0_program);
5794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (!prog)
5804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      return NULL;
5814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   prog->type = type;
5834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   prog->pipe.tokens = tgsi_dup_tokens(cso->tokens);
5844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   return (void *)prog;
5864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
5894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_sp_state_delete(struct pipe_context *pipe, void *hwcso)
5904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
5914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   struct nvc0_program *prog = (struct nvc0_program *)hwcso;
5924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0_program_destroy(nvc0_context(pipe), prog);
5944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   FREE((void *)prog->pipe.tokens);
5964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   FREE(prog);
5974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
5984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
5994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
6004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_vp_state_create(struct pipe_context *pipe,
6014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                     const struct pipe_shader_state *cso)
6024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   return nvc0_sp_state_create(pipe, cso, PIPE_SHADER_VERTEX);
6044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
6074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_vp_state_bind(struct pipe_context *pipe, void *hwcso)
6084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
6104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->vertprog = hwcso;
6124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_VERTPROG;
6134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
6164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_fp_state_create(struct pipe_context *pipe,
6174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                     const struct pipe_shader_state *cso)
6184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   return nvc0_sp_state_create(pipe, cso, PIPE_SHADER_FRAGMENT);
6204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
6234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_fp_state_bind(struct pipe_context *pipe, void *hwcso)
6244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
6264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->fragprog = hwcso;
6284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_FRAGPROG;
6294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void *
6324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_gp_state_create(struct pipe_context *pipe,
6334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                     const struct pipe_shader_state *cso)
6344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   return nvc0_sp_state_create(pipe, cso, PIPE_SHADER_GEOMETRY);
6364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
6394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_gp_state_bind(struct pipe_context *pipe, void *hwcso)
6404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
6424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->gmtyprog = hwcso;
6444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_GMTYPROG;
6454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
6484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
6494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                         struct pipe_resource *res)
6504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   struct nvc0_context *nvc0 = nvc0_context(pipe);
6524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   switch (shader) {
6544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_SHADER_VERTEX: shader = 0; break;
6554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      /*
6564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_SHADER_TESSELLATION_CONTROL: shader = 1; break;
6574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_SHADER_TESSELLATION_EVALUATION: shader = 2; break;
6584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      */
6594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_SHADER_GEOMETRY: shader = 3; break;
6604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   case PIPE_SHADER_FRAGMENT: shader = 4; break;
6614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   default:
6624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      assert(0);
6634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      break;
6644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   }
6654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   if (nvc0->constbuf[shader][index])
6674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller      nvc0_bufctx_del_resident(nvc0, NVC0_BUFCTX_CONSTANT,
6684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller			       nvc0_resource(
6694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller				       nvc0->constbuf[shader][index]));
6704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   pipe_resource_reference(&nvc0->constbuf[shader][index], res);
6724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->constbuf_dirty[shader] |= 1 << index;
6744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller   nvc0->dirty |= NVC0_NEW_CONSTBUF;
6764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller/* =============================================================================
6794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller */
6804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
6824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_blend_color(struct pipe_context *pipe,
6834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                     const struct pipe_blend_color *bcol)
6844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
6864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->blend_colour = *bcol;
6884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_BLEND_COLOUR;
6894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
6904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
6924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_stencil_ref(struct pipe_context *pipe,
6934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                     const struct pipe_stencil_ref *sr)
6944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
6954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
6964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
6974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->stencil_ref = *sr;
6984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_STENCIL_REF;
6994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
7004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
7024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_clip_state(struct pipe_context *pipe,
7034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                    const struct pipe_clip_state *clip)
7044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
7054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
7065138ac033ad3708e2b82f2beebc887f65a77309eChristoph Bumiller    const unsigned size = clip->nr * sizeof(clip->ucp[0]);
7075138ac033ad3708e2b82f2beebc887f65a77309eChristoph Bumiller
7085138ac033ad3708e2b82f2beebc887f65a77309eChristoph Bumiller    memcpy(&nvc0->clip.ucp[0][0], &clip->ucp[0][0], size);
7095138ac033ad3708e2b82f2beebc887f65a77309eChristoph Bumiller    nvc0->clip.nr = clip->nr;
7104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->clip.depth_clamp = clip->depth_clamp;
7125138ac033ad3708e2b82f2beebc887f65a77309eChristoph Bumiller
7134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_CLIP;
7144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
7154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
7174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_sample_mask(struct pipe_context *pipe, unsigned sample_mask)
7184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
7194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
7204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->sample_mask = sample_mask;
7224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_SAMPLE_MASK;
7234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
7244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
7274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_framebuffer_state(struct pipe_context *pipe,
7284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                           const struct pipe_framebuffer_state *fb)
7294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
7304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
7314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->framebuffer = *fb;
7334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_FRAMEBUFFER;
7344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
7354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
7374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_polygon_stipple(struct pipe_context *pipe,
7384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                         const struct pipe_poly_stipple *stipple)
7394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
7404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
7414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->stipple = *stipple;
7434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_STIPPLE;
7444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
7454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
7474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_scissor_state(struct pipe_context *pipe,
7484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                       const struct pipe_scissor_state *scissor)
7494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
7504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
7514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->scissor = *scissor;
7534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_SCISSOR;
7544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
7554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
7574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_viewport_state(struct pipe_context *pipe,
7584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                        const struct pipe_viewport_state *vpt)
7594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
7604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
7614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->viewport = *vpt;
7634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_VIEWPORT;
7644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
7654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
7674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_vertex_buffers(struct pipe_context *pipe,
7684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                        unsigned count,
7694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                        const struct pipe_vertex_buffer *vb)
7704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
7714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
7724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    memcpy(nvc0->vtxbuf, vb, sizeof(*vb) * count);
7744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->num_vtxbufs = count;
7754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_ARRAYS;
7774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
7784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
7804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_index_buffer(struct pipe_context *pipe,
7814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller                      const struct pipe_index_buffer *ib)
7824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
7834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
7844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    if (ib)
7864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        memcpy(&nvc0->idxbuf, ib, sizeof(nvc0->idxbuf));
7874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    else
7884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller        nvc0->idxbuf.buffer = NULL;
7894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
7904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void
7924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_vertex_state_bind(struct pipe_context *pipe, void *hwcso)
7934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
7944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    struct nvc0_context *nvc0 = nvc0_context(pipe);
7954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
7964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->vertex = hwcso;
7974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->dirty |= NVC0_NEW_VERTEX;
7984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
7994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
8004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillervoid
8014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_init_state_functions(struct nvc0_context *nvc0)
8024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{
8034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.create_blend_state = nvc0_blend_state_create;
8044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.bind_blend_state = nvc0_blend_state_bind;
8054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.delete_blend_state = nvc0_blend_state_delete;
8064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
8074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.create_rasterizer_state = nvc0_rasterizer_state_create;
8084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.bind_rasterizer_state = nvc0_rasterizer_state_bind;
8094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.delete_rasterizer_state = nvc0_rasterizer_state_delete;
8104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
8114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.create_depth_stencil_alpha_state = nvc0_zsa_state_create;
8124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.bind_depth_stencil_alpha_state = nvc0_zsa_state_bind;
8134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.delete_depth_stencil_alpha_state = nvc0_zsa_state_delete;
8144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
8154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.create_sampler_state = nvc0_sampler_state_create;
8164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.delete_sampler_state = nvc0_sampler_state_delete;
8174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.bind_vertex_sampler_states   = nvc0_vp_sampler_states_bind;
8184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.bind_fragment_sampler_states = nvc0_fp_sampler_states_bind;
8194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.bind_geometry_sampler_states = nvc0_gp_sampler_states_bind;
8204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
8214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.create_sampler_view = nvc0_create_sampler_view;
8224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.sampler_view_destroy = nvc0_sampler_view_destroy;
8234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_vertex_sampler_views   = nvc0_vp_set_sampler_views;
8244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_fragment_sampler_views = nvc0_fp_set_sampler_views;
8254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_geometry_sampler_views = nvc0_gp_set_sampler_views;
8264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
8274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.create_vs_state = nvc0_vp_state_create;
8284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.create_fs_state = nvc0_fp_state_create;
8294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.create_gs_state = nvc0_gp_state_create;
8304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.bind_vs_state = nvc0_vp_state_bind;
8314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.bind_fs_state = nvc0_fp_state_bind;
8324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.bind_gs_state = nvc0_gp_state_bind;
8334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.delete_vs_state = nvc0_sp_state_delete;
8344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.delete_fs_state = nvc0_sp_state_delete;
8354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.delete_gs_state = nvc0_sp_state_delete;
8364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
8374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_blend_color = nvc0_set_blend_color;
8384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_stencil_ref = nvc0_set_stencil_ref;
8394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_clip_state = nvc0_set_clip_state;
8404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_sample_mask = nvc0_set_sample_mask;
8414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_constant_buffer = nvc0_set_constant_buffer;
8424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_framebuffer_state = nvc0_set_framebuffer_state;
8434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_polygon_stipple = nvc0_set_polygon_stipple;
8444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_scissor_state = nvc0_set_scissor_state;
8454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_viewport_state = nvc0_set_viewport_state;
8464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
8474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.create_vertex_elements_state = nvc0_vertex_state_create;
8484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.delete_vertex_elements_state = nvc0_vertex_state_delete;
8494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.bind_vertex_elements_state = nvc0_vertex_state_bind;
8504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
8514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_vertex_buffers = nvc0_set_vertex_buffers;
8524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller    nvc0->pipe.set_index_buffer = nvc0_set_index_buffer;
8534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller}
8544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller
855