From 2aca774dd10d655bdd1d6c626eed44ab9851af3a Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Thu, 23 Oct 2025 13:25:25 -0500 Subject: [PATCH] add verbatim --- verbatim/cube_rotate.vs.asm | 67 +++++++++++++++++++ verbatim/cube_rotate.vs.glsl | 39 +++++++++++ verbatim/cube_rotate_3_temp.vs.asm | 1 + ...agment_shader_equivalent_single_color.glsl | 1 + ...agment_shader_equivalent_vertex_color.glsl | 2 + verbatim/mesa_cube_rotate.vs.asm | 27 ++++++++ verbatim/mesa_glclear.fs.asm | 4 ++ verbatim/mesa_glclear.vs.asm | 2 + verbatim/shadertoy_circle.fs.asm | 21 ++++++ verbatim/shadertoy_palette.fs.asm | 51 ++++++++++++++ verbatim/texture_dual.fs.asm | 17 +++++ verbatim/texture_dual.fs.glsl | 3 + verbatim/vap_prog_stream_vertices.c | 6 ++ verbatim/vap_prog_stream_vertices2.c | 10 +++ ...vertex_shader_equivalent_single_color.glsl | 1 + ...vertex_shader_equivalent_vertex_color.glsl | 2 + 16 files changed, 254 insertions(+) create mode 100644 verbatim/cube_rotate.vs.asm create mode 100644 verbatim/cube_rotate.vs.glsl create mode 100644 verbatim/cube_rotate_3_temp.vs.asm create mode 100644 verbatim/fragment_shader_equivalent_single_color.glsl create mode 100644 verbatim/fragment_shader_equivalent_vertex_color.glsl create mode 100644 verbatim/mesa_cube_rotate.vs.asm create mode 100644 verbatim/mesa_glclear.fs.asm create mode 100644 verbatim/mesa_glclear.vs.asm create mode 100644 verbatim/shadertoy_circle.fs.asm create mode 100644 verbatim/shadertoy_palette.fs.asm create mode 100644 verbatim/texture_dual.fs.asm create mode 100644 verbatim/texture_dual.fs.glsl create mode 100644 verbatim/vap_prog_stream_vertices.c create mode 100644 verbatim/vap_prog_stream_vertices2.c create mode 100644 verbatim/vertex_shader_equivalent_single_color.glsl create mode 100644 verbatim/vertex_shader_equivalent_vertex_color.glsl diff --git a/verbatim/cube_rotate.vs.asm b/verbatim/cube_rotate.vs.asm new file mode 100644 index 0000000..c566614 --- /dev/null +++ b/verbatim/cube_rotate.vs.asm @@ -0,0 +1,67 @@ +-- CONST[0] = {0.159155, 0.5, 6.283185, -3.141593} +-- CONST[1] = {theta1, theta2, 0.2, 0.5} + +-- each instruction is only allowed to use a single unique `const` +-- address +-- +-- instructions may use multiple `temp` addresses, so const[1] is +-- moved to temp[0]: +-- +temp[0].xy = VE_ADD const[1].xy__ const[1].00__ ; + +-- ME_SIN and ME_COS clamp their inputs to [-pi,+pi] prior to the +-- sin/cos calculation. +-- +-- This 3-instruction sequence remaps the range +-- [-inf,+inf] to [-pi,+pi] +temp[0].xy = VE_MAD temp[0].xy__ const[0].xx__ const[0].yy__ ; +temp[0].xy = VE_FRC temp[0].xy__ ; +temp[0].xy = VE_MAD temp[0].xy__ const[0].zz__ const[0].ww__ ; + +-- sin and cos +temp[3].x = ME_SIN temp[0].___x ; +temp[3].y = ME_COS temp[0].___x ; +temp[3].z = ME_SIN temp[0].___y ; +temp[3].w = ME_COS temp[0].___y ; + +-- temp[3] now contains: +-- temp[3] = {sin(theta1), cos(theta1), sin(theta2), cos(theta2)} + +---------------------------------------------------------------------- +-- first rotation: X-axis rotation: +---------------------------------------------------------------------- + +-- y_ = (-z0 * st1) +-- z_ = ( z0 * ct1) +temp[1].yz = VE_MUL input[0]._-zz_ temp[3]._xy_ ; + +-- x1 = (x0 * 1 + 0) +-- y1 = (y0 * ct1 + nz0st1) +-- z1 = (y0 * st1 + z0ct1) +temp[1].xyz = VE_MAD input[0].xyy_ temp[3].1yx_ temp[1].0yz_ ; + +---------------------------------------------------------------------- +-- second rotation: Y-axis rotation: +---------------------------------------------------------------------- + +-- x_ = (-z1 * st2) +-- z_ = ( z1 * ct2) +temp[2].xz = VE_MUL temp[1].-z_z_ temp[3].z_w_ ; + +-- x2 = (x1 * ct2 + nz1st2) +-- y2 = (y1 * 1 + 0) +-- z2 = (x1 * st2 + z1ct2) +temp[2].xyz = VE_MAD temp[1].xyx_ temp[3].w1z_ temp[2].x0z_ ; + +---------------------------------------------------------------------- +-- scale +---------------------------------------------------------------------- + +temp[3].xyz = VE_MAD temp[2].xyz_ const[1].zzz_ const[1].00w_ ; + +---------------------------------------------------------------------- +-- output +---------------------------------------------------------------------- + +out[0].xyzw = VE_MUL temp[3].xyzz temp[3].11-z1 ; +out[1].xyzw = VE_ADD input[1].xyzw input[1].0000 ; diff --git a/verbatim/cube_rotate.vs.glsl b/verbatim/cube_rotate.vs.glsl new file mode 100644 index 0000000..295fb73 --- /dev/null +++ b/verbatim/cube_rotate.vs.glsl @@ -0,0 +1,39 @@ +#version 120 + +attribute vec3 pos; +attribute vec2 tex; + +uniform float theta1; +uniform float theta2; + +vec3 rotate(vec3 v) +{ + float ct1 = cos(theta1); + float st1 = sin(theta1); + + float ct2 = cos(theta2); + float st2 = sin(theta2); + + float x0 = v.x; + float y0 = v.y; + float z0 = v.z; + + float x1 = x0; + float y1 = y0 * ct1 - z0 * st1; + float z1 = y0 * st1 + z0 * ct1; + + float x2 = x1 * ct2 - z1 * st2; + float y2 = y1; + float z2 = x1 * st2 + z1 * ct2; + + return vec3(x2 * 0.2, + y2 * 0.2, + z2 * 0.2 + 0.5); +} + +void main() +{ + vec3 rpos = rotate(pos); + gl_Position = vec4(rpos.xy, -rpos.z * rpos.z, rpos.z); + gl_TexCoord[0] = vec4(tex, 0, 0); +} diff --git a/verbatim/cube_rotate_3_temp.vs.asm b/verbatim/cube_rotate_3_temp.vs.asm new file mode 100644 index 0000000..ab3fe47 --- /dev/null +++ b/verbatim/cube_rotate_3_temp.vs.asm @@ -0,0 +1 @@ +temp[2].xyz = VE_MAD temp[1].xyx_ temp[3].w1z_ temp[2].x0z_ ; diff --git a/verbatim/fragment_shader_equivalent_single_color.glsl b/verbatim/fragment_shader_equivalent_single_color.glsl new file mode 100644 index 0000000..7f48b97 --- /dev/null +++ b/verbatim/fragment_shader_equivalent_single_color.glsl @@ -0,0 +1 @@ +colorbuffer_A = max(vec4(1, 1, 0, 0), vec4(1, 1, 0, 0)); diff --git a/verbatim/fragment_shader_equivalent_vertex_color.glsl b/verbatim/fragment_shader_equivalent_vertex_color.glsl new file mode 100644 index 0000000..10a242f --- /dev/null +++ b/verbatim/fragment_shader_equivalent_vertex_color.glsl @@ -0,0 +1,2 @@ +src0.rgb = temp[0].rgb +colorbuffer_A = max(vec4(src0.rgb, 1), vec4(src0.rgb, 1)) diff --git a/verbatim/mesa_cube_rotate.vs.asm b/verbatim/mesa_cube_rotate.vs.asm new file mode 100644 index 0000000..ab9114a --- /dev/null +++ b/verbatim/mesa_cube_rotate.vs.asm @@ -0,0 +1,27 @@ +temp[0].xyzw = VE_ADD const[2].xyzw const[2].0000 const[2].0000 ; +temp[1].xyzw = VE_ADD const[2].xyzw const[2].0000 const[2].0000 ; +temp[0].x = VE_MAD const[0].x___ temp[1].x___ temp[0].y___ ; +temp[0].x = VE_FRC temp[0].x___ temp[0].0000 temp[0].0000 ; +temp[0].x = VE_MAD temp[0].x___ const[2].z___ const[2].w___ ; +temp[0].y = ME_COS temp[0].xxxx temp[0].0000 temp[0].0000 ; +temp[0].x = ME_SIN temp[0].xxxx temp[0].0000 temp[0].0000 ; +temp[1].xyzw = VE_ADD const[2].xyzw const[2].0000 const[2].0000 ; +temp[2].xyzw = VE_ADD const[2].xyzw const[2].0000 const[2].0000 ; +temp[0].z = VE_MAD const[1].__x_ temp[2].__x_ temp[1].__y_ ; +temp[0].z = VE_FRC temp[0].__z_ temp[0].0000 temp[0].0000 ; +temp[0].z = VE_MAD temp[0].__z_ const[2].__z_ const[2].__w_ ; +temp[0].w = ME_COS temp[0].zzzz temp[0].0000 temp[0].0000 ; +temp[0].z = ME_SIN temp[0].zzzz temp[0].0000 temp[0].0000 ; +temp[1].xy = VE_MUL input[0].yz__ temp[0].xx__ temp[0].0000 ; +temp[0].x = VE_MAD input[0].z___ temp[0].y___ temp[1].x___ ; +temp[1].z = VE_MUL temp[0].__x_ temp[0].__z_ temp[0].0000 ; +temp[1].z = VE_MAD input[0].__x_ temp[0].__w_ temp[1].__-z_ ; +temp[0].y = VE_MAD input[0]._y__ temp[0]._y__ temp[1]._-y__ ; +temp[0].x = VE_MUL temp[0].x___ temp[0].w___ temp[0].0000 ; +temp[0].x = VE_MAD input[0].x___ temp[0].z___ temp[0].x___ ; +temp[2].xyzw = VE_ADD const[2].xyzw const[2].0000 const[2].0000 ; +temp[0].x = VE_MAD temp[0].x___ const[3].x___ temp[2].y___ ; +temp[0].z = VE_MUL temp[0].__x_ temp[0].__x_ temp[0].0000 ; +out[0].xz = VE_MAD temp[1].z_1_ const[3].x_0_ temp[0].0_-z_ ; +out[1].xy = VE_ADD input[1].xy__ input[1].0000 input[1].0000 ; +out[0].yw = VE_MAD temp[0]._y_1 const[3]._x_0 temp[0]._0_x ; diff --git a/verbatim/mesa_glclear.fs.asm b/verbatim/mesa_glclear.fs.asm new file mode 100644 index 0000000..1f0d4d2 --- /dev/null +++ b/verbatim/mesa_glclear.fs.asm @@ -0,0 +1,4 @@ +OUT TEX_SEM_WAIT +src0.a = const[0] : + out[0].a = MAX src0.a src0.a , + out[0].rgb = MAX src0.rgb src0.rgb ; diff --git a/verbatim/mesa_glclear.vs.asm b/verbatim/mesa_glclear.vs.asm new file mode 100644 index 0000000..e0cdbde --- /dev/null +++ b/verbatim/mesa_glclear.vs.asm @@ -0,0 +1,2 @@ +out[0].xyzw = VE_ADD input[0].xyzw input[0].0000 ; +out[1].xyzw = VE_ADD input[1].xyzw input[1].0000 ; diff --git a/verbatim/shadertoy_circle.fs.asm b/verbatim/shadertoy_circle.fs.asm new file mode 100644 index 0000000..b09dfa2 --- /dev/null +++ b/verbatim/shadertoy_circle.fs.asm @@ -0,0 +1,21 @@ +-- d = length(uv) +src0.rgb = temp[0] : + temp[0].r = DP3 src0.rg0 src0.rg0 ; +src0.rgb = temp[0] : + temp[0].a = RSQ |src0.r| ; +src0.a = temp[0] : + temp[0].a = RCP src0.a ; + +-- d = abs(d - 0.5) * 1 + -0.1 +src0.a = float(48), -- 0.5 +src1.a = temp[0], -- d +src2.a = float(29), -- 0.1015625 +srcp.a = sub : -- (src1.a - src0.a) + temp[0].a = MAD |srcp.a| src0.1 -src2.a ; + +-- d = (d >= 0.0) ? 1.0 : 0.0 +-- out.rgba = vec4(d, 0, 0, 1) +OUT TEX_SEM_WAIT +src0.a = temp[0] : + out[0].a = MAX src0.1 src0.1 , + out[0].rgb = CMP src0.100 src0.000 src0.a00 ; diff --git a/verbatim/shadertoy_palette.fs.asm b/verbatim/shadertoy_palette.fs.asm new file mode 100644 index 0000000..841b1fd --- /dev/null +++ b/verbatim/shadertoy_palette.fs.asm @@ -0,0 +1,51 @@ +-- CONST[0] = { time, 0, 0, 0 } +-- CONST[1] = { PI_2, I_PI_2, 0, 0 }, + +-- d = length(uv) +src0.rgb = temp[0] : + temp[0].r = DP3 src0.rg0 src0.rg0 ; +src0.rgb = temp[0] : + temp[0].a = RSQ |src0.r| ; +src0.a = temp[0] : + temp[0].a = RCP src0.a ; + +-- i = vec3(0.25, 0.40625, 0.5625); +-- td = time + d +src0.a = float(40) , -- 0.25 +src1.a = float(45) , -- 0.40625 +src2.rgb = float(49) , -- 0.5625 +src0.rgb = const[0] , +src2.a = temp[0] : + temp[0].rgb = MAD src0.a10 src1.1a0 src2.00r , + temp[1].a = MAD src0.1 src0.r src2.a ; + +-- t = i + vec3(td) +src0.a = temp[1] , +src0.rgb = temp[0] : + temp[0].rgb = MAD src0.111 src0.rgb src0.aaa ; + +-- j = fract(t) +src0.rgb = temp[0] : + temp[0].rgb = FRC src0.rgb ; + +-- k = cos(j * 2pi) +src0.rgb = temp[0] : + COS src0.r , + temp[0].r = SOP ; +src0.rgb = temp[0] : + COS src0.g , + temp[0].g = SOP ; +src0.rgb = temp[0] : + COS src0.b , + temp[0].b = SOP ; + +-- l = k * vec3(0.5, 0.5, 0.5) + vec3(0.5, 0.5, 0.5) +src0.rgb = temp[0] , +src1.rgb = float(48) : -- 0.5 + temp[0].rgb = MAD src0.rgb src1.rrr src1.rrr ; + +OUT TEX_SEM_WAIT +src0.a = temp[0] , +src0.rgb = temp[0] : + out[0].a = MAX src0.1 src0.1 , + out[0].rgb = MAX src0.rgb src0.rgb ; diff --git a/verbatim/texture_dual.fs.asm b/verbatim/texture_dual.fs.asm new file mode 100644 index 0000000..ff10db0 --- /dev/null +++ b/verbatim/texture_dual.fs.asm @@ -0,0 +1,17 @@ +TEX +temp[1].rgba = LD tex[0] temp[0].rgaa ; + +TEX TEX_SEM_ACQUIRE +temp[2].rgba = LD tex[1] temp[0].rgaa ; + +-- (temp[0].rrrr * (temp[2].rgba - temp[1].rgba)) + temp[1].rgba +OUT TEX_SEM_WAIT +src0.a = temp[1], +src1.a = temp[2], +srcp.a = sub, +src0.rgb = temp[1], +src1.rgb = temp[2], +src2.rgb = temp[0], +srcp.rgb = sub : + out[0].a = MAD src2.r srcp.a src0.a , + out[0].rgb = MAD src2.rrr srcp.rgb src0.rgb ; diff --git a/verbatim/texture_dual.fs.glsl b/verbatim/texture_dual.fs.glsl new file mode 100644 index 0000000..837f5e8 --- /dev/null +++ b/verbatim/texture_dual.fs.glsl @@ -0,0 +1,3 @@ +vec4 c1 = texture2D(texture[0], gl_TexCoord[0].xy); +vec4 c2 = texture2D(texture[1], gl_TexCoord[0].xy); +gl_FragColor = mix(c1, c2, gl_TexCoord[0].x); diff --git a/verbatim/vap_prog_stream_vertices.c b/verbatim/vap_prog_stream_vertices.c new file mode 100644 index 0000000..e283ddb --- /dev/null +++ b/verbatim/vap_prog_stream_vertices.c @@ -0,0 +1,6 @@ +const float vertices[] = { + // position // color + 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom right + -0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // bottom left + 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f // top +}; diff --git a/verbatim/vap_prog_stream_vertices2.c b/verbatim/vap_prog_stream_vertices2.c new file mode 100644 index 0000000..acaaba0 --- /dev/null +++ b/verbatim/vap_prog_stream_vertices2.c @@ -0,0 +1,10 @@ +const float vertices[] = { + // position + 0.5f, -0.5f, 0.0f, // bottom right + -0.5f, -0.5f, 0.0f, // bottom left + 0.0f, 0.5f, 0.0f, // top + // color + 1.0f, 0.0f, 0.0f, // bottom right + 0.0f, 1.0f, 0.0f, // bottom left + 0.0f, 0.0f, 1.0f // top +}; diff --git a/verbatim/vertex_shader_equivalent_single_color.glsl b/verbatim/vertex_shader_equivalent_single_color.glsl new file mode 100644 index 0000000..2a3528a --- /dev/null +++ b/verbatim/vertex_shader_equivalent_single_color.glsl @@ -0,0 +1 @@ +out[0] = input[0].xyzw + vec4(0, 0, 0, 0); diff --git a/verbatim/vertex_shader_equivalent_vertex_color.glsl b/verbatim/vertex_shader_equivalent_vertex_color.glsl new file mode 100644 index 0000000..0b041a3 --- /dev/null +++ b/verbatim/vertex_shader_equivalent_vertex_color.glsl @@ -0,0 +1,2 @@ +out[1] = input[1].xyz + vec3(0, 0, 0); +out[0] = vec4(input[0].xyz, 1) + vec4(0, 0, 0, 0);