Changeset 128334 in webkit


Ignore:
Timestamp:
Sep 12, 2012 10:23:06 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[CSS Shaders] Remove direct texture access via u_texture
https://bugs.webkit.org/show_bug.cgi?id=93871

Patch by Max Vujovic <mvujovic@adobe.com> on 2012-09-12
Reviewed by Dean Jackson.

Source/WebCore:

Remove the author-accessible "u_texture" sampler, which referenced the DOM element texture.

Additionally, reject shaders with author-defined sampler uniforms. When we implement texture
parameters, we will allow shaders whose samplers are bound to valid textures. We must not
allow OpenGL to give unbound samplers a default value of 0 because that references the DOM
element texture, which should be inaccessible to the author's shader code.

Test: css3/filters/custom/custom-filter-no-element-texture-access.html

  • platform/graphics/ANGLEWebKitBridge.cpp:

(WebCore::getValidationResultValue):

Add a file-static function to easily query the integer values that ANGLE exposes about
the last validation result. The new getUniforms method and the existing
validateShaderSource method now both use getValidationResultValue.

(WebCore):
(WebCore::ANGLEWebKitBridge::validateShaderSource):

Use the new getValidationResultValue function instead of ANGLE's ShGetInfo function.

(WebCore::ANGLEWebKitBridge::getUniforms):

Add a new public method to ANGLEWebKitBridge which gets the info about all of the
uniforms in the last validated vertex shader or fragment shader. Uniform info includes
name, type, and size.

  • platform/graphics/ANGLEWebKitBridge.h:

(ANGLEShaderSymbol):
(WebCore::ANGLEShaderSymbol::isSampler):

Returns true if the symbol's data type is a GLSL sampler (e.g. sampler2D, samplerCube).

(WebCore):
(ANGLEWebKitBridge):

  • platform/graphics/filters/CustomFilterCompiledProgram.cpp:

(WebCore::CustomFilterCompiledProgram::CustomFilterCompiledProgram):

Take in an additional programType constructor parameter.

(WebCore::CustomFilterCompiledProgram::initializeParameterLocations):

Remove the author-accessible DOM element texture sampler "u_texture". Only find the
location of the internal DOM element texture sampler "css_u_texture" if the author is
using the CSS mix function.

  • platform/graphics/filters/CustomFilterCompiledProgram.h:
  • platform/graphics/filters/CustomFilterProgramInfo.h:

(CustomFilterProgramInfo):
(WebCore::CustomFilterProgramInfo::programType):

Add the new CustomFilterProgramType enum. In CustomFilterProgramInfo, we plan to replace
mixSettings.enabled with a programType. See:
https://bugs.webkit.org/show_bug.cgi?id=96448

  • platform/graphics/filters/CustomFilterValidatedProgram.cpp:

Reject all shaders that have sampler uniforms defined.

(WebCore::CustomFilterValidatedProgram::CustomFilterValidatedProgram):
(WebCore::CustomFilterValidatedProgram::compiledProgram):

  • platform/graphics/filters/FECustomFilter.cpp:

(WebCore::FECustomFilter::bindProgramAndBuffers):

Add an assert to verify that the DOM element texture is bound only if the author is
using the CSS mix function.

LayoutTests:

Add tests to verify that the "u_texture" sampler is no longer accessible to author shader
code because it was removed. These tests also verify that shaders with unbound samplers do
not execute.

Add tests to verify that the internal "css_u_texture" sampler is not accessible to author
shader code. These tests check that this is true whether or not the author is using the CSS
mix function and whether or not the author attempts to define css_u_texture is his or her
shader.

  • css3/filters/custom/custom-filter-no-element-texture-access-expected.html: Added.
  • css3/filters/custom/custom-filter-no-element-texture-access.html: Added.
  • css3/filters/resources/sample-defined-css-u-texture-mix.fs: Added.
  • css3/filters/resources/sample-defined-css-u-texture.fs: Added.
  • css3/filters/resources/sample-u-texture-mix.fs: Added.
  • css3/filters/resources/sample-u-texture.fs: Added.
  • css3/filters/resources/sample-undefined-css-u-texture-mix.fs: Added.
  • css3/filters/resources/sample-undefined-css-u-texture.fs: Added.
Location:
trunk
Files:
8 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r128326 r128334  
     12012-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
    1262012-09-12  Christophe Dumez  <christophe.dumez@intel.com>
    227
  • trunk/Source/WebCore/ChangeLog

    r128332 r128334  
     12012-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
    1582012-09-12  Dominic Mazzoni  <dmazzoni@google.com>
    259
  • trunk/Source/WebCore/platform/graphics/ANGLEWebKitBridge.cpp

    r127217 r128334  
    3232
    3333namespace WebCore {
     34
     35inline static int getValidationResultValue(const ShHandle compiler, ShShaderInfo shaderInfo)
     36{
     37    int value = -1;
     38    ShGetInfo(compiler, shaderInfo, &value);
     39    return value;
     40}
    3441
    3542ANGLEWebKitBridge::ANGLEWebKitBridge(ShShaderOutput shaderOutput, ShShaderSpec shaderSpec)
     
    93100    bool validateSuccess = ShCompile(compiler, shaderSourceStrings, 1, SH_OBJECT_CODE | extraCompileOptions);
    94101    if (!validateSuccess) {
    95         int logSize = 0;
    96         ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &logSize);
     102        int logSize = getValidationResultValue(compiler, SH_INFO_LOG_LENGTH);
    97103        if (logSize > 1) {
    98104            OwnArrayPtr<char> logBuffer = adoptArrayPtr(new char[logSize]);
     
    105111    }
    106112
    107     int translationLength = 0;
    108     ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &translationLength);
     113    int translationLength = getValidationResultValue(compiler, SH_OBJECT_CODE_LENGTH);
    109114    if (translationLength > 1) {
    110115        OwnArrayPtr<char> translationBuffer = adoptArrayPtr(new char[translationLength]);
     
    118123}
    119124
     125bool 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
    120154}
    121155
  • trunk/Source/WebCore/platform/graphics/ANGLEWebKitBridge.h

    r127757 r128334  
    4343};
    4444
     45enum ANGLEShaderSymbolType {
     46    SHADER_SYMBOL_TYPE_ATTRIBUTE,
     47    SHADER_SYMBOL_TYPE_UNIFORM
     48};
     49
     50struct 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
    4565class ANGLEWebKitBridge {
    4666public:
     
    5373   
    5474    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);
    5580
    5681private:
  • trunk/Source/WebCore/platform/graphics/filters/CustomFilterCompiledProgram.cpp

    r127217 r128334  
    3737namespace WebCore {
    3838
    39 CustomFilterCompiledProgram::CustomFilterCompiledProgram(PassRefPtr<GraphicsContext3D> context, const String& validatedVertexShader, const String& validatedFragmentShader)
     39CustomFilterCompiledProgram::CustomFilterCompiledProgram(PassRefPtr<GraphicsContext3D> context, const String& validatedVertexShader, const String& validatedFragmentShader, CustomFilterProgramType programType)
    4040    : m_context(context)
    4141    , m_program(0)
     
    7474        return;
    7575   
    76     initializeParameterLocations();
     76    initializeParameterLocations(programType);
    7777   
    7878    m_isInitialized = true;
     
    118118}
    119119
    120 void CustomFilterCompiledProgram::initializeParameterLocations()
     120void CustomFilterCompiledProgram::initializeParameterLocations(CustomFilterProgramType programType)
    121121{
    122122    m_positionAttribLocation = m_context->getAttribLocation(m_program, "a_position");
     
    130130    m_samplerSizeLocation = m_context->getUniformLocation(m_program, "u_textureSize");
    131131    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    }
    138142}
    139143
  • trunk/Source/WebCore/platform/graphics/filters/CustomFilterCompiledProgram.h

    r127217 r128334  
    3333#if ENABLE(CSS_SHADERS) && USE(3D_GRAPHICS)
    3434
     35#include "CustomFilterProgramInfo.h"
    3536#include "GraphicsContext3D.h"
    3637#include <wtf/RefCounted.h>
     
    4344class CustomFilterCompiledProgram: public RefCounted<CustomFilterCompiledProgram> {
    4445public:
    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)
    4647    {
    47         return adoptRef(new CustomFilterCompiledProgram(context, validatedVertexShader, validatedFragmentShader));
     48        return adoptRef(new CustomFilterCompiledProgram(context, validatedVertexShader, validatedFragmentShader, programType));
    4849    }
    4950   
     
    7475    Platform3DObject program() const { return m_program; }
    7576private:
    76     CustomFilterCompiledProgram(PassRefPtr<GraphicsContext3D>, const String& validatedVertexShader, const String& validatedFragmentShader);
     77    CustomFilterCompiledProgram(PassRefPtr<GraphicsContext3D>, const String& validatedVertexShader, const String& validatedFragmentShader, CustomFilterProgramType);
    7778   
    7879    Platform3DObject compileShader(GC3Denum shaderType, const String& shaderString);
    7980    Platform3DObject linkProgram(Platform3DObject vertexShader, Platform3DObject fragmentShader);
    80     void initializeParameterLocations();
     81    void initializeParameterLocations(CustomFilterProgramType);
    8182   
    8283    RefPtr<GraphicsContext3D> m_context;
  • trunk/Source/WebCore/platform/graphics/filters/CustomFilterProgramInfo.h

    r127217 r128334  
    3939namespace WebCore {
    4040
     41enum CustomFilterProgramType {
     42    PROGRAM_TYPE_NO_ELEMENT_TEXTURE,
     43    PROGRAM_TYPE_BLENDS_ELEMENT_TEXTURE
     44};
     45
    4146struct CustomFilterProgramMixSettings {
    4247    CustomFilterProgramMixSettings()
     
    7681    const String& vertexShaderString() const { return m_vertexShaderString; }
    7782    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; }
    7886    const CustomFilterProgramMixSettings& mixSettings() const { return m_mixSettings; }
    7987private:
  • trunk/Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp

    r127964 r128334  
    8686    ANGLEWebKitBridge* validator = programInfo.mixSettings().enabled ? m_globalContext->mixShaderValidator() : m_globalContext->webglShaderValidator();
    8787    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);
    9090    if (!vertexShaderValid || !fragmentShaderValid) {
    9191        // FIXME: Report the validation errors.
     
    9494    }
    9595
     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
    96113    // We need to add texture access, blending, and compositing code to shaders that are referenced from the CSS mix function.
    97114    if (programInfo.mixSettings().enabled) {
     
    107124    ASSERT(m_isInitialized && m_globalContext && !m_validatedVertexShader.isNull() && !m_validatedFragmentShader.isNull());
    108125    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());
    110127    return m_compiledProgram;
    111128}
  • trunk/Source/WebCore/platform/graphics/filters/FECustomFilter.cpp

    r127758 r128334  
    330330   
    331331    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
    332335        m_context->activeTexture(GraphicsContext3D::TEXTURE0);
    333336        m_context->uniform1i(m_compiledProgram->samplerLocation(), 0);
Note: See TracChangeset for help on using the changeset viewer.