49425b98b9137058c986b1c5fdc03aeab5358534
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"
29 #include "nv50/nv50_program.h"
34 Modifier::Modifier(operation op
)
37 case OP_NEG
: bits
= NV50_IR_MOD_NEG
; break;
38 case OP_ABS
: bits
= NV50_IR_MOD_ABS
; break;
39 case OP_SAT
: bits
= NV50_IR_MOD_SAT
; break;
40 case OP_NOT
: bits
= NV50_IR_MOD_NOT
; break;
47 Modifier
Modifier::operator*(const Modifier m
) const
52 if (this->bits
& NV50_IR_MOD_ABS
)
53 b
&= ~NV50_IR_MOD_NEG
;
55 a
= (this->bits
^ b
) & (NV50_IR_MOD_NOT
| NV50_IR_MOD_NEG
);
56 c
= (this->bits
| m
.bits
) & (NV50_IR_MOD_ABS
| NV50_IR_MOD_SAT
);
58 return Modifier(a
| c
);
61 ValueRef::ValueRef(Value
*v
) : value(NULL
), insn(NULL
)
69 ValueRef::ValueRef(const ValueRef
& ref
) : value(NULL
), insn(ref
.insn
)
72 usedAsPtr
= ref
.usedAsPtr
;
80 bool ValueRef::getImmediate(ImmediateValue
&imm
) const
82 const ValueRef
*src
= this;
84 DataType type
= src
->insn
->sType
;
88 if (src
->insn
->sType
!= type
)
92 if (src
->getFile() == FILE_IMMEDIATE
) {
93 imm
= *(src
->value
->asImm());
94 // The immediate's type isn't required to match its use, it's
95 // more of a hint; applying a modifier makes use of that hint.
101 Instruction
*insn
= src
->value
->getUniqueInsn();
103 if (insn
&& insn
->op
== OP_MOV
) {
106 WARN("OP_MOV with modifier encountered !\n");
114 ValueDef::ValueDef(Value
*v
) : value(NULL
), insn(NULL
)
119 ValueDef::ValueDef(const ValueDef
& def
) : value(NULL
), insn(NULL
)
124 ValueDef::~ValueDef()
130 ValueRef::set(const ValueRef
&ref
)
132 this->set(ref
.get());
134 indirect
[0] = ref
.indirect
[0];
135 indirect
[1] = ref
.indirect
[1];
139 ValueRef::set(Value
*refVal
)
144 value
->uses
.erase(this);
146 refVal
->uses
.insert(this);
152 ValueDef::set(Value
*defVal
)
157 value
->defs
.remove(this);
159 defVal
->defs
.push_back(this);
164 // Check if we can replace this definition's value by the value in @rep,
165 // including the source modifiers, i.e. make sure that all uses support
168 ValueDef::mayReplace(const ValueRef
&rep
)
173 if (!insn
|| !insn
->bb
) // Unbound instruction ?
176 const Target
*target
= insn
->bb
->getProgram()->getTarget();
178 for (Value::UseIterator it
= value
->uses
.begin(); it
!= value
->uses
.end();
180 Instruction
*insn
= (*it
)->getInsn();
183 for (int i
= 0; insn
->srcExists(i
); ++i
) {
184 if (insn
->src(i
).get() == value
) {
185 // If there are multiple references to us we'd have to check if the
186 // combination of mods is still supported, but just bail for now.
187 if (&insn
->src(i
) != (*it
))
192 assert(s
>= 0); // integrity of uses list
194 if (!target
->isModSupported(insn
, s
, rep
.mod
))
201 ValueDef::replace(const ValueRef
&repVal
, bool doSet
)
203 assert(mayReplace(repVal
));
205 if (value
== repVal
.get())
208 while (!value
->uses
.empty()) {
209 ValueRef
*ref
= *value
->uses
.begin();
210 ref
->set(repVal
.get());
211 ref
->mod
*= repVal
.mod
;
221 memset(®
, 0, sizeof(reg
));
225 LValue::LValue(Function
*fn
, DataFile file
)
228 reg
.size
= (file
!= FILE_PREDICATE
) ? 4 : 1;
237 fn
->add(this, this->id
);
240 LValue::LValue(Function
*fn
, LValue
*lval
)
244 reg
.file
= lval
->reg
.file
;
245 reg
.size
= lval
->reg
.size
;
254 fn
->add(this, this->id
);
258 LValue::clone(ClonePolicy
<Function
>& pol
) const
260 LValue
*that
= new_LValue(pol
.context(), reg
.file
);
262 pol
.set
<Value
>(this, that
);
264 that
->reg
.size
= this->reg
.size
;
265 that
->reg
.type
= this->reg
.type
;
266 that
->reg
.data
= this->reg
.data
;
272 LValue::isUniform() const
276 Instruction
*insn
= getInsn();
277 // let's not try too hard here for now ...
278 return !insn
->srcExists(1) && insn
->getSrc(0)->isUniform();
281 Symbol::Symbol(Program
*prog
, DataFile f
, ubyte fidx
)
286 reg
.fileIndex
= fidx
;
289 prog
->add(this, this->id
);
293 Symbol::clone(ClonePolicy
<Function
>& pol
) const
295 Program
*prog
= pol
.context()->getProgram();
297 Symbol
*that
= new_Symbol(prog
, reg
.file
, reg
.fileIndex
);
299 pol
.set
<Value
>(this, that
);
301 that
->reg
.size
= this->reg
.size
;
302 that
->reg
.type
= this->reg
.type
;
303 that
->reg
.data
= this->reg
.data
;
305 that
->baseSym
= this->baseSym
;
311 Symbol::isUniform() const
314 reg
.file
!= FILE_SYSTEM_VALUE
&&
315 reg
.file
!= FILE_MEMORY_LOCAL
&&
316 reg
.file
!= FILE_SHADER_INPUT
;
319 ImmediateValue::ImmediateValue(Program
*prog
, uint32_t uval
)
321 memset(®
, 0, sizeof(reg
));
323 reg
.file
= FILE_IMMEDIATE
;
329 prog
->add(this, this->id
);
332 ImmediateValue::ImmediateValue(Program
*prog
, float fval
)
334 memset(®
, 0, sizeof(reg
));
336 reg
.file
= FILE_IMMEDIATE
;
342 prog
->add(this, this->id
);
345 ImmediateValue::ImmediateValue(Program
*prog
, double dval
)
347 memset(®
, 0, sizeof(reg
));
349 reg
.file
= FILE_IMMEDIATE
;
355 prog
->add(this, this->id
);
358 ImmediateValue::ImmediateValue(const ImmediateValue
*proto
, DataType ty
)
363 reg
.size
= typeSizeof(ty
);
367 ImmediateValue::clone(ClonePolicy
<Function
>& pol
) const
369 Program
*prog
= pol
.context()->getProgram();
370 ImmediateValue
*that
= new_ImmediateValue(prog
, 0u);
372 pol
.set
<Value
>(this, that
);
374 that
->reg
.size
= this->reg
.size
;
375 that
->reg
.type
= this->reg
.type
;
376 that
->reg
.data
= this->reg
.data
;
382 ImmediateValue::isInteger(const int i
) const
386 return reg
.data
.s8
== i
;
388 return reg
.data
.u8
== i
;
390 return reg
.data
.s16
== i
;
392 return reg
.data
.u16
== i
;
395 return reg
.data
.s32
== i
; // as if ...
398 return reg
.data
.s64
== i
; // as if ...
400 return reg
.data
.f32
== static_cast<float>(i
);
402 return reg
.data
.f64
== static_cast<double>(i
);
409 ImmediateValue::isNegative() const
412 case TYPE_S8
: return reg
.data
.s8
< 0;
413 case TYPE_S16
: return reg
.data
.s16
< 0;
415 case TYPE_U32
: return reg
.data
.s32
< 0;
416 case TYPE_F32
: return reg
.data
.u32
& (1 << 31);
417 case TYPE_F64
: return reg
.data
.u64
& (1ULL << 63);
424 ImmediateValue::isPow2() const
426 if (reg
.type
== TYPE_U64
|| reg
.type
== TYPE_S64
)
427 return util_is_power_of_two_or_zero64(reg
.data
.u64
);
429 return util_is_power_of_two_or_zero(reg
.data
.u32
);
433 ImmediateValue::applyLog2()
439 assert(!this->isNegative());
444 reg
.data
.u32
= util_logbase2(reg
.data
.u32
);
447 assert(!this->isNegative());
450 reg
.data
.u64
= util_logbase2_64(reg
.data
.u64
);
453 reg
.data
.f32
= log2f(reg
.data
.f32
);
456 reg
.data
.f64
= log2(reg
.data
.f64
);
465 ImmediateValue::compare(CondCode cc
, float fval
) const
467 if (reg
.type
!= TYPE_F32
)
468 ERROR("immediate value is not of type f32");
470 switch (static_cast<CondCode
>(cc
& 7)) {
471 case CC_TR
: return true;
472 case CC_FL
: return false;
473 case CC_LT
: return reg
.data
.f32
< fval
;
474 case CC_LE
: return reg
.data
.f32
<= fval
;
475 case CC_GT
: return reg
.data
.f32
> fval
;
476 case CC_GE
: return reg
.data
.f32
>= fval
;
477 case CC_EQ
: return reg
.data
.f32
== fval
;
478 case CC_NE
: return reg
.data
.f32
!= fval
;
486 ImmediateValue::operator=(const ImmediateValue
&that
)
488 this->reg
= that
.reg
;
493 Value::interfers(const Value
*that
) const
497 if (that
->reg
.file
!= reg
.file
|| that
->reg
.fileIndex
!= reg
.fileIndex
)
503 idA
= this->join
->reg
.data
.offset
;
504 idB
= that
->join
->reg
.data
.offset
;
506 idA
= this->join
->reg
.data
.id
* MIN2(this->reg
.size
, 4);
507 idB
= that
->join
->reg
.data
.id
* MIN2(that
->reg
.size
, 4);
511 return (idA
+ this->reg
.size
> idB
);
514 return (idB
+ that
->reg
.size
> idA
);
520 Value::equals(const Value
*that
, bool strict
) const
525 if (that
->reg
.file
!= reg
.file
|| that
->reg
.fileIndex
!= reg
.fileIndex
)
527 if (that
->reg
.size
!= this->reg
.size
)
530 if (that
->reg
.data
.id
!= this->reg
.data
.id
)
537 ImmediateValue::equals(const Value
*that
, bool strict
) const
539 const ImmediateValue
*imm
= that
->asImm();
542 return reg
.data
.u64
== imm
->reg
.data
.u64
;
546 Symbol::equals(const Value
*that
, bool strict
) const
548 if (reg
.file
!= that
->reg
.file
|| reg
.fileIndex
!= that
->reg
.fileIndex
)
550 assert(that
->asSym());
552 if (this->baseSym
!= that
->asSym()->baseSym
)
555 if (reg
.file
== FILE_SYSTEM_VALUE
)
556 return (this->reg
.data
.sv
.sv
== that
->reg
.data
.sv
.sv
&&
557 this->reg
.data
.sv
.index
== that
->reg
.data
.sv
.index
);
558 return this->reg
.data
.offset
== that
->reg
.data
.offset
;
561 void Instruction::init()
592 Instruction::Instruction()
597 dType
= sType
= TYPE_F32
;
603 Instruction::Instruction(Function
*fn
, operation opr
, DataType ty
)
613 Instruction::~Instruction()
616 Function
*fn
= bb
->getFunction();
618 fn
->allInsns
.remove(id
);
621 for (int s
= 0; srcExists(s
); ++s
)
623 // must unlink defs too since the list pointers will get deallocated
624 for (int d
= 0; defExists(d
); ++d
)
629 Instruction::setDef(int i
, Value
*val
)
631 int size
= defs
.size();
635 defs
[size
++].setInsn(this);
641 Instruction::setSrc(int s
, Value
*val
)
643 int size
= srcs
.size();
647 srcs
[size
++].setInsn(this);
653 Instruction::setSrc(int s
, const ValueRef
& ref
)
655 setSrc(s
, ref
.get());
656 srcs
[s
].mod
= ref
.mod
;
660 Instruction::swapSources(int a
, int b
)
662 Value
*value
= srcs
[a
].get();
663 Modifier m
= srcs
[a
].mod
;
671 static inline void moveSourcesAdjustIndex(int8_t &index
, int s
, int delta
)
676 if ((delta
< 0) && (index
>= (s
+ delta
)))
680 // Moves sources [@s,last_source] by @delta.
681 // If @delta < 0, sources [@s - abs(@delta), @s) are erased.
683 Instruction::moveSources(const int s
, const int delta
)
687 assert(s
+ delta
>= 0);
691 for (k
= 0; srcExists(k
); ++k
) {
692 for (int i
= 0; i
< 2; ++i
)
693 moveSourcesAdjustIndex(src(k
).indirect
[i
], s
, delta
);
695 moveSourcesAdjustIndex(predSrc
, s
, delta
);
696 moveSourcesAdjustIndex(flagsSrc
, s
, delta
);
698 TexInstruction
*tex
= asTex();
699 moveSourcesAdjustIndex(tex
->tex
.rIndirectSrc
, s
, delta
);
700 moveSourcesAdjustIndex(tex
->tex
.sIndirectSrc
, s
, delta
);
705 for (int p
= k
+ delta
; k
>= s
; --k
, --p
)
709 for (p
= s
; p
< k
; ++p
)
710 setSrc(p
+ delta
, src(p
));
711 for (; (p
+ delta
) < k
; ++p
)
712 setSrc(p
+ delta
, NULL
);
717 Instruction::takeExtraSources(int s
, Value
*values
[3])
719 values
[0] = getIndirect(s
, 0);
721 setIndirect(s
, 0, NULL
);
723 values
[1] = getIndirect(s
, 1);
725 setIndirect(s
, 1, NULL
);
727 values
[2] = getPredicate();
729 setPredicate(cc
, NULL
);
733 Instruction::putExtraSources(int s
, Value
*values
[3])
736 setIndirect(s
, 0, values
[0]);
738 setIndirect(s
, 1, values
[1]);
740 setPredicate(cc
, values
[2]);
744 Instruction::clone(ClonePolicy
<Function
>& pol
, Instruction
*i
) const
747 i
= new_Instruction(pol
.context(), op
, dType
);
748 #ifndef NDEBUG // non-conformant assert, so this is required
749 assert(typeid(*i
) == typeid(*this));
752 pol
.set
<Instruction
>(this, i
);
760 i
->saturate
= saturate
;
768 i
->perPatch
= perPatch
;
770 i
->postFactor
= postFactor
;
772 for (int d
= 0; defExists(d
); ++d
)
773 i
->setDef(d
, pol
.get(getDef(d
)));
775 for (int s
= 0; srcExists(s
); ++s
) {
776 i
->setSrc(s
, pol
.get(getSrc(s
)));
777 i
->src(s
).mod
= src(s
).mod
;
781 i
->predSrc
= predSrc
;
782 i
->flagsDef
= flagsDef
;
783 i
->flagsSrc
= flagsSrc
;
789 Instruction::defCount(unsigned int mask
, bool singleFile
) const
794 unsigned int d
= ffs(mask
);
797 for (i
= d
--; defExists(i
); ++i
)
798 if (getDef(i
)->reg
.file
!= getDef(d
)->reg
.file
)
802 for (n
= 0, i
= 0; this->defExists(i
); ++i
, mask
>>= 1)
808 Instruction::srcCount(unsigned int mask
, bool singleFile
) const
813 unsigned int s
= ffs(mask
);
816 for (i
= s
--; srcExists(i
); ++i
)
817 if (getSrc(i
)->reg
.file
!= getSrc(s
)->reg
.file
)
821 for (n
= 0, i
= 0; this->srcExists(i
); ++i
, mask
>>= 1)
827 Instruction::setIndirect(int s
, int dim
, Value
*value
)
829 assert(this->srcExists(s
));
831 int p
= srcs
[s
].indirect
[dim
];
836 while (p
> 0 && !srcExists(p
- 1))
840 srcs
[p
].usedAsPtr
= (value
!= 0);
841 srcs
[s
].indirect
[dim
] = value
? p
: -1;
846 Instruction::setPredicate(CondCode ccode
, Value
*value
)
852 srcs
[predSrc
].set(NULL
);
859 predSrc
= srcs
.size();
860 while (predSrc
> 0 && !srcExists(predSrc
- 1))
864 setSrc(predSrc
, value
);
869 Instruction::writesPredicate() const
871 for (int d
= 0; defExists(d
); ++d
)
872 if (getDef(d
)->inFile(FILE_PREDICATE
) || getDef(d
)->inFile(FILE_FLAGS
))
878 Instruction::canCommuteDefSrc(const Instruction
*i
) const
880 for (int d
= 0; defExists(d
); ++d
)
881 for (int s
= 0; i
->srcExists(s
); ++s
)
882 if (getDef(d
)->interfers(i
->getSrc(s
)))
888 Instruction::canCommuteDefDef(const Instruction
*i
) const
890 for (int d
= 0; defExists(d
); ++d
)
891 for (int c
= 0; i
->defExists(c
); ++c
)
892 if (getDef(d
)->interfers(i
->getDef(c
)))
898 Instruction::isCommutationLegal(const Instruction
*i
) const
900 return canCommuteDefDef(i
) &&
901 canCommuteDefSrc(i
) &&
902 i
->canCommuteDefSrc(this);
905 TexInstruction::TexInstruction(Function
*fn
, operation op
)
906 : Instruction(fn
, op
, TYPE_F32
)
908 memset(&tex
, 0, sizeof(tex
));
910 tex
.rIndirectSrc
= -1;
911 tex
.sIndirectSrc
= -1;
917 TexInstruction::~TexInstruction()
919 for (int c
= 0; c
< 3; ++c
) {
923 for (int n
= 0; n
< 4; ++n
)
924 for (int c
= 0; c
< 3; ++c
)
925 offset
[n
][c
].set(NULL
);
929 TexInstruction::clone(ClonePolicy
<Function
>& pol
, Instruction
*i
) const
931 TexInstruction
*tex
= (i
? static_cast<TexInstruction
*>(i
) :
932 new_TexInstruction(pol
.context(), op
));
934 Instruction::clone(pol
, tex
);
936 tex
->tex
= this->tex
;
939 for (unsigned int c
= 0; c
< tex
->tex
.target
.getDim(); ++c
) {
940 tex
->dPdx
[c
].set(dPdx
[c
]);
941 tex
->dPdy
[c
].set(dPdy
[c
]);
945 for (int n
= 0; n
< tex
->tex
.useOffsets
; ++n
)
946 for (int c
= 0; c
< 3; ++c
)
947 tex
->offset
[n
][c
].set(offset
[n
][c
]);
952 const struct TexInstruction::Target::Desc
TexInstruction::Target::descTable
[] =
954 { "1D", 1, 1, false, false, false },
955 { "2D", 2, 2, false, false, false },
956 { "2D_MS", 2, 3, false, false, false },
957 { "3D", 3, 3, false, false, false },
958 { "CUBE", 2, 3, false, true, false },
959 { "1D_SHADOW", 1, 1, false, false, true },
960 { "2D_SHADOW", 2, 2, false, false, true },
961 { "CUBE_SHADOW", 2, 3, false, true, true },
962 { "1D_ARRAY", 1, 2, true, false, false },
963 { "2D_ARRAY", 2, 3, true, false, false },
964 { "2D_MS_ARRAY", 2, 4, true, false, false },
965 { "CUBE_ARRAY", 2, 4, true, true, false },
966 { "1D_ARRAY_SHADOW", 1, 2, true, false, true },
967 { "2D_ARRAY_SHADOW", 2, 3, true, false, true },
968 { "RECT", 2, 2, false, false, false },
969 { "RECT_SHADOW", 2, 2, false, false, true },
970 { "CUBE_ARRAY_SHADOW", 2, 4, true, true, true },
971 { "BUFFER", 1, 1, false, false, false },
974 const struct TexInstruction::ImgFormatDesc
TexInstruction::formatTable
[] =
976 { "NONE", 0, { 0, 0, 0, 0 }, UINT
},
978 { "RGBA32F", 4, { 32, 32, 32, 32 }, FLOAT
},
979 { "RGBA16F", 4, { 16, 16, 16, 16 }, FLOAT
},
980 { "RG32F", 2, { 32, 32, 0, 0 }, FLOAT
},
981 { "RG16F", 2, { 16, 16, 0, 0 }, FLOAT
},
982 { "R11G11B10F", 3, { 11, 11, 10, 0 }, FLOAT
},
983 { "R32F", 1, { 32, 0, 0, 0 }, FLOAT
},
984 { "R16F", 1, { 16, 0, 0, 0 }, FLOAT
},
986 { "RGBA32UI", 4, { 32, 32, 32, 32 }, UINT
},
987 { "RGBA16UI", 4, { 16, 16, 16, 16 }, UINT
},
988 { "RGB10A2UI", 4, { 10, 10, 10, 2 }, UINT
},
989 { "RGBA8UI", 4, { 8, 8, 8, 8 }, UINT
},
990 { "RG32UI", 2, { 32, 32, 0, 0 }, UINT
},
991 { "RG16UI", 2, { 16, 16, 0, 0 }, UINT
},
992 { "RG8UI", 2, { 8, 8, 0, 0 }, UINT
},
993 { "R32UI", 1, { 32, 0, 0, 0 }, UINT
},
994 { "R16UI", 1, { 16, 0, 0, 0 }, UINT
},
995 { "R8UI", 1, { 8, 0, 0, 0 }, UINT
},
997 { "RGBA32I", 4, { 32, 32, 32, 32 }, SINT
},
998 { "RGBA16I", 4, { 16, 16, 16, 16 }, SINT
},
999 { "RGBA8I", 4, { 8, 8, 8, 8 }, SINT
},
1000 { "RG32I", 2, { 32, 32, 0, 0 }, SINT
},
1001 { "RG16I", 2, { 16, 16, 0, 0 }, SINT
},
1002 { "RG8I", 2, { 8, 8, 0, 0 }, SINT
},
1003 { "R32I", 1, { 32, 0, 0, 0 }, SINT
},
1004 { "R16I", 1, { 16, 0, 0, 0 }, SINT
},
1005 { "R8I", 1, { 8, 0, 0, 0 }, SINT
},
1007 { "RGBA16", 4, { 16, 16, 16, 16 }, UNORM
},
1008 { "RGB10A2", 4, { 10, 10, 10, 2 }, UNORM
},
1009 { "RGBA8", 4, { 8, 8, 8, 8 }, UNORM
},
1010 { "RG16", 2, { 16, 16, 0, 0 }, UNORM
},
1011 { "RG8", 2, { 8, 8, 0, 0 }, UNORM
},
1012 { "R16", 1, { 16, 0, 0, 0 }, UNORM
},
1013 { "R8", 1, { 8, 0, 0, 0 }, UNORM
},
1015 { "RGBA16_SNORM", 4, { 16, 16, 16, 16 }, SNORM
},
1016 { "RGBA8_SNORM", 4, { 8, 8, 8, 8 }, SNORM
},
1017 { "RG16_SNORM", 2, { 16, 16, 0, 0 }, SNORM
},
1018 { "RG8_SNORM", 2, { 8, 8, 0, 0 }, SNORM
},
1019 { "R16_SNORM", 1, { 16, 0, 0, 0 }, SNORM
},
1020 { "R8_SNORM", 1, { 8, 0, 0, 0 }, SNORM
},
1022 { "BGRA8", 4, { 8, 8, 8, 8 }, UNORM
, true },
1026 TexInstruction::setIndirectR(Value
*v
)
1028 int p
= ((tex
.rIndirectSrc
< 0) && v
) ? srcs
.size() : tex
.rIndirectSrc
;
1030 tex
.rIndirectSrc
= p
;
1032 srcs
[p
].usedAsPtr
= !!v
;
1037 TexInstruction::setIndirectS(Value
*v
)
1039 int p
= ((tex
.sIndirectSrc
< 0) && v
) ? srcs
.size() : tex
.sIndirectSrc
;
1041 tex
.sIndirectSrc
= p
;
1043 srcs
[p
].usedAsPtr
= !!v
;
1047 CmpInstruction::CmpInstruction(Function
*fn
, operation op
)
1048 : Instruction(fn
, op
, TYPE_F32
)
1050 setCond
= CC_ALWAYS
;
1054 CmpInstruction::clone(ClonePolicy
<Function
>& pol
, Instruction
*i
) const
1056 CmpInstruction
*cmp
= (i
? static_cast<CmpInstruction
*>(i
) :
1057 new_CmpInstruction(pol
.context(), op
));
1059 Instruction::clone(pol
, cmp
);
1060 cmp
->setCond
= setCond
;
1064 FlowInstruction::FlowInstruction(Function
*fn
, operation op
, void *targ
)
1065 : Instruction(fn
, op
, TYPE_NONE
)
1068 target
.fn
= reinterpret_cast<Function
*>(targ
);
1070 target
.bb
= reinterpret_cast<BasicBlock
*>(targ
);
1073 op
== OP_CONT
|| op
== OP_BREAK
||
1074 op
== OP_RET
|| op
== OP_EXIT
)
1078 terminator
= targ
? 1 : 0;
1080 allWarp
= absolute
= limit
= builtin
= indirect
= 0;
1084 FlowInstruction::clone(ClonePolicy
<Function
>& pol
, Instruction
*i
) const
1086 FlowInstruction
*flow
= (i
? static_cast<FlowInstruction
*>(i
) :
1087 new_FlowInstruction(pol
.context(), op
, NULL
));
1089 Instruction::clone(pol
, flow
);
1090 flow
->allWarp
= allWarp
;
1091 flow
->absolute
= absolute
;
1092 flow
->limit
= limit
;
1093 flow
->builtin
= builtin
;
1096 flow
->target
.builtin
= target
.builtin
;
1099 flow
->target
.fn
= target
.fn
;
1102 flow
->target
.bb
= pol
.get
<BasicBlock
>(target
.bb
);
1107 Program::Program(Type type
, Target
*arch
)
1110 mem_Instruction(sizeof(Instruction
), 6),
1111 mem_CmpInstruction(sizeof(CmpInstruction
), 4),
1112 mem_TexInstruction(sizeof(TexInstruction
), 4),
1113 mem_FlowInstruction(sizeof(FlowInstruction
), 4),
1114 mem_LValue(sizeof(LValue
), 8),
1115 mem_Symbol(sizeof(Symbol
), 7),
1116 mem_ImmediateValue(sizeof(ImmediateValue
), 7)
1123 main
= new Function(this, "MAIN", ~0);
1124 calls
.insert(&main
->call
);
1134 for (ArrayList::Iterator it
= allFuncs
.iterator(); !it
.end(); it
.next())
1135 delete reinterpret_cast<Function
*>(it
.get());
1137 for (ArrayList::Iterator it
= allRValues
.iterator(); !it
.end(); it
.next())
1138 releaseValue(reinterpret_cast<Value
*>(it
.get()));
1141 void Program::releaseInstruction(Instruction
*insn
)
1143 // TODO: make this not suck so much
1145 insn
->~Instruction();
1148 mem_CmpInstruction
.release(insn
);
1151 mem_TexInstruction
.release(insn
);
1154 mem_FlowInstruction
.release(insn
);
1156 mem_Instruction
.release(insn
);
1159 void Program::releaseValue(Value
*value
)
1163 if (value
->asLValue())
1164 mem_LValue
.release(value
);
1167 mem_ImmediateValue
.release(value
);
1170 mem_Symbol
.release(value
);
1174 } // namespace nv50_ir
1179 nv50_ir_init_prog_info(struct nv50_ir_prog_info
*info
)
1181 if (info
->type
== PIPE_SHADER_TESS_CTRL
|| info
->type
== PIPE_SHADER_TESS_EVAL
) {
1182 info
->prop
.tp
.domain
= PIPE_PRIM_MAX
;
1183 info
->prop
.tp
.outputPrim
= PIPE_PRIM_MAX
;
1185 if (info
->type
== PIPE_SHADER_GEOMETRY
) {
1186 info
->prop
.gp
.instanceCount
= 1;
1187 info
->prop
.gp
.maxVertices
= 1;
1189 if (info
->type
== PIPE_SHADER_COMPUTE
) {
1190 info
->prop
.cp
.numThreads
[0] =
1191 info
->prop
.cp
.numThreads
[1] =
1192 info
->prop
.cp
.numThreads
[2] = 1;
1194 info
->io
.pointSize
= 0xff;
1195 info
->io
.instanceId
= 0xff;
1196 info
->io
.vertexId
= 0xff;
1197 info
->io
.edgeFlagIn
= 0xff;
1198 info
->io
.edgeFlagOut
= 0xff;
1199 info
->io
.fragDepth
= 0xff;
1200 info
->io
.sampleMask
= 0xff;
1201 info
->io
.backFaceColor
[0] = info
->io
.backFaceColor
[1] = 0xff;
1205 nv50_ir_generate_code(struct nv50_ir_prog_info
*info
)
1209 nv50_ir::Program::Type type
;
1211 nv50_ir_init_prog_info(info
);
1213 #define PROG_TYPE_CASE(a, b) \
1214 case PIPE_SHADER_##a: type = nv50_ir::Program::TYPE_##b; break
1216 switch (info
->type
) {
1217 PROG_TYPE_CASE(VERTEX
, VERTEX
);
1218 PROG_TYPE_CASE(TESS_CTRL
, TESSELLATION_CONTROL
);
1219 PROG_TYPE_CASE(TESS_EVAL
, TESSELLATION_EVAL
);
1220 PROG_TYPE_CASE(GEOMETRY
, GEOMETRY
);
1221 PROG_TYPE_CASE(FRAGMENT
, FRAGMENT
);
1222 PROG_TYPE_CASE(COMPUTE
, COMPUTE
);
1224 INFO_DBG(info
->dbgFlags
, VERBOSE
, "unsupported program type %u\n", info
->type
);
1227 INFO_DBG(info
->dbgFlags
, VERBOSE
, "translating program of type %u\n", type
);
1229 nv50_ir::Target
*targ
= nv50_ir::Target::create(info
->target
);
1233 nv50_ir::Program
*prog
= new nv50_ir::Program(type
, targ
);
1235 nv50_ir::Target::destroy(targ
);
1238 prog
->driver
= info
;
1239 prog
->dbgFlags
= info
->dbgFlags
;
1240 prog
->optLevel
= info
->optLevel
;
1242 switch (info
->bin
.sourceRep
) {
1243 case PIPE_SHADER_IR_TGSI
:
1244 ret
= prog
->makeFromTGSI(info
) ? 0 : -2;
1252 if (prog
->dbgFlags
& NV50_IR_DEBUG_VERBOSE
)
1255 targ
->parseDriverInfo(info
);
1256 prog
->getTarget()->runLegalizePass(prog
, nv50_ir::CG_STAGE_PRE_SSA
);
1258 prog
->convertToSSA();
1260 if (prog
->dbgFlags
& NV50_IR_DEBUG_VERBOSE
)
1263 prog
->optimizeSSA(info
->optLevel
);
1264 prog
->getTarget()->runLegalizePass(prog
, nv50_ir::CG_STAGE_SSA
);
1266 if (prog
->dbgFlags
& NV50_IR_DEBUG_BASIC
)
1269 if (!prog
->registerAllocation()) {
1273 prog
->getTarget()->runLegalizePass(prog
, nv50_ir::CG_STAGE_POST_RA
);
1275 prog
->optimizePostRA(info
->optLevel
);
1277 if (!prog
->emitBinary(info
)) {
1283 INFO_DBG(prog
->dbgFlags
, VERBOSE
, "nv50_ir_generate_code: ret = %i\n", ret
);
1285 info
->bin
.maxGPR
= prog
->maxGPR
;
1286 info
->bin
.code
= prog
->code
;
1287 info
->bin
.codeSize
= prog
->binSize
;
1288 info
->bin
.tlsSpace
= prog
->tlsSize
;
1291 nv50_ir::Target::destroy(targ
);