microsoft / microsoft/DirectXShaderCompiler

[SPIR-V] 'vk::SpirvOpaqueType<NNNN>' is an object and cannot be used as a type parameter` a.k.a. SpirvType as `T` of SpirvType

Open
#7,015 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs-triage spirv
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

Description

Follow up to https://github.com/microsoft/DirectXShaderCompiler/issues/5092 as requested by @s-perron

Steps to Reproduce

Declare one SpirvOpaqueType (or even SpirvType) and shove it in another opaque type, examples:

  • image type, inside combined sampler image
template<typename SampledType, spv::Dim dim, uint32_t Depth, uint32_t Arrayed, uint32_t MS, uint32_t Sampled, spv::ImageFormat Format=spv::ImageFormatUnknown, spv::AccessQualifier AccessQualifier=spv::AccessQualifierMax>
using image = vk::SpirvOpaqueType<
    /*spv::OpTypeImage*/ 25,
    SampledType,
    vk::Literal<vk::integral_constant<uint,dim> >,
    vk::Literal<vk::integral_constant<uint,Depth> >,
    vk::Literal<vk::integral_constant<uint,Arrayed> >,
    vk::Literal<vk::integral_constant<uint,MS> >,
    vk::Literal<vk::integral_constant<uint,Sampled> >,
    vk::Literal<vk::integral_constant<uint,Format> >
// TODO: use `nbl::hlsl::conditional_t<AccessQualifier==Max` to choose between two SpirvOpaqueTypes
>;

template<typename Image>
using sampledImage = vk::SpirvOpaqueType</*spv::OpTypeSampledImage*/ 27,Image>;

// %type_2d_image = OpTypeImage %float 2D 2 0 0 1 Unknown
// %type_sampled_image = OpTypeSampledImage %type_2d_image
// %_ptr_UniformConstant_type_2d_image_0 = OpTypePointer UniformConstant %type_2d_image_0
using sampler2D = spirv::pointer<spv::StorageClassUniformConstant,spirv::sampledImage<spirv::image<float,spv::Dim2D,2,0,0,1> > >;
  • Acceleration Structure Type inside pointer type
using pointer_t = vk::SpirvOpaqueType<spv::OpTypePointer,vk::Literal<vk::integral_constant<uint32_t,StorageClass> >,T>;

using RayQueryKHR = vk::SpirvOpaqueType<spv::OpTypeRayQueryKHR>;

using RayQueryEXT = pointer_t<spv::StorageClassFunction,RayQueryKHR>;
  • obtaining a Spir-V pointer of a HLSL object / casting to native Spir-V type
using pointer_t = vk::SpirvOpaqueType<spv::OpTypePointer,vk::Literal<vk::integral_constant<uint32_t,StorageClass> >,T>;

template<uint32_t StorageClass, typename T, typename U>
[[vk::ext_instruction(spv::OpCopyObject)]]
pointer_t<StorageClass,T> copyObject([[vk::ext_reference]] U v);

Actual Behavior

Always some variation of

vk::SpirvOpaqueType<NNNN>' is an object and cannot be used as a type parameter

Environment

  • DXC version: commit ac36a797d3470e8ee906b98457a59270d01db30d
  • Host Operating System: Windows

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the diagnostic with the nested image, acceleration-structure pointer, and OpCopyObject examples in the issue using DXC commit ac36a797d3470e8ee906b98457a59270d01db30d. Trace how SpirvOpaqueType arguments are classified during compilation; done means nested SpirvOpaqueType and SpirvType arguments are accepted without the object/type-parameter diagnostic.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.