Skip to content

[SPIR-V] [[vk::ext_extension]] attribute causes "invalid SPIR-V" #8210

Closed as not planned

Description

Description
We are trying to confirm if SPV_EXT_opacity_micromap + RayTracingOpacityMicromapEXT are missing in one of our SPIR-V shaders, that cause crashes on specific hardware that uses opacity micromaps in acceleration structures. However, trying to simply add it with the [[vk::ext_extension]] attribute causes a very simple shader to suddenly stop compiling.

Steps to Reproduce
https://godbolt.org/z/fqGdETxxd (-T cs_6_9 -E main -spirv -Wno-hlsl-rayquery-flags)

Unsure if we really need -Wno-hlsl-rayquery-flags, SPIR-V doesn't define RAYQUERY_FLAG_ALLOW_OPACITY_MICROMAPS but DXC requires it in order to use RAY_FLAG_FORCE_OMM_2_STATE.

Commenting out [[vk::ext_extension("SPV_EXT_opacity_micromap")]] makes the shader compile successfully again, with the RAY_FLAG_FORCE_OMM_2_STATE = 1024 constant used in the ray query flags.

Actual Behavior

fatal error: generated SPIR-V is invalid: In Logical addressing, variables can only allocate a pointer to the StorageBuffer or Workgroup storage classes
  %58 = OpVariable %_ptr_Function__ptr_Uniform_type_ByteAddressBuffer Function

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

Compiler returned: 5

Environment

  • DXC version 1.8.2505 and trunk on Godbolt (libdxcompiler.so: 1.10(1-11951229)(1.9.0.10001)).
  • Host Operating System Linux

Activity

  1. added
    bug
    spirv
    needs-triage
    on Feb 27, 2026
  2. MarijnS95 commented on Mar 5, 2026

    @MarijnS95
    ContributorAuthor

    Well I see quite a big oopsie in the GodBolt example. I copied it from one of my earlier DXIL reports and it still erroneously uses ResourceDescriptorHeap while targeting SPIR-V. When I remove that, this error is gone:

    https://godbolt.org/z/9cs1vzh97

    I'll double-check why this same error was raised in our bigger production shaders and get back here shortly. We surely don't use ResourceDescriptorHeap in our Vulkan-targeted shaders there either 😅

    EDIT: Wondering why it was at least compiling without ext_extension(), it turns out that ResourceDescriptorHeap was made to compile for SPIR-V/Vulkan based on SPV_EXT_descriptor_indexing and VK_EXT_mutable_descriptor_type: #6650

  3. MarijnS95 commented on Mar 5, 2026

    @MarijnS95
    ContributorAuthor

    Now that I look at the diff more closely, when adding this extension the shader becomes a lot larger with dead code. We've seen similar issues before, where enabling new extensions prevents the optimize from running, leaving invalid SPIR-V in the end. SPV_EXT_opacity_micromap is simply not in the list that allows DCE to run and that ResourceDescriptorHeap was triggering it.

    Perhaps I should see what code on our end triggers the invalid SPIR-V to show up without DCE as well.

  4. MarijnS95 commented on Mar 5, 2026

    @MarijnS95
    ContributorAuthor

    Just in case, with this extension disabling DCE it's specifically "storing" a (RW)ByteAddressBuffer "to the stack" that triggers the error:

    https://godbolt.org/z/jb4nYrddc

    [[vk::binding(0, 0)]] ByteAddressBuffer g_ByteAddressBuffer[];
    
    [[vk::ext_extension("SPV_EXT_opacity_micromap")]] // Add an extension that disables DCE
    [numthreads(8, 8, 1)] void main(uint2 dispatchThreadId : SV_DispatchThreadID) {
        ByteAddressBuffer bab = g_ByteAddressBuffer[NonUniformResourceIndex(dispatchThreadId.x)];
        uint test = bab.Load(0);
    }

    And a different validation error occurs on errant OpStores that other optimizers likely filter out, when applying the same code pattern to textures and TLASes:

    https://godbolt.org/z/T1r31TPaP

    [[vk::binding(0, 0)]] RWTexture2D<uint> g_tex[];
    
    [[vk::ext_extension("SPV_EXT_opacity_micromap")]] // Add an extension that disables DCE
    [numthreads(8, 8, 1)] void main(uint2 dispatchThreadId : SV_DispatchThreadID) {
        RWTexture2D<uint> tex = g_tex[NonUniformResourceIndex(dispatchThreadId.x)];
        uint test = tex.Load(0);
    }
    fatal error: generated SPIR-V is invalid: [VUID-StandaloneSpirv-OpTypeImage-06924] Cannot store to OpTypeImage, OpTypeSampler, OpTypeSampledImage, or OpTypeAccelerationStructureKHR objects
      OpStore %29 %9
    
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

    bugneeds-triagespirv

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions