Skip to content

[Feature Request] What's the way to set OpMemoryModel ? #7180

Open

Description

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

When targetting below SPIR-V 1.5 the Vulkan memory model and BDA are extensions, and to function they require changes to the OpMemoryModel

Describe the solution you'd like

Compile flag (since its for the entire module) which lets us control OpMemoryModel

Additional context

For now it seems to just work, I wonder if in the presence of any capability requiring a change in OpMemoryModel DXC/SPIR-V Tools just declares ti correctly?

Activity

  1. devshgraphicsprogramming commented on Jun 12, 2025

    @devshgraphicsprogramming
    Author

    Steven Perron (@s-perron) I see that in 06da989 you added -fspv_use_vulkan_memory_model but its not a recognised option anymore?
    https://godbolt.org/z/6rdheznWP

  2. keptsecret commented on Jun 12, 2025

    @keptsecret

    Trying to use the memory semantic spv::MemorySemanticsMakeAvailableMask requires memory model set to Vulkan (Vulkan KHR) as per the spec (https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_memory_model_2). Is there a way to set OpMemoryModel?

    See repro on godbolt: https://godbolt.org/z/edETTxq13

  3. s-perron commented on Jun 12, 2025

    @s-perron
    Collaborator

    The option is -fspv-use-vulkan-memory-model, but it does not seem to be setting the right memory model. I'll look into this.

  4. s-perron commented on Jun 12, 2025

    @s-perron
    Collaborator

    DXC relies on the UpgradeMemoryModelPass in spir-v tools to modify the code the use the Vulkan memory model. That pass does nothing unless the logical addressing model is used. In your examples, the pass does nothing, an invalid module is generated.

    Sorakrit Chonwattanagul (@keptsecret) I'm looking into a fix for that. On your side, you need to modify your code a little to add a storage class to the atomic. I randomly picked one. You need to pick the correct one:

    void main()
    {
        [[vk::ext_decorate(5356/*spv::DecorationAliasedPointer*/)]] spirv::bda_pointer_t<uint32_t> p = bitcast<spirv::bda_pointer_t<uint32_t>,uint64_t>(0xdeadbeefull);
        // atomicIAdd(p, 1, 0x00000004|0x00002000, 1u);
        atomicIAdd(p, 1, 0x00000004|0x00002000|0x40, 1u);
    }
    
  5. devshgraphicsprogramming commented on Jul 3, 2025

    @devshgraphicsprogramming
    Author

    btw I've ran into limitations of not being able to codegen VMM directly before (being gatekept by the UpdateMemorModelPass - having the intial codegen happen in GLSL450 model)

    #7533

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancement

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions