Is there any way to use 16-bit floating point in Vulkan compute shader?
I have a matrix multiplication compute shader with a single buffer for matrix A,B, and C. On the host side, I use http://half.sourceforge.net/ to convert float32 to float16.
half* matrixTmp;
vkMapMemory(device, bufferMemory, 0, matrixSize, 0, (void **) &matrixTmp));
int offset = 0;
for(int i = 0; i < M*K; i++) {
matrixTmp[offset+i] = half_cast<half>(matrixA[i]);
}
offset = (M*K);
for(int i = 0; i < K*N; i++) {
matrixTmp[offset+i] = half_cast<half>(matrixB[i]);
}
For float32, I use the following compute shader layout.
layout(binding = 0) buffer matrixBuffer {
vec4 matrixABC[];
};
How to use the buffer in compute shader if it contains 16-bit floating point?
Edit: I use Vulkan for Android device and I also need my shader to be able to do 16-bit operation, not storage only.