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
24 changes: 24 additions & 0 deletions docs/amber_script.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,30 @@ The following commands are all specified within the `PIPELINE` command.
POLYGON_MODE {mode}
```

#### Compare operations
* `never`
* `less`
* `equal`
* `less_or_equal`
* `greater`
* `not_equal`
* `greater_or_equal`
* `always`

```groovy
# Set depth test settings. All enable options are specified with keywords on and off.
# BOUNDS and BIAS values are specified with decimal numbers. |compare_op| is selected
# from the list of compare operations above.
DEPTH
TEST {test_enable}
WRITE {write_enable}
COMPARE_OP {compare_op}
CLAMP {clamp_enable}
BOUNDS min {bound_min} max {bounds_max}
BIAS constant {bias_constant} clamp {bias_clamp} slope {bias_slope}
END
```

```groovy
# Set the size of the render buffers. |width| and |height| are integers and
# default to 250x250.
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ if (${AMBER_ENABLE_TESTS})
amberscript/parser_clear_test.cc
amberscript/parser_compile_options_test.cc
amberscript/parser_copy_test.cc
amberscript/parser_depth_test.cc
amberscript/parser_device_feature_test.cc
amberscript/parser_expect_test.cc
amberscript/parser_extension_test.cc
Expand Down
138 changes: 138 additions & 0 deletions src/amberscript/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,27 @@ ImageDimension StrToImageDimension(const std::string& str) {
return ImageDimension::kUnknown;
}

CompareOp StrToCompareOp(const std::string& str) {
if (str == "never")
return CompareOp::kNever;
if (str == "less")
return CompareOp::kLess;
if (str == "equal")
return CompareOp::kEqual;
if (str == "less_or_equal")
return CompareOp::kLessOrEqual;
if (str == "greater")
return CompareOp::kGreater;
if (str == "not_equal")
return CompareOp::kNotEqual;
if (str == "greater_or_equal")
return CompareOp::kGreaterOrEqual;
if (str == "always")
return CompareOp::kAlways;

return CompareOp::kUnknown;
}

Result ParseBufferData(Buffer* buffer,
Tokenizer* tokenizer,
bool from_data_file) {
Expand Down Expand Up @@ -548,6 +569,8 @@ Result Parser::ParsePipelineBody(const std::string& cmd_name,
r = ParsePipelineShaderCompileOptions(pipeline.get());
} else if (tok == "POLYGON_MODE") {
r = ParsePipelinePolygonMode(pipeline.get());
} else if (tok == "DEPTH") {
r = ParsePipelineDepth(pipeline.get());
} else {
r = Result("unknown token in pipeline block: " + tok);
}
Expand Down Expand Up @@ -1169,6 +1192,121 @@ Result Parser::ParsePipelinePolygonMode(Pipeline* pipeline) {
return ValidateEndOfStatement("POLYGON_MODE command");
}

Result Parser::ParsePipelineDepth(Pipeline* pipeline) {
while (true) {
auto token = tokenizer_->NextToken();
if (token->IsEOL())
continue;
if (token->IsEOS())
return Result("DEPTH missing END command");
if (!token->IsIdentifier())
return Result("DEPTH options must be identifiers");
if (token->AsString() == "END")
break;

if (token->AsString() == "TEST") {
token = tokenizer_->NextToken();

if (!token->IsIdentifier())
return Result("invalid value for TEST");

if (token->AsString() == "on")
pipeline->GetPipelineData()->SetEnableDepthTest(true);
else if (token->AsString() == "off")
pipeline->GetPipelineData()->SetEnableDepthTest(false);
else
return Result("invalid value for TEST: " + token->AsString());
} else if (token->AsString() == "CLAMP") {
token = tokenizer_->NextToken();

if (!token->IsIdentifier())
return Result("invalid value for CLAMP");

if (token->AsString() == "on")
pipeline->GetPipelineData()->SetEnableDepthClamp(true);
else if (token->AsString() == "off")
pipeline->GetPipelineData()->SetEnableDepthClamp(false);
else
return Result("invalid value for CLAMP: " + token->AsString());
} else if (token->AsString() == "WRITE") {
token = tokenizer_->NextToken();

if (!token->IsIdentifier())
return Result("invalid value for WRITE");

if (token->AsString() == "on")
pipeline->GetPipelineData()->SetEnableDepthWrite(true);
else if (token->AsString() == "off")
pipeline->GetPipelineData()->SetEnableDepthWrite(false);
else
return Result("invalid value for WRITE: " + token->AsString());
} else if (token->AsString() == "COMPARE_OP") {
token = tokenizer_->NextToken();

if (!token->IsIdentifier())
return Result("invalid value for COMPARE_OP");

CompareOp compare_op = StrToCompareOp(token->AsString());
if (compare_op != CompareOp::kUnknown) {
pipeline->GetPipelineData()->SetDepthCompareOp(compare_op);
} else {
return Result("invalid value for COMPARE_OP: " + token->AsString());
}
} else if (token->AsString() == "BOUNDS") {
token = tokenizer_->NextToken();
if (!token->IsIdentifier() || token->AsString() != "min")
return Result("BOUNDS expecting min");

token = tokenizer_->NextToken();
if (!token->IsDouble())
return Result("BOUNDS invalid value for min");
pipeline->GetPipelineData()->SetMinDepthBounds(token->AsFloat());

token = tokenizer_->NextToken();
if (!token->IsIdentifier() || token->AsString() != "max")
return Result("BOUNDS expecting max");

token = tokenizer_->NextToken();
if (!token->IsDouble())
return Result("BOUNDS invalid value for max");
pipeline->GetPipelineData()->SetMaxDepthBounds(token->AsFloat());
} else if (token->AsString() == "BIAS") {
pipeline->GetPipelineData()->SetEnableDepthBias(true);

token = tokenizer_->NextToken();
if (!token->IsIdentifier() || token->AsString() != "constant")
return Result("BIAS expecting constant");

token = tokenizer_->NextToken();
if (!token->IsDouble())
return Result("BIAS invalid value for constant");
pipeline->GetPipelineData()->SetDepthBiasConstantFactor(token->AsFloat());

token = tokenizer_->NextToken();
if (!token->IsIdentifier() || token->AsString() != "clamp")
return Result("BIAS expecting clamp");

token = tokenizer_->NextToken();
if (!token->IsDouble())
return Result("BIAS invalid value for clamp");
pipeline->GetPipelineData()->SetDepthBiasClamp(token->AsFloat());

token = tokenizer_->NextToken();
if (!token->IsIdentifier() || token->AsString() != "slope")
return Result("BIAS expecting slope");

token = tokenizer_->NextToken();
if (!token->IsDouble())
return Result("BIAS invalid value for slope");
pipeline->GetPipelineData()->SetDepthBiasSlopeFactor(token->AsFloat());
} else {
return Result("invalid value for DEPTH: " + token->AsString());
}
}

return ValidateEndOfStatement("DEPTH command");
}

Result Parser::ParseStruct() {
auto token = tokenizer_->NextToken();
if (!token->IsIdentifier())
Expand Down
1 change: 1 addition & 0 deletions src/amberscript/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Parser : public amber::Parser {
Result ParsePipelineIndexData(Pipeline*);
Result ParsePipelineSet(Pipeline*);
Result ParsePipelinePolygonMode(Pipeline*);
Result ParsePipelineDepth(Pipeline* pipeline);
Result ParseRun();
Result ParseDebug();
Result ParseDebugThread(debug::Events*);
Expand Down
Loading