Recommended Posts

Hello,

i want to use

- fxc  Effect compiler to compile my Fx Files with, Techniques, Passes, Shaders to ByteCode  => no Problem

- SharpDX ShaderReflection to get attributes of every used Shader to generate Constant Buffer Structures an other things

- to use ShaderReflection  i have to feed the ShaderByteCode of every single Shader i want to operate with.

I was succesfull to iterate through the Effect for the Techniques, an iterate through the Techniques for the Passes an the Descriptions

I struggled a lot but cannot find out where is the connection to get the ShaderByteCode of the Shaders that are used by a EffectPass ??

Here is the anser of

AlexandreMutel

And even then, you can still use the FX file format - the difference is you'd have an offline compiler tool that parses the format for techniq

ues/passes in order to acquire the necessary shader profiles + entry points. So with the profile/entry point in hand, you can run the FX file through the D3DCompiler to get a ShaderByteCode object for each shader, then use that to create a reflection object to query all your meta data. Then write out the reflected meta data to a file, that gets consumed by your application at runtime - which would be your own implementation of Effects11 (or something completely different, either way...you use the meta data to automatically setup your constant buffers, bind resources, and manage the shader pipeline by directly using the Direct3D11 shader interfaces).

How do i get the pofile/entry point at hand ??

Share on other sites

Hello,

after much, much searching the internet and reading of the Directx 11Documentation on the Microsoft Server i could eventually

find the solution.

In the following code fragment we read the compiled shaderbytecode of a effect.
For easy understanding we get one Technik, then the pass and so on.
The iteration of the techniques and passes is no problem.
The problem was how to get the shaderbytecode from the EffectPass.

I really hope that someone finds this code helpful. I had to spend much time to find this solution.

Now why this all ? From the given infos i can easily, automatically create all my ConstantBuffer Structures and inputlayouts and many other things.

           SharpDX.Direct3D11.Effect                      a_Effect           = new SharpDX.Direct3D11.Effect(Gl.Device, File.ReadAllBytes(filename),0);
SharpDX.Direct3D11.EffectTechnique             a_technique        = a_Effect.GetTechniqueByIndex(0);
SharpDX.Direct3D11.EffectPass                  a_pass             = a_technique.GetPassByIndex(0);

string []   cb_name_array = new string[100];

// for example Loop the Constantbuffer
for (int i = 0; i < SR.Description.ConstantBuffers; i++)
{
SharpDX.D3DCompiler.ConstantBuffer cb = SR.GetConstantBuffer(i);

// loop the Variables of the ConstantBuffer
for (int j = 0; j < cb.Description.VariableCount; j++)
{

cb_name_array[j] = variable.Description.Name;
}
}

Create an account

Register a new account

1. 1
2. 2
3. 3
Rutin
19
4. 4
5. 5

• 10
• 14
• 30
• 13
• 11
• Forum Statistics

• Total Topics
631782
• Total Posts
3002338
×