1// 2// Copyright (C) 2024 The Android Open Source Project 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 17package vulkan_types 18 19import ( 20 "berberis/cpp_types" 21 "fmt" 22) 23 24var DisplayType = cpp_types.OpaqueType("Display") 25 26var DWORDType = cpp_types.AliasType("DWORD", cpp_types.UInt32TType) 27 28var GgpFrameTokenType = cpp_types.AliasType("GgpFrameToken", cpp_types.UInt64TType) 29 30var GgpStreamDescriptorType = cpp_types.AliasType( 31 "GgpStreamDescriptor", cpp_types.UInt32TType) 32 33var HANDLEType = cpp_types.AliasType( 34 "HANDLE", cpp_types.PointerType(cpp_types.VoidType)) 35 36var HINSTANCEType = cpp_types.AliasType("HINSTANCE", HANDLEType) 37 38var HMONITORType = cpp_types.AliasType("HINSTANCE", HANDLEType) 39 40var HWNDType = cpp_types.AliasType("HWND", HANDLEType) 41 42// Note: that type must be converted like similar types in GLES/SLES, 43// but we don't have support for these on Android. 44var IDirectFBType = cpp_types.AliasType( 45 "IDirectFB", cpp_types.OpaqueType("struct IDirectFB")) 46 47// Note: that type must be converted like similar types in GLES/SLES, 48// but we don't have support for these on Android. 49var IDirectFBSurfaceType = cpp_types.AliasType( 50 "IDirectFBSurface", cpp_types.OpaqueType("struct IDirectFBSurface")) 51 52// Note: LPCWSTR is supposed to be pointer to Windows's 16bit const wchar_t string, but on Linux 53// (including Android) wchar_t is 32bit type. We're using char16_t for portability: that's not 54// canonical definition of LPCWSTR but it's the same on all platforms and on Windows it's compatible 55// with canonical one. 56var LPCWSTRType = cpp_types.AliasType("LPCWSTR", 57 cpp_types.PointerType(cpp_types.ConstType(cpp_types.Char16TType))) 58 59var XIDType = cpp_types.AliasType("XID", cpp_types.ULongType) 60 61var RROutputType = cpp_types.AliasType("RROutput", XIDType) 62 63var SECURITY_ATTRIBUTESType = cpp_types.OpaqueType("SECURITY_ATTRIBUTES") 64 65var VisualIDType = cpp_types.AliasType("VisualID", cpp_types.ULongType) 66 67var WindowType = cpp_types.AliasType("Window", XIDType) 68 69var WLDisplayType = cpp_types.OpaqueType("wl_display") 70 71var WLSurfaceType = cpp_types.OpaqueType("wl_surface") 72 73var XcbConnectionTType = cpp_types.OpaqueType("xcb_connection_t") 74 75var XcbVisualidTType = cpp_types.AliasType("xcb_visualid_t", cpp_types.UInt32TType) 76 77var XcbWindowTType = cpp_types.AliasType("xcb_window_t", cpp_types.UInt32TType) 78 79var ZxHandleTType = cpp_types.AliasType("zx_handle_t", cpp_types.UInt32TType) 80 81func PlatformTypes() map[string]cpp_types.Type { 82 return map[string]cpp_types.Type{ 83 "_screen_context": cpp_types.VoidType, // Treat as opaque type for now. 84 "_screen_window": cpp_types.VoidType, // Treat as opaque type for now. 85 "_screen_buffer": cpp_types.VoidType, // Treat as opaque type for now. 86 "NvSciSyncAttrList": cpp_types.IntType, 87 "NvSciSyncObj": cpp_types.IntType, 88 "NvSciSyncFence": cpp_types.IntType, 89 "NvSciBufAttrList": cpp_types.IntType, 90 "NvSciBufObj": cpp_types.IntType, 91 "char": cpp_types.CharType, 92 "Display": DisplayType, 93 "double": cpp_types.Float64Type, 94 "DWORD": DWORDType, 95 "float": cpp_types.Float32Type, 96 "GgpFrameToken": GgpFrameTokenType, 97 "GgpStreamDescriptor": GgpStreamDescriptorType, 98 "HANDLE": HANDLEType, 99 "HINSTANCE": HINSTANCEType, 100 "HMONITOR": HMONITORType, 101 "HWND": HWNDType, 102 "IDirectFB": IDirectFBType, 103 "IDirectFBSurface": IDirectFBSurfaceType, 104 "int": cpp_types.IntType, 105 "int8_t": cpp_types.Int8TType, 106 "int16_t": cpp_types.Int16TType, 107 "int32_t": cpp_types.Int32TType, 108 "int64_t": cpp_types.Int64TType, 109 "LPCWSTR": LPCWSTRType, 110 "XID": XIDType, 111 "RROutput": RROutputType, 112 "SECURITY_ATTRIBUTES": SECURITY_ATTRIBUTESType, 113 "size_t": cpp_types.SizeTType, 114 "StdVideoDecodeH264Mvc": cpp_types.VoidType, // Treat as opaque type for now. 115 "StdVideoDecodeH264MvcElement": cpp_types.VoidType, // Treat as opaque type for now. 116 "StdVideoDecodeH264MvcElementFlags": cpp_types.IntType, // That's actually a struct with bitfields, but it's compatible with int32_t. 117 "StdVideoDecodeH264PictureInfo": cpp_types.VoidType, // Treat as opaque type for now. 118 "StdVideoDecodeH264PictureInfoFlags": cpp_types.IntType, // That's actually a struct with bitfields, but it's compatible with int32_t. 119 "StdVideoDecodeH264ReferenceInfo": cpp_types.VoidType, // Treat as opaque type for now. 120 "StdVideoDecodeH264ReferenceInfoFlags": cpp_types.IntType, // That's actually a struct with bitfields, but it's compatible with int32_t. 121 "StdVideoDecodeH265PictureInfo": cpp_types.VoidType, // Treat as opaque type for now. 122 "StdVideoDecodeH265PictureInfoFlags": cpp_types.IntType, // That's actually a struct with bitfields, but it's compatible with int32_t. 123 "StdVideoDecodeH265ReferenceInfo": cpp_types.VoidType, // Treat as opaque type for now. 124 "StdVideoDecodeH265ReferenceInfoFlags": cpp_types.IntType, // That's actually a struct with bitfields, but it's compatible with int32_t. 125 "StdVideoEncodeH264PictureInfo": cpp_types.VoidType, // Treat as opaque type for now. 126 "StdVideoEncodeH264PictureInfoFlags": cpp_types.IntType, // That's actually a struct with bitfields, but it's compatible with int32_t. 127 "StdVideoEncodeH264RefListModEntry": cpp_types.VoidType, // Treat as opaque type for now. 128 "StdVideoEncodeH264RefMemMgmtCtrlOperations": cpp_types.VoidType, // Treat as opaque type for now. 129 "StdVideoEncodeH264RefMgmtFlags": cpp_types.IntType, // That's actually a struct with bitfields, but it's compatible with int32_t. 130 "StdVideoEncodeH264RefPicMarkingEntry": cpp_types.VoidType, // Treat as opaque type for now. 131 "StdVideoEncodeH264ReferenceInfo": cpp_types.VoidType, // Treat as opaque type for now. 132 "StdVideoEncodeH264ReferenceListsInfo": cpp_types.VoidType, // Treat as opaque type for now. 133 "StdVideoEncodeH264ReferenceInfoFlags": cpp_types.IntType, // That's actually a struct with bitfields, but it's compatible with int32_t. 134 "StdVideoEncodeH264SliceHeader": cpp_types.VoidType, // Treat as opaque type for now. 135 "StdVideoEncodeH264SliceHeaderFlags": cpp_types.IntType, // That's actually a struct with bitfields, but it's compatible with int32_t. 136 "StdVideoEncodeH265PictureInfo": cpp_types.VoidType, // Treat as opaque type for now. 137 "StdVideoEncodeH265PictureInfoFlags": cpp_types.IntType, // That's actually a struct with bitfields, but it's compatible with int32_t. 138 "StdVideoEncodeH265ReferenceInfo": cpp_types.VoidType, // Treat as opaque type for now. 139 "StdVideoEncodeH265ReferenceListsInfo": cpp_types.VoidType, // Treat as opaque type for now. 140 "StdVideoEncodeH265ReferenceInfoFlags": cpp_types.IntType, // That's actually a struct with bitfields, but it's compatible with int32_t. 141 "StdVideoEncodeH265ReferenceModificationFlags": cpp_types.IntType, // That's actually a struct with bitfields, but it's compatible with int32_t. 142 "StdVideoEncodeH265ReferenceModifications": cpp_types.VoidType, // Treat as opaque type for now. 143 "StdVideoEncodeH265SliceHeader": cpp_types.VoidType, // Treat as opaque type for now. 144 "StdVideoEncodeH265SliceHeaderFlags": cpp_types.IntType, // That's actually a struct with bitfields, but it's compatible with int32_t. 145 "StdVideoEncodeH265SliceSegmentHeader": cpp_types.VoidType, // Treat as opaque type for now. 146 "StdVideoEncodeH265SliceSegmentHeaderFlags": cpp_types.VoidType, // Treat as opaque type for now. 147 "StdVideoH264AspectRatioIdc": cpp_types.IntType, 148 "StdVideoH264CabacInitIdc": cpp_types.IntType, 149 "StdVideoH264ChromaFormatIdc": cpp_types.IntType, 150 "StdVideoH264DisableDeblockingFilterIdc": cpp_types.IntType, 151 "StdVideoH264HrdParameters": cpp_types.VoidType, // Treat as opaque type for now. 152 "StdVideoH264Level": cpp_types.IntType, 153 "StdVideoH264LevelIdc": cpp_types.IntType, 154 "StdVideoH264MemMgmtControlOp": cpp_types.IntType, 155 "StdVideoH264ModificationOfPicNumsIdc": cpp_types.IntType, 156 "StdVideoH264PictureParameterSet": cpp_types.VoidType, // Treat as opaque type for now. 157 "StdVideoH264PictureType": cpp_types.IntType, 158 "StdVideoH264PocType": cpp_types.IntType, 159 "StdVideoH264PpsFlags": cpp_types.IntType, // That's actually a struct with bitfields, but it's compatible with int32_t. 160 "StdVideoH264ProfileIdc": cpp_types.IntType, 161 "StdVideoH264ScalingLists": cpp_types.VoidType, // Treat as opaque type for now. 162 "StdVideoH264SequenceParameterSet": cpp_types.VoidType, // Treat as opaque type for now. 163 "StdVideoH264SequenceParameterSetVui": cpp_types.VoidType, // Treat as opaque type for now. 164 "StdVideoH264SliceType": cpp_types.IntType, 165 "StdVideoH264SpsFlags": cpp_types.IntType, // That's actually a struct with bitfields, but it's compatible with int32_t. 166 "StdVideoH264SpsVuiFlags": cpp_types.IntType, // That's actually a struct with bitfields, but it's compatible with int32_t. 167 "StdVideoH264WeightedBiPredIdc": cpp_types.IntType, 168 "StdVideoH264WeightedBipredIdc": cpp_types.IntType, 169 "StdVideoH265PictureParameterSet": cpp_types.VoidType, // Treat as opaque type for now. 170 "StdVideoH265DecPicBufMgr": cpp_types.VoidType, // Treat as opaque type for now. 171 "StdVideoH265HrdFlags": cpp_types.VoidType, // Treat as opaque type for now. 172 "StdVideoH265HrdParameters": cpp_types.VoidType, // Treat as opaque type for now. 173 "StdVideoH265Level": cpp_types.VoidType, // Treat as opaque type for now. 174 "StdVideoH265LevelIdc": cpp_types.IntType, 175 "StdVideoH265PictureType": cpp_types.IntType, 176 "StdVideoH265PpsFlags": cpp_types.VoidType, // Treat as opaque type for now. 177 "StdVideoH265PredictorPaletteEntries": cpp_types.VoidType, // Treat as opaque type for now. 178 "StdVideoH265ProfileIdc": cpp_types.IntType, 179 "StdVideoH265ScalingLists": cpp_types.VoidType, // Treat as opaque type for now. 180 "StdVideoH265SequenceParameterSet": cpp_types.VoidType, // Treat as opaque type for now. 181 "StdVideoH265SequenceParameterSetVui": cpp_types.VoidType, // Treat as opaque type for now. 182 "StdVideoH265SliceType": cpp_types.IntType, 183 "StdVideoH265SpsFlags": cpp_types.IntType, // That's actually a struct with bitfields, but it's compatible with int32_t. 184 "StdVideoH265SpsVuiFlags": cpp_types.IntType, // That's actually a struct with bitfields, but it's compatible with int32_t. 185 "StdVideoH265SubLayerHrdParameters": cpp_types.VoidType, // Treat as opaque type for now. 186 "StdVideoH265VideoParameterSet": cpp_types.VoidType, // Treat as opaque type for now. 187 "StdVideoH265VpsFlags": cpp_types.VoidType, // Treat as opaque type for now. 188 "uint8_t": cpp_types.UInt8TType, 189 "uint16_t": cpp_types.UInt16TType, 190 "uint32_t": cpp_types.UInt32TType, 191 "uint64_t": cpp_types.UInt64TType, 192 "VisualID": VisualIDType, 193 "void": cpp_types.VoidType, 194 "Window": WindowType, 195 "wl_display": WLDisplayType, 196 "wl_surface": WLSurfaceType, 197 "xcb_connection_t": XcbConnectionTType, 198 "xcb_visualid_t": XcbVisualidTType, 199 "xcb_window_t": XcbWindowTType, 200 "zx_handle_t": ZxHandleTType} 201} 202 203func IsVulkanHandle(typе cpp_types.Type) bool { 204 for arch := cpp_types.FirstArch; arch <= cpp_types.LastArch; arch++ { 205 if !isVulkanHandle(typе, arch) { 206 return false 207 } 208 } 209 return true 210} 211 212func IsVulkanNondispatchableHandle(typе cpp_types.Type) bool { 213 return isVulkanNondispatchableHandle(typе, cpp_types.Arm) && 214 isVulkanNondispatchableHandle(typе, cpp_types.X86) && 215 isVulkanHandle(typе, cpp_types.Arm64) && 216 isVulkanHandle(typе, cpp_types.X86_64) 217} 218 219func isVulkanHandle(typе cpp_types.Type, arch cpp_types.Arch) bool { 220 return typе.Kind(arch) == cpp_types.Alias && 221 typе.Elem(arch).Kind(arch) == cpp_types.Ptr && 222 typе.Elem(arch).Elem(arch).Kind(arch) == cpp_types.Opaque && 223 typе.Elem(arch).Elem(arch).Name(arch) == fmt.Sprintf("struct %s_T", typе.Name(arch)) 224} 225 226func isVulkanNondispatchableHandle(typе cpp_types.Type, arch cpp_types.Arch) bool { 227 return typе.Kind(arch) == cpp_types.Alias && 228 typе.Elem(arch).Kind(arch) == cpp_types.UInt64T 229} 230