aboutsummaryrefslogtreecommitdiff
path: root/src/executor.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/executor.cc')
-rw-r--r--src/executor.cc134
1 files changed, 134 insertions, 0 deletions
diff --git a/src/executor.cc b/src/executor.cc
index 249a89f..c6f8eae 100644
--- a/src/executor.cc
+++ b/src/executor.cc
@@ -14,10 +14,144 @@
#include "src/executor.h"
+#include <cassert>
+#include <vector>
+
+#include "src/engine.h"
+#include "src/script.h"
+#include "src/shader_compiler.h"
+
namespace amber {
Executor::Executor() = default;
Executor::~Executor() = default;
+Result Executor::Execute(Engine* engine,
+ const amber::Script* script,
+ const ShaderMap& shader_map) {
+ engine->SetEngineData(script->GetEngineData());
+
+ // Process Shader nodes
+ PipelineType pipeline_type = PipelineType::kGraphics;
+ for (const auto& shader : script->GetShaders()) {
+ ShaderCompiler sc;
+
+ Result r;
+ std::vector<uint32_t> data;
+ std::tie(r, data) = sc.Compile(shader.get(), shader_map);
+ if (!r.IsSuccess())
+ return r;
+
+ r = engine->SetShader(shader->GetType(), data);
+ if (!r.IsSuccess())
+ return r;
+
+ if (shader->GetType() == ShaderType::kCompute)
+ pipeline_type = PipelineType::kCompute;
+ }
+
+ // Handle Image and Depth buffers early so they are available when we call
+ // the CreatePipeline method.
+ for (const auto& buf : script->GetBuffers()) {
+ // Image and depth are handled earler. They will be moved to the pipeline
+ // object when it exists.
+ if (buf->GetBufferType() != BufferType::kColor &&
+ buf->GetBufferType() != BufferType::kDepth) {
+ continue;
+ }
+
+ Result r = engine->SetBuffer(
+ buf->GetBufferType(), buf->GetLocation(),
+ buf->IsFormatBuffer() ? buf->AsFormatBuffer()->GetFormat() : Format(),
+ buf->GetData());
+ if (!r.IsSuccess())
+ return r;
+ }
+
+ // TODO(jaebaek): Support multiple pipelines.
+ Result r = engine->CreatePipeline(pipeline_type);
+ if (!r.IsSuccess())
+ return r;
+
+ // Process Buffers
+ for (const auto& buf : script->GetBuffers()) {
+ // Image and depth are handled earler. They will be moved to the pipeline
+ // object when it exists.
+ if (buf->GetBufferType() == BufferType::kColor ||
+ buf->GetBufferType() == BufferType::kDepth) {
+ continue;
+ }
+
+ r = engine->SetBuffer(
+ buf->GetBufferType(), buf->GetLocation(),
+ buf->IsFormatBuffer() ? buf->AsFormatBuffer()->GetFormat() : Format(),
+ buf->GetData());
+ if (!r.IsSuccess())
+ return r;
+ }
+
+ // Process Commands
+ for (const auto& cmd : script->GetCommands()) {
+ if (cmd->IsProbe()) {
+ ResourceInfo info;
+
+ r = engine->DoProcessCommands();
+ if (!r.IsSuccess())
+ return r;
+
+ // This must come after processing commands because we require
+ // the frambuffer buffer to be mapped into host memory and have
+ // a valid host-side pointer.
+ r = engine->GetFrameBufferInfo(&info);
+ if (!r.IsSuccess())
+ return r;
+ assert(info.cpu_memory != nullptr);
+
+ r = verifier_.Probe(cmd->AsProbe(), info.image_info.texel_stride,
+ info.image_info.row_stride, info.image_info.width,
+ info.image_info.height, info.cpu_memory);
+ } else if (cmd->IsProbeSSBO()) {
+ auto probe_ssbo = cmd->AsProbeSSBO();
+ ResourceInfo info;
+ r = engine->GetDescriptorInfo(probe_ssbo->GetDescriptorSet(),
+ probe_ssbo->GetBinding(), &info);
+ if (!r.IsSuccess())
+ return r;
+
+ r = engine->DoProcessCommands();
+ if (!r.IsSuccess())
+ return r;
+
+ r = verifier_.ProbeSSBO(probe_ssbo, info.size_in_bytes, info.cpu_memory);
+ } else if (cmd->IsClear()) {
+ r = engine->DoClear(cmd->AsClear());
+ } else if (cmd->IsClearColor()) {
+ r = engine->DoClearColor(cmd->AsClearColor());
+ } else if (cmd->IsClearDepth()) {
+ r = engine->DoClearDepth(cmd->AsClearDepth());
+ } else if (cmd->IsClearStencil()) {
+ r = engine->DoClearStencil(cmd->AsClearStencil());
+ } else if (cmd->IsDrawRect()) {
+ r = engine->DoDrawRect(cmd->AsDrawRect());
+ } else if (cmd->IsDrawArrays()) {
+ r = engine->DoDrawArrays(cmd->AsDrawArrays());
+ } else if (cmd->IsCompute()) {
+ r = engine->DoCompute(cmd->AsCompute());
+ } else if (cmd->IsEntryPoint()) {
+ r = engine->DoEntryPoint(cmd->AsEntryPoint());
+ } else if (cmd->IsPatchParameterVertices()) {
+ r = engine->DoPatchParameterVertices(cmd->AsPatchParameterVertices());
+ } else if (cmd->IsBuffer()) {
+ r = engine->DoBuffer(cmd->AsBuffer());
+ } else {
+ return Result("Unknown command type");
+ }
+
+ if (!r.IsSuccess())
+ return r;
+ }
+ return {};
+}
+
} // namespace amber