OpenGL shading language (GLSL) is like a C subset language, but it contains some special features, ex: native vector type & swizzle.<br>In GLSL, you can declare vector types:<br><br>void main()<br>{<br>  vec4 a;<br>  vec3 b;<br>
  vec2 c;<br>}<br><br>You can access the element of vector by using .xyzw, it means the 1st, 2nd, 3rd, 4th element of the vector are x, y, z, w. <br>Ex:<br><br>void main()<br>
{<br>  float f;<br>
  vec4 a = vec4(1.0, 2.0, 3.0, 4.0);<br>  vec4 b = vec4(3.0, 4.0, 5.0, 6.0);<br><br>  v4.xyw = vec2(2.5, 3.3. 7.7);<br>  f = v4.y;<br><br>  b.xy += a.xy;<br>
}<br>
<br>Because my chip supports this facility in instruction & register level, I think I have to preserve the semantic of this 'vector' and 'swizzle'. I don't think this GLSL::vector can be represented directly by the llvm::vector type, because I can just operate on some elements on a GLSL::vector rather than 4 elements all the time. (Am I right about this thought?)<br>
<br>Hence, I think I would need to add some new 'intrinsic' function in LLVM, and use llvm::vector to represent GLSL::vector.<br><br>Ex:<br><br>vec4 a;<br>vec3 b<br>a.xyz = b;<br><br>will be translate to <br><br>llvm::vector<4> a;<br>
llvm::vector<3> b;<br>intrinsic_vector3_to_vector4_assign(a, 0, 1, 2, b);<br><br>Then in the backend, I can see this intrinsic function, and do instruction selections based on this intrinsic. Ex: intrinsic_vector3_to_vector4_assign will be translated to single machine instruction: mov a.xyz, b.xyz.<br>
<br>Am I right on this thought? Does it really needs to add LLVM intrinsic functions to support OpenGL shading language?<br>Or am I missing some really usful mechanism in LLVM to natively support this?<br><br>Comments are welcome.<br>
<br>---<br clear="all">Wei Hu<br><a href="http://www.csie.ntu.edu.tw/~r88052/">http://www.csie.ntu.edu.tw/~r88052/</a><br><a href="http://wei-hu-tw.blogspot.com/">http://wei-hu-tw.blogspot.com/</a><br><br>