Homebrew Simple way to convert GLSL shader to GX2 format ?

rioray

Well-Known Member
OP
Member
Joined
Jul 24, 2017
Messages
152
Trophies
0
Age
41
XP
381
Country
France
Hi,

In order to compute some shader offline , i would like to know if there is a simple way to convert GLSL to GX2 format for vertex/pixel shader ?
for record, I was able to successfully use libgui shader into retroarch https://github.com/Maschell/libgui/blob/master/source/video/shaders/Texture2DShader.cpp
but if i want to go ahead and implement some libretro glsl shader ( https://github.com/libretro/glsl-shaders ) in retroarch , is there any open free tool that
can help to convert GLSL shader to GX2. I know AMD gpu analyser can transform GLSL to ASM shader , but after we have the asm how can we transform the asm to something compatible with the GPU7 shader like @aliaspider did ?

Code:
/*******************************************************
 *******************************************************
 *
 * Pixel Shader GLSL source:
 *
 *******************************************************
 *******************************************************
 *
 * varying vec2 tex_coord;
 * uniform sampler2D s;
 * void main()
 * {
 *    gl_FragColor = texture2D(s, tex_coord);
 * }
 *
 ******************************************************
 ******************************************************
 *
 * assembly output from AMD's GPU ShaderAnalyzer :
 *
 ******************************************************
 ******************************************************
 *
 * 00 TEX: ADDR(16) CNT(1) VALID_PIX
 *        0  SAMPLE R0, R0.xy0x, t0, s0
 * 01 EXP_DONE: PIX0, R0
 * END_OF_PROGRAM
 *
 *******************************************************
 *******************************************************
 */

__attribute__((aligned(GX2_SHADER_ALIGNMENT)))
static struct
{
   u32 cf[16 * 2]; /* first ADDR() * 2 */
   u32 tex[1 * 3]; /* CNT() sum * 3 */
} ps_program =
{
   {
      TEX(16, 1) VALID_PIX,
      EXP_DONE(PIX0, _R0, _X, _Y, _Z, _W)
      END_OF_PROGRAM
   },
   {
      TEX_SAMPLE(_R0, _X, _Y, _Z, _W, _R0, _X, _Y, _0, _X, _t0, _s0)
   }
};

Any help would be appreciate. I only have an average knowledge of the GLSL shader and all the asm part is above to me.
After dealing with the result GX2VertexShader GX2PixelShader GX2SamplerVar is more in my skills.
 
Last edited by rioray, , Reason: fix name
  • Like
Reactions: JGSHEW and DarthDub

rioray

Well-Known Member
OP
Member
Joined
Jul 24, 2017
Messages
152
Trophies
0
Age
41
XP
381
Country
France
The only public non-SDK tool that allows development of GX2 shader programs is latte-assembler. So far, its shaders work when run in Decaf, but not when run on actual hardware, see here.
Thanks for answering!
that is the tool that @QuarkTheAwesome recommend to me , but i didn't know that it was not working on real hardware !
So there is no real easy open source option for now ? So I have to learn how @aliaspider has converted asm shader to GX2 compatible format like describe here https://github.com/libretro/RetroArch/blob/master/wiiu/gx2_shader_inl.h
it can take years for me
 
Last edited by rioray,

cucholix

00000780 00000438
Member
Joined
Jan 17, 2017
Messages
3,023
Trophies
1
Age
42
XP
5,019
Country
Chile
Thanks for answering!
that is the tool that @QuarkTheAwesome recommend to me , but i didn't know that it was not working on real hardware !
So there is no real easy open source option for now ? So I have to learn how @aliaspider has converted asm shader to GX2 compatible format like describe here https://github.com/libretro/RetroArch/blob/master/wiiu/gx2_shader_inl.h
it can take years for me
You could reach him by twitter
https://mobile.twitter.com/Aliaspider_
 

rioray

Well-Known Member
OP
Member
Joined
Jul 24, 2017
Messages
152
Trophies
0
Age
41
XP
381
Country
France
Thanks for the link , last tweet was put more than 1 years before ,
but honestly i think he don't mind about RA stuff now .
have to learn without him
 

rioray

Well-Known Member
OP
Member
Joined
Jul 24, 2017
Messages
152
Trophies
0
Age
41
XP
381
Country
France
Do you know where the problem is? The shader program itself, libgfd, various headers?
@QuarkTheAwesome @CreeperMario

this part look weird compared to tex_shader.c used in retroarch.
it seem there are some endian bytes swap for this part only in the pixel shader regs (the vertex shader regs doesn't look to be swapped )


Code:
         0x00000001, 0x00000002, 0x14000001, 0x00000000, /* sq_pgm_resources_ps, sq_pgm_exports_ps, spi_ps_in_control_0, spi_ps_in_control_1 */
         0x00000001, /* num_spi_ps_input_cntl */
         { 0x00000100, _x30(0x00000000)}, /* spi_ps_input_cntls @ 32*/
         0x0000000f, 0x00000001, 0x00000010, 0x00000000 /* cb_shader_mask, cb_shader_control, db_shader_control, spi_input_z */
for example for cb_shader_mask, cb_shader_control, db_shader_control, spi_input_z
we have in the gsh :
000F000 00010000 00100000 instead of 0x0000000f 0x00000001 0x00000010

and the size seem also swapped 01000000 instead of 100

ATFkUbE.png


Code:
    {
         0x00000103, 0x00000000, 0x00000000, 0x00000001, /* sq_pgm_resources_vs, vgt_primitiveid_en, spi_vs_out_config, num_spi_vs_out_id */
         { 0xffffff00, _x9(0xffffffff) }, /* spi_vs_out_id @10 */
         0x00000000, 0xfffffffc, 0x00000002, /* pa_cl_vs_out_cntl, sq_vtx_semantic_clear, num_sq_vtx_semantic */
         {
            0x00000000, 0x00000001, _x30(0x000000ff) /* sq_vtx_semantic @32 */
         },
         0x00000000, 0x0000000e, 0x00000010 /* vgt_strmout_buffer_en, vgt_vertex_reuse_block_cntl, vgt_hos_reuse_depth */

the byte order is not swapped for the shader vertex reg !

X0vd9mg.png


maybe a part of the problem why it is not working on hardware ?
 
Last edited by rioray,
D

Deleted User

Guest
this part look weird compared to tex_shader.c used in retroarch.
it seem there are some endian bytes swap for this part only in the pixel shader regs (the vertex shader regs doesn't look to be swapped )
I would encourage you to establish contact with exjam, the current leader of the Decaf and WUT projects, and discuss your ideas with him. It might just be that I'm tired, but I think you're on to something with your research. :)
 
  • Like
Reactions: rw-r-r_0644

rioray

Well-Known Member
OP
Member
Joined
Jul 24, 2017
Messages
152
Trophies
0
Age
41
XP
381
Country
France
I would encourage you to establish contact with exjam, the current leader of the Decaf and WUT projects, and discuss your ideas with him. It might just be that I'm tired, but I think you're on to something with your research. :)
@CreeperMario sorry for the noise , looking at closer and i just realize that it was me who was tired when wrote this :blush:
it's only a shift , so not the cause of the problem.
 
  • Like
Reactions: Deleted User
General chit-chat
Help Users
  • No one is chatting at the moment.
    KenniesNewName @ KenniesNewName: https://www.operanewsapp.com/us/en/share/detail?news_id=3dab7b2419e0a4719ae30b1b4441e20a&news_ent...