XNA Creators Club Online
Page 1 of 1 (4 items)
Sort Posts: Previous Next

get reflection interface for cbuffer in file

Last post 7/17/2009 5:17 PM by DieterVW. 3 replies.
  • 7/9/2009 1:25 AM

    get reflection interface for cbuffer in file

    I want to write a little command line tool to generate C++ structs in .h files that match HLSL cbuffers..  I want to use the reflection interfaces to get the cbuffer member types and alignments and all that.  Eg:

    struct Cows {
       int i3;
       float2 f2;
    };
    cbuffer Foo {
       float3 one;
       float2 two;
       Cows cows;
    };

    I could append some trivial shader like float4 PS() : SV_Target { return float4(0.0, 0.0, 0.0, 0.0); } and use D3DX10CompileFrom* and pass the blob to D3D10ReflectShader/D3DReflect.  Unfortunately, reflection info seems only to be preserved in compiled shaders for shaders that actually reference that cbuffer.  That is, ID3D10ShaderReflection::GetConstantBufferByName returns E_FAIL when I ask for "Foo" in this case.  I don't know how to create a shader that references the cbuffer without first parsing the hlsl, which of course I really would rather avoid.  Anyone know how to preserve the reflection info for an unreferenced cbuffer or otherwise involve with the shader in some trivial way that requires no parsing?

    Thanks,

    .sean

  • 7/9/2009 1:40 PM In reply to

    Re: get reflection interface for cbuffer in file

    But if you're not actually using "Foo", why do you need to get information about it? Its dead code that's not being used.

  • 7/9/2009 3:06 PM In reply to

    Re: get reflection interface for cbuffer in file

    It's really not dead code.  I just want to pass my tool the hlsl file name and the cbuffer name, and generate a matching C++ struct header for the cbuffer.  The cbuffers will still be referenced by shaders that could be compiled offline or at runtime with D3DX.. just not at the early stage when I am using the cbuffer reflection to generate C++ code.
  • 7/17/2009 5:17 PM In reply to

    Re: get reflection interface for cbuffer in file

    You actually can't.  The compiler ignores resources that are not used in the shaders being compiled.  So this means you'd have to run a real compile for every shader and every entry point in order to gather the list of all cbuffers that are used.

    Is it possible for you to compile/reflect the real shader code files directly and then do a unique on the cbuffers that you're actually writing out c++ headers for in order to avoid duplicates? 
Page 1 of 1 (4 items) Previous Next