2
* Copyright 2011 Christoph Bumiller
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* Software is furnished to do so, subject to the following conditions:
11
* The above copyright notice and this permission notice shall be included in
12
* all copies or substantial portions of the Software.
14
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
* OTHER DEALINGS IN THE SOFTWARE.
23
#include "codegen/nv50_ir.h"
24
#include "codegen/nv50_ir_target.h"
25
#include "codegen/nv50_ir_driver.h"
28
#include "nouveau_debug.h"
33
Modifier::Modifier(operation op)
36
case OP_NEG: bits = NV50_IR_MOD_NEG; break;
37
case OP_ABS: bits = NV50_IR_MOD_ABS; break;
38
case OP_SAT: bits = NV50_IR_MOD_SAT; break;
39
case OP_NOT: bits = NV50_IR_MOD_NOT; break;
46
Modifier Modifier::operator*(const Modifier m) const
51
if (this->bits & NV50_IR_MOD_ABS)
52
b &= ~NV50_IR_MOD_NEG;
54
a = (this->bits ^ b) & (NV50_IR_MOD_NOT | NV50_IR_MOD_NEG);
55
c = (this->bits | m.bits) & (NV50_IR_MOD_ABS | NV50_IR_MOD_SAT);
57
return Modifier(a | c);
60
ValueRef::ValueRef(Value *v) : value(NULL), insn(NULL)
68
ValueRef::ValueRef(const ValueRef& ref) : value(NULL), insn(ref.insn)
71
usedAsPtr = ref.usedAsPtr;
79
bool ValueRef::getImmediate(ImmediateValue &imm) const
81
const ValueRef *src = this;
83
DataType type = src->insn->sType;
87
if (src->insn->sType != type)
91
if (src->getFile() == FILE_IMMEDIATE) {
92
imm = *(src->value->asImm());
93
// The immediate's type isn't required to match its use, it's
94
// more of a hint; applying a modifier makes use of that hint.
100
Instruction *insn = src->value->getUniqueInsn();
102
if (insn && insn->op == OP_MOV) {
105
WARN("OP_MOV with modifier encountered !\n");
113
ValueDef::ValueDef(Value *v) : value(NULL), origin(NULL), insn(NULL)
118
ValueDef::ValueDef(const ValueDef& def) : value(NULL), origin(NULL), insn(NULL)
123
ValueDef::~ValueDef()
129
ValueRef::set(const ValueRef &ref)
131
this->set(ref.get());
133
indirect[0] = ref.indirect[0];
134
indirect[1] = ref.indirect[1];
138
ValueRef::set(Value *refVal)
143
value->uses.erase(this);
145
refVal->uses.insert(this);
151
ValueDef::set(Value *defVal)
156
value->defs.remove(this);
158
defVal->defs.push_back(this);
163
// Check if we can replace this definition's value by the value in @rep,
164
// including the source modifiers, i.e. make sure that all uses support
167
ValueDef::mayReplace(const ValueRef &rep)
172
if (!insn || !insn->bb) // Unbound instruction ?
175
const Target *target = insn->bb->getProgram()->getTarget();
177
for (Value::UseIterator it = value->uses.begin(); it != value->uses.end();
179
Instruction *insn = (*it)->getInsn();
182
for (int i = 0; insn->srcExists(i); ++i) {
183
if (insn->src(i).get() == value) {
184
// If there are multiple references to us we'd have to check if the
185
// combination of mods is still supported, but just bail for now.
186
if (&insn->src(i) != (*it))
191
assert(s >= 0); // integrity of uses list
193
if (!target->isModSupported(insn, s, rep.mod))
200
ValueDef::replace(const ValueRef &repVal, bool doSet)
202
assert(mayReplace(repVal));
204
if (value == repVal.get())
207
while (!value->uses.empty()) {
208
ValueRef *ref = *value->uses.begin();
209
ref->set(repVal.get());
210
ref->mod *= repVal.mod;
217
Value::Value() : id(-1)
220
memset(®, 0, sizeof(reg));
224
LValue::LValue(Function *fn, DataFile file)
227
reg.size = (file != FILE_PREDICATE) ? 4 : 1;
236
fn->add(this, this->id);
239
LValue::LValue(Function *fn, LValue *lval)
243
reg.file = lval->reg.file;
244
reg.size = lval->reg.size;
253
fn->add(this, this->id);
257
LValue::clone(ClonePolicy<Function>& pol) const
259
LValue *that = new_LValue(pol.context(), reg.file);
261
pol.set<Value>(this, that);
263
that->reg.size = this->reg.size;
264
that->reg.type = this->reg.type;
265
that->reg.data = this->reg.data;
271
LValue::isUniform() const
275
Instruction *insn = getInsn();
278
// let's not try too hard here for now ...
279
return !insn->srcExists(1) && insn->getSrc(0)->isUniform();
282
Symbol::Symbol(Program *prog, DataFile f, ubyte fidx)
287
reg.fileIndex = fidx;
290
prog->add(this, this->id);
294
Symbol::clone(ClonePolicy<Function>& pol) const
296
Program *prog = pol.context()->getProgram();
298
Symbol *that = new_Symbol(prog, reg.file, reg.fileIndex);
300
pol.set<Value>(this, that);
302
that->reg.size = this->reg.size;
303
that->reg.type = this->reg.type;
304
that->reg.data = this->reg.data;
306
that->baseSym = this->baseSym;
312
Symbol::isUniform() const
315
reg.file != FILE_SYSTEM_VALUE &&
316
reg.file != FILE_MEMORY_LOCAL &&
317
reg.file != FILE_SHADER_INPUT;
320
ImmediateValue::ImmediateValue(Program *prog, uint32_t uval)
322
memset(®, 0, sizeof(reg));
324
reg.file = FILE_IMMEDIATE;
330
prog->add(this, this->id);
333
ImmediateValue::ImmediateValue(Program *prog, float fval)
335
memset(®, 0, sizeof(reg));
337
reg.file = FILE_IMMEDIATE;
343
prog->add(this, this->id);
346
ImmediateValue::ImmediateValue(Program *prog, double dval)
348
memset(®, 0, sizeof(reg));
350
reg.file = FILE_IMMEDIATE;
356
prog->add(this, this->id);
359
ImmediateValue::ImmediateValue(const ImmediateValue *proto, DataType ty)
364
reg.size = typeSizeof(ty);
368
ImmediateValue::clone(ClonePolicy<Function>& pol) const
370
Program *prog = pol.context()->getProgram();
371
ImmediateValue *that = new_ImmediateValue(prog, 0u);
373
pol.set<Value>(this, that);
375
that->reg.size = this->reg.size;
376
that->reg.type = this->reg.type;
377
that->reg.data = this->reg.data;
383
ImmediateValue::isInteger(const int i) const
387
return reg.data.s8 == i;
389
return reg.data.u8 == i;
391
return reg.data.s16 == i;
393
return reg.data.u16 == i;
396
return reg.data.s32 == i; // as if ...
399
return reg.data.s64 == i; // as if ...
401
return reg.data.f32 == static_cast<float>(i);
403
return reg.data.f64 == static_cast<double>(i);
410
ImmediateValue::isNegative() const
413
case TYPE_S8: return reg.data.s8 < 0;
414
case TYPE_S16: return reg.data.s16 < 0;
416
case TYPE_U32: return reg.data.s32 < 0;
417
case TYPE_F32: return reg.data.u32 & (1 << 31);
418
case TYPE_F64: return reg.data.u64 & (1ULL << 63);
425
ImmediateValue::isPow2() const
427
if (reg.type == TYPE_U64 || reg.type == TYPE_S64)
428
return util_is_power_of_two_or_zero64(reg.data.u64);
430
return util_is_power_of_two_or_zero(reg.data.u32);
434
ImmediateValue::applyLog2()
440
assert(!this->isNegative());
445
reg.data.u32 = util_logbase2(reg.data.u32);
448
assert(!this->isNegative());
451
reg.data.u64 = util_logbase2_64(reg.data.u64);
454
reg.data.f32 = log2f(reg.data.f32);
457
reg.data.f64 = log2(reg.data.f64);
466
ImmediateValue::compare(CondCode cc, float fval) const
468
if (reg.type != TYPE_F32)
469
ERROR("immediate value is not of type f32");
471
switch (static_cast<CondCode>(cc & 7)) {
472
case CC_TR: return true;
473
case CC_FL: return false;
474
case CC_LT: return reg.data.f32 < fval;
475
case CC_LE: return reg.data.f32 <= fval;
476
case CC_GT: return reg.data.f32 > fval;
477
case CC_GE: return reg.data.f32 >= fval;
478
case CC_EQ: return reg.data.f32 == fval;
479
case CC_NE: return reg.data.f32 != fval;
487
ImmediateValue::operator=(const ImmediateValue &that)
489
this->reg = that.reg;
494
Value::interfers(const Value *that) const
498
if (that->reg.file != reg.file || that->reg.fileIndex != reg.fileIndex)
504
idA = this->join->reg.data.offset;
505
idB = that->join->reg.data.offset;
507
idA = this->join->reg.data.id * MIN2(this->reg.size, 4);
508
idB = that->join->reg.data.id * MIN2(that->reg.size, 4);
512
return (idA + this->reg.size > idB);
515
return (idB + that->reg.size > idA);
521
Value::equals(const Value *that, bool strict) const
526
if (that->reg.file != reg.file || that->reg.fileIndex != reg.fileIndex)
528
if (that->reg.size != this->reg.size)
531
if (that->reg.data.id != this->reg.data.id)
538
ImmediateValue::equals(const Value *that, bool strict) const
540
const ImmediateValue *imm = that->asImm();
543
return reg.data.u64 == imm->reg.data.u64;
547
Symbol::equals(const Value *that, bool strict) const
549
if (reg.file != that->reg.file || reg.fileIndex != that->reg.fileIndex)
551
assert(that->asSym());
553
if (this->baseSym != that->asSym()->baseSym)
556
if (reg.file == FILE_SYSTEM_VALUE)
557
return (this->reg.data.sv.sv == that->reg.data.sv.sv &&
558
this->reg.data.sv.index == that->reg.data.sv.index);
559
return this->reg.data.offset == that->reg.data.offset;
562
void Instruction::init()
597
Instruction::Instruction()
602
dType = sType = TYPE_F32;
607
Instruction::Instruction(Function *fn, operation opr, DataType ty)
617
Instruction::~Instruction()
620
Function *fn = bb->getFunction();
622
fn->allInsns.remove(id);
625
for (int s = 0; srcExists(s); ++s)
627
// must unlink defs too since the list pointers will get deallocated
628
for (int d = 0; defExists(d); ++d)
633
Instruction::setDef(int i, Value *val)
635
int size = defs.size();
639
defs[size++].setInsn(this);
645
Instruction::setSrc(int s, Value *val)
647
int size = srcs.size();
651
srcs[size++].setInsn(this);
657
Instruction::setSrc(int s, const ValueRef& ref)
659
setSrc(s, ref.get());
660
srcs[s].mod = ref.mod;
664
Instruction::swapSources(int a, int b)
666
Value *value = srcs[a].get();
667
Modifier m = srcs[a].mod;
675
static inline void moveSourcesAdjustIndex(int8_t &index, int s, int delta)
680
if ((delta < 0) && (index >= (s + delta)))
684
// Moves sources [@s,last_source] by @delta.
685
// If @delta < 0, sources [@s - abs(@delta), @s) are erased.
687
Instruction::moveSources(const int s, const int delta)
691
assert(s + delta >= 0);
695
for (k = 0; srcExists(k); ++k) {
696
for (int i = 0; i < 2; ++i)
697
moveSourcesAdjustIndex(src(k).indirect[i], s, delta);
699
moveSourcesAdjustIndex(predSrc, s, delta);
700
moveSourcesAdjustIndex(flagsSrc, s, delta);
702
TexInstruction *tex = asTex();
703
moveSourcesAdjustIndex(tex->tex.rIndirectSrc, s, delta);
704
moveSourcesAdjustIndex(tex->tex.sIndirectSrc, s, delta);
709
for (int p = k + delta; k >= s; --k, --p)
713
for (p = s; p < k; ++p)
714
setSrc(p + delta, src(p));
715
for (; (p + delta) < k; ++p)
716
setSrc(p + delta, NULL);
721
Instruction::takeExtraSources(int s, Value *values[3])
723
values[0] = getIndirect(s, 0);
725
setIndirect(s, 0, NULL);
727
values[1] = getIndirect(s, 1);
729
setIndirect(s, 1, NULL);
731
values[2] = getPredicate();
733
setPredicate(cc, NULL);
737
Instruction::putExtraSources(int s, Value *values[3])
740
setIndirect(s, 0, values[0]);
742
setIndirect(s, 1, values[1]);
744
setPredicate(cc, values[2]);
748
Instruction::clone(ClonePolicy<Function>& pol, Instruction *i) const
751
i = new_Instruction(pol.context(), op, dType);
752
#if !defined(NDEBUG) && defined(__cpp_rtti)
753
assert(typeid(*i) == typeid(*this));
756
pol.set<Instruction>(this, i);
764
i->saturate = saturate;
772
i->perPatch = perPatch;
774
i->postFactor = postFactor;
776
for (int d = 0; defExists(d); ++d)
777
i->setDef(d, pol.get(getDef(d)));
779
for (int s = 0; srcExists(s); ++s) {
780
i->setSrc(s, pol.get(getSrc(s)));
781
i->src(s).mod = src(s).mod;
785
i->predSrc = predSrc;
786
i->flagsDef = flagsDef;
787
i->flagsSrc = flagsSrc;
793
Instruction::defCount(unsigned int mask, bool singleFile) const
798
unsigned int d = ffs(mask);
801
for (i = d--; defExists(i); ++i)
802
if (getDef(i)->reg.file != getDef(d)->reg.file)
806
for (n = 0, i = 0; this->defExists(i); ++i, mask >>= 1)
812
Instruction::srcCount(unsigned int mask, bool singleFile) const
817
unsigned int s = ffs(mask);
820
for (i = s--; srcExists(i); ++i)
821
if (getSrc(i)->reg.file != getSrc(s)->reg.file)
825
for (n = 0, i = 0; this->srcExists(i); ++i, mask >>= 1)
831
Instruction::setIndirect(int s, int dim, Value *value)
833
assert(this->srcExists(s));
835
int p = srcs[s].indirect[dim];
840
while (p > 0 && !srcExists(p - 1))
844
srcs[p].usedAsPtr = (value != 0);
845
srcs[s].indirect[dim] = value ? p : -1;
850
Instruction::setPredicate(CondCode ccode, Value *value)
856
srcs[predSrc].set(NULL);
863
predSrc = srcs.size();
864
while (predSrc > 0 && !srcExists(predSrc - 1))
868
setSrc(predSrc, value);
873
Instruction::writesPredicate() const
875
for (int d = 0; defExists(d); ++d)
876
if (getDef(d)->inFile(FILE_PREDICATE) || getDef(d)->inFile(FILE_FLAGS))
882
Instruction::canCommuteDefSrc(const Instruction *i) const
884
for (int d = 0; defExists(d); ++d)
885
for (int s = 0; i->srcExists(s); ++s)
886
if (getDef(d)->interfers(i->getSrc(s)))
892
Instruction::canCommuteDefDef(const Instruction *i) const
894
for (int d = 0; defExists(d); ++d)
895
for (int c = 0; i->defExists(c); ++c)
896
if (getDef(d)->interfers(i->getDef(c)))
902
Instruction::isCommutationLegal(const Instruction *i) const
904
return canCommuteDefDef(i) &&
905
canCommuteDefSrc(i) &&
906
i->canCommuteDefSrc(this);
909
TexInstruction::TexInstruction(Function *fn, operation op)
910
: Instruction(fn, op, TYPE_F32), tex()
912
tex.rIndirectSrc = -1;
913
tex.sIndirectSrc = -1;
919
TexInstruction::~TexInstruction()
921
for (int c = 0; c < 3; ++c) {
925
for (int n = 0; n < 4; ++n)
926
for (int c = 0; c < 3; ++c)
927
offset[n][c].set(NULL);
931
TexInstruction::clone(ClonePolicy<Function>& pol, Instruction *i) const
933
TexInstruction *tex = (i ? static_cast<TexInstruction *>(i) :
934
new_TexInstruction(pol.context(), op));
936
Instruction::clone(pol, tex);
938
tex->tex = this->tex;
941
for (unsigned int c = 0; c < tex->tex.target.getDim(); ++c) {
942
tex->dPdx[c].set(dPdx[c]);
943
tex->dPdy[c].set(dPdy[c]);
947
for (int n = 0; n < tex->tex.useOffsets; ++n)
948
for (int c = 0; c < 3; ++c)
949
tex->offset[n][c].set(offset[n][c]);
954
const struct TexInstruction::Target::Desc TexInstruction::Target::descTable[] =
956
{ "1D", 1, 1, false, false, false },
957
{ "2D", 2, 2, false, false, false },
958
{ "2D_MS", 2, 3, false, false, false },
959
{ "3D", 3, 3, false, false, false },
960
{ "CUBE", 2, 3, false, true, false },
961
{ "1D_SHADOW", 1, 1, false, false, true },
962
{ "2D_SHADOW", 2, 2, false, false, true },
963
{ "CUBE_SHADOW", 2, 3, false, true, true },
964
{ "1D_ARRAY", 1, 2, true, false, false },
965
{ "2D_ARRAY", 2, 3, true, false, false },
966
{ "2D_MS_ARRAY", 2, 4, true, false, false },
967
{ "CUBE_ARRAY", 2, 4, true, true, false },
968
{ "1D_ARRAY_SHADOW", 1, 2, true, false, true },
969
{ "2D_ARRAY_SHADOW", 2, 3, true, false, true },
970
{ "RECT", 2, 2, false, false, false },
971
{ "RECT_SHADOW", 2, 2, false, false, true },
972
{ "CUBE_ARRAY_SHADOW", 2, 4, true, true, true },
973
{ "BUFFER", 1, 1, false, false, false },
976
const struct TexInstruction::ImgFormatDesc TexInstruction::formatTable[] =
978
{ "NONE", 0, { 0, 0, 0, 0 }, UINT },
980
{ "RGBA32F", 4, { 32, 32, 32, 32 }, FLOAT },
981
{ "RGBA16F", 4, { 16, 16, 16, 16 }, FLOAT },
982
{ "RG32F", 2, { 32, 32, 0, 0 }, FLOAT },
983
{ "RG16F", 2, { 16, 16, 0, 0 }, FLOAT },
984
{ "R11G11B10F", 3, { 11, 11, 10, 0 }, FLOAT },
985
{ "R32F", 1, { 32, 0, 0, 0 }, FLOAT },
986
{ "R16F", 1, { 16, 0, 0, 0 }, FLOAT },
988
{ "RGBA32UI", 4, { 32, 32, 32, 32 }, UINT },
989
{ "RGBA16UI", 4, { 16, 16, 16, 16 }, UINT },
990
{ "RGB10A2UI", 4, { 10, 10, 10, 2 }, UINT },
991
{ "RGBA8UI", 4, { 8, 8, 8, 8 }, UINT },
992
{ "RG32UI", 2, { 32, 32, 0, 0 }, UINT },
993
{ "RG16UI", 2, { 16, 16, 0, 0 }, UINT },
994
{ "RG8UI", 2, { 8, 8, 0, 0 }, UINT },
995
{ "R32UI", 1, { 32, 0, 0, 0 }, UINT },
996
{ "R16UI", 1, { 16, 0, 0, 0 }, UINT },
997
{ "R8UI", 1, { 8, 0, 0, 0 }, UINT },
999
{ "RGBA32I", 4, { 32, 32, 32, 32 }, SINT },
1000
{ "RGBA16I", 4, { 16, 16, 16, 16 }, SINT },
1001
{ "RGBA8I", 4, { 8, 8, 8, 8 }, SINT },
1002
{ "RG32I", 2, { 32, 32, 0, 0 }, SINT },
1003
{ "RG16I", 2, { 16, 16, 0, 0 }, SINT },
1004
{ "RG8I", 2, { 8, 8, 0, 0 }, SINT },
1005
{ "R32I", 1, { 32, 0, 0, 0 }, SINT },
1006
{ "R16I", 1, { 16, 0, 0, 0 }, SINT },
1007
{ "R8I", 1, { 8, 0, 0, 0 }, SINT },
1009
{ "RGBA16", 4, { 16, 16, 16, 16 }, UNORM },
1010
{ "RGB10A2", 4, { 10, 10, 10, 2 }, UNORM },
1011
{ "RGBA8", 4, { 8, 8, 8, 8 }, UNORM },
1012
{ "RG16", 2, { 16, 16, 0, 0 }, UNORM },
1013
{ "RG8", 2, { 8, 8, 0, 0 }, UNORM },
1014
{ "R16", 1, { 16, 0, 0, 0 }, UNORM },
1015
{ "R8", 1, { 8, 0, 0, 0 }, UNORM },
1017
{ "RGBA16_SNORM", 4, { 16, 16, 16, 16 }, SNORM },
1018
{ "RGBA8_SNORM", 4, { 8, 8, 8, 8 }, SNORM },
1019
{ "RG16_SNORM", 2, { 16, 16, 0, 0 }, SNORM },
1020
{ "RG8_SNORM", 2, { 8, 8, 0, 0 }, SNORM },
1021
{ "R16_SNORM", 1, { 16, 0, 0, 0 }, SNORM },
1022
{ "R8_SNORM", 1, { 8, 0, 0, 0 }, SNORM },
1024
{ "BGRA8", 4, { 8, 8, 8, 8 }, UNORM, true },
1027
const struct TexInstruction::ImgFormatDesc *
1028
TexInstruction::translateImgFormat(enum pipe_format format)
1031
#define FMT_CASE(a, b) \
1032
case PIPE_FORMAT_ ## a: return &formatTable[nv50_ir::FMT_ ## b]
1035
FMT_CASE(NONE, NONE);
1037
FMT_CASE(R32G32B32A32_FLOAT, RGBA32F);
1038
FMT_CASE(R16G16B16A16_FLOAT, RGBA16F);
1039
FMT_CASE(R32G32_FLOAT, RG32F);
1040
FMT_CASE(R16G16_FLOAT, RG16F);
1041
FMT_CASE(R11G11B10_FLOAT, R11G11B10F);
1042
FMT_CASE(R32_FLOAT, R32F);
1043
FMT_CASE(R16_FLOAT, R16F);
1045
FMT_CASE(R32G32B32A32_UINT, RGBA32UI);
1046
FMT_CASE(R16G16B16A16_UINT, RGBA16UI);
1047
FMT_CASE(R10G10B10A2_UINT, RGB10A2UI);
1048
FMT_CASE(R8G8B8A8_UINT, RGBA8UI);
1049
FMT_CASE(R32G32_UINT, RG32UI);
1050
FMT_CASE(R16G16_UINT, RG16UI);
1051
FMT_CASE(R8G8_UINT, RG8UI);
1052
FMT_CASE(R32_UINT, R32UI);
1053
FMT_CASE(R16_UINT, R16UI);
1054
FMT_CASE(R8_UINT, R8UI);
1056
FMT_CASE(R32G32B32A32_SINT, RGBA32I);
1057
FMT_CASE(R16G16B16A16_SINT, RGBA16I);
1058
FMT_CASE(R8G8B8A8_SINT, RGBA8I);
1059
FMT_CASE(R32G32_SINT, RG32I);
1060
FMT_CASE(R16G16_SINT, RG16I);
1061
FMT_CASE(R8G8_SINT, RG8I);
1062
FMT_CASE(R32_SINT, R32I);
1063
FMT_CASE(R16_SINT, R16I);
1064
FMT_CASE(R8_SINT, R8I);
1066
FMT_CASE(R16G16B16A16_UNORM, RGBA16);
1067
FMT_CASE(R10G10B10A2_UNORM, RGB10A2);
1068
FMT_CASE(R8G8B8A8_UNORM, RGBA8);
1069
FMT_CASE(R16G16_UNORM, RG16);
1070
FMT_CASE(R8G8_UNORM, RG8);
1071
FMT_CASE(R16_UNORM, R16);
1072
FMT_CASE(R8_UNORM, R8);
1074
FMT_CASE(R16G16B16A16_SNORM, RGBA16_SNORM);
1075
FMT_CASE(R8G8B8A8_SNORM, RGBA8_SNORM);
1076
FMT_CASE(R16G16_SNORM, RG16_SNORM);
1077
FMT_CASE(R8G8_SNORM, RG8_SNORM);
1078
FMT_CASE(R16_SNORM, R16_SNORM);
1079
FMT_CASE(R8_SNORM, R8_SNORM);
1081
FMT_CASE(B8G8R8A8_UNORM, BGRA8);
1084
assert(!"Unexpected format");
1085
return &formatTable[nv50_ir::FMT_NONE];
1090
TexInstruction::setIndirectR(Value *v)
1092
int p = ((tex.rIndirectSrc < 0) && v) ? srcs.size() : tex.rIndirectSrc;
1094
tex.rIndirectSrc = p;
1096
srcs[p].usedAsPtr = !!v;
1101
TexInstruction::setIndirectS(Value *v)
1103
int p = ((tex.sIndirectSrc < 0) && v) ? srcs.size() : tex.sIndirectSrc;
1105
tex.sIndirectSrc = p;
1107
srcs[p].usedAsPtr = !!v;
1111
CmpInstruction::CmpInstruction(Function *fn, operation op)
1112
: Instruction(fn, op, TYPE_F32)
1114
setCond = CC_ALWAYS;
1118
CmpInstruction::clone(ClonePolicy<Function>& pol, Instruction *i) const
1120
CmpInstruction *cmp = (i ? static_cast<CmpInstruction *>(i) :
1121
new_CmpInstruction(pol.context(), op));
1123
Instruction::clone(pol, cmp);
1124
cmp->setCond = setCond;
1128
FlowInstruction::FlowInstruction(Function *fn, operation op, void *targ)
1129
: Instruction(fn, op, TYPE_NONE)
1132
target.fn = reinterpret_cast<Function *>(targ);
1134
target.bb = reinterpret_cast<BasicBlock *>(targ);
1137
op == OP_CONT || op == OP_BREAK ||
1138
op == OP_RET || op == OP_EXIT)
1142
terminator = targ ? 1 : 0;
1144
allWarp = absolute = limit = builtin = indirect = 0;
1148
FlowInstruction::clone(ClonePolicy<Function>& pol, Instruction *i) const
1150
FlowInstruction *flow = (i ? static_cast<FlowInstruction *>(i) :
1151
new_FlowInstruction(pol.context(), op, NULL));
1153
Instruction::clone(pol, flow);
1154
flow->allWarp = allWarp;
1155
flow->absolute = absolute;
1156
flow->limit = limit;
1157
flow->builtin = builtin;
1160
flow->target.builtin = target.builtin;
1163
flow->target.fn = target.fn;
1166
flow->target.bb = pol.get<BasicBlock>(target.bb);
1171
Program::Program(Type type, Target *arch)
1175
mem_Instruction(sizeof(Instruction), 6),
1176
mem_CmpInstruction(sizeof(CmpInstruction), 4),
1177
mem_TexInstruction(sizeof(TexInstruction), 4),
1178
mem_FlowInstruction(sizeof(FlowInstruction), 4),
1179
mem_LValue(sizeof(LValue), 8),
1180
mem_Symbol(sizeof(Symbol), 7),
1181
mem_ImmediateValue(sizeof(ImmediateValue), 7),
1190
persampleInvocation = false;
1192
main = new Function(this, "MAIN", ~0);
1193
calls.insert(&main->call);
1203
for (ArrayList::Iterator it = allFuncs.iterator(); !it.end(); it.next())
1204
delete reinterpret_cast<Function *>(it.get());
1206
for (ArrayList::Iterator it = allRValues.iterator(); !it.end(); it.next())
1207
releaseValue(reinterpret_cast<Value *>(it.get()));
1210
void Program::releaseInstruction(Instruction *insn)
1212
// TODO: make this not suck so much
1214
insn->~Instruction();
1217
mem_CmpInstruction.release(insn);
1220
mem_TexInstruction.release(insn);
1223
mem_FlowInstruction.release(insn);
1225
mem_Instruction.release(insn);
1228
void Program::releaseValue(Value *value)
1232
if (value->asLValue())
1233
mem_LValue.release(value);
1236
mem_ImmediateValue.release(value);
1239
mem_Symbol.release(value);
1243
} // namespace nv50_ir
1248
nv50_ir_init_prog_info(struct nv50_ir_prog_info *info,
1249
struct nv50_ir_prog_info_out *info_out)
1251
info_out->target = info->target;
1252
info_out->type = info->type;
1253
if (info->type == PIPE_SHADER_TESS_CTRL || info->type == PIPE_SHADER_TESS_EVAL) {
1254
info_out->prop.tp.domain = PIPE_PRIM_MAX;
1255
info_out->prop.tp.outputPrim = PIPE_PRIM_MAX;
1257
if (info->type == PIPE_SHADER_GEOMETRY) {
1258
info_out->prop.gp.instanceCount = 1;
1259
info_out->prop.gp.maxVertices = 1;
1261
if (info->type == PIPE_SHADER_COMPUTE) {
1262
info->prop.cp.numThreads[0] =
1263
info->prop.cp.numThreads[1] =
1264
info->prop.cp.numThreads[2] = 1;
1266
info_out->bin.smemSize = info->bin.smemSize;
1267
info_out->io.genUserClip = info->io.genUserClip;
1268
info_out->io.instanceId = 0xff;
1269
info_out->io.vertexId = 0xff;
1270
info_out->io.edgeFlagIn = 0xff;
1271
info_out->io.edgeFlagOut = 0xff;
1272
info_out->io.fragDepth = 0xff;
1273
info_out->io.sampleMask = 0xff;
1277
nv50_ir_generate_code(struct nv50_ir_prog_info *info,
1278
struct nv50_ir_prog_info_out *info_out)
1282
nv50_ir::Program::Type type;
1284
nv50_ir_init_prog_info(info, info_out);
1286
#define PROG_TYPE_CASE(a, b) \
1287
case PIPE_SHADER_##a: type = nv50_ir::Program::TYPE_##b; break
1289
switch (info->type) {
1290
PROG_TYPE_CASE(VERTEX, VERTEX);
1291
PROG_TYPE_CASE(TESS_CTRL, TESSELLATION_CONTROL);
1292
PROG_TYPE_CASE(TESS_EVAL, TESSELLATION_EVAL);
1293
PROG_TYPE_CASE(GEOMETRY, GEOMETRY);
1294
PROG_TYPE_CASE(FRAGMENT, FRAGMENT);
1295
PROG_TYPE_CASE(COMPUTE, COMPUTE);
1297
INFO_DBG(info->dbgFlags, VERBOSE, "unsupported program type %u\n", info->type);
1300
INFO_DBG(info->dbgFlags, VERBOSE, "translating program of type %u\n", type);
1302
nv50_ir::Target *targ = nv50_ir::Target::create(info->target);
1306
nv50_ir::Program *prog = new nv50_ir::Program(type, targ);
1308
nv50_ir::Target::destroy(targ);
1311
prog->driver = info;
1312
prog->driver_out = info_out;
1313
prog->dbgFlags = info->dbgFlags;
1314
prog->optLevel = info->optLevel;
1316
switch (info->bin.sourceRep) {
1317
case PIPE_SHADER_IR_NIR:
1318
ret = prog->makeFromNIR(info, info_out) ? 0 : -2;
1320
case PIPE_SHADER_IR_TGSI:
1321
ret = prog->makeFromTGSI(info, info_out) ? 0 : -2;
1329
if (prog->dbgFlags & NV50_IR_DEBUG_VERBOSE)
1332
targ->parseDriverInfo(info, info_out);
1333
prog->getTarget()->runLegalizePass(prog, nv50_ir::CG_STAGE_PRE_SSA);
1335
prog->convertToSSA();
1337
if (prog->dbgFlags & NV50_IR_DEBUG_VERBOSE)
1340
prog->optimizeSSA(info->optLevel);
1341
prog->getTarget()->runLegalizePass(prog, nv50_ir::CG_STAGE_SSA);
1343
if (prog->dbgFlags & NV50_IR_DEBUG_BASIC)
1346
if (!prog->registerAllocation()) {
1350
prog->getTarget()->runLegalizePass(prog, nv50_ir::CG_STAGE_POST_RA);
1352
prog->optimizePostRA(info->optLevel);
1354
if (!prog->emitBinary(info_out)) {
1360
INFO_DBG(prog->dbgFlags, VERBOSE, "nv50_ir_generate_code: ret = %i\n", ret);
1362
info_out->bin.maxGPR = prog->maxGPR;
1363
info_out->bin.code = prog->code;
1364
info_out->bin.codeSize = prog->binSize;
1365
info_out->bin.tlsSpace = prog->tlsSize;
1368
nv50_ir::Target::destroy(targ);