# Compiling Hlsl - Shaders In Vs 2013

## Recommended Posts

Hi,

Just a short one regarding compiling of HLSL files/ shaders within Visual Studio.

To be able to compile a HLSL/ shader file as a part of your project, you have to define (at least) 2 things for the file (HLSL compiler):

When I split all shaders (VS and PS for example) in separate files, it's all good, because then I set shader type to either PS or VS (+ I specify the main entry point, i.e. PS_main).

But now I've decided to combine the PS and VS in 1 file and the above is no longer an option.

I did find a trick to bypass this, that is to set the shader type to Effect/FX, which compiles the HLSL file fine.

Never the less, FXC (ofcourse) warns me that effects are deprecated (note; I don't use effects11 in my code anymore).

In short;

- do you have any idea how to be able to compile a PS and VS in 1 file, within Visual Studio (2013)?

(without the warning and bypass as if it were an effect file)

##### Share on other sites

You could create stub files (one for VS and one for PS) that simply include the combined shader.  That would allow you to set the MSBuild properties for each of the stub files accordingly, and would allow you to have control over the naming of each of the compiled output blobs.

I'm actually investigating to do this with Hieroglyph in the near future, so if there are other solutions I would be happy to hear them as well!

##### Share on other sites

Unfortunately, VS2013's hlsl vertex/pixel shader compiling is a one input to one output file thing only. I solved this via writing a batch file to run fxc.exe on my input files and then setting it to run it as a postbuild event in the project's settings (ie. writing my own shader build system). Here's a few lines of batch file code to compile a simple vertex shader.

set entryfuncName=VS

%shadercompile% input_hlsl.hlsl /E"%entryfuncName%" /Fo"output.cso" /Tvs_4_0 /nologo

Then all you have to do for a "compile on modifying shader source code" feature is to create a file after the process, check if input files are modified later than that lock file, then compile if true.

##### Share on other sites

Thanks, appaerantly I'm not the only one getting annoyed by the warining about effects being deprecated.

Splitting the VS and PS into 2 different files is not worth if for me/ if you ask me.

I'll think about creating the batch/ manual post build event, although it sounds like a bit too much to just get rid of the warning.

Though I don't have a clue yet on how to 'create' them :o

##### Share on other sites

Though I don't have a clue yet on how to 'create' them :o

It is just an empty file with an include statement.  I haven't used it myself, but it should be a suitable solution for what you are trying to do...

##### Share on other sites
Thanks, I'll give it a shot

##### Share on other sites

Not sure if this is helpful, but I use a single HLSL file. Although, I always compile at runtime, and you may be wanting to pre-compile. It ignores any extra code in the file when you do this.

    if(SUCCEEDED(D3DX11CompileFromFile("PhongShader.hlsl", 0, 0, "VertexShaderMain", "vs_5_0", 0, 0, 0, &VS, 0, 0)))
{
{


## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627744
• Total Posts
2978895

• 10
• 10
• 21
• 14
• 14