Shader Parser

9 views
Skip to first unread message

Mike Tajmajer

unread,
Jun 28, 2010, 11:35:22 AM6/28/10
to fog...@googlegroups.com
Hi Petr,

I am slowly moving forward on the fragment parser/compiler.

I'm using the assumptions I made in the previous email.

Mike Tajmajer

unread,
Jun 28, 2010, 2:48:31 PM6/28/10
to fog...@googlegroups.com
Hi Petr,

This is accessing the framebuffer ;-)

It is as easy as it gets with the fragment shader.


My code is not pretty right now.

I am trying out things and there is much debugging code.

As I get parts working, I'll rewrite into something that is actually
useable.


Currently, I have most of a parser, and am creating the compiler -- it uses
AsmJit for this.


Here is my first sample. It uses a TEMP, modifies the TEMP, then writes it
to the framebuffer via result.color.

!!ARBfp1.0
TEMP color = {1, 0.5, -0.32, 1};
MOV color.r, -0.5;
MOV result.color, color;
END


The result is:

; Function Prototype:
; (int32)
;
; Variables:
; 0 int32 ( 4B) at dword ptr [ebp+8] - reg access: 9 , mem
access:
1
; 1 xmm_float4 (16B) at [None] - reg access: 4 , mem
access:
0
;
; Modified registers (2):
; GP :ecx
; MM :
; XMM:xmm0
L2:
push ebp
mov ebp, esp
L3:
; Initialize an XMM Register with a vector of 4 floats.
mov eax, 1065353216
mov ecx, dword ptr [ebp+8] ; alloc
mov dword ptr [ecx+32], eax
mov eax, 1056964608
mov dword ptr [ecx+36], eax
mov eax, -1096558838
mov dword ptr [ecx+40], eax
mov eax, 1065353216
mov dword ptr [ecx+44], eax
movaps xmm0, qword ptr [ecx+32]
; Update an XMM Register with a single float.
movaps qword ptr [ecx+32], xmm0
mov eax, -1090519040
mov dword ptr [ecx+32], eax
movaps xmm0, qword ptr [ecx+32]
; Copy an XMM Register to the result.color.
movaps qword ptr [ecx], xmm0
L4:
mov esp, ebp
pop ebp
ret
L1:
; Compiler successful (wrote 65 bytes).

Mike Tajmajer

unread,
Jun 29, 2010, 5:25:23 PM6/29/10
to fog...@googlegroups.com
Hi Petr,

I'm testing the MOV opcode with different data and it seems to be working OK
so far.

Next, I'm going to test using Cg to generate the ARB code -- then start
adding more OPcodes.

At that point, I can try connecting it to Fog.

For this, I will need a function to be called with the proposed pixel, and
to return the resulting pixel. Eventually I will need more info for the
context (x, y coords, etc.).

Working ARB Code:

!!ARBfp1.0
# Copy fragment.color to result.color;
MOV result.color, fragment.color;
END

!!ARBfp1.0
# Copy fragment.color to result.color
MOV result.color.r, fragment.color.r;
MOV result.color[1], fragment.color[1];
MOV result.color.ba, fragment.color.ba;
END

!!ARBfp1.0
TEMP color = {1.0, 2.0, 3.0, 4.0};
MOV result.color, color;
END

!!ARBfp1.0
TEMP color = {1.0, 2.0, 3.0, 4.0};
MOV result.color.r, color.r;
MOV result.color[1], color[1];
MOV result.color.ba, color.ba;
END

!!ARBfp1.0
MOV result.color.r, 1.0;
MOV result.color[1], 2.0;
MOV result.color.b, 3.0;
MOV result.color.a, 4.0;
END


Reply all
Reply to author
Forward
0 new messages