Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cbf5c851 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Generate Vulkan framework from Vulkan registry (Part 4)"

parents d9773a8b 8dce9d78
Loading
Loading
Loading
Loading
+3 −14
Original line number Diff line number Diff line
@@ -10,19 +10,8 @@ Use "clang-format -style=file" to format all C/C++ code, except code imported ve

## Code Generation

We generate several parts of the loader and tools from a Vulkan API description file, stored in `api/vulkan.api`. Code generation must be done manually because the generator tools aren't part of the platform toolchain (yet?). Files named `foo_gen.*` are generated from the API file and a template file named `foo.tmpl`.
We generate several parts of the loader and tools driectly from the Vulkan Registry (external/vulkan-headers/registry/vk.xml). Code generation must be done manually because the generator is not part of the platform toolchain (yet?). Files named `foo_gen.*` are generated by the code generator.

 To run the generator:

### One-time setup
- Install [golang](https://golang.org/), if you don't have it already.
- Create a directory (e.g. `$HOME/lib/go`) for local go sources and binaries and add it to `$GOPATH`.
- `$ git clone https://android.googlesource.com/platform/tools/gpu $GOPATH/src/android.googlesource.com/platform/tools/gpu`
- `$ go get android.googlesource.com/platform/tools/gpu/api/...`
- You should now have `$GOPATH/bin/apic`. You might want to add `$GOPATH/bin` to your `$PATH`.

### Generating code
To generate `libvulkan/*_gen.*`,
- `$ cd libvulkan`
- `$ apic template ../api/vulkan.api code-generator.tmpl`
Similar for `nulldrv/null_driver_gen.*`.
- Install Python3 (if not already installed)
- `$ ./<path to>/frameworks/native/vulkan/scripts/code_generator.py`

vulkan/api/platform.api

deleted100644 → 0
+0 −61
Original line number Diff line number Diff line
// Copyright (c) 2015 The Khronos Group Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and/or associated documentation files (the
// "Materials"), to deal in the Materials without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Materials, and to
// permit persons to whom the Materials are furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Materials.
//
// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.

// Platform types, as defined or included in vk_platform.h

type u64 size_t

// VK_USE_PLATFORM_XLIB_KHR
@internal class Display {}
@internal class Window {}
@internal type u64 VisualID

// VK_USE_PLATFORM_XCB_KHR
@internal class xcb_connection_t {}
@internal type u32 xcb_window_t
@internal type u32 xcb_visualid_t

// VK_USE_PLATFORM_WAYLAND_KHR
@internal class wl_display {}
@internal class wl_surface {}

// VK_USE_PLATFORM_MIR_KHR
@internal class MirConnection {}
@internal class MirSurface {}

// VK_USE_PLATFORM_ANDROID_KHR
@internal class ANativeWindow {}
@internal class AHardwareBuffer {}
@internal type void* buffer_handle_t

// VK_USE_PLATFORM_WIN32_KHR
@internal type void* HINSTANCE
@internal type void* HWND
@internal type void* HANDLE
@internal type u32   DWORD
@internal type u16*  LPCWSTR
@internal class SECURITY_ATTRIBUTES {}

// VK_USE_PLATFORM_XLIB_XRANDR_EXT
@internal type u64 RROutput

// VK_USE_PLATFORM_FUCHSIA
@internal type u32 zx_handle_t
 No newline at end of file
+0 −223
Original line number Diff line number Diff line
{{$clang_style := "{BasedOnStyle: Google, AccessModifierOffset: -4, ColumnLimit: 200, ContinuationIndentWidth: 8, IndentWidth: 4, AlignOperands: true, CommentPragmas: '.*'}"}}
{{Global "clang-format" (Strings "clang-format" "-style" $clang_style)}}


{{/*
-------------------------------------------------------------------------------
  Emits the C translation for the specified type.
-------------------------------------------------------------------------------
*/}}
{{define "Type.Class"      }}{{if GetAnnotation $.Type "internal"}}struct {{end}}{{Macro "StructName" $.Type}}{{end}}
{{define "Type.Pseudonym"  }}{{$.Type.Name}}{{end}}
{{define "Type.Enum"       }}{{$.Type.Name}}{{end}}
{{define "Type.StaticArray"}}{{Node "Type" $.Type.ValueType}}{{end}}
{{define "Type.Pointer"    }}{{if $.Type.Const}}{{Node "ConstType" $.Type.To}}{{else}}{{Node "Type" $.Type.To}}{{end}}*{{end}}
{{define "Type.Slice"      }}{{Log "%T %+v" $.Node $.Node}}{{Node "Type" $.Type.To}}*{{end}}
{{define "Type#bool"       }}bool{{end}}
{{define "Type#int"        }}int{{end}}
{{define "Type#uint"       }}unsigned int{{end}}
{{define "Type#s8"         }}int8_t{{end}}
{{define "Type#u8"         }}uint8_t{{end}}
{{define "Type#s16"        }}int16_t{{end}}
{{define "Type#u16"        }}uint16_t{{end}}
{{define "Type#s32"        }}int32_t{{end}}
{{define "Type#u32"        }}uint32_t{{end}}
{{define "Type#f32"        }}float{{end}}
{{define "Type#s64"        }}int64_t{{end}}
{{define "Type#u64"        }}uint64_t{{end}}
{{define "Type#f64"        }}double{{end}}
{{define "Type#void"       }}void{{end}}
{{define "Type#char"       }}char{{end}}

{{define "ConstType_Default"}}const {{Node "Type" $.Type}}{{end}}
{{define "ConstType.Pointer"}}{{Node "Type" $.Type}} const{{end}}


{{/*
-------------------------------------------------------------------------------
  Emits the C translation for the specified documentation block (string array).
-------------------------------------------------------------------------------
*/}}
{{define "Docs"}}
  {{if $}}// {{$ | JoinWith "\n// "}}{{end}}
{{end}}


{{/*
-------------------------------------------------------------------------------
  Emits the name of a bitfield entry.
-------------------------------------------------------------------------------
*/}}
{{define "BitfieldEntryName"}}
  {{AssertType $ "EnumEntry"}}

  {{Macro "EnumEntry" $}}
{{end}}


{{/*
-------------------------------------------------------------------------------
  Emits the name of an enum type.
-------------------------------------------------------------------------------
*/}}
{{define "EnumName"}}{{AssertType $ "Enum"}}{{$.Name}}{{end}}


{{/*
-------------------------------------------------------------------------------
  Emits the name of an enum entry.
-------------------------------------------------------------------------------
*/}}
{{define "EnumEntry"}}
  {{AssertType $.Owner "Enum"}}
  {{AssertType $.Name "string"}}

  {{$.Name}}
{{end}}


{{/*
-------------------------------------------------------------------------------
  Emits the name of the first entry of an enum.
-------------------------------------------------------------------------------
*/}}
{{define "EnumFirstEntry"}}
  {{AssertType $ "Enum"}}

  {{range $i, $e := $.Entries}}
    {{if not $i}}{{$e.Name}}{{end}}
  {{end}}
{{end}}


{{/*
-------------------------------------------------------------------------------
  Emits the name of the last entry of an enum.
-------------------------------------------------------------------------------
*/}}{{define "EnumLastEntry"}}
  {{AssertType $ "Enum"}}

  {{range $i, $e := $.Entries}}
    {{if not (HasMore $i $.Entries)}}{{$e.Name}}{{end}}
  {{end}}
{{end}}


{{/*
-------------------------------------------------------------------------------
  Emits the name of a struct (class) type.
-------------------------------------------------------------------------------
*/}}
{{define "StructName"}}{{AssertType $ "Class"}}{{$.Name}}{{end}}


{{/*
-------------------------------------------------------------------------------
  Emits the name of a function.
-------------------------------------------------------------------------------
*/}}
{{define "FunctionName"}}{{AssertType $ "Function"}}{{$.Name}}{{end}}


{{/*
-------------------------------------------------------------------------------
  Emits the fixed-size-array postfix for pseudonym types annotated with @array
-------------------------------------------------------------------------------
*/}}
{{define "ArrayPostfix"}}{{Node "ArrayPostfix" $}}{{end}}
{{define "ArrayPostfix.StaticArray"}}[{{$.Type.Size}}]{{end}}
{{define "ArrayPostfix_Default"}}{{end}}


{{/*
-------------------------------------------------------------------------------
  Emits a C type and name for the given parameter
-------------------------------------------------------------------------------
*/}}
{{define "Parameter"}}
  {{AssertType $ "Parameter"}}

  {{if GetAnnotation $ "readonly"}}const {{end}}{{Macro "ParameterType" $}} {{$.Name}}{{Macro "ArrayPostfix" $}}
{{end}}


{{/*
-------------------------------------------------------------------------------
  Emits a C name for the given parameter
-------------------------------------------------------------------------------
*/}}
{{define "ParameterName"}}
  {{AssertType $ "Parameter"}}

  {{$.Name}}
{{end}}


{{/*
-------------------------------------------------------------------------------
  Emits a C type for the given parameter
-------------------------------------------------------------------------------
*/}}
{{define "ParameterType"}}{{AssertType $ "Parameter"}}{{Node "Type" $}}{{end}}


{{/*
-------------------------------------------------------------------------------
  Emits a comma-separated list of C type-name paired parameters for the given
  command.
-------------------------------------------------------------------------------
*/}}
{{define "Parameters"}}
  {{AssertType $ "Function"}}

  {{ForEach $.CallParameters "Parameter" | JoinWith ", "}}
  {{if not $.CallParameters}}void{{end}}
{{end}}


{{/*
-------------------------------------------------------------------------------
  Emits the C function pointer name for the specified command.
-------------------------------------------------------------------------------
*/}}
{{define "FunctionPtrName"}}
  {{AssertType $ "Function"}}

  PFN_{{$.Name}}
{{end}}


{{/*
-------------------------------------------------------------------------------
  Parses const variables as text Globals.
-------------------------------------------------------------------------------
*/}}
{{define "DefineGlobals"}}
  {{AssertType $ "API"}}

  {{range $d := $.Definitions}}
    {{Global $d.Name $d.Expression}}
  {{end}}
{{end}}


{{/*
-------------------------------------------------------------------------------
  Given a function, return "Global", "Instance", or "Device" depending on which
  dispatch table the function belongs to.
-------------------------------------------------------------------------------
*/}}
{{define "Vtbl#VkInstance"      }}Instance{{end}}
{{define "Vtbl#VkPhysicalDevice"}}Instance{{end}}
{{define "Vtbl#VkDevice"        }}Device{{end}}
{{define "Vtbl#VkQueue"         }}Device{{end}}
{{define "Vtbl#VkCommandBuffer" }}Device{{end}}
{{define "Vtbl_Default"         }}Global{{end}}
{{define "Vtbl"}}
  {{AssertType $ "Function"}}

  {{if gt (len $.CallParameters) 0}}
    {{Node "Vtbl" (index $.CallParameters 0)}}
  {{else}}Global
  {{end}}
{{end}}

vulkan/api/vulkan.api

deleted100644 → 0
+0 −12163

File deleted.

Preview size limit exceeded, changes collapsed.

+210 −210

File changed.

Preview size limit exceeded, changes collapsed.

Loading