File encodings matter when writing Pixel Shaders

HLSL is the defacto language that you will be using when writing Pixel Shaders for WPF. But before you can use it, you will have to compile the HLSL to pixel shader byte code. The DirectX SDK ships with the FXC compiler that can do this job for you. However this compiler is very sensitive about the file encoding that is used for your HLSL code.

If you are writing your HLSL in Visual Studio, the default encoding for text files is Unicode (UTF-8 with signature) – Codepage 65001. You can see this by going to File –> Advanced Save Options…

image

image

 

If you keep this encoding, you will have trouble compiling the HLSL and will result in such an output:

error X3501: ‘main’: entrypoint not found

Microsoft (R) D3D10 Shader Compiler 9.23.949.2378
Copyright (C) Microsoft Corporation 2002-2007. All rights reserved.

compilation failed; no code produced

 

The Solution

Use a more rudimentary encoding such as ASCII. I chose the Western European (Windows) – Codepage 1252.

image

 

With that in place, FXC was smiling at me:

Microsoft (R) D3D10 Shader Compiler 9.23.949.2378
Copyright (C) Microsoft Corporation 2002-2007. All rights reserved.

compilation succeeded; see C:\Users\ppodila\Desktop\ … .ps

Similar Posts:

8 responses to “File encodings matter when writing Pixel Shaders”

  1. Martin

    You know, I absolutely LOVE YOU for writing post! I was getting insane!!!

  2. Cory Plotts

    I wish I had seen this post this morning! All of a sudden it started working … and I couldn’t fathom why … the only thing I did differently was to save the .fx file with a different file editor.

    Thanks for explaining this!

    One thing to note is that the templates that Greg Schechter & Co. have made have the Western European (Windows) – Codepage 1252 encoding selected by default for .fx files.

    Check out:
    http://blogs.msdn.com/greg_schechter/archive/2008/08/11/a-visualstudio-buildtask-and-project-and-item-templates-for-writing-shadereffects.aspx

  3. Encodings Matter with .fx Files « Fun with WPF

    [...] by chance I ran across Pavan Podila’s post on the matter. Ah, that’s [...]

  4. Joe

    You probably saved me a good 10-20 minutes worth of banging my head against the wall. Thanks!!!

  5. Cory Plotts’ Blog » Encodings Matter with .fx Files

    [...] by chance I ran across Pavan Podila’s post on the matter. Ah, that’s [...]

  6. Irene

    Thanks a million :)

Leave a Reply