Simple way to convert GLSL shader to GX2 format ?

Discussion in 'Wii U - Homebrew' started by rioray, Nov 28, 2017.

  1. rioray
    OP

    rioray GBAtemp Regular

    Member
    144
    319
    Jul 24, 2017
    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, Nov 28, 2017 - Reason: fix name
    DarthDub likes this.
  2. CreeperMario

    CreeperMario GBAtemp Advanced Fan

    Member
    642
    384
    Jun 18, 2016
    Australia
    Adelaide, South Australia
    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.
     
    cucholix likes this.
  3. rioray
    OP

    rioray GBAtemp Regular

    Member
    144
    319
    Jul 24, 2017
    France
    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, Nov 29, 2017
  4. cucholix

    cucholix Banners guy

    Member
    1,417
    787
    Jan 17, 2017
    Chile
    You could reach him by twitter
    https://mobile.twitter.com/Aliaspider_
     
  5. rioray
    OP

    rioray GBAtemp Regular

    Member
    144
    319
    Jul 24, 2017
    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
     
  6. QuarkTheAwesome

    QuarkTheAwesome Working for Hugs

    Member
    850
    2,144
    Apr 19, 2015
    Australia
    Stuck in the PowerPC
    Do you know where the problem is? The shader program itself, libgfd, various headers?
     
  7. rioray
    OP

    rioray GBAtemp Regular

    Member
    144
    319
    Jul 24, 2017
    France
    @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

    [​IMG]

    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 !

    [​IMG]

    maybe a part of the problem why it is not working on hardware ?
     
    Last edited by rioray, Nov 29, 2017
  8. CreeperMario

    CreeperMario GBAtemp Advanced Fan

    Member
    642
    384
    Jun 18, 2016
    Australia
    Adelaide, South Australia
    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. :)
     
    rw-r-r_0644 likes this.
  9. rioray
    OP

    rioray GBAtemp Regular

    Member
    144
    319
    Jul 24, 2017
    France
    @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.
     
    CreeperMario likes this.
Loading...