0

I'm writing a Vulkan compute shader in Android studio and launching it on Android phone. The problem I'm experiencing is next - I can not use any subgroup operations like subgroupAdd and subgroupElect. When I'm trying to use these functions I have an error like this:

reduce_vec.comp:35: error: 'subgroup op' : requires SPIR-V 1.3

I have checked - my Android phone supports subgroups, and my shader accepts such extensions:

#extension GL_KHR_shader_subgroup_arithmetic: enable
#extension GL_KHR_shader_subgroup_basic: enable

The problem is pretty much straightforward, I need to update my SPIR-V. But according to my findings, SPIR-V that comes automatically with Android studio is not something I can update easily.

Did someone experience a similar issue before? What was your solution? Thanks in advance!

Eugene Alexeev
  • 1,152
  • 12
  • 32

1 Answers1

2

Android solution

You can pass arguments to the Android shaderc compiler in your Gradle DSL:

https://developer.android.com/ndk/guides/graphics/shader-compilers

You need glslcArgs to contain --target-env=vulkan1.1

Flexible solution

Build your own compilation pipeline to compile from source into SPIR-V, and then include the SPIR-V binary files directly into your Android project.

There are multiple language front-ends that can generate SPIR-V, for GLSL the Khronos tools are here:

solidpixel
  • 10,688
  • 1
  • 20
  • 33
  • THat's what I'm working on right now. But I feel there're should be much easier option. I don't believe it has to be that complex – Eugene Alexeev Feb 08 '22 at 09:13
  • Updated to include an Android solution (not had a chance to test it yet, but works on the command line) – solidpixel Feb 08 '22 at 09:20
  • Your solution for Android studio is correct! Thank you very much for your help. Although it seems it has increased a build time of my project, but let's see, maybe it's just a lag – Eugene Alexeev Feb 08 '22 at 09:39