Skip to content

[SPIR-V] Partial Template Specializations with non-type parameters crashes DXC with found unregistered decl #7007

Closed

Description

Description
The following code:

namespace nbl
{
namespace hlsl
{


template<typename MatT>
struct matrix_traits;
// partial spec for matrices
template<typename T, int32_t N, int32_t M>
struct matrix_traits<matrix<T,N,M> >
{
    static const uint32_t RowCount = N;
    static const uint32_t ColumnCount = M;
    static const bool Square = N==M;
};

namespace impl
{
template<typename MatT>
MatT diagonal(float diagonal)
{
    MatT output;
    
    for(int i = 0; i < matrix_traits<MatT>::RowCount; ++i)
    for(int j = 0; j < matrix_traits<MatT>::ColumnCount; ++j)
        output[i][j] = 0;
    
    for(int diag = 0; diag < matrix_traits<MatT>::RowCount; ++diag)
        output[diag][diag] = diagonal;
        
    return output;
}
}
}
}

crashes the compiler when compiling SpirV and not when compiling DXIL

Steps to Reproduce

SPIR-V : https://godbolt.org/z/69KodrMb9
HLSL : https://godbolt.org/z/49YjvYnnh

Actual Behavior

<source>:10:30: fatal error: found unregistered decl N
template<typename T, int32_t N, int32_t M>
                             ^

Environment

  • DXC version: trunk
  • Host Operating System: Godbolt

Activity

  1. added
    bug
    needs-triage
    spirv
    on Nov 13, 2024
  2. zopsicle commented on Mar 6, 2025

    @zopsicle

    Until this is fixed, here is a workaround that seems to work:

    template<typename T, int32_t N, int32_t M>
    struct matrix_traits<matrix<T,N,M> >
    {
        enum : uint32_t { RowCount = N };
        enum : uint32_t { ColumnCount = M };
    };

    doesn’t work for bool though (DXC segfaults).

  3. devshgraphicsprogramming commented on Mar 6, 2025

    @devshgraphicsprogramming
    Author

    Przemog1 looks useful

  4. neversleeping commented on Mar 12, 2025

    @neversleeping

    Isn't that a duplicate of #5563 ?

  5. devshgraphicsprogramming commented on Mar 12, 2025

    @devshgraphicsprogramming
    Author

    Possibly but I narrowed mine down to it being an issue of specializing on a value instead of a typename

  6. moved this from For Google to Triaged in HLSL Triageon Jul 29, 2025
  7. moved this from New to In progress in HLSL Roadmapon Jul 29, 2025
  8. added a commit that references this issue on Jul 29, 2025
    7c7202b
  9. moved this from In progress to In review in HLSL Roadmapon Jul 29, 2025
  10. added a commit that references this issue on Jul 30, 2025
    1e3da15
  11. moved this from In review to Done in HLSL Roadmapon Jul 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugspirv

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions