Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/spirv-tools/libspirv.h
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,11 @@ SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetAllowOffsetTextureOperand(
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetAllowVulkan32BitBitwise(
spv_validator_options options, bool val);

// Records whether or not the validator should allow the Linkage
// capability when targeting Vulkan.
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetAllowVulkanLinkage(
spv_validator_options options, bool val);

// Whether friendly names should be used in validation error messages.
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetFriendlyNames(
spv_validator_options options, bool val);
Expand Down
6 changes: 6 additions & 0 deletions include/spirv-tools/libspirv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ class SPIRV_TOOLS_EXPORT ValidatorOptions {
spvValidatorOptionsSetAllowVulkan32BitBitwise(options_, val);
}

// Records whether or not the validator should allow the Linkage
// capability when targeting Vulkan.
void SetAllowVulkanLinkage(bool val) {
spvValidatorOptionsSetAllowVulkanLinkage(options_, val);
}

// Records whether or not the validator should relax the rules on pointer
// usage in logical addressing mode.
//
Expand Down
5 changes: 5 additions & 0 deletions source/spirv_validator_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ void spvValidatorOptionsSetAllowVulkan32BitBitwise(
options->allow_vulkan_32_bit_bitwise = val;
}

void spvValidatorOptionsSetAllowVulkanLinkage(spv_validator_options options,
bool val) {
options->allow_vulkan_linkage = val;
}

void spvValidatorOptionsSetFriendlyNames(spv_validator_options options,
bool val) {
options->use_friendly_names = val;
Expand Down
2 changes: 2 additions & 0 deletions source/spirv_validator_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct spv_validator_options_t {
allow_offset_texture_operand(false),
allow_vulkan_32_bit_bitwise(false),
before_hlsl_legalization(false),
allow_vulkan_linkage(false),
use_friendly_names(true) {}

validator_universal_limits_t universal_limits_;
Expand All @@ -65,6 +66,7 @@ struct spv_validator_options_t {
bool allow_offset_texture_operand;
bool allow_vulkan_32_bit_bitwise;
bool before_hlsl_legalization;
bool allow_vulkan_linkage;
bool use_friendly_names;
};

Expand Down
6 changes: 6 additions & 0 deletions source/val/validate_capability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <string>

#include "source/opcode.h"
#include "source/spirv_target_env.h"
#include "source/table2.h"
#include "source/val/instruction.h"
#include "source/val/validate.h"
Expand Down Expand Up @@ -374,6 +375,11 @@ spv_result_t CapabilityPass(ValidationState_t& _, const Instruction* inst) {
};

const auto env = _.context()->target_env;
if (spvIsVulkanEnv(env) && capability == uint32_t(spv::Capability::Linkage) &&
_.options()->allow_vulkan_linkage) {
return SPV_SUCCESS;
}

const bool opencl_embedded = env == SPV_ENV_OPENCL_EMBEDDED_1_2 ||
env == SPV_ENV_OPENCL_EMBEDDED_2_0 ||
env == SPV_ENV_OPENCL_EMBEDDED_2_1 ||
Expand Down
13 changes: 13 additions & 0 deletions test/val/val_capability_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2585,6 +2585,19 @@ OpMemoryModel Logical GLSL450
HasSubstr("Capability Linkage is not allowed by Vulkan 1.0"));
}

TEST_F(ValidateCapability, Vulkan10AllowLinkage) {
const std::string spirv = R"(
OpCapability Shader
OpCapability Linkage
OpMemoryModel Logical GLSL450
%u32 = OpTypeInt 32 0
%i32 = OpTypeInt 32 1
)";
CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_0);
spvValidatorOptionsSetAllowVulkanLinkage(options_, true);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
}

TEST_F(ValidateCapability, Vulkan10EnabledByExtension) {
const std::string spirv = R"(
OpCapability Shader
Expand Down
5 changes: 5 additions & 0 deletions test/val/val_validation_state_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ TEST_F(ValidationStateTest, CheckAccessChainIndexesLimitOption) {
EXPECT_EQ(100u, options_->universal_limits_.max_access_chain_indexes);
}

TEST_F(ValidationStateTest, CheckAllowVulkanLinkageOption) {
spvValidatorOptionsSetAllowVulkanLinkage(options_, true);
EXPECT_TRUE(options_->allow_vulkan_linkage);
}

TEST_F(ValidationStateTest, CheckNonRecursiveBodyGood) {
std::string spirv = std::string(kHeader) + kNonRecursiveBody;
CompileSuccessfully(spirv);
Expand Down
4 changes: 4 additions & 0 deletions tools/val/val.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ NOTE: The validator is a work in progress.
be allowed by the target environment.
--allow-vulkan-32-bit-bitwise Allow use of non-32 bit for the Base operand where it would otherwise
not be allowed by the target environment.
--allow-vulkan-linkage Allow use of the Linkage capability where it would otherwise not
be allowed by the target environment.
--before-hlsl-legalization Allows code patterns that are intended to be
fixed by spirv-opt's legalization passes.
--version Display validator version information.
Expand Down Expand Up @@ -220,6 +222,8 @@ int main(int argc, char** argv) {
options.SetAllowOffsetTextureOperand(true);
} else if (0 == strcmp(cur_arg, "--allow-vulkan-32-bit-bitwise")) {
options.SetAllowVulkan32BitBitwise(true);
} else if (0 == strcmp(cur_arg, "--allow-vulkan-linkage")) {
options.SetAllowVulkanLinkage(true);
} else if (0 == strcmp(cur_arg, "--relax-struct-store")) {
options.SetRelaxStructStore(true);
} else if (0 == cur_arg[1]) {
Expand Down