Metaprogramming GPUs with Sh

991060

Regular
Sh is a high-level shading language whose “parserâ€￾ is implemented as a
C++ library. Sh programs run on the GPU but act like extensions of the
host application. Sh can be used for single shaders, to implement
complex multipass algorithms, or for general-purpose computation on
GPUs.

The language is developed by university of waterloo, it's based on C++, supports many O-O programming features. For more information, see: http://libsh.sourceforge.net/
 
From the documentation, this appears to be more a clone of HLSL/GLSlang/Cg with different syntax and some extra features, and not a "run C code on GPU" Brook style tool.
 
How Sh differs from other tools

Actually, Sh is different from both Brook and the OpenGL SL. It's not really a language; it's a C++ GPU programming API that LOOKS like a shading language (or rather, than can be used as a shading language), but is a lot more flexible.

First, Sh is capable of defining *both* shaders and stream kernels. Like Brook, you can use it for general-purpose stream processing. Brook compiles down to a C++ host application providing overall control and a set of Cg kernels. Sh is EMBEDDED in C++, which provides the overall control, and provides a mechanism for dynamically defining kernels (we use our own internal intermediate representation and optimizer, and can compile to a number of different targets... including dynamically generated host CPU code!). Also, like Brook but unlike the OpenGL shading language, Sh manages textures and streams as well as shaders. Unlike Brook, you can actually use Sh for graphics (Brook is specifically designed for scientific computation, not the specification of shaders or rendering effects).

The way that Sh defines shaders is designed to mimic functions in C++, except that they can be dynamically constructed. In fact, Sh provides a number of mechanisms to create shaders out of parts using explicit manipulation by C++, providing the ability to metaprogram shaders, i.e. use a C++ program to build them (for example, from data). Some of these mechanisms are explained in our 2004 SIGGRAPH paper. Also, Sh binds parameters and textures to shaders using the scope rules of C++. This means that all the data abstraction capabilities of C++ can be used to structure Sh shaders, stream kernels, and components. For instance, you can store data in a texture, wrap it in a class, and provide access functions that can be used inside a shader. This can be used, for example, to implement your own compressed texture data types or alternative texture representations. Generally, Sh is designed to integrate in C++ in such a way that leverages its capabilities, rather than duplicating them.
 
Back
Top