-
Notifications
You must be signed in to change notification settings - Fork 70
Shader specialization #525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c3cce4a
1d8f1fd
e23f31b
5d38497
ab9bcfe
68563c7
72d29e9
6f0cb86
ee2bc2f
424b582
ad897a1
efcbe80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -215,7 +215,7 @@ END)"; | |
| Parser parser; | ||
| Result r = parser.Parse(in); | ||
| ASSERT_FALSE(r.IsSuccess()); | ||
| EXPECT_EQ("6: extra parameters after ATTACH command", r.Error()); | ||
| EXPECT_EQ("6: Unknown ATTACH parameter: INVALID", r.Error()); | ||
| } | ||
|
|
||
| TEST_F(AmberScriptParserTest, PiplineMultiShaderAttach) { | ||
|
|
@@ -307,5 +307,198 @@ END)"; | |
| EXPECT_EQ("6: ATTACH missing TYPE for multi shader", r.Error()); | ||
| } | ||
|
|
||
| TEST_F(AmberScriptParserTest, PipelineSpecializationUint32) { | ||
| std::string in = R"( | ||
| SHADER compute my_shader GLSL | ||
| #shaders | ||
| END | ||
| PIPELINE compute my_pipeline | ||
| ATTACH my_shader TYPE compute ENTRY_POINT my_ep SPECIALIZE 1 AS uint32 4 | ||
| END)"; | ||
|
|
||
| Parser parser; | ||
| Result r = parser.Parse(in); | ||
| EXPECT_EQ(r.Error(), ""); | ||
| ASSERT_TRUE(r.IsSuccess()); | ||
|
|
||
| auto script = parser.GetScript(); | ||
| const auto& pipelines = script->GetPipelines(); | ||
| ASSERT_EQ(1U, pipelines.size()); | ||
|
|
||
| const auto* pipeline = pipelines[0].get(); | ||
| const auto& shaders = pipeline->GetShaders(); | ||
| ASSERT_EQ(1U, shaders.size()); | ||
|
|
||
| EXPECT_EQ(1, shaders[0].GetSpecialization().size()); | ||
| EXPECT_EQ(4, shaders[0].GetSpecialization().at(1)); | ||
| } | ||
|
|
||
| TEST_F(AmberScriptParserTest, PipelineSpecializationInt32) { | ||
| std::string in = R"( | ||
| SHADER compute my_shader GLSL | ||
| #shaders | ||
| END | ||
| PIPELINE compute my_pipeline | ||
| ATTACH my_shader TYPE compute ENTRY_POINT my_ep SPECIALIZE 2 AS int32 -1 | ||
| END)"; | ||
|
|
||
| Parser parser; | ||
| Result r = parser.Parse(in); | ||
| ASSERT_TRUE(r.IsSuccess()); | ||
|
|
||
| auto script = parser.GetScript(); | ||
| const auto& pipelines = script->GetPipelines(); | ||
| ASSERT_EQ(1U, pipelines.size()); | ||
|
|
||
| const auto* pipeline = pipelines[0].get(); | ||
| const auto& shaders = pipeline->GetShaders(); | ||
| ASSERT_EQ(1U, shaders.size()); | ||
|
|
||
| EXPECT_EQ(1, shaders[0].GetSpecialization().size()); | ||
| EXPECT_EQ(0xffffffff, shaders[0].GetSpecialization().at(2)); | ||
| } | ||
|
|
||
| TEST_F(AmberScriptParserTest, PipelineSpecializationFloat) { | ||
| std::string in = R"( | ||
| SHADER compute my_shader GLSL | ||
| #shaders | ||
| END | ||
| PIPELINE compute my_pipeline | ||
| ATTACH my_shader TYPE compute ENTRY_POINT my_ep SPECIALIZE 3 AS float 1.1 | ||
| END)"; | ||
|
|
||
| Parser parser; | ||
| Result r = parser.Parse(in); | ||
| ASSERT_TRUE(r.IsSuccess()); | ||
|
|
||
| auto script = parser.GetScript(); | ||
| const auto& pipelines = script->GetPipelines(); | ||
| ASSERT_EQ(1U, pipelines.size()); | ||
|
|
||
| const auto* pipeline = pipelines[0].get(); | ||
| const auto& shaders = pipeline->GetShaders(); | ||
| ASSERT_EQ(1U, shaders.size()); | ||
|
|
||
| EXPECT_EQ(1, shaders[0].GetSpecialization().size()); | ||
| EXPECT_EQ(0x3f8ccccd, shaders[0].GetSpecialization().at(3)); | ||
| } | ||
|
|
||
| TEST_F(AmberScriptParserTest, PipelineSpecializationIDIsString) { | ||
| std::string in = R"( | ||
| SHADER compute my_shader GLSL | ||
| #shaders | ||
| END | ||
| PIPELINE compute my_pipeline | ||
| ATTACH my_shader TYPE compute ENTRY_POINT my_ep SPECIALIZE s3 AS float 1.1 | ||
| END)"; | ||
|
|
||
| Parser parser; | ||
| Result r = parser.Parse(in); | ||
| ASSERT_FALSE(r.IsSuccess()); | ||
| EXPECT_EQ("6: specialization ID must be an integer", r.Error()); | ||
| } | ||
|
|
||
| TEST_F(AmberScriptParserTest, PipelineSpecializationNoAS) { | ||
| std::string in = R"( | ||
| SHADER compute my_shader GLSL | ||
| #shaders | ||
| END | ||
| PIPELINE compute my_pipeline | ||
| ATTACH my_shader TYPE compute ENTRY_POINT my_ep SPECIALIZE 1 ASa float 1.1 | ||
| END)"; | ||
|
|
||
| Parser parser; | ||
| Result r = parser.Parse(in); | ||
| ASSERT_FALSE(r.IsSuccess()); | ||
| EXPECT_EQ("6: expected AS as next token", r.Error()); | ||
| } | ||
|
|
||
| TEST_F(AmberScriptParserTest, PipelineSpecializationNotDataType) { | ||
| std::string in = R"( | ||
| SHADER compute my_shader GLSL | ||
| #shaders | ||
| END | ||
| PIPELINE compute my_pipeline | ||
| ATTACH my_shader TYPE compute ENTRY_POINT my_ep SPECIALIZE 1 AS uint 1.1 | ||
| END)"; | ||
|
|
||
| Parser parser; | ||
| Result r = parser.Parse(in); | ||
| ASSERT_FALSE(r.IsSuccess()); | ||
| EXPECT_EQ("6: invalid data_type provided", r.Error()); | ||
| } | ||
|
|
||
| TEST_F(AmberScriptParserTest, PipelineSpecializationBadDataType) { | ||
| std::string in = R"( | ||
| SHADER compute my_shader GLSL | ||
| #shaders | ||
| END | ||
| PIPELINE compute my_pipeline | ||
| ATTACH my_shader ENTRY_POINT my_ep SPECIALIZE 1 AS uint8 1.1 | ||
| END)"; | ||
|
|
||
| Parser parser; | ||
| Result r = parser.Parse(in); | ||
| ASSERT_FALSE(r.IsSuccess()); | ||
| EXPECT_EQ( | ||
| "6: only 32-bit types are currently accepted for specialization values", | ||
| r.Error()); | ||
| } | ||
|
|
||
| TEST_F(AmberScriptParserTest, PipelineSpecializationMultipleSpecializations) { | ||
| std::string in = R"( | ||
| SHADER compute my_shader GLSL | ||
| #shaders | ||
| END | ||
| PIPELINE compute my_pipeline | ||
| ATTACH my_shader TYPE compute ENTRY_POINT my_ep \ | ||
| SPECIALIZE 1 AS uint32 4 \ | ||
| SPECIALIZE 2 AS uint32 5 \ | ||
| SPECIALIZE 5 AS uint32 1 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this, it reads well and keeps the data grouped together nicely. |
||
| END)"; | ||
|
|
||
| Parser parser; | ||
| Result r = parser.Parse(in); | ||
| ASSERT_TRUE(r.IsSuccess()); | ||
|
|
||
| auto script = parser.GetScript(); | ||
| const auto& pipelines = script->GetPipelines(); | ||
| ASSERT_EQ(1U, pipelines.size()); | ||
|
|
||
| const auto* pipeline = pipelines[0].get(); | ||
| const auto& shaders = pipeline->GetShaders(); | ||
| ASSERT_EQ(1U, shaders.size()); | ||
|
|
||
| EXPECT_EQ(3, shaders[0].GetSpecialization().size()); | ||
| EXPECT_EQ(4, shaders[0].GetSpecialization().at(1)); | ||
| EXPECT_EQ(5, shaders[0].GetSpecialization().at(2)); | ||
| EXPECT_EQ(1, shaders[0].GetSpecialization().at(5)); | ||
| } | ||
|
|
||
| TEST_F(AmberScriptParserTest, PipelineSpecializationNoType) { | ||
| std::string in = R"( | ||
| SHADER compute my_shader GLSL | ||
| #shaders | ||
| END | ||
| PIPELINE compute my_pipeline | ||
| ATTACH my_shader SPECIALIZE 1 AS uint32 4 | ||
| END)"; | ||
|
|
||
| Parser parser; | ||
| Result r = parser.Parse(in); | ||
| ASSERT_TRUE(r.IsSuccess()); | ||
|
|
||
| auto script = parser.GetScript(); | ||
| const auto& pipelines = script->GetPipelines(); | ||
| ASSERT_EQ(1U, pipelines.size()); | ||
|
|
||
| const auto* pipeline = pipelines[0].get(); | ||
| const auto& shaders = pipeline->GetShaders(); | ||
| ASSERT_EQ(1U, shaders.size()); | ||
|
|
||
| EXPECT_EQ(1, shaders[0].GetSpecialization().size()); | ||
| EXPECT_EQ(4, shaders[0].GetSpecialization().at(1)); | ||
| } | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add one more test where we setup a pipeline with shader specialization and then we
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| } // namespace amberscript | ||
| } // namespace amber | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably want to do token->ConvertToDouble() here before getting AsFloat otherwise a 1 will come back as 0 as the double value is zero and the token is an integer.
Also, I dont' think you need the union dance.