xref: /aosp_15_r20/external/OpenCL-CTS/test_conformance/gl/test_images_multisample.cpp (revision 6467f958c7de8070b317fc65bcb0f6472e388d82)
1 //
2 // Copyright (c) 2017 The Khronos Group Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //    http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 #include "common.h"
17 #include "testBase.h"
18 
19 #if defined(__APPLE__)
20 #include <OpenGL/glu.h>
21 #else
22 #include <GL/glu.h>
23 #include <CL/cl_gl.h>
24 #endif
25 
26 #include <algorithm>
27 
28 using namespace std;
29 
calc_2D_multisample_size_descriptors(sizevec_t * sizes,size_t nsizes)30 void calc_2D_multisample_size_descriptors(sizevec_t* sizes, size_t nsizes)
31 {
32     // Need to limit texture size according to GL device properties
33     GLint maxTextureSize = 4096;
34     glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
35 
36     RandomSeed seed(gRandomSeed);
37 
38     // Generate some random sizes (within reasonable ranges)
39     for (size_t i = 0; i < nsizes; i++)
40     {
41         sizes[i].width =
42             random_in_range(2, min(maxTextureSize, 1 << (i + 4)), seed);
43         sizes[i].height =
44             random_in_range(2, min(maxTextureSize, 1 << (i + 4)), seed);
45         sizes[i].depth = 1;
46     }
47 }
48 
calc_2D_array_multisample_size_descriptors(sizevec_t * sizes,size_t nsizes)49 void calc_2D_array_multisample_size_descriptors(sizevec_t* sizes, size_t nsizes)
50 {
51     // Need to limit array size according to GL device properties
52     GLint maxTextureLayers = 16, maxTextureSize = 4096;
53     glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &maxTextureLayers);
54     glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
55 
56     RandomSeed seed(gRandomSeed);
57 
58     // Generate some random sizes (within reasonable ranges)
59     for (size_t i = 0; i < nsizes; i++)
60     {
61         sizes[i].width =
62             random_in_range(2, min(maxTextureSize, 1 << (i + 4)), seed);
63         sizes[i].height =
64             random_in_range(2, min(maxTextureSize, 1 << (i + 4)), seed);
65         sizes[i].depth =
66             random_in_range(2, min(maxTextureLayers, 1 << (i + 4)), seed);
67     }
68 }
69 
test_images_read_2D_multisample(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)70 int test_images_read_2D_multisample(cl_device_id device, cl_context context,
71                                     cl_command_queue queue, int numElements)
72 {
73     if (!is_extension_available(device, "cl_khr_gl_msaa_sharing"))
74     {
75         log_info("Test not run because 'cl_khr_gl_msaa_sharing' extension is "
76                  "not supported by the tested device\n");
77         return 0;
78     }
79 
80     glEnable(GL_MULTISAMPLE);
81 
82     const size_t nsizes = 8;
83     sizevec_t sizes[nsizes];
84     calc_2D_multisample_size_descriptors(sizes, nsizes);
85 
86     size_t nformats;
87 
88     GLenum targets[] = { GL_TEXTURE_2D_MULTISAMPLE };
89     size_t ntargets = sizeof(targets) / sizeof(targets[0]);
90 
91     nformats = sizeof(common_formats) / sizeof(common_formats[0]);
92     int ret_common =
93         test_images_read_common(device, context, queue, common_formats,
94                                 nformats, targets, ntargets, sizes, nsizes);
95 
96     nformats = sizeof(depth_formats) / sizeof(depth_formats[0]);
97     int ret_depth =
98         test_images_read_common(device, context, queue, depth_formats, nformats,
99                                 targets, ntargets, sizes, nsizes);
100 
101     return (ret_common) ? ret_common : ret_depth;
102 }
103 
test_images_read_2Darray_multisample(cl_device_id device,cl_context context,cl_command_queue queue,int)104 int test_images_read_2Darray_multisample(cl_device_id device,
105                                          cl_context context,
106                                          cl_command_queue queue, int)
107 {
108     if (!is_extension_available(device, "cl_khr_gl_msaa_sharing"))
109     {
110         log_info("Test not run because 'cl_khr_gl_msaa_sharing' extension is "
111                  "not supported by the tested device\n");
112         return 0;
113     }
114 
115     glEnable(GL_MULTISAMPLE);
116 
117     const size_t nsizes = 4;
118     sizevec_t sizes[nsizes];
119     calc_2D_array_multisample_size_descriptors(sizes, nsizes);
120 
121     size_t nformats;
122 
123     GLenum targets[] = { GL_TEXTURE_2D_MULTISAMPLE_ARRAY };
124     size_t ntargets = sizeof(targets) / sizeof(targets[0]);
125 
126     nformats = sizeof(common_formats) / sizeof(common_formats[0]);
127     int ret_common =
128         test_images_read_common(device, context, queue, common_formats,
129                                 nformats, targets, ntargets, sizes, nsizes);
130 
131     nformats = sizeof(depth_formats) / sizeof(depth_formats[0]);
132     int ret_depth =
133         test_images_read_common(device, context, queue, depth_formats, nformats,
134                                 targets, ntargets, sizes, nsizes);
135 
136     return (ret_common) ? ret_common : ret_depth;
137 }
138