From c7db29a6e5d12af204c3644c68c6c5891df16dda Mon Sep 17 00:00:00 2001 From: Fabian Sauter Date: Tue, 12 Jul 2022 13:05:34 +0200 Subject: [PATCH] Added inline compilation of shaders again. Signed-off-by: Fabian Sauter --- docs/overview/shaders-to-headers.rst | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/docs/overview/shaders-to-headers.rst b/docs/overview/shaders-to-headers.rst index 8f5517bc8..9b8419a13 100644 --- a/docs/overview/shaders-to-headers.rst +++ b/docs/overview/shaders-to-headers.rst @@ -3,6 +3,32 @@ Processing Shaders with Kompute =============================== +Demo / testing function to compile shaders +------------------------------------------ + +GLSLANG was initially integrated as part of the framework but it now has been removed due to the license of the glslang pre-processor being under a custom NVIDIA license which explicitly excludes grant of any licenses to NVIDIA's patents in the preprocessor. This is covered in more detail here: https://github.com/KomputeProject/kompute/pull/235 + +For users that are looking to quickly test the processors it is possible to use the function that is provided in the examples which provides a (non-thread-safe / non-robust) implementation that compiles a shader string into spirv bytes. It is not recommended to use in production but it does enable for faster iteration cycles during development. + +.. code-block:: cpp + :linenos: + + static + std::vector + compileSource( + const std::string& source) + { + 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; + buffer.insert(buffer.begin(), std::istreambuf_iterator(fileStream), {}); + return {(uint32_t*)buffer.data(), (uint32_t*)(buffer.data() + buffer.size())}; + } + Converting Shaders into C / C++ Header Files --------------------------------------------