aboutsummaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authordan sinclair <dj2@everburning.com>2019-03-21 00:18:01 -0700
committerGitHub <noreply@github.com>2019-03-21 00:18:01 -0700
commit1cd61fb5f6abfdf8fbbe4e3278d5d072177aeab4 (patch)
treef926dde6e54637a3d66fa8cd6abdd6718c1c22a6 /samples
parent12a2568d67485e0c89ada7705e5e359c950e5f8a (diff)
downloadamber-1cd61fb5f6abfdf8fbbe4e3278d5d072177aeab4.tar.gz
Move config helper to use destructor (#391)
This CL moves the config helper Shutdown code into the destructor and removes the shutdown methods. Issue #42.
Diffstat (limited to 'samples')
-rw-r--r--samples/amber.cc2
-rw-r--r--samples/config_helper.cc6
-rw-r--r--samples/config_helper.h6
-rw-r--r--samples/config_helper_dawn.cc5
-rw-r--r--samples/config_helper_dawn.h3
-rw-r--r--samples/config_helper_vulkan.cc47
-rw-r--r--samples/config_helper_vulkan.h3
7 files changed, 18 insertions, 54 deletions
diff --git a/samples/amber.cc b/samples/amber.cc
index 3c71de0..3fcb01d 100644
--- a/samples/amber.cc
+++ b/samples/amber.cc
@@ -467,7 +467,5 @@ int main(int argc, const char** argv) {
<< failures.size() << " fail" << std::endl;
}
- config_helper.Shutdown();
-
return !failures.empty();
}
diff --git a/samples/config_helper.cc b/samples/config_helper.cc
index 05963fb..a1a8016 100644
--- a/samples/config_helper.cc
+++ b/samples/config_helper.cc
@@ -72,10 +72,4 @@ amber::Result ConfigHelper::CreateConfig(
disable_validation_layer, show_version_info, config);
}
-amber::Result ConfigHelper::Shutdown() {
- if (!impl_)
- return {};
- return impl_->Shutdown();
-}
-
} // namespace sample
diff --git a/samples/config_helper.h b/samples/config_helper.h
index 5698f2a..06c0c27 100644
--- a/samples/config_helper.h
+++ b/samples/config_helper.h
@@ -41,9 +41,6 @@ class ConfigHelperImpl {
bool disable_validation_layer,
bool show_version_info,
std::unique_ptr<amber::EngineConfig>* config) = 0;
-
- // Destroy instance and device.
- virtual amber::Result Shutdown() = 0;
};
// Wrapper of ConfigHelperImpl.
@@ -68,9 +65,6 @@ class ConfigHelper {
bool show_version_info,
std::unique_ptr<amber::EngineConfig>* config);
- // Destroy instance and device.
- amber::Result Shutdown();
-
private:
std::unique_ptr<ConfigHelperImpl> impl_;
};
diff --git a/samples/config_helper_dawn.cc b/samples/config_helper_dawn.cc
index 4c449f8..eeb66f3 100644
--- a/samples/config_helper_dawn.cc
+++ b/samples/config_helper_dawn.cc
@@ -58,9 +58,4 @@ amber::Result ConfigHelperDawn::CreateConfig(
return {};
}
-amber::Result ConfigHelperDawn::Shutdown() {
- dawn_device_ = {};
- return {};
-}
-
} // namespace sample
diff --git a/samples/config_helper_dawn.h b/samples/config_helper_dawn.h
index 4bc1fc7..7b8b598 100644
--- a/samples/config_helper_dawn.h
+++ b/samples/config_helper_dawn.h
@@ -47,9 +47,6 @@ class ConfigHelperDawn : public ConfigHelperImpl {
bool show_version_info,
std::unique_ptr<amber::EngineConfig>* config) override;
- // Destroy Dawn instance and device.
- amber::Result Shutdown() override;
-
private:
::dawn_native::Instance dawn_instance_;
::dawn::Device dawn_device_;
diff --git a/samples/config_helper_vulkan.cc b/samples/config_helper_vulkan.cc
index 23f07ab..2370839 100644
--- a/samples/config_helper_vulkan.cc
+++ b/samples/config_helper_vulkan.cc
@@ -599,7 +599,24 @@ ConfigHelperVulkan::ConfigHelperVulkan()
variable_pointers_feature_(VkPhysicalDeviceVariablePointerFeaturesKHR()) {
}
-ConfigHelperVulkan::~ConfigHelperVulkan() = default;
+ConfigHelperVulkan::~ConfigHelperVulkan() {
+ if (vulkan_device_)
+ vkDestroyDevice(vulkan_device_, nullptr);
+
+ if (vulkan_callback_) {
+ auto vkDestroyDebugReportCallbackEXT =
+ reinterpret_cast<PFN_vkDestroyDebugReportCallbackEXT>(
+ vkGetInstanceProcAddr(vulkan_instance_,
+ "vkDestroyDebugReportCallbackEXT"));
+ if (vkDestroyDebugReportCallbackEXT) {
+ vkDestroyDebugReportCallbackEXT(vulkan_instance_, vulkan_callback_,
+ nullptr);
+ }
+ }
+
+ if (vulkan_instance_)
+ vkDestroyInstance(vulkan_instance_, nullptr);
+}
amber::Result ConfigHelperVulkan::CreateVulkanInstance(
uint32_t engine_major,
@@ -940,32 +957,4 @@ amber::Result ConfigHelperVulkan::CreateConfig(
return {};
}
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
-
-amber::Result ConfigHelperVulkan::Shutdown() {
- if (vulkan_device_ != VK_NULL_HANDLE)
- vkDestroyDevice(vulkan_device_, nullptr);
-
- if (vulkan_callback_ != VK_NULL_HANDLE) {
- auto vkDestroyDebugReportCallbackEXT =
- reinterpret_cast<PFN_vkDestroyDebugReportCallbackEXT>(
- vkGetInstanceProcAddr(vulkan_instance_,
- "vkDestroyDebugReportCallbackEXT"));
- if (!vkDestroyDebugReportCallbackEXT)
- return amber::Result(
- "Sample: vkDestroyDebugReportCallbackEXT is nullptr");
-
- vkDestroyDebugReportCallbackEXT(vulkan_instance_, vulkan_callback_,
- nullptr);
- }
-
- if (vulkan_instance_ != VK_NULL_HANDLE)
- vkDestroyInstance(vulkan_instance_, nullptr);
-
- return {};
-}
-
-#pragma clang diagnostic pop
-
} // namespace sample
diff --git a/samples/config_helper_vulkan.h b/samples/config_helper_vulkan.h
index bf956fb..b195972 100644
--- a/samples/config_helper_vulkan.h
+++ b/samples/config_helper_vulkan.h
@@ -51,9 +51,6 @@ class ConfigHelperVulkan : public ConfigHelperImpl {
bool show_version_info,
std::unique_ptr<amber::EngineConfig>* config) override;
- // Destroy Vulkan instance and device.
- amber::Result Shutdown() override;
-
private:
// Create Vulkan instance.
amber::Result CreateVulkanInstance(