From 0dc856c47fbd14c9a644ab830c081e21b1b327d3 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Tue, 18 Jan 2022 18:36:49 +0000 Subject: [PATCH 1/4] Updating array_mutiplication example to work correctly Signed-off-by: Alejandro Saucedo --- examples/array_multiplication/src/Main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/array_multiplication/src/Main.cpp b/examples/array_multiplication/src/Main.cpp index a97fdbf24..1b02f316b 100755 --- a/examples/array_multiplication/src/Main.cpp +++ b/examples/array_multiplication/src/Main.cpp @@ -51,7 +51,7 @@ int main() std::vector> params = { tensorInA, tensorInB, tensorOut }; - std::shared_ptr algo = mgr.algorithm(params, kp_test_utils::compileSource(shader)); + std::shared_ptr algo = mgr.algorithm(params, compileSource(shader)); mgr.sequence() ->record(params) From d932b2f8ea7199f20547296909496f46fd96548b Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Tue, 18 Jan 2022 19:50:26 +0000 Subject: [PATCH 2/4] Updated example with correct function Signed-off-by: Alejandro Saucedo --- examples/array_multiplication/src/Main.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/array_multiplication/src/Main.cpp b/examples/array_multiplication/src/Main.cpp index 1b02f316b..be1be9d5d 100755 --- a/examples/array_multiplication/src/Main.cpp +++ b/examples/array_multiplication/src/Main.cpp @@ -5,11 +5,15 @@ #include "kompute/Kompute.hpp" -static std::vector +static +std::vector compileSource( const std::string& source) { - if (system(std::string("glslangValidator --stdin -S comp -V -o tmp_kp_shader.comp.spv << END\n" + source + "\nEND").c_str())) + std::ofstream fileOut("tmp_kp_shader.comp"); + fileOut << source; + fileOut.close(); + if (system(std::string("glslangValidator -V tmp_kp_shader.comp -o tmp_kp_shader.comp.spv").c_str())) throw std::runtime_error("Error running glslangValidator command"); std::ifstream fileStream("tmp_kp_shader.comp.spv", std::ios::binary); std::vector buffer; From ea983cb64d05bad31558c2ecd975bcfb32298c21 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Tue, 18 Jan 2022 19:59:09 +0000 Subject: [PATCH 3/4] Updated compilesource in godot examples Signed-off-by: Alejandro Saucedo --- .../kompute_summator/KomputeSummatorNode.cpp | 9 +++++++-- .../gdnative_shared/src/KomputeSummator.cpp | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/examples/godot_examples/custom_module/kompute_summator/KomputeSummatorNode.cpp b/examples/godot_examples/custom_module/kompute_summator/KomputeSummatorNode.cpp index e02a08d86..f937e7668 100644 --- a/examples/godot_examples/custom_module/kompute_summator/KomputeSummatorNode.cpp +++ b/examples/godot_examples/custom_module/kompute_summator/KomputeSummatorNode.cpp @@ -4,11 +4,15 @@ #include "KomputeSummatorNode.h" -static std::vector +static +std::vector compileSource( const std::string& source) { - if (system(std::string("glslangValidator --stdin -S comp -V -o tmp_kp_shader.comp.spv << END\n" + source + "\nEND").c_str())) + std::ofstream fileOut("tmp_kp_shader.comp"); + fileOut << source; + fileOut.close(); + if (system(std::string("glslangValidator -V tmp_kp_shader.comp -o tmp_kp_shader.comp.spv").c_str())) throw std::runtime_error("Error running glslangValidator command"); std::ifstream fileStream("tmp_kp_shader.comp.spv", std::ios::binary); std::vector buffer; @@ -16,6 +20,7 @@ compileSource( return {(uint32_t*)buffer.data(), (uint32_t*)(buffer.data() + buffer.size())}; } + KomputeSummatorNode::KomputeSummatorNode() { this->_init(); } diff --git a/examples/godot_examples/gdnative_shared/src/KomputeSummator.cpp b/examples/godot_examples/gdnative_shared/src/KomputeSummator.cpp index ab4067697..ac3398cb7 100644 --- a/examples/godot_examples/gdnative_shared/src/KomputeSummator.cpp +++ b/examples/godot_examples/gdnative_shared/src/KomputeSummator.cpp @@ -5,11 +5,15 @@ #include "KomputeSummator.hpp" -static std::vector +static +std::vector compileSource( const std::string& source) { - if (system(std::string("glslangValidator --stdin -S comp -V -o tmp_kp_shader.comp.spv << END\n" + source + "\nEND").c_str())) + std::ofstream fileOut("tmp_kp_shader.comp"); + fileOut << source; + fileOut.close(); + if (system(std::string("glslangValidator -V tmp_kp_shader.comp -o tmp_kp_shader.comp.spv").c_str())) throw std::runtime_error("Error running glslangValidator command"); std::ifstream fileStream("tmp_kp_shader.comp.spv", std::ios::binary); std::vector buffer; @@ -17,6 +21,7 @@ compileSource( return {(uint32_t*)buffer.data(), (uint32_t*)(buffer.data() + buffer.size())}; } + namespace godot { KomputeSummator::KomputeSummator() { From 87121c459f3cb32a2592f832830080ea71a84f5c Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Tue, 18 Jan 2022 19:59:20 +0000 Subject: [PATCH 4/4] Updated compileSource example in docs Signed-off-by: Alejandro Saucedo --- docs/overview/shaders-to-headers.rst | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/overview/shaders-to-headers.rst b/docs/overview/shaders-to-headers.rst index ab41d4683..77d46ddc4 100644 --- a/docs/overview/shaders-to-headers.rst +++ b/docs/overview/shaders-to-headers.rst @@ -13,11 +13,15 @@ For users that are looking to quickly test the processors it is possible to use .. code-block:: cpp :linenos: - static std::vector + static + std::vector compileSource( const std::string& source) { - if (system(std::string("glslangValidator --stdin -S comp -V -o tmp_kp_shader.comp.spv << END\n" + source + "\nEND").c_str())) + std::ofstream fileOut("tmp_kp_shader.comp"); + fileOut << source; + fileOut.close(); + if (system(std::string("glslangValidator -V tmp_kp_shader.comp -o tmp_kp_shader.comp.spv").c_str())) throw std::runtime_error("Error running glslangValidator command"); std::ifstream fileStream("tmp_kp_shader.comp.spv", std::ios::binary); std::vector buffer; @@ -25,6 +29,7 @@ For users that are looking to quickly test the processors it is possible to use return {(uint32_t*)buffer.data(), (uint32_t*)(buffer.data() + buffer.size())}; } + Converting Shaders into C / C++ Header Files ----------------------------------