• 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;
28 
calc_test_size_descriptors(sizevec_t * sizes,size_t nsizes)29 void calc_test_size_descriptors(sizevec_t* sizes, size_t nsizes)
30 {
31   // Need to limit array size according to GL device properties
32   GLint maxTextureSize = 4096, maxTextureBufferSize = 4096, size;
33   glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
34   glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &maxTextureBufferSize);
35 
36   size = min(maxTextureSize, maxTextureBufferSize);
37 
38   RandomSeed seed( gRandomSeed );
39 
40   // Generate some random sizes (within reasonable ranges)
41   for (size_t i = 0; i < nsizes; i++) {
42     sizes[i].width  = random_in_range( 2, min(size, 1<<(i+4)), seed );
43     sizes[i].height = 1;
44     sizes[i].depth  = 1;
45   }
46 }
47 
test_images_read_1D(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)48 int test_images_read_1D( cl_device_id device, cl_context context,
49   cl_command_queue queue, int numElements )
50 {
51   size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
52 
53   GLenum targets[] = { GL_TEXTURE_1D };
54   size_t ntargets = sizeof(targets) / sizeof(targets[0]);
55 
56   const size_t nsizes = 8;
57   sizevec_t sizes[nsizes];
58   calc_test_size_descriptors(sizes, nsizes);
59 
60   return test_images_read_common(device, context, queue, common_formats,
61       nformats, targets, ntargets, sizes, nsizes);
62 }
63 
test_images_write_1D(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)64 int test_images_write_1D( cl_device_id device, cl_context context,
65   cl_command_queue queue, int numElements )
66 {
67   GLenum targets[] = { GL_TEXTURE_1D };
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 = 8;
72   sizevec_t sizes[nsizes];
73   calc_test_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_1D_getinfo(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)79 int test_images_1D_getinfo( cl_device_id device, cl_context context,
80     cl_command_queue queue, int numElements )
81 {
82   size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
83 
84   GLenum targets[] = { GL_TEXTURE_1D };
85   size_t ntargets = sizeof(targets) / sizeof(targets[0]);
86 
87   const size_t nsizes = 8;
88   sizevec_t sizes[nsizes];
89   calc_test_size_descriptors(sizes, nsizes);
90 
91   return test_images_get_info_common( device, context, queue, common_formats,
92     nformats, targets, ntargets, sizes, nsizes);
93 }
94 
test_images_read_texturebuffer(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)95 int test_images_read_texturebuffer( cl_device_id device, cl_context context,
96                         cl_command_queue queue, int numElements )
97 {
98   size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
99 
100   GLenum targets[] = { GL_TEXTURE_BUFFER };
101   size_t ntargets = sizeof(targets) / sizeof(targets[0]);
102 
103   const size_t nsizes = 8;
104   sizevec_t sizes[nsizes];
105   calc_test_size_descriptors(sizes, nsizes);
106 
107   return test_images_read_common(device, context, queue, common_formats,
108                                  nformats, targets, ntargets, sizes, nsizes);
109 }
110 
test_images_write_texturebuffer(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)111 int test_images_write_texturebuffer( cl_device_id device, cl_context context,
112                          cl_command_queue queue, int numElements )
113 {
114   GLenum targets[] = { GL_TEXTURE_BUFFER };
115   size_t ntargets = sizeof(targets) / sizeof(targets[0]);
116   size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
117 
118   const size_t nsizes = 8;
119   sizevec_t sizes[nsizes];
120   calc_test_size_descriptors(sizes, nsizes);
121 
122   return test_images_write_common( device, context, queue, common_formats,
123                                   nformats, targets, ntargets, sizes, nsizes );
124 }
125 
test_images_texturebuffer_getinfo(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)126 int test_images_texturebuffer_getinfo( cl_device_id device, cl_context context,
127                            cl_command_queue queue, int numElements )
128 {
129   size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
130 
131   GLenum targets[] = { GL_TEXTURE_BUFFER };
132   size_t ntargets = sizeof(targets) / sizeof(targets[0]);
133 
134   const size_t nsizes = 8;
135   sizevec_t sizes[nsizes];
136   calc_test_size_descriptors(sizes, nsizes);
137 
138   return test_images_get_info_common( device, context, queue, common_formats,
139                                      nformats, targets, ntargets, sizes, nsizes);
140 }
141 
142