DirectXShaderCompiler
DirectXShaderCompiler copied to clipboard
[Feature Request] What's the way to set `OpMemoryModel` ?
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?
@s-perron I see that in https://github.com/microsoft/DirectXShaderCompiler/commit/06da989c4ab615cf7ea4bd1c5c1de00d0f7339e6 you added -fspv_use_vulkan_memory_model but its not a recognised option anymore?
https://godbolt.org/z/6rdheznWP
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
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.
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.
@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);
}
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)
https://github.com/microsoft/DirectXShaderCompiler/issues/7533