xref: /aosp_15_r20/external/OpenCL-CTS/test_conformance/gl/test_images_depth.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 
26 #include <algorithm>
27 
28 using namespace std;
29 
30 #pragma mark -
31 #pragma mark _2D depth read tests
32 
calc_depth_size_descriptors(sizevec_t * sizes,size_t nsizes)33 void calc_depth_size_descriptors(sizevec_t* sizes, size_t nsizes)
34 {
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_depth_array_size_descriptors(sizevec_t * sizes,size_t nsizes)53 void calc_depth_array_size_descriptors(sizevec_t* sizes, size_t nsizes)
54 {
55     // Need to limit texture size according to GL device properties
56     GLint maxTextureSize = 4096, maxTextureRectangleSize = 4096,
57           maxTextureLayers = 16, size;
58     glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
59     glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_EXT, &maxTextureRectangleSize);
60     glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &maxTextureLayers);
61 
62     size = min(maxTextureSize, maxTextureRectangleSize);
63 
64     RandomSeed seed(gRandomSeed);
65 
66     // Generate some random sizes (within reasonable ranges)
67     for (size_t i = 0; i < nsizes; i++)
68     {
69         sizes[i].width = random_in_range(2, min(size, 1 << (i + 4)), seed);
70         sizes[i].height = random_in_range(2, min(size, 1 << (i + 4)), seed);
71         sizes[i].depth =
72             random_in_range(2, min(maxTextureLayers, 1 << (i + 4)), seed);
73     }
74 }
75 
test_images_read_2D_depth(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)76 int test_images_read_2D_depth(cl_device_id device, cl_context context,
77                               cl_command_queue queue, int numElements)
78 {
79     if (!is_extension_available(device, "cl_khr_gl_depth_images"))
80     {
81         log_info("Test not run because 'cl_khr_gl_depth_images' extension is "
82                  "not supported by the tested device\n");
83         return 0;
84     }
85 
86     RandomSeed seed(gRandomSeed);
87 
88     GLenum targets[] = { GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_EXT };
89     size_t ntargets = sizeof(targets) / sizeof(targets[0]);
90 
91     size_t nformats = sizeof(depth_formats) / sizeof(depth_formats[0]);
92 
93     const size_t nsizes = 8;
94     sizevec_t sizes[nsizes];
95     calc_depth_size_descriptors(sizes, nsizes);
96 
97     return test_images_read_common(device, context, queue, depth_formats,
98                                    nformats, targets, ntargets, sizes, nsizes);
99 }
100 
101 #pragma mark -
102 #pragma mark _2D depth write tests
103 
104 
test_images_write_2D_depth(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)105 int test_images_write_2D_depth(cl_device_id device, cl_context context,
106                                cl_command_queue queue, int numElements)
107 {
108     if (!is_extension_available(device, "cl_khr_gl_depth_images"))
109     {
110         log_info("Test not run because 'cl_khr_gl_depth_images' extension is "
111                  "not supported by the tested device\n");
112         return 0;
113     }
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(depth_formats) / sizeof(depth_formats[0]);
118 
119     const size_t nsizes = 8;
120     sizevec_t sizes[nsizes];
121     calc_depth_size_descriptors(sizes, nsizes);
122 
123     return test_images_write_common(device, context, queue, depth_formats,
124                                     nformats, targets, ntargets, sizes, nsizes);
125 }
126 
test_images_read_2Darray_depth(cl_device_id device,cl_context context,cl_command_queue queue,int)127 int test_images_read_2Darray_depth(cl_device_id device, cl_context context,
128                                    cl_command_queue queue, int)
129 {
130     if (!is_extension_available(device, "cl_khr_gl_depth_images"))
131     {
132         log_info("Test not run because 'cl_khr_gl_depth_images' extension is "
133                  "not supported by the tested device\n");
134         return 0;
135     }
136 
137     size_t nformats = sizeof(depth_formats) / sizeof(depth_formats[0]);
138     GLenum targets[] = { GL_TEXTURE_2D_ARRAY };
139     size_t ntargets = sizeof(targets) / sizeof(targets[0]);
140 
141     const size_t nsizes = 6;
142     sizevec_t sizes[nsizes];
143     calc_depth_array_size_descriptors(sizes, nsizes);
144 
145     return test_images_read_common(device, context, queue, depth_formats,
146                                    nformats, targets, ntargets, sizes, nsizes);
147 }
148 
test_images_write_2Darray_depth(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)149 int test_images_write_2Darray_depth(cl_device_id device, cl_context context,
150                                     cl_command_queue queue, int numElements)
151 {
152     if (!is_extension_available(device, "cl_khr_gl_depth_images"))
153     {
154         log_info("Test not run because 'cl_khr_gl_depth_images' extension is "
155                  "not supported by the tested device\n");
156         return 0;
157     }
158 
159     // FIXME: Query for 2D image array write support.
160 
161     GLenum targets[] = { GL_TEXTURE_2D_ARRAY };
162     size_t ntargets = sizeof(targets) / sizeof(targets[0]);
163     size_t nformats = sizeof(depth_formats) / sizeof(depth_formats[0]);
164 
165     const size_t nsizes = 6;
166     sizevec_t sizes[nsizes];
167     calc_depth_array_size_descriptors(sizes, nsizes);
168 
169     return test_images_write_common(device, context, queue, depth_formats,
170                                     nformats, targets, ntargets, sizes, nsizes);
171 }
172