[cmake-developers] Patch pull request: support for shader entry point and shader model for Visual Studio FXCompiler custom tool build
Cedric Perthuis
cedric.perthuis at gmail.com
Sat Nov 29 00:51:33 EST 2014
Hi,
I would like to suggest the following patch. It allows the user to specify
the shader entry point and the shader model for a given shader source file.
Currently, with cmake 3.1 rc2, if you try to add a file with the extension
".hlsl" to the list of the sources, and generate a visual studio 2013
project, it will automatically configure the shader compilation custom tool
on that file and will use the Visual Studio defaults.
It will rarely be a good default behavior, in particular the entry point of
shaders varies a lot. Advanced project will very rarely use "main" as entry
point.
If the entry point is not configured properly, the shader compilation will
error out, which will fail the global compilation of the project.
So it's actually a pretty serious breakage. It would be better in that
case, to have the option to not have the shader tool automatically
configured on ".hlsl" files.
For Vertex and Pixel shaders, there's also a common practice which consists
in having both the vertex and the pixel shader in the same file.
When users do this, they rarely use "main" as entry point, but rather
things like "mainPS", "mainVS".
So, here's a patch to address this.
I tested it with the following:
set_property(SOURCE ${PIXELSHADER_FILES} PROPERTY VS_SHADER_TYPE Pixel)
set_property(SOURCE ${PIXELSHADER_FILES} PROPERTY VS_SHADER_MODEL 5.0)
set_property(SOURCE ${PIXELSHADER_FILES} PROPERTY VS_SHADER_ENTRY_POINT
mainPS)
Thanks,
Cedric
>From 537f8c4b1d0dbf79271a9a47363c8c395b3da249 Mon Sep 17 00:00:00 2001
From: cperthuis <cedric.perthuis at gmail.com>
Date: Fri, 28 Nov 2014 21:34:22 -0800
Subject: [PATCH] added VS_SHADER_ENTRY_POINT and VS_SHADER_MODEL file
properties for Visual Studio shader custom tool
---
Source/cmVisualStudio10TargetGenerator.cxx | 27 ++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx
b/Source/cmVisualStudio10TargetGenerator.cxx
index f591fc8..2e9f108 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -1203,6 +1203,8 @@ void
cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
bool toolHasSettings = false;
std::string tool = "None";
std::string shaderType;
+ std::string shaderEntryPoint;
+ std::string shaderModel;
std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
if(ext == "hlsl")
{
@@ -1213,6 +1215,18 @@ void
cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
shaderType = st;
toolHasSettings = true;
}
+ // Figure out which entry point to use if any
+ if (const char* se = sf->GetProperty("VS_SHADER_ENTRY_POINT"))
+ {
+ shaderEntryPoint = se;
+ toolHasSettings = true;
+ }
+ // Figure out which entry point to use if any
+ if (const char* sm = sf->GetProperty("VS_SHADER_MODEL"))
+ {
+ shaderModel = sm;
+ toolHasSettings = true;
+ }
}
else if(ext == "jpg" ||
ext == "png")
@@ -1295,7 +1309,18 @@ void
cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
(*this->BuildFileStream) << cmVS10EscapeXML(shaderType)
<< "</ShaderType>\n";
}
-
+ if(!shaderEntryPoint.empty())
+ {
+ this->WriteString("<EntryPointName>", 3);
+ (*this->BuildFileStream) << cmVS10EscapeXML(shaderEntryPoint)
+ << "</EntryPointName>\n";
+ }
+ if(!shaderModel.empty())
+ {
+ this->WriteString("<ShaderModel>", 3);
+ (*this->BuildFileStream) << cmVS10EscapeXML(shaderModel)
+ << "</ShaderModel>\n";
+ }
this->WriteString("</", 2);
(*this->BuildFileStream) << tool << ">\n";
}
--
1.9.4.msysgit.2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20141128/bd23af24/attachment.html>
More information about the cmake-developers
mailing list