Determing the highest possible color and depth attachement sampled count in Vulkan


Do I need to set the value of VkAttachmentDescription::samples to a power of 2 or are arbitrary values allowed, as long as they don't exceed the maximum supported by the hardware?

I'm really confused about this. The samples field is of type VkSampleCountFlagBits, which is declared in the following way

typedef enum VkSampleCountFlagBits {
    VK_SAMPLE_COUNT_1_BIT = 0x00000001,
    VK_SAMPLE_COUNT_2_BIT = 0x00000002,
    VK_SAMPLE_COUNT_4_BIT = 0x00000004,
    VK_SAMPLE_COUNT_8_BIT = 0x00000008,
    VK_SAMPLE_COUNT_16_BIT = 0x00000010,
    VK_SAMPLE_COUNT_32_BIT = 0x00000020,
    VK_SAMPLE_COUNT_64_BIT = 0x00000040,
} VkSampleCountFlagBits;

On the other hand, the VkPhysicalDeviceLimits struct contains the fields framebufferColorSampleCounts and framebufferDepthSampleCounts, which are of type VkSampleCountFlags, which in turn is simply a typedef for uint32_t.

The vulkan-tutorial page on multisampling determines the highest bit in these fields to compute the maximal usable sampled count. I actually don't get this. What if, for example, VK_SAMPLE_COUNT_16_BIT and VK_SAMPLE_COUNT_1_BIT are both set in these fields? Doesn't that mean that the maximal usable sampled count is at least 17?

What I need to do at the end of the day is, given a uint32_t requested_sampled_count, determine whether requested_sampled_count is a possible value for VkAttachmentDescription::samples for both color and depth attachements and, if it's not, what is the highest possible value smaller than requested_sampled_count.


Say I have given a std::uint32_t sample_count and, from the physical device properties, VkSampleCountFlags framebuffer_color_sample_counts and want to compute the VkSampleCountFlagBits samples. Do I need to this in the following way?

if (sample_count > 64)
    /* error */;
if (sample_count > 32)
    samples = VK_SAMPLE_COUNT_32_BIT;
else if (sample_count > 16)
    samples = VK_SAMPLE_COUNT_16_BIT;
else if (sample_count > 8)
    samples = VK_SAMPLE_COUNT_8_BIT;
else if (sample_count > 4)
    samples = VK_SAMPLE_COUNT_4_BIT;
else if (sample_count > 2)
    samples = VK_SAMPLE_COUNT_2_BIT;
else if (sample_count == 1)
    samples = VK_SAMPLE_COUNT_1_BIT;
    /* error */;
asked on Stack Overflow Dec 4, 2020 by 0xbadf00d • edited Dec 8, 2020 by 0xbadf00d

1 Answer


The sample counts in the VkSampleCountFlagsBits enumeration are a bit-mask of the available settings for the number of sampled bits in an attachment, so in your example the hardware supports either one or 16 samples (not 17!)

answered on Stack Overflow Dec 4, 2020 by stridecolossus

User contributions licensed under CC BY-SA 3.0