aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordan sinclair <dj2@everburning.com>2019-01-24 13:45:43 -0500
committerGitHub <noreply@github.com>2019-01-24 13:45:43 -0500
commit4784d319d7a5a434068642eef40d0cdc57375558 (patch)
tree20d7efe826019624eae48dc2228b8b5b7f5d5211 /src
parent9749446771ff9da897dc9fcb3b5793e1993b9f15 (diff)
downloadamber-4784d319d7a5a434068642eef40d0cdc57375558.tar.gz
[amberscript] Buffer parsering updates. (#244)
This CL updates the AmberScript parser to handle the changes to the BUFFER syntax.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/amberscript/parser.cc79
-rw-r--r--src/amberscript/parser.h1
-rw-r--r--src/amberscript/parser_test.cc534
-rw-r--r--src/buffer.cc6
-rw-r--r--src/buffer.h8
-rw-r--r--src/buffer_data.h2
-rw-r--r--src/format_parser.cc (renamed from src/vkscript/format_parser.cc)6
-rw-r--r--src/format_parser.h (renamed from src/vkscript/format_parser.h)11
-rw-r--r--src/format_parser_test.cc (renamed from src/vkscript/format_parser_test.cc)6
-rw-r--r--src/vkscript/parser.cc2
11 files changed, 168 insertions, 491 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ad4aa2f..62ec033 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -22,6 +22,7 @@ set(AMBER_SOURCES
engine.cc
executor.cc
format.cc
+ format_parser.cc
parser.cc
pipeline.cc
pipeline_data.cc
@@ -36,7 +37,6 @@ set(AMBER_SOURCES
verifier.cc
vkscript/command_parser.cc
vkscript/datum_type_parser.cc
- vkscript/format_parser.cc
vkscript/parser.cc
vkscript/section_parser.cc
)
@@ -77,6 +77,7 @@ if (${AMBER_ENABLE_TESTS})
buffer_test.cc
command_data_test.cc
executor_test.cc
+ format_parser_test.cc
pipeline_test.cc
result_test.cc
script_test.cc
@@ -85,7 +86,6 @@ if (${AMBER_ENABLE_TESTS})
verifier_test.cc
vkscript/command_parser_test.cc
vkscript/datum_type_parser_test.cc
- vkscript/format_parser_test.cc
vkscript/parser_test.cc
vkscript/section_parser_test.cc
)
diff --git a/src/amberscript/parser.cc b/src/amberscript/parser.cc
index 580f513..c397b85 100644
--- a/src/amberscript/parser.cc
+++ b/src/amberscript/parser.cc
@@ -20,6 +20,7 @@
#include <utility>
#include <vector>
+#include "src/format_parser.h"
#include "src/make_unique.h"
#include "src/shader_data.h"
#include "src/tokenizer.h"
@@ -403,8 +404,6 @@ Result Parser::ToBufferType(const std::string& str, BufferType* type) {
*type = BufferType::kColor;
else if (str == "depth")
*type = BufferType::kDepth;
- else if (str == "framebuffer")
- *type = BufferType::kFramebuffer;
else if (str == "index")
*type = BufferType::kIndex;
else if (str == "sampled")
@@ -424,87 +423,49 @@ Result Parser::ToBufferType(const std::string& str, BufferType* type) {
Result Parser::ParseBuffer() {
auto token = tokenizer_->NextToken();
if (!token->IsString())
- return Result("invalid BUFFER type provided");
-
- BufferType type;
- Result r = ToBufferType(token->AsString(), &type);
- if (!r.IsSuccess())
- return r;
-
- auto buffer = MakeUnique<DataBuffer>(type);
-
- token = tokenizer_->NextToken();
- if (!token->IsString())
return Result("invalid BUFFER name provided");
- auto& name = token->AsString();
- if (name == "DATA_TYPE" || name == "DIMS")
+ auto name = token->AsString();
+ if (name == "DATA_TYPE" || name == "FORMAT")
return Result("missing BUFFER name");
- buffer->SetName(token->AsString());
-
token = tokenizer_->NextToken();
if (!token->IsString())
return Result("invalid BUFFER command provided");
+ std::unique_ptr<Buffer> buffer;
auto& cmd = token->AsString();
if (cmd == "DATA_TYPE") {
- if (type == BufferType::kFramebuffer)
- return Result("BUFFER framebuffer must be used with DIMS");
+ buffer = MakeUnique<DataBuffer>();
- r = ParseBufferInitializer(buffer.get());
+ Result r = ParseBufferInitializer(buffer->AsDataBuffer());
if (!r.IsSuccess())
return r;
- } else if (cmd == "DIMS") {
- if (type != BufferType::kFramebuffer)
- return Result("BUFFER DIMS can only be used with a framebuffer");
+ } else if (cmd == "FORMAT") {
+ token = tokenizer_->NextToken();
+ if (!token->IsString())
+ return Result("BUFFER FORMAT must be a string");
- r = ParseBufferFramebuffer(buffer.get());
- if (!r.IsSuccess())
- return r;
+ buffer = MakeUnique<FormatBuffer>();
+
+ FormatParser fmt_parser;
+ auto fmt = fmt_parser.Parse(token->AsString());
+ if (fmt == nullptr)
+ return Result("invalid BUFFER FORMAT");
+
+ buffer->AsFormatBuffer()->SetFormat(std::move(fmt));
} else {
return Result("unknown BUFFER command provided: " + cmd);
}
+ buffer->SetName(name);
- r = script_->AddBuffer(std::move(buffer));
+ Result r = script_->AddBuffer(std::move(buffer));
if (!r.IsSuccess())
return r;
return {};
}
-Result Parser::ParseBufferFramebuffer(DataBuffer* buffer) {
- auto token = tokenizer_->NextToken();
- if (token->IsEOL() || token->IsEOS())
- return Result("BUFFER framebuffer missing DIMS values");
- if (!token->IsInteger())
- return Result("BUFFER framebuffer invalid width value");
-
- // TODO(dsinclair): Is uint32 rgba the right format to use here?
- DatumType datum;
- datum.SetType(DataType::kUint32);
- datum.SetColumnCount(4);
- buffer->SetDatumType(datum);
-
- auto w = token->AsUint32();
-
- token = tokenizer_->NextToken();
- if (token->IsEOS() || token->IsEOL())
- return Result("BUFFER framebuffer missing height value");
- if (!token->IsInteger())
- return Result("BUFFER framebuffer invalid height value");
-
- auto h = token->AsUint32();
-
- // TODO(dsinclair): Should this be a smaller maximum size?
- uint64_t size = static_cast<uint64_t>(w) * static_cast<uint64_t>(h);
- if (size >= std::numeric_limits<uint32_t>::max())
- return Result("BUFFER framebuffer size too large");
-
- buffer->SetSize(static_cast<size_t>(size));
- return ValidateEndOfStatement("BUFFER framebuffer command");
-}
-
Result Parser::ParseBufferInitializer(DataBuffer* buffer) {
auto token = tokenizer_->NextToken();
if (!token->IsString())
diff --git a/src/amberscript/parser.h b/src/amberscript/parser.h
index be922dd..e64924a 100644
--- a/src/amberscript/parser.h
+++ b/src/amberscript/parser.h
@@ -52,7 +52,6 @@ class Parser : public amber::Parser {
Result ParseBufferInitializerFill(DataBuffer*, uint32_t);
Result ParseBufferInitializerSeries(DataBuffer*, uint32_t);
Result ParseBufferInitializerData(DataBuffer*);
- Result ParseBufferFramebuffer(DataBuffer*);
Result ParseShaderBlock();
Result ParsePipelineBlock();
Result ParsePipelineAttach(Pipeline*);
diff --git a/src/amberscript/parser_test.cc b/src/amberscript/parser_test.cc
index fea347a..56bdd90 100644
--- a/src/amberscript/parser_test.cc
+++ b/src/amberscript/parser_test.cc
@@ -933,7 +933,7 @@ END)";
TEST_F(AmberScriptParserTest, BufferData) {
std::string in = R"(
-BUFFER storage my_buffer DATA_TYPE uint32 DATA
+BUFFER my_buffer DATA_TYPE uint32 DATA
1 2 3 4
55 99 1234
END)";
@@ -948,7 +948,6 @@ END)";
ASSERT_TRUE(buffers[0] != nullptr);
EXPECT_EQ("my_buffer", buffers[0]->GetName());
- EXPECT_EQ(BufferType::kStorage, buffers[0]->GetBufferType());
ASSERT_TRUE(buffers[0]->IsDataBuffer());
auto* buffer = buffers[0]->AsDataBuffer();
@@ -966,7 +965,7 @@ END)";
}
TEST_F(AmberScriptParserTest, BufferFill) {
- std::string in = "BUFFER color my_buffer DATA_TYPE uint8 SIZE 5 FILL 5";
+ std::string in = "BUFFER my_buffer DATA_TYPE uint8 SIZE 5 FILL 5";
Parser parser;
Result r = parser.Parse(in);
@@ -980,7 +979,6 @@ TEST_F(AmberScriptParserTest, BufferFill) {
ASSERT_TRUE(buffers[0]->IsDataBuffer());
auto* buffer = buffers[0]->AsDataBuffer();
EXPECT_EQ("my_buffer", buffer->GetName());
- EXPECT_EQ(BufferType::kColor, buffer->GetBufferType());
EXPECT_TRUE(buffer->GetDatumType().IsUint8());
EXPECT_EQ(5U, buffer->GetSize());
EXPECT_EQ(5U * sizeof(uint8_t), buffer->GetSizeInBytes());
@@ -995,7 +993,7 @@ TEST_F(AmberScriptParserTest, BufferFill) {
}
TEST_F(AmberScriptParserTest, BufferFillFloat) {
- std::string in = "BUFFER color my_buffer DATA_TYPE float SIZE 5 FILL 5.2";
+ std::string in = "BUFFER my_buffer DATA_TYPE float SIZE 5 FILL 5.2";
Parser parser;
Result r = parser.Parse(in);
@@ -1009,7 +1007,6 @@ TEST_F(AmberScriptParserTest, BufferFillFloat) {
ASSERT_TRUE(buffers[0]->IsDataBuffer());
auto* buffer = buffers[0]->AsDataBuffer();
EXPECT_EQ("my_buffer", buffer->GetName());
- EXPECT_EQ(BufferType::kColor, buffer->GetBufferType());
EXPECT_TRUE(buffer->GetDatumType().IsFloat());
EXPECT_EQ(5U, buffer->GetSize());
EXPECT_EQ(5U * sizeof(float), buffer->GetSizeInBytes());
@@ -1025,7 +1022,7 @@ TEST_F(AmberScriptParserTest, BufferFillFloat) {
TEST_F(AmberScriptParserTest, BufferSeries) {
std::string in =
- "BUFFER color my_buffer DATA_TYPE uint8 SIZE 5 SERIES_FROM 2 INC_BY 1";
+ "BUFFER my_buffer DATA_TYPE uint8 SIZE 5 SERIES_FROM 2 INC_BY 1";
Parser parser;
Result r = parser.Parse(in);
@@ -1039,7 +1036,6 @@ TEST_F(AmberScriptParserTest, BufferSeries) {
ASSERT_TRUE(buffers[0]->IsDataBuffer());
auto* buffer = buffers[0]->AsDataBuffer();
EXPECT_EQ("my_buffer", buffer->GetName());
- EXPECT_EQ(BufferType::kColor, buffer->GetBufferType());
EXPECT_TRUE(buffer->GetDatumType().IsUint8());
EXPECT_EQ(5U, buffer->GetSize());
EXPECT_EQ(5U * sizeof(uint8_t), buffer->GetSizeInBytes());
@@ -1055,7 +1051,7 @@ TEST_F(AmberScriptParserTest, BufferSeries) {
TEST_F(AmberScriptParserTest, BufferSeriesFloat) {
std::string in =
- "BUFFER color my_buffer DATA_TYPE float SIZE 5 SERIES_FROM 2.2 INC_BY "
+ "BUFFER my_buffer DATA_TYPE float SIZE 5 SERIES_FROM 2.2 INC_BY "
"1.1";
Parser parser;
@@ -1070,7 +1066,6 @@ TEST_F(AmberScriptParserTest, BufferSeriesFloat) {
ASSERT_TRUE(buffers[0]->IsDataBuffer());
auto* buffer = buffers[0]->AsDataBuffer();
EXPECT_EQ("my_buffer", buffer->GetName());
- EXPECT_EQ(BufferType::kColor, buffer->GetBufferType());
EXPECT_TRUE(buffer->GetDatumType().IsFloat());
EXPECT_EQ(5U, buffer->GetSize());
EXPECT_EQ(5U * sizeof(float), buffer->GetSizeInBytes());
@@ -1084,32 +1079,10 @@ TEST_F(AmberScriptParserTest, BufferSeriesFloat) {
}
}
-TEST_F(AmberScriptParserTest, BufferFramebuffer) {
- std::string in = "BUFFER framebuffer my_buffer DIMS 800 600";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_TRUE(r.IsSuccess()) << r.Error();
-
- auto script = parser.GetScript();
- const auto& buffers = script->GetBuffers();
- ASSERT_EQ(1U, buffers.size());
-
- ASSERT_TRUE(buffers[0] != nullptr);
- ASSERT_TRUE(buffers[0]->IsDataBuffer());
- auto* buffer = buffers[0]->AsDataBuffer();
- EXPECT_EQ("my_buffer", buffer->GetName());
- EXPECT_EQ(BufferType::kFramebuffer, buffer->GetBufferType());
- EXPECT_TRUE(buffer->GetDatumType().IsUint32());
- EXPECT_EQ(4U, buffer->GetDatumType().ColumnCount());
- EXPECT_EQ(800U * 600U, buffer->GetSize());
- EXPECT_EQ(800U * 600U * 4U * sizeof(uint32_t), buffer->GetSizeInBytes());
-}
-
TEST_F(AmberScriptParserTest, BufferMultipleBuffers) {
std::string in = R"(
-BUFFER color color_buffer DATA_TYPE uint8 SIZE 5 FILL 5
-BUFFER storage storage_buffer DATA_TYPE uint32 DATA
+BUFFER color_buffer DATA_TYPE uint8 SIZE 5 FILL 5
+BUFFER storage_buffer DATA_TYPE uint32 DATA
1 2 3 4
55 99 1234
END)";
@@ -1126,7 +1099,6 @@ END)";
ASSERT_TRUE(buffers[0]->IsDataBuffer());
auto* buffer = buffers[0]->AsDataBuffer();
EXPECT_EQ("color_buffer", buffer->GetName());
- EXPECT_EQ(BufferType::kColor, buffer->GetBufferType());
EXPECT_TRUE(buffer->GetDatumType().IsUint8());
EXPECT_EQ(5U, buffer->GetSize());
EXPECT_EQ(5U * sizeof(uint8_t), buffer->GetSizeInBytes());
@@ -1143,7 +1115,6 @@ END)";
ASSERT_TRUE(buffers[1]->IsDataBuffer());
buffer = buffers[1]->AsDataBuffer();
EXPECT_EQ("storage_buffer", buffer->GetName());
- EXPECT_EQ(BufferType::kStorage, buffer->GetBufferType());
EXPECT_TRUE(buffer->GetDatumType().IsUint32());
EXPECT_EQ(7U, buffer->GetSize());
EXPECT_EQ(7U * sizeof(uint32_t), buffer->GetSizeInBytes());
@@ -1159,7 +1130,7 @@ END)";
TEST_F(AmberScriptParserTest, BufferFillMultiRow) {
std::string in = R"(
-BUFFER index my_index_buffer DATA_TYPE vec2<int32> SIZE 5 FILL 2)";
+BUFFER my_index_buffer DATA_TYPE vec2<int32> SIZE 5 FILL 2)";
Parser parser;
Result r = parser.Parse(in);
@@ -1173,7 +1144,6 @@ BUFFER index my_index_buffer DATA_TYPE vec2<int32> SIZE 5 FILL 2)";
ASSERT_TRUE(buffers[0]->IsDataBuffer());
auto* buffer = buffers[0]->AsDataBuffer();
EXPECT_EQ("my_index_buffer", buffer->GetName());
- EXPECT_EQ(BufferType::kIndex, buffer->GetBufferType());
EXPECT_TRUE(buffer->GetDatumType().IsInt32());
EXPECT_EQ(5U, buffer->GetSize());
EXPECT_EQ(5U * 2 * sizeof(int32_t), buffer->GetSizeInBytes());
@@ -1189,7 +1159,7 @@ BUFFER index my_index_buffer DATA_TYPE vec2<int32> SIZE 5 FILL 2)";
TEST_F(AmberScriptParserTest, BufferDataMultiRow) {
std::string in = R"(
-BUFFER index my_index_buffer DATA_TYPE vec2<int32> DATA
+BUFFER my_index_buffer DATA_TYPE vec2<int32> DATA
2 3
4 5
6 7
@@ -1209,7 +1179,6 @@ END
ASSERT_TRUE(buffers[0]->IsDataBuffer());
auto* buffer = buffers[0]->AsDataBuffer();
EXPECT_EQ("my_index_buffer", buffer->GetName());
- EXPECT_EQ(BufferType::kIndex, buffer->GetBufferType());
EXPECT_TRUE(buffer->GetDatumType().IsInt32());
EXPECT_EQ(4U, buffer->GetSize());
EXPECT_EQ(4U * 2 * sizeof(int32_t), buffer->GetSizeInBytes());
@@ -1225,7 +1194,7 @@ END
TEST_F(AmberScriptParserTest, BufferDataHex) {
std::string in = R"(
-BUFFER index my_index_buffer DATA_TYPE uint32 DATA
+BUFFER my_index_buffer DATA_TYPE uint32 DATA
0xff000000
0x00ff0000
0x0000ff00
@@ -1245,7 +1214,6 @@ END
ASSERT_TRUE(buffers[0]->IsDataBuffer());
auto* buffer = buffers[0]->AsDataBuffer();
EXPECT_EQ("my_index_buffer", buffer->GetName());
- EXPECT_EQ(BufferType::kIndex, buffer->GetBufferType());
EXPECT_TRUE(buffer->GetDatumType().IsUint32());
EXPECT_EQ(4U, buffer->GetSize());
EXPECT_EQ(4U * sizeof(uint32_t), buffer->GetSizeInBytes());
@@ -1259,358 +1227,8 @@ END
}
}
-TEST_F(AmberScriptParserTest, BufferInvalidType) {
- std::string in = "BUFFER 1234 color_buffer DATA_TYPE uint8 SIZE 5 FILL 5";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: invalid BUFFER type provided", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferUnknownType) {
- std::string in = "BUFFER UNKNOWN color_buffer DATA_TYPE uint8 SIZE 5 FILL 5";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: unknown BUFFER type provided: UNKNOWN", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferInvalidName) {
- std::string in = "BUFFER color 1234 DATA_TYPE uint8 SIZE 5 FILL 5";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: invalid BUFFER name provided", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferMissingName) {
- std::string in = "BUFFER color DATA_TYPE uint8 SIZE 5 FILL 5";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: missing BUFFER name", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferInvalidCommand) {
- std::string in = "BUFFER color my_buf 1234";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: invalid BUFFER command provided", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferUnknownCommand) {
- std::string in = "BUFFER color my_buf INVALID";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: unknown BUFFER command provided: INVALID", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferDimsWithoutFramebuffer) {
- std::string in = "BUFFER color my_buf DIMS 256 256";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: BUFFER DIMS can only be used with a framebuffer", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferFramebufferWithoutDims) {
- std::string in = "BUFFER framebuffer my_buf DATA_TYPE int32 FILL 0";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: BUFFER framebuffer must be used with DIMS", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferInvalidSize) {
- std::string in = "BUFFER color my_buf DATA_TYPE uint8 SIZE INVALID FILL 5";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: BUFFER size invalid", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferMissingSizeValue) {
- std::string in = "BUFFER color my_buf DATA_TYPE uint8 SIZE FILL 5";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: BUFFER size invalid", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferMissingFillValue) {
- std::string in = "BUFFER color my_buf DATA_TYPE uint8 SIZE 5 FILL";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: missing BUFFER fill value", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferInvalidFillValue) {
- std::string in = "BUFFER color my_buf DATA_TYPE uint8 SIZE 5 FILL INVALID";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: invalid BUFFER fill value", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferInvalidInitializer) {
- std::string in = "BUFFER color my_buf DATA_TYPE uint8 SIZE 5 INVALID 5";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: invalid BUFFER initializer provided", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferFillInvalidValue) {
- std::string in = "BUFFER color my_buf DATA_TYPE uint8 SIZE 5 FILL INVALID";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: invalid BUFFER fill value", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferFillingMissingValue) {
- std::string in = "BUFFER color my_buf DATA_TYPE uint8 SIZE 5 FILL";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: missing BUFFER fill value", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferSeriesMissingValue) {
- std::string in =
- "BUFFER color my_buf DATA_TYPE uint8 SIZE 5 SERIES_FROM INC_BY 2";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: invalid BUFFER series_from value", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferSeriesMissingInc) {
- std::string in = "BUFFER color my_buf DATA_TYPE uint8 SIZE 5 SERIES_FROM 2";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: missing BUFFER series_from inc_by", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferSeriesMissingIncValue) {
- std::string in =
- "BUFFER color my_buf DATA_TYPE uint8 SIZE 5 SERIES_FROM 2 INC_BY";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: missing BUFFER series_from inc_by value", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferSeriesInvalidStart) {
- std::string in =
- "BUFFER color my_buf DATA_TYPE uint8 SIZE 5 SERIES_FROM INVALID INC_BY 2";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: invalid BUFFER series_from value", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferSeriesInvalidInc) {
- std::string in =
- "BUFFER color my_buf DATA_TYPE uint8 SIZE 5 SERIES_FROM 1 INC_BY INVALID";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: invalid BUFFER series_from inc_by value", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferSeriesInvalidSuffix) {
- std::string in =
- "BUFFER color my_buf DATA_TYPE uint8 SIZE 5 SERIES_FROM 1 INVALID 2";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: BUFFER series_from invalid command", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferFramebufferMissingDims) {
- std::string in = "BUFFER framebuffer my_frame";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: invalid BUFFER command provided", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferFramebufferMissingDimValues) {
- std::string in = "BUFFER framebuffer my_frame DIMS";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: BUFFER framebuffer missing DIMS values", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferFramebufferMissingHeight) {
- std::string in = "BUFFER framebuffer my_frame DIMS 256";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: BUFFER framebuffer missing height value", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferFramebufferInvalidWidth) {
- std::string in = "BUFFER framebuffer my_frame DIMS INVALID 256";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: BUFFER framebuffer invalid width value", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferFramebufferFloatWidth) {
- std::string in = "BUFFER framebuffer my_frame DIMS 2.4 256";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: BUFFER framebuffer invalid width value", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferFramebufferInvalidHeight) {
- std::string in = "BUFFER framebuffer my_frame DIMS 256 INVALID";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: BUFFER framebuffer invalid height value", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferFramebufferFloatHeight) {
- std::string in = "BUFFER framebuffer my_frame DIMS 256 2.4";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: BUFFER framebuffer invalid height value", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferFramebufferTooLarge) {
- std::string in =
- "BUFFER framebuffer my_frame DIMS 99999999999999 9999999999999";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: BUFFER framebuffer size too large", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferDataInvalidValueFloatForInt) {
- std::string in = R"(
-BUFFER index my_index_buffer DATA_TYPE int32 DATA
-1.234
-END)";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("3: invalid BUFFER data value", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferDataInvalidValueString) {
- std::string in = R"(
-BUFFER index my_index_buffer DATA_TYPE int32 DATA
-INVALID
-END)";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("3: invalid BUFFER data value", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferDataExtraParams) {
- std::string in = R"(
-BUFFER index my_index_buffer DATA_TYPE int32 DATA INVALID
-123
-END)";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("2: extra parameters after BUFFER data command", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferFillExtraParams) {
- std::string in = R"(
-BUFFER index my_index_buffer DATA_TYPE int32 SIZE 256 FILL 5 INVALID
-123
-END)";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("2: extra parameters after BUFFER fill command", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferSeriesExtraParams) {
- std::string in =
- "BUFFER index my_buffer DATA_TYPE int32 SIZE 256 SERIES_FROM 2 INC_BY 5 "
- "INVALID";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: extra parameters after BUFFER series_from command", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferFramebufferExtraParams) {
- std::string in = "BUFFER framebuffer my_buffer DIMS 256 256 INVALID";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("1: extra parameters after BUFFER framebuffer command", r.Error());
-}
-
-TEST_F(AmberScriptParserTest, BufferDuplicateName) {
- std::string in = R"(
-BUFFER vertex my_buf DATA_TYPE int32 SIZE 5 FILL 5
-BUFFER index my_buf DATA_TYPE int16 SIZE 5 FILL 2)";
-
- Parser parser;
- Result r = parser.Parse(in);
- ASSERT_FALSE(r.IsSuccess());
- EXPECT_EQ("3: duplicate buffer name provided", r.Error());
-}
-
-using AmberScriptParserBufferTypeTest = testing::TestWithParam<BufferTypeData>;
-TEST_P(AmberScriptParserBufferTypeTest, BufferTypes) {
- auto test_data = GetParam();
-
- std::string in = std::string("BUFFER ") + test_data.name +
- " my_buf DATA_TYPE int32 SIZE 2 FILL 5";
+TEST_F(AmberScriptParserTest, BufferFormat) {
+ std::string in = "BUFFER my_buf FORMAT R32G32B32A32_SINT";
Parser parser;
Result r = parser.Parse(in);
@@ -1621,27 +1239,123 @@ TEST_P(AmberScriptParserBufferTypeTest, BufferTypes) {
ASSERT_EQ(1U, buffers.size());
ASSERT_TRUE(buffers[0] != nullptr);
- EXPECT_EQ(test_data.type, buffers[0]->GetBufferType());
+ ASSERT_TRUE(buffers[0]->IsFormatBuffer());
+ auto* buffer = buffers[0]->AsFormatBuffer();
+ EXPECT_EQ("my_buf", buffer->GetName());
+
+ auto& fmt = buffer->GetFormat();
+ auto& comps = fmt.GetComponents();
+ ASSERT_EQ(4U, comps.size());
+
+ EXPECT_EQ(FormatComponentType::kR, comps[0].type);
+ EXPECT_EQ(FormatMode::kSInt, comps[0].mode);
+ EXPECT_EQ(32U, comps[0].num_bits);
+ EXPECT_EQ(FormatComponentType::kG, comps[1].type);
+ EXPECT_EQ(FormatMode::kSInt, comps[1].mode);
+ EXPECT_EQ(32U, comps[1].num_bits);
+ EXPECT_EQ(FormatComponentType::kB, comps[2].type);
+ EXPECT_EQ(FormatMode::kSInt, comps[2].mode);
+ EXPECT_EQ(32U, comps[2].num_bits);
+ EXPECT_EQ(FormatComponentType::kA, comps[3].type);
+ EXPECT_EQ(FormatMode::kSInt, comps[3].mode);
+ EXPECT_EQ(32U, comps[3].num_bits);
+}
+
+struct BufferParseError {
+ const char* in;
+ const char* err;
+};
+using AmberScriptParserBufferParseErrorTest =
+ testing::TestWithParam<BufferParseError>;
+TEST_P(AmberScriptParserBufferParseErrorTest, Test) {
+ auto test_data = GetParam();
+
+ Parser parser;
+ Result r = parser.Parse(test_data.in);
+ ASSERT_FALSE(r.IsSuccess()) << test_data.in;
+ EXPECT_EQ(std::string(test_data.err), r.Error()) << test_data.in;
}
+
INSTANTIATE_TEST_CASE_P(
- AmberScriptParserTestsBufferType,
- AmberScriptParserBufferTypeTest,
- testing::Values(BufferTypeData{"uniform", BufferType::kUniform},
- BufferTypeData{"storage", BufferType::kStorage},
- BufferTypeData{"vertex", BufferType::kVertex},
- BufferTypeData{"index", BufferType::kIndex},
- BufferTypeData{"sampled", BufferType::kSampled},
- BufferTypeData{"color", BufferType::kColor},
- BufferTypeData{
- "depth",
- BufferType::kDepth}), ); // NOLINT(whitespace/parens)
+ AmberScriptParserBufferParseErrorTest,
+ AmberScriptParserBufferParseErrorTest,
+ testing::Values(
+ BufferParseError{"BUFFER my_buf FORMAT 123",
+ "1: BUFFER FORMAT must be a string"},
+ BufferParseError{"BUFFER my_buf FORMAT A23A32",
+ "1: invalid BUFFER FORMAT"},
+ BufferParseError{"BUFFER my_buf FORMAT",
+ "1: BUFFER FORMAT must be a string"},
+ BufferParseError{"BUFFER my_buffer FORMAT R32G32B32A32_SFLOAT EXTRA",
+ "1: unknown token: EXTRA"},
+ BufferParseError{"BUFFER 1234 DATA_TYPE uint8 SIZE 5 FILL 5",
+ "1: invalid BUFFER name provided"},
+ BufferParseError{"BUFFER DATA_TYPE uint8 SIZE 5 FILL 5",
+ "1: missing BUFFER name"},
+
+ BufferParseError{"BUFFER my_buf 1234",
+ "1: invalid BUFFER command provided"},
+ BufferParseError{"BUFFER my_buf INVALID",
+ "1: unknown BUFFER command provided: INVALID"},
+ BufferParseError{"BUFFER my_buf DATA_TYPE uint8 SIZE INVALID FILL 5",
+ "1: BUFFER size invalid"},
+ BufferParseError{"BUFFER my_buf DATA_TYPE uint8 SIZE FILL 5",
+ "1: BUFFER size invalid"},
+ BufferParseError{"BUFFER my_buf DATA_TYPE uint8 SIZE 5 FILL",
+ "1: missing BUFFER fill value"},
+ BufferParseError{"BUFFER my_buf DATA_TYPE uint8 SIZE 5 FILL INVALID",
+ "1: invalid BUFFER fill value"},
+ BufferParseError{"BUFFER my_buf DATA_TYPE uint8 SIZE 5 INVALID 5",
+ "1: invalid BUFFER initializer provided"},
+ BufferParseError{"BUFFER my_buf DATA_TYPE uint8 SIZE 5 FILL INVALID",
+ "1: invalid BUFFER fill value"},
+ BufferParseError{"BUFFER my_buf DATA_TYPE uint8 SIZE 5 FILL",
+ "1: missing BUFFER fill value"},
+ BufferParseError{
+ "BUFFER my_buf DATA_TYPE uint8 SIZE 5 SERIES_FROM INC_BY 2",
+ "1: invalid BUFFER series_from value"},
+ BufferParseError{"BUFFER my_buf DATA_TYPE uint8 SIZE 5 SERIES_FROM 2",
+ "1: missing BUFFER series_from inc_by"},
+ BufferParseError{
+ "BUFFER my_buf DATA_TYPE uint8 SIZE 5 SERIES_FROM 2 INC_BY",
+ "1: missing BUFFER series_from inc_by value"},
+ BufferParseError{"BUFFER my_buf DATA_TYPE uint8 SIZE 5 "
+ "SERIES_FROM INVALID INC_BY 2",
+ "1: invalid BUFFER series_from value"},
+ BufferParseError{"BUFFER my_buf DATA_TYPE uint8 SIZE 5 "
+ "SERIES_FROM 1 INC_BY INVALID",
+ "1: invalid BUFFER series_from inc_by value"},
+ BufferParseError{"BUFFER my_buf DATA_TYPE uint8 SIZE 5 "
+ "SERIES_FROM 1 INVALID 2",
+ "1: BUFFER series_from invalid command"},
+ BufferParseError{
+ "BUFFER my_index_buffer DATA_TYPE int32 DATA\n1.234\nEND",
+ "2: invalid BUFFER data value"},
+ BufferParseError{
+ "BUFFER my_index_buffer DATA_TYPE int32 DATA\nINVALID\nEND",
+ "2: invalid BUFFER data value"},
+ BufferParseError{
+ "BUFFER my_index_buffer DATA_TYPE int32 DATA INVALID\n123\nEND",
+ "1: extra parameters after BUFFER data command"},
+ BufferParseError{"BUFFER my_index_buffer DATA_TYPE int32 SIZE 256 FILL "
+ "5 INVALID\n123\nEND",
+ "1: extra parameters after BUFFER fill command"},
+ BufferParseError{
+ "BUFFER my_buffer DATA_TYPE int32 SIZE 256 SERIES_FROM 2 "
+ "INC_BY 5 "
+ "INVALID",
+ "1: extra parameters after BUFFER series_from command"},
+ BufferParseError{"BUFFER my_buf DATA_TYPE int32 SIZE 5 FILL 5\nBUFFER "
+ "my_buf DATA_TYPE int16 SIZE 5 FILL 2",
+ // NOLINTNEXTLINE(whitespace/parens)
+ "2: duplicate buffer name provided"}), );
using AmberScriptParserBufferDataTypeTest = testing::TestWithParam<BufferData>;
TEST_P(AmberScriptParserBufferDataTypeTest, BufferTypes) {
auto test_data = GetParam();
- std::string in = std::string("BUFFER vertex my_buf DATA_TYPE ") +
- test_data.name + " SIZE 2 FILL 5";
+ std::string in = std::string("BUFFER my_buf DATA_TYPE ") + test_data.name +
+ " SIZE 2 FILL 5";
Parser parser;
Result r = parser.Parse(in);
@@ -1685,8 +1399,8 @@ using AmberScriptParserBufferDataTypeInvalidTest =
TEST_P(AmberScriptParserBufferDataTypeInvalidTest, BufferTypes) {
auto test_data = GetParam();
- std::string in = std::string("BUFFER vertex my_buf DATA_TYPE ") +
- test_data.name + " SIZE 4 FILL 5";
+ std::string in = std::string("BUFFER my_buf DATA_TYPE ") + test_data.name +
+ " SIZE 4 FILL 5";
Parser parser;
Result r = parser.Parse(in);
diff --git a/src/buffer.cc b/src/buffer.cc
index e4736da..eeabf76 100644
--- a/src/buffer.cc
+++ b/src/buffer.cc
@@ -16,6 +16,8 @@
namespace amber {
+Buffer::Buffer() = default;
+
Buffer::Buffer(BufferType type) : buffer_type_(type) {}
Buffer::~Buffer() = default;
@@ -28,10 +30,14 @@ FormatBuffer* Buffer::AsFormatBuffer() {
return static_cast<FormatBuffer*>(this);
}
+DataBuffer::DataBuffer() = default;
+
DataBuffer::DataBuffer(BufferType type) : Buffer(type) {}
DataBuffer::~DataBuffer() = default;
+FormatBuffer::FormatBuffer() = default;
+
FormatBuffer::FormatBuffer(BufferType type) : Buffer(type) {}
FormatBuffer::~FormatBuffer() = default;
diff --git a/src/buffer.h b/src/buffer.h
index 668dd65..6fd4c7f 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -49,6 +49,8 @@ class Buffer {
/// true for this method to be used.
FormatBuffer* AsFormatBuffer();
+ /// Sets the type of data stored in the buffer.
+ void SetBufferType(BufferType type) { buffer_type_ = type; }
/// Returns the BufferType of this buffer.
BufferType GetBufferType() const { return buffer_type_; }
@@ -77,7 +79,9 @@ class Buffer {
const std::vector<Value>& GetData() const { return data_; }
protected:
- /// Create a buffer of |type|.
+ /// Create an un-typed buffer.
+ Buffer();
+ /// Create a buffer of |type_|.
explicit Buffer(BufferType type);
private:
@@ -91,6 +95,7 @@ class Buffer {
/// A buffer class where the data is described by a |DatumType| object.
class DataBuffer : public Buffer {
public:
+ DataBuffer();
explicit DataBuffer(BufferType type);
~DataBuffer() override;
@@ -116,6 +121,7 @@ class DataBuffer : public Buffer {
/// A buffer class where the data is described by a |format| object.
class FormatBuffer : public Buffer {
public:
+ FormatBuffer();
explicit FormatBuffer(BufferType type);
~FormatBuffer() override;
diff --git a/src/buffer_data.h b/src/buffer_data.h
index 387018d..6ed8213 100644
--- a/src/buffer_data.h
+++ b/src/buffer_data.h
@@ -23,8 +23,6 @@ enum class BufferType : uint8_t {
kColor = 0,
/// A depth/stencil buffer.
kDepth,
- /// A framebuffer.
- kFramebuffer,
/// An index buffer.
kIndex,
/// A sampled buffer.
diff --git a/src/vkscript/format_parser.cc b/src/format_parser.cc
index 7830c37..982cbdb 100644
--- a/src/vkscript/format_parser.cc
+++ b/src/format_parser.cc
@@ -1,4 +1,4 @@
-// Copyright 2018 The Amber Authors.
+// Copyright 2019 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.
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "src/vkscript/format_parser.h"
+#include "src/format_parser.h"
#include <cassert>
#include <cstdlib>
@@ -20,7 +20,6 @@
#include "src/make_unique.h"
namespace amber {
-namespace vkscript {
FormatParser::FormatParser() = default;
@@ -501,5 +500,4 @@ std::unique_ptr<Format> FormatParser::ParseGlslFormat(const std::string& fmt) {
return Parse(new_name);
}
-} // namespace vkscript
} // namespace amber
diff --git a/src/vkscript/format_parser.h b/src/format_parser.h
index 7cef303..e99d956 100644
--- a/src/vkscript/format_parser.h
+++ b/src/format_parser.h
@@ -1,4 +1,4 @@
-// Copyright 2018 The Amber Authors.
+// Copyright 2019 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.
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#ifndef SRC_VKSCRIPT_FORMAT_PARSER_H_
-#define SRC_VKSCRIPT_FORMAT_PARSER_H_
+#ifndef SRC_FORMAT_PARSER_H_
+#define SRC_FORMAT_PARSER_H_
#include <memory>
#include <string>
@@ -25,8 +25,6 @@ namespace amber {
class Format;
-namespace vkscript {
-
class FormatParser {
public:
FormatParser();
@@ -51,7 +49,6 @@ class FormatParser {
std::vector<Pieces> pieces_;
};
-} // namespace vkscript
} // namespace amber
-#endif // SRC_VKSCRIPT_FORMAT_PARSER_H_
+#endif // SRC_FORMAT_PARSER_H_
diff --git a/src/vkscript/format_parser_test.cc b/src/format_parser_test.cc
index 5f97493..d1d6a9a 100644
--- a/src/vkscript/format_parser_test.cc
+++ b/src/format_parser_test.cc
@@ -1,4 +1,4 @@
-// Copyright 2018 The Amber Authors.
+// Copyright 2019 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.
@@ -12,11 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "src/vkscript/format_parser.h"
+#include "src/format_parser.h"
#include "gtest/gtest.h"
namespace amber {
-namespace vkscript {
using FormatParserTest = testing::Test;
@@ -1274,5 +1273,4 @@ TEST_F(FormatParserTest, GlslStringInvalid) {
}
}
-} // namespace vkscript
} // namespace amber
diff --git a/src/vkscript/parser.cc b/src/vkscript/parser.cc
index 4c50dd8..2fffda5 100644
--- a/src/vkscript/parser.cc
+++ b/src/vkscript/parser.cc
@@ -21,10 +21,10 @@
#include <utility>
#include <vector>
+#include "src/format_parser.h"
#include "src/make_unique.h"
#include "src/shader.h"
#include "src/vkscript/command_parser.h"
-#include "src/vkscript/format_parser.h"
namespace amber {
namespace vkscript {