mirror of
https://github.com/yuzu-emu/sirit.git
synced 2024-12-22 19:25:39 +00:00
Remove Emit entry in favor of auto-emitting code
All instructions but OpVariable and OpLabel are automatically emitted. These functions have to call AddLocalVariable/AddGlobalVariable or AddLabel respectively.
This commit is contained in:
parent
8cf3d225db
commit
42248408a9
|
@ -70,12 +70,26 @@ public:
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds an instruction to module's code
|
||||
* @param op Instruction to insert into code. Types and constants must not
|
||||
* be emitted.
|
||||
* @return Returns op.
|
||||
* Adds an existing label to the code
|
||||
* @param label Label to insert into code.
|
||||
* @return Returns label.
|
||||
*/
|
||||
Id Emit(Id op);
|
||||
Id AddLabel(Id label);
|
||||
|
||||
/**
|
||||
* Adds a label to the code
|
||||
* @return Returns the created label.
|
||||
*/
|
||||
Id AddLabel() {
|
||||
return AddLabel(OpLabel());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a local variable to the code
|
||||
* @param variable Variable to insert into code.
|
||||
* @return Returns variable.
|
||||
*/
|
||||
Id AddLocalVariable(Id label);
|
||||
|
||||
/**
|
||||
* Adds a global variable
|
||||
|
|
|
@ -30,7 +30,7 @@ Id Module::OpSelectionMerge(Id merge_block, spv::SelectionControlMask selection_
|
|||
}
|
||||
|
||||
Id Module::OpLabel() {
|
||||
return AddCode(spv::Op::OpLabel, bound++);
|
||||
return code_store.emplace_back(std::make_unique<Op>(spv::Op::OpLabel, bound++)).get();
|
||||
}
|
||||
|
||||
Id Module::OpBranch(Id target_label) {
|
||||
|
|
|
@ -16,7 +16,7 @@ Id Module::OpVariable(Id result_type, spv::StorageClass storage_class, Id initia
|
|||
if (initializer) {
|
||||
op->Add(initializer);
|
||||
}
|
||||
return AddCode(std::move(op));
|
||||
return code_store.emplace_back(std::move(op)).get();
|
||||
}
|
||||
|
||||
Id Module::OpLoad(Id result_type, Id pointer, std::optional<spv::MemoryAccessMask> memory_access) {
|
||||
|
|
|
@ -98,22 +98,24 @@ void Module::AddExecutionMode(Id entry_point, spv::ExecutionMode mode,
|
|||
execution_modes.push_back(std::move(op));
|
||||
}
|
||||
|
||||
Id Module::Emit(Id op) {
|
||||
assert(op != nullptr);
|
||||
code.push_back(op);
|
||||
return op;
|
||||
Id Module::AddLabel(Id label) {
|
||||
assert(label != nullptr);
|
||||
return code.emplace_back(label);
|
||||
}
|
||||
|
||||
Id Module::AddLocalVariable(Id variable) {
|
||||
assert(variable != nullptr);
|
||||
return code.emplace_back(variable);
|
||||
}
|
||||
|
||||
Id Module::AddGlobalVariable(Id variable) {
|
||||
assert(variable);
|
||||
global_variables.push_back(variable);
|
||||
return variable;
|
||||
return global_variables.emplace_back(variable);
|
||||
}
|
||||
|
||||
Id Module::AddCode(std::unique_ptr<Op> op) {
|
||||
const auto id = op.get();
|
||||
code_store.push_back(std::move(op));
|
||||
return id;
|
||||
const Id id = code_store.emplace_back(std::move(op)).get();
|
||||
return code.emplace_back(id);
|
||||
}
|
||||
|
||||
Id Module::AddCode(spv::Op opcode, std::optional<u32> id) {
|
||||
|
|
|
@ -46,30 +46,30 @@ public:
|
|||
AddGlobalVariable(in_pos);
|
||||
AddGlobalVariable(per_vertex);
|
||||
|
||||
const auto main_func = Emit(
|
||||
const auto main_func =
|
||||
Name(OpFunction(t_void, spv::FunctionControlMask::MaskNone, TypeFunction(t_void)),
|
||||
"main"));
|
||||
Emit(OpLabel());
|
||||
"main");
|
||||
AddLabel();
|
||||
|
||||
const auto ptr_pos_x = Emit(OpAccessChain(in_float, in_pos, Constant(t_uint, 0u)));
|
||||
const auto ptr_pos_y = Emit(OpAccessChain(in_float, in_pos, Constant(t_uint, 1u)));
|
||||
const auto ptr_pos_x = OpAccessChain(in_float, in_pos, Constant(t_uint, 0u));
|
||||
const auto ptr_pos_y = OpAccessChain(in_float, in_pos, Constant(t_uint, 1u));
|
||||
|
||||
const auto pos_x = Emit(OpLoad(t_float, ptr_pos_x));
|
||||
const auto pos_y = Emit(OpLoad(t_float, ptr_pos_y));
|
||||
const auto pos_x = OpLoad(t_float, ptr_pos_x);
|
||||
const auto pos_y = OpLoad(t_float, ptr_pos_y);
|
||||
|
||||
auto tmp_position = Emit(OpUndef(float4));
|
||||
auto tmp_position = OpUndef(float4);
|
||||
Decorate(tmp_position, spv::Decoration::FPRoundingMode,
|
||||
static_cast<u32>(spv::FPRoundingMode::RTE));
|
||||
tmp_position = Emit(OpCompositeInsert(float4, pos_x, tmp_position, 0));
|
||||
tmp_position = Emit(OpCompositeInsert(float4, pos_y, tmp_position, 1));
|
||||
tmp_position = Emit(OpCompositeInsert(float4, Constant(t_float, 0.f), tmp_position, 2));
|
||||
tmp_position = Emit(OpCompositeInsert(float4, Constant(t_float, 1.f), tmp_position, 3));
|
||||
tmp_position = OpCompositeInsert(float4, pos_x, tmp_position, 0);
|
||||
tmp_position = OpCompositeInsert(float4, pos_y, tmp_position, 1);
|
||||
tmp_position = OpCompositeInsert(float4, Constant(t_float, 0.f), tmp_position, 2);
|
||||
tmp_position = OpCompositeInsert(float4, Constant(t_float, 1.f), tmp_position, 3);
|
||||
|
||||
const auto gl_position = Emit(OpAccessChain(out_float4, per_vertex, Constant(t_uint, 0u)));
|
||||
Emit(OpStore(gl_position, tmp_position));
|
||||
const auto gl_position = OpAccessChain(out_float4, per_vertex, Constant(t_uint, 0u));
|
||||
OpStore(gl_position, tmp_position);
|
||||
|
||||
Emit(OpReturn());
|
||||
Emit(OpFunctionEnd());
|
||||
OpReturn();
|
||||
OpFunctionEnd();
|
||||
|
||||
AddEntryPoint(spv::ExecutionModel::Vertex, main_func, "main", in_pos, per_vertex);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue