Skip to content

nir, vtn, microsoft/compiler: Support mapping read-only SSBOs and storage images to D3D read-only resource types

Jesse Natalie requested to merge jenatali/mesa:vulkan-ssbo-srv into master

This series does a few things to improve how we can translate SPIR-V that has read-only resources, so we do it the same as other SPIR-V -> D3D converters (e.g. SPIRV-Cross). Those converters take read-only SSBOs and read-only storage images and convert them to D3D's read-only SRV resource class.

For read-only SSBOs, in SPIR-V, it just looks like a struct that has NonWritable decorating all of the struct members. If you take a D3D read-only SSBO-equivalent (ByteAddressBuffer or StructuredBuffer<my_struct_type>) and compile to SPIR-V with DXC, that's what you get. So, in vtn, we now propagate the non-writable access bit that exists on all struct members out to the parent struct.

For read-only storage images, in SPIR-V you get a NonWritable annotation on the variable. This looks pretty similar to how OpenCL does things, except OpenCL puts it on the type. When vtn emits image intrinsics, it has the type explicitly there, and propagates the access bits to the intrinsic, but there may be indirections to the variable, so we can't necessarily do the same for GL/VK SPIR-V. So, I'm re-using the lowering pass (image -> tex) we built for CL images, and modified it to be able to pull access info from the variable - since that lowering can come after indirections are lowered away.

I also want to modify the variable (and deref) types for the read-only storage images to be tex. I've currently put this in the same lowering pass, guarded by the same switch, but I'm happy to take this out of common code or add a different option if people prefer.

Once all of that's done, it's just a matter of paying attention to the right things to distinguish read-only SSBOs in the backend compiler, and add the image lowering pass to spirv-to-dxil.

/cc @jekstrand for the nir/vtn changes.
/cc @egalli and @tangm for the DXIL changes.

Merge request reports

Loading