From c9870879c61b583f82bb103bbb042cb40d13bf76 Mon Sep 17 00:00:00 2001 From: tdesveaux Date: Sat, 7 Apr 2018 19:15:45 +0200 Subject: [PATCH 1/3] VStudio: Implement FxCompile block for hlsl shader compilation --- modules/vstudio/_preload.lua | 96 +++++++++++++++++ modules/vstudio/vs2010_vcxproj.lua | 165 +++++++++++++++++++++++++++-- src/base/path.lua | 9 ++ 3 files changed, 262 insertions(+), 8 deletions(-) diff --git a/modules/vstudio/_preload.lua b/modules/vstudio/_preload.lua index 28301f5b..99f91619 100644 --- a/modules/vstudio/_preload.lua +++ b/modules/vstudio/_preload.lua @@ -21,6 +21,102 @@ include("vs2015.lua") include("vs2017.lua") + -- Initialize Specific API + + p.api.register { + name = "shaderoptions", + scope = "config", + kind = "list:string", + tokens = true, + pathVars = true, + } + + p.api.register { + name = "shaderdefines", + scope = "config", + kind = "list:string", + tokens = true, + } + + p.api.register { + name = "shadertype", + scope = "config", + kind = "string", + allowed = { + "Effect", + "Vertex", + "Pixel", + "Geometry", + "Hull", + "Domain", + "Compute", + "Texture", + "RootSignature", + } + } + + p.api.register { + name = "shadermodel", + scope = "config", + kind = "string", + allowed = { + "2.0", + "3.0", + "4.0_level_9_1", + "4.0_level_9_3", + "4.0", + "4.1", + "5.0", + } + } + + p.api.register { + name = "shaderentry", + scope = "config", + kind = "string", + tokens = true, + } + + p.api.register { + name = "shadervariablename", + scope = "config", + kind = "string", + tokens = true, + } + + p.api.register { + name = "shaderheaderfileoutput", + scope = "config", + kind = "string", + tokens = true, + } + + p.api.register { + name = "shaderobjectfileoutput", + scope = "config", + kind = "string", + tokens = true, + } + + p.api.register { + name = "shaderassembler", + scope = "config", + kind = "string", + allowed = { + "NoListing", + "AssemblyCode", + "AssemblyCodeAndHex", + } + } + + p.api.register { + name = "shaderassembleroutput", + scope = "config", + kind = "string", + tokens = true, + } + + -- -- Decide when the full module should be loaded. -- diff --git a/modules/vstudio/vs2010_vcxproj.lua b/modules/vstudio/vs2010_vcxproj.lua index ce0f79e4..6909fac8 100644 --- a/modules/vstudio/vs2010_vcxproj.lua +++ b/modules/vstudio/vs2010_vcxproj.lua @@ -274,6 +274,7 @@ else return { m.clCompile, + m.fxCompile, m.resourceCompile, m.linker, m.manifest, @@ -363,6 +364,42 @@ end +-- +-- Write the settings block. +-- + + m.elements.fxCompile = function(cfg) + return { + m.fxCompilePreprocessorDefinition, + m.fxCompileShaderType, + m.fxCompileShaderModel, + m.fxCompileShaderEntry, + m.fxCompileShaderVariableName, + m.fxCompileShaderHeaderOutput, + m.fxCompileShaderObjectOutput, + m.fxCompileShaderAssembler, + m.fxCompileShaderAssemblerOutput, + m.fxCompileShaderAdditionalOptions, + } + end + + function m.fxCompile(cfg) + if p.config.hasFile(cfg, path.ishlslfile) then + local contents = p.capture(function () + p.push() + p.callArray(m.elements.fxCompile, cfg) + p.pop() + end) + + if #contents > 0 then + p.push('') + p.outln(contents) + p.pop('') + end + end + end + + -- -- Write out the resource compiler block. -- @@ -696,13 +733,52 @@ end } +--- +-- ClCompile group +--- + m.categories.FxCompile = { + name = "FxCompile", + extensions = { ".hlsl" }, + priority = 3, + + emitFiles = function(prj, group) + local fileCfgFunc = function(fcfg, condition) + if fcfg then + return { + m.excludedFromBuild, + m.fxCompilePreprocessorDefinition, + m.fxCompileShaderType, + m.fxCompileShaderModel, + m.fxCompileShaderEntry, + m.fxCompileShaderVariableName, + m.fxCompileShaderHeaderOutput, + m.fxCompileShaderObjectOutput, + m.fxCompileShaderAssembler, + m.fxCompileShaderAssemblerOutput, + m.fxCompileShaderAdditionalOptions, + } + else + return { + m.excludedFromBuild + } + end + end + + m.emitFiles(prj, group, "FxCompile", nil, fileCfgFunc) + end, + + emitFilter = function(prj, group) + m.filterGroup(prj, group, "FxCompile") + end + } + --- -- None group --- m.categories.None = { name = "None", - priority = 3, + priority = 4, emitFiles = function(prj, group) m.emitFiles(prj, group, "None", {m.generatedFile}) @@ -720,7 +796,7 @@ m.categories.ResourceCompile = { name = "ResourceCompile", extensions = ".rc", - priority = 4, + priority = 5, emitFiles = function(prj, group) local fileCfgFunc = { @@ -743,7 +819,7 @@ --- m.categories.CustomBuild = { name = "CustomBuild", - priority = 5, + priority = 6, emitFiles = function(prj, group) local fileFunc = { @@ -776,7 +852,7 @@ m.categories.Midl = { name = "Midl", extensions = ".idl", - priority = 6, + priority = 7, emitFiles = function(prj, group) local fileCfgFunc = { @@ -800,7 +876,7 @@ m.categories.Masm = { name = "Masm", extensions = ".asm", - priority = 7, + priority = 8, emitFiles = function(prj, group) local fileCfgFunc = function(fcfg, condition) @@ -839,7 +915,7 @@ m.categories.Image = { name = "Image", extensions = { ".gif", ".jpg", ".jpe", ".png", ".bmp", ".dib", "*.tif", "*.wmf", "*.ras", "*.eps", "*.pcx", "*.pcd", "*.tga", "*.dds" }, - priority = 8, + priority = 9, emitFiles = function(prj, group) local fileCfgFunc = function(fcfg, condition) @@ -862,7 +938,7 @@ m.categories.Natvis = { name = "Natvis", extensions = { ".natvis" }, - priority = 9, + priority = 10, emitFiles = function(prj, group) m.emitFiles(prj, group, "Natvis", {m.generatedFile}) @@ -2488,12 +2564,85 @@ end - function m.xmlDeclaration() p.xmlUtf8() end + function m.fxCompilePreprocessorDefinition(cfg, condition) + if cfg.shaderdefines and #cfg.shaderdefines > 0 then + local shaderdefines = table.concat(cfg.shaderdefines, ";") + + shaderdefines = shaderdefines .. ";%%(PreprocessorDefinitions)" + m.element('PreprocessorDefinitions', condition, shaderdefines) + end + end + + + function m.fxCompileShaderType(cfg, condition) + if cfg.shadertype then + m.element("ShaderType", condition, cfg.shadertype) + end + end + + + function m.fxCompileShaderModel(cfg, condition) + if cfg.shadermodel then + m.element("ShaderModel", condition, cfg.shadermodel) + end + end + + + function m.fxCompileShaderEntry(cfg, condition) + if cfg.shaderentry then + m.element("EntryPointName", condition, cfg.shaderentry) + end + end + + + function m.fxCompileShaderVariableName(cfg, condition) + if cfg.shadervariablename then + m.element("VariableName", condition, cfg.shadervariablename) + end + end + + + function m.fxCompileShaderHeaderOutput(cfg, condition) + if cfg.shaderheaderfileoutput then + m.element("HeaderFileOutput", condition, cfg.shaderheaderfileoutput) + end + end + + + function m.fxCompileShaderObjectOutput(cfg, condition) + if cfg.shaderobjectfileoutput then + m.element("ObjectFileOutput", condition, cfg.shaderobjectfileoutput) + end + end + + + function m.fxCompileShaderAssembler(cfg, condition) + if cfg.shaderassembler then + m.element("AssemblerOutput", condition, cfg.shaderassembler) + end + end + + + function m.fxCompileShaderAssemblerOutput(cfg, condition) + if cfg.shaderassembleroutput then + m.element("AssemblerOutputFile", condition, cfg.shaderassembleroutput) + end + end + + + function m.fxCompileShaderAdditionalOptions(cfg, condition) + local opts = cfg.shaderoptions + if #opts > 0 then + opts = table.concat(opts, " ") + m.element("AdditionalOptions", condition, '%s %%(AdditionalOptions)', opts) + end + end + --------------------------------------------------------------------------- -- diff --git a/src/base/path.lua b/src/base/path.lua index 63edbb81..cd99fb13 100644 --- a/src/base/path.lua +++ b/src/base/path.lua @@ -251,6 +251,15 @@ end +-- +-- Returns true if the filename represents a hlsl shader file. +-- + + function path.ishlslfile(fname) + return path.hasextension(fname, ".hlsl") + end + + -- -- Takes a path which is relative to one location and makes it relative -- to another location instead. From 40a01361d3bae38213ac1fbe18bdfd7d37eade7a Mon Sep 17 00:00:00 2001 From: tdesveaux Date: Sat, 7 Apr 2018 19:16:29 +0200 Subject: [PATCH 2/3] VStudio: Add tests for FxCompile block --- modules/vstudio/tests/_tests.lua | 1 + .../tests/vc2010/test_fxcompile_settings.lua | 229 ++++++++++++++++++ 2 files changed, 230 insertions(+) create mode 100644 modules/vstudio/tests/vc2010/test_fxcompile_settings.lua diff --git a/modules/vstudio/tests/_tests.lua b/modules/vstudio/tests/_tests.lua index 37337d32..fad06e65 100644 --- a/modules/vstudio/tests/_tests.lua +++ b/modules/vstudio/tests/_tests.lua @@ -63,6 +63,7 @@ return { "vc2010/test_language_settings.lua", "vc2010/test_language_targets.lua", "vc2010/test_floatingpoint.lua", + "vc2010/test_fxcompile_settings.lua", "vc2010/test_globals.lua", "vc2010/test_header.lua", "vc2010/test_files.lua", diff --git a/modules/vstudio/tests/vc2010/test_fxcompile_settings.lua b/modules/vstudio/tests/vc2010/test_fxcompile_settings.lua new file mode 100644 index 00000000..1d16dff3 --- /dev/null +++ b/modules/vstudio/tests/vc2010/test_fxcompile_settings.lua @@ -0,0 +1,229 @@ +-- +-- tests/actions/vstudio/vc2010/test_fxcompile_settings.lua +-- Validate FxCompile settings in Visual Studio 2010 C/C++ projects. +-- Copyright (c) 2014 Jason Perkins and the Premake project +-- + + local p = premake + local suite = test.declare("vstudio_vs2010_fxcompile_settings") + local vc2010 = p.vstudio.vc2010 + local project = p.project + + +-- +-- Setup +-- + + local wks, prj + + function suite.setup() + p.action.set("vs2010") + wks, prj = test.createWorkspace() + end + + local function prepare(platform) + local cfg = test.getconfig(prj, "Debug", platform) + vc2010.fxCompile(cfg) + end + + +--- +-- Check the basic element structure with default settings. +-- Project should not generate this block if no hlsl files or no shader settings sets. +--- + + function suite.empty() + prepare() + test.capture [[ + + ]] + end + + + function suite.defaultSettings() + files { "shader.hlsl" } + prepare() + test.capture [[ + + ]] + end + +--- +-- Test FxCompilePreprocessorDefinition +--- + + function suite.onFxCompilePreprocessorDefinition() + files { "shader.hlsl" } + shaderdefines { "DEFINED_VALUE" } + + prepare() + test.capture [[ + + DEFINED_VALUE;%(PreprocessorDefinitions) + + ]] + end + + + function suite.onFxCompilePreprocessorDefinition_multipleDefines() + files { "shader.hlsl" } + shaderdefines { "DEFINED_VALUE", "OTHER_DEFINED_VALUE" } + + prepare() + test.capture [[ + + DEFINED_VALUE;OTHER_DEFINED_VALUE;%(PreprocessorDefinitions) + + ]] + end + +--- +-- Test FxCompileShaderType +--- + + function suite.onFxCompileShaderType() + files { "shader.hlsl" } + shadertype "Effect" + + prepare() + test.capture [[ + + Effect + + ]] + end + +--- +-- Test FxCompileShaderModel +--- + + function suite.onFxCompileShaderModel() + files { "shader.hlsl" } + shadermodel "5.0" + + prepare() + test.capture [[ + + 5.0 + + ]] + end + + +--- +-- Test FxCompileShaderEntry +--- + + function suite.onFxCompileShaderEntry() + files { "shader.hlsl" } + shaderentry "NewEntry" + + prepare() + test.capture [[ + + NewEntry + + ]] + end + + +--- +-- Test FxCompileShaderVariableName +--- + + function suite.onFxCompileShaderVariableName() + files { "shader.hlsl" } + shadervariablename "ShaderVar" + + prepare() + test.capture [[ + + ShaderVar + + ]] + end + + +--- +-- Test FxCompileShaderHeaderOutput +--- + + function suite.onFxCompileShaderHeaderOutput() + files { "shader.hlsl" } + shaderheaderfileoutput "%%(filename).hlsl.h" + + prepare() + test.capture [[ + + %(filename).hlsl.h + + ]] + end + + +--- +-- Test FxCompileShaderObjectOutput +--- + + function suite.onFxCompileShaderObjectOutput() + files { "shader.hlsl" } + shaderobjectfileoutput "%%(filename).hlsl.o" + + prepare() + test.capture [[ + + %(filename).hlsl.o + + ]] + end + + +--- +-- Test FxCompileShaderAssembler +--- + + function suite.onFxCompileShaderAssembler() + files { "shader.hlsl" } + shaderassembler "AssemblyCode" + + prepare() + test.capture [[ + + AssemblyCode + + ]] + end + + +--- +-- Test FxCompileShaderAssemblerOutput +--- + + function suite.onFxCompileShaderAssemblerOutput() + files { "shader.hlsl" } + shaderassembleroutput "%%(filename).hlsl.asm.o" + + prepare() + test.capture [[ + + %(filename).hlsl.asm.o + + ]] + end + + +--- +-- Test FxCompileShaderAdditionalOptions +--- + + function suite.onFxCompileShaderAdditionalOptions() + files { "shader.hlsl" } + shaderoptions "-opt" + + prepare() + test.capture [[ + + -opt %(AdditionalOptions) + + ]] + end From d995f687ef6f0a3d0178bcabe036cb1a0b144386 Mon Sep 17 00:00:00 2001 From: Sam Surtees Date: Mon, 9 Apr 2018 22:02:05 +1000 Subject: [PATCH 3/3] Fleshed out CI builds - Extended Bootstrap.mak to allow users to specify platform and configuration --- .travis.yml | 33 +++++++++++++++++++++++++++------ Bootstrap.mak | 18 ++++++++++-------- appveyor.yml | 9 +++++++-- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 190717d8..7fdfe4b6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,30 @@ -os: - - linux - - osx +language: c++ +dist: trusty +sudo: false +matrix: + include: + # Linux Debug + - os: linux + compiler: gcc + env: + - CONFIGURATION=debug + # Linux Release + - os: linux + compiler: gcc + env: + - CONFIGURATION=release + # macOS Debug x86 + - os: osx + osx_image: xcode9 + env: + - CONFIGURATION=debug + # macOS Release x86 + - os: osx + osx_image: xcode9 + env: + - CONFIGURATION=release script: - - make -f Bootstrap.mak $TRAVIS_OS_NAME - - make -C build/bootstrap -j config=debug - - bin/release/premake5 test + - make -f Bootstrap.mak $TRAVIS_OS_NAME CONFIG=${CONFIGURATION} + - bin/${CONFIGURATION}/premake5 test diff --git a/Bootstrap.mak b/Bootstrap.mak index 00cb6c70..39e21ba4 100644 --- a/Bootstrap.mak +++ b/Bootstrap.mak @@ -1,4 +1,6 @@ MSDEV = vs2012 +CONFIG = release +PLATFORM = x86 LUA_DIR = contrib/lua/src LUASHIM_DIR = contrib/luashim @@ -36,8 +38,8 @@ SRC = src/host/*.c \ $(LUA_DIR)/lvm.c \ $(LUA_DIR)/lzio.c \ -PLATFORM= none -default: $(PLATFORM) +HOST_PLATFORM= none +default: $(HOST_PLATFORM) none: @echo "Please do" @@ -57,7 +59,7 @@ mingw: $(SRC) $(CC) -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -I"$(LUA_DIR)" -I"$(LUASHIM_DIR)" $? -lole32 ./build/bootstrap/premake_bootstrap embed ./build/bootstrap/premake_bootstrap --os=windows --to=build/bootstrap gmake - $(MAKE) -C build/bootstrap + $(MAKE) -C build/bootstrap config=$(CONFIG)_$(PLATFORM) osx: $(SRC) $(SILENT) rm -rf ./bin @@ -67,7 +69,7 @@ osx: $(SRC) $(CC) -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -DLUA_USE_MACOSX -I"$(LUA_DIR)" -I"$(LUASHIM_DIR)" -framework CoreServices -framework Foundation -framework Security -lreadline $? ./build/bootstrap/premake_bootstrap embed ./build/bootstrap/premake_bootstrap --to=build/bootstrap gmake - $(MAKE) -C build/bootstrap -j`getconf _NPROCESSORS_ONLN` + $(MAKE) -C build/bootstrap -j`getconf _NPROCESSORS_ONLN` config=$(CONFIG) linux: $(SRC) $(SILENT) rm -rf ./bin @@ -77,7 +79,7 @@ linux: $(SRC) $(CC) -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -DLUA_USE_POSIX -DLUA_USE_DLOPEN -I"$(LUA_DIR)" -I"$(LUASHIM_DIR)" $? -lm -ldl -lrt ./build/bootstrap/premake_bootstrap embed ./build/bootstrap/premake_bootstrap --to=build/bootstrap gmake - $(MAKE) -C build/bootstrap -j`getconf _NPROCESSORS_ONLN` + $(MAKE) -C build/bootstrap -j`getconf _NPROCESSORS_ONLN` config=$(CONFIG) bsd: $(SRC) $(SILENT) rm -rf ./bin @@ -87,7 +89,7 @@ bsd: $(SRC) $(CC) -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -DLUA_USE_POSIX -DLUA_USE_DLOPEN -I"$(LUA_DIR)" -I"$(LUASHIM_DIR)" $? -lm ./build/bootstrap/premake_bootstrap embed ./build/bootstrap/premake_bootstrap --to=build/bootstrap gmake - $(MAKE) -C build/bootstrap -j`getconf _NPROCESSORS_ONLN` + $(MAKE) -C build/bootstrap -j`getconf _NPROCESSORS_ONLN` config=$(CONFIG) windows-base: $(SRC) $(SILENT) if exist .\bin rmdir /s /q .\bin @@ -100,7 +102,7 @@ windows-base: $(SRC) windows: windows-base devenv .\build\bootstrap\Premake5.sln /Upgrade - devenv .\build\bootstrap\Premake5.sln /Build Release + devenv .\build\bootstrap\Premake5.sln /Build "$(CONFIG)|$(PLATFORM:x86=win32)" windows-msbuild: windows-base - msbuild /p:Configuration=Release /p:Platform=Win32 .\build\bootstrap\Premake5.sln + msbuild /p:Configuration=$(CONFIG) /p:Platform=$(PLATFORM:x86=win32) .\build\bootstrap\Premake5.sln diff --git a/appveyor.yml b/appveyor.yml index 233e01fc..9caca386 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,13 +2,18 @@ os: Visual Studio 2015 platform: - Win32 + - x64 + +configuration: + - Debug + - Release before_build: - cmd: git clean -ffxd build_script: - cmd: call "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" - - cmd: nmake -f Bootstrap.mak MSDEV=vs2015 windows + - cmd: nmake -f Bootstrap.mak MSDEV=vs2015 windows PLATFORM=%PLATFORM% CONFIG=%CONFIGURATION% test_script: - - cmd: bin\release\premake5 test + - cmd: bin\%CONFIGURATION%\premake5 test