Skip to content

[SPIR-V] Missing VulkanMemoryModelDeviceScopeKHR Capability when using wave intrinsics #6066

Closed

Description

@mourthag

Description
When building a raytracing shader (closestHit, miss or raygeneration) with a device atomic operation and wave intrinsic operations, the compilation fails due to a missing SPIR-V capability declaration.

Steps to Reproduce

  1. Create a closestHit, miss or rayGeneration shader
  2. Add an atomic operation on a device buffer
  3. Add a waveintrinsic operation
  4. Compile for Vulkan 1.2

compiled with -HV 2021 -fspv-target-env=vulkan1.2 spirv1.4 -T lib_6_4 -E main -spirv -O0

A reproducer can be found here:
https://godbolt.org/z/Mrxb7z3K7

Actual Behavior
The compiler fails with the following error.

fatal error: generated SPIR-V is invalid: Use of device scope with VulkanKHR memory model requires the VulkanMemoryModelDeviceScopeKHR capability
  %21 = OpAtomicIAdd %int %18 %uint_1 %uint_0 %20

note: please file a bug report on https://github.com/Microsoft/DirectXShaderCompiler/issues with source code if possible

Compiler returned: 5

The created SPIR-V is obviously missing the required capability which should be added by dxc in this case.

Environment

  • DXC version: trunk (7b222ff)
  • Host Operating System Windows 11 64-bit

Activity

  1. added
    bug
    needs-triage
    spirv
    on Nov 27, 2023
  2. devshgraphicsprogramming commented on Nov 29, 2023

    @devshgraphicsprogramming

    btw if you need a quick fix, you can declare the capability yourself using inline SPIR-V somewhere in statically reachable code (by your entry point)

  3. mourthag commented on Nov 30, 2023

    @mourthag
    Author

    Mateusz Kielan (@devshgraphicsprogramming) Great idea, thank you!
    I tried adding [[vk::ext_capability(/*VulkanMemoryModelDeviceScopeKHR*/ 5346)]] next to my entry point, but it still fails to add the capability. Am I missing something?

  4. devshgraphicsprogramming commented on Nov 30, 2023

    @devshgraphicsprogramming

    Mateusz Kielan (@devshgraphicsprogramming) Great idea, thank you! I tried adding [[vk::ext_capability(/*VulkanMemoryModelDeviceScopeKHR*/ 5346)]] next to my entry point, but it still fails to add the capability. Am I missing something?

    hmm no more ideas at this point, but maybe the SPIR-V is getting validated BEFORE this inline stuff gets added?

  5. mourthag commented on Nov 30, 2023

    @mourthag
    Author

    I found the problem. The [[vk::ext_capability()]] needs to be coupled with [[vk::ext_instruction()]] for example. (see also wiki and this issue)
    With this, I created a super hacky workaround: https://godbolt.org/z/x4c91ao35. Feel free to propose a better solution though.

  6. sudonatalie commented on Dec 4, 2023

    @sudonatalie
    Collaborator

    Mourthag (@mourthag) Thanks for reporting! I'll take a look.

  7. moved this from For Google to Done in HLSL Triageon Dec 4, 2023
  8. added 5 commits that reference this issue on Jan 23, 2024
    af50dae
    20edc1a
    bf39978
    68f3f1a
    fe70cb0
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

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions