Added inline compilation of shaders again.
Signed-off-by: Fabian Sauter <sauter.fabian@mailbox.org>
This commit is contained in:
parent
c85dd89200
commit
c7db29a6e5
1 changed files with 26 additions and 0 deletions
|
|
@ -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<uint32_t>
|
||||
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<char> buffer;
|
||||
buffer.insert(buffer.begin(), std::istreambuf_iterator<char>(fileStream), {});
|
||||
return {(uint32_t*)buffer.data(), (uint32_t*)(buffer.data() + buffer.size())};
|
||||
}
|
||||
|
||||
Converting Shaders into C / C++ Header Files
|
||||
--------------------------------------------
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue