• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
calc_1D_array_size_descriptors(sizevec_t * sizes,size_t nsizes)28 void calc_1D_array_size_descriptors(sizevec_t* sizes, size_t nsizes)
29 {
30   // Need to limit array size according to GL device properties
31   GLint maxTextureLayers = 16, maxTextureSize = 4096;
32   glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &maxTextureLayers);
33   glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
34 
35   RandomSeed seed( gRandomSeed );
36 
37   // Generate some random sizes (within reasonable ranges)
38   for (size_t i = 0; i < nsizes; i++) {
39     sizes[i].width  = random_in_range( 2, min(maxTextureSize, 1<<(i+4)), seed );
40     sizes[i].height = random_in_range( 2, min(maxTextureLayers, 1<<(i+4)), seed );
41     sizes[i].depth  = 1;
42   }
43 }
44 
test_images_read_1Darray(cl_device_id device,cl_context context,cl_command_queue queue,int)45 int test_images_read_1Darray( cl_device_id device, cl_context context,
46   cl_command_queue queue, int )
47 {
48   size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
49 
50   GLenum targets[] = { GL_TEXTURE_1D_ARRAY };
51   size_t ntargets = sizeof(targets) / sizeof(targets[0]);
52 
53   const size_t nsizes = 8;
54   sizevec_t sizes[nsizes];
55   calc_1D_array_size_descriptors(sizes, nsizes);
56 
57   return test_images_read_common(device, context, queue, common_formats,
58       nformats, targets, ntargets, sizes, nsizes);
59 }
60 
test_images_write_1Darray(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)61 int test_images_write_1Darray( cl_device_id device, cl_context context,
62   cl_command_queue queue, int numElements )
63 {
64   GLenum targets[] = { GL_TEXTURE_1D_ARRAY };
65   size_t ntargets = sizeof(targets) / sizeof(targets[0]);
66   size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
67 
68   const size_t nsizes = 8;
69   sizevec_t sizes[nsizes];
70   calc_1D_array_size_descriptors(sizes, nsizes);
71 
72   return test_images_write_common( device, context, queue, common_formats,
73     nformats, targets, ntargets, sizes, nsizes );
74 }
75 
test_images_1Darray_getinfo(cl_device_id device,cl_context context,cl_command_queue queue,int)76 int test_images_1Darray_getinfo( cl_device_id device, cl_context context,
77   cl_command_queue queue, int )
78 {
79   size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
80 
81   GLenum targets[] = { GL_TEXTURE_1D_ARRAY };
82   size_t ntargets = sizeof(targets) / sizeof(targets[0]);
83 
84   const size_t nsizes = 8;
85   sizevec_t sizes[nsizes];
86   calc_1D_array_size_descriptors(sizes, nsizes);
87 
88   return test_images_get_info_common(device, context, queue, common_formats,
89       nformats, targets, ntargets, sizes, nsizes);
90 }