Skip to content

Commit

Permalink
SpirvShader: Implement OpSelect
Browse files Browse the repository at this point in the history
Bug: b/126873455
Change-Id: I5df5206cb3743dd7b36d4ad521f9e9ddf81ae638
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/26168
Presubmit-Ready: Chris Forbes <chrisforbes@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Chris Forbes <chrisforbes@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
  • Loading branch information
ben-clayton committed Mar 6, 2019
1 parent ec1aeb8 commit bf943f6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Pipeline/SpirvShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ namespace sw
case spv::OpConvertSToF:
case spv::OpConvertUToF:
case spv::OpBitcast:
case spv::OpSelect:
// Instructions that yield an intermediate value
{
TypeID typeId = insn.word(1);
Expand Down Expand Up @@ -1005,6 +1006,10 @@ namespace sw
EmitDot(insn, routine);
break;

case spv::OpSelect:
EmitSelect(insn, routine);
break;

default:
UNIMPLEMENTED(OpcodeName(insn.opcode()).c_str());
break;
Expand Down Expand Up @@ -1470,6 +1475,24 @@ namespace sw
dst.emplace(0, result);
}

void SpirvShader::EmitSelect(InsnIterator insn, SpirvRoutine *routine) const
{
auto &type = getType(insn.word(1));
auto &dst = routine->createIntermediate(insn.word(2), type.sizeInComponents);
auto srcCond = GenericValue(this, routine, insn.word(3));
auto srcLHS = GenericValue(this, routine, insn.word(4));
auto srcRHS = GenericValue(this, routine, insn.word(5));

for (auto i = 0u; i < type.sizeInComponents; i++)
{
auto cond = As<SIMD::Int>(srcCond[i]);
auto lhs = srcLHS[i];
auto rhs = srcRHS[i];
auto out = (cond & As<Int4>(lhs)) | (~cond & As<Int4>(rhs)); // FIXME: IfThenElse()
dst.emplace(i, As<SIMD::Float>(out));
}
}

void SpirvShader::emitEpilog(SpirvRoutine *routine) const
{
for (auto insn : *this)
Expand Down
1 change: 1 addition & 0 deletions src/Pipeline/SpirvShader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ namespace sw
void EmitUnaryOp(InsnIterator insn, SpirvRoutine *routine) const;
void EmitBinaryOp(InsnIterator insn, SpirvRoutine *routine) const;
void EmitDot(InsnIterator insn, SpirvRoutine *routine) const;
void EmitSelect(InsnIterator insn, SpirvRoutine *routine) const;

// OpcodeName returns the name of the opcode op.
// If NDEBUG is defined, then OpcodeName will only return the numerical code.
Expand Down

0 comments on commit bf943f6

Please sign in to comment.