• 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 "gl_headers.h"
17 #include "testBase.h"
18 
test_image_read(cl_context context,cl_command_queue queue,GLenum glTarget,GLuint glTexture,size_t imageWidth,size_t imageHeight,size_t imageDepth,cl_image_format * outFormat,ExplicitType * outType,void ** outResultBuffer)19 static int test_image_read( cl_context context, cl_command_queue queue, GLenum glTarget, GLuint glTexture,
20                     size_t imageWidth, size_t imageHeight, size_t imageDepth, cl_image_format *outFormat, ExplicitType *outType, void **outResultBuffer )
21 {
22   clMemWrapper streams[ 2 ];
23 
24   int error;
25 
26     // Create a CL image from the supplied GL texture
27     streams[ 0 ] = (*clCreateFromGLTexture_ptr)( context, CL_MEM_READ_ONLY, glTarget, 0, glTexture, &error );
28     if( error != CL_SUCCESS )
29     {
30         print_error( error, "Unable to create CL image from GL texture" );
31 #ifndef GL_ES_VERSION_2_0
32         GLint fmt;
33         glGetTexLevelParameteriv( glTarget, 0, GL_TEXTURE_INTERNAL_FORMAT, &fmt );
34         log_error( "    Supplied GL texture was format %s\n", GetGLFormatName( fmt ) );
35 #endif
36         return error;
37     }
38 
39     // Determine data type and format that CL came up with
40     error = clGetImageInfo( streams[ 0 ], CL_IMAGE_FORMAT, sizeof( cl_image_format ), outFormat, NULL );
41     test_error( error, "Unable to get CL image format" );
42 
43   return CheckGLObjectInfo(streams[0], CL_GL_OBJECT_TEXTURE3D, glTexture, glTarget, 0);
44 }
45 
test_image_format_read(cl_context context,cl_command_queue queue,size_t width,size_t height,size_t depth,GLenum target,GLenum format,GLenum internalFormat,GLenum glType,ExplicitType type,MTdata d)46 static int test_image_format_read( cl_context context, cl_command_queue queue,
47                            size_t width, size_t height, size_t depth,
48                            GLenum target, GLenum format, GLenum internalFormat,
49                            GLenum glType, ExplicitType type, MTdata d )
50 {
51     int error;
52 
53 
54     // Create the GL texture
55     glTextureWrapper glTexture;
56     void* tmp = CreateGLTexture3D( width, height, depth, target, format, internalFormat, glType, type, &glTexture, &error, d, true );
57     BufferOwningPtr<char> inputBuffer(tmp);
58     if( error != 0 )
59     {
60         return error;
61     }
62 
63     /* skip formats not supported by OpenGL */
64     if(!tmp)
65     {
66         return 0;
67     }
68 
69     // Run and get the results
70     cl_image_format clFormat;
71     ExplicitType actualType;
72     char *outBuffer;
73     return test_image_read( context, queue, target, glTexture, width, height, depth, &clFormat, &actualType, (void **)&outBuffer );
74 }
75 
76 
test_images_3D_getinfo(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)77 int test_images_3D_getinfo( cl_device_id device, cl_context context, cl_command_queue queue, int numElements )
78 {
79     GLenum targets[] = { GL_TEXTURE_3D };
80 
81     struct {
82         GLenum internal;
83         GLenum format;
84         GLenum datatype;
85         ExplicitType type;
86 
87     } formats[] = {
88 #ifdef GL_ES_VERSION_2_0
89         { GL_RGBA,         GL_RGBA,             GL_UNSIGNED_BYTE,            kUChar },
90         { GL_RGBA,         GL_RGBA,             GL_UNSIGNED_SHORT,           kUShort },
91 //        { GL_RGBA8I_EXT,   GL_RGBA_INTEGER_EXT, GL_BYTE,                     kChar },
92 //        { GL_RGBA16I_EXT,  GL_RGBA_INTEGER_EXT, GL_SHORT,                    kShort },
93 //        { GL_RGBA32I_EXT,  GL_RGBA_INTEGER_EXT, GL_INT,                      kInt },
94 //        { GL_RGBA8UI_EXT,  GL_RGBA_INTEGER_EXT, GL_UNSIGNED_BYTE,            kUChar },
95 //        { GL_RGBA16UI_EXT, GL_RGBA_INTEGER_EXT, GL_UNSIGNED_SHORT,           kUShort },
96 //        { GL_RGBA32UI_EXT, GL_RGBA_INTEGER_EXT, GL_UNSIGNED_INT,             kUInt },
97 //        { GL_RGBA32F_ARB,  GL_RGBA,             GL_FLOAT,                    kFloat }
98 #else // GL_ES_VERSION_2_0
99         { GL_RGBA,         GL_BGRA,             GL_UNSIGNED_INT_8_8_8_8_REV, kUChar },
100         { GL_RGBA,         GL_RGBA,             GL_UNSIGNED_INT_8_8_8_8_REV, kUChar },
101         { GL_RGBA8,        GL_RGBA,             GL_UNSIGNED_BYTE,            kUChar },
102         { GL_RGBA16,       GL_RGBA,             GL_UNSIGNED_SHORT,           kUShort },
103         { GL_RGBA8I_EXT,   GL_RGBA_INTEGER_EXT, GL_BYTE,                     kChar },
104         { GL_RGBA16I_EXT,  GL_RGBA_INTEGER_EXT, GL_SHORT,                    kShort },
105         { GL_RGBA32I_EXT,  GL_RGBA_INTEGER_EXT, GL_INT,                      kInt },
106         { GL_RGBA8UI_EXT,  GL_RGBA_INTEGER_EXT, GL_UNSIGNED_BYTE,            kUChar },
107         { GL_RGBA16UI_EXT, GL_RGBA_INTEGER_EXT, GL_UNSIGNED_SHORT,           kUShort },
108         { GL_RGBA32UI_EXT, GL_RGBA_INTEGER_EXT, GL_UNSIGNED_INT,             kUInt },
109         { GL_RGBA32F_ARB,  GL_RGBA,             GL_FLOAT,                    kFloat }
110 #endif
111     };
112 
113     size_t sizes[] = { 2, 4, 8, 16, 32, 64, 128 };
114 
115     size_t fmtIdx, tgtIdx;
116     int error = 0;
117     RandomSeed seed(gRandomSeed);
118 
119     size_t iter = sizeof(sizes)/sizeof(sizes[0]);
120 
121     // Check if images are supported
122   if (checkForImageSupport(device)) {
123     log_info("Device does not support images. Skipping test.\n");
124     return 0;
125   }
126 
127     // Loop through a set of GL formats, testing a set of sizes against each one
128     for( fmtIdx = 0; fmtIdx < sizeof( formats ) / sizeof( formats[ 0 ] ); fmtIdx++ )
129     {
130         for( tgtIdx = 0; tgtIdx < sizeof( targets ) / sizeof( targets[ 0 ] ); tgtIdx++ )
131         {
132             size_t i;
133 
134             log_info( "Testing image info for GL format %s : %s : %s : %s\n",
135                    GetGLTargetName( targets[ tgtIdx ] ),
136                    GetGLFormatName( formats[ fmtIdx ].internal ),
137                    GetGLBaseFormatName( formats[ fmtIdx ].format ),
138                    GetGLTypeName( formats[ fmtIdx ].datatype ) );
139 
140             for( i = 0; i < iter; i++ )
141             {
142                 if( test_image_format_read( context, queue, sizes[i], sizes[i], sizes[i],
143                                    targets[ tgtIdx ],
144                                    formats[ fmtIdx ].format,
145                                    formats[ fmtIdx ].internal,
146                                    formats[ fmtIdx ].datatype,
147                                    formats[ fmtIdx ].type, seed ) )
148                 {
149                     log_error( "ERROR: Image info test failed for %s : %s : %s : %s\n\n",
150                     GetGLTargetName( targets[ tgtIdx ] ),
151                     GetGLFormatName( formats[ fmtIdx ].internal ),
152                     GetGLBaseFormatName( formats[ fmtIdx ].format ),
153                     GetGLTypeName( formats[ fmtIdx ].datatype ) );
154 
155                     error++;
156                     break;    // Skip other sizes for this combination
157                 }
158             }
159         }
160     }
161 
162     return error;
163 }
164 
165