Texture2D

I am trying to implement SSAO in vulkan and I am trying to understand how should I pass noise texture to the shader.
In openGl I made TEXTURE_RECT, and passed it as sampler2DRect. But I have a guess, that Vulkan has some “binary buffers” entity for such a purpose. Is it really so? What is the correct way to pass noise to my AO shader?

In Vulkan everything is a buffer. It doesn’t matter if it “is” a texture, a ssbo, ubo, etc. The difference is pretty much only down to the usage bits provided. So you’re free to choose how you want to pass your data.

So for passing your random AO (noise) vectors you could simply use a ssbo with staging to upload them or upload them as a normal texture using a buffer-to-image copy.

As for the sampler2DRect, there is no such a specific thing in Vulkan, and afaik sampler2DRect has long been deprecated (all Vulkan implementations should support NPOT textures).
In general don’t try to do things in Vulkan as you did in OpenGL. Just remember that all the data you push towards the GPU in Vulkan is just buffer-backed memory that is interpreted differently solely depending on it’s specified usage.

FYI: Rectangle textures were never deprecated in OpenGL.

OK, now for example I use simple texture, because I was unable to find any SSBO code sample. But conceptual it does not make sense for me - why should I have imageView and sampler for accessing such a buffer? SSBO seems more appropriate here
Now I am getting one more stupid problem with porting SSAO GLES shader to GLSL4.5, and I do not want to create another thread for this. I got a strange error:
Shader declares capability 37, not supported in Vulkan.

My shader “headers” are:

#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable

layout (location = 0) in vec3 pos;
layout (location = 0) out vec2 uv;
layout (location = 1) out vec2 fragPos;
layout (location = 2) out vec3 viewRay;

out gl_PerVertex {
vec4 gl_Position;
};

layout(binding = 0) uniform VRBlock
{
float tanHalfFov, aspectRatio;
} ubo;

and

#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable

#define KERNEL_SIZE 32
#define NOISE_SIZE 4
#define OCCLUSION_POWER 1.5
#define OCCLUSION_RADIUS 1.0

layout (location = 0) in vec2 uv;
layout (location = 1) in vec2 fragPos;
layout (location = 2) in vec3 viewRay;

layout(binding = 1) uniform CameraBlock
{
mat4 uProjectionMatrix, uInvertedMVP, uMVP, matMV;
vec3 uKernel[KERNEL_SIZE];
} ubo;

layout (binding = 2) uniform sampler2DRect samplerNoise;
layout (binding = 3) uniform sampler2D samplerPos;
layout (binding = 4) uniform sampler2D samplerDepth;
layout (binding = 5) uniform sampler2D samplerNormalsSpecular;

layout (location = 0) out vec4 uOcclusionFactor;

(dont see to the uKernel - shader side is still not reworked for texture input).

Please post your complete shaders (and their types. I guess the second one is the fragment shader?), the glslangvalidator Version you use to compile to SPIR-V as well as the complete output of the shader compilation error. You’re propably using something that is not allowed in the Vulkan GLSL-Specs.

Edit: SPIR-V OpCapability 37 is SampledRect, please try again with non-rect sampler.

Indeed very useful error message. :doh:

If I go decode that 37 is SampledRect SPIR-V Capability. It is unsupported by Vulkan as per ch A.2. Capabilities of the spec.
Vulkan won’t probably accept your sampler2DRect.

EDIT: darn, ninja’d again.

Using a storage buffer (aka SSBO) is no different than using other buffers. You create your buffer with the VK_BUFFER_USAGE_STORAGE_BUFFER_BIT bit and access it in your shader as an array:

layout(set = x, binding = y) buffer Computedata
{
    vec4 data[];
} computedata;

Also note that you may need to check if shaderStorageBufferArrayDynamicIndexing is supported if you do dynamic indexing of such a buffer using uniforms.

P.S. : There is a tutorial on SSBOs from MALI over here and there is a compute based particle system example using an SSBO in my repo too. Both use the SSBO in a compute shader, but accessing it in the fragment shader is no different.