Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How are separated sampled images and samplers used in Vulkan with GLSL?

I just finished writing up the code for my texture and sampler objects, but now I am stumped on how to implement the separated descriptors into GLSL.

Accessing a combined image sampler in descriptor set 0, binding 0 would be done using:

layout(set = 0, binding = 0) uniform sampler2D texSampler;

The fragment shader would then sample the image using sampler2D and the texture function:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

layout(location = 0) in vec2 fragTexCoord;

layout(location = 0) out vec4 outColor;

void main() {
    outColor = texture(texSampler, fragTexCoord);
}

From what I understand, a descriptor set (or binding) is created for a sampler using VK_DESCRIPTOR_TYPE_SAMPLER and another is created for a sampled image with the type VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE. However, I do not know what syntax would be used to access the separate descriptors.

layout(set = 0, binding = 0) uniform /* idk what type it is */ sampler
layout(set = 0, binding = 1) uniform /* idk */ sampledImage
// alternatively...
layout(set = 0, binding = 0) uniform /* idk */ sampler
layout(set = 1, binding = 0) uniform /* idk */ sampledImage

Are samplers and images stored in different sets/bindings as specified when creating the descriptor sets?

If sampler2D is used for combined image samplers with the descriptor type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, then what is the syntax used for each of the separated types?

VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, and VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER?

How would these separated objects be called in main to set the outColor value?

>Solution :

The GLSL types sampler* (where * is the type of a texture, such a 1D, Cube, etc) represent descriptors of the form VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER.

As specified in the GL_KHR_vulkan_glsl extension, the GLSL type sampler (no *) represents a descriptor of the form VK_DESCRIPTOR_TYPE_SAMPLER. For descriptors of the form VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, the appropriate GLSL types are texture* (where * is again the type of the texture).

To combine a sampled image with a sampler, you create a sampler* object from the two using constructor syntax: texture(sampler2D(t, s), ...);

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading