• 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 
18 #include "gl_headers.h"
19 
test_image_read(cl_context context,cl_command_queue queue,GLenum glTarget,GLuint glTexture,size_t imageWidth,size_t imageHeight,cl_image_format * outFormat,ExplicitType * outType,void ** outResultBuffer)20 static int test_image_read( cl_context context, cl_command_queue queue, GLenum glTarget, GLuint glTexture,
21                             size_t imageWidth, size_t imageHeight, cl_image_format *outFormat,
22                             ExplicitType *outType, void **outResultBuffer )
23 {
24     // Create a CL image from the supplied GL texture
25     int error;
26     clMemWrapper image = (*clCreateFromGLTexture_ptr)( context, CL_MEM_READ_ONLY, glTarget, 0, glTexture, &error );
27     if( error != CL_SUCCESS )
28     {
29         print_error( error, "Unable to create CL image from GL texture" );
30 #ifndef GL_ES_VERSION_2_0
31         GLint fmt;
32         glGetTexLevelParameteriv( glTarget, 0, GL_TEXTURE_INTERNAL_FORMAT, &fmt );
33         log_error( "    Supplied GL texture was baseformat %s and internalformat %s\n", GetGLBaseFormatName( fmt ), GetGLFormatName( fmt ) );
34 #endif
35         return error;
36     }
37 
38     // Determine data type and format that CL came up with
39     error = clGetImageInfo( image, CL_IMAGE_FORMAT, sizeof( cl_image_format ), outFormat, NULL );
40     test_error( error, "Unable to get CL image format" );
41 
42     return CheckGLObjectInfo(image, CL_GL_OBJECT_TEXTURE2D, glTexture, glTarget, 0);
43 }
44 
test_image_object_info(cl_context context,cl_command_queue queue,size_t width,size_t height,GLenum target,GLenum format,GLenum internalFormat,GLenum glType,ExplicitType type,MTdata d)45 static int test_image_object_info( cl_context context, cl_command_queue queue,
46                                    size_t width, size_t height, GLenum target,
47                                    GLenum format, GLenum internalFormat,
48                                    GLenum glType, ExplicitType type, MTdata d )
49 {
50     int error;
51 
52     // Create the GL texture
53     glTextureWrapper glTexture;
54     void *tmp = CreateGLTexture2D( width, height, target, format, internalFormat, glType, type, &glTexture, &error, true, d );
55     BufferOwningPtr<char> inputBuffer(tmp);
56     if( error != 0 )
57     {
58         // GL_RGBA_INTEGER_EXT doesn't exist in GLES2. No need to check for it.
59         return error;
60     }
61 
62     /* skip formats not supported by OpenGL */
63     if(!tmp)
64     {
65         return 0;
66     }
67 
68     // Run and get the results
69     cl_image_format clFormat;
70     ExplicitType actualType;
71     char *outBuffer;
72     error = test_image_read( context, queue, target, glTexture, width, height, &clFormat, &actualType, (void **)&outBuffer );
73 
74     return error;
75 }
76 
test_images_2D_getinfo(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)77 int test_images_2D_getinfo( cl_device_id device, cl_context context, cl_command_queue queue, int numElements )
78 {
79     GLenum targets[] =
80 #ifdef GL_ES_VERSION_2_0
81         { GL_TEXTURE_2D };
82 #else // GL_ES_VERSION_2_0
83         { GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_EXT };
84 #endif // GL_ES_VERSION_2_0
85 
86     struct {
87         GLenum internal;
88         GLenum format;
89         GLenum datatype;
90         ExplicitType type;
91 
92     } formats[] = {
93         { GL_RGBA,         GL_RGBA,             GL_UNSIGNED_BYTE,            kUChar },
94         { GL_RGBA,         GL_RGBA,             GL_UNSIGNED_SHORT,           kUShort },
95         { GL_RGBA,         GL_RGBA,             GL_HALF_FLOAT_OES,           kHalf },
96         { GL_RGBA,         GL_RGBA,             GL_FLOAT,                    kFloat },
97     };
98 
99     size_t sizes[] = { 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 };
100 
101     size_t fmtIdx, tgtIdx;
102     int error = 0;
103     size_t iter = 6;
104     RandomSeed seed( gRandomSeed );
105 
106     // Check if images are supported
107   if (checkForImageSupport(device)) {
108     log_info("Device does not support images. Skipping test.\n");
109     return 0;
110   }
111 
112     // Loop through a set of GL formats, testing a set of sizes against each one
113     for( fmtIdx = 0; fmtIdx < sizeof( formats ) / sizeof( formats[ 0 ] ); fmtIdx++ )
114     {
115         for( tgtIdx = 0; tgtIdx < sizeof( targets ) / sizeof( targets[ 0 ] ); tgtIdx++ )
116         {
117             size_t i;
118             log_info( "Testing image texture object info test for %s : %s : %s : %s\n",
119                 GetGLTargetName( targets[ tgtIdx ] ),
120                 GetGLFormatName( formats[ fmtIdx ].internal ),
121                 GetGLBaseFormatName( formats[ fmtIdx ].format ),
122                 GetGLTypeName( formats[ fmtIdx ].datatype ) );
123 
124             for( i = 0; i < iter; i++ )
125             {
126                 if( test_image_object_info( context, queue, sizes[i], sizes[i],
127                                             targets[ tgtIdx ],
128                                             formats[ fmtIdx ].format,
129                                             formats[ fmtIdx ].internal,
130                                             formats[ fmtIdx ].datatype,
131                                             formats[ fmtIdx ].type, seed ) )
132                 {
133                     log_error( "ERROR: Image texture object info test failed for %s : %s : %s : %s\n\n",
134                         GetGLTargetName( targets[ tgtIdx ] ),
135                         GetGLFormatName( formats[ fmtIdx ].internal ),
136                         GetGLBaseFormatName( formats[ fmtIdx ].format ),
137                         GetGLTypeName( formats[ fmtIdx ].datatype ) );
138 
139 
140                     error++;
141                     break;    // Skip other sizes for this combination
142                 }
143             }
144             if( i == iter )
145             {
146                 log_info( "passed: Image texture object info test passed for %s : %s : %s : %s\n\n",
147                     GetGLTargetName( targets[ tgtIdx ] ),
148                     GetGLFormatName( formats[ fmtIdx ].internal ),
149                     GetGLBaseFormatName( formats[ fmtIdx ].format ),
150                     GetGLTypeName( formats[ fmtIdx ].datatype ) );
151             }
152             else
153                 break;    // Skip other cube map targets; they're unlikely to pass either
154         }
155     }
156 
157     return error;
158 }
test_images_cube_getinfo(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)159 int test_images_cube_getinfo( cl_device_id device, cl_context context, cl_command_queue queue, int numElements )
160 {
161     GLenum targets[] = {
162         GL_TEXTURE_CUBE_MAP_POSITIVE_X,
163         GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
164         GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
165         GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
166         GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
167         GL_TEXTURE_CUBE_MAP_NEGATIVE_Z };
168 
169     struct {
170         GLenum internal;
171         GLenum format;
172         GLenum datatype;
173         ExplicitType type;
174 
175     } formats[] = {
176 #ifdef GL_ES_VERSION_2_0
177         { GL_RGBA,         GL_RGBA,             GL_UNSIGNED_BYTE,            kUChar },
178         { GL_RGBA,         GL_RGBA,             GL_UNSIGNED_SHORT,           kUShort },
179         // XXX add others
180 #else // GL_ES_VERSION_2_0
181         { GL_RGBA,         GL_BGRA,             GL_UNSIGNED_INT_8_8_8_8_REV, kUChar },
182         { GL_RGBA,         GL_RGBA,             GL_UNSIGNED_INT_8_8_8_8_REV, kUChar },
183         { GL_RGBA8,        GL_RGBA,             GL_UNSIGNED_BYTE,            kUChar },
184         { GL_RGBA16,       GL_RGBA,             GL_UNSIGNED_SHORT,           kUShort },
185         { GL_RGBA8I_EXT,   GL_RGBA_INTEGER_EXT, GL_BYTE,                     kChar },
186         { GL_RGBA16I_EXT,  GL_RGBA_INTEGER_EXT, GL_SHORT,                    kShort },
187         { GL_RGBA32I_EXT,  GL_RGBA_INTEGER_EXT, GL_INT,                      kInt },
188         { GL_RGBA8UI_EXT,  GL_RGBA_INTEGER_EXT, GL_UNSIGNED_BYTE,            kUChar },
189         { GL_RGBA16UI_EXT, GL_RGBA_INTEGER_EXT, GL_UNSIGNED_SHORT,           kUShort },
190         { GL_RGBA32UI_EXT, GL_RGBA_INTEGER_EXT, GL_UNSIGNED_INT,             kUInt },
191         { GL_RGBA32F_ARB,  GL_RGBA,             GL_FLOAT,                    kFloat }
192 #endif
193     };
194 
195     size_t sizes[] = { 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 };
196 
197     size_t fmtIdx, tgtIdx;
198     int error = 0;
199     size_t iter = 6;
200     RandomSeed seed( gRandomSeed );
201 
202     // Check if images are supported
203   if (checkForImageSupport(device)) {
204     log_info("Device does not support images. Skipping test.\n");
205     return 0;
206   }
207 
208     // Loop through a set of GL formats, testing a set of sizes against each one
209     for( fmtIdx = 0; fmtIdx < sizeof( formats ) / sizeof( formats[ 0 ] ); fmtIdx++ )
210     {
211         for( tgtIdx = 0; tgtIdx < sizeof( targets ) / sizeof( targets[ 0 ] ); tgtIdx++ )
212         {
213             size_t i;
214             log_info( "Testing cube map object info test for %s : %s : %s : %s\n",
215                 GetGLTargetName( targets[ tgtIdx ] ),
216                 GetGLFormatName( formats[ fmtIdx ].internal ),
217                 GetGLBaseFormatName( formats[ fmtIdx ].format ),
218                 GetGLTypeName( formats[ fmtIdx ].datatype ) );
219 
220             for( i = 0; i < iter; i++ )
221             {
222                 if( test_image_object_info( context, queue, sizes[i], sizes[i],
223                                             targets[ tgtIdx ],
224                                             formats[ fmtIdx ].format,
225                                             formats[ fmtIdx ].internal,
226                                             formats[ fmtIdx ].datatype,
227                                             formats[ fmtIdx ].type, seed ) )
228                 {
229                     log_error( "ERROR: Cube map object info test failed for %s : %s : %s : %s\n\n",
230                         GetGLTargetName( targets[ tgtIdx ] ),
231                         GetGLFormatName( formats[ fmtIdx ].internal ),
232                         GetGLBaseFormatName( formats[ fmtIdx ].format ),
233                         GetGLTypeName( formats[ fmtIdx ].datatype ) );
234 
235 
236                     error++;
237                     break;    // Skip other sizes for this combination
238                 }
239             }
240             if( i == iter )
241             {
242                 log_info( "passed: Cube map object info test passed for %s : %s : %s : %s\n\n",
243                     GetGLTargetName( targets[ tgtIdx ] ),
244                     GetGLFormatName( formats[ fmtIdx ].internal ),
245                     GetGLBaseFormatName( formats[ fmtIdx ].format ),
246                     GetGLTypeName( formats[ fmtIdx ].datatype ) );
247             }
248             else
249                 break;    // Skip other cube map targets; they're unlikely to pass either
250         }
251     }
252 
253     return error;
254 }
255