Add support for SPV AMD extensions

This commit is contained in:
Rex Xu 2017-06-21 15:58:00 +08:00 committed by David Neto
parent 6136bf9e0b
commit 5fbbadca4e
9 changed files with 300 additions and 4 deletions

View File

@ -227,7 +227,10 @@ typedef enum spv_ext_inst_type_t {
SPV_EXT_INST_TYPE_NONE = 0,
SPV_EXT_INST_TYPE_GLSL_STD_450,
SPV_EXT_INST_TYPE_OPENCL_STD,
SPV_EXT_INST_TYPE_SPV_AMD_SHADER_EXPLICIT_VERTEX_PARAMETER,
SPV_EXT_INST_TYPE_SPV_AMD_SHADER_TRINARY_MINMAX,
SPV_EXT_INST_TYPE_SPV_AMD_GCN_SHADER,
SPV_EXT_INST_TYPE_SPV_AMD_SHADER_BALLOT,
SPV_FORCE_32_BIT_ENUM(spv_ext_inst_type_t)
} spv_ext_inst_type_t;

View File

@ -115,7 +115,10 @@ 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-shader-explicit-vertex-parameter")
spvtools_vendor_tables("spv-amd-shader-trinary-minmax")
spvtools_vendor_tables("spv-amd-gcn-shader")
spvtools_vendor_tables("spv-amd-shader-ballot")
spvtools_vimsyntax("1.2" "1.0")
add_custom_target(spirv-tools-vimsyntax DEPENDS ${VIMSYNTAX_FILE})

View File

@ -31,10 +31,22 @@ static const spv_ext_inst_desc_t openclEntries_1_0[] = {
#include "opencl.std.insts-1.0.inc"
};
static const spv_ext_inst_desc_t spv_amd_shader_explicit_vertex_parameter_entries[] = {
#include "spv-amd-shader-explicit-vertex-parameter.insts.inc"
};
static const spv_ext_inst_desc_t spv_amd_shader_trinary_minmax_entries[] = {
#include "spv-amd-shader-trinary-minmax.insts.inc"
};
static const spv_ext_inst_desc_t spv_amd_gcn_shader_entries[] = {
#include "spv-amd-gcn-shader.insts.inc"
};
static const spv_ext_inst_desc_t spv_amd_shader_ballot_entries[] = {
#include "spv-amd-shader-ballot.insts.inc"
};
spv_result_t spvExtInstTableGet(spv_ext_inst_table* pExtInstTable,
spv_target_env env) {
if (!pExtInstTable) return SPV_ERROR_INVALID_POINTER;
@ -44,8 +56,14 @@ spv_result_t spvExtInstTableGet(spv_ext_inst_table* pExtInstTable,
glslStd450Entries_1_0},
{SPV_EXT_INST_TYPE_OPENCL_STD, ARRAY_SIZE(openclEntries_1_0),
openclEntries_1_0},
{SPV_EXT_INST_TYPE_SPV_AMD_SHADER_EXPLICIT_VERTEX_PARAMETER,
ARRAY_SIZE(spv_amd_shader_explicit_vertex_parameter_entries), spv_amd_shader_explicit_vertex_parameter_entries},
{SPV_EXT_INST_TYPE_SPV_AMD_SHADER_TRINARY_MINMAX,
ARRAY_SIZE(spv_amd_shader_trinary_minmax_entries), spv_amd_shader_trinary_minmax_entries},
{SPV_EXT_INST_TYPE_SPV_AMD_GCN_SHADER,
ARRAY_SIZE(spv_amd_gcn_shader_entries), spv_amd_gcn_shader_entries},
{SPV_EXT_INST_TYPE_SPV_AMD_SHADER_BALLOT,
ARRAY_SIZE(spv_amd_shader_ballot_entries), spv_amd_shader_ballot_entries},
};
static const spv_ext_inst_table_t table_1_0 = {ARRAY_SIZE(groups_1_0),
@ -81,9 +99,18 @@ spv_ext_inst_type_t spvExtInstImportTypeGet(const char* name) {
if (!strcmp("OpenCL.std", name)) {
return SPV_EXT_INST_TYPE_OPENCL_STD;
}
if (!strcmp("SPV_AMD_shader_explicit_vertex_parameter", name)) {
return SPV_EXT_INST_TYPE_SPV_AMD_SHADER_EXPLICIT_VERTEX_PARAMETER;
}
if (!strcmp("SPV_AMD_shader_trinary_minmax", name)) {
return SPV_EXT_INST_TYPE_SPV_AMD_SHADER_TRINARY_MINMAX;
}
if (!strcmp("SPV_AMD_gcn_shader", name)) {
return SPV_EXT_INST_TYPE_SPV_AMD_GCN_SHADER;
}
if (!strcmp("SPV_AMD_shader_ballot", name)) {
return SPV_EXT_INST_TYPE_SPV_AMD_SHADER_BALLOT;
}
return SPV_EXT_INST_TYPE_NONE;
}

View File

@ -0,0 +1,41 @@
{
"revision" : 5,
"instructions" : [
{
"opname" : "SwizzleInvocationsAMD",
"opcode" : 1,
"operands" : [
{ "kind" : "IdRef", "name" : "'data'" },
{ "kind" : "IdRef", "name" : "'offset'" }
],
"extensions" : [ "SPV_AMD_shader_ballot" ]
},
{
"opname" : "SwizzleInvocationsMaskedAMD",
"opcode" : 2,
"operands" : [
{ "kind" : "IdRef", "name" : "'data'" },
{ "kind" : "IdRef", "name" : "'mask'" }
],
"extensions" : [ "SPV_AMD_shader_ballot" ]
},
{
"opname" : "WriteInvocationAMD",
"opcode" : 3,
"operands" : [
{ "kind" : "IdRef", "name" : "'inputValue'" },
{ "kind" : "IdRef", "name" : "'writeValue'" },
{ "kind" : "IdRef", "name" : "'invocationIndex'" }
],
"extensions" : [ "SPV_AMD_shader_ballot" ]
},
{
"opname" : "MbcntAMD",
"opcode" : 4,
"operands" : [
{ "kind" : "IdRef", "name" : "'mask'" }
],
"extensions" : [ "SPV_AMD_shader_ballot" ]
}
]
}

View File

@ -0,0 +1,14 @@
{
"revision" : 4,
"instructions" : [
{
"opname" : "InterpolateAtVertexAMD",
"opcode" : 1,
"operands" : [
{ "kind" : "IdRef", "name" : "'interpolant'" },
{ "kind" : "IdRef", "name" : "'vertexIdx'" }
],
"extensions" : [ "SPV_AMD_shader_explicit_vertex_parameter" ]
}
]
}

View File

@ -0,0 +1,95 @@
{
"revision" : 4,
"instructions" : [
{
"opname" : "FMin3AMD",
"opcode" : 1,
"operands" : [
{ "kind" : "IdRef", "name" : "'x'" },
{ "kind" : "IdRef", "name" : "'y'" },
{ "kind" : "IdRef", "name" : "'z'" }
],
"extensions" : [ "SPV_AMD_shader_trinary_minmax" ]
},
{
"opname" : "UMin3AMD",
"opcode" : 2,
"operands" : [
{ "kind" : "IdRef", "name" : "'x'" },
{ "kind" : "IdRef", "name" : "'y'" },
{ "kind" : "IdRef", "name" : "'z'" }
],
"extensions" : [ "SPV_AMD_shader_trinary_minmax" ]
},
{
"opname" : "SMin3AMD",
"opcode" : 3,
"operands" : [
{ "kind" : "IdRef", "name" : "'x'" },
{ "kind" : "IdRef", "name" : "'y'" },
{ "kind" : "IdRef", "name" : "'z'" }
],
"extensions" : [ "SPV_AMD_shader_trinary_minmax" ]
},
{
"opname" : "FMax3AMD",
"opcode" : 4,
"operands" : [
{ "kind" : "IdRef", "name" : "'x'" },
{ "kind" : "IdRef", "name" : "'y'" },
{ "kind" : "IdRef", "name" : "'z'" }
],
"extensions" : [ "SPV_AMD_shader_trinary_minmax" ]
},
{
"opname" : "UMax3AMD",
"opcode" : 5,
"operands" : [
{ "kind" : "IdRef", "name" : "'x'" },
{ "kind" : "IdRef", "name" : "'y'" },
{ "kind" : "IdRef", "name" : "'z'" }
],
"extensions" : [ "SPV_AMD_shader_trinary_minmax" ]
},
{
"opname" : "SMax3AMD",
"opcode" : 6,
"operands" : [
{ "kind" : "IdRef", "name" : "'x'" },
{ "kind" : "IdRef", "name" : "'y'" },
{ "kind" : "IdRef", "name" : "'z'" }
],
"extensions" : [ "SPV_AMD_shader_trinary_minmax" ]
},
{
"opname" : "FMid3AMD",
"opcode" : 7,
"operands" : [
{ "kind" : "IdRef", "name" : "'x'" },
{ "kind" : "IdRef", "name" : "'y'" },
{ "kind" : "IdRef", "name" : "'z'" }
],
"extensions" : [ "SPV_AMD_shader_trinary_minmax" ]
},
{
"opname" : "UMid3AMD",
"opcode" : 8,
"operands" : [
{ "kind" : "IdRef", "name" : "'x'" },
{ "kind" : "IdRef", "name" : "'y'" },
{ "kind" : "IdRef", "name" : "'z'" }
],
"extensions" : [ "SPV_AMD_shader_trinary_minmax" ]
},
{
"opname" : "SMid3AMD",
"opcode" : 9,
"operands" : [
{ "kind" : "IdRef", "name" : "'x'" },
{ "kind" : "IdRef", "name" : "'y'" },
{ "kind" : "IdRef", "name" : "'z'" }
],
"extensions" : [ "SPV_AMD_shader_trinary_minmax" ]
}
]
}

View File

@ -278,6 +278,74 @@ INSTANTIATE_TEST_CASE_P(
})), );
// SPV_AMD_shader_explicit_vertex_parameter
#define PREAMBLE "%1 = OpExtInstImport \"SPV_AMD_shader_explicit_vertex_parameter\"\n"
INSTANTIATE_TEST_CASE_P(
SPV_AMD_shader_explicit_vertex_parameter, ExtensionRoundTripTest,
// We'll get coverage over operand tables by trying the universal
// environments, and at least one specific environment.
Combine(Values(SPV_ENV_UNIVERSAL_1_0, SPV_ENV_UNIVERSAL_1_1,
SPV_ENV_VULKAN_1_0),
ValuesIn(std::vector<AssemblyCase>{
{PREAMBLE "%3 = OpExtInst %2 %1 InterpolateAtVertexAMD %4 %5\n",
Concatenate({MakeInstruction(SpvOpExtInstImport, {1},
MakeVector("SPV_AMD_shader_explicit_vertex_parameter")),
MakeInstruction(SpvOpExtInst, {2, 3, 1, 1, 4, 5})})},
})), );
#undef PREAMBLE
// SPV_AMD_shader_trinary_minmax
#define PREAMBLE "%1 = OpExtInstImport \"SPV_AMD_shader_trinary_minmax\"\n"
INSTANTIATE_TEST_CASE_P(
SPV_AMD_shader_trinary_minmax, ExtensionRoundTripTest,
// We'll get coverage over operand tables by trying the universal
// environments, and at least one specific environment.
Combine(Values(SPV_ENV_UNIVERSAL_1_0, SPV_ENV_UNIVERSAL_1_1,
SPV_ENV_VULKAN_1_0),
ValuesIn(std::vector<AssemblyCase>{
{PREAMBLE "%3 = OpExtInst %2 %1 FMin3AMD %4 %5 %6\n",
Concatenate({MakeInstruction(SpvOpExtInstImport, {1},
MakeVector("SPV_AMD_shader_trinary_minmax")),
MakeInstruction(SpvOpExtInst, {2, 3, 1, 1, 4, 5, 6})})},
{PREAMBLE "%3 = OpExtInst %2 %1 UMin3AMD %4 %5 %6\n",
Concatenate({MakeInstruction(SpvOpExtInstImport, {1},
MakeVector("SPV_AMD_shader_trinary_minmax")),
MakeInstruction(SpvOpExtInst, {2, 3, 1, 2, 4, 5, 6})})},
{PREAMBLE "%3 = OpExtInst %2 %1 SMin3AMD %4 %5 %6\n",
Concatenate({MakeInstruction(SpvOpExtInstImport, {1},
MakeVector("SPV_AMD_shader_trinary_minmax")),
MakeInstruction(SpvOpExtInst, {2, 3, 1, 3, 4, 5, 6})})},
{PREAMBLE "%3 = OpExtInst %2 %1 FMax3AMD %4 %5 %6\n",
Concatenate({MakeInstruction(SpvOpExtInstImport, {1},
MakeVector("SPV_AMD_shader_trinary_minmax")),
MakeInstruction(SpvOpExtInst, {2, 3, 1, 4, 4, 5, 6})})},
{PREAMBLE "%3 = OpExtInst %2 %1 UMax3AMD %4 %5 %6\n",
Concatenate({MakeInstruction(SpvOpExtInstImport, {1},
MakeVector("SPV_AMD_shader_trinary_minmax")),
MakeInstruction(SpvOpExtInst, {2, 3, 1, 5, 4, 5, 6})})},
{PREAMBLE "%3 = OpExtInst %2 %1 SMax3AMD %4 %5 %6\n",
Concatenate({MakeInstruction(SpvOpExtInstImport, {1},
MakeVector("SPV_AMD_shader_trinary_minmax")),
MakeInstruction(SpvOpExtInst, {2, 3, 1, 6, 4, 5, 6})})},
{PREAMBLE "%3 = OpExtInst %2 %1 FMid3AMD %4 %5 %6\n",
Concatenate({MakeInstruction(SpvOpExtInstImport, {1},
MakeVector("SPV_AMD_shader_trinary_minmax")),
MakeInstruction(SpvOpExtInst, {2, 3, 1, 7, 4, 5, 6})})},
{PREAMBLE "%3 = OpExtInst %2 %1 UMid3AMD %4 %5 %6\n",
Concatenate({MakeInstruction(SpvOpExtInstImport, {1},
MakeVector("SPV_AMD_shader_trinary_minmax")),
MakeInstruction(SpvOpExtInst, {2, 3, 1, 8, 4, 5, 6})})},
{PREAMBLE "%3 = OpExtInst %2 %1 SMid3AMD %4 %5 %6\n",
Concatenate({MakeInstruction(SpvOpExtInstImport, {1},
MakeVector("SPV_AMD_shader_trinary_minmax")),
MakeInstruction(SpvOpExtInst, {2, 3, 1, 9, 4, 5, 6})})},
})), );
#undef PREAMBLE
// SPV_AMD_gcn_shader
#define PREAMBLE "%1 = OpExtInstImport \"SPV_AMD_gcn_shader\"\n"
@ -288,14 +356,14 @@ INSTANTIATE_TEST_CASE_P(
Combine(Values(SPV_ENV_UNIVERSAL_1_0, SPV_ENV_UNIVERSAL_1_1,
SPV_ENV_VULKAN_1_0),
ValuesIn(std::vector<AssemblyCase>{
{PREAMBLE "%3 = OpExtInst %2 %1 CubeFaceCoordAMD %4\n",
Concatenate({MakeInstruction(SpvOpExtInstImport, {1},
MakeVector("SPV_AMD_gcn_shader")),
MakeInstruction(SpvOpExtInst, {2, 3, 1, 2, 4})})},
{PREAMBLE "%3 = OpExtInst %2 %1 CubeFaceIndexAMD %4\n",
Concatenate({MakeInstruction(SpvOpExtInstImport, {1},
MakeVector("SPV_AMD_gcn_shader")),
MakeInstruction(SpvOpExtInst, {2, 3, 1, 1, 4})})},
{PREAMBLE "%3 = OpExtInst %2 %1 CubeFaceCoordAMD %4\n",
Concatenate({MakeInstruction(SpvOpExtInstImport, {1},
MakeVector("SPV_AMD_gcn_shader")),
MakeInstruction(SpvOpExtInst, {2, 3, 1, 2, 4})})},
{PREAMBLE "%3 = OpExtInst %2 %1 TimeAMD\n",
Concatenate({MakeInstruction(SpvOpExtInstImport, {1},
MakeVector("SPV_AMD_gcn_shader")),
@ -304,6 +372,36 @@ INSTANTIATE_TEST_CASE_P(
#undef PREAMBLE
// SPV_AMD_shader_ballot
#define PREAMBLE "%1 = OpExtInstImport \"SPV_AMD_shader_ballot\"\n"
INSTANTIATE_TEST_CASE_P(
SPV_AMD_shader_ballot, ExtensionRoundTripTest,
// We'll get coverage over operand tables by trying the universal
// environments, and at least one specific environment.
Combine(Values(SPV_ENV_UNIVERSAL_1_0, SPV_ENV_UNIVERSAL_1_1,
SPV_ENV_VULKAN_1_0),
ValuesIn(std::vector<AssemblyCase>{
{PREAMBLE "%3 = OpExtInst %2 %1 SwizzleInvocationsAMD %4 %5\n",
Concatenate({MakeInstruction(SpvOpExtInstImport, {1},
MakeVector("SPV_AMD_shader_ballot")),
MakeInstruction(SpvOpExtInst, {2, 3, 1, 1, 4, 5})})},
{PREAMBLE "%3 = OpExtInst %2 %1 SwizzleInvocationsMaskedAMD %4 %5\n",
Concatenate({MakeInstruction(SpvOpExtInstImport, {1},
MakeVector("SPV_AMD_shader_ballot")),
MakeInstruction(SpvOpExtInst, {2, 3, 1, 2, 4, 5})})},
{PREAMBLE "%3 = OpExtInst %2 %1 WriteInvocationAMD %4 %5 %6\n",
Concatenate({MakeInstruction(SpvOpExtInstImport, {1},
MakeVector("SPV_AMD_shader_ballot")),
MakeInstruction(SpvOpExtInst, {2, 3, 1, 3, 4, 5, 6})})},
{PREAMBLE "%3 = OpExtInst %2 %1 MbcntAMD %4\n",
Concatenate({MakeInstruction(SpvOpExtInstImport, {1},
MakeVector("SPV_AMD_shader_ballot")),
MakeInstruction(SpvOpExtInst, {2, 3, 1, 4, 4})})},
})), );
#undef PREAMBLE
// SPV_KHR_variable_pointers
INSTANTIATE_TEST_CASE_P(

View File

@ -43,7 +43,13 @@ string GetErrorString(const std::string& extension) {
}
INSTANTIATE_TEST_CASE_P(ExpectSuccess, ValidateKnownExtensions, Values(
"SPV_AMD_shader_explicit_vertex_parameter",
"SPV_AMD_shader_trinary_minmax",
"SPV_AMD_gcn_shader",
"SPV_AMD_shader_ballot",
"SPV_AMD_gpu_shader_half_float",
"SPV_AMD_texture_gather_bias_lod",
"SPV_AMD_gpu_shader_int16",
"SPV_KHR_shader_ballot",
"SPV_KHR_shader_draw_parameters",
"SPV_KHR_subgroup_vote",

View File

@ -27,7 +27,16 @@ PYGEN_VARIABLE_PREFIX = 'pygen_variable'
# Extensions to recognize, but which don't come from the SPIRV-V core grammar.
NONSTANDARD_EXTENSIONS = [
# TODO(dneto): Vendor extension names should really be derived from the
# content of .json files.
'SPV_AMD_gcn_shader',
'SPV_AMD_shader_ballot',
'SPV_AMD_shader_explicit_vertex_parameter',
'SPV_AMD_shader_trinary_minmax',
# The following don't have an extended instruction set grammar file.
'SPV_AMD_gpu_shader_half_float',
'SPV_AMD_texture_gather_bias_lod',
'SPV_AMD_gpu_shader_int16',
# Validator would ignore type declaration unique check. Should only be used
# for legacy autogenerated test files containing multiple instances of the
# same type declaration, if fixing the test by other methods is too