[ir][spirv-writer] Emit load instructions
Bug: tint:1906 Change-Id: I86396d0eaa7886f010cf037c2b1253014146d37c Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/133225 Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: James Price <jrprice@google.com> Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
dededb1e5d
commit
92151b238b
|
@ -19,6 +19,7 @@
|
||||||
#include "src/tint/ir/block.h"
|
#include "src/tint/ir/block.h"
|
||||||
#include "src/tint/ir/function_terminator.h"
|
#include "src/tint/ir/function_terminator.h"
|
||||||
#include "src/tint/ir/if.h"
|
#include "src/tint/ir/if.h"
|
||||||
|
#include "src/tint/ir/load.h"
|
||||||
#include "src/tint/ir/module.h"
|
#include "src/tint/ir/module.h"
|
||||||
#include "src/tint/ir/store.h"
|
#include "src/tint/ir/store.h"
|
||||||
#include "src/tint/ir/transform/add_empty_entry_point.h"
|
#include "src/tint/ir/transform/add_empty_entry_point.h"
|
||||||
|
@ -296,6 +297,7 @@ void GeneratorImplIr::EmitBlock(const ir::Block* block) {
|
||||||
auto result = Switch(
|
auto result = Switch(
|
||||||
inst, //
|
inst, //
|
||||||
[&](const ir::Binary* b) { return EmitBinary(b); },
|
[&](const ir::Binary* b) { return EmitBinary(b); },
|
||||||
|
[&](const ir::Load* l) { return EmitLoad(l); },
|
||||||
[&](const ir::Store* s) {
|
[&](const ir::Store* s) {
|
||||||
EmitStore(s);
|
EmitStore(s);
|
||||||
return 0u;
|
return 0u;
|
||||||
|
@ -396,6 +398,12 @@ uint32_t GeneratorImplIr::EmitBinary(const ir::Binary* binary) {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t GeneratorImplIr::EmitLoad(const ir::Load* load) {
|
||||||
|
auto id = module_.NextId();
|
||||||
|
current_function_.push_inst(spv::Op::OpLoad, {Type(load->Type()), id, Value(load->from)});
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
void GeneratorImplIr::EmitStore(const ir::Store* store) {
|
void GeneratorImplIr::EmitStore(const ir::Store* store) {
|
||||||
current_function_.push_inst(spv::Op::OpStore, {Value(store->to), Value(store->from)});
|
current_function_.push_inst(spv::Op::OpStore, {Value(store->to), Value(store->from)});
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ class Binary;
|
||||||
class Block;
|
class Block;
|
||||||
class If;
|
class If;
|
||||||
class Function;
|
class Function;
|
||||||
|
class Load;
|
||||||
class Module;
|
class Module;
|
||||||
class Store;
|
class Store;
|
||||||
class Value;
|
class Value;
|
||||||
|
@ -106,6 +107,11 @@ class GeneratorImplIr {
|
||||||
/// @returns the result ID of the instruction
|
/// @returns the result ID of the instruction
|
||||||
uint32_t EmitBinary(const ir::Binary* binary);
|
uint32_t EmitBinary(const ir::Binary* binary);
|
||||||
|
|
||||||
|
/// Emit a load instruction.
|
||||||
|
/// @param load the load instruction to emit
|
||||||
|
/// @returns the result ID of the instruction
|
||||||
|
uint32_t EmitLoad(const ir::Load* load);
|
||||||
|
|
||||||
/// Emit a store instruction.
|
/// Emit a store instruction.
|
||||||
/// @param store the store instruction to emit
|
/// @param store the store instruction to emit
|
||||||
void EmitStore(const ir::Store* store);
|
void EmitStore(const ir::Store* store);
|
||||||
|
|
|
@ -138,6 +138,32 @@ OpFunctionEnd
|
||||||
)");
|
)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(SpvGeneratorImplTest, FunctionVar_Load) {
|
||||||
|
auto* func = b.CreateFunction(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||||
|
b.Branch(func->start_target, func->end_target);
|
||||||
|
|
||||||
|
auto* store_ty = mod.types.Get<type::I32>();
|
||||||
|
auto* ty = mod.types.Get<type::Pointer>(store_ty, builtin::AddressSpace::kFunction,
|
||||||
|
builtin::Access::kReadWrite);
|
||||||
|
auto* v = b.Declare(ty);
|
||||||
|
func->start_target->instructions.Push(v);
|
||||||
|
func->start_target->instructions.Push(b.Load(v));
|
||||||
|
|
||||||
|
generator_.EmitFunction(func);
|
||||||
|
EXPECT_EQ(DumpModule(generator_.Module()), R"(OpName %1 "foo"
|
||||||
|
%2 = OpTypeVoid
|
||||||
|
%3 = OpTypeFunction %2
|
||||||
|
%7 = OpTypeInt 32 1
|
||||||
|
%6 = OpTypePointer Function %7
|
||||||
|
%1 = OpFunction %2 None %3
|
||||||
|
%4 = OpLabel
|
||||||
|
%5 = OpVariable %6 Function
|
||||||
|
%8 = OpLoad %7 %5
|
||||||
|
OpReturn
|
||||||
|
OpFunctionEnd
|
||||||
|
)");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(SpvGeneratorImplTest, FunctionVar_Store) {
|
TEST_F(SpvGeneratorImplTest, FunctionVar_Store) {
|
||||||
auto* func = b.CreateFunction(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
auto* func = b.CreateFunction(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||||
b.Branch(func->start_target, func->end_target);
|
b.Branch(func->start_target, func->end_target);
|
||||||
|
|
Loading…
Reference in New Issue