Pixel Power (P2) - Columbia Universityaho/cs4115_Fall-2009/lectures/09... · 2009. 12. 12. ·...

19
Pixel Power (P2) Eliane Kabkab System Integrator Nageswar Keetha Language Guru Eric Liu Project Manager Kaushik Viswanathan System Architect

Transcript of Pixel Power (P2) - Columbia Universityaho/cs4115_Fall-2009/lectures/09... · 2009. 12. 12. ·...

Page 1: Pixel Power (P2) - Columbia Universityaho/cs4115_Fall-2009/lectures/09... · 2009. 12. 12. · graphics but for general computing • Stream processing paradigm –apply the same

Pixel Power (P2)

Eliane Kabkab – System Integrator

Nageswar Keetha – Language Guru

Eric Liu – Project Manager

Kaushik Viswanathan – System Architect

Page 2: Pixel Power (P2) - Columbia Universityaho/cs4115_Fall-2009/lectures/09... · 2009. 12. 12. · graphics but for general computing • Stream processing paradigm –apply the same

Today’s Landscape

• Multi-core computers

• Increasing importance of GPU not only for

graphics but for general computing

• Stream processing paradigm – apply the same • Stream processing paradigm – apply the same

function to each element in a data set at the

same time

Page 3: Pixel Power (P2) - Columbia Universityaho/cs4115_Fall-2009/lectures/09... · 2009. 12. 12. · graphics but for general computing • Stream processing paradigm –apply the same

Goals

• Programming using stream processing

• Eliminates some synchronization-related

issues with parallel processing

• Abstract away details of thread management• Abstract away details of thread management

• Code that can run on GPU’s

• Familiarity – programmers comfortable with C

will find it easier to learn and use

Page 4: Pixel Power (P2) - Columbia Universityaho/cs4115_Fall-2009/lectures/09... · 2009. 12. 12. · graphics but for general computing • Stream processing paradigm –apply the same

Applications

• Large data sets such as scientific computation

and high performance computing

• Image manipulation and processing

• 3D graphics and rendering (shaders)• 3D graphics and rendering (shaders)

• Parallelization of existing C code

Page 5: Pixel Power (P2) - Columbia Universityaho/cs4115_Fall-2009/lectures/09... · 2009. 12. 12. · graphics but for general computing • Stream processing paradigm –apply the same

Features

• Imperative, statically typed

• Stream functions – automatically split

function into multiple threads

• Shader functions – running code on GPU’s• Shader functions – running code on GPU’s

• New types: [type-name]NxM

– Image2D, matrix, float2x3

• Built-in functions: manipulation of newly

defined types

Page 6: Pixel Power (P2) - Columbia Universityaho/cs4115_Fall-2009/lectures/09... · 2009. 12. 12. · graphics but for general computing • Stream processing paradigm –apply the same

Syntax: C + HLSL + custom - reserved

HLSL

C++

p2

Page 7: Pixel Power (P2) - Columbia Universityaho/cs4115_Fall-2009/lectures/09... · 2009. 12. 12. · graphics but for general computing • Stream processing paradigm –apply the same

Reservedint switch break continue

uint case if return

stream default else Matrix

float Image2d do sizeof

TextBox Image3d while typedefTextBox Image3d while typedef

Vector Texture2d for extern

char Quad struct SHelper

String static enum shader

Page 8: Pixel Power (P2) - Columbia Universityaho/cs4115_Fall-2009/lectures/09... · 2009. 12. 12. · graphics but for general computing • Stream processing paradigm –apply the same

Language constructs

• Stream

• Shared buffer for stream functions (mapping

to a list of threads)

• Shader• Shader

• Vector, Matrix, Tensor

• Easy declaration – swizzling

• Example: color = color.rrg

Page 9: Pixel Power (P2) - Columbia Universityaho/cs4115_Fall-2009/lectures/09... · 2009. 12. 12. · graphics but for general computing • Stream processing paradigm –apply the same

Inbuilt types

Intrinsic Type Variable

Scalar One-component scalar (1D)

Vector, Matrix Multiple-component tensors (1D, 2D)

Image Image object (2D, 3D)

Texture Texture object (2D)

TextBox TextBox objectTextBox TextBox object

Struct Custom structure

Svar Shader variable list

Enum C-style enumerations

User Defined typedef

Page 10: Pixel Power (P2) - Columbia Universityaho/cs4115_Fall-2009/lectures/09... · 2009. 12. 12. · graphics but for general computing • Stream processing paradigm –apply the same

Inbuilt functionsTEXTURE

int Create(Texture* tex, uint2 resolution,

PIXEL_FORMAT format, TEX_ACCESS

access)

Image2D* GetImage(Texture* tex)

int SetRenderTarget(Texture* tex)

TEXTBOX

int CreateFont (TextBox* tBox, float2 size,

bool isBold, bool isItalic, String fontType)

int Draw(TextBox* tBox, RGBA color, Rect

rect, TEXT_ALIGN alignment)

C-GLOBALS

void AddElementTo([User-defined-type]* int Clear(Texture* tex, RGBA color)

int Release(Texture* tex)

void AddElementTo([User-defined-type]*

container, float2 position, [Type]* value)

int BindSvar(svar* SVar, string address,

[Type]* value)

int SetShader(shader* Name)

STREAM SYNCHRONIZATION

void synch()

Page 11: Pixel Power (P2) - Columbia Universityaho/cs4115_Fall-2009/lectures/09... · 2009. 12. 12. · graphics but for general computing • Stream processing paradigm –apply the same

Inbuilt states

• Timing information – between states

• BackBuffer – screen

• Input – mouse/keyboard info

• SHADER_IN – pixel information• SHADER_IN – pixel information

• STREAM_IN – current thread

Page 12: Pixel Power (P2) - Columbia Universityaho/cs4115_Fall-2009/lectures/09... · 2009. 12. 12. · graphics but for general computing • Stream processing paradigm –apply the same

Program Structure

• Multiple files allowed like C

• int init() – Once per program

• int main() – Once per frame (Required)

• int input_callback(Input*) – Once per • int input_callback(Input*) – Once per

keyboard / mouse event

Page 13: Pixel Power (P2) - Columbia Universityaho/cs4115_Fall-2009/lectures/09... · 2009. 12. 12. · graphics but for general computing • Stream processing paradigm –apply the same

//Converts an image to black and white

SHelper float calcRGB (int r, int g, int b)

{

//Computation for rgbColor.rgb

return r * 0.3 + g * 0.6 + b * 0.1;

}

shader RGBToBW

{

//Read the color of the current pixel

float4 rgbColor = Tex2D(&rgbIn, PS_IN.texCoord, TEX_FILTER_LINEAR);

rgbColor.rgb = calcRGB(rgbColor.r,rgbColor.g,rgbColor.b);

return rgbColor;

}

//Shader variable list

svarRGBToBW

{ {

Image rgbIn;

};

//Main render loop

int main()

{

Image img;

img.Load(“example.jpg”);

//Target texture for the shader

SetRenderTarget(&backBuffer);

BindSvar(“RGBToBW”, “rgbin”, &img);

SetShader(“RGBToBW”);

//Draw the default Quad to the screen using //shader RGBToBW

screenAligned.Draw();

return 0;

}

Page 14: Pixel Power (P2) - Columbia Universityaho/cs4115_Fall-2009/lectures/09... · 2009. 12. 12. · graphics but for general computing • Stream processing paradigm –apply the same

.p2 & .h files Cleanup Exclude C++

+ HLSL – p2

Line Buffer Error Buffer Symbol Table Translation

Table

Lex + Parse

Custom

File Split

(Scoping)

.exe

SDTCustom Code

InjectionVC++ compiler +

linker

HLSL

compiler

List of .cpp, .h, and

.fx files

Page 15: Pixel Power (P2) - Columbia Universityaho/cs4115_Fall-2009/lectures/09... · 2009. 12. 12. · graphics but for general computing • Stream processing paradigm –apply the same

Implementation

• DirectX based mini-engine, Windows .exe,

Visual C++ compiler

• [.p2, .h] -> [.cpp, .h, .fx] + graphics and

threading API -> .exethreading API -> .exe

.p2, .h files .cpp/.h/.fx files

.exe

Display engine

p2 compiler

C++ compiler

Page 16: Pixel Power (P2) - Columbia Universityaho/cs4115_Fall-2009/lectures/09... · 2009. 12. 12. · graphics but for general computing • Stream processing paradigm –apply the same

Tools and API’s used

• Visual C++ express IDE

• Visual C++ command

line compiler

• Flex/Bison• Flex/Bison

• Assembla / Tortoise for

SVN

• DirectX 9 SDK

• Custom graphics API

• Google Groups

Page 17: Pixel Power (P2) - Columbia Universityaho/cs4115_Fall-2009/lectures/09... · 2009. 12. 12. · graphics but for general computing • Stream processing paradigm –apply the same

Testing methodology

Gradual Step-by-Step Testing

• Unit testing

Design relatively independent sub-units

Test shared structures

Test each sub-unit extensively

• Integration testing

Test shared interaction

• System Testing

Test whole compiler

Page 18: Pixel Power (P2) - Columbia Universityaho/cs4115_Fall-2009/lectures/09... · 2009. 12. 12. · graphics but for general computing • Stream processing paradigm –apply the same

Challenges

Technical Challenges

• New to Image Processing and Graphics Programming

• New APIs to work on

Human Challenges

• Diverse backgrounds

• Scheduling

Page 19: Pixel Power (P2) - Columbia Universityaho/cs4115_Fall-2009/lectures/09... · 2009. 12. 12. · graphics but for general computing • Stream processing paradigm –apply the same

However,

Not only did we

• Come up with a comprehensive language

• Manage to compile code and run it with visualizable

results

Our language

• Is easy to learn for a C/C++ programmer

• Is easier than already existing graphics oriented

languages

• Does the work for you and saves you a lot of time