1857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs/* 2d2d19ea51fa3575a8d014a69a9b835c335728817Christoph Bumiller * Copyright 2010 Christoph Bumiller 3857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * 4857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a 5857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * copy of this software and associated documentation files (the "Software"), 6857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * to deal in the Software without restriction, including without limitation 7857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the 9857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * Software is furnished to do so, subject to the following conditions: 10857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * 11857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * The above copyright notice and this permission notice shall be included in 12857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * all copies or substantial portions of the Software. 13857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * 14857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 18857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 19857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * SOFTWARE. 21857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs */ 22857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs 23633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller#include "nv50_program.h" 24633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller#include "nv50_context.h" 25f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs 263afabfb929cf24a783c10c99bf0d86245e70a94aChristoph Bumiller#include "codegen/nv50_ir_driver.h" 273afabfb929cf24a783c10c99bf0d86245e70a94aChristoph Bumiller 286516594c8eec1088ee59e7c3254b2fdced2ff04bChristoph Bumillerstatic INLINE unsigned 29633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillerbitcount4(const uint32_t val) 30170cdb4507683fb9042620f7ab2ad96e57787d6cChristoph Bumiller{ 310bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller static const uint8_t cnt[16] 32633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; 33633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller return cnt[val & 0xf]; 34170cdb4507683fb9042620f7ab2ad96e57787d6cChristoph Bumiller} 35170cdb4507683fb9042620f7ab2ad96e57787d6cChristoph Bumiller 360bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumillerstatic int 370bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumillernv50_vertprog_assign_slots(struct nv50_ir_prog_info *info) 38633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller{ 390bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller struct nv50_program *prog = (struct nv50_program *)info->driverPriv; 400bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller unsigned i, n, c; 41633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller 420bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller n = 0; 430bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller for (i = 0; i < info->numInputs; ++i) { 440bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->in[i].id = i; 450bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->in[i].sn = info->in[i].sn; 460bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->in[i].si = info->in[i].si; 470bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->in[i].hw = n; 480bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->in[i].mask = info->in[i].mask; 49633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller 500bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->vp.attrs[(4 * i) / 32] |= info->in[i].mask << ((4 * i) % 32); 51633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller 52633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller for (c = 0; c < 4; ++c) 530bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller if (info->in[i].mask & (1 << c)) 540bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller info->in[i].slot[c] = n++; 55d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller } 560bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->in_nr = info->numInputs; 57d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller 580bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller for (i = 0; i < info->numSysVals; ++i) { 590bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller switch (info->sv[i].sn) { 600bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller case TGSI_SEMANTIC_INSTANCEID: 610bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->vp.attrs[2] |= NV50_3D_VP_GP_BUILTIN_ATTR_EN_INSTANCE_ID; 62633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller continue; 630bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller case TGSI_SEMANTIC_VERTEXID: 640bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->vp.attrs[2] |= NV50_3D_VP_GP_BUILTIN_ATTR_EN_VERTEX_ID; 650bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->vp.attrs[2] |= NV50_3D_VP_GP_BUILTIN_ATTR_EN_UNK12; 66d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller continue; 67633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller default: 68633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller break; 69633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller } 700bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller } 71ecc7e5e85b65bf7c87e31126f893065d4466246aMarcin Slusarz 72ecc7e5e85b65bf7c87e31126f893065d4466246aMarcin Slusarz /* 73ecc7e5e85b65bf7c87e31126f893065d4466246aMarcin Slusarz * Corner case: VP has no inputs, but we will still need to submit data to 74ecc7e5e85b65bf7c87e31126f893065d4466246aMarcin Slusarz * draw it. HW will shout at us and won't draw anything if we don't enable 75ecc7e5e85b65bf7c87e31126f893065d4466246aMarcin Slusarz * any input, so let's just pretend it's the first one. 76ecc7e5e85b65bf7c87e31126f893065d4466246aMarcin Slusarz */ 77ecc7e5e85b65bf7c87e31126f893065d4466246aMarcin Slusarz if (prog->vp.attrs[0] == 0 && 78ecc7e5e85b65bf7c87e31126f893065d4466246aMarcin Slusarz prog->vp.attrs[1] == 0 && 79ecc7e5e85b65bf7c87e31126f893065d4466246aMarcin Slusarz prog->vp.attrs[2] == 0) 80ecc7e5e85b65bf7c87e31126f893065d4466246aMarcin Slusarz prog->vp.attrs[0] |= 0xf; 81ecc7e5e85b65bf7c87e31126f893065d4466246aMarcin Slusarz 820bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller /* VertexID before InstanceID */ 830bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller if (info->io.vertexId < info->numSysVals) 840bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller info->sv[info->io.vertexId].slot[0] = n++; 850bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller if (info->io.instanceId < info->numSysVals) 860bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller info->sv[info->io.instanceId].slot[0] = n++; 870bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller 880bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller n = 0; 890bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller for (i = 0; i < info->numOutputs; ++i) { 900bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller switch (info->out[i].sn) { 910bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller case TGSI_SEMANTIC_PSIZE: 920bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->vp.psiz = i; 93633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller break; 940bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller case TGSI_SEMANTIC_CLIPDIST: 950bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->vp.clpd[info->out[i].si] = n; 96633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller break; 970bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller case TGSI_SEMANTIC_EDGEFLAG: 980bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->vp.edgeflag = i; 99633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller break; 1000bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller case TGSI_SEMANTIC_BCOLOR: 1010bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->vp.bfc[info->out[i].si] = i; 102633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller break; 103633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller default: 104633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller break; 105633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller } 1060bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->out[i].id = i; 1070bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->out[i].sn = info->out[i].sn; 1080bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->out[i].si = info->out[i].si; 1090bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->out[i].hw = n; 1100bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->out[i].mask = info->out[i].mask; 111116133af3499947500a6d0c877fbc8f564ee4c76Maxim Levitsky 1120bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller for (c = 0; c < 4; ++c) 1130bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller if (info->out[i].mask & (1 << c)) 1140bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller info->out[i].slot[c] = n++; 115533bf171d4c926e4ab6fcd0d51396b195b9e024fChristoph Bumiller } 1160bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->out_nr = info->numOutputs; 1170bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->max_out = n; 118533bf171d4c926e4ab6fcd0d51396b195b9e024fChristoph Bumiller 1190bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller if (prog->vp.psiz < info->numOutputs) 1200bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->vp.psiz = prog->out[prog->vp.psiz].hw; 121d4d880199ead954e79cad141f7a29f7dd17fe7fcPatrice Mandin 122633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller return 0; 1232a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs} 1242a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs 12533e4d30d50344be26398a51365bea1be37487403Ben Skeggsstatic int 1260bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumillernv50_fragprog_assign_slots(struct nv50_ir_prog_info *info) 127633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller{ 1280bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller struct nv50_program *prog = (struct nv50_program *)info->driverPriv; 1290bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller unsigned i, n, m, c; 1300bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller unsigned nvary; 1310bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller unsigned nflat; 1320bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller unsigned nintp = 0; 1330bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller 1340bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller /* count recorded non-flat inputs */ 1350bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller for (m = 0, i = 0; i < info->numInputs; ++i) { 1360bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller switch (info->in[i].sn) { 1370bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller case TGSI_SEMANTIC_POSITION: 1380bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller case TGSI_SEMANTIC_FACE: 1390bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller continue; 1400bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller default: 1410bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller m += info->in[i].flat ? 0 : 1; 1420bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller break; 1430bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller } 144633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller } 1450bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller /* careful: id may be != i in info->in[prog->in[i].id] */ 146633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller 1470bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller /* Fill prog->in[] so that non-flat inputs are first and 1480bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller * kick out special inputs that don't use the RESULT_MAP. 149633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller */ 1500bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller for (n = 0, i = 0; i < info->numInputs; ++i) { 1510bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller if (info->in[i].sn == TGSI_SEMANTIC_POSITION) { 1520bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->fp.interp |= info->in[i].mask << 24; 1530bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller for (c = 0; c < 4; ++c) 1540bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller if (info->in[i].mask & (1 << c)) 1550bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller info->in[i].slot[c] = nintp++; 156633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller } else 1570bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller if (info->in[i].sn == TGSI_SEMANTIC_FACE) { 1580bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller info->in[i].slot[0] = 255; 1590bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller } else { 1600bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller unsigned j = info->in[i].flat ? m++ : n++; 161633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller 1620bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller if (info->in[i].sn == TGSI_SEMANTIC_COLOR) 1630bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->vp.bfc[info->in[i].si] = j; 164633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller 1650bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->in[j].id = i; 1660bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->in[j].mask = info->in[i].mask; 1670bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->in[j].sn = info->in[i].sn; 1680bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->in[j].si = info->in[i].si; 1690bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->in[j].linear = info->in[i].linear; 170633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller 1710bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->in_nr++; 1720bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller } 1730bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller } 1740bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller if (!(prog->fp.interp & (8 << 24))) { 175633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller ++nintp; 1760bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->fp.interp |= 8 << 24; 177633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller } 178633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller 1790bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller for (i = 0; i < prog->in_nr; ++i) { 1800bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller int j = prog->in[i].id; 181633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller 1820bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->in[i].hw = nintp; 1830bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller for (c = 0; c < 4; ++c) 18429a0c8cd60b6e1fc9ad39e626852ce598fe4d2b4Christoph Bumiller if (prog->in[i].mask & (1 << c)) 1850bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller info->in[j].slot[c] = nintp++; 186633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller } 1870bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller /* (n == m) if m never increased, i.e. no flat inputs */ 1880bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller nflat = (n < m) ? (nintp - prog->in[n].hw) : 0; 1890bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller nintp -= bitcount4(prog->fp.interp >> 24); /* subtract position inputs */ 1900bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller nvary = nintp - nflat; 1910bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller 1920bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->fp.interp |= nvary << NV50_3D_FP_INTERPOLANT_CTRL_COUNT_NONFLAT__SHIFT; 1930bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->fp.interp |= nintp << NV50_3D_FP_INTERPOLANT_CTRL_COUNT__SHIFT; 194633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller 1950bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller /* put front/back colors right after HPOS */ 1960bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->fp.colors = 4 << NV50_3D_SEMANTIC_COLOR_FFC0_ID__SHIFT; 1970bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller for (i = 0; i < 2; ++i) 198e55c276255db9cba0a3b6780913a1e924cb6ff6bChristoph Bumiller if (prog->vp.bfc[i] < 0xff) 1990bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->fp.colors += bitcount4(prog->in[prog->vp.bfc[i]].mask) << 16; 200633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller 201633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller /* FP outputs */ 202633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller 2030bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller if (info->prop.fp.numColourResults > 1) 2040bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->fp.flags[0] |= NV50_3D_FP_CONTROL_MULTIPLE_RESULTS; 205633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller 2060bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller for (i = 0; i < info->numOutputs; ++i) { 2070bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->out[i].id = i; 2080bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->out[i].sn = info->out[i].sn; 2090bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->out[i].si = info->out[i].si; 2100bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->out[i].mask = info->out[i].mask; 2110bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller 2120bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller if (i == info->io.fragDepth || i == info->io.sampleMask) 213633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller continue; 2140bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->out[i].hw = info->out[i].si * 4; 215633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller 216633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller for (c = 0; c < 4; ++c) 2170bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller info->out[i].slot[c] = prog->out[i].hw + c; 2180bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller 2190bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->max_out = MAX2(prog->max_out, prog->out[i].hw + 4); 220633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller } 221633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller 2220bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller if (info->io.sampleMask < PIPE_MAX_SHADER_OUTPUTS) 2230bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller info->out[info->io.sampleMask].slot[0] = prog->max_out++; 2240bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller 2250bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller if (info->io.fragDepth < PIPE_MAX_SHADER_OUTPUTS) 2260bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller info->out[info->io.fragDepth].slot[2] = prog->max_out++; 2270bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller 2280bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller if (!prog->max_out) 2290bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->max_out = 4; 2300bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller 231633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller return 0; 23255b2fe1047b37d0d86641a252e1c745111030393Ben Skeggs} 23355b2fe1047b37d0d86641a252e1c745111030393Ben Skeggs 234633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillerstatic int 2350bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumillernv50_program_assign_varying_slots(struct nv50_ir_prog_info *info) 23644d8c9add2f095fc365ede751253d9fb7fc5c6e1Christoph Bumiller{ 2370bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller switch (info->type) { 2380bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller case PIPE_SHADER_VERTEX: 2390bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller return nv50_vertprog_assign_slots(info); 2400bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller case PIPE_SHADER_GEOMETRY: 2410bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller return nv50_vertprog_assign_slots(info); 2420bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller case PIPE_SHADER_FRAGMENT: 2430bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller return nv50_fragprog_assign_slots(info); 2440bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller default: 2450bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller return -1; 2460bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller } 24744d8c9add2f095fc365ede751253d9fb7fc5c6e1Christoph Bumiller} 24844d8c9add2f095fc365ede751253d9fb7fc5c6e1Christoph Bumiller 24902fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumillerstatic struct nv50_stream_output_state * 25002fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumillernv50_program_create_strmout_state(const struct nv50_ir_prog_info *info, 25102fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller const struct pipe_stream_output_info *pso) 25202fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller{ 25302fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller struct nv50_stream_output_state *so; 25402fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller unsigned b, i, c; 25502fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller unsigned base[4]; 25602fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller 25702fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller so = MALLOC_STRUCT(nv50_stream_output_state); 25802fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller if (!so) 25902fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller return NULL; 26002fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller memset(so->map, 0xff, sizeof(so->map)); 26102fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller 26202fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller for (b = 0; b < 4; ++b) 26302fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller so->num_attribs[b] = 0; 26402fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller for (i = 0; i < pso->num_outputs; ++i) { 26502fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller unsigned end = pso->output[i].dst_offset + pso->output[i].num_components; 26602fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller b = pso->output[i].output_buffer; 26702fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller assert(b < 4); 26802fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller so->num_attribs[b] = MAX2(so->num_attribs[b], end); 26902fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller } 27002fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller 27102fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller so->ctrl = NV50_3D_STRMOUT_BUFFERS_CTRL_INTERLEAVED; 27202fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller 27302fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller so->stride[0] = pso->stride[0] * 4; 27402fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller base[0] = 0; 27502fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller for (b = 1; b < 4; ++b) { 27602fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller assert(!so->num_attribs[b] || so->num_attribs[b] == pso->stride[b]); 27702fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller so->stride[b] = so->num_attribs[b] * 4; 27802fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller if (so->num_attribs[b]) 27902fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller so->ctrl = (b + 1) << NV50_3D_STRMOUT_BUFFERS_CTRL_SEPARATE__SHIFT; 28002fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller base[b] = align(base[b - 1] + so->num_attribs[b - 1], 4); 28102fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller } 28202fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller if (so->ctrl & NV50_3D_STRMOUT_BUFFERS_CTRL_INTERLEAVED) { 28302fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller assert(so->stride[0] < NV50_3D_STRMOUT_BUFFERS_CTRL_STRIDE__MAX); 28402fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller so->ctrl |= so->stride[0] << NV50_3D_STRMOUT_BUFFERS_CTRL_STRIDE__SHIFT; 28502fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller } 28602fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller 28702fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller so->map_size = base[3] + so->num_attribs[3]; 28802fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller 28902fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller for (i = 0; i < pso->num_outputs; ++i) { 29002fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller const unsigned s = pso->output[i].start_component; 29102fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller const unsigned p = pso->output[i].dst_offset; 29202fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller const unsigned r = pso->output[i].register_index; 29302fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller b = pso->output[i].output_buffer; 29402fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller 29502fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller for (c = 0; c < pso->output[i].num_components; ++c) 29602fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller so->map[base[b] + p + c] = info->out[r].slot[s + c]; 29702fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller } 29802fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller 29902fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller return so; 30002fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller} 30102fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller 3020bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumillerboolean 3030bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumillernv50_program_translate(struct nv50_program *prog, uint16_t chipset) 304633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller{ 3050bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller struct nv50_ir_prog_info *info; 3060bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller int ret; 307e55c276255db9cba0a3b6780913a1e924cb6ff6bChristoph Bumiller const uint8_t map_undef = (prog->type == PIPE_SHADER_VERTEX) ? 0x40 : 0x80; 308633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller 3090bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller info = CALLOC_STRUCT(nv50_ir_prog_info); 3100bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller if (!info) 3110bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller return FALSE; 312633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller 3130bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller info->type = prog->type; 3140bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller info->target = chipset; 3150bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller info->bin.sourceRep = NV50_PROGRAM_IR_TGSI; 3160bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller info->bin.source = (void *)prog->pipe.tokens; 317d90502b2b468732e2a42985580bbbe9d9fdfd14eChristoph Bumiller 31848aec56559a0199d8099d9edff8e51312f55f15cChristoph Bumiller info->io.ucpBinding = 15; 31948aec56559a0199d8099d9edff8e51312f55f15cChristoph Bumiller info->io.ucpBase = 0; 3200bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller info->io.genUserClip = prog->vp.clpd_nr; 321d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller 3220bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller info->assignSlots = nv50_program_assign_varying_slots; 323e08f70a41d1012a0270468866614485a3415168eChristoph Bumiller 324e55c276255db9cba0a3b6780913a1e924cb6ff6bChristoph Bumiller prog->vp.bfc[0] = 0xff; 325e55c276255db9cba0a3b6780913a1e924cb6ff6bChristoph Bumiller prog->vp.bfc[1] = 0xff; 326e55c276255db9cba0a3b6780913a1e924cb6ff6bChristoph Bumiller prog->vp.edgeflag = 0xff; 327e55c276255db9cba0a3b6780913a1e924cb6ff6bChristoph Bumiller prog->vp.clpd[0] = map_undef; 328e55c276255db9cba0a3b6780913a1e924cb6ff6bChristoph Bumiller prog->vp.clpd[1] = map_undef; 329e55c276255db9cba0a3b6780913a1e924cb6ff6bChristoph Bumiller prog->vp.psiz = map_undef; 3300bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->gp.primid = 0x80; 331217542a061ef31150b1b04f1b45b6099bcc153feChristoph Bumiller 3320bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller info->driverPriv = prog; 333633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller 3340bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller#ifdef DEBUG 3350bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller info->optLevel = debug_get_num_option("NV50_PROG_OPTIMIZE", 3); 3360bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller info->dbgFlags = debug_get_num_option("NV50_PROG_DEBUG", 0); 3370bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller#else 3380bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller info->optLevel = 3; 3390bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller#endif 340633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller 3410bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller ret = nv50_ir_generate_code(info); 3420bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller if (ret) { 3430bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller NOUVEAU_ERR("shader translation failed: %i\n", ret); 3440bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller goto out; 345d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller } 346cfa7cb991ce7d2fd77ea7f5abf96c90d8a1ea68cMarcin Slusarz if (info->bin.syms) /* we don't need them yet */ 347cfa7cb991ce7d2fd77ea7f5abf96c90d8a1ea68cMarcin Slusarz FREE(info->bin.syms); 348cfa7cb991ce7d2fd77ea7f5abf96c90d8a1ea68cMarcin Slusarz 3490bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->code = info->bin.code; 3500bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->code_size = info->bin.codeSize; 3510bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->fixups = info->bin.relocData; 3520bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->max_gpr = MAX2(4, (info->bin.maxGPR >> 1) + 1); 3531906d2b46b21a8e7496409e0639d8463ad86dcfeMarcin Slusarz prog->tls_space = info->bin.tlsSpace; 3540bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller 3550bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller if (prog->type == PIPE_SHADER_FRAGMENT) { 3560bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller if (info->prop.fp.writesDepth) { 3570bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->fp.flags[0] |= NV50_3D_FP_CONTROL_EXPORTS_Z; 3580bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->fp.flags[1] = 0x11; 3590bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller } 3600bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller if (info->prop.fp.usesDiscard) 3610bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->fp.flags[0] |= NV50_3D_FP_CONTROL_USES_KIL; 362633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller } 363633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller 36402fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller if (prog->pipe.stream_output.num_outputs) 36502fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller prog->so = nv50_program_create_strmout_state(info, 36602fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller &prog->pipe.stream_output); 36702fac2930581b9bea9f6d221eb6d6b471fc3b9c6Christoph Bumiller 3680bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumillerout: 3690bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller FREE(info); 3700bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller return !ret; 3713afabfb929cf24a783c10c99bf0d86245e70a94aChristoph Bumiller} 3723afabfb929cf24a783c10c99bf0d86245e70a94aChristoph Bumiller 373633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillerboolean 3740bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumillernv50_program_upload_code(struct nv50_context *nv50, struct nv50_program *prog) 37544d8c9add2f095fc365ede751253d9fb7fc5c6e1Christoph Bumiller{ 3760bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller struct nouveau_heap *heap; 377633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller int ret; 3780bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller uint32_t size = align(prog->code_size, 0x40); 37944d8c9add2f095fc365ede751253d9fb7fc5c6e1Christoph Bumiller 3800bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller switch (prog->type) { 3810bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller case PIPE_SHADER_VERTEX: heap = nv50->screen->vp_code_heap; break; 3820bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller case PIPE_SHADER_GEOMETRY: heap = nv50->screen->fp_code_heap; break; 3830bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller case PIPE_SHADER_FRAGMENT: heap = nv50->screen->gp_code_heap; break; 3840bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller default: 3850bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller assert(!"invalid program type"); 3860bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller return FALSE; 387633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller } 388708c711f8361ea82c1217e2614914ae047bc5bdfChristoph Bumiller 3890bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller ret = nouveau_heap_alloc(heap, size, prog, &prog->mem); 390633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller if (ret) { 3910bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller /* Out of space: evict everything to compactify the code segment, hoping 3920bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller * the working set is much smaller and drifts slowly. Improve me ! 3930bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller */ 3940bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller while (heap->next) { 3950bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller struct nv50_program *evict = heap->next->priv; 3960bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller if (evict) 3970bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller nouveau_heap_free(&evict->mem); 3980bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller } 3990bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller debug_printf("WARNING: out of code space, evicting all shaders.\n"); 400633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller } 4010bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller prog->code_base = prog->mem->start; 4022a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs 4031906d2b46b21a8e7496409e0639d8463ad86dcfeMarcin Slusarz ret = nv50_tls_realloc(nv50->screen, prog->tls_space); 4041906d2b46b21a8e7496409e0639d8463ad86dcfeMarcin Slusarz if (ret < 0) 4051906d2b46b21a8e7496409e0639d8463ad86dcfeMarcin Slusarz return FALSE; 4061906d2b46b21a8e7496409e0639d8463ad86dcfeMarcin Slusarz if (ret > 0) 4071906d2b46b21a8e7496409e0639d8463ad86dcfeMarcin Slusarz nv50->state.new_tls_space = TRUE; 4081906d2b46b21a8e7496409e0639d8463ad86dcfeMarcin Slusarz 4090bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller if (prog->fixups) 4100bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller nv50_ir_relocate_code(prog->fixups, prog->code, prog->code_base, 0, 0); 4110bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller 4120bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller nv50_sifc_linear_u8(&nv50->base, nv50->screen->code, 4130bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller (prog->type << NV50_CODE_BO_SIZE_LOG2) + prog->code_base, 4140bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller NOUVEAU_BO_VRAM, prog->code_size, prog->code); 4150bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller 4160bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller BEGIN_NV04(nv50->base.pushbuf, NV50_3D(CODE_CB_FLUSH), 1); 4170bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller PUSH_DATA (nv50->base.pushbuf, 0); 4180bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller 4190bbf1659df3adf51784bcb376e681c05f49b6070Christoph Bumiller return TRUE; 4202a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs} 4212a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs 422633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillervoid 423633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillernv50_program_destroy(struct nv50_context *nv50, struct nv50_program *p) 4242a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs{ 425f6b994b3058d1c6cd7c28eef522c08df3d83bea7Christoph Bumiller const struct pipe_shader_state pipe = p->pipe; 426f6b994b3058d1c6cd7c28eef522c08df3d83bea7Christoph Bumiller const ubyte type = p->type; 427f6b994b3058d1c6cd7c28eef522c08df3d83bea7Christoph Bumiller 4286d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller if (p->mem) 4296d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller nouveau_heap_free(&p->mem); 430f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs 431633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller if (p->code) 432633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller FREE(p->code); 4337c745de74997e859d7e2640092bda9ad900e28a9Ben Skeggs 4343a62365f402b1159afd526fb4b510cdb51de1365Christoph Bumiller if (p->fixups) 4353a62365f402b1159afd526fb4b510cdb51de1365Christoph Bumiller FREE(p->fixups); 4363a62365f402b1159afd526fb4b510cdb51de1365Christoph Bumiller 4373232a86efe76df9fcee869c4ed4af8d68824920cMarcin Slusarz if (p->so) 4383232a86efe76df9fcee869c4ed4af8d68824920cMarcin Slusarz FREE(p->so); 4393232a86efe76df9fcee869c4ed4af8d68824920cMarcin Slusarz 440f6b994b3058d1c6cd7c28eef522c08df3d83bea7Christoph Bumiller memset(p, 0, sizeof(*p)); 441f6b994b3058d1c6cd7c28eef522c08df3d83bea7Christoph Bumiller 442f6b994b3058d1c6cd7c28eef522c08df3d83bea7Christoph Bumiller p->pipe = pipe; 443f6b994b3058d1c6cd7c28eef522c08df3d83bea7Christoph Bumiller p->type = type; 444f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs} 445