Cloak
Cloak copied to clipboard
Applicability to other C-like languages?
I was wondering if anyone has investigated if some or all of these work on other C-based languages that include support for a similar preprocessor. (I would like to use something like this for explicit loop-unrolling given that the compilers for these languages lack much of the optimization capabilities of modern C compilers.)
I’m thinking specifically of:
- Sony’s Open Shading Language(OSL)
- The Khronos Group’s GLSL (part of OpenGL)
These are basically very simplified subsets of C/C++ for writing GPU shaders.
If those languages require a compliant C99 preprocessor then that will work, I believe opencl does specify a C99 preprocessor, but that doesn't mean an implementation maybe fully compliant. If the languages are llvm-based its very likely so.
I believe earlier versions of GLSL did not include the ##
token pasting operator, but i’ve read that current versions do. I’m unsure if GLSL specifies a C99 compliant preprocessor specifically, as I have yet to review the GLSL spec, but the OSL spec simply states:
Open Shading Language compilers support the full complement of C/C++ preprocessing directives, including:
#define #undef #if #ifdef #ifndef #elif #else #endif #include #pragma once
which sounds somewhat ambiguous to me.
Updated:
I have already asked the OSL maintainers about the #
and ##
operators, and they confirmed that they are supported.
Yea, you can try to run the test.h
header and see if it produces the correct output.
I will need to investigate if I can capture the Preprocessor output.
Also note: Be aware that most shader languages are currently expected to be compiled primarily at runtime rather than build time until intermediate cross-GPU shader formats like SPIR-V become widely utilized.