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 sizes[i].width = random_in_range( 2, min(maxTextureSize, 1<<(i+4)), seed );
41 sizes[i].height = random_in_range( 2, min(maxTextureSize, 1<<(i+4)), seed );
42 sizes[i].depth = random_in_range( 2, min(maxTextureLayers, 1<<(i+4)), seed );
43 }
44 }
45
test_images_read_2Darray(cl_device_id device,cl_context context,cl_command_queue queue,int)46 int test_images_read_2Darray( cl_device_id device, cl_context context,
47 cl_command_queue queue, int )
48 {
49 size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
50
51 GLenum targets[] = { GL_TEXTURE_2D_ARRAY };
52 size_t ntargets = sizeof(targets) / sizeof(targets[0]);
53
54 const size_t nsizes = 6;
55 sizevec_t sizes[nsizes];
56 calc_2D_array_size_descriptors(sizes, nsizes);
57
58 return test_images_read_common(device, context, queue, common_formats,
59 nformats, targets, ntargets, sizes, nsizes);
60 }
61
test_images_write_2Darray(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)62 int test_images_write_2Darray( cl_device_id device, cl_context context,
63 cl_command_queue queue, int numElements )
64 {
65 // FIXME: Query for 2D image array write support.
66
67 GLenum targets[] = { GL_TEXTURE_2D_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 = 6;
72 sizevec_t sizes[nsizes];
73 calc_2D_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_2Darray_getinfo(cl_device_id device,cl_context context,cl_command_queue queue,int)79 int test_images_2Darray_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_2D_ARRAY };
85 size_t ntargets = sizeof(targets) / sizeof(targets[0]);
86
87 const size_t nsizes = 6;
88 sizevec_t sizes[nsizes];
89 calc_2D_array_size_descriptors(sizes, nsizes);
90
91 return test_images_get_info_common(device, context, queue, common_formats,
92 nformats, targets, ntargets, sizes, nsizes);
93 }