xref: /aosp_15_r20/external/OpenCL-CTS/test_conformance/gl/test_images_1Darray.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 #include <algorithm>
26 
27 using namespace std;
calc_1D_array_size_descriptors(sizevec_t * sizes,size_t nsizes)28 void calc_1D_array_size_descriptors(sizevec_t* sizes, size_t nsizes)
29 {
30     // Need to limit array size according to GL device properties
31     GLint maxTextureLayers = 16, maxTextureSize = 4096;
32     glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &maxTextureLayers);
33     glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
34 
35     RandomSeed seed(gRandomSeed);
36 
37     // Generate some random sizes (within reasonable ranges)
38     for (size_t i = 0; i < nsizes; i++)
39     {
40         sizes[i].width =
41             random_in_range(2, min(maxTextureSize, 1 << (i + 4)), seed);
42         sizes[i].height =
43             random_in_range(2, min(maxTextureLayers, 1 << (i + 4)), seed);
44         sizes[i].depth = 1;
45     }
46 }
47 
test_images_read_1Darray(cl_device_id device,cl_context context,cl_command_queue queue,int)48 int test_images_read_1Darray(cl_device_id device, cl_context context,
49                              cl_command_queue queue, int)
50 {
51     size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
52 
53     GLenum targets[] = { GL_TEXTURE_1D_ARRAY };
54     size_t ntargets = sizeof(targets) / sizeof(targets[0]);
55 
56     const size_t nsizes = 8;
57     sizevec_t sizes[nsizes];
58     calc_1D_array_size_descriptors(sizes, nsizes);
59 
60     return test_images_read_common(device, context, queue, common_formats,
61                                    nformats, targets, ntargets, sizes, nsizes);
62 }
63 
test_images_write_1Darray(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)64 int test_images_write_1Darray(cl_device_id device, cl_context context,
65                               cl_command_queue queue, int numElements)
66 {
67     GLenum targets[] = { GL_TEXTURE_1D_ARRAY };
68     size_t ntargets = sizeof(targets) / sizeof(targets[0]);
69     size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
70 
71     const size_t nsizes = 8;
72     sizevec_t sizes[nsizes];
73     calc_1D_array_size_descriptors(sizes, nsizes);
74 
75     return test_images_write_common(device, context, queue, common_formats,
76                                     nformats, targets, ntargets, sizes, nsizes);
77 }
78 
test_images_1Darray_getinfo(cl_device_id device,cl_context context,cl_command_queue queue,int)79 int test_images_1Darray_getinfo(cl_device_id device, cl_context context,
80                                 cl_command_queue queue, int)
81 {
82     size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
83 
84     GLenum targets[] = { GL_TEXTURE_1D_ARRAY };
85     size_t ntargets = sizeof(targets) / sizeof(targets[0]);
86 
87     const size_t nsizes = 8;
88     sizevec_t sizes[nsizes];
89     calc_1D_array_size_descriptors(sizes, nsizes);
90 
91     return test_images_get_info_common(device, context, queue, common_formats,
92                                        nformats, targets, ntargets, sizes,
93                                        nsizes);
94 }