aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Neto <dneto@google.com>2019-03-05 09:56:43 -0500
committerdan sinclair <dj2@everburning.com>2019-03-05 09:56:43 -0500
commit4c4017d29dddd40433b5865aa391e212ffe741d6 (patch)
treec918d1233875956888c22c813893d6e6212c4c86 /src
parent34e401a936f407c21dc428fd8154e16ea6bad6d4 (diff)
downloadamber-4c4017d29dddd40433b5865aa391e212ffe741d6.tar.gz
Add Amber::AreAllRequirementsSupported (#321)
It determines if the engine satisfies all requirements declared in the recipe.
Diffstat (limited to 'src')
-rw-r--r--src/amber.cc55
-rw-r--r--src/tests1
2 files changed, 46 insertions, 10 deletions
diff --git a/src/amber.cc b/src/amber.cc
index 3ad7e9a..592277a 100644
--- a/src/amber.cc
+++ b/src/amber.cc
@@ -51,16 +51,18 @@ amber::Result Amber::Parse(const std::string& input, amber::Recipe* recipe) {
return {};
}
-amber::Result Amber::Execute(const amber::Recipe* recipe, Options* opts) {
- ShaderMap map;
- return ExecuteWithShaderData(recipe, opts, map);
-}
-
-amber::Result Amber::ExecuteWithShaderData(const amber::Recipe* recipe,
- Options* opts,
- const ShaderMap& shader_data) {
+namespace {
+
+// Create an engine initialize it, and check the recipe's requirements.
+// Returns a failing result if anything fails. Otherwise pass the created
+// engine out through |engine_ptr| and the script via |script|. The |script|
+// pointer is borrowed, and should not be freed.
+Result CreateEngineAndCheckRequirements(const Recipe* recipe,
+ Options* opts,
+ std::unique_ptr<Engine>* engine_ptr,
+ Script** script_ptr) {
if (!recipe)
- return Result("Attempting to execute and invalid recipe");
+ return Result("Attempting to check an invalid recipe");
Script* script = static_cast<Script*>(recipe->GetImpl());
if (!script)
@@ -69,15 +71,48 @@ amber::Result Amber::ExecuteWithShaderData(const amber::Recipe* recipe,
script->SetSpvTargetEnv(opts->spv_env);
auto engine = Engine::Create(opts->engine);
- if (!engine)
+ if (!engine) {
return Result("Failed to create engine");
+ }
+ // Engine initialization checks requirements. Current backends don't do
+ // much else. Refactor this if they end up doing to much here.
Result r = engine->Initialize(opts->config, script->GetRequiredFeatures(),
script->GetRequiredInstanceExtensions(),
script->GetRequiredDeviceExtensions());
if (!r.IsSuccess())
return r;
+ *engine_ptr = std::move(engine);
+ *script_ptr = script;
+
+ return r;
+}
+} // namespace
+
+amber::Result Amber::AreAllRequirementsSupported(const amber::Recipe* recipe,
+ Options* opts) {
+ std::unique_ptr<Engine> engine;
+ Script* script = nullptr;
+
+ return CreateEngineAndCheckRequirements(recipe, opts, &engine, &script);
+}
+
+amber::Result Amber::Execute(const amber::Recipe* recipe, Options* opts) {
+ ShaderMap map;
+ return ExecuteWithShaderData(recipe, opts, map);
+}
+
+amber::Result Amber::ExecuteWithShaderData(const amber::Recipe* recipe,
+ Options* opts,
+ const ShaderMap& shader_data) {
+ std::unique_ptr<Engine> engine;
+ Script* script = nullptr;
+ Result r = CreateEngineAndCheckRequirements(recipe, opts, &engine, &script);
+ if (!r.IsSuccess())
+ return r;
+ script->SetSpvTargetEnv(opts->spv_env);
+
Executor executor;
Result executor_result = executor.Execute(
engine.get(), script, shader_data,
diff --git a/src/tests b/src/tests
new file mode 100644
index 0000000..5e30749
--- /dev/null
+++ b/src/tests
@@ -0,0 +1 @@
+2 probes in a row : no actual commands in between