Case Study: Custom Shading Language Precompiler

Activity Summary

A leading producer of 3D rendering and special effects software needed to add a specialized scripting language to their product family. The language would be used to provide end-user programmable properties when rendering surfaces, vertexes and other 3D models of complex 3D elements. Delera developed a C-like language and a custom 'precompiler' that used dynamic code snippets and produced fully compiled binaries for the appropriate platform.

Problem

Our client, a key player in the 3D graphics rendering and special effects space, was looking to provide its end users - highly technical individuals with limited programming skills - with the ability to write their own routines to be used during preprocessing and pipeline rendering of complex 3D graphics.

Many of these end users were already familiar with a legacy C-like language used in expensive Unix-based proprietary graphics workstations of the near past. It was imperative that they be able to transfer this knowledge to our client's systems, running in a multiplatform environment on modern PC hardware. On the other hand, replicating the language design exactly would not be a good option; the legacy subroutine processors were using some outdated conceptual approaches to data handling and computation workflow.

The task was complicated further by extremely high performance requirements. A shading routine can easily be called many millions of times during rendering of a single frame, every time with different input parameters. Interpreted language was not an option, p-code compilation was also judged as too slow. User routines would need to be compiled to native binary code.

Solution

After investigating various approaches, Delera Systems offered the client a win-win scenario: we would build a complete language parser that would process user-provided source code, building an execution tree (similar to CODEDOM in the Microsoft .NET environment). This tree would then be used to dynamically generate highly optimized and inlined C++ source code. C++ would be 'fed' to a native C++ optimizing compiler on the end-user platform, such as g++. The final output would be a dynamic library (.dll or .so) callable by our client's software.

The entire parsing / code generation process would be completely transparent to end users. Syntax and structural errors in the original script would be caught and reported by Delera's custom-built parser and grammar. If the script was processed OK, the C++ compiler would be invoked internally without users having to understand (or mess around with) makefiles, linkers and libraries.

The end result was a script preprocessor that delivered unmatched rendering performance on end-users PCs - a major selling point for our client's software, as operational speed is of the utmost importance in the 3D market.

The whole project took less than 4 months from starting the specification phase to delivery of a well-tested beta version ready to be integrated in our client's solution.

Service Offerings

The following Delera Systems service offerings were applied to this project:

  • Specification Design: Delera senior consultants were responsible for interviewing the client extensively, researching available documentation on the legacy language used as basis, and delivering a complete solution specification
  • Software Outsourcing: The system was architected and coded entirely by Delera staff

Technologies

  • C++ (Microsoft Visual C++ 2003)
  • Flex and Bison - driven parsing and grammar engine
  • Interface to externally callable C++ compiler (g++ used in this first implementation)

 
Copyright (C) 2005-2007 Delera Systems. I Contact I