Compare commits

..

1 Commits

Author SHA1 Message Date
db0574345b wip 2025-11-11 08:27:15 -06:00
12 changed files with 108 additions and 1082 deletions

View File

@ -304,18 +304,18 @@ int indirect_buffer(float time)
| SC_SCISSOR0__YS0(0)
);
T0V(SC_SCISSOR1
, SC_SCISSOR1__XS1(800 - 1)
| SC_SCISSOR1__YS1(600 - 1)
, SC_SCISSOR1__XS1(1600 - 1)
| SC_SCISSOR1__YS1(1200 - 1)
);
//////////////////////////////////////////////////////////////////////////////
// VAP
//////////////////////////////////////////////////////////////////////////////
T0Vf(VAP_VPORT_XSCALE, 400.0f);
T0Vf(VAP_VPORT_XOFFSET, 400.0f);
T0Vf(VAP_VPORT_YSCALE, -300.0f);
T0Vf(VAP_VPORT_YOFFSET, 300.0f);
T0Vf(VAP_VPORT_XSCALE, 800.0f);
T0Vf(VAP_VPORT_XOFFSET, 800.0f);
T0Vf(VAP_VPORT_YSCALE, -600.0f);
T0Vf(VAP_VPORT_YOFFSET, 600.0f);
T0Vf(VAP_VPORT_ZSCALE, 0.5f);
T0Vf(VAP_VPORT_ZOFFSET, 0.5f);

View File

@ -23,15 +23,82 @@ src0.rgb = temp[0] : -- uv0
--------------------------------------------------------------------------------
-- loop start
--------------------------------------------------------------------------------
#include "shadertoy_palette_fractal_loop_inner.fs.asm"
#include "shadertoy_palette_fractal_loop_inner.fs.asm"
#include "shadertoy_palette_fractal_loop_inner.fs.asm"
#include "shadertoy_palette_fractal_loop_inner.fs.asm"
--------------------------------------------------------------------------------
-- loop end
--------------------------------------------------------------------------------
-- uv = uv * 1.5;
src0.rgb = temp[1] , -- uv
src0.a = float(60) : -- 1.5
temp[1].rg = MAD src0.rg_ src0.aa_ src0.00_ ;
-- uv = fract(uv);
src0.rgb = temp[1] : -- uv
temp[1].rg = FRC src0.rg_ ;
-- uv = uv - 0.5;
src0.a = float(48) : -- 0.5
temp[1].rg = MAD src0.rg_ src0.11_ src0.aa_ ;
-- l = length(uv0);
src0.rgb = temp[0] : -- uv0
DP3 src0.rg0 src0.rg0 ,
temp[0].a = DP ;
src0.a = temp[0] :
temp[0].a = RSQ |src0.a| ;
src0.a = temp[0] :
temp[0].a = RCP src0.a ;
-- d = i * 0.4 + l;
src0.a = const[0] , -- 0.4
src1.a = temp[0] , -- l
src2.a = temp[3] : -- i
temp[1].a = MAD src2.a src0.a src1.a ;
-- d = time * 0.4 + d;
src0.a = const[0] , -- 0.4
src1.a = temp[1] , -- d
src0.rgb = const[0] : -- time (r)
temp[1].a = MAD src0.r src0.a src1.a ;
-- palette
-- v = d + (vec3(0.25, 0.40625, 0.5625) + 0.5)
src0.a = temp[1] , -- d
src0.rgb = const[2] , -- vec3(0.25, 0.40625, 0.5625)
src1.rgb = float(48) , -- 0.5
srcp.rgb = add : -- (vec3(0.25, 0.40625, 0.5625) + 0.5)
temp[3].rgb = MAD src0.111 src0.aaa srcp.rgb ;
-- v = frac(v)
src0.rgb = temp[3] : -- v
temp[3].rgb = FRC src0.rgb ;
src0.rgb = temp[3] , -- v
src1.rgb = float(48) : -- 0.5
temp[3].rgb = MAD src0.111 src0.rgb -src1.rgb ;
-- v = cos(v)
src0.rgb = temp[3] : -- v
COS src0.r ,
temp[3].r = SOP ;
src0.rgb = temp[3] : -- v
COS src0.g ,
temp[3].g = SOP ;
src0.rgb = temp[3] : -- v
COS src0.b ,
temp[3].b = SOP ;
-- col = vec3(0.5, 0.5, 0.5) * v + vec3(0.5, 0.5, 0.5)
src0.rgb = temp[3] , -- v
src1.rgb = float(48) : -- 0.5
temp[3].rgb = MAD src1.rgb src0.rgb src1.rgb;
-- end of 'palette' function
-----
-----
-----
OUT TEX_SEM_WAIT
src0.rgb = temp[2] :
src0.a = temp[0] ,
src0.rgb = temp[0] ,
src1.rgb = temp[3] :
out[0].a = MAX src0.1 src0.1 ,
out[0].rgb = MAX src0.rgb src0.rgb ;
out[0].rgb = MAX src1.rgb src1.rgb ;

View File

@ -34,11 +34,11 @@
0x00000019,
0x00001800,
0x08020001,
0x0802c080,
0x08020080,
0x080200b0,
0x00fb0720,
0x00000000,
0x00f6d010,
0x0076c010,
0x00004000,
0x08020000,
@ -124,801 +124,10 @@
0x00000000,
0x00221030,
0x00004000,
0x08020080,
0x08020000,
0x00000000,
0x0002c018,
0x00000000,
0x00004000,
0x08020001,
0x08020080,
0x00840420,
0x00000001,
0x00000001,
0x00004000,
0x08020080,
0x08020000,
0x00000000,
0x0004c00b,
0x00000000,
0x00004000,
0x08020080,
0x08020000,
0x00000000,
0x0000c00a,
0x00000000,
0x00004000,
0x08020080,
0x08000400,
0x00000000,
0x0068c010,
0x20000000,
0x00004000,
0x10020080,
0x08034001,
0x00000000,
0x0068c010,
0x04000000,
0x00004000,
0x08040480,
0x0b020001,
0x00000000,
0x0028c010,
0x1c000000,
0x00004000,
0x08020080,
0x08020001,
0x00000000,
0x0000c017,
0x00000000,
0x00004000,
0x08020080,
0x0802c001,
0x00000000,
0x00618010,
0x5a000000,
0x00004000,
0x08020080,
0x08020001,
0x00000000,
0x1800c01c,
0x00000000,
0x00004000,
0x08020080,
0x08020001,
0x00000000,
0x0004c01a,
0x00000000,
0x00004000,
0x08040080,
0x08020001,
0x00000000,
0x0048c010,
0x20000000,
0x00004000,
0x08020080,
0x08020001,
0x00000000,
0x0000c019,
0x00000000,
0x00004000,
0x08040080,
0x08020001,
0x00000000,
0x0028c010,
0x20000000,
0x00004000,
0x08020080,
0x08020001,
0x00000000,
0x0000c018,
0x00000000,
0x00003800,
0x00220003,
0x08000480,
0x006da220,
0x00000000,
0x00222020,
0x00004000,
0x08020080,
0x08020003,
0x00000000,
0x00618030,
0x30000000,
0x00001800,
0x08020001,
0x080200bc,
0x00ed8720,
0x00000000,
0x00790010,
0x00001800,
0x08020001,
0x08020080,
0x00000720,
0x00000000,
0x00000019,
0x00001800,
0x08020001,
0x0802c080,
0x00fb0720,
0x00000000,
0x00f6d010,
0x00004000,
0x08020000,
0x08020080,
0x00840420,
0x00000001,
0x00000001,
0x00004000,
0x08020080,
0x08020000,
0x00000000,
0x0004c00b,
0x00000000,
0x00004000,
0x08020080,
0x08020000,
0x00000000,
0x0000c00a,
0x00000000,
0x00004000,
0x08020080,
0x00300100,
0x00000000,
0x0060e010,
0x1a000000,
0x00004000,
0x08020100,
0x08000500,
0x00000000,
0x00600010,
0x1a000000,
0x00003800,
0x8802c102,
0x08020001,
0x006d86d8,
0x00000000,
0x00223030,
0x00003800,
0x08020003,
0x08020080,
0x00000220,
0x00000000,
0x00000039,
0x00003800,
0x0802c003,
0x08020080,
0x004406d8,
0x00000000,
0x00a21030,
0x00000800,
0x08020003,
0x08020080,
0x00000000,
0x0000000d,
0x0000003a,
0x00001000,
0x08020003,
0x08020080,
0x00000000,
0x0000400d,
0x0000003a,
0x00002000,
0x08020003,
0x08020080,
0x00000000,
0x0000800d,
0x0000003a,
0x00003800,
0x0802c003,
0x08020080,
0x00440221,
0x00000000,
0x00221030,
0x00004000,
0x08020080,
0x08020000,
0x00000000,
0x0002c018,
0x00000000,
0x00004000,
0x08020001,
0x08020080,
0x00840420,
0x00000001,
0x00000001,
0x00004000,
0x08020080,
0x08020000,
0x00000000,
0x0004c00b,
0x00000000,
0x00004000,
0x08020080,
0x08020000,
0x00000000,
0x0000c00a,
0x00000000,
0x00004000,
0x08020080,
0x08000400,
0x00000000,
0x0068c010,
0x20000000,
0x00004000,
0x10020080,
0x08034001,
0x00000000,
0x0068c010,
0x04000000,
0x00004000,
0x08040480,
0x0b020001,
0x00000000,
0x0028c010,
0x1c000000,
0x00004000,
0x08020080,
0x08020001,
0x00000000,
0x0000c017,
0x00000000,
0x00004000,
0x08020080,
0x0802c001,
0x00000000,
0x00618010,
0x5a000000,
0x00004000,
0x08020080,
0x08020001,
0x00000000,
0x1800c01c,
0x00000000,
0x00004000,
0x08020080,
0x08020001,
0x00000000,
0x0004c01a,
0x00000000,
0x00004000,
0x08040080,
0x08020001,
0x00000000,
0x0048c010,
0x20000000,
0x00004000,
0x08020080,
0x08020001,
0x00000000,
0x0000c019,
0x00000000,
0x00004000,
0x08040080,
0x08020001,
0x00000000,
0x0028c010,
0x20000000,
0x00004000,
0x08020080,
0x08020001,
0x00000000,
0x0000c018,
0x00000000,
0x00003800,
0x00220003,
0x08000480,
0x006da220,
0x00000000,
0x00222020,
0x00004000,
0x08020080,
0x08020003,
0x00000000,
0x00618030,
0x30000000,
0x00001800,
0x08020001,
0x080200bc,
0x00ed8720,
0x00000000,
0x00790010,
0x00001800,
0x08020001,
0x08020080,
0x00000720,
0x00000000,
0x00000019,
0x00001800,
0x08020001,
0x0802c080,
0x00fb0720,
0x00000000,
0x00f6d010,
0x00004000,
0x08020000,
0x08020080,
0x00840420,
0x00000001,
0x00000001,
0x00004000,
0x08020080,
0x08020000,
0x00000000,
0x0004c00b,
0x00000000,
0x00004000,
0x08020080,
0x08020000,
0x00000000,
0x0000c00a,
0x00000000,
0x00004000,
0x08020080,
0x00300100,
0x00000000,
0x0060e010,
0x1a000000,
0x00004000,
0x08020100,
0x08000500,
0x00000000,
0x00600010,
0x1a000000,
0x00003800,
0x8802c102,
0x08020001,
0x006d86d8,
0x00000000,
0x00223030,
0x00003800,
0x08020003,
0x08020080,
0x00000220,
0x00000000,
0x00000039,
0x00003800,
0x0802c003,
0x08020080,
0x004406d8,
0x00000000,
0x00a21030,
0x00000800,
0x08020003,
0x08020080,
0x00000000,
0x0000000d,
0x0000003a,
0x00001000,
0x08020003,
0x08020080,
0x00000000,
0x0000400d,
0x0000003a,
0x00002000,
0x08020003,
0x08020080,
0x00000000,
0x0000800d,
0x0000003a,
0x00003800,
0x0802c003,
0x08020080,
0x00440221,
0x00000000,
0x00221030,
0x00004000,
0x08020080,
0x08020000,
0x00000000,
0x0002c018,
0x00000000,
0x00004000,
0x08020001,
0x08020080,
0x00840420,
0x00000001,
0x00000001,
0x00004000,
0x08020080,
0x08020000,
0x00000000,
0x0004c00b,
0x00000000,
0x00004000,
0x08020080,
0x08020000,
0x00000000,
0x0000c00a,
0x00000000,
0x00004000,
0x08020080,
0x08000400,
0x00000000,
0x0068c010,
0x20000000,
0x00004000,
0x10020080,
0x08034001,
0x00000000,
0x0068c010,
0x04000000,
0x00004000,
0x08040480,
0x0b020001,
0x00000000,
0x0028c010,
0x1c000000,
0x00004000,
0x08020080,
0x08020001,
0x00000000,
0x0000c017,
0x00000000,
0x00004000,
0x08020080,
0x0802c001,
0x00000000,
0x00618010,
0x5a000000,
0x00004000,
0x08020080,
0x08020001,
0x00000000,
0x1800c01c,
0x00000000,
0x00004000,
0x08020080,
0x08020001,
0x00000000,
0x0004c01a,
0x00000000,
0x00004000,
0x08040080,
0x08020001,
0x00000000,
0x0048c010,
0x20000000,
0x00004000,
0x08020080,
0x08020001,
0x00000000,
0x0000c019,
0x00000000,
0x00004000,
0x08040080,
0x08020001,
0x00000000,
0x0028c010,
0x20000000,
0x00004000,
0x08020080,
0x08020001,
0x00000000,
0x0000c018,
0x00000000,
0x00003800,
0x00220003,
0x08000480,
0x006da220,
0x00000000,
0x00222020,
0x00004000,
0x08020080,
0x08020003,
0x00000000,
0x00618030,
0x30000000,
0x00001800,
0x08020001,
0x080200bc,
0x00ed8720,
0x00000000,
0x00790010,
0x00001800,
0x08020001,
0x08020080,
0x00000720,
0x00000000,
0x00000019,
0x00001800,
0x08020001,
0x0802c080,
0x00fb0720,
0x00000000,
0x00f6d010,
0x00004000,
0x08020000,
0x08020080,
0x00840420,
0x00000001,
0x00000001,
0x00004000,
0x08020080,
0x08020000,
0x00000000,
0x0004c00b,
0x00000000,
0x00004000,
0x08020080,
0x08020000,
0x00000000,
0x0000c00a,
0x00000000,
0x00004000,
0x08020080,
0x00300100,
0x00000000,
0x0060e010,
0x1a000000,
0x00004000,
0x08020100,
0x08000500,
0x00000000,
0x00600010,
0x1a000000,
0x00003800,
0x8802c102,
0x08020001,
0x006d86d8,
0x00000000,
0x00223030,
0x00003800,
0x08020003,
0x08020080,
0x00000220,
0x00000000,
0x00000039,
0x00003800,
0x0802c003,
0x08020080,
0x004406d8,
0x00000000,
0x00a21030,
0x00000800,
0x08020003,
0x08020080,
0x00000000,
0x0000000d,
0x0000003a,
0x00001000,
0x08020003,
0x08020080,
0x00000000,
0x0000400d,
0x0000003a,
0x00002000,
0x08020003,
0x08020080,
0x00000000,
0x0000800d,
0x0000003a,
0x00003800,
0x0802c003,
0x08020080,
0x00440221,
0x00000000,
0x00221030,
0x00004000,
0x08020080,
0x08020000,
0x00000000,
0x0002c018,
0x00000000,
0x00004000,
0x08020001,
0x08020080,
0x00840420,
0x00000001,
0x00000001,
0x00004000,
0x08020080,
0x08020000,
0x00000000,
0x0004c00b,
0x00000000,
0x00004000,
0x08020080,
0x08020000,
0x00000000,
0x0000c00a,
0x00000000,
0x00004000,
0x08020080,
0x08000400,
0x00000000,
0x0068c010,
0x20000000,
0x00004000,
0x10020080,
0x08034001,
0x00000000,
0x0068c010,
0x04000000,
0x00004000,
0x08040480,
0x0b020001,
0x00000000,
0x0028c010,
0x1c000000,
0x00004000,
0x08020080,
0x08020001,
0x00000000,
0x0000c017,
0x00000000,
0x00004000,
0x08020080,
0x0802c001,
0x00000000,
0x00618010,
0x5a000000,
0x00004000,
0x08020080,
0x08020001,
0x00000000,
0x1800c01c,
0x00000000,
0x00004000,
0x08020080,
0x08020001,
0x00000000,
0x0004c01a,
0x00000000,
0x00004000,
0x08040080,
0x08020001,
0x00000000,
0x0048c010,
0x20000000,
0x00004000,
0x08020080,
0x08020001,
0x00000000,
0x0000c019,
0x00000000,
0x00004000,
0x08040080,
0x08020001,
0x00000000,
0x0028c010,
0x20000000,
0x00004000,
0x08020080,
0x08020001,
0x00000000,
0x0000c018,
0x00000000,
0x00003800,
0x00220003,
0x08000480,
0x006da220,
0x00000000,
0x00222020,
0x00004000,
0x08020080,
0x08020003,
0x00000000,
0x00618030,
0x30000000,
0x00078005,
0x08020002,
0x08020080,
0x00440220,
0x08000c00,
0x08020000,
0x00442221,
0x00c18003,
0x00000005,

View File

@ -1,142 +0,0 @@
-- uv = uv * 1.5;
src0.rgb = temp[1] , -- uv
src0.a = float(60) : -- 1.5
temp[1].rg = MAD src0.rg_ src0.aa_ src0.00_ ;
-- uv = fract(uv);
src0.rgb = temp[1] : -- uv
temp[1].rg = FRC src0.rg_ ;
-- uv = uv - 0.5;
src0.rgb = temp[1] ,
src1.a = float(48) : -- 0.5
temp[1].rg = MAD src0.rg_ src0.11_ -src1.aa_ ;
-- l = length(uv0);
src0.rgb = temp[0] : -- uv0
DP3 src0.rg0 src0.rg0 ,
temp[0].a = DP ;
src0.a = temp[0] :
temp[0].a = RSQ |src0.a| ;
src0.a = temp[0] :
temp[0].a = RCP src0.a ;
-- d = i * 0.4 + l;
src0.a = const[0] , -- 0.4
src1.a = temp[0] , -- l
src2.a = temp[3] : -- i
temp[1].a = MAD src2.a src0.a src1.a ;
-- d = time * 0.4 + d;
src0.a = const[0] , -- 0.4
src1.a = temp[1] , -- d
src0.rgb = const[0] : -- time (r)
temp[1].a = MAD src0.r src0.a src1.a ;
--------------------------------------------------------------------------------
-- start of 'palette' function
--------------------------------------------------------------------------------
-- v = d + (vec3(0.25, 0.40625, 0.5625) + 0.5)
src0.a = temp[1] , -- d
src0.rgb = const[2] , -- vec3(0.25, 0.40625, 0.5625)
src1.rgb = float(48) , -- 0.5
srcp.rgb = add : -- (vec3(0.25, 0.40625, 0.5625) + 0.5)
temp[3].rgb = MAD src0.111 src0.aaa srcp.rgb ;
-- v = frac(v)
src0.rgb = temp[3] : -- v
temp[3].rgb = FRC src0.rgb ;
src0.rgb = temp[3] , -- v
src1.rgb = float(48) : -- 0.5
temp[3].rgb = MAD src0.111 src0.rgb -src1.rgb ;
-- v = cos(v)
src0.rgb = temp[3] : -- v
COS src0.r ,
temp[3].r = SOP ;
src0.rgb = temp[3] : -- v
COS src0.g ,
temp[3].g = SOP ;
src0.rgb = temp[3] : -- v
COS src0.b ,
temp[3].b = SOP ;
-- col = vec3(0.5, 0.5, 0.5) * v + vec3(0.5, 0.5, 0.5)
src0.rgb = temp[3] , -- v
src1.rgb = float(48) : -- 0.5
temp[3].rgb = MAD src1.rgb src0.rgb src1.rgb;
--------------------------------------------------------------------------------
-- end of 'palette' function
--------------------------------------------------------------------------------
-- d = ex2(-l);
src0.a = temp[0] : -- l
temp[1].a = EX2 -src0.a ;
-- l = length(uv);
src0.rgb = temp[1] : -- uv
DP3 src0.rg0 src0.rg0 ,
temp[0].a = DP ;
src0.a = temp[0] :
temp[0].a = RSQ |src0.a| ;
src0.a = temp[0] :
temp[0].a = RCP src0.a ;
-- d = l * d;
src0.a = temp[0] , -- l
src1.a = temp[1] : -- d
temp[1].a = MAD src0.a src1.a src0.0 ;
-- d = d * 8.0 + time;
src0.a = temp[1] , -- d
src1.a = float(80) , -- 8.0
src2.rgb = const[0] : -- time (r)
temp[1].a = MAD src0.a src1.a src2.r ;
-- d = 0.125 * sin(d); <OMOD>
-- d = d * 0.159154936671257019043 + 0.5; // 48
src0.a = temp[1] , -- d
src1.rgb = const[1] , -- I_PI_2 (g)
src2.a = float(48) : -- 0.5
temp[1].a = MAD src0.a src1.g src2.a ;
-- d = fract(d);
src0.a = temp[1] : -- d
temp[1].a = FRC src0.a ;
-- d = d - 0.5;
src0.a = temp[1] , -- d
src1.a = float(48) : -- 0.5
temp[1].a = MAD src0.1 src0.a -src1.a ;
-- d = 0.125 * sin(d * PI_2);
src0.a = temp[1] :
temp[1].a = 0.125 * SIN src0.a ;
-- d = 1.0 / abs(d);
src0.a = temp[1] : -- d
temp[1].a = RCP |src0.a|;
-- d = 0.01 * d;
src0.a = temp[1] , -- d
src1.rgb = const[0] : -- 0.01 (b)
temp[1].a = MAD src0.a src1.b src0.0 ;
-- d = pow(d, 1.2);
src0.a = temp[1] : -- d
temp[1].a = LN2 src0.a ;
src0.a = temp[1] ,
src1.rgb = const[0] : -- 1.2 (g)
temp[1].a = MAD src0.a src1.g src0.0 ;
src0.a = temp[1] :
temp[1].a = EX2 src0.a ;
-- final_color = col * d + final_color
src0.rgb = temp[3] , -- col
src1.a = temp[1] , -- d
src2.rgb = temp[2] : -- final_color
temp[2].rgb = MAD src0.rgb src1.aaa src2.rgb ;
-- i = i + 1
src0.a = temp[3] :
temp[3].a = MAD src0.1 src0.a src0.1 ;

View File

@ -1,10 +1,8 @@
import sys
def print_error(e):
def print_error(filename, buf, e):
assert len(e.args) == 2, e
message, token = e.args
with open(token.filename, 'rb') as f:
buf = f.read()
lines = buf.splitlines()
line = lines[token.line - 1]
@ -13,7 +11,7 @@ def print_error(e):
col_pointer = '^' * len(token.lexeme)
RED = "\033[0;31m"
DEFAULT = "\033[0;0m"
print(f'File: "{token.filename}", line {token.line}, column {token.col}\n', file=sys.stderr)
print(f'File: "{filename}", line {token.line}, column {token.col}\n', file=sys.stderr)
sys.stderr.write(' ')
wrote_default = False
for i, c in enumerate(line.decode('utf-8')):

View File

@ -10,8 +10,8 @@ from assembler.fs.validator import validate_instruction
from assembler.fs.emitter import emit_instruction
from assembler.error import print_error
def frontend_inner(filename, buf):
lexer = Lexer(filename, buf, find_keyword, emit_newlines=False, minus_is_token=True)
def frontend_inner(buf):
lexer = Lexer(buf, find_keyword, emit_newlines=False, minus_is_token=True)
tokens = list(lexer.lex_tokens())
parser = Parser(tokens)
for ins_ast in parser.instructions():
@ -22,15 +22,15 @@ def frontend_inner(filename, buf):
def frontend(filename, buf):
try:
yield from frontend_inner(filename, buf)
yield from frontend_inner(buf)
except LexerError as e:
print_error(e)
print_error(filename, buf, e)
raise
except ParserError as e:
print_error(e)
print_error(filename, buf, e)
raise
except ValidatorError as e:
print_error(e)
print_error(filename, buf, e)
raise
if __name__ == "__main__":

View File

@ -17,9 +17,6 @@ def emit_alpha_op(code, alpha_op):
if alpha_op.dest.omask is not None:
US_CMN_INST.ALPHA_OMASK(code, alpha_op.dest.omask.value)
# omod
US_ALU_ALPHA_INST.OMOD(code, alpha_op.omod.value)
# opcode
US_ALU_ALPHA_INST.ALPHA_OP(code, alpha_op.opcode.value)
@ -62,9 +59,6 @@ def emit_rgb_op(code, rgb_op):
if rgb_op.dest.omask is not None:
US_CMN_INST.RGB_OMASK(code, rgb_op.dest.omask.value)
# omod
US_ALU_RGB_INST.OMOD(code, rgb_op.omod.value)
# opcode
US_ALU_RGBA_INST.RGB_OP(code, rgb_op.opcode.value)

View File

@ -110,26 +110,6 @@ class Swizzle(IntEnum):
one = 6
unused = 7
class Omod(IntEnum):
mul_1 = 0
mul_2 = 1
mul_4 = 2
mul_8 = 3
div_2 = 4
div_4 = 5
div_8 = 6
disable = 7
omod_lexemes = OrderedDict([
((b"1", b"0"), Omod.mul_1),
((b"2", b"0"), Omod.mul_2),
((b"4", b"0"), Omod.mul_4),
((b"8", b"0"), Omod.mul_8),
((b"0", b"5"), Omod.div_2),
((b"0", b"25"), Omod.div_4),
((b"0", b"125"), Omod.div_8),
])
@dataclass
class SwizzleSel:
src: SwizzleSelSrc
@ -139,14 +119,12 @@ class SwizzleSel:
@dataclass
class AlphaOperation:
dest: AlphaDest
omod: Omod
opcode: AlphaOp
sels: list[SwizzleSel]
@dataclass
class RGBOperation:
dest: RGBDest
omod: Omod
opcode: RGBOp
sels: list[SwizzleSel]
@ -435,27 +413,14 @@ def validate_instruction_operation_sels(swizzle_sels, is_alpha):
sels.append(SwizzleSel(src, swizzle, mod))
return sels
def validate_omod_operation(operation):
omod = Omod.mul_1
if operation.omod != None:
integer, decimal = operation.omod
key = (integer.lexeme, decimal.lexeme)
if key not in omod_lexemes:
valid_omods = b", ".join(b".".join(key) for key in omod_lexemes.keys()).decode('utf-8')
raise ValidatorError(f"invalid omod, expected one of [{valid_omods}]", integer)
omod = omod_lexemes[key]
return omod
def validate_alpha_instruction_operation(operation):
dest = validate_instruction_operation_dest(operation.dest_addr_swizzles,
mask_lookup=alpha_masks,
type_cls=AlphaDest)
omod = validate_omod_operation(operation)
opcode = alpha_op_kws[operation.opcode_keyword.keyword]
sels = validate_instruction_operation_sels(operation.swizzle_sels, is_alpha=True)
return AlphaOperation(
dest,
omod,
opcode,
sels
)
@ -464,12 +429,10 @@ def validate_rgb_instruction_operation(operation):
dest = validate_instruction_operation_dest(operation.dest_addr_swizzles,
mask_lookup=rgb_masks,
type_cls=RGBDest)
omod = validate_omod_operation(operation)
opcode = rgb_op_kws[operation.opcode_keyword.keyword]
sels = validate_instruction_operation_sels(operation.swizzle_sels, is_alpha=False)
return RGBOperation(
dest,
omod,
opcode,
sels
)

View File

@ -35,7 +35,6 @@ class ALUSwizzleSel:
@dataclass
class ALUOperation:
dest_addr_swizzles: list[DestAddrSwizzle]
omod: tuple[Token, Token]
opcode_keyword: Token
swizzle_sels: list[ALUSwizzleSel]
@ -116,15 +115,6 @@ class Parser(BaseParser):
return token.keyword in opcode_keywords
return False
def alu_is_omod(self):
is_omod = (
self.match(TT.identifier, offset=0)
and self.match(TT.dot, offset=1)
and self.match(TT.identifier, offset=2)
and self.match(TT.star, offset=3)
)
return is_omod
def alu_is_neg(self):
result = self.match(TT.minus)
if result:
@ -164,17 +154,9 @@ class Parser(BaseParser):
def alu_operation(self):
dest_addr_swizzles = []
while not (self.alu_is_opcode() or self.alu_is_omod()):
while not self.alu_is_opcode():
dest_addr_swizzles.append(self.dest_addr_swizzle())
omod = None
if self.alu_is_omod():
omod_integer = self.consume(TT.identifier, "expected omod decimal identifier")
self.consume(TT.dot, "expected omod decimal dot")
omod_decimal = self.consume(TT.identifier, "expected omod decimal identifier")
self.consume(TT.star, "expected omod star")
omod = (omod_integer, omod_decimal)
opcode_keyword = self.consume(TT.keyword, "expected opcode keyword")
swizzle_sels = []
@ -183,7 +165,6 @@ class Parser(BaseParser):
return ALUOperation(
dest_addr_swizzles,
omod,
opcode_keyword,
swizzle_sels
)

View File

@ -2,7 +2,6 @@ from dataclasses import dataclass
from enum import Enum, auto
from itertools import chain
from typing import Union, Any
from os import path
DEBUG = True
@ -22,11 +21,9 @@ class TT(Enum):
bar = auto()
comma = auto()
minus = auto()
star = auto()
@dataclass
class Token:
filename: str
start_ix: int
line: int
col: int
@ -45,10 +42,7 @@ class LexerError(Exception):
pass
class Lexer:
def __init__(self,
filename: str,
buf: memoryview,
find_keyword,
def __init__(self, buf: memoryview, find_keyword,
emit_newlines=False,
minus_is_token=False):
self.start_ix = 0
@ -59,8 +53,6 @@ class Lexer:
self.find_keyword = find_keyword
self.emit_newlines = emit_newlines
self.minus_is_token = minus_is_token
self.filename = filename
self.nested_lexer = None
def at_end_p(self):
return self.current_ix >= len(self.buf)
@ -81,7 +73,7 @@ class Lexer:
return self.buf[self.current_ix]
def pos(self):
return self.filename, self.start_ix, self.line, self.col - (self.current_ix - self.start_ix)
return self.start_ix, self.line, self.col - (self.current_ix - self.start_ix)
def identifier(self):
while not self.at_end_p() and self.peek() in identifier_characters:
@ -92,26 +84,8 @@ class Lexer:
else:
return Token(*self.pos(), TT.identifier, self.lexeme(), None)
def include(self, filename):
dirname = path.dirname(self.filename)
new_filename = path.join(dirname, filename.decode('utf-8'))
with open(new_filename, 'rb') as f:
buf = f.read()
self.nested_lexer = Lexer(new_filename,
buf,
find_keyword=self.find_keyword,
emit_newlines=self.emit_newlines,
minus_is_token=self.minus_is_token)
def lex_token(self):
while True:
if self.nested_lexer is not None:
token = self.nested_lexer.lex_token()
if token.type is TT.eof:
self.nested_lexer = None
else:
return token
self.start_ix = self.current_ix
if self.at_end_p():
@ -138,8 +112,6 @@ class Lexer:
return Token(*self.pos(), TT.semicolon, self.lexeme())
elif c == ord(','):
return Token(*self.pos(), TT.comma, self.lexeme())
elif c == ord('*'):
return Token(*self.pos(), TT.star, self.lexeme())
elif c == ord('-') and self.peek() == ord('-'):
self.advance()
while not self.at_end_p() and self.peek() != ord('\n'):
@ -147,24 +119,8 @@ class Lexer:
elif self.minus_is_token and c == ord('-'):
return Token(*self.pos(), TT.minus, self.lexeme())
elif c == ord('#'):
for c in b"include":
o = self.advance()
if o != c:
token = Token(*self.pos(), None, self.lexeme())
raise LexerError(f"unexpected character at line:{self.line} col:{self.col}, expected `#include`", token)
while self.peek() == ord(' '):
while not self.at_end_p() and self.peek() != ord('\n'):
self.advance()
self.start_ix = self.current_ix
quote = self.advance()
if quote != ord('"'):
token = Token(*self.pos(), None, self.lexeme())
raise LexerError(f"unexpected character at line:{self.line} col:{self.col}, expected `\"`", token)
self.start_ix = self.current_ix
while self.peek() != ord('"'):
self.advance()
filename = self.lexeme()
assert self.advance() == ord('"')
self.include(filename)
elif c == ord(' ') or c == ord('\r') or c == ord('\t'):
pass
elif c == ord('\n'):

View File

@ -22,8 +22,8 @@ class BaseParser:
self.current_ix += 1
return token
def match(self, token_type, offset=0):
token = self.peek(offset)
def match(self, token_type):
token = self.peek()
return token.type == token_type
def match_keyword(self, keyword):

View File

@ -22,8 +22,8 @@ out[0].xz = VE_MAD input[0].-y-_-0-_ temp[0].x_0_ temp[0].y_0_
out[0].yw = VE_MAD input[0]._x_0 temp[0]._x_0 temp[0]._z_1
"""
def frontend_inner(filename, buf):
lexer = Lexer(filename, buf, find_keyword)
def frontend_inner(buf):
lexer = Lexer(buf, find_keyword)
tokens = list(lexer.lex_tokens())
parser = Parser(tokens)
for ins in parser.instructions():
@ -37,15 +37,15 @@ def frontend_inner(filename, buf):
def frontend(filename, buf):
try:
yield from frontend_inner(filename, buf)
yield from frontend_inner(buf)
except ParserError as e:
print_error(e)
print_error(input_filename, buf, e)
raise
except LexerError as e:
print_error(e)
print_error(input_filename, buf, e)
raise
except ValidatorError as e:
print_error(e)
print_error(filename, buf, e)
raise
if __name__ == "__main__":