AnneP
AnneP

Reputation: 27

SharpDX - fxc.exe error when compiling hlsl file

I'am starting to learn SharpDX and Holographic template for C#.

While compiling project I have error at compilation of shader file.

var vertexShaderByteCode = ShaderBytecode.CompileFromFile("Content/Shaders/VertexSharderShared.hlsl", "VS", "vs_5_0", ShaderFlags.Debug);

fxc.exe exited with code 1.

In the sample they use some .cso file while loading shader into byte code: code img

As I don't really understand where that .cso comes from and what Vprt is, I prefer loading hlsl file directly. I'm using SharpDX 3.0.2, SharpDX.Direct3D11 3.0.2 and SharpDX.D3DCompiler 3.0.2.

Thanks!

Upvotes: 1

Views: 852

Answers (1)

ErnieDingo
ErnieDingo

Reputation: 444

The CSO files need to be loaded then the relevant shader created. Below is an example of a function I use to load the shader. Please note, that you should hold onto the byte code as well as the vertex shader in this example.

The Helper function is my cross uwp/mfc wrapper, but it basically returns the file in a datastream in memory.

The CSO file is byte code, you need to attach it to the correct Sharpdx.Direct3D11 shader class.

The bytecode is also used to reference the semantic interface (for Vertex buffers only). once you have created that, your draw call can match the data against the GPU register that it is associated to. But the code below at least will load your CSO file in and create the vertexshader.

goodluck.

         using (Stream fileStream = Helper.GetFileStream(a_fileName, a_filePath))
        {
            a_byteCode = new D3DCompiler.ShaderBytecode(fileStream);

            if (a_byteCode != null)
            {
                a_child = new D3D11.VertexShader(a_device, a_byteCode)
                {
                    DebugName = "a_fileName"
                };
            }
            else
            {
                throw new Exception("Unable to load file: " + a_fileName);
            }

        }

Upvotes: 0

Related Questions