Debian Codegraph @

src/gallium/drivers/r600/sfn/tests/sfn_shaderfromstring_test.cpp

raw
1
2 #include "../sfn_instr_alu.h"
3 #include "../sfn_instr_export.h"
4 #include "../sfn_instr_tex.h"
5 #include "../sfn_instrfactory.h"
6
7 #include "gtest/gtest.h"
8 #include <sstream>
9
10 using namespace r600;
11
12 using std::istringstream;
13 using std::string;
14 using std::vector;
15
16 class TestShaderFromString : public ::testing::Test {
17 public:
18 void SetUp() override
19 {
20 init_pool();
21 m_instr_factory = new InstrFactory();
22 }
23
24 void TearDown() override { release_pool(); }
25
26 TestShaderFromString();
27
28 std::vector<PInst> from_string(const std::string& s);
29
30 protected:
31 void check(const vector<PInst>& eval,
32 const std::vector<PInst, Allocator<PInst>>& expect);
33
34 private:
35 InstrFactory *m_instr_factory = nullptr;
36 };
37
38 TEST_F(TestShaderFromString, test_simple_fs)
39 {
40 auto init_str =
41 R"(
42
43 # load constant color
44 ALU MOV R2000.x@group : L[0x38000000] {W}
45 ALU MOV R2000.y@group : L[0x0] {W}
46 ALU MOV R2000.z@group : L[0x0] {W}
47 ALU MOV R2000.w@group : L[0x38F00000] {WL}
48
49 # write output
50 EXPORT_DONE PIXEL 0 R2000.xyzw
51 )";
52
53 auto shader = from_string(init_str);
54
55 std::vector<PInst, Allocator<PInst>> expect;
56
57 expect.push_back(new AluInstr(op1_mov,
58 new Register(2000, 0, pin_group),
59 new LiteralConstant(0x38000000),
60 AluInstr::write));
61
62 expect.push_back(new AluInstr(op1_mov,
63 new Register(2000, 1, pin_group),
64 new LiteralConstant(0x0),
65 AluInstr::write));
66
67 expect.push_back(new AluInstr(op1_mov,
68 new Register(2000, 2, pin_group),
69 new LiteralConstant(0x0),
70 AluInstr::write));
71
72 expect.push_back(new AluInstr(op1_mov,
73 new Register(2000, 3, pin_group),
74 new LiteralConstant(0x38F00000),
75 {alu_write, alu_last_instr}));
76
77 auto exp = new ExportInstr(ExportInstr::pixel, 0, RegisterVec4(2000, false));
78 exp->set_is_last_export(true);
79 expect.push_back(exp);
80
81 check(shader, expect);
82 }
83
84 TestShaderFromString::TestShaderFromString() {}
85
86 std::vector<PInst>
87 TestShaderFromString::from_string(const std::string& s)
88 {
89 istringstream is(s);
90 string line;
91
92 std::vector<PInst> shader;
93
94 while (std::getline(is, line)) {
95 if (line.find_first_not_of(" \t") == std::string::npos)
96 continue;
97 if (line[0] == '#')
98 continue;
99
100 shader.push_back(m_instr_factory->from_string(line, 0, false));
101 }
102
103 return shader;
104 }
105
106 void
107 TestShaderFromString::check(const vector<PInst>& eval,
108 const std::vector<PInst, Allocator<PInst>>& expect)
109 {
110 ASSERT_EQ(eval.size(), expect.size());
111
112 for (unsigned i = 0; i < eval.size(); ++i) {
113 EXPECT_EQ(*eval[i], *expect[i]);
114 }
115 }