[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
Tue Dec 2 05:09:12 EST 2014


Hi Brad and Gilles.

I have updated the patch suggestion, please find it below. Gilles, I took
your spelling for ENTRYPOINT and your documentation.

Gilles' fork is more exhaustive than the minimal patch I am suggesting.
What's important for me, is to have one or the other pushed as soon as
possible, as the addition of the shader support without the shader model
and without the entrypoint is breaking some of the projects I am working
on. And I suspect that it will break many people.

I leave it up to you guys to decide which patch you prefer.

Thanks again for the quick answers, it's really nice to get an answer so
fast!


>From e92c4b804b1b253f96297fff4e4915934e5e0c59 Mon Sep 17 00:00:00 2001
From: cperthuis <cedric.perthuis at gmail.com>
Date: Tue, 2 Dec 2014 01:41:10 -0800
Subject: [PATCH] added VS_SHADER_ENTRYPOINT and VS_SHADER_MODEL file
 properties for Visual Studio shader custom tool

---
 Help/manual/cmake-properties.7.rst                 |  2 ++
 Help/prop_sf/VS_SHADER_ENTRYPOINT.rst              |  5 ++++
 Help/prop_sf/VS_SHADER_MODEL.rst                   |  5 ++++
 Source/cmVisualStudio10TargetGenerator.cxx         | 27
+++++++++++++++++++++-
 Tests/VSWinStorePhone/CMakeLists.txt               |  6 +++++
 .../Direct3DApp1/SimplePixelShader.hlsl            |  2 +-
 .../Direct3DApp1/SimpleVertexShader.hlsl           |  2 +-
 7 files changed, 46 insertions(+), 3 deletions(-)
 create mode 100644 Help/prop_sf/VS_SHADER_ENTRYPOINT.rst
 create mode 100644 Help/prop_sf/VS_SHADER_MODEL.rst

diff --git a/Help/manual/cmake-properties.7.rst
b/Help/manual/cmake-properties.7.rst
index bf456f5..5bbb89e 100644
--- a/Help/manual/cmake-properties.7.rst
+++ b/Help/manual/cmake-properties.7.rst
@@ -291,6 +291,8 @@ Properties on Source Files
    /prop_sf/OBJECT_OUTPUTS
    /prop_sf/SYMBOLIC
    /prop_sf/VS_DEPLOYMENT_CONTENT
+   /prop_sf/VS_SHADER_MODEL
+   /prop_sf/VS_SHADER_ENTRYPOINT
    /prop_sf/VS_SHADER_TYPE
    /prop_sf/WRAP_EXCLUDE
    /prop_sf/XCODE_EXPLICIT_FILE_TYPE
diff --git a/Help/prop_sf/VS_SHADER_ENTRYPOINT.rst
b/Help/prop_sf/VS_SHADER_ENTRYPOINT.rst
new file mode 100644
index 0000000..69ff3e6
--- /dev/null
+++ b/Help/prop_sf/VS_SHADER_ENTRYPOINT.rst
@@ -0,0 +1,5 @@
+VS_SHADER_ENTRYPOINT
+--------------
+
+Specifies the name of the entry point for the shader of a ``.hlsl`` source
+file.
diff --git a/Help/prop_sf/VS_SHADER_MODEL.rst
b/Help/prop_sf/VS_SHADER_MODEL.rst
new file mode 100644
index 0000000..5adb680
--- /dev/null
+++ b/Help/prop_sf/VS_SHADER_MODEL.rst
@@ -0,0 +1,5 @@
+VS_SHADER_MODEL
+--------------
+
+Specifies the shader model of a ``.hlsl`` source file. Some shader types
can
+only be used with recent shader models
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx
b/Source/cmVisualStudio10TargetGenerator.cxx
index f591fc8..d1031cc 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_ENTRYPOINT"))
+      {
+      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";
     }
diff --git a/Tests/VSWinStorePhone/CMakeLists.txt
b/Tests/VSWinStorePhone/CMakeLists.txt
index 0041c75..c6f814d 100644
--- a/Tests/VSWinStorePhone/CMakeLists.txt
+++ b/Tests/VSWinStorePhone/CMakeLists.txt
@@ -103,7 +103,13 @@ set_property(SOURCE ${RELEASE_CONTENT_FILES} PROPERTY
   VS_DEPLOYMENT_CONTENT
$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>,$<CONFIG:MinSizeRel>>)

 set_property(SOURCE ${PIXELSHADER_FILES} PROPERTY VS_SHADER_TYPE Pixel)
+set_property(SOURCE ${PIXELSHADER_FILES} PROPERTY VS_SHADER_ENTRYPOINT
mainPS)
+set_property(SOURCE ${PIXELSHADER_FILES} PROPERTY VS_SHADER_MODEL
4.0_level_9_3)
+
 set_property(SOURCE ${VERTEXSHADER_FILES} PROPERTY VS_SHADER_TYPE Vertex)
+set_property(SOURCE ${VERTEXSHADER_FILES} PROPERTY VS_SHADER_ENTRYPOINT
mainVS)
+set_property(SOURCE ${VERTEXSHADER_FILES} PROPERTY VS_SHADER_MODEL
4.0_level_9_3)
+

 source_group("Source Files" FILES ${SOURCE_FILES})
 source_group("Header Files" FILES ${HEADER_FILES})
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/SimplePixelShader.hlsl
b/Tests/VSWinStorePhone/Direct3DApp1/SimplePixelShader.hlsl
index d61e2c8..6796da1 100644
--- a/Tests/VSWinStorePhone/Direct3DApp1/SimplePixelShader.hlsl
+++ b/Tests/VSWinStorePhone/Direct3DApp1/SimplePixelShader.hlsl
@@ -4,7 +4,7 @@ struct PixelShaderInput
   float3 color : COLOR0;
 };

-float4 main(PixelShaderInput input) : SV_TARGET
+float4 mainPS(PixelShaderInput input) : SV_TARGET
 {
   return float4(input.color,1.0f);
 }
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/SimpleVertexShader.hlsl
b/Tests/VSWinStorePhone/Direct3DApp1/SimpleVertexShader.hlsl
index 65d60e5..0963060 100644
--- a/Tests/VSWinStorePhone/Direct3DApp1/SimpleVertexShader.hlsl
+++ b/Tests/VSWinStorePhone/Direct3DApp1/SimpleVertexShader.hlsl
@@ -17,7 +17,7 @@ struct VertexShaderOutput
   float3 color : COLOR0;
 };

-VertexShaderOutput main(VertexShaderInput input)
+VertexShaderOutput mainVS(VertexShaderInput input)
 {
   VertexShaderOutput output;
   float4 pos = float4(input.pos, 1.0f);
-- 
1.9.4.msysgit.2


On Mon, Dec 1, 2014 at 7:59 AM, Gilles Khouzam <Gilles.Khouzam at microsoft.com
> wrote:

> Hi Cedric
>
> Thanks for the patch,
>
> I had started adding a full set of shader property support on our fork:
>
>
> https://cmakems.codeplex.com/SourceControl/changeset/c5f9c207ee3490dda1e4c2a0eb647492b934fc11
>
> I haven't asked to get this pulled in because with the number of options,
> it is probably better to add this support as a flag set instead of having a
> set of specific if statements. I haven't had a chance to complete this work
> though.
>
> -----Original Message-----
> From: Brad King [mailto:brad.king at kitware.com]
> Sent: Monday, December 1, 2014 07:06
> To: Cedric Perthuis
> Cc: cmake-developers at cmake.org; Gilles Khouzam
> Subject: Re: [cmake-developers] Patch pull request: support for shader
> entry point and shader model for Visual Studio FXCompiler custom tool build
>
> On 11/29/2014 12:51 AM, Cedric Perthuis wrote:
> > So, here's a patch to address this.
> [snip]
> > +    if (const char* se = sf->GetProperty("VS_SHADER_ENTRY_POINT"))
> [snip]
> > +    if (const char* sm = sf->GetProperty("VS_SHADER_MODEL"))
>
> Thanks.  Here are some comments on the patch:
>
> * Please update the documentation too.  See
>
>    Help/manual/cmake-properties.7.rst
>    Help/prop_sf/VS_SHADER_TYPE.rst
>
>   for how VS_SHADER_TYPE is documented.
>
> * Please update the test.  See
>
>    Tests/VSWinStorePhone/CMakeLists.txt
>
>   for current testing of VS_SHADER_TYPE.
>
> Thanks,
> -Brad
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20141202/b101940b/attachment.html>


More information about the cmake-developers mailing list