• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2019 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 
7 // MemoryObjectTest.cpp : Tests of the GL_EXT_memory_object extension.
8 
9 #include "test_utils/ANGLETest.h"
10 
11 #include "test_utils/gl_raii.h"
12 
13 namespace angle
14 {
15 
16 class MemoryObjectTest : public ANGLETest
17 {
18   protected:
MemoryObjectTest()19     MemoryObjectTest()
20     {
21         setWindowWidth(1);
22         setWindowHeight(1);
23         setConfigRedBits(8);
24         setConfigGreenBits(8);
25         setConfigBlueBits(8);
26         setConfigAlphaBits(8);
27     }
28 };
29 
30 // glIsMemoryObjectEXT must identify memory objects.
TEST_P(MemoryObjectTest,MemoryObjectShouldBeMemoryObject)31 TEST_P(MemoryObjectTest, MemoryObjectShouldBeMemoryObject)
32 {
33     ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object"));
34 
35     constexpr GLsizei kMemoryObjectCount = 2;
36     GLuint memoryObjects[kMemoryObjectCount];
37     glCreateMemoryObjectsEXT(kMemoryObjectCount, memoryObjects);
38 
39     EXPECT_FALSE(glIsMemoryObjectEXT(0));
40 
41     for (GLsizei i = 0; i < kMemoryObjectCount; ++i)
42     {
43         EXPECT_TRUE(glIsMemoryObjectEXT(memoryObjects[i]));
44     }
45 
46     glDeleteMemoryObjectsEXT(kMemoryObjectCount, memoryObjects);
47 
48     EXPECT_GL_NO_ERROR();
49 }
50 
51 // glImportMemoryFdEXT must fail for handle types that are not file descriptors.
TEST_P(MemoryObjectTest,ShouldFailValidationOnImportFdUnsupportedHandleType)52 TEST_P(MemoryObjectTest, ShouldFailValidationOnImportFdUnsupportedHandleType)
53 {
54     ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
55 
56     {
57         GLMemoryObject memoryObject;
58         GLsizei deviceMemorySize = 1;
59         int fd                   = -1;
60         glImportMemoryFdEXT(memoryObject, deviceMemorySize, GL_HANDLE_TYPE_OPAQUE_WIN32_EXT, fd);
61         EXPECT_GL_ERROR(GL_INVALID_ENUM);
62     }
63 
64     EXPECT_GL_NO_ERROR();
65 }
66 
67 // Test memory object queries
TEST_P(MemoryObjectTest,MemoryObjectQueries)68 TEST_P(MemoryObjectTest, MemoryObjectQueries)
69 {
70     ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object"));
71 
72     GLMemoryObject memoryObject;
73 
74     // Validate that the initial state of GL_DEDICATED_MEMORY_OBJECT_EXT is GL_FALSE
75     {
76         GLint dedicatedMemory = 0;
77         glGetMemoryObjectParameterivEXT(memoryObject, GL_DEDICATED_MEMORY_OBJECT_EXT,
78                                         &dedicatedMemory);
79         EXPECT_GL_NO_ERROR();
80         EXPECT_GL_FALSE(dedicatedMemory);
81     }
82 
83     // Change GL_DEDICATED_MEMORY_OBJECT_EXT to GL_TRUE
84     {
85         GLint dedicatedMemory = GL_TRUE;
86         glMemoryObjectParameterivEXT(memoryObject, GL_DEDICATED_MEMORY_OBJECT_EXT,
87                                      &dedicatedMemory);
88         EXPECT_GL_NO_ERROR();
89     }
90 
91     // Confirm that GL_DEDICATED_MEMORY_OBJECT_EXT is now TRUE
92     {
93         GLint dedicatedMemory = 0;
94         glGetMemoryObjectParameterivEXT(memoryObject, GL_DEDICATED_MEMORY_OBJECT_EXT,
95                                         &dedicatedMemory);
96         EXPECT_GL_NO_ERROR();
97         EXPECT_GL_TRUE(dedicatedMemory);
98     }
99 
100     EXPECT_GL_NO_ERROR();
101 }
102 
103 // Use this to select which configurations (e.g. which renderer, which GLES major version) these
104 // tests should be run against.
105 ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(MemoryObjectTest);
106 
107 }  // namespace angle
108