xref: /aosp_15_r20/external/OpenCL-CTS/test_conformance/gles/test_renderbuffer_info.cpp (revision 6467f958c7de8070b317fc65bcb0f6472e388d82)
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_renderbuffer_object_info(cl_context context,cl_command_queue queue,GLsizei width,GLsizei height,GLenum attachment,GLenum rbFormat,GLenum rbType,GLenum texFormat,GLenum texType,ExplicitType type,MTdata d)19 static int test_renderbuffer_object_info( cl_context context, cl_command_queue queue,
20                                           GLsizei width, GLsizei height, GLenum attachment,
21                                               GLenum rbFormat, GLenum rbType,
22                                            GLenum texFormat, GLenum texType,
23                                           ExplicitType type, MTdata d )
24 {
25     int error;
26 
27     // Create the GL render buffer
28     glFramebufferWrapper glFramebuffer;
29     glRenderbufferWrapper glRenderbuffer;
30     void* tmp = CreateGLRenderbuffer( width, height, attachment, rbFormat, rbType, texFormat, texType,
31                                     type, &glFramebuffer, &glRenderbuffer, &error, d, true );
32     BufferOwningPtr<char> inputBuffer(tmp);
33     if( error != 0 )
34         return error;
35 
36     clMemWrapper image = (*clCreateFromGLRenderbuffer_ptr)(context, CL_MEM_READ_ONLY, glRenderbuffer, &error);
37     test_error(error, "clCreateFromGLRenderbuffer failed");
38 
39     log_info( "- Given a GL format of %s, input type was %s, size was %d x %d\n",
40               GetGLFormatName( rbFormat ),
41               get_explicit_type_name( type ), (int)width, (int)height );
42 
43     // Verify the expected information here.
44     return CheckGLObjectInfo(image, CL_GL_OBJECT_RENDERBUFFER, (GLuint)glRenderbuffer, rbFormat, 0);
45 }
46 
test_renderbuffer_getinfo(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)47 int test_renderbuffer_getinfo( cl_device_id device, cl_context context, cl_command_queue queue, int numElements )
48 {
49     GLenum attachments[] = { GL_COLOR_ATTACHMENT0_EXT };
50 
51     struct {
52         GLenum rbFormat;
53         GLenum rbType;
54         GLenum texFormat;
55         GLenum texType;
56         ExplicitType type;
57 
58     } formats[] = {
59         { GL_RGBA8_OES,    GL_UNSIGNED_BYTE,   GL_RGBA,    GL_UNSIGNED_BYTE,    kUChar },
60         { GL_RGBA32F,      GL_FLOAT,           GL_RGBA,    GL_FLOAT,            kFloat }
61     };
62 
63     size_t fmtIdx, tgtIdx;
64     int error = 0;
65     size_t iter = 6;
66     RandomSeed seed(gRandomSeed);
67 
68     // Check if images are supported
69   if (checkForImageSupport(device)) {
70     log_info("Device does not support images. Skipping test.\n");
71     return 0;
72   }
73 
74     // Loop through a set of GL formats, testing a set of sizes against each one
75     for( fmtIdx = 0; fmtIdx < sizeof( formats ) / sizeof( formats[ 0 ] ); fmtIdx++ )
76     {
77         for( tgtIdx = 0; tgtIdx < sizeof( attachments ) / sizeof( attachments[ 0 ] ); tgtIdx++ )
78         {
79             log_info( "Testing Renderbuffer object info for %s : %s : %s\n",
80                 GetGLFormatName( formats[ fmtIdx ].rbFormat ),
81                 GetGLBaseFormatName( formats[ fmtIdx ].rbFormat ),
82                 GetGLTypeName( formats[ fmtIdx ].type ) );
83 
84             size_t i;
85             for( i = 0; i < iter; i++ )
86             {
87                 GLsizei width = random_in_range( 16, 512, seed );
88                 GLsizei height = random_in_range( 16, 512, seed );
89 
90                 if( test_renderbuffer_object_info( context, queue, (int)width, (int)height,
91                                                    attachments[ tgtIdx ],
92                                                    formats[ fmtIdx ].rbFormat,
93                                                    formats[ fmtIdx ].rbType,
94                                                    formats[ fmtIdx ].texFormat,
95                                                    formats[ fmtIdx ].texType,
96                                                    formats[ fmtIdx ].type, seed ) )
97                 {
98                     log_error( "ERROR: Renderbuffer write test failed for GL format %s : %s\n\n",
99                         GetGLFormatName( formats[ fmtIdx ].rbFormat ),
100                         GetGLTypeName( formats[ fmtIdx ].rbType ) );
101 
102                     error++;
103                     break;    // Skip other sizes for this combination
104                 }
105             }
106             if( i == iter )
107             {
108                 log_info( "passed: Renderbuffer write test passed for GL format %s : %s\n\n",
109                     GetGLFormatName( formats[ fmtIdx ].rbFormat ),
110                     GetGLTypeName( formats[ fmtIdx ].rbType ) );
111 
112             }
113         }
114     }
115 
116     return error;
117 }
118