Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2015 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | // validationES unit tests: |
| 7 | // Unit tests for general ES validation functions. |
| 8 | // |
| 9 | |
| 10 | #include <gmock/gmock.h> |
| 11 | #include <gtest/gtest.h> |
| 12 | |
Jamie Madill | 9082b98 | 2016-04-27 15:21:51 -0400 | [diff] [blame] | 13 | #include "libANGLE/ContextState.h" |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 14 | #include "libANGLE/ErrorStrings.h" |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 15 | #include "libANGLE/VaryingPacking.h" |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 16 | #include "libANGLE/renderer/FramebufferImpl_mock.h" |
| 17 | #include "libANGLE/renderer/ProgramImpl_mock.h" |
| 18 | #include "libANGLE/renderer/TextureImpl_mock.h" |
| 19 | #include "libANGLE/validationES.h" |
| 20 | #include "tests/angle_unittests_utils.h" |
| 21 | |
| 22 | using namespace gl; |
| 23 | using namespace rx; |
| 24 | using testing::_; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 25 | using testing::NiceMock; |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 26 | using testing::Return; |
| 27 | |
| 28 | namespace |
| 29 | { |
| 30 | |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 31 | class MockValidationContext : public ValidationContext |
| 32 | { |
| 33 | public: |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 34 | MockValidationContext(const ValidationContext *shareContext, |
Geoff Lang | ce02f08 | 2017-02-06 16:46:21 -0500 | [diff] [blame] | 35 | TextureManager *shareTextures, |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 36 | const Version &version, |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 37 | State *state, |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 38 | const Caps &caps, |
| 39 | const TextureCapsMap &textureCaps, |
| 40 | const Extensions &extensions, |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 41 | const Limitations &limitations, |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 42 | bool skipValidation) |
| 43 | : ValidationContext(shareContext, |
Geoff Lang | ce02f08 | 2017-02-06 16:46:21 -0500 | [diff] [blame] | 44 | shareTextures, |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 45 | version, |
| 46 | state, |
| 47 | caps, |
| 48 | textureCaps, |
| 49 | extensions, |
| 50 | limitations, |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 51 | skipValidation) |
| 52 | { |
| 53 | } |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 54 | |
Jamie Madill | 4c19a8a | 2017-07-24 11:46:06 -0400 | [diff] [blame^] | 55 | MOCK_METHOD1(handleError, Error(const Error &)); |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 56 | }; |
| 57 | |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 58 | // Test that ANGLE generates an INVALID_OPERATION when validating index data that uses a value |
| 59 | // larger than MAX_ELEMENT_INDEX. Not specified in the GLES 3 spec, it's undefined behaviour, |
| 60 | // but we want a test to ensure we maintain this behaviour. |
Jamie Madill | fa416b1 | 2017-04-06 11:34:17 -0400 | [diff] [blame] | 61 | // TODO(jmadill): Re-enable when framebuffer sync state doesn't happen in validation. |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 62 | // Also broken because of change of api of the state initialize method. |
Jamie Madill | fa416b1 | 2017-04-06 11:34:17 -0400 | [diff] [blame] | 63 | TEST(ValidationESTest, DISABLED_DrawElementsWithMaxIndexGivesError) |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 64 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 65 | auto framebufferImpl = MakeFramebufferMock(); |
| 66 | auto programImpl = MakeProgramMock(); |
| 67 | |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 68 | // TODO(jmadill): Generalize some of this code so we can re-use it for other tests. |
Jamie Madill | 7aea7e0 | 2016-05-10 10:39:45 -0400 | [diff] [blame] | 69 | NiceMock<MockGLFactory> mockFactory; |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 70 | EXPECT_CALL(mockFactory, createFramebuffer(_)).WillOnce(Return(framebufferImpl)); |
| 71 | EXPECT_CALL(mockFactory, createProgram(_)).WillOnce(Return(programImpl)); |
| 72 | EXPECT_CALL(mockFactory, createVertexArray(_)).WillOnce(Return(nullptr)); |
| 73 | |
| 74 | State state; |
| 75 | Caps caps; |
| 76 | TextureCapsMap textureCaps; |
| 77 | Extensions extensions; |
| 78 | Limitations limitations; |
| 79 | |
| 80 | // Set some basic caps. |
| 81 | caps.maxElementIndex = 100; |
| 82 | caps.maxDrawBuffers = 1; |
| 83 | caps.maxColorAttachments = 1; |
Jamie Madill | c43be72 | 2017-07-13 16:22:14 -0400 | [diff] [blame] | 84 | state.initialize(nullptr, false, true, true, false, false); |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 85 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 86 | NiceMock<MockTextureImpl> *textureImpl = new NiceMock<MockTextureImpl>(); |
Olli Etuaho | 82c47ad | 2016-04-20 18:28:47 +0300 | [diff] [blame] | 87 | EXPECT_CALL(mockFactory, createTexture(_)).WillOnce(Return(textureImpl)); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 88 | EXPECT_CALL(*textureImpl, setStorage(_, _, _, _, _)).WillOnce(Return(gl::NoError())); |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 89 | EXPECT_CALL(*textureImpl, destructor()).Times(1).RetiresOnSaturation(); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 90 | |
Olli Etuaho | 82c47ad | 2016-04-20 18:28:47 +0300 | [diff] [blame] | 91 | Texture *texture = new Texture(&mockFactory, 0, GL_TEXTURE_2D); |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 92 | texture->addRef(); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 93 | texture->setStorage(nullptr, GL_TEXTURE_2D, 1, GL_RGBA8, Extents(1, 1, 0)); |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 94 | |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 95 | VertexArray *vertexArray = new VertexArray(&mockFactory, 0, 1, 1); |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 96 | Framebuffer *framebuffer = new Framebuffer(caps, &mockFactory, 1); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 97 | framebuffer->setAttachment(nullptr, GL_FRAMEBUFFER_DEFAULT, GL_BACK, ImageIndex::Make2D(0), |
| 98 | texture); |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 99 | |
| 100 | Program *program = new Program(&mockFactory, nullptr, 1); |
| 101 | |
| 102 | state.setVertexArrayBinding(vertexArray); |
| 103 | state.setDrawFramebufferBinding(framebuffer); |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 104 | state.setProgram(nullptr, program); |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 105 | |
Geoff Lang | ce02f08 | 2017-02-06 16:46:21 -0500 | [diff] [blame] | 106 | NiceMock<MockValidationContext> testContext(nullptr, nullptr, Version(3, 0), &state, caps, |
| 107 | textureCaps, extensions, limitations, false); |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 108 | |
| 109 | // Set the expectation for the validation error here. |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 110 | |
| 111 | Error expectedError(gl::InvalidOperation() << kErrorExceedsMaxElement); |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 112 | EXPECT_CALL(testContext, handleError(expectedError)).Times(1); |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 113 | |
| 114 | // Call once with maximum index, and once with an excessive index. |
| 115 | GLuint indexData[] = {0, 1, static_cast<GLuint>(caps.maxElementIndex - 1), |
| 116 | 3, 4, static_cast<GLuint>(caps.maxElementIndex)}; |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 117 | EXPECT_TRUE( |
| 118 | ValidateDrawElementsCommon(&testContext, GL_TRIANGLES, 3, GL_UNSIGNED_INT, indexData, 1)); |
| 119 | EXPECT_FALSE( |
| 120 | ValidateDrawElementsCommon(&testContext, GL_TRIANGLES, 6, GL_UNSIGNED_INT, indexData, 2)); |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 121 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 122 | texture->release(nullptr); |
Jamie Madill | daa8c27 | 2015-11-18 14:13:55 -0500 | [diff] [blame] | 123 | |
| 124 | state.setVertexArrayBinding(nullptr); |
| 125 | state.setDrawFramebufferBinding(nullptr); |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 126 | state.setProgram(nullptr, nullptr); |
Jamie Madill | daa8c27 | 2015-11-18 14:13:55 -0500 | [diff] [blame] | 127 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 128 | vertexArray->onDestroy(nullptr); |
| 129 | framebuffer->onDestroy(nullptr); |
| 130 | program->onDestroy(nullptr); |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | } // anonymous namespace |