xref: /aosp_15_r20/external/angle/src/tests/gl_tests/MemoryObjectTest.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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     // http://anglebug.com/42263921
36     ANGLE_SKIP_TEST_IF(IsLinux() && IsAMD() && IsDesktopOpenGL());
37 
38     constexpr GLsizei kMemoryObjectCount = 2;
39     GLuint memoryObjects[kMemoryObjectCount];
40     glCreateMemoryObjectsEXT(kMemoryObjectCount, memoryObjects);
41 
42     EXPECT_FALSE(glIsMemoryObjectEXT(0));
43 
44     for (GLsizei i = 0; i < kMemoryObjectCount; ++i)
45     {
46         EXPECT_TRUE(glIsMemoryObjectEXT(memoryObjects[i]));
47     }
48 
49     glDeleteMemoryObjectsEXT(kMemoryObjectCount, memoryObjects);
50 
51     EXPECT_GL_NO_ERROR();
52 }
53 
54 // glImportMemoryFdEXT must fail for handle types that are not file descriptors.
TEST_P(MemoryObjectTest,ShouldFailValidationOnImportFdUnsupportedHandleType)55 TEST_P(MemoryObjectTest, ShouldFailValidationOnImportFdUnsupportedHandleType)
56 {
57     ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
58 
59     // http://anglebug.com/42263921
60     ANGLE_SKIP_TEST_IF(IsLinux() && IsAMD() && IsDesktopOpenGL());
61 
62     {
63         GLMemoryObject memoryObject;
64         GLsizei deviceMemorySize = 1;
65         int fd                   = -1;
66         glImportMemoryFdEXT(memoryObject, deviceMemorySize, GL_HANDLE_TYPE_OPAQUE_WIN32_EXT, fd);
67         EXPECT_GL_ERROR(GL_INVALID_ENUM);
68     }
69 
70     EXPECT_GL_NO_ERROR();
71 }
72 
73 // Test memory object queries
TEST_P(MemoryObjectTest,MemoryObjectQueries)74 TEST_P(MemoryObjectTest, MemoryObjectQueries)
75 {
76     ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object"));
77 
78     // http://anglebug.com/42263921
79     ANGLE_SKIP_TEST_IF(IsLinux() && IsAMD() && IsDesktopOpenGL());
80 
81     GLMemoryObject memoryObject;
82 
83     // Validate that the initial state of GL_DEDICATED_MEMORY_OBJECT_EXT is GL_FALSE
84     {
85         GLint dedicatedMemory = 0;
86         glGetMemoryObjectParameterivEXT(memoryObject, GL_DEDICATED_MEMORY_OBJECT_EXT,
87                                         &dedicatedMemory);
88         EXPECT_GL_NO_ERROR();
89         EXPECT_GL_FALSE(dedicatedMemory);
90     }
91 
92     // Change GL_DEDICATED_MEMORY_OBJECT_EXT to GL_TRUE
93     {
94         GLint dedicatedMemory = GL_TRUE;
95         glMemoryObjectParameterivEXT(memoryObject, GL_DEDICATED_MEMORY_OBJECT_EXT,
96                                      &dedicatedMemory);
97         EXPECT_GL_NO_ERROR();
98     }
99 
100     // Confirm that GL_DEDICATED_MEMORY_OBJECT_EXT is now TRUE
101     {
102         GLint dedicatedMemory = 0;
103         glGetMemoryObjectParameterivEXT(memoryObject, GL_DEDICATED_MEMORY_OBJECT_EXT,
104                                         &dedicatedMemory);
105         EXPECT_GL_NO_ERROR();
106         EXPECT_GL_TRUE(dedicatedMemory);
107     }
108 
109     EXPECT_GL_NO_ERROR();
110 }
111 
112 // Use this to select which configurations (e.g. which renderer, which GLES major version) these
113 // tests should be run against.
114 ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(MemoryObjectTest);
115 
116 }  // namespace angle
117