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
26 #include <algorithm>
27
28 using namespace std;
29
calc_2D_multisample_size_descriptors(sizevec_t * sizes,size_t nsizes)30 void calc_2D_multisample_size_descriptors(sizevec_t* sizes, size_t nsizes)
31 {
32 // Need to limit texture size according to GL device properties
33 GLint maxTextureSize = 4096;
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 = 1;
43 }
44 }
45
calc_2D_array_multisample_size_descriptors(sizevec_t * sizes,size_t nsizes)46 void calc_2D_array_multisample_size_descriptors(sizevec_t* sizes, size_t nsizes)
47 {
48 // Need to limit array size according to GL device properties
49 GLint maxTextureLayers = 16, maxTextureSize = 4096;
50 glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &maxTextureLayers);
51 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
52
53 RandomSeed seed( gRandomSeed );
54
55 // Generate some random sizes (within reasonable ranges)
56 for (size_t i = 0; i < nsizes; i++) {
57 sizes[i].width = random_in_range( 2, min(maxTextureSize, 1<<(i+4)), seed );
58 sizes[i].height = random_in_range( 2, min(maxTextureSize, 1<<(i+4)), seed );
59 sizes[i].depth = random_in_range( 2, min(maxTextureLayers, 1<<(i+4)), seed );
60 }
61 }
62
test_images_read_2D_multisample(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)63 int test_images_read_2D_multisample( cl_device_id device, cl_context context,
64 cl_command_queue queue, int numElements )
65 {
66 if (!is_extension_available(device, "cl_khr_gl_msaa_sharing")) {
67 log_info("Test not run because 'cl_khr_gl_msaa_sharing' extension is not supported by the tested device\n");
68 return 0;
69 }
70
71 glEnable(GL_MULTISAMPLE);
72
73 const size_t nsizes = 8;
74 sizevec_t sizes[nsizes];
75 calc_2D_multisample_size_descriptors(sizes, nsizes);
76
77 size_t nformats;
78
79 GLenum targets[] = { GL_TEXTURE_2D_MULTISAMPLE };
80 size_t ntargets = sizeof(targets) / sizeof(targets[0]);
81
82 nformats = sizeof(common_formats) / sizeof(common_formats[0]);
83 int ret_common = test_images_read_common(device, context, queue, common_formats, nformats, targets, ntargets, sizes, nsizes);
84
85 nformats = sizeof(depth_formats) / sizeof(depth_formats[0]);
86 int ret_depth = test_images_read_common(device, context, queue, depth_formats, nformats, targets, ntargets, sizes, nsizes);
87
88 return (ret_common) ? ret_common : ret_depth;
89 }
90
test_images_read_2Darray_multisample(cl_device_id device,cl_context context,cl_command_queue queue,int)91 int test_images_read_2Darray_multisample( cl_device_id device, cl_context context,
92 cl_command_queue queue, int )
93 {
94 if (!is_extension_available(device, "cl_khr_gl_msaa_sharing")) {
95 log_info("Test not run because 'cl_khr_gl_msaa_sharing' extension is not supported by the tested device\n");
96 return 0;
97 }
98
99 glEnable(GL_MULTISAMPLE);
100
101 const size_t nsizes = 4;
102 sizevec_t sizes[nsizes];
103 calc_2D_array_multisample_size_descriptors(sizes, nsizes);
104
105 size_t nformats;
106
107 GLenum targets[] = { GL_TEXTURE_2D_MULTISAMPLE_ARRAY };
108 size_t ntargets = sizeof(targets) / sizeof(targets[0]);
109
110 nformats = sizeof(common_formats) / sizeof(common_formats[0]);
111 int ret_common = test_images_read_common(device, context, queue, common_formats, nformats, targets, ntargets, sizes, nsizes);
112
113 nformats = sizeof(depth_formats) / sizeof(depth_formats[0]);
114 int ret_depth = test_images_read_common(device, context, queue, depth_formats, nformats, targets, ntargets, sizes, nsizes);
115
116 return (ret_common) ? ret_common : ret_depth;
117 }
118
119