15bd8deadSopenharmony_ciName 25bd8deadSopenharmony_ci INTEL_map_texture 35bd8deadSopenharmony_ci 45bd8deadSopenharmony_ciName Strings 55bd8deadSopenharmony_ci GL_INTEL_map_texture 65bd8deadSopenharmony_ci 75bd8deadSopenharmony_ciContact 85bd8deadSopenharmony_ci Slawomir Grajewski, INTEL (slawomir.grajewski 'at' intel.com) 95bd8deadSopenharmony_ci 105bd8deadSopenharmony_ciContributors 115bd8deadSopenharmony_ci Jan Paul van Waveren, id Software 125bd8deadSopenharmony_ci Kamil Patelczyk, INTEL 135bd8deadSopenharmony_ci Aneta Roztkowska, INTEL 145bd8deadSopenharmony_ci Piotr Uminski, INTEL 155bd8deadSopenharmony_ci 165bd8deadSopenharmony_ciStatus 175bd8deadSopenharmony_ci Draft. 185bd8deadSopenharmony_ci 195bd8deadSopenharmony_ciVersion 205bd8deadSopenharmony_ci Last Modified Date: June 5, 2012 215bd8deadSopenharmony_ci Author Revision: 1 225bd8deadSopenharmony_ci 235bd8deadSopenharmony_ciNumber 245bd8deadSopenharmony_ci 255bd8deadSopenharmony_ci 429 265bd8deadSopenharmony_ci 275bd8deadSopenharmony_ciDependencies 285bd8deadSopenharmony_ci OpenGL 3.0 is required. 295bd8deadSopenharmony_ci 305bd8deadSopenharmony_ci This extension is written against the OpenGL 4.2 Specification 315bd8deadSopenharmony_ci compatibility profile. 325bd8deadSopenharmony_ci 335bd8deadSopenharmony_ciOverview 345bd8deadSopenharmony_ci Systems with integrated GPUs can share the same physical memory between CPU 355bd8deadSopenharmony_ci and GPU. This feature, if exposed by API, can bring significant performance 365bd8deadSopenharmony_ci benefits for graphics applications by reducing the complexity of 375bd8deadSopenharmony_ci uploading/accessing texture contents. This extension enables CPU direct 385bd8deadSopenharmony_ci access to the GPU memory holding textures. 395bd8deadSopenharmony_ci 405bd8deadSopenharmony_ci The problem with texture memory directly exposed to clients is that 415bd8deadSopenharmony_ci textures are often 'tiled'. Texels are kept in specific layout to improve 425bd8deadSopenharmony_ci locality of reference and thus performance of texturing. This 'tiling' 435bd8deadSopenharmony_ci is specific to particular hardware and would be thus difficult to use. 445bd8deadSopenharmony_ci 455bd8deadSopenharmony_ci This extension allows to create textures with 'linear' layout which allows 465bd8deadSopenharmony_ci for simplified access on user side (potentially sacrificing some 475bd8deadSopenharmony_ci performance during texture sampling). 485bd8deadSopenharmony_ci 495bd8deadSopenharmony_ciNew Procedures and Functions 505bd8deadSopenharmony_ci 515bd8deadSopenharmony_ci void* MapTexture2DINTEL(uint texture, int level, bitfield access, 525bd8deadSopenharmony_ci int *stride, enum *layout); 535bd8deadSopenharmony_ci 545bd8deadSopenharmony_ci void UnmapTexture2DINTEL(uint texture, int level); 555bd8deadSopenharmony_ci 565bd8deadSopenharmony_ci void SyncTextureINTEL(uint texture); 575bd8deadSopenharmony_ci 585bd8deadSopenharmony_ci 595bd8deadSopenharmony_ciNew Tokens 605bd8deadSopenharmony_ci 615bd8deadSopenharmony_ci Accepted by the <pname> parameter of TexParameteri, for target TEXTURE_2D 625bd8deadSopenharmony_ci 635bd8deadSopenharmony_ci TEXTURE_MEMORY_LAYOUT_INTEL 0x83FF 645bd8deadSopenharmony_ci 655bd8deadSopenharmony_ci Accepted by the <params> when <pname> is set to 665bd8deadSopenharmony_ci <TEXTURE_MEMORY_LAYOUT_INTEL>: 675bd8deadSopenharmony_ci 685bd8deadSopenharmony_ci LAYOUT_DEFAULT_INTEL 0 695bd8deadSopenharmony_ci LAYOUT_LINEAR_INTEL 1 705bd8deadSopenharmony_ci LAYOUT_LINEAR_CPU_CACHED_INTEL 2 715bd8deadSopenharmony_ci 725bd8deadSopenharmony_ciAdditions to Chapter 3.10.8 of the OpenGL 4.2 (Compatibility Profile) 735bd8deadSopenharmony_ciSpecification 745bd8deadSopenharmony_ci 755bd8deadSopenharmony_ciAdd a row to the table 3.22 765bd8deadSopenharmony_ci 775bd8deadSopenharmony_ci Name: 785bd8deadSopenharmony_ci TEXTURE_MEMORY_LAYOUT_INTEL 795bd8deadSopenharmony_ci 805bd8deadSopenharmony_ci Type: 815bd8deadSopenharmony_ci enum 825bd8deadSopenharmony_ci 835bd8deadSopenharmony_ci Legal Values: 845bd8deadSopenharmony_ci LAYOUT_DEFAULT_INTEL 855bd8deadSopenharmony_ci LAYOUT_LINEAR_INTEL 865bd8deadSopenharmony_ci LAYOUT_LINEAR_CPU_CACHED_INTEL 875bd8deadSopenharmony_ci 885bd8deadSopenharmony_ciAdd a paragraph in the end of the section: 895bd8deadSopenharmony_ci 905bd8deadSopenharmony_ci When <pname> is TEXTURE_MEMORY_LAYOUT_INTEL and <params> is 915bd8deadSopenharmony_ci LAYOUT_LINEAR_INTEL the texture is forced to be allocated as linear and can 925bd8deadSopenharmony_ci be mapped directly to the CPU address space by MapTexture2DINTEL (see section 935bd8deadSopenharmony_ci 3.10.4). 945bd8deadSopenharmony_ci 955bd8deadSopenharmony_ci When <pname> is TEXTURE_MEMORY_LAYOUT_INTEL and <params> is 965bd8deadSopenharmony_ci LAYOUT_LINEAR_CPU_CACHED_INTEL the behavior is the same as in case of 975bd8deadSopenharmony_ci <params> set to LAYOUT_LINEAR_INTEL with an exception that texture is 985bd8deadSopenharmony_ci cached for CPU accesses. This can result in better performance when reading 995bd8deadSopenharmony_ci texture on CPU but might negatively impact the GPU side access to the 1005bd8deadSopenharmony_ci texture. Thus the option is intended only for cases when volume of the read 1015bd8deadSopenharmony_ci access from CPU justifies such effect. 1025bd8deadSopenharmony_ci 1035bd8deadSopenharmony_ci Only when <pname> is TEXTURE_MEMORY_LAYOUT_INTEL or 1045bd8deadSopenharmony_ci LAYOUT_LINEAR_CPU_CACHED_INTEL, MapTexture2DINTEL returns CPU accessible 1055bd8deadSopenharmony_ci pointer. 1065bd8deadSopenharmony_ci 1075bd8deadSopenharmony_ci The allocation of the texture can be reverted to the default, 1085bd8deadSopenharmony_ci implementation-specific format, including tiled formats, by calling 1095bd8deadSopenharmony_ci TexParameteri with <pname> set to TEXTURE_MEMORY_LAYOUT_INTEL and <params> 1105bd8deadSopenharmony_ci set to LAYOUT_DEFAULT_INTEL. The configured texture layout is ignored until 1115bd8deadSopenharmony_ci the texture is allocated or reallocated using TexImage2D function. 1125bd8deadSopenharmony_ci 1135bd8deadSopenharmony_ci The error INVALID_VALUE is generated when <pname> is 1145bd8deadSopenharmony_ci TEXTURE_MEMORY_LAYOUT_INTEL and the texture target is not TEXTURE_2D. 1155bd8deadSopenharmony_ci 1165bd8deadSopenharmony_ciAdditions to Chapter 3.10.4 of the OpenGL 4.2 (Compatibility Profile) Specification 1175bd8deadSopenharmony_ci 1185bd8deadSopenharmony_ci The command 1195bd8deadSopenharmony_ci 1205bd8deadSopenharmony_ci void* MapTexture2DINTEL(uint texture, int level, bitfield access, 1215bd8deadSopenharmony_ci int *stride, enum *layout); 1225bd8deadSopenharmony_ci 1235bd8deadSopenharmony_ci attempts to return a direct pointer to the graphics storage for 2D texture 1245bd8deadSopenharmony_ci indicated by the <texture> parameter. 1255bd8deadSopenharmony_ci 1265bd8deadSopenharmony_ci The <level> parameter indicates the mipmap level-of-detail of the texture 1275bd8deadSopenharmony_ci for which pointer is requested. 1285bd8deadSopenharmony_ci 1295bd8deadSopenharmony_ci The <access> bitfield indicates type of access that will be performed by 1305bd8deadSopenharmony_ci the application on the memory accessed via the returned pointer: reading - 1315bd8deadSopenharmony_ci MAP_READ_BIT, writing - MAP_WRITE_BIT. Performing access on mapped memory 1325bd8deadSopenharmony_ci different then specified in <access> is undefined (and may result in 1335bd8deadSopenharmony_ci application termination). 1345bd8deadSopenharmony_ci 1355bd8deadSopenharmony_ci If the operation is successful, the function returns a valid pointer, 1365bd8deadSopenharmony_ci otherwise NULL is returned. Upon successful completion, the function also 1375bd8deadSopenharmony_ci returns 'stride', which is the distance in bytes between subsequent rows in the 1385bd8deadSopenharmony_ci texture, and <layout>, indicating the internal layout of the texture in the 1395bd8deadSopenharmony_ci graphics memory. 1405bd8deadSopenharmony_ci 1415bd8deadSopenharmony_ci When texture uses linear memory layout, subsequent texels in a row of the 1425bd8deadSopenharmony_ci image are occupying subsequent addresses in memory. Subsequent rows of 1435bd8deadSopenharmony_ci image are located at 'stride' bytes distance within each other. For tiled 1445bd8deadSopenharmony_ci layout, the relationship between texels and addresses in memory is 1455bd8deadSopenharmony_ci different and will not be further discussed in this extension. 1465bd8deadSopenharmony_ci 1475bd8deadSopenharmony_ci The layout of the texture, discussed in the preceding section, is returned 1485bd8deadSopenharmony_ci via <layout> parameter. In this version of the extension, the only texture 1495bd8deadSopenharmony_ci memory layout that can be returned is LAYOUT_LINEAR_INTEL or 1505bd8deadSopenharmony_ci LAYOUT_LINEAR_CPU_CACHED_INTEL. 1515bd8deadSopenharmony_ci 1525bd8deadSopenharmony_ci All of the following conditions need to be met for the operation to succeed: 1535bd8deadSopenharmony_ci - <texture> is a texture first bound to TEXTURE_2D target 1545bd8deadSopenharmony_ci - <texture> has sized color internal format (see section 3.10.3) 1555bd8deadSopenharmony_ci - texture parameter TEXTURE_MEMORY_LAYOUT_INTEL was either 1565bd8deadSopenharmony_ci LAYOUT_LINEAR_INTEL or LAYOUT_LINEAR_CPU_CACHED_INTEL during texture 1575bd8deadSopenharmony_ci image specification 1585bd8deadSopenharmony_ci - <level> texture mipmap level is defined 1595bd8deadSopenharmony_ci - texture border of <texture> is zero 1605bd8deadSopenharmony_ci Otherwise MapTexture2DINTEL fails with INVALID_OPERATION error, and return 1615bd8deadSopenharmony_ci NULL. 1625bd8deadSopenharmony_ci 1635bd8deadSopenharmony_ci Please note that texture allocated as linear is noticeably slower than 1645bd8deadSopenharmony_ci tiled when accessed by the GPU, however in many scenarios direct access to 1655bd8deadSopenharmony_ci such texture from CPU is more important than slower GPU access, especially 1665bd8deadSopenharmony_ci when texture is frequently updated with limited number of accesses from 1675bd8deadSopenharmony_ci GPU. 1685bd8deadSopenharmony_ci 1695bd8deadSopenharmony_ci The command MapTexture2DINTEL can return valid pointer only if given 1705bd8deadSopenharmony_ci internalformat as specified by TexImage2D() is sized (as indicated in 1715bd8deadSopenharmony_ci tables 16 and 17) and natively supported by the GPU hardware. This means 1725bd8deadSopenharmony_ci that there has to be 1:1 match between internalformat and underlying 1735bd8deadSopenharmony_ci hardware format with respect to the number of components, their sizes and 1745bd8deadSopenharmony_ci order in graphics memory. 1755bd8deadSopenharmony_ci 1765bd8deadSopenharmony_ci It is an error to attempt to map texture that is defined inconsistently (one 1775bd8deadSopenharmony_ci which doesn't provide mipmap levels with the same internal format or with 1785bd8deadSopenharmony_ci sizes not being half the previous level) or to redefine texture levels 1795bd8deadSopenharmony_ci (through TexImage2D, CopyTexImage2D) when texture mappings exist for this 1805bd8deadSopenharmony_ci texture. These cases will result in undefined behavior. 1815bd8deadSopenharmony_ci 1825bd8deadSopenharmony_ci The command 1835bd8deadSopenharmony_ci 1845bd8deadSopenharmony_ci void UnmapTexture2DINTEL(uint texture, int level); 1855bd8deadSopenharmony_ci 1865bd8deadSopenharmony_ci releases the pointer obtained previously via MapTexture2DINTEL. This means 1875bd8deadSopenharmony_ci that virtual memory space dedicated to make the texture available via 1885bd8deadSopenharmony_ci a pointer is released and an application can no longer assume this memory 1895bd8deadSopenharmony_ci is accessible from CPU. Successful execution of this command has an additional 1905bd8deadSopenharmony_ci effect as if SyncTextureINTEL was called with <texture> parameter. 1915bd8deadSopenharmony_ci 1925bd8deadSopenharmony_ci The command 1935bd8deadSopenharmony_ci 1945bd8deadSopenharmony_ci void SyncTextureINTEL(uint texture); 1955bd8deadSopenharmony_ci 1965bd8deadSopenharmony_ci makes sure that changes made by CPU are visible to GPU by flushing texture 1975bd8deadSopenharmony_ci cache in GPU. The GL implementation tracks the cache usage and ignores the 1985bd8deadSopenharmony_ci command if such flush is not needed. 1995bd8deadSopenharmony_ci 2005bd8deadSopenharmony_ci It is worth noting that this extension does not address automatic 2015bd8deadSopenharmony_ci synchronization between CPU and GPU when both entities operate on the same 2025bd8deadSopenharmony_ci texture at the same time. This is up to the application to assure such 2035bd8deadSopenharmony_ci synchronization. Otherwise, the results may not be deterministic (writes 2045bd8deadSopenharmony_ci from different entities may interleave in a non-deterministic way). 2055bd8deadSopenharmony_ci 2065bd8deadSopenharmony_ciModifications to the OpenGL Shading Language Specification. 2075bd8deadSopenharmony_ci 2085bd8deadSopenharmony_ci None. 2095bd8deadSopenharmony_ci 2105bd8deadSopenharmony_ciErrors 2115bd8deadSopenharmony_ci 2125bd8deadSopenharmony_ci INVALID_OPERATION is generated by MapTexture2DINTEL when <texture> is 0 or 2135bd8deadSopenharmony_ci not a name of texture object first bound to TEXTURE_2D target, when <level> 2145bd8deadSopenharmony_ci of <texture> is already mapped, when <texture> storage was allocated with 2155bd8deadSopenharmony_ci TEXTURE_MEMORY_LAYOUT_INTEL different then LAYOUT_LINEAR_INTEL or 2165bd8deadSopenharmony_ci LAYOUT_LINEAR_CPU_CACHED_INTEL or <level> is mipmap level not defined in 2175bd8deadSopenharmony_ci <texture>. 2185bd8deadSopenharmony_ci 2195bd8deadSopenharmony_ci INVALID_VALUE is generated by MapTexture2DINTEL when <access> has bits other 2205bd8deadSopenharmony_ci then MAP_WRITE_BIT or MAP_READ_BIT set or is 0. 2215bd8deadSopenharmony_ci 2225bd8deadSopenharmony_ci INVALID_OPERATION is generated by UnmapTexture2DINTEL when <texture> is not 2235bd8deadSopenharmony_ci an existing texture object or is 0, <level> of <texture> is not currently 2245bd8deadSopenharmony_ci mapped. 2255bd8deadSopenharmony_ci 2265bd8deadSopenharmony_ciNew State 2275bd8deadSopenharmony_ci 2285bd8deadSopenharmony_ci(add to table 6.24, "Textures (state per texture object)") 2295bd8deadSopenharmony_ci 2305bd8deadSopenharmony_ci Get Value Type Get Command Initial Value Description Section Attribute 2315bd8deadSopenharmony_ci ------------------------------- ------ ------------- ------------- -------------------- ------------ --------- 2325bd8deadSopenharmony_ci TEXTURE_MEMORY_LAYOUT_INTEL Z GetTexParameteriv LAYOUT_DEFAULT_INTEL Texture memory layout - - 2335bd8deadSopenharmony_ci 2345bd8deadSopenharmony_ciIssues 2355bd8deadSopenharmony_ci 2365bd8deadSopenharmony_ci (1) Is it possible to ensure that contents of mapped texture is 2375bd8deadSopenharmony_ci automatically updated after rendering to texture or GPU write (using 2385bd8deadSopenharmony_ci texture as FBO attachment or using image_load_store functionality)? 2395bd8deadSopenharmony_ci 2405bd8deadSopenharmony_ci RESOLUTION: 2415bd8deadSopenharmony_ci a) No guarantees are given in case of 'rendering loops' when surface 2425bd8deadSopenharmony_ci is mapped. To make sure that contents of mapping is 'current', 2435bd8deadSopenharmony_ci texture data mutation needs to be guaranteed as is done already 2445bd8deadSopenharmony_ci and mapped only after that. 2455bd8deadSopenharmony_ci 2465bd8deadSopenharmony_ci RESOLVED: No. 2475bd8deadSopenharmony_ci 2485bd8deadSopenharmony_ci 2495bd8deadSopenharmony_ci (2) What happens if Tex(Sub)Image* or CopyTex(Sub)Image is called on 2505bd8deadSopenharmony_ci mapped texture? What happens if mapped texture is deleted? 2515bd8deadSopenharmony_ci 2525bd8deadSopenharmony_ci RESOLUTION: 2535bd8deadSopenharmony_ci a) Calling Tex(Sub)Image may cause the texture to be reallocated, thus 2545bd8deadSopenharmony_ci it is necessary to unmap texture before calling these functions 2555bd8deadSopenharmony_ci (after these functions complete, the pointer may become invalid). 2565bd8deadSopenharmony_ci 2575bd8deadSopenharmony_ci b) Calling CopyTex(Sub)Image is safe for a texture for which a CPU 2585bd8deadSopenharmony_ci pointer has been obtained via MapTexture2DINTEL. 2595bd8deadSopenharmony_ci 2605bd8deadSopenharmony_ci c) After deleting the texture, the pointer obtained via 2615bd8deadSopenharmony_ci MapTexture2DINTEL becomes invalid. 2625bd8deadSopenharmony_ci 2635bd8deadSopenharmony_ci RESOLVED: Yes. 2645bd8deadSopenharmony_ci 2655bd8deadSopenharmony_ci 2665bd8deadSopenharmony_ci (3) Is it possible to enforce alignment of mapped texture level? 2675bd8deadSopenharmony_ci 2685bd8deadSopenharmony_ci RESOLUTION: No. 2695bd8deadSopenharmony_ci 2705bd8deadSopenharmony_ci 2715bd8deadSopenharmony_ci (4) Is it legal to write to / read from regions between row end and stride? 2725bd8deadSopenharmony_ci 2735bd8deadSopenharmony_ci RESOLUTION: 2745bd8deadSopenharmony_ci a) Yes. Writing to memory that is after end of the row up to stride is 2755bd8deadSopenharmony_ci safe and has no effect. 2765bd8deadSopenharmony_ci 2775bd8deadSopenharmony_ci RESOLVED: Yes. 2785bd8deadSopenharmony_ci 2795bd8deadSopenharmony_ci 2805bd8deadSopenharmony_ci (5) What happens if texture with unsupported (not native) format is 2815bd8deadSopenharmony_ci mapped? 2825bd8deadSopenharmony_ci 2835bd8deadSopenharmony_ci RESOLUTION: 2845bd8deadSopenharmony_ci NULL pointer is returned. 2855bd8deadSopenharmony_ci 2865bd8deadSopenharmony_ci RESOLVED: Yes. 2875bd8deadSopenharmony_ci 2885bd8deadSopenharmony_ci 2895bd8deadSopenharmony_ci (6) Are compressed formats supported? 2905bd8deadSopenharmony_ci 2915bd8deadSopenharmony_ci RESOLUTION: 2925bd8deadSopenharmony_ci a) Yes. 2935bd8deadSopenharmony_ci 2945bd8deadSopenharmony_ci RESOLVED: Yes. 2955bd8deadSopenharmony_ci 2965bd8deadSopenharmony_ci 2975bd8deadSopenharmony_ci 2985bd8deadSopenharmony_ciRevision History 2995bd8deadSopenharmony_ci 3005bd8deadSopenharmony_ci Rev. Date Author Changes 3015bd8deadSopenharmony_ci ---- -------- -------- ----------------------------------------- 3025bd8deadSopenharmony_ci 1 06/05/12 S. Grajewski Initial revision. 303