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).
The
g_prefix hints that it might be a global variable, and reading theCreatePixelShaderdocumentation 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 theCreatePixelShaderfunction. 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.