diff options
author | dan sinclair <dj2@everburning.com> | 2019-02-21 15:45:53 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-21 15:45:53 -0500 |
commit | 585cb72d9bf34b038ba82e39284d96f0bf6f2c42 (patch) | |
tree | b3eddb7693caf1dcb9a7296fbf6870347b5fa55b /src | |
parent | 6bf5315b230a022037354789cc1c8968300b7800 (diff) | |
download | amber-585cb72d9bf34b038ba82e39284d96f0bf6f2c42.tar.gz |
Add fbsize require setting (#315)
This CL adds parsing for the `fbsize 200 200` requirement to set the
framebuffer size for a given script.
Fixes #12.
Diffstat (limited to 'src')
-rw-r--r-- | src/vkscript/parser.cc | 36 | ||||
-rw-r--r-- | src/vkscript/parser_test.cc | 60 | ||||
-rw-r--r-- | src/vulkan/engine_vulkan.cc | 6 |
3 files changed, 95 insertions, 7 deletions
diff --git a/src/vkscript/parser.cc b/src/vkscript/parser.cc index 416a27a..e6403de 100644 --- a/src/vkscript/parser.cc +++ b/src/vkscript/parser.cc @@ -34,7 +34,8 @@ uint32_t kDefaultFrameBufferSize = 250; const char kDefaultPipelineName[] = "vk_pipeline"; bool IsKnownFeature(const std::string& name) { - // Note framebuffer, depthstencil and fence_timeout are not matched here. + // Note framebuffer, depthstencil, fbsize and fence_timeout are not matched + // here. return name == "robustBufferAccess" || name == "fullDrawIndexUint32" || name == "imageCubeArray" || name == "independentBlend" || name == "geometryShader" || name == "tessellationShader" || @@ -185,7 +186,8 @@ Result Parser::ProcessShaderBlock(const SectionParser::Section& section) { Result Parser::ProcessRequireBlock(const SectionParser::Section& section) { Tokenizer tokenizer(section.contents); - tokenizer.SetCurrentLine(section.starting_line_number); + tokenizer.SetCurrentLine(section.starting_line_number + 1); + for (auto token = tokenizer.NextToken(); !token->IsEOS(); token = tokenizer.NextToken()) { if (token->IsEOL()) @@ -250,6 +252,34 @@ Result Parser::ProcessRequireBlock(const SectionParser::Section& section) { return Result(make_error(tokenizer, "Missing fence_timeout value")); script_->GetEngineData().fence_timeout_ms = token->AsUint32(); + + } else if (str == "fbsize") { + auto* pipeline = script_->GetPipeline(kDefaultPipelineName); + + token = tokenizer.NextToken(); + if (token->IsEOL() || token->IsEOS()) { + return Result(make_error( + tokenizer, "Missing width and height for fbsize command")); + } + if (!token->IsInteger()) { + return Result( + make_error(tokenizer, "Invalid width for fbsize command")); + } + + pipeline->SetFramebufferWidth(token->AsUint32()); + + token = tokenizer.NextToken(); + if (token->IsEOL() || token->IsEOS()) { + return Result( + make_error(tokenizer, "Missing height for fbsize command")); + } + if (!token->IsInteger()) { + return Result( + make_error(tokenizer, "Invalid height for fbsize command")); + } + + pipeline->SetFramebufferHeight(token->AsUint32()); + } else { auto it = std::find_if(str.begin(), str.end(), [](char c) { return !(isalnum(c) || c == '_'); }); @@ -264,7 +294,7 @@ Result Parser::ProcessRequireBlock(const SectionParser::Section& section) { token = tokenizer.NextToken(); if (!token->IsEOS() && !token->IsEOL()) { return Result(make_error( - tokenizer, "Failed to parser requirements block: invalid token: " + + tokenizer, "Failed to parse requirements block: invalid token: " + token->ToOriginalString())); } } diff --git a/src/vkscript/parser_test.cc b/src/vkscript/parser_test.cc index b2fe86d..29a72fc 100644 --- a/src/vkscript/parser_test.cc +++ b/src/vkscript/parser_test.cc @@ -151,6 +151,66 @@ TEST_F(VkScriptParserTest, RequireBlockDepthStencil) { buffers[1]->AsFormatBuffer()->GetFormat().GetFormatType()); } +TEST_F(VkScriptParserTest, RequireFbSize) { + std::string block = "[require]\nfbsize 300 400"; + + Parser parser; + Result r = parser.Parse(block); + ASSERT_TRUE(r.IsSuccess()) << r.Error(); + + auto script = parser.GetScript(); + const auto& pipelines = script->GetPipelines(); + ASSERT_EQ(1U, pipelines.size()); + EXPECT_EQ(300, pipelines[0]->GetFramebufferWidth()); + EXPECT_EQ(400, pipelines[0]->GetFramebufferHeight()); +} + +TEST_F(VkScriptParserTest, RequireFbSizeMissingSize) { + std::string block = "[require]\nfbsize"; + + Parser parser; + Result r = parser.Parse(block); + ASSERT_FALSE(r.IsSuccess()); + EXPECT_EQ("2: Missing width and height for fbsize command", r.Error()); +} + +TEST_F(VkScriptParserTest, RequireFbSizeMissingValue) { + std::string block = "[require]\nfbsize 200"; + + Parser parser; + Result r = parser.Parse(block); + ASSERT_FALSE(r.IsSuccess()); + EXPECT_EQ("2: Missing height for fbsize command", r.Error()); +} + +TEST_F(VkScriptParserTest, RequireFbSizeExtraParams) { + std::string block = "[require]\nfbsize 200 300 EXTRA"; + + Parser parser; + Result r = parser.Parse(block); + ASSERT_FALSE(r.IsSuccess()); + EXPECT_EQ("2: Failed to parse requirements block: invalid token: EXTRA", + r.Error()); +} + +TEST_F(VkScriptParserTest, RequireFbSizeInvalidFirstParam) { + std::string block = "[require]\nfbsize INVALID 200"; + + Parser parser; + Result r = parser.Parse(block); + ASSERT_FALSE(r.IsSuccess()); + EXPECT_EQ("2: Invalid width for fbsize command", r.Error()); +} + +TEST_F(VkScriptParserTest, RequireFbSizeInvalidSecondParam) { + std::string block = "[require]\nfbsize 200 INVALID"; + + Parser parser; + Result r = parser.Parse(block); + ASSERT_FALSE(r.IsSuccess()); + EXPECT_EQ("2: Invalid height for fbsize command", r.Error()); +} + TEST_F(VkScriptParserTest, RequireBlockMultipleLines) { std::string block = R"([require] # Requirements block stuff. diff --git a/src/vulkan/engine_vulkan.cc b/src/vulkan/engine_vulkan.cc index 5bd20ce..1ae9c8e 100644 --- a/src/vulkan/engine_vulkan.cc +++ b/src/vulkan/engine_vulkan.cc @@ -29,8 +29,6 @@ namespace amber { namespace vulkan { namespace { -const uint32_t kFramebufferWidth = 250; -const uint32_t kFramebufferHeight = 250; const FormatType kDefaultFramebufferFormat = FormatType::kB8G8R8A8_UNORM; VkShaderStageFlagBits ToVkShaderStage(ShaderType type) { @@ -206,8 +204,8 @@ Result EngineVulkan::CreatePipeline(amber::Pipeline* pipeline) { engine_data.fence_timeout_ms, GetShaderStageInfo()); Result r = pipeline_->AsGraphics()->Initialize( - kFramebufferWidth, kFramebufferHeight, pool_->GetCommandPool(), - device_->GetQueue()); + pipeline->GetFramebufferWidth(), pipeline->GetFramebufferHeight(), + pool_->GetCommandPool(), device_->GetQueue()); if (!r.IsSuccess()) return r; } |