mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2025-01-12 09:20:15 +00:00
opt: change Get* functions to return const& (#5331)
GetCapabilities returned a const*, and GetExtensions did not exist. This commit adds GetExtensions, and changes the return value to be a const&. This commit also removes the overload to GetCapabilities which returns a mutable set, as it is unused. Signed-off-by: Nathan Gauër <brioche@google.com>
This commit is contained in:
parent
876ccc6cd5
commit
bf03d40922
@ -33,7 +33,11 @@ class FeatureManager {
|
||||
return capabilities_.contains(cap);
|
||||
}
|
||||
|
||||
const CapabilitySet* GetCapabilities() const { return &capabilities_; }
|
||||
// Returns the capabilities the module declares.
|
||||
inline const CapabilitySet& GetCapabilities() const { return capabilities_; }
|
||||
|
||||
// Returns the extensions the module imports.
|
||||
inline const ExtensionSet& GetExtensions() const { return extensions_; }
|
||||
|
||||
uint32_t GetExtInstImportId_GLSLstd450() const {
|
||||
return extinst_importid_GLSLstd450_;
|
||||
@ -77,8 +81,6 @@ class FeatureManager {
|
||||
// Removes the given |capability| from the current FeatureManager.
|
||||
void RemoveCapability(spv::Capability capability);
|
||||
|
||||
CapabilitySet* GetCapabilities() { return &capabilities_; }
|
||||
|
||||
// Analyzes |module| and records imported external instruction sets.
|
||||
void AddExtInstImportIds(Module* module);
|
||||
|
||||
|
@ -770,7 +770,7 @@ void IRContext::AddCombinatorsForExtension(Instruction* extension) {
|
||||
}
|
||||
|
||||
void IRContext::InitializeCombinators() {
|
||||
for (auto capability : *get_feature_mgr()->GetCapabilities()) {
|
||||
for (auto capability : get_feature_mgr()->GetCapabilities()) {
|
||||
AddCombinatorsForCapability(uint32_t(capability));
|
||||
}
|
||||
|
||||
|
@ -87,6 +87,25 @@ OpExtension "SPV_KHR_storage_buffer_storage_class"
|
||||
Extension::kSPV_KHR_storage_buffer_storage_class));
|
||||
}
|
||||
|
||||
TEST_F(FeatureManagerTest, GetExtensionsReturnsExtensions) {
|
||||
const std::string text = R"(
|
||||
OpCapability Shader
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpExtension "SPV_KHR_variable_pointers"
|
||||
OpExtension "SPV_KHR_storage_buffer_storage_class"
|
||||
)";
|
||||
|
||||
std::unique_ptr<IRContext> context =
|
||||
BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text);
|
||||
ASSERT_NE(context, nullptr);
|
||||
|
||||
const auto& extensions = context->get_feature_mgr()->GetExtensions();
|
||||
EXPECT_EQ(extensions.size(), 2);
|
||||
EXPECT_TRUE(extensions.contains(Extension::kSPV_KHR_variable_pointers));
|
||||
EXPECT_TRUE(
|
||||
extensions.contains(Extension::kSPV_KHR_storage_buffer_storage_class));
|
||||
}
|
||||
|
||||
// Test capability checks.
|
||||
TEST_F(FeatureManagerTest, ExplicitlyPresent1) {
|
||||
const std::string text = R"(
|
||||
@ -142,6 +161,24 @@ OpMemoryModel Logical GLSL450
|
||||
context->get_feature_mgr()->HasCapability(spv::Capability::Kernel));
|
||||
}
|
||||
|
||||
TEST_F(FeatureManagerTest, GetCapabilitiesReturnsImplicitCapabilities) {
|
||||
const std::string text = R"(
|
||||
OpCapability Tessellation
|
||||
OpMemoryModel Logical GLSL450
|
||||
)";
|
||||
|
||||
std::unique_ptr<IRContext> context =
|
||||
BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text);
|
||||
ASSERT_NE(context, nullptr);
|
||||
|
||||
const auto& capabilities = context->get_feature_mgr()->GetCapabilities();
|
||||
// Tesselation implies Shader, which implies Matrix.
|
||||
EXPECT_EQ(capabilities.size(), 3);
|
||||
EXPECT_TRUE(capabilities.contains(spv::Capability::Tessellation));
|
||||
EXPECT_TRUE(capabilities.contains(spv::Capability::Shader));
|
||||
EXPECT_TRUE(capabilities.contains(spv::Capability::Matrix));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace opt
|
||||
} // namespace spvtools
|
||||
|
Loading…
Reference in New Issue
Block a user