aboutsummaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authordan sinclair <dj2@everburning.com>2019-02-07 18:01:44 -0500
committerDavid Neto <dneto@google.com>2019-02-07 18:01:44 -0500
commitf92853163c270f7bdc5c9da15c179ddd2b3a8f86 (patch)
tree17958b324b886b66efe8df41111f98e3e7c68add /samples
parentde7c1aa073f241093e730f6f44e034a73cb58d02 (diff)
downloadamber-f92853163c270f7bdc5c9da15c179ddd2b3a8f86.tar.gz
Add flag to set vulkan version. (#272)
This CL adds a flag to the sample app to allow specifing the version of vulkan to use in the apiVersion field.
Diffstat (limited to 'samples')
-rw-r--r--samples/amber.cc48
-rw-r--r--samples/config_helper.cc7
-rw-r--r--samples/config_helper.h4
-rw-r--r--samples/config_helper_vulkan.cc9
-rw-r--r--samples/config_helper_vulkan.h6
5 files changed, 58 insertions, 16 deletions
diff --git a/samples/amber.cc b/samples/amber.cc
index b0deacc..1c5c32a 100644
--- a/samples/amber.cc
+++ b/samples/amber.cc
@@ -35,6 +35,8 @@ struct Options {
std::string image_filename;
std::string buffer_filename;
int64_t buffer_binding_index = 0;
+ uint32_t engine_major = 1;
+ uint32_t engine_minor = 0;
bool parse_only = false;
bool disable_validation_layer = false;
bool show_summary = false;
@@ -47,16 +49,17 @@ struct Options {
const char kUsage[] = R"(Usage: amber [options] SCRIPT [SCRIPTS...]
options:
- -p -- Parse input files only; Don't execute.
- -s -- Print summary of pass/failure.
- -d -- Disable Vulkan/Dawn validation layer.
+ -p -- Parse input files only; Don't execute.
+ -s -- Print summary of pass/failure.
+ -d -- Disable validation layers.
-t <spirv_env> -- The target SPIR-V environment. Defaults to SPV_ENV_UNIVERSAL_1_0.
- -i <filename> -- Write rendering to <filename> as a PPM image.
- -b <filename> -- Write contents of a UBO or SSBO to <filename>.
- -B <buffer> -- Index of buffer to write. Defaults buffer 0.
- -e <engine> -- Specify graphics engine: vulkan, dawn. Default is vulkan.
- -V, --version -- Output version information for Amber and libraries.
- -h -- This help text.
+ -i <filename> -- Write rendering to <filename> as a PPM image.
+ -b <filename> -- Write contents of a UBO or SSBO to <filename>.
+ -B <buffer> -- Index of buffer to write. Defaults buffer 0.
+ -e <engine> -- Specify graphics engine: vulkan, dawn. Default is vulkan.
+ -v <engine version> -- Engine version (eg, 1.1 for Vulkan). Default 1.0.
+ -V, --version -- Output version information for Amber and libraries.
+ -h -- This help text.
)";
bool ParseArgs(const std::vector<std::string>& args, Options* opts) {
@@ -116,9 +119,32 @@ bool ParseArgs(const std::vector<std::string>& args, Options* opts) {
return false;
}
opts->spv_env = args[i];
-
} else if (arg == "-h" || arg == "--help") {
opts->show_help = true;
+ } else if (arg == "-v") {
+ ++i;
+ if (i >= args.size()) {
+ std::cerr << "Missing value for -v argument." << std::endl;
+ return false;
+ }
+ const std::string& ver = args[i];
+
+ size_t dot_pos = 0;
+ int32_t val = std::stoi(ver, &dot_pos);
+ if (val < 0) {
+ std::cerr << "Version major must be non-negative" << std::endl;
+ return false;
+ }
+
+ opts->engine_major = static_cast<uint32_t>(val);
+ if (dot_pos != std::string::npos && (dot_pos + 1) < ver.size()) {
+ val = std::stoi(ver.substr(dot_pos + 1));
+ if (val < 0) {
+ std::cerr << "Version minor must be non-negative" << std::endl;
+ return false;
+ }
+ opts->engine_minor = static_cast<uint32_t>(val);
+ }
} else if (arg == "-V" || arg == "--version") {
opts->show_version_info = true;
} else if (arg == "-p") {
@@ -257,7 +283,7 @@ int main(int argc, const char** argv) {
std::unique_ptr<amber::EngineConfig> config;
amber::Result r = config_helper.CreateConfig(
- amber_options.engine,
+ amber_options.engine, options.engine_major, options.engine_minor,
std::vector<std::string>(required_features.begin(),
required_features.end()),
std::vector<std::string>(required_extensions.begin(),
diff --git a/samples/config_helper.cc b/samples/config_helper.cc
index 095f572..3983b53 100644
--- a/samples/config_helper.cc
+++ b/samples/config_helper.cc
@@ -35,6 +35,8 @@ ConfigHelper::~ConfigHelper() = default;
amber::Result ConfigHelper::CreateConfig(
amber::EngineType engine,
+ uint32_t engine_major,
+ uint32_t engine_minor,
const std::vector<std::string>& required_features,
const std::vector<std::string>& required_extensions,
bool disable_validation_layer,
@@ -48,8 +50,9 @@ amber::Result ConfigHelper::CreateConfig(
if (!impl_)
return amber::Result("Unable to create config helper");
- return impl_->CreateConfig(required_features, required_extensions,
- disable_validation_layer, config);
+ return impl_->CreateConfig(engine_major, engine_minor, required_features,
+ required_extensions, disable_validation_layer,
+ config);
}
amber::Result ConfigHelper::Shutdown() {
diff --git a/samples/config_helper.h b/samples/config_helper.h
index e0362c7..23d7fa0 100644
--- a/samples/config_helper.h
+++ b/samples/config_helper.h
@@ -33,6 +33,8 @@ class ConfigHelperImpl {
// |required_features| and |required_extensions| contain lists of
// required features and required extensions, respectively.
virtual amber::Result CreateConfig(
+ uint32_t engine_major,
+ uint32_t engine_minor,
const std::vector<std::string>& required_features,
const std::vector<std::string>& required_extensions,
bool disable_validation_layer,
@@ -55,6 +57,8 @@ class ConfigHelper {
// DawnEngineConfig.
amber::Result CreateConfig(
amber::EngineType engine,
+ uint32_t engine_major,
+ uint32_t engine_minor,
const std::vector<std::string>& required_features,
const std::vector<std::string>& required_extensions,
bool disable_validation_layer,
diff --git a/samples/config_helper_vulkan.cc b/samples/config_helper_vulkan.cc
index 2ce9e13..1eee200 100644
--- a/samples/config_helper_vulkan.cc
+++ b/samples/config_helper_vulkan.cc
@@ -547,10 +547,12 @@ ConfigHelperVulkan::ConfigHelperVulkan() = default;
ConfigHelperVulkan::~ConfigHelperVulkan() = default;
amber::Result ConfigHelperVulkan::CreateVulkanInstance(
+ uint32_t engine_major,
+ uint32_t engine_minor,
bool disable_validation_layer) {
VkApplicationInfo app_info = {};
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
- app_info.apiVersion = VK_MAKE_VERSION(1, 0, 0);
+ app_info.apiVersion = VK_MAKE_VERSION(engine_major, engine_minor, 0);
VkInstanceCreateInfo instance_info = {};
instance_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
@@ -669,6 +671,8 @@ amber::Result ConfigHelperVulkan::CreateVulkanDevice(
}
amber::Result ConfigHelperVulkan::CreateConfig(
+ uint32_t engine_major,
+ uint32_t engine_minor,
const std::vector<std::string>& required_features,
const std::vector<std::string>& required_extensions,
bool disable_validation_layer,
@@ -679,7 +683,8 @@ amber::Result ConfigHelperVulkan::CreateConfig(
if (!r.IsSuccess())
return r;
- r = CreateVulkanInstance(disable_validation_layer);
+ r = CreateVulkanInstance(engine_major, engine_minor,
+ disable_validation_layer);
if (!r.IsSuccess())
return r;
diff --git a/samples/config_helper_vulkan.h b/samples/config_helper_vulkan.h
index cbcac40..7d7e9ff 100644
--- a/samples/config_helper_vulkan.h
+++ b/samples/config_helper_vulkan.h
@@ -39,6 +39,8 @@ class ConfigHelperVulkan : public ConfigHelperImpl {
// extensions are given in |required_features| and
// |required_extensions|, respectively.
amber::Result CreateConfig(
+ uint32_t engine_major,
+ uint32_t engine_minor,
const std::vector<std::string>& required_features,
const std::vector<std::string>& required_extensions,
bool disable_validation_layer,
@@ -49,7 +51,9 @@ class ConfigHelperVulkan : public ConfigHelperImpl {
private:
// Create Vulkan instance.
- amber::Result CreateVulkanInstance(bool disable_validation_layer);
+ amber::Result CreateVulkanInstance(uint32_t engine_major,
+ uint32_t engine_minor,
+ bool disable_validation_layer);
// Create |vulkan_callback_| that reports validation layer errors
// via debugCallback() function in config_helper_vulkan.cc.