[SlimDX] ShaderReflection

Started by
1 comment, last by Starnick 12 years, 3 months ago
I'm trying to get a look at ShaderReflection but i get an exception on its constructor.


ShaderBytecode bytecode = ShaderBytecode.CompileFromFile(selectedFile, "fx_5_0", ShaderFlags.None, EffectFlags.None);
var text = bytecode.Disassemble();
ShaderReflection reflection = new ShaderReflection(bytecode);

selectedFile is the MiniTri 11 fx file. The disassemble seems to work.

I tried to enable unmanaged debug, but as its a "SlimDX.D3DCompiler.D3DCompilerException", i'd guess it originates in "D3DCompiler_43.dll".

but all i get is :


A first chance exception of type 'SlimDX.D3DCompiler.D3DCompilerException' occurred in SlimDX.dll
An unhandled exception of type 'SlimDX.D3DCompiler.D3DCompilerException' occurred in SlimDX.dll
Additional information: E_FAIL: An undetermined error occurred (-2147467259)
Advertisement
oh noes, reflection doesn't work on effects but only on shaders. :'(
What are you trying to accomplish with shader reflection?

In order to use the reflection API with an effect, you're going to have to get the byte code for the individual shader fragments that make up each effect pass, e.g. after compiling an effect, given an EffectPass:


EffectPass pass; //From your effect

EffectShaderVariable shaderVar = pass.VertexShaderDescription.Variable;
ShaderDescription shDesc;
shaderVar.GetShaderDescription(0, out shDesc);
ShaderReflection reflect = new ShaderReflection(shDesc.Bytecode);

//Do something with the reflection object

//Don't forget to dispose of these afterwards, otherwise the slimdx object table will report them as a leak!
reflect.Dispose();
shDesc.Signature.Dispose();
shDesc.Bytecode.Dispose();


The above would be reflecting over the vertex shader in the given pass, e.g. say you want to create an input layout up front when loading your effect you can use the ShaderReflection to examine the inputs.

This topic is closed to new replies.

Advertisement