123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284 |
- // Copyright (c) 2017 Pierre Moreau
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- #include <iostream>
- #include <memory>
- #include <string>
- #include <vector>
- #include "gmock/gmock.h"
- #include "source/opt/build_module.h"
- #include "source/opt/decoration_manager.h"
- #include "source/opt/ir_context.h"
- #include "source/spirv_constant.h"
- #include "test/unit_spirv.h"
- namespace spvtools {
- namespace opt {
- namespace analysis {
- namespace {
- using spvtest::MakeVector;
- class DecorationManagerTest : public ::testing::Test {
- public:
- DecorationManagerTest()
- : tools_(SPV_ENV_UNIVERSAL_1_2),
- context_(),
- consumer_([this](spv_message_level_t level, const char*,
- const spv_position_t& position, const char* message) {
- if (!error_message_.empty()) error_message_ += "\n";
- switch (level) {
- case SPV_MSG_FATAL:
- case SPV_MSG_INTERNAL_ERROR:
- case SPV_MSG_ERROR:
- error_message_ += "ERROR";
- break;
- case SPV_MSG_WARNING:
- error_message_ += "WARNING";
- break;
- case SPV_MSG_INFO:
- error_message_ += "INFO";
- break;
- case SPV_MSG_DEBUG:
- error_message_ += "DEBUG";
- break;
- }
- error_message_ +=
- ": " + std::to_string(position.index) + ": " + message;
- }),
- disassemble_options_(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER),
- error_message_() {
- tools_.SetMessageConsumer(consumer_);
- }
- void TearDown() override { error_message_.clear(); }
- DecorationManager* GetDecorationManager(const std::string& text) {
- context_ = BuildModule(SPV_ENV_UNIVERSAL_1_2, consumer_, text);
- if (context_.get())
- return context_->get_decoration_mgr();
- else
- return nullptr;
- }
- // Disassembles |binary| and outputs the result in |text|. If |text| is a
- // null pointer, SPV_ERROR_INVALID_POINTER is returned.
- spv_result_t Disassemble(const std::vector<uint32_t>& binary,
- std::string* text) {
- if (!text) return SPV_ERROR_INVALID_POINTER;
- return tools_.Disassemble(binary, text, disassemble_options_)
- ? SPV_SUCCESS
- : SPV_ERROR_INVALID_BINARY;
- }
- // Returns the accumulated error messages for the test.
- std::string GetErrorMessage() const { return error_message_; }
- std::string ToText(const std::vector<Instruction*>& inst) {
- std::vector<uint32_t> binary = {SpvMagicNumber, 0x10200, 0u, 2u, 0u};
- for (const Instruction* i : inst)
- i->ToBinaryWithoutAttachedDebugInsts(&binary);
- std::string text;
- Disassemble(binary, &text);
- return text;
- }
- std::string ModuleToText() {
- std::vector<uint32_t> binary;
- context_->module()->ToBinary(&binary, false);
- std::string text;
- Disassemble(binary, &text);
- return text;
- }
- spvtools::MessageConsumer GetConsumer() { return consumer_; }
- private:
- // An instance for calling SPIRV-Tools functionalities.
- spvtools::SpirvTools tools_;
- std::unique_ptr<IRContext> context_;
- spvtools::MessageConsumer consumer_;
- uint32_t disassemble_options_;
- std::string error_message_;
- };
- TEST_F(DecorationManagerTest,
- ComparingDecorationsWithDiffOpcodesDecorateDecorateId) {
- IRContext ir_context(SPV_ENV_UNIVERSAL_1_2, GetConsumer());
- // This parameter can be interprated both as { SpvDecorationConstant }
- // and also as a list of IDs: { 22 }
- const std::vector<uint32_t> param{SpvDecorationConstant};
- // OpDecorate %1 Constant
- Instruction inst1(
- &ir_context, SpvOpDecorate, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {1u}}, {SPV_OPERAND_TYPE_DECORATION, param}});
- // OpDecorateId %1 %22 ; 'Constant' is decoration number 22
- Instruction inst2(
- &ir_context, SpvOpDecorateId, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {1u}}, {SPV_OPERAND_TYPE_ID, param}});
- DecorationManager* decoManager = ir_context.get_decoration_mgr();
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->AreDecorationsTheSame(&inst1, &inst2, true));
- }
- TEST_F(DecorationManagerTest,
- ComparingDecorationsWithDiffOpcodesDecorateDecorateString) {
- IRContext ir_context(SPV_ENV_UNIVERSAL_1_2, GetConsumer());
- // This parameter can be interprated both as { SpvDecorationConstant }
- // and also as a null-terminated string with a single character with value 22.
- const std::vector<uint32_t> param{SpvDecorationConstant};
- // OpDecorate %1 Constant
- Instruction inst1(
- &ir_context, SpvOpDecorate, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {1u}}, {SPV_OPERAND_TYPE_DECORATION, param}});
- // OpDecorateStringGOOGLE %1 !22
- Instruction inst2(
- &ir_context, SpvOpDecorateStringGOOGLE, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {1u}}, {SPV_OPERAND_TYPE_LITERAL_STRING, param}});
- DecorationManager* decoManager = ir_context.get_decoration_mgr();
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->AreDecorationsTheSame(&inst1, &inst2, true));
- }
- TEST_F(DecorationManagerTest, ComparingDecorationsWithDiffDecorateParam) {
- IRContext ir_context(SPV_ENV_UNIVERSAL_1_2, GetConsumer());
- // OpDecorate %1 Constant
- Instruction inst1(&ir_context, SpvOpDecorate, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {1u}},
- {SPV_OPERAND_TYPE_DECORATION, {SpvDecorationConstant}}});
- // OpDecorate %1 Restrict
- Instruction inst2(&ir_context, SpvOpDecorate, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {1u}},
- {SPV_OPERAND_TYPE_DECORATION, {SpvDecorationRestrict}}});
- DecorationManager* decoManager = ir_context.get_decoration_mgr();
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->AreDecorationsTheSame(&inst1, &inst2, true));
- }
- TEST_F(DecorationManagerTest, ComparingDecorationsWithDiffDecorateIdParam) {
- IRContext ir_context(SPV_ENV_UNIVERSAL_1_2, GetConsumer());
- // OpDecorate %1 Constant
- Instruction inst1(
- &ir_context, SpvOpDecorateId, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {1u}}, {SPV_OPERAND_TYPE_ID, {555}}});
- // OpDecorate %1 Restrict
- Instruction inst2(
- &ir_context, SpvOpDecorateId, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {1u}}, {SPV_OPERAND_TYPE_ID, {666}}});
- DecorationManager* decoManager = ir_context.get_decoration_mgr();
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->AreDecorationsTheSame(&inst1, &inst2, true));
- }
- TEST_F(DecorationManagerTest, ComparingDecorationsWithDiffDecorateStringParam) {
- IRContext ir_context(SPV_ENV_UNIVERSAL_1_2, GetConsumer());
- // OpDecorate %1 Constant
- Instruction inst1(&ir_context, SpvOpDecorateStringGOOGLE, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {1u}},
- {SPV_OPERAND_TYPE_LITERAL_STRING, MakeVector("Hello!")}});
- // OpDecorate %1 Restrict
- Instruction inst2(&ir_context, SpvOpDecorateStringGOOGLE, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {1u}},
- {SPV_OPERAND_TYPE_LITERAL_STRING, MakeVector("Hellx")}});
- DecorationManager* decoManager = ir_context.get_decoration_mgr();
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->AreDecorationsTheSame(&inst1, &inst2, true));
- }
- TEST_F(DecorationManagerTest, ComparingSameDecorationsOnDiffTargetAllowed) {
- IRContext ir_context(SPV_ENV_UNIVERSAL_1_2, GetConsumer());
- // OpDecorate %1 Constant
- Instruction inst1(&ir_context, SpvOpDecorate, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {1u}},
- {SPV_OPERAND_TYPE_DECORATION, {SpvDecorationConstant}}});
- // OpDecorate %2 Constant
- Instruction inst2(&ir_context, SpvOpDecorate, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {2u}},
- {SPV_OPERAND_TYPE_DECORATION, {SpvDecorationConstant}}});
- DecorationManager* decoManager = ir_context.get_decoration_mgr();
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_TRUE(decoManager->AreDecorationsTheSame(&inst1, &inst2, true));
- }
- TEST_F(DecorationManagerTest, ComparingSameDecorationIdsOnDiffTargetAllowed) {
- IRContext ir_context(SPV_ENV_UNIVERSAL_1_2, GetConsumer());
- Instruction inst1(
- &ir_context, SpvOpDecorateId, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {1u}}, {SPV_OPERAND_TYPE_DECORATION, {44}}});
- Instruction inst2(
- &ir_context, SpvOpDecorateId, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {2u}}, {SPV_OPERAND_TYPE_DECORATION, {44}}});
- DecorationManager* decoManager = ir_context.get_decoration_mgr();
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_TRUE(decoManager->AreDecorationsTheSame(&inst1, &inst2, true));
- }
- TEST_F(DecorationManagerTest,
- ComparingSameDecorationStringsOnDiffTargetAllowed) {
- IRContext ir_context(SPV_ENV_UNIVERSAL_1_2, GetConsumer());
- Instruction inst1(&ir_context, SpvOpDecorateStringGOOGLE, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {1u}},
- {SPV_OPERAND_TYPE_LITERAL_STRING, MakeVector("hello")}});
- Instruction inst2(&ir_context, SpvOpDecorateStringGOOGLE, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {2u}},
- {SPV_OPERAND_TYPE_LITERAL_STRING, MakeVector("hello")}});
- DecorationManager* decoManager = ir_context.get_decoration_mgr();
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_TRUE(decoManager->AreDecorationsTheSame(&inst1, &inst2, true));
- }
- TEST_F(DecorationManagerTest, ComparingSameDecorationsOnDiffTargetDisallowed) {
- IRContext ir_context(SPV_ENV_UNIVERSAL_1_2, GetConsumer());
- // OpDecorate %1 Constant
- Instruction inst1(&ir_context, SpvOpDecorate, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {1u}},
- {SPV_OPERAND_TYPE_DECORATION, {SpvDecorationConstant}}});
- // OpDecorate %2 Constant
- Instruction inst2(&ir_context, SpvOpDecorate, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {2u}},
- {SPV_OPERAND_TYPE_DECORATION, {SpvDecorationConstant}}});
- DecorationManager* decoManager = ir_context.get_decoration_mgr();
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->AreDecorationsTheSame(&inst1, &inst2, false));
- }
- TEST_F(DecorationManagerTest, ComparingMemberDecorationsOnSameTypeDiffMember) {
- IRContext ir_context(SPV_ENV_UNIVERSAL_1_2, GetConsumer());
- // OpMemberDecorate %1 0 Constant
- Instruction inst1(&ir_context, SpvOpMemberDecorate, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {1u}},
- {SPV_OPERAND_TYPE_LITERAL_INTEGER, {0u}},
- {SPV_OPERAND_TYPE_DECORATION, {SpvDecorationConstant}}});
- // OpMemberDecorate %1 1 Constant
- Instruction inst2(&ir_context, SpvOpMemberDecorate, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {1u}},
- {SPV_OPERAND_TYPE_LITERAL_INTEGER, {1u}},
- {SPV_OPERAND_TYPE_DECORATION, {SpvDecorationConstant}}});
- DecorationManager* decoManager = ir_context.get_decoration_mgr();
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->AreDecorationsTheSame(&inst1, &inst2, true));
- }
- TEST_F(DecorationManagerTest,
- ComparingSameMemberDecorationsOnDiffTargetAllowed) {
- IRContext ir_context(SPV_ENV_UNIVERSAL_1_2, GetConsumer());
- // OpMemberDecorate %1 0 Constant
- Instruction inst1(&ir_context, SpvOpMemberDecorate, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {1u}},
- {SPV_OPERAND_TYPE_LITERAL_INTEGER, {0u}},
- {SPV_OPERAND_TYPE_DECORATION, {SpvDecorationConstant}}});
- // OpMemberDecorate %2 0 Constant
- Instruction inst2(&ir_context, SpvOpMemberDecorate, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {2u}},
- {SPV_OPERAND_TYPE_LITERAL_INTEGER, {0u}},
- {SPV_OPERAND_TYPE_DECORATION, {SpvDecorationConstant}}});
- DecorationManager* decoManager = ir_context.get_decoration_mgr();
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_TRUE(decoManager->AreDecorationsTheSame(&inst1, &inst2, true));
- }
- TEST_F(DecorationManagerTest,
- ComparingSameMemberDecorationsOnDiffTargetDisallowed) {
- IRContext ir_context(SPV_ENV_UNIVERSAL_1_2, GetConsumer());
- // OpMemberDecorate %1 0 Constant
- Instruction inst1(&ir_context, SpvOpMemberDecorate, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {1u}},
- {SPV_OPERAND_TYPE_LITERAL_INTEGER, {0u}},
- {SPV_OPERAND_TYPE_DECORATION, {SpvDecorationConstant}}});
- // OpMemberDecorate %2 0 Constant
- Instruction inst2(&ir_context, SpvOpMemberDecorate, 0u, 0u,
- {{SPV_OPERAND_TYPE_ID, {2u}},
- {SPV_OPERAND_TYPE_LITERAL_INTEGER, {0u}},
- {SPV_OPERAND_TYPE_DECORATION, {SpvDecorationConstant}}});
- DecorationManager* decoManager = ir_context.get_decoration_mgr();
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->AreDecorationsTheSame(&inst1, &inst2, false));
- }
- TEST_F(DecorationManagerTest, RemoveDecorationFromVariable) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %1 Constant
- OpDecorate %2 Restrict
- %2 = OpDecorationGroup
- OpGroupDecorate %2 %1 %3
- %4 = OpTypeInt 32 0
- %1 = OpVariable %4 Uniform
- %3 = OpVariable %4 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- decoManager->RemoveDecorationsFrom(1u);
- auto decorations = decoManager->GetDecorationsFor(1u, false);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_TRUE(decorations.empty());
- decorations = decoManager->GetDecorationsFor(3u, false);
- EXPECT_THAT(GetErrorMessage(), "");
- const std::string expected_decorations = R"(OpDecorate %2 Restrict
- )";
- EXPECT_THAT(ToText(decorations), expected_decorations);
- const std::string expected_binary = R"(OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %2 Restrict
- %2 = OpDecorationGroup
- OpGroupDecorate %2 %3
- %4 = OpTypeInt 32 0
- %1 = OpVariable %4 Uniform
- %3 = OpVariable %4 Uniform
- )";
- EXPECT_THAT(ModuleToText(), expected_binary);
- }
- TEST_F(DecorationManagerTest, RemoveDecorationStringFromVariable) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpExtension "SPV_GOOGLE_hlsl_functionality1"
- OpExtension "SPV_GOOGLE_decorate_string"
- OpMemoryModel Logical GLSL450
- OpDecorateStringGOOGLE %1 HlslSemanticGOOGLE "hello world"
- OpDecorate %2 Restrict
- %2 = OpDecorationGroup
- OpGroupDecorate %2 %1 %3
- %4 = OpTypeInt 32 0
- %1 = OpVariable %4 Uniform
- %3 = OpVariable %4 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- decoManager->RemoveDecorationsFrom(1u);
- auto decorations = decoManager->GetDecorationsFor(1u, false);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_TRUE(decorations.empty());
- decorations = decoManager->GetDecorationsFor(3u, false);
- EXPECT_THAT(GetErrorMessage(), "");
- const std::string expected_decorations = R"(OpDecorate %2 Restrict
- )";
- EXPECT_THAT(ToText(decorations), expected_decorations);
- const std::string expected_binary = R"(OpCapability Shader
- OpCapability Linkage
- OpExtension "SPV_GOOGLE_hlsl_functionality1"
- OpExtension "SPV_GOOGLE_decorate_string"
- OpMemoryModel Logical GLSL450
- OpDecorate %2 Restrict
- %2 = OpDecorationGroup
- OpGroupDecorate %2 %3
- %4 = OpTypeInt 32 0
- %1 = OpVariable %4 Uniform
- %3 = OpVariable %4 Uniform
- )";
- EXPECT_THAT(ModuleToText(), expected_binary);
- }
- TEST_F(DecorationManagerTest, RemoveDecorationFromDecorationGroup) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %1 Constant
- OpDecorate %2 Restrict
- %2 = OpDecorationGroup
- OpGroupDecorate %2 %1 %3
- %4 = OpTypeInt 32 0
- %1 = OpVariable %4 Uniform
- %3 = OpVariable %4 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- decoManager->RemoveDecorationsFrom(2u);
- auto decorations = decoManager->GetDecorationsFor(2u, false);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_TRUE(decorations.empty());
- decorations = decoManager->GetDecorationsFor(1u, false);
- EXPECT_THAT(GetErrorMessage(), "");
- const std::string expected_decorations = R"(OpDecorate %1 Constant
- )";
- EXPECT_THAT(ToText(decorations), expected_decorations);
- decorations = decoManager->GetDecorationsFor(3u, false);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_THAT(ToText(decorations), "");
- const std::string expected_binary = R"(OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %1 Constant
- %2 = OpDecorationGroup
- %4 = OpTypeInt 32 0
- %1 = OpVariable %4 Uniform
- %3 = OpVariable %4 Uniform
- )";
- EXPECT_THAT(ModuleToText(), expected_binary);
- }
- TEST_F(DecorationManagerTest,
- RemoveDecorationFromDecorationGroupKeepDeadDecorations) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %1 Constant
- OpDecorate %2 Restrict
- %2 = OpDecorationGroup
- OpGroupDecorate %2 %1
- %3 = OpTypeInt 32 0
- %1 = OpVariable %3 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- decoManager->RemoveDecorationsFrom(1u);
- auto decorations = decoManager->GetDecorationsFor(1u, false);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_TRUE(decorations.empty());
- decorations = decoManager->GetDecorationsFor(2u, false);
- EXPECT_THAT(GetErrorMessage(), "");
- const std::string expected_decorations = R"(OpDecorate %2 Restrict
- )";
- EXPECT_THAT(ToText(decorations), expected_decorations);
- const std::string expected_binary = R"(OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %2 Restrict
- %2 = OpDecorationGroup
- %3 = OpTypeInt 32 0
- %1 = OpVariable %3 Uniform
- )";
- EXPECT_THAT(ModuleToText(), expected_binary);
- }
- TEST_F(DecorationManagerTest, RemoveAllDecorationsAppliedByGroup) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %1 Constant
- OpDecorate %2 Restrict
- %2 = OpDecorationGroup
- OpGroupDecorate %2 %1
- OpDecorate %3 BuiltIn VertexId
- %3 = OpDecorationGroup
- OpGroupDecorate %3 %1
- %4 = OpTypeInt 32 0
- %1 = OpVariable %4 Input
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- decoManager->RemoveDecorationsFrom(1u, [](const Instruction& inst) {
- return inst.opcode() == SpvOpDecorate &&
- inst.GetSingleWordInOperand(0u) == 3u;
- });
- auto decorations = decoManager->GetDecorationsFor(1u, false);
- EXPECT_THAT(GetErrorMessage(), "");
- std::string expected_decorations = R"(OpDecorate %1 Constant
- OpDecorate %2 Restrict
- )";
- EXPECT_THAT(ToText(decorations), expected_decorations);
- decorations = decoManager->GetDecorationsFor(2u, false);
- EXPECT_THAT(GetErrorMessage(), "");
- expected_decorations = R"(OpDecorate %2 Restrict
- )";
- EXPECT_THAT(ToText(decorations), expected_decorations);
- const std::string expected_binary = R"(OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %1 Constant
- OpDecorate %2 Restrict
- %2 = OpDecorationGroup
- OpGroupDecorate %2 %1
- OpDecorate %3 BuiltIn VertexId
- %3 = OpDecorationGroup
- %4 = OpTypeInt 32 0
- %1 = OpVariable %4 Input
- )";
- EXPECT_THAT(ModuleToText(), expected_binary);
- }
- TEST_F(DecorationManagerTest, RemoveSomeDecorationsAppliedByGroup) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %1 Constant
- OpDecorate %2 Restrict
- %2 = OpDecorationGroup
- OpGroupDecorate %2 %1
- OpDecorate %3 BuiltIn VertexId
- OpDecorate %3 Invariant
- %3 = OpDecorationGroup
- OpGroupDecorate %3 %1
- %uint = OpTypeInt 32 0
- %1 = OpVariable %uint Input
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- decoManager->RemoveDecorationsFrom(1u, [](const Instruction& inst) {
- return inst.opcode() == SpvOpDecorate &&
- inst.GetSingleWordInOperand(0u) == 3u &&
- inst.GetSingleWordInOperand(1u) == SpvDecorationBuiltIn;
- });
- auto decorations = decoManager->GetDecorationsFor(1u, false);
- EXPECT_THAT(GetErrorMessage(), "");
- std::string expected_decorations = R"(OpDecorate %1 Constant
- OpDecorate %1 Invariant
- OpDecorate %2 Restrict
- )";
- EXPECT_THAT(ToText(decorations), expected_decorations);
- decorations = decoManager->GetDecorationsFor(2u, false);
- EXPECT_THAT(GetErrorMessage(), "");
- expected_decorations = R"(OpDecorate %2 Restrict
- )";
- EXPECT_THAT(ToText(decorations), expected_decorations);
- const std::string expected_binary = R"(OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %1 Constant
- OpDecorate %2 Restrict
- %2 = OpDecorationGroup
- OpGroupDecorate %2 %1
- OpDecorate %3 BuiltIn VertexId
- OpDecorate %3 Invariant
- %3 = OpDecorationGroup
- OpDecorate %1 Invariant
- %4 = OpTypeInt 32 0
- %1 = OpVariable %4 Input
- )";
- EXPECT_THAT(ModuleToText(), expected_binary);
- }
- TEST_F(DecorationManagerTest, RemoveDecorationDecorate) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %1 Constant
- OpDecorate %1 Restrict
- %2 = OpTypeInt 32 0
- %1 = OpVariable %2 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- auto decorations = decoManager->GetDecorationsFor(1u, false);
- decoManager->RemoveDecoration(decorations.front());
- decorations = decoManager->GetDecorationsFor(1u, false);
- EXPECT_THAT(GetErrorMessage(), "");
- const std::string expected_decorations = R"(OpDecorate %1 Restrict
- )";
- EXPECT_THAT(ToText(decorations), expected_decorations);
- }
- TEST_F(DecorationManagerTest, RemoveDecorationStringDecorate) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpExtension "SPV_GOOGLE_hlsl_functionality1"
- OpExtension "SPV_GOOGLE_decorate_string"
- OpMemoryModel Logical GLSL450
- OpDecorateStringGOOGLE %1 HlslSemanticGOOGLE "foobar"
- OpDecorate %1 Restrict
- %2 = OpTypeInt 32 0
- %1 = OpVariable %2 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- auto decorations = decoManager->GetDecorationsFor(1u, false);
- decoManager->RemoveDecoration(decorations.front());
- decorations = decoManager->GetDecorationsFor(1u, false);
- EXPECT_THAT(GetErrorMessage(), "");
- const std::string expected_decorations = R"(OpDecorate %1 Restrict
- )";
- EXPECT_THAT(ToText(decorations), expected_decorations);
- }
- TEST_F(DecorationManagerTest, CloneDecorations) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %1 Constant
- OpDecorate %2 Restrict
- %2 = OpDecorationGroup
- OpGroupDecorate %2 %1
- OpDecorate %3 BuiltIn VertexId
- OpDecorate %3 Invariant
- %3 = OpDecorationGroup
- OpGroupDecorate %3 %1
- %4 = OpTypeInt 32 0
- %1 = OpVariable %4 Input
- %5 = OpVariable %4 Input
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- // Check cloning OpDecorate including group decorations.
- auto decorations = decoManager->GetDecorationsFor(5u, false);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_TRUE(decorations.empty());
- decoManager->CloneDecorations(1u, 5u);
- decorations = decoManager->GetDecorationsFor(5u, false);
- EXPECT_THAT(GetErrorMessage(), "");
- std::string expected_decorations = R"(OpDecorate %5 Constant
- OpDecorate %2 Restrict
- OpDecorate %3 BuiltIn VertexId
- OpDecorate %3 Invariant
- )";
- EXPECT_THAT(ToText(decorations), expected_decorations);
- // Check that bookkeeping for ID 2 remains the same.
- decorations = decoManager->GetDecorationsFor(2u, false);
- EXPECT_THAT(GetErrorMessage(), "");
- expected_decorations = R"(OpDecorate %2 Restrict
- )";
- EXPECT_THAT(ToText(decorations), expected_decorations);
- const std::string expected_binary = R"(OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %1 Constant
- OpDecorate %2 Restrict
- %2 = OpDecorationGroup
- OpGroupDecorate %2 %1 %5
- OpDecorate %3 BuiltIn VertexId
- OpDecorate %3 Invariant
- %3 = OpDecorationGroup
- OpGroupDecorate %3 %1 %5
- OpDecorate %5 Constant
- %4 = OpTypeInt 32 0
- %1 = OpVariable %4 Input
- %5 = OpVariable %4 Input
- )";
- EXPECT_THAT(ModuleToText(), expected_binary);
- }
- TEST_F(DecorationManagerTest, CloneDecorationsStringAndId) {
- const std::string spirv = R"(OpCapability Shader
- OpCapability Linkage
- OpExtension "SPV_GOOGLE_hlsl_functionality1"
- OpExtension "SPV_GOOGLE_decorate_string"
- OpMemoryModel Logical GLSL450
- OpDecorateStringGOOGLE %1 HlslSemanticGOOGLE "blah"
- OpDecorateId %1 HlslCounterBufferGOOGLE %2
- OpDecorate %1 Aliased
- %3 = OpTypeInt 32 0
- %4 = OpTypePointer Uniform %3
- %1 = OpVariable %4 Uniform
- %2 = OpVariable %4 Uniform
- %5 = OpVariable %4 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- // Check cloning OpDecorate including group decorations.
- auto decorations = decoManager->GetDecorationsFor(5u, false);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_TRUE(decorations.empty());
- decoManager->CloneDecorations(1u, 5u);
- decorations = decoManager->GetDecorationsFor(5u, false);
- EXPECT_THAT(GetErrorMessage(), "");
- std::string expected_decorations =
- R"(OpDecorateStringGOOGLE %5 HlslSemanticGOOGLE "blah"
- OpDecorateId %5 HlslCounterBufferGOOGLE %2
- OpDecorate %5 Aliased
- )";
- EXPECT_THAT(ToText(decorations), expected_decorations);
- const std::string expected_binary = R"(OpCapability Shader
- OpCapability Linkage
- OpExtension "SPV_GOOGLE_hlsl_functionality1"
- OpExtension "SPV_GOOGLE_decorate_string"
- OpMemoryModel Logical GLSL450
- OpDecorateStringGOOGLE %1 HlslSemanticGOOGLE "blah"
- OpDecorateId %1 HlslCounterBufferGOOGLE %2
- OpDecorate %1 Aliased
- OpDecorateStringGOOGLE %5 HlslSemanticGOOGLE "blah"
- OpDecorateId %5 HlslCounterBufferGOOGLE %2
- OpDecorate %5 Aliased
- %3 = OpTypeInt 32 0
- %4 = OpTypePointer Uniform %3
- %1 = OpVariable %4 Uniform
- %2 = OpVariable %4 Uniform
- %5 = OpVariable %4 Uniform
- )";
- EXPECT_THAT(ModuleToText(), expected_binary);
- }
- TEST_F(DecorationManagerTest, CloneSomeDecorations) {
- const std::string spirv = R"(OpCapability Shader
- OpCapability Linkage
- OpExtension "SPV_GOOGLE_hlsl_functionality1"
- OpExtension "SPV_GOOGLE_decorate_string"
- OpMemoryModel Logical GLSL450
- OpDecorate %1 RelaxedPrecision
- OpDecorate %1 Restrict
- %2 = OpTypeInt 32 0
- %3 = OpTypePointer Function %2
- %4 = OpTypeVoid
- %5 = OpTypeFunction %4
- %6 = OpFunction %4 None %5
- %7 = OpLabel
- %1 = OpVariable %3 Function
- %8 = OpUndef %2
- OpReturn
- OpFunctionEnd
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_EQ(GetErrorMessage(), "");
- // Check cloning OpDecorate including group decorations.
- auto decorations = decoManager->GetDecorationsFor(8u, false);
- EXPECT_EQ(GetErrorMessage(), "");
- EXPECT_TRUE(decorations.empty());
- decoManager->CloneDecorations(1u, 8u, {SpvDecorationRelaxedPrecision});
- decorations = decoManager->GetDecorationsFor(8u, false);
- EXPECT_THAT(GetErrorMessage(), "");
- std::string expected_decorations =
- R"(OpDecorate %8 RelaxedPrecision
- )";
- EXPECT_EQ(ToText(decorations), expected_decorations);
- const std::string expected_binary = R"(OpCapability Shader
- OpCapability Linkage
- OpExtension "SPV_GOOGLE_hlsl_functionality1"
- OpExtension "SPV_GOOGLE_decorate_string"
- OpMemoryModel Logical GLSL450
- OpDecorate %1 RelaxedPrecision
- OpDecorate %1 Restrict
- OpDecorate %8 RelaxedPrecision
- %2 = OpTypeInt 32 0
- %3 = OpTypePointer Function %2
- %4 = OpTypeVoid
- %5 = OpTypeFunction %4
- %6 = OpFunction %4 None %5
- %7 = OpLabel
- %1 = OpVariable %3 Function
- %8 = OpUndef %2
- OpReturn
- OpFunctionEnd
- )";
- EXPECT_EQ(ModuleToText(), expected_binary);
- }
- // Test cloning decoration for an id that is decorated via a group decoration.
- TEST_F(DecorationManagerTest, CloneSomeGroupDecorations) {
- const std::string spirv = R"(OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %1 RelaxedPrecision
- OpDecorate %1 Restrict
- %1 = OpDecorationGroup
- OpGroupDecorate %1 %2
- %3 = OpTypeInt 32 0
- %4 = OpTypePointer Function %3
- %5 = OpTypeVoid
- %6 = OpTypeFunction %5
- %7 = OpFunction %5 None %6
- %8 = OpLabel
- %2 = OpVariable %4 Function
- %9 = OpUndef %3
- OpReturn
- OpFunctionEnd
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_EQ(GetErrorMessage(), "");
- // Check cloning OpDecorate including group decorations.
- auto decorations = decoManager->GetDecorationsFor(9u, false);
- EXPECT_EQ(GetErrorMessage(), "");
- EXPECT_TRUE(decorations.empty());
- decoManager->CloneDecorations(2u, 9u, {SpvDecorationRelaxedPrecision});
- decorations = decoManager->GetDecorationsFor(9u, false);
- EXPECT_THAT(GetErrorMessage(), "");
- std::string expected_decorations =
- R"(OpDecorate %9 RelaxedPrecision
- )";
- EXPECT_EQ(ToText(decorations), expected_decorations);
- const std::string expected_binary = R"(OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %1 RelaxedPrecision
- OpDecorate %1 Restrict
- %1 = OpDecorationGroup
- OpGroupDecorate %1 %2
- OpDecorate %9 RelaxedPrecision
- %3 = OpTypeInt 32 0
- %4 = OpTypePointer Function %3
- %5 = OpTypeVoid
- %6 = OpTypeFunction %5
- %7 = OpFunction %5 None %6
- %8 = OpLabel
- %2 = OpVariable %4 Function
- %9 = OpUndef %3
- OpReturn
- OpFunctionEnd
- )";
- EXPECT_EQ(ModuleToText(), expected_binary);
- }
- TEST_F(DecorationManagerTest, HaveTheSameDecorationsWithoutGroupsTrue) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %1 Restrict
- OpDecorate %2 Constant
- OpDecorate %2 Restrict
- OpDecorate %1 Constant
- %u32 = OpTypeInt 32 0
- %1 = OpVariable %u32 Uniform
- %2 = OpVariable %u32 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_TRUE(decoManager->HaveTheSameDecorations(1u, 2u));
- }
- TEST_F(DecorationManagerTest, HaveTheSameDecorationsWithoutGroupsFalse) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %1 Restrict
- OpDecorate %2 Constant
- OpDecorate %2 Restrict
- %u32 = OpTypeInt 32 0
- %1 = OpVariable %u32 Uniform
- %2 = OpVariable %u32 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->HaveTheSameDecorations(1u, 2u));
- }
- TEST_F(DecorationManagerTest, HaveTheSameDecorationsIdWithoutGroupsTrue) {
- const std::string spirv = R"(
- OpCapability Kernel
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorateId %1 AlignmentId %nine
- OpDecorateId %3 MaxByteOffsetId %nine
- OpDecorateId %3 AlignmentId %nine
- OpDecorateId %1 MaxByteOffsetId %nine
- %u32 = OpTypeInt 32 0
- %nine = OpConstant %u32 9
- %1 = OpVariable %u32 Uniform
- %3 = OpVariable %u32 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_TRUE(decoManager->HaveTheSameDecorations(1u, 3u));
- }
- TEST_F(DecorationManagerTest, HaveTheSameDecorationsIdWithoutGroupsFalse) {
- const std::string spirv = R"(
- OpCapability Kernel
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorateId %1 AlignmentId %nine
- OpDecorateId %2 MaxByteOffsetId %nine
- OpDecorateId %2 AlignmentId %nine
- %u32 = OpTypeInt 32 0
- %nine = OpConstant %u32 9
- %1 = OpVariable %u32 Uniform
- %2 = OpVariable %u32 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->HaveTheSameDecorations(1u, 2u));
- }
- TEST_F(DecorationManagerTest, HaveTheSameDecorationsStringWithoutGroupsTrue) {
- const std::string spirv = R"(
- OpCapability Kernel
- OpCapability Linkage
- OpExtension "SPV_GOOGLE_hlsl_functionality1"
- OpExtension "SPV_GOOGLE_decorate_string"
- OpMemoryModel Logical GLSL450
- OpDecorateStringGOOGLE %1 HlslSemanticGOOGLE "hello"
- OpDecorateStringGOOGLE %2 HlslSemanticGOOGLE "world"
- OpDecorateStringGOOGLE %2 HlslSemanticGOOGLE "hello"
- OpDecorateStringGOOGLE %1 HlslSemanticGOOGLE "world"
- %u32 = OpTypeInt 32 0
- %1 = OpVariable %u32 Uniform
- %2 = OpVariable %u32 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_TRUE(decoManager->HaveTheSameDecorations(1u, 2u));
- }
- TEST_F(DecorationManagerTest, HaveTheSameDecorationsStringWithoutGroupsFalse) {
- const std::string spirv = R"(
- OpCapability Kernel
- OpCapability Linkage
- OpExtension "SPV_GOOGLE_hlsl_functionality1"
- OpExtension "SPV_GOOGLE_decorate_string"
- OpMemoryModel Logical GLSL450
- OpDecorateStringGOOGLE %1 HlslSemanticGOOGLE "hello"
- OpDecorateStringGOOGLE %2 HlslSemanticGOOGLE "world"
- OpDecorateStringGOOGLE %2 HlslSemanticGOOGLE "hello"
- %u32 = OpTypeInt 32 0
- %1 = OpVariable %u32 Uniform
- %2 = OpVariable %u32 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->HaveTheSameDecorations(1u, 2u));
- }
- TEST_F(DecorationManagerTest, HaveTheSameDecorationsWithGroupsTrue) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %1 Restrict
- OpDecorate %2 Constant
- OpDecorate %1 Constant
- OpDecorate %3 Restrict
- %3 = OpDecorationGroup
- OpGroupDecorate %3 %2
- OpDecorate %4 Invariant
- %4 = OpDecorationGroup
- OpGroupDecorate %4 %1 %2
- %u32 = OpTypeInt 32 0
- %1 = OpVariable %u32 Uniform
- %2 = OpVariable %u32 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_TRUE(decoManager->HaveTheSameDecorations(1u, 2u));
- }
- TEST_F(DecorationManagerTest, HaveTheSameDecorationsWithGroupsFalse) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %1 Restrict
- OpDecorate %2 Constant
- OpDecorate %1 Constant
- OpDecorate %4 Invariant
- %4 = OpDecorationGroup
- OpGroupDecorate %4 %1 %2
- %u32 = OpTypeInt 32 0
- %1 = OpVariable %u32 Uniform
- %2 = OpVariable %u32 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->HaveTheSameDecorations(1u, 2u));
- }
- TEST_F(DecorationManagerTest, HaveTheSameDecorationsDuplicateDecorations) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %1 Constant
- OpDecorate %2 Constant
- OpDecorate %2 Constant
- %u32 = OpTypeInt 32 0
- %1 = OpVariable %u32 Uniform
- %2 = OpVariable %u32 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_TRUE(decoManager->HaveTheSameDecorations(1u, 2u));
- }
- TEST_F(DecorationManagerTest, HaveTheSameDecorationsDifferentVariations) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %1 Location 0
- OpDecorate %2 Location 1
- %u32 = OpTypeInt 32 0
- %1 = OpVariable %u32 Uniform
- %2 = OpVariable %u32 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->HaveTheSameDecorations(1u, 2u));
- }
- TEST_F(DecorationManagerTest,
- HaveTheSameDecorationsDuplicateMemberDecorations) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpMemberDecorate %1 0 Location 0
- OpMemberDecorate %2 0 Location 0
- OpMemberDecorate %2 0 Location 0
- %u32 = OpTypeInt 32 0
- %1 = OpTypeStruct %u32 %u32
- %2 = OpTypeStruct %u32 %u32
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_TRUE(decoManager->HaveTheSameDecorations(1u, 2u));
- }
- TEST_F(DecorationManagerTest,
- HaveTheSameDecorationsDifferentMemberSameDecoration) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpMemberDecorate %1 0 Location 0
- OpMemberDecorate %2 1 Location 0
- %u32 = OpTypeInt 32 0
- %1 = OpTypeStruct %u32 %u32
- %2 = OpTypeStruct %u32 %u32
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->HaveTheSameDecorations(1u, 2u));
- }
- TEST_F(DecorationManagerTest, HaveTheSameDecorationsDifferentMemberVariations) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpMemberDecorate %1 0 Location 0
- OpMemberDecorate %2 0 Location 1
- %u32 = OpTypeInt 32 0
- %1 = OpTypeStruct %u32 %u32
- %2 = OpTypeStruct %u32 %u32
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->HaveTheSameDecorations(1u, 2u));
- }
- TEST_F(DecorationManagerTest, HaveTheSameDecorationsDuplicateIdDecorations) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorateId %1 AlignmentId %2
- OpDecorateId %3 AlignmentId %2
- OpDecorateId %3 AlignmentId %2
- %u32 = OpTypeInt 32 0
- %1 = OpVariable %u32 Uniform
- %3 = OpVariable %u32 Uniform
- %2 = OpSpecConstant %u32 0
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_TRUE(decoManager->HaveTheSameDecorations(1u, 3u));
- }
- TEST_F(DecorationManagerTest,
- HaveTheSameDecorationsDuplicateStringDecorations) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpExtension "SPV_GOOGLE_hlsl_functionality1"
- OpExtension "SPV_GOOGLE_decorate_string"
- OpMemoryModel Logical GLSL450
- OpDecorateStringGOOGLE %1 HlslSemanticGOOGLE "hello"
- OpDecorateStringGOOGLE %2 HlslSemanticGOOGLE "hello"
- OpDecorateStringGOOGLE %2 HlslSemanticGOOGLE "hello"
- %u32 = OpTypeInt 32 0
- %1 = OpVariable %u32 Uniform
- %2 = OpVariable %u32 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_TRUE(decoManager->HaveTheSameDecorations(1u, 2u));
- }
- TEST_F(DecorationManagerTest, HaveTheSameDecorationsDifferentIdVariations) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorateId %1 AlignmentId %2
- OpDecorateId %3 AlignmentId %4
- %u32 = OpTypeInt 32 0
- %1 = OpVariable %u32 Uniform
- %3 = OpVariable %u32 Uniform
- %2 = OpSpecConstant %u32 0
- %4 = OpSpecConstant %u32 0
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->HaveTheSameDecorations(1u, 2u));
- }
- TEST_F(DecorationManagerTest, HaveTheSameDecorationsDifferentStringVariations) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpExtension "SPV_GOOGLE_hlsl_functionality1"
- OpExtension "SPV_GOOGLE_decorate_string"
- OpMemoryModel Logical GLSL450
- OpDecorateStringGOOGLE %1 HlslSemanticGOOGLE "hello"
- OpDecorateStringGOOGLE %2 HlslSemanticGOOGLE "world"
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->HaveTheSameDecorations(1u, 2u));
- }
- TEST_F(DecorationManagerTest, HaveTheSameDecorationsLeftSymmetry) {
- // Left being a subset of right is not enough.
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %1 Constant
- OpDecorate %1 Constant
- OpDecorate %2 Constant
- OpDecorate %2 Restrict
- %u32 = OpTypeInt 32 0
- %1 = OpVariable %u32 Uniform
- %2 = OpVariable %u32 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->HaveTheSameDecorations(1u, 2u));
- }
- TEST_F(DecorationManagerTest, HaveTheSameDecorationsRightSymmetry) {
- // Right being a subset of left is not enough.
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %1 Constant
- OpDecorate %1 Restrict
- OpDecorate %2 Constant
- OpDecorate %2 Constant
- %u32 = OpTypeInt 32 0
- %1 = OpVariable %u32 Uniform
- %2 = OpVariable %u32 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->HaveTheSameDecorations(1u, 2u));
- }
- TEST_F(DecorationManagerTest, HaveTheSameDecorationIdsLeftSymmetry) {
- const std::string spirv = R"(
- OpCapability Kernel
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorateId %1 AlignmentId %nine
- OpDecorateId %1 AlignmentId %nine
- OpDecorateId %2 AlignmentId %nine
- OpDecorateId %2 MaxByteOffsetId %nine
- %u32 = OpTypeInt 32 0
- %nine = OpConstant %u32 9
- %1 = OpVariable %u32 Uniform
- %2 = OpVariable %u32 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->HaveTheSameDecorations(1u, 2u));
- }
- TEST_F(DecorationManagerTest, HaveTheSameDecorationIdsRightSymmetry) {
- const std::string spirv = R"(
- OpCapability Kernel
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorateId %1 AlignmentId %nine
- OpDecorateId %1 MaxByteOffsetId %nine
- OpDecorateId %2 AlignmentId %nine
- OpDecorateId %2 AlignmentId %nine
- %u32 = OpTypeInt 32 0
- %nine = OpConstant %u32 9
- %1 = OpVariable %u32 Uniform
- %2 = OpVariable %u32 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->HaveTheSameDecorations(1u, 2u));
- }
- TEST_F(DecorationManagerTest, HaveTheSameDecorationStringsLeftSymmetry) {
- const std::string spirv = R"(
- OpCapability Kernel
- OpCapability Linkage
- OpExtension "SPV_GOOGLE_hlsl_functionality1"
- OpExtension "SPV_GOOGLE_decorate_string"
- OpMemoryModel Logical GLSL450
- OpDecorateStringGOOGLE %1 HlslSemanticGOOGLE "hello"
- OpDecorateStringGOOGLE %1 HlslSemanticGOOGLE "hello"
- OpDecorateStringGOOGLE %2 HlslSemanticGOOGLE "hello"
- OpDecorateStringGOOGLE %2 HlslSemanticGOOGLE "world"
- %u32 = OpTypeInt 32 0
- %1 = OpVariable %u32 Uniform
- %2 = OpVariable %u32 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->HaveTheSameDecorations(1u, 2u));
- }
- TEST_F(DecorationManagerTest, HaveTheSameDecorationStringsRightSymmetry) {
- const std::string spirv = R"(
- OpCapability Kernel
- OpCapability Linkage
- OpExtension "SPV_GOOGLE_hlsl_functionality1"
- OpExtension "SPV_GOOGLE_decorate_string"
- OpMemoryModel Logical GLSL450
- OpDecorateStringGOOGLE %1 HlslSemanticGOOGLE "hello"
- OpDecorateStringGOOGLE %1 HlslSemanticGOOGLE "world"
- OpDecorateStringGOOGLE %2 HlslSemanticGOOGLE "hello"
- OpDecorateStringGOOGLE %2 HlslSemanticGOOGLE "hello"
- %u32 = OpTypeInt 32 0
- %1 = OpVariable %u32 Uniform
- %2 = OpVariable %u32 Uniform
- )";
- DecorationManager* decoManager = GetDecorationManager(spirv);
- EXPECT_THAT(GetErrorMessage(), "");
- EXPECT_FALSE(decoManager->HaveTheSameDecorations(1u, 2u));
- }
- } // namespace
- } // namespace analysis
- } // namespace opt
- } // namespace spvtools
|