Commit bc3a0ee9 by Chris Forbes

Add minimal support for integer constants

This is just enough support to be able to handle array sizes, etc. Bug: b/120799499 Change-Id: I790d6accabe55efab9fd5e0c23c93b5d10b72e36 Reviewed-on: https://swiftshader-review.googlesource.com/c/23448Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Tested-by: 's avatarChris Forbes <chrisforbes@google.com>
parent 7ca9f4a0
......@@ -160,6 +160,21 @@ namespace sw
break;
}
case spv::OpConstant:
case spv::OpConstantComposite:
case spv::OpConstantFalse:
case spv::OpConstantTrue:
case spv::OpConstantNull:
{
auto typeId = insn.word(1);
auto resultId = insn.word(2);
auto &object = defs[resultId];
object.kind = Object::Kind::Constant;
object.definition = insn;
object.sizeInComponents = defs[typeId].sizeInComponents;
break;
}
default:
break; // This is OK, these passes are intentionally partial
}
......@@ -409,4 +424,18 @@ namespace sw
Block |= src.Block;
BufferBlock |= src.BufferBlock;
}
uint32_t SpirvShader::GetConstantInt(uint32_t id)
{
// Slightly hackish access to constants very early in translation.
// General consumption of constants by other instructions should
// probably be just lowered to Reactor.
// TODO: not encountered yet since we only use this for array sizes etc,
// but is possible to construct integer constant 0 via OpConstantNull.
auto insn = defs[id].definition;
assert(insn.opcode() == spv::OpConstant);
assert(defs[insn.word(1)].definition.opcode() == spv::OpTypeInt);
return insn.word(3);
}
}
......@@ -109,6 +109,7 @@ namespace sw
Unknown, /* for paranoia -- if we get left with an object in this state, the module was broken */
Type,
Variable,
Constant,
Value,
} kind = Kind::Unknown;
};
......@@ -218,6 +219,8 @@ namespace sw
int PopulateInterfaceInner(std::vector<InterfaceComponent> *iface, uint32_t id, Decorations d);
void PopulateInterface(std::vector<InterfaceComponent> *iface, uint32_t id);
uint32_t GetConstantInt(uint32_t id);
};
}
......
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