From ea4e9975310f9f9c32445e4016eccc6f5c48f627 Mon Sep 17 00:00:00 2001 From: aliPMPAINT Date: Sat, 27 Feb 2021 20:24:26 +0330 Subject: [PATCH 1/6] added initial test --- test/TestShaderResources.cpp | 89 ++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 test/TestShaderResources.cpp diff --git a/test/TestShaderResources.cpp b/test/TestShaderResources.cpp new file mode 100644 index 000000000..95ca36b3b --- /dev/null +++ b/test/TestShaderResources.cpp @@ -0,0 +1,89 @@ +#include "gtest/gtest.h" + +#include "kompute/Kompute.hpp" + +const TBuiltInResource noMaxLightResource = { /* .MaxLights = */ 0, 6, 32, 32, 64, 4096, 64, 32, 80, 32, 4096, 32, 128, 8, 16, 16, 15, -8, 7, 8, 65535, 65535, 65535, 1024, 1024, 64, 1024, 16, 8, 8, 1, 60, 64, 64, 128, 128, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 16, 256, 1024, 1024, 64, 128, 128, 16, 1024, 4096, 128, 128, 16, 1024, 120, 32, 64, 16, 0, 0, 0, 0, 8, 8, 1, 0, 0, 0, 0, 1, 1, 16384, 4, 64, 8, 8, 4, 256, 512, 32, 1, 1, 32, 1, 1, 4, 1, {true, true, true, true, true, true, true, true, true}}; + +TEST(TestShaderResources, TestNoMaxLight) +{ + + kp::Manager mgr; + + auto tensorInA = mgr.tensor({ 2., 2., 2. }); + auto tensorInB = mgr.tensor({ 1., 2., 3. }); + auto tensorOut = mgr.tensor({ 0., 0., 0. }); + + std::string shaderString = (R"( + #version 450 + + layout (local_size_x = 1) in; + + // The input tensors bind index is relative to index in parameter passed + layout(set = 0, binding = 0) buffer bina { float tina[]; }; + layout(set = 0, binding = 1) buffer binb { float tinb[]; }; + layout(set = 0, binding = 2) buffer bout { float tout[]; }; + + void main() { + uint index = gl_GlobalInvocationID.x; + + int i = 1; + + while(i < 200) { + tout[index] += tina[index] * tinb[index]; + i++; + } + } + )"); + + + mgr.evalOpDefault( + { tensorInA, tensorInB, tensorOut }, + kp::Shader::compile_source(shaderString, "main", std::vector>({}), noMaxLightResource)); + + mgr.evalOpDefault({ tensorInA, tensorInB, tensorOut }); + + SUCCEED(); +} + +const TBuiltInResource noWhileLoopResource = { 32, 6, 32, 32, 64, 4096, 64, 32, 80, 32, 4096, 32, 128, 8, 16, 16, 15, -8, 7, 8, 65535, 65535, 65535, 1024, 1024, 64, 1024, 16, 8, 8, 1, 60, 64, 64, 128, 128, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 16, 256, 1024, 1024, 64, 128, 128, 16, 1024, 4096, 128, 128, 16, 1024, 120, 32, 64, 16, 0, 0, 0, 0, 8, 8, 1, 0, 0, 0, 0, 1, 1, 16384, 4, 64, 8, 8, 4, 256, 512, 32, 1, 1, 32, 1, 1, 4, 1, {true, /* .whileLoops = */false, true, true, true, true, true, true, true}}; + + +TEST(TestShaderResources, TestNoWhileLoop) +{ + + kp::Manager mgr; + + auto tensorInA = mgr.tensor({ 2., 2., 2. }); + auto tensorInB = mgr.tensor({ 1., 2., 3. }); + auto tensorOut = mgr.tensor({ 0., 0., 0. }); + + std::string shaderString = (R"( + #version 450 + + layout (local_size_x = 1) in; + + layout(set = 0, binding = 0) buffer bina { float tina[]; }; + layout(set = 0, binding = 1) buffer binb { float tinb[]; }; + layout(set = 0, binding = 2) buffer bout { float tout[]; }; + + void main() { + uint index = gl_GlobalInvocationID.x; + + int i = 1; + + while(i < 200) { + tout[index] += tina[index] * tinb[index]; + i++; + } + } + )"); + + + mgr.evalOpDefault( + { tensorInA, tensorInB, tensorOut }, + kp::Shader::compile_source(shaderString, "main", std::vector>({}), noWhileLoopResource)); + + mgr.evalOpDefault({ tensorInA, tensorInB, tensorOut }); + + FAIL(); +} From 01037ca16a3bb02dd9ccf18420652d6384622626 Mon Sep 17 00:00:00 2001 From: aliPMPAINT Date: Sun, 28 Feb 2021 12:12:51 +0330 Subject: [PATCH 2/6] updates ShaderResources Test --- test/TestShaderResources.cpp | 106 ++++++++++------------------------- 1 file changed, 31 insertions(+), 75 deletions(-) diff --git a/test/TestShaderResources.cpp b/test/TestShaderResources.cpp index 95ca36b3b..703237500 100644 --- a/test/TestShaderResources.cpp +++ b/test/TestShaderResources.cpp @@ -2,88 +2,44 @@ #include "kompute/Kompute.hpp" -const TBuiltInResource noMaxLightResource = { /* .MaxLights = */ 0, 6, 32, 32, 64, 4096, 64, 32, 80, 32, 4096, 32, 128, 8, 16, 16, 15, -8, 7, 8, 65535, 65535, 65535, 1024, 1024, 64, 1024, 16, 8, 8, 1, 60, 64, 64, 128, 128, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 16, 256, 1024, 1024, 64, 128, 128, 16, 1024, 4096, 128, 128, 16, 1024, 120, 32, 64, 16, 0, 0, 0, 0, 8, 8, 1, 0, 0, 0, 0, 1, 1, 16384, 4, 64, 8, 8, 4, 256, 512, 32, 1, 1, 32, 1, 1, 4, 1, {true, true, true, true, true, true, true, true, true}}; +const std::string shaderString = (R"( + #version 450 + + layout (local_size_x = 1) in; + + // The input tensors bind index is relative to index in parameter passed + layout(set = 0, binding = 0) buffer bina { float tina[]; }; + layout(set = 0, binding = 1) buffer binb { float tinb[]; }; + layout(set = 0, binding = 2) buffer bout { float tout[]; }; + + void main() { + uint index = gl_GlobalInvocationID.x; + + int i = 1; + + while(i < 200) { + tout[index] += tina[index] * tinb[index]; + i++; + } + } +)"); + +void compileShaderWithGivenResources(const std::string shaderString, const TBuiltInResource resources) { + kp::Shader::compile_source(shaderString, std::string("main"), std::vector>({}), resources); +} + + TEST(TestShaderResources, TestNoMaxLight) { - - kp::Manager mgr; - - auto tensorInA = mgr.tensor({ 2., 2., 2. }); - auto tensorInB = mgr.tensor({ 1., 2., 3. }); - auto tensorOut = mgr.tensor({ 0., 0., 0. }); - - std::string shaderString = (R"( - #version 450 - - layout (local_size_x = 1) in; - - // The input tensors bind index is relative to index in parameter passed - layout(set = 0, binding = 0) buffer bina { float tina[]; }; - layout(set = 0, binding = 1) buffer binb { float tinb[]; }; - layout(set = 0, binding = 2) buffer bout { float tout[]; }; - - void main() { - uint index = gl_GlobalInvocationID.x; - - int i = 1; - - while(i < 200) { - tout[index] += tina[index] * tinb[index]; - i++; - } - } - )"); - - - mgr.evalOpDefault( - { tensorInA, tensorInB, tensorOut }, - kp::Shader::compile_source(shaderString, "main", std::vector>({}), noMaxLightResource)); - - mgr.evalOpDefault({ tensorInA, tensorInB, tensorOut }); - - SUCCEED(); + const TBuiltInResource noMaxLightResources = { /* .MaxLights = */ 0, 6, 32, 32, 64, 4096, 64, 32, 80, 32, 4096, 32, 128, 8, 16, 16, 15, -8, 7, 8, 65535, 65535, 65535, 1024, 1024, 64, 1024, 16, 8, 8, 1, 60, 64, 64, 128, 128, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 16, 256, 1024, 1024, 64, 128, 128, 16, 1024, 4096, 128, 128, 16, 1024, 120, 32, 64, 16, 0, 0, 0, 0, 8, 8, 1, 0, 0, 0, 0, 1, 1, 16384, 4, 64, 8, 8, 4, 256, 512, 32, 1, 1, 32, 1, 1, 4, 1, {true, true, true, true, true, true, true, true, true}}; + EXPECT_NO_THROW(compileShaderWithGivenResources(shaderString,noMaxLightResources)); } -const TBuiltInResource noWhileLoopResource = { 32, 6, 32, 32, 64, 4096, 64, 32, 80, 32, 4096, 32, 128, 8, 16, 16, 15, -8, 7, 8, 65535, 65535, 65535, 1024, 1024, 64, 1024, 16, 8, 8, 1, 60, 64, 64, 128, 128, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 16, 256, 1024, 1024, 64, 128, 128, 16, 1024, 4096, 128, 128, 16, 1024, 120, 32, 64, 16, 0, 0, 0, 0, 8, 8, 1, 0, 0, 0, 0, 1, 1, 16384, 4, 64, 8, 8, 4, 256, 512, 32, 1, 1, 32, 1, 1, 4, 1, {true, /* .whileLoops = */false, true, true, true, true, true, true, true}}; TEST(TestShaderResources, TestNoWhileLoop) { - - kp::Manager mgr; - - auto tensorInA = mgr.tensor({ 2., 2., 2. }); - auto tensorInB = mgr.tensor({ 1., 2., 3. }); - auto tensorOut = mgr.tensor({ 0., 0., 0. }); - - std::string shaderString = (R"( - #version 450 - - layout (local_size_x = 1) in; - - layout(set = 0, binding = 0) buffer bina { float tina[]; }; - layout(set = 0, binding = 1) buffer binb { float tinb[]; }; - layout(set = 0, binding = 2) buffer bout { float tout[]; }; - - void main() { - uint index = gl_GlobalInvocationID.x; - - int i = 1; - - while(i < 200) { - tout[index] += tina[index] * tinb[index]; - i++; - } - } - )"); - - - mgr.evalOpDefault( - { tensorInA, tensorInB, tensorOut }, - kp::Shader::compile_source(shaderString, "main", std::vector>({}), noWhileLoopResource)); - - mgr.evalOpDefault({ tensorInA, tensorInB, tensorOut }); - - FAIL(); + const TBuiltInResource noWhileLoopResources = { 32, 6, 32, 32, 64, 4096, 64, 32, 80, 32, 4096, 32, 128, 8, 16, 16, 15, -8, 7, 8, 65535, 65535, 65535, 1024, 1024, 64, 1024, 16, 8, 8, 1, 60, 64, 64, 128, 128, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 16, 256, 1024, 1024, 64, 128, 128, 16, 1024, 4096, 128, 128, 16, 1024, 120, 32, 64, 16, 0, 0, 0, 0, 8, 8, 1, 0, 0, 0, 0, 1, 1, 16384, 4, 64, 8, 8, 4, 256, 512, 32, 1, 1, 32, 1, 1, 4, 1, {true, /* .whileLoops = */false, true, true, true, true, true, true, true}}; + ASSERT_THROW(compileShaderWithGivenResources(shaderString, noWhileLoopResources), std::runtime_error); } From 9a3cbd97cb601060c7ae920ba53b3c7e8d45b41a Mon Sep 17 00:00:00 2001 From: aliPMPAINT <53617231+aliPMPAINT@users.noreply.github.com> Date: Sun, 28 Feb 2021 12:53:36 +0330 Subject: [PATCH 3/6] Made shaderString const static, added another subtest --- test/TestShaderResources.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/TestShaderResources.cpp b/test/TestShaderResources.cpp index 703237500..e1bf94685 100644 --- a/test/TestShaderResources.cpp +++ b/test/TestShaderResources.cpp @@ -2,7 +2,7 @@ #include "kompute/Kompute.hpp" -const std::string shaderString = (R"( +static const std::string shaderString = (R"( #version 450 layout (local_size_x = 1) in; @@ -37,6 +37,12 @@ TEST(TestShaderResources, TestNoMaxLight) } +TEST(TestShaderResources, TestSmallComputeWorkGroupSizeX) +{ + const TBuiltInResource smallComputeWorkGroupSizeXResources = { 32, 6, 32, 32, 64, 4096, 64, 32, 80, 32, 4096, 32, 128, 8, 16, 16, 15, -8, 7, 8, 65535, 65535, 65535, /* .MaxComputeWorkGroupSizeX = */0, 1024, 64, 1024, 16, 8, 8, 1, 60, 64, 64, 128, 128, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 16, 256, 1024, 1024, 64, 128, 128, 16, 1024, 4096, 128, 128, 16, 1024, 120, 32, 64, 16, 0, 0, 0, 0, 8, 8, 1, 0, 0, 0, 0, 1, 1, 16384, 4, 64, 8, 8, 4, 256, 512, 32, 1, 1, 32, 1, 1, 4, 1, {true, true, true, true, true, true, true, true, true}}; + ASSERT_THROW(compileShaderWithGivenResources(shaderString, smallComputeWorkGroupSizeXResources), std::runtime_error); +} + TEST(TestShaderResources, TestNoWhileLoop) { From 2e923380f1f79e3036a1b6c5c0fcba8e00d20f34 Mon Sep 17 00:00:00 2001 From: aliPMPAINT <53617231+aliPMPAINT@users.noreply.github.com> Date: Sun, 28 Feb 2021 13:58:32 +0330 Subject: [PATCH 4/6] Changed the way Resources are created --- test/TestShaderResources.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/TestShaderResources.cpp b/test/TestShaderResources.cpp index e1bf94685..f89dd053f 100644 --- a/test/TestShaderResources.cpp +++ b/test/TestShaderResources.cpp @@ -32,20 +32,26 @@ void compileShaderWithGivenResources(const std::string shaderString, const TBuil TEST(TestShaderResources, TestNoMaxLight) { - const TBuiltInResource noMaxLightResources = { /* .MaxLights = */ 0, 6, 32, 32, 64, 4096, 64, 32, 80, 32, 4096, 32, 128, 8, 16, 16, 15, -8, 7, 8, 65535, 65535, 65535, 1024, 1024, 64, 1024, 16, 8, 8, 1, 60, 64, 64, 128, 128, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 16, 256, 1024, 1024, 64, 128, 128, 16, 1024, 4096, 128, 128, 16, 1024, 120, 32, 64, 16, 0, 0, 0, 0, 8, 8, 1, 0, 0, 0, 0, 1, 1, 16384, 4, 64, 8, 8, 4, 256, 512, 32, 1, 1, 32, 1, 1, 4, 1, {true, true, true, true, true, true, true, true, true}}; - EXPECT_NO_THROW(compileShaderWithGivenResources(shaderString,noMaxLightResources)); + TBuiltInResource noMaxLightResources = kp::defaultResource; + noMaxLightResources.maxLights=0; + + EXPECT_NO_THROW(compileShaderWithGivenResources(shaderString, noMaxLightResources)); } TEST(TestShaderResources, TestSmallComputeWorkGroupSizeX) { - const TBuiltInResource smallComputeWorkGroupSizeXResources = { 32, 6, 32, 32, 64, 4096, 64, 32, 80, 32, 4096, 32, 128, 8, 16, 16, 15, -8, 7, 8, 65535, 65535, 65535, /* .MaxComputeWorkGroupSizeX = */0, 1024, 64, 1024, 16, 8, 8, 1, 60, 64, 64, 128, 128, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 16, 256, 1024, 1024, 64, 128, 128, 16, 1024, 4096, 128, 128, 16, 1024, 120, 32, 64, 16, 0, 0, 0, 0, 8, 8, 1, 0, 0, 0, 0, 1, 1, 16384, 4, 64, 8, 8, 4, 256, 512, 32, 1, 1, 32, 1, 1, 4, 1, {true, true, true, true, true, true, true, true, true}}; + TBuiltInResource smallComputeWorkGroupSizeXResources = kp::defaultResource; + noMaxLightResources.maxComputeWorkGroupSizeX=0; + ASSERT_THROW(compileShaderWithGivenResources(shaderString, smallComputeWorkGroupSizeXResources), std::runtime_error); } TEST(TestShaderResources, TestNoWhileLoop) { - const TBuiltInResource noWhileLoopResources = { 32, 6, 32, 32, 64, 4096, 64, 32, 80, 32, 4096, 32, 128, 8, 16, 16, 15, -8, 7, 8, 65535, 65535, 65535, 1024, 1024, 64, 1024, 16, 8, 8, 1, 60, 64, 64, 128, 128, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 16, 256, 1024, 1024, 64, 128, 128, 16, 1024, 4096, 128, 128, 16, 1024, 120, 32, 64, 16, 0, 0, 0, 0, 8, 8, 1, 0, 0, 0, 0, 1, 1, 16384, 4, 64, 8, 8, 4, 256, 512, 32, 1, 1, 32, 1, 1, 4, 1, {true, /* .whileLoops = */false, true, true, true, true, true, true, true}}; + TBuiltInResource noWhileLoopResources = kp::defaultResource; + noWhileLoopResources.limits.whileLoops=0; + ASSERT_THROW(compileShaderWithGivenResources(shaderString, noWhileLoopResources), std::runtime_error); } From 042fd163f1b3b56be178bb3084bb50ba1ff834dd Mon Sep 17 00:00:00 2001 From: aliPMPAINT <53617231+aliPMPAINT@users.noreply.github.com> Date: Sun, 28 Feb 2021 14:27:50 +0330 Subject: [PATCH 5/6] Fixes --- test/TestShaderResources.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/TestShaderResources.cpp b/test/TestShaderResources.cpp index f89dd053f..16ebc7ac9 100644 --- a/test/TestShaderResources.cpp +++ b/test/TestShaderResources.cpp @@ -42,7 +42,7 @@ TEST(TestShaderResources, TestNoMaxLight) TEST(TestShaderResources, TestSmallComputeWorkGroupSizeX) { TBuiltInResource smallComputeWorkGroupSizeXResources = kp::defaultResource; - noMaxLightResources.maxComputeWorkGroupSizeX=0; + smallComputeWorkGroupSizeXResources.maxComputeWorkGroupSizeX=0; ASSERT_THROW(compileShaderWithGivenResources(shaderString, smallComputeWorkGroupSizeXResources), std::runtime_error); } From d08c56b3443e3ea57d9f78c25082b6d3a848b113 Mon Sep 17 00:00:00 2001 From: aliPMPAINT <53617231+aliPMPAINT@users.noreply.github.com> Date: Sun, 28 Feb 2021 14:33:24 +0330 Subject: [PATCH 6/6] More accurate name for the last subset(TestNoWhileLoopLimit) --- test/TestShaderResources.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/TestShaderResources.cpp b/test/TestShaderResources.cpp index 16ebc7ac9..f3436f228 100644 --- a/test/TestShaderResources.cpp +++ b/test/TestShaderResources.cpp @@ -48,10 +48,10 @@ TEST(TestShaderResources, TestSmallComputeWorkGroupSizeX) } -TEST(TestShaderResources, TestNoWhileLoop) +TEST(TestShaderResources, TestNoWhileLoopLimit) { - TBuiltInResource noWhileLoopResources = kp::defaultResource; - noWhileLoopResources.limits.whileLoops=0; + TBuiltInResource noWhileLoopLimitResources = kp::defaultResource; + noWhileLoopLimitResources.limits.whileLoops=0; - ASSERT_THROW(compileShaderWithGivenResources(shaderString, noWhileLoopResources), std::runtime_error); + ASSERT_THROW(compileShaderWithGivenResources(shaderString, noWhileLoopLimitResources), std::runtime_error); }