2017-03-08 18:59:01 +00:00
|
|
|
// Copyright (c) 2017 Google Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
// Tests for OpExtension validator rules.
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2017-03-15 21:28:24 +00:00
|
|
|
#include "enum_string_mapping.h"
|
2017-03-10 20:58:15 +00:00
|
|
|
#include "extensions.h"
|
2017-03-08 18:59:01 +00:00
|
|
|
#include "gmock/gmock.h"
|
|
|
|
#include "test_fixture.h"
|
|
|
|
#include "unit_spirv.h"
|
|
|
|
#include "val_fixtures.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2017-03-10 20:58:15 +00:00
|
|
|
using ::libspirv::Extension;
|
|
|
|
|
2017-03-08 18:59:01 +00:00
|
|
|
using ::testing::HasSubstr;
|
|
|
|
using ::testing::Not;
|
|
|
|
using ::testing::Values;
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
using ValidateKnownExtensions = spvtest::ValidateBase<string>;
|
|
|
|
using ValidateUnknownExtensions = spvtest::ValidateBase<string>;
|
2017-03-10 20:58:15 +00:00
|
|
|
using ValidateExtensionCapabilities = spvtest::ValidateBase<bool>;
|
2017-03-08 18:59:01 +00:00
|
|
|
|
|
|
|
// Returns expected error string if |extension| is not recognized.
|
|
|
|
string GetErrorString(const std::string& extension) {
|
2017-03-10 20:58:15 +00:00
|
|
|
return "Found unrecognized extension " + extension;
|
2017-03-08 18:59:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(ExpectSuccess, ValidateKnownExtensions, Values(
|
2017-08-17 17:53:14 +00:00
|
|
|
// Match the order as published on the SPIR-V Registry.
|
2017-06-21 07:58:00 +00:00
|
|
|
"SPV_AMD_shader_explicit_vertex_parameter",
|
|
|
|
"SPV_AMD_shader_trinary_minmax",
|
2017-03-21 16:43:26 +00:00
|
|
|
"SPV_AMD_gcn_shader",
|
2017-08-17 17:53:14 +00:00
|
|
|
"SPV_KHR_shader_ballot",
|
2017-06-21 07:58:00 +00:00
|
|
|
"SPV_AMD_shader_ballot",
|
|
|
|
"SPV_AMD_gpu_shader_half_float",
|
2017-03-08 18:59:01 +00:00
|
|
|
"SPV_KHR_shader_draw_parameters",
|
|
|
|
"SPV_KHR_subgroup_vote",
|
|
|
|
"SPV_KHR_16bit_storage",
|
|
|
|
"SPV_KHR_device_group",
|
|
|
|
"SPV_KHR_multiview",
|
2017-08-17 17:53:14 +00:00
|
|
|
"SPV_NVX_multiview_per_view_attributes",
|
2017-03-08 18:59:01 +00:00
|
|
|
"SPV_NV_viewport_array2",
|
|
|
|
"SPV_NV_stereo_view_rendering",
|
2017-08-17 17:53:14 +00:00
|
|
|
"SPV_NV_sample_mask_override_coverage",
|
|
|
|
"SPV_NV_geometry_shader_passthrough",
|
|
|
|
"SPV_AMD_texture_gather_bias_lod",
|
|
|
|
"SPV_KHR_storage_buffer_storage_class",
|
|
|
|
"SPV_KHR_variable_pointers",
|
|
|
|
"SPV_AMD_gpu_shader_int16",
|
|
|
|
"SPV_KHR_post_depth_coverage",
|
|
|
|
"SPV_KHR_shader_atomic_counter_ops",
|
|
|
|
"SPV_EXT_shader_stencil_export",
|
|
|
|
"SPV_EXT_shader_viewport_index_layer",
|
2017-09-14 14:35:22 +00:00
|
|
|
"SPV_AMD_shader_image_load_store_lod",
|
|
|
|
"SPV_AMD_shader_fragment_mask"
|
2017-03-08 18:59:01 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(FailSilently, ValidateUnknownExtensions, Values(
|
|
|
|
"ERROR_unknown_extension",
|
|
|
|
"SPV_KHR_",
|
|
|
|
"SPV_KHR_shader_ballot_ERROR"
|
|
|
|
));
|
|
|
|
|
|
|
|
TEST_P(ValidateKnownExtensions, ExpectSuccess) {
|
|
|
|
const std::string extension = GetParam();
|
|
|
|
const string str =
|
|
|
|
"OpCapability Shader\nOpCapability Linkage\nOpExtension \"" + extension +
|
|
|
|
"\"\nOpMemoryModel Logical GLSL450";
|
|
|
|
CompileSuccessfully(str.c_str());
|
|
|
|
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
|
|
|
|
EXPECT_THAT(getDiagnosticString(), Not(HasSubstr(GetErrorString(extension))));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(ValidateUnknownExtensions, FailSilently) {
|
|
|
|
const std::string extension = GetParam();
|
|
|
|
const string str =
|
|
|
|
"OpCapability Shader\nOpCapability Linkage\nOpExtension \"" + extension +
|
|
|
|
"\"\nOpMemoryModel Logical GLSL450";
|
|
|
|
CompileSuccessfully(str.c_str());
|
|
|
|
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
|
|
|
|
EXPECT_THAT(getDiagnosticString(), HasSubstr(GetErrorString(extension)));
|
|
|
|
}
|
|
|
|
|
2017-03-10 20:58:15 +00:00
|
|
|
TEST_F(ValidateExtensionCapabilities, DeclCapabilitySuccess) {
|
|
|
|
const string str =
|
|
|
|
"OpCapability Shader\nOpCapability Linkage\nOpCapability DeviceGroup\n"
|
|
|
|
"OpExtension \"SPV_KHR_device_group\""
|
|
|
|
"\nOpMemoryModel Logical GLSL450";
|
|
|
|
CompileSuccessfully(str.c_str());
|
|
|
|
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ValidateExtensionCapabilities, DeclCapabilityFailure) {
|
|
|
|
const string str =
|
|
|
|
"OpCapability Shader\nOpCapability Linkage\nOpCapability DeviceGroup\n"
|
|
|
|
"\nOpMemoryModel Logical GLSL450";
|
|
|
|
CompileSuccessfully(str.c_str());
|
|
|
|
ASSERT_EQ(SPV_ERROR_MISSING_EXTENSION, ValidateInstructions());
|
|
|
|
EXPECT_THAT(getDiagnosticString(), HasSubstr("1st operand of Capability"));
|
|
|
|
EXPECT_THAT(getDiagnosticString(), HasSubstr("requires one of these extensions"));
|
|
|
|
EXPECT_THAT(getDiagnosticString(), HasSubstr("SPV_KHR_device_group"));
|
|
|
|
}
|
|
|
|
|
2017-03-08 18:59:01 +00:00
|
|
|
} // anonymous namespace
|