Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
Graphics Programming Software Books Media Book Reviews IT Technology

Metaprogramming GPUs with Sh 139

Martin Ecker writes "With the advent of powerful, programmable GPUs in consumer graphics hardware, an increasing number of shading languages to program these GPUs has become available. One quite interesting language that - in many ways - has a very different approach than other mainstream shading languages (such as Cg or the OpenGL Shading Language) is Sh. The recently released book "Metaprogramming GPUs with Sh" by Michael McCool and Stefanus Du Toit, both major contributors to the Sh project, explains the basics of the Sh high-level shading language and the corresponding API and also goes into some of the details of the implementation. The book is intended for an audience that is already familiar with traditional shader development for programmable GPUs. Also, a firm background in 3D graphics programming and C++ is a must for the interested reader." Read on for the rest.
Metaprogramming GPUs with Sh
author Michael McCool, Stefanus Du Toit
pages 308
publisher A K Peters
rating 7/10
reviewer Martin Ecker
ISBN 0321197895
summary A book that describes an interesting shading language and accompanying API to program GPUs.


Before discussing the book in more detail, I will try to give a basic overview of Sh, since most readers will not be familiar with it. For a more in-depth look at Sh, I recommend taking a look at a recently posted Gamasutra article by Michael McCool (http://www.gamasutra.com/features/20040716/mccool _01.shtml), the paper on Sh from the authors presented at the recently held SIGGRAPH 2004 conference (http://www.cgl.uwaterloo.ca/Projects/rendering/Pa pers/#algebra), and of course the Sh homepage at http://www.libsh.org.

Sh started out as a research project at the University of Waterloo (http://www.cgl.uwaterloo.ca), and it is both a shading language and a runtime API to use the Sh shaders. As a shading language Sh is embedded into C++ as a domain-specific language, which is made possible by using C++ operator overloading and by defining special tuple and matrix types that are used extensively in shader code. So instead of defining its own language that requires a full compiler, like other shading languages do, Sh uses regular C++ syntax to describe shader code, which is then dynamically (at runtime) compiled to a specific backend, such as a GPU or possibly even the CPU. In addition to compiling to a specific GPU or CPU target, Sh can also be used in a special stream mode where a shader is applied to a stream of input tuples. This is very useful for general purpose GPU programming where the GPU is basically used as an additional processor to the host CPU (see http://www.gpgpu.org for more information on the subject). Finally, Sh code can also be executed in an immediate mode where every Sh statement is directly executed on the host CPU (without being compiled into a shader program), which makes it very easy to debug shaders with any host debugger running on the CPU.

Due to the way Sh is embedded into C++, the full range of abstraction mechanisms offered by C++ can be used to structure and modularize shader code. Abstract base classes, regular functions, templates, and any other features offered by C++ can be used to develop shaders. This is an interesting consequence of the metaprogramming approach of Sh that also allows the use of software engineering principles in shader development, such as object orientation, that other shading languages currently cannot offer.
This kind of metaprogramming in C++ is used by an increasing number of libraries. For example, the Spirit parser framework (see http://spirit.sourceforge.net) uses a similar approach to describe and generate parsers directly in C++ instead of using traditional external tools, such as yacc or bison.

One of the most fascinating features of the Sh toolkit is the possibility to combine and connect shader programs to form new shader programs, which allows one to easily build complex shaders out of simple shader fragments. In a more general sense, Sh provides what can be called a shader algebra (see also the aforementioned SIGGRAPH 2004 paper), where shader programs are the objects on which special operators to combine and connect them are defined. An interesting application of this shader algebra is to specifically bind certain varying shader inputs to uniform variables and the other way around (this is what functional programming languages usually call currying). Also combining a matrix palette skinning shader with any light model shader (or any shaders that perform specific tasks, for that matter) is easily possible.

After this short introduction to the Sh toolkit, we shall now take a closer look at the book "Metaprogramming GPUs with Sh".
The book is split into three parts, an introduction, a reference, and an engineering overview.

The introduction consists of the first five chapters and discusses the basics of the Sh shading language and the API. In particular, the tuple and matrix types and the operators defined on them are presented. The way shader programs are defined and how parameters and attributes are handled is discussed, followed by the way textures are represented. Finally, the stream and channel concept used to feed data into shader programs is discussed. These introductory chapters contain a number of examples that demonstrate the presented concepts. Chapter three contains a quite interesting sample shader that uses constructive solid geometry techniques and metaprogramming in Sh to render text. While not the most useful use case, the shader shows some interesting capabilities of Sh, in particular the shader algebra operators. Chapter four on textures has some more nice sample shaders for doing shiny bump mapping, rendering wood and marble, and using Worley noise.

The second part of the book is a reference on Sh. Unlike references in many other computer books, this is not just a technical listing of the available features of Sh but is written in regular prose (with the occasional reference-like table here and there). The six chapters of the reference section describe how to setup and use the Sh library, and then discuss the available types, operators, and standard library functions more thoroughly than in the introduction. Additionally, the available backends are mentioned in the last chapter of this part of the book. A draft of the reference manual can also be found online at http://www.libsh.org/ref/online.

The final part of the book deals with engineering aspects of Sh. These final five chapters of the book discuss the details of the current implementation. The intermediate representation for shaders that is used by Sh is presented as well as how streams and textures are managed and stored internally. The interface between the Sh frontend and the various specific backends is discussed, as well as the current state of the optimizer including some further improvements that are planned in the future.

The images in the book are all in black and white except for 14 color plates in the middle of the book. The color plates and other images usually show teapots or animals, so they aren't all that exciting, but do demonstrate what the sample shaders presented in the book look like.

The book does not come with a CD-ROM, but with such a young library that is still under heavy development, putting a snapshot of the library's source code base on a CD-ROM would be a waste of resources. Sh itself as well as all sample shaders presented in the book can be downloaded from the Sh homepage at http://www.libsh.org. This website also has additional documentation, including some papers and the API reference documentation generated with Doxygen from the sources. Sh is distributed under a very liberal open source license (based on the zlib/libpng license) that also allows commercial use.

For the reader with enough expertise in 3D and shader programming, this book provides a concise and well-written introduction to Sh. The book will definitely contribute to enlarging the currently relative small user base of Sh and hopefully help the library grow and get more refined in the near future. Everyone familiar with "regular" high-level shading languages, such as Cg or the OpenGL Shading Language, should take a look at this book to see a new and interesting way of programming GPUs that the aforementioned languages do not offer.

About the review author:
The author has been involved in real-time graphics programming for more than 9 years and works as a games developer for arcade games. In his rare spare time he works on a graphics-related open source project called XEngine http://xengine.sourceforge.net.


You can purchase Metaprogramming GPUs with Sh from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

This discussion has been archived. No new comments can be posted.

Metaprogramming GPUs with Sh

Comments Filter:
  • Wow (Score:4, Funny)

    by Anonymous Coward on Wednesday September 22, 2004 @02:31PM (#10321809)
    I thought I'd accidentally clicked on this article.
  • Is this the longest headline blurb ever?

  • by Carnildo ( 712617 )
    Is the book review template broken or something? This is the second review in as many days that's been misclassified.
  • by mnemonic_ ( 164550 ) <jamec.umich@edu> on Wednesday September 22, 2004 @02:31PM (#10321815) Homepage Journal
    Awesome story formatting. Looks great!
  • by illumin8 ( 148082 ) on Wednesday September 22, 2004 @02:32PM (#10321822) Journal
    Schweet!!! I always wanted to write my own CounterStrike-like 3D FPS as a shell script! Now my uber-leet shell hacking skills can make me rock-star dollars as a video game developer!
    • Comment removed based on user account deletion
  • it really has to be, I thought I had hit the wrong link when I got to the page! someone wake up Tacoman and see whatup on the whois!

    CB
  • /bin/sh (Score:5, Funny)

    by philfr ( 89798 ) on Wednesday September 22, 2004 @02:35PM (#10321857)
    At first read I thought they ported bash to the Radeon GPU...
    • #!/bin/sh

      for n in pixbuf/* ; do
      if [ $n -nt screen/${n##*/} ]; then
      cat $n > screen/${n##*/}
      else
      touch screen/${n##*/}
      fi
      done
    • Maybe if someone would do this, we could hack together a new driver in shell script that doesn't suck.
  • SDL-perl (Score:4, Insightful)

    by Speare ( 84249 ) on Wednesday September 22, 2004 @02:37PM (#10321881) Homepage Journal
    I've done some OpenGL work with SDL's Perl bindings, but the SDL-perl group has been quite fractured over the past several months. Forks, missing maintainers, etc. I finally got texture-mapping to work, but there are some persistent bugs with missing GL constants or missing APIs which have put my spare-time projects on the shelf for now.

    This is a shame, because perl's a nice quick way of working through the edit-try-edit-try-edit development process when working with OpenGL and 3D geometrical stuff in general.

    I don't want to learn Yet Another Scripting Language just to try out some OpenGL routines, and I don't want to slog through a ton of C code makefile junk either. Script languages are a great help there.

    • Try the Lua bindings [lua-users.org]. Lua is a much better language than PERL anyway.
  • Amazon linkage (Score:4, Informative)

    by bujoojoo ( 161227 ) on Wednesday September 22, 2004 @02:37PM (#10321885)
    Or, buy it from Amazon [amazon.com]
  • /bin/sh (Score:4, Funny)

    by rcamera ( 517595 ) on Wednesday September 22, 2004 @02:41PM (#10321934) Homepage
    i always do my low level device programming in sh. my graphics card has never been faster!

    sed | awk | sed | grep | awk | sed | awk
  • sh? (Score:2, Funny)

    What if I want to use korn or csh?
  • lol (Score:3, Insightful)

    by here4fun ( 813136 ) on Wednesday September 22, 2004 @02:44PM (#10321968) Homepage Journal
    Before discussing the book in more detail, I will try to give a basic overview of Sh, since most readers will not be familiar with it.

    lol, how many languages do we need? back in the day, knowing 2 or 3 languages very well (like c and some db language) would have been enough to land a job. add to that knowing another 2 or 3 languages well enough to feel comfortable doing small coding, and you have an excellent programmer. now it seems like there are so many languages, from python to cobol to fortran. there must easily be over 50. it is like if i wanted to work at the united nations and said i knew english and spanish and german, and they asked "well what about sanskrit and tagalog". how much is enough?

    • Everyone in the OSS community needs to have either their own linux distro (gentoo forks), their own desktop environment (gnome forks), or their own scripting language.

      In the real world, I would expect a professional programmer with a background in OO to be able to perform competently in any OO language with very little learning curve. The only thing that really changes from language to language is the syntax.

      Big paradigm shifts have been few (Sequential to functional to object oriented). There are of co
      • In the real world, I would expect a professional programmer with a background in OO to be able to perform competently in any OO language with very little learning curve. The only thing that really changes from language to language is the syntax.

        Have to disagree with you there. OO languages are different in implementation, shorcomings, and strengths depending on the language in question. Java can do things that are difficult in Ruby, and vice versa (functions as objects), and Smalltalk can do things that

        • I think that's the point, though. A competent programmer will look at another language with the confidence that he could pick it up and start working in it (maybe not 100%) "with very little learning curve." Sure, there are intricacies of every language - but those are the things that you pick up over time as you learn.

          In college, I watched entire classes go through the same intro topics (how hard is it to switch between C++ and Java when you're only talking about freakin' conditionals?!) for weeks... I th
      • I'll agree that there is little learning curve in being able to write a program that will compile and run in another language.. but being a competent programmer in that language requires much more.

        I guess it depends on how similar the languages are, but from personal experience:
        a good Java programmer != a good C++ programmer, and vice versa.
    • How many do we need? Two. Personally, I'd pick C++ and assembly, though I know quite a few people who'd pick Java and assembly. (And assembly's only so we can make OSes.)

      How many do we want? More.

      Imagine I want to do some quick parsing. Both C++ and Java suck at this. So I'll use Perl instead.

      Imagine I want to write code for a GPU. Sure, I could do it in bytecode. I could do it with some library for C++. Or I could write a custom language - say, Cg or Sh - that works well for that purpose.

      Imagine I want
      • How many do we need? Two. Personally, I'd pick C++ and assembly, though I know quite a few people who'd pick Java and assembly. (And assembly's only so we can make OSes.)

        This is exactly what I thought, except I never knew anyone who works doing assembly. It might be nice for some theory, but in practice it is never applied. I would think someone who is expert in assembly has a small niche market for themseleves and they probably make good money. My thinking is either C or C++ is a must (or maybe Java, it

        • VB is NOT an easy language. VB is a very, very hard language.

          It is a language that it is simple to get started with, sure, but it is, for a professional programmer, a language full of tedium and details that need to be remembered.

          EIvind.

      • How many do we want? More.

        First off, I totally agree with this, people always make the analogy that languages are like tools and each job should be implemented with the most appropriate tool. Who would argue against more tools in the workshop?

        But there's a huge missing link here: Languages are horribly inoperable. Even C to C++ requires some tomfoolery like

        #ifdef CPLUSPLUS
        extern "C" {
        #endif
        #include ...
        #ifdef CPLUSPLUS
        }
        #endif

        Is this a joke? The problem is that once you've used that nice band

        • Personally I use text files as the links. Yes, this means I end up doing things step-by-step, but for my work that's usually what I do anyway.

          You're right, with some exceptions, languages aren't very interoperable. Python is an exception, and the entire .net family is an exception - I've made some great tools combining C++ and C# with .net, and to be honest, I was very very impressed by the whole thing.

          COM and CORBA and so on and so forth do a reasonably good job of bridging most gaps, but unfortunately t
    • There are actually more than 1000 programming languages.. although many of those aren't in wide use! Different languages are suited for different tasks. Some things that are trivial in one programming language are exceedingly difficult in others.
    • Re:lol (Score:4, Insightful)

      by Lord Omlette ( 124579 ) on Wednesday September 22, 2004 @03:28PM (#10322481) Homepage
      "I've got a hammer, and I use it for everything!"

      Excellent plan.
    • Imagine how must fun it must be explaining to the human resource people that yes, you do have experience in sh and Sh, and yes, those are different.
  • by Angst Badger ( 8636 ) on Wednesday September 22, 2004 @02:45PM (#10321986)
    It may well be my utter ignorance of how GPUs work, but it would be nice, if possible, to have tools to utilize all of that computing power when I'm just displaying a simple GUI or text interface. I understand GPUs are heavily optimized for what they do, but I expect they're still good for general purpose tasks and might be really useful in some math-heavy applications.
    • As far as I know, one problem is the AGP interface, which gets data from main memory to the graphics card fast but not the other way. This will be fixed with PCI Express, so maybe when more computers have that we will also see some non-display applications of GPUs.

    • You can use it for some things, like anti-aliasing for text and such. That is pretty much what all 3d accelerated window managers are doing. (Though I'm not aware of one for Linux, upcoming Avalon in Windows Longhorn is an example, possibly something like it in OSX too.)

      Using GPU for searching in text and stuff like that is not useful though. The point with a GPU is that it is massively parallel and has very deep pipelines. As such it is perfect for doing the same computation on a large image but pretty us
      • Re:Not really. (Score:4, Interesting)

        by tiger99 ( 725715 ) on Wednesday September 22, 2004 @04:14PM (#10323077)
        Yes, and I don't see why you could not run an entire GUI in the GPU. Maybe not right now, but if the chip manufacturers wanted to make it possible it would not be too difficult. Just imagine, X running in the GPU, the CPU(s) free to get on with non-graphical tasks....

        It is one place that an OS architecture which makes a clean separation of GUI and kernel would win over the mess of sundry .dlls from the Criminal Monopoly. The other place would have been the ill-fated tablet computer, had it been correctly designed, with the X serevr on the portable bit.

        Because simple single-processor relatively high-performance silicon is now very affordable, the time is right to go back to parallelism, dedicated I/O and graphics processors, etc, to get even better performance.

        It would be nice to have a GPU compiler to run ordinary code, such as X, but the compiler would be different for each architecture, not like AMD vs Intel, where you can use the same compiler with just the optimisations tweaked. But my thinking is to replicate a full CPU in the GPU chip or at least on the graphics card. You could put a Pentium/Athlon there, feeding the gPU as usual, fed itself from the AGP bus or its successor via a big FIFO.

        But whatever way things go, I do think we are in for some big steps forward in graphics processing, at least. I am not into shaders and so on, I don't need fast 3-D or anything like that, but I know that many people do, and not just for games. But if it offloads things from my main CPU, I would find immediate benefit.

        • Just to pick up on a little bit from your comment:

          The other place would have been the ill-fated tablet computer, had it been correctly designed, with the X serevr on the portable bit.

          I thought about this a couple of months ago - how great it'd be to have a tablet PC that was literally just an X/VNC/RDC/Citrix server. With a GPU that most of the hard work could be dedicated to, and possibly something like a Transmeta/C3 etc type CPU for networking, device management etc - which wouldn't require much
        • I have to say that I'm not well versed in the specifics of how a normal window manager works. From what I've understood of Avalon the idea there is to put as much as possible in the OS, and let the OS delegate stuff to the GPU as it sees fit. So your app would write stuff to a buffer but the OS handles double buffering and all things like that.

          Putting all of X on a GPU would probably not be a good idea however. (For reasons to be mentioned later.) And while you can free up your CPU from the specifics of GU
        • You are suggesting that the CPU and GPU - which are very different beasts, as other posts mention - try to work as effectively a multi-processor system.

          The only problem with that is that when there is a lot of work, they are often both working full-out already. I agree it would be nice if GPUs could also do less specialized (i.e. completely different) parallel processes, but I am sure someone will be able to hack even the current generation to do say weather modelling if they really want to.

          Anyway, to dig
  • by Esterhaus_48 ( 634600 ) on Wednesday September 22, 2004 @02:47PM (#10322002) Homepage
    The GPGPU course [gpgpu.org] was at the top of my list for SIGGRAPH 2004 this year, and I was impressed with all of the presenters' material. However, in my estimation, Sh is built to more closely resemble the existing HLSL for DX and similar GLSLang from the ARB.

    Brook [stanford.edu], on the other hand, was written from a more C-like perspective, and approaches the GPU as a massively data-parallel stream processor (well, Sh does as well, but IMHO Brook achieves that aim more directly as is evidenced by things like iterator streams and similar kernels).
  • by adisakp ( 705706 ) on Wednesday September 22, 2004 @02:50PM (#10322037) Journal
    I'm a graphics and systems programmer at Midway Games.

    I think it will be a while before sh / GPU metaprogramming will be commonly used for "real" games programming. For example, their paper on Worley shaders claimed interactive rates of 14 FPS on a very simple single model for stone shading on the fastest video hardware (6800GT) currently available.

    The benefit of HLSL and Cg are that they achieve performance close to or better than the PS/VS-Asembler implementations and are orders of magnitude easier to program. This allows them to be used on hundreds of objects per frame at video game "interactive" framerates (which usually starts at 30 FPS, with 60 FPS as a gold standard, and 300 FPS or other crazy numbers as the Doom/Quake standard for some reason).

    Still it's good to see that there are languages evolving that will handle more complex shading algorithms and as the hardware becomes faster in 2 or 3 years from now, this may be practical for real-time use in video games.
    • by sdt ( 7606 ) on Wednesday September 22, 2004 @03:09PM (#10322222) Homepage

      (Disclaimer: I'm Stefanus Du Toit, one of the authors of this book and implementer of most of the Sh compiler/library)

      I think it will be a while before sh / GPU metaprogramming will be commonly used for "real" games programming. For example, their paper on Worley shaders claimed interactive rates of 14 FPS on a very simple single model for stone shading on the fastest video hardware (6800GT) currently available.

      I should point out that the Worley shaders are rather large shaders. It's not that they're written in Sh that makes them so huge, it's simply the way the algorithm works. The shaders would be approximately the same size if written in Cg (or HLSL, etc.).

      The benefit of HLSL and Cg are that they achieve performance close to or better than the PS/VS-Asembler implementations and are orders of magnitude easier to program.

      The same holds true for Sh. Both Sh and Cg target "assembly" interfaces such as RB_fragment_program. Sh provides a superset of Cg's functionality. Because in both the case of Sh and Cg the actual program is executed by the GPU, not in any way the system itself, the only difference in performance that might be caused between the two languages would be due to the optimizer. I've actually just rewritten the Sh optimizer, and the only major optimization left to do is common subexpression elimination, and some arithmetic simplifications.

      In fact, we already provide an optimization that no other shading language provides (this will be in the next release, and is working in the subversion repository) called uniform lifting. Sh will automatically discover computations which do not change from one fragment to the next, and move them to the host where they can be evaluated more efficiently. This is something that would be difficult to do in other shading languages.

      So, to summarize, there is nothing intrinsic about Sh that makes it any slower than Cg. In fact, we're thinking of adding a Cg backend, so that your Sh code can automatically be converted to equivalent Cg code. Then, if you really want, you can take advantage of the backends and optimizations provided by Cg while using the modularity facilities of Sh.

      • by adisakp ( 705706 ) on Wednesday September 22, 2004 @03:43PM (#10322661) Journal
        Well that's good to know Stefanus. If your performance claims are true, I guess I'll have to take a look at Sh then :-) Now that MK6 is just about wrapped up, the guys on my team are eager to get a chance to learn and explore new technology for upcoming games.

        And here's a question that's sure to anger the general Slashdot crowd -- however, the answer will be important in whether or not your language makes it into common usage in the game industry. How do you feel about the use of your technology in closed source proprietary products (like video games)?
        • by GooberToo ( 74388 ) on Wednesday September 22, 2004 @05:02PM (#10323704)
          Considering the license that he released his efforts under, I think it speaks clear and loud.

          The zlib/libpng License

          Copyright (c)

          This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

          Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

          1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.

          2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.

          3. This notice may not be removed or altered from any source distribution.
      • In fact, we already provide an optimization that no other shading language provides (this will be in the next release, and is working in the subversion repository) called uniform lifting. Sh will automatically discover computations which do not change from one fragment to the next, and move them to the host where they can be evaluated more efficiently. This is something that would be difficult to do in other shading languages.

        How is this different from the preshaders introduced in DirectX 9.0c? Not tha
        • It's similar to preshaders (we thought of the idea independently, and call it something different in the book... uniform lifting... but it is basically the same idea). So I guess it's a little unfair to say "an optimization that no other shading language provides". It also would be possible, in theory, for OpenGL SL implementations to provide this optimization.

          In Sh, though, this optimization is internal and automatic, and so invisible to the user. It's important to do it that way, because the shade

    • by spworley ( 121031 ) on Wednesday September 22, 2004 @03:37PM (#10322588)
      Yes, 14 fps seems slow, doesn't it? But what are you comparing the 14 fps to? The simple stone model they show isn't an image map, it's fully procedural and not just a texture lookup.

      I happen to know a bit about that specific procedural model, and on a modern CPU, I'd expect perhaps about 0.5s to render the same pixels.
      So that example is already an order of magnitude faster than CPU evaluations. And GPU speeds scale faster than CPU so this gulf will widen, quickly, with time.

      But the poster is correct, GPU metaprogramming is NOT going to be common in games quite yet. But it's going to happen, absolutely, and the time frame is measured in just a year or two, not some vague future date. sh is fascinating because it is a solid attempt to give developers tools to start using the GPU for different kinds of computations, not just polygons/pixels/shading.

      And the important applications are likely NOT to be games. Think 3D movie renderering, think fluid simulators, think finite element analysis, think fracture simulation.. all of those massively parallel, highly numeric applications. Graphics is just one of them.
      • Hey Steve, nice to see you on this thread. It's been about ten years since we last chatted about graphics back on the Amiga days :-)

        I agree with your time frame of a couple years. The stuff in the games industry has been moving crazy fast. Every time we hear about something at SIGGRAPH that can't be done "yet" in realtime, it seems to be about 2-3 years before the hardware is catching up and someone figures out a clever technique to do it.
      • I happen to know a bit about that specific procedural model

        BTW, that's a minor understatement considering it's named after you - LOL :)
        • Actually, the stone shader uses both Worley basis functions and several octaves of Perlin noise. It's the Perlin noise that slows it down. We have a stained glass shader that runs at 200fps that uses just the Worley basis functions and a few cube map lookups to do the glass. Perlin noise could be sped up *a lot* if there was a "hash" instruction on the GPU to generate position-dependent pseudorandom numbers. But there isn't, so we have to generate the hash by using texture lookups, or several instruc
    • which usually starts at 30 FPS, with 60 FPS as a gold standard, and 300 FPS or other crazy numbers as the Doom/Quake standard for some reason).
      - - -

      Phisics affected by framerate bugs:
      [netquake] you can jump higher and cross water faster with faster framerate
      [quakeworld] relation with mouse lag, or something similar, etc..

  • by thelenm ( 213782 ) <mthelen@gmai l . com> on Wednesday September 22, 2004 @02:52PM (#10322056) Homepage Journal
    I just installed this "sh" thing in /bin, and now all my shell scripts run with 3D shading! This rules!!
  • I was just thinking to myself, "You know what 00 these Bash scripts I wrote are clean, efficient, work well and are extremely portable across multiple platforms... but they lack pizazz." Nwo I have the perfect solution!

    too bad this joke doesn't even work because the blurb was basically the whole book article anywyas
  • /bin/sh (Score:3, Funny)

    by Tokerat ( 150341 ) on Wednesday September 22, 2004 @03:02PM (#10322163) Journal

    Look out for the second book, "Metaprogramming GPUs with bash", and a third and final "Metaprogramming GPUs with X11", comming soon to all fine book retailers.
  • "Also, a firm background in 3D graphics programming and C++ is a must for the interested reader."

    in other words, you must be a slashdot regular
  • by borwells ( 566148 ) on Wednesday September 22, 2004 @03:09PM (#10322226) Homepage
    I don't care what anyone says. With names like that the book has to be awesome.
    • I got modded troll for noting the authors funny names.

      UNFAIR!

      Du Toit's first name is Steph-ANUS!

      I've seen plenty of Stephans and Stephanies, but never a Steph-ANUS!

      I've heard of Staph-Anus, you get that from yo momma.
  • by dfiguero ( 324827 ) on Wednesday September 22, 2004 @03:09PM (#10322238)
    #!/bin/sh

    echo #
    echo ###
    echo ##### :] oh come on!!!
  • by worst_name_ever ( 633374 ) on Wednesday September 22, 2004 @03:27PM (#10322459)
    Sh! Even before you start, that was a preemptive Sh. Just know I have a whole bag of Sh with your name on it.
  • Wow. It really is amazing what you can use the good ol' bourne shell for!
  • From the review, it sounds like SH is basically a library, and that library invocations are dressed up through the use of operator overloading.

    Is this "metaprogramming"? Googling turns up a variety of definitions of the term, but the term sounds like it should mean writing a program which generates a program. Which is different from a library and syntactic sugar.
    • by sdt ( 7606 ) on Wednesday September 22, 2004 @04:00PM (#10322870) Homepage

      From the review, it sounds like SH is basically a library, and that library invocations are dressed up through the use of operator overloading. Is this "metaprogramming"?

      Yes, because rather than just executing the the operations you specify, Sh has a special "retained mode", which instead collects these operations, builds an intermediate representation of them, runs an optimizer and passes them on to a backend compiler. For example:

      void foo() {
      ShAttrib3f x, y, z; // three Sh variables
      x = y + z; // Executes immediately
      ShProgram prg = SH_BEGIN_PROGRAM() {
      ShAttrib3f i, j, k;
      i = j + k; // Doesn't execute, gets collected
      } SH_END;
      }

      So, the bits that are written inside the declaration of "prg" (the above is valid C++/Sh), are actually collected into prg, instead of being executed. prg can then be compiled to a GPU (or CPU) backend and sent to the GPU to run. Thus, your C++ program is used to write Sh programs at runtime. This allows all sorts of metaprogramming techniques.

      We also provide further levels of metaprogramming with the shader algebra operations, but that's at an even higher level. These let you take previously written Sh programs and combine them in various ways, at run time. See our SIGGRAPH paper for details.

      The About Page [libsh.org] on our homepage [libsh.org] tries to explain this in more detail.

      • by mdmccool ( 789798 )
        To emphasize this... Sh just "pretends" to look like a vector/matrix/colour library, since that is a familiar concept to graphics programmers. But it's this "retained mode" trick (also a common concept to graphics programmers) that lets you, basically, add dynamic definition of functions to C++. And those functions are really "remote procedure calls" that can run on another processor... like the GPU.

        Another thing to emphasize: yes, Sh does compile to the *CPU* as well as the GPU. So you can use it fo

      • Actually, there's one more trick Sh uses. If you declare a variable outside a SH_BEGIN_PROGRAM/SH_END block, then use that variable inside such a block, then that's how Sh sets up "uniform" parameters. For instance, suppose we have

        ShVector3f d;
        ShProgram p = SH_BEGIN_PROGRAM("gpu:stream") {
        ShInputVector3f a;
        ShOutputVector3f b;
        b = a + d;
        } SH_END;

        Now the program object p uses d as a constant over each data-parallel invocation of p to data. To support GPGPU, Sh supports a stream data abstraction so i



  • Is anyone working on a method of using the GPU on some of the faster video cards to offload processing power to from the cpu?

    Is it even feasible?
  • Unfortunately, the developers of Sh chose to publish the book which details features which are not yet supported in the library. Since the software is currently in the alpha stage of development and constantly changing, many of the examples described in their book do not work as expected (the minimal GLUT example doesn't even compile).

    In short, a lot of work remains before they meet their full project goals. The name, however, which is an abbreviation of Serious Hack [serioushack.com], seems quite appropriate.

    • by sdt ( 7606 ) on Wednesday September 22, 2004 @04:06PM (#10322954) Homepage

      Unfortunately, the developers of Sh chose to publish the book which details features which are not yet supported in the library.

      Yes, this is true. If we had written the book based entirely on what we had implemented at the time, it would however have become out of date completely very quickly. Instead we chose to write the book as a specification. Too many programming language books, and books describing systems become out of date as soon as they are published, so it's a tough decision to make.

      I should point out that we are getting closer to full support of everything in the book every day. Most of the missing features are very simple things like missing library functions. Sh works, right now, and can be used to write real shaders.

      With the next release I will post a fixed version of the glut example. As unfortunately happens so often, the example got broken during book writing stage...

      You're welcome to browse our Issue Tracker [libsh.org]. Progress has been slow of late because I've been working hard on the optimizer, and we've been busy with non-Sh-related things. However, note that most of the issues in the track are either "easy" or "bitesized", and once development gets on track again (in a week or so) I expect most of them to be resolved quite quickly.

      • In our defense... the OpenGL Shading Language is defined the same way. There are very few cards/drivers (that you can afford) that can currently implement *everything* in the OpenGL SL spec, or described in the OpenGL SL book, and current implementations are missing a few things here and there. There are things like true data-dependent control flow, derivatives, and arbitrary-length shaders, that are very hard to do correctly if the hardware doesn't cooperate. Not impossible... just hard.

        We *were* p

  • And math, too! (Score:2, Interesting)

    by meburke ( 736645 )
    The GPU ought to be able to be optimized for FP arithmetic, also.

    This idea is not mine, but back when the first Netra came out, a couple of guys here in Houston who used to optimize Crays figured out how to use the GPU to do floating point arithmetic a whole magnitude faster than Sun knew it could be done.

    My optimization skills are a little rusty, but the same architectural elements are there in the ATI graphics cards.

    If some one does this, drop me a line and tell me how you did it.
    • The big problem with FP operations on GPU hardware right now is that nobody conforms to the IEEE standard. There's been some work at Stanford [stanford.edu] on determining exactly how much error propagates, but there's variation not only between the major card companies, but between individual cards and even between vertex and fragment FP units on a given same card!

      Floating point operations aren't much use unless you have some idea how accurate they are.
      • I should point out that it seems the original poster may not have been aware that modern GPUs can do floating-point natively. We played around with using rational arithmetic on older cards, but...

        But anyways, it's true that the FP on GPUs takes a bunch of shortcuts, doesn't handle various things the way it's supposed to according to the IEEE spec, drops low-order bits for some cards, etc. etc. The work at Stanford is certainly valuable in characterizing these issues. However, I suspect the next gene

  • "Chapter three contains a quite interesting sample shader that uses constructive solid geometry techniques and metaprogramming in Sh to render text." Which means it can do one of the most complicated sounding "Hello World" programs of any language!

Brain off-line, please wait.

Working...