Skip to content
Closed
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
6 changes: 4 additions & 2 deletions include/amber/amber.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ class Amber {
Amber();
~Amber();

/// Parse the given |data| into the |recipe|.
amber::Result Parse(const std::string& data, amber::Recipe* recipe);
/// Parse the given |data| into the |recipe|. Perform validation if
/// |validate| set to true.
amber::Result Parse(const std::string& data, amber::Recipe* recipe,
const bool validate = true);

/// Determines whether the engine supports all features required by the
/// |recipe|. Modifies the |recipe| by applying some of the |opts| to the
Expand Down
7 changes: 6 additions & 1 deletion src/amber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ Amber::Amber() = default;

Amber::~Amber() = default;

amber::Result Amber::Parse(const std::string& input, amber::Recipe* recipe) {
amber::Result Amber::Parse(const std::string& input,
amber::Recipe* recipe,
const bool validate) {
if (!recipe)
return Result("Recipe must be provided to Parse.");

Expand All @@ -96,6 +98,9 @@ amber::Result Amber::Parse(const std::string& input, amber::Recipe* recipe) {
else
parser = MakeUnique<vkscript::Parser>();

if (!validate)
parser->SkipValidationForTest();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is only to be used in testing and shouldn't appear anywhere else.


Result r = parser->Parse(input);
if (!r.IsSuccess())
return r;
Expand Down
10 changes: 6 additions & 4 deletions src/amberscript/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ Result Parser::Parse(const std::string& data) {

// Validate all the pipelines at the end. This allows us to verify the
// framebuffer sizes are consistent over pipelines.
for (const auto& pipeline : script_->GetPipelines()) {
Result r = pipeline->Validate();
if (!r.IsSuccess())
return r;
if (!skip_validation_for_test_) {
for (const auto& pipeline : script_->GetPipelines()) {
Result r = pipeline->Validate();
if (!r.IsSuccess())
return r;
}
}

return {};
Expand Down
5 changes: 5 additions & 0 deletions src/amberscript/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ class Parser : public amber::Parser {
// amber::Parser
Result Parse(const std::string& data) override;

/// Disables validation after parse.
void SkipValidationForTest() { skip_validation_for_test_ = true; }

private:
bool skip_validation_for_test_ = false;

std::string make_error(const std::string& err);
Result ToShaderType(const std::string& str, ShaderType* type);
Result ToBufferType(const std::string& str, BufferType* type);
Expand Down
3 changes: 3 additions & 0 deletions src/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class Parser {
/// completes correctly.
virtual Result Parse(const std::string& data) = 0;

/// Disables validation after parse.
virtual void SkipValidationForTest() = 0;

/// Retrieve the script which is generated by the parser.
std::unique_ptr<Script> GetScript() { return std::move(script_); }

Expand Down
1 change: 1 addition & 0 deletions src/vkscript/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Parser : public amber::Parser {
// amber::Parser
Result Parse(const std::string& data) override;

/// Disables validation after parse.
void SkipValidationForTest() { skip_validation_for_test_ = true; }

private:
Expand Down