xref: /aosp_15_r20/external/OpenCL-CTS/test_conformance/gl/test_images_2D.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 "testBase.h"
17 #include "common.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 #include <algorithm>
26 
27 using namespace std;
28 
29 #pragma mark -
30 #pragma mark _2D read tests
31 
calc_2D_test_size_descriptors(sizevec_t * sizes,size_t nsizes)32 void calc_2D_test_size_descriptors(sizevec_t* sizes, size_t nsizes)
33 {
34     // Need to limit array size according to GL device properties
35     // Need to limit texture size according to GL device properties
36     GLint maxTextureSize = 4096, maxTextureRectangleSize = 4096, size;
37     glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
38     glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_EXT, &maxTextureRectangleSize);
39 
40     size = min(maxTextureSize, maxTextureRectangleSize);
41 
42     RandomSeed seed(gRandomSeed);
43 
44     // Generate some random sizes (within reasonable ranges)
45     for (size_t i = 0; i < nsizes; i++)
46     {
47         sizes[i].width = random_in_range(2, min(size, 1 << (i + 4)), seed);
48         sizes[i].height = random_in_range(2, min(size, 1 << (i + 4)), seed);
49         sizes[i].depth = 1;
50     }
51 }
52 
calc_cube_test_size_descriptors(sizevec_t * sizes,size_t nsizes)53 void calc_cube_test_size_descriptors(sizevec_t* sizes, size_t nsizes)
54 {
55     // Need to limit array size according to GL device properties
56     // Need to limit texture size according to GL device properties
57     GLint maxQubeMapSize = 4096;
58     glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &maxQubeMapSize);
59 
60     RandomSeed seed(gRandomSeed);
61 
62     // Generate some random sizes (within reasonable ranges)
63     for (size_t i = 0; i < nsizes; i++)
64     {
65         sizes[i].width = sizes[i].height =
66             random_in_range(2, min(maxQubeMapSize, 1 << (i + 4)), seed);
67         sizes[i].depth = 1;
68     }
69 }
70 
test_images_read_2D(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)71 int test_images_read_2D(cl_device_id device, cl_context context,
72                         cl_command_queue queue, int numElements)
73 {
74     GLenum targets[] = { GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_EXT };
75     size_t ntargets = sizeof(targets) / sizeof(targets[0]);
76 
77     size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
78 
79     const size_t nsizes = 8;
80     sizevec_t sizes[nsizes];
81     calc_2D_test_size_descriptors(sizes, nsizes);
82 
83     return test_images_read_common(device, context, queue, common_formats,
84                                    nformats, targets, ntargets, sizes, nsizes);
85 }
86 
test_images_read_cube(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)87 int test_images_read_cube(cl_device_id device, cl_context context,
88                           cl_command_queue queue, int numElements)
89 {
90     GLenum targets[] = {
91         GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
92         GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
93         GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
94     };
95 
96     size_t ntargets = sizeof(targets) / sizeof(targets[0]);
97     size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
98 
99     const size_t nsizes = 8;
100     sizevec_t sizes[nsizes];
101     calc_cube_test_size_descriptors(sizes, nsizes);
102 
103     return test_images_read_common(device, context, queue, common_formats,
104                                    nformats, targets, ntargets, sizes, nsizes);
105 }
106 
107 #pragma mark -
108 #pragma mark _2D write tests
109 
110 #include "common.h"
111 
test_images_write(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)112 int test_images_write(cl_device_id device, cl_context context,
113                       cl_command_queue queue, int numElements)
114 {
115     GLenum targets[] = { GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_EXT };
116     size_t ntargets = sizeof(targets) / sizeof(targets[0]);
117     size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
118 
119     const size_t nsizes = 8;
120     sizevec_t sizes[nsizes];
121     calc_2D_test_size_descriptors(sizes, nsizes);
122 
123     return test_images_write_common(device, context, queue, common_formats,
124                                     nformats, targets, ntargets, sizes, nsizes);
125 }
126 
test_images_write_cube(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)127 int test_images_write_cube(cl_device_id device, cl_context context,
128                            cl_command_queue queue, int numElements)
129 {
130     size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
131 
132     GLenum targets[] = {
133         GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
134         GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
135         GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
136     };
137     size_t ntargets = sizeof(targets) / sizeof(targets[0]);
138 
139     const size_t nsizes = 8;
140     sizevec_t sizes[nsizes];
141     calc_cube_test_size_descriptors(sizes, nsizes);
142 
143     return test_images_write_common(device, context, queue, common_formats,
144                                     nformats, targets, ntargets, sizes, nsizes);
145 }
146 
147 #pragma mark -
148 #pragma mark _2D get info tests
149 
test_images_2D_getinfo(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)150 int test_images_2D_getinfo(cl_device_id device, cl_context context,
151                            cl_command_queue queue, int numElements)
152 {
153     GLenum targets[] = { GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_EXT };
154     size_t ntargets = sizeof(targets) / sizeof(targets[0]);
155 
156     size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
157 
158     const size_t nsizes = 8;
159     sizevec_t sizes[nsizes];
160     calc_2D_test_size_descriptors(sizes, nsizes);
161 
162     return test_images_get_info_common(device, context, queue, common_formats,
163                                        nformats, targets, ntargets, sizes,
164                                        nsizes);
165 }
166 
test_images_cube_getinfo(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)167 int test_images_cube_getinfo(cl_device_id device, cl_context context,
168                              cl_command_queue queue, int numElements)
169 {
170     GLenum targets[] = {
171         GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
172         GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
173         GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
174     };
175     size_t ntargets = sizeof(targets) / sizeof(targets[0]);
176     size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
177 
178     const size_t nsizes = 8;
179     sizevec_t sizes[nsizes];
180     calc_cube_test_size_descriptors(sizes, nsizes);
181 
182     return test_images_get_info_common(device, context, queue, common_formats,
183                                        nformats, targets, ntargets, sizes,
184                                        nsizes);
185 }
186