Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions include/amber/amber.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ enum EngineType {
kEngineTypeDawn,
};

enum class ExecutionType {
/// Execute as normal.
kExecute = 0,
/// Only create the pipelines and then exit.
kPipelineCreateOnly
};

/// Override point of engines to add their own configuration.
struct EngineConfig {
virtual ~EngineConfig();
Expand Down Expand Up @@ -101,8 +108,12 @@ struct Options {
std::string spv_env;
/// Lists the buffers to extract at the end of the execution
std::vector<BufferInfo> extractions;
/// Terminate after creating the pipelines.
bool pipeline_create_only;
/// The type of execution. For example, execute as normal or just create the
/// piplines and exit.
ExecutionType execution_type;
/// If true, disables SPIR-V validation. If false, SPIR-V shaders will be
/// validated using the Validator component (spirv-val) from SPIRV-Tools.
bool disable_spirv_validation;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this up with pipeline_create_only.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

/// Delegate implementation
Delegate* delegate;
};
Expand Down
9 changes: 8 additions & 1 deletion samples/amber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct Options {
bool log_graphics_calls = false;
bool log_graphics_calls_time = false;
bool log_execute_calls = false;
bool disable_spirv_validation = false;
amber::EngineType engine = amber::kEngineTypeVulkan;
std::string spv_env;
};
Expand Down Expand Up @@ -86,6 +87,7 @@ const char kUsage[] = R"(Usage: amber [options] SCRIPT [SCRIPTS...]
--log-graphics-calls -- Log graphics API calls (only for Vulkan so far).
--log-graphics-calls-time -- Log timing of graphics API calls timing (Vulkan only).
--log-execute-calls -- Log each execute call before run.
--disable-spirv-val -- Disable SPIR-V validation.
-h -- This help text.
)";

Expand Down Expand Up @@ -193,6 +195,8 @@ bool ParseArgs(const std::vector<std::string>& args, Options* opts) {
opts->log_graphics_calls_time = true;
} else if (arg == "--log-execute-calls") {
opts->log_execute_calls = true;
} else if (arg == "--disable-spirv-val") {
opts->disable_spirv_validation = true;
} else if (arg.size() > 0 && arg[0] == '-') {
std::cerr << "Unrecognized option " << arg << std::endl;
return false;
Expand Down Expand Up @@ -352,8 +356,11 @@ int main(int argc, const char** argv) {
amber::Options amber_options;
amber_options.engine = options.engine;
amber_options.spv_env = options.spv_env;
amber_options.pipeline_create_only = options.pipeline_create_only;
amber_options.execution_type = options.pipeline_create_only
? amber::ExecutionType::kPipelineCreateOnly
: amber::ExecutionType::kExecute;
amber_options.delegate = &delegate;
amber_options.disable_spirv_validation = options.disable_spirv_validation;

std::set<std::string> required_features;
std::set<std::string> required_device_extensions;
Expand Down
9 changes: 4 additions & 5 deletions src/amber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ EngineConfig::~EngineConfig() = default;
Options::Options()
: engine(amber::EngineType::kEngineTypeVulkan),
config(nullptr),
pipeline_create_only(false),
execution_type(ExecutionType::kExecute),
disable_spirv_validation(false),
delegate(nullptr) {}

Options::~Options() = default;
Expand Down Expand Up @@ -168,10 +169,8 @@ amber::Result Amber::ExecuteWithShaderData(const amber::Recipe* recipe,
script->SetSpvTargetEnv(opts->spv_env);

Executor executor;
Result executor_result = executor.Execute(
engine.get(), script, opts->delegate, shader_data,
opts->pipeline_create_only ? ExecutionType::kPipelineCreateOnly
: ExecutionType::kExecute);
Result executor_result =
executor.Execute(engine.get(), script, shader_data, opts);
// Hold the executor result until the extractions are complete. This will let
// us dump any buffers requested even on failure.

Expand Down
19 changes: 11 additions & 8 deletions src/executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ Executor::Executor() = default;
Executor::~Executor() = default;

Result Executor::CompileShaders(const amber::Script* script,
const ShaderMap& shader_map) {
const ShaderMap& shader_map,
Options* options) {
for (auto& pipeline : script->GetPipelines()) {
for (auto& shader_info : pipeline->GetShaders()) {
ShaderCompiler sc(script->GetSpvTargetEnv());
ShaderCompiler sc(script->GetSpvTargetEnv(),
options->disable_spirv_validation);

Result r;
std::vector<uint32_t> data;
Expand All @@ -49,13 +51,12 @@ Result Executor::CompileShaders(const amber::Script* script,

Result Executor::Execute(Engine* engine,
const amber::Script* script,
Delegate* delegate,
const ShaderMap& shader_map,
ExecutionType executionType) {
Options* options) {
engine->SetEngineData(script->GetEngineData());

if (!script->GetPipelines().empty()) {
Result r = CompileShaders(script, shader_map);
Result r = CompileShaders(script, shader_map, options);
if (!r.IsSuccess())
return r;

Expand All @@ -76,13 +77,15 @@ Result Executor::Execute(Engine* engine,
}
}

if (executionType == ExecutionType::kPipelineCreateOnly)
if (options->execution_type == ExecutionType::kPipelineCreateOnly)
return {};

// Process Commands
for (const auto& cmd : script->GetCommands()) {
if (delegate && delegate->LogExecuteCalls())
delegate->Log(std::to_string(cmd->GetLine()) + ": " + cmd->ToString());
if (options->delegate && options->delegate->LogExecuteCalls()) {
options->delegate->Log(std::to_string(cmd->GetLine()) + ": " +
cmd->ToString());
}

Result r = ExecuteCommand(engine, cmd.get());
if (!r.IsSuccess())
Expand Down
9 changes: 4 additions & 5 deletions src/executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

namespace amber {

enum class ExecutionType { kExecute = 0, kPipelineCreateOnly };

/// The executor is responsible for running the given script against an engine.
class Executor {
public:
Expand All @@ -37,12 +35,13 @@ class Executor {
/// used as the shader binary.
Result Execute(Engine* engine,
const Script* script,
Delegate* delegate,
const ShaderMap& map,
ExecutionType executionType);
Options* options);

private:
Result CompileShaders(const Script* script, const ShaderMap& shader_map);
Result CompileShaders(const Script* script,
const ShaderMap& shader_map,
Options* options);
Result ExecuteCommand(Engine* engine, Command* cmd);

Verifier verifier_;
Expand Down
Loading