• 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 "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 #include <algorithm>
26 
27 using namespace std;
28 
29 #pragma mark -
30 #pragma mark _3D read test
31 
calc_3D_size_descriptors(sizevec_t * sizes,size_t nsizes)32 void calc_3D_size_descriptors(sizevec_t* sizes, size_t nsizes)
33 {
34   // Need to limit array size according to GL device properties
35   GLint maxTextureSize = 2048;
36   glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &maxTextureSize);
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(maxTextureSize, 1<<(i+4)), seed );
43     sizes[i].height = random_in_range( 2, min(maxTextureSize, 1<<(i+4)), seed );
44     sizes[i].depth  = random_in_range( 2, min(maxTextureSize, 1<<(i+4)), seed );
45   }
46 }
47 
test_images_read_3D(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)48 int test_images_read_3D( cl_device_id device, cl_context context, cl_command_queue queue, int numElements )
49 {
50     GLenum targets[] = { GL_TEXTURE_3D };
51   size_t ntargets = 1;
52 
53   size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
54 
55   const size_t nsizes = 6;
56   sizevec_t sizes[nsizes];
57   calc_3D_size_descriptors(sizes, nsizes);
58 
59   return test_images_read_common(device, context, queue, common_formats,
60     nformats, targets, ntargets, sizes, nsizes);
61 }
62 
63 #pragma mark -
64 #pragma marm _3D write test
65 
test_images_write_3D(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)66 int test_images_write_3D( cl_device_id device, cl_context context,
67   cl_command_queue queue, int numElements )
68 {
69   // TODO: Perhaps the expected behavior is to FAIL if 3D images are
70   //       unsupported?
71 
72   if (!is_extension_available(device, "cl_khr_3d_image_writes")) {
73     log_info("This device does not support 3D image writes.  Skipping test.\n");
74     return 0;
75   }
76 
77   GLenum targets[] = { GL_TEXTURE_3D };
78   size_t ntargets = sizeof(targets) / sizeof(targets[0]);
79   size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
80 
81 
82   const size_t nsizes = 6;
83   sizevec_t sizes[nsizes];
84   calc_3D_size_descriptors(sizes, nsizes);
85 
86   return test_images_write_common( device, context, queue, common_formats,
87     nformats, targets, ntargets, sizes, nsizes );
88 }
89 
90 #pragma mark -
91 #pragma mark _3D get info test
92 
test_images_3D_getinfo(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)93 int test_images_3D_getinfo( cl_device_id device, cl_context context,
94   cl_command_queue queue, int numElements )
95 {
96   GLenum targets[] = { GL_TEXTURE_3D };
97   size_t ntargets = 1;
98 
99   size_t nformats = sizeof(common_formats) / sizeof(common_formats[0]);
100 
101   const size_t nsizes = 6;
102   sizevec_t sizes[nsizes];
103   calc_3D_size_descriptors(sizes, nsizes);
104 
105     return test_images_get_info_common(device, context, queue, common_formats,
106       nformats, targets, ntargets, sizes, nsizes);
107 }
108