Skip to content

Commit bf98dd7

Browse files
jzadnikdneto0
andauthored
Add support for SPV_INTEL_function_variants (KhronosGroup#6211)
Add support for SPV_INTEL_function_variants * Adds validation support for the SPV_INTEL_function_variants extension. See https://github.com/intel/llvm/blob/sycl/sycl/doc/design/spirv-extensions/SPV_INTEL_function_variants.asciidoc * Augments the linker to be able to produce multitarget modules described in the extension spec. Details of how it works are documented in fnvar.h. The values to pass to OpSpecConstantArchitectureINTEL and OpSpecConstantTargetINTEL can be determined from targets registry. Co-authored-by: David Neto <[email protected]>
1 parent 5e7108e commit bf98dd7

31 files changed

+2424
-62
lines changed

BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ cc_library(
202202
cc_library(
203203
name = "spirv_tools_link",
204204
srcs = glob(["source/link/*.cpp"]),
205-
hdrs = ["include/spirv-tools/linker.hpp"],
205+
hdrs = ["include/spirv-tools/linker.hpp", "source/link/fnvar.h"],
206206
copts = COMMON_COPTS,
207207
linkstatic = 1,
208208
visibility = ["//visibility:public"],

include/spirv-tools/libspirv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ typedef enum spv_result_t {
8080
SPV_ERROR_INVALID_DATA = -14, // Indicates data rules validation failure.
8181
SPV_ERROR_MISSING_EXTENSION = -15,
8282
SPV_ERROR_WRONG_VERSION = -16, // Indicates wrong SPIR-V version
83+
SPV_ERROR_FNVAR =
84+
-17, // Error related to SPV_INTEL_function_variants extension
8385
SPV_FORCE_32_BIT_ENUM(spv_result_t)
8486
} spv_result_t;
8587

include/spirv-tools/linker.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,36 @@ class SPIRV_TOOLS_EXPORT LinkerOptions {
6767
allow_ptr_type_mismatch_ = allow_ptr_type_mismatch;
6868
}
6969

70+
std::string GetFnVarTargetsCsv() const { return fnvar_targets_csv_; }
71+
void SetFnVarTargetsCsv(std::string fnvar_targets_csv) {
72+
fnvar_targets_csv_ = fnvar_targets_csv;
73+
}
74+
75+
std::string GetFnVarArchitecturesCsv() const {
76+
return fnvar_architectures_csv_;
77+
}
78+
void SetFnVarArchitecturesCsv(std::string fnvar_architectures_csv) {
79+
fnvar_architectures_csv_ = fnvar_architectures_csv;
80+
}
81+
82+
bool GetHasFnVarCapabilities() const { return has_fnvar_capabilities_; }
83+
void SetHasFnVarCapabilities(bool fnvar_capabilities) {
84+
has_fnvar_capabilities_ = fnvar_capabilities;
85+
}
86+
87+
std::vector<std::string> GetInFiles() const { return in_files_; }
88+
void SetInFiles(std::vector<std::string> in_files) { in_files_ = in_files; }
89+
7090
private:
7191
bool create_library_{false};
7292
bool verify_ids_{false};
7393
bool allow_partial_linkage_{false};
7494
bool use_highest_version_{false};
7595
bool allow_ptr_type_mismatch_{false};
96+
std::string fnvar_targets_csv_{""};
97+
std::string fnvar_architectures_csv_{""};
98+
bool has_fnvar_capabilities_ = false;
99+
std::vector<std::string> in_files_{{}};
76100
};
77101

78102
// Links one or more SPIR-V modules into a new SPIR-V module. That is, combine

source/extensions.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,24 @@
2424
namespace spvtools {
2525

2626
std::string GetExtensionString(const spv_parsed_instruction_t* inst) {
27-
if (inst->opcode != static_cast<uint16_t>(spv::Op::OpExtension)) {
27+
if ((inst->opcode != static_cast<uint16_t>(spv::Op::OpExtension)) &&
28+
(inst->opcode !=
29+
static_cast<uint16_t>(spv::Op::OpConditionalExtensionINTEL))) {
2830
return "ERROR_not_op_extension";
2931
}
3032

31-
assert(inst->num_operands == 1);
33+
const bool is_conditional =
34+
inst->opcode ==
35+
static_cast<uint16_t>(spv::Op::OpConditionalExtensionINTEL);
36+
assert(inst->num_operands == (is_conditional ? 2 : 1));
37+
const uint16_t op_i = is_conditional ? 1 : 0;
3238

33-
const auto& operand = inst->operands[0];
39+
const auto& operand = inst->operands[op_i];
3440
assert(operand.type == SPV_OPERAND_TYPE_LITERAL_STRING);
3541
assert(inst->num_words > operand.offset);
3642
(void)operand; /* No unused variables in release builds. */
3743

38-
return spvDecodeLiteralStringOperand(*inst, 0);
44+
return spvDecodeLiteralStringOperand(*inst, op_i);
3945
}
4046

4147
std::string ExtensionSetToString(const ExtensionSet& extensions) {

source/fuzz/force_render_red.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ opt::Function* FindFragmentShaderEntryPoint(opt::IRContext* ir_context,
3636
// Check that this is a fragment shader
3737
bool found_capability_shader = false;
3838
for (auto& capability : ir_context->capabilities()) {
39-
assert(capability.opcode() == spv::Op::OpCapability);
40-
if (spv::Capability(capability.GetSingleWordInOperand(0)) ==
39+
assert(capability.opcode() == spv::Op::OpCapability ||
40+
capability.opcode() == spv::Op::OpConditionalCapabilityINTEL);
41+
const uint32_t i_cap =
42+
capability.opcode() == spv::Op::OpConditionalCapabilityINTEL ? 1 : 0;
43+
if (spv::Capability(capability.GetSingleWordInOperand(i_cap)) ==
4144
spv::Capability::Shader) {
4245
found_capability_shader = true;
4346
break;

source/link/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
add_library(SPIRV-Tools-link ${SPIRV_TOOLS_LIBRARY_TYPE}
15+
fnvar.cpp
1516
linker.cpp
1617
)
1718

0 commit comments

Comments
 (0)