nvc0_state.c revision e4c968cdbbdc020afbf869d12b536c0a0dbf9de8
14c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller/* 24c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * Copyright 2010 Christoph Bumiller 34c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * 44c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * Permission is hereby granted, free of charge, to any person obtaining a 54c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * copy of this software and associated documentation files (the "Software"), 64c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * to deal in the Software without restriction, including without limitation 74c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * the rights to use, copy, modify, merge, publish, distribute, sublicense, 84c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * and/or sell copies of the Software, and to permit persons to whom the 94c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * Software is furnished to do so, subject to the following conditions: 104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * 114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * The above copyright notice and this permission notice shall be included in 124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * all copies or substantial portions of the Software. 134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * 144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * SOFTWARE. 214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller */ 224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "pipe/p_defines.h" 244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "util/u_inlines.h" 25588fa884d212eba5ffbc69fda75db37d7c77214cMarek Olšák#include "util/u_transfer.h" 264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "tgsi/tgsi_parse.h" 284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "nvc0_stateobj.h" 304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "nvc0_context.h" 314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "nvc0_3d.xml.h" 33e4c968cdbbdc020afbf869d12b536c0a0dbf9de8Christoph Bumiller#include "nv50/nv50_texture.xml.h" 344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "nouveau/nouveau_gldefs.h" 364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic INLINE uint32_t 384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_colormask(unsigned mask) 394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller uint32_t ret = 0; 414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (mask & PIPE_MASK_R) 434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller ret |= 0x0001; 444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (mask & PIPE_MASK_G) 454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller ret |= 0x0010; 464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (mask & PIPE_MASK_B) 474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller ret |= 0x0100; 484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (mask & PIPE_MASK_A) 494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller ret |= 0x1000; 504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller return ret; 524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 543903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller#define NVC0_BLEND_FACTOR_CASE(a, b) \ 553903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller case PIPE_BLENDFACTOR_##a: return NV50_3D_BLEND_FACTOR_##b 563903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller 574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic INLINE uint32_t 584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_blend_fac(unsigned factor) 594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 603903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller switch (factor) { 613903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller NVC0_BLEND_FACTOR_CASE(ONE, ONE); 623903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller NVC0_BLEND_FACTOR_CASE(SRC_COLOR, SRC_COLOR); 633903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller NVC0_BLEND_FACTOR_CASE(SRC_ALPHA, SRC_ALPHA); 643903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller NVC0_BLEND_FACTOR_CASE(DST_ALPHA, DST_ALPHA); 653903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller NVC0_BLEND_FACTOR_CASE(DST_COLOR, DST_COLOR); 663903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller NVC0_BLEND_FACTOR_CASE(SRC_ALPHA_SATURATE, SRC_ALPHA_SATURATE); 673903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller NVC0_BLEND_FACTOR_CASE(CONST_COLOR, CONSTANT_COLOR); 683903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller NVC0_BLEND_FACTOR_CASE(CONST_ALPHA, CONSTANT_ALPHA); 693903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller NVC0_BLEND_FACTOR_CASE(SRC1_COLOR, SRC1_COLOR); 703903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller NVC0_BLEND_FACTOR_CASE(SRC1_ALPHA, SRC1_ALPHA); 713903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller NVC0_BLEND_FACTOR_CASE(ZERO, ZERO); 723903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller NVC0_BLEND_FACTOR_CASE(INV_SRC_COLOR, ONE_MINUS_SRC_COLOR); 733903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller NVC0_BLEND_FACTOR_CASE(INV_SRC_ALPHA, ONE_MINUS_SRC_ALPHA); 743903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller NVC0_BLEND_FACTOR_CASE(INV_DST_ALPHA, ONE_MINUS_DST_ALPHA); 753903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller NVC0_BLEND_FACTOR_CASE(INV_DST_COLOR, ONE_MINUS_DST_COLOR); 763903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller NVC0_BLEND_FACTOR_CASE(INV_CONST_COLOR, ONE_MINUS_CONSTANT_COLOR); 773903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller NVC0_BLEND_FACTOR_CASE(INV_CONST_ALPHA, ONE_MINUS_CONSTANT_ALPHA); 783903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller NVC0_BLEND_FACTOR_CASE(INV_SRC1_COLOR, ONE_MINUS_SRC1_COLOR); 793903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller NVC0_BLEND_FACTOR_CASE(INV_SRC1_ALPHA, ONE_MINUS_SRC1_ALPHA); 803903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller default: 813903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller return NV50_3D_BLEND_FACTOR_ZERO; 823903e25a2cd6c198581021242897b1952d2afea0Christoph Bumiller } 834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void * 864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_blend_state_create(struct pipe_context *pipe, 874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller const struct pipe_blend_state *cso) 884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct nvc0_blend_stateobj *so = CALLOC_STRUCT(nvc0_blend_stateobj); 904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller int i; 914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->pipe = *cso; 934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 942c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller SB_IMMED_3D(so, BLEND_INDEPENDENT, cso->independent_blend_enable); 954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (!cso->independent_blend_enable) { 974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, BLEND_ENABLES, 1); 984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, cso->rt[0].blend_enable ? 0xff : 0); 994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 1004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (cso->rt[0].blend_enable) { 1014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, BLEND_EQUATION_RGB, 5); 1024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvgl_blend_eqn(cso->rt[0].rgb_func)); 1034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvc0_blend_fac(cso->rt[0].rgb_src_factor)); 1044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvc0_blend_fac(cso->rt[0].rgb_dst_factor)); 1054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvgl_blend_eqn(cso->rt[0].alpha_func)); 1064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvc0_blend_fac(cso->rt[0].alpha_src_factor)); 1074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, BLEND_FUNC_DST_ALPHA, 1); 1084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvc0_blend_fac(cso->rt[0].alpha_dst_factor)); 1094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 1104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 1114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, COLOR_MASK_BROADCAST, 1); 1124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvc0_colormask(cso->rt[0].colormask)); 1134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } else { 1144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller uint8_t en = 0; 1154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 1164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller for (i = 0; i < 8; ++i) { 1174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (!cso->rt[i].blend_enable) 1184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller continue; 1194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller en |= 1 << i; 1204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 1214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, IBLEND_EQUATION_RGB(i), 6); 1224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvgl_blend_eqn(cso->rt[i].rgb_func)); 1234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvc0_blend_fac(cso->rt[i].rgb_src_factor)); 1244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvc0_blend_fac(cso->rt[i].rgb_dst_factor)); 1254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvgl_blend_eqn(cso->rt[i].alpha_func)); 1264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvc0_blend_fac(cso->rt[i].alpha_src_factor)); 1274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvc0_blend_fac(cso->rt[i].alpha_dst_factor)); 1284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 1294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, BLEND_ENABLES, 1); 1304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, en); 1314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 1324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, COLOR_MASK(0), 8); 1334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller for (i = 0; i < 8; ++i) 1344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA(so, nvc0_colormask(cso->rt[i].colormask)); 1354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 1364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 1374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (cso->logicop_enable) { 1384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, LOGIC_OP_ENABLE, 2); 1394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, 1); 1404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvgl_logicop_func(cso->logicop_func)); 1414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } else { 1422c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller SB_IMMED_3D(so, LOGIC_OP_ENABLE, 0); 1434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 1444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 1454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller assert(so->size < (sizeof(so->state) / sizeof(so->state[0]))); 1464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller return so; 1474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 1484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 1494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 1504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_blend_state_bind(struct pipe_context *pipe, void *hwcso) 1514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 1524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct nvc0_context *nvc0 = nvc0_context(pipe); 1534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 1544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0->blend = hwcso; 1554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0->dirty |= NVC0_NEW_BLEND; 1564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 1574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 1584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 1594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_blend_state_delete(struct pipe_context *pipe, void *hwcso) 1604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 1614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller FREE(hwcso); 1624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 1634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 1644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void * 1654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_rasterizer_state_create(struct pipe_context *pipe, 1664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller const struct pipe_rasterizer_state *cso) 1674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 1684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct nvc0_rasterizer_stateobj *so; 1694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 1704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so = CALLOC_STRUCT(nvc0_rasterizer_stateobj); 1714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (!so) 1724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller return NULL; 1734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->pipe = *cso; 174d047168d81cfeb39a98f3ae16416872facc6237cChristoph Bumiller 175e7845e319679e3539274c37e9c16692a2dfe59feChristoph Bumiller /* Scissor enables are handled in scissor state, we will not want to 176e7845e319679e3539274c37e9c16692a2dfe59feChristoph Bumiller * always emit 16 commands, one for each scissor rectangle, here. 177e7845e319679e3539274c37e9c16692a2dfe59feChristoph Bumiller */ 1784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 1794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, SHADE_MODEL, 1); 1804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, cso->flatshade ? NVC0_3D_SHADE_MODEL_FLAT : 1814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller NVC0_3D_SHADE_MODEL_SMOOTH); 1822c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller SB_IMMED_3D(so, PROVOKING_VERTEX_LAST, !cso->flatshade_first); 1832c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller SB_IMMED_3D(so, VERTEX_TWO_SIDE_ENABLE, cso->light_twoside); 1844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 1854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, LINE_WIDTH, 1); 1864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, fui(cso->line_width)); 1872c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller SB_IMMED_3D(so, LINE_SMOOTH_ENABLE, cso->line_smooth); 1884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 1894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, LINE_STIPPLE_ENABLE, 1); 1904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (cso->line_stipple_enable) { 1914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, 1); 1924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, LINE_STIPPLE_PATTERN, 1); 1934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, (cso->line_stipple_pattern << 8) | 1944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller cso->line_stipple_factor); 1954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 1964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } else { 1974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, 0); 1984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 1994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 2002c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller SB_IMMED_3D(so, VP_POINT_SIZE_EN, cso->point_size_per_vertex); 2014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (!cso->point_size_per_vertex) { 2024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, POINT_SIZE, 1); 2034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, fui(cso->point_size)); 2044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 2052c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller SB_IMMED_3D(so, POINT_SPRITE_ENABLE, cso->point_quad_rasterization); 206370ae0bd614fcbf9c4c0424fb5c41f2cfbc17b3eChristoph Bumiller SB_IMMED_3D(so, POINT_SMOOTH_ENABLE, cso->point_smooth); 2074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 2084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, POLYGON_MODE_FRONT, 1); 2094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvgl_polygon_mode(cso->fill_front)); 2104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, POLYGON_MODE_BACK, 1); 2114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvgl_polygon_mode(cso->fill_back)); 2122c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller SB_IMMED_3D(so, POLYGON_SMOOTH_ENABLE, cso->poly_smooth); 2134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 214dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller SB_BEGIN_3D(so, CULL_FACE_ENABLE, 3); 215dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller SB_DATA (so, cso->cull_face != PIPE_FACE_NONE); 216dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller SB_DATA (so, cso->front_ccw ? NVC0_3D_FRONT_FACE_CCW : 217dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller NVC0_3D_FRONT_FACE_CW); 218dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller switch (cso->cull_face) { 219dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller case PIPE_FACE_FRONT_AND_BACK: 220dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller SB_DATA(so, NVC0_3D_CULL_FACE_FRONT_AND_BACK); 221dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller break; 222dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller case PIPE_FACE_FRONT: 223dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller SB_DATA(so, NVC0_3D_CULL_FACE_FRONT); 224dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller break; 225dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller case PIPE_FACE_BACK: 226dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller default: 227dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller SB_DATA(so, NVC0_3D_CULL_FACE_BACK); 228dea9d604005e9aaed2bd6807f1913ac668479443Christoph Bumiller break; 2294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 2304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 2312c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller SB_IMMED_3D(so, POLYGON_STIPPLE_ENABLE, cso->poly_stipple_enable); 2324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, POLYGON_OFFSET_POINT_ENABLE, 3); 2334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, cso->offset_point); 2344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, cso->offset_line); 2354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, cso->offset_tri); 2364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 2374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (cso->offset_point || cso->offset_line || cso->offset_tri) { 2384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, POLYGON_OFFSET_FACTOR, 1); 2394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, fui(cso->offset_scale)); 2404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, POLYGON_OFFSET_UNITS, 1); 2411579017b08f28d460e17de65bcc8ba17ba695c37Christoph Bumiller SB_DATA (so, fui(cso->offset_units * 2.0f)); 2424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 2434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 2444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller assert(so->size < (sizeof(so->state) / sizeof(so->state[0]))); 2454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller return (void *)so; 2464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 2474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 2484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 2494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_rasterizer_state_bind(struct pipe_context *pipe, void *hwcso) 2504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 2514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct nvc0_context *nvc0 = nvc0_context(pipe); 2524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 2534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0->rast = hwcso; 2544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0->dirty |= NVC0_NEW_RASTERIZER; 2554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 2564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 2574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 2584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_rasterizer_state_delete(struct pipe_context *pipe, void *hwcso) 2594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 2604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller FREE(hwcso); 2614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 2624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 2634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void * 2644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_zsa_state_create(struct pipe_context *pipe, 2654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller const struct pipe_depth_stencil_alpha_state *cso) 2664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 2674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct nvc0_zsa_stateobj *so = CALLOC_STRUCT(nvc0_zsa_stateobj); 2684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 2694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->pipe = *cso; 2704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 2712c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller SB_IMMED_3D(so, DEPTH_WRITE_ENABLE, cso->depth.writemask); 2724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, DEPTH_TEST_ENABLE, 1); 2734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (cso->depth.enabled) { 2744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, 1); 2754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, DEPTH_TEST_FUNC, 1); 2764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvgl_comparison_op(cso->depth.func)); 2774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } else { 2784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, 0); 2794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 2804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 2814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (cso->stencil[0].enabled) { 282293a8d1b600cd5bd89b3c4c0b6c2bb245d9bd80fChristoph Bumiller SB_BEGIN_3D(so, STENCIL_ENABLE, 5); 2834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, 1); 2844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvgl_stencil_op(cso->stencil[0].fail_op)); 2854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvgl_stencil_op(cso->stencil[0].zfail_op)); 2864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvgl_stencil_op(cso->stencil[0].zpass_op)); 2874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvgl_comparison_op(cso->stencil[0].func)); 288293a8d1b600cd5bd89b3c4c0b6c2bb245d9bd80fChristoph Bumiller SB_BEGIN_3D(so, STENCIL_FRONT_FUNC_MASK, 2); 2894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, cso->stencil[0].valuemask); 290293a8d1b600cd5bd89b3c4c0b6c2bb245d9bd80fChristoph Bumiller SB_DATA (so, cso->stencil[0].writemask); 2914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } else { 292293a8d1b600cd5bd89b3c4c0b6c2bb245d9bd80fChristoph Bumiller SB_IMMED_3D(so, STENCIL_ENABLE, 0); 2934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 2944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 2954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (cso->stencil[1].enabled) { 296293a8d1b600cd5bd89b3c4c0b6c2bb245d9bd80fChristoph Bumiller assert(cso->stencil[0].enabled); 2974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, STENCIL_TWO_SIDE_ENABLE, 5); 2984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, 1); 2994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvgl_stencil_op(cso->stencil[1].fail_op)); 3004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvgl_stencil_op(cso->stencil[1].zfail_op)); 3014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvgl_stencil_op(cso->stencil[1].zpass_op)); 3024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvgl_comparison_op(cso->stencil[1].func)); 3034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, STENCIL_BACK_MASK, 2); 3044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, cso->stencil[1].writemask); 3054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, cso->stencil[1].valuemask); 306293a8d1b600cd5bd89b3c4c0b6c2bb245d9bd80fChristoph Bumiller } else 307293a8d1b600cd5bd89b3c4c0b6c2bb245d9bd80fChristoph Bumiller if (cso->stencil[0].enabled) { 3082c20aae23393a3f6899f1775df47697ce65fc6caChristoph Bumiller SB_IMMED_3D(so, STENCIL_TWO_SIDE_ENABLE, 0); 3094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 3104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 3114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, ALPHA_TEST_ENABLE, 1); 3124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (cso->alpha.enabled) { 3134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, 1); 3144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_BEGIN_3D(so, ALPHA_TEST_REF, 2); 3154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, fui(cso->alpha.ref_value)); 3164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, nvgl_comparison_op(cso->alpha.func)); 3174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } else { 3184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller SB_DATA (so, 0); 3194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 3204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 3214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller assert(so->size < (sizeof(so->state) / sizeof(so->state[0]))); 3224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller return (void *)so; 3234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 3244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 3254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 3264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_zsa_state_bind(struct pipe_context *pipe, void *hwcso) 3274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 3284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct nvc0_context *nvc0 = nvc0_context(pipe); 3294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 3304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0->zsa = hwcso; 3314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0->dirty |= NVC0_NEW_ZSA; 3324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 3334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 3344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 3354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_zsa_state_delete(struct pipe_context *pipe, void *hwcso) 3364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 3374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller FREE(hwcso); 3384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 3394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 3404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller/* ====================== SAMPLERS AND TEXTURES ================================ 3414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller */ 3424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 3434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#define NV50_TSC_WRAP_CASE(n) \ 3444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller case PIPE_TEX_WRAP_##n: return NV50_TSC_WRAP_##n 3454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 3464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic INLINE unsigned 3474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernv50_tsc_wrap_mode(unsigned wrap) 3484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 3494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller switch (wrap) { 3504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller NV50_TSC_WRAP_CASE(REPEAT); 3514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller NV50_TSC_WRAP_CASE(MIRROR_REPEAT); 3524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller NV50_TSC_WRAP_CASE(CLAMP_TO_EDGE); 3534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller NV50_TSC_WRAP_CASE(CLAMP_TO_BORDER); 3544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller NV50_TSC_WRAP_CASE(CLAMP); 3554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller NV50_TSC_WRAP_CASE(MIRROR_CLAMP_TO_EDGE); 3564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller NV50_TSC_WRAP_CASE(MIRROR_CLAMP_TO_BORDER); 3574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller NV50_TSC_WRAP_CASE(MIRROR_CLAMP); 3584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller default: 3594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller NOUVEAU_ERR("unknown wrap mode: %d\n", wrap); 3604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller return NV50_TSC_WRAP_REPEAT; 3614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 3624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 3634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 3644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void * 3654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_sampler_state_create(struct pipe_context *pipe, 3664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller const struct pipe_sampler_state *cso) 3674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 3684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct nvc0_tsc_entry *so = CALLOC_STRUCT(nvc0_tsc_entry); 3694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller float f[2]; 3704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 3714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->id = -1; 3724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 3734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->tsc[0] = (0x00026000 | 3744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller (nv50_tsc_wrap_mode(cso->wrap_s) << 0) | 3754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller (nv50_tsc_wrap_mode(cso->wrap_t) << 3) | 3764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller (nv50_tsc_wrap_mode(cso->wrap_r) << 6)); 3774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 3784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller switch (cso->mag_img_filter) { 3794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller case PIPE_TEX_FILTER_LINEAR: 3804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->tsc[1] |= NV50_TSC_1_MAGF_LINEAR; 3814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller break; 3824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller case PIPE_TEX_FILTER_NEAREST: 3834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller default: 3844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->tsc[1] |= NV50_TSC_1_MAGF_NEAREST; 3854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller break; 3864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 3874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 3884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller switch (cso->min_img_filter) { 3894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller case PIPE_TEX_FILTER_LINEAR: 3904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->tsc[1] |= NV50_TSC_1_MINF_LINEAR; 3914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller break; 3924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller case PIPE_TEX_FILTER_NEAREST: 3934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller default: 3944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->tsc[1] |= NV50_TSC_1_MINF_NEAREST; 3954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller break; 3964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 3974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 3984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller switch (cso->min_mip_filter) { 3994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller case PIPE_TEX_MIPFILTER_LINEAR: 4004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->tsc[1] |= NV50_TSC_1_MIPF_LINEAR; 4014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller break; 4024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller case PIPE_TEX_MIPFILTER_NEAREST: 4034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->tsc[1] |= NV50_TSC_1_MIPF_NEAREST; 4044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller break; 4054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller case PIPE_TEX_MIPFILTER_NONE: 4064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller default: 4074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->tsc[1] |= NV50_TSC_1_MIPF_NONE; 4084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller break; 4094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 4104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (cso->max_anisotropy >= 16) 4124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->tsc[0] |= (7 << 20); 4134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller else 4144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (cso->max_anisotropy >= 12) 4154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->tsc[0] |= (6 << 20); 4164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller else { 4174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->tsc[0] |= (cso->max_anisotropy >> 1) << 20; 4184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (cso->max_anisotropy >= 4) 4204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->tsc[1] |= NV50_TSC_1_UNKN_ANISO_35; 4214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller else 4224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (cso->max_anisotropy >= 2) 4234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->tsc[1] |= NV50_TSC_1_UNKN_ANISO_15; 4244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 4254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (cso->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) { 4274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller /* NOTE: must be deactivated for non-shadow textures */ 4284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->tsc[0] |= (1 << 9); 4294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->tsc[0] |= (nvgl_comparison_op(cso->compare_func) & 0x7) << 10; 4304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 4314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller f[0] = CLAMP(cso->lod_bias, -16.0f, 15.0f); 4334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->tsc[1] |= ((int)(f[0] * 256.0f) & 0x1fff) << 12; 4344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller f[0] = CLAMP(cso->min_lod, 0.0f, 15.0f); 4364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller f[1] = CLAMP(cso->max_lod, 0.0f, 15.0f); 4374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->tsc[2] |= 4384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller (((int)(f[1] * 256.0f) & 0xfff) << 12) | ((int)(f[0] * 256.0f) & 0xfff); 4394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->tsc[4] = fui(cso->border_color[0]); 4414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->tsc[5] = fui(cso->border_color[1]); 4424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->tsc[6] = fui(cso->border_color[2]); 4434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller so->tsc[7] = fui(cso->border_color[3]); 4444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller return (void *)so; 4464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 4474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 4494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_sampler_state_delete(struct pipe_context *pipe, void *hwcso) 4504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 4514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller unsigned s, i; 4524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller for (s = 0; s < 5; ++s) 4544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller for (i = 0; i < nvc0_context(pipe)->num_samplers[s]; ++i) 4554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (nvc0_context(pipe)->samplers[s][i] == hwcso) 4564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0_context(pipe)->samplers[s][i] = NULL; 4574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0_screen_tsc_free(nvc0_context(pipe)->screen, nvc0_tsc_entry(hwcso)); 4594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller FREE(hwcso); 4614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 4624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic INLINE void 4644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_stage_sampler_states_bind(struct nvc0_context *nvc0, int s, 4654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller unsigned nr, void **hwcso) 4664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 4674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller unsigned i; 4684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller for (i = 0; i < nr; ++i) { 4704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct nvc0_tsc_entry *old = nvc0->samplers[s][i]; 4714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0->samplers[s][i] = nvc0_tsc_entry(hwcso[i]); 4734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (old) 4744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0_screen_tsc_unlock(nvc0->screen, old); 4754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 4764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller for (; i < nvc0->num_samplers[s]; ++i) 4774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (nvc0->samplers[s][i]) 4784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0_screen_tsc_unlock(nvc0->screen, nvc0->samplers[s][i]); 4794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0->num_samplers[s] = nr; 4814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0->dirty |= NVC0_NEW_SAMPLERS; 4834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 4844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 4864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_vp_sampler_states_bind(struct pipe_context *pipe, unsigned nr, void **s) 4874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 4884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0_stage_sampler_states_bind(nvc0_context(pipe), 0, nr, s); 4894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 4904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 4924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_fp_sampler_states_bind(struct pipe_context *pipe, unsigned nr, void **s) 4934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 4944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0_stage_sampler_states_bind(nvc0_context(pipe), 4, nr, s); 4954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 4964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 4984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_gp_sampler_states_bind(struct pipe_context *pipe, unsigned nr, void **s) 4994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 5004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0_stage_sampler_states_bind(nvc0_context(pipe), 3, nr, s); 5014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 5024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 5034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller/* NOTE: only called when not referenced anywhere, won't be bound */ 5044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 5054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_sampler_view_destroy(struct pipe_context *pipe, 5064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct pipe_sampler_view *view) 5074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 5084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller pipe_resource_reference(&view->texture, NULL); 5094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 5104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0_screen_tic_free(nvc0_context(pipe)->screen, nvc0_tic_entry(view)); 5114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 5124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller FREE(nvc0_tic_entry(view)); 5134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 5144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 5154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic INLINE void 5164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_stage_set_sampler_views(struct nvc0_context *nvc0, int s, 5174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller unsigned nr, 5184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct pipe_sampler_view **views) 5194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 5204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller unsigned i; 5214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 5224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller for (i = 0; i < nr; ++i) { 5234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct nvc0_tic_entry *old = nvc0_tic_entry(nvc0->textures[s][i]); 5244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (old) 5254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0_screen_tic_unlock(nvc0->screen, old); 5264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 5274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller pipe_sampler_view_reference(&nvc0->textures[s][i], views[i]); 5284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 5294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 5304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller for (i = nr; i < nvc0->num_textures[s]; ++i) { 5314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct nvc0_tic_entry *old = nvc0_tic_entry(nvc0->textures[s][i]); 5324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (!old) 5334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller continue; 5344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0_screen_tic_unlock(nvc0->screen, old); 5354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 5364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller pipe_sampler_view_reference(&nvc0->textures[s][i], NULL); 5374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 5384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 5394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0->num_textures[s] = nr; 5404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 541e4349027f6842563555992a39add4d0b2283fbbbChristoph Bumiller nvc0_bufctx_reset(nvc0, NVC0_BUFCTX_TEXTURES); 542e4349027f6842563555992a39add4d0b2283fbbbChristoph Bumiller 5434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0->dirty |= NVC0_NEW_TEXTURES; 5444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 5454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 5464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 5474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_vp_set_sampler_views(struct pipe_context *pipe, 5484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller unsigned nr, 5494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct pipe_sampler_view **views) 5504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 5514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0_stage_set_sampler_views(nvc0_context(pipe), 0, nr, views); 5524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 5534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 5544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 5554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_fp_set_sampler_views(struct pipe_context *pipe, 5564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller unsigned nr, 5574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct pipe_sampler_view **views) 5584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 5594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0_stage_set_sampler_views(nvc0_context(pipe), 4, nr, views); 5604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 5614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 5624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 5634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_gp_set_sampler_views(struct pipe_context *pipe, 5644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller unsigned nr, 5654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct pipe_sampler_view **views) 5664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 5674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0_stage_set_sampler_views(nvc0_context(pipe), 3, nr, views); 5684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 5694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 5704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller/* ============================= SHADERS ======================================= 5714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller */ 5724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 5734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void * 5744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_sp_state_create(struct pipe_context *pipe, 5754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller const struct pipe_shader_state *cso, unsigned type) 5764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 5774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct nvc0_program *prog; 5784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 5794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller prog = CALLOC_STRUCT(nvc0_program); 5804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (!prog) 5814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller return NULL; 5824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 5834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller prog->type = type; 5844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller prog->pipe.tokens = tgsi_dup_tokens(cso->tokens); 5854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 5864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller return (void *)prog; 5874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 5884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 5894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 5904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_sp_state_delete(struct pipe_context *pipe, void *hwcso) 5914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 5924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct nvc0_program *prog = (struct nvc0_program *)hwcso; 5934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 5944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0_program_destroy(nvc0_context(pipe), prog); 5954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 5964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller FREE((void *)prog->pipe.tokens); 5974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller FREE(prog); 5984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 5994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 6004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void * 6014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_vp_state_create(struct pipe_context *pipe, 6024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller const struct pipe_shader_state *cso) 6034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 6044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller return nvc0_sp_state_create(pipe, cso, PIPE_SHADER_VERTEX); 6054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 6064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 6074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 6084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_vp_state_bind(struct pipe_context *pipe, void *hwcso) 6094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 6104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct nvc0_context *nvc0 = nvc0_context(pipe); 6114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 6124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0->vertprog = hwcso; 6134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0->dirty |= NVC0_NEW_VERTPROG; 6144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 6154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 6164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void * 6174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_fp_state_create(struct pipe_context *pipe, 6184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller const struct pipe_shader_state *cso) 6194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 6204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller return nvc0_sp_state_create(pipe, cso, PIPE_SHADER_FRAGMENT); 6214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 6224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 6234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 6244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_fp_state_bind(struct pipe_context *pipe, void *hwcso) 6254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 6264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct nvc0_context *nvc0 = nvc0_context(pipe); 6274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 6284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0->fragprog = hwcso; 6294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0->dirty |= NVC0_NEW_FRAGPROG; 6304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 6314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 6324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void * 6334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_gp_state_create(struct pipe_context *pipe, 6344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller const struct pipe_shader_state *cso) 6354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 6364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller return nvc0_sp_state_create(pipe, cso, PIPE_SHADER_GEOMETRY); 6374c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 6384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 6394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 6404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_gp_state_bind(struct pipe_context *pipe, void *hwcso) 6414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 6424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct nvc0_context *nvc0 = nvc0_context(pipe); 6434c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 6444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0->gmtyprog = hwcso; 6454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0->dirty |= NVC0_NEW_GMTYPROG; 6464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 6474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 6484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 6494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index, 6504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct pipe_resource *res) 6514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 6524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct nvc0_context *nvc0 = nvc0_context(pipe); 6534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 6544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller switch (shader) { 6554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller case PIPE_SHADER_VERTEX: shader = 0; break; 6564c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller /* 6574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller case PIPE_SHADER_TESSELLATION_CONTROL: shader = 1; break; 6584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller case PIPE_SHADER_TESSELLATION_EVALUATION: shader = 2; break; 6594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller */ 6604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller case PIPE_SHADER_GEOMETRY: shader = 3; break; 6614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller case PIPE_SHADER_FRAGMENT: shader = 4; break; 6624c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller default: 6634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller assert(0); 6644c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller break; 6654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 6664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 6674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (nvc0->constbuf[shader][index]) 6684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0_bufctx_del_resident(nvc0, NVC0_BUFCTX_CONSTANT, 6694826cd0f6125b071530026143ffd8205d84b3d5eBen Skeggs nv04_resource(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); 7720cb6d1a4eb2dd682b499f54a82505bc3bd318bbcChristoph Bumiller unsigned i; 7730cb6d1a4eb2dd682b499f54a82505bc3bd318bbcChristoph Bumiller 7740cb6d1a4eb2dd682b499f54a82505bc3bd318bbcChristoph Bumiller for (i = 0; i < count; ++i) 7750cb6d1a4eb2dd682b499f54a82505bc3bd318bbcChristoph Bumiller pipe_resource_reference(&nvc0->vtxbuf[i].buffer, vb[i].buffer); 7760cb6d1a4eb2dd682b499f54a82505bc3bd318bbcChristoph Bumiller for (; i < nvc0->num_vtxbufs; ++i) 7770cb6d1a4eb2dd682b499f54a82505bc3bd318bbcChristoph Bumiller pipe_resource_reference(&nvc0->vtxbuf[i].buffer, NULL); 7784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 7794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller memcpy(nvc0->vtxbuf, vb, sizeof(*vb) * count); 7804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0->num_vtxbufs = count; 7814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 782e4349027f6842563555992a39add4d0b2283fbbbChristoph Bumiller nvc0_bufctx_reset(nvc0, NVC0_BUFCTX_VERTEX); 783e4349027f6842563555992a39add4d0b2283fbbbChristoph Bumiller 7844c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0->dirty |= NVC0_NEW_ARRAYS; 7854c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 7864c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 7874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 7884c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_set_index_buffer(struct pipe_context *pipe, 7894c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller const struct pipe_index_buffer *ib) 7904c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 7914c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct nvc0_context *nvc0 = nvc0_context(pipe); 7924c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 7934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (ib) 7944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller memcpy(&nvc0->idxbuf, ib, sizeof(nvc0->idxbuf)); 7954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller else 7964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0->idxbuf.buffer = NULL; 7974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 7984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 7994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 8004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_vertex_state_bind(struct pipe_context *pipe, void *hwcso) 8014c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 8024c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct nvc0_context *nvc0 = nvc0_context(pipe); 8034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 8044c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0->vertex = hwcso; 8054c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller nvc0->dirty |= NVC0_NEW_VERTEX; 8064c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 8074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 808f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillerstatic void * 809f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillernvc0_tfb_state_create(struct pipe_context *pipe, 810f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller const struct pipe_stream_output_state *pso) 811f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller{ 812f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller struct nvc0_transform_feedback_state *so; 813f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller int n = 0; 814f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller int i, c, b; 815f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller 816f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller so = MALLOC(sizeof(*so) + pso->num_outputs * 4 * sizeof(uint8_t)); 817f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller if (!so) 818f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller return NULL; 819f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller 820f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller for (b = 0; b < 4; ++b) { 821f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller for (i = 0; i < pso->num_outputs; ++i) { 822f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller if (pso->output_buffer[i] != b) 823f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller continue; 824f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller for (c = 0; c < 4; ++c) { 825f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller if (!(pso->register_mask[i] & (1 << c))) 826f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller continue; 827f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller so->varying_count[b]++; 828f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller so->varying_index[n++] = (pso->register_index[i] << 2) | c; 829f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller } 830f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller } 831f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller so->stride[b] = so->varying_count[b] * 4; 832f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller } 833f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller if (pso->stride) 834f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller so->stride[0] = pso->stride; 835f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller 836f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller return so; 837f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller} 838f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller 839f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillerstatic void 840f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillernvc0_tfb_state_delete(struct pipe_context *pipe, void *hwcso) 841f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller{ 842f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller FREE(hwcso); 843f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller} 844f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller 845f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillerstatic void 846f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillernvc0_tfb_state_bind(struct pipe_context *pipe, void *hwcso) 847f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller{ 848f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller nvc0_context(pipe)->tfb = hwcso; 849f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller nvc0_context(pipe)->dirty |= NVC0_NEW_TFB; 850f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller} 851f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller 852f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillerstatic void 853f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumillernvc0_set_transform_feedback_buffers(struct pipe_context *pipe, 854f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller struct pipe_resource **buffers, 855f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller int *offsets, 856f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller int num_buffers) 857f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller{ 858f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller struct nvc0_context *nvc0 = nvc0_context(pipe); 859f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller int i; 860f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller 861f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller assert(num_buffers >= 0 && num_buffers <= 4); /* why signed ? */ 862f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller 863f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller for (i = 0; i < num_buffers; ++i) { 864f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller assert(offsets[i] >= 0); 865f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller nvc0->tfb_offset[i] = offsets[i]; 866f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller pipe_resource_reference(&nvc0->tfbbuf[i], buffers[i]); 867f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller } 868f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller for (; i < nvc0->num_tfbbufs; ++i) 869f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller pipe_resource_reference(&nvc0->tfbbuf[i], NULL); 870f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller 871f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller nvc0->num_tfbbufs = num_buffers; 872f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller 873f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller nvc0->dirty |= NVC0_NEW_TFB_BUFFERS; 874f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller} 875f8a7a0b6f30ff38b2743860cbc4caeab102c2c29Christoph Bumiller 8764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillervoid 8774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_init_state_functions(struct nvc0_context *nvc0) 8784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 8791ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs struct pipe_context *pipe = &nvc0->base.pipe; 8801ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs 8811ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->create_blend_state = nvc0_blend_state_create; 8821ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->bind_blend_state = nvc0_blend_state_bind; 8831ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->delete_blend_state = nvc0_blend_state_delete; 8841ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs 8851ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->create_rasterizer_state = nvc0_rasterizer_state_create; 8861ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->bind_rasterizer_state = nvc0_rasterizer_state_bind; 8871ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->delete_rasterizer_state = nvc0_rasterizer_state_delete; 8881ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs 8891ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->create_depth_stencil_alpha_state = nvc0_zsa_state_create; 8901ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->bind_depth_stencil_alpha_state = nvc0_zsa_state_bind; 8911ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->delete_depth_stencil_alpha_state = nvc0_zsa_state_delete; 8921ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs 8931ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->create_sampler_state = nvc0_sampler_state_create; 8941ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->delete_sampler_state = nvc0_sampler_state_delete; 8951ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->bind_vertex_sampler_states = nvc0_vp_sampler_states_bind; 8961ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->bind_fragment_sampler_states = nvc0_fp_sampler_states_bind; 8971ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->bind_geometry_sampler_states = nvc0_gp_sampler_states_bind; 8981ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs 8991ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->create_sampler_view = nvc0_create_sampler_view; 9001ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->sampler_view_destroy = nvc0_sampler_view_destroy; 9011ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->set_vertex_sampler_views = nvc0_vp_set_sampler_views; 9021ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->set_fragment_sampler_views = nvc0_fp_set_sampler_views; 9031ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->set_geometry_sampler_views = nvc0_gp_set_sampler_views; 9041ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs 9051ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->create_vs_state = nvc0_vp_state_create; 9061ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->create_fs_state = nvc0_fp_state_create; 9071ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->create_gs_state = nvc0_gp_state_create; 9081ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->bind_vs_state = nvc0_vp_state_bind; 9091ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->bind_fs_state = nvc0_fp_state_bind; 9101ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->bind_gs_state = nvc0_gp_state_bind; 9111ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->delete_vs_state = nvc0_sp_state_delete; 9121ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->delete_fs_state = nvc0_sp_state_delete; 9131ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->delete_gs_state = nvc0_sp_state_delete; 9141ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs 9151ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->set_blend_color = nvc0_set_blend_color; 9161ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->set_stencil_ref = nvc0_set_stencil_ref; 9171ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->set_clip_state = nvc0_set_clip_state; 9181ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->set_sample_mask = nvc0_set_sample_mask; 9191ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->set_constant_buffer = nvc0_set_constant_buffer; 9201ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->set_framebuffer_state = nvc0_set_framebuffer_state; 9211ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->set_polygon_stipple = nvc0_set_polygon_stipple; 9221ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->set_scissor_state = nvc0_set_scissor_state; 9231ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->set_viewport_state = nvc0_set_viewport_state; 9241ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs 9251ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->create_vertex_elements_state = nvc0_vertex_state_create; 9261ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->delete_vertex_elements_state = nvc0_vertex_state_delete; 9271ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->bind_vertex_elements_state = nvc0_vertex_state_bind; 9281ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs 9291ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->set_vertex_buffers = nvc0_set_vertex_buffers; 9301ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->set_index_buffer = nvc0_set_index_buffer; 9311ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs 9321ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->create_stream_output_state = nvc0_tfb_state_create; 9331ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->delete_stream_output_state = nvc0_tfb_state_delete; 9341ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->bind_stream_output_state = nvc0_tfb_state_bind; 9351ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->set_stream_output_buffers = nvc0_set_transform_feedback_buffers; 9361ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs 9371ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->redefine_user_buffer = u_default_redefine_user_buffer; 9384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 9394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 940