mirror of
https://github.com/RPCSX/SPIRV-Tools.git
synced 2024-12-13 14:16:01 +00:00
The version header word has 3 byte-size components.
Bits 24-31: 0 Bits 16-23: SPIR-V major number (1) Bits 8-15: SPIR-V minor number (0) Bits 0-7: SPIR-V minor number (2) The assembler will construct the word appropriately, and the disassemble will print it in major.minor.revision form.
This commit is contained in:
parent
14b93e49ed
commit
3d348a8440
@ -38,6 +38,14 @@ extern "C" {
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// Versions
|
||||
// This library is based on SPIR-V 1.0 Rev2
|
||||
// TODO(dneto): Use the values from the SPIR-V header, when it's updated for
|
||||
// SPIR-V 1.0 public release.
|
||||
#define SPV_SPIRV_VERSION_MAJOR 1
|
||||
#define SPV_SPIRV_VERSION_MINOR 0
|
||||
#define SPV_SPIRV_VERSION_REVISION 2
|
||||
|
||||
// Helpers
|
||||
|
||||
#define spvIsInBitfield(value, bitfield) (value == (value & bitfield))
|
||||
|
@ -135,7 +135,9 @@ spv_result_t Disassembler::HandleHeader(spv_endianness_t endian,
|
||||
const char* generator_tool =
|
||||
spvGeneratorStr(SPV_GENERATOR_TOOL_PART(generator));
|
||||
stream_ << "; SPIR-V\n"
|
||||
<< "; Version: " << version << "\n"
|
||||
<< "; Version: " << SPV_SPIRV_VERSION_MAJOR_PART(version) << "."
|
||||
<< SPV_SPIRV_VERSION_MINOR_PART(version) << "."
|
||||
<< SPV_SPIRV_VERSION_REVISION_PART(version) << "\n"
|
||||
<< "; Generator: " << generator_tool;
|
||||
// For unknown tools, print the numeric tool value.
|
||||
if (0 == strcmp("Unknown", generator_tool)) {
|
||||
|
@ -29,6 +29,20 @@
|
||||
|
||||
#include "libspirv/libspirv.h"
|
||||
|
||||
// Version number macros.
|
||||
|
||||
// Evaluates to a well-formed version header word, given valid
|
||||
// SPIR-V version major, minor, and revision numbers.
|
||||
#define SPV_SPIRV_VERSION_WORD(MAJOR, MINOR, REVISION) \
|
||||
((uint32_t(uint8_t(MAJOR)) << 16) | (uint32_t(uint8_t(MINOR)) << 8) | \
|
||||
uint8_t(REVISION))
|
||||
// Returns the major version extracted from a version header word.
|
||||
#define SPV_SPIRV_VERSION_MAJOR_PART(WORD) ((uint32_t(WORD) >> 16) & 0xff)
|
||||
// Returns the minor version extracted from a version header word.
|
||||
#define SPV_SPIRV_VERSION_MINOR_PART(WORD) ((uint32_t(WORD) >> 8) & 0xff)
|
||||
// Returns the revision number extracted from a version header word.
|
||||
#define SPV_SPIRV_VERSION_REVISION_PART(WORD) (uint32_t(WORD) & 0xff)
|
||||
|
||||
// Header indices
|
||||
|
||||
#define SPV_INDEX_MAGIC_NUMBER 0u
|
||||
|
@ -667,7 +667,9 @@ SetHeader(uint32_t* words, const uint32_t bound) {
|
||||
if (!words) return SPV_ERROR_INVALID_BINARY;
|
||||
|
||||
words[SPV_INDEX_MAGIC_NUMBER] = SpvMagicNumber;
|
||||
words[SPV_INDEX_VERSION_NUMBER] = SpvVersion;
|
||||
words[SPV_INDEX_VERSION_NUMBER] =
|
||||
SPV_SPIRV_VERSION_WORD(SPV_SPIRV_VERSION_MAJOR, SPV_SPIRV_VERSION_MINOR,
|
||||
SPV_SPIRV_VERSION_REVISION);
|
||||
words[SPV_INDEX_GENERATOR_NUMBER] =
|
||||
SPV_GENERATOR_WORD(SPV_GENERATOR_KHRONOS_ASSEMBLER, kAssemblerVersion);
|
||||
words[SPV_INDEX_BOUND] = bound;
|
||||
|
@ -395,6 +395,25 @@ OpStore %2 %3 Aligned|Volatile 4 ; bogus, but not indented
|
||||
expected);
|
||||
}
|
||||
|
||||
// Test version string.
|
||||
TEST_F(TextToBinaryTest, VersionString) {
|
||||
auto words = CompileSuccessfully("");
|
||||
spv_text decoded_text = nullptr;
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
EXPECT_THAT(spvBinaryToText(context, words.data(), words.size(),
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE, &decoded_text,
|
||||
&diagnostic),
|
||||
Eq(SPV_SUCCESS));
|
||||
EXPECT_EQ(nullptr, diagnostic);
|
||||
|
||||
EXPECT_EQ(1, SPV_SPIRV_VERSION_MAJOR);
|
||||
EXPECT_EQ(0, SPV_SPIRV_VERSION_MINOR);
|
||||
EXPECT_EQ(2, SPV_SPIRV_VERSION_REVISION);
|
||||
EXPECT_THAT(decoded_text->str, HasSubstr("Version: 1.0.2\n"))
|
||||
<< EncodeAndDecodeSuccessfully("");
|
||||
spvTextDestroy(decoded_text);
|
||||
}
|
||||
|
||||
// Test generator string.
|
||||
|
||||
// A test case for the generator string. This allows us to
|
||||
|
@ -66,7 +66,7 @@ OpFunctionEnd
|
||||
)";
|
||||
const std::string spirv_header =
|
||||
R"(; SPIR-V
|
||||
; Version: 100
|
||||
; Version: 1.0.2
|
||||
; Generator: Khronos SPIR-V Tools Assembler; 0
|
||||
; Bound: 9
|
||||
; Schema: 0)";
|
||||
|
Loading…
Reference in New Issue
Block a user