Compare commits

...

3 Commits

12 changed files with 1252 additions and 34 deletions

View File

@ -304,18 +304,18 @@ int indirect_buffer(float time)
| SC_SCISSOR0__YS0(0) | SC_SCISSOR0__YS0(0)
); );
T0V(SC_SCISSOR1 T0V(SC_SCISSOR1
, SC_SCISSOR1__XS1(1600 - 1) , SC_SCISSOR1__XS1(800 - 1)
| SC_SCISSOR1__YS1(1200 - 1) | SC_SCISSOR1__YS1(600 - 1)
); );
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// VAP // VAP
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
T0Vf(VAP_VPORT_XSCALE, 800.0f); T0Vf(VAP_VPORT_XSCALE, 400.0f);
T0Vf(VAP_VPORT_XOFFSET, 800.0f); T0Vf(VAP_VPORT_XOFFSET, 400.0f);
T0Vf(VAP_VPORT_YSCALE, -600.0f); T0Vf(VAP_VPORT_YSCALE, -300.0f);
T0Vf(VAP_VPORT_YOFFSET, 600.0f); T0Vf(VAP_VPORT_YOFFSET, 300.0f);
T0Vf(VAP_VPORT_ZSCALE, 0.5f); T0Vf(VAP_VPORT_ZSCALE, 0.5f);
T0Vf(VAP_VPORT_ZOFFSET, 0.5f); T0Vf(VAP_VPORT_ZOFFSET, 0.5f);
@ -409,7 +409,7 @@ int indirect_buffer(float time)
}; };
const int vertex_shader_length = (sizeof (vertex_shader)) / (sizeof (vertex_shader[0])); const int vertex_shader_length = (sizeof (vertex_shader)) / (sizeof (vertex_shader[0]));
assert(vertex_shader_length % 4 == 0); assert(vertex_shader_length % 4 == 0);
printf("vs length %d\n", vertex_shader_length); //printf("vs length %d\n", vertex_shader_length);
T0_ONE_REG(VAP_PVS_VECTOR_DATA_REG_128, vertex_shader_length - 1); T0_ONE_REG(VAP_PVS_VECTOR_DATA_REG_128, vertex_shader_length - 1);
for (int i = 0; i < vertex_shader_length; i++) { for (int i = 0; i < vertex_shader_length; i++) {
@ -449,10 +449,17 @@ int indirect_buffer(float time)
// fragment constants // fragment constants
#define PI (3.14159274101257324219f)
#define PI_2 (PI * 2.0f)
#define I_PI_2 (1.0f / (PI_2))
const float fragment_consts[] = { const float fragment_consts[] = {
time, 0, 0, 0, time, 1.2, 0.01, 0.4,
PI_2, I_PI_2, 0, 0,
0.25, 0.40625, 0.5625, 0,
}; };
int fragment_consts_length = (sizeof (fragment_consts)) / (sizeof (fragment_consts[0])); int fragment_consts_length = (sizeof (fragment_consts)) / (sizeof (fragment_consts[0]));
assert(fragment_consts_length % 4 == 0);
T0V(GA_US_VECTOR_INDEX T0V(GA_US_VECTOR_INDEX
, GA_US_VECTOR_INDEX__INDEX(0) , GA_US_VECTOR_INDEX__INDEX(0)
@ -465,16 +472,16 @@ int indirect_buffer(float time)
// fragment code // fragment code
const uint32_t fragment_shader[] = { const uint32_t fragment_shader[] = {
#include "shadertoy_palette.fs.inc" #include "shadertoy_palette_fractal.fs.inc"
}; };
const int fragment_shader_length = (sizeof (fragment_shader)) / (sizeof (fragment_shader[0])); const int fragment_shader_length = (sizeof (fragment_shader)) / (sizeof (fragment_shader[0]));
assert(fragment_shader_length % 6 == 0); assert(fragment_shader_length % 6 == 0);
printf("fs length %d\n", fragment_shader_length); //printf("fs length %d\n", fragment_shader_length);
const int fragment_shader_instructions = fragment_shader_length / 6; const int fragment_shader_instructions = fragment_shader_length / 6;
printf("fs instructions %d\n", fragment_shader_instructions); //printf("fs instructions %d\n", fragment_shader_instructions);
T0V(US_PIXSIZE T0V(US_PIXSIZE
, US_PIXSIZE__PIX_SIZE(2) // pixel shader stack frame size , US_PIXSIZE__PIX_SIZE(3) // pixel shader stack frame size
); );
T0V(US_CODE_RANGE T0V(US_CODE_RANGE
@ -513,7 +520,7 @@ int indirect_buffer(float time)
-1.0f, 1.0f, 0.0f -1.0f, 1.0f, 0.0f
}; };
const int vertices_length = (sizeof (vertices)) / (sizeof (vertices[0])); const int vertices_length = (sizeof (vertices)) / (sizeof (vertices[0]));
printf("vtx length %d\n", vertices_length); //printf("vtx length %d\n", vertices_length);
T3(_3D_DRAW_IMMD_2, (1 + vertices_length) - 1); T3(_3D_DRAW_IMMD_2, (1 + vertices_length) - 1);
ib[ix++].u32 ib[ix++].u32
= VAP_VF_CNTL__PRIM_TYPE(4) = VAP_VF_CNTL__PRIM_TYPE(4)
@ -708,7 +715,7 @@ int main()
#define D1GRPH_UPDATE__D1GRPH_SURFACE_UPDATE_PENDING (1 << 2) #define D1GRPH_UPDATE__D1GRPH_SURFACE_UPDATE_PENDING (1 << 2)
uint32_t d1crtc_double_buffer_control = rreg(rmmio, D1CRTC_DOUBLE_BUFFER_CONTROL); uint32_t d1crtc_double_buffer_control = rreg(rmmio, D1CRTC_DOUBLE_BUFFER_CONTROL);
printf("D1CRTC_DOUBLE_BUFFER_CONTROL: %08x\n", d1crtc_double_buffer_control); //printf("D1CRTC_DOUBLE_BUFFER_CONTROL: %08x\n", d1crtc_double_buffer_control);
assert(d1crtc_double_buffer_control == (1 << 8)); assert(d1crtc_double_buffer_control == (1 << 8));
// addresses were retrieved from /sys/kernel/debug/radeon_vram_mm // addresses were retrieved from /sys/kernel/debug/radeon_vram_mm

View File

@ -0,0 +1,37 @@
-- CONST[0] = { time, 1.2, 0.01, 0.4 }
-- CONST[1] = { PI_2, I_PI_2, 0, 0 },
-- CONST[2] = { 0.25, 0.40625, 0.5625, 0 },
-- temp[0] : { uv0.xy , _, l }
-- temp[1] : { uv.xy , _, d }
-- temp[2] : final_color.xyzw
-- temp[3] : {col.xyz , i }
-- vec2 uv = uv0; // temp[1]
src0.rgb = temp[0] : -- uv0
temp[1].rg = MAX src0.rg_ src0.rg_ ;
-- vec4 final_color = vec4(0, 0, 0, 1);
:
temp[2].a = MAX src0.1 src0.1 ,
temp[2].rgb = MAX src0.000 src0.000 ;
-- i = 0;
:
temp[3].a = MAX src0.0 src0.0 ;
--------------------------------------------------------------------------------
-- 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
--------------------------------------------------------------------------------
OUT TEX_SEM_WAIT
src0.rgb = temp[2] :
out[0].a = MAX src0.1 src0.1 ,
out[0].rgb = MAX src0.rgb src0.rgb ;

View File

@ -0,0 +1,924 @@
0x00001800,
0x08020000,
0x08020080,
0x00e40720,
0x00000000,
0x00000015,
0x00007800,
0x08020080,
0x08020080,
0x00920490,
0x00c18023,
0x00000025,
0x00004000,
0x08020080,
0x08020080,
0x00000000,
0x00810033,
0x00000000,
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,
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,
0x00c18003,
0x00000005,

View File

@ -0,0 +1,142 @@
-- 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,8 +1,10 @@
import sys import sys
def print_error(filename, buf, e): def print_error(e):
assert len(e.args) == 2, e assert len(e.args) == 2, e
message, token = e.args message, token = e.args
with open(token.filename, 'rb') as f:
buf = f.read()
lines = buf.splitlines() lines = buf.splitlines()
line = lines[token.line - 1] line = lines[token.line - 1]
@ -11,7 +13,7 @@ def print_error(filename, buf, e):
col_pointer = '^' * len(token.lexeme) col_pointer = '^' * len(token.lexeme)
RED = "\033[0;31m" RED = "\033[0;31m"
DEFAULT = "\033[0;0m" DEFAULT = "\033[0;0m"
print(f'File: "{filename}", line {token.line}, column {token.col}\n', file=sys.stderr) print(f'File: "{token.filename}", line {token.line}, column {token.col}\n', file=sys.stderr)
sys.stderr.write(' ') sys.stderr.write(' ')
wrote_default = False wrote_default = False
for i, c in enumerate(line.decode('utf-8')): 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.fs.emitter import emit_instruction
from assembler.error import print_error from assembler.error import print_error
def frontend_inner(buf): def frontend_inner(filename, buf):
lexer = Lexer(buf, find_keyword, emit_newlines=False, minus_is_token=True) lexer = Lexer(filename, buf, find_keyword, emit_newlines=False, minus_is_token=True)
tokens = list(lexer.lex_tokens()) tokens = list(lexer.lex_tokens())
parser = Parser(tokens) parser = Parser(tokens)
for ins_ast in parser.instructions(): for ins_ast in parser.instructions():
@ -22,15 +22,15 @@ def frontend_inner(buf):
def frontend(filename, buf): def frontend(filename, buf):
try: try:
yield from frontend_inner(buf) yield from frontend_inner(filename, buf)
except LexerError as e: except LexerError as e:
print_error(filename, buf, e) print_error(e)
raise raise
except ParserError as e: except ParserError as e:
print_error(filename, buf, e) print_error(e)
raise raise
except ValidatorError as e: except ValidatorError as e:
print_error(filename, buf, e) print_error(e)
raise raise
if __name__ == "__main__": if __name__ == "__main__":

View File

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

View File

@ -110,6 +110,26 @@ class Swizzle(IntEnum):
one = 6 one = 6
unused = 7 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 @dataclass
class SwizzleSel: class SwizzleSel:
src: SwizzleSelSrc src: SwizzleSelSrc
@ -119,12 +139,14 @@ class SwizzleSel:
@dataclass @dataclass
class AlphaOperation: class AlphaOperation:
dest: AlphaDest dest: AlphaDest
omod: Omod
opcode: AlphaOp opcode: AlphaOp
sels: list[SwizzleSel] sels: list[SwizzleSel]
@dataclass @dataclass
class RGBOperation: class RGBOperation:
dest: RGBDest dest: RGBDest
omod: Omod
opcode: RGBOp opcode: RGBOp
sels: list[SwizzleSel] sels: list[SwizzleSel]
@ -413,14 +435,27 @@ def validate_instruction_operation_sels(swizzle_sels, is_alpha):
sels.append(SwizzleSel(src, swizzle, mod)) sels.append(SwizzleSel(src, swizzle, mod))
return sels 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): def validate_alpha_instruction_operation(operation):
dest = validate_instruction_operation_dest(operation.dest_addr_swizzles, dest = validate_instruction_operation_dest(operation.dest_addr_swizzles,
mask_lookup=alpha_masks, mask_lookup=alpha_masks,
type_cls=AlphaDest) type_cls=AlphaDest)
omod = validate_omod_operation(operation)
opcode = alpha_op_kws[operation.opcode_keyword.keyword] opcode = alpha_op_kws[operation.opcode_keyword.keyword]
sels = validate_instruction_operation_sels(operation.swizzle_sels, is_alpha=True) sels = validate_instruction_operation_sels(operation.swizzle_sels, is_alpha=True)
return AlphaOperation( return AlphaOperation(
dest, dest,
omod,
opcode, opcode,
sels sels
) )
@ -429,10 +464,12 @@ def validate_rgb_instruction_operation(operation):
dest = validate_instruction_operation_dest(operation.dest_addr_swizzles, dest = validate_instruction_operation_dest(operation.dest_addr_swizzles,
mask_lookup=rgb_masks, mask_lookup=rgb_masks,
type_cls=RGBDest) type_cls=RGBDest)
omod = validate_omod_operation(operation)
opcode = rgb_op_kws[operation.opcode_keyword.keyword] opcode = rgb_op_kws[operation.opcode_keyword.keyword]
sels = validate_instruction_operation_sels(operation.swizzle_sels, is_alpha=False) sels = validate_instruction_operation_sels(operation.swizzle_sels, is_alpha=False)
return RGBOperation( return RGBOperation(
dest, dest,
omod,
opcode, opcode,
sels sels
) )

View File

@ -35,6 +35,7 @@ class ALUSwizzleSel:
@dataclass @dataclass
class ALUOperation: class ALUOperation:
dest_addr_swizzles: list[DestAddrSwizzle] dest_addr_swizzles: list[DestAddrSwizzle]
omod: tuple[Token, Token]
opcode_keyword: Token opcode_keyword: Token
swizzle_sels: list[ALUSwizzleSel] swizzle_sels: list[ALUSwizzleSel]
@ -115,6 +116,15 @@ class Parser(BaseParser):
return token.keyword in opcode_keywords return token.keyword in opcode_keywords
return False 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): def alu_is_neg(self):
result = self.match(TT.minus) result = self.match(TT.minus)
if result: if result:
@ -154,9 +164,17 @@ class Parser(BaseParser):
def alu_operation(self): def alu_operation(self):
dest_addr_swizzles = [] dest_addr_swizzles = []
while not self.alu_is_opcode(): while not (self.alu_is_opcode() or self.alu_is_omod()):
dest_addr_swizzles.append(self.dest_addr_swizzle()) 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") opcode_keyword = self.consume(TT.keyword, "expected opcode keyword")
swizzle_sels = [] swizzle_sels = []
@ -165,6 +183,7 @@ class Parser(BaseParser):
return ALUOperation( return ALUOperation(
dest_addr_swizzles, dest_addr_swizzles,
omod,
opcode_keyword, opcode_keyword,
swizzle_sels swizzle_sels
) )

View File

@ -2,6 +2,7 @@ from dataclasses import dataclass
from enum import Enum, auto from enum import Enum, auto
from itertools import chain from itertools import chain
from typing import Union, Any from typing import Union, Any
from os import path
DEBUG = True DEBUG = True
@ -21,9 +22,11 @@ class TT(Enum):
bar = auto() bar = auto()
comma = auto() comma = auto()
minus = auto() minus = auto()
star = auto()
@dataclass @dataclass
class Token: class Token:
filename: str
start_ix: int start_ix: int
line: int line: int
col: int col: int
@ -42,7 +45,10 @@ class LexerError(Exception):
pass pass
class Lexer: class Lexer:
def __init__(self, buf: memoryview, find_keyword, def __init__(self,
filename: str,
buf: memoryview,
find_keyword,
emit_newlines=False, emit_newlines=False,
minus_is_token=False): minus_is_token=False):
self.start_ix = 0 self.start_ix = 0
@ -53,6 +59,8 @@ class Lexer:
self.find_keyword = find_keyword self.find_keyword = find_keyword
self.emit_newlines = emit_newlines self.emit_newlines = emit_newlines
self.minus_is_token = minus_is_token self.minus_is_token = minus_is_token
self.filename = filename
self.nested_lexer = None
def at_end_p(self): def at_end_p(self):
return self.current_ix >= len(self.buf) return self.current_ix >= len(self.buf)
@ -73,7 +81,7 @@ class Lexer:
return self.buf[self.current_ix] return self.buf[self.current_ix]
def pos(self): def pos(self):
return self.start_ix, self.line, self.col - (self.current_ix - self.start_ix) return self.filename, self.start_ix, self.line, self.col - (self.current_ix - self.start_ix)
def identifier(self): def identifier(self):
while not self.at_end_p() and self.peek() in identifier_characters: while not self.at_end_p() and self.peek() in identifier_characters:
@ -84,8 +92,26 @@ class Lexer:
else: else:
return Token(*self.pos(), TT.identifier, self.lexeme(), None) 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): def lex_token(self):
while True: 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 self.start_ix = self.current_ix
if self.at_end_p(): if self.at_end_p():
@ -112,6 +138,8 @@ class Lexer:
return Token(*self.pos(), TT.semicolon, self.lexeme()) return Token(*self.pos(), TT.semicolon, self.lexeme())
elif c == ord(','): elif c == ord(','):
return Token(*self.pos(), TT.comma, self.lexeme()) 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('-'): elif c == ord('-') and self.peek() == ord('-'):
self.advance() self.advance()
while not self.at_end_p() and self.peek() != ord('\n'): while not self.at_end_p() and self.peek() != ord('\n'):
@ -119,8 +147,24 @@ class Lexer:
elif self.minus_is_token and c == ord('-'): elif self.minus_is_token and c == ord('-'):
return Token(*self.pos(), TT.minus, self.lexeme()) return Token(*self.pos(), TT.minus, self.lexeme())
elif c == ord('#'): elif c == ord('#'):
while not self.at_end_p() and self.peek() != ord('\n'): 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(' '):
self.advance() 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'): elif c == ord(' ') or c == ord('\r') or c == ord('\t'):
pass pass
elif c == ord('\n'): elif c == ord('\n'):

View File

@ -22,8 +22,8 @@ class BaseParser:
self.current_ix += 1 self.current_ix += 1
return token return token
def match(self, token_type): def match(self, token_type, offset=0):
token = self.peek() token = self.peek(offset)
return token.type == token_type return token.type == token_type
def match_keyword(self, keyword): 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 out[0].yw = VE_MAD input[0]._x_0 temp[0]._x_0 temp[0]._z_1
""" """
def frontend_inner(buf): def frontend_inner(filename, buf):
lexer = Lexer(buf, find_keyword) lexer = Lexer(filename, buf, find_keyword)
tokens = list(lexer.lex_tokens()) tokens = list(lexer.lex_tokens())
parser = Parser(tokens) parser = Parser(tokens)
for ins in parser.instructions(): for ins in parser.instructions():
@ -37,15 +37,15 @@ def frontend_inner(buf):
def frontend(filename, buf): def frontend(filename, buf):
try: try:
yield from frontend_inner(buf) yield from frontend_inner(filename, buf)
except ParserError as e: except ParserError as e:
print_error(input_filename, buf, e) print_error(e)
raise raise
except LexerError as e: except LexerError as e:
print_error(input_filename, buf, e) print_error(e)
raise raise
except ValidatorError as e: except ValidatorError as e:
print_error(filename, buf, e) print_error(e)
raise raise
if __name__ == "__main__": if __name__ == "__main__":