| 1 |
# formatting.py |
| 2 |
# Sphinx extension providing formatting for Gallium-specific data |
| 3 |
# (c) Corbin Simpson 2010 |
| 4 |
# Public domain to the extent permitted; contact author for special licensing |
| 5 |
|
| 6 |
import docutils.nodes |
| 7 |
import sphinx.addnodes |
| 8 |
|
| 9 |
from sphinx.util.nodes import split_explicit_title |
| 10 |
from docutils import nodes, utils |
| 11 |
|
| 12 |
def parse_opcode(env, sig, signode): |
| 13 |
opcode, desc = sig.split("-", 1) |
| 14 |
opcode = opcode.strip().upper() |
| 15 |
desc = " (%s)" % desc.strip() |
| 16 |
signode += sphinx.addnodes.desc_name(opcode, opcode) |
| 17 |
signode += sphinx.addnodes.desc_annotation(desc, desc) |
| 18 |
return opcode |
| 19 |
|
| 20 |
|
| 21 |
def ext_role(name, rawtext, text, lineno, inliner, options={}, content=[]): |
| 22 |
text = utils.unescape(text) |
| 23 |
has_explicit_title, title, ext = split_explicit_title(text) |
| 24 |
|
| 25 |
parts = ext.split('_', 2) |
| 26 |
if parts[0] == 'VK': |
| 27 |
full_url = f'https://docs.vulkan.org/refpages/latest/refpages/source/{ext}.html' |
| 28 |
elif parts[0] == 'GL': |
| 29 |
full_url = f'https://registry.khronos.org/OpenGL/extensions/{parts[1]}/{parts[1]}_{parts[2]}.txt' |
| 30 |
else: |
| 31 |
raise Exception(f'Unexpected API: {parts[0]}') |
| 32 |
|
| 33 |
pnode = nodes.reference(title, title, internal=False, refuri=full_url) |
| 34 |
return [pnode], [] |
| 35 |
|
| 36 |
def vkfeat_role(name, rawtext, text, lineno, inliner, options={}, content=[]): |
| 37 |
text = utils.unescape(text) |
| 38 |
has_explicit_title, title, ext = split_explicit_title(text) |
| 39 |
|
| 40 |
full_url = f'https://docs.vulkan.org/spec/latest/chapters/features.html#features-{ext}' |
| 41 |
|
| 42 |
pnode = nodes.reference(title, title, internal=False, refuri=full_url) |
| 43 |
return [pnode], [] |
| 44 |
|
| 45 |
def setup(app): |
| 46 |
app.add_object_type("opcode", "opcode", "%s (TGSI opcode)", |
| 47 |
parse_opcode) |
| 48 |
app.add_role('ext', ext_role) |
| 49 |
app.add_role('vk-feat', vkfeat_role) |