简体   繁体   English

在 Vulkan 中确定最高可能的颜色和深度附件采样计数

[英]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?我是否需要将VkAttachmentDescription::samples的值设置为 2 的幂或允许任意值,只要它们不超过硬件支持的最大值?

I'm really confused about this.我真的很困惑。 The samples field is of type VkSampleCountFlagBits , which is declared in the following way samples字段的类型为VkSampleCountFlagBits ,其声明方式如下

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 .另一方面, VkPhysicalDeviceLimits结构包含字段framebufferColorSampleCountsframebufferDepthSampleCounts ,它们的类型是VkSampleCountFlags ,而这又只是uint32_ttypedef

The vulkan-tutorial page on multisampling determines the highest bit in these fields to compute the maximal usable sampled count. 关于多重采样的 vulkan 教程页面确定这些字段中的最高位以计算最大可用采样计数。 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?例如,如果在这些字段中都设置了VK_SAMPLE_COUNT_16_BITVK_SAMPLE_COUNT_1_BIT怎么办? Doesn't that mean that the maximal usable sampled count is at least 17?这是否意味着最大可用采样数至少为 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 .在一天结束时我需要做的是,给定一个uint32_t requested_sampled_count ,确定requested_sampled_count是否是颜色和深度附件的VkAttachmentDescription::samples可能值,如果不是,则最大可能值小于requested_sampled_count

EDIT :编辑

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 .假设我给出了一个std::uint32_t sample_count ,并且从物理设备属性VkSampleCountFlags framebuffer_color_sample_counts并想要计算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!) VkSampleCountFlagsBits枚举中的样本计数是附件中采样位数的可用设置的位掩码,因此在您的示例中,硬件支持一个或16个样本(不是 17 个!)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM