Skip to content

Commit

Permalink
Add SPIR-V 1.2 support, for OpenCL 2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dneto0 committed May 15, 2017
1 parent eb720b2 commit dbc2049
Show file tree
Hide file tree
Showing 34 changed files with 143 additions and 57 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Revision history for SPIRV-Tools

v2016.7-dev 2017-01-06
- Add SPIR-V 1.2
- OpenCL 2.2 support is now based on SPIR-V 1.2
- Optimizer: Add inlining of all function calls in entry points.
- Optimizer: Add flattening of decoration groups. Fixes #602
- Optimizer: Add Id compaction (minimize Id bound). Fixes #624
Expand Down
3 changes: 2 additions & 1 deletion include/spirv-tools/libspirv.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ typedef enum {
SPV_ENV_OPENGL_4_2, // OpenGL 4.2 plus GL_ARB_gl_spirv, latest revisions.
SPV_ENV_OPENGL_4_3, // OpenGL 4.3 plus GL_ARB_gl_spirv, latest revisions.
// There is no variant for OpenGL 4.4.
SPV_ENV_OPENGL_4_5, // OpenGL 4.5 plus GL_ARB_gl_spirv, latest revisions.
SPV_ENV_OPENGL_4_5, // OpenGL 4.5 plus GL_ARB_gl_spirv, latest revisions.
SPV_ENV_UNIVERSAL_1_2, // SPIR-V 1.2, latest revision, no other restrictions.
} spv_target_env;

// SPIR-V Validator can be parameterized with the following Universal Limits.
Expand Down
5 changes: 3 additions & 2 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,13 @@ endmacro(spvtools_vendor_tables)

spvtools_core_tables("1.0")
spvtools_core_tables("1.1")
spvtools_enum_string_mapping("1.1")
spvtools_core_tables("1.2")
spvtools_enum_string_mapping("1.2")
spvtools_opencl_tables("1.0")
spvtools_glsl_tables("1.0")
spvtools_vendor_tables("spv-amd-gcn-shader")

spvtools_vimsyntax("1.1" "1.0")
spvtools_vimsyntax("1.2" "1.0")
add_custom_target(spirv-tools-vimsyntax DEPENDS ${VIMSYNTAX_FILE})
set_property(TARGET spirv-tools-vimsyntax PROPERTY FOLDER "SPIRV-Tools utilities")

Expand Down
2 changes: 1 addition & 1 deletion source/assembly_grammar.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "operand.h"
#include "spirv-tools/libspirv.h"
#include "spirv/1.1/spirv.h"
#include "spirv/1.2/spirv.h"
#include "table.h"

namespace libspirv {
Expand Down
2 changes: 1 addition & 1 deletion source/binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "ext_inst.h"
#include "opcode.h"
#include "operand.h"
#include "spirv/1.1/spirv.h"
#include "spirv/1.2/spirv.h"
#include "spirv_constant.h"
#include "spirv_endian.h"

Expand Down
2 changes: 1 addition & 1 deletion source/enum_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <set>
#include <utility>

#include "spirv/1.1/spirv.h"
#include "spirv/1.2/spirv.h"

namespace libspirv {

Expand Down
1 change: 1 addition & 0 deletions source/ext_inst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ spv_result_t spvExtInstTableGet(spv_ext_inst_table* pExtInstTable,
case SPV_ENV_UNIVERSAL_1_0:
case SPV_ENV_VULKAN_1_0:
case SPV_ENV_UNIVERSAL_1_1:
case SPV_ENV_UNIVERSAL_1_2:
case SPV_ENV_OPENCL_2_1:
case SPV_ENV_OPENCL_2_2:
case SPV_ENV_OPENGL_4_0:
Expand Down
2 changes: 1 addition & 1 deletion source/instruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <vector>

#include "spirv-tools/libspirv.h"
#include "spirv/1.1/spirv.h"
#include "spirv/1.2/spirv.h"

// Describes an instruction.
struct spv_instruction_t {
Expand Down
2 changes: 1 addition & 1 deletion source/name_mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <unordered_set>

#include "spirv-tools/libspirv.h"
#include "spirv/1.1/spirv.h"
#include "spirv/1.2/spirv.h"

#include "parsed_operand.h"

Expand Down
16 changes: 12 additions & 4 deletions source/opcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const spv_opcode_desc_t opcodeTableEntries_1_0[] = {
const spv_opcode_desc_t opcodeTableEntries_1_1[] = {
#include "core.insts-1.1.inc"
};
const spv_opcode_desc_t opcodeTableEntries_1_2[] = {
#include "core.insts-1.2.inc"
};

// Represents a vendor tool entry in the SPIR-V XML Regsitry.
struct VendorTool {
Expand Down Expand Up @@ -83,6 +86,8 @@ spv_result_t spvOpcodeTableGet(spv_opcode_table* pInstTable,
ARRAY_SIZE(opcodeTableEntries_1_0), opcodeTableEntries_1_0};
static const spv_opcode_table_t table_1_1 = {
ARRAY_SIZE(opcodeTableEntries_1_1), opcodeTableEntries_1_1};
static const spv_opcode_table_t table_1_2 = {
ARRAY_SIZE(opcodeTableEntries_1_2), opcodeTableEntries_1_2};

switch (env) {
case SPV_ENV_UNIVERSAL_1_0:
Expand All @@ -96,9 +101,12 @@ spv_result_t spvOpcodeTableGet(spv_opcode_table* pInstTable,
*pInstTable = &table_1_0;
return SPV_SUCCESS;
case SPV_ENV_UNIVERSAL_1_1:
case SPV_ENV_OPENCL_2_2:
*pInstTable = &table_1_1;
return SPV_SUCCESS;
case SPV_ENV_UNIVERSAL_1_2:
case SPV_ENV_OPENCL_2_2:
*pInstTable = &table_1_2;
return SPV_SUCCESS;
}
assert(0 && "Unknown spv_target_env in spvOpcodeTableGet()");
return SPV_ERROR_INVALID_TABLE;
Expand Down Expand Up @@ -165,9 +173,9 @@ void spvInstructionCopy(const uint32_t* words, const SpvOp opcode,
const char* spvOpcodeString(const SpvOp opcode) {
// Use the latest SPIR-V version, which should be backward-compatible with all
// previous ones.
for (uint32_t i = 0; i < ARRAY_SIZE(opcodeTableEntries_1_1); ++i) {
if (opcodeTableEntries_1_1[i].opcode == opcode)
return opcodeTableEntries_1_1[i].name;
for (uint32_t i = 0; i < ARRAY_SIZE(opcodeTableEntries_1_2); ++i) {
if (opcodeTableEntries_1_2[i].opcode == opcode)
return opcodeTableEntries_1_2[i].name;
}
assert(0 && "Unreachable!");
return "unknown";
Expand Down
2 changes: 1 addition & 1 deletion source/opcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "instruction.h"
#include "spirv-tools/libspirv.h"
#include "spirv/1.1/spirv.h"
#include "spirv/1.2/spirv.h"
#include "table.h"

// Returns the name of a registered SPIR-V generator as a null-terminated
Expand Down
11 changes: 10 additions & 1 deletion source/operand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ namespace v1_0 {
namespace v1_1 {
#include "operand.kinds-1.1.inc"
} // namespace v1_1
namespace v1_2 {
#include "operand.kinds-1.2.inc"
} // namespace v1_2

spv_result_t spvOperandTableGet(spv_operand_table* pOperandTable,
spv_target_env env) {
Expand All @@ -37,6 +40,9 @@ spv_result_t spvOperandTableGet(spv_operand_table* pOperandTable,
static const spv_operand_table_t table_1_1 = {
ARRAY_SIZE(v1_1::pygen_variable_OperandInfoTable),
v1_1::pygen_variable_OperandInfoTable};
static const spv_operand_table_t table_1_2 = {
ARRAY_SIZE(v1_2::pygen_variable_OperandInfoTable),
v1_2::pygen_variable_OperandInfoTable};

switch (env) {
case SPV_ENV_UNIVERSAL_1_0:
Expand All @@ -50,9 +56,12 @@ spv_result_t spvOperandTableGet(spv_operand_table* pOperandTable,
*pOperandTable = &table_1_0;
return SPV_SUCCESS;
case SPV_ENV_UNIVERSAL_1_1:
case SPV_ENV_OPENCL_2_2:
*pOperandTable = &table_1_1;
return SPV_SUCCESS;
case SPV_ENV_UNIVERSAL_1_2:
case SPV_ENV_OPENCL_2_2:
*pOperandTable = &table_1_2;
return SPV_SUCCESS;
}
assert(0 && "Unknown spv_target_env in spvOperandTableGet()");
return SPV_ERROR_INVALID_TABLE;
Expand Down
2 changes: 1 addition & 1 deletion source/opt/instruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "operand.h"

#include "spirv-tools/libspirv.h"
#include "spirv/1.1/spirv.h"
#include "spirv/1.2/spirv.h"

namespace spvtools {
namespace ir {
Expand Down
2 changes: 1 addition & 1 deletion source/opt/reflect.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef LIBSPIRV_OPT_REFLECT_H_
#define LIBSPIRV_OPT_REFLECT_H_

#include "spirv/1.1/spirv.h"
#include "spirv/1.2/spirv.h"

namespace spvtools {
namespace ir {
Expand Down
2 changes: 1 addition & 1 deletion source/opt/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <vector>

#include "spirv-tools/libspirv.h"
#include "spirv/1.1/spirv.h"
#include "spirv/1.2/spirv.h"

namespace spvtools {
namespace opt {
Expand Down
2 changes: 1 addition & 1 deletion source/spirv_constant.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define LIBSPIRV_SPIRV_CONSTANT_H_

#include "spirv-tools/libspirv.h"
#include "spirv/1.1/spirv.h"
#include "spirv/1.2/spirv.h"

// Version number macros.

Expand Down
2 changes: 1 addition & 1 deletion source/spirv_definition.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include <cstdint>

#include "spirv/1.1/spirv.h"
#include "spirv/1.2/spirv.h"

#define spvIsInBitfield(value, bitfield) ((value) == ((value)&bitfield))

Expand Down
9 changes: 8 additions & 1 deletion source/spirv_target_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const char* spvTargetEnvDescription(spv_target_env env) {
return "SPIR-V 1.0 (under OpenCL 4.3 semantics)";
case SPV_ENV_OPENGL_4_5:
return "SPIR-V 1.0 (under OpenCL 4.5 semantics)";
case SPV_ENV_UNIVERSAL_1_2:
return "SPIR-V 1.2";
}
assert(0 && "Unhandled SPIR-V target environment");
return "";
Expand All @@ -57,8 +59,10 @@ uint32_t spvVersionForTargetEnv(spv_target_env env) {
case SPV_ENV_OPENGL_4_5:
return SPV_SPIRV_VERSION_WORD(1, 0);
case SPV_ENV_UNIVERSAL_1_1:
case SPV_ENV_OPENCL_2_2:
return SPV_SPIRV_VERSION_WORD(1, 1);
case SPV_ENV_UNIVERSAL_1_2:
case SPV_ENV_OPENCL_2_2:
return SPV_SPIRV_VERSION_WORD(1, 2);
}
assert(0 && "Unhandled SPIR-V target environment");
return SPV_SPIRV_VERSION_WORD(0, 0);
Expand All @@ -77,6 +81,9 @@ bool spvParseTargetEnv(const char* s, spv_target_env* env) {
} else if (match("spv1.1")) {
if (env) *env = SPV_ENV_UNIVERSAL_1_1;
return true;
} else if (match("spv1.2")) {
if (env) *env = SPV_ENV_UNIVERSAL_1_2;
return true;
} else if (match("opencl2.1")) {
if (env) *env = SPV_ENV_OPENCL_2_1;
return true;
Expand Down
1 change: 1 addition & 0 deletions source/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ spv_context spvContextCreate(spv_target_env env) {
case SPV_ENV_OPENGL_4_2:
case SPV_ENV_OPENGL_4_3:
case SPV_ENV_OPENGL_4_5:
case SPV_ENV_UNIVERSAL_1_2:
break;
default:
return nullptr;
Expand Down
4 changes: 1 addition & 3 deletions source/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
#ifndef LIBSPIRV_TABLE_H_
#define LIBSPIRV_TABLE_H_

#include <string>

#include "spirv/1.1/spirv.h"
#include "spirv/1.2/spirv.h"

#include "extensions.h"
#include "message.h"
Expand Down
2 changes: 1 addition & 1 deletion source/val/basic_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef LIBSPIRV_VAL_BASICBLOCK_H_
#define LIBSPIRV_VAL_BASICBLOCK_H_

#include "spirv/1.1/spirv.h"
#include "spirv/1.2/spirv.h"

#include <cstdint>

Expand Down
2 changes: 1 addition & 1 deletion source/val/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <vector>

#include "spirv-tools/libspirv.h"
#include "spirv/1.1/spirv.h"
#include "spirv/1.2/spirv.h"
#include "val/basic_block.h"
#include "val/construct.h"

Expand Down
2 changes: 1 addition & 1 deletion source/val/validation_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "diagnostic.h"
#include "enum_set.h"
#include "spirv-tools/libspirv.h"
#include "spirv/1.1/spirv.h"
#include "spirv/1.2/spirv.h"
#include "spirv_definition.h"
#include "val/function.h"
#include "val/instruction.h"
Expand Down
2 changes: 1 addition & 1 deletion test/binary_header_get_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ TEST_F(BinaryHeaderGet, Default) {
ASSERT_EQ(SPV_SUCCESS, spvBinaryHeaderGet(&const_bin, endian, &header));

ASSERT_EQ(static_cast<uint32_t>(SpvMagicNumber), header.magic);
ASSERT_EQ(0x00010100u, header.version);
ASSERT_EQ(0x00010200u, header.version);
ASSERT_EQ(static_cast<uint32_t>(SPV_GENERATOR_CODEPLAY), header.generator);
ASSERT_EQ(1u, header.bound);
ASSERT_EQ(0u, header.schema);
Expand Down
Loading

0 comments on commit dbc2049

Please sign in to comment.