Announcement

Collapse
No announcement yet.

need help to understand TGSI

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • need help to understand TGSI

    hi guys, someone can explain me with a code example how to use TGSI for example multiply 2 vectors {vectors = floats like with sse??}

    i have found this documentation http://people.freedesktop.org/~csimp...ocs/index.html
    but not how write the shader code

    the ovbious
    * im good enough in C
    * i know enough of glsl at least for basic coding
    * i know enough assembly X86 to defend myself
    * i already have a working tracker(vdpau that misses idct to render{aka what im trying to code})

    thx in advance

  • #2
    For example see this fragment shader:

    FRAG
    DCL IN[0], GENERIC[0], LINEAR
    DCL IN[1], GENERIC[1], LINEAR
    DCL OUT[0], COLOR
    0: MUL OUT[0], IN[0], IN[1]
    1: END

    IN means a varying (input), OUT is the output (like gl_FragColor). GENERIC[i] is basically like gl_TexCoord[i]. Everything is implicitly a 4D vector and you can use swizzles and masks as you want. The code performs:
    OUT[0].xyzw = IN[0].xyzw * IN[1].xyzw;

    Put it in a file or a string and load it using tgsi_text_translate, then you get the tokens you can pass to the driver (create_fs_state).

    See also these shaders:

    Comment


    • #3
      Originally posted by marek View Post
      For example see this fragment shader:

      FRAG
      DCL IN[0], GENERIC[0], LINEAR
      DCL IN[1], GENERIC[1], LINEAR
      DCL OUT[0], COLOR
      0: MUL OUT[0], IN[0], IN[1]
      1: END

      IN means a varying (input), OUT is the output (like gl_FragColor). GENERIC[i] is basically like gl_TexCoord[i]. Everything is implicitly a 4D vector and you can use swizzles and masks as you want. The code performs:
      OUT[0].xyzw = IN[0].xyzw * IN[1].xyzw;

      Put it in a file or a string and load it using tgsi_text_translate, then you get the tokens you can pass to the driver (create_fs_state).

      See also these shaders:
      http://cgit.freedesktop.org/mesa/mes...ega/asm_util.h
      ok , this make a lot of sense to me XD thx a lot.
      now 3 more questions:
      1. what is ureg_XXXX for then?
      2. how i can get the result back to the program?aka the c code
      3. how i fill IN[x] aka inside the same text or ??

      to be more precise i'am translating the IDCT code using T'MT with matrixes(i dont have the guts to try the butterfly code just yet), so i need to basically multiply 3 matrixes and the result is the IDCT'ed original 8x8 block that ill pass to the motion compesation code(that seeing you example i think that the shader function are dummies and the dude do all the stuff in plain C so at least for now i need to to be able to readback the results )

      a million thx again

      Comment


      • #4
        1. ureg is another way to load shaders, it's an alternative to tgsi_text_translate, basically.

        2. It's a fragment shader so you must set all the states as you would in OpenGL, like shaders, blending, renderbuffers, textures, vertex buffers, etc. Assuming you store the results in a texture, you have to map it (get_transfer) and read it, like you do with VBOs or PBOs in OpenGL.

        3. IN is like a varying variable in GLSL and contains interpolated data from the vertex shader. Other input types are CONST[x..y] (constants from set_constant_buffer, like uniform variables in GLSL), IMM[x..y] (inline constants in the TGSI code), and SAMP[x..y] (samplers, i.e. textures).

        Comment


        • #5
          Originally posted by marek View Post
          1. ureg is another way to load shaders, it's an alternative to tgsi_text_translate, basically.

          2. It's a fragment shader so you must set all the states as you would in OpenGL, like shaders, blending, renderbuffers, textures, vertex buffers, etc. Assuming you store the results in a texture, you have to map it (get_transfer) and read it, like you do with VBOs or PBOs in OpenGL.

          3. IN is like a varying variable in GLSL and contains interpolated data from the vertex shader. Other input types are CONST[x..y] (constants from set_constant_buffer, like uniform variables in GLSL), IMM[x..y] (inline constants in the TGSI code), and SAMP[x..y] (samplers, i.e. textures).
          thx a lot marek ill try that XD

          Comment


          • #6
            ok i advanced a big step in the shader code but i have a little doubt marek.

            my idct code is basically 3 matrixes muliplication, which at the end of the day is only sums and mult of floats values packed in a vec4(like sse __m128), so to reduce processing time i precomputed the all dct coefficients(i assumed that would be very expensive in the gpu since require a lot of div and cos) and loaded in 16 vec4 types, so np so far (this give me some nice speedup in the C-SSE version too btw). now in glsl i can load that data as 16 rgba data packs and call the same name in all the shaders, aka when i map those 16 rgba pacs as a texture i can keep them in the gpu memory for as long as i need(i've readed in a tutorial, i've done some code but i can't say for sure if the data is staying always in memory, in case im wrong XD ), so i figured that doing the same on tgsi i can save myself for a truckload of download to gpu memory and load the coeff data only once and use them as long as macroblocks keep coming from the video huffman parser, so the question is:

            1.) if i name the same const variable (uniform) in all the shader, the compiler assume that and keep using that texture as long as i need without look to ram again?
            2.) i should upload first a shader with all the coeff data and the process in a separate shader calling the same var names i used in the first shader that declared the coeff table?
            3.) i should use ARL(or MOV not sure what it means in tgsi compared to x85 asm) and load the data in the char matrix for that shader? btw how exactly work ARL?
            4.) im absoletely wrong and i should drop dead somewhere? XD

            thx a lot for your help and sorry for bother you this much XD

            Comment


            • #7
              btw this is correct?

              static const char shader1_asm[] =
              "FRAG\n"
              "DCL OUT[0], POSITION\n"
              "DCL OUT2[0], POSITION\n"
              "DCL TEMP[0]\n"
              "DCL CONST[0..3]\n"
              "0: DP4 TEMP[0].x, IN[0], CONST[0]\n"
              "1: DP4 TEMP[0].y, IN[0], CONST[1]\n"
              "2: DP4 TEMP[0].z, IN[0], CONST[2]\n"
              "3: DP4 TEMP[0].w, IN[0], CONST[3]\n"

              this is correct?
              "4: DP4 OUT2[0].x, OUT[0], CONST[0]\n"
              "5: DP4 OUT2[0].y, OUT[0], CONST[1]\n"
              "6: DP4 OUT2[0].z, OUT[0], CONST[2]\n"
              "7: DP4 OUT2[0].w, OUT[0], CONST[3]\n";

              i know it misses some variables and stuff, i just mean the way process the data first calling each component of out since DP4 says dst and not dst.x, etc and second if using out is valid

              Comment

              Working...
              X