Changeset 128334 in webkit
- Timestamp:
- Sep 12, 2012 10:23:06 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 8 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r128326 r128334 1 2012-09-12 Max Vujovic <mvujovic@adobe.com> 2 3 [CSS Shaders] Remove direct texture access via u_texture 4 https://bugs.webkit.org/show_bug.cgi?id=93871 5 6 Reviewed by Dean Jackson. 7 8 Add tests to verify that the "u_texture" sampler is no longer accessible to author shader 9 code because it was removed. These tests also verify that shaders with unbound samplers do 10 not execute. 11 12 Add tests to verify that the internal "css_u_texture" sampler is not accessible to author 13 shader code. These tests check that this is true whether or not the author is using the CSS 14 mix function and whether or not the author attempts to define css_u_texture is his or her 15 shader. 16 17 * css3/filters/custom/custom-filter-no-element-texture-access-expected.html: Added. 18 * css3/filters/custom/custom-filter-no-element-texture-access.html: Added. 19 * css3/filters/resources/sample-defined-css-u-texture-mix.fs: Added. 20 * css3/filters/resources/sample-defined-css-u-texture.fs: Added. 21 * css3/filters/resources/sample-u-texture-mix.fs: Added. 22 * css3/filters/resources/sample-u-texture.fs: Added. 23 * css3/filters/resources/sample-undefined-css-u-texture-mix.fs: Added. 24 * css3/filters/resources/sample-undefined-css-u-texture.fs: Added. 25 1 26 2012-09-12 Christophe Dumez <christophe.dumez@intel.com> 2 27 -
trunk/Source/WebCore/ChangeLog
r128332 r128334 1 2012-09-12 Max Vujovic <mvujovic@adobe.com> 2 3 [CSS Shaders] Remove direct texture access via u_texture 4 https://bugs.webkit.org/show_bug.cgi?id=93871 5 6 Reviewed by Dean Jackson. 7 8 Remove the author-accessible "u_texture" sampler, which referenced the DOM element texture. 9 10 Additionally, reject shaders with author-defined sampler uniforms. When we implement texture 11 parameters, we will allow shaders whose samplers are bound to valid textures. We must not 12 allow OpenGL to give unbound samplers a default value of 0 because that references the DOM 13 element texture, which should be inaccessible to the author's shader code. 14 15 Test: css3/filters/custom/custom-filter-no-element-texture-access.html 16 17 * platform/graphics/ANGLEWebKitBridge.cpp: 18 (WebCore::getValidationResultValue): 19 Add a file-static function to easily query the integer values that ANGLE exposes about 20 the last validation result. The new getUniforms method and the existing 21 validateShaderSource method now both use getValidationResultValue. 22 (WebCore): 23 (WebCore::ANGLEWebKitBridge::validateShaderSource): 24 Use the new getValidationResultValue function instead of ANGLE's ShGetInfo function. 25 (WebCore::ANGLEWebKitBridge::getUniforms): 26 Add a new public method to ANGLEWebKitBridge which gets the info about all of the 27 uniforms in the last validated vertex shader or fragment shader. Uniform info includes 28 name, type, and size. 29 * platform/graphics/ANGLEWebKitBridge.h: 30 (ANGLEShaderSymbol): 31 (WebCore::ANGLEShaderSymbol::isSampler): 32 Returns true if the symbol's data type is a GLSL sampler (e.g. sampler2D, samplerCube). 33 (WebCore): 34 (ANGLEWebKitBridge): 35 * platform/graphics/filters/CustomFilterCompiledProgram.cpp: 36 (WebCore::CustomFilterCompiledProgram::CustomFilterCompiledProgram): 37 Take in an additional programType constructor parameter. 38 (WebCore::CustomFilterCompiledProgram::initializeParameterLocations): 39 Remove the author-accessible DOM element texture sampler "u_texture". Only find the 40 location of the internal DOM element texture sampler "css_u_texture" if the author is 41 using the CSS mix function. 42 * platform/graphics/filters/CustomFilterCompiledProgram.h: 43 * platform/graphics/filters/CustomFilterProgramInfo.h: 44 (CustomFilterProgramInfo): 45 (WebCore::CustomFilterProgramInfo::programType): 46 Add the new CustomFilterProgramType enum. In CustomFilterProgramInfo, we plan to replace 47 mixSettings.enabled with a programType. See: 48 https://bugs.webkit.org/show_bug.cgi?id=96448 49 * platform/graphics/filters/CustomFilterValidatedProgram.cpp: 50 Reject all shaders that have sampler uniforms defined. 51 (WebCore::CustomFilterValidatedProgram::CustomFilterValidatedProgram): 52 (WebCore::CustomFilterValidatedProgram::compiledProgram): 53 * platform/graphics/filters/FECustomFilter.cpp: 54 (WebCore::FECustomFilter::bindProgramAndBuffers): 55 Add an assert to verify that the DOM element texture is bound only if the author is 56 using the CSS mix function. 57 1 58 2012-09-12 Dominic Mazzoni <dmazzoni@google.com> 2 59 -
trunk/Source/WebCore/platform/graphics/ANGLEWebKitBridge.cpp
r127217 r128334 32 32 33 33 namespace WebCore { 34 35 inline static int getValidationResultValue(const ShHandle compiler, ShShaderInfo shaderInfo) 36 { 37 int value = -1; 38 ShGetInfo(compiler, shaderInfo, &value); 39 return value; 40 } 34 41 35 42 ANGLEWebKitBridge::ANGLEWebKitBridge(ShShaderOutput shaderOutput, ShShaderSpec shaderSpec) … … 93 100 bool validateSuccess = ShCompile(compiler, shaderSourceStrings, 1, SH_OBJECT_CODE | extraCompileOptions); 94 101 if (!validateSuccess) { 95 int logSize = 0; 96 ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &logSize); 102 int logSize = getValidationResultValue(compiler, SH_INFO_LOG_LENGTH); 97 103 if (logSize > 1) { 98 104 OwnArrayPtr<char> logBuffer = adoptArrayPtr(new char[logSize]); … … 105 111 } 106 112 107 int translationLength = 0; 108 ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &translationLength); 113 int translationLength = getValidationResultValue(compiler, SH_OBJECT_CODE_LENGTH); 109 114 if (translationLength > 1) { 110 115 OwnArrayPtr<char> translationBuffer = adoptArrayPtr(new char[translationLength]); … … 118 123 } 119 124 125 bool ANGLEWebKitBridge::getUniforms(ShShaderType shaderType, Vector<ANGLEShaderSymbol> &symbols) 126 { 127 const ShHandle compiler = (shaderType == SH_VERTEX_SHADER ? m_vertexCompiler : m_fragmentCompiler); 128 129 int numUniforms = getValidationResultValue(compiler, SH_ACTIVE_UNIFORMS); 130 if (numUniforms < 0) 131 return false; 132 if (!numUniforms) 133 return true; 134 135 int maxNameLength = getValidationResultValue(compiler, SH_ACTIVE_UNIFORM_MAX_LENGTH); 136 if (maxNameLength <= 1) 137 return false; 138 OwnArrayPtr<char> nameBuffer = adoptArrayPtr(new char[maxNameLength]); 139 140 for (int i = 0; i < numUniforms; ++i) { 141 ANGLEShaderSymbol symbol; 142 symbol.symbolType = SHADER_SYMBOL_TYPE_UNIFORM; 143 int nameLength = -1; 144 ShGetActiveUniform(compiler, i, &nameLength, &symbol.size, &symbol.dataType, nameBuffer.get(), 0); 145 if (nameLength <= 0) 146 return false; 147 symbol.name = String::fromUTF8(nameBuffer.get(), nameLength); 148 symbols.append(symbol); 149 } 150 151 return true; 152 } 153 120 154 } 121 155 -
trunk/Source/WebCore/platform/graphics/ANGLEWebKitBridge.h
r127757 r128334 43 43 }; 44 44 45 enum ANGLEShaderSymbolType { 46 SHADER_SYMBOL_TYPE_ATTRIBUTE, 47 SHADER_SYMBOL_TYPE_UNIFORM 48 }; 49 50 struct ANGLEShaderSymbol { 51 ANGLEShaderSymbolType symbolType; 52 String name; 53 ShDataType dataType; 54 int size; 55 56 bool isSampler() 57 { 58 return dataType == SH_SAMPLER_2D 59 || dataType == SH_SAMPLER_CUBE 60 || dataType == SH_SAMPLER_2D_RECT_ARB 61 || dataType == SH_SAMPLER_EXTERNAL_OES; 62 } 63 }; 64 45 65 class ANGLEWebKitBridge { 46 66 public: … … 53 73 54 74 bool validateShaderSource(const char* shaderSource, ANGLEShaderType, String& translatedShaderSource, String& shaderValidationLog, int extraCompileOptions = 0); 75 76 // Get the uniforms for the last validated shader of type ShShaderType. 77 // For this function to work, you must use the SH_ATTRIBUTES_UNIFORMS compile option during validation. 78 // Returns false if an unexpected error occurred in ANGLE. 79 bool getUniforms(ShShaderType, Vector<ANGLEShaderSymbol> &symbols); 55 80 56 81 private: -
trunk/Source/WebCore/platform/graphics/filters/CustomFilterCompiledProgram.cpp
r127217 r128334 37 37 namespace WebCore { 38 38 39 CustomFilterCompiledProgram::CustomFilterCompiledProgram(PassRefPtr<GraphicsContext3D> context, const String& validatedVertexShader, const String& validatedFragmentShader )39 CustomFilterCompiledProgram::CustomFilterCompiledProgram(PassRefPtr<GraphicsContext3D> context, const String& validatedVertexShader, const String& validatedFragmentShader, CustomFilterProgramType programType) 40 40 : m_context(context) 41 41 , m_program(0) … … 74 74 return; 75 75 76 initializeParameterLocations( );76 initializeParameterLocations(programType); 77 77 78 78 m_isInitialized = true; … … 118 118 } 119 119 120 void CustomFilterCompiledProgram::initializeParameterLocations( )120 void CustomFilterCompiledProgram::initializeParameterLocations(CustomFilterProgramType programType) 121 121 { 122 122 m_positionAttribLocation = m_context->getAttribLocation(m_program, "a_position"); … … 130 130 m_samplerSizeLocation = m_context->getUniformLocation(m_program, "u_textureSize"); 131 131 m_contentSamplerLocation = m_context->getUniformLocation(m_program, "u_contentTexture"); 132 m_internalTexCoordAttribLocation = m_context->getAttribLocation(m_program, "css_a_texCoord"); 133 m_samplerLocation = m_context->getUniformLocation(m_program, "css_u_texture"); 134 // FIXME: Remove texture access via u_texture and change the tests to use blending and compositing. 135 // https://bugs.webkit.org/show_bug.cgi?id=93871 136 if (m_samplerLocation == -1) 137 m_samplerLocation = m_context->getUniformLocation(m_program, "u_texture"); 132 if (programType == PROGRAM_TYPE_BLENDS_ELEMENT_TEXTURE) { 133 // When the author uses the CSS mix function in a custom filter, we add internal symbols to the shader code. 134 // One of them, css_u_texture, references the texture of the element. 135 m_samplerLocation = m_context->getUniformLocation(m_program, "css_u_texture"); 136 m_internalTexCoordAttribLocation = m_context->getAttribLocation(m_program, "css_a_texCoord"); 137 138 // These internal symbols should have been added to the validated shaders. 139 ASSERT(m_samplerLocation != -1); 140 ASSERT(m_internalTexCoordAttribLocation != -1); 141 } 138 142 } 139 143 -
trunk/Source/WebCore/platform/graphics/filters/CustomFilterCompiledProgram.h
r127217 r128334 33 33 #if ENABLE(CSS_SHADERS) && USE(3D_GRAPHICS) 34 34 35 #include "CustomFilterProgramInfo.h" 35 36 #include "GraphicsContext3D.h" 36 37 #include <wtf/RefCounted.h> … … 43 44 class CustomFilterCompiledProgram: public RefCounted<CustomFilterCompiledProgram> { 44 45 public: 45 static PassRefPtr<CustomFilterCompiledProgram> create(PassRefPtr<GraphicsContext3D> context, const String& validatedVertexShader, const String& validatedFragmentShader )46 static PassRefPtr<CustomFilterCompiledProgram> create(PassRefPtr<GraphicsContext3D> context, const String& validatedVertexShader, const String& validatedFragmentShader, CustomFilterProgramType programType) 46 47 { 47 return adoptRef(new CustomFilterCompiledProgram(context, validatedVertexShader, validatedFragmentShader ));48 return adoptRef(new CustomFilterCompiledProgram(context, validatedVertexShader, validatedFragmentShader, programType)); 48 49 } 49 50 … … 74 75 Platform3DObject program() const { return m_program; } 75 76 private: 76 CustomFilterCompiledProgram(PassRefPtr<GraphicsContext3D>, const String& validatedVertexShader, const String& validatedFragmentShader );77 CustomFilterCompiledProgram(PassRefPtr<GraphicsContext3D>, const String& validatedVertexShader, const String& validatedFragmentShader, CustomFilterProgramType); 77 78 78 79 Platform3DObject compileShader(GC3Denum shaderType, const String& shaderString); 79 80 Platform3DObject linkProgram(Platform3DObject vertexShader, Platform3DObject fragmentShader); 80 void initializeParameterLocations( );81 void initializeParameterLocations(CustomFilterProgramType); 81 82 82 83 RefPtr<GraphicsContext3D> m_context; -
trunk/Source/WebCore/platform/graphics/filters/CustomFilterProgramInfo.h
r127217 r128334 39 39 namespace WebCore { 40 40 41 enum CustomFilterProgramType { 42 PROGRAM_TYPE_NO_ELEMENT_TEXTURE, 43 PROGRAM_TYPE_BLENDS_ELEMENT_TEXTURE 44 }; 45 41 46 struct CustomFilterProgramMixSettings { 42 47 CustomFilterProgramMixSettings() … … 76 81 const String& vertexShaderString() const { return m_vertexShaderString; } 77 82 const String& fragmentShaderString() const { return m_fragmentShaderString; } 83 // FIXME: We should add CustomFilterProgramType to CustomFilterProgramInfo and remove mixSettings.enabled. 84 // https://bugs.webkit.org/show_bug.cgi?id=96448 85 CustomFilterProgramType programType() const { return m_mixSettings.enabled ? PROGRAM_TYPE_BLENDS_ELEMENT_TEXTURE : PROGRAM_TYPE_NO_ELEMENT_TEXTURE; } 78 86 const CustomFilterProgramMixSettings& mixSettings() const { return m_mixSettings; } 79 87 private: -
trunk/Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp
r127964 r128334 86 86 ANGLEWebKitBridge* validator = programInfo.mixSettings().enabled ? m_globalContext->mixShaderValidator() : m_globalContext->webglShaderValidator(); 87 87 String vertexShaderLog, fragmentShaderLog; 88 bool vertexShaderValid = validator->validateShaderSource(originalVertexShader.utf8().data(), SHADER_TYPE_VERTEX, m_validatedVertexShader, vertexShaderLog );89 bool fragmentShaderValid = validator->validateShaderSource(originalFragmentShader.utf8().data(), SHADER_TYPE_FRAGMENT, m_validatedFragmentShader, fragmentShaderLog );88 bool vertexShaderValid = validator->validateShaderSource(originalVertexShader.utf8().data(), SHADER_TYPE_VERTEX, m_validatedVertexShader, vertexShaderLog, SH_ATTRIBUTES_UNIFORMS); 89 bool fragmentShaderValid = validator->validateShaderSource(originalFragmentShader.utf8().data(), SHADER_TYPE_FRAGMENT, m_validatedFragmentShader, fragmentShaderLog, SH_ATTRIBUTES_UNIFORMS); 90 90 if (!vertexShaderValid || !fragmentShaderValid) { 91 91 // FIXME: Report the validation errors. … … 94 94 } 95 95 96 // Validate the author's samplers. 97 Vector<ANGLEShaderSymbol> uniforms; 98 if (!validator->getUniforms(SH_VERTEX_SHADER, uniforms)) 99 return; 100 if (!validator->getUniforms(SH_FRAGMENT_SHADER, uniforms)) 101 return; 102 for (Vector<ANGLEShaderSymbol>::iterator it = uniforms.begin(); it != uniforms.end(); ++it) { 103 if (it->isSampler()) { 104 // FIXME: For now, we restrict shaders with any sampler defined. 105 // When we implement texture parameters, we will allow shaders whose samplers are bound to valid textures. 106 // We must not allow OpenGL to give unbound samplers a default value of 0 because that references the DOM element texture, 107 // which should be inaccessible to the author's shader code. 108 // https://bugs.webkit.org/show_bug.cgi?id=96230 109 return; 110 } 111 } 112 96 113 // We need to add texture access, blending, and compositing code to shaders that are referenced from the CSS mix function. 97 114 if (programInfo.mixSettings().enabled) { … … 107 124 ASSERT(m_isInitialized && m_globalContext && !m_validatedVertexShader.isNull() && !m_validatedFragmentShader.isNull()); 108 125 if (!m_compiledProgram) 109 m_compiledProgram = CustomFilterCompiledProgram::create(m_globalContext->context(), m_validatedVertexShader, m_validatedFragmentShader );126 m_compiledProgram = CustomFilterCompiledProgram::create(m_globalContext->context(), m_validatedVertexShader, m_validatedFragmentShader, m_programInfo.programType()); 110 127 return m_compiledProgram; 111 128 } -
trunk/Source/WebCore/platform/graphics/filters/FECustomFilter.cpp
r127758 r128334 330 330 331 331 if (m_compiledProgram->samplerLocation() != -1) { 332 // We should be binding the DOM element texture sampler only if the author is using the CSS mix function. 333 ASSERT(m_validatedProgram->programInfo().programType() == PROGRAM_TYPE_BLENDS_ELEMENT_TEXTURE); 334 332 335 m_context->activeTexture(GraphicsContext3D::TEXTURE0); 333 336 m_context->uniform1i(m_compiledProgram->samplerLocation(), 0);
Note: See TracChangeset
for help on using the changeset viewer.