am 114eb0ab: (-s ours) am 61cf23d7: Remove a few tests from M mustpass am: 3c4fdbd832
[platform/upstream/VK-GL-CTS.git] / scripts / opengl / gen_call_log_wrapper.py
1 # -*- coding: utf-8 -*-
2
3 #-------------------------------------------------------------------------
4 # drawElements Quality Program utilities
5 # --------------------------------------
6 #
7 # Copyright 2015 The Android Open Source Project
8 #
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
12 #
13 #      http://www.apache.org/licenses/LICENSE-2.0
14 #
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 #
21 #-------------------------------------------------------------------------
22
23 from src_util import *
24 import re
25
26 class LogSpec:
27         def __init__ (self, argInPrints, argOutPrints = {}, returnPrint = None):
28                 self.argInPrints        = argInPrints
29                 self.argOutPrints       = argOutPrints
30                 self.returnPrint        = returnPrint
31
32 def enum (group):
33         return lambda name: "get%sStr(%s)" % (group, name)
34
35 def pointer (size):
36         return lambda name: "getPointerStr(%s, %s)" % (name, size)
37
38 def enumPointer (group, size):
39         return lambda name: "getEnumPointerStr(%(name)s, %(size)s, %(nameFunc)s)" % {"name": name, "size": size, "nameFunc": ("get%sName" % group)}
40
41 def booleanPointer (size):
42         return lambda name: "getBooleanPointerStr(%s, %s)" % (name, size)
43
44 def textureUnit (name):
45         return "getTextureUnitStr(%s)" % name
46
47 def voidPointer (name):
48         return "toHex(reinterpret_cast<deUintptr>(static_cast<const void*>(%s)))" % name
49
50 def fnPointer (name):
51         return "toHex(reinterpret_cast<deUintptr>(%s))" % name
52
53 stringVal = lambda name: "getStringStr(%s)" % name
54
55 # Special rules for printing call arguments
56 CALL_LOG_SPECS = {
57         "glActiveTexture":                                              LogSpec({0: textureUnit}),
58         "glBeginQuery":                                                 LogSpec({0: enum("QueryTarget")}),
59         "glBeginTransformFeedback":                             LogSpec({0: enum("PrimitiveType")}),
60         "glBindBuffer":                                                 LogSpec({0: enum("BufferTarget")}),
61         "glBindBufferBase":                                             LogSpec({0: enum("BufferTarget")}),
62         "glBindBufferRange":                                    LogSpec({0: enum("BufferTarget")}),
63         "glBindFramebuffer":                                    LogSpec({0: enum("FramebufferTarget")}),
64         "glBindRenderbuffer":                                   LogSpec({0: enum("FramebufferTarget")}),
65         "glBindTexture":                                                LogSpec({0: enum("TextureTarget")}),
66         "glBindTransformFeedback":                              LogSpec({0: enum("TransformFeedbackTarget")}),
67         "glBlendEquation":                                              LogSpec({0: enum("BlendEquation")}),
68         "glBlendEquationSeparate":                              LogSpec({0: enum("BlendEquation"), 1: enum("BlendEquation")}),
69         "glBlendEquationi":                                             LogSpec({1: enum("BlendEquation")}),
70         "glBlendEquationSeparatei":                             LogSpec({1: enum("BlendEquation"), 2: enum("BlendEquation")}),
71         "glBlendFunc":                                                  LogSpec({0: enum("BlendFactor"), 1: enum("BlendFactor")}),
72         "glBlendFuncSeparate":                                  LogSpec({0: enum("BlendFactor"), 1: enum("BlendFactor"), 2: enum("BlendFactor"), 3: enum("BlendFactor")}),
73         "glBlitFramebuffer":                                    LogSpec({8: enum("BufferMask"), 9: enum("TextureFilter")}),
74         "glBufferData":                                                 LogSpec({0: enum("BufferTarget"), 3: enum("Usage")}),
75         "glBufferSubData":                                              LogSpec({0: enum("BufferTarget")}),
76         "glCheckFramebufferStatus":                             LogSpec({0: enum("FramebufferTarget")}, returnPrint = enum("FramebufferStatus")),
77         "glClear":                                                              LogSpec({0: enum("BufferMask")}),
78         "glClearBufferfv":                                              LogSpec({0: enum("Buffer")}),
79         "glClearBufferfi":                                              LogSpec({0: enum("Buffer")}),
80         "glClearBufferiv":                                              LogSpec({0: enum("Buffer")}),
81         "glClearBufferuiv":                                             LogSpec({0: enum("Buffer")}),
82         "glCompressedTexImage2D":                               LogSpec({0: enum("TextureTarget"), 2: enum("CompressedTextureFormat")}),
83         "glCompressedTexSubImage2D":                    LogSpec({0: enum("TextureTarget"), 6: enum("CompressedTextureFormat")}),
84         "glCompressedTexImage3D":                               LogSpec({0: enum("TextureTarget"), 2: enum("CompressedTextureFormat")}),
85         "glCompressedTexSubImage3D":                    LogSpec({0: enum("TextureTarget"), 8: enum("CompressedTextureFormat")}),
86         "glCopyTexImage1D":                                             LogSpec({0: enum("TextureTarget"), 2: enum("UncompressedTextureFormat")}),
87         "glCopyTexImage2D":                                             LogSpec({0: enum("TextureTarget"), 2: enum("UncompressedTextureFormat")}),
88         "glCreateShader":                                               LogSpec({0: enum("ShaderType")}),
89         "glCullFace":                                                   LogSpec({0: enum("Face")}),
90         "glDeleteBuffers":                                              LogSpec({1: pointer(size = "n")}),
91         "glDeleteFramebuffers":                                 LogSpec({1: pointer(size = "n")}),
92         "glDeleteQueries":                                              LogSpec({1: pointer(size = "n")}),
93         "glDeleteRenderbuffers":                                LogSpec({1: pointer(size = "n")}),
94         "glDeleteBuffers":                                              LogSpec({1: pointer(size = "n")}),
95         "glDeleteTextures":                                             LogSpec({1: pointer(size = "n")}),
96         "glDeleteVertexArrays":                                 LogSpec({1: pointer(size = "n")}),
97         "glDeleteProgramPipelines":                             LogSpec({1: pointer(size = "n")}),
98         "glDepthFunc":                                                  LogSpec({0: enum("CompareFunc")}),
99         "glDisable":                                                    LogSpec({0: enum("EnableCap")}),
100         "glDisablei":                                                   LogSpec({0: enum("IndexedEnableCap")}),
101         "glDrawArrays":                                                 LogSpec({0: enum("PrimitiveType")}),
102         "glDrawArraysInstanced":                                LogSpec({0: enum("PrimitiveType")}),
103         "glDrawBuffers":                                                LogSpec({1: enumPointer("DrawReadBuffer", size = "n")}),
104         "glDrawElements":                                               LogSpec({0: enum("PrimitiveType"), 2: enum("Type")}),
105         "glDrawElementsInstanced":                              LogSpec({0: enum("PrimitiveType"), 2: enum("Type")}),
106         "glDrawRangeElements":                                  LogSpec({0: enum("PrimitiveType"), 4: enum("Type")}),
107         "glDrawArraysIndirect":                                 LogSpec({0: enum("PrimitiveType")}),
108         "glDrawElementsIndirect":                               LogSpec({0: enum("PrimitiveType"), 1: enum("Type")}),
109         "glDrawElementsBaseVertex":                             LogSpec({0: enum("PrimitiveType"), 2: enum("Type")}),
110         "glDrawElementsInstancedBaseVertex":    LogSpec({0: enum("PrimitiveType"), 2: enum("Type")}),
111         "glDrawRangeElementsBaseVertex":                LogSpec({0: enum("PrimitiveType"), 4: enum("Type")}),
112         "glMultiDrawArrays":                                    LogSpec({0: enum("PrimitiveType")}),
113         "glMultiDrawElements":                                  LogSpec({0: enum("PrimitiveType"), 2: enum("Type")}),
114         "glMultiDrawElementsBaseVertex":                LogSpec({0: enum("PrimitiveType"), 2: enum("Type")}),
115         "glEnable":                                                             LogSpec({0: enum("EnableCap")}),
116         "glEnablei":                                                    LogSpec({0: enum("IndexedEnableCap")}),
117         "glEndQuery":                                                   LogSpec({0: enum("QueryTarget")}),
118         "glFramebufferRenderbuffer":                    LogSpec({0: enum("FramebufferTarget"), 1: enum("FramebufferAttachment"), 2: enum("FramebufferTarget")}),
119         "glFramebufferTexture2D":                               LogSpec({0: enum("FramebufferTarget"), 1: enum("FramebufferAttachment"), 2: enum("TextureTarget")}),
120         "glFramebufferTextureLayer":                    LogSpec({0: enum("FramebufferTarget"), 1: enum("FramebufferAttachment")}),
121         "glFramebufferTexture":                                 LogSpec({0: enum("FramebufferTarget"), 1: enum("FramebufferAttachment")}),
122         "glFramebufferParameteri":                              LogSpec({0: enum("FramebufferTarget"), 1: enum("FramebufferParameter")}),
123         "glFrontFace":                                                  LogSpec({0: enum("Winding")}),
124         "glGenBuffers":                                                 LogSpec({}, argOutPrints = {1: pointer(size = "n")}),
125         "glGenerateMipmap":                                             LogSpec({0: enum("TextureTarget")}),
126         "glGenFramebuffers":                                    LogSpec({}, argOutPrints = {1: pointer(size = "n")}),
127         "glGenQueries":                                                 LogSpec({}, argOutPrints = {1: pointer(size = "n")}),
128         "glGenRenderbuffers":                                   LogSpec({}, argOutPrints = {1: pointer(size = "n")}),
129         "glGenTextures":                                                LogSpec({}, argOutPrints = {1: pointer(size = "n")}),
130         "glGenTransformFeedbacks":                              LogSpec({}, argOutPrints = {1: pointer(size = "n")}),
131         "glGenVertexArrays":                                    LogSpec({}, argOutPrints = {1: pointer(size = "n")}),
132         "glGenProgramPipelines":                                LogSpec({}, argOutPrints = {1: pointer(size = "n")}),
133 #       "glGetActiveAttrib":
134         "glGetActiveUniform":                                   LogSpec({}, argOutPrints = {3: pointer(size = "1"), 4: pointer(size = "1"), 5: enumPointer("ShaderVarType", size = "1"), 6: stringVal}),
135         "glGetActiveUniformsiv":                                LogSpec({2: pointer(size = "uniformCount"), 3: enum("UniformParam")}, argOutPrints = {4: pointer(size = "uniformCount")}),
136 #       "glGetAttachedShaders":
137         "glGetBooleanv":
138                 LogSpec(
139                         {
140                                 0: enum("GettableState"),
141                                 1: voidPointer                                  # second argument has type of GLboolean* (aka. char*). Prevent
142                                                                                                 # wrapper from attempting to print the argument as a C string.
143                         },
144                         argOutPrints = {1: booleanPointer(size = "getBasicQueryNumArgsOut(pname)")}),
145         "glGetBufferParameteriv":                               LogSpec({0: enum("BufferTarget"), 1: enum("BufferQuery")}),
146         "glGetBufferParameteri64v":                             LogSpec({0: enum("BufferTarget"), 1: enum("BufferQuery")}),
147         "glGetError":                                                   LogSpec({}, returnPrint = enum("Error")),
148         "glGetFloatv":                                                  LogSpec({0: enum("GettableState")}, argOutPrints = {1: pointer(size = "getBasicQueryNumArgsOut(pname)")}),
149         "glGetFramebufferAttachmentParameteriv":
150                 LogSpec(
151                         {
152                                 0: enum("FramebufferTarget"),
153                                 1: enum("FramebufferAttachment"),
154                                 2: enum("FramebufferAttachmentParameter")
155                         },
156                         argOutPrints = {3: lambda name: "getFramebufferAttachmentParameterValueStr(pname, %s)" % name}),
157         "glGetFramebufferParameteriv":                  LogSpec({0: enum("FramebufferTarget"), 1: enum("FramebufferParameter")}, argOutPrints = {2: pointer(size = "1")}),
158         "glGetIntegerv":                                                LogSpec({0: enum("GettableState")}, argOutPrints = {1: pointer(size = "getBasicQueryNumArgsOut(pname)")}),
159         "glGetInteger64v":                                              LogSpec({0: enum("GettableState")}, argOutPrints = {1: pointer(size = "getBasicQueryNumArgsOut(pname)")}),
160         "glGetIntegeri_v":                                              LogSpec({0: enum("GettableIndexedState")}, argOutPrints = {2:pointer(size = "getIndexedQueryNumArgsOut(target)")}),
161         "glGetInteger64i_v":                                            LogSpec({0: enum("GettableIndexedState")}, argOutPrints = {2: pointer(size = "getIndexedQueryNumArgsOut(target)")}),
162         "glGetBooleani_v":
163                 LogSpec(
164                         {
165                                 0: enum("GettableIndexedState"),
166                                 2: voidPointer                                  # last argument has type of GLboolean* (aka. char*). Prevent
167                                                                                                 # wrapper from attempting to print the argument as a C string.
168                         },
169                         argOutPrints = {2: booleanPointer(size = "getIndexedQueryNumArgsOut(target)")}),
170         "glGetInternalformativ":                                LogSpec({0: enum("InternalFormatTarget"), 1: enum("UncompressedTextureFormat"), 2: enum("InternalFormatParameter")}, argOutPrints = {4: pointer(size = "bufSize")}),
171         "glGetMultisamplefv":                                   LogSpec({0: enum("MultisampleParameter")}, argOutPrints = {2: pointer(size = "2")}),
172         "glGetPointerv":                                                LogSpec({0: enum("PointerState")}, argOutPrints = {1: pointer(size = "1")}),
173         "glGetProgramiv":                                               LogSpec({1: enum("ProgramParam")}, argOutPrints = {2: pointer(size = "getProgramQueryNumArgsOut(pname)")}),
174         "glGetProgramInfoLog":                                  LogSpec({3: voidPointer}, argOutPrints = {2: pointer(size = "1")}),
175         "glGetProgramPipelineiv":                               LogSpec({1: enum("PipelineParam")}, argOutPrints = {2: pointer(size = "1")}),
176         "glGetProgramPipelineInfoLog":                  LogSpec({3: voidPointer}, argOutPrints = {2: pointer(size = "1")}),
177         "glGetQueryiv":                                                 LogSpec({0: enum("QueryTarget"), 1: enum("QueryParam")}, argOutPrints = {2: pointer(size = "1")}),
178         "glGetQueryObjectiv":                                   LogSpec({1: enum("QueryObjectParam")}, argOutPrints = {2: pointer(size = "1")}),
179         "glGetQueryObjectuiv":                                  LogSpec({1: enum("QueryObjectParam")}, argOutPrints = {2: pointer(size = "1")}),
180         "glGetQueryObjecti64v":                                 LogSpec({1: enum("QueryObjectParam")}, argOutPrints = {2: pointer(size = "1")}),
181         "glGetQueryObjectui64v":                                LogSpec({1: enum("QueryObjectParam")}, argOutPrints = {2: pointer(size = "1")}),
182         "glGetRenderbufferParameteriv":                 LogSpec({0: enum("FramebufferTarget"), 1: enum("RenderbufferParameter")}),
183         "glGetSamplerParameterfv":                              LogSpec({1: enum("TextureParameter")}, argOutPrints = {2: pointer(size = "getTextureParamQueryNumArgsOut(pname)")}),
184         "glGetSamplerParameteriv":                              LogSpec({1: enum("TextureParameter")}, argOutPrints = {2: pointer(size = "getTextureParamQueryNumArgsOut(pname)")}),
185         "glGetSamplerParameterIiv":                             LogSpec({1: enum("TextureParameter")}, argOutPrints = {2: pointer(size = "getTextureParamQueryNumArgsOut(pname)")}),
186         "glGetSamplerParameterIuiv":                    LogSpec({1: enum("TextureParameter")}, argOutPrints = {2: pointer(size = "getTextureParamQueryNumArgsOut(pname)")}),
187         "glGetShaderiv":                                                LogSpec({1: enum("ShaderParam")}, argOutPrints = {2: pointer(size = "1")}),
188         "glGetShaderInfoLog":                                   LogSpec({3: voidPointer}, argOutPrints = {2: pointer(size = "1")}),
189         "glGetShaderPrecisionFormat":                   LogSpec({0: enum("ShaderType"), 1: enum("PrecisionFormatType")}),
190 #       "glGetShaderSource":
191         "glGetString":                                                  LogSpec({0: enum("GettableString")}, returnPrint=stringVal),
192         "glGetStringi":                                                 LogSpec({0: enum("GettableString")}, returnPrint=stringVal),
193         "glGetTexParameterfv":                                  LogSpec({0: enum("TextureTarget"), 1: enum("TextureParameter")}, argOutPrints = {2: pointer(size = "getTextureParamQueryNumArgsOut(pname)")}),
194         "glGetTexParameteriv":                                  LogSpec({0: enum("TextureTarget"), 1: enum("TextureParameter")}, argOutPrints = {2: pointer(size = "getTextureParamQueryNumArgsOut(pname)")}),
195         "glGetTexParameterIiv":                                 LogSpec({0: enum("TextureTarget"), 1: enum("TextureParameter")}, argOutPrints = {2: pointer(size = "getTextureParamQueryNumArgsOut(pname)")}),
196         "glGetTexParameterIuiv":                                LogSpec({0: enum("TextureTarget"), 1: enum("TextureParameter")}, argOutPrints = {2: pointer(size = "getTextureParamQueryNumArgsOut(pname)")}),
197         "glGetTexLevelParameterfv":                             LogSpec({0: enum("TextureTarget"), 2: enum("TextureLevelParameter")}, argOutPrints = {3: pointer(size = "1")}),
198         "glGetTexLevelParameteriv":                             LogSpec({0: enum("TextureTarget"), 2: enum("TextureLevelParameter")}, argOutPrints = {3: pointer(size = "1")}),
199 #       "glGetUniformfv":
200 #       "glGetUniformiv":
201         "glGetUniformIndices":                                  LogSpec({2: pointer(size = "uniformCount")}, argOutPrints = {3: pointer(size = "uniformCount")}),
202         "glGetVertexAttribfv":                                  LogSpec({1: enum("VertexAttribParameterName")}, argOutPrints = {2: pointer(size = "getAttributeQueryNumArgsOut(pname)")}),
203         "glGetVertexAttribiv":                                  LogSpec({1: enum("VertexAttribParameterName")}, argOutPrints = {2: pointer(size = "getAttributeQueryNumArgsOut(pname)")}),
204         "glGetVertexAttribIiv":                                 LogSpec({1: enum("VertexAttribParameterName")}, argOutPrints = {2: pointer(size = "getAttributeQueryNumArgsOut(pname)")}),
205         "glGetVertexAttribIuiv":                                LogSpec({1: enum("VertexAttribParameterName")}, argOutPrints = {2: pointer(size = "getAttributeQueryNumArgsOut(pname)")}),
206 #       "glGetVertexAttribPointerv":
207         "glHint":                                                               LogSpec({0: enum("Hint"), 1: enum("HintMode")}),
208         "glIsEnabled":                                                  LogSpec({0: enum("EnableCap")}),
209         "glIsEnabledi":                                                 LogSpec({0: enum("IndexedEnableCap")}),
210         "glPixelStorei":                                                LogSpec({0: enum("PixelStoreParameter")}),
211         "glReadBuffer":                                                 LogSpec({0: enum("DrawReadBuffer")}),
212         "glReadPixels":                                                 LogSpec({4: enum("UncompressedTextureFormat"), 5: enum("Type")}),
213         "glRenderbufferStorage":                                LogSpec({0: enum("FramebufferTarget"), 1: enum("UncompressedTextureFormat")}),
214         "glRenderbufferStorageMultisample":             LogSpec({0: enum("FramebufferTarget"), 2: enum("UncompressedTextureFormat")}),
215         "glStencilFunc":                                                LogSpec({0: enum("CompareFunc")}),
216         "glStencilFuncSeparate":                                LogSpec({0: enum("Face"), 1: enum("CompareFunc")}),
217         "glStencilMaskSeparate":                                LogSpec({0: enum("Face")}),
218         "glStencilOp":                                                  LogSpec({0: enum("StencilOp"), 1: enum("StencilOp"), 2: enum("StencilOp")}),
219         "glStencilOpSeparate":                                  LogSpec({0: enum("Face"), 1: enum("StencilOp"), 2: enum("StencilOp"), 3: enum("StencilOp")}),
220         "glTexImage1D":                                                 LogSpec({0: enum("TextureTarget"), 2: enum("UncompressedTextureFormat"), 5: enum("UncompressedTextureFormat"), 6: enum("Type")}),
221         "glTexImage2D":                                                 LogSpec({0: enum("TextureTarget"), 2: enum("UncompressedTextureFormat"), 6: enum("UncompressedTextureFormat"), 7: enum("Type")}),
222         "glTexImage2DMultisample":                              LogSpec({0: enum("TextureTarget"), 2: enum("UncompressedTextureFormat"), 5: enum("Boolean")}),
223         "glTexImage3D":                                                 LogSpec({0: enum("TextureTarget"), 2: enum("UncompressedTextureFormat"), 7: enum("UncompressedTextureFormat"), 8: enum("Type")}),
224         "glTexStorage2D":                                               LogSpec({0: enum("TextureTarget"), 2: enum("TextureFormat")}),
225         "glTexStorage3D":                                               LogSpec({0: enum("TextureTarget"), 2: enum("TextureFormat")}),
226         "glTexStorage2DMultisample":                    LogSpec({0: enum("TextureTarget"), 2: enum("UncompressedTextureFormat"), 5: enum("Boolean")}),
227         "glTexStorage3DMultisample":                    LogSpec({0: enum("TextureTarget"), 2: enum("UncompressedTextureFormat"), 6: enum("Boolean")}),
228         # \todo [2012-03-08 pyry] Pointer values..
229         "glTexParameterf":                                              LogSpec({0: enum("TextureTarget"), 1: enum("TextureParameter")}),
230         "glTexParameteri":                                              LogSpec({0: enum("TextureTarget"), 1: enum("TextureParameter"), 2: lambda name: "getTextureParameterValueStr(pname, %s)" % name}),
231         "glTexParameterfv":                                             LogSpec({0: enum("TextureTarget"), 1: enum("TextureParameter"), 2: pointer(size = "getTextureParamNumArgs(pname)")}),
232         "glTexParameteriv":                                             LogSpec({0: enum("TextureTarget"), 1: enum("TextureParameter"), 2: pointer(size = "getTextureParamNumArgs(pname)")}),
233         "glTexParameterIiv":                                    LogSpec({0: enum("TextureTarget"), 1: enum("TextureParameter"), 2: pointer(size = "getTextureParamNumArgs(pname)")}),
234         "glTexParameterIuiv":                                   LogSpec({0: enum("TextureTarget"), 1: enum("TextureParameter"), 2: pointer(size = "getTextureParamNumArgs(pname)")}),
235         "glSamplerParameterf":                                  LogSpec({1: enum("TextureParameter")}),
236         "glSamplerParameteri":                                  LogSpec({1: enum("TextureParameter"), 2: lambda name: "getTextureParameterValueStr(pname, %s)" % name}),
237         "glSamplerParameterfv":                                 LogSpec({1: enum("TextureParameter"), 2: pointer(size = "getTextureParamNumArgs(pname)")}),
238         "glSamplerParameteriv":                                 LogSpec({1: enum("TextureParameter"), 2: pointer(size = "getTextureParamNumArgs(pname)")}),
239         "glSamplerParameterIiv":                                LogSpec({1: enum("TextureParameter"), 2: pointer(size = "getTextureParamNumArgs(pname)")}),
240         "glSamplerParameterIuiv":                               LogSpec({1: enum("TextureParameter"), 2: pointer(size = "getTextureParamNumArgs(pname)")}),
241         "glTexSubImage1D":                                              LogSpec({0: enum("TextureTarget"), 4: enum("UncompressedTextureFormat"), 5: enum("Type")}),
242         "glTexSubImage2D":                                              LogSpec({0: enum("TextureTarget"), 6: enum("UncompressedTextureFormat"), 7: enum("Type")}),
243         "glTexSubImage3D":                                              LogSpec({0: enum("TextureTarget"), 8: enum("UncompressedTextureFormat"), 9: enum("Type")}),
244         "glUniform1fv":                                                 LogSpec({2: pointer(size = "(count * 1)")}),
245         "glUniform1iv":                                                 LogSpec({2: pointer(size = "(count * 1)")}),
246         "glUniform1uiv":                                                LogSpec({2: pointer(size = "(count * 1)")}),
247         "glUniform2fv":                                                 LogSpec({2: pointer(size = "(count * 2)")}),
248         "glUniform2iv":                                                 LogSpec({2: pointer(size = "(count * 2)")}),
249         "glUniform2uiv":                                                LogSpec({2: pointer(size = "(count * 2)")}),
250         "glUniform3fv":                                                 LogSpec({2: pointer(size = "(count * 3)")}),
251         "glUniform3iv":                                                 LogSpec({2: pointer(size = "(count * 3)")}),
252         "glUniform3uiv":                                                LogSpec({2: pointer(size = "(count * 3)")}),
253         "glUniform4fv":                                                 LogSpec({2: pointer(size = "(count * 4)")}),
254         "glUniform4iv":                                                 LogSpec({2: pointer(size = "(count * 4)")}),
255         "glUniform4uiv":                                                LogSpec({2: pointer(size = "(count * 4)")}),
256         "glUniformMatrix2fv":                                   LogSpec({3: pointer(size = "(count * 2*2)")}),
257         "glUniformMatrix3fv":                                   LogSpec({3: pointer(size = "(count * 3*3)")}),
258         "glUniformMatrix4fv":                                   LogSpec({3: pointer(size = "(count * 4*4)")}),
259         "glUniformMatrix2x3fv":                                 LogSpec({3: pointer(size = "(count * 2*3)")}),
260         "glUniformMatrix2x4fv":                                 LogSpec({3: pointer(size = "(count * 2*4)")}),
261         "glUniformMatrix3x2fv":                                 LogSpec({3: pointer(size = "(count * 3*2)")}),
262         "glUniformMatrix3x4fv":                                 LogSpec({3: pointer(size = "(count * 3*4)")}),
263         "glUniformMatrix4x2fv":                                 LogSpec({3: pointer(size = "(count * 4*2)")}),
264         "glUniformMatrix4x3fv":                                 LogSpec({3: pointer(size = "(count * 4*3)")}),
265         "glUseProgramStages":                                   LogSpec({1: enum("ShaderTypeMask")}),
266         "glPatchParameteri":                                    LogSpec({0: enum("PatchParam")}),
267         "glProgramParameteri":                                  LogSpec({1: enum("ProgramParam")}),
268         "glProgramUniform1fv":                                  LogSpec({3: pointer(size = "(count * 1)")}),
269         "glProgramUniform1iv":                                  LogSpec({3: pointer(size = "(count * 1)")}),
270         "glProgramUniform1uiv":                                 LogSpec({3: pointer(size = "(count * 1)")}),
271         "glProgramUniform2fv":                                  LogSpec({3: pointer(size = "(count * 2)")}),
272         "glProgramUniform2iv":                                  LogSpec({3: pointer(size = "(count * 2)")}),
273         "glProgramUniform2uiv":                                 LogSpec({3: pointer(size = "(count * 2)")}),
274         "glProgramUniform3fv":                                  LogSpec({3: pointer(size = "(count * 3)")}),
275         "glProgramUniform3iv":                                  LogSpec({3: pointer(size = "(count * 3)")}),
276         "glProgramUniform3uiv":                                 LogSpec({3: pointer(size = "(count * 3)")}),
277         "glProgramUniform4fv":                                  LogSpec({3: pointer(size = "(count * 4)")}),
278         "glProgramUniform4iv":                                  LogSpec({3: pointer(size = "(count * 4)")}),
279         "glProgramUniform4uiv":                                 LogSpec({3: pointer(size = "(count * 4)")}),
280         "glProgramUniformMatrix2fv":                    LogSpec({4: pointer(size = "(count * 2*2)")}),
281         "glProgramUniformMatrix3fv":                    LogSpec({4: pointer(size = "(count * 3*3)")}),
282         "glProgramUniformMatrix4fv":                    LogSpec({4: pointer(size = "(count * 4*4)")}),
283         "glProgramUniformMatrix2x3fv":                  LogSpec({4: pointer(size = "(count * 2*3)")}),
284         "glProgramUniformMatrix2x4fv":                  LogSpec({4: pointer(size = "(count * 2*4)")}),
285         "glProgramUniformMatrix3x2fv":                  LogSpec({4: pointer(size = "(count * 3*2)")}),
286         "glProgramUniformMatrix3x4fv":                  LogSpec({4: pointer(size = "(count * 3*4)")}),
287         "glProgramUniformMatrix4x3fv":                  LogSpec({4: pointer(size = "(count * 4*3)")}),
288         "glProgramUniformMatrix4x2fv":                  LogSpec({4: pointer(size = "(count * 4*2)")}),
289         "glProvokingVertex":                                    LogSpec({0: enum("ProvokingVertex")}),
290         "glVertexAttrib1fv":                                    LogSpec({1: pointer(size = "1")}),
291         "glVertexAttrib2fv":                                    LogSpec({1: pointer(size = "2")}),
292         "glVertexAttrib3fv":                                    LogSpec({1: pointer(size = "3")}),
293         "glVertexAttrib4fv":                                    LogSpec({1: pointer(size = "4")}),
294         "glVertexAttrib1sv":                                    LogSpec({1: pointer(size = "1")}),
295         "glVertexAttrib2sv":                                    LogSpec({1: pointer(size = "2")}),
296         "glVertexAttrib3sv":                                    LogSpec({1: pointer(size = "3")}),
297         "glVertexAttrib4sv":                                    LogSpec({1: pointer(size = "4")}),
298         "glVertexAttrib1dv":                                    LogSpec({1: pointer(size = "1")}),
299         "glVertexAttrib2dv":                                    LogSpec({1: pointer(size = "2")}),
300         "glVertexAttrib3dv":                                    LogSpec({1: pointer(size = "3")}),
301         "glVertexAttrib4dv":                                    LogSpec({1: pointer(size = "4")}),
302         "glVertexAttrib4bv":                                    LogSpec({1: pointer(size = "4")}),
303         "glVertexAttrib4iv":                                    LogSpec({1: pointer(size = "4")}),
304         "glVertexAttrib4ubv":                                   LogSpec({1: pointer(size = "4")}),
305         "glVertexAttrib4usv":                                   LogSpec({1: pointer(size = "4")}),
306         "glVertexAttrib4uiv":                                   LogSpec({1: pointer(size = "4")}),
307         "glVertexAttrib4Nbv":                                   LogSpec({1: pointer(size = "4")}),
308         "glVertexAttrib4Nsv":                                   LogSpec({1: pointer(size = "4")}),
309         "glVertexAttrib4Niv":                                   LogSpec({1: pointer(size = "4")}),
310         "glVertexAttrib4Nubv":                                  LogSpec({1: pointer(size = "4")}),
311         "glVertexAttrib4Nusv":                                  LogSpec({1: pointer(size = "4")}),
312         "glVertexAttrib4Nuiv":                                  LogSpec({1: pointer(size = "4")}),
313         "glVertexAttribI1iv":                                   LogSpec({1: pointer(size = "1")}),
314         "glVertexAttribI2iv":                                   LogSpec({1: pointer(size = "2")}),
315         "glVertexAttribI3iv":                                   LogSpec({1: pointer(size = "3")}),
316         "glVertexAttribI4iv":                                   LogSpec({1: pointer(size = "4")}),
317         "glVertexAttribI1uiv":                                  LogSpec({1: pointer(size = "1")}),
318         "glVertexAttribI2uiv":                                  LogSpec({1: pointer(size = "2")}),
319         "glVertexAttribI3uiv":                                  LogSpec({1: pointer(size = "3")}),
320         "glVertexAttribI4uiv":                                  LogSpec({1: pointer(size = "4")}),
321         "glVertexAttribI4bv":                                   LogSpec({1: pointer(size = "4")}),
322         "glVertexAttribI4sv":                                   LogSpec({1: pointer(size = "4")}),
323         "glVertexAttribI4ubv":                                  LogSpec({1: pointer(size = "4")}),
324         "glVertexAttribI4usv":                                  LogSpec({1: pointer(size = "4")}),
325         "glVertexAttribPointer":                                LogSpec({2: enum("Type")}),
326         "glVertexAttribIPointer":                               LogSpec({2: enum("Type")}),
327         "glVertexAttribFormat":                                 LogSpec({2: enum("Type")}),
328         "glVertexAttribIFormat":                                LogSpec({2: enum("Type")}),
329         "glInvalidateFramebuffer":                              LogSpec({0: enum("FramebufferTarget"), 2: enumPointer("InvalidateAttachment", "numAttachments")}),
330         "glInvalidateSubFramebuffer":                   LogSpec({0: enum("FramebufferTarget"), 2: enumPointer("InvalidateAttachment", "numAttachments")}),
331         "glMapBufferRange":                                             LogSpec({0: enum("BufferTarget"), 3: enum("BufferMapFlags")}),
332         "glUnmapBuffer":                                                LogSpec({0: enum("BufferTarget")}),
333         "glFlushMappedBufferRange":                             LogSpec({0: enum("BufferTarget")}),
334         "glMemoryBarrier":                                              LogSpec({0: enum("MemoryBarrierFlags")}),
335         "glBindImageTexture":                                   LogSpec({5: enum("ImageAccess"), 6: enum("UncompressedTextureFormat")}),
336         "glGetProgramResourceIndex":                    LogSpec({1: enum("ProgramInterface")}),
337         "glGetProgramResourceiv":
338                 LogSpec(
339                         {
340                                 1: enum("ProgramInterface"),
341                                 4: enumPointer("ProgramResourceProperty", "propCount")
342                         },
343                         argOutPrints =
344                         {
345                                 6: pointer(size = "1"),
346                                 7: pointer(size = "((length == DE_NULL) ? (bufSize) : ((bufSize < *length) ? (bufSize) : (*length)))")
347                         }),
348         "glDebugMessageInsert":                                 LogSpec({0: enum("DebugMessageSource"), 1: enum("DebugMessageType"), 3: enum("DebugMessageSeverity")}),
349         "glDebugMessageControl":                                LogSpec({0: enum("DebugMessageSource"), 1: enum("DebugMessageType"), 2: enum("DebugMessageSeverity"), 4: pointer(size = "(count)")}),
350         "glDebugMessageCallback":                               LogSpec({0: fnPointer, 1: voidPointer}),
351         "glPushDebugGroup":                                             LogSpec({0: enum("DebugMessageSource")}),
352         "glTexBuffer":                                                  LogSpec({0: enum("BufferTarget"), 1: enum("UncompressedTextureFormat")}),
353         "glTexBufferRange":                                             LogSpec({0: enum("BufferTarget"), 1: enum("UncompressedTextureFormat")}),
354 }
355
356 def glwPrefix (string):
357         return re.sub(r'\bGL', 'glw::GL', string)
358
359 def prefixedParams (command):
360         if len(command.params) > 0:
361                 return ", ".join(glwPrefix(param.declaration) for param in command.params)
362         else:
363                 return "void"
364
365 def commandLogWrapperMemberDecl (command):
366         return "%s\t%s\t(%s);" % (glwPrefix(command.type), command.name, prefixedParams(command))
367
368 def getVarDefaultPrint (type, varName):
369         if re.match(r'^const +GLchar *\*$', type):
370                 return "getStringStr(%s)" % varName
371         elif re.match(r'(GLubyte|GLbyte|GLenum|GLushort|GLbitfield|\*)$', type):
372                 return "toHex(%s)" % varName
373         elif type == 'GLboolean':
374                 return "getBooleanStr(%s)" % varName
375         elif re.match(r'^(const +)?.+ *\*$', type) and not re.match(r'^(const +)?void *\*$', type):
376                 # non-void pointer type, always cast to void* to avoid unforeseen consequences of
377                 # implicit assumptions (such as char* should be printed as a zero-terminated string)
378                 # \note use static_cast to break the build if function pointer is supplied
379                 return "toHex(reinterpret_cast<deUintptr>(static_cast<const void*>(%s)))" % varName
380         else:
381                 return varName
382
383 def commandLogWrapperMemberDef (command):
384         src = ""
385         try:
386                 logSpec = CALL_LOG_SPECS[command.name]
387         except KeyError:
388                 logSpec = None
389
390         src += "\n"
391         src += "%s CallLogWrapper::%s (%s)\n{\n" % (glwPrefix(command.type), command.name, prefixedParams(command))
392
393         # Append paramemetrs
394         callPrintItems = ["\"%s(\"" % command.name]
395         for paramNdx, param in enumerate(command.params):
396                 if paramNdx > 0:
397                         callPrintItems.append("\", \"")
398
399                 if logSpec and paramNdx in logSpec.argInPrints:
400                         callPrintItems.append(logSpec.argInPrints[paramNdx](param.name))
401                 else:
402                         callPrintItems.append(getVarDefaultPrint(param.type, param.name))
403
404         callPrintItems += ["\");\"", "TestLog::EndMessage"]
405
406         src += "\tif (m_enableLog)\n"
407         src += "\t\tm_log << TestLog::Message << %s;\n" % " << ".join(callPrintItems)
408
409         callStr = "m_gl.%s(%s)" % (getFunctionMemberName(command.name), ", ".join([p.name for p in command.params]))
410
411         isVoid  = command.type == 'void'
412         if isVoid:
413                 src += "\t%s;\n" % callStr
414         else:
415                 src += "\t%s returnValue = %s;\n" % (glwPrefix(command.type), callStr)
416
417         if logSpec and len(logSpec.argOutPrints) > 0:
418                 # Print values returned in pointers
419                 src += "\tif (m_enableLog)\n"
420                 printouts = ""
421                 numPrintouts = 0
422
423                 for paramNdx, param in enumerate(command.params):
424                         if paramNdx in logSpec.argOutPrints:
425                                 printouts += "\t\tm_log << TestLog::Message << \"// %s = \" << %s << TestLog::EndMessage;\n" % (param.name, logSpec.argOutPrints[paramNdx](param.name))
426                                 numPrintouts += 1
427
428                 # If print handlers do not match the actual command, that is very likely an error. Check
429                 # print handlers is a subset of all arguments.
430                 if numPrintouts == 0 or len(set(logSpec.argOutPrints.keys()) - set(range(len(command.params)))) > 0:
431                         raise Exception("Invalid print handlers when processing command %s" % command.name)
432
433                 if numPrintouts != 1:
434                         src += "\t{\n"
435                 src += printouts
436                 if numPrintouts != 1:
437                         src += "\t}\n"
438
439         if not isVoid:
440                 # Print return value
441                 returnPrint = getVarDefaultPrint(command.type, "returnValue")
442                 if logSpec and logSpec.returnPrint:
443                         returnPrint = logSpec.returnPrint("returnValue")
444
445                 src += "\tif (m_enableLog)\n"
446                 src += "\t\tm_log << TestLog::Message << \"// \" << %s << \" returned\" << TestLog::EndMessage;\n" % returnPrint
447                 src += "\treturn returnValue;\n"
448
449         src += "}"
450         return src
451
452 def genCallLogWrapper (iface):
453         genCommandList(iface, commandLogWrapperMemberDecl, OPENGL_DIR, "gluCallLogWrapperApi.inl", True)
454         genCommandList(iface, commandLogWrapperMemberDef, OPENGL_DIR, "gluCallLogWrapper.inl", False)
455
456 if __name__ == "__main__":
457         genCallLogWrapper(getHybridInterface())