veldrid: [Android/Vulkan] CopyTexture crashes the app
This code crashes when running on Android/Vulkan:
var src = factory.CreateTexture(TextureDescription.Texture2D(
texSize, texSize, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Sampled));
var dst = factory.CreateTexture(TextureDescription.Texture2D(
texSize, texSize, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Sampled));
var cl = factory.CreateCommandList();
cl.Begin();
cl.CopyTexture(src, dst);
cl.End();
device.SubmitCommands(cl);
device.WaitForIdle();
Only tested it on a Xiaomi Redmi 4X (Android 7.1). You can find a small repro project here.

About this issue
- Original URL
- State: open
- Created 6 years ago
- Comments: 34 (16 by maintainers)
This is the code generated by Mono’s AOT compiler in release mode:
Essentially, this is what the registers and the stack look like when vkCmdCopyImage is called:
And here’s the equivalent (except working) code generated by clang:
So the arguments are passed like this:
Notice where pRegions is stored. The location is different, and that’s because here we have a 4 byte gap between srcImageLayout and dstImage. I don’t have an explanation for this. Could be some sort of convention that Mono doesn’t respect, I don’t know. But the fact of the matter is, the implementation expects to find pRegions at [SP + 18], not [SP + 14].
I’ve already tried changing the function signature so that the arguments would end up at the corrent locations, and it worked. You can do that by adding an extra 4 byte parameter after srcImageLayout. Removing the extra parameter makes it crash again. I think this will only work in release mode, though.