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