microsoft / DirectXShaderCompiler

This repo hosts the source for the DirectX Shader Compiler which is based on LLVM/Clang.
Other
3.04k stars 677 forks source link

[Feature Request] [SPIR-V] `vk::ext_extension(string name,bool enable)` to conditionally enable extensions #6584

Closed devshgraphicsprogramming closed 4 months ago

devshgraphicsprogramming commented 4 months ago

Is your feature request related to a problem? Please describe.

I'm autogenerating large amounts of templates SPIR-V intrinsics, and as you know depending on their argument types extensions or capabilities might be required (i.e. atomicIAdd on a 64bit value needs 64-bit atomic capability).

Describe the solution you'd like

Since I would have used a template metaprogramming conditional to choose between the extension string and some other ubiquitous string, it would save everyone legwork, if the ext_extension attribute just took a literal boolean whether to enable it or not.

Describe alternatives you've considered

For capabilities its easy to do:

[[vk::ext_capability(conditional_capability_v<SomeCondition,CapabilityEnum>)]]

where upon false I just default to the Shader capability which everyone needs to have.

but because vk::ext_extension takes a string, it makes any of these impossible

// complains not literal
static const string str = "SPV_EXT_shader_stencil_export";
// non-type template argument does not refer to any declaration
using cstr = integral_type<string,"SPV_EXT_shader_stencil_export">;
using cstr2 = integral_type<__decltype("SPV_EXT_shader_stencil_export"),"SPV_EXT_shader_stencil_export">;
// SIGSEGV
static __decltype("SPV_EXT_shader_stencil_export") str = "SPV_EXT_shader_stencil_export";
sudonatalie commented 4 months ago

Requests for changes to the HLSL language (including Vulkan-specific attributes) now fall under the scope of the microsoft/hlsl-specs repository. Please consider submitting a proposal there instead.

That said, adding complexity to the API for the support of extensive template metaprogramming is not a high-priority and unlikely to be strongly considered at this time.

devshgraphicsprogramming commented 3 months ago

Btw a little note after the fact, it seems that

[[vk::ext_capability(conditional_capability_v<SomeCondition,CapabilityEnum>)]]

wasn't possible in the first place wher SomeCondition depends on a typename T. https://godbolt.org/z/58Y7fTdf7

I don't know if its a DXC or general Clang thing that attributes can't depend on templates

I guess a ext_extension(string,bool) would have suffered from the same problem