aboutsummaryrefslogtreecommitdiff
path: root/src/amberscript
diff options
context:
space:
mode:
authordan sinclair <dj2@everburning.com>2018-12-11 15:11:15 -0500
committerGitHub <noreply@github.com>2018-12-11 15:11:15 -0500
commitfb1ade89cc3b73c63c4295d3b2b6eddfd8972a6b (patch)
treebc87ed570dfa620420fffee9f4f70dcc4c17993b /src/amberscript
parent4566ccba2cee294a043b272e728b5d2cdc08bba1 (diff)
downloadamber-fb1ade89cc3b73c63c4295d3b2b6eddfd8972a6b.tar.gz
Merge scripts and executors. (#170)
This CL merges the vk and amber Script classes along with the vk and amber Executor classes.
Diffstat (limited to 'src/amberscript')
-rw-r--r--src/amberscript/executor.cc36
-rw-r--r--src/amberscript/executor.h37
-rw-r--r--src/amberscript/parser.cc3
-rw-r--r--src/amberscript/parser.h7
-rw-r--r--src/amberscript/parser_test.cc59
-rw-r--r--src/amberscript/pipeline.cc144
-rw-r--r--src/amberscript/pipeline.h85
-rw-r--r--src/amberscript/pipeline_test.cc333
-rw-r--r--src/amberscript/script.cc30
-rw-r--r--src/amberscript/script.h85
-rw-r--r--src/amberscript/script_test.cc248
11 files changed, 23 insertions, 1044 deletions
diff --git a/src/amberscript/executor.cc b/src/amberscript/executor.cc
deleted file mode 100644
index 1c9954b..0000000
--- a/src/amberscript/executor.cc
+++ /dev/null
@@ -1,36 +0,0 @@
-// 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.
-
-#include "src/amberscript/executor.h"
-
-namespace amber {
-namespace amberscript {
-
-Executor::Executor() : amber::Executor() {}
-
-Executor::~Executor() = default;
-
-Result Executor::Execute(Engine*,
- const amber::Script* src_script,
- const ShaderMap&) {
- if (!src_script->IsAmberScript())
- return Result("AmberScript executor called with non-amber script source");
-
- // const amberscript::Script* script = ToAmberScript(src_script);
-
- return {};
-}
-
-} // namespace amberscript
-} // namespace amber
diff --git a/src/amberscript/executor.h b/src/amberscript/executor.h
deleted file mode 100644
index 71b6098..0000000
--- a/src/amberscript/executor.h
+++ /dev/null
@@ -1,37 +0,0 @@
-// 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 SRC_AMBERSCRIPT_EXECUTOR_H_
-#define SRC_AMBERSCRIPT_EXECUTOR_H_
-
-#include "amber/result.h"
-#include "src/engine.h"
-#include "src/executor.h"
-#include "src/script.h"
-
-namespace amber {
-namespace amberscript {
-
-class Executor : public amber::Executor {
- public:
- Executor();
- ~Executor() override;
-
- Result Execute(Engine*, const amber::Script*, const ShaderMap&) override;
-};
-
-} // namespace amberscript
-} // namespace amber
-
-#endif // SRC_AMBERSCRIPT_EXECUTOR_H_
diff --git a/src/amberscript/parser.cc b/src/amberscript/parser.cc
index d45c52a..2e004cb 100644
--- a/src/amberscript/parser.cc
+++ b/src/amberscript/parser.cc
@@ -27,8 +27,7 @@
namespace amber {
namespace amberscript {
-Parser::Parser()
- : amber::Parser(), script_(MakeUnique<amberscript::Script>()) {}
+Parser::Parser() : amber::Parser(), script_(MakeUnique<Script>()) {}
Parser::~Parser() = default;
diff --git a/src/amberscript/parser.h b/src/amberscript/parser.h
index 7e4b764..7f0fc05 100644
--- a/src/amberscript/parser.h
+++ b/src/amberscript/parser.h
@@ -20,7 +20,6 @@
#include <utility>
#include "amber/result.h"
-#include "src/amberscript/script.h"
#include "src/parser.h"
#include "src/script.h"
@@ -37,9 +36,7 @@ class Parser : public amber::Parser {
// amber::Parser
Result Parse(const std::string& data) override;
- std::unique_ptr<amber::Script> GetScript() override {
- return std::move(script_);
- }
+ std::unique_ptr<Script> GetScript() override { return std::move(script_); }
private:
std::string make_error(const std::string& err);
@@ -63,7 +60,7 @@ class Parser : public amber::Parser {
Result ParsePipelineEntryPoint(Pipeline*);
Result ParsePipelineShaderOptimizations(Pipeline*);
- std::unique_ptr<amberscript::Script> script_;
+ std::unique_ptr<Script> script_;
std::unique_ptr<Tokenizer> tokenizer_;
};
diff --git a/src/amberscript/parser_test.cc b/src/amberscript/parser_test.cc
index fd57a5d..03f3fe8 100644
--- a/src/amberscript/parser_test.cc
+++ b/src/amberscript/parser_test.cc
@@ -60,7 +60,7 @@ TEST_F(AmberScriptParserTest, EmptyInput) {
ASSERT_TRUE(r.IsSuccess()) << r.Error();
auto script = parser.GetScript();
- ASSERT_TRUE(script->IsAmberScript());
+ ASSERT_TRUE(script != nullptr);
}
TEST_F(AmberScriptParserTest, InvalidStartToken) {
@@ -90,8 +90,7 @@ TEST_F(AmberScriptParserTest, ShaderPassThrough) {
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << r.Error();
- auto parent_script = parser.GetScript();
- auto script = ToAmberScript(parent_script.get());
+ auto script = parser.GetScript();
const auto& shaders = script->GetShaders();
ASSERT_EQ(1U, shaders.size());
@@ -197,8 +196,7 @@ SHADER geometry shader_name GLSL
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << r.Error();
- auto parent_script = parser.GetScript();
- auto script = ToAmberScript(parent_script.get());
+ auto script = parser.GetScript();
const auto& shaders = script->GetShaders();
ASSERT_EQ(1U, shaders.size());
@@ -312,8 +310,7 @@ void main() {
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << r.Error();
- auto parent_script = parser.GetScript();
- auto script = ToAmberScript(parent_script.get());
+ auto script = parser.GetScript();
const auto& shaders = script->GetShaders();
ASSERT_EQ(1U, shaders.size());
@@ -354,8 +351,7 @@ TEST_P(AmberScriptParserShaderFormatTest, ShaderFormats) {
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << r.Error();
- auto parent_script = parser.GetScript();
- auto script = ToAmberScript(parent_script.get());
+ auto script = parser.GetScript();
const auto& shaders = script->GetShaders();
ASSERT_EQ(1U, shaders.size());
@@ -407,8 +403,7 @@ END
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << r.Error();
- auto parent_script = parser.GetScript();
- auto script = ToAmberScript(parent_script.get());
+ auto script = parser.GetScript();
EXPECT_EQ(2U, script->GetShaders().size());
const auto& pipelines = script->GetPipelines();
@@ -672,8 +667,7 @@ END
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << r.Error();
- auto parent_script = parser.GetScript();
- auto script = ToAmberScript(parent_script.get());
+ auto script = parser.GetScript();
const auto& pipelines = script->GetPipelines();
ASSERT_EQ(1U, pipelines.size());
@@ -819,8 +813,7 @@ END
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << r.Error();
- auto parent_script = parser.GetScript();
- auto script = ToAmberScript(parent_script.get());
+ auto script = parser.GetScript();
const auto& pipelines = script->GetPipelines();
ASSERT_EQ(1U, pipelines.size());
@@ -949,8 +942,7 @@ END)";
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << r.Error();
- auto parent_script = parser.GetScript();
- auto script = ToAmberScript(parent_script.get());
+ auto script = parser.GetScript();
const auto& buffers = script->GetBuffers();
ASSERT_EQ(1U, buffers.size());
@@ -980,8 +972,7 @@ TEST_F(AmberScriptParserTest, BufferFill) {
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << r.Error();
- auto parent_script = parser.GetScript();
- auto script = ToAmberScript(parent_script.get());
+ auto script = parser.GetScript();
const auto& buffers = script->GetBuffers();
ASSERT_EQ(1U, buffers.size());
@@ -1010,8 +1001,7 @@ TEST_F(AmberScriptParserTest, BufferFillFloat) {
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << r.Error();
- auto parent_script = parser.GetScript();
- auto script = ToAmberScript(parent_script.get());
+ auto script = parser.GetScript();
const auto& buffers = script->GetBuffers();
ASSERT_EQ(1U, buffers.size());
@@ -1041,8 +1031,7 @@ TEST_F(AmberScriptParserTest, BufferSeries) {
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << r.Error();
- auto parent_script = parser.GetScript();
- auto script = ToAmberScript(parent_script.get());
+ auto script = parser.GetScript();
const auto& buffers = script->GetBuffers();
ASSERT_EQ(1U, buffers.size());
@@ -1073,8 +1062,7 @@ TEST_F(AmberScriptParserTest, BufferSeriesFloat) {
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << r.Error();
- auto parent_script = parser.GetScript();
- auto script = ToAmberScript(parent_script.get());
+ auto script = parser.GetScript();
const auto& buffers = script->GetBuffers();
ASSERT_EQ(1U, buffers.size());
@@ -1103,8 +1091,7 @@ TEST_F(AmberScriptParserTest, BufferFramebuffer) {
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << r.Error();
- auto parent_script = parser.GetScript();
- auto script = ToAmberScript(parent_script.get());
+ auto script = parser.GetScript();
const auto& buffers = script->GetBuffers();
ASSERT_EQ(1U, buffers.size());
@@ -1131,8 +1118,7 @@ END)";
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << r.Error();
- auto parent_script = parser.GetScript();
- auto script = ToAmberScript(parent_script.get());
+ auto script = parser.GetScript();
const auto& buffers = script->GetBuffers();
ASSERT_EQ(2U, buffers.size());
@@ -1179,8 +1165,7 @@ BUFFER index my_index_buffer DATA_TYPE vec2<int32> SIZE 5 FILL 2)";
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << r.Error();
- auto parent_script = parser.GetScript();
- auto script = ToAmberScript(parent_script.get());
+ auto script = parser.GetScript();
const auto& buffers = script->GetBuffers();
ASSERT_EQ(1U, buffers.size());
@@ -1216,8 +1201,7 @@ END
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << r.Error();
- auto parent_script = parser.GetScript();
- auto script = ToAmberScript(parent_script.get());
+ auto script = parser.GetScript();
const auto& buffers = script->GetBuffers();
ASSERT_EQ(1U, buffers.size());
@@ -1253,8 +1237,7 @@ END
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << r.Error();
- auto parent_script = parser.GetScript();
- auto script = ToAmberScript(parent_script.get());
+ auto script = parser.GetScript();
const auto& buffers = script->GetBuffers();
ASSERT_EQ(1U, buffers.size());
@@ -1633,8 +1616,7 @@ TEST_P(AmberScriptParserBufferTypeTest, BufferTypes) {
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << r.Error();
- auto parent_script = parser.GetScript();
- auto script = ToAmberScript(parent_script.get());
+ auto script = parser.GetScript();
const auto& buffers = script->GetBuffers();
ASSERT_EQ(1U, buffers.size());
@@ -1665,8 +1647,7 @@ TEST_P(AmberScriptParserBufferDataTypeTest, BufferTypes) {
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << test_data.name << " :" << r.Error();
- auto parent_script = parser.GetScript();
- auto script = ToAmberScript(parent_script.get());
+ auto script = parser.GetScript();
const auto& buffers = script->GetBuffers();
ASSERT_EQ(1U, buffers.size());
diff --git a/src/amberscript/pipeline.cc b/src/amberscript/pipeline.cc
deleted file mode 100644
index 94f498b..0000000
--- a/src/amberscript/pipeline.cc
+++ /dev/null
@@ -1,144 +0,0 @@
-// 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.
-
-#include "src/amberscript/pipeline.h"
-
-#include <algorithm>
-#include <set>
-
-namespace amber {
-namespace amberscript {
-
-Pipeline::ShaderInfo::ShaderInfo(const Shader* shader)
- : shader_(shader), entry_point_("main") {}
-
-Pipeline::ShaderInfo::ShaderInfo(const ShaderInfo&) = default;
-
-Pipeline::ShaderInfo::~ShaderInfo() = default;
-
-Pipeline::Pipeline(PipelineType type) : pipeline_type_(type) {}
-
-Pipeline::~Pipeline() = default;
-
-Result Pipeline::AddShader(const Shader* shader) {
- if (!shader)
- return Result("shader can not be null when attached to pipeline");
-
- if (pipeline_type_ == PipelineType::kCompute &&
- shader->GetType() != ShaderType::kCompute) {
- return Result("only compute shaders allowed in a compute pipeline");
- }
- if (pipeline_type_ == PipelineType::kGraphics &&
- shader->GetType() == ShaderType::kCompute) {
- return Result("can not add a compute shader to a graphics pipeline");
- }
-
- for (const auto& info : shaders_) {
- const auto* is = info.GetShader();
- if (is == shader)
- return Result("can not add duplicate shader to pipeline");
- if (is->GetType() == shader->GetType())
- return Result("can not add duplicate shader type to pipeline");
- }
-
- shaders_.emplace_back(shader);
- return {};
-}
-
-Result Pipeline::SetShaderOptimizations(const Shader* shader,
- const std::vector<std::string>& opts) {
- if (!shader)
- return Result("invalid shader specified for optimizations");
-
- std::set<std::string> seen;
- for (const auto& opt : opts) {
- if (seen.count(opt) != 0)
- return Result("duplicate optimization flag (" + opt + ") set on shader");
-
- seen.insert(opt);
- }
-
- for (auto& info : shaders_) {
- const auto* is = info.GetShader();
- if (is == shader) {
- info.SetShaderOptimizations(opts);
- return {};
- }
- }
-
- return Result("unknown shader specified for optimizations: " +
- shader->GetName());
-}
-
-Result Pipeline::SetShaderEntryPoint(const Shader* shader,
- const std::string& name) {
- if (!shader)
- return Result("invalid shader specified for entry point");
- if (name.empty())
- return Result("entry point should not be blank");
-
- for (auto& info : shaders_) {
- if (info.GetShader() == shader) {
- if (info.GetEntryPoint() != "main")
- return Result("multiple entry points given for the same shader");
-
- info.SetEntryPoint(name);
- return {};
- }
- }
-
- return Result("unknown shader specified for entry point: " +
- shader->GetName());
-}
-
-Result Pipeline::Validate() const {
- if (pipeline_type_ == PipelineType::kGraphics)
- return ValidateGraphics();
- return ValidateCompute();
-}
-
-Result Pipeline::ValidateGraphics() const {
- if (shaders_.empty())
- return Result("graphics pipeline requires vertex and fragment shaders");
-
- bool found_vertex = false;
- bool found_fragment = false;
- for (const auto& info : shaders_) {
- const auto* is = info.GetShader();
- if (is->GetType() == ShaderType::kVertex)
- found_vertex = true;
- if (is->GetType() == ShaderType::kFragment)
- found_fragment = true;
- if (found_vertex && found_fragment)
- break;
- }
-
- if (!found_vertex && !found_fragment)
- return Result("graphics pipeline requires vertex and fragment shaders");
- if (!found_vertex)
- return Result("graphics pipeline requires a vertex shader");
- if (!found_fragment)
- return Result("graphics pipeline requires a fragment shader");
- return {};
-}
-
-Result Pipeline::ValidateCompute() const {
- if (shaders_.empty())
- return Result("compute pipeline requires a compute shader");
-
- return {};
-}
-
-} // namespace amberscript
-} // namespace amber
diff --git a/src/amberscript/pipeline.h b/src/amberscript/pipeline.h
deleted file mode 100644
index ba7bdb1..0000000
--- a/src/amberscript/pipeline.h
+++ /dev/null
@@ -1,85 +0,0 @@
-// 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 SRC_AMBERSCRIPT_PIPELINE_H_
-#define SRC_AMBERSCRIPT_PIPELINE_H_
-
-#include <string>
-#include <vector>
-
-#include "amber/result.h"
-#include "src/shader.h"
-
-namespace amber {
-namespace amberscript {
-
-enum class PipelineType { kCompute = 0, kGraphics };
-
-class Pipeline {
- public:
- class ShaderInfo {
- public:
- explicit ShaderInfo(const Shader*);
- ShaderInfo(const ShaderInfo&);
- ~ShaderInfo();
-
- void SetShaderOptimizations(const std::vector<std::string>& opts) {
- shader_optimizations_ = opts;
- }
- const std::vector<std::string>& GetShaderOptimizations() const {
- return shader_optimizations_;
- }
-
- const Shader* GetShader() const { return shader_; }
-
- void SetEntryPoint(const std::string& ep) { entry_point_ = ep; }
- std::string GetEntryPoint() const { return entry_point_; }
-
- private:
- const Shader* shader_ = nullptr;
- std::vector<std::string> shader_optimizations_;
- std::string entry_point_;
- };
-
- explicit Pipeline(PipelineType type);
- ~Pipeline();
-
- PipelineType GetType() const { return pipeline_type_; }
-
- void SetName(const std::string& name) { name_ = name; }
- const std::string& GetName() const { return name_; }
-
- Result AddShader(const Shader*);
- const std::vector<ShaderInfo>& GetShaders() const { return shaders_; }
-
- Result SetShaderEntryPoint(const Shader* shader, const std::string& name);
- Result SetShaderOptimizations(const Shader* shader,
- const std::vector<std::string>& opts);
-
- // Validates that the pipeline has been created correctly.
- Result Validate() const;
-
- private:
- Result ValidateGraphics() const;
- Result ValidateCompute() const;
-
- PipelineType pipeline_type_ = PipelineType::kCompute;
- std::string name_;
- std::vector<ShaderInfo> shaders_;
-};
-
-} // namespace amberscript
-} // namespace amber
-
-#endif // SRC_AMBERSCRIPT_PIPELINE_H_
diff --git a/src/amberscript/pipeline_test.cc b/src/amberscript/pipeline_test.cc
deleted file mode 100644
index b0866f1..0000000
--- a/src/amberscript/pipeline_test.cc
+++ /dev/null
@@ -1,333 +0,0 @@
-// 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.
-
-#include "src/amberscript/pipeline.h"
-#include "gtest/gtest.h"
-
-namespace amber {
-namespace amberscript {
-namespace {
-
-struct ShaderTypeData {
- ShaderType type;
-};
-
-} // namespace
-
-using AmberScriptPipelineTest = testing::Test;
-
-TEST_F(AmberScriptPipelineTest, AddShader) {
- Shader v(ShaderType::kVertex);
- Shader f(ShaderType::kFragment);
-
- Pipeline p(PipelineType::kGraphics);
- Result r = p.AddShader(&v);
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- r = p.AddShader(&f);
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- const auto& shaders = p.GetShaders();
- EXPECT_EQ(2U, shaders.size());
-
- EXPECT_EQ(&v, shaders[0].GetShader());
- EXPECT_EQ(&f, shaders[1].GetShader());
-}
-
-TEST_F(AmberScriptPipelineTest, MissingShader) {
- Pipeline p(PipelineType::kGraphics);
- Result r = p.AddShader(nullptr);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("shader can not be null when attached to pipeline", r.Error());
-}
-
-TEST_F(AmberScriptPipelineTest, DuplicateShaders) {
- Shader v(ShaderType::kVertex);
- Shader f(ShaderType::kFragment);
-
- Pipeline p(PipelineType::kGraphics);
- Result r = p.AddShader(&v);
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- r = p.AddShader(&f);
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- r = p.AddShader(&v);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("can not add duplicate shader to pipeline", r.Error());
-}
-
-TEST_F(AmberScriptPipelineTest, DuplicateShaderType) {
- Shader v(ShaderType::kVertex);
- Shader f(ShaderType::kVertex);
-
- Pipeline p(PipelineType::kGraphics);
- Result r = p.AddShader(&v);
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- r = p.AddShader(&f);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("can not add duplicate shader type to pipeline", r.Error());
-}
-
-using AmberScriptPipelineComputePipelineTest =
- testing::TestWithParam<ShaderTypeData>;
-TEST_P(AmberScriptPipelineComputePipelineTest,
- SettingGraphicsShaderToComputePipeline) {
- const auto test_data = GetParam();
-
- Shader s(test_data.type);
-
- Pipeline p(PipelineType::kCompute);
- Result r = p.AddShader(&s);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("only compute shaders allowed in a compute pipeline", r.Error());
-}
-INSTANTIATE_TEST_CASE_P(
- AmberScriptPipelineComputePipelineTests,
- AmberScriptPipelineComputePipelineTest,
- testing::Values(
- ShaderTypeData{ShaderType::kVertex},
- ShaderTypeData{ShaderType::kFragment},
- ShaderTypeData{ShaderType::kGeometry},
- ShaderTypeData{ShaderType::kTessellationEvaluation},
- ShaderTypeData{
- ShaderType::kTessellationControl}), ); // NOLINT(whitespace/parens)
-
-TEST_F(AmberScriptPipelineTest, SettingComputeShaderToGraphicsPipeline) {
- Shader c(ShaderType::kCompute);
-
- Pipeline p(PipelineType::kGraphics);
- Result r = p.AddShader(&c);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("can not add a compute shader to a graphics pipeline", r.Error());
-}
-
-TEST_F(AmberScriptPipelineTest, SetShaderOptimizations) {
- Shader v(ShaderType::kVertex);
- Shader f(ShaderType::kFragment);
-
- Pipeline p(PipelineType::kGraphics);
- Result r = p.AddShader(&v);
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- r = p.AddShader(&f);
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- std::vector<std::string> first = {"First", "Second"};
- std::vector<std::string> second = {"Third", "Forth"};
-
- r = p.SetShaderOptimizations(&f, first);
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- r = p.SetShaderOptimizations(&v, second);
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- const auto& shaders = p.GetShaders();
- EXPECT_EQ(2U, shaders.size());
- EXPECT_EQ(second, shaders[0].GetShaderOptimizations());
- EXPECT_EQ(first, shaders[1].GetShaderOptimizations());
-}
-
-TEST_F(AmberScriptPipelineTest, DuplicateShaderOptimizations) {
- Shader v(ShaderType::kVertex);
-
- Pipeline p(PipelineType::kGraphics);
- Result r = p.AddShader(&v);
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- std::vector<std::string> data = {"One", "One"};
- r = p.SetShaderOptimizations(&v, data);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("duplicate optimization flag (One) set on shader", r.Error());
-}
-
-TEST_F(AmberScriptPipelineTest, SetOptimizationForMissingShader) {
- Pipeline p(PipelineType::kGraphics);
- Result r = p.SetShaderOptimizations(nullptr, {"One", "Two"});
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("invalid shader specified for optimizations", r.Error());
-}
-
-TEST_F(AmberScriptPipelineTest, SetOptimizationForInvalidShader) {
- Shader v(ShaderType::kVertex);
- v.SetName("my_shader");
-
- Pipeline p(PipelineType::kGraphics);
- Result r = p.SetShaderOptimizations(&v, {"One", "Two"});
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("unknown shader specified for optimizations: my_shader", r.Error());
-}
-
-TEST_F(AmberScriptPipelineTest,
- GraphicsPipelineRequiresVertexAndFragmentShader) {
- Shader v(ShaderType::kVertex);
- Shader f(ShaderType::kFragment);
- Shader g(ShaderType::kGeometry);
-
- Pipeline p(PipelineType::kGraphics);
- Result r = p.AddShader(&v);
- EXPECT_TRUE(r.IsSuccess()) << r.Error();
-
- r = p.AddShader(&g);
- EXPECT_TRUE(r.IsSuccess()) << r.Error();
-
- r = p.AddShader(&f);
- EXPECT_TRUE(r.IsSuccess()) << r.Error();
-
- r = p.Validate();
- EXPECT_TRUE(r.IsSuccess()) << r.Error();
-}
-
-TEST_F(AmberScriptPipelineTest, GraphicsPipelineMissingFragmentShader) {
- Shader v(ShaderType::kVertex);
- Shader g(ShaderType::kGeometry);
-
- Pipeline p(PipelineType::kGraphics);
- Result r = p.AddShader(&v);
- EXPECT_TRUE(r.IsSuccess()) << r.Error();
-
- r = p.AddShader(&g);
- EXPECT_TRUE(r.IsSuccess()) << r.Error();
-
- r = p.Validate();
- EXPECT_FALSE(r.IsSuccess()) << r.Error();
- EXPECT_EQ("graphics pipeline requires a fragment shader", r.Error());
-}
-
-TEST_F(AmberScriptPipelineTest, GraphicsPipelineMissingVertexShader) {
- Shader f(ShaderType::kFragment);
- Shader g(ShaderType::kGeometry);
-
- Pipeline p(PipelineType::kGraphics);
- Result r = p.AddShader(&g);
- EXPECT_TRUE(r.IsSuccess()) << r.Error();
-
- r = p.AddShader(&f);
- EXPECT_TRUE(r.IsSuccess()) << r.Error();
-
- r = p.Validate();
- EXPECT_FALSE(r.IsSuccess()) << r.Error();
- EXPECT_EQ("graphics pipeline requires a vertex shader", r.Error());
-}
-
-TEST_F(AmberScriptPipelineTest,
- GraphicsPipelineMissingVertexAndFragmentShader) {
- Shader g(ShaderType::kGeometry);
-
- Pipeline p(PipelineType::kGraphics);
- Result r = p.AddShader(&g);
- EXPECT_TRUE(r.IsSuccess()) << r.Error();
-
- r = p.Validate();
- EXPECT_FALSE(r.IsSuccess()) << r.Error();
- EXPECT_EQ("graphics pipeline requires vertex and fragment shaders",
- r.Error());
-}
-
-TEST_F(AmberScriptPipelineTest, GraphicsPipelineWihoutShaders) {
- Pipeline p(PipelineType::kGraphics);
- Result r = p.Validate();
- EXPECT_FALSE(r.IsSuccess()) << r.Error();
- EXPECT_EQ("graphics pipeline requires vertex and fragment shaders",
- r.Error());
-}
-
-TEST_F(AmberScriptPipelineTest, ComputePipelineRequiresComputeShader) {
- Shader c(ShaderType::kCompute);
-
- Pipeline p(PipelineType::kCompute);
- Result r = p.AddShader(&c);
- EXPECT_TRUE(r.IsSuccess()) << r.Error();
-
- r = p.Validate();
- EXPECT_TRUE(r.IsSuccess()) << r.Error();
-}
-
-TEST_F(AmberScriptPipelineTest, ComputePipelineWithoutShader) {
- Pipeline p(PipelineType::kCompute);
- Result r = p.Validate();
- EXPECT_FALSE(r.IsSuccess()) << r.Error();
- EXPECT_EQ("compute pipeline requires a compute shader", r.Error());
-}
-
-TEST_F(AmberScriptPipelineTest, SetEntryPointForMissingShader) {
- Shader c(ShaderType::kCompute);
- c.SetName("my_shader");
-
- Pipeline p(PipelineType::kCompute);
- Result r = p.SetShaderEntryPoint(&c, "test");
- EXPECT_FALSE(r.IsSuccess());
- EXPECT_EQ("unknown shader specified for entry point: my_shader", r.Error());
-}
-
-TEST_F(AmberScriptPipelineTest, SetEntryPointForNullShader) {
- Pipeline p(PipelineType::kCompute);
- Result r = p.SetShaderEntryPoint(nullptr, "test");
- EXPECT_FALSE(r.IsSuccess());
- EXPECT_EQ("invalid shader specified for entry point", r.Error());
-}
-
-TEST_F(AmberScriptPipelineTest, SetBlankEntryPoint) {
- Shader c(ShaderType::kCompute);
- Pipeline p(PipelineType::kCompute);
- Result r = p.AddShader(&c);
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- r = p.SetShaderEntryPoint(&c, "");
- EXPECT_FALSE(r.IsSuccess());
- EXPECT_EQ("entry point should not be blank", r.Error());
-}
-
-TEST_F(AmberScriptPipelineTest, ShaderDefaultEntryPoint) {
- Shader c(ShaderType::kCompute);
- Pipeline p(PipelineType::kCompute);
- Result r = p.AddShader(&c);
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- const auto& shaders = p.GetShaders();
- ASSERT_EQ(1U, shaders.size());
- EXPECT_EQ("main", shaders[0].GetEntryPoint());
-}
-
-TEST_F(AmberScriptPipelineTest, SetShaderEntryPoint) {
- Shader c(ShaderType::kCompute);
- Pipeline p(PipelineType::kCompute);
- Result r = p.AddShader(&c);
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- r = p.SetShaderEntryPoint(&c, "my_main");
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- const auto& shaders = p.GetShaders();
- ASSERT_EQ(1U, shaders.size());
- EXPECT_EQ("my_main", shaders[0].GetEntryPoint());
-}
-
-TEST_F(AmberScriptPipelineTest, SetEntryPointMulitpleTimes) {
- Shader c(ShaderType::kCompute);
- Pipeline p(PipelineType::kCompute);
- Result r = p.AddShader(&c);
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- r = p.SetShaderEntryPoint(&c, "my_main");
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- r = p.SetShaderEntryPoint(&c, "another_main");
- EXPECT_FALSE(r.IsSuccess());
- EXPECT_EQ("multiple entry points given for the same shader", r.Error());
-}
-
-} // namespace amberscript
-} // namespace amber
diff --git a/src/amberscript/script.cc b/src/amberscript/script.cc
deleted file mode 100644
index 17bfedc..0000000
--- a/src/amberscript/script.cc
+++ /dev/null
@@ -1,30 +0,0 @@
-// 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.
-
-#include "src/amberscript/script.h"
-
-namespace amber {
-namespace amberscript {
-
-Script::Script() : amber::Script(ScriptType::kAmberScript) {}
-
-Script::~Script() = default;
-
-} // namespace amberscript
-
-const amberscript::Script* ToAmberScript(const amber::Script* s) {
- return static_cast<const amberscript::Script*>(s);
-}
-
-} // namespace amber
diff --git a/src/amberscript/script.h b/src/amberscript/script.h
deleted file mode 100644
index 81d0258..0000000
--- a/src/amberscript/script.h
+++ /dev/null
@@ -1,85 +0,0 @@
-// 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 SRC_AMBERSCRIPT_SCRIPT_H_
-#define SRC_AMBERSCRIPT_SCRIPT_H_
-
-#include <map>
-#include <memory>
-#include <string>
-#include <utility>
-#include <vector>
-
-#include "src/amberscript/pipeline.h"
-#include "src/buffer.h"
-#include "src/script.h"
-
-namespace amber {
-namespace amberscript {
-
-class Script : public amber::Script {
- public:
- Script();
- ~Script() override;
-
- Result AddPipeline(std::unique_ptr<Pipeline> pipeline) {
- if (name_to_pipeline_.count(pipeline->GetName()) > 0)
- return Result("duplicate pipeline name provided");
-
- pipelines_.push_back(std::move(pipeline));
- name_to_pipeline_[pipelines_.back()->GetName()] = pipelines_.back().get();
- return {};
- }
-
- Pipeline* GetPipeline(const std::string& name) const {
- auto it = name_to_pipeline_.find(name);
- return it == name_to_pipeline_.end() ? nullptr : it->second;
- }
-
- const std::vector<std::unique_ptr<Pipeline>>& GetPipelines() const {
- return pipelines_;
- }
-
- Result AddBuffer(std::unique_ptr<Buffer> buffer) {
- if (name_to_buffer_.count(buffer->GetName()) > 0)
- return Result("duplicate buffer name provided");
-
- buffers_.push_back(std::move(buffer));
- name_to_buffer_[buffers_.back()->GetName()] = buffers_.back().get();
- return {};
- }
-
- Buffer* GetBuffer(const std::string& name) const {
- auto it = name_to_buffer_.find(name);
- return it == name_to_buffer_.end() ? nullptr : it->second;
- }
-
- const std::vector<std::unique_ptr<Buffer>>& GetBuffers() const {
- return buffers_;
- }
-
- private:
- std::map<std::string, Pipeline*> name_to_pipeline_;
- std::map<std::string, Buffer*> name_to_buffer_;
- std::vector<std::unique_ptr<Pipeline>> pipelines_;
- std::vector<std::unique_ptr<Buffer>> buffers_;
-};
-
-} // namespace amberscript
-
-const amberscript::Script* ToAmberScript(const amber::Script* s);
-
-} // namespace amber
-
-#endif // SRC_AMBERSCRIPT_SCRIPT_H_
diff --git a/src/amberscript/script_test.cc b/src/amberscript/script_test.cc
deleted file mode 100644
index 2a2bd5e..0000000
--- a/src/amberscript/script_test.cc
+++ /dev/null
@@ -1,248 +0,0 @@
-// 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.
-
-#include <utility>
-
-#include "gtest/gtest.h"
-#include "src/amberscript/pipeline.h"
-#include "src/amberscript/script.h"
-#include "src/buffer.h"
-#include "src/make_unique.h"
-#include "src/shader.h"
-
-namespace amber {
-namespace amberscript {
-
-using ScriptTest = testing::Test;
-
-TEST_F(ScriptTest, AddShader) {
- auto shader = MakeUnique<Shader>(ShaderType::kVertex);
- shader->SetName("My Shader");
-
- Script s;
- Result r = s.AddShader(std::move(shader));
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-}
-
-TEST_F(ScriptTest, AddDuplicateShader) {
- auto shader1 = MakeUnique<Shader>(ShaderType::kVertex);
- shader1->SetName("My Shader");
-
- Script s;
- Result r = s.AddShader(std::move(shader1));
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- auto shader2 = MakeUnique<Shader>(ShaderType::kFragment);
- shader2->SetName("My Shader");
-
- r = s.AddShader(std::move(shader2));
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("duplicate shader name provided", r.Error());
-}
-
-TEST_F(ScriptTest, GetShader) {
- auto shader = MakeUnique<Shader>(ShaderType::kVertex);
- shader->SetName("My Shader");
-
- auto* ptr = shader.get();
-
- Script s;
- Result r = s.AddShader(std::move(shader));
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- EXPECT_EQ(ptr, s.GetShader("My Shader"));
-}
-
-TEST_F(ScriptTest, GetMissingShader) {
- Script s;
- EXPECT_TRUE(s.GetShader("My Shader") == nullptr);
-}
-
-TEST_F(ScriptTest, GetShadersEmpty) {
- Script s;
- const auto& shaders = s.GetShaders();
- EXPECT_TRUE(shaders.empty());
-}
-
-TEST_F(ScriptTest, GetShaders) {
- auto shader1 = MakeUnique<Shader>(ShaderType::kVertex);
- shader1->SetName("My Shader");
-
- const auto* ptr1 = shader1.get();
-
- Script s;
- Result r = s.AddShader(std::move(shader1));
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- auto shader2 = MakeUnique<Shader>(ShaderType::kFragment);
- shader2->SetName("My Fragment");
-
- const auto* ptr2 = shader2.get();
-
- r = s.AddShader(std::move(shader2));
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- const auto& shaders = s.GetShaders();
- ASSERT_EQ(2U, shaders.size());
- EXPECT_EQ(ptr1, shaders[0].get());
- EXPECT_EQ(ptr2, shaders[1].get());
-}
-
-TEST_F(ScriptTest, AddPipeline) {
- auto pipeline = MakeUnique<Pipeline>(PipelineType::kCompute);
- pipeline->SetName("my_pipeline");
-
- Script s;
- Result r = s.AddPipeline(std::move(pipeline));
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-}
-
-TEST_F(ScriptTest, AddDuplicatePipeline) {
- auto pipeline1 = MakeUnique<Pipeline>(PipelineType::kCompute);
- pipeline1->SetName("my_pipeline");
-
- Script s;
- Result r = s.AddPipeline(std::move(pipeline1));
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- auto pipeline2 = MakeUnique<Pipeline>(PipelineType::kGraphics);
- pipeline2->SetName("my_pipeline");
- r = s.AddPipeline(std::move(pipeline2));
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("duplicate pipeline name provided", r.Error());
-}
-
-TEST_F(ScriptTest, GetPipeline) {
- auto pipeline = MakeUnique<Pipeline>(PipelineType::kCompute);
- pipeline->SetName("my_pipeline");
-
- const auto* ptr = pipeline.get();
-
- Script s;
- Result r = s.AddPipeline(std::move(pipeline));
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- EXPECT_EQ(ptr, s.GetPipeline("my_pipeline"));
-}
-
-TEST_F(ScriptTest, GetMissingPipeline) {
- Script s;
- EXPECT_TRUE(s.GetPipeline("my_pipeline") == nullptr);
-}
-
-TEST_F(ScriptTest, GetPipelinesEmpty) {
- Script s;
- const auto& pipelines = s.GetPipelines();
- EXPECT_TRUE(pipelines.empty());
-}
-
-TEST_F(ScriptTest, GetPipelines) {
- auto pipeline1 = MakeUnique<Pipeline>(PipelineType::kCompute);
- pipeline1->SetName("my_pipeline1");
-
- const auto* ptr1 = pipeline1.get();
-
- Script s;
- Result r = s.AddPipeline(std::move(pipeline1));
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- auto pipeline2 = MakeUnique<Pipeline>(PipelineType::kGraphics);
- pipeline2->SetName("my_pipeline2");
-
- const auto* ptr2 = pipeline2.get();
-
- r = s.AddPipeline(std::move(pipeline2));
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- const auto& pipelines = s.GetPipelines();
- ASSERT_EQ(2U, pipelines.size());
- EXPECT_EQ(ptr1, pipelines[0].get());
- EXPECT_EQ(ptr2, pipelines[1].get());
-}
-
-TEST_F(ScriptTest, AddDataBuffer) {
- auto buffer = MakeUnique<DataBuffer>(BufferType::kStorage);
- buffer->SetName("my_buffer");
-
- Script s;
- Result r = s.AddBuffer(std::move(buffer));
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-}
-
-TEST_F(ScriptTest, AddDuplicateDataBuffer) {
- auto buffer1 = MakeUnique<DataBuffer>(BufferType::kStorage);
- buffer1->SetName("my_buffer");
-
- Script s;
- Result r = s.AddBuffer(std::move(buffer1));
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- auto buffer2 = MakeUnique<DataBuffer>(BufferType::kUniform);
- buffer2->SetName("my_buffer");
-
- r = s.AddBuffer(std::move(buffer2));
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("duplicate buffer name provided", r.Error());
-}
-
-TEST_F(ScriptTest, GetDataBuffer) {
- auto buffer = MakeUnique<DataBuffer>(BufferType::kStorage);
- buffer->SetName("my_buffer");
-
- const auto* ptr = buffer.get();
-
- Script s;
- Result r = s.AddBuffer(std::move(buffer));
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- EXPECT_EQ(ptr, s.GetBuffer("my_buffer"));
-}
-
-TEST_F(ScriptTest, GetMissingBuffer) {
- Script s;
- EXPECT_TRUE(s.GetBuffer("my_buffer") == nullptr);
-}
-
-TEST_F(ScriptTest, GetBuffersEmpty) {
- Script s;
- const auto& buffers = s.GetBuffers();
- EXPECT_TRUE(buffers.empty());
-}
-
-TEST_F(ScriptTest, GetBuffers) {
- auto buffer1 = MakeUnique<DataBuffer>(BufferType::kStorage);
- buffer1->SetName("my_buffer1");
-
- const auto* ptr1 = buffer1.get();
-
- Script s;
- Result r = s.AddBuffer(std::move(buffer1));
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- auto buffer2 = MakeUnique<DataBuffer>(BufferType::kUniform);
- buffer2->SetName("my_buffer2");
-
- const auto* ptr2 = buffer2.get();
-
- r = s.AddBuffer(std::move(buffer2));
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- const auto& buffers = s.GetBuffers();
- ASSERT_EQ(2U, buffers.size());
- EXPECT_EQ(ptr1, buffers[0].get());
- EXPECT_EQ(ptr2, buffers[1].get());
-}
-
-} // namespace amberscript
-} // namespace amber