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 #if defined( __APPLE__ )
18 #include <OpenGL/glu.h>
19 #else
20 #include <GL/glu.h>
21 #include <CL/cl_gl.h>
22 #endif
23
test_renderbuffer_object_info(cl_context context,cl_command_queue queue,GLsizei width,GLsizei height,GLenum attachment,GLenum format,GLenum internalFormat,GLenum glType,ExplicitType type,MTdata d)24 static int test_renderbuffer_object_info( cl_context context, cl_command_queue queue,
25 GLsizei width, GLsizei height, GLenum attachment,
26 GLenum format, GLenum internalFormat,
27 GLenum glType, ExplicitType type, MTdata d )
28 {
29 int error;
30
31 if( type == kHalf )
32 if( DetectFloatToHalfRoundingMode(queue) )
33 return 1;
34
35 // Create the GL render buffer
36 glFramebufferWrapper glFramebuffer;
37 glRenderbufferWrapper glRenderbuffer;
38 BufferOwningPtr<char> inputBuffer(CreateGLRenderbuffer( width, height, attachment, format, internalFormat, glType, type, &glFramebuffer, &glRenderbuffer, &error, d, true ));
39 if( error != 0 )
40 return error;
41
42 clMemWrapper image = (*clCreateFromGLRenderbuffer_ptr)(context, CL_MEM_READ_ONLY, glRenderbuffer, &error);
43 test_error(error, "clCreateFromGLRenderbuffer failed");
44
45 log_info( "- Given a GL format of %s, input type was %s, size was %d x %d\n",
46 GetGLFormatName( internalFormat ),
47 get_explicit_type_name( type ), (int)width, (int)height );
48
49 // Verify the expected information here.
50 return CheckGLObjectInfo(image, CL_GL_OBJECT_RENDERBUFFER, (GLuint)glRenderbuffer, internalFormat, 0);
51 }
52
test_renderbuffer_getinfo(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)53 int test_renderbuffer_getinfo( cl_device_id device, cl_context context, cl_command_queue queue, int numElements )
54 {
55 GLenum attachments[] = { GL_COLOR_ATTACHMENT0_EXT };
56
57 struct {
58 GLenum internal;
59 GLenum format;
60 GLenum datatype;
61 ExplicitType type;
62
63 } formats[] = {
64 { GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, kUChar },
65 { GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, kUChar },
66 { GL_RGBA16, GL_RGBA, GL_UNSIGNED_SHORT, kUShort },
67 { GL_RGBA32F_ARB, GL_RGBA, GL_FLOAT, kFloat },
68 { GL_RGBA16F_ARB, GL_RGBA, GL_HALF_FLOAT, kHalf }
69 };
70
71 size_t fmtIdx, tgtIdx;
72 int error = 0;
73 size_t iter = 6;
74 RandomSeed seed(gRandomSeed);
75
76 // Check if images are supported
77 if (checkForImageSupport(device)) {
78 log_info("Device does not support images. Skipping test.\n");
79 return 0;
80 }
81
82 if( !gluCheckExtension( (const GLubyte *)"GL_EXT_framebuffer_object", glGetString( GL_EXTENSIONS ) ) )
83 {
84 log_info( "Renderbuffers are not supported by this OpenGL implementation; skipping test\n" );
85 return 0;
86 }
87
88 // Loop through a set of GL formats, testing a set of sizes against each one
89 for( fmtIdx = 0; fmtIdx < sizeof( formats ) / sizeof( formats[ 0 ] ); fmtIdx++ )
90 {
91 for( tgtIdx = 0; tgtIdx < sizeof( attachments ) / sizeof( attachments[ 0 ] ); tgtIdx++ )
92 {
93 log_info( "Testing Renderbuffer object info for %s : %s : %s\n",
94 GetGLFormatName( formats[ fmtIdx ].internal ),
95 GetGLBaseFormatName( formats[ fmtIdx ].format ),
96 GetGLTypeName( formats[ fmtIdx ].datatype ) );
97
98 size_t i;
99 for( i = 0; i < iter; i++ )
100 {
101 GLsizei width = random_in_range( 16, 512, seed );
102 GLsizei height = random_in_range( 16, 512, seed );
103
104 if( test_renderbuffer_object_info( context, queue, (int)width, (int)height,
105 attachments[ tgtIdx ],
106 formats[ fmtIdx ].format,
107 formats[ fmtIdx ].internal,
108 formats[ fmtIdx ].datatype,
109 formats[ fmtIdx ].type, seed ) )
110 {
111 log_error( "ERROR: Renderbuffer write test failed for GL format %s : %s\n\n",
112 GetGLFormatName( formats[ fmtIdx ].internal ),
113 GetGLTypeName( formats[ fmtIdx ].datatype ) );
114
115 error++;
116 break; // Skip other sizes for this combination
117 }
118 }
119 if( i == iter )
120 {
121 log_info( "passed: Renderbuffer write test passed for GL format %s : %s\n\n",
122 GetGLFormatName( formats[ fmtIdx ].internal ),
123 GetGLTypeName( formats[ fmtIdx ].datatype ) );
124
125 }
126 }
127 }
128
129 return error;
130 }
131
132