vulkan: use capability flags to enumerate formats

This commit is contained in:
columbarius 2023-08-12 02:50:34 +02:00 committed by Wim Taymans
parent d549d9e595
commit 3274880e8e
5 changed files with 42 additions and 14 deletions

View file

@ -292,18 +292,23 @@ static struct spa_pod *build_EnumFormat(uint32_t fmt, const struct vulkan_format
// This function enumerates the available formats in vulkan_state::formats, announcing all formats capable to support DmaBufs // This function enumerates the available formats in vulkan_state::formats, announcing all formats capable to support DmaBufs
// first and then falling back to those supported with SHM buffers. // first and then falling back to those supported with SHM buffers.
static bool find_EnumFormatInfo(struct vulkan_base *s, uint32_t index, uint32_t *fmt_idx, bool *has_modifier) { static bool find_EnumFormatInfo(struct vulkan_base *s, uint32_t index, uint32_t caps, uint32_t *fmt_idx, bool *has_modifier) {
int64_t fmtIterator = 0; int64_t fmtIterator = 0;
int64_t maxIterator = 0;
if (caps & VULKAN_BUFFER_TYPE_CAP_SHM)
maxIterator += s->formatInfoCount;
if (caps & VULKAN_BUFFER_TYPE_CAP_DMABUF)
maxIterator += s->formatInfoCount;
// Count available formats until index underflows, while fmtIterator indexes the current format. // Count available formats until index underflows, while fmtIterator indexes the current format.
// Iterate twice over formats first time with modifiers, second time without. // Iterate twice over formats first time with modifiers, second time without if both caps are supported.
while (index < (uint32_t)-1 && fmtIterator < 2*s->formatInfoCount) { while (index < (uint32_t)-1 && fmtIterator < maxIterator) {
const struct vulkan_format_info *f_info = &s->formatInfos[fmtIterator%s->formatInfoCount]; const struct vulkan_format_info *f_info = &s->formatInfos[fmtIterator%s->formatInfoCount];
if (fmtIterator < s->formatInfoCount) { if (caps & VULKAN_BUFFER_TYPE_CAP_DMABUF && fmtIterator < s->formatInfoCount) {
// First round, check for modifiers // First round, check for modifiers
if (f_info->modifierCount > 0) { if (f_info->modifierCount > 0) {
index--; index--;
} }
} else { } else if (caps & VULKAN_BUFFER_TYPE_CAP_SHM) {
// Second round, every format should be supported. // Second round, every format should be supported.
index--; index--;
} }
@ -318,7 +323,7 @@ static bool find_EnumFormatInfo(struct vulkan_base *s, uint32_t index, uint32_t
fmtIterator--; fmtIterator--;
*fmt_idx = fmtIterator%s->formatInfoCount; *fmt_idx = fmtIterator%s->formatInfoCount;
// Loop finished in first round // Loop finished in first round
*has_modifier = fmtIterator < s->formatInfoCount; *has_modifier = caps & VULKAN_BUFFER_TYPE_CAP_DMABUF && fmtIterator < s->formatInfoCount;
return true; return true;
} }
@ -333,7 +338,7 @@ static int port_enum_formats(void *object,
uint32_t fmt_index; uint32_t fmt_index;
bool has_modifier; bool has_modifier;
if (!find_EnumFormatInfo(&this->state.base, index, &fmt_index, &has_modifier)) if (!find_EnumFormatInfo(&this->state.base, index, spa_vulkan_get_buffer_caps(&this->state, direction), &fmt_index, &has_modifier))
return 0; return 0;
const struct vulkan_format_info *f_info = &this->state.base.formatInfos[fmt_index]; const struct vulkan_format_info *f_info = &this->state.base.formatInfos[fmt_index];

View file

@ -526,18 +526,23 @@ static struct spa_pod *build_EnumFormat(uint32_t fmt, const struct vulkan_format
// This function enumerates the available formats in vulkan_state::formats, announcing all formats capable to support DmaBufs // This function enumerates the available formats in vulkan_state::formats, announcing all formats capable to support DmaBufs
// first and then falling back to those supported with SHM buffers. // first and then falling back to those supported with SHM buffers.
static bool find_EnumFormatInfo(struct vulkan_base *s, uint32_t index, uint32_t *fmt_idx, bool *has_modifier) { static bool find_EnumFormatInfo(struct vulkan_base *s, uint32_t index, uint32_t caps, uint32_t *fmt_idx, bool *has_modifier) {
int64_t fmtIterator = 0; int64_t fmtIterator = 0;
int64_t maxIterator = 0;
if (caps & VULKAN_BUFFER_TYPE_CAP_SHM)
maxIterator += s->formatInfoCount;
if (caps & VULKAN_BUFFER_TYPE_CAP_DMABUF)
maxIterator += s->formatInfoCount;
// Count available formats until index underflows, while fmtIterator indexes the current format. // Count available formats until index underflows, while fmtIterator indexes the current format.
// Iterate twice over formats first time with modifiers, second time without. // Iterate twice over formats first time with modifiers, second time without if both caps are supported.
while (index < (uint32_t)-1 && fmtIterator < 2*s->formatInfoCount) { while (index < (uint32_t)-1 && fmtIterator < maxIterator) {
const struct vulkan_format_info *f_info = &s->formatInfos[fmtIterator%s->formatInfoCount]; const struct vulkan_format_info *f_info = &s->formatInfos[fmtIterator%s->formatInfoCount];
if (fmtIterator < s->formatInfoCount) { if (caps & VULKAN_BUFFER_TYPE_CAP_DMABUF && fmtIterator < s->formatInfoCount) {
// First round, check for modifiers // First round, check for modifiers
if (f_info->modifierCount > 0) { if (f_info->modifierCount > 0) {
index--; index--;
} }
} else { } else if (caps & VULKAN_BUFFER_TYPE_CAP_SHM) {
// Second round, every format should be supported. // Second round, every format should be supported.
index--; index--;
} }
@ -552,7 +557,7 @@ static bool find_EnumFormatInfo(struct vulkan_base *s, uint32_t index, uint32_t
fmtIterator--; fmtIterator--;
*fmt_idx = fmtIterator%s->formatInfoCount; *fmt_idx = fmtIterator%s->formatInfoCount;
// Loop finished in first round // Loop finished in first round
*has_modifier = fmtIterator < s->formatInfoCount; *has_modifier = caps & VULKAN_BUFFER_TYPE_CAP_DMABUF && fmtIterator < s->formatInfoCount;
return true; return true;
} }
@ -567,7 +572,7 @@ static int port_enum_formats(void *object,
uint32_t fmt_index; uint32_t fmt_index;
bool has_modifier; bool has_modifier;
if (!find_EnumFormatInfo(&this->state.base, index, &fmt_index, &has_modifier)) if (!find_EnumFormatInfo(&this->state.base, index, spa_vulkan_get_buffer_caps(&this->state, direction), &fmt_index, &has_modifier))
return 0; return 0;
const struct vulkan_format_info *f_info = &this->state.base.formatInfos[fmt_index]; const struct vulkan_format_info *f_info = &this->state.base.formatInfos[fmt_index];

View file

@ -492,6 +492,17 @@ int spa_vulkan_process(struct vulkan_compute_state *s)
return 0; return 0;
} }
int spa_vulkan_get_buffer_caps(struct vulkan_compute_state *s, enum spa_direction direction)
{
switch (direction) {
case SPA_DIRECTION_INPUT:
return VULKAN_BUFFER_TYPE_CAP_DMABUF;
case SPA_DIRECTION_OUTPUT:
return VULKAN_BUFFER_TYPE_CAP_DMABUF;
}
return 0;
}
int spa_vulkan_init(struct vulkan_compute_state *s) int spa_vulkan_init(struct vulkan_compute_state *s)
{ {
s->base.log = s->log; s->base.log = s->log;

View file

@ -71,5 +71,7 @@ int spa_vulkan_ready(struct vulkan_compute_state *s);
int spa_vulkan_process(struct vulkan_compute_state *s); int spa_vulkan_process(struct vulkan_compute_state *s);
int spa_vulkan_cleanup(struct vulkan_compute_state *s); int spa_vulkan_cleanup(struct vulkan_compute_state *s);
int spa_vulkan_get_buffer_caps(struct vulkan_compute_state *s, enum spa_direction direction);
int spa_vulkan_init(struct vulkan_compute_state *s); int spa_vulkan_init(struct vulkan_compute_state *s);
void spa_vulkan_deinit(struct vulkan_compute_state *s); void spa_vulkan_deinit(struct vulkan_compute_state *s);

View file

@ -8,6 +8,11 @@
#define MAX_BUFFERS 16 #define MAX_BUFFERS 16
#define DMABUF_MAX_PLANES 1 #define DMABUF_MAX_PLANES 1
enum buffer_type_caps {
VULKAN_BUFFER_TYPE_CAP_SHM = 1<<0,
VULKAN_BUFFER_TYPE_CAP_DMABUF = 1<<1,
};
struct vulkan_modifier_info { struct vulkan_modifier_info {
VkDrmFormatModifierPropertiesEXT props; VkDrmFormatModifierPropertiesEXT props;
VkExtent2D max_extent; VkExtent2D max_extent;