Changeset 221831 in webkit
- Timestamp:
- Sep 9, 2017 3:54:13 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r221830 r221831 1 2017-09-08 Dean Jackson <dino@apple.com> 2 3 gl.detachShader breaks shader program 4 https://bugs.webkit.org/show_bug.cgi?id=137689 5 <rdar://problem/34025056> 6 7 Reviewed by Sam Weinig. 8 9 Test that detaches and deletes shaders after linking, but before 10 asking for uniform locations. 11 12 * fast/canvas/webgl/detachShader-before-accessing-uniform-expected.txt: Added. 13 * fast/canvas/webgl/detachShader-before-accessing-uniform.html: Added. 14 1 15 2017-09-09 Per Arne Vollan <pvollan@apple.com> 2 16 -
trunk/Source/WebCore/ChangeLog
r221822 r221831 1 2017-09-08 Dean Jackson <dino@apple.com> 2 3 gl.detachShader breaks shader program 4 https://bugs.webkit.org/show_bug.cgi?id=137689 5 <rdar://problem/34025056> 6 7 Reviewed by Sam Weinig. 8 9 It should be possible to compile shaders, attach them to a program, 10 link the program, detach the shaders, delete the shaders, and then 11 ask for the uniform and attribute locations. That is, once you've 12 linked, the shaders can be thrown away. 13 14 We were using the attached shaders to look up uniform locations, so 15 we now keep around a separate map that remembers what shaders were 16 attached when the program links. 17 18 This fixes the bug, but the whole area is still a bit messy. For one, 19 we're keeping around all the shader information even after it is 20 no longer used. 21 See https://bugs.webkit.org/show_bug.cgi?id=98204 22 23 Test: fast/canvas/webgl/detachShader-before-accessing-uniform.html 24 25 * platform/graphics/GraphicsContext3D.h: Add another map to remember 26 what shaders were used when a program was linked. 27 * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp: 28 (WebCore::GraphicsContext3D::mappedSymbolInShaderSourceMap): New helper 29 to look up a name in our source maps. 30 (WebCore::GraphicsContext3D::mappedSymbolName): Use the helper, and look 31 at linked shaders if there are no attached shaders. 32 (WebCore::GraphicsContext3D::originalSymbolInShaderSourceMap): Does the 33 reverse of the above. 34 (WebCore::GraphicsContext3D::originalSymbolName): 35 (WebCore::GraphicsContext3D::linkProgram): Add to the new map. 36 (WebCore::GraphicsContext3D::deleteProgram): Delete the program from 37 our shader entries. 38 1 39 2017-09-09 Mark Lam <mark.lam@apple.com> 2 40 -
trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h
r221762 r221831 1349 1349 }; 1350 1350 1351 // FIXME: Shaders are never removed from this map, even if they and their program are deleted. 1352 // This is bad, and it also relies on the fact we never reuse Platform3DObject numbers. 1351 1353 typedef HashMap<Platform3DObject, ShaderSourceEntry> ShaderSourceMap; 1352 1354 ShaderSourceMap m_shaderSourceMap; 1355 1356 typedef HashMap<Platform3DObject, std::pair<Platform3DObject, Platform3DObject>> LinkedShaderMap; 1357 LinkedShaderMap m_linkedShaderMap; 1353 1358 1354 1359 struct ActiveShaderSymbolCounts { … … 1378 1383 String mappedSymbolName(Platform3DObject shaders[2], size_t count, const String& name); 1379 1384 String originalSymbolName(Platform3DObject program, ANGLEShaderSymbolType, const String& name); 1385 std::optional<String> mappedSymbolInShaderSourceMap(Platform3DObject shader, ANGLEShaderSymbolType, const String& name); 1386 std::optional<String> originalSymbolInShaderSourceMap(Platform3DObject shader, ANGLEShaderSymbolType, const String& name); 1380 1387 1381 1388 std::unique_ptr<ShaderNameHash> nameHashMapForShaders; -
trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp
r221762 r221831 966 966 } 967 967 968 std::optional<String> GraphicsContext3D::mappedSymbolInShaderSourceMap(Platform3DObject shader, ANGLEShaderSymbolType symbolType, const String& name) 969 { 970 auto result = m_shaderSourceMap.find(shader); 971 if (result == m_shaderSourceMap.end()) 972 return std::nullopt; 973 974 const auto& symbolMap = result->value.symbolMap(symbolType); 975 auto symbolEntry = symbolMap.find(name); 976 if (symbolEntry == symbolMap.end()) 977 return std::nullopt; 978 979 auto& mappedName = symbolEntry->value.mappedName; 980 return String(mappedName.c_str(), mappedName.length()); 981 } 982 968 983 String GraphicsContext3D::mappedSymbolName(Platform3DObject program, ANGLEShaderSymbolType symbolType, const String& name) 969 984 { … … 973 988 974 989 for (GC3Dsizei i = 0; i < count; ++i) { 975 ShaderSourceMap::iterator result = m_shaderSourceMap.find(shaders[i]); 976 if (result == m_shaderSourceMap.end()) 977 continue; 978 979 const ShaderSymbolMap& symbolMap = result->value.symbolMap(symbolType); 980 ShaderSymbolMap::const_iterator symbolEntry = symbolMap.find(name); 981 if (symbolEntry != symbolMap.end()) { 982 const std::string& mappedName = symbolEntry->value.mappedName; 983 return String(mappedName.c_str(), mappedName.length()); 984 } 990 auto mappedName = mappedSymbolInShaderSourceMap(shaders[i], symbolType, name); 991 if (mappedName) 992 return mappedName.value(); 993 } 994 995 // We might have detached or deleted the shaders after linking. 996 auto result = m_linkedShaderMap.find(program); 997 if (result != m_linkedShaderMap.end()) { 998 auto linkedShaders = result->value; 999 auto mappedName = mappedSymbolInShaderSourceMap(linkedShaders.first, symbolType, name); 1000 if (mappedName) 1001 return mappedName.value(); 1002 mappedName = mappedSymbolInShaderSourceMap(linkedShaders.second, symbolType, name); 1003 if (mappedName) 1004 return mappedName.value(); 985 1005 } 986 1006 … … 992 1012 setCurrentNameHashMapForShader(nameHashMapForShaders.get()); 993 1013 994 StringgeneratedName = generateHashedName(name);1014 auto generatedName = generateHashedName(name); 995 1015 996 1016 setCurrentNameHashMapForShader(nullptr); … … 1003 1023 return name; 1004 1024 } 1005 1025 1026 std::optional<String> GraphicsContext3D::originalSymbolInShaderSourceMap(Platform3DObject shader, ANGLEShaderSymbolType symbolType, const String& name) 1027 { 1028 auto result = m_shaderSourceMap.find(shader); 1029 if (result == m_shaderSourceMap.end()) 1030 return std::nullopt; 1031 1032 const auto& symbolMap = result->value.symbolMap(symbolType); 1033 for (const auto& symbolEntry : symbolMap) { 1034 if (name == symbolEntry.value.mappedName.c_str()) 1035 return symbolEntry.key; 1036 } 1037 return std::nullopt; 1038 } 1039 1006 1040 String GraphicsContext3D::originalSymbolName(Platform3DObject program, ANGLEShaderSymbolType symbolType, const String& name) 1007 1041 { … … 1011 1045 1012 1046 for (GC3Dsizei i = 0; i < count; ++i) { 1013 ShaderSourceMap::iterator result = m_shaderSourceMap.find(shaders[i]); 1014 if (result == m_shaderSourceMap.end()) 1015 continue; 1016 1017 const ShaderSymbolMap& symbolMap = result->value.symbolMap(symbolType); 1018 for (const auto& symbolEntry : symbolMap) { 1019 if (name == symbolEntry.value.mappedName.c_str()) 1020 return symbolEntry.key; 1021 } 1047 auto originalName = originalSymbolInShaderSourceMap(shaders[i], symbolType, name); 1048 if (originalName) 1049 return originalName.value(); 1050 } 1051 1052 // We might have detached or deleted the shaders after linking. 1053 auto result = m_linkedShaderMap.find(program); 1054 if (result != m_linkedShaderMap.end()) { 1055 auto linkedShaders = result->value; 1056 auto originalName = originalSymbolInShaderSourceMap(linkedShaders.first, symbolType, name); 1057 if (originalName) 1058 return originalName.value(); 1059 originalName = originalSymbolInShaderSourceMap(linkedShaders.second, symbolType, name); 1060 if (originalName) 1061 return originalName.value(); 1022 1062 } 1023 1063 … … 1194 1234 ASSERT(program); 1195 1235 makeContextCurrent(); 1236 1237 GC3Dsizei count = 0; 1238 Platform3DObject shaders[2] = { }; 1239 getAttachedShaders(program, 2, &count, shaders); 1240 1241 if (count == 2) 1242 m_linkedShaderMap.set(program, std::make_pair(shaders[0], shaders[1])); 1243 1196 1244 ::glLinkProgram(program); 1197 1245 } … … 1905 1953 { 1906 1954 makeContextCurrent(); 1955 m_shaderProgramSymbolCountMap.remove(program); 1907 1956 glDeleteProgram(program); 1908 1957 }
Note: See TracChangeset
for help on using the changeset viewer.