SPIRV: Add more utility functions to build some opcodes (#2398)
Add more builder functions to OpExecutionMode, OpExecutionModeId, OpDecorateString, OpMemberDecorateString. According to SPIR-V, OpExecutionMode and OpExecutionModeId could take variable extra operands. Current implementation doesn't support this and assumes at most 3 operands are extra operands. It is not true. Similarly, OpDecorateString and OpMemberDecorateString could support multiple strings either as literal strings or as string operands. Further, OpDecorate and OpDecorateId have the same problem, taking variable extra operands.
This commit is contained in:
@@ -1183,6 +1183,28 @@ void Builder::addExecutionMode(Function* entryPoint, ExecutionMode mode, int val
|
||||
executionModes.push_back(std::unique_ptr<Instruction>(instr));
|
||||
}
|
||||
|
||||
void Builder::addExecutionMode(Function* entryPoint, ExecutionMode mode, const std::vector<unsigned>& literals)
|
||||
{
|
||||
Instruction* instr = new Instruction(OpExecutionMode);
|
||||
instr->addIdOperand(entryPoint->getId());
|
||||
instr->addImmediateOperand(mode);
|
||||
for (auto literal : literals)
|
||||
instr->addImmediateOperand(literal);
|
||||
|
||||
executionModes.push_back(std::unique_ptr<Instruction>(instr));
|
||||
}
|
||||
|
||||
void Builder::addExecutionModeId(Function* entryPoint, ExecutionMode mode, const std::vector<Id>& operandIds)
|
||||
{
|
||||
Instruction* instr = new Instruction(OpExecutionModeId);
|
||||
instr->addIdOperand(entryPoint->getId());
|
||||
instr->addImmediateOperand(mode);
|
||||
for (auto operandId : operandIds)
|
||||
instr->addIdOperand(operandId);
|
||||
|
||||
executionModes.push_back(std::unique_ptr<Instruction>(instr));
|
||||
}
|
||||
|
||||
void Builder::addName(Id id, const char* string)
|
||||
{
|
||||
Instruction* name = new Instruction(OpName);
|
||||
@@ -1221,7 +1243,7 @@ void Builder::addDecoration(Id id, Decoration decoration, const char* s)
|
||||
if (decoration == spv::DecorationMax)
|
||||
return;
|
||||
|
||||
Instruction* dec = new Instruction(OpDecorateStringGOOGLE);
|
||||
Instruction* dec = new Instruction(OpDecorateString);
|
||||
dec->addIdOperand(id);
|
||||
dec->addImmediateOperand(decoration);
|
||||
dec->addStringOperand(s);
|
||||
@@ -1229,6 +1251,34 @@ void Builder::addDecoration(Id id, Decoration decoration, const char* s)
|
||||
decorations.push_back(std::unique_ptr<Instruction>(dec));
|
||||
}
|
||||
|
||||
void Builder::addDecoration(Id id, Decoration decoration, const std::vector<unsigned>& literals)
|
||||
{
|
||||
if (decoration == spv::DecorationMax)
|
||||
return;
|
||||
|
||||
Instruction* dec = new Instruction(OpDecorate);
|
||||
dec->addIdOperand(id);
|
||||
dec->addImmediateOperand(decoration);
|
||||
for (auto literal : literals)
|
||||
dec->addImmediateOperand(literal);
|
||||
|
||||
decorations.push_back(std::unique_ptr<Instruction>(dec));
|
||||
}
|
||||
|
||||
void Builder::addDecoration(Id id, Decoration decoration, const std::vector<const char*>& strings)
|
||||
{
|
||||
if (decoration == spv::DecorationMax)
|
||||
return;
|
||||
|
||||
Instruction* dec = new Instruction(OpDecorateString);
|
||||
dec->addIdOperand(id);
|
||||
dec->addImmediateOperand(decoration);
|
||||
for (auto string : strings)
|
||||
dec->addStringOperand(string);
|
||||
|
||||
decorations.push_back(std::unique_ptr<Instruction>(dec));
|
||||
}
|
||||
|
||||
void Builder::addDecorationId(Id id, Decoration decoration, Id idDecoration)
|
||||
{
|
||||
if (decoration == spv::DecorationMax)
|
||||
@@ -1242,6 +1292,21 @@ void Builder::addDecorationId(Id id, Decoration decoration, Id idDecoration)
|
||||
decorations.push_back(std::unique_ptr<Instruction>(dec));
|
||||
}
|
||||
|
||||
void Builder::addDecorationId(Id id, Decoration decoration, const std::vector<Id>& operandIds)
|
||||
{
|
||||
if(decoration == spv::DecorationMax)
|
||||
return;
|
||||
|
||||
Instruction* dec = new Instruction(OpDecorateId);
|
||||
dec->addIdOperand(id);
|
||||
dec->addImmediateOperand(decoration);
|
||||
|
||||
for (auto operandId : operandIds)
|
||||
dec->addIdOperand(operandId);
|
||||
|
||||
decorations.push_back(std::unique_ptr<Instruction>(dec));
|
||||
}
|
||||
|
||||
void Builder::addMemberDecoration(Id id, unsigned int member, Decoration decoration, int num)
|
||||
{
|
||||
if (decoration == spv::DecorationMax)
|
||||
@@ -1271,6 +1336,36 @@ void Builder::addMemberDecoration(Id id, unsigned int member, Decoration decorat
|
||||
decorations.push_back(std::unique_ptr<Instruction>(dec));
|
||||
}
|
||||
|
||||
void Builder::addMemberDecoration(Id id, unsigned int member, Decoration decoration, const std::vector<unsigned>& literals)
|
||||
{
|
||||
if (decoration == spv::DecorationMax)
|
||||
return;
|
||||
|
||||
Instruction* dec = new Instruction(OpMemberDecorate);
|
||||
dec->addIdOperand(id);
|
||||
dec->addImmediateOperand(member);
|
||||
dec->addImmediateOperand(decoration);
|
||||
for (auto literal : literals)
|
||||
dec->addImmediateOperand(literal);
|
||||
|
||||
decorations.push_back(std::unique_ptr<Instruction>(dec));
|
||||
}
|
||||
|
||||
void Builder::addMemberDecoration(Id id, unsigned int member, Decoration decoration, const std::vector<const char*>& strings)
|
||||
{
|
||||
if (decoration == spv::DecorationMax)
|
||||
return;
|
||||
|
||||
Instruction* dec = new Instruction(OpMemberDecorateString);
|
||||
dec->addIdOperand(id);
|
||||
dec->addImmediateOperand(member);
|
||||
dec->addImmediateOperand(decoration);
|
||||
for (auto string : strings)
|
||||
dec->addStringOperand(string);
|
||||
|
||||
decorations.push_back(std::unique_ptr<Instruction>(dec));
|
||||
}
|
||||
|
||||
// Comments in header
|
||||
Function* Builder::makeEntryPoint(const char* entryPoint)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user