Commit 974981c4 authored by Eric Anholt's avatar Eric Anholt

gallium/drm: Make the pipe loader handle the driconf merging.

We can pretty easily handle merging the driver's driconf with the common
driverconf right there, rather than pushing that to each driver.

Part-of: <!6751>
parent 87392385
Pipeline #205373 waiting for manual action with stages
......@@ -52,9 +52,7 @@ static int (*backends[])(struct pipe_loader_device **, int) = {
};
const char gallium_driinfo_xml[] =
DRI_CONF_BEGIN
#include "driinfo_gallium.h"
DRI_CONF_END
;
int
......@@ -93,26 +91,39 @@ pipe_loader_load_options(struct pipe_loader_device *dev)
if (dev->option_info.info)
return;
const char *xml_options = dev->ops->get_driconf_xml(dev);
if (!xml_options)
xml_options = gallium_driinfo_xml;
driParseOptionInfo(&dev->option_info, xml_options);
driParseConfigFiles(&dev->option_cache, &dev->option_info, 0,
dev->driver_name, NULL, NULL, 0, NULL, 0);
const char *driver_xml = dev->ops->get_driconf_xml(dev);
char *xml_options;
int ret = asprintf(&xml_options, "%s%s%s%s",
DRI_CONF_BEGIN,
gallium_driinfo_xml,
driver_xml ? driver_xml : "",
DRI_CONF_END);
if (ret >= 0) {
driParseOptionInfo(&dev->option_info, xml_options);
driParseConfigFiles(&dev->option_cache, &dev->option_info, 0,
dev->driver_name, NULL, NULL, 0, NULL, 0);
free(xml_options);
}
}
char *
pipe_loader_get_driinfo_xml(const char *driver_name)
{
#ifdef HAVE_LIBDRM
char *xml = pipe_loader_drm_get_driinfo_xml(driver_name);
char *driver_xml = pipe_loader_drm_get_driinfo_xml(driver_name);
#else
char *xml = NULL;
char *driver_xml = NULL;
#endif
if (!xml)
xml = strdup(gallium_driinfo_xml);
char *xml;
int ret = asprintf(&xml, "%s%s%s%s",
DRI_CONF_BEGIN,
gallium_driinfo_xml,
driver_xml ? driver_xml : "",
DRI_CONF_END);
if (ret < 0)
xml = NULL;
return xml;
}
......
......@@ -93,7 +93,7 @@ pipe_iris_create_screen(int fd, const struct pipe_screen_config *config)
}
const char *iris_driconf_xml =
#include "iris/iris_driinfo.h"
#include "iris/driinfo_iris.h"
;
DRM_DRIVER_DESCRIPTOR(iris, &iris_driconf_xml)
......@@ -120,7 +120,7 @@ DRM_DRIVER_DESCRIPTOR_STUB(nouveau)
#if defined(GALLIUM_VC4) || defined(GALLIUM_V3D)
const char *v3d_driconf_xml =
#include "v3d/v3d_driinfo.h"
#include "v3d/driinfo_v3d.h"
;
#endif
......@@ -195,7 +195,7 @@ pipe_radeonsi_create_screen(int fd, const struct pipe_screen_config *config)
}
const char *radeonsi_driconf_xml =
#include "radeonsi/si_driinfo.h"
#include "radeonsi/driinfo_radeonsi.h"
;
DRM_DRIVER_DESCRIPTOR(radeonsi, &radeonsi_driconf_xml)
......@@ -257,7 +257,7 @@ pipe_virtio_gpu_create_screen(int fd, const struct pipe_screen_config *config)
}
const char *virgl_driconf_xml =
#include "virgl/virgl_driinfo.h"
#include "virgl/virgl_driinfo.h.in"
;
DRM_DRIVER_DESCRIPTOR(virtio_gpu, &virgl_driconf_xml)
......
......@@ -151,17 +151,6 @@ intermediates := $(call local-generated-sources-dir)
LOCAL_GENERATED_SOURCES := $(addprefix $(intermediates)/iris/,$(GENERATED_SOURCES))
GEN_DRIINFO_INPUTS := \
$(MESA_TOP)/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h \
$(LOCAL_PATH)/driinfo_iris.h
MERGE_DRIINFO := $(MESA_TOP)/src/util/merge_driinfo.py
$(intermediates)/iris/iris_driinfo.h: $(MERGE_DRIINFO) $(GEN_DRIINFO_INPUTS)
@mkdir -p $(dir $@)
@echo "Gen Header: $(PRIVATE_MODULE) <= $(notdir $(@))"
$(hide) $(MESA_PYTHON2) $(MERGE_DRIINFO) $(GEN_DRIINFO_INPUTS) > $@ || ($(RM) $@; false)
LOCAL_EXPORT_C_INCLUDE_DIRS := $(intermediates)
LOCAL_SRC_FILES := \
......
......@@ -7,11 +7,7 @@ DRI_CONF_SECTION_DEBUG
DRI_CONF_SECTION_END
DRI_CONF_SECTION_PERFORMANCE
//= BEGIN VERBATIM
DRI_CONF_OPT_BEGIN_V(bo_reuse, enum, 1, "0:1")
DRI_CONF_DESC("Buffer object reuse")
DRI_CONF_OPT_END
//= END VERBATIM
DRI_CONF_SECTION_END
......@@ -55,17 +55,6 @@ files_libiris = files(
'iris_disk_cache.c',
)
iris_driinfo_h = custom_target(
'iris_driinfo.h',
input : files(
'../../../util/merge_driinfo.py',
'../../auxiliary/pipe-loader/driinfo_gallium.h', 'driinfo_iris.h'
),
output : 'iris_driinfo.h',
command : [prog_python, '@INPUT@'],
capture : true,
)
iris_gen_libs = []
foreach v : ['80', '90', '100', '110', '120']
iris_gen_libs += static_library(
......@@ -83,7 +72,7 @@ endforeach
libiris = static_library(
'iris',
[files_libiris, gen_xml_pack, iris_driinfo_h],
[files_libiris, gen_xml_pack],
include_directories : [
inc_src, inc_include, inc_gallium, inc_gallium_aux, inc_intel,
inc_gallium_drivers,
......@@ -102,6 +91,5 @@ libiris = static_library(
driver_iris = declare_dependency(
compile_args : '-DGALLIUM_IRIS',
sources : iris_driinfo_h,
link_with : [libiris, libiriswinsys],
)
......@@ -55,17 +55,6 @@ intermediates := $(call local-generated-sources-dir)
LOCAL_GENERATED_SOURCES := $(MESA_GEN_NIR_H)
LOCAL_GENERATED_SOURCES += $(addprefix $(intermediates)/radeonsi/,$(GENERATED_SOURCES))
GEN_DRIINFO_INPUTS := \
$(MESA_TOP)/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h \
$(LOCAL_PATH)/driinfo_radeonsi.h
MERGE_DRIINFO := $(MESA_TOP)/src/util/merge_driinfo.py
$(intermediates)/radeonsi/si_driinfo.h: $(MERGE_DRIINFO) $(GEN_DRIINFO_INPUTS)
@mkdir -p $(dir $@)
@echo "Gen Header: $(PRIVATE_MODULE) <= $(notdir $(@))"
$(hide) $(MESA_PYTHON2) $(MERGE_DRIINFO) $(GEN_DRIINFO_INPUTS) > $@ || ($(RM) $@; false)
LOCAL_C_INCLUDES += $(intermediates)/radeonsi
LOCAL_EXPORT_C_INCLUDE_DIRS := $(intermediates)
......
......@@ -7,14 +7,10 @@ DRI_CONF_RADEONSI_ZERO_ALL_VRAM_ALLOCS("false")
DRI_CONF_SECTION_END
DRI_CONF_SECTION_DEBUG
//= BEGIN VERBATIM
#define OPT_BOOL(name, dflt, description) \
DRI_CONF_OPT_BEGIN_B(radeonsi_##name, #dflt) \
DRI_CONF_DESC(description) \
DRI_CONF_OPT_END
#include "radeonsi/si_debug_options.h"
//= END VERBATIM
DRI_CONF_SECTION_END
......@@ -94,20 +94,9 @@ files_libradeonsi = files(
'../radeon/radeon_winsys.h',
)
si_driinfo_h = custom_target(
'si_driinfo.h',
input : files(
'../../../util/merge_driinfo.py',
'../../auxiliary/pipe-loader/driinfo_gallium.h', 'driinfo_radeonsi.h'
),
output : 'si_driinfo.h',
command : [prog_python, '@INPUT@'],
capture : true,
)
libradeonsi = static_library(
'radeonsi',
[files_libradeonsi, si_driinfo_h, sid_tables_h],
[files_libradeonsi, sid_tables_h],
include_directories : [
inc_src, inc_include, inc_gallium, inc_gallium_aux, inc_amd_common, inc_amd_common_llvm,
inc_gallium_drivers,
......@@ -119,7 +108,6 @@ libradeonsi = static_library(
driver_radeonsi = declare_dependency(
compile_args : '-DGALLIUM_RADEONSI',
sources : si_driinfo_h,
link_with : [
libradeonsi, libradeonwinsys, libamdgpuwinsys, libamd_common, libamd_common_llvm, libgalliumvl
],
......
......@@ -47,16 +47,6 @@ files_per_version = files(
'v3dx_state.c',
)
v3d_driinfo_h = custom_target(
'v3d_driinfo.h',
input : files(
'../../../util/merge_driinfo.py',
'../../auxiliary/pipe-loader/driinfo_gallium.h', 'driinfo_v3d.h'
),
output : 'v3d_driinfo.h',
command : [prog_python, '@INPUT@'],
capture : true,
)
v3d_args = ['-DV3D_BUILD_NEON']
dep_v3dv3 = dependency('v3dv3', required: false)
......@@ -104,7 +94,6 @@ libv3d = static_library(
[
files_libv3d,
v3d_xml_pack,
v3d_driinfo_h
],
include_directories : [
inc_src, inc_include, inc_gallium, inc_gallium_aux, inc_broadcom,
......@@ -120,6 +109,5 @@ libv3d = static_library(
driver_v3d = declare_dependency(
compile_args : '-DGALLIUM_V3D',
link_with : [libv3d, libv3dwinsys, libbroadcom_cle, libbroadcom_v3d],
sources : v3d_driinfo_h,
dependencies : idep_nir,
)
......@@ -41,13 +41,6 @@ GEN_DRIINFO_INPUTS := \
$(MESA_TOP)/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h \
$(LOCAL_PATH)/virgl_driinfo.h.in
MERGE_DRIINFO := $(MESA_TOP)/src/util/merge_driinfo.py
$(intermediates)/virgl/virgl_driinfo.h: $(MERGE_DRIINFO) $(GEN_DRIINFO_INPUTS)
@mkdir -p $(dir $@)
@echo "Gen Header: $(PRIVATE_MODULE) <= $(notdir $(@))"
$(hide) $(MESA_PYTHON2) $(MERGE_DRIINFO) $(GEN_DRIINFO_INPUTS) > $@ || ($(RM) $@; false)
LOCAL_EXPORT_C_INCLUDE_DIRS := $(intermediates)
include $(GALLIUM_COMMON_MK)
......
......@@ -32,27 +32,15 @@ files_libvirgl = files(
'virgl_tgsi.c',
)
virgl_driinfo_h = custom_target(
'virgl_driinfo.h',
input : files(
'../../../util/merge_driinfo.py',
'../../auxiliary/pipe-loader/driinfo_gallium.h', 'virgl_driinfo.h.in'
),
output : 'virgl_driinfo.h',
command : [prog_python, '@INPUT@'],
capture : true,
)
libvirgl = static_library(
'virgl',
[ files_libvirgl, virgl_driinfo_h ],
[ files_libvirgl ],
gnu_symbol_visibility : 'hidden',
include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_virtio],
dependencies : dep_libdrm
)
driver_virgl = declare_dependency(
sources : virgl_driinfo_h,
compile_args : '-DGALLIUM_VIRGL',
link_with : [libvirgl, libvirgldrm, libvirglvtest],
)
......
......@@ -19,8 +19,9 @@ struct drm_driver_descriptor
const char *driver_name;
/**
* Pointer to the XML string describing driver-specific driconf options.
* Use DRI_CONF_* macros to create the string.
* Pointer to the XML string fragment describing driver-specific driconf
* options. Use DRI_CONF_* macros to create the string, do not wrap in
* DRI_CONF_BEGIN/END.
*/
const char **driconf_xml;
......
#
# Copyright 2017 Advanced Micro Devices, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# on the rights to use, copy, modify, merge, publish, distribute, sub
# license, and/or sell copies of the Software, and to permit persons to whom
# the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice (including the next
# paragraph) shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS 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 NON-INFRINGEMENT. IN NO EVENT SHALL
# THE AUTHOR(S) AND/OR THEIR SUPPLIERS 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 SOFTWARE OR THE
# USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
usage: merge_driinfo.py <list of input files>
Generates a source file which contains the DRI_CONF_xxx macros for generating
the driinfo XML that describes the available DriConf options for a driver and
its supported gallium frontends, based on the merged information from the input
files.
"""
from __future__ import print_function
import mako.template
import re
import sys
# Some regexps used during input parsing
RE_section_begin = re.compile(r'DRI_CONF_SECTION_(.*)')
RE_option = re.compile(r'DRI_CONF_(.*)\((.*)\)')
class Option(object):
"""
Represent a config option as:
* name: the xxx part of the DRI_CONF_xxx macro
* defaults: the defaults parameters that are passed into the macro
"""
def __init__(self, name, defaults):
self.name = name
self.defaults = defaults
class Verbatim(object):
"""
Represent a chunk of code that is copied into the result file verbatim.
"""
def __init__(self):
self.string = ''
class Section(object):
"""
Represent a config section description as:
* name: the xxx part of the DRI_CONF_SECTION_xxx macro
* options: list of options
"""
def __init__(self, name):
self.name = name
self.options = []
def parse_inputs(input_filenames):
success = True
sections_lists = []
for input_filename in input_filenames:
with open(input_filename, 'r') as infile:
sections = []
sections_lists.append(sections)
section = None
linenum = 0
verbatim = None
for line in infile:
linenum += 1
if line.startswith('//= BEGIN VERBATIM'):
if verbatim is not None:
print('{}:{}: nested verbatim'
.format(input_filename, linenum))
success = False
continue
verbatim = Verbatim()
if verbatim is not None:
verbatim.string += line
if line.startswith('//= END VERBATIM'):
if section is None:
sections.append(verbatim)
else:
section.options.append(verbatim)
verbatim = None
continue
line = line.strip()
if not line:
continue
if line.startswith('//'):
continue
if line == 'DRI_CONF_SECTION_END':
if section is None:
print('{}:{}: no open section'
.format(input_filename, linenum))
success = False
continue
section = None
continue
m = RE_section_begin.match(line)
if m:
if section is not None:
print('{}:{}: nested sections are not supported'
.format(input_filename, linenum))
success = False
continue
if sections is None:
print('{}:{}: missing DRIINFO line'
.format(input_filename, linenum))
success = False
break # parsing the rest really makes no sense
section = Section(m.group(1))
sections.append(section)
continue
m = RE_option.match(line)
if m:
if section is None:
print('{}:{}: no open section'
.format(input_filename, linenum))
success = False
break
section.options.append(Option(m.group(1), m.group(2)))
continue
print('{}:{}: do not understand this line'
.format(input_filename, linenum))
success = False
if section is not None:
print('{}:end-of-file: missing end of section'
.format(input_filename))
success = False
if success:
return sections_lists
return None
def merge_sections(section_list):
"""
section_list: list of Section objects to be merged, all of the same name
Return a merged Section object (everything is deeply copied)
"""
merged_section = Section(section_list[0].name)
for section in section_list:
assert section.name == merged_section.name
for orig_option in section.options:
if isinstance(orig_option, Option):
for merged_option in merged_section.options:
if not isinstance(merged_option, Option):
continue
if orig_option.name == merged_option.name:
merged_option.defaults = orig_option.defaults
break
else:
merged_section.options.append(Option(orig_option.name, orig_option.defaults))
else:
merged_section.options.append(orig_option)
return merged_section
def merge_sections_lists(sections_lists):
"""
sections_lists: list of lists of Section objects to be merged
Return a merged list of merged Section objects; everything is deeply copied.
Default values for options in later lists override earlier default values.
"""
merged_sections = []
for idx,sections in enumerate(sections_lists):
for base_section in sections:
if not isinstance(base_section, Section):
merged_sections.append(base_section)
continue
original_sections = [base_section]
for next_sections in sections_lists[idx+1:]:
for j,section in enumerate(next_sections):
if section.name == base_section.name:
original_sections.append(section)
del next_sections[j]
break
merged_section = merge_sections(original_sections)
merged_sections.append(merged_section)
return merged_sections
def main(input_filenames):
sections_lists = parse_inputs(input_filenames)
if sections_lists is None:
return False
merged_sections_list = merge_sections_lists(sections_lists)
driinfo_h_template = mako.template.Template("""\
// DO NOT EDIT - this file is automatically generated by merge_driinfo.py
/*
Use as:
#include "driconf.h"
static const char driinfo_xml[] =
#include "this_file"
;
*/
DRI_CONF_BEGIN
% for section in sections:
% if isinstance(section, Section):
DRI_CONF_SECTION_${section.name}
% for option in section.options:
% if isinstance(option, Option):
DRI_CONF_${option.name}(${option.defaults})
% else:
${option.string}
% endif
% endfor
DRI_CONF_SECTION_END
% else:
${section.string}
% endif
% endfor
DRI_CONF_END""")
print(driinfo_h_template.render(sections=merged_sections_list, Section=Section, Option=Option))
return True
if __name__ == '__main__':
if len(sys.argv) <= 1:
print('Missing arguments')
sys.exit(1)
if not main(sys.argv[1:]):
sys.exit(1)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment