ARB Fragment Program in GPULib
Summary Fragment program arquitecture New instructions. Emulating instructions not supported directly New Required GL State Compiler status
Fragment program architecture What fragment programs bypass: Replaces multitexturing pipe: Replaces this calculations: Texture blending Color sum Fog What not (is preserved): Coverage application Alpha Test Stencil and depth test Blending
Fragment program architecture (II) User-defined Fragment Processing frame-buffer ops Color Sum setup Texture Fetch and Application rasterizer Fog
Fragment program architecture (III) Attributes Fragment Program Result Registers Temporary Variables Program Local Parameters Program Environment Parameters Address Variables
Fragment program architecture(IV) Input attributes (called fragment attributes): color (primary and secondary) vector of texture coordinates (for multitexturing) fog coordinate position (window position + z) Output attributes: 2 attributes to write: color (r,g,b,a) depth (*,*,d,*)
Fragment program architecture(V) Program local and environment parameters: Like vertex programs: local: private for each fragment program env: shared for all programs (including vertex programs). Limits (the implementation has to guarantee equal or higher limits): Total Number of instructions: 72 ALU instructions: 48 Texture instructions: 24 Texture indirections: 4 Temporaries: 16 Program parameters: 24
New instructions The same instructions as vertex programs: Except: ARL: Now, no address registers to load LOG, EXP: Remain LG2 and EX2 instructions. Plus: SIN, COS, SCS(leave sinus on.x and cosinus on.y) LRP (Linear Interpolation instruction) CMP (Compare instruction) Note about ALU instructions: Implementations may be able to perform fragment program computations at more than one precision: New program option directives: OPTION ARB_precision_hint_fastest; # Minimize execution time OPTION ARB_precision_hint_nicest; # Maximize execution time
New instructions (II) And... the Texture instructions: Gets texture coordinates of fragment and samples the texture color corresponding to the fragment. TEX myTexel, fragment.texcoord[1], texture[2], 3D; Extended texture fetches: TXP and TXB
Texture indirections A texture dependency occurs when a texture instruction depends on the result of a previous instruction (ALU or texture) for use as its texture coordinate. A fragment program with no dependencies has 1 texture indirections: !!ARBfp1.0 # No texture instructions, but always 1 indirection MOV result.color, fragment.color; END Texture dependencies sums indirection !!ARBfp1.0 # A simple dependent texture instruction, 2 indirections TEMP myColor; MUL myColor, fragment.texcoord[0], fragment.texcoord[1]; TEX result.color, myColor, texture[0], 2D; END
New instructions (III) KIL instruction: KIL vectorSrcReg; Prevents a fragment from receiving any future processing if any component of its source vector is negative ARB instruction takes a vector operand rather than a condition code (NVIDIA) Saturation Flag: Optional clamping of each component of the destination register to the range [0,1] is controlled by an opcode modifier. There is a clamped version of each instruction: ADD_SAT, TEX_SAT, CMP_SAT, LRP_SAT.
Instruction emulation SIN, COS, TEX, TXP, TXB supported directly by GPU. SCS: Emulated using the separate SIN and COS LRP: LPR result, op0, op1, op2; ADD result, op0, -op2; MAD result, result, op1, op2;
Instruction emulation CMP: CMP dst, src0, src1, src2; SLT tmp, src0, {0,0,0,0}; LRP dst, tmp, src1, src2;
New GLState GLState shared with vertex programs: Material Properties: material ambient, diffuse, specular (for front and back faces) Light and Lightmodel Properties: ambient, diffuse, specular, attenuation, spot direction, spot cut-off (for each GL_LIGHTX). Matrix Properties: Modelview, MVP, projection matrices with.transpose,.inverse,.invtrans modifiers. New GLState: Texture Environment Color Property: state.texenv[n].color ( n = 0 to #texture units) Fog Properties: RGB fog color Params (fog density, linear start and end, and 1/(end-start)) Depth Properties: Depth range near, far, and (far-near)
Compiler Status !!ARBfp1.0 # Simple program to show how to code up # the default texture environment ATTRIB tex = fragment.texcoord; #first set of texture # coordinates ATTRIB col = fragment.color.primary; OUTPUT outColor = result.color; TEMP tmp; TXP tmp, tex, texture, 2D; #sample the texture MUL outColor, tmp, col; #perform the modulation END Flex + Bison (Completed) !!ARBvp1.0 IR Code Generation Específico GPU Generic + TEX,CMP,... Line:By0By1By2By3By4By5By6By7By8By9ByAByBByByDByEByF 011: b 6a 00 0f 1b : b 1b b : b 1b b 14 b8 014: b 1b b : b 1b b 04 f8 016: b 1b b : b 1b b : b b 04 d8 019: b b : ae 00 0c 1b : b 04 b8 022: b : c 1b 14 f8 024: a ae 00 0c 1b : b c 1b (Completed) Current work:
Compiler Status Lexical and Syntactical: Complete Translation of generic to GPU instructions: Complete Current Work: Generating new IR for the fragment program grammar. Semantic Parse and Code generation parse