Cloak icon indicating copy to clipboard operation
Cloak copied to clipboard

Applicability to other C-like languages?

Open loren-osborn opened this issue 5 years ago • 4 comments

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:

These are basically very simplified subsets of C/C++ for writing GPU shaders.

loren-osborn avatar May 14 '19 22:05 loren-osborn

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.

pfultz2 avatar May 15 '19 15:05 pfultz2

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.

loren-osborn avatar May 15 '19 16:05 loren-osborn

Yea, you can try to run the test.h header and see if it produces the correct output.

pfultz2 avatar May 15 '19 16:05 pfultz2

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.

loren-osborn avatar May 15 '19 16:05 loren-osborn