1Name 2 3 AMD_vertex_shader_tessellator 4 5Name Strings 6 7 GL_AMD_vertex_shader_tessellator 8 9Contact 10 11 Bill Licea-Kane, AMD ( Bill.Licea-Kane 'at' amd.com ) 12 13Status 14 15 Complete 16 17Version 18 19 Last Modified Date: 2009-03-06 20 Author Revision: 8 21 22Number 23 24 363 25 26Dependencies 27 28 29 OpenGL 2.0 is required. 30 31 EXT_gpu_shader4 affects the definition of this extension. 32 33 EXT_geometry_shader4 affects the definition of this extension. 34 35 This extension interracts with AMDX_vertex_shader_tesselator. 36 37 This extension is written against the OpenGL Shading Language 38 1.20 Specification. 39 40 The extension is written against the OpenGL 2.1 Specification. 41 42Overview 43 44 The vertex shader tessellator gives new flexibility to the shader 45 author to shade at a tessellated vertex, rather than just at a 46 provided vertex. 47 48 In unextended vertex shading, the built-in attributes such as 49 gl_Vertex, gl_Normal, and gl_MultiTexcoord0, together with the 50 user defined attributes, are system provided values which are 51 initialized prior to vertex shader invocation. 52 53 With vertex shading tessellation, additional vertex shader special 54 values are available: 55 56 ivec3 gl_VertexTriangleIndex; // indices of the three control 57 // points for the vertex 58 vec3 gl_BarycentricCoord; // barycentric coordinates 59 // of the vertex 60 61 i o 62 |\ 63 | \ 64 *--* 65 |\ |\ 66 | \| \ 67 *--*--* 68 |\ |\ |\ 69 | \| \| \ 70 j o--*--*--o k 71 72 Figure 1 A Tessellated Triangle 73 o = control point (and tessellated vertex) 74 * = tessellated vertex 75 76 ivec4 gl_VertexQuadIndex; // indices for the four control 77 // points for the vertex 78 vec2 gl_UVCoord; // UV coordinates of the vertex 79 80 i o--*--*--o k 81 |\ |\ |\ | 82 | \| \| \| 83 *--*--*--* 84 |\ |\ |\ | 85 | \| \| \| 86 *--*--*--* 87 |\ |\ |\ | 88 | \| \| \| 89 j o--*--*--o l 90 91 Figure 2 A Tessellated Quad 92 o = control point (and tessellated vertex) 93 * = tessellated vertex 94 95 When this extension is enabled, conventional built-in attributes 96 and user defined attributes are uninitialized. The shader writer 97 is responsible for explicitly fetching all other vertex data either 98 from textures, uniform buffers, or vertex buffers. 99 100 The shader writer is further responsible for interpolating 101 the vertex data at the given barycentric coordinates or uv 102 coordinates of the vertex. 103 104IP Status 105 106 No known claims. 107 108New Procedures and Functions 109 110 void TessellationFactorAMD( float factor ); 111 void TessellationModeAMD( enum mode ); 112 113New Types 114 115 (None.) 116 117New Tokens 118 119 Returned by the <type> parameter of GetActiveUniform: 120 121 SAMPLER_BUFFER_AMD 0x9001 122 INT_SAMPLER_BUFFER_AMD 0x9002 123 UNSIGNED_INT_SAMPLER_BUFFER_AMD 0x9003 124 125 Accepted by TessellationModeAMD 126 127 DISCRETE_AMD 0x9006 128 CONTINUOUS_AMD 0x9007 129 130 Accepted by GetIntegerv 131 132 TESSELLATION_MODE_AMD 0x9004 133 134 Accepted by GetFloatv 135 136 TESSELLATION_FACTOR_AMD 0x9005 137 138Additions to Chapter 2 of the OpenGL 2.1 Specification 139(OpenGL Operation) 140 141 Modify section 2.15.3, "Shader Variables", page 75 142 143 Add the following new return types to the description of 144 GetActiveUniform on p. 81. 145 146 SAMPLER_BUFFER_AMD, 147 INT_SAMPLER_BUFFER_AMD, 148 UNSIGNED_INT_SAMPLER_BUFFER_AMD. 149 150 Replace section "Samplers" p. 83 with: 151 152 Samplers 153 154 Samplers are special uniforms used in the OpenGL Shading Language 155 to identify the texture object or vertex buffer object used for 156 each lookup. 157 158 Samplers and Texture objects 159 160 If the sampler is one of the texture types, the value of a sampler 161 indicates the texture image unit being accessed. Setting a 162 sampler's value to i selects texture image unit number i. The values 163 of i range from zero to the implementation dependent maximum 164 supported number of texture image units. 165 166 The type of the sampler identifies the target on the texture image 167 unit. The texture object bound to that texture image unit's target 168 is then used for the texture lookup. For example, a variable of type 169 sampler2D selects target TEXTURE 2D on its texture image unit. 170 Binding of texture objects to targets is done as usual with 171 BindTexture. Selecting the texture image unit to bind to is done as 172 usual with ActiveTexture. 173 174 It is not allowed to have variables of different sampler types 175 pointing to the same texture image unit within a program object. 176 This situation can only be detected at the next rendering command 177 issued, and an INVALID OPERATION error will then be generated. 178 179 Samplers and vertex buffer objects 180 181 If the sampler is one of the vertex types, the value of a sampler 182 indicates the vertex array being accessed. Setting a sampler's 183 value to i selects vertex array i. The values of i range from zero 184 to the implementation dependent maximum supported max vertex 185 attributes. Binding of vertex buffer objects to vertex arrays is 186 done as usual with BindBuffer. 187 188 It is not allowed to have multiple variables of samplers to the same 189 vertex array within a program object. This situation can only be 190 detected at the next rendering command issued, and an INVALID 191 OPERATION error will then be generated. 192 193 All samplers 194 195 The location of a sampler needs to be queried with 196 GetUniformLocation, just like any uniform variable. Sampler values 197 need to be set by calling Uniform1i{v}. Loading samplers with any 198 of the other Uniform* entry points is not allowed and will result 199 in an INVALID OPERATION error. 200 201 Active samplers are samplers actually being used in a program 202 object. The LinkProgram command determines if a sampler is active or 203 not. The LinkProgram command will attempt to determine if the active 204 samplers in the shader(s) contained in the program object exceed the 205 maximum allowable limits. If it determines that the count of active 206 samplers exceeds the allowable limits, then the link fails (these 207 limits can be different for different types of shaders). Each active 208 sampler variable counts against the limit, even if multiple samplers 209 refer to the same texture image unit. If this cannot be determined 210 at link time, for example if the program object only contains a 211 vertex shader, then it will be determined at the next rendering 212 command issued, and an INVALID OPERATION error will then be 213 generated. 214 215 Insert section prior to "Validation" on p. 87 216 217 Tessellation 218 219 If a vertex shader enables GL_AMD_vertex_shader_tessellation, then 220 the shader writer is responsible for fetching and evaluating the 221 vertex attributes at the barycentric coordinates of the vertex. 222 (See the shading language specification.) 223 224 Only indexed triangles or indexed quads may be drawn with such a 225 shader. Each triangle or quad will introduce generated vertices 226 (including the original vertices of the triangle or quad) 227 controlled by: 228 229 void TessellationFactorAMD( float factor ); 230 231 where the factor is a value between 1.0 and 15.0 inclusive 232 233 The introduction of generated vertices is further controlled by: 234 235 void TessellationModeAMD( enum mode ); 236 237 where mode is either DISCRETE_AMD or CONTINUOUS_AMD. 238 239 Add to the list of "begin errors": 240 241 * any two samplers of vertex type refer to the same vertex array. 242 243 * Any sampler bound to a vertex array has vertex buffer object 0 244 bound. 245 246 * A vertex shader enables GL_AMD_vertex_shader_tessellation, 247 statically reads gl_VertexTriangleIndex or gl_BarycentricCoord 248 and the Implicit Begin mode is NOT GL_TRIANGLES 249 250 * A vertex shader enables GL_AMD_vertex_shader_tessellation, 251 statically reads gl_VertexQuadIndex or gl_UVCoord and 252 the Implicit Begin mode is NOT GL_QUADS 253 254 * A vertex shader enables GL_AMD_vertex_shader_tessellation and 255 the command is RasterPos. 256 257Additions to Chapter 3 of the OpenGL 2.1 Specification (Rasterization) 258 259Additions to Chapter 4 of the OpenGL 2.1 Specification (Per-Fragment 260Operations and the Frame Buffer) 261 262Additions to Chapter 5 of the OpenGL 2.1 Specification 263(Special Functions) 264 265 266Additions to Chapter 6 of the OpenGL 2.1 Specification (State and State 267Requests) 268 269 270Additions to Appendix A of the OpenGL 2.1 Specification (Invariance) 271 272Modifications to The OpenGL Shading Language 1.20 Specification 273 274 Including the following line in a shader can be used to control the 275 language features described in this extension: 276 277 #extension GL_AMD_vertex_shader_tessellator : <behavior> 278 279 where <behavior> is as specified in section 3.3. 280 281 A new preprocessor #define is added to the OpenGL Shading Language: 282 283 #define GL_AMD_vertex_shader_tessellator 1 284 285Additions to Chapter 1 of the OpenGL Shading Language 1.20 Specification 286(Introduction) 287 288Additions to Chapter 2 of the OpenGL Shading Language 1.20 Specification 289(Overview of OpenGL Shading) 290 291 2.1 Vertex Processor 292 293 Change 2nd paragraph to: 294 295 The vertex processor operates on one vertex at a time. It does not 296 replace graphics operations that require knowledge of several 297 vertices at a time. While a tessellated vertex however has LIMITED 298 knowledge of the immediately adjacent control points (three for a 299 triangle, four for a quad), the vertex processor is still operating 300 on one tessellated vertex at a time. The vertex shaders running on 301 the vertex processor must compute the homogeneous position 302 of the incoming vertex. 303 304 305Additions to Chapter 3 of the OpenGL Shading Language 1.20 Specification 306(Basics) 307 308 3.6 Keywords 309 310 Add the keywords 311 312 __samplerVertexAMD 313 __isamplerVertexAMD 314 __usamplerVertexAMD 315 316Additions to Chapter 4 of the OpenGL Shading Language 1.20 Specification 317(Variables and Types) 318 3194.3.4 Attribute, Change third sentence: 320 321 "Attribute values are read-only as far as the vertex shader is 322 concerned, unless GL_AMD_vertex_shader_tessellator is enabled. If 323 GL_AMD_vertex_shader is enabled, they are read-write with undefined 324 initial values." 325 326Additions to Chapter 5 of the OpenGL Shading Language 1.20 Specification 327(Operators and Expressions) 328 329Additions to Chapter 6 of the OpenGL Shading Language 1.20 Specification 330(Statements and Structure) 331 332Additions to Chapter 7 of the OpenGL Shading Language 1.20 Specification 333(Built-in Variables) 334 3357.1 Vertex Shader Special Variables 336 337Add the list of intrinsically declared with the following types: 338 339 // if GL_AMD_vertex_shader_tessellator enabled 340 341 ivec3 gl_VertexTriangleIndex; // may be read 342 // indices of the three control 343 // points for the vertex 344 vec3 gl_BarycentricCoord; // may be read 345 // barycentric coordinates of the 346 // vertex 347 348 ivec4 gl_VertexQuadIndex; // may be read 349 vec2 gl_UVCoord; // may be read 350 351 352 If gl_VertexTriangleIndex and/or gl_BarycentricCoord is statically 353 read by the shader, the shader is a Triangle Tessellator shader. 354 355 If gl_VertexQuadIndex and/or gl_UVCoord is statically read by the 356 shader, the shader is a Quad Tessellator shader. 357 358 It is a link error if both a Triangle Tessellator shader and a Quad 359 Tessellator shader are attached to a program. 360 3617.3 Vertex Shader Built-In Attributes 362 363Add the following paragraph. 364 365 If GL_AMD_vertex_shader_tessellator is enabled, the values of the 366 built-in Attributes are undefined. 367 368Additions to Chapter 8 of the OpenGL Shading Language 1.20 Specification 369(Built-in Functions) 370 3718.7 Texture Lookup Functions 372 373Rename section to "Lookup Functions" 374 375Add in front of first sentence: 376 377 Vertex lookup functions are available to the vertex shader. 378 379Add to the front of the table of functions: 380 381 Syntax: 382 vec4 vertexFetchAMD( __samplerVertexAMD sampler, int i ); 383 ivec4 vertexFetchAMD( __isamplerVertexAMD sampler, int i ); 384 uvec4 vertexFetchAMD( __usamplerVertexAMD sampler, int i ); 385 386 Description: 387 388 If GL_AMD_vertex_shader_tessellator is enabled, fetch the "ith" 389 element from the vertex buffer bound to the vertex array bound to 390 the sampler. 391 392Additions to Chapter 9 of the OpenGL Shading Language 1.20 Specification 393(Shading Language Grammar) 394 395Additions to Chapter 10 of the OpenGL Shading Language 1.20 396Specification (Issues) 397 398Additions to the AGL/EGL/GLX/WGL Specifications 399 400 None 401 402 403Dependencies on ARB_vertex_shader 404 405 ARB_vertex_shader is required. 406 407Interactions with EXT_gpu_shader4 408 409 If EXT_gpu_shader4 is not supported, remove all references to: 410 411 __isamplerVertexAMD 412 __usamplerVertexAMD 413 ivec4 vertexFetchAMD 414 uvec4 vertexFetchAMD 415 416Interactions with EXT_geometry_shader4 417 418 If EXT_geometry_shader4 is supported, change the last 419 paragraph of Section 2.16, Geometry Shaders to: 420 421 A program object that includes a geometry shader must also include 422 a vertex shader; otherwise a link error will occur. If a program 423 object that includes a geometry shader also includes a vertex shader 424 with that has enabled GL_AMD_vertex_shader_tessellator, a link error 425 will occur. 426 427Interactions with AMDX_vertex_shader_tessellator 428 429 This extension is symantically identical to the experimental 430 AMDX_vertex_shader_tessellator. (It has been "promoted" to 431 non-experimental status.) 432 433 Only the prefix AMDX has been changed to AMD. 434 Only the suffix AMDX has been changed to AMD. 435 436 We encourage applications and shader writers to migrate from 437 AMDX to AMD. However, the AMDX entry points, enums, keywords 438 and function names are not yet deprecated. 439 440Errors 441 442New State 443 444Add to Table 6.5 Vertex Array Data 445 446 Get Value Type Get Command Value Description Sec. Attribute 447 --------- ---- --------------- ------- -------------------- ---- --------- 448 TESSELLATION_FACTOR_AMD R GetFloatv 1.0 tessellation factor 2.8 vertex-array 449 TESSELLATION_MODE_AMD Z_2 GetIntegerv DISCRETE_AMD tessellation mode 2.8 vertex-array 450 451New Implementation Dependent State 452 453 None. 454 455Sample Code 456 457#extension GL_AMD_vertex_shader_tessellator : require 458 459__samplerVertexAMD Vertex; 460__samplerVertexAMD Normal; 461__samplerVertexAMD Texcoord0; 462__samplerVertexAMD Temperature; 463__samplerVertexAMD Pressure; 464 465attribute float myTemperature; 466 467void main ( void ) 468{ 469 gl_Vertex = vec4( 0.0 ); 470 gl_Normal = vec4( 0.0 ); 471 gl_MultiTexCoord0 = vec4( 0.0 ); 472 myTemperature = 0.0; 473 float myPressure = 0.0; // Don't have to interpolate to attribute 474 475 for ( int i=0; i<3; i++ ) 476 { 477 float weight = gl_BarycentricCoord[i]; 478 479 gl_Vertex += weight*vertexFetchAMD( Vertex, gl_VertexTriangleIndex[i] ); 480 gl_Normal += weight*vertexFetchAMD( Normal, gl_VertexTriangleIndex[i] ); 481 gl_MultiTexCoord0 += weight*vertexFetchAMD( Texcoord0, gl_VertexTriangleIndex[i] ); 482 myTemperature += weight*vertexFetchAMD( Temperature, gl_VertexTriangleIndex[i] ).x; 483 myPressure += weight*vertexFetchAMD( Pressure, gl_VertexTriangleIndex[i] ).x; 484 485 } 486 // Rest of vertex shader goes here.... 487} 488 489Issues 490 4911) Does this belong conceptually in the pipe as subsuming geometry 492 shader (after primitive combine) or vertex unpack. 493 494 Vertex unpack. Even though there is "primitive information" it 495 is limited to the immediate neighborhood. 496 4972) Do we need a new stage? 498 499 If we add a "tessellation" stage: 500 501 Input to the tessellator is the unpacked vertex attributes, but 502 each attribute is now an array of size 3, the "superprim" attributes, 503 plus a barycentric coordinate. 504 505 The output of the tessellator is the varying. 506 507 The varying output of the tessellator then becomes the attributes 508 input to the vertex shader. 509 510 Alternatively, we can make the "unpack" part of the vertex shader 511 responsibility. 512 513 No. We'll just make the attributes undefined, and the 514 "vertex unpack" stage naturally collapses into the vertex shader. 515 5163) Why make attributes undefined but writable? 517 518 This is the easiest way to have an unpack shader merged into 519 existing shaders. 520 5214) What variants of vertexFetch do we need. 522 523 1D is probably all we need, and probably all we will ever need. 524 The return types should be vec4, ivec4 and uvec4. 525 So, we need: 526 527 vec4 vertexFetchAMD( __samplerVertexAMD sampler, int i ); 528 ivec4 vertexFetchAMD( __isamplerVertexAMD sampler, int i ); 529 uvec4 vertexFetchAMD( __usamplerVertexAMD sampler, int i ); 530 5315) How does __samplerVertexAMD and vertexFetchAMD interact with vertex arrays? 532 533 The __samplerVertexAMD becomes an active uniform. As existing 534 samplers are bound to texture units, the samplerVertex is bound to a 535 VertexAttrib array, and similarly, the "enable" of the 536 VertexAttribArray is ignored. vertexFetchAMD will use the size, 537 type, normalized and stride to fetch the "ith" element from the array 538 as the following pseudocode: 539 540 if (generic vertex attribute j array normalization flag is set, and 541 type is not FLOAT or DOUBLE) 542 VertexAttrib[size]N[type]v 543 (j, generic vertex attribute j array element i); 544 else 545 VertexAttrib[size][type]v 546 (j, generic vertex attribute j array element i); 547 5486) What happens if a buffer object is not bound to an array? 549 550 There is no reason why it shouldn't work, but there's also no good 551 reason to make it work. Undefined. 552 5537) What about "conventional" OpenGL array state (Vertex, Color, Normal, 554 TexCoord, etc....)? 555 556 By binding the buffer objects to the appropriate vertexAttrib array, 557 and setting appropriate size, type, normalized and stride, the 558 application programmer can access all "conventional" OpenGL array 559 state? 560 5618) Are attributes declared or used in the shader "active?" 562 563 For the purposes of GetActiveAttrib, GetAttribLocation and 564 BindAttribLocation, no. 565 5669) What about geometry shaders and tessellation? 567 568 Future hardware may relax this restriction, but you can not 569 successfully link a program that includes a vertex shader that has 570 enabled GL_AMD_vertex_shader_tessellator and a geometry shader. 571 57210) What draw calls do we support? 573 574 To the shader writer, everything looks like indexed triangles or 575 indexed quads, with discrete and continuous tessellation. These 576 indexed triangles result from a polygon Begin/End object, a 577 triangle resulting from a triangle strip, triangle fan, or series 578 of separate triangles, or a quadrilateral arising from a 579 quadrilateral strip, series of separate quadrilaterals, or a Rect 580 command. 581 582 Points, Lines and pixel rectangles and bitmaps are unsupported by 583 a tessellation shader. 584 58511) Do we need additional enables? 586 587 Lets first see how "implicit" enable of vertex arrays and 588 tessellation draw calls works. The first follows precedent (samplers 589 override texture enable hierarchy.) The second seems to follow. 590 59111) What about begin errors? 592 593 They are evil, but I don't see how they can be avoided. 594 Clearly sampler validation needs to follow precedent. 595 59612) What about quads? 597 598 Quads are necessary for subdivision surfaces such as Catmull-Clark. 599 We have received several significant requests to support subdivision 600 surfaces. 601 602Revision History 603 604 Revision 1, 2007-06-26 wwlk 605 Preliminary review document 606 607 Revision 2, 2007-08-16 wwlk 608 Review document 609 610 Correct spelling of "tessellate" throughout. Blush. 611 Rename special variables. 612 Add additional sampler types. 613 Remove "1D" from sampler types and vertex fetches. 614 Add core OpenGL api spec changes. 615 Add interactions with EXT_gpu_shader4. 616 Add many issues. 617 Expanded example shader. 618 619 Revision 3, 2007-08-17 wwlk 620 Correct edit headers 621 (OpenGL 1.5 -> OpenGL 2.0) 622 (Shading Language 1.10 -> Shading Language 1.20) 623 624 Revision 4, 2007-09-21 wwlk 625 Fix typo in reserved keywords (remove "1D") 626 Added support for all polygon calls, explicitly disallowing points 627 lines and RasterPos, 628 List additional BEGIN errors - yes they are evil. 629 630 Revision 5, 2008-05-22 wwlk 631 Add quad support 632 633 Revision 6, 2009-03-05 wwlk 634 General cleanup to ready for posting to repository 635 636 Revision 7, 2009-03-05 wwlk 637 Promote from AMDX to AMD. 638 639 Revision 8, 2009-03-06 wwlk 640 Minor update to enums section. 641 Cleaned up typos and <cr><lf>. 642