diff options
-rw-r--r-- | src/amberscript/parser.cc | 19 | ||||
-rw-r--r-- | src/amberscript/parser_run_test.cc | 58 |
2 files changed, 70 insertions, 7 deletions
diff --git a/src/amberscript/parser.cc b/src/amberscript/parser.cc index 953fc12..8157476 100644 --- a/src/amberscript/parser.cc +++ b/src/amberscript/parser.cc @@ -1894,16 +1894,21 @@ Result Parser::ParseRun() { count = token->AsUint32(); } } + + uint32_t vertex_count = + indexed ? pipeline->GetIndexBuffer()->ElementCount() + : pipeline->GetVertexBuffers()[0].buffer->ElementCount(); + // If we get here then we never set count, as if count was set it must // be > 0. - if (count == 0) { - count = - pipeline->GetVertexBuffers()[0].buffer->ElementCount() - start_idx; - } + if (count == 0) + count = vertex_count - start_idx; - if (start_idx + count > - pipeline->GetVertexBuffers()[0].buffer->ElementCount()) { - return Result("START_IDX plus COUNT exceeds vertex buffer data size"); + if (start_idx + count > vertex_count) { + if (indexed) + return Result("START_IDX plus COUNT exceeds index buffer data size"); + else + return Result("START_IDX plus COUNT exceeds vertex buffer data size"); } auto cmd = MakeUnique<DrawArraysCommand>(pipeline, PipelineData{}); diff --git a/src/amberscript/parser_run_test.cc b/src/amberscript/parser_run_test.cc index 4911414..4d2d69c 100644 --- a/src/amberscript/parser_run_test.cc +++ b/src/amberscript/parser_run_test.cc @@ -1404,6 +1404,64 @@ RUN my_pipeline DRAW_ARRAY AS TRIANGLE_LIST START_IDX 1 COUNT 9)"; r.Error()); } +TEST_F(AmberScriptParserTest, RunDrawArraysIndexedStartIdxTooLarge) { + std::string in = R"( +SHADER vertex my_shader PASSTHROUGH +SHADER fragment my_fragment GLSL +# GLSL Shader +END +BUFFER vtex_buf DATA_TYPE vec3<float> DATA +1 2 3 +END +BUFFER indices DATA_TYPE int32 DATA +0 1 2 1 2 0 +END + +PIPELINE graphics my_pipeline + ATTACH my_shader + ATTACH my_fragment + VERTEX_DATA vtex_buf LOCATION 0 + INDEX_DATA indices +END + +RUN my_pipeline DRAW_ARRAY AS TRIANGLE_LIST INDEXED START_IDX 6 COUNT 1)"; + + Parser parser; + Result r = parser.Parse(in); + ASSERT_FALSE(r.IsSuccess()); + EXPECT_EQ("20: START_IDX plus COUNT exceeds index buffer data size", + r.Error()); +} + +TEST_F(AmberScriptParserTest, RunDrawArraysIndexedCountTooLarge) { + std::string in = R"( +SHADER vertex my_shader PASSTHROUGH +SHADER fragment my_fragment GLSL +# GLSL Shader +END +BUFFER vtex_buf DATA_TYPE vec3<float> DATA +1 2 3 +END +BUFFER indices DATA_TYPE int32 DATA +0 1 2 1 2 0 +END + +PIPELINE graphics my_pipeline + ATTACH my_shader + ATTACH my_fragment + VERTEX_DATA vtex_buf LOCATION 0 + INDEX_DATA indices +END + +RUN my_pipeline DRAW_ARRAY AS TRIANGLE_LIST INDEXED START_IDX 1 COUNT 6)"; + + Parser parser; + Result r = parser.Parse(in); + ASSERT_FALSE(r.IsSuccess()); + EXPECT_EQ("20: START_IDX plus COUNT exceeds index buffer data size", + r.Error()); +} + TEST_F(AmberScriptParserTest, RunDrawArraysInvalidCountValueFormat) { std::string in = R"( SHADER vertex my_shader PASSTHROUGH |