From c1ef9536726c41bf94fed099982735d2a2a30cb7 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 19 Jan 2021 01:24:05 +0300 Subject: [PATCH 1/3] waf: add glslc module --- ref_vk/wscript | 12 ++++++++++++ scripts/waifulib/glslc.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 scripts/waifulib/glslc.py diff --git a/ref_vk/wscript b/ref_vk/wscript index 74466d99..ced96abc 100644 --- a/ref_vk/wscript +++ b/ref_vk/wscript @@ -15,12 +15,16 @@ def configure(conf): if conf.options.DEDICATED: return + conf.load('glslc') conf.define('REF_DLL', 1) + # conf.env.GLSLCFLAGS.append_unique(['-O']) + def build(bld): libs = [ 'public', 'M' ] source = bld.path.ant_glob(['*.c']) + glsl_source = bld.path.ant_glob(['shaders/*.vert', 'shaders/*.frag']) includes = ['.', '../engine', @@ -42,3 +46,11 @@ def build(bld): subsystem = bld.env.MSVC_SUBSYSTEM ) + bld( + source = glsl_source, + features = 'glsl', + # includes = 'shaders/', # write your includes here + # defines = 'TEST', # write your C preprocessor defines here + install_path = '${PREFIX}/lib/xash3d/valve' # TEMPORARY!!!! + ) + diff --git a/scripts/waifulib/glslc.py b/scripts/waifulib/glslc.py new file mode 100644 index 00000000..61f8558f --- /dev/null +++ b/scripts/waifulib/glslc.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python +# encoding: utf-8 +# a1batross, 2020 + +import os +from waflib import * +from waflib.Tools import c_preproc + +def options(opt): + pass + +def configure(conf): + conf.find_program('glslc') + + self.env.GLSLCFLAGS = [] + +class glsl(Task.Task): + color = 'BLUE' + run_str = '${GLSLC} ${GLSLCFLAGS} ${GLSLCINCLUDES} ${GLSLCDEFINES} -o ${TGT} ${SRC}' + vars = ['GLSLC', 'GLSLCFLAGS', 'GLSLCINCLUDES', 'GLSLCDEFINES'] + +@TaskGen.extension('.vert', '.frag') +def process_glsl_source(self, src): + includes = self.to_list(getattr(self, 'includes', [])) + defines = self.to_list(getattr(self, 'defines', [])) + sources = self.to_list(getattr(self, 'source', [])) + + self.env.GLSLCINCLUDES = ['-I' + s for s in includes] + self.env.GLSLCDEFINES = ['-D' + s for s in defines] + + tsk = self.create_task('glsl', src, src.parent.find_or_declare('%s.spv' % src.name)) + + inst_to = getattr(self, 'install_path', None) + if inst_to: + self.add_install_files(install_to=inst_to, + install_from=tsk.outputs[:], chmod=Utils.O755, task=tsk) From 8ee87d441c29398c5b1d46c3399167be257272d2 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sun, 7 Feb 2021 03:10:01 +0300 Subject: [PATCH 2/3] waf: glslc: remove useless shebang --- scripts/waifulib/glslc.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/waifulib/glslc.py b/scripts/waifulib/glslc.py index 61f8558f..679f55d5 100644 --- a/scripts/waifulib/glslc.py +++ b/scripts/waifulib/glslc.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # encoding: utf-8 # a1batross, 2020 From 074e4fd540a32e41b7047a8ca6eaf56076c82698 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Wed, 10 Feb 2021 02:48:30 +0300 Subject: [PATCH 3/3] glslc: rework tool, support dependency scan, preliminary work on making tool dependless from compiler(like ccroot) --- ref_vk/wscript | 2 +- scripts/waifulib/glslc.py | 41 ++++++++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/ref_vk/wscript b/ref_vk/wscript index ced96abc..0122dab3 100644 --- a/ref_vk/wscript +++ b/ref_vk/wscript @@ -51,6 +51,6 @@ def build(bld): features = 'glsl', # includes = 'shaders/', # write your includes here # defines = 'TEST', # write your C preprocessor defines here - install_path = '${PREFIX}/lib/xash3d/valve' # TEMPORARY!!!! + install_path = '${LIBDIR}/valve' # TEMPORARY!!!! ) diff --git a/scripts/waifulib/glslc.py b/scripts/waifulib/glslc.py index 679f55d5..0df54771 100644 --- a/scripts/waifulib/glslc.py +++ b/scripts/waifulib/glslc.py @@ -3,29 +3,42 @@ import os from waflib import * -from waflib.Tools import c_preproc - -def options(opt): - pass +from waflib.Tools import c_preproc, ccroot def configure(conf): conf.find_program('glslc') - self.env.GLSLCFLAGS = [] + conf.add_os_flags('GLSLCPPFLAGS', dup=False) + conf.add_os_flags('GLSLCFLAGS', dup=False) + + v = conf.env + + v.GLSLCINCLUDES = [] + v.GLSLCDEFINES = [] + + v.GLSLCPPPATH_ST = '-I%s' + v.GLSLDEFINES_ST = '-D%s' + v.GLSLC_SRC_F = [] + v.GLSLC_TGT_F = ['-c', '-o'] class glsl(Task.Task): - color = 'BLUE' - run_str = '${GLSLC} ${GLSLCFLAGS} ${GLSLCINCLUDES} ${GLSLCDEFINES} -o ${TGT} ${SRC}' - vars = ['GLSLC', 'GLSLCFLAGS', 'GLSLCINCLUDES', 'GLSLCDEFINES'] + color = 'PINK' + run_str = '${GLSLC} ${GLSLCFLAGS} ${GLSLCPPPATH_ST:INCPATHS} ${GLSLDEFINES_ST:GLSLCDEFINES} ${GLSLC_SRC_F}${SRC} ${GLSLC_TGT_F}${TGT[0].abspath()} ${GLSLCPPFLAGS}' + vars = ['GLSLCDEPS'] # unused variable to depend on, just in case + ext_in = ['.h'] # set the build order easily by using ext_out=['.h'] + scan = c_preproc.scan + + def keyword(self): + return 'Compiling shader' @TaskGen.extension('.vert', '.frag') def process_glsl_source(self, src): - includes = self.to_list(getattr(self, 'includes', [])) - defines = self.to_list(getattr(self, 'defines', [])) - sources = self.to_list(getattr(self, 'source', [])) - - self.env.GLSLCINCLUDES = ['-I' + s for s in includes] - self.env.GLSLCDEFINES = ['-D' + s for s in defines] + # see ccroot.apply_incpaths + lst = self.to_incnodes(self.to_list(getattr(self, 'includes', [])) + self.env.GLSLCINCLUDES) + self.includes_nodes = lst + cwd = self.get_cwd() + self.env.INCPATHS = [x.path_from(cwd) for x in lst] + self.env.append_unique('GLSLCDEFINES', self.to_list(getattr(self, 'defines', []))) tsk = self.create_task('glsl', src, src.parent.find_or_declare('%s.spv' % src.name))