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_2D_array_size_descriptors(sizevec_t * sizes,size_t nsizes)29 void calc_2D_array_size_descriptors(sizevec_t* sizes, size_t nsizes)
30 {
31 // Need to limit array size according to GL device properties
32 GLint maxTextureLayers = 16, maxTextureSize = 4096;
33 glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &maxTextureLayers);
34 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
35
36 RandomSeed seed(gRandomSeed);
37
38 // Generate some random sizes (within reasonable ranges)
39 for (size_t i = 0; i < nsizes; i++)
40 {
41 sizes[i].width =
42 random_in_range(2, min(maxTextureSize, 1 << (i + 4)), seed);
43 sizes[i].height =
44 random_in_range(2, min(maxTextureSize, 1 << (i + 4)), seed);
45 sizes[i].depth =
46 random_in_range(2, min(maxTextureLayers, 1 << (i + 4)), seed);
47 }
48 }
49
test_images_read_2Darray(cl_device_id device,cl_context context,cl_command_queue queue,int)50 int test_images_read_2Darray(cl_device_id device, cl_context context,
51 cl_command_queue queue, int)
52 {
53 size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
54
55 GLenum targets[] = { GL_TEXTURE_2D_ARRAY };
56 size_t ntargets = sizeof(targets) / sizeof(targets[0]);
57
58 const size_t nsizes = 6;
59 sizevec_t sizes[nsizes];
60 calc_2D_array_size_descriptors(sizes, nsizes);
61
62 return test_images_read_common(device, context, queue, common_formats,
63 nformats, targets, ntargets, sizes, nsizes);
64 }
65
test_images_write_2Darray(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)66 int test_images_write_2Darray(cl_device_id device, cl_context context,
67 cl_command_queue queue, int numElements)
68 {
69 // FIXME: Query for 2D image array write support.
70
71 GLenum targets[] = { GL_TEXTURE_2D_ARRAY };
72 size_t ntargets = sizeof(targets) / sizeof(targets[0]);
73 size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
74
75 const size_t nsizes = 6;
76 sizevec_t sizes[nsizes];
77 calc_2D_array_size_descriptors(sizes, nsizes);
78
79 return test_images_write_common(device, context, queue, common_formats,
80 nformats, targets, ntargets, sizes, nsizes);
81 }
82
test_images_2Darray_getinfo(cl_device_id device,cl_context context,cl_command_queue queue,int)83 int test_images_2Darray_getinfo(cl_device_id device, cl_context context,
84 cl_command_queue queue, int)
85 {
86 size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
87
88 GLenum targets[] = { GL_TEXTURE_2D_ARRAY };
89 size_t ntargets = sizeof(targets) / sizeof(targets[0]);
90
91 const size_t nsizes = 6;
92 sizevec_t sizes[nsizes];
93 calc_2D_array_size_descriptors(sizes, nsizes);
94
95 return test_images_get_info_common(device, context, queue, common_formats,
96 nformats, targets, ntargets, sizes,
97 nsizes);
98 }