ARB Fragment Program in GPULib Summary Fragment program
ARB Fragment Program in GPULib
Summary Fragment program arquitecture n New instructions. n ¨ Emulating instructions not supported directly New Required GL State n Compiler status n
Fragment program architecture n What fragment programs bypass: ¨ Replaces multitexturing pipe: n Replaces this calculations: ¨ ¨ ¨ n Texture blending Color sum Fog What not (is preserved): ¨ Coverage application ¨ Alpha Test ¨ Stencil and depth test ¨ Blending
Fragment program architecture (II) setup rasterizer Texture Fetch and Application Color Sum Fog frame-buffer ops User-defined Fragment Processing
Fragment program architecture (III) Program Environment Parameters Attributes Program Local Parameters Fragment Program Address Variables Temporary Variables Result Registers
Fragment program architecture(IV) n Input attributes (called fragment attributes): ¨ color (primary and secondary) ¨ vector of texture coordinates (for multitexturing) ¨ fog coordinate ¨ position (window position + z) n Output attributes: ¨ 2 attributes to write: n n color (r, g, b, a) depth (*, *, d, *)
Fragment program architecture(V) n Program local and environment parameters: ¨ Like vertex programs: n n n 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 n n ¨ ¨ ¨ ALU instructions: 48 Texture instructions: 24 Texture indirections: 4 Temporaries: 16 Program parameters: 24
New instructions n The same instructions as vertex programs: ¨ Except: n n ¨ Plus: n n ARL: Now, no address registers to load LOG, EXP: Remain LG 2 and EX 2 instructions. 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: ¨ n n OPTION ARB_precision_hint_fastest; # Minimize execution time OPTION ARB_precision_hint_nicest; # Maximize execution time
New instructions (II) n And. . . the Texture instructions: ¨ Gets texture coordinates of fragment and samples the texture color corresponding to the fragment. TEX my. Texel, fragment. texcoord[1], texture[2], 3 D; ¨ Extended n texture fetches: TXP and TXB
Texture indirections n n 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: !!ARBfp 1. 0 # No texture instructions, but always 1 indirection MOV result. color, fragment. color; END n Texture dependencies sums indirection !!ARBfp 1. 0 # A simple dependent texture instruction, 2 indirections TEMP my. Color; MUL my. Color, fragment. texcoord[0], fragment. texcoord[1]; TEX result. color, my. Color, texture[0], 2 D; END
New instructions (III) n KIL instruction: KIL vector. Src. Reg; 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) ¨ n 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. n SCS: n ¨ Emulated n using the separate SIN and COS LRP: LPR result, op 0, op 1, op 2; ADD result, op 0, -op 2; MAD result, op 1, op 2;
Instruction emulation n CMP: CMP dst, src 0, src 1, src 2; SLT tmp, src 0, {0, 0, 0, 0}; LRP dst, tmp, src 1, src 2;
New GLState n 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. ¨ n New GLState: ¨ Texture Environment Color Property: n ¨ Fog Properties: n n ¨ state. texenv[n]. color ( n = 0 to #texture units) RGB fog color Params (fog density, linear start and end, and 1/(end-start)) Depth Properties: n Depth range near, far, and (far-near)
Compiler Status Line: By 0 By 1 By 2 By 3 By 4 By 5 By 6 By 7 By 8 By 9 By. ABy. By. DBy. EBy. F 011: 16 00 03 28 00 01 00 08 26 1 b 6 a 00 0 f 1 b 04 78 012: 09 00 03 00 00 00 02 08 24 1 b 1 b 00 08 1 b 14 18 013: 09 00 04 00 00 00 02 08 24 1 b 1 b 00 04 1 b 14 b 8 014: 09 00 05 00 00 00 02 08 24 1 b 1 b 00 02 1 b 04 58 015: 09 00 06 00 00 00 02 08 24 1 b 1 b 00 01 1 b 04 f 8 016: 16 00 01 00 00 00 02 30 24 1 b 1 b 00 08 1 b 14 98 017: 16 00 02 00 00 01 02 30 24 1 b 1 b 00 08 1 b 04 38 018: 16 00 00 00 03 30 24 00 1 b 00 02 1 b 04 d 8 019: 16 00 01 00 00 00 03 30 24 00 1 b 00 01 1 b 14 78 020: 01 00 08 00 00 08 18 08 24 04 ae 00 0 c 1 b 04 18 021: 17 00 00 00 13 30 24 00 00 00 08 1 b 04 b 8 022: 17 00 01 00 00 00 13 30 24 00 00 00 04 1 b 14 58 023: 01 00 08 00 00 09 18 08 24 04 04 00 0 c 1 b 14 f 8 024: 01 00 08 00 00 0 a 18 08 26 04 ae 00 0 c 1 b 04 98 025: 01 00 08 00 00 0 b 18 08 26 04 04 00 0 c 1 b 14 38 !!ARBfp 1. 0 # Simple program to show to code up # the default texture environment ATTRIB tex = fragment. texcoord; #first set of texture # coordinates ATTRIB col = fragment. color. primary; OUTPUT out. Color = result. color; TEMP tmp; TXP tmp, texture, 2 D; #sample the texture MUL out. Color, tmp, col; #perform the modulation END Current work: IR Específico GPU !!ARBvp 1. 0 Flex + Bison (Completed) Code Generation (Completed) Generic + TEX, CMP, . . .
Compiler Status Lexical and Syntactical: Complete n Translation of generic to GPU instructions: Complete n Current Work: n ¨ Generating new IR for the fragment programmar. ¨ Semantic Parse and Code generation parse
- Slides: 16