mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-20 20:20:18 +01:00
util/format: expose generated format packing functions through a header
Some of the generated functions can be useful without going through the format table (filling border color struct in turnip). By not calling these functions through the format table, we should eventually be able to garbage collect the unused packing functions, and also allows LTOs to happen. Signed-off-by: Jonathan Marek <jonathan@marek.ca> Reviewed-by: Eric Anholt <eric@anholt.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6093>
This commit is contained in:
parent
a322924d9c
commit
84ed2d0980
5 changed files with 51 additions and 16 deletions
|
|
@ -130,7 +130,8 @@ MESA_UTIL_FILES := \
|
|||
|
||||
MESA_UTIL_GENERATED_FILES = \
|
||||
format_srgb.c \
|
||||
format/u_format_table.c
|
||||
format/u_format_table.c \
|
||||
format/u_format_pack.h
|
||||
|
||||
XMLCONFIG_FILES := \
|
||||
xmlconfig.c \
|
||||
|
|
|
|||
|
|
@ -26,6 +26,18 @@ env.CodeGenerate(
|
|||
command = python_cmd + ' $SCRIPT > $TARGET'
|
||||
)
|
||||
|
||||
env.CodeGenerate(
|
||||
target = 'format/u_format_pack.h',
|
||||
script = 'format/u_format_table.py',
|
||||
source = ['format/u_format.csv'],
|
||||
command = python_cmd + ' $SCRIPT $SOURCE --header > $TARGET'
|
||||
)
|
||||
|
||||
env.Depends('format/u_format_pack.h', [
|
||||
'format/u_format_parse.py',
|
||||
'format/u_format_pack.py',
|
||||
])
|
||||
|
||||
env.CodeGenerate(
|
||||
target = 'format/u_format_table.c',
|
||||
script = 'format/u_format_table.py',
|
||||
|
|
|
|||
|
|
@ -31,6 +31,15 @@ files_mesa_format = [
|
|||
'u_format_zs.c',
|
||||
]
|
||||
|
||||
u_format_pack_h = custom_target(
|
||||
'u_format_pack.h',
|
||||
input : ['u_format_table.py', 'u_format.csv'],
|
||||
output : 'u_format_pack.h',
|
||||
command : [prog_python, '@INPUT@', '--header'],
|
||||
depend_files : files('u_format_pack.py', 'u_format_parse.py'),
|
||||
capture : true,
|
||||
)
|
||||
|
||||
u_format_table_c = custom_target(
|
||||
'u_format_table.c',
|
||||
input : ['u_format_table.py', 'u_format.csv'],
|
||||
|
|
@ -42,7 +51,7 @@ u_format_table_c = custom_target(
|
|||
|
||||
libmesa_format = static_library(
|
||||
'mesa_format',
|
||||
[files_mesa_format, u_format_table_c],
|
||||
[files_mesa_format, u_format_table_c, u_format_pack_h],
|
||||
include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
|
||||
dependencies : dep_m,
|
||||
c_args : [c_msvc_compat_args],
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@ if sys.version_info < (3, 0):
|
|||
else:
|
||||
integer_types = (int, )
|
||||
|
||||
|
||||
def inv_swizzles(swizzles):
|
||||
'''Return an array[4] of inverse swizzle terms'''
|
||||
'''Only pick the first matching value to avoid l8 getting blue and i8 getting alpha'''
|
||||
|
|
@ -658,9 +657,11 @@ def generate_format_pack(format, src_channel, src_native_type, src_suffix):
|
|||
|
||||
name = format.short_name()
|
||||
|
||||
print('static inline void')
|
||||
print('void')
|
||||
print('util_format_%s_pack_%s(uint8_t *dst_row, unsigned dst_stride, const %s *src_row, unsigned src_stride, unsigned width, unsigned height)' % (name, src_suffix, src_native_type))
|
||||
print('{')
|
||||
|
||||
print('void util_format_%s_pack_%s(uint8_t *dst_row, unsigned dst_stride, const %s *src_row, unsigned src_stride, unsigned width, unsigned height);' % (name, src_suffix, src_native_type), file=sys.stdout2)
|
||||
|
||||
if is_format_supported(format):
|
||||
print(' unsigned x, y;')
|
||||
|
|
@ -712,6 +713,7 @@ def generate(formats):
|
|||
print('#include "util/format_srgb.h"')
|
||||
print('#include "u_format_yuv.h"')
|
||||
print('#include "u_format_zs.h"')
|
||||
print('#include "u_format_pack.h"')
|
||||
print()
|
||||
|
||||
for format in formats:
|
||||
|
|
@ -761,4 +763,3 @@ def generate(formats):
|
|||
|
||||
generate_format_unpack(format, channel, native_type, suffix)
|
||||
generate_format_pack(format, channel, native_type, suffix)
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ CopyRight = '''
|
|||
'''
|
||||
|
||||
|
||||
import sys
|
||||
import sys, os
|
||||
|
||||
from u_format_parse import *
|
||||
import u_format_pack
|
||||
|
|
@ -112,19 +112,24 @@ def has_access(format):
|
|||
return False
|
||||
return True
|
||||
|
||||
def write_format_table(formats):
|
||||
print('/* This file is autogenerated by u_format_table.py from u_format.csv. Do not edit directly. */')
|
||||
print()
|
||||
def write_format_table_header(file):
|
||||
print('/* This file is autogenerated by u_format_table.py from u_format.csv. Do not edit directly. */', file=file)
|
||||
print(file=file)
|
||||
# This will print the copyright message on the top of this file
|
||||
print(CopyRight.strip())
|
||||
print()
|
||||
print('#include "u_format.h"')
|
||||
print(CopyRight.strip(), file=file)
|
||||
print(file=file)
|
||||
print('#include "util/format/u_format.h"', file=file)
|
||||
|
||||
def write_format_table(formats):
|
||||
write_format_table_header(sys.stdout)
|
||||
print('#include "u_format_bptc.h"')
|
||||
print('#include "u_format_s3tc.h"')
|
||||
print('#include "u_format_rgtc.h"')
|
||||
print('#include "u_format_latc.h"')
|
||||
print('#include "u_format_etc.h"')
|
||||
print()
|
||||
|
||||
write_format_table_header(sys.stdout2)
|
||||
|
||||
u_format_pack.generate(formats)
|
||||
|
||||
|
|
@ -261,12 +266,19 @@ def write_format_table(formats):
|
|||
generate_table_getter("unpack_")
|
||||
|
||||
def main():
|
||||
|
||||
formats = []
|
||||
for arg in sys.argv[1:]:
|
||||
formats.extend(parse(arg))
|
||||
write_format_table(formats)
|
||||
|
||||
sys.stdout2 = open(os.devnull, "w")
|
||||
|
||||
for arg in sys.argv[1:]:
|
||||
if arg == '--header':
|
||||
sys.stdout2 = sys.stdout
|
||||
sys.stdout = open(os.devnull, "w")
|
||||
continue
|
||||
|
||||
formats.extend(parse(arg))
|
||||
|
||||
write_format_table(formats)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue