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 ® D3D10 Shader Compiler 9.23.949.2378
Copyright © 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 ® D3D10 Shader Compiler 9.23.949.2378
Copyright © Microsoft Corporation 2002-2007. All rights reserved.

compilation succeeded; see C:UsersppodilaDesktop … .ps