Commit 2060866e by Nicolas Capens Committed by Nicolas Capens

Implement implicit casting support for constructors.

BUG=15415045 Change-Id: Ib6ec56f545ff37b5711bdf22bca1b33429521937 Reviewed-on: https://swiftshader-review.googlesource.com/1111Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent a582b31d
...@@ -707,8 +707,8 @@ namespace sh ...@@ -707,8 +707,8 @@ namespace sh
case EOpFunctionCall: case EOpFunctionCall:
if(visit == PostVisit) if(visit == PostVisit)
{ {
if(node->isUserDefined()) if(node->isUserDefined())
{ {
const TString &name = node->getName(); const TString &name = node->getName();
const Function &function = findFunction(name); const Function &function = findFunction(name);
TIntermSequence &arguments = *function.arg; TIntermSequence &arguments = *function.arg;
...@@ -716,7 +716,7 @@ namespace sh ...@@ -716,7 +716,7 @@ namespace sh
for(int i = 0; i < argumentCount; i++) for(int i = 0; i < argumentCount; i++)
{ {
TIntermTyped *in = arguments[i]->getAsTyped(); TIntermTyped *in = arguments[i]->getAsTyped();
if(in->getQualifier() == EvqIn || if(in->getQualifier() == EvqIn ||
in->getQualifier() == EvqInOut || in->getQualifier() == EvqInOut ||
in->getQualifier() == EvqConstReadOnly) in->getQualifier() == EvqConstReadOnly)
...@@ -769,10 +769,10 @@ namespace sh ...@@ -769,10 +769,10 @@ namespace sh
else UNREACHABLE(); else UNREACHABLE();
} }
else if(name == "texture2DProj") else if(name == "texture2DProj")
{ {
TIntermTyped *t = arg[1]->getAsTyped(); TIntermTyped *t = arg[1]->getAsTyped();
if(argumentCount == 2) if(argumentCount == 2)
{ {
Instruction *tex = emit(sw::Shader::OPCODE_TEX, result, arg[1], arg[0]); Instruction *tex = emit(sw::Shader::OPCODE_TEX, result, arg[1], arg[0]);
tex->project = true; tex->project = true;
...@@ -808,19 +808,19 @@ namespace sh ...@@ -808,19 +808,19 @@ namespace sh
tex->bias = true; tex->bias = true;
} }
else UNREACHABLE(); else UNREACHABLE();
} }
else if(name == "texture2DLod" || name == "textureCubeLod") else if(name == "texture2DLod" || name == "textureCubeLod")
{ {
Temporary uvwb(this); Temporary uvwb(this);
emit(sw::Shader::OPCODE_MOV, &uvwb, arg[1]); emit(sw::Shader::OPCODE_MOV, &uvwb, arg[1]);
Instruction *lod = emit(sw::Shader::OPCODE_MOV, &uvwb, arg[2]); Instruction *lod = emit(sw::Shader::OPCODE_MOV, &uvwb, arg[2]);
lod->dst.mask = 0x8; lod->dst.mask = 0x8;
emit(sw::Shader::OPCODE_TEXLDL, result, &uvwb, arg[0]); emit(sw::Shader::OPCODE_TEXLDL, result, &uvwb, arg[0]);
} }
else if(name == "texture2DProjLod") else if(name == "texture2DProjLod")
{ {
TIntermTyped *t = arg[1]->getAsTyped(); TIntermTyped *t = arg[1]->getAsTyped();
Temporary proj(this); Temporary proj(this);
if(t->getNominalSize() == 3) if(t->getNominalSize() == 3)
...@@ -841,12 +841,13 @@ namespace sh ...@@ -841,12 +841,13 @@ namespace sh
lod->dst.mask = 0x8; lod->dst.mask = 0x8;
emit(sw::Shader::OPCODE_TEXLDL, result, &proj, arg[0]); emit(sw::Shader::OPCODE_TEXLDL, result, &proj, arg[0]);
} }
else UNREACHABLE(); else UNREACHABLE();
} }
} }
break; break;
case EOpParameters: break; case EOpParameters:
break;
case EOpConstructFloat: case EOpConstructFloat:
case EOpConstructVec2: case EOpConstructVec2:
case EOpConstructVec3: case EOpConstructVec3:
...@@ -864,12 +865,12 @@ namespace sh ...@@ -864,12 +865,12 @@ namespace sh
int component = 0; int component = 0;
for(int i = 0; i < argumentCount; i++) for(int i = 0; i < argumentCount; i++)
{ {
TIntermTyped *argi = arg[i]->getAsTyped(); TIntermTyped *argi = arg[i]->getAsTyped();
int size = argi->getNominalSize(); int size = argi->getNominalSize();
ASSERT(!argi->isMatrix()); ASSERT(!argi->isMatrix());
Instruction *mov = emit(sw::Shader::OPCODE_MOV, result, argi); Instruction *mov = emitCast(result, argi);
mov->dst.mask = (0xF << component) & 0xF; mov->dst.mask = (0xF << component) & 0xF;
mov->src[0].swizzle = readSwizzle(argi, size) << (component * 2); mov->src[0].swizzle = readSwizzle(argi, size) << (component * 2);
...@@ -893,13 +894,13 @@ namespace sh ...@@ -893,13 +894,13 @@ namespace sh
{ {
// Initialize to identity matrix // Initialize to identity matrix
Constant col((i == 0 ? 1.0f : 0.0f), (i == 1 ? 1.0f : 0.0f), (i == 2 ? 1.0f : 0.0f), (i == 3 ? 1.0f : 0.0f)); Constant col((i == 0 ? 1.0f : 0.0f), (i == 1 ? 1.0f : 0.0f), (i == 2 ? 1.0f : 0.0f), (i == 3 ? 1.0f : 0.0f));
Instruction *mov = emit(sw::Shader::OPCODE_MOV, result, &col); Instruction *mov = emitCast(result, &col);
mov->dst.index += i; mov->dst.index += i;
} }
if(i < dim2(arg0)) if(i < dim2(arg0))
{ {
Instruction *mov = emit(sw::Shader::OPCODE_MOV, result, arg0); Instruction *mov = emitCast(result, arg0);
mov->dst.index += i; mov->dst.index += i;
mov->dst.mask = 0xF >> (4 - dim2(arg0)); mov->dst.mask = 0xF >> (4 - dim2(arg0));
argument(mov->src[0], arg0, i); argument(mov->src[0], arg0, i);
...@@ -919,11 +920,11 @@ namespace sh ...@@ -919,11 +920,11 @@ namespace sh
while(element < size) while(element < size)
{ {
Instruction *mov = emit(sw::Shader::OPCODE_MOV, result, argi); Instruction *mov = emitCast(result, argi);
mov->dst.index += column; mov->dst.index += column;
mov->dst.mask = (0xF << row) & 0xF; mov->dst.mask = (0xF << row) & 0xF;
mov->src[0].swizzle = (readSwizzle(argi, size) << (row * 2)) + 0x55 * element; mov->src[0].swizzle = (readSwizzle(argi, size) << (row * 2)) + 0x55 * element;
int end = row + size - element; int end = row + size - element;
column = end >= dim ? column + 1 : column; column = end >= dim ? column + 1 : column;
element = element + dim - row; element = element + dim - row;
...@@ -987,7 +988,7 @@ namespace sh ...@@ -987,7 +988,7 @@ namespace sh
ASSERT(dim2(arg[0]) == dim2(arg[1])); ASSERT(dim2(arg[0]) == dim2(arg[1]));
for(int i = 0; i < dim2(arg[0]); i++) for(int i = 0; i < dim2(arg[0]); i++)
{ {
Instruction *mul = emit(sw::Shader::OPCODE_MUL, result, arg[0], arg[1]); Instruction *mul = emit(sw::Shader::OPCODE_MUL, result, arg[0], arg[1]);
mul->dst.index += i; mul->dst.index += i;
argument(mul->src[0], arg[0], i); argument(mul->src[0], arg[0], i);
...@@ -1208,8 +1209,8 @@ namespace sh ...@@ -1208,8 +1209,8 @@ namespace sh
switch(node->getFlowOp()) switch(node->getFlowOp())
{ {
case EOpKill: if(visit == PostVisit) emit(sw::Shader::OPCODE_DISCARD); break; case EOpKill: if(visit == PostVisit) emit(sw::Shader::OPCODE_DISCARD); break;
case EOpBreak: if(visit == PostVisit) emit(sw::Shader::OPCODE_BREAK); break; case EOpBreak: if(visit == PostVisit) emit(sw::Shader::OPCODE_BREAK); break;
case EOpContinue: if(visit == PostVisit) emit(sw::Shader::OPCODE_CONTINUE); break; case EOpContinue: if(visit == PostVisit) emit(sw::Shader::OPCODE_CONTINUE); break;
case EOpReturn: case EOpReturn:
if(visit == PostVisit) if(visit == PostVisit)
...@@ -1256,6 +1257,25 @@ namespace sh ...@@ -1256,6 +1257,25 @@ namespace sh
return instruction; return instruction;
} }
Instruction *OutputASM::emitCast(TIntermTyped *dst, TIntermTyped *src)
{
// Integers are implemented as float
if((dst->getBasicType() == EbtFloat || dst->getBasicType() == EbtInt) && src->getBasicType() == EbtBool)
{
return emit(sw::Shader::OPCODE_B2F, dst, src);
}
if(dst->getBasicType() == EbtBool && (src->getBasicType() == EbtFloat || src->getBasicType() == EbtInt))
{
return emit(sw::Shader::OPCODE_F2B, dst, src);
}
if(dst->getBasicType() == EbtInt && src->getBasicType() == EbtFloat)
{
return emit(sw::Shader::OPCODE_TRUNC, dst, src);
}
return emit(sw::Shader::OPCODE_MOV, dst, src);
}
void OutputASM::emitBinary(sw::Shader::Opcode op, TIntermTyped *dst, TIntermNode *src0, TIntermNode *src1, TIntermNode *src2) void OutputASM::emitBinary(sw::Shader::Opcode op, TIntermTyped *dst, TIntermNode *src0, TIntermNode *src1, TIntermNode *src2)
{ {
for(int index = 0; index < dst->elementRegisterCount(); index++) for(int index = 0; index < dst->elementRegisterCount(); index++)
...@@ -2281,10 +2301,10 @@ namespace sh ...@@ -2281,10 +2301,10 @@ namespace sh
{ {
return GL_SAMPLER_CUBE; return GL_SAMPLER_CUBE;
} }
else if(type.getBasicType() == EbtSamplerExternalOES) else if(type.getBasicType() == EbtSamplerExternalOES)
{ {
return GL_SAMPLER_EXTERNAL_OES; return GL_SAMPLER_EXTERNAL_OES;
} }
else UNREACHABLE(); else UNREACHABLE();
return GL_NONE; return GL_NONE;
...@@ -2382,7 +2402,7 @@ namespace sh ...@@ -2382,7 +2402,7 @@ namespace sh
if(index && node->getCondition()) if(index && node->getCondition())
{ {
TIntermBinary *test = node->getCondition()->getAsBinaryNode(); TIntermBinary *test = node->getCondition()->getAsBinaryNode();
if(test && test->getLeft()->getAsSymbolNode()->getId() == index->getId()) if(test && test->getLeft()->getAsSymbolNode()->getId() == index->getId())
{ {
TIntermConstantUnion *constant = test->getRight()->getAsConstantUnion(); TIntermConstantUnion *constant = test->getRight()->getAsConstantUnion();
...@@ -2403,7 +2423,7 @@ namespace sh ...@@ -2403,7 +2423,7 @@ namespace sh
{ {
TIntermBinary *binaryTerminal = node->getExpression()->getAsBinaryNode(); TIntermBinary *binaryTerminal = node->getExpression()->getAsBinaryNode();
TIntermUnary *unaryTerminal = node->getExpression()->getAsUnaryNode(); TIntermUnary *unaryTerminal = node->getExpression()->getAsUnaryNode();
if(binaryTerminal) if(binaryTerminal)
{ {
TOperator op = binaryTerminal->getOp(); TOperator op = binaryTerminal->getOp();
......
...@@ -107,6 +107,7 @@ namespace sh ...@@ -107,6 +107,7 @@ namespace sh
virtual bool visitBranch(Visit visit, TIntermBranch*); virtual bool visitBranch(Visit visit, TIntermBranch*);
Instruction *emit(sw::Shader::Opcode op, TIntermTyped *dst = 0, TIntermNode *src0 = 0, TIntermNode *src1 = 0, TIntermNode *src2 = 0, int index = 0); Instruction *emit(sw::Shader::Opcode op, TIntermTyped *dst = 0, TIntermNode *src0 = 0, TIntermNode *src1 = 0, TIntermNode *src2 = 0, int index = 0);
Instruction *emitCast(TIntermTyped *dst, TIntermTyped *src);
void emitBinary(sw::Shader::Opcode op, TIntermTyped *dst = 0, TIntermNode *src0 = 0, TIntermNode *src1 = 0, TIntermNode *src2 = 0); void emitBinary(sw::Shader::Opcode op, TIntermTyped *dst = 0, TIntermNode *src0 = 0, TIntermNode *src1 = 0, TIntermNode *src2 = 0);
void emitAssign(sw::Shader::Opcode op, TIntermTyped *result, TIntermTyped *lhs, TIntermTyped *src0, TIntermTyped *src1 = 0); void emitAssign(sw::Shader::Opcode op, TIntermTyped *result, TIntermTyped *lhs, TIntermTyped *src0, TIntermTyped *src1 = 0);
void emitCmp(sw::Shader::Control cmpOp, TIntermTyped *dst, TIntermNode *left, TIntermNode *right, int index = 0); void emitCmp(sw::Shader::Control cmpOp, TIntermTyped *dst, TIntermNode *left, TIntermNode *right, int index = 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment