Home | History | Annotate | Download | only in templates
      1 {{Include "vulkan_common.tmpl"}}
      2 {{if not (Global "AsciiDocPath")}}{{Global "AsciiDocPath" "../../doc/specs/vulkan/"}}{{end}}
      3 {{$ | Macro "AsciiDoc.Main"}}
      4 
      5 
      6 {{/*
      7 -------------------------------------------------------------------------------
      8   AsciiDoc generation main entry point.
      9 -------------------------------------------------------------------------------
     10 */}}
     11 {{define "AsciiDoc.Main"}}
     12   {{$docPath := Global "AsciiDocPath"}}
     13 
     14   {{/* Generate AsciiDoc files for API enums and bitfields (flags). */}}
     15   {{range $e := $.Enums}}
     16     {{if not $e.IsBitfield}}
     17       {{$filename := print $docPath "enums/" (Macro "EnumName" $e) ".txt"}}
     18       {{Macro "AsciiDoc.Write" "Code" (Macro "AsciiDoc.Enum" $e) "File" $filename}}
     19     {{else}}
     20       {{$filename := print $docPath "flags/" (Macro "EnumName" $e) ".txt"}}
     21       {{Macro "AsciiDoc.Write" "Code" (Macro "AsciiDoc.Flag" $e) "File" $filename}}
     22     {{end}}
     23   {{end}}
     24 
     25   {{/* Generate AsciiDoc files for API commands (protos). */}}
     26   {{range $f := (AllCommands $)}}
     27     {{if not (GetAnnotation $f "pfn")}}
     28       {{$filename := print $docPath "protos/" $f.Name ".txt"}}
     29       {{Macro "AsciiDoc.Write" "Code" (Macro "AsciiDoc.Proto" $f) "File" $filename}}
     30     {{end}}
     31   {{end}}
     32 
     33   {{/* Generate AsciiDoc files for API structs. */}}
     34   {{range $c := $.Classes}}
     35     {{if not (GetAnnotation $c "internal")}}
     36       {{$filename := print $docPath "structs/" $c.Name ".txt"}}
     37       {{Macro "AsciiDoc.Write" "Code" (Macro "AsciiDoc.Struct" $c) "File" $filename}}
     38     {{end}}
     39   {{end}}
     40 {{end}}
     41 
     42 
     43 {{/*
     44 -------------------------------------------------------------------------------
     45   Emits the AsciiDoc contents for the specified API enum.
     46 -------------------------------------------------------------------------------
     47 */}}
     48 {{define "AsciiDoc.Enum"}}
     49   {{AssertType $ "Enum"}}
     50 
     51   {{Macro "Docs" $.Docs}}
     52   typedef enum {
     53     {{range $i, $e := $.Entries}}
     54       {{Macro "EnumEntry" $e}} = {{AsSigned $e.Value}}, {{Macro "Docs" $e.Docs}}
     55     {{end}}
     56   
     57     {{$name := Macro "EnumName" $ | TrimRight "ABCDEFGHIJKLMNOQRSTUVWXYZ" | SplitPascalCase | Upper | JoinWith "_"}}
     58     {{$first := Macro "EnumFirstEntry" $}}
     59     {{$last  := Macro "EnumLastEntry" $}}
     60     {{$name}}_BEGIN_RANGE = {{$first}},
     61     {{$name}}_END_RANGE = {{$last}},
     62     {{$name}}_NUM = ({{$last}} - {{$first}} + 1),
     63     {{$name}}_MAX_ENUM = 0x7FFFFFFF
     64   } {{Macro "EnumName" $}};
     65 {{end}}
     66 
     67 
     68 {{/*
     69 -------------------------------------------------------------------------------
     70   Emits the AsciiDoc contents for the specified API bitfield.
     71 -------------------------------------------------------------------------------
     72 */}}
     73 {{define "AsciiDoc.Flag"}}
     74   {{AssertType $ "Enum"}}
     75 
     76   {{Macro "Docs" $.Docs}}
     77   typedef VkFlags {{Macro "EnumName" $}};
     78   {{if $.Entries}}
     79   typedef enum {
     80   {{range $e := $.Entries}}
     81     {{Macro "BitfieldEntryName" $e}} = {{printf "%#.8x" $e.Value}}, {{Macro "Docs" $e.Docs}}
     82   {{end}}
     83   } {{Macro "EnumName" $ | TrimRight "s"}}Bits;
     84   {{end}}
     85 {{end}}
     86 
     87 
     88 
     89 {{/*
     90 -------------------------------------------------------------------------------
     91   Emits the AsciiDoc contents for the specified API class.
     92 -------------------------------------------------------------------------------
     93 */}}
     94 {{define "AsciiDoc.Struct"}}
     95   {{AssertType $ "Class"}}
     96 
     97   {{Macro "Docs" $.Docs}}
     98   typedef {{if GetAnnotation $ "union"}}union{{else}}struct{{end}} {
     99     {{range $f := $.Fields}}
    100       {{Node "Type" $f}} {{$f.Name}}{{Macro "ArrayPostfix" (TypeOf $f)}}; {{Macro "Docs" $f.Docs}}
    101     {{end}}
    102   } {{Macro "StructName" $}};
    103 {{end}}
    104 
    105 
    106 {{/*
    107 -------------------------------------------------------------------------------
    108   Emits the AsciiDoc contents for the specified API function.
    109 -------------------------------------------------------------------------------
    110 */}}
    111 {{define "AsciiDoc.Proto"}}
    112   {{AssertType $ "Function"}}
    113 
    114   {{Macro "Docs" $.Docs}}
    115   {{Node "Type" $.Return}} VKAPI {{Macro "FunctionName" $}}({{Macro "Parameters" $}});
    116 {{end}}
    117 
    118 
    119 {{/*
    120 -------------------------------------------------------------------------------
    121   Wraps the specified Code in AsciiDoc source tags then writes to the specified File.
    122 -------------------------------------------------------------------------------
    123 */}}
    124 {{define "AsciiDoc.Write"}}
    125   {{AssertType $.Code "string"}}
    126   {{AssertType $.File "string"}}
    127 
    128   {{$code := $.Code | Format (Global "clang-format")}}
    129   {{JoinWith "\n" (Macro "AsciiDoc.Header") $code (Macro "AsciiDoc.Footer") ""| Write $.File}}
    130 {{end}}
    131 
    132 
    133 {{/*
    134 -------------------------------------------------------------------------------
    135   Emits an AsciiDoc source header.
    136 -------------------------------------------------------------------------------
    137 */}}
    138 {{define "AsciiDoc.Header"}}
    139 [source,{basebackend@docbook:c++:cpp}]
    140 ------------------------------------------------------------------------------
    141 {{end}}
    142 
    143 
    144 {{/*
    145 -------------------------------------------------------------------------------
    146   Emits an AsciiDoc source footer.
    147 -------------------------------------------------------------------------------
    148 */}}
    149 {{define "AsciiDoc.Footer"}}
    150 ------------------------------------------------------------------------------
    151 {{end}}
    152