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,
VK_SAMPLE_COUNT_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
} 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;
else
/* error */;
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!)
So, in general, only powers of $2$ are supported, right?
Yes, although I would still use the enumeration bit masks rather than any power-of-two maths, just to make the purpose of the code clearer.
I'm asking cause I need to adopt to an interface which gives me a
uint32_t
for the sample count. I guess the best solution is to&
this sample count against the enumeration bit masks and use the largest nonzero one.@0xbadf00d Yes that's exactly the approach I expect you have to take - basically a for loop over the bit mask testing each to enumerate the values from
VkSampleCountFlagBits
and then you can apply your logic to work out the highest for the colour and depth attachments.Please take note of my edit. Is this how I need to do it?