15bd8deadSopenharmony_ciName 25bd8deadSopenharmony_ci 35bd8deadSopenharmony_ci AMD_transform_feedback4 45bd8deadSopenharmony_ci 55bd8deadSopenharmony_ciName Strings 65bd8deadSopenharmony_ci 75bd8deadSopenharmony_ci GL_AMD_transform_feedback4 85bd8deadSopenharmony_ci 95bd8deadSopenharmony_ciContributors 105bd8deadSopenharmony_ci 115bd8deadSopenharmony_ci Graham Sellers, AMD 125bd8deadSopenharmony_ci Eric Zolnowski, AMD 135bd8deadSopenharmony_ci 145bd8deadSopenharmony_ciContact 155bd8deadSopenharmony_ci 165bd8deadSopenharmony_ci Graham Sellers (graham.sellers 'at' amd.com) 175bd8deadSopenharmony_ci 185bd8deadSopenharmony_ciStatus 195bd8deadSopenharmony_ci 205bd8deadSopenharmony_ci Shipping 215bd8deadSopenharmony_ci 225bd8deadSopenharmony_ciVersion 235bd8deadSopenharmony_ci 245bd8deadSopenharmony_ci Last Modified Date: 31/04/2014 255bd8deadSopenharmony_ci Author Revision: 5 265bd8deadSopenharmony_ci 275bd8deadSopenharmony_ciNumber 285bd8deadSopenharmony_ci 295bd8deadSopenharmony_ci OpenGL Extension #450 305bd8deadSopenharmony_ci 315bd8deadSopenharmony_ciDependencies 325bd8deadSopenharmony_ci 335bd8deadSopenharmony_ci OpenGL 4.0 or ARB_transform_feedback3 is required. 345bd8deadSopenharmony_ci 355bd8deadSopenharmony_ci This extension is written against the OpenGL Specification, Version 4.4 365bd8deadSopenharmony_ci (Core Profile). 375bd8deadSopenharmony_ci 385bd8deadSopenharmony_ci This extension is written against the OpenGL Shading Language (GLSL) 395bd8deadSopenharmony_ci Specification, Version 4.40 405bd8deadSopenharmony_ci 415bd8deadSopenharmony_ciOverview 425bd8deadSopenharmony_ci 435bd8deadSopenharmony_ci Transform feedback is a mechanism to record the output of the vertex, 445bd8deadSopenharmony_ci tessellation evaluation or geometry shader into one or more buffers for 455bd8deadSopenharmony_ci further processing, recursive rendering or read-back by the client. 465bd8deadSopenharmony_ci ARB_transform_feedback3 (and OpenGL 4.0) extended the transform feedback 475bd8deadSopenharmony_ci subsystem to allow multiple streams of primitive information to be 485bd8deadSopenharmony_ci captured. However, it imposed a limitation that the primitive type for all 495bd8deadSopenharmony_ci streams must be POINTS if more than one stream is to be captured. 505bd8deadSopenharmony_ci AMD_transform_feedback3_lines_triangles relaxed that restriction to allow 515bd8deadSopenharmony_ci lines or triangles to be captured, in the case where multiple streams are 525bd8deadSopenharmony_ci to be processed. However, it still required that all streams share the same 535bd8deadSopenharmony_ci primitive type. Additionally, with all current extensions to transform 545bd8deadSopenharmony_ci feedback, only a single primitive stream may be rasterized. 555bd8deadSopenharmony_ci 565bd8deadSopenharmony_ci This extension enhances transform feedback in two significant ways. First, 575bd8deadSopenharmony_ci it allows multiple transform feedback streams to be captured, each with its 585bd8deadSopenharmony_ci own, independent primitve type. Second, it allows any combination of streams 595bd8deadSopenharmony_ci to be rasterized. As an example, this enables the geometry shader to take 605bd8deadSopenharmony_ci a single stream of triangle geometry and emit filled triangles with a 615bd8deadSopenharmony_ci wireframe outline and a point at each vertex, all in a single pass through 625bd8deadSopenharmony_ci the input vertices. Combined with features such those provided by 635bd8deadSopenharmony_ci ARB_viewport_array, layered rendering, shader subroutines and so on, an 645bd8deadSopenharmony_ci application can render several views of its geoemtry, each with a 655bd8deadSopenharmony_ci radically different style, all in a single pass. 665bd8deadSopenharmony_ci 675bd8deadSopenharmony_ciIP Status 685bd8deadSopenharmony_ci 695bd8deadSopenharmony_ci None. 705bd8deadSopenharmony_ci 715bd8deadSopenharmony_ciNew Procedures and Functions 725bd8deadSopenharmony_ci 735bd8deadSopenharmony_ci None. 745bd8deadSopenharmony_ci 755bd8deadSopenharmony_ciNew Tokens 765bd8deadSopenharmony_ci 775bd8deadSopenharmony_ci Accepted by the <pname> parameter of Enablei, Disablei and IsEnabledi: 785bd8deadSopenharmony_ci 795bd8deadSopenharmony_ci STREAM_RASTERIZATION_AMD 0x91A0 805bd8deadSopenharmony_ci 815bd8deadSopenharmony_ciAdditions to Chapter 11 of the OpenGL 4.4 (Core Profile) Specification 825bd8deadSopenharmony_ci(Programmable Vertex Processing) 835bd8deadSopenharmony_ci 845bd8deadSopenharmony_ci Modify subsection 11.3.4.3, "Geometry Shader Vertex Streams": 855bd8deadSopenharmony_ci 865bd8deadSopenharmony_ci Replace the second to last paragraph of the subsection with: 875bd8deadSopenharmony_ci 885bd8deadSopenharmony_ci The primitives emitted to all vertex streams are passed to the transform 895bd8deadSopenharmony_ci feedback stage to be captured and written to buffer objects in the manner 905bd8deadSopenharmony_ci specified by the transform feedback state. The primitives emitted to vertex 915bd8deadSopenharmony_ci streams for which rasterization is enabled are then passed to subsequent 925bd8deadSopenharmony_ci pipeline stages for clipping, rasterization, and subsequent fragment 935bd8deadSopenharmony_ci processing. 945bd8deadSopenharmony_ci 955bd8deadSopenharmony_ci Replace the last paragraph of the subsection with: 965bd8deadSopenharmony_ci 975bd8deadSopenharmony_ci Geometry shaders that emit vertices to multiple vertex streams may 985bd8deadSopenharmony_ci generate a different primitive type on each stream. Any combination of 995bd8deadSopenharmony_ci streams may be rasterized (see Section 3.1). This allows a geometry shader 1005bd8deadSopenharmony_ci to transform a single input vertex stream into multiple primitives of 1015bd8deadSopenharmony_ci different types, all of which may be rasterized. 1025bd8deadSopenharmony_ci 1035bd8deadSopenharmony_ciAdditions to Chapter 14 of the OpenGL 4.4 (Core Profile) Specification 1045bd8deadSopenharmony_ci(Fixed-Function Primitive Assembly and Rasterization) 1055bd8deadSopenharmony_ci 1065bd8deadSopenharmony_ci Modify Section 14.1 "Discarding Primitives Before Rasterization", p. 409: 1075bd8deadSopenharmony_ci 1085bd8deadSopenharmony_ci Primitives sent to any vertex stream (see section 13.2) may be processed 1095bd8deadSopenharmony_ci further. When geometry shaders are disabled, all vertices are considered 1105bd8deadSopenharmony_ci to be emitted to stream zero. 1115bd8deadSopenharmony_ci Primitives can be optionally discarded before rasterization but after 1125bd8deadSopenharmony_ci the optional transform feedback stage (see section 13.2). All primitives 1135bd8deadSopenharmony_ci may be discarded by calling Enable with RASTERIZER_DISCARD. When enabled, 1145bd8deadSopenharmony_ci primitives emitted to any stream are discarded. When enabled, 1155bd8deadSopenharmony_ci RASTERIZER_DISCARD also causes the Clear and ClearBuffer* commands to be 1165bd8deadSopenharmony_ci ignored. When RASTERIZER_DISCARD is disabled, primitives emitted on streams 1175bd8deadSopenharmony_ci for which rasterization is enabled are passed through to the rasterization 1185bd8deadSopenharmony_ci stage to be processed normally. Rasterization for specific streams may be 1195bd8deadSopenharmony_ci enabled by calling Enablei (or disabled by calling Disablei) with the 1205bd8deadSopenharmony_ci constant STREAM_RASTERIZATION_AMD and the index of the selected stream. 1215bd8deadSopenharmony_ci Initially, rasterization is enabled for stream zero and is disabled for all 1225bd8deadSopenharmony_ci other streams. 1235bd8deadSopenharmony_ci If primitives are emitted on more than one stream for which 1245bd8deadSopenharmony_ci rasterization is enabled, the order of rasterization of primitives on 1255bd8deadSopenharmony_ci different streams is undefined. However, it is guaranteed that all 1265bd8deadSopenharmony_ci primitives emitted on a single stream are rasterized in the order in which 1275bd8deadSopenharmony_ci they are generated, and that all primitives generated by a single invocation 1285bd8deadSopenharmony_ci of a geometry shader are rasterized in stream order, starting with the 1295bd8deadSopenharmony_ci lowest numbered stream. 1305bd8deadSopenharmony_ci 1315bd8deadSopenharmony_ciAdditions to Chapter 15 of the OpenGL 4.4 (Core Profile) Specification 1325bd8deadSopenharmony_ci(Programmable Fragment Processing) 1335bd8deadSopenharmony_ci 1345bd8deadSopenharmony_ci Modify Section 15.2, "Shader Execution" 1355bd8deadSopenharmony_ci 1365bd8deadSopenharmony_ci Insert the following paragraph to subsection 15.2.2, "Shader Inputs", 1375bd8deadSopenharmony_ci after the paragraph describing gl_SamplePosition on p. 433: 1385bd8deadSopenharmony_ci 1395bd8deadSopenharmony_ci The built-in read-only variable gl_StreamID contains the index of the 1405bd8deadSopenharmony_ci vertex stream from which the vertices forming the primitive currently being 1415bd8deadSopenharmony_ci rasterized were taken. User defined input varying variables belonging to 1425bd8deadSopenharmony_ci this stream have defined values, whilst all other user defined input 1435bd8deadSopenharmony_ci variables are undefined. When no geometry shader is active, gl_StreamID 1445bd8deadSopenharmony_ci is zero. When a geometry shader is active and writes to multiple output 1455bd8deadSopenharmony_ci vertex streams for which rasterization is enabled, gl_StreamID may range 1465bd8deadSopenharmony_ci from zero to the value of MAX_VERTEX_STREAMS - 1. 1475bd8deadSopenharmony_ci 1485bd8deadSopenharmony_ciModifications to Chapter 4 of the OpenGL Shading Language Specification, 1495bd8deadSopenharmony_ciVersion 4.40 (Variables and Types) 1505bd8deadSopenharmony_ci 1515bd8deadSopenharmony_ci Append to the end of Section 4.4.1 "Input Layout Qualifiers" 1525bd8deadSopenharmony_ci 1535bd8deadSopenharmony_ci The identifier <stream> is used to specify that a fragment shader input 1545bd8deadSopenharmony_ci variable or block is associated with a particular vertex stream (numbered 1555bd8deadSopenharmony_ci beginning with zero). A default stream number may be declared at global 1565bd8deadSopenharmony_ci scope by qualifying interface qualifier out as in this example: 1575bd8deadSopenharmony_ci 1585bd8deadSopenharmony_ci layout (stream = 1) in; 1595bd8deadSopenharmony_ci 1605bd8deadSopenharmony_ci The stream number specified in such a declaration replaces any previous 1615bd8deadSopenharmony_ci default and applies to all subsequent block and variable declarations until 1625bd8deadSopenharmony_ci a new default is established. The initial default stream number is zero. 1635bd8deadSopenharmony_ci 1645bd8deadSopenharmony_ci Each input block or non-block input variable is associated with a 1655bd8deadSopenharmony_ci vertex stream. If the block or variable is declared with the <stream> 1665bd8deadSopenharmony_ci identifier, it is associated with the specified stream; otherwise, it is 1675bd8deadSopenharmony_ci associated with the current default stream. A block member may be declared 1685bd8deadSopenharmony_ci with a stream identifier, but the specified stream must match the stream 1695bd8deadSopenharmony_ci associated with the containing block. One example: 1705bd8deadSopenharmony_ci 1715bd8deadSopenharmony_ci layout (stream = 1) in; // default is now stream 1 1725bd8deadSopenharmony_ci out vec4 var1; // var1 belongs to default stream (1) 1735bd8deadSopenharmony_ci layout (stream = 2) in Block1 { // "Block1" belongs to stream 2 1745bd8deadSopenharmony_ci layout (stream = 2) vec4 var2; // redundant block member stream decl 1755bd8deadSopenharmony_ci layout (stream = 3) vec2 var3; // ILLEGAL (must match block stream) 1765bd8deadSopenharmony_ci vec3 var4; // belongs to stream 2 1775bd8deadSopenharmony_ci }; 1785bd8deadSopenharmony_ci layout (stream = 0) in; // default is now stream 0 1795bd8deadSopenharmony_ci in vec4 var5; // var5 belongs to default stream (0) 1805bd8deadSopenharmony_ci in Block2 { // "Block2" belongs to default stream (0) 1815bd8deadSopenharmony_ci vec4 var6; 1825bd8deadSopenharmony_ci }; 1835bd8deadSopenharmony_ci layout ( stream = 3) in vec4 var7; // var7 belongs to stream 3 1845bd8deadSopenharmony_ci 1855bd8deadSopenharmony_ci Each fragment processed by the fragment shader receives its input 1865bd8deadSopenharmony_ci variables from a specific stream corresponding to the stream upon which the 1875bd8deadSopenharmony_ci source vertices were emitted in the geometry shader. Each invocation of 1885bd8deadSopenharmony_ci the fragment shader processes a fragment belonging to a primitive generated 1895bd8deadSopenharmony_ci from vertices emitted to a single stream. The index of the stream to which 1905bd8deadSopenharmony_ci these vertices belong is available in the built-in variable gl_StreamID 1915bd8deadSopenharmony_ci (see Section 7.1, "Built-in Language Variables"). Only those input variables 1925bd8deadSopenharmony_ci belonging to the current stream have defined values. Reading from a variable 1935bd8deadSopenharmony_ci belonging to any other stream may cause undefined behavior, including 1945bd8deadSopenharmony_ci program termination. 1955bd8deadSopenharmony_ci 1965bd8deadSopenharmony_ciModifications to Chapter 7 of the OpenGL Shading Language Specification, 1975bd8deadSopenharmony_ciVersion 4.40 (Built-in Variables) 1985bd8deadSopenharmony_ci 1995bd8deadSopenharmony_ci Add to the list of built-in variables in the fragment language, sec. 7.1, 2005bd8deadSopenharmony_ci p.122. 2015bd8deadSopenharmony_ci 2025bd8deadSopenharmony_ci in int gl_StreamID; 2035bd8deadSopenharmony_ci 2045bd8deadSopenharmony_ci Insert the following paragraph after the description of gl_SamplePosition 2055bd8deadSopenharmony_ci on p.122: 2065bd8deadSopenharmony_ci 2075bd8deadSopenharmony_ci The input variable gl_StreamID indicates the vertex stream from which 2085bd8deadSopenharmony_ci vertices were taken to generate the primitive to which the current fragment 2095bd8deadSopenharmony_ci belongs. This information may be used to deduce which of the fragment 2105bd8deadSopenharmony_ci shader input variables contain defined values. Reading from input variables 2115bd8deadSopenharmony_ci belonging to a vertex stream other than that indicated by gl_StreamID 2125bd8deadSopenharmony_ci may produce undefined behavior, possibly including application termination. 2135bd8deadSopenharmony_ci 2145bd8deadSopenharmony_ciModifications to Chapter 8 of the OpenGL Shading Language Specification, 2155bd8deadSopenharmony_ciVersion 4.40 (Built-in Functions) 2165bd8deadSopenharmony_ci 2175bd8deadSopenharmony_ci Remove the final paragraph of section 8.15 "Geometry Shader Functions" on 2185bd8deadSopenharmony_ci p.180, which disallows shaders with multiple streams that are not all 2195bd8deadSopenharmony_ci set to POINTS primitive type. 2205bd8deadSopenharmony_ci 2215bd8deadSopenharmony_ciAdditions to the AGL/GLX/WGL Specifications 2225bd8deadSopenharmony_ci 2235bd8deadSopenharmony_ci None. 2245bd8deadSopenharmony_ci 2255bd8deadSopenharmony_ciGLX Protocol 2265bd8deadSopenharmony_ci 2275bd8deadSopenharmony_ci None. 2285bd8deadSopenharmony_ci 2295bd8deadSopenharmony_ciErrors 2305bd8deadSopenharmony_ci 2315bd8deadSopenharmony_ci INVALID_VALUE is generated by Enablei, Disablei and IsEnabledi if <target> 2325bd8deadSopenharmony_ci is STREAM_RASTERIZATION_AMD and <index> is greater than or equal to 2335bd8deadSopenharmony_ci MAX_VERTEX_STREAMS_AMD. 2345bd8deadSopenharmony_ci 2355bd8deadSopenharmony_ciNew State 2365bd8deadSopenharmony_ci 2375bd8deadSopenharmony_ci Append to table 23.9, Rasterization 2385bd8deadSopenharmony_ci 2395bd8deadSopenharmony_ci +---------------------------------------------------+-----------+-------------------+---------------+-----------------------------------------------+-------+ 2405bd8deadSopenharmony_ci | | | Get | Initial | | | 2415bd8deadSopenharmony_ci | Get Value | Type | Command | Value | Description | Sec. | 2425bd8deadSopenharmony_ci +---------------------------------------------------+-----------+-------------------+---------------+-----------------------------------------------+-------+ 2435bd8deadSopenharmony_ci | STREAM_RASTERIZATION_AMD | nxB | GetBoolean | See 14.1 | Per stream rasterizer enable | 14.1 | 2445bd8deadSopenharmony_ci +---------------------------------------------------+-----------+-------------------+---------------+-----------------------------------------------+-------+ 2455bd8deadSopenharmony_ci 2465bd8deadSopenharmony_ciIssues 2475bd8deadSopenharmony_ci 2485bd8deadSopenharmony_ci 1) Why is rasterization order undefined? 2495bd8deadSopenharmony_ci 2505bd8deadSopenharmony_ci DISCUSSION: Implementations typically break large draws into chunks and 2515bd8deadSopenharmony_ci process each separately. Within each chunk, the rasterization order is 2525bd8deadSopenharmony_ci guaranteed. Between chunks, ordering is also guaranteed - everything in 2535bd8deadSopenharmony_ci early chunks is rasterized before later chunks. However, this means 2545bd8deadSopenharmony_ci that primitives emitted to higher numbered streams in early chunks will 2555bd8deadSopenharmony_ci be rasterized before primitives emitted to lower numbered streams in 2565bd8deadSopenharmony_ci later chunks. Because the boundaries between chunks are not necessarily 2575bd8deadSopenharmony_ci in fixed positions, it is not possible to specify where they will be and 2585bd8deadSopenharmony_ci therefore guarantee rasterization order. 2595bd8deadSopenharmony_ci 2605bd8deadSopenharmony_ci 2) Is this still useful then? 2615bd8deadSopenharmony_ci 2625bd8deadSopenharmony_ci RESOLVED: Yes, sure. If rendering is order independent (depth test on, 2635bd8deadSopenharmony_ci blending off for example), or can be guaranteed to not overlap (viewport 2645bd8deadSopenharmony_ci arrays, layered rendering and so on), it makes no difference whether 2655bd8deadSopenharmony_ci rasterization order between streams is guaranteed or not. 2665bd8deadSopenharmony_ci 2675bd8deadSopenharmony_ci 3) What's the need for multiple 'streams' in the fragment shader? 2685bd8deadSopenharmony_ci 2695bd8deadSopenharmony_ci DISCUSSION: In unextended OpenGL, the inputs to the fragment shader are 2705bd8deadSopenharmony_ci derived from the vertices generated on stream 0 in the geometry shader 2715bd8deadSopenharmony_ci (the vertex shader always writes to stream 0). When multiple streams can 2725bd8deadSopenharmony_ci be rasterized, the fragment shader can be invoked as part of a primitive 2735bd8deadSopenharmony_ci on any stream. As each stream can have wildly different outputs in the 2745bd8deadSopenharmony_ci geometry shader, it is really not possible to have only a single set 2755bd8deadSopenharmony_ci of inputs in the fragment shader. Therefore, we expose each stream 2765bd8deadSopenharmony_ci independently. Only those variables written by the geometry shader on the 2775bd8deadSopenharmony_ci stream from which the current primitive was generated will be defined, 2785bd8deadSopenharmony_ci and the others will likely have garbage in them (aliases of the real 2795bd8deadSopenharmony_ci variables). That stream is given by the new gl_StreamID built-in in the 2805bd8deadSopenharmony_ci fragment shader. Other built-in variables (such as gl_FragCoord) are 2815bd8deadSopenharmony_ci always available on any stream. 2825bd8deadSopenharmony_ci 2835bd8deadSopenharmony_ciRevision History 2845bd8deadSopenharmony_ci 2855bd8deadSopenharmony_ci Rev. Date Author Changes 2865bd8deadSopenharmony_ci ---- ---------- -------- ----------------------------------------- 2875bd8deadSopenharmony_ci 5 31/04/2014 gsellers Update for OpenGL 4.4, ready for posting. 2885bd8deadSopenharmony_ci 4 12/03/2012 gsellers Update against OpenGL 4.3. 2895bd8deadSopenharmony_ci 3 05/01/2011 gsellers Assign enumerants 2905bd8deadSopenharmony_ci 2 10/14/2010 gsellers Add fragment shader streams. 2915bd8deadSopenharmony_ci 1 10/11/2010 gsellers Initial revision 292