Changeset 57709 in webkit


Ignore:
Timestamp:
Apr 15, 2010 7:01:34 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-04-15 Zhenyao Mo <zmo@google.com>

Reviewed by Dimitri Glazkov.

Index validation code validates too many vertex attributes
https://bugs.webkit.org/show_bug.cgi?id=31892

  • fast/canvas/webgl/index-validation-expected.txt: Add new test cases for index validations.
  • fast/canvas/webgl/script-tests/index-validation.js: Ditto.

2010-04-15 Zhenyao Mo <zmo@google.com>

Reviewed by Dimitri Glazkov.

Index validation code validates too many vertex attributes
https://bugs.webkit.org/show_bug.cgi?id=31892

  • html/canvas/WebGLProgram.cpp: (WebCore::WebGLProgram::cacheActiveAttribLocations): Cache active attribute locations for a program at linkProgram time. (WebCore::WebGLProgram::getActiveAttribLocation): Get the cached attribute location. (WebCore::WebGLProgram::numActiveAttribLocations): Get the number of cached attribute locations.
  • html/canvas/WebGLProgram.h: Add attribute locations member.
  • html/canvas/WebGLRenderingContext.cpp: (WebCore::WebGLRenderingContext::validateRenderingState): Add logic not to validate those attributes that do not belong to the current program. (WebCore::WebGLRenderingContext::linkProgram): Call cacheActiveAttribLocations().
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r57708 r57709  
     12010-04-15  Zhenyao Mo  <zmo@google.com>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        Index validation code validates too many vertex attributes
     6        https://bugs.webkit.org/show_bug.cgi?id=31892
     7
     8        * fast/canvas/webgl/index-validation-expected.txt: Add new test cases for index validations.
     9        * fast/canvas/webgl/script-tests/index-validation.js: Ditto.
     10
    1112010-04-15  Jian Li  <jianli@chromium.org>
    212
  • trunk/LayoutTests/fast/canvas/webgl/index-validation-expected.txt

    r57015 r57709  
    1 Test of get calls against GL objects like getBufferParameter, etc.
     1Test of validating indices for drawElements().
    22
    33On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
    44
     5Testing with valid indices
    56PASS gl.checkFramebufferStatus(gl.FRAMEBUFFER) is gl.FRAMEBUFFER_COMPLETE
     7PASS gl.getError() is 0
     8PASS gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0) is undefined.
     9PASS gl.getError() is 0
     10Testing with out-of-range indices
     11Enable vertices, valid
     12PASS gl.getError() is 0
     13PASS gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0) is undefined.
     14PASS gl.getError() is 0
     15Enable normals, out-of-range
     16PASS gl.getError() is 0
     17PASS gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0) is undefined.
     18PASS gl.getError() is gl.INVALID_OPERATION
     19Test with enabled attribute that does not belong to current program
     20Enable an extra attribute with null
     21PASS gl.getError() is 0
     22PASS gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0) is undefined.
     23PASS gl.getError() is 0
     24Enable an extra attribute with insufficient data buffer
    625PASS gl.getError() is 0
    726PASS gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0) is undefined.
  • trunk/LayoutTests/fast/canvas/webgl/script-tests/index-validation.js

    r57234 r57709  
    1 description("Test of get calls against GL objects like getBufferParameter, etc.");
     1description("Test of validating indices for drawElements().");
    22
    33var gl = create3DContext();
     
    55
    66// 3 vertices => 1 triangle, interleaved data
    7 var data = new WebGLFloatArray([0, 0, 0, 1,
    8                                 0, 0, 1,
    9                                 1, 0, 0, 1,
    10                                 0, 0, 1,
    11                                 1, 1, 1, 1,
    12                                 0, 0, 1]);
     7var dataComplete = new WebGLFloatArray([0, 0, 0, 1,
     8                                        0, 0, 1,
     9                                        1, 0, 0, 1,
     10                                        0, 0, 1,
     11                                        1, 1, 1, 1,
     12                                        0, 0, 1]);
     13var dataIncomplete = new WebGLFloatArray([0, 0, 0, 1,
     14                                          0, 0, 1,
     15                                          1, 0, 0, 1,
     16                                          0, 0, 1,
     17                                          1, 1, 1, 1]);
    1318var indices = new WebGLUnsignedShortArray([0, 1, 2]);
    1419
    15 var buffer = gl.createBuffer();
    16 gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
    17 gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
     20debug("Testing with valid indices");
     21
     22var bufferComplete = gl.createBuffer();
     23gl.bindBuffer(gl.ARRAY_BUFFER, bufferComplete);
     24gl.bufferData(gl.ARRAY_BUFFER, dataComplete, gl.STATIC_DRAW);
    1825var elements = gl.createBuffer();
    1926gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elements);
     
    2431gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 0);
    2532gl.enableVertexAttribArray(vertexLoc);
    26 gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 3 * gl.sizeInBytes(gl.FLOAT));
     33gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 4 * gl.sizeInBytes(gl.FLOAT));
    2734gl.enableVertexAttribArray(normalLoc);
    2835shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE');
     
    3138shouldBe('gl.getError()', '0');
    3239
     40debug("Testing with out-of-range indices");
     41
     42var bufferIncomplete = gl.createBuffer();
     43gl.bindBuffer(gl.ARRAY_BUFFER, bufferIncomplete);
     44gl.bufferData(gl.ARRAY_BUFFER, dataIncomplete, gl.STATIC_DRAW);
     45gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 0);
     46gl.enableVertexAttribArray(vertexLoc);
     47gl.disableVertexAttribArray(normalLoc);
     48debug("Enable vertices, valid");
     49shouldBe('gl.getError()', '0');
     50shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
     51shouldBe('gl.getError()', '0');
     52debug("Enable normals, out-of-range");
     53gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 4 * gl.sizeInBytes(gl.FLOAT));
     54gl.enableVertexAttribArray(normalLoc);
     55shouldBe('gl.getError()', '0');
     56shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
     57shouldBe('gl.getError()', 'gl.INVALID_OPERATION');
     58
     59debug("Test with enabled attribute that does not belong to current program");
     60
     61gl.disableVertexAttribArray(normalLoc);
     62var extraLoc = Math.max(vertexLoc, normalLoc) + 1;
     63gl.enableVertexAttribArray(extraLoc);
     64debug("Enable an extra attribute with null");
     65shouldBe('gl.getError()', '0');
     66shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
     67shouldBe('gl.getError()', '0');
     68debug("Enable an extra attribute with insufficient data buffer");
     69gl.vertexAttribPointer(extraLoc, 3, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 4 * gl.sizeInBytes(gl.FLOAT));
     70shouldBe('gl.getError()', '0');
     71shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
     72shouldBe('gl.getError()', '0');
     73
    3374successfullyParsed = true;
  • trunk/WebCore/ChangeLog

    r57705 r57709  
     12010-04-15  Zhenyao Mo  <zmo@google.com>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        Index validation code validates too many vertex attributes
     6        https://bugs.webkit.org/show_bug.cgi?id=31892
     7
     8        * html/canvas/WebGLProgram.cpp:
     9        (WebCore::WebGLProgram::cacheActiveAttribLocations): Cache active attribute locations for a program at linkProgram time.
     10        (WebCore::WebGLProgram::getActiveAttribLocation): Get the cached attribute location.
     11        (WebCore::WebGLProgram::numActiveAttribLocations): Get the number of cached attribute locations.
     12        * html/canvas/WebGLProgram.h: Add attribute locations member.
     13        * html/canvas/WebGLRenderingContext.cpp:
     14        (WebCore::WebGLRenderingContext::validateRenderingState): Add logic not to validate those attributes that do not belong to the current program.
     15        (WebCore::WebGLRenderingContext::linkProgram): Call cacheActiveAttribLocations().
     16
    1172010-04-16  Adam Roben  <aroben@apple.com>
    218
  • trunk/WebCore/html/canvas/WebGLProgram.cpp

    r50725 r57709  
    4949}
    5050
     51bool WebGLProgram::cacheActiveAttribLocations()
     52{
     53    m_activeAttribLocations.clear();
     54    if (!object())
     55        return false;
     56    GraphicsContext3D* context3d = context()->graphicsContext3D();
     57    int linkStatus;
     58    context3d->getProgramiv(this, GraphicsContext3D::LINK_STATUS, &linkStatus);
     59    if (!linkStatus)
     60        return false;
     61
     62    int numAttribs = 0;
     63    context3d->getProgramiv(this, GraphicsContext3D::ACTIVE_ATTRIBUTES, &numAttribs);
     64    m_activeAttribLocations.resize(static_cast<size_t>(numAttribs));
     65    for (int i = 0; i < numAttribs; ++i) {
     66        ActiveInfo info;
     67        context3d->getActiveAttrib(this, i, info);
     68        m_activeAttribLocations[i] = context3d->getAttribLocation(this, info.name.charactersWithNullTermination());
     69    }
     70
     71    return true;
     72}
     73
     74int WebGLProgram::numActiveAttribLocations()
     75{
     76    return static_cast<int>(m_activeAttribLocations.size());
     77}
     78
     79int WebGLProgram::getActiveAttribLocation(int index)
     80{
     81    if (index < 0 || index >= numActiveAttribLocations())
     82        return -1;
     83    return m_activeAttribLocations[static_cast<size_t>(index)];
     84}
     85
    5186}
    5287
  • trunk/WebCore/html/canvas/WebGLProgram.h

    r50725 r57709  
    3131#include <wtf/PassRefPtr.h>
    3232#include <wtf/RefCounted.h>
     33#include <wtf/Vector.h>
    3334
    3435namespace WebCore {
     
    3940       
    4041        static PassRefPtr<WebGLProgram> create(WebGLRenderingContext*);
     42
     43        // cacheActiveAttribLocation() is only called once after linkProgram()
     44        // succeeds.
     45        bool cacheActiveAttribLocations();
     46        int numActiveAttribLocations();
     47        int getActiveAttribLocation(int index);
    4148       
    4249    protected:
     
    4451       
    4552        virtual void _deleteObject(Platform3DObject);
     53
     54    private:
     55        Vector<int> m_activeAttribLocations;
    4656    };
    4757   
  • trunk/WebCore/html/canvas/WebGLRenderingContext.cpp

    r57574 r57709  
    694694bool WebGLRenderingContext::validateRenderingState(long numElementsRequired)
    695695{
     696    if (!m_currentProgram)
     697        return false;
     698
    696699    // Look in each enabled vertex attrib and find the smallest buffer size
    697700    long smallestNumElements = LONG_MAX;
    698     for (unsigned i = 0; i < m_vertexAttribState.size(); ++i) {
    699         const VertexAttribState& state = m_vertexAttribState[i];
    700         if (state.enabled && state.numElements < smallestNumElements)
    701             smallestNumElements = state.numElements;
     701    int numActiveAttribLocations = m_currentProgram->numActiveAttribLocations();
     702    int numAttribStates = static_cast<int>(m_vertexAttribState.size());
     703    for (int i = 0; i < numActiveAttribLocations; ++i) {
     704        int loc = m_currentProgram->getActiveAttribLocation(i);
     705        if (loc >=0 && loc < numAttribStates) {
     706            const VertexAttribState& state = m_vertexAttribState[loc];
     707            if (state.enabled && state.numElements < smallestNumElements)
     708                smallestNumElements = state.numElements;
     709        }
    702710    }
    703711   
     
    15701578        return;
    15711579    m_context->linkProgram(program);
     1580    program->cacheActiveAttribLocations();
    15721581    cleanupAfterGraphicsCall(false);
    15731582}
Note: See TracChangeset for help on using the changeset viewer.