Defining shader programs by hardware platform

REDsdk uses another important concept through the RED::HARDWARE_PLATFORM enumeration. Given the fact that shaders are using programs for the description of their renderings, we face the problem that because all graphic cards don't support the same set of instructions, it may be wishful to write programs dedicated to a given hardware class and not to another one. For example, G80 and G200 chipsets support advanced shaders in which dynamic loops and conditional branching code can be executed. Dynamic branching shaders can't run on NV30 class hardware.

Therefore, REDsdk offers a way to register a shader and its parameters for a given hardware platform. Then, at run-time, the engine uses a hierarchical rule to select the right shader programs and parameters based on the underlying hardware category. The hardware we discuss of include a software version of the shader that can be defined for pure CPU rendering of an image using REDsdk's software ray-tracer. The RED::IResourceManager::GetPlatform and RED::IResourceManager::SetPlatform calls are used to manipulate the hardware platform. There's no need to force the hardware platform, unless RED::HW_USER_GENERIC platforms are targeted.

A hardware platform is either a chipset class hardware or an user platform identifier, for specific application customization. The schema below illustrates the inheritance rules used by the engine at the time it looks for shaders for the rendering:

Hardware / software platform inheritance rule for shader selection at runtime

If REDsdk runs an application on a RED::HW_ATI_R300 class hardware, then if a shader contains a description for the RED::HW_ATI_R400 or above, it'll be ignored. If that shader contains a RED::HW_ATI_R300 description, then this description will be selected. If there's no R300 shader description, then the engine will look for a RED::HW_ATI_GENERIC description, and if it's not successful in this research, it'll look for the RED::HW_GENERIC shader. The engine automatically detects the hardware class it uses at the application startup.

The RED::HW_USER_01 to RED::HW_USER_03 platforms can only be assigned manually through the RED::IResourceManager::SetPlatform call. These platforms can be used to store alternative shader configurations whose usage is selected by the application based on the criteria it chooses (for example the shading quality level wished in a game, independently of the hardware). Both the RED::RenderShader and the RED::StateShader classes are using the hardware platform identifier.

The RED::HW_SOFT_TRACER runtime configuration is used for all shaders that can be rendered fully on the CPU. This configuration must be defined for the software processing of an image. All built-in REDsdk shaders have a software rendering based implementation.