spirv-dis: add decorations to comments (#5675)

This commit is contained in:
Shahbaz Youssefi 2024-06-10 15:22:25 -04:00 committed by GitHub
parent ce46482db7
commit c3178da8ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 601 additions and 67 deletions

View File

@ -194,7 +194,27 @@ spv_result_t DisassembleTargetInstruction(
return SPV_SUCCESS;
}
uint32_t GetLineLengthWithoutColor(const std::string line) {
// Currently, every added color is in the form \x1b...m, so instead of doing a
// lot of string comparisons with spvtools::clr::* strings, we just ignore
// those ranges.
uint32_t length = 0;
for (size_t i = 0; i < line.size(); ++i) {
if (line[i] == '\x1b') {
do {
++i;
} while (line[i] != 'm');
continue;
}
++length;
}
return length;
}
constexpr int kStandardIndent = 15;
constexpr uint32_t kCommentColumn = 50;
} // namespace
namespace disassemble {
@ -212,7 +232,8 @@ InstructionDisassembler::InstructionDisassembler(const AssemblyGrammar& grammar,
comment_(spvIsInBitfield(SPV_BINARY_TO_TEXT_OPTION_COMMENT, options)),
show_byte_offset_(
spvIsInBitfield(SPV_BINARY_TO_TEXT_OPTION_SHOW_BYTE_OFFSET, options)),
name_mapper_(std::move(name_mapper)) {}
name_mapper_(std::move(name_mapper)),
last_instruction_comment_alignment_(0) {}
void InstructionDisassembler::EmitHeaderSpirv() { stream_ << "; SPIR-V\n"; }
@ -246,47 +267,119 @@ void InstructionDisassembler::EmitInstruction(
const spv_parsed_instruction_t& inst, size_t inst_byte_offset) {
auto opcode = static_cast<spv::Op>(inst.opcode);
// To better align the comments (if any), write the instruction to a line
// first so its length can be readily available.
std::ostringstream line;
if (inst.result_id) {
SetBlue();
const std::string id_name = name_mapper_(inst.result_id);
if (indent_)
stream_ << std::setw(std::max(0, indent_ - 3 - int(id_name.size())));
stream_ << "%" << id_name;
line << std::setw(std::max(0, indent_ - 3 - int(id_name.size())));
line << "%" << id_name;
ResetColor();
stream_ << " = ";
line << " = ";
} else {
stream_ << std::string(indent_, ' ');
line << std::string(indent_, ' ');
}
stream_ << "Op" << spvOpcodeString(opcode);
line << "Op" << spvOpcodeString(opcode);
for (uint16_t i = 0; i < inst.num_operands; i++) {
const spv_operand_type_t type = inst.operands[i].type;
assert(type != SPV_OPERAND_TYPE_NONE);
if (type == SPV_OPERAND_TYPE_RESULT_ID) continue;
stream_ << " ";
EmitOperand(inst, i);
line << " ";
EmitOperand(line, inst, i);
}
// For the sake of comment generation, store information from some
// instructions for the future.
if (comment_) {
GenerateCommentForDecoratedId(inst);
}
std::ostringstream comments;
const char* comment_separator = "";
if (show_byte_offset_) {
SetGrey(comments);
auto saved_flags = comments.flags();
auto saved_fill = comments.fill();
comments << comment_separator << "0x" << std::setw(8) << std::hex
<< std::setfill('0') << inst_byte_offset;
comments.flags(saved_flags);
comments.fill(saved_fill);
ResetColor(comments);
comment_separator = ", ";
}
if (comment_ && opcode == spv::Op::OpName) {
const spv_parsed_operand_t& operand = inst.operands[0];
const uint32_t word = inst.words[operand.offset];
stream_ << " ; id %" << word;
comments << comment_separator << "id %" << word;
comment_separator = ", ";
}
if (show_byte_offset_) {
SetGrey();
auto saved_flags = stream_.flags();
auto saved_fill = stream_.fill();
stream_ << " ; 0x" << std::setw(8) << std::hex << std::setfill('0')
<< inst_byte_offset;
stream_.flags(saved_flags);
stream_.fill(saved_fill);
ResetColor();
if (comment_ && inst.result_id && id_comments_.count(inst.result_id) > 0) {
comments << comment_separator << id_comments_[inst.result_id].str();
comment_separator = ", ";
}
stream_ << line.str();
if (!comments.str().empty()) {
// Align the comments
const uint32_t line_length = GetLineLengthWithoutColor(line.str());
uint32_t align = std::max(
{line_length + 2, last_instruction_comment_alignment_, kCommentColumn});
// Round up the alignment to a multiple of 4 for more niceness.
align = (align + 3) & ~0x3u;
last_instruction_comment_alignment_ = align;
stream_ << std::string(align - line_length, ' ') << "; " << comments.str();
} else {
last_instruction_comment_alignment_ = 0;
}
stream_ << "\n";
}
void InstructionDisassembler::GenerateCommentForDecoratedId(
const spv_parsed_instruction_t& inst) {
assert(comment_);
auto opcode = static_cast<spv::Op>(inst.opcode);
std::ostringstream partial;
uint32_t id = 0;
const char* separator = "";
switch (opcode) {
case spv::Op::OpDecorate:
// Take everything after `OpDecorate %id` and associate it with id.
id = inst.words[inst.operands[0].offset];
for (uint16_t i = 1; i < inst.num_operands; i++) {
partial << separator;
separator = " ";
EmitOperand(partial, inst, i);
}
break;
default:
break;
}
if (id == 0) {
return;
}
// Add the new comment to the comments of this id
std::ostringstream& id_comment = id_comments_[id];
if (!id_comment.str().empty()) {
id_comment << ", ";
}
id_comment << partial.str();
}
void InstructionDisassembler::EmitSectionComment(
const spv_parsed_instruction_t& inst, bool& inserted_decoration_space,
bool& inserted_debug_space, bool& inserted_type_space) {
@ -316,36 +409,37 @@ void InstructionDisassembler::EmitSectionComment(
}
}
void InstructionDisassembler::EmitOperand(const spv_parsed_instruction_t& inst,
const uint16_t operand_index) {
void InstructionDisassembler::EmitOperand(std::ostream& stream,
const spv_parsed_instruction_t& inst,
const uint16_t operand_index) const {
assert(operand_index < inst.num_operands);
const spv_parsed_operand_t& operand = inst.operands[operand_index];
const uint32_t word = inst.words[operand.offset];
switch (operand.type) {
case SPV_OPERAND_TYPE_RESULT_ID:
assert(false && "<result-id> is not supposed to be handled here");
SetBlue();
stream_ << "%" << name_mapper_(word);
SetBlue(stream);
stream << "%" << name_mapper_(word);
break;
case SPV_OPERAND_TYPE_ID:
case SPV_OPERAND_TYPE_TYPE_ID:
case SPV_OPERAND_TYPE_SCOPE_ID:
case SPV_OPERAND_TYPE_MEMORY_SEMANTICS_ID:
SetYellow();
stream_ << "%" << name_mapper_(word);
SetYellow(stream);
stream << "%" << name_mapper_(word);
break;
case SPV_OPERAND_TYPE_EXTENSION_INSTRUCTION_NUMBER: {
spv_ext_inst_desc ext_inst;
SetRed();
SetRed(stream);
if (grammar_.lookupExtInst(inst.ext_inst_type, word, &ext_inst) ==
SPV_SUCCESS) {
stream_ << ext_inst->name;
stream << ext_inst->name;
} else {
if (!spvExtInstIsNonSemantic(inst.ext_inst_type)) {
assert(false && "should have caught this earlier");
} else {
// for non-semantic instruction sets we can just print the number
stream_ << word;
stream << word;
}
}
} break;
@ -353,27 +447,27 @@ void InstructionDisassembler::EmitOperand(const spv_parsed_instruction_t& inst,
spv_opcode_desc opcode_desc;
if (grammar_.lookupOpcode(spv::Op(word), &opcode_desc))
assert(false && "should have caught this earlier");
SetRed();
stream_ << opcode_desc->name;
SetRed(stream);
stream << opcode_desc->name;
} break;
case SPV_OPERAND_TYPE_LITERAL_INTEGER:
case SPV_OPERAND_TYPE_TYPED_LITERAL_NUMBER:
case SPV_OPERAND_TYPE_LITERAL_FLOAT: {
SetRed();
EmitNumericLiteral(&stream_, inst, operand);
ResetColor();
SetRed(stream);
EmitNumericLiteral(&stream, inst, operand);
ResetColor(stream);
} break;
case SPV_OPERAND_TYPE_LITERAL_STRING: {
stream_ << "\"";
SetGreen();
stream << "\"";
SetGreen(stream);
std::string str = spvDecodeLiteralStringOperand(inst, operand_index);
for (char const& c : str) {
if (c == '"' || c == '\\') stream_ << '\\';
stream_ << c;
if (c == '"' || c == '\\') stream << '\\';
stream << c;
}
ResetColor();
stream_ << '"';
ResetColor(stream);
stream << '"';
} break;
case SPV_OPERAND_TYPE_CAPABILITY:
case SPV_OPERAND_TYPE_SOURCE_LANGUAGE:
@ -415,7 +509,7 @@ void InstructionDisassembler::EmitOperand(const spv_parsed_instruction_t& inst,
spv_operand_desc entry;
if (grammar_.lookupOperand(operand.type, word, &entry))
assert(false && "should have caught this earlier");
stream_ << entry->name;
stream << entry->name;
} break;
case SPV_OPERAND_TYPE_FP_FAST_MATH_MODE:
case SPV_OPERAND_TYPE_FUNCTION_CONTROL:
@ -426,26 +520,27 @@ void InstructionDisassembler::EmitOperand(const spv_parsed_instruction_t& inst,
case SPV_OPERAND_TYPE_DEBUG_INFO_FLAGS:
case SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_INFO_FLAGS:
case SPV_OPERAND_TYPE_RAW_ACCESS_CHAIN_OPERANDS:
EmitMaskOperand(operand.type, word);
EmitMaskOperand(stream, operand.type, word);
break;
default:
if (spvOperandIsConcreteMask(operand.type)) {
EmitMaskOperand(operand.type, word);
EmitMaskOperand(stream, operand.type, word);
} else if (spvOperandIsConcrete(operand.type)) {
spv_operand_desc entry;
if (grammar_.lookupOperand(operand.type, word, &entry))
assert(false && "should have caught this earlier");
stream_ << entry->name;
stream << entry->name;
} else {
assert(false && "unhandled or invalid case");
}
break;
}
ResetColor();
ResetColor(stream);
}
void InstructionDisassembler::EmitMaskOperand(const spv_operand_type_t type,
const uint32_t word) {
void InstructionDisassembler::EmitMaskOperand(std::ostream& stream,
const spv_operand_type_t type,
const uint32_t word) const {
// Scan the mask from least significant bit to most significant bit. For each
// set bit, emit the name of that bit. Separate multiple names with '|'.
uint32_t remaining_word = word;
@ -457,8 +552,8 @@ void InstructionDisassembler::EmitMaskOperand(const spv_operand_type_t type,
spv_operand_desc entry;
if (grammar_.lookupOperand(type, mask, &entry))
assert(false && "should have caught this earlier");
if (num_emitted) stream_ << "|";
stream_ << entry->name;
if (num_emitted) stream << "|";
stream << entry->name;
num_emitted++;
}
}
@ -467,28 +562,35 @@ void InstructionDisassembler::EmitMaskOperand(const spv_operand_type_t type,
// of the 0 value. In many cases, that's "None".
spv_operand_desc entry;
if (SPV_SUCCESS == grammar_.lookupOperand(type, 0, &entry))
stream_ << entry->name;
stream << entry->name;
}
}
void InstructionDisassembler::ResetColor() {
if (color_) stream_ << spvtools::clr::reset{print_};
void InstructionDisassembler::ResetColor(std::ostream& stream) const {
if (color_) stream << spvtools::clr::reset{print_};
}
void InstructionDisassembler::SetGrey() {
if (color_) stream_ << spvtools::clr::grey{print_};
void InstructionDisassembler::SetGrey(std::ostream& stream) const {
if (color_) stream << spvtools::clr::grey{print_};
}
void InstructionDisassembler::SetBlue() {
if (color_) stream_ << spvtools::clr::blue{print_};
void InstructionDisassembler::SetBlue(std::ostream& stream) const {
if (color_) stream << spvtools::clr::blue{print_};
}
void InstructionDisassembler::SetYellow() {
if (color_) stream_ << spvtools::clr::yellow{print_};
void InstructionDisassembler::SetYellow(std::ostream& stream) const {
if (color_) stream << spvtools::clr::yellow{print_};
}
void InstructionDisassembler::SetRed() {
if (color_) stream_ << spvtools::clr::red{print_};
void InstructionDisassembler::SetRed(std::ostream& stream) const {
if (color_) stream << spvtools::clr::red{print_};
}
void InstructionDisassembler::SetGreen() {
if (color_) stream_ << spvtools::clr::green{print_};
void InstructionDisassembler::SetGreen(std::ostream& stream) const {
if (color_) stream << spvtools::clr::green{print_};
}
void InstructionDisassembler::ResetColor() { ResetColor(stream_); }
void InstructionDisassembler::SetGrey() { SetGrey(stream_); }
void InstructionDisassembler::SetBlue() { SetBlue(stream_); }
void InstructionDisassembler::SetYellow() { SetYellow(stream_); }
void InstructionDisassembler::SetRed() { SetRed(stream_); }
void InstructionDisassembler::SetGreen() { SetGreen(stream_); }
} // namespace disassemble
std::string spvInstructionBinaryToText(const spv_target_env env,

View File

@ -16,6 +16,7 @@
#define SOURCE_DISASSEMBLE_H_
#include <iosfwd>
#include <sstream>
#include <string>
#include "source/name_mapper.h"
@ -74,13 +75,25 @@ class InstructionDisassembler {
void SetGreen();
private:
void ResetColor(std::ostream& stream) const;
void SetGrey(std::ostream& stream) const;
void SetBlue(std::ostream& stream) const;
void SetYellow(std::ostream& stream) const;
void SetRed(std::ostream& stream) const;
void SetGreen(std::ostream& stream) const;
// Emits an operand for the given instruction, where the instruction
// is at offset words from the start of the binary.
void EmitOperand(const spv_parsed_instruction_t& inst,
const uint16_t operand_index);
void EmitOperand(std::ostream& stream, const spv_parsed_instruction_t& inst,
const uint16_t operand_index) const;
// Emits a mask expression for the given mask word of the specified type.
void EmitMaskOperand(const spv_operand_type_t type, const uint32_t word);
void EmitMaskOperand(std::ostream& stream, const spv_operand_type_t type,
const uint32_t word) const;
// Generate part of the instruction as a comment to be added to
// |id_comments_|.
void GenerateCommentForDecoratedId(const spv_parsed_instruction_t& inst);
const spvtools::AssemblyGrammar& grammar_;
std::ostream& stream_;
@ -90,6 +103,13 @@ class InstructionDisassembler {
const int comment_; // Should we comment the source
const bool show_byte_offset_; // Should we print byte offset, in hex?
spvtools::NameMapper name_mapper_;
// Some comments are generated as instructions (such as OpDecorate) are
// visited so that when the instruction with that result id is visited, the
// comment can be output.
std::unordered_map<uint32_t, std::ostringstream> id_comments_;
// Align the comments in consecutive lines for more readability.
uint32_t last_instruction_comment_alignment_;
};
} // namespace disassemble

View File

@ -494,16 +494,428 @@ OpMemoryModel Logical GLSL450
%2 = OpTypeVoid
)";
const std::string expected =
R"(OpCapability Shader ; 0x00000014
OpMemoryModel Logical GLSL450 ; 0x0000001c
%1 = OpTypeInt 32 0 ; 0x00000028
%2 = OpTypeVoid ; 0x00000038
R"(OpCapability Shader ; 0x00000014
OpMemoryModel Logical GLSL450 ; 0x0000001c
%1 = OpTypeInt 32 0 ; 0x00000028
%2 = OpTypeVoid ; 0x00000038
)";
EXPECT_THAT(EncodeAndDecodeSuccessfully(
input, SPV_BINARY_TO_TEXT_OPTION_SHOW_BYTE_OFFSET),
expected);
}
TEST_F(TextToBinaryTest, Comments) {
const std::string input = R"(OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %63 "main" %4 %22
OpExecutionMode %63 OriginUpperLeft
OpSource GLSL 450
OpName %4 "_ue"
OpName %8 "_uf"
OpName %11 "_ug"
OpName %12 "_uA"
OpMemberName %12 0 "_ux"
OpName %14 "_uc"
OpName %15 "_uB"
OpMemberName %15 0 "_ux"
OpName %20 "_ud"
OpName %22 "_ucol"
OpName %26 "ANGLEDepthRangeParams"
OpMemberName %26 0 "near"
OpMemberName %26 1 "far"
OpMemberName %26 2 "diff"
OpMemberName %26 3 "reserved"
OpName %27 "ANGLEUniformBlock"
OpMemberName %27 0 "viewport"
OpMemberName %27 1 "clipDistancesEnabled"
OpMemberName %27 2 "xfbActiveUnpaused"
OpMemberName %27 3 "xfbVerticesPerInstance"
OpMemberName %27 4 "numSamples"
OpMemberName %27 5 "xfbBufferOffsets"
OpMemberName %27 6 "acbBufferOffsets"
OpMemberName %27 7 "depthRange"
OpName %29 "ANGLEUniforms"
OpName %33 "_uc"
OpName %32 "_uh"
OpName %49 "_ux"
OpName %50 "_uy"
OpName %48 "_ui"
OpName %63 "main"
OpName %65 "param"
OpName %68 "param"
OpName %73 "param"
OpDecorate %4 Location 0
OpDecorate %8 RelaxedPrecision
OpDecorate %8 DescriptorSet 0
OpDecorate %8 Binding 0
OpDecorate %11 DescriptorSet 0
OpDecorate %11 Binding 1
OpMemberDecorate %12 0 Offset 0
OpMemberDecorate %12 0 RelaxedPrecision
OpDecorate %12 Block
OpDecorate %14 DescriptorSet 0
OpDecorate %14 Binding 2
OpMemberDecorate %15 0 Offset 0
OpMemberDecorate %15 0 RelaxedPrecision
OpDecorate %15 BufferBlock
OpDecorate %20 DescriptorSet 0
OpDecorate %20 Binding 3
OpDecorate %22 RelaxedPrecision
OpDecorate %22 Location 0
OpMemberDecorate %26 0 Offset 0
OpMemberDecorate %26 1 Offset 4
OpMemberDecorate %26 2 Offset 8
OpMemberDecorate %26 3 Offset 12
OpMemberDecorate %27 0 Offset 0
OpMemberDecorate %27 1 Offset 16
OpMemberDecorate %27 2 Offset 20
OpMemberDecorate %27 3 Offset 24
OpMemberDecorate %27 4 Offset 28
OpMemberDecorate %27 5 Offset 32
OpMemberDecorate %27 6 Offset 48
OpMemberDecorate %27 7 Offset 64
OpMemberDecorate %27 2 RelaxedPrecision
OpMemberDecorate %27 4 RelaxedPrecision
OpDecorate %27 Block
OpDecorate %29 DescriptorSet 0
OpDecorate %29 Binding 4
OpDecorate %32 RelaxedPrecision
OpDecorate %33 RelaxedPrecision
OpDecorate %36 RelaxedPrecision
OpDecorate %37 RelaxedPrecision
OpDecorate %38 RelaxedPrecision
OpDecorate %39 RelaxedPrecision
OpDecorate %41 RelaxedPrecision
OpDecorate %42 RelaxedPrecision
OpDecorate %43 RelaxedPrecision
OpDecorate %48 RelaxedPrecision
OpDecorate %49 RelaxedPrecision
OpDecorate %50 RelaxedPrecision
OpDecorate %52 RelaxedPrecision
OpDecorate %53 RelaxedPrecision
OpDecorate %54 RelaxedPrecision
OpDecorate %55 RelaxedPrecision
OpDecorate %56 RelaxedPrecision
OpDecorate %57 RelaxedPrecision
OpDecorate %58 RelaxedPrecision
OpDecorate %59 RelaxedPrecision
OpDecorate %60 RelaxedPrecision
OpDecorate %67 RelaxedPrecision
OpDecorate %68 RelaxedPrecision
OpDecorate %72 RelaxedPrecision
OpDecorate %73 RelaxedPrecision
OpDecorate %75 RelaxedPrecision
OpDecorate %76 RelaxedPrecision
OpDecorate %77 RelaxedPrecision
OpDecorate %80 RelaxedPrecision
OpDecorate %81 RelaxedPrecision
%1 = OpTypeFloat 32
%2 = OpTypeVector %1 4
%5 = OpTypeImage %1 2D 0 0 0 1 Unknown
%6 = OpTypeSampledImage %5
%9 = OpTypeImage %1 2D 0 0 0 2 Rgba8
%12 = OpTypeStruct %2
%15 = OpTypeStruct %2
%16 = OpTypeInt 32 0
%17 = OpConstant %16 2
%18 = OpTypeArray %15 %17
%23 = OpTypeInt 32 1
%24 = OpTypeVector %23 4
%25 = OpTypeVector %16 4
%26 = OpTypeStruct %1 %1 %1 %1
%27 = OpTypeStruct %2 %16 %16 %23 %23 %24 %25 %26
%35 = OpTypeVector %1 2
%40 = OpTypeVector %23 2
%61 = OpTypeVoid
%69 = OpConstant %16 0
%78 = OpConstant %16 1
%3 = OpTypePointer Input %2
%7 = OpTypePointer UniformConstant %6
%10 = OpTypePointer UniformConstant %9
%13 = OpTypePointer Uniform %12
%19 = OpTypePointer Uniform %18
%21 = OpTypePointer Output %2
%28 = OpTypePointer Uniform %27
%30 = OpTypePointer Function %2
%70 = OpTypePointer Uniform %2
%31 = OpTypeFunction %2 %30
%47 = OpTypeFunction %2 %30 %30
%62 = OpTypeFunction %61
%4 = OpVariable %3 Input
%8 = OpVariable %7 UniformConstant
%11 = OpVariable %10 UniformConstant
%14 = OpVariable %13 Uniform
%20 = OpVariable %19 Uniform
%22 = OpVariable %21 Output
%29 = OpVariable %28 Uniform
%32 = OpFunction %2 None %31
%33 = OpFunctionParameter %30
%34 = OpLabel
%36 = OpLoad %6 %8
%37 = OpLoad %2 %33
%38 = OpVectorShuffle %35 %37 %37 0 1
%39 = OpImageSampleImplicitLod %2 %36 %38
%41 = OpLoad %2 %33
%42 = OpVectorShuffle %35 %41 %41 2 3
%43 = OpConvertFToS %40 %42
%44 = OpLoad %9 %11
%45 = OpImageRead %2 %44 %43
%46 = OpFAdd %2 %39 %45
OpReturnValue %46
OpFunctionEnd
%48 = OpFunction %2 None %47
%49 = OpFunctionParameter %30
%50 = OpFunctionParameter %30
%51 = OpLabel
%52 = OpLoad %2 %49
%53 = OpVectorShuffle %35 %52 %52 0 1
%54 = OpLoad %2 %50
%55 = OpVectorShuffle %35 %54 %54 2 3
%56 = OpCompositeExtract %1 %53 0
%57 = OpCompositeExtract %1 %53 1
%58 = OpCompositeExtract %1 %55 0
%59 = OpCompositeExtract %1 %55 1
%60 = OpCompositeConstruct %2 %56 %57 %58 %59
OpReturnValue %60
OpFunctionEnd
%63 = OpFunction %61 None %62
%64 = OpLabel
%65 = OpVariable %30 Function
%68 = OpVariable %30 Function
%73 = OpVariable %30 Function
%66 = OpLoad %2 %4
OpStore %65 %66
%67 = OpFunctionCall %2 %32 %65
%71 = OpAccessChain %70 %14 %69
%72 = OpLoad %2 %71
OpStore %68 %72
%74 = OpAccessChain %70 %20 %69 %69
%75 = OpLoad %2 %74
OpStore %73 %75
%76 = OpFunctionCall %2 %48 %68 %73
%77 = OpFAdd %2 %67 %76
%79 = OpAccessChain %70 %20 %78 %69
%80 = OpLoad %2 %79
%81 = OpFAdd %2 %77 %80
OpStore %22 %81
OpReturn
OpFunctionEnd
)";
const std::string expected = R"( OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %1 "main" %2 %3
OpExecutionMode %1 OriginUpperLeft
; Debug Information
OpSource GLSL 450
OpName %2 "_ue" ; id %2
OpName %4 "_uf" ; id %4
OpName %5 "_ug" ; id %5
OpName %6 "_uA" ; id %6
OpMemberName %6 0 "_ux"
OpName %7 "_uc" ; id %7
OpName %8 "_uB" ; id %8
OpMemberName %8 0 "_ux"
OpName %9 "_ud" ; id %9
OpName %3 "_ucol" ; id %3
OpName %10 "ANGLEDepthRangeParams" ; id %10
OpMemberName %10 0 "near"
OpMemberName %10 1 "far"
OpMemberName %10 2 "diff"
OpMemberName %10 3 "reserved"
OpName %11 "ANGLEUniformBlock" ; id %11
OpMemberName %11 0 "viewport"
OpMemberName %11 1 "clipDistancesEnabled"
OpMemberName %11 2 "xfbActiveUnpaused"
OpMemberName %11 3 "xfbVerticesPerInstance"
OpMemberName %11 4 "numSamples"
OpMemberName %11 5 "xfbBufferOffsets"
OpMemberName %11 6 "acbBufferOffsets"
OpMemberName %11 7 "depthRange"
OpName %12 "ANGLEUniforms" ; id %12
OpName %13 "_uc" ; id %13
OpName %14 "_uh" ; id %14
OpName %15 "_ux" ; id %15
OpName %16 "_uy" ; id %16
OpName %17 "_ui" ; id %17
OpName %1 "main" ; id %1
OpName %18 "param" ; id %18
OpName %19 "param" ; id %19
OpName %20 "param" ; id %20
; Annotations
OpDecorate %2 Location 0
OpDecorate %4 RelaxedPrecision
OpDecorate %4 DescriptorSet 0
OpDecorate %4 Binding 0
OpDecorate %5 DescriptorSet 0
OpDecorate %5 Binding 1
OpMemberDecorate %6 0 Offset 0
OpMemberDecorate %6 0 RelaxedPrecision
OpDecorate %6 Block
OpDecorate %7 DescriptorSet 0
OpDecorate %7 Binding 2
OpMemberDecorate %8 0 Offset 0
OpMemberDecorate %8 0 RelaxedPrecision
OpDecorate %8 BufferBlock
OpDecorate %9 DescriptorSet 0
OpDecorate %9 Binding 3
OpDecorate %3 RelaxedPrecision
OpDecorate %3 Location 0
OpMemberDecorate %10 0 Offset 0
OpMemberDecorate %10 1 Offset 4
OpMemberDecorate %10 2 Offset 8
OpMemberDecorate %10 3 Offset 12
OpMemberDecorate %11 0 Offset 0
OpMemberDecorate %11 1 Offset 16
OpMemberDecorate %11 2 Offset 20
OpMemberDecorate %11 3 Offset 24
OpMemberDecorate %11 4 Offset 28
OpMemberDecorate %11 5 Offset 32
OpMemberDecorate %11 6 Offset 48
OpMemberDecorate %11 7 Offset 64
OpMemberDecorate %11 2 RelaxedPrecision
OpMemberDecorate %11 4 RelaxedPrecision
OpDecorate %11 Block
OpDecorate %12 DescriptorSet 0
OpDecorate %12 Binding 4
OpDecorate %14 RelaxedPrecision
OpDecorate %13 RelaxedPrecision
OpDecorate %21 RelaxedPrecision
OpDecorate %22 RelaxedPrecision
OpDecorate %23 RelaxedPrecision
OpDecorate %24 RelaxedPrecision
OpDecorate %25 RelaxedPrecision
OpDecorate %26 RelaxedPrecision
OpDecorate %27 RelaxedPrecision
OpDecorate %17 RelaxedPrecision
OpDecorate %15 RelaxedPrecision
OpDecorate %16 RelaxedPrecision
OpDecorate %28 RelaxedPrecision
OpDecorate %29 RelaxedPrecision
OpDecorate %30 RelaxedPrecision
OpDecorate %31 RelaxedPrecision
OpDecorate %32 RelaxedPrecision
OpDecorate %33 RelaxedPrecision
OpDecorate %34 RelaxedPrecision
OpDecorate %35 RelaxedPrecision
OpDecorate %36 RelaxedPrecision
OpDecorate %37 RelaxedPrecision
OpDecorate %19 RelaxedPrecision
OpDecorate %38 RelaxedPrecision
OpDecorate %20 RelaxedPrecision
OpDecorate %39 RelaxedPrecision
OpDecorate %40 RelaxedPrecision
OpDecorate %41 RelaxedPrecision
OpDecorate %42 RelaxedPrecision
OpDecorate %43 RelaxedPrecision
; Types, variables and constants
%44 = OpTypeFloat 32
%45 = OpTypeVector %44 4
%46 = OpTypeImage %44 2D 0 0 0 1 Unknown
%47 = OpTypeSampledImage %46
%48 = OpTypeImage %44 2D 0 0 0 2 Rgba8
%6 = OpTypeStruct %45 ; Block
%8 = OpTypeStruct %45 ; BufferBlock
%49 = OpTypeInt 32 0
%50 = OpConstant %49 2
%51 = OpTypeArray %8 %50
%52 = OpTypeInt 32 1
%53 = OpTypeVector %52 4
%54 = OpTypeVector %49 4
%10 = OpTypeStruct %44 %44 %44 %44
%11 = OpTypeStruct %45 %49 %49 %52 %52 %53 %54 %10 ; Block
%55 = OpTypeVector %44 2
%56 = OpTypeVector %52 2
%57 = OpTypeVoid
%58 = OpConstant %49 0
%59 = OpConstant %49 1
%60 = OpTypePointer Input %45
%61 = OpTypePointer UniformConstant %47
%62 = OpTypePointer UniformConstant %48
%63 = OpTypePointer Uniform %6
%64 = OpTypePointer Uniform %51
%65 = OpTypePointer Output %45
%66 = OpTypePointer Uniform %11
%67 = OpTypePointer Function %45
%68 = OpTypePointer Uniform %45
%69 = OpTypeFunction %45 %67
%70 = OpTypeFunction %45 %67 %67
%71 = OpTypeFunction %57
%2 = OpVariable %60 Input ; Location 0
%4 = OpVariable %61 UniformConstant ; RelaxedPrecision, DescriptorSet 0, Binding 0
%5 = OpVariable %62 UniformConstant ; DescriptorSet 0, Binding 1
%7 = OpVariable %63 Uniform ; DescriptorSet 0, Binding 2
%9 = OpVariable %64 Uniform ; DescriptorSet 0, Binding 3
%3 = OpVariable %65 Output ; RelaxedPrecision, Location 0
%12 = OpVariable %66 Uniform ; DescriptorSet 0, Binding 4
; Function 14
%14 = OpFunction %45 None %69 ; RelaxedPrecision
%13 = OpFunctionParameter %67 ; RelaxedPrecision
%72 = OpLabel
%21 = OpLoad %47 %4 ; RelaxedPrecision
%22 = OpLoad %45 %13 ; RelaxedPrecision
%23 = OpVectorShuffle %55 %22 %22 0 1 ; RelaxedPrecision
%24 = OpImageSampleImplicitLod %45 %21 %23 ; RelaxedPrecision
%25 = OpLoad %45 %13 ; RelaxedPrecision
%26 = OpVectorShuffle %55 %25 %25 2 3 ; RelaxedPrecision
%27 = OpConvertFToS %56 %26 ; RelaxedPrecision
%73 = OpLoad %48 %5
%74 = OpImageRead %45 %73 %27
%75 = OpFAdd %45 %24 %74
OpReturnValue %75
OpFunctionEnd
; Function 17
%17 = OpFunction %45 None %70 ; RelaxedPrecision
%15 = OpFunctionParameter %67 ; RelaxedPrecision
%16 = OpFunctionParameter %67 ; RelaxedPrecision
%76 = OpLabel
%28 = OpLoad %45 %15 ; RelaxedPrecision
%29 = OpVectorShuffle %55 %28 %28 0 1 ; RelaxedPrecision
%30 = OpLoad %45 %16 ; RelaxedPrecision
%31 = OpVectorShuffle %55 %30 %30 2 3 ; RelaxedPrecision
%32 = OpCompositeExtract %44 %29 0 ; RelaxedPrecision
%33 = OpCompositeExtract %44 %29 1 ; RelaxedPrecision
%34 = OpCompositeExtract %44 %31 0 ; RelaxedPrecision
%35 = OpCompositeExtract %44 %31 1 ; RelaxedPrecision
%36 = OpCompositeConstruct %45 %32 %33 %34 %35 ; RelaxedPrecision
OpReturnValue %36
OpFunctionEnd
; Function 1
%1 = OpFunction %57 None %71
%77 = OpLabel
%18 = OpVariable %67 Function
%19 = OpVariable %67 Function ; RelaxedPrecision
%20 = OpVariable %67 Function ; RelaxedPrecision
%78 = OpLoad %45 %2
OpStore %18 %78
%37 = OpFunctionCall %45 %14 %18 ; RelaxedPrecision
%79 = OpAccessChain %68 %7 %58
%38 = OpLoad %45 %79 ; RelaxedPrecision
OpStore %19 %38
%80 = OpAccessChain %68 %9 %58 %58
%39 = OpLoad %45 %80 ; RelaxedPrecision
OpStore %20 %39
%40 = OpFunctionCall %45 %17 %19 %20 ; RelaxedPrecision
%41 = OpFAdd %45 %37 %40 ; RelaxedPrecision
%81 = OpAccessChain %68 %9 %59 %58
%42 = OpLoad %45 %81 ; RelaxedPrecision
%43 = OpFAdd %45 %41 %42 ; RelaxedPrecision
OpStore %3 %43
OpReturn
OpFunctionEnd
)";
EXPECT_THAT(
EncodeAndDecodeSuccessfully(input, SPV_BINARY_TO_TEXT_OPTION_COMMENT |
SPV_BINARY_TO_TEXT_OPTION_INDENT),
expected);
}
// Test version string.
TEST_F(TextToBinaryTest, VersionString) {
auto words = CompileSuccessfully("");