Merge pull request #1037 from tdesveauxPKFX/vstudio-fxcompile

HLSL Shader compilation in Visual Studio
This commit is contained in:
J. Perkins 2018-04-09 12:03:47 -04:00 committed by GitHub
commit 0db3f5680b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 492 additions and 8 deletions

View File

@ -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.
--

View File

@ -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",

View File

@ -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 [[
<FxCompile>
<PreprocessorDefinitions>DEFINED_VALUE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</FxCompile>
]]
end
function suite.onFxCompilePreprocessorDefinition_multipleDefines()
files { "shader.hlsl" }
shaderdefines { "DEFINED_VALUE", "OTHER_DEFINED_VALUE" }
prepare()
test.capture [[
<FxCompile>
<PreprocessorDefinitions>DEFINED_VALUE;OTHER_DEFINED_VALUE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</FxCompile>
]]
end
---
-- Test FxCompileShaderType
---
function suite.onFxCompileShaderType()
files { "shader.hlsl" }
shadertype "Effect"
prepare()
test.capture [[
<FxCompile>
<ShaderType>Effect</ShaderType>
</FxCompile>
]]
end
---
-- Test FxCompileShaderModel
---
function suite.onFxCompileShaderModel()
files { "shader.hlsl" }
shadermodel "5.0"
prepare()
test.capture [[
<FxCompile>
<ShaderModel>5.0</ShaderModel>
</FxCompile>
]]
end
---
-- Test FxCompileShaderEntry
---
function suite.onFxCompileShaderEntry()
files { "shader.hlsl" }
shaderentry "NewEntry"
prepare()
test.capture [[
<FxCompile>
<EntryPointName>NewEntry</EntryPointName>
</FxCompile>
]]
end
---
-- Test FxCompileShaderVariableName
---
function suite.onFxCompileShaderVariableName()
files { "shader.hlsl" }
shadervariablename "ShaderVar"
prepare()
test.capture [[
<FxCompile>
<VariableName>ShaderVar</VariableName>
</FxCompile>
]]
end
---
-- Test FxCompileShaderHeaderOutput
---
function suite.onFxCompileShaderHeaderOutput()
files { "shader.hlsl" }
shaderheaderfileoutput "%%(filename).hlsl.h"
prepare()
test.capture [[
<FxCompile>
<HeaderFileOutput>%(filename).hlsl.h</HeaderFileOutput>
</FxCompile>
]]
end
---
-- Test FxCompileShaderObjectOutput
---
function suite.onFxCompileShaderObjectOutput()
files { "shader.hlsl" }
shaderobjectfileoutput "%%(filename).hlsl.o"
prepare()
test.capture [[
<FxCompile>
<ObjectFileOutput>%(filename).hlsl.o</ObjectFileOutput>
</FxCompile>
]]
end
---
-- Test FxCompileShaderAssembler
---
function suite.onFxCompileShaderAssembler()
files { "shader.hlsl" }
shaderassembler "AssemblyCode"
prepare()
test.capture [[
<FxCompile>
<AssemblerOutput>AssemblyCode</AssemblerOutput>
</FxCompile>
]]
end
---
-- Test FxCompileShaderAssemblerOutput
---
function suite.onFxCompileShaderAssemblerOutput()
files { "shader.hlsl" }
shaderassembleroutput "%%(filename).hlsl.asm.o"
prepare()
test.capture [[
<FxCompile>
<AssemblerOutputFile>%(filename).hlsl.asm.o</AssemblerOutputFile>
</FxCompile>
]]
end
---
-- Test FxCompileShaderAdditionalOptions
---
function suite.onFxCompileShaderAdditionalOptions()
files { "shader.hlsl" }
shaderoptions "-opt"
prepare()
test.capture [[
<FxCompile>
<AdditionalOptions>-opt %(AdditionalOptions)</AdditionalOptions>
</FxCompile>
]]
end

View File

@ -274,6 +274,7 @@
else
return {
m.clCompile,
m.fxCompile,
m.resourceCompile,
m.linker,
m.manifest,
@ -363,6 +364,42 @@
end
--
-- Write the <FxCompile> 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('<FxCompile>')
p.outln(contents)
p.pop('</FxCompile>')
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
---------------------------------------------------------------------------
--

View File

@ -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.