Skip to content

Library compilation to support library reflection #657

Closed

Description

@mrvux

Since compiled shaders already support reflection (using ID3D11LibraryReflection/ID3D12ShaderReflection)

Bytecode compiled with lib_6_1 could definitely also provide ID3D11LibraryReflection support.

Reflection data should match what's already in the D3D11 counterpart (eg: function name / parameters), since it's already quite exhaustive (and ideally use the same interface).

This is really useful in order to scan library for existing functions (when building authoring tools).

Activity

  1. pow2clk commented on Sep 11, 2020

    @pow2clk
    Collaborator

    Supported!

  2. mrvux commented on Nov 1, 2020

    @mrvux
    ContributorAuthor

    Thanks, I finally had time to try it, seems there is some partial support, also I could see a few issues

    Taking this extremely simple code :

    float3 Apply(float3 input)
    {
        return input * 2.0f;
    }
    

    accessing reflection gives a mangled name in function desc :

     D3D12_FUNCTION_DESC func_desc;
     auto fr = lib_ref->GetFunctionByIndex(0);
     fr->GetDesc(&func_desc);
    

    func_desc.Name gives me :

    �?Apply@ya?AV?$vector@M$02@v1@Tyler "-z-" Mulligan (@z)

    Also seems parameter reflection is not working versus d3d12 counterpart :

    D3D12_PARAMETER_DESC pdesc;
    auto p = fr->GetFunctionParameter(0);
    HRESULT hr = p->GetDesc(&pdesc);

    hr returns an E_FAIL here

    Should I actually post those as separate issues?

    Thanks

  3. pow2clk commented on Nov 2, 2020

    @pow2clk
    Collaborator

    Hi mrvux (@mrvux)!

    The name mangling is intentional I'm afraid. See this line where the mangled name return is tested:

    if (Name.compare("\01?function0@@YAM$min16f@@Z") == 0) {

    To demangle it, you might consider the fairly simple approach taken by the internal code:

    StringRef DemangleFunctionName(StringRef name) {

    unfortunately, this function isn't directly available outside the codebase

    The GetFunctionParameter issue looks unexpected. I notice we have no testing for it. 😞 Maybe Tex Riddell (@tex3d) has some insight, but I think it's worth creating a new issue regardless.

  4. tex3d commented on Nov 2, 2020

    @tex3d
    Contributor

    While we implemented some library reflection through the ID3D11LibraryReflection interface, there are fundamental differences between what a library is and what it's used for in D3D11 with FXC and DXBC vs. D3D12 with DXC and DXIL. One (DXBC) consists of shader snippets used exclusively for constructing function linking graphs at runtime in D3D11, and the other (DXIL) is more similar to a C++ library for use in offline linking of modules, as well as for DXR shaders and functions linked by drivers. As you point out, one difference is that DXIL libraries mangle functions in order to support function overloading.

    It may not be worth it to attempt to make reflection match in more than some useful subset of ways. The implementation of DXIL library reflection in this interface was limited to known use cases that were needed for developers using them at the time (for DXR).

    I agree we should create a new issue for GetFunctionParameter. Then we would like to know how high a priority this is for developers who would like to use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions