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