xref: /aosp_15_r20/external/OpenCL-CTS/test_conformance/gl/test_images_1D.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;
28 
calc_test_size_descriptors(sizevec_t * sizes,size_t nsizes)29 void calc_test_size_descriptors(sizevec_t* sizes, size_t nsizes)
30 {
31     // Need to limit array size according to GL device properties
32     GLint maxTextureSize = 4096, maxTextureBufferSize = 4096, size;
33     glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
34     glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &maxTextureBufferSize);
35 
36     size = min(maxTextureSize, maxTextureBufferSize);
37 
38     RandomSeed seed(gRandomSeed);
39 
40     // Generate some random sizes (within reasonable ranges)
41     for (size_t i = 0; i < nsizes; i++)
42     {
43         sizes[i].width = random_in_range(2, min(size, 1 << (i + 4)), seed);
44         sizes[i].height = 1;
45         sizes[i].depth = 1;
46     }
47 }
48 
test_images_read_1D(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)49 int test_images_read_1D(cl_device_id device, cl_context context,
50                         cl_command_queue queue, int numElements)
51 {
52     size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
53 
54     GLenum targets[] = { GL_TEXTURE_1D };
55     size_t ntargets = sizeof(targets) / sizeof(targets[0]);
56 
57     const size_t nsizes = 8;
58     sizevec_t sizes[nsizes];
59     calc_test_size_descriptors(sizes, nsizes);
60 
61     return test_images_read_common(device, context, queue, common_formats,
62                                    nformats, targets, ntargets, sizes, nsizes);
63 }
64 
test_images_write_1D(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)65 int test_images_write_1D(cl_device_id device, cl_context context,
66                          cl_command_queue queue, int numElements)
67 {
68     GLenum targets[] = { GL_TEXTURE_1D };
69     size_t ntargets = sizeof(targets) / sizeof(targets[0]);
70     size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
71 
72     const size_t nsizes = 8;
73     sizevec_t sizes[nsizes];
74     calc_test_size_descriptors(sizes, nsizes);
75 
76     return test_images_write_common(device, context, queue, common_formats,
77                                     nformats, targets, ntargets, sizes, nsizes);
78 }
79 
test_images_1D_getinfo(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)80 int test_images_1D_getinfo(cl_device_id device, cl_context context,
81                            cl_command_queue queue, int numElements)
82 {
83     size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
84 
85     GLenum targets[] = { GL_TEXTURE_1D };
86     size_t ntargets = sizeof(targets) / sizeof(targets[0]);
87 
88     const size_t nsizes = 8;
89     sizevec_t sizes[nsizes];
90     calc_test_size_descriptors(sizes, nsizes);
91 
92     return test_images_get_info_common(device, context, queue, common_formats,
93                                        nformats, targets, ntargets, sizes,
94                                        nsizes);
95 }
96 
test_images_read_texturebuffer(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)97 int test_images_read_texturebuffer(cl_device_id device, cl_context context,
98                                    cl_command_queue queue, int numElements)
99 {
100     size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
101 
102     GLenum targets[] = { GL_TEXTURE_BUFFER };
103     size_t ntargets = sizeof(targets) / sizeof(targets[0]);
104 
105     const size_t nsizes = 8;
106     sizevec_t sizes[nsizes];
107     calc_test_size_descriptors(sizes, nsizes);
108 
109     return test_images_read_common(device, context, queue, common_formats,
110                                    nformats, targets, ntargets, sizes, nsizes);
111 }
112 
test_images_write_texturebuffer(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)113 int test_images_write_texturebuffer(cl_device_id device, cl_context context,
114                                     cl_command_queue queue, int numElements)
115 {
116     GLenum targets[] = { GL_TEXTURE_BUFFER };
117     size_t ntargets = sizeof(targets) / sizeof(targets[0]);
118     size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
119 
120     const size_t nsizes = 8;
121     sizevec_t sizes[nsizes];
122     calc_test_size_descriptors(sizes, nsizes);
123 
124     return test_images_write_common(device, context, queue, common_formats,
125                                     nformats, targets, ntargets, sizes, nsizes);
126 }
127 
test_images_texturebuffer_getinfo(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)128 int test_images_texturebuffer_getinfo(cl_device_id device, cl_context context,
129                                       cl_command_queue queue, int numElements)
130 {
131     size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
132 
133     GLenum targets[] = { GL_TEXTURE_BUFFER };
134     size_t ntargets = sizeof(targets) / sizeof(targets[0]);
135 
136     const size_t nsizes = 8;
137     sizevec_t sizes[nsizes];
138     calc_test_size_descriptors(sizes, nsizes);
139 
140     return test_images_get_info_common(device, context, queue, common_formats,
141                                        nformats, targets, ntargets, sizes,
142                                        nsizes);
143 }
144