diff options
author | orbea <orbea@riseup.net> | 2020-12-28 15:37:52 -0800 |
---|---|---|
committer | Willy Sudiarto Raharjo <willysr@slackbuilds.org> | 2021-01-02 10:48:36 +0700 |
commit | 0fd6cac3253ab591b420eb04fe3fb47df4575f32 (patch) | |
tree | e9170c7cb1119103638a90f0704c834d3fc4fc6e | |
parent | ba241cdc6f3f4c33df3f9a15512fcc98779b553a (diff) | |
download | slackbuilds-0fd6cac3253ab591b420eb04fe3fb47df4575f32.tar.gz |
graphics/SPIRV-Tools: Updated for version 2020.6.
Signed-off-by: orbea <orbea@riseup.net>
Signed-off-by: Willy Sudiarto Raharjo <willysr@slackbuilds.org>
-rw-r--r-- | graphics/SPIRV-Tools/SPIRV-Tools.SlackBuild | 12 | ||||
-rw-r--r-- | graphics/SPIRV-Tools/SPIRV-Tools.info | 6 | ||||
-rw-r--r-- | graphics/SPIRV-Tools/build-fix.patch | 373 | ||||
-rw-r--r-- | graphics/SPIRV-Tools/build-shared.patch | 367 |
4 files changed, 4 insertions, 754 deletions
diff --git a/graphics/SPIRV-Tools/SPIRV-Tools.SlackBuild b/graphics/SPIRV-Tools/SPIRV-Tools.SlackBuild index 81f0659b5e..cdde34904a 100644 --- a/graphics/SPIRV-Tools/SPIRV-Tools.SlackBuild +++ b/graphics/SPIRV-Tools/SPIRV-Tools.SlackBuild @@ -23,7 +23,7 @@ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. PRGNAM=SPIRV-Tools -VERSION=${VERSION:-2020.5} +VERSION=${VERSION:-2020.6} BUILD=${BUILD:-1} TAG=${TAG:-_SBo} @@ -69,16 +69,6 @@ find -L . \ \( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \ -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \; -# Support SPV_KHR_fragment_shading_rate -# https://github.com/KhronosGroup/SPIRV-Tools/commit/a1d38174b1f7d2651c718ae661886d606cb50a32 -# https://github.com/KhronosGroup/SPIRV-Tools/pull/3943 -patch -p1 < $CWD/build-fix.patch - -# CMake: Add SPIRV_TOOLS_BUILD_STATIC flag -# https://github.com/KhronosGroup/SPIRV-Tools/commit/7403dfafd8a4b7216343dd9be891e540a5f30240 -# https://github.com/KhronosGroup/SPIRV-Tools/pull/3910 -patch -p1 < $CWD/build-shared.patch - mkdir -p build cd build cmake \ diff --git a/graphics/SPIRV-Tools/SPIRV-Tools.info b/graphics/SPIRV-Tools/SPIRV-Tools.info index 4c0a93c902..ab0b391ef3 100644 --- a/graphics/SPIRV-Tools/SPIRV-Tools.info +++ b/graphics/SPIRV-Tools/SPIRV-Tools.info @@ -1,8 +1,8 @@ PRGNAM="SPIRV-Tools" -VERSION="2020.5" +VERSION="2020.6" HOMEPAGE="https://github.com/KhronosGroup/SPIRV-Tools" -DOWNLOAD="https://github.com/KhronosGroup/SPIRV-Tools/archive/v2020.5/SPIRV-Tools-2020.5.tar.gz" -MD5SUM="294a6497fc918eb3bff1cb9693ce78cd" +DOWNLOAD="https://github.com/KhronosGroup/SPIRV-Tools/archive/v2020.6/SPIRV-Tools-2020.6.tar.gz" +MD5SUM="a5e7b94edc9f8ecc798c66a549bba181" DOWNLOAD_x86_64="" MD5SUM_x86_64="" REQUIRES="SPIRV-Headers python3" diff --git a/graphics/SPIRV-Tools/build-fix.patch b/graphics/SPIRV-Tools/build-fix.patch deleted file mode 100644 index 4c6a4e4df7..0000000000 --- a/graphics/SPIRV-Tools/build-fix.patch +++ /dev/null @@ -1,373 +0,0 @@ -From a1d38174b1f7d2651c718ae661886d606cb50a32 Mon Sep 17 00:00:00 2001 -From: Tobski <TobyHector@hotmail.com> -Date: Tue, 20 Oct 2020 13:00:13 +0100 -Subject: [PATCH] Support SPV_KHR_fragment_shading_rate (#3943) - ---- - include/spirv-tools/libspirv.h | 13 +-- - source/operand.cpp | 3 + - source/val/validate_builtins.cpp | 159 +++++++++++++++++++++++++++++++ - test/val/val_builtins_test.cpp | 104 ++++++++++++++++++++ - 4 files changed, 273 insertions(+), 6 deletions(-) - -diff --git a/include/spirv-tools/libspirv.h b/include/spirv-tools/libspirv.h -index 16ea7ffac5..a0114c3f4b 100644 ---- a/include/spirv-tools/libspirv.h -+++ b/include/spirv-tools/libspirv.h -@@ -176,12 +176,13 @@ typedef enum spv_operand_type_t { - - // Set 5: Operands that are a single word bitmask. - // Sometimes a set bit indicates the instruction requires still more operands. -- SPV_OPERAND_TYPE_IMAGE, // SPIR-V Sec 3.14 -- SPV_OPERAND_TYPE_FP_FAST_MATH_MODE, // SPIR-V Sec 3.15 -- SPV_OPERAND_TYPE_SELECTION_CONTROL, // SPIR-V Sec 3.22 -- SPV_OPERAND_TYPE_LOOP_CONTROL, // SPIR-V Sec 3.23 -- SPV_OPERAND_TYPE_FUNCTION_CONTROL, // SPIR-V Sec 3.24 -- SPV_OPERAND_TYPE_MEMORY_ACCESS, // SPIR-V Sec 3.26 -+ SPV_OPERAND_TYPE_IMAGE, // SPIR-V Sec 3.14 -+ SPV_OPERAND_TYPE_FP_FAST_MATH_MODE, // SPIR-V Sec 3.15 -+ SPV_OPERAND_TYPE_SELECTION_CONTROL, // SPIR-V Sec 3.22 -+ SPV_OPERAND_TYPE_LOOP_CONTROL, // SPIR-V Sec 3.23 -+ SPV_OPERAND_TYPE_FUNCTION_CONTROL, // SPIR-V Sec 3.24 -+ SPV_OPERAND_TYPE_MEMORY_ACCESS, // SPIR-V Sec 3.26 -+ SPV_OPERAND_TYPE_FRAGMENT_SHADING_RATE, // SPIR-V Sec 3.FSR - - // The remaining operand types are only used internally by the assembler. - // There are two categories: -diff --git a/source/operand.cpp b/source/operand.cpp -index 7b2b98f2d1..d4b64a8b82 100644 ---- a/source/operand.cpp -+++ b/source/operand.cpp -@@ -208,6 +208,8 @@ const char* spvOperandTypeStr(spv_operand_type_t type) { - case SPV_OPERAND_TYPE_MEMORY_ACCESS: - case SPV_OPERAND_TYPE_OPTIONAL_MEMORY_ACCESS: - return "memory access"; -+ case SPV_OPERAND_TYPE_FRAGMENT_SHADING_RATE: -+ return "shading rate"; - case SPV_OPERAND_TYPE_SCOPE_ID: - return "scope ID"; - case SPV_OPERAND_TYPE_GROUP_OPERATION: -@@ -360,6 +362,7 @@ bool spvOperandIsConcreteMask(spv_operand_type_t type) { - case SPV_OPERAND_TYPE_LOOP_CONTROL: - case SPV_OPERAND_TYPE_FUNCTION_CONTROL: - case SPV_OPERAND_TYPE_MEMORY_ACCESS: -+ case SPV_OPERAND_TYPE_FRAGMENT_SHADING_RATE: - case SPV_OPERAND_TYPE_DEBUG_INFO_FLAGS: - case SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_INFO_FLAGS: - return true; -diff --git a/source/val/validate_builtins.cpp b/source/val/validate_builtins.cpp -index 1d7017d118..5b9eed6407 100644 ---- a/source/val/validate_builtins.cpp -+++ b/source/val/validate_builtins.cpp -@@ -1,4 +1,6 @@ - // Copyright (c) 2018 Google LLC. -+// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights -+// reserved. - // - // Licensed under the Apache License, Version 2.0 (the "License"); - // you may not use this file except in compliance with the License. -@@ -230,6 +232,12 @@ class BuiltInsValidator { - spv_result_t ValidateComputeI32InputAtDefinition(const Decoration& decoration, - const Instruction& inst); - -+ spv_result_t ValidatePrimitiveShadingRateAtDefinition( -+ const Decoration& decoration, const Instruction& inst); -+ -+ spv_result_t ValidateShadingRateAtDefinition(const Decoration& decoration, -+ const Instruction& inst); -+ - // The following section contains functions which are called when id defined - // by |referenced_inst| is - // 1. referenced by |referenced_from_inst| -@@ -383,6 +391,16 @@ class BuiltInsValidator { - const Instruction& referenced_inst, - const Instruction& referenced_from_inst); - -+ spv_result_t ValidatePrimitiveShadingRateAtReference( -+ const Decoration& decoration, const Instruction& built_in_inst, -+ const Instruction& referenced_inst, -+ const Instruction& referenced_from_inst); -+ -+ spv_result_t ValidateShadingRateAtReference( -+ const Decoration& decoration, const Instruction& built_in_inst, -+ const Instruction& referenced_inst, -+ const Instruction& referenced_from_inst); -+ - // Validates that |built_in_inst| is not (even indirectly) referenced from - // within a function which can be called with |execution_model|. - // -@@ -3314,6 +3332,142 @@ spv_result_t BuiltInsValidator::ValidateSMBuiltinsAtReference( - return SPV_SUCCESS; - } - -+spv_result_t BuiltInsValidator::ValidatePrimitiveShadingRateAtDefinition( -+ const Decoration& decoration, const Instruction& inst) { -+ if (spvIsVulkanEnv(_.context()->target_env)) { -+ if (spv_result_t error = ValidateI32( -+ decoration, inst, -+ [this, &inst, -+ &decoration](const std::string& message) -> spv_result_t { -+ return _.diag(SPV_ERROR_INVALID_DATA, &inst) -+ << _.VkErrorID(4486) -+ << "According to the Vulkan spec BuiltIn " -+ << _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, -+ decoration.params()[0]) -+ << " variable needs to be a 32-bit int scalar. " -+ << message; -+ })) { -+ return error; -+ } -+ } -+ -+ // Seed at reference checks with this built-in. -+ return ValidatePrimitiveShadingRateAtReference(decoration, inst, inst, inst); -+} -+ -+spv_result_t BuiltInsValidator::ValidatePrimitiveShadingRateAtReference( -+ const Decoration& decoration, const Instruction& built_in_inst, -+ const Instruction& referenced_inst, -+ const Instruction& referenced_from_inst) { -+ if (spvIsVulkanEnv(_.context()->target_env)) { -+ const SpvStorageClass storage_class = GetStorageClass(referenced_from_inst); -+ if (storage_class != SpvStorageClassMax && -+ storage_class != SpvStorageClassOutput) { -+ return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst) -+ << _.VkErrorID(4485) << "Vulkan spec allows BuiltIn " -+ << _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, -+ decoration.params()[0]) -+ << " to be only used for variables with Output storage class. " -+ << GetReferenceDesc(decoration, built_in_inst, referenced_inst, -+ referenced_from_inst) -+ << " " << GetStorageClassDesc(referenced_from_inst); -+ } -+ -+ for (const SpvExecutionModel execution_model : execution_models_) { -+ switch (execution_model) { -+ case SpvExecutionModelVertex: -+ case SpvExecutionModelGeometry: -+ case SpvExecutionModelMeshNV: -+ break; -+ default: { -+ return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst) -+ << _.VkErrorID(4484) << "Vulkan spec allows BuiltIn " -+ << _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, -+ decoration.params()[0]) -+ << " to be used only with Vertex, Geometry, or MeshNV " -+ "execution models. " -+ << GetReferenceDesc(decoration, built_in_inst, referenced_inst, -+ referenced_from_inst, execution_model); -+ } -+ } -+ } -+ } -+ -+ if (function_id_ == 0) { -+ // Propagate this rule to all dependant ids in the global scope. -+ id_to_at_reference_checks_[referenced_from_inst.id()].push_back( -+ std::bind(&BuiltInsValidator::ValidatePrimitiveShadingRateAtReference, -+ this, decoration, built_in_inst, referenced_from_inst, -+ std::placeholders::_1)); -+ } -+ -+ return SPV_SUCCESS; -+} -+ -+spv_result_t BuiltInsValidator::ValidateShadingRateAtDefinition( -+ const Decoration& decoration, const Instruction& inst) { -+ if (spvIsVulkanEnv(_.context()->target_env)) { -+ if (spv_result_t error = ValidateI32( -+ decoration, inst, -+ [this, &inst, -+ &decoration](const std::string& message) -> spv_result_t { -+ return _.diag(SPV_ERROR_INVALID_DATA, &inst) -+ << _.VkErrorID(4492) -+ << "According to the Vulkan spec BuiltIn " -+ << _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, -+ decoration.params()[0]) -+ << " variable needs to be a 32-bit int scalar. " -+ << message; -+ })) { -+ return error; -+ } -+ } -+ -+ // Seed at reference checks with this built-in. -+ return ValidateShadingRateAtReference(decoration, inst, inst, inst); -+} -+ -+spv_result_t BuiltInsValidator::ValidateShadingRateAtReference( -+ const Decoration& decoration, const Instruction& built_in_inst, -+ const Instruction& referenced_inst, -+ const Instruction& referenced_from_inst) { -+ if (spvIsVulkanEnv(_.context()->target_env)) { -+ const SpvStorageClass storage_class = GetStorageClass(referenced_from_inst); -+ if (storage_class != SpvStorageClassMax && -+ storage_class != SpvStorageClassInput) { -+ return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst) -+ << _.VkErrorID(4491) << "Vulkan spec allows BuiltIn " -+ << _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, -+ decoration.params()[0]) -+ << " to be only used for variables with Input storage class. " -+ << GetReferenceDesc(decoration, built_in_inst, referenced_inst, -+ referenced_from_inst) -+ << " " << GetStorageClassDesc(referenced_from_inst); -+ } -+ -+ for (const SpvExecutionModel execution_model : execution_models_) { -+ if (execution_model != SpvExecutionModelFragment) { -+ return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst) -+ << _.VkErrorID(4490) << "Vulkan spec allows BuiltIn " -+ << _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, -+ decoration.params()[0]) -+ << " to be used only with the Fragment execution model. " -+ << GetReferenceDesc(decoration, built_in_inst, referenced_inst, -+ referenced_from_inst, execution_model); -+ } -+ } -+ } -+ -+ if (function_id_ == 0) { -+ // Propagate this rule to all dependant ids in the global scope. -+ id_to_at_reference_checks_[referenced_from_inst.id()].push_back(std::bind( -+ &BuiltInsValidator::ValidateShadingRateAtReference, this, decoration, -+ built_in_inst, referenced_from_inst, std::placeholders::_1)); -+ } -+ -+ return SPV_SUCCESS; -+} -+ - spv_result_t BuiltInsValidator::ValidateSingleBuiltInAtDefinition( - const Decoration& decoration, const Instruction& inst) { - const SpvBuiltIn label = SpvBuiltIn(decoration.params()[0]); -@@ -3514,6 +3668,11 @@ spv_result_t BuiltInsValidator::ValidateSingleBuiltInAtDefinition( - case SpvBuiltInRayGeometryIndexKHR: { - // No validation rules (for the moment). - break; -+ -+ case SpvBuiltInPrimitiveShadingRateKHR: -+ return ValidatePrimitiveShadingRateAtDefinition(decoration, inst); -+ case SpvBuiltInShadingRateKHR: -+ return ValidateShadingRateAtDefinition(decoration, inst); - } - } - return SPV_SUCCESS; -diff --git a/test/val/val_builtins_test.cpp b/test/val/val_builtins_test.cpp -index cc9bda67cf..4248caa9b1 100644 ---- a/test/val/val_builtins_test.cpp -+++ b/test/val/val_builtins_test.cpp -@@ -1,4 +1,6 @@ - // Copyright (c) 2018 Google LLC. -+// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights -+// reserved. - // - // Licensed under the Apache License, Version 2.0 (the "License"); - // you may not use this file except in compliance with the License. -@@ -3723,6 +3725,108 @@ OpDecorate %int0 BuiltIn Position - EXPECT_EQ(SPV_SUCCESS, ValidateInstructions()); - } - -+INSTANTIATE_TEST_SUITE_P( -+ PrimitiveShadingRateOutputSuccess, -+ ValidateVulkanCombineBuiltInExecutionModelDataTypeCapabilityExtensionResult, -+ Combine(Values("PrimitiveShadingRateKHR"), Values("Vertex", "Geometry"), -+ Values("Output"), Values("%u32"), -+ Values("OpCapability FragmentShadingRateKHR\n"), -+ Values("OpExtension \"SPV_KHR_fragment_shading_rate\"\n"), -+ Values(nullptr), Values(TestResult()))); -+ -+INSTANTIATE_TEST_SUITE_P( -+ PrimitiveShadingRateMeshOutputSuccess, -+ ValidateVulkanCombineBuiltInExecutionModelDataTypeCapabilityExtensionResult, -+ Combine(Values("PrimitiveShadingRateKHR"), Values("MeshNV"), -+ Values("Output"), Values("%u32"), -+ Values("OpCapability FragmentShadingRateKHR\nOpCapability " -+ "MeshShadingNV\n"), -+ Values("OpExtension \"SPV_KHR_fragment_shading_rate\"\nOpExtension " -+ "\"SPV_NV_mesh_shader\"\n"), -+ Values(nullptr), Values(TestResult()))); -+ -+INSTANTIATE_TEST_SUITE_P( -+ PrimitiveShadingRateInvalidExecutionModel, -+ ValidateVulkanCombineBuiltInExecutionModelDataTypeCapabilityExtensionResult, -+ Combine( -+ Values("PrimitiveShadingRateKHR"), Values("Fragment"), Values("Output"), -+ Values("%u32"), Values("OpCapability FragmentShadingRateKHR\n"), -+ Values("OpExtension \"SPV_KHR_fragment_shading_rate\"\n"), -+ Values("VUID-PrimitiveShadingRateKHR-PrimitiveShadingRateKHR-04484 "), -+ Values(TestResult( -+ SPV_ERROR_INVALID_DATA, -+ "Vulkan spec allows BuiltIn PrimitiveShadingRateKHR to be used " -+ "only with Vertex, Geometry, or MeshNV execution models.")))); -+ -+INSTANTIATE_TEST_SUITE_P( -+ PrimitiveShadingRateInvalidStorageClass, -+ ValidateVulkanCombineBuiltInExecutionModelDataTypeCapabilityExtensionResult, -+ Combine( -+ Values("PrimitiveShadingRateKHR"), Values("Vertex"), Values("Input"), -+ Values("%u32"), Values("OpCapability FragmentShadingRateKHR\n"), -+ Values("OpExtension \"SPV_KHR_fragment_shading_rate\"\n"), -+ Values("VUID-PrimitiveShadingRateKHR-PrimitiveShadingRateKHR-04485 "), -+ Values(TestResult( -+ SPV_ERROR_INVALID_DATA, -+ "Vulkan spec allows BuiltIn PrimitiveShadingRateKHR to be only " -+ "used for variables with Output storage class.")))); -+ -+INSTANTIATE_TEST_SUITE_P( -+ PrimitiveShadingRateInvalidType, -+ ValidateVulkanCombineBuiltInExecutionModelDataTypeCapabilityExtensionResult, -+ Combine( -+ Values("PrimitiveShadingRateKHR"), Values("Vertex"), Values("Output"), -+ Values("%f32"), Values("OpCapability FragmentShadingRateKHR\n"), -+ Values("OpExtension \"SPV_KHR_fragment_shading_rate\"\n"), -+ Values("VUID-PrimitiveShadingRateKHR-PrimitiveShadingRateKHR-04485 "), -+ Values(TestResult( -+ SPV_ERROR_INVALID_DATA, -+ "According to the Vulkan spec BuiltIn PrimitiveShadingRateKHR " -+ "variable needs to be a 32-bit int scalar.")))); -+ -+INSTANTIATE_TEST_SUITE_P( -+ ShadingRateInputSuccess, -+ ValidateVulkanCombineBuiltInExecutionModelDataTypeCapabilityExtensionResult, -+ Combine(Values("ShadingRateKHR"), Values("Fragment"), Values("Input"), -+ Values("%u32"), Values("OpCapability FragmentShadingRateKHR\n"), -+ Values("OpExtension \"SPV_KHR_fragment_shading_rate\"\n"), -+ Values(nullptr), Values(TestResult()))); -+ -+INSTANTIATE_TEST_SUITE_P( -+ ShadingRateInvalidExecutionModel, -+ ValidateVulkanCombineBuiltInExecutionModelDataTypeCapabilityExtensionResult, -+ Combine(Values("ShadingRateKHR"), Values("Vertex"), Values("Input"), -+ Values("%u32"), Values("OpCapability FragmentShadingRateKHR\n"), -+ Values("OpExtension \"SPV_KHR_fragment_shading_rate\"\n"), -+ Values("VUID-ShadingRateKHR-ShadingRateKHR-04490 "), -+ Values(TestResult( -+ SPV_ERROR_INVALID_DATA, -+ "Vulkan spec allows BuiltIn ShadingRateKHR to be used " -+ "only with the Fragment execution model.")))); -+ -+INSTANTIATE_TEST_SUITE_P( -+ ShadingRateInvalidStorageClass, -+ ValidateVulkanCombineBuiltInExecutionModelDataTypeCapabilityExtensionResult, -+ Combine(Values("ShadingRateKHR"), Values("Fragment"), Values("Output"), -+ Values("%u32"), Values("OpCapability FragmentShadingRateKHR\n"), -+ Values("OpExtension \"SPV_KHR_fragment_shading_rate\"\n"), -+ Values("VUID-ShadingRateKHR-ShadingRateKHR-04491 "), -+ Values(TestResult( -+ SPV_ERROR_INVALID_DATA, -+ "Vulkan spec allows BuiltIn ShadingRateKHR to be only " -+ "used for variables with Input storage class.")))); -+ -+INSTANTIATE_TEST_SUITE_P( -+ ShadingRateInvalidType, -+ ValidateVulkanCombineBuiltInExecutionModelDataTypeCapabilityExtensionResult, -+ Combine( -+ Values("ShadingRateKHR"), Values("Fragment"), Values("Input"), -+ Values("%f32"), Values("OpCapability FragmentShadingRateKHR\n"), -+ Values("OpExtension \"SPV_KHR_fragment_shading_rate\"\n"), -+ Values("VUID-ShadingRateKHR-ShadingRateKHR-04492 "), -+ Values(TestResult(SPV_ERROR_INVALID_DATA, -+ "According to the Vulkan spec BuiltIn ShadingRateKHR " -+ "variable needs to be a 32-bit int scalar.")))); - } // namespace - } // namespace val - } // namespace spvtools diff --git a/graphics/SPIRV-Tools/build-shared.patch b/graphics/SPIRV-Tools/build-shared.patch deleted file mode 100644 index 0bee8ba4a3..0000000000 --- a/graphics/SPIRV-Tools/build-shared.patch +++ /dev/null @@ -1,367 +0,0 @@ -From 7403dfafd8a4b7216343dd9be891e540a5f30240 Mon Sep 17 00:00:00 2001 -From: Ben Clayton <bclayton@google.com> -Date: Thu, 29 Oct 2020 13:25:26 +0000 -Subject: [PATCH] CMake: Add SPIRV_TOOLS_BUILD_STATIC flag (#3910) - -If enabled the following targets will be created: - -* `${SPIRV_TOOLS}-static` - `STATIC` library. Has full public symbol visibility. -* `${SPIRV_TOOLS}-shared` - `SHARED` library. Has default-hidden symbol visibility. -* `${SPIRV_TOOLS}` - will alias to one of above, based on BUILD_SHARED_LIBS. - -If disabled the following targets will be created: - -* `${SPIRV_TOOLS}` - either `STATIC` or `SHARED` based on the new `SPIRV_TOOLS_LIBRARY_TYPE` flag. Has full public symbol visibility. -* `${SPIRV_TOOLS}-shared` - `SHARED` library. Has default-hidden symbol visibility. - -Defaults to `ON`, matching existing build behavior. - -This flag can be used by package maintainers to ensure that all libraries are built as shared objects. ---- - CMakeLists.txt | 40 +++++++++++++++++++++ - source/CMakeLists.txt | 70 +++++++++++++++++++----------------- - source/fuzz/CMakeLists.txt | 2 +- - source/link/CMakeLists.txt | 2 +- - source/opt/CMakeLists.txt | 4 +-- - source/reduce/CMakeLists.txt | 4 +-- - test/CMakeLists.txt | 6 ++-- - test/val/CMakeLists.txt | 10 +++--- - tools/CMakeLists.txt | 16 ++++----- - 9 files changed, 100 insertions(+), 54 deletions(-) - -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 30dde20a44..55f84e6d81 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -132,6 +132,46 @@ if (DEFINED SPIRV_TOOLS_EXTRA_DEFINITIONS) - add_definitions(${SPIRV_TOOLS_EXTRA_DEFINITIONS}) - endif() - -+# Library build setting definitions: -+# -+# * SPIRV_TOOLS_BUILD_STATIC - ON or OFF - Defaults to ON. -+# If enabled the following targets will be created: -+# ${SPIRV_TOOLS}-static - STATIC library. -+# Has full public symbol visibility. -+# ${SPIRV_TOOLS}-shared - SHARED library. -+# Has default-hidden symbol visibility. -+# ${SPIRV_TOOLS} - will alias to one of above, based on BUILD_SHARED_LIBS. -+# If disabled the following targets will be created: -+# ${SPIRV_TOOLS} - either STATIC or SHARED based on SPIRV_TOOLS_LIBRARY_TYPE. -+# Has full public symbol visibility. -+# ${SPIRV_TOOLS}-shared - SHARED library. -+# Has default-hidden symbol visibility. -+# -+# * SPIRV_TOOLS_LIBRARY_TYPE - SHARED or STATIC. -+# Specifies the library type used for building SPIRV-Tools libraries. -+# Defaults to SHARED when BUILD_SHARED_LIBS=1, otherwise STATIC. -+# -+# * SPIRV_TOOLS_FULL_VISIBILITY - "${SPIRV_TOOLS}-static" or "${SPIRV_TOOLS}" -+# Evaluates to the SPIRV_TOOLS target library name that has no hidden symbols. -+# This is used by internal targets for accessing symbols that are non-public. -+# Note this target provides no API stability guarantees. -+# -+# Ideally, all of these will go away - see https://github.com/KhronosGroup/SPIRV-Tools/issues/3909. -+option(SPIRV_TOOLS_BUILD_STATIC "Build ${SPIRV_TOOLS}-static target. ${SPIRV_TOOLS} will alias to ${SPIRV_TOOLS}-static or ${SPIRV_TOOLS}-shared based on BUILD_SHARED_LIBS" ON) -+if(SPIRV_TOOLS_BUILD_STATIC) -+ set(SPIRV_TOOLS_FULL_VISIBILITY ${SPIRV_TOOLS}-static) -+ set(SPIRV_TOOLS_LIBRARY_TYPE "STATIC") -+else(SPIRV_TOOLS_BUILD_STATIC) -+ set(SPIRV_TOOLS_FULL_VISIBILITY ${SPIRV_TOOLS}) -+ if (NOT DEFINED SPIRV_TOOLS_LIBRARY_TYPE) -+ if(BUILD_SHARED_LIBS) -+ set(SPIRV_TOOLS_LIBRARY_TYPE "SHARED") -+ else() -+ set(SPIRV_TOOLS_LIBRARY_TYPE "STATIC") -+ endif() -+ endif() -+endif(SPIRV_TOOLS_BUILD_STATIC) -+ - function(spvtools_default_compile_options TARGET) - target_compile_options(${TARGET} PRIVATE ${SPIRV_WARNINGS}) - -diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt -index fa900e03e1..65087f2c93 100644 ---- a/source/CMakeLists.txt -+++ b/source/CMakeLists.txt -@@ -346,58 +346,64 @@ set_source_files_properties( - - spvtools_pch(SPIRV_SOURCES pch_source) - --add_library(${SPIRV_TOOLS}-static STATIC ${SPIRV_SOURCES}) --spvtools_default_compile_options(${SPIRV_TOOLS}-static) --target_include_directories(${SPIRV_TOOLS}-static -- PUBLIC -- $<BUILD_INTERFACE:${spirv-tools_SOURCE_DIR}/include> -- $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> -- PRIVATE ${spirv-tools_BINARY_DIR} -- PRIVATE ${SPIRV_HEADER_INCLUDE_DIR} -+# spirv_tools_default_target_options() sets the target options that are common -+# for all ${SPIRV_TOOLS} targets. -+function(spirv_tools_default_target_options target) -+ spvtools_default_compile_options(${target}) -+ target_include_directories(${target} -+ PUBLIC -+ $<BUILD_INTERFACE:${spirv-tools_SOURCE_DIR}/include> -+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> -+ PRIVATE ${spirv-tools_BINARY_DIR} -+ PRIVATE ${SPIRV_HEADER_INCLUDE_DIR} - ) --set_property(TARGET ${SPIRV_TOOLS}-static PROPERTY FOLDER "SPIRV-Tools libraries") --spvtools_check_symbol_exports(${SPIRV_TOOLS}-static) --add_dependencies(${SPIRV_TOOLS}-static core_tables enum_string_mapping extinst_tables) -- --# The static target does not have the '-static' suffix. --set_target_properties(${SPIRV_TOOLS}-static PROPERTIES OUTPUT_NAME "${SPIRV_TOOLS}") -+ set_property(TARGET ${target} PROPERTY FOLDER "SPIRV-Tools libraries") -+ spvtools_check_symbol_exports(${target}) -+ add_dependencies(${target} core_tables enum_string_mapping extinst_tables) -+endfunction() - -+# Always build ${SPIRV_TOOLS}-shared. This is expected distro packages, and -+# unlike the other SPIRV_TOOLS target, defaults to hidden symbol visibility. - add_library(${SPIRV_TOOLS}-shared SHARED ${SPIRV_SOURCES}) --spvtools_default_compile_options(${SPIRV_TOOLS}-shared) --target_include_directories(${SPIRV_TOOLS}-shared -- PUBLIC -- $<BUILD_INTERFACE:${spirv-tools_SOURCE_DIR}/include> -- $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> -- PRIVATE ${spirv-tools_BINARY_DIR} -- PRIVATE ${SPIRV_HEADER_INCLUDE_DIR} -- ) -+spirv_tools_default_target_options(${SPIRV_TOOLS}-shared) - set_target_properties(${SPIRV_TOOLS}-shared PROPERTIES CXX_VISIBILITY_PRESET hidden) --set_property(TARGET ${SPIRV_TOOLS}-shared PROPERTY FOLDER "SPIRV-Tools libraries") --spvtools_check_symbol_exports(${SPIRV_TOOLS}-shared) - target_compile_definitions(${SPIRV_TOOLS}-shared - PRIVATE SPIRV_TOOLS_IMPLEMENTATION - PUBLIC SPIRV_TOOLS_SHAREDLIB - ) --add_dependencies(${SPIRV_TOOLS}-shared core_tables enum_string_mapping extinst_tables) - --# Create the "${SPIRV_TOOLS}" target as an alias to either "${SPIRV_TOOLS}-static" --# or "${SPIRV_TOOLS}-shared" depending on the value of BUILD_SHARED_LIBS. --if(BUILD_SHARED_LIBS) -+if(SPIRV_TOOLS_BUILD_STATIC) -+ add_library(${SPIRV_TOOLS}-static STATIC ${SPIRV_SOURCES}) -+ spirv_tools_default_target_options(${SPIRV_TOOLS}-static) -+ # The static target does not have the '-static' suffix. -+ set_target_properties(${SPIRV_TOOLS}-static PROPERTIES OUTPUT_NAME "${SPIRV_TOOLS}") -+ -+ # Create the "${SPIRV_TOOLS}" target as an alias to either "${SPIRV_TOOLS}-static" -+ # or "${SPIRV_TOOLS}-shared" depending on the value of BUILD_SHARED_LIBS. -+ if(BUILD_SHARED_LIBS) - add_library(${SPIRV_TOOLS} ALIAS ${SPIRV_TOOLS}-shared) --else() -+ else() - add_library(${SPIRV_TOOLS} ALIAS ${SPIRV_TOOLS}-static) -+ endif() -+ -+ set(SPIRV_TOOLS_TARGETS ${SPIRV_TOOLS}-static ${SPIRV_TOOLS}-shared) -+else() -+ add_library(${SPIRV_TOOLS} ${SPIRV_TOOLS_LIBRARY_TYPE} ${SPIRV_SOURCES}) -+ spirv_tools_default_target_options(${SPIRV_TOOLS}) -+ set(SPIRV_TOOLS_TARGETS ${SPIRV_TOOLS} ${SPIRV_TOOLS}-shared) - endif() - - if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") - find_library(LIBRT rt) - if(LIBRT) -- target_link_libraries(${SPIRV_TOOLS}-static ${LIBRT}) -- target_link_libraries(${SPIRV_TOOLS}-shared ${LIBRT}) -+ foreach(target ${SPIRV_TOOLS_TARGETS}) -+ target_link_libraries(${target} ${LIBRT}) -+ endforeach() - endif() - endif() - - if(ENABLE_SPIRV_TOOLS_INSTALL) -- install(TARGETS ${SPIRV_TOOLS}-static ${SPIRV_TOOLS}-shared EXPORT ${SPIRV_TOOLS}Targets -+ install(TARGETS ${SPIRV_TOOLS_TARGETS} EXPORT ${SPIRV_TOOLS}Targets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) -diff --git a/source/fuzz/CMakeLists.txt b/source/fuzz/CMakeLists.txt -index 63a6625177..d3aa9f1e03 100644 ---- a/source/fuzz/CMakeLists.txt -+++ b/source/fuzz/CMakeLists.txt -@@ -447,7 +447,7 @@ if(SPIRV_BUILD_FUZZER) - - # The fuzzer reuses a lot of functionality from the SPIRV-Tools library. - target_link_libraries(SPIRV-Tools-fuzz -- PUBLIC ${SPIRV_TOOLS}-static -+ PUBLIC ${SPIRV_TOOLS_FULL_VISIBILITY} - PUBLIC SPIRV-Tools-opt - PUBLIC SPIRV-Tools-reduce - PUBLIC protobuf::libprotobuf) -diff --git a/source/link/CMakeLists.txt b/source/link/CMakeLists.txt -index bb058ea226..c8dd2f7153 100644 ---- a/source/link/CMakeLists.txt -+++ b/source/link/CMakeLists.txt -@@ -11,7 +11,7 @@ - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. --add_library(SPIRV-Tools-link STATIC -+add_library(SPIRV-Tools-link ${SPIRV_TOOLS_LIBRARY_TYPE} - linker.cpp - ) - -diff --git a/source/opt/CMakeLists.txt b/source/opt/CMakeLists.txt -index 3630a06051..fa74690882 100644 ---- a/source/opt/CMakeLists.txt -+++ b/source/opt/CMakeLists.txt -@@ -233,7 +233,7 @@ endif() - - spvtools_pch(SPIRV_TOOLS_OPT_SOURCES pch_source_opt) - --add_library(SPIRV-Tools-opt STATIC ${SPIRV_TOOLS_OPT_SOURCES}) -+add_library(SPIRV-Tools-opt ${SPIRV_TOOLS_LIBRARY_TYPE} ${SPIRV_TOOLS_OPT_SOURCES}) - - spvtools_default_compile_options(SPIRV-Tools-opt) - target_include_directories(SPIRV-Tools-opt -@@ -245,7 +245,7 @@ target_include_directories(SPIRV-Tools-opt - ) - # We need the assembling and disassembling functionalities in the main library. - target_link_libraries(SPIRV-Tools-opt -- PUBLIC ${SPIRV_TOOLS}-static) -+ PUBLIC ${SPIRV_TOOLS_FULL_VISIBILITY}) - - set_property(TARGET SPIRV-Tools-opt PROPERTY FOLDER "SPIRV-Tools libraries") - spvtools_check_symbol_exports(SPIRV-Tools-opt) -diff --git a/source/reduce/CMakeLists.txt b/source/reduce/CMakeLists.txt -index e113ca2554..a3291c77b2 100644 ---- a/source/reduce/CMakeLists.txt -+++ b/source/reduce/CMakeLists.txt -@@ -78,7 +78,7 @@ endif() - - spvtools_pch(SPIRV_TOOLS_REDUCE_SOURCES pch_source_reduce) - --add_library(SPIRV-Tools-reduce STATIC ${SPIRV_TOOLS_REDUCE_SOURCES}) -+add_library(SPIRV-Tools-reduce ${SPIRV_TOOLS_LIBRARY_TYPE} ${SPIRV_TOOLS_REDUCE_SOURCES}) - - spvtools_default_compile_options(SPIRV-Tools-reduce) - target_include_directories(SPIRV-Tools-reduce -@@ -90,7 +90,7 @@ target_include_directories(SPIRV-Tools-reduce - ) - # The reducer reuses a lot of functionality from the SPIRV-Tools library. - target_link_libraries(SPIRV-Tools-reduce -- PUBLIC ${SPIRV_TOOLS}-static -+ PUBLIC ${SPIRV_TOOLS_FULL_VISIBILITY} - PUBLIC SPIRV-Tools-opt) - - set_property(TARGET SPIRV-Tools-reduce PROPERTY FOLDER "SPIRV-Tools libraries") -diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt -index 5dd4036c2a..8ede58bfa6 100644 ---- a/test/CMakeLists.txt -+++ b/test/CMakeLists.txt -@@ -159,12 +159,12 @@ spvtools_pch(TEST_SOURCES pch_test) - add_spvtools_unittest( - TARGET spirv_unit_tests - SRCS ${TEST_SOURCES} -- LIBS ${SPIRV_TOOLS}-static) -+ LIBS ${SPIRV_TOOLS_FULL_VISIBILITY}) - - add_spvtools_unittest( - TARGET c_interface - SRCS c_interface_test.cpp -- LIBS ${SPIRV_TOOLS}-static) -+ LIBS ${SPIRV_TOOLS_FULL_VISIBILITY}) - - add_spvtools_unittest( - TARGET c_interface_shared -@@ -181,7 +181,7 @@ if (${SPIRV_TIMER_ENABLED}) - add_spvtools_unittest( - TARGET timer - SRCS timer_test.cpp -- LIBS ${SPIRV_TOOLS}-static) -+ LIBS ${SPIRV_TOOLS_FULL_VISIBILITY}) - endif() - - -diff --git a/test/val/CMakeLists.txt b/test/val/CMakeLists.txt -index c458a2f93a..153a91670c 100644 ---- a/test/val/CMakeLists.txt -+++ b/test/val/CMakeLists.txt -@@ -41,21 +41,21 @@ add_spvtools_unittest(TARGET val_abcde - val_extension_spv_khr_terminate_invocation.cpp - val_ext_inst_test.cpp - ${VAL_TEST_COMMON_SRCS} -- LIBS ${SPIRV_TOOLS}-static -+ LIBS ${SPIRV_TOOLS_FULL_VISIBILITY} - PCH_FILE pch_test_val - ) - - add_spvtools_unittest(TARGET val_capability - SRCS - val_capability_test.cpp -- LIBS ${SPIRV_TOOLS}-static -+ LIBS ${SPIRV_TOOLS_FULL_VISIBILITY} - PCH_FILE pch_test_val - ) - - add_spvtools_unittest(TARGET val_limits - SRCS val_limits_test.cpp - ${VAL_TEST_COMMON_SRCS} -- LIBS ${SPIRV_TOOLS}-static -+ LIBS ${SPIRV_TOOLS_FULL_VISIBILITY} - PCH_FILE pch_test_val - ) - -@@ -76,7 +76,7 @@ add_spvtools_unittest(TARGET val_fghijklmnop - val_opencl_test.cpp - val_primitives_test.cpp - ${VAL_TEST_COMMON_SRCS} -- LIBS ${SPIRV_TOOLS}-static -+ LIBS ${SPIRV_TOOLS_FULL_VISIBILITY} - PCH_FILE pch_test_val - ) - -@@ -91,6 +91,6 @@ add_spvtools_unittest(TARGET val_stuvw - val_version_test.cpp - val_webgpu_test.cpp - ${VAL_TEST_COMMON_SRCS} -- LIBS ${SPIRV_TOOLS}-static -+ LIBS ${SPIRV_TOOLS_FULL_VISIBILITY} - PCH_FILE pch_test_val - ) -diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt -index 67d606a849..124a33281a 100644 ---- a/tools/CMakeLists.txt -+++ b/tools/CMakeLists.txt -@@ -40,19 +40,19 @@ function(add_spvtools_tool) - endfunction() - - if (NOT ${SPIRV_SKIP_EXECUTABLES}) -- add_spvtools_tool(TARGET spirv-as SRCS as/as.cpp LIBS ${SPIRV_TOOLS}-static) -- add_spvtools_tool(TARGET spirv-dis SRCS dis/dis.cpp LIBS ${SPIRV_TOOLS}-static) -- add_spvtools_tool(TARGET spirv-val SRCS val/val.cpp util/cli_consumer.cpp LIBS ${SPIRV_TOOLS}-static) -- add_spvtools_tool(TARGET spirv-opt SRCS opt/opt.cpp util/cli_consumer.cpp LIBS SPIRV-Tools-opt ${SPIRV_TOOLS}-static) -+ add_spvtools_tool(TARGET spirv-as SRCS as/as.cpp LIBS ${SPIRV_TOOLS_FULL_VISIBILITY}) -+ add_spvtools_tool(TARGET spirv-dis SRCS dis/dis.cpp LIBS ${SPIRV_TOOLS_FULL_VISIBILITY}) -+ add_spvtools_tool(TARGET spirv-val SRCS val/val.cpp util/cli_consumer.cpp LIBS ${SPIRV_TOOLS_FULL_VISIBILITY}) -+ add_spvtools_tool(TARGET spirv-opt SRCS opt/opt.cpp util/cli_consumer.cpp LIBS SPIRV-Tools-opt ${SPIRV_TOOLS_FULL_VISIBILITY}) - if (NOT DEFINED IOS_PLATFORM) # iOS does not allow std::system calls which spirv-reduce requires -- add_spvtools_tool(TARGET spirv-reduce SRCS reduce/reduce.cpp util/cli_consumer.cpp LIBS SPIRV-Tools-reduce ${SPIRV_TOOLS}-static) -+ add_spvtools_tool(TARGET spirv-reduce SRCS reduce/reduce.cpp util/cli_consumer.cpp LIBS SPIRV-Tools-reduce ${SPIRV_TOOLS_FULL_VISIBILITY}) - endif() -- add_spvtools_tool(TARGET spirv-link SRCS link/linker.cpp LIBS SPIRV-Tools-link ${SPIRV_TOOLS}-static) -+ add_spvtools_tool(TARGET spirv-link SRCS link/linker.cpp LIBS SPIRV-Tools-link ${SPIRV_TOOLS_FULL_VISIBILITY}) - add_spvtools_tool(TARGET spirv-cfg - SRCS cfg/cfg.cpp - cfg/bin_to_dot.h - cfg/bin_to_dot.cpp -- LIBS ${SPIRV_TOOLS}-static) -+ LIBS ${SPIRV_TOOLS_FULL_VISIBILITY}) - target_include_directories(spirv-cfg PRIVATE ${spirv-tools_SOURCE_DIR} - ${SPIRV_HEADER_INCLUDE_DIR}) - set(SPIRV_INSTALL_TARGETS spirv-as spirv-dis spirv-val spirv-opt -@@ -62,7 +62,7 @@ if (NOT ${SPIRV_SKIP_EXECUTABLES}) - endif() - - if(SPIRV_BUILD_FUZZER) -- add_spvtools_tool(TARGET spirv-fuzz SRCS fuzz/fuzz.cpp util/cli_consumer.cpp LIBS SPIRV-Tools-fuzz ${SPIRV_TOOLS}-static) -+ add_spvtools_tool(TARGET spirv-fuzz SRCS fuzz/fuzz.cpp util/cli_consumer.cpp LIBS SPIRV-Tools-fuzz ${SPIRV_TOOLS_FULL_VISIBILITY}) - set(SPIRV_INSTALL_TARGETS ${SPIRV_INSTALL_TARGETS} spirv-fuzz) - endif(SPIRV_BUILD_FUZZER) - |