views:

604

answers:

2

Can someone explain the different between Pixel Bender in Flash and Pixel Shader(HLSL) in Silverlight in terms of programming flexibility and run-time performance?

A: 

I don't really know about the Silverlight shaders but I can talk about PixelBender.

A pixelbender shader takes bitmap data and evaluates each 32-bit pixel (actually each chunk of 4 floats) one at a time and performs calculations on it. The input to the shader is one or more images and optional parameters and the output is always a single image. The calculation happens in parallel across all the pixels in the image and is 'stateless' between pixels, meaning that you cannot store values while evaluating one pixel and use them in another. In fact, in terms of the pixel evaluation, the function is designed to operate on an infinitely large image and is therefore ignorant to the size and shape of the image.

The functionality available to Flash Player for shaders is a subset of the entire pixelbender language. It excludes such language features as reusable library functions and region functions.

The pixel bender shader can run on the GPU in a separate thread from the Flash Player essentially allowing threaded processes in Flash. In practice, this is only useful for large-batch number crunching given the statelessness and limited functionality of pixelbender. A bytearray of numbers can be passed to the shader disguised as bitmapdata and run asynchronously (or synchronously) using a ShaderJob.

Syntax-wise, both HLSL and PBJ are C-like and based on GLSL. My guess is that HLSL probably has better performance and more features given Microsoft's experience with graphic's hardware. However, the differences between Flash and Silverlight go far beyond their shaders and I think Flash excels beyond Silverlight in almost every area so it comes down to which platform better meets needs.

Mims H. Wright
Thanks for your detailed info. However, PB in Flash does NOT run in GPU. Hope there will be more comparisons between the two :)
Andy Li
Thanks for pointing that out. my bad!
Mims H. Wright
@Andy: Apparently the (final) 10.1 release of Flash Player will have a GPU rasterizer, which I assume would require a GPU implementation of Pixel Bender.
Simon Buchan
@Simon Buchan: Really? I only know there will be GPU accelerated video decoding... Hope that true and it will come soon :)
Andy Li
excels beyond Silverlight in almost every area? This was shaping up to be a good half of an answer
Rob Fonseca-Ensor
Bah, Just because its stateless doesn't mean you can't compute in it. Look into some of the older GPGPU algorithms (shader code has the same stateless limitation). I've written automatons that work entirely in pixel shaders (which included mouse input, just needed to be told where the mouse was and if a button was down). Furthermore, people have done physics, ray-tracing, sorting, AI and many other algorithms without being able to directly affect other data sets.
Grant Peters
+1  A: 

I do not know about programmability, but as for run-time performance, pixelbender is great. Currently Silverlight 3 does not let you do this processing in the background, but with PixelBender, you can. This is good because the UI is not affected as much when using computationally intense filters.

This forum (half-way down the page) had some good pro's and con's for Silverlight 3: Pros and Cons (half-way down the page is a list). I know this topic is old, but I'm adding to it since it seemed a little incomplete.

mdiehl13