aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordan sinclair <dj2@everburning.com>2018-12-05 16:06:32 -0500
committerDavid Neto <dneto@google.com>2018-12-05 16:06:32 -0500
commit048ff06c36359edb8a1da872cc7549c56b772d61 (patch)
tree1a5dd4135242334ce62c3a3a1d34afb2d23395a0 /include
parent1f9a5cb320098c305b8052e66e8264a3d2c3fce5 (diff)
downloadamber-048ff06c36359edb8a1da872cc7549c56b772d61.tar.gz
Break apart Amber::Execute method. (#143)
Break apart Amber::Execute method. This CL splits Amber::Execute into a parse and execute step. The Parse step accepts a Recipe to fill out, that Recipe is then passed into the Execute step. The recipe, in the future, will allow retrieving information about the given script.
Diffstat (limited to 'include')
-rw-r--r--include/amber/amber.h14
-rw-r--r--include/amber/recipe.h56
-rw-r--r--include/amber/shader_info.h55
3 files changed, 119 insertions, 6 deletions
diff --git a/include/amber/amber.h b/include/amber/amber.h
index d01748c..fc4103b 100644
--- a/include/amber/amber.h
+++ b/include/amber/amber.h
@@ -20,6 +20,7 @@
#include <string>
#include <vector>
+#include "amber/recipe.h"
#include "amber/result.h"
namespace amber {
@@ -43,8 +44,6 @@ struct Options {
EngineType engine = EngineType::kVulkan;
/// Holds engine specific configuration.
std::unique_ptr<EngineConfig> config;
- /// Set true to only parse the given script, does not execute the engine.
- bool parse_only = false;
};
/// Main interface to the Amber environment.
@@ -53,14 +52,17 @@ class Amber {
Amber();
~Amber();
- /// Executes the given |data| script with the provided |opts|. Returns a
+ /// Parse the given |data| into the |recipe|.
+ amber::Result Parse(const std::string& data, amber::Recipe* recipe);
+
+ /// Executes the given |recipe| with the provided |opts|. Returns a
/// |Result| which indicates if the execution succeded.
- amber::Result Execute(const std::string& data, const Options& opts);
+ amber::Result Execute(const amber::Recipe* recipe, const Options& opts);
- /// Executes the given |data| script with the provided |opts|. Will use
+ /// Executes the given |recipe| with the provided |opts|. Will use
/// |shader_map| to lookup shader data before attempting to compile the
/// shader if possible.
- amber::Result ExecuteWithShaderData(const std::string& data,
+ amber::Result ExecuteWithShaderData(const amber::Recipe* recipe,
const Options& opts,
const ShaderMap& shader_data);
};
diff --git a/include/amber/recipe.h b/include/amber/recipe.h
new file mode 100644
index 0000000..3dd932c
--- /dev/null
+++ b/include/amber/recipe.h
@@ -0,0 +1,56 @@
+// Copyright 2018 The Amber Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef AMBER_RECIPE_H_
+#define AMBER_RECIPE_H_
+
+#include <memory>
+#include <utility>
+#include <vector>
+
+#include "amber/shader_info.h"
+
+namespace amber {
+
+/// Internal recipe implementation.
+class RecipeImpl {
+ public:
+ virtual ~RecipeImpl();
+
+ /// Retrieves information on all the shaders in the given recipe.
+ virtual std::vector<ShaderInfo> GetShaderInfo() const = 0;
+
+ protected:
+ RecipeImpl();
+};
+
+/// A recipe is the parsed representation of the input script.
+class Recipe {
+ public:
+ Recipe();
+ ~Recipe();
+
+ /// Retrieves information on all the shaders in the recipe.
+ std::vector<ShaderInfo> GetShaderInfo() const;
+
+ RecipeImpl* GetImpl() const { return impl_.get(); }
+ void SetImpl(std::unique_ptr<RecipeImpl> impl) { impl_ = std::move(impl); }
+
+ private:
+ std::unique_ptr<RecipeImpl> impl_;
+};
+
+} // namespace amber
+
+#endif // AMBER_RECIPE_H_
diff --git a/include/amber/shader_info.h b/include/amber/shader_info.h
new file mode 100644
index 0000000..7c0874e
--- /dev/null
+++ b/include/amber/shader_info.h
@@ -0,0 +1,55 @@
+// Copyright 2018 The Amber Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef AMBER_SHADER_INFO_H_
+#define AMBER_SHADER_INFO_H_
+
+#include <string>
+#include <vector>
+
+namespace amber {
+
+enum class ShaderFormat : uint8_t {
+ kDefault = 0,
+ kText,
+ kGlsl,
+ kSpirvAsm,
+ kSpirvHex,
+};
+
+enum class ShaderType : uint8_t {
+ kCompute = 0,
+ kGeometry,
+ kFragment,
+ kVertex,
+ kTessellationControl,
+ kTessellationEvaluation,
+};
+
+struct ShaderInfo {
+ ShaderFormat format;
+ ShaderType type;
+ /// This is a unique name for this shader. The name is produced from the
+ /// input script, possibly with extra prefix contents. This name, if used
+ /// in the ShaderMap will map to this specific shader.
+ std::string shader_name;
+ /// This is the shader source, the source is in the |format| given above.
+ std::string shader_source;
+ /// A list of SPIR-V optimization passes to execute on the shader.
+ std::vector<std::string> optimizations;
+};
+
+} // namespace amber
+
+#endif // AMBER_SHADER_INFO_H_