user955249
user955249

Reputation:

How to write the header file if I want to compile HLSL at build time to header files,

MSDN says you can compile your .hlsl files into byte arrays that are defined in header files. And this is the code they give.

    #include "PixelShader.h"
    ComPtr<ID3D11PixelShader> m_pPixelShader;
    hr = pDevice->CreatePixelShader(g_psshader, 
         sizeof(g_psshader), nullptr, &m_pPixelShader);

So g_psshader is the byte array. But how to define g_psshader? There's nowhere I can find talk about that. I tried sereral way but all failed. MSDN provided a Media extensions sample. But there is no PixelShader.h in that sample.

In case you missed the question: How to define g_psshader in the code above(I mean in header PixelShader.h).

Upvotes: 3

Views: 5463

Answers (2)

pracsec
pracsec

Reputation: 330

This solution is for Visual Studio 2012.

To set the header file and variable name associated with a .fx or .hlsl file:

  1. Right-click on the .fx or .hlsl file inside of the Solution Explorer, and select Properties.
  2. There should be a tree on the left called "HLSL Compiler". Expand this tree and select "Output Files".
  3. On the Property Sheet on the right there are several properties for managing the HLSL Compilation.

"Header Variable Name" -> The name of the variable that will contain the shader byte code.

"Header File Name" -> The name of the header file to put the shader byte code in.

My understanding is that if you include this file into your code, then you should have access to the variables compiled into this file. The FX and HLSL code should be compiled into these files before the build process in the main project begins.

NOTE: You may also have to change the "Entrypoint Name" under General to reflect the name of the technique you wish to compile (assuming you're using a .fx). There may also be issues with the "Shader Type" and "Shader Model" that you will have to specify for your particular shader file.

Upvotes: 7

Some programmer dude
Some programmer dude

Reputation: 409472

The g_ prefix hints that it might be a global variable, and reading the CreatePixelShader documentation tells me that it's a pointer to compiled bytecode. This means that you first have to actually load and compile the shader source, and then pass a pointer to this compiled code to the CreatePixelShader function. What function does the loading/compilation of the shader source I have no idea, as I don't know anything about D3D, I'm just using some common sense (regarding the variable name) and a quick Internet search for the function documentation.

Upvotes: 0

Related Questions