aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/amber/amber.h10
-rw-r--r--src/amber.cc55
-rw-r--r--src/tests1
3 files changed, 55 insertions, 11 deletions
diff --git a/include/amber/amber.h b/include/amber/amber.h
index 5b55164..b332129 100644
--- a/include/amber/amber.h
+++ b/include/amber/amber.h
@@ -74,8 +74,16 @@ class Amber {
/// Parse the given |data| into the |recipe|.
amber::Result Parse(const std::string& data, amber::Recipe* recipe);
+ /// Determines whether the engine supports all features required by the
+ /// |recipe|. Modifies the |recipe| by applying some of the |opts| to the
+ /// recipe's internal state.
+ amber::Result AreAllRequirementsSupported(const amber::Recipe* recipe,
+ Options* opts);
+
/// Executes the given |recipe| with the provided |opts|. Returns a
- /// |Result| which indicates if the execution succeded.
+ /// |Result| which indicates if the execution succeded. Modifies the
+ /// |recipe| by applying some of the |opts| to the recipe's internal
+ /// state.
amber::Result Execute(const amber::Recipe* recipe, Options* opts);
/// Executes the given |recipe| with the provided |opts|. Will use
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