Skip to content

[SPIR-V] static variable in template structures cannot pass to other functions with library profile #7049

@GinShio

Description

@GinShio

Description

Hi, I want to use a series template structures as trait.
When I pass the static constant variables to function or return it in function.
I get the undef value.

Of course, if profile is normal stage (e.g. fragment) it looks good, but it failed if profile is library.

Steps to Reproduce

HLL

template <typename S> struct Trait;
template <> struct Trait<half> {
  using type = half;
  static const uint size = 2;
};

uint get_size() { return Trait<half>::size; }
float cvt(uint x) { return float(x); }

export float testcase(int x) {
  if (x == 2)
    return float(Trait<half>::size); // return 2.0
  else if (x == 4)
    return cvt(Trait<half>::size); // return undef
  else if (x == 8)
    return get_size(); // return undef
  return 0.f;
}

compilation

dxc -O3 -T lib_6_8 -HV 2021 -spirv -fcgl -fspv-target-env=universal1.5 -Fo test.spv test.hlsl

Actual Behavior

%size = OpVariable %_ptr_Private_uint Private
   %testcase = OpFunction %float None %11
          %x = OpFunctionParameter %_ptr_Function_int
   %bb_entry = OpLabel
%param_var_x = OpVariable %_ptr_Function_uint Function
         %26 = OpIEqual %bool %25 %int_4
               OpSelectionMerge %if_merge_0 None
               OpBranchConditional %26 %if_true_0 %if_false_0
  %if_true_0 = OpLabel
         %30 = OpLoad %uint %size
               OpStore %param_var_x %30
         %31 = OpFunctionCall %float %cvt %param_var_x
               OpReturnValue %31

%size is not initialized.

Environment

  • DXC version libdxcompiler.so: 1.8(dev;4662-416fab6b); libdxil.so: 1.8
  • Host Operating System openSUSE Tumbleweed x86_64 6.12.6-1-default

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug, regression, crashneeds-triageAwaiting triagespirvWork related to SPIR-V

    Type

    No type

    Projects

    Status

    Done

    Status

    Triaged

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions