Skip to content

[SPIR-V] HLSL to SPIR-V with subgroup extensions #2692

Closed

Description

@bzm3r

In GLSL, there are many subgroup instrinsics available via Vulkan extensions for GLSL. To some extent, this is true for HLSL, but many intrinsics are not available, as DX12/DXIL does not support them. For example, there is no way to write something in HLSL so that it compiles to the SPIR-V instruction GroupNonUniformShuffleXor.

Is there a way (possibly experimental?) to write HLSL which compiles to subgroup related SPIR-V extensions not supported by DX12?

Activity

  1. added
    spirv
    on Feb 13, 2020
  2. jaebaek commented on Feb 13, 2020

    @jaebaek
    Collaborator

    bzm3r (@bzm3r) Thank you for your question. We have something like [[vk::...]] but I am not sure. Let me check it.

  3. sudonatalie commented on Jun 23, 2022

    @sudonatalie
    Collaborator

    Arbitrary inline SPIR-V instructions are now supported through vk::ext_* attributes.

    For example, the following HLSL shader:

    [[vk::ext_capability(65 /* GroupNonUniformShuffle */)]]
    [[vk::ext_instruction(346 /* OpGroupNonUniformShuffleXor */)]]
    uint GroupNonUniformShuffleXor(uint scope, uint value, uint mask);
    
    uint main() : SV_Target{
      return GroupNonUniformShuffleXor(vk::SubgroupScope, 1, 1);
    }
    

    generates the desired GroupNonUniformShuffleXor SPIR-V instruction when compiled with dxc -T ps_6_0 -E main -spirv -fspv-target-env=vulkan1.3:

    ; SPIR-V
    ; Version: 1.6
    ; Generator: Google spiregg; 0
    ; Bound: 11
    ; Schema: 0
                   OpCapability Shader
                   OpCapability GroupNonUniformShuffle
                   OpMemoryModel Logical GLSL450
                   OpEntryPoint Fragment %main "main" %out_var_SV_Target
                   OpExecutionMode %main OriginUpperLeft
                   OpSource HLSL 600
                   OpName %out_var_SV_Target "out.var.SV_Target"
                   OpName %main "main"
                   OpDecorate %out_var_SV_Target Location 0
           %uint = OpTypeInt 32 0
         %uint_3 = OpConstant %uint 3
         %uint_1 = OpConstant %uint 1
    %_ptr_Output_uint = OpTypePointer Output %uint
           %void = OpTypeVoid
              %8 = OpTypeFunction %void
    %out_var_SV_Target = OpVariable %_ptr_Output_uint Output
           %main = OpFunction %void None %8
              %9 = OpLabel
             %10 = OpGroupNonUniformShuffleXor %uint %uint_3 %uint_1 %uint_1
                   OpStore %out_var_SV_Target %10
                   OpReturn
                   OpFunctionEnd
    
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

    spirv

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions