2016-01-31 04:32:09 +00:00
|
|
|
// Copyright (c) 2015-2016 The Khronos Group Inc.
|
2016-09-01 17:04:00 +00:00
|
|
|
// Copyright (c) 2016 Google Inc.
|
2016-01-31 04:32:09 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// 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
|
2016-01-31 04:32:09 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2016-01-31 04:32:09 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// 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.
|
2016-01-31 04:32:09 +00:00
|
|
|
|
|
|
|
// Unit tests for ValidationState_t.
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2016-06-02 22:51:05 +00:00
|
|
|
#include "gtest/gtest.h"
|
2017-12-13 22:55:00 +00:00
|
|
|
#include "latest_version_spirv_header.h"
|
2016-08-29 18:49:00 +00:00
|
|
|
|
2016-08-31 18:35:58 +00:00
|
|
|
#include "enum_set.h"
|
2017-03-10 20:58:15 +00:00
|
|
|
#include "extensions.h"
|
2017-02-15 18:29:33 +00:00
|
|
|
#include "spirv_validator_options.h"
|
2016-11-08 18:26:09 +00:00
|
|
|
#include "val/construct.h"
|
|
|
|
#include "val/function.h"
|
|
|
|
#include "val/validation_state.h"
|
2016-06-02 22:51:05 +00:00
|
|
|
#include "validate.h"
|
2016-01-31 04:32:09 +00:00
|
|
|
|
|
|
|
namespace {
|
2016-08-29 18:49:00 +00:00
|
|
|
using libspirv::CapabilitySet;
|
2017-03-10 20:58:15 +00:00
|
|
|
using libspirv::Extension;
|
|
|
|
using libspirv::ExtensionSet;
|
2016-01-31 04:32:09 +00:00
|
|
|
using libspirv::ValidationState_t;
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
// A test with a ValidationState_t member transparently.
|
|
|
|
class ValidationStateTest : public testing::Test {
|
|
|
|
public:
|
|
|
|
ValidationStateTest()
|
2017-02-15 18:29:33 +00:00
|
|
|
: context_(spvContextCreate(SPV_ENV_UNIVERSAL_1_0)),
|
|
|
|
options_(spvValidatorOptionsCreate()),
|
|
|
|
state_(context_, options_) {}
|
2016-01-31 04:32:09 +00:00
|
|
|
|
2017-02-15 18:29:33 +00:00
|
|
|
~ValidationStateTest() {
|
|
|
|
spvContextDestroy(context_);
|
|
|
|
spvValidatorOptionsDestroy(options_);
|
|
|
|
}
|
2017-11-27 15:16:41 +00:00
|
|
|
|
2016-01-31 04:32:09 +00:00
|
|
|
protected:
|
|
|
|
spv_context context_;
|
2017-02-15 18:29:33 +00:00
|
|
|
spv_validator_options options_;
|
2016-01-31 04:32:09 +00:00
|
|
|
ValidationState_t state_;
|
|
|
|
};
|
|
|
|
|
2017-03-10 20:58:15 +00:00
|
|
|
// A test of ValidationState_t::HasAnyOfCapabilities().
|
|
|
|
using ValidationState_HasAnyOfCapabilities = ValidationStateTest;
|
2016-01-31 04:32:09 +00:00
|
|
|
|
2017-03-10 20:58:15 +00:00
|
|
|
TEST_F(ValidationState_HasAnyOfCapabilities, EmptyMask) {
|
|
|
|
EXPECT_TRUE(state_.HasAnyOfCapabilities({}));
|
2016-03-16 21:20:02 +00:00
|
|
|
state_.RegisterCapability(SpvCapabilityMatrix);
|
2017-03-10 20:58:15 +00:00
|
|
|
EXPECT_TRUE(state_.HasAnyOfCapabilities({}));
|
2016-03-16 21:20:02 +00:00
|
|
|
state_.RegisterCapability(SpvCapabilityImageMipmap);
|
2017-03-10 20:58:15 +00:00
|
|
|
EXPECT_TRUE(state_.HasAnyOfCapabilities({}));
|
2016-03-16 21:20:02 +00:00
|
|
|
state_.RegisterCapability(SpvCapabilityPipes);
|
2017-03-10 20:58:15 +00:00
|
|
|
EXPECT_TRUE(state_.HasAnyOfCapabilities({}));
|
2016-03-16 21:20:02 +00:00
|
|
|
state_.RegisterCapability(SpvCapabilityStorageImageArrayDynamicIndexing);
|
2017-03-10 20:58:15 +00:00
|
|
|
EXPECT_TRUE(state_.HasAnyOfCapabilities({}));
|
2016-03-16 21:20:02 +00:00
|
|
|
state_.RegisterCapability(SpvCapabilityClipDistance);
|
2017-03-10 20:58:15 +00:00
|
|
|
EXPECT_TRUE(state_.HasAnyOfCapabilities({}));
|
2016-03-16 21:20:02 +00:00
|
|
|
state_.RegisterCapability(SpvCapabilityStorageImageWriteWithoutFormat);
|
2017-03-10 20:58:15 +00:00
|
|
|
EXPECT_TRUE(state_.HasAnyOfCapabilities({}));
|
2016-01-31 04:32:09 +00:00
|
|
|
}
|
|
|
|
|
2017-03-10 20:58:15 +00:00
|
|
|
TEST_F(ValidationState_HasAnyOfCapabilities, SingleCapMask) {
|
|
|
|
EXPECT_FALSE(state_.HasAnyOfCapabilities({SpvCapabilityMatrix}));
|
|
|
|
EXPECT_FALSE(state_.HasAnyOfCapabilities({SpvCapabilityImageMipmap}));
|
2016-03-16 21:20:02 +00:00
|
|
|
state_.RegisterCapability(SpvCapabilityMatrix);
|
2017-03-10 20:58:15 +00:00
|
|
|
EXPECT_TRUE(state_.HasAnyOfCapabilities({SpvCapabilityMatrix}));
|
|
|
|
EXPECT_FALSE(state_.HasAnyOfCapabilities({SpvCapabilityImageMipmap}));
|
2016-03-16 21:20:02 +00:00
|
|
|
state_.RegisterCapability(SpvCapabilityImageMipmap);
|
2017-03-10 20:58:15 +00:00
|
|
|
EXPECT_TRUE(state_.HasAnyOfCapabilities({SpvCapabilityMatrix}));
|
|
|
|
EXPECT_TRUE(state_.HasAnyOfCapabilities({SpvCapabilityImageMipmap}));
|
2016-01-31 04:32:09 +00:00
|
|
|
}
|
|
|
|
|
2017-03-10 20:58:15 +00:00
|
|
|
TEST_F(ValidationState_HasAnyOfCapabilities, MultiCapMask) {
|
2016-08-29 18:49:00 +00:00
|
|
|
const auto set1 =
|
|
|
|
CapabilitySet{SpvCapabilitySampledRect, SpvCapabilityImageBuffer};
|
|
|
|
const auto set2 = CapabilitySet{SpvCapabilityStorageImageWriteWithoutFormat,
|
|
|
|
SpvCapabilityStorageImageReadWithoutFormat,
|
|
|
|
SpvCapabilityGeometryStreams};
|
2017-03-10 20:58:15 +00:00
|
|
|
EXPECT_FALSE(state_.HasAnyOfCapabilities(set1));
|
|
|
|
EXPECT_FALSE(state_.HasAnyOfCapabilities(set2));
|
2016-03-16 21:20:02 +00:00
|
|
|
state_.RegisterCapability(SpvCapabilityImageBuffer);
|
2017-03-10 20:58:15 +00:00
|
|
|
EXPECT_TRUE(state_.HasAnyOfCapabilities(set1));
|
|
|
|
EXPECT_FALSE(state_.HasAnyOfCapabilities(set2));
|
2016-01-31 04:32:09 +00:00
|
|
|
}
|
2017-03-10 20:58:15 +00:00
|
|
|
|
|
|
|
// A test of ValidationState_t::HasAnyOfExtensions().
|
|
|
|
using ValidationState_HasAnyOfExtensions = ValidationStateTest;
|
|
|
|
|
|
|
|
TEST_F(ValidationState_HasAnyOfExtensions, EmptyMask) {
|
|
|
|
EXPECT_TRUE(state_.HasAnyOfExtensions({}));
|
|
|
|
state_.RegisterExtension(Extension::kSPV_KHR_shader_ballot);
|
|
|
|
EXPECT_TRUE(state_.HasAnyOfExtensions({}));
|
|
|
|
state_.RegisterExtension(Extension::kSPV_KHR_16bit_storage);
|
|
|
|
EXPECT_TRUE(state_.HasAnyOfExtensions({}));
|
|
|
|
state_.RegisterExtension(Extension::kSPV_NV_viewport_array2);
|
|
|
|
EXPECT_TRUE(state_.HasAnyOfExtensions({}));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ValidationState_HasAnyOfExtensions, SingleCapMask) {
|
|
|
|
EXPECT_FALSE(state_.HasAnyOfExtensions({Extension::kSPV_KHR_shader_ballot}));
|
|
|
|
EXPECT_FALSE(state_.HasAnyOfExtensions({Extension::kSPV_KHR_16bit_storage}));
|
|
|
|
state_.RegisterExtension(Extension::kSPV_KHR_shader_ballot);
|
|
|
|
EXPECT_TRUE(state_.HasAnyOfExtensions({Extension::kSPV_KHR_shader_ballot}));
|
|
|
|
EXPECT_FALSE(state_.HasAnyOfExtensions({Extension::kSPV_KHR_16bit_storage}));
|
|
|
|
state_.RegisterExtension(Extension::kSPV_KHR_16bit_storage);
|
|
|
|
EXPECT_TRUE(state_.HasAnyOfExtensions({Extension::kSPV_KHR_shader_ballot}));
|
|
|
|
EXPECT_TRUE(state_.HasAnyOfExtensions({Extension::kSPV_KHR_16bit_storage}));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ValidationState_HasAnyOfExtensions, MultiCapMask) {
|
2017-11-27 15:16:41 +00:00
|
|
|
const auto set1 = ExtensionSet{Extension::kSPV_KHR_multiview,
|
|
|
|
Extension::kSPV_KHR_16bit_storage};
|
|
|
|
const auto set2 = ExtensionSet{Extension::kSPV_KHR_shader_draw_parameters,
|
|
|
|
Extension::kSPV_NV_stereo_view_rendering,
|
|
|
|
Extension::kSPV_KHR_shader_ballot};
|
2017-03-10 20:58:15 +00:00
|
|
|
EXPECT_FALSE(state_.HasAnyOfExtensions(set1));
|
|
|
|
EXPECT_FALSE(state_.HasAnyOfExtensions(set2));
|
|
|
|
state_.RegisterExtension(Extension::kSPV_KHR_multiview);
|
|
|
|
EXPECT_TRUE(state_.HasAnyOfExtensions(set1));
|
|
|
|
EXPECT_FALSE(state_.HasAnyOfExtensions(set2));
|
|
|
|
}
|
2017-11-27 15:16:41 +00:00
|
|
|
} // namespace
|